xref: /openbmc/linux/drivers/media/pci/ddbridge/ddbridge.h (revision e933a6f1af4648c6a0023795d99aa5470fd2f49d)
1 /*
2  * ddbridge.h: Digital Devices PCIe bridge driver
3  *
4  * Copyright (C) 2010-2011 Digital Devices GmbH
5  *
6  * This program is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU General Public License
8  * version 2 only, as published by the Free Software Foundation.
9  *
10  *
11  * This program is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14  * GNU General Public License for more details.
15  *
16  * To obtain the license, point your browser to
17  * http://www.gnu.org/copyleft/gpl.html
18  */
19 
20 #ifndef _DDBRIDGE_H_
21 #define _DDBRIDGE_H_
22 
23 #include <linux/types.h>
24 #include <linux/sched.h>
25 #include <linux/interrupt.h>
26 #include <linux/i2c.h>
27 #include <linux/mutex.h>
28 #include <asm/dma.h>
29 #include <linux/dvb/frontend.h>
30 #include <linux/dvb/ca.h>
31 #include <linux/socket.h>
32 
33 #include "dmxdev.h"
34 #include "dvbdev.h"
35 #include "dvb_demux.h"
36 #include "dvb_frontend.h"
37 #include "dvb_ringbuffer.h"
38 #include "dvb_ca_en50221.h"
39 #include "dvb_net.h"
40 #include "cxd2099.h"
41 
42 #define DDB_MAX_I2C     4
43 #define DDB_MAX_PORT    4
44 #define DDB_MAX_INPUT   8
45 #define DDB_MAX_OUTPUT  4
46 #define DDB_MAX_LINK    4
47 #define DDB_LINK_SHIFT 28
48 
49 #define DDB_LINK_TAG(_x) (_x << DDB_LINK_SHIFT)
50 
51 #define DDB_XO2_TYPE_NONE	0
52 #define DDB_XO2_TYPE_DUOFLEX	1
53 #define DDB_XO2_TYPE_CI		2
54 
55 struct ddb_info {
56 	int   type;
57 #define DDB_NONE         0
58 #define DDB_OCTOPUS      1
59 	char *name;
60 	int   port_num;
61 	u32   port_type[DDB_MAX_PORT];
62 	u32   board_control;
63 	u32   board_control_2;
64 	u8    ts_quirks;
65 #define TS_QUIRK_SERIAL   1
66 #define TS_QUIRK_REVERSED 2
67 #define TS_QUIRK_ALT_OSC  8
68 };
69 
70 /* DMA_SIZE MUST be divisible by 188 and 128 !!! */
71 
72 #define INPUT_DMA_MAX_BUFS 32      /* hardware table limit */
73 #define INPUT_DMA_BUFS 8
74 #define INPUT_DMA_SIZE (128*47*21)
75 
76 #define OUTPUT_DMA_MAX_BUFS 32
77 #define OUTPUT_DMA_BUFS 8
78 #define OUTPUT_DMA_SIZE (128*47*21)
79 
80 struct ddb;
81 struct ddb_port;
82 
83 struct ddb_input {
84 	struct ddb_port       *port;
85 	u32                    nr;
86 	int                    attached;
87 
88 	dma_addr_t             pbuf[INPUT_DMA_MAX_BUFS];
89 	u8                    *vbuf[INPUT_DMA_MAX_BUFS];
90 	u32                    dma_buf_num;
91 	u32                    dma_buf_size;
92 
93 	struct tasklet_struct  tasklet;
94 	spinlock_t             lock;
95 	wait_queue_head_t      wq;
96 	int                    running;
97 	u32                    stat;
98 	u32                    cbuf;
99 	u32                    coff;
100 
101 	struct dvb_adapter     adap;
102 	struct dvb_device     *dev;
103 	struct i2c_client     *i2c_client[1];
104 	struct dvb_frontend   *fe;
105 	struct dvb_frontend   *fe2;
106 	struct dmxdev          dmxdev;
107 	struct dvb_demux       demux;
108 	struct dvb_net         dvbnet;
109 	struct dmx_frontend    hw_frontend;
110 	struct dmx_frontend    mem_frontend;
111 	int                    users;
112 	int (*gate_ctrl)(struct dvb_frontend *, int);
113 };
114 
115 struct ddb_output {
116 	struct ddb_port       *port;
117 	u32                    nr;
118 	dma_addr_t             pbuf[OUTPUT_DMA_MAX_BUFS];
119 	u8                    *vbuf[OUTPUT_DMA_MAX_BUFS];
120 	u32                    dma_buf_num;
121 	u32                    dma_buf_size;
122 	struct tasklet_struct  tasklet;
123 	spinlock_t             lock;
124 	wait_queue_head_t      wq;
125 	int                    running;
126 	u32                    stat;
127 	u32                    cbuf;
128 	u32                    coff;
129 
130 	struct dvb_adapter     adap;
131 	struct dvb_device     *dev;
132 };
133 
134 struct ddb_i2c {
135 	struct ddb            *dev;
136 	u32                    nr;
137 	struct i2c_adapter     adap;
138 	struct i2c_adapter     adap2;
139 	u32                    regs;
140 	u32                    rbuf;
141 	u32                    wbuf;
142 	int                    done;
143 	wait_queue_head_t      wq;
144 };
145 
146 struct ddb_port {
147 	struct ddb            *dev;
148 	u32                    nr;
149 	struct ddb_i2c        *i2c;
150 	struct mutex           i2c_gate_lock;
151 	u32                    class;
152 #define DDB_PORT_NONE           0
153 #define DDB_PORT_CI             1
154 #define DDB_PORT_TUNER          2
155 	u32                    type;
156 #define DDB_TUNER_NONE          0
157 #define DDB_TUNER_DVBS_ST       1
158 #define DDB_TUNER_DVBS_ST_AA    2
159 #define DDB_TUNER_DVBCT_TR     16
160 #define DDB_TUNER_DVBCT_ST     17
161 #define DDB_TUNER_XO2_DVBS_STV0910	32
162 #define DDB_TUNER_XO2_DVBCT2_SONY	33
163 #define DDB_TUNER_XO2_ISDBT_SONY	34
164 #define DDB_TUNER_XO2_DVBC2T2_SONY	35
165 #define DDB_TUNER_XO2_ATSC_ST		36
166 #define DDB_TUNER_XO2_DVBC2T2I_SONY	37
167 
168 	u32                    adr;
169 
170 	struct ddb_input      *input[2];
171 	struct ddb_output     *output;
172 	struct dvb_ca_en50221 *en;
173 };
174 
175 struct ddb {
176 	struct pci_dev        *pdev;
177 	unsigned char __iomem *regs;
178 	struct ddb_port        port[DDB_MAX_PORT];
179 	struct ddb_i2c         i2c[DDB_MAX_I2C];
180 	struct ddb_input       input[DDB_MAX_INPUT];
181 	struct ddb_output      output[DDB_MAX_OUTPUT];
182 
183 	struct device         *ddb_dev;
184 	int                    nr;
185 	u8                     iobuf[1028];
186 
187 	struct ddb_info       *info;
188 	int                    msi;
189 };
190 
191 /****************************************************************************/
192 
193 #define ddbwritel(_val, _adr)        writel((_val), \
194 				     dev->regs+(_adr))
195 #define ddbreadl(_adr)               readl(dev->regs+(_adr))
196 #define ddbcpyto(_adr, _src, _count) memcpy_toio(dev->regs+(_adr), (_src), (_count))
197 #define ddbcpyfrom(_dst, _adr, _count) memcpy_fromio((_dst), dev->regs+(_adr), (_count))
198 
199 /****************************************************************************/
200 
201 #endif
202