V4L/DVB (6192): Ensure start_dma() is capable of starting dma on port VIDB
[linux-2.6] / drivers / media / video / cx23885 / cx23885.h
1 /*
2  *  Driver for the Conexant CX23885 PCIe bridge
3  *
4  *  Copyright (c) 2006 Steven Toth <stoth@hauppauge.com>
5  *
6  *  This program is free software; you can redistribute it and/or modify
7  *  it under the terms of the GNU General Public License as published by
8  *  the Free Software Foundation; either version 2 of the License, or
9  *  (at your option) any later version.
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  *
15  *  GNU General Public License for more details.
16  *
17  *  You should have received a copy of the GNU General Public License
18  *  along with this program; if not, write to the Free Software
19  *  Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
20  */
21
22 #include <linux/pci.h>
23 #include <linux/i2c.h>
24 #include <linux/i2c-algo-bit.h>
25 #include <linux/kdev_t.h>
26
27 #include <media/v4l2-common.h>
28 #include <media/tuner.h>
29 #include <media/tveeprom.h>
30 #include <media/video-buf.h>
31 #if defined(CONFIG_VIDEO_BUF_DVB) || defined(CONFIG_VIDEO_BUF_DVB_MODULE)
32 #include <media/video-buf-dvb.h>
33 #endif
34
35 #include "btcx-risc.h"
36 #include "cx23885-reg.h"
37
38 #include <linux/version.h>
39 #include <linux/mutex.h>
40
41 #define CX23885_VERSION_CODE KERNEL_VERSION(0,0,1)
42
43 #define UNSET (-1U)
44
45 #define CX23885_MAXBOARDS 8
46
47 /* Max number of inputs by card */
48 #define MAX_CX23885_INPUT 8
49
50 #define BUFFER_TIMEOUT     (HZ)  /* 0.5 seconds */
51
52 #define CX23885_BOARD_NOAUTO               UNSET
53 #define CX23885_BOARD_UNKNOWN                  0
54 #define CX23885_BOARD_HAUPPAUGE_HVR1800lp      1
55 #define CX23885_BOARD_HAUPPAUGE_HVR1800        2
56 #define CX23885_BOARD_HAUPPAUGE_HVR1250        3
57
58 enum cx23885_itype {
59         CX23885_VMUX_COMPOSITE1 = 1,
60         CX23885_VMUX_COMPOSITE2,
61         CX23885_VMUX_COMPOSITE3,
62         CX23885_VMUX_COMPOSITE4,
63         CX23885_VMUX_SVIDEO,
64         CX23885_VMUX_TELEVISION,
65         CX23885_VMUX_CABLE,
66         CX23885_VMUX_DVB,
67         CX23885_VMUX_DEBUG,
68         CX23885_RADIO,
69 };
70
71 /* buffer for one video frame */
72 struct cx23885_buffer {
73         /* common v4l buffer stuff -- must be first */
74         struct videobuf_buffer vb;
75
76         /* cx23885 specific */
77         unsigned int           bpl;
78         struct btcx_riscmem    risc;
79         struct cx23885_fmt     *fmt;
80         u32                    count;
81 };
82
83 struct cx23885_input {
84         enum cx23885_itype type;
85         unsigned int    vmux;
86         u32             gpio0, gpio1, gpio2, gpio3;
87 };
88
89 typedef enum {
90         CX23885_MPEG_UNDEFINED = 0,
91         CX23885_MPEG_DVB
92 } port_t;
93
94 struct cx23885_board {
95         char                    *name;
96         port_t                  portb, portc;
97         struct cx23885_input    input[MAX_CX23885_INPUT];
98 };
99
100 struct cx23885_subid {
101         u16     subvendor;
102         u16     subdevice;
103         u32     card;
104 };
105
106 struct cx23885_i2c {
107         struct cx23885_dev *dev;
108
109         int                        nr;
110
111         /* i2c i/o */
112         struct i2c_adapter         i2c_adap;
113         struct i2c_algo_bit_data   i2c_algo;
114         struct i2c_client          i2c_client;
115         u32                        i2c_rc;
116
117         /* 885 registers used for raw addess */
118         u32                        i2c_period;
119         u32                        reg_ctrl;
120         u32                        reg_stat;
121         u32                        reg_addr;
122         u32                        reg_rdata;
123         u32                        reg_wdata;
124 };
125
126 struct cx23885_dmaqueue {
127         struct list_head       active;
128         struct list_head       queued;
129         struct timer_list      timeout;
130         struct btcx_riscmem    stopper;
131         u32                    count;
132 };
133
134 struct cx23885_tsport {
135         struct cx23885_dev *dev;
136
137         int                        nr;
138         int                        sram_chno;
139
140         struct videobuf_dvb        dvb;
141
142         /* dma queues */
143         struct cx23885_dmaqueue    mpegq;
144         u32                        ts_packet_size;
145         u32                        ts_packet_count;
146
147         int                        width;
148         int                        height;
149
150         spinlock_t                 slock;
151
152         /* registers */
153         u32                        reg_gpcnt;
154         u32                        reg_gpcnt_ctl;
155         u32                        reg_dma_ctl;
156         u32                        reg_lngth;
157         u32                        reg_hw_sop_ctrl;
158         u32                        reg_gen_ctrl;
159         u32                        reg_bd_pkt_status;
160         u32                        reg_sop_status;
161         u32                        reg_fifo_ovfl_stat;
162         u32                        reg_vld_misc;
163         u32                        reg_ts_clk_en;
164         u32                        reg_ts_int_msk;
165
166         /* Default register vals */
167         int                        pci_irqmask;
168         u32                        dma_ctl_val;
169         u32                        ts_int_msk_val;
170         u32                        gen_ctrl_val;
171         u32                        ts_clk_en_val;
172 };
173
174 struct cx23885_dev {
175         struct list_head           devlist;
176         atomic_t                   refcount;
177
178         /* pci stuff */
179         struct pci_dev             *pci;
180         unsigned char              pci_rev, pci_lat;
181         int                        pci_bus, pci_slot;
182         u32                        __iomem *lmmio;
183         u8                         __iomem *bmmio;
184         int                        pci_irqmask;
185
186         /* I2C adapters: Master 1 & 2 (External) & Master 3 (Internal only) */
187         struct cx23885_i2c         i2c_bus[3];
188
189         int                        nr;
190         struct mutex               lock;
191
192         /* board details */
193         unsigned int               board;
194         char                       name[32];
195
196         struct cx23885_tsport      ts2;
197
198         /* sram configuration */
199         struct sram_channel        *sram_channels;
200
201         enum {
202                 CX23885_BRIDGE_UNDEFINED = 0,
203                 CX23885_BRIDGE_885 = 885,
204                 CX23885_BRIDGE_887 = 887,
205         } bridge;
206 };
207
208 #define SRAM_CH01  0 /* Video A */
209 #define SRAM_CH02  1 /* VBI A */
210 #define SRAM_CH03  2 /* Video B */
211 #define SRAM_CH04  3 /* Transport via B */
212 #define SRAM_CH05  4 /* VBI B */
213 #define SRAM_CH06  5 /* Video C */
214 #define SRAM_CH07  6 /* Transport via C */
215 #define SRAM_CH08  7 /* Audio Internal A */
216 #define SRAM_CH09  8 /* Audio Internal B */
217 #define SRAM_CH10  9 /* Audio External */
218 #define SRAM_CH11 10 /* COMB_3D_N */
219 #define SRAM_CH12 11 /* Comb 3D N1 */
220 #define SRAM_CH13 12 /* Comb 3D N2 */
221 #define SRAM_CH14 13 /* MOE Vid */
222 #define SRAM_CH15 14 /* MOE RSLT */
223
224 struct sram_channel {
225         char *name;
226         u32  cmds_start;
227         u32  ctrl_start;
228         u32  cdt;
229         u32  fifo_start;;
230         u32  fifo_size;
231         u32  ptr1_reg;
232         u32  ptr2_reg;
233         u32  cnt1_reg;
234         u32  cnt2_reg;
235         u32  jumponly;
236 };
237
238 /* ----------------------------------------------------------- */
239
240 #define cx_read(reg)             readl(dev->lmmio + ((reg)>>2))
241 #define cx_write(reg,value)      writel((value), dev->lmmio + ((reg)>>2))
242
243 #define cx_andor(reg,mask,value) \
244   writel((readl(dev->lmmio+((reg)>>2)) & ~(mask)) |\
245   ((value) & (mask)), dev->lmmio+((reg)>>2))
246
247 #define cx_set(reg,bit)          cx_andor((reg),(bit),(bit))
248 #define cx_clear(reg,bit)        cx_andor((reg),(bit),0)
249
250 extern int cx23885_sram_channel_setup(struct cx23885_dev *dev,
251         struct sram_channel *ch,
252         unsigned int bpl, u32 risc);
253
254 /* ----------------------------------------------------------- */
255 /* cx23885-cards.c                                                */
256
257 extern struct cx23885_board cx23885_boards[];
258 extern const unsigned int cx23885_bcount;
259
260 extern struct cx23885_subid cx23885_subids[];
261 extern const unsigned int cx23885_idcount;
262
263 extern void cx23885_card_list(struct cx23885_dev *dev);
264 extern void cx23885_card_setup(struct cx23885_dev *dev);
265 extern void cx23885_card_setup_pre_i2c(struct cx23885_dev *dev);
266
267 extern int cx23885_dvb_register(struct cx23885_tsport *port);
268 extern int cx23885_dvb_unregister(struct cx23885_tsport *port);
269
270 extern int cx23885_buf_prepare(struct videobuf_queue *q,
271                                struct cx23885_tsport *port,
272                                struct cx23885_buffer *buf,
273                                enum v4l2_field field);
274
275 extern void cx23885_buf_queue(struct cx23885_tsport *port,
276                               struct cx23885_buffer *buf);
277 extern void cx23885_free_buffer(struct videobuf_queue *q,
278                                 struct cx23885_buffer *buf);
279
280 /* ----------------------------------------------------------- */
281 /* cx23885-i2c.c                                                */
282 extern int cx23885_i2c_register(struct cx23885_i2c *bus);
283 extern int cx23885_i2c_unregister(struct cx23885_i2c *bus);
284 extern void cx23885_call_i2c_clients(struct cx23885_i2c *bus, unsigned int cmd,
285                                      void *arg);
286
287 /*
288  * Local variables:
289  * c-basic-offset: 8
290  * End:
291  * kate: eol "unix"; indent-width 3; remove-trailing-space on; replace-trailing-space-save on; tab-width 8; replace-tabs off; space-indent off; mixed-indent off
292  */