aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/media/video/gspca/gspca.c
diff options
context:
space:
mode:
authorHans Verkuil <hans.verkuil@cisco.com>2012-05-06 08:28:17 -0400
committerMauro Carvalho Chehab <mchehab@redhat.com>2012-05-14 08:22:50 -0400
commit62bba5dd8181bed282967f1054ed5749b2c499f9 (patch)
treeba82dfdf5fb88e257a80b3392ddc0652f577f557 /drivers/media/video/gspca/gspca.c
parentceede9fa8939e40ad0ddb4ad1355f45c6f1d3478 (diff)
[media] gspca: Allow subdrivers to use the control framework
Make the necessary changes to allow subdrivers to use the control framework. This does not add control event support, that comes later. It add a init_control cam_op that is called after init in probe that allows the subdriver to set up the controls. HdG: Call v4l2_ctrl_handler_setup from resume instead of gspca_set_default_mode, as we just want to resend the current ctrl values to the device. Signed-off-by: Hans Verkuil <hans.verkuil@cisco.com> Signed-off-by: Hans de Goede <hdegoede@redhat.com> Signed-off-by: Mauro Carvalho Chehab <mchehab@redhat.com>
Diffstat (limited to 'drivers/media/video/gspca/gspca.c')
-rw-r--r--drivers/media/video/gspca/gspca.c36
1 files changed, 27 insertions, 9 deletions
diff --git a/drivers/media/video/gspca/gspca.c b/drivers/media/video/gspca/gspca.c
index ca5a2b139d0b..d85c30dd37ad 100644
--- a/drivers/media/video/gspca/gspca.c
+++ b/drivers/media/video/gspca/gspca.c
@@ -38,6 +38,7 @@
38#include <linux/uaccess.h> 38#include <linux/uaccess.h>
39#include <linux/ktime.h> 39#include <linux/ktime.h>
40#include <media/v4l2-ioctl.h> 40#include <media/v4l2-ioctl.h>
41#include <media/v4l2-ctrls.h>
41 42
42#include "gspca.h" 43#include "gspca.h"
43 44
@@ -1006,6 +1007,8 @@ static void gspca_set_default_mode(struct gspca_dev *gspca_dev)
1006 1007
1007 /* set the current control values to their default values 1008 /* set the current control values to their default values
1008 * which may have changed in sd_init() */ 1009 * which may have changed in sd_init() */
1010 /* does nothing if ctrl_handler == NULL */
1011 v4l2_ctrl_handler_setup(gspca_dev->vdev.ctrl_handler);
1009 ctrl = gspca_dev->cam.ctrls; 1012 ctrl = gspca_dev->cam.ctrls;
1010 if (ctrl != NULL) { 1013 if (ctrl != NULL) {
1011 for (i = 0; 1014 for (i = 0;
@@ -1323,6 +1326,7 @@ static void gspca_release(struct video_device *vfd)
1323 PDEBUG(D_PROBE, "%s released", 1326 PDEBUG(D_PROBE, "%s released",
1324 video_device_node_name(&gspca_dev->vdev)); 1327 video_device_node_name(&gspca_dev->vdev));
1325 1328
1329 v4l2_ctrl_handler_free(gspca_dev->vdev.ctrl_handler);
1326 kfree(gspca_dev->usb_buf); 1330 kfree(gspca_dev->usb_buf);
1327 kfree(gspca_dev); 1331 kfree(gspca_dev);
1328} 1332}
@@ -2347,6 +2351,14 @@ int gspca_dev_probe2(struct usb_interface *intf,
2347 gspca_dev->sd_desc = sd_desc; 2351 gspca_dev->sd_desc = sd_desc;
2348 gspca_dev->nbufread = 2; 2352 gspca_dev->nbufread = 2;
2349 gspca_dev->empty_packet = -1; /* don't check the empty packets */ 2353 gspca_dev->empty_packet = -1; /* don't check the empty packets */
2354 gspca_dev->vdev = gspca_template;
2355 gspca_dev->vdev.parent = &intf->dev;
2356 gspca_dev->module = module;
2357 gspca_dev->present = 1;
2358
2359 mutex_init(&gspca_dev->usb_lock);
2360 mutex_init(&gspca_dev->queue_lock);
2361 init_waitqueue_head(&gspca_dev->wq);
2350 2362
2351 /* configure the subdriver and initialize the USB device */ 2363 /* configure the subdriver and initialize the USB device */
2352 ret = sd_desc->config(gspca_dev, id); 2364 ret = sd_desc->config(gspca_dev, id);
@@ -2357,21 +2369,17 @@ int gspca_dev_probe2(struct usb_interface *intf,
2357 ret = sd_desc->init(gspca_dev); 2369 ret = sd_desc->init(gspca_dev);
2358 if (ret < 0) 2370 if (ret < 0)
2359 goto out; 2371 goto out;
2372 if (sd_desc->init_controls)
2373 ret = sd_desc->init_controls(gspca_dev);
2374 if (ret < 0)
2375 goto out;
2360 gspca_set_default_mode(gspca_dev); 2376 gspca_set_default_mode(gspca_dev);
2361 2377
2362 ret = gspca_input_connect(gspca_dev); 2378 ret = gspca_input_connect(gspca_dev);
2363 if (ret) 2379 if (ret)
2364 goto out; 2380 goto out;
2365 2381
2366 mutex_init(&gspca_dev->usb_lock);
2367 mutex_init(&gspca_dev->queue_lock);
2368 init_waitqueue_head(&gspca_dev->wq);
2369
2370 /* init video stuff */ 2382 /* init video stuff */
2371 memcpy(&gspca_dev->vdev, &gspca_template, sizeof gspca_template);
2372 gspca_dev->vdev.parent = &intf->dev;
2373 gspca_dev->module = module;
2374 gspca_dev->present = 1;
2375 ret = video_register_device(&gspca_dev->vdev, 2383 ret = video_register_device(&gspca_dev->vdev,
2376 VFL_TYPE_GRABBER, 2384 VFL_TYPE_GRABBER,
2377 -1); 2385 -1);
@@ -2391,6 +2399,7 @@ out:
2391 if (gspca_dev->input_dev) 2399 if (gspca_dev->input_dev)
2392 input_unregister_device(gspca_dev->input_dev); 2400 input_unregister_device(gspca_dev->input_dev);
2393#endif 2401#endif
2402 v4l2_ctrl_handler_free(gspca_dev->vdev.ctrl_handler);
2394 kfree(gspca_dev->usb_buf); 2403 kfree(gspca_dev->usb_buf);
2395 kfree(gspca_dev); 2404 kfree(gspca_dev);
2396 return ret; 2405 return ret;
@@ -2489,11 +2498,20 @@ EXPORT_SYMBOL(gspca_suspend);
2489int gspca_resume(struct usb_interface *intf) 2498int gspca_resume(struct usb_interface *intf)
2490{ 2499{
2491 struct gspca_dev *gspca_dev = usb_get_intfdata(intf); 2500 struct gspca_dev *gspca_dev = usb_get_intfdata(intf);
2501 int streaming;
2492 2502
2493 gspca_dev->frozen = 0; 2503 gspca_dev->frozen = 0;
2494 gspca_dev->sd_desc->init(gspca_dev); 2504 gspca_dev->sd_desc->init(gspca_dev);
2495 gspca_input_create_urb(gspca_dev); 2505 gspca_input_create_urb(gspca_dev);
2496 if (gspca_dev->streaming) 2506 /*
2507 * Most subdrivers send all ctrl values on sd_start and thus
2508 * only write to the device registers on s_ctrl when streaming ->
2509 * Clear streaming to avoid setting all ctrls twice.
2510 */
2511 streaming = gspca_dev->streaming;
2512 gspca_dev->streaming = 0;
2513 v4l2_ctrl_handler_setup(gspca_dev->vdev.ctrl_handler);
2514 if (streaming)
2497 return gspca_init_transfer(gspca_dev); 2515 return gspca_init_transfer(gspca_dev);
2498 return 0; 2516 return 0;
2499} 2517}