3 * device driver for Conexant 2388x based TV cards
4 * video4linux video interface
6 * (c) 2003-04 Gerd Knorr <kraxel@bytesex.org> [SuSE Labs]
8 * (c) 2005-2006 Mauro Carvalho Chehab <mchehab@infradead.org>
10 * - video_ioctl2 conversion
13 * This program is free software; you can redistribute it and/or modify
14 * it under the terms of the GNU General Public License as published by
15 * the Free Software Foundation; either version 2 of the License, or
16 * (at your option) any later version.
18 * This program is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU General Public License for more details.
23 * You should have received a copy of the GNU General Public License
24 * along with this program; if not, write to the Free Software
25 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
28 #include <linux/init.h>
29 #include <linux/list.h>
30 #include <linux/module.h>
31 #include <linux/kmod.h>
32 #include <linux/kernel.h>
33 #include <linux/slab.h>
34 #include <linux/interrupt.h>
35 #include <linux/dma-mapping.h>
36 #include <linux/delay.h>
37 #include <linux/kthread.h>
38 #include <asm/div64.h>
41 #include <media/v4l2-common.h>
42 #include <media/v4l2-ioctl.h>
43 #include <media/v4l2-event.h>
44 #include <media/wm8775.h>
46 MODULE_DESCRIPTION("v4l2 driver module for cx2388x based TV cards");
47 MODULE_AUTHOR("Gerd Knorr <kraxel@bytesex.org> [SuSE Labs]");
48 MODULE_LICENSE("GPL");
49 MODULE_VERSION(CX88_VERSION
);
51 /* ------------------------------------------------------------------ */
53 static unsigned int video_nr
[] = {[0 ... (CX88_MAXBOARDS
- 1)] = UNSET
};
54 static unsigned int vbi_nr
[] = {[0 ... (CX88_MAXBOARDS
- 1)] = UNSET
};
55 static unsigned int radio_nr
[] = {[0 ... (CX88_MAXBOARDS
- 1)] = UNSET
};
57 module_param_array(video_nr
, int, NULL
, 0444);
58 module_param_array(vbi_nr
, int, NULL
, 0444);
59 module_param_array(radio_nr
, int, NULL
, 0444);
61 MODULE_PARM_DESC(video_nr
,"video device numbers");
62 MODULE_PARM_DESC(vbi_nr
,"vbi device numbers");
63 MODULE_PARM_DESC(radio_nr
,"radio device numbers");
65 static unsigned int video_debug
;
66 module_param(video_debug
,int,0644);
67 MODULE_PARM_DESC(video_debug
,"enable debug messages [video]");
69 static unsigned int irq_debug
;
70 module_param(irq_debug
,int,0644);
71 MODULE_PARM_DESC(irq_debug
,"enable debug messages [IRQ handler]");
73 #define dprintk(level,fmt, arg...) if (video_debug >= level) \
74 printk(KERN_DEBUG "%s/0: " fmt, core->name , ## arg)
76 /* ------------------------------------------------------------------- */
79 static const struct cx8800_fmt formats
[] = {
81 .name
= "8 bpp, gray",
82 .fourcc
= V4L2_PIX_FMT_GREY
,
83 .cxformat
= ColorFormatY8
,
85 .flags
= FORMAT_FLAGS_PACKED
,
87 .name
= "15 bpp RGB, le",
88 .fourcc
= V4L2_PIX_FMT_RGB555
,
89 .cxformat
= ColorFormatRGB15
,
91 .flags
= FORMAT_FLAGS_PACKED
,
93 .name
= "15 bpp RGB, be",
94 .fourcc
= V4L2_PIX_FMT_RGB555X
,
95 .cxformat
= ColorFormatRGB15
| ColorFormatBSWAP
,
97 .flags
= FORMAT_FLAGS_PACKED
,
99 .name
= "16 bpp RGB, le",
100 .fourcc
= V4L2_PIX_FMT_RGB565
,
101 .cxformat
= ColorFormatRGB16
,
103 .flags
= FORMAT_FLAGS_PACKED
,
105 .name
= "16 bpp RGB, be",
106 .fourcc
= V4L2_PIX_FMT_RGB565X
,
107 .cxformat
= ColorFormatRGB16
| ColorFormatBSWAP
,
109 .flags
= FORMAT_FLAGS_PACKED
,
111 .name
= "24 bpp RGB, le",
112 .fourcc
= V4L2_PIX_FMT_BGR24
,
113 .cxformat
= ColorFormatRGB24
,
115 .flags
= FORMAT_FLAGS_PACKED
,
117 .name
= "32 bpp RGB, le",
118 .fourcc
= V4L2_PIX_FMT_BGR32
,
119 .cxformat
= ColorFormatRGB32
,
121 .flags
= FORMAT_FLAGS_PACKED
,
123 .name
= "32 bpp RGB, be",
124 .fourcc
= V4L2_PIX_FMT_RGB32
,
125 .cxformat
= ColorFormatRGB32
| ColorFormatBSWAP
| ColorFormatWSWAP
,
127 .flags
= FORMAT_FLAGS_PACKED
,
129 .name
= "4:2:2, packed, YUYV",
130 .fourcc
= V4L2_PIX_FMT_YUYV
,
131 .cxformat
= ColorFormatYUY2
,
133 .flags
= FORMAT_FLAGS_PACKED
,
135 .name
= "4:2:2, packed, UYVY",
136 .fourcc
= V4L2_PIX_FMT_UYVY
,
137 .cxformat
= ColorFormatYUY2
| ColorFormatBSWAP
,
139 .flags
= FORMAT_FLAGS_PACKED
,
143 static const struct cx8800_fmt
* format_by_fourcc(unsigned int fourcc
)
147 for (i
= 0; i
< ARRAY_SIZE(formats
); i
++)
148 if (formats
[i
].fourcc
== fourcc
)
153 /* ------------------------------------------------------------------- */
156 /* control information */
163 /* control register information */
171 static const struct cx88_ctrl cx8800_vid_ctls
[] = {
174 .id
= V4L2_CID_BRIGHTNESS
,
178 .default_value
= 0x7f,
180 .reg
= MO_CONTR_BRIGHT
,
184 .id
= V4L2_CID_CONTRAST
,
188 .default_value
= 0x3f,
190 .reg
= MO_CONTR_BRIGHT
,
198 .default_value
= 0x7f,
204 /* strictly, this only describes only U saturation.
205 * V saturation is handled specially through code.
207 .id
= V4L2_CID_SATURATION
,
211 .default_value
= 0x7f,
213 .reg
= MO_UV_SATURATION
,
217 .id
= V4L2_CID_SHARPNESS
,
221 .default_value
= 0x0,
223 /* NOTE: the value is converted and written to both even
224 and odd registers in the code */
225 .reg
= MO_FILTER_ODD
,
229 .id
= V4L2_CID_CHROMA_AGC
,
232 .default_value
= 0x1,
233 .reg
= MO_INPUT_FORMAT
,
237 .id
= V4L2_CID_COLOR_KILLER
,
240 .default_value
= 0x1,
241 .reg
= MO_INPUT_FORMAT
,
245 .id
= V4L2_CID_BAND_STOP_FILTER
,
249 .default_value
= 0x0,
257 static const struct cx88_ctrl cx8800_aud_ctls
[] = {
260 .id
= V4L2_CID_AUDIO_MUTE
,
265 .sreg
= SHADOW_AUD_VOL_CTL
,
269 .id
= V4L2_CID_AUDIO_VOLUME
,
273 .default_value
= 0x3f,
275 .sreg
= SHADOW_AUD_VOL_CTL
,
279 .id
= V4L2_CID_AUDIO_BALANCE
,
283 .default_value
= 0x40,
285 .sreg
= SHADOW_AUD_BAL_CTL
,
292 CX8800_VID_CTLS
= ARRAY_SIZE(cx8800_vid_ctls
),
293 CX8800_AUD_CTLS
= ARRAY_SIZE(cx8800_aud_ctls
),
296 /* ------------------------------------------------------------------ */
298 int cx88_video_mux(struct cx88_core
*core
, unsigned int input
)
300 /* struct cx88_core *core = dev->core; */
302 dprintk(1,"video_mux: %d [vmux=%d,gpio=0x%x,0x%x,0x%x,0x%x]\n",
303 input
, INPUT(input
).vmux
,
304 INPUT(input
).gpio0
,INPUT(input
).gpio1
,
305 INPUT(input
).gpio2
,INPUT(input
).gpio3
);
307 cx_andor(MO_INPUT_FORMAT
, 0x03 << 14, INPUT(input
).vmux
<< 14);
308 cx_write(MO_GP3_IO
, INPUT(input
).gpio3
);
309 cx_write(MO_GP0_IO
, INPUT(input
).gpio0
);
310 cx_write(MO_GP1_IO
, INPUT(input
).gpio1
);
311 cx_write(MO_GP2_IO
, INPUT(input
).gpio2
);
313 switch (INPUT(input
).type
) {
314 case CX88_VMUX_SVIDEO
:
315 cx_set(MO_AFECFG_IO
, 0x00000001);
316 cx_set(MO_INPUT_FORMAT
, 0x00010010);
317 cx_set(MO_FILTER_EVEN
, 0x00002020);
318 cx_set(MO_FILTER_ODD
, 0x00002020);
321 cx_clear(MO_AFECFG_IO
, 0x00000001);
322 cx_clear(MO_INPUT_FORMAT
, 0x00010010);
323 cx_clear(MO_FILTER_EVEN
, 0x00002020);
324 cx_clear(MO_FILTER_ODD
, 0x00002020);
328 /* if there are audioroutes defined, we have an external
329 ADC to deal with audio */
330 if (INPUT(input
).audioroute
) {
331 /* The wm8775 module has the "2" route hardwired into
332 the initialization. Some boards may use different
333 routes for different inputs. HVR-1300 surely does */
334 if (core
->sd_wm8775
) {
335 call_all(core
, audio
, s_routing
,
336 INPUT(input
).audioroute
, 0, 0);
338 /* cx2388's C-ADC is connected to the tuner only.
339 When used with S-Video, that ADC is busy dealing with
340 chroma, so an external must be used for baseband audio */
341 if (INPUT(input
).type
!= CX88_VMUX_TELEVISION
&&
342 INPUT(input
).type
!= CX88_VMUX_CABLE
) {
344 core
->tvaudio
= WW_I2SADC
;
345 cx88_set_tvaudio(core
);
348 cx_write(AUD_I2SCNTL
, 0x0);
349 cx_clear(AUD_CTL
, EN_I2SIN_ENABLE
);
355 EXPORT_SYMBOL(cx88_video_mux
);
357 /* ------------------------------------------------------------------ */
359 static int start_video_dma(struct cx8800_dev
*dev
,
360 struct cx88_dmaqueue
*q
,
361 struct cx88_buffer
*buf
)
363 struct cx88_core
*core
= dev
->core
;
365 /* setup fifo + format */
366 cx88_sram_channel_setup(core
, &cx88_sram_channels
[SRAM_CH21
],
367 buf
->bpl
, buf
->risc
.dma
);
368 cx88_set_scale(core
, core
->width
, core
->height
, core
->field
);
369 cx_write(MO_COLOR_CTRL
, dev
->fmt
->cxformat
| ColorFormatGamma
);
372 cx_write(MO_VIDY_GPCNTRL
,GP_COUNT_CONTROL_RESET
);
376 cx_set(MO_PCI_INTMSK
, core
->pci_irqmask
| PCI_INT_VIDINT
);
378 /* Enables corresponding bits at PCI_INT_STAT:
379 bits 0 to 4: video, audio, transport stream, VIP, Host
381 bits 8 and 9: DMA complete for: SRC, DST
382 bits 10 and 11: BERR signal asserted for RISC: RD, WR
383 bits 12 to 15: BERR signal asserted for: BRDG, SRC, DST, IPB
385 cx_set(MO_VID_INTMSK
, 0x0f0011);
388 cx_set(VID_CAPTURE_CONTROL
,0x06);
391 cx_set(MO_DEV_CNTRL2
, (1<<5));
392 cx_set(MO_VID_DMACNTRL
, 0x11); /* Planar Y and packed FIFO and RISC enable */
398 static int stop_video_dma(struct cx8800_dev
*dev
)
400 struct cx88_core
*core
= dev
->core
;
403 cx_clear(MO_VID_DMACNTRL
, 0x11);
405 /* disable capture */
406 cx_clear(VID_CAPTURE_CONTROL
,0x06);
409 cx_clear(MO_PCI_INTMSK
, PCI_INT_VIDINT
);
410 cx_clear(MO_VID_INTMSK
, 0x0f0011);
414 static int restart_video_queue(struct cx8800_dev
*dev
,
415 struct cx88_dmaqueue
*q
)
417 struct cx88_core
*core
= dev
->core
;
418 struct cx88_buffer
*buf
;
420 if (!list_empty(&q
->active
)) {
421 buf
= list_entry(q
->active
.next
, struct cx88_buffer
, list
);
422 dprintk(2,"restart_queue [%p/%d]: restart dma\n",
423 buf
, buf
->vb
.v4l2_buf
.index
);
424 start_video_dma(dev
, q
, buf
);
430 /* ------------------------------------------------------------------ */
432 static int queue_setup(struct vb2_queue
*q
, const struct v4l2_format
*fmt
,
433 unsigned int *num_buffers
, unsigned int *num_planes
,
434 unsigned int sizes
[], void *alloc_ctxs
[])
436 struct cx8800_dev
*dev
= q
->drv_priv
;
437 struct cx88_core
*core
= dev
->core
;
440 sizes
[0] = (dev
->fmt
->depth
* core
->width
* core
->height
) >> 3;
441 alloc_ctxs
[0] = dev
->alloc_ctx
;
445 static int buffer_prepare(struct vb2_buffer
*vb
)
447 struct cx8800_dev
*dev
= vb
->vb2_queue
->drv_priv
;
448 struct cx88_core
*core
= dev
->core
;
449 struct cx88_buffer
*buf
= container_of(vb
, struct cx88_buffer
, vb
);
450 struct sg_table
*sgt
= vb2_dma_sg_plane_desc(vb
, 0);
452 buf
->bpl
= core
->width
* dev
->fmt
->depth
>> 3;
454 if (vb2_plane_size(vb
, 0) < core
->height
* buf
->bpl
)
456 vb2_set_plane_payload(vb
, 0, core
->height
* buf
->bpl
);
458 switch (core
->field
) {
460 cx88_risc_buffer(dev
->pci
, &buf
->risc
,
462 buf
->bpl
, 0, core
->height
);
464 case V4L2_FIELD_BOTTOM
:
465 cx88_risc_buffer(dev
->pci
, &buf
->risc
,
467 buf
->bpl
, 0, core
->height
);
469 case V4L2_FIELD_SEQ_TB
:
470 cx88_risc_buffer(dev
->pci
, &buf
->risc
,
472 0, buf
->bpl
* (core
->height
>> 1),
476 case V4L2_FIELD_SEQ_BT
:
477 cx88_risc_buffer(dev
->pci
, &buf
->risc
,
479 buf
->bpl
* (core
->height
>> 1), 0,
483 case V4L2_FIELD_INTERLACED
:
485 cx88_risc_buffer(dev
->pci
, &buf
->risc
,
486 sgt
->sgl
, 0, buf
->bpl
,
491 dprintk(2,"[%p/%d] buffer_prepare - %dx%d %dbpp \"%s\" - dma=0x%08lx\n",
492 buf
, buf
->vb
.v4l2_buf
.index
,
493 core
->width
, core
->height
, dev
->fmt
->depth
, dev
->fmt
->name
,
494 (unsigned long)buf
->risc
.dma
);
498 static void buffer_finish(struct vb2_buffer
*vb
)
500 struct cx8800_dev
*dev
= vb
->vb2_queue
->drv_priv
;
501 struct cx88_buffer
*buf
= container_of(vb
, struct cx88_buffer
, vb
);
502 struct cx88_riscmem
*risc
= &buf
->risc
;
505 pci_free_consistent(dev
->pci
, risc
->size
, risc
->cpu
, risc
->dma
);
506 memset(risc
, 0, sizeof(*risc
));
509 static void buffer_queue(struct vb2_buffer
*vb
)
511 struct cx8800_dev
*dev
= vb
->vb2_queue
->drv_priv
;
512 struct cx88_buffer
*buf
= container_of(vb
, struct cx88_buffer
, vb
);
513 struct cx88_buffer
*prev
;
514 struct cx88_core
*core
= dev
->core
;
515 struct cx88_dmaqueue
*q
= &dev
->vidq
;
517 /* add jump to start */
518 buf
->risc
.cpu
[1] = cpu_to_le32(buf
->risc
.dma
+ 8);
519 buf
->risc
.jmp
[0] = cpu_to_le32(RISC_JUMP
| RISC_CNT_INC
);
520 buf
->risc
.jmp
[1] = cpu_to_le32(buf
->risc
.dma
+ 8);
522 if (list_empty(&q
->active
)) {
523 list_add_tail(&buf
->list
, &q
->active
);
524 dprintk(2,"[%p/%d] buffer_queue - first active\n",
525 buf
, buf
->vb
.v4l2_buf
.index
);
528 buf
->risc
.cpu
[0] |= cpu_to_le32(RISC_IRQ1
);
529 prev
= list_entry(q
->active
.prev
, struct cx88_buffer
, list
);
530 list_add_tail(&buf
->list
, &q
->active
);
531 prev
->risc
.jmp
[1] = cpu_to_le32(buf
->risc
.dma
);
532 dprintk(2, "[%p/%d] buffer_queue - append to active\n",
533 buf
, buf
->vb
.v4l2_buf
.index
);
537 static int start_streaming(struct vb2_queue
*q
, unsigned int count
)
539 struct cx8800_dev
*dev
= q
->drv_priv
;
540 struct cx88_dmaqueue
*dmaq
= &dev
->vidq
;
541 struct cx88_buffer
*buf
= list_entry(dmaq
->active
.next
,
542 struct cx88_buffer
, list
);
544 start_video_dma(dev
, dmaq
, buf
);
548 static void stop_streaming(struct vb2_queue
*q
)
550 struct cx8800_dev
*dev
= q
->drv_priv
;
551 struct cx88_core
*core
= dev
->core
;
552 struct cx88_dmaqueue
*dmaq
= &dev
->vidq
;
555 cx_clear(MO_VID_DMACNTRL
, 0x11);
556 cx_clear(VID_CAPTURE_CONTROL
, 0x06);
557 spin_lock_irqsave(&dev
->slock
, flags
);
558 while (!list_empty(&dmaq
->active
)) {
559 struct cx88_buffer
*buf
= list_entry(dmaq
->active
.next
,
560 struct cx88_buffer
, list
);
562 list_del(&buf
->list
);
563 vb2_buffer_done(&buf
->vb
, VB2_BUF_STATE_ERROR
);
565 spin_unlock_irqrestore(&dev
->slock
, flags
);
568 static struct vb2_ops cx8800_video_qops
= {
569 .queue_setup
= queue_setup
,
570 .buf_prepare
= buffer_prepare
,
571 .buf_finish
= buffer_finish
,
572 .buf_queue
= buffer_queue
,
573 .wait_prepare
= vb2_ops_wait_prepare
,
574 .wait_finish
= vb2_ops_wait_finish
,
575 .start_streaming
= start_streaming
,
576 .stop_streaming
= stop_streaming
,
579 /* ------------------------------------------------------------------ */
581 static int radio_open(struct file
*file
)
583 struct cx8800_dev
*dev
= video_drvdata(file
);
584 struct cx88_core
*core
= dev
->core
;
585 int ret
= v4l2_fh_open(file
);
590 cx_write(MO_GP3_IO
, core
->board
.radio
.gpio3
);
591 cx_write(MO_GP0_IO
, core
->board
.radio
.gpio0
);
592 cx_write(MO_GP1_IO
, core
->board
.radio
.gpio1
);
593 cx_write(MO_GP2_IO
, core
->board
.radio
.gpio2
);
594 if (core
->board
.radio
.audioroute
) {
595 if (core
->sd_wm8775
) {
596 call_all(core
, audio
, s_routing
,
597 core
->board
.radio
.audioroute
, 0, 0);
600 core
->tvaudio
= WW_I2SADC
;
601 cx88_set_tvaudio(core
);
604 core
->tvaudio
= WW_FM
;
605 cx88_set_tvaudio(core
);
606 cx88_set_stereo(core
, V4L2_TUNER_MODE_STEREO
, 1);
608 call_all(core
, tuner
, s_radio
);
612 /* ------------------------------------------------------------------ */
613 /* VIDEO CTRL IOCTLS */
615 static int cx8800_s_vid_ctrl(struct v4l2_ctrl
*ctrl
)
617 struct cx88_core
*core
=
618 container_of(ctrl
->handler
, struct cx88_core
, video_hdl
);
619 const struct cx88_ctrl
*cc
= ctrl
->priv
;
624 case V4L2_CID_SATURATION
:
625 /* special v_sat handling */
627 value
= ((ctrl
->val
- cc
->off
) << cc
->shift
) & cc
->mask
;
629 if (core
->tvnorm
& V4L2_STD_SECAM
) {
630 /* For SECAM, both U and V sat should be equal */
631 value
= value
<< 8 | value
;
633 /* Keeps U Saturation proportional to V Sat */
634 value
= (value
* 0x5a) / 0x7f << 8 | value
;
638 case V4L2_CID_SHARPNESS
:
639 /* 0b000, 0b100, 0b101, 0b110, or 0b111 */
640 value
= (ctrl
->val
< 1 ? 0 : ((ctrl
->val
+ 3) << 7));
641 /* needs to be set for both fields */
642 cx_andor(MO_FILTER_EVEN
, mask
, value
);
644 case V4L2_CID_CHROMA_AGC
:
645 value
= ((ctrl
->val
- cc
->off
) << cc
->shift
) & cc
->mask
;
648 value
= ((ctrl
->val
- cc
->off
) << cc
->shift
) & cc
->mask
;
651 dprintk(1, "set_control id=0x%X(%s) ctrl=0x%02x, reg=0x%02x val=0x%02x (mask 0x%02x)%s\n",
652 ctrl
->id
, ctrl
->name
, ctrl
->val
, cc
->reg
, value
,
653 mask
, cc
->sreg
? " [shadowed]" : "");
655 cx_sandor(cc
->sreg
, cc
->reg
, mask
, value
);
657 cx_andor(cc
->reg
, mask
, value
);
661 static int cx8800_s_aud_ctrl(struct v4l2_ctrl
*ctrl
)
663 struct cx88_core
*core
=
664 container_of(ctrl
->handler
, struct cx88_core
, audio_hdl
);
665 const struct cx88_ctrl
*cc
= ctrl
->priv
;
668 /* Pass changes onto any WM8775 */
669 if (core
->sd_wm8775
) {
671 case V4L2_CID_AUDIO_MUTE
:
672 wm8775_s_ctrl(core
, ctrl
->id
, ctrl
->val
);
674 case V4L2_CID_AUDIO_VOLUME
:
675 wm8775_s_ctrl(core
, ctrl
->id
, (ctrl
->val
) ?
676 (0x90 + ctrl
->val
) << 8 : 0);
678 case V4L2_CID_AUDIO_BALANCE
:
679 wm8775_s_ctrl(core
, ctrl
->id
, ctrl
->val
<< 9);
688 case V4L2_CID_AUDIO_BALANCE
:
689 value
= (ctrl
->val
< 0x40) ? (0x7f - ctrl
->val
) : (ctrl
->val
- 0x40);
691 case V4L2_CID_AUDIO_VOLUME
:
692 value
= 0x3f - (ctrl
->val
& 0x3f);
695 value
= ((ctrl
->val
- cc
->off
) << cc
->shift
) & cc
->mask
;
698 dprintk(1,"set_control id=0x%X(%s) ctrl=0x%02x, reg=0x%02x val=0x%02x (mask 0x%02x)%s\n",
699 ctrl
->id
, ctrl
->name
, ctrl
->val
, cc
->reg
, value
,
700 mask
, cc
->sreg
? " [shadowed]" : "");
702 cx_sandor(cc
->sreg
, cc
->reg
, mask
, value
);
704 cx_andor(cc
->reg
, mask
, value
);
708 /* ------------------------------------------------------------------ */
711 static int vidioc_g_fmt_vid_cap(struct file
*file
, void *priv
,
712 struct v4l2_format
*f
)
714 struct cx8800_dev
*dev
= video_drvdata(file
);
715 struct cx88_core
*core
= dev
->core
;
717 f
->fmt
.pix
.width
= core
->width
;
718 f
->fmt
.pix
.height
= core
->height
;
719 f
->fmt
.pix
.field
= core
->field
;
720 f
->fmt
.pix
.pixelformat
= dev
->fmt
->fourcc
;
721 f
->fmt
.pix
.bytesperline
=
722 (f
->fmt
.pix
.width
* dev
->fmt
->depth
) >> 3;
723 f
->fmt
.pix
.sizeimage
=
724 f
->fmt
.pix
.height
* f
->fmt
.pix
.bytesperline
;
725 f
->fmt
.pix
.colorspace
= V4L2_COLORSPACE_SMPTE170M
;
729 static int vidioc_try_fmt_vid_cap(struct file
*file
, void *priv
,
730 struct v4l2_format
*f
)
732 struct cx8800_dev
*dev
= video_drvdata(file
);
733 struct cx88_core
*core
= dev
->core
;
734 const struct cx8800_fmt
*fmt
;
735 enum v4l2_field field
;
736 unsigned int maxw
, maxh
;
738 fmt
= format_by_fourcc(f
->fmt
.pix
.pixelformat
);
742 maxw
= norm_maxw(core
->tvnorm
);
743 maxh
= norm_maxh(core
->tvnorm
);
745 field
= f
->fmt
.pix
.field
;
749 case V4L2_FIELD_BOTTOM
:
750 case V4L2_FIELD_INTERLACED
:
751 case V4L2_FIELD_SEQ_BT
:
752 case V4L2_FIELD_SEQ_TB
:
755 field
= (f
->fmt
.pix
.height
> maxh
/ 2)
756 ? V4L2_FIELD_INTERLACED
760 if (V4L2_FIELD_HAS_T_OR_B(field
))
763 v4l_bound_align_image(&f
->fmt
.pix
.width
, 48, maxw
, 2,
764 &f
->fmt
.pix
.height
, 32, maxh
, 0, 0);
765 f
->fmt
.pix
.field
= field
;
766 f
->fmt
.pix
.bytesperline
=
767 (f
->fmt
.pix
.width
* fmt
->depth
) >> 3;
768 f
->fmt
.pix
.sizeimage
=
769 f
->fmt
.pix
.height
* f
->fmt
.pix
.bytesperline
;
770 f
->fmt
.pix
.colorspace
= V4L2_COLORSPACE_SMPTE170M
;
775 static int vidioc_s_fmt_vid_cap(struct file
*file
, void *priv
,
776 struct v4l2_format
*f
)
778 struct cx8800_dev
*dev
= video_drvdata(file
);
779 struct cx88_core
*core
= dev
->core
;
780 int err
= vidioc_try_fmt_vid_cap (file
,priv
,f
);
784 if (vb2_is_busy(&dev
->vb2_vidq
) || vb2_is_busy(&dev
->vb2_vbiq
))
786 if (core
->dvbdev
&& vb2_is_busy(&core
->dvbdev
->vb2_mpegq
))
788 dev
->fmt
= format_by_fourcc(f
->fmt
.pix
.pixelformat
);
789 core
->width
= f
->fmt
.pix
.width
;
790 core
->height
= f
->fmt
.pix
.height
;
791 core
->field
= f
->fmt
.pix
.field
;
795 void cx88_querycap(struct file
*file
, struct cx88_core
*core
,
796 struct v4l2_capability
*cap
)
798 struct video_device
*vdev
= video_devdata(file
);
800 strlcpy(cap
->card
, core
->board
.name
, sizeof(cap
->card
));
801 cap
->device_caps
= V4L2_CAP_READWRITE
| V4L2_CAP_STREAMING
;
802 if (UNSET
!= core
->board
.tuner_type
)
803 cap
->device_caps
|= V4L2_CAP_TUNER
;
804 switch (vdev
->vfl_type
) {
806 cap
->device_caps
= V4L2_CAP_RADIO
| V4L2_CAP_TUNER
;
808 case VFL_TYPE_GRABBER
:
809 cap
->device_caps
|= V4L2_CAP_VIDEO_CAPTURE
;
812 cap
->device_caps
|= V4L2_CAP_VBI_CAPTURE
;
815 cap
->capabilities
= cap
->device_caps
| V4L2_CAP_VIDEO_CAPTURE
|
816 V4L2_CAP_VBI_CAPTURE
| V4L2_CAP_DEVICE_CAPS
;
817 if (core
->board
.radio
.type
== CX88_RADIO
)
818 cap
->capabilities
|= V4L2_CAP_RADIO
;
820 EXPORT_SYMBOL(cx88_querycap
);
822 static int vidioc_querycap(struct file
*file
, void *priv
,
823 struct v4l2_capability
*cap
)
825 struct cx8800_dev
*dev
= video_drvdata(file
);
826 struct cx88_core
*core
= dev
->core
;
828 strcpy(cap
->driver
, "cx8800");
829 sprintf(cap
->bus_info
, "PCI:%s", pci_name(dev
->pci
));
830 cx88_querycap(file
, core
, cap
);
834 static int vidioc_enum_fmt_vid_cap (struct file
*file
, void *priv
,
835 struct v4l2_fmtdesc
*f
)
837 if (unlikely(f
->index
>= ARRAY_SIZE(formats
)))
840 strlcpy(f
->description
,formats
[f
->index
].name
,sizeof(f
->description
));
841 f
->pixelformat
= formats
[f
->index
].fourcc
;
846 static int vidioc_g_std(struct file
*file
, void *priv
, v4l2_std_id
*tvnorm
)
848 struct cx8800_dev
*dev
= video_drvdata(file
);
849 struct cx88_core
*core
= dev
->core
;
851 *tvnorm
= core
->tvnorm
;
855 static int vidioc_s_std(struct file
*file
, void *priv
, v4l2_std_id tvnorms
)
857 struct cx8800_dev
*dev
= video_drvdata(file
);
858 struct cx88_core
*core
= dev
->core
;
860 return cx88_set_tvnorm(core
, tvnorms
);
863 /* only one input in this sample driver */
864 int cx88_enum_input (struct cx88_core
*core
,struct v4l2_input
*i
)
866 static const char * const iname
[] = {
867 [ CX88_VMUX_COMPOSITE1
] = "Composite1",
868 [ CX88_VMUX_COMPOSITE2
] = "Composite2",
869 [ CX88_VMUX_COMPOSITE3
] = "Composite3",
870 [ CX88_VMUX_COMPOSITE4
] = "Composite4",
871 [ CX88_VMUX_SVIDEO
] = "S-Video",
872 [ CX88_VMUX_TELEVISION
] = "Television",
873 [ CX88_VMUX_CABLE
] = "Cable TV",
874 [ CX88_VMUX_DVB
] = "DVB",
875 [ CX88_VMUX_DEBUG
] = "for debug only",
877 unsigned int n
= i
->index
;
881 if (0 == INPUT(n
).type
)
883 i
->type
= V4L2_INPUT_TYPE_CAMERA
;
884 strcpy(i
->name
,iname
[INPUT(n
).type
]);
885 if ((CX88_VMUX_TELEVISION
== INPUT(n
).type
) ||
886 (CX88_VMUX_CABLE
== INPUT(n
).type
)) {
887 i
->type
= V4L2_INPUT_TYPE_TUNER
;
892 EXPORT_SYMBOL(cx88_enum_input
);
894 static int vidioc_enum_input (struct file
*file
, void *priv
,
895 struct v4l2_input
*i
)
897 struct cx8800_dev
*dev
= video_drvdata(file
);
898 struct cx88_core
*core
= dev
->core
;
899 return cx88_enum_input (core
,i
);
902 static int vidioc_g_input (struct file
*file
, void *priv
, unsigned int *i
)
904 struct cx8800_dev
*dev
= video_drvdata(file
);
905 struct cx88_core
*core
= dev
->core
;
911 static int vidioc_s_input (struct file
*file
, void *priv
, unsigned int i
)
913 struct cx8800_dev
*dev
= video_drvdata(file
);
914 struct cx88_core
*core
= dev
->core
;
918 if (0 == INPUT(i
).type
)
921 cx88_newstation(core
);
922 cx88_video_mux(core
,i
);
926 static int vidioc_g_tuner (struct file
*file
, void *priv
,
927 struct v4l2_tuner
*t
)
929 struct cx8800_dev
*dev
= video_drvdata(file
);
930 struct cx88_core
*core
= dev
->core
;
933 if (unlikely(UNSET
== core
->board
.tuner_type
))
938 strcpy(t
->name
, "Television");
939 t
->capability
= V4L2_TUNER_CAP_NORM
;
940 t
->rangehigh
= 0xffffffffUL
;
941 call_all(core
, tuner
, g_tuner
, t
);
943 cx88_get_stereo(core
,t
);
944 reg
= cx_read(MO_DEVICE_STATUS
);
945 t
->signal
= (reg
& (1<<5)) ? 0xffff : 0x0000;
949 static int vidioc_s_tuner (struct file
*file
, void *priv
,
950 const struct v4l2_tuner
*t
)
952 struct cx8800_dev
*dev
= video_drvdata(file
);
953 struct cx88_core
*core
= dev
->core
;
955 if (UNSET
== core
->board
.tuner_type
)
960 cx88_set_stereo(core
, t
->audmode
, 1);
964 static int vidioc_g_frequency (struct file
*file
, void *priv
,
965 struct v4l2_frequency
*f
)
967 struct cx8800_dev
*dev
= video_drvdata(file
);
968 struct cx88_core
*core
= dev
->core
;
970 if (unlikely(UNSET
== core
->board
.tuner_type
))
975 f
->frequency
= core
->freq
;
977 call_all(core
, tuner
, g_frequency
, f
);
982 int cx88_set_freq (struct cx88_core
*core
,
983 const struct v4l2_frequency
*f
)
985 struct v4l2_frequency new_freq
= *f
;
987 if (unlikely(UNSET
== core
->board
.tuner_type
))
989 if (unlikely(f
->tuner
!= 0))
992 cx88_newstation(core
);
993 call_all(core
, tuner
, s_frequency
, f
);
994 call_all(core
, tuner
, g_frequency
, &new_freq
);
995 core
->freq
= new_freq
.frequency
;
997 /* When changing channels it is required to reset TVAUDIO */
999 cx88_set_tvaudio(core
);
1003 EXPORT_SYMBOL(cx88_set_freq
);
1005 static int vidioc_s_frequency (struct file
*file
, void *priv
,
1006 const struct v4l2_frequency
*f
)
1008 struct cx8800_dev
*dev
= video_drvdata(file
);
1009 struct cx88_core
*core
= dev
->core
;
1011 return cx88_set_freq(core
, f
);
1014 #ifdef CONFIG_VIDEO_ADV_DEBUG
1015 static int vidioc_g_register (struct file
*file
, void *fh
,
1016 struct v4l2_dbg_register
*reg
)
1018 struct cx8800_dev
*dev
= video_drvdata(file
);
1019 struct cx88_core
*core
= dev
->core
;
1021 /* cx2388x has a 24-bit register space */
1022 reg
->val
= cx_read(reg
->reg
& 0xfffffc);
1027 static int vidioc_s_register (struct file
*file
, void *fh
,
1028 const struct v4l2_dbg_register
*reg
)
1030 struct cx8800_dev
*dev
= video_drvdata(file
);
1031 struct cx88_core
*core
= dev
->core
;
1033 cx_write(reg
->reg
& 0xfffffc, reg
->val
);
1038 /* ----------------------------------------------------------- */
1039 /* RADIO ESPECIFIC IOCTLS */
1040 /* ----------------------------------------------------------- */
1042 static int radio_g_tuner (struct file
*file
, void *priv
,
1043 struct v4l2_tuner
*t
)
1045 struct cx8800_dev
*dev
= video_drvdata(file
);
1046 struct cx88_core
*core
= dev
->core
;
1048 if (unlikely(t
->index
> 0))
1051 strcpy(t
->name
, "Radio");
1053 call_all(core
, tuner
, g_tuner
, t
);
1057 static int radio_s_tuner (struct file
*file
, void *priv
,
1058 const struct v4l2_tuner
*t
)
1060 struct cx8800_dev
*dev
= video_drvdata(file
);
1061 struct cx88_core
*core
= dev
->core
;
1066 call_all(core
, tuner
, s_tuner
, t
);
1070 /* ----------------------------------------------------------- */
1072 static const char *cx88_vid_irqs
[32] = {
1073 "y_risci1", "u_risci1", "v_risci1", "vbi_risc1",
1074 "y_risci2", "u_risci2", "v_risci2", "vbi_risc2",
1075 "y_oflow", "u_oflow", "v_oflow", "vbi_oflow",
1076 "y_sync", "u_sync", "v_sync", "vbi_sync",
1077 "opc_err", "par_err", "rip_err", "pci_abort",
1080 static void cx8800_vid_irq(struct cx8800_dev
*dev
)
1082 struct cx88_core
*core
= dev
->core
;
1083 u32 status
, mask
, count
;
1085 status
= cx_read(MO_VID_INTSTAT
);
1086 mask
= cx_read(MO_VID_INTMSK
);
1087 if (0 == (status
& mask
))
1089 cx_write(MO_VID_INTSTAT
, status
);
1090 if (irq_debug
|| (status
& mask
& ~0xff))
1091 cx88_print_irqbits(core
->name
, "irq vid",
1092 cx88_vid_irqs
, ARRAY_SIZE(cx88_vid_irqs
),
1095 /* risc op code error */
1096 if (status
& (1 << 16)) {
1097 printk(KERN_WARNING
"%s/0: video risc op code error\n",core
->name
);
1098 cx_clear(MO_VID_DMACNTRL
, 0x11);
1099 cx_clear(VID_CAPTURE_CONTROL
, 0x06);
1100 cx88_sram_channel_dump(core
, &cx88_sram_channels
[SRAM_CH21
]);
1104 if (status
& 0x01) {
1105 spin_lock(&dev
->slock
);
1106 count
= cx_read(MO_VIDY_GPCNT
);
1107 cx88_wakeup(core
, &dev
->vidq
, count
);
1108 spin_unlock(&dev
->slock
);
1112 if (status
& 0x08) {
1113 spin_lock(&dev
->slock
);
1114 count
= cx_read(MO_VBI_GPCNT
);
1115 cx88_wakeup(core
, &dev
->vbiq
, count
);
1116 spin_unlock(&dev
->slock
);
1120 static irqreturn_t
cx8800_irq(int irq
, void *dev_id
)
1122 struct cx8800_dev
*dev
= dev_id
;
1123 struct cx88_core
*core
= dev
->core
;
1125 int loop
, handled
= 0;
1127 for (loop
= 0; loop
< 10; loop
++) {
1128 status
= cx_read(MO_PCI_INTSTAT
) &
1129 (core
->pci_irqmask
| PCI_INT_VIDINT
);
1132 cx_write(MO_PCI_INTSTAT
, status
);
1135 if (status
& core
->pci_irqmask
)
1136 cx88_core_irq(core
,status
);
1137 if (status
& PCI_INT_VIDINT
)
1138 cx8800_vid_irq(dev
);
1141 printk(KERN_WARNING
"%s/0: irq loop -- clearing mask\n",
1143 cx_write(MO_PCI_INTMSK
,0);
1147 return IRQ_RETVAL(handled
);
1150 /* ----------------------------------------------------------- */
1151 /* exported stuff */
1153 static const struct v4l2_file_operations video_fops
=
1155 .owner
= THIS_MODULE
,
1156 .open
= v4l2_fh_open
,
1157 .release
= vb2_fop_release
,
1158 .read
= vb2_fop_read
,
1159 .poll
= vb2_fop_poll
,
1160 .mmap
= vb2_fop_mmap
,
1161 .unlocked_ioctl
= video_ioctl2
,
1164 static const struct v4l2_ioctl_ops video_ioctl_ops
= {
1165 .vidioc_querycap
= vidioc_querycap
,
1166 .vidioc_enum_fmt_vid_cap
= vidioc_enum_fmt_vid_cap
,
1167 .vidioc_g_fmt_vid_cap
= vidioc_g_fmt_vid_cap
,
1168 .vidioc_try_fmt_vid_cap
= vidioc_try_fmt_vid_cap
,
1169 .vidioc_s_fmt_vid_cap
= vidioc_s_fmt_vid_cap
,
1170 .vidioc_reqbufs
= vb2_ioctl_reqbufs
,
1171 .vidioc_querybuf
= vb2_ioctl_querybuf
,
1172 .vidioc_qbuf
= vb2_ioctl_qbuf
,
1173 .vidioc_dqbuf
= vb2_ioctl_dqbuf
,
1174 .vidioc_g_std
= vidioc_g_std
,
1175 .vidioc_s_std
= vidioc_s_std
,
1176 .vidioc_enum_input
= vidioc_enum_input
,
1177 .vidioc_g_input
= vidioc_g_input
,
1178 .vidioc_s_input
= vidioc_s_input
,
1179 .vidioc_streamon
= vb2_ioctl_streamon
,
1180 .vidioc_streamoff
= vb2_ioctl_streamoff
,
1181 .vidioc_g_tuner
= vidioc_g_tuner
,
1182 .vidioc_s_tuner
= vidioc_s_tuner
,
1183 .vidioc_g_frequency
= vidioc_g_frequency
,
1184 .vidioc_s_frequency
= vidioc_s_frequency
,
1185 .vidioc_subscribe_event
= v4l2_ctrl_subscribe_event
,
1186 .vidioc_unsubscribe_event
= v4l2_event_unsubscribe
,
1187 #ifdef CONFIG_VIDEO_ADV_DEBUG
1188 .vidioc_g_register
= vidioc_g_register
,
1189 .vidioc_s_register
= vidioc_s_register
,
1193 static const struct video_device cx8800_video_template
= {
1194 .name
= "cx8800-video",
1195 .fops
= &video_fops
,
1196 .ioctl_ops
= &video_ioctl_ops
,
1197 .tvnorms
= CX88_NORMS
,
1200 static const struct v4l2_ioctl_ops vbi_ioctl_ops
= {
1201 .vidioc_querycap
= vidioc_querycap
,
1202 .vidioc_g_fmt_vbi_cap
= cx8800_vbi_fmt
,
1203 .vidioc_try_fmt_vbi_cap
= cx8800_vbi_fmt
,
1204 .vidioc_s_fmt_vbi_cap
= cx8800_vbi_fmt
,
1205 .vidioc_reqbufs
= vb2_ioctl_reqbufs
,
1206 .vidioc_querybuf
= vb2_ioctl_querybuf
,
1207 .vidioc_qbuf
= vb2_ioctl_qbuf
,
1208 .vidioc_dqbuf
= vb2_ioctl_dqbuf
,
1209 .vidioc_g_std
= vidioc_g_std
,
1210 .vidioc_s_std
= vidioc_s_std
,
1211 .vidioc_enum_input
= vidioc_enum_input
,
1212 .vidioc_g_input
= vidioc_g_input
,
1213 .vidioc_s_input
= vidioc_s_input
,
1214 .vidioc_streamon
= vb2_ioctl_streamon
,
1215 .vidioc_streamoff
= vb2_ioctl_streamoff
,
1216 .vidioc_g_tuner
= vidioc_g_tuner
,
1217 .vidioc_s_tuner
= vidioc_s_tuner
,
1218 .vidioc_g_frequency
= vidioc_g_frequency
,
1219 .vidioc_s_frequency
= vidioc_s_frequency
,
1220 #ifdef CONFIG_VIDEO_ADV_DEBUG
1221 .vidioc_g_register
= vidioc_g_register
,
1222 .vidioc_s_register
= vidioc_s_register
,
1226 static const struct video_device cx8800_vbi_template
= {
1227 .name
= "cx8800-vbi",
1228 .fops
= &video_fops
,
1229 .ioctl_ops
= &vbi_ioctl_ops
,
1230 .tvnorms
= CX88_NORMS
,
1233 static const struct v4l2_file_operations radio_fops
=
1235 .owner
= THIS_MODULE
,
1237 .poll
= v4l2_ctrl_poll
,
1238 .release
= v4l2_fh_release
,
1239 .unlocked_ioctl
= video_ioctl2
,
1242 static const struct v4l2_ioctl_ops radio_ioctl_ops
= {
1243 .vidioc_querycap
= vidioc_querycap
,
1244 .vidioc_g_tuner
= radio_g_tuner
,
1245 .vidioc_s_tuner
= radio_s_tuner
,
1246 .vidioc_g_frequency
= vidioc_g_frequency
,
1247 .vidioc_s_frequency
= vidioc_s_frequency
,
1248 .vidioc_subscribe_event
= v4l2_ctrl_subscribe_event
,
1249 .vidioc_unsubscribe_event
= v4l2_event_unsubscribe
,
1250 #ifdef CONFIG_VIDEO_ADV_DEBUG
1251 .vidioc_g_register
= vidioc_g_register
,
1252 .vidioc_s_register
= vidioc_s_register
,
1256 static const struct video_device cx8800_radio_template
= {
1257 .name
= "cx8800-radio",
1258 .fops
= &radio_fops
,
1259 .ioctl_ops
= &radio_ioctl_ops
,
1262 static const struct v4l2_ctrl_ops cx8800_ctrl_vid_ops
= {
1263 .s_ctrl
= cx8800_s_vid_ctrl
,
1266 static const struct v4l2_ctrl_ops cx8800_ctrl_aud_ops
= {
1267 .s_ctrl
= cx8800_s_aud_ctrl
,
1270 /* ----------------------------------------------------------- */
1272 static void cx8800_unregister_video(struct cx8800_dev
*dev
)
1274 video_unregister_device(&dev
->radio_dev
);
1275 video_unregister_device(&dev
->vbi_dev
);
1276 video_unregister_device(&dev
->video_dev
);
1279 static int cx8800_initdev(struct pci_dev
*pci_dev
,
1280 const struct pci_device_id
*pci_id
)
1282 struct cx8800_dev
*dev
;
1283 struct cx88_core
*core
;
1284 struct vb2_queue
*q
;
1288 dev
= kzalloc(sizeof(*dev
),GFP_KERNEL
);
1294 if (pci_enable_device(pci_dev
)) {
1298 core
= cx88_core_get(dev
->pci
);
1305 /* print pci info */
1306 dev
->pci_rev
= pci_dev
->revision
;
1307 pci_read_config_byte(pci_dev
, PCI_LATENCY_TIMER
, &dev
->pci_lat
);
1308 printk(KERN_INFO
"%s/0: found at %s, rev: %d, irq: %d, "
1309 "latency: %d, mmio: 0x%llx\n", core
->name
,
1310 pci_name(pci_dev
), dev
->pci_rev
, pci_dev
->irq
,
1311 dev
->pci_lat
,(unsigned long long)pci_resource_start(pci_dev
,0));
1313 pci_set_master(pci_dev
);
1314 if (!pci_dma_supported(pci_dev
,DMA_BIT_MASK(32))) {
1315 printk("%s/0: Oops: no 32bit PCI DMA ???\n",core
->name
);
1319 dev
->alloc_ctx
= vb2_dma_sg_init_ctx(&pci_dev
->dev
);
1320 if (IS_ERR(dev
->alloc_ctx
)) {
1321 err
= PTR_ERR(dev
->alloc_ctx
);
1326 /* initialize driver struct */
1327 spin_lock_init(&dev
->slock
);
1329 /* init video dma queues */
1330 INIT_LIST_HEAD(&dev
->vidq
.active
);
1332 /* init vbi dma queues */
1333 INIT_LIST_HEAD(&dev
->vbiq
.active
);
1336 err
= request_irq(pci_dev
->irq
, cx8800_irq
,
1337 IRQF_SHARED
, core
->name
, dev
);
1339 printk(KERN_ERR
"%s/0: can't get IRQ %d\n",
1340 core
->name
,pci_dev
->irq
);
1343 cx_set(MO_PCI_INTMSK
, core
->pci_irqmask
);
1345 for (i
= 0; i
< CX8800_AUD_CTLS
; i
++) {
1346 const struct cx88_ctrl
*cc
= &cx8800_aud_ctls
[i
];
1347 struct v4l2_ctrl
*vc
;
1349 vc
= v4l2_ctrl_new_std(&core
->audio_hdl
, &cx8800_ctrl_aud_ops
,
1350 cc
->id
, cc
->minimum
, cc
->maximum
, cc
->step
, cc
->default_value
);
1352 err
= core
->audio_hdl
.error
;
1355 vc
->priv
= (void *)cc
;
1358 for (i
= 0; i
< CX8800_VID_CTLS
; i
++) {
1359 const struct cx88_ctrl
*cc
= &cx8800_vid_ctls
[i
];
1360 struct v4l2_ctrl
*vc
;
1362 vc
= v4l2_ctrl_new_std(&core
->video_hdl
, &cx8800_ctrl_vid_ops
,
1363 cc
->id
, cc
->minimum
, cc
->maximum
, cc
->step
, cc
->default_value
);
1365 err
= core
->video_hdl
.error
;
1368 vc
->priv
= (void *)cc
;
1369 if (vc
->id
== V4L2_CID_CHROMA_AGC
)
1370 core
->chroma_agc
= vc
;
1372 v4l2_ctrl_add_handler(&core
->video_hdl
, &core
->audio_hdl
, NULL
);
1374 /* load and configure helper modules */
1376 if (core
->board
.audio_chip
== CX88_AUDIO_WM8775
) {
1377 struct i2c_board_info wm8775_info
= {
1380 .platform_data
= &core
->wm8775_data
,
1382 struct v4l2_subdev
*sd
;
1384 if (core
->boardnr
== CX88_BOARD_HAUPPAUGE_NOVASPLUS_S1
)
1385 core
->wm8775_data
.is_nova_s
= true;
1387 core
->wm8775_data
.is_nova_s
= false;
1389 sd
= v4l2_i2c_new_subdev_board(&core
->v4l2_dev
, &core
->i2c_adap
,
1390 &wm8775_info
, NULL
);
1392 core
->sd_wm8775
= sd
;
1393 sd
->grp_id
= WM8775_GID
;
1397 if (core
->board
.audio_chip
== CX88_AUDIO_TVAUDIO
) {
1398 /* This probes for a tda9874 as is used on some
1399 Pixelview Ultra boards. */
1400 v4l2_i2c_new_subdev(&core
->v4l2_dev
, &core
->i2c_adap
,
1401 "tvaudio", 0, I2C_ADDRS(0xb0 >> 1));
1404 switch (core
->boardnr
) {
1405 case CX88_BOARD_DVICO_FUSIONHDTV_5_GOLD
:
1406 case CX88_BOARD_DVICO_FUSIONHDTV_7_GOLD
: {
1407 static const struct i2c_board_info rtc_info
= {
1408 I2C_BOARD_INFO("isl1208", 0x6f)
1411 request_module("rtc-isl1208");
1412 core
->i2c_rtc
= i2c_new_device(&core
->i2c_adap
, &rtc_info
);
1414 /* break intentionally omitted */
1415 case CX88_BOARD_DVICO_FUSIONHDTV_5_PCI_NANO
:
1416 request_module("ir-kbd-i2c");
1419 /* Sets device info at pci_dev */
1420 pci_set_drvdata(pci_dev
, dev
);
1422 dev
->fmt
= format_by_fourcc(V4L2_PIX_FMT_BGR24
);
1424 /* Maintain a reference so cx88-blackbird can query the 8800 device. */
1427 /* initial device configuration */
1428 mutex_lock(&core
->lock
);
1429 cx88_set_tvnorm(core
, core
->tvnorm
);
1430 v4l2_ctrl_handler_setup(&core
->video_hdl
);
1431 v4l2_ctrl_handler_setup(&core
->audio_hdl
);
1432 cx88_video_mux(core
, 0);
1435 q
->type
= V4L2_BUF_TYPE_VIDEO_CAPTURE
;
1436 q
->io_modes
= VB2_MMAP
| VB2_USERPTR
| VB2_DMABUF
| VB2_READ
;
1437 q
->gfp_flags
= GFP_DMA32
;
1438 q
->min_buffers_needed
= 2;
1440 q
->buf_struct_size
= sizeof(struct cx88_buffer
);
1441 q
->ops
= &cx8800_video_qops
;
1442 q
->mem_ops
= &vb2_dma_sg_memops
;
1443 q
->timestamp_flags
= V4L2_BUF_FLAG_TIMESTAMP_MONOTONIC
;
1444 q
->lock
= &core
->lock
;
1446 err
= vb2_queue_init(q
);
1451 q
->type
= V4L2_BUF_TYPE_VBI_CAPTURE
;
1452 q
->io_modes
= VB2_MMAP
| VB2_USERPTR
| VB2_DMABUF
| VB2_READ
;
1453 q
->gfp_flags
= GFP_DMA32
;
1454 q
->min_buffers_needed
= 2;
1456 q
->buf_struct_size
= sizeof(struct cx88_buffer
);
1457 q
->ops
= &cx8800_vbi_qops
;
1458 q
->mem_ops
= &vb2_dma_sg_memops
;
1459 q
->timestamp_flags
= V4L2_BUF_FLAG_TIMESTAMP_MONOTONIC
;
1460 q
->lock
= &core
->lock
;
1462 err
= vb2_queue_init(q
);
1466 /* register v4l devices */
1467 cx88_vdev_init(core
, dev
->pci
, &dev
->video_dev
,
1468 &cx8800_video_template
, "video");
1469 video_set_drvdata(&dev
->video_dev
, dev
);
1470 dev
->video_dev
.ctrl_handler
= &core
->video_hdl
;
1471 dev
->video_dev
.queue
= &dev
->vb2_vidq
;
1472 err
= video_register_device(&dev
->video_dev
, VFL_TYPE_GRABBER
,
1473 video_nr
[core
->nr
]);
1475 printk(KERN_ERR
"%s/0: can't register video device\n",
1479 printk(KERN_INFO
"%s/0: registered device %s [v4l2]\n",
1480 core
->name
, video_device_node_name(&dev
->video_dev
));
1482 cx88_vdev_init(core
, dev
->pci
, &dev
->vbi_dev
,
1483 &cx8800_vbi_template
, "vbi");
1484 video_set_drvdata(&dev
->vbi_dev
, dev
);
1485 dev
->vbi_dev
.queue
= &dev
->vb2_vbiq
;
1486 err
= video_register_device(&dev
->vbi_dev
, VFL_TYPE_VBI
,
1489 printk(KERN_ERR
"%s/0: can't register vbi device\n",
1493 printk(KERN_INFO
"%s/0: registered device %s\n",
1494 core
->name
, video_device_node_name(&dev
->vbi_dev
));
1496 if (core
->board
.radio
.type
== CX88_RADIO
) {
1497 cx88_vdev_init(core
, dev
->pci
, &dev
->radio_dev
,
1498 &cx8800_radio_template
, "radio");
1499 video_set_drvdata(&dev
->radio_dev
, dev
);
1500 dev
->radio_dev
.ctrl_handler
= &core
->audio_hdl
;
1501 err
= video_register_device(&dev
->radio_dev
, VFL_TYPE_RADIO
,
1502 radio_nr
[core
->nr
]);
1504 printk(KERN_ERR
"%s/0: can't register radio device\n",
1508 printk(KERN_INFO
"%s/0: registered device %s\n",
1509 core
->name
, video_device_node_name(&dev
->radio_dev
));
1512 /* start tvaudio thread */
1513 if (core
->board
.tuner_type
!= UNSET
) {
1514 core
->kthread
= kthread_run(cx88_audio_thread
, core
, "cx88 tvaudio");
1515 if (IS_ERR(core
->kthread
)) {
1516 err
= PTR_ERR(core
->kthread
);
1517 printk(KERN_ERR
"%s/0: failed to create cx88 audio thread, err=%d\n",
1521 mutex_unlock(&core
->lock
);
1526 cx8800_unregister_video(dev
);
1527 free_irq(pci_dev
->irq
, dev
);
1528 mutex_unlock(&core
->lock
);
1530 vb2_dma_sg_cleanup_ctx(dev
->alloc_ctx
);
1531 core
->v4ldev
= NULL
;
1532 cx88_core_put(core
,dev
->pci
);
1538 static void cx8800_finidev(struct pci_dev
*pci_dev
)
1540 struct cx8800_dev
*dev
= pci_get_drvdata(pci_dev
);
1541 struct cx88_core
*core
= dev
->core
;
1544 if (core
->kthread
) {
1545 kthread_stop(core
->kthread
);
1546 core
->kthread
= NULL
;
1552 cx88_shutdown(core
); /* FIXME */
1554 /* unregister stuff */
1556 free_irq(pci_dev
->irq
, dev
);
1557 cx8800_unregister_video(dev
);
1558 pci_disable_device(pci_dev
);
1560 core
->v4ldev
= NULL
;
1563 cx88_core_put(core
,dev
->pci
);
1564 vb2_dma_sg_cleanup_ctx(dev
->alloc_ctx
);
1569 static int cx8800_suspend(struct pci_dev
*pci_dev
, pm_message_t state
)
1571 struct cx8800_dev
*dev
= pci_get_drvdata(pci_dev
);
1572 struct cx88_core
*core
= dev
->core
;
1573 unsigned long flags
;
1575 /* stop video+vbi capture */
1576 spin_lock_irqsave(&dev
->slock
, flags
);
1577 if (!list_empty(&dev
->vidq
.active
)) {
1578 printk("%s/0: suspend video\n", core
->name
);
1579 stop_video_dma(dev
);
1581 if (!list_empty(&dev
->vbiq
.active
)) {
1582 printk("%s/0: suspend vbi\n", core
->name
);
1583 cx8800_stop_vbi_dma(dev
);
1585 spin_unlock_irqrestore(&dev
->slock
, flags
);
1589 /* FIXME -- shutdown device */
1590 cx88_shutdown(core
);
1592 pci_save_state(pci_dev
);
1593 if (0 != pci_set_power_state(pci_dev
, pci_choose_state(pci_dev
, state
))) {
1594 pci_disable_device(pci_dev
);
1595 dev
->state
.disabled
= 1;
1600 static int cx8800_resume(struct pci_dev
*pci_dev
)
1602 struct cx8800_dev
*dev
= pci_get_drvdata(pci_dev
);
1603 struct cx88_core
*core
= dev
->core
;
1604 unsigned long flags
;
1607 if (dev
->state
.disabled
) {
1608 err
=pci_enable_device(pci_dev
);
1610 printk(KERN_ERR
"%s/0: can't enable device\n",
1615 dev
->state
.disabled
= 0;
1617 err
= pci_set_power_state(pci_dev
, PCI_D0
);
1619 printk(KERN_ERR
"%s/0: can't set power state\n", core
->name
);
1620 pci_disable_device(pci_dev
);
1621 dev
->state
.disabled
= 1;
1625 pci_restore_state(pci_dev
);
1627 /* FIXME: re-initialize hardware */
1630 cx88_ir_start(core
);
1632 cx_set(MO_PCI_INTMSK
, core
->pci_irqmask
);
1634 /* restart video+vbi capture */
1635 spin_lock_irqsave(&dev
->slock
, flags
);
1636 if (!list_empty(&dev
->vidq
.active
)) {
1637 printk("%s/0: resume video\n", core
->name
);
1638 restart_video_queue(dev
,&dev
->vidq
);
1640 if (!list_empty(&dev
->vbiq
.active
)) {
1641 printk("%s/0: resume vbi\n", core
->name
);
1642 cx8800_restart_vbi_queue(dev
,&dev
->vbiq
);
1644 spin_unlock_irqrestore(&dev
->slock
, flags
);
1650 /* ----------------------------------------------------------- */
1652 static const struct pci_device_id cx8800_pci_tbl
[] = {
1656 .subvendor
= PCI_ANY_ID
,
1657 .subdevice
= PCI_ANY_ID
,
1659 /* --- end of list --- */
1662 MODULE_DEVICE_TABLE(pci
, cx8800_pci_tbl
);
1664 static struct pci_driver cx8800_pci_driver
= {
1666 .id_table
= cx8800_pci_tbl
,
1667 .probe
= cx8800_initdev
,
1668 .remove
= cx8800_finidev
,
1670 .suspend
= cx8800_suspend
,
1671 .resume
= cx8800_resume
,
1675 module_pci_driver(cx8800_pci_driver
);