aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorHans Verkuil <hans.verkuil@cisco.com>2013-02-04 06:53:11 -0500
committerMauro Carvalho Chehab <mchehab@redhat.com>2013-03-05 12:39:40 -0500
commitdc0fb28675e7ef7ac12a5532500b2f89e41f2174 (patch)
treed25b4752c6a5aa6e7f8ac210b4c380f3f577b0eb
parent968c60f60376a573460b6ef4991435d09528d48c (diff)
[media] stk-webcam: convert to the control framework
Signed-off-by: Hans Verkuil <hans.verkuil@cisco.com> Tested-by: Arvydas Sidorenko <asido4@gmail.com> Signed-off-by: Mauro Carvalho Chehab <mchehab@redhat.com>
-rw-r--r--drivers/media/usb/stkwebcam/stk-webcam.c119
-rw-r--r--drivers/media/usb/stkwebcam/stk-webcam.h3
2 files changed, 33 insertions, 89 deletions
diff --git a/drivers/media/usb/stkwebcam/stk-webcam.c b/drivers/media/usb/stkwebcam/stk-webcam.c
index eaf152c51ae2..f1cf9060ce71 100644
--- a/drivers/media/usb/stkwebcam/stk-webcam.c
+++ b/drivers/media/usb/stkwebcam/stk-webcam.c
@@ -806,99 +806,25 @@ static int stk_vidioc_s_input(struct file *filp, void *priv, unsigned int i)
806 return 0; 806 return 0;
807} 807}
808 808
809/* List of all V4Lv2 controls supported by the driver */ 809static int stk_s_ctrl(struct v4l2_ctrl *ctrl)
810static struct v4l2_queryctrl stk_controls[] = {
811 {
812 .id = V4L2_CID_BRIGHTNESS,
813 .type = V4L2_CTRL_TYPE_INTEGER,
814 .name = "Brightness",
815 .minimum = 0,
816 .maximum = 0xffff,
817 .step = 0x0100,
818 .default_value = 0x6000,
819 },
820 {
821 .id = V4L2_CID_HFLIP,
822 .type = V4L2_CTRL_TYPE_BOOLEAN,
823 .name = "Horizontal Flip",
824 .minimum = 0,
825 .maximum = 1,
826 .step = 1,
827 .default_value = 1,
828 },
829 {
830 .id = V4L2_CID_VFLIP,
831 .type = V4L2_CTRL_TYPE_BOOLEAN,
832 .name = "Vertical Flip",
833 .minimum = 0,
834 .maximum = 1,
835 .step = 1,
836 .default_value = 1,
837 },
838};
839
840static int stk_vidioc_queryctrl(struct file *filp,
841 void *priv, struct v4l2_queryctrl *c)
842{ 810{
843 int i; 811 struct stk_camera *dev =
844 int nbr; 812 container_of(ctrl->handler, struct stk_camera, hdl);
845 nbr = ARRAY_SIZE(stk_controls);
846
847 for (i = 0; i < nbr; i++) {
848 if (stk_controls[i].id == c->id) {
849 memcpy(c, &stk_controls[i],
850 sizeof(struct v4l2_queryctrl));
851 return 0;
852 }
853 }
854 return -EINVAL;
855}
856
857static int stk_vidioc_g_ctrl(struct file *filp,
858 void *priv, struct v4l2_control *c)
859{
860 struct stk_camera *dev = priv;
861 switch (c->id) {
862 case V4L2_CID_BRIGHTNESS:
863 c->value = dev->vsettings.brightness;
864 break;
865 case V4L2_CID_HFLIP:
866 if (dmi_check_system(stk_upside_down_dmi_table))
867 c->value = !dev->vsettings.hflip;
868 else
869 c->value = dev->vsettings.hflip;
870 break;
871 case V4L2_CID_VFLIP:
872 if (dmi_check_system(stk_upside_down_dmi_table))
873 c->value = !dev->vsettings.vflip;
874 else
875 c->value = dev->vsettings.vflip;
876 break;
877 default:
878 return -EINVAL;
879 }
880 return 0;
881}
882 813
883static int stk_vidioc_s_ctrl(struct file *filp, 814 switch (ctrl->id) {
884 void *priv, struct v4l2_control *c)
885{
886 struct stk_camera *dev = priv;
887 switch (c->id) {
888 case V4L2_CID_BRIGHTNESS: 815 case V4L2_CID_BRIGHTNESS:
889 dev->vsettings.brightness = c->value; 816 return stk_sensor_set_brightness(dev, ctrl->val);
890 return stk_sensor_set_brightness(dev, c->value >> 8);
891 case V4L2_CID_HFLIP: 817 case V4L2_CID_HFLIP:
892 if (dmi_check_system(stk_upside_down_dmi_table)) 818 if (dmi_check_system(stk_upside_down_dmi_table))
893 dev->vsettings.hflip = !c->value; 819 dev->vsettings.hflip = !ctrl->val;
894 else 820 else
895 dev->vsettings.hflip = c->value; 821 dev->vsettings.hflip = ctrl->val;
896 return 0; 822 return 0;
897 case V4L2_CID_VFLIP: 823 case V4L2_CID_VFLIP:
898 if (dmi_check_system(stk_upside_down_dmi_table)) 824 if (dmi_check_system(stk_upside_down_dmi_table))
899 dev->vsettings.vflip = !c->value; 825 dev->vsettings.vflip = !ctrl->val;
900 else 826 else
901 dev->vsettings.vflip = c->value; 827 dev->vsettings.vflip = ctrl->val;
902 return 0; 828 return 0;
903 default: 829 default:
904 return -EINVAL; 830 return -EINVAL;
@@ -1238,6 +1164,10 @@ static int stk_vidioc_enum_framesizes(struct file *filp,
1238 } 1164 }
1239} 1165}
1240 1166
1167static const struct v4l2_ctrl_ops stk_ctrl_ops = {
1168 .s_ctrl = stk_s_ctrl,
1169};
1170
1241static struct v4l2_file_operations v4l_stk_fops = { 1171static struct v4l2_file_operations v4l_stk_fops = {
1242 .owner = THIS_MODULE, 1172 .owner = THIS_MODULE,
1243 .open = v4l_stk_open, 1173 .open = v4l_stk_open,
@@ -1263,9 +1193,6 @@ static const struct v4l2_ioctl_ops v4l_stk_ioctl_ops = {
1263 .vidioc_dqbuf = stk_vidioc_dqbuf, 1193 .vidioc_dqbuf = stk_vidioc_dqbuf,
1264 .vidioc_streamon = stk_vidioc_streamon, 1194 .vidioc_streamon = stk_vidioc_streamon,
1265 .vidioc_streamoff = stk_vidioc_streamoff, 1195 .vidioc_streamoff = stk_vidioc_streamoff,
1266 .vidioc_queryctrl = stk_vidioc_queryctrl,
1267 .vidioc_g_ctrl = stk_vidioc_g_ctrl,
1268 .vidioc_s_ctrl = stk_vidioc_s_ctrl,
1269 .vidioc_g_parm = stk_vidioc_g_parm, 1196 .vidioc_g_parm = stk_vidioc_g_parm,
1270 .vidioc_enum_framesizes = stk_vidioc_enum_framesizes, 1197 .vidioc_enum_framesizes = stk_vidioc_enum_framesizes,
1271}; 1198};
@@ -1310,8 +1237,9 @@ static int stk_register_video_device(struct stk_camera *dev)
1310static int stk_camera_probe(struct usb_interface *interface, 1237static int stk_camera_probe(struct usb_interface *interface,
1311 const struct usb_device_id *id) 1238 const struct usb_device_id *id)
1312{ 1239{
1313 int i; 1240 struct v4l2_ctrl_handler *hdl;
1314 int err = 0; 1241 int err = 0;
1242 int i;
1315 1243
1316 struct stk_camera *dev = NULL; 1244 struct stk_camera *dev = NULL;
1317 struct usb_device *udev = interface_to_usbdev(interface); 1245 struct usb_device *udev = interface_to_usbdev(interface);
@@ -1329,6 +1257,20 @@ static int stk_camera_probe(struct usb_interface *interface,
1329 kfree(dev); 1257 kfree(dev);
1330 return err; 1258 return err;
1331 } 1259 }
1260 hdl = &dev->hdl;
1261 v4l2_ctrl_handler_init(hdl, 3);
1262 v4l2_ctrl_new_std(hdl, &stk_ctrl_ops,
1263 V4L2_CID_BRIGHTNESS, 0, 0xff, 0x1, 0x60);
1264 v4l2_ctrl_new_std(hdl, &stk_ctrl_ops,
1265 V4L2_CID_HFLIP, 0, 1, 1, 1);
1266 v4l2_ctrl_new_std(hdl, &stk_ctrl_ops,
1267 V4L2_CID_VFLIP, 0, 1, 1, 1);
1268 if (hdl->error) {
1269 err = hdl->error;
1270 dev_err(&udev->dev, "couldn't register control\n");
1271 goto error;
1272 }
1273 dev->v4l2_dev.ctrl_handler = hdl;
1332 1274
1333 spin_lock_init(&dev->spinlock); 1275 spin_lock_init(&dev->spinlock);
1334 init_waitqueue_head(&dev->wait_frame); 1276 init_waitqueue_head(&dev->wait_frame);
@@ -1372,7 +1314,6 @@ static int stk_camera_probe(struct usb_interface *interface,
1372 err = -ENODEV; 1314 err = -ENODEV;
1373 goto error; 1315 goto error;
1374 } 1316 }
1375 dev->vsettings.brightness = 0x7fff;
1376 dev->vsettings.palette = V4L2_PIX_FMT_RGB565; 1317 dev->vsettings.palette = V4L2_PIX_FMT_RGB565;
1377 dev->vsettings.mode = MODE_VGA; 1318 dev->vsettings.mode = MODE_VGA;
1378 dev->frame_size = 640 * 480 * 2; 1319 dev->frame_size = 640 * 480 * 2;
@@ -1389,6 +1330,7 @@ static int stk_camera_probe(struct usb_interface *interface,
1389 return 0; 1330 return 0;
1390 1331
1391error: 1332error:
1333 v4l2_ctrl_handler_free(hdl);
1392 v4l2_device_unregister(&dev->v4l2_dev); 1334 v4l2_device_unregister(&dev->v4l2_dev);
1393 kfree(dev); 1335 kfree(dev);
1394 return err; 1336 return err;
@@ -1407,6 +1349,7 @@ static void stk_camera_disconnect(struct usb_interface *interface)
1407 video_device_node_name(&dev->vdev)); 1349 video_device_node_name(&dev->vdev));
1408 1350
1409 video_unregister_device(&dev->vdev); 1351 video_unregister_device(&dev->vdev);
1352 v4l2_ctrl_handler_free(&dev->hdl);
1410 v4l2_device_unregister(&dev->v4l2_dev); 1353 v4l2_device_unregister(&dev->v4l2_dev);
1411} 1354}
1412 1355
diff --git a/drivers/media/usb/stkwebcam/stk-webcam.h b/drivers/media/usb/stkwebcam/stk-webcam.h
index 49ebe855cba6..901f0df21bc7 100644
--- a/drivers/media/usb/stkwebcam/stk-webcam.h
+++ b/drivers/media/usb/stkwebcam/stk-webcam.h
@@ -24,6 +24,7 @@
24 24
25#include <linux/usb.h> 25#include <linux/usb.h>
26#include <media/v4l2-device.h> 26#include <media/v4l2-device.h>
27#include <media/v4l2-ctrls.h>
27#include <media/v4l2-common.h> 28#include <media/v4l2-common.h>
28 29
29#define DRIVER_VERSION "v0.0.1" 30#define DRIVER_VERSION "v0.0.1"
@@ -60,7 +61,6 @@ enum stk_mode {MODE_VGA, MODE_SXGA, MODE_CIF, MODE_QVGA, MODE_QCIF};
60 61
61struct stk_video { 62struct stk_video {
62 enum stk_mode mode; 63 enum stk_mode mode;
63 int brightness;
64 __u32 palette; 64 __u32 palette;
65 int hflip; 65 int hflip;
66 int vflip; 66 int vflip;
@@ -93,6 +93,7 @@ struct regval {
93 93
94struct stk_camera { 94struct stk_camera {
95 struct v4l2_device v4l2_dev; 95 struct v4l2_device v4l2_dev;
96 struct v4l2_ctrl_handler hdl;
96 struct video_device vdev; 97 struct video_device vdev;
97 struct usb_device *udev; 98 struct usb_device *udev;
98 struct usb_interface *interface; 99 struct usb_interface *interface;