V4L/DVB (4756): Cx88: cleanups
[linux-2.6/kvm.git] / drivers / media / video / cx88 / cx88-video.c
blobf27312189d79273d477a406f8b4724fbcde7771b
1 /*
3 * device driver for Conexant 2388x based TV cards
4 * video4linux video interface
6 * (c) 2003-04 Gerd Knorr <kraxel@bytesex.org> [SuSE Labs]
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; either version 2 of the License, or
11 * (at your option) any later version.
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
18 * You should have received a copy of the GNU General Public License
19 * along with this program; if not, write to the Free Software
20 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
23 #include <linux/init.h>
24 #include <linux/list.h>
25 #include <linux/module.h>
26 #include <linux/moduleparam.h>
27 #include <linux/kmod.h>
28 #include <linux/kernel.h>
29 #include <linux/slab.h>
30 #include <linux/interrupt.h>
31 #include <linux/delay.h>
32 #include <linux/kthread.h>
33 #include <asm/div64.h>
35 #include "cx88.h"
36 #include <media/v4l2-common.h>
38 #ifdef CONFIG_VIDEO_V4L1_COMPAT
39 /* Include V4L1 specific functions. Should be removed soon */
40 #include <linux/videodev.h>
41 #endif
43 MODULE_DESCRIPTION("v4l2 driver module for cx2388x based TV cards");
44 MODULE_AUTHOR("Gerd Knorr <kraxel@bytesex.org> [SuSE Labs]");
45 MODULE_LICENSE("GPL");
47 /* ------------------------------------------------------------------ */
49 static unsigned int video_nr[] = {[0 ... (CX88_MAXBOARDS - 1)] = UNSET };
50 static unsigned int vbi_nr[] = {[0 ... (CX88_MAXBOARDS - 1)] = UNSET };
51 static unsigned int radio_nr[] = {[0 ... (CX88_MAXBOARDS - 1)] = UNSET };
53 module_param_array(video_nr, int, NULL, 0444);
54 module_param_array(vbi_nr, int, NULL, 0444);
55 module_param_array(radio_nr, int, NULL, 0444);
57 MODULE_PARM_DESC(video_nr,"video device numbers");
58 MODULE_PARM_DESC(vbi_nr,"vbi device numbers");
59 MODULE_PARM_DESC(radio_nr,"radio device numbers");
61 static unsigned int video_debug = 0;
62 module_param(video_debug,int,0644);
63 MODULE_PARM_DESC(video_debug,"enable debug messages [video]");
65 static unsigned int irq_debug = 0;
66 module_param(irq_debug,int,0644);
67 MODULE_PARM_DESC(irq_debug,"enable debug messages [IRQ handler]");
69 static unsigned int vid_limit = 16;
70 module_param(vid_limit,int,0644);
71 MODULE_PARM_DESC(vid_limit,"capture memory limit in megabytes");
73 #define dprintk(level,fmt, arg...) if (video_debug >= level) \
74 printk(KERN_DEBUG "%s/0: " fmt, core->name , ## arg)
76 /* ------------------------------------------------------------------ */
78 static LIST_HEAD(cx8800_devlist);
80 /* ------------------------------------------------------------------- */
81 /* static data */
83 static struct cx88_tvnorm tvnorms[] = {
85 .name = "NTSC-M",
86 .id = V4L2_STD_NTSC_M,
87 .cxiformat = VideoFormatNTSC,
88 .cxoformat = 0x181f0008,
89 },{
90 .name = "NTSC-JP",
91 .id = V4L2_STD_NTSC_M_JP,
92 .cxiformat = VideoFormatNTSCJapan,
93 .cxoformat = 0x181f0008,
94 },{
95 .name = "PAL-BG",
96 .id = V4L2_STD_PAL_BG,
97 .cxiformat = VideoFormatPAL,
98 .cxoformat = 0x181f0008,
99 },{
100 .name = "PAL-DK",
101 .id = V4L2_STD_PAL_DK,
102 .cxiformat = VideoFormatPAL,
103 .cxoformat = 0x181f0008,
105 .name = "PAL-I",
106 .id = V4L2_STD_PAL_I,
107 .cxiformat = VideoFormatPAL,
108 .cxoformat = 0x181f0008,
110 .name = "PAL-M",
111 .id = V4L2_STD_PAL_M,
112 .cxiformat = VideoFormatPALM,
113 .cxoformat = 0x1c1f0008,
115 .name = "PAL-N",
116 .id = V4L2_STD_PAL_N,
117 .cxiformat = VideoFormatPALN,
118 .cxoformat = 0x1c1f0008,
120 .name = "PAL-Nc",
121 .id = V4L2_STD_PAL_Nc,
122 .cxiformat = VideoFormatPALNC,
123 .cxoformat = 0x1c1f0008,
125 .name = "PAL-60",
126 .id = V4L2_STD_PAL_60,
127 .cxiformat = VideoFormatPAL60,
128 .cxoformat = 0x181f0008,
130 .name = "SECAM-L",
131 .id = V4L2_STD_SECAM_L,
132 .cxiformat = VideoFormatSECAM,
133 .cxoformat = 0x181f0008,
135 .name = "SECAM-DK",
136 .id = V4L2_STD_SECAM_DK,
137 .cxiformat = VideoFormatSECAM,
138 .cxoformat = 0x181f0008,
142 static struct cx8800_fmt formats[] = {
144 .name = "8 bpp, gray",
145 .fourcc = V4L2_PIX_FMT_GREY,
146 .cxformat = ColorFormatY8,
147 .depth = 8,
148 .flags = FORMAT_FLAGS_PACKED,
150 .name = "15 bpp RGB, le",
151 .fourcc = V4L2_PIX_FMT_RGB555,
152 .cxformat = ColorFormatRGB15,
153 .depth = 16,
154 .flags = FORMAT_FLAGS_PACKED,
156 .name = "15 bpp RGB, be",
157 .fourcc = V4L2_PIX_FMT_RGB555X,
158 .cxformat = ColorFormatRGB15 | ColorFormatBSWAP,
159 .depth = 16,
160 .flags = FORMAT_FLAGS_PACKED,
162 .name = "16 bpp RGB, le",
163 .fourcc = V4L2_PIX_FMT_RGB565,
164 .cxformat = ColorFormatRGB16,
165 .depth = 16,
166 .flags = FORMAT_FLAGS_PACKED,
168 .name = "16 bpp RGB, be",
169 .fourcc = V4L2_PIX_FMT_RGB565X,
170 .cxformat = ColorFormatRGB16 | ColorFormatBSWAP,
171 .depth = 16,
172 .flags = FORMAT_FLAGS_PACKED,
174 .name = "24 bpp RGB, le",
175 .fourcc = V4L2_PIX_FMT_BGR24,
176 .cxformat = ColorFormatRGB24,
177 .depth = 24,
178 .flags = FORMAT_FLAGS_PACKED,
180 .name = "32 bpp RGB, le",
181 .fourcc = V4L2_PIX_FMT_BGR32,
182 .cxformat = ColorFormatRGB32,
183 .depth = 32,
184 .flags = FORMAT_FLAGS_PACKED,
186 .name = "32 bpp RGB, be",
187 .fourcc = V4L2_PIX_FMT_RGB32,
188 .cxformat = ColorFormatRGB32 | ColorFormatBSWAP | ColorFormatWSWAP,
189 .depth = 32,
190 .flags = FORMAT_FLAGS_PACKED,
192 .name = "4:2:2, packed, YUYV",
193 .fourcc = V4L2_PIX_FMT_YUYV,
194 .cxformat = ColorFormatYUY2,
195 .depth = 16,
196 .flags = FORMAT_FLAGS_PACKED,
198 .name = "4:2:2, packed, UYVY",
199 .fourcc = V4L2_PIX_FMT_UYVY,
200 .cxformat = ColorFormatYUY2 | ColorFormatBSWAP,
201 .depth = 16,
202 .flags = FORMAT_FLAGS_PACKED,
206 static struct cx8800_fmt* format_by_fourcc(unsigned int fourcc)
208 unsigned int i;
210 for (i = 0; i < ARRAY_SIZE(formats); i++)
211 if (formats[i].fourcc == fourcc)
212 return formats+i;
213 return NULL;
216 /* ------------------------------------------------------------------- */
218 static const struct v4l2_queryctrl no_ctl = {
219 .name = "42",
220 .flags = V4L2_CTRL_FLAG_DISABLED,
223 static struct cx88_ctrl cx8800_ctls[] = {
224 /* --- video --- */
226 .v = {
227 .id = V4L2_CID_BRIGHTNESS,
228 .name = "Brightness",
229 .minimum = 0x00,
230 .maximum = 0xff,
231 .step = 1,
232 .default_value = 0x7f,
233 .type = V4L2_CTRL_TYPE_INTEGER,
235 .off = 128,
236 .reg = MO_CONTR_BRIGHT,
237 .mask = 0x00ff,
238 .shift = 0,
240 .v = {
241 .id = V4L2_CID_CONTRAST,
242 .name = "Contrast",
243 .minimum = 0,
244 .maximum = 0xff,
245 .step = 1,
246 .default_value = 0x3f,
247 .type = V4L2_CTRL_TYPE_INTEGER,
249 .off = 0,
250 .reg = MO_CONTR_BRIGHT,
251 .mask = 0xff00,
252 .shift = 8,
254 .v = {
255 .id = V4L2_CID_HUE,
256 .name = "Hue",
257 .minimum = 0,
258 .maximum = 0xff,
259 .step = 1,
260 .default_value = 0x7f,
261 .type = V4L2_CTRL_TYPE_INTEGER,
263 .off = 128,
264 .reg = MO_HUE,
265 .mask = 0x00ff,
266 .shift = 0,
268 /* strictly, this only describes only U saturation.
269 * V saturation is handled specially through code.
271 .v = {
272 .id = V4L2_CID_SATURATION,
273 .name = "Saturation",
274 .minimum = 0,
275 .maximum = 0xff,
276 .step = 1,
277 .default_value = 0x7f,
278 .type = V4L2_CTRL_TYPE_INTEGER,
280 .off = 0,
281 .reg = MO_UV_SATURATION,
282 .mask = 0x00ff,
283 .shift = 0,
285 /* --- audio --- */
286 .v = {
287 .id = V4L2_CID_AUDIO_MUTE,
288 .name = "Mute",
289 .minimum = 0,
290 .maximum = 1,
291 .default_value = 1,
292 .type = V4L2_CTRL_TYPE_BOOLEAN,
294 .reg = AUD_VOL_CTL,
295 .sreg = SHADOW_AUD_VOL_CTL,
296 .mask = (1 << 6),
297 .shift = 6,
299 .v = {
300 .id = V4L2_CID_AUDIO_VOLUME,
301 .name = "Volume",
302 .minimum = 0,
303 .maximum = 0x3f,
304 .step = 1,
305 .default_value = 0x3f,
306 .type = V4L2_CTRL_TYPE_INTEGER,
308 .reg = AUD_VOL_CTL,
309 .sreg = SHADOW_AUD_VOL_CTL,
310 .mask = 0x3f,
311 .shift = 0,
313 .v = {
314 .id = V4L2_CID_AUDIO_BALANCE,
315 .name = "Balance",
316 .minimum = 0,
317 .maximum = 0x7f,
318 .step = 1,
319 .default_value = 0x40,
320 .type = V4L2_CTRL_TYPE_INTEGER,
322 .reg = AUD_BAL_CTL,
323 .sreg = SHADOW_AUD_BAL_CTL,
324 .mask = 0x7f,
325 .shift = 0,
328 static const int CX8800_CTLS = ARRAY_SIZE(cx8800_ctls);
330 const u32 cx88_user_ctrls[] = {
331 V4L2_CID_USER_CLASS,
332 V4L2_CID_BRIGHTNESS,
333 V4L2_CID_CONTRAST,
334 V4L2_CID_SATURATION,
335 V4L2_CID_HUE,
336 V4L2_CID_AUDIO_VOLUME,
337 V4L2_CID_AUDIO_BALANCE,
338 V4L2_CID_AUDIO_MUTE,
341 EXPORT_SYMBOL(cx88_user_ctrls);
343 static const u32 *ctrl_classes[] = {
344 cx88_user_ctrls,
345 NULL
348 int cx8800_ctrl_query(struct v4l2_queryctrl *qctrl)
350 int i;
352 if (qctrl->id < V4L2_CID_BASE ||
353 qctrl->id >= V4L2_CID_LASTP1)
354 return -EINVAL;
355 for (i = 0; i < CX8800_CTLS; i++)
356 if (cx8800_ctls[i].v.id == qctrl->id)
357 break;
358 if (i == CX8800_CTLS) {
359 *qctrl = no_ctl;
360 return 0;
362 *qctrl = cx8800_ctls[i].v;
363 return 0;
365 EXPORT_SYMBOL(cx8800_ctrl_query);
367 static int cx88_queryctrl(struct v4l2_queryctrl *qctrl)
369 qctrl->id = v4l2_ctrl_next(ctrl_classes, qctrl->id);
370 if (qctrl->id == 0)
371 return -EINVAL;
372 return cx8800_ctrl_query(qctrl);
375 /* ------------------------------------------------------------------- */
376 /* resource management */
378 static int res_get(struct cx8800_dev *dev, struct cx8800_fh *fh, unsigned int bit)
380 struct cx88_core *core = dev->core;
381 if (fh->resources & bit)
382 /* have it already allocated */
383 return 1;
385 /* is it free? */
386 mutex_lock(&core->lock);
387 if (dev->resources & bit) {
388 /* no, someone else uses it */
389 mutex_unlock(&core->lock);
390 return 0;
392 /* it's free, grab it */
393 fh->resources |= bit;
394 dev->resources |= bit;
395 dprintk(1,"res: get %d\n",bit);
396 mutex_unlock(&core->lock);
397 return 1;
400 static
401 int res_check(struct cx8800_fh *fh, unsigned int bit)
403 return (fh->resources & bit);
406 static
407 int res_locked(struct cx8800_dev *dev, unsigned int bit)
409 return (dev->resources & bit);
412 static
413 void res_free(struct cx8800_dev *dev, struct cx8800_fh *fh, unsigned int bits)
415 struct cx88_core *core = dev->core;
416 BUG_ON((fh->resources & bits) != bits);
418 mutex_lock(&core->lock);
419 fh->resources &= ~bits;
420 dev->resources &= ~bits;
421 dprintk(1,"res: put %d\n",bits);
422 mutex_unlock(&core->lock);
425 /* ------------------------------------------------------------------ */
427 /* static int video_mux(struct cx8800_dev *dev, unsigned int input) */
428 static int video_mux(struct cx88_core *core, unsigned int input)
430 /* struct cx88_core *core = dev->core; */
432 dprintk(1,"video_mux: %d [vmux=%d,gpio=0x%x,0x%x,0x%x,0x%x]\n",
433 input, INPUT(input)->vmux,
434 INPUT(input)->gpio0,INPUT(input)->gpio1,
435 INPUT(input)->gpio2,INPUT(input)->gpio3);
436 core->input = input;
437 cx_andor(MO_INPUT_FORMAT, 0x03 << 14, INPUT(input)->vmux << 14);
438 cx_write(MO_GP3_IO, INPUT(input)->gpio3);
439 cx_write(MO_GP0_IO, INPUT(input)->gpio0);
440 cx_write(MO_GP1_IO, INPUT(input)->gpio1);
441 cx_write(MO_GP2_IO, INPUT(input)->gpio2);
443 switch (INPUT(input)->type) {
444 case CX88_VMUX_SVIDEO:
445 cx_set(MO_AFECFG_IO, 0x00000001);
446 cx_set(MO_INPUT_FORMAT, 0x00010010);
447 cx_set(MO_FILTER_EVEN, 0x00002020);
448 cx_set(MO_FILTER_ODD, 0x00002020);
449 break;
450 default:
451 cx_clear(MO_AFECFG_IO, 0x00000001);
452 cx_clear(MO_INPUT_FORMAT, 0x00010010);
453 cx_clear(MO_FILTER_EVEN, 0x00002020);
454 cx_clear(MO_FILTER_ODD, 0x00002020);
455 break;
457 return 0;
460 /* ------------------------------------------------------------------ */
462 static int start_video_dma(struct cx8800_dev *dev,
463 struct cx88_dmaqueue *q,
464 struct cx88_buffer *buf)
466 struct cx88_core *core = dev->core;
468 /* setup fifo + format */
469 cx88_sram_channel_setup(core, &cx88_sram_channels[SRAM_CH21],
470 buf->bpl, buf->risc.dma);
471 cx88_set_scale(core, buf->vb.width, buf->vb.height, buf->vb.field);
472 cx_write(MO_COLOR_CTRL, buf->fmt->cxformat | ColorFormatGamma);
474 /* reset counter */
475 cx_write(MO_VIDY_GPCNTRL,GP_COUNT_CONTROL_RESET);
476 q->count = 1;
478 /* enable irqs */
479 cx_set(MO_PCI_INTMSK, core->pci_irqmask | 0x01);
481 /* Enables corresponding bits at PCI_INT_STAT:
482 bits 0 to 4: video, audio, transport stream, VIP, Host
483 bit 7: timer
484 bits 8 and 9: DMA complete for: SRC, DST
485 bits 10 and 11: BERR signal asserted for RISC: RD, WR
486 bits 12 to 15: BERR signal asserted for: BRDG, SRC, DST, IPB
488 cx_set(MO_VID_INTMSK, 0x0f0011);
490 /* enable capture */
491 cx_set(VID_CAPTURE_CONTROL,0x06);
493 /* start dma */
494 cx_set(MO_DEV_CNTRL2, (1<<5));
495 cx_set(MO_VID_DMACNTRL, 0x11); /* Planar Y and packed FIFO and RISC enable */
497 return 0;
500 #ifdef CONFIG_PM
501 static int stop_video_dma(struct cx8800_dev *dev)
503 struct cx88_core *core = dev->core;
505 /* stop dma */
506 cx_clear(MO_VID_DMACNTRL, 0x11);
508 /* disable capture */
509 cx_clear(VID_CAPTURE_CONTROL,0x06);
511 /* disable irqs */
512 cx_clear(MO_PCI_INTMSK, 0x000001);
513 cx_clear(MO_VID_INTMSK, 0x0f0011);
514 return 0;
516 #endif
518 static int restart_video_queue(struct cx8800_dev *dev,
519 struct cx88_dmaqueue *q)
521 struct cx88_core *core = dev->core;
522 struct cx88_buffer *buf, *prev;
523 struct list_head *item;
525 if (!list_empty(&q->active)) {
526 buf = list_entry(q->active.next, struct cx88_buffer, vb.queue);
527 dprintk(2,"restart_queue [%p/%d]: restart dma\n",
528 buf, buf->vb.i);
529 start_video_dma(dev, q, buf);
530 list_for_each(item,&q->active) {
531 buf = list_entry(item, struct cx88_buffer, vb.queue);
532 buf->count = q->count++;
534 mod_timer(&q->timeout, jiffies+BUFFER_TIMEOUT);
535 return 0;
538 prev = NULL;
539 for (;;) {
540 if (list_empty(&q->queued))
541 return 0;
542 buf = list_entry(q->queued.next, struct cx88_buffer, vb.queue);
543 if (NULL == prev) {
544 list_move_tail(&buf->vb.queue, &q->active);
545 start_video_dma(dev, q, buf);
546 buf->vb.state = STATE_ACTIVE;
547 buf->count = q->count++;
548 mod_timer(&q->timeout, jiffies+BUFFER_TIMEOUT);
549 dprintk(2,"[%p/%d] restart_queue - first active\n",
550 buf,buf->vb.i);
552 } else if (prev->vb.width == buf->vb.width &&
553 prev->vb.height == buf->vb.height &&
554 prev->fmt == buf->fmt) {
555 list_move_tail(&buf->vb.queue, &q->active);
556 buf->vb.state = STATE_ACTIVE;
557 buf->count = q->count++;
558 prev->risc.jmp[1] = cpu_to_le32(buf->risc.dma);
559 dprintk(2,"[%p/%d] restart_queue - move to active\n",
560 buf,buf->vb.i);
561 } else {
562 return 0;
564 prev = buf;
568 /* ------------------------------------------------------------------ */
570 static int
571 buffer_setup(struct videobuf_queue *q, unsigned int *count, unsigned int *size)
573 struct cx8800_fh *fh = q->priv_data;
575 *size = fh->fmt->depth*fh->width*fh->height >> 3;
576 if (0 == *count)
577 *count = 32;
578 while (*size * *count > vid_limit * 1024 * 1024)
579 (*count)--;
580 return 0;
583 static int
584 buffer_prepare(struct videobuf_queue *q, struct videobuf_buffer *vb,
585 enum v4l2_field field)
587 struct cx8800_fh *fh = q->priv_data;
588 struct cx8800_dev *dev = fh->dev;
589 struct cx88_core *core = dev->core;
590 struct cx88_buffer *buf = container_of(vb,struct cx88_buffer,vb);
591 int rc, init_buffer = 0;
593 BUG_ON(NULL == fh->fmt);
594 if (fh->width < 48 || fh->width > norm_maxw(core->tvnorm) ||
595 fh->height < 32 || fh->height > norm_maxh(core->tvnorm))
596 return -EINVAL;
597 buf->vb.size = (fh->width * fh->height * fh->fmt->depth) >> 3;
598 if (0 != buf->vb.baddr && buf->vb.bsize < buf->vb.size)
599 return -EINVAL;
601 if (buf->fmt != fh->fmt ||
602 buf->vb.width != fh->width ||
603 buf->vb.height != fh->height ||
604 buf->vb.field != field) {
605 buf->fmt = fh->fmt;
606 buf->vb.width = fh->width;
607 buf->vb.height = fh->height;
608 buf->vb.field = field;
609 init_buffer = 1;
612 if (STATE_NEEDS_INIT == buf->vb.state) {
613 init_buffer = 1;
614 if (0 != (rc = videobuf_iolock(q,&buf->vb,NULL)))
615 goto fail;
618 if (init_buffer) {
619 buf->bpl = buf->vb.width * buf->fmt->depth >> 3;
620 switch (buf->vb.field) {
621 case V4L2_FIELD_TOP:
622 cx88_risc_buffer(dev->pci, &buf->risc,
623 buf->vb.dma.sglist, 0, UNSET,
624 buf->bpl, 0, buf->vb.height);
625 break;
626 case V4L2_FIELD_BOTTOM:
627 cx88_risc_buffer(dev->pci, &buf->risc,
628 buf->vb.dma.sglist, UNSET, 0,
629 buf->bpl, 0, buf->vb.height);
630 break;
631 case V4L2_FIELD_INTERLACED:
632 cx88_risc_buffer(dev->pci, &buf->risc,
633 buf->vb.dma.sglist, 0, buf->bpl,
634 buf->bpl, buf->bpl,
635 buf->vb.height >> 1);
636 break;
637 case V4L2_FIELD_SEQ_TB:
638 cx88_risc_buffer(dev->pci, &buf->risc,
639 buf->vb.dma.sglist,
640 0, buf->bpl * (buf->vb.height >> 1),
641 buf->bpl, 0,
642 buf->vb.height >> 1);
643 break;
644 case V4L2_FIELD_SEQ_BT:
645 cx88_risc_buffer(dev->pci, &buf->risc,
646 buf->vb.dma.sglist,
647 buf->bpl * (buf->vb.height >> 1), 0,
648 buf->bpl, 0,
649 buf->vb.height >> 1);
650 break;
651 default:
652 BUG();
655 dprintk(2,"[%p/%d] buffer_prepare - %dx%d %dbpp \"%s\" - dma=0x%08lx\n",
656 buf, buf->vb.i,
657 fh->width, fh->height, fh->fmt->depth, fh->fmt->name,
658 (unsigned long)buf->risc.dma);
660 buf->vb.state = STATE_PREPARED;
661 return 0;
663 fail:
664 cx88_free_buffer(q,buf);
665 return rc;
668 static void
669 buffer_queue(struct videobuf_queue *vq, struct videobuf_buffer *vb)
671 struct cx88_buffer *buf = container_of(vb,struct cx88_buffer,vb);
672 struct cx88_buffer *prev;
673 struct cx8800_fh *fh = vq->priv_data;
674 struct cx8800_dev *dev = fh->dev;
675 struct cx88_core *core = dev->core;
676 struct cx88_dmaqueue *q = &dev->vidq;
678 /* add jump to stopper */
679 buf->risc.jmp[0] = cpu_to_le32(RISC_JUMP | RISC_IRQ1 | RISC_CNT_INC);
680 buf->risc.jmp[1] = cpu_to_le32(q->stopper.dma);
682 if (!list_empty(&q->queued)) {
683 list_add_tail(&buf->vb.queue,&q->queued);
684 buf->vb.state = STATE_QUEUED;
685 dprintk(2,"[%p/%d] buffer_queue - append to queued\n",
686 buf, buf->vb.i);
688 } else if (list_empty(&q->active)) {
689 list_add_tail(&buf->vb.queue,&q->active);
690 start_video_dma(dev, q, buf);
691 buf->vb.state = STATE_ACTIVE;
692 buf->count = q->count++;
693 mod_timer(&q->timeout, jiffies+BUFFER_TIMEOUT);
694 dprintk(2,"[%p/%d] buffer_queue - first active\n",
695 buf, buf->vb.i);
697 } else {
698 prev = list_entry(q->active.prev, struct cx88_buffer, vb.queue);
699 if (prev->vb.width == buf->vb.width &&
700 prev->vb.height == buf->vb.height &&
701 prev->fmt == buf->fmt) {
702 list_add_tail(&buf->vb.queue,&q->active);
703 buf->vb.state = STATE_ACTIVE;
704 buf->count = q->count++;
705 prev->risc.jmp[1] = cpu_to_le32(buf->risc.dma);
706 dprintk(2,"[%p/%d] buffer_queue - append to active\n",
707 buf, buf->vb.i);
709 } else {
710 list_add_tail(&buf->vb.queue,&q->queued);
711 buf->vb.state = STATE_QUEUED;
712 dprintk(2,"[%p/%d] buffer_queue - first queued\n",
713 buf, buf->vb.i);
718 static void buffer_release(struct videobuf_queue *q, struct videobuf_buffer *vb)
720 struct cx88_buffer *buf = container_of(vb,struct cx88_buffer,vb);
722 cx88_free_buffer(q,buf);
725 static struct videobuf_queue_ops cx8800_video_qops = {
726 .buf_setup = buffer_setup,
727 .buf_prepare = buffer_prepare,
728 .buf_queue = buffer_queue,
729 .buf_release = buffer_release,
732 /* ------------------------------------------------------------------ */
735 /* ------------------------------------------------------------------ */
737 static struct videobuf_queue* get_queue(struct cx8800_fh *fh)
739 switch (fh->type) {
740 case V4L2_BUF_TYPE_VIDEO_CAPTURE:
741 return &fh->vidq;
742 case V4L2_BUF_TYPE_VBI_CAPTURE:
743 return &fh->vbiq;
744 default:
745 BUG();
746 return NULL;
750 static int get_ressource(struct cx8800_fh *fh)
752 switch (fh->type) {
753 case V4L2_BUF_TYPE_VIDEO_CAPTURE:
754 return RESOURCE_VIDEO;
755 case V4L2_BUF_TYPE_VBI_CAPTURE:
756 return RESOURCE_VBI;
757 default:
758 BUG();
759 return 0;
763 static int video_open(struct inode *inode, struct file *file)
765 int minor = iminor(inode);
766 struct cx8800_dev *h,*dev = NULL;
767 struct cx88_core *core;
768 struct cx8800_fh *fh;
769 struct list_head *list;
770 enum v4l2_buf_type type = 0;
771 int radio = 0;
773 list_for_each(list,&cx8800_devlist) {
774 h = list_entry(list, struct cx8800_dev, devlist);
775 if (h->video_dev->minor == minor) {
776 dev = h;
777 type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
779 if (h->vbi_dev->minor == minor) {
780 dev = h;
781 type = V4L2_BUF_TYPE_VBI_CAPTURE;
783 if (h->radio_dev &&
784 h->radio_dev->minor == minor) {
785 radio = 1;
786 dev = h;
789 if (NULL == dev)
790 return -ENODEV;
792 core = dev->core;
794 dprintk(1,"open minor=%d radio=%d type=%s\n",
795 minor,radio,v4l2_type_names[type]);
797 /* allocate + initialize per filehandle data */
798 fh = kzalloc(sizeof(*fh),GFP_KERNEL);
799 if (NULL == fh)
800 return -ENOMEM;
801 file->private_data = fh;
802 fh->dev = dev;
803 fh->radio = radio;
804 fh->type = type;
805 fh->width = 320;
806 fh->height = 240;
807 fh->fmt = format_by_fourcc(V4L2_PIX_FMT_BGR24);
809 videobuf_queue_init(&fh->vidq, &cx8800_video_qops,
810 dev->pci, &dev->slock,
811 V4L2_BUF_TYPE_VIDEO_CAPTURE,
812 V4L2_FIELD_INTERLACED,
813 sizeof(struct cx88_buffer),
814 fh);
815 videobuf_queue_init(&fh->vbiq, &cx8800_vbi_qops,
816 dev->pci, &dev->slock,
817 V4L2_BUF_TYPE_VBI_CAPTURE,
818 V4L2_FIELD_SEQ_TB,
819 sizeof(struct cx88_buffer),
820 fh);
822 if (fh->radio) {
823 int board = core->board;
824 dprintk(1,"video_open: setting radio device\n");
825 cx_write(MO_GP3_IO, cx88_boards[board].radio.gpio3);
826 cx_write(MO_GP0_IO, cx88_boards[board].radio.gpio0);
827 cx_write(MO_GP1_IO, cx88_boards[board].radio.gpio1);
828 cx_write(MO_GP2_IO, cx88_boards[board].radio.gpio2);
829 core->tvaudio = WW_FM;
830 cx88_set_tvaudio(core);
831 cx88_set_stereo(core,V4L2_TUNER_MODE_STEREO,1);
832 cx88_call_i2c_clients(core,AUDC_SET_RADIO,NULL);
835 return 0;
838 static ssize_t
839 video_read(struct file *file, char __user *data, size_t count, loff_t *ppos)
841 struct cx8800_fh *fh = file->private_data;
843 switch (fh->type) {
844 case V4L2_BUF_TYPE_VIDEO_CAPTURE:
845 if (res_locked(fh->dev,RESOURCE_VIDEO))
846 return -EBUSY;
847 return videobuf_read_one(&fh->vidq, data, count, ppos,
848 file->f_flags & O_NONBLOCK);
849 case V4L2_BUF_TYPE_VBI_CAPTURE:
850 if (!res_get(fh->dev,fh,RESOURCE_VBI))
851 return -EBUSY;
852 return videobuf_read_stream(&fh->vbiq, data, count, ppos, 1,
853 file->f_flags & O_NONBLOCK);
854 default:
855 BUG();
856 return 0;
860 static unsigned int
861 video_poll(struct file *file, struct poll_table_struct *wait)
863 struct cx8800_fh *fh = file->private_data;
864 struct cx88_buffer *buf;
866 if (V4L2_BUF_TYPE_VBI_CAPTURE == fh->type) {
867 if (!res_get(fh->dev,fh,RESOURCE_VBI))
868 return POLLERR;
869 return videobuf_poll_stream(file, &fh->vbiq, wait);
872 if (res_check(fh,RESOURCE_VIDEO)) {
873 /* streaming capture */
874 if (list_empty(&fh->vidq.stream))
875 return POLLERR;
876 buf = list_entry(fh->vidq.stream.next,struct cx88_buffer,vb.stream);
877 } else {
878 /* read() capture */
879 buf = (struct cx88_buffer*)fh->vidq.read_buf;
880 if (NULL == buf)
881 return POLLERR;
883 poll_wait(file, &buf->vb.done, wait);
884 if (buf->vb.state == STATE_DONE ||
885 buf->vb.state == STATE_ERROR)
886 return POLLIN|POLLRDNORM;
887 return 0;
890 static int video_release(struct inode *inode, struct file *file)
892 struct cx8800_fh *fh = file->private_data;
893 struct cx8800_dev *dev = fh->dev;
895 /* turn off overlay */
896 if (res_check(fh, RESOURCE_OVERLAY)) {
897 /* FIXME */
898 res_free(dev,fh,RESOURCE_OVERLAY);
901 /* stop video capture */
902 if (res_check(fh, RESOURCE_VIDEO)) {
903 videobuf_queue_cancel(&fh->vidq);
904 res_free(dev,fh,RESOURCE_VIDEO);
906 if (fh->vidq.read_buf) {
907 buffer_release(&fh->vidq,fh->vidq.read_buf);
908 kfree(fh->vidq.read_buf);
911 /* stop vbi capture */
912 if (res_check(fh, RESOURCE_VBI)) {
913 if (fh->vbiq.streaming)
914 videobuf_streamoff(&fh->vbiq);
915 if (fh->vbiq.reading)
916 videobuf_read_stop(&fh->vbiq);
917 res_free(dev,fh,RESOURCE_VBI);
920 videobuf_mmap_free(&fh->vidq);
921 videobuf_mmap_free(&fh->vbiq);
922 file->private_data = NULL;
923 kfree(fh);
925 cx88_call_i2c_clients (dev->core, TUNER_SET_STANDBY, NULL);
927 return 0;
930 static int
931 video_mmap(struct file *file, struct vm_area_struct * vma)
933 struct cx8800_fh *fh = file->private_data;
935 return videobuf_mmap_mapper(get_queue(fh), vma);
938 /* ------------------------------------------------------------------ */
940 /* static int get_control(struct cx8800_dev *dev, struct v4l2_control *ctl) */
941 static int get_control(struct cx88_core *core, struct v4l2_control *ctl)
943 /* struct cx88_core *core = dev->core; */
944 struct cx88_ctrl *c = NULL;
945 u32 value;
946 int i;
948 for (i = 0; i < CX8800_CTLS; i++)
949 if (cx8800_ctls[i].v.id == ctl->id)
950 c = &cx8800_ctls[i];
951 if (NULL == c)
952 return -EINVAL;
954 value = c->sreg ? cx_sread(c->sreg) : cx_read(c->reg);
955 switch (ctl->id) {
956 case V4L2_CID_AUDIO_BALANCE:
957 ctl->value = ((value & 0x7f) < 0x40) ? ((value & 0x7f) + 0x40)
958 : (0x7f - (value & 0x7f));
959 break;
960 case V4L2_CID_AUDIO_VOLUME:
961 ctl->value = 0x3f - (value & 0x3f);
962 break;
963 default:
964 ctl->value = ((value + (c->off << c->shift)) & c->mask) >> c->shift;
965 break;
967 dprintk(1,"get_control id=0x%X(%s) ctrl=0x%02x, reg=0x%02x val=0x%02x (mask 0x%02x)%s\n",
968 ctl->id, c->v.name, ctl->value, c->reg,
969 value,c->mask, c->sreg ? " [shadowed]" : "");
970 return 0;
973 /* static int set_control(struct cx8800_dev *dev, struct v4l2_control *ctl) */
974 static int set_control(struct cx88_core *core, struct v4l2_control *ctl)
976 /* struct cx88_core *core = dev->core; */
977 struct cx88_ctrl *c = NULL;
978 u32 value,mask;
979 int i;
980 for (i = 0; i < CX8800_CTLS; i++) {
981 if (cx8800_ctls[i].v.id == ctl->id) {
982 c = &cx8800_ctls[i];
985 if (NULL == c)
986 return -EINVAL;
988 if (ctl->value < c->v.minimum)
989 ctl->value = c->v.minimum;
990 if (ctl->value > c->v.maximum)
991 ctl->value = c->v.maximum;
992 mask=c->mask;
993 switch (ctl->id) {
994 case V4L2_CID_AUDIO_BALANCE:
995 value = (ctl->value < 0x40) ? (0x7f - ctl->value) : (ctl->value - 0x40);
996 break;
997 case V4L2_CID_AUDIO_VOLUME:
998 value = 0x3f - (ctl->value & 0x3f);
999 break;
1000 case V4L2_CID_SATURATION:
1001 /* special v_sat handling */
1003 value = ((ctl->value - c->off) << c->shift) & c->mask;
1005 if (core->tvnorm->id & V4L2_STD_SECAM) {
1006 /* For SECAM, both U and V sat should be equal */
1007 value=value<<8|value;
1008 } else {
1009 /* Keeps U Saturation proportional to V Sat */
1010 value=(value*0x5a)/0x7f<<8|value;
1012 mask=0xffff;
1013 break;
1014 default:
1015 value = ((ctl->value - c->off) << c->shift) & c->mask;
1016 break;
1018 dprintk(1,"set_control id=0x%X(%s) ctrl=0x%02x, reg=0x%02x val=0x%02x (mask 0x%02x)%s\n",
1019 ctl->id, c->v.name, ctl->value, c->reg, value,
1020 mask, c->sreg ? " [shadowed]" : "");
1021 if (c->sreg) {
1022 cx_sandor(c->sreg, c->reg, mask, value);
1023 } else {
1024 cx_andor(c->reg, mask, value);
1026 return 0;
1029 static void init_controls(struct cx88_core *core)
1031 struct v4l2_control ctrl;
1032 int i;
1034 for (i = 0; i < CX8800_CTLS; i++) {
1035 ctrl.id=cx8800_ctls[i].v.id;
1036 ctrl.value=cx8800_ctls[i].v.default_value;
1037 set_control(core, &ctrl);
1041 /* ------------------------------------------------------------------ */
1043 static int cx8800_g_fmt(struct cx8800_dev *dev, struct cx8800_fh *fh,
1044 struct v4l2_format *f)
1046 switch (f->type) {
1047 case V4L2_BUF_TYPE_VIDEO_CAPTURE:
1048 memset(&f->fmt.pix,0,sizeof(f->fmt.pix));
1049 f->fmt.pix.width = fh->width;
1050 f->fmt.pix.height = fh->height;
1051 f->fmt.pix.field = fh->vidq.field;
1052 f->fmt.pix.pixelformat = fh->fmt->fourcc;
1053 f->fmt.pix.bytesperline =
1054 (f->fmt.pix.width * fh->fmt->depth) >> 3;
1055 f->fmt.pix.sizeimage =
1056 f->fmt.pix.height * f->fmt.pix.bytesperline;
1057 return 0;
1058 case V4L2_BUF_TYPE_VBI_CAPTURE:
1059 cx8800_vbi_fmt(dev, f);
1060 return 0;
1061 default:
1062 return -EINVAL;
1066 static int cx8800_try_fmt(struct cx8800_dev *dev, struct cx8800_fh *fh,
1067 struct v4l2_format *f)
1069 struct cx88_core *core = dev->core;
1071 switch (f->type) {
1072 case V4L2_BUF_TYPE_VIDEO_CAPTURE:
1074 struct cx8800_fmt *fmt;
1075 enum v4l2_field field;
1076 unsigned int maxw, maxh;
1078 fmt = format_by_fourcc(f->fmt.pix.pixelformat);
1079 if (NULL == fmt)
1080 return -EINVAL;
1082 field = f->fmt.pix.field;
1083 maxw = norm_maxw(core->tvnorm);
1084 maxh = norm_maxh(core->tvnorm);
1086 if (V4L2_FIELD_ANY == field) {
1087 field = (f->fmt.pix.height > maxh/2)
1088 ? V4L2_FIELD_INTERLACED
1089 : V4L2_FIELD_BOTTOM;
1092 switch (field) {
1093 case V4L2_FIELD_TOP:
1094 case V4L2_FIELD_BOTTOM:
1095 maxh = maxh / 2;
1096 break;
1097 case V4L2_FIELD_INTERLACED:
1098 break;
1099 default:
1100 return -EINVAL;
1103 f->fmt.pix.field = field;
1104 if (f->fmt.pix.height < 32)
1105 f->fmt.pix.height = 32;
1106 if (f->fmt.pix.height > maxh)
1107 f->fmt.pix.height = maxh;
1108 if (f->fmt.pix.width < 48)
1109 f->fmt.pix.width = 48;
1110 if (f->fmt.pix.width > maxw)
1111 f->fmt.pix.width = maxw;
1112 f->fmt.pix.width &= ~0x03;
1113 f->fmt.pix.bytesperline =
1114 (f->fmt.pix.width * fmt->depth) >> 3;
1115 f->fmt.pix.sizeimage =
1116 f->fmt.pix.height * f->fmt.pix.bytesperline;
1118 return 0;
1120 case V4L2_BUF_TYPE_VBI_CAPTURE:
1121 cx8800_vbi_fmt(dev, f);
1122 return 0;
1123 default:
1124 return -EINVAL;
1128 static int cx8800_s_fmt(struct cx8800_dev *dev, struct cx8800_fh *fh,
1129 struct v4l2_format *f)
1131 int err;
1133 switch (f->type) {
1134 case V4L2_BUF_TYPE_VIDEO_CAPTURE:
1135 err = cx8800_try_fmt(dev,fh,f);
1136 if (0 != err)
1137 return err;
1139 fh->fmt = format_by_fourcc(f->fmt.pix.pixelformat);
1140 fh->width = f->fmt.pix.width;
1141 fh->height = f->fmt.pix.height;
1142 fh->vidq.field = f->fmt.pix.field;
1143 return 0;
1144 case V4L2_BUF_TYPE_VBI_CAPTURE:
1145 cx8800_vbi_fmt(dev, f);
1146 return 0;
1147 default:
1148 return -EINVAL;
1153 * This function is _not_ called directly, but from
1154 * video_generic_ioctl (and maybe others). userspace
1155 * copying is done already, arg is a kernel pointer.
1157 static int video_do_ioctl(struct inode *inode, struct file *file,
1158 unsigned int cmd, void *arg)
1160 struct cx8800_fh *fh = file->private_data;
1161 struct cx8800_dev *dev = fh->dev;
1162 struct cx88_core *core = dev->core;
1163 int err;
1165 if (video_debug > 1)
1166 v4l_print_ioctl(core->name,cmd);
1167 switch (cmd) {
1169 /* --- capabilities ------------------------------------------ */
1170 case VIDIOC_QUERYCAP:
1172 struct v4l2_capability *cap = arg;
1174 memset(cap,0,sizeof(*cap));
1175 strcpy(cap->driver, "cx8800");
1176 strlcpy(cap->card, cx88_boards[core->board].name,
1177 sizeof(cap->card));
1178 sprintf(cap->bus_info,"PCI:%s",pci_name(dev->pci));
1179 cap->version = CX88_VERSION_CODE;
1180 cap->capabilities =
1181 V4L2_CAP_VIDEO_CAPTURE |
1182 V4L2_CAP_READWRITE |
1183 V4L2_CAP_STREAMING |
1184 V4L2_CAP_VBI_CAPTURE |
1186 if (UNSET != core->tuner_type)
1187 cap->capabilities |= V4L2_CAP_TUNER;
1188 return 0;
1191 /* --- capture ioctls ---------------------------------------- */
1192 case VIDIOC_ENUM_FMT:
1194 struct v4l2_fmtdesc *f = arg;
1195 enum v4l2_buf_type type;
1196 unsigned int index;
1198 index = f->index;
1199 type = f->type;
1200 switch (type) {
1201 case V4L2_BUF_TYPE_VIDEO_CAPTURE:
1202 if (index >= ARRAY_SIZE(formats))
1203 return -EINVAL;
1204 memset(f,0,sizeof(*f));
1205 f->index = index;
1206 f->type = type;
1207 strlcpy(f->description,formats[index].name,sizeof(f->description));
1208 f->pixelformat = formats[index].fourcc;
1209 break;
1210 default:
1211 return -EINVAL;
1213 return 0;
1215 case VIDIOC_G_FMT:
1217 struct v4l2_format *f = arg;
1218 return cx8800_g_fmt(dev,fh,f);
1220 case VIDIOC_S_FMT:
1222 struct v4l2_format *f = arg;
1223 return cx8800_s_fmt(dev,fh,f);
1225 case VIDIOC_TRY_FMT:
1227 struct v4l2_format *f = arg;
1228 return cx8800_try_fmt(dev,fh,f);
1230 #ifdef CONFIG_VIDEO_V4L1_COMPAT
1231 /* --- streaming capture ------------------------------------- */
1232 case VIDIOCGMBUF:
1234 struct video_mbuf *mbuf = arg;
1235 struct videobuf_queue *q;
1236 struct v4l2_requestbuffers req;
1237 unsigned int i;
1239 q = get_queue(fh);
1240 memset(&req,0,sizeof(req));
1241 req.type = q->type;
1242 req.count = 8;
1243 req.memory = V4L2_MEMORY_MMAP;
1244 err = videobuf_reqbufs(q,&req);
1245 if (err < 0)
1246 return err;
1247 memset(mbuf,0,sizeof(*mbuf));
1248 mbuf->frames = req.count;
1249 mbuf->size = 0;
1250 for (i = 0; i < mbuf->frames; i++) {
1251 mbuf->offsets[i] = q->bufs[i]->boff;
1252 mbuf->size += q->bufs[i]->bsize;
1254 return 0;
1256 #endif
1257 case VIDIOC_REQBUFS:
1258 return videobuf_reqbufs(get_queue(fh), arg);
1260 case VIDIOC_QUERYBUF:
1261 return videobuf_querybuf(get_queue(fh), arg);
1263 case VIDIOC_QBUF:
1264 return videobuf_qbuf(get_queue(fh), arg);
1266 case VIDIOC_DQBUF:
1267 return videobuf_dqbuf(get_queue(fh), arg,
1268 file->f_flags & O_NONBLOCK);
1270 case VIDIOC_STREAMON:
1272 int res = get_ressource(fh);
1274 if (!res_get(dev,fh,res))
1275 return -EBUSY;
1276 return videobuf_streamon(get_queue(fh));
1278 case VIDIOC_STREAMOFF:
1280 int res = get_ressource(fh);
1282 err = videobuf_streamoff(get_queue(fh));
1283 if (err < 0)
1284 return err;
1285 res_free(dev,fh,res);
1286 return 0;
1288 default:
1289 return cx88_do_ioctl( inode, file, fh->radio, core, cmd, arg, video_do_ioctl );
1291 return 0;
1294 int cx88_do_ioctl(struct inode *inode, struct file *file, int radio,
1295 struct cx88_core *core, unsigned int cmd, void *arg, v4l2_kioctl driver_ioctl)
1297 int err;
1299 if (video_debug) {
1300 if (video_debug > 1) {
1301 if (_IOC_DIR(cmd) & _IOC_WRITE)
1302 v4l_printk_ioctl_arg("cx88(w)",cmd, arg);
1303 else if (!_IOC_DIR(cmd) & _IOC_READ) {
1304 v4l_print_ioctl("cx88", cmd);
1306 } else
1307 v4l_print_ioctl(core->name,cmd);
1311 switch (cmd) {
1312 /* ---------- tv norms ---------- */
1313 case VIDIOC_ENUMSTD:
1315 struct v4l2_standard *e = arg;
1316 unsigned int i;
1318 i = e->index;
1319 if (i >= ARRAY_SIZE(tvnorms))
1320 return -EINVAL;
1321 err = v4l2_video_std_construct(e, tvnorms[e->index].id,
1322 tvnorms[e->index].name);
1323 e->index = i;
1324 if (err < 0)
1325 return err;
1326 return 0;
1328 case VIDIOC_G_STD:
1330 v4l2_std_id *id = arg;
1332 *id = core->tvnorm->id;
1333 return 0;
1335 case VIDIOC_S_STD:
1337 v4l2_std_id *id = arg;
1338 unsigned int i;
1340 for(i = 0; i < ARRAY_SIZE(tvnorms); i++)
1341 if (*id & tvnorms[i].id)
1342 break;
1343 if (i == ARRAY_SIZE(tvnorms))
1344 return -EINVAL;
1346 mutex_lock(&core->lock);
1347 cx88_set_tvnorm(core,&tvnorms[i]);
1348 mutex_unlock(&core->lock);
1349 return 0;
1352 /* ------ input switching ---------- */
1353 case VIDIOC_ENUMINPUT:
1355 static const char *iname[] = {
1356 [ CX88_VMUX_COMPOSITE1 ] = "Composite1",
1357 [ CX88_VMUX_COMPOSITE2 ] = "Composite2",
1358 [ CX88_VMUX_COMPOSITE3 ] = "Composite3",
1359 [ CX88_VMUX_COMPOSITE4 ] = "Composite4",
1360 [ CX88_VMUX_SVIDEO ] = "S-Video",
1361 [ CX88_VMUX_TELEVISION ] = "Television",
1362 [ CX88_VMUX_CABLE ] = "Cable TV",
1363 [ CX88_VMUX_DVB ] = "DVB",
1364 [ CX88_VMUX_DEBUG ] = "for debug only",
1366 struct v4l2_input *i = arg;
1367 unsigned int n;
1369 n = i->index;
1370 if (n >= 4)
1371 return -EINVAL;
1372 if (0 == INPUT(n)->type)
1373 return -EINVAL;
1374 memset(i,0,sizeof(*i));
1375 i->index = n;
1376 i->type = V4L2_INPUT_TYPE_CAMERA;
1377 strcpy(i->name,iname[INPUT(n)->type]);
1378 if ((CX88_VMUX_TELEVISION == INPUT(n)->type) ||
1379 (CX88_VMUX_CABLE == INPUT(n)->type))
1380 i->type = V4L2_INPUT_TYPE_TUNER;
1381 for (n = 0; n < ARRAY_SIZE(tvnorms); n++)
1382 i->std |= tvnorms[n].id;
1383 return 0;
1385 case VIDIOC_G_INPUT:
1387 unsigned int *i = arg;
1389 *i = core->input;
1390 return 0;
1392 case VIDIOC_S_INPUT:
1394 unsigned int *i = arg;
1396 if (*i >= 4)
1397 return -EINVAL;
1398 mutex_lock(&core->lock);
1399 cx88_newstation(core);
1400 video_mux(core,*i);
1401 mutex_unlock(&core->lock);
1402 return 0;
1407 /* --- controls ---------------------------------------------- */
1408 case VIDIOC_QUERYCTRL:
1410 struct v4l2_queryctrl *c = arg;
1412 return cx88_queryctrl(c);
1414 case VIDIOC_G_CTRL:
1415 return get_control(core,arg);
1416 case VIDIOC_S_CTRL:
1417 return set_control(core,arg);
1419 /* --- tuner ioctls ------------------------------------------ */
1420 case VIDIOC_G_TUNER:
1422 struct v4l2_tuner *t = arg;
1423 u32 reg;
1425 if (UNSET == core->tuner_type)
1426 return -EINVAL;
1427 if (0 != t->index)
1428 return -EINVAL;
1430 memset(t,0,sizeof(*t));
1431 strcpy(t->name, "Television");
1432 t->type = V4L2_TUNER_ANALOG_TV;
1433 t->capability = V4L2_TUNER_CAP_NORM;
1434 t->rangehigh = 0xffffffffUL;
1436 cx88_get_stereo(core ,t);
1437 reg = cx_read(MO_DEVICE_STATUS);
1438 t->signal = (reg & (1<<5)) ? 0xffff : 0x0000;
1439 return 0;
1441 case VIDIOC_S_TUNER:
1443 struct v4l2_tuner *t = arg;
1445 if (UNSET == core->tuner_type)
1446 return -EINVAL;
1447 if (0 != t->index)
1448 return -EINVAL;
1449 cx88_set_stereo(core, t->audmode, 1);
1450 return 0;
1452 case VIDIOC_G_FREQUENCY:
1454 struct v4l2_frequency *f = arg;
1456 memset(f,0,sizeof(*f));
1458 if (UNSET == core->tuner_type)
1459 return -EINVAL;
1461 /* f->type = fh->radio ? V4L2_TUNER_RADIO : V4L2_TUNER_ANALOG_TV; */
1462 f->type = radio ? V4L2_TUNER_RADIO : V4L2_TUNER_ANALOG_TV;
1463 f->frequency = core->freq;
1465 cx88_call_i2c_clients(core,VIDIOC_G_FREQUENCY,f);
1467 return 0;
1469 case VIDIOC_S_FREQUENCY:
1471 struct v4l2_frequency *f = arg;
1473 if (UNSET == core->tuner_type)
1474 return -EINVAL;
1475 if (f->tuner != 0)
1476 return -EINVAL;
1477 if (0 == radio && f->type != V4L2_TUNER_ANALOG_TV)
1478 return -EINVAL;
1479 if (1 == radio && f->type != V4L2_TUNER_RADIO)
1480 return -EINVAL;
1481 mutex_lock(&core->lock);
1482 core->freq = f->frequency;
1483 cx88_newstation(core);
1484 cx88_call_i2c_clients(core,VIDIOC_S_FREQUENCY,f);
1486 /* When changing channels it is required to reset TVAUDIO */
1487 msleep (10);
1488 cx88_set_tvaudio(core);
1490 mutex_unlock(&core->lock);
1491 return 0;
1493 #ifdef CONFIG_VIDEO_ADV_DEBUG
1494 /* ioctls to allow direct acces to the cx2388x registers */
1495 case VIDIOC_INT_G_REGISTER:
1497 struct v4l2_register *reg = arg;
1499 if (reg->i2c_id != 0)
1500 return -EINVAL;
1501 /* cx2388x has a 24-bit register space */
1502 reg->val = cx_read(reg->reg&0xffffff);
1503 return 0;
1505 case VIDIOC_INT_S_REGISTER:
1507 struct v4l2_register *reg = arg;
1509 if (reg->i2c_id != 0)
1510 return -EINVAL;
1511 if (!capable(CAP_SYS_ADMIN))
1512 return -EPERM;
1513 cx_write(reg->reg&0xffffff, reg->val);
1514 return 0;
1516 #endif
1518 default:
1519 return v4l_compat_translate_ioctl(inode,file,cmd,arg,
1520 driver_ioctl);
1522 return 0;
1525 static int video_ioctl(struct inode *inode, struct file *file,
1526 unsigned int cmd, unsigned long arg)
1528 int retval;
1530 retval=video_usercopy(inode, file, cmd, arg, video_do_ioctl);
1532 if (video_debug > 1) {
1533 if (retval < 0) {
1534 v4l_print_ioctl("cx88(err)", cmd);
1535 printk(KERN_DEBUG "cx88(err): errcode=%d\n",retval);
1536 } else if (_IOC_DIR(cmd) & _IOC_READ)
1537 v4l_printk_ioctl_arg("cx88(r)",cmd, (void *)arg);
1540 return retval;
1543 /* ----------------------------------------------------------- */
1545 static int radio_do_ioctl(struct inode *inode, struct file *file,
1546 unsigned int cmd, void *arg)
1548 struct cx8800_fh *fh = file->private_data;
1549 struct cx8800_dev *dev = fh->dev;
1550 struct cx88_core *core = dev->core;
1552 if (video_debug > 1)
1553 v4l_print_ioctl(core->name,cmd);
1555 switch (cmd) {
1556 case VIDIOC_QUERYCAP:
1558 struct v4l2_capability *cap = arg;
1560 memset(cap,0,sizeof(*cap));
1561 strcpy(cap->driver, "cx8800");
1562 strlcpy(cap->card, cx88_boards[core->board].name,
1563 sizeof(cap->card));
1564 sprintf(cap->bus_info,"PCI:%s", pci_name(dev->pci));
1565 cap->version = CX88_VERSION_CODE;
1566 cap->capabilities = V4L2_CAP_TUNER;
1567 return 0;
1569 case VIDIOC_G_TUNER:
1571 struct v4l2_tuner *t = arg;
1573 if (t->index > 0)
1574 return -EINVAL;
1576 memset(t,0,sizeof(*t));
1577 strcpy(t->name, "Radio");
1578 t->type = V4L2_TUNER_RADIO;
1580 cx88_call_i2c_clients(core,VIDIOC_G_TUNER,t);
1581 return 0;
1583 case VIDIOC_ENUMINPUT:
1585 struct v4l2_input *i = arg;
1587 if (i->index != 0)
1588 return -EINVAL;
1589 strcpy(i->name,"Radio");
1590 i->type = V4L2_INPUT_TYPE_TUNER;
1591 return 0;
1593 case VIDIOC_G_INPUT:
1595 int *i = arg;
1596 *i = 0;
1597 return 0;
1599 case VIDIOC_G_AUDIO:
1601 struct v4l2_audio *a = arg;
1603 memset(a,0,sizeof(*a));
1604 strcpy(a->name,"Radio");
1605 return 0;
1607 case VIDIOC_G_STD:
1609 v4l2_std_id *id = arg;
1610 *id = 0;
1611 return 0;
1613 #ifdef CONFIG_VIDEO_V4L1_COMPAT
1614 case VIDIOCSTUNER:
1616 struct video_tuner *v = arg;
1618 if (v->tuner) /* Only tuner 0 */
1619 return -EINVAL;
1621 cx88_call_i2c_clients(core,VIDIOCSTUNER,v);
1622 return 0;
1624 #endif
1625 case VIDIOC_S_TUNER:
1627 struct v4l2_tuner *t = arg;
1629 if (0 != t->index)
1630 return -EINVAL;
1632 cx88_call_i2c_clients(core,VIDIOC_S_TUNER,t);
1634 return 0;
1637 case VIDIOC_S_AUDIO:
1638 case VIDIOC_S_INPUT:
1639 case VIDIOC_S_STD:
1640 return 0;
1642 case VIDIOC_QUERYCTRL:
1644 struct v4l2_queryctrl *c = arg;
1645 int i;
1647 if (c->id < V4L2_CID_BASE ||
1648 c->id >= V4L2_CID_LASTP1)
1649 return -EINVAL;
1650 if (c->id == V4L2_CID_AUDIO_MUTE) {
1651 for (i = 0; i < CX8800_CTLS; i++)
1652 if (cx8800_ctls[i].v.id == c->id)
1653 break;
1654 *c = cx8800_ctls[i].v;
1655 } else
1656 *c = no_ctl;
1657 return 0;
1661 case VIDIOC_G_CTRL:
1662 case VIDIOC_S_CTRL:
1663 case VIDIOC_G_FREQUENCY:
1664 case VIDIOC_S_FREQUENCY:
1665 return video_do_ioctl(inode,file,cmd,arg);
1667 default:
1668 return v4l_compat_translate_ioctl(inode,file,cmd,arg,
1669 radio_do_ioctl);
1671 return 0;
1674 static int radio_ioctl(struct inode *inode, struct file *file,
1675 unsigned int cmd, unsigned long arg)
1677 return video_usercopy(inode, file, cmd, arg, radio_do_ioctl);
1680 /* ----------------------------------------------------------- */
1682 static void cx8800_vid_timeout(unsigned long data)
1684 struct cx8800_dev *dev = (struct cx8800_dev*)data;
1685 struct cx88_core *core = dev->core;
1686 struct cx88_dmaqueue *q = &dev->vidq;
1687 struct cx88_buffer *buf;
1688 unsigned long flags;
1690 cx88_sram_channel_dump(core, &cx88_sram_channels[SRAM_CH21]);
1692 cx_clear(MO_VID_DMACNTRL, 0x11);
1693 cx_clear(VID_CAPTURE_CONTROL, 0x06);
1695 spin_lock_irqsave(&dev->slock,flags);
1696 while (!list_empty(&q->active)) {
1697 buf = list_entry(q->active.next, struct cx88_buffer, vb.queue);
1698 list_del(&buf->vb.queue);
1699 buf->vb.state = STATE_ERROR;
1700 wake_up(&buf->vb.done);
1701 printk("%s/0: [%p/%d] timeout - dma=0x%08lx\n", core->name,
1702 buf, buf->vb.i, (unsigned long)buf->risc.dma);
1704 restart_video_queue(dev,q);
1705 spin_unlock_irqrestore(&dev->slock,flags);
1708 static char *cx88_vid_irqs[32] = {
1709 "y_risci1", "u_risci1", "v_risci1", "vbi_risc1",
1710 "y_risci2", "u_risci2", "v_risci2", "vbi_risc2",
1711 "y_oflow", "u_oflow", "v_oflow", "vbi_oflow",
1712 "y_sync", "u_sync", "v_sync", "vbi_sync",
1713 "opc_err", "par_err", "rip_err", "pci_abort",
1716 static void cx8800_vid_irq(struct cx8800_dev *dev)
1718 struct cx88_core *core = dev->core;
1719 u32 status, mask, count;
1721 status = cx_read(MO_VID_INTSTAT);
1722 mask = cx_read(MO_VID_INTMSK);
1723 if (0 == (status & mask))
1724 return;
1725 cx_write(MO_VID_INTSTAT, status);
1726 if (irq_debug || (status & mask & ~0xff))
1727 cx88_print_irqbits(core->name, "irq vid",
1728 cx88_vid_irqs, status, mask);
1730 /* risc op code error */
1731 if (status & (1 << 16)) {
1732 printk(KERN_WARNING "%s/0: video risc op code error\n",core->name);
1733 cx_clear(MO_VID_DMACNTRL, 0x11);
1734 cx_clear(VID_CAPTURE_CONTROL, 0x06);
1735 cx88_sram_channel_dump(core, &cx88_sram_channels[SRAM_CH21]);
1738 /* risc1 y */
1739 if (status & 0x01) {
1740 spin_lock(&dev->slock);
1741 count = cx_read(MO_VIDY_GPCNT);
1742 cx88_wakeup(core, &dev->vidq, count);
1743 spin_unlock(&dev->slock);
1746 /* risc1 vbi */
1747 if (status & 0x08) {
1748 spin_lock(&dev->slock);
1749 count = cx_read(MO_VBI_GPCNT);
1750 cx88_wakeup(core, &dev->vbiq, count);
1751 spin_unlock(&dev->slock);
1754 /* risc2 y */
1755 if (status & 0x10) {
1756 dprintk(2,"stopper video\n");
1757 spin_lock(&dev->slock);
1758 restart_video_queue(dev,&dev->vidq);
1759 spin_unlock(&dev->slock);
1762 /* risc2 vbi */
1763 if (status & 0x80) {
1764 dprintk(2,"stopper vbi\n");
1765 spin_lock(&dev->slock);
1766 cx8800_restart_vbi_queue(dev,&dev->vbiq);
1767 spin_unlock(&dev->slock);
1771 static irqreturn_t cx8800_irq(int irq, void *dev_id)
1773 struct cx8800_dev *dev = dev_id;
1774 struct cx88_core *core = dev->core;
1775 u32 status;
1776 int loop, handled = 0;
1778 for (loop = 0; loop < 10; loop++) {
1779 status = cx_read(MO_PCI_INTSTAT) & (core->pci_irqmask | 0x01);
1780 if (0 == status)
1781 goto out;
1782 cx_write(MO_PCI_INTSTAT, status);
1783 handled = 1;
1785 if (status & core->pci_irqmask)
1786 cx88_core_irq(core,status);
1787 if (status & 0x01)
1788 cx8800_vid_irq(dev);
1790 if (10 == loop) {
1791 printk(KERN_WARNING "%s/0: irq loop -- clearing mask\n",
1792 core->name);
1793 cx_write(MO_PCI_INTMSK,0);
1796 out:
1797 return IRQ_RETVAL(handled);
1800 /* ----------------------------------------------------------- */
1801 /* exported stuff */
1803 static struct file_operations video_fops =
1805 .owner = THIS_MODULE,
1806 .open = video_open,
1807 .release = video_release,
1808 .read = video_read,
1809 .poll = video_poll,
1810 .mmap = video_mmap,
1811 .ioctl = video_ioctl,
1812 .compat_ioctl = v4l_compat_ioctl32,
1813 .llseek = no_llseek,
1816 static struct video_device cx8800_video_template =
1818 .name = "cx8800-video",
1819 .type = VID_TYPE_CAPTURE|VID_TYPE_TUNER|VID_TYPE_SCALES,
1820 .hardware = 0,
1821 .fops = &video_fops,
1822 .minor = -1,
1825 static struct video_device cx8800_vbi_template =
1827 .name = "cx8800-vbi",
1828 .type = VID_TYPE_TELETEXT|VID_TYPE_TUNER,
1829 .hardware = 0,
1830 .fops = &video_fops,
1831 .minor = -1,
1834 static struct file_operations radio_fops =
1836 .owner = THIS_MODULE,
1837 .open = video_open,
1838 .release = video_release,
1839 .ioctl = radio_ioctl,
1840 .compat_ioctl = v4l_compat_ioctl32,
1841 .llseek = no_llseek,
1844 static struct video_device cx8800_radio_template =
1846 .name = "cx8800-radio",
1847 .type = VID_TYPE_TUNER,
1848 .hardware = 0,
1849 .fops = &radio_fops,
1850 .minor = -1,
1853 /* ----------------------------------------------------------- */
1855 static void cx8800_unregister_video(struct cx8800_dev *dev)
1857 if (dev->radio_dev) {
1858 if (-1 != dev->radio_dev->minor)
1859 video_unregister_device(dev->radio_dev);
1860 else
1861 video_device_release(dev->radio_dev);
1862 dev->radio_dev = NULL;
1864 if (dev->vbi_dev) {
1865 if (-1 != dev->vbi_dev->minor)
1866 video_unregister_device(dev->vbi_dev);
1867 else
1868 video_device_release(dev->vbi_dev);
1869 dev->vbi_dev = NULL;
1871 if (dev->video_dev) {
1872 if (-1 != dev->video_dev->minor)
1873 video_unregister_device(dev->video_dev);
1874 else
1875 video_device_release(dev->video_dev);
1876 dev->video_dev = NULL;
1880 static int __devinit cx8800_initdev(struct pci_dev *pci_dev,
1881 const struct pci_device_id *pci_id)
1883 struct cx8800_dev *dev;
1884 struct cx88_core *core;
1885 int err;
1887 dev = kzalloc(sizeof(*dev),GFP_KERNEL);
1888 if (NULL == dev)
1889 return -ENOMEM;
1891 /* pci init */
1892 dev->pci = pci_dev;
1893 if (pci_enable_device(pci_dev)) {
1894 err = -EIO;
1895 goto fail_free;
1897 core = cx88_core_get(dev->pci);
1898 if (NULL == core) {
1899 err = -EINVAL;
1900 goto fail_free;
1902 dev->core = core;
1904 /* print pci info */
1905 pci_read_config_byte(pci_dev, PCI_CLASS_REVISION, &dev->pci_rev);
1906 pci_read_config_byte(pci_dev, PCI_LATENCY_TIMER, &dev->pci_lat);
1907 printk(KERN_INFO "%s/0: found at %s, rev: %d, irq: %d, "
1908 "latency: %d, mmio: 0x%llx\n", core->name,
1909 pci_name(pci_dev), dev->pci_rev, pci_dev->irq,
1910 dev->pci_lat,(unsigned long long)pci_resource_start(pci_dev,0));
1912 pci_set_master(pci_dev);
1913 if (!pci_dma_supported(pci_dev,0xffffffff)) {
1914 printk("%s/0: Oops: no 32bit PCI DMA ???\n",core->name);
1915 err = -EIO;
1916 goto fail_core;
1919 /* initialize driver struct */
1920 spin_lock_init(&dev->slock);
1921 core->tvnorm = tvnorms;
1923 /* init video dma queues */
1924 INIT_LIST_HEAD(&dev->vidq.active);
1925 INIT_LIST_HEAD(&dev->vidq.queued);
1926 dev->vidq.timeout.function = cx8800_vid_timeout;
1927 dev->vidq.timeout.data = (unsigned long)dev;
1928 init_timer(&dev->vidq.timeout);
1929 cx88_risc_stopper(dev->pci,&dev->vidq.stopper,
1930 MO_VID_DMACNTRL,0x11,0x00);
1932 /* init vbi dma queues */
1933 INIT_LIST_HEAD(&dev->vbiq.active);
1934 INIT_LIST_HEAD(&dev->vbiq.queued);
1935 dev->vbiq.timeout.function = cx8800_vbi_timeout;
1936 dev->vbiq.timeout.data = (unsigned long)dev;
1937 init_timer(&dev->vbiq.timeout);
1938 cx88_risc_stopper(dev->pci,&dev->vbiq.stopper,
1939 MO_VID_DMACNTRL,0x88,0x00);
1941 /* get irq */
1942 err = request_irq(pci_dev->irq, cx8800_irq,
1943 IRQF_SHARED | IRQF_DISABLED, core->name, dev);
1944 if (err < 0) {
1945 printk(KERN_ERR "%s: can't get IRQ %d\n",
1946 core->name,pci_dev->irq);
1947 goto fail_core;
1949 cx_set(MO_PCI_INTMSK, core->pci_irqmask);
1951 /* load and configure helper modules */
1952 if (TUNER_ABSENT != core->tuner_type)
1953 request_module("tuner");
1955 if (cx88_boards[ core->board ].audio_chip == AUDIO_CHIP_WM8775)
1956 request_module("wm8775");
1958 /* register v4l devices */
1959 dev->video_dev = cx88_vdev_init(core,dev->pci,
1960 &cx8800_video_template,"video");
1961 err = video_register_device(dev->video_dev,VFL_TYPE_GRABBER,
1962 video_nr[core->nr]);
1963 if (err < 0) {
1964 printk(KERN_INFO "%s: can't register video device\n",
1965 core->name);
1966 goto fail_unreg;
1968 printk(KERN_INFO "%s/0: registered device video%d [v4l2]\n",
1969 core->name,dev->video_dev->minor & 0x1f);
1971 dev->vbi_dev = cx88_vdev_init(core,dev->pci,&cx8800_vbi_template,"vbi");
1972 err = video_register_device(dev->vbi_dev,VFL_TYPE_VBI,
1973 vbi_nr[core->nr]);
1974 if (err < 0) {
1975 printk(KERN_INFO "%s/0: can't register vbi device\n",
1976 core->name);
1977 goto fail_unreg;
1979 printk(KERN_INFO "%s/0: registered device vbi%d\n",
1980 core->name,dev->vbi_dev->minor & 0x1f);
1982 if (core->has_radio) {
1983 dev->radio_dev = cx88_vdev_init(core,dev->pci,
1984 &cx8800_radio_template,"radio");
1985 err = video_register_device(dev->radio_dev,VFL_TYPE_RADIO,
1986 radio_nr[core->nr]);
1987 if (err < 0) {
1988 printk(KERN_INFO "%s/0: can't register radio device\n",
1989 core->name);
1990 goto fail_unreg;
1992 printk(KERN_INFO "%s/0: registered device radio%d\n",
1993 core->name,dev->radio_dev->minor & 0x1f);
1996 /* everything worked */
1997 list_add_tail(&dev->devlist,&cx8800_devlist);
1998 pci_set_drvdata(pci_dev,dev);
2000 /* initial device configuration */
2001 mutex_lock(&core->lock);
2002 cx88_set_tvnorm(core,tvnorms);
2003 init_controls(core);
2004 video_mux(core,0);
2005 mutex_unlock(&core->lock);
2007 /* start tvaudio thread */
2008 if (core->tuner_type != TUNER_ABSENT)
2009 core->kthread = kthread_run(cx88_audio_thread, core, "cx88 tvaudio");
2010 return 0;
2012 fail_unreg:
2013 cx8800_unregister_video(dev);
2014 free_irq(pci_dev->irq, dev);
2015 fail_core:
2016 cx88_core_put(core,dev->pci);
2017 fail_free:
2018 kfree(dev);
2019 return err;
2022 static void __devexit cx8800_finidev(struct pci_dev *pci_dev)
2024 struct cx8800_dev *dev = pci_get_drvdata(pci_dev);
2025 struct cx88_core *core = dev->core;
2027 /* stop thread */
2028 if (core->kthread) {
2029 kthread_stop(core->kthread);
2030 core->kthread = NULL;
2033 cx88_shutdown(core); /* FIXME */
2034 pci_disable_device(pci_dev);
2036 /* unregister stuff */
2038 free_irq(pci_dev->irq, dev);
2039 cx8800_unregister_video(dev);
2040 pci_set_drvdata(pci_dev, NULL);
2042 /* free memory */
2043 btcx_riscmem_free(dev->pci,&dev->vidq.stopper);
2044 list_del(&dev->devlist);
2045 cx88_core_put(core,dev->pci);
2046 kfree(dev);
2049 #ifdef CONFIG_PM
2050 static int cx8800_suspend(struct pci_dev *pci_dev, pm_message_t state)
2052 struct cx8800_dev *dev = pci_get_drvdata(pci_dev);
2053 struct cx88_core *core = dev->core;
2055 /* stop video+vbi capture */
2056 spin_lock(&dev->slock);
2057 if (!list_empty(&dev->vidq.active)) {
2058 printk("%s: suspend video\n", core->name);
2059 stop_video_dma(dev);
2060 del_timer(&dev->vidq.timeout);
2062 if (!list_empty(&dev->vbiq.active)) {
2063 printk("%s: suspend vbi\n", core->name);
2064 cx8800_stop_vbi_dma(dev);
2065 del_timer(&dev->vbiq.timeout);
2067 spin_unlock(&dev->slock);
2069 /* FIXME -- shutdown device */
2070 cx88_shutdown(core);
2072 pci_save_state(pci_dev);
2073 if (0 != pci_set_power_state(pci_dev, pci_choose_state(pci_dev, state))) {
2074 pci_disable_device(pci_dev);
2075 dev->state.disabled = 1;
2077 return 0;
2080 static int cx8800_resume(struct pci_dev *pci_dev)
2082 struct cx8800_dev *dev = pci_get_drvdata(pci_dev);
2083 struct cx88_core *core = dev->core;
2084 int err;
2086 if (dev->state.disabled) {
2087 err=pci_enable_device(pci_dev);
2088 if (err) {
2089 printk(KERN_ERR "%s: can't enable device\n",
2090 core->name);
2091 return err;
2094 dev->state.disabled = 0;
2096 err= pci_set_power_state(pci_dev, PCI_D0);
2097 if (err) {
2098 printk(KERN_ERR "%s: can't enable device\n",
2099 core->name);
2101 pci_disable_device(pci_dev);
2102 dev->state.disabled = 1;
2104 return err;
2106 pci_restore_state(pci_dev);
2108 /* FIXME: re-initialize hardware */
2109 cx88_reset(core);
2111 /* restart video+vbi capture */
2112 spin_lock(&dev->slock);
2113 if (!list_empty(&dev->vidq.active)) {
2114 printk("%s: resume video\n", core->name);
2115 restart_video_queue(dev,&dev->vidq);
2117 if (!list_empty(&dev->vbiq.active)) {
2118 printk("%s: resume vbi\n", core->name);
2119 cx8800_restart_vbi_queue(dev,&dev->vbiq);
2121 spin_unlock(&dev->slock);
2123 return 0;
2125 #endif
2127 /* ----------------------------------------------------------- */
2129 static struct pci_device_id cx8800_pci_tbl[] = {
2131 .vendor = 0x14f1,
2132 .device = 0x8800,
2133 .subvendor = PCI_ANY_ID,
2134 .subdevice = PCI_ANY_ID,
2136 /* --- end of list --- */
2139 MODULE_DEVICE_TABLE(pci, cx8800_pci_tbl);
2141 static struct pci_driver cx8800_pci_driver = {
2142 .name = "cx8800",
2143 .id_table = cx8800_pci_tbl,
2144 .probe = cx8800_initdev,
2145 .remove = __devexit_p(cx8800_finidev),
2146 #ifdef CONFIG_PM
2147 .suspend = cx8800_suspend,
2148 .resume = cx8800_resume,
2149 #endif
2152 static int cx8800_init(void)
2154 printk(KERN_INFO "cx2388x v4l2 driver version %d.%d.%d loaded\n",
2155 (CX88_VERSION_CODE >> 16) & 0xff,
2156 (CX88_VERSION_CODE >> 8) & 0xff,
2157 CX88_VERSION_CODE & 0xff);
2158 #ifdef SNAPSHOT
2159 printk(KERN_INFO "cx2388x: snapshot date %04d-%02d-%02d\n",
2160 SNAPSHOT/10000, (SNAPSHOT/100)%100, SNAPSHOT%100);
2161 #endif
2162 return pci_register_driver(&cx8800_pci_driver);
2165 static void cx8800_fini(void)
2167 pci_unregister_driver(&cx8800_pci_driver);
2170 module_init(cx8800_init);
2171 module_exit(cx8800_fini);
2173 EXPORT_SYMBOL(cx88_do_ioctl);
2175 /* ----------------------------------------------------------- */
2177 * Local variables:
2178 * c-basic-offset: 8
2179 * End:
2180 * 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