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