2 * v4l2 device driver for cx2388x based TV cards
4 * (c) 2003,04 Gerd Knorr <kraxel@bytesex.org> [SUSE Labs]
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.
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.
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.
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>
27 #include <media/video-buf.h>
28 #include <media/tuner.h>
29 #include <media/audiochip.h>
31 #include "btcx-risc.h"
34 #include <linux/version.h>
35 #define CX88_VERSION_CODE KERNEL_VERSION(0,0,3)
45 #define CX88_MAXBOARDS 8
47 /* ----------------------------------------------------------- */
48 /* defines and enums */
50 #define FORMAT_FLAGS_PACKED 0x01
51 #define FORMAT_FLAGS_PLANAR 0x02
53 #define VBI_LINE_COUNT 17
54 #define VBI_LINE_LENGTH 2048
56 /* need "shadow" registers for some write-only ones ... */
57 #define SHADOW_AUD_VOL_CTL 1
58 #define SHADOW_AUD_BAL_CTL 2
61 /* ----------------------------------------------------------- */
64 struct cx8800_tvnorm {
73 u32 fourcc; /* v4l2 format id */
80 struct v4l2_queryctrl v;
88 /* ----------------------------------------------------------- */
89 /* SRAM memory management data (see cx88-core.c) */
91 #define SRAM_CH21 0 /* video */
94 #define SRAM_CH24 3 /* vbi */
95 #define SRAM_CH25 4 /* audio */
111 extern struct sram_channel cx88_sram_channels[];
113 /* ----------------------------------------------------------- */
114 /* card configuration */
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
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,
141 enum cx88_itype type;
143 u32 gpio0, gpio1, gpio2, gpio3;
148 unsigned int tuner_type;
150 struct cx88_input input[8];
151 struct cx88_input radio;
160 #define INPUT(nr) (&cx88_boards[dev->board].input[nr])
162 /* ----------------------------------------------------------- */
163 /* device / file handle status */
165 #define RESOURCE_OVERLAY 1
166 #define RESOURCE_VIDEO 2
167 #define RESOURCE_VBI 4
169 //#define BUFFER_TIMEOUT (HZ/2) /* 0.5 seconds */
170 #define BUFFER_TIMEOUT (HZ*2)
174 /* buffer for one video frame */
176 /* common v4l buffer stuff -- must be first */
177 struct videobuf_buffer vb;
181 struct btcx_riscmem risc;
182 struct cx8800_fmt *fmt;
186 struct cx88_dmaqueue {
187 struct list_head active;
188 struct list_head queued;
189 struct timer_list timeout;
190 struct btcx_riscmem stopper;
194 /* video filehandle status */
196 struct cx8800_dev *dev;
197 enum v4l2_buf_type type;
199 unsigned int resources;
202 struct v4l2_window win;
203 struct v4l2_clip *clips;
207 struct cx8800_fmt *fmt;
208 unsigned int width,height;
209 struct videobuf_queue vidq;
212 struct videobuf_queue vbiq;
215 struct cx8800_suspend_state {
216 u32 pci_cfg[64 / sizeof(u32)];
220 /* global device status */
222 struct list_head devlist;
223 struct semaphore lock;
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;
235 unsigned char pci_rev,pci_lat;
241 unsigned int tuner_type;
242 unsigned int has_radio;
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;
251 struct v4l2_framebuffer fbuf;
252 struct cx88_buffer *screen;
255 struct cx88_dmaqueue vidq;
256 struct cx88_dmaqueue vbiq;
258 /* various v4l controls */
259 struct cx8800_tvnorm *tvnorm;
264 /* other global state info */
265 u32 shadow[SHADOW_MAX];
266 struct cx8800_suspend_state state;
269 /* ----------------------------------------------------------- */
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));
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)
281 #define cx_wait(d) { if (need_resched()) schedule(); else udelay(d); }
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)))
292 /* ----------------------------------------------------------- */
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,
299 extern void cx88_print_ioctl(char *name, unsigned int cmd);
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);
307 cx88_risc_stopper(struct pci_dev *pci, struct btcx_riscmem *risc,
308 u32 reg, u32 mask, u32 value);
310 cx88_free_buffer(struct pci_dev *pci, struct cx88_buffer *buf);
312 extern void cx88_risc_disasm(struct cx8800_dev *dev,
313 struct btcx_riscmem *risc);
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);
321 extern int cx88_pci_quirks(char *name, struct pci_dev *pci,
322 unsigned int *latency);
324 /* ----------------------------------------------------------- */
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);
335 extern struct videobuf_queue_ops cx8800_vbi_qops;
337 /* ----------------------------------------------------------- */
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);
345 /* ----------------------------------------------------------- */
348 extern struct cx88_board cx88_boards[];
349 extern const unsigned int cx88_bcount;
351 extern struct cx88_subid cx88_subids[];
352 extern const unsigned int cx88_idcount;
354 extern void __devinit cx88_card_setup(struct cx8800_dev *dev);
356 /* ----------------------------------------------------------- */
362 #define WW_NICAM_BGDKL 4
368 #define WW_SYSTEM_L_AM 10
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);