blob: ff37b4c15f444e43c54034622113384ac8f498e0 [file] [log] [blame]
akpm@osdl.orga6c2ba22005-11-08 21:37:07 -08001/*
Douglas Schilling Landgraf6ea54d92008-04-17 21:41:10 -03002 em28xx-video.c - driver for Empia EM2800/EM2820/2840 USB
3 video capture devices
akpm@osdl.orga6c2ba22005-11-08 21:37:07 -08004
Mauro Carvalho Chehabf7abcd32005-11-08 21:38:25 -08005 Copyright (C) 2005 Ludovico Cavedon <cavedon@sssup.it>
6 Markus Rechberger <mrechberger@gmail.com>
Mauro Carvalho Chehab2e7c6dc2006-04-03 07:53:40 -03007 Mauro Carvalho Chehab <mchehab@infradead.org>
Mauro Carvalho Chehabf7abcd32005-11-08 21:38:25 -08008 Sascha Sommer <saschasommer@freenet.de>
akpm@osdl.orga6c2ba22005-11-08 21:37:07 -08009
Mauro Carvalho Chehab439090d2006-01-23 17:10:54 -020010 Some parts based on SN9C10x PC Camera Controllers GPL driver made
11 by Luca Risolia <luca.risolia@studio.unibo.it>
12
akpm@osdl.orga6c2ba22005-11-08 21:37:07 -080013 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.
17
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.
22
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.
26 */
27
28#include <linux/init.h>
29#include <linux/list.h>
30#include <linux/module.h>
31#include <linux/kernel.h>
Mauro Carvalho Chehabe5589be2006-01-23 17:11:08 -020032#include <linux/bitmap.h>
akpm@osdl.orga6c2ba22005-11-08 21:37:07 -080033#include <linux/usb.h>
akpm@osdl.orga6c2ba22005-11-08 21:37:07 -080034#include <linux/i2c.h>
Mauro Carvalho Chehabb296fc62005-11-08 21:38:37 -080035#include <linux/version.h>
Trent Piepho6d35c8f2007-11-01 01:16:09 -030036#include <linux/mm.h>
Ingo Molnar1e4baed2006-01-15 07:52:23 -020037#include <linux/mutex.h>
akpm@osdl.orga6c2ba22005-11-08 21:37:07 -080038
Mauro Carvalho Chehabf7abcd32005-11-08 21:38:25 -080039#include "em28xx.h"
Mauro Carvalho Chehabc0477ad2006-01-09 15:25:14 -020040#include <media/v4l2-common.h>
Hans Verkuil35ea11f2008-07-20 08:12:02 -030041#include <media/v4l2-ioctl.h>
Mauro Carvalho Chehab14983d82008-12-22 20:58:41 -030042#include <media/v4l2-chip-ident.h>
Hans Verkuil2474ed42006-03-19 12:35:57 -030043#include <media/msp3400.h>
Mauro Carvalho Chehabed086312008-01-24 06:59:20 -030044#include <media/tuner.h>
akpm@osdl.orga6c2ba22005-11-08 21:37:07 -080045
Mauro Carvalho Chehabf7abcd32005-11-08 21:38:25 -080046#define DRIVER_AUTHOR "Ludovico Cavedon <cavedon@sssup.it>, " \
47 "Markus Rechberger <mrechberger@gmail.com>, " \
Mauro Carvalho Chehab2e7c6dc2006-04-03 07:53:40 -030048 "Mauro Carvalho Chehab <mchehab@infradead.org>, " \
Mauro Carvalho Chehabf7abcd32005-11-08 21:38:25 -080049 "Sascha Sommer <saschasommer@freenet.de>"
akpm@osdl.orga6c2ba22005-11-08 21:37:07 -080050
Mauro Carvalho Chehabf7abcd32005-11-08 21:38:25 -080051#define DRIVER_DESC "Empia em28xx based USB video device driver"
Douglas Schilling Landgraff2cf2502009-03-31 17:10:58 -030052#define EM28XX_VERSION_CODE KERNEL_VERSION(0, 1, 2)
akpm@osdl.orga6c2ba22005-11-08 21:37:07 -080053
Mauro Carvalho Chehab3acf2802005-11-08 21:38:27 -080054#define em28xx_videodbg(fmt, arg...) do {\
Mauro Carvalho Chehab4ac97912005-11-08 21:37:43 -080055 if (video_debug) \
56 printk(KERN_INFO "%s %s :"fmt, \
Harvey Harrisond80e1342008-04-08 23:20:00 -030057 dev->name, __func__ , ##arg); } while (0)
akpm@osdl.orga6c2ba22005-11-08 21:37:07 -080058
Mauro Carvalho Chehabad0ebb92008-04-13 14:37:52 -030059static unsigned int isoc_debug;
Mauro Carvalho Chehabf245e542008-04-13 14:41:23 -030060module_param(isoc_debug, int, 0644);
61MODULE_PARM_DESC(isoc_debug, "enable debug messages [isoc transfers]");
Mauro Carvalho Chehabad0ebb92008-04-13 14:37:52 -030062
Douglas Schilling Landgraf6ea54d92008-04-17 21:41:10 -030063#define em28xx_isocdbg(fmt, arg...) \
64do {\
65 if (isoc_debug) { \
Mauro Carvalho Chehabad0ebb92008-04-13 14:37:52 -030066 printk(KERN_INFO "%s %s :"fmt, \
Douglas Schilling Landgraf6ea54d92008-04-17 21:41:10 -030067 dev->name, __func__ , ##arg); \
68 } \
69 } while (0)
Mauro Carvalho Chehabad0ebb92008-04-13 14:37:52 -030070
akpm@osdl.orga6c2ba22005-11-08 21:37:07 -080071MODULE_AUTHOR(DRIVER_AUTHOR);
72MODULE_DESCRIPTION(DRIVER_DESC);
73MODULE_LICENSE("GPL");
74
Mauro Carvalho Chehabe5589be2006-01-23 17:11:08 -020075static unsigned int video_nr[] = {[0 ... (EM28XX_MAXBOARDS - 1)] = UNSET };
Mauro Carvalho Chehab0be43752008-01-05 17:22:01 -030076static unsigned int vbi_nr[] = {[0 ... (EM28XX_MAXBOARDS - 1)] = UNSET };
77static unsigned int radio_nr[] = {[0 ... (EM28XX_MAXBOARDS - 1)] = UNSET };
78
Mauro Carvalho Chehabe5589be2006-01-23 17:11:08 -020079module_param_array(video_nr, int, NULL, 0444);
80module_param_array(vbi_nr, int, NULL, 0444);
Mauro Carvalho Chehab0be43752008-01-05 17:22:01 -030081module_param_array(radio_nr, int, NULL, 0444);
Mauro Carvalho Chehab0be43752008-01-05 17:22:01 -030082MODULE_PARM_DESC(video_nr, "video device numbers");
83MODULE_PARM_DESC(vbi_nr, "vbi device numbers");
84MODULE_PARM_DESC(radio_nr, "radio device numbers");
Mauro Carvalho Chehab596d92d2005-11-08 21:37:24 -080085
Douglas Schilling Landgrafff699e62008-04-22 14:41:48 -030086static unsigned int video_debug;
Douglas Schilling Landgraf6ea54d92008-04-17 21:41:10 -030087module_param(video_debug, int, 0644);
88MODULE_PARM_DESC(video_debug, "enable debug messages [video]");
akpm@osdl.orga6c2ba22005-11-08 21:37:07 -080089
Mauro Carvalho Chehabbddcf632008-12-20 09:06:37 -030090/* supported video standards */
91static struct em28xx_fmt format[] = {
92 {
Mauro Carvalho Chehab58fc1ce2009-07-03 02:54:18 -030093 .name = "16 bpp YUY2, 4:2:2, packed",
Mauro Carvalho Chehabbddcf632008-12-20 09:06:37 -030094 .fourcc = V4L2_PIX_FMT_YUYV,
95 .depth = 16,
Devin Heitmueller3fbf9302008-12-29 23:34:37 -030096 .reg = EM28XX_OUTFMT_YUV422_Y0UY1V,
Mauro Carvalho Chehab43cb9fe2009-06-30 08:36:17 -030097 }, {
Mauro Carvalho Chehab58fc1ce2009-07-03 02:54:18 -030098 .name = "16 bpp RGB 565, LE",
Mauro Carvalho Chehab43cb9fe2009-06-30 08:36:17 -030099 .fourcc = V4L2_PIX_FMT_RGB565,
100 .depth = 16,
Mauro Carvalho Chehab58fc1ce2009-07-03 02:54:18 -0300101 .reg = EM28XX_OUTFMT_RGB_16_656,
102 }, {
103 .name = "8 bpp Bayer BGBG..GRGR",
104 .fourcc = V4L2_PIX_FMT_SBGGR8,
105 .depth = 8,
106 .reg = EM28XX_OUTFMT_RGB_8_BGBG,
107 }, {
108 .name = "8 bpp Bayer GRGR..BGBG",
109 .fourcc = V4L2_PIX_FMT_SGRBG8,
110 .depth = 8,
111 .reg = EM28XX_OUTFMT_RGB_8_GRGR,
112 }, {
113 .name = "8 bpp Bayer GBGB..RGRG",
114 .fourcc = V4L2_PIX_FMT_SGBRG8,
115 .depth = 8,
116 .reg = EM28XX_OUTFMT_RGB_8_GBGB,
117 }, {
118 .name = "12 bpp YUV411",
119 .fourcc = V4L2_PIX_FMT_YUV411P,
120 .depth = 12,
121 .reg = EM28XX_OUTFMT_YUV411,
Mauro Carvalho Chehabbddcf632008-12-20 09:06:37 -0300122 },
123};
124
akpm@osdl.orga6c2ba22005-11-08 21:37:07 -0800125/* supported controls */
Mauro Carvalho Chehabc0477ad2006-01-09 15:25:14 -0200126/* Common to all boards */
Mauro Carvalho Chehab3acf2802005-11-08 21:38:27 -0800127static struct v4l2_queryctrl em28xx_qctrl[] = {
akpm@osdl.orga6c2ba22005-11-08 21:37:07 -0800128 {
Mauro Carvalho Chehabc0477ad2006-01-09 15:25:14 -0200129 .id = V4L2_CID_AUDIO_VOLUME,
130 .type = V4L2_CTRL_TYPE_INTEGER,
131 .name = "Volume",
132 .minimum = 0x0,
133 .maximum = 0x1f,
134 .step = 0x1,
135 .default_value = 0x1f,
136 .flags = 0,
Douglas Schilling Landgraf6ea54d92008-04-17 21:41:10 -0300137 }, {
Mauro Carvalho Chehabc0477ad2006-01-09 15:25:14 -0200138 .id = V4L2_CID_AUDIO_MUTE,
139 .type = V4L2_CTRL_TYPE_BOOLEAN,
140 .name = "Mute",
141 .minimum = 0,
142 .maximum = 1,
143 .step = 1,
144 .default_value = 1,
145 .flags = 0,
146 }
147};
148
Mauro Carvalho Chehabad0ebb92008-04-13 14:37:52 -0300149/* ------------------------------------------------------------------
150 DMA and thread functions
151 ------------------------------------------------------------------*/
152
153/*
154 * Announces that a buffer were filled and request the next
155 */
Mauro Carvalho Chehabf245e542008-04-13 14:41:23 -0300156static inline void buffer_filled(struct em28xx *dev,
Mauro Carvalho Chehabad0ebb92008-04-13 14:37:52 -0300157 struct em28xx_dmaqueue *dma_q,
158 struct em28xx_buffer *buf)
159{
Mauro Carvalho Chehabad0ebb92008-04-13 14:37:52 -0300160 /* 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);
165
Mauro Carvalho Chehabcb784722008-04-13 15:06:52 -0300166 dev->isoc_ctl.buf = NULL;
167
Mauro Carvalho Chehabad0ebb92008-04-13 14:37:52 -0300168 list_del(&buf->vb.queue);
169 wake_up(&buf->vb.done);
170}
171
172/*
173 * Identify the buffer header type and properly handles
174 */
175static void em28xx_copy_video(struct em28xx *dev,
176 struct em28xx_dmaqueue *dma_q,
177 struct em28xx_buffer *buf,
178 unsigned char *p,
179 unsigned char *outp, unsigned long len)
180{
181 void *fieldstart, *startwrite, *startread;
Mauro Carvalho Chehabf245e542008-04-13 14:41:23 -0300182 int linesdone, currlinedone, offset, lencopy, remain;
Mauro Carvalho Chehab44dc7332008-04-13 15:11:08 -0300183 int bytesperline = dev->width << 1;
Mauro Carvalho Chehabad0ebb92008-04-13 14:37:52 -0300184
185 if (dma_q->pos + len > buf->vb.size)
186 len = buf->vb.size - dma_q->pos;
187
Aidan Thorntond7aa8022008-04-13 14:38:47 -0300188 if (p[0] != 0x88 && p[0] != 0x22) {
Mauro Carvalho Chehabad0ebb92008-04-13 14:37:52 -0300189 em28xx_isocdbg("frame is not complete\n");
190 len += 4;
191 } else
Mauro Carvalho Chehabf245e542008-04-13 14:41:23 -0300192 p += 4;
Mauro Carvalho Chehabad0ebb92008-04-13 14:37:52 -0300193
194 startread = p;
195 remain = len;
196
197 /* Interlaces frame */
198 if (buf->top_field)
199 fieldstart = outp;
200 else
Mauro Carvalho Chehab44dc7332008-04-13 15:11:08 -0300201 fieldstart = outp + bytesperline;
Mauro Carvalho Chehabad0ebb92008-04-13 14:37:52 -0300202
Mauro Carvalho Chehab44dc7332008-04-13 15:11:08 -0300203 linesdone = dma_q->pos / bytesperline;
204 currlinedone = dma_q->pos % bytesperline;
205 offset = linesdone * bytesperline * 2 + currlinedone;
Mauro Carvalho Chehabad0ebb92008-04-13 14:37:52 -0300206 startwrite = fieldstart + offset;
Mauro Carvalho Chehab44dc7332008-04-13 15:11:08 -0300207 lencopy = bytesperline - currlinedone;
Mauro Carvalho Chehabad0ebb92008-04-13 14:37:52 -0300208 lencopy = lencopy > remain ? remain : lencopy;
209
Mauro Carvalho Chehabf245e542008-04-13 14:41:23 -0300210 if ((char *)startwrite + lencopy > (char *)outp + buf->vb.size) {
Mauro Carvalho Chehabea8df7e2008-04-13 14:39:29 -0300211 em28xx_isocdbg("Overflow of %zi bytes past buffer end (1)\n",
Mauro Carvalho Chehabf245e542008-04-13 14:41:23 -0300212 ((char *)startwrite + lencopy) -
213 ((char *)outp + buf->vb.size));
Nicola Soranzoa1a6ee72009-02-10 23:28:24 -0300214 remain = (char *)outp + buf->vb.size - (char *)startwrite;
215 lencopy = remain;
Aidan Thorntond7aa8022008-04-13 14:38:47 -0300216 }
Aidan Thorntone0fadfd2008-04-13 14:56:02 -0300217 if (lencopy <= 0)
218 return;
Aidan Thorntond7aa8022008-04-13 14:38:47 -0300219 memcpy(startwrite, startread, lencopy);
Mauro Carvalho Chehabad0ebb92008-04-13 14:37:52 -0300220
221 remain -= lencopy;
222
223 while (remain > 0) {
Mauro Carvalho Chehab44dc7332008-04-13 15:11:08 -0300224 startwrite += lencopy + bytesperline;
Mauro Carvalho Chehabad0ebb92008-04-13 14:37:52 -0300225 startread += lencopy;
Mauro Carvalho Chehab44dc7332008-04-13 15:11:08 -0300226 if (bytesperline > remain)
Mauro Carvalho Chehabad0ebb92008-04-13 14:37:52 -0300227 lencopy = remain;
228 else
Mauro Carvalho Chehab44dc7332008-04-13 15:11:08 -0300229 lencopy = bytesperline;
Mauro Carvalho Chehabad0ebb92008-04-13 14:37:52 -0300230
Nicola Soranzoa1a6ee72009-02-10 23:28:24 -0300231 if ((char *)startwrite + lencopy > (char *)outp +
232 buf->vb.size) {
Mauro Carvalho Chehabea8df7e2008-04-13 14:39:29 -0300233 em28xx_isocdbg("Overflow of %zi bytes past buffer end (2)\n",
Mauro Carvalho Chehabf245e542008-04-13 14:41:23 -0300234 ((char *)startwrite + lencopy) -
235 ((char *)outp + buf->vb.size));
236 lencopy = remain = (char *)outp + buf->vb.size -
237 (char *)startwrite;
Aidan Thorntond7aa8022008-04-13 14:38:47 -0300238 }
Mauro Carvalho Chehabf245e542008-04-13 14:41:23 -0300239 if (lencopy <= 0)
240 break;
Aidan Thorntond7aa8022008-04-13 14:38:47 -0300241
242 memcpy(startwrite, startread, lencopy);
Mauro Carvalho Chehabad0ebb92008-04-13 14:37:52 -0300243
244 remain -= lencopy;
245 }
246
247 dma_q->pos += len;
248}
249
Mauro Carvalho Chehabf245e542008-04-13 14:41:23 -0300250static inline void print_err_status(struct em28xx *dev,
Mauro Carvalho Chehabad0ebb92008-04-13 14:37:52 -0300251 int packet, int status)
252{
253 char *errmsg = "Unknown";
254
Mauro Carvalho Chehabf245e542008-04-13 14:41:23 -0300255 switch (status) {
Mauro Carvalho Chehabad0ebb92008-04-13 14:37:52 -0300256 case -ENOENT:
257 errmsg = "unlinked synchronuously";
258 break;
259 case -ECONNRESET:
260 errmsg = "unlinked asynchronuously";
261 break;
262 case -ENOSR:
263 errmsg = "Buffer error (overrun)";
264 break;
265 case -EPIPE:
266 errmsg = "Stalled (device not responding)";
267 break;
268 case -EOVERFLOW:
269 errmsg = "Babble (bad cable?)";
270 break;
271 case -EPROTO:
272 errmsg = "Bit-stuff error (bad cable?)";
273 break;
274 case -EILSEQ:
275 errmsg = "CRC/Timeout (could be anything)";
276 break;
277 case -ETIME:
278 errmsg = "Device does not respond";
279 break;
280 }
Mauro Carvalho Chehabf245e542008-04-13 14:41:23 -0300281 if (packet < 0) {
Mauro Carvalho Chehabad0ebb92008-04-13 14:37:52 -0300282 em28xx_isocdbg("URB status %d [%s].\n", status, errmsg);
283 } else {
284 em28xx_isocdbg("URB packet %d, status %d [%s].\n",
285 packet, status, errmsg);
286 }
287}
288
289/*
290 * video-buf generic routine to get the next available buffer
291 */
Aidan Thornton3b5fa922008-04-13 15:09:36 -0300292static inline void get_next_buf(struct em28xx_dmaqueue *dma_q,
Mauro Carvalho Chehabad0ebb92008-04-13 14:37:52 -0300293 struct em28xx_buffer **buf)
294{
295 struct em28xx *dev = container_of(dma_q, struct em28xx, vidq);
Mauro Carvalho Chehabdbecb442008-04-13 15:08:55 -0300296 char *outp;
Mauro Carvalho Chehabad0ebb92008-04-13 14:37:52 -0300297
Mauro Carvalho Chehabdbecb442008-04-13 15:08:55 -0300298 if (list_empty(&dma_q->active)) {
299 em28xx_isocdbg("No active queue to serve\n");
300 dev->isoc_ctl.buf = NULL;
Mauro Carvalho Chehabdbecb442008-04-13 15:08:55 -0300301 *buf = NULL;
Aidan Thornton3b5fa922008-04-13 15:09:36 -0300302 return;
Mauro Carvalho Chehabdbecb442008-04-13 15:08:55 -0300303 }
304
Mauro Carvalho Chehabdbecb442008-04-13 15:08:55 -0300305 /* Get the next buffer */
306 *buf = list_entry(dma_q->active.next, struct em28xx_buffer, vb.queue);
307
Mauro Carvalho Chehabdbecb442008-04-13 15:08:55 -0300308 /* Cleans up buffer - Usefull for testing for frame/URB loss */
309 outp = videobuf_to_vmalloc(&(*buf)->vb);
310 memset(outp, 0, (*buf)->vb.size);
Mauro Carvalho Chehabcb784722008-04-13 15:06:52 -0300311
312 dev->isoc_ctl.buf = *buf;
313
Aidan Thornton3b5fa922008-04-13 15:09:36 -0300314 return;
Mauro Carvalho Chehabad0ebb92008-04-13 14:37:52 -0300315}
316
317/*
318 * Controls the isoc copy of each urb packet
319 */
Aidan Thornton579f72e2008-04-17 21:40:16 -0300320static inline int em28xx_isoc_copy(struct em28xx *dev, struct urb *urb)
Mauro Carvalho Chehabad0ebb92008-04-13 14:37:52 -0300321{
Aidan Thorntond7aa8022008-04-13 14:38:47 -0300322 struct em28xx_buffer *buf;
Mauro Carvalho Chehabad0ebb92008-04-13 14:37:52 -0300323 struct em28xx_dmaqueue *dma_q = urb->context;
Aidan Thornton3b5fa922008-04-13 15:09:36 -0300324 unsigned char *outp = NULL;
Mauro Carvalho Chehabad0ebb92008-04-13 14:37:52 -0300325 int i, len = 0, rc = 1;
Aidan Thorntond7aa8022008-04-13 14:38:47 -0300326 unsigned char *p;
Mauro Carvalho Chehabad0ebb92008-04-13 14:37:52 -0300327
328 if (!dev)
329 return 0;
330
331 if ((dev->state & DEV_DISCONNECTED) || (dev->state & DEV_MISCONFIGURED))
332 return 0;
333
Mauro Carvalho Chehabf245e542008-04-13 14:41:23 -0300334 if (urb->status < 0) {
335 print_err_status(dev, -1, urb->status);
Mauro Carvalho Chehabad0ebb92008-04-13 14:37:52 -0300336 if (urb->status == -ENOENT)
337 return 0;
338 }
339
Aidan Thornton3b5fa922008-04-13 15:09:36 -0300340 buf = dev->isoc_ctl.buf;
341 if (buf != NULL)
342 outp = videobuf_to_vmalloc(&buf->vb);
Aidan Thorntond7aa8022008-04-13 14:38:47 -0300343
Mauro Carvalho Chehabad0ebb92008-04-13 14:37:52 -0300344 for (i = 0; i < urb->number_of_packets; i++) {
345 int status = urb->iso_frame_desc[i].status;
346
Mauro Carvalho Chehabf245e542008-04-13 14:41:23 -0300347 if (status < 0) {
348 print_err_status(dev, i, status);
Mauro Carvalho Chehabad0ebb92008-04-13 14:37:52 -0300349 if (urb->iso_frame_desc[i].status != -EPROTO)
350 continue;
351 }
352
Mauro Carvalho Chehabf245e542008-04-13 14:41:23 -0300353 len = urb->iso_frame_desc[i].actual_length - 4;
Mauro Carvalho Chehabad0ebb92008-04-13 14:37:52 -0300354
355 if (urb->iso_frame_desc[i].actual_length <= 0) {
Aidan Thorntond7aa8022008-04-13 14:38:47 -0300356 /* em28xx_isocdbg("packet %d is empty",i); - spammy */
Mauro Carvalho Chehabad0ebb92008-04-13 14:37:52 -0300357 continue;
358 }
359 if (urb->iso_frame_desc[i].actual_length >
360 dev->max_pkt_size) {
361 em28xx_isocdbg("packet bigger than packet size");
362 continue;
363 }
364
365 p = urb->transfer_buffer + urb->iso_frame_desc[i].offset;
Mauro Carvalho Chehabad0ebb92008-04-13 14:37:52 -0300366
367 /* FIXME: incomplete buffer checks where removed to make
368 logic simpler. Impacts of those changes should be evaluated
369 */
Mauro Carvalho Chehabb4916f82008-04-13 15:09:14 -0300370 if (p[0] == 0x33 && p[1] == 0x95 && p[2] == 0x00) {
371 em28xx_isocdbg("VBI HEADER!!!\n");
372 /* FIXME: Should add vbi copy */
373 continue;
374 }
Aidan Thorntond7aa8022008-04-13 14:38:47 -0300375 if (p[0] == 0x22 && p[1] == 0x5a) {
Mauro Carvalho Chehab78bb3942008-04-13 14:56:25 -0300376 em28xx_isocdbg("Video frame %d, length=%i, %s\n", p[2],
Nicola Soranzoa1a6ee72009-02-10 23:28:24 -0300377 len, (p[2] & 1) ? "odd" : "even");
Mauro Carvalho Chehabad0ebb92008-04-13 14:37:52 -0300378
Aidan Thornton3b5fa922008-04-13 15:09:36 -0300379 if (!(p[2] & 1)) {
380 if (buf != NULL)
381 buffer_filled(dev, dma_q, buf);
382 get_next_buf(dma_q, &buf);
383 if (buf == NULL)
384 outp = NULL;
385 else
386 outp = videobuf_to_vmalloc(&buf->vb);
Aidan Thorntone0fadfd2008-04-13 14:56:02 -0300387 }
Aidan Thornton3b5fa922008-04-13 15:09:36 -0300388
389 if (buf != NULL) {
390 if (p[2] & 1)
391 buf->top_field = 0;
392 else
393 buf->top_field = 1;
394 }
Mauro Carvalho Chehabb4916f82008-04-13 15:09:14 -0300395
Mauro Carvalho Chehabad0ebb92008-04-13 14:37:52 -0300396 dma_q->pos = 0;
Mauro Carvalho Chehabad0ebb92008-04-13 14:37:52 -0300397 }
Aidan Thornton3b5fa922008-04-13 15:09:36 -0300398 if (buf != NULL)
399 em28xx_copy_video(dev, dma_q, buf, p, outp, len);
Mauro Carvalho Chehabad0ebb92008-04-13 14:37:52 -0300400 }
401 return rc;
402}
403
404/* ------------------------------------------------------------------
Mauro Carvalho Chehabad0ebb92008-04-13 14:37:52 -0300405 Videobuf operations
406 ------------------------------------------------------------------*/
407
408static int
409buffer_setup(struct videobuf_queue *vq, unsigned int *count, unsigned int *size)
410{
411 struct em28xx_fh *fh = vq->priv_data;
Mauro Carvalho Chehabd2d9fbf2008-04-17 21:38:53 -0300412 struct em28xx *dev = fh->dev;
413 struct v4l2_frequency f;
Mauro Carvalho Chehabad0ebb92008-04-13 14:37:52 -0300414
Mauro Carvalho Chehabbddcf632008-12-20 09:06:37 -0300415 *size = (fh->dev->width * fh->dev->height * dev->format->depth + 7) >> 3;
416
Mauro Carvalho Chehabad0ebb92008-04-13 14:37:52 -0300417 if (0 == *count)
418 *count = EM28XX_DEF_BUF;
419
Mauro Carvalho Chehabf245e542008-04-13 14:41:23 -0300420 if (*count < EM28XX_MIN_BUF)
421 *count = EM28XX_MIN_BUF;
Mauro Carvalho Chehabad0ebb92008-04-13 14:37:52 -0300422
Mauro Carvalho Chehab381aaba2008-12-20 07:43:34 -0300423 /* Ask tuner to go to analog or radio mode */
Douglas Schilling Landgraf6ea54d92008-04-17 21:41:10 -0300424 memset(&f, 0, sizeof(f));
Mauro Carvalho Chehabd2d9fbf2008-04-17 21:38:53 -0300425 f.frequency = dev->ctl_freq;
Mauro Carvalho Chehab381aaba2008-12-20 07:43:34 -0300426 f.type = fh->radio ? V4L2_TUNER_RADIO : V4L2_TUNER_ANALOG_TV;
Mauro Carvalho Chehabd2d9fbf2008-04-17 21:38:53 -0300427
Douglas Schilling Landgraff2cf2502009-03-31 17:10:58 -0300428 v4l2_device_call_all(&dev->v4l2_dev, 0, tuner, s_frequency, &f);
Mauro Carvalho Chehabd2d9fbf2008-04-17 21:38:53 -0300429
Mauro Carvalho Chehabad0ebb92008-04-13 14:37:52 -0300430 return 0;
431}
432
Aidan Thornton3b5fa922008-04-13 15:09:36 -0300433/* This is called *without* dev->slock held; please keep it that way */
Mauro Carvalho Chehabad0ebb92008-04-13 14:37:52 -0300434static void free_buffer(struct videobuf_queue *vq, struct em28xx_buffer *buf)
435{
Aidan Thornton3b5fa922008-04-13 15:09:36 -0300436 struct em28xx_fh *fh = vq->priv_data;
437 struct em28xx *dev = fh->dev;
438 unsigned long flags = 0;
Mauro Carvalho Chehabad0ebb92008-04-13 14:37:52 -0300439 if (in_interrupt())
440 BUG();
441
Aidan Thornton3b5fa922008-04-13 15:09:36 -0300442 /* We used to wait for the buffer to finish here, but this didn't work
443 because, as we were keeping the state as VIDEOBUF_QUEUED,
444 videobuf_queue_cancel marked it as finished for us.
445 (Also, it could wedge forever if the hardware was misconfigured.)
446
447 This should be safe; by the time we get here, the buffer isn't
448 queued anymore. If we ever start marking the buffers as
449 VIDEOBUF_ACTIVE, it won't be, though.
450 */
451 spin_lock_irqsave(&dev->slock, flags);
452 if (dev->isoc_ctl.buf == buf)
453 dev->isoc_ctl.buf = NULL;
454 spin_unlock_irqrestore(&dev->slock, flags);
455
Mauro Carvalho Chehabad0ebb92008-04-13 14:37:52 -0300456 videobuf_vmalloc_free(&buf->vb);
457 buf->vb.state = VIDEOBUF_NEEDS_INIT;
458}
459
460static int
461buffer_prepare(struct videobuf_queue *vq, struct videobuf_buffer *vb,
462 enum v4l2_field field)
463{
464 struct em28xx_fh *fh = vq->priv_data;
Mauro Carvalho Chehabf245e542008-04-13 14:41:23 -0300465 struct em28xx_buffer *buf = container_of(vb, struct em28xx_buffer, vb);
Mauro Carvalho Chehabad0ebb92008-04-13 14:37:52 -0300466 struct em28xx *dev = fh->dev;
467 int rc = 0, urb_init = 0;
Mauro Carvalho Chehabad0ebb92008-04-13 14:37:52 -0300468
Mauro Carvalho Chehabbddcf632008-12-20 09:06:37 -0300469 buf->vb.size = (fh->dev->width * fh->dev->height * dev->format->depth + 7) >> 3;
Mauro Carvalho Chehabad0ebb92008-04-13 14:37:52 -0300470
471 if (0 != buf->vb.baddr && buf->vb.bsize < buf->vb.size)
472 return -EINVAL;
473
Brandon Philips05612972008-04-13 14:57:01 -0300474 buf->vb.width = dev->width;
475 buf->vb.height = dev->height;
476 buf->vb.field = field;
Mauro Carvalho Chehabad0ebb92008-04-13 14:37:52 -0300477
478 if (VIDEOBUF_NEEDS_INIT == buf->vb.state) {
Aidan Thorntond7aa8022008-04-13 14:38:47 -0300479 rc = videobuf_iolock(vq, &buf->vb, NULL);
480 if (rc < 0)
Mauro Carvalho Chehabad0ebb92008-04-13 14:37:52 -0300481 goto fail;
Mauro Carvalho Chehabad0ebb92008-04-13 14:37:52 -0300482 }
483
Mauro Carvalho Chehabad0ebb92008-04-13 14:37:52 -0300484 if (!dev->isoc_ctl.num_bufs)
Mauro Carvalho Chehabf245e542008-04-13 14:41:23 -0300485 urb_init = 1;
Mauro Carvalho Chehabad0ebb92008-04-13 14:37:52 -0300486
487 if (urb_init) {
Aidan Thornton579f72e2008-04-17 21:40:16 -0300488 rc = em28xx_init_isoc(dev, EM28XX_NUM_PACKETS,
489 EM28XX_NUM_BUFS, dev->max_pkt_size,
Mauro Carvalho Chehabc67ec532008-04-17 21:48:00 -0300490 em28xx_isoc_copy);
Mauro Carvalho Chehabf245e542008-04-13 14:41:23 -0300491 if (rc < 0)
Mauro Carvalho Chehabad0ebb92008-04-13 14:37:52 -0300492 goto fail;
493 }
494
495 buf->vb.state = VIDEOBUF_PREPARED;
496 return 0;
497
498fail:
Mauro Carvalho Chehabf245e542008-04-13 14:41:23 -0300499 free_buffer(vq, buf);
Mauro Carvalho Chehabad0ebb92008-04-13 14:37:52 -0300500 return rc;
501}
502
503static void
504buffer_queue(struct videobuf_queue *vq, struct videobuf_buffer *vb)
505{
Nicola Soranzoa1a6ee72009-02-10 23:28:24 -0300506 struct em28xx_buffer *buf = container_of(vb,
507 struct em28xx_buffer,
508 vb);
Mauro Carvalho Chehabad0ebb92008-04-13 14:37:52 -0300509 struct em28xx_fh *fh = vq->priv_data;
Mauro Carvalho Chehabf245e542008-04-13 14:41:23 -0300510 struct em28xx *dev = fh->dev;
Mauro Carvalho Chehabad0ebb92008-04-13 14:37:52 -0300511 struct em28xx_dmaqueue *vidq = &dev->vidq;
Mauro Carvalho Chehabad0ebb92008-04-13 14:37:52 -0300512
Aidan Thorntond7aa8022008-04-13 14:38:47 -0300513 buf->vb.state = VIDEOBUF_QUEUED;
514 list_add_tail(&buf->vb.queue, &vidq->active);
515
Mauro Carvalho Chehabad0ebb92008-04-13 14:37:52 -0300516}
517
Douglas Schilling Landgraf6ea54d92008-04-17 21:41:10 -0300518static void buffer_release(struct videobuf_queue *vq,
519 struct videobuf_buffer *vb)
Mauro Carvalho Chehabad0ebb92008-04-13 14:37:52 -0300520{
Nicola Soranzoa1a6ee72009-02-10 23:28:24 -0300521 struct em28xx_buffer *buf = container_of(vb,
522 struct em28xx_buffer,
523 vb);
Mauro Carvalho Chehabad0ebb92008-04-13 14:37:52 -0300524 struct em28xx_fh *fh = vq->priv_data;
Mauro Carvalho Chehabf245e542008-04-13 14:41:23 -0300525 struct em28xx *dev = (struct em28xx *)fh->dev;
Mauro Carvalho Chehabad0ebb92008-04-13 14:37:52 -0300526
Aidan Thorntond7aa8022008-04-13 14:38:47 -0300527 em28xx_isocdbg("em28xx: called buffer_release\n");
Mauro Carvalho Chehabad0ebb92008-04-13 14:37:52 -0300528
Mauro Carvalho Chehabf245e542008-04-13 14:41:23 -0300529 free_buffer(vq, buf);
Mauro Carvalho Chehabad0ebb92008-04-13 14:37:52 -0300530}
531
532static struct videobuf_queue_ops em28xx_video_qops = {
533 .buf_setup = buffer_setup,
534 .buf_prepare = buffer_prepare,
535 .buf_queue = buffer_queue,
536 .buf_release = buffer_release,
537};
akpm@osdl.orga6c2ba22005-11-08 21:37:07 -0800538
Douglas Schilling Landgraf6ea54d92008-04-17 21:41:10 -0300539/********************* v4l2 interface **************************************/
akpm@osdl.orga6c2ba22005-11-08 21:37:07 -0800540
Mauro Carvalho Chehabeac94352005-11-08 21:38:43 -0800541static void video_mux(struct em28xx *dev, int index)
542{
Mauro Carvalho Chehabeac94352005-11-08 21:38:43 -0800543 dev->ctl_input = index;
544 dev->ctl_ainput = INPUT(index)->amux;
Mauro Carvalho Chehab35ae6f02008-11-20 12:40:51 -0300545 dev->ctl_aoutput = INPUT(index)->aout;
Mauro Carvalho Chehabeac94352005-11-08 21:38:43 -0800546
Mauro Carvalho Chehabe879b8e2008-11-20 13:39:39 -0300547 if (!dev->ctl_aoutput)
548 dev->ctl_aoutput = EM28XX_AOUT_MASTER;
549
Hans Verkuil5325b422009-04-02 11:26:22 -0300550 v4l2_device_call_all(&dev->v4l2_dev, 0, video, s_routing,
551 INPUT(index)->vmux, 0, 0);
Mauro Carvalho Chehabeac94352005-11-08 21:38:43 -0800552
Mauro Carvalho Chehab505b6d02008-11-25 09:39:50 -0300553 if (dev->board.has_msp34xx) {
Douglas Schilling Landgraf6ea54d92008-04-17 21:41:10 -0300554 if (dev->i2s_speed) {
Douglas Schilling Landgraff2cf2502009-03-31 17:10:58 -0300555 v4l2_device_call_all(&dev->v4l2_dev, 0, audio,
556 s_i2s_clock_freq, dev->i2s_speed);
Douglas Schilling Landgraf6ea54d92008-04-17 21:41:10 -0300557 }
Hans Verkuil2474ed42006-03-19 12:35:57 -0300558 /* Note: this is msp3400 specific */
Hans Verkuil5325b422009-04-02 11:26:22 -0300559 v4l2_device_call_all(&dev->v4l2_dev, 0, audio, s_routing,
560 dev->ctl_ainput, MSP_OUTPUT(MSP_SC_IN_DSP_SCART1), 0);
Mauro Carvalho Chehabeac94352005-11-08 21:38:43 -0800561 }
Mauro Carvalho Chehab539c96d2008-01-05 09:53:54 -0300562
Vitaly Wool2bd1d9e2009-03-04 08:27:52 -0300563 if (dev->board.adecoder != EM28XX_NOADECODER) {
Hans Verkuil5325b422009-04-02 11:26:22 -0300564 v4l2_device_call_all(&dev->v4l2_dev, 0, audio, s_routing,
565 dev->ctl_ainput, dev->ctl_aoutput, 0);
Vitaly Wool2bd1d9e2009-03-04 08:27:52 -0300566 }
567
Mauro Carvalho Chehab00b87302008-02-06 18:34:13 -0300568 em28xx_audio_analog_set(dev);
Mauro Carvalho Chehabeac94352005-11-08 21:38:43 -0800569}
570
Mauro Carvalho Chehaba2254522007-11-11 01:08:26 -0300571/* Usage lock check functions */
572static int res_get(struct em28xx_fh *fh)
573{
574 struct em28xx *dev = fh->dev;
575 int rc = 0;
576
577 /* This instance already has stream_on */
578 if (fh->stream_on)
579 return rc;
580
Mauro Carvalho Chehaba2254522007-11-11 01:08:26 -0300581 if (dev->stream_on)
Mauro Carvalho Chehab29b59412008-12-16 20:19:24 -0300582 return -EBUSY;
Mauro Carvalho Chehaba2254522007-11-11 01:08:26 -0300583
Mauro Carvalho Chehabe74153d2008-04-13 14:55:38 -0300584 dev->stream_on = 1;
585 fh->stream_on = 1;
Mauro Carvalho Chehaba2254522007-11-11 01:08:26 -0300586 return rc;
587}
588
589static int res_check(struct em28xx_fh *fh)
590{
Nicola Soranzoa1a6ee72009-02-10 23:28:24 -0300591 return fh->stream_on;
Mauro Carvalho Chehaba2254522007-11-11 01:08:26 -0300592}
593
594static void res_free(struct em28xx_fh *fh)
595{
596 struct em28xx *dev = fh->dev;
597
Mauro Carvalho Chehaba2254522007-11-11 01:08:26 -0300598 fh->stream_on = 0;
599 dev->stream_on = 0;
Mauro Carvalho Chehaba2254522007-11-11 01:08:26 -0300600}
601
akpm@osdl.orga6c2ba22005-11-08 21:37:07 -0800602/*
Mauro Carvalho Chehab195a4ef2007-11-11 13:17:17 -0300603 * em28xx_get_ctrl()
604 * return the current saturation, brightness or contrast, mute state
605 */
606static int em28xx_get_ctrl(struct em28xx *dev, struct v4l2_control *ctrl)
607{
608 switch (ctrl->id) {
609 case V4L2_CID_AUDIO_MUTE:
610 ctrl->value = dev->mute;
611 return 0;
612 case V4L2_CID_AUDIO_VOLUME:
613 ctrl->value = dev->volume;
614 return 0;
615 default:
616 return -EINVAL;
617 }
618}
619
620/*
621 * em28xx_set_ctrl()
622 * mute or set new saturation, brightness or contrast
623 */
624static int em28xx_set_ctrl(struct em28xx *dev, const struct v4l2_control *ctrl)
625{
626 switch (ctrl->id) {
627 case V4L2_CID_AUDIO_MUTE:
628 if (ctrl->value != dev->mute) {
629 dev->mute = ctrl->value;
Mauro Carvalho Chehab195a4ef2007-11-11 13:17:17 -0300630 return em28xx_audio_analog_set(dev);
631 }
632 return 0;
633 case V4L2_CID_AUDIO_VOLUME:
634 dev->volume = ctrl->value;
635 return em28xx_audio_analog_set(dev);
636 default:
637 return -EINVAL;
638 }
639}
640
Mauro Carvalho Chehab195a4ef2007-11-11 13:17:17 -0300641static int check_dev(struct em28xx *dev)
642{
643 if (dev->state & DEV_DISCONNECTED) {
644 em28xx_errdev("v4l2 ioctl: device not present\n");
645 return -ENODEV;
646 }
647
648 if (dev->state & DEV_MISCONFIGURED) {
649 em28xx_errdev("v4l2 ioctl: device is misconfigured; "
650 "close and open it again\n");
651 return -EIO;
652 }
653 return 0;
654}
655
656static void get_scale(struct em28xx *dev,
657 unsigned int width, unsigned int height,
658 unsigned int *hscale, unsigned int *vscale)
659{
Mauro Carvalho Chehab55699962009-07-13 20:15:02 -0300660 unsigned int maxw = norm_maxw(dev);
661 unsigned int maxh = norm_maxh(dev);
Mauro Carvalho Chehab195a4ef2007-11-11 13:17:17 -0300662
663 *hscale = (((unsigned long)maxw) << 12) / width - 4096L;
664 if (*hscale >= 0x4000)
665 *hscale = 0x3fff;
666
667 *vscale = (((unsigned long)maxh) << 12) / height - 4096L;
668 if (*vscale >= 0x4000)
669 *vscale = 0x3fff;
670}
671
672/* ------------------------------------------------------------------
673 IOCTL vidioc handling
674 ------------------------------------------------------------------*/
675
Hans Verkuil78b526a2008-05-28 12:16:41 -0300676static int vidioc_g_fmt_vid_cap(struct file *file, void *priv,
Mauro Carvalho Chehab195a4ef2007-11-11 13:17:17 -0300677 struct v4l2_format *f)
678{
679 struct em28xx_fh *fh = priv;
680 struct em28xx *dev = fh->dev;
681
682 mutex_lock(&dev->lock);
683
684 f->fmt.pix.width = dev->width;
685 f->fmt.pix.height = dev->height;
Mauro Carvalho Chehabbddcf632008-12-20 09:06:37 -0300686 f->fmt.pix.pixelformat = dev->format->fourcc;
687 f->fmt.pix.bytesperline = (dev->width * dev->format->depth + 7) >> 3;
Mauro Carvalho Chehab44dc7332008-04-13 15:11:08 -0300688 f->fmt.pix.sizeimage = f->fmt.pix.bytesperline * dev->height;
Mauro Carvalho Chehab195a4ef2007-11-11 13:17:17 -0300689 f->fmt.pix.colorspace = V4L2_COLORSPACE_SMPTE170M;
690
691 /* FIXME: TOP? NONE? BOTTOM? ALTENATE? */
692 f->fmt.pix.field = dev->interlaced ?
693 V4L2_FIELD_INTERLACED : V4L2_FIELD_TOP;
694
695 mutex_unlock(&dev->lock);
696 return 0;
697}
698
Mauro Carvalho Chehabbddcf632008-12-20 09:06:37 -0300699static struct em28xx_fmt *format_by_fourcc(unsigned int fourcc)
700{
701 unsigned int i;
702
703 for (i = 0; i < ARRAY_SIZE(format); i++)
704 if (format[i].fourcc == fourcc)
705 return &format[i];
706
707 return NULL;
708}
709
Hans Verkuil78b526a2008-05-28 12:16:41 -0300710static int vidioc_try_fmt_vid_cap(struct file *file, void *priv,
Mauro Carvalho Chehab195a4ef2007-11-11 13:17:17 -0300711 struct v4l2_format *f)
712{
713 struct em28xx_fh *fh = priv;
714 struct em28xx *dev = fh->dev;
Trent Piephoccb83402009-05-30 21:45:46 -0300715 unsigned int width = f->fmt.pix.width;
716 unsigned int height = f->fmt.pix.height;
Mauro Carvalho Chehab195a4ef2007-11-11 13:17:17 -0300717 unsigned int maxw = norm_maxw(dev);
718 unsigned int maxh = norm_maxh(dev);
719 unsigned int hscale, vscale;
Mauro Carvalho Chehabbddcf632008-12-20 09:06:37 -0300720 struct em28xx_fmt *fmt;
721
722 fmt = format_by_fourcc(f->fmt.pix.pixelformat);
723 if (!fmt) {
724 em28xx_videodbg("Fourcc format (%08x) invalid.\n",
725 f->fmt.pix.pixelformat);
726 return -EINVAL;
727 }
Mauro Carvalho Chehab195a4ef2007-11-11 13:17:17 -0300728
Mauro Carvalho Chehab55699962009-07-13 20:15:02 -0300729 if (dev->board.is_em2800) {
Mauro Carvalho Chehab195a4ef2007-11-11 13:17:17 -0300730 /* the em2800 can only scale down to 50% */
Trent Piephoccb83402009-05-30 21:45:46 -0300731 height = height > (3 * maxh / 4) ? maxh : maxh / 2;
732 width = width > (3 * maxw / 4) ? maxw : maxw / 2;
733 /* According to empiatech support the MaxPacketSize is too small
734 * to support framesizes larger than 640x480 @ 30 fps or 640x576
735 * @ 25 fps. As this would cut of a part of the image we prefer
736 * 360x576 or 360x480 for now */
Mauro Carvalho Chehab195a4ef2007-11-11 13:17:17 -0300737 if (width == maxw && height == maxh)
738 width /= 2;
Trent Piephoccb83402009-05-30 21:45:46 -0300739 } else {
740 /* width must even because of the YUYV format
741 height must be even because of interlacing */
742 v4l_bound_align_image(&width, 48, maxw, 1, &height, 32, maxh, 1, 0);
Mauro Carvalho Chehab195a4ef2007-11-11 13:17:17 -0300743 }
744
745 get_scale(dev, width, height, &hscale, &vscale);
746
747 width = (((unsigned long)maxw) << 12) / (hscale + 4096L);
748 height = (((unsigned long)maxh) << 12) / (vscale + 4096L);
749
750 f->fmt.pix.width = width;
751 f->fmt.pix.height = height;
Mauro Carvalho Chehabbddcf632008-12-20 09:06:37 -0300752 f->fmt.pix.pixelformat = fmt->fourcc;
753 f->fmt.pix.bytesperline = (dev->width * fmt->depth + 7) >> 3;
754 f->fmt.pix.sizeimage = f->fmt.pix.bytesperline * height;
Mauro Carvalho Chehab195a4ef2007-11-11 13:17:17 -0300755 f->fmt.pix.colorspace = V4L2_COLORSPACE_SMPTE170M;
756 f->fmt.pix.field = V4L2_FIELD_INTERLACED;
757
Mauro Carvalho Chehab195a4ef2007-11-11 13:17:17 -0300758 return 0;
759}
760
Mauro Carvalho Chehabed5f1432009-07-02 17:34:04 -0300761static int em28xx_set_video_format(struct em28xx *dev, unsigned int fourcc,
762 unsigned width, unsigned height)
763{
764 struct em28xx_fmt *fmt;
765
Mauro Carvalho Chehabed5f1432009-07-02 17:34:04 -0300766 fmt = format_by_fourcc(fourcc);
767 if (!fmt)
768 return -EINVAL;
769
770 dev->format = fmt;
771 dev->width = width;
772 dev->height = height;
773
774 /* set new image size */
775 get_scale(dev, dev->width, dev->height, &dev->hscale, &dev->vscale);
776
777 em28xx_set_alternate(dev);
778 em28xx_resolution_set(dev);
779
780 return 0;
781}
782
Hans Verkuil78b526a2008-05-28 12:16:41 -0300783static int vidioc_s_fmt_vid_cap(struct file *file, void *priv,
Mauro Carvalho Chehab195a4ef2007-11-11 13:17:17 -0300784 struct v4l2_format *f)
785{
786 struct em28xx_fh *fh = priv;
787 struct em28xx *dev = fh->dev;
Mauro Carvalho Chehabad0ebb92008-04-13 14:37:52 -0300788 int rc;
Mauro Carvalho Chehab195a4ef2007-11-11 13:17:17 -0300789
790 rc = check_dev(dev);
791 if (rc < 0)
792 return rc;
793
Mauro Carvalho Chehab195a4ef2007-11-11 13:17:17 -0300794 mutex_lock(&dev->lock);
795
Mauro Carvalho Chehabefc52a92008-12-16 22:04:56 -0300796 vidioc_try_fmt_vid_cap(file, priv, f);
797
Brandon Philips05612972008-04-13 14:57:01 -0300798 if (videobuf_queue_is_busy(&fh->vb_vidq)) {
799 em28xx_errdev("%s queue busy\n", __func__);
800 rc = -EBUSY;
801 goto out;
802 }
803
Aidan Thornton0ea13e62008-04-13 15:02:24 -0300804 if (dev->stream_on && !fh->stream_on) {
805 em28xx_errdev("%s device in use by another fh\n", __func__);
806 rc = -EBUSY;
807 goto out;
808 }
809
Mauro Carvalho Chehabed5f1432009-07-02 17:34:04 -0300810 rc = em28xx_set_video_format(dev, f->fmt.pix.pixelformat,
811 f->fmt.pix.width, f->fmt.pix.height);
Brandon Philips05612972008-04-13 14:57:01 -0300812
813out:
Mauro Carvalho Chehab195a4ef2007-11-11 13:17:17 -0300814 mutex_unlock(&dev->lock);
Brandon Philips05612972008-04-13 14:57:01 -0300815 return rc;
Mauro Carvalho Chehab195a4ef2007-11-11 13:17:17 -0300816}
817
Nicola Soranzoa1a6ee72009-02-10 23:28:24 -0300818static int vidioc_s_std(struct file *file, void *priv, v4l2_std_id *norm)
Mauro Carvalho Chehab195a4ef2007-11-11 13:17:17 -0300819{
820 struct em28xx_fh *fh = priv;
821 struct em28xx *dev = fh->dev;
822 struct v4l2_format f;
Mauro Carvalho Chehab195a4ef2007-11-11 13:17:17 -0300823 int rc;
824
825 rc = check_dev(dev);
826 if (rc < 0)
827 return rc;
828
Mauro Carvalho Chehab195a4ef2007-11-11 13:17:17 -0300829 mutex_lock(&dev->lock);
Mauro Carvalho Chehab7d497f82007-11-11 14:15:34 -0300830 dev->norm = *norm;
Mauro Carvalho Chehab195a4ef2007-11-11 13:17:17 -0300831
832 /* Adjusts width/height, if needed */
833 f.fmt.pix.width = dev->width;
834 f.fmt.pix.height = dev->height;
Hans Verkuil78b526a2008-05-28 12:16:41 -0300835 vidioc_try_fmt_vid_cap(file, priv, &f);
Mauro Carvalho Chehab195a4ef2007-11-11 13:17:17 -0300836
Mauro Carvalho Chehab195a4ef2007-11-11 13:17:17 -0300837 /* set new image size */
838 dev->width = f.fmt.pix.width;
839 dev->height = f.fmt.pix.height;
Mauro Carvalho Chehab195a4ef2007-11-11 13:17:17 -0300840 get_scale(dev, dev->width, dev->height, &dev->hscale, &dev->vscale);
841
842 em28xx_resolution_set(dev);
Hans Verkuilf41737e2009-04-01 03:52:39 -0300843 v4l2_device_call_all(&dev->v4l2_dev, 0, core, s_std, dev->norm);
Mauro Carvalho Chehab195a4ef2007-11-11 13:17:17 -0300844
845 mutex_unlock(&dev->lock);
846 return 0;
847}
848
849static const char *iname[] = {
850 [EM28XX_VMUX_COMPOSITE1] = "Composite1",
851 [EM28XX_VMUX_COMPOSITE2] = "Composite2",
852 [EM28XX_VMUX_COMPOSITE3] = "Composite3",
853 [EM28XX_VMUX_COMPOSITE4] = "Composite4",
854 [EM28XX_VMUX_SVIDEO] = "S-Video",
855 [EM28XX_VMUX_TELEVISION] = "Television",
856 [EM28XX_VMUX_CABLE] = "Cable TV",
857 [EM28XX_VMUX_DVB] = "DVB",
858 [EM28XX_VMUX_DEBUG] = "for debug only",
859};
860
861static int vidioc_enum_input(struct file *file, void *priv,
862 struct v4l2_input *i)
863{
864 struct em28xx_fh *fh = priv;
865 struct em28xx *dev = fh->dev;
866 unsigned int n;
867
868 n = i->index;
869 if (n >= MAX_EM28XX_INPUT)
870 return -EINVAL;
871 if (0 == INPUT(n)->type)
872 return -EINVAL;
873
874 i->index = n;
875 i->type = V4L2_INPUT_TYPE_CAMERA;
876
877 strcpy(i->name, iname[INPUT(n)->type]);
878
879 if ((EM28XX_VMUX_TELEVISION == INPUT(n)->type) ||
880 (EM28XX_VMUX_CABLE == INPUT(n)->type))
881 i->type = V4L2_INPUT_TYPE_TUNER;
882
Mauro Carvalho Chehab7d497f82007-11-11 14:15:34 -0300883 i->std = dev->vdev->tvnorms;
Mauro Carvalho Chehab195a4ef2007-11-11 13:17:17 -0300884
885 return 0;
886}
887
888static int vidioc_g_input(struct file *file, void *priv, unsigned int *i)
889{
890 struct em28xx_fh *fh = priv;
891 struct em28xx *dev = fh->dev;
892
893 *i = dev->ctl_input;
894
895 return 0;
896}
897
898static int vidioc_s_input(struct file *file, void *priv, unsigned int i)
899{
900 struct em28xx_fh *fh = priv;
901 struct em28xx *dev = fh->dev;
902 int rc;
903
904 rc = check_dev(dev);
905 if (rc < 0)
906 return rc;
907
908 if (i >= MAX_EM28XX_INPUT)
909 return -EINVAL;
910 if (0 == INPUT(i)->type)
911 return -EINVAL;
912
Mauro Carvalho Chehab24c3c412009-01-07 22:49:25 -0300913 dev->ctl_input = i;
914
Mauro Carvalho Chehab195a4ef2007-11-11 13:17:17 -0300915 mutex_lock(&dev->lock);
Mauro Carvalho Chehab24c3c412009-01-07 22:49:25 -0300916 video_mux(dev, dev->ctl_input);
Mauro Carvalho Chehab195a4ef2007-11-11 13:17:17 -0300917 mutex_unlock(&dev->lock);
918 return 0;
919}
920
921static int vidioc_g_audio(struct file *file, void *priv, struct v4l2_audio *a)
922{
923 struct em28xx_fh *fh = priv;
924 struct em28xx *dev = fh->dev;
Mauro Carvalho Chehab195a4ef2007-11-11 13:17:17 -0300925
Mauro Carvalho Chehab35ae6f02008-11-20 12:40:51 -0300926 switch (a->index) {
927 case EM28XX_AMUX_VIDEO:
Mauro Carvalho Chehab195a4ef2007-11-11 13:17:17 -0300928 strcpy(a->name, "Television");
Mauro Carvalho Chehab35ae6f02008-11-20 12:40:51 -0300929 break;
930 case EM28XX_AMUX_LINE_IN:
Mauro Carvalho Chehab195a4ef2007-11-11 13:17:17 -0300931 strcpy(a->name, "Line In");
Mauro Carvalho Chehab35ae6f02008-11-20 12:40:51 -0300932 break;
933 case EM28XX_AMUX_VIDEO2:
934 strcpy(a->name, "Television alt");
935 break;
936 case EM28XX_AMUX_PHONE:
937 strcpy(a->name, "Phone");
938 break;
939 case EM28XX_AMUX_MIC:
940 strcpy(a->name, "Mic");
941 break;
942 case EM28XX_AMUX_CD:
943 strcpy(a->name, "CD");
944 break;
945 case EM28XX_AMUX_AUX:
946 strcpy(a->name, "Aux");
947 break;
948 case EM28XX_AMUX_PCM_OUT:
949 strcpy(a->name, "PCM");
950 break;
951 default:
952 return -EINVAL;
953 }
Douglas Schilling Landgraf6ea54d92008-04-17 21:41:10 -0300954
Mauro Carvalho Chehab35ae6f02008-11-20 12:40:51 -0300955 a->index = dev->ctl_ainput;
Mauro Carvalho Chehab195a4ef2007-11-11 13:17:17 -0300956 a->capability = V4L2_AUDCAP_STEREO;
Mauro Carvalho Chehab195a4ef2007-11-11 13:17:17 -0300957
958 return 0;
959}
960
961static int vidioc_s_audio(struct file *file, void *priv, struct v4l2_audio *a)
962{
963 struct em28xx_fh *fh = priv;
964 struct em28xx *dev = fh->dev;
965
Mauro Carvalho Chehab24c3c412009-01-07 22:49:25 -0300966
967 if (a->index >= MAX_EM28XX_INPUT)
968 return -EINVAL;
969 if (0 == INPUT(a->index)->type)
970 return -EINVAL;
971
Mauro Carvalho Chehabefc52a92008-12-16 22:04:56 -0300972 mutex_lock(&dev->lock);
973
Mauro Carvalho Chehab35ae6f02008-11-20 12:40:51 -0300974 dev->ctl_ainput = INPUT(a->index)->amux;
975 dev->ctl_aoutput = INPUT(a->index)->aout;
Mauro Carvalho Chehabe879b8e2008-11-20 13:39:39 -0300976
977 if (!dev->ctl_aoutput)
978 dev->ctl_aoutput = EM28XX_AOUT_MASTER;
Mauro Carvalho Chehabefc52a92008-12-16 22:04:56 -0300979
980 mutex_unlock(&dev->lock);
Mauro Carvalho Chehab195a4ef2007-11-11 13:17:17 -0300981 return 0;
982}
983
984static int vidioc_queryctrl(struct file *file, void *priv,
985 struct v4l2_queryctrl *qc)
986{
987 struct em28xx_fh *fh = priv;
988 struct em28xx *dev = fh->dev;
989 int id = qc->id;
990 int i;
991 int rc;
992
993 rc = check_dev(dev);
994 if (rc < 0)
995 return rc;
996
997 memset(qc, 0, sizeof(*qc));
998
999 qc->id = id;
1000
Mauro Carvalho Chehab505b6d02008-11-25 09:39:50 -03001001 if (!dev->board.has_msp34xx) {
Mauro Carvalho Chehab195a4ef2007-11-11 13:17:17 -03001002 for (i = 0; i < ARRAY_SIZE(em28xx_qctrl); i++) {
1003 if (qc->id && qc->id == em28xx_qctrl[i].id) {
1004 memcpy(qc, &(em28xx_qctrl[i]), sizeof(*qc));
1005 return 0;
1006 }
1007 }
1008 }
Douglas Schilling Landgraff2cf2502009-03-31 17:10:58 -03001009
Mauro Carvalho Chehab195a4ef2007-11-11 13:17:17 -03001010 mutex_lock(&dev->lock);
Douglas Schilling Landgraff2cf2502009-03-31 17:10:58 -03001011 v4l2_device_call_all(&dev->v4l2_dev, 0, core, queryctrl, qc);
Mauro Carvalho Chehab195a4ef2007-11-11 13:17:17 -03001012 mutex_unlock(&dev->lock);
1013
1014 if (qc->type)
1015 return 0;
1016 else
1017 return -EINVAL;
1018}
1019
1020static int vidioc_g_ctrl(struct file *file, void *priv,
1021 struct v4l2_control *ctrl)
1022{
1023 struct em28xx_fh *fh = priv;
1024 struct em28xx *dev = fh->dev;
1025 int rc;
1026
1027 rc = check_dev(dev);
1028 if (rc < 0)
1029 return rc;
Mauro Carvalho Chehabb6070f02008-12-22 06:20:32 -03001030 rc = 0;
Mauro Carvalho Chehabefc52a92008-12-16 22:04:56 -03001031
Mauro Carvalho Chehab195a4ef2007-11-11 13:17:17 -03001032 mutex_lock(&dev->lock);
1033
Mauro Carvalho Chehabb6070f02008-12-22 06:20:32 -03001034 if (dev->board.has_msp34xx)
Douglas Schilling Landgraff2cf2502009-03-31 17:10:58 -03001035 v4l2_device_call_all(&dev->v4l2_dev, 0, core, g_ctrl, ctrl);
Hans Verkuil07f7db42009-01-21 17:06:42 -03001036 else {
Mauro Carvalho Chehabb6070f02008-12-22 06:20:32 -03001037 rc = em28xx_get_ctrl(dev, ctrl);
Hans Verkuil07f7db42009-01-21 17:06:42 -03001038 if (rc < 0) {
Douglas Schilling Landgraff2cf2502009-03-31 17:10:58 -03001039 v4l2_device_call_all(&dev->v4l2_dev, 0, core, g_ctrl, ctrl);
Hans Verkuil07f7db42009-01-21 17:06:42 -03001040 rc = 0;
1041 }
1042 }
Mauro Carvalho Chehab195a4ef2007-11-11 13:17:17 -03001043
1044 mutex_unlock(&dev->lock);
1045 return rc;
1046}
1047
1048static int vidioc_s_ctrl(struct file *file, void *priv,
1049 struct v4l2_control *ctrl)
1050{
1051 struct em28xx_fh *fh = priv;
1052 struct em28xx *dev = fh->dev;
1053 u8 i;
1054 int rc;
1055
1056 rc = check_dev(dev);
1057 if (rc < 0)
1058 return rc;
1059
1060 mutex_lock(&dev->lock);
1061
Mauro Carvalho Chehab505b6d02008-11-25 09:39:50 -03001062 if (dev->board.has_msp34xx)
Douglas Schilling Landgraff2cf2502009-03-31 17:10:58 -03001063 v4l2_device_call_all(&dev->v4l2_dev, 0, core, s_ctrl, ctrl);
Mauro Carvalho Chehab195a4ef2007-11-11 13:17:17 -03001064 else {
1065 rc = 1;
1066 for (i = 0; i < ARRAY_SIZE(em28xx_qctrl); i++) {
1067 if (ctrl->id == em28xx_qctrl[i].id) {
1068 if (ctrl->value < em28xx_qctrl[i].minimum ||
1069 ctrl->value > em28xx_qctrl[i].maximum) {
1070 rc = -ERANGE;
1071 break;
1072 }
1073
1074 rc = em28xx_set_ctrl(dev, ctrl);
1075 break;
1076 }
1077 }
1078 }
1079
1080 /* Control not found - try to send it to the attached devices */
1081 if (rc == 1) {
Douglas Schilling Landgraff2cf2502009-03-31 17:10:58 -03001082 v4l2_device_call_all(&dev->v4l2_dev, 0, core, s_ctrl, ctrl);
Mauro Carvalho Chehab195a4ef2007-11-11 13:17:17 -03001083 rc = 0;
1084 }
1085
1086 mutex_unlock(&dev->lock);
1087 return rc;
1088}
1089
1090static int vidioc_g_tuner(struct file *file, void *priv,
1091 struct v4l2_tuner *t)
1092{
1093 struct em28xx_fh *fh = priv;
1094 struct em28xx *dev = fh->dev;
1095 int rc;
1096
1097 rc = check_dev(dev);
1098 if (rc < 0)
1099 return rc;
1100
1101 if (0 != t->index)
1102 return -EINVAL;
1103
1104 strcpy(t->name, "Tuner");
1105
1106 mutex_lock(&dev->lock);
Douglas Schilling Landgraff2cf2502009-03-31 17:10:58 -03001107 v4l2_device_call_all(&dev->v4l2_dev, 0, tuner, g_tuner, t);
Mauro Carvalho Chehab195a4ef2007-11-11 13:17:17 -03001108 mutex_unlock(&dev->lock);
Douglas Schilling Landgraff2cf2502009-03-31 17:10:58 -03001109
Mauro Carvalho Chehab195a4ef2007-11-11 13:17:17 -03001110 return 0;
1111}
1112
1113static int vidioc_s_tuner(struct file *file, void *priv,
1114 struct v4l2_tuner *t)
1115{
1116 struct em28xx_fh *fh = priv;
1117 struct em28xx *dev = fh->dev;
1118 int rc;
1119
1120 rc = check_dev(dev);
1121 if (rc < 0)
1122 return rc;
1123
1124 if (0 != t->index)
1125 return -EINVAL;
1126
1127 mutex_lock(&dev->lock);
Douglas Schilling Landgraff2cf2502009-03-31 17:10:58 -03001128 v4l2_device_call_all(&dev->v4l2_dev, 0, tuner, s_tuner, t);
Mauro Carvalho Chehab195a4ef2007-11-11 13:17:17 -03001129 mutex_unlock(&dev->lock);
Douglas Schilling Landgraff2cf2502009-03-31 17:10:58 -03001130
Mauro Carvalho Chehab195a4ef2007-11-11 13:17:17 -03001131 return 0;
1132}
1133
1134static int vidioc_g_frequency(struct file *file, void *priv,
1135 struct v4l2_frequency *f)
1136{
1137 struct em28xx_fh *fh = priv;
1138 struct em28xx *dev = fh->dev;
1139
Mauro Carvalho Chehabefc52a92008-12-16 22:04:56 -03001140 mutex_lock(&dev->lock);
Mauro Carvalho Chehab0be43752008-01-05 17:22:01 -03001141 f->type = fh->radio ? V4L2_TUNER_RADIO : V4L2_TUNER_ANALOG_TV;
Mauro Carvalho Chehab195a4ef2007-11-11 13:17:17 -03001142 f->frequency = dev->ctl_freq;
Mauro Carvalho Chehabefc52a92008-12-16 22:04:56 -03001143 mutex_unlock(&dev->lock);
Mauro Carvalho Chehab195a4ef2007-11-11 13:17:17 -03001144
1145 return 0;
1146}
1147
1148static int vidioc_s_frequency(struct file *file, void *priv,
1149 struct v4l2_frequency *f)
1150{
1151 struct em28xx_fh *fh = priv;
1152 struct em28xx *dev = fh->dev;
1153 int rc;
1154
1155 rc = check_dev(dev);
1156 if (rc < 0)
1157 return rc;
1158
1159 if (0 != f->tuner)
1160 return -EINVAL;
1161
Mauro Carvalho Chehab0be43752008-01-05 17:22:01 -03001162 if (unlikely(0 == fh->radio && f->type != V4L2_TUNER_ANALOG_TV))
1163 return -EINVAL;
1164 if (unlikely(1 == fh->radio && f->type != V4L2_TUNER_RADIO))
Mauro Carvalho Chehab195a4ef2007-11-11 13:17:17 -03001165 return -EINVAL;
1166
1167 mutex_lock(&dev->lock);
1168
1169 dev->ctl_freq = f->frequency;
Douglas Schilling Landgraff2cf2502009-03-31 17:10:58 -03001170 v4l2_device_call_all(&dev->v4l2_dev, 0, tuner, s_frequency, f);
Mauro Carvalho Chehab195a4ef2007-11-11 13:17:17 -03001171
1172 mutex_unlock(&dev->lock);
Mauro Carvalho Chehabefc52a92008-12-16 22:04:56 -03001173
Mauro Carvalho Chehab195a4ef2007-11-11 13:17:17 -03001174 return 0;
1175}
1176
Mauro Carvalho Chehab1e7ad562008-02-06 09:00:41 -03001177#ifdef CONFIG_VIDEO_ADV_DEBUG
1178static int em28xx_reg_len(int reg)
1179{
1180 switch (reg) {
Mauro Carvalho Chehab41facaa2008-04-17 21:44:58 -03001181 case EM28XX_R40_AC97LSB:
1182 case EM28XX_R30_HSCALELOW:
1183 case EM28XX_R32_VSCALELOW:
Mauro Carvalho Chehab1e7ad562008-02-06 09:00:41 -03001184 return 2;
1185 default:
1186 return 1;
1187 }
1188}
1189
Mauro Carvalho Chehab14983d82008-12-22 20:58:41 -03001190static int vidioc_g_chip_ident(struct file *file, void *priv,
Hans Verkuilaecde8b2008-12-30 07:14:19 -03001191 struct v4l2_dbg_chip_ident *chip)
Mauro Carvalho Chehab14983d82008-12-22 20:58:41 -03001192{
1193 struct em28xx_fh *fh = priv;
1194 struct em28xx *dev = fh->dev;
1195
1196 chip->ident = V4L2_IDENT_NONE;
1197 chip->revision = 0;
1198
Douglas Schilling Landgraff2cf2502009-03-31 17:10:58 -03001199 v4l2_device_call_all(&dev->v4l2_dev, 0, core, g_chip_ident, chip);
Mauro Carvalho Chehab14983d82008-12-22 20:58:41 -03001200
1201 return 0;
1202}
1203
1204
Mauro Carvalho Chehab1e7ad562008-02-06 09:00:41 -03001205static int vidioc_g_register(struct file *file, void *priv,
Hans Verkuilaecde8b2008-12-30 07:14:19 -03001206 struct v4l2_dbg_register *reg)
Mauro Carvalho Chehab1e7ad562008-02-06 09:00:41 -03001207{
1208 struct em28xx_fh *fh = priv;
1209 struct em28xx *dev = fh->dev;
1210 int ret;
1211
Hans Verkuilaecde8b2008-12-30 07:14:19 -03001212 switch (reg->match.type) {
Mauro Carvalho Chehab14983d82008-12-22 20:58:41 -03001213 case V4L2_CHIP_MATCH_AC97:
Mauro Carvalho Chehab531c98e2008-12-22 13:18:27 -03001214 mutex_lock(&dev->lock);
1215 ret = em28xx_read_ac97(dev, reg->reg);
1216 mutex_unlock(&dev->lock);
1217 if (ret < 0)
1218 return ret;
1219
1220 reg->val = ret;
Hans Verkuilaecde8b2008-12-30 07:14:19 -03001221 reg->size = 1;
Mauro Carvalho Chehab531c98e2008-12-22 13:18:27 -03001222 return 0;
Mauro Carvalho Chehab14983d82008-12-22 20:58:41 -03001223 case V4L2_CHIP_MATCH_I2C_DRIVER:
Douglas Schilling Landgraff2cf2502009-03-31 17:10:58 -03001224 v4l2_device_call_all(&dev->v4l2_dev, 0, core, g_register, reg);
Mauro Carvalho Chehab14983d82008-12-22 20:58:41 -03001225 return 0;
1226 case V4L2_CHIP_MATCH_I2C_ADDR:
1227 /* Not supported yet */
1228 return -EINVAL;
1229 default:
Hans Verkuilaecde8b2008-12-30 07:14:19 -03001230 if (!v4l2_chip_match_host(&reg->match))
Mauro Carvalho Chehab14983d82008-12-22 20:58:41 -03001231 return -EINVAL;
Mauro Carvalho Chehab531c98e2008-12-22 13:18:27 -03001232 }
1233
Mauro Carvalho Chehab14983d82008-12-22 20:58:41 -03001234 /* Match host */
Hans Verkuilaecde8b2008-12-30 07:14:19 -03001235 reg->size = em28xx_reg_len(reg->reg);
1236 if (reg->size == 1) {
Mauro Carvalho Chehabefc52a92008-12-16 22:04:56 -03001237 mutex_lock(&dev->lock);
Mauro Carvalho Chehab1e7ad562008-02-06 09:00:41 -03001238 ret = em28xx_read_reg(dev, reg->reg);
Mauro Carvalho Chehabefc52a92008-12-16 22:04:56 -03001239 mutex_unlock(&dev->lock);
1240
Mauro Carvalho Chehab1e7ad562008-02-06 09:00:41 -03001241 if (ret < 0)
1242 return ret;
1243
1244 reg->val = ret;
1245 } else {
Hans Verkuilaecde8b2008-12-30 07:14:19 -03001246 __le16 val = 0;
Mauro Carvalho Chehabefc52a92008-12-16 22:04:56 -03001247 mutex_lock(&dev->lock);
Mauro Carvalho Chehab1e7ad562008-02-06 09:00:41 -03001248 ret = em28xx_read_reg_req_len(dev, USB_REQ_GET_STATUS,
1249 reg->reg, (char *)&val, 2);
Mauro Carvalho Chehabefc52a92008-12-16 22:04:56 -03001250 mutex_unlock(&dev->lock);
Mauro Carvalho Chehab1e7ad562008-02-06 09:00:41 -03001251 if (ret < 0)
1252 return ret;
1253
Hans Verkuilaecde8b2008-12-30 07:14:19 -03001254 reg->val = le16_to_cpu(val);
Mauro Carvalho Chehab1e7ad562008-02-06 09:00:41 -03001255 }
1256
1257 return 0;
1258}
1259
1260static int vidioc_s_register(struct file *file, void *priv,
Hans Verkuilaecde8b2008-12-30 07:14:19 -03001261 struct v4l2_dbg_register *reg)
Mauro Carvalho Chehab1e7ad562008-02-06 09:00:41 -03001262{
1263 struct em28xx_fh *fh = priv;
1264 struct em28xx *dev = fh->dev;
Hans Verkuilaecde8b2008-12-30 07:14:19 -03001265 __le16 buf;
Mauro Carvalho Chehabefc52a92008-12-16 22:04:56 -03001266 int rc;
Mauro Carvalho Chehab1e7ad562008-02-06 09:00:41 -03001267
Hans Verkuilaecde8b2008-12-30 07:14:19 -03001268 switch (reg->match.type) {
Mauro Carvalho Chehab14983d82008-12-22 20:58:41 -03001269 case V4L2_CHIP_MATCH_AC97:
Mauro Carvalho Chehab531c98e2008-12-22 13:18:27 -03001270 mutex_lock(&dev->lock);
1271 rc = em28xx_write_ac97(dev, reg->reg, reg->val);
1272 mutex_unlock(&dev->lock);
1273
1274 return rc;
Mauro Carvalho Chehab14983d82008-12-22 20:58:41 -03001275 case V4L2_CHIP_MATCH_I2C_DRIVER:
Douglas Schilling Landgraff2cf2502009-03-31 17:10:58 -03001276 v4l2_device_call_all(&dev->v4l2_dev, 0, core, s_register, reg);
Mauro Carvalho Chehab14983d82008-12-22 20:58:41 -03001277 return 0;
1278 case V4L2_CHIP_MATCH_I2C_ADDR:
1279 /* Not supported yet */
1280 return -EINVAL;
1281 default:
Hans Verkuilaecde8b2008-12-30 07:14:19 -03001282 if (!v4l2_chip_match_host(&reg->match))
Mauro Carvalho Chehab14983d82008-12-22 20:58:41 -03001283 return -EINVAL;
Mauro Carvalho Chehab531c98e2008-12-22 13:18:27 -03001284 }
1285
Mauro Carvalho Chehab14983d82008-12-22 20:58:41 -03001286 /* Match host */
Hans Verkuilaecde8b2008-12-30 07:14:19 -03001287 buf = cpu_to_le16(reg->val);
Mauro Carvalho Chehab1e7ad562008-02-06 09:00:41 -03001288
Mauro Carvalho Chehabefc52a92008-12-16 22:04:56 -03001289 mutex_lock(&dev->lock);
1290 rc = em28xx_write_regs(dev, reg->reg, (char *)&buf,
1291 em28xx_reg_len(reg->reg));
1292 mutex_unlock(&dev->lock);
1293
1294 return rc;
Mauro Carvalho Chehab1e7ad562008-02-06 09:00:41 -03001295}
1296#endif
1297
1298
Mauro Carvalho Chehab195a4ef2007-11-11 13:17:17 -03001299static int vidioc_cropcap(struct file *file, void *priv,
1300 struct v4l2_cropcap *cc)
1301{
1302 struct em28xx_fh *fh = priv;
1303 struct em28xx *dev = fh->dev;
1304
1305 if (cc->type != V4L2_BUF_TYPE_VIDEO_CAPTURE)
1306 return -EINVAL;
1307
1308 cc->bounds.left = 0;
1309 cc->bounds.top = 0;
1310 cc->bounds.width = dev->width;
1311 cc->bounds.height = dev->height;
1312 cc->defrect = cc->bounds;
1313 cc->pixelaspect.numerator = 54; /* 4:3 FIXME: remove magic numbers */
1314 cc->pixelaspect.denominator = 59;
1315
1316 return 0;
1317}
1318
1319static int vidioc_streamon(struct file *file, void *priv,
1320 enum v4l2_buf_type type)
1321{
1322 struct em28xx_fh *fh = priv;
1323 struct em28xx *dev = fh->dev;
1324 int rc;
1325
1326 rc = check_dev(dev);
1327 if (rc < 0)
1328 return rc;
1329
Mauro Carvalho Chehab195a4ef2007-11-11 13:17:17 -03001330
Mauro Carvalho Chehab29b59412008-12-16 20:19:24 -03001331 mutex_lock(&dev->lock);
1332 rc = res_get(fh);
Mauro Carvalho Chehab29b59412008-12-16 20:19:24 -03001333
Mauro Carvalho Chehab5db0b5e2008-12-22 06:14:31 -03001334 if (likely(rc >= 0))
1335 rc = videobuf_streamon(&fh->vb_vidq);
Mauro Carvalho Chehabefc52a92008-12-16 22:04:56 -03001336
1337 mutex_unlock(&dev->lock);
1338
1339 return rc;
Mauro Carvalho Chehab195a4ef2007-11-11 13:17:17 -03001340}
1341
1342static int vidioc_streamoff(struct file *file, void *priv,
1343 enum v4l2_buf_type type)
1344{
1345 struct em28xx_fh *fh = priv;
1346 struct em28xx *dev = fh->dev;
1347 int rc;
1348
1349 rc = check_dev(dev);
1350 if (rc < 0)
1351 return rc;
1352
Mauro Carvalho Chehabad0ebb92008-04-13 14:37:52 -03001353 if (fh->type != V4L2_BUF_TYPE_VIDEO_CAPTURE)
1354 return -EINVAL;
1355 if (type != fh->type)
Mauro Carvalho Chehab195a4ef2007-11-11 13:17:17 -03001356 return -EINVAL;
1357
Mauro Carvalho Chehab78313642008-12-16 20:00:49 -03001358 mutex_lock(&dev->lock);
Mauro Carvalho Chehabefc52a92008-12-16 22:04:56 -03001359
1360 videobuf_streamoff(&fh->vb_vidq);
Mauro Carvalho Chehabad0ebb92008-04-13 14:37:52 -03001361 res_free(fh);
Mauro Carvalho Chehabefc52a92008-12-16 22:04:56 -03001362
Mauro Carvalho Chehab78313642008-12-16 20:00:49 -03001363 mutex_unlock(&dev->lock);
Mauro Carvalho Chehab195a4ef2007-11-11 13:17:17 -03001364
Mauro Carvalho Chehab195a4ef2007-11-11 13:17:17 -03001365 return 0;
1366}
1367
1368static int vidioc_querycap(struct file *file, void *priv,
1369 struct v4l2_capability *cap)
1370{
1371 struct em28xx_fh *fh = priv;
1372 struct em28xx *dev = fh->dev;
1373
1374 strlcpy(cap->driver, "em28xx", sizeof(cap->driver));
1375 strlcpy(cap->card, em28xx_boards[dev->model].name, sizeof(cap->card));
Thierry MERLEcb977162009-01-20 18:01:33 -03001376 usb_make_path(dev->udev, cap->bus_info, sizeof(cap->bus_info));
Mauro Carvalho Chehab195a4ef2007-11-11 13:17:17 -03001377
1378 cap->version = EM28XX_VERSION_CODE;
1379
1380 cap->capabilities =
1381 V4L2_CAP_SLICED_VBI_CAPTURE |
1382 V4L2_CAP_VIDEO_CAPTURE |
1383 V4L2_CAP_AUDIO |
1384 V4L2_CAP_READWRITE | V4L2_CAP_STREAMING;
1385
Mauro Carvalho Chehabed086312008-01-24 06:59:20 -03001386 if (dev->tuner_type != TUNER_ABSENT)
Mauro Carvalho Chehab195a4ef2007-11-11 13:17:17 -03001387 cap->capabilities |= V4L2_CAP_TUNER;
1388
1389 return 0;
1390}
1391
Hans Verkuil78b526a2008-05-28 12:16:41 -03001392static int vidioc_enum_fmt_vid_cap(struct file *file, void *priv,
Mauro Carvalho Chehabbddcf632008-12-20 09:06:37 -03001393 struct v4l2_fmtdesc *f)
Mauro Carvalho Chehab195a4ef2007-11-11 13:17:17 -03001394{
Mauro Carvalho Chehabbddcf632008-12-20 09:06:37 -03001395 if (unlikely(f->index >= ARRAY_SIZE(format)))
Mauro Carvalho Chehab195a4ef2007-11-11 13:17:17 -03001396 return -EINVAL;
1397
Mauro Carvalho Chehabbddcf632008-12-20 09:06:37 -03001398 strlcpy(f->description, format[f->index].name, sizeof(f->description));
1399 f->pixelformat = format[f->index].fourcc;
Mauro Carvalho Chehab195a4ef2007-11-11 13:17:17 -03001400
1401 return 0;
1402}
1403
1404/* Sliced VBI ioctls */
Hans Verkuil78b526a2008-05-28 12:16:41 -03001405static int vidioc_g_fmt_sliced_vbi_cap(struct file *file, void *priv,
Mauro Carvalho Chehab195a4ef2007-11-11 13:17:17 -03001406 struct v4l2_format *f)
1407{
1408 struct em28xx_fh *fh = priv;
1409 struct em28xx *dev = fh->dev;
1410 int rc;
1411
1412 rc = check_dev(dev);
1413 if (rc < 0)
1414 return rc;
1415
1416 mutex_lock(&dev->lock);
1417
1418 f->fmt.sliced.service_set = 0;
Douglas Schilling Landgraff2cf2502009-03-31 17:10:58 -03001419 v4l2_device_call_all(&dev->v4l2_dev, 0, video, g_fmt, f);
Mauro Carvalho Chehab195a4ef2007-11-11 13:17:17 -03001420
1421 if (f->fmt.sliced.service_set == 0)
1422 rc = -EINVAL;
1423
1424 mutex_unlock(&dev->lock);
Douglas Schilling Landgraff2cf2502009-03-31 17:10:58 -03001425
Mauro Carvalho Chehab195a4ef2007-11-11 13:17:17 -03001426 return rc;
1427}
1428
Hans Verkuil78b526a2008-05-28 12:16:41 -03001429static int vidioc_try_set_sliced_vbi_cap(struct file *file, void *priv,
Mauro Carvalho Chehab195a4ef2007-11-11 13:17:17 -03001430 struct v4l2_format *f)
1431{
1432 struct em28xx_fh *fh = priv;
1433 struct em28xx *dev = fh->dev;
1434 int rc;
1435
1436 rc = check_dev(dev);
1437 if (rc < 0)
1438 return rc;
1439
1440 mutex_lock(&dev->lock);
Douglas Schilling Landgraff2cf2502009-03-31 17:10:58 -03001441 v4l2_device_call_all(&dev->v4l2_dev, 0, video, g_fmt, f);
Mauro Carvalho Chehab195a4ef2007-11-11 13:17:17 -03001442 mutex_unlock(&dev->lock);
1443
1444 if (f->fmt.sliced.service_set == 0)
1445 return -EINVAL;
1446
1447 return 0;
1448}
1449
1450
1451static int vidioc_reqbufs(struct file *file, void *priv,
1452 struct v4l2_requestbuffers *rb)
1453{
1454 struct em28xx_fh *fh = priv;
1455 struct em28xx *dev = fh->dev;
Mauro Carvalho Chehab195a4ef2007-11-11 13:17:17 -03001456 int rc;
1457
1458 rc = check_dev(dev);
1459 if (rc < 0)
1460 return rc;
1461
Nicola Soranzoa1a6ee72009-02-10 23:28:24 -03001462 return videobuf_reqbufs(&fh->vb_vidq, rb);
Mauro Carvalho Chehab195a4ef2007-11-11 13:17:17 -03001463}
1464
1465static int vidioc_querybuf(struct file *file, void *priv,
1466 struct v4l2_buffer *b)
1467{
1468 struct em28xx_fh *fh = priv;
1469 struct em28xx *dev = fh->dev;
1470 int rc;
1471
1472 rc = check_dev(dev);
1473 if (rc < 0)
1474 return rc;
1475
Nicola Soranzoa1a6ee72009-02-10 23:28:24 -03001476 return videobuf_querybuf(&fh->vb_vidq, b);
Mauro Carvalho Chehab195a4ef2007-11-11 13:17:17 -03001477}
1478
1479static int vidioc_qbuf(struct file *file, void *priv, struct v4l2_buffer *b)
1480{
1481 struct em28xx_fh *fh = priv;
1482 struct em28xx *dev = fh->dev;
Mauro Carvalho Chehab195a4ef2007-11-11 13:17:17 -03001483 int rc;
1484
1485 rc = check_dev(dev);
1486 if (rc < 0)
1487 return rc;
1488
Nicola Soranzoa1a6ee72009-02-10 23:28:24 -03001489 return videobuf_qbuf(&fh->vb_vidq, b);
Mauro Carvalho Chehab195a4ef2007-11-11 13:17:17 -03001490}
1491
1492static int vidioc_dqbuf(struct file *file, void *priv, struct v4l2_buffer *b)
1493{
1494 struct em28xx_fh *fh = priv;
1495 struct em28xx *dev = fh->dev;
1496 int rc;
Mauro Carvalho Chehab195a4ef2007-11-11 13:17:17 -03001497
1498 rc = check_dev(dev);
1499 if (rc < 0)
1500 return rc;
1501
Nicola Soranzoa1a6ee72009-02-10 23:28:24 -03001502 return videobuf_dqbuf(&fh->vb_vidq, b, file->f_flags & O_NONBLOCK);
Mauro Carvalho Chehab195a4ef2007-11-11 13:17:17 -03001503}
1504
Mauro Carvalho Chehabad0ebb92008-04-13 14:37:52 -03001505#ifdef CONFIG_VIDEO_V4L1_COMPAT
Mauro Carvalho Chehabf245e542008-04-13 14:41:23 -03001506static int vidiocgmbuf(struct file *file, void *priv, struct video_mbuf *mbuf)
Mauro Carvalho Chehabad0ebb92008-04-13 14:37:52 -03001507{
Mauro Carvalho Chehabf245e542008-04-13 14:41:23 -03001508 struct em28xx_fh *fh = priv;
Mauro Carvalho Chehabad0ebb92008-04-13 14:37:52 -03001509
Mauro Carvalho Chehabf245e542008-04-13 14:41:23 -03001510 return videobuf_cgmbuf(&fh->vb_vidq, mbuf, 8);
Mauro Carvalho Chehabad0ebb92008-04-13 14:37:52 -03001511}
1512#endif
1513
1514
Mauro Carvalho Chehab0be43752008-01-05 17:22:01 -03001515/* ----------------------------------------------------------- */
1516/* RADIO ESPECIFIC IOCTLS */
1517/* ----------------------------------------------------------- */
1518
1519static int radio_querycap(struct file *file, void *priv,
1520 struct v4l2_capability *cap)
1521{
1522 struct em28xx *dev = ((struct em28xx_fh *)priv)->dev;
1523
1524 strlcpy(cap->driver, "em28xx", sizeof(cap->driver));
1525 strlcpy(cap->card, em28xx_boards[dev->model].name, sizeof(cap->card));
Thierry MERLEcb977162009-01-20 18:01:33 -03001526 usb_make_path(dev->udev, cap->bus_info, sizeof(cap->bus_info));
Mauro Carvalho Chehab0be43752008-01-05 17:22:01 -03001527
1528 cap->version = EM28XX_VERSION_CODE;
1529 cap->capabilities = V4L2_CAP_TUNER;
1530 return 0;
1531}
1532
1533static int radio_g_tuner(struct file *file, void *priv,
1534 struct v4l2_tuner *t)
1535{
1536 struct em28xx *dev = ((struct em28xx_fh *)priv)->dev;
1537
1538 if (unlikely(t->index > 0))
1539 return -EINVAL;
1540
1541 strcpy(t->name, "Radio");
1542 t->type = V4L2_TUNER_RADIO;
1543
Mauro Carvalho Chehabefc52a92008-12-16 22:04:56 -03001544 mutex_lock(&dev->lock);
Douglas Schilling Landgraff2cf2502009-03-31 17:10:58 -03001545 v4l2_device_call_all(&dev->v4l2_dev, 0, tuner, g_tuner, t);
Mauro Carvalho Chehabefc52a92008-12-16 22:04:56 -03001546 mutex_unlock(&dev->lock);
1547
Mauro Carvalho Chehab0be43752008-01-05 17:22:01 -03001548 return 0;
1549}
1550
1551static int radio_enum_input(struct file *file, void *priv,
1552 struct v4l2_input *i)
1553{
1554 if (i->index != 0)
1555 return -EINVAL;
1556 strcpy(i->name, "Radio");
1557 i->type = V4L2_INPUT_TYPE_TUNER;
1558
1559 return 0;
1560}
1561
1562static int radio_g_audio(struct file *file, void *priv, struct v4l2_audio *a)
1563{
1564 if (unlikely(a->index))
1565 return -EINVAL;
1566
1567 strcpy(a->name, "Radio");
1568 return 0;
1569}
1570
1571static int radio_s_tuner(struct file *file, void *priv,
1572 struct v4l2_tuner *t)
1573{
1574 struct em28xx *dev = ((struct em28xx_fh *)priv)->dev;
1575
1576 if (0 != t->index)
1577 return -EINVAL;
1578
Mauro Carvalho Chehabefc52a92008-12-16 22:04:56 -03001579 mutex_lock(&dev->lock);
Douglas Schilling Landgraff2cf2502009-03-31 17:10:58 -03001580 v4l2_device_call_all(&dev->v4l2_dev, 0, tuner, s_tuner, t);
Mauro Carvalho Chehabefc52a92008-12-16 22:04:56 -03001581 mutex_unlock(&dev->lock);
Mauro Carvalho Chehab0be43752008-01-05 17:22:01 -03001582
1583 return 0;
1584}
1585
1586static int radio_s_audio(struct file *file, void *fh,
1587 struct v4l2_audio *a)
1588{
1589 return 0;
1590}
1591
1592static int radio_s_input(struct file *file, void *fh, unsigned int i)
1593{
1594 return 0;
1595}
1596
1597static int radio_queryctrl(struct file *file, void *priv,
1598 struct v4l2_queryctrl *qc)
1599{
1600 int i;
1601
1602 if (qc->id < V4L2_CID_BASE ||
1603 qc->id >= V4L2_CID_LASTP1)
1604 return -EINVAL;
1605
1606 for (i = 0; i < ARRAY_SIZE(em28xx_qctrl); i++) {
1607 if (qc->id && qc->id == em28xx_qctrl[i].id) {
1608 memcpy(qc, &(em28xx_qctrl[i]), sizeof(*qc));
1609 return 0;
1610 }
1611 }
1612
1613 return -EINVAL;
1614}
1615
Mauro Carvalho Chehab195a4ef2007-11-11 13:17:17 -03001616/*
Mauro Carvalho Chehab3acf2802005-11-08 21:38:27 -08001617 * em28xx_v4l2_open()
akpm@osdl.orga6c2ba22005-11-08 21:37:07 -08001618 * inits the device and starts isoc transfer
1619 */
Hans Verkuilbec43662008-12-30 06:58:20 -03001620static int em28xx_v4l2_open(struct file *filp)
akpm@osdl.orga6c2ba22005-11-08 21:37:07 -08001621{
Hans Verkuilbec43662008-12-30 06:58:20 -03001622 int minor = video_devdata(filp)->minor;
Mauro Carvalho Chehab1a23f812008-12-28 22:18:14 -03001623 int errCode = 0, radio;
1624 struct em28xx *dev;
1625 enum v4l2_buf_type fh_type;
Mauro Carvalho Chehaba3a048c2007-11-10 22:21:01 -03001626 struct em28xx_fh *fh;
Markus Rechberger9c755412005-11-08 21:37:52 -08001627
Hans Verkuilbec43662008-12-30 06:58:20 -03001628 dev = em28xx_get_device(minor, &fh_type, &radio);
Mauro Carvalho Chehabefc52a92008-12-16 22:04:56 -03001629
Mauro Carvalho Chehab818a5572008-11-20 10:30:26 -03001630 if (NULL == dev)
Mauro Carvalho Chehabe5589be2006-01-23 17:11:08 -02001631 return -ENODEV;
Mauro Carvalho Chehab818a5572008-11-20 10:30:26 -03001632
1633 mutex_lock(&dev->lock);
Markus Rechberger9c755412005-11-08 21:37:52 -08001634
Mauro Carvalho Chehabe5589be2006-01-23 17:11:08 -02001635 em28xx_videodbg("open minor=%d type=%s users=%d\n",
Aidan Thorntond7aa8022008-04-13 14:38:47 -03001636 minor, v4l2_type_names[fh_type], dev->users);
akpm@osdl.orga6c2ba22005-11-08 21:37:07 -08001637
akpm@osdl.orga6c2ba22005-11-08 21:37:07 -08001638
Mauro Carvalho Chehabc67ec532008-04-17 21:48:00 -03001639 fh = kzalloc(sizeof(struct em28xx_fh), GFP_KERNEL);
Mauro Carvalho Chehaba3a048c2007-11-10 22:21:01 -03001640 if (!fh) {
1641 em28xx_errdev("em28xx-video.c: Out of memory?!\n");
Mauro Carvalho Chehab818a5572008-11-20 10:30:26 -03001642 mutex_unlock(&dev->lock);
Mauro Carvalho Chehaba3a048c2007-11-10 22:21:01 -03001643 return -ENOMEM;
akpm@osdl.orga6c2ba22005-11-08 21:37:07 -08001644 }
Mauro Carvalho Chehaba3a048c2007-11-10 22:21:01 -03001645 fh->dev = dev;
Mauro Carvalho Chehab0be43752008-01-05 17:22:01 -03001646 fh->radio = radio;
Aidan Thorntond7aa8022008-04-13 14:38:47 -03001647 fh->type = fh_type;
Mauro Carvalho Chehaba3a048c2007-11-10 22:21:01 -03001648 filp->private_data = fh;
akpm@osdl.orga6c2ba22005-11-08 21:37:07 -08001649
Aidan Thorntond7aa8022008-04-13 14:38:47 -03001650 if (fh->type == V4L2_BUF_TYPE_VIDEO_CAPTURE && dev->users == 0) {
Mauro Carvalho Chehabc67ec532008-04-17 21:48:00 -03001651 em28xx_set_mode(dev, EM28XX_ANALOG_MODE);
Mauro Carvalho Chehab3687e1e2008-02-08 15:44:25 -03001652 em28xx_set_alternate(dev);
Mauro Carvalho Chehabe5589be2006-01-23 17:11:08 -02001653 em28xx_resolution_set(dev);
akpm@osdl.orga6c2ba22005-11-08 21:37:07 -08001654
Mauro Carvalho Chehabc67ec532008-04-17 21:48:00 -03001655 /* Needed, since GPIO might have disabled power of
1656 some i2c device
1657 */
Mauro Carvalho Chehab1a23f812008-12-28 22:18:14 -03001658 em28xx_wake_i2c(dev);
Mauro Carvalho Chehabc67ec532008-04-17 21:48:00 -03001659
Mauro Carvalho Chehabe5589be2006-01-23 17:11:08 -02001660 }
Mauro Carvalho Chehab0be43752008-01-05 17:22:01 -03001661 if (fh->radio) {
1662 em28xx_videodbg("video_open: setting radio device\n");
Douglas Schilling Landgraff2cf2502009-03-31 17:10:58 -03001663 v4l2_device_call_all(&dev->v4l2_dev, 0, tuner, s_radio);
Mauro Carvalho Chehab0be43752008-01-05 17:22:01 -03001664 }
akpm@osdl.orga6c2ba22005-11-08 21:37:07 -08001665
1666 dev->users++;
akpm@osdl.orga6c2ba22005-11-08 21:37:07 -08001667
Mauro Carvalho Chehabad0ebb92008-04-13 14:37:52 -03001668 videobuf_queue_vmalloc_init(&fh->vb_vidq, &em28xx_video_qops,
1669 NULL, &dev->slock, fh->type, V4L2_FIELD_INTERLACED,
1670 sizeof(struct em28xx_buffer), fh);
1671
Ingo Molnar3593cab2006-02-07 06:49:14 -02001672 mutex_unlock(&dev->lock);
Mauro Carvalho Chehabc67ec532008-04-17 21:48:00 -03001673
akpm@osdl.orga6c2ba22005-11-08 21:37:07 -08001674 return errCode;
1675}
1676
1677/*
Mauro Carvalho Chehab3acf2802005-11-08 21:38:27 -08001678 * em28xx_realease_resources()
akpm@osdl.orga6c2ba22005-11-08 21:37:07 -08001679 * unregisters the v4l2,i2c and usb devices
1680 * called when the device gets disconected or at module unload
1681*/
Mauro Carvalho Chehab1a23f812008-12-28 22:18:14 -03001682void em28xx_release_analog_resources(struct em28xx *dev)
akpm@osdl.orga6c2ba22005-11-08 21:37:07 -08001683{
akpm@osdl.orga6c2ba22005-11-08 21:37:07 -08001684
Mauro Carvalho Chehabe5589be2006-01-23 17:11:08 -02001685 /*FIXME: I2C IR should be disconnected */
1686
Mauro Carvalho Chehab0be43752008-01-05 17:22:01 -03001687 if (dev->radio_dev) {
1688 if (-1 != dev->radio_dev->minor)
1689 video_unregister_device(dev->radio_dev);
1690 else
1691 video_device_release(dev->radio_dev);
1692 dev->radio_dev = NULL;
1693 }
1694 if (dev->vbi_dev) {
Devin Heitmueller49240442008-11-12 02:05:15 -03001695 em28xx_info("V4L2 device /dev/vbi%d deregistered\n",
1696 dev->vbi_dev->num);
Mauro Carvalho Chehab0be43752008-01-05 17:22:01 -03001697 if (-1 != dev->vbi_dev->minor)
1698 video_unregister_device(dev->vbi_dev);
1699 else
1700 video_device_release(dev->vbi_dev);
1701 dev->vbi_dev = NULL;
1702 }
1703 if (dev->vdev) {
Devin Heitmueller49240442008-11-12 02:05:15 -03001704 em28xx_info("V4L2 device /dev/video%d deregistered\n",
1705 dev->vdev->num);
Mauro Carvalho Chehab0be43752008-01-05 17:22:01 -03001706 if (-1 != dev->vdev->minor)
1707 video_unregister_device(dev->vdev);
1708 else
1709 video_device_release(dev->vdev);
1710 dev->vdev = NULL;
1711 }
akpm@osdl.orga6c2ba22005-11-08 21:37:07 -08001712}
1713
1714/*
Mauro Carvalho Chehab3acf2802005-11-08 21:38:27 -08001715 * em28xx_v4l2_close()
Douglas Schilling Landgraf6ea54d92008-04-17 21:41:10 -03001716 * stops streaming and deallocates all resources allocated by the v4l2
1717 * calls and ioctls
akpm@osdl.orga6c2ba22005-11-08 21:37:07 -08001718 */
Hans Verkuilbec43662008-12-30 06:58:20 -03001719static int em28xx_v4l2_close(struct file *filp)
akpm@osdl.orga6c2ba22005-11-08 21:37:07 -08001720{
Mauro Carvalho Chehaba3a048c2007-11-10 22:21:01 -03001721 struct em28xx_fh *fh = filp->private_data;
1722 struct em28xx *dev = fh->dev;
1723 int errCode;
akpm@osdl.orga6c2ba22005-11-08 21:37:07 -08001724
Mauro Carvalho Chehabeac94352005-11-08 21:38:43 -08001725 em28xx_videodbg("users=%d\n", dev->users);
akpm@osdl.orga6c2ba22005-11-08 21:37:07 -08001726
Mauro Carvalho Chehaba2254522007-11-11 01:08:26 -03001727
Mauro Carvalho Chehab78313642008-12-16 20:00:49 -03001728 mutex_lock(&dev->lock);
Mauro Carvalho Chehaba2254522007-11-11 01:08:26 -03001729 if (res_check(fh))
1730 res_free(fh);
1731
Mauro Carvalho Chehaba3a048c2007-11-10 22:21:01 -03001732 if (dev->users == 1) {
Mauro Carvalho Chehabad0ebb92008-04-13 14:37:52 -03001733 videobuf_stop(&fh->vb_vidq);
1734 videobuf_mmap_free(&fh->vb_vidq);
akpm@osdl.orga6c2ba22005-11-08 21:37:07 -08001735
Mauro Carvalho Chehaba3a048c2007-11-10 22:21:01 -03001736 /* the device is already disconnect,
1737 free the remaining resources */
1738 if (dev->state & DEV_DISCONNECTED) {
1739 em28xx_release_resources(dev);
1740 mutex_unlock(&dev->lock);
1741 kfree(dev);
1742 return 0;
1743 }
1744
Mauro Carvalho Chehabeb6c9632008-12-05 10:39:12 -03001745 /* Save some power by putting tuner to sleep */
Hans Verkuil7c9fc9d2009-04-01 03:49:59 -03001746 v4l2_device_call_all(&dev->v4l2_dev, 0, tuner, s_standby);
Mauro Carvalho Chehabeb6c9632008-12-05 10:39:12 -03001747
Aidan Thorntond7aa8022008-04-13 14:38:47 -03001748 /* do this before setting alternate! */
1749 em28xx_uninit_isoc(dev);
Mauro Carvalho Chehab2fe3e2e2008-11-27 09:10:40 -03001750 em28xx_set_mode(dev, EM28XX_SUSPEND);
Aidan Thorntond7aa8022008-04-13 14:38:47 -03001751
Mauro Carvalho Chehaba3a048c2007-11-10 22:21:01 -03001752 /* set alternate 0 */
1753 dev->alt = 0;
1754 em28xx_videodbg("setting alternate 0\n");
1755 errCode = usb_set_interface(dev->udev, 0, 0);
1756 if (errCode < 0) {
1757 em28xx_errdev("cannot change alternate number to "
1758 "0 (error=%i)\n", errCode);
1759 }
akpm@osdl.orga6c2ba22005-11-08 21:37:07 -08001760 }
Mauro Carvalho Chehaba3a048c2007-11-10 22:21:01 -03001761 kfree(fh);
akpm@osdl.orga6c2ba22005-11-08 21:37:07 -08001762 dev->users--;
1763 wake_up_interruptible_nr(&dev->open, 1);
Ingo Molnar3593cab2006-02-07 06:49:14 -02001764 mutex_unlock(&dev->lock);
akpm@osdl.orga6c2ba22005-11-08 21:37:07 -08001765 return 0;
1766}
1767
1768/*
Mauro Carvalho Chehab3acf2802005-11-08 21:38:27 -08001769 * em28xx_v4l2_read()
akpm@osdl.orga6c2ba22005-11-08 21:37:07 -08001770 * will allocate buffers when called for the first time
1771 */
1772static ssize_t
Douglas Schilling Landgraf6ea54d92008-04-17 21:41:10 -03001773em28xx_v4l2_read(struct file *filp, char __user *buf, size_t count,
Mauro Carvalho Chehabf245e542008-04-13 14:41:23 -03001774 loff_t *pos)
akpm@osdl.orga6c2ba22005-11-08 21:37:07 -08001775{
Mauro Carvalho Chehaba3a048c2007-11-10 22:21:01 -03001776 struct em28xx_fh *fh = filp->private_data;
1777 struct em28xx *dev = fh->dev;
Mauro Carvalho Chehabad0ebb92008-04-13 14:37:52 -03001778 int rc;
1779
1780 rc = check_dev(dev);
1781 if (rc < 0)
1782 return rc;
akpm@osdl.orga6c2ba22005-11-08 21:37:07 -08001783
Mauro Carvalho Chehab9e31ced2007-11-11 01:13:49 -03001784 /* FIXME: read() is not prepared to allow changing the video
1785 resolution while streaming. Seems a bug at em28xx_set_fmt
1786 */
Mauro Carvalho Chehaba2254522007-11-11 01:08:26 -03001787
Mauro Carvalho Chehabad0ebb92008-04-13 14:37:52 -03001788 if (fh->type == V4L2_BUF_TYPE_VIDEO_CAPTURE) {
Mauro Carvalho Chehab29b59412008-12-16 20:19:24 -03001789 mutex_lock(&dev->lock);
1790 rc = res_get(fh);
1791 mutex_unlock(&dev->lock);
1792
1793 if (unlikely(rc < 0))
1794 return rc;
Mauro Carvalho Chehaba2254522007-11-11 01:08:26 -03001795
Mauro Carvalho Chehabad0ebb92008-04-13 14:37:52 -03001796 return videobuf_read_stream(&fh->vb_vidq, buf, count, pos, 0,
1797 filp->f_flags & O_NONBLOCK);
Mauro Carvalho Chehabe5589be2006-01-23 17:11:08 -02001798 }
Mauro Carvalho Chehabad0ebb92008-04-13 14:37:52 -03001799 return 0;
akpm@osdl.orga6c2ba22005-11-08 21:37:07 -08001800}
1801
1802/*
Mauro Carvalho Chehab3acf2802005-11-08 21:38:27 -08001803 * em28xx_v4l2_poll()
akpm@osdl.orga6c2ba22005-11-08 21:37:07 -08001804 * will allocate buffers when called for the first time
1805 */
Nicola Soranzoa1a6ee72009-02-10 23:28:24 -03001806static unsigned int em28xx_v4l2_poll(struct file *filp, poll_table *wait)
akpm@osdl.orga6c2ba22005-11-08 21:37:07 -08001807{
Mauro Carvalho Chehaba3a048c2007-11-10 22:21:01 -03001808 struct em28xx_fh *fh = filp->private_data;
1809 struct em28xx *dev = fh->dev;
Mauro Carvalho Chehabad0ebb92008-04-13 14:37:52 -03001810 int rc;
1811
1812 rc = check_dev(dev);
1813 if (rc < 0)
1814 return rc;
akpm@osdl.orga6c2ba22005-11-08 21:37:07 -08001815
Mauro Carvalho Chehab29b59412008-12-16 20:19:24 -03001816 mutex_lock(&dev->lock);
1817 rc = res_get(fh);
1818 mutex_unlock(&dev->lock);
1819
1820 if (unlikely(rc < 0))
Mauro Carvalho Chehaba2254522007-11-11 01:08:26 -03001821 return POLLERR;
1822
Mauro Carvalho Chehabad0ebb92008-04-13 14:37:52 -03001823 if (V4L2_BUF_TYPE_VIDEO_CAPTURE != fh->type)
1824 return POLLERR;
akpm@osdl.orga6c2ba22005-11-08 21:37:07 -08001825
Mauro Carvalho Chehabad0ebb92008-04-13 14:37:52 -03001826 return videobuf_poll_stream(filp, &fh->vb_vidq, wait);
akpm@osdl.orga6c2ba22005-11-08 21:37:07 -08001827}
1828
1829/*
Mauro Carvalho Chehab3acf2802005-11-08 21:38:27 -08001830 * em28xx_v4l2_mmap()
akpm@osdl.orga6c2ba22005-11-08 21:37:07 -08001831 */
Mauro Carvalho Chehab3acf2802005-11-08 21:38:27 -08001832static int em28xx_v4l2_mmap(struct file *filp, struct vm_area_struct *vma)
akpm@osdl.orga6c2ba22005-11-08 21:37:07 -08001833{
Mauro Carvalho Chehaba3a048c2007-11-10 22:21:01 -03001834 struct em28xx_fh *fh = filp->private_data;
1835 struct em28xx *dev = fh->dev;
Mauro Carvalho Chehabad0ebb92008-04-13 14:37:52 -03001836 int rc;
Markus Rechberger9c755412005-11-08 21:37:52 -08001837
Mauro Carvalho Chehabad0ebb92008-04-13 14:37:52 -03001838 rc = check_dev(dev);
1839 if (rc < 0)
1840 return rc;
Mauro Carvalho Chehaba3a048c2007-11-10 22:21:01 -03001841
Mauro Carvalho Chehab29b59412008-12-16 20:19:24 -03001842 mutex_lock(&dev->lock);
1843 rc = res_get(fh);
1844 mutex_unlock(&dev->lock);
1845
1846 if (unlikely(rc < 0))
1847 return rc;
1848
Mauro Carvalho Chehabad0ebb92008-04-13 14:37:52 -03001849 rc = videobuf_mmap_mapper(&fh->vb_vidq, vma);
akpm@osdl.orga6c2ba22005-11-08 21:37:07 -08001850
Mauro Carvalho Chehabad0ebb92008-04-13 14:37:52 -03001851 em28xx_videodbg("vma start=0x%08lx, size=%ld, ret=%d\n",
1852 (unsigned long)vma->vm_start,
1853 (unsigned long)vma->vm_end-(unsigned long)vma->vm_start,
1854 rc);
akpm@osdl.orga6c2ba22005-11-08 21:37:07 -08001855
Mauro Carvalho Chehabad0ebb92008-04-13 14:37:52 -03001856 return rc;
akpm@osdl.orga6c2ba22005-11-08 21:37:07 -08001857}
1858
Hans Verkuilbec43662008-12-30 06:58:20 -03001859static const struct v4l2_file_operations em28xx_v4l_fops = {
Mauro Carvalho Chehab195a4ef2007-11-11 13:17:17 -03001860 .owner = THIS_MODULE,
1861 .open = em28xx_v4l2_open,
1862 .release = em28xx_v4l2_close,
1863 .read = em28xx_v4l2_read,
1864 .poll = em28xx_v4l2_poll,
1865 .mmap = em28xx_v4l2_mmap,
1866 .ioctl = video_ioctl2,
akpm@osdl.orga6c2ba22005-11-08 21:37:07 -08001867};
1868
Hans Verkuila3998102008-07-21 02:57:38 -03001869static const struct v4l2_ioctl_ops video_ioctl_ops = {
Mauro Carvalho Chehab195a4ef2007-11-11 13:17:17 -03001870 .vidioc_querycap = vidioc_querycap,
Hans Verkuil78b526a2008-05-28 12:16:41 -03001871 .vidioc_enum_fmt_vid_cap = vidioc_enum_fmt_vid_cap,
1872 .vidioc_g_fmt_vid_cap = vidioc_g_fmt_vid_cap,
1873 .vidioc_try_fmt_vid_cap = vidioc_try_fmt_vid_cap,
1874 .vidioc_s_fmt_vid_cap = vidioc_s_fmt_vid_cap,
Mauro Carvalho Chehab195a4ef2007-11-11 13:17:17 -03001875 .vidioc_g_audio = vidioc_g_audio,
1876 .vidioc_s_audio = vidioc_s_audio,
1877 .vidioc_cropcap = vidioc_cropcap,
1878
Hans Verkuil78b526a2008-05-28 12:16:41 -03001879 .vidioc_g_fmt_sliced_vbi_cap = vidioc_g_fmt_sliced_vbi_cap,
1880 .vidioc_try_fmt_sliced_vbi_cap = vidioc_try_set_sliced_vbi_cap,
1881 .vidioc_s_fmt_sliced_vbi_cap = vidioc_try_set_sliced_vbi_cap,
Mauro Carvalho Chehab195a4ef2007-11-11 13:17:17 -03001882
1883 .vidioc_reqbufs = vidioc_reqbufs,
1884 .vidioc_querybuf = vidioc_querybuf,
1885 .vidioc_qbuf = vidioc_qbuf,
1886 .vidioc_dqbuf = vidioc_dqbuf,
1887 .vidioc_s_std = vidioc_s_std,
1888 .vidioc_enum_input = vidioc_enum_input,
1889 .vidioc_g_input = vidioc_g_input,
1890 .vidioc_s_input = vidioc_s_input,
1891 .vidioc_queryctrl = vidioc_queryctrl,
1892 .vidioc_g_ctrl = vidioc_g_ctrl,
1893 .vidioc_s_ctrl = vidioc_s_ctrl,
1894 .vidioc_streamon = vidioc_streamon,
1895 .vidioc_streamoff = vidioc_streamoff,
1896 .vidioc_g_tuner = vidioc_g_tuner,
1897 .vidioc_s_tuner = vidioc_s_tuner,
1898 .vidioc_g_frequency = vidioc_g_frequency,
1899 .vidioc_s_frequency = vidioc_s_frequency,
Mauro Carvalho Chehab1e7ad562008-02-06 09:00:41 -03001900#ifdef CONFIG_VIDEO_ADV_DEBUG
1901 .vidioc_g_register = vidioc_g_register,
1902 .vidioc_s_register = vidioc_s_register,
Mauro Carvalho Chehab14983d82008-12-22 20:58:41 -03001903 .vidioc_g_chip_ident = vidioc_g_chip_ident,
Mauro Carvalho Chehab1e7ad562008-02-06 09:00:41 -03001904#endif
Mauro Carvalho Chehabad0ebb92008-04-13 14:37:52 -03001905#ifdef CONFIG_VIDEO_V4L1_COMPAT
1906 .vidiocgmbuf = vidiocgmbuf,
1907#endif
Hans Verkuila3998102008-07-21 02:57:38 -03001908};
1909
1910static const struct video_device em28xx_video_template = {
1911 .fops = &em28xx_v4l_fops,
1912 .release = video_device_release,
1913 .ioctl_ops = &video_ioctl_ops,
1914
1915 .minor = -1,
Mauro Carvalho Chehab195a4ef2007-11-11 13:17:17 -03001916
1917 .tvnorms = V4L2_STD_ALL,
Mauro Carvalho Chehab7d497f82007-11-11 14:15:34 -03001918 .current_norm = V4L2_STD_PAL,
Mauro Carvalho Chehab195a4ef2007-11-11 13:17:17 -03001919};
1920
Hans Verkuilbec43662008-12-30 06:58:20 -03001921static const struct v4l2_file_operations radio_fops = {
Hans Verkuila3998102008-07-21 02:57:38 -03001922 .owner = THIS_MODULE,
1923 .open = em28xx_v4l2_open,
1924 .release = em28xx_v4l2_close,
1925 .ioctl = video_ioctl2,
Hans Verkuila3998102008-07-21 02:57:38 -03001926};
1927
1928static const struct v4l2_ioctl_ops radio_ioctl_ops = {
Mauro Carvalho Chehab0be43752008-01-05 17:22:01 -03001929 .vidioc_querycap = radio_querycap,
1930 .vidioc_g_tuner = radio_g_tuner,
1931 .vidioc_enum_input = radio_enum_input,
1932 .vidioc_g_audio = radio_g_audio,
1933 .vidioc_s_tuner = radio_s_tuner,
1934 .vidioc_s_audio = radio_s_audio,
1935 .vidioc_s_input = radio_s_input,
1936 .vidioc_queryctrl = radio_queryctrl,
1937 .vidioc_g_ctrl = vidioc_g_ctrl,
1938 .vidioc_s_ctrl = vidioc_s_ctrl,
1939 .vidioc_g_frequency = vidioc_g_frequency,
1940 .vidioc_s_frequency = vidioc_s_frequency,
Mauro Carvalho Chehab1e7ad562008-02-06 09:00:41 -03001941#ifdef CONFIG_VIDEO_ADV_DEBUG
1942 .vidioc_g_register = vidioc_g_register,
1943 .vidioc_s_register = vidioc_s_register,
1944#endif
Mauro Carvalho Chehab0be43752008-01-05 17:22:01 -03001945};
1946
Hans Verkuila3998102008-07-21 02:57:38 -03001947static struct video_device em28xx_radio_template = {
1948 .name = "em28xx-radio",
Hans Verkuila3998102008-07-21 02:57:38 -03001949 .fops = &radio_fops,
1950 .ioctl_ops = &radio_ioctl_ops,
1951 .minor = -1,
1952};
1953
Douglas Schilling Landgraf6ea54d92008-04-17 21:41:10 -03001954/******************************** usb interface ******************************/
akpm@osdl.orga6c2ba22005-11-08 21:37:07 -08001955
Mauro Carvalho Chehab6d794682008-01-05 09:57:31 -03001956
Mauro Carvalho Chehab6d794682008-01-05 09:57:31 -03001957
Adrian Bunk532fe652008-01-28 22:10:48 -03001958static struct video_device *em28xx_vdev_init(struct em28xx *dev,
Nicola Soranzoa1a6ee72009-02-10 23:28:24 -03001959 const struct video_device *template,
1960 const char *type_name)
Mauro Carvalho Chehab0be43752008-01-05 17:22:01 -03001961{
1962 struct video_device *vfd;
1963
1964 vfd = video_device_alloc();
1965 if (NULL == vfd)
1966 return NULL;
Douglas Schilling Landgraff2cf2502009-03-31 17:10:58 -03001967
1968 *vfd = *template;
1969 vfd->minor = -1;
1970 vfd->v4l2_dev = &dev->v4l2_dev;
1971 vfd->release = video_device_release;
1972 vfd->debug = video_debug;
Mauro Carvalho Chehab0be43752008-01-05 17:22:01 -03001973
1974 snprintf(vfd->name, sizeof(vfd->name), "%s %s",
1975 dev->name, type_name);
1976
1977 return vfd;
1978}
1979
Mauro Carvalho Chehab2e5ef2d2008-12-28 22:26:36 -03001980int em28xx_register_analog_devices(struct em28xx *dev)
Mauro Carvalho Chehab1a23f812008-12-28 22:18:14 -03001981{
Robert Krakora6e7b9ea2009-01-18 21:59:34 -03001982 u8 val;
Mauro Carvalho Chehab2e5ef2d2008-12-28 22:26:36 -03001983 int ret;
1984
Mauro Carvalho Chehab1a23f812008-12-28 22:18:14 -03001985 printk(KERN_INFO "%s: v4l2 driver version %d.%d.%d\n",
1986 dev->name,
1987 (EM28XX_VERSION_CODE >> 16) & 0xff,
1988 (EM28XX_VERSION_CODE >> 8) & 0xff, EM28XX_VERSION_CODE & 0xff);
1989
Mauro Carvalho Chehab1a23f812008-12-28 22:18:14 -03001990 /* set default norm */
1991 dev->norm = em28xx_video_template.current_norm;
Mauro Carvalho Chehab1a23f812008-12-28 22:18:14 -03001992 dev->interlaced = EM28XX_INTERLACED_DEFAULT;
Mauro Carvalho Chehab24c3c412009-01-07 22:49:25 -03001993 dev->ctl_input = 0;
Mauro Carvalho Chehab1a23f812008-12-28 22:18:14 -03001994
Mauro Carvalho Chehab24c3c412009-01-07 22:49:25 -03001995 /* Analog specific initialization */
1996 dev->format = &format[0];
Mauro Carvalho Chehabed5f1432009-07-02 17:34:04 -03001997 em28xx_set_video_format(dev, format[0].fourcc,
1998 norm_maxw(dev), norm_maxh(dev));
1999
Mauro Carvalho Chehab24c3c412009-01-07 22:49:25 -03002000 video_mux(dev, dev->ctl_input);
2001
2002 /* Audio defaults */
2003 dev->mute = 1;
2004 dev->volume = 0x1f;
2005
2006 /* enable vbi capturing */
2007
2008/* em28xx_write_reg(dev, EM28XX_R0E_AUDIOSRC, 0xc0); audio register */
Nicola Soranzoa1a6ee72009-02-10 23:28:24 -03002009 val = (u8)em28xx_read_reg(dev, EM28XX_R0F_XCLK);
2010 em28xx_write_reg(dev, EM28XX_R0F_XCLK,
2011 (EM28XX_XCLK_AUDIO_UNMUTE | val));
Mauro Carvalho Chehab24c3c412009-01-07 22:49:25 -03002012 em28xx_write_reg(dev, EM28XX_R11_VINCTRL, 0x51);
2013
2014 em28xx_set_outfmt(dev);
2015 em28xx_colorlevels_set_default(dev);
2016 em28xx_compression_disable(dev);
Mauro Carvalho Chehab1a23f812008-12-28 22:18:14 -03002017
Mauro Carvalho Chehab818a5572008-11-20 10:30:26 -03002018 /* allocate and fill video video_device struct */
2019 dev->vdev = em28xx_vdev_init(dev, &em28xx_video_template, "video");
2020 if (!dev->vdev) {
2021 em28xx_errdev("cannot allocate video_device.\n");
2022 return -ENODEV;
2023 }
2024
2025 /* register v4l2 video video_device */
2026 ret = video_register_device(dev->vdev, VFL_TYPE_GRABBER,
2027 video_nr[dev->devno]);
2028 if (ret) {
2029 em28xx_errdev("unable to register video device (error=%i).\n",
2030 ret);
2031 return ret;
2032 }
2033
2034 /* Allocate and fill vbi video_device struct */
2035 dev->vbi_dev = em28xx_vdev_init(dev, &em28xx_video_template, "vbi");
2036
2037 /* register v4l2 vbi video_device */
2038 ret = video_register_device(dev->vbi_dev, VFL_TYPE_VBI,
2039 vbi_nr[dev->devno]);
2040 if (ret < 0) {
2041 em28xx_errdev("unable to register vbi device\n");
2042 return ret;
2043 }
2044
2045 if (em28xx_boards[dev->model].radio.type == EM28XX_RADIO) {
Nicola Soranzoa1a6ee72009-02-10 23:28:24 -03002046 dev->radio_dev = em28xx_vdev_init(dev, &em28xx_radio_template,
2047 "radio");
Mauro Carvalho Chehab818a5572008-11-20 10:30:26 -03002048 if (!dev->radio_dev) {
2049 em28xx_errdev("cannot allocate video_device.\n");
2050 return -ENODEV;
2051 }
2052 ret = video_register_device(dev->radio_dev, VFL_TYPE_RADIO,
2053 radio_nr[dev->devno]);
2054 if (ret < 0) {
2055 em28xx_errdev("can't register radio device\n");
2056 return ret;
2057 }
2058 em28xx_info("Registered radio device as /dev/radio%d\n",
2059 dev->radio_dev->num);
2060 }
2061
2062 em28xx_info("V4L2 device registered as /dev/video%d and /dev/vbi%d\n",
2063 dev->vdev->num, dev->vbi_dev->num);
2064
2065 return 0;
2066}