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/smp_lock.h>
30 #include <linux/interrupt.h>
31 #include <linux/delay.h>
32 #include <linux/kthread.h>
33 #include <asm/div64.h>
36 #include <media/v4l2-common.h>
37 #include <media/v4l2-ioctl.h>
38 #include "cx23885-ioctl.h"
39 #include "tuner-xc2028.h"
41 MODULE_DESCRIPTION("v4l2 driver module for cx23885 based TV cards");
42 MODULE_AUTHOR("Steven Toth <stoth@linuxtv.org>");
43 MODULE_LICENSE("GPL");
45 /* ------------------------------------------------------------------ */
47 static unsigned int video_nr
[] = {[0 ... (CX23885_MAXBOARDS
- 1)] = UNSET
};
48 static unsigned int vbi_nr
[] = {[0 ... (CX23885_MAXBOARDS
- 1)] = UNSET
};
49 static unsigned int radio_nr
[] = {[0 ... (CX23885_MAXBOARDS
- 1)] = UNSET
};
51 module_param_array(video_nr
, int, NULL
, 0444);
52 module_param_array(vbi_nr
, int, NULL
, 0444);
53 module_param_array(radio_nr
, int, NULL
, 0444);
55 MODULE_PARM_DESC(video_nr
, "video device numbers");
56 MODULE_PARM_DESC(vbi_nr
, "vbi device numbers");
57 MODULE_PARM_DESC(radio_nr
, "radio device numbers");
59 static unsigned int video_debug
;
60 module_param(video_debug
, int, 0644);
61 MODULE_PARM_DESC(video_debug
, "enable debug messages [video]");
63 static unsigned int irq_debug
;
64 module_param(irq_debug
, int, 0644);
65 MODULE_PARM_DESC(irq_debug
, "enable debug messages [IRQ handler]");
67 static unsigned int vid_limit
= 16;
68 module_param(vid_limit
, int, 0644);
69 MODULE_PARM_DESC(vid_limit
, "capture memory limit in megabytes");
71 #define dprintk(level, fmt, arg...)\
72 do { if (video_debug >= level)\
73 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", __func__
, 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 /* Must be sorted from low to high control ID! */
246 static const u32 cx23885_user_ctrls
[] = {
252 V4L2_CID_AUDIO_VOLUME
,
257 static const u32
*ctrl_classes
[] = {
262 static 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
);
274 /* count comes from the hw and is is 16bit wide --
275 * this trick handles wrap-arounds correctly for
276 * up to 32767 buffers in flight... */
277 if ((s16
) (count
- buf
->count
) < 0)
280 do_gettimeofday(&buf
->vb
.ts
);
281 dprintk(2, "[%p/%d] wakeup reg=%d buf=%d\n", buf
, buf
->vb
.i
,
283 buf
->vb
.state
= VIDEOBUF_DONE
;
284 list_del(&buf
->vb
.queue
);
285 wake_up(&buf
->vb
.done
);
287 if (list_empty(&q
->active
))
288 del_timer(&q
->timeout
);
290 mod_timer(&q
->timeout
, jiffies
+BUFFER_TIMEOUT
);
292 printk(KERN_ERR
"%s: %d buffers handled (should be 1)\n",
296 static int cx23885_set_tvnorm(struct cx23885_dev
*dev
, v4l2_std_id norm
)
298 dprintk(1, "%s(norm = 0x%08x) name: [%s]\n",
301 v4l2_norm_to_name(norm
));
305 call_all(dev
, core
, s_std
, norm
);
310 static struct video_device
*cx23885_vdev_init(struct cx23885_dev
*dev
,
312 struct video_device
*template,
315 struct video_device
*vfd
;
316 dprintk(1, "%s()\n", __func__
);
318 vfd
= video_device_alloc();
322 vfd
->v4l2_dev
= &dev
->v4l2_dev
;
323 vfd
->release
= video_device_release
;
324 snprintf(vfd
->name
, sizeof(vfd
->name
), "%s %s (%s)",
325 dev
->name
, type
, cx23885_boards
[dev
->board
].name
);
326 video_set_drvdata(vfd
, dev
);
330 static int cx23885_ctrl_query(struct v4l2_queryctrl
*qctrl
)
334 if (qctrl
->id
< V4L2_CID_BASE
||
335 qctrl
->id
>= V4L2_CID_LASTP1
)
337 for (i
= 0; i
< CX23885_CTLS
; i
++)
338 if (cx23885_ctls
[i
].v
.id
== qctrl
->id
)
340 if (i
== CX23885_CTLS
) {
344 *qctrl
= cx23885_ctls
[i
].v
;
348 /* ------------------------------------------------------------------- */
349 /* resource management */
351 static int res_get(struct cx23885_dev
*dev
, struct cx23885_fh
*fh
,
354 dprintk(1, "%s()\n", __func__
);
355 if (fh
->resources
& bit
)
356 /* have it already allocated */
360 mutex_lock(&dev
->lock
);
361 if (dev
->resources
& bit
) {
362 /* no, someone else uses it */
363 mutex_unlock(&dev
->lock
);
366 /* it's free, grab it */
367 fh
->resources
|= bit
;
368 dev
->resources
|= bit
;
369 dprintk(1, "res: get %d\n", bit
);
370 mutex_unlock(&dev
->lock
);
374 static int res_check(struct cx23885_fh
*fh
, unsigned int bit
)
376 return fh
->resources
& bit
;
379 static int res_locked(struct cx23885_dev
*dev
, unsigned int bit
)
381 return dev
->resources
& bit
;
384 static void res_free(struct cx23885_dev
*dev
, struct cx23885_fh
*fh
,
387 BUG_ON((fh
->resources
& bits
) != bits
);
388 dprintk(1, "%s()\n", __func__
);
390 mutex_lock(&dev
->lock
);
391 fh
->resources
&= ~bits
;
392 dev
->resources
&= ~bits
;
393 dprintk(1, "res: put %d\n", bits
);
394 mutex_unlock(&dev
->lock
);
397 static int cx23885_video_mux(struct cx23885_dev
*dev
, unsigned int input
)
399 dprintk(1, "%s() video_mux: %d [vmux=%d, gpio=0x%x,0x%x,0x%x,0x%x]\n",
401 input
, INPUT(input
)->vmux
,
402 INPUT(input
)->gpio0
, INPUT(input
)->gpio1
,
403 INPUT(input
)->gpio2
, INPUT(input
)->gpio3
);
406 if (dev
->board
== CX23885_BOARD_MYGICA_X8506
||
407 dev
->board
== CX23885_BOARD_MAGICPRO_PROHDTVE2
) {
408 /* Select Analog TV */
409 if (INPUT(input
)->type
== CX23885_VMUX_TELEVISION
)
410 cx23885_gpio_clear(dev
, GPIO_0
);
413 /* Tell the internal A/V decoder */
414 v4l2_subdev_call(dev
->sd_cx25840
, video
, s_routing
,
415 INPUT(input
)->vmux
, 0, 0);
420 /* ------------------------------------------------------------------ */
421 static int cx23885_set_scale(struct cx23885_dev
*dev
, unsigned int width
,
422 unsigned int height
, enum v4l2_field field
)
424 dprintk(1, "%s()\n", __func__
);
428 static int cx23885_start_video_dma(struct cx23885_dev
*dev
,
429 struct cx23885_dmaqueue
*q
,
430 struct cx23885_buffer
*buf
)
432 dprintk(1, "%s()\n", __func__
);
434 /* setup fifo + format */
435 cx23885_sram_channel_setup(dev
, &dev
->sram_channels
[SRAM_CH01
],
436 buf
->bpl
, buf
->risc
.dma
);
437 cx23885_set_scale(dev
, buf
->vb
.width
, buf
->vb
.height
, buf
->vb
.field
);
440 cx_write(VID_A_GPCNT_CTL
, 3);
444 cx_set(PCI_INT_MSK
, cx_read(PCI_INT_MSK
) | 0x01);
445 cx_set(VID_A_INT_MSK
, 0x000011);
448 cx_set(DEV_CNTRL2
, (1<<5));
449 cx_set(VID_A_DMA_CTL
, 0x11); /* FIFO and RISC enable */
455 static int cx23885_restart_video_queue(struct cx23885_dev
*dev
,
456 struct cx23885_dmaqueue
*q
)
458 struct cx23885_buffer
*buf
, *prev
;
459 struct list_head
*item
;
460 dprintk(1, "%s()\n", __func__
);
462 if (!list_empty(&q
->active
)) {
463 buf
= list_entry(q
->active
.next
, struct cx23885_buffer
,
465 dprintk(2, "restart_queue [%p/%d]: restart dma\n",
467 cx23885_start_video_dma(dev
, q
, buf
);
468 list_for_each(item
, &q
->active
) {
469 buf
= list_entry(item
, struct cx23885_buffer
,
471 buf
->count
= q
->count
++;
473 mod_timer(&q
->timeout
, jiffies
+BUFFER_TIMEOUT
);
479 if (list_empty(&q
->queued
))
481 buf
= list_entry(q
->queued
.next
, struct cx23885_buffer
,
484 list_move_tail(&buf
->vb
.queue
, &q
->active
);
485 cx23885_start_video_dma(dev
, q
, buf
);
486 buf
->vb
.state
= VIDEOBUF_ACTIVE
;
487 buf
->count
= q
->count
++;
488 mod_timer(&q
->timeout
, jiffies
+BUFFER_TIMEOUT
);
489 dprintk(2, "[%p/%d] restart_queue - first active\n",
492 } else if (prev
->vb
.width
== buf
->vb
.width
&&
493 prev
->vb
.height
== buf
->vb
.height
&&
494 prev
->fmt
== buf
->fmt
) {
495 list_move_tail(&buf
->vb
.queue
, &q
->active
);
496 buf
->vb
.state
= VIDEOBUF_ACTIVE
;
497 buf
->count
= q
->count
++;
498 prev
->risc
.jmp
[1] = cpu_to_le32(buf
->risc
.dma
);
499 prev
->risc
.jmp
[2] = cpu_to_le32(0); /* Bits 63 - 32 */
500 dprintk(2, "[%p/%d] restart_queue - move to active\n",
509 static int buffer_setup(struct videobuf_queue
*q
, unsigned int *count
,
512 struct cx23885_fh
*fh
= q
->priv_data
;
514 *size
= fh
->fmt
->depth
*fh
->width
*fh
->height
>> 3;
517 while (*size
* *count
> vid_limit
* 1024 * 1024)
522 static int buffer_prepare(struct videobuf_queue
*q
, struct videobuf_buffer
*vb
,
523 enum v4l2_field field
)
525 struct cx23885_fh
*fh
= q
->priv_data
;
526 struct cx23885_dev
*dev
= fh
->dev
;
527 struct cx23885_buffer
*buf
=
528 container_of(vb
, struct cx23885_buffer
, vb
);
529 int rc
, init_buffer
= 0;
530 u32 line0_offset
, line1_offset
;
531 struct videobuf_dmabuf
*dma
= videobuf_to_dma(&buf
->vb
);
533 BUG_ON(NULL
== fh
->fmt
);
534 if (fh
->width
< 48 || fh
->width
> norm_maxw(dev
->tvnorm
) ||
535 fh
->height
< 32 || fh
->height
> norm_maxh(dev
->tvnorm
))
537 buf
->vb
.size
= (fh
->width
* fh
->height
* fh
->fmt
->depth
) >> 3;
538 if (0 != buf
->vb
.baddr
&& buf
->vb
.bsize
< buf
->vb
.size
)
541 if (buf
->fmt
!= fh
->fmt
||
542 buf
->vb
.width
!= fh
->width
||
543 buf
->vb
.height
!= fh
->height
||
544 buf
->vb
.field
!= field
) {
546 buf
->vb
.width
= fh
->width
;
547 buf
->vb
.height
= fh
->height
;
548 buf
->vb
.field
= field
;
552 if (VIDEOBUF_NEEDS_INIT
== buf
->vb
.state
) {
554 rc
= videobuf_iolock(q
, &buf
->vb
, NULL
);
560 buf
->bpl
= buf
->vb
.width
* buf
->fmt
->depth
>> 3;
561 switch (buf
->vb
.field
) {
563 cx23885_risc_buffer(dev
->pci
, &buf
->risc
,
564 dma
->sglist
, 0, UNSET
,
565 buf
->bpl
, 0, buf
->vb
.height
);
567 case V4L2_FIELD_BOTTOM
:
568 cx23885_risc_buffer(dev
->pci
, &buf
->risc
,
569 dma
->sglist
, UNSET
, 0,
570 buf
->bpl
, 0, buf
->vb
.height
);
572 case V4L2_FIELD_INTERLACED
:
573 if (dev
->tvnorm
& V4L2_STD_NTSC
) {
574 /* cx25840 transmits NTSC bottom field first */
575 dprintk(1, "%s() Creating NTSC risc\n",
577 line0_offset
= buf
->bpl
;
580 /* All other formats are top field first */
581 dprintk(1, "%s() Creating PAL/SECAM risc\n",
584 line1_offset
= buf
->bpl
;
586 cx23885_risc_buffer(dev
->pci
, &buf
->risc
,
587 dma
->sglist
, line0_offset
,
590 buf
->vb
.height
>> 1);
592 case V4L2_FIELD_SEQ_TB
:
593 cx23885_risc_buffer(dev
->pci
, &buf
->risc
,
595 0, buf
->bpl
* (buf
->vb
.height
>> 1),
597 buf
->vb
.height
>> 1);
599 case V4L2_FIELD_SEQ_BT
:
600 cx23885_risc_buffer(dev
->pci
, &buf
->risc
,
602 buf
->bpl
* (buf
->vb
.height
>> 1), 0,
604 buf
->vb
.height
>> 1);
610 dprintk(2, "[%p/%d] buffer_prep - %dx%d %dbpp \"%s\" - dma=0x%08lx\n",
612 fh
->width
, fh
->height
, fh
->fmt
->depth
, fh
->fmt
->name
,
613 (unsigned long)buf
->risc
.dma
);
615 buf
->vb
.state
= VIDEOBUF_PREPARED
;
619 cx23885_free_buffer(q
, buf
);
623 static void buffer_queue(struct videobuf_queue
*vq
, struct videobuf_buffer
*vb
)
625 struct cx23885_buffer
*buf
= container_of(vb
,
626 struct cx23885_buffer
, vb
);
627 struct cx23885_buffer
*prev
;
628 struct cx23885_fh
*fh
= vq
->priv_data
;
629 struct cx23885_dev
*dev
= fh
->dev
;
630 struct cx23885_dmaqueue
*q
= &dev
->vidq
;
632 /* add jump to stopper */
633 buf
->risc
.jmp
[0] = cpu_to_le32(RISC_JUMP
| RISC_IRQ1
| RISC_CNT_INC
);
634 buf
->risc
.jmp
[1] = cpu_to_le32(q
->stopper
.dma
);
635 buf
->risc
.jmp
[2] = cpu_to_le32(0); /* bits 63-32 */
637 if (!list_empty(&q
->queued
)) {
638 list_add_tail(&buf
->vb
.queue
, &q
->queued
);
639 buf
->vb
.state
= VIDEOBUF_QUEUED
;
640 dprintk(2, "[%p/%d] buffer_queue - append to queued\n",
643 } else if (list_empty(&q
->active
)) {
644 list_add_tail(&buf
->vb
.queue
, &q
->active
);
645 cx23885_start_video_dma(dev
, q
, buf
);
646 buf
->vb
.state
= VIDEOBUF_ACTIVE
;
647 buf
->count
= q
->count
++;
648 mod_timer(&q
->timeout
, jiffies
+BUFFER_TIMEOUT
);
649 dprintk(2, "[%p/%d] buffer_queue - first active\n",
653 prev
= list_entry(q
->active
.prev
, struct cx23885_buffer
,
655 if (prev
->vb
.width
== buf
->vb
.width
&&
656 prev
->vb
.height
== buf
->vb
.height
&&
657 prev
->fmt
== buf
->fmt
) {
658 list_add_tail(&buf
->vb
.queue
, &q
->active
);
659 buf
->vb
.state
= VIDEOBUF_ACTIVE
;
660 buf
->count
= q
->count
++;
661 prev
->risc
.jmp
[1] = cpu_to_le32(buf
->risc
.dma
);
662 /* 64 bit bits 63-32 */
663 prev
->risc
.jmp
[2] = cpu_to_le32(0);
664 dprintk(2, "[%p/%d] buffer_queue - append to active\n",
668 list_add_tail(&buf
->vb
.queue
, &q
->queued
);
669 buf
->vb
.state
= VIDEOBUF_QUEUED
;
670 dprintk(2, "[%p/%d] buffer_queue - first queued\n",
676 static void buffer_release(struct videobuf_queue
*q
,
677 struct videobuf_buffer
*vb
)
679 struct cx23885_buffer
*buf
= container_of(vb
,
680 struct cx23885_buffer
, vb
);
682 cx23885_free_buffer(q
, buf
);
685 static struct videobuf_queue_ops cx23885_video_qops
= {
686 .buf_setup
= buffer_setup
,
687 .buf_prepare
= buffer_prepare
,
688 .buf_queue
= buffer_queue
,
689 .buf_release
= buffer_release
,
692 static struct videobuf_queue
*get_queue(struct cx23885_fh
*fh
)
695 case V4L2_BUF_TYPE_VIDEO_CAPTURE
:
697 case V4L2_BUF_TYPE_VBI_CAPTURE
:
705 static int get_resource(struct cx23885_fh
*fh
)
708 case V4L2_BUF_TYPE_VIDEO_CAPTURE
:
709 return RESOURCE_VIDEO
;
710 case V4L2_BUF_TYPE_VBI_CAPTURE
:
718 static int video_open(struct file
*file
)
720 struct video_device
*vdev
= video_devdata(file
);
721 struct cx23885_dev
*dev
= video_drvdata(file
);
722 struct cx23885_fh
*fh
;
723 enum v4l2_buf_type type
= 0;
726 switch (vdev
->vfl_type
) {
727 case VFL_TYPE_GRABBER
:
728 type
= V4L2_BUF_TYPE_VIDEO_CAPTURE
;
731 type
= V4L2_BUF_TYPE_VBI_CAPTURE
;
738 dprintk(1, "open dev=%s radio=%d type=%s\n",
739 video_device_node_name(vdev
), radio
, v4l2_type_names
[type
]);
741 /* allocate + initialize per filehandle data */
742 fh
= kzalloc(sizeof(*fh
), GFP_KERNEL
);
748 file
->private_data
= fh
;
754 fh
->fmt
= format_by_fourcc(V4L2_PIX_FMT_BGR24
);
756 videobuf_queue_sg_init(&fh
->vidq
, &cx23885_video_qops
,
757 &dev
->pci
->dev
, &dev
->slock
,
758 V4L2_BUF_TYPE_VIDEO_CAPTURE
,
759 V4L2_FIELD_INTERLACED
,
760 sizeof(struct cx23885_buffer
),
763 dprintk(1, "post videobuf_queue_init()\n");
770 static ssize_t
video_read(struct file
*file
, char __user
*data
,
771 size_t count
, loff_t
*ppos
)
773 struct cx23885_fh
*fh
= file
->private_data
;
776 case V4L2_BUF_TYPE_VIDEO_CAPTURE
:
777 if (res_locked(fh
->dev
, RESOURCE_VIDEO
))
779 return videobuf_read_one(&fh
->vidq
, data
, count
, ppos
,
780 file
->f_flags
& O_NONBLOCK
);
781 case V4L2_BUF_TYPE_VBI_CAPTURE
:
782 if (!res_get(fh
->dev
, fh
, RESOURCE_VBI
))
784 return videobuf_read_stream(&fh
->vbiq
, data
, count
, ppos
, 1,
785 file
->f_flags
& O_NONBLOCK
);
792 static unsigned int video_poll(struct file
*file
,
793 struct poll_table_struct
*wait
)
795 struct cx23885_fh
*fh
= file
->private_data
;
796 struct cx23885_buffer
*buf
;
797 unsigned int rc
= POLLERR
;
799 if (V4L2_BUF_TYPE_VBI_CAPTURE
== fh
->type
) {
800 if (!res_get(fh
->dev
, fh
, RESOURCE_VBI
))
802 return videobuf_poll_stream(file
, &fh
->vbiq
, wait
);
805 mutex_lock(&fh
->vidq
.vb_lock
);
806 if (res_check(fh
, RESOURCE_VIDEO
)) {
807 /* streaming capture */
808 if (list_empty(&fh
->vidq
.stream
))
810 buf
= list_entry(fh
->vidq
.stream
.next
,
811 struct cx23885_buffer
, vb
.stream
);
814 buf
= (struct cx23885_buffer
*)fh
->vidq
.read_buf
;
818 poll_wait(file
, &buf
->vb
.done
, wait
);
819 if (buf
->vb
.state
== VIDEOBUF_DONE
||
820 buf
->vb
.state
== VIDEOBUF_ERROR
)
821 rc
= POLLIN
|POLLRDNORM
;
825 mutex_unlock(&fh
->vidq
.vb_lock
);
829 static int video_release(struct file
*file
)
831 struct cx23885_fh
*fh
= file
->private_data
;
832 struct cx23885_dev
*dev
= fh
->dev
;
834 /* turn off overlay */
835 if (res_check(fh
, RESOURCE_OVERLAY
)) {
837 res_free(dev
, fh
, RESOURCE_OVERLAY
);
840 /* stop video capture */
841 if (res_check(fh
, RESOURCE_VIDEO
)) {
842 videobuf_queue_cancel(&fh
->vidq
);
843 res_free(dev
, fh
, RESOURCE_VIDEO
);
845 if (fh
->vidq
.read_buf
) {
846 buffer_release(&fh
->vidq
, fh
->vidq
.read_buf
);
847 kfree(fh
->vidq
.read_buf
);
850 /* stop vbi capture */
851 if (res_check(fh
, RESOURCE_VBI
)) {
852 if (fh
->vbiq
.streaming
)
853 videobuf_streamoff(&fh
->vbiq
);
854 if (fh
->vbiq
.reading
)
855 videobuf_read_stop(&fh
->vbiq
);
856 res_free(dev
, fh
, RESOURCE_VBI
);
859 videobuf_mmap_free(&fh
->vidq
);
860 file
->private_data
= NULL
;
863 /* We are not putting the tuner to sleep here on exit, because
864 * we want to use the mpeg encoder in another session to capture
865 * tuner video. Closing this will result in no video to the encoder.
871 static int video_mmap(struct file
*file
, struct vm_area_struct
*vma
)
873 struct cx23885_fh
*fh
= file
->private_data
;
875 return videobuf_mmap_mapper(get_queue(fh
), vma
);
878 /* ------------------------------------------------------------------ */
879 /* VIDEO CTRL IOCTLS */
881 static int cx23885_get_control(struct cx23885_dev
*dev
,
882 struct v4l2_control
*ctl
)
884 dprintk(1, "%s() calling cx25840(VIDIOC_G_CTRL)\n", __func__
);
885 call_all(dev
, core
, g_ctrl
, ctl
);
889 static int cx23885_set_control(struct cx23885_dev
*dev
,
890 struct v4l2_control
*ctl
)
892 dprintk(1, "%s() calling cx25840(VIDIOC_S_CTRL)"
893 " (disabled - no action)\n", __func__
);
897 static void init_controls(struct cx23885_dev
*dev
)
899 struct v4l2_control ctrl
;
902 for (i
= 0; i
< CX23885_CTLS
; i
++) {
903 ctrl
.id
= cx23885_ctls
[i
].v
.id
;
904 ctrl
.value
= cx23885_ctls
[i
].v
.default_value
;
906 cx23885_set_control(dev
, &ctrl
);
910 /* ------------------------------------------------------------------ */
913 static int vidioc_g_fmt_vid_cap(struct file
*file
, void *priv
,
914 struct v4l2_format
*f
)
916 struct cx23885_fh
*fh
= priv
;
918 f
->fmt
.pix
.width
= fh
->width
;
919 f
->fmt
.pix
.height
= fh
->height
;
920 f
->fmt
.pix
.field
= fh
->vidq
.field
;
921 f
->fmt
.pix
.pixelformat
= fh
->fmt
->fourcc
;
922 f
->fmt
.pix
.bytesperline
=
923 (f
->fmt
.pix
.width
* fh
->fmt
->depth
) >> 3;
924 f
->fmt
.pix
.sizeimage
=
925 f
->fmt
.pix
.height
* f
->fmt
.pix
.bytesperline
;
930 static int vidioc_try_fmt_vid_cap(struct file
*file
, void *priv
,
931 struct v4l2_format
*f
)
933 struct cx23885_dev
*dev
= ((struct cx23885_fh
*)priv
)->dev
;
934 struct cx23885_fmt
*fmt
;
935 enum v4l2_field field
;
936 unsigned int maxw
, maxh
;
938 fmt
= format_by_fourcc(f
->fmt
.pix
.pixelformat
);
942 field
= f
->fmt
.pix
.field
;
943 maxw
= norm_maxw(dev
->tvnorm
);
944 maxh
= norm_maxh(dev
->tvnorm
);
946 if (V4L2_FIELD_ANY
== field
) {
947 field
= (f
->fmt
.pix
.height
> maxh
/2)
948 ? V4L2_FIELD_INTERLACED
954 case V4L2_FIELD_BOTTOM
:
957 case V4L2_FIELD_INTERLACED
:
963 f
->fmt
.pix
.field
= field
;
964 v4l_bound_align_image(&f
->fmt
.pix
.width
, 48, maxw
, 2,
965 &f
->fmt
.pix
.height
, 32, maxh
, 0, 0);
966 f
->fmt
.pix
.bytesperline
=
967 (f
->fmt
.pix
.width
* fmt
->depth
) >> 3;
968 f
->fmt
.pix
.sizeimage
=
969 f
->fmt
.pix
.height
* f
->fmt
.pix
.bytesperline
;
974 static int vidioc_s_fmt_vid_cap(struct file
*file
, void *priv
,
975 struct v4l2_format
*f
)
977 struct cx23885_fh
*fh
= priv
;
978 struct cx23885_dev
*dev
= ((struct cx23885_fh
*)priv
)->dev
;
981 dprintk(2, "%s()\n", __func__
);
982 err
= vidioc_try_fmt_vid_cap(file
, priv
, f
);
986 fh
->fmt
= format_by_fourcc(f
->fmt
.pix
.pixelformat
);
987 fh
->width
= f
->fmt
.pix
.width
;
988 fh
->height
= f
->fmt
.pix
.height
;
989 fh
->vidq
.field
= f
->fmt
.pix
.field
;
990 dprintk(2, "%s() width=%d height=%d field=%d\n", __func__
,
991 fh
->width
, fh
->height
, fh
->vidq
.field
);
992 call_all(dev
, video
, s_fmt
, f
);
996 static int vidioc_querycap(struct file
*file
, void *priv
,
997 struct v4l2_capability
*cap
)
999 struct cx23885_dev
*dev
= ((struct cx23885_fh
*)priv
)->dev
;
1001 strcpy(cap
->driver
, "cx23885");
1002 strlcpy(cap
->card
, cx23885_boards
[dev
->board
].name
,
1004 sprintf(cap
->bus_info
, "PCIe:%s", pci_name(dev
->pci
));
1005 cap
->version
= CX23885_VERSION_CODE
;
1007 V4L2_CAP_VIDEO_CAPTURE
|
1008 V4L2_CAP_READWRITE
|
1009 V4L2_CAP_STREAMING
|
1010 V4L2_CAP_VBI_CAPTURE
;
1011 if (UNSET
!= dev
->tuner_type
)
1012 cap
->capabilities
|= V4L2_CAP_TUNER
;
1016 static int vidioc_enum_fmt_vid_cap(struct file
*file
, void *priv
,
1017 struct v4l2_fmtdesc
*f
)
1019 if (unlikely(f
->index
>= ARRAY_SIZE(formats
)))
1022 strlcpy(f
->description
, formats
[f
->index
].name
,
1023 sizeof(f
->description
));
1024 f
->pixelformat
= formats
[f
->index
].fourcc
;
1029 #ifdef CONFIG_VIDEO_V4L1_COMPAT
1030 static int vidiocgmbuf(struct file
*file
, void *priv
,
1031 struct video_mbuf
*mbuf
)
1033 struct cx23885_fh
*fh
= priv
;
1034 struct videobuf_queue
*q
;
1035 struct v4l2_requestbuffers req
;
1040 memset(&req
, 0, sizeof(req
));
1043 req
.memory
= V4L2_MEMORY_MMAP
;
1044 err
= videobuf_reqbufs(q
, &req
);
1048 mbuf
->frames
= req
.count
;
1050 for (i
= 0; i
< mbuf
->frames
; i
++) {
1051 mbuf
->offsets
[i
] = q
->bufs
[i
]->boff
;
1052 mbuf
->size
+= q
->bufs
[i
]->bsize
;
1058 static int vidioc_reqbufs(struct file
*file
, void *priv
,
1059 struct v4l2_requestbuffers
*p
)
1061 struct cx23885_fh
*fh
= priv
;
1062 return videobuf_reqbufs(get_queue(fh
), p
);
1065 static int vidioc_querybuf(struct file
*file
, void *priv
,
1066 struct v4l2_buffer
*p
)
1068 struct cx23885_fh
*fh
= priv
;
1069 return videobuf_querybuf(get_queue(fh
), p
);
1072 static int vidioc_qbuf(struct file
*file
, void *priv
,
1073 struct v4l2_buffer
*p
)
1075 struct cx23885_fh
*fh
= priv
;
1076 return videobuf_qbuf(get_queue(fh
), p
);
1079 static int vidioc_dqbuf(struct file
*file
, void *priv
,
1080 struct v4l2_buffer
*p
)
1082 struct cx23885_fh
*fh
= priv
;
1083 return videobuf_dqbuf(get_queue(fh
), p
,
1084 file
->f_flags
& O_NONBLOCK
);
1087 static int vidioc_streamon(struct file
*file
, void *priv
,
1088 enum v4l2_buf_type i
)
1090 struct cx23885_fh
*fh
= priv
;
1091 struct cx23885_dev
*dev
= fh
->dev
;
1092 dprintk(1, "%s()\n", __func__
);
1094 if (unlikely(fh
->type
!= V4L2_BUF_TYPE_VIDEO_CAPTURE
))
1096 if (unlikely(i
!= fh
->type
))
1099 if (unlikely(!res_get(dev
, fh
, get_resource(fh
))))
1101 return videobuf_streamon(get_queue(fh
));
1104 static int vidioc_streamoff(struct file
*file
, void *priv
, enum v4l2_buf_type i
)
1106 struct cx23885_fh
*fh
= priv
;
1107 struct cx23885_dev
*dev
= fh
->dev
;
1109 dprintk(1, "%s()\n", __func__
);
1111 if (fh
->type
!= V4L2_BUF_TYPE_VIDEO_CAPTURE
)
1116 res
= get_resource(fh
);
1117 err
= videobuf_streamoff(get_queue(fh
));
1120 res_free(dev
, fh
, res
);
1124 static int vidioc_s_std(struct file
*file
, void *priv
, v4l2_std_id
*tvnorms
)
1126 struct cx23885_dev
*dev
= ((struct cx23885_fh
*)priv
)->dev
;
1127 dprintk(1, "%s()\n", __func__
);
1129 mutex_lock(&dev
->lock
);
1130 cx23885_set_tvnorm(dev
, *tvnorms
);
1131 mutex_unlock(&dev
->lock
);
1136 static int cx23885_enum_input(struct cx23885_dev
*dev
, struct v4l2_input
*i
)
1138 static const char *iname
[] = {
1139 [CX23885_VMUX_COMPOSITE1
] = "Composite1",
1140 [CX23885_VMUX_COMPOSITE2
] = "Composite2",
1141 [CX23885_VMUX_COMPOSITE3
] = "Composite3",
1142 [CX23885_VMUX_COMPOSITE4
] = "Composite4",
1143 [CX23885_VMUX_SVIDEO
] = "S-Video",
1144 [CX23885_VMUX_COMPONENT
] = "Component",
1145 [CX23885_VMUX_TELEVISION
] = "Television",
1146 [CX23885_VMUX_CABLE
] = "Cable TV",
1147 [CX23885_VMUX_DVB
] = "DVB",
1148 [CX23885_VMUX_DEBUG
] = "for debug only",
1151 dprintk(1, "%s()\n", __func__
);
1157 if (0 == INPUT(n
)->type
)
1160 memset(i
, 0, sizeof(*i
));
1162 i
->type
= V4L2_INPUT_TYPE_CAMERA
;
1163 strcpy(i
->name
, iname
[INPUT(n
)->type
]);
1164 if ((CX23885_VMUX_TELEVISION
== INPUT(n
)->type
) ||
1165 (CX23885_VMUX_CABLE
== INPUT(n
)->type
))
1166 i
->type
= V4L2_INPUT_TYPE_TUNER
;
1167 i
->std
= CX23885_NORMS
;
1171 static int vidioc_enum_input(struct file
*file
, void *priv
,
1172 struct v4l2_input
*i
)
1174 struct cx23885_dev
*dev
= ((struct cx23885_fh
*)priv
)->dev
;
1175 dprintk(1, "%s()\n", __func__
);
1176 return cx23885_enum_input(dev
, i
);
1179 static int vidioc_g_input(struct file
*file
, void *priv
, unsigned int *i
)
1181 struct cx23885_dev
*dev
= ((struct cx23885_fh
*)priv
)->dev
;
1184 dprintk(1, "%s() returns %d\n", __func__
, *i
);
1188 static int vidioc_s_input(struct file
*file
, void *priv
, unsigned int i
)
1190 struct cx23885_dev
*dev
= ((struct cx23885_fh
*)priv
)->dev
;
1192 dprintk(1, "%s(%d)\n", __func__
, i
);
1195 dprintk(1, "%s() -EINVAL\n", __func__
);
1199 mutex_lock(&dev
->lock
);
1200 cx23885_video_mux(dev
, i
);
1201 mutex_unlock(&dev
->lock
);
1205 static int vidioc_queryctrl(struct file
*file
, void *priv
,
1206 struct v4l2_queryctrl
*qctrl
)
1208 qctrl
->id
= v4l2_ctrl_next(ctrl_classes
, qctrl
->id
);
1209 if (unlikely(qctrl
->id
== 0))
1211 return cx23885_ctrl_query(qctrl
);
1214 static int vidioc_g_ctrl(struct file
*file
, void *priv
,
1215 struct v4l2_control
*ctl
)
1217 struct cx23885_dev
*dev
= ((struct cx23885_fh
*)priv
)->dev
;
1219 return cx23885_get_control(dev
, ctl
);
1222 static int vidioc_s_ctrl(struct file
*file
, void *priv
,
1223 struct v4l2_control
*ctl
)
1225 struct cx23885_dev
*dev
= ((struct cx23885_fh
*)priv
)->dev
;
1227 return cx23885_set_control(dev
, ctl
);
1230 static int vidioc_g_tuner(struct file
*file
, void *priv
,
1231 struct v4l2_tuner
*t
)
1233 struct cx23885_dev
*dev
= ((struct cx23885_fh
*)priv
)->dev
;
1235 if (unlikely(UNSET
== dev
->tuner_type
))
1240 strcpy(t
->name
, "Television");
1241 t
->type
= V4L2_TUNER_ANALOG_TV
;
1242 t
->capability
= V4L2_TUNER_CAP_NORM
;
1243 t
->rangehigh
= 0xffffffffUL
;
1244 t
->signal
= 0xffff ; /* LOCKED */
1248 static int vidioc_s_tuner(struct file
*file
, void *priv
,
1249 struct v4l2_tuner
*t
)
1251 struct cx23885_dev
*dev
= ((struct cx23885_fh
*)priv
)->dev
;
1253 if (UNSET
== dev
->tuner_type
)
1260 static int vidioc_g_frequency(struct file
*file
, void *priv
,
1261 struct v4l2_frequency
*f
)
1263 struct cx23885_fh
*fh
= priv
;
1264 struct cx23885_dev
*dev
= fh
->dev
;
1266 if (unlikely(UNSET
== dev
->tuner_type
))
1269 /* f->type = fh->radio ? V4L2_TUNER_RADIO : V4L2_TUNER_ANALOG_TV; */
1270 f
->type
= fh
->radio
? V4L2_TUNER_RADIO
: V4L2_TUNER_ANALOG_TV
;
1271 f
->frequency
= dev
->freq
;
1273 call_all(dev
, tuner
, g_frequency
, f
);
1278 static int cx23885_set_freq(struct cx23885_dev
*dev
, struct v4l2_frequency
*f
)
1280 if (unlikely(UNSET
== dev
->tuner_type
))
1282 if (unlikely(f
->tuner
!= 0))
1285 mutex_lock(&dev
->lock
);
1286 dev
->freq
= f
->frequency
;
1288 call_all(dev
, tuner
, s_frequency
, f
);
1290 /* When changing channels it is required to reset TVAUDIO */
1293 mutex_unlock(&dev
->lock
);
1298 static int vidioc_s_frequency(struct file
*file
, void *priv
,
1299 struct v4l2_frequency
*f
)
1301 struct cx23885_fh
*fh
= priv
;
1302 struct cx23885_dev
*dev
= fh
->dev
;
1304 if (unlikely(0 == fh
->radio
&& f
->type
!= V4L2_TUNER_ANALOG_TV
))
1306 if (unlikely(1 == fh
->radio
&& f
->type
!= V4L2_TUNER_RADIO
))
1310 cx23885_set_freq(dev
, f
);
1313 /* ----------------------------------------------------------- */
1315 static void cx23885_vid_timeout(unsigned long data
)
1317 struct cx23885_dev
*dev
= (struct cx23885_dev
*)data
;
1318 struct cx23885_dmaqueue
*q
= &dev
->vidq
;
1319 struct cx23885_buffer
*buf
;
1320 unsigned long flags
;
1322 cx23885_sram_channel_dump(dev
, &dev
->sram_channels
[SRAM_CH01
]);
1324 cx_clear(VID_A_DMA_CTL
, 0x11);
1326 spin_lock_irqsave(&dev
->slock
, flags
);
1327 while (!list_empty(&q
->active
)) {
1328 buf
= list_entry(q
->active
.next
,
1329 struct cx23885_buffer
, vb
.queue
);
1330 list_del(&buf
->vb
.queue
);
1331 buf
->vb
.state
= VIDEOBUF_ERROR
;
1332 wake_up(&buf
->vb
.done
);
1333 printk(KERN_ERR
"%s/0: [%p/%d] timeout - dma=0x%08lx\n",
1334 dev
->name
, buf
, buf
->vb
.i
,
1335 (unsigned long)buf
->risc
.dma
);
1337 cx23885_restart_video_queue(dev
, q
);
1338 spin_unlock_irqrestore(&dev
->slock
, flags
);
1341 int cx23885_video_irq(struct cx23885_dev
*dev
, u32 status
)
1346 mask
= cx_read(VID_A_INT_MSK
);
1347 if (0 == (status
& mask
))
1349 cx_write(VID_A_INT_STAT
, status
);
1351 dprintk(2, "%s() status = 0x%08x\n", __func__
, status
);
1352 /* risc op code error */
1353 if (status
& (1 << 16)) {
1354 printk(KERN_WARNING
"%s/0: video risc op code error\n",
1356 cx_clear(VID_A_DMA_CTL
, 0x11);
1357 cx23885_sram_channel_dump(dev
, &dev
->sram_channels
[SRAM_CH01
]);
1361 if (status
& 0x01) {
1362 spin_lock(&dev
->slock
);
1363 count
= cx_read(VID_A_GPCNT
);
1364 cx23885_video_wakeup(dev
, &dev
->vidq
, count
);
1365 spin_unlock(&dev
->slock
);
1369 if (status
& 0x10) {
1370 dprintk(2, "stopper video\n");
1371 spin_lock(&dev
->slock
);
1372 cx23885_restart_video_queue(dev
, &dev
->vidq
);
1373 spin_unlock(&dev
->slock
);
1380 /* ----------------------------------------------------------- */
1381 /* exported stuff */
1383 static const struct v4l2_file_operations video_fops
= {
1384 .owner
= THIS_MODULE
,
1386 .release
= video_release
,
1390 .ioctl
= video_ioctl2
,
1393 static const struct v4l2_ioctl_ops video_ioctl_ops
= {
1394 .vidioc_querycap
= vidioc_querycap
,
1395 .vidioc_enum_fmt_vid_cap
= vidioc_enum_fmt_vid_cap
,
1396 .vidioc_g_fmt_vid_cap
= vidioc_g_fmt_vid_cap
,
1397 .vidioc_try_fmt_vid_cap
= vidioc_try_fmt_vid_cap
,
1398 .vidioc_s_fmt_vid_cap
= vidioc_s_fmt_vid_cap
,
1399 .vidioc_g_fmt_vbi_cap
= cx23885_vbi_fmt
,
1400 .vidioc_try_fmt_vbi_cap
= cx23885_vbi_fmt
,
1401 .vidioc_s_fmt_vbi_cap
= cx23885_vbi_fmt
,
1402 .vidioc_reqbufs
= vidioc_reqbufs
,
1403 .vidioc_querybuf
= vidioc_querybuf
,
1404 .vidioc_qbuf
= vidioc_qbuf
,
1405 .vidioc_dqbuf
= vidioc_dqbuf
,
1406 .vidioc_s_std
= vidioc_s_std
,
1407 .vidioc_enum_input
= vidioc_enum_input
,
1408 .vidioc_g_input
= vidioc_g_input
,
1409 .vidioc_s_input
= vidioc_s_input
,
1410 .vidioc_queryctrl
= vidioc_queryctrl
,
1411 .vidioc_g_ctrl
= vidioc_g_ctrl
,
1412 .vidioc_s_ctrl
= vidioc_s_ctrl
,
1413 .vidioc_streamon
= vidioc_streamon
,
1414 .vidioc_streamoff
= vidioc_streamoff
,
1415 #ifdef CONFIG_VIDEO_V4L1_COMPAT
1416 .vidiocgmbuf
= vidiocgmbuf
,
1418 .vidioc_g_tuner
= vidioc_g_tuner
,
1419 .vidioc_s_tuner
= vidioc_s_tuner
,
1420 .vidioc_g_frequency
= vidioc_g_frequency
,
1421 .vidioc_s_frequency
= vidioc_s_frequency
,
1422 .vidioc_g_chip_ident
= cx23885_g_chip_ident
,
1423 #ifdef CONFIG_VIDEO_ADV_DEBUG
1424 .vidioc_g_register
= cx23885_g_register
,
1425 .vidioc_s_register
= cx23885_s_register
,
1429 static struct video_device cx23885_vbi_template
;
1430 static struct video_device cx23885_video_template
= {
1431 .name
= "cx23885-video",
1432 .fops
= &video_fops
,
1433 .ioctl_ops
= &video_ioctl_ops
,
1434 .tvnorms
= CX23885_NORMS
,
1435 .current_norm
= V4L2_STD_NTSC_M
,
1438 static const struct v4l2_file_operations radio_fops
= {
1439 .owner
= THIS_MODULE
,
1441 .release
= video_release
,
1442 .ioctl
= video_ioctl2
,
1446 void cx23885_video_unregister(struct cx23885_dev
*dev
)
1448 dprintk(1, "%s()\n", __func__
);
1449 cx_clear(PCI_INT_MSK
, 1);
1451 if (dev
->video_dev
) {
1452 if (video_is_registered(dev
->video_dev
))
1453 video_unregister_device(dev
->video_dev
);
1455 video_device_release(dev
->video_dev
);
1456 dev
->video_dev
= NULL
;
1458 btcx_riscmem_free(dev
->pci
, &dev
->vidq
.stopper
);
1462 int cx23885_video_register(struct cx23885_dev
*dev
)
1466 dprintk(1, "%s()\n", __func__
);
1467 spin_lock_init(&dev
->slock
);
1469 /* Initialize VBI template */
1470 memcpy(&cx23885_vbi_template
, &cx23885_video_template
,
1471 sizeof(cx23885_vbi_template
));
1472 strcpy(cx23885_vbi_template
.name
, "cx23885-vbi");
1474 dev
->tvnorm
= cx23885_video_template
.current_norm
;
1476 /* init video dma queues */
1477 INIT_LIST_HEAD(&dev
->vidq
.active
);
1478 INIT_LIST_HEAD(&dev
->vidq
.queued
);
1479 dev
->vidq
.timeout
.function
= cx23885_vid_timeout
;
1480 dev
->vidq
.timeout
.data
= (unsigned long)dev
;
1481 init_timer(&dev
->vidq
.timeout
);
1482 cx23885_risc_stopper(dev
->pci
, &dev
->vidq
.stopper
,
1483 VID_A_DMA_CTL
, 0x11, 0x00);
1485 /* Don't enable VBI yet */
1486 cx_set(PCI_INT_MSK
, 1);
1488 if (TUNER_ABSENT
!= dev
->tuner_type
) {
1489 struct v4l2_subdev
*sd
= NULL
;
1491 if (dev
->tuner_addr
)
1492 sd
= v4l2_i2c_new_subdev(&dev
->v4l2_dev
,
1493 &dev
->i2c_bus
[1].i2c_adap
,
1494 "tuner", "tuner", dev
->tuner_addr
, NULL
);
1496 sd
= v4l2_i2c_new_subdev(&dev
->v4l2_dev
,
1497 &dev
->i2c_bus
[1].i2c_adap
,
1498 "tuner", "tuner", 0, v4l2_i2c_tuner_addrs(ADDRS_TV
));
1500 struct tuner_setup tun_setup
;
1502 memset(&tun_setup
, 0, sizeof(tun_setup
));
1503 tun_setup
.mode_mask
= T_ANALOG_TV
;
1504 tun_setup
.type
= dev
->tuner_type
;
1505 tun_setup
.addr
= v4l2_i2c_subdev_addr(sd
);
1506 tun_setup
.tuner_callback
= cx23885_tuner_callback
;
1508 v4l2_subdev_call(sd
, tuner
, s_type_addr
, &tun_setup
);
1510 if (dev
->board
== CX23885_BOARD_LEADTEK_WINFAST_PXTV1200
) {
1511 struct xc2028_ctrl ctrl
= {
1512 .fname
= XC2028_DEFAULT_FIRMWARE
,
1515 struct v4l2_priv_tun_config cfg
= {
1516 .tuner
= dev
->tuner_type
,
1519 v4l2_subdev_call(sd
, tuner
, s_config
, &cfg
);
1525 /* register v4l devices */
1526 dev
->video_dev
= cx23885_vdev_init(dev
, dev
->pci
,
1527 &cx23885_video_template
, "video");
1528 err
= video_register_device(dev
->video_dev
, VFL_TYPE_GRABBER
,
1531 printk(KERN_INFO
"%s: can't register video device\n",
1535 printk(KERN_INFO
"%s/0: registered device %s [v4l2]\n",
1536 dev
->name
, video_device_node_name(dev
->video_dev
));
1537 /* initial device configuration */
1538 mutex_lock(&dev
->lock
);
1539 cx23885_set_tvnorm(dev
, dev
->tvnorm
);
1541 cx23885_video_mux(dev
, 0);
1542 mutex_unlock(&dev
->lock
);
1547 cx23885_video_unregister(dev
);