akpm@osdl.org | a6c2ba2 | 2005-11-08 21:37:07 -0800 | [diff] [blame] | 1 | /* |
Mauro Carvalho Chehab | f7abcd3 | 2005-11-08 21:38:25 -0800 | [diff] [blame] | 2 | em28xx-video.c - driver for Empia EM2800/EM2820/2840 USB video capture devices |
akpm@osdl.org | a6c2ba2 | 2005-11-08 21:37:07 -0800 | [diff] [blame] | 3 | |
Mauro Carvalho Chehab | f7abcd3 | 2005-11-08 21:38:25 -0800 | [diff] [blame] | 4 | Copyright (C) 2005 Ludovico Cavedon <cavedon@sssup.it> |
| 5 | Markus Rechberger <mrechberger@gmail.com> |
Mauro Carvalho Chehab | 4ac9791 | 2005-11-08 21:37:43 -0800 | [diff] [blame] | 6 | Mauro Carvalho Chehab <mchehab@brturbo.com.br> |
Mauro Carvalho Chehab | f7abcd3 | 2005-11-08 21:38:25 -0800 | [diff] [blame] | 7 | Sascha Sommer <saschasommer@freenet.de> |
akpm@osdl.org | a6c2ba2 | 2005-11-08 21:37:07 -0800 | [diff] [blame] | 8 | |
| 9 | This program is free software; you can redistribute it and/or modify |
| 10 | it under the terms of the GNU General Public License as published by |
| 11 | the Free Software Foundation; either version 2 of the License, or |
| 12 | (at your option) any later version. |
| 13 | |
| 14 | This program is distributed in the hope that it will be useful, |
| 15 | but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 16 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 17 | GNU General Public License for more details. |
| 18 | |
| 19 | You should have received a copy of the GNU General Public License |
| 20 | along with this program; if not, write to the Free Software |
| 21 | Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. |
| 22 | */ |
| 23 | |
| 24 | #include <linux/init.h> |
| 25 | #include <linux/list.h> |
| 26 | #include <linux/module.h> |
| 27 | #include <linux/kernel.h> |
| 28 | #include <linux/usb.h> |
akpm@osdl.org | a6c2ba2 | 2005-11-08 21:37:07 -0800 | [diff] [blame] | 29 | #include <linux/i2c.h> |
Mauro Carvalho Chehab | b296fc6 | 2005-11-08 21:38:37 -0800 | [diff] [blame] | 30 | #include <linux/version.h> |
akpm@osdl.org | a6c2ba2 | 2005-11-08 21:37:07 -0800 | [diff] [blame] | 31 | #include <linux/video_decoder.h> |
| 32 | |
Mauro Carvalho Chehab | f7abcd3 | 2005-11-08 21:38:25 -0800 | [diff] [blame] | 33 | #include "em28xx.h" |
Mauro Carvalho Chehab | d5e5265 | 2005-11-08 21:37:32 -0800 | [diff] [blame] | 34 | #include <media/tuner.h> |
Mauro Carvalho Chehab | c0477ad | 2006-01-09 15:25:14 -0200 | [diff] [blame] | 35 | #include <media/v4l2-common.h> |
akpm@osdl.org | a6c2ba2 | 2005-11-08 21:37:07 -0800 | [diff] [blame] | 36 | |
Mauro Carvalho Chehab | f7abcd3 | 2005-11-08 21:38:25 -0800 | [diff] [blame] | 37 | #define DRIVER_AUTHOR "Ludovico Cavedon <cavedon@sssup.it>, " \ |
| 38 | "Markus Rechberger <mrechberger@gmail.com>, " \ |
| 39 | "Mauro Carvalho Chehab <mchehab@brturbo.com.br>, " \ |
| 40 | "Sascha Sommer <saschasommer@freenet.de>" |
akpm@osdl.org | a6c2ba2 | 2005-11-08 21:37:07 -0800 | [diff] [blame] | 41 | |
Mauro Carvalho Chehab | f7abcd3 | 2005-11-08 21:38:25 -0800 | [diff] [blame] | 42 | #define DRIVER_NAME "em28xx" |
| 43 | #define DRIVER_DESC "Empia em28xx based USB video device driver" |
Mauro Carvalho Chehab | 3acf280 | 2005-11-08 21:38:27 -0800 | [diff] [blame] | 44 | #define EM28XX_VERSION_CODE KERNEL_VERSION(0, 0, 1) |
akpm@osdl.org | a6c2ba2 | 2005-11-08 21:37:07 -0800 | [diff] [blame] | 45 | |
Mauro Carvalho Chehab | 3acf280 | 2005-11-08 21:38:27 -0800 | [diff] [blame] | 46 | #define em28xx_videodbg(fmt, arg...) do {\ |
Mauro Carvalho Chehab | 4ac9791 | 2005-11-08 21:37:43 -0800 | [diff] [blame] | 47 | if (video_debug) \ |
| 48 | printk(KERN_INFO "%s %s :"fmt, \ |
Jean Delvare | f85c657 | 2005-12-19 08:53:59 -0200 | [diff] [blame] | 49 | dev->name, __FUNCTION__ , ##arg); } while (0) |
akpm@osdl.org | a6c2ba2 | 2005-11-08 21:37:07 -0800 | [diff] [blame] | 50 | |
| 51 | MODULE_AUTHOR(DRIVER_AUTHOR); |
| 52 | MODULE_DESCRIPTION(DRIVER_DESC); |
| 53 | MODULE_LICENSE("GPL"); |
| 54 | |
Mauro Carvalho Chehab | 3acf280 | 2005-11-08 21:38:27 -0800 | [diff] [blame] | 55 | static LIST_HEAD(em28xx_devlist); |
Markus Rechberger | 9c75541 | 2005-11-08 21:37:52 -0800 | [diff] [blame] | 56 | |
Mauro Carvalho Chehab | 9d4d9c0 | 2005-11-08 21:38:52 -0800 | [diff] [blame] | 57 | static unsigned int card[] = {[0 ... (EM28XX_MAXBOARDS - 1)] = UNSET }; |
Mauro Carvalho Chehab | 596d92d | 2005-11-08 21:37:24 -0800 | [diff] [blame] | 58 | module_param_array(card, int, NULL, 0444); |
| 59 | MODULE_PARM_DESC(card,"card type"); |
| 60 | |
akpm@osdl.org | a6c2ba2 | 2005-11-08 21:37:07 -0800 | [diff] [blame] | 61 | static int tuner = -1; |
| 62 | module_param(tuner, int, 0444); |
| 63 | MODULE_PARM_DESC(tuner, "tuner type"); |
| 64 | |
| 65 | static unsigned int video_debug = 0; |
| 66 | module_param(video_debug,int,0644); |
| 67 | MODULE_PARM_DESC(video_debug,"enable debug messages [video]"); |
| 68 | |
| 69 | /* supported tv norms */ |
Mauro Carvalho Chehab | 3acf280 | 2005-11-08 21:38:27 -0800 | [diff] [blame] | 70 | static struct em28xx_tvnorm tvnorms[] = { |
akpm@osdl.org | a6c2ba2 | 2005-11-08 21:37:07 -0800 | [diff] [blame] | 71 | { |
| 72 | .name = "PAL", |
| 73 | .id = V4L2_STD_PAL, |
| 74 | .mode = VIDEO_MODE_PAL, |
| 75 | }, { |
| 76 | .name = "NTSC", |
| 77 | .id = V4L2_STD_NTSC, |
| 78 | .mode = VIDEO_MODE_NTSC, |
| 79 | }, { |
| 80 | .name = "SECAM", |
| 81 | .id = V4L2_STD_SECAM, |
| 82 | .mode = VIDEO_MODE_SECAM, |
| 83 | }, { |
| 84 | .name = "PAL-M", |
| 85 | .id = V4L2_STD_PAL_M, |
| 86 | .mode = VIDEO_MODE_PAL, |
| 87 | } |
| 88 | }; |
| 89 | |
Markus Rechberger | a38a7d4 | 2005-11-08 21:38:06 -0800 | [diff] [blame] | 90 | static const unsigned char saa7114_i2c_init[] = { |
| 91 | 0x00,0x00,0x01,0x08,0x02,0xc4,0x03,0x30,0x04,0x90,0x05,0x90,0x06,0xeb,0x07,0xe0, |
| 92 | 0x08,0x88,0x09,0x40,0x0a,0x80,0x0b,0x44,0x0c,0x40,0x0d,0x00,0x0e,0x81,0x0f,0x2a, |
| 93 | 0x10,0x06,0x11,0x00,0x12,0xc8,0x13,0x80,0x14,0x00,0x15,0x11,0x16,0x01,0x17,0x42, |
| 94 | 0x18,0x40,0x19,0x80,0x40,0x00,0x41,0xff,0x42,0xff,0x43,0xff,0x44,0xff,0x45,0xff, |
| 95 | 0x46,0xff,0x47,0xff,0x48,0xff,0x49,0xff,0x4a,0xff,0x4b,0xff,0x4c,0xff,0x4d,0xff, |
| 96 | 0x4e,0xff,0x4f,0xff,0x50,0xff,0x51,0xff,0x52,0xff,0x53,0xff,0x54,0x5f,0x55,0xff, |
| 97 | 0x56,0xff,0x57,0xff,0x58,0x00,0x59,0x47,0x5a,0x03,0x5b,0x03,0x5d,0x3e,0x5e,0x00, |
| 98 | 0x80,0x1c,0x83,0x01,0x84,0xa5,0x85,0x10,0x86,0x45,0x87,0x41,0x88,0xf0,0x88,0x00, |
| 99 | 0x88,0xf0,0x90,0x00,0x91,0x08,0x92,0x00,0x93,0x80,0x94,0x08,0x95,0x00,0x96,0xc0, |
| 100 | 0x97,0x02,0x98,0x13,0x99,0x00,0x9a,0x38,0x9b,0x01,0x9c,0x80,0x9d,0x02,0x9e,0x06, |
| 101 | 0x9f,0x01,0xa0,0x01,0xa1,0x00,0xa2,0x00,0xa4,0x80,0xa5,0x36,0xa6,0x36,0xa8,0x67, |
| 102 | 0xa9,0x04,0xaa,0x00,0xac,0x33,0xad,0x02,0xae,0x00,0xb0,0xcd,0xb1,0x04,0xb2,0xcd, |
| 103 | 0xb3,0x04,0xb4,0x01,0xb8,0x00,0xb9,0x00,0xba,0x00,0xbb,0x00,0xbc,0x00,0xbd,0x00, |
| 104 | 0xbe,0x00,0xbf,0x00 |
| 105 | }; |
| 106 | |
akpm@osdl.org | a6c2ba2 | 2005-11-08 21:37:07 -0800 | [diff] [blame] | 107 | #define TVNORMS ARRAY_SIZE(tvnorms) |
| 108 | |
| 109 | /* supported controls */ |
Mauro Carvalho Chehab | c0477ad | 2006-01-09 15:25:14 -0200 | [diff] [blame] | 110 | /* Common to all boards */ |
Mauro Carvalho Chehab | 3acf280 | 2005-11-08 21:38:27 -0800 | [diff] [blame] | 111 | static struct v4l2_queryctrl em28xx_qctrl[] = { |
akpm@osdl.org | a6c2ba2 | 2005-11-08 21:37:07 -0800 | [diff] [blame] | 112 | { |
Mauro Carvalho Chehab | c0477ad | 2006-01-09 15:25:14 -0200 | [diff] [blame] | 113 | .id = V4L2_CID_AUDIO_VOLUME, |
| 114 | .type = V4L2_CTRL_TYPE_INTEGER, |
| 115 | .name = "Volume", |
| 116 | .minimum = 0x0, |
| 117 | .maximum = 0x1f, |
| 118 | .step = 0x1, |
| 119 | .default_value = 0x1f, |
| 120 | .flags = 0, |
| 121 | },{ |
| 122 | .id = V4L2_CID_AUDIO_MUTE, |
| 123 | .type = V4L2_CTRL_TYPE_BOOLEAN, |
| 124 | .name = "Mute", |
| 125 | .minimum = 0, |
| 126 | .maximum = 1, |
| 127 | .step = 1, |
| 128 | .default_value = 1, |
| 129 | .flags = 0, |
| 130 | } |
| 131 | }; |
| 132 | |
| 133 | /* FIXME: These are specific to saa711x - should be moved to its code */ |
| 134 | static struct v4l2_queryctrl saa711x_qctrl[] = { |
| 135 | { |
akpm@osdl.org | a6c2ba2 | 2005-11-08 21:37:07 -0800 | [diff] [blame] | 136 | .id = V4L2_CID_BRIGHTNESS, |
| 137 | .type = V4L2_CTRL_TYPE_INTEGER, |
| 138 | .name = "Brightness", |
| 139 | .minimum = -128, |
| 140 | .maximum = 127, |
| 141 | .step = 1, |
| 142 | .default_value = 0, |
| 143 | .flags = 0, |
| 144 | },{ |
| 145 | .id = V4L2_CID_CONTRAST, |
| 146 | .type = V4L2_CTRL_TYPE_INTEGER, |
| 147 | .name = "Contrast", |
| 148 | .minimum = 0x0, |
| 149 | .maximum = 0x1f, |
| 150 | .step = 0x1, |
| 151 | .default_value = 0x10, |
| 152 | .flags = 0, |
| 153 | },{ |
| 154 | .id = V4L2_CID_SATURATION, |
| 155 | .type = V4L2_CTRL_TYPE_INTEGER, |
| 156 | .name = "Saturation", |
| 157 | .minimum = 0x0, |
| 158 | .maximum = 0x1f, |
| 159 | .step = 0x1, |
| 160 | .default_value = 0x10, |
| 161 | .flags = 0, |
| 162 | },{ |
akpm@osdl.org | a6c2ba2 | 2005-11-08 21:37:07 -0800 | [diff] [blame] | 163 | .id = V4L2_CID_RED_BALANCE, |
| 164 | .type = V4L2_CTRL_TYPE_INTEGER, |
| 165 | .name = "Red chroma balance", |
| 166 | .minimum = -128, |
| 167 | .maximum = 127, |
| 168 | .step = 1, |
| 169 | .default_value = 0, |
| 170 | .flags = 0, |
| 171 | },{ |
| 172 | .id = V4L2_CID_BLUE_BALANCE, |
| 173 | .type = V4L2_CTRL_TYPE_INTEGER, |
| 174 | .name = "Blue chroma balance", |
| 175 | .minimum = -128, |
| 176 | .maximum = 127, |
| 177 | .step = 1, |
| 178 | .default_value = 0, |
| 179 | .flags = 0, |
| 180 | },{ |
| 181 | .id = V4L2_CID_GAMMA, |
| 182 | .type = V4L2_CTRL_TYPE_INTEGER, |
| 183 | .name = "Gamma", |
| 184 | .minimum = 0x0, |
| 185 | .maximum = 0x3f, |
| 186 | .step = 0x1, |
| 187 | .default_value = 0x20, |
| 188 | .flags = 0, |
Mauro Carvalho Chehab | c0477ad | 2006-01-09 15:25:14 -0200 | [diff] [blame] | 189 | } |
akpm@osdl.org | a6c2ba2 | 2005-11-08 21:37:07 -0800 | [diff] [blame] | 190 | }; |
| 191 | |
Mauro Carvalho Chehab | 3acf280 | 2005-11-08 21:38:27 -0800 | [diff] [blame] | 192 | static struct usb_driver em28xx_usb_driver; |
akpm@osdl.org | a6c2ba2 | 2005-11-08 21:37:07 -0800 | [diff] [blame] | 193 | |
Mauro Carvalho Chehab | 3acf280 | 2005-11-08 21:38:27 -0800 | [diff] [blame] | 194 | static DECLARE_MUTEX(em28xx_sysfs_lock); |
| 195 | static DECLARE_RWSEM(em28xx_disconnect); |
akpm@osdl.org | a6c2ba2 | 2005-11-08 21:37:07 -0800 | [diff] [blame] | 196 | |
| 197 | /********************* v4l2 interface ******************************************/ |
| 198 | |
akpm@osdl.org | a6c2ba2 | 2005-11-08 21:37:07 -0800 | [diff] [blame] | 199 | /* |
Mauro Carvalho Chehab | 3acf280 | 2005-11-08 21:38:27 -0800 | [diff] [blame] | 200 | * em28xx_config() |
akpm@osdl.org | a6c2ba2 | 2005-11-08 21:37:07 -0800 | [diff] [blame] | 201 | * inits registers with sane defaults |
| 202 | */ |
Mauro Carvalho Chehab | 3acf280 | 2005-11-08 21:38:27 -0800 | [diff] [blame] | 203 | static int em28xx_config(struct em28xx *dev) |
akpm@osdl.org | a6c2ba2 | 2005-11-08 21:37:07 -0800 | [diff] [blame] | 204 | { |
| 205 | |
| 206 | /* Sets I2C speed to 100 KHz */ |
Mauro Carvalho Chehab | 3acf280 | 2005-11-08 21:38:27 -0800 | [diff] [blame] | 207 | em28xx_write_regs_req(dev, 0x00, 0x06, "\x40", 1); |
akpm@osdl.org | a6c2ba2 | 2005-11-08 21:37:07 -0800 | [diff] [blame] | 208 | |
| 209 | /* enable vbi capturing */ |
Mauro Carvalho Chehab | 3acf280 | 2005-11-08 21:38:27 -0800 | [diff] [blame] | 210 | em28xx_audio_usb_mute(dev, 1); |
akpm@osdl.org | a6c2ba2 | 2005-11-08 21:37:07 -0800 | [diff] [blame] | 211 | dev->mute = 1; /* maybe not the right place... */ |
| 212 | dev->volume = 0x1f; |
Mauro Carvalho Chehab | 3acf280 | 2005-11-08 21:38:27 -0800 | [diff] [blame] | 213 | em28xx_audio_analog_set(dev); |
| 214 | em28xx_audio_analog_setup(dev); |
| 215 | em28xx_outfmt_set_yuv422(dev); |
| 216 | em28xx_colorlevels_set_default(dev); |
| 217 | em28xx_compression_disable(dev); |
akpm@osdl.org | a6c2ba2 | 2005-11-08 21:37:07 -0800 | [diff] [blame] | 218 | |
| 219 | return 0; |
| 220 | } |
| 221 | |
| 222 | /* |
Mauro Carvalho Chehab | 3acf280 | 2005-11-08 21:38:27 -0800 | [diff] [blame] | 223 | * em28xx_config_i2c() |
akpm@osdl.org | a6c2ba2 | 2005-11-08 21:37:07 -0800 | [diff] [blame] | 224 | * configure i2c attached devices |
| 225 | */ |
Adrian Bunk | 943a490 | 2005-12-01 00:51:35 -0800 | [diff] [blame] | 226 | static void em28xx_config_i2c(struct em28xx *dev) |
akpm@osdl.org | a6c2ba2 | 2005-11-08 21:37:07 -0800 | [diff] [blame] | 227 | { |
| 228 | struct v4l2_frequency f; |
Mauro Carvalho Chehab | 3acf280 | 2005-11-08 21:38:27 -0800 | [diff] [blame] | 229 | struct video_decoder_init em28xx_vdi = {.data = NULL }; |
akpm@osdl.org | a6c2ba2 | 2005-11-08 21:37:07 -0800 | [diff] [blame] | 230 | |
| 231 | |
| 232 | /* configure decoder */ |
Markus Rechberger | a38a7d4 | 2005-11-08 21:38:06 -0800 | [diff] [blame] | 233 | if(dev->model == EM2820_BOARD_MSI_VOX_USB_2){ |
Mauro Carvalho Chehab | 3acf280 | 2005-11-08 21:38:27 -0800 | [diff] [blame] | 234 | em28xx_vdi.data=saa7114_i2c_init; |
| 235 | em28xx_vdi.len=sizeof(saa7114_i2c_init); |
Markus Rechberger | a38a7d4 | 2005-11-08 21:38:06 -0800 | [diff] [blame] | 236 | } |
| 237 | |
| 238 | |
Mauro Carvalho Chehab | 3acf280 | 2005-11-08 21:38:27 -0800 | [diff] [blame] | 239 | em28xx_i2c_call_clients(dev, DECODER_INIT, &em28xx_vdi); |
| 240 | em28xx_i2c_call_clients(dev, DECODER_SET_INPUT, &dev->ctl_input); |
| 241 | /* em28xx_i2c_call_clients(dev,DECODER_SET_PICTURE, &dev->vpic); */ |
| 242 | /* em28xx_i2c_call_clients(dev,DECODER_SET_NORM,&dev->tvnorm->id); */ |
| 243 | /* em28xx_i2c_call_clients(dev,DECODER_ENABLE_OUTPUT,&output); */ |
| 244 | /* em28xx_i2c_call_clients(dev,DECODER_DUMP, NULL); */ |
akpm@osdl.org | a6c2ba2 | 2005-11-08 21:37:07 -0800 | [diff] [blame] | 245 | |
| 246 | /* configure tuner */ |
| 247 | f.tuner = 0; |
| 248 | f.type = V4L2_TUNER_ANALOG_TV; |
| 249 | f.frequency = 9076; /* FIXME:remove magic number */ |
| 250 | dev->ctl_freq = f.frequency; |
Mauro Carvalho Chehab | 3acf280 | 2005-11-08 21:38:27 -0800 | [diff] [blame] | 251 | em28xx_i2c_call_clients(dev, VIDIOC_S_FREQUENCY, &f); |
akpm@osdl.org | a6c2ba2 | 2005-11-08 21:37:07 -0800 | [diff] [blame] | 252 | |
| 253 | /* configure tda9887 */ |
| 254 | |
akpm@osdl.org | a6c2ba2 | 2005-11-08 21:37:07 -0800 | [diff] [blame] | 255 | |
Mauro Carvalho Chehab | 3acf280 | 2005-11-08 21:38:27 -0800 | [diff] [blame] | 256 | /* em28xx_i2c_call_clients(dev,VIDIOC_S_STD,&dev->tvnorm->id); */ |
akpm@osdl.org | a6c2ba2 | 2005-11-08 21:37:07 -0800 | [diff] [blame] | 257 | } |
| 258 | |
| 259 | /* |
Mauro Carvalho Chehab | 3acf280 | 2005-11-08 21:38:27 -0800 | [diff] [blame] | 260 | * em28xx_empty_framequeues() |
akpm@osdl.org | a6c2ba2 | 2005-11-08 21:37:07 -0800 | [diff] [blame] | 261 | * prepare queues for incoming and outgoing frames |
| 262 | */ |
Mauro Carvalho Chehab | 3acf280 | 2005-11-08 21:38:27 -0800 | [diff] [blame] | 263 | static void em28xx_empty_framequeues(struct em28xx *dev) |
akpm@osdl.org | a6c2ba2 | 2005-11-08 21:37:07 -0800 | [diff] [blame] | 264 | { |
| 265 | u32 i; |
| 266 | |
| 267 | INIT_LIST_HEAD(&dev->inqueue); |
| 268 | INIT_LIST_HEAD(&dev->outqueue); |
| 269 | |
Mauro Carvalho Chehab | 3acf280 | 2005-11-08 21:38:27 -0800 | [diff] [blame] | 270 | for (i = 0; i < EM28XX_NUM_FRAMES; i++) { |
akpm@osdl.org | a6c2ba2 | 2005-11-08 21:37:07 -0800 | [diff] [blame] | 271 | dev->frame[i].state = F_UNUSED; |
| 272 | dev->frame[i].buf.bytesused = 0; |
| 273 | } |
| 274 | } |
| 275 | |
Mauro Carvalho Chehab | eac9435 | 2005-11-08 21:38:43 -0800 | [diff] [blame] | 276 | static void video_mux(struct em28xx *dev, int index) |
| 277 | { |
| 278 | int input, ainput; |
| 279 | |
| 280 | input = INPUT(index)->vmux; |
| 281 | dev->ctl_input = index; |
| 282 | dev->ctl_ainput = INPUT(index)->amux; |
| 283 | |
| 284 | em28xx_i2c_call_clients(dev, DECODER_SET_INPUT, &input); |
| 285 | |
| 286 | |
| 287 | em28xx_videodbg("Setting input index=%d, vmux=%d, amux=%d\n",index,input,dev->ctl_ainput); |
| 288 | |
| 289 | if (dev->has_msp34xx) { |
Mauro Carvalho Chehab | 9bb13a6 | 2006-01-09 15:25:37 -0200 | [diff] [blame] | 290 | if (dev->i2s_speed) |
| 291 | em28xx_i2c_call_clients(dev, VIDIOC_INT_I2S_CLOCK_FREQ, &dev->i2s_speed); |
Mauro Carvalho Chehab | eac9435 | 2005-11-08 21:38:43 -0800 | [diff] [blame] | 292 | em28xx_i2c_call_clients(dev, VIDIOC_S_AUDIO, &dev->ctl_ainput); |
| 293 | ainput = EM28XX_AUDIO_SRC_TUNER; |
| 294 | em28xx_audio_source(dev, ainput); |
| 295 | } else { |
| 296 | switch (dev->ctl_ainput) { |
| 297 | case 0: |
| 298 | ainput = EM28XX_AUDIO_SRC_TUNER; |
| 299 | break; |
| 300 | default: |
| 301 | ainput = EM28XX_AUDIO_SRC_LINE; |
| 302 | } |
| 303 | em28xx_audio_source(dev, ainput); |
| 304 | } |
| 305 | } |
| 306 | |
akpm@osdl.org | a6c2ba2 | 2005-11-08 21:37:07 -0800 | [diff] [blame] | 307 | /* |
Mauro Carvalho Chehab | 3acf280 | 2005-11-08 21:38:27 -0800 | [diff] [blame] | 308 | * em28xx_v4l2_open() |
akpm@osdl.org | a6c2ba2 | 2005-11-08 21:37:07 -0800 | [diff] [blame] | 309 | * inits the device and starts isoc transfer |
| 310 | */ |
Mauro Carvalho Chehab | 3acf280 | 2005-11-08 21:38:27 -0800 | [diff] [blame] | 311 | static int em28xx_v4l2_open(struct inode *inode, struct file *filp) |
akpm@osdl.org | a6c2ba2 | 2005-11-08 21:37:07 -0800 | [diff] [blame] | 312 | { |
akpm@osdl.org | a6c2ba2 | 2005-11-08 21:37:07 -0800 | [diff] [blame] | 313 | int minor = iminor(inode); |
akpm@osdl.org | a6c2ba2 | 2005-11-08 21:37:07 -0800 | [diff] [blame] | 314 | int errCode = 0; |
Mauro Carvalho Chehab | 3acf280 | 2005-11-08 21:38:27 -0800 | [diff] [blame] | 315 | struct em28xx *h,*dev = NULL; |
Markus Rechberger | 9c75541 | 2005-11-08 21:37:52 -0800 | [diff] [blame] | 316 | struct list_head *list; |
| 317 | |
Mauro Carvalho Chehab | 3acf280 | 2005-11-08 21:38:27 -0800 | [diff] [blame] | 318 | list_for_each(list,&em28xx_devlist) { |
| 319 | h = list_entry(list, struct em28xx, devlist); |
Markus Rechberger | 9c75541 | 2005-11-08 21:37:52 -0800 | [diff] [blame] | 320 | if (h->vdev->minor == minor) { |
| 321 | dev = h; |
| 322 | } |
| 323 | } |
| 324 | |
| 325 | filp->private_data=dev; |
| 326 | |
akpm@osdl.org | a6c2ba2 | 2005-11-08 21:37:07 -0800 | [diff] [blame] | 327 | |
Mauro Carvalho Chehab | eac9435 | 2005-11-08 21:38:43 -0800 | [diff] [blame] | 328 | em28xx_videodbg("users=%d\n", dev->users); |
akpm@osdl.org | a6c2ba2 | 2005-11-08 21:37:07 -0800 | [diff] [blame] | 329 | |
Mauro Carvalho Chehab | 3acf280 | 2005-11-08 21:38:27 -0800 | [diff] [blame] | 330 | if (!down_read_trylock(&em28xx_disconnect)) |
akpm@osdl.org | a6c2ba2 | 2005-11-08 21:37:07 -0800 | [diff] [blame] | 331 | return -ERESTARTSYS; |
| 332 | |
| 333 | if (dev->users) { |
Mauro Carvalho Chehab | 3acf280 | 2005-11-08 21:38:27 -0800 | [diff] [blame] | 334 | em28xx_warn("this driver can be opened only once\n"); |
| 335 | up_read(&em28xx_disconnect); |
akpm@osdl.org | a6c2ba2 | 2005-11-08 21:37:07 -0800 | [diff] [blame] | 336 | return -EBUSY; |
| 337 | } |
| 338 | |
| 339 | /* if(dev->vbi_dev->minor == minor){ |
| 340 | dev->type=V4L2_BUF_TYPE_VBI_CAPTURE; |
| 341 | }*/ |
| 342 | if (dev->vdev->minor == minor) { |
| 343 | dev->type = V4L2_BUF_TYPE_VIDEO_CAPTURE; |
| 344 | } |
| 345 | |
| 346 | init_MUTEX(&dev->fileop_lock); /* to 1 == available */ |
| 347 | spin_lock_init(&dev->queue_lock); |
| 348 | init_waitqueue_head(&dev->wait_frame); |
| 349 | init_waitqueue_head(&dev->wait_stream); |
| 350 | |
| 351 | down(&dev->lock); |
| 352 | |
Mauro Carvalho Chehab | 3acf280 | 2005-11-08 21:38:27 -0800 | [diff] [blame] | 353 | em28xx_set_alternate(dev); |
akpm@osdl.org | a6c2ba2 | 2005-11-08 21:37:07 -0800 | [diff] [blame] | 354 | |
| 355 | dev->width = norm_maxw(dev); |
| 356 | dev->height = norm_maxh(dev); |
| 357 | dev->frame_size = dev->width * dev->height * 2; |
| 358 | dev->field_size = dev->frame_size >> 1; /*both_fileds ? dev->frame_size>>1 : dev->frame_size; */ |
| 359 | dev->bytesperline = dev->width * 2; |
| 360 | dev->hscale = 0; |
| 361 | dev->vscale = 0; |
| 362 | |
Mauro Carvalho Chehab | 3acf280 | 2005-11-08 21:38:27 -0800 | [diff] [blame] | 363 | em28xx_capture_start(dev, 1); |
| 364 | em28xx_resolution_set(dev); |
akpm@osdl.org | a6c2ba2 | 2005-11-08 21:37:07 -0800 | [diff] [blame] | 365 | |
| 366 | /* start the transfer */ |
Mauro Carvalho Chehab | 3acf280 | 2005-11-08 21:38:27 -0800 | [diff] [blame] | 367 | errCode = em28xx_init_isoc(dev); |
akpm@osdl.org | a6c2ba2 | 2005-11-08 21:37:07 -0800 | [diff] [blame] | 368 | if (errCode) |
| 369 | goto err; |
| 370 | |
| 371 | dev->users++; |
| 372 | filp->private_data = dev; |
| 373 | dev->io = IO_NONE; |
| 374 | dev->stream = STREAM_OFF; |
| 375 | dev->num_frames = 0; |
| 376 | |
| 377 | /* prepare queues */ |
Mauro Carvalho Chehab | 3acf280 | 2005-11-08 21:38:27 -0800 | [diff] [blame] | 378 | em28xx_empty_framequeues(dev); |
akpm@osdl.org | a6c2ba2 | 2005-11-08 21:37:07 -0800 | [diff] [blame] | 379 | |
| 380 | dev->state |= DEV_INITIALIZED; |
| 381 | |
Mauro Carvalho Chehab | eac9435 | 2005-11-08 21:38:43 -0800 | [diff] [blame] | 382 | video_mux(dev, 0); |
| 383 | |
akpm@osdl.org | a6c2ba2 | 2005-11-08 21:37:07 -0800 | [diff] [blame] | 384 | err: |
| 385 | up(&dev->lock); |
Mauro Carvalho Chehab | 3acf280 | 2005-11-08 21:38:27 -0800 | [diff] [blame] | 386 | up_read(&em28xx_disconnect); |
akpm@osdl.org | a6c2ba2 | 2005-11-08 21:37:07 -0800 | [diff] [blame] | 387 | return errCode; |
| 388 | } |
| 389 | |
| 390 | /* |
Mauro Carvalho Chehab | 3acf280 | 2005-11-08 21:38:27 -0800 | [diff] [blame] | 391 | * em28xx_realease_resources() |
akpm@osdl.org | a6c2ba2 | 2005-11-08 21:37:07 -0800 | [diff] [blame] | 392 | * unregisters the v4l2,i2c and usb devices |
| 393 | * called when the device gets disconected or at module unload |
| 394 | */ |
Mauro Carvalho Chehab | 3acf280 | 2005-11-08 21:38:27 -0800 | [diff] [blame] | 395 | static void em28xx_release_resources(struct em28xx *dev) |
akpm@osdl.org | a6c2ba2 | 2005-11-08 21:37:07 -0800 | [diff] [blame] | 396 | { |
Mauro Carvalho Chehab | 3acf280 | 2005-11-08 21:38:27 -0800 | [diff] [blame] | 397 | down(&em28xx_sysfs_lock); |
akpm@osdl.org | a6c2ba2 | 2005-11-08 21:37:07 -0800 | [diff] [blame] | 398 | |
Mauro Carvalho Chehab | 3acf280 | 2005-11-08 21:38:27 -0800 | [diff] [blame] | 399 | em28xx_info("V4L2 device /dev/video%d deregistered\n", |
akpm@osdl.org | a6c2ba2 | 2005-11-08 21:37:07 -0800 | [diff] [blame] | 400 | dev->vdev->minor); |
Markus Rechberger | 9c75541 | 2005-11-08 21:37:52 -0800 | [diff] [blame] | 401 | list_del(&dev->devlist); |
akpm@osdl.org | a6c2ba2 | 2005-11-08 21:37:07 -0800 | [diff] [blame] | 402 | video_unregister_device(dev->vdev); |
| 403 | /* video_unregister_device(dev->vbi_dev); */ |
Mauro Carvalho Chehab | 3acf280 | 2005-11-08 21:38:27 -0800 | [diff] [blame] | 404 | em28xx_i2c_unregister(dev); |
akpm@osdl.org | a6c2ba2 | 2005-11-08 21:37:07 -0800 | [diff] [blame] | 405 | usb_put_dev(dev->udev); |
Mauro Carvalho Chehab | 3acf280 | 2005-11-08 21:38:27 -0800 | [diff] [blame] | 406 | up(&em28xx_sysfs_lock); |
akpm@osdl.org | a6c2ba2 | 2005-11-08 21:37:07 -0800 | [diff] [blame] | 407 | } |
| 408 | |
| 409 | /* |
Mauro Carvalho Chehab | 3acf280 | 2005-11-08 21:38:27 -0800 | [diff] [blame] | 410 | * em28xx_v4l2_close() |
akpm@osdl.org | a6c2ba2 | 2005-11-08 21:37:07 -0800 | [diff] [blame] | 411 | * stops streaming and deallocates all resources allocated by the v4l2 calls and ioctls |
| 412 | */ |
Mauro Carvalho Chehab | 3acf280 | 2005-11-08 21:38:27 -0800 | [diff] [blame] | 413 | static int em28xx_v4l2_close(struct inode *inode, struct file *filp) |
akpm@osdl.org | a6c2ba2 | 2005-11-08 21:37:07 -0800 | [diff] [blame] | 414 | { |
akpm@osdl.org | a6c2ba2 | 2005-11-08 21:37:07 -0800 | [diff] [blame] | 415 | int errCode; |
Mauro Carvalho Chehab | 3acf280 | 2005-11-08 21:38:27 -0800 | [diff] [blame] | 416 | struct em28xx *dev=filp->private_data; |
akpm@osdl.org | a6c2ba2 | 2005-11-08 21:37:07 -0800 | [diff] [blame] | 417 | |
Mauro Carvalho Chehab | eac9435 | 2005-11-08 21:38:43 -0800 | [diff] [blame] | 418 | em28xx_videodbg("users=%d\n", dev->users); |
akpm@osdl.org | a6c2ba2 | 2005-11-08 21:37:07 -0800 | [diff] [blame] | 419 | |
| 420 | down(&dev->lock); |
| 421 | |
Mauro Carvalho Chehab | 3acf280 | 2005-11-08 21:38:27 -0800 | [diff] [blame] | 422 | em28xx_uninit_isoc(dev); |
akpm@osdl.org | a6c2ba2 | 2005-11-08 21:37:07 -0800 | [diff] [blame] | 423 | |
Mauro Carvalho Chehab | 3acf280 | 2005-11-08 21:38:27 -0800 | [diff] [blame] | 424 | em28xx_release_buffers(dev); |
akpm@osdl.org | a6c2ba2 | 2005-11-08 21:37:07 -0800 | [diff] [blame] | 425 | |
| 426 | /* the device is already disconnect, free the remaining resources */ |
| 427 | if (dev->state & DEV_DISCONNECTED) { |
Mauro Carvalho Chehab | 3acf280 | 2005-11-08 21:38:27 -0800 | [diff] [blame] | 428 | em28xx_release_resources(dev); |
akpm@osdl.org | a6c2ba2 | 2005-11-08 21:37:07 -0800 | [diff] [blame] | 429 | up(&dev->lock); |
| 430 | kfree(dev); |
| 431 | return 0; |
| 432 | } |
| 433 | |
| 434 | /* set alternate 0 */ |
| 435 | dev->alt = 0; |
Mauro Carvalho Chehab | eac9435 | 2005-11-08 21:38:43 -0800 | [diff] [blame] | 436 | em28xx_videodbg("setting alternate 0\n"); |
akpm@osdl.org | a6c2ba2 | 2005-11-08 21:37:07 -0800 | [diff] [blame] | 437 | errCode = usb_set_interface(dev->udev, 0, 0); |
| 438 | if (errCode < 0) { |
Mauro Carvalho Chehab | 3acf280 | 2005-11-08 21:38:27 -0800 | [diff] [blame] | 439 | em28xx_errdev ("cannot change alternate number to 0 (error=%i)\n", |
akpm@osdl.org | a6c2ba2 | 2005-11-08 21:37:07 -0800 | [diff] [blame] | 440 | errCode); |
| 441 | } |
| 442 | |
| 443 | dev->users--; |
| 444 | wake_up_interruptible_nr(&dev->open, 1); |
| 445 | up(&dev->lock); |
| 446 | return 0; |
| 447 | } |
| 448 | |
| 449 | /* |
Mauro Carvalho Chehab | 3acf280 | 2005-11-08 21:38:27 -0800 | [diff] [blame] | 450 | * em28xx_v4l2_read() |
akpm@osdl.org | a6c2ba2 | 2005-11-08 21:37:07 -0800 | [diff] [blame] | 451 | * will allocate buffers when called for the first time |
| 452 | */ |
| 453 | static ssize_t |
Mauro Carvalho Chehab | 3acf280 | 2005-11-08 21:38:27 -0800 | [diff] [blame] | 454 | em28xx_v4l2_read(struct file *filp, char __user * buf, size_t count, |
akpm@osdl.org | a6c2ba2 | 2005-11-08 21:37:07 -0800 | [diff] [blame] | 455 | loff_t * f_pos) |
| 456 | { |
Mauro Carvalho Chehab | 3acf280 | 2005-11-08 21:38:27 -0800 | [diff] [blame] | 457 | struct em28xx_frame_t *f, *i; |
akpm@osdl.org | a6c2ba2 | 2005-11-08 21:37:07 -0800 | [diff] [blame] | 458 | unsigned long lock_flags; |
| 459 | int ret = 0; |
Mauro Carvalho Chehab | 3acf280 | 2005-11-08 21:38:27 -0800 | [diff] [blame] | 460 | struct em28xx *dev = filp->private_data; |
akpm@osdl.org | a6c2ba2 | 2005-11-08 21:37:07 -0800 | [diff] [blame] | 461 | |
| 462 | if (down_interruptible(&dev->fileop_lock)) |
| 463 | return -ERESTARTSYS; |
| 464 | |
| 465 | if (dev->state & DEV_DISCONNECTED) { |
Mauro Carvalho Chehab | eac9435 | 2005-11-08 21:38:43 -0800 | [diff] [blame] | 466 | em28xx_videodbg("device not present\n"); |
akpm@osdl.org | a6c2ba2 | 2005-11-08 21:37:07 -0800 | [diff] [blame] | 467 | up(&dev->fileop_lock); |
| 468 | return -ENODEV; |
| 469 | } |
| 470 | |
| 471 | if (dev->state & DEV_MISCONFIGURED) { |
Mauro Carvalho Chehab | eac9435 | 2005-11-08 21:38:43 -0800 | [diff] [blame] | 472 | em28xx_videodbg("device misconfigured; close and open it again\n"); |
akpm@osdl.org | a6c2ba2 | 2005-11-08 21:37:07 -0800 | [diff] [blame] | 473 | up(&dev->fileop_lock); |
| 474 | return -EIO; |
| 475 | } |
| 476 | |
| 477 | if (dev->io == IO_MMAP) { |
Mauro Carvalho Chehab | 3acf280 | 2005-11-08 21:38:27 -0800 | [diff] [blame] | 478 | em28xx_videodbg ("IO method is set to mmap; close and open" |
Mauro Carvalho Chehab | eac9435 | 2005-11-08 21:38:43 -0800 | [diff] [blame] | 479 | " the device again to choose the read method\n"); |
akpm@osdl.org | a6c2ba2 | 2005-11-08 21:37:07 -0800 | [diff] [blame] | 480 | up(&dev->fileop_lock); |
| 481 | return -EINVAL; |
| 482 | } |
| 483 | |
| 484 | if (dev->io == IO_NONE) { |
Mauro Carvalho Chehab | 3acf280 | 2005-11-08 21:38:27 -0800 | [diff] [blame] | 485 | if (!em28xx_request_buffers(dev, EM28XX_NUM_READ_FRAMES)) { |
| 486 | em28xx_errdev("read failed, not enough memory\n"); |
akpm@osdl.org | a6c2ba2 | 2005-11-08 21:37:07 -0800 | [diff] [blame] | 487 | up(&dev->fileop_lock); |
| 488 | return -ENOMEM; |
| 489 | } |
| 490 | dev->io = IO_READ; |
| 491 | dev->stream = STREAM_ON; |
Mauro Carvalho Chehab | 3acf280 | 2005-11-08 21:38:27 -0800 | [diff] [blame] | 492 | em28xx_queue_unusedframes(dev); |
akpm@osdl.org | a6c2ba2 | 2005-11-08 21:37:07 -0800 | [diff] [blame] | 493 | } |
| 494 | |
| 495 | if (!count) { |
| 496 | up(&dev->fileop_lock); |
| 497 | return 0; |
| 498 | } |
| 499 | |
| 500 | if (list_empty(&dev->outqueue)) { |
| 501 | if (filp->f_flags & O_NONBLOCK) { |
| 502 | up(&dev->fileop_lock); |
| 503 | return -EAGAIN; |
| 504 | } |
| 505 | ret = wait_event_interruptible |
| 506 | (dev->wait_frame, |
| 507 | (!list_empty(&dev->outqueue)) || |
| 508 | (dev->state & DEV_DISCONNECTED)); |
| 509 | if (ret) { |
| 510 | up(&dev->fileop_lock); |
| 511 | return ret; |
| 512 | } |
| 513 | if (dev->state & DEV_DISCONNECTED) { |
| 514 | up(&dev->fileop_lock); |
| 515 | return -ENODEV; |
| 516 | } |
| 517 | } |
| 518 | |
Mauro Carvalho Chehab | 3acf280 | 2005-11-08 21:38:27 -0800 | [diff] [blame] | 519 | f = list_entry(dev->outqueue.prev, struct em28xx_frame_t, frame); |
akpm@osdl.org | a6c2ba2 | 2005-11-08 21:37:07 -0800 | [diff] [blame] | 520 | |
| 521 | spin_lock_irqsave(&dev->queue_lock, lock_flags); |
| 522 | list_for_each_entry(i, &dev->outqueue, frame) |
| 523 | i->state = F_UNUSED; |
| 524 | INIT_LIST_HEAD(&dev->outqueue); |
| 525 | spin_unlock_irqrestore(&dev->queue_lock, lock_flags); |
| 526 | |
Mauro Carvalho Chehab | 3acf280 | 2005-11-08 21:38:27 -0800 | [diff] [blame] | 527 | em28xx_queue_unusedframes(dev); |
akpm@osdl.org | a6c2ba2 | 2005-11-08 21:37:07 -0800 | [diff] [blame] | 528 | |
| 529 | if (count > f->buf.length) |
| 530 | count = f->buf.length; |
| 531 | |
| 532 | if (copy_to_user(buf, f->bufmem, count)) { |
| 533 | up(&dev->fileop_lock); |
| 534 | return -EFAULT; |
| 535 | } |
| 536 | *f_pos += count; |
| 537 | |
| 538 | up(&dev->fileop_lock); |
| 539 | |
| 540 | return count; |
| 541 | } |
| 542 | |
| 543 | /* |
Mauro Carvalho Chehab | 3acf280 | 2005-11-08 21:38:27 -0800 | [diff] [blame] | 544 | * em28xx_v4l2_poll() |
akpm@osdl.org | a6c2ba2 | 2005-11-08 21:37:07 -0800 | [diff] [blame] | 545 | * will allocate buffers when called for the first time |
| 546 | */ |
Mauro Carvalho Chehab | 3acf280 | 2005-11-08 21:38:27 -0800 | [diff] [blame] | 547 | 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] | 548 | { |
akpm@osdl.org | a6c2ba2 | 2005-11-08 21:37:07 -0800 | [diff] [blame] | 549 | unsigned int mask = 0; |
Mauro Carvalho Chehab | 3acf280 | 2005-11-08 21:38:27 -0800 | [diff] [blame] | 550 | struct em28xx *dev = filp->private_data; |
akpm@osdl.org | a6c2ba2 | 2005-11-08 21:37:07 -0800 | [diff] [blame] | 551 | |
| 552 | if (down_interruptible(&dev->fileop_lock)) |
| 553 | return POLLERR; |
| 554 | |
| 555 | if (dev->state & DEV_DISCONNECTED) { |
Mauro Carvalho Chehab | eac9435 | 2005-11-08 21:38:43 -0800 | [diff] [blame] | 556 | em28xx_videodbg("device not present\n"); |
akpm@osdl.org | a6c2ba2 | 2005-11-08 21:37:07 -0800 | [diff] [blame] | 557 | } else if (dev->state & DEV_MISCONFIGURED) { |
Mauro Carvalho Chehab | eac9435 | 2005-11-08 21:38:43 -0800 | [diff] [blame] | 558 | em28xx_videodbg("device is misconfigured; close and open it again\n"); |
akpm@osdl.org | a6c2ba2 | 2005-11-08 21:37:07 -0800 | [diff] [blame] | 559 | } else { |
| 560 | if (dev->io == IO_NONE) { |
Mauro Carvalho Chehab | 3acf280 | 2005-11-08 21:38:27 -0800 | [diff] [blame] | 561 | if (!em28xx_request_buffers |
| 562 | (dev, EM28XX_NUM_READ_FRAMES)) { |
| 563 | em28xx_warn |
akpm@osdl.org | a6c2ba2 | 2005-11-08 21:37:07 -0800 | [diff] [blame] | 564 | ("poll() failed, not enough memory\n"); |
| 565 | } else { |
| 566 | dev->io = IO_READ; |
| 567 | dev->stream = STREAM_ON; |
| 568 | } |
| 569 | } |
| 570 | |
| 571 | if (dev->io == IO_READ) { |
Mauro Carvalho Chehab | 3acf280 | 2005-11-08 21:38:27 -0800 | [diff] [blame] | 572 | em28xx_queue_unusedframes(dev); |
akpm@osdl.org | a6c2ba2 | 2005-11-08 21:37:07 -0800 | [diff] [blame] | 573 | poll_wait(filp, &dev->wait_frame, wait); |
| 574 | |
| 575 | if (!list_empty(&dev->outqueue)) |
| 576 | mask |= POLLIN | POLLRDNORM; |
| 577 | |
| 578 | up(&dev->fileop_lock); |
| 579 | |
| 580 | return mask; |
| 581 | } |
| 582 | } |
| 583 | |
| 584 | up(&dev->fileop_lock); |
| 585 | return POLLERR; |
| 586 | } |
| 587 | |
| 588 | /* |
Mauro Carvalho Chehab | 3acf280 | 2005-11-08 21:38:27 -0800 | [diff] [blame] | 589 | * em28xx_vm_open() |
akpm@osdl.org | a6c2ba2 | 2005-11-08 21:37:07 -0800 | [diff] [blame] | 590 | */ |
Mauro Carvalho Chehab | 3acf280 | 2005-11-08 21:38:27 -0800 | [diff] [blame] | 591 | static void em28xx_vm_open(struct vm_area_struct *vma) |
akpm@osdl.org | a6c2ba2 | 2005-11-08 21:37:07 -0800 | [diff] [blame] | 592 | { |
Mauro Carvalho Chehab | 3acf280 | 2005-11-08 21:38:27 -0800 | [diff] [blame] | 593 | struct em28xx_frame_t *f = vma->vm_private_data; |
akpm@osdl.org | a6c2ba2 | 2005-11-08 21:37:07 -0800 | [diff] [blame] | 594 | f->vma_use_count++; |
| 595 | } |
| 596 | |
| 597 | /* |
Mauro Carvalho Chehab | 3acf280 | 2005-11-08 21:38:27 -0800 | [diff] [blame] | 598 | * em28xx_vm_close() |
akpm@osdl.org | a6c2ba2 | 2005-11-08 21:37:07 -0800 | [diff] [blame] | 599 | */ |
Mauro Carvalho Chehab | 3acf280 | 2005-11-08 21:38:27 -0800 | [diff] [blame] | 600 | static void em28xx_vm_close(struct vm_area_struct *vma) |
akpm@osdl.org | a6c2ba2 | 2005-11-08 21:37:07 -0800 | [diff] [blame] | 601 | { |
| 602 | /* NOTE: buffers are not freed here */ |
Mauro Carvalho Chehab | 3acf280 | 2005-11-08 21:38:27 -0800 | [diff] [blame] | 603 | struct em28xx_frame_t *f = vma->vm_private_data; |
akpm@osdl.org | a6c2ba2 | 2005-11-08 21:37:07 -0800 | [diff] [blame] | 604 | f->vma_use_count--; |
| 605 | } |
| 606 | |
Mauro Carvalho Chehab | 3acf280 | 2005-11-08 21:38:27 -0800 | [diff] [blame] | 607 | static struct vm_operations_struct em28xx_vm_ops = { |
| 608 | .open = em28xx_vm_open, |
| 609 | .close = em28xx_vm_close, |
akpm@osdl.org | a6c2ba2 | 2005-11-08 21:37:07 -0800 | [diff] [blame] | 610 | }; |
| 611 | |
| 612 | /* |
Mauro Carvalho Chehab | 3acf280 | 2005-11-08 21:38:27 -0800 | [diff] [blame] | 613 | * em28xx_v4l2_mmap() |
akpm@osdl.org | a6c2ba2 | 2005-11-08 21:37:07 -0800 | [diff] [blame] | 614 | */ |
Mauro Carvalho Chehab | 3acf280 | 2005-11-08 21:38:27 -0800 | [diff] [blame] | 615 | 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] | 616 | { |
akpm@osdl.org | a6c2ba2 | 2005-11-08 21:37:07 -0800 | [diff] [blame] | 617 | unsigned long size = vma->vm_end - vma->vm_start, |
Sascha Sommer | 3639c86 | 2005-12-12 00:37:30 -0800 | [diff] [blame] | 618 | start = vma->vm_start; |
| 619 | void *pos; |
akpm@osdl.org | a6c2ba2 | 2005-11-08 21:37:07 -0800 | [diff] [blame] | 620 | u32 i; |
Markus Rechberger | 9c75541 | 2005-11-08 21:37:52 -0800 | [diff] [blame] | 621 | |
Mauro Carvalho Chehab | 3acf280 | 2005-11-08 21:38:27 -0800 | [diff] [blame] | 622 | struct em28xx *dev = filp->private_data; |
Markus Rechberger | 9c75541 | 2005-11-08 21:37:52 -0800 | [diff] [blame] | 623 | |
akpm@osdl.org | a6c2ba2 | 2005-11-08 21:37:07 -0800 | [diff] [blame] | 624 | if (down_interruptible(&dev->fileop_lock)) |
| 625 | return -ERESTARTSYS; |
| 626 | |
| 627 | if (dev->state & DEV_DISCONNECTED) { |
Mauro Carvalho Chehab | eac9435 | 2005-11-08 21:38:43 -0800 | [diff] [blame] | 628 | em28xx_videodbg("mmap: device not present\n"); |
akpm@osdl.org | a6c2ba2 | 2005-11-08 21:37:07 -0800 | [diff] [blame] | 629 | up(&dev->fileop_lock); |
| 630 | return -ENODEV; |
| 631 | } |
| 632 | |
| 633 | if (dev->state & DEV_MISCONFIGURED) { |
Mauro Carvalho Chehab | 3acf280 | 2005-11-08 21:38:27 -0800 | [diff] [blame] | 634 | em28xx_videodbg ("mmap: Device is misconfigured; close and " |
Mauro Carvalho Chehab | eac9435 | 2005-11-08 21:38:43 -0800 | [diff] [blame] | 635 | "open it again\n"); |
akpm@osdl.org | a6c2ba2 | 2005-11-08 21:37:07 -0800 | [diff] [blame] | 636 | up(&dev->fileop_lock); |
| 637 | return -EIO; |
| 638 | } |
| 639 | |
| 640 | if (dev->io != IO_MMAP || !(vma->vm_flags & VM_WRITE) || |
| 641 | size != PAGE_ALIGN(dev->frame[0].buf.length)) { |
| 642 | up(&dev->fileop_lock); |
| 643 | return -EINVAL; |
| 644 | } |
| 645 | |
| 646 | for (i = 0; i < dev->num_frames; i++) { |
| 647 | if ((dev->frame[i].buf.m.offset >> PAGE_SHIFT) == vma->vm_pgoff) |
| 648 | break; |
| 649 | } |
| 650 | if (i == dev->num_frames) { |
Mauro Carvalho Chehab | eac9435 | 2005-11-08 21:38:43 -0800 | [diff] [blame] | 651 | em28xx_videodbg("mmap: user supplied mapping address is out of range\n"); |
akpm@osdl.org | a6c2ba2 | 2005-11-08 21:37:07 -0800 | [diff] [blame] | 652 | up(&dev->fileop_lock); |
| 653 | return -EINVAL; |
| 654 | } |
| 655 | |
| 656 | /* VM_IO is eventually going to replace PageReserved altogether */ |
| 657 | vma->vm_flags |= VM_IO; |
| 658 | vma->vm_flags |= VM_RESERVED; /* avoid to swap out this VMA */ |
| 659 | |
Sascha Sommer | 3639c86 | 2005-12-12 00:37:30 -0800 | [diff] [blame] | 660 | pos = dev->frame[i].bufmem; |
akpm@osdl.org | a6c2ba2 | 2005-11-08 21:37:07 -0800 | [diff] [blame] | 661 | while (size > 0) { /* size is page-aligned */ |
Sascha Sommer | 3639c86 | 2005-12-12 00:37:30 -0800 | [diff] [blame] | 662 | if (vm_insert_page(vma, start, vmalloc_to_page(pos))) { |
| 663 | em28xx_videodbg("mmap: vm_insert_page failed\n"); |
akpm@osdl.org | a6c2ba2 | 2005-11-08 21:37:07 -0800 | [diff] [blame] | 664 | up(&dev->fileop_lock); |
| 665 | return -EAGAIN; |
| 666 | } |
| 667 | start += PAGE_SIZE; |
| 668 | pos += PAGE_SIZE; |
| 669 | size -= PAGE_SIZE; |
| 670 | } |
| 671 | |
Mauro Carvalho Chehab | 3acf280 | 2005-11-08 21:38:27 -0800 | [diff] [blame] | 672 | vma->vm_ops = &em28xx_vm_ops; |
akpm@osdl.org | a6c2ba2 | 2005-11-08 21:37:07 -0800 | [diff] [blame] | 673 | vma->vm_private_data = &dev->frame[i]; |
| 674 | |
Mauro Carvalho Chehab | 3acf280 | 2005-11-08 21:38:27 -0800 | [diff] [blame] | 675 | em28xx_vm_open(vma); |
akpm@osdl.org | a6c2ba2 | 2005-11-08 21:37:07 -0800 | [diff] [blame] | 676 | up(&dev->fileop_lock); |
| 677 | return 0; |
| 678 | } |
| 679 | |
| 680 | /* |
Mauro Carvalho Chehab | 3acf280 | 2005-11-08 21:38:27 -0800 | [diff] [blame] | 681 | * em28xx_get_ctrl() |
akpm@osdl.org | a6c2ba2 | 2005-11-08 21:37:07 -0800 | [diff] [blame] | 682 | * return the current saturation, brightness or contrast, mute state |
| 683 | */ |
Mauro Carvalho Chehab | 3acf280 | 2005-11-08 21:38:27 -0800 | [diff] [blame] | 684 | static int em28xx_get_ctrl(struct em28xx *dev, struct v4l2_control *ctrl) |
akpm@osdl.org | a6c2ba2 | 2005-11-08 21:37:07 -0800 | [diff] [blame] | 685 | { |
akpm@osdl.org | a6c2ba2 | 2005-11-08 21:37:07 -0800 | [diff] [blame] | 686 | switch (ctrl->id) { |
| 687 | case V4L2_CID_AUDIO_MUTE: |
| 688 | ctrl->value = dev->mute; |
| 689 | return 0; |
| 690 | case V4L2_CID_AUDIO_VOLUME: |
| 691 | ctrl->value = dev->volume; |
| 692 | return 0; |
Mauro Carvalho Chehab | c0477ad | 2006-01-09 15:25:14 -0200 | [diff] [blame] | 693 | default: |
| 694 | return -EINVAL; |
| 695 | } |
| 696 | } |
| 697 | |
| 698 | /*FIXME: should be moved to saa711x */ |
| 699 | static int saa711x_get_ctrl(struct em28xx *dev, struct v4l2_control *ctrl) |
| 700 | { |
| 701 | s32 tmp; |
| 702 | switch (ctrl->id) { |
akpm@osdl.org | a6c2ba2 | 2005-11-08 21:37:07 -0800 | [diff] [blame] | 703 | case V4L2_CID_BRIGHTNESS: |
Mauro Carvalho Chehab | 3acf280 | 2005-11-08 21:38:27 -0800 | [diff] [blame] | 704 | if ((tmp = em28xx_brightness_get(dev)) < 0) |
akpm@osdl.org | a6c2ba2 | 2005-11-08 21:37:07 -0800 | [diff] [blame] | 705 | return -EIO; |
| 706 | ctrl->value = (s32) ((s8) tmp); /* FIXME: clenaer way to extend sign? */ |
| 707 | return 0; |
| 708 | case V4L2_CID_CONTRAST: |
Mauro Carvalho Chehab | 3acf280 | 2005-11-08 21:38:27 -0800 | [diff] [blame] | 709 | if ((ctrl->value = em28xx_contrast_get(dev)) < 0) |
akpm@osdl.org | a6c2ba2 | 2005-11-08 21:37:07 -0800 | [diff] [blame] | 710 | return -EIO; |
| 711 | return 0; |
| 712 | case V4L2_CID_SATURATION: |
Mauro Carvalho Chehab | 3acf280 | 2005-11-08 21:38:27 -0800 | [diff] [blame] | 713 | if ((ctrl->value = em28xx_saturation_get(dev)) < 0) |
akpm@osdl.org | a6c2ba2 | 2005-11-08 21:37:07 -0800 | [diff] [blame] | 714 | return -EIO; |
| 715 | return 0; |
| 716 | case V4L2_CID_RED_BALANCE: |
Mauro Carvalho Chehab | 3acf280 | 2005-11-08 21:38:27 -0800 | [diff] [blame] | 717 | if ((tmp = em28xx_v_balance_get(dev)) < 0) |
akpm@osdl.org | a6c2ba2 | 2005-11-08 21:37:07 -0800 | [diff] [blame] | 718 | return -EIO; |
| 719 | ctrl->value = (s32) ((s8) tmp); /* FIXME: clenaer way to extend sign? */ |
| 720 | return 0; |
| 721 | case V4L2_CID_BLUE_BALANCE: |
Mauro Carvalho Chehab | 3acf280 | 2005-11-08 21:38:27 -0800 | [diff] [blame] | 722 | if ((tmp = em28xx_u_balance_get(dev)) < 0) |
akpm@osdl.org | a6c2ba2 | 2005-11-08 21:37:07 -0800 | [diff] [blame] | 723 | return -EIO; |
| 724 | ctrl->value = (s32) ((s8) tmp); /* FIXME: clenaer way to extend sign? */ |
| 725 | return 0; |
| 726 | case V4L2_CID_GAMMA: |
Mauro Carvalho Chehab | 3acf280 | 2005-11-08 21:38:27 -0800 | [diff] [blame] | 727 | if ((ctrl->value = em28xx_gamma_get(dev)) < 0) |
akpm@osdl.org | a6c2ba2 | 2005-11-08 21:37:07 -0800 | [diff] [blame] | 728 | return -EIO; |
| 729 | return 0; |
| 730 | default: |
| 731 | return -EINVAL; |
| 732 | } |
| 733 | } |
| 734 | |
| 735 | /* |
Mauro Carvalho Chehab | 3acf280 | 2005-11-08 21:38:27 -0800 | [diff] [blame] | 736 | * em28xx_set_ctrl() |
akpm@osdl.org | a6c2ba2 | 2005-11-08 21:37:07 -0800 | [diff] [blame] | 737 | * mute or set new saturation, brightness or contrast |
| 738 | */ |
Mauro Carvalho Chehab | 3acf280 | 2005-11-08 21:38:27 -0800 | [diff] [blame] | 739 | static int em28xx_set_ctrl(struct em28xx *dev, const struct v4l2_control *ctrl) |
akpm@osdl.org | a6c2ba2 | 2005-11-08 21:37:07 -0800 | [diff] [blame] | 740 | { |
| 741 | switch (ctrl->id) { |
| 742 | case V4L2_CID_AUDIO_MUTE: |
| 743 | if (ctrl->value != dev->mute) { |
| 744 | dev->mute = ctrl->value; |
Mauro Carvalho Chehab | 3acf280 | 2005-11-08 21:38:27 -0800 | [diff] [blame] | 745 | em28xx_audio_usb_mute(dev, ctrl->value); |
| 746 | return em28xx_audio_analog_set(dev); |
akpm@osdl.org | a6c2ba2 | 2005-11-08 21:37:07 -0800 | [diff] [blame] | 747 | } |
| 748 | return 0; |
| 749 | case V4L2_CID_AUDIO_VOLUME: |
| 750 | dev->volume = ctrl->value; |
Mauro Carvalho Chehab | 3acf280 | 2005-11-08 21:38:27 -0800 | [diff] [blame] | 751 | return em28xx_audio_analog_set(dev); |
Mauro Carvalho Chehab | c0477ad | 2006-01-09 15:25:14 -0200 | [diff] [blame] | 752 | default: |
| 753 | return -EINVAL; |
| 754 | } |
| 755 | } |
| 756 | |
| 757 | /*FIXME: should be moved to saa711x */ |
| 758 | static int saa711x_set_ctrl(struct em28xx *dev, const struct v4l2_control *ctrl) |
| 759 | { |
| 760 | switch (ctrl->id) { |
akpm@osdl.org | a6c2ba2 | 2005-11-08 21:37:07 -0800 | [diff] [blame] | 761 | case V4L2_CID_BRIGHTNESS: |
Mauro Carvalho Chehab | 3acf280 | 2005-11-08 21:38:27 -0800 | [diff] [blame] | 762 | return em28xx_brightness_set(dev, ctrl->value); |
akpm@osdl.org | a6c2ba2 | 2005-11-08 21:37:07 -0800 | [diff] [blame] | 763 | case V4L2_CID_CONTRAST: |
Mauro Carvalho Chehab | 3acf280 | 2005-11-08 21:38:27 -0800 | [diff] [blame] | 764 | return em28xx_contrast_set(dev, ctrl->value); |
akpm@osdl.org | a6c2ba2 | 2005-11-08 21:37:07 -0800 | [diff] [blame] | 765 | case V4L2_CID_SATURATION: |
Mauro Carvalho Chehab | 3acf280 | 2005-11-08 21:38:27 -0800 | [diff] [blame] | 766 | return em28xx_saturation_set(dev, ctrl->value); |
akpm@osdl.org | a6c2ba2 | 2005-11-08 21:37:07 -0800 | [diff] [blame] | 767 | case V4L2_CID_RED_BALANCE: |
Mauro Carvalho Chehab | 3acf280 | 2005-11-08 21:38:27 -0800 | [diff] [blame] | 768 | return em28xx_v_balance_set(dev, ctrl->value); |
akpm@osdl.org | a6c2ba2 | 2005-11-08 21:37:07 -0800 | [diff] [blame] | 769 | case V4L2_CID_BLUE_BALANCE: |
Mauro Carvalho Chehab | 3acf280 | 2005-11-08 21:38:27 -0800 | [diff] [blame] | 770 | return em28xx_u_balance_set(dev, ctrl->value); |
akpm@osdl.org | a6c2ba2 | 2005-11-08 21:37:07 -0800 | [diff] [blame] | 771 | case V4L2_CID_GAMMA: |
Mauro Carvalho Chehab | 3acf280 | 2005-11-08 21:38:27 -0800 | [diff] [blame] | 772 | return em28xx_gamma_set(dev, ctrl->value); |
akpm@osdl.org | a6c2ba2 | 2005-11-08 21:37:07 -0800 | [diff] [blame] | 773 | default: |
| 774 | return -EINVAL; |
| 775 | } |
| 776 | } |
| 777 | |
| 778 | /* |
Mauro Carvalho Chehab | 3acf280 | 2005-11-08 21:38:27 -0800 | [diff] [blame] | 779 | * em28xx_stream_interrupt() |
akpm@osdl.org | a6c2ba2 | 2005-11-08 21:37:07 -0800 | [diff] [blame] | 780 | * stops streaming |
| 781 | */ |
Mauro Carvalho Chehab | 3acf280 | 2005-11-08 21:38:27 -0800 | [diff] [blame] | 782 | static int em28xx_stream_interrupt(struct em28xx *dev) |
akpm@osdl.org | a6c2ba2 | 2005-11-08 21:37:07 -0800 | [diff] [blame] | 783 | { |
| 784 | int ret = 0; |
| 785 | |
| 786 | /* stop reading from the device */ |
| 787 | |
| 788 | dev->stream = STREAM_INTERRUPT; |
| 789 | ret = wait_event_timeout(dev->wait_stream, |
| 790 | (dev->stream == STREAM_OFF) || |
| 791 | (dev->state & DEV_DISCONNECTED), |
Mauro Carvalho Chehab | 3acf280 | 2005-11-08 21:38:27 -0800 | [diff] [blame] | 792 | EM28XX_URB_TIMEOUT); |
akpm@osdl.org | a6c2ba2 | 2005-11-08 21:37:07 -0800 | [diff] [blame] | 793 | if (dev->state & DEV_DISCONNECTED) |
| 794 | return -ENODEV; |
| 795 | else if (ret) { |
| 796 | dev->state |= DEV_MISCONFIGURED; |
Mauro Carvalho Chehab | 3acf280 | 2005-11-08 21:38:27 -0800 | [diff] [blame] | 797 | em28xx_videodbg("device is misconfigured; close and " |
Mauro Carvalho Chehab | eac9435 | 2005-11-08 21:38:43 -0800 | [diff] [blame] | 798 | "open /dev/video%d again\n", dev->vdev->minor); |
akpm@osdl.org | a6c2ba2 | 2005-11-08 21:37:07 -0800 | [diff] [blame] | 799 | return ret; |
| 800 | } |
| 801 | |
| 802 | return 0; |
| 803 | } |
| 804 | |
Mauro Carvalho Chehab | 3acf280 | 2005-11-08 21:38:27 -0800 | [diff] [blame] | 805 | static int em28xx_set_norm(struct em28xx *dev, int width, int height) |
akpm@osdl.org | a6c2ba2 | 2005-11-08 21:37:07 -0800 | [diff] [blame] | 806 | { |
| 807 | unsigned int hscale, vscale; |
| 808 | unsigned int maxh, maxw; |
| 809 | |
| 810 | maxw = norm_maxw(dev); |
| 811 | maxh = norm_maxh(dev); |
| 812 | |
| 813 | /* width must even because of the YUYV format */ |
| 814 | /* height must be even because of interlacing */ |
| 815 | height &= 0xfffe; |
| 816 | width &= 0xfffe; |
| 817 | |
| 818 | if (height < 32) |
| 819 | height = 32; |
| 820 | if (height > maxh) |
| 821 | height = maxh; |
| 822 | if (width < 48) |
| 823 | width = 48; |
| 824 | if (width > maxw) |
| 825 | width = maxw; |
| 826 | |
| 827 | if ((hscale = (((unsigned long)maxw) << 12) / width - 4096L) >= 0x4000) |
| 828 | hscale = 0x3fff; |
| 829 | width = (((unsigned long)maxw) << 12) / (hscale + 4096L); |
| 830 | |
| 831 | if ((vscale = (((unsigned long)maxh) << 12) / height - 4096L) >= 0x4000) |
| 832 | vscale = 0x3fff; |
| 833 | height = (((unsigned long)maxh) << 12) / (vscale + 4096L); |
| 834 | |
| 835 | /* set new image size */ |
| 836 | dev->width = width; |
| 837 | dev->height = height; |
| 838 | dev->frame_size = dev->width * dev->height * 2; |
| 839 | dev->field_size = dev->frame_size >> 1; /*both_fileds ? dev->frame_size>>1 : dev->frame_size; */ |
| 840 | dev->bytesperline = dev->width * 2; |
| 841 | dev->hscale = hscale; |
| 842 | dev->vscale = vscale; |
| 843 | |
Mauro Carvalho Chehab | 3acf280 | 2005-11-08 21:38:27 -0800 | [diff] [blame] | 844 | em28xx_resolution_set(dev); |
akpm@osdl.org | a6c2ba2 | 2005-11-08 21:37:07 -0800 | [diff] [blame] | 845 | |
| 846 | return 0; |
| 847 | } |
| 848 | |
akpm@osdl.org | a6c2ba2 | 2005-11-08 21:37:07 -0800 | [diff] [blame] | 849 | /* |
Mauro Carvalho Chehab | 3acf280 | 2005-11-08 21:38:27 -0800 | [diff] [blame] | 850 | * em28xx_v4l2_do_ioctl() |
akpm@osdl.org | a6c2ba2 | 2005-11-08 21:37:07 -0800 | [diff] [blame] | 851 | * This function is _not_ called directly, but from |
Mauro Carvalho Chehab | 3acf280 | 2005-11-08 21:38:27 -0800 | [diff] [blame] | 852 | * em28xx_v4l2_ioctl. Userspace |
akpm@osdl.org | a6c2ba2 | 2005-11-08 21:37:07 -0800 | [diff] [blame] | 853 | * copying is done already, arg is a kernel pointer. |
| 854 | */ |
Mauro Carvalho Chehab | 3acf280 | 2005-11-08 21:38:27 -0800 | [diff] [blame] | 855 | static int em28xx_do_ioctl(struct inode *inode, struct file *filp, |
| 856 | struct em28xx *dev, unsigned int cmd, void *arg, |
akpm@osdl.org | a6c2ba2 | 2005-11-08 21:37:07 -0800 | [diff] [blame] | 857 | v4l2_kioctl driver_ioctl) |
| 858 | { |
| 859 | int ret; |
| 860 | |
| 861 | switch (cmd) { |
| 862 | /* ---------- tv norms ---------- */ |
| 863 | case VIDIOC_ENUMSTD: |
| 864 | { |
| 865 | struct v4l2_standard *e = arg; |
| 866 | unsigned int i; |
| 867 | |
| 868 | i = e->index; |
| 869 | if (i >= TVNORMS) |
| 870 | return -EINVAL; |
| 871 | ret = v4l2_video_std_construct(e, tvnorms[e->index].id, |
| 872 | tvnorms[e->index].name); |
| 873 | e->index = i; |
| 874 | if (ret < 0) |
| 875 | return ret; |
| 876 | return 0; |
| 877 | } |
| 878 | case VIDIOC_G_STD: |
| 879 | { |
| 880 | v4l2_std_id *id = arg; |
| 881 | |
| 882 | *id = dev->tvnorm->id; |
| 883 | return 0; |
| 884 | } |
| 885 | case VIDIOC_S_STD: |
| 886 | { |
| 887 | v4l2_std_id *id = arg; |
| 888 | unsigned int i; |
| 889 | |
| 890 | for (i = 0; i < TVNORMS; i++) |
| 891 | if (*id == tvnorms[i].id) |
| 892 | break; |
| 893 | if (i == TVNORMS) |
| 894 | for (i = 0; i < TVNORMS; i++) |
| 895 | if (*id & tvnorms[i].id) |
| 896 | break; |
| 897 | if (i == TVNORMS) |
| 898 | return -EINVAL; |
| 899 | |
| 900 | down(&dev->lock); |
| 901 | dev->tvnorm = &tvnorms[i]; |
| 902 | |
Mauro Carvalho Chehab | 3acf280 | 2005-11-08 21:38:27 -0800 | [diff] [blame] | 903 | em28xx_set_norm(dev, dev->width, dev->height); |
akpm@osdl.org | a6c2ba2 | 2005-11-08 21:37:07 -0800 | [diff] [blame] | 904 | |
| 905 | /* |
| 906 | dev->width=norm_maxw(dev); |
| 907 | dev->height=norm_maxh(dev); |
| 908 | dev->frame_size=dev->width*dev->height*2; |
| 909 | dev->field_size=dev->frame_size>>1; |
| 910 | dev->bytesperline=dev->width*2; |
| 911 | dev->hscale=0; |
| 912 | dev->vscale=0; |
| 913 | |
Mauro Carvalho Chehab | 3acf280 | 2005-11-08 21:38:27 -0800 | [diff] [blame] | 914 | em28xx_resolution_set(dev); |
akpm@osdl.org | a6c2ba2 | 2005-11-08 21:37:07 -0800 | [diff] [blame] | 915 | */ |
| 916 | /* |
Mauro Carvalho Chehab | 3acf280 | 2005-11-08 21:38:27 -0800 | [diff] [blame] | 917 | em28xx_uninit_isoc(dev); |
| 918 | em28xx_set_alternate(dev); |
| 919 | em28xx_capture_start(dev, 1); |
| 920 | em28xx_resolution_set(dev); |
| 921 | em28xx_init_isoc(dev); |
akpm@osdl.org | a6c2ba2 | 2005-11-08 21:37:07 -0800 | [diff] [blame] | 922 | */ |
Mauro Carvalho Chehab | 3acf280 | 2005-11-08 21:38:27 -0800 | [diff] [blame] | 923 | em28xx_i2c_call_clients(dev, DECODER_SET_NORM, |
akpm@osdl.org | a6c2ba2 | 2005-11-08 21:37:07 -0800 | [diff] [blame] | 924 | &tvnorms[i].mode); |
Mauro Carvalho Chehab | 3acf280 | 2005-11-08 21:38:27 -0800 | [diff] [blame] | 925 | em28xx_i2c_call_clients(dev, VIDIOC_S_STD, |
akpm@osdl.org | a6c2ba2 | 2005-11-08 21:37:07 -0800 | [diff] [blame] | 926 | &dev->tvnorm->id); |
| 927 | |
| 928 | up(&dev->lock); |
| 929 | |
| 930 | return 0; |
| 931 | } |
| 932 | |
| 933 | /* ------ input switching ---------- */ |
| 934 | case VIDIOC_ENUMINPUT: |
| 935 | { |
| 936 | struct v4l2_input *i = arg; |
| 937 | unsigned int n; |
| 938 | static const char *iname[] = { |
Mauro Carvalho Chehab | 3acf280 | 2005-11-08 21:38:27 -0800 | [diff] [blame] | 939 | [EM28XX_VMUX_COMPOSITE1] = "Composite1", |
| 940 | [EM28XX_VMUX_COMPOSITE2] = "Composite2", |
| 941 | [EM28XX_VMUX_COMPOSITE3] = "Composite3", |
| 942 | [EM28XX_VMUX_COMPOSITE4] = "Composite4", |
| 943 | [EM28XX_VMUX_SVIDEO] = "S-Video", |
| 944 | [EM28XX_VMUX_TELEVISION] = "Television", |
| 945 | [EM28XX_VMUX_CABLE] = "Cable TV", |
| 946 | [EM28XX_VMUX_DVB] = "DVB", |
| 947 | [EM28XX_VMUX_DEBUG] = "for debug only", |
akpm@osdl.org | a6c2ba2 | 2005-11-08 21:37:07 -0800 | [diff] [blame] | 948 | }; |
| 949 | |
| 950 | n = i->index; |
Mauro Carvalho Chehab | 3acf280 | 2005-11-08 21:38:27 -0800 | [diff] [blame] | 951 | if (n >= MAX_EM28XX_INPUT) |
akpm@osdl.org | a6c2ba2 | 2005-11-08 21:37:07 -0800 | [diff] [blame] | 952 | return -EINVAL; |
| 953 | if (0 == INPUT(n)->type) |
| 954 | return -EINVAL; |
| 955 | memset(i, 0, sizeof(*i)); |
| 956 | i->index = n; |
| 957 | i->type = V4L2_INPUT_TYPE_CAMERA; |
| 958 | strcpy(i->name, iname[INPUT(n)->type]); |
Mauro Carvalho Chehab | 3acf280 | 2005-11-08 21:38:27 -0800 | [diff] [blame] | 959 | if ((EM28XX_VMUX_TELEVISION == INPUT(n)->type) || |
| 960 | (EM28XX_VMUX_CABLE == INPUT(n)->type)) |
akpm@osdl.org | a6c2ba2 | 2005-11-08 21:37:07 -0800 | [diff] [blame] | 961 | i->type = V4L2_INPUT_TYPE_TUNER; |
| 962 | for (n = 0; n < ARRAY_SIZE(tvnorms); n++) |
| 963 | i->std |= tvnorms[n].id; |
| 964 | return 0; |
| 965 | } |
| 966 | |
| 967 | case VIDIOC_G_INPUT: |
| 968 | { |
| 969 | int *i = arg; |
| 970 | *i = dev->ctl_input; |
| 971 | |
| 972 | return 0; |
| 973 | } |
| 974 | |
| 975 | case VIDIOC_S_INPUT: |
| 976 | { |
| 977 | int *index = arg; |
| 978 | |
Mauro Carvalho Chehab | 3acf280 | 2005-11-08 21:38:27 -0800 | [diff] [blame] | 979 | if (*index >= MAX_EM28XX_INPUT) |
akpm@osdl.org | a6c2ba2 | 2005-11-08 21:37:07 -0800 | [diff] [blame] | 980 | return -EINVAL; |
| 981 | if (0 == INPUT(*index)->type) |
| 982 | return -EINVAL; |
| 983 | |
| 984 | down(&dev->lock); |
| 985 | video_mux(dev, *index); |
| 986 | up(&dev->lock); |
| 987 | |
| 988 | return 0; |
| 989 | } |
| 990 | |
| 991 | case VIDIOC_G_AUDIO: |
| 992 | { |
| 993 | struct v4l2_audio *a = arg; |
| 994 | unsigned int index = a->index; |
| 995 | |
| 996 | if (a->index > 1) |
| 997 | return -EINVAL; |
| 998 | memset(a, 0, sizeof(*a)); |
| 999 | index = dev->ctl_ainput; |
| 1000 | |
| 1001 | if (index == 0) { |
| 1002 | strcpy(a->name, "Television"); |
| 1003 | } else { |
| 1004 | strcpy(a->name, "Line In"); |
| 1005 | } |
| 1006 | a->capability = V4L2_AUDCAP_STEREO; |
| 1007 | a->index = index; |
| 1008 | return 0; |
| 1009 | } |
| 1010 | |
| 1011 | case VIDIOC_S_AUDIO: |
| 1012 | { |
| 1013 | struct v4l2_audio *a = arg; |
| 1014 | if (a->index != dev->ctl_ainput) |
| 1015 | return -EINVAL; |
| 1016 | |
| 1017 | return 0; |
| 1018 | } |
| 1019 | |
| 1020 | /* --- controls ---------------------------------------------- */ |
| 1021 | case VIDIOC_QUERYCTRL: |
| 1022 | { |
| 1023 | struct v4l2_queryctrl *qc = arg; |
Mauro Carvalho Chehab | c0477ad | 2006-01-09 15:25:14 -0200 | [diff] [blame] | 1024 | int i, id=qc->id; |
| 1025 | |
| 1026 | memset(qc,0,sizeof(*qc)); |
| 1027 | qc->id=id; |
| 1028 | |
| 1029 | if (!dev->has_msp34xx) { |
| 1030 | for (i = 0; i < ARRAY_SIZE(em28xx_qctrl); i++) { |
| 1031 | if (qc->id && qc->id == em28xx_qctrl[i].id) { |
| 1032 | memcpy(qc, &(em28xx_qctrl[i]), |
| 1033 | sizeof(*qc)); |
| 1034 | return 0; |
| 1035 | } |
| 1036 | } |
| 1037 | } |
| 1038 | if (dev->decoder == EM28XX_TVP5150) { |
| 1039 | em28xx_i2c_call_clients(dev,cmd,qc); |
| 1040 | if (qc->type) |
| 1041 | return 0; |
| 1042 | else |
| 1043 | return -EINVAL; |
| 1044 | } |
| 1045 | for (i = 0; i < ARRAY_SIZE(saa711x_qctrl); i++) { |
| 1046 | if (qc->id && qc->id == saa711x_qctrl[i].id) { |
| 1047 | memcpy(qc, &(saa711x_qctrl[i]), |
akpm@osdl.org | a6c2ba2 | 2005-11-08 21:37:07 -0800 | [diff] [blame] | 1048 | sizeof(*qc)); |
| 1049 | return 0; |
| 1050 | } |
Mauro Carvalho Chehab | c0477ad | 2006-01-09 15:25:14 -0200 | [diff] [blame] | 1051 | } |
akpm@osdl.org | a6c2ba2 | 2005-11-08 21:37:07 -0800 | [diff] [blame] | 1052 | |
| 1053 | return -EINVAL; |
| 1054 | } |
| 1055 | |
| 1056 | case VIDIOC_G_CTRL: |
| 1057 | { |
| 1058 | struct v4l2_control *ctrl = arg; |
Mauro Carvalho Chehab | c0477ad | 2006-01-09 15:25:14 -0200 | [diff] [blame] | 1059 | int retval=-EINVAL; |
akpm@osdl.org | a6c2ba2 | 2005-11-08 21:37:07 -0800 | [diff] [blame] | 1060 | |
Mauro Carvalho Chehab | c0477ad | 2006-01-09 15:25:14 -0200 | [diff] [blame] | 1061 | if (!dev->has_msp34xx) |
| 1062 | retval=em28xx_get_ctrl(dev, ctrl); |
| 1063 | if (retval==-EINVAL) { |
| 1064 | if (dev->decoder == EM28XX_TVP5150) { |
| 1065 | em28xx_i2c_call_clients(dev,cmd,arg); |
| 1066 | return 0; |
| 1067 | } |
akpm@osdl.org | a6c2ba2 | 2005-11-08 21:37:07 -0800 | [diff] [blame] | 1068 | |
Mauro Carvalho Chehab | c0477ad | 2006-01-09 15:25:14 -0200 | [diff] [blame] | 1069 | return saa711x_get_ctrl(dev, ctrl); |
| 1070 | } else return retval; |
akpm@osdl.org | a6c2ba2 | 2005-11-08 21:37:07 -0800 | [diff] [blame] | 1071 | } |
| 1072 | |
akpm@osdl.org | a6c2ba2 | 2005-11-08 21:37:07 -0800 | [diff] [blame] | 1073 | case VIDIOC_S_CTRL: |
| 1074 | { |
| 1075 | struct v4l2_control *ctrl = arg; |
Mauro Carvalho Chehab | c0477ad | 2006-01-09 15:25:14 -0200 | [diff] [blame] | 1076 | u8 i; |
akpm@osdl.org | a6c2ba2 | 2005-11-08 21:37:07 -0800 | [diff] [blame] | 1077 | |
Mauro Carvalho Chehab | c0477ad | 2006-01-09 15:25:14 -0200 | [diff] [blame] | 1078 | if (!dev->has_msp34xx){ |
| 1079 | for (i = 0; i < ARRAY_SIZE(em28xx_qctrl); i++) { |
| 1080 | if (ctrl->id == em28xx_qctrl[i].id) { |
| 1081 | if (ctrl->value < |
| 1082 | em28xx_qctrl[i].minimum |
| 1083 | || ctrl->value > |
| 1084 | em28xx_qctrl[i].maximum) |
| 1085 | return -ERANGE; |
| 1086 | return em28xx_set_ctrl(dev, ctrl); |
| 1087 | } |
akpm@osdl.org | a6c2ba2 | 2005-11-08 21:37:07 -0800 | [diff] [blame] | 1088 | } |
Mauro Carvalho Chehab | c0477ad | 2006-01-09 15:25:14 -0200 | [diff] [blame] | 1089 | } |
| 1090 | |
| 1091 | if (dev->decoder == EM28XX_TVP5150) { |
| 1092 | em28xx_i2c_call_clients(dev,cmd,arg); |
| 1093 | return 0; |
Hans Verkuil | 7865c44 | 2006-01-09 15:25:14 -0200 | [diff] [blame] | 1094 | } else if (!dev->has_msp34xx) { |
Mauro Carvalho Chehab | c0477ad | 2006-01-09 15:25:14 -0200 | [diff] [blame] | 1095 | for (i = 0; i < ARRAY_SIZE(em28xx_qctrl); i++) { |
| 1096 | if (ctrl->id == em28xx_qctrl[i].id) { |
| 1097 | if (ctrl->value < |
| 1098 | em28xx_qctrl[i].minimum |
| 1099 | || ctrl->value > |
| 1100 | em28xx_qctrl[i].maximum) |
| 1101 | return -ERANGE; |
| 1102 | return em28xx_set_ctrl(dev, ctrl); |
| 1103 | } |
| 1104 | } |
| 1105 | for (i = 0; i < ARRAY_SIZE(saa711x_qctrl); i++) { |
| 1106 | if (ctrl->id == saa711x_qctrl[i].id) { |
| 1107 | if (ctrl->value < |
| 1108 | saa711x_qctrl[i].minimum |
| 1109 | || ctrl->value > |
| 1110 | saa711x_qctrl[i].maximum) |
| 1111 | return -ERANGE; |
| 1112 | return saa711x_set_ctrl(dev, ctrl); |
| 1113 | } |
| 1114 | } |
| 1115 | } |
| 1116 | |
akpm@osdl.org | a6c2ba2 | 2005-11-08 21:37:07 -0800 | [diff] [blame] | 1117 | return -EINVAL; |
| 1118 | } |
| 1119 | |
| 1120 | /* --- tuner ioctls ------------------------------------------ */ |
| 1121 | case VIDIOC_G_TUNER: |
| 1122 | { |
| 1123 | struct v4l2_tuner *t = arg; |
| 1124 | int status = 0; |
| 1125 | |
| 1126 | if (0 != t->index) |
| 1127 | return -EINVAL; |
| 1128 | |
| 1129 | memset(t, 0, sizeof(*t)); |
| 1130 | strcpy(t->name, "Tuner"); |
| 1131 | t->type = V4L2_TUNER_ANALOG_TV; |
| 1132 | t->capability = V4L2_TUNER_CAP_NORM; |
| 1133 | t->rangehigh = 0xffffffffUL; /* FIXME: set correct range */ |
| 1134 | /* t->signal = 0xffff;*/ |
Mauro Carvalho Chehab | 3acf280 | 2005-11-08 21:38:27 -0800 | [diff] [blame] | 1135 | /* em28xx_i2c_call_clients(dev,VIDIOC_G_TUNER,t);*/ |
akpm@osdl.org | a6c2ba2 | 2005-11-08 21:37:07 -0800 | [diff] [blame] | 1136 | /* No way to get signal strength? */ |
| 1137 | down(&dev->lock); |
Mauro Carvalho Chehab | 3acf280 | 2005-11-08 21:38:27 -0800 | [diff] [blame] | 1138 | em28xx_i2c_call_clients(dev, DECODER_GET_STATUS, |
akpm@osdl.org | a6c2ba2 | 2005-11-08 21:37:07 -0800 | [diff] [blame] | 1139 | &status); |
| 1140 | up(&dev->lock); |
| 1141 | t->signal = |
| 1142 | (status & DECODER_STATUS_GOOD) != 0 ? 0xffff : 0; |
| 1143 | |
Mauro Carvalho Chehab | eac9435 | 2005-11-08 21:38:43 -0800 | [diff] [blame] | 1144 | em28xx_videodbg("VIDIO_G_TUNER: signal=%x, afc=%x\n", t->signal, |
akpm@osdl.org | a6c2ba2 | 2005-11-08 21:37:07 -0800 | [diff] [blame] | 1145 | t->afc); |
| 1146 | return 0; |
| 1147 | } |
| 1148 | case VIDIOC_S_TUNER: |
| 1149 | { |
| 1150 | struct v4l2_tuner *t = arg; |
| 1151 | int status = 0; |
| 1152 | |
| 1153 | if (0 != t->index) |
| 1154 | return -EINVAL; |
| 1155 | memset(t, 0, sizeof(*t)); |
| 1156 | strcpy(t->name, "Tuner"); |
| 1157 | t->type = V4L2_TUNER_ANALOG_TV; |
| 1158 | t->capability = V4L2_TUNER_CAP_NORM; |
| 1159 | t->rangehigh = 0xffffffffUL; /* FIXME: set correct range */ |
| 1160 | /* t->signal = 0xffff; */ |
| 1161 | /* No way to get signal strength? */ |
| 1162 | down(&dev->lock); |
Mauro Carvalho Chehab | 3acf280 | 2005-11-08 21:38:27 -0800 | [diff] [blame] | 1163 | em28xx_i2c_call_clients(dev, DECODER_GET_STATUS, |
akpm@osdl.org | a6c2ba2 | 2005-11-08 21:37:07 -0800 | [diff] [blame] | 1164 | &status); |
| 1165 | up(&dev->lock); |
| 1166 | t->signal = |
| 1167 | (status & DECODER_STATUS_GOOD) != 0 ? 0xffff : 0; |
| 1168 | |
Mauro Carvalho Chehab | 3acf280 | 2005-11-08 21:38:27 -0800 | [diff] [blame] | 1169 | em28xx_videodbg("VIDIO_S_TUNER: signal=%x, afc=%x\n", |
akpm@osdl.org | a6c2ba2 | 2005-11-08 21:37:07 -0800 | [diff] [blame] | 1170 | t->signal, t->afc); |
| 1171 | return 0; |
| 1172 | } |
| 1173 | case VIDIOC_G_FREQUENCY: |
| 1174 | { |
| 1175 | struct v4l2_frequency *f = arg; |
| 1176 | |
| 1177 | memset(f, 0, sizeof(*f)); |
| 1178 | f->type = V4L2_TUNER_ANALOG_TV; |
| 1179 | f->frequency = dev->ctl_freq; |
| 1180 | |
| 1181 | return 0; |
| 1182 | } |
| 1183 | case VIDIOC_S_FREQUENCY: |
| 1184 | { |
| 1185 | struct v4l2_frequency *f = arg; |
| 1186 | |
| 1187 | if (0 != f->tuner) |
| 1188 | return -EINVAL; |
| 1189 | |
| 1190 | if (V4L2_TUNER_ANALOG_TV != f->type) |
| 1191 | return -EINVAL; |
| 1192 | |
| 1193 | down(&dev->lock); |
| 1194 | dev->ctl_freq = f->frequency; |
Mauro Carvalho Chehab | 3acf280 | 2005-11-08 21:38:27 -0800 | [diff] [blame] | 1195 | em28xx_i2c_call_clients(dev, VIDIOC_S_FREQUENCY, f); |
akpm@osdl.org | a6c2ba2 | 2005-11-08 21:37:07 -0800 | [diff] [blame] | 1196 | up(&dev->lock); |
| 1197 | return 0; |
| 1198 | } |
| 1199 | |
| 1200 | case VIDIOC_CROPCAP: |
| 1201 | { |
| 1202 | struct v4l2_cropcap *cc = arg; |
| 1203 | |
| 1204 | if (cc->type != V4L2_BUF_TYPE_VIDEO_CAPTURE) |
Mauro Carvalho Chehab | 596d92d | 2005-11-08 21:37:24 -0800 | [diff] [blame] | 1205 | return -EINVAL; |
akpm@osdl.org | a6c2ba2 | 2005-11-08 21:37:07 -0800 | [diff] [blame] | 1206 | cc->bounds.left = 0; |
| 1207 | cc->bounds.top = 0; |
| 1208 | cc->bounds.width = dev->width; |
| 1209 | cc->bounds.height = dev->height; |
| 1210 | cc->defrect = cc->bounds; |
| 1211 | cc->pixelaspect.numerator = 54; /* 4:3 FIXME: remove magic numbers */ |
| 1212 | cc->pixelaspect.denominator = 59; |
| 1213 | return 0; |
| 1214 | } |
| 1215 | case VIDIOC_STREAMON: |
| 1216 | { |
| 1217 | int *type = arg; |
| 1218 | |
| 1219 | if (*type != V4L2_BUF_TYPE_VIDEO_CAPTURE |
| 1220 | || dev->io != IO_MMAP) |
| 1221 | return -EINVAL; |
| 1222 | |
| 1223 | if (list_empty(&dev->inqueue)) |
| 1224 | return -EINVAL; |
| 1225 | |
| 1226 | dev->stream = STREAM_ON; /* FIXME: Start video capture here? */ |
| 1227 | |
Mauro Carvalho Chehab | eac9435 | 2005-11-08 21:38:43 -0800 | [diff] [blame] | 1228 | em28xx_videodbg("VIDIOC_STREAMON: starting stream\n"); |
akpm@osdl.org | a6c2ba2 | 2005-11-08 21:37:07 -0800 | [diff] [blame] | 1229 | |
| 1230 | return 0; |
| 1231 | } |
| 1232 | case VIDIOC_STREAMOFF: |
| 1233 | { |
| 1234 | int *type = arg; |
| 1235 | int ret; |
| 1236 | |
| 1237 | if (*type != V4L2_BUF_TYPE_VIDEO_CAPTURE |
| 1238 | || dev->io != IO_MMAP) |
| 1239 | return -EINVAL; |
| 1240 | |
| 1241 | if (dev->stream == STREAM_ON) { |
Mauro Carvalho Chehab | eac9435 | 2005-11-08 21:38:43 -0800 | [diff] [blame] | 1242 | em28xx_videodbg ("VIDIOC_STREAMOFF: interrupting stream\n"); |
Mauro Carvalho Chehab | 3acf280 | 2005-11-08 21:38:27 -0800 | [diff] [blame] | 1243 | if ((ret = em28xx_stream_interrupt(dev))) |
akpm@osdl.org | a6c2ba2 | 2005-11-08 21:37:07 -0800 | [diff] [blame] | 1244 | return ret; |
| 1245 | } |
Mauro Carvalho Chehab | 3acf280 | 2005-11-08 21:38:27 -0800 | [diff] [blame] | 1246 | em28xx_empty_framequeues(dev); |
akpm@osdl.org | a6c2ba2 | 2005-11-08 21:37:07 -0800 | [diff] [blame] | 1247 | |
| 1248 | return 0; |
| 1249 | } |
| 1250 | default: |
| 1251 | return v4l_compat_translate_ioctl(inode, filp, cmd, arg, |
| 1252 | driver_ioctl); |
| 1253 | } |
| 1254 | return 0; |
| 1255 | } |
| 1256 | |
| 1257 | /* |
Mauro Carvalho Chehab | 3acf280 | 2005-11-08 21:38:27 -0800 | [diff] [blame] | 1258 | * em28xx_v4l2_do_ioctl() |
akpm@osdl.org | a6c2ba2 | 2005-11-08 21:37:07 -0800 | [diff] [blame] | 1259 | * This function is _not_ called directly, but from |
Mauro Carvalho Chehab | 3acf280 | 2005-11-08 21:38:27 -0800 | [diff] [blame] | 1260 | * em28xx_v4l2_ioctl. Userspace |
akpm@osdl.org | a6c2ba2 | 2005-11-08 21:37:07 -0800 | [diff] [blame] | 1261 | * copying is done already, arg is a kernel pointer. |
| 1262 | */ |
Mauro Carvalho Chehab | 3acf280 | 2005-11-08 21:38:27 -0800 | [diff] [blame] | 1263 | static int em28xx_video_do_ioctl(struct inode *inode, struct file *filp, |
akpm@osdl.org | a6c2ba2 | 2005-11-08 21:37:07 -0800 | [diff] [blame] | 1264 | unsigned int cmd, void *arg) |
| 1265 | { |
Mauro Carvalho Chehab | 3acf280 | 2005-11-08 21:38:27 -0800 | [diff] [blame] | 1266 | struct em28xx *dev = filp->private_data; |
akpm@osdl.org | a6c2ba2 | 2005-11-08 21:37:07 -0800 | [diff] [blame] | 1267 | |
| 1268 | if (!dev) |
| 1269 | return -ENODEV; |
| 1270 | |
| 1271 | if (video_debug > 1) |
Michael Krufky | 5e453dc | 2006-01-09 15:32:31 -0200 | [diff] [blame] | 1272 | v4l_print_ioctl(dev->name,cmd); |
akpm@osdl.org | a6c2ba2 | 2005-11-08 21:37:07 -0800 | [diff] [blame] | 1273 | |
| 1274 | switch (cmd) { |
| 1275 | |
| 1276 | /* --- capabilities ------------------------------------------ */ |
| 1277 | case VIDIOC_QUERYCAP: |
| 1278 | { |
| 1279 | struct v4l2_capability *cap = arg; |
| 1280 | |
| 1281 | memset(cap, 0, sizeof(*cap)); |
Mauro Carvalho Chehab | 3acf280 | 2005-11-08 21:38:27 -0800 | [diff] [blame] | 1282 | strlcpy(cap->driver, "em28xx", sizeof(cap->driver)); |
| 1283 | strlcpy(cap->card, em28xx_boards[dev->model].name, |
akpm@osdl.org | a6c2ba2 | 2005-11-08 21:37:07 -0800 | [diff] [blame] | 1284 | sizeof(cap->card)); |
| 1285 | strlcpy(cap->bus_info, dev->udev->dev.bus_id, |
| 1286 | sizeof(cap->bus_info)); |
Mauro Carvalho Chehab | 3acf280 | 2005-11-08 21:38:27 -0800 | [diff] [blame] | 1287 | cap->version = EM28XX_VERSION_CODE; |
akpm@osdl.org | a6c2ba2 | 2005-11-08 21:37:07 -0800 | [diff] [blame] | 1288 | cap->capabilities = |
| 1289 | V4L2_CAP_VIDEO_CAPTURE | |
| 1290 | V4L2_CAP_AUDIO | |
| 1291 | V4L2_CAP_READWRITE | V4L2_CAP_STREAMING; |
| 1292 | if (dev->has_tuner) |
| 1293 | cap->capabilities |= V4L2_CAP_TUNER; |
| 1294 | return 0; |
| 1295 | } |
| 1296 | |
| 1297 | /* --- capture ioctls ---------------------------------------- */ |
| 1298 | case VIDIOC_ENUM_FMT: |
| 1299 | { |
| 1300 | struct v4l2_fmtdesc *fmtd = arg; |
| 1301 | |
| 1302 | if (fmtd->index != 0) |
| 1303 | return -EINVAL; |
| 1304 | memset(fmtd, 0, sizeof(*fmtd)); |
| 1305 | fmtd->type = V4L2_BUF_TYPE_VIDEO_CAPTURE; |
| 1306 | strcpy(fmtd->description, "Packed YUY2"); |
| 1307 | fmtd->pixelformat = V4L2_PIX_FMT_YUYV; |
| 1308 | memset(fmtd->reserved, 0, sizeof(fmtd->reserved)); |
| 1309 | return 0; |
| 1310 | } |
| 1311 | |
| 1312 | case VIDIOC_G_FMT: |
| 1313 | { |
| 1314 | struct v4l2_format *format = arg; |
| 1315 | |
Mauro Carvalho Chehab | eac9435 | 2005-11-08 21:38:43 -0800 | [diff] [blame] | 1316 | em28xx_videodbg("VIDIOC_G_FMT: type=%s\n", |
akpm@osdl.org | a6c2ba2 | 2005-11-08 21:37:07 -0800 | [diff] [blame] | 1317 | format->type == |
| 1318 | V4L2_BUF_TYPE_VIDEO_CAPTURE ? |
| 1319 | "V4L2_BUF_TYPE_VIDEO_CAPTURE" : format->type == |
| 1320 | V4L2_BUF_TYPE_VBI_CAPTURE ? |
| 1321 | "V4L2_BUF_TYPE_VBI_CAPTURE " : |
| 1322 | "not supported"); |
| 1323 | |
| 1324 | if (format->type != V4L2_BUF_TYPE_VIDEO_CAPTURE) |
| 1325 | return -EINVAL; |
| 1326 | |
| 1327 | format->fmt.pix.width = dev->width; |
| 1328 | format->fmt.pix.height = dev->height; |
| 1329 | format->fmt.pix.pixelformat = V4L2_PIX_FMT_YUYV; |
| 1330 | format->fmt.pix.bytesperline = dev->bytesperline; |
| 1331 | format->fmt.pix.sizeimage = dev->frame_size; |
| 1332 | format->fmt.pix.colorspace = V4L2_COLORSPACE_SMPTE170M; |
| 1333 | format->fmt.pix.field = dev->interlaced ? V4L2_FIELD_INTERLACED : V4L2_FIELD_TOP; /* FIXME: TOP? NONE? BOTTOM? ALTENATE? */ |
| 1334 | |
Mauro Carvalho Chehab | eac9435 | 2005-11-08 21:38:43 -0800 | [diff] [blame] | 1335 | em28xx_videodbg("VIDIOC_G_FMT: %dx%d\n", dev->width, |
akpm@osdl.org | a6c2ba2 | 2005-11-08 21:37:07 -0800 | [diff] [blame] | 1336 | dev->height); |
| 1337 | return 0; |
| 1338 | } |
| 1339 | |
| 1340 | case VIDIOC_TRY_FMT: |
| 1341 | case VIDIOC_S_FMT: |
| 1342 | { |
| 1343 | struct v4l2_format *format = arg; |
| 1344 | u32 i; |
| 1345 | int ret = 0; |
| 1346 | int width = format->fmt.pix.width; |
| 1347 | int height = format->fmt.pix.height; |
| 1348 | unsigned int hscale, vscale; |
| 1349 | unsigned int maxh, maxw; |
| 1350 | |
| 1351 | maxw = norm_maxw(dev); |
| 1352 | maxh = norm_maxh(dev); |
| 1353 | |
| 1354 | /* int both_fields; */ |
| 1355 | |
Mauro Carvalho Chehab | eac9435 | 2005-11-08 21:38:43 -0800 | [diff] [blame] | 1356 | em28xx_videodbg("%s: type=%s\n", |
akpm@osdl.org | a6c2ba2 | 2005-11-08 21:37:07 -0800 | [diff] [blame] | 1357 | cmd == |
| 1358 | VIDIOC_TRY_FMT ? "VIDIOC_TRY_FMT" : |
| 1359 | "VIDIOC_S_FMT", |
| 1360 | format->type == |
| 1361 | V4L2_BUF_TYPE_VIDEO_CAPTURE ? |
| 1362 | "V4L2_BUF_TYPE_VIDEO_CAPTURE" : format->type == |
| 1363 | V4L2_BUF_TYPE_VBI_CAPTURE ? |
| 1364 | "V4L2_BUF_TYPE_VBI_CAPTURE " : |
| 1365 | "not supported"); |
| 1366 | |
| 1367 | if (format->type != V4L2_BUF_TYPE_VIDEO_CAPTURE) |
| 1368 | return -EINVAL; |
| 1369 | |
Mauro Carvalho Chehab | eac9435 | 2005-11-08 21:38:43 -0800 | [diff] [blame] | 1370 | em28xx_videodbg("%s: requested %dx%d\n", |
akpm@osdl.org | a6c2ba2 | 2005-11-08 21:37:07 -0800 | [diff] [blame] | 1371 | cmd == |
| 1372 | VIDIOC_TRY_FMT ? "VIDIOC_TRY_FMT" : |
| 1373 | "VIDIOC_S_FMT", format->fmt.pix.width, |
| 1374 | format->fmt.pix.height); |
| 1375 | |
| 1376 | /* FIXME: Move some code away from here */ |
| 1377 | /* width must even because of the YUYV format */ |
| 1378 | /* height must be even because of interlacing */ |
| 1379 | height &= 0xfffe; |
| 1380 | width &= 0xfffe; |
| 1381 | |
| 1382 | if (height < 32) |
| 1383 | height = 32; |
| 1384 | if (height > maxh) |
| 1385 | height = maxh; |
| 1386 | if (width < 48) |
| 1387 | width = 48; |
| 1388 | if (width > maxw) |
| 1389 | width = maxw; |
| 1390 | |
Sascha Sommer | 74458e6 | 2005-11-08 21:37:33 -0800 | [diff] [blame] | 1391 | if(dev->is_em2800){ |
Sascha Sommer | 52c02fc | 2005-11-08 21:38:10 -0800 | [diff] [blame] | 1392 | /* the em2800 can only scale down to 50% */ |
Sascha Sommer | 74458e6 | 2005-11-08 21:37:33 -0800 | [diff] [blame] | 1393 | if(height % (maxh / 2)) |
| 1394 | height=maxh; |
| 1395 | if(width % (maxw / 2)) |
| 1396 | width=maxw; |
Sascha Sommer | 52c02fc | 2005-11-08 21:38:10 -0800 | [diff] [blame] | 1397 | /* according to empiatech support */ |
| 1398 | /* the MaxPacketSize is to small to support */ |
| 1399 | /* framesizes larger than 640x480 @ 30 fps */ |
| 1400 | /* or 640x576 @ 25 fps. As this would cut */ |
| 1401 | /* of a part of the image we prefer */ |
| 1402 | /* 360x576 or 360x480 for now */ |
Sascha Sommer | 74458e6 | 2005-11-08 21:37:33 -0800 | [diff] [blame] | 1403 | if(width == maxw && height == maxh) |
| 1404 | width /= 2; |
| 1405 | } |
| 1406 | |
akpm@osdl.org | a6c2ba2 | 2005-11-08 21:37:07 -0800 | [diff] [blame] | 1407 | if ((hscale = |
| 1408 | (((unsigned long)maxw) << 12) / width - 4096L) >= |
| 1409 | 0x4000) |
| 1410 | hscale = 0x3fff; |
| 1411 | width = |
| 1412 | (((unsigned long)maxw) << 12) / (hscale + 4096L); |
| 1413 | |
| 1414 | if ((vscale = |
| 1415 | (((unsigned long)maxh) << 12) / height - 4096L) >= |
| 1416 | 0x4000) |
| 1417 | vscale = 0x3fff; |
| 1418 | height = |
| 1419 | (((unsigned long)maxh) << 12) / (vscale + 4096L); |
| 1420 | |
| 1421 | format->fmt.pix.width = width; |
| 1422 | format->fmt.pix.height = height; |
| 1423 | format->fmt.pix.pixelformat = V4L2_PIX_FMT_YUYV; |
| 1424 | format->fmt.pix.bytesperline = width * 2; |
| 1425 | format->fmt.pix.sizeimage = width * 2 * height; |
| 1426 | format->fmt.pix.colorspace = V4L2_COLORSPACE_SMPTE170M; |
| 1427 | format->fmt.pix.field = V4L2_FIELD_INTERLACED; |
| 1428 | |
Mauro Carvalho Chehab | eac9435 | 2005-11-08 21:38:43 -0800 | [diff] [blame] | 1429 | em28xx_videodbg("%s: returned %dx%d (%d, %d)\n", |
akpm@osdl.org | a6c2ba2 | 2005-11-08 21:37:07 -0800 | [diff] [blame] | 1430 | cmd == |
| 1431 | VIDIOC_TRY_FMT ? "VIDIOC_TRY_FMT" : |
| 1432 | "VIDIOC_S_FMT", format->fmt.pix.width, |
| 1433 | format->fmt.pix.height, hscale, vscale); |
| 1434 | |
| 1435 | if (cmd == VIDIOC_TRY_FMT) |
| 1436 | return 0; |
| 1437 | |
| 1438 | for (i = 0; i < dev->num_frames; i++) |
| 1439 | if (dev->frame[i].vma_use_count) { |
Mauro Carvalho Chehab | 3acf280 | 2005-11-08 21:38:27 -0800 | [diff] [blame] | 1440 | em28xx_videodbg("VIDIOC_S_FMT failed. " |
Mauro Carvalho Chehab | eac9435 | 2005-11-08 21:38:43 -0800 | [diff] [blame] | 1441 | "Unmap the buffers first.\n"); |
akpm@osdl.org | a6c2ba2 | 2005-11-08 21:37:07 -0800 | [diff] [blame] | 1442 | return -EINVAL; |
| 1443 | } |
| 1444 | |
| 1445 | /* stop io in case it is already in progress */ |
| 1446 | if (dev->stream == STREAM_ON) { |
Mauro Carvalho Chehab | eac9435 | 2005-11-08 21:38:43 -0800 | [diff] [blame] | 1447 | em28xx_videodbg("VIDIOC_SET_FMT: interupting stream\n"); |
Mauro Carvalho Chehab | 3acf280 | 2005-11-08 21:38:27 -0800 | [diff] [blame] | 1448 | if ((ret = em28xx_stream_interrupt(dev))) |
akpm@osdl.org | a6c2ba2 | 2005-11-08 21:37:07 -0800 | [diff] [blame] | 1449 | return ret; |
| 1450 | } |
| 1451 | |
Mauro Carvalho Chehab | 3acf280 | 2005-11-08 21:38:27 -0800 | [diff] [blame] | 1452 | em28xx_release_buffers(dev); |
akpm@osdl.org | a6c2ba2 | 2005-11-08 21:37:07 -0800 | [diff] [blame] | 1453 | dev->io = IO_NONE; |
| 1454 | |
| 1455 | /* set new image size */ |
| 1456 | dev->width = width; |
| 1457 | dev->height = height; |
| 1458 | dev->frame_size = dev->width * dev->height * 2; |
| 1459 | dev->field_size = dev->frame_size >> 1; /*both_fileds ? dev->frame_size>>1 : dev->frame_size; */ |
| 1460 | dev->bytesperline = dev->width * 2; |
| 1461 | dev->hscale = hscale; |
| 1462 | dev->vscale = vscale; |
| 1463 | /* dev->both_fileds = both_fileds; */ |
Mauro Carvalho Chehab | 3acf280 | 2005-11-08 21:38:27 -0800 | [diff] [blame] | 1464 | em28xx_uninit_isoc(dev); |
| 1465 | em28xx_set_alternate(dev); |
| 1466 | em28xx_capture_start(dev, 1); |
| 1467 | em28xx_resolution_set(dev); |
| 1468 | em28xx_init_isoc(dev); |
akpm@osdl.org | a6c2ba2 | 2005-11-08 21:37:07 -0800 | [diff] [blame] | 1469 | |
| 1470 | return 0; |
| 1471 | } |
| 1472 | |
| 1473 | /* --- streaming capture ------------------------------------- */ |
| 1474 | case VIDIOC_REQBUFS: |
| 1475 | { |
| 1476 | struct v4l2_requestbuffers *rb = arg; |
| 1477 | u32 i; |
| 1478 | int ret; |
| 1479 | |
| 1480 | if (rb->type != V4L2_BUF_TYPE_VIDEO_CAPTURE || |
| 1481 | rb->memory != V4L2_MEMORY_MMAP) |
| 1482 | return -EINVAL; |
| 1483 | |
| 1484 | if (dev->io == IO_READ) { |
Mauro Carvalho Chehab | 3acf280 | 2005-11-08 21:38:27 -0800 | [diff] [blame] | 1485 | em28xx_videodbg ("method is set to read;" |
akpm@osdl.org | a6c2ba2 | 2005-11-08 21:37:07 -0800 | [diff] [blame] | 1486 | " close and open the device again to" |
Mauro Carvalho Chehab | eac9435 | 2005-11-08 21:38:43 -0800 | [diff] [blame] | 1487 | " choose the mmap I/O method\n"); |
akpm@osdl.org | a6c2ba2 | 2005-11-08 21:37:07 -0800 | [diff] [blame] | 1488 | return -EINVAL; |
| 1489 | } |
| 1490 | |
| 1491 | for (i = 0; i < dev->num_frames; i++) |
| 1492 | if (dev->frame[i].vma_use_count) { |
Mauro Carvalho Chehab | eac9435 | 2005-11-08 21:38:43 -0800 | [diff] [blame] | 1493 | em28xx_videodbg ("VIDIOC_REQBUFS failed; previous buffers are still mapped\n"); |
akpm@osdl.org | a6c2ba2 | 2005-11-08 21:37:07 -0800 | [diff] [blame] | 1494 | return -EINVAL; |
| 1495 | } |
| 1496 | |
| 1497 | if (dev->stream == STREAM_ON) { |
Mauro Carvalho Chehab | eac9435 | 2005-11-08 21:38:43 -0800 | [diff] [blame] | 1498 | em28xx_videodbg("VIDIOC_REQBUFS: interrupting stream\n"); |
Mauro Carvalho Chehab | 3acf280 | 2005-11-08 21:38:27 -0800 | [diff] [blame] | 1499 | if ((ret = em28xx_stream_interrupt(dev))) |
akpm@osdl.org | a6c2ba2 | 2005-11-08 21:37:07 -0800 | [diff] [blame] | 1500 | return ret; |
| 1501 | } |
| 1502 | |
Mauro Carvalho Chehab | 3acf280 | 2005-11-08 21:38:27 -0800 | [diff] [blame] | 1503 | em28xx_empty_framequeues(dev); |
akpm@osdl.org | a6c2ba2 | 2005-11-08 21:37:07 -0800 | [diff] [blame] | 1504 | |
Mauro Carvalho Chehab | 3acf280 | 2005-11-08 21:38:27 -0800 | [diff] [blame] | 1505 | em28xx_release_buffers(dev); |
akpm@osdl.org | a6c2ba2 | 2005-11-08 21:37:07 -0800 | [diff] [blame] | 1506 | if (rb->count) |
| 1507 | rb->count = |
Mauro Carvalho Chehab | 3acf280 | 2005-11-08 21:38:27 -0800 | [diff] [blame] | 1508 | em28xx_request_buffers(dev, rb->count); |
akpm@osdl.org | a6c2ba2 | 2005-11-08 21:37:07 -0800 | [diff] [blame] | 1509 | |
| 1510 | dev->frame_current = NULL; |
| 1511 | |
Mauro Carvalho Chehab | eac9435 | 2005-11-08 21:38:43 -0800 | [diff] [blame] | 1512 | em28xx_videodbg ("VIDIOC_REQBUFS: setting io method to mmap: num bufs %i\n", |
akpm@osdl.org | a6c2ba2 | 2005-11-08 21:37:07 -0800 | [diff] [blame] | 1513 | rb->count); |
| 1514 | dev->io = rb->count ? IO_MMAP : IO_NONE; |
| 1515 | return 0; |
| 1516 | } |
| 1517 | |
| 1518 | case VIDIOC_QUERYBUF: |
| 1519 | { |
| 1520 | struct v4l2_buffer *b = arg; |
| 1521 | |
| 1522 | if (b->type != V4L2_BUF_TYPE_VIDEO_CAPTURE || |
| 1523 | b->index >= dev->num_frames || dev->io != IO_MMAP) |
| 1524 | return -EINVAL; |
| 1525 | |
| 1526 | memcpy(b, &dev->frame[b->index].buf, sizeof(*b)); |
| 1527 | |
| 1528 | if (dev->frame[b->index].vma_use_count) { |
| 1529 | b->flags |= V4L2_BUF_FLAG_MAPPED; |
| 1530 | } |
| 1531 | if (dev->frame[b->index].state == F_DONE) |
| 1532 | b->flags |= V4L2_BUF_FLAG_DONE; |
| 1533 | else if (dev->frame[b->index].state != F_UNUSED) |
| 1534 | b->flags |= V4L2_BUF_FLAG_QUEUED; |
| 1535 | return 0; |
| 1536 | } |
| 1537 | case VIDIOC_QBUF: |
| 1538 | { |
| 1539 | struct v4l2_buffer *b = arg; |
| 1540 | unsigned long lock_flags; |
| 1541 | |
| 1542 | if (b->type != V4L2_BUF_TYPE_VIDEO_CAPTURE || |
| 1543 | b->index >= dev->num_frames || dev->io != IO_MMAP) { |
| 1544 | return -EINVAL; |
| 1545 | } |
| 1546 | |
| 1547 | if (dev->frame[b->index].state != F_UNUSED) { |
| 1548 | return -EAGAIN; |
| 1549 | } |
| 1550 | dev->frame[b->index].state = F_QUEUED; |
| 1551 | |
| 1552 | /* add frame to fifo */ |
| 1553 | spin_lock_irqsave(&dev->queue_lock, lock_flags); |
| 1554 | list_add_tail(&dev->frame[b->index].frame, |
| 1555 | &dev->inqueue); |
| 1556 | spin_unlock_irqrestore(&dev->queue_lock, lock_flags); |
| 1557 | |
| 1558 | return 0; |
| 1559 | } |
| 1560 | case VIDIOC_DQBUF: |
| 1561 | { |
| 1562 | struct v4l2_buffer *b = arg; |
Mauro Carvalho Chehab | 3acf280 | 2005-11-08 21:38:27 -0800 | [diff] [blame] | 1563 | struct em28xx_frame_t *f; |
akpm@osdl.org | a6c2ba2 | 2005-11-08 21:37:07 -0800 | [diff] [blame] | 1564 | unsigned long lock_flags; |
| 1565 | int ret = 0; |
| 1566 | |
| 1567 | if (b->type != V4L2_BUF_TYPE_VIDEO_CAPTURE |
| 1568 | || dev->io != IO_MMAP) |
| 1569 | return -EINVAL; |
| 1570 | |
| 1571 | if (list_empty(&dev->outqueue)) { |
| 1572 | if (dev->stream == STREAM_OFF) |
| 1573 | return -EINVAL; |
| 1574 | if (filp->f_flags & O_NONBLOCK) |
| 1575 | return -EAGAIN; |
| 1576 | ret = wait_event_interruptible |
| 1577 | (dev->wait_frame, |
| 1578 | (!list_empty(&dev->outqueue)) || |
| 1579 | (dev->state & DEV_DISCONNECTED)); |
| 1580 | if (ret) |
| 1581 | return ret; |
| 1582 | if (dev->state & DEV_DISCONNECTED) |
| 1583 | return -ENODEV; |
| 1584 | } |
| 1585 | |
| 1586 | spin_lock_irqsave(&dev->queue_lock, lock_flags); |
| 1587 | f = list_entry(dev->outqueue.next, |
Mauro Carvalho Chehab | 3acf280 | 2005-11-08 21:38:27 -0800 | [diff] [blame] | 1588 | struct em28xx_frame_t, frame); |
akpm@osdl.org | a6c2ba2 | 2005-11-08 21:37:07 -0800 | [diff] [blame] | 1589 | list_del(dev->outqueue.next); |
| 1590 | spin_unlock_irqrestore(&dev->queue_lock, lock_flags); |
| 1591 | |
| 1592 | f->state = F_UNUSED; |
| 1593 | memcpy(b, &f->buf, sizeof(*b)); |
| 1594 | |
| 1595 | if (f->vma_use_count) |
| 1596 | b->flags |= V4L2_BUF_FLAG_MAPPED; |
| 1597 | |
| 1598 | return 0; |
| 1599 | } |
| 1600 | default: |
Mauro Carvalho Chehab | 3acf280 | 2005-11-08 21:38:27 -0800 | [diff] [blame] | 1601 | return em28xx_do_ioctl(inode, filp, dev, cmd, arg, |
| 1602 | em28xx_video_do_ioctl); |
akpm@osdl.org | a6c2ba2 | 2005-11-08 21:37:07 -0800 | [diff] [blame] | 1603 | } |
| 1604 | return 0; |
| 1605 | } |
| 1606 | |
| 1607 | /* |
Mauro Carvalho Chehab | 3acf280 | 2005-11-08 21:38:27 -0800 | [diff] [blame] | 1608 | * em28xx_v4l2_ioctl() |
| 1609 | * handle v4l2 ioctl the main action happens in em28xx_v4l2_do_ioctl() |
akpm@osdl.org | a6c2ba2 | 2005-11-08 21:37:07 -0800 | [diff] [blame] | 1610 | */ |
Mauro Carvalho Chehab | 3acf280 | 2005-11-08 21:38:27 -0800 | [diff] [blame] | 1611 | static int em28xx_v4l2_ioctl(struct inode *inode, struct file *filp, |
akpm@osdl.org | a6c2ba2 | 2005-11-08 21:37:07 -0800 | [diff] [blame] | 1612 | unsigned int cmd, unsigned long arg) |
| 1613 | { |
akpm@osdl.org | a6c2ba2 | 2005-11-08 21:37:07 -0800 | [diff] [blame] | 1614 | int ret = 0; |
Mauro Carvalho Chehab | 3acf280 | 2005-11-08 21:38:27 -0800 | [diff] [blame] | 1615 | struct em28xx *dev = filp->private_data; |
akpm@osdl.org | a6c2ba2 | 2005-11-08 21:37:07 -0800 | [diff] [blame] | 1616 | |
| 1617 | if (down_interruptible(&dev->fileop_lock)) |
| 1618 | return -ERESTARTSYS; |
| 1619 | |
| 1620 | if (dev->state & DEV_DISCONNECTED) { |
Mauro Carvalho Chehab | 3acf280 | 2005-11-08 21:38:27 -0800 | [diff] [blame] | 1621 | em28xx_errdev("v4l2 ioctl: device not present\n"); |
akpm@osdl.org | a6c2ba2 | 2005-11-08 21:37:07 -0800 | [diff] [blame] | 1622 | up(&dev->fileop_lock); |
| 1623 | return -ENODEV; |
| 1624 | } |
| 1625 | |
| 1626 | if (dev->state & DEV_MISCONFIGURED) { |
Mauro Carvalho Chehab | 3acf280 | 2005-11-08 21:38:27 -0800 | [diff] [blame] | 1627 | em28xx_errdev |
akpm@osdl.org | a6c2ba2 | 2005-11-08 21:37:07 -0800 | [diff] [blame] | 1628 | ("v4l2 ioctl: device is misconfigured; close and open it again\n"); |
| 1629 | up(&dev->fileop_lock); |
| 1630 | return -EIO; |
| 1631 | } |
| 1632 | |
Mauro Carvalho Chehab | 3acf280 | 2005-11-08 21:38:27 -0800 | [diff] [blame] | 1633 | ret = video_usercopy(inode, filp, cmd, arg, em28xx_video_do_ioctl); |
akpm@osdl.org | a6c2ba2 | 2005-11-08 21:37:07 -0800 | [diff] [blame] | 1634 | |
| 1635 | up(&dev->fileop_lock); |
| 1636 | |
| 1637 | return ret; |
| 1638 | } |
| 1639 | |
Mauro Carvalho Chehab | 3acf280 | 2005-11-08 21:38:27 -0800 | [diff] [blame] | 1640 | static struct file_operations em28xx_v4l_fops = { |
akpm@osdl.org | a6c2ba2 | 2005-11-08 21:37:07 -0800 | [diff] [blame] | 1641 | .owner = THIS_MODULE, |
Mauro Carvalho Chehab | 3acf280 | 2005-11-08 21:38:27 -0800 | [diff] [blame] | 1642 | .open = em28xx_v4l2_open, |
| 1643 | .release = em28xx_v4l2_close, |
| 1644 | .ioctl = em28xx_v4l2_ioctl, |
| 1645 | .read = em28xx_v4l2_read, |
| 1646 | .poll = em28xx_v4l2_poll, |
| 1647 | .mmap = em28xx_v4l2_mmap, |
akpm@osdl.org | a6c2ba2 | 2005-11-08 21:37:07 -0800 | [diff] [blame] | 1648 | .llseek = no_llseek, |
Mauro Carvalho Chehab | 17cbe2e | 2006-01-09 15:24:58 -0200 | [diff] [blame] | 1649 | .compat_ioctl = v4l_compat_ioctl32, |
| 1650 | |
akpm@osdl.org | a6c2ba2 | 2005-11-08 21:37:07 -0800 | [diff] [blame] | 1651 | }; |
| 1652 | |
| 1653 | /******************************** usb interface *****************************************/ |
| 1654 | |
| 1655 | /* |
Mauro Carvalho Chehab | 3acf280 | 2005-11-08 21:38:27 -0800 | [diff] [blame] | 1656 | * em28xx_init_dev() |
akpm@osdl.org | a6c2ba2 | 2005-11-08 21:37:07 -0800 | [diff] [blame] | 1657 | * allocates and inits the device structs, registers i2c bus and v4l device |
| 1658 | */ |
Mauro Carvalho Chehab | 3acf280 | 2005-11-08 21:38:27 -0800 | [diff] [blame] | 1659 | static int em28xx_init_dev(struct em28xx **devhandle, struct usb_device *udev, |
akpm@osdl.org | a6c2ba2 | 2005-11-08 21:37:07 -0800 | [diff] [blame] | 1660 | int minor, int model) |
| 1661 | { |
Mauro Carvalho Chehab | 3acf280 | 2005-11-08 21:38:27 -0800 | [diff] [blame] | 1662 | struct em28xx *dev = *devhandle; |
akpm@osdl.org | a6c2ba2 | 2005-11-08 21:37:07 -0800 | [diff] [blame] | 1663 | int retval = -ENOMEM; |
| 1664 | int errCode, i; |
| 1665 | unsigned int maxh, maxw; |
akpm@osdl.org | a6c2ba2 | 2005-11-08 21:37:07 -0800 | [diff] [blame] | 1666 | |
akpm@osdl.org | a6c2ba2 | 2005-11-08 21:37:07 -0800 | [diff] [blame] | 1667 | dev->udev = udev; |
| 1668 | dev->model = model; |
| 1669 | init_MUTEX(&dev->lock); |
| 1670 | init_waitqueue_head(&dev->open); |
| 1671 | |
Mauro Carvalho Chehab | 3acf280 | 2005-11-08 21:38:27 -0800 | [diff] [blame] | 1672 | dev->em28xx_write_regs = em28xx_write_regs; |
| 1673 | dev->em28xx_read_reg = em28xx_read_reg; |
| 1674 | dev->em28xx_read_reg_req_len = em28xx_read_reg_req_len; |
| 1675 | dev->em28xx_write_regs_req = em28xx_write_regs_req; |
| 1676 | dev->em28xx_read_reg_req = em28xx_read_reg_req; |
| 1677 | dev->is_em2800 = em28xx_boards[model].is_em2800; |
| 1678 | dev->has_tuner = em28xx_boards[model].has_tuner; |
| 1679 | dev->has_msp34xx = em28xx_boards[model].has_msp34xx; |
| 1680 | dev->tda9887_conf = em28xx_boards[model].tda9887_conf; |
| 1681 | dev->decoder = em28xx_boards[model].decoder; |
akpm@osdl.org | a6c2ba2 | 2005-11-08 21:37:07 -0800 | [diff] [blame] | 1682 | |
| 1683 | if (tuner >= 0) |
| 1684 | dev->tuner_type = tuner; |
| 1685 | else |
Mauro Carvalho Chehab | 3acf280 | 2005-11-08 21:38:27 -0800 | [diff] [blame] | 1686 | dev->tuner_type = em28xx_boards[model].tuner_type; |
akpm@osdl.org | a6c2ba2 | 2005-11-08 21:37:07 -0800 | [diff] [blame] | 1687 | |
Mauro Carvalho Chehab | 3acf280 | 2005-11-08 21:38:27 -0800 | [diff] [blame] | 1688 | dev->video_inputs = em28xx_boards[model].vchannels; |
akpm@osdl.org | a6c2ba2 | 2005-11-08 21:37:07 -0800 | [diff] [blame] | 1689 | |
| 1690 | for (i = 0; i < TVNORMS; i++) |
Mauro Carvalho Chehab | 3acf280 | 2005-11-08 21:38:27 -0800 | [diff] [blame] | 1691 | if (em28xx_boards[model].norm == tvnorms[i].mode) |
akpm@osdl.org | a6c2ba2 | 2005-11-08 21:37:07 -0800 | [diff] [blame] | 1692 | break; |
| 1693 | if (i == TVNORMS) |
| 1694 | i = 0; |
| 1695 | |
| 1696 | dev->tvnorm = &tvnorms[i]; /* set default norm */ |
| 1697 | |
Mauro Carvalho Chehab | 3acf280 | 2005-11-08 21:38:27 -0800 | [diff] [blame] | 1698 | em28xx_videodbg("tvnorm=%s\n", dev->tvnorm->name); |
akpm@osdl.org | a6c2ba2 | 2005-11-08 21:37:07 -0800 | [diff] [blame] | 1699 | |
| 1700 | maxw = norm_maxw(dev); |
| 1701 | maxh = norm_maxh(dev); |
| 1702 | |
| 1703 | /* set default image size */ |
| 1704 | dev->width = maxw; |
| 1705 | dev->height = maxh; |
Mauro Carvalho Chehab | 3acf280 | 2005-11-08 21:38:27 -0800 | [diff] [blame] | 1706 | dev->interlaced = EM28XX_INTERLACED_DEFAULT; |
akpm@osdl.org | a6c2ba2 | 2005-11-08 21:37:07 -0800 | [diff] [blame] | 1707 | dev->field_size = dev->width * dev->height; |
| 1708 | dev->frame_size = |
| 1709 | dev->interlaced ? dev->field_size << 1 : dev->field_size; |
| 1710 | dev->bytesperline = dev->width * 2; |
| 1711 | dev->hscale = 0; |
| 1712 | dev->vscale = 0; |
| 1713 | dev->ctl_input = 2; |
| 1714 | |
| 1715 | /* setup video picture settings for saa7113h */ |
| 1716 | memset(&dev->vpic, 0, sizeof(dev->vpic)); |
| 1717 | dev->vpic.colour = 128 << 8; |
| 1718 | dev->vpic.hue = 128 << 8; |
| 1719 | dev->vpic.brightness = 128 << 8; |
| 1720 | dev->vpic.contrast = 192 << 8; |
| 1721 | dev->vpic.whiteness = 128 << 8; /* This one isn't used */ |
| 1722 | dev->vpic.depth = 16; |
| 1723 | dev->vpic.palette = VIDEO_PALETTE_YUV422; |
| 1724 | |
akpm@osdl.org | a6c2ba2 | 2005-11-08 21:37:07 -0800 | [diff] [blame] | 1725 | #ifdef CONFIG_MODULES |
| 1726 | /* request some modules */ |
Mauro Carvalho Chehab | 3acf280 | 2005-11-08 21:38:27 -0800 | [diff] [blame] | 1727 | if (dev->decoder == EM28XX_SAA7113 || dev->decoder == EM28XX_SAA7114) |
Mauro Carvalho Chehab | 91cad0f | 2005-11-08 21:38:13 -0800 | [diff] [blame] | 1728 | request_module("saa711x"); |
Mauro Carvalho Chehab | 3acf280 | 2005-11-08 21:38:27 -0800 | [diff] [blame] | 1729 | if (dev->decoder == EM28XX_TVP5150) |
akpm@osdl.org | a6c2ba2 | 2005-11-08 21:37:07 -0800 | [diff] [blame] | 1730 | request_module("tvp5150"); |
| 1731 | if (dev->has_tuner) |
| 1732 | request_module("tuner"); |
| 1733 | if (dev->tda9887_conf) |
| 1734 | request_module("tda9887"); |
| 1735 | #endif |
Mauro Carvalho Chehab | 3acf280 | 2005-11-08 21:38:27 -0800 | [diff] [blame] | 1736 | errCode = em28xx_config(dev); |
akpm@osdl.org | a6c2ba2 | 2005-11-08 21:37:07 -0800 | [diff] [blame] | 1737 | if (errCode) { |
Mauro Carvalho Chehab | 3acf280 | 2005-11-08 21:38:27 -0800 | [diff] [blame] | 1738 | em28xx_errdev("error configuring device\n"); |
akpm@osdl.org | a6c2ba2 | 2005-11-08 21:37:07 -0800 | [diff] [blame] | 1739 | kfree(dev); |
| 1740 | return -ENOMEM; |
| 1741 | } |
| 1742 | |
| 1743 | down(&dev->lock); |
| 1744 | /* register i2c bus */ |
Mauro Carvalho Chehab | 3acf280 | 2005-11-08 21:38:27 -0800 | [diff] [blame] | 1745 | em28xx_i2c_register(dev); |
akpm@osdl.org | a6c2ba2 | 2005-11-08 21:37:07 -0800 | [diff] [blame] | 1746 | |
| 1747 | /* Do board specific init and eeprom reading */ |
Mauro Carvalho Chehab | 3acf280 | 2005-11-08 21:38:27 -0800 | [diff] [blame] | 1748 | em28xx_card_setup(dev); |
akpm@osdl.org | a6c2ba2 | 2005-11-08 21:37:07 -0800 | [diff] [blame] | 1749 | |
| 1750 | /* configure the device */ |
Mauro Carvalho Chehab | 3acf280 | 2005-11-08 21:38:27 -0800 | [diff] [blame] | 1751 | em28xx_config_i2c(dev); |
akpm@osdl.org | a6c2ba2 | 2005-11-08 21:37:07 -0800 | [diff] [blame] | 1752 | |
| 1753 | up(&dev->lock); |
| 1754 | |
Mauro Carvalho Chehab | 3acf280 | 2005-11-08 21:38:27 -0800 | [diff] [blame] | 1755 | errCode = em28xx_config(dev); |
akpm@osdl.org | a6c2ba2 | 2005-11-08 21:37:07 -0800 | [diff] [blame] | 1756 | |
| 1757 | #ifdef CONFIG_MODULES |
| 1758 | if (dev->has_msp34xx) |
| 1759 | request_module("msp3400"); |
| 1760 | #endif |
| 1761 | /* allocate and fill v4l2 device struct */ |
| 1762 | dev->vdev = video_device_alloc(); |
| 1763 | if (NULL == dev->vdev) { |
Mauro Carvalho Chehab | 3acf280 | 2005-11-08 21:38:27 -0800 | [diff] [blame] | 1764 | em28xx_errdev("cannot allocate video_device.\n"); |
akpm@osdl.org | a6c2ba2 | 2005-11-08 21:37:07 -0800 | [diff] [blame] | 1765 | kfree(dev); |
| 1766 | return -ENOMEM; |
| 1767 | } |
| 1768 | |
akpm@osdl.org | a6c2ba2 | 2005-11-08 21:37:07 -0800 | [diff] [blame] | 1769 | dev->vdev->type = VID_TYPE_CAPTURE; |
| 1770 | if (dev->has_tuner) |
| 1771 | dev->vdev->type |= VID_TYPE_TUNER; |
| 1772 | dev->vdev->hardware = 0; |
Mauro Carvalho Chehab | 3acf280 | 2005-11-08 21:38:27 -0800 | [diff] [blame] | 1773 | dev->vdev->fops = &em28xx_v4l_fops; |
akpm@osdl.org | a6c2ba2 | 2005-11-08 21:37:07 -0800 | [diff] [blame] | 1774 | dev->vdev->minor = -1; |
| 1775 | dev->vdev->dev = &dev->udev->dev; |
| 1776 | dev->vdev->release = video_device_release; |
| 1777 | snprintf(dev->vdev->name, sizeof(dev->vdev->name), "%s", |
Mauro Carvalho Chehab | 3acf280 | 2005-11-08 21:38:27 -0800 | [diff] [blame] | 1778 | "em28xx video"); |
| 1779 | list_add_tail(&dev->devlist,&em28xx_devlist); |
akpm@osdl.org | a6c2ba2 | 2005-11-08 21:37:07 -0800 | [diff] [blame] | 1780 | |
| 1781 | /* register v4l2 device */ |
| 1782 | down(&dev->lock); |
| 1783 | if ((retval = video_register_device(dev->vdev, VFL_TYPE_GRABBER, -1))) { |
Mauro Carvalho Chehab | 3acf280 | 2005-11-08 21:38:27 -0800 | [diff] [blame] | 1784 | em28xx_errdev("unable to register video device (error=%i).\n", |
akpm@osdl.org | a6c2ba2 | 2005-11-08 21:37:07 -0800 | [diff] [blame] | 1785 | retval); |
| 1786 | up(&dev->lock); |
Markus Rechberger | 9c75541 | 2005-11-08 21:37:52 -0800 | [diff] [blame] | 1787 | list_del(&dev->devlist); |
akpm@osdl.org | a6c2ba2 | 2005-11-08 21:37:07 -0800 | [diff] [blame] | 1788 | video_device_release(dev->vdev); |
| 1789 | kfree(dev); |
| 1790 | return -ENODEV; |
| 1791 | } |
| 1792 | if (dev->has_msp34xx) { |
| 1793 | /* Send a reset to other chips via gpio */ |
Mauro Carvalho Chehab | 3acf280 | 2005-11-08 21:38:27 -0800 | [diff] [blame] | 1794 | em28xx_write_regs_req(dev, 0x00, 0x08, "\xf7", 1); |
akpm@osdl.org | a6c2ba2 | 2005-11-08 21:37:07 -0800 | [diff] [blame] | 1795 | udelay(2500); |
Mauro Carvalho Chehab | 3acf280 | 2005-11-08 21:38:27 -0800 | [diff] [blame] | 1796 | em28xx_write_regs_req(dev, 0x00, 0x08, "\xff", 1); |
akpm@osdl.org | a6c2ba2 | 2005-11-08 21:37:07 -0800 | [diff] [blame] | 1797 | udelay(2500); |
| 1798 | |
| 1799 | } |
| 1800 | video_mux(dev, 0); |
| 1801 | |
| 1802 | up(&dev->lock); |
| 1803 | |
Mauro Carvalho Chehab | 3acf280 | 2005-11-08 21:38:27 -0800 | [diff] [blame] | 1804 | em28xx_info("V4L2 device registered as /dev/video%d\n", |
akpm@osdl.org | a6c2ba2 | 2005-11-08 21:37:07 -0800 | [diff] [blame] | 1805 | dev->vdev->minor); |
| 1806 | |
akpm@osdl.org | a6c2ba2 | 2005-11-08 21:37:07 -0800 | [diff] [blame] | 1807 | return 0; |
| 1808 | } |
| 1809 | |
| 1810 | /* |
Mauro Carvalho Chehab | 3acf280 | 2005-11-08 21:38:27 -0800 | [diff] [blame] | 1811 | * em28xx_usb_probe() |
akpm@osdl.org | a6c2ba2 | 2005-11-08 21:37:07 -0800 | [diff] [blame] | 1812 | * checks for supported devices |
| 1813 | */ |
Mauro Carvalho Chehab | 3acf280 | 2005-11-08 21:38:27 -0800 | [diff] [blame] | 1814 | static int em28xx_usb_probe(struct usb_interface *interface, |
akpm@osdl.org | a6c2ba2 | 2005-11-08 21:37:07 -0800 | [diff] [blame] | 1815 | const struct usb_device_id *id) |
| 1816 | { |
| 1817 | const struct usb_endpoint_descriptor *endpoint; |
| 1818 | struct usb_device *udev; |
Mauro Carvalho Chehab | 9d4d9c0 | 2005-11-08 21:38:52 -0800 | [diff] [blame] | 1819 | struct usb_interface *uif; |
Mauro Carvalho Chehab | 3acf280 | 2005-11-08 21:38:27 -0800 | [diff] [blame] | 1820 | struct em28xx *dev = NULL; |
akpm@osdl.org | a6c2ba2 | 2005-11-08 21:37:07 -0800 | [diff] [blame] | 1821 | int retval = -ENODEV; |
Mauro Carvalho Chehab | d5e5265 | 2005-11-08 21:37:32 -0800 | [diff] [blame] | 1822 | int model,i,nr,ifnum; |
akpm@osdl.org | a6c2ba2 | 2005-11-08 21:37:07 -0800 | [diff] [blame] | 1823 | |
| 1824 | udev = usb_get_dev(interface_to_usbdev(interface)); |
Mauro Carvalho Chehab | d5e5265 | 2005-11-08 21:37:32 -0800 | [diff] [blame] | 1825 | ifnum = interface->altsetting[0].desc.bInterfaceNumber; |
| 1826 | |
Mauro Carvalho Chehab | 91cad0f | 2005-11-08 21:38:13 -0800 | [diff] [blame] | 1827 | |
| 1828 | /* Don't register audio interfaces */ |
| 1829 | if (interface->altsetting[0].desc.bInterfaceClass == USB_CLASS_AUDIO) { |
Mauro Carvalho Chehab | 3acf280 | 2005-11-08 21:38:27 -0800 | [diff] [blame] | 1830 | em28xx_err(DRIVER_NAME " audio device (%04x:%04x): interface %i, class %i\n", |
Mauro Carvalho Chehab | 91cad0f | 2005-11-08 21:38:13 -0800 | [diff] [blame] | 1831 | udev->descriptor.idVendor,udev->descriptor.idProduct, |
| 1832 | ifnum, |
| 1833 | interface->altsetting[0].desc.bInterfaceClass); |
| 1834 | return -ENODEV; |
| 1835 | } |
| 1836 | |
Mauro Carvalho Chehab | 3acf280 | 2005-11-08 21:38:27 -0800 | [diff] [blame] | 1837 | em28xx_err(DRIVER_NAME " new video device (%04x:%04x): interface %i, class %i\n", |
Mauro Carvalho Chehab | d5e5265 | 2005-11-08 21:37:32 -0800 | [diff] [blame] | 1838 | udev->descriptor.idVendor,udev->descriptor.idProduct, |
| 1839 | ifnum, |
| 1840 | interface->altsetting[0].desc.bInterfaceClass); |
akpm@osdl.org | a6c2ba2 | 2005-11-08 21:37:07 -0800 | [diff] [blame] | 1841 | |
Mauro Carvalho Chehab | d5e5265 | 2005-11-08 21:37:32 -0800 | [diff] [blame] | 1842 | endpoint = &interface->cur_altsetting->endpoint[1].desc; |
| 1843 | |
akpm@osdl.org | a6c2ba2 | 2005-11-08 21:37:07 -0800 | [diff] [blame] | 1844 | /* check if the the device has the iso in endpoint at the correct place */ |
| 1845 | if ((endpoint->bmAttributes & USB_ENDPOINT_XFERTYPE_MASK) != |
| 1846 | USB_ENDPOINT_XFER_ISOC) { |
Mauro Carvalho Chehab | 3acf280 | 2005-11-08 21:38:27 -0800 | [diff] [blame] | 1847 | em28xx_err(DRIVER_NAME " probing error: endpoint is non-ISO endpoint!\n"); |
akpm@osdl.org | a6c2ba2 | 2005-11-08 21:37:07 -0800 | [diff] [blame] | 1848 | return -ENODEV; |
| 1849 | } |
| 1850 | if ((endpoint->bEndpointAddress & USB_ENDPOINT_DIR_MASK) == USB_DIR_OUT) { |
Mauro Carvalho Chehab | 3acf280 | 2005-11-08 21:38:27 -0800 | [diff] [blame] | 1851 | em28xx_err(DRIVER_NAME " probing error: endpoint is ISO OUT endpoint!\n"); |
akpm@osdl.org | a6c2ba2 | 2005-11-08 21:37:07 -0800 | [diff] [blame] | 1852 | return -ENODEV; |
| 1853 | } |
| 1854 | |
Mauro Carvalho Chehab | 596d92d | 2005-11-08 21:37:24 -0800 | [diff] [blame] | 1855 | model=id->driver_info; |
| 1856 | nr=interface->minor; |
| 1857 | |
Mauro Carvalho Chehab | 3acf280 | 2005-11-08 21:38:27 -0800 | [diff] [blame] | 1858 | if (nr>EM28XX_MAXBOARDS) { |
Mauro Carvalho Chehab | 9d4d9c0 | 2005-11-08 21:38:52 -0800 | [diff] [blame] | 1859 | printk (DRIVER_NAME ": Supports only %i em28xx boards.\n",EM28XX_MAXBOARDS); |
Mauro Carvalho Chehab | 596d92d | 2005-11-08 21:37:24 -0800 | [diff] [blame] | 1860 | return -ENOMEM; |
| 1861 | } |
| 1862 | |
| 1863 | /* allocate memory for our device state and initialize it */ |
| 1864 | dev = kmalloc(sizeof(*dev), GFP_KERNEL); |
| 1865 | if (dev == NULL) { |
Mauro Carvalho Chehab | 3acf280 | 2005-11-08 21:38:27 -0800 | [diff] [blame] | 1866 | em28xx_err(DRIVER_NAME ": out of memory!\n"); |
Mauro Carvalho Chehab | 596d92d | 2005-11-08 21:37:24 -0800 | [diff] [blame] | 1867 | return -ENOMEM; |
| 1868 | } |
| 1869 | memset(dev, 0, sizeof(*dev)); |
| 1870 | |
Mauro Carvalho Chehab | 9d4d9c0 | 2005-11-08 21:38:52 -0800 | [diff] [blame] | 1871 | /* compute alternate max packet sizes */ |
| 1872 | uif = udev->actconfig->interface[0]; |
| 1873 | |
| 1874 | dev->num_alt=uif->num_altsetting; |
| 1875 | printk(DRIVER_NAME ": Alternate settings: %i\n",dev->num_alt); |
| 1876 | // dev->alt_max_pkt_size = kmalloc(sizeof(*dev->alt_max_pkt_size)* |
| 1877 | dev->alt_max_pkt_size = kmalloc(32* |
| 1878 | dev->num_alt,GFP_KERNEL); |
| 1879 | if (dev->alt_max_pkt_size == NULL) { |
| 1880 | em28xx_err(DRIVER_NAME ": out of memory!\n"); |
| 1881 | return -ENOMEM; |
| 1882 | } |
| 1883 | |
| 1884 | for (i = 0; i < dev->num_alt ; i++) { |
| 1885 | u16 tmp = le16_to_cpu(uif->altsetting[i].endpoint[1].desc. |
| 1886 | wMaxPacketSize); |
| 1887 | dev->alt_max_pkt_size[i] = |
| 1888 | (tmp & 0x07ff) * (((tmp & 0x1800) >> 11) + 1); |
| 1889 | printk(DRIVER_NAME ": Alternate setting %i, max size= %i\n",i, |
| 1890 | dev->alt_max_pkt_size[i]); |
| 1891 | } |
| 1892 | |
Mauro Carvalho Chehab | 3acf280 | 2005-11-08 21:38:27 -0800 | [diff] [blame] | 1893 | snprintf(dev->name, 29, "em28xx #%d", nr); |
Mauro Carvalho Chehab | 596d92d | 2005-11-08 21:37:24 -0800 | [diff] [blame] | 1894 | |
Mauro Carvalho Chehab | 3acf280 | 2005-11-08 21:38:27 -0800 | [diff] [blame] | 1895 | if ((card[nr]>=0)&&(card[nr]<em28xx_bcount)) |
Mauro Carvalho Chehab | 596d92d | 2005-11-08 21:37:24 -0800 | [diff] [blame] | 1896 | model=card[nr]; |
| 1897 | |
| 1898 | if ((model==EM2800_BOARD_UNKNOWN)||(model==EM2820_BOARD_UNKNOWN)) { |
| 1899 | printk( "%s: Your board has no eeprom inside it and thus can't\n" |
| 1900 | "%s: be autodetected. Please pass card=<n> insmod option to\n" |
| 1901 | "%s: workaround that. Redirect complaints to the vendor of\n" |
| 1902 | "%s: the TV card. Best regards,\n" |
| 1903 | "%s: -- tux\n", |
| 1904 | dev->name,dev->name,dev->name,dev->name,dev->name); |
| 1905 | printk("%s: Here is a list of valid choices for the card=<n> insmod option:\n", |
| 1906 | dev->name); |
Mauro Carvalho Chehab | 3acf280 | 2005-11-08 21:38:27 -0800 | [diff] [blame] | 1907 | for (i = 0; i < em28xx_bcount; i++) { |
Mauro Carvalho Chehab | 596d92d | 2005-11-08 21:37:24 -0800 | [diff] [blame] | 1908 | printk("%s: card=%d -> %s\n", |
Mauro Carvalho Chehab | 3acf280 | 2005-11-08 21:38:27 -0800 | [diff] [blame] | 1909 | dev->name, i, em28xx_boards[i].name); |
Mauro Carvalho Chehab | 596d92d | 2005-11-08 21:37:24 -0800 | [diff] [blame] | 1910 | } |
| 1911 | } |
| 1912 | |
akpm@osdl.org | a6c2ba2 | 2005-11-08 21:37:07 -0800 | [diff] [blame] | 1913 | /* allocate device struct */ |
Mauro Carvalho Chehab | 3acf280 | 2005-11-08 21:38:27 -0800 | [diff] [blame] | 1914 | retval = em28xx_init_dev(&dev, udev, nr, model); |
akpm@osdl.org | a6c2ba2 | 2005-11-08 21:37:07 -0800 | [diff] [blame] | 1915 | if (retval) |
| 1916 | return retval; |
| 1917 | |
Mauro Carvalho Chehab | 3acf280 | 2005-11-08 21:38:27 -0800 | [diff] [blame] | 1918 | em28xx_info("Found %s\n", em28xx_boards[model].name); |
akpm@osdl.org | a6c2ba2 | 2005-11-08 21:37:07 -0800 | [diff] [blame] | 1919 | |
| 1920 | /* save our data pointer in this interface device */ |
| 1921 | usb_set_intfdata(interface, dev); |
| 1922 | return 0; |
| 1923 | } |
| 1924 | |
| 1925 | /* |
Mauro Carvalho Chehab | 3acf280 | 2005-11-08 21:38:27 -0800 | [diff] [blame] | 1926 | * em28xx_usb_disconnect() |
akpm@osdl.org | a6c2ba2 | 2005-11-08 21:37:07 -0800 | [diff] [blame] | 1927 | * called when the device gets diconencted |
| 1928 | * video device will be unregistered on v4l2_close in case it is still open |
| 1929 | */ |
Mauro Carvalho Chehab | 3acf280 | 2005-11-08 21:38:27 -0800 | [diff] [blame] | 1930 | static void em28xx_usb_disconnect(struct usb_interface *interface) |
akpm@osdl.org | a6c2ba2 | 2005-11-08 21:37:07 -0800 | [diff] [blame] | 1931 | { |
Mauro Carvalho Chehab | 3acf280 | 2005-11-08 21:38:27 -0800 | [diff] [blame] | 1932 | struct em28xx *dev = usb_get_intfdata(interface); |
akpm@osdl.org | a6c2ba2 | 2005-11-08 21:37:07 -0800 | [diff] [blame] | 1933 | usb_set_intfdata(interface, NULL); |
| 1934 | |
Mauro Carvalho Chehab | c0477ad | 2006-01-09 15:25:14 -0200 | [diff] [blame] | 1935 | /*FIXME: IR should be disconnected */ |
| 1936 | |
akpm@osdl.org | a6c2ba2 | 2005-11-08 21:37:07 -0800 | [diff] [blame] | 1937 | if (!dev) |
| 1938 | return; |
| 1939 | |
Mauro Carvalho Chehab | c0477ad | 2006-01-09 15:25:14 -0200 | [diff] [blame] | 1940 | |
Mauro Carvalho Chehab | 3acf280 | 2005-11-08 21:38:27 -0800 | [diff] [blame] | 1941 | down_write(&em28xx_disconnect); |
akpm@osdl.org | a6c2ba2 | 2005-11-08 21:37:07 -0800 | [diff] [blame] | 1942 | |
| 1943 | down(&dev->lock); |
| 1944 | |
Mauro Carvalho Chehab | 3acf280 | 2005-11-08 21:38:27 -0800 | [diff] [blame] | 1945 | em28xx_info("disconnecting %s\n", dev->vdev->name); |
akpm@osdl.org | a6c2ba2 | 2005-11-08 21:37:07 -0800 | [diff] [blame] | 1946 | |
| 1947 | wake_up_interruptible_all(&dev->open); |
| 1948 | |
| 1949 | if (dev->users) { |
Mauro Carvalho Chehab | 3acf280 | 2005-11-08 21:38:27 -0800 | [diff] [blame] | 1950 | em28xx_warn |
akpm@osdl.org | a6c2ba2 | 2005-11-08 21:37:07 -0800 | [diff] [blame] | 1951 | ("device /dev/video%d is open! Deregistration and memory " |
| 1952 | "deallocation are deferred on close.\n", dev->vdev->minor); |
| 1953 | dev->state |= DEV_MISCONFIGURED; |
Mauro Carvalho Chehab | 3acf280 | 2005-11-08 21:38:27 -0800 | [diff] [blame] | 1954 | em28xx_uninit_isoc(dev); |
akpm@osdl.org | a6c2ba2 | 2005-11-08 21:37:07 -0800 | [diff] [blame] | 1955 | dev->state |= DEV_DISCONNECTED; |
| 1956 | wake_up_interruptible(&dev->wait_frame); |
| 1957 | wake_up_interruptible(&dev->wait_stream); |
| 1958 | } else { |
| 1959 | dev->state |= DEV_DISCONNECTED; |
Mauro Carvalho Chehab | 3acf280 | 2005-11-08 21:38:27 -0800 | [diff] [blame] | 1960 | em28xx_release_resources(dev); |
akpm@osdl.org | a6c2ba2 | 2005-11-08 21:37:07 -0800 | [diff] [blame] | 1961 | } |
| 1962 | |
| 1963 | up(&dev->lock); |
| 1964 | |
Mauro Carvalho Chehab | 9d4d9c0 | 2005-11-08 21:38:52 -0800 | [diff] [blame] | 1965 | if (!dev->users) { |
| 1966 | kfree(dev->alt_max_pkt_size); |
akpm@osdl.org | a6c2ba2 | 2005-11-08 21:37:07 -0800 | [diff] [blame] | 1967 | kfree(dev); |
Mauro Carvalho Chehab | 9d4d9c0 | 2005-11-08 21:38:52 -0800 | [diff] [blame] | 1968 | } |
akpm@osdl.org | a6c2ba2 | 2005-11-08 21:37:07 -0800 | [diff] [blame] | 1969 | |
Mauro Carvalho Chehab | 3acf280 | 2005-11-08 21:38:27 -0800 | [diff] [blame] | 1970 | up_write(&em28xx_disconnect); |
akpm@osdl.org | a6c2ba2 | 2005-11-08 21:37:07 -0800 | [diff] [blame] | 1971 | } |
| 1972 | |
Mauro Carvalho Chehab | 3acf280 | 2005-11-08 21:38:27 -0800 | [diff] [blame] | 1973 | static struct usb_driver em28xx_usb_driver = { |
Mauro Carvalho Chehab | 3acf280 | 2005-11-08 21:38:27 -0800 | [diff] [blame] | 1974 | .name = "em28xx", |
| 1975 | .probe = em28xx_usb_probe, |
| 1976 | .disconnect = em28xx_usb_disconnect, |
| 1977 | .id_table = em28xx_id_table, |
akpm@osdl.org | a6c2ba2 | 2005-11-08 21:37:07 -0800 | [diff] [blame] | 1978 | }; |
| 1979 | |
Mauro Carvalho Chehab | 3acf280 | 2005-11-08 21:38:27 -0800 | [diff] [blame] | 1980 | static int __init em28xx_module_init(void) |
akpm@osdl.org | a6c2ba2 | 2005-11-08 21:37:07 -0800 | [diff] [blame] | 1981 | { |
| 1982 | int result; |
| 1983 | |
| 1984 | 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] | 1985 | (EM28XX_VERSION_CODE >> 16) & 0xff, |
| 1986 | (EM28XX_VERSION_CODE >> 8) & 0xff, EM28XX_VERSION_CODE & 0xff); |
akpm@osdl.org | a6c2ba2 | 2005-11-08 21:37:07 -0800 | [diff] [blame] | 1987 | #ifdef SNAPSHOT |
| 1988 | printk(KERN_INFO DRIVER_NAME " snapshot date %04d-%02d-%02d\n", |
| 1989 | SNAPSHOT / 10000, (SNAPSHOT / 100) % 100, SNAPSHOT % 100); |
| 1990 | #endif |
| 1991 | |
| 1992 | /* register this driver with the USB subsystem */ |
Mauro Carvalho Chehab | 3acf280 | 2005-11-08 21:38:27 -0800 | [diff] [blame] | 1993 | result = usb_register(&em28xx_usb_driver); |
akpm@osdl.org | a6c2ba2 | 2005-11-08 21:37:07 -0800 | [diff] [blame] | 1994 | if (result) |
Mauro Carvalho Chehab | 3acf280 | 2005-11-08 21:38:27 -0800 | [diff] [blame] | 1995 | em28xx_err(DRIVER_NAME |
akpm@osdl.org | a6c2ba2 | 2005-11-08 21:37:07 -0800 | [diff] [blame] | 1996 | " usb_register failed. Error number %d.\n", result); |
| 1997 | |
| 1998 | return result; |
| 1999 | } |
| 2000 | |
Mauro Carvalho Chehab | 3acf280 | 2005-11-08 21:38:27 -0800 | [diff] [blame] | 2001 | static void __exit em28xx_module_exit(void) |
akpm@osdl.org | a6c2ba2 | 2005-11-08 21:37:07 -0800 | [diff] [blame] | 2002 | { |
| 2003 | /* deregister this driver with the USB subsystem */ |
Mauro Carvalho Chehab | 3acf280 | 2005-11-08 21:38:27 -0800 | [diff] [blame] | 2004 | usb_deregister(&em28xx_usb_driver); |
akpm@osdl.org | a6c2ba2 | 2005-11-08 21:37:07 -0800 | [diff] [blame] | 2005 | } |
| 2006 | |
Mauro Carvalho Chehab | 3acf280 | 2005-11-08 21:38:27 -0800 | [diff] [blame] | 2007 | module_init(em28xx_module_init); |
| 2008 | module_exit(em28xx_module_exit); |