summaryrefslogtreecommitdiff
path: root/drivers/media/pci/pt3/pt3.h
blob: 1b3f2ad25db37b4356ee0132c004628471f0c7ed (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
/*
 * Earthsoft PT3 driver
 *
 * Copyright (C) 2014 Akihiro Tsukada <tskd08@gmail.com>
 *
 * This program is free software; you can redistribute it and/or
 * modify it under the terms of the GNU General Public License as
 * published by the Free Software Foundation version 2.
 *
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 */

#ifndef PT3_H
#define PT3_H

#include <linux/atomic.h>
#include <linux/types.h>

#include "dvb_demux.h"
#include "dvb_frontend.h"
#include "dmxdev.h"

#include "tc90522.h"
#include "mxl301rf.h"
#include "qm1d1c0042.h"

#define DRV_NAME KBUILD_MODNAME

#define PT3_NUM_FE 4

/*
 * register index of the FPGA chip
 */
#define REG_VERSION	0x00
#define REG_BUS		0x04
#define REG_SYSTEM_W	0x08
#define REG_SYSTEM_R	0x0c
#define REG_I2C_W	0x10
#define REG_I2C_R	0x14
#define REG_RAM_W	0x18
#define REG_RAM_R	0x1c
#define REG_DMA_BASE	0x40	/* regs for FE[i] = REG_DMA_BASE + 0x18 * i */
#define OFST_DMA_DESC_L	0x00
#define OFST_DMA_DESC_H	0x04
#define OFST_DMA_CTL	0x08
#define OFST_TS_CTL	0x0c
#define OFST_STATUS	0x10
#define OFST_TS_ERR	0x14

/*
 * internal buffer for I2C
 */
#define PT3_I2C_MAX 4091
struct pt3_i2cbuf {
	u8  data[PT3_I2C_MAX];
	u8  tmp;
	u32 num_cmds;
};

/*
 * DMA things
 */
#define TS_PACKET_SZ  188
/* DMA transfers must not cross 4GiB, so use one page / transfer */
#define DATA_XFER_SZ   4096
#define DATA_BUF_XFERS 47
/* (num_bufs * DATA_BUF_SZ) % TS_PACKET_SZ must be 0 */
#define DATA_BUF_SZ    (DATA_BUF_XFERS * DATA_XFER_SZ)
#define MAX_DATA_BUFS  16
#define MIN_DATA_BUFS   2

#define DESCS_IN_PAGE (PAGE_SIZE / sizeof(struct xfer_desc))
#define MAX_NUM_XFERS (MAX_DATA_BUFS * DATA_BUF_XFERS)
#define MAX_DESC_BUFS DIV_ROUND_UP(MAX_NUM_XFERS, DESCS_IN_PAGE)

/* DMA transfer description.
 * device is passed a pointer to this struct, dma-reads it,
 * and gets the DMA buffer ring for storing TS data.
 */
struct xfer_desc {
	u32 addr_l; /* bus address of target data buffer */
	u32 addr_h;
	u32 size;
	u32 next_l; /* bus adddress of the next xfer_desc */
	u32 next_h;
};

/* A DMA mapping of a page containing xfer_desc's */
struct xfer_desc_buffer {
	dma_addr_t b_addr;
	struct xfer_desc *descs; /* PAGE_SIZE (xfer_desc[DESCS_IN_PAGE]) */
};

/* A DMA mapping of a data buffer */
struct dma_data_buffer {
	dma_addr_t b_addr;
	u8 *data; /* size: u8[PAGE_SIZE] */
};

/*
 * device things
 */
struct pt3_adap_config {
	struct i2c_board_info demod_info;
	struct tc90522_config demod_cfg;

	struct i2c_board_info tuner_info;
	union tuner_config {
		struct qm1d1c0042_config qm1d1c0042;
		struct mxl301rf_config   mxl301rf;
	} tuner_cfg;
	u32 init_freq;
};

struct pt3_adapter {
	struct dvb_adapter  dvb_adap;  /* dvb_adap.priv => struct pt3_board */
	int adap_idx;

	struct dvb_demux    demux;
	struct dmxdev       dmxdev;
	struct dvb_frontend *fe;
	struct i2c_client   *i2c_demod;
	struct i2c_client   *i2c_tuner;

	/* data fetch thread */
	struct task_struct *thread;
	int num_feeds;

	bool cur_lna;
	bool cur_lnb; /* current LNB power status (on/off) */

	/* items below are for DMA */
	struct dma_data_buffer buffer[MAX_DATA_BUFS];
	int buf_idx;
	int buf_ofs;
	int num_bufs;  /* == pt3_board->num_bufs */
	int num_discard; /* how many access units to discard initially */

	struct xfer_desc_buffer desc_buf[MAX_DESC_BUFS];
	int num_desc_bufs;  /* == num_bufs * DATA_BUF_XFERS / DESCS_IN_PAGE */
};


struct pt3_board {
	struct pci_dev *pdev;
	void __iomem *regs[2];
	/* regs[0]: registers, regs[1]: internal memory, used for I2C */

	struct mutex lock;

	/* LNB power shared among sat-FEs */
	int lnb_on_cnt; /* LNB power on count */

	/* LNA shared among terr-FEs */
	int lna_on_cnt; /* booster enabled count */

	int num_bufs;  /* number of DMA buffers allocated/mapped per FE */

	struct i2c_adapter i2c_adap;
	struct pt3_i2cbuf *i2c_buf;

	struct pt3_adapter *adaps[PT3_NUM_FE];
};


/*
 * prototypes
 */
extern int  pt3_alloc_dmabuf(struct pt3_adapter *adap);
extern void pt3_init_dmabuf(struct pt3_adapter *adap);
extern void pt3_free_dmabuf(struct pt3_adapter *adap);
extern int  pt3_start_dma(struct pt3_adapter *adap);
extern int  pt3_stop_dma(struct pt3_adapter *adap);
extern int  pt3_proc_dma(struct pt3_adapter *adap);

extern int  pt3_i2c_master_xfer(struct i2c_adapter *adap,
				struct i2c_msg *msgs, int num);
extern u32  pt3_i2c_functionality(struct i2c_adapter *adap);
extern void pt3_i2c_reset(struct pt3_board *pt3);
extern int  pt3_init_all_demods(struct pt3_board *pt3);
extern int  pt3_init_all_mxl301rf(struct pt3_board *pt3);
#endif /* PT3_H */