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>
40 #include <media/v4l2-common.h>
41 #include <media/v4l2-ioctl.h>
42 #include <media/v4l2-chip-ident.h>
43 #include <media/msp3400.h>
44 #include <media/tuner.h>
46 #define DRIVER_AUTHOR "Ludovico Cavedon <cavedon@sssup.it>, " \
47 "Markus Rechberger <mrechberger@gmail.com>, " \
48 "Mauro Carvalho Chehab <mchehab@infradead.org>, " \
49 "Sascha Sommer <saschasommer@freenet.de>"
51 #define DRIVER_DESC "Empia em28xx based USB video device driver"
52 #define EM28XX_VERSION_CODE KERNEL_VERSION(0, 1, 2)
54 #define em28xx_videodbg(fmt, arg...) do {\
56 printk(KERN_INFO "%s %s :"fmt, \
57 dev->name, __func__ , ##arg); } while (0)
59 static unsigned int isoc_debug;
60 module_param(isoc_debug, int, 0644);
61 MODULE_PARM_DESC(isoc_debug, "enable debug messages [isoc transfers]");
63 #define em28xx_isocdbg(fmt, arg...) \
66 printk(KERN_INFO "%s %s :"fmt, \
67 dev->name, __func__ , ##arg); \
71 MODULE_AUTHOR(DRIVER_AUTHOR);
72 MODULE_DESCRIPTION(DRIVER_DESC);
73 MODULE_LICENSE("GPL");
75 static unsigned int video_nr[] = {[0 ... (EM28XX_MAXBOARDS - 1)] = UNSET };
76 static unsigned int vbi_nr[] = {[0 ... (EM28XX_MAXBOARDS - 1)] = UNSET };
77 static unsigned int radio_nr[] = {[0 ... (EM28XX_MAXBOARDS - 1)] = UNSET };
79 module_param_array(video_nr, int, NULL, 0444);
80 module_param_array(vbi_nr, int, NULL, 0444);
81 module_param_array(radio_nr, int, NULL, 0444);
82 MODULE_PARM_DESC(video_nr, "video device numbers");
83 MODULE_PARM_DESC(vbi_nr, "vbi device numbers");
84 MODULE_PARM_DESC(radio_nr, "radio device numbers");
86 static unsigned int video_debug;
87 module_param(video_debug, int, 0644);
88 MODULE_PARM_DESC(video_debug, "enable debug messages [video]");
90 /* supported video standards */
91 static struct em28xx_fmt format[] = {
93 .name = "16 bpp YUY2, 4:2:2, packed",
94 .fourcc = V4L2_PIX_FMT_YUYV,
96 .reg = EM28XX_OUTFMT_YUV422_Y0UY1V,
98 .name = "16 bpp RGB 565, LE",
99 .fourcc = V4L2_PIX_FMT_RGB565,
101 .reg = EM28XX_OUTFMT_RGB_16_656,
103 .name = "8 bpp Bayer BGBG..GRGR",
104 .fourcc = V4L2_PIX_FMT_SBGGR8,
106 .reg = EM28XX_OUTFMT_RGB_8_BGBG,
108 .name = "8 bpp Bayer GRGR..BGBG",
109 .fourcc = V4L2_PIX_FMT_SGRBG8,
111 .reg = EM28XX_OUTFMT_RGB_8_GRGR,
113 .name = "8 bpp Bayer GBGB..RGRG",
114 .fourcc = V4L2_PIX_FMT_SGBRG8,
116 .reg = EM28XX_OUTFMT_RGB_8_GBGB,
118 .name = "12 bpp YUV411",
119 .fourcc = V4L2_PIX_FMT_YUV411P,
121 .reg = EM28XX_OUTFMT_YUV411,
125 /* supported controls */
126 /* Common to all boards */
127 static struct v4l2_queryctrl ac97_qctrl[] = {
129 .id = V4L2_CID_AUDIO_VOLUME,
130 .type = V4L2_CTRL_TYPE_INTEGER,
135 .default_value = 0x1f,
136 .flags = V4L2_CTRL_FLAG_SLIDER,
138 .id = V4L2_CID_AUDIO_MUTE,
139 .type = V4L2_CTRL_TYPE_BOOLEAN,
149 /* ------------------------------------------------------------------
150 DMA and thread functions
151 ------------------------------------------------------------------*/
154 * Announces that a buffer were filled and request the next
156 static inline void buffer_filled(struct em28xx *dev,
157 struct em28xx_dmaqueue *dma_q,
158 struct em28xx_buffer *buf)
160 /* Advice that buffer was filled */
161 em28xx_isocdbg("[%p/%d] wakeup\n", buf, buf->vb.i);
162 buf->vb.state = VIDEOBUF_DONE;
163 buf->vb.field_count++;
164 do_gettimeofday(&buf->vb.ts);
166 dev->isoc_ctl.vid_buf = NULL;
168 list_del(&buf->vb.queue);
169 wake_up(&buf->vb.done);
172 static inline void vbi_buffer_filled(struct em28xx *dev,
173 struct em28xx_dmaqueue *dma_q,
174 struct em28xx_buffer *buf)
176 /* Advice that buffer was filled */
177 em28xx_isocdbg("[%p/%d] wakeup\n", buf, buf->vb.i);
179 buf->vb.state = VIDEOBUF_DONE;
180 buf->vb.field_count++;
181 do_gettimeofday(&buf->vb.ts);
183 dev->isoc_ctl.vbi_buf = NULL;
185 list_del(&buf->vb.queue);
186 wake_up(&buf->vb.done);
190 * Identify the buffer header type and properly handles
192 static void em28xx_copy_video(struct em28xx *dev,
193 struct em28xx_dmaqueue *dma_q,
194 struct em28xx_buffer *buf,
196 unsigned char *outp, unsigned long len)
198 void *fieldstart, *startwrite, *startread;
199 int linesdone, currlinedone, offset, lencopy, remain;
200 int bytesperline = dev->width << 1;
202 if (dma_q->pos + len > buf->vb.size)
203 len = buf->vb.size - dma_q->pos;
205 if (p[0] != 0x88 && p[0] != 0x22) {
206 em28xx_isocdbg("frame is not complete\n");
214 if (dev->progressive)
217 /* Interlaces two half frames */
221 fieldstart = outp + bytesperline;
224 linesdone = dma_q->pos / bytesperline;
225 currlinedone = dma_q->pos % bytesperline;
227 if (dev->progressive)
228 offset = linesdone * bytesperline + currlinedone;
230 offset = linesdone * bytesperline * 2 + currlinedone;
232 startwrite = fieldstart + offset;
233 lencopy = bytesperline - currlinedone;
234 lencopy = lencopy > remain ? remain : lencopy;
236 if ((char *)startwrite + lencopy > (char *)outp + buf->vb.size) {
237 em28xx_isocdbg("Overflow of %zi bytes past buffer end (1)\n",
238 ((char *)startwrite + lencopy) -
239 ((char *)outp + buf->vb.size));
240 remain = (char *)outp + buf->vb.size - (char *)startwrite;
245 memcpy(startwrite, startread, lencopy);
250 startwrite += lencopy + bytesperline;
251 startread += lencopy;
252 if (bytesperline > remain)
255 lencopy = bytesperline;
257 if ((char *)startwrite + lencopy > (char *)outp +
259 em28xx_isocdbg("Overflow of %zi bytes past buffer end"
261 ((char *)startwrite + lencopy) -
262 ((char *)outp + buf->vb.size));
263 lencopy = remain = (char *)outp + buf->vb.size -
269 memcpy(startwrite, startread, lencopy);
277 static void em28xx_copy_vbi(struct em28xx *dev,
278 struct em28xx_dmaqueue *dma_q,
279 struct em28xx_buffer *buf,
281 unsigned char *outp, unsigned long len)
283 void *startwrite, *startread;
285 int bytesperline = dev->vbi_width;
288 em28xx_isocdbg("dev is null\n");
293 em28xx_isocdbg("dma_q is null\n");
300 em28xx_isocdbg("p is null\n");
304 em28xx_isocdbg("outp is null\n");
308 if (dma_q->pos + len > buf->vb.size)
309 len = buf->vb.size - dma_q->pos;
311 if ((p[0] == 0x33 && p[1] == 0x95) ||
312 (p[0] == 0x88 && p[1] == 0x88)) {
313 /* Header field, advance past it */
321 startwrite = outp + dma_q->pos;
324 /* Make sure the bottom field populates the second half of the frame */
325 if (buf->top_field == 0) {
326 startwrite += bytesperline * dev->vbi_height;
327 offset += bytesperline * dev->vbi_height;
330 memcpy(startwrite, startread, len);
334 static inline void print_err_status(struct em28xx *dev,
335 int packet, int status)
337 char *errmsg = "Unknown";
341 errmsg = "unlinked synchronuously";
344 errmsg = "unlinked asynchronuously";
347 errmsg = "Buffer error (overrun)";
350 errmsg = "Stalled (device not responding)";
353 errmsg = "Babble (bad cable?)";
356 errmsg = "Bit-stuff error (bad cable?)";
359 errmsg = "CRC/Timeout (could be anything)";
362 errmsg = "Device does not respond";
366 em28xx_isocdbg("URB status %d [%s].\n", status, errmsg);
368 em28xx_isocdbg("URB packet %d, status %d [%s].\n",
369 packet, status, errmsg);
374 * video-buf generic routine to get the next available buffer
376 static inline void get_next_buf(struct em28xx_dmaqueue *dma_q,
377 struct em28xx_buffer **buf)
379 struct em28xx *dev = container_of(dma_q, struct em28xx, vidq);
382 if (list_empty(&dma_q->active)) {
383 em28xx_isocdbg("No active queue to serve\n");
384 dev->isoc_ctl.vid_buf = NULL;
389 /* Get the next buffer */
390 *buf = list_entry(dma_q->active.next, struct em28xx_buffer, vb.queue);
392 /* Cleans up buffer - Usefull for testing for frame/URB loss */
393 outp = videobuf_to_vmalloc(&(*buf)->vb);
394 memset(outp, 0, (*buf)->vb.size);
396 dev->isoc_ctl.vid_buf = *buf;
402 * video-buf generic routine to get the next available VBI buffer
404 static inline void vbi_get_next_buf(struct em28xx_dmaqueue *dma_q,
405 struct em28xx_buffer **buf)
407 struct em28xx *dev = container_of(dma_q, struct em28xx, vbiq);
410 if (list_empty(&dma_q->active)) {
411 em28xx_isocdbg("No active queue to serve\n");
412 dev->isoc_ctl.vbi_buf = NULL;
417 /* Get the next buffer */
418 *buf = list_entry(dma_q->active.next, struct em28xx_buffer, vb.queue);
419 /* Cleans up buffer - Usefull for testing for frame/URB loss */
420 outp = videobuf_to_vmalloc(&(*buf)->vb);
421 memset(outp, 0x00, (*buf)->vb.size);
423 dev->isoc_ctl.vbi_buf = *buf;
429 * Controls the isoc copy of each urb packet
431 static inline int em28xx_isoc_copy(struct em28xx *dev, struct urb *urb)
433 struct em28xx_buffer *buf;
434 struct em28xx_dmaqueue *dma_q = &dev->vidq;
435 unsigned char *outp = NULL;
436 int i, len = 0, rc = 1;
442 if ((dev->state & DEV_DISCONNECTED) || (dev->state & DEV_MISCONFIGURED))
445 if (urb->status < 0) {
446 print_err_status(dev, -1, urb->status);
447 if (urb->status == -ENOENT)
451 buf = dev->isoc_ctl.vid_buf;
453 outp = videobuf_to_vmalloc(&buf->vb);
455 for (i = 0; i < urb->number_of_packets; i++) {
456 int status = urb->iso_frame_desc[i].status;
459 print_err_status(dev, i, status);
460 if (urb->iso_frame_desc[i].status != -EPROTO)
464 len = urb->iso_frame_desc[i].actual_length - 4;
466 if (urb->iso_frame_desc[i].actual_length <= 0) {
467 /* em28xx_isocdbg("packet %d is empty",i); - spammy */
470 if (urb->iso_frame_desc[i].actual_length >
472 em28xx_isocdbg("packet bigger than packet size");
476 p = urb->transfer_buffer + urb->iso_frame_desc[i].offset;
478 /* FIXME: incomplete buffer checks where removed to make
479 logic simpler. Impacts of those changes should be evaluated
481 if (p[0] == 0x33 && p[1] == 0x95 && p[2] == 0x00) {
482 em28xx_isocdbg("VBI HEADER!!!\n");
483 /* FIXME: Should add vbi copy */
486 if (p[0] == 0x22 && p[1] == 0x5a) {
487 em28xx_isocdbg("Video frame %d, length=%i, %s\n", p[2],
488 len, (p[2] & 1) ? "odd" : "even");
490 if (dev->progressive || !(p[2] & 1)) {
492 buffer_filled(dev, dma_q, buf);
493 get_next_buf(dma_q, &buf);
497 outp = videobuf_to_vmalloc(&buf->vb);
510 em28xx_copy_video(dev, dma_q, buf, p, outp, len);
515 /* Version of isoc handler that takes into account a mixture of video and
517 static inline int em28xx_isoc_copy_vbi(struct em28xx *dev, struct urb *urb)
519 struct em28xx_buffer *buf, *vbi_buf;
520 struct em28xx_dmaqueue *dma_q = &dev->vidq;
521 struct em28xx_dmaqueue *vbi_dma_q = &dev->vbiq;
522 unsigned char *outp = NULL;
523 unsigned char *vbioutp = NULL;
524 int i, len = 0, rc = 1;
531 if ((dev->state & DEV_DISCONNECTED) || (dev->state & DEV_MISCONFIGURED))
534 if (urb->status < 0) {
535 print_err_status(dev, -1, urb->status);
536 if (urb->status == -ENOENT)
540 buf = dev->isoc_ctl.vid_buf;
542 outp = videobuf_to_vmalloc(&buf->vb);
544 vbi_buf = dev->isoc_ctl.vbi_buf;
546 vbioutp = videobuf_to_vmalloc(&vbi_buf->vb);
548 for (i = 0; i < urb->number_of_packets; i++) {
549 int status = urb->iso_frame_desc[i].status;
552 print_err_status(dev, i, status);
553 if (urb->iso_frame_desc[i].status != -EPROTO)
557 len = urb->iso_frame_desc[i].actual_length - 4;
559 if (urb->iso_frame_desc[i].actual_length <= 0) {
560 /* em28xx_isocdbg("packet %d is empty",i); - spammy */
563 if (urb->iso_frame_desc[i].actual_length >
565 em28xx_isocdbg("packet bigger than packet size");
569 p = urb->transfer_buffer + urb->iso_frame_desc[i].offset;
571 /* capture type 0 = vbi start
572 capture type 1 = video start
573 capture type 2 = video in progress */
574 if (p[0] == 0x33 && p[1] == 0x95) {
575 dev->capture_type = 0;
577 em28xx_isocdbg("VBI START HEADER!!!\n");
578 dev->cur_field = p[2];
581 vbi_size = dev->vbi_width * dev->vbi_height;
583 if (dev->capture_type == 0) {
584 if (dev->vbi_read >= vbi_size) {
585 /* We've already read all the VBI data, so
586 treat the rest as video */
587 em28xx_isocdbg("dev->vbi_read > vbi_size\n");
588 } else if ((dev->vbi_read + len) < vbi_size) {
589 /* This entire frame is VBI data */
590 if (dev->vbi_read == 0 &&
591 (!(dev->cur_field & 1))) {
592 /* Brand new frame */
594 vbi_buffer_filled(dev,
597 vbi_get_next_buf(vbi_dma_q, &vbi_buf);
601 vbioutp = videobuf_to_vmalloc(
605 if (dev->vbi_read == 0) {
607 if (vbi_buf != NULL) {
608 if (dev->cur_field & 1)
609 vbi_buf->top_field = 0;
611 vbi_buf->top_field = 1;
615 dev->vbi_read += len;
616 em28xx_copy_vbi(dev, vbi_dma_q, vbi_buf, p,
619 /* Some of this frame is VBI data and some is
621 int vbi_data_len = vbi_size - dev->vbi_read;
622 dev->vbi_read += vbi_data_len;
623 em28xx_copy_vbi(dev, vbi_dma_q, vbi_buf, p,
624 vbioutp, vbi_data_len);
625 dev->capture_type = 1;
631 if (dev->capture_type == 1) {
632 dev->capture_type = 2;
633 em28xx_isocdbg("Video frame %d, length=%i, %s\n", p[2],
634 len, (p[2] & 1) ? "odd" : "even");
636 if (dev->progressive || !(dev->cur_field & 1)) {
638 buffer_filled(dev, dma_q, buf);
639 get_next_buf(dma_q, &buf);
643 outp = videobuf_to_vmalloc(&buf->vb);
646 if (dev->cur_field & 1)
654 if (buf != NULL && dev->capture_type == 2)
655 em28xx_copy_video(dev, dma_q, buf, p, outp, len);
661 /* ------------------------------------------------------------------
663 ------------------------------------------------------------------*/
666 buffer_setup(struct videobuf_queue *vq, unsigned int *count, unsigned int *size)
668 struct em28xx_fh *fh = vq->priv_data;
669 struct em28xx *dev = fh->dev;
670 struct v4l2_frequency f;
672 *size = (fh->dev->width * fh->dev->height * dev->format->depth + 7)
676 *count = EM28XX_DEF_BUF;
678 if (*count < EM28XX_MIN_BUF)
679 *count = EM28XX_MIN_BUF;
681 /* Ask tuner to go to analog or radio mode */
682 memset(&f, 0, sizeof(f));
683 f.frequency = dev->ctl_freq;
684 f.type = fh->radio ? V4L2_TUNER_RADIO : V4L2_TUNER_ANALOG_TV;
686 v4l2_device_call_all(&dev->v4l2_dev, 0, tuner, s_frequency, &f);
691 /* This is called *without* dev->slock held; please keep it that way */
692 static void free_buffer(struct videobuf_queue *vq, struct em28xx_buffer *buf)
694 struct em28xx_fh *fh = vq->priv_data;
695 struct em28xx *dev = fh->dev;
696 unsigned long flags = 0;
700 /* We used to wait for the buffer to finish here, but this didn't work
701 because, as we were keeping the state as VIDEOBUF_QUEUED,
702 videobuf_queue_cancel marked it as finished for us.
703 (Also, it could wedge forever if the hardware was misconfigured.)
705 This should be safe; by the time we get here, the buffer isn't
706 queued anymore. If we ever start marking the buffers as
707 VIDEOBUF_ACTIVE, it won't be, though.
709 spin_lock_irqsave(&dev->slock, flags);
710 if (dev->isoc_ctl.vid_buf == buf)
711 dev->isoc_ctl.vid_buf = NULL;
712 spin_unlock_irqrestore(&dev->slock, flags);
714 videobuf_vmalloc_free(&buf->vb);
715 buf->vb.state = VIDEOBUF_NEEDS_INIT;
719 buffer_prepare(struct videobuf_queue *vq, struct videobuf_buffer *vb,
720 enum v4l2_field field)
722 struct em28xx_fh *fh = vq->priv_data;
723 struct em28xx_buffer *buf = container_of(vb, struct em28xx_buffer, vb);
724 struct em28xx *dev = fh->dev;
725 int rc = 0, urb_init = 0;
727 buf->vb.size = (fh->dev->width * fh->dev->height * dev->format->depth
730 if (0 != buf->vb.baddr && buf->vb.bsize < buf->vb.size)
733 buf->vb.width = dev->width;
734 buf->vb.height = dev->height;
735 buf->vb.field = field;
737 if (VIDEOBUF_NEEDS_INIT == buf->vb.state) {
738 rc = videobuf_iolock(vq, &buf->vb, NULL);
743 if (!dev->isoc_ctl.num_bufs)
747 if (em28xx_vbi_supported(dev) == 1)
748 rc = em28xx_init_isoc(dev, EM28XX_NUM_PACKETS,
751 em28xx_isoc_copy_vbi);
753 rc = em28xx_init_isoc(dev, EM28XX_NUM_PACKETS,
761 buf->vb.state = VIDEOBUF_PREPARED;
765 free_buffer(vq, buf);
770 buffer_queue(struct videobuf_queue *vq, struct videobuf_buffer *vb)
772 struct em28xx_buffer *buf = container_of(vb,
773 struct em28xx_buffer,
775 struct em28xx_fh *fh = vq->priv_data;
776 struct em28xx *dev = fh->dev;
777 struct em28xx_dmaqueue *vidq = &dev->vidq;
779 buf->vb.state = VIDEOBUF_QUEUED;
780 list_add_tail(&buf->vb.queue, &vidq->active);
784 static void buffer_release(struct videobuf_queue *vq,
785 struct videobuf_buffer *vb)
787 struct em28xx_buffer *buf = container_of(vb,
788 struct em28xx_buffer,
790 struct em28xx_fh *fh = vq->priv_data;
791 struct em28xx *dev = (struct em28xx *)fh->dev;
793 em28xx_isocdbg("em28xx: called buffer_release\n");
795 free_buffer(vq, buf);
798 static struct videobuf_queue_ops em28xx_video_qops = {
799 .buf_setup = buffer_setup,
800 .buf_prepare = buffer_prepare,
801 .buf_queue = buffer_queue,
802 .buf_release = buffer_release,
805 /********************* v4l2 interface **************************************/
807 static void video_mux(struct em28xx *dev, int index)
809 dev->ctl_input = index;
810 dev->ctl_ainput = INPUT(index)->amux;
811 dev->ctl_aoutput = INPUT(index)->aout;
813 if (!dev->ctl_aoutput)
814 dev->ctl_aoutput = EM28XX_AOUT_MASTER;
816 v4l2_device_call_all(&dev->v4l2_dev, 0, video, s_routing,
817 INPUT(index)->vmux, 0, 0);
819 if (dev->board.has_msp34xx) {
820 if (dev->i2s_speed) {
821 v4l2_device_call_all(&dev->v4l2_dev, 0, audio,
822 s_i2s_clock_freq, dev->i2s_speed);
824 /* Note: this is msp3400 specific */
825 v4l2_device_call_all(&dev->v4l2_dev, 0, audio, s_routing,
826 dev->ctl_ainput, MSP_OUTPUT(MSP_SC_IN_DSP_SCART1), 0);
829 if (dev->board.adecoder != EM28XX_NOADECODER) {
830 v4l2_device_call_all(&dev->v4l2_dev, 0, audio, s_routing,
831 dev->ctl_ainput, dev->ctl_aoutput, 0);
834 em28xx_audio_analog_set(dev);
837 /* Usage lock check functions */
838 static int res_get(struct em28xx_fh *fh, unsigned int bit)
840 struct em28xx *dev = fh->dev;
842 if (fh->resources & bit)
843 /* have it already allocated */
847 mutex_lock(&dev->lock);
848 if (dev->resources & bit) {
849 /* no, someone else uses it */
850 mutex_unlock(&dev->lock);
853 /* it's free, grab it */
854 fh->resources |= bit;
855 dev->resources |= bit;
856 em28xx_videodbg("res: get %d\n", bit);
857 mutex_unlock(&dev->lock);
861 static int res_check(struct em28xx_fh *fh, unsigned int bit)
863 return fh->resources & bit;
866 static int res_locked(struct em28xx *dev, unsigned int bit)
868 return dev->resources & bit;
871 static void res_free(struct em28xx_fh *fh, unsigned int bits)
873 struct em28xx *dev = fh->dev;
875 BUG_ON((fh->resources & bits) != bits);
877 mutex_lock(&dev->lock);
878 fh->resources &= ~bits;
879 dev->resources &= ~bits;
880 em28xx_videodbg("res: put %d\n", bits);
881 mutex_unlock(&dev->lock);
884 static int get_ressource(struct em28xx_fh *fh)
887 case V4L2_BUF_TYPE_VIDEO_CAPTURE:
888 return EM28XX_RESOURCE_VIDEO;
889 case V4L2_BUF_TYPE_VBI_CAPTURE:
890 return EM28XX_RESOURCE_VBI;
899 * return the ac97 supported controls
901 static int ac97_queryctrl(struct v4l2_queryctrl *qc)
905 for (i = 0; i < ARRAY_SIZE(ac97_qctrl); i++) {
906 if (qc->id && qc->id == ac97_qctrl[i].id) {
907 memcpy(qc, &(ac97_qctrl[i]), sizeof(*qc));
912 /* Control is not ac97 related */
918 * return the current values for ac97 mute and volume
920 static int ac97_get_ctrl(struct em28xx *dev, struct v4l2_control *ctrl)
923 case V4L2_CID_AUDIO_MUTE:
924 ctrl->value = dev->mute;
926 case V4L2_CID_AUDIO_VOLUME:
927 ctrl->value = dev->volume;
930 /* Control is not ac97 related */
937 * set values for ac97 mute and volume
939 static int ac97_set_ctrl(struct em28xx *dev, const struct v4l2_control *ctrl)
943 for (i = 0; i < ARRAY_SIZE(ac97_qctrl); i++)
944 if (ctrl->id == ac97_qctrl[i].id)
947 /* Announce that hasn't handle it */
951 if (ctrl->value < ac97_qctrl[i].minimum ||
952 ctrl->value > ac97_qctrl[i].maximum)
956 case V4L2_CID_AUDIO_MUTE:
957 dev->mute = ctrl->value;
959 case V4L2_CID_AUDIO_VOLUME:
960 dev->volume = ctrl->value;
964 return em28xx_audio_analog_set(dev);
967 static int check_dev(struct em28xx *dev)
969 if (dev->state & DEV_DISCONNECTED) {
970 em28xx_errdev("v4l2 ioctl: device not present\n");
974 if (dev->state & DEV_MISCONFIGURED) {
975 em28xx_errdev("v4l2 ioctl: device is misconfigured; "
976 "close and open it again\n");
982 static void get_scale(struct em28xx *dev,
983 unsigned int width, unsigned int height,
984 unsigned int *hscale, unsigned int *vscale)
986 unsigned int maxw = norm_maxw(dev);
987 unsigned int maxh = norm_maxh(dev);
989 *hscale = (((unsigned long)maxw) << 12) / width - 4096L;
990 if (*hscale >= 0x4000)
993 *vscale = (((unsigned long)maxh) << 12) / height - 4096L;
994 if (*vscale >= 0x4000)
998 /* ------------------------------------------------------------------
999 IOCTL vidioc handling
1000 ------------------------------------------------------------------*/
1002 static int vidioc_g_fmt_vid_cap(struct file *file, void *priv,
1003 struct v4l2_format *f)
1005 struct em28xx_fh *fh = priv;
1006 struct em28xx *dev = fh->dev;
1008 mutex_lock(&dev->lock);
1010 f->fmt.pix.width = dev->width;
1011 f->fmt.pix.height = dev->height;
1012 f->fmt.pix.pixelformat = dev->format->fourcc;
1013 f->fmt.pix.bytesperline = (dev->width * dev->format->depth + 7) >> 3;
1014 f->fmt.pix.sizeimage = f->fmt.pix.bytesperline * dev->height;
1015 f->fmt.pix.colorspace = V4L2_COLORSPACE_SMPTE170M;
1017 /* FIXME: TOP? NONE? BOTTOM? ALTENATE? */
1018 if (dev->progressive)
1019 f->fmt.pix.field = V4L2_FIELD_NONE;
1021 f->fmt.pix.field = dev->interlaced ?
1022 V4L2_FIELD_INTERLACED : V4L2_FIELD_TOP;
1024 mutex_unlock(&dev->lock);
1028 static struct em28xx_fmt *format_by_fourcc(unsigned int fourcc)
1032 for (i = 0; i < ARRAY_SIZE(format); i++)
1033 if (format[i].fourcc == fourcc)
1039 static int vidioc_try_fmt_vid_cap(struct file *file, void *priv,
1040 struct v4l2_format *f)
1042 struct em28xx_fh *fh = priv;
1043 struct em28xx *dev = fh->dev;
1044 unsigned int width = f->fmt.pix.width;
1045 unsigned int height = f->fmt.pix.height;
1046 unsigned int maxw = norm_maxw(dev);
1047 unsigned int maxh = norm_maxh(dev);
1048 unsigned int hscale, vscale;
1049 struct em28xx_fmt *fmt;
1051 fmt = format_by_fourcc(f->fmt.pix.pixelformat);
1053 em28xx_videodbg("Fourcc format (%08x) invalid.\n",
1054 f->fmt.pix.pixelformat);
1058 if (dev->board.is_em2800) {
1059 /* the em2800 can only scale down to 50% */
1060 height = height > (3 * maxh / 4) ? maxh : maxh / 2;
1061 width = width > (3 * maxw / 4) ? maxw : maxw / 2;
1063 /* width must even because of the YUYV format
1064 height must be even because of interlacing */
1065 v4l_bound_align_image(&width, 48, maxw, 1, &height, 32, maxh,
1069 get_scale(dev, width, height, &hscale, &vscale);
1071 width = (((unsigned long)maxw) << 12) / (hscale + 4096L);
1072 height = (((unsigned long)maxh) << 12) / (vscale + 4096L);
1074 f->fmt.pix.width = width;
1075 f->fmt.pix.height = height;
1076 f->fmt.pix.pixelformat = fmt->fourcc;
1077 f->fmt.pix.bytesperline = (dev->width * fmt->depth + 7) >> 3;
1078 f->fmt.pix.sizeimage = f->fmt.pix.bytesperline * height;
1079 f->fmt.pix.colorspace = V4L2_COLORSPACE_SMPTE170M;
1080 if (dev->progressive)
1081 f->fmt.pix.field = V4L2_FIELD_NONE;
1083 f->fmt.pix.field = dev->interlaced ?
1084 V4L2_FIELD_INTERLACED : V4L2_FIELD_TOP;
1089 static int em28xx_set_video_format(struct em28xx *dev, unsigned int fourcc,
1090 unsigned width, unsigned height)
1092 struct em28xx_fmt *fmt;
1094 fmt = format_by_fourcc(fourcc);
1100 dev->height = height;
1102 /* set new image size */
1103 get_scale(dev, dev->width, dev->height, &dev->hscale, &dev->vscale);
1105 em28xx_set_alternate(dev);
1106 em28xx_resolution_set(dev);
1111 static int vidioc_s_fmt_vid_cap(struct file *file, void *priv,
1112 struct v4l2_format *f)
1114 struct em28xx_fh *fh = priv;
1115 struct em28xx *dev = fh->dev;
1118 rc = check_dev(dev);
1122 mutex_lock(&dev->lock);
1124 vidioc_try_fmt_vid_cap(file, priv, f);
1126 if (videobuf_queue_is_busy(&fh->vb_vidq)) {
1127 em28xx_errdev("%s queue busy\n", __func__);
1132 rc = em28xx_set_video_format(dev, f->fmt.pix.pixelformat,
1133 f->fmt.pix.width, f->fmt.pix.height);
1136 mutex_unlock(&dev->lock);
1140 static int vidioc_g_std(struct file *file, void *priv, v4l2_std_id *norm)
1142 struct em28xx_fh *fh = priv;
1143 struct em28xx *dev = fh->dev;
1146 rc = check_dev(dev);
1155 static int vidioc_s_std(struct file *file, void *priv, v4l2_std_id *norm)
1157 struct em28xx_fh *fh = priv;
1158 struct em28xx *dev = fh->dev;
1159 struct v4l2_format f;
1162 rc = check_dev(dev);
1166 mutex_lock(&dev->lock);
1169 /* Adjusts width/height, if needed */
1170 f.fmt.pix.width = dev->width;
1171 f.fmt.pix.height = dev->height;
1172 vidioc_try_fmt_vid_cap(file, priv, &f);
1174 /* set new image size */
1175 dev->width = f.fmt.pix.width;
1176 dev->height = f.fmt.pix.height;
1177 get_scale(dev, dev->width, dev->height, &dev->hscale, &dev->vscale);
1179 em28xx_resolution_set(dev);
1180 v4l2_device_call_all(&dev->v4l2_dev, 0, core, s_std, dev->norm);
1182 mutex_unlock(&dev->lock);
1186 static int vidioc_g_parm(struct file *file, void *priv,
1187 struct v4l2_streamparm *p)
1189 struct em28xx_fh *fh = priv;
1190 struct em28xx *dev = fh->dev;
1193 if (p->type != V4L2_BUF_TYPE_VIDEO_CAPTURE)
1196 if (dev->board.is_webcam)
1197 rc = v4l2_device_call_until_err(&dev->v4l2_dev, 0,
1200 v4l2_video_std_frame_period(dev->norm,
1201 &p->parm.capture.timeperframe);
1206 static int vidioc_s_parm(struct file *file, void *priv,
1207 struct v4l2_streamparm *p)
1209 struct em28xx_fh *fh = priv;
1210 struct em28xx *dev = fh->dev;
1212 if (!dev->board.is_webcam)
1215 if (p->type != V4L2_BUF_TYPE_VIDEO_CAPTURE)
1218 return v4l2_device_call_until_err(&dev->v4l2_dev, 0, video, s_parm, p);
1221 static const char *iname[] = {
1222 [EM28XX_VMUX_COMPOSITE1] = "Composite1",
1223 [EM28XX_VMUX_COMPOSITE2] = "Composite2",
1224 [EM28XX_VMUX_COMPOSITE3] = "Composite3",
1225 [EM28XX_VMUX_COMPOSITE4] = "Composite4",
1226 [EM28XX_VMUX_SVIDEO] = "S-Video",
1227 [EM28XX_VMUX_TELEVISION] = "Television",
1228 [EM28XX_VMUX_CABLE] = "Cable TV",
1229 [EM28XX_VMUX_DVB] = "DVB",
1230 [EM28XX_VMUX_DEBUG] = "for debug only",
1233 static int vidioc_enum_input(struct file *file, void *priv,
1234 struct v4l2_input *i)
1236 struct em28xx_fh *fh = priv;
1237 struct em28xx *dev = fh->dev;
1241 if (n >= MAX_EM28XX_INPUT)
1243 if (0 == INPUT(n)->type)
1247 i->type = V4L2_INPUT_TYPE_CAMERA;
1249 strcpy(i->name, iname[INPUT(n)->type]);
1251 if ((EM28XX_VMUX_TELEVISION == INPUT(n)->type) ||
1252 (EM28XX_VMUX_CABLE == INPUT(n)->type))
1253 i->type = V4L2_INPUT_TYPE_TUNER;
1255 i->std = dev->vdev->tvnorms;
1260 static int vidioc_g_input(struct file *file, void *priv, unsigned int *i)
1262 struct em28xx_fh *fh = priv;
1263 struct em28xx *dev = fh->dev;
1265 *i = dev->ctl_input;
1270 static int vidioc_s_input(struct file *file, void *priv, unsigned int i)
1272 struct em28xx_fh *fh = priv;
1273 struct em28xx *dev = fh->dev;
1276 rc = check_dev(dev);
1280 if (i >= MAX_EM28XX_INPUT)
1282 if (0 == INPUT(i)->type)
1287 mutex_lock(&dev->lock);
1288 video_mux(dev, dev->ctl_input);
1289 mutex_unlock(&dev->lock);
1293 static int vidioc_g_audio(struct file *file, void *priv, struct v4l2_audio *a)
1295 struct em28xx_fh *fh = priv;
1296 struct em28xx *dev = fh->dev;
1298 if (!dev->audio_mode.has_audio)
1302 case EM28XX_AMUX_VIDEO:
1303 strcpy(a->name, "Television");
1305 case EM28XX_AMUX_LINE_IN:
1306 strcpy(a->name, "Line In");
1308 case EM28XX_AMUX_VIDEO2:
1309 strcpy(a->name, "Television alt");
1311 case EM28XX_AMUX_PHONE:
1312 strcpy(a->name, "Phone");
1314 case EM28XX_AMUX_MIC:
1315 strcpy(a->name, "Mic");
1317 case EM28XX_AMUX_CD:
1318 strcpy(a->name, "CD");
1320 case EM28XX_AMUX_AUX:
1321 strcpy(a->name, "Aux");
1323 case EM28XX_AMUX_PCM_OUT:
1324 strcpy(a->name, "PCM");
1330 a->index = dev->ctl_ainput;
1331 a->capability = V4L2_AUDCAP_STEREO;
1336 static int vidioc_s_audio(struct file *file, void *priv, struct v4l2_audio *a)
1338 struct em28xx_fh *fh = priv;
1339 struct em28xx *dev = fh->dev;
1342 if (!dev->audio_mode.has_audio)
1345 if (a->index >= MAX_EM28XX_INPUT)
1347 if (0 == INPUT(a->index)->type)
1350 mutex_lock(&dev->lock);
1352 dev->ctl_ainput = INPUT(a->index)->amux;
1353 dev->ctl_aoutput = INPUT(a->index)->aout;
1355 if (!dev->ctl_aoutput)
1356 dev->ctl_aoutput = EM28XX_AOUT_MASTER;
1358 mutex_unlock(&dev->lock);
1362 static int vidioc_queryctrl(struct file *file, void *priv,
1363 struct v4l2_queryctrl *qc)
1365 struct em28xx_fh *fh = priv;
1366 struct em28xx *dev = fh->dev;
1370 rc = check_dev(dev);
1374 memset(qc, 0, sizeof(*qc));
1378 /* enumberate AC97 controls */
1379 if (dev->audio_mode.ac97 != EM28XX_NO_AC97) {
1380 rc = ac97_queryctrl(qc);
1385 /* enumberate V4L2 device controls */
1386 mutex_lock(&dev->lock);
1387 v4l2_device_call_all(&dev->v4l2_dev, 0, core, queryctrl, qc);
1388 mutex_unlock(&dev->lock);
1396 static int vidioc_g_ctrl(struct file *file, void *priv,
1397 struct v4l2_control *ctrl)
1399 struct em28xx_fh *fh = priv;
1400 struct em28xx *dev = fh->dev;
1403 rc = check_dev(dev);
1408 mutex_lock(&dev->lock);
1410 /* Set an AC97 control */
1411 if (dev->audio_mode.ac97 != EM28XX_NO_AC97)
1412 rc = ac97_get_ctrl(dev, ctrl);
1416 /* It were not an AC97 control. Sends it to the v4l2 dev interface */
1418 v4l2_device_call_all(&dev->v4l2_dev, 0, core, g_ctrl, ctrl);
1422 mutex_unlock(&dev->lock);
1426 static int vidioc_s_ctrl(struct file *file, void *priv,
1427 struct v4l2_control *ctrl)
1429 struct em28xx_fh *fh = priv;
1430 struct em28xx *dev = fh->dev;
1433 rc = check_dev(dev);
1437 mutex_lock(&dev->lock);
1439 /* Set an AC97 control */
1440 if (dev->audio_mode.ac97 != EM28XX_NO_AC97)
1441 rc = ac97_set_ctrl(dev, ctrl);
1445 /* It isn't an AC97 control. Sends it to the v4l2 dev interface */
1447 v4l2_device_call_all(&dev->v4l2_dev, 0, core, s_ctrl, ctrl);
1450 * In the case of non-AC97 volume controls, we still need
1451 * to do some setups at em28xx, in order to mute/unmute
1452 * and to adjust audio volume. However, the value ranges
1453 * should be checked by the corresponding V4L subdriver.
1456 case V4L2_CID_AUDIO_MUTE:
1457 dev->mute = ctrl->value;
1458 rc = em28xx_audio_analog_set(dev);
1460 case V4L2_CID_AUDIO_VOLUME:
1461 dev->volume = ctrl->value;
1462 rc = em28xx_audio_analog_set(dev);
1466 mutex_unlock(&dev->lock);
1470 static int vidioc_g_tuner(struct file *file, void *priv,
1471 struct v4l2_tuner *t)
1473 struct em28xx_fh *fh = priv;
1474 struct em28xx *dev = fh->dev;
1477 rc = check_dev(dev);
1484 strcpy(t->name, "Tuner");
1486 mutex_lock(&dev->lock);
1487 v4l2_device_call_all(&dev->v4l2_dev, 0, tuner, g_tuner, t);
1488 mutex_unlock(&dev->lock);
1493 static int vidioc_s_tuner(struct file *file, void *priv,
1494 struct v4l2_tuner *t)
1496 struct em28xx_fh *fh = priv;
1497 struct em28xx *dev = fh->dev;
1500 rc = check_dev(dev);
1507 mutex_lock(&dev->lock);
1508 v4l2_device_call_all(&dev->v4l2_dev, 0, tuner, s_tuner, t);
1509 mutex_unlock(&dev->lock);
1514 static int vidioc_g_frequency(struct file *file, void *priv,
1515 struct v4l2_frequency *f)
1517 struct em28xx_fh *fh = priv;
1518 struct em28xx *dev = fh->dev;
1520 mutex_lock(&dev->lock);
1521 f->type = fh->radio ? V4L2_TUNER_RADIO : V4L2_TUNER_ANALOG_TV;
1522 f->frequency = dev->ctl_freq;
1523 mutex_unlock(&dev->lock);
1528 static int vidioc_s_frequency(struct file *file, void *priv,
1529 struct v4l2_frequency *f)
1531 struct em28xx_fh *fh = priv;
1532 struct em28xx *dev = fh->dev;
1535 rc = check_dev(dev);
1542 if (unlikely(0 == fh->radio && f->type != V4L2_TUNER_ANALOG_TV))
1544 if (unlikely(1 == fh->radio && f->type != V4L2_TUNER_RADIO))
1547 mutex_lock(&dev->lock);
1549 dev->ctl_freq = f->frequency;
1550 v4l2_device_call_all(&dev->v4l2_dev, 0, tuner, s_frequency, f);
1552 mutex_unlock(&dev->lock);
1557 #ifdef CONFIG_VIDEO_ADV_DEBUG
1558 static int em28xx_reg_len(int reg)
1561 case EM28XX_R40_AC97LSB:
1562 case EM28XX_R30_HSCALELOW:
1563 case EM28XX_R32_VSCALELOW:
1570 static int vidioc_g_chip_ident(struct file *file, void *priv,
1571 struct v4l2_dbg_chip_ident *chip)
1573 struct em28xx_fh *fh = priv;
1574 struct em28xx *dev = fh->dev;
1576 chip->ident = V4L2_IDENT_NONE;
1579 v4l2_device_call_all(&dev->v4l2_dev, 0, core, g_chip_ident, chip);
1585 static int vidioc_g_register(struct file *file, void *priv,
1586 struct v4l2_dbg_register *reg)
1588 struct em28xx_fh *fh = priv;
1589 struct em28xx *dev = fh->dev;
1592 switch (reg->match.type) {
1593 case V4L2_CHIP_MATCH_AC97:
1594 mutex_lock(&dev->lock);
1595 ret = em28xx_read_ac97(dev, reg->reg);
1596 mutex_unlock(&dev->lock);
1603 case V4L2_CHIP_MATCH_I2C_DRIVER:
1604 v4l2_device_call_all(&dev->v4l2_dev, 0, core, g_register, reg);
1606 case V4L2_CHIP_MATCH_I2C_ADDR:
1607 /* TODO: is this correct? */
1608 v4l2_device_call_all(&dev->v4l2_dev, 0, core, g_register, reg);
1611 if (!v4l2_chip_match_host(®->match))
1616 reg->size = em28xx_reg_len(reg->reg);
1617 if (reg->size == 1) {
1618 mutex_lock(&dev->lock);
1619 ret = em28xx_read_reg(dev, reg->reg);
1620 mutex_unlock(&dev->lock);
1628 mutex_lock(&dev->lock);
1629 ret = em28xx_read_reg_req_len(dev, USB_REQ_GET_STATUS,
1630 reg->reg, (char *)&val, 2);
1631 mutex_unlock(&dev->lock);
1635 reg->val = le16_to_cpu(val);
1641 static int vidioc_s_register(struct file *file, void *priv,
1642 struct v4l2_dbg_register *reg)
1644 struct em28xx_fh *fh = priv;
1645 struct em28xx *dev = fh->dev;
1649 switch (reg->match.type) {
1650 case V4L2_CHIP_MATCH_AC97:
1651 mutex_lock(&dev->lock);
1652 rc = em28xx_write_ac97(dev, reg->reg, reg->val);
1653 mutex_unlock(&dev->lock);
1656 case V4L2_CHIP_MATCH_I2C_DRIVER:
1657 v4l2_device_call_all(&dev->v4l2_dev, 0, core, s_register, reg);
1659 case V4L2_CHIP_MATCH_I2C_ADDR:
1660 /* TODO: is this correct? */
1661 v4l2_device_call_all(&dev->v4l2_dev, 0, core, s_register, reg);
1664 if (!v4l2_chip_match_host(®->match))
1669 buf = cpu_to_le16(reg->val);
1671 mutex_lock(&dev->lock);
1672 rc = em28xx_write_regs(dev, reg->reg, (char *)&buf,
1673 em28xx_reg_len(reg->reg));
1674 mutex_unlock(&dev->lock);
1681 static int vidioc_cropcap(struct file *file, void *priv,
1682 struct v4l2_cropcap *cc)
1684 struct em28xx_fh *fh = priv;
1685 struct em28xx *dev = fh->dev;
1687 if (cc->type != V4L2_BUF_TYPE_VIDEO_CAPTURE)
1690 cc->bounds.left = 0;
1692 cc->bounds.width = dev->width;
1693 cc->bounds.height = dev->height;
1694 cc->defrect = cc->bounds;
1695 cc->pixelaspect.numerator = 54; /* 4:3 FIXME: remove magic numbers */
1696 cc->pixelaspect.denominator = 59;
1701 static int vidioc_streamon(struct file *file, void *priv,
1702 enum v4l2_buf_type type)
1704 struct em28xx_fh *fh = priv;
1705 struct em28xx *dev = fh->dev;
1708 rc = check_dev(dev);
1712 if (unlikely(type != fh->type))
1715 em28xx_videodbg("vidioc_streamon fh=%p t=%d fh->res=%d dev->res=%d\n",
1716 fh, type, fh->resources, dev->resources);
1718 if (unlikely(!res_get(fh, get_ressource(fh))))
1721 if (fh->type == V4L2_BUF_TYPE_VIDEO_CAPTURE)
1722 rc = videobuf_streamon(&fh->vb_vidq);
1723 else if (fh->type == V4L2_BUF_TYPE_VBI_CAPTURE)
1724 rc = videobuf_streamon(&fh->vb_vbiq);
1729 static int vidioc_streamoff(struct file *file, void *priv,
1730 enum v4l2_buf_type type)
1732 struct em28xx_fh *fh = priv;
1733 struct em28xx *dev = fh->dev;
1736 rc = check_dev(dev);
1740 if (fh->type != V4L2_BUF_TYPE_VIDEO_CAPTURE &&
1741 fh->type != V4L2_BUF_TYPE_VBI_CAPTURE)
1743 if (type != fh->type)
1746 em28xx_videodbg("vidioc_streamoff fh=%p t=%d fh->res=%d dev->res=%d\n",
1747 fh, type, fh->resources, dev->resources);
1749 if (fh->type == V4L2_BUF_TYPE_VIDEO_CAPTURE) {
1750 videobuf_streamoff(&fh->vb_vidq);
1751 res_free(fh, EM28XX_RESOURCE_VIDEO);
1752 } else if (fh->type == V4L2_BUF_TYPE_VBI_CAPTURE) {
1753 videobuf_streamoff(&fh->vb_vbiq);
1754 res_free(fh, EM28XX_RESOURCE_VBI);
1760 static int vidioc_querycap(struct file *file, void *priv,
1761 struct v4l2_capability *cap)
1763 struct em28xx_fh *fh = priv;
1764 struct em28xx *dev = fh->dev;
1766 strlcpy(cap->driver, "em28xx", sizeof(cap->driver));
1767 strlcpy(cap->card, em28xx_boards[dev->model].name, sizeof(cap->card));
1768 usb_make_path(dev->udev, cap->bus_info, sizeof(cap->bus_info));
1770 cap->version = EM28XX_VERSION_CODE;
1773 V4L2_CAP_SLICED_VBI_CAPTURE |
1774 V4L2_CAP_VIDEO_CAPTURE |
1775 V4L2_CAP_READWRITE | V4L2_CAP_STREAMING;
1778 cap->capabilities |= V4L2_CAP_VBI_CAPTURE;
1780 if (dev->audio_mode.has_audio)
1781 cap->capabilities |= V4L2_CAP_AUDIO;
1783 if (dev->tuner_type != TUNER_ABSENT)
1784 cap->capabilities |= V4L2_CAP_TUNER;
1789 static int vidioc_enum_fmt_vid_cap(struct file *file, void *priv,
1790 struct v4l2_fmtdesc *f)
1792 if (unlikely(f->index >= ARRAY_SIZE(format)))
1795 strlcpy(f->description, format[f->index].name, sizeof(f->description));
1796 f->pixelformat = format[f->index].fourcc;
1801 /* Sliced VBI ioctls */
1802 static int vidioc_g_fmt_sliced_vbi_cap(struct file *file, void *priv,
1803 struct v4l2_format *f)
1805 struct em28xx_fh *fh = priv;
1806 struct em28xx *dev = fh->dev;
1809 rc = check_dev(dev);
1813 mutex_lock(&dev->lock);
1815 f->fmt.sliced.service_set = 0;
1816 v4l2_device_call_all(&dev->v4l2_dev, 0, video, g_fmt, f);
1818 if (f->fmt.sliced.service_set == 0)
1821 mutex_unlock(&dev->lock);
1826 static int vidioc_try_set_sliced_vbi_cap(struct file *file, void *priv,
1827 struct v4l2_format *f)
1829 struct em28xx_fh *fh = priv;
1830 struct em28xx *dev = fh->dev;
1833 rc = check_dev(dev);
1837 mutex_lock(&dev->lock);
1838 v4l2_device_call_all(&dev->v4l2_dev, 0, video, g_fmt, f);
1839 mutex_unlock(&dev->lock);
1841 if (f->fmt.sliced.service_set == 0)
1847 /* RAW VBI ioctls */
1849 static int vidioc_g_fmt_vbi_cap(struct file *file, void *priv,
1850 struct v4l2_format *format)
1852 struct em28xx_fh *fh = priv;
1853 struct em28xx *dev = fh->dev;
1855 format->fmt.vbi.samples_per_line = dev->vbi_width;
1856 format->fmt.vbi.sample_format = V4L2_PIX_FMT_GREY;
1857 format->fmt.vbi.offset = 0;
1858 format->fmt.vbi.flags = 0;
1859 format->fmt.vbi.sampling_rate = 6750000 * 4 / 2;
1860 format->fmt.vbi.count[0] = dev->vbi_height;
1861 format->fmt.vbi.count[1] = dev->vbi_height;
1863 /* Varies by video standard (NTSC, PAL, etc.) */
1864 if (dev->norm & V4L2_STD_525_60) {
1866 format->fmt.vbi.start[0] = 10;
1867 format->fmt.vbi.start[1] = 273;
1868 } else if (dev->norm & V4L2_STD_625_50) {
1870 format->fmt.vbi.start[0] = 6;
1871 format->fmt.vbi.start[1] = 318;
1877 static int vidioc_s_fmt_vbi_cap(struct file *file, void *priv,
1878 struct v4l2_format *format)
1880 struct em28xx_fh *fh = priv;
1881 struct em28xx *dev = fh->dev;
1883 format->fmt.vbi.samples_per_line = dev->vbi_width;
1884 format->fmt.vbi.sample_format = V4L2_PIX_FMT_GREY;
1885 format->fmt.vbi.offset = 0;
1886 format->fmt.vbi.flags = 0;
1887 format->fmt.vbi.sampling_rate = 6750000 * 4 / 2;
1888 format->fmt.vbi.count[0] = dev->vbi_height;
1889 format->fmt.vbi.count[1] = dev->vbi_height;
1891 /* Varies by video standard (NTSC, PAL, etc.) */
1892 if (dev->norm & V4L2_STD_525_60) {
1894 format->fmt.vbi.start[0] = 10;
1895 format->fmt.vbi.start[1] = 273;
1896 } else if (dev->norm & V4L2_STD_625_50) {
1898 format->fmt.vbi.start[0] = 6;
1899 format->fmt.vbi.start[1] = 318;
1905 static int vidioc_reqbufs(struct file *file, void *priv,
1906 struct v4l2_requestbuffers *rb)
1908 struct em28xx_fh *fh = priv;
1909 struct em28xx *dev = fh->dev;
1912 rc = check_dev(dev);
1916 if (fh->type == V4L2_BUF_TYPE_VIDEO_CAPTURE)
1917 return videobuf_reqbufs(&fh->vb_vidq, rb);
1919 return videobuf_reqbufs(&fh->vb_vbiq, rb);
1922 static int vidioc_querybuf(struct file *file, void *priv,
1923 struct v4l2_buffer *b)
1925 struct em28xx_fh *fh = priv;
1926 struct em28xx *dev = fh->dev;
1929 rc = check_dev(dev);
1933 if (fh->type == V4L2_BUF_TYPE_VIDEO_CAPTURE)
1934 return videobuf_querybuf(&fh->vb_vidq, b);
1936 /* FIXME: I'm not sure yet whether this is a bug in zvbi or
1937 the videobuf framework, but we probably shouldn't be
1938 returning a buffer larger than that which was asked for.
1939 At a minimum, it causes a crash in zvbi since it does
1940 a memcpy based on the source buffer length */
1941 int result = videobuf_querybuf(&fh->vb_vbiq, b);
1942 b->length = dev->vbi_width * dev->vbi_height * 2;
1948 static int vidioc_qbuf(struct file *file, void *priv, struct v4l2_buffer *b)
1950 struct em28xx_fh *fh = priv;
1951 struct em28xx *dev = fh->dev;
1954 rc = check_dev(dev);
1958 if (fh->type == V4L2_BUF_TYPE_VIDEO_CAPTURE)
1959 return videobuf_qbuf(&fh->vb_vidq, b);
1961 return videobuf_qbuf(&fh->vb_vbiq, b);
1964 static int vidioc_dqbuf(struct file *file, void *priv, struct v4l2_buffer *b)
1966 struct em28xx_fh *fh = priv;
1967 struct em28xx *dev = fh->dev;
1970 rc = check_dev(dev);
1974 if (fh->type == V4L2_BUF_TYPE_VIDEO_CAPTURE)
1975 return videobuf_dqbuf(&fh->vb_vidq, b, file->f_flags &
1978 return videobuf_dqbuf(&fh->vb_vbiq, b, file->f_flags &
1982 #ifdef CONFIG_VIDEO_V4L1_COMPAT
1983 static int vidiocgmbuf(struct file *file, void *priv, struct video_mbuf *mbuf)
1985 struct em28xx_fh *fh = priv;
1987 if (fh->type == V4L2_BUF_TYPE_VIDEO_CAPTURE)
1988 return videobuf_cgmbuf(&fh->vb_vidq, mbuf, 8);
1990 return videobuf_cgmbuf(&fh->vb_vbiq, mbuf, 8);
1995 /* ----------------------------------------------------------- */
1996 /* RADIO ESPECIFIC IOCTLS */
1997 /* ----------------------------------------------------------- */
1999 static int radio_querycap(struct file *file, void *priv,
2000 struct v4l2_capability *cap)
2002 struct em28xx *dev = ((struct em28xx_fh *)priv)->dev;
2004 strlcpy(cap->driver, "em28xx", sizeof(cap->driver));
2005 strlcpy(cap->card, em28xx_boards[dev->model].name, sizeof(cap->card));
2006 usb_make_path(dev->udev, cap->bus_info, sizeof(cap->bus_info));
2008 cap->version = EM28XX_VERSION_CODE;
2009 cap->capabilities = V4L2_CAP_TUNER;
2013 static int radio_g_tuner(struct file *file, void *priv,
2014 struct v4l2_tuner *t)
2016 struct em28xx *dev = ((struct em28xx_fh *)priv)->dev;
2018 if (unlikely(t->index > 0))
2021 strcpy(t->name, "Radio");
2022 t->type = V4L2_TUNER_RADIO;
2024 mutex_lock(&dev->lock);
2025 v4l2_device_call_all(&dev->v4l2_dev, 0, tuner, g_tuner, t);
2026 mutex_unlock(&dev->lock);
2031 static int radio_enum_input(struct file *file, void *priv,
2032 struct v4l2_input *i)
2036 strcpy(i->name, "Radio");
2037 i->type = V4L2_INPUT_TYPE_TUNER;
2042 static int radio_g_audio(struct file *file, void *priv, struct v4l2_audio *a)
2044 if (unlikely(a->index))
2047 strcpy(a->name, "Radio");
2051 static int radio_s_tuner(struct file *file, void *priv,
2052 struct v4l2_tuner *t)
2054 struct em28xx *dev = ((struct em28xx_fh *)priv)->dev;
2059 mutex_lock(&dev->lock);
2060 v4l2_device_call_all(&dev->v4l2_dev, 0, tuner, s_tuner, t);
2061 mutex_unlock(&dev->lock);
2066 static int radio_s_audio(struct file *file, void *fh,
2067 struct v4l2_audio *a)
2072 static int radio_s_input(struct file *file, void *fh, unsigned int i)
2077 static int radio_queryctrl(struct file *file, void *priv,
2078 struct v4l2_queryctrl *qc)
2082 if (qc->id < V4L2_CID_BASE ||
2083 qc->id >= V4L2_CID_LASTP1)
2086 for (i = 0; i < ARRAY_SIZE(ac97_qctrl); i++) {
2087 if (qc->id && qc->id == ac97_qctrl[i].id) {
2088 memcpy(qc, &(ac97_qctrl[i]), sizeof(*qc));
2097 * em28xx_v4l2_open()
2098 * inits the device and starts isoc transfer
2100 static int em28xx_v4l2_open(struct file *filp)
2102 int errCode = 0, radio = 0;
2103 struct video_device *vdev = video_devdata(filp);
2104 struct em28xx *dev = video_drvdata(filp);
2105 enum v4l2_buf_type fh_type = 0;
2106 struct em28xx_fh *fh;
2107 enum v4l2_field field;
2109 switch (vdev->vfl_type) {
2110 case VFL_TYPE_GRABBER:
2111 fh_type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
2114 fh_type = V4L2_BUF_TYPE_VBI_CAPTURE;
2116 case VFL_TYPE_RADIO:
2121 mutex_lock(&dev->lock);
2123 em28xx_videodbg("open dev=%s type=%s users=%d\n",
2124 video_device_node_name(vdev), v4l2_type_names[fh_type],
2128 fh = kzalloc(sizeof(struct em28xx_fh), GFP_KERNEL);
2130 em28xx_errdev("em28xx-video.c: Out of memory?!\n");
2131 mutex_unlock(&dev->lock);
2137 filp->private_data = fh;
2139 if (fh->type == V4L2_BUF_TYPE_VIDEO_CAPTURE && dev->users == 0) {
2140 em28xx_set_mode(dev, EM28XX_ANALOG_MODE);
2141 em28xx_set_alternate(dev);
2142 em28xx_resolution_set(dev);
2144 /* Needed, since GPIO might have disabled power of
2147 em28xx_wake_i2c(dev);
2151 em28xx_videodbg("video_open: setting radio device\n");
2152 v4l2_device_call_all(&dev->v4l2_dev, 0, tuner, s_radio);
2157 if (dev->progressive)
2158 field = V4L2_FIELD_NONE;
2160 field = V4L2_FIELD_INTERLACED;
2162 videobuf_queue_vmalloc_init(&fh->vb_vidq, &em28xx_video_qops,
2164 V4L2_BUF_TYPE_VIDEO_CAPTURE, field,
2165 sizeof(struct em28xx_buffer), fh);
2167 videobuf_queue_vmalloc_init(&fh->vb_vbiq, &em28xx_vbi_qops,
2169 V4L2_BUF_TYPE_VBI_CAPTURE,
2171 sizeof(struct em28xx_buffer), fh);
2173 mutex_unlock(&dev->lock);
2179 * em28xx_realease_resources()
2180 * unregisters the v4l2,i2c and usb devices
2181 * called when the device gets disconected or at module unload
2183 void em28xx_release_analog_resources(struct em28xx *dev)
2186 /*FIXME: I2C IR should be disconnected */
2188 if (dev->radio_dev) {
2189 if (video_is_registered(dev->radio_dev))
2190 video_unregister_device(dev->radio_dev);
2192 video_device_release(dev->radio_dev);
2193 dev->radio_dev = NULL;
2196 em28xx_info("V4L2 device %s deregistered\n",
2197 video_device_node_name(dev->vbi_dev));
2198 if (video_is_registered(dev->vbi_dev))
2199 video_unregister_device(dev->vbi_dev);
2201 video_device_release(dev->vbi_dev);
2202 dev->vbi_dev = NULL;
2205 em28xx_info("V4L2 device %s deregistered\n",
2206 video_device_node_name(dev->vdev));
2207 if (video_is_registered(dev->vdev))
2208 video_unregister_device(dev->vdev);
2210 video_device_release(dev->vdev);
2216 * em28xx_v4l2_close()
2217 * stops streaming and deallocates all resources allocated by the v4l2
2220 static int em28xx_v4l2_close(struct file *filp)
2222 struct em28xx_fh *fh = filp->private_data;
2223 struct em28xx *dev = fh->dev;
2226 em28xx_videodbg("users=%d\n", dev->users);
2228 if (res_check(fh, EM28XX_RESOURCE_VIDEO)) {
2229 videobuf_stop(&fh->vb_vidq);
2230 res_free(fh, EM28XX_RESOURCE_VIDEO);
2233 if (res_check(fh, EM28XX_RESOURCE_VBI)) {
2234 videobuf_stop(&fh->vb_vbiq);
2235 res_free(fh, EM28XX_RESOURCE_VBI);
2238 if (dev->users == 1) {
2239 /* the device is already disconnect,
2240 free the remaining resources */
2241 if (dev->state & DEV_DISCONNECTED) {
2242 em28xx_release_resources(dev);
2247 /* Save some power by putting tuner to sleep */
2248 v4l2_device_call_all(&dev->v4l2_dev, 0, core, s_power, 0);
2250 /* do this before setting alternate! */
2251 em28xx_uninit_isoc(dev);
2252 em28xx_set_mode(dev, EM28XX_SUSPEND);
2254 /* set alternate 0 */
2256 em28xx_videodbg("setting alternate 0\n");
2257 errCode = usb_set_interface(dev->udev, 0, 0);
2259 em28xx_errdev("cannot change alternate number to "
2260 "0 (error=%i)\n", errCode);
2264 videobuf_mmap_free(&fh->vb_vidq);
2265 videobuf_mmap_free(&fh->vb_vbiq);
2268 wake_up_interruptible_nr(&dev->open, 1);
2273 * em28xx_v4l2_read()
2274 * will allocate buffers when called for the first time
2277 em28xx_v4l2_read(struct file *filp, char __user *buf, size_t count,
2280 struct em28xx_fh *fh = filp->private_data;
2281 struct em28xx *dev = fh->dev;
2284 rc = check_dev(dev);
2288 /* FIXME: read() is not prepared to allow changing the video
2289 resolution while streaming. Seems a bug at em28xx_set_fmt
2292 if (fh->type == V4L2_BUF_TYPE_VIDEO_CAPTURE) {
2293 if (res_locked(dev, EM28XX_RESOURCE_VIDEO))
2296 return videobuf_read_stream(&fh->vb_vidq, buf, count, pos, 0,
2297 filp->f_flags & O_NONBLOCK);
2301 if (fh->type == V4L2_BUF_TYPE_VBI_CAPTURE) {
2302 if (!res_get(fh, EM28XX_RESOURCE_VBI))
2305 return videobuf_read_stream(&fh->vb_vbiq, buf, count, pos, 0,
2306 filp->f_flags & O_NONBLOCK);
2313 * em28xx_v4l2_poll()
2314 * will allocate buffers when called for the first time
2316 static unsigned int em28xx_v4l2_poll(struct file *filp, poll_table *wait)
2318 struct em28xx_fh *fh = filp->private_data;
2319 struct em28xx *dev = fh->dev;
2322 rc = check_dev(dev);
2326 if (fh->type == V4L2_BUF_TYPE_VIDEO_CAPTURE) {
2327 if (!res_get(fh, EM28XX_RESOURCE_VIDEO))
2329 return videobuf_poll_stream(filp, &fh->vb_vidq, wait);
2330 } else if (fh->type == V4L2_BUF_TYPE_VBI_CAPTURE) {
2331 if (!res_get(fh, EM28XX_RESOURCE_VBI))
2333 return videobuf_poll_stream(filp, &fh->vb_vbiq, wait);
2340 * em28xx_v4l2_mmap()
2342 static int em28xx_v4l2_mmap(struct file *filp, struct vm_area_struct *vma)
2344 struct em28xx_fh *fh = filp->private_data;
2345 struct em28xx *dev = fh->dev;
2348 rc = check_dev(dev);
2352 if (fh->type == V4L2_BUF_TYPE_VIDEO_CAPTURE)
2353 rc = videobuf_mmap_mapper(&fh->vb_vidq, vma);
2354 else if (fh->type == V4L2_BUF_TYPE_VBI_CAPTURE)
2355 rc = videobuf_mmap_mapper(&fh->vb_vbiq, vma);
2357 em28xx_videodbg("vma start=0x%08lx, size=%ld, ret=%d\n",
2358 (unsigned long)vma->vm_start,
2359 (unsigned long)vma->vm_end-(unsigned long)vma->vm_start,
2365 static const struct v4l2_file_operations em28xx_v4l_fops = {
2366 .owner = THIS_MODULE,
2367 .open = em28xx_v4l2_open,
2368 .release = em28xx_v4l2_close,
2369 .read = em28xx_v4l2_read,
2370 .poll = em28xx_v4l2_poll,
2371 .mmap = em28xx_v4l2_mmap,
2372 .ioctl = video_ioctl2,
2375 static const struct v4l2_ioctl_ops video_ioctl_ops = {
2376 .vidioc_querycap = vidioc_querycap,
2377 .vidioc_enum_fmt_vid_cap = vidioc_enum_fmt_vid_cap,
2378 .vidioc_g_fmt_vid_cap = vidioc_g_fmt_vid_cap,
2379 .vidioc_try_fmt_vid_cap = vidioc_try_fmt_vid_cap,
2380 .vidioc_s_fmt_vid_cap = vidioc_s_fmt_vid_cap,
2381 .vidioc_g_fmt_vbi_cap = vidioc_g_fmt_vbi_cap,
2382 .vidioc_s_fmt_vbi_cap = vidioc_s_fmt_vbi_cap,
2383 .vidioc_g_audio = vidioc_g_audio,
2384 .vidioc_s_audio = vidioc_s_audio,
2385 .vidioc_cropcap = vidioc_cropcap,
2387 .vidioc_g_fmt_sliced_vbi_cap = vidioc_g_fmt_sliced_vbi_cap,
2388 .vidioc_try_fmt_sliced_vbi_cap = vidioc_try_set_sliced_vbi_cap,
2389 .vidioc_s_fmt_sliced_vbi_cap = vidioc_try_set_sliced_vbi_cap,
2391 .vidioc_reqbufs = vidioc_reqbufs,
2392 .vidioc_querybuf = vidioc_querybuf,
2393 .vidioc_qbuf = vidioc_qbuf,
2394 .vidioc_dqbuf = vidioc_dqbuf,
2395 .vidioc_g_std = vidioc_g_std,
2396 .vidioc_s_std = vidioc_s_std,
2397 .vidioc_g_parm = vidioc_g_parm,
2398 .vidioc_s_parm = vidioc_s_parm,
2399 .vidioc_enum_input = vidioc_enum_input,
2400 .vidioc_g_input = vidioc_g_input,
2401 .vidioc_s_input = vidioc_s_input,
2402 .vidioc_queryctrl = vidioc_queryctrl,
2403 .vidioc_g_ctrl = vidioc_g_ctrl,
2404 .vidioc_s_ctrl = vidioc_s_ctrl,
2405 .vidioc_streamon = vidioc_streamon,
2406 .vidioc_streamoff = vidioc_streamoff,
2407 .vidioc_g_tuner = vidioc_g_tuner,
2408 .vidioc_s_tuner = vidioc_s_tuner,
2409 .vidioc_g_frequency = vidioc_g_frequency,
2410 .vidioc_s_frequency = vidioc_s_frequency,
2411 #ifdef CONFIG_VIDEO_ADV_DEBUG
2412 .vidioc_g_register = vidioc_g_register,
2413 .vidioc_s_register = vidioc_s_register,
2414 .vidioc_g_chip_ident = vidioc_g_chip_ident,
2416 #ifdef CONFIG_VIDEO_V4L1_COMPAT
2417 .vidiocgmbuf = vidiocgmbuf,
2421 static const struct video_device em28xx_video_template = {
2422 .fops = &em28xx_v4l_fops,
2423 .release = video_device_release,
2424 .ioctl_ops = &video_ioctl_ops,
2426 .tvnorms = V4L2_STD_ALL,
2427 .current_norm = V4L2_STD_PAL,
2430 static const struct v4l2_file_operations radio_fops = {
2431 .owner = THIS_MODULE,
2432 .open = em28xx_v4l2_open,
2433 .release = em28xx_v4l2_close,
2434 .ioctl = video_ioctl2,
2437 static const struct v4l2_ioctl_ops radio_ioctl_ops = {
2438 .vidioc_querycap = radio_querycap,
2439 .vidioc_g_tuner = radio_g_tuner,
2440 .vidioc_enum_input = radio_enum_input,
2441 .vidioc_g_audio = radio_g_audio,
2442 .vidioc_s_tuner = radio_s_tuner,
2443 .vidioc_s_audio = radio_s_audio,
2444 .vidioc_s_input = radio_s_input,
2445 .vidioc_queryctrl = radio_queryctrl,
2446 .vidioc_g_ctrl = vidioc_g_ctrl,
2447 .vidioc_s_ctrl = vidioc_s_ctrl,
2448 .vidioc_g_frequency = vidioc_g_frequency,
2449 .vidioc_s_frequency = vidioc_s_frequency,
2450 #ifdef CONFIG_VIDEO_ADV_DEBUG
2451 .vidioc_g_register = vidioc_g_register,
2452 .vidioc_s_register = vidioc_s_register,
2456 static struct video_device em28xx_radio_template = {
2457 .name = "em28xx-radio",
2458 .fops = &radio_fops,
2459 .ioctl_ops = &radio_ioctl_ops,
2462 /******************************** usb interface ******************************/
2466 static struct video_device *em28xx_vdev_init(struct em28xx *dev,
2467 const struct video_device *template,
2468 const char *type_name)
2470 struct video_device *vfd;
2472 vfd = video_device_alloc();
2477 vfd->v4l2_dev = &dev->v4l2_dev;
2478 vfd->release = video_device_release;
2479 vfd->debug = video_debug;
2481 snprintf(vfd->name, sizeof(vfd->name), "%s %s",
2482 dev->name, type_name);
2484 video_set_drvdata(vfd, dev);
2488 int em28xx_register_analog_devices(struct em28xx *dev)
2493 printk(KERN_INFO "%s: v4l2 driver version %d.%d.%d\n",
2495 (EM28XX_VERSION_CODE >> 16) & 0xff,
2496 (EM28XX_VERSION_CODE >> 8) & 0xff, EM28XX_VERSION_CODE & 0xff);
2498 /* set default norm */
2499 dev->norm = em28xx_video_template.current_norm;
2500 dev->interlaced = EM28XX_INTERLACED_DEFAULT;
2503 /* Analog specific initialization */
2504 dev->format = &format[0];
2505 em28xx_set_video_format(dev, format[0].fourcc,
2506 norm_maxw(dev), norm_maxh(dev));
2508 video_mux(dev, dev->ctl_input);
2510 /* Audio defaults */
2514 /* em28xx_write_reg(dev, EM28XX_R0E_AUDIOSRC, 0xc0); audio register */
2515 val = (u8)em28xx_read_reg(dev, EM28XX_R0F_XCLK);
2516 em28xx_write_reg(dev, EM28XX_R0F_XCLK,
2517 (EM28XX_XCLK_AUDIO_UNMUTE | val));
2519 em28xx_set_outfmt(dev);
2520 em28xx_colorlevels_set_default(dev);
2521 em28xx_compression_disable(dev);
2523 /* allocate and fill video video_device struct */
2524 dev->vdev = em28xx_vdev_init(dev, &em28xx_video_template, "video");
2526 em28xx_errdev("cannot allocate video_device.\n");
2530 /* register v4l2 video video_device */
2531 ret = video_register_device(dev->vdev, VFL_TYPE_GRABBER,
2532 video_nr[dev->devno]);
2534 em28xx_errdev("unable to register video device (error=%i).\n",
2539 /* Allocate and fill vbi video_device struct */
2540 if (em28xx_vbi_supported(dev) == 1) {
2541 dev->vbi_dev = em28xx_vdev_init(dev, &em28xx_video_template,
2544 /* register v4l2 vbi video_device */
2545 ret = video_register_device(dev->vbi_dev, VFL_TYPE_VBI,
2546 vbi_nr[dev->devno]);
2548 em28xx_errdev("unable to register vbi device\n");
2553 if (em28xx_boards[dev->model].radio.type == EM28XX_RADIO) {
2554 dev->radio_dev = em28xx_vdev_init(dev, &em28xx_radio_template,
2556 if (!dev->radio_dev) {
2557 em28xx_errdev("cannot allocate video_device.\n");
2560 ret = video_register_device(dev->radio_dev, VFL_TYPE_RADIO,
2561 radio_nr[dev->devno]);
2563 em28xx_errdev("can't register radio device\n");
2566 em28xx_info("Registered radio device as %s\n",
2567 video_device_node_name(dev->radio_dev));
2570 em28xx_info("V4L2 video device registered as %s\n",
2571 video_device_node_name(dev->vdev));
2574 em28xx_info("V4L2 VBI device registered as %s\n",
2575 video_device_node_name(dev->vbi_dev));