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 
47 struct ddb_info {
48 	int   type;
49 #define DDB_NONE         0
50 #define DDB_OCTOPUS      1
51 	char *name;
52 	int   port_num;
53 	u32   port_type[DDB_MAX_PORT];
54 };
55 
56 /* DMA_SIZE MUST be divisible by 188 and 128 !!! */
57 
58 #define INPUT_DMA_MAX_BUFS 32      /* hardware table limit */
59 #define INPUT_DMA_BUFS 8
60 #define INPUT_DMA_SIZE (128*47*21)
61 
62 #define OUTPUT_DMA_MAX_BUFS 32
63 #define OUTPUT_DMA_BUFS 8
64 #define OUTPUT_DMA_SIZE (128*47*21)
65 
66 struct ddb;
67 struct ddb_port;
68 
69 struct ddb_input {
70 	struct ddb_port       *port;
71 	u32                    nr;
72 	int                    attached;
73 
74 	dma_addr_t             pbuf[INPUT_DMA_MAX_BUFS];
75 	u8                    *vbuf[INPUT_DMA_MAX_BUFS];
76 	u32                    dma_buf_num;
77 	u32                    dma_buf_size;
78 
79 	struct tasklet_struct  tasklet;
80 	spinlock_t             lock;
81 	wait_queue_head_t      wq;
82 	int                    running;
83 	u32                    stat;
84 	u32                    cbuf;
85 	u32                    coff;
86 
87 	struct dvb_adapter     adap;
88 	struct dvb_device     *dev;
89 	struct dvb_frontend   *fe;
90 	struct dvb_frontend   *fe2;
91 	struct dmxdev          dmxdev;
92 	struct dvb_demux       demux;
93 	struct dvb_net         dvbnet;
94 	struct dmx_frontend    hw_frontend;
95 	struct dmx_frontend    mem_frontend;
96 	int                    users;
97 	int (*gate_ctrl)(struct dvb_frontend *, int);
98 };
99 
100 struct ddb_output {
101 	struct ddb_port       *port;
102 	u32                    nr;
103 	dma_addr_t             pbuf[OUTPUT_DMA_MAX_BUFS];
104 	u8                    *vbuf[OUTPUT_DMA_MAX_BUFS];
105 	u32                    dma_buf_num;
106 	u32                    dma_buf_size;
107 	struct tasklet_struct  tasklet;
108 	spinlock_t             lock;
109 	wait_queue_head_t      wq;
110 	int                    running;
111 	u32                    stat;
112 	u32                    cbuf;
113 	u32                    coff;
114 
115 	struct dvb_adapter     adap;
116 	struct dvb_device     *dev;
117 };
118 
119 struct ddb_i2c {
120 	struct ddb            *dev;
121 	u32                    nr;
122 	struct i2c_adapter     adap;
123 	struct i2c_adapter     adap2;
124 	u32                    regs;
125 	u32                    rbuf;
126 	u32                    wbuf;
127 	int                    done;
128 	wait_queue_head_t      wq;
129 };
130 
131 struct ddb_port {
132 	struct ddb            *dev;
133 	u32                    nr;
134 	struct ddb_i2c        *i2c;
135 	struct mutex           i2c_gate_lock;
136 	u32                    class;
137 #define DDB_PORT_NONE           0
138 #define DDB_PORT_CI             1
139 #define DDB_PORT_TUNER          2
140 	u32                    type;
141 #define DDB_TUNER_NONE          0
142 #define DDB_TUNER_DVBS_ST       1
143 #define DDB_TUNER_DVBS_ST_AA    2
144 #define DDB_TUNER_DVBCT_TR     16
145 #define DDB_TUNER_DVBCT_ST     17
146 	u32                    adr;
147 
148 	struct ddb_input      *input[2];
149 	struct ddb_output     *output;
150 	struct dvb_ca_en50221 *en;
151 };
152 
153 struct ddb {
154 	struct pci_dev        *pdev;
155 	unsigned char __iomem *regs;
156 	struct ddb_port        port[DDB_MAX_PORT];
157 	struct ddb_i2c         i2c[DDB_MAX_I2C];
158 	struct ddb_input       input[DDB_MAX_INPUT];
159 	struct ddb_output      output[DDB_MAX_OUTPUT];
160 
161 	struct device         *ddb_dev;
162 	int                    nr;
163 	u8                     iobuf[1028];
164 
165 	struct ddb_info       *info;
166 	int                    msi;
167 };
168 
169 /****************************************************************************/
170 
171 #define ddbwritel(_val, _adr)        writel((_val), \
172 				     dev->regs+(_adr))
173 #define ddbreadl(_adr)               readl(dev->regs+(_adr))
174 #define ddbcpyto(_adr, _src, _count) memcpy_toio(dev->regs+(_adr), (_src), (_count))
175 #define ddbcpyfrom(_dst, _adr, _count) memcpy_fromio((_dst), dev->regs+(_adr), (_count))
176 
177 /****************************************************************************/
178 
179 #endif
180