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