2 * Driver for the Conexant CX23885 PCIe bridge
4 * Copyright (c) 2007 Steven Toth <stoth@linuxtv.org>
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>
36 #include <media/v4l2-ioctl.h>
38 MODULE_DESCRIPTION("v4l2 driver module for cx23885 based TV cards");
39 MODULE_AUTHOR("Steven Toth <stoth@linuxtv.org>");
40 MODULE_LICENSE("GPL");
42 /* ------------------------------------------------------------------ */
44 static unsigned int video_nr
[] = {[0 ... (CX23885_MAXBOARDS
- 1)] = UNSET
};
45 static unsigned int vbi_nr
[] = {[0 ... (CX23885_MAXBOARDS
- 1)] = UNSET
};
46 static unsigned int radio_nr
[] = {[0 ... (CX23885_MAXBOARDS
- 1)] = UNSET
};
48 module_param_array(video_nr
, int, NULL
, 0444);
49 module_param_array(vbi_nr
, int, NULL
, 0444);
50 module_param_array(radio_nr
, int, NULL
, 0444);
52 MODULE_PARM_DESC(video_nr
, "video device numbers");
53 MODULE_PARM_DESC(vbi_nr
, "vbi device numbers");
54 MODULE_PARM_DESC(radio_nr
, "radio device numbers");
56 static unsigned int video_debug
;
57 module_param(video_debug
, int, 0644);
58 MODULE_PARM_DESC(video_debug
, "enable debug messages [video]");
60 static unsigned int irq_debug
;
61 module_param(irq_debug
, int, 0644);
62 MODULE_PARM_DESC(irq_debug
, "enable debug messages [IRQ handler]");
64 static unsigned int vid_limit
= 16;
65 module_param(vid_limit
, int, 0644);
66 MODULE_PARM_DESC(vid_limit
, "capture memory limit in megabytes");
68 #define dprintk(level, fmt, arg...)\
69 do { if (video_debug >= level)\
70 printk(KERN_DEBUG "%s/0: " fmt, dev->name, ## arg);\
73 /* ------------------------------------------------------------------- */
76 #define FORMAT_FLAGS_PACKED 0x01
78 static struct cx23885_fmt formats
[] = {
80 .name
= "8 bpp, gray",
81 .fourcc
= V4L2_PIX_FMT_GREY
,
83 .flags
= FORMAT_FLAGS_PACKED
,
85 .name
= "15 bpp RGB, le",
86 .fourcc
= V4L2_PIX_FMT_RGB555
,
88 .flags
= FORMAT_FLAGS_PACKED
,
90 .name
= "15 bpp RGB, be",
91 .fourcc
= V4L2_PIX_FMT_RGB555X
,
93 .flags
= FORMAT_FLAGS_PACKED
,
95 .name
= "16 bpp RGB, le",
96 .fourcc
= V4L2_PIX_FMT_RGB565
,
98 .flags
= FORMAT_FLAGS_PACKED
,
100 .name
= "16 bpp RGB, be",
101 .fourcc
= V4L2_PIX_FMT_RGB565X
,
103 .flags
= FORMAT_FLAGS_PACKED
,
105 .name
= "24 bpp RGB, le",
106 .fourcc
= V4L2_PIX_FMT_BGR24
,
108 .flags
= FORMAT_FLAGS_PACKED
,
110 .name
= "32 bpp RGB, le",
111 .fourcc
= V4L2_PIX_FMT_BGR32
,
113 .flags
= FORMAT_FLAGS_PACKED
,
115 .name
= "32 bpp RGB, be",
116 .fourcc
= V4L2_PIX_FMT_RGB32
,
118 .flags
= FORMAT_FLAGS_PACKED
,
120 .name
= "4:2:2, packed, YUYV",
121 .fourcc
= V4L2_PIX_FMT_YUYV
,
123 .flags
= FORMAT_FLAGS_PACKED
,
125 .name
= "4:2:2, packed, UYVY",
126 .fourcc
= V4L2_PIX_FMT_UYVY
,
128 .flags
= FORMAT_FLAGS_PACKED
,
132 static struct cx23885_fmt
*format_by_fourcc(unsigned int fourcc
)
136 for (i
= 0; i
< ARRAY_SIZE(formats
); i
++)
137 if (formats
[i
].fourcc
== fourcc
)
140 printk(KERN_ERR
"%s(0x%08x) NOT FOUND\n", __func__
, fourcc
);
144 /* ------------------------------------------------------------------- */
146 static const struct v4l2_queryctrl no_ctl
= {
148 .flags
= V4L2_CTRL_FLAG_DISABLED
,
151 static struct cx23885_ctrl cx23885_ctls
[] = {
155 .id
= V4L2_CID_BRIGHTNESS
,
156 .name
= "Brightness",
160 .default_value
= 0x7f,
161 .type
= V4L2_CTRL_TYPE_INTEGER
,
169 .id
= V4L2_CID_CONTRAST
,
174 .default_value
= 0x3f,
175 .type
= V4L2_CTRL_TYPE_INTEGER
,
188 .default_value
= 0x7f,
189 .type
= V4L2_CTRL_TYPE_INTEGER
,
196 /* strictly, this only describes only U saturation.
197 * V saturation is handled specially through code.
200 .id
= V4L2_CID_SATURATION
,
201 .name
= "Saturation",
205 .default_value
= 0x7f,
206 .type
= V4L2_CTRL_TYPE_INTEGER
,
215 .id
= V4L2_CID_AUDIO_MUTE
,
220 .type
= V4L2_CTRL_TYPE_BOOLEAN
,
223 .mask
= (0x1f << 24),
227 .id
= V4L2_CID_AUDIO_VOLUME
,
232 .default_value
= 0x3f,
233 .type
= V4L2_CTRL_TYPE_INTEGER
,
235 .reg
= PATH1_VOL_CTL
,
240 static const int CX23885_CTLS
= ARRAY_SIZE(cx23885_ctls
);
242 /* Must be sorted from low to high control ID! */
243 static const u32 cx23885_user_ctrls
[] = {
249 V4L2_CID_AUDIO_VOLUME
,
254 static const u32
*ctrl_classes
[] = {
259 static void cx23885_video_wakeup(struct cx23885_dev
*dev
,
260 struct cx23885_dmaqueue
*q
, u32 count
)
262 struct cx23885_buffer
*buf
;
265 for (bc
= 0;; bc
++) {
266 if (list_empty(&q
->active
))
268 buf
= list_entry(q
->active
.next
,
269 struct cx23885_buffer
, vb
.queue
);
271 /* count comes from the hw and is is 16bit wide --
272 * this trick handles wrap-arounds correctly for
273 * up to 32767 buffers in flight... */
274 if ((s16
) (count
- buf
->count
) < 0)
277 do_gettimeofday(&buf
->vb
.ts
);
278 dprintk(2, "[%p/%d] wakeup reg=%d buf=%d\n", buf
, buf
->vb
.i
,
280 buf
->vb
.state
= VIDEOBUF_DONE
;
281 list_del(&buf
->vb
.queue
);
282 wake_up(&buf
->vb
.done
);
284 if (list_empty(&q
->active
))
285 del_timer(&q
->timeout
);
287 mod_timer(&q
->timeout
, jiffies
+BUFFER_TIMEOUT
);
289 printk(KERN_ERR
"%s: %d buffers handled (should be 1)\n",
293 static int cx23885_set_tvnorm(struct cx23885_dev
*dev
, v4l2_std_id norm
)
295 dprintk(1, "%s(norm = 0x%08x) name: [%s]\n",
298 v4l2_norm_to_name(norm
));
302 call_all(dev
, core
, s_std
, norm
);
307 static struct video_device
*cx23885_vdev_init(struct cx23885_dev
*dev
,
309 struct video_device
*template,
312 struct video_device
*vfd
;
313 dprintk(1, "%s()\n", __func__
);
315 vfd
= video_device_alloc();
320 vfd
->v4l2_dev
= &dev
->v4l2_dev
;
321 vfd
->release
= video_device_release
;
322 snprintf(vfd
->name
, sizeof(vfd
->name
), "%s %s (%s)",
323 dev
->name
, type
, cx23885_boards
[dev
->board
].name
);
327 static int cx23885_ctrl_query(struct v4l2_queryctrl
*qctrl
)
331 if (qctrl
->id
< V4L2_CID_BASE
||
332 qctrl
->id
>= V4L2_CID_LASTP1
)
334 for (i
= 0; i
< CX23885_CTLS
; i
++)
335 if (cx23885_ctls
[i
].v
.id
== qctrl
->id
)
337 if (i
== CX23885_CTLS
) {
341 *qctrl
= cx23885_ctls
[i
].v
;
345 /* ------------------------------------------------------------------- */
346 /* resource management */
348 static int res_get(struct cx23885_dev
*dev
, struct cx23885_fh
*fh
,
351 dprintk(1, "%s()\n", __func__
);
352 if (fh
->resources
& bit
)
353 /* have it already allocated */
357 mutex_lock(&dev
->lock
);
358 if (dev
->resources
& bit
) {
359 /* no, someone else uses it */
360 mutex_unlock(&dev
->lock
);
363 /* it's free, grab it */
364 fh
->resources
|= bit
;
365 dev
->resources
|= bit
;
366 dprintk(1, "res: get %d\n", bit
);
367 mutex_unlock(&dev
->lock
);
371 static int res_check(struct cx23885_fh
*fh
, unsigned int bit
)
373 return fh
->resources
& bit
;
376 static int res_locked(struct cx23885_dev
*dev
, unsigned int bit
)
378 return dev
->resources
& bit
;
381 static void res_free(struct cx23885_dev
*dev
, struct cx23885_fh
*fh
,
384 BUG_ON((fh
->resources
& bits
) != bits
);
385 dprintk(1, "%s()\n", __func__
);
387 mutex_lock(&dev
->lock
);
388 fh
->resources
&= ~bits
;
389 dev
->resources
&= ~bits
;
390 dprintk(1, "res: put %d\n", bits
);
391 mutex_unlock(&dev
->lock
);
394 static int cx23885_video_mux(struct cx23885_dev
*dev
, unsigned int input
)
396 dprintk(1, "%s() video_mux: %d [vmux=%d, gpio=0x%x,0x%x,0x%x,0x%x]\n",
398 input
, INPUT(input
)->vmux
,
399 INPUT(input
)->gpio0
, INPUT(input
)->gpio1
,
400 INPUT(input
)->gpio2
, INPUT(input
)->gpio3
);
403 /* Tell the internal A/V decoder */
404 v4l2_subdev_call(dev
->sd_cx25840
, video
, s_routing
,
405 INPUT(input
)->vmux
, 0, 0);
410 /* ------------------------------------------------------------------ */
411 static int cx23885_set_scale(struct cx23885_dev
*dev
, unsigned int width
,
412 unsigned int height
, enum v4l2_field field
)
414 dprintk(1, "%s()\n", __func__
);
418 static int cx23885_start_video_dma(struct cx23885_dev
*dev
,
419 struct cx23885_dmaqueue
*q
,
420 struct cx23885_buffer
*buf
)
422 dprintk(1, "%s()\n", __func__
);
424 /* setup fifo + format */
425 cx23885_sram_channel_setup(dev
, &dev
->sram_channels
[SRAM_CH01
],
426 buf
->bpl
, buf
->risc
.dma
);
427 cx23885_set_scale(dev
, buf
->vb
.width
, buf
->vb
.height
, buf
->vb
.field
);
430 cx_write(VID_A_GPCNT_CTL
, 3);
434 cx_set(PCI_INT_MSK
, cx_read(PCI_INT_MSK
) | 0x01);
435 cx_set(VID_A_INT_MSK
, 0x000011);
438 cx_set(DEV_CNTRL2
, (1<<5));
439 cx_set(VID_A_DMA_CTL
, 0x11); /* FIFO and RISC enable */
445 static int cx23885_restart_video_queue(struct cx23885_dev
*dev
,
446 struct cx23885_dmaqueue
*q
)
448 struct cx23885_buffer
*buf
, *prev
;
449 struct list_head
*item
;
450 dprintk(1, "%s()\n", __func__
);
452 if (!list_empty(&q
->active
)) {
453 buf
= list_entry(q
->active
.next
, struct cx23885_buffer
,
455 dprintk(2, "restart_queue [%p/%d]: restart dma\n",
457 cx23885_start_video_dma(dev
, q
, buf
);
458 list_for_each(item
, &q
->active
) {
459 buf
= list_entry(item
, struct cx23885_buffer
,
461 buf
->count
= q
->count
++;
463 mod_timer(&q
->timeout
, jiffies
+BUFFER_TIMEOUT
);
469 if (list_empty(&q
->queued
))
471 buf
= list_entry(q
->queued
.next
, struct cx23885_buffer
,
474 list_move_tail(&buf
->vb
.queue
, &q
->active
);
475 cx23885_start_video_dma(dev
, q
, buf
);
476 buf
->vb
.state
= VIDEOBUF_ACTIVE
;
477 buf
->count
= q
->count
++;
478 mod_timer(&q
->timeout
, jiffies
+BUFFER_TIMEOUT
);
479 dprintk(2, "[%p/%d] restart_queue - first active\n",
482 } else if (prev
->vb
.width
== buf
->vb
.width
&&
483 prev
->vb
.height
== buf
->vb
.height
&&
484 prev
->fmt
== buf
->fmt
) {
485 list_move_tail(&buf
->vb
.queue
, &q
->active
);
486 buf
->vb
.state
= VIDEOBUF_ACTIVE
;
487 buf
->count
= q
->count
++;
488 prev
->risc
.jmp
[1] = cpu_to_le32(buf
->risc
.dma
);
489 prev
->risc
.jmp
[2] = cpu_to_le32(0); /* Bits 63 - 32 */
490 dprintk(2, "[%p/%d] restart_queue - move to active\n",
499 static int buffer_setup(struct videobuf_queue
*q
, unsigned int *count
,
502 struct cx23885_fh
*fh
= q
->priv_data
;
504 *size
= fh
->fmt
->depth
*fh
->width
*fh
->height
>> 3;
507 while (*size
* *count
> vid_limit
* 1024 * 1024)
512 static int buffer_prepare(struct videobuf_queue
*q
, struct videobuf_buffer
*vb
,
513 enum v4l2_field field
)
515 struct cx23885_fh
*fh
= q
->priv_data
;
516 struct cx23885_dev
*dev
= fh
->dev
;
517 struct cx23885_buffer
*buf
=
518 container_of(vb
, struct cx23885_buffer
, vb
);
519 int rc
, init_buffer
= 0;
520 u32 line0_offset
, line1_offset
;
521 struct videobuf_dmabuf
*dma
= videobuf_to_dma(&buf
->vb
);
523 BUG_ON(NULL
== fh
->fmt
);
524 if (fh
->width
< 48 || fh
->width
> norm_maxw(dev
->tvnorm
) ||
525 fh
->height
< 32 || fh
->height
> norm_maxh(dev
->tvnorm
))
527 buf
->vb
.size
= (fh
->width
* fh
->height
* fh
->fmt
->depth
) >> 3;
528 if (0 != buf
->vb
.baddr
&& buf
->vb
.bsize
< buf
->vb
.size
)
531 if (buf
->fmt
!= fh
->fmt
||
532 buf
->vb
.width
!= fh
->width
||
533 buf
->vb
.height
!= fh
->height
||
534 buf
->vb
.field
!= field
) {
536 buf
->vb
.width
= fh
->width
;
537 buf
->vb
.height
= fh
->height
;
538 buf
->vb
.field
= field
;
542 if (VIDEOBUF_NEEDS_INIT
== buf
->vb
.state
) {
544 rc
= videobuf_iolock(q
, &buf
->vb
, NULL
);
550 buf
->bpl
= buf
->vb
.width
* buf
->fmt
->depth
>> 3;
551 switch (buf
->vb
.field
) {
553 cx23885_risc_buffer(dev
->pci
, &buf
->risc
,
554 dma
->sglist
, 0, UNSET
,
555 buf
->bpl
, 0, buf
->vb
.height
);
557 case V4L2_FIELD_BOTTOM
:
558 cx23885_risc_buffer(dev
->pci
, &buf
->risc
,
559 dma
->sglist
, UNSET
, 0,
560 buf
->bpl
, 0, buf
->vb
.height
);
562 case V4L2_FIELD_INTERLACED
:
563 if (dev
->tvnorm
& V4L2_STD_NTSC
) {
564 /* cx25840 transmits NTSC bottom field first */
565 dprintk(1, "%s() Creating NTSC risc\n",
567 line0_offset
= buf
->bpl
;
570 /* All other formats are top field first */
571 dprintk(1, "%s() Creating PAL/SECAM risc\n",
574 line1_offset
= buf
->bpl
;
576 cx23885_risc_buffer(dev
->pci
, &buf
->risc
,
577 dma
->sglist
, line0_offset
,
580 buf
->vb
.height
>> 1);
582 case V4L2_FIELD_SEQ_TB
:
583 cx23885_risc_buffer(dev
->pci
, &buf
->risc
,
585 0, buf
->bpl
* (buf
->vb
.height
>> 1),
587 buf
->vb
.height
>> 1);
589 case V4L2_FIELD_SEQ_BT
:
590 cx23885_risc_buffer(dev
->pci
, &buf
->risc
,
592 buf
->bpl
* (buf
->vb
.height
>> 1), 0,
594 buf
->vb
.height
>> 1);
600 dprintk(2, "[%p/%d] buffer_prep - %dx%d %dbpp \"%s\" - dma=0x%08lx\n",
602 fh
->width
, fh
->height
, fh
->fmt
->depth
, fh
->fmt
->name
,
603 (unsigned long)buf
->risc
.dma
);
605 buf
->vb
.state
= VIDEOBUF_PREPARED
;
609 cx23885_free_buffer(q
, buf
);
613 static void buffer_queue(struct videobuf_queue
*vq
, struct videobuf_buffer
*vb
)
615 struct cx23885_buffer
*buf
= container_of(vb
,
616 struct cx23885_buffer
, vb
);
617 struct cx23885_buffer
*prev
;
618 struct cx23885_fh
*fh
= vq
->priv_data
;
619 struct cx23885_dev
*dev
= fh
->dev
;
620 struct cx23885_dmaqueue
*q
= &dev
->vidq
;
622 /* add jump to stopper */
623 buf
->risc
.jmp
[0] = cpu_to_le32(RISC_JUMP
| RISC_IRQ1
| RISC_CNT_INC
);
624 buf
->risc
.jmp
[1] = cpu_to_le32(q
->stopper
.dma
);
625 buf
->risc
.jmp
[2] = cpu_to_le32(0); /* bits 63-32 */
627 if (!list_empty(&q
->queued
)) {
628 list_add_tail(&buf
->vb
.queue
, &q
->queued
);
629 buf
->vb
.state
= VIDEOBUF_QUEUED
;
630 dprintk(2, "[%p/%d] buffer_queue - append to queued\n",
633 } else if (list_empty(&q
->active
)) {
634 list_add_tail(&buf
->vb
.queue
, &q
->active
);
635 cx23885_start_video_dma(dev
, q
, buf
);
636 buf
->vb
.state
= VIDEOBUF_ACTIVE
;
637 buf
->count
= q
->count
++;
638 mod_timer(&q
->timeout
, jiffies
+BUFFER_TIMEOUT
);
639 dprintk(2, "[%p/%d] buffer_queue - first active\n",
643 prev
= list_entry(q
->active
.prev
, struct cx23885_buffer
,
645 if (prev
->vb
.width
== buf
->vb
.width
&&
646 prev
->vb
.height
== buf
->vb
.height
&&
647 prev
->fmt
== buf
->fmt
) {
648 list_add_tail(&buf
->vb
.queue
, &q
->active
);
649 buf
->vb
.state
= VIDEOBUF_ACTIVE
;
650 buf
->count
= q
->count
++;
651 prev
->risc
.jmp
[1] = cpu_to_le32(buf
->risc
.dma
);
652 /* 64 bit bits 63-32 */
653 prev
->risc
.jmp
[2] = cpu_to_le32(0);
654 dprintk(2, "[%p/%d] buffer_queue - append to active\n",
658 list_add_tail(&buf
->vb
.queue
, &q
->queued
);
659 buf
->vb
.state
= VIDEOBUF_QUEUED
;
660 dprintk(2, "[%p/%d] buffer_queue - first queued\n",
666 static void buffer_release(struct videobuf_queue
*q
,
667 struct videobuf_buffer
*vb
)
669 struct cx23885_buffer
*buf
= container_of(vb
,
670 struct cx23885_buffer
, vb
);
672 cx23885_free_buffer(q
, buf
);
675 static struct videobuf_queue_ops cx23885_video_qops
= {
676 .buf_setup
= buffer_setup
,
677 .buf_prepare
= buffer_prepare
,
678 .buf_queue
= buffer_queue
,
679 .buf_release
= buffer_release
,
682 static struct videobuf_queue
*get_queue(struct cx23885_fh
*fh
)
685 case V4L2_BUF_TYPE_VIDEO_CAPTURE
:
687 case V4L2_BUF_TYPE_VBI_CAPTURE
:
695 static int get_resource(struct cx23885_fh
*fh
)
698 case V4L2_BUF_TYPE_VIDEO_CAPTURE
:
699 return RESOURCE_VIDEO
;
700 case V4L2_BUF_TYPE_VBI_CAPTURE
:
708 static int video_open(struct file
*file
)
710 int minor
= video_devdata(file
)->minor
;
711 struct cx23885_dev
*h
, *dev
= NULL
;
712 struct cx23885_fh
*fh
;
713 struct list_head
*list
;
714 enum v4l2_buf_type type
= 0;
718 list_for_each(list
, &cx23885_devlist
) {
719 h
= list_entry(list
, struct cx23885_dev
, devlist
);
721 h
->video_dev
->minor
== minor
) {
723 type
= V4L2_BUF_TYPE_VIDEO_CAPTURE
;
726 h
->vbi_dev
->minor
== minor
) {
728 type
= V4L2_BUF_TYPE_VBI_CAPTURE
;
731 h
->radio_dev
->minor
== minor
) {
741 dprintk(1, "open minor=%d radio=%d type=%s\n",
742 minor
, radio
, v4l2_type_names
[type
]);
744 /* allocate + initialize per filehandle data */
745 fh
= kzalloc(sizeof(*fh
), GFP_KERNEL
);
750 file
->private_data
= fh
;
756 fh
->fmt
= format_by_fourcc(V4L2_PIX_FMT_BGR24
);
758 videobuf_queue_sg_init(&fh
->vidq
, &cx23885_video_qops
,
759 &dev
->pci
->dev
, &dev
->slock
,
760 V4L2_BUF_TYPE_VIDEO_CAPTURE
,
761 V4L2_FIELD_INTERLACED
,
762 sizeof(struct cx23885_buffer
),
765 dprintk(1, "post videobuf_queue_init()\n");
772 static ssize_t
video_read(struct file
*file
, char __user
*data
,
773 size_t count
, loff_t
*ppos
)
775 struct cx23885_fh
*fh
= file
->private_data
;
778 case V4L2_BUF_TYPE_VIDEO_CAPTURE
:
779 if (res_locked(fh
->dev
, RESOURCE_VIDEO
))
781 return videobuf_read_one(&fh
->vidq
, data
, count
, ppos
,
782 file
->f_flags
& O_NONBLOCK
);
783 case V4L2_BUF_TYPE_VBI_CAPTURE
:
784 if (!res_get(fh
->dev
, fh
, RESOURCE_VBI
))
786 return videobuf_read_stream(&fh
->vbiq
, data
, count
, ppos
, 1,
787 file
->f_flags
& O_NONBLOCK
);
794 static unsigned int video_poll(struct file
*file
,
795 struct poll_table_struct
*wait
)
797 struct cx23885_fh
*fh
= file
->private_data
;
798 struct cx23885_buffer
*buf
;
799 unsigned int rc
= POLLERR
;
801 if (V4L2_BUF_TYPE_VBI_CAPTURE
== fh
->type
) {
802 if (!res_get(fh
->dev
, fh
, RESOURCE_VBI
))
804 return videobuf_poll_stream(file
, &fh
->vbiq
, wait
);
807 mutex_lock(&fh
->vidq
.vb_lock
);
808 if (res_check(fh
, RESOURCE_VIDEO
)) {
809 /* streaming capture */
810 if (list_empty(&fh
->vidq
.stream
))
812 buf
= list_entry(fh
->vidq
.stream
.next
,
813 struct cx23885_buffer
, vb
.stream
);
816 buf
= (struct cx23885_buffer
*)fh
->vidq
.read_buf
;
820 poll_wait(file
, &buf
->vb
.done
, wait
);
821 if (buf
->vb
.state
== VIDEOBUF_DONE
||
822 buf
->vb
.state
== VIDEOBUF_ERROR
)
823 rc
= POLLIN
|POLLRDNORM
;
827 mutex_unlock(&fh
->vidq
.vb_lock
);
831 static int video_release(struct file
*file
)
833 struct cx23885_fh
*fh
= file
->private_data
;
834 struct cx23885_dev
*dev
= fh
->dev
;
836 /* turn off overlay */
837 if (res_check(fh
, RESOURCE_OVERLAY
)) {
839 res_free(dev
, fh
, RESOURCE_OVERLAY
);
842 /* stop video capture */
843 if (res_check(fh
, RESOURCE_VIDEO
)) {
844 videobuf_queue_cancel(&fh
->vidq
);
845 res_free(dev
, fh
, RESOURCE_VIDEO
);
847 if (fh
->vidq
.read_buf
) {
848 buffer_release(&fh
->vidq
, fh
->vidq
.read_buf
);
849 kfree(fh
->vidq
.read_buf
);
852 /* stop vbi capture */
853 if (res_check(fh
, RESOURCE_VBI
)) {
854 if (fh
->vbiq
.streaming
)
855 videobuf_streamoff(&fh
->vbiq
);
856 if (fh
->vbiq
.reading
)
857 videobuf_read_stop(&fh
->vbiq
);
858 res_free(dev
, fh
, RESOURCE_VBI
);
861 videobuf_mmap_free(&fh
->vidq
);
862 file
->private_data
= NULL
;
865 /* We are not putting the tuner to sleep here on exit, because
866 * we want to use the mpeg encoder in another session to capture
867 * tuner video. Closing this will result in no video to the encoder.
873 static int video_mmap(struct file
*file
, struct vm_area_struct
*vma
)
875 struct cx23885_fh
*fh
= file
->private_data
;
877 return videobuf_mmap_mapper(get_queue(fh
), vma
);
880 /* ------------------------------------------------------------------ */
881 /* VIDEO CTRL IOCTLS */
883 static int cx23885_get_control(struct cx23885_dev
*dev
,
884 struct v4l2_control
*ctl
)
886 dprintk(1, "%s() calling cx25840(VIDIOC_G_CTRL)\n", __func__
);
887 call_all(dev
, core
, g_ctrl
, ctl
);
891 static int cx23885_set_control(struct cx23885_dev
*dev
,
892 struct v4l2_control
*ctl
)
894 dprintk(1, "%s() calling cx25840(VIDIOC_S_CTRL)"
895 " (disabled - no action)\n", __func__
);
899 static void init_controls(struct cx23885_dev
*dev
)
901 struct v4l2_control ctrl
;
904 for (i
= 0; i
< CX23885_CTLS
; i
++) {
905 ctrl
.id
= cx23885_ctls
[i
].v
.id
;
906 ctrl
.value
= cx23885_ctls
[i
].v
.default_value
;
908 cx23885_set_control(dev
, &ctrl
);
912 /* ------------------------------------------------------------------ */
915 static int vidioc_g_fmt_vid_cap(struct file
*file
, void *priv
,
916 struct v4l2_format
*f
)
918 struct cx23885_fh
*fh
= priv
;
920 f
->fmt
.pix
.width
= fh
->width
;
921 f
->fmt
.pix
.height
= fh
->height
;
922 f
->fmt
.pix
.field
= fh
->vidq
.field
;
923 f
->fmt
.pix
.pixelformat
= fh
->fmt
->fourcc
;
924 f
->fmt
.pix
.bytesperline
=
925 (f
->fmt
.pix
.width
* fh
->fmt
->depth
) >> 3;
926 f
->fmt
.pix
.sizeimage
=
927 f
->fmt
.pix
.height
* f
->fmt
.pix
.bytesperline
;
932 static int vidioc_try_fmt_vid_cap(struct file
*file
, void *priv
,
933 struct v4l2_format
*f
)
935 struct cx23885_dev
*dev
= ((struct cx23885_fh
*)priv
)->dev
;
936 struct cx23885_fmt
*fmt
;
937 enum v4l2_field field
;
938 unsigned int maxw
, maxh
;
940 fmt
= format_by_fourcc(f
->fmt
.pix
.pixelformat
);
944 field
= f
->fmt
.pix
.field
;
945 maxw
= norm_maxw(dev
->tvnorm
);
946 maxh
= norm_maxh(dev
->tvnorm
);
948 if (V4L2_FIELD_ANY
== field
) {
949 field
= (f
->fmt
.pix
.height
> maxh
/2)
950 ? V4L2_FIELD_INTERLACED
956 case V4L2_FIELD_BOTTOM
:
959 case V4L2_FIELD_INTERLACED
:
965 f
->fmt
.pix
.field
= field
;
966 v4l_bound_align_image(&f
->fmt
.pix
.width
, 48, maxw
, 2,
967 &f
->fmt
.pix
.height
, 32, maxh
, 0, 0);
968 f
->fmt
.pix
.bytesperline
=
969 (f
->fmt
.pix
.width
* fmt
->depth
) >> 3;
970 f
->fmt
.pix
.sizeimage
=
971 f
->fmt
.pix
.height
* f
->fmt
.pix
.bytesperline
;
976 static int vidioc_s_fmt_vid_cap(struct file
*file
, void *priv
,
977 struct v4l2_format
*f
)
979 struct cx23885_fh
*fh
= priv
;
980 struct cx23885_dev
*dev
= ((struct cx23885_fh
*)priv
)->dev
;
983 dprintk(2, "%s()\n", __func__
);
984 err
= vidioc_try_fmt_vid_cap(file
, priv
, f
);
988 fh
->fmt
= format_by_fourcc(f
->fmt
.pix
.pixelformat
);
989 fh
->width
= f
->fmt
.pix
.width
;
990 fh
->height
= f
->fmt
.pix
.height
;
991 fh
->vidq
.field
= f
->fmt
.pix
.field
;
992 dprintk(2, "%s() width=%d height=%d field=%d\n", __func__
,
993 fh
->width
, fh
->height
, fh
->vidq
.field
);
994 call_all(dev
, video
, s_fmt
, f
);
998 static int vidioc_querycap(struct file
*file
, void *priv
,
999 struct v4l2_capability
*cap
)
1001 struct cx23885_dev
*dev
= ((struct cx23885_fh
*)priv
)->dev
;
1003 strcpy(cap
->driver
, "cx23885");
1004 strlcpy(cap
->card
, cx23885_boards
[dev
->board
].name
,
1006 sprintf(cap
->bus_info
, "PCIe:%s", pci_name(dev
->pci
));
1007 cap
->version
= CX23885_VERSION_CODE
;
1009 V4L2_CAP_VIDEO_CAPTURE
|
1010 V4L2_CAP_READWRITE
|
1011 V4L2_CAP_STREAMING
|
1012 V4L2_CAP_VBI_CAPTURE
;
1013 if (UNSET
!= dev
->tuner_type
)
1014 cap
->capabilities
|= V4L2_CAP_TUNER
;
1018 static int vidioc_enum_fmt_vid_cap(struct file
*file
, void *priv
,
1019 struct v4l2_fmtdesc
*f
)
1021 if (unlikely(f
->index
>= ARRAY_SIZE(formats
)))
1024 strlcpy(f
->description
, formats
[f
->index
].name
,
1025 sizeof(f
->description
));
1026 f
->pixelformat
= formats
[f
->index
].fourcc
;
1031 #ifdef CONFIG_VIDEO_V4L1_COMPAT
1032 static int vidiocgmbuf(struct file
*file
, void *priv
,
1033 struct video_mbuf
*mbuf
)
1035 struct cx23885_fh
*fh
= priv
;
1036 struct videobuf_queue
*q
;
1037 struct v4l2_requestbuffers req
;
1042 memset(&req
, 0, sizeof(req
));
1045 req
.memory
= V4L2_MEMORY_MMAP
;
1046 err
= videobuf_reqbufs(q
, &req
);
1050 mbuf
->frames
= req
.count
;
1052 for (i
= 0; i
< mbuf
->frames
; i
++) {
1053 mbuf
->offsets
[i
] = q
->bufs
[i
]->boff
;
1054 mbuf
->size
+= q
->bufs
[i
]->bsize
;
1060 static int vidioc_reqbufs(struct file
*file
, void *priv
,
1061 struct v4l2_requestbuffers
*p
)
1063 struct cx23885_fh
*fh
= priv
;
1064 return videobuf_reqbufs(get_queue(fh
), p
);
1067 static int vidioc_querybuf(struct file
*file
, void *priv
,
1068 struct v4l2_buffer
*p
)
1070 struct cx23885_fh
*fh
= priv
;
1071 return videobuf_querybuf(get_queue(fh
), p
);
1074 static int vidioc_qbuf(struct file
*file
, void *priv
,
1075 struct v4l2_buffer
*p
)
1077 struct cx23885_fh
*fh
= priv
;
1078 return videobuf_qbuf(get_queue(fh
), p
);
1081 static int vidioc_dqbuf(struct file
*file
, void *priv
,
1082 struct v4l2_buffer
*p
)
1084 struct cx23885_fh
*fh
= priv
;
1085 return videobuf_dqbuf(get_queue(fh
), p
,
1086 file
->f_flags
& O_NONBLOCK
);
1089 static int vidioc_streamon(struct file
*file
, void *priv
,
1090 enum v4l2_buf_type i
)
1092 struct cx23885_fh
*fh
= priv
;
1093 struct cx23885_dev
*dev
= fh
->dev
;
1094 dprintk(1, "%s()\n", __func__
);
1096 if (unlikely(fh
->type
!= V4L2_BUF_TYPE_VIDEO_CAPTURE
))
1098 if (unlikely(i
!= fh
->type
))
1101 if (unlikely(!res_get(dev
, fh
, get_resource(fh
))))
1103 return videobuf_streamon(get_queue(fh
));
1106 static int vidioc_streamoff(struct file
*file
, void *priv
, enum v4l2_buf_type i
)
1108 struct cx23885_fh
*fh
= priv
;
1109 struct cx23885_dev
*dev
= fh
->dev
;
1111 dprintk(1, "%s()\n", __func__
);
1113 if (fh
->type
!= V4L2_BUF_TYPE_VIDEO_CAPTURE
)
1118 res
= get_resource(fh
);
1119 err
= videobuf_streamoff(get_queue(fh
));
1122 res_free(dev
, fh
, res
);
1126 static int vidioc_s_std(struct file
*file
, void *priv
, v4l2_std_id
*tvnorms
)
1128 struct cx23885_dev
*dev
= ((struct cx23885_fh
*)priv
)->dev
;
1129 dprintk(1, "%s()\n", __func__
);
1131 mutex_lock(&dev
->lock
);
1132 cx23885_set_tvnorm(dev
, *tvnorms
);
1133 mutex_unlock(&dev
->lock
);
1138 static int cx23885_enum_input(struct cx23885_dev
*dev
, struct v4l2_input
*i
)
1140 static const char *iname
[] = {
1141 [CX23885_VMUX_COMPOSITE1
] = "Composite1",
1142 [CX23885_VMUX_COMPOSITE2
] = "Composite2",
1143 [CX23885_VMUX_COMPOSITE3
] = "Composite3",
1144 [CX23885_VMUX_COMPOSITE4
] = "Composite4",
1145 [CX23885_VMUX_SVIDEO
] = "S-Video",
1146 [CX23885_VMUX_TELEVISION
] = "Television",
1147 [CX23885_VMUX_CABLE
] = "Cable TV",
1148 [CX23885_VMUX_DVB
] = "DVB",
1149 [CX23885_VMUX_DEBUG
] = "for debug only",
1152 dprintk(1, "%s()\n", __func__
);
1158 if (0 == INPUT(n
)->type
)
1161 memset(i
, 0, sizeof(*i
));
1163 i
->type
= V4L2_INPUT_TYPE_CAMERA
;
1164 strcpy(i
->name
, iname
[INPUT(n
)->type
]);
1165 if ((CX23885_VMUX_TELEVISION
== INPUT(n
)->type
) ||
1166 (CX23885_VMUX_CABLE
== INPUT(n
)->type
))
1167 i
->type
= V4L2_INPUT_TYPE_TUNER
;
1168 i
->std
= CX23885_NORMS
;
1172 static int vidioc_enum_input(struct file
*file
, void *priv
,
1173 struct v4l2_input
*i
)
1175 struct cx23885_dev
*dev
= ((struct cx23885_fh
*)priv
)->dev
;
1176 dprintk(1, "%s()\n", __func__
);
1177 return cx23885_enum_input(dev
, i
);
1180 static int vidioc_g_input(struct file
*file
, void *priv
, unsigned int *i
)
1182 struct cx23885_dev
*dev
= ((struct cx23885_fh
*)priv
)->dev
;
1185 dprintk(1, "%s() returns %d\n", __func__
, *i
);
1189 static int vidioc_s_input(struct file
*file
, void *priv
, unsigned int i
)
1191 struct cx23885_dev
*dev
= ((struct cx23885_fh
*)priv
)->dev
;
1193 dprintk(1, "%s(%d)\n", __func__
, i
);
1196 dprintk(1, "%s() -EINVAL\n", __func__
);
1200 mutex_lock(&dev
->lock
);
1201 cx23885_video_mux(dev
, i
);
1202 mutex_unlock(&dev
->lock
);
1206 static int vidioc_queryctrl(struct file
*file
, void *priv
,
1207 struct v4l2_queryctrl
*qctrl
)
1209 qctrl
->id
= v4l2_ctrl_next(ctrl_classes
, qctrl
->id
);
1210 if (unlikely(qctrl
->id
== 0))
1212 return cx23885_ctrl_query(qctrl
);
1215 static int vidioc_g_ctrl(struct file
*file
, void *priv
,
1216 struct v4l2_control
*ctl
)
1218 struct cx23885_dev
*dev
= ((struct cx23885_fh
*)priv
)->dev
;
1220 return cx23885_get_control(dev
, ctl
);
1223 static int vidioc_s_ctrl(struct file
*file
, void *priv
,
1224 struct v4l2_control
*ctl
)
1226 struct cx23885_dev
*dev
= ((struct cx23885_fh
*)priv
)->dev
;
1228 return cx23885_set_control(dev
, ctl
);
1231 static int vidioc_g_tuner(struct file
*file
, void *priv
,
1232 struct v4l2_tuner
*t
)
1234 struct cx23885_dev
*dev
= ((struct cx23885_fh
*)priv
)->dev
;
1236 if (unlikely(UNSET
== dev
->tuner_type
))
1241 strcpy(t
->name
, "Television");
1242 t
->type
= V4L2_TUNER_ANALOG_TV
;
1243 t
->capability
= V4L2_TUNER_CAP_NORM
;
1244 t
->rangehigh
= 0xffffffffUL
;
1245 t
->signal
= 0xffff ; /* LOCKED */
1249 static int vidioc_s_tuner(struct file
*file
, void *priv
,
1250 struct v4l2_tuner
*t
)
1252 struct cx23885_dev
*dev
= ((struct cx23885_fh
*)priv
)->dev
;
1254 if (UNSET
== dev
->tuner_type
)
1261 static int vidioc_g_frequency(struct file
*file
, void *priv
,
1262 struct v4l2_frequency
*f
)
1264 struct cx23885_fh
*fh
= priv
;
1265 struct cx23885_dev
*dev
= fh
->dev
;
1267 if (unlikely(UNSET
== dev
->tuner_type
))
1270 /* f->type = fh->radio ? V4L2_TUNER_RADIO : V4L2_TUNER_ANALOG_TV; */
1271 f
->type
= fh
->radio
? V4L2_TUNER_RADIO
: V4L2_TUNER_ANALOG_TV
;
1272 f
->frequency
= dev
->freq
;
1274 call_all(dev
, tuner
, g_frequency
, f
);
1279 static int cx23885_set_freq(struct cx23885_dev
*dev
, struct v4l2_frequency
*f
)
1281 if (unlikely(UNSET
== dev
->tuner_type
))
1283 if (unlikely(f
->tuner
!= 0))
1286 mutex_lock(&dev
->lock
);
1287 dev
->freq
= f
->frequency
;
1289 call_all(dev
, tuner
, s_frequency
, f
);
1291 /* When changing channels it is required to reset TVAUDIO */
1294 mutex_unlock(&dev
->lock
);
1299 static int vidioc_s_frequency(struct file
*file
, void *priv
,
1300 struct v4l2_frequency
*f
)
1302 struct cx23885_fh
*fh
= priv
;
1303 struct cx23885_dev
*dev
= fh
->dev
;
1305 if (unlikely(0 == fh
->radio
&& f
->type
!= V4L2_TUNER_ANALOG_TV
))
1307 if (unlikely(1 == fh
->radio
&& f
->type
!= V4L2_TUNER_RADIO
))
1311 cx23885_set_freq(dev
, f
);
1314 #ifdef CONFIG_VIDEO_ADV_DEBUG
1315 static int vidioc_g_register(struct file
*file
, void *fh
,
1316 struct v4l2_dbg_register
*reg
)
1318 struct cx23885_dev
*dev
= ((struct cx23885_fh
*)fh
)->dev
;
1320 if (!v4l2_chip_match_host(®
->match
))
1323 call_all(dev
, core
, g_register
, reg
);
1328 static int vidioc_s_register(struct file
*file
, void *fh
,
1329 struct v4l2_dbg_register
*reg
)
1331 struct cx23885_dev
*dev
= ((struct cx23885_fh
*)fh
)->dev
;
1333 if (!v4l2_chip_match_host(®
->match
))
1336 call_all(dev
, core
, s_register
, reg
);
1342 /* ----------------------------------------------------------- */
1344 static void cx23885_vid_timeout(unsigned long data
)
1346 struct cx23885_dev
*dev
= (struct cx23885_dev
*)data
;
1347 struct cx23885_dmaqueue
*q
= &dev
->vidq
;
1348 struct cx23885_buffer
*buf
;
1349 unsigned long flags
;
1351 cx23885_sram_channel_dump(dev
, &dev
->sram_channels
[SRAM_CH01
]);
1353 cx_clear(VID_A_DMA_CTL
, 0x11);
1355 spin_lock_irqsave(&dev
->slock
, flags
);
1356 while (!list_empty(&q
->active
)) {
1357 buf
= list_entry(q
->active
.next
,
1358 struct cx23885_buffer
, vb
.queue
);
1359 list_del(&buf
->vb
.queue
);
1360 buf
->vb
.state
= VIDEOBUF_ERROR
;
1361 wake_up(&buf
->vb
.done
);
1362 printk(KERN_ERR
"%s/0: [%p/%d] timeout - dma=0x%08lx\n",
1363 dev
->name
, buf
, buf
->vb
.i
,
1364 (unsigned long)buf
->risc
.dma
);
1366 cx23885_restart_video_queue(dev
, q
);
1367 spin_unlock_irqrestore(&dev
->slock
, flags
);
1370 int cx23885_video_irq(struct cx23885_dev
*dev
, u32 status
)
1375 mask
= cx_read(VID_A_INT_MSK
);
1376 if (0 == (status
& mask
))
1378 cx_write(VID_A_INT_STAT
, status
);
1380 dprintk(2, "%s() status = 0x%08x\n", __func__
, status
);
1381 /* risc op code error */
1382 if (status
& (1 << 16)) {
1383 printk(KERN_WARNING
"%s/0: video risc op code error\n",
1385 cx_clear(VID_A_DMA_CTL
, 0x11);
1386 cx23885_sram_channel_dump(dev
, &dev
->sram_channels
[SRAM_CH01
]);
1390 if (status
& 0x01) {
1391 spin_lock(&dev
->slock
);
1392 count
= cx_read(VID_A_GPCNT
);
1393 cx23885_video_wakeup(dev
, &dev
->vidq
, count
);
1394 spin_unlock(&dev
->slock
);
1398 if (status
& 0x10) {
1399 dprintk(2, "stopper video\n");
1400 spin_lock(&dev
->slock
);
1401 cx23885_restart_video_queue(dev
, &dev
->vidq
);
1402 spin_unlock(&dev
->slock
);
1409 /* ----------------------------------------------------------- */
1410 /* exported stuff */
1412 static const struct v4l2_file_operations video_fops
= {
1413 .owner
= THIS_MODULE
,
1415 .release
= video_release
,
1419 .ioctl
= video_ioctl2
,
1422 static const struct v4l2_ioctl_ops video_ioctl_ops
= {
1423 .vidioc_querycap
= vidioc_querycap
,
1424 .vidioc_enum_fmt_vid_cap
= vidioc_enum_fmt_vid_cap
,
1425 .vidioc_g_fmt_vid_cap
= vidioc_g_fmt_vid_cap
,
1426 .vidioc_try_fmt_vid_cap
= vidioc_try_fmt_vid_cap
,
1427 .vidioc_s_fmt_vid_cap
= vidioc_s_fmt_vid_cap
,
1428 .vidioc_g_fmt_vbi_cap
= cx23885_vbi_fmt
,
1429 .vidioc_try_fmt_vbi_cap
= cx23885_vbi_fmt
,
1430 .vidioc_s_fmt_vbi_cap
= cx23885_vbi_fmt
,
1431 .vidioc_reqbufs
= vidioc_reqbufs
,
1432 .vidioc_querybuf
= vidioc_querybuf
,
1433 .vidioc_qbuf
= vidioc_qbuf
,
1434 .vidioc_dqbuf
= vidioc_dqbuf
,
1435 .vidioc_s_std
= vidioc_s_std
,
1436 .vidioc_enum_input
= vidioc_enum_input
,
1437 .vidioc_g_input
= vidioc_g_input
,
1438 .vidioc_s_input
= vidioc_s_input
,
1439 .vidioc_queryctrl
= vidioc_queryctrl
,
1440 .vidioc_g_ctrl
= vidioc_g_ctrl
,
1441 .vidioc_s_ctrl
= vidioc_s_ctrl
,
1442 .vidioc_streamon
= vidioc_streamon
,
1443 .vidioc_streamoff
= vidioc_streamoff
,
1444 #ifdef CONFIG_VIDEO_V4L1_COMPAT
1445 .vidiocgmbuf
= vidiocgmbuf
,
1447 .vidioc_g_tuner
= vidioc_g_tuner
,
1448 .vidioc_s_tuner
= vidioc_s_tuner
,
1449 .vidioc_g_frequency
= vidioc_g_frequency
,
1450 .vidioc_s_frequency
= vidioc_s_frequency
,
1451 #ifdef CONFIG_VIDEO_ADV_DEBUG
1452 .vidioc_g_register
= vidioc_g_register
,
1453 .vidioc_s_register
= vidioc_s_register
,
1457 static struct video_device cx23885_vbi_template
;
1458 static struct video_device cx23885_video_template
= {
1459 .name
= "cx23885-video",
1460 .fops
= &video_fops
,
1462 .ioctl_ops
= &video_ioctl_ops
,
1463 .tvnorms
= CX23885_NORMS
,
1464 .current_norm
= V4L2_STD_NTSC_M
,
1467 static const struct v4l2_file_operations radio_fops
= {
1468 .owner
= THIS_MODULE
,
1470 .release
= video_release
,
1471 .ioctl
= video_ioctl2
,
1475 void cx23885_video_unregister(struct cx23885_dev
*dev
)
1477 dprintk(1, "%s()\n", __func__
);
1478 cx_clear(PCI_INT_MSK
, 1);
1480 if (dev
->video_dev
) {
1481 if (-1 != dev
->video_dev
->minor
)
1482 video_unregister_device(dev
->video_dev
);
1484 video_device_release(dev
->video_dev
);
1485 dev
->video_dev
= NULL
;
1487 btcx_riscmem_free(dev
->pci
, &dev
->vidq
.stopper
);
1491 int cx23885_video_register(struct cx23885_dev
*dev
)
1495 dprintk(1, "%s()\n", __func__
);
1496 spin_lock_init(&dev
->slock
);
1498 /* Initialize VBI template */
1499 memcpy(&cx23885_vbi_template
, &cx23885_video_template
,
1500 sizeof(cx23885_vbi_template
));
1501 strcpy(cx23885_vbi_template
.name
, "cx23885-vbi");
1503 dev
->tvnorm
= cx23885_video_template
.current_norm
;
1505 /* init video dma queues */
1506 INIT_LIST_HEAD(&dev
->vidq
.active
);
1507 INIT_LIST_HEAD(&dev
->vidq
.queued
);
1508 dev
->vidq
.timeout
.function
= cx23885_vid_timeout
;
1509 dev
->vidq
.timeout
.data
= (unsigned long)dev
;
1510 init_timer(&dev
->vidq
.timeout
);
1511 cx23885_risc_stopper(dev
->pci
, &dev
->vidq
.stopper
,
1512 VID_A_DMA_CTL
, 0x11, 0x00);
1514 /* Don't enable VBI yet */
1515 cx_set(PCI_INT_MSK
, 1);
1517 if (TUNER_ABSENT
!= dev
->tuner_type
) {
1518 struct v4l2_subdev
*sd
= NULL
;
1520 if (dev
->tuner_addr
)
1521 sd
= v4l2_i2c_new_subdev(&dev
->v4l2_dev
,
1522 &dev
->i2c_bus
[1].i2c_adap
,
1523 "tuner", "tuner", dev
->tuner_addr
);
1525 sd
= v4l2_i2c_new_probed_subdev(&dev
->v4l2_dev
,
1526 &dev
->i2c_bus
[1].i2c_adap
,
1527 "tuner", "tuner", v4l2_i2c_tuner_addrs(ADDRS_TV
));
1529 struct tuner_setup tun_setup
;
1531 tun_setup
.mode_mask
= T_ANALOG_TV
;
1532 tun_setup
.type
= dev
->tuner_type
;
1533 tun_setup
.addr
= v4l2_i2c_subdev_addr(sd
);
1535 v4l2_subdev_call(sd
, tuner
, s_type_addr
, &tun_setup
);
1540 /* register v4l devices */
1541 dev
->video_dev
= cx23885_vdev_init(dev
, dev
->pci
,
1542 &cx23885_video_template
, "video");
1543 err
= video_register_device(dev
->video_dev
, VFL_TYPE_GRABBER
,
1546 printk(KERN_INFO
"%s: can't register video device\n",
1550 printk(KERN_INFO
"%s/0: registered device video%d [v4l2]\n",
1551 dev
->name
, dev
->video_dev
->num
);
1552 /* initial device configuration */
1553 mutex_lock(&dev
->lock
);
1554 cx23885_set_tvnorm(dev
, dev
->tvnorm
);
1556 cx23885_video_mux(dev
, 0);
1557 mutex_unlock(&dev
->lock
);
1562 cx23885_video_unregister(dev
);