ftp://ftp.kernel.org/pub/linux/kernel/v2.6/linux-2.6.6.tar.bz2
[linux-2.6.git] / drivers / media / video / cx88 / cx88.h
1 /*
2  * v4l2 device driver for cx2388x based TV cards
3  *
4  * (c) 2003,04 Gerd Knorr <kraxel@bytesex.org> [SUSE Labs]
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  *  GNU General Public License for more details.
15  *
16  *  You should have received a copy of the GNU General Public License
17  *  along with this program; if not, write to the Free Software
18  *  Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
19  */
20
21 #include <linux/pci.h>
22 #include <linux/i2c.h>
23 #include <linux/i2c-algo-bit.h>
24 #include <linux/videodev.h>
25 #include <linux/kdev_t.h>
26
27 #include <media/video-buf.h>
28 #include <media/tuner.h>
29 #include <media/audiochip.h>
30
31 #include "btcx-risc.h"
32 #include "cx88-reg.h"
33
34 #include <linux/version.h>
35 #define CX88_VERSION_CODE KERNEL_VERSION(0,0,3)
36
37 #ifndef TRUE
38 # define TRUE (1==1)
39 #endif
40 #ifndef FALSE
41 # define FALSE (1==0)
42 #endif
43 #define UNSET (-1U)
44
45 #define CX88_MAXBOARDS 8
46
47 /* ----------------------------------------------------------- */
48 /* defines and enums                                           */
49
50 #define FORMAT_FLAGS_PACKED       0x01
51 #define FORMAT_FLAGS_PLANAR       0x02
52
53 #define VBI_LINE_COUNT              17
54 #define VBI_LINE_LENGTH           2048
55
56 /* need "shadow" registers for some write-only ones ... */
57 #define SHADOW_AUD_VOL_CTL           1
58 #define SHADOW_AUD_BAL_CTL           2
59 #define SHADOW_MAX                   2
60
61 /* ----------------------------------------------------------- */
62 /* static data                                                 */
63
64 struct cx8800_tvnorm {
65         char                   *name;
66         v4l2_std_id            id;
67         u32                    cxiformat;
68         u32                    cxoformat;
69 };
70
71 struct cx8800_fmt {
72         char  *name;
73         u32   fourcc;          /* v4l2 format id */
74         int   depth;
75         int   flags;
76         u32   cxformat;
77 };
78
79 struct cx88_ctrl {
80         struct v4l2_queryctrl  v;
81         u32                    off;
82         u32                    reg;
83         u32                    sreg;
84         u32                    mask;
85         u32                    shift;
86 };
87
88 /* ----------------------------------------------------------- */
89 /* SRAM memory management data (see cx88-core.c)               */
90
91 #define SRAM_CH21 0   /* video */
92 #define SRAM_CH22 1
93 #define SRAM_CH23 2
94 #define SRAM_CH24 3   /* vbi   */
95 #define SRAM_CH25 4   /* audio */
96 #define SRAM_CH26 5
97 /* more */
98
99 struct sram_channel {
100         char *name;
101         u32  cmds_start;
102         u32  ctrl_start;
103         u32  cdt;
104         u32  fifo_start;
105         u32  fifo_size;
106         u32  ptr1_reg;
107         u32  ptr2_reg;
108         u32  cnt1_reg;
109         u32  cnt2_reg;
110 };
111 extern struct sram_channel cx88_sram_channels[];
112
113 /* ----------------------------------------------------------- */
114 /* card configuration                                          */
115
116 #define CX88_BOARD_NOAUTO        UNSET
117 #define CX88_BOARD_UNKNOWN           0
118 #define CX88_BOARD_HAUPPAUGE         1
119 #define CX88_BOARD_GDI               2
120 #define CX88_BOARD_PIXELVIEW         3
121 #define CX88_BOARD_ATI_WONDER_PRO    4
122 #define CX88_BOARD_WINFAST2000XP     5
123 #define CX88_BOARD_AVERTV_303        6
124 #define CX88_BOARD_MSI_TVANYWHERE    7
125 #define CX88_BOARD_WINFAST_DV2000    8
126 #define CX88_BOARD_LEADTEK_PVR2000   9
127
128
129 enum cx88_itype {
130         CX88_VMUX_COMPOSITE1 = 1,
131         CX88_VMUX_COMPOSITE2 = 2,
132         CX88_VMUX_COMPOSITE3 = 3,
133         CX88_VMUX_COMPOSITE4 = 4,
134         CX88_VMUX_TELEVISION = 5,
135         CX88_VMUX_SVIDEO     = 6,
136         CX88_VMUX_DEBUG      = 7,
137         CX88_RADIO           = 8,
138 };
139
140 struct cx88_input {
141         enum cx88_itype type;
142         unsigned int    vmux;
143         u32             gpio0, gpio1, gpio2, gpio3;
144 };
145
146 struct cx88_board {
147         char                    *name;
148         unsigned int            tuner_type;
149         int                     needs_tda9887:1;
150         struct cx88_input       input[8];
151         struct cx88_input       radio;
152 };
153
154 struct cx88_subid {
155         u16     subvendor;
156         u16     subdevice;
157         u32     card;
158 };
159
160 #define INPUT(nr) (&cx88_boards[dev->board].input[nr])
161
162 /* ----------------------------------------------------------- */
163 /* device / file handle status                                 */
164
165 #define RESOURCE_OVERLAY       1
166 #define RESOURCE_VIDEO         2
167 #define RESOURCE_VBI           4
168
169 //#define BUFFER_TIMEOUT     (HZ/2)  /* 0.5 seconds */
170 #define BUFFER_TIMEOUT     (HZ*2)
171
172 struct cx8800_dev;
173
174 /* buffer for one video frame */
175 struct cx88_buffer {
176         /* common v4l buffer stuff -- must be first */
177         struct videobuf_buffer vb;
178
179         /* cx88 specific */
180         unsigned int           bpl;
181         struct btcx_riscmem    risc;
182         struct cx8800_fmt      *fmt;
183         u32                    count;
184 };
185
186 struct cx88_dmaqueue {
187         struct list_head       active;
188         struct list_head       queued;
189         struct timer_list      timeout;
190         struct btcx_riscmem    stopper;
191         u32                    count;
192 };
193
194 /* video filehandle status */
195 struct cx8800_fh {
196         struct cx8800_dev          *dev;
197         enum v4l2_buf_type         type;
198         int                        radio;
199         unsigned int               resources;
200
201         /* video overlay */
202         struct v4l2_window         win;
203         struct v4l2_clip           *clips;
204         unsigned int               nclips;
205
206         /* video capture */
207         struct cx8800_fmt          *fmt;
208         unsigned int               width,height;
209         struct videobuf_queue      vidq;
210
211         /* vbi capture */
212         struct videobuf_queue      vbiq;
213 };
214
215 struct cx8800_suspend_state {
216         u32                        pci_cfg[64 / sizeof(u32)];
217         int                        disabled;
218 };
219
220 /* global device status */
221 struct cx8800_dev {
222         struct list_head           devlist;
223         struct semaphore           lock;
224         spinlock_t                 slock;
225
226         /* various device info */
227         unsigned int               resources;
228         struct video_device        *video_dev;
229         struct video_device        *vbi_dev;
230         struct video_device        *radio_dev;
231
232         /* pci i/o */
233         char                       name[32];
234         struct pci_dev             *pci;
235         unsigned char              pci_rev,pci_lat;
236         u32                        *lmmio;
237         u8                         *bmmio;
238
239         /* config info */
240         unsigned int               board;
241         unsigned int               tuner_type;
242         unsigned int               has_radio;
243
244         /* i2c i/o */
245         struct i2c_adapter         i2c_adap;
246         struct i2c_algo_bit_data   i2c_algo;
247         struct i2c_client          i2c_client;
248         u32                        i2c_state, i2c_rc;
249
250         /* video overlay */
251         struct v4l2_framebuffer    fbuf;
252         struct cx88_buffer         *screen;
253
254         /* capture queues */
255         struct cx88_dmaqueue       vidq;
256         struct cx88_dmaqueue       vbiq;
257
258         /* various v4l controls */
259         struct cx8800_tvnorm       *tvnorm;
260         u32                        tvaudio;
261         u32                        input;
262         u32                        freq;
263
264         /* other global state info */
265         u32                         shadow[SHADOW_MAX];
266         struct cx8800_suspend_state state;
267 };
268
269 /* ----------------------------------------------------------- */
270
271 #define cx_read(reg)             readl(dev->lmmio + ((reg)>>2))
272 #define cx_write(reg,value)      writel((value), dev->lmmio + ((reg)>>2));
273 #define cx_writeb(reg,value)     writeb((value), dev->bmmio + (reg));
274
275 #define cx_andor(reg,mask,value) \
276   writel((readl(dev->lmmio+((reg)>>2)) & ~(mask)) |\
277   ((value) & (mask)), dev->lmmio+((reg)>>2))
278 #define cx_set(reg,bit)          cx_andor((reg),(bit),(bit))
279 #define cx_clear(reg,bit)        cx_andor((reg),(bit),0)
280
281 #define cx_wait(d) { if (need_resched()) schedule(); else udelay(d); }
282
283 /* shadow registers */
284 #define cx_sread(sreg)              (dev->shadow[sreg])
285 #define cx_swrite(sreg,reg,value) \
286   (dev->shadow[sreg] = value, \
287    writel(dev->shadow[sreg], dev->lmmio + ((reg)>>2)))
288 #define cx_sandor(sreg,reg,mask,value) \
289   (dev->shadow[sreg] = (dev->shadow[sreg] & ~(mask)) | ((value) & (mask)), \
290    writel(dev->shadow[sreg], dev->lmmio + ((reg)>>2)))
291
292 /* ----------------------------------------------------------- */
293 /* cx88-core.c                                                 */
294
295 extern char *cx88_pci_irqs[32];
296 extern char *cx88_vid_irqs[32];
297 extern void cx88_print_irqbits(char *name, char *tag, char **strings,
298                                u32 bits, u32 mask);
299 extern void cx88_print_ioctl(char *name, unsigned int cmd);
300
301 extern int
302 cx88_risc_buffer(struct pci_dev *pci, struct btcx_riscmem *risc,
303                  struct scatterlist *sglist,
304                  unsigned int top_offset, unsigned int bottom_offset,
305                  unsigned int bpl, unsigned int padding, unsigned int lines);
306 extern int
307 cx88_risc_stopper(struct pci_dev *pci, struct btcx_riscmem *risc,
308                   u32 reg, u32 mask, u32 value);
309 extern void
310 cx88_free_buffer(struct pci_dev *pci, struct cx88_buffer *buf);
311
312 extern void cx88_risc_disasm(struct cx8800_dev *dev,
313                              struct btcx_riscmem *risc);
314
315 extern int cx88_sram_channel_setup(struct cx8800_dev *dev,
316                                    struct sram_channel *ch,
317                                    unsigned int bpl, u32 risc);
318 extern void cx88_sram_channel_dump(struct cx8800_dev *dev,
319                                    struct sram_channel *ch);
320
321 extern int cx88_pci_quirks(char *name, struct pci_dev *pci,
322                            unsigned int *latency);
323
324 /* ----------------------------------------------------------- */
325 /* cx88-vbi.c                                                  */
326
327 void cx8800_vbi_fmt(struct cx8800_dev *dev, struct v4l2_format *f);
328 int cx8800_start_vbi_dma(struct cx8800_dev    *dev,
329                          struct cx88_dmaqueue *q,
330                          struct cx88_buffer   *buf);
331 int cx8800_restart_vbi_queue(struct cx8800_dev    *dev,
332                              struct cx88_dmaqueue *q);
333 void cx8800_vbi_timeout(unsigned long data);
334
335 extern struct videobuf_queue_ops cx8800_vbi_qops;
336
337 /* ----------------------------------------------------------- */
338 /* cx88-i2c.c                                                  */
339
340 extern int cx8800_i2c_init(struct cx8800_dev *dev);
341 extern void cx8800_call_i2c_clients(struct cx8800_dev *dev,
342                                     unsigned int cmd, void *arg);
343
344
345 /* ----------------------------------------------------------- */
346 /* cx88-cards.c                                                */
347
348 extern struct cx88_board cx88_boards[];
349 extern const unsigned int cx88_bcount;
350
351 extern struct cx88_subid cx88_subids[];
352 extern const unsigned int cx88_idcount;
353
354 extern void __devinit cx88_card_setup(struct cx8800_dev *dev);
355
356 /* ----------------------------------------------------------- */
357 /* cx88-tvaudio.c                                              */
358
359 #define WW_NONE          1
360 #define WW_BTSC          2
361 #define WW_NICAM_I       3
362 #define WW_NICAM_BGDKL   4
363 #define WW_A1            5
364 #define WW_A2_BG         6
365 #define WW_A2_DK         7
366 #define WW_A2_M          8
367 #define WW_EIAJ          9
368 #define WW_SYSTEM_L_AM  10
369 #define WW_I2SPT        11
370 #define WW_FM           12
371
372 void cx88_set_tvaudio(struct cx8800_dev *dev);
373 void cx88_get_stereo(struct cx8800_dev *dev, struct v4l2_tuner *t);
374 void cx88_set_stereo(struct cx8800_dev *dev, u32 mode);
375
376 /*
377  * Local variables:
378  * c-basic-offset: 8
379  * End:
380  */