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>
35 #include <linux/slab.h>
37 #include <media/v4l2-common.h>
38 #include <media/v4l2-ioctl.h>
39 #include <media/v4l2-chip-ident.h>
40 #include <media/msp3400.h>
41 #include <media/tuner.h>
43 #include "dvb_frontend.h"
46 #include "cx231xx-vbi.h"
48 #define CX231XX_VERSION_CODE KERNEL_VERSION(0, 0, 1)
50 #define DRIVER_AUTHOR "Srinivasa Deevi <srinivasa.deevi@conexant.com>"
51 #define DRIVER_DESC "Conexant cx231xx based USB video device driver"
53 #define cx231xx_videodbg(fmt, arg...) do {\
55 printk(KERN_INFO "%s %s :"fmt, \
56 dev->name, __func__ , ##arg); } while (0)
58 static unsigned int isoc_debug;
59 module_param(isoc_debug, int, 0644);
60 MODULE_PARM_DESC(isoc_debug, "enable debug messages [isoc transfers]");
62 #define cx231xx_isocdbg(fmt, arg...) \
65 printk(KERN_INFO "%s %s :"fmt, \
66 dev->name, __func__ , ##arg); \
70 MODULE_AUTHOR(DRIVER_AUTHOR);
71 MODULE_DESCRIPTION(DRIVER_DESC);
72 MODULE_LICENSE("GPL");
74 static unsigned int card[] = {[0 ... (CX231XX_MAXBOARDS - 1)] = UNSET };
75 static unsigned int video_nr[] = {[0 ... (CX231XX_MAXBOARDS - 1)] = UNSET };
76 static unsigned int vbi_nr[] = {[0 ... (CX231XX_MAXBOARDS - 1)] = UNSET };
77 static unsigned int radio_nr[] = {[0 ... (CX231XX_MAXBOARDS - 1)] = UNSET };
79 module_param_array(card, int, NULL, 0444);
80 module_param_array(video_nr, int, NULL, 0444);
81 module_param_array(vbi_nr, int, NULL, 0444);
82 module_param_array(radio_nr, int, NULL, 0444);
84 MODULE_PARM_DESC(card, "card type");
85 MODULE_PARM_DESC(video_nr, "video device numbers");
86 MODULE_PARM_DESC(vbi_nr, "vbi device numbers");
87 MODULE_PARM_DESC(radio_nr, "radio device numbers");
89 static unsigned int video_debug;
90 module_param(video_debug, int, 0644);
91 MODULE_PARM_DESC(video_debug, "enable debug messages [video]");
93 /* supported video standards */
94 static struct cx231xx_fmt format[] = {
96 .name = "16bpp YUY2, 4:2:2, packed",
97 .fourcc = V4L2_PIX_FMT_YUYV,
103 /* supported controls */
104 /* Common to all boards */
106 /* ------------------------------------------------------------------- */
108 static const struct v4l2_queryctrl no_ctl = {
110 .flags = V4L2_CTRL_FLAG_DISABLED,
113 static struct cx231xx_ctrl cx231xx_ctls[] = {
117 .id = V4L2_CID_BRIGHTNESS,
118 .name = "Brightness",
122 .default_value = 0x7f,
123 .type = V4L2_CTRL_TYPE_INTEGER,
131 .id = V4L2_CID_CONTRAST,
136 .default_value = 0x3f,
137 .type = V4L2_CTRL_TYPE_INTEGER,
150 .default_value = 0x7f,
151 .type = V4L2_CTRL_TYPE_INTEGER,
158 /* strictly, this only describes only U saturation.
159 * V saturation is handled specially through code.
162 .id = V4L2_CID_SATURATION,
163 .name = "Saturation",
167 .default_value = 0x7f,
168 .type = V4L2_CTRL_TYPE_INTEGER,
177 .id = V4L2_CID_AUDIO_MUTE,
182 .type = V4L2_CTRL_TYPE_BOOLEAN,
185 .mask = (0x1f << 24),
189 .id = V4L2_CID_AUDIO_VOLUME,
194 .default_value = 0x3f,
195 .type = V4L2_CTRL_TYPE_INTEGER,
197 .reg = PATH1_VOL_CTL,
202 static const int CX231XX_CTLS = ARRAY_SIZE(cx231xx_ctls);
204 static const u32 cx231xx_user_ctrls[] = {
210 V4L2_CID_AUDIO_VOLUME,
212 V4L2_CID_AUDIO_BALANCE,
218 static const u32 *ctrl_classes[] = {
223 /* ------------------------------------------------------------------
224 Video buffer and parser functions
225 ------------------------------------------------------------------*/
228 * Announces that a buffer were filled and request the next
230 static inline void buffer_filled(struct cx231xx *dev,
231 struct cx231xx_dmaqueue *dma_q,
232 struct cx231xx_buffer *buf)
234 /* Advice that buffer was filled */
235 cx231xx_isocdbg("[%p/%d] wakeup\n", buf, buf->vb.i);
236 buf->vb.state = VIDEOBUF_DONE;
237 buf->vb.field_count++;
238 do_gettimeofday(&buf->vb.ts);
241 dev->video_mode.isoc_ctl.buf = NULL;
243 dev->video_mode.bulk_ctl.buf = NULL;
245 list_del(&buf->vb.queue);
246 wake_up(&buf->vb.done);
249 static inline void print_err_status(struct cx231xx *dev, int packet, int status)
251 char *errmsg = "Unknown";
255 errmsg = "unlinked synchronuously";
258 errmsg = "unlinked asynchronuously";
261 errmsg = "Buffer error (overrun)";
264 errmsg = "Stalled (device not responding)";
267 errmsg = "Babble (bad cable?)";
270 errmsg = "Bit-stuff error (bad cable?)";
273 errmsg = "CRC/Timeout (could be anything)";
276 errmsg = "Device does not respond";
280 cx231xx_isocdbg("URB status %d [%s].\n", status, errmsg);
282 cx231xx_isocdbg("URB packet %d, status %d [%s].\n",
283 packet, status, errmsg);
288 * video-buf generic routine to get the next available buffer
290 static inline void get_next_buf(struct cx231xx_dmaqueue *dma_q,
291 struct cx231xx_buffer **buf)
293 struct cx231xx_video_mode *vmode =
294 container_of(dma_q, struct cx231xx_video_mode, vidq);
295 struct cx231xx *dev = container_of(vmode, struct cx231xx, video_mode);
299 if (list_empty(&dma_q->active)) {
300 cx231xx_isocdbg("No active queue to serve\n");
302 dev->video_mode.isoc_ctl.buf = NULL;
304 dev->video_mode.bulk_ctl.buf = NULL;
309 /* Get the next buffer */
310 *buf = list_entry(dma_q->active.next, struct cx231xx_buffer, vb.queue);
312 /* Cleans up buffer - Usefull for testing for frame/URB loss */
313 outp = videobuf_to_vmalloc(&(*buf)->vb);
314 memset(outp, 0, (*buf)->vb.size);
317 dev->video_mode.isoc_ctl.buf = *buf;
319 dev->video_mode.bulk_ctl.buf = *buf;
325 * Controls the isoc copy of each urb packet
327 static inline int cx231xx_isoc_copy(struct cx231xx *dev, struct urb *urb)
329 struct cx231xx_buffer *buf;
330 struct cx231xx_dmaqueue *dma_q = urb->context;
331 unsigned char *outp = NULL;
333 unsigned char *p_buffer;
334 u32 bytes_parsed = 0, buffer_size = 0;
340 if ((dev->state & DEV_DISCONNECTED) || (dev->state & DEV_MISCONFIGURED))
343 if (urb->status < 0) {
344 print_err_status(dev, -1, urb->status);
345 if (urb->status == -ENOENT)
349 buf = dev->video_mode.isoc_ctl.buf;
351 outp = videobuf_to_vmalloc(&buf->vb);
353 for (i = 0; i < urb->number_of_packets; i++) {
354 int status = urb->iso_frame_desc[i].status;
357 print_err_status(dev, i, status);
358 if (urb->iso_frame_desc[i].status != -EPROTO)
362 if (urb->iso_frame_desc[i].actual_length <= 0) {
363 /* cx231xx_isocdbg("packet %d is empty",i); - spammy */
366 if (urb->iso_frame_desc[i].actual_length >
367 dev->video_mode.max_pkt_size) {
368 cx231xx_isocdbg("packet bigger than packet size");
372 /* get buffer pointer and length */
373 p_buffer = urb->transfer_buffer + urb->iso_frame_desc[i].offset;
374 buffer_size = urb->iso_frame_desc[i].actual_length;
377 if (dma_q->is_partial_line) {
378 /* Handle the case of a partial line */
379 sav_eav = dma_q->last_sav;
381 /* Check for a SAV/EAV overlapping
382 the buffer boundary */
384 cx231xx_find_boundary_SAV_EAV(p_buffer,
390 /* Get the first line if we have some portion of an SAV/EAV from
391 the last buffer or a partial line */
393 bytes_parsed += cx231xx_get_video_line(dev, dma_q,
394 sav_eav, /* SAV/EAV */
395 p_buffer + bytes_parsed, /* p_buffer */
396 buffer_size - bytes_parsed);/* buf size */
399 /* Now parse data that is completely in this buffer */
400 /* dma_q->is_partial_line = 0; */
402 while (bytes_parsed < buffer_size) {
405 sav_eav = cx231xx_find_next_SAV_EAV(
406 p_buffer + bytes_parsed, /* p_buffer */
407 buffer_size - bytes_parsed, /* buf size */
408 &bytes_used);/* bytes used to get SAV/EAV */
410 bytes_parsed += bytes_used;
413 if (sav_eav && (bytes_parsed < buffer_size)) {
414 bytes_parsed += cx231xx_get_video_line(dev,
415 dma_q, sav_eav, /* SAV/EAV */
416 p_buffer + bytes_parsed,/* p_buffer */
417 buffer_size - bytes_parsed);/*buf size*/
421 /* Save the last four bytes of the buffer so we can check the
422 buffer boundary condition next time */
423 memcpy(dma_q->partial_buf, p_buffer + buffer_size - 4, 4);
430 static inline int cx231xx_bulk_copy(struct cx231xx *dev, struct urb *urb)
432 struct cx231xx_buffer *buf;
433 struct cx231xx_dmaqueue *dma_q = urb->context;
434 unsigned char *outp = NULL;
436 unsigned char *p_buffer;
437 u32 bytes_parsed = 0, buffer_size = 0;
443 if ((dev->state & DEV_DISCONNECTED) || (dev->state & DEV_MISCONFIGURED))
446 if (urb->status < 0) {
447 print_err_status(dev, -1, urb->status);
448 if (urb->status == -ENOENT)
452 buf = dev->video_mode.bulk_ctl.buf;
454 outp = videobuf_to_vmalloc(&buf->vb);
458 /* get buffer pointer and length */
459 p_buffer = urb->transfer_buffer;
460 buffer_size = urb->actual_length;
463 if (dma_q->is_partial_line) {
464 /* Handle the case of a partial line */
465 sav_eav = dma_q->last_sav;
467 /* Check for a SAV/EAV overlapping
468 the buffer boundary */
470 cx231xx_find_boundary_SAV_EAV(p_buffer,
476 /* Get the first line if we have some portion of an SAV/EAV from
477 the last buffer or a partial line */
479 bytes_parsed += cx231xx_get_video_line(dev, dma_q,
480 sav_eav, /* SAV/EAV */
481 p_buffer + bytes_parsed, /* p_buffer */
482 buffer_size - bytes_parsed);/* buf size */
485 /* Now parse data that is completely in this buffer */
486 /* dma_q->is_partial_line = 0; */
488 while (bytes_parsed < buffer_size) {
491 sav_eav = cx231xx_find_next_SAV_EAV(
492 p_buffer + bytes_parsed, /* p_buffer */
493 buffer_size - bytes_parsed, /* buf size */
494 &bytes_used);/* bytes used to get SAV/EAV */
496 bytes_parsed += bytes_used;
499 if (sav_eav && (bytes_parsed < buffer_size)) {
500 bytes_parsed += cx231xx_get_video_line(dev,
501 dma_q, sav_eav, /* SAV/EAV */
502 p_buffer + bytes_parsed,/* p_buffer */
503 buffer_size - bytes_parsed);/*buf size*/
507 /* Save the last four bytes of the buffer so we can check the
508 buffer boundary condition next time */
509 memcpy(dma_q->partial_buf, p_buffer + buffer_size - 4, 4);
517 u8 cx231xx_find_boundary_SAV_EAV(u8 *p_buffer, u8 *partial_buf,
521 u8 boundary_bytes[8];
526 /* Create an array of the last 4 bytes of the last buffer and the first
527 4 bytes of the current buffer. */
529 memcpy(boundary_bytes, partial_buf, 4);
530 memcpy(boundary_bytes + 4, p_buffer, 4);
532 /* Check for the SAV/EAV in the boundary buffer */
533 sav_eav = cx231xx_find_next_SAV_EAV((u8 *)&boundary_bytes, 8,
537 /* found a boundary SAV/EAV. Updates the bytes used to reflect
538 only those used in the new buffer */
539 *p_bytes_used = bytes_used - 4;
545 u8 cx231xx_find_next_SAV_EAV(u8 *p_buffer, u32 buffer_size, u32 *p_bytes_used)
551 * Don't search if the buffer size is less than 4. It causes a page
552 * fault since buffer_size - 4 evaluates to a large number in that
555 if (buffer_size < 4) {
556 *p_bytes_used = buffer_size;
560 for (i = 0; i < (buffer_size - 3); i++) {
562 if ((p_buffer[i] == 0xFF) &&
563 (p_buffer[i + 1] == 0x00) && (p_buffer[i + 2] == 0x00)) {
565 *p_bytes_used = i + 4;
566 sav_eav = p_buffer[i + 3];
571 *p_bytes_used = buffer_size;
575 u32 cx231xx_get_video_line(struct cx231xx *dev,
576 struct cx231xx_dmaqueue *dma_q, u8 sav_eav,
577 u8 *p_buffer, u32 buffer_size)
579 u32 bytes_copied = 0;
580 int current_field = -1;
583 case SAV_ACTIVE_VIDEO_FIELD1:
584 /* looking for skipped line which occurred in PAL 720x480 mode.
585 In this case, there will be no active data contained
586 between the SAV and EAV */
587 if ((buffer_size > 3) && (p_buffer[0] == 0xFF) &&
588 (p_buffer[1] == 0x00) && (p_buffer[2] == 0x00) &&
589 ((p_buffer[3] == EAV_ACTIVE_VIDEO_FIELD1) ||
590 (p_buffer[3] == EAV_ACTIVE_VIDEO_FIELD2) ||
591 (p_buffer[3] == EAV_VBLANK_FIELD1) ||
592 (p_buffer[3] == EAV_VBLANK_FIELD2)))
597 case SAV_ACTIVE_VIDEO_FIELD2:
598 /* looking for skipped line which occurred in PAL 720x480 mode.
599 In this case, there will be no active data contained between
601 if ((buffer_size > 3) && (p_buffer[0] == 0xFF) &&
602 (p_buffer[1] == 0x00) && (p_buffer[2] == 0x00) &&
603 ((p_buffer[3] == EAV_ACTIVE_VIDEO_FIELD1) ||
604 (p_buffer[3] == EAV_ACTIVE_VIDEO_FIELD2) ||
605 (p_buffer[3] == EAV_VBLANK_FIELD1) ||
606 (p_buffer[3] == EAV_VBLANK_FIELD2)))
612 dma_q->last_sav = sav_eav;
614 bytes_copied = cx231xx_copy_video_line(dev, dma_q, p_buffer,
615 buffer_size, current_field);
620 u32 cx231xx_copy_video_line(struct cx231xx *dev,
621 struct cx231xx_dmaqueue *dma_q, u8 *p_line,
622 u32 length, int field_number)
625 struct cx231xx_buffer *buf;
626 u32 _line_size = dev->width * 2;
628 if (dma_q->current_field != field_number)
629 cx231xx_reset_video_buffer(dev, dma_q);
631 /* get the buffer pointer */
633 buf = dev->video_mode.isoc_ctl.buf;
635 buf = dev->video_mode.bulk_ctl.buf;
637 /* Remember the field number for next time */
638 dma_q->current_field = field_number;
640 bytes_to_copy = dma_q->bytes_left_in_line;
641 if (bytes_to_copy > length)
642 bytes_to_copy = length;
644 if (dma_q->lines_completed >= dma_q->lines_per_field) {
645 dma_q->bytes_left_in_line -= bytes_to_copy;
646 dma_q->is_partial_line = (dma_q->bytes_left_in_line == 0) ?
651 dma_q->is_partial_line = 1;
653 /* If we don't have a buffer, just return the number of bytes we would
654 have copied if we had a buffer. */
656 dma_q->bytes_left_in_line -= bytes_to_copy;
657 dma_q->is_partial_line = (dma_q->bytes_left_in_line == 0)
659 return bytes_to_copy;
662 /* copy the data to video buffer */
663 cx231xx_do_copy(dev, dma_q, p_line, bytes_to_copy);
665 dma_q->pos += bytes_to_copy;
666 dma_q->bytes_left_in_line -= bytes_to_copy;
668 if (dma_q->bytes_left_in_line == 0) {
669 dma_q->bytes_left_in_line = _line_size;
670 dma_q->lines_completed++;
671 dma_q->is_partial_line = 0;
673 if (cx231xx_is_buffer_done(dev, dma_q) && buf) {
674 buffer_filled(dev, dma_q, buf);
678 dma_q->lines_completed = 0;
682 return bytes_to_copy;
685 void cx231xx_reset_video_buffer(struct cx231xx *dev,
686 struct cx231xx_dmaqueue *dma_q)
688 struct cx231xx_buffer *buf;
690 /* handle the switch from field 1 to field 2 */
691 if (dma_q->current_field == 1) {
692 if (dma_q->lines_completed >= dma_q->lines_per_field)
693 dma_q->field1_done = 1;
695 dma_q->field1_done = 0;
699 buf = dev->video_mode.isoc_ctl.buf;
701 buf = dev->video_mode.bulk_ctl.buf;
705 /* first try to get the buffer */
706 get_next_buf(dma_q, &buf);
709 outp = videobuf_to_vmalloc(&buf->vb);
712 dma_q->field1_done = 0;
713 dma_q->current_field = -1;
716 /* reset the counters */
717 dma_q->bytes_left_in_line = dev->width << 1;
718 dma_q->lines_completed = 0;
721 int cx231xx_do_copy(struct cx231xx *dev, struct cx231xx_dmaqueue *dma_q,
722 u8 *p_buffer, u32 bytes_to_copy)
724 u8 *p_out_buffer = NULL;
725 u32 current_line_bytes_copied = 0;
726 struct cx231xx_buffer *buf;
727 u32 _line_size = dev->width << 1;
732 buf = dev->video_mode.isoc_ctl.buf;
734 buf = dev->video_mode.bulk_ctl.buf;
739 p_out_buffer = videobuf_to_vmalloc(&buf->vb);
741 current_line_bytes_copied = _line_size - dma_q->bytes_left_in_line;
743 /* Offset field 2 one line from the top of the buffer */
744 offset = (dma_q->current_field == 1) ? 0 : _line_size;
746 /* Offset for field 2 */
747 startwrite = p_out_buffer + offset;
749 /* lines already completed in the current field */
750 startwrite += (dma_q->lines_completed * _line_size * 2);
752 /* bytes already completed in the current line */
753 startwrite += current_line_bytes_copied;
755 lencopy = dma_q->bytes_left_in_line > bytes_to_copy ?
756 bytes_to_copy : dma_q->bytes_left_in_line;
758 if ((u8 *)(startwrite + lencopy) > (u8 *)(p_out_buffer + buf->vb.size))
761 /* The below copies the UYVY data straight into video buffer */
762 cx231xx_swab((u16 *) p_buffer, (u16 *) startwrite, (u16) lencopy);
767 void cx231xx_swab(u16 *from, u16 *to, u16 len)
774 for (i = 0; i < len / 2; i++)
775 to[i] = (from[i] << 8) | (from[i] >> 8);
778 u8 cx231xx_is_buffer_done(struct cx231xx *dev, struct cx231xx_dmaqueue *dma_q)
780 u8 buffer_complete = 0;
782 /* Dual field stream */
783 buffer_complete = ((dma_q->current_field == 2) &&
784 (dma_q->lines_completed >= dma_q->lines_per_field) &&
787 return buffer_complete;
790 /* ------------------------------------------------------------------
792 ------------------------------------------------------------------*/
795 buffer_setup(struct videobuf_queue *vq, unsigned int *count, unsigned int *size)
797 struct cx231xx_fh *fh = vq->priv_data;
798 struct cx231xx *dev = fh->dev;
800 *size = (fh->dev->width * fh->dev->height * dev->format->depth + 7)>>3;
802 *count = CX231XX_DEF_BUF;
804 if (*count < CX231XX_MIN_BUF)
805 *count = CX231XX_MIN_BUF;
810 /* This is called *without* dev->slock held; please keep it that way */
811 static void free_buffer(struct videobuf_queue *vq, struct cx231xx_buffer *buf)
813 struct cx231xx_fh *fh = vq->priv_data;
814 struct cx231xx *dev = fh->dev;
815 unsigned long flags = 0;
820 /* We used to wait for the buffer to finish here, but this didn't work
821 because, as we were keeping the state as VIDEOBUF_QUEUED,
822 videobuf_queue_cancel marked it as finished for us.
823 (Also, it could wedge forever if the hardware was misconfigured.)
825 This should be safe; by the time we get here, the buffer isn't
826 queued anymore. If we ever start marking the buffers as
827 VIDEOBUF_ACTIVE, it won't be, though.
829 spin_lock_irqsave(&dev->video_mode.slock, flags);
831 if (dev->video_mode.isoc_ctl.buf == buf)
832 dev->video_mode.isoc_ctl.buf = NULL;
834 if (dev->video_mode.bulk_ctl.buf == buf)
835 dev->video_mode.bulk_ctl.buf = NULL;
837 spin_unlock_irqrestore(&dev->video_mode.slock, flags);
839 videobuf_vmalloc_free(&buf->vb);
840 buf->vb.state = VIDEOBUF_NEEDS_INIT;
844 buffer_prepare(struct videobuf_queue *vq, struct videobuf_buffer *vb,
845 enum v4l2_field field)
847 struct cx231xx_fh *fh = vq->priv_data;
848 struct cx231xx_buffer *buf =
849 container_of(vb, struct cx231xx_buffer, vb);
850 struct cx231xx *dev = fh->dev;
851 int rc = 0, urb_init = 0;
853 /* The only currently supported format is 16 bits/pixel */
854 buf->vb.size = (fh->dev->width * fh->dev->height * dev->format->depth
856 if (0 != buf->vb.baddr && buf->vb.bsize < buf->vb.size)
859 buf->vb.width = dev->width;
860 buf->vb.height = dev->height;
861 buf->vb.field = field;
863 if (VIDEOBUF_NEEDS_INIT == buf->vb.state) {
864 rc = videobuf_iolock(vq, &buf->vb, NULL);
870 if (!dev->video_mode.isoc_ctl.num_bufs)
873 if (!dev->video_mode.bulk_ctl.num_bufs)
876 /*cx231xx_info("urb_init=%d dev->video_mode.max_pkt_size=%d\n",
877 urb_init, dev->video_mode.max_pkt_size);*/
881 rc = cx231xx_init_isoc(dev, CX231XX_NUM_PACKETS,
883 dev->video_mode.max_pkt_size,
886 rc = cx231xx_init_bulk(dev, CX231XX_NUM_PACKETS,
888 dev->video_mode.max_pkt_size,
894 buf->vb.state = VIDEOBUF_PREPARED;
898 free_buffer(vq, buf);
902 static void buffer_queue(struct videobuf_queue *vq, struct videobuf_buffer *vb)
904 struct cx231xx_buffer *buf =
905 container_of(vb, struct cx231xx_buffer, vb);
906 struct cx231xx_fh *fh = vq->priv_data;
907 struct cx231xx *dev = fh->dev;
908 struct cx231xx_dmaqueue *vidq = &dev->video_mode.vidq;
910 buf->vb.state = VIDEOBUF_QUEUED;
911 list_add_tail(&buf->vb.queue, &vidq->active);
915 static void buffer_release(struct videobuf_queue *vq,
916 struct videobuf_buffer *vb)
918 struct cx231xx_buffer *buf =
919 container_of(vb, struct cx231xx_buffer, vb);
920 struct cx231xx_fh *fh = vq->priv_data;
921 struct cx231xx *dev = (struct cx231xx *)fh->dev;
923 cx231xx_isocdbg("cx231xx: called buffer_release\n");
925 free_buffer(vq, buf);
928 static struct videobuf_queue_ops cx231xx_video_qops = {
929 .buf_setup = buffer_setup,
930 .buf_prepare = buffer_prepare,
931 .buf_queue = buffer_queue,
932 .buf_release = buffer_release,
935 /********************* v4l2 interface **************************************/
937 void video_mux(struct cx231xx *dev, int index)
939 dev->video_input = index;
940 dev->ctl_ainput = INPUT(index)->amux;
942 cx231xx_set_video_input_mux(dev, index);
944 cx25840_call(dev, video, s_routing, INPUT(index)->vmux, 0, 0);
946 cx231xx_set_audio_input(dev, dev->ctl_ainput);
948 cx231xx_info("video_mux : %d\n", index);
950 /* do mode control overrides if required */
951 cx231xx_do_mode_ctrl_overrides(dev);
954 /* Usage lock check functions */
955 static int res_get(struct cx231xx_fh *fh)
957 struct cx231xx *dev = fh->dev;
960 /* This instance already has stream_on */
964 if (fh->type == V4L2_BUF_TYPE_VIDEO_CAPTURE) {
968 } else if (fh->type == V4L2_BUF_TYPE_VBI_CAPTURE) {
969 if (dev->vbi_stream_on)
971 dev->vbi_stream_on = 1;
980 static int res_check(struct cx231xx_fh *fh)
982 return fh->stream_on;
985 static void res_free(struct cx231xx_fh *fh)
987 struct cx231xx *dev = fh->dev;
991 if (fh->type == V4L2_BUF_TYPE_VIDEO_CAPTURE)
993 if (fh->type == V4L2_BUF_TYPE_VBI_CAPTURE)
994 dev->vbi_stream_on = 0;
997 static int check_dev(struct cx231xx *dev)
999 if (dev->state & DEV_DISCONNECTED) {
1000 cx231xx_errdev("v4l2 ioctl: device not present\n");
1004 if (dev->state & DEV_MISCONFIGURED) {
1005 cx231xx_errdev("v4l2 ioctl: device is misconfigured; "
1006 "close and open it again\n");
1012 /* ------------------------------------------------------------------
1013 IOCTL vidioc handling
1014 ------------------------------------------------------------------*/
1016 static int vidioc_g_fmt_vid_cap(struct file *file, void *priv,
1017 struct v4l2_format *f)
1019 struct cx231xx_fh *fh = priv;
1020 struct cx231xx *dev = fh->dev;
1022 f->fmt.pix.width = dev->width;
1023 f->fmt.pix.height = dev->height;
1024 f->fmt.pix.pixelformat = dev->format->fourcc;
1025 f->fmt.pix.bytesperline = (dev->width * dev->format->depth + 7) >> 3;
1026 f->fmt.pix.sizeimage = f->fmt.pix.bytesperline * dev->height;
1027 f->fmt.pix.colorspace = V4L2_COLORSPACE_SMPTE170M;
1029 f->fmt.pix.field = V4L2_FIELD_INTERLACED;
1034 static struct cx231xx_fmt *format_by_fourcc(unsigned int fourcc)
1038 for (i = 0; i < ARRAY_SIZE(format); i++)
1039 if (format[i].fourcc == fourcc)
1045 static int vidioc_try_fmt_vid_cap(struct file *file, void *priv,
1046 struct v4l2_format *f)
1048 struct cx231xx_fh *fh = priv;
1049 struct cx231xx *dev = fh->dev;
1050 unsigned int width = f->fmt.pix.width;
1051 unsigned int height = f->fmt.pix.height;
1052 unsigned int maxw = norm_maxw(dev);
1053 unsigned int maxh = norm_maxh(dev);
1054 struct cx231xx_fmt *fmt;
1056 fmt = format_by_fourcc(f->fmt.pix.pixelformat);
1058 cx231xx_videodbg("Fourcc format (%08x) invalid.\n",
1059 f->fmt.pix.pixelformat);
1063 /* width must even because of the YUYV format
1064 height must be even because of interlacing */
1065 v4l_bound_align_image(&width, 48, maxw, 1, &height, 32, maxh, 1, 0);
1067 f->fmt.pix.width = width;
1068 f->fmt.pix.height = height;
1069 f->fmt.pix.pixelformat = fmt->fourcc;
1070 f->fmt.pix.bytesperline = (dev->width * fmt->depth + 7) >> 3;
1071 f->fmt.pix.sizeimage = f->fmt.pix.bytesperline * height;
1072 f->fmt.pix.colorspace = V4L2_COLORSPACE_SMPTE170M;
1073 f->fmt.pix.field = V4L2_FIELD_INTERLACED;
1078 static int vidioc_s_fmt_vid_cap(struct file *file, void *priv,
1079 struct v4l2_format *f)
1081 struct cx231xx_fh *fh = priv;
1082 struct cx231xx *dev = fh->dev;
1084 struct cx231xx_fmt *fmt;
1085 struct v4l2_mbus_framefmt mbus_fmt;
1087 rc = check_dev(dev);
1091 vidioc_try_fmt_vid_cap(file, priv, f);
1093 fmt = format_by_fourcc(f->fmt.pix.pixelformat);
1097 if (videobuf_queue_is_busy(&fh->vb_vidq)) {
1098 cx231xx_errdev("%s queue busy\n", __func__);
1102 if (dev->stream_on && !fh->stream_on) {
1103 cx231xx_errdev("%s device in use by another fh\n", __func__);
1107 /* set new image size */
1108 dev->width = f->fmt.pix.width;
1109 dev->height = f->fmt.pix.height;
1112 v4l2_fill_mbus_format(&mbus_fmt, &f->fmt.pix, V4L2_MBUS_FMT_FIXED);
1113 call_all(dev, video, s_mbus_fmt, &mbus_fmt);
1114 v4l2_fill_pix_format(&f->fmt.pix, &mbus_fmt);
1119 static int vidioc_g_std(struct file *file, void *priv, v4l2_std_id *id)
1121 struct cx231xx_fh *fh = priv;
1122 struct cx231xx *dev = fh->dev;
1128 static int vidioc_s_std(struct file *file, void *priv, v4l2_std_id *norm)
1130 struct cx231xx_fh *fh = priv;
1131 struct cx231xx *dev = fh->dev;
1132 struct v4l2_mbus_framefmt mbus_fmt;
1133 struct v4l2_format f;
1136 rc = check_dev(dev);
1140 cx231xx_info("vidioc_s_std : 0x%x\n", (unsigned int)*norm);
1144 /* Adjusts width/height, if needed */
1145 f.fmt.pix.width = dev->width;
1146 f.fmt.pix.height = dev->height;
1147 vidioc_try_fmt_vid_cap(file, priv, &f);
1149 call_all(dev, core, s_std, dev->norm);
1151 /* We need to reset basic properties in the decoder related to
1152 resolution (since a standard change effects things like the number
1153 of lines in VACT, etc) */
1154 v4l2_fill_mbus_format(&mbus_fmt, &f.fmt.pix, V4L2_MBUS_FMT_FIXED);
1155 call_all(dev, video, s_mbus_fmt, &mbus_fmt);
1156 v4l2_fill_pix_format(&f.fmt.pix, &mbus_fmt);
1158 /* set new image size */
1159 dev->width = f.fmt.pix.width;
1160 dev->height = f.fmt.pix.height;
1162 /* do mode control overrides */
1163 cx231xx_do_mode_ctrl_overrides(dev);
1168 static const char *iname[] = {
1169 [CX231XX_VMUX_COMPOSITE1] = "Composite1",
1170 [CX231XX_VMUX_SVIDEO] = "S-Video",
1171 [CX231XX_VMUX_TELEVISION] = "Television",
1172 [CX231XX_VMUX_CABLE] = "Cable TV",
1173 [CX231XX_VMUX_DVB] = "DVB",
1174 [CX231XX_VMUX_DEBUG] = "for debug only",
1177 static int vidioc_enum_input(struct file *file, void *priv,
1178 struct v4l2_input *i)
1180 struct cx231xx_fh *fh = priv;
1181 struct cx231xx *dev = fh->dev;
1185 if (n >= MAX_CX231XX_INPUT)
1187 if (0 == INPUT(n)->type)
1191 i->type = V4L2_INPUT_TYPE_CAMERA;
1193 strcpy(i->name, iname[INPUT(n)->type]);
1195 if ((CX231XX_VMUX_TELEVISION == INPUT(n)->type) ||
1196 (CX231XX_VMUX_CABLE == INPUT(n)->type))
1197 i->type = V4L2_INPUT_TYPE_TUNER;
1199 i->std = dev->vdev->tvnorms;
1204 static int vidioc_g_input(struct file *file, void *priv, unsigned int *i)
1206 struct cx231xx_fh *fh = priv;
1207 struct cx231xx *dev = fh->dev;
1209 *i = dev->video_input;
1214 static int vidioc_s_input(struct file *file, void *priv, unsigned int i)
1216 struct cx231xx_fh *fh = priv;
1217 struct cx231xx *dev = fh->dev;
1221 rc = check_dev(dev);
1225 if (i >= MAX_CX231XX_INPUT)
1227 if (0 == INPUT(i)->type)
1232 if (INPUT(i)->type == CX231XX_VMUX_TELEVISION ||
1233 INPUT(i)->type == CX231XX_VMUX_CABLE) {
1234 /* There's a tuner, so reset the standard and put it on the
1235 last known frequency (since it was probably powered down
1237 call_all(dev, core, s_std, dev->norm);
1243 static int vidioc_g_audio(struct file *file, void *priv, struct v4l2_audio *a)
1245 struct cx231xx_fh *fh = priv;
1246 struct cx231xx *dev = fh->dev;
1249 case CX231XX_AMUX_VIDEO:
1250 strcpy(a->name, "Television");
1252 case CX231XX_AMUX_LINE_IN:
1253 strcpy(a->name, "Line In");
1259 a->index = dev->ctl_ainput;
1260 a->capability = V4L2_AUDCAP_STEREO;
1265 static int vidioc_s_audio(struct file *file, void *priv, struct v4l2_audio *a)
1267 struct cx231xx_fh *fh = priv;
1268 struct cx231xx *dev = fh->dev;
1271 /* Doesn't allow manual routing */
1272 if (a->index != dev->ctl_ainput)
1275 dev->ctl_ainput = INPUT(a->index)->amux;
1276 status = cx231xx_set_audio_input(dev, dev->ctl_ainput);
1281 static int vidioc_queryctrl(struct file *file, void *priv,
1282 struct v4l2_queryctrl *qc)
1284 struct cx231xx_fh *fh = priv;
1285 struct cx231xx *dev = fh->dev;
1290 rc = check_dev(dev);
1294 qc->id = v4l2_ctrl_next(ctrl_classes, qc->id);
1295 if (unlikely(qc->id == 0))
1298 memset(qc, 0, sizeof(*qc));
1302 if (qc->id < V4L2_CID_BASE || qc->id >= V4L2_CID_LASTP1)
1305 for (i = 0; i < CX231XX_CTLS; i++)
1306 if (cx231xx_ctls[i].v.id == qc->id)
1309 if (i == CX231XX_CTLS) {
1313 *qc = cx231xx_ctls[i].v;
1315 call_all(dev, core, queryctrl, qc);
1323 static int vidioc_g_ctrl(struct file *file, void *priv,
1324 struct v4l2_control *ctrl)
1326 struct cx231xx_fh *fh = priv;
1327 struct cx231xx *dev = fh->dev;
1330 rc = check_dev(dev);
1334 call_all(dev, core, g_ctrl, ctrl);
1338 static int vidioc_s_ctrl(struct file *file, void *priv,
1339 struct v4l2_control *ctrl)
1341 struct cx231xx_fh *fh = priv;
1342 struct cx231xx *dev = fh->dev;
1345 rc = check_dev(dev);
1349 call_all(dev, core, s_ctrl, ctrl);
1353 static int vidioc_g_tuner(struct file *file, void *priv, struct v4l2_tuner *t)
1355 struct cx231xx_fh *fh = priv;
1356 struct cx231xx *dev = fh->dev;
1359 rc = check_dev(dev);
1366 strcpy(t->name, "Tuner");
1368 t->type = V4L2_TUNER_ANALOG_TV;
1369 t->capability = V4L2_TUNER_CAP_NORM;
1370 t->rangehigh = 0xffffffffUL;
1371 t->signal = 0xffff; /* LOCKED */
1376 static int vidioc_s_tuner(struct file *file, void *priv, struct v4l2_tuner *t)
1378 struct cx231xx_fh *fh = priv;
1379 struct cx231xx *dev = fh->dev;
1382 rc = check_dev(dev);
1389 call_all(dev, tuner, s_tuner, t);
1394 static int vidioc_g_frequency(struct file *file, void *priv,
1395 struct v4l2_frequency *f)
1397 struct cx231xx_fh *fh = priv;
1398 struct cx231xx *dev = fh->dev;
1400 f->type = fh->radio ? V4L2_TUNER_RADIO : V4L2_TUNER_ANALOG_TV;
1401 f->frequency = dev->ctl_freq;
1403 call_all(dev, tuner, g_frequency, f);
1408 static int vidioc_s_frequency(struct file *file, void *priv,
1409 struct v4l2_frequency *f)
1411 struct cx231xx_fh *fh = priv;
1412 struct cx231xx *dev = fh->dev;
1414 u32 if_frequency = 5400000;
1416 cx231xx_info("Enter vidioc_s_frequency()f->frequency=%d;f->type=%d\n",
1417 f->frequency, f->type);
1418 /*cx231xx_info("f->type: 1-radio 2-analogTV 3-digitalTV\n");*/
1420 rc = check_dev(dev);
1427 if (unlikely(0 == fh->radio && f->type != V4L2_TUNER_ANALOG_TV))
1429 if (unlikely(1 == fh->radio && f->type != V4L2_TUNER_RADIO))
1432 /* set pre channel change settings in DIF first */
1433 rc = cx231xx_tuner_pre_channel_change(dev);
1435 dev->ctl_freq = f->frequency;
1436 call_all(dev, tuner, s_frequency, f);
1438 /* set post channel change settings in DIF first */
1439 rc = cx231xx_tuner_post_channel_change(dev);
1441 if (dev->tuner_type == TUNER_NXP_TDA18271) {
1442 if (dev->norm & (V4L2_STD_MN | V4L2_STD_NTSC_443))
1443 if_frequency = 5400000; /*5.4MHz */
1444 else if (dev->norm & V4L2_STD_B)
1445 if_frequency = 6000000; /*6.0MHz */
1446 else if (dev->norm & (V4L2_STD_PAL_DK | V4L2_STD_SECAM_DK))
1447 if_frequency = 6900000; /*6.9MHz */
1448 else if (dev->norm & V4L2_STD_GH)
1449 if_frequency = 7100000; /*7.1MHz */
1450 else if (dev->norm & V4L2_STD_PAL_I)
1451 if_frequency = 7250000; /*7.25MHz */
1452 else if (dev->norm & V4L2_STD_SECAM_L)
1453 if_frequency = 6900000; /*6.9MHz */
1454 else if (dev->norm & V4L2_STD_SECAM_LC)
1455 if_frequency = 1250000; /*1.25MHz */
1457 cx231xx_info("if_frequency is set to %d\n", if_frequency);
1458 cx231xx_set_Colibri_For_LowIF(dev, if_frequency, 1, 1);
1460 update_HH_register_after_set_DIF(dev);
1463 cx231xx_info("Set New FREQUENCY to %d\n", f->frequency);
1468 #ifdef CONFIG_VIDEO_ADV_DEBUG
1471 -R, --list-registers=type=<host/i2cdrv/i2caddr>,
1472 chip=<chip>[,min=<addr>,max=<addr>]
1473 dump registers from <min> to <max> [VIDIOC_DBG_G_REGISTER]
1474 -r, --set-register=type=<host/i2cdrv/i2caddr>,
1475 chip=<chip>,reg=<addr>,val=<val>
1476 set the register [VIDIOC_DBG_S_REGISTER]
1478 if type == host, then <chip> is the hosts chip ID (default 0)
1479 if type == i2cdrv (default), then <chip> is the I2C driver name or ID
1480 if type == i2caddr, then <chip> is the 7-bit I2C address
1483 static int vidioc_g_register(struct file *file, void *priv,
1484 struct v4l2_dbg_register *reg)
1486 struct cx231xx_fh *fh = priv;
1487 struct cx231xx *dev = fh->dev;
1489 u8 value[4] = { 0, 0, 0, 0 };
1492 switch (reg->match.type) {
1493 case V4L2_CHIP_MATCH_HOST:
1494 switch (reg->match.addr) {
1495 case 0: /* Cx231xx - internal registers */
1496 ret = cx231xx_read_ctrl_reg(dev, VRT_GET_REGISTER,
1497 (u16)reg->reg, value, 4);
1498 reg->val = value[0] | value[1] << 8 |
1499 value[2] << 16 | value[3] << 24;
1501 case 1: /* AFE - read byte */
1502 ret = cx231xx_read_i2c_data(dev, AFE_DEVICE_ADDRESS,
1503 (u16)reg->reg, 2, &data, 1);
1504 reg->val = le32_to_cpu(data & 0xff);
1506 case 14: /* AFE - read dword */
1507 ret = cx231xx_read_i2c_data(dev, AFE_DEVICE_ADDRESS,
1508 (u16)reg->reg, 2, &data, 4);
1509 reg->val = le32_to_cpu(data);
1511 case 2: /* Video Block - read byte */
1512 ret = cx231xx_read_i2c_data(dev, VID_BLK_I2C_ADDRESS,
1513 (u16)reg->reg, 2, &data, 1);
1514 reg->val = le32_to_cpu(data & 0xff);
1516 case 24: /* Video Block - read dword */
1517 ret = cx231xx_read_i2c_data(dev, VID_BLK_I2C_ADDRESS,
1518 (u16)reg->reg, 2, &data, 4);
1519 reg->val = le32_to_cpu(data);
1521 case 3: /* I2S block - read byte */
1522 ret = cx231xx_read_i2c_data(dev,
1523 I2S_BLK_DEVICE_ADDRESS,
1526 reg->val = le32_to_cpu(data & 0xff);
1528 case 34: /* I2S Block - read dword */
1530 cx231xx_read_i2c_data(dev, I2S_BLK_DEVICE_ADDRESS,
1531 (u16)reg->reg, 1, &data, 4);
1532 reg->val = le32_to_cpu(data);
1535 return ret < 0 ? ret : 0;
1537 case V4L2_CHIP_MATCH_I2C_DRIVER:
1538 call_all(dev, core, g_register, reg);
1540 case V4L2_CHIP_MATCH_I2C_ADDR:/*for register debug*/
1541 switch (reg->match.addr) {
1542 case 0: /* Cx231xx - internal registers */
1543 ret = cx231xx_read_ctrl_reg(dev, VRT_GET_REGISTER,
1544 (u16)reg->reg, value, 4);
1545 reg->val = value[0] | value[1] << 8 |
1546 value[2] << 16 | value[3] << 24;
1549 case 0x600:/* AFE - read byte */
1550 ret = cx231xx_read_i2c_master(dev, AFE_DEVICE_ADDRESS,
1553 reg->val = le32_to_cpu(data & 0xff);
1556 case 0x880:/* Video Block - read byte */
1557 if (reg->reg < 0x0b) {
1558 ret = cx231xx_read_i2c_master(dev,
1559 VID_BLK_I2C_ADDRESS,
1562 reg->val = le32_to_cpu(data & 0xff);
1564 ret = cx231xx_read_i2c_master(dev,
1565 VID_BLK_I2C_ADDRESS,
1568 reg->val = le32_to_cpu(data);
1572 ret = cx231xx_read_i2c_master(dev,
1573 I2S_BLK_DEVICE_ADDRESS,
1576 reg->val = le32_to_cpu(data & 0xff);
1580 cx231xx_read_i2c_master(dev, 0x40,
1583 reg->val = le32_to_cpu(data & 0xff);
1587 cx231xx_read_i2c_master(dev, 0xc0,
1590 reg->val = le32_to_cpu(data);
1594 cx231xx_read_i2c_master(dev, 0x02,
1597 reg->val = le32_to_cpu(data & 0xff);
1600 ret = cx231xx_read_i2c_master(dev,
1604 reg->val = le32_to_cpu(data);
1607 ret = cx231xx_read_i2c_master(dev,
1611 reg->val = le32_to_cpu(data);
1615 cx231xx_info("no match device address!!\n");
1618 return ret < 0 ? ret : 0;
1621 if (!v4l2_chip_match_host(®->match))
1625 call_all(dev, core, g_register, reg);
1630 static int vidioc_s_register(struct file *file, void *priv,
1631 struct v4l2_dbg_register *reg)
1633 struct cx231xx_fh *fh = priv;
1634 struct cx231xx *dev = fh->dev;
1638 u8 data[4] = { 0, 0, 0, 0 };
1640 buf = cpu_to_le64(reg->val);
1642 switch (reg->match.type) {
1643 case V4L2_CHIP_MATCH_HOST:
1645 value = (u32) buf & 0xffffffff;
1647 switch (reg->match.addr) {
1648 case 0: /* cx231xx internal registers */
1649 data[0] = (u8) value;
1650 data[1] = (u8) (value >> 8);
1651 data[2] = (u8) (value >> 16);
1652 data[3] = (u8) (value >> 24);
1653 ret = cx231xx_write_ctrl_reg(dev,
1655 (u16)reg->reg, data,
1658 case 1: /* AFE - read byte */
1659 ret = cx231xx_write_i2c_data(dev,
1664 case 14: /* AFE - read dword */
1665 ret = cx231xx_write_i2c_data(dev,
1670 case 2: /* Video Block - read byte */
1672 cx231xx_write_i2c_data(dev,
1673 VID_BLK_I2C_ADDRESS,
1677 case 24: /* Video Block - read dword */
1679 cx231xx_write_i2c_data(dev,
1680 VID_BLK_I2C_ADDRESS,
1684 case 3: /* I2S block - read byte */
1686 cx231xx_write_i2c_data(dev,
1687 I2S_BLK_DEVICE_ADDRESS,
1691 case 34: /* I2S block - read dword */
1693 cx231xx_write_i2c_data(dev,
1694 I2S_BLK_DEVICE_ADDRESS,
1700 return ret < 0 ? ret : 0;
1701 case V4L2_CHIP_MATCH_I2C_ADDR:
1703 value = (u32) buf & 0xffffffff;
1705 switch (reg->match.addr) {
1706 case 0:/*cx231xx internal registers*/
1707 data[0] = (u8) value;
1708 data[1] = (u8) (value >> 8);
1709 data[2] = (u8) (value >> 16);
1710 data[3] = (u8) (value >> 24);
1711 ret = cx231xx_write_ctrl_reg(dev,
1713 (u16)reg->reg, data,
1716 case 0x600:/* AFE - read byte */
1717 ret = cx231xx_write_i2c_master(dev,
1723 case 0x880:/* Video Block - read byte */
1724 if (reg->reg < 0x0b)
1725 cx231xx_write_i2c_master(dev,
1726 VID_BLK_I2C_ADDRESS,
1730 cx231xx_write_i2c_master(dev,
1731 VID_BLK_I2C_ADDRESS,
1737 cx231xx_write_i2c_master(dev,
1738 I2S_BLK_DEVICE_ADDRESS,
1744 cx231xx_write_i2c_master(dev,
1751 cx231xx_write_i2c_master(dev,
1759 cx231xx_write_i2c_master(dev,
1765 cx231xx_write_i2c_master(dev,
1773 cx231xx_write_i2c_master(dev,
1779 cx231xx_info("no match device address, "
1780 "the value is %x\n", reg->match.addr);
1790 call_all(dev, core, s_register, reg);
1796 static int vidioc_cropcap(struct file *file, void *priv,
1797 struct v4l2_cropcap *cc)
1799 struct cx231xx_fh *fh = priv;
1800 struct cx231xx *dev = fh->dev;
1802 if (cc->type != V4L2_BUF_TYPE_VIDEO_CAPTURE)
1805 cc->bounds.left = 0;
1807 cc->bounds.width = dev->width;
1808 cc->bounds.height = dev->height;
1809 cc->defrect = cc->bounds;
1810 cc->pixelaspect.numerator = 54; /* 4:3 FIXME: remove magic numbers */
1811 cc->pixelaspect.denominator = 59;
1816 static int vidioc_streamon(struct file *file, void *priv,
1817 enum v4l2_buf_type type)
1819 struct cx231xx_fh *fh = priv;
1820 struct cx231xx *dev = fh->dev;
1823 rc = check_dev(dev);
1829 if (likely(rc >= 0))
1830 rc = videobuf_streamon(&fh->vb_vidq);
1832 call_all(dev, video, s_stream, 1);
1837 static int vidioc_streamoff(struct file *file, void *priv,
1838 enum v4l2_buf_type type)
1840 struct cx231xx_fh *fh = priv;
1841 struct cx231xx *dev = fh->dev;
1844 rc = check_dev(dev);
1848 if ((fh->type != V4L2_BUF_TYPE_VIDEO_CAPTURE) &&
1849 (fh->type != V4L2_BUF_TYPE_VBI_CAPTURE))
1851 if (type != fh->type)
1854 cx25840_call(dev, video, s_stream, 0);
1856 videobuf_streamoff(&fh->vb_vidq);
1862 static int vidioc_querycap(struct file *file, void *priv,
1863 struct v4l2_capability *cap)
1865 struct cx231xx_fh *fh = priv;
1866 struct cx231xx *dev = fh->dev;
1868 strlcpy(cap->driver, "cx231xx", sizeof(cap->driver));
1869 strlcpy(cap->card, cx231xx_boards[dev->model].name, sizeof(cap->card));
1870 usb_make_path(dev->udev, cap->bus_info, sizeof(cap->bus_info));
1872 cap->version = CX231XX_VERSION_CODE;
1874 cap->capabilities = V4L2_CAP_VBI_CAPTURE |
1876 V4L2_CAP_SLICED_VBI_CAPTURE |
1878 V4L2_CAP_VIDEO_CAPTURE |
1880 V4L2_CAP_READWRITE |
1883 if (dev->tuner_type != TUNER_ABSENT)
1884 cap->capabilities |= V4L2_CAP_TUNER;
1889 static int vidioc_enum_fmt_vid_cap(struct file *file, void *priv,
1890 struct v4l2_fmtdesc *f)
1892 if (unlikely(f->index >= ARRAY_SIZE(format)))
1895 strlcpy(f->description, format[f->index].name, sizeof(f->description));
1896 f->pixelformat = format[f->index].fourcc;
1901 /* Sliced VBI ioctls */
1902 static int vidioc_g_fmt_sliced_vbi_cap(struct file *file, void *priv,
1903 struct v4l2_format *f)
1905 struct cx231xx_fh *fh = priv;
1906 struct cx231xx *dev = fh->dev;
1909 rc = check_dev(dev);
1913 f->fmt.sliced.service_set = 0;
1915 call_all(dev, vbi, g_sliced_fmt, &f->fmt.sliced);
1917 if (f->fmt.sliced.service_set == 0)
1923 static int vidioc_try_set_sliced_vbi_cap(struct file *file, void *priv,
1924 struct v4l2_format *f)
1926 struct cx231xx_fh *fh = priv;
1927 struct cx231xx *dev = fh->dev;
1930 rc = check_dev(dev);
1934 call_all(dev, vbi, g_sliced_fmt, &f->fmt.sliced);
1936 if (f->fmt.sliced.service_set == 0)
1942 /* RAW VBI ioctls */
1944 static int vidioc_g_fmt_vbi_cap(struct file *file, void *priv,
1945 struct v4l2_format *f)
1947 struct cx231xx_fh *fh = priv;
1948 struct cx231xx *dev = fh->dev;
1949 f->fmt.vbi.sampling_rate = 6750000 * 4;
1950 f->fmt.vbi.samples_per_line = VBI_LINE_LENGTH;
1951 f->fmt.vbi.sample_format = V4L2_PIX_FMT_GREY;
1952 f->fmt.vbi.offset = 0;
1953 f->fmt.vbi.start[0] = (dev->norm & V4L2_STD_625_50) ?
1954 PAL_VBI_START_LINE : NTSC_VBI_START_LINE;
1955 f->fmt.vbi.count[0] = (dev->norm & V4L2_STD_625_50) ?
1956 PAL_VBI_LINES : NTSC_VBI_LINES;
1957 f->fmt.vbi.start[1] = (dev->norm & V4L2_STD_625_50) ?
1958 PAL_VBI_START_LINE + 312 : NTSC_VBI_START_LINE + 263;
1959 f->fmt.vbi.count[1] = f->fmt.vbi.count[0];
1965 static int vidioc_try_fmt_vbi_cap(struct file *file, void *priv,
1966 struct v4l2_format *f)
1968 struct cx231xx_fh *fh = priv;
1969 struct cx231xx *dev = fh->dev;
1971 if (dev->vbi_stream_on && !fh->stream_on) {
1972 cx231xx_errdev("%s device in use by another fh\n", __func__);
1976 f->type = V4L2_BUF_TYPE_VBI_CAPTURE;
1977 f->fmt.vbi.sampling_rate = 6750000 * 4;
1978 f->fmt.vbi.samples_per_line = VBI_LINE_LENGTH;
1979 f->fmt.vbi.sample_format = V4L2_PIX_FMT_GREY;
1980 f->fmt.vbi.offset = 0;
1981 f->fmt.vbi.flags = 0;
1982 f->fmt.vbi.start[0] = (dev->norm & V4L2_STD_625_50) ?
1983 PAL_VBI_START_LINE : NTSC_VBI_START_LINE;
1984 f->fmt.vbi.count[0] = (dev->norm & V4L2_STD_625_50) ?
1985 PAL_VBI_LINES : NTSC_VBI_LINES;
1986 f->fmt.vbi.start[1] = (dev->norm & V4L2_STD_625_50) ?
1987 PAL_VBI_START_LINE + 312 : NTSC_VBI_START_LINE + 263;
1988 f->fmt.vbi.count[1] = f->fmt.vbi.count[0];
1994 static int vidioc_reqbufs(struct file *file, void *priv,
1995 struct v4l2_requestbuffers *rb)
1997 struct cx231xx_fh *fh = priv;
1998 struct cx231xx *dev = fh->dev;
2001 rc = check_dev(dev);
2005 return videobuf_reqbufs(&fh->vb_vidq, rb);
2008 static int vidioc_querybuf(struct file *file, void *priv, struct v4l2_buffer *b)
2010 struct cx231xx_fh *fh = priv;
2011 struct cx231xx *dev = fh->dev;
2014 rc = check_dev(dev);
2018 return videobuf_querybuf(&fh->vb_vidq, b);
2021 static int vidioc_qbuf(struct file *file, void *priv, struct v4l2_buffer *b)
2023 struct cx231xx_fh *fh = priv;
2024 struct cx231xx *dev = fh->dev;
2027 rc = check_dev(dev);
2031 return videobuf_qbuf(&fh->vb_vidq, b);
2034 static int vidioc_dqbuf(struct file *file, void *priv, struct v4l2_buffer *b)
2036 struct cx231xx_fh *fh = priv;
2037 struct cx231xx *dev = fh->dev;
2040 rc = check_dev(dev);
2044 return videobuf_dqbuf(&fh->vb_vidq, b, file->f_flags & O_NONBLOCK);
2047 /* ----------------------------------------------------------- */
2048 /* RADIO ESPECIFIC IOCTLS */
2049 /* ----------------------------------------------------------- */
2051 static int radio_querycap(struct file *file, void *priv,
2052 struct v4l2_capability *cap)
2054 struct cx231xx *dev = ((struct cx231xx_fh *)priv)->dev;
2056 strlcpy(cap->driver, "cx231xx", sizeof(cap->driver));
2057 strlcpy(cap->card, cx231xx_boards[dev->model].name, sizeof(cap->card));
2058 usb_make_path(dev->udev, cap->bus_info, sizeof(cap->bus_info));
2060 cap->version = CX231XX_VERSION_CODE;
2061 cap->capabilities = V4L2_CAP_TUNER;
2065 static int radio_g_tuner(struct file *file, void *priv, struct v4l2_tuner *t)
2067 struct cx231xx *dev = ((struct cx231xx_fh *)priv)->dev;
2069 if (unlikely(t->index > 0))
2072 strcpy(t->name, "Radio");
2073 t->type = V4L2_TUNER_RADIO;
2075 call_all(dev, tuner, s_tuner, t);
2080 static int radio_enum_input(struct file *file, void *priv, struct v4l2_input *i)
2084 strcpy(i->name, "Radio");
2085 i->type = V4L2_INPUT_TYPE_TUNER;
2090 static int radio_g_audio(struct file *file, void *priv, struct v4l2_audio *a)
2092 if (unlikely(a->index))
2095 strcpy(a->name, "Radio");
2099 static int radio_s_tuner(struct file *file, void *priv, struct v4l2_tuner *t)
2101 struct cx231xx *dev = ((struct cx231xx_fh *)priv)->dev;
2106 call_all(dev, tuner, s_tuner, t);
2111 static int radio_s_audio(struct file *file, void *fh, struct v4l2_audio *a)
2116 static int radio_s_input(struct file *file, void *fh, unsigned int i)
2121 static int radio_queryctrl(struct file *file, void *priv,
2122 struct v4l2_queryctrl *c)
2126 if (c->id < V4L2_CID_BASE || c->id >= V4L2_CID_LASTP1)
2128 if (c->id == V4L2_CID_AUDIO_MUTE) {
2129 for (i = 0; i < CX231XX_CTLS; i++) {
2130 if (cx231xx_ctls[i].v.id == c->id)
2133 if (i == CX231XX_CTLS)
2135 *c = cx231xx_ctls[i].v;
2142 * cx231xx_v4l2_open()
2143 * inits the device and starts isoc transfer
2145 static int cx231xx_v4l2_open(struct file *filp)
2147 int errCode = 0, radio = 0;
2148 struct video_device *vdev = video_devdata(filp);
2149 struct cx231xx *dev = video_drvdata(filp);
2150 struct cx231xx_fh *fh;
2151 enum v4l2_buf_type fh_type = 0;
2153 switch (vdev->vfl_type) {
2154 case VFL_TYPE_GRABBER:
2155 fh_type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
2158 fh_type = V4L2_BUF_TYPE_VBI_CAPTURE;
2160 case VFL_TYPE_RADIO:
2165 cx231xx_videodbg("open dev=%s type=%s users=%d\n",
2166 video_device_node_name(vdev), v4l2_type_names[fh_type],
2170 errCode = cx231xx_set_mode(dev, CX231XX_ANALOG_MODE);
2173 ("Device locked on digital mode. Can't open analog\n");
2178 fh = kzalloc(sizeof(struct cx231xx_fh), GFP_KERNEL);
2180 cx231xx_errdev("cx231xx-video.c: Out of memory?!\n");
2186 filp->private_data = fh;
2188 if (fh->type == V4L2_BUF_TYPE_VIDEO_CAPTURE && dev->users == 0) {
2189 dev->width = norm_maxw(dev);
2190 dev->height = norm_maxh(dev);
2192 /* Power up in Analog TV mode */
2193 if (dev->model == CX231XX_BOARD_CNXT_VIDEO_GRABBER ||
2194 dev->model == CX231XX_BOARD_HAUPPAUGE_USBLIVE2)
2195 cx231xx_set_power_mode(dev,
2196 POLARIS_AVMODE_ENXTERNAL_AV);
2198 cx231xx_set_power_mode(dev, POLARIS_AVMODE_ANALOGT_TV);
2201 cx231xx_set_mode(dev, CX231XX_ANALOG_MODE);
2204 /* set video alternate setting */
2205 cx231xx_set_video_alternate(dev);
2207 /* Needed, since GPIO might have disabled power of
2209 cx231xx_config_i2c(dev);
2211 /* device needs to be initialized before isoc transfer */
2212 dev->video_input = dev->video_input > 2 ? 2 : dev->video_input;
2216 cx231xx_videodbg("video_open: setting radio device\n");
2218 /* cx231xx_start_radio(dev); */
2220 call_all(dev, tuner, s_radio);
2225 if (fh->type == V4L2_BUF_TYPE_VIDEO_CAPTURE)
2226 videobuf_queue_vmalloc_init(&fh->vb_vidq, &cx231xx_video_qops,
2227 NULL, &dev->video_mode.slock,
2228 fh->type, V4L2_FIELD_INTERLACED,
2229 sizeof(struct cx231xx_buffer),
2231 if (fh->type == V4L2_BUF_TYPE_VBI_CAPTURE) {
2232 /* Set the required alternate setting VBI interface works in
2234 if (dev->model != CX231XX_BOARD_CNXT_VIDEO_GRABBER &&
2235 dev->model != CX231XX_BOARD_HAUPPAUGE_USBLIVE2)
2236 cx231xx_set_alt_setting(dev, INDEX_VANC, 0);
2238 videobuf_queue_vmalloc_init(&fh->vb_vidq, &cx231xx_vbi_qops,
2239 NULL, &dev->vbi_mode.slock,
2240 fh->type, V4L2_FIELD_SEQ_TB,
2241 sizeof(struct cx231xx_buffer),
2249 * cx231xx_realease_resources()
2250 * unregisters the v4l2,i2c and usb devices
2251 * called when the device gets disconected or at module unload
2253 void cx231xx_release_analog_resources(struct cx231xx *dev)
2256 /*FIXME: I2C IR should be disconnected */
2258 if (dev->radio_dev) {
2259 if (video_is_registered(dev->radio_dev))
2260 video_unregister_device(dev->radio_dev);
2262 video_device_release(dev->radio_dev);
2263 dev->radio_dev = NULL;
2266 cx231xx_info("V4L2 device %s deregistered\n",
2267 video_device_node_name(dev->vbi_dev));
2268 if (video_is_registered(dev->vbi_dev))
2269 video_unregister_device(dev->vbi_dev);
2271 video_device_release(dev->vbi_dev);
2272 dev->vbi_dev = NULL;
2275 cx231xx_info("V4L2 device %s deregistered\n",
2276 video_device_node_name(dev->vdev));
2278 if (dev->model == CX231XX_BOARD_CNXT_VIDEO_GRABBER)
2279 cx231xx_417_unregister(dev);
2281 if (video_is_registered(dev->vdev))
2282 video_unregister_device(dev->vdev);
2284 video_device_release(dev->vdev);
2290 * cx231xx_v4l2_close()
2291 * stops streaming and deallocates all resources allocated by the v4l2
2294 static int cx231xx_v4l2_close(struct file *filp)
2296 struct cx231xx_fh *fh = filp->private_data;
2297 struct cx231xx *dev = fh->dev;
2299 cx231xx_videodbg("users=%d\n", dev->users);
2301 cx231xx_videodbg("users=%d\n", dev->users);
2305 /*To workaround error number=-71 on EP0 for VideoGrabber,
2306 need exclude following.*/
2307 if (dev->model != CX231XX_BOARD_CNXT_VIDEO_GRABBER &&
2308 dev->model != CX231XX_BOARD_HAUPPAUGE_USBLIVE2)
2309 if (fh->type == V4L2_BUF_TYPE_VBI_CAPTURE) {
2310 videobuf_stop(&fh->vb_vidq);
2311 videobuf_mmap_free(&fh->vb_vidq);
2313 /* the device is already disconnect,
2314 free the remaining resources */
2315 if (dev->state & DEV_DISCONNECTED) {
2316 if (atomic_read(&dev->devlist_count) > 0) {
2317 cx231xx_release_resources(dev);
2325 /* do this before setting alternate! */
2326 cx231xx_uninit_vbi_isoc(dev);
2328 /* set alternate 0 */
2329 if (!dev->vbi_or_sliced_cc_mode)
2330 cx231xx_set_alt_setting(dev, INDEX_VANC, 0);
2332 cx231xx_set_alt_setting(dev, INDEX_HANC, 0);
2336 wake_up_interruptible_nr(&dev->open, 1);
2340 if (dev->users == 1) {
2341 videobuf_stop(&fh->vb_vidq);
2342 videobuf_mmap_free(&fh->vb_vidq);
2344 /* the device is already disconnect,
2345 free the remaining resources */
2346 if (dev->state & DEV_DISCONNECTED) {
2347 cx231xx_release_resources(dev);
2353 /* Save some power by putting tuner to sleep */
2354 call_all(dev, core, s_power, 0);
2356 /* do this before setting alternate! */
2358 cx231xx_uninit_isoc(dev);
2360 cx231xx_uninit_bulk(dev);
2361 cx231xx_set_mode(dev, CX231XX_SUSPEND);
2363 /* set alternate 0 */
2364 cx231xx_set_alt_setting(dev, INDEX_VIDEO, 0);
2368 wake_up_interruptible_nr(&dev->open, 1);
2373 * cx231xx_v4l2_read()
2374 * will allocate buffers when called for the first time
2377 cx231xx_v4l2_read(struct file *filp, char __user *buf, size_t count,
2380 struct cx231xx_fh *fh = filp->private_data;
2381 struct cx231xx *dev = fh->dev;
2384 rc = check_dev(dev);
2388 if ((fh->type == V4L2_BUF_TYPE_VIDEO_CAPTURE) ||
2389 (fh->type == V4L2_BUF_TYPE_VBI_CAPTURE)) {
2392 if (unlikely(rc < 0))
2395 return videobuf_read_stream(&fh->vb_vidq, buf, count, pos, 0,
2396 filp->f_flags & O_NONBLOCK);
2402 * cx231xx_v4l2_poll()
2403 * will allocate buffers when called for the first time
2405 static unsigned int cx231xx_v4l2_poll(struct file *filp, poll_table *wait)
2407 struct cx231xx_fh *fh = filp->private_data;
2408 struct cx231xx *dev = fh->dev;
2411 rc = check_dev(dev);
2417 if (unlikely(rc < 0))
2420 if ((V4L2_BUF_TYPE_VIDEO_CAPTURE == fh->type) ||
2421 (V4L2_BUF_TYPE_VBI_CAPTURE == fh->type))
2422 return videobuf_poll_stream(filp, &fh->vb_vidq, wait);
2428 * cx231xx_v4l2_mmap()
2430 static int cx231xx_v4l2_mmap(struct file *filp, struct vm_area_struct *vma)
2432 struct cx231xx_fh *fh = filp->private_data;
2433 struct cx231xx *dev = fh->dev;
2436 rc = check_dev(dev);
2442 if (unlikely(rc < 0))
2445 rc = videobuf_mmap_mapper(&fh->vb_vidq, vma);
2447 cx231xx_videodbg("vma start=0x%08lx, size=%ld, ret=%d\n",
2448 (unsigned long)vma->vm_start,
2449 (unsigned long)vma->vm_end -
2450 (unsigned long)vma->vm_start, rc);
2455 static const struct v4l2_file_operations cx231xx_v4l_fops = {
2456 .owner = THIS_MODULE,
2457 .open = cx231xx_v4l2_open,
2458 .release = cx231xx_v4l2_close,
2459 .read = cx231xx_v4l2_read,
2460 .poll = cx231xx_v4l2_poll,
2461 .mmap = cx231xx_v4l2_mmap,
2462 .unlocked_ioctl = video_ioctl2,
2465 static const struct v4l2_ioctl_ops video_ioctl_ops = {
2466 .vidioc_querycap = vidioc_querycap,
2467 .vidioc_enum_fmt_vid_cap = vidioc_enum_fmt_vid_cap,
2468 .vidioc_g_fmt_vid_cap = vidioc_g_fmt_vid_cap,
2469 .vidioc_try_fmt_vid_cap = vidioc_try_fmt_vid_cap,
2470 .vidioc_s_fmt_vid_cap = vidioc_s_fmt_vid_cap,
2471 .vidioc_g_fmt_vbi_cap = vidioc_g_fmt_vbi_cap,
2472 .vidioc_try_fmt_vbi_cap = vidioc_try_fmt_vbi_cap,
2473 .vidioc_s_fmt_vbi_cap = vidioc_try_fmt_vbi_cap,
2474 .vidioc_g_audio = vidioc_g_audio,
2475 .vidioc_s_audio = vidioc_s_audio,
2476 .vidioc_cropcap = vidioc_cropcap,
2477 .vidioc_g_fmt_sliced_vbi_cap = vidioc_g_fmt_sliced_vbi_cap,
2478 .vidioc_try_fmt_sliced_vbi_cap = vidioc_try_set_sliced_vbi_cap,
2479 .vidioc_reqbufs = vidioc_reqbufs,
2480 .vidioc_querybuf = vidioc_querybuf,
2481 .vidioc_qbuf = vidioc_qbuf,
2482 .vidioc_dqbuf = vidioc_dqbuf,
2483 .vidioc_s_std = vidioc_s_std,
2484 .vidioc_g_std = vidioc_g_std,
2485 .vidioc_enum_input = vidioc_enum_input,
2486 .vidioc_g_input = vidioc_g_input,
2487 .vidioc_s_input = vidioc_s_input,
2488 .vidioc_queryctrl = vidioc_queryctrl,
2489 .vidioc_g_ctrl = vidioc_g_ctrl,
2490 .vidioc_s_ctrl = vidioc_s_ctrl,
2491 .vidioc_streamon = vidioc_streamon,
2492 .vidioc_streamoff = vidioc_streamoff,
2493 .vidioc_g_tuner = vidioc_g_tuner,
2494 .vidioc_s_tuner = vidioc_s_tuner,
2495 .vidioc_g_frequency = vidioc_g_frequency,
2496 .vidioc_s_frequency = vidioc_s_frequency,
2497 #ifdef CONFIG_VIDEO_ADV_DEBUG
2498 .vidioc_g_register = vidioc_g_register,
2499 .vidioc_s_register = vidioc_s_register,
2503 static struct video_device cx231xx_vbi_template;
2505 static const struct video_device cx231xx_video_template = {
2506 .fops = &cx231xx_v4l_fops,
2507 .release = video_device_release,
2508 .ioctl_ops = &video_ioctl_ops,
2509 .tvnorms = V4L2_STD_ALL,
2510 .current_norm = V4L2_STD_PAL,
2513 static const struct v4l2_file_operations radio_fops = {
2514 .owner = THIS_MODULE,
2515 .open = cx231xx_v4l2_open,
2516 .release = cx231xx_v4l2_close,
2517 .ioctl = video_ioctl2,
2520 static const struct v4l2_ioctl_ops radio_ioctl_ops = {
2521 .vidioc_querycap = radio_querycap,
2522 .vidioc_g_tuner = radio_g_tuner,
2523 .vidioc_enum_input = radio_enum_input,
2524 .vidioc_g_audio = radio_g_audio,
2525 .vidioc_s_tuner = radio_s_tuner,
2526 .vidioc_s_audio = radio_s_audio,
2527 .vidioc_s_input = radio_s_input,
2528 .vidioc_queryctrl = radio_queryctrl,
2529 .vidioc_g_ctrl = vidioc_g_ctrl,
2530 .vidioc_s_ctrl = vidioc_s_ctrl,
2531 .vidioc_g_frequency = vidioc_g_frequency,
2532 .vidioc_s_frequency = vidioc_s_frequency,
2533 #ifdef CONFIG_VIDEO_ADV_DEBUG
2534 .vidioc_g_register = vidioc_g_register,
2535 .vidioc_s_register = vidioc_s_register,
2539 static struct video_device cx231xx_radio_template = {
2540 .name = "cx231xx-radio",
2541 .fops = &radio_fops,
2542 .ioctl_ops = &radio_ioctl_ops,
2545 /******************************** usb interface ******************************/
2547 static struct video_device *cx231xx_vdev_init(struct cx231xx *dev,
2548 const struct video_device
2549 *template, const char *type_name)
2551 struct video_device *vfd;
2553 vfd = video_device_alloc();
2558 vfd->v4l2_dev = &dev->v4l2_dev;
2559 vfd->release = video_device_release;
2560 vfd->debug = video_debug;
2561 vfd->lock = &dev->lock;
2563 snprintf(vfd->name, sizeof(vfd->name), "%s %s", dev->name, type_name);
2565 video_set_drvdata(vfd, dev);
2569 int cx231xx_register_analog_devices(struct cx231xx *dev)
2573 cx231xx_info("%s: v4l2 driver version %d.%d.%d\n",
2575 (CX231XX_VERSION_CODE >> 16) & 0xff,
2576 (CX231XX_VERSION_CODE >> 8) & 0xff,
2577 CX231XX_VERSION_CODE & 0xff);
2579 /* set default norm */
2580 /*dev->norm = cx231xx_video_template.current_norm; */
2581 dev->width = norm_maxw(dev);
2582 dev->height = norm_maxh(dev);
2583 dev->interlaced = 0;
2585 /* Analog specific initialization */
2586 dev->format = &format[0];
2588 /* Set the initial input */
2589 video_mux(dev, dev->video_input);
2591 /* Audio defaults */
2595 /* enable vbi capturing */
2596 /* write code here... */
2598 /* allocate and fill video video_device struct */
2599 dev->vdev = cx231xx_vdev_init(dev, &cx231xx_video_template, "video");
2601 cx231xx_errdev("cannot allocate video_device.\n");
2605 /* register v4l2 video video_device */
2606 ret = video_register_device(dev->vdev, VFL_TYPE_GRABBER,
2607 video_nr[dev->devno]);
2609 cx231xx_errdev("unable to register video device (error=%i).\n",
2614 cx231xx_info("%s/0: registered device %s [v4l2]\n",
2615 dev->name, video_device_node_name(dev->vdev));
2617 /* Initialize VBI template */
2618 memcpy(&cx231xx_vbi_template, &cx231xx_video_template,
2619 sizeof(cx231xx_vbi_template));
2620 strcpy(cx231xx_vbi_template.name, "cx231xx-vbi");
2622 /* Allocate and fill vbi video_device struct */
2623 dev->vbi_dev = cx231xx_vdev_init(dev, &cx231xx_vbi_template, "vbi");
2625 /* register v4l2 vbi video_device */
2626 ret = video_register_device(dev->vbi_dev, VFL_TYPE_VBI,
2627 vbi_nr[dev->devno]);
2629 cx231xx_errdev("unable to register vbi device\n");
2633 cx231xx_info("%s/0: registered device %s\n",
2634 dev->name, video_device_node_name(dev->vbi_dev));
2636 if (cx231xx_boards[dev->model].radio.type == CX231XX_RADIO) {
2637 dev->radio_dev = cx231xx_vdev_init(dev, &cx231xx_radio_template,
2639 if (!dev->radio_dev) {
2640 cx231xx_errdev("cannot allocate video_device.\n");
2643 ret = video_register_device(dev->radio_dev, VFL_TYPE_RADIO,
2644 radio_nr[dev->devno]);
2646 cx231xx_errdev("can't register radio device\n");
2649 cx231xx_info("Registered radio device as %s\n",
2650 video_device_node_name(dev->radio_dev));
2653 cx231xx_info("V4L2 device registered as %s and %s\n",
2654 video_device_node_name(dev->vdev),
2655 video_device_node_name(dev->vbi_dev));