VServer 1.9.2 (patch-2.6.8.1-vs1.9.2.diff)
[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,4)
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_MASTER 7
125 #define CX88_BOARD_WINFAST_DV2000        8
126 #define CX88_BOARD_LEADTEK_PVR2000       9
127 #define CX88_BOARD_IODATA_GVVCP3PCI      10
128 #define CX88_BOARD_PROLINK_PLAYTVPVR     11
129 #define CX88_BOARD_ASUS_PVR_416          12
130 #define CX88_BOARD_MSI_TVANYWHERE        13
131
132 enum cx88_itype {
133         CX88_VMUX_COMPOSITE1 = 1,
134         CX88_VMUX_COMPOSITE2 = 2,
135         CX88_VMUX_COMPOSITE3 = 3,
136         CX88_VMUX_COMPOSITE4 = 4,
137         CX88_VMUX_TELEVISION = 5,
138         CX88_VMUX_SVIDEO     = 6,
139         CX88_VMUX_DEBUG      = 7,
140         CX88_RADIO           = 8,
141 };
142
143 struct cx88_input {
144         enum cx88_itype type;
145         unsigned int    vmux;
146         u32             gpio0, gpio1, gpio2, gpio3;
147 };
148
149 struct cx88_board {
150         char                    *name;
151         unsigned int            tuner_type;
152         int                     needs_tda9887:1;
153         struct cx88_input       input[8];
154         struct cx88_input       radio;
155 };
156
157 struct cx88_subid {
158         u16     subvendor;
159         u16     subdevice;
160         u32     card;
161 };
162
163 #define INPUT(nr) (&cx88_boards[dev->board].input[nr])
164
165 /* ----------------------------------------------------------- */
166 /* device / file handle status                                 */
167
168 #define RESOURCE_OVERLAY       1
169 #define RESOURCE_VIDEO         2
170 #define RESOURCE_VBI           4
171
172 //#define BUFFER_TIMEOUT     (HZ/2)  /* 0.5 seconds */
173 #define BUFFER_TIMEOUT     (HZ*2)
174
175 struct cx8800_dev;
176
177 /* buffer for one video frame */
178 struct cx88_buffer {
179         /* common v4l buffer stuff -- must be first */
180         struct videobuf_buffer vb;
181
182         /* cx88 specific */
183         unsigned int           bpl;
184         struct btcx_riscmem    risc;
185         struct cx8800_fmt      *fmt;
186         u32                    count;
187 };
188
189 struct cx88_dmaqueue {
190         struct list_head       active;
191         struct list_head       queued;
192         struct timer_list      timeout;
193         struct btcx_riscmem    stopper;
194         u32                    count;
195 };
196
197 /* video filehandle status */
198 struct cx8800_fh {
199         struct cx8800_dev          *dev;
200         enum v4l2_buf_type         type;
201         int                        radio;
202         unsigned int               resources;
203
204         /* video overlay */
205         struct v4l2_window         win;
206         struct v4l2_clip           *clips;
207         unsigned int               nclips;
208
209         /* video capture */
210         struct cx8800_fmt          *fmt;
211         unsigned int               width,height;
212         struct videobuf_queue      vidq;
213
214         /* vbi capture */
215         struct videobuf_queue      vbiq;
216 };
217
218 struct cx8800_suspend_state {
219         u32                        pci_cfg[64 / sizeof(u32)];
220         int                        disabled;
221 };
222
223 /* global device status */
224 struct cx8800_dev {
225         struct list_head           devlist;
226         struct semaphore           lock;
227         spinlock_t                 slock;
228
229         /* various device info */
230         unsigned int               resources;
231         struct video_device        *video_dev;
232         struct video_device        *vbi_dev;
233         struct video_device        *radio_dev;
234
235         /* pci i/o */
236         char                       name[32];
237         struct pci_dev             *pci;
238         unsigned char              pci_rev,pci_lat;
239         u32                        *lmmio;
240         u8                         *bmmio;
241
242         /* config info */
243         unsigned int               board;
244         unsigned int               tuner_type;
245         unsigned int               has_radio;
246
247         /* i2c i/o */
248         struct i2c_adapter         i2c_adap;
249         struct i2c_algo_bit_data   i2c_algo;
250         struct i2c_client          i2c_client;
251         u32                        i2c_state, i2c_rc;
252
253         /* video overlay */
254         struct v4l2_framebuffer    fbuf;
255         struct cx88_buffer         *screen;
256
257         /* capture queues */
258         struct cx88_dmaqueue       vidq;
259         struct cx88_dmaqueue       vbiq;
260
261         /* various v4l controls */
262         struct cx8800_tvnorm       *tvnorm;
263         u32                        tvaudio;
264         u32                        input;
265         u32                        freq;
266
267         /* other global state info */
268         u32                         shadow[SHADOW_MAX];
269         int                         shutdown;
270         pid_t                       tpid;
271         struct completion           texit;
272         struct cx8800_suspend_state state;
273 };
274
275 /* ----------------------------------------------------------- */
276
277 #define cx_read(reg)             readl(dev->lmmio + ((reg)>>2))
278 #define cx_write(reg,value)      writel((value), dev->lmmio + ((reg)>>2));
279 #define cx_writeb(reg,value)     writeb((value), dev->bmmio + (reg));
280
281 #define cx_andor(reg,mask,value) \
282   writel((readl(dev->lmmio+((reg)>>2)) & ~(mask)) |\
283   ((value) & (mask)), dev->lmmio+((reg)>>2))
284 #define cx_set(reg,bit)          cx_andor((reg),(bit),(bit))
285 #define cx_clear(reg,bit)        cx_andor((reg),(bit),0)
286
287 #define cx_wait(d) { if (need_resched()) schedule(); else udelay(d); }
288
289 /* shadow registers */
290 #define cx_sread(sreg)              (dev->shadow[sreg])
291 #define cx_swrite(sreg,reg,value) \
292   (dev->shadow[sreg] = value, \
293    writel(dev->shadow[sreg], dev->lmmio + ((reg)>>2)))
294 #define cx_sandor(sreg,reg,mask,value) \
295   (dev->shadow[sreg] = (dev->shadow[sreg] & ~(mask)) | ((value) & (mask)), \
296    writel(dev->shadow[sreg], dev->lmmio + ((reg)>>2)))
297
298 /* ----------------------------------------------------------- */
299 /* cx88-core.c                                                 */
300
301 extern char *cx88_pci_irqs[32];
302 extern char *cx88_vid_irqs[32];
303 extern void cx88_print_irqbits(char *name, char *tag, char **strings,
304                                u32 bits, u32 mask);
305 extern void cx88_print_ioctl(char *name, unsigned int cmd);
306
307 extern int
308 cx88_risc_buffer(struct pci_dev *pci, struct btcx_riscmem *risc,
309                  struct scatterlist *sglist,
310                  unsigned int top_offset, unsigned int bottom_offset,
311                  unsigned int bpl, unsigned int padding, unsigned int lines);
312 extern int
313 cx88_risc_stopper(struct pci_dev *pci, struct btcx_riscmem *risc,
314                   u32 reg, u32 mask, u32 value);
315 extern void
316 cx88_free_buffer(struct pci_dev *pci, struct cx88_buffer *buf);
317
318 extern void cx88_risc_disasm(struct cx8800_dev *dev,
319                              struct btcx_riscmem *risc);
320
321 extern int cx88_sram_channel_setup(struct cx8800_dev *dev,
322                                    struct sram_channel *ch,
323                                    unsigned int bpl, u32 risc);
324 extern void cx88_sram_channel_dump(struct cx8800_dev *dev,
325                                    struct sram_channel *ch);
326
327 extern int cx88_pci_quirks(char *name, struct pci_dev *pci,
328                            unsigned int *latency);
329
330 /* ----------------------------------------------------------- */
331 /* cx88-vbi.c                                                  */
332
333 void cx8800_vbi_fmt(struct cx8800_dev *dev, struct v4l2_format *f);
334 int cx8800_start_vbi_dma(struct cx8800_dev    *dev,
335                          struct cx88_dmaqueue *q,
336                          struct cx88_buffer   *buf);
337 int cx8800_restart_vbi_queue(struct cx8800_dev    *dev,
338                              struct cx88_dmaqueue *q);
339 void cx8800_vbi_timeout(unsigned long data);
340
341 extern struct videobuf_queue_ops cx8800_vbi_qops;
342
343 /* ----------------------------------------------------------- */
344 /* cx88-i2c.c                                                  */
345
346 extern int cx8800_i2c_init(struct cx8800_dev *dev);
347 extern void cx8800_call_i2c_clients(struct cx8800_dev *dev,
348                                     unsigned int cmd, void *arg);
349
350
351 /* ----------------------------------------------------------- */
352 /* cx88-cards.c                                                */
353
354 extern struct cx88_board cx88_boards[];
355 extern const unsigned int cx88_bcount;
356
357 extern struct cx88_subid cx88_subids[];
358 extern const unsigned int cx88_idcount;
359
360 extern void cx88_card_list(struct cx8800_dev *dev);
361 extern void cx88_card_setup(struct cx8800_dev *dev);
362
363 /* ----------------------------------------------------------- */
364 /* cx88-tvaudio.c                                              */
365
366 #define WW_NONE          1
367 #define WW_BTSC          2
368 #define WW_NICAM_I       3
369 #define WW_NICAM_BGDKL   4
370 #define WW_A1            5
371 #define WW_A2_BG         6
372 #define WW_A2_DK         7
373 #define WW_A2_M          8
374 #define WW_EIAJ          9
375 #define WW_SYSTEM_L_AM  10
376 #define WW_I2SPT        11
377 #define WW_FM           12
378
379 void cx88_set_tvaudio(struct cx8800_dev *dev);
380 void cx88_get_stereo(struct cx8800_dev *dev, struct v4l2_tuner *t);
381 void cx88_set_stereo(struct cx8800_dev *dev, u32 mode);
382 int cx88_audio_thread(void *data);
383
384 /*
385  * Local variables:
386  * c-basic-offset: 8
387  * End:
388  */