diff options
| author | Florian Echtler <floe@butterbrot.org> | 2018-02-08 03:43:06 -0500 |
|---|---|---|
| committer | Mauro Carvalho Chehab <mchehab@s-opensource.com> | 2018-02-14 13:29:55 -0500 |
| commit | cee1e3e2ef39cc3184710c164503143f0e4dcdd4 (patch) | |
| tree | 08b8e6c53306f5d9fe72507105a921c25f69dc97 /drivers/input | |
| parent | bbc0c4eb6b6b6bd5f5a83caa99d221a85f3063eb (diff) | |
media: add video control handlers using V4L2 control framework
This patch registers four standard control handlers using the corresponding
V4L2 framework.
Signed-off-by: Florian Echtler <floe@butterbrot.org>
[hans.verkuil@cisco.com: lower-cased 0x0F and 0xF0]
Signed-off-by: Hans Verkuil <hans.verkuil@cisco.com>
Signed-off-by: Mauro Carvalho Chehab <mchehab@s-opensource.com>
Diffstat (limited to 'drivers/input')
| -rw-r--r-- | drivers/input/touchscreen/sur40.c | 64 |
1 files changed, 64 insertions, 0 deletions
diff --git a/drivers/input/touchscreen/sur40.c b/drivers/input/touchscreen/sur40.c index 3b56f7d05ec5..894843a7ec7b 100644 --- a/drivers/input/touchscreen/sur40.c +++ b/drivers/input/touchscreen/sur40.c | |||
| @@ -38,6 +38,7 @@ | |||
| 38 | #include <media/v4l2-device.h> | 38 | #include <media/v4l2-device.h> |
| 39 | #include <media/v4l2-dev.h> | 39 | #include <media/v4l2-dev.h> |
| 40 | #include <media/v4l2-ioctl.h> | 40 | #include <media/v4l2-ioctl.h> |
| 41 | #include <media/v4l2-ctrls.h> | ||
| 41 | #include <media/videobuf2-v4l2.h> | 42 | #include <media/videobuf2-v4l2.h> |
| 42 | #include <media/videobuf2-dma-sg.h> | 43 | #include <media/videobuf2-dma-sg.h> |
| 43 | 44 | ||
| @@ -215,6 +216,7 @@ struct sur40_state { | |||
| 215 | struct video_device vdev; | 216 | struct video_device vdev; |
| 216 | struct mutex lock; | 217 | struct mutex lock; |
| 217 | struct v4l2_pix_format pix_fmt; | 218 | struct v4l2_pix_format pix_fmt; |
| 219 | struct v4l2_ctrl_handler hdl; | ||
| 218 | 220 | ||
| 219 | struct vb2_queue queue; | 221 | struct vb2_queue queue; |
| 220 | struct list_head buf_list; | 222 | struct list_head buf_list; |
| @@ -224,6 +226,7 @@ struct sur40_state { | |||
| 224 | struct sur40_data *bulk_in_buffer; | 226 | struct sur40_data *bulk_in_buffer; |
| 225 | size_t bulk_in_size; | 227 | size_t bulk_in_size; |
| 226 | u8 bulk_in_epaddr; | 228 | u8 bulk_in_epaddr; |
| 229 | u8 vsvideo; | ||
| 227 | 230 | ||
| 228 | char phys[64]; | 231 | char phys[64]; |
| 229 | }; | 232 | }; |
| @@ -237,6 +240,11 @@ struct sur40_buffer { | |||
| 237 | static const struct video_device sur40_video_device; | 240 | static const struct video_device sur40_video_device; |
| 238 | static const struct vb2_queue sur40_queue; | 241 | static const struct vb2_queue sur40_queue; |
| 239 | static void sur40_process_video(struct sur40_state *sur40); | 242 | static void sur40_process_video(struct sur40_state *sur40); |
| 243 | static int sur40_s_ctrl(struct v4l2_ctrl *ctrl); | ||
| 244 | |||
| 245 | static const struct v4l2_ctrl_ops sur40_ctrl_ops = { | ||
| 246 | .s_ctrl = sur40_s_ctrl, | ||
| 247 | }; | ||
| 240 | 248 | ||
| 241 | /* | 249 | /* |
| 242 | * Note: an earlier, non-public version of this driver used USB_RECIP_ENDPOINT | 250 | * Note: an earlier, non-public version of this driver used USB_RECIP_ENDPOINT |
| @@ -743,6 +751,36 @@ static int sur40_probe(struct usb_interface *interface, | |||
| 743 | sur40->vdev.queue = &sur40->queue; | 751 | sur40->vdev.queue = &sur40->queue; |
| 744 | video_set_drvdata(&sur40->vdev, sur40); | 752 | video_set_drvdata(&sur40->vdev, sur40); |
| 745 | 753 | ||
| 754 | /* initialize the control handler for 4 controls */ | ||
| 755 | v4l2_ctrl_handler_init(&sur40->hdl, 4); | ||
| 756 | sur40->v4l2.ctrl_handler = &sur40->hdl; | ||
| 757 | sur40->vsvideo = (SUR40_CONTRAST_DEF << 4) | SUR40_GAIN_DEF; | ||
| 758 | |||
| 759 | v4l2_ctrl_new_std(&sur40->hdl, &sur40_ctrl_ops, V4L2_CID_BRIGHTNESS, | ||
| 760 | SUR40_BRIGHTNESS_MIN, SUR40_BRIGHTNESS_MAX, 1, clamp(brightness, | ||
| 761 | (uint)SUR40_BRIGHTNESS_MIN, (uint)SUR40_BRIGHTNESS_MAX)); | ||
| 762 | |||
| 763 | v4l2_ctrl_new_std(&sur40->hdl, &sur40_ctrl_ops, V4L2_CID_CONTRAST, | ||
| 764 | SUR40_CONTRAST_MIN, SUR40_CONTRAST_MAX, 1, clamp(contrast, | ||
| 765 | (uint)SUR40_CONTRAST_MIN, (uint)SUR40_CONTRAST_MAX)); | ||
| 766 | |||
| 767 | v4l2_ctrl_new_std(&sur40->hdl, &sur40_ctrl_ops, V4L2_CID_GAIN, | ||
| 768 | SUR40_GAIN_MIN, SUR40_GAIN_MAX, 1, clamp(gain, | ||
| 769 | (uint)SUR40_GAIN_MIN, (uint)SUR40_GAIN_MAX)); | ||
| 770 | |||
| 771 | v4l2_ctrl_new_std(&sur40->hdl, &sur40_ctrl_ops, | ||
| 772 | V4L2_CID_BACKLIGHT_COMPENSATION, SUR40_BACKLIGHT_MIN, | ||
| 773 | SUR40_BACKLIGHT_MAX, 1, SUR40_BACKLIGHT_DEF); | ||
| 774 | |||
| 775 | v4l2_ctrl_handler_setup(&sur40->hdl); | ||
| 776 | |||
| 777 | if (sur40->hdl.error) { | ||
| 778 | dev_err(&interface->dev, | ||
| 779 | "Unable to register video controls."); | ||
| 780 | v4l2_ctrl_handler_free(&sur40->hdl); | ||
| 781 | goto err_unreg_v4l2; | ||
| 782 | } | ||
| 783 | |||
| 746 | error = video_register_device(&sur40->vdev, VFL_TYPE_TOUCH, -1); | 784 | error = video_register_device(&sur40->vdev, VFL_TYPE_TOUCH, -1); |
| 747 | if (error) { | 785 | if (error) { |
| 748 | dev_err(&interface->dev, | 786 | dev_err(&interface->dev, |
| @@ -775,6 +813,7 @@ static void sur40_disconnect(struct usb_interface *interface) | |||
| 775 | { | 813 | { |
| 776 | struct sur40_state *sur40 = usb_get_intfdata(interface); | 814 | struct sur40_state *sur40 = usb_get_intfdata(interface); |
| 777 | 815 | ||
| 816 | v4l2_ctrl_handler_free(&sur40->hdl); | ||
| 778 | video_unregister_device(&sur40->vdev); | 817 | video_unregister_device(&sur40->vdev); |
| 779 | v4l2_device_unregister(&sur40->v4l2); | 818 | v4l2_device_unregister(&sur40->v4l2); |
| 780 | 819 | ||
| @@ -968,6 +1007,31 @@ static int sur40_vidioc_g_fmt(struct file *file, void *priv, | |||
| 968 | return 0; | 1007 | return 0; |
| 969 | } | 1008 | } |
| 970 | 1009 | ||
| 1010 | static int sur40_s_ctrl(struct v4l2_ctrl *ctrl) | ||
| 1011 | { | ||
| 1012 | struct sur40_state *sur40 = container_of(ctrl->handler, | ||
| 1013 | struct sur40_state, hdl); | ||
| 1014 | u8 value = sur40->vsvideo; | ||
| 1015 | |||
| 1016 | switch (ctrl->id) { | ||
| 1017 | case V4L2_CID_BRIGHTNESS: | ||
| 1018 | sur40_set_irlevel(sur40, ctrl->val); | ||
| 1019 | break; | ||
| 1020 | case V4L2_CID_CONTRAST: | ||
| 1021 | value = (value & 0x0f) | (ctrl->val << 4); | ||
| 1022 | sur40_set_vsvideo(sur40, value); | ||
| 1023 | break; | ||
| 1024 | case V4L2_CID_GAIN: | ||
| 1025 | value = (value & 0xf0) | (ctrl->val); | ||
| 1026 | sur40_set_vsvideo(sur40, value); | ||
| 1027 | break; | ||
| 1028 | case V4L2_CID_BACKLIGHT_COMPENSATION: | ||
| 1029 | sur40_set_preprocessor(sur40, ctrl->val); | ||
| 1030 | break; | ||
| 1031 | } | ||
| 1032 | return 0; | ||
| 1033 | } | ||
| 1034 | |||
| 971 | static int sur40_ioctl_parm(struct file *file, void *priv, | 1035 | static int sur40_ioctl_parm(struct file *file, void *priv, |
| 972 | struct v4l2_streamparm *p) | 1036 | struct v4l2_streamparm *p) |
| 973 | { | 1037 | { |
