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