]> pilppa.org Git - linux-2.6-omap-h63xx.git/blob - drivers/media/video/cx23885/cx23885.h
769a0e7541c07fbc37352c500d77d4288ce8c47a
[linux-2.6-omap-h63xx.git] / 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 CX88_VERSION_CODE KERNEL_VERSION(0,0,6)
42
43 #define UNSET (-1U)
44
45 #define CX23885_MAXBOARDS 8
46
47 #define SRAM 0
48
49 /* Max number of inputs by card */
50 #define MAX_CX23885_INPUT 8
51
52 //#define SHADOW_MAX 3
53
54 #define BUFFER_TIMEOUT     (HZ)  /* 0.5 seconds */
55
56 #define CX23885_BOARD_NOAUTO               UNSET
57 #define CX23885_BOARD_UNKNOWN                  0
58 #define CX23885_BOARD_HAUPPAUGE_HVR1800lp      1
59 #define CX23885_BOARD_HAUPPAUGE_HVR1800        2
60
61 enum cx23885_itype {
62         CX23885_VMUX_COMPOSITE1 = 1,
63         CX23885_VMUX_COMPOSITE2,
64         CX23885_VMUX_COMPOSITE3,
65         CX23885_VMUX_COMPOSITE4,
66         CX23885_VMUX_SVIDEO,
67         CX23885_VMUX_TELEVISION,
68         CX23885_VMUX_CABLE,
69         CX23885_VMUX_DVB,
70         CX23885_VMUX_DEBUG,
71         CX23885_RADIO,
72 };
73
74 struct cx23885_fmt {
75         char  *name;
76         u32   fourcc;          /* v4l2 format id */
77         int   depth;
78         int   flags;
79         u32   cxformat;
80 };
81
82 /* buffer for one video frame */
83 struct cx23885_buffer {
84         /* common v4l buffer stuff -- must be first */
85         struct videobuf_buffer vb;
86
87         /* cx23885 specific */
88         unsigned int           bpl;
89         struct btcx_riscmem    risc;
90         struct cx23885_fmt     *fmt;
91         u32                    count;
92 };
93
94 struct cx23885_input {
95         enum cx23885_itype type;
96         unsigned int    vmux;
97         u32             gpio0, gpio1, gpio2, gpio3;
98 };
99
100 struct cx23885_board {
101         char                    *name;
102         enum {
103                 CX23885_MPEG_UNDEFINED = 0,
104                 CX23885_MPEG_DVB
105         } portc;
106         enum {
107                 CX23885_BRIDGE_UNDEFINED = 0,
108                 CX23885_BRIDGE_885 = 885,
109                 CX23885_BRIDGE_887 = 887,
110         } bridge;
111         struct cx23885_input    input[MAX_CX23885_INPUT];
112 };
113
114 struct cx23885_subid {
115         u16     subvendor;
116         u16     subdevice;
117         u32     card;
118 };
119
120 struct cx23885_i2c {
121         struct cx23885_dev *dev;
122
123         int                        nr;
124
125         /* i2c i/o */
126         struct i2c_adapter         i2c_adap;
127         struct i2c_algo_bit_data   i2c_algo;
128         struct i2c_client          i2c_client;
129         u32                        i2c_rc;
130
131         /* 885 registers used for raw addess */
132         u32                        i2c_period;
133         u32                        reg_ctrl;
134         u32                        reg_stat;
135         u32                        reg_addr;
136         u32                        reg_rdata;
137         u32                        reg_wdata;
138 };
139
140 struct cx23885_dmaqueue {
141         struct list_head       active;
142         struct list_head       queued;
143         struct timer_list      timeout;
144         struct btcx_riscmem    stopper;
145         u32                    count;
146 };
147
148 struct cx23885_tsport {
149         struct cx23885_dev *dev;
150
151         int                        nr;
152         int                        sram_chno;
153
154         struct videobuf_dvb        dvb;
155
156         /* dma queues */
157         struct cx23885_dmaqueue    mpegq;
158         u32                        ts_packet_size;
159         u32                        ts_packet_count;
160
161         int                        width;
162         int                        height;
163
164         spinlock_t                 slock;
165
166         /* registers */
167         u32                        reg_gpcnt;
168         u32                        reg_gpcnt_ctl;
169         u32                        reg_dma_ctl;
170         u32                        reg_lngth;
171         u32                        reg_hw_sop_ctrl;
172         u32                        reg_gen_ctrl;
173         u32                        reg_bd_pkt_status;
174         u32                        reg_sop_status;
175         u32                        reg_fifo_ovfl_stat;
176         u32                        reg_vld_misc;
177         u32                        reg_ts_clk_en;
178         u32                        reg_ts_int_msk;
179
180         /* Default register vals */
181         int                        pci_irqmask;
182         u32                        dma_ctl_val;
183         u32                        ts_int_msk_val;
184         u32                        gen_ctrl_val;
185         u32                        ts_clk_en_val;
186 };
187
188 struct cx23885_dev {
189         struct list_head           devlist;
190         atomic_t                   refcount;
191
192         /* pci stuff */
193         struct pci_dev             *pci;
194         unsigned char              pci_rev, pci_lat;
195         int                        pci_bus, pci_slot;
196         u32                        __iomem *lmmio;
197         u8                         __iomem *bmmio;
198         //u32                        shadow[SHADOW_MAX];
199         int                        pci_irqmask;
200
201         /* I2C adapters: Master 1 and 2 (External) and Master 3 (Internal only) */
202         struct cx23885_i2c         i2c_bus[3];
203
204         int                        nr;
205         struct mutex               lock;
206
207         /* board details */
208         unsigned int               board;
209         char                       name[32];
210
211         struct cx23885_tsport      ts2;
212
213         /* sram configuration */
214         struct sram_channel        *sram_channels;
215 };
216
217 #define SRAM_CH01  0 /* Video A */
218 #define SRAM_CH02  1 /* VBI A */
219 #define SRAM_CH03  2 /* Video B */
220 #define SRAM_CH04  3 /* Transport via B */
221 #define SRAM_CH05  4 /* VBI B */
222 #define SRAM_CH06  5 /* Video C */
223 #define SRAM_CH07  6 /* Transport via C */
224 #define SRAM_CH08  7 /* Audio Internal A */
225 #define SRAM_CH09  8 /* Audio Internal B */
226 #define SRAM_CH10  9 /* Audio External */
227 #define SRAM_CH11 10 /* COMB_3D_N */
228 #define SRAM_CH12 11 /* Comb 3D N1 */
229 #define SRAM_CH13 12 /* Comb 3D N2 */
230 #define SRAM_CH14 13 /* MOE Vid */
231 #define SRAM_CH15 14 /* MOE RSLT */
232
233 struct sram_channel {
234         char *name;
235         u32  cmds_start;
236         u32  ctrl_start;
237         u32  cdt;
238         u32  fifo_start;;
239         u32  fifo_size;
240         u32  ptr1_reg;
241         u32  ptr2_reg;
242         u32  cnt1_reg;
243         u32  cnt2_reg;
244         u32  jumponly;
245 };
246
247 /* ----------------------------------------------------------- */
248
249 #define cx_read(reg)             readl(dev->lmmio + ((reg)>>2))
250 #define cx_write(reg,value)      writel((value), dev->lmmio + ((reg)>>2))
251
252 #define cx_andor(reg,mask,value) \
253   writel((readl(dev->lmmio+((reg)>>2)) & ~(mask)) |\
254   ((value) & (mask)), dev->lmmio+((reg)>>2))
255
256 #define cx_set(reg,bit)          cx_andor((reg),(bit),(bit))
257 #define cx_clear(reg,bit)        cx_andor((reg),(bit),0)
258
259
260 extern int cx23885_sram_channel_setup(struct cx23885_dev *dev,
261         struct sram_channel *ch,
262         unsigned int bpl, u32 risc);
263
264 /* ----------------------------------------------------------- */
265 /* cx23885-cards.c                                                */
266
267 extern struct cx23885_board cx23885_boards[];
268 extern const unsigned int cx23885_bcount;
269
270 extern struct cx23885_subid cx23885_subids[];
271 extern const unsigned int cx23885_idcount;
272
273 extern void cx23885_card_list(struct cx23885_dev *dev);
274 extern void cx23885_card_setup(struct cx23885_dev *dev);
275 extern void cx23885_card_setup_pre_i2c(struct cx23885_dev *dev);
276
277 extern int cx23885_dvb_register(struct cx23885_tsport *port);
278 extern int cx23885_dvb_unregister(struct cx23885_tsport *port);
279
280 extern int cx23885_buf_prepare(struct videobuf_queue *q, struct cx23885_tsport *port,
281                         struct cx23885_buffer *buf, enum v4l2_field field);
282
283 extern void cx23885_buf_queue(struct cx23885_tsport *port, struct cx23885_buffer *buf);
284 extern void cx23885_free_buffer(struct videobuf_queue *q, struct cx23885_buffer *buf);
285
286 /* ----------------------------------------------------------- */
287 /* cx23885-i2c.c                                                */
288 extern int cx23885_i2c_register(struct cx23885_i2c *bus);
289 extern int cx23885_i2c_unregister(struct cx23885_i2c *bus);
290 extern void cx23885_call_i2c_clients(struct cx23885_i2c *bus, unsigned int cmd, void *arg);
291
292 /*
293  * Local variables:
294  * c-basic-offset: 8
295  * End:
296  * 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
297  */