2 cx231xx-video.c - driver for Conexant Cx23100/101/102
3 USB video capture devices
5 Copyright (C) 2008 <srinivasa.deevi at conexant dot com>
7 Based on cx23885 driver
10 This program is free software; you can redistribute it and/or modify
11 it under the terms of the GNU General Public License as published by
12 the Free Software Foundation; either version 2 of the License, or
13 (at your option) any later version.
15 This program is distributed in the hope that it will be useful,
16 but WITHOUT ANY WARRANTY; without even the implied warranty of
17 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 GNU General Public License for more details.
20 You should have received a copy of the GNU General Public License
21 along with this program; if not, write to the Free Software
22 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
25 #include <linux/init.h>
26 #include <linux/list.h>
27 #include <linux/module.h>
28 #include <linux/kernel.h>
29 #include <linux/bitmap.h>
30 #include <linux/usb.h>
31 #include <linux/i2c.h>
32 #include <linux/version.h>
34 #include <linux/mutex.h>
36 #include <media/v4l2-common.h>
37 #include <media/v4l2-ioctl.h>
38 #include <media/v4l2-chip-ident.h>
39 #include <media/msp3400.h>
40 #include <media/tuner.h>
42 #include "dvb_frontend.h"
45 #include "cx231xx-vbi.h"
47 #define CX231XX_VERSION_CODE KERNEL_VERSION(0, 0, 1)
49 #define DRIVER_AUTHOR "Srinivasa Deevi <srinivasa.deevi@conexant.com>"
50 #define DRIVER_DESC "Conexant cx231xx based USB video device driver"
52 #define cx231xx_videodbg(fmt, arg...) do {\
54 printk(KERN_INFO "%s %s :"fmt, \
55 dev->name, __func__ , ##arg); } while (0)
57 static unsigned int isoc_debug
;
58 module_param(isoc_debug
, int, 0644);
59 MODULE_PARM_DESC(isoc_debug
, "enable debug messages [isoc transfers]");
61 #define cx231xx_isocdbg(fmt, arg...) \
64 printk(KERN_INFO "%s %s :"fmt, \
65 dev->name, __func__ , ##arg); \
69 MODULE_AUTHOR(DRIVER_AUTHOR
);
70 MODULE_DESCRIPTION(DRIVER_DESC
);
71 MODULE_LICENSE("GPL");
73 static unsigned int card
[] = {[0 ... (CX231XX_MAXBOARDS
- 1)] = UNSET
};
74 static unsigned int video_nr
[] = {[0 ... (CX231XX_MAXBOARDS
- 1)] = UNSET
};
75 static unsigned int vbi_nr
[] = {[0 ... (CX231XX_MAXBOARDS
- 1)] = UNSET
};
76 static unsigned int radio_nr
[] = {[0 ... (CX231XX_MAXBOARDS
- 1)] = UNSET
};
78 module_param_array(card
, int, NULL
, 0444);
79 module_param_array(video_nr
, int, NULL
, 0444);
80 module_param_array(vbi_nr
, int, NULL
, 0444);
81 module_param_array(radio_nr
, int, NULL
, 0444);
83 MODULE_PARM_DESC(card
, "card type");
84 MODULE_PARM_DESC(video_nr
, "video device numbers");
85 MODULE_PARM_DESC(vbi_nr
, "vbi device numbers");
86 MODULE_PARM_DESC(radio_nr
, "radio device numbers");
88 static unsigned int video_debug
;
89 module_param(video_debug
, int, 0644);
90 MODULE_PARM_DESC(video_debug
, "enable debug messages [video]");
92 /* supported video standards */
93 static struct cx231xx_fmt format
[] = {
95 .name
= "16bpp YUY2, 4:2:2, packed",
96 .fourcc
= V4L2_PIX_FMT_YUYV
,
102 /* supported controls */
103 /* Common to all boards */
105 /* ------------------------------------------------------------------- */
107 static const struct v4l2_queryctrl no_ctl
= {
109 .flags
= V4L2_CTRL_FLAG_DISABLED
,
112 static struct cx231xx_ctrl cx231xx_ctls
[] = {
116 .id
= V4L2_CID_BRIGHTNESS
,
117 .name
= "Brightness",
121 .default_value
= 0x7f,
122 .type
= V4L2_CTRL_TYPE_INTEGER
,
130 .id
= V4L2_CID_CONTRAST
,
135 .default_value
= 0x3f,
136 .type
= V4L2_CTRL_TYPE_INTEGER
,
149 .default_value
= 0x7f,
150 .type
= V4L2_CTRL_TYPE_INTEGER
,
157 /* strictly, this only describes only U saturation.
158 * V saturation is handled specially through code.
161 .id
= V4L2_CID_SATURATION
,
162 .name
= "Saturation",
166 .default_value
= 0x7f,
167 .type
= V4L2_CTRL_TYPE_INTEGER
,
176 .id
= V4L2_CID_AUDIO_MUTE
,
181 .type
= V4L2_CTRL_TYPE_BOOLEAN
,
184 .mask
= (0x1f << 24),
188 .id
= V4L2_CID_AUDIO_VOLUME
,
193 .default_value
= 0x3f,
194 .type
= V4L2_CTRL_TYPE_INTEGER
,
196 .reg
= PATH1_VOL_CTL
,
201 static const int CX231XX_CTLS
= ARRAY_SIZE(cx231xx_ctls
);
203 static const u32 cx231xx_user_ctrls
[] = {
209 V4L2_CID_AUDIO_VOLUME
,
211 V4L2_CID_AUDIO_BALANCE
,
217 static const u32
*ctrl_classes
[] = {
222 /* ------------------------------------------------------------------
223 Video buffer and parser functions
224 ------------------------------------------------------------------*/
227 * Announces that a buffer were filled and request the next
229 static inline void buffer_filled(struct cx231xx
*dev
,
230 struct cx231xx_dmaqueue
*dma_q
,
231 struct cx231xx_buffer
*buf
)
233 /* Advice that buffer was filled */
234 cx231xx_isocdbg("[%p/%d] wakeup\n", buf
, buf
->vb
.i
);
235 buf
->vb
.state
= VIDEOBUF_DONE
;
236 buf
->vb
.field_count
++;
237 do_gettimeofday(&buf
->vb
.ts
);
239 dev
->video_mode
.isoc_ctl
.buf
= NULL
;
241 list_del(&buf
->vb
.queue
);
242 wake_up(&buf
->vb
.done
);
245 static inline void print_err_status(struct cx231xx
*dev
, int packet
, int status
)
247 char *errmsg
= "Unknown";
251 errmsg
= "unlinked synchronuously";
254 errmsg
= "unlinked asynchronuously";
257 errmsg
= "Buffer error (overrun)";
260 errmsg
= "Stalled (device not responding)";
263 errmsg
= "Babble (bad cable?)";
266 errmsg
= "Bit-stuff error (bad cable?)";
269 errmsg
= "CRC/Timeout (could be anything)";
272 errmsg
= "Device does not respond";
276 cx231xx_isocdbg("URB status %d [%s].\n", status
, errmsg
);
278 cx231xx_isocdbg("URB packet %d, status %d [%s].\n",
279 packet
, status
, errmsg
);
284 * video-buf generic routine to get the next available buffer
286 static inline void get_next_buf(struct cx231xx_dmaqueue
*dma_q
,
287 struct cx231xx_buffer
**buf
)
289 struct cx231xx_video_mode
*vmode
=
290 container_of(dma_q
, struct cx231xx_video_mode
, vidq
);
291 struct cx231xx
*dev
= container_of(vmode
, struct cx231xx
, video_mode
);
295 if (list_empty(&dma_q
->active
)) {
296 cx231xx_isocdbg("No active queue to serve\n");
297 dev
->video_mode
.isoc_ctl
.buf
= NULL
;
302 /* Get the next buffer */
303 *buf
= list_entry(dma_q
->active
.next
, struct cx231xx_buffer
, vb
.queue
);
305 /* Cleans up buffer - Usefull for testing for frame/URB loss */
306 outp
= videobuf_to_vmalloc(&(*buf
)->vb
);
307 memset(outp
, 0, (*buf
)->vb
.size
);
309 dev
->video_mode
.isoc_ctl
.buf
= *buf
;
315 * Controls the isoc copy of each urb packet
317 static inline int cx231xx_isoc_copy(struct cx231xx
*dev
, struct urb
*urb
)
319 struct cx231xx_buffer
*buf
;
320 struct cx231xx_dmaqueue
*dma_q
= urb
->context
;
321 unsigned char *outp
= NULL
;
323 unsigned char *p_buffer
;
324 u32 bytes_parsed
= 0, buffer_size
= 0;
330 if ((dev
->state
& DEV_DISCONNECTED
) || (dev
->state
& DEV_MISCONFIGURED
))
333 if (urb
->status
< 0) {
334 print_err_status(dev
, -1, urb
->status
);
335 if (urb
->status
== -ENOENT
)
339 buf
= dev
->video_mode
.isoc_ctl
.buf
;
341 outp
= videobuf_to_vmalloc(&buf
->vb
);
343 for (i
= 0; i
< urb
->number_of_packets
; i
++) {
344 int status
= urb
->iso_frame_desc
[i
].status
;
347 print_err_status(dev
, i
, status
);
348 if (urb
->iso_frame_desc
[i
].status
!= -EPROTO
)
352 if (urb
->iso_frame_desc
[i
].actual_length
<= 0) {
353 /* cx231xx_isocdbg("packet %d is empty",i); - spammy */
356 if (urb
->iso_frame_desc
[i
].actual_length
>
357 dev
->video_mode
.max_pkt_size
) {
358 cx231xx_isocdbg("packet bigger than packet size");
362 /* get buffer pointer and length */
363 p_buffer
= urb
->transfer_buffer
+ urb
->iso_frame_desc
[i
].offset
;
364 buffer_size
= urb
->iso_frame_desc
[i
].actual_length
;
367 if (dma_q
->is_partial_line
) {
368 /* Handle the case of a partial line */
369 sav_eav
= dma_q
->last_sav
;
371 /* Check for a SAV/EAV overlapping
372 the buffer boundary */
374 cx231xx_find_boundary_SAV_EAV(p_buffer
,
380 /* Get the first line if we have some portion of an SAV/EAV from
381 the last buffer or a partial line */
383 bytes_parsed
+= cx231xx_get_video_line(dev
, dma_q
,
384 sav_eav
, /* SAV/EAV */
385 p_buffer
+ bytes_parsed
, /* p_buffer */
386 buffer_size
- bytes_parsed
);/* buf size */
389 /* Now parse data that is completely in this buffer */
390 /* dma_q->is_partial_line = 0; */
392 while (bytes_parsed
< buffer_size
) {
395 sav_eav
= cx231xx_find_next_SAV_EAV(
396 p_buffer
+ bytes_parsed
, /* p_buffer */
397 buffer_size
- bytes_parsed
, /* buf size */
398 &bytes_used
);/* bytes used to get SAV/EAV */
400 bytes_parsed
+= bytes_used
;
403 if (sav_eav
&& (bytes_parsed
< buffer_size
)) {
404 bytes_parsed
+= cx231xx_get_video_line(dev
,
405 dma_q
, sav_eav
, /* SAV/EAV */
406 p_buffer
+ bytes_parsed
,/* p_buffer */
407 buffer_size
- bytes_parsed
);/*buf size*/
411 /* Save the last four bytes of the buffer so we can check the
412 buffer boundary condition next time */
413 memcpy(dma_q
->partial_buf
, p_buffer
+ buffer_size
- 4, 4);
420 u8
cx231xx_find_boundary_SAV_EAV(u8
*p_buffer
, u8
*partial_buf
,
424 u8 boundary_bytes
[8];
429 /* Create an array of the last 4 bytes of the last buffer and the first
430 4 bytes of the current buffer. */
432 memcpy(boundary_bytes
, partial_buf
, 4);
433 memcpy(boundary_bytes
+ 4, p_buffer
, 4);
435 /* Check for the SAV/EAV in the boundary buffer */
436 sav_eav
= cx231xx_find_next_SAV_EAV((u8
*)&boundary_bytes
, 8,
440 /* found a boundary SAV/EAV. Updates the bytes used to reflect
441 only those used in the new buffer */
442 *p_bytes_used
= bytes_used
- 4;
448 u8
cx231xx_find_next_SAV_EAV(u8
*p_buffer
, u32 buffer_size
, u32
*p_bytes_used
)
454 * Don't search if the buffer size is less than 4. It causes a page
455 * fault since buffer_size - 4 evaluates to a large number in that
458 if (buffer_size
< 4) {
459 *p_bytes_used
= buffer_size
;
463 for (i
= 0; i
< (buffer_size
- 3); i
++) {
465 if ((p_buffer
[i
] == 0xFF) &&
466 (p_buffer
[i
+ 1] == 0x00) && (p_buffer
[i
+ 2] == 0x00)) {
468 *p_bytes_used
= i
+ 4;
469 sav_eav
= p_buffer
[i
+ 3];
474 *p_bytes_used
= buffer_size
;
478 u32
cx231xx_get_video_line(struct cx231xx
*dev
,
479 struct cx231xx_dmaqueue
*dma_q
, u8 sav_eav
,
480 u8
*p_buffer
, u32 buffer_size
)
482 u32 bytes_copied
= 0;
483 int current_field
= -1;
486 case SAV_ACTIVE_VIDEO_FIELD1
:
487 /* looking for skipped line which occurred in PAL 720x480 mode.
488 In this case, there will be no active data contained
489 between the SAV and EAV */
490 if ((buffer_size
> 3) && (p_buffer
[0] == 0xFF) &&
491 (p_buffer
[1] == 0x00) && (p_buffer
[2] == 0x00) &&
492 ((p_buffer
[3] == EAV_ACTIVE_VIDEO_FIELD1
) ||
493 (p_buffer
[3] == EAV_ACTIVE_VIDEO_FIELD2
) ||
494 (p_buffer
[3] == EAV_VBLANK_FIELD1
) ||
495 (p_buffer
[3] == EAV_VBLANK_FIELD2
)))
500 case SAV_ACTIVE_VIDEO_FIELD2
:
501 /* looking for skipped line which occurred in PAL 720x480 mode.
502 In this case, there will be no active data contained between
504 if ((buffer_size
> 3) && (p_buffer
[0] == 0xFF) &&
505 (p_buffer
[1] == 0x00) && (p_buffer
[2] == 0x00) &&
506 ((p_buffer
[3] == EAV_ACTIVE_VIDEO_FIELD1
) ||
507 (p_buffer
[3] == EAV_ACTIVE_VIDEO_FIELD2
) ||
508 (p_buffer
[3] == EAV_VBLANK_FIELD1
) ||
509 (p_buffer
[3] == EAV_VBLANK_FIELD2
)))
515 dma_q
->last_sav
= sav_eav
;
517 bytes_copied
= cx231xx_copy_video_line(dev
, dma_q
, p_buffer
,
518 buffer_size
, current_field
);
523 u32
cx231xx_copy_video_line(struct cx231xx
*dev
,
524 struct cx231xx_dmaqueue
*dma_q
, u8
*p_line
,
525 u32 length
, int field_number
)
528 struct cx231xx_buffer
*buf
;
529 u32 _line_size
= dev
->width
* 2;
531 if (dma_q
->current_field
!= field_number
)
532 cx231xx_reset_video_buffer(dev
, dma_q
);
534 /* get the buffer pointer */
535 buf
= dev
->video_mode
.isoc_ctl
.buf
;
537 /* Remember the field number for next time */
538 dma_q
->current_field
= field_number
;
540 bytes_to_copy
= dma_q
->bytes_left_in_line
;
541 if (bytes_to_copy
> length
)
542 bytes_to_copy
= length
;
544 if (dma_q
->lines_completed
>= dma_q
->lines_per_field
) {
545 dma_q
->bytes_left_in_line
-= bytes_to_copy
;
546 dma_q
->is_partial_line
= (dma_q
->bytes_left_in_line
== 0) ?
551 dma_q
->is_partial_line
= 1;
553 /* If we don't have a buffer, just return the number of bytes we would
554 have copied if we had a buffer. */
556 dma_q
->bytes_left_in_line
-= bytes_to_copy
;
557 dma_q
->is_partial_line
= (dma_q
->bytes_left_in_line
== 0)
559 return bytes_to_copy
;
562 /* copy the data to video buffer */
563 cx231xx_do_copy(dev
, dma_q
, p_line
, bytes_to_copy
);
565 dma_q
->pos
+= bytes_to_copy
;
566 dma_q
->bytes_left_in_line
-= bytes_to_copy
;
568 if (dma_q
->bytes_left_in_line
== 0) {
569 dma_q
->bytes_left_in_line
= _line_size
;
570 dma_q
->lines_completed
++;
571 dma_q
->is_partial_line
= 0;
573 if (cx231xx_is_buffer_done(dev
, dma_q
) && buf
) {
574 buffer_filled(dev
, dma_q
, buf
);
578 dma_q
->lines_completed
= 0;
582 return bytes_to_copy
;
585 void cx231xx_reset_video_buffer(struct cx231xx
*dev
,
586 struct cx231xx_dmaqueue
*dma_q
)
588 struct cx231xx_buffer
*buf
;
590 /* handle the switch from field 1 to field 2 */
591 if (dma_q
->current_field
== 1) {
592 if (dma_q
->lines_completed
>= dma_q
->lines_per_field
)
593 dma_q
->field1_done
= 1;
595 dma_q
->field1_done
= 0;
598 buf
= dev
->video_mode
.isoc_ctl
.buf
;
602 /* first try to get the buffer */
603 get_next_buf(dma_q
, &buf
);
606 outp
= videobuf_to_vmalloc(&buf
->vb
);
609 dma_q
->field1_done
= 0;
610 dma_q
->current_field
= -1;
613 /* reset the counters */
614 dma_q
->bytes_left_in_line
= dev
->width
<< 1;
615 dma_q
->lines_completed
= 0;
618 int cx231xx_do_copy(struct cx231xx
*dev
, struct cx231xx_dmaqueue
*dma_q
,
619 u8
*p_buffer
, u32 bytes_to_copy
)
621 u8
*p_out_buffer
= NULL
;
622 u32 current_line_bytes_copied
= 0;
623 struct cx231xx_buffer
*buf
;
624 u32 _line_size
= dev
->width
<< 1;
628 buf
= dev
->video_mode
.isoc_ctl
.buf
;
633 p_out_buffer
= videobuf_to_vmalloc(&buf
->vb
);
635 current_line_bytes_copied
= _line_size
- dma_q
->bytes_left_in_line
;
637 /* Offset field 2 one line from the top of the buffer */
638 offset
= (dma_q
->current_field
== 1) ? 0 : _line_size
;
640 /* Offset for field 2 */
641 startwrite
= p_out_buffer
+ offset
;
643 /* lines already completed in the current field */
644 startwrite
+= (dma_q
->lines_completed
* _line_size
* 2);
646 /* bytes already completed in the current line */
647 startwrite
+= current_line_bytes_copied
;
649 lencopy
= dma_q
->bytes_left_in_line
> bytes_to_copy
?
650 bytes_to_copy
: dma_q
->bytes_left_in_line
;
652 if ((u8
*)(startwrite
+ lencopy
) > (u8
*)(p_out_buffer
+ buf
->vb
.size
))
655 /* The below copies the UYVY data straight into video buffer */
656 cx231xx_swab((u16
*) p_buffer
, (u16
*) startwrite
, (u16
) lencopy
);
661 void cx231xx_swab(u16
*from
, u16
*to
, u16 len
)
668 for (i
= 0; i
< len
/ 2; i
++)
669 to
[i
] = (from
[i
] << 8) | (from
[i
] >> 8);
672 u8
cx231xx_is_buffer_done(struct cx231xx
*dev
, struct cx231xx_dmaqueue
*dma_q
)
674 u8 buffer_complete
= 0;
676 /* Dual field stream */
677 buffer_complete
= ((dma_q
->current_field
== 2) &&
678 (dma_q
->lines_completed
>= dma_q
->lines_per_field
) &&
681 return buffer_complete
;
684 /* ------------------------------------------------------------------
686 ------------------------------------------------------------------*/
689 buffer_setup(struct videobuf_queue
*vq
, unsigned int *count
, unsigned int *size
)
691 struct cx231xx_fh
*fh
= vq
->priv_data
;
692 struct cx231xx
*dev
= fh
->dev
;
693 struct v4l2_frequency f
;
695 *size
= (fh
->dev
->width
* fh
->dev
->height
* dev
->format
->depth
+ 7)>>3;
697 *count
= CX231XX_DEF_BUF
;
699 if (*count
< CX231XX_MIN_BUF
)
700 *count
= CX231XX_MIN_BUF
;
702 /* Ask tuner to go to analog mode */
703 memset(&f
, 0, sizeof(f
));
704 f
.frequency
= dev
->ctl_freq
;
705 f
.type
= fh
->radio
? V4L2_TUNER_RADIO
: V4L2_TUNER_ANALOG_TV
;
707 call_all(dev
, tuner
, s_frequency
, &f
);
712 /* This is called *without* dev->slock held; please keep it that way */
713 static void free_buffer(struct videobuf_queue
*vq
, struct cx231xx_buffer
*buf
)
715 struct cx231xx_fh
*fh
= vq
->priv_data
;
716 struct cx231xx
*dev
= fh
->dev
;
717 unsigned long flags
= 0;
722 /* We used to wait for the buffer to finish here, but this didn't work
723 because, as we were keeping the state as VIDEOBUF_QUEUED,
724 videobuf_queue_cancel marked it as finished for us.
725 (Also, it could wedge forever if the hardware was misconfigured.)
727 This should be safe; by the time we get here, the buffer isn't
728 queued anymore. If we ever start marking the buffers as
729 VIDEOBUF_ACTIVE, it won't be, though.
731 spin_lock_irqsave(&dev
->video_mode
.slock
, flags
);
732 if (dev
->video_mode
.isoc_ctl
.buf
== buf
)
733 dev
->video_mode
.isoc_ctl
.buf
= NULL
;
734 spin_unlock_irqrestore(&dev
->video_mode
.slock
, flags
);
736 videobuf_vmalloc_free(&buf
->vb
);
737 buf
->vb
.state
= VIDEOBUF_NEEDS_INIT
;
741 buffer_prepare(struct videobuf_queue
*vq
, struct videobuf_buffer
*vb
,
742 enum v4l2_field field
)
744 struct cx231xx_fh
*fh
= vq
->priv_data
;
745 struct cx231xx_buffer
*buf
=
746 container_of(vb
, struct cx231xx_buffer
, vb
);
747 struct cx231xx
*dev
= fh
->dev
;
748 int rc
= 0, urb_init
= 0;
750 /* The only currently supported format is 16 bits/pixel */
751 buf
->vb
.size
= (fh
->dev
->width
* fh
->dev
->height
* dev
->format
->depth
753 if (0 != buf
->vb
.baddr
&& buf
->vb
.bsize
< buf
->vb
.size
)
756 buf
->vb
.width
= dev
->width
;
757 buf
->vb
.height
= dev
->height
;
758 buf
->vb
.field
= field
;
760 if (VIDEOBUF_NEEDS_INIT
== buf
->vb
.state
) {
761 rc
= videobuf_iolock(vq
, &buf
->vb
, NULL
);
766 if (!dev
->video_mode
.isoc_ctl
.num_bufs
)
770 rc
= cx231xx_init_isoc(dev
, CX231XX_NUM_PACKETS
,
772 dev
->video_mode
.max_pkt_size
,
778 buf
->vb
.state
= VIDEOBUF_PREPARED
;
782 free_buffer(vq
, buf
);
786 static void buffer_queue(struct videobuf_queue
*vq
, struct videobuf_buffer
*vb
)
788 struct cx231xx_buffer
*buf
=
789 container_of(vb
, struct cx231xx_buffer
, vb
);
790 struct cx231xx_fh
*fh
= vq
->priv_data
;
791 struct cx231xx
*dev
= fh
->dev
;
792 struct cx231xx_dmaqueue
*vidq
= &dev
->video_mode
.vidq
;
794 buf
->vb
.state
= VIDEOBUF_QUEUED
;
795 list_add_tail(&buf
->vb
.queue
, &vidq
->active
);
799 static void buffer_release(struct videobuf_queue
*vq
,
800 struct videobuf_buffer
*vb
)
802 struct cx231xx_buffer
*buf
=
803 container_of(vb
, struct cx231xx_buffer
, vb
);
804 struct cx231xx_fh
*fh
= vq
->priv_data
;
805 struct cx231xx
*dev
= (struct cx231xx
*)fh
->dev
;
807 cx231xx_isocdbg("cx231xx: called buffer_release\n");
809 free_buffer(vq
, buf
);
812 static struct videobuf_queue_ops cx231xx_video_qops
= {
813 .buf_setup
= buffer_setup
,
814 .buf_prepare
= buffer_prepare
,
815 .buf_queue
= buffer_queue
,
816 .buf_release
= buffer_release
,
819 /********************* v4l2 interface **************************************/
821 void video_mux(struct cx231xx
*dev
, int index
)
824 struct v4l2_routing route
;
826 route
.input
= INPUT(index
)->vmux
;
828 dev
->video_input
= index
;
829 dev
->ctl_ainput
= INPUT(index
)->amux
;
831 cx231xx_set_video_input_mux(dev
, index
);
833 cx25840_call(dev
, video
, s_routing
, &route
);
835 cx231xx_set_audio_input(dev
, dev
->ctl_ainput
);
837 cx231xx_info("video_mux : %d\n", index
);
839 /* do mode control overrides if required */
840 cx231xx_do_mode_ctrl_overrides(dev
);
843 /* Usage lock check functions */
844 static int res_get(struct cx231xx_fh
*fh
)
846 struct cx231xx
*dev
= fh
->dev
;
849 /* This instance already has stream_on */
853 if (fh
->type
== V4L2_BUF_TYPE_VIDEO_CAPTURE
) {
857 } else if (fh
->type
== V4L2_BUF_TYPE_VBI_CAPTURE
) {
858 if (dev
->vbi_stream_on
)
860 dev
->vbi_stream_on
= 1;
869 static int res_check(struct cx231xx_fh
*fh
)
871 return fh
->stream_on
;
874 static void res_free(struct cx231xx_fh
*fh
)
876 struct cx231xx
*dev
= fh
->dev
;
880 if (fh
->type
== V4L2_BUF_TYPE_VIDEO_CAPTURE
)
882 if (fh
->type
== V4L2_BUF_TYPE_VBI_CAPTURE
)
883 dev
->vbi_stream_on
= 0;
886 static int check_dev(struct cx231xx
*dev
)
888 if (dev
->state
& DEV_DISCONNECTED
) {
889 cx231xx_errdev("v4l2 ioctl: device not present\n");
893 if (dev
->state
& DEV_MISCONFIGURED
) {
894 cx231xx_errdev("v4l2 ioctl: device is misconfigured; "
895 "close and open it again\n");
901 void get_scale(struct cx231xx
*dev
,
902 unsigned int width
, unsigned int height
,
903 unsigned int *hscale
, unsigned int *vscale
)
905 unsigned int maxw
= norm_maxw(dev
);
906 unsigned int maxh
= norm_maxh(dev
);
908 *hscale
= (((unsigned long)maxw
) << 12) / width
- 4096L;
909 if (*hscale
>= 0x4000)
912 *vscale
= (((unsigned long)maxh
) << 12) / height
- 4096L;
913 if (*vscale
>= 0x4000)
916 dev
->hscale
= *hscale
;
917 dev
->vscale
= *vscale
;
921 /* ------------------------------------------------------------------
922 IOCTL vidioc handling
923 ------------------------------------------------------------------*/
925 static int vidioc_g_fmt_vid_cap(struct file
*file
, void *priv
,
926 struct v4l2_format
*f
)
928 struct cx231xx_fh
*fh
= priv
;
929 struct cx231xx
*dev
= fh
->dev
;
931 mutex_lock(&dev
->lock
);
933 f
->fmt
.pix
.width
= dev
->width
;
934 f
->fmt
.pix
.height
= dev
->height
;
935 f
->fmt
.pix
.pixelformat
= dev
->format
->fourcc
;;
936 f
->fmt
.pix
.bytesperline
= (dev
->width
* dev
->format
->depth
+ 7) >> 3;;
937 f
->fmt
.pix
.sizeimage
= f
->fmt
.pix
.bytesperline
* dev
->height
;
938 f
->fmt
.pix
.colorspace
= V4L2_COLORSPACE_SMPTE170M
;
940 f
->fmt
.pix
.field
= V4L2_FIELD_INTERLACED
;
942 mutex_unlock(&dev
->lock
);
947 static struct cx231xx_fmt
*format_by_fourcc(unsigned int fourcc
)
951 for (i
= 0; i
< ARRAY_SIZE(format
); i
++)
952 if (format
[i
].fourcc
== fourcc
)
958 static int vidioc_try_fmt_vid_cap(struct file
*file
, void *priv
,
959 struct v4l2_format
*f
)
961 struct cx231xx_fh
*fh
= priv
;
962 struct cx231xx
*dev
= fh
->dev
;
963 int width
= f
->fmt
.pix
.width
;
964 int height
= f
->fmt
.pix
.height
;
965 unsigned int maxw
= norm_maxw(dev
);
966 unsigned int maxh
= norm_maxh(dev
);
967 unsigned int hscale
, vscale
;
968 struct cx231xx_fmt
*fmt
;
970 fmt
= format_by_fourcc(f
->fmt
.pix
.pixelformat
);
972 cx231xx_videodbg("Fourcc format (%08x) invalid.\n",
973 f
->fmt
.pix
.pixelformat
);
977 /* width must even because of the YUYV format
978 height must be even because of interlacing */
982 if (unlikely(height
< 32))
984 if (unlikely(height
> maxh
))
986 if (unlikely(width
< 48))
988 if (unlikely(width
> maxw
))
991 get_scale(dev
, width
, height
, &hscale
, &vscale
);
993 width
= (((unsigned long)maxw
) << 12) / (hscale
+ 4096L);
994 height
= (((unsigned long)maxh
) << 12) / (vscale
+ 4096L);
996 f
->fmt
.pix
.width
= width
;
997 f
->fmt
.pix
.height
= height
;
998 f
->fmt
.pix
.pixelformat
= fmt
->fourcc
;
999 f
->fmt
.pix
.bytesperline
= (dev
->width
* fmt
->depth
+ 7) >> 3;
1000 f
->fmt
.pix
.sizeimage
= f
->fmt
.pix
.bytesperline
* height
;
1001 f
->fmt
.pix
.colorspace
= V4L2_COLORSPACE_SMPTE170M
;
1002 f
->fmt
.pix
.field
= V4L2_FIELD_INTERLACED
;
1007 static int vidioc_s_fmt_vid_cap(struct file
*file
, void *priv
,
1008 struct v4l2_format
*f
)
1010 struct cx231xx_fh
*fh
= priv
;
1011 struct cx231xx
*dev
= fh
->dev
;
1013 struct cx231xx_fmt
*fmt
;
1015 rc
= check_dev(dev
);
1019 mutex_lock(&dev
->lock
);
1021 vidioc_try_fmt_vid_cap(file
, priv
, f
);
1023 fmt
= format_by_fourcc(f
->fmt
.pix
.pixelformat
);
1029 if (videobuf_queue_is_busy(&fh
->vb_vidq
)) {
1030 cx231xx_errdev("%s queue busy\n", __func__
);
1035 if (dev
->stream_on
&& !fh
->stream_on
) {
1036 cx231xx_errdev("%s device in use by another fh\n", __func__
);
1041 /* set new image size */
1042 dev
->width
= f
->fmt
.pix
.width
;
1043 dev
->height
= f
->fmt
.pix
.height
;
1045 get_scale(dev
, dev
->width
, dev
->height
, &dev
->hscale
, &dev
->vscale
);
1047 call_all(dev
, video
, s_fmt
, f
);
1049 /* Set the correct alternate setting for this resolution */
1050 cx231xx_resolution_set(dev
);
1053 mutex_unlock(&dev
->lock
);
1057 static int vidioc_g_std(struct file
*file
, void *priv
, v4l2_std_id
* id
)
1059 struct cx231xx_fh
*fh
= priv
;
1060 struct cx231xx
*dev
= fh
->dev
;
1066 static int vidioc_s_std(struct file
*file
, void *priv
, v4l2_std_id
*norm
)
1068 struct cx231xx_fh
*fh
= priv
;
1069 struct cx231xx
*dev
= fh
->dev
;
1070 struct v4l2_format f
;
1073 rc
= check_dev(dev
);
1077 cx231xx_info("vidioc_s_std : 0x%x\n", (unsigned int)*norm
);
1079 mutex_lock(&dev
->lock
);
1082 /* Adjusts width/height, if needed */
1083 f
.fmt
.pix
.width
= dev
->width
;
1084 f
.fmt
.pix
.height
= dev
->height
;
1085 vidioc_try_fmt_vid_cap(file
, priv
, &f
);
1087 /* set new image size */
1088 dev
->width
= f
.fmt
.pix
.width
;
1089 dev
->height
= f
.fmt
.pix
.height
;
1090 get_scale(dev
, dev
->width
, dev
->height
, &dev
->hscale
, &dev
->vscale
);
1092 call_all(dev
, core
, s_std
, dev
->norm
);
1094 mutex_unlock(&dev
->lock
);
1096 cx231xx_resolution_set(dev
);
1098 /* do mode control overrides */
1099 cx231xx_do_mode_ctrl_overrides(dev
);
1104 static const char *iname
[] = {
1105 [CX231XX_VMUX_COMPOSITE1
] = "Composite1",
1106 [CX231XX_VMUX_SVIDEO
] = "S-Video",
1107 [CX231XX_VMUX_TELEVISION
] = "Television",
1108 [CX231XX_VMUX_CABLE
] = "Cable TV",
1109 [CX231XX_VMUX_DVB
] = "DVB",
1110 [CX231XX_VMUX_DEBUG
] = "for debug only",
1113 static int vidioc_enum_input(struct file
*file
, void *priv
,
1114 struct v4l2_input
*i
)
1116 struct cx231xx_fh
*fh
= priv
;
1117 struct cx231xx
*dev
= fh
->dev
;
1121 if (n
>= MAX_CX231XX_INPUT
)
1123 if (0 == INPUT(n
)->type
)
1127 i
->type
= V4L2_INPUT_TYPE_CAMERA
;
1129 strcpy(i
->name
, iname
[INPUT(n
)->type
]);
1131 if ((CX231XX_VMUX_TELEVISION
== INPUT(n
)->type
) ||
1132 (CX231XX_VMUX_CABLE
== INPUT(n
)->type
))
1133 i
->type
= V4L2_INPUT_TYPE_TUNER
;
1135 i
->std
= dev
->vdev
->tvnorms
;
1140 static int vidioc_g_input(struct file
*file
, void *priv
, unsigned int *i
)
1142 struct cx231xx_fh
*fh
= priv
;
1143 struct cx231xx
*dev
= fh
->dev
;
1145 *i
= dev
->video_input
;
1150 static int vidioc_s_input(struct file
*file
, void *priv
, unsigned int i
)
1152 struct cx231xx_fh
*fh
= priv
;
1153 struct cx231xx
*dev
= fh
->dev
;
1156 rc
= check_dev(dev
);
1160 if (i
>= MAX_CX231XX_INPUT
)
1162 if (0 == INPUT(i
)->type
)
1165 mutex_lock(&dev
->lock
);
1169 mutex_unlock(&dev
->lock
);
1173 static int vidioc_g_audio(struct file
*file
, void *priv
, struct v4l2_audio
*a
)
1175 struct cx231xx_fh
*fh
= priv
;
1176 struct cx231xx
*dev
= fh
->dev
;
1179 case CX231XX_AMUX_VIDEO
:
1180 strcpy(a
->name
, "Television");
1182 case CX231XX_AMUX_LINE_IN
:
1183 strcpy(a
->name
, "Line In");
1189 a
->index
= dev
->ctl_ainput
;
1190 a
->capability
= V4L2_AUDCAP_STEREO
;
1195 static int vidioc_s_audio(struct file
*file
, void *priv
, struct v4l2_audio
*a
)
1197 struct cx231xx_fh
*fh
= priv
;
1198 struct cx231xx
*dev
= fh
->dev
;
1201 /* Doesn't allow manual routing */
1202 if (a
->index
!= dev
->ctl_ainput
)
1205 dev
->ctl_ainput
= INPUT(a
->index
)->amux
;
1206 status
= cx231xx_set_audio_input(dev
, dev
->ctl_ainput
);
1211 static int vidioc_queryctrl(struct file
*file
, void *priv
,
1212 struct v4l2_queryctrl
*qc
)
1214 struct cx231xx_fh
*fh
= priv
;
1215 struct cx231xx
*dev
= fh
->dev
;
1220 rc
= check_dev(dev
);
1224 qc
->id
= v4l2_ctrl_next(ctrl_classes
, qc
->id
);
1225 if (unlikely(qc
->id
== 0))
1228 memset(qc
, 0, sizeof(*qc
));
1232 if (qc
->id
< V4L2_CID_BASE
|| qc
->id
>= V4L2_CID_LASTP1
)
1235 for (i
= 0; i
< CX231XX_CTLS
; i
++)
1236 if (cx231xx_ctls
[i
].v
.id
== qc
->id
)
1239 if (i
== CX231XX_CTLS
) {
1243 *qc
= cx231xx_ctls
[i
].v
;
1245 mutex_lock(&dev
->lock
);
1246 call_all(dev
, core
, queryctrl
, qc
);
1247 mutex_unlock(&dev
->lock
);
1255 static int vidioc_g_ctrl(struct file
*file
, void *priv
,
1256 struct v4l2_control
*ctrl
)
1258 struct cx231xx_fh
*fh
= priv
;
1259 struct cx231xx
*dev
= fh
->dev
;
1262 rc
= check_dev(dev
);
1266 mutex_lock(&dev
->lock
);
1267 call_all(dev
, core
, g_ctrl
, ctrl
);
1268 mutex_unlock(&dev
->lock
);
1272 static int vidioc_s_ctrl(struct file
*file
, void *priv
,
1273 struct v4l2_control
*ctrl
)
1275 struct cx231xx_fh
*fh
= priv
;
1276 struct cx231xx
*dev
= fh
->dev
;
1279 rc
= check_dev(dev
);
1283 mutex_lock(&dev
->lock
);
1284 call_all(dev
, core
, s_ctrl
, ctrl
);
1285 mutex_unlock(&dev
->lock
);
1289 static int vidioc_g_tuner(struct file
*file
, void *priv
, struct v4l2_tuner
*t
)
1291 struct cx231xx_fh
*fh
= priv
;
1292 struct cx231xx
*dev
= fh
->dev
;
1295 rc
= check_dev(dev
);
1302 strcpy(t
->name
, "Tuner");
1304 t
->type
= V4L2_TUNER_ANALOG_TV
;
1305 t
->capability
= V4L2_TUNER_CAP_NORM
;
1306 t
->rangehigh
= 0xffffffffUL
;
1307 t
->signal
= 0xffff; /* LOCKED */
1312 static int vidioc_s_tuner(struct file
*file
, void *priv
, struct v4l2_tuner
*t
)
1314 struct cx231xx_fh
*fh
= priv
;
1315 struct cx231xx
*dev
= fh
->dev
;
1318 rc
= check_dev(dev
);
1325 mutex_lock(&dev
->lock
);
1326 call_all(dev
, tuner
, s_tuner
, t
);
1327 mutex_unlock(&dev
->lock
);
1332 static int vidioc_g_frequency(struct file
*file
, void *priv
,
1333 struct v4l2_frequency
*f
)
1335 struct cx231xx_fh
*fh
= priv
;
1336 struct cx231xx
*dev
= fh
->dev
;
1338 mutex_lock(&dev
->lock
);
1339 f
->type
= fh
->radio
? V4L2_TUNER_RADIO
: V4L2_TUNER_ANALOG_TV
;
1340 f
->frequency
= dev
->ctl_freq
;
1342 call_all(dev
, tuner
, g_frequency
, f
);
1344 mutex_unlock(&dev
->lock
);
1349 static int vidioc_s_frequency(struct file
*file
, void *priv
,
1350 struct v4l2_frequency
*f
)
1352 struct cx231xx_fh
*fh
= priv
;
1353 struct cx231xx
*dev
= fh
->dev
;
1356 rc
= check_dev(dev
);
1363 if (unlikely(0 == fh
->radio
&& f
->type
!= V4L2_TUNER_ANALOG_TV
))
1365 if (unlikely(1 == fh
->radio
&& f
->type
!= V4L2_TUNER_RADIO
))
1368 /* set pre channel change settings in DIF first */
1369 rc
= cx231xx_tuner_pre_channel_change(dev
);
1371 mutex_lock(&dev
->lock
);
1373 dev
->ctl_freq
= f
->frequency
;
1375 if (dev
->tuner_type
== TUNER_XC5000
) {
1376 if (dev
->cx231xx_set_analog_freq
!= NULL
)
1377 dev
->cx231xx_set_analog_freq(dev
, f
->frequency
);
1379 call_all(dev
, tuner
, s_frequency
, f
);
1381 mutex_unlock(&dev
->lock
);
1383 /* set post channel change settings in DIF first */
1384 rc
= cx231xx_tuner_post_channel_change(dev
);
1386 cx231xx_info("Set New FREQUENCY to %d\n", f
->frequency
);
1391 #ifdef CONFIG_VIDEO_ADV_DEBUG
1394 -R, --list-registers=type=<host/i2cdrv/i2caddr>,
1395 chip=<chip>[,min=<addr>,max=<addr>]
1396 dump registers from <min> to <max> [VIDIOC_DBG_G_REGISTER]
1397 -r, --set-register=type=<host/i2cdrv/i2caddr>,
1398 chip=<chip>,reg=<addr>,val=<val>
1399 set the register [VIDIOC_DBG_S_REGISTER]
1401 if type == host, then <chip> is the hosts chip ID (default 0)
1402 if type == i2cdrv (default), then <chip> is the I2C driver name or ID
1403 if type == i2caddr, then <chip> is the 7-bit I2C address
1406 static int vidioc_g_register(struct file
*file
, void *priv
,
1407 struct v4l2_dbg_register
*reg
)
1409 struct cx231xx_fh
*fh
= priv
;
1410 struct cx231xx
*dev
= fh
->dev
;
1412 u8 value
[4] = { 0, 0, 0, 0 };
1415 switch (reg
->match
.type
) {
1416 case V4L2_CHIP_MATCH_HOST
:
1417 switch (reg
->match
.addr
) {
1418 case 0: /* Cx231xx - internal registers */
1419 ret
= cx231xx_read_ctrl_reg(dev
, VRT_GET_REGISTER
,
1420 (u16
)reg
->reg
, value
, 4);
1421 reg
->val
= value
[0] | value
[1] << 8 |
1422 value
[2] << 16 | value
[3] << 24;
1424 case 1: /* AFE - read byte */
1425 ret
= cx231xx_read_i2c_data(dev
, AFE_DEVICE_ADDRESS
,
1426 (u16
)reg
->reg
, 2, &data
, 1);
1427 reg
->val
= le32_to_cpu(data
& 0xff);
1429 case 14: /* AFE - read dword */
1430 ret
= cx231xx_read_i2c_data(dev
, AFE_DEVICE_ADDRESS
,
1431 (u16
)reg
->reg
, 2, &data
, 4);
1432 reg
->val
= le32_to_cpu(data
);
1434 case 2: /* Video Block - read byte */
1435 ret
= cx231xx_read_i2c_data(dev
, VID_BLK_I2C_ADDRESS
,
1436 (u16
)reg
->reg
, 2, &data
, 1);
1437 reg
->val
= le32_to_cpu(data
& 0xff);
1439 case 24: /* Video Block - read dword */
1440 ret
= cx231xx_read_i2c_data(dev
, VID_BLK_I2C_ADDRESS
,
1441 (u16
)reg
->reg
, 2, &data
, 4);
1442 reg
->val
= le32_to_cpu(data
);
1444 case 3: /* I2S block - read byte */
1445 ret
= cx231xx_read_i2c_data(dev
,
1446 I2S_BLK_DEVICE_ADDRESS
,
1449 reg
->val
= le32_to_cpu(data
& 0xff);
1451 case 34: /* I2S Block - read dword */
1453 cx231xx_read_i2c_data(dev
, I2S_BLK_DEVICE_ADDRESS
,
1454 (u16
)reg
->reg
, 1, &data
, 4);
1455 reg
->val
= le32_to_cpu(data
);
1458 return ret
< 0 ? ret
: 0;
1460 case V4L2_CHIP_MATCH_I2C_DRIVER
:
1461 call_all(dev
, core
, g_register
, reg
);
1463 case V4L2_CHIP_MATCH_I2C_ADDR
:
1464 /* Not supported yet */
1467 if (!v4l2_chip_match_host(®
->match
))
1471 mutex_lock(&dev
->lock
);
1472 call_all(dev
, core
, g_register
, reg
);
1473 mutex_unlock(&dev
->lock
);
1478 static int vidioc_s_register(struct file
*file
, void *priv
,
1479 struct v4l2_dbg_register
*reg
)
1481 struct cx231xx_fh
*fh
= priv
;
1482 struct cx231xx
*dev
= fh
->dev
;
1486 u8 data
[4] = { 0, 0, 0, 0 };
1488 buf
= cpu_to_le64(reg
->val
);
1490 switch (reg
->match
.type
) {
1491 case V4L2_CHIP_MATCH_HOST
:
1493 value
= (u32
) buf
& 0xffffffff;
1495 switch (reg
->match
.addr
) {
1496 case 0: /* cx231xx internal registers */
1497 data
[0] = (u8
) value
;
1498 data
[1] = (u8
) (value
>> 8);
1499 data
[2] = (u8
) (value
>> 16);
1500 data
[3] = (u8
) (value
>> 24);
1501 ret
= cx231xx_write_ctrl_reg(dev
,
1503 (u16
)reg
->reg
, data
,
1506 case 1: /* AFE - read byte */
1507 ret
= cx231xx_write_i2c_data(dev
,
1512 case 14: /* AFE - read dword */
1513 ret
= cx231xx_write_i2c_data(dev
,
1518 case 2: /* Video Block - read byte */
1520 cx231xx_write_i2c_data(dev
,
1521 VID_BLK_I2C_ADDRESS
,
1525 case 24: /* Video Block - read dword */
1527 cx231xx_write_i2c_data(dev
,
1528 VID_BLK_I2C_ADDRESS
,
1532 case 3: /* I2S block - read byte */
1534 cx231xx_write_i2c_data(dev
,
1535 I2S_BLK_DEVICE_ADDRESS
,
1539 case 34: /* I2S block - read dword */
1541 cx231xx_write_i2c_data(dev
,
1542 I2S_BLK_DEVICE_ADDRESS
,
1548 return ret
< 0 ? ret
: 0;
1554 mutex_lock(&dev
->lock
);
1555 call_all(dev
, core
, s_register
, reg
);
1556 mutex_unlock(&dev
->lock
);
1562 static int vidioc_cropcap(struct file
*file
, void *priv
,
1563 struct v4l2_cropcap
*cc
)
1565 struct cx231xx_fh
*fh
= priv
;
1566 struct cx231xx
*dev
= fh
->dev
;
1568 if (cc
->type
!= V4L2_BUF_TYPE_VIDEO_CAPTURE
)
1571 cc
->bounds
.left
= 0;
1573 cc
->bounds
.width
= dev
->width
;
1574 cc
->bounds
.height
= dev
->height
;
1575 cc
->defrect
= cc
->bounds
;
1576 cc
->pixelaspect
.numerator
= 54; /* 4:3 FIXME: remove magic numbers */
1577 cc
->pixelaspect
.denominator
= 59;
1582 static int vidioc_streamon(struct file
*file
, void *priv
,
1583 enum v4l2_buf_type type
)
1585 struct cx231xx_fh
*fh
= priv
;
1586 struct cx231xx
*dev
= fh
->dev
;
1589 rc
= check_dev(dev
);
1593 mutex_lock(&dev
->lock
);
1596 if (likely(rc
>= 0))
1597 rc
= videobuf_streamon(&fh
->vb_vidq
);
1599 call_all(dev
, video
, s_stream
, 1);
1601 mutex_unlock(&dev
->lock
);
1606 static int vidioc_streamoff(struct file
*file
, void *priv
,
1607 enum v4l2_buf_type type
)
1609 struct cx231xx_fh
*fh
= priv
;
1610 struct cx231xx
*dev
= fh
->dev
;
1613 rc
= check_dev(dev
);
1617 if ((fh
->type
!= V4L2_BUF_TYPE_VIDEO_CAPTURE
) &&
1618 (fh
->type
!= V4L2_BUF_TYPE_VBI_CAPTURE
))
1620 if (type
!= fh
->type
)
1623 mutex_lock(&dev
->lock
);
1625 cx25840_call(dev
, video
, s_stream
, 0);
1627 videobuf_streamoff(&fh
->vb_vidq
);
1630 mutex_unlock(&dev
->lock
);
1635 static int vidioc_querycap(struct file
*file
, void *priv
,
1636 struct v4l2_capability
*cap
)
1638 struct cx231xx_fh
*fh
= priv
;
1639 struct cx231xx
*dev
= fh
->dev
;
1641 strlcpy(cap
->driver
, "cx231xx", sizeof(cap
->driver
));
1642 strlcpy(cap
->card
, cx231xx_boards
[dev
->model
].name
, sizeof(cap
->card
));
1643 usb_make_path(dev
->udev
, cap
->bus_info
, sizeof(cap
->bus_info
));
1645 cap
->version
= CX231XX_VERSION_CODE
;
1647 cap
->capabilities
= V4L2_CAP_VBI_CAPTURE
|
1649 V4L2_CAP_SLICED_VBI_CAPTURE
|
1651 V4L2_CAP_VIDEO_CAPTURE
|
1653 V4L2_CAP_READWRITE
|
1656 if (dev
->tuner_type
!= TUNER_ABSENT
)
1657 cap
->capabilities
|= V4L2_CAP_TUNER
;
1662 static int vidioc_enum_fmt_vid_cap(struct file
*file
, void *priv
,
1663 struct v4l2_fmtdesc
*f
)
1665 if (unlikely(f
->index
>= ARRAY_SIZE(format
)))
1668 strlcpy(f
->description
, format
[f
->index
].name
, sizeof(f
->description
));
1669 f
->pixelformat
= format
[f
->index
].fourcc
;
1674 /* Sliced VBI ioctls */
1675 static int vidioc_g_fmt_sliced_vbi_cap(struct file
*file
, void *priv
,
1676 struct v4l2_format
*f
)
1678 struct cx231xx_fh
*fh
= priv
;
1679 struct cx231xx
*dev
= fh
->dev
;
1682 rc
= check_dev(dev
);
1686 mutex_lock(&dev
->lock
);
1688 f
->fmt
.sliced
.service_set
= 0;
1690 call_all(dev
, video
, g_fmt
, f
);
1692 if (f
->fmt
.sliced
.service_set
== 0)
1695 mutex_unlock(&dev
->lock
);
1699 static int vidioc_try_set_sliced_vbi_cap(struct file
*file
, void *priv
,
1700 struct v4l2_format
*f
)
1702 struct cx231xx_fh
*fh
= priv
;
1703 struct cx231xx
*dev
= fh
->dev
;
1706 rc
= check_dev(dev
);
1710 mutex_lock(&dev
->lock
);
1711 call_all(dev
, video
, g_fmt
, f
);
1712 mutex_unlock(&dev
->lock
);
1714 if (f
->fmt
.sliced
.service_set
== 0)
1720 /* RAW VBI ioctls */
1722 static int vidioc_g_fmt_vbi_cap(struct file
*file
, void *priv
,
1723 struct v4l2_format
*f
)
1725 struct cx231xx_fh
*fh
= priv
;
1726 struct cx231xx
*dev
= fh
->dev
;
1728 f
->fmt
.vbi
.sampling_rate
= (dev
->norm
& V4L2_STD_625_50
) ?
1729 35468950 : 28636363;
1730 f
->fmt
.vbi
.samples_per_line
= VBI_LINE_LENGTH
;
1731 f
->fmt
.vbi
.sample_format
= V4L2_PIX_FMT_GREY
;
1732 f
->fmt
.vbi
.offset
= 64 * 4;
1733 f
->fmt
.vbi
.start
[0] = (dev
->norm
& V4L2_STD_625_50
) ?
1734 PAL_VBI_START_LINE
: NTSC_VBI_START_LINE
;
1735 f
->fmt
.vbi
.count
[0] = (dev
->norm
& V4L2_STD_625_50
) ?
1736 PAL_VBI_LINES
: NTSC_VBI_LINES
;
1737 f
->fmt
.vbi
.start
[1] = (dev
->norm
& V4L2_STD_625_50
) ?
1738 PAL_VBI_START_LINE
+ 312 : NTSC_VBI_START_LINE
+ 263;
1739 f
->fmt
.vbi
.count
[1] = f
->fmt
.vbi
.count
[0];
1745 static int vidioc_try_fmt_vbi_cap(struct file
*file
, void *priv
,
1746 struct v4l2_format
*f
)
1748 struct cx231xx_fh
*fh
= priv
;
1749 struct cx231xx
*dev
= fh
->dev
;
1751 if (dev
->vbi_stream_on
&& !fh
->stream_on
) {
1752 cx231xx_errdev("%s device in use by another fh\n", __func__
);
1756 f
->type
= V4L2_BUF_TYPE_VBI_CAPTURE
;
1757 f
->fmt
.vbi
.sampling_rate
= (dev
->norm
& V4L2_STD_625_50
) ?
1758 35468950 : 28636363;
1759 f
->fmt
.vbi
.samples_per_line
= VBI_LINE_LENGTH
;
1760 f
->fmt
.vbi
.sample_format
= V4L2_PIX_FMT_GREY
;
1761 f
->fmt
.vbi
.offset
= 244;
1762 f
->fmt
.vbi
.flags
= 0;
1763 f
->fmt
.vbi
.start
[0] = (dev
->norm
& V4L2_STD_625_50
) ?
1764 PAL_VBI_START_LINE
: NTSC_VBI_START_LINE
;
1765 f
->fmt
.vbi
.count
[0] = (dev
->norm
& V4L2_STD_625_50
) ?
1766 PAL_VBI_LINES
: NTSC_VBI_LINES
;
1767 f
->fmt
.vbi
.start
[1] = (dev
->norm
& V4L2_STD_625_50
) ?
1768 PAL_VBI_START_LINE
+ 312 : NTSC_VBI_START_LINE
+ 263;
1769 f
->fmt
.vbi
.count
[1] = f
->fmt
.vbi
.count
[0];
1775 static int vidioc_reqbufs(struct file
*file
, void *priv
,
1776 struct v4l2_requestbuffers
*rb
)
1778 struct cx231xx_fh
*fh
= priv
;
1779 struct cx231xx
*dev
= fh
->dev
;
1782 rc
= check_dev(dev
);
1786 return videobuf_reqbufs(&fh
->vb_vidq
, rb
);
1789 static int vidioc_querybuf(struct file
*file
, void *priv
, struct v4l2_buffer
*b
)
1791 struct cx231xx_fh
*fh
= priv
;
1792 struct cx231xx
*dev
= fh
->dev
;
1795 rc
= check_dev(dev
);
1799 return videobuf_querybuf(&fh
->vb_vidq
, b
);
1802 static int vidioc_qbuf(struct file
*file
, void *priv
, struct v4l2_buffer
*b
)
1804 struct cx231xx_fh
*fh
= priv
;
1805 struct cx231xx
*dev
= fh
->dev
;
1808 rc
= check_dev(dev
);
1812 return videobuf_qbuf(&fh
->vb_vidq
, b
);
1815 static int vidioc_dqbuf(struct file
*file
, void *priv
, struct v4l2_buffer
*b
)
1817 struct cx231xx_fh
*fh
= priv
;
1818 struct cx231xx
*dev
= fh
->dev
;
1821 rc
= check_dev(dev
);
1825 return videobuf_dqbuf(&fh
->vb_vidq
, b
, file
->f_flags
& O_NONBLOCK
);
1828 #ifdef CONFIG_VIDEO_V4L1_COMPAT
1829 static int vidiocgmbuf(struct file
*file
, void *priv
, struct video_mbuf
*mbuf
)
1831 struct cx231xx_fh
*fh
= priv
;
1833 return videobuf_cgmbuf(&fh
->vb_vidq
, mbuf
, 8);
1837 /* ----------------------------------------------------------- */
1838 /* RADIO ESPECIFIC IOCTLS */
1839 /* ----------------------------------------------------------- */
1841 static int radio_querycap(struct file
*file
, void *priv
,
1842 struct v4l2_capability
*cap
)
1844 struct cx231xx
*dev
= ((struct cx231xx_fh
*)priv
)->dev
;
1846 strlcpy(cap
->driver
, "cx231xx", sizeof(cap
->driver
));
1847 strlcpy(cap
->card
, cx231xx_boards
[dev
->model
].name
, sizeof(cap
->card
));
1848 usb_make_path(dev
->udev
, cap
->bus_info
, sizeof(cap
->bus_info
));
1850 cap
->version
= CX231XX_VERSION_CODE
;
1851 cap
->capabilities
= V4L2_CAP_TUNER
;
1855 static int radio_g_tuner(struct file
*file
, void *priv
, struct v4l2_tuner
*t
)
1857 struct cx231xx
*dev
= ((struct cx231xx_fh
*)priv
)->dev
;
1859 if (unlikely(t
->index
> 0))
1862 strcpy(t
->name
, "Radio");
1863 t
->type
= V4L2_TUNER_RADIO
;
1865 mutex_lock(&dev
->lock
);
1866 call_all(dev
, tuner
, s_tuner
, t
);
1867 mutex_unlock(&dev
->lock
);
1872 static int radio_enum_input(struct file
*file
, void *priv
, struct v4l2_input
*i
)
1876 strcpy(i
->name
, "Radio");
1877 i
->type
= V4L2_INPUT_TYPE_TUNER
;
1882 static int radio_g_audio(struct file
*file
, void *priv
, struct v4l2_audio
*a
)
1884 if (unlikely(a
->index
))
1887 strcpy(a
->name
, "Radio");
1891 static int radio_s_tuner(struct file
*file
, void *priv
, struct v4l2_tuner
*t
)
1893 struct cx231xx
*dev
= ((struct cx231xx_fh
*)priv
)->dev
;
1898 mutex_lock(&dev
->lock
);
1899 call_all(dev
, tuner
, s_tuner
, t
);
1900 mutex_unlock(&dev
->lock
);
1905 static int radio_s_audio(struct file
*file
, void *fh
, struct v4l2_audio
*a
)
1910 static int radio_s_input(struct file
*file
, void *fh
, unsigned int i
)
1915 static int radio_queryctrl(struct file
*file
, void *priv
,
1916 struct v4l2_queryctrl
*c
)
1920 if (c
->id
< V4L2_CID_BASE
|| c
->id
>= V4L2_CID_LASTP1
)
1922 if (c
->id
== V4L2_CID_AUDIO_MUTE
) {
1923 for (i
= 0; i
< CX231XX_CTLS
; i
++)
1924 if (cx231xx_ctls
[i
].v
.id
== c
->id
)
1926 *c
= cx231xx_ctls
[i
].v
;
1933 * cx231xx_v4l2_open()
1934 * inits the device and starts isoc transfer
1936 static int cx231xx_v4l2_open(struct file
*filp
)
1938 int minor
= video_devdata(filp
)->minor
;
1939 int errCode
= 0, radio
= 0;
1940 struct cx231xx
*dev
= NULL
;
1941 struct cx231xx_fh
*fh
;
1942 enum v4l2_buf_type fh_type
= 0;
1944 dev
= cx231xx_get_device(minor
, &fh_type
, &radio
);
1948 mutex_lock(&dev
->lock
);
1950 cx231xx_videodbg("open minor=%d type=%s users=%d\n",
1951 minor
, v4l2_type_names
[fh_type
], dev
->users
);
1954 errCode
= cx231xx_set_mode(dev
, CX231XX_ANALOG_MODE
);
1957 ("Device locked on digital mode. Can't open analog\n");
1958 mutex_unlock(&dev
->lock
);
1963 fh
= kzalloc(sizeof(struct cx231xx_fh
), GFP_KERNEL
);
1965 cx231xx_errdev("cx231xx-video.c: Out of memory?!\n");
1966 mutex_unlock(&dev
->lock
);
1972 filp
->private_data
= fh
;
1974 if (fh
->type
== V4L2_BUF_TYPE_VIDEO_CAPTURE
&& dev
->users
== 0) {
1975 dev
->width
= norm_maxw(dev
);
1976 dev
->height
= norm_maxh(dev
);
1980 /* Power up in Analog TV mode */
1981 cx231xx_set_power_mode(dev
, POLARIS_AVMODE_ANALOGT_TV
);
1984 cx231xx_set_mode(dev
, CX231XX_ANALOG_MODE
);
1986 cx231xx_resolution_set(dev
);
1988 /* set video alternate setting */
1989 cx231xx_set_video_alternate(dev
);
1991 /* Needed, since GPIO might have disabled power of
1993 cx231xx_config_i2c(dev
);
1995 /* device needs to be initialized before isoc transfer */
1996 dev
->video_input
= dev
->video_input
> 2 ? 2 : dev
->video_input
;
1997 video_mux(dev
, dev
->video_input
);
2001 cx231xx_videodbg("video_open: setting radio device\n");
2003 /* cx231xx_start_radio(dev); */
2005 call_all(dev
, tuner
, s_radio
);
2010 if (fh
->type
== V4L2_BUF_TYPE_VIDEO_CAPTURE
)
2011 videobuf_queue_vmalloc_init(&fh
->vb_vidq
, &cx231xx_video_qops
,
2012 NULL
, &dev
->video_mode
.slock
,
2013 fh
->type
, V4L2_FIELD_INTERLACED
,
2014 sizeof(struct cx231xx_buffer
), fh
);
2015 if (fh
->type
== V4L2_BUF_TYPE_VBI_CAPTURE
) {
2016 /* Set the required alternate setting VBI interface works in
2018 cx231xx_set_alt_setting(dev
, INDEX_VANC
, 0);
2020 videobuf_queue_vmalloc_init(&fh
->vb_vidq
, &cx231xx_vbi_qops
,
2021 NULL
, &dev
->vbi_mode
.slock
,
2022 fh
->type
, V4L2_FIELD_SEQ_TB
,
2023 sizeof(struct cx231xx_buffer
), fh
);
2026 mutex_unlock(&dev
->lock
);
2032 * cx231xx_realease_resources()
2033 * unregisters the v4l2,i2c and usb devices
2034 * called when the device gets disconected or at module unload
2036 void cx231xx_release_analog_resources(struct cx231xx
*dev
)
2039 /*FIXME: I2C IR should be disconnected */
2041 if (dev
->radio_dev
) {
2042 if (-1 != dev
->radio_dev
->minor
)
2043 video_unregister_device(dev
->radio_dev
);
2045 video_device_release(dev
->radio_dev
);
2046 dev
->radio_dev
= NULL
;
2049 cx231xx_info("V4L2 device /dev/vbi%d deregistered\n",
2051 if (-1 != dev
->vbi_dev
->minor
)
2052 video_unregister_device(dev
->vbi_dev
);
2054 video_device_release(dev
->vbi_dev
);
2055 dev
->vbi_dev
= NULL
;
2058 cx231xx_info("V4L2 device /dev/video%d deregistered\n",
2060 if (-1 != dev
->vdev
->minor
)
2061 video_unregister_device(dev
->vdev
);
2063 video_device_release(dev
->vdev
);
2069 * cx231xx_v4l2_close()
2070 * stops streaming and deallocates all resources allocated by the v4l2
2073 static int cx231xx_v4l2_close(struct file
*filp
)
2075 struct cx231xx_fh
*fh
= filp
->private_data
;
2076 struct cx231xx
*dev
= fh
->dev
;
2078 cx231xx_videodbg("users=%d\n", dev
->users
);
2080 mutex_lock(&dev
->lock
);
2085 if (fh
->type
== V4L2_BUF_TYPE_VBI_CAPTURE
) {
2086 videobuf_stop(&fh
->vb_vidq
);
2087 videobuf_mmap_free(&fh
->vb_vidq
);
2089 /* the device is already disconnect,
2090 free the remaining resources */
2091 if (dev
->state
& DEV_DISCONNECTED
) {
2092 cx231xx_release_resources(dev
);
2093 mutex_unlock(&dev
->lock
);
2098 /* do this before setting alternate! */
2099 cx231xx_uninit_vbi_isoc(dev
);
2101 /* set alternate 0 */
2102 if (!dev
->vbi_or_sliced_cc_mode
)
2103 cx231xx_set_alt_setting(dev
, INDEX_VANC
, 0);
2105 cx231xx_set_alt_setting(dev
, INDEX_HANC
, 0);
2109 wake_up_interruptible_nr(&dev
->open
, 1);
2110 mutex_unlock(&dev
->lock
);
2114 if (dev
->users
== 1) {
2115 videobuf_stop(&fh
->vb_vidq
);
2116 videobuf_mmap_free(&fh
->vb_vidq
);
2118 /* the device is already disconnect,
2119 free the remaining resources */
2120 if (dev
->state
& DEV_DISCONNECTED
) {
2121 cx231xx_release_resources(dev
);
2122 mutex_unlock(&dev
->lock
);
2127 /* Save some power by putting tuner to sleep */
2128 call_all(dev
, tuner
, s_standby
);
2130 /* do this before setting alternate! */
2131 cx231xx_uninit_isoc(dev
);
2132 cx231xx_set_mode(dev
, CX231XX_SUSPEND
);
2134 /* set alternate 0 */
2135 cx231xx_set_alt_setting(dev
, INDEX_VIDEO
, 0);
2139 wake_up_interruptible_nr(&dev
->open
, 1);
2140 mutex_unlock(&dev
->lock
);
2145 * cx231xx_v4l2_read()
2146 * will allocate buffers when called for the first time
2149 cx231xx_v4l2_read(struct file
*filp
, char __user
*buf
, size_t count
,
2152 struct cx231xx_fh
*fh
= filp
->private_data
;
2153 struct cx231xx
*dev
= fh
->dev
;
2156 rc
= check_dev(dev
);
2160 if ((fh
->type
== V4L2_BUF_TYPE_VIDEO_CAPTURE
) ||
2161 (fh
->type
== V4L2_BUF_TYPE_VBI_CAPTURE
)) {
2162 mutex_lock(&dev
->lock
);
2164 mutex_unlock(&dev
->lock
);
2166 if (unlikely(rc
< 0))
2169 return videobuf_read_stream(&fh
->vb_vidq
, buf
, count
, pos
, 0,
2170 filp
->f_flags
& O_NONBLOCK
);
2176 * cx231xx_v4l2_poll()
2177 * will allocate buffers when called for the first time
2179 static unsigned int cx231xx_v4l2_poll(struct file
*filp
, poll_table
* wait
)
2181 struct cx231xx_fh
*fh
= filp
->private_data
;
2182 struct cx231xx
*dev
= fh
->dev
;
2185 rc
= check_dev(dev
);
2189 mutex_lock(&dev
->lock
);
2191 mutex_unlock(&dev
->lock
);
2193 if (unlikely(rc
< 0))
2196 if ((V4L2_BUF_TYPE_VIDEO_CAPTURE
== fh
->type
) ||
2197 (V4L2_BUF_TYPE_VBI_CAPTURE
== fh
->type
))
2198 return videobuf_poll_stream(filp
, &fh
->vb_vidq
, wait
);
2204 * cx231xx_v4l2_mmap()
2206 static int cx231xx_v4l2_mmap(struct file
*filp
, struct vm_area_struct
*vma
)
2208 struct cx231xx_fh
*fh
= filp
->private_data
;
2209 struct cx231xx
*dev
= fh
->dev
;
2212 rc
= check_dev(dev
);
2216 mutex_lock(&dev
->lock
);
2218 mutex_unlock(&dev
->lock
);
2220 if (unlikely(rc
< 0))
2223 rc
= videobuf_mmap_mapper(&fh
->vb_vidq
, vma
);
2225 cx231xx_videodbg("vma start=0x%08lx, size=%ld, ret=%d\n",
2226 (unsigned long)vma
->vm_start
,
2227 (unsigned long)vma
->vm_end
-
2228 (unsigned long)vma
->vm_start
, rc
);
2233 static const struct v4l2_file_operations cx231xx_v4l_fops
= {
2234 .owner
= THIS_MODULE
,
2235 .open
= cx231xx_v4l2_open
,
2236 .release
= cx231xx_v4l2_close
,
2237 .read
= cx231xx_v4l2_read
,
2238 .poll
= cx231xx_v4l2_poll
,
2239 .mmap
= cx231xx_v4l2_mmap
,
2240 .ioctl
= video_ioctl2
,
2243 static const struct v4l2_ioctl_ops video_ioctl_ops
= {
2244 .vidioc_querycap
= vidioc_querycap
,
2245 .vidioc_enum_fmt_vid_cap
= vidioc_enum_fmt_vid_cap
,
2246 .vidioc_g_fmt_vid_cap
= vidioc_g_fmt_vid_cap
,
2247 .vidioc_try_fmt_vid_cap
= vidioc_try_fmt_vid_cap
,
2248 .vidioc_s_fmt_vid_cap
= vidioc_s_fmt_vid_cap
,
2249 .vidioc_g_fmt_vbi_cap
= vidioc_g_fmt_vbi_cap
,
2250 .vidioc_try_fmt_vbi_cap
= vidioc_try_fmt_vbi_cap
,
2251 .vidioc_s_fmt_vbi_cap
= vidioc_try_fmt_vbi_cap
,
2252 .vidioc_g_audio
= vidioc_g_audio
,
2253 .vidioc_s_audio
= vidioc_s_audio
,
2254 .vidioc_cropcap
= vidioc_cropcap
,
2255 .vidioc_g_fmt_sliced_vbi_cap
= vidioc_g_fmt_sliced_vbi_cap
,
2256 .vidioc_try_fmt_sliced_vbi_cap
= vidioc_try_set_sliced_vbi_cap
,
2257 .vidioc_reqbufs
= vidioc_reqbufs
,
2258 .vidioc_querybuf
= vidioc_querybuf
,
2259 .vidioc_qbuf
= vidioc_qbuf
,
2260 .vidioc_dqbuf
= vidioc_dqbuf
,
2261 .vidioc_s_std
= vidioc_s_std
,
2262 .vidioc_g_std
= vidioc_g_std
,
2263 .vidioc_enum_input
= vidioc_enum_input
,
2264 .vidioc_g_input
= vidioc_g_input
,
2265 .vidioc_s_input
= vidioc_s_input
,
2266 .vidioc_queryctrl
= vidioc_queryctrl
,
2267 .vidioc_g_ctrl
= vidioc_g_ctrl
,
2268 .vidioc_s_ctrl
= vidioc_s_ctrl
,
2269 .vidioc_streamon
= vidioc_streamon
,
2270 .vidioc_streamoff
= vidioc_streamoff
,
2271 .vidioc_g_tuner
= vidioc_g_tuner
,
2272 .vidioc_s_tuner
= vidioc_s_tuner
,
2273 .vidioc_g_frequency
= vidioc_g_frequency
,
2274 .vidioc_s_frequency
= vidioc_s_frequency
,
2275 #ifdef CONFIG_VIDEO_ADV_DEBUG
2276 .vidioc_g_register
= vidioc_g_register
,
2277 .vidioc_s_register
= vidioc_s_register
,
2279 #ifdef CONFIG_VIDEO_V4L1_COMPAT
2280 .vidiocgmbuf
= vidiocgmbuf
,
2284 static struct video_device cx231xx_vbi_template
;
2286 static const struct video_device cx231xx_video_template
= {
2287 .fops
= &cx231xx_v4l_fops
,
2288 .release
= video_device_release
,
2289 .ioctl_ops
= &video_ioctl_ops
,
2291 .tvnorms
= V4L2_STD_ALL
,
2292 .current_norm
= V4L2_STD_PAL
,
2295 static const struct v4l2_file_operations radio_fops
= {
2296 .owner
= THIS_MODULE
,
2297 .open
= cx231xx_v4l2_open
,
2298 .release
= cx231xx_v4l2_close
,
2299 .ioctl
= video_ioctl2
,
2302 static const struct v4l2_ioctl_ops radio_ioctl_ops
= {
2303 .vidioc_querycap
= radio_querycap
,
2304 .vidioc_g_tuner
= radio_g_tuner
,
2305 .vidioc_enum_input
= radio_enum_input
,
2306 .vidioc_g_audio
= radio_g_audio
,
2307 .vidioc_s_tuner
= radio_s_tuner
,
2308 .vidioc_s_audio
= radio_s_audio
,
2309 .vidioc_s_input
= radio_s_input
,
2310 .vidioc_queryctrl
= radio_queryctrl
,
2311 .vidioc_g_ctrl
= vidioc_g_ctrl
,
2312 .vidioc_s_ctrl
= vidioc_s_ctrl
,
2313 .vidioc_g_frequency
= vidioc_g_frequency
,
2314 .vidioc_s_frequency
= vidioc_s_frequency
,
2315 #ifdef CONFIG_VIDEO_ADV_DEBUG
2316 .vidioc_g_register
= vidioc_g_register
,
2317 .vidioc_s_register
= vidioc_s_register
,
2321 static struct video_device cx231xx_radio_template
= {
2322 .name
= "cx231xx-radio",
2323 .fops
= &radio_fops
,
2324 .ioctl_ops
= &radio_ioctl_ops
,
2328 /******************************** usb interface ******************************/
2330 static struct video_device
*cx231xx_vdev_init(struct cx231xx
*dev
,
2331 const struct video_device
2332 *template, const char *type_name
)
2334 struct video_device
*vfd
;
2336 vfd
= video_device_alloc();
2342 vfd
->v4l2_dev
= &dev
->v4l2_dev
;
2343 vfd
->release
= video_device_release
;
2344 vfd
->debug
= video_debug
;
2346 snprintf(vfd
->name
, sizeof(vfd
->name
), "%s %s", dev
->name
, type_name
);
2351 int cx231xx_register_analog_devices(struct cx231xx
*dev
)
2355 cx231xx_info("%s: v4l2 driver version %d.%d.%d\n",
2357 (CX231XX_VERSION_CODE
>> 16) & 0xff,
2358 (CX231XX_VERSION_CODE
>> 8) & 0xff,
2359 CX231XX_VERSION_CODE
& 0xff);
2361 /* set default norm */
2362 /*dev->norm = cx231xx_video_template.current_norm; */
2363 dev
->width
= norm_maxw(dev
);
2364 dev
->height
= norm_maxh(dev
);
2365 dev
->interlaced
= 0;
2369 /* Analog specific initialization */
2370 dev
->format
= &format
[0];
2371 /* video_mux(dev, dev->video_input); */
2373 /* Audio defaults */
2377 /* enable vbi capturing */
2378 /* write code here... */
2380 /* allocate and fill video video_device struct */
2381 dev
->vdev
= cx231xx_vdev_init(dev
, &cx231xx_video_template
, "video");
2383 cx231xx_errdev("cannot allocate video_device.\n");
2387 /* register v4l2 video video_device */
2388 ret
= video_register_device(dev
->vdev
, VFL_TYPE_GRABBER
,
2389 video_nr
[dev
->devno
]);
2391 cx231xx_errdev("unable to register video device (error=%i).\n",
2396 cx231xx_info("%s/0: registered device video%d [v4l2]\n",
2397 dev
->name
, dev
->vdev
->num
);
2399 /* Initialize VBI template */
2400 memcpy(&cx231xx_vbi_template
, &cx231xx_video_template
,
2401 sizeof(cx231xx_vbi_template
));
2402 strcpy(cx231xx_vbi_template
.name
, "cx231xx-vbi");
2404 /* Allocate and fill vbi video_device struct */
2405 dev
->vbi_dev
= cx231xx_vdev_init(dev
, &cx231xx_vbi_template
, "vbi");
2407 /* register v4l2 vbi video_device */
2408 ret
= video_register_device(dev
->vbi_dev
, VFL_TYPE_VBI
,
2409 vbi_nr
[dev
->devno
]);
2411 cx231xx_errdev("unable to register vbi device\n");
2415 cx231xx_info("%s/0: registered device vbi%d\n",
2416 dev
->name
, dev
->vbi_dev
->num
);
2418 if (cx231xx_boards
[dev
->model
].radio
.type
== CX231XX_RADIO
) {
2419 dev
->radio_dev
= cx231xx_vdev_init(dev
, &cx231xx_radio_template
,
2421 if (!dev
->radio_dev
) {
2422 cx231xx_errdev("cannot allocate video_device.\n");
2425 ret
= video_register_device(dev
->radio_dev
, VFL_TYPE_RADIO
,
2426 radio_nr
[dev
->devno
]);
2428 cx231xx_errdev("can't register radio device\n");
2431 cx231xx_info("Registered radio device as /dev/radio%d\n",
2432 dev
->radio_dev
->num
);
2435 cx231xx_info("V4L2 device registered as /dev/video%d and /dev/vbi%d\n",
2436 dev
->vdev
->num
, dev
->vbi_dev
->num
);