2 * Driver for the Conexant CX23885 PCIe bridge
4 * Copyright (c) 2007 Steven Toth <stoth@hauppauge.com>
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
15 * GNU General Public License for more details.
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.
22 #include <linux/init.h>
23 #include <linux/list.h>
24 #include <linux/module.h>
25 #include <linux/moduleparam.h>
26 #include <linux/kmod.h>
27 #include <linux/kernel.h>
28 #include <linux/slab.h>
29 #include <linux/interrupt.h>
30 #include <linux/delay.h>
31 #include <linux/kthread.h>
32 #include <asm/div64.h>
35 #include <media/v4l2-common.h>
37 #ifdef CONFIG_VIDEO_V4L1_COMPAT
38 /* Include V4L1 specific functions. Should be removed soon */
39 #include <linux/videodev.h>
42 MODULE_DESCRIPTION("v4l2 driver module for cx23885 based TV cards");
43 MODULE_AUTHOR("Steven Toth <stoth@hauppauge.com>");
44 MODULE_LICENSE("GPL");
46 /* ------------------------------------------------------------------ */
48 static unsigned int video_nr[] = {[0 ... (CX23885_MAXBOARDS - 1)] = UNSET };
49 static unsigned int vbi_nr[] = {[0 ... (CX23885_MAXBOARDS - 1)] = UNSET };
50 static unsigned int radio_nr[] = {[0 ... (CX23885_MAXBOARDS - 1)] = UNSET };
52 module_param_array(video_nr, int, NULL, 0444);
53 module_param_array(vbi_nr, int, NULL, 0444);
54 module_param_array(radio_nr, int, NULL, 0444);
56 MODULE_PARM_DESC(video_nr, "video device numbers");
57 MODULE_PARM_DESC(vbi_nr, "vbi device numbers");
58 MODULE_PARM_DESC(radio_nr, "radio device numbers");
60 static unsigned int video_debug = 0;
61 module_param(video_debug, int, 0644);
62 MODULE_PARM_DESC(video_debug, "enable debug messages [video]");
64 static unsigned int irq_debug = 0;
65 module_param(irq_debug, int, 0644);
66 MODULE_PARM_DESC(irq_debug, "enable debug messages [IRQ handler]");
68 static unsigned int vid_limit = 16;
69 module_param(vid_limit, int, 0644);
70 MODULE_PARM_DESC(vid_limit, "capture memory limit in megabytes");
72 #define dprintk(level, fmt, arg...)\
73 if (video_debug >= level)\
74 printk(KERN_DEBUG "%s/0: " fmt, dev->name, ## arg)
76 /* ------------------------------------------------------------------- */
79 #define FORMAT_FLAGS_PACKED 0x01
81 static struct cx23885_fmt formats[] = {
83 .name = "8 bpp, gray",
84 .fourcc = V4L2_PIX_FMT_GREY,
86 .flags = FORMAT_FLAGS_PACKED,
88 .name = "15 bpp RGB, le",
89 .fourcc = V4L2_PIX_FMT_RGB555,
91 .flags = FORMAT_FLAGS_PACKED,
93 .name = "15 bpp RGB, be",
94 .fourcc = V4L2_PIX_FMT_RGB555X,
96 .flags = FORMAT_FLAGS_PACKED,
98 .name = "16 bpp RGB, le",
99 .fourcc = V4L2_PIX_FMT_RGB565,
101 .flags = FORMAT_FLAGS_PACKED,
103 .name = "16 bpp RGB, be",
104 .fourcc = V4L2_PIX_FMT_RGB565X,
106 .flags = FORMAT_FLAGS_PACKED,
108 .name = "24 bpp RGB, le",
109 .fourcc = V4L2_PIX_FMT_BGR24,
111 .flags = FORMAT_FLAGS_PACKED,
113 .name = "32 bpp RGB, le",
114 .fourcc = V4L2_PIX_FMT_BGR32,
116 .flags = FORMAT_FLAGS_PACKED,
118 .name = "32 bpp RGB, be",
119 .fourcc = V4L2_PIX_FMT_RGB32,
121 .flags = FORMAT_FLAGS_PACKED,
123 .name = "4:2:2, packed, YUYV",
124 .fourcc = V4L2_PIX_FMT_YUYV,
126 .flags = FORMAT_FLAGS_PACKED,
128 .name = "4:2:2, packed, UYVY",
129 .fourcc = V4L2_PIX_FMT_UYVY,
131 .flags = FORMAT_FLAGS_PACKED,
135 static struct cx23885_fmt *format_by_fourcc(unsigned int fourcc)
139 for (i = 0; i < ARRAY_SIZE(formats); i++)
140 if (formats[i].fourcc == fourcc)
143 printk(KERN_ERR "%s(0x%08x) NOT FOUND\n", __FUNCTION__, fourcc);
147 /* ------------------------------------------------------------------- */
149 static const struct v4l2_queryctrl no_ctl = {
151 .flags = V4L2_CTRL_FLAG_DISABLED,
154 static struct cx23885_ctrl cx23885_ctls[] = {
158 .id = V4L2_CID_BRIGHTNESS,
159 .name = "Brightness",
163 .default_value = 0x7f,
164 .type = V4L2_CTRL_TYPE_INTEGER,
172 .id = V4L2_CID_CONTRAST,
177 .default_value = 0x3f,
178 .type = V4L2_CTRL_TYPE_INTEGER,
191 .default_value = 0x7f,
192 .type = V4L2_CTRL_TYPE_INTEGER,
199 /* strictly, this only describes only U saturation.
200 * V saturation is handled specially through code.
203 .id = V4L2_CID_SATURATION,
204 .name = "Saturation",
208 .default_value = 0x7f,
209 .type = V4L2_CTRL_TYPE_INTEGER,
218 .id = V4L2_CID_AUDIO_MUTE,
223 .type = V4L2_CTRL_TYPE_BOOLEAN,
226 .mask = (0x1f << 24),
230 .id = V4L2_CID_AUDIO_VOLUME,
235 .default_value = 0x3f,
236 .type = V4L2_CTRL_TYPE_INTEGER,
238 .reg = PATH1_VOL_CTL,
243 static const int CX23885_CTLS = ARRAY_SIZE(cx23885_ctls);
245 const u32 cx23885_user_ctrls[] = {
251 V4L2_CID_AUDIO_VOLUME,
255 EXPORT_SYMBOL(cx23885_user_ctrls);
257 static const u32 *ctrl_classes[] = {
262 void cx23885_video_wakeup(struct cx23885_dev *dev,
263 struct cx23885_dmaqueue *q, u32 count)
265 struct cx23885_buffer *buf;
268 for (bc = 0;; bc++) {
269 if (list_empty(&q->active))
271 buf = list_entry(q->active.next,
272 struct cx23885_buffer, vb.queue);
273 /* count comes from the hw and is is 16bit wide --
274 * this trick handles wrap-arounds correctly for
275 * up to 32767 buffers in flight... */
276 if ((s16) (count - buf->count) < 0)
278 do_gettimeofday(&buf->vb.ts);
279 dprintk(2, "[%p/%d] wakeup reg=%d buf=%d\n", buf, buf->vb.i,
281 buf->vb.state = VIDEOBUF_DONE;
282 list_del(&buf->vb.queue);
283 wake_up(&buf->vb.done);
285 if (list_empty(&q->active)) {
286 del_timer(&q->timeout);
288 mod_timer(&q->timeout, jiffies+BUFFER_TIMEOUT);
291 printk(KERN_ERR "%s: %d buffers handled (should be 1)\n",
295 int cx23885_set_tvnorm(struct cx23885_dev *dev, v4l2_std_id norm)
297 dprintk(1, "%s(norm = 0x%08x) name: [%s]\n",
300 v4l2_norm_to_name(norm));
305 /* Tell the analog tuner/demods */
306 cx23885_call_i2c_clients(&dev->i2c_bus[1], VIDIOC_S_STD, &norm);
308 /* Tell the internal A/V decoder */
309 cx23885_call_i2c_clients(&dev->i2c_bus[2], VIDIOC_S_STD, &norm);
314 struct video_device *cx23885_vdev_init(struct cx23885_dev *dev,
316 struct video_device *template,
319 struct video_device *vfd;
320 dprintk(1, "%s()\n", __FUNCTION__);
322 vfd = video_device_alloc();
327 vfd->dev = &pci->dev;
328 vfd->release = video_device_release;
329 snprintf(vfd->name, sizeof(vfd->name), "%s %s (%s)",
330 dev->name, type, cx23885_boards[dev->board].name);
334 int cx23885_ctrl_query(struct v4l2_queryctrl *qctrl)
338 if (qctrl->id < V4L2_CID_BASE ||
339 qctrl->id >= V4L2_CID_LASTP1)
341 for (i = 0; i < CX23885_CTLS; i++)
342 if (cx23885_ctls[i].v.id == qctrl->id)
344 if (i == CX23885_CTLS) {
348 *qctrl = cx23885_ctls[i].v;
351 EXPORT_SYMBOL(cx23885_ctrl_query);
353 /* ------------------------------------------------------------------- */
354 /* resource management */
356 static int res_get(struct cx23885_dev *dev, struct cx23885_fh *fh,
359 dprintk(1, "%s()\n", __FUNCTION__);
360 if (fh->resources & bit)
361 /* have it already allocated */
365 mutex_lock(&dev->lock);
366 if (dev->resources & bit) {
367 /* no, someone else uses it */
368 mutex_unlock(&dev->lock);
371 /* it's free, grab it */
372 fh->resources |= bit;
373 dev->resources |= bit;
374 dprintk(1, "res: get %d\n", bit);
375 mutex_unlock(&dev->lock);
379 static int res_check(struct cx23885_fh *fh, unsigned int bit)
381 return (fh->resources & bit);
384 static int res_locked(struct cx23885_dev *dev, unsigned int bit)
386 return (dev->resources & bit);
389 static void res_free(struct cx23885_dev *dev, struct cx23885_fh *fh,
392 BUG_ON((fh->resources & bits) != bits);
393 dprintk(1, "%s()\n", __FUNCTION__);
395 mutex_lock(&dev->lock);
396 fh->resources &= ~bits;
397 dev->resources &= ~bits;
398 dprintk(1, "res: put %d\n", bits);
399 mutex_unlock(&dev->lock);
402 int cx23885_video_mux(struct cx23885_dev *dev, unsigned int input)
404 struct v4l2_routing route;
405 memset(&route, 0, sizeof(route));
407 dprintk(1, "%s() video_mux: %d [vmux=%d, gpio=0x%x,0x%x,0x%x,0x%x]\n",
409 input, INPUT(input)->vmux,
410 INPUT(input)->gpio0, INPUT(input)->gpio1,
411 INPUT(input)->gpio2, INPUT(input)->gpio3);
414 route.input = INPUT(input)->vmux;
416 /* Tell the internal A/V decoder */
417 cx23885_call_i2c_clients(&dev->i2c_bus[2],
418 VIDIOC_INT_S_VIDEO_ROUTING, &route);
422 EXPORT_SYMBOL(cx23885_video_mux);
424 /* ------------------------------------------------------------------ */
425 int cx23885_set_scale(struct cx23885_dev *dev, unsigned int width,
426 unsigned int height, enum v4l2_field field)
428 dprintk(1, "%s()\n", __FUNCTION__);
432 static int cx23885_start_video_dma(struct cx23885_dev *dev,
433 struct cx23885_dmaqueue *q,
434 struct cx23885_buffer *buf)
436 dprintk(1, "%s()\n", __FUNCTION__);
438 /* setup fifo + format */
439 cx23885_sram_channel_setup(dev, &dev->sram_channels[SRAM_CH01],
440 buf->bpl, buf->risc.dma);
441 cx23885_set_scale(dev, buf->vb.width, buf->vb.height, buf->vb.field);
444 cx_write(VID_A_GPCNT_CTL, 3);
448 cx_set(PCI_INT_MSK, cx_read(PCI_INT_MSK) | 0x01);
449 cx_set(VID_A_INT_MSK, 0x000011);
452 cx_set(DEV_CNTRL2, (1<<5));
453 cx_set(VID_A_DMA_CTL, 0x11); /* FIFO and RISC enable */
459 static int cx23885_stop_video_dma(struct cx23885_dev *dev)
461 dprintk(1, "%s()\n", __FUNCTION__);
463 cx_clear(VID_A_DMA_CTL, 0x11);
466 cx_clear(PCI_INT_MSK, 0x000001);
467 cx_clear(VID_A_INT_MSK, 0x000011);
473 static int cx23885_restart_video_queue(struct cx23885_dev *dev,
474 struct cx23885_dmaqueue *q)
476 struct cx23885_buffer *buf, *prev;
477 struct list_head *item;
478 dprintk(1, "%s()\n", __FUNCTION__);
480 if (!list_empty(&q->active)) {
481 buf = list_entry(q->active.next, struct cx23885_buffer,
483 dprintk(2, "restart_queue [%p/%d]: restart dma\n",
485 cx23885_start_video_dma(dev, q, buf);
486 list_for_each(item, &q->active) {
487 buf = list_entry(item, struct cx23885_buffer,
489 buf->count = q->count++;
491 mod_timer(&q->timeout, jiffies+BUFFER_TIMEOUT);
497 if (list_empty(&q->queued))
499 buf = list_entry(q->queued.next, struct cx23885_buffer,
502 list_move_tail(&buf->vb.queue, &q->active);
503 cx23885_start_video_dma(dev, q, buf);
504 buf->vb.state = VIDEOBUF_ACTIVE;
505 buf->count = q->count++;
506 mod_timer(&q->timeout, jiffies+BUFFER_TIMEOUT);
507 dprintk(2, "[%p/%d] restart_queue - first active\n",
510 } else if (prev->vb.width == buf->vb.width &&
511 prev->vb.height == buf->vb.height &&
512 prev->fmt == buf->fmt) {
513 list_move_tail(&buf->vb.queue, &q->active);
514 buf->vb.state = VIDEOBUF_ACTIVE;
515 buf->count = q->count++;
516 prev->risc.jmp[1] = cpu_to_le32(buf->risc.dma);
517 prev->risc.jmp[2] = cpu_to_le32(0); /* Bits 63 - 32 */
518 dprintk(2, "[%p/%d] restart_queue - move to active\n",
527 static int buffer_setup(struct videobuf_queue *q, unsigned int *count,
530 struct cx23885_fh *fh = q->priv_data;
532 *size = fh->fmt->depth*fh->width*fh->height >> 3;
535 while (*size * *count > vid_limit * 1024 * 1024)
540 static int buffer_prepare(struct videobuf_queue *q, struct videobuf_buffer *vb,
541 enum v4l2_field field)
543 struct cx23885_fh *fh = q->priv_data;
544 struct cx23885_dev *dev = fh->dev;
545 struct cx23885_buffer *buf =
546 container_of(vb, struct cx23885_buffer, vb);
547 int rc, init_buffer = 0;
548 u32 line0_offset, line1_offset;
549 struct videobuf_dmabuf *dma = videobuf_to_dma(&buf->vb);
551 BUG_ON(NULL == fh->fmt);
552 if (fh->width < 48 || fh->width > norm_maxw(dev->tvnorm) ||
553 fh->height < 32 || fh->height > norm_maxh(dev->tvnorm))
555 buf->vb.size = (fh->width * fh->height * fh->fmt->depth) >> 3;
556 if (0 != buf->vb.baddr && buf->vb.bsize < buf->vb.size)
559 if (buf->fmt != fh->fmt ||
560 buf->vb.width != fh->width ||
561 buf->vb.height != fh->height ||
562 buf->vb.field != field) {
564 buf->vb.width = fh->width;
565 buf->vb.height = fh->height;
566 buf->vb.field = field;
570 if (VIDEOBUF_NEEDS_INIT == buf->vb.state) {
572 rc = videobuf_iolock(q, &buf->vb, NULL);
578 buf->bpl = buf->vb.width * buf->fmt->depth >> 3;
579 switch (buf->vb.field) {
581 cx23885_risc_buffer(dev->pci, &buf->risc,
582 dma->sglist, 0, UNSET,
583 buf->bpl, 0, buf->vb.height);
585 case V4L2_FIELD_BOTTOM:
586 cx23885_risc_buffer(dev->pci, &buf->risc,
587 dma->sglist, UNSET, 0,
588 buf->bpl, 0, buf->vb.height);
590 case V4L2_FIELD_INTERLACED:
591 if (dev->tvnorm & V4L2_STD_NTSC) {
592 /* cx25840 transmits NTSC bottom field first */
593 dprintk(1, "%s() Creating NTSC risc\n",
595 line0_offset = buf->bpl;
598 /* All other formats are top field first */
599 dprintk(1, "%s() Creating PAL/SECAM risc\n",
602 line1_offset = buf->bpl;
604 cx23885_risc_buffer(dev->pci, &buf->risc,
605 dma->sglist, line0_offset,
608 buf->vb.height >> 1);
610 case V4L2_FIELD_SEQ_TB:
611 cx23885_risc_buffer(dev->pci, &buf->risc,
613 0, buf->bpl * (buf->vb.height >> 1),
615 buf->vb.height >> 1);
617 case V4L2_FIELD_SEQ_BT:
618 cx23885_risc_buffer(dev->pci, &buf->risc,
620 buf->bpl * (buf->vb.height >> 1), 0,
622 buf->vb.height >> 1);
628 dprintk(2, "[%p/%d] buffer_prep - %dx%d %dbpp \"%s\" - dma=0x%08lx\n",
630 fh->width, fh->height, fh->fmt->depth, fh->fmt->name,
631 (unsigned long)buf->risc.dma);
633 buf->vb.state = VIDEOBUF_PREPARED;
637 cx23885_free_buffer(q, buf);
641 static void buffer_queue(struct videobuf_queue *vq, struct videobuf_buffer *vb)
643 struct cx23885_buffer *buf = container_of(vb,
644 struct cx23885_buffer, vb);
645 struct cx23885_buffer *prev;
646 struct cx23885_fh *fh = vq->priv_data;
647 struct cx23885_dev *dev = fh->dev;
648 struct cx23885_dmaqueue *q = &dev->vidq;
650 /* add jump to stopper */
651 buf->risc.jmp[0] = cpu_to_le32(RISC_JUMP | RISC_IRQ1 | RISC_CNT_INC);
652 buf->risc.jmp[1] = cpu_to_le32(q->stopper.dma);
653 buf->risc.jmp[2] = cpu_to_le32(0); /* bits 63-32 */
655 if (!list_empty(&q->queued)) {
656 list_add_tail(&buf->vb.queue, &q->queued);
657 buf->vb.state = VIDEOBUF_QUEUED;
658 dprintk(2, "[%p/%d] buffer_queue - append to queued\n",
661 } else if (list_empty(&q->active)) {
662 list_add_tail(&buf->vb.queue, &q->active);
663 cx23885_start_video_dma(dev, q, buf);
664 buf->vb.state = VIDEOBUF_ACTIVE;
665 buf->count = q->count++;
666 mod_timer(&q->timeout, jiffies+BUFFER_TIMEOUT);
667 dprintk(2, "[%p/%d] buffer_queue - first active\n",
671 prev = list_entry(q->active.prev, struct cx23885_buffer,
673 if (prev->vb.width == buf->vb.width &&
674 prev->vb.height == buf->vb.height &&
675 prev->fmt == buf->fmt) {
676 list_add_tail(&buf->vb.queue, &q->active);
677 buf->vb.state = VIDEOBUF_ACTIVE;
678 buf->count = q->count++;
679 prev->risc.jmp[1] = cpu_to_le32(buf->risc.dma);
680 /* 64 bit bits 63-32 */
681 prev->risc.jmp[2] = cpu_to_le32(0);
682 dprintk(2, "[%p/%d] buffer_queue - append to active\n",
686 list_add_tail(&buf->vb.queue, &q->queued);
687 buf->vb.state = VIDEOBUF_QUEUED;
688 dprintk(2, "[%p/%d] buffer_queue - first queued\n",
694 static void buffer_release(struct videobuf_queue *q,
695 struct videobuf_buffer *vb)
697 struct cx23885_buffer *buf = container_of(vb,
698 struct cx23885_buffer, vb);
700 cx23885_free_buffer(q, buf);
703 static struct videobuf_queue_ops cx23885_video_qops = {
704 .buf_setup = buffer_setup,
705 .buf_prepare = buffer_prepare,
706 .buf_queue = buffer_queue,
707 .buf_release = buffer_release,
710 static struct videobuf_queue *get_queue(struct cx23885_fh *fh)
713 case V4L2_BUF_TYPE_VIDEO_CAPTURE:
715 case V4L2_BUF_TYPE_VBI_CAPTURE:
723 static int get_resource(struct cx23885_fh *fh)
726 case V4L2_BUF_TYPE_VIDEO_CAPTURE:
727 return RESOURCE_VIDEO;
728 case V4L2_BUF_TYPE_VBI_CAPTURE:
736 static int video_open(struct inode *inode, struct file *file)
738 int minor = iminor(inode);
739 struct cx23885_dev *h, *dev = NULL;
740 struct cx23885_fh *fh;
741 struct list_head *list;
742 enum v4l2_buf_type type = 0;
745 list_for_each(list, &cx23885_devlist) {
746 h = list_entry(list, struct cx23885_dev, devlist);
747 if (h->video_dev->minor == minor) {
749 type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
752 h->vbi_dev->minor == minor) {
754 type = V4L2_BUF_TYPE_VBI_CAPTURE;
757 h->radio_dev->minor == minor) {
765 dprintk(1, "open minor=%d radio=%d type=%s\n",
766 minor, radio, v4l2_type_names[type]);
768 /* allocate + initialize per filehandle data */
769 fh = kzalloc(sizeof(*fh), GFP_KERNEL);
772 file->private_data = fh;
778 fh->fmt = format_by_fourcc(V4L2_PIX_FMT_BGR24);
780 videobuf_queue_pci_init(&fh->vidq, &cx23885_video_qops,
781 dev->pci, &dev->slock,
782 V4L2_BUF_TYPE_VIDEO_CAPTURE,
783 V4L2_FIELD_INTERLACED,
784 sizeof(struct cx23885_buffer),
787 dprintk(1, "post videobuf_queue_init()\n");
793 static ssize_t video_read(struct file *file, char __user *data,
794 size_t count, loff_t *ppos)
796 struct cx23885_fh *fh = file->private_data;
799 case V4L2_BUF_TYPE_VIDEO_CAPTURE:
800 if (res_locked(fh->dev, RESOURCE_VIDEO))
802 return videobuf_read_one(&fh->vidq, data, count, ppos,
803 file->f_flags & O_NONBLOCK);
804 case V4L2_BUF_TYPE_VBI_CAPTURE:
805 if (!res_get(fh->dev, fh, RESOURCE_VBI))
807 return videobuf_read_stream(&fh->vbiq, data, count, ppos, 1,
808 file->f_flags & O_NONBLOCK);
815 static unsigned int video_poll(struct file *file,
816 struct poll_table_struct *wait)
818 struct cx23885_fh *fh = file->private_data;
819 struct cx23885_buffer *buf;
821 if (V4L2_BUF_TYPE_VBI_CAPTURE == fh->type) {
822 if (!res_get(fh->dev, fh, RESOURCE_VBI))
824 return videobuf_poll_stream(file, &fh->vbiq, wait);
827 if (res_check(fh, RESOURCE_VIDEO)) {
828 /* streaming capture */
829 if (list_empty(&fh->vidq.stream))
831 buf = list_entry(fh->vidq.stream.next,
832 struct cx23885_buffer, vb.stream);
835 buf = (struct cx23885_buffer *)fh->vidq.read_buf;
839 poll_wait(file, &buf->vb.done, wait);
840 if (buf->vb.state == VIDEOBUF_DONE ||
841 buf->vb.state == VIDEOBUF_ERROR)
842 return POLLIN|POLLRDNORM;
846 static int video_release(struct inode *inode, struct file *file)
848 struct cx23885_fh *fh = file->private_data;
849 struct cx23885_dev *dev = fh->dev;
851 /* turn off overlay */
852 if (res_check(fh, RESOURCE_OVERLAY)) {
854 res_free(dev, fh, RESOURCE_OVERLAY);
857 /* stop video capture */
858 if (res_check(fh, RESOURCE_VIDEO)) {
859 videobuf_queue_cancel(&fh->vidq);
860 res_free(dev, fh, RESOURCE_VIDEO);
862 if (fh->vidq.read_buf) {
863 buffer_release(&fh->vidq, fh->vidq.read_buf);
864 kfree(fh->vidq.read_buf);
867 /* stop vbi capture */
868 if (res_check(fh, RESOURCE_VBI)) {
869 if (fh->vbiq.streaming)
870 videobuf_streamoff(&fh->vbiq);
871 if (fh->vbiq.reading)
872 videobuf_read_stop(&fh->vbiq);
873 res_free(dev, fh, RESOURCE_VBI);
876 videobuf_mmap_free(&fh->vidq);
877 file->private_data = NULL;
884 static int video_mmap(struct file *file, struct vm_area_struct *vma)
886 struct cx23885_fh *fh = file->private_data;
888 return videobuf_mmap_mapper(get_queue(fh), vma);
891 /* ------------------------------------------------------------------ */
892 /* VIDEO CTRL IOCTLS */
894 int cx23885_get_control(struct cx23885_dev *dev, struct v4l2_control *ctl)
896 dprintk(1, "%s() calling cx25840(VIDIOC_G_CTRL)\n", __FUNCTION__);
897 cx23885_call_i2c_clients(&dev->i2c_bus[2], VIDIOC_G_CTRL, ctl);
900 EXPORT_SYMBOL(cx23885_get_control);
902 int cx23885_set_control(struct cx23885_dev *dev, struct v4l2_control *ctl)
904 dprintk(1, "%s() calling cx25840(VIDIOC_S_CTRL)"
905 " (disabled - no action)\n", __FUNCTION__);
908 EXPORT_SYMBOL(cx23885_set_control);
910 static void init_controls(struct cx23885_dev *dev)
912 struct v4l2_control ctrl;
915 for (i = 0; i < CX23885_CTLS; i++) {
916 ctrl.id = cx23885_ctls[i].v.id;
917 ctrl.value = cx23885_ctls[i].v.default_value;
919 cx23885_set_control(dev, &ctrl);
923 /* ------------------------------------------------------------------ */
926 static int vidioc_g_fmt_cap(struct file *file, void *priv,
927 struct v4l2_format *f)
929 struct cx23885_fh *fh = priv;
931 f->fmt.pix.width = fh->width;
932 f->fmt.pix.height = fh->height;
933 f->fmt.pix.field = fh->vidq.field;
934 f->fmt.pix.pixelformat = fh->fmt->fourcc;
935 f->fmt.pix.bytesperline =
936 (f->fmt.pix.width * fh->fmt->depth) >> 3;
937 f->fmt.pix.sizeimage =
938 f->fmt.pix.height * f->fmt.pix.bytesperline;
943 static int vidioc_try_fmt_cap(struct file *file, void *priv,
944 struct v4l2_format *f)
946 struct cx23885_dev *dev = ((struct cx23885_fh *)priv)->dev;
947 struct cx23885_fmt *fmt;
948 enum v4l2_field field;
949 unsigned int maxw, maxh;
951 fmt = format_by_fourcc(f->fmt.pix.pixelformat);
955 field = f->fmt.pix.field;
956 maxw = norm_maxw(dev->tvnorm);
957 maxh = norm_maxh(dev->tvnorm);
959 if (V4L2_FIELD_ANY == field) {
960 field = (f->fmt.pix.height > maxh/2)
961 ? V4L2_FIELD_INTERLACED
967 case V4L2_FIELD_BOTTOM:
970 case V4L2_FIELD_INTERLACED:
976 f->fmt.pix.field = field;
977 if (f->fmt.pix.height < 32)
978 f->fmt.pix.height = 32;
979 if (f->fmt.pix.height > maxh)
980 f->fmt.pix.height = maxh;
981 if (f->fmt.pix.width < 48)
982 f->fmt.pix.width = 48;
983 if (f->fmt.pix.width > maxw)
984 f->fmt.pix.width = maxw;
985 f->fmt.pix.width &= ~0x03;
986 f->fmt.pix.bytesperline =
987 (f->fmt.pix.width * fmt->depth) >> 3;
988 f->fmt.pix.sizeimage =
989 f->fmt.pix.height * f->fmt.pix.bytesperline;
994 static int vidioc_s_fmt_cap(struct file *file, void *priv,
995 struct v4l2_format *f)
997 struct cx23885_fh *fh = priv;
998 struct cx23885_dev *dev = ((struct cx23885_fh *)priv)->dev;
1001 dprintk(2, "%s()\n", __FUNCTION__);
1002 err = vidioc_try_fmt_cap(file, priv, f);
1006 fh->fmt = format_by_fourcc(f->fmt.pix.pixelformat);
1007 fh->width = f->fmt.pix.width;
1008 fh->height = f->fmt.pix.height;
1009 fh->vidq.field = f->fmt.pix.field;
1010 dprintk(2, "%s() width=%d height=%d field=%d\n", __FUNCTION__,
1011 fh->width, fh->height, fh->vidq.field);
1012 cx23885_call_i2c_clients(&dev->i2c_bus[2], VIDIOC_S_FMT, f);
1016 static int vidioc_querycap(struct file *file, void *priv,
1017 struct v4l2_capability *cap)
1019 struct cx23885_dev *dev = ((struct cx23885_fh *)priv)->dev;
1021 strcpy(cap->driver, "cx23885");
1022 strlcpy(cap->card, cx23885_boards[dev->board].name,
1024 sprintf(cap->bus_info, "PCIe:%s", pci_name(dev->pci));
1025 cap->version = CX23885_VERSION_CODE;
1027 V4L2_CAP_VIDEO_CAPTURE |
1028 V4L2_CAP_READWRITE |
1029 V4L2_CAP_STREAMING |
1030 V4L2_CAP_VBI_CAPTURE;
1031 if (UNSET != dev->tuner_type)
1032 cap->capabilities |= V4L2_CAP_TUNER;
1036 static int vidioc_enum_fmt_cap(struct file *file, void *priv,
1037 struct v4l2_fmtdesc *f)
1039 if (unlikely(f->index >= ARRAY_SIZE(formats)))
1042 strlcpy(f->description, formats[f->index].name,
1043 sizeof(f->description));
1044 f->pixelformat = formats[f->index].fourcc;
1049 #ifdef CONFIG_VIDEO_V4L1_COMPAT
1050 static int vidiocgmbuf(struct file *file, void *priv,
1051 struct video_mbuf *mbuf)
1053 struct cx23885_fh *fh = priv;
1054 struct videobuf_queue *q;
1055 struct v4l2_requestbuffers req;
1060 memset(&req, 0, sizeof(req));
1063 req.memory = V4L2_MEMORY_MMAP;
1064 err = videobuf_reqbufs(q, &req);
1068 mbuf->frames = req.count;
1070 for (i = 0; i < mbuf->frames; i++) {
1071 mbuf->offsets[i] = q->bufs[i]->boff;
1072 mbuf->size += q->bufs[i]->bsize;
1078 static int vidioc_reqbufs(struct file *file, void *priv,
1079 struct v4l2_requestbuffers *p)
1081 struct cx23885_fh *fh = priv;
1082 return (videobuf_reqbufs(get_queue(fh), p));
1085 static int vidioc_querybuf(struct file *file, void *priv,
1086 struct v4l2_buffer *p)
1088 struct cx23885_fh *fh = priv;
1089 return (videobuf_querybuf(get_queue(fh), p));
1092 static int vidioc_qbuf(struct file *file, void *priv,
1093 struct v4l2_buffer *p)
1095 struct cx23885_fh *fh = priv;
1096 return (videobuf_qbuf(get_queue(fh), p));
1099 static int vidioc_dqbuf(struct file *file, void *priv,
1100 struct v4l2_buffer *p)
1102 struct cx23885_fh *fh = priv;
1103 return (videobuf_dqbuf(get_queue(fh), p,
1104 file->f_flags & O_NONBLOCK));
1107 static int vidioc_streamon(struct file *file, void *priv,
1108 enum v4l2_buf_type i)
1110 struct cx23885_fh *fh = priv;
1111 struct cx23885_dev *dev = fh->dev;
1112 dprintk(1, "%s()\n", __FUNCTION__);
1114 if (unlikely(fh->type != V4L2_BUF_TYPE_VIDEO_CAPTURE))
1116 if (unlikely(i != fh->type))
1119 if (unlikely(!res_get(dev, fh, get_resource(fh))))
1121 return videobuf_streamon(get_queue(fh));
1124 static int vidioc_streamoff(struct file *file, void *priv, enum v4l2_buf_type i)
1126 struct cx23885_fh *fh = priv;
1127 struct cx23885_dev *dev = fh->dev;
1129 dprintk(1, "%s()\n", __FUNCTION__);
1131 if (fh->type != V4L2_BUF_TYPE_VIDEO_CAPTURE)
1136 res = get_resource(fh);
1137 err = videobuf_streamoff(get_queue(fh));
1140 res_free(dev, fh, res);
1144 static int vidioc_s_std(struct file *file, void *priv, v4l2_std_id *tvnorms)
1146 struct cx23885_dev *dev = ((struct cx23885_fh *)priv)->dev;
1147 dprintk(1, "%s()\n", __FUNCTION__);
1149 mutex_lock(&dev->lock);
1150 cx23885_set_tvnorm(dev, *tvnorms);
1151 mutex_unlock(&dev->lock);
1156 int cx23885_enum_input(struct cx23885_dev *dev, struct v4l2_input *i)
1158 static const char *iname[] = {
1159 [CX23885_VMUX_COMPOSITE1] = "Composite1",
1160 [CX23885_VMUX_COMPOSITE2] = "Composite2",
1161 [CX23885_VMUX_COMPOSITE3] = "Composite3",
1162 [CX23885_VMUX_COMPOSITE4] = "Composite4",
1163 [CX23885_VMUX_SVIDEO] = "S-Video",
1164 [CX23885_VMUX_TELEVISION] = "Television",
1165 [CX23885_VMUX_CABLE] = "Cable TV",
1166 [CX23885_VMUX_DVB] = "DVB",
1167 [CX23885_VMUX_DEBUG] = "for debug only",
1170 dprintk(1, "%s()\n", __FUNCTION__);
1176 if (0 == INPUT(n)->type)
1179 memset(i, 0, sizeof(*i));
1181 i->type = V4L2_INPUT_TYPE_CAMERA;
1182 strcpy(i->name, iname[INPUT(n)->type]);
1183 if ((CX23885_VMUX_TELEVISION == INPUT(n)->type) ||
1184 (CX23885_VMUX_CABLE == INPUT(n)->type))
1185 i->type = V4L2_INPUT_TYPE_TUNER;
1186 i->std = CX23885_NORMS;
1189 EXPORT_SYMBOL(cx23885_enum_input);
1191 static int vidioc_enum_input(struct file *file, void *priv,
1192 struct v4l2_input *i)
1194 struct cx23885_dev *dev = ((struct cx23885_fh *)priv)->dev;
1195 dprintk(1, "%s()\n", __FUNCTION__);
1196 return cx23885_enum_input(dev, i);
1199 static int vidioc_g_input(struct file *file, void *priv, unsigned int *i)
1201 struct cx23885_dev *dev = ((struct cx23885_fh *)priv)->dev;
1204 dprintk(1, "%s() returns %d\n", __FUNCTION__, *i);
1208 static int vidioc_s_input(struct file *file, void *priv, unsigned int i)
1210 struct cx23885_dev *dev = ((struct cx23885_fh *)priv)->dev;
1212 dprintk(1, "%s(%d)\n", __FUNCTION__, i);
1215 dprintk(1, "%s() -EINVAL\n", __FUNCTION__);
1219 mutex_lock(&dev->lock);
1220 cx23885_video_mux(dev, i);
1221 mutex_unlock(&dev->lock);
1225 static int vidioc_queryctrl(struct file *file, void *priv,
1226 struct v4l2_queryctrl *qctrl)
1228 qctrl->id = v4l2_ctrl_next(ctrl_classes, qctrl->id);
1229 if (unlikely(qctrl->id == 0))
1231 return cx23885_ctrl_query(qctrl);
1234 static int vidioc_g_ctrl(struct file *file, void *priv,
1235 struct v4l2_control *ctl)
1237 struct cx23885_dev *dev = ((struct cx23885_fh *)priv)->dev;
1239 return cx23885_get_control(dev, ctl);
1242 static int vidioc_s_ctrl(struct file *file, void *priv,
1243 struct v4l2_control *ctl)
1245 struct cx23885_dev *dev = ((struct cx23885_fh *)priv)->dev;
1247 return cx23885_set_control(dev, ctl);
1250 static int vidioc_g_tuner(struct file *file, void *priv,
1251 struct v4l2_tuner *t)
1253 struct cx23885_dev *dev = ((struct cx23885_fh *)priv)->dev;
1255 if (unlikely(UNSET == dev->tuner_type))
1260 strcpy(t->name, "Television");
1261 t->type = V4L2_TUNER_ANALOG_TV;
1262 t->capability = V4L2_TUNER_CAP_NORM;
1263 t->rangehigh = 0xffffffffUL;
1264 t->signal = 0xffff ; /* LOCKED */
1268 static int vidioc_s_tuner(struct file *file, void *priv,
1269 struct v4l2_tuner *t)
1271 struct cx23885_dev *dev = ((struct cx23885_fh *)priv)->dev;
1273 if (UNSET == dev->tuner_type)
1280 static int vidioc_g_frequency(struct file *file, void *priv,
1281 struct v4l2_frequency *f)
1283 struct cx23885_fh *fh = priv;
1284 struct cx23885_dev *dev = fh->dev;
1286 if (unlikely(UNSET == dev->tuner_type))
1289 /* f->type = fh->radio ? V4L2_TUNER_RADIO : V4L2_TUNER_ANALOG_TV; */
1290 f->type = fh->radio ? V4L2_TUNER_RADIO : V4L2_TUNER_ANALOG_TV;
1291 f->frequency = dev->freq;
1293 cx23885_call_i2c_clients(&dev->i2c_bus[1], VIDIOC_G_FREQUENCY, f);
1298 int cx23885_set_freq(struct cx23885_dev *dev, struct v4l2_frequency *f)
1300 if (unlikely(UNSET == dev->tuner_type))
1302 if (unlikely(f->tuner != 0))
1305 mutex_lock(&dev->lock);
1306 dev->freq = f->frequency;
1308 cx23885_call_i2c_clients(&dev->i2c_bus[1], VIDIOC_S_FREQUENCY, f);
1310 /* When changing channels it is required to reset TVAUDIO */
1313 mutex_unlock(&dev->lock);
1317 EXPORT_SYMBOL(cx23885_set_freq);
1319 static int vidioc_s_frequency(struct file *file, void *priv,
1320 struct v4l2_frequency *f)
1322 struct cx23885_fh *fh = priv;
1323 struct cx23885_dev *dev = fh->dev;
1325 if (unlikely(0 == fh->radio && f->type != V4L2_TUNER_ANALOG_TV))
1327 if (unlikely(1 == fh->radio && f->type != V4L2_TUNER_RADIO))
1331 cx23885_set_freq(dev, f);
1334 #ifdef CONFIG_VIDEO_ADV_DEBUG
1335 static int vidioc_g_register(struct file *file, void *fh,
1336 struct v4l2_register *reg)
1338 struct cx23885_dev *dev = ((struct cx23885_fh *)fh)->dev;
1340 cx23885_call_i2c_clients(&dev->i2c_bus[2], VIDIOC_DBG_G_REGISTER, reg);
1345 static int vidioc_s_register(struct file *file, void *fh,
1346 struct v4l2_register *reg)
1348 struct cx23885_dev *dev = ((struct cx23885_fh *)fh)->dev;
1350 cx23885_call_i2c_clients(&dev->i2c_bus[2], VIDIOC_DBG_S_REGISTER, reg);
1355 /* ----------------------------------------------------------- */
1356 /* RADIO ESPECIFIC IOCTLS */
1357 /* ----------------------------------------------------------- */
1359 static int radio_querycap(struct file *file, void *priv,
1360 struct v4l2_capability *cap)
1362 struct cx23885_dev *dev = ((struct cx23885_fh *)priv)->dev;
1364 strcpy(cap->driver, "cx23885");
1365 strlcpy(cap->card, cx23885_boards[dev->board].name,
1367 sprintf(cap->bus_info, "PCIe:%s", pci_name(dev->pci));
1368 cap->version = CX23885_VERSION_CODE;
1369 cap->capabilities = V4L2_CAP_TUNER;
1373 static int radio_g_tuner(struct file *file, void *priv,
1374 struct v4l2_tuner *t)
1376 struct cx23885_dev *dev = ((struct cx23885_fh *)priv)->dev;
1378 if (unlikely(t->index > 0))
1381 strcpy(t->name, "Radio");
1382 t->type = V4L2_TUNER_RADIO;
1384 cx23885_call_i2c_clients(&dev->i2c_bus[1], VIDIOC_G_TUNER, t);
1388 static int radio_enum_input(struct file *file, void *priv,
1389 struct v4l2_input *i)
1393 strcpy(i->name, "Radio");
1394 i->type = V4L2_INPUT_TYPE_TUNER;
1399 static int radio_g_audio(struct file *file, void *priv, struct v4l2_audio *a)
1401 if (unlikely(a->index))
1404 memset(a, 0, sizeof(*a));
1405 strcpy(a->name, "Radio");
1409 /* FIXME: Should add a standard for radio */
1411 static int radio_s_tuner(struct file *file, void *priv,
1412 struct v4l2_tuner *t)
1414 struct cx23885_dev *dev = ((struct cx23885_fh *)priv)->dev;
1419 cx23885_call_i2c_clients(&dev->i2c_bus[1], VIDIOC_S_TUNER, t);
1424 static int radio_s_audio(struct file *file, void *fh,
1425 struct v4l2_audio *a)
1430 static int radio_s_input(struct file *file, void *fh, unsigned int i)
1435 static int radio_queryctrl(struct file *file, void *priv,
1436 struct v4l2_queryctrl *c)
1440 if (c->id < V4L2_CID_BASE ||
1441 c->id >= V4L2_CID_LASTP1)
1443 if (c->id == V4L2_CID_AUDIO_MUTE) {
1444 for (i = 0; i < CX23885_CTLS; i++)
1445 if (cx23885_ctls[i].v.id == c->id)
1447 *c = cx23885_ctls[i].v;
1453 /* ----------------------------------------------------------- */
1455 static void cx23885_vid_timeout(unsigned long data)
1457 struct cx23885_dev *dev = (struct cx23885_dev *)data;
1458 struct cx23885_dmaqueue *q = &dev->vidq;
1459 struct cx23885_buffer *buf;
1460 unsigned long flags;
1462 cx23885_sram_channel_dump(dev, &dev->sram_channels[SRAM_CH01]);
1464 cx_clear(VID_A_DMA_CTL, 0x11);
1466 spin_lock_irqsave(&dev->slock, flags);
1467 while (!list_empty(&q->active)) {
1468 buf = list_entry(q->active.next,
1469 struct cx23885_buffer, vb.queue);
1470 list_del(&buf->vb.queue);
1471 buf->vb.state = VIDEOBUF_ERROR;
1472 wake_up(&buf->vb.done);
1473 printk(KERN_ERR "%s/0: [%p/%d] timeout - dma=0x%08lx\n",
1474 dev->name, buf, buf->vb.i,
1475 (unsigned long)buf->risc.dma);
1477 cx23885_restart_video_queue(dev, q);
1478 spin_unlock_irqrestore(&dev->slock, flags);
1481 int cx23885_video_irq(struct cx23885_dev *dev, u32 status)
1486 mask = cx_read(VID_A_INT_MSK);
1487 if (0 == (status & mask))
1489 cx_write(VID_A_INT_STAT, status);
1491 dprintk(2, "%s() status = 0x%08x\n", __FUNCTION__, status);
1492 /* risc op code error */
1493 if (status & (1 << 16)) {
1494 printk(KERN_WARNING "%s/0: video risc op code error\n",
1496 cx_clear(VID_A_DMA_CTL, 0x11);
1497 cx23885_sram_channel_dump(dev, &dev->sram_channels[SRAM_CH01]);
1501 if (status & 0x01) {
1502 spin_lock(&dev->slock);
1503 count = cx_read(VID_A_GPCNT);
1504 cx23885_video_wakeup(dev, &dev->vidq, count);
1505 spin_unlock(&dev->slock);
1509 if (status & 0x10) {
1510 dprintk(2, "stopper video\n");
1511 spin_lock(&dev->slock);
1512 cx23885_restart_video_queue(dev, &dev->vidq);
1513 spin_unlock(&dev->slock);
1521 /* ----------------------------------------------------------- */
1522 /* exported stuff */
1524 static const struct file_operations video_fops = {
1525 .owner = THIS_MODULE,
1527 .release = video_release,
1531 .ioctl = video_ioctl2,
1532 .compat_ioctl = v4l_compat_ioctl32,
1533 .llseek = no_llseek,
1536 static struct video_device cx23885_vbi_template;
1537 static struct video_device cx23885_video_template = {
1538 .name = "cx23885-video",
1539 .type = VID_TYPE_CAPTURE|VID_TYPE_TUNER|VID_TYPE_SCALES,
1540 .fops = &video_fops,
1542 .vidioc_querycap = vidioc_querycap,
1543 .vidioc_enum_fmt_cap = vidioc_enum_fmt_cap,
1544 .vidioc_g_fmt_cap = vidioc_g_fmt_cap,
1545 .vidioc_try_fmt_cap = vidioc_try_fmt_cap,
1546 .vidioc_s_fmt_cap = vidioc_s_fmt_cap,
1547 .vidioc_g_fmt_vbi = cx23885_vbi_fmt,
1548 .vidioc_try_fmt_vbi = cx23885_vbi_fmt,
1549 .vidioc_s_fmt_vbi = cx23885_vbi_fmt,
1550 .vidioc_reqbufs = vidioc_reqbufs,
1551 .vidioc_querybuf = vidioc_querybuf,
1552 .vidioc_qbuf = vidioc_qbuf,
1553 .vidioc_dqbuf = vidioc_dqbuf,
1554 .vidioc_s_std = vidioc_s_std,
1555 .vidioc_enum_input = vidioc_enum_input,
1556 .vidioc_g_input = vidioc_g_input,
1557 .vidioc_s_input = vidioc_s_input,
1558 .vidioc_queryctrl = vidioc_queryctrl,
1559 .vidioc_g_ctrl = vidioc_g_ctrl,
1560 .vidioc_s_ctrl = vidioc_s_ctrl,
1561 .vidioc_streamon = vidioc_streamon,
1562 .vidioc_streamoff = vidioc_streamoff,
1563 #ifdef CONFIG_VIDEO_V4L1_COMPAT
1564 .vidiocgmbuf = vidiocgmbuf,
1566 .vidioc_g_tuner = vidioc_g_tuner,
1567 .vidioc_s_tuner = vidioc_s_tuner,
1568 .vidioc_g_frequency = vidioc_g_frequency,
1569 .vidioc_s_frequency = vidioc_s_frequency,
1570 #ifdef CONFIG_VIDEO_ADV_DEBUG
1571 .vidioc_g_register = vidioc_g_register,
1572 .vidioc_s_register = vidioc_s_register,
1574 .tvnorms = CX23885_NORMS,
1575 .current_norm = V4L2_STD_NTSC_M,
1578 static const struct file_operations radio_fops = {
1579 .owner = THIS_MODULE,
1581 .release = video_release,
1582 .ioctl = video_ioctl2,
1583 .compat_ioctl = v4l_compat_ioctl32,
1584 .llseek = no_llseek,
1588 void cx23885_video_unregister(struct cx23885_dev *dev)
1590 dprintk(1, "%s()\n", __FUNCTION__);
1591 cx_clear(PCI_INT_MSK, 1);
1593 if (dev->video_dev) {
1594 if (-1 != dev->video_dev->minor)
1595 video_unregister_device(dev->video_dev);
1597 video_device_release(dev->video_dev);
1598 dev->video_dev = NULL;
1600 btcx_riscmem_free(dev->pci, &dev->vidq.stopper);
1604 int cx23885_video_register(struct cx23885_dev *dev)
1608 dprintk(1, "%s()\n", __FUNCTION__);
1609 spin_lock_init(&dev->slock);
1611 /* Initialize VBI template */
1612 memcpy(&cx23885_vbi_template, &cx23885_video_template,
1613 sizeof(cx23885_vbi_template));
1614 strcpy(cx23885_vbi_template.name, "cx23885-vbi");
1615 cx23885_vbi_template.type = VID_TYPE_TELETEXT|VID_TYPE_TUNER;
1617 dev->tvnorm = cx23885_video_template.current_norm;
1619 /* init video dma queues */
1620 INIT_LIST_HEAD(&dev->vidq.active);
1621 INIT_LIST_HEAD(&dev->vidq.queued);
1622 dev->vidq.timeout.function = cx23885_vid_timeout;
1623 dev->vidq.timeout.data = (unsigned long)dev;
1624 init_timer(&dev->vidq.timeout);
1625 cx23885_risc_stopper(dev->pci, &dev->vidq.stopper,
1626 VID_A_DMA_CTL, 0x11, 0x00);
1628 cx_set(PCI_INT_MSK, 1);
1631 /* register v4l devices */
1632 dev->video_dev = cx23885_vdev_init(dev, dev->pci,
1633 &cx23885_video_template, "video");
1634 err = video_register_device(dev->video_dev, VFL_TYPE_GRABBER,
1637 printk(KERN_INFO "%s: can't register video device\n",
1641 printk(KERN_INFO "%s/0: registered device video%d [v4l2]\n",
1642 dev->name, dev->video_dev->minor & 0x1f);
1643 /* initial device configuration */
1644 mutex_lock(&dev->lock);
1645 cx23885_set_tvnorm(dev, dev->tvnorm);
1647 cx23885_video_mux(dev, 0);
1648 mutex_unlock(&dev->lock);
1650 /* FIXME start tvaudio thread */
1655 cx23885_video_unregister(dev);