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>
36 #include <linux/mutex.h>
37 #include <linux/slab.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"
53 #define EM28XX_VERSION "0.1.3"
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");
75 MODULE_VERSION(EM28XX_VERSION);
77 static unsigned int video_nr[] = {[0 ... (EM28XX_MAXBOARDS - 1)] = UNSET };
78 static unsigned int vbi_nr[] = {[0 ... (EM28XX_MAXBOARDS - 1)] = UNSET };
79 static unsigned int radio_nr[] = {[0 ... (EM28XX_MAXBOARDS - 1)] = UNSET };
81 module_param_array(video_nr, int, NULL, 0444);
82 module_param_array(vbi_nr, int, NULL, 0444);
83 module_param_array(radio_nr, int, NULL, 0444);
84 MODULE_PARM_DESC(video_nr, "video device numbers");
85 MODULE_PARM_DESC(vbi_nr, "vbi device numbers");
86 MODULE_PARM_DESC(radio_nr, "radio device numbers");
88 static unsigned int video_debug;
89 module_param(video_debug, int, 0644);
90 MODULE_PARM_DESC(video_debug, "enable debug messages [video]");
92 /* supported video standards */
93 static struct em28xx_fmt format[] = {
95 .name = "16 bpp YUY2, 4:2:2, packed",
96 .fourcc = V4L2_PIX_FMT_YUYV,
98 .reg = EM28XX_OUTFMT_YUV422_Y0UY1V,
100 .name = "16 bpp RGB 565, LE",
101 .fourcc = V4L2_PIX_FMT_RGB565,
103 .reg = EM28XX_OUTFMT_RGB_16_656,
105 .name = "8 bpp Bayer BGBG..GRGR",
106 .fourcc = V4L2_PIX_FMT_SBGGR8,
108 .reg = EM28XX_OUTFMT_RGB_8_BGBG,
110 .name = "8 bpp Bayer GRGR..BGBG",
111 .fourcc = V4L2_PIX_FMT_SGRBG8,
113 .reg = EM28XX_OUTFMT_RGB_8_GRGR,
115 .name = "8 bpp Bayer GBGB..RGRG",
116 .fourcc = V4L2_PIX_FMT_SGBRG8,
118 .reg = EM28XX_OUTFMT_RGB_8_GBGB,
120 .name = "12 bpp YUV411",
121 .fourcc = V4L2_PIX_FMT_YUV411P,
123 .reg = EM28XX_OUTFMT_YUV411,
127 /* supported controls */
128 /* Common to all boards */
129 static struct v4l2_queryctrl ac97_qctrl[] = {
131 .id = V4L2_CID_AUDIO_VOLUME,
132 .type = V4L2_CTRL_TYPE_INTEGER,
137 .default_value = 0x1f,
138 .flags = V4L2_CTRL_FLAG_SLIDER,
140 .id = V4L2_CID_AUDIO_MUTE,
141 .type = V4L2_CTRL_TYPE_BOOLEAN,
151 /* ------------------------------------------------------------------
152 DMA and thread functions
153 ------------------------------------------------------------------*/
156 * Announces that a buffer were filled and request the next
158 static inline void buffer_filled(struct em28xx *dev,
159 struct em28xx_dmaqueue *dma_q,
160 struct em28xx_buffer *buf)
162 /* Advice that buffer was filled */
163 em28xx_isocdbg("[%p/%d] wakeup\n", buf, buf->vb.i);
164 buf->vb.state = VIDEOBUF_DONE;
165 buf->vb.field_count++;
166 do_gettimeofday(&buf->vb.ts);
168 dev->isoc_ctl.vid_buf = NULL;
170 list_del(&buf->vb.queue);
171 wake_up(&buf->vb.done);
174 static inline void vbi_buffer_filled(struct em28xx *dev,
175 struct em28xx_dmaqueue *dma_q,
176 struct em28xx_buffer *buf)
178 /* Advice that buffer was filled */
179 em28xx_isocdbg("[%p/%d] wakeup\n", buf, buf->vb.i);
181 buf->vb.state = VIDEOBUF_DONE;
182 buf->vb.field_count++;
183 do_gettimeofday(&buf->vb.ts);
185 dev->isoc_ctl.vbi_buf = NULL;
187 list_del(&buf->vb.queue);
188 wake_up(&buf->vb.done);
192 * Identify the buffer header type and properly handles
194 static void em28xx_copy_video(struct em28xx *dev,
195 struct em28xx_dmaqueue *dma_q,
196 struct em28xx_buffer *buf,
198 unsigned char *outp, unsigned long len)
200 void *fieldstart, *startwrite, *startread;
201 int linesdone, currlinedone, offset, lencopy, remain;
202 int bytesperline = dev->width << 1;
204 if (dma_q->pos + len > buf->vb.size)
205 len = buf->vb.size - dma_q->pos;
210 if (dev->progressive)
213 /* Interlaces two half frames */
217 fieldstart = outp + bytesperline;
220 linesdone = dma_q->pos / bytesperline;
221 currlinedone = dma_q->pos % bytesperline;
223 if (dev->progressive)
224 offset = linesdone * bytesperline + currlinedone;
226 offset = linesdone * bytesperline * 2 + currlinedone;
228 startwrite = fieldstart + offset;
229 lencopy = bytesperline - currlinedone;
230 lencopy = lencopy > remain ? remain : lencopy;
232 if ((char *)startwrite + lencopy > (char *)outp + buf->vb.size) {
233 em28xx_isocdbg("Overflow of %zi bytes past buffer end (1)\n",
234 ((char *)startwrite + lencopy) -
235 ((char *)outp + buf->vb.size));
236 remain = (char *)outp + buf->vb.size - (char *)startwrite;
241 memcpy(startwrite, startread, lencopy);
246 startwrite += lencopy + bytesperline;
247 startread += lencopy;
248 if (bytesperline > remain)
251 lencopy = bytesperline;
253 if ((char *)startwrite + lencopy > (char *)outp +
255 em28xx_isocdbg("Overflow of %zi bytes past buffer end"
257 ((char *)startwrite + lencopy) -
258 ((char *)outp + buf->vb.size));
259 lencopy = remain = (char *)outp + buf->vb.size -
265 memcpy(startwrite, startread, lencopy);
273 static void em28xx_copy_vbi(struct em28xx *dev,
274 struct em28xx_dmaqueue *dma_q,
275 struct em28xx_buffer *buf,
277 unsigned char *outp, unsigned long len)
279 void *startwrite, *startread;
284 em28xx_isocdbg("dev is null\n");
287 bytesperline = dev->vbi_width;
290 em28xx_isocdbg("dma_q is null\n");
297 em28xx_isocdbg("p is null\n");
301 em28xx_isocdbg("outp is null\n");
305 if (dma_q->pos + len > buf->vb.size)
306 len = buf->vb.size - dma_q->pos;
310 startwrite = outp + dma_q->pos;
313 /* Make sure the bottom field populates the second half of the frame */
314 if (buf->top_field == 0) {
315 startwrite += bytesperline * dev->vbi_height;
316 offset += bytesperline * dev->vbi_height;
319 memcpy(startwrite, startread, len);
323 static inline void print_err_status(struct em28xx *dev,
324 int packet, int status)
326 char *errmsg = "Unknown";
330 errmsg = "unlinked synchronuously";
333 errmsg = "unlinked asynchronuously";
336 errmsg = "Buffer error (overrun)";
339 errmsg = "Stalled (device not responding)";
342 errmsg = "Babble (bad cable?)";
345 errmsg = "Bit-stuff error (bad cable?)";
348 errmsg = "CRC/Timeout (could be anything)";
351 errmsg = "Device does not respond";
355 em28xx_isocdbg("URB status %d [%s].\n", status, errmsg);
357 em28xx_isocdbg("URB packet %d, status %d [%s].\n",
358 packet, status, errmsg);
363 * video-buf generic routine to get the next available buffer
365 static inline void get_next_buf(struct em28xx_dmaqueue *dma_q,
366 struct em28xx_buffer **buf)
368 struct em28xx *dev = container_of(dma_q, struct em28xx, vidq);
371 if (list_empty(&dma_q->active)) {
372 em28xx_isocdbg("No active queue to serve\n");
373 dev->isoc_ctl.vid_buf = NULL;
378 /* Get the next buffer */
379 *buf = list_entry(dma_q->active.next, struct em28xx_buffer, vb.queue);
381 /* Cleans up buffer - Useful for testing for frame/URB loss */
382 outp = videobuf_to_vmalloc(&(*buf)->vb);
383 memset(outp, 0, (*buf)->vb.size);
385 dev->isoc_ctl.vid_buf = *buf;
391 * video-buf generic routine to get the next available VBI buffer
393 static inline void vbi_get_next_buf(struct em28xx_dmaqueue *dma_q,
394 struct em28xx_buffer **buf)
396 struct em28xx *dev = container_of(dma_q, struct em28xx, vbiq);
399 if (list_empty(&dma_q->active)) {
400 em28xx_isocdbg("No active queue to serve\n");
401 dev->isoc_ctl.vbi_buf = NULL;
406 /* Get the next buffer */
407 *buf = list_entry(dma_q->active.next, struct em28xx_buffer, vb.queue);
408 /* Cleans up buffer - Useful for testing for frame/URB loss */
409 outp = videobuf_to_vmalloc(&(*buf)->vb);
410 memset(outp, 0x00, (*buf)->vb.size);
412 dev->isoc_ctl.vbi_buf = *buf;
418 * Controls the isoc copy of each urb packet
420 static inline int em28xx_isoc_copy(struct em28xx *dev, struct urb *urb)
422 struct em28xx_buffer *buf;
423 struct em28xx_dmaqueue *dma_q = &dev->vidq;
424 unsigned char *outp = NULL;
425 int i, len = 0, rc = 1;
431 if ((dev->state & DEV_DISCONNECTED) || (dev->state & DEV_MISCONFIGURED))
434 if (urb->status < 0) {
435 print_err_status(dev, -1, urb->status);
436 if (urb->status == -ENOENT)
440 buf = dev->isoc_ctl.vid_buf;
442 outp = videobuf_to_vmalloc(&buf->vb);
444 for (i = 0; i < urb->number_of_packets; i++) {
445 int status = urb->iso_frame_desc[i].status;
448 print_err_status(dev, i, status);
449 if (urb->iso_frame_desc[i].status != -EPROTO)
453 len = urb->iso_frame_desc[i].actual_length - 4;
455 if (urb->iso_frame_desc[i].actual_length <= 0) {
456 /* em28xx_isocdbg("packet %d is empty",i); - spammy */
459 if (urb->iso_frame_desc[i].actual_length >
461 em28xx_isocdbg("packet bigger than packet size");
465 p = urb->transfer_buffer + urb->iso_frame_desc[i].offset;
467 /* FIXME: incomplete buffer checks where removed to make
468 logic simpler. Impacts of those changes should be evaluated
470 if (p[0] == 0x33 && p[1] == 0x95 && p[2] == 0x00) {
471 em28xx_isocdbg("VBI HEADER!!!\n");
472 /* FIXME: Should add vbi copy */
475 if (p[0] == 0x22 && p[1] == 0x5a) {
476 em28xx_isocdbg("Video frame %d, length=%i, %s\n", p[2],
477 len, (p[2] & 1) ? "odd" : "even");
479 if (dev->progressive || !(p[2] & 1)) {
481 buffer_filled(dev, dma_q, buf);
482 get_next_buf(dma_q, &buf);
486 outp = videobuf_to_vmalloc(&buf->vb);
499 if (p[0] != 0x88 && p[0] != 0x22) {
500 em28xx_isocdbg("frame is not complete\n");
505 em28xx_copy_video(dev, dma_q, buf, p, outp, len);
511 /* Version of isoc handler that takes into account a mixture of video and
513 static inline int em28xx_isoc_copy_vbi(struct em28xx *dev, struct urb *urb)
515 struct em28xx_buffer *buf, *vbi_buf;
516 struct em28xx_dmaqueue *dma_q = &dev->vidq;
517 struct em28xx_dmaqueue *vbi_dma_q = &dev->vbiq;
518 unsigned char *outp = NULL;
519 unsigned char *vbioutp = NULL;
520 int i, len = 0, rc = 1;
527 if ((dev->state & DEV_DISCONNECTED) || (dev->state & DEV_MISCONFIGURED))
530 if (urb->status < 0) {
531 print_err_status(dev, -1, urb->status);
532 if (urb->status == -ENOENT)
536 buf = dev->isoc_ctl.vid_buf;
538 outp = videobuf_to_vmalloc(&buf->vb);
540 vbi_buf = dev->isoc_ctl.vbi_buf;
542 vbioutp = videobuf_to_vmalloc(&vbi_buf->vb);
544 for (i = 0; i < urb->number_of_packets; i++) {
545 int status = urb->iso_frame_desc[i].status;
548 print_err_status(dev, i, status);
549 if (urb->iso_frame_desc[i].status != -EPROTO)
553 len = urb->iso_frame_desc[i].actual_length;
554 if (urb->iso_frame_desc[i].actual_length <= 0) {
555 /* em28xx_isocdbg("packet %d is empty",i); - spammy */
558 if (urb->iso_frame_desc[i].actual_length >
560 em28xx_isocdbg("packet bigger than packet size");
564 p = urb->transfer_buffer + urb->iso_frame_desc[i].offset;
566 /* capture type 0 = vbi start
567 capture type 1 = video start
568 capture type 2 = video in progress */
569 if (p[0] == 0x33 && p[1] == 0x95) {
570 dev->capture_type = 0;
572 em28xx_isocdbg("VBI START HEADER!!!\n");
573 dev->cur_field = p[2];
576 } else if (p[0] == 0x88 && p[1] == 0x88 &&
577 p[2] == 0x88 && p[3] == 0x88) {
581 } else if (p[0] == 0x22 && p[1] == 0x5a) {
587 vbi_size = dev->vbi_width * dev->vbi_height;
589 if (dev->capture_type == 0) {
590 if (dev->vbi_read >= vbi_size) {
591 /* We've already read all the VBI data, so
592 treat the rest as video */
593 em28xx_isocdbg("dev->vbi_read > vbi_size\n");
594 } else if ((dev->vbi_read + len) < vbi_size) {
595 /* This entire frame is VBI data */
596 if (dev->vbi_read == 0 &&
597 (!(dev->cur_field & 1))) {
598 /* Brand new frame */
600 vbi_buffer_filled(dev,
603 vbi_get_next_buf(vbi_dma_q, &vbi_buf);
607 vbioutp = videobuf_to_vmalloc(
611 if (dev->vbi_read == 0) {
613 if (vbi_buf != NULL) {
614 if (dev->cur_field & 1)
615 vbi_buf->top_field = 0;
617 vbi_buf->top_field = 1;
621 dev->vbi_read += len;
622 em28xx_copy_vbi(dev, vbi_dma_q, vbi_buf, p,
625 /* Some of this frame is VBI data and some is
627 int vbi_data_len = vbi_size - dev->vbi_read;
628 dev->vbi_read += vbi_data_len;
629 em28xx_copy_vbi(dev, vbi_dma_q, vbi_buf, p,
630 vbioutp, vbi_data_len);
631 dev->capture_type = 1;
637 if (dev->capture_type == 1) {
638 dev->capture_type = 2;
639 if (dev->progressive || !(dev->cur_field & 1)) {
641 buffer_filled(dev, dma_q, buf);
642 get_next_buf(dma_q, &buf);
646 outp = videobuf_to_vmalloc(&buf->vb);
649 if (dev->cur_field & 1)
658 if (buf != NULL && dev->capture_type == 2) {
659 if (len >= 4 && p[0] == 0x88 && p[1] == 0x88 &&
660 p[2] == 0x88 && p[3] == 0x88) {
664 if (len >= 4 && p[0] == 0x22 && p[1] == 0x5a) {
665 em28xx_isocdbg("Video frame %d, len=%i, %s\n",
666 p[2], len, (p[2] & 1) ?
673 em28xx_copy_video(dev, dma_q, buf, p, outp,
681 /* ------------------------------------------------------------------
683 ------------------------------------------------------------------*/
686 buffer_setup(struct videobuf_queue *vq, unsigned int *count, unsigned int *size)
688 struct em28xx_fh *fh = vq->priv_data;
689 struct em28xx *dev = fh->dev;
690 struct v4l2_frequency f;
692 *size = (fh->dev->width * fh->dev->height * dev->format->depth + 7)
696 *count = EM28XX_DEF_BUF;
698 if (*count < EM28XX_MIN_BUF)
699 *count = EM28XX_MIN_BUF;
701 /* Ask tuner to go to analog or radio mode */
702 memset(&f, 0, sizeof(f));
703 f.frequency = dev->ctl_freq;
704 f.type = fh->radio ? V4L2_TUNER_RADIO : V4L2_TUNER_ANALOG_TV;
706 v4l2_device_call_all(&dev->v4l2_dev, 0, tuner, s_frequency, &f);
711 /* This is called *without* dev->slock held; please keep it that way */
712 static void free_buffer(struct videobuf_queue *vq, struct em28xx_buffer *buf)
714 struct em28xx_fh *fh = vq->priv_data;
715 struct em28xx *dev = fh->dev;
716 unsigned long flags = 0;
720 /* We used to wait for the buffer to finish here, but this didn't work
721 because, as we were keeping the state as VIDEOBUF_QUEUED,
722 videobuf_queue_cancel marked it as finished for us.
723 (Also, it could wedge forever if the hardware was misconfigured.)
725 This should be safe; by the time we get here, the buffer isn't
726 queued anymore. If we ever start marking the buffers as
727 VIDEOBUF_ACTIVE, it won't be, though.
729 spin_lock_irqsave(&dev->slock, flags);
730 if (dev->isoc_ctl.vid_buf == buf)
731 dev->isoc_ctl.vid_buf = NULL;
732 spin_unlock_irqrestore(&dev->slock, flags);
734 videobuf_vmalloc_free(&buf->vb);
735 buf->vb.state = VIDEOBUF_NEEDS_INIT;
739 buffer_prepare(struct videobuf_queue *vq, struct videobuf_buffer *vb,
740 enum v4l2_field field)
742 struct em28xx_fh *fh = vq->priv_data;
743 struct em28xx_buffer *buf = container_of(vb, struct em28xx_buffer, vb);
744 struct em28xx *dev = fh->dev;
745 int rc = 0, urb_init = 0;
747 buf->vb.size = (fh->dev->width * fh->dev->height * dev->format->depth
750 if (0 != buf->vb.baddr && buf->vb.bsize < buf->vb.size)
753 buf->vb.width = dev->width;
754 buf->vb.height = dev->height;
755 buf->vb.field = field;
757 if (VIDEOBUF_NEEDS_INIT == buf->vb.state) {
758 rc = videobuf_iolock(vq, &buf->vb, NULL);
763 if (!dev->isoc_ctl.num_bufs)
767 if (em28xx_vbi_supported(dev) == 1)
768 rc = em28xx_init_isoc(dev, EM28XX_NUM_PACKETS,
771 em28xx_isoc_copy_vbi);
773 rc = em28xx_init_isoc(dev, EM28XX_NUM_PACKETS,
781 buf->vb.state = VIDEOBUF_PREPARED;
785 free_buffer(vq, buf);
790 buffer_queue(struct videobuf_queue *vq, struct videobuf_buffer *vb)
792 struct em28xx_buffer *buf = container_of(vb,
793 struct em28xx_buffer,
795 struct em28xx_fh *fh = vq->priv_data;
796 struct em28xx *dev = fh->dev;
797 struct em28xx_dmaqueue *vidq = &dev->vidq;
799 buf->vb.state = VIDEOBUF_QUEUED;
800 list_add_tail(&buf->vb.queue, &vidq->active);
804 static void buffer_release(struct videobuf_queue *vq,
805 struct videobuf_buffer *vb)
807 struct em28xx_buffer *buf = container_of(vb,
808 struct em28xx_buffer,
810 struct em28xx_fh *fh = vq->priv_data;
811 struct em28xx *dev = (struct em28xx *)fh->dev;
813 em28xx_isocdbg("em28xx: called buffer_release\n");
815 free_buffer(vq, buf);
818 static struct videobuf_queue_ops em28xx_video_qops = {
819 .buf_setup = buffer_setup,
820 .buf_prepare = buffer_prepare,
821 .buf_queue = buffer_queue,
822 .buf_release = buffer_release,
825 /********************* v4l2 interface **************************************/
827 static void video_mux(struct em28xx *dev, int index)
829 dev->ctl_input = index;
830 dev->ctl_ainput = INPUT(index)->amux;
831 dev->ctl_aoutput = INPUT(index)->aout;
833 if (!dev->ctl_aoutput)
834 dev->ctl_aoutput = EM28XX_AOUT_MASTER;
836 v4l2_device_call_all(&dev->v4l2_dev, 0, video, s_routing,
837 INPUT(index)->vmux, 0, 0);
839 if (dev->board.has_msp34xx) {
840 if (dev->i2s_speed) {
841 v4l2_device_call_all(&dev->v4l2_dev, 0, audio,
842 s_i2s_clock_freq, dev->i2s_speed);
844 /* Note: this is msp3400 specific */
845 v4l2_device_call_all(&dev->v4l2_dev, 0, audio, s_routing,
846 dev->ctl_ainput, MSP_OUTPUT(MSP_SC_IN_DSP_SCART1), 0);
849 if (dev->board.adecoder != EM28XX_NOADECODER) {
850 v4l2_device_call_all(&dev->v4l2_dev, 0, audio, s_routing,
851 dev->ctl_ainput, dev->ctl_aoutput, 0);
854 em28xx_audio_analog_set(dev);
857 /* Usage lock check functions */
858 static int res_get(struct em28xx_fh *fh, unsigned int bit)
860 struct em28xx *dev = fh->dev;
862 if (fh->resources & bit)
863 /* have it already allocated */
867 if (dev->resources & bit) {
868 /* no, someone else uses it */
871 /* it's free, grab it */
872 fh->resources |= bit;
873 dev->resources |= bit;
874 em28xx_videodbg("res: get %d\n", bit);
878 static int res_check(struct em28xx_fh *fh, unsigned int bit)
880 return fh->resources & bit;
883 static int res_locked(struct em28xx *dev, unsigned int bit)
885 return dev->resources & bit;
888 static void res_free(struct em28xx_fh *fh, unsigned int bits)
890 struct em28xx *dev = fh->dev;
892 BUG_ON((fh->resources & bits) != bits);
894 fh->resources &= ~bits;
895 dev->resources &= ~bits;
896 em28xx_videodbg("res: put %d\n", bits);
899 static int get_ressource(struct em28xx_fh *fh)
902 case V4L2_BUF_TYPE_VIDEO_CAPTURE:
903 return EM28XX_RESOURCE_VIDEO;
904 case V4L2_BUF_TYPE_VBI_CAPTURE:
905 return EM28XX_RESOURCE_VBI;
914 * return the ac97 supported controls
916 static int ac97_queryctrl(struct v4l2_queryctrl *qc)
920 for (i = 0; i < ARRAY_SIZE(ac97_qctrl); i++) {
921 if (qc->id && qc->id == ac97_qctrl[i].id) {
922 memcpy(qc, &(ac97_qctrl[i]), sizeof(*qc));
927 /* Control is not ac97 related */
933 * return the current values for ac97 mute and volume
935 static int ac97_get_ctrl(struct em28xx *dev, struct v4l2_control *ctrl)
938 case V4L2_CID_AUDIO_MUTE:
939 ctrl->value = dev->mute;
941 case V4L2_CID_AUDIO_VOLUME:
942 ctrl->value = dev->volume;
945 /* Control is not ac97 related */
952 * set values for ac97 mute and volume
954 static int ac97_set_ctrl(struct em28xx *dev, const struct v4l2_control *ctrl)
958 for (i = 0; i < ARRAY_SIZE(ac97_qctrl); i++)
959 if (ctrl->id == ac97_qctrl[i].id)
962 /* Announce that hasn't handle it */
966 if (ctrl->value < ac97_qctrl[i].minimum ||
967 ctrl->value > ac97_qctrl[i].maximum)
971 case V4L2_CID_AUDIO_MUTE:
972 dev->mute = ctrl->value;
974 case V4L2_CID_AUDIO_VOLUME:
975 dev->volume = ctrl->value;
979 return em28xx_audio_analog_set(dev);
982 static int check_dev(struct em28xx *dev)
984 if (dev->state & DEV_DISCONNECTED) {
985 em28xx_errdev("v4l2 ioctl: device not present\n");
989 if (dev->state & DEV_MISCONFIGURED) {
990 em28xx_errdev("v4l2 ioctl: device is misconfigured; "
991 "close and open it again\n");
997 static void get_scale(struct em28xx *dev,
998 unsigned int width, unsigned int height,
999 unsigned int *hscale, unsigned int *vscale)
1001 unsigned int maxw = norm_maxw(dev);
1002 unsigned int maxh = norm_maxh(dev);
1004 *hscale = (((unsigned long)maxw) << 12) / width - 4096L;
1005 if (*hscale >= 0x4000)
1008 *vscale = (((unsigned long)maxh) << 12) / height - 4096L;
1009 if (*vscale >= 0x4000)
1013 /* ------------------------------------------------------------------
1014 IOCTL vidioc handling
1015 ------------------------------------------------------------------*/
1017 static int vidioc_g_fmt_vid_cap(struct file *file, void *priv,
1018 struct v4l2_format *f)
1020 struct em28xx_fh *fh = priv;
1021 struct em28xx *dev = fh->dev;
1023 f->fmt.pix.width = dev->width;
1024 f->fmt.pix.height = dev->height;
1025 f->fmt.pix.pixelformat = dev->format->fourcc;
1026 f->fmt.pix.bytesperline = (dev->width * dev->format->depth + 7) >> 3;
1027 f->fmt.pix.sizeimage = f->fmt.pix.bytesperline * dev->height;
1028 f->fmt.pix.colorspace = V4L2_COLORSPACE_SMPTE170M;
1030 /* FIXME: TOP? NONE? BOTTOM? ALTENATE? */
1031 if (dev->progressive)
1032 f->fmt.pix.field = V4L2_FIELD_NONE;
1034 f->fmt.pix.field = dev->interlaced ?
1035 V4L2_FIELD_INTERLACED : V4L2_FIELD_TOP;
1039 static struct em28xx_fmt *format_by_fourcc(unsigned int fourcc)
1043 for (i = 0; i < ARRAY_SIZE(format); i++)
1044 if (format[i].fourcc == fourcc)
1050 static int vidioc_try_fmt_vid_cap(struct file *file, void *priv,
1051 struct v4l2_format *f)
1053 struct em28xx_fh *fh = priv;
1054 struct em28xx *dev = fh->dev;
1055 unsigned int width = f->fmt.pix.width;
1056 unsigned int height = f->fmt.pix.height;
1057 unsigned int maxw = norm_maxw(dev);
1058 unsigned int maxh = norm_maxh(dev);
1059 unsigned int hscale, vscale;
1060 struct em28xx_fmt *fmt;
1062 fmt = format_by_fourcc(f->fmt.pix.pixelformat);
1064 em28xx_videodbg("Fourcc format (%08x) invalid.\n",
1065 f->fmt.pix.pixelformat);
1069 if (dev->board.is_em2800) {
1070 /* the em2800 can only scale down to 50% */
1071 height = height > (3 * maxh / 4) ? maxh : maxh / 2;
1072 width = width > (3 * maxw / 4) ? maxw : maxw / 2;
1074 /* width must even because of the YUYV format
1075 height must be even because of interlacing */
1076 v4l_bound_align_image(&width, 48, maxw, 1, &height, 32, maxh,
1080 get_scale(dev, width, height, &hscale, &vscale);
1082 width = (((unsigned long)maxw) << 12) / (hscale + 4096L);
1083 height = (((unsigned long)maxh) << 12) / (vscale + 4096L);
1085 f->fmt.pix.width = width;
1086 f->fmt.pix.height = height;
1087 f->fmt.pix.pixelformat = fmt->fourcc;
1088 f->fmt.pix.bytesperline = (dev->width * fmt->depth + 7) >> 3;
1089 f->fmt.pix.sizeimage = f->fmt.pix.bytesperline * height;
1090 f->fmt.pix.colorspace = V4L2_COLORSPACE_SMPTE170M;
1091 if (dev->progressive)
1092 f->fmt.pix.field = V4L2_FIELD_NONE;
1094 f->fmt.pix.field = dev->interlaced ?
1095 V4L2_FIELD_INTERLACED : V4L2_FIELD_TOP;
1100 static int em28xx_set_video_format(struct em28xx *dev, unsigned int fourcc,
1101 unsigned width, unsigned height)
1103 struct em28xx_fmt *fmt;
1105 fmt = format_by_fourcc(fourcc);
1111 dev->height = height;
1113 /* set new image size */
1114 get_scale(dev, dev->width, dev->height, &dev->hscale, &dev->vscale);
1116 em28xx_set_alternate(dev);
1117 em28xx_resolution_set(dev);
1122 static int vidioc_s_fmt_vid_cap(struct file *file, void *priv,
1123 struct v4l2_format *f)
1125 struct em28xx_fh *fh = priv;
1126 struct em28xx *dev = fh->dev;
1129 rc = check_dev(dev);
1133 vidioc_try_fmt_vid_cap(file, priv, f);
1135 if (videobuf_queue_is_busy(&fh->vb_vidq)) {
1136 em28xx_errdev("%s queue busy\n", __func__);
1140 return em28xx_set_video_format(dev, f->fmt.pix.pixelformat,
1141 f->fmt.pix.width, f->fmt.pix.height);
1144 static int vidioc_g_std(struct file *file, void *priv, v4l2_std_id *norm)
1146 struct em28xx_fh *fh = priv;
1147 struct em28xx *dev = fh->dev;
1150 rc = check_dev(dev);
1159 static int vidioc_querystd(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);
1169 v4l2_device_call_all(&dev->v4l2_dev, 0, video, querystd, norm);
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);
1187 /* Adjusts width/height, if needed */
1188 f.fmt.pix.width = dev->width;
1189 f.fmt.pix.height = dev->height;
1190 vidioc_try_fmt_vid_cap(file, priv, &f);
1192 /* set new image size */
1193 dev->width = f.fmt.pix.width;
1194 dev->height = f.fmt.pix.height;
1195 get_scale(dev, dev->width, dev->height, &dev->hscale, &dev->vscale);
1197 em28xx_resolution_set(dev);
1198 v4l2_device_call_all(&dev->v4l2_dev, 0, core, s_std, dev->norm);
1203 static int vidioc_g_parm(struct file *file, void *priv,
1204 struct v4l2_streamparm *p)
1206 struct em28xx_fh *fh = priv;
1207 struct em28xx *dev = fh->dev;
1210 if (p->type != V4L2_BUF_TYPE_VIDEO_CAPTURE)
1213 if (dev->board.is_webcam)
1214 rc = v4l2_device_call_until_err(&dev->v4l2_dev, 0,
1217 v4l2_video_std_frame_period(dev->norm,
1218 &p->parm.capture.timeperframe);
1223 static int vidioc_s_parm(struct file *file, void *priv,
1224 struct v4l2_streamparm *p)
1226 struct em28xx_fh *fh = priv;
1227 struct em28xx *dev = fh->dev;
1229 if (!dev->board.is_webcam)
1232 if (p->type != V4L2_BUF_TYPE_VIDEO_CAPTURE)
1235 return v4l2_device_call_until_err(&dev->v4l2_dev, 0, video, s_parm, p);
1238 static const char *iname[] = {
1239 [EM28XX_VMUX_COMPOSITE1] = "Composite1",
1240 [EM28XX_VMUX_COMPOSITE2] = "Composite2",
1241 [EM28XX_VMUX_COMPOSITE3] = "Composite3",
1242 [EM28XX_VMUX_COMPOSITE4] = "Composite4",
1243 [EM28XX_VMUX_SVIDEO] = "S-Video",
1244 [EM28XX_VMUX_TELEVISION] = "Television",
1245 [EM28XX_VMUX_CABLE] = "Cable TV",
1246 [EM28XX_VMUX_DVB] = "DVB",
1247 [EM28XX_VMUX_DEBUG] = "for debug only",
1250 static int vidioc_enum_input(struct file *file, void *priv,
1251 struct v4l2_input *i)
1253 struct em28xx_fh *fh = priv;
1254 struct em28xx *dev = fh->dev;
1258 if (n >= MAX_EM28XX_INPUT)
1260 if (0 == INPUT(n)->type)
1264 i->type = V4L2_INPUT_TYPE_CAMERA;
1266 strcpy(i->name, iname[INPUT(n)->type]);
1268 if ((EM28XX_VMUX_TELEVISION == INPUT(n)->type) ||
1269 (EM28XX_VMUX_CABLE == INPUT(n)->type))
1270 i->type = V4L2_INPUT_TYPE_TUNER;
1272 i->std = dev->vdev->tvnorms;
1277 static int vidioc_g_input(struct file *file, void *priv, unsigned int *i)
1279 struct em28xx_fh *fh = priv;
1280 struct em28xx *dev = fh->dev;
1282 *i = dev->ctl_input;
1287 static int vidioc_s_input(struct file *file, void *priv, unsigned int i)
1289 struct em28xx_fh *fh = priv;
1290 struct em28xx *dev = fh->dev;
1293 rc = check_dev(dev);
1297 if (i >= MAX_EM28XX_INPUT)
1299 if (0 == INPUT(i)->type)
1304 video_mux(dev, dev->ctl_input);
1308 static int vidioc_g_audio(struct file *file, void *priv, struct v4l2_audio *a)
1310 struct em28xx_fh *fh = priv;
1311 struct em28xx *dev = fh->dev;
1313 if (!dev->audio_mode.has_audio)
1317 case EM28XX_AMUX_VIDEO:
1318 strcpy(a->name, "Television");
1320 case EM28XX_AMUX_LINE_IN:
1321 strcpy(a->name, "Line In");
1323 case EM28XX_AMUX_VIDEO2:
1324 strcpy(a->name, "Television alt");
1326 case EM28XX_AMUX_PHONE:
1327 strcpy(a->name, "Phone");
1329 case EM28XX_AMUX_MIC:
1330 strcpy(a->name, "Mic");
1332 case EM28XX_AMUX_CD:
1333 strcpy(a->name, "CD");
1335 case EM28XX_AMUX_AUX:
1336 strcpy(a->name, "Aux");
1338 case EM28XX_AMUX_PCM_OUT:
1339 strcpy(a->name, "PCM");
1345 a->index = dev->ctl_ainput;
1346 a->capability = V4L2_AUDCAP_STEREO;
1351 static int vidioc_s_audio(struct file *file, void *priv, struct v4l2_audio *a)
1353 struct em28xx_fh *fh = priv;
1354 struct em28xx *dev = fh->dev;
1357 if (!dev->audio_mode.has_audio)
1360 if (a->index >= MAX_EM28XX_INPUT)
1362 if (0 == INPUT(a->index)->type)
1365 dev->ctl_ainput = INPUT(a->index)->amux;
1366 dev->ctl_aoutput = INPUT(a->index)->aout;
1368 if (!dev->ctl_aoutput)
1369 dev->ctl_aoutput = EM28XX_AOUT_MASTER;
1374 static int vidioc_queryctrl(struct file *file, void *priv,
1375 struct v4l2_queryctrl *qc)
1377 struct em28xx_fh *fh = priv;
1378 struct em28xx *dev = fh->dev;
1382 rc = check_dev(dev);
1386 memset(qc, 0, sizeof(*qc));
1390 /* enumerate AC97 controls */
1391 if (dev->audio_mode.ac97 != EM28XX_NO_AC97) {
1392 rc = ac97_queryctrl(qc);
1397 /* enumerate V4L2 device controls */
1398 v4l2_device_call_all(&dev->v4l2_dev, 0, core, queryctrl, qc);
1407 * FIXME: This is an indirect way to check if a control exists at a
1408 * subdev. Instead of that hack, maybe the better would be to change all
1409 * subdevs to return -ENOIOCTLCMD, if an ioctl is not supported.
1411 static int check_subdev_ctrl(struct em28xx *dev, int id)
1413 struct v4l2_queryctrl qc;
1415 memset(&qc, 0, sizeof(qc));
1418 /* enumerate V4L2 device controls */
1419 v4l2_device_call_all(&dev->v4l2_dev, 0, core, queryctrl, &qc);
1427 static int vidioc_g_ctrl(struct file *file, void *priv,
1428 struct v4l2_control *ctrl)
1430 struct em28xx_fh *fh = priv;
1431 struct em28xx *dev = fh->dev;
1434 rc = check_dev(dev);
1439 /* Set an AC97 control */
1440 if (dev->audio_mode.ac97 != EM28XX_NO_AC97)
1441 rc = ac97_get_ctrl(dev, ctrl);
1445 /* It were not an AC97 control. Sends it to the v4l2 dev interface */
1447 if (check_subdev_ctrl(dev, ctrl->id))
1450 v4l2_device_call_all(&dev->v4l2_dev, 0, core, g_ctrl, ctrl);
1457 static int vidioc_s_ctrl(struct file *file, void *priv,
1458 struct v4l2_control *ctrl)
1460 struct em28xx_fh *fh = priv;
1461 struct em28xx *dev = fh->dev;
1464 rc = check_dev(dev);
1468 /* Set an AC97 control */
1469 if (dev->audio_mode.ac97 != EM28XX_NO_AC97)
1470 rc = ac97_set_ctrl(dev, ctrl);
1474 /* It isn't an AC97 control. Sends it to the v4l2 dev interface */
1476 rc = check_subdev_ctrl(dev, ctrl->id);
1478 v4l2_device_call_all(&dev->v4l2_dev, 0,
1479 core, s_ctrl, ctrl);
1481 * In the case of non-AC97 volume controls, we still need
1482 * to do some setups at em28xx, in order to mute/unmute
1483 * and to adjust audio volume. However, the value ranges
1484 * should be checked by the corresponding V4L subdriver.
1487 case V4L2_CID_AUDIO_MUTE:
1488 dev->mute = ctrl->value;
1489 rc = em28xx_audio_analog_set(dev);
1491 case V4L2_CID_AUDIO_VOLUME:
1492 dev->volume = ctrl->value;
1493 rc = em28xx_audio_analog_set(dev);
1496 return (rc < 0) ? rc : 0;
1499 static int vidioc_g_tuner(struct file *file, void *priv,
1500 struct v4l2_tuner *t)
1502 struct em28xx_fh *fh = priv;
1503 struct em28xx *dev = fh->dev;
1506 rc = check_dev(dev);
1513 strcpy(t->name, "Tuner");
1514 t->type = V4L2_TUNER_ANALOG_TV;
1516 v4l2_device_call_all(&dev->v4l2_dev, 0, tuner, g_tuner, t);
1520 static int vidioc_s_tuner(struct file *file, void *priv,
1521 struct v4l2_tuner *t)
1523 struct em28xx_fh *fh = priv;
1524 struct em28xx *dev = fh->dev;
1527 rc = check_dev(dev);
1534 v4l2_device_call_all(&dev->v4l2_dev, 0, tuner, s_tuner, t);
1538 static int vidioc_g_frequency(struct file *file, void *priv,
1539 struct v4l2_frequency *f)
1541 struct em28xx_fh *fh = priv;
1542 struct em28xx *dev = fh->dev;
1544 f->type = fh->radio ? V4L2_TUNER_RADIO : V4L2_TUNER_ANALOG_TV;
1545 f->frequency = dev->ctl_freq;
1549 static int vidioc_s_frequency(struct file *file, void *priv,
1550 struct v4l2_frequency *f)
1552 struct em28xx_fh *fh = priv;
1553 struct em28xx *dev = fh->dev;
1556 rc = check_dev(dev);
1563 if (unlikely(0 == fh->radio && f->type != V4L2_TUNER_ANALOG_TV))
1565 if (unlikely(1 == fh->radio && f->type != V4L2_TUNER_RADIO))
1568 dev->ctl_freq = f->frequency;
1569 v4l2_device_call_all(&dev->v4l2_dev, 0, tuner, s_frequency, f);
1574 #ifdef CONFIG_VIDEO_ADV_DEBUG
1575 static int em28xx_reg_len(int reg)
1578 case EM28XX_R40_AC97LSB:
1579 case EM28XX_R30_HSCALELOW:
1580 case EM28XX_R32_VSCALELOW:
1587 static int vidioc_g_chip_ident(struct file *file, void *priv,
1588 struct v4l2_dbg_chip_ident *chip)
1590 struct em28xx_fh *fh = priv;
1591 struct em28xx *dev = fh->dev;
1593 chip->ident = V4L2_IDENT_NONE;
1596 v4l2_device_call_all(&dev->v4l2_dev, 0, core, g_chip_ident, chip);
1602 static int vidioc_g_register(struct file *file, void *priv,
1603 struct v4l2_dbg_register *reg)
1605 struct em28xx_fh *fh = priv;
1606 struct em28xx *dev = fh->dev;
1609 switch (reg->match.type) {
1610 case V4L2_CHIP_MATCH_AC97:
1611 ret = em28xx_read_ac97(dev, reg->reg);
1618 case V4L2_CHIP_MATCH_I2C_DRIVER:
1619 v4l2_device_call_all(&dev->v4l2_dev, 0, core, g_register, reg);
1621 case V4L2_CHIP_MATCH_I2C_ADDR:
1622 /* TODO: is this correct? */
1623 v4l2_device_call_all(&dev->v4l2_dev, 0, core, g_register, reg);
1626 if (!v4l2_chip_match_host(®->match))
1631 reg->size = em28xx_reg_len(reg->reg);
1632 if (reg->size == 1) {
1633 ret = em28xx_read_reg(dev, reg->reg);
1641 ret = em28xx_read_reg_req_len(dev, USB_REQ_GET_STATUS,
1642 reg->reg, (char *)&val, 2);
1646 reg->val = le16_to_cpu(val);
1652 static int vidioc_s_register(struct file *file, void *priv,
1653 struct v4l2_dbg_register *reg)
1655 struct em28xx_fh *fh = priv;
1656 struct em28xx *dev = fh->dev;
1659 switch (reg->match.type) {
1660 case V4L2_CHIP_MATCH_AC97:
1661 return em28xx_write_ac97(dev, reg->reg, reg->val);
1662 case V4L2_CHIP_MATCH_I2C_DRIVER:
1663 v4l2_device_call_all(&dev->v4l2_dev, 0, core, s_register, reg);
1665 case V4L2_CHIP_MATCH_I2C_ADDR:
1666 /* TODO: is this correct? */
1667 v4l2_device_call_all(&dev->v4l2_dev, 0, core, s_register, reg);
1670 if (!v4l2_chip_match_host(®->match))
1675 buf = cpu_to_le16(reg->val);
1677 return em28xx_write_regs(dev, reg->reg, (char *)&buf,
1678 em28xx_reg_len(reg->reg));
1683 static int vidioc_cropcap(struct file *file, void *priv,
1684 struct v4l2_cropcap *cc)
1686 struct em28xx_fh *fh = priv;
1687 struct em28xx *dev = fh->dev;
1689 if (cc->type != V4L2_BUF_TYPE_VIDEO_CAPTURE)
1692 cc->bounds.left = 0;
1694 cc->bounds.width = dev->width;
1695 cc->bounds.height = dev->height;
1696 cc->defrect = cc->bounds;
1697 cc->pixelaspect.numerator = 54; /* 4:3 FIXME: remove magic numbers */
1698 cc->pixelaspect.denominator = 59;
1703 static int vidioc_streamon(struct file *file, void *priv,
1704 enum v4l2_buf_type type)
1706 struct em28xx_fh *fh = priv;
1707 struct em28xx *dev = fh->dev;
1710 rc = check_dev(dev);
1714 if (unlikely(type != fh->type))
1717 em28xx_videodbg("vidioc_streamon fh=%p t=%d fh->res=%d dev->res=%d\n",
1718 fh, type, fh->resources, dev->resources);
1720 if (unlikely(!res_get(fh, get_ressource(fh))))
1723 if (fh->type == V4L2_BUF_TYPE_VIDEO_CAPTURE)
1724 rc = videobuf_streamon(&fh->vb_vidq);
1725 else if (fh->type == V4L2_BUF_TYPE_VBI_CAPTURE)
1726 rc = videobuf_streamon(&fh->vb_vbiq);
1731 static int vidioc_streamoff(struct file *file, void *priv,
1732 enum v4l2_buf_type type)
1734 struct em28xx_fh *fh = priv;
1735 struct em28xx *dev = fh->dev;
1738 rc = check_dev(dev);
1742 if (fh->type != V4L2_BUF_TYPE_VIDEO_CAPTURE &&
1743 fh->type != V4L2_BUF_TYPE_VBI_CAPTURE)
1745 if (type != fh->type)
1748 em28xx_videodbg("vidioc_streamoff fh=%p t=%d fh->res=%d dev->res=%d\n",
1749 fh, type, fh->resources, dev->resources);
1751 if (fh->type == V4L2_BUF_TYPE_VIDEO_CAPTURE) {
1752 if (res_check(fh, EM28XX_RESOURCE_VIDEO)) {
1753 videobuf_streamoff(&fh->vb_vidq);
1754 res_free(fh, EM28XX_RESOURCE_VIDEO);
1756 } else if (fh->type == V4L2_BUF_TYPE_VBI_CAPTURE) {
1757 if (res_check(fh, EM28XX_RESOURCE_VBI)) {
1758 videobuf_streamoff(&fh->vb_vbiq);
1759 res_free(fh, EM28XX_RESOURCE_VBI);
1766 static int vidioc_querycap(struct file *file, void *priv,
1767 struct v4l2_capability *cap)
1769 struct em28xx_fh *fh = priv;
1770 struct em28xx *dev = fh->dev;
1772 strlcpy(cap->driver, "em28xx", sizeof(cap->driver));
1773 strlcpy(cap->card, em28xx_boards[dev->model].name, sizeof(cap->card));
1774 usb_make_path(dev->udev, cap->bus_info, sizeof(cap->bus_info));
1777 V4L2_CAP_SLICED_VBI_CAPTURE |
1778 V4L2_CAP_VIDEO_CAPTURE |
1779 V4L2_CAP_READWRITE | V4L2_CAP_STREAMING;
1782 cap->capabilities |= V4L2_CAP_VBI_CAPTURE;
1784 if (dev->audio_mode.has_audio)
1785 cap->capabilities |= V4L2_CAP_AUDIO;
1787 if (dev->tuner_type != TUNER_ABSENT)
1788 cap->capabilities |= V4L2_CAP_TUNER;
1793 static int vidioc_enum_fmt_vid_cap(struct file *file, void *priv,
1794 struct v4l2_fmtdesc *f)
1796 if (unlikely(f->index >= ARRAY_SIZE(format)))
1799 strlcpy(f->description, format[f->index].name, sizeof(f->description));
1800 f->pixelformat = format[f->index].fourcc;
1805 static int vidioc_enum_framesizes(struct file *file, void *priv,
1806 struct v4l2_frmsizeenum *fsize)
1808 struct em28xx_fh *fh = priv;
1809 struct em28xx *dev = fh->dev;
1810 struct em28xx_fmt *fmt;
1811 unsigned int maxw = norm_maxw(dev);
1812 unsigned int maxh = norm_maxh(dev);
1814 fmt = format_by_fourcc(fsize->pixel_format);
1816 em28xx_videodbg("Fourcc format (%08x) invalid.\n",
1817 fsize->pixel_format);
1821 if (dev->board.is_em2800) {
1822 if (fsize->index > 1)
1824 fsize->type = V4L2_FRMSIZE_TYPE_DISCRETE;
1825 fsize->discrete.width = maxw / (1 + fsize->index);
1826 fsize->discrete.height = maxh / (1 + fsize->index);
1830 if (fsize->index != 0)
1833 /* Report a continuous range */
1834 fsize->type = V4L2_FRMSIZE_TYPE_STEPWISE;
1835 fsize->stepwise.min_width = 48;
1836 fsize->stepwise.min_height = 32;
1837 fsize->stepwise.max_width = maxw;
1838 fsize->stepwise.max_height = maxh;
1839 fsize->stepwise.step_width = 1;
1840 fsize->stepwise.step_height = 1;
1844 /* Sliced VBI ioctls */
1845 static int vidioc_g_fmt_sliced_vbi_cap(struct file *file, void *priv,
1846 struct v4l2_format *f)
1848 struct em28xx_fh *fh = priv;
1849 struct em28xx *dev = fh->dev;
1852 rc = check_dev(dev);
1856 f->fmt.sliced.service_set = 0;
1857 v4l2_device_call_all(&dev->v4l2_dev, 0, vbi, g_sliced_fmt, &f->fmt.sliced);
1859 if (f->fmt.sliced.service_set == 0)
1865 static int vidioc_try_set_sliced_vbi_cap(struct file *file, void *priv,
1866 struct v4l2_format *f)
1868 struct em28xx_fh *fh = priv;
1869 struct em28xx *dev = fh->dev;
1872 rc = check_dev(dev);
1876 v4l2_device_call_all(&dev->v4l2_dev, 0, vbi, g_sliced_fmt, &f->fmt.sliced);
1878 if (f->fmt.sliced.service_set == 0)
1884 /* RAW VBI ioctls */
1886 static int vidioc_g_fmt_vbi_cap(struct file *file, void *priv,
1887 struct v4l2_format *format)
1889 struct em28xx_fh *fh = priv;
1890 struct em28xx *dev = fh->dev;
1892 format->fmt.vbi.samples_per_line = dev->vbi_width;
1893 format->fmt.vbi.sample_format = V4L2_PIX_FMT_GREY;
1894 format->fmt.vbi.offset = 0;
1895 format->fmt.vbi.flags = 0;
1896 format->fmt.vbi.sampling_rate = 6750000 * 4 / 2;
1897 format->fmt.vbi.count[0] = dev->vbi_height;
1898 format->fmt.vbi.count[1] = dev->vbi_height;
1900 /* Varies by video standard (NTSC, PAL, etc.) */
1901 if (dev->norm & V4L2_STD_525_60) {
1903 format->fmt.vbi.start[0] = 10;
1904 format->fmt.vbi.start[1] = 273;
1905 } else if (dev->norm & V4L2_STD_625_50) {
1907 format->fmt.vbi.start[0] = 6;
1908 format->fmt.vbi.start[1] = 318;
1914 static int vidioc_s_fmt_vbi_cap(struct file *file, void *priv,
1915 struct v4l2_format *format)
1917 struct em28xx_fh *fh = priv;
1918 struct em28xx *dev = fh->dev;
1920 format->fmt.vbi.samples_per_line = dev->vbi_width;
1921 format->fmt.vbi.sample_format = V4L2_PIX_FMT_GREY;
1922 format->fmt.vbi.offset = 0;
1923 format->fmt.vbi.flags = 0;
1924 format->fmt.vbi.sampling_rate = 6750000 * 4 / 2;
1925 format->fmt.vbi.count[0] = dev->vbi_height;
1926 format->fmt.vbi.count[1] = dev->vbi_height;
1928 /* Varies by video standard (NTSC, PAL, etc.) */
1929 if (dev->norm & V4L2_STD_525_60) {
1931 format->fmt.vbi.start[0] = 10;
1932 format->fmt.vbi.start[1] = 273;
1933 } else if (dev->norm & V4L2_STD_625_50) {
1935 format->fmt.vbi.start[0] = 6;
1936 format->fmt.vbi.start[1] = 318;
1942 static int vidioc_reqbufs(struct file *file, void *priv,
1943 struct v4l2_requestbuffers *rb)
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_reqbufs(&fh->vb_vidq, rb);
1956 return videobuf_reqbufs(&fh->vb_vbiq, rb);
1959 static int vidioc_querybuf(struct file *file, void *priv,
1960 struct v4l2_buffer *b)
1962 struct em28xx_fh *fh = priv;
1963 struct em28xx *dev = fh->dev;
1966 rc = check_dev(dev);
1970 if (fh->type == V4L2_BUF_TYPE_VIDEO_CAPTURE)
1971 return videobuf_querybuf(&fh->vb_vidq, b);
1973 /* FIXME: I'm not sure yet whether this is a bug in zvbi or
1974 the videobuf framework, but we probably shouldn't be
1975 returning a buffer larger than that which was asked for.
1976 At a minimum, it causes a crash in zvbi since it does
1977 a memcpy based on the source buffer length */
1978 int result = videobuf_querybuf(&fh->vb_vbiq, b);
1979 b->length = dev->vbi_width * dev->vbi_height * 2;
1985 static int vidioc_qbuf(struct file *file, void *priv, struct v4l2_buffer *b)
1987 struct em28xx_fh *fh = priv;
1988 struct em28xx *dev = fh->dev;
1991 rc = check_dev(dev);
1995 if (fh->type == V4L2_BUF_TYPE_VIDEO_CAPTURE)
1996 return videobuf_qbuf(&fh->vb_vidq, b);
1998 return videobuf_qbuf(&fh->vb_vbiq, b);
2001 static int vidioc_dqbuf(struct file *file, void *priv, struct v4l2_buffer *b)
2003 struct em28xx_fh *fh = priv;
2004 struct em28xx *dev = fh->dev;
2007 rc = check_dev(dev);
2011 if (fh->type == V4L2_BUF_TYPE_VIDEO_CAPTURE)
2012 return videobuf_dqbuf(&fh->vb_vidq, b, file->f_flags &
2015 return videobuf_dqbuf(&fh->vb_vbiq, b, file->f_flags &
2019 /* ----------------------------------------------------------- */
2020 /* RADIO ESPECIFIC IOCTLS */
2021 /* ----------------------------------------------------------- */
2023 static int radio_querycap(struct file *file, void *priv,
2024 struct v4l2_capability *cap)
2026 struct em28xx *dev = ((struct em28xx_fh *)priv)->dev;
2028 strlcpy(cap->driver, "em28xx", sizeof(cap->driver));
2029 strlcpy(cap->card, em28xx_boards[dev->model].name, sizeof(cap->card));
2030 usb_make_path(dev->udev, cap->bus_info, sizeof(cap->bus_info));
2032 cap->capabilities = V4L2_CAP_TUNER;
2036 static int radio_g_tuner(struct file *file, void *priv,
2037 struct v4l2_tuner *t)
2039 struct em28xx *dev = ((struct em28xx_fh *)priv)->dev;
2041 if (unlikely(t->index > 0))
2044 strcpy(t->name, "Radio");
2045 t->type = V4L2_TUNER_RADIO;
2047 v4l2_device_call_all(&dev->v4l2_dev, 0, tuner, g_tuner, t);
2052 static int radio_enum_input(struct file *file, void *priv,
2053 struct v4l2_input *i)
2057 strcpy(i->name, "Radio");
2058 i->type = V4L2_INPUT_TYPE_TUNER;
2063 static int radio_g_audio(struct file *file, void *priv, struct v4l2_audio *a)
2065 if (unlikely(a->index))
2068 strcpy(a->name, "Radio");
2072 static int radio_s_tuner(struct file *file, void *priv,
2073 struct v4l2_tuner *t)
2075 struct em28xx *dev = ((struct em28xx_fh *)priv)->dev;
2080 v4l2_device_call_all(&dev->v4l2_dev, 0, tuner, s_tuner, t);
2085 static int radio_s_audio(struct file *file, void *fh,
2086 struct v4l2_audio *a)
2091 static int radio_s_input(struct file *file, void *fh, unsigned int i)
2096 static int radio_queryctrl(struct file *file, void *priv,
2097 struct v4l2_queryctrl *qc)
2101 if (qc->id < V4L2_CID_BASE ||
2102 qc->id >= V4L2_CID_LASTP1)
2105 for (i = 0; i < ARRAY_SIZE(ac97_qctrl); i++) {
2106 if (qc->id && qc->id == ac97_qctrl[i].id) {
2107 memcpy(qc, &(ac97_qctrl[i]), sizeof(*qc));
2116 * em28xx_v4l2_open()
2117 * inits the device and starts isoc transfer
2119 static int em28xx_v4l2_open(struct file *filp)
2121 int errCode = 0, radio = 0;
2122 struct video_device *vdev = video_devdata(filp);
2123 struct em28xx *dev = video_drvdata(filp);
2124 enum v4l2_buf_type fh_type = 0;
2125 struct em28xx_fh *fh;
2126 enum v4l2_field field;
2128 switch (vdev->vfl_type) {
2129 case VFL_TYPE_GRABBER:
2130 fh_type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
2133 fh_type = V4L2_BUF_TYPE_VBI_CAPTURE;
2135 case VFL_TYPE_RADIO:
2140 em28xx_videodbg("open dev=%s type=%s users=%d\n",
2141 video_device_node_name(vdev), v4l2_type_names[fh_type],
2145 fh = kzalloc(sizeof(struct em28xx_fh), GFP_KERNEL);
2147 em28xx_errdev("em28xx-video.c: Out of memory?!\n");
2153 filp->private_data = fh;
2155 if (fh->type == V4L2_BUF_TYPE_VIDEO_CAPTURE && dev->users == 0) {
2156 em28xx_set_mode(dev, EM28XX_ANALOG_MODE);
2157 em28xx_set_alternate(dev);
2158 em28xx_resolution_set(dev);
2160 /* Needed, since GPIO might have disabled power of
2163 em28xx_wake_i2c(dev);
2167 em28xx_videodbg("video_open: setting radio device\n");
2168 v4l2_device_call_all(&dev->v4l2_dev, 0, tuner, s_radio);
2173 if (dev->progressive)
2174 field = V4L2_FIELD_NONE;
2176 field = V4L2_FIELD_INTERLACED;
2178 videobuf_queue_vmalloc_init(&fh->vb_vidq, &em28xx_video_qops,
2180 V4L2_BUF_TYPE_VIDEO_CAPTURE, field,
2181 sizeof(struct em28xx_buffer), fh, &dev->lock);
2183 videobuf_queue_vmalloc_init(&fh->vb_vbiq, &em28xx_vbi_qops,
2185 V4L2_BUF_TYPE_VBI_CAPTURE,
2187 sizeof(struct em28xx_buffer), fh, &dev->lock);
2193 * em28xx_realease_resources()
2194 * unregisters the v4l2,i2c and usb devices
2195 * called when the device gets disconected or at module unload
2197 void em28xx_release_analog_resources(struct em28xx *dev)
2200 /*FIXME: I2C IR should be disconnected */
2202 if (dev->radio_dev) {
2203 if (video_is_registered(dev->radio_dev))
2204 video_unregister_device(dev->radio_dev);
2206 video_device_release(dev->radio_dev);
2207 dev->radio_dev = NULL;
2210 em28xx_info("V4L2 device %s deregistered\n",
2211 video_device_node_name(dev->vbi_dev));
2212 if (video_is_registered(dev->vbi_dev))
2213 video_unregister_device(dev->vbi_dev);
2215 video_device_release(dev->vbi_dev);
2216 dev->vbi_dev = NULL;
2219 em28xx_info("V4L2 device %s deregistered\n",
2220 video_device_node_name(dev->vdev));
2221 if (video_is_registered(dev->vdev))
2222 video_unregister_device(dev->vdev);
2224 video_device_release(dev->vdev);
2230 * em28xx_v4l2_close()
2231 * stops streaming and deallocates all resources allocated by the v4l2
2234 static int em28xx_v4l2_close(struct file *filp)
2236 struct em28xx_fh *fh = filp->private_data;
2237 struct em28xx *dev = fh->dev;
2240 em28xx_videodbg("users=%d\n", dev->users);
2242 if (res_check(fh, EM28XX_RESOURCE_VIDEO)) {
2243 videobuf_stop(&fh->vb_vidq);
2244 res_free(fh, EM28XX_RESOURCE_VIDEO);
2247 if (res_check(fh, EM28XX_RESOURCE_VBI)) {
2248 videobuf_stop(&fh->vb_vbiq);
2249 res_free(fh, EM28XX_RESOURCE_VBI);
2252 if (dev->users == 1) {
2253 /* the device is already disconnect,
2254 free the remaining resources */
2255 if (dev->state & DEV_DISCONNECTED) {
2256 em28xx_release_resources(dev);
2257 kfree(dev->alt_max_pkt_size);
2262 /* Save some power by putting tuner to sleep */
2263 v4l2_device_call_all(&dev->v4l2_dev, 0, core, s_power, 0);
2265 /* do this before setting alternate! */
2266 em28xx_uninit_isoc(dev);
2267 em28xx_set_mode(dev, EM28XX_SUSPEND);
2269 /* set alternate 0 */
2271 em28xx_videodbg("setting alternate 0\n");
2272 errCode = usb_set_interface(dev->udev, 0, 0);
2274 em28xx_errdev("cannot change alternate number to "
2275 "0 (error=%i)\n", errCode);
2279 videobuf_mmap_free(&fh->vb_vidq);
2280 videobuf_mmap_free(&fh->vb_vbiq);
2283 wake_up_interruptible_nr(&dev->open, 1);
2288 * em28xx_v4l2_read()
2289 * will allocate buffers when called for the first time
2292 em28xx_v4l2_read(struct file *filp, char __user *buf, size_t count,
2295 struct em28xx_fh *fh = filp->private_data;
2296 struct em28xx *dev = fh->dev;
2299 rc = check_dev(dev);
2303 /* FIXME: read() is not prepared to allow changing the video
2304 resolution while streaming. Seems a bug at em28xx_set_fmt
2307 if (fh->type == V4L2_BUF_TYPE_VIDEO_CAPTURE) {
2308 if (res_locked(dev, EM28XX_RESOURCE_VIDEO))
2311 return videobuf_read_stream(&fh->vb_vidq, buf, count, pos, 0,
2312 filp->f_flags & O_NONBLOCK);
2316 if (fh->type == V4L2_BUF_TYPE_VBI_CAPTURE) {
2317 if (!res_get(fh, EM28XX_RESOURCE_VBI))
2320 return videobuf_read_stream(&fh->vb_vbiq, buf, count, pos, 0,
2321 filp->f_flags & O_NONBLOCK);
2328 * em28xx_v4l2_poll()
2329 * will allocate buffers when called for the first time
2331 static unsigned int em28xx_v4l2_poll(struct file *filp, poll_table *wait)
2333 struct em28xx_fh *fh = filp->private_data;
2334 struct em28xx *dev = fh->dev;
2337 rc = check_dev(dev);
2341 if (fh->type == V4L2_BUF_TYPE_VIDEO_CAPTURE) {
2342 if (!res_get(fh, EM28XX_RESOURCE_VIDEO))
2344 return videobuf_poll_stream(filp, &fh->vb_vidq, wait);
2345 } else if (fh->type == V4L2_BUF_TYPE_VBI_CAPTURE) {
2346 if (!res_get(fh, EM28XX_RESOURCE_VBI))
2348 return videobuf_poll_stream(filp, &fh->vb_vbiq, wait);
2355 * em28xx_v4l2_mmap()
2357 static int em28xx_v4l2_mmap(struct file *filp, struct vm_area_struct *vma)
2359 struct em28xx_fh *fh = filp->private_data;
2360 struct em28xx *dev = fh->dev;
2363 rc = check_dev(dev);
2367 if (fh->type == V4L2_BUF_TYPE_VIDEO_CAPTURE)
2368 rc = videobuf_mmap_mapper(&fh->vb_vidq, vma);
2369 else if (fh->type == V4L2_BUF_TYPE_VBI_CAPTURE)
2370 rc = videobuf_mmap_mapper(&fh->vb_vbiq, vma);
2372 em28xx_videodbg("vma start=0x%08lx, size=%ld, ret=%d\n",
2373 (unsigned long)vma->vm_start,
2374 (unsigned long)vma->vm_end-(unsigned long)vma->vm_start,
2380 static const struct v4l2_file_operations em28xx_v4l_fops = {
2381 .owner = THIS_MODULE,
2382 .open = em28xx_v4l2_open,
2383 .release = em28xx_v4l2_close,
2384 .read = em28xx_v4l2_read,
2385 .poll = em28xx_v4l2_poll,
2386 .mmap = em28xx_v4l2_mmap,
2387 .unlocked_ioctl = video_ioctl2,
2390 static const struct v4l2_ioctl_ops video_ioctl_ops = {
2391 .vidioc_querycap = vidioc_querycap,
2392 .vidioc_enum_fmt_vid_cap = vidioc_enum_fmt_vid_cap,
2393 .vidioc_g_fmt_vid_cap = vidioc_g_fmt_vid_cap,
2394 .vidioc_try_fmt_vid_cap = vidioc_try_fmt_vid_cap,
2395 .vidioc_s_fmt_vid_cap = vidioc_s_fmt_vid_cap,
2396 .vidioc_g_fmt_vbi_cap = vidioc_g_fmt_vbi_cap,
2397 .vidioc_s_fmt_vbi_cap = vidioc_s_fmt_vbi_cap,
2398 .vidioc_enum_framesizes = vidioc_enum_framesizes,
2399 .vidioc_g_audio = vidioc_g_audio,
2400 .vidioc_s_audio = vidioc_s_audio,
2401 .vidioc_cropcap = vidioc_cropcap,
2402 .vidioc_g_fmt_sliced_vbi_cap = vidioc_g_fmt_sliced_vbi_cap,
2403 .vidioc_try_fmt_sliced_vbi_cap = vidioc_try_set_sliced_vbi_cap,
2404 .vidioc_s_fmt_sliced_vbi_cap = vidioc_try_set_sliced_vbi_cap,
2406 .vidioc_reqbufs = vidioc_reqbufs,
2407 .vidioc_querybuf = vidioc_querybuf,
2408 .vidioc_qbuf = vidioc_qbuf,
2409 .vidioc_dqbuf = vidioc_dqbuf,
2410 .vidioc_g_std = vidioc_g_std,
2411 .vidioc_querystd = vidioc_querystd,
2412 .vidioc_s_std = vidioc_s_std,
2413 .vidioc_g_parm = vidioc_g_parm,
2414 .vidioc_s_parm = vidioc_s_parm,
2415 .vidioc_enum_input = vidioc_enum_input,
2416 .vidioc_g_input = vidioc_g_input,
2417 .vidioc_s_input = vidioc_s_input,
2418 .vidioc_queryctrl = vidioc_queryctrl,
2419 .vidioc_g_ctrl = vidioc_g_ctrl,
2420 .vidioc_s_ctrl = vidioc_s_ctrl,
2421 .vidioc_streamon = vidioc_streamon,
2422 .vidioc_streamoff = vidioc_streamoff,
2423 .vidioc_g_tuner = vidioc_g_tuner,
2424 .vidioc_s_tuner = vidioc_s_tuner,
2425 .vidioc_g_frequency = vidioc_g_frequency,
2426 .vidioc_s_frequency = vidioc_s_frequency,
2427 #ifdef CONFIG_VIDEO_ADV_DEBUG
2428 .vidioc_g_register = vidioc_g_register,
2429 .vidioc_s_register = vidioc_s_register,
2430 .vidioc_g_chip_ident = vidioc_g_chip_ident,
2434 static const struct video_device em28xx_video_template = {
2435 .fops = &em28xx_v4l_fops,
2436 .release = video_device_release,
2437 .ioctl_ops = &video_ioctl_ops,
2439 .tvnorms = V4L2_STD_ALL,
2440 .current_norm = V4L2_STD_PAL,
2443 static const struct v4l2_file_operations radio_fops = {
2444 .owner = THIS_MODULE,
2445 .open = em28xx_v4l2_open,
2446 .release = em28xx_v4l2_close,
2447 .unlocked_ioctl = video_ioctl2,
2450 static const struct v4l2_ioctl_ops radio_ioctl_ops = {
2451 .vidioc_querycap = radio_querycap,
2452 .vidioc_g_tuner = radio_g_tuner,
2453 .vidioc_enum_input = radio_enum_input,
2454 .vidioc_g_audio = radio_g_audio,
2455 .vidioc_s_tuner = radio_s_tuner,
2456 .vidioc_s_audio = radio_s_audio,
2457 .vidioc_s_input = radio_s_input,
2458 .vidioc_queryctrl = radio_queryctrl,
2459 .vidioc_g_ctrl = vidioc_g_ctrl,
2460 .vidioc_s_ctrl = vidioc_s_ctrl,
2461 .vidioc_g_frequency = vidioc_g_frequency,
2462 .vidioc_s_frequency = vidioc_s_frequency,
2463 #ifdef CONFIG_VIDEO_ADV_DEBUG
2464 .vidioc_g_register = vidioc_g_register,
2465 .vidioc_s_register = vidioc_s_register,
2469 static struct video_device em28xx_radio_template = {
2470 .name = "em28xx-radio",
2471 .fops = &radio_fops,
2472 .ioctl_ops = &radio_ioctl_ops,
2475 /******************************** usb interface ******************************/
2479 static struct video_device *em28xx_vdev_init(struct em28xx *dev,
2480 const struct video_device *template,
2481 const char *type_name)
2483 struct video_device *vfd;
2485 vfd = video_device_alloc();
2490 vfd->v4l2_dev = &dev->v4l2_dev;
2491 vfd->release = video_device_release;
2492 vfd->debug = video_debug;
2493 vfd->lock = &dev->lock;
2495 snprintf(vfd->name, sizeof(vfd->name), "%s %s",
2496 dev->name, type_name);
2498 video_set_drvdata(vfd, dev);
2502 int em28xx_register_analog_devices(struct em28xx *dev)
2507 printk(KERN_INFO "%s: v4l2 driver version %s\n",
2508 dev->name, EM28XX_VERSION);
2510 /* set default norm */
2511 dev->norm = em28xx_video_template.current_norm;
2512 v4l2_device_call_all(&dev->v4l2_dev, 0, core, s_std, dev->norm);
2513 dev->interlaced = EM28XX_INTERLACED_DEFAULT;
2516 /* Analog specific initialization */
2517 dev->format = &format[0];
2518 em28xx_set_video_format(dev, format[0].fourcc,
2519 norm_maxw(dev), norm_maxh(dev));
2521 video_mux(dev, dev->ctl_input);
2523 /* Audio defaults */
2527 /* em28xx_write_reg(dev, EM28XX_R0E_AUDIOSRC, 0xc0); audio register */
2528 val = (u8)em28xx_read_reg(dev, EM28XX_R0F_XCLK);
2529 em28xx_write_reg(dev, EM28XX_R0F_XCLK,
2530 (EM28XX_XCLK_AUDIO_UNMUTE | val));
2532 em28xx_set_outfmt(dev);
2533 em28xx_colorlevels_set_default(dev);
2534 em28xx_compression_disable(dev);
2536 /* allocate and fill video video_device struct */
2537 dev->vdev = em28xx_vdev_init(dev, &em28xx_video_template, "video");
2539 em28xx_errdev("cannot allocate video_device.\n");
2543 /* register v4l2 video video_device */
2544 ret = video_register_device(dev->vdev, VFL_TYPE_GRABBER,
2545 video_nr[dev->devno]);
2547 em28xx_errdev("unable to register video device (error=%i).\n",
2552 /* Allocate and fill vbi video_device struct */
2553 if (em28xx_vbi_supported(dev) == 1) {
2554 dev->vbi_dev = em28xx_vdev_init(dev, &em28xx_video_template,
2557 /* register v4l2 vbi video_device */
2558 ret = video_register_device(dev->vbi_dev, VFL_TYPE_VBI,
2559 vbi_nr[dev->devno]);
2561 em28xx_errdev("unable to register vbi device\n");
2566 if (em28xx_boards[dev->model].radio.type == EM28XX_RADIO) {
2567 dev->radio_dev = em28xx_vdev_init(dev, &em28xx_radio_template,
2569 if (!dev->radio_dev) {
2570 em28xx_errdev("cannot allocate video_device.\n");
2573 ret = video_register_device(dev->radio_dev, VFL_TYPE_RADIO,
2574 radio_nr[dev->devno]);
2576 em28xx_errdev("can't register radio device\n");
2579 em28xx_info("Registered radio device as %s\n",
2580 video_device_node_name(dev->radio_dev));
2583 em28xx_info("V4L2 video device registered as %s\n",
2584 video_device_node_name(dev->vdev));
2587 em28xx_info("V4L2 VBI device registered as %s\n",
2588 video_device_node_name(dev->vbi_dev));