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