akpm@osdl.org | a6c2ba2 | 2005-11-08 21:37:07 -0800 | [diff] [blame] | 1 | /* |
Douglas Schilling Landgraf | 6ea54d9 | 2008-04-17 21:41:10 -0300 | [diff] [blame] | 2 | em28xx-video.c - driver for Empia EM2800/EM2820/2840 USB |
| 3 | video capture devices |
akpm@osdl.org | a6c2ba2 | 2005-11-08 21:37:07 -0800 | [diff] [blame] | 4 | |
Mauro Carvalho Chehab | f7abcd3 | 2005-11-08 21:38:25 -0800 | [diff] [blame] | 5 | Copyright (C) 2005 Ludovico Cavedon <cavedon@sssup.it> |
| 6 | Markus Rechberger <mrechberger@gmail.com> |
Mauro Carvalho Chehab | 2e7c6dc | 2006-04-03 07:53:40 -0300 | [diff] [blame] | 7 | Mauro Carvalho Chehab <mchehab@infradead.org> |
Mauro Carvalho Chehab | f7abcd3 | 2005-11-08 21:38:25 -0800 | [diff] [blame] | 8 | Sascha Sommer <saschasommer@freenet.de> |
akpm@osdl.org | a6c2ba2 | 2005-11-08 21:37:07 -0800 | [diff] [blame] | 9 | |
Mauro Carvalho Chehab | 439090d | 2006-01-23 17:10:54 -0200 | [diff] [blame] | 10 | Some parts based on SN9C10x PC Camera Controllers GPL driver made |
| 11 | by Luca Risolia <luca.risolia@studio.unibo.it> |
| 12 | |
akpm@osdl.org | a6c2ba2 | 2005-11-08 21:37:07 -0800 | [diff] [blame] | 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. |
| 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 Chehab | e5589be | 2006-01-23 17:11:08 -0200 | [diff] [blame] | 32 | #include <linux/bitmap.h> |
akpm@osdl.org | a6c2ba2 | 2005-11-08 21:37:07 -0800 | [diff] [blame] | 33 | #include <linux/usb.h> |
akpm@osdl.org | a6c2ba2 | 2005-11-08 21:37:07 -0800 | [diff] [blame] | 34 | #include <linux/i2c.h> |
Mauro Carvalho Chehab | b296fc6 | 2005-11-08 21:38:37 -0800 | [diff] [blame] | 35 | #include <linux/version.h> |
Trent Piepho | 6d35c8f | 2007-11-01 01:16:09 -0300 | [diff] [blame] | 36 | #include <linux/mm.h> |
Ingo Molnar | 1e4baed | 2006-01-15 07:52:23 -0200 | [diff] [blame] | 37 | #include <linux/mutex.h> |
akpm@osdl.org | a6c2ba2 | 2005-11-08 21:37:07 -0800 | [diff] [blame] | 38 | |
Mauro Carvalho Chehab | f7abcd3 | 2005-11-08 21:38:25 -0800 | [diff] [blame] | 39 | #include "em28xx.h" |
Mauro Carvalho Chehab | c0477ad | 2006-01-09 15:25:14 -0200 | [diff] [blame] | 40 | #include <media/v4l2-common.h> |
Hans Verkuil | 35ea11f | 2008-07-20 08:12:02 -0300 | [diff] [blame] | 41 | #include <media/v4l2-ioctl.h> |
Mauro Carvalho Chehab | 14983d8 | 2008-12-22 20:58:41 -0300 | [diff] [blame] | 42 | #include <media/v4l2-chip-ident.h> |
Hans Verkuil | 2474ed4 | 2006-03-19 12:35:57 -0300 | [diff] [blame] | 43 | #include <media/msp3400.h> |
Mauro Carvalho Chehab | ed08631 | 2008-01-24 06:59:20 -0300 | [diff] [blame] | 44 | #include <media/tuner.h> |
akpm@osdl.org | a6c2ba2 | 2005-11-08 21:37:07 -0800 | [diff] [blame] | 45 | |
Mauro Carvalho Chehab | f7abcd3 | 2005-11-08 21:38:25 -0800 | [diff] [blame] | 46 | #define DRIVER_AUTHOR "Ludovico Cavedon <cavedon@sssup.it>, " \ |
| 47 | "Markus Rechberger <mrechberger@gmail.com>, " \ |
Mauro Carvalho Chehab | 2e7c6dc | 2006-04-03 07:53:40 -0300 | [diff] [blame] | 48 | "Mauro Carvalho Chehab <mchehab@infradead.org>, " \ |
Mauro Carvalho Chehab | f7abcd3 | 2005-11-08 21:38:25 -0800 | [diff] [blame] | 49 | "Sascha Sommer <saschasommer@freenet.de>" |
akpm@osdl.org | a6c2ba2 | 2005-11-08 21:37:07 -0800 | [diff] [blame] | 50 | |
Mauro Carvalho Chehab | f7abcd3 | 2005-11-08 21:38:25 -0800 | [diff] [blame] | 51 | #define DRIVER_DESC "Empia em28xx based USB video device driver" |
Douglas Schilling Landgraf | f2cf250 | 2009-03-31 17:10:58 -0300 | [diff] [blame] | 52 | #define EM28XX_VERSION_CODE KERNEL_VERSION(0, 1, 2) |
akpm@osdl.org | a6c2ba2 | 2005-11-08 21:37:07 -0800 | [diff] [blame] | 53 | |
Mauro Carvalho Chehab | 3acf280 | 2005-11-08 21:38:27 -0800 | [diff] [blame] | 54 | #define em28xx_videodbg(fmt, arg...) do {\ |
Mauro Carvalho Chehab | 4ac9791 | 2005-11-08 21:37:43 -0800 | [diff] [blame] | 55 | if (video_debug) \ |
| 56 | printk(KERN_INFO "%s %s :"fmt, \ |
Harvey Harrison | d80e134 | 2008-04-08 23:20:00 -0300 | [diff] [blame] | 57 | dev->name, __func__ , ##arg); } while (0) |
akpm@osdl.org | a6c2ba2 | 2005-11-08 21:37:07 -0800 | [diff] [blame] | 58 | |
Mauro Carvalho Chehab | ad0ebb9 | 2008-04-13 14:37:52 -0300 | [diff] [blame] | 59 | static unsigned int isoc_debug; |
Mauro Carvalho Chehab | f245e54 | 2008-04-13 14:41:23 -0300 | [diff] [blame] | 60 | module_param(isoc_debug, int, 0644); |
| 61 | MODULE_PARM_DESC(isoc_debug, "enable debug messages [isoc transfers]"); |
Mauro Carvalho Chehab | ad0ebb9 | 2008-04-13 14:37:52 -0300 | [diff] [blame] | 62 | |
Douglas Schilling Landgraf | 6ea54d9 | 2008-04-17 21:41:10 -0300 | [diff] [blame] | 63 | #define em28xx_isocdbg(fmt, arg...) \ |
| 64 | do {\ |
| 65 | if (isoc_debug) { \ |
Mauro Carvalho Chehab | ad0ebb9 | 2008-04-13 14:37:52 -0300 | [diff] [blame] | 66 | printk(KERN_INFO "%s %s :"fmt, \ |
Douglas Schilling Landgraf | 6ea54d9 | 2008-04-17 21:41:10 -0300 | [diff] [blame] | 67 | dev->name, __func__ , ##arg); \ |
| 68 | } \ |
| 69 | } while (0) |
Mauro Carvalho Chehab | ad0ebb9 | 2008-04-13 14:37:52 -0300 | [diff] [blame] | 70 | |
akpm@osdl.org | a6c2ba2 | 2005-11-08 21:37:07 -0800 | [diff] [blame] | 71 | MODULE_AUTHOR(DRIVER_AUTHOR); |
| 72 | MODULE_DESCRIPTION(DRIVER_DESC); |
| 73 | MODULE_LICENSE("GPL"); |
| 74 | |
Mauro Carvalho Chehab | e5589be | 2006-01-23 17:11:08 -0200 | [diff] [blame] | 75 | static unsigned int video_nr[] = {[0 ... (EM28XX_MAXBOARDS - 1)] = UNSET }; |
Mauro Carvalho Chehab | 0be4375 | 2008-01-05 17:22:01 -0300 | [diff] [blame] | 76 | static unsigned int vbi_nr[] = {[0 ... (EM28XX_MAXBOARDS - 1)] = UNSET }; |
| 77 | static unsigned int radio_nr[] = {[0 ... (EM28XX_MAXBOARDS - 1)] = UNSET }; |
| 78 | |
Mauro Carvalho Chehab | e5589be | 2006-01-23 17:11:08 -0200 | [diff] [blame] | 79 | module_param_array(video_nr, int, NULL, 0444); |
| 80 | module_param_array(vbi_nr, int, NULL, 0444); |
Mauro Carvalho Chehab | 0be4375 | 2008-01-05 17:22:01 -0300 | [diff] [blame] | 81 | module_param_array(radio_nr, int, NULL, 0444); |
Mauro Carvalho Chehab | 0be4375 | 2008-01-05 17:22:01 -0300 | [diff] [blame] | 82 | MODULE_PARM_DESC(video_nr, "video device numbers"); |
| 83 | MODULE_PARM_DESC(vbi_nr, "vbi device numbers"); |
| 84 | MODULE_PARM_DESC(radio_nr, "radio device numbers"); |
Mauro Carvalho Chehab | 596d92d | 2005-11-08 21:37:24 -0800 | [diff] [blame] | 85 | |
Douglas Schilling Landgraf | ff699e6 | 2008-04-22 14:41:48 -0300 | [diff] [blame] | 86 | static unsigned int video_debug; |
Douglas Schilling Landgraf | 6ea54d9 | 2008-04-17 21:41:10 -0300 | [diff] [blame] | 87 | module_param(video_debug, int, 0644); |
| 88 | MODULE_PARM_DESC(video_debug, "enable debug messages [video]"); |
akpm@osdl.org | a6c2ba2 | 2005-11-08 21:37:07 -0800 | [diff] [blame] | 89 | |
Mauro Carvalho Chehab | bddcf63 | 2008-12-20 09:06:37 -0300 | [diff] [blame] | 90 | /* supported video standards */ |
| 91 | static struct em28xx_fmt format[] = { |
| 92 | { |
Mauro Carvalho Chehab | 58fc1ce | 2009-07-03 02:54:18 -0300 | [diff] [blame] | 93 | .name = "16 bpp YUY2, 4:2:2, packed", |
Mauro Carvalho Chehab | bddcf63 | 2008-12-20 09:06:37 -0300 | [diff] [blame] | 94 | .fourcc = V4L2_PIX_FMT_YUYV, |
| 95 | .depth = 16, |
Devin Heitmueller | 3fbf930 | 2008-12-29 23:34:37 -0300 | [diff] [blame] | 96 | .reg = EM28XX_OUTFMT_YUV422_Y0UY1V, |
Mauro Carvalho Chehab | 43cb9fe | 2009-06-30 08:36:17 -0300 | [diff] [blame] | 97 | }, { |
Mauro Carvalho Chehab | 58fc1ce | 2009-07-03 02:54:18 -0300 | [diff] [blame] | 98 | .name = "16 bpp RGB 565, LE", |
Mauro Carvalho Chehab | 43cb9fe | 2009-06-30 08:36:17 -0300 | [diff] [blame] | 99 | .fourcc = V4L2_PIX_FMT_RGB565, |
| 100 | .depth = 16, |
Mauro Carvalho Chehab | 58fc1ce | 2009-07-03 02:54:18 -0300 | [diff] [blame] | 101 | .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 Chehab | bddcf63 | 2008-12-20 09:06:37 -0300 | [diff] [blame] | 122 | }, |
| 123 | }; |
| 124 | |
akpm@osdl.org | a6c2ba2 | 2005-11-08 21:37:07 -0800 | [diff] [blame] | 125 | /* supported controls */ |
Mauro Carvalho Chehab | c0477ad | 2006-01-09 15:25:14 -0200 | [diff] [blame] | 126 | /* Common to all boards */ |
Mauro Carvalho Chehab | 3acf280 | 2005-11-08 21:38:27 -0800 | [diff] [blame] | 127 | static struct v4l2_queryctrl em28xx_qctrl[] = { |
akpm@osdl.org | a6c2ba2 | 2005-11-08 21:37:07 -0800 | [diff] [blame] | 128 | { |
Mauro Carvalho Chehab | c0477ad | 2006-01-09 15:25:14 -0200 | [diff] [blame] | 129 | .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 Landgraf | 6ea54d9 | 2008-04-17 21:41:10 -0300 | [diff] [blame] | 137 | }, { |
Mauro Carvalho Chehab | c0477ad | 2006-01-09 15:25:14 -0200 | [diff] [blame] | 138 | .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 Chehab | ad0ebb9 | 2008-04-13 14:37:52 -0300 | [diff] [blame] | 149 | /* ------------------------------------------------------------------ |
| 150 | DMA and thread functions |
| 151 | ------------------------------------------------------------------*/ |
| 152 | |
| 153 | /* |
| 154 | * Announces that a buffer were filled and request the next |
| 155 | */ |
Mauro Carvalho Chehab | f245e54 | 2008-04-13 14:41:23 -0300 | [diff] [blame] | 156 | static inline void buffer_filled(struct em28xx *dev, |
Mauro Carvalho Chehab | ad0ebb9 | 2008-04-13 14:37:52 -0300 | [diff] [blame] | 157 | struct em28xx_dmaqueue *dma_q, |
| 158 | struct em28xx_buffer *buf) |
| 159 | { |
Mauro Carvalho Chehab | ad0ebb9 | 2008-04-13 14:37:52 -0300 | [diff] [blame] | 160 | /* Advice that buffer was filled */ |
| 161 | em28xx_isocdbg("[%p/%d] wakeup\n", buf, buf->vb.i); |
| 162 | buf->vb.state = VIDEOBUF_DONE; |
| 163 | buf->vb.field_count++; |
| 164 | do_gettimeofday(&buf->vb.ts); |
| 165 | |
Mauro Carvalho Chehab | cb78472 | 2008-04-13 15:06:52 -0300 | [diff] [blame] | 166 | dev->isoc_ctl.buf = NULL; |
| 167 | |
Mauro Carvalho Chehab | ad0ebb9 | 2008-04-13 14:37:52 -0300 | [diff] [blame] | 168 | list_del(&buf->vb.queue); |
| 169 | wake_up(&buf->vb.done); |
| 170 | } |
| 171 | |
| 172 | /* |
| 173 | * Identify the buffer header type and properly handles |
| 174 | */ |
| 175 | static 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 Chehab | f245e54 | 2008-04-13 14:41:23 -0300 | [diff] [blame] | 182 | int linesdone, currlinedone, offset, lencopy, remain; |
Mauro Carvalho Chehab | 44dc733 | 2008-04-13 15:11:08 -0300 | [diff] [blame] | 183 | int bytesperline = dev->width << 1; |
Mauro Carvalho Chehab | ad0ebb9 | 2008-04-13 14:37:52 -0300 | [diff] [blame] | 184 | |
| 185 | if (dma_q->pos + len > buf->vb.size) |
| 186 | len = buf->vb.size - dma_q->pos; |
| 187 | |
Aidan Thornton | d7aa802 | 2008-04-13 14:38:47 -0300 | [diff] [blame] | 188 | if (p[0] != 0x88 && p[0] != 0x22) { |
Mauro Carvalho Chehab | ad0ebb9 | 2008-04-13 14:37:52 -0300 | [diff] [blame] | 189 | em28xx_isocdbg("frame is not complete\n"); |
| 190 | len += 4; |
| 191 | } else |
Mauro Carvalho Chehab | f245e54 | 2008-04-13 14:41:23 -0300 | [diff] [blame] | 192 | p += 4; |
Mauro Carvalho Chehab | ad0ebb9 | 2008-04-13 14:37:52 -0300 | [diff] [blame] | 193 | |
| 194 | startread = p; |
| 195 | remain = len; |
| 196 | |
Mauro Carvalho Chehab | c2a6b54 | 2009-08-08 03:14:55 -0300 | [diff] [blame] | 197 | if (dev->progressive) |
Mauro Carvalho Chehab | ad0ebb9 | 2008-04-13 14:37:52 -0300 | [diff] [blame] | 198 | fieldstart = outp; |
Mauro Carvalho Chehab | c2a6b54 | 2009-08-08 03:14:55 -0300 | [diff] [blame] | 199 | else { |
| 200 | /* Interlaces two half frames */ |
| 201 | if (buf->top_field) |
| 202 | fieldstart = outp; |
| 203 | else |
| 204 | fieldstart = outp + bytesperline; |
| 205 | } |
Mauro Carvalho Chehab | ad0ebb9 | 2008-04-13 14:37:52 -0300 | [diff] [blame] | 206 | |
Mauro Carvalho Chehab | 44dc733 | 2008-04-13 15:11:08 -0300 | [diff] [blame] | 207 | linesdone = dma_q->pos / bytesperline; |
| 208 | currlinedone = dma_q->pos % bytesperline; |
Mauro Carvalho Chehab | c2a6b54 | 2009-08-08 03:14:55 -0300 | [diff] [blame] | 209 | |
| 210 | if (dev->progressive) |
| 211 | offset = linesdone * bytesperline + currlinedone; |
| 212 | else |
| 213 | offset = linesdone * bytesperline * 2 + currlinedone; |
| 214 | |
Mauro Carvalho Chehab | ad0ebb9 | 2008-04-13 14:37:52 -0300 | [diff] [blame] | 215 | startwrite = fieldstart + offset; |
Mauro Carvalho Chehab | 44dc733 | 2008-04-13 15:11:08 -0300 | [diff] [blame] | 216 | lencopy = bytesperline - currlinedone; |
Mauro Carvalho Chehab | ad0ebb9 | 2008-04-13 14:37:52 -0300 | [diff] [blame] | 217 | lencopy = lencopy > remain ? remain : lencopy; |
| 218 | |
Mauro Carvalho Chehab | f245e54 | 2008-04-13 14:41:23 -0300 | [diff] [blame] | 219 | if ((char *)startwrite + lencopy > (char *)outp + buf->vb.size) { |
Mauro Carvalho Chehab | ea8df7e | 2008-04-13 14:39:29 -0300 | [diff] [blame] | 220 | em28xx_isocdbg("Overflow of %zi bytes past buffer end (1)\n", |
Mauro Carvalho Chehab | f245e54 | 2008-04-13 14:41:23 -0300 | [diff] [blame] | 221 | ((char *)startwrite + lencopy) - |
| 222 | ((char *)outp + buf->vb.size)); |
Nicola Soranzo | a1a6ee7 | 2009-02-10 23:28:24 -0300 | [diff] [blame] | 223 | remain = (char *)outp + buf->vb.size - (char *)startwrite; |
| 224 | lencopy = remain; |
Aidan Thornton | d7aa802 | 2008-04-13 14:38:47 -0300 | [diff] [blame] | 225 | } |
Aidan Thornton | e0fadfd34 | 2008-04-13 14:56:02 -0300 | [diff] [blame] | 226 | if (lencopy <= 0) |
| 227 | return; |
Aidan Thornton | d7aa802 | 2008-04-13 14:38:47 -0300 | [diff] [blame] | 228 | memcpy(startwrite, startread, lencopy); |
Mauro Carvalho Chehab | ad0ebb9 | 2008-04-13 14:37:52 -0300 | [diff] [blame] | 229 | |
| 230 | remain -= lencopy; |
| 231 | |
| 232 | while (remain > 0) { |
Mauro Carvalho Chehab | 44dc733 | 2008-04-13 15:11:08 -0300 | [diff] [blame] | 233 | startwrite += lencopy + bytesperline; |
Mauro Carvalho Chehab | ad0ebb9 | 2008-04-13 14:37:52 -0300 | [diff] [blame] | 234 | startread += lencopy; |
Mauro Carvalho Chehab | 44dc733 | 2008-04-13 15:11:08 -0300 | [diff] [blame] | 235 | if (bytesperline > remain) |
Mauro Carvalho Chehab | ad0ebb9 | 2008-04-13 14:37:52 -0300 | [diff] [blame] | 236 | lencopy = remain; |
| 237 | else |
Mauro Carvalho Chehab | 44dc733 | 2008-04-13 15:11:08 -0300 | [diff] [blame] | 238 | lencopy = bytesperline; |
Mauro Carvalho Chehab | ad0ebb9 | 2008-04-13 14:37:52 -0300 | [diff] [blame] | 239 | |
Nicola Soranzo | a1a6ee7 | 2009-02-10 23:28:24 -0300 | [diff] [blame] | 240 | if ((char *)startwrite + lencopy > (char *)outp + |
| 241 | buf->vb.size) { |
Mauro Carvalho Chehab | ea8df7e | 2008-04-13 14:39:29 -0300 | [diff] [blame] | 242 | em28xx_isocdbg("Overflow of %zi bytes past buffer end (2)\n", |
Mauro Carvalho Chehab | f245e54 | 2008-04-13 14:41:23 -0300 | [diff] [blame] | 243 | ((char *)startwrite + lencopy) - |
| 244 | ((char *)outp + buf->vb.size)); |
| 245 | lencopy = remain = (char *)outp + buf->vb.size - |
| 246 | (char *)startwrite; |
Aidan Thornton | d7aa802 | 2008-04-13 14:38:47 -0300 | [diff] [blame] | 247 | } |
Mauro Carvalho Chehab | f245e54 | 2008-04-13 14:41:23 -0300 | [diff] [blame] | 248 | if (lencopy <= 0) |
| 249 | break; |
Aidan Thornton | d7aa802 | 2008-04-13 14:38:47 -0300 | [diff] [blame] | 250 | |
| 251 | memcpy(startwrite, startread, lencopy); |
Mauro Carvalho Chehab | ad0ebb9 | 2008-04-13 14:37:52 -0300 | [diff] [blame] | 252 | |
| 253 | remain -= lencopy; |
| 254 | } |
| 255 | |
| 256 | dma_q->pos += len; |
| 257 | } |
| 258 | |
Mauro Carvalho Chehab | f245e54 | 2008-04-13 14:41:23 -0300 | [diff] [blame] | 259 | static inline void print_err_status(struct em28xx *dev, |
Mauro Carvalho Chehab | ad0ebb9 | 2008-04-13 14:37:52 -0300 | [diff] [blame] | 260 | int packet, int status) |
| 261 | { |
| 262 | char *errmsg = "Unknown"; |
| 263 | |
Mauro Carvalho Chehab | f245e54 | 2008-04-13 14:41:23 -0300 | [diff] [blame] | 264 | switch (status) { |
Mauro Carvalho Chehab | ad0ebb9 | 2008-04-13 14:37:52 -0300 | [diff] [blame] | 265 | case -ENOENT: |
| 266 | errmsg = "unlinked synchronuously"; |
| 267 | break; |
| 268 | case -ECONNRESET: |
| 269 | errmsg = "unlinked asynchronuously"; |
| 270 | break; |
| 271 | case -ENOSR: |
| 272 | errmsg = "Buffer error (overrun)"; |
| 273 | break; |
| 274 | case -EPIPE: |
| 275 | errmsg = "Stalled (device not responding)"; |
| 276 | break; |
| 277 | case -EOVERFLOW: |
| 278 | errmsg = "Babble (bad cable?)"; |
| 279 | break; |
| 280 | case -EPROTO: |
| 281 | errmsg = "Bit-stuff error (bad cable?)"; |
| 282 | break; |
| 283 | case -EILSEQ: |
| 284 | errmsg = "CRC/Timeout (could be anything)"; |
| 285 | break; |
| 286 | case -ETIME: |
| 287 | errmsg = "Device does not respond"; |
| 288 | break; |
| 289 | } |
Mauro Carvalho Chehab | f245e54 | 2008-04-13 14:41:23 -0300 | [diff] [blame] | 290 | if (packet < 0) { |
Mauro Carvalho Chehab | ad0ebb9 | 2008-04-13 14:37:52 -0300 | [diff] [blame] | 291 | em28xx_isocdbg("URB status %d [%s].\n", status, errmsg); |
| 292 | } else { |
| 293 | em28xx_isocdbg("URB packet %d, status %d [%s].\n", |
| 294 | packet, status, errmsg); |
| 295 | } |
| 296 | } |
| 297 | |
| 298 | /* |
| 299 | * video-buf generic routine to get the next available buffer |
| 300 | */ |
Aidan Thornton | 3b5fa92 | 2008-04-13 15:09:36 -0300 | [diff] [blame] | 301 | static inline void get_next_buf(struct em28xx_dmaqueue *dma_q, |
Mauro Carvalho Chehab | ad0ebb9 | 2008-04-13 14:37:52 -0300 | [diff] [blame] | 302 | struct em28xx_buffer **buf) |
| 303 | { |
| 304 | struct em28xx *dev = container_of(dma_q, struct em28xx, vidq); |
Mauro Carvalho Chehab | dbecb44 | 2008-04-13 15:08:55 -0300 | [diff] [blame] | 305 | char *outp; |
Mauro Carvalho Chehab | ad0ebb9 | 2008-04-13 14:37:52 -0300 | [diff] [blame] | 306 | |
Mauro Carvalho Chehab | dbecb44 | 2008-04-13 15:08:55 -0300 | [diff] [blame] | 307 | if (list_empty(&dma_q->active)) { |
| 308 | em28xx_isocdbg("No active queue to serve\n"); |
| 309 | dev->isoc_ctl.buf = NULL; |
Mauro Carvalho Chehab | dbecb44 | 2008-04-13 15:08:55 -0300 | [diff] [blame] | 310 | *buf = NULL; |
Aidan Thornton | 3b5fa92 | 2008-04-13 15:09:36 -0300 | [diff] [blame] | 311 | return; |
Mauro Carvalho Chehab | dbecb44 | 2008-04-13 15:08:55 -0300 | [diff] [blame] | 312 | } |
| 313 | |
Mauro Carvalho Chehab | dbecb44 | 2008-04-13 15:08:55 -0300 | [diff] [blame] | 314 | /* Get the next buffer */ |
| 315 | *buf = list_entry(dma_q->active.next, struct em28xx_buffer, vb.queue); |
| 316 | |
Mauro Carvalho Chehab | dbecb44 | 2008-04-13 15:08:55 -0300 | [diff] [blame] | 317 | /* Cleans up buffer - Usefull for testing for frame/URB loss */ |
| 318 | outp = videobuf_to_vmalloc(&(*buf)->vb); |
| 319 | memset(outp, 0, (*buf)->vb.size); |
Mauro Carvalho Chehab | cb78472 | 2008-04-13 15:06:52 -0300 | [diff] [blame] | 320 | |
| 321 | dev->isoc_ctl.buf = *buf; |
| 322 | |
Aidan Thornton | 3b5fa92 | 2008-04-13 15:09:36 -0300 | [diff] [blame] | 323 | return; |
Mauro Carvalho Chehab | ad0ebb9 | 2008-04-13 14:37:52 -0300 | [diff] [blame] | 324 | } |
| 325 | |
| 326 | /* |
| 327 | * Controls the isoc copy of each urb packet |
| 328 | */ |
Aidan Thornton | 579f72e | 2008-04-17 21:40:16 -0300 | [diff] [blame] | 329 | static inline int em28xx_isoc_copy(struct em28xx *dev, struct urb *urb) |
Mauro Carvalho Chehab | ad0ebb9 | 2008-04-13 14:37:52 -0300 | [diff] [blame] | 330 | { |
Aidan Thornton | d7aa802 | 2008-04-13 14:38:47 -0300 | [diff] [blame] | 331 | struct em28xx_buffer *buf; |
Mauro Carvalho Chehab | ad0ebb9 | 2008-04-13 14:37:52 -0300 | [diff] [blame] | 332 | struct em28xx_dmaqueue *dma_q = urb->context; |
Aidan Thornton | 3b5fa92 | 2008-04-13 15:09:36 -0300 | [diff] [blame] | 333 | unsigned char *outp = NULL; |
Mauro Carvalho Chehab | ad0ebb9 | 2008-04-13 14:37:52 -0300 | [diff] [blame] | 334 | int i, len = 0, rc = 1; |
Aidan Thornton | d7aa802 | 2008-04-13 14:38:47 -0300 | [diff] [blame] | 335 | unsigned char *p; |
Mauro Carvalho Chehab | ad0ebb9 | 2008-04-13 14:37:52 -0300 | [diff] [blame] | 336 | |
| 337 | if (!dev) |
| 338 | return 0; |
| 339 | |
| 340 | if ((dev->state & DEV_DISCONNECTED) || (dev->state & DEV_MISCONFIGURED)) |
| 341 | return 0; |
| 342 | |
Mauro Carvalho Chehab | f245e54 | 2008-04-13 14:41:23 -0300 | [diff] [blame] | 343 | if (urb->status < 0) { |
| 344 | print_err_status(dev, -1, urb->status); |
Mauro Carvalho Chehab | ad0ebb9 | 2008-04-13 14:37:52 -0300 | [diff] [blame] | 345 | if (urb->status == -ENOENT) |
| 346 | return 0; |
| 347 | } |
| 348 | |
Aidan Thornton | 3b5fa92 | 2008-04-13 15:09:36 -0300 | [diff] [blame] | 349 | buf = dev->isoc_ctl.buf; |
| 350 | if (buf != NULL) |
| 351 | outp = videobuf_to_vmalloc(&buf->vb); |
Aidan Thornton | d7aa802 | 2008-04-13 14:38:47 -0300 | [diff] [blame] | 352 | |
Mauro Carvalho Chehab | ad0ebb9 | 2008-04-13 14:37:52 -0300 | [diff] [blame] | 353 | for (i = 0; i < urb->number_of_packets; i++) { |
| 354 | int status = urb->iso_frame_desc[i].status; |
| 355 | |
Mauro Carvalho Chehab | f245e54 | 2008-04-13 14:41:23 -0300 | [diff] [blame] | 356 | if (status < 0) { |
| 357 | print_err_status(dev, i, status); |
Mauro Carvalho Chehab | ad0ebb9 | 2008-04-13 14:37:52 -0300 | [diff] [blame] | 358 | if (urb->iso_frame_desc[i].status != -EPROTO) |
| 359 | continue; |
| 360 | } |
| 361 | |
Mauro Carvalho Chehab | f245e54 | 2008-04-13 14:41:23 -0300 | [diff] [blame] | 362 | len = urb->iso_frame_desc[i].actual_length - 4; |
Mauro Carvalho Chehab | ad0ebb9 | 2008-04-13 14:37:52 -0300 | [diff] [blame] | 363 | |
| 364 | if (urb->iso_frame_desc[i].actual_length <= 0) { |
Aidan Thornton | d7aa802 | 2008-04-13 14:38:47 -0300 | [diff] [blame] | 365 | /* em28xx_isocdbg("packet %d is empty",i); - spammy */ |
Mauro Carvalho Chehab | ad0ebb9 | 2008-04-13 14:37:52 -0300 | [diff] [blame] | 366 | continue; |
| 367 | } |
| 368 | if (urb->iso_frame_desc[i].actual_length > |
| 369 | dev->max_pkt_size) { |
| 370 | em28xx_isocdbg("packet bigger than packet size"); |
| 371 | continue; |
| 372 | } |
| 373 | |
| 374 | p = urb->transfer_buffer + urb->iso_frame_desc[i].offset; |
Mauro Carvalho Chehab | ad0ebb9 | 2008-04-13 14:37:52 -0300 | [diff] [blame] | 375 | |
| 376 | /* FIXME: incomplete buffer checks where removed to make |
| 377 | logic simpler. Impacts of those changes should be evaluated |
| 378 | */ |
Mauro Carvalho Chehab | b4916f8 | 2008-04-13 15:09:14 -0300 | [diff] [blame] | 379 | if (p[0] == 0x33 && p[1] == 0x95 && p[2] == 0x00) { |
| 380 | em28xx_isocdbg("VBI HEADER!!!\n"); |
| 381 | /* FIXME: Should add vbi copy */ |
| 382 | continue; |
| 383 | } |
Aidan Thornton | d7aa802 | 2008-04-13 14:38:47 -0300 | [diff] [blame] | 384 | if (p[0] == 0x22 && p[1] == 0x5a) { |
Mauro Carvalho Chehab | 78bb394 | 2008-04-13 14:56:25 -0300 | [diff] [blame] | 385 | em28xx_isocdbg("Video frame %d, length=%i, %s\n", p[2], |
Nicola Soranzo | a1a6ee7 | 2009-02-10 23:28:24 -0300 | [diff] [blame] | 386 | len, (p[2] & 1) ? "odd" : "even"); |
Mauro Carvalho Chehab | ad0ebb9 | 2008-04-13 14:37:52 -0300 | [diff] [blame] | 387 | |
Mauro Carvalho Chehab | c2a6b54 | 2009-08-08 03:14:55 -0300 | [diff] [blame] | 388 | if (dev->progressive || !(p[2] & 1)) { |
Aidan Thornton | 3b5fa92 | 2008-04-13 15:09:36 -0300 | [diff] [blame] | 389 | if (buf != NULL) |
| 390 | buffer_filled(dev, dma_q, buf); |
| 391 | get_next_buf(dma_q, &buf); |
| 392 | if (buf == NULL) |
| 393 | outp = NULL; |
| 394 | else |
| 395 | outp = videobuf_to_vmalloc(&buf->vb); |
Aidan Thornton | e0fadfd34 | 2008-04-13 14:56:02 -0300 | [diff] [blame] | 396 | } |
Aidan Thornton | 3b5fa92 | 2008-04-13 15:09:36 -0300 | [diff] [blame] | 397 | |
| 398 | if (buf != NULL) { |
| 399 | if (p[2] & 1) |
| 400 | buf->top_field = 0; |
| 401 | else |
| 402 | buf->top_field = 1; |
| 403 | } |
Mauro Carvalho Chehab | b4916f8 | 2008-04-13 15:09:14 -0300 | [diff] [blame] | 404 | |
Mauro Carvalho Chehab | ad0ebb9 | 2008-04-13 14:37:52 -0300 | [diff] [blame] | 405 | dma_q->pos = 0; |
Mauro Carvalho Chehab | ad0ebb9 | 2008-04-13 14:37:52 -0300 | [diff] [blame] | 406 | } |
Aidan Thornton | 3b5fa92 | 2008-04-13 15:09:36 -0300 | [diff] [blame] | 407 | if (buf != NULL) |
| 408 | em28xx_copy_video(dev, dma_q, buf, p, outp, len); |
Mauro Carvalho Chehab | ad0ebb9 | 2008-04-13 14:37:52 -0300 | [diff] [blame] | 409 | } |
| 410 | return rc; |
| 411 | } |
| 412 | |
| 413 | /* ------------------------------------------------------------------ |
Mauro Carvalho Chehab | ad0ebb9 | 2008-04-13 14:37:52 -0300 | [diff] [blame] | 414 | Videobuf operations |
| 415 | ------------------------------------------------------------------*/ |
| 416 | |
| 417 | static int |
| 418 | buffer_setup(struct videobuf_queue *vq, unsigned int *count, unsigned int *size) |
| 419 | { |
| 420 | struct em28xx_fh *fh = vq->priv_data; |
Mauro Carvalho Chehab | d2d9fbf | 2008-04-17 21:38:53 -0300 | [diff] [blame] | 421 | struct em28xx *dev = fh->dev; |
| 422 | struct v4l2_frequency f; |
Mauro Carvalho Chehab | ad0ebb9 | 2008-04-13 14:37:52 -0300 | [diff] [blame] | 423 | |
Mauro Carvalho Chehab | bddcf63 | 2008-12-20 09:06:37 -0300 | [diff] [blame] | 424 | *size = (fh->dev->width * fh->dev->height * dev->format->depth + 7) >> 3; |
| 425 | |
Mauro Carvalho Chehab | ad0ebb9 | 2008-04-13 14:37:52 -0300 | [diff] [blame] | 426 | if (0 == *count) |
| 427 | *count = EM28XX_DEF_BUF; |
| 428 | |
Mauro Carvalho Chehab | f245e54 | 2008-04-13 14:41:23 -0300 | [diff] [blame] | 429 | if (*count < EM28XX_MIN_BUF) |
| 430 | *count = EM28XX_MIN_BUF; |
Mauro Carvalho Chehab | ad0ebb9 | 2008-04-13 14:37:52 -0300 | [diff] [blame] | 431 | |
Mauro Carvalho Chehab | 381aaba | 2008-12-20 07:43:34 -0300 | [diff] [blame] | 432 | /* Ask tuner to go to analog or radio mode */ |
Douglas Schilling Landgraf | 6ea54d9 | 2008-04-17 21:41:10 -0300 | [diff] [blame] | 433 | memset(&f, 0, sizeof(f)); |
Mauro Carvalho Chehab | d2d9fbf | 2008-04-17 21:38:53 -0300 | [diff] [blame] | 434 | f.frequency = dev->ctl_freq; |
Mauro Carvalho Chehab | 381aaba | 2008-12-20 07:43:34 -0300 | [diff] [blame] | 435 | f.type = fh->radio ? V4L2_TUNER_RADIO : V4L2_TUNER_ANALOG_TV; |
Mauro Carvalho Chehab | d2d9fbf | 2008-04-17 21:38:53 -0300 | [diff] [blame] | 436 | |
Douglas Schilling Landgraf | f2cf250 | 2009-03-31 17:10:58 -0300 | [diff] [blame] | 437 | v4l2_device_call_all(&dev->v4l2_dev, 0, tuner, s_frequency, &f); |
Mauro Carvalho Chehab | d2d9fbf | 2008-04-17 21:38:53 -0300 | [diff] [blame] | 438 | |
Mauro Carvalho Chehab | ad0ebb9 | 2008-04-13 14:37:52 -0300 | [diff] [blame] | 439 | return 0; |
| 440 | } |
| 441 | |
Aidan Thornton | 3b5fa92 | 2008-04-13 15:09:36 -0300 | [diff] [blame] | 442 | /* This is called *without* dev->slock held; please keep it that way */ |
Mauro Carvalho Chehab | ad0ebb9 | 2008-04-13 14:37:52 -0300 | [diff] [blame] | 443 | static void free_buffer(struct videobuf_queue *vq, struct em28xx_buffer *buf) |
| 444 | { |
Aidan Thornton | 3b5fa92 | 2008-04-13 15:09:36 -0300 | [diff] [blame] | 445 | struct em28xx_fh *fh = vq->priv_data; |
| 446 | struct em28xx *dev = fh->dev; |
| 447 | unsigned long flags = 0; |
Mauro Carvalho Chehab | ad0ebb9 | 2008-04-13 14:37:52 -0300 | [diff] [blame] | 448 | if (in_interrupt()) |
| 449 | BUG(); |
| 450 | |
Aidan Thornton | 3b5fa92 | 2008-04-13 15:09:36 -0300 | [diff] [blame] | 451 | /* We used to wait for the buffer to finish here, but this didn't work |
| 452 | because, as we were keeping the state as VIDEOBUF_QUEUED, |
| 453 | videobuf_queue_cancel marked it as finished for us. |
| 454 | (Also, it could wedge forever if the hardware was misconfigured.) |
| 455 | |
| 456 | This should be safe; by the time we get here, the buffer isn't |
| 457 | queued anymore. If we ever start marking the buffers as |
| 458 | VIDEOBUF_ACTIVE, it won't be, though. |
| 459 | */ |
| 460 | spin_lock_irqsave(&dev->slock, flags); |
| 461 | if (dev->isoc_ctl.buf == buf) |
| 462 | dev->isoc_ctl.buf = NULL; |
| 463 | spin_unlock_irqrestore(&dev->slock, flags); |
| 464 | |
Mauro Carvalho Chehab | ad0ebb9 | 2008-04-13 14:37:52 -0300 | [diff] [blame] | 465 | videobuf_vmalloc_free(&buf->vb); |
| 466 | buf->vb.state = VIDEOBUF_NEEDS_INIT; |
| 467 | } |
| 468 | |
| 469 | static int |
| 470 | buffer_prepare(struct videobuf_queue *vq, struct videobuf_buffer *vb, |
| 471 | enum v4l2_field field) |
| 472 | { |
| 473 | struct em28xx_fh *fh = vq->priv_data; |
Mauro Carvalho Chehab | f245e54 | 2008-04-13 14:41:23 -0300 | [diff] [blame] | 474 | struct em28xx_buffer *buf = container_of(vb, struct em28xx_buffer, vb); |
Mauro Carvalho Chehab | ad0ebb9 | 2008-04-13 14:37:52 -0300 | [diff] [blame] | 475 | struct em28xx *dev = fh->dev; |
| 476 | int rc = 0, urb_init = 0; |
Mauro Carvalho Chehab | ad0ebb9 | 2008-04-13 14:37:52 -0300 | [diff] [blame] | 477 | |
Mauro Carvalho Chehab | bddcf63 | 2008-12-20 09:06:37 -0300 | [diff] [blame] | 478 | buf->vb.size = (fh->dev->width * fh->dev->height * dev->format->depth + 7) >> 3; |
Mauro Carvalho Chehab | ad0ebb9 | 2008-04-13 14:37:52 -0300 | [diff] [blame] | 479 | |
| 480 | if (0 != buf->vb.baddr && buf->vb.bsize < buf->vb.size) |
| 481 | return -EINVAL; |
| 482 | |
Brandon Philips | 0561297 | 2008-04-13 14:57:01 -0300 | [diff] [blame] | 483 | buf->vb.width = dev->width; |
| 484 | buf->vb.height = dev->height; |
| 485 | buf->vb.field = field; |
Mauro Carvalho Chehab | ad0ebb9 | 2008-04-13 14:37:52 -0300 | [diff] [blame] | 486 | |
| 487 | if (VIDEOBUF_NEEDS_INIT == buf->vb.state) { |
Aidan Thornton | d7aa802 | 2008-04-13 14:38:47 -0300 | [diff] [blame] | 488 | rc = videobuf_iolock(vq, &buf->vb, NULL); |
| 489 | if (rc < 0) |
Mauro Carvalho Chehab | ad0ebb9 | 2008-04-13 14:37:52 -0300 | [diff] [blame] | 490 | goto fail; |
Mauro Carvalho Chehab | ad0ebb9 | 2008-04-13 14:37:52 -0300 | [diff] [blame] | 491 | } |
| 492 | |
Mauro Carvalho Chehab | ad0ebb9 | 2008-04-13 14:37:52 -0300 | [diff] [blame] | 493 | if (!dev->isoc_ctl.num_bufs) |
Mauro Carvalho Chehab | f245e54 | 2008-04-13 14:41:23 -0300 | [diff] [blame] | 494 | urb_init = 1; |
Mauro Carvalho Chehab | ad0ebb9 | 2008-04-13 14:37:52 -0300 | [diff] [blame] | 495 | |
| 496 | if (urb_init) { |
Aidan Thornton | 579f72e | 2008-04-17 21:40:16 -0300 | [diff] [blame] | 497 | rc = em28xx_init_isoc(dev, EM28XX_NUM_PACKETS, |
| 498 | EM28XX_NUM_BUFS, dev->max_pkt_size, |
Mauro Carvalho Chehab | c67ec53 | 2008-04-17 21:48:00 -0300 | [diff] [blame] | 499 | em28xx_isoc_copy); |
Mauro Carvalho Chehab | f245e54 | 2008-04-13 14:41:23 -0300 | [diff] [blame] | 500 | if (rc < 0) |
Mauro Carvalho Chehab | ad0ebb9 | 2008-04-13 14:37:52 -0300 | [diff] [blame] | 501 | goto fail; |
| 502 | } |
| 503 | |
| 504 | buf->vb.state = VIDEOBUF_PREPARED; |
| 505 | return 0; |
| 506 | |
| 507 | fail: |
Mauro Carvalho Chehab | f245e54 | 2008-04-13 14:41:23 -0300 | [diff] [blame] | 508 | free_buffer(vq, buf); |
Mauro Carvalho Chehab | ad0ebb9 | 2008-04-13 14:37:52 -0300 | [diff] [blame] | 509 | return rc; |
| 510 | } |
| 511 | |
| 512 | static void |
| 513 | buffer_queue(struct videobuf_queue *vq, struct videobuf_buffer *vb) |
| 514 | { |
Nicola Soranzo | a1a6ee7 | 2009-02-10 23:28:24 -0300 | [diff] [blame] | 515 | struct em28xx_buffer *buf = container_of(vb, |
| 516 | struct em28xx_buffer, |
| 517 | vb); |
Mauro Carvalho Chehab | ad0ebb9 | 2008-04-13 14:37:52 -0300 | [diff] [blame] | 518 | struct em28xx_fh *fh = vq->priv_data; |
Mauro Carvalho Chehab | f245e54 | 2008-04-13 14:41:23 -0300 | [diff] [blame] | 519 | struct em28xx *dev = fh->dev; |
Mauro Carvalho Chehab | ad0ebb9 | 2008-04-13 14:37:52 -0300 | [diff] [blame] | 520 | struct em28xx_dmaqueue *vidq = &dev->vidq; |
Mauro Carvalho Chehab | ad0ebb9 | 2008-04-13 14:37:52 -0300 | [diff] [blame] | 521 | |
Aidan Thornton | d7aa802 | 2008-04-13 14:38:47 -0300 | [diff] [blame] | 522 | buf->vb.state = VIDEOBUF_QUEUED; |
| 523 | list_add_tail(&buf->vb.queue, &vidq->active); |
| 524 | |
Mauro Carvalho Chehab | ad0ebb9 | 2008-04-13 14:37:52 -0300 | [diff] [blame] | 525 | } |
| 526 | |
Douglas Schilling Landgraf | 6ea54d9 | 2008-04-17 21:41:10 -0300 | [diff] [blame] | 527 | static void buffer_release(struct videobuf_queue *vq, |
| 528 | struct videobuf_buffer *vb) |
Mauro Carvalho Chehab | ad0ebb9 | 2008-04-13 14:37:52 -0300 | [diff] [blame] | 529 | { |
Nicola Soranzo | a1a6ee7 | 2009-02-10 23:28:24 -0300 | [diff] [blame] | 530 | struct em28xx_buffer *buf = container_of(vb, |
| 531 | struct em28xx_buffer, |
| 532 | vb); |
Mauro Carvalho Chehab | ad0ebb9 | 2008-04-13 14:37:52 -0300 | [diff] [blame] | 533 | struct em28xx_fh *fh = vq->priv_data; |
Mauro Carvalho Chehab | f245e54 | 2008-04-13 14:41:23 -0300 | [diff] [blame] | 534 | struct em28xx *dev = (struct em28xx *)fh->dev; |
Mauro Carvalho Chehab | ad0ebb9 | 2008-04-13 14:37:52 -0300 | [diff] [blame] | 535 | |
Aidan Thornton | d7aa802 | 2008-04-13 14:38:47 -0300 | [diff] [blame] | 536 | em28xx_isocdbg("em28xx: called buffer_release\n"); |
Mauro Carvalho Chehab | ad0ebb9 | 2008-04-13 14:37:52 -0300 | [diff] [blame] | 537 | |
Mauro Carvalho Chehab | f245e54 | 2008-04-13 14:41:23 -0300 | [diff] [blame] | 538 | free_buffer(vq, buf); |
Mauro Carvalho Chehab | ad0ebb9 | 2008-04-13 14:37:52 -0300 | [diff] [blame] | 539 | } |
| 540 | |
| 541 | static struct videobuf_queue_ops em28xx_video_qops = { |
| 542 | .buf_setup = buffer_setup, |
| 543 | .buf_prepare = buffer_prepare, |
| 544 | .buf_queue = buffer_queue, |
| 545 | .buf_release = buffer_release, |
| 546 | }; |
akpm@osdl.org | a6c2ba2 | 2005-11-08 21:37:07 -0800 | [diff] [blame] | 547 | |
Douglas Schilling Landgraf | 6ea54d9 | 2008-04-17 21:41:10 -0300 | [diff] [blame] | 548 | /********************* v4l2 interface **************************************/ |
akpm@osdl.org | a6c2ba2 | 2005-11-08 21:37:07 -0800 | [diff] [blame] | 549 | |
Mauro Carvalho Chehab | eac9435 | 2005-11-08 21:38:43 -0800 | [diff] [blame] | 550 | static void video_mux(struct em28xx *dev, int index) |
| 551 | { |
Mauro Carvalho Chehab | eac9435 | 2005-11-08 21:38:43 -0800 | [diff] [blame] | 552 | dev->ctl_input = index; |
| 553 | dev->ctl_ainput = INPUT(index)->amux; |
Mauro Carvalho Chehab | 35ae6f0 | 2008-11-20 12:40:51 -0300 | [diff] [blame] | 554 | dev->ctl_aoutput = INPUT(index)->aout; |
Mauro Carvalho Chehab | eac9435 | 2005-11-08 21:38:43 -0800 | [diff] [blame] | 555 | |
Mauro Carvalho Chehab | e879b8e | 2008-11-20 13:39:39 -0300 | [diff] [blame] | 556 | if (!dev->ctl_aoutput) |
| 557 | dev->ctl_aoutput = EM28XX_AOUT_MASTER; |
| 558 | |
Hans Verkuil | 5325b42 | 2009-04-02 11:26:22 -0300 | [diff] [blame] | 559 | v4l2_device_call_all(&dev->v4l2_dev, 0, video, s_routing, |
| 560 | INPUT(index)->vmux, 0, 0); |
Mauro Carvalho Chehab | eac9435 | 2005-11-08 21:38:43 -0800 | [diff] [blame] | 561 | |
Mauro Carvalho Chehab | 505b6d0 | 2008-11-25 09:39:50 -0300 | [diff] [blame] | 562 | if (dev->board.has_msp34xx) { |
Douglas Schilling Landgraf | 6ea54d9 | 2008-04-17 21:41:10 -0300 | [diff] [blame] | 563 | if (dev->i2s_speed) { |
Douglas Schilling Landgraf | f2cf250 | 2009-03-31 17:10:58 -0300 | [diff] [blame] | 564 | v4l2_device_call_all(&dev->v4l2_dev, 0, audio, |
| 565 | s_i2s_clock_freq, dev->i2s_speed); |
Douglas Schilling Landgraf | 6ea54d9 | 2008-04-17 21:41:10 -0300 | [diff] [blame] | 566 | } |
Hans Verkuil | 2474ed4 | 2006-03-19 12:35:57 -0300 | [diff] [blame] | 567 | /* Note: this is msp3400 specific */ |
Hans Verkuil | 5325b42 | 2009-04-02 11:26:22 -0300 | [diff] [blame] | 568 | v4l2_device_call_all(&dev->v4l2_dev, 0, audio, s_routing, |
| 569 | dev->ctl_ainput, MSP_OUTPUT(MSP_SC_IN_DSP_SCART1), 0); |
Mauro Carvalho Chehab | eac9435 | 2005-11-08 21:38:43 -0800 | [diff] [blame] | 570 | } |
Mauro Carvalho Chehab | 539c96d | 2008-01-05 09:53:54 -0300 | [diff] [blame] | 571 | |
Vitaly Wool | 2bd1d9e | 2009-03-04 08:27:52 -0300 | [diff] [blame] | 572 | if (dev->board.adecoder != EM28XX_NOADECODER) { |
Hans Verkuil | 5325b42 | 2009-04-02 11:26:22 -0300 | [diff] [blame] | 573 | v4l2_device_call_all(&dev->v4l2_dev, 0, audio, s_routing, |
| 574 | dev->ctl_ainput, dev->ctl_aoutput, 0); |
Vitaly Wool | 2bd1d9e | 2009-03-04 08:27:52 -0300 | [diff] [blame] | 575 | } |
| 576 | |
Mauro Carvalho Chehab | 00b8730 | 2008-02-06 18:34:13 -0300 | [diff] [blame] | 577 | em28xx_audio_analog_set(dev); |
Mauro Carvalho Chehab | eac9435 | 2005-11-08 21:38:43 -0800 | [diff] [blame] | 578 | } |
| 579 | |
Mauro Carvalho Chehab | a225452 | 2007-11-11 01:08:26 -0300 | [diff] [blame] | 580 | /* Usage lock check functions */ |
| 581 | static int res_get(struct em28xx_fh *fh) |
| 582 | { |
| 583 | struct em28xx *dev = fh->dev; |
| 584 | int rc = 0; |
| 585 | |
| 586 | /* This instance already has stream_on */ |
| 587 | if (fh->stream_on) |
| 588 | return rc; |
| 589 | |
Mauro Carvalho Chehab | a225452 | 2007-11-11 01:08:26 -0300 | [diff] [blame] | 590 | if (dev->stream_on) |
Mauro Carvalho Chehab | 29b5941 | 2008-12-16 20:19:24 -0300 | [diff] [blame] | 591 | return -EBUSY; |
Mauro Carvalho Chehab | a225452 | 2007-11-11 01:08:26 -0300 | [diff] [blame] | 592 | |
Mauro Carvalho Chehab | e74153d | 2008-04-13 14:55:38 -0300 | [diff] [blame] | 593 | dev->stream_on = 1; |
| 594 | fh->stream_on = 1; |
Mauro Carvalho Chehab | a225452 | 2007-11-11 01:08:26 -0300 | [diff] [blame] | 595 | return rc; |
| 596 | } |
| 597 | |
| 598 | static int res_check(struct em28xx_fh *fh) |
| 599 | { |
Nicola Soranzo | a1a6ee7 | 2009-02-10 23:28:24 -0300 | [diff] [blame] | 600 | return fh->stream_on; |
Mauro Carvalho Chehab | a225452 | 2007-11-11 01:08:26 -0300 | [diff] [blame] | 601 | } |
| 602 | |
| 603 | static void res_free(struct em28xx_fh *fh) |
| 604 | { |
| 605 | struct em28xx *dev = fh->dev; |
| 606 | |
Mauro Carvalho Chehab | a225452 | 2007-11-11 01:08:26 -0300 | [diff] [blame] | 607 | fh->stream_on = 0; |
| 608 | dev->stream_on = 0; |
Mauro Carvalho Chehab | a225452 | 2007-11-11 01:08:26 -0300 | [diff] [blame] | 609 | } |
| 610 | |
akpm@osdl.org | a6c2ba2 | 2005-11-08 21:37:07 -0800 | [diff] [blame] | 611 | /* |
Mauro Carvalho Chehab | 195a4ef | 2007-11-11 13:17:17 -0300 | [diff] [blame] | 612 | * em28xx_get_ctrl() |
| 613 | * return the current saturation, brightness or contrast, mute state |
| 614 | */ |
| 615 | static int em28xx_get_ctrl(struct em28xx *dev, struct v4l2_control *ctrl) |
| 616 | { |
| 617 | switch (ctrl->id) { |
| 618 | case V4L2_CID_AUDIO_MUTE: |
| 619 | ctrl->value = dev->mute; |
| 620 | return 0; |
| 621 | case V4L2_CID_AUDIO_VOLUME: |
| 622 | ctrl->value = dev->volume; |
| 623 | return 0; |
| 624 | default: |
| 625 | return -EINVAL; |
| 626 | } |
| 627 | } |
| 628 | |
| 629 | /* |
| 630 | * em28xx_set_ctrl() |
| 631 | * mute or set new saturation, brightness or contrast |
| 632 | */ |
| 633 | static int em28xx_set_ctrl(struct em28xx *dev, const struct v4l2_control *ctrl) |
| 634 | { |
| 635 | switch (ctrl->id) { |
| 636 | case V4L2_CID_AUDIO_MUTE: |
| 637 | if (ctrl->value != dev->mute) { |
| 638 | dev->mute = ctrl->value; |
Mauro Carvalho Chehab | 195a4ef | 2007-11-11 13:17:17 -0300 | [diff] [blame] | 639 | return em28xx_audio_analog_set(dev); |
| 640 | } |
| 641 | return 0; |
| 642 | case V4L2_CID_AUDIO_VOLUME: |
| 643 | dev->volume = ctrl->value; |
| 644 | return em28xx_audio_analog_set(dev); |
| 645 | default: |
| 646 | return -EINVAL; |
| 647 | } |
| 648 | } |
| 649 | |
Mauro Carvalho Chehab | 195a4ef | 2007-11-11 13:17:17 -0300 | [diff] [blame] | 650 | static int check_dev(struct em28xx *dev) |
| 651 | { |
| 652 | if (dev->state & DEV_DISCONNECTED) { |
| 653 | em28xx_errdev("v4l2 ioctl: device not present\n"); |
| 654 | return -ENODEV; |
| 655 | } |
| 656 | |
| 657 | if (dev->state & DEV_MISCONFIGURED) { |
| 658 | em28xx_errdev("v4l2 ioctl: device is misconfigured; " |
| 659 | "close and open it again\n"); |
| 660 | return -EIO; |
| 661 | } |
| 662 | return 0; |
| 663 | } |
| 664 | |
| 665 | static void get_scale(struct em28xx *dev, |
| 666 | unsigned int width, unsigned int height, |
| 667 | unsigned int *hscale, unsigned int *vscale) |
| 668 | { |
Mauro Carvalho Chehab | 5569996 | 2009-07-13 20:15:02 -0300 | [diff] [blame] | 669 | unsigned int maxw = norm_maxw(dev); |
| 670 | unsigned int maxh = norm_maxh(dev); |
Mauro Carvalho Chehab | 195a4ef | 2007-11-11 13:17:17 -0300 | [diff] [blame] | 671 | |
| 672 | *hscale = (((unsigned long)maxw) << 12) / width - 4096L; |
| 673 | if (*hscale >= 0x4000) |
| 674 | *hscale = 0x3fff; |
| 675 | |
| 676 | *vscale = (((unsigned long)maxh) << 12) / height - 4096L; |
| 677 | if (*vscale >= 0x4000) |
| 678 | *vscale = 0x3fff; |
| 679 | } |
| 680 | |
| 681 | /* ------------------------------------------------------------------ |
| 682 | IOCTL vidioc handling |
| 683 | ------------------------------------------------------------------*/ |
| 684 | |
Hans Verkuil | 78b526a | 2008-05-28 12:16:41 -0300 | [diff] [blame] | 685 | static int vidioc_g_fmt_vid_cap(struct file *file, void *priv, |
Mauro Carvalho Chehab | 195a4ef | 2007-11-11 13:17:17 -0300 | [diff] [blame] | 686 | struct v4l2_format *f) |
| 687 | { |
| 688 | struct em28xx_fh *fh = priv; |
| 689 | struct em28xx *dev = fh->dev; |
| 690 | |
| 691 | mutex_lock(&dev->lock); |
| 692 | |
| 693 | f->fmt.pix.width = dev->width; |
| 694 | f->fmt.pix.height = dev->height; |
Mauro Carvalho Chehab | bddcf63 | 2008-12-20 09:06:37 -0300 | [diff] [blame] | 695 | f->fmt.pix.pixelformat = dev->format->fourcc; |
| 696 | f->fmt.pix.bytesperline = (dev->width * dev->format->depth + 7) >> 3; |
Mauro Carvalho Chehab | 44dc733 | 2008-04-13 15:11:08 -0300 | [diff] [blame] | 697 | f->fmt.pix.sizeimage = f->fmt.pix.bytesperline * dev->height; |
Mauro Carvalho Chehab | 195a4ef | 2007-11-11 13:17:17 -0300 | [diff] [blame] | 698 | f->fmt.pix.colorspace = V4L2_COLORSPACE_SMPTE170M; |
| 699 | |
| 700 | /* FIXME: TOP? NONE? BOTTOM? ALTENATE? */ |
Mauro Carvalho Chehab | c2a6b54 | 2009-08-08 03:14:55 -0300 | [diff] [blame] | 701 | if (dev->progressive) |
| 702 | f->fmt.pix.field = V4L2_FIELD_NONE; |
| 703 | else |
| 704 | f->fmt.pix.field = dev->interlaced ? |
Mauro Carvalho Chehab | 195a4ef | 2007-11-11 13:17:17 -0300 | [diff] [blame] | 705 | V4L2_FIELD_INTERLACED : V4L2_FIELD_TOP; |
| 706 | |
| 707 | mutex_unlock(&dev->lock); |
| 708 | return 0; |
| 709 | } |
| 710 | |
Mauro Carvalho Chehab | bddcf63 | 2008-12-20 09:06:37 -0300 | [diff] [blame] | 711 | static struct em28xx_fmt *format_by_fourcc(unsigned int fourcc) |
| 712 | { |
| 713 | unsigned int i; |
| 714 | |
| 715 | for (i = 0; i < ARRAY_SIZE(format); i++) |
| 716 | if (format[i].fourcc == fourcc) |
| 717 | return &format[i]; |
| 718 | |
| 719 | return NULL; |
| 720 | } |
| 721 | |
Hans Verkuil | 78b526a | 2008-05-28 12:16:41 -0300 | [diff] [blame] | 722 | static int vidioc_try_fmt_vid_cap(struct file *file, void *priv, |
Mauro Carvalho Chehab | 195a4ef | 2007-11-11 13:17:17 -0300 | [diff] [blame] | 723 | struct v4l2_format *f) |
| 724 | { |
| 725 | struct em28xx_fh *fh = priv; |
| 726 | struct em28xx *dev = fh->dev; |
Trent Piepho | ccb8340 | 2009-05-30 21:45:46 -0300 | [diff] [blame] | 727 | unsigned int width = f->fmt.pix.width; |
| 728 | unsigned int height = f->fmt.pix.height; |
Mauro Carvalho Chehab | 195a4ef | 2007-11-11 13:17:17 -0300 | [diff] [blame] | 729 | unsigned int maxw = norm_maxw(dev); |
| 730 | unsigned int maxh = norm_maxh(dev); |
| 731 | unsigned int hscale, vscale; |
Mauro Carvalho Chehab | bddcf63 | 2008-12-20 09:06:37 -0300 | [diff] [blame] | 732 | struct em28xx_fmt *fmt; |
| 733 | |
| 734 | fmt = format_by_fourcc(f->fmt.pix.pixelformat); |
| 735 | if (!fmt) { |
| 736 | em28xx_videodbg("Fourcc format (%08x) invalid.\n", |
| 737 | f->fmt.pix.pixelformat); |
| 738 | return -EINVAL; |
| 739 | } |
Mauro Carvalho Chehab | 195a4ef | 2007-11-11 13:17:17 -0300 | [diff] [blame] | 740 | |
Mauro Carvalho Chehab | 5569996 | 2009-07-13 20:15:02 -0300 | [diff] [blame] | 741 | if (dev->board.is_em2800) { |
Mauro Carvalho Chehab | 195a4ef | 2007-11-11 13:17:17 -0300 | [diff] [blame] | 742 | /* the em2800 can only scale down to 50% */ |
Trent Piepho | ccb8340 | 2009-05-30 21:45:46 -0300 | [diff] [blame] | 743 | height = height > (3 * maxh / 4) ? maxh : maxh / 2; |
| 744 | width = width > (3 * maxw / 4) ? maxw : maxw / 2; |
| 745 | /* According to empiatech support the MaxPacketSize is too small |
| 746 | * to support framesizes larger than 640x480 @ 30 fps or 640x576 |
| 747 | * @ 25 fps. As this would cut of a part of the image we prefer |
| 748 | * 360x576 or 360x480 for now */ |
Mauro Carvalho Chehab | 195a4ef | 2007-11-11 13:17:17 -0300 | [diff] [blame] | 749 | if (width == maxw && height == maxh) |
| 750 | width /= 2; |
Trent Piepho | ccb8340 | 2009-05-30 21:45:46 -0300 | [diff] [blame] | 751 | } else { |
| 752 | /* width must even because of the YUYV format |
| 753 | height must be even because of interlacing */ |
| 754 | v4l_bound_align_image(&width, 48, maxw, 1, &height, 32, maxh, 1, 0); |
Mauro Carvalho Chehab | 195a4ef | 2007-11-11 13:17:17 -0300 | [diff] [blame] | 755 | } |
| 756 | |
| 757 | get_scale(dev, width, height, &hscale, &vscale); |
| 758 | |
| 759 | width = (((unsigned long)maxw) << 12) / (hscale + 4096L); |
| 760 | height = (((unsigned long)maxh) << 12) / (vscale + 4096L); |
| 761 | |
| 762 | f->fmt.pix.width = width; |
| 763 | f->fmt.pix.height = height; |
Mauro Carvalho Chehab | bddcf63 | 2008-12-20 09:06:37 -0300 | [diff] [blame] | 764 | f->fmt.pix.pixelformat = fmt->fourcc; |
| 765 | f->fmt.pix.bytesperline = (dev->width * fmt->depth + 7) >> 3; |
| 766 | f->fmt.pix.sizeimage = f->fmt.pix.bytesperline * height; |
Mauro Carvalho Chehab | 195a4ef | 2007-11-11 13:17:17 -0300 | [diff] [blame] | 767 | f->fmt.pix.colorspace = V4L2_COLORSPACE_SMPTE170M; |
Mauro Carvalho Chehab | c2a6b54 | 2009-08-08 03:14:55 -0300 | [diff] [blame] | 768 | if (dev->progressive) |
| 769 | f->fmt.pix.field = V4L2_FIELD_NONE; |
| 770 | else |
| 771 | f->fmt.pix.field = dev->interlaced ? |
| 772 | V4L2_FIELD_INTERLACED : V4L2_FIELD_TOP; |
Mauro Carvalho Chehab | 195a4ef | 2007-11-11 13:17:17 -0300 | [diff] [blame] | 773 | |
Mauro Carvalho Chehab | 195a4ef | 2007-11-11 13:17:17 -0300 | [diff] [blame] | 774 | return 0; |
| 775 | } |
| 776 | |
Mauro Carvalho Chehab | ed5f143 | 2009-07-02 17:34:04 -0300 | [diff] [blame] | 777 | static int em28xx_set_video_format(struct em28xx *dev, unsigned int fourcc, |
| 778 | unsigned width, unsigned height) |
| 779 | { |
| 780 | struct em28xx_fmt *fmt; |
| 781 | |
Mauro Carvalho Chehab | ed5f143 | 2009-07-02 17:34:04 -0300 | [diff] [blame] | 782 | fmt = format_by_fourcc(fourcc); |
| 783 | if (!fmt) |
| 784 | return -EINVAL; |
| 785 | |
| 786 | dev->format = fmt; |
| 787 | dev->width = width; |
| 788 | dev->height = height; |
| 789 | |
| 790 | /* set new image size */ |
| 791 | get_scale(dev, dev->width, dev->height, &dev->hscale, &dev->vscale); |
| 792 | |
| 793 | em28xx_set_alternate(dev); |
| 794 | em28xx_resolution_set(dev); |
| 795 | |
| 796 | return 0; |
| 797 | } |
| 798 | |
Hans Verkuil | 78b526a | 2008-05-28 12:16:41 -0300 | [diff] [blame] | 799 | static int vidioc_s_fmt_vid_cap(struct file *file, void *priv, |
Mauro Carvalho Chehab | 195a4ef | 2007-11-11 13:17:17 -0300 | [diff] [blame] | 800 | struct v4l2_format *f) |
| 801 | { |
| 802 | struct em28xx_fh *fh = priv; |
| 803 | struct em28xx *dev = fh->dev; |
Mauro Carvalho Chehab | ad0ebb9 | 2008-04-13 14:37:52 -0300 | [diff] [blame] | 804 | int rc; |
Mauro Carvalho Chehab | 195a4ef | 2007-11-11 13:17:17 -0300 | [diff] [blame] | 805 | |
| 806 | rc = check_dev(dev); |
| 807 | if (rc < 0) |
| 808 | return rc; |
| 809 | |
Mauro Carvalho Chehab | 195a4ef | 2007-11-11 13:17:17 -0300 | [diff] [blame] | 810 | mutex_lock(&dev->lock); |
| 811 | |
Mauro Carvalho Chehab | efc52a9 | 2008-12-16 22:04:56 -0300 | [diff] [blame] | 812 | vidioc_try_fmt_vid_cap(file, priv, f); |
| 813 | |
Brandon Philips | 0561297 | 2008-04-13 14:57:01 -0300 | [diff] [blame] | 814 | if (videobuf_queue_is_busy(&fh->vb_vidq)) { |
| 815 | em28xx_errdev("%s queue busy\n", __func__); |
| 816 | rc = -EBUSY; |
| 817 | goto out; |
| 818 | } |
| 819 | |
Aidan Thornton | 0ea13e6 | 2008-04-13 15:02:24 -0300 | [diff] [blame] | 820 | if (dev->stream_on && !fh->stream_on) { |
| 821 | em28xx_errdev("%s device in use by another fh\n", __func__); |
| 822 | rc = -EBUSY; |
| 823 | goto out; |
| 824 | } |
| 825 | |
Mauro Carvalho Chehab | ed5f143 | 2009-07-02 17:34:04 -0300 | [diff] [blame] | 826 | rc = em28xx_set_video_format(dev, f->fmt.pix.pixelformat, |
| 827 | f->fmt.pix.width, f->fmt.pix.height); |
Brandon Philips | 0561297 | 2008-04-13 14:57:01 -0300 | [diff] [blame] | 828 | |
| 829 | out: |
Mauro Carvalho Chehab | 195a4ef | 2007-11-11 13:17:17 -0300 | [diff] [blame] | 830 | mutex_unlock(&dev->lock); |
Brandon Philips | 0561297 | 2008-04-13 14:57:01 -0300 | [diff] [blame] | 831 | return rc; |
Mauro Carvalho Chehab | 195a4ef | 2007-11-11 13:17:17 -0300 | [diff] [blame] | 832 | } |
| 833 | |
Nicola Soranzo | a1a6ee7 | 2009-02-10 23:28:24 -0300 | [diff] [blame] | 834 | static int vidioc_s_std(struct file *file, void *priv, v4l2_std_id *norm) |
Mauro Carvalho Chehab | 195a4ef | 2007-11-11 13:17:17 -0300 | [diff] [blame] | 835 | { |
| 836 | struct em28xx_fh *fh = priv; |
| 837 | struct em28xx *dev = fh->dev; |
| 838 | struct v4l2_format f; |
Mauro Carvalho Chehab | 195a4ef | 2007-11-11 13:17:17 -0300 | [diff] [blame] | 839 | int rc; |
| 840 | |
| 841 | rc = check_dev(dev); |
| 842 | if (rc < 0) |
| 843 | return rc; |
| 844 | |
Mauro Carvalho Chehab | 195a4ef | 2007-11-11 13:17:17 -0300 | [diff] [blame] | 845 | mutex_lock(&dev->lock); |
Mauro Carvalho Chehab | 7d497f8 | 2007-11-11 14:15:34 -0300 | [diff] [blame] | 846 | dev->norm = *norm; |
Mauro Carvalho Chehab | 195a4ef | 2007-11-11 13:17:17 -0300 | [diff] [blame] | 847 | |
| 848 | /* Adjusts width/height, if needed */ |
| 849 | f.fmt.pix.width = dev->width; |
| 850 | f.fmt.pix.height = dev->height; |
Hans Verkuil | 78b526a | 2008-05-28 12:16:41 -0300 | [diff] [blame] | 851 | vidioc_try_fmt_vid_cap(file, priv, &f); |
Mauro Carvalho Chehab | 195a4ef | 2007-11-11 13:17:17 -0300 | [diff] [blame] | 852 | |
Mauro Carvalho Chehab | 195a4ef | 2007-11-11 13:17:17 -0300 | [diff] [blame] | 853 | /* set new image size */ |
| 854 | dev->width = f.fmt.pix.width; |
| 855 | dev->height = f.fmt.pix.height; |
Mauro Carvalho Chehab | 195a4ef | 2007-11-11 13:17:17 -0300 | [diff] [blame] | 856 | get_scale(dev, dev->width, dev->height, &dev->hscale, &dev->vscale); |
| 857 | |
| 858 | em28xx_resolution_set(dev); |
Hans Verkuil | f41737e | 2009-04-01 03:52:39 -0300 | [diff] [blame] | 859 | v4l2_device_call_all(&dev->v4l2_dev, 0, core, s_std, dev->norm); |
Mauro Carvalho Chehab | 195a4ef | 2007-11-11 13:17:17 -0300 | [diff] [blame] | 860 | |
| 861 | mutex_unlock(&dev->lock); |
| 862 | return 0; |
| 863 | } |
| 864 | |
Mauro Carvalho Chehab | d96ecda | 2009-08-06 21:53:59 -0300 | [diff] [blame] | 865 | static int vidioc_g_parm(struct file *file, void *priv, |
| 866 | struct v4l2_streamparm *p) |
| 867 | { |
| 868 | struct em28xx_fh *fh = priv; |
| 869 | struct em28xx *dev = fh->dev; |
| 870 | int rc = 0; |
| 871 | |
| 872 | if (p->type != V4L2_BUF_TYPE_VIDEO_CAPTURE) |
| 873 | return -EINVAL; |
| 874 | |
| 875 | if (dev->board.is_webcam) |
| 876 | rc = v4l2_device_call_until_err(&dev->v4l2_dev, 0, |
| 877 | video, g_parm, p); |
| 878 | else |
| 879 | v4l2_video_std_frame_period(dev->norm, |
| 880 | &p->parm.capture.timeperframe); |
| 881 | |
| 882 | return rc; |
| 883 | } |
| 884 | |
| 885 | static int vidioc_s_parm(struct file *file, void *priv, |
| 886 | struct v4l2_streamparm *p) |
| 887 | { |
| 888 | struct em28xx_fh *fh = priv; |
| 889 | struct em28xx *dev = fh->dev; |
| 890 | |
| 891 | if (!dev->board.is_webcam) |
| 892 | return -EINVAL; |
| 893 | |
| 894 | if (p->type != V4L2_BUF_TYPE_VIDEO_CAPTURE) |
| 895 | return -EINVAL; |
| 896 | |
| 897 | return v4l2_device_call_until_err(&dev->v4l2_dev, 0, video, s_parm, p); |
| 898 | } |
| 899 | |
Mauro Carvalho Chehab | 195a4ef | 2007-11-11 13:17:17 -0300 | [diff] [blame] | 900 | static const char *iname[] = { |
| 901 | [EM28XX_VMUX_COMPOSITE1] = "Composite1", |
| 902 | [EM28XX_VMUX_COMPOSITE2] = "Composite2", |
| 903 | [EM28XX_VMUX_COMPOSITE3] = "Composite3", |
| 904 | [EM28XX_VMUX_COMPOSITE4] = "Composite4", |
| 905 | [EM28XX_VMUX_SVIDEO] = "S-Video", |
| 906 | [EM28XX_VMUX_TELEVISION] = "Television", |
| 907 | [EM28XX_VMUX_CABLE] = "Cable TV", |
| 908 | [EM28XX_VMUX_DVB] = "DVB", |
| 909 | [EM28XX_VMUX_DEBUG] = "for debug only", |
| 910 | }; |
| 911 | |
| 912 | static int vidioc_enum_input(struct file *file, void *priv, |
| 913 | struct v4l2_input *i) |
| 914 | { |
| 915 | struct em28xx_fh *fh = priv; |
| 916 | struct em28xx *dev = fh->dev; |
| 917 | unsigned int n; |
| 918 | |
| 919 | n = i->index; |
| 920 | if (n >= MAX_EM28XX_INPUT) |
| 921 | return -EINVAL; |
| 922 | if (0 == INPUT(n)->type) |
| 923 | return -EINVAL; |
| 924 | |
| 925 | i->index = n; |
| 926 | i->type = V4L2_INPUT_TYPE_CAMERA; |
| 927 | |
| 928 | strcpy(i->name, iname[INPUT(n)->type]); |
| 929 | |
| 930 | if ((EM28XX_VMUX_TELEVISION == INPUT(n)->type) || |
| 931 | (EM28XX_VMUX_CABLE == INPUT(n)->type)) |
| 932 | i->type = V4L2_INPUT_TYPE_TUNER; |
| 933 | |
Mauro Carvalho Chehab | 7d497f8 | 2007-11-11 14:15:34 -0300 | [diff] [blame] | 934 | i->std = dev->vdev->tvnorms; |
Mauro Carvalho Chehab | 195a4ef | 2007-11-11 13:17:17 -0300 | [diff] [blame] | 935 | |
| 936 | return 0; |
| 937 | } |
| 938 | |
| 939 | static int vidioc_g_input(struct file *file, void *priv, unsigned int *i) |
| 940 | { |
| 941 | struct em28xx_fh *fh = priv; |
| 942 | struct em28xx *dev = fh->dev; |
| 943 | |
| 944 | *i = dev->ctl_input; |
| 945 | |
| 946 | return 0; |
| 947 | } |
| 948 | |
| 949 | static int vidioc_s_input(struct file *file, void *priv, unsigned int i) |
| 950 | { |
| 951 | struct em28xx_fh *fh = priv; |
| 952 | struct em28xx *dev = fh->dev; |
| 953 | int rc; |
| 954 | |
| 955 | rc = check_dev(dev); |
| 956 | if (rc < 0) |
| 957 | return rc; |
| 958 | |
| 959 | if (i >= MAX_EM28XX_INPUT) |
| 960 | return -EINVAL; |
| 961 | if (0 == INPUT(i)->type) |
| 962 | return -EINVAL; |
| 963 | |
Mauro Carvalho Chehab | 24c3c41 | 2009-01-07 22:49:25 -0300 | [diff] [blame] | 964 | dev->ctl_input = i; |
| 965 | |
Mauro Carvalho Chehab | 195a4ef | 2007-11-11 13:17:17 -0300 | [diff] [blame] | 966 | mutex_lock(&dev->lock); |
Mauro Carvalho Chehab | 24c3c41 | 2009-01-07 22:49:25 -0300 | [diff] [blame] | 967 | video_mux(dev, dev->ctl_input); |
Mauro Carvalho Chehab | 195a4ef | 2007-11-11 13:17:17 -0300 | [diff] [blame] | 968 | mutex_unlock(&dev->lock); |
| 969 | return 0; |
| 970 | } |
| 971 | |
| 972 | static int vidioc_g_audio(struct file *file, void *priv, struct v4l2_audio *a) |
| 973 | { |
| 974 | struct em28xx_fh *fh = priv; |
| 975 | struct em28xx *dev = fh->dev; |
Mauro Carvalho Chehab | 195a4ef | 2007-11-11 13:17:17 -0300 | [diff] [blame] | 976 | |
Mauro Carvalho Chehab | 35ae6f0 | 2008-11-20 12:40:51 -0300 | [diff] [blame] | 977 | switch (a->index) { |
| 978 | case EM28XX_AMUX_VIDEO: |
Mauro Carvalho Chehab | 195a4ef | 2007-11-11 13:17:17 -0300 | [diff] [blame] | 979 | strcpy(a->name, "Television"); |
Mauro Carvalho Chehab | 35ae6f0 | 2008-11-20 12:40:51 -0300 | [diff] [blame] | 980 | break; |
| 981 | case EM28XX_AMUX_LINE_IN: |
Mauro Carvalho Chehab | 195a4ef | 2007-11-11 13:17:17 -0300 | [diff] [blame] | 982 | strcpy(a->name, "Line In"); |
Mauro Carvalho Chehab | 35ae6f0 | 2008-11-20 12:40:51 -0300 | [diff] [blame] | 983 | break; |
| 984 | case EM28XX_AMUX_VIDEO2: |
| 985 | strcpy(a->name, "Television alt"); |
| 986 | break; |
| 987 | case EM28XX_AMUX_PHONE: |
| 988 | strcpy(a->name, "Phone"); |
| 989 | break; |
| 990 | case EM28XX_AMUX_MIC: |
| 991 | strcpy(a->name, "Mic"); |
| 992 | break; |
| 993 | case EM28XX_AMUX_CD: |
| 994 | strcpy(a->name, "CD"); |
| 995 | break; |
| 996 | case EM28XX_AMUX_AUX: |
| 997 | strcpy(a->name, "Aux"); |
| 998 | break; |
| 999 | case EM28XX_AMUX_PCM_OUT: |
| 1000 | strcpy(a->name, "PCM"); |
| 1001 | break; |
| 1002 | default: |
| 1003 | return -EINVAL; |
| 1004 | } |
Douglas Schilling Landgraf | 6ea54d9 | 2008-04-17 21:41:10 -0300 | [diff] [blame] | 1005 | |
Mauro Carvalho Chehab | 35ae6f0 | 2008-11-20 12:40:51 -0300 | [diff] [blame] | 1006 | a->index = dev->ctl_ainput; |
Mauro Carvalho Chehab | 195a4ef | 2007-11-11 13:17:17 -0300 | [diff] [blame] | 1007 | a->capability = V4L2_AUDCAP_STEREO; |
Mauro Carvalho Chehab | 195a4ef | 2007-11-11 13:17:17 -0300 | [diff] [blame] | 1008 | |
| 1009 | return 0; |
| 1010 | } |
| 1011 | |
| 1012 | static int vidioc_s_audio(struct file *file, void *priv, struct v4l2_audio *a) |
| 1013 | { |
| 1014 | struct em28xx_fh *fh = priv; |
| 1015 | struct em28xx *dev = fh->dev; |
| 1016 | |
Mauro Carvalho Chehab | 24c3c41 | 2009-01-07 22:49:25 -0300 | [diff] [blame] | 1017 | |
| 1018 | if (a->index >= MAX_EM28XX_INPUT) |
| 1019 | return -EINVAL; |
| 1020 | if (0 == INPUT(a->index)->type) |
| 1021 | return -EINVAL; |
| 1022 | |
Mauro Carvalho Chehab | efc52a9 | 2008-12-16 22:04:56 -0300 | [diff] [blame] | 1023 | mutex_lock(&dev->lock); |
| 1024 | |
Mauro Carvalho Chehab | 35ae6f0 | 2008-11-20 12:40:51 -0300 | [diff] [blame] | 1025 | dev->ctl_ainput = INPUT(a->index)->amux; |
| 1026 | dev->ctl_aoutput = INPUT(a->index)->aout; |
Mauro Carvalho Chehab | e879b8e | 2008-11-20 13:39:39 -0300 | [diff] [blame] | 1027 | |
| 1028 | if (!dev->ctl_aoutput) |
| 1029 | dev->ctl_aoutput = EM28XX_AOUT_MASTER; |
Mauro Carvalho Chehab | efc52a9 | 2008-12-16 22:04:56 -0300 | [diff] [blame] | 1030 | |
| 1031 | mutex_unlock(&dev->lock); |
Mauro Carvalho Chehab | 195a4ef | 2007-11-11 13:17:17 -0300 | [diff] [blame] | 1032 | return 0; |
| 1033 | } |
| 1034 | |
| 1035 | static int vidioc_queryctrl(struct file *file, void *priv, |
| 1036 | struct v4l2_queryctrl *qc) |
| 1037 | { |
| 1038 | struct em28xx_fh *fh = priv; |
| 1039 | struct em28xx *dev = fh->dev; |
| 1040 | int id = qc->id; |
| 1041 | int i; |
| 1042 | int rc; |
| 1043 | |
| 1044 | rc = check_dev(dev); |
| 1045 | if (rc < 0) |
| 1046 | return rc; |
| 1047 | |
| 1048 | memset(qc, 0, sizeof(*qc)); |
| 1049 | |
| 1050 | qc->id = id; |
| 1051 | |
Mauro Carvalho Chehab | 505b6d0 | 2008-11-25 09:39:50 -0300 | [diff] [blame] | 1052 | if (!dev->board.has_msp34xx) { |
Mauro Carvalho Chehab | 195a4ef | 2007-11-11 13:17:17 -0300 | [diff] [blame] | 1053 | for (i = 0; i < ARRAY_SIZE(em28xx_qctrl); i++) { |
| 1054 | if (qc->id && qc->id == em28xx_qctrl[i].id) { |
| 1055 | memcpy(qc, &(em28xx_qctrl[i]), sizeof(*qc)); |
| 1056 | return 0; |
| 1057 | } |
| 1058 | } |
| 1059 | } |
Douglas Schilling Landgraf | f2cf250 | 2009-03-31 17:10:58 -0300 | [diff] [blame] | 1060 | |
Mauro Carvalho Chehab | 195a4ef | 2007-11-11 13:17:17 -0300 | [diff] [blame] | 1061 | mutex_lock(&dev->lock); |
Douglas Schilling Landgraf | f2cf250 | 2009-03-31 17:10:58 -0300 | [diff] [blame] | 1062 | v4l2_device_call_all(&dev->v4l2_dev, 0, core, queryctrl, qc); |
Mauro Carvalho Chehab | 195a4ef | 2007-11-11 13:17:17 -0300 | [diff] [blame] | 1063 | mutex_unlock(&dev->lock); |
| 1064 | |
| 1065 | if (qc->type) |
| 1066 | return 0; |
| 1067 | else |
| 1068 | return -EINVAL; |
| 1069 | } |
| 1070 | |
| 1071 | static int vidioc_g_ctrl(struct file *file, void *priv, |
| 1072 | struct v4l2_control *ctrl) |
| 1073 | { |
| 1074 | struct em28xx_fh *fh = priv; |
| 1075 | struct em28xx *dev = fh->dev; |
| 1076 | int rc; |
| 1077 | |
| 1078 | rc = check_dev(dev); |
| 1079 | if (rc < 0) |
| 1080 | return rc; |
Mauro Carvalho Chehab | b6070f0 | 2008-12-22 06:20:32 -0300 | [diff] [blame] | 1081 | rc = 0; |
Mauro Carvalho Chehab | efc52a9 | 2008-12-16 22:04:56 -0300 | [diff] [blame] | 1082 | |
Mauro Carvalho Chehab | 195a4ef | 2007-11-11 13:17:17 -0300 | [diff] [blame] | 1083 | mutex_lock(&dev->lock); |
| 1084 | |
Mauro Carvalho Chehab | b6070f0 | 2008-12-22 06:20:32 -0300 | [diff] [blame] | 1085 | if (dev->board.has_msp34xx) |
Douglas Schilling Landgraf | f2cf250 | 2009-03-31 17:10:58 -0300 | [diff] [blame] | 1086 | v4l2_device_call_all(&dev->v4l2_dev, 0, core, g_ctrl, ctrl); |
Hans Verkuil | 07f7db4 | 2009-01-21 17:06:42 -0300 | [diff] [blame] | 1087 | else { |
Mauro Carvalho Chehab | b6070f0 | 2008-12-22 06:20:32 -0300 | [diff] [blame] | 1088 | rc = em28xx_get_ctrl(dev, ctrl); |
Hans Verkuil | 07f7db4 | 2009-01-21 17:06:42 -0300 | [diff] [blame] | 1089 | if (rc < 0) { |
Douglas Schilling Landgraf | f2cf250 | 2009-03-31 17:10:58 -0300 | [diff] [blame] | 1090 | v4l2_device_call_all(&dev->v4l2_dev, 0, core, g_ctrl, ctrl); |
Hans Verkuil | 07f7db4 | 2009-01-21 17:06:42 -0300 | [diff] [blame] | 1091 | rc = 0; |
| 1092 | } |
| 1093 | } |
Mauro Carvalho Chehab | 195a4ef | 2007-11-11 13:17:17 -0300 | [diff] [blame] | 1094 | |
| 1095 | mutex_unlock(&dev->lock); |
| 1096 | return rc; |
| 1097 | } |
| 1098 | |
| 1099 | static int vidioc_s_ctrl(struct file *file, void *priv, |
| 1100 | struct v4l2_control *ctrl) |
| 1101 | { |
| 1102 | struct em28xx_fh *fh = priv; |
| 1103 | struct em28xx *dev = fh->dev; |
| 1104 | u8 i; |
| 1105 | int rc; |
| 1106 | |
| 1107 | rc = check_dev(dev); |
| 1108 | if (rc < 0) |
| 1109 | return rc; |
| 1110 | |
| 1111 | mutex_lock(&dev->lock); |
| 1112 | |
Mauro Carvalho Chehab | 505b6d0 | 2008-11-25 09:39:50 -0300 | [diff] [blame] | 1113 | if (dev->board.has_msp34xx) |
Douglas Schilling Landgraf | f2cf250 | 2009-03-31 17:10:58 -0300 | [diff] [blame] | 1114 | v4l2_device_call_all(&dev->v4l2_dev, 0, core, s_ctrl, ctrl); |
Mauro Carvalho Chehab | 195a4ef | 2007-11-11 13:17:17 -0300 | [diff] [blame] | 1115 | else { |
| 1116 | rc = 1; |
| 1117 | for (i = 0; i < ARRAY_SIZE(em28xx_qctrl); i++) { |
| 1118 | if (ctrl->id == em28xx_qctrl[i].id) { |
| 1119 | if (ctrl->value < em28xx_qctrl[i].minimum || |
| 1120 | ctrl->value > em28xx_qctrl[i].maximum) { |
| 1121 | rc = -ERANGE; |
| 1122 | break; |
| 1123 | } |
| 1124 | |
| 1125 | rc = em28xx_set_ctrl(dev, ctrl); |
| 1126 | break; |
| 1127 | } |
| 1128 | } |
| 1129 | } |
| 1130 | |
| 1131 | /* Control not found - try to send it to the attached devices */ |
| 1132 | if (rc == 1) { |
Douglas Schilling Landgraf | f2cf250 | 2009-03-31 17:10:58 -0300 | [diff] [blame] | 1133 | v4l2_device_call_all(&dev->v4l2_dev, 0, core, s_ctrl, ctrl); |
Mauro Carvalho Chehab | 195a4ef | 2007-11-11 13:17:17 -0300 | [diff] [blame] | 1134 | rc = 0; |
| 1135 | } |
| 1136 | |
| 1137 | mutex_unlock(&dev->lock); |
| 1138 | return rc; |
| 1139 | } |
| 1140 | |
| 1141 | static int vidioc_g_tuner(struct file *file, void *priv, |
| 1142 | struct v4l2_tuner *t) |
| 1143 | { |
| 1144 | struct em28xx_fh *fh = priv; |
| 1145 | struct em28xx *dev = fh->dev; |
| 1146 | int rc; |
| 1147 | |
| 1148 | rc = check_dev(dev); |
| 1149 | if (rc < 0) |
| 1150 | return rc; |
| 1151 | |
| 1152 | if (0 != t->index) |
| 1153 | return -EINVAL; |
| 1154 | |
| 1155 | strcpy(t->name, "Tuner"); |
| 1156 | |
| 1157 | mutex_lock(&dev->lock); |
Douglas Schilling Landgraf | f2cf250 | 2009-03-31 17:10:58 -0300 | [diff] [blame] | 1158 | v4l2_device_call_all(&dev->v4l2_dev, 0, tuner, g_tuner, t); |
Mauro Carvalho Chehab | 195a4ef | 2007-11-11 13:17:17 -0300 | [diff] [blame] | 1159 | mutex_unlock(&dev->lock); |
Douglas Schilling Landgraf | f2cf250 | 2009-03-31 17:10:58 -0300 | [diff] [blame] | 1160 | |
Mauro Carvalho Chehab | 195a4ef | 2007-11-11 13:17:17 -0300 | [diff] [blame] | 1161 | return 0; |
| 1162 | } |
| 1163 | |
| 1164 | static int vidioc_s_tuner(struct file *file, void *priv, |
| 1165 | struct v4l2_tuner *t) |
| 1166 | { |
| 1167 | struct em28xx_fh *fh = priv; |
| 1168 | struct em28xx *dev = fh->dev; |
| 1169 | int rc; |
| 1170 | |
| 1171 | rc = check_dev(dev); |
| 1172 | if (rc < 0) |
| 1173 | return rc; |
| 1174 | |
| 1175 | if (0 != t->index) |
| 1176 | return -EINVAL; |
| 1177 | |
| 1178 | mutex_lock(&dev->lock); |
Douglas Schilling Landgraf | f2cf250 | 2009-03-31 17:10:58 -0300 | [diff] [blame] | 1179 | v4l2_device_call_all(&dev->v4l2_dev, 0, tuner, s_tuner, t); |
Mauro Carvalho Chehab | 195a4ef | 2007-11-11 13:17:17 -0300 | [diff] [blame] | 1180 | mutex_unlock(&dev->lock); |
Douglas Schilling Landgraf | f2cf250 | 2009-03-31 17:10:58 -0300 | [diff] [blame] | 1181 | |
Mauro Carvalho Chehab | 195a4ef | 2007-11-11 13:17:17 -0300 | [diff] [blame] | 1182 | return 0; |
| 1183 | } |
| 1184 | |
| 1185 | static int vidioc_g_frequency(struct file *file, void *priv, |
| 1186 | struct v4l2_frequency *f) |
| 1187 | { |
| 1188 | struct em28xx_fh *fh = priv; |
| 1189 | struct em28xx *dev = fh->dev; |
| 1190 | |
Mauro Carvalho Chehab | efc52a9 | 2008-12-16 22:04:56 -0300 | [diff] [blame] | 1191 | mutex_lock(&dev->lock); |
Mauro Carvalho Chehab | 0be4375 | 2008-01-05 17:22:01 -0300 | [diff] [blame] | 1192 | f->type = fh->radio ? V4L2_TUNER_RADIO : V4L2_TUNER_ANALOG_TV; |
Mauro Carvalho Chehab | 195a4ef | 2007-11-11 13:17:17 -0300 | [diff] [blame] | 1193 | f->frequency = dev->ctl_freq; |
Mauro Carvalho Chehab | efc52a9 | 2008-12-16 22:04:56 -0300 | [diff] [blame] | 1194 | mutex_unlock(&dev->lock); |
Mauro Carvalho Chehab | 195a4ef | 2007-11-11 13:17:17 -0300 | [diff] [blame] | 1195 | |
| 1196 | return 0; |
| 1197 | } |
| 1198 | |
| 1199 | static int vidioc_s_frequency(struct file *file, void *priv, |
| 1200 | struct v4l2_frequency *f) |
| 1201 | { |
| 1202 | struct em28xx_fh *fh = priv; |
| 1203 | struct em28xx *dev = fh->dev; |
| 1204 | int rc; |
| 1205 | |
| 1206 | rc = check_dev(dev); |
| 1207 | if (rc < 0) |
| 1208 | return rc; |
| 1209 | |
| 1210 | if (0 != f->tuner) |
| 1211 | return -EINVAL; |
| 1212 | |
Mauro Carvalho Chehab | 0be4375 | 2008-01-05 17:22:01 -0300 | [diff] [blame] | 1213 | if (unlikely(0 == fh->radio && f->type != V4L2_TUNER_ANALOG_TV)) |
| 1214 | return -EINVAL; |
| 1215 | if (unlikely(1 == fh->radio && f->type != V4L2_TUNER_RADIO)) |
Mauro Carvalho Chehab | 195a4ef | 2007-11-11 13:17:17 -0300 | [diff] [blame] | 1216 | return -EINVAL; |
| 1217 | |
| 1218 | mutex_lock(&dev->lock); |
| 1219 | |
| 1220 | dev->ctl_freq = f->frequency; |
Douglas Schilling Landgraf | f2cf250 | 2009-03-31 17:10:58 -0300 | [diff] [blame] | 1221 | v4l2_device_call_all(&dev->v4l2_dev, 0, tuner, s_frequency, f); |
Mauro Carvalho Chehab | 195a4ef | 2007-11-11 13:17:17 -0300 | [diff] [blame] | 1222 | |
| 1223 | mutex_unlock(&dev->lock); |
Mauro Carvalho Chehab | efc52a9 | 2008-12-16 22:04:56 -0300 | [diff] [blame] | 1224 | |
Mauro Carvalho Chehab | 195a4ef | 2007-11-11 13:17:17 -0300 | [diff] [blame] | 1225 | return 0; |
| 1226 | } |
| 1227 | |
Mauro Carvalho Chehab | 1e7ad56 | 2008-02-06 09:00:41 -0300 | [diff] [blame] | 1228 | #ifdef CONFIG_VIDEO_ADV_DEBUG |
| 1229 | static int em28xx_reg_len(int reg) |
| 1230 | { |
| 1231 | switch (reg) { |
Mauro Carvalho Chehab | 41facaa | 2008-04-17 21:44:58 -0300 | [diff] [blame] | 1232 | case EM28XX_R40_AC97LSB: |
| 1233 | case EM28XX_R30_HSCALELOW: |
| 1234 | case EM28XX_R32_VSCALELOW: |
Mauro Carvalho Chehab | 1e7ad56 | 2008-02-06 09:00:41 -0300 | [diff] [blame] | 1235 | return 2; |
| 1236 | default: |
| 1237 | return 1; |
| 1238 | } |
| 1239 | } |
| 1240 | |
Mauro Carvalho Chehab | 14983d8 | 2008-12-22 20:58:41 -0300 | [diff] [blame] | 1241 | static int vidioc_g_chip_ident(struct file *file, void *priv, |
Hans Verkuil | aecde8b5 | 2008-12-30 07:14:19 -0300 | [diff] [blame] | 1242 | struct v4l2_dbg_chip_ident *chip) |
Mauro Carvalho Chehab | 14983d8 | 2008-12-22 20:58:41 -0300 | [diff] [blame] | 1243 | { |
| 1244 | struct em28xx_fh *fh = priv; |
| 1245 | struct em28xx *dev = fh->dev; |
| 1246 | |
| 1247 | chip->ident = V4L2_IDENT_NONE; |
| 1248 | chip->revision = 0; |
| 1249 | |
Douglas Schilling Landgraf | f2cf250 | 2009-03-31 17:10:58 -0300 | [diff] [blame] | 1250 | v4l2_device_call_all(&dev->v4l2_dev, 0, core, g_chip_ident, chip); |
Mauro Carvalho Chehab | 14983d8 | 2008-12-22 20:58:41 -0300 | [diff] [blame] | 1251 | |
| 1252 | return 0; |
| 1253 | } |
| 1254 | |
| 1255 | |
Mauro Carvalho Chehab | 1e7ad56 | 2008-02-06 09:00:41 -0300 | [diff] [blame] | 1256 | static int vidioc_g_register(struct file *file, void *priv, |
Hans Verkuil | aecde8b5 | 2008-12-30 07:14:19 -0300 | [diff] [blame] | 1257 | struct v4l2_dbg_register *reg) |
Mauro Carvalho Chehab | 1e7ad56 | 2008-02-06 09:00:41 -0300 | [diff] [blame] | 1258 | { |
| 1259 | struct em28xx_fh *fh = priv; |
| 1260 | struct em28xx *dev = fh->dev; |
| 1261 | int ret; |
| 1262 | |
Hans Verkuil | aecde8b5 | 2008-12-30 07:14:19 -0300 | [diff] [blame] | 1263 | switch (reg->match.type) { |
Mauro Carvalho Chehab | 14983d8 | 2008-12-22 20:58:41 -0300 | [diff] [blame] | 1264 | case V4L2_CHIP_MATCH_AC97: |
Mauro Carvalho Chehab | 531c98e | 2008-12-22 13:18:27 -0300 | [diff] [blame] | 1265 | mutex_lock(&dev->lock); |
| 1266 | ret = em28xx_read_ac97(dev, reg->reg); |
| 1267 | mutex_unlock(&dev->lock); |
| 1268 | if (ret < 0) |
| 1269 | return ret; |
| 1270 | |
| 1271 | reg->val = ret; |
Hans Verkuil | aecde8b5 | 2008-12-30 07:14:19 -0300 | [diff] [blame] | 1272 | reg->size = 1; |
Mauro Carvalho Chehab | 531c98e | 2008-12-22 13:18:27 -0300 | [diff] [blame] | 1273 | return 0; |
Mauro Carvalho Chehab | 14983d8 | 2008-12-22 20:58:41 -0300 | [diff] [blame] | 1274 | case V4L2_CHIP_MATCH_I2C_DRIVER: |
Douglas Schilling Landgraf | f2cf250 | 2009-03-31 17:10:58 -0300 | [diff] [blame] | 1275 | v4l2_device_call_all(&dev->v4l2_dev, 0, core, g_register, reg); |
Mauro Carvalho Chehab | 14983d8 | 2008-12-22 20:58:41 -0300 | [diff] [blame] | 1276 | return 0; |
| 1277 | case V4L2_CHIP_MATCH_I2C_ADDR: |
| 1278 | /* Not supported yet */ |
| 1279 | return -EINVAL; |
| 1280 | default: |
Hans Verkuil | aecde8b5 | 2008-12-30 07:14:19 -0300 | [diff] [blame] | 1281 | if (!v4l2_chip_match_host(®->match)) |
Mauro Carvalho Chehab | 14983d8 | 2008-12-22 20:58:41 -0300 | [diff] [blame] | 1282 | return -EINVAL; |
Mauro Carvalho Chehab | 531c98e | 2008-12-22 13:18:27 -0300 | [diff] [blame] | 1283 | } |
| 1284 | |
Mauro Carvalho Chehab | 14983d8 | 2008-12-22 20:58:41 -0300 | [diff] [blame] | 1285 | /* Match host */ |
Hans Verkuil | aecde8b5 | 2008-12-30 07:14:19 -0300 | [diff] [blame] | 1286 | reg->size = em28xx_reg_len(reg->reg); |
| 1287 | if (reg->size == 1) { |
Mauro Carvalho Chehab | efc52a9 | 2008-12-16 22:04:56 -0300 | [diff] [blame] | 1288 | mutex_lock(&dev->lock); |
Mauro Carvalho Chehab | 1e7ad56 | 2008-02-06 09:00:41 -0300 | [diff] [blame] | 1289 | ret = em28xx_read_reg(dev, reg->reg); |
Mauro Carvalho Chehab | efc52a9 | 2008-12-16 22:04:56 -0300 | [diff] [blame] | 1290 | mutex_unlock(&dev->lock); |
| 1291 | |
Mauro Carvalho Chehab | 1e7ad56 | 2008-02-06 09:00:41 -0300 | [diff] [blame] | 1292 | if (ret < 0) |
| 1293 | return ret; |
| 1294 | |
| 1295 | reg->val = ret; |
| 1296 | } else { |
Hans Verkuil | aecde8b5 | 2008-12-30 07:14:19 -0300 | [diff] [blame] | 1297 | __le16 val = 0; |
Mauro Carvalho Chehab | efc52a9 | 2008-12-16 22:04:56 -0300 | [diff] [blame] | 1298 | mutex_lock(&dev->lock); |
Mauro Carvalho Chehab | 1e7ad56 | 2008-02-06 09:00:41 -0300 | [diff] [blame] | 1299 | ret = em28xx_read_reg_req_len(dev, USB_REQ_GET_STATUS, |
| 1300 | reg->reg, (char *)&val, 2); |
Mauro Carvalho Chehab | efc52a9 | 2008-12-16 22:04:56 -0300 | [diff] [blame] | 1301 | mutex_unlock(&dev->lock); |
Mauro Carvalho Chehab | 1e7ad56 | 2008-02-06 09:00:41 -0300 | [diff] [blame] | 1302 | if (ret < 0) |
| 1303 | return ret; |
| 1304 | |
Hans Verkuil | aecde8b5 | 2008-12-30 07:14:19 -0300 | [diff] [blame] | 1305 | reg->val = le16_to_cpu(val); |
Mauro Carvalho Chehab | 1e7ad56 | 2008-02-06 09:00:41 -0300 | [diff] [blame] | 1306 | } |
| 1307 | |
| 1308 | return 0; |
| 1309 | } |
| 1310 | |
| 1311 | static int vidioc_s_register(struct file *file, void *priv, |
Hans Verkuil | aecde8b5 | 2008-12-30 07:14:19 -0300 | [diff] [blame] | 1312 | struct v4l2_dbg_register *reg) |
Mauro Carvalho Chehab | 1e7ad56 | 2008-02-06 09:00:41 -0300 | [diff] [blame] | 1313 | { |
| 1314 | struct em28xx_fh *fh = priv; |
| 1315 | struct em28xx *dev = fh->dev; |
Hans Verkuil | aecde8b5 | 2008-12-30 07:14:19 -0300 | [diff] [blame] | 1316 | __le16 buf; |
Mauro Carvalho Chehab | efc52a9 | 2008-12-16 22:04:56 -0300 | [diff] [blame] | 1317 | int rc; |
Mauro Carvalho Chehab | 1e7ad56 | 2008-02-06 09:00:41 -0300 | [diff] [blame] | 1318 | |
Hans Verkuil | aecde8b5 | 2008-12-30 07:14:19 -0300 | [diff] [blame] | 1319 | switch (reg->match.type) { |
Mauro Carvalho Chehab | 14983d8 | 2008-12-22 20:58:41 -0300 | [diff] [blame] | 1320 | case V4L2_CHIP_MATCH_AC97: |
Mauro Carvalho Chehab | 531c98e | 2008-12-22 13:18:27 -0300 | [diff] [blame] | 1321 | mutex_lock(&dev->lock); |
| 1322 | rc = em28xx_write_ac97(dev, reg->reg, reg->val); |
| 1323 | mutex_unlock(&dev->lock); |
| 1324 | |
| 1325 | return rc; |
Mauro Carvalho Chehab | 14983d8 | 2008-12-22 20:58:41 -0300 | [diff] [blame] | 1326 | case V4L2_CHIP_MATCH_I2C_DRIVER: |
Douglas Schilling Landgraf | f2cf250 | 2009-03-31 17:10:58 -0300 | [diff] [blame] | 1327 | v4l2_device_call_all(&dev->v4l2_dev, 0, core, s_register, reg); |
Mauro Carvalho Chehab | 14983d8 | 2008-12-22 20:58:41 -0300 | [diff] [blame] | 1328 | return 0; |
| 1329 | case V4L2_CHIP_MATCH_I2C_ADDR: |
| 1330 | /* Not supported yet */ |
| 1331 | return -EINVAL; |
| 1332 | default: |
Hans Verkuil | aecde8b5 | 2008-12-30 07:14:19 -0300 | [diff] [blame] | 1333 | if (!v4l2_chip_match_host(®->match)) |
Mauro Carvalho Chehab | 14983d8 | 2008-12-22 20:58:41 -0300 | [diff] [blame] | 1334 | return -EINVAL; |
Mauro Carvalho Chehab | 531c98e | 2008-12-22 13:18:27 -0300 | [diff] [blame] | 1335 | } |
| 1336 | |
Mauro Carvalho Chehab | 14983d8 | 2008-12-22 20:58:41 -0300 | [diff] [blame] | 1337 | /* Match host */ |
Hans Verkuil | aecde8b5 | 2008-12-30 07:14:19 -0300 | [diff] [blame] | 1338 | buf = cpu_to_le16(reg->val); |
Mauro Carvalho Chehab | 1e7ad56 | 2008-02-06 09:00:41 -0300 | [diff] [blame] | 1339 | |
Mauro Carvalho Chehab | efc52a9 | 2008-12-16 22:04:56 -0300 | [diff] [blame] | 1340 | mutex_lock(&dev->lock); |
| 1341 | rc = em28xx_write_regs(dev, reg->reg, (char *)&buf, |
| 1342 | em28xx_reg_len(reg->reg)); |
| 1343 | mutex_unlock(&dev->lock); |
| 1344 | |
| 1345 | return rc; |
Mauro Carvalho Chehab | 1e7ad56 | 2008-02-06 09:00:41 -0300 | [diff] [blame] | 1346 | } |
| 1347 | #endif |
| 1348 | |
| 1349 | |
Mauro Carvalho Chehab | 195a4ef | 2007-11-11 13:17:17 -0300 | [diff] [blame] | 1350 | static int vidioc_cropcap(struct file *file, void *priv, |
| 1351 | struct v4l2_cropcap *cc) |
| 1352 | { |
| 1353 | struct em28xx_fh *fh = priv; |
| 1354 | struct em28xx *dev = fh->dev; |
| 1355 | |
| 1356 | if (cc->type != V4L2_BUF_TYPE_VIDEO_CAPTURE) |
| 1357 | return -EINVAL; |
| 1358 | |
| 1359 | cc->bounds.left = 0; |
| 1360 | cc->bounds.top = 0; |
| 1361 | cc->bounds.width = dev->width; |
| 1362 | cc->bounds.height = dev->height; |
| 1363 | cc->defrect = cc->bounds; |
| 1364 | cc->pixelaspect.numerator = 54; /* 4:3 FIXME: remove magic numbers */ |
| 1365 | cc->pixelaspect.denominator = 59; |
| 1366 | |
| 1367 | return 0; |
| 1368 | } |
| 1369 | |
| 1370 | static int vidioc_streamon(struct file *file, void *priv, |
| 1371 | enum v4l2_buf_type type) |
| 1372 | { |
| 1373 | struct em28xx_fh *fh = priv; |
| 1374 | struct em28xx *dev = fh->dev; |
| 1375 | int rc; |
| 1376 | |
| 1377 | rc = check_dev(dev); |
| 1378 | if (rc < 0) |
| 1379 | return rc; |
| 1380 | |
Mauro Carvalho Chehab | 195a4ef | 2007-11-11 13:17:17 -0300 | [diff] [blame] | 1381 | |
Mauro Carvalho Chehab | 29b5941 | 2008-12-16 20:19:24 -0300 | [diff] [blame] | 1382 | mutex_lock(&dev->lock); |
| 1383 | rc = res_get(fh); |
Mauro Carvalho Chehab | 29b5941 | 2008-12-16 20:19:24 -0300 | [diff] [blame] | 1384 | |
Mauro Carvalho Chehab | 5db0b5e | 2008-12-22 06:14:31 -0300 | [diff] [blame] | 1385 | if (likely(rc >= 0)) |
| 1386 | rc = videobuf_streamon(&fh->vb_vidq); |
Mauro Carvalho Chehab | efc52a9 | 2008-12-16 22:04:56 -0300 | [diff] [blame] | 1387 | |
| 1388 | mutex_unlock(&dev->lock); |
| 1389 | |
| 1390 | return rc; |
Mauro Carvalho Chehab | 195a4ef | 2007-11-11 13:17:17 -0300 | [diff] [blame] | 1391 | } |
| 1392 | |
| 1393 | static int vidioc_streamoff(struct file *file, void *priv, |
| 1394 | enum v4l2_buf_type type) |
| 1395 | { |
| 1396 | struct em28xx_fh *fh = priv; |
| 1397 | struct em28xx *dev = fh->dev; |
| 1398 | int rc; |
| 1399 | |
| 1400 | rc = check_dev(dev); |
| 1401 | if (rc < 0) |
| 1402 | return rc; |
| 1403 | |
Mauro Carvalho Chehab | ad0ebb9 | 2008-04-13 14:37:52 -0300 | [diff] [blame] | 1404 | if (fh->type != V4L2_BUF_TYPE_VIDEO_CAPTURE) |
| 1405 | return -EINVAL; |
| 1406 | if (type != fh->type) |
Mauro Carvalho Chehab | 195a4ef | 2007-11-11 13:17:17 -0300 | [diff] [blame] | 1407 | return -EINVAL; |
| 1408 | |
Mauro Carvalho Chehab | 7831364 | 2008-12-16 20:00:49 -0300 | [diff] [blame] | 1409 | mutex_lock(&dev->lock); |
Mauro Carvalho Chehab | efc52a9 | 2008-12-16 22:04:56 -0300 | [diff] [blame] | 1410 | |
| 1411 | videobuf_streamoff(&fh->vb_vidq); |
Mauro Carvalho Chehab | ad0ebb9 | 2008-04-13 14:37:52 -0300 | [diff] [blame] | 1412 | res_free(fh); |
Mauro Carvalho Chehab | efc52a9 | 2008-12-16 22:04:56 -0300 | [diff] [blame] | 1413 | |
Mauro Carvalho Chehab | 7831364 | 2008-12-16 20:00:49 -0300 | [diff] [blame] | 1414 | mutex_unlock(&dev->lock); |
Mauro Carvalho Chehab | 195a4ef | 2007-11-11 13:17:17 -0300 | [diff] [blame] | 1415 | |
Mauro Carvalho Chehab | 195a4ef | 2007-11-11 13:17:17 -0300 | [diff] [blame] | 1416 | return 0; |
| 1417 | } |
| 1418 | |
| 1419 | static int vidioc_querycap(struct file *file, void *priv, |
| 1420 | struct v4l2_capability *cap) |
| 1421 | { |
| 1422 | struct em28xx_fh *fh = priv; |
| 1423 | struct em28xx *dev = fh->dev; |
| 1424 | |
| 1425 | strlcpy(cap->driver, "em28xx", sizeof(cap->driver)); |
| 1426 | strlcpy(cap->card, em28xx_boards[dev->model].name, sizeof(cap->card)); |
Thierry MERLE | cb97716 | 2009-01-20 18:01:33 -0300 | [diff] [blame] | 1427 | usb_make_path(dev->udev, cap->bus_info, sizeof(cap->bus_info)); |
Mauro Carvalho Chehab | 195a4ef | 2007-11-11 13:17:17 -0300 | [diff] [blame] | 1428 | |
| 1429 | cap->version = EM28XX_VERSION_CODE; |
| 1430 | |
| 1431 | cap->capabilities = |
| 1432 | V4L2_CAP_SLICED_VBI_CAPTURE | |
| 1433 | V4L2_CAP_VIDEO_CAPTURE | |
| 1434 | V4L2_CAP_AUDIO | |
| 1435 | V4L2_CAP_READWRITE | V4L2_CAP_STREAMING; |
| 1436 | |
Mauro Carvalho Chehab | ed08631 | 2008-01-24 06:59:20 -0300 | [diff] [blame] | 1437 | if (dev->tuner_type != TUNER_ABSENT) |
Mauro Carvalho Chehab | 195a4ef | 2007-11-11 13:17:17 -0300 | [diff] [blame] | 1438 | cap->capabilities |= V4L2_CAP_TUNER; |
| 1439 | |
| 1440 | return 0; |
| 1441 | } |
| 1442 | |
Hans Verkuil | 78b526a | 2008-05-28 12:16:41 -0300 | [diff] [blame] | 1443 | static int vidioc_enum_fmt_vid_cap(struct file *file, void *priv, |
Mauro Carvalho Chehab | bddcf63 | 2008-12-20 09:06:37 -0300 | [diff] [blame] | 1444 | struct v4l2_fmtdesc *f) |
Mauro Carvalho Chehab | 195a4ef | 2007-11-11 13:17:17 -0300 | [diff] [blame] | 1445 | { |
Mauro Carvalho Chehab | bddcf63 | 2008-12-20 09:06:37 -0300 | [diff] [blame] | 1446 | if (unlikely(f->index >= ARRAY_SIZE(format))) |
Mauro Carvalho Chehab | 195a4ef | 2007-11-11 13:17:17 -0300 | [diff] [blame] | 1447 | return -EINVAL; |
| 1448 | |
Mauro Carvalho Chehab | bddcf63 | 2008-12-20 09:06:37 -0300 | [diff] [blame] | 1449 | strlcpy(f->description, format[f->index].name, sizeof(f->description)); |
| 1450 | f->pixelformat = format[f->index].fourcc; |
Mauro Carvalho Chehab | 195a4ef | 2007-11-11 13:17:17 -0300 | [diff] [blame] | 1451 | |
| 1452 | return 0; |
| 1453 | } |
| 1454 | |
| 1455 | /* Sliced VBI ioctls */ |
Hans Verkuil | 78b526a | 2008-05-28 12:16:41 -0300 | [diff] [blame] | 1456 | static int vidioc_g_fmt_sliced_vbi_cap(struct file *file, void *priv, |
Mauro Carvalho Chehab | 195a4ef | 2007-11-11 13:17:17 -0300 | [diff] [blame] | 1457 | struct v4l2_format *f) |
| 1458 | { |
| 1459 | struct em28xx_fh *fh = priv; |
| 1460 | struct em28xx *dev = fh->dev; |
| 1461 | int rc; |
| 1462 | |
| 1463 | rc = check_dev(dev); |
| 1464 | if (rc < 0) |
| 1465 | return rc; |
| 1466 | |
| 1467 | mutex_lock(&dev->lock); |
| 1468 | |
| 1469 | f->fmt.sliced.service_set = 0; |
Douglas Schilling Landgraf | f2cf250 | 2009-03-31 17:10:58 -0300 | [diff] [blame] | 1470 | v4l2_device_call_all(&dev->v4l2_dev, 0, video, g_fmt, f); |
Mauro Carvalho Chehab | 195a4ef | 2007-11-11 13:17:17 -0300 | [diff] [blame] | 1471 | |
| 1472 | if (f->fmt.sliced.service_set == 0) |
| 1473 | rc = -EINVAL; |
| 1474 | |
| 1475 | mutex_unlock(&dev->lock); |
Douglas Schilling Landgraf | f2cf250 | 2009-03-31 17:10:58 -0300 | [diff] [blame] | 1476 | |
Mauro Carvalho Chehab | 195a4ef | 2007-11-11 13:17:17 -0300 | [diff] [blame] | 1477 | return rc; |
| 1478 | } |
| 1479 | |
Hans Verkuil | 78b526a | 2008-05-28 12:16:41 -0300 | [diff] [blame] | 1480 | static int vidioc_try_set_sliced_vbi_cap(struct file *file, void *priv, |
Mauro Carvalho Chehab | 195a4ef | 2007-11-11 13:17:17 -0300 | [diff] [blame] | 1481 | struct v4l2_format *f) |
| 1482 | { |
| 1483 | struct em28xx_fh *fh = priv; |
| 1484 | struct em28xx *dev = fh->dev; |
| 1485 | int rc; |
| 1486 | |
| 1487 | rc = check_dev(dev); |
| 1488 | if (rc < 0) |
| 1489 | return rc; |
| 1490 | |
| 1491 | mutex_lock(&dev->lock); |
Douglas Schilling Landgraf | f2cf250 | 2009-03-31 17:10:58 -0300 | [diff] [blame] | 1492 | v4l2_device_call_all(&dev->v4l2_dev, 0, video, g_fmt, f); |
Mauro Carvalho Chehab | 195a4ef | 2007-11-11 13:17:17 -0300 | [diff] [blame] | 1493 | mutex_unlock(&dev->lock); |
| 1494 | |
| 1495 | if (f->fmt.sliced.service_set == 0) |
| 1496 | return -EINVAL; |
| 1497 | |
| 1498 | return 0; |
| 1499 | } |
| 1500 | |
| 1501 | |
| 1502 | static int vidioc_reqbufs(struct file *file, void *priv, |
| 1503 | struct v4l2_requestbuffers *rb) |
| 1504 | { |
| 1505 | struct em28xx_fh *fh = priv; |
| 1506 | struct em28xx *dev = fh->dev; |
Mauro Carvalho Chehab | 195a4ef | 2007-11-11 13:17:17 -0300 | [diff] [blame] | 1507 | int rc; |
| 1508 | |
| 1509 | rc = check_dev(dev); |
| 1510 | if (rc < 0) |
| 1511 | return rc; |
| 1512 | |
Nicola Soranzo | a1a6ee7 | 2009-02-10 23:28:24 -0300 | [diff] [blame] | 1513 | return videobuf_reqbufs(&fh->vb_vidq, rb); |
Mauro Carvalho Chehab | 195a4ef | 2007-11-11 13:17:17 -0300 | [diff] [blame] | 1514 | } |
| 1515 | |
| 1516 | static int vidioc_querybuf(struct file *file, void *priv, |
| 1517 | struct v4l2_buffer *b) |
| 1518 | { |
| 1519 | struct em28xx_fh *fh = priv; |
| 1520 | struct em28xx *dev = fh->dev; |
| 1521 | int rc; |
| 1522 | |
| 1523 | rc = check_dev(dev); |
| 1524 | if (rc < 0) |
| 1525 | return rc; |
| 1526 | |
Nicola Soranzo | a1a6ee7 | 2009-02-10 23:28:24 -0300 | [diff] [blame] | 1527 | return videobuf_querybuf(&fh->vb_vidq, b); |
Mauro Carvalho Chehab | 195a4ef | 2007-11-11 13:17:17 -0300 | [diff] [blame] | 1528 | } |
| 1529 | |
| 1530 | static int vidioc_qbuf(struct file *file, void *priv, struct v4l2_buffer *b) |
| 1531 | { |
| 1532 | struct em28xx_fh *fh = priv; |
| 1533 | struct em28xx *dev = fh->dev; |
Mauro Carvalho Chehab | 195a4ef | 2007-11-11 13:17:17 -0300 | [diff] [blame] | 1534 | int rc; |
| 1535 | |
| 1536 | rc = check_dev(dev); |
| 1537 | if (rc < 0) |
| 1538 | return rc; |
| 1539 | |
Nicola Soranzo | a1a6ee7 | 2009-02-10 23:28:24 -0300 | [diff] [blame] | 1540 | return videobuf_qbuf(&fh->vb_vidq, b); |
Mauro Carvalho Chehab | 195a4ef | 2007-11-11 13:17:17 -0300 | [diff] [blame] | 1541 | } |
| 1542 | |
| 1543 | static int vidioc_dqbuf(struct file *file, void *priv, struct v4l2_buffer *b) |
| 1544 | { |
| 1545 | struct em28xx_fh *fh = priv; |
| 1546 | struct em28xx *dev = fh->dev; |
| 1547 | int rc; |
Mauro Carvalho Chehab | 195a4ef | 2007-11-11 13:17:17 -0300 | [diff] [blame] | 1548 | |
| 1549 | rc = check_dev(dev); |
| 1550 | if (rc < 0) |
| 1551 | return rc; |
| 1552 | |
Nicola Soranzo | a1a6ee7 | 2009-02-10 23:28:24 -0300 | [diff] [blame] | 1553 | return videobuf_dqbuf(&fh->vb_vidq, b, file->f_flags & O_NONBLOCK); |
Mauro Carvalho Chehab | 195a4ef | 2007-11-11 13:17:17 -0300 | [diff] [blame] | 1554 | } |
| 1555 | |
Mauro Carvalho Chehab | ad0ebb9 | 2008-04-13 14:37:52 -0300 | [diff] [blame] | 1556 | #ifdef CONFIG_VIDEO_V4L1_COMPAT |
Mauro Carvalho Chehab | f245e54 | 2008-04-13 14:41:23 -0300 | [diff] [blame] | 1557 | static int vidiocgmbuf(struct file *file, void *priv, struct video_mbuf *mbuf) |
Mauro Carvalho Chehab | ad0ebb9 | 2008-04-13 14:37:52 -0300 | [diff] [blame] | 1558 | { |
Mauro Carvalho Chehab | f245e54 | 2008-04-13 14:41:23 -0300 | [diff] [blame] | 1559 | struct em28xx_fh *fh = priv; |
Mauro Carvalho Chehab | ad0ebb9 | 2008-04-13 14:37:52 -0300 | [diff] [blame] | 1560 | |
Mauro Carvalho Chehab | f245e54 | 2008-04-13 14:41:23 -0300 | [diff] [blame] | 1561 | return videobuf_cgmbuf(&fh->vb_vidq, mbuf, 8); |
Mauro Carvalho Chehab | ad0ebb9 | 2008-04-13 14:37:52 -0300 | [diff] [blame] | 1562 | } |
| 1563 | #endif |
| 1564 | |
| 1565 | |
Mauro Carvalho Chehab | 0be4375 | 2008-01-05 17:22:01 -0300 | [diff] [blame] | 1566 | /* ----------------------------------------------------------- */ |
| 1567 | /* RADIO ESPECIFIC IOCTLS */ |
| 1568 | /* ----------------------------------------------------------- */ |
| 1569 | |
| 1570 | static int radio_querycap(struct file *file, void *priv, |
| 1571 | struct v4l2_capability *cap) |
| 1572 | { |
| 1573 | struct em28xx *dev = ((struct em28xx_fh *)priv)->dev; |
| 1574 | |
| 1575 | strlcpy(cap->driver, "em28xx", sizeof(cap->driver)); |
| 1576 | strlcpy(cap->card, em28xx_boards[dev->model].name, sizeof(cap->card)); |
Thierry MERLE | cb97716 | 2009-01-20 18:01:33 -0300 | [diff] [blame] | 1577 | usb_make_path(dev->udev, cap->bus_info, sizeof(cap->bus_info)); |
Mauro Carvalho Chehab | 0be4375 | 2008-01-05 17:22:01 -0300 | [diff] [blame] | 1578 | |
| 1579 | cap->version = EM28XX_VERSION_CODE; |
| 1580 | cap->capabilities = V4L2_CAP_TUNER; |
| 1581 | return 0; |
| 1582 | } |
| 1583 | |
| 1584 | static int radio_g_tuner(struct file *file, void *priv, |
| 1585 | struct v4l2_tuner *t) |
| 1586 | { |
| 1587 | struct em28xx *dev = ((struct em28xx_fh *)priv)->dev; |
| 1588 | |
| 1589 | if (unlikely(t->index > 0)) |
| 1590 | return -EINVAL; |
| 1591 | |
| 1592 | strcpy(t->name, "Radio"); |
| 1593 | t->type = V4L2_TUNER_RADIO; |
| 1594 | |
Mauro Carvalho Chehab | efc52a9 | 2008-12-16 22:04:56 -0300 | [diff] [blame] | 1595 | mutex_lock(&dev->lock); |
Douglas Schilling Landgraf | f2cf250 | 2009-03-31 17:10:58 -0300 | [diff] [blame] | 1596 | v4l2_device_call_all(&dev->v4l2_dev, 0, tuner, g_tuner, t); |
Mauro Carvalho Chehab | efc52a9 | 2008-12-16 22:04:56 -0300 | [diff] [blame] | 1597 | mutex_unlock(&dev->lock); |
| 1598 | |
Mauro Carvalho Chehab | 0be4375 | 2008-01-05 17:22:01 -0300 | [diff] [blame] | 1599 | return 0; |
| 1600 | } |
| 1601 | |
| 1602 | static int radio_enum_input(struct file *file, void *priv, |
| 1603 | struct v4l2_input *i) |
| 1604 | { |
| 1605 | if (i->index != 0) |
| 1606 | return -EINVAL; |
| 1607 | strcpy(i->name, "Radio"); |
| 1608 | i->type = V4L2_INPUT_TYPE_TUNER; |
| 1609 | |
| 1610 | return 0; |
| 1611 | } |
| 1612 | |
| 1613 | static int radio_g_audio(struct file *file, void *priv, struct v4l2_audio *a) |
| 1614 | { |
| 1615 | if (unlikely(a->index)) |
| 1616 | return -EINVAL; |
| 1617 | |
| 1618 | strcpy(a->name, "Radio"); |
| 1619 | return 0; |
| 1620 | } |
| 1621 | |
| 1622 | static int radio_s_tuner(struct file *file, void *priv, |
| 1623 | struct v4l2_tuner *t) |
| 1624 | { |
| 1625 | struct em28xx *dev = ((struct em28xx_fh *)priv)->dev; |
| 1626 | |
| 1627 | if (0 != t->index) |
| 1628 | return -EINVAL; |
| 1629 | |
Mauro Carvalho Chehab | efc52a9 | 2008-12-16 22:04:56 -0300 | [diff] [blame] | 1630 | mutex_lock(&dev->lock); |
Douglas Schilling Landgraf | f2cf250 | 2009-03-31 17:10:58 -0300 | [diff] [blame] | 1631 | v4l2_device_call_all(&dev->v4l2_dev, 0, tuner, s_tuner, t); |
Mauro Carvalho Chehab | efc52a9 | 2008-12-16 22:04:56 -0300 | [diff] [blame] | 1632 | mutex_unlock(&dev->lock); |
Mauro Carvalho Chehab | 0be4375 | 2008-01-05 17:22:01 -0300 | [diff] [blame] | 1633 | |
| 1634 | return 0; |
| 1635 | } |
| 1636 | |
| 1637 | static int radio_s_audio(struct file *file, void *fh, |
| 1638 | struct v4l2_audio *a) |
| 1639 | { |
| 1640 | return 0; |
| 1641 | } |
| 1642 | |
| 1643 | static int radio_s_input(struct file *file, void *fh, unsigned int i) |
| 1644 | { |
| 1645 | return 0; |
| 1646 | } |
| 1647 | |
| 1648 | static int radio_queryctrl(struct file *file, void *priv, |
| 1649 | struct v4l2_queryctrl *qc) |
| 1650 | { |
| 1651 | int i; |
| 1652 | |
| 1653 | if (qc->id < V4L2_CID_BASE || |
| 1654 | qc->id >= V4L2_CID_LASTP1) |
| 1655 | return -EINVAL; |
| 1656 | |
| 1657 | for (i = 0; i < ARRAY_SIZE(em28xx_qctrl); i++) { |
| 1658 | if (qc->id && qc->id == em28xx_qctrl[i].id) { |
| 1659 | memcpy(qc, &(em28xx_qctrl[i]), sizeof(*qc)); |
| 1660 | return 0; |
| 1661 | } |
| 1662 | } |
| 1663 | |
| 1664 | return -EINVAL; |
| 1665 | } |
| 1666 | |
Mauro Carvalho Chehab | 195a4ef | 2007-11-11 13:17:17 -0300 | [diff] [blame] | 1667 | /* |
Mauro Carvalho Chehab | 3acf280 | 2005-11-08 21:38:27 -0800 | [diff] [blame] | 1668 | * em28xx_v4l2_open() |
akpm@osdl.org | a6c2ba2 | 2005-11-08 21:37:07 -0800 | [diff] [blame] | 1669 | * inits the device and starts isoc transfer |
| 1670 | */ |
Hans Verkuil | bec4366 | 2008-12-30 06:58:20 -0300 | [diff] [blame] | 1671 | static int em28xx_v4l2_open(struct file *filp) |
akpm@osdl.org | a6c2ba2 | 2005-11-08 21:37:07 -0800 | [diff] [blame] | 1672 | { |
Hans Verkuil | bec4366 | 2008-12-30 06:58:20 -0300 | [diff] [blame] | 1673 | int minor = video_devdata(filp)->minor; |
Mauro Carvalho Chehab | 1a23f81 | 2008-12-28 22:18:14 -0300 | [diff] [blame] | 1674 | int errCode = 0, radio; |
| 1675 | struct em28xx *dev; |
| 1676 | enum v4l2_buf_type fh_type; |
Mauro Carvalho Chehab | a3a048c | 2007-11-10 22:21:01 -0300 | [diff] [blame] | 1677 | struct em28xx_fh *fh; |
Mauro Carvalho Chehab | c2a6b54 | 2009-08-08 03:14:55 -0300 | [diff] [blame] | 1678 | enum v4l2_field field; |
Markus Rechberger | 9c75541 | 2005-11-08 21:37:52 -0800 | [diff] [blame] | 1679 | |
Hans Verkuil | bec4366 | 2008-12-30 06:58:20 -0300 | [diff] [blame] | 1680 | dev = em28xx_get_device(minor, &fh_type, &radio); |
Mauro Carvalho Chehab | efc52a9 | 2008-12-16 22:04:56 -0300 | [diff] [blame] | 1681 | |
Mauro Carvalho Chehab | 818a557 | 2008-11-20 10:30:26 -0300 | [diff] [blame] | 1682 | if (NULL == dev) |
Mauro Carvalho Chehab | e5589be | 2006-01-23 17:11:08 -0200 | [diff] [blame] | 1683 | return -ENODEV; |
Mauro Carvalho Chehab | 818a557 | 2008-11-20 10:30:26 -0300 | [diff] [blame] | 1684 | |
| 1685 | mutex_lock(&dev->lock); |
Markus Rechberger | 9c75541 | 2005-11-08 21:37:52 -0800 | [diff] [blame] | 1686 | |
Mauro Carvalho Chehab | e5589be | 2006-01-23 17:11:08 -0200 | [diff] [blame] | 1687 | em28xx_videodbg("open minor=%d type=%s users=%d\n", |
Aidan Thornton | d7aa802 | 2008-04-13 14:38:47 -0300 | [diff] [blame] | 1688 | minor, v4l2_type_names[fh_type], dev->users); |
akpm@osdl.org | a6c2ba2 | 2005-11-08 21:37:07 -0800 | [diff] [blame] | 1689 | |
akpm@osdl.org | a6c2ba2 | 2005-11-08 21:37:07 -0800 | [diff] [blame] | 1690 | |
Mauro Carvalho Chehab | c67ec53 | 2008-04-17 21:48:00 -0300 | [diff] [blame] | 1691 | fh = kzalloc(sizeof(struct em28xx_fh), GFP_KERNEL); |
Mauro Carvalho Chehab | a3a048c | 2007-11-10 22:21:01 -0300 | [diff] [blame] | 1692 | if (!fh) { |
| 1693 | em28xx_errdev("em28xx-video.c: Out of memory?!\n"); |
Mauro Carvalho Chehab | 818a557 | 2008-11-20 10:30:26 -0300 | [diff] [blame] | 1694 | mutex_unlock(&dev->lock); |
Mauro Carvalho Chehab | a3a048c | 2007-11-10 22:21:01 -0300 | [diff] [blame] | 1695 | return -ENOMEM; |
akpm@osdl.org | a6c2ba2 | 2005-11-08 21:37:07 -0800 | [diff] [blame] | 1696 | } |
Mauro Carvalho Chehab | a3a048c | 2007-11-10 22:21:01 -0300 | [diff] [blame] | 1697 | fh->dev = dev; |
Mauro Carvalho Chehab | 0be4375 | 2008-01-05 17:22:01 -0300 | [diff] [blame] | 1698 | fh->radio = radio; |
Aidan Thornton | d7aa802 | 2008-04-13 14:38:47 -0300 | [diff] [blame] | 1699 | fh->type = fh_type; |
Mauro Carvalho Chehab | a3a048c | 2007-11-10 22:21:01 -0300 | [diff] [blame] | 1700 | filp->private_data = fh; |
akpm@osdl.org | a6c2ba2 | 2005-11-08 21:37:07 -0800 | [diff] [blame] | 1701 | |
Aidan Thornton | d7aa802 | 2008-04-13 14:38:47 -0300 | [diff] [blame] | 1702 | if (fh->type == V4L2_BUF_TYPE_VIDEO_CAPTURE && dev->users == 0) { |
Mauro Carvalho Chehab | c67ec53 | 2008-04-17 21:48:00 -0300 | [diff] [blame] | 1703 | em28xx_set_mode(dev, EM28XX_ANALOG_MODE); |
Mauro Carvalho Chehab | 3687e1e | 2008-02-08 15:44:25 -0300 | [diff] [blame] | 1704 | em28xx_set_alternate(dev); |
Mauro Carvalho Chehab | e5589be | 2006-01-23 17:11:08 -0200 | [diff] [blame] | 1705 | em28xx_resolution_set(dev); |
akpm@osdl.org | a6c2ba2 | 2005-11-08 21:37:07 -0800 | [diff] [blame] | 1706 | |
Mauro Carvalho Chehab | c67ec53 | 2008-04-17 21:48:00 -0300 | [diff] [blame] | 1707 | /* Needed, since GPIO might have disabled power of |
| 1708 | some i2c device |
| 1709 | */ |
Mauro Carvalho Chehab | 1a23f81 | 2008-12-28 22:18:14 -0300 | [diff] [blame] | 1710 | em28xx_wake_i2c(dev); |
Mauro Carvalho Chehab | c67ec53 | 2008-04-17 21:48:00 -0300 | [diff] [blame] | 1711 | |
Mauro Carvalho Chehab | e5589be | 2006-01-23 17:11:08 -0200 | [diff] [blame] | 1712 | } |
Mauro Carvalho Chehab | 0be4375 | 2008-01-05 17:22:01 -0300 | [diff] [blame] | 1713 | if (fh->radio) { |
| 1714 | em28xx_videodbg("video_open: setting radio device\n"); |
Douglas Schilling Landgraf | f2cf250 | 2009-03-31 17:10:58 -0300 | [diff] [blame] | 1715 | v4l2_device_call_all(&dev->v4l2_dev, 0, tuner, s_radio); |
Mauro Carvalho Chehab | 0be4375 | 2008-01-05 17:22:01 -0300 | [diff] [blame] | 1716 | } |
akpm@osdl.org | a6c2ba2 | 2005-11-08 21:37:07 -0800 | [diff] [blame] | 1717 | |
| 1718 | dev->users++; |
akpm@osdl.org | a6c2ba2 | 2005-11-08 21:37:07 -0800 | [diff] [blame] | 1719 | |
Mauro Carvalho Chehab | c2a6b54 | 2009-08-08 03:14:55 -0300 | [diff] [blame] | 1720 | if (dev->progressive) |
| 1721 | field = V4L2_FIELD_NONE; |
| 1722 | else |
| 1723 | field = V4L2_FIELD_INTERLACED; |
| 1724 | |
Mauro Carvalho Chehab | ad0ebb9 | 2008-04-13 14:37:52 -0300 | [diff] [blame] | 1725 | videobuf_queue_vmalloc_init(&fh->vb_vidq, &em28xx_video_qops, |
Mauro Carvalho Chehab | c2a6b54 | 2009-08-08 03:14:55 -0300 | [diff] [blame] | 1726 | NULL, &dev->slock, fh->type, field, |
Mauro Carvalho Chehab | ad0ebb9 | 2008-04-13 14:37:52 -0300 | [diff] [blame] | 1727 | sizeof(struct em28xx_buffer), fh); |
| 1728 | |
Ingo Molnar | 3593cab | 2006-02-07 06:49:14 -0200 | [diff] [blame] | 1729 | mutex_unlock(&dev->lock); |
Mauro Carvalho Chehab | c67ec53 | 2008-04-17 21:48:00 -0300 | [diff] [blame] | 1730 | |
akpm@osdl.org | a6c2ba2 | 2005-11-08 21:37:07 -0800 | [diff] [blame] | 1731 | return errCode; |
| 1732 | } |
| 1733 | |
| 1734 | /* |
Mauro Carvalho Chehab | 3acf280 | 2005-11-08 21:38:27 -0800 | [diff] [blame] | 1735 | * em28xx_realease_resources() |
akpm@osdl.org | a6c2ba2 | 2005-11-08 21:37:07 -0800 | [diff] [blame] | 1736 | * unregisters the v4l2,i2c and usb devices |
| 1737 | * called when the device gets disconected or at module unload |
| 1738 | */ |
Mauro Carvalho Chehab | 1a23f81 | 2008-12-28 22:18:14 -0300 | [diff] [blame] | 1739 | void em28xx_release_analog_resources(struct em28xx *dev) |
akpm@osdl.org | a6c2ba2 | 2005-11-08 21:37:07 -0800 | [diff] [blame] | 1740 | { |
akpm@osdl.org | a6c2ba2 | 2005-11-08 21:37:07 -0800 | [diff] [blame] | 1741 | |
Mauro Carvalho Chehab | e5589be | 2006-01-23 17:11:08 -0200 | [diff] [blame] | 1742 | /*FIXME: I2C IR should be disconnected */ |
| 1743 | |
Mauro Carvalho Chehab | 0be4375 | 2008-01-05 17:22:01 -0300 | [diff] [blame] | 1744 | if (dev->radio_dev) { |
| 1745 | if (-1 != dev->radio_dev->minor) |
| 1746 | video_unregister_device(dev->radio_dev); |
| 1747 | else |
| 1748 | video_device_release(dev->radio_dev); |
| 1749 | dev->radio_dev = NULL; |
| 1750 | } |
| 1751 | if (dev->vbi_dev) { |
Devin Heitmueller | 4924044 | 2008-11-12 02:05:15 -0300 | [diff] [blame] | 1752 | em28xx_info("V4L2 device /dev/vbi%d deregistered\n", |
| 1753 | dev->vbi_dev->num); |
Mauro Carvalho Chehab | 0be4375 | 2008-01-05 17:22:01 -0300 | [diff] [blame] | 1754 | if (-1 != dev->vbi_dev->minor) |
| 1755 | video_unregister_device(dev->vbi_dev); |
| 1756 | else |
| 1757 | video_device_release(dev->vbi_dev); |
| 1758 | dev->vbi_dev = NULL; |
| 1759 | } |
| 1760 | if (dev->vdev) { |
Devin Heitmueller | 4924044 | 2008-11-12 02:05:15 -0300 | [diff] [blame] | 1761 | em28xx_info("V4L2 device /dev/video%d deregistered\n", |
| 1762 | dev->vdev->num); |
Mauro Carvalho Chehab | 0be4375 | 2008-01-05 17:22:01 -0300 | [diff] [blame] | 1763 | if (-1 != dev->vdev->minor) |
| 1764 | video_unregister_device(dev->vdev); |
| 1765 | else |
| 1766 | video_device_release(dev->vdev); |
| 1767 | dev->vdev = NULL; |
| 1768 | } |
akpm@osdl.org | a6c2ba2 | 2005-11-08 21:37:07 -0800 | [diff] [blame] | 1769 | } |
| 1770 | |
| 1771 | /* |
Mauro Carvalho Chehab | 3acf280 | 2005-11-08 21:38:27 -0800 | [diff] [blame] | 1772 | * em28xx_v4l2_close() |
Douglas Schilling Landgraf | 6ea54d9 | 2008-04-17 21:41:10 -0300 | [diff] [blame] | 1773 | * stops streaming and deallocates all resources allocated by the v4l2 |
| 1774 | * calls and ioctls |
akpm@osdl.org | a6c2ba2 | 2005-11-08 21:37:07 -0800 | [diff] [blame] | 1775 | */ |
Hans Verkuil | bec4366 | 2008-12-30 06:58:20 -0300 | [diff] [blame] | 1776 | static int em28xx_v4l2_close(struct file *filp) |
akpm@osdl.org | a6c2ba2 | 2005-11-08 21:37:07 -0800 | [diff] [blame] | 1777 | { |
Mauro Carvalho Chehab | a3a048c | 2007-11-10 22:21:01 -0300 | [diff] [blame] | 1778 | struct em28xx_fh *fh = filp->private_data; |
| 1779 | struct em28xx *dev = fh->dev; |
| 1780 | int errCode; |
akpm@osdl.org | a6c2ba2 | 2005-11-08 21:37:07 -0800 | [diff] [blame] | 1781 | |
Mauro Carvalho Chehab | eac9435 | 2005-11-08 21:38:43 -0800 | [diff] [blame] | 1782 | em28xx_videodbg("users=%d\n", dev->users); |
akpm@osdl.org | a6c2ba2 | 2005-11-08 21:37:07 -0800 | [diff] [blame] | 1783 | |
Mauro Carvalho Chehab | a225452 | 2007-11-11 01:08:26 -0300 | [diff] [blame] | 1784 | |
Mauro Carvalho Chehab | 7831364 | 2008-12-16 20:00:49 -0300 | [diff] [blame] | 1785 | mutex_lock(&dev->lock); |
Mauro Carvalho Chehab | a225452 | 2007-11-11 01:08:26 -0300 | [diff] [blame] | 1786 | if (res_check(fh)) |
| 1787 | res_free(fh); |
| 1788 | |
Mauro Carvalho Chehab | a3a048c | 2007-11-10 22:21:01 -0300 | [diff] [blame] | 1789 | if (dev->users == 1) { |
Mauro Carvalho Chehab | ad0ebb9 | 2008-04-13 14:37:52 -0300 | [diff] [blame] | 1790 | videobuf_stop(&fh->vb_vidq); |
| 1791 | videobuf_mmap_free(&fh->vb_vidq); |
akpm@osdl.org | a6c2ba2 | 2005-11-08 21:37:07 -0800 | [diff] [blame] | 1792 | |
Mauro Carvalho Chehab | a3a048c | 2007-11-10 22:21:01 -0300 | [diff] [blame] | 1793 | /* the device is already disconnect, |
| 1794 | free the remaining resources */ |
| 1795 | if (dev->state & DEV_DISCONNECTED) { |
| 1796 | em28xx_release_resources(dev); |
| 1797 | mutex_unlock(&dev->lock); |
| 1798 | kfree(dev); |
| 1799 | return 0; |
| 1800 | } |
| 1801 | |
Mauro Carvalho Chehab | eb6c963 | 2008-12-05 10:39:12 -0300 | [diff] [blame] | 1802 | /* Save some power by putting tuner to sleep */ |
Hans Verkuil | 7c9fc9d | 2009-04-01 03:49:59 -0300 | [diff] [blame] | 1803 | v4l2_device_call_all(&dev->v4l2_dev, 0, tuner, s_standby); |
Mauro Carvalho Chehab | eb6c963 | 2008-12-05 10:39:12 -0300 | [diff] [blame] | 1804 | |
Aidan Thornton | d7aa802 | 2008-04-13 14:38:47 -0300 | [diff] [blame] | 1805 | /* do this before setting alternate! */ |
| 1806 | em28xx_uninit_isoc(dev); |
Mauro Carvalho Chehab | 2fe3e2e | 2008-11-27 09:10:40 -0300 | [diff] [blame] | 1807 | em28xx_set_mode(dev, EM28XX_SUSPEND); |
Aidan Thornton | d7aa802 | 2008-04-13 14:38:47 -0300 | [diff] [blame] | 1808 | |
Mauro Carvalho Chehab | a3a048c | 2007-11-10 22:21:01 -0300 | [diff] [blame] | 1809 | /* set alternate 0 */ |
| 1810 | dev->alt = 0; |
| 1811 | em28xx_videodbg("setting alternate 0\n"); |
| 1812 | errCode = usb_set_interface(dev->udev, 0, 0); |
| 1813 | if (errCode < 0) { |
| 1814 | em28xx_errdev("cannot change alternate number to " |
| 1815 | "0 (error=%i)\n", errCode); |
| 1816 | } |
akpm@osdl.org | a6c2ba2 | 2005-11-08 21:37:07 -0800 | [diff] [blame] | 1817 | } |
Mauro Carvalho Chehab | a3a048c | 2007-11-10 22:21:01 -0300 | [diff] [blame] | 1818 | kfree(fh); |
akpm@osdl.org | a6c2ba2 | 2005-11-08 21:37:07 -0800 | [diff] [blame] | 1819 | dev->users--; |
| 1820 | wake_up_interruptible_nr(&dev->open, 1); |
Ingo Molnar | 3593cab | 2006-02-07 06:49:14 -0200 | [diff] [blame] | 1821 | mutex_unlock(&dev->lock); |
akpm@osdl.org | a6c2ba2 | 2005-11-08 21:37:07 -0800 | [diff] [blame] | 1822 | return 0; |
| 1823 | } |
| 1824 | |
| 1825 | /* |
Mauro Carvalho Chehab | 3acf280 | 2005-11-08 21:38:27 -0800 | [diff] [blame] | 1826 | * em28xx_v4l2_read() |
akpm@osdl.org | a6c2ba2 | 2005-11-08 21:37:07 -0800 | [diff] [blame] | 1827 | * will allocate buffers when called for the first time |
| 1828 | */ |
| 1829 | static ssize_t |
Douglas Schilling Landgraf | 6ea54d9 | 2008-04-17 21:41:10 -0300 | [diff] [blame] | 1830 | em28xx_v4l2_read(struct file *filp, char __user *buf, size_t count, |
Mauro Carvalho Chehab | f245e54 | 2008-04-13 14:41:23 -0300 | [diff] [blame] | 1831 | loff_t *pos) |
akpm@osdl.org | a6c2ba2 | 2005-11-08 21:37:07 -0800 | [diff] [blame] | 1832 | { |
Mauro Carvalho Chehab | a3a048c | 2007-11-10 22:21:01 -0300 | [diff] [blame] | 1833 | struct em28xx_fh *fh = filp->private_data; |
| 1834 | struct em28xx *dev = fh->dev; |
Mauro Carvalho Chehab | ad0ebb9 | 2008-04-13 14:37:52 -0300 | [diff] [blame] | 1835 | int rc; |
| 1836 | |
| 1837 | rc = check_dev(dev); |
| 1838 | if (rc < 0) |
| 1839 | return rc; |
akpm@osdl.org | a6c2ba2 | 2005-11-08 21:37:07 -0800 | [diff] [blame] | 1840 | |
Mauro Carvalho Chehab | 9e31ced | 2007-11-11 01:13:49 -0300 | [diff] [blame] | 1841 | /* FIXME: read() is not prepared to allow changing the video |
| 1842 | resolution while streaming. Seems a bug at em28xx_set_fmt |
| 1843 | */ |
Mauro Carvalho Chehab | a225452 | 2007-11-11 01:08:26 -0300 | [diff] [blame] | 1844 | |
Mauro Carvalho Chehab | ad0ebb9 | 2008-04-13 14:37:52 -0300 | [diff] [blame] | 1845 | if (fh->type == V4L2_BUF_TYPE_VIDEO_CAPTURE) { |
Mauro Carvalho Chehab | 29b5941 | 2008-12-16 20:19:24 -0300 | [diff] [blame] | 1846 | mutex_lock(&dev->lock); |
| 1847 | rc = res_get(fh); |
| 1848 | mutex_unlock(&dev->lock); |
| 1849 | |
| 1850 | if (unlikely(rc < 0)) |
| 1851 | return rc; |
Mauro Carvalho Chehab | a225452 | 2007-11-11 01:08:26 -0300 | [diff] [blame] | 1852 | |
Mauro Carvalho Chehab | ad0ebb9 | 2008-04-13 14:37:52 -0300 | [diff] [blame] | 1853 | return videobuf_read_stream(&fh->vb_vidq, buf, count, pos, 0, |
| 1854 | filp->f_flags & O_NONBLOCK); |
Mauro Carvalho Chehab | e5589be | 2006-01-23 17:11:08 -0200 | [diff] [blame] | 1855 | } |
Mauro Carvalho Chehab | ad0ebb9 | 2008-04-13 14:37:52 -0300 | [diff] [blame] | 1856 | return 0; |
akpm@osdl.org | a6c2ba2 | 2005-11-08 21:37:07 -0800 | [diff] [blame] | 1857 | } |
| 1858 | |
| 1859 | /* |
Mauro Carvalho Chehab | 3acf280 | 2005-11-08 21:38:27 -0800 | [diff] [blame] | 1860 | * em28xx_v4l2_poll() |
akpm@osdl.org | a6c2ba2 | 2005-11-08 21:37:07 -0800 | [diff] [blame] | 1861 | * will allocate buffers when called for the first time |
| 1862 | */ |
Nicola Soranzo | a1a6ee7 | 2009-02-10 23:28:24 -0300 | [diff] [blame] | 1863 | static unsigned int em28xx_v4l2_poll(struct file *filp, poll_table *wait) |
akpm@osdl.org | a6c2ba2 | 2005-11-08 21:37:07 -0800 | [diff] [blame] | 1864 | { |
Mauro Carvalho Chehab | a3a048c | 2007-11-10 22:21:01 -0300 | [diff] [blame] | 1865 | struct em28xx_fh *fh = filp->private_data; |
| 1866 | struct em28xx *dev = fh->dev; |
Mauro Carvalho Chehab | ad0ebb9 | 2008-04-13 14:37:52 -0300 | [diff] [blame] | 1867 | int rc; |
| 1868 | |
| 1869 | rc = check_dev(dev); |
| 1870 | if (rc < 0) |
| 1871 | return rc; |
akpm@osdl.org | a6c2ba2 | 2005-11-08 21:37:07 -0800 | [diff] [blame] | 1872 | |
Mauro Carvalho Chehab | 29b5941 | 2008-12-16 20:19:24 -0300 | [diff] [blame] | 1873 | mutex_lock(&dev->lock); |
| 1874 | rc = res_get(fh); |
| 1875 | mutex_unlock(&dev->lock); |
| 1876 | |
| 1877 | if (unlikely(rc < 0)) |
Mauro Carvalho Chehab | a225452 | 2007-11-11 01:08:26 -0300 | [diff] [blame] | 1878 | return POLLERR; |
| 1879 | |
Mauro Carvalho Chehab | ad0ebb9 | 2008-04-13 14:37:52 -0300 | [diff] [blame] | 1880 | if (V4L2_BUF_TYPE_VIDEO_CAPTURE != fh->type) |
| 1881 | return POLLERR; |
akpm@osdl.org | a6c2ba2 | 2005-11-08 21:37:07 -0800 | [diff] [blame] | 1882 | |
Mauro Carvalho Chehab | ad0ebb9 | 2008-04-13 14:37:52 -0300 | [diff] [blame] | 1883 | return videobuf_poll_stream(filp, &fh->vb_vidq, wait); |
akpm@osdl.org | a6c2ba2 | 2005-11-08 21:37:07 -0800 | [diff] [blame] | 1884 | } |
| 1885 | |
| 1886 | /* |
Mauro Carvalho Chehab | 3acf280 | 2005-11-08 21:38:27 -0800 | [diff] [blame] | 1887 | * em28xx_v4l2_mmap() |
akpm@osdl.org | a6c2ba2 | 2005-11-08 21:37:07 -0800 | [diff] [blame] | 1888 | */ |
Mauro Carvalho Chehab | 3acf280 | 2005-11-08 21:38:27 -0800 | [diff] [blame] | 1889 | static int em28xx_v4l2_mmap(struct file *filp, struct vm_area_struct *vma) |
akpm@osdl.org | a6c2ba2 | 2005-11-08 21:37:07 -0800 | [diff] [blame] | 1890 | { |
Mauro Carvalho Chehab | a3a048c | 2007-11-10 22:21:01 -0300 | [diff] [blame] | 1891 | struct em28xx_fh *fh = filp->private_data; |
| 1892 | struct em28xx *dev = fh->dev; |
Mauro Carvalho Chehab | ad0ebb9 | 2008-04-13 14:37:52 -0300 | [diff] [blame] | 1893 | int rc; |
Markus Rechberger | 9c75541 | 2005-11-08 21:37:52 -0800 | [diff] [blame] | 1894 | |
Mauro Carvalho Chehab | ad0ebb9 | 2008-04-13 14:37:52 -0300 | [diff] [blame] | 1895 | rc = check_dev(dev); |
| 1896 | if (rc < 0) |
| 1897 | return rc; |
Mauro Carvalho Chehab | a3a048c | 2007-11-10 22:21:01 -0300 | [diff] [blame] | 1898 | |
Mauro Carvalho Chehab | 29b5941 | 2008-12-16 20:19:24 -0300 | [diff] [blame] | 1899 | mutex_lock(&dev->lock); |
| 1900 | rc = res_get(fh); |
| 1901 | mutex_unlock(&dev->lock); |
| 1902 | |
| 1903 | if (unlikely(rc < 0)) |
| 1904 | return rc; |
| 1905 | |
Mauro Carvalho Chehab | ad0ebb9 | 2008-04-13 14:37:52 -0300 | [diff] [blame] | 1906 | rc = videobuf_mmap_mapper(&fh->vb_vidq, vma); |
akpm@osdl.org | a6c2ba2 | 2005-11-08 21:37:07 -0800 | [diff] [blame] | 1907 | |
Mauro Carvalho Chehab | ad0ebb9 | 2008-04-13 14:37:52 -0300 | [diff] [blame] | 1908 | em28xx_videodbg("vma start=0x%08lx, size=%ld, ret=%d\n", |
| 1909 | (unsigned long)vma->vm_start, |
| 1910 | (unsigned long)vma->vm_end-(unsigned long)vma->vm_start, |
| 1911 | rc); |
akpm@osdl.org | a6c2ba2 | 2005-11-08 21:37:07 -0800 | [diff] [blame] | 1912 | |
Mauro Carvalho Chehab | ad0ebb9 | 2008-04-13 14:37:52 -0300 | [diff] [blame] | 1913 | return rc; |
akpm@osdl.org | a6c2ba2 | 2005-11-08 21:37:07 -0800 | [diff] [blame] | 1914 | } |
| 1915 | |
Hans Verkuil | bec4366 | 2008-12-30 06:58:20 -0300 | [diff] [blame] | 1916 | static const struct v4l2_file_operations em28xx_v4l_fops = { |
Mauro Carvalho Chehab | 195a4ef | 2007-11-11 13:17:17 -0300 | [diff] [blame] | 1917 | .owner = THIS_MODULE, |
| 1918 | .open = em28xx_v4l2_open, |
| 1919 | .release = em28xx_v4l2_close, |
| 1920 | .read = em28xx_v4l2_read, |
| 1921 | .poll = em28xx_v4l2_poll, |
| 1922 | .mmap = em28xx_v4l2_mmap, |
| 1923 | .ioctl = video_ioctl2, |
akpm@osdl.org | a6c2ba2 | 2005-11-08 21:37:07 -0800 | [diff] [blame] | 1924 | }; |
| 1925 | |
Hans Verkuil | a399810 | 2008-07-21 02:57:38 -0300 | [diff] [blame] | 1926 | static const struct v4l2_ioctl_ops video_ioctl_ops = { |
Mauro Carvalho Chehab | 195a4ef | 2007-11-11 13:17:17 -0300 | [diff] [blame] | 1927 | .vidioc_querycap = vidioc_querycap, |
Hans Verkuil | 78b526a | 2008-05-28 12:16:41 -0300 | [diff] [blame] | 1928 | .vidioc_enum_fmt_vid_cap = vidioc_enum_fmt_vid_cap, |
| 1929 | .vidioc_g_fmt_vid_cap = vidioc_g_fmt_vid_cap, |
| 1930 | .vidioc_try_fmt_vid_cap = vidioc_try_fmt_vid_cap, |
| 1931 | .vidioc_s_fmt_vid_cap = vidioc_s_fmt_vid_cap, |
Mauro Carvalho Chehab | 195a4ef | 2007-11-11 13:17:17 -0300 | [diff] [blame] | 1932 | .vidioc_g_audio = vidioc_g_audio, |
| 1933 | .vidioc_s_audio = vidioc_s_audio, |
| 1934 | .vidioc_cropcap = vidioc_cropcap, |
| 1935 | |
Hans Verkuil | 78b526a | 2008-05-28 12:16:41 -0300 | [diff] [blame] | 1936 | .vidioc_g_fmt_sliced_vbi_cap = vidioc_g_fmt_sliced_vbi_cap, |
| 1937 | .vidioc_try_fmt_sliced_vbi_cap = vidioc_try_set_sliced_vbi_cap, |
| 1938 | .vidioc_s_fmt_sliced_vbi_cap = vidioc_try_set_sliced_vbi_cap, |
Mauro Carvalho Chehab | 195a4ef | 2007-11-11 13:17:17 -0300 | [diff] [blame] | 1939 | |
| 1940 | .vidioc_reqbufs = vidioc_reqbufs, |
| 1941 | .vidioc_querybuf = vidioc_querybuf, |
| 1942 | .vidioc_qbuf = vidioc_qbuf, |
| 1943 | .vidioc_dqbuf = vidioc_dqbuf, |
| 1944 | .vidioc_s_std = vidioc_s_std, |
Mauro Carvalho Chehab | d96ecda | 2009-08-06 21:53:59 -0300 | [diff] [blame] | 1945 | .vidioc_g_parm = vidioc_g_parm, |
| 1946 | .vidioc_s_parm = vidioc_s_parm, |
Mauro Carvalho Chehab | 195a4ef | 2007-11-11 13:17:17 -0300 | [diff] [blame] | 1947 | .vidioc_enum_input = vidioc_enum_input, |
| 1948 | .vidioc_g_input = vidioc_g_input, |
| 1949 | .vidioc_s_input = vidioc_s_input, |
| 1950 | .vidioc_queryctrl = vidioc_queryctrl, |
| 1951 | .vidioc_g_ctrl = vidioc_g_ctrl, |
| 1952 | .vidioc_s_ctrl = vidioc_s_ctrl, |
| 1953 | .vidioc_streamon = vidioc_streamon, |
| 1954 | .vidioc_streamoff = vidioc_streamoff, |
| 1955 | .vidioc_g_tuner = vidioc_g_tuner, |
| 1956 | .vidioc_s_tuner = vidioc_s_tuner, |
| 1957 | .vidioc_g_frequency = vidioc_g_frequency, |
| 1958 | .vidioc_s_frequency = vidioc_s_frequency, |
Mauro Carvalho Chehab | 1e7ad56 | 2008-02-06 09:00:41 -0300 | [diff] [blame] | 1959 | #ifdef CONFIG_VIDEO_ADV_DEBUG |
| 1960 | .vidioc_g_register = vidioc_g_register, |
| 1961 | .vidioc_s_register = vidioc_s_register, |
Mauro Carvalho Chehab | 14983d8 | 2008-12-22 20:58:41 -0300 | [diff] [blame] | 1962 | .vidioc_g_chip_ident = vidioc_g_chip_ident, |
Mauro Carvalho Chehab | 1e7ad56 | 2008-02-06 09:00:41 -0300 | [diff] [blame] | 1963 | #endif |
Mauro Carvalho Chehab | ad0ebb9 | 2008-04-13 14:37:52 -0300 | [diff] [blame] | 1964 | #ifdef CONFIG_VIDEO_V4L1_COMPAT |
| 1965 | .vidiocgmbuf = vidiocgmbuf, |
| 1966 | #endif |
Hans Verkuil | a399810 | 2008-07-21 02:57:38 -0300 | [diff] [blame] | 1967 | }; |
| 1968 | |
| 1969 | static const struct video_device em28xx_video_template = { |
| 1970 | .fops = &em28xx_v4l_fops, |
| 1971 | .release = video_device_release, |
| 1972 | .ioctl_ops = &video_ioctl_ops, |
| 1973 | |
| 1974 | .minor = -1, |
Mauro Carvalho Chehab | 195a4ef | 2007-11-11 13:17:17 -0300 | [diff] [blame] | 1975 | |
| 1976 | .tvnorms = V4L2_STD_ALL, |
Mauro Carvalho Chehab | 7d497f8 | 2007-11-11 14:15:34 -0300 | [diff] [blame] | 1977 | .current_norm = V4L2_STD_PAL, |
Mauro Carvalho Chehab | 195a4ef | 2007-11-11 13:17:17 -0300 | [diff] [blame] | 1978 | }; |
| 1979 | |
Hans Verkuil | bec4366 | 2008-12-30 06:58:20 -0300 | [diff] [blame] | 1980 | static const struct v4l2_file_operations radio_fops = { |
Hans Verkuil | a399810 | 2008-07-21 02:57:38 -0300 | [diff] [blame] | 1981 | .owner = THIS_MODULE, |
| 1982 | .open = em28xx_v4l2_open, |
| 1983 | .release = em28xx_v4l2_close, |
| 1984 | .ioctl = video_ioctl2, |
Hans Verkuil | a399810 | 2008-07-21 02:57:38 -0300 | [diff] [blame] | 1985 | }; |
| 1986 | |
| 1987 | static const struct v4l2_ioctl_ops radio_ioctl_ops = { |
Mauro Carvalho Chehab | 0be4375 | 2008-01-05 17:22:01 -0300 | [diff] [blame] | 1988 | .vidioc_querycap = radio_querycap, |
| 1989 | .vidioc_g_tuner = radio_g_tuner, |
| 1990 | .vidioc_enum_input = radio_enum_input, |
| 1991 | .vidioc_g_audio = radio_g_audio, |
| 1992 | .vidioc_s_tuner = radio_s_tuner, |
| 1993 | .vidioc_s_audio = radio_s_audio, |
| 1994 | .vidioc_s_input = radio_s_input, |
| 1995 | .vidioc_queryctrl = radio_queryctrl, |
| 1996 | .vidioc_g_ctrl = vidioc_g_ctrl, |
| 1997 | .vidioc_s_ctrl = vidioc_s_ctrl, |
| 1998 | .vidioc_g_frequency = vidioc_g_frequency, |
| 1999 | .vidioc_s_frequency = vidioc_s_frequency, |
Mauro Carvalho Chehab | 1e7ad56 | 2008-02-06 09:00:41 -0300 | [diff] [blame] | 2000 | #ifdef CONFIG_VIDEO_ADV_DEBUG |
| 2001 | .vidioc_g_register = vidioc_g_register, |
| 2002 | .vidioc_s_register = vidioc_s_register, |
| 2003 | #endif |
Mauro Carvalho Chehab | 0be4375 | 2008-01-05 17:22:01 -0300 | [diff] [blame] | 2004 | }; |
| 2005 | |
Hans Verkuil | a399810 | 2008-07-21 02:57:38 -0300 | [diff] [blame] | 2006 | static struct video_device em28xx_radio_template = { |
| 2007 | .name = "em28xx-radio", |
Hans Verkuil | a399810 | 2008-07-21 02:57:38 -0300 | [diff] [blame] | 2008 | .fops = &radio_fops, |
| 2009 | .ioctl_ops = &radio_ioctl_ops, |
| 2010 | .minor = -1, |
| 2011 | }; |
| 2012 | |
Douglas Schilling Landgraf | 6ea54d9 | 2008-04-17 21:41:10 -0300 | [diff] [blame] | 2013 | /******************************** usb interface ******************************/ |
akpm@osdl.org | a6c2ba2 | 2005-11-08 21:37:07 -0800 | [diff] [blame] | 2014 | |
Mauro Carvalho Chehab | 6d79468 | 2008-01-05 09:57:31 -0300 | [diff] [blame] | 2015 | |
Mauro Carvalho Chehab | 6d79468 | 2008-01-05 09:57:31 -0300 | [diff] [blame] | 2016 | |
Adrian Bunk | 532fe65 | 2008-01-28 22:10:48 -0300 | [diff] [blame] | 2017 | static struct video_device *em28xx_vdev_init(struct em28xx *dev, |
Nicola Soranzo | a1a6ee7 | 2009-02-10 23:28:24 -0300 | [diff] [blame] | 2018 | const struct video_device *template, |
| 2019 | const char *type_name) |
Mauro Carvalho Chehab | 0be4375 | 2008-01-05 17:22:01 -0300 | [diff] [blame] | 2020 | { |
| 2021 | struct video_device *vfd; |
| 2022 | |
| 2023 | vfd = video_device_alloc(); |
| 2024 | if (NULL == vfd) |
| 2025 | return NULL; |
Douglas Schilling Landgraf | f2cf250 | 2009-03-31 17:10:58 -0300 | [diff] [blame] | 2026 | |
| 2027 | *vfd = *template; |
| 2028 | vfd->minor = -1; |
| 2029 | vfd->v4l2_dev = &dev->v4l2_dev; |
| 2030 | vfd->release = video_device_release; |
| 2031 | vfd->debug = video_debug; |
Mauro Carvalho Chehab | 0be4375 | 2008-01-05 17:22:01 -0300 | [diff] [blame] | 2032 | |
| 2033 | snprintf(vfd->name, sizeof(vfd->name), "%s %s", |
| 2034 | dev->name, type_name); |
| 2035 | |
| 2036 | return vfd; |
| 2037 | } |
| 2038 | |
Mauro Carvalho Chehab | 2e5ef2d | 2008-12-28 22:26:36 -0300 | [diff] [blame] | 2039 | int em28xx_register_analog_devices(struct em28xx *dev) |
Mauro Carvalho Chehab | 1a23f81 | 2008-12-28 22:18:14 -0300 | [diff] [blame] | 2040 | { |
Robert Krakora | 6e7b9ea | 2009-01-18 21:59:34 -0300 | [diff] [blame] | 2041 | u8 val; |
Mauro Carvalho Chehab | 2e5ef2d | 2008-12-28 22:26:36 -0300 | [diff] [blame] | 2042 | int ret; |
| 2043 | |
Mauro Carvalho Chehab | 1a23f81 | 2008-12-28 22:18:14 -0300 | [diff] [blame] | 2044 | printk(KERN_INFO "%s: v4l2 driver version %d.%d.%d\n", |
| 2045 | dev->name, |
| 2046 | (EM28XX_VERSION_CODE >> 16) & 0xff, |
| 2047 | (EM28XX_VERSION_CODE >> 8) & 0xff, EM28XX_VERSION_CODE & 0xff); |
| 2048 | |
Mauro Carvalho Chehab | 1a23f81 | 2008-12-28 22:18:14 -0300 | [diff] [blame] | 2049 | /* set default norm */ |
| 2050 | dev->norm = em28xx_video_template.current_norm; |
Mauro Carvalho Chehab | 1a23f81 | 2008-12-28 22:18:14 -0300 | [diff] [blame] | 2051 | dev->interlaced = EM28XX_INTERLACED_DEFAULT; |
Mauro Carvalho Chehab | 24c3c41 | 2009-01-07 22:49:25 -0300 | [diff] [blame] | 2052 | dev->ctl_input = 0; |
Mauro Carvalho Chehab | 1a23f81 | 2008-12-28 22:18:14 -0300 | [diff] [blame] | 2053 | |
Mauro Carvalho Chehab | 24c3c41 | 2009-01-07 22:49:25 -0300 | [diff] [blame] | 2054 | /* Analog specific initialization */ |
| 2055 | dev->format = &format[0]; |
Mauro Carvalho Chehab | ed5f143 | 2009-07-02 17:34:04 -0300 | [diff] [blame] | 2056 | em28xx_set_video_format(dev, format[0].fourcc, |
| 2057 | norm_maxw(dev), norm_maxh(dev)); |
| 2058 | |
Mauro Carvalho Chehab | 24c3c41 | 2009-01-07 22:49:25 -0300 | [diff] [blame] | 2059 | video_mux(dev, dev->ctl_input); |
| 2060 | |
| 2061 | /* Audio defaults */ |
| 2062 | dev->mute = 1; |
| 2063 | dev->volume = 0x1f; |
| 2064 | |
| 2065 | /* enable vbi capturing */ |
| 2066 | |
| 2067 | /* em28xx_write_reg(dev, EM28XX_R0E_AUDIOSRC, 0xc0); audio register */ |
Nicola Soranzo | a1a6ee7 | 2009-02-10 23:28:24 -0300 | [diff] [blame] | 2068 | val = (u8)em28xx_read_reg(dev, EM28XX_R0F_XCLK); |
| 2069 | em28xx_write_reg(dev, EM28XX_R0F_XCLK, |
| 2070 | (EM28XX_XCLK_AUDIO_UNMUTE | val)); |
Mauro Carvalho Chehab | 24c3c41 | 2009-01-07 22:49:25 -0300 | [diff] [blame] | 2071 | em28xx_write_reg(dev, EM28XX_R11_VINCTRL, 0x51); |
| 2072 | |
| 2073 | em28xx_set_outfmt(dev); |
| 2074 | em28xx_colorlevels_set_default(dev); |
| 2075 | em28xx_compression_disable(dev); |
Mauro Carvalho Chehab | 1a23f81 | 2008-12-28 22:18:14 -0300 | [diff] [blame] | 2076 | |
Mauro Carvalho Chehab | 818a557 | 2008-11-20 10:30:26 -0300 | [diff] [blame] | 2077 | /* allocate and fill video video_device struct */ |
| 2078 | dev->vdev = em28xx_vdev_init(dev, &em28xx_video_template, "video"); |
| 2079 | if (!dev->vdev) { |
| 2080 | em28xx_errdev("cannot allocate video_device.\n"); |
| 2081 | return -ENODEV; |
| 2082 | } |
| 2083 | |
| 2084 | /* register v4l2 video video_device */ |
| 2085 | ret = video_register_device(dev->vdev, VFL_TYPE_GRABBER, |
| 2086 | video_nr[dev->devno]); |
| 2087 | if (ret) { |
| 2088 | em28xx_errdev("unable to register video device (error=%i).\n", |
| 2089 | ret); |
| 2090 | return ret; |
| 2091 | } |
| 2092 | |
| 2093 | /* Allocate and fill vbi video_device struct */ |
| 2094 | dev->vbi_dev = em28xx_vdev_init(dev, &em28xx_video_template, "vbi"); |
| 2095 | |
| 2096 | /* register v4l2 vbi video_device */ |
| 2097 | ret = video_register_device(dev->vbi_dev, VFL_TYPE_VBI, |
| 2098 | vbi_nr[dev->devno]); |
| 2099 | if (ret < 0) { |
| 2100 | em28xx_errdev("unable to register vbi device\n"); |
| 2101 | return ret; |
| 2102 | } |
| 2103 | |
| 2104 | if (em28xx_boards[dev->model].radio.type == EM28XX_RADIO) { |
Nicola Soranzo | a1a6ee7 | 2009-02-10 23:28:24 -0300 | [diff] [blame] | 2105 | dev->radio_dev = em28xx_vdev_init(dev, &em28xx_radio_template, |
| 2106 | "radio"); |
Mauro Carvalho Chehab | 818a557 | 2008-11-20 10:30:26 -0300 | [diff] [blame] | 2107 | if (!dev->radio_dev) { |
| 2108 | em28xx_errdev("cannot allocate video_device.\n"); |
| 2109 | return -ENODEV; |
| 2110 | } |
| 2111 | ret = video_register_device(dev->radio_dev, VFL_TYPE_RADIO, |
| 2112 | radio_nr[dev->devno]); |
| 2113 | if (ret < 0) { |
| 2114 | em28xx_errdev("can't register radio device\n"); |
| 2115 | return ret; |
| 2116 | } |
| 2117 | em28xx_info("Registered radio device as /dev/radio%d\n", |
| 2118 | dev->radio_dev->num); |
| 2119 | } |
| 2120 | |
| 2121 | em28xx_info("V4L2 device registered as /dev/video%d and /dev/vbi%d\n", |
| 2122 | dev->vdev->num, dev->vbi_dev->num); |
| 2123 | |
| 2124 | return 0; |
| 2125 | } |