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