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