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> |
Hans Verkuil | 2474ed4 | 2006-03-19 12:35:57 -0300 | [diff] [blame] | 42 | #include <media/msp3400.h> |
Mauro Carvalho Chehab | ed08631 | 2008-01-24 06:59:20 -0300 | [diff] [blame] | 43 | #include <media/tuner.h> |
akpm@osdl.org | a6c2ba2 | 2005-11-08 21:37:07 -0800 | [diff] [blame] | 44 | |
Mauro Carvalho Chehab | f7abcd3 | 2005-11-08 21:38:25 -0800 | [diff] [blame] | 45 | #define DRIVER_AUTHOR "Ludovico Cavedon <cavedon@sssup.it>, " \ |
| 46 | "Markus Rechberger <mrechberger@gmail.com>, " \ |
Mauro Carvalho Chehab | 2e7c6dc | 2006-04-03 07:53:40 -0300 | [diff] [blame] | 47 | "Mauro Carvalho Chehab <mchehab@infradead.org>, " \ |
Mauro Carvalho Chehab | f7abcd3 | 2005-11-08 21:38:25 -0800 | [diff] [blame] | 48 | "Sascha Sommer <saschasommer@freenet.de>" |
akpm@osdl.org | a6c2ba2 | 2005-11-08 21:37:07 -0800 | [diff] [blame] | 49 | |
Mauro Carvalho Chehab | f7abcd3 | 2005-11-08 21:38:25 -0800 | [diff] [blame] | 50 | #define DRIVER_NAME "em28xx" |
| 51 | #define DRIVER_DESC "Empia em28xx based USB video device driver" |
Mauro Carvalho Chehab | 195a4ef | 2007-11-11 13:17:17 -0300 | [diff] [blame] | 52 | #define EM28XX_VERSION_CODE KERNEL_VERSION(0, 1, 0) |
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 | 3acf280 | 2005-11-08 21:38:27 -0800 | [diff] [blame] | 75 | static LIST_HEAD(em28xx_devlist); |
Mauro Carvalho Chehab | 818a557 | 2008-11-20 10:30:26 -0300 | [diff] [blame] | 76 | static DEFINE_MUTEX(em28xx_devlist_mutex); |
Markus Rechberger | 9c75541 | 2005-11-08 21:37:52 -0800 | [diff] [blame] | 77 | |
Mauro Carvalho Chehab | 9d4d9c0 | 2005-11-08 21:38:52 -0800 | [diff] [blame] | 78 | static unsigned int card[] = {[0 ... (EM28XX_MAXBOARDS - 1)] = UNSET }; |
Mauro Carvalho Chehab | e5589be | 2006-01-23 17:11:08 -0200 | [diff] [blame] | 79 | static unsigned int video_nr[] = {[0 ... (EM28XX_MAXBOARDS - 1)] = UNSET }; |
Mauro Carvalho Chehab | 0be4375 | 2008-01-05 17:22:01 -0300 | [diff] [blame] | 80 | static unsigned int vbi_nr[] = {[0 ... (EM28XX_MAXBOARDS - 1)] = UNSET }; |
| 81 | static unsigned int radio_nr[] = {[0 ... (EM28XX_MAXBOARDS - 1)] = UNSET }; |
| 82 | |
Mauro Carvalho Chehab | 596d92d | 2005-11-08 21:37:24 -0800 | [diff] [blame] | 83 | module_param_array(card, int, NULL, 0444); |
Mauro Carvalho Chehab | e5589be | 2006-01-23 17:11:08 -0200 | [diff] [blame] | 84 | module_param_array(video_nr, int, NULL, 0444); |
| 85 | module_param_array(vbi_nr, int, NULL, 0444); |
Mauro Carvalho Chehab | 0be4375 | 2008-01-05 17:22:01 -0300 | [diff] [blame] | 86 | module_param_array(radio_nr, int, NULL, 0444); |
| 87 | MODULE_PARM_DESC(card, "card type"); |
| 88 | MODULE_PARM_DESC(video_nr, "video device numbers"); |
| 89 | MODULE_PARM_DESC(vbi_nr, "vbi device numbers"); |
| 90 | MODULE_PARM_DESC(radio_nr, "radio device numbers"); |
Mauro Carvalho Chehab | 596d92d | 2005-11-08 21:37:24 -0800 | [diff] [blame] | 91 | |
Douglas Schilling Landgraf | ff699e6 | 2008-04-22 14:41:48 -0300 | [diff] [blame] | 92 | static unsigned int video_debug; |
Douglas Schilling Landgraf | 6ea54d9 | 2008-04-17 21:41:10 -0300 | [diff] [blame] | 93 | module_param(video_debug, int, 0644); |
| 94 | MODULE_PARM_DESC(video_debug, "enable debug messages [video]"); |
akpm@osdl.org | a6c2ba2 | 2005-11-08 21:37:07 -0800 | [diff] [blame] | 95 | |
Mauro Carvalho Chehab | e5589be | 2006-01-23 17:11:08 -0200 | [diff] [blame] | 96 | /* Bitmask marking allocated devices from 0 to EM28XX_MAXBOARDS */ |
| 97 | static unsigned long em28xx_devused; |
| 98 | |
akpm@osdl.org | a6c2ba2 | 2005-11-08 21:37:07 -0800 | [diff] [blame] | 99 | /* supported controls */ |
Mauro Carvalho Chehab | c0477ad | 2006-01-09 15:25:14 -0200 | [diff] [blame] | 100 | /* Common to all boards */ |
Mauro Carvalho Chehab | 3acf280 | 2005-11-08 21:38:27 -0800 | [diff] [blame] | 101 | static struct v4l2_queryctrl em28xx_qctrl[] = { |
akpm@osdl.org | a6c2ba2 | 2005-11-08 21:37:07 -0800 | [diff] [blame] | 102 | { |
Mauro Carvalho Chehab | c0477ad | 2006-01-09 15:25:14 -0200 | [diff] [blame] | 103 | .id = V4L2_CID_AUDIO_VOLUME, |
| 104 | .type = V4L2_CTRL_TYPE_INTEGER, |
| 105 | .name = "Volume", |
| 106 | .minimum = 0x0, |
| 107 | .maximum = 0x1f, |
| 108 | .step = 0x1, |
| 109 | .default_value = 0x1f, |
| 110 | .flags = 0, |
Douglas Schilling Landgraf | 6ea54d9 | 2008-04-17 21:41:10 -0300 | [diff] [blame] | 111 | }, { |
Mauro Carvalho Chehab | c0477ad | 2006-01-09 15:25:14 -0200 | [diff] [blame] | 112 | .id = V4L2_CID_AUDIO_MUTE, |
| 113 | .type = V4L2_CTRL_TYPE_BOOLEAN, |
| 114 | .name = "Mute", |
| 115 | .minimum = 0, |
| 116 | .maximum = 1, |
| 117 | .step = 1, |
| 118 | .default_value = 1, |
| 119 | .flags = 0, |
| 120 | } |
| 121 | }; |
| 122 | |
Mauro Carvalho Chehab | 3acf280 | 2005-11-08 21:38:27 -0800 | [diff] [blame] | 123 | static struct usb_driver em28xx_usb_driver; |
akpm@osdl.org | a6c2ba2 | 2005-11-08 21:37:07 -0800 | [diff] [blame] | 124 | |
Mauro Carvalho Chehab | ad0ebb9 | 2008-04-13 14:37:52 -0300 | [diff] [blame] | 125 | /* ------------------------------------------------------------------ |
| 126 | DMA and thread functions |
| 127 | ------------------------------------------------------------------*/ |
| 128 | |
| 129 | /* |
| 130 | * Announces that a buffer were filled and request the next |
| 131 | */ |
Mauro Carvalho Chehab | f245e54 | 2008-04-13 14:41:23 -0300 | [diff] [blame] | 132 | static inline void buffer_filled(struct em28xx *dev, |
Mauro Carvalho Chehab | ad0ebb9 | 2008-04-13 14:37:52 -0300 | [diff] [blame] | 133 | struct em28xx_dmaqueue *dma_q, |
| 134 | struct em28xx_buffer *buf) |
| 135 | { |
Mauro Carvalho Chehab | ad0ebb9 | 2008-04-13 14:37:52 -0300 | [diff] [blame] | 136 | /* Advice that buffer was filled */ |
| 137 | em28xx_isocdbg("[%p/%d] wakeup\n", buf, buf->vb.i); |
| 138 | buf->vb.state = VIDEOBUF_DONE; |
| 139 | buf->vb.field_count++; |
| 140 | do_gettimeofday(&buf->vb.ts); |
| 141 | |
Mauro Carvalho Chehab | cb78472 | 2008-04-13 15:06:52 -0300 | [diff] [blame] | 142 | dev->isoc_ctl.buf = NULL; |
| 143 | |
Mauro Carvalho Chehab | ad0ebb9 | 2008-04-13 14:37:52 -0300 | [diff] [blame] | 144 | list_del(&buf->vb.queue); |
| 145 | wake_up(&buf->vb.done); |
| 146 | } |
| 147 | |
| 148 | /* |
| 149 | * Identify the buffer header type and properly handles |
| 150 | */ |
| 151 | static void em28xx_copy_video(struct em28xx *dev, |
| 152 | struct em28xx_dmaqueue *dma_q, |
| 153 | struct em28xx_buffer *buf, |
| 154 | unsigned char *p, |
| 155 | unsigned char *outp, unsigned long len) |
| 156 | { |
| 157 | void *fieldstart, *startwrite, *startread; |
Mauro Carvalho Chehab | f245e54 | 2008-04-13 14:41:23 -0300 | [diff] [blame] | 158 | int linesdone, currlinedone, offset, lencopy, remain; |
Mauro Carvalho Chehab | 44dc733 | 2008-04-13 15:11:08 -0300 | [diff] [blame] | 159 | int bytesperline = dev->width << 1; |
Mauro Carvalho Chehab | ad0ebb9 | 2008-04-13 14:37:52 -0300 | [diff] [blame] | 160 | |
| 161 | if (dma_q->pos + len > buf->vb.size) |
| 162 | len = buf->vb.size - dma_q->pos; |
| 163 | |
Aidan Thornton | d7aa802 | 2008-04-13 14:38:47 -0300 | [diff] [blame] | 164 | if (p[0] != 0x88 && p[0] != 0x22) { |
Mauro Carvalho Chehab | ad0ebb9 | 2008-04-13 14:37:52 -0300 | [diff] [blame] | 165 | em28xx_isocdbg("frame is not complete\n"); |
| 166 | len += 4; |
| 167 | } else |
Mauro Carvalho Chehab | f245e54 | 2008-04-13 14:41:23 -0300 | [diff] [blame] | 168 | p += 4; |
Mauro Carvalho Chehab | ad0ebb9 | 2008-04-13 14:37:52 -0300 | [diff] [blame] | 169 | |
| 170 | startread = p; |
| 171 | remain = len; |
| 172 | |
| 173 | /* Interlaces frame */ |
| 174 | if (buf->top_field) |
| 175 | fieldstart = outp; |
| 176 | else |
Mauro Carvalho Chehab | 44dc733 | 2008-04-13 15:11:08 -0300 | [diff] [blame] | 177 | fieldstart = outp + bytesperline; |
Mauro Carvalho Chehab | ad0ebb9 | 2008-04-13 14:37:52 -0300 | [diff] [blame] | 178 | |
Mauro Carvalho Chehab | 44dc733 | 2008-04-13 15:11:08 -0300 | [diff] [blame] | 179 | linesdone = dma_q->pos / bytesperline; |
| 180 | currlinedone = dma_q->pos % bytesperline; |
| 181 | offset = linesdone * bytesperline * 2 + currlinedone; |
Mauro Carvalho Chehab | ad0ebb9 | 2008-04-13 14:37:52 -0300 | [diff] [blame] | 182 | startwrite = fieldstart + offset; |
Mauro Carvalho Chehab | 44dc733 | 2008-04-13 15:11:08 -0300 | [diff] [blame] | 183 | lencopy = bytesperline - currlinedone; |
Mauro Carvalho Chehab | ad0ebb9 | 2008-04-13 14:37:52 -0300 | [diff] [blame] | 184 | lencopy = lencopy > remain ? remain : lencopy; |
| 185 | |
Mauro Carvalho Chehab | f245e54 | 2008-04-13 14:41:23 -0300 | [diff] [blame] | 186 | if ((char *)startwrite + lencopy > (char *)outp + buf->vb.size) { |
Mauro Carvalho Chehab | ea8df7e | 2008-04-13 14:39:29 -0300 | [diff] [blame] | 187 | em28xx_isocdbg("Overflow of %zi bytes past buffer end (1)\n", |
Mauro Carvalho Chehab | f245e54 | 2008-04-13 14:41:23 -0300 | [diff] [blame] | 188 | ((char *)startwrite + lencopy) - |
| 189 | ((char *)outp + buf->vb.size)); |
| 190 | lencopy = remain = (char *)outp + buf->vb.size - (char *)startwrite; |
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 | |
Mauro Carvalho Chehab | f245e54 | 2008-04-13 14:41:23 -0300 | [diff] [blame] | 206 | if ((char *)startwrite + lencopy > (char *)outp + buf->vb.size) { |
Mauro Carvalho Chehab | ea8df7e | 2008-04-13 14:39:29 -0300 | [diff] [blame] | 207 | em28xx_isocdbg("Overflow of %zi bytes past buffer end (2)\n", |
Mauro Carvalho Chehab | f245e54 | 2008-04-13 14:41:23 -0300 | [diff] [blame] | 208 | ((char *)startwrite + lencopy) - |
| 209 | ((char *)outp + buf->vb.size)); |
| 210 | lencopy = remain = (char *)outp + buf->vb.size - |
| 211 | (char *)startwrite; |
Aidan Thornton | d7aa802 | 2008-04-13 14:38:47 -0300 | [diff] [blame] | 212 | } |
Mauro Carvalho Chehab | f245e54 | 2008-04-13 14:41:23 -0300 | [diff] [blame] | 213 | if (lencopy <= 0) |
| 214 | break; |
Aidan Thornton | d7aa802 | 2008-04-13 14:38:47 -0300 | [diff] [blame] | 215 | |
| 216 | memcpy(startwrite, startread, lencopy); |
Mauro Carvalho Chehab | ad0ebb9 | 2008-04-13 14:37:52 -0300 | [diff] [blame] | 217 | |
| 218 | remain -= lencopy; |
| 219 | } |
| 220 | |
| 221 | dma_q->pos += len; |
| 222 | } |
| 223 | |
Mauro Carvalho Chehab | f245e54 | 2008-04-13 14:41:23 -0300 | [diff] [blame] | 224 | static inline void print_err_status(struct em28xx *dev, |
Mauro Carvalho Chehab | ad0ebb9 | 2008-04-13 14:37:52 -0300 | [diff] [blame] | 225 | int packet, int status) |
| 226 | { |
| 227 | char *errmsg = "Unknown"; |
| 228 | |
Mauro Carvalho Chehab | f245e54 | 2008-04-13 14:41:23 -0300 | [diff] [blame] | 229 | switch (status) { |
Mauro Carvalho Chehab | ad0ebb9 | 2008-04-13 14:37:52 -0300 | [diff] [blame] | 230 | case -ENOENT: |
| 231 | errmsg = "unlinked synchronuously"; |
| 232 | break; |
| 233 | case -ECONNRESET: |
| 234 | errmsg = "unlinked asynchronuously"; |
| 235 | break; |
| 236 | case -ENOSR: |
| 237 | errmsg = "Buffer error (overrun)"; |
| 238 | break; |
| 239 | case -EPIPE: |
| 240 | errmsg = "Stalled (device not responding)"; |
| 241 | break; |
| 242 | case -EOVERFLOW: |
| 243 | errmsg = "Babble (bad cable?)"; |
| 244 | break; |
| 245 | case -EPROTO: |
| 246 | errmsg = "Bit-stuff error (bad cable?)"; |
| 247 | break; |
| 248 | case -EILSEQ: |
| 249 | errmsg = "CRC/Timeout (could be anything)"; |
| 250 | break; |
| 251 | case -ETIME: |
| 252 | errmsg = "Device does not respond"; |
| 253 | break; |
| 254 | } |
Mauro Carvalho Chehab | f245e54 | 2008-04-13 14:41:23 -0300 | [diff] [blame] | 255 | if (packet < 0) { |
Mauro Carvalho Chehab | ad0ebb9 | 2008-04-13 14:37:52 -0300 | [diff] [blame] | 256 | em28xx_isocdbg("URB status %d [%s].\n", status, errmsg); |
| 257 | } else { |
| 258 | em28xx_isocdbg("URB packet %d, status %d [%s].\n", |
| 259 | packet, status, errmsg); |
| 260 | } |
| 261 | } |
| 262 | |
| 263 | /* |
| 264 | * video-buf generic routine to get the next available buffer |
| 265 | */ |
Aidan Thornton | 3b5fa92 | 2008-04-13 15:09:36 -0300 | [diff] [blame] | 266 | static inline void get_next_buf(struct em28xx_dmaqueue *dma_q, |
Mauro Carvalho Chehab | ad0ebb9 | 2008-04-13 14:37:52 -0300 | [diff] [blame] | 267 | struct em28xx_buffer **buf) |
| 268 | { |
| 269 | struct em28xx *dev = container_of(dma_q, struct em28xx, vidq); |
Mauro Carvalho Chehab | dbecb44 | 2008-04-13 15:08:55 -0300 | [diff] [blame] | 270 | char *outp; |
Mauro Carvalho Chehab | ad0ebb9 | 2008-04-13 14:37:52 -0300 | [diff] [blame] | 271 | |
Mauro Carvalho Chehab | dbecb44 | 2008-04-13 15:08:55 -0300 | [diff] [blame] | 272 | if (list_empty(&dma_q->active)) { |
| 273 | em28xx_isocdbg("No active queue to serve\n"); |
| 274 | dev->isoc_ctl.buf = NULL; |
Mauro Carvalho Chehab | dbecb44 | 2008-04-13 15:08:55 -0300 | [diff] [blame] | 275 | *buf = NULL; |
Aidan Thornton | 3b5fa92 | 2008-04-13 15:09:36 -0300 | [diff] [blame] | 276 | return; |
Mauro Carvalho Chehab | dbecb44 | 2008-04-13 15:08:55 -0300 | [diff] [blame] | 277 | } |
| 278 | |
Mauro Carvalho Chehab | dbecb44 | 2008-04-13 15:08:55 -0300 | [diff] [blame] | 279 | /* Get the next buffer */ |
| 280 | *buf = list_entry(dma_q->active.next, struct em28xx_buffer, vb.queue); |
| 281 | |
Mauro Carvalho Chehab | dbecb44 | 2008-04-13 15:08:55 -0300 | [diff] [blame] | 282 | /* Cleans up buffer - Usefull for testing for frame/URB loss */ |
| 283 | outp = videobuf_to_vmalloc(&(*buf)->vb); |
| 284 | memset(outp, 0, (*buf)->vb.size); |
Mauro Carvalho Chehab | cb78472 | 2008-04-13 15:06:52 -0300 | [diff] [blame] | 285 | |
| 286 | dev->isoc_ctl.buf = *buf; |
| 287 | |
Aidan Thornton | 3b5fa92 | 2008-04-13 15:09:36 -0300 | [diff] [blame] | 288 | return; |
Mauro Carvalho Chehab | ad0ebb9 | 2008-04-13 14:37:52 -0300 | [diff] [blame] | 289 | } |
| 290 | |
| 291 | /* |
| 292 | * Controls the isoc copy of each urb packet |
| 293 | */ |
Aidan Thornton | 579f72e | 2008-04-17 21:40:16 -0300 | [diff] [blame] | 294 | 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] | 295 | { |
Aidan Thornton | d7aa802 | 2008-04-13 14:38:47 -0300 | [diff] [blame] | 296 | struct em28xx_buffer *buf; |
Mauro Carvalho Chehab | ad0ebb9 | 2008-04-13 14:37:52 -0300 | [diff] [blame] | 297 | struct em28xx_dmaqueue *dma_q = urb->context; |
Aidan Thornton | 3b5fa92 | 2008-04-13 15:09:36 -0300 | [diff] [blame] | 298 | unsigned char *outp = NULL; |
Mauro Carvalho Chehab | ad0ebb9 | 2008-04-13 14:37:52 -0300 | [diff] [blame] | 299 | int i, len = 0, rc = 1; |
Aidan Thornton | d7aa802 | 2008-04-13 14:38:47 -0300 | [diff] [blame] | 300 | unsigned char *p; |
Mauro Carvalho Chehab | ad0ebb9 | 2008-04-13 14:37:52 -0300 | [diff] [blame] | 301 | |
| 302 | if (!dev) |
| 303 | return 0; |
| 304 | |
| 305 | if ((dev->state & DEV_DISCONNECTED) || (dev->state & DEV_MISCONFIGURED)) |
| 306 | return 0; |
| 307 | |
Mauro Carvalho Chehab | f245e54 | 2008-04-13 14:41:23 -0300 | [diff] [blame] | 308 | if (urb->status < 0) { |
| 309 | print_err_status(dev, -1, urb->status); |
Mauro Carvalho Chehab | ad0ebb9 | 2008-04-13 14:37:52 -0300 | [diff] [blame] | 310 | if (urb->status == -ENOENT) |
| 311 | return 0; |
| 312 | } |
| 313 | |
Aidan Thornton | 3b5fa92 | 2008-04-13 15:09:36 -0300 | [diff] [blame] | 314 | buf = dev->isoc_ctl.buf; |
| 315 | if (buf != NULL) |
| 316 | outp = videobuf_to_vmalloc(&buf->vb); |
Aidan Thornton | d7aa802 | 2008-04-13 14:38:47 -0300 | [diff] [blame] | 317 | |
Mauro Carvalho Chehab | ad0ebb9 | 2008-04-13 14:37:52 -0300 | [diff] [blame] | 318 | for (i = 0; i < urb->number_of_packets; i++) { |
| 319 | int status = urb->iso_frame_desc[i].status; |
| 320 | |
Mauro Carvalho Chehab | f245e54 | 2008-04-13 14:41:23 -0300 | [diff] [blame] | 321 | if (status < 0) { |
| 322 | print_err_status(dev, i, status); |
Mauro Carvalho Chehab | ad0ebb9 | 2008-04-13 14:37:52 -0300 | [diff] [blame] | 323 | if (urb->iso_frame_desc[i].status != -EPROTO) |
| 324 | continue; |
| 325 | } |
| 326 | |
Mauro Carvalho Chehab | f245e54 | 2008-04-13 14:41:23 -0300 | [diff] [blame] | 327 | len = urb->iso_frame_desc[i].actual_length - 4; |
Mauro Carvalho Chehab | ad0ebb9 | 2008-04-13 14:37:52 -0300 | [diff] [blame] | 328 | |
| 329 | if (urb->iso_frame_desc[i].actual_length <= 0) { |
Aidan Thornton | d7aa802 | 2008-04-13 14:38:47 -0300 | [diff] [blame] | 330 | /* em28xx_isocdbg("packet %d is empty",i); - spammy */ |
Mauro Carvalho Chehab | ad0ebb9 | 2008-04-13 14:37:52 -0300 | [diff] [blame] | 331 | continue; |
| 332 | } |
| 333 | if (urb->iso_frame_desc[i].actual_length > |
| 334 | dev->max_pkt_size) { |
| 335 | em28xx_isocdbg("packet bigger than packet size"); |
| 336 | continue; |
| 337 | } |
| 338 | |
| 339 | p = urb->transfer_buffer + urb->iso_frame_desc[i].offset; |
Mauro Carvalho Chehab | ad0ebb9 | 2008-04-13 14:37:52 -0300 | [diff] [blame] | 340 | |
| 341 | /* FIXME: incomplete buffer checks where removed to make |
| 342 | logic simpler. Impacts of those changes should be evaluated |
| 343 | */ |
Mauro Carvalho Chehab | b4916f8 | 2008-04-13 15:09:14 -0300 | [diff] [blame] | 344 | if (p[0] == 0x33 && p[1] == 0x95 && p[2] == 0x00) { |
| 345 | em28xx_isocdbg("VBI HEADER!!!\n"); |
| 346 | /* FIXME: Should add vbi copy */ |
| 347 | continue; |
| 348 | } |
Aidan Thornton | d7aa802 | 2008-04-13 14:38:47 -0300 | [diff] [blame] | 349 | if (p[0] == 0x22 && p[1] == 0x5a) { |
Mauro Carvalho Chehab | 78bb394 | 2008-04-13 14:56:25 -0300 | [diff] [blame] | 350 | em28xx_isocdbg("Video frame %d, length=%i, %s\n", p[2], |
| 351 | len, (p[2] & 1)? "odd" : "even"); |
Mauro Carvalho Chehab | ad0ebb9 | 2008-04-13 14:37:52 -0300 | [diff] [blame] | 352 | |
Aidan Thornton | 3b5fa92 | 2008-04-13 15:09:36 -0300 | [diff] [blame] | 353 | if (!(p[2] & 1)) { |
| 354 | if (buf != NULL) |
| 355 | buffer_filled(dev, dma_q, buf); |
| 356 | get_next_buf(dma_q, &buf); |
| 357 | if (buf == NULL) |
| 358 | outp = NULL; |
| 359 | else |
| 360 | outp = videobuf_to_vmalloc(&buf->vb); |
Aidan Thornton | e0fadfd34 | 2008-04-13 14:56:02 -0300 | [diff] [blame] | 361 | } |
Aidan Thornton | 3b5fa92 | 2008-04-13 15:09:36 -0300 | [diff] [blame] | 362 | |
| 363 | if (buf != NULL) { |
| 364 | if (p[2] & 1) |
| 365 | buf->top_field = 0; |
| 366 | else |
| 367 | buf->top_field = 1; |
| 368 | } |
Mauro Carvalho Chehab | b4916f8 | 2008-04-13 15:09:14 -0300 | [diff] [blame] | 369 | |
Mauro Carvalho Chehab | ad0ebb9 | 2008-04-13 14:37:52 -0300 | [diff] [blame] | 370 | dma_q->pos = 0; |
Mauro Carvalho Chehab | ad0ebb9 | 2008-04-13 14:37:52 -0300 | [diff] [blame] | 371 | } |
Aidan Thornton | 3b5fa92 | 2008-04-13 15:09:36 -0300 | [diff] [blame] | 372 | if (buf != NULL) |
| 373 | em28xx_copy_video(dev, dma_q, buf, p, outp, len); |
Mauro Carvalho Chehab | ad0ebb9 | 2008-04-13 14:37:52 -0300 | [diff] [blame] | 374 | } |
| 375 | return rc; |
| 376 | } |
| 377 | |
| 378 | /* ------------------------------------------------------------------ |
Mauro Carvalho Chehab | ad0ebb9 | 2008-04-13 14:37:52 -0300 | [diff] [blame] | 379 | Videobuf operations |
| 380 | ------------------------------------------------------------------*/ |
| 381 | |
| 382 | static int |
| 383 | buffer_setup(struct videobuf_queue *vq, unsigned int *count, unsigned int *size) |
| 384 | { |
| 385 | struct em28xx_fh *fh = vq->priv_data; |
Mauro Carvalho Chehab | d2d9fbf | 2008-04-17 21:38:53 -0300 | [diff] [blame] | 386 | struct em28xx *dev = fh->dev; |
| 387 | struct v4l2_frequency f; |
Mauro Carvalho Chehab | ad0ebb9 | 2008-04-13 14:37:52 -0300 | [diff] [blame] | 388 | |
Aidan Thornton | d7aa802 | 2008-04-13 14:38:47 -0300 | [diff] [blame] | 389 | *size = 16 * fh->dev->width * fh->dev->height >> 3; |
Mauro Carvalho Chehab | ad0ebb9 | 2008-04-13 14:37:52 -0300 | [diff] [blame] | 390 | if (0 == *count) |
| 391 | *count = EM28XX_DEF_BUF; |
| 392 | |
Mauro Carvalho Chehab | f245e54 | 2008-04-13 14:41:23 -0300 | [diff] [blame] | 393 | if (*count < EM28XX_MIN_BUF) |
| 394 | *count = EM28XX_MIN_BUF; |
Mauro Carvalho Chehab | ad0ebb9 | 2008-04-13 14:37:52 -0300 | [diff] [blame] | 395 | |
Mauro Carvalho Chehab | d2d9fbf | 2008-04-17 21:38:53 -0300 | [diff] [blame] | 396 | /* Ask tuner to go to analog mode */ |
Douglas Schilling Landgraf | 6ea54d9 | 2008-04-17 21:41:10 -0300 | [diff] [blame] | 397 | memset(&f, 0, sizeof(f)); |
Mauro Carvalho Chehab | d2d9fbf | 2008-04-17 21:38:53 -0300 | [diff] [blame] | 398 | f.frequency = dev->ctl_freq; |
| 399 | |
| 400 | em28xx_i2c_call_clients(dev, VIDIOC_S_FREQUENCY, &f); |
| 401 | |
Mauro Carvalho Chehab | ad0ebb9 | 2008-04-13 14:37:52 -0300 | [diff] [blame] | 402 | return 0; |
| 403 | } |
| 404 | |
Aidan Thornton | 3b5fa92 | 2008-04-13 15:09:36 -0300 | [diff] [blame] | 405 | /* 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] | 406 | static void free_buffer(struct videobuf_queue *vq, struct em28xx_buffer *buf) |
| 407 | { |
Aidan Thornton | 3b5fa92 | 2008-04-13 15:09:36 -0300 | [diff] [blame] | 408 | struct em28xx_fh *fh = vq->priv_data; |
| 409 | struct em28xx *dev = fh->dev; |
| 410 | unsigned long flags = 0; |
Mauro Carvalho Chehab | ad0ebb9 | 2008-04-13 14:37:52 -0300 | [diff] [blame] | 411 | if (in_interrupt()) |
| 412 | BUG(); |
| 413 | |
Aidan Thornton | 3b5fa92 | 2008-04-13 15:09:36 -0300 | [diff] [blame] | 414 | /* We used to wait for the buffer to finish here, but this didn't work |
| 415 | because, as we were keeping the state as VIDEOBUF_QUEUED, |
| 416 | videobuf_queue_cancel marked it as finished for us. |
| 417 | (Also, it could wedge forever if the hardware was misconfigured.) |
| 418 | |
| 419 | This should be safe; by the time we get here, the buffer isn't |
| 420 | queued anymore. If we ever start marking the buffers as |
| 421 | VIDEOBUF_ACTIVE, it won't be, though. |
| 422 | */ |
| 423 | spin_lock_irqsave(&dev->slock, flags); |
| 424 | if (dev->isoc_ctl.buf == buf) |
| 425 | dev->isoc_ctl.buf = NULL; |
| 426 | spin_unlock_irqrestore(&dev->slock, flags); |
| 427 | |
Mauro Carvalho Chehab | ad0ebb9 | 2008-04-13 14:37:52 -0300 | [diff] [blame] | 428 | videobuf_vmalloc_free(&buf->vb); |
| 429 | buf->vb.state = VIDEOBUF_NEEDS_INIT; |
| 430 | } |
| 431 | |
| 432 | static int |
| 433 | buffer_prepare(struct videobuf_queue *vq, struct videobuf_buffer *vb, |
| 434 | enum v4l2_field field) |
| 435 | { |
| 436 | struct em28xx_fh *fh = vq->priv_data; |
Mauro Carvalho Chehab | f245e54 | 2008-04-13 14:41:23 -0300 | [diff] [blame] | 437 | struct em28xx_buffer *buf = container_of(vb, struct em28xx_buffer, vb); |
Mauro Carvalho Chehab | ad0ebb9 | 2008-04-13 14:37:52 -0300 | [diff] [blame] | 438 | struct em28xx *dev = fh->dev; |
| 439 | int rc = 0, urb_init = 0; |
Mauro Carvalho Chehab | ad0ebb9 | 2008-04-13 14:37:52 -0300 | [diff] [blame] | 440 | |
Mauro Carvalho Chehab | ad0ebb9 | 2008-04-13 14:37:52 -0300 | [diff] [blame] | 441 | /* FIXME: It assumes depth = 16 */ |
| 442 | /* The only currently supported format is 16 bits/pixel */ |
Aidan Thornton | d7aa802 | 2008-04-13 14:38:47 -0300 | [diff] [blame] | 443 | buf->vb.size = 16 * dev->width * dev->height >> 3; |
Mauro Carvalho Chehab | ad0ebb9 | 2008-04-13 14:37:52 -0300 | [diff] [blame] | 444 | |
| 445 | if (0 != buf->vb.baddr && buf->vb.bsize < buf->vb.size) |
| 446 | return -EINVAL; |
| 447 | |
Brandon Philips | 0561297 | 2008-04-13 14:57:01 -0300 | [diff] [blame] | 448 | buf->vb.width = dev->width; |
| 449 | buf->vb.height = dev->height; |
| 450 | buf->vb.field = field; |
Mauro Carvalho Chehab | ad0ebb9 | 2008-04-13 14:37:52 -0300 | [diff] [blame] | 451 | |
| 452 | if (VIDEOBUF_NEEDS_INIT == buf->vb.state) { |
Aidan Thornton | d7aa802 | 2008-04-13 14:38:47 -0300 | [diff] [blame] | 453 | rc = videobuf_iolock(vq, &buf->vb, NULL); |
| 454 | if (rc < 0) |
Mauro Carvalho Chehab | ad0ebb9 | 2008-04-13 14:37:52 -0300 | [diff] [blame] | 455 | goto fail; |
Mauro Carvalho Chehab | ad0ebb9 | 2008-04-13 14:37:52 -0300 | [diff] [blame] | 456 | } |
| 457 | |
Mauro Carvalho Chehab | ad0ebb9 | 2008-04-13 14:37:52 -0300 | [diff] [blame] | 458 | if (!dev->isoc_ctl.num_bufs) |
Mauro Carvalho Chehab | f245e54 | 2008-04-13 14:41:23 -0300 | [diff] [blame] | 459 | urb_init = 1; |
Mauro Carvalho Chehab | ad0ebb9 | 2008-04-13 14:37:52 -0300 | [diff] [blame] | 460 | |
| 461 | if (urb_init) { |
Aidan Thornton | 579f72e | 2008-04-17 21:40:16 -0300 | [diff] [blame] | 462 | rc = em28xx_init_isoc(dev, EM28XX_NUM_PACKETS, |
| 463 | EM28XX_NUM_BUFS, dev->max_pkt_size, |
Mauro Carvalho Chehab | c67ec53 | 2008-04-17 21:48:00 -0300 | [diff] [blame] | 464 | em28xx_isoc_copy); |
Mauro Carvalho Chehab | f245e54 | 2008-04-13 14:41:23 -0300 | [diff] [blame] | 465 | if (rc < 0) |
Mauro Carvalho Chehab | ad0ebb9 | 2008-04-13 14:37:52 -0300 | [diff] [blame] | 466 | goto fail; |
| 467 | } |
| 468 | |
| 469 | buf->vb.state = VIDEOBUF_PREPARED; |
| 470 | return 0; |
| 471 | |
| 472 | fail: |
Mauro Carvalho Chehab | f245e54 | 2008-04-13 14:41:23 -0300 | [diff] [blame] | 473 | free_buffer(vq, buf); |
Mauro Carvalho Chehab | ad0ebb9 | 2008-04-13 14:37:52 -0300 | [diff] [blame] | 474 | return rc; |
| 475 | } |
| 476 | |
| 477 | static void |
| 478 | buffer_queue(struct videobuf_queue *vq, struct videobuf_buffer *vb) |
| 479 | { |
| 480 | struct em28xx_buffer *buf = container_of(vb, struct em28xx_buffer, vb); |
| 481 | struct em28xx_fh *fh = vq->priv_data; |
Mauro Carvalho Chehab | f245e54 | 2008-04-13 14:41:23 -0300 | [diff] [blame] | 482 | struct em28xx *dev = fh->dev; |
Mauro Carvalho Chehab | ad0ebb9 | 2008-04-13 14:37:52 -0300 | [diff] [blame] | 483 | struct em28xx_dmaqueue *vidq = &dev->vidq; |
Mauro Carvalho Chehab | ad0ebb9 | 2008-04-13 14:37:52 -0300 | [diff] [blame] | 484 | |
Aidan Thornton | d7aa802 | 2008-04-13 14:38:47 -0300 | [diff] [blame] | 485 | buf->vb.state = VIDEOBUF_QUEUED; |
| 486 | list_add_tail(&buf->vb.queue, &vidq->active); |
| 487 | |
Mauro Carvalho Chehab | ad0ebb9 | 2008-04-13 14:37:52 -0300 | [diff] [blame] | 488 | } |
| 489 | |
Douglas Schilling Landgraf | 6ea54d9 | 2008-04-17 21:41:10 -0300 | [diff] [blame] | 490 | static void buffer_release(struct videobuf_queue *vq, |
| 491 | struct videobuf_buffer *vb) |
Mauro Carvalho Chehab | ad0ebb9 | 2008-04-13 14:37:52 -0300 | [diff] [blame] | 492 | { |
Mauro Carvalho Chehab | f245e54 | 2008-04-13 14:41:23 -0300 | [diff] [blame] | 493 | struct em28xx_buffer *buf = container_of(vb, struct em28xx_buffer, vb); |
Mauro Carvalho Chehab | ad0ebb9 | 2008-04-13 14:37:52 -0300 | [diff] [blame] | 494 | struct em28xx_fh *fh = vq->priv_data; |
Mauro Carvalho Chehab | f245e54 | 2008-04-13 14:41:23 -0300 | [diff] [blame] | 495 | struct em28xx *dev = (struct em28xx *)fh->dev; |
Mauro Carvalho Chehab | ad0ebb9 | 2008-04-13 14:37:52 -0300 | [diff] [blame] | 496 | |
Aidan Thornton | d7aa802 | 2008-04-13 14:38:47 -0300 | [diff] [blame] | 497 | em28xx_isocdbg("em28xx: called buffer_release\n"); |
Mauro Carvalho Chehab | ad0ebb9 | 2008-04-13 14:37:52 -0300 | [diff] [blame] | 498 | |
Mauro Carvalho Chehab | f245e54 | 2008-04-13 14:41:23 -0300 | [diff] [blame] | 499 | free_buffer(vq, buf); |
Mauro Carvalho Chehab | ad0ebb9 | 2008-04-13 14:37:52 -0300 | [diff] [blame] | 500 | } |
| 501 | |
| 502 | static struct videobuf_queue_ops em28xx_video_qops = { |
| 503 | .buf_setup = buffer_setup, |
| 504 | .buf_prepare = buffer_prepare, |
| 505 | .buf_queue = buffer_queue, |
| 506 | .buf_release = buffer_release, |
| 507 | }; |
akpm@osdl.org | a6c2ba2 | 2005-11-08 21:37:07 -0800 | [diff] [blame] | 508 | |
Douglas Schilling Landgraf | 6ea54d9 | 2008-04-17 21:41:10 -0300 | [diff] [blame] | 509 | /********************* v4l2 interface **************************************/ |
akpm@osdl.org | a6c2ba2 | 2005-11-08 21:37:07 -0800 | [diff] [blame] | 510 | |
akpm@osdl.org | a6c2ba2 | 2005-11-08 21:37:07 -0800 | [diff] [blame] | 511 | /* |
Mauro Carvalho Chehab | 3acf280 | 2005-11-08 21:38:27 -0800 | [diff] [blame] | 512 | * em28xx_config() |
akpm@osdl.org | a6c2ba2 | 2005-11-08 21:37:07 -0800 | [diff] [blame] | 513 | * inits registers with sane defaults |
| 514 | */ |
Mauro Carvalho Chehab | 3acf280 | 2005-11-08 21:38:27 -0800 | [diff] [blame] | 515 | static int em28xx_config(struct em28xx *dev) |
akpm@osdl.org | a6c2ba2 | 2005-11-08 21:37:07 -0800 | [diff] [blame] | 516 | { |
Douglas Schilling Landgraf | f2a01a0 | 2008-09-08 03:27:20 -0300 | [diff] [blame] | 517 | int retval; |
akpm@osdl.org | a6c2ba2 | 2005-11-08 21:37:07 -0800 | [diff] [blame] | 518 | |
| 519 | /* Sets I2C speed to 100 KHz */ |
Mauro Carvalho Chehab | 505b6d0 | 2008-11-25 09:39:50 -0300 | [diff] [blame] | 520 | if (!dev->board.is_em2800) { |
Mauro Carvalho Chehab | 2a29a0d | 2008-11-26 16:28:42 -0300 | [diff] [blame] | 521 | retval = em28xx_write_reg(dev, EM28XX_R06_I2C_CLK, 0x40); |
Douglas Schilling Landgraf | f2a01a0 | 2008-09-08 03:27:20 -0300 | [diff] [blame] | 522 | if (retval < 0) { |
| 523 | em28xx_errdev("%s: em28xx_write_regs_req failed! retval [%d]\n", |
| 524 | __func__, retval); |
| 525 | return retval; |
| 526 | } |
| 527 | } |
akpm@osdl.org | a6c2ba2 | 2005-11-08 21:37:07 -0800 | [diff] [blame] | 528 | |
| 529 | /* enable vbi capturing */ |
Mauro Carvalho Chehab | e5589be | 2006-01-23 17:11:08 -0200 | [diff] [blame] | 530 | |
Mauro Carvalho Chehab | 2a29a0d | 2008-11-26 16:28:42 -0300 | [diff] [blame] | 531 | /* em28xx_write_reg(dev, EM28XX_R0E_AUDIOSRC, 0xc0); audio register */ |
| 532 | /* em28xx_write_reg(dev, EM28XX_R0F_XCLK, 0x80); clk register */ |
| 533 | em28xx_write_reg(dev, EM28XX_R11_VINCTRL, 0x51); |
Mauro Carvalho Chehab | e5589be | 2006-01-23 17:11:08 -0200 | [diff] [blame] | 534 | |
akpm@osdl.org | a6c2ba2 | 2005-11-08 21:37:07 -0800 | [diff] [blame] | 535 | dev->mute = 1; /* maybe not the right place... */ |
| 536 | dev->volume = 0x1f; |
Mauro Carvalho Chehab | 539c96d | 2008-01-05 09:53:54 -0300 | [diff] [blame] | 537 | |
Mauro Carvalho Chehab | 3acf280 | 2005-11-08 21:38:27 -0800 | [diff] [blame] | 538 | em28xx_outfmt_set_yuv422(dev); |
| 539 | em28xx_colorlevels_set_default(dev); |
| 540 | em28xx_compression_disable(dev); |
akpm@osdl.org | a6c2ba2 | 2005-11-08 21:37:07 -0800 | [diff] [blame] | 541 | |
| 542 | return 0; |
| 543 | } |
| 544 | |
| 545 | /* |
Mauro Carvalho Chehab | 3acf280 | 2005-11-08 21:38:27 -0800 | [diff] [blame] | 546 | * em28xx_config_i2c() |
akpm@osdl.org | a6c2ba2 | 2005-11-08 21:37:07 -0800 | [diff] [blame] | 547 | * configure i2c attached devices |
| 548 | */ |
Adrian Bunk | 943a490 | 2005-12-01 00:51:35 -0800 | [diff] [blame] | 549 | static void em28xx_config_i2c(struct em28xx *dev) |
akpm@osdl.org | a6c2ba2 | 2005-11-08 21:37:07 -0800 | [diff] [blame] | 550 | { |
Hans Verkuil | c7c0b34 | 2006-04-02 13:35:00 -0300 | [diff] [blame] | 551 | struct v4l2_routing route; |
Devin Heitmueller | 231ffc9 | 2008-12-16 23:09:35 -0300 | [diff] [blame] | 552 | int zero = 0; |
Hans Verkuil | c7c0b34 | 2006-04-02 13:35:00 -0300 | [diff] [blame] | 553 | |
| 554 | route.input = INPUT(dev->ctl_input)->vmux; |
| 555 | route.output = 0; |
Devin Heitmueller | 231ffc9 | 2008-12-16 23:09:35 -0300 | [diff] [blame] | 556 | em28xx_i2c_call_clients(dev, VIDIOC_INT_RESET, &zero); |
Hans Verkuil | c7c0b34 | 2006-04-02 13:35:00 -0300 | [diff] [blame] | 557 | em28xx_i2c_call_clients(dev, VIDIOC_INT_S_VIDEO_ROUTING, &route); |
Mauro Carvalho Chehab | f5762e4 | 2006-03-13 13:31:31 -0300 | [diff] [blame] | 558 | em28xx_i2c_call_clients(dev, VIDIOC_STREAMON, NULL); |
akpm@osdl.org | a6c2ba2 | 2005-11-08 21:37:07 -0800 | [diff] [blame] | 559 | } |
| 560 | |
Mauro Carvalho Chehab | eac9435 | 2005-11-08 21:38:43 -0800 | [diff] [blame] | 561 | static void video_mux(struct em28xx *dev, int index) |
| 562 | { |
Hans Verkuil | c7c0b34 | 2006-04-02 13:35:00 -0300 | [diff] [blame] | 563 | struct v4l2_routing route; |
Mauro Carvalho Chehab | eac9435 | 2005-11-08 21:38:43 -0800 | [diff] [blame] | 564 | |
Hans Verkuil | c7c0b34 | 2006-04-02 13:35:00 -0300 | [diff] [blame] | 565 | route.input = INPUT(index)->vmux; |
| 566 | route.output = 0; |
Mauro Carvalho Chehab | eac9435 | 2005-11-08 21:38:43 -0800 | [diff] [blame] | 567 | dev->ctl_input = index; |
| 568 | dev->ctl_ainput = INPUT(index)->amux; |
Mauro Carvalho Chehab | 35ae6f0 | 2008-11-20 12:40:51 -0300 | [diff] [blame] | 569 | dev->ctl_aoutput = INPUT(index)->aout; |
Mauro Carvalho Chehab | eac9435 | 2005-11-08 21:38:43 -0800 | [diff] [blame] | 570 | |
Mauro Carvalho Chehab | e879b8e | 2008-11-20 13:39:39 -0300 | [diff] [blame] | 571 | if (!dev->ctl_aoutput) |
| 572 | dev->ctl_aoutput = EM28XX_AOUT_MASTER; |
| 573 | |
Hans Verkuil | c7c0b34 | 2006-04-02 13:35:00 -0300 | [diff] [blame] | 574 | em28xx_i2c_call_clients(dev, VIDIOC_INT_S_VIDEO_ROUTING, &route); |
Mauro Carvalho Chehab | eac9435 | 2005-11-08 21:38:43 -0800 | [diff] [blame] | 575 | |
Mauro Carvalho Chehab | 505b6d0 | 2008-11-25 09:39:50 -0300 | [diff] [blame] | 576 | if (dev->board.has_msp34xx) { |
Douglas Schilling Landgraf | 6ea54d9 | 2008-04-17 21:41:10 -0300 | [diff] [blame] | 577 | if (dev->i2s_speed) { |
| 578 | em28xx_i2c_call_clients(dev, VIDIOC_INT_I2S_CLOCK_FREQ, |
| 579 | &dev->i2s_speed); |
| 580 | } |
Hans Verkuil | 2474ed4 | 2006-03-19 12:35:57 -0300 | [diff] [blame] | 581 | route.input = dev->ctl_ainput; |
Hans Verkuil | 0715172 | 2006-04-01 18:03:23 -0300 | [diff] [blame] | 582 | route.output = MSP_OUTPUT(MSP_SC_IN_DSP_SCART1); |
Hans Verkuil | 2474ed4 | 2006-03-19 12:35:57 -0300 | [diff] [blame] | 583 | /* Note: this is msp3400 specific */ |
Douglas Schilling Landgraf | 6ea54d9 | 2008-04-17 21:41:10 -0300 | [diff] [blame] | 584 | em28xx_i2c_call_clients(dev, VIDIOC_INT_S_AUDIO_ROUTING, |
| 585 | &route); |
Mauro Carvalho Chehab | eac9435 | 2005-11-08 21:38:43 -0800 | [diff] [blame] | 586 | } |
Mauro Carvalho Chehab | 539c96d | 2008-01-05 09:53:54 -0300 | [diff] [blame] | 587 | |
Mauro Carvalho Chehab | 00b8730 | 2008-02-06 18:34:13 -0300 | [diff] [blame] | 588 | em28xx_audio_analog_set(dev); |
Mauro Carvalho Chehab | eac9435 | 2005-11-08 21:38:43 -0800 | [diff] [blame] | 589 | } |
| 590 | |
Mauro Carvalho Chehab | a225452 | 2007-11-11 01:08:26 -0300 | [diff] [blame] | 591 | /* Usage lock check functions */ |
| 592 | static int res_get(struct em28xx_fh *fh) |
| 593 | { |
| 594 | struct em28xx *dev = fh->dev; |
| 595 | int rc = 0; |
| 596 | |
| 597 | /* This instance already has stream_on */ |
| 598 | if (fh->stream_on) |
| 599 | return rc; |
| 600 | |
Mauro Carvalho Chehab | a225452 | 2007-11-11 01:08:26 -0300 | [diff] [blame] | 601 | if (dev->stream_on) |
Mauro Carvalho Chehab | 29b5941 | 2008-12-16 20:19:24 -0300 | [diff] [blame] | 602 | return -EBUSY; |
Mauro Carvalho Chehab | a225452 | 2007-11-11 01:08:26 -0300 | [diff] [blame] | 603 | |
Mauro Carvalho Chehab | e74153d | 2008-04-13 14:55:38 -0300 | [diff] [blame] | 604 | dev->stream_on = 1; |
| 605 | fh->stream_on = 1; |
Mauro Carvalho Chehab | a225452 | 2007-11-11 01:08:26 -0300 | [diff] [blame] | 606 | return rc; |
| 607 | } |
| 608 | |
| 609 | static int res_check(struct em28xx_fh *fh) |
| 610 | { |
| 611 | return (fh->stream_on); |
| 612 | } |
| 613 | |
| 614 | static void res_free(struct em28xx_fh *fh) |
| 615 | { |
| 616 | struct em28xx *dev = fh->dev; |
| 617 | |
Mauro Carvalho Chehab | a225452 | 2007-11-11 01:08:26 -0300 | [diff] [blame] | 618 | fh->stream_on = 0; |
| 619 | dev->stream_on = 0; |
Mauro Carvalho Chehab | a225452 | 2007-11-11 01:08:26 -0300 | [diff] [blame] | 620 | } |
| 621 | |
akpm@osdl.org | a6c2ba2 | 2005-11-08 21:37:07 -0800 | [diff] [blame] | 622 | /* |
Mauro Carvalho Chehab | 195a4ef | 2007-11-11 13:17:17 -0300 | [diff] [blame] | 623 | * em28xx_get_ctrl() |
| 624 | * return the current saturation, brightness or contrast, mute state |
| 625 | */ |
| 626 | static int em28xx_get_ctrl(struct em28xx *dev, struct v4l2_control *ctrl) |
| 627 | { |
| 628 | switch (ctrl->id) { |
| 629 | case V4L2_CID_AUDIO_MUTE: |
| 630 | ctrl->value = dev->mute; |
| 631 | return 0; |
| 632 | case V4L2_CID_AUDIO_VOLUME: |
| 633 | ctrl->value = dev->volume; |
| 634 | return 0; |
| 635 | default: |
| 636 | return -EINVAL; |
| 637 | } |
| 638 | } |
| 639 | |
| 640 | /* |
| 641 | * em28xx_set_ctrl() |
| 642 | * mute or set new saturation, brightness or contrast |
| 643 | */ |
| 644 | static int em28xx_set_ctrl(struct em28xx *dev, const struct v4l2_control *ctrl) |
| 645 | { |
| 646 | switch (ctrl->id) { |
| 647 | case V4L2_CID_AUDIO_MUTE: |
| 648 | if (ctrl->value != dev->mute) { |
| 649 | dev->mute = ctrl->value; |
Mauro Carvalho Chehab | 195a4ef | 2007-11-11 13:17:17 -0300 | [diff] [blame] | 650 | return em28xx_audio_analog_set(dev); |
| 651 | } |
| 652 | return 0; |
| 653 | case V4L2_CID_AUDIO_VOLUME: |
| 654 | dev->volume = ctrl->value; |
| 655 | return em28xx_audio_analog_set(dev); |
| 656 | default: |
| 657 | return -EINVAL; |
| 658 | } |
| 659 | } |
| 660 | |
Mauro Carvalho Chehab | 195a4ef | 2007-11-11 13:17:17 -0300 | [diff] [blame] | 661 | static int check_dev(struct em28xx *dev) |
| 662 | { |
| 663 | if (dev->state & DEV_DISCONNECTED) { |
| 664 | em28xx_errdev("v4l2 ioctl: device not present\n"); |
| 665 | return -ENODEV; |
| 666 | } |
| 667 | |
| 668 | if (dev->state & DEV_MISCONFIGURED) { |
| 669 | em28xx_errdev("v4l2 ioctl: device is misconfigured; " |
| 670 | "close and open it again\n"); |
| 671 | return -EIO; |
| 672 | } |
| 673 | return 0; |
| 674 | } |
| 675 | |
| 676 | static void get_scale(struct em28xx *dev, |
| 677 | unsigned int width, unsigned int height, |
| 678 | unsigned int *hscale, unsigned int *vscale) |
| 679 | { |
| 680 | unsigned int maxw = norm_maxw(dev); |
| 681 | unsigned int maxh = norm_maxh(dev); |
| 682 | |
| 683 | *hscale = (((unsigned long)maxw) << 12) / width - 4096L; |
| 684 | if (*hscale >= 0x4000) |
| 685 | *hscale = 0x3fff; |
| 686 | |
| 687 | *vscale = (((unsigned long)maxh) << 12) / height - 4096L; |
| 688 | if (*vscale >= 0x4000) |
| 689 | *vscale = 0x3fff; |
| 690 | } |
| 691 | |
| 692 | /* ------------------------------------------------------------------ |
| 693 | IOCTL vidioc handling |
| 694 | ------------------------------------------------------------------*/ |
| 695 | |
Hans Verkuil | 78b526a | 2008-05-28 12:16:41 -0300 | [diff] [blame] | 696 | 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] | 697 | struct v4l2_format *f) |
| 698 | { |
| 699 | struct em28xx_fh *fh = priv; |
| 700 | struct em28xx *dev = fh->dev; |
| 701 | |
| 702 | mutex_lock(&dev->lock); |
| 703 | |
| 704 | f->fmt.pix.width = dev->width; |
| 705 | f->fmt.pix.height = dev->height; |
| 706 | f->fmt.pix.pixelformat = V4L2_PIX_FMT_YUYV; |
Mauro Carvalho Chehab | 44dc733 | 2008-04-13 15:11:08 -0300 | [diff] [blame] | 707 | f->fmt.pix.bytesperline = dev->width * 2; |
| 708 | f->fmt.pix.sizeimage = f->fmt.pix.bytesperline * dev->height; |
Mauro Carvalho Chehab | 195a4ef | 2007-11-11 13:17:17 -0300 | [diff] [blame] | 709 | f->fmt.pix.colorspace = V4L2_COLORSPACE_SMPTE170M; |
| 710 | |
| 711 | /* FIXME: TOP? NONE? BOTTOM? ALTENATE? */ |
| 712 | f->fmt.pix.field = dev->interlaced ? |
| 713 | V4L2_FIELD_INTERLACED : V4L2_FIELD_TOP; |
| 714 | |
| 715 | mutex_unlock(&dev->lock); |
| 716 | return 0; |
| 717 | } |
| 718 | |
Hans Verkuil | 78b526a | 2008-05-28 12:16:41 -0300 | [diff] [blame] | 719 | 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] | 720 | struct v4l2_format *f) |
| 721 | { |
| 722 | struct em28xx_fh *fh = priv; |
| 723 | struct em28xx *dev = fh->dev; |
| 724 | int width = f->fmt.pix.width; |
| 725 | int height = f->fmt.pix.height; |
| 726 | unsigned int maxw = norm_maxw(dev); |
| 727 | unsigned int maxh = norm_maxh(dev); |
| 728 | unsigned int hscale, vscale; |
| 729 | |
| 730 | /* width must even because of the YUYV format |
| 731 | height must be even because of interlacing */ |
| 732 | height &= 0xfffe; |
Mauro Carvalho Chehab | cf8c91c | 2008-12-16 20:36:13 -0300 | [diff] [blame^] | 733 | width &= 0xfffe; |
Mauro Carvalho Chehab | 195a4ef | 2007-11-11 13:17:17 -0300 | [diff] [blame] | 734 | |
Mauro Carvalho Chehab | cf8c91c | 2008-12-16 20:36:13 -0300 | [diff] [blame^] | 735 | if (unlikely(height < 32)) |
Mauro Carvalho Chehab | 195a4ef | 2007-11-11 13:17:17 -0300 | [diff] [blame] | 736 | height = 32; |
Mauro Carvalho Chehab | cf8c91c | 2008-12-16 20:36:13 -0300 | [diff] [blame^] | 737 | if (unlikely(height > maxh)) |
Mauro Carvalho Chehab | 195a4ef | 2007-11-11 13:17:17 -0300 | [diff] [blame] | 738 | height = maxh; |
Mauro Carvalho Chehab | cf8c91c | 2008-12-16 20:36:13 -0300 | [diff] [blame^] | 739 | if (unlikely(width < 48)) |
Mauro Carvalho Chehab | 195a4ef | 2007-11-11 13:17:17 -0300 | [diff] [blame] | 740 | width = 48; |
Mauro Carvalho Chehab | cf8c91c | 2008-12-16 20:36:13 -0300 | [diff] [blame^] | 741 | if (unlikely(width > maxw)) |
Mauro Carvalho Chehab | 195a4ef | 2007-11-11 13:17:17 -0300 | [diff] [blame] | 742 | width = maxw; |
| 743 | |
Mauro Carvalho Chehab | 505b6d0 | 2008-11-25 09:39:50 -0300 | [diff] [blame] | 744 | if (dev->board.is_em2800) { |
Mauro Carvalho Chehab | 195a4ef | 2007-11-11 13:17:17 -0300 | [diff] [blame] | 745 | /* the em2800 can only scale down to 50% */ |
| 746 | if (height % (maxh / 2)) |
| 747 | height = maxh; |
| 748 | if (width % (maxw / 2)) |
| 749 | width = maxw; |
| 750 | /* according to empiatech support */ |
| 751 | /* the MaxPacketSize is to small to support */ |
| 752 | /* framesizes larger than 640x480 @ 30 fps */ |
| 753 | /* or 640x576 @ 25 fps. As this would cut */ |
| 754 | /* of a part of the image we prefer */ |
| 755 | /* 360x576 or 360x480 for now */ |
| 756 | if (width == maxw && height == maxh) |
| 757 | width /= 2; |
| 758 | } |
| 759 | |
| 760 | get_scale(dev, width, height, &hscale, &vscale); |
| 761 | |
| 762 | width = (((unsigned long)maxw) << 12) / (hscale + 4096L); |
| 763 | height = (((unsigned long)maxh) << 12) / (vscale + 4096L); |
| 764 | |
| 765 | f->fmt.pix.width = width; |
| 766 | f->fmt.pix.height = height; |
| 767 | f->fmt.pix.pixelformat = V4L2_PIX_FMT_YUYV; |
| 768 | f->fmt.pix.bytesperline = width * 2; |
| 769 | f->fmt.pix.sizeimage = width * 2 * height; |
| 770 | f->fmt.pix.colorspace = V4L2_COLORSPACE_SMPTE170M; |
| 771 | f->fmt.pix.field = V4L2_FIELD_INTERLACED; |
| 772 | |
Mauro Carvalho Chehab | 195a4ef | 2007-11-11 13:17:17 -0300 | [diff] [blame] | 773 | return 0; |
| 774 | } |
| 775 | |
Hans Verkuil | 78b526a | 2008-05-28 12:16:41 -0300 | [diff] [blame] | 776 | 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] | 777 | struct v4l2_format *f) |
| 778 | { |
| 779 | struct em28xx_fh *fh = priv; |
| 780 | struct em28xx *dev = fh->dev; |
Mauro Carvalho Chehab | ad0ebb9 | 2008-04-13 14:37:52 -0300 | [diff] [blame] | 781 | int rc; |
Mauro Carvalho Chehab | 195a4ef | 2007-11-11 13:17:17 -0300 | [diff] [blame] | 782 | |
| 783 | rc = check_dev(dev); |
| 784 | if (rc < 0) |
| 785 | return rc; |
| 786 | |
Hans Verkuil | 78b526a | 2008-05-28 12:16:41 -0300 | [diff] [blame] | 787 | vidioc_try_fmt_vid_cap(file, priv, f); |
Mauro Carvalho Chehab | 195a4ef | 2007-11-11 13:17:17 -0300 | [diff] [blame] | 788 | |
| 789 | mutex_lock(&dev->lock); |
| 790 | |
Brandon Philips | 0561297 | 2008-04-13 14:57:01 -0300 | [diff] [blame] | 791 | if (videobuf_queue_is_busy(&fh->vb_vidq)) { |
| 792 | em28xx_errdev("%s queue busy\n", __func__); |
| 793 | rc = -EBUSY; |
| 794 | goto out; |
| 795 | } |
| 796 | |
Aidan Thornton | 0ea13e6 | 2008-04-13 15:02:24 -0300 | [diff] [blame] | 797 | if (dev->stream_on && !fh->stream_on) { |
| 798 | em28xx_errdev("%s device in use by another fh\n", __func__); |
| 799 | rc = -EBUSY; |
| 800 | goto out; |
| 801 | } |
| 802 | |
Mauro Carvalho Chehab | 195a4ef | 2007-11-11 13:17:17 -0300 | [diff] [blame] | 803 | /* set new image size */ |
| 804 | dev->width = f->fmt.pix.width; |
| 805 | dev->height = f->fmt.pix.height; |
Mauro Carvalho Chehab | 195a4ef | 2007-11-11 13:17:17 -0300 | [diff] [blame] | 806 | get_scale(dev, dev->width, dev->height, &dev->hscale, &dev->vscale); |
| 807 | |
Mauro Carvalho Chehab | 195a4ef | 2007-11-11 13:17:17 -0300 | [diff] [blame] | 808 | em28xx_set_alternate(dev); |
Mauro Carvalho Chehab | 195a4ef | 2007-11-11 13:17:17 -0300 | [diff] [blame] | 809 | em28xx_resolution_set(dev); |
Mauro Carvalho Chehab | 195a4ef | 2007-11-11 13:17:17 -0300 | [diff] [blame] | 810 | |
Brandon Philips | 0561297 | 2008-04-13 14:57:01 -0300 | [diff] [blame] | 811 | rc = 0; |
| 812 | |
| 813 | out: |
Mauro Carvalho Chehab | 195a4ef | 2007-11-11 13:17:17 -0300 | [diff] [blame] | 814 | mutex_unlock(&dev->lock); |
Brandon Philips | 0561297 | 2008-04-13 14:57:01 -0300 | [diff] [blame] | 815 | return rc; |
Mauro Carvalho Chehab | 195a4ef | 2007-11-11 13:17:17 -0300 | [diff] [blame] | 816 | } |
| 817 | |
Douglas Schilling Landgraf | 6ea54d9 | 2008-04-17 21:41:10 -0300 | [diff] [blame] | 818 | 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] | 819 | { |
| 820 | struct em28xx_fh *fh = priv; |
| 821 | struct em28xx *dev = fh->dev; |
| 822 | struct v4l2_format f; |
Mauro Carvalho Chehab | 195a4ef | 2007-11-11 13:17:17 -0300 | [diff] [blame] | 823 | int rc; |
| 824 | |
| 825 | rc = check_dev(dev); |
| 826 | if (rc < 0) |
| 827 | return rc; |
| 828 | |
Mauro Carvalho Chehab | 195a4ef | 2007-11-11 13:17:17 -0300 | [diff] [blame] | 829 | mutex_lock(&dev->lock); |
Mauro Carvalho Chehab | 7d497f8 | 2007-11-11 14:15:34 -0300 | [diff] [blame] | 830 | dev->norm = *norm; |
Mauro Carvalho Chehab | 195a4ef | 2007-11-11 13:17:17 -0300 | [diff] [blame] | 831 | mutex_unlock(&dev->lock); |
| 832 | |
| 833 | /* Adjusts width/height, if needed */ |
| 834 | f.fmt.pix.width = dev->width; |
| 835 | f.fmt.pix.height = dev->height; |
Hans Verkuil | 78b526a | 2008-05-28 12:16:41 -0300 | [diff] [blame] | 836 | vidioc_try_fmt_vid_cap(file, priv, &f); |
Mauro Carvalho Chehab | 195a4ef | 2007-11-11 13:17:17 -0300 | [diff] [blame] | 837 | |
| 838 | mutex_lock(&dev->lock); |
| 839 | |
| 840 | /* set new image size */ |
| 841 | dev->width = f.fmt.pix.width; |
| 842 | dev->height = f.fmt.pix.height; |
Mauro Carvalho Chehab | 195a4ef | 2007-11-11 13:17:17 -0300 | [diff] [blame] | 843 | get_scale(dev, dev->width, dev->height, &dev->hscale, &dev->vscale); |
| 844 | |
| 845 | em28xx_resolution_set(dev); |
Mauro Carvalho Chehab | 7d497f8 | 2007-11-11 14:15:34 -0300 | [diff] [blame] | 846 | em28xx_i2c_call_clients(dev, VIDIOC_S_STD, &dev->norm); |
Mauro Carvalho Chehab | 195a4ef | 2007-11-11 13:17:17 -0300 | [diff] [blame] | 847 | |
| 848 | mutex_unlock(&dev->lock); |
| 849 | return 0; |
| 850 | } |
| 851 | |
| 852 | static const char *iname[] = { |
| 853 | [EM28XX_VMUX_COMPOSITE1] = "Composite1", |
| 854 | [EM28XX_VMUX_COMPOSITE2] = "Composite2", |
| 855 | [EM28XX_VMUX_COMPOSITE3] = "Composite3", |
| 856 | [EM28XX_VMUX_COMPOSITE4] = "Composite4", |
| 857 | [EM28XX_VMUX_SVIDEO] = "S-Video", |
| 858 | [EM28XX_VMUX_TELEVISION] = "Television", |
| 859 | [EM28XX_VMUX_CABLE] = "Cable TV", |
| 860 | [EM28XX_VMUX_DVB] = "DVB", |
| 861 | [EM28XX_VMUX_DEBUG] = "for debug only", |
| 862 | }; |
| 863 | |
| 864 | static int vidioc_enum_input(struct file *file, void *priv, |
| 865 | struct v4l2_input *i) |
| 866 | { |
| 867 | struct em28xx_fh *fh = priv; |
| 868 | struct em28xx *dev = fh->dev; |
| 869 | unsigned int n; |
| 870 | |
| 871 | n = i->index; |
| 872 | if (n >= MAX_EM28XX_INPUT) |
| 873 | return -EINVAL; |
| 874 | if (0 == INPUT(n)->type) |
| 875 | return -EINVAL; |
| 876 | |
| 877 | i->index = n; |
| 878 | i->type = V4L2_INPUT_TYPE_CAMERA; |
| 879 | |
| 880 | strcpy(i->name, iname[INPUT(n)->type]); |
| 881 | |
| 882 | if ((EM28XX_VMUX_TELEVISION == INPUT(n)->type) || |
| 883 | (EM28XX_VMUX_CABLE == INPUT(n)->type)) |
| 884 | i->type = V4L2_INPUT_TYPE_TUNER; |
| 885 | |
Mauro Carvalho Chehab | 7d497f8 | 2007-11-11 14:15:34 -0300 | [diff] [blame] | 886 | i->std = dev->vdev->tvnorms; |
Mauro Carvalho Chehab | 195a4ef | 2007-11-11 13:17:17 -0300 | [diff] [blame] | 887 | |
| 888 | return 0; |
| 889 | } |
| 890 | |
| 891 | static int vidioc_g_input(struct file *file, void *priv, unsigned int *i) |
| 892 | { |
| 893 | struct em28xx_fh *fh = priv; |
| 894 | struct em28xx *dev = fh->dev; |
| 895 | |
| 896 | *i = dev->ctl_input; |
| 897 | |
| 898 | return 0; |
| 899 | } |
| 900 | |
| 901 | static int vidioc_s_input(struct file *file, void *priv, unsigned int i) |
| 902 | { |
| 903 | struct em28xx_fh *fh = priv; |
| 904 | struct em28xx *dev = fh->dev; |
| 905 | int rc; |
| 906 | |
| 907 | rc = check_dev(dev); |
| 908 | if (rc < 0) |
| 909 | return rc; |
| 910 | |
| 911 | if (i >= MAX_EM28XX_INPUT) |
| 912 | return -EINVAL; |
| 913 | if (0 == INPUT(i)->type) |
| 914 | return -EINVAL; |
| 915 | |
| 916 | mutex_lock(&dev->lock); |
| 917 | |
| 918 | video_mux(dev, i); |
| 919 | |
| 920 | mutex_unlock(&dev->lock); |
| 921 | return 0; |
| 922 | } |
| 923 | |
| 924 | static int vidioc_g_audio(struct file *file, void *priv, struct v4l2_audio *a) |
| 925 | { |
| 926 | struct em28xx_fh *fh = priv; |
| 927 | struct em28xx *dev = fh->dev; |
Mauro Carvalho Chehab | 195a4ef | 2007-11-11 13:17:17 -0300 | [diff] [blame] | 928 | |
Mauro Carvalho Chehab | 35ae6f0 | 2008-11-20 12:40:51 -0300 | [diff] [blame] | 929 | switch (a->index) { |
| 930 | case EM28XX_AMUX_VIDEO: |
Mauro Carvalho Chehab | 195a4ef | 2007-11-11 13:17:17 -0300 | [diff] [blame] | 931 | strcpy(a->name, "Television"); |
Mauro Carvalho Chehab | 35ae6f0 | 2008-11-20 12:40:51 -0300 | [diff] [blame] | 932 | break; |
| 933 | case EM28XX_AMUX_LINE_IN: |
Mauro Carvalho Chehab | 195a4ef | 2007-11-11 13:17:17 -0300 | [diff] [blame] | 934 | strcpy(a->name, "Line In"); |
Mauro Carvalho Chehab | 35ae6f0 | 2008-11-20 12:40:51 -0300 | [diff] [blame] | 935 | break; |
| 936 | case EM28XX_AMUX_VIDEO2: |
| 937 | strcpy(a->name, "Television alt"); |
| 938 | break; |
| 939 | case EM28XX_AMUX_PHONE: |
| 940 | strcpy(a->name, "Phone"); |
| 941 | break; |
| 942 | case EM28XX_AMUX_MIC: |
| 943 | strcpy(a->name, "Mic"); |
| 944 | break; |
| 945 | case EM28XX_AMUX_CD: |
| 946 | strcpy(a->name, "CD"); |
| 947 | break; |
| 948 | case EM28XX_AMUX_AUX: |
| 949 | strcpy(a->name, "Aux"); |
| 950 | break; |
| 951 | case EM28XX_AMUX_PCM_OUT: |
| 952 | strcpy(a->name, "PCM"); |
| 953 | break; |
| 954 | default: |
| 955 | return -EINVAL; |
| 956 | } |
Douglas Schilling Landgraf | 6ea54d9 | 2008-04-17 21:41:10 -0300 | [diff] [blame] | 957 | |
Mauro Carvalho Chehab | 35ae6f0 | 2008-11-20 12:40:51 -0300 | [diff] [blame] | 958 | a->index = dev->ctl_ainput; |
Mauro Carvalho Chehab | 195a4ef | 2007-11-11 13:17:17 -0300 | [diff] [blame] | 959 | a->capability = V4L2_AUDCAP_STEREO; |
Mauro Carvalho Chehab | 195a4ef | 2007-11-11 13:17:17 -0300 | [diff] [blame] | 960 | |
| 961 | return 0; |
| 962 | } |
| 963 | |
| 964 | static int vidioc_s_audio(struct file *file, void *priv, struct v4l2_audio *a) |
| 965 | { |
| 966 | struct em28xx_fh *fh = priv; |
| 967 | struct em28xx *dev = fh->dev; |
| 968 | |
Mauro Carvalho Chehab | 35ae6f0 | 2008-11-20 12:40:51 -0300 | [diff] [blame] | 969 | dev->ctl_ainput = INPUT(a->index)->amux; |
| 970 | dev->ctl_aoutput = INPUT(a->index)->aout; |
Mauro Carvalho Chehab | e879b8e | 2008-11-20 13:39:39 -0300 | [diff] [blame] | 971 | |
| 972 | if (!dev->ctl_aoutput) |
| 973 | dev->ctl_aoutput = EM28XX_AOUT_MASTER; |
Mauro Carvalho Chehab | 195a4ef | 2007-11-11 13:17:17 -0300 | [diff] [blame] | 974 | return 0; |
| 975 | } |
| 976 | |
| 977 | static int vidioc_queryctrl(struct file *file, void *priv, |
| 978 | struct v4l2_queryctrl *qc) |
| 979 | { |
| 980 | struct em28xx_fh *fh = priv; |
| 981 | struct em28xx *dev = fh->dev; |
| 982 | int id = qc->id; |
| 983 | int i; |
| 984 | int rc; |
| 985 | |
| 986 | rc = check_dev(dev); |
| 987 | if (rc < 0) |
| 988 | return rc; |
| 989 | |
| 990 | memset(qc, 0, sizeof(*qc)); |
| 991 | |
| 992 | qc->id = id; |
| 993 | |
Mauro Carvalho Chehab | 505b6d0 | 2008-11-25 09:39:50 -0300 | [diff] [blame] | 994 | if (!dev->board.has_msp34xx) { |
Mauro Carvalho Chehab | 195a4ef | 2007-11-11 13:17:17 -0300 | [diff] [blame] | 995 | for (i = 0; i < ARRAY_SIZE(em28xx_qctrl); i++) { |
| 996 | if (qc->id && qc->id == em28xx_qctrl[i].id) { |
| 997 | memcpy(qc, &(em28xx_qctrl[i]), sizeof(*qc)); |
| 998 | return 0; |
| 999 | } |
| 1000 | } |
| 1001 | } |
| 1002 | mutex_lock(&dev->lock); |
| 1003 | em28xx_i2c_call_clients(dev, VIDIOC_QUERYCTRL, qc); |
| 1004 | mutex_unlock(&dev->lock); |
| 1005 | |
| 1006 | if (qc->type) |
| 1007 | return 0; |
| 1008 | else |
| 1009 | return -EINVAL; |
| 1010 | } |
| 1011 | |
| 1012 | static int vidioc_g_ctrl(struct file *file, void *priv, |
| 1013 | struct v4l2_control *ctrl) |
| 1014 | { |
| 1015 | struct em28xx_fh *fh = priv; |
| 1016 | struct em28xx *dev = fh->dev; |
| 1017 | int rc; |
| 1018 | |
| 1019 | rc = check_dev(dev); |
| 1020 | if (rc < 0) |
| 1021 | return rc; |
| 1022 | mutex_lock(&dev->lock); |
| 1023 | |
Mauro Carvalho Chehab | 505b6d0 | 2008-11-25 09:39:50 -0300 | [diff] [blame] | 1024 | if (!dev->board.has_msp34xx) |
Mauro Carvalho Chehab | 195a4ef | 2007-11-11 13:17:17 -0300 | [diff] [blame] | 1025 | rc = em28xx_get_ctrl(dev, ctrl); |
| 1026 | else |
| 1027 | rc = -EINVAL; |
| 1028 | |
| 1029 | if (rc == -EINVAL) { |
| 1030 | em28xx_i2c_call_clients(dev, VIDIOC_G_CTRL, ctrl); |
| 1031 | rc = 0; |
| 1032 | } |
| 1033 | |
| 1034 | mutex_unlock(&dev->lock); |
| 1035 | return rc; |
| 1036 | } |
| 1037 | |
| 1038 | static int vidioc_s_ctrl(struct file *file, void *priv, |
| 1039 | struct v4l2_control *ctrl) |
| 1040 | { |
| 1041 | struct em28xx_fh *fh = priv; |
| 1042 | struct em28xx *dev = fh->dev; |
| 1043 | u8 i; |
| 1044 | int rc; |
| 1045 | |
| 1046 | rc = check_dev(dev); |
| 1047 | if (rc < 0) |
| 1048 | return rc; |
| 1049 | |
| 1050 | mutex_lock(&dev->lock); |
| 1051 | |
Mauro Carvalho Chehab | 505b6d0 | 2008-11-25 09:39:50 -0300 | [diff] [blame] | 1052 | if (dev->board.has_msp34xx) |
Mauro Carvalho Chehab | 195a4ef | 2007-11-11 13:17:17 -0300 | [diff] [blame] | 1053 | em28xx_i2c_call_clients(dev, VIDIOC_S_CTRL, ctrl); |
| 1054 | else { |
| 1055 | rc = 1; |
| 1056 | for (i = 0; i < ARRAY_SIZE(em28xx_qctrl); i++) { |
| 1057 | if (ctrl->id == em28xx_qctrl[i].id) { |
| 1058 | if (ctrl->value < em28xx_qctrl[i].minimum || |
| 1059 | ctrl->value > em28xx_qctrl[i].maximum) { |
| 1060 | rc = -ERANGE; |
| 1061 | break; |
| 1062 | } |
| 1063 | |
| 1064 | rc = em28xx_set_ctrl(dev, ctrl); |
| 1065 | break; |
| 1066 | } |
| 1067 | } |
| 1068 | } |
| 1069 | |
| 1070 | /* Control not found - try to send it to the attached devices */ |
| 1071 | if (rc == 1) { |
| 1072 | em28xx_i2c_call_clients(dev, VIDIOC_S_CTRL, ctrl); |
| 1073 | rc = 0; |
| 1074 | } |
| 1075 | |
| 1076 | mutex_unlock(&dev->lock); |
| 1077 | return rc; |
| 1078 | } |
| 1079 | |
| 1080 | static int vidioc_g_tuner(struct file *file, void *priv, |
| 1081 | struct v4l2_tuner *t) |
| 1082 | { |
| 1083 | struct em28xx_fh *fh = priv; |
| 1084 | struct em28xx *dev = fh->dev; |
| 1085 | int rc; |
| 1086 | |
| 1087 | rc = check_dev(dev); |
| 1088 | if (rc < 0) |
| 1089 | return rc; |
| 1090 | |
| 1091 | if (0 != t->index) |
| 1092 | return -EINVAL; |
| 1093 | |
| 1094 | strcpy(t->name, "Tuner"); |
| 1095 | |
| 1096 | mutex_lock(&dev->lock); |
| 1097 | |
| 1098 | em28xx_i2c_call_clients(dev, VIDIOC_G_TUNER, t); |
| 1099 | |
| 1100 | mutex_unlock(&dev->lock); |
| 1101 | return 0; |
| 1102 | } |
| 1103 | |
| 1104 | static int vidioc_s_tuner(struct file *file, void *priv, |
| 1105 | struct v4l2_tuner *t) |
| 1106 | { |
| 1107 | struct em28xx_fh *fh = priv; |
| 1108 | struct em28xx *dev = fh->dev; |
| 1109 | int rc; |
| 1110 | |
| 1111 | rc = check_dev(dev); |
| 1112 | if (rc < 0) |
| 1113 | return rc; |
| 1114 | |
| 1115 | if (0 != t->index) |
| 1116 | return -EINVAL; |
| 1117 | |
| 1118 | mutex_lock(&dev->lock); |
| 1119 | |
| 1120 | em28xx_i2c_call_clients(dev, VIDIOC_S_TUNER, t); |
| 1121 | |
| 1122 | mutex_unlock(&dev->lock); |
| 1123 | return 0; |
| 1124 | } |
| 1125 | |
| 1126 | static int vidioc_g_frequency(struct file *file, void *priv, |
| 1127 | struct v4l2_frequency *f) |
| 1128 | { |
| 1129 | struct em28xx_fh *fh = priv; |
| 1130 | struct em28xx *dev = fh->dev; |
| 1131 | |
Mauro Carvalho Chehab | 0be4375 | 2008-01-05 17:22:01 -0300 | [diff] [blame] | 1132 | f->type = fh->radio ? V4L2_TUNER_RADIO : V4L2_TUNER_ANALOG_TV; |
Mauro Carvalho Chehab | 195a4ef | 2007-11-11 13:17:17 -0300 | [diff] [blame] | 1133 | f->frequency = dev->ctl_freq; |
| 1134 | |
| 1135 | return 0; |
| 1136 | } |
| 1137 | |
| 1138 | static int vidioc_s_frequency(struct file *file, void *priv, |
| 1139 | struct v4l2_frequency *f) |
| 1140 | { |
| 1141 | struct em28xx_fh *fh = priv; |
| 1142 | struct em28xx *dev = fh->dev; |
| 1143 | int rc; |
| 1144 | |
| 1145 | rc = check_dev(dev); |
| 1146 | if (rc < 0) |
| 1147 | return rc; |
| 1148 | |
| 1149 | if (0 != f->tuner) |
| 1150 | return -EINVAL; |
| 1151 | |
Mauro Carvalho Chehab | 0be4375 | 2008-01-05 17:22:01 -0300 | [diff] [blame] | 1152 | if (unlikely(0 == fh->radio && f->type != V4L2_TUNER_ANALOG_TV)) |
| 1153 | return -EINVAL; |
| 1154 | if (unlikely(1 == fh->radio && f->type != V4L2_TUNER_RADIO)) |
Mauro Carvalho Chehab | 195a4ef | 2007-11-11 13:17:17 -0300 | [diff] [blame] | 1155 | return -EINVAL; |
| 1156 | |
| 1157 | mutex_lock(&dev->lock); |
| 1158 | |
| 1159 | dev->ctl_freq = f->frequency; |
| 1160 | em28xx_i2c_call_clients(dev, VIDIOC_S_FREQUENCY, f); |
| 1161 | |
| 1162 | mutex_unlock(&dev->lock); |
| 1163 | return 0; |
| 1164 | } |
| 1165 | |
Mauro Carvalho Chehab | 1e7ad56 | 2008-02-06 09:00:41 -0300 | [diff] [blame] | 1166 | #ifdef CONFIG_VIDEO_ADV_DEBUG |
| 1167 | static int em28xx_reg_len(int reg) |
| 1168 | { |
| 1169 | switch (reg) { |
Mauro Carvalho Chehab | 41facaa | 2008-04-17 21:44:58 -0300 | [diff] [blame] | 1170 | case EM28XX_R40_AC97LSB: |
| 1171 | case EM28XX_R30_HSCALELOW: |
| 1172 | case EM28XX_R32_VSCALELOW: |
Mauro Carvalho Chehab | 1e7ad56 | 2008-02-06 09:00:41 -0300 | [diff] [blame] | 1173 | return 2; |
| 1174 | default: |
| 1175 | return 1; |
| 1176 | } |
| 1177 | } |
| 1178 | |
| 1179 | static int vidioc_g_register(struct file *file, void *priv, |
| 1180 | struct v4l2_register *reg) |
| 1181 | { |
| 1182 | struct em28xx_fh *fh = priv; |
| 1183 | struct em28xx *dev = fh->dev; |
| 1184 | int ret; |
| 1185 | |
| 1186 | if (!v4l2_chip_match_host(reg->match_type, reg->match_chip)) |
| 1187 | return -EINVAL; |
| 1188 | |
| 1189 | if (em28xx_reg_len(reg->reg) == 1) { |
| 1190 | ret = em28xx_read_reg(dev, reg->reg); |
| 1191 | if (ret < 0) |
| 1192 | return ret; |
| 1193 | |
| 1194 | reg->val = ret; |
| 1195 | } else { |
Al Viro | a954b66 | 2008-05-21 00:32:51 -0300 | [diff] [blame] | 1196 | __le64 val = 0; |
Mauro Carvalho Chehab | 1e7ad56 | 2008-02-06 09:00:41 -0300 | [diff] [blame] | 1197 | ret = em28xx_read_reg_req_len(dev, USB_REQ_GET_STATUS, |
| 1198 | reg->reg, (char *)&val, 2); |
| 1199 | if (ret < 0) |
| 1200 | return ret; |
| 1201 | |
Al Viro | a954b66 | 2008-05-21 00:32:51 -0300 | [diff] [blame] | 1202 | reg->val = le64_to_cpu(val); |
Mauro Carvalho Chehab | 1e7ad56 | 2008-02-06 09:00:41 -0300 | [diff] [blame] | 1203 | } |
| 1204 | |
| 1205 | return 0; |
| 1206 | } |
| 1207 | |
| 1208 | static int vidioc_s_register(struct file *file, void *priv, |
| 1209 | struct v4l2_register *reg) |
| 1210 | { |
| 1211 | struct em28xx_fh *fh = priv; |
| 1212 | struct em28xx *dev = fh->dev; |
Al Viro | a954b66 | 2008-05-21 00:32:51 -0300 | [diff] [blame] | 1213 | __le64 buf; |
Mauro Carvalho Chehab | 1e7ad56 | 2008-02-06 09:00:41 -0300 | [diff] [blame] | 1214 | |
Al Viro | a954b66 | 2008-05-21 00:32:51 -0300 | [diff] [blame] | 1215 | buf = cpu_to_le64(reg->val); |
Mauro Carvalho Chehab | 1e7ad56 | 2008-02-06 09:00:41 -0300 | [diff] [blame] | 1216 | |
| 1217 | return em28xx_write_regs(dev, reg->reg, (char *)&buf, |
| 1218 | em28xx_reg_len(reg->reg)); |
| 1219 | } |
| 1220 | #endif |
| 1221 | |
| 1222 | |
Mauro Carvalho Chehab | 195a4ef | 2007-11-11 13:17:17 -0300 | [diff] [blame] | 1223 | static int vidioc_cropcap(struct file *file, void *priv, |
| 1224 | struct v4l2_cropcap *cc) |
| 1225 | { |
| 1226 | struct em28xx_fh *fh = priv; |
| 1227 | struct em28xx *dev = fh->dev; |
| 1228 | |
| 1229 | if (cc->type != V4L2_BUF_TYPE_VIDEO_CAPTURE) |
| 1230 | return -EINVAL; |
| 1231 | |
| 1232 | cc->bounds.left = 0; |
| 1233 | cc->bounds.top = 0; |
| 1234 | cc->bounds.width = dev->width; |
| 1235 | cc->bounds.height = dev->height; |
| 1236 | cc->defrect = cc->bounds; |
| 1237 | cc->pixelaspect.numerator = 54; /* 4:3 FIXME: remove magic numbers */ |
| 1238 | cc->pixelaspect.denominator = 59; |
| 1239 | |
| 1240 | return 0; |
| 1241 | } |
| 1242 | |
| 1243 | static int vidioc_streamon(struct file *file, void *priv, |
| 1244 | enum v4l2_buf_type type) |
| 1245 | { |
| 1246 | struct em28xx_fh *fh = priv; |
| 1247 | struct em28xx *dev = fh->dev; |
| 1248 | int rc; |
| 1249 | |
| 1250 | rc = check_dev(dev); |
| 1251 | if (rc < 0) |
| 1252 | return rc; |
| 1253 | |
Mauro Carvalho Chehab | 195a4ef | 2007-11-11 13:17:17 -0300 | [diff] [blame] | 1254 | |
Mauro Carvalho Chehab | 29b5941 | 2008-12-16 20:19:24 -0300 | [diff] [blame] | 1255 | mutex_lock(&dev->lock); |
| 1256 | rc = res_get(fh); |
| 1257 | mutex_unlock(&dev->lock); |
| 1258 | |
| 1259 | if (unlikely(rc < 0)) |
| 1260 | return rc; |
Mauro Carvalho Chehab | 195a4ef | 2007-11-11 13:17:17 -0300 | [diff] [blame] | 1261 | |
Mauro Carvalho Chehab | ad0ebb9 | 2008-04-13 14:37:52 -0300 | [diff] [blame] | 1262 | return (videobuf_streamon(&fh->vb_vidq)); |
Mauro Carvalho Chehab | 195a4ef | 2007-11-11 13:17:17 -0300 | [diff] [blame] | 1263 | } |
| 1264 | |
| 1265 | static int vidioc_streamoff(struct file *file, void *priv, |
| 1266 | enum v4l2_buf_type type) |
| 1267 | { |
| 1268 | struct em28xx_fh *fh = priv; |
| 1269 | struct em28xx *dev = fh->dev; |
| 1270 | int rc; |
| 1271 | |
| 1272 | rc = check_dev(dev); |
| 1273 | if (rc < 0) |
| 1274 | return rc; |
| 1275 | |
Mauro Carvalho Chehab | ad0ebb9 | 2008-04-13 14:37:52 -0300 | [diff] [blame] | 1276 | if (fh->type != V4L2_BUF_TYPE_VIDEO_CAPTURE) |
| 1277 | return -EINVAL; |
| 1278 | if (type != fh->type) |
Mauro Carvalho Chehab | 195a4ef | 2007-11-11 13:17:17 -0300 | [diff] [blame] | 1279 | return -EINVAL; |
| 1280 | |
Mauro Carvalho Chehab | ad0ebb9 | 2008-04-13 14:37:52 -0300 | [diff] [blame] | 1281 | videobuf_streamoff(&fh->vb_vidq); |
Mauro Carvalho Chehab | 7831364 | 2008-12-16 20:00:49 -0300 | [diff] [blame] | 1282 | mutex_lock(&dev->lock); |
Mauro Carvalho Chehab | ad0ebb9 | 2008-04-13 14:37:52 -0300 | [diff] [blame] | 1283 | res_free(fh); |
Mauro Carvalho Chehab | 7831364 | 2008-12-16 20:00:49 -0300 | [diff] [blame] | 1284 | mutex_unlock(&dev->lock); |
Mauro Carvalho Chehab | 195a4ef | 2007-11-11 13:17:17 -0300 | [diff] [blame] | 1285 | |
Mauro Carvalho Chehab | 195a4ef | 2007-11-11 13:17:17 -0300 | [diff] [blame] | 1286 | return 0; |
| 1287 | } |
| 1288 | |
| 1289 | static int vidioc_querycap(struct file *file, void *priv, |
| 1290 | struct v4l2_capability *cap) |
| 1291 | { |
| 1292 | struct em28xx_fh *fh = priv; |
| 1293 | struct em28xx *dev = fh->dev; |
| 1294 | |
| 1295 | strlcpy(cap->driver, "em28xx", sizeof(cap->driver)); |
| 1296 | strlcpy(cap->card, em28xx_boards[dev->model].name, sizeof(cap->card)); |
Kay Sievers | af128a1 | 2008-10-30 00:51:46 -0300 | [diff] [blame] | 1297 | strlcpy(cap->bus_info, dev_name(&dev->udev->dev), sizeof(cap->bus_info)); |
Mauro Carvalho Chehab | 195a4ef | 2007-11-11 13:17:17 -0300 | [diff] [blame] | 1298 | |
| 1299 | cap->version = EM28XX_VERSION_CODE; |
| 1300 | |
| 1301 | cap->capabilities = |
| 1302 | V4L2_CAP_SLICED_VBI_CAPTURE | |
| 1303 | V4L2_CAP_VIDEO_CAPTURE | |
| 1304 | V4L2_CAP_AUDIO | |
| 1305 | V4L2_CAP_READWRITE | V4L2_CAP_STREAMING; |
| 1306 | |
Mauro Carvalho Chehab | ed08631 | 2008-01-24 06:59:20 -0300 | [diff] [blame] | 1307 | if (dev->tuner_type != TUNER_ABSENT) |
Mauro Carvalho Chehab | 195a4ef | 2007-11-11 13:17:17 -0300 | [diff] [blame] | 1308 | cap->capabilities |= V4L2_CAP_TUNER; |
| 1309 | |
| 1310 | return 0; |
| 1311 | } |
| 1312 | |
Hans Verkuil | 78b526a | 2008-05-28 12:16:41 -0300 | [diff] [blame] | 1313 | static int vidioc_enum_fmt_vid_cap(struct file *file, void *priv, |
Mauro Carvalho Chehab | 195a4ef | 2007-11-11 13:17:17 -0300 | [diff] [blame] | 1314 | struct v4l2_fmtdesc *fmtd) |
| 1315 | { |
| 1316 | if (fmtd->index != 0) |
| 1317 | return -EINVAL; |
| 1318 | |
| 1319 | fmtd->type = V4L2_BUF_TYPE_VIDEO_CAPTURE; |
| 1320 | strcpy(fmtd->description, "Packed YUY2"); |
| 1321 | fmtd->pixelformat = V4L2_PIX_FMT_YUYV; |
| 1322 | memset(fmtd->reserved, 0, sizeof(fmtd->reserved)); |
| 1323 | |
| 1324 | return 0; |
| 1325 | } |
| 1326 | |
| 1327 | /* Sliced VBI ioctls */ |
Hans Verkuil | 78b526a | 2008-05-28 12:16:41 -0300 | [diff] [blame] | 1328 | 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] | 1329 | struct v4l2_format *f) |
| 1330 | { |
| 1331 | struct em28xx_fh *fh = priv; |
| 1332 | struct em28xx *dev = fh->dev; |
| 1333 | int rc; |
| 1334 | |
| 1335 | rc = check_dev(dev); |
| 1336 | if (rc < 0) |
| 1337 | return rc; |
| 1338 | |
| 1339 | mutex_lock(&dev->lock); |
| 1340 | |
| 1341 | f->fmt.sliced.service_set = 0; |
| 1342 | |
| 1343 | em28xx_i2c_call_clients(dev, VIDIOC_G_FMT, f); |
| 1344 | |
| 1345 | if (f->fmt.sliced.service_set == 0) |
| 1346 | rc = -EINVAL; |
| 1347 | |
| 1348 | mutex_unlock(&dev->lock); |
| 1349 | return rc; |
| 1350 | } |
| 1351 | |
Hans Verkuil | 78b526a | 2008-05-28 12:16:41 -0300 | [diff] [blame] | 1352 | 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] | 1353 | struct v4l2_format *f) |
| 1354 | { |
| 1355 | struct em28xx_fh *fh = priv; |
| 1356 | struct em28xx *dev = fh->dev; |
| 1357 | int rc; |
| 1358 | |
| 1359 | rc = check_dev(dev); |
| 1360 | if (rc < 0) |
| 1361 | return rc; |
| 1362 | |
| 1363 | mutex_lock(&dev->lock); |
| 1364 | em28xx_i2c_call_clients(dev, VIDIOC_G_FMT, f); |
| 1365 | mutex_unlock(&dev->lock); |
| 1366 | |
| 1367 | if (f->fmt.sliced.service_set == 0) |
| 1368 | return -EINVAL; |
| 1369 | |
| 1370 | return 0; |
| 1371 | } |
| 1372 | |
| 1373 | |
| 1374 | static int vidioc_reqbufs(struct file *file, void *priv, |
| 1375 | struct v4l2_requestbuffers *rb) |
| 1376 | { |
| 1377 | struct em28xx_fh *fh = priv; |
| 1378 | struct em28xx *dev = fh->dev; |
Mauro Carvalho Chehab | 195a4ef | 2007-11-11 13:17:17 -0300 | [diff] [blame] | 1379 | int rc; |
| 1380 | |
| 1381 | rc = check_dev(dev); |
| 1382 | if (rc < 0) |
| 1383 | return rc; |
| 1384 | |
Mauro Carvalho Chehab | ad0ebb9 | 2008-04-13 14:37:52 -0300 | [diff] [blame] | 1385 | return (videobuf_reqbufs(&fh->vb_vidq, rb)); |
Mauro Carvalho Chehab | 195a4ef | 2007-11-11 13:17:17 -0300 | [diff] [blame] | 1386 | } |
| 1387 | |
| 1388 | static int vidioc_querybuf(struct file *file, void *priv, |
| 1389 | struct v4l2_buffer *b) |
| 1390 | { |
| 1391 | struct em28xx_fh *fh = priv; |
| 1392 | struct em28xx *dev = fh->dev; |
| 1393 | int rc; |
| 1394 | |
| 1395 | rc = check_dev(dev); |
| 1396 | if (rc < 0) |
| 1397 | return rc; |
| 1398 | |
Mauro Carvalho Chehab | ad0ebb9 | 2008-04-13 14:37:52 -0300 | [diff] [blame] | 1399 | return (videobuf_querybuf(&fh->vb_vidq, b)); |
Mauro Carvalho Chehab | 195a4ef | 2007-11-11 13:17:17 -0300 | [diff] [blame] | 1400 | } |
| 1401 | |
| 1402 | static int vidioc_qbuf(struct file *file, void *priv, struct v4l2_buffer *b) |
| 1403 | { |
| 1404 | struct em28xx_fh *fh = priv; |
| 1405 | struct em28xx *dev = fh->dev; |
Mauro Carvalho Chehab | 195a4ef | 2007-11-11 13:17:17 -0300 | [diff] [blame] | 1406 | int rc; |
| 1407 | |
| 1408 | rc = check_dev(dev); |
| 1409 | if (rc < 0) |
| 1410 | return rc; |
| 1411 | |
Mauro Carvalho Chehab | ad0ebb9 | 2008-04-13 14:37:52 -0300 | [diff] [blame] | 1412 | return (videobuf_qbuf(&fh->vb_vidq, b)); |
Mauro Carvalho Chehab | 195a4ef | 2007-11-11 13:17:17 -0300 | [diff] [blame] | 1413 | } |
| 1414 | |
| 1415 | static int vidioc_dqbuf(struct file *file, void *priv, struct v4l2_buffer *b) |
| 1416 | { |
| 1417 | struct em28xx_fh *fh = priv; |
| 1418 | struct em28xx *dev = fh->dev; |
| 1419 | int rc; |
Mauro Carvalho Chehab | 195a4ef | 2007-11-11 13:17:17 -0300 | [diff] [blame] | 1420 | |
| 1421 | rc = check_dev(dev); |
| 1422 | if (rc < 0) |
| 1423 | return rc; |
| 1424 | |
Mauro Carvalho Chehab | ad0ebb9 | 2008-04-13 14:37:52 -0300 | [diff] [blame] | 1425 | return (videobuf_dqbuf(&fh->vb_vidq, b, |
| 1426 | file->f_flags & O_NONBLOCK)); |
Mauro Carvalho Chehab | 195a4ef | 2007-11-11 13:17:17 -0300 | [diff] [blame] | 1427 | } |
| 1428 | |
Mauro Carvalho Chehab | ad0ebb9 | 2008-04-13 14:37:52 -0300 | [diff] [blame] | 1429 | #ifdef CONFIG_VIDEO_V4L1_COMPAT |
Mauro Carvalho Chehab | f245e54 | 2008-04-13 14:41:23 -0300 | [diff] [blame] | 1430 | 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] | 1431 | { |
Mauro Carvalho Chehab | f245e54 | 2008-04-13 14:41:23 -0300 | [diff] [blame] | 1432 | struct em28xx_fh *fh = priv; |
Mauro Carvalho Chehab | ad0ebb9 | 2008-04-13 14:37:52 -0300 | [diff] [blame] | 1433 | |
Mauro Carvalho Chehab | f245e54 | 2008-04-13 14:41:23 -0300 | [diff] [blame] | 1434 | return videobuf_cgmbuf(&fh->vb_vidq, mbuf, 8); |
Mauro Carvalho Chehab | ad0ebb9 | 2008-04-13 14:37:52 -0300 | [diff] [blame] | 1435 | } |
| 1436 | #endif |
| 1437 | |
| 1438 | |
Mauro Carvalho Chehab | 0be4375 | 2008-01-05 17:22:01 -0300 | [diff] [blame] | 1439 | /* ----------------------------------------------------------- */ |
| 1440 | /* RADIO ESPECIFIC IOCTLS */ |
| 1441 | /* ----------------------------------------------------------- */ |
| 1442 | |
| 1443 | static int radio_querycap(struct file *file, void *priv, |
| 1444 | struct v4l2_capability *cap) |
| 1445 | { |
| 1446 | struct em28xx *dev = ((struct em28xx_fh *)priv)->dev; |
| 1447 | |
| 1448 | strlcpy(cap->driver, "em28xx", sizeof(cap->driver)); |
| 1449 | strlcpy(cap->card, em28xx_boards[dev->model].name, sizeof(cap->card)); |
Kay Sievers | af128a1 | 2008-10-30 00:51:46 -0300 | [diff] [blame] | 1450 | strlcpy(cap->bus_info, dev_name(&dev->udev->dev), sizeof(cap->bus_info)); |
Mauro Carvalho Chehab | 0be4375 | 2008-01-05 17:22:01 -0300 | [diff] [blame] | 1451 | |
| 1452 | cap->version = EM28XX_VERSION_CODE; |
| 1453 | cap->capabilities = V4L2_CAP_TUNER; |
| 1454 | return 0; |
| 1455 | } |
| 1456 | |
| 1457 | static int radio_g_tuner(struct file *file, void *priv, |
| 1458 | struct v4l2_tuner *t) |
| 1459 | { |
| 1460 | struct em28xx *dev = ((struct em28xx_fh *)priv)->dev; |
| 1461 | |
| 1462 | if (unlikely(t->index > 0)) |
| 1463 | return -EINVAL; |
| 1464 | |
| 1465 | strcpy(t->name, "Radio"); |
| 1466 | t->type = V4L2_TUNER_RADIO; |
| 1467 | |
| 1468 | em28xx_i2c_call_clients(dev, VIDIOC_G_TUNER, t); |
| 1469 | return 0; |
| 1470 | } |
| 1471 | |
| 1472 | static int radio_enum_input(struct file *file, void *priv, |
| 1473 | struct v4l2_input *i) |
| 1474 | { |
| 1475 | if (i->index != 0) |
| 1476 | return -EINVAL; |
| 1477 | strcpy(i->name, "Radio"); |
| 1478 | i->type = V4L2_INPUT_TYPE_TUNER; |
| 1479 | |
| 1480 | return 0; |
| 1481 | } |
| 1482 | |
| 1483 | static int radio_g_audio(struct file *file, void *priv, struct v4l2_audio *a) |
| 1484 | { |
| 1485 | if (unlikely(a->index)) |
| 1486 | return -EINVAL; |
| 1487 | |
| 1488 | strcpy(a->name, "Radio"); |
| 1489 | return 0; |
| 1490 | } |
| 1491 | |
| 1492 | static int radio_s_tuner(struct file *file, void *priv, |
| 1493 | struct v4l2_tuner *t) |
| 1494 | { |
| 1495 | struct em28xx *dev = ((struct em28xx_fh *)priv)->dev; |
| 1496 | |
| 1497 | if (0 != t->index) |
| 1498 | return -EINVAL; |
| 1499 | |
| 1500 | em28xx_i2c_call_clients(dev, VIDIOC_S_TUNER, t); |
| 1501 | |
| 1502 | return 0; |
| 1503 | } |
| 1504 | |
| 1505 | static int radio_s_audio(struct file *file, void *fh, |
| 1506 | struct v4l2_audio *a) |
| 1507 | { |
| 1508 | return 0; |
| 1509 | } |
| 1510 | |
| 1511 | static int radio_s_input(struct file *file, void *fh, unsigned int i) |
| 1512 | { |
| 1513 | return 0; |
| 1514 | } |
| 1515 | |
| 1516 | static int radio_queryctrl(struct file *file, void *priv, |
| 1517 | struct v4l2_queryctrl *qc) |
| 1518 | { |
| 1519 | int i; |
| 1520 | |
| 1521 | if (qc->id < V4L2_CID_BASE || |
| 1522 | qc->id >= V4L2_CID_LASTP1) |
| 1523 | return -EINVAL; |
| 1524 | |
| 1525 | for (i = 0; i < ARRAY_SIZE(em28xx_qctrl); i++) { |
| 1526 | if (qc->id && qc->id == em28xx_qctrl[i].id) { |
| 1527 | memcpy(qc, &(em28xx_qctrl[i]), sizeof(*qc)); |
| 1528 | return 0; |
| 1529 | } |
| 1530 | } |
| 1531 | |
| 1532 | return -EINVAL; |
| 1533 | } |
| 1534 | |
Mauro Carvalho Chehab | 195a4ef | 2007-11-11 13:17:17 -0300 | [diff] [blame] | 1535 | /* |
Mauro Carvalho Chehab | 3acf280 | 2005-11-08 21:38:27 -0800 | [diff] [blame] | 1536 | * em28xx_v4l2_open() |
akpm@osdl.org | a6c2ba2 | 2005-11-08 21:37:07 -0800 | [diff] [blame] | 1537 | * inits the device and starts isoc transfer |
| 1538 | */ |
Mauro Carvalho Chehab | 3acf280 | 2005-11-08 21:38:27 -0800 | [diff] [blame] | 1539 | static int em28xx_v4l2_open(struct inode *inode, struct file *filp) |
akpm@osdl.org | a6c2ba2 | 2005-11-08 21:37:07 -0800 | [diff] [blame] | 1540 | { |
akpm@osdl.org | a6c2ba2 | 2005-11-08 21:37:07 -0800 | [diff] [blame] | 1541 | int minor = iminor(inode); |
Mauro Carvalho Chehab | 0be4375 | 2008-01-05 17:22:01 -0300 | [diff] [blame] | 1542 | int errCode = 0, radio = 0; |
Douglas Schilling Landgraf | 6ea54d9 | 2008-04-17 21:41:10 -0300 | [diff] [blame] | 1543 | struct em28xx *h, *dev = NULL; |
Mauro Carvalho Chehab | a3a048c | 2007-11-10 22:21:01 -0300 | [diff] [blame] | 1544 | struct em28xx_fh *fh; |
Aidan Thornton | d7aa802 | 2008-04-13 14:38:47 -0300 | [diff] [blame] | 1545 | enum v4l2_buf_type fh_type = 0; |
Markus Rechberger | 9c75541 | 2005-11-08 21:37:52 -0800 | [diff] [blame] | 1546 | |
Mauro Carvalho Chehab | 818a557 | 2008-11-20 10:30:26 -0300 | [diff] [blame] | 1547 | mutex_lock(&em28xx_devlist_mutex); |
Trent Piepho | a991f44 | 2007-10-10 05:37:43 -0300 | [diff] [blame] | 1548 | list_for_each_entry(h, &em28xx_devlist, devlist) { |
Markus Rechberger | 9c75541 | 2005-11-08 21:37:52 -0800 | [diff] [blame] | 1549 | if (h->vdev->minor == minor) { |
| 1550 | dev = h; |
Aidan Thornton | d7aa802 | 2008-04-13 14:38:47 -0300 | [diff] [blame] | 1551 | fh_type = V4L2_BUF_TYPE_VIDEO_CAPTURE; |
Mauro Carvalho Chehab | e5589be | 2006-01-23 17:11:08 -0200 | [diff] [blame] | 1552 | } |
| 1553 | if (h->vbi_dev->minor == minor) { |
| 1554 | dev = h; |
Aidan Thornton | d7aa802 | 2008-04-13 14:38:47 -0300 | [diff] [blame] | 1555 | fh_type = V4L2_BUF_TYPE_VBI_CAPTURE; |
Markus Rechberger | 9c75541 | 2005-11-08 21:37:52 -0800 | [diff] [blame] | 1556 | } |
Mauro Carvalho Chehab | 0be4375 | 2008-01-05 17:22:01 -0300 | [diff] [blame] | 1557 | if (h->radio_dev && |
| 1558 | h->radio_dev->minor == minor) { |
| 1559 | radio = 1; |
| 1560 | dev = h; |
| 1561 | } |
Markus Rechberger | 9c75541 | 2005-11-08 21:37:52 -0800 | [diff] [blame] | 1562 | } |
Mauro Carvalho Chehab | 818a557 | 2008-11-20 10:30:26 -0300 | [diff] [blame] | 1563 | mutex_unlock(&em28xx_devlist_mutex); |
| 1564 | if (NULL == dev) |
Mauro Carvalho Chehab | e5589be | 2006-01-23 17:11:08 -0200 | [diff] [blame] | 1565 | return -ENODEV; |
Mauro Carvalho Chehab | 818a557 | 2008-11-20 10:30:26 -0300 | [diff] [blame] | 1566 | |
| 1567 | mutex_lock(&dev->lock); |
Markus Rechberger | 9c75541 | 2005-11-08 21:37:52 -0800 | [diff] [blame] | 1568 | |
Mauro Carvalho Chehab | e5589be | 2006-01-23 17:11:08 -0200 | [diff] [blame] | 1569 | em28xx_videodbg("open minor=%d type=%s users=%d\n", |
Aidan Thornton | d7aa802 | 2008-04-13 14:38:47 -0300 | [diff] [blame] | 1570 | minor, v4l2_type_names[fh_type], dev->users); |
akpm@osdl.org | a6c2ba2 | 2005-11-08 21:37:07 -0800 | [diff] [blame] | 1571 | |
akpm@osdl.org | a6c2ba2 | 2005-11-08 21:37:07 -0800 | [diff] [blame] | 1572 | |
Mauro Carvalho Chehab | c67ec53 | 2008-04-17 21:48:00 -0300 | [diff] [blame] | 1573 | fh = kzalloc(sizeof(struct em28xx_fh), GFP_KERNEL); |
Mauro Carvalho Chehab | a3a048c | 2007-11-10 22:21:01 -0300 | [diff] [blame] | 1574 | if (!fh) { |
| 1575 | em28xx_errdev("em28xx-video.c: Out of memory?!\n"); |
Mauro Carvalho Chehab | 818a557 | 2008-11-20 10:30:26 -0300 | [diff] [blame] | 1576 | mutex_unlock(&dev->lock); |
Mauro Carvalho Chehab | a3a048c | 2007-11-10 22:21:01 -0300 | [diff] [blame] | 1577 | return -ENOMEM; |
akpm@osdl.org | a6c2ba2 | 2005-11-08 21:37:07 -0800 | [diff] [blame] | 1578 | } |
Mauro Carvalho Chehab | a3a048c | 2007-11-10 22:21:01 -0300 | [diff] [blame] | 1579 | fh->dev = dev; |
Mauro Carvalho Chehab | 0be4375 | 2008-01-05 17:22:01 -0300 | [diff] [blame] | 1580 | fh->radio = radio; |
Aidan Thornton | d7aa802 | 2008-04-13 14:38:47 -0300 | [diff] [blame] | 1581 | fh->type = fh_type; |
Mauro Carvalho Chehab | a3a048c | 2007-11-10 22:21:01 -0300 | [diff] [blame] | 1582 | filp->private_data = fh; |
akpm@osdl.org | a6c2ba2 | 2005-11-08 21:37:07 -0800 | [diff] [blame] | 1583 | |
Aidan Thornton | d7aa802 | 2008-04-13 14:38:47 -0300 | [diff] [blame] | 1584 | if (fh->type == V4L2_BUF_TYPE_VIDEO_CAPTURE && dev->users == 0) { |
Mauro Carvalho Chehab | e5589be | 2006-01-23 17:11:08 -0200 | [diff] [blame] | 1585 | dev->width = norm_maxw(dev); |
| 1586 | dev->height = norm_maxh(dev); |
Mauro Carvalho Chehab | e5589be | 2006-01-23 17:11:08 -0200 | [diff] [blame] | 1587 | dev->hscale = 0; |
| 1588 | dev->vscale = 0; |
akpm@osdl.org | a6c2ba2 | 2005-11-08 21:37:07 -0800 | [diff] [blame] | 1589 | |
Mauro Carvalho Chehab | c67ec53 | 2008-04-17 21:48:00 -0300 | [diff] [blame] | 1590 | em28xx_set_mode(dev, EM28XX_ANALOG_MODE); |
Mauro Carvalho Chehab | 3687e1e | 2008-02-08 15:44:25 -0300 | [diff] [blame] | 1591 | em28xx_set_alternate(dev); |
Mauro Carvalho Chehab | e5589be | 2006-01-23 17:11:08 -0200 | [diff] [blame] | 1592 | em28xx_resolution_set(dev); |
akpm@osdl.org | a6c2ba2 | 2005-11-08 21:37:07 -0800 | [diff] [blame] | 1593 | |
Mauro Carvalho Chehab | c67ec53 | 2008-04-17 21:48:00 -0300 | [diff] [blame] | 1594 | /* Needed, since GPIO might have disabled power of |
| 1595 | some i2c device |
| 1596 | */ |
| 1597 | em28xx_config_i2c(dev); |
| 1598 | |
Mauro Carvalho Chehab | e5589be | 2006-01-23 17:11:08 -0200 | [diff] [blame] | 1599 | } |
Mauro Carvalho Chehab | 0be4375 | 2008-01-05 17:22:01 -0300 | [diff] [blame] | 1600 | if (fh->radio) { |
| 1601 | em28xx_videodbg("video_open: setting radio device\n"); |
| 1602 | em28xx_i2c_call_clients(dev, AUDC_SET_RADIO, NULL); |
| 1603 | } |
akpm@osdl.org | a6c2ba2 | 2005-11-08 21:37:07 -0800 | [diff] [blame] | 1604 | |
| 1605 | dev->users++; |
akpm@osdl.org | a6c2ba2 | 2005-11-08 21:37:07 -0800 | [diff] [blame] | 1606 | |
Mauro Carvalho Chehab | ad0ebb9 | 2008-04-13 14:37:52 -0300 | [diff] [blame] | 1607 | videobuf_queue_vmalloc_init(&fh->vb_vidq, &em28xx_video_qops, |
| 1608 | NULL, &dev->slock, fh->type, V4L2_FIELD_INTERLACED, |
| 1609 | sizeof(struct em28xx_buffer), fh); |
| 1610 | |
Ingo Molnar | 3593cab | 2006-02-07 06:49:14 -0200 | [diff] [blame] | 1611 | mutex_unlock(&dev->lock); |
Mauro Carvalho Chehab | c67ec53 | 2008-04-17 21:48:00 -0300 | [diff] [blame] | 1612 | |
akpm@osdl.org | a6c2ba2 | 2005-11-08 21:37:07 -0800 | [diff] [blame] | 1613 | return errCode; |
| 1614 | } |
| 1615 | |
| 1616 | /* |
Mauro Carvalho Chehab | 3acf280 | 2005-11-08 21:38:27 -0800 | [diff] [blame] | 1617 | * em28xx_realease_resources() |
akpm@osdl.org | a6c2ba2 | 2005-11-08 21:37:07 -0800 | [diff] [blame] | 1618 | * unregisters the v4l2,i2c and usb devices |
| 1619 | * called when the device gets disconected or at module unload |
| 1620 | */ |
Mauro Carvalho Chehab | 3acf280 | 2005-11-08 21:38:27 -0800 | [diff] [blame] | 1621 | static void em28xx_release_resources(struct em28xx *dev) |
akpm@osdl.org | a6c2ba2 | 2005-11-08 21:37:07 -0800 | [diff] [blame] | 1622 | { |
akpm@osdl.org | a6c2ba2 | 2005-11-08 21:37:07 -0800 | [diff] [blame] | 1623 | |
Mauro Carvalho Chehab | e5589be | 2006-01-23 17:11:08 -0200 | [diff] [blame] | 1624 | /*FIXME: I2C IR should be disconnected */ |
| 1625 | |
Markus Rechberger | 9c75541 | 2005-11-08 21:37:52 -0800 | [diff] [blame] | 1626 | list_del(&dev->devlist); |
Devin Heitmueller | a9fc52b | 2008-06-28 08:57:06 -0300 | [diff] [blame] | 1627 | if (dev->sbutton_input_dev) |
| 1628 | em28xx_deregister_snapshot_button(dev); |
Mauro Carvalho Chehab | a924a49 | 2008-11-12 08:41:29 -0300 | [diff] [blame] | 1629 | |
| 1630 | if (dev->ir) |
| 1631 | em28xx_ir_fini(dev); |
| 1632 | |
Mauro Carvalho Chehab | 0be4375 | 2008-01-05 17:22:01 -0300 | [diff] [blame] | 1633 | if (dev->radio_dev) { |
| 1634 | if (-1 != dev->radio_dev->minor) |
| 1635 | video_unregister_device(dev->radio_dev); |
| 1636 | else |
| 1637 | video_device_release(dev->radio_dev); |
| 1638 | dev->radio_dev = NULL; |
| 1639 | } |
| 1640 | if (dev->vbi_dev) { |
Devin Heitmueller | 4924044 | 2008-11-12 02:05:15 -0300 | [diff] [blame] | 1641 | em28xx_info("V4L2 device /dev/vbi%d deregistered\n", |
| 1642 | dev->vbi_dev->num); |
Mauro Carvalho Chehab | 0be4375 | 2008-01-05 17:22:01 -0300 | [diff] [blame] | 1643 | if (-1 != dev->vbi_dev->minor) |
| 1644 | video_unregister_device(dev->vbi_dev); |
| 1645 | else |
| 1646 | video_device_release(dev->vbi_dev); |
| 1647 | dev->vbi_dev = NULL; |
| 1648 | } |
| 1649 | if (dev->vdev) { |
Devin Heitmueller | 4924044 | 2008-11-12 02:05:15 -0300 | [diff] [blame] | 1650 | em28xx_info("V4L2 device /dev/video%d deregistered\n", |
| 1651 | dev->vdev->num); |
Mauro Carvalho Chehab | 0be4375 | 2008-01-05 17:22:01 -0300 | [diff] [blame] | 1652 | if (-1 != dev->vdev->minor) |
| 1653 | video_unregister_device(dev->vdev); |
| 1654 | else |
| 1655 | video_device_release(dev->vdev); |
| 1656 | dev->vdev = NULL; |
| 1657 | } |
Mauro Carvalho Chehab | 3acf280 | 2005-11-08 21:38:27 -0800 | [diff] [blame] | 1658 | em28xx_i2c_unregister(dev); |
akpm@osdl.org | a6c2ba2 | 2005-11-08 21:37:07 -0800 | [diff] [blame] | 1659 | usb_put_dev(dev->udev); |
Mauro Carvalho Chehab | e5589be | 2006-01-23 17:11:08 -0200 | [diff] [blame] | 1660 | |
Mauro Carvalho Chehab | e5589be | 2006-01-23 17:11:08 -0200 | [diff] [blame] | 1661 | /* Mark device as unused */ |
Douglas Schilling Landgraf | 6ea54d9 | 2008-04-17 21:41:10 -0300 | [diff] [blame] | 1662 | em28xx_devused &= ~(1<<dev->devno); |
akpm@osdl.org | a6c2ba2 | 2005-11-08 21:37:07 -0800 | [diff] [blame] | 1663 | } |
| 1664 | |
| 1665 | /* |
Mauro Carvalho Chehab | 3acf280 | 2005-11-08 21:38:27 -0800 | [diff] [blame] | 1666 | * em28xx_v4l2_close() |
Douglas Schilling Landgraf | 6ea54d9 | 2008-04-17 21:41:10 -0300 | [diff] [blame] | 1667 | * stops streaming and deallocates all resources allocated by the v4l2 |
| 1668 | * calls and ioctls |
akpm@osdl.org | a6c2ba2 | 2005-11-08 21:37:07 -0800 | [diff] [blame] | 1669 | */ |
Mauro Carvalho Chehab | 3acf280 | 2005-11-08 21:38:27 -0800 | [diff] [blame] | 1670 | static int em28xx_v4l2_close(struct inode *inode, struct file *filp) |
akpm@osdl.org | a6c2ba2 | 2005-11-08 21:37:07 -0800 | [diff] [blame] | 1671 | { |
Mauro Carvalho Chehab | a3a048c | 2007-11-10 22:21:01 -0300 | [diff] [blame] | 1672 | struct em28xx_fh *fh = filp->private_data; |
| 1673 | struct em28xx *dev = fh->dev; |
| 1674 | int errCode; |
akpm@osdl.org | a6c2ba2 | 2005-11-08 21:37:07 -0800 | [diff] [blame] | 1675 | |
Mauro Carvalho Chehab | eac9435 | 2005-11-08 21:38:43 -0800 | [diff] [blame] | 1676 | em28xx_videodbg("users=%d\n", dev->users); |
akpm@osdl.org | a6c2ba2 | 2005-11-08 21:37:07 -0800 | [diff] [blame] | 1677 | |
Mauro Carvalho Chehab | a225452 | 2007-11-11 01:08:26 -0300 | [diff] [blame] | 1678 | |
Mauro Carvalho Chehab | 7831364 | 2008-12-16 20:00:49 -0300 | [diff] [blame] | 1679 | mutex_lock(&dev->lock); |
Mauro Carvalho Chehab | a225452 | 2007-11-11 01:08:26 -0300 | [diff] [blame] | 1680 | if (res_check(fh)) |
| 1681 | res_free(fh); |
| 1682 | |
Mauro Carvalho Chehab | a3a048c | 2007-11-10 22:21:01 -0300 | [diff] [blame] | 1683 | if (dev->users == 1) { |
Mauro Carvalho Chehab | ad0ebb9 | 2008-04-13 14:37:52 -0300 | [diff] [blame] | 1684 | videobuf_stop(&fh->vb_vidq); |
| 1685 | videobuf_mmap_free(&fh->vb_vidq); |
akpm@osdl.org | a6c2ba2 | 2005-11-08 21:37:07 -0800 | [diff] [blame] | 1686 | |
Mauro Carvalho Chehab | a3a048c | 2007-11-10 22:21:01 -0300 | [diff] [blame] | 1687 | /* the device is already disconnect, |
| 1688 | free the remaining resources */ |
| 1689 | if (dev->state & DEV_DISCONNECTED) { |
| 1690 | em28xx_release_resources(dev); |
| 1691 | mutex_unlock(&dev->lock); |
| 1692 | kfree(dev); |
| 1693 | return 0; |
| 1694 | } |
| 1695 | |
Mauro Carvalho Chehab | eb6c963 | 2008-12-05 10:39:12 -0300 | [diff] [blame] | 1696 | /* Save some power by putting tuner to sleep */ |
| 1697 | em28xx_i2c_call_clients(dev, TUNER_SET_STANDBY, NULL); |
| 1698 | |
Aidan Thornton | d7aa802 | 2008-04-13 14:38:47 -0300 | [diff] [blame] | 1699 | /* do this before setting alternate! */ |
| 1700 | em28xx_uninit_isoc(dev); |
Mauro Carvalho Chehab | 2fe3e2e | 2008-11-27 09:10:40 -0300 | [diff] [blame] | 1701 | em28xx_set_mode(dev, EM28XX_SUSPEND); |
Aidan Thornton | d7aa802 | 2008-04-13 14:38:47 -0300 | [diff] [blame] | 1702 | |
Mauro Carvalho Chehab | a3a048c | 2007-11-10 22:21:01 -0300 | [diff] [blame] | 1703 | /* set alternate 0 */ |
| 1704 | dev->alt = 0; |
| 1705 | em28xx_videodbg("setting alternate 0\n"); |
| 1706 | errCode = usb_set_interface(dev->udev, 0, 0); |
| 1707 | if (errCode < 0) { |
| 1708 | em28xx_errdev("cannot change alternate number to " |
| 1709 | "0 (error=%i)\n", errCode); |
| 1710 | } |
akpm@osdl.org | a6c2ba2 | 2005-11-08 21:37:07 -0800 | [diff] [blame] | 1711 | } |
Mauro Carvalho Chehab | a3a048c | 2007-11-10 22:21:01 -0300 | [diff] [blame] | 1712 | kfree(fh); |
akpm@osdl.org | a6c2ba2 | 2005-11-08 21:37:07 -0800 | [diff] [blame] | 1713 | dev->users--; |
| 1714 | wake_up_interruptible_nr(&dev->open, 1); |
Ingo Molnar | 3593cab | 2006-02-07 06:49:14 -0200 | [diff] [blame] | 1715 | mutex_unlock(&dev->lock); |
akpm@osdl.org | a6c2ba2 | 2005-11-08 21:37:07 -0800 | [diff] [blame] | 1716 | return 0; |
| 1717 | } |
| 1718 | |
| 1719 | /* |
Mauro Carvalho Chehab | 3acf280 | 2005-11-08 21:38:27 -0800 | [diff] [blame] | 1720 | * em28xx_v4l2_read() |
akpm@osdl.org | a6c2ba2 | 2005-11-08 21:37:07 -0800 | [diff] [blame] | 1721 | * will allocate buffers when called for the first time |
| 1722 | */ |
| 1723 | static ssize_t |
Douglas Schilling Landgraf | 6ea54d9 | 2008-04-17 21:41:10 -0300 | [diff] [blame] | 1724 | 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] | 1725 | loff_t *pos) |
akpm@osdl.org | a6c2ba2 | 2005-11-08 21:37:07 -0800 | [diff] [blame] | 1726 | { |
Mauro Carvalho Chehab | a3a048c | 2007-11-10 22:21:01 -0300 | [diff] [blame] | 1727 | struct em28xx_fh *fh = filp->private_data; |
| 1728 | struct em28xx *dev = fh->dev; |
Mauro Carvalho Chehab | ad0ebb9 | 2008-04-13 14:37:52 -0300 | [diff] [blame] | 1729 | int rc; |
| 1730 | |
| 1731 | rc = check_dev(dev); |
| 1732 | if (rc < 0) |
| 1733 | return rc; |
akpm@osdl.org | a6c2ba2 | 2005-11-08 21:37:07 -0800 | [diff] [blame] | 1734 | |
Mauro Carvalho Chehab | 9e31ced | 2007-11-11 01:13:49 -0300 | [diff] [blame] | 1735 | /* FIXME: read() is not prepared to allow changing the video |
| 1736 | resolution while streaming. Seems a bug at em28xx_set_fmt |
| 1737 | */ |
Mauro Carvalho Chehab | a225452 | 2007-11-11 01:08:26 -0300 | [diff] [blame] | 1738 | |
Mauro Carvalho Chehab | ad0ebb9 | 2008-04-13 14:37:52 -0300 | [diff] [blame] | 1739 | if (fh->type == V4L2_BUF_TYPE_VIDEO_CAPTURE) { |
Mauro Carvalho Chehab | 29b5941 | 2008-12-16 20:19:24 -0300 | [diff] [blame] | 1740 | mutex_lock(&dev->lock); |
| 1741 | rc = res_get(fh); |
| 1742 | mutex_unlock(&dev->lock); |
| 1743 | |
| 1744 | if (unlikely(rc < 0)) |
| 1745 | return rc; |
Mauro Carvalho Chehab | a225452 | 2007-11-11 01:08:26 -0300 | [diff] [blame] | 1746 | |
Mauro Carvalho Chehab | ad0ebb9 | 2008-04-13 14:37:52 -0300 | [diff] [blame] | 1747 | return videobuf_read_stream(&fh->vb_vidq, buf, count, pos, 0, |
| 1748 | filp->f_flags & O_NONBLOCK); |
Mauro Carvalho Chehab | e5589be | 2006-01-23 17:11:08 -0200 | [diff] [blame] | 1749 | } |
Mauro Carvalho Chehab | ad0ebb9 | 2008-04-13 14:37:52 -0300 | [diff] [blame] | 1750 | return 0; |
akpm@osdl.org | a6c2ba2 | 2005-11-08 21:37:07 -0800 | [diff] [blame] | 1751 | } |
| 1752 | |
| 1753 | /* |
Mauro Carvalho Chehab | 3acf280 | 2005-11-08 21:38:27 -0800 | [diff] [blame] | 1754 | * em28xx_v4l2_poll() |
akpm@osdl.org | a6c2ba2 | 2005-11-08 21:37:07 -0800 | [diff] [blame] | 1755 | * will allocate buffers when called for the first time |
| 1756 | */ |
Mauro Carvalho Chehab | 3acf280 | 2005-11-08 21:38:27 -0800 | [diff] [blame] | 1757 | 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] | 1758 | { |
Mauro Carvalho Chehab | a3a048c | 2007-11-10 22:21:01 -0300 | [diff] [blame] | 1759 | struct em28xx_fh *fh = filp->private_data; |
| 1760 | struct em28xx *dev = fh->dev; |
Mauro Carvalho Chehab | ad0ebb9 | 2008-04-13 14:37:52 -0300 | [diff] [blame] | 1761 | int rc; |
| 1762 | |
| 1763 | rc = check_dev(dev); |
| 1764 | if (rc < 0) |
| 1765 | return rc; |
akpm@osdl.org | a6c2ba2 | 2005-11-08 21:37:07 -0800 | [diff] [blame] | 1766 | |
Mauro Carvalho Chehab | 29b5941 | 2008-12-16 20:19:24 -0300 | [diff] [blame] | 1767 | mutex_lock(&dev->lock); |
| 1768 | rc = res_get(fh); |
| 1769 | mutex_unlock(&dev->lock); |
| 1770 | |
| 1771 | if (unlikely(rc < 0)) |
Mauro Carvalho Chehab | a225452 | 2007-11-11 01:08:26 -0300 | [diff] [blame] | 1772 | return POLLERR; |
| 1773 | |
Mauro Carvalho Chehab | ad0ebb9 | 2008-04-13 14:37:52 -0300 | [diff] [blame] | 1774 | if (V4L2_BUF_TYPE_VIDEO_CAPTURE != fh->type) |
| 1775 | return POLLERR; |
akpm@osdl.org | a6c2ba2 | 2005-11-08 21:37:07 -0800 | [diff] [blame] | 1776 | |
Mauro Carvalho Chehab | ad0ebb9 | 2008-04-13 14:37:52 -0300 | [diff] [blame] | 1777 | return videobuf_poll_stream(filp, &fh->vb_vidq, wait); |
akpm@osdl.org | a6c2ba2 | 2005-11-08 21:37:07 -0800 | [diff] [blame] | 1778 | } |
| 1779 | |
| 1780 | /* |
Mauro Carvalho Chehab | 3acf280 | 2005-11-08 21:38:27 -0800 | [diff] [blame] | 1781 | * em28xx_v4l2_mmap() |
akpm@osdl.org | a6c2ba2 | 2005-11-08 21:37:07 -0800 | [diff] [blame] | 1782 | */ |
Mauro Carvalho Chehab | 3acf280 | 2005-11-08 21:38:27 -0800 | [diff] [blame] | 1783 | 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] | 1784 | { |
Mauro Carvalho Chehab | a3a048c | 2007-11-10 22:21:01 -0300 | [diff] [blame] | 1785 | struct em28xx_fh *fh = filp->private_data; |
| 1786 | struct em28xx *dev = fh->dev; |
Mauro Carvalho Chehab | ad0ebb9 | 2008-04-13 14:37:52 -0300 | [diff] [blame] | 1787 | int rc; |
Markus Rechberger | 9c75541 | 2005-11-08 21:37:52 -0800 | [diff] [blame] | 1788 | |
Mauro Carvalho Chehab | ad0ebb9 | 2008-04-13 14:37:52 -0300 | [diff] [blame] | 1789 | rc = check_dev(dev); |
| 1790 | if (rc < 0) |
| 1791 | return rc; |
Mauro Carvalho Chehab | a3a048c | 2007-11-10 22:21:01 -0300 | [diff] [blame] | 1792 | |
Mauro Carvalho Chehab | 29b5941 | 2008-12-16 20:19:24 -0300 | [diff] [blame] | 1793 | mutex_lock(&dev->lock); |
| 1794 | rc = res_get(fh); |
| 1795 | mutex_unlock(&dev->lock); |
| 1796 | |
| 1797 | if (unlikely(rc < 0)) |
| 1798 | return rc; |
| 1799 | |
Mauro Carvalho Chehab | ad0ebb9 | 2008-04-13 14:37:52 -0300 | [diff] [blame] | 1800 | rc = videobuf_mmap_mapper(&fh->vb_vidq, vma); |
akpm@osdl.org | a6c2ba2 | 2005-11-08 21:37:07 -0800 | [diff] [blame] | 1801 | |
Mauro Carvalho Chehab | ad0ebb9 | 2008-04-13 14:37:52 -0300 | [diff] [blame] | 1802 | em28xx_videodbg("vma start=0x%08lx, size=%ld, ret=%d\n", |
| 1803 | (unsigned long)vma->vm_start, |
| 1804 | (unsigned long)vma->vm_end-(unsigned long)vma->vm_start, |
| 1805 | rc); |
akpm@osdl.org | a6c2ba2 | 2005-11-08 21:37:07 -0800 | [diff] [blame] | 1806 | |
Mauro Carvalho Chehab | ad0ebb9 | 2008-04-13 14:37:52 -0300 | [diff] [blame] | 1807 | return rc; |
akpm@osdl.org | a6c2ba2 | 2005-11-08 21:37:07 -0800 | [diff] [blame] | 1808 | } |
| 1809 | |
Arjan van de Ven | fa027c2 | 2007-02-12 00:55:33 -0800 | [diff] [blame] | 1810 | static const struct file_operations em28xx_v4l_fops = { |
Mauro Carvalho Chehab | 195a4ef | 2007-11-11 13:17:17 -0300 | [diff] [blame] | 1811 | .owner = THIS_MODULE, |
| 1812 | .open = em28xx_v4l2_open, |
| 1813 | .release = em28xx_v4l2_close, |
| 1814 | .read = em28xx_v4l2_read, |
| 1815 | .poll = em28xx_v4l2_poll, |
| 1816 | .mmap = em28xx_v4l2_mmap, |
| 1817 | .ioctl = video_ioctl2, |
| 1818 | .llseek = no_llseek, |
| 1819 | .compat_ioctl = v4l_compat_ioctl32, |
akpm@osdl.org | a6c2ba2 | 2005-11-08 21:37:07 -0800 | [diff] [blame] | 1820 | }; |
| 1821 | |
Hans Verkuil | a399810 | 2008-07-21 02:57:38 -0300 | [diff] [blame] | 1822 | static const struct v4l2_ioctl_ops video_ioctl_ops = { |
Mauro Carvalho Chehab | 195a4ef | 2007-11-11 13:17:17 -0300 | [diff] [blame] | 1823 | .vidioc_querycap = vidioc_querycap, |
Hans Verkuil | 78b526a | 2008-05-28 12:16:41 -0300 | [diff] [blame] | 1824 | .vidioc_enum_fmt_vid_cap = vidioc_enum_fmt_vid_cap, |
| 1825 | .vidioc_g_fmt_vid_cap = vidioc_g_fmt_vid_cap, |
| 1826 | .vidioc_try_fmt_vid_cap = vidioc_try_fmt_vid_cap, |
| 1827 | .vidioc_s_fmt_vid_cap = vidioc_s_fmt_vid_cap, |
Mauro Carvalho Chehab | 195a4ef | 2007-11-11 13:17:17 -0300 | [diff] [blame] | 1828 | .vidioc_g_audio = vidioc_g_audio, |
| 1829 | .vidioc_s_audio = vidioc_s_audio, |
| 1830 | .vidioc_cropcap = vidioc_cropcap, |
| 1831 | |
Hans Verkuil | 78b526a | 2008-05-28 12:16:41 -0300 | [diff] [blame] | 1832 | .vidioc_g_fmt_sliced_vbi_cap = vidioc_g_fmt_sliced_vbi_cap, |
| 1833 | .vidioc_try_fmt_sliced_vbi_cap = vidioc_try_set_sliced_vbi_cap, |
| 1834 | .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] | 1835 | |
| 1836 | .vidioc_reqbufs = vidioc_reqbufs, |
| 1837 | .vidioc_querybuf = vidioc_querybuf, |
| 1838 | .vidioc_qbuf = vidioc_qbuf, |
| 1839 | .vidioc_dqbuf = vidioc_dqbuf, |
| 1840 | .vidioc_s_std = vidioc_s_std, |
| 1841 | .vidioc_enum_input = vidioc_enum_input, |
| 1842 | .vidioc_g_input = vidioc_g_input, |
| 1843 | .vidioc_s_input = vidioc_s_input, |
| 1844 | .vidioc_queryctrl = vidioc_queryctrl, |
| 1845 | .vidioc_g_ctrl = vidioc_g_ctrl, |
| 1846 | .vidioc_s_ctrl = vidioc_s_ctrl, |
| 1847 | .vidioc_streamon = vidioc_streamon, |
| 1848 | .vidioc_streamoff = vidioc_streamoff, |
| 1849 | .vidioc_g_tuner = vidioc_g_tuner, |
| 1850 | .vidioc_s_tuner = vidioc_s_tuner, |
| 1851 | .vidioc_g_frequency = vidioc_g_frequency, |
| 1852 | .vidioc_s_frequency = vidioc_s_frequency, |
Mauro Carvalho Chehab | 1e7ad56 | 2008-02-06 09:00:41 -0300 | [diff] [blame] | 1853 | #ifdef CONFIG_VIDEO_ADV_DEBUG |
| 1854 | .vidioc_g_register = vidioc_g_register, |
| 1855 | .vidioc_s_register = vidioc_s_register, |
| 1856 | #endif |
Mauro Carvalho Chehab | ad0ebb9 | 2008-04-13 14:37:52 -0300 | [diff] [blame] | 1857 | #ifdef CONFIG_VIDEO_V4L1_COMPAT |
| 1858 | .vidiocgmbuf = vidiocgmbuf, |
| 1859 | #endif |
Hans Verkuil | a399810 | 2008-07-21 02:57:38 -0300 | [diff] [blame] | 1860 | }; |
| 1861 | |
| 1862 | static const struct video_device em28xx_video_template = { |
| 1863 | .fops = &em28xx_v4l_fops, |
| 1864 | .release = video_device_release, |
| 1865 | .ioctl_ops = &video_ioctl_ops, |
| 1866 | |
| 1867 | .minor = -1, |
Mauro Carvalho Chehab | 195a4ef | 2007-11-11 13:17:17 -0300 | [diff] [blame] | 1868 | |
| 1869 | .tvnorms = V4L2_STD_ALL, |
Mauro Carvalho Chehab | 7d497f8 | 2007-11-11 14:15:34 -0300 | [diff] [blame] | 1870 | .current_norm = V4L2_STD_PAL, |
Mauro Carvalho Chehab | 195a4ef | 2007-11-11 13:17:17 -0300 | [diff] [blame] | 1871 | }; |
| 1872 | |
Hans Verkuil | a399810 | 2008-07-21 02:57:38 -0300 | [diff] [blame] | 1873 | static const struct file_operations radio_fops = { |
| 1874 | .owner = THIS_MODULE, |
| 1875 | .open = em28xx_v4l2_open, |
| 1876 | .release = em28xx_v4l2_close, |
| 1877 | .ioctl = video_ioctl2, |
| 1878 | .compat_ioctl = v4l_compat_ioctl32, |
| 1879 | .llseek = no_llseek, |
| 1880 | }; |
| 1881 | |
| 1882 | static const struct v4l2_ioctl_ops radio_ioctl_ops = { |
Mauro Carvalho Chehab | 0be4375 | 2008-01-05 17:22:01 -0300 | [diff] [blame] | 1883 | .vidioc_querycap = radio_querycap, |
| 1884 | .vidioc_g_tuner = radio_g_tuner, |
| 1885 | .vidioc_enum_input = radio_enum_input, |
| 1886 | .vidioc_g_audio = radio_g_audio, |
| 1887 | .vidioc_s_tuner = radio_s_tuner, |
| 1888 | .vidioc_s_audio = radio_s_audio, |
| 1889 | .vidioc_s_input = radio_s_input, |
| 1890 | .vidioc_queryctrl = radio_queryctrl, |
| 1891 | .vidioc_g_ctrl = vidioc_g_ctrl, |
| 1892 | .vidioc_s_ctrl = vidioc_s_ctrl, |
| 1893 | .vidioc_g_frequency = vidioc_g_frequency, |
| 1894 | .vidioc_s_frequency = vidioc_s_frequency, |
Mauro Carvalho Chehab | 1e7ad56 | 2008-02-06 09:00:41 -0300 | [diff] [blame] | 1895 | #ifdef CONFIG_VIDEO_ADV_DEBUG |
| 1896 | .vidioc_g_register = vidioc_g_register, |
| 1897 | .vidioc_s_register = vidioc_s_register, |
| 1898 | #endif |
Mauro Carvalho Chehab | 0be4375 | 2008-01-05 17:22:01 -0300 | [diff] [blame] | 1899 | }; |
| 1900 | |
Hans Verkuil | a399810 | 2008-07-21 02:57:38 -0300 | [diff] [blame] | 1901 | static struct video_device em28xx_radio_template = { |
| 1902 | .name = "em28xx-radio", |
Hans Verkuil | a399810 | 2008-07-21 02:57:38 -0300 | [diff] [blame] | 1903 | .fops = &radio_fops, |
| 1904 | .ioctl_ops = &radio_ioctl_ops, |
| 1905 | .minor = -1, |
| 1906 | }; |
| 1907 | |
Douglas Schilling Landgraf | 6ea54d9 | 2008-04-17 21:41:10 -0300 | [diff] [blame] | 1908 | /******************************** usb interface ******************************/ |
akpm@osdl.org | a6c2ba2 | 2005-11-08 21:37:07 -0800 | [diff] [blame] | 1909 | |
Mauro Carvalho Chehab | 6d79468 | 2008-01-05 09:57:31 -0300 | [diff] [blame] | 1910 | |
| 1911 | static LIST_HEAD(em28xx_extension_devlist); |
| 1912 | static DEFINE_MUTEX(em28xx_extension_devlist_lock); |
| 1913 | |
| 1914 | int em28xx_register_extension(struct em28xx_ops *ops) |
| 1915 | { |
Devin Heitmueller | 0367ca1 | 2008-06-09 14:58:04 -0300 | [diff] [blame] | 1916 | struct em28xx *dev = NULL; |
Mauro Carvalho Chehab | 6d79468 | 2008-01-05 09:57:31 -0300 | [diff] [blame] | 1917 | |
Mauro Carvalho Chehab | 818a557 | 2008-11-20 10:30:26 -0300 | [diff] [blame] | 1918 | mutex_lock(&em28xx_devlist_mutex); |
Mauro Carvalho Chehab | 6d79468 | 2008-01-05 09:57:31 -0300 | [diff] [blame] | 1919 | mutex_lock(&em28xx_extension_devlist_lock); |
| 1920 | list_add_tail(&ops->next, &em28xx_extension_devlist); |
Devin Heitmueller | 0367ca1 | 2008-06-09 14:58:04 -0300 | [diff] [blame] | 1921 | list_for_each_entry(dev, &em28xx_devlist, devlist) { |
| 1922 | if (dev) |
| 1923 | ops->init(dev); |
| 1924 | } |
Mauro Carvalho Chehab | 6d79468 | 2008-01-05 09:57:31 -0300 | [diff] [blame] | 1925 | printk(KERN_INFO "Em28xx: Initialized (%s) extension\n", ops->name); |
| 1926 | mutex_unlock(&em28xx_extension_devlist_lock); |
Mauro Carvalho Chehab | 818a557 | 2008-11-20 10:30:26 -0300 | [diff] [blame] | 1927 | mutex_unlock(&em28xx_devlist_mutex); |
Mauro Carvalho Chehab | 6d79468 | 2008-01-05 09:57:31 -0300 | [diff] [blame] | 1928 | return 0; |
| 1929 | } |
| 1930 | EXPORT_SYMBOL(em28xx_register_extension); |
| 1931 | |
| 1932 | void em28xx_unregister_extension(struct em28xx_ops *ops) |
| 1933 | { |
Devin Heitmueller | 0367ca1 | 2008-06-09 14:58:04 -0300 | [diff] [blame] | 1934 | struct em28xx *dev = NULL; |
Mauro Carvalho Chehab | 6d79468 | 2008-01-05 09:57:31 -0300 | [diff] [blame] | 1935 | |
Mauro Carvalho Chehab | 818a557 | 2008-11-20 10:30:26 -0300 | [diff] [blame] | 1936 | mutex_lock(&em28xx_devlist_mutex); |
Devin Heitmueller | 0367ca1 | 2008-06-09 14:58:04 -0300 | [diff] [blame] | 1937 | list_for_each_entry(dev, &em28xx_devlist, devlist) { |
| 1938 | if (dev) |
| 1939 | ops->fini(dev); |
| 1940 | } |
Mauro Carvalho Chehab | 6d79468 | 2008-01-05 09:57:31 -0300 | [diff] [blame] | 1941 | |
| 1942 | mutex_lock(&em28xx_extension_devlist_lock); |
| 1943 | printk(KERN_INFO "Em28xx: Removed (%s) extension\n", ops->name); |
| 1944 | list_del(&ops->next); |
| 1945 | mutex_unlock(&em28xx_extension_devlist_lock); |
Mauro Carvalho Chehab | 818a557 | 2008-11-20 10:30:26 -0300 | [diff] [blame] | 1946 | mutex_unlock(&em28xx_devlist_mutex); |
Mauro Carvalho Chehab | 6d79468 | 2008-01-05 09:57:31 -0300 | [diff] [blame] | 1947 | } |
| 1948 | EXPORT_SYMBOL(em28xx_unregister_extension); |
| 1949 | |
Adrian Bunk | 532fe65 | 2008-01-28 22:10:48 -0300 | [diff] [blame] | 1950 | static struct video_device *em28xx_vdev_init(struct em28xx *dev, |
| 1951 | const struct video_device *template, |
Adrian Bunk | 532fe65 | 2008-01-28 22:10:48 -0300 | [diff] [blame] | 1952 | const char *type_name) |
Mauro Carvalho Chehab | 0be4375 | 2008-01-05 17:22:01 -0300 | [diff] [blame] | 1953 | { |
| 1954 | struct video_device *vfd; |
| 1955 | |
| 1956 | vfd = video_device_alloc(); |
| 1957 | if (NULL == vfd) |
| 1958 | return NULL; |
| 1959 | *vfd = *template; |
| 1960 | vfd->minor = -1; |
Hans Verkuil | 5e85e73 | 2008-07-20 06:31:39 -0300 | [diff] [blame] | 1961 | vfd->parent = &dev->udev->dev; |
Mauro Carvalho Chehab | 0be4375 | 2008-01-05 17:22:01 -0300 | [diff] [blame] | 1962 | vfd->release = video_device_release; |
Mauro Carvalho Chehab | e9e6040 | 2008-04-13 15:05:47 -0300 | [diff] [blame] | 1963 | vfd->debug = video_debug; |
Mauro Carvalho Chehab | 0be4375 | 2008-01-05 17:22:01 -0300 | [diff] [blame] | 1964 | |
| 1965 | snprintf(vfd->name, sizeof(vfd->name), "%s %s", |
| 1966 | dev->name, type_name); |
| 1967 | |
| 1968 | return vfd; |
| 1969 | } |
| 1970 | |
Mauro Carvalho Chehab | 818a557 | 2008-11-20 10:30:26 -0300 | [diff] [blame] | 1971 | static int register_analog_devices(struct em28xx *dev) |
| 1972 | { |
| 1973 | int ret; |
| 1974 | |
| 1975 | /* allocate and fill video video_device struct */ |
| 1976 | dev->vdev = em28xx_vdev_init(dev, &em28xx_video_template, "video"); |
| 1977 | if (!dev->vdev) { |
| 1978 | em28xx_errdev("cannot allocate video_device.\n"); |
| 1979 | return -ENODEV; |
| 1980 | } |
| 1981 | |
| 1982 | /* register v4l2 video video_device */ |
| 1983 | ret = video_register_device(dev->vdev, VFL_TYPE_GRABBER, |
| 1984 | video_nr[dev->devno]); |
| 1985 | if (ret) { |
| 1986 | em28xx_errdev("unable to register video device (error=%i).\n", |
| 1987 | ret); |
| 1988 | return ret; |
| 1989 | } |
| 1990 | |
| 1991 | /* Allocate and fill vbi video_device struct */ |
| 1992 | dev->vbi_dev = em28xx_vdev_init(dev, &em28xx_video_template, "vbi"); |
| 1993 | |
| 1994 | /* register v4l2 vbi video_device */ |
| 1995 | ret = video_register_device(dev->vbi_dev, VFL_TYPE_VBI, |
| 1996 | vbi_nr[dev->devno]); |
| 1997 | if (ret < 0) { |
| 1998 | em28xx_errdev("unable to register vbi device\n"); |
| 1999 | return ret; |
| 2000 | } |
| 2001 | |
| 2002 | if (em28xx_boards[dev->model].radio.type == EM28XX_RADIO) { |
| 2003 | dev->radio_dev = em28xx_vdev_init(dev, &em28xx_radio_template, "radio"); |
| 2004 | if (!dev->radio_dev) { |
| 2005 | em28xx_errdev("cannot allocate video_device.\n"); |
| 2006 | return -ENODEV; |
| 2007 | } |
| 2008 | ret = video_register_device(dev->radio_dev, VFL_TYPE_RADIO, |
| 2009 | radio_nr[dev->devno]); |
| 2010 | if (ret < 0) { |
| 2011 | em28xx_errdev("can't register radio device\n"); |
| 2012 | return ret; |
| 2013 | } |
| 2014 | em28xx_info("Registered radio device as /dev/radio%d\n", |
| 2015 | dev->radio_dev->num); |
| 2016 | } |
| 2017 | |
| 2018 | em28xx_info("V4L2 device registered as /dev/video%d and /dev/vbi%d\n", |
| 2019 | dev->vdev->num, dev->vbi_dev->num); |
| 2020 | |
| 2021 | return 0; |
| 2022 | } |
| 2023 | |
| 2024 | |
akpm@osdl.org | a6c2ba2 | 2005-11-08 21:37:07 -0800 | [diff] [blame] | 2025 | /* |
Mauro Carvalho Chehab | 3acf280 | 2005-11-08 21:38:27 -0800 | [diff] [blame] | 2026 | * em28xx_init_dev() |
akpm@osdl.org | a6c2ba2 | 2005-11-08 21:37:07 -0800 | [diff] [blame] | 2027 | * allocates and inits the device structs, registers i2c bus and v4l device |
| 2028 | */ |
Mauro Carvalho Chehab | 3acf280 | 2005-11-08 21:38:27 -0800 | [diff] [blame] | 2029 | static int em28xx_init_dev(struct em28xx **devhandle, struct usb_device *udev, |
Mauro Carvalho Chehab | 03910cc | 2007-11-03 21:20:59 -0300 | [diff] [blame] | 2030 | int minor) |
akpm@osdl.org | a6c2ba2 | 2005-11-08 21:37:07 -0800 | [diff] [blame] | 2031 | { |
Mauro Carvalho Chehab | 6d79468 | 2008-01-05 09:57:31 -0300 | [diff] [blame] | 2032 | struct em28xx_ops *ops = NULL; |
Mauro Carvalho Chehab | 3acf280 | 2005-11-08 21:38:27 -0800 | [diff] [blame] | 2033 | struct em28xx *dev = *devhandle; |
akpm@osdl.org | a6c2ba2 | 2005-11-08 21:37:07 -0800 | [diff] [blame] | 2034 | int retval = -ENOMEM; |
Mauro Carvalho Chehab | 7d497f8 | 2007-11-11 14:15:34 -0300 | [diff] [blame] | 2035 | int errCode; |
akpm@osdl.org | a6c2ba2 | 2005-11-08 21:37:07 -0800 | [diff] [blame] | 2036 | unsigned int maxh, maxw; |
akpm@osdl.org | a6c2ba2 | 2005-11-08 21:37:07 -0800 | [diff] [blame] | 2037 | |
akpm@osdl.org | a6c2ba2 | 2005-11-08 21:37:07 -0800 | [diff] [blame] | 2038 | dev->udev = udev; |
Ingo Molnar | 3593cab | 2006-02-07 06:49:14 -0200 | [diff] [blame] | 2039 | mutex_init(&dev->lock); |
Mauro Carvalho Chehab | f2a2e49 | 2008-11-19 06:17:44 -0300 | [diff] [blame] | 2040 | mutex_init(&dev->ctrl_urb_lock); |
Aidan Thornton | d7aa802 | 2008-04-13 14:38:47 -0300 | [diff] [blame] | 2041 | spin_lock_init(&dev->slock); |
akpm@osdl.org | a6c2ba2 | 2005-11-08 21:37:07 -0800 | [diff] [blame] | 2042 | init_waitqueue_head(&dev->open); |
Mauro Carvalho Chehab | a3a048c | 2007-11-10 22:21:01 -0300 | [diff] [blame] | 2043 | init_waitqueue_head(&dev->wait_frame); |
| 2044 | init_waitqueue_head(&dev->wait_stream); |
akpm@osdl.org | a6c2ba2 | 2005-11-08 21:37:07 -0800 | [diff] [blame] | 2045 | |
Mauro Carvalho Chehab | 3acf280 | 2005-11-08 21:38:27 -0800 | [diff] [blame] | 2046 | dev->em28xx_write_regs = em28xx_write_regs; |
| 2047 | dev->em28xx_read_reg = em28xx_read_reg; |
| 2048 | dev->em28xx_read_reg_req_len = em28xx_read_reg_req_len; |
| 2049 | dev->em28xx_write_regs_req = em28xx_write_regs_req; |
| 2050 | dev->em28xx_read_reg_req = em28xx_read_reg_req; |
Mauro Carvalho Chehab | 505b6d0 | 2008-11-25 09:39:50 -0300 | [diff] [blame] | 2051 | dev->board.is_em2800 = em28xx_boards[dev->model].is_em2800; |
akpm@osdl.org | a6c2ba2 | 2005-11-08 21:37:07 -0800 | [diff] [blame] | 2052 | |
Mauro Carvalho Chehab | 03910cc | 2007-11-03 21:20:59 -0300 | [diff] [blame] | 2053 | em28xx_pre_card_setup(dev); |
| 2054 | |
| 2055 | errCode = em28xx_config(dev); |
| 2056 | if (errCode) { |
| 2057 | em28xx_errdev("error configuring device\n"); |
Mauro Carvalho Chehab | 03910cc | 2007-11-03 21:20:59 -0300 | [diff] [blame] | 2058 | return -ENOMEM; |
| 2059 | } |
| 2060 | |
Mauro Carvalho Chehab | 03910cc | 2007-11-03 21:20:59 -0300 | [diff] [blame] | 2061 | /* register i2c bus */ |
Douglas Schilling Landgraf | f2a01a0 | 2008-09-08 03:27:20 -0300 | [diff] [blame] | 2062 | errCode = em28xx_i2c_register(dev); |
| 2063 | if (errCode < 0) { |
| 2064 | em28xx_errdev("%s: em28xx_i2c_register - errCode [%d]!\n", |
| 2065 | __func__, errCode); |
| 2066 | return errCode; |
| 2067 | } |
Mauro Carvalho Chehab | 03910cc | 2007-11-03 21:20:59 -0300 | [diff] [blame] | 2068 | |
| 2069 | /* Do board specific init and eeprom reading */ |
| 2070 | em28xx_card_setup(dev); |
| 2071 | |
Mauro Carvalho Chehab | 3abee53 | 2008-01-05 17:01:41 -0300 | [diff] [blame] | 2072 | /* Configure audio */ |
Mauro Carvalho Chehab | 3564394 | 2008-11-19 12:01:33 -0300 | [diff] [blame] | 2073 | errCode = em28xx_audio_setup(dev); |
Douglas Schilling Landgraf | f2a01a0 | 2008-09-08 03:27:20 -0300 | [diff] [blame] | 2074 | if (errCode < 0) { |
Mauro Carvalho Chehab | 3564394 | 2008-11-19 12:01:33 -0300 | [diff] [blame] | 2075 | em28xx_errdev("%s: Error while setting audio - errCode [%d]!\n", |
Douglas Schilling Landgraf | f2a01a0 | 2008-09-08 03:27:20 -0300 | [diff] [blame] | 2076 | __func__, errCode); |
Douglas Schilling Landgraf | f2a01a0 | 2008-09-08 03:27:20 -0300 | [diff] [blame] | 2077 | } |
Mauro Carvalho Chehab | 3abee53 | 2008-01-05 17:01:41 -0300 | [diff] [blame] | 2078 | |
Mauro Carvalho Chehab | 03910cc | 2007-11-03 21:20:59 -0300 | [diff] [blame] | 2079 | /* configure the device */ |
| 2080 | em28xx_config_i2c(dev); |
| 2081 | |
Mauro Carvalho Chehab | 7d497f8 | 2007-11-11 14:15:34 -0300 | [diff] [blame] | 2082 | /* set default norm */ |
| 2083 | dev->norm = em28xx_video_template.current_norm; |
akpm@osdl.org | a6c2ba2 | 2005-11-08 21:37:07 -0800 | [diff] [blame] | 2084 | |
| 2085 | maxw = norm_maxw(dev); |
| 2086 | maxh = norm_maxh(dev); |
| 2087 | |
| 2088 | /* set default image size */ |
| 2089 | dev->width = maxw; |
| 2090 | dev->height = maxh; |
Mauro Carvalho Chehab | 3acf280 | 2005-11-08 21:38:27 -0800 | [diff] [blame] | 2091 | dev->interlaced = EM28XX_INTERLACED_DEFAULT; |
akpm@osdl.org | a6c2ba2 | 2005-11-08 21:37:07 -0800 | [diff] [blame] | 2092 | dev->hscale = 0; |
| 2093 | dev->vscale = 0; |
| 2094 | dev->ctl_input = 2; |
| 2095 | |
Mauro Carvalho Chehab | 3acf280 | 2005-11-08 21:38:27 -0800 | [diff] [blame] | 2096 | errCode = em28xx_config(dev); |
Douglas Schilling Landgraf | f2a01a0 | 2008-09-08 03:27:20 -0300 | [diff] [blame] | 2097 | if (errCode < 0) { |
| 2098 | em28xx_errdev("%s: em28xx_config - errCode [%d]!\n", |
| 2099 | __func__, errCode); |
| 2100 | return errCode; |
| 2101 | } |
akpm@osdl.org | a6c2ba2 | 2005-11-08 21:37:07 -0800 | [diff] [blame] | 2102 | |
Mauro Carvalho Chehab | ad0ebb9 | 2008-04-13 14:37:52 -0300 | [diff] [blame] | 2103 | /* init video dma queues */ |
| 2104 | INIT_LIST_HEAD(&dev->vidq.active); |
| 2105 | INIT_LIST_HEAD(&dev->vidq.queued); |
| 2106 | |
akpm@osdl.org | a6c2ba2 | 2005-11-08 21:37:07 -0800 | [diff] [blame] | 2107 | |
Mauro Carvalho Chehab | 505b6d0 | 2008-11-25 09:39:50 -0300 | [diff] [blame] | 2108 | if (dev->board.has_msp34xx) { |
Sascha Sommer | 5a80415 | 2007-11-03 21:22:38 -0300 | [diff] [blame] | 2109 | /* Send a reset to other chips via gpio */ |
Mauro Carvalho Chehab | 2a29a0d | 2008-11-26 16:28:42 -0300 | [diff] [blame] | 2110 | errCode = em28xx_write_reg(dev, EM28XX_R08_GPIO, 0xf7); |
Douglas Schilling Landgraf | f2a01a0 | 2008-09-08 03:27:20 -0300 | [diff] [blame] | 2111 | if (errCode < 0) { |
| 2112 | em28xx_errdev("%s: em28xx_write_regs_req - msp34xx(1) failed! errCode [%d]\n", |
| 2113 | __func__, errCode); |
| 2114 | return errCode; |
| 2115 | } |
Sascha Sommer | 5a80415 | 2007-11-03 21:22:38 -0300 | [diff] [blame] | 2116 | msleep(3); |
Douglas Schilling Landgraf | f2a01a0 | 2008-09-08 03:27:20 -0300 | [diff] [blame] | 2117 | |
Mauro Carvalho Chehab | 2a29a0d | 2008-11-26 16:28:42 -0300 | [diff] [blame] | 2118 | errCode = em28xx_write_reg(dev, EM28XX_R08_GPIO, 0xff); |
Douglas Schilling Landgraf | f2a01a0 | 2008-09-08 03:27:20 -0300 | [diff] [blame] | 2119 | if (errCode < 0) { |
| 2120 | em28xx_errdev("%s: em28xx_write_regs_req - msp34xx(2) failed! errCode [%d]\n", |
| 2121 | __func__, errCode); |
| 2122 | return errCode; |
| 2123 | } |
Sascha Sommer | 5a80415 | 2007-11-03 21:22:38 -0300 | [diff] [blame] | 2124 | msleep(3); |
Sascha Sommer | 5a80415 | 2007-11-03 21:22:38 -0300 | [diff] [blame] | 2125 | } |
Mauro Carvalho Chehab | 195a4ef | 2007-11-11 13:17:17 -0300 | [diff] [blame] | 2126 | |
Sascha Sommer | 5a80415 | 2007-11-03 21:22:38 -0300 | [diff] [blame] | 2127 | video_mux(dev, 0); |
| 2128 | |
Mauro Carvalho Chehab | 818a557 | 2008-11-20 10:30:26 -0300 | [diff] [blame] | 2129 | mutex_lock(&em28xx_devlist_mutex); |
| 2130 | list_add_tail(&dev->devlist, &em28xx_devlist); |
| 2131 | retval = register_analog_devices(dev); |
| 2132 | if (retval < 0) { |
| 2133 | em28xx_release_resources(dev); |
| 2134 | mutex_unlock(&em28xx_devlist_mutex); |
| 2135 | goto fail_reg_devices; |
| 2136 | } |
akpm@osdl.org | a6c2ba2 | 2005-11-08 21:37:07 -0800 | [diff] [blame] | 2137 | |
Mauro Carvalho Chehab | 6d79468 | 2008-01-05 09:57:31 -0300 | [diff] [blame] | 2138 | mutex_lock(&em28xx_extension_devlist_lock); |
| 2139 | if (!list_empty(&em28xx_extension_devlist)) { |
| 2140 | list_for_each_entry(ops, &em28xx_extension_devlist, next) { |
| 2141 | if (ops->id) |
| 2142 | ops->init(dev); |
| 2143 | } |
| 2144 | } |
| 2145 | mutex_unlock(&em28xx_extension_devlist_lock); |
Mauro Carvalho Chehab | 818a557 | 2008-11-20 10:30:26 -0300 | [diff] [blame] | 2146 | mutex_unlock(&em28xx_devlist_mutex); |
Mauro Carvalho Chehab | 6d79468 | 2008-01-05 09:57:31 -0300 | [diff] [blame] | 2147 | |
Mauro Carvalho Chehab | eb6c963 | 2008-12-05 10:39:12 -0300 | [diff] [blame] | 2148 | /* Save some power by putting tuner to sleep */ |
| 2149 | em28xx_i2c_call_clients(dev, TUNER_SET_STANDBY, NULL); |
| 2150 | |
akpm@osdl.org | a6c2ba2 | 2005-11-08 21:37:07 -0800 | [diff] [blame] | 2151 | return 0; |
Mauro Carvalho Chehab | 0be4375 | 2008-01-05 17:22:01 -0300 | [diff] [blame] | 2152 | |
Mauro Carvalho Chehab | 818a557 | 2008-11-20 10:30:26 -0300 | [diff] [blame] | 2153 | fail_reg_devices: |
Mauro Carvalho Chehab | 0be4375 | 2008-01-05 17:22:01 -0300 | [diff] [blame] | 2154 | mutex_unlock(&dev->lock); |
Mauro Carvalho Chehab | 0be4375 | 2008-01-05 17:22:01 -0300 | [diff] [blame] | 2155 | return retval; |
akpm@osdl.org | a6c2ba2 | 2005-11-08 21:37:07 -0800 | [diff] [blame] | 2156 | } |
| 2157 | |
Mauro Carvalho Chehab | d7448a8 | 2008-01-05 09:59:03 -0300 | [diff] [blame] | 2158 | #if defined(CONFIG_MODULES) && defined(MODULE) |
| 2159 | static void request_module_async(struct work_struct *work) |
| 2160 | { |
| 2161 | struct em28xx *dev = container_of(work, |
| 2162 | struct em28xx, request_module_wk); |
| 2163 | |
Mauro Carvalho Chehab | 3f4dfe2 | 2008-01-06 09:54:17 -0300 | [diff] [blame] | 2164 | if (dev->has_audio_class) |
| 2165 | request_module("snd-usb-audio"); |
Devin Heitmueller | 24a613e | 2008-11-12 02:05:19 -0300 | [diff] [blame] | 2166 | else if (dev->has_alsa_audio) |
Mauro Carvalho Chehab | d7448a8 | 2008-01-05 09:59:03 -0300 | [diff] [blame] | 2167 | request_module("em28xx-alsa"); |
Mauro Carvalho Chehab | 3aefb79 | 2008-04-17 21:36:41 -0300 | [diff] [blame] | 2168 | |
Mauro Carvalho Chehab | 505b6d0 | 2008-11-25 09:39:50 -0300 | [diff] [blame] | 2169 | if (dev->board.has_dvb) |
Mauro Carvalho Chehab | 3aefb79 | 2008-04-17 21:36:41 -0300 | [diff] [blame] | 2170 | request_module("em28xx-dvb"); |
Mauro Carvalho Chehab | d7448a8 | 2008-01-05 09:59:03 -0300 | [diff] [blame] | 2171 | } |
| 2172 | |
| 2173 | static void request_modules(struct em28xx *dev) |
| 2174 | { |
| 2175 | INIT_WORK(&dev->request_module_wk, request_module_async); |
| 2176 | schedule_work(&dev->request_module_wk); |
| 2177 | } |
| 2178 | #else |
| 2179 | #define request_modules(dev) |
| 2180 | #endif /* CONFIG_MODULES */ |
| 2181 | |
akpm@osdl.org | a6c2ba2 | 2005-11-08 21:37:07 -0800 | [diff] [blame] | 2182 | /* |
Mauro Carvalho Chehab | 3acf280 | 2005-11-08 21:38:27 -0800 | [diff] [blame] | 2183 | * em28xx_usb_probe() |
akpm@osdl.org | a6c2ba2 | 2005-11-08 21:37:07 -0800 | [diff] [blame] | 2184 | * checks for supported devices |
| 2185 | */ |
Mauro Carvalho Chehab | 3acf280 | 2005-11-08 21:38:27 -0800 | [diff] [blame] | 2186 | static int em28xx_usb_probe(struct usb_interface *interface, |
akpm@osdl.org | a6c2ba2 | 2005-11-08 21:37:07 -0800 | [diff] [blame] | 2187 | const struct usb_device_id *id) |
| 2188 | { |
| 2189 | const struct usb_endpoint_descriptor *endpoint; |
| 2190 | struct usb_device *udev; |
Mauro Carvalho Chehab | 9d4d9c0 | 2005-11-08 21:38:52 -0800 | [diff] [blame] | 2191 | struct usb_interface *uif; |
Mauro Carvalho Chehab | 3acf280 | 2005-11-08 21:38:27 -0800 | [diff] [blame] | 2192 | struct em28xx *dev = NULL; |
akpm@osdl.org | a6c2ba2 | 2005-11-08 21:37:07 -0800 | [diff] [blame] | 2193 | int retval = -ENODEV; |
Devin Heitmueller | 95ea470 | 2008-11-12 02:02:17 -0300 | [diff] [blame] | 2194 | int i, nr, ifnum, isoc_pipe; |
Mauro Carvalho Chehab | 6a18eaf | 2008-11-27 14:32:17 -0300 | [diff] [blame] | 2195 | char *speed; |
Mauro Carvalho Chehab | 8c23998 | 2008-11-28 23:46:43 -0300 | [diff] [blame] | 2196 | char descr[255] = ""; |
akpm@osdl.org | a6c2ba2 | 2005-11-08 21:37:07 -0800 | [diff] [blame] | 2197 | |
| 2198 | udev = usb_get_dev(interface_to_usbdev(interface)); |
Mauro Carvalho Chehab | d5e5265 | 2005-11-08 21:37:32 -0800 | [diff] [blame] | 2199 | ifnum = interface->altsetting[0].desc.bInterfaceNumber; |
| 2200 | |
Mauro Carvalho Chehab | e5589be | 2006-01-23 17:11:08 -0200 | [diff] [blame] | 2201 | /* Check to see next free device and mark as used */ |
Douglas Schilling Landgraf | 6ea54d9 | 2008-04-17 21:41:10 -0300 | [diff] [blame] | 2202 | nr = find_first_zero_bit(&em28xx_devused, EM28XX_MAXBOARDS); |
| 2203 | em28xx_devused |= 1<<nr; |
Mauro Carvalho Chehab | 91cad0f | 2005-11-08 21:38:13 -0800 | [diff] [blame] | 2204 | |
| 2205 | /* Don't register audio interfaces */ |
| 2206 | if (interface->altsetting[0].desc.bInterfaceClass == USB_CLASS_AUDIO) { |
Mauro Carvalho Chehab | 6a18eaf | 2008-11-27 14:32:17 -0300 | [diff] [blame] | 2207 | em28xx_err(DRIVER_NAME " audio device (%04x:%04x): " |
| 2208 | "interface %i, class %i\n", |
| 2209 | le16_to_cpu(udev->descriptor.idVendor), |
| 2210 | le16_to_cpu(udev->descriptor.idProduct), |
| 2211 | ifnum, |
| 2212 | interface->altsetting[0].desc.bInterfaceClass); |
Mauro Carvalho Chehab | e5589be | 2006-01-23 17:11:08 -0200 | [diff] [blame] | 2213 | |
Douglas Schilling Landgraf | 6ea54d9 | 2008-04-17 21:41:10 -0300 | [diff] [blame] | 2214 | em28xx_devused &= ~(1<<nr); |
Mauro Carvalho Chehab | 91cad0f | 2005-11-08 21:38:13 -0800 | [diff] [blame] | 2215 | return -ENODEV; |
| 2216 | } |
| 2217 | |
Devin Heitmueller | 95ea470 | 2008-11-12 02:02:17 -0300 | [diff] [blame] | 2218 | endpoint = &interface->cur_altsetting->endpoint[0].desc; |
Mauro Carvalho Chehab | d5e5265 | 2005-11-08 21:37:32 -0800 | [diff] [blame] | 2219 | |
Michael Opdenacker | 59c5159 | 2007-05-09 08:57:56 +0200 | [diff] [blame] | 2220 | /* check if the device has the iso in endpoint at the correct place */ |
Devin Heitmueller | 95ea470 | 2008-11-12 02:02:17 -0300 | [diff] [blame] | 2221 | if ((endpoint->bmAttributes & USB_ENDPOINT_XFERTYPE_MASK) == |
| 2222 | USB_ENDPOINT_XFER_ISOC && |
| 2223 | (interface->altsetting[1].endpoint[0].desc.wMaxPacketSize == 940)) |
| 2224 | { |
| 2225 | /* It's a newer em2874/em2875 device */ |
| 2226 | isoc_pipe = 0; |
| 2227 | } else { |
Mauro Carvalho Chehab | c9455fb | 2008-11-22 10:50:38 -0300 | [diff] [blame] | 2228 | int check_interface = 1; |
Devin Heitmueller | 95ea470 | 2008-11-12 02:02:17 -0300 | [diff] [blame] | 2229 | isoc_pipe = 1; |
| 2230 | endpoint = &interface->cur_altsetting->endpoint[1].desc; |
| 2231 | if ((endpoint->bmAttributes & USB_ENDPOINT_XFERTYPE_MASK) != |
Mauro Carvalho Chehab | c9455fb | 2008-11-22 10:50:38 -0300 | [diff] [blame] | 2232 | USB_ENDPOINT_XFER_ISOC) |
| 2233 | check_interface = 0; |
| 2234 | |
| 2235 | if ((endpoint->bEndpointAddress & USB_ENDPOINT_DIR_MASK) == USB_DIR_OUT) |
| 2236 | check_interface = 0; |
| 2237 | |
| 2238 | if (!check_interface) { |
| 2239 | em28xx_err(DRIVER_NAME " video device (%04x:%04x): " |
| 2240 | "interface %i, class %i found.\n", |
Mauro Carvalho Chehab | 6a18eaf | 2008-11-27 14:32:17 -0300 | [diff] [blame] | 2241 | le16_to_cpu(udev->descriptor.idVendor), |
| 2242 | le16_to_cpu(udev->descriptor.idProduct), |
Mauro Carvalho Chehab | c9455fb | 2008-11-22 10:50:38 -0300 | [diff] [blame] | 2243 | ifnum, |
| 2244 | interface->altsetting[0].desc.bInterfaceClass); |
| 2245 | |
| 2246 | em28xx_err(DRIVER_NAME " This is an anciliary " |
| 2247 | "interface not used by the driver\n"); |
| 2248 | |
Devin Heitmueller | 95ea470 | 2008-11-12 02:02:17 -0300 | [diff] [blame] | 2249 | em28xx_devused &= ~(1<<nr); |
| 2250 | return -ENODEV; |
| 2251 | } |
akpm@osdl.org | a6c2ba2 | 2005-11-08 21:37:07 -0800 | [diff] [blame] | 2252 | } |
| 2253 | |
Mauro Carvalho Chehab | 6a18eaf | 2008-11-27 14:32:17 -0300 | [diff] [blame] | 2254 | switch (udev->speed) { |
| 2255 | case USB_SPEED_LOW: |
| 2256 | speed = "1.5"; |
| 2257 | break; |
| 2258 | case USB_SPEED_UNKNOWN: |
| 2259 | case USB_SPEED_FULL: |
| 2260 | speed = "12"; |
| 2261 | break; |
| 2262 | case USB_SPEED_HIGH: |
| 2263 | speed = "480"; |
| 2264 | break; |
| 2265 | default: |
| 2266 | speed = "unknown"; |
| 2267 | } |
| 2268 | |
Mauro Carvalho Chehab | 8c23998 | 2008-11-28 23:46:43 -0300 | [diff] [blame] | 2269 | if (udev->manufacturer) |
| 2270 | strlcpy(descr, udev->manufacturer, sizeof(descr)); |
| 2271 | |
| 2272 | if (udev->product) { |
| 2273 | if (*descr) |
| 2274 | strlcat(descr, " ", sizeof(descr)); |
| 2275 | strlcat(descr, udev->product, sizeof(descr)); |
| 2276 | } |
| 2277 | if (*descr) |
| 2278 | strlcat(descr, " ", sizeof(descr)); |
| 2279 | |
| 2280 | printk(DRIVER_NAME ": New device %s@ %s Mbps " |
Mauro Carvalho Chehab | 6a18eaf | 2008-11-27 14:32:17 -0300 | [diff] [blame] | 2281 | "(%04x:%04x, interface %d, class %d)\n", |
Mauro Carvalho Chehab | 8c23998 | 2008-11-28 23:46:43 -0300 | [diff] [blame] | 2282 | descr, |
Mauro Carvalho Chehab | 6a18eaf | 2008-11-27 14:32:17 -0300 | [diff] [blame] | 2283 | speed, |
| 2284 | le16_to_cpu(udev->descriptor.idVendor), |
| 2285 | le16_to_cpu(udev->descriptor.idProduct), |
| 2286 | ifnum, |
| 2287 | interface->altsetting->desc.bInterfaceNumber); |
Mauro Carvalho Chehab | c9455fb | 2008-11-22 10:50:38 -0300 | [diff] [blame] | 2288 | |
Mauro Carvalho Chehab | 1947884 | 2006-03-14 17:24:57 -0300 | [diff] [blame] | 2289 | if (nr >= EM28XX_MAXBOARDS) { |
Douglas Schilling Landgraf | 6ea54d9 | 2008-04-17 21:41:10 -0300 | [diff] [blame] | 2290 | printk(DRIVER_NAME ": Supports only %i em28xx boards.\n", |
| 2291 | EM28XX_MAXBOARDS); |
| 2292 | em28xx_devused &= ~(1<<nr); |
Mauro Carvalho Chehab | 596d92d | 2005-11-08 21:37:24 -0800 | [diff] [blame] | 2293 | return -ENOMEM; |
| 2294 | } |
| 2295 | |
| 2296 | /* allocate memory for our device state and initialize it */ |
Panagiotis Issaris | 7408187 | 2006-01-11 19:40:56 -0200 | [diff] [blame] | 2297 | dev = kzalloc(sizeof(*dev), GFP_KERNEL); |
Mauro Carvalho Chehab | 596d92d | 2005-11-08 21:37:24 -0800 | [diff] [blame] | 2298 | if (dev == NULL) { |
Mauro Carvalho Chehab | 3acf280 | 2005-11-08 21:38:27 -0800 | [diff] [blame] | 2299 | em28xx_err(DRIVER_NAME ": out of memory!\n"); |
Douglas Schilling Landgraf | 6ea54d9 | 2008-04-17 21:41:10 -0300 | [diff] [blame] | 2300 | em28xx_devused &= ~(1<<nr); |
Mauro Carvalho Chehab | 596d92d | 2005-11-08 21:37:24 -0800 | [diff] [blame] | 2301 | return -ENOMEM; |
| 2302 | } |
Mauro Carvalho Chehab | 596d92d | 2005-11-08 21:37:24 -0800 | [diff] [blame] | 2303 | |
Mauro Carvalho Chehab | e5589be | 2006-01-23 17:11:08 -0200 | [diff] [blame] | 2304 | snprintf(dev->name, 29, "em28xx #%d", nr); |
Mauro Carvalho Chehab | 03910cc | 2007-11-03 21:20:59 -0300 | [diff] [blame] | 2305 | dev->devno = nr; |
| 2306 | dev->model = id->driver_info; |
Mauro Carvalho Chehab | 3687e1e | 2008-02-08 15:44:25 -0300 | [diff] [blame] | 2307 | dev->alt = -1; |
Mauro Carvalho Chehab | e5589be | 2006-01-23 17:11:08 -0200 | [diff] [blame] | 2308 | |
Mauro Carvalho Chehab | d7448a8 | 2008-01-05 09:59:03 -0300 | [diff] [blame] | 2309 | /* Checks if audio is provided by some interface */ |
| 2310 | for (i = 0; i < udev->config->desc.bNumInterfaces; i++) { |
| 2311 | uif = udev->config->interface[i]; |
| 2312 | if (uif->altsetting[0].desc.bInterfaceClass == USB_CLASS_AUDIO) { |
| 2313 | dev->has_audio_class = 1; |
| 2314 | break; |
| 2315 | } |
| 2316 | } |
| 2317 | |
Mauro Carvalho Chehab | 9d4d9c0 | 2005-11-08 21:38:52 -0800 | [diff] [blame] | 2318 | /* compute alternate max packet sizes */ |
| 2319 | uif = udev->actconfig->interface[0]; |
| 2320 | |
Douglas Schilling Landgraf | 6ea54d9 | 2008-04-17 21:41:10 -0300 | [diff] [blame] | 2321 | dev->num_alt = uif->num_altsetting; |
Mauro Carvalho Chehab | 1bee018 | 2008-11-25 10:06:21 -0300 | [diff] [blame] | 2322 | em28xx_videodbg("Alternate settings: %i\n", dev->num_alt); |
Douglas Schilling Landgraf | 6ea54d9 | 2008-04-17 21:41:10 -0300 | [diff] [blame] | 2323 | /* dev->alt_max_pkt_size = kmalloc(sizeof(*dev->alt_max_pkt_size)* */ |
| 2324 | dev->alt_max_pkt_size = kmalloc(32 * dev->num_alt, GFP_KERNEL); |
| 2325 | |
Mauro Carvalho Chehab | 9d4d9c0 | 2005-11-08 21:38:52 -0800 | [diff] [blame] | 2326 | if (dev->alt_max_pkt_size == NULL) { |
Mauro Carvalho Chehab | e5589be | 2006-01-23 17:11:08 -0200 | [diff] [blame] | 2327 | em28xx_errdev("out of memory!\n"); |
Douglas Schilling Landgraf | 6ea54d9 | 2008-04-17 21:41:10 -0300 | [diff] [blame] | 2328 | em28xx_devused &= ~(1<<nr); |
Jesper Juhl | 1207cf84 | 2007-08-09 23:02:36 +0200 | [diff] [blame] | 2329 | kfree(dev); |
Mauro Carvalho Chehab | 9d4d9c0 | 2005-11-08 21:38:52 -0800 | [diff] [blame] | 2330 | return -ENOMEM; |
| 2331 | } |
| 2332 | |
| 2333 | for (i = 0; i < dev->num_alt ; i++) { |
Devin Heitmueller | 95ea470 | 2008-11-12 02:02:17 -0300 | [diff] [blame] | 2334 | u16 tmp = le16_to_cpu(uif->altsetting[i].endpoint[isoc_pipe].desc. |
Mauro Carvalho Chehab | 9d4d9c0 | 2005-11-08 21:38:52 -0800 | [diff] [blame] | 2335 | wMaxPacketSize); |
| 2336 | dev->alt_max_pkt_size[i] = |
| 2337 | (tmp & 0x07ff) * (((tmp & 0x1800) >> 11) + 1); |
Mauro Carvalho Chehab | 1bee018 | 2008-11-25 10:06:21 -0300 | [diff] [blame] | 2338 | em28xx_videodbg("Alternate setting %i, max size= %i\n", i, |
Douglas Schilling Landgraf | 6ea54d9 | 2008-04-17 21:41:10 -0300 | [diff] [blame] | 2339 | dev->alt_max_pkt_size[i]); |
Mauro Carvalho Chehab | 9d4d9c0 | 2005-11-08 21:38:52 -0800 | [diff] [blame] | 2340 | } |
| 2341 | |
Douglas Schilling Landgraf | 6ea54d9 | 2008-04-17 21:41:10 -0300 | [diff] [blame] | 2342 | if ((card[nr] >= 0) && (card[nr] < em28xx_bcount)) |
Mauro Carvalho Chehab | 03910cc | 2007-11-03 21:20:59 -0300 | [diff] [blame] | 2343 | dev->model = card[nr]; |
Mauro Carvalho Chehab | 596d92d | 2005-11-08 21:37:24 -0800 | [diff] [blame] | 2344 | |
akpm@osdl.org | a6c2ba2 | 2005-11-08 21:37:07 -0800 | [diff] [blame] | 2345 | /* allocate device struct */ |
Mauro Carvalho Chehab | 03910cc | 2007-11-03 21:20:59 -0300 | [diff] [blame] | 2346 | retval = em28xx_init_dev(&dev, udev, nr); |
Mauro Carvalho Chehab | 625ff16 | 2008-11-18 10:23:19 -0300 | [diff] [blame] | 2347 | if (retval) { |
| 2348 | em28xx_devused &= ~(1<<dev->devno); |
| 2349 | kfree(dev); |
| 2350 | |
akpm@osdl.org | a6c2ba2 | 2005-11-08 21:37:07 -0800 | [diff] [blame] | 2351 | return retval; |
Mauro Carvalho Chehab | 625ff16 | 2008-11-18 10:23:19 -0300 | [diff] [blame] | 2352 | } |
akpm@osdl.org | a6c2ba2 | 2005-11-08 21:37:07 -0800 | [diff] [blame] | 2353 | |
akpm@osdl.org | a6c2ba2 | 2005-11-08 21:37:07 -0800 | [diff] [blame] | 2354 | /* save our data pointer in this interface device */ |
| 2355 | usb_set_intfdata(interface, dev); |
Mauro Carvalho Chehab | d7448a8 | 2008-01-05 09:59:03 -0300 | [diff] [blame] | 2356 | |
| 2357 | request_modules(dev); |
| 2358 | |
akpm@osdl.org | a6c2ba2 | 2005-11-08 21:37:07 -0800 | [diff] [blame] | 2359 | return 0; |
| 2360 | } |
| 2361 | |
| 2362 | /* |
Mauro Carvalho Chehab | 3acf280 | 2005-11-08 21:38:27 -0800 | [diff] [blame] | 2363 | * em28xx_usb_disconnect() |
akpm@osdl.org | a6c2ba2 | 2005-11-08 21:37:07 -0800 | [diff] [blame] | 2364 | * called when the device gets diconencted |
| 2365 | * video device will be unregistered on v4l2_close in case it is still open |
| 2366 | */ |
Mauro Carvalho Chehab | 3acf280 | 2005-11-08 21:38:27 -0800 | [diff] [blame] | 2367 | static void em28xx_usb_disconnect(struct usb_interface *interface) |
akpm@osdl.org | a6c2ba2 | 2005-11-08 21:37:07 -0800 | [diff] [blame] | 2368 | { |
Sascha Sommer | 5a80415 | 2007-11-03 21:22:38 -0300 | [diff] [blame] | 2369 | struct em28xx *dev; |
Mauro Carvalho Chehab | 6d79468 | 2008-01-05 09:57:31 -0300 | [diff] [blame] | 2370 | struct em28xx_ops *ops = NULL; |
Sascha Sommer | 5a80415 | 2007-11-03 21:22:38 -0300 | [diff] [blame] | 2371 | |
| 2372 | dev = usb_get_intfdata(interface); |
akpm@osdl.org | a6c2ba2 | 2005-11-08 21:37:07 -0800 | [diff] [blame] | 2373 | usb_set_intfdata(interface, NULL); |
| 2374 | |
| 2375 | if (!dev) |
| 2376 | return; |
| 2377 | |
Mauro Carvalho Chehab | 3acf280 | 2005-11-08 21:38:27 -0800 | [diff] [blame] | 2378 | em28xx_info("disconnecting %s\n", dev->vdev->name); |
akpm@osdl.org | a6c2ba2 | 2005-11-08 21:37:07 -0800 | [diff] [blame] | 2379 | |
Douglas Schilling Landgraf | 6ea54d9 | 2008-04-17 21:41:10 -0300 | [diff] [blame] | 2380 | /* wait until all current v4l2 io is finished then deallocate |
| 2381 | resources */ |
Sascha Sommer | 5a80415 | 2007-11-03 21:22:38 -0300 | [diff] [blame] | 2382 | mutex_lock(&dev->lock); |
| 2383 | |
akpm@osdl.org | a6c2ba2 | 2005-11-08 21:37:07 -0800 | [diff] [blame] | 2384 | wake_up_interruptible_all(&dev->open); |
| 2385 | |
| 2386 | if (dev->users) { |
Mauro Carvalho Chehab | 3acf280 | 2005-11-08 21:38:27 -0800 | [diff] [blame] | 2387 | em28xx_warn |
akpm@osdl.org | a6c2ba2 | 2005-11-08 21:37:07 -0800 | [diff] [blame] | 2388 | ("device /dev/video%d is open! Deregistration and memory " |
Mauro Carvalho Chehab | e5589be | 2006-01-23 17:11:08 -0200 | [diff] [blame] | 2389 | "deallocation are deferred on close.\n", |
Hans Verkuil | dd89601 | 2008-10-04 08:36:54 -0300 | [diff] [blame] | 2390 | dev->vdev->num); |
Mauro Carvalho Chehab | e5589be | 2006-01-23 17:11:08 -0200 | [diff] [blame] | 2391 | |
akpm@osdl.org | a6c2ba2 | 2005-11-08 21:37:07 -0800 | [diff] [blame] | 2392 | dev->state |= DEV_MISCONFIGURED; |
Mauro Carvalho Chehab | 3acf280 | 2005-11-08 21:38:27 -0800 | [diff] [blame] | 2393 | em28xx_uninit_isoc(dev); |
akpm@osdl.org | a6c2ba2 | 2005-11-08 21:37:07 -0800 | [diff] [blame] | 2394 | dev->state |= DEV_DISCONNECTED; |
| 2395 | wake_up_interruptible(&dev->wait_frame); |
| 2396 | wake_up_interruptible(&dev->wait_stream); |
| 2397 | } else { |
| 2398 | dev->state |= DEV_DISCONNECTED; |
Mauro Carvalho Chehab | 3acf280 | 2005-11-08 21:38:27 -0800 | [diff] [blame] | 2399 | em28xx_release_resources(dev); |
akpm@osdl.org | a6c2ba2 | 2005-11-08 21:37:07 -0800 | [diff] [blame] | 2400 | } |
Ingo Molnar | 3593cab | 2006-02-07 06:49:14 -0200 | [diff] [blame] | 2401 | mutex_unlock(&dev->lock); |
akpm@osdl.org | a6c2ba2 | 2005-11-08 21:37:07 -0800 | [diff] [blame] | 2402 | |
Mauro Carvalho Chehab | 6d79468 | 2008-01-05 09:57:31 -0300 | [diff] [blame] | 2403 | mutex_lock(&em28xx_extension_devlist_lock); |
| 2404 | if (!list_empty(&em28xx_extension_devlist)) { |
| 2405 | list_for_each_entry(ops, &em28xx_extension_devlist, next) { |
| 2406 | ops->fini(dev); |
| 2407 | } |
| 2408 | } |
| 2409 | mutex_unlock(&em28xx_extension_devlist_lock); |
| 2410 | |
Mauro Carvalho Chehab | 9d4d9c0 | 2005-11-08 21:38:52 -0800 | [diff] [blame] | 2411 | if (!dev->users) { |
| 2412 | kfree(dev->alt_max_pkt_size); |
akpm@osdl.org | a6c2ba2 | 2005-11-08 21:37:07 -0800 | [diff] [blame] | 2413 | kfree(dev); |
Mauro Carvalho Chehab | 9d4d9c0 | 2005-11-08 21:38:52 -0800 | [diff] [blame] | 2414 | } |
akpm@osdl.org | a6c2ba2 | 2005-11-08 21:37:07 -0800 | [diff] [blame] | 2415 | } |
| 2416 | |
Mauro Carvalho Chehab | 3acf280 | 2005-11-08 21:38:27 -0800 | [diff] [blame] | 2417 | static struct usb_driver em28xx_usb_driver = { |
Mauro Carvalho Chehab | 3acf280 | 2005-11-08 21:38:27 -0800 | [diff] [blame] | 2418 | .name = "em28xx", |
| 2419 | .probe = em28xx_usb_probe, |
| 2420 | .disconnect = em28xx_usb_disconnect, |
| 2421 | .id_table = em28xx_id_table, |
akpm@osdl.org | a6c2ba2 | 2005-11-08 21:37:07 -0800 | [diff] [blame] | 2422 | }; |
| 2423 | |
Mauro Carvalho Chehab | 3acf280 | 2005-11-08 21:38:27 -0800 | [diff] [blame] | 2424 | static int __init em28xx_module_init(void) |
akpm@osdl.org | a6c2ba2 | 2005-11-08 21:37:07 -0800 | [diff] [blame] | 2425 | { |
| 2426 | int result; |
| 2427 | |
| 2428 | printk(KERN_INFO DRIVER_NAME " v4l2 driver version %d.%d.%d loaded\n", |
Mauro Carvalho Chehab | 3acf280 | 2005-11-08 21:38:27 -0800 | [diff] [blame] | 2429 | (EM28XX_VERSION_CODE >> 16) & 0xff, |
| 2430 | (EM28XX_VERSION_CODE >> 8) & 0xff, EM28XX_VERSION_CODE & 0xff); |
akpm@osdl.org | a6c2ba2 | 2005-11-08 21:37:07 -0800 | [diff] [blame] | 2431 | #ifdef SNAPSHOT |
| 2432 | printk(KERN_INFO DRIVER_NAME " snapshot date %04d-%02d-%02d\n", |
| 2433 | SNAPSHOT / 10000, (SNAPSHOT / 100) % 100, SNAPSHOT % 100); |
| 2434 | #endif |
| 2435 | |
| 2436 | /* register this driver with the USB subsystem */ |
Mauro Carvalho Chehab | 3acf280 | 2005-11-08 21:38:27 -0800 | [diff] [blame] | 2437 | result = usb_register(&em28xx_usb_driver); |
akpm@osdl.org | a6c2ba2 | 2005-11-08 21:37:07 -0800 | [diff] [blame] | 2438 | if (result) |
Mauro Carvalho Chehab | 3acf280 | 2005-11-08 21:38:27 -0800 | [diff] [blame] | 2439 | em28xx_err(DRIVER_NAME |
akpm@osdl.org | a6c2ba2 | 2005-11-08 21:37:07 -0800 | [diff] [blame] | 2440 | " usb_register failed. Error number %d.\n", result); |
| 2441 | |
| 2442 | return result; |
| 2443 | } |
| 2444 | |
Mauro Carvalho Chehab | 3acf280 | 2005-11-08 21:38:27 -0800 | [diff] [blame] | 2445 | static void __exit em28xx_module_exit(void) |
akpm@osdl.org | a6c2ba2 | 2005-11-08 21:37:07 -0800 | [diff] [blame] | 2446 | { |
| 2447 | /* deregister this driver with the USB subsystem */ |
Mauro Carvalho Chehab | 3acf280 | 2005-11-08 21:38:27 -0800 | [diff] [blame] | 2448 | usb_deregister(&em28xx_usb_driver); |
akpm@osdl.org | a6c2ba2 | 2005-11-08 21:37:07 -0800 | [diff] [blame] | 2449 | } |
| 2450 | |
Mauro Carvalho Chehab | 3acf280 | 2005-11-08 21:38:27 -0800 | [diff] [blame] | 2451 | module_init(em28xx_module_init); |
| 2452 | module_exit(em28xx_module_exit); |