2 em28xx-video.c - driver for Empia EM2800/EM2820/2840 USB
5 Copyright (C) 2005 Ludovico Cavedon <cavedon@sssup.it>
6 Markus Rechberger <mrechberger@gmail.com>
7 Mauro Carvalho Chehab <mchehab@infradead.org>
8 Sascha Sommer <saschasommer@freenet.de>
10 Some parts based on SN9C10x PC Camera Controllers GPL driver made
11 by Luca Risolia <luca.risolia@studio.unibo.it>
13 This program is free software; you can redistribute it and/or modify
14 it under the terms of the GNU General Public License as published by
15 the Free Software Foundation; either version 2 of the License, or
16 (at your option) any later version.
18 This program is distributed in the hope that it will be useful,
19 but WITHOUT ANY WARRANTY; without even the implied warranty of
20 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 GNU General Public License for more details.
23 You should have received a copy of the GNU General Public License
24 along with this program; if not, write to the Free Software
25 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
28 #include <linux/init.h>
29 #include <linux/list.h>
30 #include <linux/module.h>
31 #include <linux/kernel.h>
32 #include <linux/bitmap.h>
33 #include <linux/usb.h>
34 #include <linux/i2c.h>
35 #include <linux/version.h>
37 #include <linux/mutex.h>
38 #include <linux/slab.h>
41 #include <media/v4l2-common.h>
42 #include <media/v4l2-ioctl.h>
43 #include <media/v4l2-chip-ident.h>
44 #include <media/msp3400.h>
45 #include <media/tuner.h>
47 #define DRIVER_AUTHOR "Ludovico Cavedon <cavedon@sssup.it>, " \
48 "Markus Rechberger <mrechberger@gmail.com>, " \
49 "Mauro Carvalho Chehab <mchehab@infradead.org>, " \
50 "Sascha Sommer <saschasommer@freenet.de>"
52 #define DRIVER_DESC "Empia em28xx based USB video device driver"
53 #define EM28XX_VERSION_CODE KERNEL_VERSION(0, 1, 2)
55 #define em28xx_videodbg(fmt, arg...) do {\
57 printk(KERN_INFO "%s %s :"fmt, \
58 dev->name, __func__ , ##arg); } while (0)
60 static unsigned int isoc_debug;
61 module_param(isoc_debug, int, 0644);
62 MODULE_PARM_DESC(isoc_debug, "enable debug messages [isoc transfers]");
64 #define em28xx_isocdbg(fmt, arg...) \
67 printk(KERN_INFO "%s %s :"fmt, \
68 dev->name, __func__ , ##arg); \
72 MODULE_AUTHOR(DRIVER_AUTHOR);
73 MODULE_DESCRIPTION(DRIVER_DESC);
74 MODULE_LICENSE("GPL");
76 static unsigned int video_nr[] = {[0 ... (EM28XX_MAXBOARDS - 1)] = UNSET };
77 static unsigned int vbi_nr[] = {[0 ... (EM28XX_MAXBOARDS - 1)] = UNSET };
78 static unsigned int radio_nr[] = {[0 ... (EM28XX_MAXBOARDS - 1)] = UNSET };
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);
83 MODULE_PARM_DESC(video_nr, "video device numbers");
84 MODULE_PARM_DESC(vbi_nr, "vbi device numbers");
85 MODULE_PARM_DESC(radio_nr, "radio device numbers");
87 static unsigned int video_debug;
88 module_param(video_debug, int, 0644);
89 MODULE_PARM_DESC(video_debug, "enable debug messages [video]");
91 /* supported video standards */
92 static struct em28xx_fmt format[] = {
94 .name = "16 bpp YUY2, 4:2:2, packed",
95 .fourcc = V4L2_PIX_FMT_YUYV,
97 .reg = EM28XX_OUTFMT_YUV422_Y0UY1V,
99 .name = "16 bpp RGB 565, LE",
100 .fourcc = V4L2_PIX_FMT_RGB565,
102 .reg = EM28XX_OUTFMT_RGB_16_656,
104 .name = "8 bpp Bayer BGBG..GRGR",
105 .fourcc = V4L2_PIX_FMT_SBGGR8,
107 .reg = EM28XX_OUTFMT_RGB_8_BGBG,
109 .name = "8 bpp Bayer GRGR..BGBG",
110 .fourcc = V4L2_PIX_FMT_SGRBG8,
112 .reg = EM28XX_OUTFMT_RGB_8_GRGR,
114 .name = "8 bpp Bayer GBGB..RGRG",
115 .fourcc = V4L2_PIX_FMT_SGBRG8,
117 .reg = EM28XX_OUTFMT_RGB_8_GBGB,
119 .name = "12 bpp YUV411",
120 .fourcc = V4L2_PIX_FMT_YUV411P,
122 .reg = EM28XX_OUTFMT_YUV411,
126 /* supported controls */
127 /* Common to all boards */
128 static struct v4l2_queryctrl ac97_qctrl[] = {
130 .id = V4L2_CID_AUDIO_VOLUME,
131 .type = V4L2_CTRL_TYPE_INTEGER,
136 .default_value = 0x1f,
137 .flags = V4L2_CTRL_FLAG_SLIDER,
139 .id = V4L2_CID_AUDIO_MUTE,
140 .type = V4L2_CTRL_TYPE_BOOLEAN,
150 /* ------------------------------------------------------------------
151 DMA and thread functions
152 ------------------------------------------------------------------*/
155 * Announces that a buffer were filled and request the next
157 static inline void buffer_filled(struct em28xx *dev,
158 struct em28xx_dmaqueue *dma_q,
159 struct em28xx_buffer *buf)
161 /* Advice that buffer was filled */
162 em28xx_isocdbg("[%p/%d] wakeup\n", buf, buf->vb.i);
163 buf->vb.state = VIDEOBUF_DONE;
164 buf->vb.field_count++;
165 do_gettimeofday(&buf->vb.ts);
167 dev->isoc_ctl.vid_buf = NULL;
169 list_del(&buf->vb.queue);
170 wake_up(&buf->vb.done);
173 static inline void vbi_buffer_filled(struct em28xx *dev,
174 struct em28xx_dmaqueue *dma_q,
175 struct em28xx_buffer *buf)
177 /* Advice that buffer was filled */
178 em28xx_isocdbg("[%p/%d] wakeup\n", buf, buf->vb.i);
180 buf->vb.state = VIDEOBUF_DONE;
181 buf->vb.field_count++;
182 do_gettimeofday(&buf->vb.ts);
184 dev->isoc_ctl.vbi_buf = NULL;
186 list_del(&buf->vb.queue);
187 wake_up(&buf->vb.done);
191 * Identify the buffer header type and properly handles
193 static void em28xx_copy_video(struct em28xx *dev,
194 struct em28xx_dmaqueue *dma_q,
195 struct em28xx_buffer *buf,
197 unsigned char *outp, unsigned long len)
199 void *fieldstart, *startwrite, *startread;
200 int linesdone, currlinedone, offset, lencopy, remain;
201 int bytesperline = dev->width << 1;
203 if (dma_q->pos + len > buf->vb.size)
204 len = buf->vb.size - dma_q->pos;
209 if (dev->progressive)
212 /* Interlaces two half frames */
216 fieldstart = outp + bytesperline;
219 linesdone = dma_q->pos / bytesperline;
220 currlinedone = dma_q->pos % bytesperline;
222 if (dev->progressive)
223 offset = linesdone * bytesperline + currlinedone;
225 offset = linesdone * bytesperline * 2 + currlinedone;
227 startwrite = fieldstart + offset;
228 lencopy = bytesperline - currlinedone;
229 lencopy = lencopy > remain ? remain : lencopy;
231 if ((char *)startwrite + lencopy > (char *)outp + buf->vb.size) {
232 em28xx_isocdbg("Overflow of %zi bytes past buffer end (1)\n",
233 ((char *)startwrite + lencopy) -
234 ((char *)outp + buf->vb.size));
235 remain = (char *)outp + buf->vb.size - (char *)startwrite;
240 memcpy(startwrite, startread, lencopy);
245 startwrite += lencopy + bytesperline;
246 startread += lencopy;
247 if (bytesperline > remain)
250 lencopy = bytesperline;
252 if ((char *)startwrite + lencopy > (char *)outp +
254 em28xx_isocdbg("Overflow of %zi bytes past buffer end"
256 ((char *)startwrite + lencopy) -
257 ((char *)outp + buf->vb.size));
258 lencopy = remain = (char *)outp + buf->vb.size -
264 memcpy(startwrite, startread, lencopy);
272 static void em28xx_copy_vbi(struct em28xx *dev,
273 struct em28xx_dmaqueue *dma_q,
274 struct em28xx_buffer *buf,
276 unsigned char *outp, unsigned long len)
278 void *startwrite, *startread;
283 em28xx_isocdbg("dev is null\n");
286 bytesperline = dev->vbi_width;
289 em28xx_isocdbg("dma_q is null\n");
296 em28xx_isocdbg("p is null\n");
300 em28xx_isocdbg("outp is null\n");
304 if (dma_q->pos + len > buf->vb.size)
305 len = buf->vb.size - dma_q->pos;
309 startwrite = outp + dma_q->pos;
312 /* Make sure the bottom field populates the second half of the frame */
313 if (buf->top_field == 0) {
314 startwrite += bytesperline * dev->vbi_height;
315 offset += bytesperline * dev->vbi_height;
318 memcpy(startwrite, startread, len);
322 static inline void print_err_status(struct em28xx *dev,
323 int packet, int status)
325 char *errmsg = "Unknown";
329 errmsg = "unlinked synchronuously";
332 errmsg = "unlinked asynchronuously";
335 errmsg = "Buffer error (overrun)";
338 errmsg = "Stalled (device not responding)";
341 errmsg = "Babble (bad cable?)";
344 errmsg = "Bit-stuff error (bad cable?)";
347 errmsg = "CRC/Timeout (could be anything)";
350 errmsg = "Device does not respond";
354 em28xx_isocdbg("URB status %d [%s].\n", status, errmsg);
356 em28xx_isocdbg("URB packet %d, status %d [%s].\n",
357 packet, status, errmsg);
362 * video-buf generic routine to get the next available buffer
364 static inline void get_next_buf(struct em28xx_dmaqueue *dma_q,
365 struct em28xx_buffer **buf)
367 struct em28xx *dev = container_of(dma_q, struct em28xx, vidq);
370 if (list_empty(&dma_q->active)) {
371 em28xx_isocdbg("No active queue to serve\n");
372 dev->isoc_ctl.vid_buf = NULL;
377 /* Get the next buffer */
378 *buf = list_entry(dma_q->active.next, struct em28xx_buffer, vb.queue);
380 /* Cleans up buffer - Usefull for testing for frame/URB loss */
381 outp = videobuf_to_vmalloc(&(*buf)->vb);
382 memset(outp, 0, (*buf)->vb.size);
384 dev->isoc_ctl.vid_buf = *buf;
390 * video-buf generic routine to get the next available VBI buffer
392 static inline void vbi_get_next_buf(struct em28xx_dmaqueue *dma_q,
393 struct em28xx_buffer **buf)
395 struct em28xx *dev = container_of(dma_q, struct em28xx, vbiq);
398 if (list_empty(&dma_q->active)) {
399 em28xx_isocdbg("No active queue to serve\n");
400 dev->isoc_ctl.vbi_buf = NULL;
405 /* Get the next buffer */
406 *buf = list_entry(dma_q->active.next, struct em28xx_buffer, vb.queue);
407 /* Cleans up buffer - Usefull for testing for frame/URB loss */
408 outp = videobuf_to_vmalloc(&(*buf)->vb);
409 memset(outp, 0x00, (*buf)->vb.size);
411 dev->isoc_ctl.vbi_buf = *buf;
417 * Controls the isoc copy of each urb packet
419 static inline int em28xx_isoc_copy(struct em28xx *dev, struct urb *urb)
421 struct em28xx_buffer *buf;
422 struct em28xx_dmaqueue *dma_q = &dev->vidq;
423 unsigned char *outp = NULL;
424 int i, len = 0, rc = 1;
430 if ((dev->state & DEV_DISCONNECTED) || (dev->state & DEV_MISCONFIGURED))
433 if (urb->status < 0) {
434 print_err_status(dev, -1, urb->status);
435 if (urb->status == -ENOENT)
439 buf = dev->isoc_ctl.vid_buf;
441 outp = videobuf_to_vmalloc(&buf->vb);
443 for (i = 0; i < urb->number_of_packets; i++) {
444 int status = urb->iso_frame_desc[i].status;
447 print_err_status(dev, i, status);
448 if (urb->iso_frame_desc[i].status != -EPROTO)
452 len = urb->iso_frame_desc[i].actual_length - 4;
454 if (urb->iso_frame_desc[i].actual_length <= 0) {
455 /* em28xx_isocdbg("packet %d is empty",i); - spammy */
458 if (urb->iso_frame_desc[i].actual_length >
460 em28xx_isocdbg("packet bigger than packet size");
464 p = urb->transfer_buffer + urb->iso_frame_desc[i].offset;
466 /* FIXME: incomplete buffer checks where removed to make
467 logic simpler. Impacts of those changes should be evaluated
469 if (p[0] == 0x33 && p[1] == 0x95 && p[2] == 0x00) {
470 em28xx_isocdbg("VBI HEADER!!!\n");
471 /* FIXME: Should add vbi copy */
474 if (p[0] == 0x22 && p[1] == 0x5a) {
475 em28xx_isocdbg("Video frame %d, length=%i, %s\n", p[2],
476 len, (p[2] & 1) ? "odd" : "even");
478 if (dev->progressive || !(p[2] & 1)) {
480 buffer_filled(dev, dma_q, buf);
481 get_next_buf(dma_q, &buf);
485 outp = videobuf_to_vmalloc(&buf->vb);
498 if (p[0] != 0x88 && p[0] != 0x22) {
499 em28xx_isocdbg("frame is not complete\n");
504 em28xx_copy_video(dev, dma_q, buf, p, outp, len);
510 /* Version of isoc handler that takes into account a mixture of video and
512 static inline int em28xx_isoc_copy_vbi(struct em28xx *dev, struct urb *urb)
514 struct em28xx_buffer *buf, *vbi_buf;
515 struct em28xx_dmaqueue *dma_q = &dev->vidq;
516 struct em28xx_dmaqueue *vbi_dma_q = &dev->vbiq;
517 unsigned char *outp = NULL;
518 unsigned char *vbioutp = NULL;
519 int i, len = 0, rc = 1;
526 if ((dev->state & DEV_DISCONNECTED) || (dev->state & DEV_MISCONFIGURED))
529 if (urb->status < 0) {
530 print_err_status(dev, -1, urb->status);
531 if (urb->status == -ENOENT)
535 buf = dev->isoc_ctl.vid_buf;
537 outp = videobuf_to_vmalloc(&buf->vb);
539 vbi_buf = dev->isoc_ctl.vbi_buf;
541 vbioutp = videobuf_to_vmalloc(&vbi_buf->vb);
543 for (i = 0; i < urb->number_of_packets; i++) {
544 int status = urb->iso_frame_desc[i].status;
547 print_err_status(dev, i, status);
548 if (urb->iso_frame_desc[i].status != -EPROTO)
552 len = urb->iso_frame_desc[i].actual_length;
553 if (urb->iso_frame_desc[i].actual_length <= 0) {
554 /* em28xx_isocdbg("packet %d is empty",i); - spammy */
557 if (urb->iso_frame_desc[i].actual_length >
559 em28xx_isocdbg("packet bigger than packet size");
563 p = urb->transfer_buffer + urb->iso_frame_desc[i].offset;
565 /* capture type 0 = vbi start
566 capture type 1 = video start
567 capture type 2 = video in progress */
568 if (p[0] == 0x33 && p[1] == 0x95) {
569 dev->capture_type = 0;
571 em28xx_isocdbg("VBI START HEADER!!!\n");
572 dev->cur_field = p[2];
575 } else if (p[0] == 0x88 && p[1] == 0x88 &&
576 p[2] == 0x88 && p[3] == 0x88) {
580 } else if (p[0] == 0x22 && p[1] == 0x5a) {
586 vbi_size = dev->vbi_width * dev->vbi_height;
588 if (dev->capture_type == 0) {
589 if (dev->vbi_read >= vbi_size) {
590 /* We've already read all the VBI data, so
591 treat the rest as video */
592 em28xx_isocdbg("dev->vbi_read > vbi_size\n");
593 } else if ((dev->vbi_read + len) < vbi_size) {
594 /* This entire frame is VBI data */
595 if (dev->vbi_read == 0 &&
596 (!(dev->cur_field & 1))) {
597 /* Brand new frame */
599 vbi_buffer_filled(dev,
602 vbi_get_next_buf(vbi_dma_q, &vbi_buf);
606 vbioutp = videobuf_to_vmalloc(
610 if (dev->vbi_read == 0) {
612 if (vbi_buf != NULL) {
613 if (dev->cur_field & 1)
614 vbi_buf->top_field = 0;
616 vbi_buf->top_field = 1;
620 dev->vbi_read += len;
621 em28xx_copy_vbi(dev, vbi_dma_q, vbi_buf, p,
624 /* Some of this frame is VBI data and some is
626 int vbi_data_len = vbi_size - dev->vbi_read;
627 dev->vbi_read += vbi_data_len;
628 em28xx_copy_vbi(dev, vbi_dma_q, vbi_buf, p,
629 vbioutp, vbi_data_len);
630 dev->capture_type = 1;
636 if (dev->capture_type == 1) {
637 dev->capture_type = 2;
638 if (dev->progressive || !(dev->cur_field & 1)) {
640 buffer_filled(dev, dma_q, buf);
641 get_next_buf(dma_q, &buf);
645 outp = videobuf_to_vmalloc(&buf->vb);
648 if (dev->cur_field & 1)
657 if (buf != NULL && dev->capture_type == 2) {
658 if (len >= 4 && p[0] == 0x88 && p[1] == 0x88 &&
659 p[2] == 0x88 && p[3] == 0x88) {
663 if (len >= 4 && p[0] == 0x22 && p[1] == 0x5a) {
664 em28xx_isocdbg("Video frame %d, len=%i, %s\n",
665 p[2], len, (p[2] & 1) ?
672 em28xx_copy_video(dev, dma_q, buf, p, outp,
680 /* ------------------------------------------------------------------
682 ------------------------------------------------------------------*/
685 buffer_setup(struct videobuf_queue *vq, unsigned int *count, unsigned int *size)
687 struct em28xx_fh *fh = vq->priv_data;
688 struct em28xx *dev = fh->dev;
689 struct v4l2_frequency f;
691 *size = (fh->dev->width * fh->dev->height * dev->format->depth + 7)
695 *count = EM28XX_DEF_BUF;
697 if (*count < EM28XX_MIN_BUF)
698 *count = EM28XX_MIN_BUF;
700 /* Ask tuner to go to analog or radio mode */
701 memset(&f, 0, sizeof(f));
702 f.frequency = dev->ctl_freq;
703 f.type = fh->radio ? V4L2_TUNER_RADIO : V4L2_TUNER_ANALOG_TV;
705 v4l2_device_call_all(&dev->v4l2_dev, 0, tuner, s_frequency, &f);
710 /* This is called *without* dev->slock held; please keep it that way */
711 static void free_buffer(struct videobuf_queue *vq, struct em28xx_buffer *buf)
713 struct em28xx_fh *fh = vq->priv_data;
714 struct em28xx *dev = fh->dev;
715 unsigned long flags = 0;
719 /* We used to wait for the buffer to finish here, but this didn't work
720 because, as we were keeping the state as VIDEOBUF_QUEUED,
721 videobuf_queue_cancel marked it as finished for us.
722 (Also, it could wedge forever if the hardware was misconfigured.)
724 This should be safe; by the time we get here, the buffer isn't
725 queued anymore. If we ever start marking the buffers as
726 VIDEOBUF_ACTIVE, it won't be, though.
728 spin_lock_irqsave(&dev->slock, flags);
729 if (dev->isoc_ctl.vid_buf == buf)
730 dev->isoc_ctl.vid_buf = NULL;
731 spin_unlock_irqrestore(&dev->slock, flags);
733 videobuf_vmalloc_free(&buf->vb);
734 buf->vb.state = VIDEOBUF_NEEDS_INIT;
738 buffer_prepare(struct videobuf_queue *vq, struct videobuf_buffer *vb,
739 enum v4l2_field field)
741 struct em28xx_fh *fh = vq->priv_data;
742 struct em28xx_buffer *buf = container_of(vb, struct em28xx_buffer, vb);
743 struct em28xx *dev = fh->dev;
744 int rc = 0, urb_init = 0;
746 buf->vb.size = (fh->dev->width * fh->dev->height * dev->format->depth
749 if (0 != buf->vb.baddr && buf->vb.bsize < buf->vb.size)
752 buf->vb.width = dev->width;
753 buf->vb.height = dev->height;
754 buf->vb.field = field;
756 if (VIDEOBUF_NEEDS_INIT == buf->vb.state) {
757 rc = videobuf_iolock(vq, &buf->vb, NULL);
762 if (!dev->isoc_ctl.num_bufs)
766 if (em28xx_vbi_supported(dev) == 1)
767 rc = em28xx_init_isoc(dev, EM28XX_NUM_PACKETS,
770 em28xx_isoc_copy_vbi);
772 rc = em28xx_init_isoc(dev, EM28XX_NUM_PACKETS,
780 buf->vb.state = VIDEOBUF_PREPARED;
784 free_buffer(vq, buf);
789 buffer_queue(struct videobuf_queue *vq, struct videobuf_buffer *vb)
791 struct em28xx_buffer *buf = container_of(vb,
792 struct em28xx_buffer,
794 struct em28xx_fh *fh = vq->priv_data;
795 struct em28xx *dev = fh->dev;
796 struct em28xx_dmaqueue *vidq = &dev->vidq;
798 buf->vb.state = VIDEOBUF_QUEUED;
799 list_add_tail(&buf->vb.queue, &vidq->active);
803 static void buffer_release(struct videobuf_queue *vq,
804 struct videobuf_buffer *vb)
806 struct em28xx_buffer *buf = container_of(vb,
807 struct em28xx_buffer,
809 struct em28xx_fh *fh = vq->priv_data;
810 struct em28xx *dev = (struct em28xx *)fh->dev;
812 em28xx_isocdbg("em28xx: called buffer_release\n");
814 free_buffer(vq, buf);
817 static struct videobuf_queue_ops em28xx_video_qops = {
818 .buf_setup = buffer_setup,
819 .buf_prepare = buffer_prepare,
820 .buf_queue = buffer_queue,
821 .buf_release = buffer_release,
824 /********************* v4l2 interface **************************************/
826 static void video_mux(struct em28xx *dev, int index)
828 dev->ctl_input = index;
829 dev->ctl_ainput = INPUT(index)->amux;
830 dev->ctl_aoutput = INPUT(index)->aout;
832 if (!dev->ctl_aoutput)
833 dev->ctl_aoutput = EM28XX_AOUT_MASTER;
835 v4l2_device_call_all(&dev->v4l2_dev, 0, video, s_routing,
836 INPUT(index)->vmux, 0, 0);
838 if (dev->board.has_msp34xx) {
839 if (dev->i2s_speed) {
840 v4l2_device_call_all(&dev->v4l2_dev, 0, audio,
841 s_i2s_clock_freq, dev->i2s_speed);
843 /* Note: this is msp3400 specific */
844 v4l2_device_call_all(&dev->v4l2_dev, 0, audio, s_routing,
845 dev->ctl_ainput, MSP_OUTPUT(MSP_SC_IN_DSP_SCART1), 0);
848 if (dev->board.adecoder != EM28XX_NOADECODER) {
849 v4l2_device_call_all(&dev->v4l2_dev, 0, audio, s_routing,
850 dev->ctl_ainput, dev->ctl_aoutput, 0);
853 em28xx_audio_analog_set(dev);
856 /* Usage lock check functions */
857 static int res_get(struct em28xx_fh *fh, unsigned int bit)
859 struct em28xx *dev = fh->dev;
861 if (fh->resources & bit)
862 /* have it already allocated */
866 mutex_lock(&dev->lock);
867 if (dev->resources & bit) {
868 /* no, someone else uses it */
869 mutex_unlock(&dev->lock);
872 /* it's free, grab it */
873 fh->resources |= bit;
874 dev->resources |= bit;
875 em28xx_videodbg("res: get %d\n", bit);
876 mutex_unlock(&dev->lock);
880 static int res_check(struct em28xx_fh *fh, unsigned int bit)
882 return fh->resources & bit;
885 static int res_locked(struct em28xx *dev, unsigned int bit)
887 return dev->resources & bit;
890 static void res_free(struct em28xx_fh *fh, unsigned int bits)
892 struct em28xx *dev = fh->dev;
894 BUG_ON((fh->resources & bits) != bits);
896 mutex_lock(&dev->lock);
897 fh->resources &= ~bits;
898 dev->resources &= ~bits;
899 em28xx_videodbg("res: put %d\n", bits);
900 mutex_unlock(&dev->lock);
903 static int get_ressource(struct em28xx_fh *fh)
906 case V4L2_BUF_TYPE_VIDEO_CAPTURE:
907 return EM28XX_RESOURCE_VIDEO;
908 case V4L2_BUF_TYPE_VBI_CAPTURE:
909 return EM28XX_RESOURCE_VBI;
918 * return the ac97 supported controls
920 static int ac97_queryctrl(struct v4l2_queryctrl *qc)
924 for (i = 0; i < ARRAY_SIZE(ac97_qctrl); i++) {
925 if (qc->id && qc->id == ac97_qctrl[i].id) {
926 memcpy(qc, &(ac97_qctrl[i]), sizeof(*qc));
931 /* Control is not ac97 related */
937 * return the current values for ac97 mute and volume
939 static int ac97_get_ctrl(struct em28xx *dev, struct v4l2_control *ctrl)
942 case V4L2_CID_AUDIO_MUTE:
943 ctrl->value = dev->mute;
945 case V4L2_CID_AUDIO_VOLUME:
946 ctrl->value = dev->volume;
949 /* Control is not ac97 related */
956 * set values for ac97 mute and volume
958 static int ac97_set_ctrl(struct em28xx *dev, const struct v4l2_control *ctrl)
962 for (i = 0; i < ARRAY_SIZE(ac97_qctrl); i++)
963 if (ctrl->id == ac97_qctrl[i].id)
966 /* Announce that hasn't handle it */
970 if (ctrl->value < ac97_qctrl[i].minimum ||
971 ctrl->value > ac97_qctrl[i].maximum)
975 case V4L2_CID_AUDIO_MUTE:
976 dev->mute = ctrl->value;
978 case V4L2_CID_AUDIO_VOLUME:
979 dev->volume = ctrl->value;
983 return em28xx_audio_analog_set(dev);
986 static int check_dev(struct em28xx *dev)
988 if (dev->state & DEV_DISCONNECTED) {
989 em28xx_errdev("v4l2 ioctl: device not present\n");
993 if (dev->state & DEV_MISCONFIGURED) {
994 em28xx_errdev("v4l2 ioctl: device is misconfigured; "
995 "close and open it again\n");
1001 static void get_scale(struct em28xx *dev,
1002 unsigned int width, unsigned int height,
1003 unsigned int *hscale, unsigned int *vscale)
1005 unsigned int maxw = norm_maxw(dev);
1006 unsigned int maxh = norm_maxh(dev);
1008 *hscale = (((unsigned long)maxw) << 12) / width - 4096L;
1009 if (*hscale >= 0x4000)
1012 *vscale = (((unsigned long)maxh) << 12) / height - 4096L;
1013 if (*vscale >= 0x4000)
1017 /* ------------------------------------------------------------------
1018 IOCTL vidioc handling
1019 ------------------------------------------------------------------*/
1021 static int vidioc_g_fmt_vid_cap(struct file *file, void *priv,
1022 struct v4l2_format *f)
1024 struct em28xx_fh *fh = priv;
1025 struct em28xx *dev = fh->dev;
1027 mutex_lock(&dev->lock);
1029 f->fmt.pix.width = dev->width;
1030 f->fmt.pix.height = dev->height;
1031 f->fmt.pix.pixelformat = dev->format->fourcc;
1032 f->fmt.pix.bytesperline = (dev->width * dev->format->depth + 7) >> 3;
1033 f->fmt.pix.sizeimage = f->fmt.pix.bytesperline * dev->height;
1034 f->fmt.pix.colorspace = V4L2_COLORSPACE_SMPTE170M;
1036 /* FIXME: TOP? NONE? BOTTOM? ALTENATE? */
1037 if (dev->progressive)
1038 f->fmt.pix.field = V4L2_FIELD_NONE;
1040 f->fmt.pix.field = dev->interlaced ?
1041 V4L2_FIELD_INTERLACED : V4L2_FIELD_TOP;
1043 mutex_unlock(&dev->lock);
1047 static struct em28xx_fmt *format_by_fourcc(unsigned int fourcc)
1051 for (i = 0; i < ARRAY_SIZE(format); i++)
1052 if (format[i].fourcc == fourcc)
1058 static int vidioc_try_fmt_vid_cap(struct file *file, void *priv,
1059 struct v4l2_format *f)
1061 struct em28xx_fh *fh = priv;
1062 struct em28xx *dev = fh->dev;
1063 unsigned int width = f->fmt.pix.width;
1064 unsigned int height = f->fmt.pix.height;
1065 unsigned int maxw = norm_maxw(dev);
1066 unsigned int maxh = norm_maxh(dev);
1067 unsigned int hscale, vscale;
1068 struct em28xx_fmt *fmt;
1070 fmt = format_by_fourcc(f->fmt.pix.pixelformat);
1072 em28xx_videodbg("Fourcc format (%08x) invalid.\n",
1073 f->fmt.pix.pixelformat);
1077 if (dev->board.is_em2800) {
1078 /* the em2800 can only scale down to 50% */
1079 height = height > (3 * maxh / 4) ? maxh : maxh / 2;
1080 width = width > (3 * maxw / 4) ? maxw : maxw / 2;
1082 /* width must even because of the YUYV format
1083 height must be even because of interlacing */
1084 v4l_bound_align_image(&width, 48, maxw, 1, &height, 32, maxh,
1088 get_scale(dev, width, height, &hscale, &vscale);
1090 width = (((unsigned long)maxw) << 12) / (hscale + 4096L);
1091 height = (((unsigned long)maxh) << 12) / (vscale + 4096L);
1093 f->fmt.pix.width = width;
1094 f->fmt.pix.height = height;
1095 f->fmt.pix.pixelformat = fmt->fourcc;
1096 f->fmt.pix.bytesperline = (dev->width * fmt->depth + 7) >> 3;
1097 f->fmt.pix.sizeimage = f->fmt.pix.bytesperline * height;
1098 f->fmt.pix.colorspace = V4L2_COLORSPACE_SMPTE170M;
1099 if (dev->progressive)
1100 f->fmt.pix.field = V4L2_FIELD_NONE;
1102 f->fmt.pix.field = dev->interlaced ?
1103 V4L2_FIELD_INTERLACED : V4L2_FIELD_TOP;
1108 static int em28xx_set_video_format(struct em28xx *dev, unsigned int fourcc,
1109 unsigned width, unsigned height)
1111 struct em28xx_fmt *fmt;
1113 fmt = format_by_fourcc(fourcc);
1119 dev->height = height;
1121 /* set new image size */
1122 get_scale(dev, dev->width, dev->height, &dev->hscale, &dev->vscale);
1124 em28xx_set_alternate(dev);
1125 em28xx_resolution_set(dev);
1130 static int vidioc_s_fmt_vid_cap(struct file *file, void *priv,
1131 struct v4l2_format *f)
1133 struct em28xx_fh *fh = priv;
1134 struct em28xx *dev = fh->dev;
1137 rc = check_dev(dev);
1141 mutex_lock(&dev->lock);
1143 vidioc_try_fmt_vid_cap(file, priv, f);
1145 if (videobuf_queue_is_busy(&fh->vb_vidq)) {
1146 em28xx_errdev("%s queue busy\n", __func__);
1151 rc = em28xx_set_video_format(dev, f->fmt.pix.pixelformat,
1152 f->fmt.pix.width, f->fmt.pix.height);
1155 mutex_unlock(&dev->lock);
1159 static int vidioc_g_std(struct file *file, void *priv, v4l2_std_id *norm)
1161 struct em28xx_fh *fh = priv;
1162 struct em28xx *dev = fh->dev;
1165 rc = check_dev(dev);
1174 static int vidioc_s_std(struct file *file, void *priv, v4l2_std_id *norm)
1176 struct em28xx_fh *fh = priv;
1177 struct em28xx *dev = fh->dev;
1178 struct v4l2_format f;
1181 rc = check_dev(dev);
1185 mutex_lock(&dev->lock);
1188 /* Adjusts width/height, if needed */
1189 f.fmt.pix.width = dev->width;
1190 f.fmt.pix.height = dev->height;
1191 vidioc_try_fmt_vid_cap(file, priv, &f);
1193 /* set new image size */
1194 dev->width = f.fmt.pix.width;
1195 dev->height = f.fmt.pix.height;
1196 get_scale(dev, dev->width, dev->height, &dev->hscale, &dev->vscale);
1198 em28xx_resolution_set(dev);
1199 v4l2_device_call_all(&dev->v4l2_dev, 0, core, s_std, dev->norm);
1201 mutex_unlock(&dev->lock);
1205 static int vidioc_g_parm(struct file *file, void *priv,
1206 struct v4l2_streamparm *p)
1208 struct em28xx_fh *fh = priv;
1209 struct em28xx *dev = fh->dev;
1212 if (p->type != V4L2_BUF_TYPE_VIDEO_CAPTURE)
1215 if (dev->board.is_webcam)
1216 rc = v4l2_device_call_until_err(&dev->v4l2_dev, 0,
1219 v4l2_video_std_frame_period(dev->norm,
1220 &p->parm.capture.timeperframe);
1225 static int vidioc_s_parm(struct file *file, void *priv,
1226 struct v4l2_streamparm *p)
1228 struct em28xx_fh *fh = priv;
1229 struct em28xx *dev = fh->dev;
1231 if (!dev->board.is_webcam)
1234 if (p->type != V4L2_BUF_TYPE_VIDEO_CAPTURE)
1237 return v4l2_device_call_until_err(&dev->v4l2_dev, 0, video, s_parm, p);
1240 static const char *iname[] = {
1241 [EM28XX_VMUX_COMPOSITE1] = "Composite1",
1242 [EM28XX_VMUX_COMPOSITE2] = "Composite2",
1243 [EM28XX_VMUX_COMPOSITE3] = "Composite3",
1244 [EM28XX_VMUX_COMPOSITE4] = "Composite4",
1245 [EM28XX_VMUX_SVIDEO] = "S-Video",
1246 [EM28XX_VMUX_TELEVISION] = "Television",
1247 [EM28XX_VMUX_CABLE] = "Cable TV",
1248 [EM28XX_VMUX_DVB] = "DVB",
1249 [EM28XX_VMUX_DEBUG] = "for debug only",
1252 static int vidioc_enum_input(struct file *file, void *priv,
1253 struct v4l2_input *i)
1255 struct em28xx_fh *fh = priv;
1256 struct em28xx *dev = fh->dev;
1260 if (n >= MAX_EM28XX_INPUT)
1262 if (0 == INPUT(n)->type)
1266 i->type = V4L2_INPUT_TYPE_CAMERA;
1268 strcpy(i->name, iname[INPUT(n)->type]);
1270 if ((EM28XX_VMUX_TELEVISION == INPUT(n)->type) ||
1271 (EM28XX_VMUX_CABLE == INPUT(n)->type))
1272 i->type = V4L2_INPUT_TYPE_TUNER;
1274 i->std = dev->vdev->tvnorms;
1279 static int vidioc_g_input(struct file *file, void *priv, unsigned int *i)
1281 struct em28xx_fh *fh = priv;
1282 struct em28xx *dev = fh->dev;
1284 *i = dev->ctl_input;
1289 static int vidioc_s_input(struct file *file, void *priv, unsigned int i)
1291 struct em28xx_fh *fh = priv;
1292 struct em28xx *dev = fh->dev;
1295 rc = check_dev(dev);
1299 if (i >= MAX_EM28XX_INPUT)
1301 if (0 == INPUT(i)->type)
1306 mutex_lock(&dev->lock);
1307 video_mux(dev, dev->ctl_input);
1308 mutex_unlock(&dev->lock);
1312 static int vidioc_g_audio(struct file *file, void *priv, struct v4l2_audio *a)
1314 struct em28xx_fh *fh = priv;
1315 struct em28xx *dev = fh->dev;
1317 if (!dev->audio_mode.has_audio)
1321 case EM28XX_AMUX_VIDEO:
1322 strcpy(a->name, "Television");
1324 case EM28XX_AMUX_LINE_IN:
1325 strcpy(a->name, "Line In");
1327 case EM28XX_AMUX_VIDEO2:
1328 strcpy(a->name, "Television alt");
1330 case EM28XX_AMUX_PHONE:
1331 strcpy(a->name, "Phone");
1333 case EM28XX_AMUX_MIC:
1334 strcpy(a->name, "Mic");
1336 case EM28XX_AMUX_CD:
1337 strcpy(a->name, "CD");
1339 case EM28XX_AMUX_AUX:
1340 strcpy(a->name, "Aux");
1342 case EM28XX_AMUX_PCM_OUT:
1343 strcpy(a->name, "PCM");
1349 a->index = dev->ctl_ainput;
1350 a->capability = V4L2_AUDCAP_STEREO;
1355 static int vidioc_s_audio(struct file *file, void *priv, struct v4l2_audio *a)
1357 struct em28xx_fh *fh = priv;
1358 struct em28xx *dev = fh->dev;
1361 if (!dev->audio_mode.has_audio)
1364 if (a->index >= MAX_EM28XX_INPUT)
1366 if (0 == INPUT(a->index)->type)
1369 mutex_lock(&dev->lock);
1371 dev->ctl_ainput = INPUT(a->index)->amux;
1372 dev->ctl_aoutput = INPUT(a->index)->aout;
1374 if (!dev->ctl_aoutput)
1375 dev->ctl_aoutput = EM28XX_AOUT_MASTER;
1377 mutex_unlock(&dev->lock);
1381 static int vidioc_queryctrl(struct file *file, void *priv,
1382 struct v4l2_queryctrl *qc)
1384 struct em28xx_fh *fh = priv;
1385 struct em28xx *dev = fh->dev;
1389 rc = check_dev(dev);
1393 memset(qc, 0, sizeof(*qc));
1397 /* enumberate AC97 controls */
1398 if (dev->audio_mode.ac97 != EM28XX_NO_AC97) {
1399 rc = ac97_queryctrl(qc);
1404 /* enumberate V4L2 device controls */
1405 mutex_lock(&dev->lock);
1406 v4l2_device_call_all(&dev->v4l2_dev, 0, core, queryctrl, qc);
1407 mutex_unlock(&dev->lock);
1415 static int vidioc_g_ctrl(struct file *file, void *priv,
1416 struct v4l2_control *ctrl)
1418 struct em28xx_fh *fh = priv;
1419 struct em28xx *dev = fh->dev;
1422 rc = check_dev(dev);
1427 mutex_lock(&dev->lock);
1429 /* Set an AC97 control */
1430 if (dev->audio_mode.ac97 != EM28XX_NO_AC97)
1431 rc = ac97_get_ctrl(dev, ctrl);
1435 /* It were not an AC97 control. Sends it to the v4l2 dev interface */
1437 v4l2_device_call_all(&dev->v4l2_dev, 0, core, g_ctrl, ctrl);
1441 mutex_unlock(&dev->lock);
1445 static int vidioc_s_ctrl(struct file *file, void *priv,
1446 struct v4l2_control *ctrl)
1448 struct em28xx_fh *fh = priv;
1449 struct em28xx *dev = fh->dev;
1452 rc = check_dev(dev);
1456 mutex_lock(&dev->lock);
1458 /* Set an AC97 control */
1459 if (dev->audio_mode.ac97 != EM28XX_NO_AC97)
1460 rc = ac97_set_ctrl(dev, ctrl);
1464 /* It isn't an AC97 control. Sends it to the v4l2 dev interface */
1466 v4l2_device_call_all(&dev->v4l2_dev, 0, core, s_ctrl, ctrl);
1469 * In the case of non-AC97 volume controls, we still need
1470 * to do some setups at em28xx, in order to mute/unmute
1471 * and to adjust audio volume. However, the value ranges
1472 * should be checked by the corresponding V4L subdriver.
1475 case V4L2_CID_AUDIO_MUTE:
1476 dev->mute = ctrl->value;
1477 rc = em28xx_audio_analog_set(dev);
1479 case V4L2_CID_AUDIO_VOLUME:
1480 dev->volume = ctrl->value;
1481 rc = em28xx_audio_analog_set(dev);
1485 mutex_unlock(&dev->lock);
1489 static int vidioc_g_tuner(struct file *file, void *priv,
1490 struct v4l2_tuner *t)
1492 struct em28xx_fh *fh = priv;
1493 struct em28xx *dev = fh->dev;
1496 rc = check_dev(dev);
1503 strcpy(t->name, "Tuner");
1504 t->type = V4L2_TUNER_ANALOG_TV;
1506 mutex_lock(&dev->lock);
1507 v4l2_device_call_all(&dev->v4l2_dev, 0, tuner, g_tuner, t);
1508 mutex_unlock(&dev->lock);
1513 static int vidioc_s_tuner(struct file *file, void *priv,
1514 struct v4l2_tuner *t)
1516 struct em28xx_fh *fh = priv;
1517 struct em28xx *dev = fh->dev;
1520 rc = check_dev(dev);
1527 mutex_lock(&dev->lock);
1528 v4l2_device_call_all(&dev->v4l2_dev, 0, tuner, s_tuner, t);
1529 mutex_unlock(&dev->lock);
1534 static int vidioc_g_frequency(struct file *file, void *priv,
1535 struct v4l2_frequency *f)
1537 struct em28xx_fh *fh = priv;
1538 struct em28xx *dev = fh->dev;
1540 mutex_lock(&dev->lock);
1541 f->type = fh->radio ? V4L2_TUNER_RADIO : V4L2_TUNER_ANALOG_TV;
1542 f->frequency = dev->ctl_freq;
1543 mutex_unlock(&dev->lock);
1548 static int vidioc_s_frequency(struct file *file, void *priv,
1549 struct v4l2_frequency *f)
1551 struct em28xx_fh *fh = priv;
1552 struct em28xx *dev = fh->dev;
1555 rc = check_dev(dev);
1562 if (unlikely(0 == fh->radio && f->type != V4L2_TUNER_ANALOG_TV))
1564 if (unlikely(1 == fh->radio && f->type != V4L2_TUNER_RADIO))
1567 mutex_lock(&dev->lock);
1569 dev->ctl_freq = f->frequency;
1570 v4l2_device_call_all(&dev->v4l2_dev, 0, tuner, s_frequency, f);
1572 mutex_unlock(&dev->lock);
1577 #ifdef CONFIG_VIDEO_ADV_DEBUG
1578 static int em28xx_reg_len(int reg)
1581 case EM28XX_R40_AC97LSB:
1582 case EM28XX_R30_HSCALELOW:
1583 case EM28XX_R32_VSCALELOW:
1590 static int vidioc_g_chip_ident(struct file *file, void *priv,
1591 struct v4l2_dbg_chip_ident *chip)
1593 struct em28xx_fh *fh = priv;
1594 struct em28xx *dev = fh->dev;
1596 chip->ident = V4L2_IDENT_NONE;
1599 v4l2_device_call_all(&dev->v4l2_dev, 0, core, g_chip_ident, chip);
1605 static int vidioc_g_register(struct file *file, void *priv,
1606 struct v4l2_dbg_register *reg)
1608 struct em28xx_fh *fh = priv;
1609 struct em28xx *dev = fh->dev;
1612 switch (reg->match.type) {
1613 case V4L2_CHIP_MATCH_AC97:
1614 mutex_lock(&dev->lock);
1615 ret = em28xx_read_ac97(dev, reg->reg);
1616 mutex_unlock(&dev->lock);
1623 case V4L2_CHIP_MATCH_I2C_DRIVER:
1624 v4l2_device_call_all(&dev->v4l2_dev, 0, core, g_register, reg);
1626 case V4L2_CHIP_MATCH_I2C_ADDR:
1627 /* TODO: is this correct? */
1628 v4l2_device_call_all(&dev->v4l2_dev, 0, core, g_register, reg);
1631 if (!v4l2_chip_match_host(®->match))
1636 reg->size = em28xx_reg_len(reg->reg);
1637 if (reg->size == 1) {
1638 mutex_lock(&dev->lock);
1639 ret = em28xx_read_reg(dev, reg->reg);
1640 mutex_unlock(&dev->lock);
1648 mutex_lock(&dev->lock);
1649 ret = em28xx_read_reg_req_len(dev, USB_REQ_GET_STATUS,
1650 reg->reg, (char *)&val, 2);
1651 mutex_unlock(&dev->lock);
1655 reg->val = le16_to_cpu(val);
1661 static int vidioc_s_register(struct file *file, void *priv,
1662 struct v4l2_dbg_register *reg)
1664 struct em28xx_fh *fh = priv;
1665 struct em28xx *dev = fh->dev;
1669 switch (reg->match.type) {
1670 case V4L2_CHIP_MATCH_AC97:
1671 mutex_lock(&dev->lock);
1672 rc = em28xx_write_ac97(dev, reg->reg, reg->val);
1673 mutex_unlock(&dev->lock);
1676 case V4L2_CHIP_MATCH_I2C_DRIVER:
1677 v4l2_device_call_all(&dev->v4l2_dev, 0, core, s_register, reg);
1679 case V4L2_CHIP_MATCH_I2C_ADDR:
1680 /* TODO: is this correct? */
1681 v4l2_device_call_all(&dev->v4l2_dev, 0, core, s_register, reg);
1684 if (!v4l2_chip_match_host(®->match))
1689 buf = cpu_to_le16(reg->val);
1691 mutex_lock(&dev->lock);
1692 rc = em28xx_write_regs(dev, reg->reg, (char *)&buf,
1693 em28xx_reg_len(reg->reg));
1694 mutex_unlock(&dev->lock);
1701 static int vidioc_cropcap(struct file *file, void *priv,
1702 struct v4l2_cropcap *cc)
1704 struct em28xx_fh *fh = priv;
1705 struct em28xx *dev = fh->dev;
1707 if (cc->type != V4L2_BUF_TYPE_VIDEO_CAPTURE)
1710 cc->bounds.left = 0;
1712 cc->bounds.width = dev->width;
1713 cc->bounds.height = dev->height;
1714 cc->defrect = cc->bounds;
1715 cc->pixelaspect.numerator = 54; /* 4:3 FIXME: remove magic numbers */
1716 cc->pixelaspect.denominator = 59;
1721 static int vidioc_streamon(struct file *file, void *priv,
1722 enum v4l2_buf_type type)
1724 struct em28xx_fh *fh = priv;
1725 struct em28xx *dev = fh->dev;
1728 rc = check_dev(dev);
1732 if (unlikely(type != fh->type))
1735 em28xx_videodbg("vidioc_streamon fh=%p t=%d fh->res=%d dev->res=%d\n",
1736 fh, type, fh->resources, dev->resources);
1738 if (unlikely(!res_get(fh, get_ressource(fh))))
1741 if (fh->type == V4L2_BUF_TYPE_VIDEO_CAPTURE)
1742 rc = videobuf_streamon(&fh->vb_vidq);
1743 else if (fh->type == V4L2_BUF_TYPE_VBI_CAPTURE)
1744 rc = videobuf_streamon(&fh->vb_vbiq);
1749 static int vidioc_streamoff(struct file *file, void *priv,
1750 enum v4l2_buf_type type)
1752 struct em28xx_fh *fh = priv;
1753 struct em28xx *dev = fh->dev;
1756 rc = check_dev(dev);
1760 if (fh->type != V4L2_BUF_TYPE_VIDEO_CAPTURE &&
1761 fh->type != V4L2_BUF_TYPE_VBI_CAPTURE)
1763 if (type != fh->type)
1766 em28xx_videodbg("vidioc_streamoff fh=%p t=%d fh->res=%d dev->res=%d\n",
1767 fh, type, fh->resources, dev->resources);
1769 if (fh->type == V4L2_BUF_TYPE_VIDEO_CAPTURE) {
1770 videobuf_streamoff(&fh->vb_vidq);
1771 res_free(fh, EM28XX_RESOURCE_VIDEO);
1772 } else if (fh->type == V4L2_BUF_TYPE_VBI_CAPTURE) {
1773 videobuf_streamoff(&fh->vb_vbiq);
1774 res_free(fh, EM28XX_RESOURCE_VBI);
1780 static int vidioc_querycap(struct file *file, void *priv,
1781 struct v4l2_capability *cap)
1783 struct em28xx_fh *fh = priv;
1784 struct em28xx *dev = fh->dev;
1786 strlcpy(cap->driver, "em28xx", sizeof(cap->driver));
1787 strlcpy(cap->card, em28xx_boards[dev->model].name, sizeof(cap->card));
1788 usb_make_path(dev->udev, cap->bus_info, sizeof(cap->bus_info));
1790 cap->version = EM28XX_VERSION_CODE;
1793 V4L2_CAP_SLICED_VBI_CAPTURE |
1794 V4L2_CAP_VIDEO_CAPTURE |
1795 V4L2_CAP_READWRITE | V4L2_CAP_STREAMING;
1798 cap->capabilities |= V4L2_CAP_VBI_CAPTURE;
1800 if (dev->audio_mode.has_audio)
1801 cap->capabilities |= V4L2_CAP_AUDIO;
1803 if (dev->tuner_type != TUNER_ABSENT)
1804 cap->capabilities |= V4L2_CAP_TUNER;
1809 static int vidioc_enum_fmt_vid_cap(struct file *file, void *priv,
1810 struct v4l2_fmtdesc *f)
1812 if (unlikely(f->index >= ARRAY_SIZE(format)))
1815 strlcpy(f->description, format[f->index].name, sizeof(f->description));
1816 f->pixelformat = format[f->index].fourcc;
1821 /* Sliced VBI ioctls */
1822 static int vidioc_g_fmt_sliced_vbi_cap(struct file *file, void *priv,
1823 struct v4l2_format *f)
1825 struct em28xx_fh *fh = priv;
1826 struct em28xx *dev = fh->dev;
1829 rc = check_dev(dev);
1833 mutex_lock(&dev->lock);
1835 f->fmt.sliced.service_set = 0;
1836 v4l2_device_call_all(&dev->v4l2_dev, 0, vbi, g_sliced_fmt, &f->fmt.sliced);
1838 if (f->fmt.sliced.service_set == 0)
1841 mutex_unlock(&dev->lock);
1846 static int vidioc_try_set_sliced_vbi_cap(struct file *file, void *priv,
1847 struct v4l2_format *f)
1849 struct em28xx_fh *fh = priv;
1850 struct em28xx *dev = fh->dev;
1853 rc = check_dev(dev);
1857 mutex_lock(&dev->lock);
1858 v4l2_device_call_all(&dev->v4l2_dev, 0, vbi, g_sliced_fmt, &f->fmt.sliced);
1859 mutex_unlock(&dev->lock);
1861 if (f->fmt.sliced.service_set == 0)
1867 /* RAW VBI ioctls */
1869 static int vidioc_g_fmt_vbi_cap(struct file *file, void *priv,
1870 struct v4l2_format *format)
1872 struct em28xx_fh *fh = priv;
1873 struct em28xx *dev = fh->dev;
1875 format->fmt.vbi.samples_per_line = dev->vbi_width;
1876 format->fmt.vbi.sample_format = V4L2_PIX_FMT_GREY;
1877 format->fmt.vbi.offset = 0;
1878 format->fmt.vbi.flags = 0;
1879 format->fmt.vbi.sampling_rate = 6750000 * 4 / 2;
1880 format->fmt.vbi.count[0] = dev->vbi_height;
1881 format->fmt.vbi.count[1] = dev->vbi_height;
1883 /* Varies by video standard (NTSC, PAL, etc.) */
1884 if (dev->norm & V4L2_STD_525_60) {
1886 format->fmt.vbi.start[0] = 10;
1887 format->fmt.vbi.start[1] = 273;
1888 } else if (dev->norm & V4L2_STD_625_50) {
1890 format->fmt.vbi.start[0] = 6;
1891 format->fmt.vbi.start[1] = 318;
1897 static int vidioc_s_fmt_vbi_cap(struct file *file, void *priv,
1898 struct v4l2_format *format)
1900 struct em28xx_fh *fh = priv;
1901 struct em28xx *dev = fh->dev;
1903 format->fmt.vbi.samples_per_line = dev->vbi_width;
1904 format->fmt.vbi.sample_format = V4L2_PIX_FMT_GREY;
1905 format->fmt.vbi.offset = 0;
1906 format->fmt.vbi.flags = 0;
1907 format->fmt.vbi.sampling_rate = 6750000 * 4 / 2;
1908 format->fmt.vbi.count[0] = dev->vbi_height;
1909 format->fmt.vbi.count[1] = dev->vbi_height;
1911 /* Varies by video standard (NTSC, PAL, etc.) */
1912 if (dev->norm & V4L2_STD_525_60) {
1914 format->fmt.vbi.start[0] = 10;
1915 format->fmt.vbi.start[1] = 273;
1916 } else if (dev->norm & V4L2_STD_625_50) {
1918 format->fmt.vbi.start[0] = 6;
1919 format->fmt.vbi.start[1] = 318;
1925 static int vidioc_reqbufs(struct file *file, void *priv,
1926 struct v4l2_requestbuffers *rb)
1928 struct em28xx_fh *fh = priv;
1929 struct em28xx *dev = fh->dev;
1932 rc = check_dev(dev);
1936 if (fh->type == V4L2_BUF_TYPE_VIDEO_CAPTURE)
1937 return videobuf_reqbufs(&fh->vb_vidq, rb);
1939 return videobuf_reqbufs(&fh->vb_vbiq, rb);
1942 static int vidioc_querybuf(struct file *file, void *priv,
1943 struct v4l2_buffer *b)
1945 struct em28xx_fh *fh = priv;
1946 struct em28xx *dev = fh->dev;
1949 rc = check_dev(dev);
1953 if (fh->type == V4L2_BUF_TYPE_VIDEO_CAPTURE)
1954 return videobuf_querybuf(&fh->vb_vidq, b);
1956 /* FIXME: I'm not sure yet whether this is a bug in zvbi or
1957 the videobuf framework, but we probably shouldn't be
1958 returning a buffer larger than that which was asked for.
1959 At a minimum, it causes a crash in zvbi since it does
1960 a memcpy based on the source buffer length */
1961 int result = videobuf_querybuf(&fh->vb_vbiq, b);
1962 b->length = dev->vbi_width * dev->vbi_height * 2;
1968 static int vidioc_qbuf(struct file *file, void *priv, struct v4l2_buffer *b)
1970 struct em28xx_fh *fh = priv;
1971 struct em28xx *dev = fh->dev;
1974 rc = check_dev(dev);
1978 if (fh->type == V4L2_BUF_TYPE_VIDEO_CAPTURE)
1979 return videobuf_qbuf(&fh->vb_vidq, b);
1981 return videobuf_qbuf(&fh->vb_vbiq, b);
1984 static int vidioc_dqbuf(struct file *file, void *priv, struct v4l2_buffer *b)
1986 struct em28xx_fh *fh = priv;
1987 struct em28xx *dev = fh->dev;
1990 rc = check_dev(dev);
1994 if (fh->type == V4L2_BUF_TYPE_VIDEO_CAPTURE)
1995 return videobuf_dqbuf(&fh->vb_vidq, b, file->f_flags &
1998 return videobuf_dqbuf(&fh->vb_vbiq, b, file->f_flags &
2002 #ifdef CONFIG_VIDEO_V4L1_COMPAT
2003 static int vidiocgmbuf(struct file *file, void *priv, struct video_mbuf *mbuf)
2005 struct em28xx_fh *fh = priv;
2007 if (fh->type == V4L2_BUF_TYPE_VIDEO_CAPTURE)
2008 return videobuf_cgmbuf(&fh->vb_vidq, mbuf, 8);
2010 return videobuf_cgmbuf(&fh->vb_vbiq, mbuf, 8);
2015 /* ----------------------------------------------------------- */
2016 /* RADIO ESPECIFIC IOCTLS */
2017 /* ----------------------------------------------------------- */
2019 static int radio_querycap(struct file *file, void *priv,
2020 struct v4l2_capability *cap)
2022 struct em28xx *dev = ((struct em28xx_fh *)priv)->dev;
2024 strlcpy(cap->driver, "em28xx", sizeof(cap->driver));
2025 strlcpy(cap->card, em28xx_boards[dev->model].name, sizeof(cap->card));
2026 usb_make_path(dev->udev, cap->bus_info, sizeof(cap->bus_info));
2028 cap->version = EM28XX_VERSION_CODE;
2029 cap->capabilities = V4L2_CAP_TUNER;
2033 static int radio_g_tuner(struct file *file, void *priv,
2034 struct v4l2_tuner *t)
2036 struct em28xx *dev = ((struct em28xx_fh *)priv)->dev;
2038 if (unlikely(t->index > 0))
2041 strcpy(t->name, "Radio");
2042 t->type = V4L2_TUNER_RADIO;
2044 mutex_lock(&dev->lock);
2045 v4l2_device_call_all(&dev->v4l2_dev, 0, tuner, g_tuner, t);
2046 mutex_unlock(&dev->lock);
2051 static int radio_enum_input(struct file *file, void *priv,
2052 struct v4l2_input *i)
2056 strcpy(i->name, "Radio");
2057 i->type = V4L2_INPUT_TYPE_TUNER;
2062 static int radio_g_audio(struct file *file, void *priv, struct v4l2_audio *a)
2064 if (unlikely(a->index))
2067 strcpy(a->name, "Radio");
2071 static int radio_s_tuner(struct file *file, void *priv,
2072 struct v4l2_tuner *t)
2074 struct em28xx *dev = ((struct em28xx_fh *)priv)->dev;
2079 mutex_lock(&dev->lock);
2080 v4l2_device_call_all(&dev->v4l2_dev, 0, tuner, s_tuner, t);
2081 mutex_unlock(&dev->lock);
2086 static int radio_s_audio(struct file *file, void *fh,
2087 struct v4l2_audio *a)
2092 static int radio_s_input(struct file *file, void *fh, unsigned int i)
2097 static int radio_queryctrl(struct file *file, void *priv,
2098 struct v4l2_queryctrl *qc)
2102 if (qc->id < V4L2_CID_BASE ||
2103 qc->id >= V4L2_CID_LASTP1)
2106 for (i = 0; i < ARRAY_SIZE(ac97_qctrl); i++) {
2107 if (qc->id && qc->id == ac97_qctrl[i].id) {
2108 memcpy(qc, &(ac97_qctrl[i]), sizeof(*qc));
2117 * em28xx_v4l2_open()
2118 * inits the device and starts isoc transfer
2120 static int em28xx_v4l2_open(struct file *filp)
2122 int errCode = 0, radio = 0;
2123 struct video_device *vdev = video_devdata(filp);
2124 struct em28xx *dev = video_drvdata(filp);
2125 enum v4l2_buf_type fh_type = 0;
2126 struct em28xx_fh *fh;
2127 enum v4l2_field field;
2129 switch (vdev->vfl_type) {
2130 case VFL_TYPE_GRABBER:
2131 fh_type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
2134 fh_type = V4L2_BUF_TYPE_VBI_CAPTURE;
2136 case VFL_TYPE_RADIO:
2141 mutex_lock(&dev->lock);
2143 em28xx_videodbg("open dev=%s type=%s users=%d\n",
2144 video_device_node_name(vdev), v4l2_type_names[fh_type],
2148 fh = kzalloc(sizeof(struct em28xx_fh), GFP_KERNEL);
2150 em28xx_errdev("em28xx-video.c: Out of memory?!\n");
2151 mutex_unlock(&dev->lock);
2157 filp->private_data = fh;
2159 if (fh->type == V4L2_BUF_TYPE_VIDEO_CAPTURE && dev->users == 0) {
2160 em28xx_set_mode(dev, EM28XX_ANALOG_MODE);
2161 em28xx_set_alternate(dev);
2162 em28xx_resolution_set(dev);
2164 /* Needed, since GPIO might have disabled power of
2167 em28xx_wake_i2c(dev);
2171 em28xx_videodbg("video_open: setting radio device\n");
2172 v4l2_device_call_all(&dev->v4l2_dev, 0, tuner, s_radio);
2177 if (dev->progressive)
2178 field = V4L2_FIELD_NONE;
2180 field = V4L2_FIELD_INTERLACED;
2182 videobuf_queue_vmalloc_init(&fh->vb_vidq, &em28xx_video_qops,
2184 V4L2_BUF_TYPE_VIDEO_CAPTURE, field,
2185 sizeof(struct em28xx_buffer), fh, NULL);
2187 videobuf_queue_vmalloc_init(&fh->vb_vbiq, &em28xx_vbi_qops,
2189 V4L2_BUF_TYPE_VBI_CAPTURE,
2191 sizeof(struct em28xx_buffer), fh, NULL);
2193 mutex_unlock(&dev->lock);
2199 * em28xx_realease_resources()
2200 * unregisters the v4l2,i2c and usb devices
2201 * called when the device gets disconected or at module unload
2203 void em28xx_release_analog_resources(struct em28xx *dev)
2206 /*FIXME: I2C IR should be disconnected */
2208 if (dev->radio_dev) {
2209 if (video_is_registered(dev->radio_dev))
2210 video_unregister_device(dev->radio_dev);
2212 video_device_release(dev->radio_dev);
2213 dev->radio_dev = NULL;
2216 em28xx_info("V4L2 device %s deregistered\n",
2217 video_device_node_name(dev->vbi_dev));
2218 if (video_is_registered(dev->vbi_dev))
2219 video_unregister_device(dev->vbi_dev);
2221 video_device_release(dev->vbi_dev);
2222 dev->vbi_dev = NULL;
2225 em28xx_info("V4L2 device %s deregistered\n",
2226 video_device_node_name(dev->vdev));
2227 if (video_is_registered(dev->vdev))
2228 video_unregister_device(dev->vdev);
2230 video_device_release(dev->vdev);
2236 * em28xx_v4l2_close()
2237 * stops streaming and deallocates all resources allocated by the v4l2
2240 static int em28xx_v4l2_close(struct file *filp)
2242 struct em28xx_fh *fh = filp->private_data;
2243 struct em28xx *dev = fh->dev;
2246 em28xx_videodbg("users=%d\n", dev->users);
2248 if (res_check(fh, EM28XX_RESOURCE_VIDEO)) {
2249 videobuf_stop(&fh->vb_vidq);
2250 res_free(fh, EM28XX_RESOURCE_VIDEO);
2253 if (res_check(fh, EM28XX_RESOURCE_VBI)) {
2254 videobuf_stop(&fh->vb_vbiq);
2255 res_free(fh, EM28XX_RESOURCE_VBI);
2258 if (dev->users == 1) {
2259 /* the device is already disconnect,
2260 free the remaining resources */
2261 if (dev->state & DEV_DISCONNECTED) {
2262 em28xx_release_resources(dev);
2267 /* Save some power by putting tuner to sleep */
2268 v4l2_device_call_all(&dev->v4l2_dev, 0, core, s_power, 0);
2270 /* do this before setting alternate! */
2271 em28xx_uninit_isoc(dev);
2272 em28xx_set_mode(dev, EM28XX_SUSPEND);
2274 /* set alternate 0 */
2276 em28xx_videodbg("setting alternate 0\n");
2277 errCode = usb_set_interface(dev->udev, 0, 0);
2279 em28xx_errdev("cannot change alternate number to "
2280 "0 (error=%i)\n", errCode);
2284 videobuf_mmap_free(&fh->vb_vidq);
2285 videobuf_mmap_free(&fh->vb_vbiq);
2288 wake_up_interruptible_nr(&dev->open, 1);
2293 * em28xx_v4l2_read()
2294 * will allocate buffers when called for the first time
2297 em28xx_v4l2_read(struct file *filp, char __user *buf, size_t count,
2300 struct em28xx_fh *fh = filp->private_data;
2301 struct em28xx *dev = fh->dev;
2304 rc = check_dev(dev);
2308 /* FIXME: read() is not prepared to allow changing the video
2309 resolution while streaming. Seems a bug at em28xx_set_fmt
2312 if (fh->type == V4L2_BUF_TYPE_VIDEO_CAPTURE) {
2313 if (res_locked(dev, EM28XX_RESOURCE_VIDEO))
2316 return videobuf_read_stream(&fh->vb_vidq, buf, count, pos, 0,
2317 filp->f_flags & O_NONBLOCK);
2321 if (fh->type == V4L2_BUF_TYPE_VBI_CAPTURE) {
2322 if (!res_get(fh, EM28XX_RESOURCE_VBI))
2325 return videobuf_read_stream(&fh->vb_vbiq, buf, count, pos, 0,
2326 filp->f_flags & O_NONBLOCK);
2333 * em28xx_v4l2_poll()
2334 * will allocate buffers when called for the first time
2336 static unsigned int em28xx_v4l2_poll(struct file *filp, poll_table *wait)
2338 struct em28xx_fh *fh = filp->private_data;
2339 struct em28xx *dev = fh->dev;
2342 rc = check_dev(dev);
2346 if (fh->type == V4L2_BUF_TYPE_VIDEO_CAPTURE) {
2347 if (!res_get(fh, EM28XX_RESOURCE_VIDEO))
2349 return videobuf_poll_stream(filp, &fh->vb_vidq, wait);
2350 } else if (fh->type == V4L2_BUF_TYPE_VBI_CAPTURE) {
2351 if (!res_get(fh, EM28XX_RESOURCE_VBI))
2353 return videobuf_poll_stream(filp, &fh->vb_vbiq, wait);
2360 * em28xx_v4l2_mmap()
2362 static int em28xx_v4l2_mmap(struct file *filp, struct vm_area_struct *vma)
2364 struct em28xx_fh *fh = filp->private_data;
2365 struct em28xx *dev = fh->dev;
2368 rc = check_dev(dev);
2372 if (fh->type == V4L2_BUF_TYPE_VIDEO_CAPTURE)
2373 rc = videobuf_mmap_mapper(&fh->vb_vidq, vma);
2374 else if (fh->type == V4L2_BUF_TYPE_VBI_CAPTURE)
2375 rc = videobuf_mmap_mapper(&fh->vb_vbiq, vma);
2377 em28xx_videodbg("vma start=0x%08lx, size=%ld, ret=%d\n",
2378 (unsigned long)vma->vm_start,
2379 (unsigned long)vma->vm_end-(unsigned long)vma->vm_start,
2385 static const struct v4l2_file_operations em28xx_v4l_fops = {
2386 .owner = THIS_MODULE,
2387 .open = em28xx_v4l2_open,
2388 .release = em28xx_v4l2_close,
2389 .read = em28xx_v4l2_read,
2390 .poll = em28xx_v4l2_poll,
2391 .mmap = em28xx_v4l2_mmap,
2392 .ioctl = video_ioctl2,
2395 static const struct v4l2_ioctl_ops video_ioctl_ops = {
2396 .vidioc_querycap = vidioc_querycap,
2397 .vidioc_enum_fmt_vid_cap = vidioc_enum_fmt_vid_cap,
2398 .vidioc_g_fmt_vid_cap = vidioc_g_fmt_vid_cap,
2399 .vidioc_try_fmt_vid_cap = vidioc_try_fmt_vid_cap,
2400 .vidioc_s_fmt_vid_cap = vidioc_s_fmt_vid_cap,
2401 .vidioc_g_fmt_vbi_cap = vidioc_g_fmt_vbi_cap,
2402 .vidioc_s_fmt_vbi_cap = vidioc_s_fmt_vbi_cap,
2403 .vidioc_g_audio = vidioc_g_audio,
2404 .vidioc_s_audio = vidioc_s_audio,
2405 .vidioc_cropcap = vidioc_cropcap,
2407 .vidioc_g_fmt_sliced_vbi_cap = vidioc_g_fmt_sliced_vbi_cap,
2408 .vidioc_try_fmt_sliced_vbi_cap = vidioc_try_set_sliced_vbi_cap,
2409 .vidioc_s_fmt_sliced_vbi_cap = vidioc_try_set_sliced_vbi_cap,
2411 .vidioc_reqbufs = vidioc_reqbufs,
2412 .vidioc_querybuf = vidioc_querybuf,
2413 .vidioc_qbuf = vidioc_qbuf,
2414 .vidioc_dqbuf = vidioc_dqbuf,
2415 .vidioc_g_std = vidioc_g_std,
2416 .vidioc_s_std = vidioc_s_std,
2417 .vidioc_g_parm = vidioc_g_parm,
2418 .vidioc_s_parm = vidioc_s_parm,
2419 .vidioc_enum_input = vidioc_enum_input,
2420 .vidioc_g_input = vidioc_g_input,
2421 .vidioc_s_input = vidioc_s_input,
2422 .vidioc_queryctrl = vidioc_queryctrl,
2423 .vidioc_g_ctrl = vidioc_g_ctrl,
2424 .vidioc_s_ctrl = vidioc_s_ctrl,
2425 .vidioc_streamon = vidioc_streamon,
2426 .vidioc_streamoff = vidioc_streamoff,
2427 .vidioc_g_tuner = vidioc_g_tuner,
2428 .vidioc_s_tuner = vidioc_s_tuner,
2429 .vidioc_g_frequency = vidioc_g_frequency,
2430 .vidioc_s_frequency = vidioc_s_frequency,
2431 #ifdef CONFIG_VIDEO_ADV_DEBUG
2432 .vidioc_g_register = vidioc_g_register,
2433 .vidioc_s_register = vidioc_s_register,
2434 .vidioc_g_chip_ident = vidioc_g_chip_ident,
2436 #ifdef CONFIG_VIDEO_V4L1_COMPAT
2437 .vidiocgmbuf = vidiocgmbuf,
2441 static const struct video_device em28xx_video_template = {
2442 .fops = &em28xx_v4l_fops,
2443 .release = video_device_release,
2444 .ioctl_ops = &video_ioctl_ops,
2446 .tvnorms = V4L2_STD_ALL,
2447 .current_norm = V4L2_STD_PAL,
2450 static const struct v4l2_file_operations radio_fops = {
2451 .owner = THIS_MODULE,
2452 .open = em28xx_v4l2_open,
2453 .release = em28xx_v4l2_close,
2454 .ioctl = video_ioctl2,
2457 static const struct v4l2_ioctl_ops radio_ioctl_ops = {
2458 .vidioc_querycap = radio_querycap,
2459 .vidioc_g_tuner = radio_g_tuner,
2460 .vidioc_enum_input = radio_enum_input,
2461 .vidioc_g_audio = radio_g_audio,
2462 .vidioc_s_tuner = radio_s_tuner,
2463 .vidioc_s_audio = radio_s_audio,
2464 .vidioc_s_input = radio_s_input,
2465 .vidioc_queryctrl = radio_queryctrl,
2466 .vidioc_g_ctrl = vidioc_g_ctrl,
2467 .vidioc_s_ctrl = vidioc_s_ctrl,
2468 .vidioc_g_frequency = vidioc_g_frequency,
2469 .vidioc_s_frequency = vidioc_s_frequency,
2470 #ifdef CONFIG_VIDEO_ADV_DEBUG
2471 .vidioc_g_register = vidioc_g_register,
2472 .vidioc_s_register = vidioc_s_register,
2476 static struct video_device em28xx_radio_template = {
2477 .name = "em28xx-radio",
2478 .fops = &radio_fops,
2479 .ioctl_ops = &radio_ioctl_ops,
2482 /******************************** usb interface ******************************/
2486 static struct video_device *em28xx_vdev_init(struct em28xx *dev,
2487 const struct video_device *template,
2488 const char *type_name)
2490 struct video_device *vfd;
2492 vfd = video_device_alloc();
2497 vfd->v4l2_dev = &dev->v4l2_dev;
2498 vfd->release = video_device_release;
2499 vfd->debug = video_debug;
2501 snprintf(vfd->name, sizeof(vfd->name), "%s %s",
2502 dev->name, type_name);
2504 video_set_drvdata(vfd, dev);
2508 int em28xx_register_analog_devices(struct em28xx *dev)
2513 printk(KERN_INFO "%s: v4l2 driver version %d.%d.%d\n",
2515 (EM28XX_VERSION_CODE >> 16) & 0xff,
2516 (EM28XX_VERSION_CODE >> 8) & 0xff, EM28XX_VERSION_CODE & 0xff);
2518 /* set default norm */
2519 dev->norm = em28xx_video_template.current_norm;
2520 dev->interlaced = EM28XX_INTERLACED_DEFAULT;
2523 /* Analog specific initialization */
2524 dev->format = &format[0];
2525 em28xx_set_video_format(dev, format[0].fourcc,
2526 norm_maxw(dev), norm_maxh(dev));
2528 video_mux(dev, dev->ctl_input);
2530 /* Audio defaults */
2534 /* em28xx_write_reg(dev, EM28XX_R0E_AUDIOSRC, 0xc0); audio register */
2535 val = (u8)em28xx_read_reg(dev, EM28XX_R0F_XCLK);
2536 em28xx_write_reg(dev, EM28XX_R0F_XCLK,
2537 (EM28XX_XCLK_AUDIO_UNMUTE | val));
2539 em28xx_set_outfmt(dev);
2540 em28xx_colorlevels_set_default(dev);
2541 em28xx_compression_disable(dev);
2543 /* allocate and fill video video_device struct */
2544 dev->vdev = em28xx_vdev_init(dev, &em28xx_video_template, "video");
2546 em28xx_errdev("cannot allocate video_device.\n");
2550 /* register v4l2 video video_device */
2551 ret = video_register_device(dev->vdev, VFL_TYPE_GRABBER,
2552 video_nr[dev->devno]);
2554 em28xx_errdev("unable to register video device (error=%i).\n",
2559 /* Allocate and fill vbi video_device struct */
2560 if (em28xx_vbi_supported(dev) == 1) {
2561 dev->vbi_dev = em28xx_vdev_init(dev, &em28xx_video_template,
2564 /* register v4l2 vbi video_device */
2565 ret = video_register_device(dev->vbi_dev, VFL_TYPE_VBI,
2566 vbi_nr[dev->devno]);
2568 em28xx_errdev("unable to register vbi device\n");
2573 if (em28xx_boards[dev->model].radio.type == EM28XX_RADIO) {
2574 dev->radio_dev = em28xx_vdev_init(dev, &em28xx_radio_template,
2576 if (!dev->radio_dev) {
2577 em28xx_errdev("cannot allocate video_device.\n");
2580 ret = video_register_device(dev->radio_dev, VFL_TYPE_RADIO,
2581 radio_nr[dev->devno]);
2583 em28xx_errdev("can't register radio device\n");
2586 em28xx_info("Registered radio device as %s\n",
2587 video_device_node_name(dev->radio_dev));
2590 em28xx_info("V4L2 video device registered as %s\n",
2591 video_device_node_name(dev->vdev));
2594 em28xx_info("V4L2 VBI device registered as %s\n",
2595 video_device_node_name(dev->vbi_dev));