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