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> |
Trent Piepho | 6d35c8f | 2007-11-01 01:16:09 -0300 | [diff] [blame] | 35 | #include <linux/mm.h> |
Ingo Molnar | 1e4baed | 2006-01-15 07:52:23 -0200 | [diff] [blame] | 36 | #include <linux/mutex.h> |
Tejun Heo | 5a0e3ad | 2010-03-24 17:04:11 +0900 | [diff] [blame] | 37 | #include <linux/slab.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" |
Mauro Carvalho Chehab | 1990d50 | 2011-06-24 14:45:49 -0300 | [diff] [blame] | 52 | |
| 53 | #define EM28XX_VERSION "0.1.3" |
akpm@osdl.org | a6c2ba2 | 2005-11-08 21:37:07 -0800 | [diff] [blame] | 54 | |
Mauro Carvalho Chehab | 3acf280 | 2005-11-08 21:38:27 -0800 | [diff] [blame] | 55 | #define em28xx_videodbg(fmt, arg...) do {\ |
Mauro Carvalho Chehab | 4ac9791 | 2005-11-08 21:37:43 -0800 | [diff] [blame] | 56 | if (video_debug) \ |
| 57 | printk(KERN_INFO "%s %s :"fmt, \ |
Harvey Harrison | d80e134 | 2008-04-08 23:20:00 -0300 | [diff] [blame] | 58 | dev->name, __func__ , ##arg); } while (0) |
akpm@osdl.org | a6c2ba2 | 2005-11-08 21:37:07 -0800 | [diff] [blame] | 59 | |
Mauro Carvalho Chehab | ad0ebb9 | 2008-04-13 14:37:52 -0300 | [diff] [blame] | 60 | static unsigned int isoc_debug; |
Mauro Carvalho Chehab | f245e54 | 2008-04-13 14:41:23 -0300 | [diff] [blame] | 61 | module_param(isoc_debug, int, 0644); |
| 62 | MODULE_PARM_DESC(isoc_debug, "enable debug messages [isoc transfers]"); |
Mauro Carvalho Chehab | ad0ebb9 | 2008-04-13 14:37:52 -0300 | [diff] [blame] | 63 | |
Douglas Schilling Landgraf | 6ea54d9 | 2008-04-17 21:41:10 -0300 | [diff] [blame] | 64 | #define em28xx_isocdbg(fmt, arg...) \ |
| 65 | do {\ |
| 66 | if (isoc_debug) { \ |
Mauro Carvalho Chehab | ad0ebb9 | 2008-04-13 14:37:52 -0300 | [diff] [blame] | 67 | printk(KERN_INFO "%s %s :"fmt, \ |
Douglas Schilling Landgraf | 6ea54d9 | 2008-04-17 21:41:10 -0300 | [diff] [blame] | 68 | dev->name, __func__ , ##arg); \ |
| 69 | } \ |
| 70 | } while (0) |
Mauro Carvalho Chehab | ad0ebb9 | 2008-04-13 14:37:52 -0300 | [diff] [blame] | 71 | |
akpm@osdl.org | a6c2ba2 | 2005-11-08 21:37:07 -0800 | [diff] [blame] | 72 | MODULE_AUTHOR(DRIVER_AUTHOR); |
| 73 | MODULE_DESCRIPTION(DRIVER_DESC); |
| 74 | MODULE_LICENSE("GPL"); |
Mauro Carvalho Chehab | 1990d50 | 2011-06-24 14:45:49 -0300 | [diff] [blame] | 75 | MODULE_VERSION(EM28XX_VERSION); |
akpm@osdl.org | a6c2ba2 | 2005-11-08 21:37:07 -0800 | [diff] [blame] | 76 | |
Mauro Carvalho Chehab | e5589be | 2006-01-23 17:11:08 -0200 | [diff] [blame] | 77 | static unsigned int video_nr[] = {[0 ... (EM28XX_MAXBOARDS - 1)] = UNSET }; |
Mauro Carvalho Chehab | 0be4375 | 2008-01-05 17:22:01 -0300 | [diff] [blame] | 78 | static unsigned int vbi_nr[] = {[0 ... (EM28XX_MAXBOARDS - 1)] = UNSET }; |
| 79 | static unsigned int radio_nr[] = {[0 ... (EM28XX_MAXBOARDS - 1)] = UNSET }; |
| 80 | |
Mauro Carvalho Chehab | e5589be | 2006-01-23 17:11:08 -0200 | [diff] [blame] | 81 | module_param_array(video_nr, int, NULL, 0444); |
| 82 | module_param_array(vbi_nr, int, NULL, 0444); |
Mauro Carvalho Chehab | 0be4375 | 2008-01-05 17:22:01 -0300 | [diff] [blame] | 83 | module_param_array(radio_nr, int, NULL, 0444); |
Mauro Carvalho Chehab | 0be4375 | 2008-01-05 17:22:01 -0300 | [diff] [blame] | 84 | MODULE_PARM_DESC(video_nr, "video device numbers"); |
| 85 | MODULE_PARM_DESC(vbi_nr, "vbi device numbers"); |
| 86 | MODULE_PARM_DESC(radio_nr, "radio device numbers"); |
Mauro Carvalho Chehab | 596d92d | 2005-11-08 21:37:24 -0800 | [diff] [blame] | 87 | |
Douglas Schilling Landgraf | ff699e6 | 2008-04-22 14:41:48 -0300 | [diff] [blame] | 88 | static unsigned int video_debug; |
Douglas Schilling Landgraf | 6ea54d9 | 2008-04-17 21:41:10 -0300 | [diff] [blame] | 89 | module_param(video_debug, int, 0644); |
| 90 | MODULE_PARM_DESC(video_debug, "enable debug messages [video]"); |
akpm@osdl.org | a6c2ba2 | 2005-11-08 21:37:07 -0800 | [diff] [blame] | 91 | |
Mauro Carvalho Chehab | bddcf63 | 2008-12-20 09:06:37 -0300 | [diff] [blame] | 92 | /* supported video standards */ |
| 93 | static struct em28xx_fmt format[] = { |
| 94 | { |
Mauro Carvalho Chehab | 58fc1ce | 2009-07-03 02:54:18 -0300 | [diff] [blame] | 95 | .name = "16 bpp YUY2, 4:2:2, packed", |
Mauro Carvalho Chehab | bddcf63 | 2008-12-20 09:06:37 -0300 | [diff] [blame] | 96 | .fourcc = V4L2_PIX_FMT_YUYV, |
| 97 | .depth = 16, |
Devin Heitmueller | 3fbf930 | 2008-12-29 23:34:37 -0300 | [diff] [blame] | 98 | .reg = EM28XX_OUTFMT_YUV422_Y0UY1V, |
Mauro Carvalho Chehab | 43cb9fe | 2009-06-30 08:36:17 -0300 | [diff] [blame] | 99 | }, { |
Mauro Carvalho Chehab | 58fc1ce | 2009-07-03 02:54:18 -0300 | [diff] [blame] | 100 | .name = "16 bpp RGB 565, LE", |
Mauro Carvalho Chehab | 43cb9fe | 2009-06-30 08:36:17 -0300 | [diff] [blame] | 101 | .fourcc = V4L2_PIX_FMT_RGB565, |
| 102 | .depth = 16, |
Mauro Carvalho Chehab | 58fc1ce | 2009-07-03 02:54:18 -0300 | [diff] [blame] | 103 | .reg = EM28XX_OUTFMT_RGB_16_656, |
| 104 | }, { |
| 105 | .name = "8 bpp Bayer BGBG..GRGR", |
| 106 | .fourcc = V4L2_PIX_FMT_SBGGR8, |
| 107 | .depth = 8, |
| 108 | .reg = EM28XX_OUTFMT_RGB_8_BGBG, |
| 109 | }, { |
| 110 | .name = "8 bpp Bayer GRGR..BGBG", |
| 111 | .fourcc = V4L2_PIX_FMT_SGRBG8, |
| 112 | .depth = 8, |
| 113 | .reg = EM28XX_OUTFMT_RGB_8_GRGR, |
| 114 | }, { |
| 115 | .name = "8 bpp Bayer GBGB..RGRG", |
| 116 | .fourcc = V4L2_PIX_FMT_SGBRG8, |
| 117 | .depth = 8, |
| 118 | .reg = EM28XX_OUTFMT_RGB_8_GBGB, |
| 119 | }, { |
| 120 | .name = "12 bpp YUV411", |
| 121 | .fourcc = V4L2_PIX_FMT_YUV411P, |
| 122 | .depth = 12, |
| 123 | .reg = EM28XX_OUTFMT_YUV411, |
Mauro Carvalho Chehab | bddcf63 | 2008-12-20 09:06:37 -0300 | [diff] [blame] | 124 | }, |
| 125 | }; |
| 126 | |
akpm@osdl.org | a6c2ba2 | 2005-11-08 21:37:07 -0800 | [diff] [blame] | 127 | /* supported controls */ |
Mauro Carvalho Chehab | c0477ad | 2006-01-09 15:25:14 -0200 | [diff] [blame] | 128 | /* Common to all boards */ |
Mauro Carvalho Chehab | ed10daa | 2009-07-19 09:10:06 -0300 | [diff] [blame] | 129 | static struct v4l2_queryctrl ac97_qctrl[] = { |
akpm@osdl.org | a6c2ba2 | 2005-11-08 21:37:07 -0800 | [diff] [blame] | 130 | { |
Mauro Carvalho Chehab | c0477ad | 2006-01-09 15:25:14 -0200 | [diff] [blame] | 131 | .id = V4L2_CID_AUDIO_VOLUME, |
| 132 | .type = V4L2_CTRL_TYPE_INTEGER, |
| 133 | .name = "Volume", |
| 134 | .minimum = 0x0, |
| 135 | .maximum = 0x1f, |
| 136 | .step = 0x1, |
| 137 | .default_value = 0x1f, |
Mauro Carvalho Chehab | a98f6af | 2009-07-19 10:45:49 -0300 | [diff] [blame] | 138 | .flags = V4L2_CTRL_FLAG_SLIDER, |
Douglas Schilling Landgraf | 6ea54d9 | 2008-04-17 21:41:10 -0300 | [diff] [blame] | 139 | }, { |
Mauro Carvalho Chehab | c0477ad | 2006-01-09 15:25:14 -0200 | [diff] [blame] | 140 | .id = V4L2_CID_AUDIO_MUTE, |
| 141 | .type = V4L2_CTRL_TYPE_BOOLEAN, |
| 142 | .name = "Mute", |
| 143 | .minimum = 0, |
| 144 | .maximum = 1, |
| 145 | .step = 1, |
| 146 | .default_value = 1, |
| 147 | .flags = 0, |
| 148 | } |
| 149 | }; |
| 150 | |
Mauro Carvalho Chehab | ad0ebb9 | 2008-04-13 14:37:52 -0300 | [diff] [blame] | 151 | /* ------------------------------------------------------------------ |
| 152 | DMA and thread functions |
| 153 | ------------------------------------------------------------------*/ |
| 154 | |
| 155 | /* |
| 156 | * Announces that a buffer were filled and request the next |
| 157 | */ |
Mauro Carvalho Chehab | f245e54 | 2008-04-13 14:41:23 -0300 | [diff] [blame] | 158 | static inline void buffer_filled(struct em28xx *dev, |
Mauro Carvalho Chehab | ad0ebb9 | 2008-04-13 14:37:52 -0300 | [diff] [blame] | 159 | struct em28xx_dmaqueue *dma_q, |
| 160 | struct em28xx_buffer *buf) |
| 161 | { |
Mauro Carvalho Chehab | ad0ebb9 | 2008-04-13 14:37:52 -0300 | [diff] [blame] | 162 | /* Advice that buffer was filled */ |
| 163 | em28xx_isocdbg("[%p/%d] wakeup\n", buf, buf->vb.i); |
| 164 | buf->vb.state = VIDEOBUF_DONE; |
| 165 | buf->vb.field_count++; |
| 166 | do_gettimeofday(&buf->vb.ts); |
| 167 | |
Devin Heitmueller | 28abf083 | 2009-09-01 01:54:54 -0300 | [diff] [blame] | 168 | dev->isoc_ctl.vid_buf = NULL; |
| 169 | |
| 170 | list_del(&buf->vb.queue); |
| 171 | wake_up(&buf->vb.done); |
| 172 | } |
| 173 | |
| 174 | static inline void vbi_buffer_filled(struct em28xx *dev, |
| 175 | struct em28xx_dmaqueue *dma_q, |
| 176 | struct em28xx_buffer *buf) |
| 177 | { |
| 178 | /* Advice that buffer was filled */ |
| 179 | em28xx_isocdbg("[%p/%d] wakeup\n", buf, buf->vb.i); |
| 180 | |
| 181 | buf->vb.state = VIDEOBUF_DONE; |
| 182 | buf->vb.field_count++; |
| 183 | do_gettimeofday(&buf->vb.ts); |
| 184 | |
| 185 | dev->isoc_ctl.vbi_buf = NULL; |
Mauro Carvalho Chehab | cb78472 | 2008-04-13 15:06:52 -0300 | [diff] [blame] | 186 | |
Mauro Carvalho Chehab | ad0ebb9 | 2008-04-13 14:37:52 -0300 | [diff] [blame] | 187 | list_del(&buf->vb.queue); |
| 188 | wake_up(&buf->vb.done); |
| 189 | } |
| 190 | |
| 191 | /* |
| 192 | * Identify the buffer header type and properly handles |
| 193 | */ |
| 194 | static void em28xx_copy_video(struct em28xx *dev, |
| 195 | struct em28xx_dmaqueue *dma_q, |
| 196 | struct em28xx_buffer *buf, |
| 197 | unsigned char *p, |
| 198 | unsigned char *outp, unsigned long len) |
| 199 | { |
| 200 | void *fieldstart, *startwrite, *startread; |
Mauro Carvalho Chehab | f245e54 | 2008-04-13 14:41:23 -0300 | [diff] [blame] | 201 | int linesdone, currlinedone, offset, lencopy, remain; |
Mauro Carvalho Chehab | 44dc733 | 2008-04-13 15:11:08 -0300 | [diff] [blame] | 202 | int bytesperline = dev->width << 1; |
Mauro Carvalho Chehab | ad0ebb9 | 2008-04-13 14:37:52 -0300 | [diff] [blame] | 203 | |
| 204 | if (dma_q->pos + len > buf->vb.size) |
| 205 | len = buf->vb.size - dma_q->pos; |
| 206 | |
Mauro Carvalho Chehab | ad0ebb9 | 2008-04-13 14:37:52 -0300 | [diff] [blame] | 207 | startread = p; |
| 208 | remain = len; |
| 209 | |
Mauro Carvalho Chehab | c2a6b54 | 2009-08-08 03:14:55 -0300 | [diff] [blame] | 210 | if (dev->progressive) |
Mauro Carvalho Chehab | ad0ebb9 | 2008-04-13 14:37:52 -0300 | [diff] [blame] | 211 | fieldstart = outp; |
Mauro Carvalho Chehab | c2a6b54 | 2009-08-08 03:14:55 -0300 | [diff] [blame] | 212 | else { |
| 213 | /* Interlaces two half frames */ |
| 214 | if (buf->top_field) |
| 215 | fieldstart = outp; |
| 216 | else |
| 217 | fieldstart = outp + bytesperline; |
| 218 | } |
Mauro Carvalho Chehab | ad0ebb9 | 2008-04-13 14:37:52 -0300 | [diff] [blame] | 219 | |
Mauro Carvalho Chehab | 44dc733 | 2008-04-13 15:11:08 -0300 | [diff] [blame] | 220 | linesdone = dma_q->pos / bytesperline; |
| 221 | currlinedone = dma_q->pos % bytesperline; |
Mauro Carvalho Chehab | c2a6b54 | 2009-08-08 03:14:55 -0300 | [diff] [blame] | 222 | |
| 223 | if (dev->progressive) |
| 224 | offset = linesdone * bytesperline + currlinedone; |
| 225 | else |
| 226 | offset = linesdone * bytesperline * 2 + currlinedone; |
| 227 | |
Mauro Carvalho Chehab | ad0ebb9 | 2008-04-13 14:37:52 -0300 | [diff] [blame] | 228 | startwrite = fieldstart + offset; |
Mauro Carvalho Chehab | 44dc733 | 2008-04-13 15:11:08 -0300 | [diff] [blame] | 229 | lencopy = bytesperline - currlinedone; |
Mauro Carvalho Chehab | ad0ebb9 | 2008-04-13 14:37:52 -0300 | [diff] [blame] | 230 | lencopy = lencopy > remain ? remain : lencopy; |
| 231 | |
Mauro Carvalho Chehab | f245e54 | 2008-04-13 14:41:23 -0300 | [diff] [blame] | 232 | if ((char *)startwrite + lencopy > (char *)outp + buf->vb.size) { |
Mauro Carvalho Chehab | ea8df7e | 2008-04-13 14:39:29 -0300 | [diff] [blame] | 233 | em28xx_isocdbg("Overflow of %zi bytes past buffer end (1)\n", |
Mauro Carvalho Chehab | f245e54 | 2008-04-13 14:41:23 -0300 | [diff] [blame] | 234 | ((char *)startwrite + lencopy) - |
| 235 | ((char *)outp + buf->vb.size)); |
Nicola Soranzo | a1a6ee7 | 2009-02-10 23:28:24 -0300 | [diff] [blame] | 236 | remain = (char *)outp + buf->vb.size - (char *)startwrite; |
| 237 | lencopy = remain; |
Aidan Thornton | d7aa802 | 2008-04-13 14:38:47 -0300 | [diff] [blame] | 238 | } |
Aidan Thornton | e0fadfd34 | 2008-04-13 14:56:02 -0300 | [diff] [blame] | 239 | if (lencopy <= 0) |
| 240 | return; |
Aidan Thornton | d7aa802 | 2008-04-13 14:38:47 -0300 | [diff] [blame] | 241 | memcpy(startwrite, startread, lencopy); |
Mauro Carvalho Chehab | ad0ebb9 | 2008-04-13 14:37:52 -0300 | [diff] [blame] | 242 | |
| 243 | remain -= lencopy; |
| 244 | |
| 245 | while (remain > 0) { |
Mauro Carvalho Chehab | 44dc733 | 2008-04-13 15:11:08 -0300 | [diff] [blame] | 246 | startwrite += lencopy + bytesperline; |
Mauro Carvalho Chehab | ad0ebb9 | 2008-04-13 14:37:52 -0300 | [diff] [blame] | 247 | startread += lencopy; |
Mauro Carvalho Chehab | 44dc733 | 2008-04-13 15:11:08 -0300 | [diff] [blame] | 248 | if (bytesperline > remain) |
Mauro Carvalho Chehab | ad0ebb9 | 2008-04-13 14:37:52 -0300 | [diff] [blame] | 249 | lencopy = remain; |
| 250 | else |
Mauro Carvalho Chehab | 44dc733 | 2008-04-13 15:11:08 -0300 | [diff] [blame] | 251 | lencopy = bytesperline; |
Mauro Carvalho Chehab | ad0ebb9 | 2008-04-13 14:37:52 -0300 | [diff] [blame] | 252 | |
Nicola Soranzo | a1a6ee7 | 2009-02-10 23:28:24 -0300 | [diff] [blame] | 253 | if ((char *)startwrite + lencopy > (char *)outp + |
| 254 | buf->vb.size) { |
Devin Heitmueller | e3ba4d3 | 2009-09-15 00:18:06 -0300 | [diff] [blame] | 255 | em28xx_isocdbg("Overflow of %zi bytes past buffer end" |
| 256 | "(2)\n", |
Mauro Carvalho Chehab | f245e54 | 2008-04-13 14:41:23 -0300 | [diff] [blame] | 257 | ((char *)startwrite + lencopy) - |
| 258 | ((char *)outp + buf->vb.size)); |
| 259 | lencopy = remain = (char *)outp + buf->vb.size - |
| 260 | (char *)startwrite; |
Aidan Thornton | d7aa802 | 2008-04-13 14:38:47 -0300 | [diff] [blame] | 261 | } |
Mauro Carvalho Chehab | f245e54 | 2008-04-13 14:41:23 -0300 | [diff] [blame] | 262 | if (lencopy <= 0) |
| 263 | break; |
Aidan Thornton | d7aa802 | 2008-04-13 14:38:47 -0300 | [diff] [blame] | 264 | |
| 265 | memcpy(startwrite, startread, lencopy); |
Mauro Carvalho Chehab | ad0ebb9 | 2008-04-13 14:37:52 -0300 | [diff] [blame] | 266 | |
| 267 | remain -= lencopy; |
| 268 | } |
| 269 | |
| 270 | dma_q->pos += len; |
| 271 | } |
| 272 | |
Devin Heitmueller | 28abf083 | 2009-09-01 01:54:54 -0300 | [diff] [blame] | 273 | static void em28xx_copy_vbi(struct em28xx *dev, |
| 274 | struct em28xx_dmaqueue *dma_q, |
| 275 | struct em28xx_buffer *buf, |
| 276 | unsigned char *p, |
| 277 | unsigned char *outp, unsigned long len) |
| 278 | { |
| 279 | void *startwrite, *startread; |
| 280 | int offset; |
Julia Lawall | 6b81bef | 2010-08-27 02:57:18 -0300 | [diff] [blame] | 281 | int bytesperline; |
Devin Heitmueller | 28abf083 | 2009-09-01 01:54:54 -0300 | [diff] [blame] | 282 | |
| 283 | if (dev == NULL) { |
Devin Heitmueller | e3ba4d3 | 2009-09-15 00:18:06 -0300 | [diff] [blame] | 284 | em28xx_isocdbg("dev is null\n"); |
Devin Heitmueller | 28abf083 | 2009-09-01 01:54:54 -0300 | [diff] [blame] | 285 | return; |
| 286 | } |
Julia Lawall | 6b81bef | 2010-08-27 02:57:18 -0300 | [diff] [blame] | 287 | bytesperline = dev->vbi_width; |
Devin Heitmueller | 28abf083 | 2009-09-01 01:54:54 -0300 | [diff] [blame] | 288 | |
| 289 | if (dma_q == NULL) { |
Devin Heitmueller | e3ba4d3 | 2009-09-15 00:18:06 -0300 | [diff] [blame] | 290 | em28xx_isocdbg("dma_q is null\n"); |
Devin Heitmueller | 28abf083 | 2009-09-01 01:54:54 -0300 | [diff] [blame] | 291 | return; |
| 292 | } |
| 293 | if (buf == NULL) { |
| 294 | return; |
| 295 | } |
| 296 | if (p == NULL) { |
Devin Heitmueller | e3ba4d3 | 2009-09-15 00:18:06 -0300 | [diff] [blame] | 297 | em28xx_isocdbg("p is null\n"); |
Devin Heitmueller | 28abf083 | 2009-09-01 01:54:54 -0300 | [diff] [blame] | 298 | return; |
| 299 | } |
| 300 | if (outp == NULL) { |
Devin Heitmueller | e3ba4d3 | 2009-09-15 00:18:06 -0300 | [diff] [blame] | 301 | em28xx_isocdbg("outp is null\n"); |
Devin Heitmueller | 28abf083 | 2009-09-01 01:54:54 -0300 | [diff] [blame] | 302 | return; |
| 303 | } |
| 304 | |
| 305 | if (dma_q->pos + len > buf->vb.size) |
| 306 | len = buf->vb.size - dma_q->pos; |
| 307 | |
Devin Heitmueller | 28abf083 | 2009-09-01 01:54:54 -0300 | [diff] [blame] | 308 | startread = p; |
| 309 | |
| 310 | startwrite = outp + dma_q->pos; |
| 311 | offset = dma_q->pos; |
| 312 | |
| 313 | /* Make sure the bottom field populates the second half of the frame */ |
| 314 | if (buf->top_field == 0) { |
Devin Heitmueller | 66d9cba | 2009-11-24 23:17:25 -0300 | [diff] [blame] | 315 | startwrite += bytesperline * dev->vbi_height; |
| 316 | offset += bytesperline * dev->vbi_height; |
Devin Heitmueller | 28abf083 | 2009-09-01 01:54:54 -0300 | [diff] [blame] | 317 | } |
| 318 | |
| 319 | memcpy(startwrite, startread, len); |
| 320 | dma_q->pos += len; |
| 321 | } |
| 322 | |
Mauro Carvalho Chehab | f245e54 | 2008-04-13 14:41:23 -0300 | [diff] [blame] | 323 | static inline void print_err_status(struct em28xx *dev, |
Mauro Carvalho Chehab | ad0ebb9 | 2008-04-13 14:37:52 -0300 | [diff] [blame] | 324 | int packet, int status) |
| 325 | { |
| 326 | char *errmsg = "Unknown"; |
| 327 | |
Mauro Carvalho Chehab | f245e54 | 2008-04-13 14:41:23 -0300 | [diff] [blame] | 328 | switch (status) { |
Mauro Carvalho Chehab | ad0ebb9 | 2008-04-13 14:37:52 -0300 | [diff] [blame] | 329 | case -ENOENT: |
| 330 | errmsg = "unlinked synchronuously"; |
| 331 | break; |
| 332 | case -ECONNRESET: |
| 333 | errmsg = "unlinked asynchronuously"; |
| 334 | break; |
| 335 | case -ENOSR: |
| 336 | errmsg = "Buffer error (overrun)"; |
| 337 | break; |
| 338 | case -EPIPE: |
| 339 | errmsg = "Stalled (device not responding)"; |
| 340 | break; |
| 341 | case -EOVERFLOW: |
| 342 | errmsg = "Babble (bad cable?)"; |
| 343 | break; |
| 344 | case -EPROTO: |
| 345 | errmsg = "Bit-stuff error (bad cable?)"; |
| 346 | break; |
| 347 | case -EILSEQ: |
| 348 | errmsg = "CRC/Timeout (could be anything)"; |
| 349 | break; |
| 350 | case -ETIME: |
| 351 | errmsg = "Device does not respond"; |
| 352 | break; |
| 353 | } |
Mauro Carvalho Chehab | f245e54 | 2008-04-13 14:41:23 -0300 | [diff] [blame] | 354 | if (packet < 0) { |
Mauro Carvalho Chehab | ad0ebb9 | 2008-04-13 14:37:52 -0300 | [diff] [blame] | 355 | em28xx_isocdbg("URB status %d [%s].\n", status, errmsg); |
| 356 | } else { |
| 357 | em28xx_isocdbg("URB packet %d, status %d [%s].\n", |
| 358 | packet, status, errmsg); |
| 359 | } |
| 360 | } |
| 361 | |
| 362 | /* |
| 363 | * video-buf generic routine to get the next available buffer |
| 364 | */ |
Aidan Thornton | 3b5fa92 | 2008-04-13 15:09:36 -0300 | [diff] [blame] | 365 | static inline void get_next_buf(struct em28xx_dmaqueue *dma_q, |
Mauro Carvalho Chehab | ad0ebb9 | 2008-04-13 14:37:52 -0300 | [diff] [blame] | 366 | struct em28xx_buffer **buf) |
| 367 | { |
| 368 | struct em28xx *dev = container_of(dma_q, struct em28xx, vidq); |
Mauro Carvalho Chehab | dbecb44 | 2008-04-13 15:08:55 -0300 | [diff] [blame] | 369 | char *outp; |
Mauro Carvalho Chehab | ad0ebb9 | 2008-04-13 14:37:52 -0300 | [diff] [blame] | 370 | |
Mauro Carvalho Chehab | dbecb44 | 2008-04-13 15:08:55 -0300 | [diff] [blame] | 371 | if (list_empty(&dma_q->active)) { |
| 372 | em28xx_isocdbg("No active queue to serve\n"); |
Devin Heitmueller | 28abf083 | 2009-09-01 01:54:54 -0300 | [diff] [blame] | 373 | dev->isoc_ctl.vid_buf = NULL; |
Mauro Carvalho Chehab | dbecb44 | 2008-04-13 15:08:55 -0300 | [diff] [blame] | 374 | *buf = NULL; |
Aidan Thornton | 3b5fa92 | 2008-04-13 15:09:36 -0300 | [diff] [blame] | 375 | return; |
Mauro Carvalho Chehab | dbecb44 | 2008-04-13 15:08:55 -0300 | [diff] [blame] | 376 | } |
| 377 | |
Mauro Carvalho Chehab | dbecb44 | 2008-04-13 15:08:55 -0300 | [diff] [blame] | 378 | /* Get the next buffer */ |
| 379 | *buf = list_entry(dma_q->active.next, struct em28xx_buffer, vb.queue); |
| 380 | |
Lucas De Marchi | 25985ed | 2011-03-30 22:57:33 -0300 | [diff] [blame] | 381 | /* Cleans up buffer - Useful for testing for frame/URB loss */ |
Mauro Carvalho Chehab | dbecb44 | 2008-04-13 15:08:55 -0300 | [diff] [blame] | 382 | outp = videobuf_to_vmalloc(&(*buf)->vb); |
| 383 | memset(outp, 0, (*buf)->vb.size); |
Mauro Carvalho Chehab | cb78472 | 2008-04-13 15:06:52 -0300 | [diff] [blame] | 384 | |
Devin Heitmueller | 28abf083 | 2009-09-01 01:54:54 -0300 | [diff] [blame] | 385 | dev->isoc_ctl.vid_buf = *buf; |
| 386 | |
| 387 | return; |
| 388 | } |
| 389 | |
| 390 | /* |
| 391 | * video-buf generic routine to get the next available VBI buffer |
| 392 | */ |
| 393 | static inline void vbi_get_next_buf(struct em28xx_dmaqueue *dma_q, |
| 394 | struct em28xx_buffer **buf) |
| 395 | { |
| 396 | struct em28xx *dev = container_of(dma_q, struct em28xx, vbiq); |
| 397 | char *outp; |
| 398 | |
| 399 | if (list_empty(&dma_q->active)) { |
| 400 | em28xx_isocdbg("No active queue to serve\n"); |
| 401 | dev->isoc_ctl.vbi_buf = NULL; |
| 402 | *buf = NULL; |
| 403 | return; |
| 404 | } |
| 405 | |
| 406 | /* Get the next buffer */ |
| 407 | *buf = list_entry(dma_q->active.next, struct em28xx_buffer, vb.queue); |
Lucas De Marchi | 25985ed | 2011-03-30 22:57:33 -0300 | [diff] [blame] | 408 | /* Cleans up buffer - Useful for testing for frame/URB loss */ |
Devin Heitmueller | 28abf083 | 2009-09-01 01:54:54 -0300 | [diff] [blame] | 409 | outp = videobuf_to_vmalloc(&(*buf)->vb); |
| 410 | memset(outp, 0x00, (*buf)->vb.size); |
| 411 | |
| 412 | dev->isoc_ctl.vbi_buf = *buf; |
Mauro Carvalho Chehab | cb78472 | 2008-04-13 15:06:52 -0300 | [diff] [blame] | 413 | |
Aidan Thornton | 3b5fa92 | 2008-04-13 15:09:36 -0300 | [diff] [blame] | 414 | return; |
Mauro Carvalho Chehab | ad0ebb9 | 2008-04-13 14:37:52 -0300 | [diff] [blame] | 415 | } |
| 416 | |
| 417 | /* |
| 418 | * Controls the isoc copy of each urb packet |
| 419 | */ |
Aidan Thornton | 579f72e | 2008-04-17 21:40:16 -0300 | [diff] [blame] | 420 | 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] | 421 | { |
Aidan Thornton | d7aa802 | 2008-04-13 14:38:47 -0300 | [diff] [blame] | 422 | struct em28xx_buffer *buf; |
Devin Heitmueller | da52a55 | 2009-09-01 01:19:46 -0300 | [diff] [blame] | 423 | struct em28xx_dmaqueue *dma_q = &dev->vidq; |
Aidan Thornton | 3b5fa92 | 2008-04-13 15:09:36 -0300 | [diff] [blame] | 424 | unsigned char *outp = NULL; |
Mauro Carvalho Chehab | ad0ebb9 | 2008-04-13 14:37:52 -0300 | [diff] [blame] | 425 | int i, len = 0, rc = 1; |
Aidan Thornton | d7aa802 | 2008-04-13 14:38:47 -0300 | [diff] [blame] | 426 | unsigned char *p; |
Mauro Carvalho Chehab | ad0ebb9 | 2008-04-13 14:37:52 -0300 | [diff] [blame] | 427 | |
| 428 | if (!dev) |
| 429 | return 0; |
| 430 | |
| 431 | if ((dev->state & DEV_DISCONNECTED) || (dev->state & DEV_MISCONFIGURED)) |
| 432 | return 0; |
| 433 | |
Mauro Carvalho Chehab | f245e54 | 2008-04-13 14:41:23 -0300 | [diff] [blame] | 434 | if (urb->status < 0) { |
| 435 | print_err_status(dev, -1, urb->status); |
Mauro Carvalho Chehab | ad0ebb9 | 2008-04-13 14:37:52 -0300 | [diff] [blame] | 436 | if (urb->status == -ENOENT) |
| 437 | return 0; |
| 438 | } |
| 439 | |
Devin Heitmueller | 28abf083 | 2009-09-01 01:54:54 -0300 | [diff] [blame] | 440 | buf = dev->isoc_ctl.vid_buf; |
Aidan Thornton | 3b5fa92 | 2008-04-13 15:09:36 -0300 | [diff] [blame] | 441 | if (buf != NULL) |
| 442 | outp = videobuf_to_vmalloc(&buf->vb); |
Aidan Thornton | d7aa802 | 2008-04-13 14:38:47 -0300 | [diff] [blame] | 443 | |
Mauro Carvalho Chehab | ad0ebb9 | 2008-04-13 14:37:52 -0300 | [diff] [blame] | 444 | for (i = 0; i < urb->number_of_packets; i++) { |
| 445 | int status = urb->iso_frame_desc[i].status; |
| 446 | |
Mauro Carvalho Chehab | f245e54 | 2008-04-13 14:41:23 -0300 | [diff] [blame] | 447 | if (status < 0) { |
| 448 | print_err_status(dev, i, status); |
Mauro Carvalho Chehab | ad0ebb9 | 2008-04-13 14:37:52 -0300 | [diff] [blame] | 449 | if (urb->iso_frame_desc[i].status != -EPROTO) |
| 450 | continue; |
| 451 | } |
| 452 | |
Mauro Carvalho Chehab | f245e54 | 2008-04-13 14:41:23 -0300 | [diff] [blame] | 453 | len = urb->iso_frame_desc[i].actual_length - 4; |
Mauro Carvalho Chehab | ad0ebb9 | 2008-04-13 14:37:52 -0300 | [diff] [blame] | 454 | |
| 455 | if (urb->iso_frame_desc[i].actual_length <= 0) { |
Aidan Thornton | d7aa802 | 2008-04-13 14:38:47 -0300 | [diff] [blame] | 456 | /* em28xx_isocdbg("packet %d is empty",i); - spammy */ |
Mauro Carvalho Chehab | ad0ebb9 | 2008-04-13 14:37:52 -0300 | [diff] [blame] | 457 | continue; |
| 458 | } |
| 459 | if (urb->iso_frame_desc[i].actual_length > |
| 460 | dev->max_pkt_size) { |
| 461 | em28xx_isocdbg("packet bigger than packet size"); |
| 462 | continue; |
| 463 | } |
| 464 | |
| 465 | p = urb->transfer_buffer + urb->iso_frame_desc[i].offset; |
Mauro Carvalho Chehab | ad0ebb9 | 2008-04-13 14:37:52 -0300 | [diff] [blame] | 466 | |
| 467 | /* FIXME: incomplete buffer checks where removed to make |
| 468 | logic simpler. Impacts of those changes should be evaluated |
| 469 | */ |
Mauro Carvalho Chehab | b4916f8 | 2008-04-13 15:09:14 -0300 | [diff] [blame] | 470 | if (p[0] == 0x33 && p[1] == 0x95 && p[2] == 0x00) { |
| 471 | em28xx_isocdbg("VBI HEADER!!!\n"); |
| 472 | /* FIXME: Should add vbi copy */ |
| 473 | continue; |
| 474 | } |
Aidan Thornton | d7aa802 | 2008-04-13 14:38:47 -0300 | [diff] [blame] | 475 | if (p[0] == 0x22 && p[1] == 0x5a) { |
Mauro Carvalho Chehab | 78bb394 | 2008-04-13 14:56:25 -0300 | [diff] [blame] | 476 | em28xx_isocdbg("Video frame %d, length=%i, %s\n", p[2], |
Nicola Soranzo | a1a6ee7 | 2009-02-10 23:28:24 -0300 | [diff] [blame] | 477 | len, (p[2] & 1) ? "odd" : "even"); |
Mauro Carvalho Chehab | ad0ebb9 | 2008-04-13 14:37:52 -0300 | [diff] [blame] | 478 | |
Mauro Carvalho Chehab | c2a6b54 | 2009-08-08 03:14:55 -0300 | [diff] [blame] | 479 | if (dev->progressive || !(p[2] & 1)) { |
Aidan Thornton | 3b5fa92 | 2008-04-13 15:09:36 -0300 | [diff] [blame] | 480 | if (buf != NULL) |
| 481 | buffer_filled(dev, dma_q, buf); |
| 482 | get_next_buf(dma_q, &buf); |
| 483 | if (buf == NULL) |
| 484 | outp = NULL; |
| 485 | else |
| 486 | outp = videobuf_to_vmalloc(&buf->vb); |
Aidan Thornton | e0fadfd34 | 2008-04-13 14:56:02 -0300 | [diff] [blame] | 487 | } |
Aidan Thornton | 3b5fa92 | 2008-04-13 15:09:36 -0300 | [diff] [blame] | 488 | |
| 489 | if (buf != NULL) { |
| 490 | if (p[2] & 1) |
| 491 | buf->top_field = 0; |
| 492 | else |
| 493 | buf->top_field = 1; |
| 494 | } |
Mauro Carvalho Chehab | b4916f8 | 2008-04-13 15:09:14 -0300 | [diff] [blame] | 495 | |
Mauro Carvalho Chehab | ad0ebb9 | 2008-04-13 14:37:52 -0300 | [diff] [blame] | 496 | dma_q->pos = 0; |
Mauro Carvalho Chehab | ad0ebb9 | 2008-04-13 14:37:52 -0300 | [diff] [blame] | 497 | } |
Devin Heitmueller | 5fee334 | 2010-01-22 02:34:32 -0300 | [diff] [blame] | 498 | if (buf != NULL) { |
| 499 | if (p[0] != 0x88 && p[0] != 0x22) { |
| 500 | em28xx_isocdbg("frame is not complete\n"); |
| 501 | len += 4; |
| 502 | } else { |
| 503 | p += 4; |
| 504 | } |
Aidan Thornton | 3b5fa92 | 2008-04-13 15:09:36 -0300 | [diff] [blame] | 505 | em28xx_copy_video(dev, dma_q, buf, p, outp, len); |
Devin Heitmueller | 5fee334 | 2010-01-22 02:34:32 -0300 | [diff] [blame] | 506 | } |
Mauro Carvalho Chehab | ad0ebb9 | 2008-04-13 14:37:52 -0300 | [diff] [blame] | 507 | } |
| 508 | return rc; |
| 509 | } |
| 510 | |
Devin Heitmueller | da52a55 | 2009-09-01 01:19:46 -0300 | [diff] [blame] | 511 | /* Version of isoc handler that takes into account a mixture of video and |
| 512 | VBI data */ |
| 513 | static inline int em28xx_isoc_copy_vbi(struct em28xx *dev, struct urb *urb) |
| 514 | { |
| 515 | struct em28xx_buffer *buf, *vbi_buf; |
| 516 | struct em28xx_dmaqueue *dma_q = &dev->vidq; |
Devin Heitmueller | 28abf083 | 2009-09-01 01:54:54 -0300 | [diff] [blame] | 517 | struct em28xx_dmaqueue *vbi_dma_q = &dev->vbiq; |
Devin Heitmueller | da52a55 | 2009-09-01 01:19:46 -0300 | [diff] [blame] | 518 | unsigned char *outp = NULL; |
| 519 | unsigned char *vbioutp = NULL; |
| 520 | int i, len = 0, rc = 1; |
| 521 | unsigned char *p; |
| 522 | int vbi_size; |
| 523 | |
| 524 | if (!dev) |
| 525 | return 0; |
| 526 | |
| 527 | if ((dev->state & DEV_DISCONNECTED) || (dev->state & DEV_MISCONFIGURED)) |
| 528 | return 0; |
| 529 | |
| 530 | if (urb->status < 0) { |
| 531 | print_err_status(dev, -1, urb->status); |
| 532 | if (urb->status == -ENOENT) |
| 533 | return 0; |
| 534 | } |
| 535 | |
Devin Heitmueller | 28abf083 | 2009-09-01 01:54:54 -0300 | [diff] [blame] | 536 | buf = dev->isoc_ctl.vid_buf; |
Devin Heitmueller | da52a55 | 2009-09-01 01:19:46 -0300 | [diff] [blame] | 537 | if (buf != NULL) |
| 538 | outp = videobuf_to_vmalloc(&buf->vb); |
Devin Heitmueller | 28abf083 | 2009-09-01 01:54:54 -0300 | [diff] [blame] | 539 | |
| 540 | vbi_buf = dev->isoc_ctl.vbi_buf; |
| 541 | if (vbi_buf != NULL) |
| 542 | vbioutp = videobuf_to_vmalloc(&vbi_buf->vb); |
| 543 | |
Devin Heitmueller | da52a55 | 2009-09-01 01:19:46 -0300 | [diff] [blame] | 544 | for (i = 0; i < urb->number_of_packets; i++) { |
| 545 | int status = urb->iso_frame_desc[i].status; |
| 546 | |
| 547 | if (status < 0) { |
| 548 | print_err_status(dev, i, status); |
| 549 | if (urb->iso_frame_desc[i].status != -EPROTO) |
| 550 | continue; |
| 551 | } |
| 552 | |
Devin Heitmueller | 5fee334 | 2010-01-22 02:34:32 -0300 | [diff] [blame] | 553 | len = urb->iso_frame_desc[i].actual_length; |
Devin Heitmueller | da52a55 | 2009-09-01 01:19:46 -0300 | [diff] [blame] | 554 | if (urb->iso_frame_desc[i].actual_length <= 0) { |
| 555 | /* em28xx_isocdbg("packet %d is empty",i); - spammy */ |
| 556 | continue; |
| 557 | } |
| 558 | if (urb->iso_frame_desc[i].actual_length > |
| 559 | dev->max_pkt_size) { |
| 560 | em28xx_isocdbg("packet bigger than packet size"); |
| 561 | continue; |
| 562 | } |
| 563 | |
| 564 | p = urb->transfer_buffer + urb->iso_frame_desc[i].offset; |
| 565 | |
| 566 | /* capture type 0 = vbi start |
| 567 | capture type 1 = video start |
| 568 | capture type 2 = video in progress */ |
| 569 | if (p[0] == 0x33 && p[1] == 0x95) { |
| 570 | dev->capture_type = 0; |
| 571 | dev->vbi_read = 0; |
| 572 | em28xx_isocdbg("VBI START HEADER!!!\n"); |
| 573 | dev->cur_field = p[2]; |
Devin Heitmueller | 5fee334 | 2010-01-22 02:34:32 -0300 | [diff] [blame] | 574 | p += 4; |
| 575 | len -= 4; |
| 576 | } else if (p[0] == 0x88 && p[1] == 0x88 && |
| 577 | p[2] == 0x88 && p[3] == 0x88) { |
| 578 | /* continuation */ |
| 579 | p += 4; |
| 580 | len -= 4; |
| 581 | } else if (p[0] == 0x22 && p[1] == 0x5a) { |
| 582 | /* start video */ |
| 583 | p += 4; |
| 584 | len -= 4; |
Devin Heitmueller | da52a55 | 2009-09-01 01:19:46 -0300 | [diff] [blame] | 585 | } |
| 586 | |
Devin Heitmueller | 66d9cba | 2009-11-24 23:17:25 -0300 | [diff] [blame] | 587 | vbi_size = dev->vbi_width * dev->vbi_height; |
Devin Heitmueller | da52a55 | 2009-09-01 01:19:46 -0300 | [diff] [blame] | 588 | |
| 589 | if (dev->capture_type == 0) { |
| 590 | if (dev->vbi_read >= vbi_size) { |
| 591 | /* We've already read all the VBI data, so |
| 592 | treat the rest as video */ |
Devin Heitmueller | e3ba4d3 | 2009-09-15 00:18:06 -0300 | [diff] [blame] | 593 | em28xx_isocdbg("dev->vbi_read > vbi_size\n"); |
Devin Heitmueller | da52a55 | 2009-09-01 01:19:46 -0300 | [diff] [blame] | 594 | } else if ((dev->vbi_read + len) < vbi_size) { |
| 595 | /* This entire frame is VBI data */ |
Devin Heitmueller | 28abf083 | 2009-09-01 01:54:54 -0300 | [diff] [blame] | 596 | if (dev->vbi_read == 0 && |
| 597 | (!(dev->cur_field & 1))) { |
| 598 | /* Brand new frame */ |
| 599 | if (vbi_buf != NULL) |
| 600 | vbi_buffer_filled(dev, |
| 601 | vbi_dma_q, |
| 602 | vbi_buf); |
| 603 | vbi_get_next_buf(vbi_dma_q, &vbi_buf); |
| 604 | if (vbi_buf == NULL) |
| 605 | vbioutp = NULL; |
Devin Heitmueller | e3ba4d3 | 2009-09-15 00:18:06 -0300 | [diff] [blame] | 606 | else |
| 607 | vbioutp = videobuf_to_vmalloc( |
| 608 | &vbi_buf->vb); |
Devin Heitmueller | 28abf083 | 2009-09-01 01:54:54 -0300 | [diff] [blame] | 609 | } |
| 610 | |
| 611 | if (dev->vbi_read == 0) { |
| 612 | vbi_dma_q->pos = 0; |
| 613 | if (vbi_buf != NULL) { |
| 614 | if (dev->cur_field & 1) |
| 615 | vbi_buf->top_field = 0; |
| 616 | else |
| 617 | vbi_buf->top_field = 1; |
| 618 | } |
| 619 | } |
| 620 | |
Devin Heitmueller | da52a55 | 2009-09-01 01:19:46 -0300 | [diff] [blame] | 621 | dev->vbi_read += len; |
Devin Heitmueller | 28abf083 | 2009-09-01 01:54:54 -0300 | [diff] [blame] | 622 | em28xx_copy_vbi(dev, vbi_dma_q, vbi_buf, p, |
| 623 | vbioutp, len); |
Devin Heitmueller | da52a55 | 2009-09-01 01:19:46 -0300 | [diff] [blame] | 624 | } else { |
| 625 | /* Some of this frame is VBI data and some is |
| 626 | video data */ |
| 627 | int vbi_data_len = vbi_size - dev->vbi_read; |
| 628 | dev->vbi_read += vbi_data_len; |
Devin Heitmueller | 28abf083 | 2009-09-01 01:54:54 -0300 | [diff] [blame] | 629 | em28xx_copy_vbi(dev, vbi_dma_q, vbi_buf, p, |
| 630 | vbioutp, vbi_data_len); |
Devin Heitmueller | da52a55 | 2009-09-01 01:19:46 -0300 | [diff] [blame] | 631 | dev->capture_type = 1; |
| 632 | p += vbi_data_len; |
| 633 | len -= vbi_data_len; |
| 634 | } |
| 635 | } |
| 636 | |
| 637 | if (dev->capture_type == 1) { |
| 638 | dev->capture_type = 2; |
Devin Heitmueller | da52a55 | 2009-09-01 01:19:46 -0300 | [diff] [blame] | 639 | if (dev->progressive || !(dev->cur_field & 1)) { |
| 640 | if (buf != NULL) |
| 641 | buffer_filled(dev, dma_q, buf); |
| 642 | get_next_buf(dma_q, &buf); |
| 643 | if (buf == NULL) |
| 644 | outp = NULL; |
| 645 | else |
| 646 | outp = videobuf_to_vmalloc(&buf->vb); |
| 647 | } |
| 648 | if (buf != NULL) { |
| 649 | if (dev->cur_field & 1) |
| 650 | buf->top_field = 0; |
| 651 | else |
| 652 | buf->top_field = 1; |
| 653 | } |
| 654 | |
| 655 | dma_q->pos = 0; |
| 656 | } |
Devin Heitmueller | 5fee334 | 2010-01-22 02:34:32 -0300 | [diff] [blame] | 657 | |
| 658 | if (buf != NULL && dev->capture_type == 2) { |
Devin Heitmueller | 2584bc4 | 2010-06-13 17:00:23 -0300 | [diff] [blame] | 659 | if (len >= 4 && p[0] == 0x88 && p[1] == 0x88 && |
Devin Heitmueller | 5fee334 | 2010-01-22 02:34:32 -0300 | [diff] [blame] | 660 | p[2] == 0x88 && p[3] == 0x88) { |
| 661 | p += 4; |
| 662 | len -= 4; |
| 663 | } |
Devin Heitmueller | 2584bc4 | 2010-06-13 17:00:23 -0300 | [diff] [blame] | 664 | if (len >= 4 && p[0] == 0x22 && p[1] == 0x5a) { |
Devin Heitmueller | 5fee334 | 2010-01-22 02:34:32 -0300 | [diff] [blame] | 665 | em28xx_isocdbg("Video frame %d, len=%i, %s\n", |
| 666 | p[2], len, (p[2] & 1) ? |
| 667 | "odd" : "even"); |
| 668 | p += 4; |
| 669 | len -= 4; |
| 670 | } |
| 671 | |
| 672 | if (len > 0) |
| 673 | em28xx_copy_video(dev, dma_q, buf, p, outp, |
| 674 | len); |
| 675 | } |
Devin Heitmueller | da52a55 | 2009-09-01 01:19:46 -0300 | [diff] [blame] | 676 | } |
| 677 | return rc; |
| 678 | } |
| 679 | |
| 680 | |
Mauro Carvalho Chehab | ad0ebb9 | 2008-04-13 14:37:52 -0300 | [diff] [blame] | 681 | /* ------------------------------------------------------------------ |
Mauro Carvalho Chehab | ad0ebb9 | 2008-04-13 14:37:52 -0300 | [diff] [blame] | 682 | Videobuf operations |
| 683 | ------------------------------------------------------------------*/ |
| 684 | |
| 685 | static int |
| 686 | buffer_setup(struct videobuf_queue *vq, unsigned int *count, unsigned int *size) |
| 687 | { |
| 688 | struct em28xx_fh *fh = vq->priv_data; |
Mauro Carvalho Chehab | d2d9fbf | 2008-04-17 21:38:53 -0300 | [diff] [blame] | 689 | struct em28xx *dev = fh->dev; |
| 690 | struct v4l2_frequency f; |
Mauro Carvalho Chehab | ad0ebb9 | 2008-04-13 14:37:52 -0300 | [diff] [blame] | 691 | |
Devin Heitmueller | e3ba4d3 | 2009-09-15 00:18:06 -0300 | [diff] [blame] | 692 | *size = (fh->dev->width * fh->dev->height * dev->format->depth + 7) |
| 693 | >> 3; |
Mauro Carvalho Chehab | bddcf63 | 2008-12-20 09:06:37 -0300 | [diff] [blame] | 694 | |
Mauro Carvalho Chehab | ad0ebb9 | 2008-04-13 14:37:52 -0300 | [diff] [blame] | 695 | if (0 == *count) |
| 696 | *count = EM28XX_DEF_BUF; |
| 697 | |
Mauro Carvalho Chehab | f245e54 | 2008-04-13 14:41:23 -0300 | [diff] [blame] | 698 | if (*count < EM28XX_MIN_BUF) |
| 699 | *count = EM28XX_MIN_BUF; |
Mauro Carvalho Chehab | ad0ebb9 | 2008-04-13 14:37:52 -0300 | [diff] [blame] | 700 | |
Mauro Carvalho Chehab | 381aaba | 2008-12-20 07:43:34 -0300 | [diff] [blame] | 701 | /* Ask tuner to go to analog or radio mode */ |
Douglas Schilling Landgraf | 6ea54d9 | 2008-04-17 21:41:10 -0300 | [diff] [blame] | 702 | memset(&f, 0, sizeof(f)); |
Mauro Carvalho Chehab | d2d9fbf | 2008-04-17 21:38:53 -0300 | [diff] [blame] | 703 | f.frequency = dev->ctl_freq; |
Mauro Carvalho Chehab | 381aaba | 2008-12-20 07:43:34 -0300 | [diff] [blame] | 704 | f.type = fh->radio ? V4L2_TUNER_RADIO : V4L2_TUNER_ANALOG_TV; |
Mauro Carvalho Chehab | d2d9fbf | 2008-04-17 21:38:53 -0300 | [diff] [blame] | 705 | |
Douglas Schilling Landgraf | f2cf250 | 2009-03-31 17:10:58 -0300 | [diff] [blame] | 706 | 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] | 707 | |
Mauro Carvalho Chehab | ad0ebb9 | 2008-04-13 14:37:52 -0300 | [diff] [blame] | 708 | return 0; |
| 709 | } |
| 710 | |
Aidan Thornton | 3b5fa92 | 2008-04-13 15:09:36 -0300 | [diff] [blame] | 711 | /* 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] | 712 | static void free_buffer(struct videobuf_queue *vq, struct em28xx_buffer *buf) |
| 713 | { |
Aidan Thornton | 3b5fa92 | 2008-04-13 15:09:36 -0300 | [diff] [blame] | 714 | struct em28xx_fh *fh = vq->priv_data; |
| 715 | struct em28xx *dev = fh->dev; |
| 716 | unsigned long flags = 0; |
Mauro Carvalho Chehab | ad0ebb9 | 2008-04-13 14:37:52 -0300 | [diff] [blame] | 717 | if (in_interrupt()) |
| 718 | BUG(); |
| 719 | |
Aidan Thornton | 3b5fa92 | 2008-04-13 15:09:36 -0300 | [diff] [blame] | 720 | /* We used to wait for the buffer to finish here, but this didn't work |
| 721 | because, as we were keeping the state as VIDEOBUF_QUEUED, |
| 722 | videobuf_queue_cancel marked it as finished for us. |
| 723 | (Also, it could wedge forever if the hardware was misconfigured.) |
| 724 | |
| 725 | This should be safe; by the time we get here, the buffer isn't |
| 726 | queued anymore. If we ever start marking the buffers as |
| 727 | VIDEOBUF_ACTIVE, it won't be, though. |
| 728 | */ |
| 729 | spin_lock_irqsave(&dev->slock, flags); |
Devin Heitmueller | 28abf083 | 2009-09-01 01:54:54 -0300 | [diff] [blame] | 730 | if (dev->isoc_ctl.vid_buf == buf) |
| 731 | dev->isoc_ctl.vid_buf = NULL; |
Aidan Thornton | 3b5fa92 | 2008-04-13 15:09:36 -0300 | [diff] [blame] | 732 | spin_unlock_irqrestore(&dev->slock, flags); |
| 733 | |
Mauro Carvalho Chehab | ad0ebb9 | 2008-04-13 14:37:52 -0300 | [diff] [blame] | 734 | videobuf_vmalloc_free(&buf->vb); |
| 735 | buf->vb.state = VIDEOBUF_NEEDS_INIT; |
| 736 | } |
| 737 | |
| 738 | static int |
| 739 | buffer_prepare(struct videobuf_queue *vq, struct videobuf_buffer *vb, |
| 740 | enum v4l2_field field) |
| 741 | { |
| 742 | struct em28xx_fh *fh = vq->priv_data; |
Mauro Carvalho Chehab | f245e54 | 2008-04-13 14:41:23 -0300 | [diff] [blame] | 743 | struct em28xx_buffer *buf = container_of(vb, struct em28xx_buffer, vb); |
Mauro Carvalho Chehab | ad0ebb9 | 2008-04-13 14:37:52 -0300 | [diff] [blame] | 744 | struct em28xx *dev = fh->dev; |
| 745 | int rc = 0, urb_init = 0; |
Mauro Carvalho Chehab | ad0ebb9 | 2008-04-13 14:37:52 -0300 | [diff] [blame] | 746 | |
Devin Heitmueller | e3ba4d3 | 2009-09-15 00:18:06 -0300 | [diff] [blame] | 747 | buf->vb.size = (fh->dev->width * fh->dev->height * dev->format->depth |
| 748 | + 7) >> 3; |
Mauro Carvalho Chehab | ad0ebb9 | 2008-04-13 14:37:52 -0300 | [diff] [blame] | 749 | |
| 750 | if (0 != buf->vb.baddr && buf->vb.bsize < buf->vb.size) |
| 751 | return -EINVAL; |
| 752 | |
Brandon Philips | 0561297 | 2008-04-13 14:57:01 -0300 | [diff] [blame] | 753 | buf->vb.width = dev->width; |
| 754 | buf->vb.height = dev->height; |
| 755 | buf->vb.field = field; |
Mauro Carvalho Chehab | ad0ebb9 | 2008-04-13 14:37:52 -0300 | [diff] [blame] | 756 | |
| 757 | if (VIDEOBUF_NEEDS_INIT == buf->vb.state) { |
Aidan Thornton | d7aa802 | 2008-04-13 14:38:47 -0300 | [diff] [blame] | 758 | rc = videobuf_iolock(vq, &buf->vb, NULL); |
| 759 | if (rc < 0) |
Mauro Carvalho Chehab | ad0ebb9 | 2008-04-13 14:37:52 -0300 | [diff] [blame] | 760 | goto fail; |
Mauro Carvalho Chehab | ad0ebb9 | 2008-04-13 14:37:52 -0300 | [diff] [blame] | 761 | } |
| 762 | |
Mauro Carvalho Chehab | ad0ebb9 | 2008-04-13 14:37:52 -0300 | [diff] [blame] | 763 | if (!dev->isoc_ctl.num_bufs) |
Mauro Carvalho Chehab | f245e54 | 2008-04-13 14:41:23 -0300 | [diff] [blame] | 764 | urb_init = 1; |
Mauro Carvalho Chehab | ad0ebb9 | 2008-04-13 14:37:52 -0300 | [diff] [blame] | 765 | |
| 766 | if (urb_init) { |
Devin Heitmueller | da52a55 | 2009-09-01 01:19:46 -0300 | [diff] [blame] | 767 | if (em28xx_vbi_supported(dev) == 1) |
| 768 | rc = em28xx_init_isoc(dev, EM28XX_NUM_PACKETS, |
| 769 | EM28XX_NUM_BUFS, |
| 770 | dev->max_pkt_size, |
| 771 | em28xx_isoc_copy_vbi); |
| 772 | else |
| 773 | rc = em28xx_init_isoc(dev, EM28XX_NUM_PACKETS, |
| 774 | EM28XX_NUM_BUFS, |
| 775 | dev->max_pkt_size, |
| 776 | em28xx_isoc_copy); |
Mauro Carvalho Chehab | f245e54 | 2008-04-13 14:41:23 -0300 | [diff] [blame] | 777 | if (rc < 0) |
Mauro Carvalho Chehab | ad0ebb9 | 2008-04-13 14:37:52 -0300 | [diff] [blame] | 778 | goto fail; |
| 779 | } |
| 780 | |
| 781 | buf->vb.state = VIDEOBUF_PREPARED; |
| 782 | return 0; |
| 783 | |
| 784 | fail: |
Mauro Carvalho Chehab | f245e54 | 2008-04-13 14:41:23 -0300 | [diff] [blame] | 785 | free_buffer(vq, buf); |
Mauro Carvalho Chehab | ad0ebb9 | 2008-04-13 14:37:52 -0300 | [diff] [blame] | 786 | return rc; |
| 787 | } |
| 788 | |
| 789 | static void |
| 790 | buffer_queue(struct videobuf_queue *vq, struct videobuf_buffer *vb) |
| 791 | { |
Nicola Soranzo | a1a6ee7 | 2009-02-10 23:28:24 -0300 | [diff] [blame] | 792 | struct em28xx_buffer *buf = container_of(vb, |
| 793 | struct em28xx_buffer, |
| 794 | vb); |
Mauro Carvalho Chehab | ad0ebb9 | 2008-04-13 14:37:52 -0300 | [diff] [blame] | 795 | struct em28xx_fh *fh = vq->priv_data; |
Mauro Carvalho Chehab | f245e54 | 2008-04-13 14:41:23 -0300 | [diff] [blame] | 796 | struct em28xx *dev = fh->dev; |
Mauro Carvalho Chehab | ad0ebb9 | 2008-04-13 14:37:52 -0300 | [diff] [blame] | 797 | struct em28xx_dmaqueue *vidq = &dev->vidq; |
Mauro Carvalho Chehab | ad0ebb9 | 2008-04-13 14:37:52 -0300 | [diff] [blame] | 798 | |
Aidan Thornton | d7aa802 | 2008-04-13 14:38:47 -0300 | [diff] [blame] | 799 | buf->vb.state = VIDEOBUF_QUEUED; |
| 800 | list_add_tail(&buf->vb.queue, &vidq->active); |
| 801 | |
Mauro Carvalho Chehab | ad0ebb9 | 2008-04-13 14:37:52 -0300 | [diff] [blame] | 802 | } |
| 803 | |
Douglas Schilling Landgraf | 6ea54d9 | 2008-04-17 21:41:10 -0300 | [diff] [blame] | 804 | static void buffer_release(struct videobuf_queue *vq, |
| 805 | struct videobuf_buffer *vb) |
Mauro Carvalho Chehab | ad0ebb9 | 2008-04-13 14:37:52 -0300 | [diff] [blame] | 806 | { |
Nicola Soranzo | a1a6ee7 | 2009-02-10 23:28:24 -0300 | [diff] [blame] | 807 | struct em28xx_buffer *buf = container_of(vb, |
| 808 | struct em28xx_buffer, |
| 809 | vb); |
Mauro Carvalho Chehab | ad0ebb9 | 2008-04-13 14:37:52 -0300 | [diff] [blame] | 810 | struct em28xx_fh *fh = vq->priv_data; |
Mauro Carvalho Chehab | f245e54 | 2008-04-13 14:41:23 -0300 | [diff] [blame] | 811 | struct em28xx *dev = (struct em28xx *)fh->dev; |
Mauro Carvalho Chehab | ad0ebb9 | 2008-04-13 14:37:52 -0300 | [diff] [blame] | 812 | |
Aidan Thornton | d7aa802 | 2008-04-13 14:38:47 -0300 | [diff] [blame] | 813 | em28xx_isocdbg("em28xx: called buffer_release\n"); |
Mauro Carvalho Chehab | ad0ebb9 | 2008-04-13 14:37:52 -0300 | [diff] [blame] | 814 | |
Mauro Carvalho Chehab | f245e54 | 2008-04-13 14:41:23 -0300 | [diff] [blame] | 815 | free_buffer(vq, buf); |
Mauro Carvalho Chehab | ad0ebb9 | 2008-04-13 14:37:52 -0300 | [diff] [blame] | 816 | } |
| 817 | |
| 818 | static struct videobuf_queue_ops em28xx_video_qops = { |
| 819 | .buf_setup = buffer_setup, |
| 820 | .buf_prepare = buffer_prepare, |
| 821 | .buf_queue = buffer_queue, |
| 822 | .buf_release = buffer_release, |
| 823 | }; |
akpm@osdl.org | a6c2ba2 | 2005-11-08 21:37:07 -0800 | [diff] [blame] | 824 | |
Douglas Schilling Landgraf | 6ea54d9 | 2008-04-17 21:41:10 -0300 | [diff] [blame] | 825 | /********************* v4l2 interface **************************************/ |
akpm@osdl.org | a6c2ba2 | 2005-11-08 21:37:07 -0800 | [diff] [blame] | 826 | |
Mauro Carvalho Chehab | eac9435 | 2005-11-08 21:38:43 -0800 | [diff] [blame] | 827 | static void video_mux(struct em28xx *dev, int index) |
| 828 | { |
Mauro Carvalho Chehab | eac9435 | 2005-11-08 21:38:43 -0800 | [diff] [blame] | 829 | dev->ctl_input = index; |
| 830 | dev->ctl_ainput = INPUT(index)->amux; |
Mauro Carvalho Chehab | 35ae6f0 | 2008-11-20 12:40:51 -0300 | [diff] [blame] | 831 | dev->ctl_aoutput = INPUT(index)->aout; |
Mauro Carvalho Chehab | eac9435 | 2005-11-08 21:38:43 -0800 | [diff] [blame] | 832 | |
Mauro Carvalho Chehab | e879b8e | 2008-11-20 13:39:39 -0300 | [diff] [blame] | 833 | if (!dev->ctl_aoutput) |
| 834 | dev->ctl_aoutput = EM28XX_AOUT_MASTER; |
| 835 | |
Hans Verkuil | 5325b42 | 2009-04-02 11:26:22 -0300 | [diff] [blame] | 836 | v4l2_device_call_all(&dev->v4l2_dev, 0, video, s_routing, |
| 837 | INPUT(index)->vmux, 0, 0); |
Mauro Carvalho Chehab | eac9435 | 2005-11-08 21:38:43 -0800 | [diff] [blame] | 838 | |
Mauro Carvalho Chehab | 505b6d0 | 2008-11-25 09:39:50 -0300 | [diff] [blame] | 839 | if (dev->board.has_msp34xx) { |
Douglas Schilling Landgraf | 6ea54d9 | 2008-04-17 21:41:10 -0300 | [diff] [blame] | 840 | if (dev->i2s_speed) { |
Douglas Schilling Landgraf | f2cf250 | 2009-03-31 17:10:58 -0300 | [diff] [blame] | 841 | v4l2_device_call_all(&dev->v4l2_dev, 0, audio, |
| 842 | s_i2s_clock_freq, dev->i2s_speed); |
Douglas Schilling Landgraf | 6ea54d9 | 2008-04-17 21:41:10 -0300 | [diff] [blame] | 843 | } |
Hans Verkuil | 2474ed4 | 2006-03-19 12:35:57 -0300 | [diff] [blame] | 844 | /* Note: this is msp3400 specific */ |
Hans Verkuil | 5325b42 | 2009-04-02 11:26:22 -0300 | [diff] [blame] | 845 | v4l2_device_call_all(&dev->v4l2_dev, 0, audio, s_routing, |
| 846 | dev->ctl_ainput, MSP_OUTPUT(MSP_SC_IN_DSP_SCART1), 0); |
Mauro Carvalho Chehab | eac9435 | 2005-11-08 21:38:43 -0800 | [diff] [blame] | 847 | } |
Mauro Carvalho Chehab | 539c96d | 2008-01-05 09:53:54 -0300 | [diff] [blame] | 848 | |
Vitaly Wool | 2bd1d9e | 2009-03-04 08:27:52 -0300 | [diff] [blame] | 849 | if (dev->board.adecoder != EM28XX_NOADECODER) { |
Hans Verkuil | 5325b42 | 2009-04-02 11:26:22 -0300 | [diff] [blame] | 850 | v4l2_device_call_all(&dev->v4l2_dev, 0, audio, s_routing, |
| 851 | dev->ctl_ainput, dev->ctl_aoutput, 0); |
Vitaly Wool | 2bd1d9e | 2009-03-04 08:27:52 -0300 | [diff] [blame] | 852 | } |
| 853 | |
Mauro Carvalho Chehab | 00b8730 | 2008-02-06 18:34:13 -0300 | [diff] [blame] | 854 | em28xx_audio_analog_set(dev); |
Mauro Carvalho Chehab | eac9435 | 2005-11-08 21:38:43 -0800 | [diff] [blame] | 855 | } |
| 856 | |
Mauro Carvalho Chehab | a225452 | 2007-11-11 01:08:26 -0300 | [diff] [blame] | 857 | /* Usage lock check functions */ |
Devin Heitmueller | 8c873d3 | 2009-09-03 00:23:27 -0300 | [diff] [blame] | 858 | static int res_get(struct em28xx_fh *fh, unsigned int bit) |
Mauro Carvalho Chehab | a225452 | 2007-11-11 01:08:26 -0300 | [diff] [blame] | 859 | { |
| 860 | struct em28xx *dev = fh->dev; |
| 861 | |
Devin Heitmueller | 8c873d3 | 2009-09-03 00:23:27 -0300 | [diff] [blame] | 862 | if (fh->resources & bit) |
| 863 | /* have it already allocated */ |
| 864 | return 1; |
| 865 | |
| 866 | /* is it free? */ |
Devin Heitmueller | 8c873d3 | 2009-09-03 00:23:27 -0300 | [diff] [blame] | 867 | if (dev->resources & bit) { |
| 868 | /* no, someone else uses it */ |
Devin Heitmueller | 8c873d3 | 2009-09-03 00:23:27 -0300 | [diff] [blame] | 869 | return 0; |
| 870 | } |
| 871 | /* it's free, grab it */ |
| 872 | fh->resources |= bit; |
| 873 | dev->resources |= bit; |
| 874 | em28xx_videodbg("res: get %d\n", bit); |
Devin Heitmueller | 8c873d3 | 2009-09-03 00:23:27 -0300 | [diff] [blame] | 875 | return 1; |
| 876 | } |
| 877 | |
| 878 | static int res_check(struct em28xx_fh *fh, unsigned int bit) |
| 879 | { |
Devin Heitmueller | e3ba4d3 | 2009-09-15 00:18:06 -0300 | [diff] [blame] | 880 | return fh->resources & bit; |
Devin Heitmueller | 8c873d3 | 2009-09-03 00:23:27 -0300 | [diff] [blame] | 881 | } |
| 882 | |
| 883 | static int res_locked(struct em28xx *dev, unsigned int bit) |
| 884 | { |
Devin Heitmueller | e3ba4d3 | 2009-09-15 00:18:06 -0300 | [diff] [blame] | 885 | return dev->resources & bit; |
Devin Heitmueller | 8c873d3 | 2009-09-03 00:23:27 -0300 | [diff] [blame] | 886 | } |
| 887 | |
| 888 | static void res_free(struct em28xx_fh *fh, unsigned int bits) |
| 889 | { |
| 890 | struct em28xx *dev = fh->dev; |
| 891 | |
| 892 | BUG_ON((fh->resources & bits) != bits); |
| 893 | |
Devin Heitmueller | 8c873d3 | 2009-09-03 00:23:27 -0300 | [diff] [blame] | 894 | fh->resources &= ~bits; |
| 895 | dev->resources &= ~bits; |
| 896 | em28xx_videodbg("res: put %d\n", bits); |
Devin Heitmueller | 8c873d3 | 2009-09-03 00:23:27 -0300 | [diff] [blame] | 897 | } |
| 898 | |
| 899 | static int get_ressource(struct em28xx_fh *fh) |
| 900 | { |
| 901 | switch (fh->type) { |
| 902 | case V4L2_BUF_TYPE_VIDEO_CAPTURE: |
| 903 | return EM28XX_RESOURCE_VIDEO; |
| 904 | case V4L2_BUF_TYPE_VBI_CAPTURE: |
| 905 | return EM28XX_RESOURCE_VBI; |
| 906 | default: |
| 907 | BUG(); |
| 908 | return 0; |
| 909 | } |
Mauro Carvalho Chehab | a225452 | 2007-11-11 01:08:26 -0300 | [diff] [blame] | 910 | } |
| 911 | |
akpm@osdl.org | a6c2ba2 | 2005-11-08 21:37:07 -0800 | [diff] [blame] | 912 | /* |
Mauro Carvalho Chehab | a98f6af | 2009-07-19 10:45:49 -0300 | [diff] [blame] | 913 | * ac97_queryctrl() |
| 914 | * return the ac97 supported controls |
Mauro Carvalho Chehab | 195a4ef | 2007-11-11 13:17:17 -0300 | [diff] [blame] | 915 | */ |
Mauro Carvalho Chehab | a98f6af | 2009-07-19 10:45:49 -0300 | [diff] [blame] | 916 | static int ac97_queryctrl(struct v4l2_queryctrl *qc) |
| 917 | { |
| 918 | int i; |
| 919 | |
| 920 | for (i = 0; i < ARRAY_SIZE(ac97_qctrl); i++) { |
| 921 | if (qc->id && qc->id == ac97_qctrl[i].id) { |
| 922 | memcpy(qc, &(ac97_qctrl[i]), sizeof(*qc)); |
| 923 | return 0; |
| 924 | } |
| 925 | } |
| 926 | |
| 927 | /* Control is not ac97 related */ |
| 928 | return 1; |
| 929 | } |
| 930 | |
| 931 | /* |
| 932 | * ac97_get_ctrl() |
| 933 | * return the current values for ac97 mute and volume |
| 934 | */ |
| 935 | static int ac97_get_ctrl(struct em28xx *dev, struct v4l2_control *ctrl) |
Mauro Carvalho Chehab | 195a4ef | 2007-11-11 13:17:17 -0300 | [diff] [blame] | 936 | { |
| 937 | switch (ctrl->id) { |
| 938 | case V4L2_CID_AUDIO_MUTE: |
| 939 | ctrl->value = dev->mute; |
| 940 | return 0; |
| 941 | case V4L2_CID_AUDIO_VOLUME: |
| 942 | ctrl->value = dev->volume; |
| 943 | return 0; |
| 944 | default: |
Mauro Carvalho Chehab | a98f6af | 2009-07-19 10:45:49 -0300 | [diff] [blame] | 945 | /* Control is not ac97 related */ |
| 946 | return 1; |
Mauro Carvalho Chehab | 195a4ef | 2007-11-11 13:17:17 -0300 | [diff] [blame] | 947 | } |
| 948 | } |
| 949 | |
| 950 | /* |
Mauro Carvalho Chehab | a98f6af | 2009-07-19 10:45:49 -0300 | [diff] [blame] | 951 | * ac97_set_ctrl() |
| 952 | * set values for ac97 mute and volume |
Mauro Carvalho Chehab | 195a4ef | 2007-11-11 13:17:17 -0300 | [diff] [blame] | 953 | */ |
Mauro Carvalho Chehab | a98f6af | 2009-07-19 10:45:49 -0300 | [diff] [blame] | 954 | static int ac97_set_ctrl(struct em28xx *dev, const struct v4l2_control *ctrl) |
Mauro Carvalho Chehab | 195a4ef | 2007-11-11 13:17:17 -0300 | [diff] [blame] | 955 | { |
Mauro Carvalho Chehab | a98f6af | 2009-07-19 10:45:49 -0300 | [diff] [blame] | 956 | int i; |
| 957 | |
| 958 | for (i = 0; i < ARRAY_SIZE(ac97_qctrl); i++) |
| 959 | if (ctrl->id == ac97_qctrl[i].id) |
| 960 | goto handle; |
| 961 | |
| 962 | /* Announce that hasn't handle it */ |
| 963 | return 1; |
| 964 | |
| 965 | handle: |
| 966 | if (ctrl->value < ac97_qctrl[i].minimum || |
| 967 | ctrl->value > ac97_qctrl[i].maximum) |
| 968 | return -ERANGE; |
| 969 | |
Mauro Carvalho Chehab | 195a4ef | 2007-11-11 13:17:17 -0300 | [diff] [blame] | 970 | switch (ctrl->id) { |
| 971 | case V4L2_CID_AUDIO_MUTE: |
Mauro Carvalho Chehab | a98f6af | 2009-07-19 10:45:49 -0300 | [diff] [blame] | 972 | dev->mute = ctrl->value; |
| 973 | break; |
Mauro Carvalho Chehab | 195a4ef | 2007-11-11 13:17:17 -0300 | [diff] [blame] | 974 | case V4L2_CID_AUDIO_VOLUME: |
| 975 | dev->volume = ctrl->value; |
Mauro Carvalho Chehab | a98f6af | 2009-07-19 10:45:49 -0300 | [diff] [blame] | 976 | break; |
Mauro Carvalho Chehab | 195a4ef | 2007-11-11 13:17:17 -0300 | [diff] [blame] | 977 | } |
Mauro Carvalho Chehab | a98f6af | 2009-07-19 10:45:49 -0300 | [diff] [blame] | 978 | |
| 979 | return em28xx_audio_analog_set(dev); |
Mauro Carvalho Chehab | 195a4ef | 2007-11-11 13:17:17 -0300 | [diff] [blame] | 980 | } |
| 981 | |
Mauro Carvalho Chehab | 195a4ef | 2007-11-11 13:17:17 -0300 | [diff] [blame] | 982 | static int check_dev(struct em28xx *dev) |
| 983 | { |
| 984 | if (dev->state & DEV_DISCONNECTED) { |
| 985 | em28xx_errdev("v4l2 ioctl: device not present\n"); |
| 986 | return -ENODEV; |
| 987 | } |
| 988 | |
| 989 | if (dev->state & DEV_MISCONFIGURED) { |
| 990 | em28xx_errdev("v4l2 ioctl: device is misconfigured; " |
| 991 | "close and open it again\n"); |
| 992 | return -EIO; |
| 993 | } |
| 994 | return 0; |
| 995 | } |
| 996 | |
| 997 | static void get_scale(struct em28xx *dev, |
| 998 | unsigned int width, unsigned int height, |
| 999 | unsigned int *hscale, unsigned int *vscale) |
| 1000 | { |
Mauro Carvalho Chehab | 5569996 | 2009-07-13 20:15:02 -0300 | [diff] [blame] | 1001 | unsigned int maxw = norm_maxw(dev); |
| 1002 | unsigned int maxh = norm_maxh(dev); |
Mauro Carvalho Chehab | 195a4ef | 2007-11-11 13:17:17 -0300 | [diff] [blame] | 1003 | |
| 1004 | *hscale = (((unsigned long)maxw) << 12) / width - 4096L; |
| 1005 | if (*hscale >= 0x4000) |
| 1006 | *hscale = 0x3fff; |
| 1007 | |
| 1008 | *vscale = (((unsigned long)maxh) << 12) / height - 4096L; |
| 1009 | if (*vscale >= 0x4000) |
| 1010 | *vscale = 0x3fff; |
| 1011 | } |
| 1012 | |
| 1013 | /* ------------------------------------------------------------------ |
| 1014 | IOCTL vidioc handling |
| 1015 | ------------------------------------------------------------------*/ |
| 1016 | |
Hans Verkuil | 78b526a | 2008-05-28 12:16:41 -0300 | [diff] [blame] | 1017 | 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] | 1018 | struct v4l2_format *f) |
| 1019 | { |
| 1020 | struct em28xx_fh *fh = priv; |
| 1021 | struct em28xx *dev = fh->dev; |
| 1022 | |
Mauro Carvalho Chehab | 195a4ef | 2007-11-11 13:17:17 -0300 | [diff] [blame] | 1023 | f->fmt.pix.width = dev->width; |
| 1024 | f->fmt.pix.height = dev->height; |
Mauro Carvalho Chehab | bddcf63 | 2008-12-20 09:06:37 -0300 | [diff] [blame] | 1025 | f->fmt.pix.pixelformat = dev->format->fourcc; |
| 1026 | f->fmt.pix.bytesperline = (dev->width * dev->format->depth + 7) >> 3; |
Mauro Carvalho Chehab | 44dc733 | 2008-04-13 15:11:08 -0300 | [diff] [blame] | 1027 | f->fmt.pix.sizeimage = f->fmt.pix.bytesperline * dev->height; |
Mauro Carvalho Chehab | 195a4ef | 2007-11-11 13:17:17 -0300 | [diff] [blame] | 1028 | f->fmt.pix.colorspace = V4L2_COLORSPACE_SMPTE170M; |
| 1029 | |
| 1030 | /* FIXME: TOP? NONE? BOTTOM? ALTENATE? */ |
Mauro Carvalho Chehab | c2a6b54 | 2009-08-08 03:14:55 -0300 | [diff] [blame] | 1031 | if (dev->progressive) |
| 1032 | f->fmt.pix.field = V4L2_FIELD_NONE; |
| 1033 | else |
| 1034 | f->fmt.pix.field = dev->interlaced ? |
Mauro Carvalho Chehab | 195a4ef | 2007-11-11 13:17:17 -0300 | [diff] [blame] | 1035 | V4L2_FIELD_INTERLACED : V4L2_FIELD_TOP; |
Mauro Carvalho Chehab | 195a4ef | 2007-11-11 13:17:17 -0300 | [diff] [blame] | 1036 | return 0; |
| 1037 | } |
| 1038 | |
Mauro Carvalho Chehab | bddcf63 | 2008-12-20 09:06:37 -0300 | [diff] [blame] | 1039 | static struct em28xx_fmt *format_by_fourcc(unsigned int fourcc) |
| 1040 | { |
| 1041 | unsigned int i; |
| 1042 | |
| 1043 | for (i = 0; i < ARRAY_SIZE(format); i++) |
| 1044 | if (format[i].fourcc == fourcc) |
| 1045 | return &format[i]; |
| 1046 | |
| 1047 | return NULL; |
| 1048 | } |
| 1049 | |
Hans Verkuil | 78b526a | 2008-05-28 12:16:41 -0300 | [diff] [blame] | 1050 | 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] | 1051 | struct v4l2_format *f) |
| 1052 | { |
| 1053 | struct em28xx_fh *fh = priv; |
| 1054 | struct em28xx *dev = fh->dev; |
Trent Piepho | ccb8340 | 2009-05-30 21:45:46 -0300 | [diff] [blame] | 1055 | unsigned int width = f->fmt.pix.width; |
| 1056 | unsigned int height = f->fmt.pix.height; |
Mauro Carvalho Chehab | 195a4ef | 2007-11-11 13:17:17 -0300 | [diff] [blame] | 1057 | unsigned int maxw = norm_maxw(dev); |
| 1058 | unsigned int maxh = norm_maxh(dev); |
| 1059 | unsigned int hscale, vscale; |
Mauro Carvalho Chehab | bddcf63 | 2008-12-20 09:06:37 -0300 | [diff] [blame] | 1060 | struct em28xx_fmt *fmt; |
| 1061 | |
| 1062 | fmt = format_by_fourcc(f->fmt.pix.pixelformat); |
| 1063 | if (!fmt) { |
| 1064 | em28xx_videodbg("Fourcc format (%08x) invalid.\n", |
| 1065 | f->fmt.pix.pixelformat); |
| 1066 | return -EINVAL; |
| 1067 | } |
Mauro Carvalho Chehab | 195a4ef | 2007-11-11 13:17:17 -0300 | [diff] [blame] | 1068 | |
Mauro Carvalho Chehab | 5569996 | 2009-07-13 20:15:02 -0300 | [diff] [blame] | 1069 | if (dev->board.is_em2800) { |
Mauro Carvalho Chehab | 195a4ef | 2007-11-11 13:17:17 -0300 | [diff] [blame] | 1070 | /* the em2800 can only scale down to 50% */ |
Trent Piepho | ccb8340 | 2009-05-30 21:45:46 -0300 | [diff] [blame] | 1071 | height = height > (3 * maxh / 4) ? maxh : maxh / 2; |
| 1072 | width = width > (3 * maxw / 4) ? maxw : maxw / 2; |
Trent Piepho | ccb8340 | 2009-05-30 21:45:46 -0300 | [diff] [blame] | 1073 | } else { |
| 1074 | /* width must even because of the YUYV format |
| 1075 | height must be even because of interlacing */ |
Devin Heitmueller | e3ba4d3 | 2009-09-15 00:18:06 -0300 | [diff] [blame] | 1076 | v4l_bound_align_image(&width, 48, maxw, 1, &height, 32, maxh, |
| 1077 | 1, 0); |
Mauro Carvalho Chehab | 195a4ef | 2007-11-11 13:17:17 -0300 | [diff] [blame] | 1078 | } |
| 1079 | |
| 1080 | get_scale(dev, width, height, &hscale, &vscale); |
| 1081 | |
| 1082 | width = (((unsigned long)maxw) << 12) / (hscale + 4096L); |
| 1083 | height = (((unsigned long)maxh) << 12) / (vscale + 4096L); |
| 1084 | |
| 1085 | f->fmt.pix.width = width; |
| 1086 | f->fmt.pix.height = height; |
Mauro Carvalho Chehab | bddcf63 | 2008-12-20 09:06:37 -0300 | [diff] [blame] | 1087 | f->fmt.pix.pixelformat = fmt->fourcc; |
| 1088 | f->fmt.pix.bytesperline = (dev->width * fmt->depth + 7) >> 3; |
| 1089 | f->fmt.pix.sizeimage = f->fmt.pix.bytesperline * height; |
Mauro Carvalho Chehab | 195a4ef | 2007-11-11 13:17:17 -0300 | [diff] [blame] | 1090 | f->fmt.pix.colorspace = V4L2_COLORSPACE_SMPTE170M; |
Mauro Carvalho Chehab | c2a6b54 | 2009-08-08 03:14:55 -0300 | [diff] [blame] | 1091 | if (dev->progressive) |
| 1092 | f->fmt.pix.field = V4L2_FIELD_NONE; |
| 1093 | else |
| 1094 | f->fmt.pix.field = dev->interlaced ? |
| 1095 | V4L2_FIELD_INTERLACED : V4L2_FIELD_TOP; |
Mauro Carvalho Chehab | 195a4ef | 2007-11-11 13:17:17 -0300 | [diff] [blame] | 1096 | |
Mauro Carvalho Chehab | 195a4ef | 2007-11-11 13:17:17 -0300 | [diff] [blame] | 1097 | return 0; |
| 1098 | } |
| 1099 | |
Mauro Carvalho Chehab | ed5f143 | 2009-07-02 17:34:04 -0300 | [diff] [blame] | 1100 | static int em28xx_set_video_format(struct em28xx *dev, unsigned int fourcc, |
| 1101 | unsigned width, unsigned height) |
| 1102 | { |
| 1103 | struct em28xx_fmt *fmt; |
| 1104 | |
Mauro Carvalho Chehab | ed5f143 | 2009-07-02 17:34:04 -0300 | [diff] [blame] | 1105 | fmt = format_by_fourcc(fourcc); |
| 1106 | if (!fmt) |
| 1107 | return -EINVAL; |
| 1108 | |
| 1109 | dev->format = fmt; |
| 1110 | dev->width = width; |
| 1111 | dev->height = height; |
| 1112 | |
| 1113 | /* set new image size */ |
| 1114 | get_scale(dev, dev->width, dev->height, &dev->hscale, &dev->vscale); |
| 1115 | |
| 1116 | em28xx_set_alternate(dev); |
| 1117 | em28xx_resolution_set(dev); |
| 1118 | |
| 1119 | return 0; |
| 1120 | } |
| 1121 | |
Hans Verkuil | 78b526a | 2008-05-28 12:16:41 -0300 | [diff] [blame] | 1122 | 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] | 1123 | struct v4l2_format *f) |
| 1124 | { |
| 1125 | struct em28xx_fh *fh = priv; |
| 1126 | struct em28xx *dev = fh->dev; |
Mauro Carvalho Chehab | ad0ebb9 | 2008-04-13 14:37:52 -0300 | [diff] [blame] | 1127 | int rc; |
Mauro Carvalho Chehab | 195a4ef | 2007-11-11 13:17:17 -0300 | [diff] [blame] | 1128 | |
| 1129 | rc = check_dev(dev); |
| 1130 | if (rc < 0) |
| 1131 | return rc; |
| 1132 | |
Mauro Carvalho Chehab | efc52a9 | 2008-12-16 22:04:56 -0300 | [diff] [blame] | 1133 | vidioc_try_fmt_vid_cap(file, priv, f); |
| 1134 | |
Brandon Philips | 0561297 | 2008-04-13 14:57:01 -0300 | [diff] [blame] | 1135 | if (videobuf_queue_is_busy(&fh->vb_vidq)) { |
| 1136 | em28xx_errdev("%s queue busy\n", __func__); |
Hans Verkuil | 0499a5a | 2010-09-26 07:34:45 -0300 | [diff] [blame] | 1137 | return -EBUSY; |
Brandon Philips | 0561297 | 2008-04-13 14:57:01 -0300 | [diff] [blame] | 1138 | } |
| 1139 | |
Hans Verkuil | 0499a5a | 2010-09-26 07:34:45 -0300 | [diff] [blame] | 1140 | return em28xx_set_video_format(dev, f->fmt.pix.pixelformat, |
Mauro Carvalho Chehab | ed5f143 | 2009-07-02 17:34:04 -0300 | [diff] [blame] | 1141 | f->fmt.pix.width, f->fmt.pix.height); |
Mauro Carvalho Chehab | 195a4ef | 2007-11-11 13:17:17 -0300 | [diff] [blame] | 1142 | } |
| 1143 | |
Devin Heitmueller | 19bf003 | 2009-09-11 00:40:18 -0300 | [diff] [blame] | 1144 | static int vidioc_g_std(struct file *file, void *priv, v4l2_std_id *norm) |
| 1145 | { |
| 1146 | struct em28xx_fh *fh = priv; |
| 1147 | struct em28xx *dev = fh->dev; |
Devin Heitmueller | 19bf003 | 2009-09-11 00:40:18 -0300 | [diff] [blame] | 1148 | int rc; |
| 1149 | |
| 1150 | rc = check_dev(dev); |
| 1151 | if (rc < 0) |
| 1152 | return rc; |
| 1153 | |
| 1154 | *norm = dev->norm; |
| 1155 | |
| 1156 | return 0; |
| 1157 | } |
| 1158 | |
Mauro Carvalho Chehab | d56ae6f | 2011-10-04 09:53:00 -0300 | [diff] [blame] | 1159 | static int vidioc_querystd(struct file *file, void *priv, v4l2_std_id *norm) |
| 1160 | { |
| 1161 | struct em28xx_fh *fh = priv; |
| 1162 | struct em28xx *dev = fh->dev; |
| 1163 | int rc; |
| 1164 | |
| 1165 | rc = check_dev(dev); |
| 1166 | if (rc < 0) |
| 1167 | return rc; |
| 1168 | |
| 1169 | v4l2_device_call_all(&dev->v4l2_dev, 0, video, querystd, norm); |
| 1170 | |
| 1171 | return 0; |
| 1172 | } |
| 1173 | |
Nicola Soranzo | a1a6ee7 | 2009-02-10 23:28:24 -0300 | [diff] [blame] | 1174 | 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] | 1175 | { |
| 1176 | struct em28xx_fh *fh = priv; |
| 1177 | struct em28xx *dev = fh->dev; |
| 1178 | struct v4l2_format f; |
Mauro Carvalho Chehab | 195a4ef | 2007-11-11 13:17:17 -0300 | [diff] [blame] | 1179 | int rc; |
| 1180 | |
| 1181 | rc = check_dev(dev); |
| 1182 | if (rc < 0) |
| 1183 | return rc; |
| 1184 | |
Mauro Carvalho Chehab | 7d497f8 | 2007-11-11 14:15:34 -0300 | [diff] [blame] | 1185 | dev->norm = *norm; |
Mauro Carvalho Chehab | 195a4ef | 2007-11-11 13:17:17 -0300 | [diff] [blame] | 1186 | |
| 1187 | /* Adjusts width/height, if needed */ |
| 1188 | f.fmt.pix.width = dev->width; |
| 1189 | f.fmt.pix.height = dev->height; |
Hans Verkuil | 78b526a | 2008-05-28 12:16:41 -0300 | [diff] [blame] | 1190 | vidioc_try_fmt_vid_cap(file, priv, &f); |
Mauro Carvalho Chehab | 195a4ef | 2007-11-11 13:17:17 -0300 | [diff] [blame] | 1191 | |
Mauro Carvalho Chehab | 195a4ef | 2007-11-11 13:17:17 -0300 | [diff] [blame] | 1192 | /* set new image size */ |
| 1193 | dev->width = f.fmt.pix.width; |
| 1194 | dev->height = f.fmt.pix.height; |
Mauro Carvalho Chehab | 195a4ef | 2007-11-11 13:17:17 -0300 | [diff] [blame] | 1195 | get_scale(dev, dev->width, dev->height, &dev->hscale, &dev->vscale); |
| 1196 | |
| 1197 | em28xx_resolution_set(dev); |
Hans Verkuil | f41737e | 2009-04-01 03:52:39 -0300 | [diff] [blame] | 1198 | 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] | 1199 | |
Mauro Carvalho Chehab | 195a4ef | 2007-11-11 13:17:17 -0300 | [diff] [blame] | 1200 | return 0; |
| 1201 | } |
| 1202 | |
Mauro Carvalho Chehab | d96ecda | 2009-08-06 21:53:59 -0300 | [diff] [blame] | 1203 | static int vidioc_g_parm(struct file *file, void *priv, |
| 1204 | struct v4l2_streamparm *p) |
| 1205 | { |
| 1206 | struct em28xx_fh *fh = priv; |
| 1207 | struct em28xx *dev = fh->dev; |
| 1208 | int rc = 0; |
| 1209 | |
| 1210 | if (p->type != V4L2_BUF_TYPE_VIDEO_CAPTURE) |
| 1211 | return -EINVAL; |
| 1212 | |
| 1213 | if (dev->board.is_webcam) |
| 1214 | rc = v4l2_device_call_until_err(&dev->v4l2_dev, 0, |
| 1215 | video, g_parm, p); |
| 1216 | else |
| 1217 | v4l2_video_std_frame_period(dev->norm, |
| 1218 | &p->parm.capture.timeperframe); |
| 1219 | |
| 1220 | return rc; |
| 1221 | } |
| 1222 | |
| 1223 | static int vidioc_s_parm(struct file *file, void *priv, |
| 1224 | struct v4l2_streamparm *p) |
| 1225 | { |
| 1226 | struct em28xx_fh *fh = priv; |
| 1227 | struct em28xx *dev = fh->dev; |
| 1228 | |
| 1229 | if (!dev->board.is_webcam) |
| 1230 | return -EINVAL; |
| 1231 | |
| 1232 | if (p->type != V4L2_BUF_TYPE_VIDEO_CAPTURE) |
| 1233 | return -EINVAL; |
| 1234 | |
| 1235 | return v4l2_device_call_until_err(&dev->v4l2_dev, 0, video, s_parm, p); |
| 1236 | } |
| 1237 | |
Mauro Carvalho Chehab | 195a4ef | 2007-11-11 13:17:17 -0300 | [diff] [blame] | 1238 | static const char *iname[] = { |
| 1239 | [EM28XX_VMUX_COMPOSITE1] = "Composite1", |
| 1240 | [EM28XX_VMUX_COMPOSITE2] = "Composite2", |
| 1241 | [EM28XX_VMUX_COMPOSITE3] = "Composite3", |
| 1242 | [EM28XX_VMUX_COMPOSITE4] = "Composite4", |
| 1243 | [EM28XX_VMUX_SVIDEO] = "S-Video", |
| 1244 | [EM28XX_VMUX_TELEVISION] = "Television", |
| 1245 | [EM28XX_VMUX_CABLE] = "Cable TV", |
| 1246 | [EM28XX_VMUX_DVB] = "DVB", |
| 1247 | [EM28XX_VMUX_DEBUG] = "for debug only", |
| 1248 | }; |
| 1249 | |
| 1250 | static int vidioc_enum_input(struct file *file, void *priv, |
| 1251 | struct v4l2_input *i) |
| 1252 | { |
| 1253 | struct em28xx_fh *fh = priv; |
| 1254 | struct em28xx *dev = fh->dev; |
| 1255 | unsigned int n; |
| 1256 | |
| 1257 | n = i->index; |
| 1258 | if (n >= MAX_EM28XX_INPUT) |
| 1259 | return -EINVAL; |
| 1260 | if (0 == INPUT(n)->type) |
| 1261 | return -EINVAL; |
| 1262 | |
| 1263 | i->index = n; |
| 1264 | i->type = V4L2_INPUT_TYPE_CAMERA; |
| 1265 | |
| 1266 | strcpy(i->name, iname[INPUT(n)->type]); |
| 1267 | |
| 1268 | if ((EM28XX_VMUX_TELEVISION == INPUT(n)->type) || |
| 1269 | (EM28XX_VMUX_CABLE == INPUT(n)->type)) |
| 1270 | i->type = V4L2_INPUT_TYPE_TUNER; |
| 1271 | |
Mauro Carvalho Chehab | 7d497f8 | 2007-11-11 14:15:34 -0300 | [diff] [blame] | 1272 | i->std = dev->vdev->tvnorms; |
Mauro Carvalho Chehab | 195a4ef | 2007-11-11 13:17:17 -0300 | [diff] [blame] | 1273 | |
| 1274 | return 0; |
| 1275 | } |
| 1276 | |
| 1277 | static int vidioc_g_input(struct file *file, void *priv, unsigned int *i) |
| 1278 | { |
| 1279 | struct em28xx_fh *fh = priv; |
| 1280 | struct em28xx *dev = fh->dev; |
| 1281 | |
| 1282 | *i = dev->ctl_input; |
| 1283 | |
| 1284 | return 0; |
| 1285 | } |
| 1286 | |
| 1287 | static int vidioc_s_input(struct file *file, void *priv, unsigned int i) |
| 1288 | { |
| 1289 | struct em28xx_fh *fh = priv; |
| 1290 | struct em28xx *dev = fh->dev; |
| 1291 | int rc; |
| 1292 | |
| 1293 | rc = check_dev(dev); |
| 1294 | if (rc < 0) |
| 1295 | return rc; |
| 1296 | |
| 1297 | if (i >= MAX_EM28XX_INPUT) |
| 1298 | return -EINVAL; |
| 1299 | if (0 == INPUT(i)->type) |
| 1300 | return -EINVAL; |
| 1301 | |
Mauro Carvalho Chehab | 24c3c41 | 2009-01-07 22:49:25 -0300 | [diff] [blame] | 1302 | dev->ctl_input = i; |
| 1303 | |
Mauro Carvalho Chehab | 24c3c41 | 2009-01-07 22:49:25 -0300 | [diff] [blame] | 1304 | video_mux(dev, dev->ctl_input); |
Mauro Carvalho Chehab | 195a4ef | 2007-11-11 13:17:17 -0300 | [diff] [blame] | 1305 | return 0; |
| 1306 | } |
| 1307 | |
| 1308 | static int vidioc_g_audio(struct file *file, void *priv, struct v4l2_audio *a) |
| 1309 | { |
| 1310 | struct em28xx_fh *fh = priv; |
| 1311 | struct em28xx *dev = fh->dev; |
Mauro Carvalho Chehab | 195a4ef | 2007-11-11 13:17:17 -0300 | [diff] [blame] | 1312 | |
Mauro Carvalho Chehab | 6c428b5 | 2009-08-04 19:52:37 -0300 | [diff] [blame] | 1313 | if (!dev->audio_mode.has_audio) |
| 1314 | return -EINVAL; |
| 1315 | |
Mauro Carvalho Chehab | 35ae6f0 | 2008-11-20 12:40:51 -0300 | [diff] [blame] | 1316 | switch (a->index) { |
| 1317 | case EM28XX_AMUX_VIDEO: |
Mauro Carvalho Chehab | 195a4ef | 2007-11-11 13:17:17 -0300 | [diff] [blame] | 1318 | strcpy(a->name, "Television"); |
Mauro Carvalho Chehab | 35ae6f0 | 2008-11-20 12:40:51 -0300 | [diff] [blame] | 1319 | break; |
| 1320 | case EM28XX_AMUX_LINE_IN: |
Mauro Carvalho Chehab | 195a4ef | 2007-11-11 13:17:17 -0300 | [diff] [blame] | 1321 | strcpy(a->name, "Line In"); |
Mauro Carvalho Chehab | 35ae6f0 | 2008-11-20 12:40:51 -0300 | [diff] [blame] | 1322 | break; |
| 1323 | case EM28XX_AMUX_VIDEO2: |
| 1324 | strcpy(a->name, "Television alt"); |
| 1325 | break; |
| 1326 | case EM28XX_AMUX_PHONE: |
| 1327 | strcpy(a->name, "Phone"); |
| 1328 | break; |
| 1329 | case EM28XX_AMUX_MIC: |
| 1330 | strcpy(a->name, "Mic"); |
| 1331 | break; |
| 1332 | case EM28XX_AMUX_CD: |
| 1333 | strcpy(a->name, "CD"); |
| 1334 | break; |
| 1335 | case EM28XX_AMUX_AUX: |
| 1336 | strcpy(a->name, "Aux"); |
| 1337 | break; |
| 1338 | case EM28XX_AMUX_PCM_OUT: |
| 1339 | strcpy(a->name, "PCM"); |
| 1340 | break; |
| 1341 | default: |
| 1342 | return -EINVAL; |
| 1343 | } |
Douglas Schilling Landgraf | 6ea54d9 | 2008-04-17 21:41:10 -0300 | [diff] [blame] | 1344 | |
Mauro Carvalho Chehab | 35ae6f0 | 2008-11-20 12:40:51 -0300 | [diff] [blame] | 1345 | a->index = dev->ctl_ainput; |
Mauro Carvalho Chehab | 195a4ef | 2007-11-11 13:17:17 -0300 | [diff] [blame] | 1346 | a->capability = V4L2_AUDCAP_STEREO; |
Mauro Carvalho Chehab | 195a4ef | 2007-11-11 13:17:17 -0300 | [diff] [blame] | 1347 | |
| 1348 | return 0; |
| 1349 | } |
| 1350 | |
| 1351 | static int vidioc_s_audio(struct file *file, void *priv, struct v4l2_audio *a) |
| 1352 | { |
| 1353 | struct em28xx_fh *fh = priv; |
| 1354 | struct em28xx *dev = fh->dev; |
| 1355 | |
Mauro Carvalho Chehab | 24c3c41 | 2009-01-07 22:49:25 -0300 | [diff] [blame] | 1356 | |
Mauro Carvalho Chehab | 6c428b5 | 2009-08-04 19:52:37 -0300 | [diff] [blame] | 1357 | if (!dev->audio_mode.has_audio) |
| 1358 | return -EINVAL; |
| 1359 | |
Mauro Carvalho Chehab | 24c3c41 | 2009-01-07 22:49:25 -0300 | [diff] [blame] | 1360 | if (a->index >= MAX_EM28XX_INPUT) |
| 1361 | return -EINVAL; |
| 1362 | if (0 == INPUT(a->index)->type) |
| 1363 | return -EINVAL; |
| 1364 | |
Mauro Carvalho Chehab | 35ae6f0 | 2008-11-20 12:40:51 -0300 | [diff] [blame] | 1365 | dev->ctl_ainput = INPUT(a->index)->amux; |
| 1366 | dev->ctl_aoutput = INPUT(a->index)->aout; |
Mauro Carvalho Chehab | e879b8e | 2008-11-20 13:39:39 -0300 | [diff] [blame] | 1367 | |
| 1368 | if (!dev->ctl_aoutput) |
| 1369 | dev->ctl_aoutput = EM28XX_AOUT_MASTER; |
Mauro Carvalho Chehab | efc52a9 | 2008-12-16 22:04:56 -0300 | [diff] [blame] | 1370 | |
Mauro Carvalho Chehab | 195a4ef | 2007-11-11 13:17:17 -0300 | [diff] [blame] | 1371 | return 0; |
| 1372 | } |
| 1373 | |
| 1374 | static int vidioc_queryctrl(struct file *file, void *priv, |
| 1375 | struct v4l2_queryctrl *qc) |
| 1376 | { |
| 1377 | struct em28xx_fh *fh = priv; |
| 1378 | struct em28xx *dev = fh->dev; |
| 1379 | int id = qc->id; |
Mauro Carvalho Chehab | 195a4ef | 2007-11-11 13:17:17 -0300 | [diff] [blame] | 1380 | int rc; |
| 1381 | |
| 1382 | rc = check_dev(dev); |
| 1383 | if (rc < 0) |
| 1384 | return rc; |
| 1385 | |
| 1386 | memset(qc, 0, sizeof(*qc)); |
| 1387 | |
| 1388 | qc->id = id; |
| 1389 | |
Hans Verkuil | 0499a5a | 2010-09-26 07:34:45 -0300 | [diff] [blame] | 1390 | /* enumerate AC97 controls */ |
Mauro Carvalho Chehab | a98f6af | 2009-07-19 10:45:49 -0300 | [diff] [blame] | 1391 | if (dev->audio_mode.ac97 != EM28XX_NO_AC97) { |
| 1392 | rc = ac97_queryctrl(qc); |
| 1393 | if (!rc) |
| 1394 | return 0; |
Mauro Carvalho Chehab | 195a4ef | 2007-11-11 13:17:17 -0300 | [diff] [blame] | 1395 | } |
Douglas Schilling Landgraf | f2cf250 | 2009-03-31 17:10:58 -0300 | [diff] [blame] | 1396 | |
Hans Verkuil | 0499a5a | 2010-09-26 07:34:45 -0300 | [diff] [blame] | 1397 | /* enumerate V4L2 device controls */ |
Douglas Schilling Landgraf | f2cf250 | 2009-03-31 17:10:58 -0300 | [diff] [blame] | 1398 | v4l2_device_call_all(&dev->v4l2_dev, 0, core, queryctrl, qc); |
Mauro Carvalho Chehab | 195a4ef | 2007-11-11 13:17:17 -0300 | [diff] [blame] | 1399 | |
| 1400 | if (qc->type) |
| 1401 | return 0; |
| 1402 | else |
| 1403 | return -EINVAL; |
| 1404 | } |
| 1405 | |
Mauro Carvalho Chehab | fb8decf | 2011-02-22 01:00:58 -0300 | [diff] [blame] | 1406 | /* |
| 1407 | * FIXME: This is an indirect way to check if a control exists at a |
| 1408 | * subdev. Instead of that hack, maybe the better would be to change all |
| 1409 | * subdevs to return -ENOIOCTLCMD, if an ioctl is not supported. |
| 1410 | */ |
| 1411 | static int check_subdev_ctrl(struct em28xx *dev, int id) |
| 1412 | { |
| 1413 | struct v4l2_queryctrl qc; |
| 1414 | |
| 1415 | memset(&qc, 0, sizeof(qc)); |
| 1416 | qc.id = id; |
| 1417 | |
| 1418 | /* enumerate V4L2 device controls */ |
| 1419 | v4l2_device_call_all(&dev->v4l2_dev, 0, core, queryctrl, &qc); |
| 1420 | |
| 1421 | if (qc.type) |
| 1422 | return 0; |
| 1423 | else |
| 1424 | return -EINVAL; |
| 1425 | } |
| 1426 | |
Mauro Carvalho Chehab | 195a4ef | 2007-11-11 13:17:17 -0300 | [diff] [blame] | 1427 | static int vidioc_g_ctrl(struct file *file, void *priv, |
| 1428 | struct v4l2_control *ctrl) |
| 1429 | { |
| 1430 | struct em28xx_fh *fh = priv; |
| 1431 | struct em28xx *dev = fh->dev; |
| 1432 | int rc; |
| 1433 | |
| 1434 | rc = check_dev(dev); |
| 1435 | if (rc < 0) |
| 1436 | return rc; |
Mauro Carvalho Chehab | b6070f0 | 2008-12-22 06:20:32 -0300 | [diff] [blame] | 1437 | rc = 0; |
Mauro Carvalho Chehab | efc52a9 | 2008-12-16 22:04:56 -0300 | [diff] [blame] | 1438 | |
Mauro Carvalho Chehab | a98f6af | 2009-07-19 10:45:49 -0300 | [diff] [blame] | 1439 | /* Set an AC97 control */ |
| 1440 | if (dev->audio_mode.ac97 != EM28XX_NO_AC97) |
| 1441 | rc = ac97_get_ctrl(dev, ctrl); |
| 1442 | else |
| 1443 | rc = 1; |
| 1444 | |
| 1445 | /* It were not an AC97 control. Sends it to the v4l2 dev interface */ |
| 1446 | if (rc == 1) { |
Mauro Carvalho Chehab | fb8decf | 2011-02-22 01:00:58 -0300 | [diff] [blame] | 1447 | if (check_subdev_ctrl(dev, ctrl->id)) |
| 1448 | return -EINVAL; |
| 1449 | |
Douglas Schilling Landgraf | f2cf250 | 2009-03-31 17:10:58 -0300 | [diff] [blame] | 1450 | v4l2_device_call_all(&dev->v4l2_dev, 0, core, g_ctrl, ctrl); |
Mauro Carvalho Chehab | a98f6af | 2009-07-19 10:45:49 -0300 | [diff] [blame] | 1451 | rc = 0; |
Hans Verkuil | 07f7db4 | 2009-01-21 17:06:42 -0300 | [diff] [blame] | 1452 | } |
Mauro Carvalho Chehab | 195a4ef | 2007-11-11 13:17:17 -0300 | [diff] [blame] | 1453 | |
Mauro Carvalho Chehab | 195a4ef | 2007-11-11 13:17:17 -0300 | [diff] [blame] | 1454 | return rc; |
| 1455 | } |
| 1456 | |
| 1457 | static int vidioc_s_ctrl(struct file *file, void *priv, |
| 1458 | struct v4l2_control *ctrl) |
| 1459 | { |
| 1460 | struct em28xx_fh *fh = priv; |
| 1461 | struct em28xx *dev = fh->dev; |
Mauro Carvalho Chehab | 195a4ef | 2007-11-11 13:17:17 -0300 | [diff] [blame] | 1462 | int rc; |
| 1463 | |
| 1464 | rc = check_dev(dev); |
| 1465 | if (rc < 0) |
| 1466 | return rc; |
| 1467 | |
Mauro Carvalho Chehab | a98f6af | 2009-07-19 10:45:49 -0300 | [diff] [blame] | 1468 | /* Set an AC97 control */ |
| 1469 | if (dev->audio_mode.ac97 != EM28XX_NO_AC97) |
| 1470 | rc = ac97_set_ctrl(dev, ctrl); |
| 1471 | else |
Mauro Carvalho Chehab | 195a4ef | 2007-11-11 13:17:17 -0300 | [diff] [blame] | 1472 | rc = 1; |
Mauro Carvalho Chehab | 195a4ef | 2007-11-11 13:17:17 -0300 | [diff] [blame] | 1473 | |
Mauro Carvalho Chehab | 73c6f46 | 2009-07-29 01:42:02 -0300 | [diff] [blame] | 1474 | /* It isn't an AC97 control. Sends it to the v4l2 dev interface */ |
Mauro Carvalho Chehab | 195a4ef | 2007-11-11 13:17:17 -0300 | [diff] [blame] | 1475 | if (rc == 1) { |
Mauro Carvalho Chehab | fb8decf | 2011-02-22 01:00:58 -0300 | [diff] [blame] | 1476 | rc = check_subdev_ctrl(dev, ctrl->id); |
| 1477 | if (!rc) |
| 1478 | v4l2_device_call_all(&dev->v4l2_dev, 0, |
| 1479 | core, s_ctrl, ctrl); |
Mauro Carvalho Chehab | 73c6f46 | 2009-07-29 01:42:02 -0300 | [diff] [blame] | 1480 | /* |
| 1481 | * In the case of non-AC97 volume controls, we still need |
| 1482 | * to do some setups at em28xx, in order to mute/unmute |
| 1483 | * and to adjust audio volume. However, the value ranges |
| 1484 | * should be checked by the corresponding V4L subdriver. |
| 1485 | */ |
| 1486 | switch (ctrl->id) { |
| 1487 | case V4L2_CID_AUDIO_MUTE: |
| 1488 | dev->mute = ctrl->value; |
| 1489 | rc = em28xx_audio_analog_set(dev); |
| 1490 | break; |
| 1491 | case V4L2_CID_AUDIO_VOLUME: |
| 1492 | dev->volume = ctrl->value; |
| 1493 | rc = em28xx_audio_analog_set(dev); |
| 1494 | } |
Mauro Carvalho Chehab | 195a4ef | 2007-11-11 13:17:17 -0300 | [diff] [blame] | 1495 | } |
Mauro Carvalho Chehab | 78e5156 | 2011-02-22 00:27:41 -0300 | [diff] [blame] | 1496 | return (rc < 0) ? rc : 0; |
Mauro Carvalho Chehab | 195a4ef | 2007-11-11 13:17:17 -0300 | [diff] [blame] | 1497 | } |
| 1498 | |
| 1499 | static int vidioc_g_tuner(struct file *file, void *priv, |
| 1500 | struct v4l2_tuner *t) |
| 1501 | { |
| 1502 | struct em28xx_fh *fh = priv; |
| 1503 | struct em28xx *dev = fh->dev; |
| 1504 | int rc; |
| 1505 | |
| 1506 | rc = check_dev(dev); |
| 1507 | if (rc < 0) |
| 1508 | return rc; |
| 1509 | |
| 1510 | if (0 != t->index) |
| 1511 | return -EINVAL; |
| 1512 | |
| 1513 | strcpy(t->name, "Tuner"); |
Hans Verkuil | 0eed42e | 2010-05-01 18:06:50 -0300 | [diff] [blame] | 1514 | t->type = V4L2_TUNER_ANALOG_TV; |
Mauro Carvalho Chehab | 195a4ef | 2007-11-11 13:17:17 -0300 | [diff] [blame] | 1515 | |
Douglas Schilling Landgraf | f2cf250 | 2009-03-31 17:10:58 -0300 | [diff] [blame] | 1516 | 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] | 1517 | return 0; |
| 1518 | } |
| 1519 | |
| 1520 | static int vidioc_s_tuner(struct file *file, void *priv, |
| 1521 | struct v4l2_tuner *t) |
| 1522 | { |
| 1523 | struct em28xx_fh *fh = priv; |
| 1524 | struct em28xx *dev = fh->dev; |
| 1525 | int rc; |
| 1526 | |
| 1527 | rc = check_dev(dev); |
| 1528 | if (rc < 0) |
| 1529 | return rc; |
| 1530 | |
| 1531 | if (0 != t->index) |
| 1532 | return -EINVAL; |
| 1533 | |
Douglas Schilling Landgraf | f2cf250 | 2009-03-31 17:10:58 -0300 | [diff] [blame] | 1534 | 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] | 1535 | return 0; |
| 1536 | } |
| 1537 | |
| 1538 | static int vidioc_g_frequency(struct file *file, void *priv, |
| 1539 | struct v4l2_frequency *f) |
| 1540 | { |
| 1541 | struct em28xx_fh *fh = priv; |
| 1542 | struct em28xx *dev = fh->dev; |
| 1543 | |
Mauro Carvalho Chehab | 0be4375 | 2008-01-05 17:22:01 -0300 | [diff] [blame] | 1544 | f->type = fh->radio ? V4L2_TUNER_RADIO : V4L2_TUNER_ANALOG_TV; |
Mauro Carvalho Chehab | 195a4ef | 2007-11-11 13:17:17 -0300 | [diff] [blame] | 1545 | f->frequency = dev->ctl_freq; |
Mauro Carvalho Chehab | 195a4ef | 2007-11-11 13:17:17 -0300 | [diff] [blame] | 1546 | return 0; |
| 1547 | } |
| 1548 | |
| 1549 | static int vidioc_s_frequency(struct file *file, void *priv, |
| 1550 | struct v4l2_frequency *f) |
| 1551 | { |
| 1552 | struct em28xx_fh *fh = priv; |
| 1553 | struct em28xx *dev = fh->dev; |
| 1554 | int rc; |
| 1555 | |
| 1556 | rc = check_dev(dev); |
| 1557 | if (rc < 0) |
| 1558 | return rc; |
| 1559 | |
| 1560 | if (0 != f->tuner) |
| 1561 | return -EINVAL; |
| 1562 | |
Mauro Carvalho Chehab | 0be4375 | 2008-01-05 17:22:01 -0300 | [diff] [blame] | 1563 | if (unlikely(0 == fh->radio && f->type != V4L2_TUNER_ANALOG_TV)) |
| 1564 | return -EINVAL; |
| 1565 | if (unlikely(1 == fh->radio && f->type != V4L2_TUNER_RADIO)) |
Mauro Carvalho Chehab | 195a4ef | 2007-11-11 13:17:17 -0300 | [diff] [blame] | 1566 | return -EINVAL; |
| 1567 | |
Mauro Carvalho Chehab | 195a4ef | 2007-11-11 13:17:17 -0300 | [diff] [blame] | 1568 | dev->ctl_freq = f->frequency; |
Douglas Schilling Landgraf | f2cf250 | 2009-03-31 17:10:58 -0300 | [diff] [blame] | 1569 | 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] | 1570 | |
Mauro Carvalho Chehab | 195a4ef | 2007-11-11 13:17:17 -0300 | [diff] [blame] | 1571 | return 0; |
| 1572 | } |
| 1573 | |
Mauro Carvalho Chehab | 1e7ad56 | 2008-02-06 09:00:41 -0300 | [diff] [blame] | 1574 | #ifdef CONFIG_VIDEO_ADV_DEBUG |
| 1575 | static int em28xx_reg_len(int reg) |
| 1576 | { |
| 1577 | switch (reg) { |
Mauro Carvalho Chehab | 41facaa | 2008-04-17 21:44:58 -0300 | [diff] [blame] | 1578 | case EM28XX_R40_AC97LSB: |
| 1579 | case EM28XX_R30_HSCALELOW: |
| 1580 | case EM28XX_R32_VSCALELOW: |
Mauro Carvalho Chehab | 1e7ad56 | 2008-02-06 09:00:41 -0300 | [diff] [blame] | 1581 | return 2; |
| 1582 | default: |
| 1583 | return 1; |
| 1584 | } |
| 1585 | } |
| 1586 | |
Mauro Carvalho Chehab | 14983d8 | 2008-12-22 20:58:41 -0300 | [diff] [blame] | 1587 | static int vidioc_g_chip_ident(struct file *file, void *priv, |
Hans Verkuil | aecde8b5 | 2008-12-30 07:14:19 -0300 | [diff] [blame] | 1588 | struct v4l2_dbg_chip_ident *chip) |
Mauro Carvalho Chehab | 14983d8 | 2008-12-22 20:58:41 -0300 | [diff] [blame] | 1589 | { |
| 1590 | struct em28xx_fh *fh = priv; |
| 1591 | struct em28xx *dev = fh->dev; |
| 1592 | |
| 1593 | chip->ident = V4L2_IDENT_NONE; |
| 1594 | chip->revision = 0; |
| 1595 | |
Douglas Schilling Landgraf | f2cf250 | 2009-03-31 17:10:58 -0300 | [diff] [blame] | 1596 | 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] | 1597 | |
| 1598 | return 0; |
| 1599 | } |
| 1600 | |
| 1601 | |
Mauro Carvalho Chehab | 1e7ad56 | 2008-02-06 09:00:41 -0300 | [diff] [blame] | 1602 | static int vidioc_g_register(struct file *file, void *priv, |
Hans Verkuil | aecde8b5 | 2008-12-30 07:14:19 -0300 | [diff] [blame] | 1603 | struct v4l2_dbg_register *reg) |
Mauro Carvalho Chehab | 1e7ad56 | 2008-02-06 09:00:41 -0300 | [diff] [blame] | 1604 | { |
| 1605 | struct em28xx_fh *fh = priv; |
| 1606 | struct em28xx *dev = fh->dev; |
| 1607 | int ret; |
| 1608 | |
Hans Verkuil | aecde8b5 | 2008-12-30 07:14:19 -0300 | [diff] [blame] | 1609 | switch (reg->match.type) { |
Mauro Carvalho Chehab | 14983d8 | 2008-12-22 20:58:41 -0300 | [diff] [blame] | 1610 | case V4L2_CHIP_MATCH_AC97: |
Mauro Carvalho Chehab | 531c98e | 2008-12-22 13:18:27 -0300 | [diff] [blame] | 1611 | ret = em28xx_read_ac97(dev, reg->reg); |
Mauro Carvalho Chehab | 531c98e | 2008-12-22 13:18:27 -0300 | [diff] [blame] | 1612 | if (ret < 0) |
| 1613 | return ret; |
| 1614 | |
| 1615 | reg->val = ret; |
Hans Verkuil | aecde8b5 | 2008-12-30 07:14:19 -0300 | [diff] [blame] | 1616 | reg->size = 1; |
Mauro Carvalho Chehab | 531c98e | 2008-12-22 13:18:27 -0300 | [diff] [blame] | 1617 | return 0; |
Mauro Carvalho Chehab | 14983d8 | 2008-12-22 20:58:41 -0300 | [diff] [blame] | 1618 | case V4L2_CHIP_MATCH_I2C_DRIVER: |
Douglas Schilling Landgraf | f2cf250 | 2009-03-31 17:10:58 -0300 | [diff] [blame] | 1619 | 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] | 1620 | return 0; |
| 1621 | case V4L2_CHIP_MATCH_I2C_ADDR: |
Mauro Carvalho Chehab | 4efa2d7 | 2009-08-09 19:39:23 -0300 | [diff] [blame] | 1622 | /* TODO: is this correct? */ |
| 1623 | v4l2_device_call_all(&dev->v4l2_dev, 0, core, g_register, reg); |
| 1624 | return 0; |
Mauro Carvalho Chehab | 14983d8 | 2008-12-22 20:58:41 -0300 | [diff] [blame] | 1625 | default: |
Hans Verkuil | aecde8b5 | 2008-12-30 07:14:19 -0300 | [diff] [blame] | 1626 | if (!v4l2_chip_match_host(®->match)) |
Mauro Carvalho Chehab | 14983d8 | 2008-12-22 20:58:41 -0300 | [diff] [blame] | 1627 | return -EINVAL; |
Mauro Carvalho Chehab | 531c98e | 2008-12-22 13:18:27 -0300 | [diff] [blame] | 1628 | } |
| 1629 | |
Mauro Carvalho Chehab | 14983d8 | 2008-12-22 20:58:41 -0300 | [diff] [blame] | 1630 | /* Match host */ |
Hans Verkuil | aecde8b5 | 2008-12-30 07:14:19 -0300 | [diff] [blame] | 1631 | reg->size = em28xx_reg_len(reg->reg); |
| 1632 | if (reg->size == 1) { |
Mauro Carvalho Chehab | 1e7ad56 | 2008-02-06 09:00:41 -0300 | [diff] [blame] | 1633 | ret = em28xx_read_reg(dev, reg->reg); |
Mauro Carvalho Chehab | efc52a9 | 2008-12-16 22:04:56 -0300 | [diff] [blame] | 1634 | |
Mauro Carvalho Chehab | 1e7ad56 | 2008-02-06 09:00:41 -0300 | [diff] [blame] | 1635 | if (ret < 0) |
| 1636 | return ret; |
| 1637 | |
| 1638 | reg->val = ret; |
| 1639 | } else { |
Hans Verkuil | aecde8b5 | 2008-12-30 07:14:19 -0300 | [diff] [blame] | 1640 | __le16 val = 0; |
Mauro Carvalho Chehab | 1e7ad56 | 2008-02-06 09:00:41 -0300 | [diff] [blame] | 1641 | ret = em28xx_read_reg_req_len(dev, USB_REQ_GET_STATUS, |
| 1642 | reg->reg, (char *)&val, 2); |
| 1643 | if (ret < 0) |
| 1644 | return ret; |
| 1645 | |
Hans Verkuil | aecde8b5 | 2008-12-30 07:14:19 -0300 | [diff] [blame] | 1646 | reg->val = le16_to_cpu(val); |
Mauro Carvalho Chehab | 1e7ad56 | 2008-02-06 09:00:41 -0300 | [diff] [blame] | 1647 | } |
| 1648 | |
| 1649 | return 0; |
| 1650 | } |
| 1651 | |
| 1652 | static int vidioc_s_register(struct file *file, void *priv, |
Hans Verkuil | aecde8b5 | 2008-12-30 07:14:19 -0300 | [diff] [blame] | 1653 | struct v4l2_dbg_register *reg) |
Mauro Carvalho Chehab | 1e7ad56 | 2008-02-06 09:00:41 -0300 | [diff] [blame] | 1654 | { |
| 1655 | struct em28xx_fh *fh = priv; |
| 1656 | struct em28xx *dev = fh->dev; |
Hans Verkuil | aecde8b5 | 2008-12-30 07:14:19 -0300 | [diff] [blame] | 1657 | __le16 buf; |
Mauro Carvalho Chehab | 1e7ad56 | 2008-02-06 09:00:41 -0300 | [diff] [blame] | 1658 | |
Hans Verkuil | aecde8b5 | 2008-12-30 07:14:19 -0300 | [diff] [blame] | 1659 | switch (reg->match.type) { |
Mauro Carvalho Chehab | 14983d8 | 2008-12-22 20:58:41 -0300 | [diff] [blame] | 1660 | case V4L2_CHIP_MATCH_AC97: |
Hans Verkuil | 0499a5a | 2010-09-26 07:34:45 -0300 | [diff] [blame] | 1661 | return em28xx_write_ac97(dev, reg->reg, reg->val); |
Mauro Carvalho Chehab | 14983d8 | 2008-12-22 20:58:41 -0300 | [diff] [blame] | 1662 | case V4L2_CHIP_MATCH_I2C_DRIVER: |
Douglas Schilling Landgraf | f2cf250 | 2009-03-31 17:10:58 -0300 | [diff] [blame] | 1663 | 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] | 1664 | return 0; |
| 1665 | case V4L2_CHIP_MATCH_I2C_ADDR: |
Mauro Carvalho Chehab | 4efa2d7 | 2009-08-09 19:39:23 -0300 | [diff] [blame] | 1666 | /* TODO: is this correct? */ |
| 1667 | v4l2_device_call_all(&dev->v4l2_dev, 0, core, s_register, reg); |
| 1668 | return 0; |
Mauro Carvalho Chehab | 14983d8 | 2008-12-22 20:58:41 -0300 | [diff] [blame] | 1669 | default: |
Hans Verkuil | aecde8b5 | 2008-12-30 07:14:19 -0300 | [diff] [blame] | 1670 | if (!v4l2_chip_match_host(®->match)) |
Mauro Carvalho Chehab | 14983d8 | 2008-12-22 20:58:41 -0300 | [diff] [blame] | 1671 | return -EINVAL; |
Mauro Carvalho Chehab | 531c98e | 2008-12-22 13:18:27 -0300 | [diff] [blame] | 1672 | } |
| 1673 | |
Mauro Carvalho Chehab | 14983d8 | 2008-12-22 20:58:41 -0300 | [diff] [blame] | 1674 | /* Match host */ |
Hans Verkuil | aecde8b5 | 2008-12-30 07:14:19 -0300 | [diff] [blame] | 1675 | buf = cpu_to_le16(reg->val); |
Mauro Carvalho Chehab | 1e7ad56 | 2008-02-06 09:00:41 -0300 | [diff] [blame] | 1676 | |
Hans Verkuil | 0499a5a | 2010-09-26 07:34:45 -0300 | [diff] [blame] | 1677 | return em28xx_write_regs(dev, reg->reg, (char *)&buf, |
Mauro Carvalho Chehab | efc52a9 | 2008-12-16 22:04:56 -0300 | [diff] [blame] | 1678 | em28xx_reg_len(reg->reg)); |
Mauro Carvalho Chehab | 1e7ad56 | 2008-02-06 09:00:41 -0300 | [diff] [blame] | 1679 | } |
| 1680 | #endif |
| 1681 | |
| 1682 | |
Mauro Carvalho Chehab | 195a4ef | 2007-11-11 13:17:17 -0300 | [diff] [blame] | 1683 | static int vidioc_cropcap(struct file *file, void *priv, |
| 1684 | struct v4l2_cropcap *cc) |
| 1685 | { |
| 1686 | struct em28xx_fh *fh = priv; |
| 1687 | struct em28xx *dev = fh->dev; |
| 1688 | |
| 1689 | if (cc->type != V4L2_BUF_TYPE_VIDEO_CAPTURE) |
| 1690 | return -EINVAL; |
| 1691 | |
| 1692 | cc->bounds.left = 0; |
| 1693 | cc->bounds.top = 0; |
| 1694 | cc->bounds.width = dev->width; |
| 1695 | cc->bounds.height = dev->height; |
| 1696 | cc->defrect = cc->bounds; |
| 1697 | cc->pixelaspect.numerator = 54; /* 4:3 FIXME: remove magic numbers */ |
| 1698 | cc->pixelaspect.denominator = 59; |
| 1699 | |
| 1700 | return 0; |
| 1701 | } |
| 1702 | |
| 1703 | static int vidioc_streamon(struct file *file, void *priv, |
| 1704 | enum v4l2_buf_type type) |
| 1705 | { |
| 1706 | struct em28xx_fh *fh = priv; |
| 1707 | struct em28xx *dev = fh->dev; |
Devin Heitmueller | 8c873d3 | 2009-09-03 00:23:27 -0300 | [diff] [blame] | 1708 | int rc = -EINVAL; |
Mauro Carvalho Chehab | 195a4ef | 2007-11-11 13:17:17 -0300 | [diff] [blame] | 1709 | |
| 1710 | rc = check_dev(dev); |
| 1711 | if (rc < 0) |
| 1712 | return rc; |
| 1713 | |
Devin Heitmueller | 8c873d3 | 2009-09-03 00:23:27 -0300 | [diff] [blame] | 1714 | if (unlikely(type != fh->type)) |
| 1715 | return -EINVAL; |
Mauro Carvalho Chehab | 195a4ef | 2007-11-11 13:17:17 -0300 | [diff] [blame] | 1716 | |
Devin Heitmueller | 8c873d3 | 2009-09-03 00:23:27 -0300 | [diff] [blame] | 1717 | em28xx_videodbg("vidioc_streamon fh=%p t=%d fh->res=%d dev->res=%d\n", |
| 1718 | fh, type, fh->resources, dev->resources); |
Mauro Carvalho Chehab | 29b5941 | 2008-12-16 20:19:24 -0300 | [diff] [blame] | 1719 | |
Devin Heitmueller | e3ba4d3 | 2009-09-15 00:18:06 -0300 | [diff] [blame] | 1720 | if (unlikely(!res_get(fh, get_ressource(fh)))) |
Devin Heitmueller | 8c873d3 | 2009-09-03 00:23:27 -0300 | [diff] [blame] | 1721 | return -EBUSY; |
Mauro Carvalho Chehab | efc52a9 | 2008-12-16 22:04:56 -0300 | [diff] [blame] | 1722 | |
Devin Heitmueller | 8c873d3 | 2009-09-03 00:23:27 -0300 | [diff] [blame] | 1723 | if (fh->type == V4L2_BUF_TYPE_VIDEO_CAPTURE) |
| 1724 | rc = videobuf_streamon(&fh->vb_vidq); |
| 1725 | else if (fh->type == V4L2_BUF_TYPE_VBI_CAPTURE) |
| 1726 | rc = videobuf_streamon(&fh->vb_vbiq); |
Mauro Carvalho Chehab | efc52a9 | 2008-12-16 22:04:56 -0300 | [diff] [blame] | 1727 | |
| 1728 | return rc; |
Mauro Carvalho Chehab | 195a4ef | 2007-11-11 13:17:17 -0300 | [diff] [blame] | 1729 | } |
| 1730 | |
| 1731 | static int vidioc_streamoff(struct file *file, void *priv, |
| 1732 | enum v4l2_buf_type type) |
| 1733 | { |
| 1734 | struct em28xx_fh *fh = priv; |
| 1735 | struct em28xx *dev = fh->dev; |
| 1736 | int rc; |
| 1737 | |
| 1738 | rc = check_dev(dev); |
| 1739 | if (rc < 0) |
| 1740 | return rc; |
| 1741 | |
Devin Heitmueller | 28abf083 | 2009-09-01 01:54:54 -0300 | [diff] [blame] | 1742 | if (fh->type != V4L2_BUF_TYPE_VIDEO_CAPTURE && |
| 1743 | fh->type != V4L2_BUF_TYPE_VBI_CAPTURE) |
Mauro Carvalho Chehab | ad0ebb9 | 2008-04-13 14:37:52 -0300 | [diff] [blame] | 1744 | return -EINVAL; |
| 1745 | if (type != fh->type) |
Mauro Carvalho Chehab | 195a4ef | 2007-11-11 13:17:17 -0300 | [diff] [blame] | 1746 | return -EINVAL; |
| 1747 | |
Devin Heitmueller | 8c873d3 | 2009-09-03 00:23:27 -0300 | [diff] [blame] | 1748 | em28xx_videodbg("vidioc_streamoff fh=%p t=%d fh->res=%d dev->res=%d\n", |
| 1749 | fh, type, fh->resources, dev->resources); |
Mauro Carvalho Chehab | efc52a9 | 2008-12-16 22:04:56 -0300 | [diff] [blame] | 1750 | |
Devin Heitmueller | 8c873d3 | 2009-09-03 00:23:27 -0300 | [diff] [blame] | 1751 | if (fh->type == V4L2_BUF_TYPE_VIDEO_CAPTURE) { |
Hans Verkuil | 3ea2b67 | 2010-12-29 14:28:13 -0300 | [diff] [blame] | 1752 | if (res_check(fh, EM28XX_RESOURCE_VIDEO)) { |
| 1753 | videobuf_streamoff(&fh->vb_vidq); |
| 1754 | res_free(fh, EM28XX_RESOURCE_VIDEO); |
| 1755 | } |
Devin Heitmueller | 8c873d3 | 2009-09-03 00:23:27 -0300 | [diff] [blame] | 1756 | } else if (fh->type == V4L2_BUF_TYPE_VBI_CAPTURE) { |
Hans Verkuil | 3ea2b67 | 2010-12-29 14:28:13 -0300 | [diff] [blame] | 1757 | if (res_check(fh, EM28XX_RESOURCE_VBI)) { |
| 1758 | videobuf_streamoff(&fh->vb_vbiq); |
| 1759 | res_free(fh, EM28XX_RESOURCE_VBI); |
| 1760 | } |
Devin Heitmueller | 8c873d3 | 2009-09-03 00:23:27 -0300 | [diff] [blame] | 1761 | } |
Mauro Carvalho Chehab | 195a4ef | 2007-11-11 13:17:17 -0300 | [diff] [blame] | 1762 | |
Mauro Carvalho Chehab | 195a4ef | 2007-11-11 13:17:17 -0300 | [diff] [blame] | 1763 | return 0; |
| 1764 | } |
| 1765 | |
| 1766 | static int vidioc_querycap(struct file *file, void *priv, |
| 1767 | struct v4l2_capability *cap) |
| 1768 | { |
| 1769 | struct em28xx_fh *fh = priv; |
| 1770 | struct em28xx *dev = fh->dev; |
| 1771 | |
| 1772 | strlcpy(cap->driver, "em28xx", sizeof(cap->driver)); |
| 1773 | strlcpy(cap->card, em28xx_boards[dev->model].name, sizeof(cap->card)); |
Thierry MERLE | cb97716 | 2009-01-20 18:01:33 -0300 | [diff] [blame] | 1774 | 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] | 1775 | |
Mauro Carvalho Chehab | 195a4ef | 2007-11-11 13:17:17 -0300 | [diff] [blame] | 1776 | cap->capabilities = |
| 1777 | V4L2_CAP_SLICED_VBI_CAPTURE | |
| 1778 | V4L2_CAP_VIDEO_CAPTURE | |
Mauro Carvalho Chehab | 195a4ef | 2007-11-11 13:17:17 -0300 | [diff] [blame] | 1779 | V4L2_CAP_READWRITE | V4L2_CAP_STREAMING; |
| 1780 | |
Devin Heitmueller | 0414614 | 2009-09-11 00:08:44 -0300 | [diff] [blame] | 1781 | if (dev->vbi_dev) |
| 1782 | cap->capabilities |= V4L2_CAP_VBI_CAPTURE; |
| 1783 | |
Mauro Carvalho Chehab | 6c428b5 | 2009-08-04 19:52:37 -0300 | [diff] [blame] | 1784 | if (dev->audio_mode.has_audio) |
| 1785 | cap->capabilities |= V4L2_CAP_AUDIO; |
| 1786 | |
Mauro Carvalho Chehab | ed08631 | 2008-01-24 06:59:20 -0300 | [diff] [blame] | 1787 | if (dev->tuner_type != TUNER_ABSENT) |
Mauro Carvalho Chehab | 195a4ef | 2007-11-11 13:17:17 -0300 | [diff] [blame] | 1788 | cap->capabilities |= V4L2_CAP_TUNER; |
| 1789 | |
| 1790 | return 0; |
| 1791 | } |
| 1792 | |
Hans Verkuil | 78b526a | 2008-05-28 12:16:41 -0300 | [diff] [blame] | 1793 | 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] | 1794 | struct v4l2_fmtdesc *f) |
Mauro Carvalho Chehab | 195a4ef | 2007-11-11 13:17:17 -0300 | [diff] [blame] | 1795 | { |
Mauro Carvalho Chehab | bddcf63 | 2008-12-20 09:06:37 -0300 | [diff] [blame] | 1796 | if (unlikely(f->index >= ARRAY_SIZE(format))) |
Mauro Carvalho Chehab | 195a4ef | 2007-11-11 13:17:17 -0300 | [diff] [blame] | 1797 | return -EINVAL; |
| 1798 | |
Mauro Carvalho Chehab | bddcf63 | 2008-12-20 09:06:37 -0300 | [diff] [blame] | 1799 | strlcpy(f->description, format[f->index].name, sizeof(f->description)); |
| 1800 | f->pixelformat = format[f->index].fourcc; |
Mauro Carvalho Chehab | 195a4ef | 2007-11-11 13:17:17 -0300 | [diff] [blame] | 1801 | |
| 1802 | return 0; |
| 1803 | } |
| 1804 | |
Mauro Carvalho Chehab | 1c5c506 | 2011-10-16 13:52:43 -0200 | [diff] [blame^] | 1805 | static int vidioc_enum_framesizes(struct file *file, void *priv, |
| 1806 | struct v4l2_frmsizeenum *fsize) |
| 1807 | { |
| 1808 | struct em28xx_fh *fh = priv; |
| 1809 | struct em28xx *dev = fh->dev; |
| 1810 | struct em28xx_fmt *fmt; |
| 1811 | unsigned int maxw = norm_maxw(dev); |
| 1812 | unsigned int maxh = norm_maxh(dev); |
| 1813 | |
| 1814 | fmt = format_by_fourcc(fsize->pixel_format); |
| 1815 | if (!fmt) { |
| 1816 | em28xx_videodbg("Fourcc format (%08x) invalid.\n", |
| 1817 | fsize->pixel_format); |
| 1818 | return -EINVAL; |
| 1819 | } |
| 1820 | |
| 1821 | if (dev->board.is_em2800) { |
| 1822 | if (fsize->index > 1) |
| 1823 | return -EINVAL; |
| 1824 | fsize->type = V4L2_FRMSIZE_TYPE_DISCRETE; |
| 1825 | fsize->discrete.width = maxw / (1 + fsize->index); |
| 1826 | fsize->discrete.height = maxh / (1 + fsize->index); |
| 1827 | return 0; |
| 1828 | } |
| 1829 | |
| 1830 | if (fsize->index != 0) |
| 1831 | return -EINVAL; |
| 1832 | |
| 1833 | /* Report a continuous range */ |
| 1834 | fsize->type = V4L2_FRMSIZE_TYPE_STEPWISE; |
| 1835 | fsize->stepwise.min_width = 48; |
| 1836 | fsize->stepwise.min_height = 32; |
| 1837 | fsize->stepwise.max_width = maxw; |
| 1838 | fsize->stepwise.max_height = maxh; |
| 1839 | fsize->stepwise.step_width = 1; |
| 1840 | fsize->stepwise.step_height = 1; |
| 1841 | return 0; |
| 1842 | } |
| 1843 | |
Mauro Carvalho Chehab | 195a4ef | 2007-11-11 13:17:17 -0300 | [diff] [blame] | 1844 | /* Sliced VBI ioctls */ |
Hans Verkuil | 78b526a | 2008-05-28 12:16:41 -0300 | [diff] [blame] | 1845 | 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] | 1846 | struct v4l2_format *f) |
| 1847 | { |
| 1848 | struct em28xx_fh *fh = priv; |
| 1849 | struct em28xx *dev = fh->dev; |
| 1850 | int rc; |
| 1851 | |
| 1852 | rc = check_dev(dev); |
| 1853 | if (rc < 0) |
| 1854 | return rc; |
| 1855 | |
Mauro Carvalho Chehab | 195a4ef | 2007-11-11 13:17:17 -0300 | [diff] [blame] | 1856 | f->fmt.sliced.service_set = 0; |
Hans Verkuil | 4a61ecb | 2010-03-14 12:39:27 -0300 | [diff] [blame] | 1857 | v4l2_device_call_all(&dev->v4l2_dev, 0, vbi, g_sliced_fmt, &f->fmt.sliced); |
Mauro Carvalho Chehab | 195a4ef | 2007-11-11 13:17:17 -0300 | [diff] [blame] | 1858 | |
| 1859 | if (f->fmt.sliced.service_set == 0) |
| 1860 | rc = -EINVAL; |
| 1861 | |
Mauro Carvalho Chehab | 195a4ef | 2007-11-11 13:17:17 -0300 | [diff] [blame] | 1862 | return rc; |
| 1863 | } |
| 1864 | |
Hans Verkuil | 78b526a | 2008-05-28 12:16:41 -0300 | [diff] [blame] | 1865 | 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] | 1866 | struct v4l2_format *f) |
| 1867 | { |
| 1868 | struct em28xx_fh *fh = priv; |
| 1869 | struct em28xx *dev = fh->dev; |
| 1870 | int rc; |
| 1871 | |
| 1872 | rc = check_dev(dev); |
| 1873 | if (rc < 0) |
| 1874 | return rc; |
| 1875 | |
Hans Verkuil | 4a61ecb | 2010-03-14 12:39:27 -0300 | [diff] [blame] | 1876 | v4l2_device_call_all(&dev->v4l2_dev, 0, vbi, g_sliced_fmt, &f->fmt.sliced); |
Mauro Carvalho Chehab | 195a4ef | 2007-11-11 13:17:17 -0300 | [diff] [blame] | 1877 | |
| 1878 | if (f->fmt.sliced.service_set == 0) |
| 1879 | return -EINVAL; |
| 1880 | |
| 1881 | return 0; |
| 1882 | } |
| 1883 | |
Devin Heitmueller | 28abf083 | 2009-09-01 01:54:54 -0300 | [diff] [blame] | 1884 | /* RAW VBI ioctls */ |
| 1885 | |
| 1886 | static int vidioc_g_fmt_vbi_cap(struct file *file, void *priv, |
| 1887 | struct v4l2_format *format) |
| 1888 | { |
Devin Heitmueller | 66d9cba | 2009-11-24 23:17:25 -0300 | [diff] [blame] | 1889 | struct em28xx_fh *fh = priv; |
| 1890 | struct em28xx *dev = fh->dev; |
| 1891 | |
| 1892 | format->fmt.vbi.samples_per_line = dev->vbi_width; |
Devin Heitmueller | 28abf083 | 2009-09-01 01:54:54 -0300 | [diff] [blame] | 1893 | format->fmt.vbi.sample_format = V4L2_PIX_FMT_GREY; |
| 1894 | format->fmt.vbi.offset = 0; |
| 1895 | format->fmt.vbi.flags = 0; |
Devin Heitmueller | 66d9cba | 2009-11-24 23:17:25 -0300 | [diff] [blame] | 1896 | format->fmt.vbi.sampling_rate = 6750000 * 4 / 2; |
| 1897 | format->fmt.vbi.count[0] = dev->vbi_height; |
| 1898 | format->fmt.vbi.count[1] = dev->vbi_height; |
Devin Heitmueller | 28abf083 | 2009-09-01 01:54:54 -0300 | [diff] [blame] | 1899 | |
| 1900 | /* Varies by video standard (NTSC, PAL, etc.) */ |
Devin Heitmueller | 66d9cba | 2009-11-24 23:17:25 -0300 | [diff] [blame] | 1901 | if (dev->norm & V4L2_STD_525_60) { |
| 1902 | /* NTSC */ |
| 1903 | format->fmt.vbi.start[0] = 10; |
| 1904 | format->fmt.vbi.start[1] = 273; |
| 1905 | } else if (dev->norm & V4L2_STD_625_50) { |
| 1906 | /* PAL */ |
| 1907 | format->fmt.vbi.start[0] = 6; |
| 1908 | format->fmt.vbi.start[1] = 318; |
| 1909 | } |
Devin Heitmueller | 28abf083 | 2009-09-01 01:54:54 -0300 | [diff] [blame] | 1910 | |
| 1911 | return 0; |
| 1912 | } |
| 1913 | |
| 1914 | static int vidioc_s_fmt_vbi_cap(struct file *file, void *priv, |
| 1915 | struct v4l2_format *format) |
| 1916 | { |
Devin Heitmueller | 66d9cba | 2009-11-24 23:17:25 -0300 | [diff] [blame] | 1917 | struct em28xx_fh *fh = priv; |
| 1918 | struct em28xx *dev = fh->dev; |
| 1919 | |
| 1920 | format->fmt.vbi.samples_per_line = dev->vbi_width; |
Devin Heitmueller | 28abf083 | 2009-09-01 01:54:54 -0300 | [diff] [blame] | 1921 | format->fmt.vbi.sample_format = V4L2_PIX_FMT_GREY; |
| 1922 | format->fmt.vbi.offset = 0; |
| 1923 | format->fmt.vbi.flags = 0; |
Devin Heitmueller | 66d9cba | 2009-11-24 23:17:25 -0300 | [diff] [blame] | 1924 | format->fmt.vbi.sampling_rate = 6750000 * 4 / 2; |
| 1925 | format->fmt.vbi.count[0] = dev->vbi_height; |
| 1926 | format->fmt.vbi.count[1] = dev->vbi_height; |
Devin Heitmueller | 28abf083 | 2009-09-01 01:54:54 -0300 | [diff] [blame] | 1927 | |
| 1928 | /* Varies by video standard (NTSC, PAL, etc.) */ |
Devin Heitmueller | 66d9cba | 2009-11-24 23:17:25 -0300 | [diff] [blame] | 1929 | if (dev->norm & V4L2_STD_525_60) { |
| 1930 | /* NTSC */ |
| 1931 | format->fmt.vbi.start[0] = 10; |
| 1932 | format->fmt.vbi.start[1] = 273; |
| 1933 | } else if (dev->norm & V4L2_STD_625_50) { |
| 1934 | /* PAL */ |
| 1935 | format->fmt.vbi.start[0] = 6; |
| 1936 | format->fmt.vbi.start[1] = 318; |
| 1937 | } |
Devin Heitmueller | 28abf083 | 2009-09-01 01:54:54 -0300 | [diff] [blame] | 1938 | |
| 1939 | return 0; |
| 1940 | } |
Mauro Carvalho Chehab | 195a4ef | 2007-11-11 13:17:17 -0300 | [diff] [blame] | 1941 | |
| 1942 | static int vidioc_reqbufs(struct file *file, void *priv, |
| 1943 | struct v4l2_requestbuffers *rb) |
| 1944 | { |
| 1945 | struct em28xx_fh *fh = priv; |
| 1946 | struct em28xx *dev = fh->dev; |
Mauro Carvalho Chehab | 195a4ef | 2007-11-11 13:17:17 -0300 | [diff] [blame] | 1947 | int rc; |
| 1948 | |
| 1949 | rc = check_dev(dev); |
| 1950 | if (rc < 0) |
| 1951 | return rc; |
| 1952 | |
Devin Heitmueller | 28abf083 | 2009-09-01 01:54:54 -0300 | [diff] [blame] | 1953 | if (fh->type == V4L2_BUF_TYPE_VIDEO_CAPTURE) |
| 1954 | return videobuf_reqbufs(&fh->vb_vidq, rb); |
| 1955 | else |
| 1956 | return videobuf_reqbufs(&fh->vb_vbiq, rb); |
Mauro Carvalho Chehab | 195a4ef | 2007-11-11 13:17:17 -0300 | [diff] [blame] | 1957 | } |
| 1958 | |
| 1959 | static int vidioc_querybuf(struct file *file, void *priv, |
| 1960 | struct v4l2_buffer *b) |
| 1961 | { |
| 1962 | struct em28xx_fh *fh = priv; |
| 1963 | struct em28xx *dev = fh->dev; |
| 1964 | int rc; |
| 1965 | |
| 1966 | rc = check_dev(dev); |
| 1967 | if (rc < 0) |
| 1968 | return rc; |
| 1969 | |
Devin Heitmueller | 28abf083 | 2009-09-01 01:54:54 -0300 | [diff] [blame] | 1970 | if (fh->type == V4L2_BUF_TYPE_VIDEO_CAPTURE) |
| 1971 | return videobuf_querybuf(&fh->vb_vidq, b); |
| 1972 | else { |
| 1973 | /* FIXME: I'm not sure yet whether this is a bug in zvbi or |
| 1974 | the videobuf framework, but we probably shouldn't be |
| 1975 | returning a buffer larger than that which was asked for. |
| 1976 | At a minimum, it causes a crash in zvbi since it does |
| 1977 | a memcpy based on the source buffer length */ |
| 1978 | int result = videobuf_querybuf(&fh->vb_vbiq, b); |
Devin Heitmueller | 66d9cba | 2009-11-24 23:17:25 -0300 | [diff] [blame] | 1979 | b->length = dev->vbi_width * dev->vbi_height * 2; |
| 1980 | |
Devin Heitmueller | 28abf083 | 2009-09-01 01:54:54 -0300 | [diff] [blame] | 1981 | return result; |
| 1982 | } |
Mauro Carvalho Chehab | 195a4ef | 2007-11-11 13:17:17 -0300 | [diff] [blame] | 1983 | } |
| 1984 | |
| 1985 | static int vidioc_qbuf(struct file *file, void *priv, struct v4l2_buffer *b) |
| 1986 | { |
| 1987 | struct em28xx_fh *fh = priv; |
| 1988 | struct em28xx *dev = fh->dev; |
Mauro Carvalho Chehab | 195a4ef | 2007-11-11 13:17:17 -0300 | [diff] [blame] | 1989 | int rc; |
| 1990 | |
| 1991 | rc = check_dev(dev); |
| 1992 | if (rc < 0) |
| 1993 | return rc; |
| 1994 | |
Devin Heitmueller | 28abf083 | 2009-09-01 01:54:54 -0300 | [diff] [blame] | 1995 | if (fh->type == V4L2_BUF_TYPE_VIDEO_CAPTURE) |
| 1996 | return videobuf_qbuf(&fh->vb_vidq, b); |
Devin Heitmueller | e3ba4d3 | 2009-09-15 00:18:06 -0300 | [diff] [blame] | 1997 | else |
Devin Heitmueller | 28abf083 | 2009-09-01 01:54:54 -0300 | [diff] [blame] | 1998 | return videobuf_qbuf(&fh->vb_vbiq, b); |
Mauro Carvalho Chehab | 195a4ef | 2007-11-11 13:17:17 -0300 | [diff] [blame] | 1999 | } |
| 2000 | |
| 2001 | static int vidioc_dqbuf(struct file *file, void *priv, struct v4l2_buffer *b) |
| 2002 | { |
| 2003 | struct em28xx_fh *fh = priv; |
| 2004 | struct em28xx *dev = fh->dev; |
| 2005 | int rc; |
Mauro Carvalho Chehab | 195a4ef | 2007-11-11 13:17:17 -0300 | [diff] [blame] | 2006 | |
| 2007 | rc = check_dev(dev); |
| 2008 | if (rc < 0) |
| 2009 | return rc; |
| 2010 | |
Devin Heitmueller | 28abf083 | 2009-09-01 01:54:54 -0300 | [diff] [blame] | 2011 | if (fh->type == V4L2_BUF_TYPE_VIDEO_CAPTURE) |
| 2012 | return videobuf_dqbuf(&fh->vb_vidq, b, file->f_flags & |
| 2013 | O_NONBLOCK); |
| 2014 | else |
| 2015 | return videobuf_dqbuf(&fh->vb_vbiq, b, file->f_flags & |
| 2016 | O_NONBLOCK); |
Mauro Carvalho Chehab | 195a4ef | 2007-11-11 13:17:17 -0300 | [diff] [blame] | 2017 | } |
| 2018 | |
Mauro Carvalho Chehab | 0be4375 | 2008-01-05 17:22:01 -0300 | [diff] [blame] | 2019 | /* ----------------------------------------------------------- */ |
| 2020 | /* RADIO ESPECIFIC IOCTLS */ |
| 2021 | /* ----------------------------------------------------------- */ |
| 2022 | |
| 2023 | static int radio_querycap(struct file *file, void *priv, |
| 2024 | struct v4l2_capability *cap) |
| 2025 | { |
| 2026 | struct em28xx *dev = ((struct em28xx_fh *)priv)->dev; |
| 2027 | |
| 2028 | strlcpy(cap->driver, "em28xx", sizeof(cap->driver)); |
| 2029 | strlcpy(cap->card, em28xx_boards[dev->model].name, sizeof(cap->card)); |
Thierry MERLE | cb97716 | 2009-01-20 18:01:33 -0300 | [diff] [blame] | 2030 | 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] | 2031 | |
Mauro Carvalho Chehab | 0be4375 | 2008-01-05 17:22:01 -0300 | [diff] [blame] | 2032 | cap->capabilities = V4L2_CAP_TUNER; |
| 2033 | return 0; |
| 2034 | } |
| 2035 | |
| 2036 | static int radio_g_tuner(struct file *file, void *priv, |
| 2037 | struct v4l2_tuner *t) |
| 2038 | { |
| 2039 | struct em28xx *dev = ((struct em28xx_fh *)priv)->dev; |
| 2040 | |
| 2041 | if (unlikely(t->index > 0)) |
| 2042 | return -EINVAL; |
| 2043 | |
| 2044 | strcpy(t->name, "Radio"); |
| 2045 | t->type = V4L2_TUNER_RADIO; |
| 2046 | |
Douglas Schilling Landgraf | f2cf250 | 2009-03-31 17:10:58 -0300 | [diff] [blame] | 2047 | 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] | 2048 | |
Mauro Carvalho Chehab | 0be4375 | 2008-01-05 17:22:01 -0300 | [diff] [blame] | 2049 | return 0; |
| 2050 | } |
| 2051 | |
| 2052 | static int radio_enum_input(struct file *file, void *priv, |
| 2053 | struct v4l2_input *i) |
| 2054 | { |
| 2055 | if (i->index != 0) |
| 2056 | return -EINVAL; |
| 2057 | strcpy(i->name, "Radio"); |
| 2058 | i->type = V4L2_INPUT_TYPE_TUNER; |
| 2059 | |
| 2060 | return 0; |
| 2061 | } |
| 2062 | |
| 2063 | static int radio_g_audio(struct file *file, void *priv, struct v4l2_audio *a) |
| 2064 | { |
| 2065 | if (unlikely(a->index)) |
| 2066 | return -EINVAL; |
| 2067 | |
| 2068 | strcpy(a->name, "Radio"); |
| 2069 | return 0; |
| 2070 | } |
| 2071 | |
| 2072 | static int radio_s_tuner(struct file *file, void *priv, |
| 2073 | struct v4l2_tuner *t) |
| 2074 | { |
| 2075 | struct em28xx *dev = ((struct em28xx_fh *)priv)->dev; |
| 2076 | |
| 2077 | if (0 != t->index) |
| 2078 | return -EINVAL; |
| 2079 | |
Douglas Schilling Landgraf | f2cf250 | 2009-03-31 17:10:58 -0300 | [diff] [blame] | 2080 | v4l2_device_call_all(&dev->v4l2_dev, 0, tuner, s_tuner, t); |
Mauro Carvalho Chehab | 0be4375 | 2008-01-05 17:22:01 -0300 | [diff] [blame] | 2081 | |
| 2082 | return 0; |
| 2083 | } |
| 2084 | |
| 2085 | static int radio_s_audio(struct file *file, void *fh, |
| 2086 | struct v4l2_audio *a) |
| 2087 | { |
| 2088 | return 0; |
| 2089 | } |
| 2090 | |
| 2091 | static int radio_s_input(struct file *file, void *fh, unsigned int i) |
| 2092 | { |
| 2093 | return 0; |
| 2094 | } |
| 2095 | |
| 2096 | static int radio_queryctrl(struct file *file, void *priv, |
| 2097 | struct v4l2_queryctrl *qc) |
| 2098 | { |
| 2099 | int i; |
| 2100 | |
| 2101 | if (qc->id < V4L2_CID_BASE || |
| 2102 | qc->id >= V4L2_CID_LASTP1) |
| 2103 | return -EINVAL; |
| 2104 | |
Mauro Carvalho Chehab | ed10daa | 2009-07-19 09:10:06 -0300 | [diff] [blame] | 2105 | for (i = 0; i < ARRAY_SIZE(ac97_qctrl); i++) { |
| 2106 | if (qc->id && qc->id == ac97_qctrl[i].id) { |
| 2107 | memcpy(qc, &(ac97_qctrl[i]), sizeof(*qc)); |
Mauro Carvalho Chehab | 0be4375 | 2008-01-05 17:22:01 -0300 | [diff] [blame] | 2108 | return 0; |
| 2109 | } |
| 2110 | } |
| 2111 | |
| 2112 | return -EINVAL; |
| 2113 | } |
| 2114 | |
Mauro Carvalho Chehab | 195a4ef | 2007-11-11 13:17:17 -0300 | [diff] [blame] | 2115 | /* |
Mauro Carvalho Chehab | 3acf280 | 2005-11-08 21:38:27 -0800 | [diff] [blame] | 2116 | * em28xx_v4l2_open() |
akpm@osdl.org | a6c2ba2 | 2005-11-08 21:37:07 -0800 | [diff] [blame] | 2117 | * inits the device and starts isoc transfer |
| 2118 | */ |
Hans Verkuil | bec4366 | 2008-12-30 06:58:20 -0300 | [diff] [blame] | 2119 | static int em28xx_v4l2_open(struct file *filp) |
akpm@osdl.org | a6c2ba2 | 2005-11-08 21:37:07 -0800 | [diff] [blame] | 2120 | { |
Laurent Pinchart | 63b0d5a | 2009-12-10 11:44:04 -0200 | [diff] [blame] | 2121 | int errCode = 0, radio = 0; |
| 2122 | struct video_device *vdev = video_devdata(filp); |
| 2123 | struct em28xx *dev = video_drvdata(filp); |
| 2124 | enum v4l2_buf_type fh_type = 0; |
Mauro Carvalho Chehab | a3a048c | 2007-11-10 22:21:01 -0300 | [diff] [blame] | 2125 | struct em28xx_fh *fh; |
Mauro Carvalho Chehab | c2a6b54 | 2009-08-08 03:14:55 -0300 | [diff] [blame] | 2126 | enum v4l2_field field; |
Markus Rechberger | 9c75541 | 2005-11-08 21:37:52 -0800 | [diff] [blame] | 2127 | |
Laurent Pinchart | 63b0d5a | 2009-12-10 11:44:04 -0200 | [diff] [blame] | 2128 | switch (vdev->vfl_type) { |
| 2129 | case VFL_TYPE_GRABBER: |
| 2130 | fh_type = V4L2_BUF_TYPE_VIDEO_CAPTURE; |
| 2131 | break; |
| 2132 | case VFL_TYPE_VBI: |
| 2133 | fh_type = V4L2_BUF_TYPE_VBI_CAPTURE; |
| 2134 | break; |
| 2135 | case VFL_TYPE_RADIO: |
| 2136 | radio = 1; |
| 2137 | break; |
| 2138 | } |
Mauro Carvalho Chehab | 818a557 | 2008-11-20 10:30:26 -0300 | [diff] [blame] | 2139 | |
Laurent Pinchart | 50462eb | 2009-12-10 11:47:13 -0200 | [diff] [blame] | 2140 | em28xx_videodbg("open dev=%s type=%s users=%d\n", |
| 2141 | video_device_node_name(vdev), v4l2_type_names[fh_type], |
| 2142 | dev->users); |
akpm@osdl.org | a6c2ba2 | 2005-11-08 21:37:07 -0800 | [diff] [blame] | 2143 | |
akpm@osdl.org | a6c2ba2 | 2005-11-08 21:37:07 -0800 | [diff] [blame] | 2144 | |
Mauro Carvalho Chehab | c67ec53 | 2008-04-17 21:48:00 -0300 | [diff] [blame] | 2145 | fh = kzalloc(sizeof(struct em28xx_fh), GFP_KERNEL); |
Mauro Carvalho Chehab | a3a048c | 2007-11-10 22:21:01 -0300 | [diff] [blame] | 2146 | if (!fh) { |
| 2147 | em28xx_errdev("em28xx-video.c: Out of memory?!\n"); |
| 2148 | return -ENOMEM; |
akpm@osdl.org | a6c2ba2 | 2005-11-08 21:37:07 -0800 | [diff] [blame] | 2149 | } |
Mauro Carvalho Chehab | a3a048c | 2007-11-10 22:21:01 -0300 | [diff] [blame] | 2150 | fh->dev = dev; |
Mauro Carvalho Chehab | 0be4375 | 2008-01-05 17:22:01 -0300 | [diff] [blame] | 2151 | fh->radio = radio; |
Aidan Thornton | d7aa802 | 2008-04-13 14:38:47 -0300 | [diff] [blame] | 2152 | fh->type = fh_type; |
Mauro Carvalho Chehab | a3a048c | 2007-11-10 22:21:01 -0300 | [diff] [blame] | 2153 | filp->private_data = fh; |
akpm@osdl.org | a6c2ba2 | 2005-11-08 21:37:07 -0800 | [diff] [blame] | 2154 | |
Aidan Thornton | d7aa802 | 2008-04-13 14:38:47 -0300 | [diff] [blame] | 2155 | if (fh->type == V4L2_BUF_TYPE_VIDEO_CAPTURE && dev->users == 0) { |
Mauro Carvalho Chehab | c67ec53 | 2008-04-17 21:48:00 -0300 | [diff] [blame] | 2156 | em28xx_set_mode(dev, EM28XX_ANALOG_MODE); |
Mauro Carvalho Chehab | 3687e1e | 2008-02-08 15:44:25 -0300 | [diff] [blame] | 2157 | em28xx_set_alternate(dev); |
Mauro Carvalho Chehab | e5589be | 2006-01-23 17:11:08 -0200 | [diff] [blame] | 2158 | em28xx_resolution_set(dev); |
akpm@osdl.org | a6c2ba2 | 2005-11-08 21:37:07 -0800 | [diff] [blame] | 2159 | |
Mauro Carvalho Chehab | c67ec53 | 2008-04-17 21:48:00 -0300 | [diff] [blame] | 2160 | /* Needed, since GPIO might have disabled power of |
| 2161 | some i2c device |
| 2162 | */ |
Mauro Carvalho Chehab | 1a23f81 | 2008-12-28 22:18:14 -0300 | [diff] [blame] | 2163 | em28xx_wake_i2c(dev); |
Mauro Carvalho Chehab | c67ec53 | 2008-04-17 21:48:00 -0300 | [diff] [blame] | 2164 | |
Mauro Carvalho Chehab | e5589be | 2006-01-23 17:11:08 -0200 | [diff] [blame] | 2165 | } |
Mauro Carvalho Chehab | 0be4375 | 2008-01-05 17:22:01 -0300 | [diff] [blame] | 2166 | if (fh->radio) { |
| 2167 | em28xx_videodbg("video_open: setting radio device\n"); |
Douglas Schilling Landgraf | f2cf250 | 2009-03-31 17:10:58 -0300 | [diff] [blame] | 2168 | v4l2_device_call_all(&dev->v4l2_dev, 0, tuner, s_radio); |
Mauro Carvalho Chehab | 0be4375 | 2008-01-05 17:22:01 -0300 | [diff] [blame] | 2169 | } |
akpm@osdl.org | a6c2ba2 | 2005-11-08 21:37:07 -0800 | [diff] [blame] | 2170 | |
| 2171 | dev->users++; |
akpm@osdl.org | a6c2ba2 | 2005-11-08 21:37:07 -0800 | [diff] [blame] | 2172 | |
Mauro Carvalho Chehab | c2a6b54 | 2009-08-08 03:14:55 -0300 | [diff] [blame] | 2173 | if (dev->progressive) |
| 2174 | field = V4L2_FIELD_NONE; |
| 2175 | else |
| 2176 | field = V4L2_FIELD_INTERLACED; |
| 2177 | |
Devin Heitmueller | 8c873d3 | 2009-09-03 00:23:27 -0300 | [diff] [blame] | 2178 | videobuf_queue_vmalloc_init(&fh->vb_vidq, &em28xx_video_qops, |
| 2179 | NULL, &dev->slock, |
| 2180 | V4L2_BUF_TYPE_VIDEO_CAPTURE, field, |
Hans Verkuil | 0499a5a | 2010-09-26 07:34:45 -0300 | [diff] [blame] | 2181 | sizeof(struct em28xx_buffer), fh, &dev->lock); |
Devin Heitmueller | 28abf083 | 2009-09-01 01:54:54 -0300 | [diff] [blame] | 2182 | |
Devin Heitmueller | 8c873d3 | 2009-09-03 00:23:27 -0300 | [diff] [blame] | 2183 | videobuf_queue_vmalloc_init(&fh->vb_vbiq, &em28xx_vbi_qops, |
| 2184 | NULL, &dev->slock, |
| 2185 | V4L2_BUF_TYPE_VBI_CAPTURE, |
| 2186 | V4L2_FIELD_SEQ_TB, |
Hans Verkuil | 0499a5a | 2010-09-26 07:34:45 -0300 | [diff] [blame] | 2187 | sizeof(struct em28xx_buffer), fh, &dev->lock); |
Mauro Carvalho Chehab | c67ec53 | 2008-04-17 21:48:00 -0300 | [diff] [blame] | 2188 | |
akpm@osdl.org | a6c2ba2 | 2005-11-08 21:37:07 -0800 | [diff] [blame] | 2189 | return errCode; |
| 2190 | } |
| 2191 | |
| 2192 | /* |
Mauro Carvalho Chehab | 3acf280 | 2005-11-08 21:38:27 -0800 | [diff] [blame] | 2193 | * em28xx_realease_resources() |
akpm@osdl.org | a6c2ba2 | 2005-11-08 21:37:07 -0800 | [diff] [blame] | 2194 | * unregisters the v4l2,i2c and usb devices |
| 2195 | * called when the device gets disconected or at module unload |
| 2196 | */ |
Mauro Carvalho Chehab | 1a23f81 | 2008-12-28 22:18:14 -0300 | [diff] [blame] | 2197 | void em28xx_release_analog_resources(struct em28xx *dev) |
akpm@osdl.org | a6c2ba2 | 2005-11-08 21:37:07 -0800 | [diff] [blame] | 2198 | { |
akpm@osdl.org | a6c2ba2 | 2005-11-08 21:37:07 -0800 | [diff] [blame] | 2199 | |
Mauro Carvalho Chehab | e5589be | 2006-01-23 17:11:08 -0200 | [diff] [blame] | 2200 | /*FIXME: I2C IR should be disconnected */ |
| 2201 | |
Mauro Carvalho Chehab | 0be4375 | 2008-01-05 17:22:01 -0300 | [diff] [blame] | 2202 | if (dev->radio_dev) { |
Laurent Pinchart | f0813b4 | 2009-11-27 13:57:30 -0300 | [diff] [blame] | 2203 | if (video_is_registered(dev->radio_dev)) |
Mauro Carvalho Chehab | 0be4375 | 2008-01-05 17:22:01 -0300 | [diff] [blame] | 2204 | video_unregister_device(dev->radio_dev); |
| 2205 | else |
| 2206 | video_device_release(dev->radio_dev); |
| 2207 | dev->radio_dev = NULL; |
| 2208 | } |
| 2209 | if (dev->vbi_dev) { |
Laurent Pinchart | 38c7c03 | 2009-11-27 13:57:15 -0300 | [diff] [blame] | 2210 | em28xx_info("V4L2 device %s deregistered\n", |
| 2211 | video_device_node_name(dev->vbi_dev)); |
Laurent Pinchart | f0813b4 | 2009-11-27 13:57:30 -0300 | [diff] [blame] | 2212 | if (video_is_registered(dev->vbi_dev)) |
Mauro Carvalho Chehab | 0be4375 | 2008-01-05 17:22:01 -0300 | [diff] [blame] | 2213 | video_unregister_device(dev->vbi_dev); |
| 2214 | else |
| 2215 | video_device_release(dev->vbi_dev); |
| 2216 | dev->vbi_dev = NULL; |
| 2217 | } |
| 2218 | if (dev->vdev) { |
Laurent Pinchart | 38c7c03 | 2009-11-27 13:57:15 -0300 | [diff] [blame] | 2219 | em28xx_info("V4L2 device %s deregistered\n", |
| 2220 | video_device_node_name(dev->vdev)); |
Laurent Pinchart | f0813b4 | 2009-11-27 13:57:30 -0300 | [diff] [blame] | 2221 | if (video_is_registered(dev->vdev)) |
Mauro Carvalho Chehab | 0be4375 | 2008-01-05 17:22:01 -0300 | [diff] [blame] | 2222 | video_unregister_device(dev->vdev); |
| 2223 | else |
| 2224 | video_device_release(dev->vdev); |
| 2225 | dev->vdev = NULL; |
| 2226 | } |
akpm@osdl.org | a6c2ba2 | 2005-11-08 21:37:07 -0800 | [diff] [blame] | 2227 | } |
| 2228 | |
| 2229 | /* |
Mauro Carvalho Chehab | 3acf280 | 2005-11-08 21:38:27 -0800 | [diff] [blame] | 2230 | * em28xx_v4l2_close() |
Douglas Schilling Landgraf | 6ea54d9 | 2008-04-17 21:41:10 -0300 | [diff] [blame] | 2231 | * stops streaming and deallocates all resources allocated by the v4l2 |
| 2232 | * calls and ioctls |
akpm@osdl.org | a6c2ba2 | 2005-11-08 21:37:07 -0800 | [diff] [blame] | 2233 | */ |
Hans Verkuil | bec4366 | 2008-12-30 06:58:20 -0300 | [diff] [blame] | 2234 | static int em28xx_v4l2_close(struct file *filp) |
akpm@osdl.org | a6c2ba2 | 2005-11-08 21:37:07 -0800 | [diff] [blame] | 2235 | { |
Mauro Carvalho Chehab | a3a048c | 2007-11-10 22:21:01 -0300 | [diff] [blame] | 2236 | struct em28xx_fh *fh = filp->private_data; |
| 2237 | struct em28xx *dev = fh->dev; |
| 2238 | int errCode; |
akpm@osdl.org | a6c2ba2 | 2005-11-08 21:37:07 -0800 | [diff] [blame] | 2239 | |
Mauro Carvalho Chehab | eac9435 | 2005-11-08 21:38:43 -0800 | [diff] [blame] | 2240 | em28xx_videodbg("users=%d\n", dev->users); |
akpm@osdl.org | a6c2ba2 | 2005-11-08 21:37:07 -0800 | [diff] [blame] | 2241 | |
Devin Heitmueller | 8c873d3 | 2009-09-03 00:23:27 -0300 | [diff] [blame] | 2242 | if (res_check(fh, EM28XX_RESOURCE_VIDEO)) { |
Mauro Carvalho Chehab | ad0ebb9 | 2008-04-13 14:37:52 -0300 | [diff] [blame] | 2243 | videobuf_stop(&fh->vb_vidq); |
Devin Heitmueller | 8c873d3 | 2009-09-03 00:23:27 -0300 | [diff] [blame] | 2244 | res_free(fh, EM28XX_RESOURCE_VIDEO); |
| 2245 | } |
akpm@osdl.org | a6c2ba2 | 2005-11-08 21:37:07 -0800 | [diff] [blame] | 2246 | |
Devin Heitmueller | 8c873d3 | 2009-09-03 00:23:27 -0300 | [diff] [blame] | 2247 | if (res_check(fh, EM28XX_RESOURCE_VBI)) { |
| 2248 | videobuf_stop(&fh->vb_vbiq); |
| 2249 | res_free(fh, EM28XX_RESOURCE_VBI); |
| 2250 | } |
| 2251 | |
Devin Heitmueller | e3ba4d3 | 2009-09-15 00:18:06 -0300 | [diff] [blame] | 2252 | if (dev->users == 1) { |
Mauro Carvalho Chehab | a3a048c | 2007-11-10 22:21:01 -0300 | [diff] [blame] | 2253 | /* the device is already disconnect, |
| 2254 | free the remaining resources */ |
| 2255 | if (dev->state & DEV_DISCONNECTED) { |
| 2256 | em28xx_release_resources(dev); |
Chris Rankin | 16e3d2f | 2011-09-04 15:38:14 -0300 | [diff] [blame] | 2257 | kfree(dev->alt_max_pkt_size); |
Mauro Carvalho Chehab | a3a048c | 2007-11-10 22:21:01 -0300 | [diff] [blame] | 2258 | kfree(dev); |
| 2259 | return 0; |
| 2260 | } |
| 2261 | |
Mauro Carvalho Chehab | eb6c963 | 2008-12-05 10:39:12 -0300 | [diff] [blame] | 2262 | /* Save some power by putting tuner to sleep */ |
Laurent Pinchart | 622b828 | 2009-10-05 10:48:17 -0300 | [diff] [blame] | 2263 | v4l2_device_call_all(&dev->v4l2_dev, 0, core, s_power, 0); |
Mauro Carvalho Chehab | eb6c963 | 2008-12-05 10:39:12 -0300 | [diff] [blame] | 2264 | |
Aidan Thornton | d7aa802 | 2008-04-13 14:38:47 -0300 | [diff] [blame] | 2265 | /* do this before setting alternate! */ |
| 2266 | em28xx_uninit_isoc(dev); |
Mauro Carvalho Chehab | 2fe3e2e | 2008-11-27 09:10:40 -0300 | [diff] [blame] | 2267 | em28xx_set_mode(dev, EM28XX_SUSPEND); |
Aidan Thornton | d7aa802 | 2008-04-13 14:38:47 -0300 | [diff] [blame] | 2268 | |
Mauro Carvalho Chehab | a3a048c | 2007-11-10 22:21:01 -0300 | [diff] [blame] | 2269 | /* set alternate 0 */ |
| 2270 | dev->alt = 0; |
| 2271 | em28xx_videodbg("setting alternate 0\n"); |
| 2272 | errCode = usb_set_interface(dev->udev, 0, 0); |
| 2273 | if (errCode < 0) { |
| 2274 | em28xx_errdev("cannot change alternate number to " |
| 2275 | "0 (error=%i)\n", errCode); |
| 2276 | } |
akpm@osdl.org | a6c2ba2 | 2005-11-08 21:37:07 -0800 | [diff] [blame] | 2277 | } |
Devin Heitmueller | 28abf083 | 2009-09-01 01:54:54 -0300 | [diff] [blame] | 2278 | |
Devin Heitmueller | 8c873d3 | 2009-09-03 00:23:27 -0300 | [diff] [blame] | 2279 | videobuf_mmap_free(&fh->vb_vidq); |
| 2280 | videobuf_mmap_free(&fh->vb_vbiq); |
Mauro Carvalho Chehab | a3a048c | 2007-11-10 22:21:01 -0300 | [diff] [blame] | 2281 | kfree(fh); |
akpm@osdl.org | a6c2ba2 | 2005-11-08 21:37:07 -0800 | [diff] [blame] | 2282 | dev->users--; |
| 2283 | wake_up_interruptible_nr(&dev->open, 1); |
akpm@osdl.org | a6c2ba2 | 2005-11-08 21:37:07 -0800 | [diff] [blame] | 2284 | return 0; |
| 2285 | } |
| 2286 | |
| 2287 | /* |
Mauro Carvalho Chehab | 3acf280 | 2005-11-08 21:38:27 -0800 | [diff] [blame] | 2288 | * em28xx_v4l2_read() |
akpm@osdl.org | a6c2ba2 | 2005-11-08 21:37:07 -0800 | [diff] [blame] | 2289 | * will allocate buffers when called for the first time |
| 2290 | */ |
| 2291 | static ssize_t |
Douglas Schilling Landgraf | 6ea54d9 | 2008-04-17 21:41:10 -0300 | [diff] [blame] | 2292 | 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] | 2293 | loff_t *pos) |
akpm@osdl.org | a6c2ba2 | 2005-11-08 21:37:07 -0800 | [diff] [blame] | 2294 | { |
Mauro Carvalho Chehab | a3a048c | 2007-11-10 22:21:01 -0300 | [diff] [blame] | 2295 | struct em28xx_fh *fh = filp->private_data; |
| 2296 | struct em28xx *dev = fh->dev; |
Mauro Carvalho Chehab | ad0ebb9 | 2008-04-13 14:37:52 -0300 | [diff] [blame] | 2297 | int rc; |
| 2298 | |
| 2299 | rc = check_dev(dev); |
| 2300 | if (rc < 0) |
| 2301 | return rc; |
akpm@osdl.org | a6c2ba2 | 2005-11-08 21:37:07 -0800 | [diff] [blame] | 2302 | |
Mauro Carvalho Chehab | 9e31ced | 2007-11-11 01:13:49 -0300 | [diff] [blame] | 2303 | /* FIXME: read() is not prepared to allow changing the video |
| 2304 | resolution while streaming. Seems a bug at em28xx_set_fmt |
| 2305 | */ |
Mauro Carvalho Chehab | a225452 | 2007-11-11 01:08:26 -0300 | [diff] [blame] | 2306 | |
Mauro Carvalho Chehab | ad0ebb9 | 2008-04-13 14:37:52 -0300 | [diff] [blame] | 2307 | if (fh->type == V4L2_BUF_TYPE_VIDEO_CAPTURE) { |
Devin Heitmueller | 8c873d3 | 2009-09-03 00:23:27 -0300 | [diff] [blame] | 2308 | if (res_locked(dev, EM28XX_RESOURCE_VIDEO)) |
| 2309 | return -EBUSY; |
Mauro Carvalho Chehab | a225452 | 2007-11-11 01:08:26 -0300 | [diff] [blame] | 2310 | |
Mauro Carvalho Chehab | ad0ebb9 | 2008-04-13 14:37:52 -0300 | [diff] [blame] | 2311 | return videobuf_read_stream(&fh->vb_vidq, buf, count, pos, 0, |
| 2312 | filp->f_flags & O_NONBLOCK); |
Mauro Carvalho Chehab | e5589be | 2006-01-23 17:11:08 -0200 | [diff] [blame] | 2313 | } |
Devin Heitmueller | 28abf083 | 2009-09-01 01:54:54 -0300 | [diff] [blame] | 2314 | |
| 2315 | |
| 2316 | if (fh->type == V4L2_BUF_TYPE_VBI_CAPTURE) { |
Devin Heitmueller | 8c873d3 | 2009-09-03 00:23:27 -0300 | [diff] [blame] | 2317 | if (!res_get(fh, EM28XX_RESOURCE_VBI)) |
| 2318 | return -EBUSY; |
Devin Heitmueller | 28abf083 | 2009-09-01 01:54:54 -0300 | [diff] [blame] | 2319 | |
| 2320 | return videobuf_read_stream(&fh->vb_vbiq, buf, count, pos, 0, |
| 2321 | filp->f_flags & O_NONBLOCK); |
| 2322 | } |
| 2323 | |
Mauro Carvalho Chehab | ad0ebb9 | 2008-04-13 14:37:52 -0300 | [diff] [blame] | 2324 | return 0; |
akpm@osdl.org | a6c2ba2 | 2005-11-08 21:37:07 -0800 | [diff] [blame] | 2325 | } |
| 2326 | |
| 2327 | /* |
Mauro Carvalho Chehab | 3acf280 | 2005-11-08 21:38:27 -0800 | [diff] [blame] | 2328 | * em28xx_v4l2_poll() |
akpm@osdl.org | a6c2ba2 | 2005-11-08 21:37:07 -0800 | [diff] [blame] | 2329 | * will allocate buffers when called for the first time |
| 2330 | */ |
Nicola Soranzo | a1a6ee7 | 2009-02-10 23:28:24 -0300 | [diff] [blame] | 2331 | 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] | 2332 | { |
Mauro Carvalho Chehab | a3a048c | 2007-11-10 22:21:01 -0300 | [diff] [blame] | 2333 | struct em28xx_fh *fh = filp->private_data; |
| 2334 | struct em28xx *dev = fh->dev; |
Mauro Carvalho Chehab | ad0ebb9 | 2008-04-13 14:37:52 -0300 | [diff] [blame] | 2335 | int rc; |
| 2336 | |
| 2337 | rc = check_dev(dev); |
| 2338 | if (rc < 0) |
| 2339 | return rc; |
akpm@osdl.org | a6c2ba2 | 2005-11-08 21:37:07 -0800 | [diff] [blame] | 2340 | |
Devin Heitmueller | 8c873d3 | 2009-09-03 00:23:27 -0300 | [diff] [blame] | 2341 | if (fh->type == V4L2_BUF_TYPE_VIDEO_CAPTURE) { |
| 2342 | if (!res_get(fh, EM28XX_RESOURCE_VIDEO)) |
| 2343 | return POLLERR; |
Devin Heitmueller | 28abf083 | 2009-09-01 01:54:54 -0300 | [diff] [blame] | 2344 | return videobuf_poll_stream(filp, &fh->vb_vidq, wait); |
Devin Heitmueller | 8c873d3 | 2009-09-03 00:23:27 -0300 | [diff] [blame] | 2345 | } else if (fh->type == V4L2_BUF_TYPE_VBI_CAPTURE) { |
| 2346 | if (!res_get(fh, EM28XX_RESOURCE_VBI)) |
| 2347 | return POLLERR; |
Devin Heitmueller | 28abf083 | 2009-09-01 01:54:54 -0300 | [diff] [blame] | 2348 | return videobuf_poll_stream(filp, &fh->vb_vbiq, wait); |
Devin Heitmueller | 8c873d3 | 2009-09-03 00:23:27 -0300 | [diff] [blame] | 2349 | } else { |
Mauro Carvalho Chehab | ad0ebb9 | 2008-04-13 14:37:52 -0300 | [diff] [blame] | 2350 | return POLLERR; |
Devin Heitmueller | 8c873d3 | 2009-09-03 00:23:27 -0300 | [diff] [blame] | 2351 | } |
akpm@osdl.org | a6c2ba2 | 2005-11-08 21:37:07 -0800 | [diff] [blame] | 2352 | } |
| 2353 | |
| 2354 | /* |
Mauro Carvalho Chehab | 3acf280 | 2005-11-08 21:38:27 -0800 | [diff] [blame] | 2355 | * em28xx_v4l2_mmap() |
akpm@osdl.org | a6c2ba2 | 2005-11-08 21:37:07 -0800 | [diff] [blame] | 2356 | */ |
Mauro Carvalho Chehab | 3acf280 | 2005-11-08 21:38:27 -0800 | [diff] [blame] | 2357 | 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] | 2358 | { |
Mauro Carvalho Chehab | a3a048c | 2007-11-10 22:21:01 -0300 | [diff] [blame] | 2359 | struct em28xx_fh *fh = filp->private_data; |
| 2360 | struct em28xx *dev = fh->dev; |
Mauro Carvalho Chehab | ad0ebb9 | 2008-04-13 14:37:52 -0300 | [diff] [blame] | 2361 | int rc; |
Markus Rechberger | 9c75541 | 2005-11-08 21:37:52 -0800 | [diff] [blame] | 2362 | |
Mauro Carvalho Chehab | ad0ebb9 | 2008-04-13 14:37:52 -0300 | [diff] [blame] | 2363 | rc = check_dev(dev); |
| 2364 | if (rc < 0) |
| 2365 | return rc; |
Mauro Carvalho Chehab | a3a048c | 2007-11-10 22:21:01 -0300 | [diff] [blame] | 2366 | |
Devin Heitmueller | 91f6dce | 2009-09-02 22:23:23 -0300 | [diff] [blame] | 2367 | if (fh->type == V4L2_BUF_TYPE_VIDEO_CAPTURE) |
| 2368 | rc = videobuf_mmap_mapper(&fh->vb_vidq, vma); |
| 2369 | else if (fh->type == V4L2_BUF_TYPE_VBI_CAPTURE) |
| 2370 | rc = videobuf_mmap_mapper(&fh->vb_vbiq, vma); |
akpm@osdl.org | a6c2ba2 | 2005-11-08 21:37:07 -0800 | [diff] [blame] | 2371 | |
Mauro Carvalho Chehab | ad0ebb9 | 2008-04-13 14:37:52 -0300 | [diff] [blame] | 2372 | em28xx_videodbg("vma start=0x%08lx, size=%ld, ret=%d\n", |
| 2373 | (unsigned long)vma->vm_start, |
| 2374 | (unsigned long)vma->vm_end-(unsigned long)vma->vm_start, |
| 2375 | rc); |
akpm@osdl.org | a6c2ba2 | 2005-11-08 21:37:07 -0800 | [diff] [blame] | 2376 | |
Mauro Carvalho Chehab | ad0ebb9 | 2008-04-13 14:37:52 -0300 | [diff] [blame] | 2377 | return rc; |
akpm@osdl.org | a6c2ba2 | 2005-11-08 21:37:07 -0800 | [diff] [blame] | 2378 | } |
| 2379 | |
Hans Verkuil | bec4366 | 2008-12-30 06:58:20 -0300 | [diff] [blame] | 2380 | static const struct v4l2_file_operations em28xx_v4l_fops = { |
Mauro Carvalho Chehab | 195a4ef | 2007-11-11 13:17:17 -0300 | [diff] [blame] | 2381 | .owner = THIS_MODULE, |
| 2382 | .open = em28xx_v4l2_open, |
| 2383 | .release = em28xx_v4l2_close, |
| 2384 | .read = em28xx_v4l2_read, |
| 2385 | .poll = em28xx_v4l2_poll, |
| 2386 | .mmap = em28xx_v4l2_mmap, |
Hans Verkuil | 0499a5a | 2010-09-26 07:34:45 -0300 | [diff] [blame] | 2387 | .unlocked_ioctl = video_ioctl2, |
akpm@osdl.org | a6c2ba2 | 2005-11-08 21:37:07 -0800 | [diff] [blame] | 2388 | }; |
| 2389 | |
Hans Verkuil | a399810 | 2008-07-21 02:57:38 -0300 | [diff] [blame] | 2390 | static const struct v4l2_ioctl_ops video_ioctl_ops = { |
Mauro Carvalho Chehab | 195a4ef | 2007-11-11 13:17:17 -0300 | [diff] [blame] | 2391 | .vidioc_querycap = vidioc_querycap, |
Hans Verkuil | 78b526a | 2008-05-28 12:16:41 -0300 | [diff] [blame] | 2392 | .vidioc_enum_fmt_vid_cap = vidioc_enum_fmt_vid_cap, |
| 2393 | .vidioc_g_fmt_vid_cap = vidioc_g_fmt_vid_cap, |
| 2394 | .vidioc_try_fmt_vid_cap = vidioc_try_fmt_vid_cap, |
| 2395 | .vidioc_s_fmt_vid_cap = vidioc_s_fmt_vid_cap, |
Devin Heitmueller | 28abf083 | 2009-09-01 01:54:54 -0300 | [diff] [blame] | 2396 | .vidioc_g_fmt_vbi_cap = vidioc_g_fmt_vbi_cap, |
| 2397 | .vidioc_s_fmt_vbi_cap = vidioc_s_fmt_vbi_cap, |
Mauro Carvalho Chehab | 1c5c506 | 2011-10-16 13:52:43 -0200 | [diff] [blame^] | 2398 | .vidioc_enum_framesizes = vidioc_enum_framesizes, |
Mauro Carvalho Chehab | 195a4ef | 2007-11-11 13:17:17 -0300 | [diff] [blame] | 2399 | .vidioc_g_audio = vidioc_g_audio, |
| 2400 | .vidioc_s_audio = vidioc_s_audio, |
| 2401 | .vidioc_cropcap = vidioc_cropcap, |
Hans Verkuil | 78b526a | 2008-05-28 12:16:41 -0300 | [diff] [blame] | 2402 | .vidioc_g_fmt_sliced_vbi_cap = vidioc_g_fmt_sliced_vbi_cap, |
| 2403 | .vidioc_try_fmt_sliced_vbi_cap = vidioc_try_set_sliced_vbi_cap, |
| 2404 | .vidioc_s_fmt_sliced_vbi_cap = vidioc_try_set_sliced_vbi_cap, |
Mauro Carvalho Chehab | 195a4ef | 2007-11-11 13:17:17 -0300 | [diff] [blame] | 2405 | |
| 2406 | .vidioc_reqbufs = vidioc_reqbufs, |
| 2407 | .vidioc_querybuf = vidioc_querybuf, |
| 2408 | .vidioc_qbuf = vidioc_qbuf, |
| 2409 | .vidioc_dqbuf = vidioc_dqbuf, |
Devin Heitmueller | 19bf003 | 2009-09-11 00:40:18 -0300 | [diff] [blame] | 2410 | .vidioc_g_std = vidioc_g_std, |
Mauro Carvalho Chehab | d56ae6f | 2011-10-04 09:53:00 -0300 | [diff] [blame] | 2411 | .vidioc_querystd = vidioc_querystd, |
Mauro Carvalho Chehab | 195a4ef | 2007-11-11 13:17:17 -0300 | [diff] [blame] | 2412 | .vidioc_s_std = vidioc_s_std, |
Mauro Carvalho Chehab | d96ecda | 2009-08-06 21:53:59 -0300 | [diff] [blame] | 2413 | .vidioc_g_parm = vidioc_g_parm, |
| 2414 | .vidioc_s_parm = vidioc_s_parm, |
Mauro Carvalho Chehab | 195a4ef | 2007-11-11 13:17:17 -0300 | [diff] [blame] | 2415 | .vidioc_enum_input = vidioc_enum_input, |
| 2416 | .vidioc_g_input = vidioc_g_input, |
| 2417 | .vidioc_s_input = vidioc_s_input, |
| 2418 | .vidioc_queryctrl = vidioc_queryctrl, |
| 2419 | .vidioc_g_ctrl = vidioc_g_ctrl, |
| 2420 | .vidioc_s_ctrl = vidioc_s_ctrl, |
| 2421 | .vidioc_streamon = vidioc_streamon, |
| 2422 | .vidioc_streamoff = vidioc_streamoff, |
| 2423 | .vidioc_g_tuner = vidioc_g_tuner, |
| 2424 | .vidioc_s_tuner = vidioc_s_tuner, |
| 2425 | .vidioc_g_frequency = vidioc_g_frequency, |
| 2426 | .vidioc_s_frequency = vidioc_s_frequency, |
Mauro Carvalho Chehab | 1e7ad56 | 2008-02-06 09:00:41 -0300 | [diff] [blame] | 2427 | #ifdef CONFIG_VIDEO_ADV_DEBUG |
| 2428 | .vidioc_g_register = vidioc_g_register, |
| 2429 | .vidioc_s_register = vidioc_s_register, |
Mauro Carvalho Chehab | 14983d8 | 2008-12-22 20:58:41 -0300 | [diff] [blame] | 2430 | .vidioc_g_chip_ident = vidioc_g_chip_ident, |
Mauro Carvalho Chehab | 1e7ad56 | 2008-02-06 09:00:41 -0300 | [diff] [blame] | 2431 | #endif |
Hans Verkuil | a399810 | 2008-07-21 02:57:38 -0300 | [diff] [blame] | 2432 | }; |
| 2433 | |
| 2434 | static const struct video_device em28xx_video_template = { |
| 2435 | .fops = &em28xx_v4l_fops, |
| 2436 | .release = video_device_release, |
| 2437 | .ioctl_ops = &video_ioctl_ops, |
| 2438 | |
Mauro Carvalho Chehab | 195a4ef | 2007-11-11 13:17:17 -0300 | [diff] [blame] | 2439 | .tvnorms = V4L2_STD_ALL, |
Devin Heitmueller | 19bf003 | 2009-09-11 00:40:18 -0300 | [diff] [blame] | 2440 | .current_norm = V4L2_STD_PAL, |
Mauro Carvalho Chehab | 195a4ef | 2007-11-11 13:17:17 -0300 | [diff] [blame] | 2441 | }; |
| 2442 | |
Hans Verkuil | bec4366 | 2008-12-30 06:58:20 -0300 | [diff] [blame] | 2443 | static const struct v4l2_file_operations radio_fops = { |
Hans Verkuil | a399810 | 2008-07-21 02:57:38 -0300 | [diff] [blame] | 2444 | .owner = THIS_MODULE, |
| 2445 | .open = em28xx_v4l2_open, |
| 2446 | .release = em28xx_v4l2_close, |
Hans Verkuil | 8fd0bda | 2010-12-18 09:59:51 -0300 | [diff] [blame] | 2447 | .unlocked_ioctl = video_ioctl2, |
Hans Verkuil | a399810 | 2008-07-21 02:57:38 -0300 | [diff] [blame] | 2448 | }; |
| 2449 | |
| 2450 | static const struct v4l2_ioctl_ops radio_ioctl_ops = { |
Mauro Carvalho Chehab | 0be4375 | 2008-01-05 17:22:01 -0300 | [diff] [blame] | 2451 | .vidioc_querycap = radio_querycap, |
| 2452 | .vidioc_g_tuner = radio_g_tuner, |
| 2453 | .vidioc_enum_input = radio_enum_input, |
| 2454 | .vidioc_g_audio = radio_g_audio, |
| 2455 | .vidioc_s_tuner = radio_s_tuner, |
| 2456 | .vidioc_s_audio = radio_s_audio, |
| 2457 | .vidioc_s_input = radio_s_input, |
| 2458 | .vidioc_queryctrl = radio_queryctrl, |
| 2459 | .vidioc_g_ctrl = vidioc_g_ctrl, |
| 2460 | .vidioc_s_ctrl = vidioc_s_ctrl, |
| 2461 | .vidioc_g_frequency = vidioc_g_frequency, |
| 2462 | .vidioc_s_frequency = vidioc_s_frequency, |
Mauro Carvalho Chehab | 1e7ad56 | 2008-02-06 09:00:41 -0300 | [diff] [blame] | 2463 | #ifdef CONFIG_VIDEO_ADV_DEBUG |
| 2464 | .vidioc_g_register = vidioc_g_register, |
| 2465 | .vidioc_s_register = vidioc_s_register, |
| 2466 | #endif |
Mauro Carvalho Chehab | 0be4375 | 2008-01-05 17:22:01 -0300 | [diff] [blame] | 2467 | }; |
| 2468 | |
Hans Verkuil | a399810 | 2008-07-21 02:57:38 -0300 | [diff] [blame] | 2469 | static struct video_device em28xx_radio_template = { |
| 2470 | .name = "em28xx-radio", |
Hans Verkuil | a399810 | 2008-07-21 02:57:38 -0300 | [diff] [blame] | 2471 | .fops = &radio_fops, |
| 2472 | .ioctl_ops = &radio_ioctl_ops, |
Hans Verkuil | a399810 | 2008-07-21 02:57:38 -0300 | [diff] [blame] | 2473 | }; |
| 2474 | |
Douglas Schilling Landgraf | 6ea54d9 | 2008-04-17 21:41:10 -0300 | [diff] [blame] | 2475 | /******************************** usb interface ******************************/ |
akpm@osdl.org | a6c2ba2 | 2005-11-08 21:37:07 -0800 | [diff] [blame] | 2476 | |
Mauro Carvalho Chehab | 6d79468 | 2008-01-05 09:57:31 -0300 | [diff] [blame] | 2477 | |
Mauro Carvalho Chehab | 6d79468 | 2008-01-05 09:57:31 -0300 | [diff] [blame] | 2478 | |
Adrian Bunk | 532fe65 | 2008-01-28 22:10:48 -0300 | [diff] [blame] | 2479 | static struct video_device *em28xx_vdev_init(struct em28xx *dev, |
Nicola Soranzo | a1a6ee7 | 2009-02-10 23:28:24 -0300 | [diff] [blame] | 2480 | const struct video_device *template, |
| 2481 | const char *type_name) |
Mauro Carvalho Chehab | 0be4375 | 2008-01-05 17:22:01 -0300 | [diff] [blame] | 2482 | { |
| 2483 | struct video_device *vfd; |
| 2484 | |
| 2485 | vfd = video_device_alloc(); |
| 2486 | if (NULL == vfd) |
| 2487 | return NULL; |
Douglas Schilling Landgraf | f2cf250 | 2009-03-31 17:10:58 -0300 | [diff] [blame] | 2488 | |
| 2489 | *vfd = *template; |
Douglas Schilling Landgraf | f2cf250 | 2009-03-31 17:10:58 -0300 | [diff] [blame] | 2490 | vfd->v4l2_dev = &dev->v4l2_dev; |
| 2491 | vfd->release = video_device_release; |
| 2492 | vfd->debug = video_debug; |
Hans Verkuil | 0499a5a | 2010-09-26 07:34:45 -0300 | [diff] [blame] | 2493 | vfd->lock = &dev->lock; |
Mauro Carvalho Chehab | 0be4375 | 2008-01-05 17:22:01 -0300 | [diff] [blame] | 2494 | |
| 2495 | snprintf(vfd->name, sizeof(vfd->name), "%s %s", |
| 2496 | dev->name, type_name); |
| 2497 | |
Laurent Pinchart | 63b0d5a | 2009-12-10 11:44:04 -0200 | [diff] [blame] | 2498 | video_set_drvdata(vfd, dev); |
Mauro Carvalho Chehab | 0be4375 | 2008-01-05 17:22:01 -0300 | [diff] [blame] | 2499 | return vfd; |
| 2500 | } |
| 2501 | |
Mauro Carvalho Chehab | 2e5ef2d | 2008-12-28 22:26:36 -0300 | [diff] [blame] | 2502 | int em28xx_register_analog_devices(struct em28xx *dev) |
Mauro Carvalho Chehab | 1a23f81 | 2008-12-28 22:18:14 -0300 | [diff] [blame] | 2503 | { |
Robert Krakora | 6e7b9ea | 2009-01-18 21:59:34 -0300 | [diff] [blame] | 2504 | u8 val; |
Mauro Carvalho Chehab | 2e5ef2d | 2008-12-28 22:26:36 -0300 | [diff] [blame] | 2505 | int ret; |
| 2506 | |
Mauro Carvalho Chehab | 1990d50 | 2011-06-24 14:45:49 -0300 | [diff] [blame] | 2507 | printk(KERN_INFO "%s: v4l2 driver version %s\n", |
| 2508 | dev->name, EM28XX_VERSION); |
Mauro Carvalho Chehab | 1a23f81 | 2008-12-28 22:18:14 -0300 | [diff] [blame] | 2509 | |
Mauro Carvalho Chehab | 1a23f81 | 2008-12-28 22:18:14 -0300 | [diff] [blame] | 2510 | /* set default norm */ |
| 2511 | dev->norm = em28xx_video_template.current_norm; |
Hans Verkuil | d5906dd | 2010-09-26 07:45:15 -0300 | [diff] [blame] | 2512 | v4l2_device_call_all(&dev->v4l2_dev, 0, core, s_std, dev->norm); |
Mauro Carvalho Chehab | 1a23f81 | 2008-12-28 22:18:14 -0300 | [diff] [blame] | 2513 | dev->interlaced = EM28XX_INTERLACED_DEFAULT; |
Mauro Carvalho Chehab | 24c3c41 | 2009-01-07 22:49:25 -0300 | [diff] [blame] | 2514 | dev->ctl_input = 0; |
Mauro Carvalho Chehab | 1a23f81 | 2008-12-28 22:18:14 -0300 | [diff] [blame] | 2515 | |
Mauro Carvalho Chehab | 24c3c41 | 2009-01-07 22:49:25 -0300 | [diff] [blame] | 2516 | /* Analog specific initialization */ |
| 2517 | dev->format = &format[0]; |
Mauro Carvalho Chehab | ed5f143 | 2009-07-02 17:34:04 -0300 | [diff] [blame] | 2518 | em28xx_set_video_format(dev, format[0].fourcc, |
| 2519 | norm_maxw(dev), norm_maxh(dev)); |
| 2520 | |
Mauro Carvalho Chehab | 24c3c41 | 2009-01-07 22:49:25 -0300 | [diff] [blame] | 2521 | video_mux(dev, dev->ctl_input); |
| 2522 | |
| 2523 | /* Audio defaults */ |
| 2524 | dev->mute = 1; |
| 2525 | dev->volume = 0x1f; |
| 2526 | |
Mauro Carvalho Chehab | 24c3c41 | 2009-01-07 22:49:25 -0300 | [diff] [blame] | 2527 | /* em28xx_write_reg(dev, EM28XX_R0E_AUDIOSRC, 0xc0); audio register */ |
Nicola Soranzo | a1a6ee7 | 2009-02-10 23:28:24 -0300 | [diff] [blame] | 2528 | val = (u8)em28xx_read_reg(dev, EM28XX_R0F_XCLK); |
| 2529 | em28xx_write_reg(dev, EM28XX_R0F_XCLK, |
| 2530 | (EM28XX_XCLK_AUDIO_UNMUTE | val)); |
Mauro Carvalho Chehab | 24c3c41 | 2009-01-07 22:49:25 -0300 | [diff] [blame] | 2531 | |
| 2532 | em28xx_set_outfmt(dev); |
| 2533 | em28xx_colorlevels_set_default(dev); |
| 2534 | em28xx_compression_disable(dev); |
Mauro Carvalho Chehab | 1a23f81 | 2008-12-28 22:18:14 -0300 | [diff] [blame] | 2535 | |
Mauro Carvalho Chehab | 818a557 | 2008-11-20 10:30:26 -0300 | [diff] [blame] | 2536 | /* allocate and fill video video_device struct */ |
| 2537 | dev->vdev = em28xx_vdev_init(dev, &em28xx_video_template, "video"); |
| 2538 | if (!dev->vdev) { |
| 2539 | em28xx_errdev("cannot allocate video_device.\n"); |
| 2540 | return -ENODEV; |
| 2541 | } |
| 2542 | |
| 2543 | /* register v4l2 video video_device */ |
| 2544 | ret = video_register_device(dev->vdev, VFL_TYPE_GRABBER, |
| 2545 | video_nr[dev->devno]); |
| 2546 | if (ret) { |
| 2547 | em28xx_errdev("unable to register video device (error=%i).\n", |
| 2548 | ret); |
| 2549 | return ret; |
| 2550 | } |
| 2551 | |
| 2552 | /* Allocate and fill vbi video_device struct */ |
Devin Heitmueller | 290c0cf | 2009-09-11 00:01:06 -0300 | [diff] [blame] | 2553 | if (em28xx_vbi_supported(dev) == 1) { |
| 2554 | dev->vbi_dev = em28xx_vdev_init(dev, &em28xx_video_template, |
| 2555 | "vbi"); |
Mauro Carvalho Chehab | 818a557 | 2008-11-20 10:30:26 -0300 | [diff] [blame] | 2556 | |
Devin Heitmueller | 290c0cf | 2009-09-11 00:01:06 -0300 | [diff] [blame] | 2557 | /* register v4l2 vbi video_device */ |
| 2558 | ret = video_register_device(dev->vbi_dev, VFL_TYPE_VBI, |
| 2559 | vbi_nr[dev->devno]); |
| 2560 | if (ret < 0) { |
| 2561 | em28xx_errdev("unable to register vbi device\n"); |
| 2562 | return ret; |
| 2563 | } |
Mauro Carvalho Chehab | 818a557 | 2008-11-20 10:30:26 -0300 | [diff] [blame] | 2564 | } |
| 2565 | |
| 2566 | if (em28xx_boards[dev->model].radio.type == EM28XX_RADIO) { |
Nicola Soranzo | a1a6ee7 | 2009-02-10 23:28:24 -0300 | [diff] [blame] | 2567 | dev->radio_dev = em28xx_vdev_init(dev, &em28xx_radio_template, |
| 2568 | "radio"); |
Mauro Carvalho Chehab | 818a557 | 2008-11-20 10:30:26 -0300 | [diff] [blame] | 2569 | if (!dev->radio_dev) { |
| 2570 | em28xx_errdev("cannot allocate video_device.\n"); |
| 2571 | return -ENODEV; |
| 2572 | } |
| 2573 | ret = video_register_device(dev->radio_dev, VFL_TYPE_RADIO, |
| 2574 | radio_nr[dev->devno]); |
| 2575 | if (ret < 0) { |
| 2576 | em28xx_errdev("can't register radio device\n"); |
| 2577 | return ret; |
| 2578 | } |
Laurent Pinchart | 38c7c03 | 2009-11-27 13:57:15 -0300 | [diff] [blame] | 2579 | em28xx_info("Registered radio device as %s\n", |
| 2580 | video_device_node_name(dev->radio_dev)); |
Mauro Carvalho Chehab | 818a557 | 2008-11-20 10:30:26 -0300 | [diff] [blame] | 2581 | } |
| 2582 | |
Laurent Pinchart | 38c7c03 | 2009-11-27 13:57:15 -0300 | [diff] [blame] | 2583 | em28xx_info("V4L2 video device registered as %s\n", |
| 2584 | video_device_node_name(dev->vdev)); |
Devin Heitmueller | 290c0cf | 2009-09-11 00:01:06 -0300 | [diff] [blame] | 2585 | |
| 2586 | if (dev->vbi_dev) |
Laurent Pinchart | 38c7c03 | 2009-11-27 13:57:15 -0300 | [diff] [blame] | 2587 | em28xx_info("V4L2 VBI device registered as %s\n", |
| 2588 | video_device_node_name(dev->vbi_dev)); |
Mauro Carvalho Chehab | 818a557 | 2008-11-20 10:30:26 -0300 | [diff] [blame] | 2589 | |
| 2590 | return 0; |
| 2591 | } |