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>
33 #include <linux/mutex.h>
34 #include <linux/slab.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 "0.0.2"
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");
72 MODULE_VERSION(CX231XX_VERSION
);
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 - Useful 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_dmaqueue
*dma_q
= urb
->context
;
331 unsigned char *p_buffer
;
332 u32 bytes_parsed
= 0, buffer_size
= 0;
338 if (dev
->state
& DEV_DISCONNECTED
)
341 if (urb
->status
< 0) {
342 print_err_status(dev
, -1, urb
->status
);
343 if (urb
->status
== -ENOENT
)
347 for (i
= 0; i
< urb
->number_of_packets
; i
++) {
348 int status
= urb
->iso_frame_desc
[i
].status
;
351 print_err_status(dev
, i
, status
);
352 if (urb
->iso_frame_desc
[i
].status
!= -EPROTO
)
356 if (urb
->iso_frame_desc
[i
].actual_length
<= 0) {
357 /* cx231xx_isocdbg("packet %d is empty",i); - spammy */
360 if (urb
->iso_frame_desc
[i
].actual_length
>
361 dev
->video_mode
.max_pkt_size
) {
362 cx231xx_isocdbg("packet bigger than packet size");
366 /* get buffer pointer and length */
367 p_buffer
= urb
->transfer_buffer
+ urb
->iso_frame_desc
[i
].offset
;
368 buffer_size
= urb
->iso_frame_desc
[i
].actual_length
;
371 if (dma_q
->is_partial_line
) {
372 /* Handle the case of a partial line */
373 sav_eav
= dma_q
->last_sav
;
375 /* Check for a SAV/EAV overlapping
376 the buffer boundary */
378 cx231xx_find_boundary_SAV_EAV(p_buffer
,
384 /* Get the first line if we have some portion of an SAV/EAV from
385 the last buffer or a partial line */
387 bytes_parsed
+= cx231xx_get_video_line(dev
, dma_q
,
388 sav_eav
, /* SAV/EAV */
389 p_buffer
+ bytes_parsed
, /* p_buffer */
390 buffer_size
- bytes_parsed
);/* buf size */
393 /* Now parse data that is completely in this buffer */
394 /* dma_q->is_partial_line = 0; */
396 while (bytes_parsed
< buffer_size
) {
399 sav_eav
= cx231xx_find_next_SAV_EAV(
400 p_buffer
+ bytes_parsed
, /* p_buffer */
401 buffer_size
- bytes_parsed
, /* buf size */
402 &bytes_used
);/* bytes used to get SAV/EAV */
404 bytes_parsed
+= bytes_used
;
407 if (sav_eav
&& (bytes_parsed
< buffer_size
)) {
408 bytes_parsed
+= cx231xx_get_video_line(dev
,
409 dma_q
, sav_eav
, /* SAV/EAV */
410 p_buffer
+ bytes_parsed
,/* p_buffer */
411 buffer_size
- bytes_parsed
);/*buf size*/
415 /* Save the last four bytes of the buffer so we can check the
416 buffer boundary condition next time */
417 memcpy(dma_q
->partial_buf
, p_buffer
+ buffer_size
- 4, 4);
424 static inline int cx231xx_bulk_copy(struct cx231xx
*dev
, struct urb
*urb
)
426 struct cx231xx_dmaqueue
*dma_q
= urb
->context
;
428 unsigned char *p_buffer
;
429 u32 bytes_parsed
= 0, buffer_size
= 0;
435 if (dev
->state
& DEV_DISCONNECTED
)
438 if (urb
->status
< 0) {
439 print_err_status(dev
, -1, urb
->status
);
440 if (urb
->status
== -ENOENT
)
446 /* get buffer pointer and length */
447 p_buffer
= urb
->transfer_buffer
;
448 buffer_size
= urb
->actual_length
;
451 if (dma_q
->is_partial_line
) {
452 /* Handle the case of a partial line */
453 sav_eav
= dma_q
->last_sav
;
455 /* Check for a SAV/EAV overlapping
456 the buffer boundary */
458 cx231xx_find_boundary_SAV_EAV(p_buffer
,
464 /* Get the first line if we have some portion of an SAV/EAV from
465 the last buffer or a partial line */
467 bytes_parsed
+= cx231xx_get_video_line(dev
, dma_q
,
468 sav_eav
, /* SAV/EAV */
469 p_buffer
+ bytes_parsed
, /* p_buffer */
470 buffer_size
- bytes_parsed
);/* buf size */
473 /* Now parse data that is completely in this buffer */
474 /* dma_q->is_partial_line = 0; */
476 while (bytes_parsed
< buffer_size
) {
479 sav_eav
= cx231xx_find_next_SAV_EAV(
480 p_buffer
+ bytes_parsed
, /* p_buffer */
481 buffer_size
- bytes_parsed
, /* buf size */
482 &bytes_used
);/* bytes used to get SAV/EAV */
484 bytes_parsed
+= bytes_used
;
487 if (sav_eav
&& (bytes_parsed
< buffer_size
)) {
488 bytes_parsed
+= cx231xx_get_video_line(dev
,
489 dma_q
, sav_eav
, /* SAV/EAV */
490 p_buffer
+ bytes_parsed
,/* p_buffer */
491 buffer_size
- bytes_parsed
);/*buf size*/
495 /* Save the last four bytes of the buffer so we can check the
496 buffer boundary condition next time */
497 memcpy(dma_q
->partial_buf
, p_buffer
+ buffer_size
- 4, 4);
505 u8
cx231xx_find_boundary_SAV_EAV(u8
*p_buffer
, u8
*partial_buf
,
509 u8 boundary_bytes
[8];
514 /* Create an array of the last 4 bytes of the last buffer and the first
515 4 bytes of the current buffer. */
517 memcpy(boundary_bytes
, partial_buf
, 4);
518 memcpy(boundary_bytes
+ 4, p_buffer
, 4);
520 /* Check for the SAV/EAV in the boundary buffer */
521 sav_eav
= cx231xx_find_next_SAV_EAV((u8
*)&boundary_bytes
, 8,
525 /* found a boundary SAV/EAV. Updates the bytes used to reflect
526 only those used in the new buffer */
527 *p_bytes_used
= bytes_used
- 4;
533 u8
cx231xx_find_next_SAV_EAV(u8
*p_buffer
, u32 buffer_size
, u32
*p_bytes_used
)
539 * Don't search if the buffer size is less than 4. It causes a page
540 * fault since buffer_size - 4 evaluates to a large number in that
543 if (buffer_size
< 4) {
544 *p_bytes_used
= buffer_size
;
548 for (i
= 0; i
< (buffer_size
- 3); i
++) {
550 if ((p_buffer
[i
] == 0xFF) &&
551 (p_buffer
[i
+ 1] == 0x00) && (p_buffer
[i
+ 2] == 0x00)) {
553 *p_bytes_used
= i
+ 4;
554 sav_eav
= p_buffer
[i
+ 3];
559 *p_bytes_used
= buffer_size
;
563 u32
cx231xx_get_video_line(struct cx231xx
*dev
,
564 struct cx231xx_dmaqueue
*dma_q
, u8 sav_eav
,
565 u8
*p_buffer
, u32 buffer_size
)
567 u32 bytes_copied
= 0;
568 int current_field
= -1;
571 case SAV_ACTIVE_VIDEO_FIELD1
:
572 /* looking for skipped line which occurred in PAL 720x480 mode.
573 In this case, there will be no active data contained
574 between the SAV and EAV */
575 if ((buffer_size
> 3) && (p_buffer
[0] == 0xFF) &&
576 (p_buffer
[1] == 0x00) && (p_buffer
[2] == 0x00) &&
577 ((p_buffer
[3] == EAV_ACTIVE_VIDEO_FIELD1
) ||
578 (p_buffer
[3] == EAV_ACTIVE_VIDEO_FIELD2
) ||
579 (p_buffer
[3] == EAV_VBLANK_FIELD1
) ||
580 (p_buffer
[3] == EAV_VBLANK_FIELD2
)))
585 case SAV_ACTIVE_VIDEO_FIELD2
:
586 /* looking for skipped line which occurred in PAL 720x480 mode.
587 In this case, there will be no active data contained between
589 if ((buffer_size
> 3) && (p_buffer
[0] == 0xFF) &&
590 (p_buffer
[1] == 0x00) && (p_buffer
[2] == 0x00) &&
591 ((p_buffer
[3] == EAV_ACTIVE_VIDEO_FIELD1
) ||
592 (p_buffer
[3] == EAV_ACTIVE_VIDEO_FIELD2
) ||
593 (p_buffer
[3] == EAV_VBLANK_FIELD1
) ||
594 (p_buffer
[3] == EAV_VBLANK_FIELD2
)))
600 dma_q
->last_sav
= sav_eav
;
602 bytes_copied
= cx231xx_copy_video_line(dev
, dma_q
, p_buffer
,
603 buffer_size
, current_field
);
608 u32
cx231xx_copy_video_line(struct cx231xx
*dev
,
609 struct cx231xx_dmaqueue
*dma_q
, u8
*p_line
,
610 u32 length
, int field_number
)
613 struct cx231xx_buffer
*buf
;
614 u32 _line_size
= dev
->width
* 2;
616 if (dma_q
->current_field
!= field_number
)
617 cx231xx_reset_video_buffer(dev
, dma_q
);
619 /* get the buffer pointer */
621 buf
= dev
->video_mode
.isoc_ctl
.buf
;
623 buf
= dev
->video_mode
.bulk_ctl
.buf
;
625 /* Remember the field number for next time */
626 dma_q
->current_field
= field_number
;
628 bytes_to_copy
= dma_q
->bytes_left_in_line
;
629 if (bytes_to_copy
> length
)
630 bytes_to_copy
= length
;
632 if (dma_q
->lines_completed
>= dma_q
->lines_per_field
) {
633 dma_q
->bytes_left_in_line
-= bytes_to_copy
;
634 dma_q
->is_partial_line
= (dma_q
->bytes_left_in_line
== 0) ?
639 dma_q
->is_partial_line
= 1;
641 /* If we don't have a buffer, just return the number of bytes we would
642 have copied if we had a buffer. */
644 dma_q
->bytes_left_in_line
-= bytes_to_copy
;
645 dma_q
->is_partial_line
= (dma_q
->bytes_left_in_line
== 0)
647 return bytes_to_copy
;
650 /* copy the data to video buffer */
651 cx231xx_do_copy(dev
, dma_q
, p_line
, bytes_to_copy
);
653 dma_q
->pos
+= bytes_to_copy
;
654 dma_q
->bytes_left_in_line
-= bytes_to_copy
;
656 if (dma_q
->bytes_left_in_line
== 0) {
657 dma_q
->bytes_left_in_line
= _line_size
;
658 dma_q
->lines_completed
++;
659 dma_q
->is_partial_line
= 0;
661 if (cx231xx_is_buffer_done(dev
, dma_q
) && buf
) {
662 buffer_filled(dev
, dma_q
, buf
);
666 dma_q
->lines_completed
= 0;
670 return bytes_to_copy
;
673 void cx231xx_reset_video_buffer(struct cx231xx
*dev
,
674 struct cx231xx_dmaqueue
*dma_q
)
676 struct cx231xx_buffer
*buf
;
678 /* handle the switch from field 1 to field 2 */
679 if (dma_q
->current_field
== 1) {
680 if (dma_q
->lines_completed
>= dma_q
->lines_per_field
)
681 dma_q
->field1_done
= 1;
683 dma_q
->field1_done
= 0;
687 buf
= dev
->video_mode
.isoc_ctl
.buf
;
689 buf
= dev
->video_mode
.bulk_ctl
.buf
;
692 /* first try to get the buffer */
693 get_next_buf(dma_q
, &buf
);
696 dma_q
->field1_done
= 0;
697 dma_q
->current_field
= -1;
700 /* reset the counters */
701 dma_q
->bytes_left_in_line
= dev
->width
<< 1;
702 dma_q
->lines_completed
= 0;
705 int cx231xx_do_copy(struct cx231xx
*dev
, struct cx231xx_dmaqueue
*dma_q
,
706 u8
*p_buffer
, u32 bytes_to_copy
)
708 u8
*p_out_buffer
= NULL
;
709 u32 current_line_bytes_copied
= 0;
710 struct cx231xx_buffer
*buf
;
711 u32 _line_size
= dev
->width
<< 1;
716 buf
= dev
->video_mode
.isoc_ctl
.buf
;
718 buf
= dev
->video_mode
.bulk_ctl
.buf
;
723 p_out_buffer
= videobuf_to_vmalloc(&buf
->vb
);
725 current_line_bytes_copied
= _line_size
- dma_q
->bytes_left_in_line
;
727 /* Offset field 2 one line from the top of the buffer */
728 offset
= (dma_q
->current_field
== 1) ? 0 : _line_size
;
730 /* Offset for field 2 */
731 startwrite
= p_out_buffer
+ offset
;
733 /* lines already completed in the current field */
734 startwrite
+= (dma_q
->lines_completed
* _line_size
* 2);
736 /* bytes already completed in the current line */
737 startwrite
+= current_line_bytes_copied
;
739 lencopy
= dma_q
->bytes_left_in_line
> bytes_to_copy
?
740 bytes_to_copy
: dma_q
->bytes_left_in_line
;
742 if ((u8
*)(startwrite
+ lencopy
) > (u8
*)(p_out_buffer
+ buf
->vb
.size
))
745 /* The below copies the UYVY data straight into video buffer */
746 cx231xx_swab((u16
*) p_buffer
, (u16
*) startwrite
, (u16
) lencopy
);
751 void cx231xx_swab(u16
*from
, u16
*to
, u16 len
)
758 for (i
= 0; i
< len
/ 2; i
++)
759 to
[i
] = (from
[i
] << 8) | (from
[i
] >> 8);
762 u8
cx231xx_is_buffer_done(struct cx231xx
*dev
, struct cx231xx_dmaqueue
*dma_q
)
764 u8 buffer_complete
= 0;
766 /* Dual field stream */
767 buffer_complete
= ((dma_q
->current_field
== 2) &&
768 (dma_q
->lines_completed
>= dma_q
->lines_per_field
) &&
771 return buffer_complete
;
774 /* ------------------------------------------------------------------
776 ------------------------------------------------------------------*/
779 buffer_setup(struct videobuf_queue
*vq
, unsigned int *count
, unsigned int *size
)
781 struct cx231xx_fh
*fh
= vq
->priv_data
;
782 struct cx231xx
*dev
= fh
->dev
;
784 *size
= (fh
->dev
->width
* fh
->dev
->height
* dev
->format
->depth
+ 7)>>3;
786 *count
= CX231XX_DEF_BUF
;
788 if (*count
< CX231XX_MIN_BUF
)
789 *count
= CX231XX_MIN_BUF
;
794 /* This is called *without* dev->slock held; please keep it that way */
795 static void free_buffer(struct videobuf_queue
*vq
, struct cx231xx_buffer
*buf
)
797 struct cx231xx_fh
*fh
= vq
->priv_data
;
798 struct cx231xx
*dev
= fh
->dev
;
799 unsigned long flags
= 0;
804 /* We used to wait for the buffer to finish here, but this didn't work
805 because, as we were keeping the state as VIDEOBUF_QUEUED,
806 videobuf_queue_cancel marked it as finished for us.
807 (Also, it could wedge forever if the hardware was misconfigured.)
809 This should be safe; by the time we get here, the buffer isn't
810 queued anymore. If we ever start marking the buffers as
811 VIDEOBUF_ACTIVE, it won't be, though.
813 spin_lock_irqsave(&dev
->video_mode
.slock
, flags
);
815 if (dev
->video_mode
.isoc_ctl
.buf
== buf
)
816 dev
->video_mode
.isoc_ctl
.buf
= NULL
;
818 if (dev
->video_mode
.bulk_ctl
.buf
== buf
)
819 dev
->video_mode
.bulk_ctl
.buf
= NULL
;
821 spin_unlock_irqrestore(&dev
->video_mode
.slock
, flags
);
823 videobuf_vmalloc_free(&buf
->vb
);
824 buf
->vb
.state
= VIDEOBUF_NEEDS_INIT
;
828 buffer_prepare(struct videobuf_queue
*vq
, struct videobuf_buffer
*vb
,
829 enum v4l2_field field
)
831 struct cx231xx_fh
*fh
= vq
->priv_data
;
832 struct cx231xx_buffer
*buf
=
833 container_of(vb
, struct cx231xx_buffer
, vb
);
834 struct cx231xx
*dev
= fh
->dev
;
835 int rc
= 0, urb_init
= 0;
837 /* The only currently supported format is 16 bits/pixel */
838 buf
->vb
.size
= (fh
->dev
->width
* fh
->dev
->height
* dev
->format
->depth
840 if (0 != buf
->vb
.baddr
&& buf
->vb
.bsize
< buf
->vb
.size
)
843 buf
->vb
.width
= dev
->width
;
844 buf
->vb
.height
= dev
->height
;
845 buf
->vb
.field
= field
;
847 if (VIDEOBUF_NEEDS_INIT
== buf
->vb
.state
) {
848 rc
= videobuf_iolock(vq
, &buf
->vb
, NULL
);
854 if (!dev
->video_mode
.isoc_ctl
.num_bufs
)
857 if (!dev
->video_mode
.bulk_ctl
.num_bufs
)
860 /*cx231xx_info("urb_init=%d dev->video_mode.max_pkt_size=%d\n",
861 urb_init, dev->video_mode.max_pkt_size);*/
865 rc
= cx231xx_init_isoc(dev
, CX231XX_NUM_PACKETS
,
867 dev
->video_mode
.max_pkt_size
,
870 rc
= cx231xx_init_bulk(dev
, CX231XX_NUM_PACKETS
,
872 dev
->video_mode
.max_pkt_size
,
878 buf
->vb
.state
= VIDEOBUF_PREPARED
;
882 free_buffer(vq
, buf
);
886 static void buffer_queue(struct videobuf_queue
*vq
, struct videobuf_buffer
*vb
)
888 struct cx231xx_buffer
*buf
=
889 container_of(vb
, struct cx231xx_buffer
, vb
);
890 struct cx231xx_fh
*fh
= vq
->priv_data
;
891 struct cx231xx
*dev
= fh
->dev
;
892 struct cx231xx_dmaqueue
*vidq
= &dev
->video_mode
.vidq
;
894 buf
->vb
.state
= VIDEOBUF_QUEUED
;
895 list_add_tail(&buf
->vb
.queue
, &vidq
->active
);
899 static void buffer_release(struct videobuf_queue
*vq
,
900 struct videobuf_buffer
*vb
)
902 struct cx231xx_buffer
*buf
=
903 container_of(vb
, struct cx231xx_buffer
, vb
);
904 struct cx231xx_fh
*fh
= vq
->priv_data
;
905 struct cx231xx
*dev
= (struct cx231xx
*)fh
->dev
;
907 cx231xx_isocdbg("cx231xx: called buffer_release\n");
909 free_buffer(vq
, buf
);
912 static struct videobuf_queue_ops cx231xx_video_qops
= {
913 .buf_setup
= buffer_setup
,
914 .buf_prepare
= buffer_prepare
,
915 .buf_queue
= buffer_queue
,
916 .buf_release
= buffer_release
,
919 /********************* v4l2 interface **************************************/
921 void video_mux(struct cx231xx
*dev
, int index
)
923 dev
->video_input
= index
;
924 dev
->ctl_ainput
= INPUT(index
)->amux
;
926 cx231xx_set_video_input_mux(dev
, index
);
928 cx25840_call(dev
, video
, s_routing
, INPUT(index
)->vmux
, 0, 0);
930 cx231xx_set_audio_input(dev
, dev
->ctl_ainput
);
932 cx231xx_info("video_mux : %d\n", index
);
934 /* do mode control overrides if required */
935 cx231xx_do_mode_ctrl_overrides(dev
);
938 /* Usage lock check functions */
939 static int res_get(struct cx231xx_fh
*fh
)
941 struct cx231xx
*dev
= fh
->dev
;
944 /* This instance already has stream_on */
948 if (fh
->type
== V4L2_BUF_TYPE_VIDEO_CAPTURE
) {
952 } else if (fh
->type
== V4L2_BUF_TYPE_VBI_CAPTURE
) {
953 if (dev
->vbi_stream_on
)
955 dev
->vbi_stream_on
= 1;
964 static int res_check(struct cx231xx_fh
*fh
)
966 return fh
->stream_on
;
969 static void res_free(struct cx231xx_fh
*fh
)
971 struct cx231xx
*dev
= fh
->dev
;
975 if (fh
->type
== V4L2_BUF_TYPE_VIDEO_CAPTURE
)
977 if (fh
->type
== V4L2_BUF_TYPE_VBI_CAPTURE
)
978 dev
->vbi_stream_on
= 0;
981 static int check_dev(struct cx231xx
*dev
)
983 if (dev
->state
& DEV_DISCONNECTED
) {
984 cx231xx_errdev("v4l2 ioctl: device not present\n");
990 /* ------------------------------------------------------------------
991 IOCTL vidioc handling
992 ------------------------------------------------------------------*/
994 static int vidioc_g_fmt_vid_cap(struct file
*file
, void *priv
,
995 struct v4l2_format
*f
)
997 struct cx231xx_fh
*fh
= priv
;
998 struct cx231xx
*dev
= fh
->dev
;
1000 f
->fmt
.pix
.width
= dev
->width
;
1001 f
->fmt
.pix
.height
= dev
->height
;
1002 f
->fmt
.pix
.pixelformat
= dev
->format
->fourcc
;
1003 f
->fmt
.pix
.bytesperline
= (dev
->width
* dev
->format
->depth
+ 7) >> 3;
1004 f
->fmt
.pix
.sizeimage
= f
->fmt
.pix
.bytesperline
* dev
->height
;
1005 f
->fmt
.pix
.colorspace
= V4L2_COLORSPACE_SMPTE170M
;
1007 f
->fmt
.pix
.field
= V4L2_FIELD_INTERLACED
;
1012 static struct cx231xx_fmt
*format_by_fourcc(unsigned int fourcc
)
1016 for (i
= 0; i
< ARRAY_SIZE(format
); i
++)
1017 if (format
[i
].fourcc
== fourcc
)
1023 static int vidioc_try_fmt_vid_cap(struct file
*file
, void *priv
,
1024 struct v4l2_format
*f
)
1026 struct cx231xx_fh
*fh
= priv
;
1027 struct cx231xx
*dev
= fh
->dev
;
1028 unsigned int width
= f
->fmt
.pix
.width
;
1029 unsigned int height
= f
->fmt
.pix
.height
;
1030 unsigned int maxw
= norm_maxw(dev
);
1031 unsigned int maxh
= norm_maxh(dev
);
1032 struct cx231xx_fmt
*fmt
;
1034 fmt
= format_by_fourcc(f
->fmt
.pix
.pixelformat
);
1036 cx231xx_videodbg("Fourcc format (%08x) invalid.\n",
1037 f
->fmt
.pix
.pixelformat
);
1041 /* width must even because of the YUYV format
1042 height must be even because of interlacing */
1043 v4l_bound_align_image(&width
, 48, maxw
, 1, &height
, 32, maxh
, 1, 0);
1045 f
->fmt
.pix
.width
= width
;
1046 f
->fmt
.pix
.height
= height
;
1047 f
->fmt
.pix
.pixelformat
= fmt
->fourcc
;
1048 f
->fmt
.pix
.bytesperline
= (dev
->width
* fmt
->depth
+ 7) >> 3;
1049 f
->fmt
.pix
.sizeimage
= f
->fmt
.pix
.bytesperline
* height
;
1050 f
->fmt
.pix
.colorspace
= V4L2_COLORSPACE_SMPTE170M
;
1051 f
->fmt
.pix
.field
= V4L2_FIELD_INTERLACED
;
1056 static int vidioc_s_fmt_vid_cap(struct file
*file
, void *priv
,
1057 struct v4l2_format
*f
)
1059 struct cx231xx_fh
*fh
= priv
;
1060 struct cx231xx
*dev
= fh
->dev
;
1062 struct cx231xx_fmt
*fmt
;
1063 struct v4l2_mbus_framefmt mbus_fmt
;
1065 rc
= check_dev(dev
);
1069 vidioc_try_fmt_vid_cap(file
, priv
, f
);
1071 fmt
= format_by_fourcc(f
->fmt
.pix
.pixelformat
);
1075 if (videobuf_queue_is_busy(&fh
->vb_vidq
)) {
1076 cx231xx_errdev("%s queue busy\n", __func__
);
1080 if (dev
->stream_on
&& !fh
->stream_on
) {
1081 cx231xx_errdev("%s device in use by another fh\n", __func__
);
1085 /* set new image size */
1086 dev
->width
= f
->fmt
.pix
.width
;
1087 dev
->height
= f
->fmt
.pix
.height
;
1090 v4l2_fill_mbus_format(&mbus_fmt
, &f
->fmt
.pix
, V4L2_MBUS_FMT_FIXED
);
1091 call_all(dev
, video
, s_mbus_fmt
, &mbus_fmt
);
1092 v4l2_fill_pix_format(&f
->fmt
.pix
, &mbus_fmt
);
1097 static int vidioc_g_std(struct file
*file
, void *priv
, v4l2_std_id
*id
)
1099 struct cx231xx_fh
*fh
= priv
;
1100 struct cx231xx
*dev
= fh
->dev
;
1106 static int vidioc_s_std(struct file
*file
, void *priv
, v4l2_std_id
*norm
)
1108 struct cx231xx_fh
*fh
= priv
;
1109 struct cx231xx
*dev
= fh
->dev
;
1110 struct v4l2_mbus_framefmt mbus_fmt
;
1111 struct v4l2_format f
;
1114 rc
= check_dev(dev
);
1118 cx231xx_info("vidioc_s_std : 0x%x\n", (unsigned int)*norm
);
1122 /* Adjusts width/height, if needed */
1123 f
.fmt
.pix
.width
= dev
->width
;
1124 f
.fmt
.pix
.height
= dev
->height
;
1125 vidioc_try_fmt_vid_cap(file
, priv
, &f
);
1127 call_all(dev
, core
, s_std
, dev
->norm
);
1129 /* We need to reset basic properties in the decoder related to
1130 resolution (since a standard change effects things like the number
1131 of lines in VACT, etc) */
1132 v4l2_fill_mbus_format(&mbus_fmt
, &f
.fmt
.pix
, V4L2_MBUS_FMT_FIXED
);
1133 call_all(dev
, video
, s_mbus_fmt
, &mbus_fmt
);
1134 v4l2_fill_pix_format(&f
.fmt
.pix
, &mbus_fmt
);
1136 /* set new image size */
1137 dev
->width
= f
.fmt
.pix
.width
;
1138 dev
->height
= f
.fmt
.pix
.height
;
1140 /* do mode control overrides */
1141 cx231xx_do_mode_ctrl_overrides(dev
);
1146 static const char *iname
[] = {
1147 [CX231XX_VMUX_COMPOSITE1
] = "Composite1",
1148 [CX231XX_VMUX_SVIDEO
] = "S-Video",
1149 [CX231XX_VMUX_TELEVISION
] = "Television",
1150 [CX231XX_VMUX_CABLE
] = "Cable TV",
1151 [CX231XX_VMUX_DVB
] = "DVB",
1152 [CX231XX_VMUX_DEBUG
] = "for debug only",
1155 static int vidioc_enum_input(struct file
*file
, void *priv
,
1156 struct v4l2_input
*i
)
1158 struct cx231xx_fh
*fh
= priv
;
1159 struct cx231xx
*dev
= fh
->dev
;
1161 unsigned int ret
, n
;
1164 if (n
>= MAX_CX231XX_INPUT
)
1166 if (0 == INPUT(n
)->type
)
1170 i
->type
= V4L2_INPUT_TYPE_CAMERA
;
1172 strcpy(i
->name
, iname
[INPUT(n
)->type
]);
1174 if ((CX231XX_VMUX_TELEVISION
== INPUT(n
)->type
) ||
1175 (CX231XX_VMUX_CABLE
== INPUT(n
)->type
))
1176 i
->type
= V4L2_INPUT_TYPE_TUNER
;
1178 i
->std
= dev
->vdev
->tvnorms
;
1180 /* If they are asking about the active input, read signal status */
1181 if (n
== dev
->video_input
) {
1182 ret
= cx231xx_read_i2c_data(dev
, VID_BLK_I2C_ADDRESS
,
1183 GEN_STAT
, 2, &gen_stat
, 4);
1185 if ((gen_stat
& FLD_VPRES
) == 0x00)
1186 i
->status
|= V4L2_IN_ST_NO_SIGNAL
;
1187 if ((gen_stat
& FLD_HLOCK
) == 0x00)
1188 i
->status
|= V4L2_IN_ST_NO_H_LOCK
;
1195 static int vidioc_g_input(struct file
*file
, void *priv
, unsigned int *i
)
1197 struct cx231xx_fh
*fh
= priv
;
1198 struct cx231xx
*dev
= fh
->dev
;
1200 *i
= dev
->video_input
;
1205 static int vidioc_s_input(struct file
*file
, void *priv
, unsigned int i
)
1207 struct cx231xx_fh
*fh
= priv
;
1208 struct cx231xx
*dev
= fh
->dev
;
1212 rc
= check_dev(dev
);
1216 if (i
>= MAX_CX231XX_INPUT
)
1218 if (0 == INPUT(i
)->type
)
1223 if (INPUT(i
)->type
== CX231XX_VMUX_TELEVISION
||
1224 INPUT(i
)->type
== CX231XX_VMUX_CABLE
) {
1225 /* There's a tuner, so reset the standard and put it on the
1226 last known frequency (since it was probably powered down
1228 call_all(dev
, core
, s_std
, dev
->norm
);
1234 static int vidioc_g_audio(struct file
*file
, void *priv
, struct v4l2_audio
*a
)
1236 struct cx231xx_fh
*fh
= priv
;
1237 struct cx231xx
*dev
= fh
->dev
;
1240 case CX231XX_AMUX_VIDEO
:
1241 strcpy(a
->name
, "Television");
1243 case CX231XX_AMUX_LINE_IN
:
1244 strcpy(a
->name
, "Line In");
1250 a
->index
= dev
->ctl_ainput
;
1251 a
->capability
= V4L2_AUDCAP_STEREO
;
1256 static int vidioc_s_audio(struct file
*file
, void *priv
, struct v4l2_audio
*a
)
1258 struct cx231xx_fh
*fh
= priv
;
1259 struct cx231xx
*dev
= fh
->dev
;
1262 /* Doesn't allow manual routing */
1263 if (a
->index
!= dev
->ctl_ainput
)
1266 dev
->ctl_ainput
= INPUT(a
->index
)->amux
;
1267 status
= cx231xx_set_audio_input(dev
, dev
->ctl_ainput
);
1272 static int vidioc_queryctrl(struct file
*file
, void *priv
,
1273 struct v4l2_queryctrl
*qc
)
1275 struct cx231xx_fh
*fh
= priv
;
1276 struct cx231xx
*dev
= fh
->dev
;
1281 rc
= check_dev(dev
);
1285 qc
->id
= v4l2_ctrl_next(ctrl_classes
, qc
->id
);
1286 if (unlikely(qc
->id
== 0))
1289 memset(qc
, 0, sizeof(*qc
));
1293 if (qc
->id
< V4L2_CID_BASE
|| qc
->id
>= V4L2_CID_LASTP1
)
1296 for (i
= 0; i
< CX231XX_CTLS
; i
++)
1297 if (cx231xx_ctls
[i
].v
.id
== qc
->id
)
1300 if (i
== CX231XX_CTLS
) {
1304 *qc
= cx231xx_ctls
[i
].v
;
1306 call_all(dev
, core
, queryctrl
, qc
);
1314 static int vidioc_g_ctrl(struct file
*file
, void *priv
,
1315 struct v4l2_control
*ctrl
)
1317 struct cx231xx_fh
*fh
= priv
;
1318 struct cx231xx
*dev
= fh
->dev
;
1321 rc
= check_dev(dev
);
1325 call_all(dev
, core
, g_ctrl
, ctrl
);
1329 static int vidioc_s_ctrl(struct file
*file
, void *priv
,
1330 struct v4l2_control
*ctrl
)
1332 struct cx231xx_fh
*fh
= priv
;
1333 struct cx231xx
*dev
= fh
->dev
;
1336 rc
= check_dev(dev
);
1340 call_all(dev
, core
, s_ctrl
, ctrl
);
1344 static int vidioc_g_tuner(struct file
*file
, void *priv
, struct v4l2_tuner
*t
)
1346 struct cx231xx_fh
*fh
= priv
;
1347 struct cx231xx
*dev
= fh
->dev
;
1350 rc
= check_dev(dev
);
1357 strcpy(t
->name
, "Tuner");
1359 t
->type
= V4L2_TUNER_ANALOG_TV
;
1360 t
->capability
= V4L2_TUNER_CAP_NORM
;
1361 t
->rangehigh
= 0xffffffffUL
;
1362 t
->signal
= 0xffff; /* LOCKED */
1367 static int vidioc_s_tuner(struct file
*file
, void *priv
, struct v4l2_tuner
*t
)
1369 struct cx231xx_fh
*fh
= priv
;
1370 struct cx231xx
*dev
= fh
->dev
;
1373 rc
= check_dev(dev
);
1380 call_all(dev
, tuner
, s_tuner
, t
);
1385 static int vidioc_g_frequency(struct file
*file
, void *priv
,
1386 struct v4l2_frequency
*f
)
1388 struct cx231xx_fh
*fh
= priv
;
1389 struct cx231xx
*dev
= fh
->dev
;
1391 f
->type
= fh
->radio
? V4L2_TUNER_RADIO
: V4L2_TUNER_ANALOG_TV
;
1392 f
->frequency
= dev
->ctl_freq
;
1394 call_all(dev
, tuner
, g_frequency
, f
);
1399 static int vidioc_s_frequency(struct file
*file
, void *priv
,
1400 struct v4l2_frequency
*f
)
1402 struct cx231xx_fh
*fh
= priv
;
1403 struct cx231xx
*dev
= fh
->dev
;
1405 u32 if_frequency
= 5400000;
1407 cx231xx_info("Enter vidioc_s_frequency()f->frequency=%d;f->type=%d\n",
1408 f
->frequency
, f
->type
);
1409 /*cx231xx_info("f->type: 1-radio 2-analogTV 3-digitalTV\n");*/
1411 rc
= check_dev(dev
);
1418 if (unlikely(0 == fh
->radio
&& f
->type
!= V4L2_TUNER_ANALOG_TV
))
1420 if (unlikely(1 == fh
->radio
&& f
->type
!= V4L2_TUNER_RADIO
))
1423 /* set pre channel change settings in DIF first */
1424 rc
= cx231xx_tuner_pre_channel_change(dev
);
1426 dev
->ctl_freq
= f
->frequency
;
1427 call_all(dev
, tuner
, s_frequency
, f
);
1429 /* set post channel change settings in DIF first */
1430 rc
= cx231xx_tuner_post_channel_change(dev
);
1432 if (dev
->tuner_type
== TUNER_NXP_TDA18271
) {
1433 if (dev
->norm
& (V4L2_STD_MN
| V4L2_STD_NTSC_443
))
1434 if_frequency
= 5400000; /*5.4MHz */
1435 else if (dev
->norm
& V4L2_STD_B
)
1436 if_frequency
= 6000000; /*6.0MHz */
1437 else if (dev
->norm
& (V4L2_STD_PAL_DK
| V4L2_STD_SECAM_DK
))
1438 if_frequency
= 6900000; /*6.9MHz */
1439 else if (dev
->norm
& V4L2_STD_GH
)
1440 if_frequency
= 7100000; /*7.1MHz */
1441 else if (dev
->norm
& V4L2_STD_PAL_I
)
1442 if_frequency
= 7250000; /*7.25MHz */
1443 else if (dev
->norm
& V4L2_STD_SECAM_L
)
1444 if_frequency
= 6900000; /*6.9MHz */
1445 else if (dev
->norm
& V4L2_STD_SECAM_LC
)
1446 if_frequency
= 1250000; /*1.25MHz */
1448 cx231xx_info("if_frequency is set to %d\n", if_frequency
);
1449 cx231xx_set_Colibri_For_LowIF(dev
, if_frequency
, 1, 1);
1451 update_HH_register_after_set_DIF(dev
);
1454 cx231xx_info("Set New FREQUENCY to %d\n", f
->frequency
);
1459 #ifdef CONFIG_VIDEO_ADV_DEBUG
1462 -R, --list-registers=type=<host/i2cdrv/i2caddr>,
1463 chip=<chip>[,min=<addr>,max=<addr>]
1464 dump registers from <min> to <max> [VIDIOC_DBG_G_REGISTER]
1465 -r, --set-register=type=<host/i2cdrv/i2caddr>,
1466 chip=<chip>,reg=<addr>,val=<val>
1467 set the register [VIDIOC_DBG_S_REGISTER]
1469 if type == host, then <chip> is the hosts chip ID (default 0)
1470 if type == i2cdrv (default), then <chip> is the I2C driver name or ID
1471 if type == i2caddr, then <chip> is the 7-bit I2C address
1474 static int vidioc_g_register(struct file
*file
, void *priv
,
1475 struct v4l2_dbg_register
*reg
)
1477 struct cx231xx_fh
*fh
= priv
;
1478 struct cx231xx
*dev
= fh
->dev
;
1480 u8 value
[4] = { 0, 0, 0, 0 };
1483 switch (reg
->match
.type
) {
1484 case V4L2_CHIP_MATCH_HOST
:
1485 switch (reg
->match
.addr
) {
1486 case 0: /* Cx231xx - internal registers */
1487 ret
= cx231xx_read_ctrl_reg(dev
, VRT_GET_REGISTER
,
1488 (u16
)reg
->reg
, value
, 4);
1489 reg
->val
= value
[0] | value
[1] << 8 |
1490 value
[2] << 16 | value
[3] << 24;
1492 case 1: /* AFE - read byte */
1493 ret
= cx231xx_read_i2c_data(dev
, AFE_DEVICE_ADDRESS
,
1494 (u16
)reg
->reg
, 2, &data
, 1);
1495 reg
->val
= le32_to_cpu(data
& 0xff);
1497 case 14: /* AFE - read dword */
1498 ret
= cx231xx_read_i2c_data(dev
, AFE_DEVICE_ADDRESS
,
1499 (u16
)reg
->reg
, 2, &data
, 4);
1500 reg
->val
= le32_to_cpu(data
);
1502 case 2: /* Video Block - read byte */
1503 ret
= cx231xx_read_i2c_data(dev
, VID_BLK_I2C_ADDRESS
,
1504 (u16
)reg
->reg
, 2, &data
, 1);
1505 reg
->val
= le32_to_cpu(data
& 0xff);
1507 case 24: /* Video Block - read dword */
1508 ret
= cx231xx_read_i2c_data(dev
, VID_BLK_I2C_ADDRESS
,
1509 (u16
)reg
->reg
, 2, &data
, 4);
1510 reg
->val
= le32_to_cpu(data
);
1512 case 3: /* I2S block - read byte */
1513 ret
= cx231xx_read_i2c_data(dev
,
1514 I2S_BLK_DEVICE_ADDRESS
,
1517 reg
->val
= le32_to_cpu(data
& 0xff);
1519 case 34: /* I2S Block - read dword */
1521 cx231xx_read_i2c_data(dev
, I2S_BLK_DEVICE_ADDRESS
,
1522 (u16
)reg
->reg
, 1, &data
, 4);
1523 reg
->val
= le32_to_cpu(data
);
1526 return ret
< 0 ? ret
: 0;
1528 case V4L2_CHIP_MATCH_I2C_DRIVER
:
1529 call_all(dev
, core
, g_register
, reg
);
1531 case V4L2_CHIP_MATCH_I2C_ADDR
:/*for register debug*/
1532 switch (reg
->match
.addr
) {
1533 case 0: /* Cx231xx - internal registers */
1534 ret
= cx231xx_read_ctrl_reg(dev
, VRT_GET_REGISTER
,
1535 (u16
)reg
->reg
, value
, 4);
1536 reg
->val
= value
[0] | value
[1] << 8 |
1537 value
[2] << 16 | value
[3] << 24;
1540 case 0x600:/* AFE - read byte */
1541 ret
= cx231xx_read_i2c_master(dev
, AFE_DEVICE_ADDRESS
,
1544 reg
->val
= le32_to_cpu(data
& 0xff);
1547 case 0x880:/* Video Block - read byte */
1548 if (reg
->reg
< 0x0b) {
1549 ret
= cx231xx_read_i2c_master(dev
,
1550 VID_BLK_I2C_ADDRESS
,
1553 reg
->val
= le32_to_cpu(data
& 0xff);
1555 ret
= cx231xx_read_i2c_master(dev
,
1556 VID_BLK_I2C_ADDRESS
,
1559 reg
->val
= le32_to_cpu(data
);
1563 ret
= cx231xx_read_i2c_master(dev
,
1564 I2S_BLK_DEVICE_ADDRESS
,
1567 reg
->val
= le32_to_cpu(data
& 0xff);
1571 cx231xx_read_i2c_master(dev
, 0x40,
1574 reg
->val
= le32_to_cpu(data
& 0xff);
1578 cx231xx_read_i2c_master(dev
, 0xc0,
1581 reg
->val
= le32_to_cpu(data
);
1585 cx231xx_read_i2c_master(dev
, 0x02,
1588 reg
->val
= le32_to_cpu(data
& 0xff);
1591 ret
= cx231xx_read_i2c_master(dev
,
1595 reg
->val
= le32_to_cpu(data
);
1598 ret
= cx231xx_read_i2c_master(dev
,
1602 reg
->val
= le32_to_cpu(data
);
1606 cx231xx_info("no match device address!!\n");
1609 return ret
< 0 ? ret
: 0;
1612 if (!v4l2_chip_match_host(®
->match
))
1616 call_all(dev
, core
, g_register
, reg
);
1621 static int vidioc_s_register(struct file
*file
, void *priv
,
1622 struct v4l2_dbg_register
*reg
)
1624 struct cx231xx_fh
*fh
= priv
;
1625 struct cx231xx
*dev
= fh
->dev
;
1629 u8 data
[4] = { 0, 0, 0, 0 };
1631 buf
= cpu_to_le64(reg
->val
);
1633 switch (reg
->match
.type
) {
1634 case V4L2_CHIP_MATCH_HOST
:
1636 value
= (u32
) buf
& 0xffffffff;
1638 switch (reg
->match
.addr
) {
1639 case 0: /* cx231xx internal registers */
1640 data
[0] = (u8
) value
;
1641 data
[1] = (u8
) (value
>> 8);
1642 data
[2] = (u8
) (value
>> 16);
1643 data
[3] = (u8
) (value
>> 24);
1644 ret
= cx231xx_write_ctrl_reg(dev
,
1646 (u16
)reg
->reg
, data
,
1649 case 1: /* AFE - read byte */
1650 ret
= cx231xx_write_i2c_data(dev
,
1655 case 14: /* AFE - read dword */
1656 ret
= cx231xx_write_i2c_data(dev
,
1661 case 2: /* Video Block - read byte */
1663 cx231xx_write_i2c_data(dev
,
1664 VID_BLK_I2C_ADDRESS
,
1668 case 24: /* Video Block - read dword */
1670 cx231xx_write_i2c_data(dev
,
1671 VID_BLK_I2C_ADDRESS
,
1675 case 3: /* I2S block - read byte */
1677 cx231xx_write_i2c_data(dev
,
1678 I2S_BLK_DEVICE_ADDRESS
,
1682 case 34: /* I2S block - read dword */
1684 cx231xx_write_i2c_data(dev
,
1685 I2S_BLK_DEVICE_ADDRESS
,
1691 return ret
< 0 ? ret
: 0;
1692 case V4L2_CHIP_MATCH_I2C_ADDR
:
1694 value
= (u32
) buf
& 0xffffffff;
1696 switch (reg
->match
.addr
) {
1697 case 0:/*cx231xx internal registers*/
1698 data
[0] = (u8
) value
;
1699 data
[1] = (u8
) (value
>> 8);
1700 data
[2] = (u8
) (value
>> 16);
1701 data
[3] = (u8
) (value
>> 24);
1702 ret
= cx231xx_write_ctrl_reg(dev
,
1704 (u16
)reg
->reg
, data
,
1707 case 0x600:/* AFE - read byte */
1708 ret
= cx231xx_write_i2c_master(dev
,
1714 case 0x880:/* Video Block - read byte */
1715 if (reg
->reg
< 0x0b)
1716 cx231xx_write_i2c_master(dev
,
1717 VID_BLK_I2C_ADDRESS
,
1721 cx231xx_write_i2c_master(dev
,
1722 VID_BLK_I2C_ADDRESS
,
1728 cx231xx_write_i2c_master(dev
,
1729 I2S_BLK_DEVICE_ADDRESS
,
1735 cx231xx_write_i2c_master(dev
,
1742 cx231xx_write_i2c_master(dev
,
1750 cx231xx_write_i2c_master(dev
,
1756 cx231xx_write_i2c_master(dev
,
1764 cx231xx_write_i2c_master(dev
,
1770 cx231xx_info("no match device address, "
1771 "the value is %x\n", reg
->match
.addr
);
1781 call_all(dev
, core
, s_register
, reg
);
1787 static int vidioc_cropcap(struct file
*file
, void *priv
,
1788 struct v4l2_cropcap
*cc
)
1790 struct cx231xx_fh
*fh
= priv
;
1791 struct cx231xx
*dev
= fh
->dev
;
1793 if (cc
->type
!= V4L2_BUF_TYPE_VIDEO_CAPTURE
)
1796 cc
->bounds
.left
= 0;
1798 cc
->bounds
.width
= dev
->width
;
1799 cc
->bounds
.height
= dev
->height
;
1800 cc
->defrect
= cc
->bounds
;
1801 cc
->pixelaspect
.numerator
= 54; /* 4:3 FIXME: remove magic numbers */
1802 cc
->pixelaspect
.denominator
= 59;
1807 static int vidioc_streamon(struct file
*file
, void *priv
,
1808 enum v4l2_buf_type type
)
1810 struct cx231xx_fh
*fh
= priv
;
1811 struct cx231xx
*dev
= fh
->dev
;
1814 rc
= check_dev(dev
);
1820 if (likely(rc
>= 0))
1821 rc
= videobuf_streamon(&fh
->vb_vidq
);
1823 call_all(dev
, video
, s_stream
, 1);
1828 static int vidioc_streamoff(struct file
*file
, void *priv
,
1829 enum v4l2_buf_type type
)
1831 struct cx231xx_fh
*fh
= priv
;
1832 struct cx231xx
*dev
= fh
->dev
;
1835 rc
= check_dev(dev
);
1839 if ((fh
->type
!= V4L2_BUF_TYPE_VIDEO_CAPTURE
) &&
1840 (fh
->type
!= V4L2_BUF_TYPE_VBI_CAPTURE
))
1842 if (type
!= fh
->type
)
1845 cx25840_call(dev
, video
, s_stream
, 0);
1847 videobuf_streamoff(&fh
->vb_vidq
);
1853 static int vidioc_querycap(struct file
*file
, void *priv
,
1854 struct v4l2_capability
*cap
)
1856 struct cx231xx_fh
*fh
= priv
;
1857 struct cx231xx
*dev
= fh
->dev
;
1859 strlcpy(cap
->driver
, "cx231xx", sizeof(cap
->driver
));
1860 strlcpy(cap
->card
, cx231xx_boards
[dev
->model
].name
, sizeof(cap
->card
));
1861 usb_make_path(dev
->udev
, cap
->bus_info
, sizeof(cap
->bus_info
));
1863 cap
->capabilities
= V4L2_CAP_VBI_CAPTURE
|
1865 V4L2_CAP_SLICED_VBI_CAPTURE
|
1867 V4L2_CAP_VIDEO_CAPTURE
|
1869 V4L2_CAP_READWRITE
|
1872 if (dev
->tuner_type
!= TUNER_ABSENT
)
1873 cap
->capabilities
|= V4L2_CAP_TUNER
;
1878 static int vidioc_enum_fmt_vid_cap(struct file
*file
, void *priv
,
1879 struct v4l2_fmtdesc
*f
)
1881 if (unlikely(f
->index
>= ARRAY_SIZE(format
)))
1884 strlcpy(f
->description
, format
[f
->index
].name
, sizeof(f
->description
));
1885 f
->pixelformat
= format
[f
->index
].fourcc
;
1890 /* Sliced VBI ioctls */
1891 static int vidioc_g_fmt_sliced_vbi_cap(struct file
*file
, void *priv
,
1892 struct v4l2_format
*f
)
1894 struct cx231xx_fh
*fh
= priv
;
1895 struct cx231xx
*dev
= fh
->dev
;
1898 rc
= check_dev(dev
);
1902 f
->fmt
.sliced
.service_set
= 0;
1904 call_all(dev
, vbi
, g_sliced_fmt
, &f
->fmt
.sliced
);
1906 if (f
->fmt
.sliced
.service_set
== 0)
1912 static int vidioc_try_set_sliced_vbi_cap(struct file
*file
, void *priv
,
1913 struct v4l2_format
*f
)
1915 struct cx231xx_fh
*fh
= priv
;
1916 struct cx231xx
*dev
= fh
->dev
;
1919 rc
= check_dev(dev
);
1923 call_all(dev
, vbi
, g_sliced_fmt
, &f
->fmt
.sliced
);
1925 if (f
->fmt
.sliced
.service_set
== 0)
1931 /* RAW VBI ioctls */
1933 static int vidioc_g_fmt_vbi_cap(struct file
*file
, void *priv
,
1934 struct v4l2_format
*f
)
1936 struct cx231xx_fh
*fh
= priv
;
1937 struct cx231xx
*dev
= fh
->dev
;
1938 f
->fmt
.vbi
.sampling_rate
= 6750000 * 4;
1939 f
->fmt
.vbi
.samples_per_line
= VBI_LINE_LENGTH
;
1940 f
->fmt
.vbi
.sample_format
= V4L2_PIX_FMT_GREY
;
1941 f
->fmt
.vbi
.offset
= 0;
1942 f
->fmt
.vbi
.start
[0] = (dev
->norm
& V4L2_STD_625_50
) ?
1943 PAL_VBI_START_LINE
: NTSC_VBI_START_LINE
;
1944 f
->fmt
.vbi
.count
[0] = (dev
->norm
& V4L2_STD_625_50
) ?
1945 PAL_VBI_LINES
: NTSC_VBI_LINES
;
1946 f
->fmt
.vbi
.start
[1] = (dev
->norm
& V4L2_STD_625_50
) ?
1947 PAL_VBI_START_LINE
+ 312 : NTSC_VBI_START_LINE
+ 263;
1948 f
->fmt
.vbi
.count
[1] = f
->fmt
.vbi
.count
[0];
1954 static int vidioc_try_fmt_vbi_cap(struct file
*file
, void *priv
,
1955 struct v4l2_format
*f
)
1957 struct cx231xx_fh
*fh
= priv
;
1958 struct cx231xx
*dev
= fh
->dev
;
1960 if (dev
->vbi_stream_on
&& !fh
->stream_on
) {
1961 cx231xx_errdev("%s device in use by another fh\n", __func__
);
1965 f
->type
= V4L2_BUF_TYPE_VBI_CAPTURE
;
1966 f
->fmt
.vbi
.sampling_rate
= 6750000 * 4;
1967 f
->fmt
.vbi
.samples_per_line
= VBI_LINE_LENGTH
;
1968 f
->fmt
.vbi
.sample_format
= V4L2_PIX_FMT_GREY
;
1969 f
->fmt
.vbi
.offset
= 0;
1970 f
->fmt
.vbi
.flags
= 0;
1971 f
->fmt
.vbi
.start
[0] = (dev
->norm
& V4L2_STD_625_50
) ?
1972 PAL_VBI_START_LINE
: NTSC_VBI_START_LINE
;
1973 f
->fmt
.vbi
.count
[0] = (dev
->norm
& V4L2_STD_625_50
) ?
1974 PAL_VBI_LINES
: NTSC_VBI_LINES
;
1975 f
->fmt
.vbi
.start
[1] = (dev
->norm
& V4L2_STD_625_50
) ?
1976 PAL_VBI_START_LINE
+ 312 : NTSC_VBI_START_LINE
+ 263;
1977 f
->fmt
.vbi
.count
[1] = f
->fmt
.vbi
.count
[0];
1983 static int vidioc_reqbufs(struct file
*file
, void *priv
,
1984 struct v4l2_requestbuffers
*rb
)
1986 struct cx231xx_fh
*fh
= priv
;
1987 struct cx231xx
*dev
= fh
->dev
;
1990 rc
= check_dev(dev
);
1994 return videobuf_reqbufs(&fh
->vb_vidq
, rb
);
1997 static int vidioc_querybuf(struct file
*file
, void *priv
, struct v4l2_buffer
*b
)
1999 struct cx231xx_fh
*fh
= priv
;
2000 struct cx231xx
*dev
= fh
->dev
;
2003 rc
= check_dev(dev
);
2007 return videobuf_querybuf(&fh
->vb_vidq
, b
);
2010 static int vidioc_qbuf(struct file
*file
, void *priv
, struct v4l2_buffer
*b
)
2012 struct cx231xx_fh
*fh
= priv
;
2013 struct cx231xx
*dev
= fh
->dev
;
2016 rc
= check_dev(dev
);
2020 return videobuf_qbuf(&fh
->vb_vidq
, b
);
2023 static int vidioc_dqbuf(struct file
*file
, void *priv
, struct v4l2_buffer
*b
)
2025 struct cx231xx_fh
*fh
= priv
;
2026 struct cx231xx
*dev
= fh
->dev
;
2029 rc
= check_dev(dev
);
2033 return videobuf_dqbuf(&fh
->vb_vidq
, b
, file
->f_flags
& O_NONBLOCK
);
2036 /* ----------------------------------------------------------- */
2037 /* RADIO ESPECIFIC IOCTLS */
2038 /* ----------------------------------------------------------- */
2040 static int radio_querycap(struct file
*file
, void *priv
,
2041 struct v4l2_capability
*cap
)
2043 struct cx231xx
*dev
= ((struct cx231xx_fh
*)priv
)->dev
;
2045 strlcpy(cap
->driver
, "cx231xx", sizeof(cap
->driver
));
2046 strlcpy(cap
->card
, cx231xx_boards
[dev
->model
].name
, sizeof(cap
->card
));
2047 usb_make_path(dev
->udev
, cap
->bus_info
, sizeof(cap
->bus_info
));
2049 cap
->capabilities
= V4L2_CAP_TUNER
;
2053 static int radio_g_tuner(struct file
*file
, void *priv
, struct v4l2_tuner
*t
)
2055 struct cx231xx
*dev
= ((struct cx231xx_fh
*)priv
)->dev
;
2057 if (unlikely(t
->index
> 0))
2060 strcpy(t
->name
, "Radio");
2061 t
->type
= V4L2_TUNER_RADIO
;
2063 call_all(dev
, tuner
, s_tuner
, t
);
2068 static int radio_enum_input(struct file
*file
, void *priv
, struct v4l2_input
*i
)
2072 strcpy(i
->name
, "Radio");
2073 i
->type
= V4L2_INPUT_TYPE_TUNER
;
2078 static int radio_g_audio(struct file
*file
, void *priv
, struct v4l2_audio
*a
)
2080 if (unlikely(a
->index
))
2083 strcpy(a
->name
, "Radio");
2087 static int radio_s_tuner(struct file
*file
, void *priv
, struct v4l2_tuner
*t
)
2089 struct cx231xx
*dev
= ((struct cx231xx_fh
*)priv
)->dev
;
2094 call_all(dev
, tuner
, s_tuner
, t
);
2099 static int radio_s_audio(struct file
*file
, void *fh
, struct v4l2_audio
*a
)
2104 static int radio_s_input(struct file
*file
, void *fh
, unsigned int i
)
2109 static int radio_queryctrl(struct file
*file
, void *priv
,
2110 struct v4l2_queryctrl
*c
)
2114 if (c
->id
< V4L2_CID_BASE
|| c
->id
>= V4L2_CID_LASTP1
)
2116 if (c
->id
== V4L2_CID_AUDIO_MUTE
) {
2117 for (i
= 0; i
< CX231XX_CTLS
; i
++) {
2118 if (cx231xx_ctls
[i
].v
.id
== c
->id
)
2121 if (i
== CX231XX_CTLS
)
2123 *c
= cx231xx_ctls
[i
].v
;
2130 * cx231xx_v4l2_open()
2131 * inits the device and starts isoc transfer
2133 static int cx231xx_v4l2_open(struct file
*filp
)
2135 int errCode
= 0, radio
= 0;
2136 struct video_device
*vdev
= video_devdata(filp
);
2137 struct cx231xx
*dev
= video_drvdata(filp
);
2138 struct cx231xx_fh
*fh
;
2139 enum v4l2_buf_type fh_type
= 0;
2141 switch (vdev
->vfl_type
) {
2142 case VFL_TYPE_GRABBER
:
2143 fh_type
= V4L2_BUF_TYPE_VIDEO_CAPTURE
;
2146 fh_type
= V4L2_BUF_TYPE_VBI_CAPTURE
;
2148 case VFL_TYPE_RADIO
:
2153 cx231xx_videodbg("open dev=%s type=%s users=%d\n",
2154 video_device_node_name(vdev
), v4l2_type_names
[fh_type
],
2158 errCode
= cx231xx_set_mode(dev
, CX231XX_ANALOG_MODE
);
2161 ("Device locked on digital mode. Can't open analog\n");
2166 fh
= kzalloc(sizeof(struct cx231xx_fh
), GFP_KERNEL
);
2168 cx231xx_errdev("cx231xx-video.c: Out of memory?!\n");
2171 if (mutex_lock_interruptible(&dev
->lock
)) {
2173 return -ERESTARTSYS
;
2178 filp
->private_data
= fh
;
2180 if (fh
->type
== V4L2_BUF_TYPE_VIDEO_CAPTURE
&& dev
->users
== 0) {
2181 dev
->width
= norm_maxw(dev
);
2182 dev
->height
= norm_maxh(dev
);
2184 /* Power up in Analog TV mode */
2185 if (dev
->board
.external_av
)
2186 cx231xx_set_power_mode(dev
,
2187 POLARIS_AVMODE_ENXTERNAL_AV
);
2189 cx231xx_set_power_mode(dev
, POLARIS_AVMODE_ANALOGT_TV
);
2192 cx231xx_set_mode(dev
, CX231XX_ANALOG_MODE
);
2195 /* set video alternate setting */
2196 cx231xx_set_video_alternate(dev
);
2198 /* Needed, since GPIO might have disabled power of
2200 cx231xx_config_i2c(dev
);
2202 /* device needs to be initialized before isoc transfer */
2203 dev
->video_input
= dev
->video_input
> 2 ? 2 : dev
->video_input
;
2207 cx231xx_videodbg("video_open: setting radio device\n");
2209 /* cx231xx_start_radio(dev); */
2211 call_all(dev
, tuner
, s_radio
);
2216 if (fh
->type
== V4L2_BUF_TYPE_VIDEO_CAPTURE
)
2217 videobuf_queue_vmalloc_init(&fh
->vb_vidq
, &cx231xx_video_qops
,
2218 NULL
, &dev
->video_mode
.slock
,
2219 fh
->type
, V4L2_FIELD_INTERLACED
,
2220 sizeof(struct cx231xx_buffer
),
2222 if (fh
->type
== V4L2_BUF_TYPE_VBI_CAPTURE
) {
2223 /* Set the required alternate setting VBI interface works in
2225 cx231xx_set_alt_setting(dev
, INDEX_VANC
, 0);
2227 videobuf_queue_vmalloc_init(&fh
->vb_vidq
, &cx231xx_vbi_qops
,
2228 NULL
, &dev
->vbi_mode
.slock
,
2229 fh
->type
, V4L2_FIELD_SEQ_TB
,
2230 sizeof(struct cx231xx_buffer
),
2233 mutex_unlock(&dev
->lock
);
2239 * cx231xx_realease_resources()
2240 * unregisters the v4l2,i2c and usb devices
2241 * called when the device gets disconected or at module unload
2243 void cx231xx_release_analog_resources(struct cx231xx
*dev
)
2246 /*FIXME: I2C IR should be disconnected */
2248 if (dev
->radio_dev
) {
2249 if (video_is_registered(dev
->radio_dev
))
2250 video_unregister_device(dev
->radio_dev
);
2252 video_device_release(dev
->radio_dev
);
2253 dev
->radio_dev
= NULL
;
2256 cx231xx_info("V4L2 device %s deregistered\n",
2257 video_device_node_name(dev
->vbi_dev
));
2258 if (video_is_registered(dev
->vbi_dev
))
2259 video_unregister_device(dev
->vbi_dev
);
2261 video_device_release(dev
->vbi_dev
);
2262 dev
->vbi_dev
= NULL
;
2265 cx231xx_info("V4L2 device %s deregistered\n",
2266 video_device_node_name(dev
->vdev
));
2268 if (dev
->board
.has_417
)
2269 cx231xx_417_unregister(dev
);
2271 if (video_is_registered(dev
->vdev
))
2272 video_unregister_device(dev
->vdev
);
2274 video_device_release(dev
->vdev
);
2281 * stops streaming and deallocates all resources allocated by the v4l2
2284 static int cx231xx_close(struct file
*filp
)
2286 struct cx231xx_fh
*fh
= filp
->private_data
;
2287 struct cx231xx
*dev
= fh
->dev
;
2289 cx231xx_videodbg("users=%d\n", dev
->users
);
2291 cx231xx_videodbg("users=%d\n", dev
->users
);
2296 * To workaround error number=-71 on EP0 for VideoGrabber,
2297 * need exclude following.
2298 * FIXME: It is probably safe to remove most of these, as we're
2299 * now avoiding the alternate setting for INDEX_VANC
2301 if (!dev
->board
.no_alt_vanc
)
2302 if (fh
->type
== V4L2_BUF_TYPE_VBI_CAPTURE
) {
2303 videobuf_stop(&fh
->vb_vidq
);
2304 videobuf_mmap_free(&fh
->vb_vidq
);
2306 /* the device is already disconnect,
2307 free the remaining resources */
2308 if (dev
->state
& DEV_DISCONNECTED
) {
2309 if (atomic_read(&dev
->devlist_count
) > 0) {
2310 cx231xx_release_resources(dev
);
2317 /* do this before setting alternate! */
2318 cx231xx_uninit_vbi_isoc(dev
);
2320 /* set alternate 0 */
2321 if (!dev
->vbi_or_sliced_cc_mode
)
2322 cx231xx_set_alt_setting(dev
, INDEX_VANC
, 0);
2324 cx231xx_set_alt_setting(dev
, INDEX_HANC
, 0);
2328 wake_up_interruptible_nr(&dev
->open
, 1);
2334 videobuf_stop(&fh
->vb_vidq
);
2335 videobuf_mmap_free(&fh
->vb_vidq
);
2337 /* the device is already disconnect,
2338 free the remaining resources */
2339 if (dev
->state
& DEV_DISCONNECTED
) {
2340 cx231xx_release_resources(dev
);
2345 /* Save some power by putting tuner to sleep */
2346 call_all(dev
, core
, s_power
, 0);
2348 /* do this before setting alternate! */
2350 cx231xx_uninit_isoc(dev
);
2352 cx231xx_uninit_bulk(dev
);
2353 cx231xx_set_mode(dev
, CX231XX_SUSPEND
);
2355 /* set alternate 0 */
2356 cx231xx_set_alt_setting(dev
, INDEX_VIDEO
, 0);
2359 wake_up_interruptible_nr(&dev
->open
, 1);
2363 static int cx231xx_v4l2_close(struct file
*filp
)
2365 struct cx231xx_fh
*fh
= filp
->private_data
;
2366 struct cx231xx
*dev
= fh
->dev
;
2369 mutex_lock(&dev
->lock
);
2370 rc
= cx231xx_close(filp
);
2371 mutex_unlock(&dev
->lock
);
2376 * cx231xx_v4l2_read()
2377 * will allocate buffers when called for the first time
2380 cx231xx_v4l2_read(struct file
*filp
, char __user
*buf
, size_t count
,
2383 struct cx231xx_fh
*fh
= filp
->private_data
;
2384 struct cx231xx
*dev
= fh
->dev
;
2387 rc
= check_dev(dev
);
2391 if ((fh
->type
== V4L2_BUF_TYPE_VIDEO_CAPTURE
) ||
2392 (fh
->type
== V4L2_BUF_TYPE_VBI_CAPTURE
)) {
2395 if (unlikely(rc
< 0))
2398 if (mutex_lock_interruptible(&dev
->lock
))
2399 return -ERESTARTSYS
;
2400 rc
= videobuf_read_stream(&fh
->vb_vidq
, buf
, count
, pos
, 0,
2401 filp
->f_flags
& O_NONBLOCK
);
2402 mutex_unlock(&dev
->lock
);
2409 * cx231xx_v4l2_poll()
2410 * will allocate buffers when called for the first time
2412 static unsigned int cx231xx_v4l2_poll(struct file
*filp
, poll_table
*wait
)
2414 struct cx231xx_fh
*fh
= filp
->private_data
;
2415 struct cx231xx
*dev
= fh
->dev
;
2418 rc
= check_dev(dev
);
2424 if (unlikely(rc
< 0))
2427 if ((V4L2_BUF_TYPE_VIDEO_CAPTURE
== fh
->type
) ||
2428 (V4L2_BUF_TYPE_VBI_CAPTURE
== fh
->type
)) {
2431 mutex_lock(&dev
->lock
);
2432 res
= videobuf_poll_stream(filp
, &fh
->vb_vidq
, wait
);
2433 mutex_unlock(&dev
->lock
);
2440 * cx231xx_v4l2_mmap()
2442 static int cx231xx_v4l2_mmap(struct file
*filp
, struct vm_area_struct
*vma
)
2444 struct cx231xx_fh
*fh
= filp
->private_data
;
2445 struct cx231xx
*dev
= fh
->dev
;
2448 rc
= check_dev(dev
);
2454 if (unlikely(rc
< 0))
2457 if (mutex_lock_interruptible(&dev
->lock
))
2458 return -ERESTARTSYS
;
2459 rc
= videobuf_mmap_mapper(&fh
->vb_vidq
, vma
);
2460 mutex_unlock(&dev
->lock
);
2462 cx231xx_videodbg("vma start=0x%08lx, size=%ld, ret=%d\n",
2463 (unsigned long)vma
->vm_start
,
2464 (unsigned long)vma
->vm_end
-
2465 (unsigned long)vma
->vm_start
, rc
);
2470 static const struct v4l2_file_operations cx231xx_v4l_fops
= {
2471 .owner
= THIS_MODULE
,
2472 .open
= cx231xx_v4l2_open
,
2473 .release
= cx231xx_v4l2_close
,
2474 .read
= cx231xx_v4l2_read
,
2475 .poll
= cx231xx_v4l2_poll
,
2476 .mmap
= cx231xx_v4l2_mmap
,
2477 .unlocked_ioctl
= video_ioctl2
,
2480 static const struct v4l2_ioctl_ops video_ioctl_ops
= {
2481 .vidioc_querycap
= vidioc_querycap
,
2482 .vidioc_enum_fmt_vid_cap
= vidioc_enum_fmt_vid_cap
,
2483 .vidioc_g_fmt_vid_cap
= vidioc_g_fmt_vid_cap
,
2484 .vidioc_try_fmt_vid_cap
= vidioc_try_fmt_vid_cap
,
2485 .vidioc_s_fmt_vid_cap
= vidioc_s_fmt_vid_cap
,
2486 .vidioc_g_fmt_vbi_cap
= vidioc_g_fmt_vbi_cap
,
2487 .vidioc_try_fmt_vbi_cap
= vidioc_try_fmt_vbi_cap
,
2488 .vidioc_s_fmt_vbi_cap
= vidioc_try_fmt_vbi_cap
,
2489 .vidioc_g_audio
= vidioc_g_audio
,
2490 .vidioc_s_audio
= vidioc_s_audio
,
2491 .vidioc_cropcap
= vidioc_cropcap
,
2492 .vidioc_g_fmt_sliced_vbi_cap
= vidioc_g_fmt_sliced_vbi_cap
,
2493 .vidioc_try_fmt_sliced_vbi_cap
= vidioc_try_set_sliced_vbi_cap
,
2494 .vidioc_reqbufs
= vidioc_reqbufs
,
2495 .vidioc_querybuf
= vidioc_querybuf
,
2496 .vidioc_qbuf
= vidioc_qbuf
,
2497 .vidioc_dqbuf
= vidioc_dqbuf
,
2498 .vidioc_s_std
= vidioc_s_std
,
2499 .vidioc_g_std
= vidioc_g_std
,
2500 .vidioc_enum_input
= vidioc_enum_input
,
2501 .vidioc_g_input
= vidioc_g_input
,
2502 .vidioc_s_input
= vidioc_s_input
,
2503 .vidioc_queryctrl
= vidioc_queryctrl
,
2504 .vidioc_g_ctrl
= vidioc_g_ctrl
,
2505 .vidioc_s_ctrl
= vidioc_s_ctrl
,
2506 .vidioc_streamon
= vidioc_streamon
,
2507 .vidioc_streamoff
= vidioc_streamoff
,
2508 .vidioc_g_tuner
= vidioc_g_tuner
,
2509 .vidioc_s_tuner
= vidioc_s_tuner
,
2510 .vidioc_g_frequency
= vidioc_g_frequency
,
2511 .vidioc_s_frequency
= vidioc_s_frequency
,
2512 #ifdef CONFIG_VIDEO_ADV_DEBUG
2513 .vidioc_g_register
= vidioc_g_register
,
2514 .vidioc_s_register
= vidioc_s_register
,
2518 static struct video_device cx231xx_vbi_template
;
2520 static const struct video_device cx231xx_video_template
= {
2521 .fops
= &cx231xx_v4l_fops
,
2522 .release
= video_device_release
,
2523 .ioctl_ops
= &video_ioctl_ops
,
2524 .tvnorms
= V4L2_STD_ALL
,
2525 .current_norm
= V4L2_STD_PAL
,
2528 static const struct v4l2_file_operations radio_fops
= {
2529 .owner
= THIS_MODULE
,
2530 .open
= cx231xx_v4l2_open
,
2531 .release
= cx231xx_v4l2_close
,
2532 .ioctl
= video_ioctl2
,
2535 static const struct v4l2_ioctl_ops radio_ioctl_ops
= {
2536 .vidioc_querycap
= radio_querycap
,
2537 .vidioc_g_tuner
= radio_g_tuner
,
2538 .vidioc_enum_input
= radio_enum_input
,
2539 .vidioc_g_audio
= radio_g_audio
,
2540 .vidioc_s_tuner
= radio_s_tuner
,
2541 .vidioc_s_audio
= radio_s_audio
,
2542 .vidioc_s_input
= radio_s_input
,
2543 .vidioc_queryctrl
= radio_queryctrl
,
2544 .vidioc_g_ctrl
= vidioc_g_ctrl
,
2545 .vidioc_s_ctrl
= vidioc_s_ctrl
,
2546 .vidioc_g_frequency
= vidioc_g_frequency
,
2547 .vidioc_s_frequency
= vidioc_s_frequency
,
2548 #ifdef CONFIG_VIDEO_ADV_DEBUG
2549 .vidioc_g_register
= vidioc_g_register
,
2550 .vidioc_s_register
= vidioc_s_register
,
2554 static struct video_device cx231xx_radio_template
= {
2555 .name
= "cx231xx-radio",
2556 .fops
= &radio_fops
,
2557 .ioctl_ops
= &radio_ioctl_ops
,
2560 /******************************** usb interface ******************************/
2562 static struct video_device
*cx231xx_vdev_init(struct cx231xx
*dev
,
2563 const struct video_device
2564 *template, const char *type_name
)
2566 struct video_device
*vfd
;
2568 vfd
= video_device_alloc();
2573 vfd
->v4l2_dev
= &dev
->v4l2_dev
;
2574 vfd
->release
= video_device_release
;
2575 vfd
->debug
= video_debug
;
2576 vfd
->lock
= &dev
->lock
;
2578 snprintf(vfd
->name
, sizeof(vfd
->name
), "%s %s", dev
->name
, type_name
);
2580 video_set_drvdata(vfd
, dev
);
2584 int cx231xx_register_analog_devices(struct cx231xx
*dev
)
2588 cx231xx_info("%s: v4l2 driver version %s\n",
2589 dev
->name
, CX231XX_VERSION
);
2591 /* set default norm */
2592 /*dev->norm = cx231xx_video_template.current_norm; */
2593 dev
->width
= norm_maxw(dev
);
2594 dev
->height
= norm_maxh(dev
);
2595 dev
->interlaced
= 0;
2597 /* Analog specific initialization */
2598 dev
->format
= &format
[0];
2600 /* Set the initial input */
2601 video_mux(dev
, dev
->video_input
);
2603 /* Audio defaults */
2607 /* enable vbi capturing */
2608 /* write code here... */
2610 /* allocate and fill video video_device struct */
2611 dev
->vdev
= cx231xx_vdev_init(dev
, &cx231xx_video_template
, "video");
2613 cx231xx_errdev("cannot allocate video_device.\n");
2617 /* register v4l2 video video_device */
2618 ret
= video_register_device(dev
->vdev
, VFL_TYPE_GRABBER
,
2619 video_nr
[dev
->devno
]);
2621 cx231xx_errdev("unable to register video device (error=%i).\n",
2626 cx231xx_info("%s/0: registered device %s [v4l2]\n",
2627 dev
->name
, video_device_node_name(dev
->vdev
));
2629 /* Initialize VBI template */
2630 memcpy(&cx231xx_vbi_template
, &cx231xx_video_template
,
2631 sizeof(cx231xx_vbi_template
));
2632 strcpy(cx231xx_vbi_template
.name
, "cx231xx-vbi");
2634 /* Allocate and fill vbi video_device struct */
2635 dev
->vbi_dev
= cx231xx_vdev_init(dev
, &cx231xx_vbi_template
, "vbi");
2637 /* register v4l2 vbi video_device */
2638 ret
= video_register_device(dev
->vbi_dev
, VFL_TYPE_VBI
,
2639 vbi_nr
[dev
->devno
]);
2641 cx231xx_errdev("unable to register vbi device\n");
2645 cx231xx_info("%s/0: registered device %s\n",
2646 dev
->name
, video_device_node_name(dev
->vbi_dev
));
2648 if (cx231xx_boards
[dev
->model
].radio
.type
== CX231XX_RADIO
) {
2649 dev
->radio_dev
= cx231xx_vdev_init(dev
, &cx231xx_radio_template
,
2651 if (!dev
->radio_dev
) {
2652 cx231xx_errdev("cannot allocate video_device.\n");
2655 ret
= video_register_device(dev
->radio_dev
, VFL_TYPE_RADIO
,
2656 radio_nr
[dev
->devno
]);
2658 cx231xx_errdev("can't register radio device\n");
2661 cx231xx_info("Registered radio device as %s\n",
2662 video_device_node_name(dev
->radio_dev
));
2665 cx231xx_info("V4L2 device registered as %s and %s\n",
2666 video_device_node_name(dev
->vdev
),
2667 video_device_node_name(dev
->vbi_dev
));