a76de95bf3e2e455d6850f2ab1a7569db435b6a2
[openwrt/openwrt.git] / target / linux / bcm27xx / patches-5.4 / 950-0908-media-v4l2-ctrls-Add-helper-to-register-properties.patch
1 From 67429ff939ad15a313663a05461d7a07d209449f Mon Sep 17 00:00:00 2001
2 From: Jacopo Mondi <jacopo@jmondi.org>
3 Date: Sat, 9 May 2020 11:04:52 +0200
4 Subject: [PATCH] media: v4l2-ctrls: Add helper to register
5 properties
6
7 Add an helper function to v4l2-ctrls to register controls associated
8 with a device property.
9
10 Signed-off-by: Jacopo Mondi <jacopo@jmondi.org>
11 Signed-off-by: Hans Verkuil <hverkuil-cisco@xs4all.nl>
12 Signed-off-by: Mauro Carvalho Chehab <mchehab+huawei@kernel.org>
13
14 Commit e0a360630debdf12355d9ec9f1417172c3fa6756 upstream
15
16 Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
17 ---
18 drivers/media/v4l2-core/v4l2-ctrls.c | 40 ++++++++++++++++++++++++++++
19 include/media/v4l2-ctrls.h | 26 ++++++++++++++++++
20 2 files changed, 66 insertions(+)
21
22 --- a/drivers/media/v4l2-core/v4l2-ctrls.c
23 +++ b/drivers/media/v4l2-core/v4l2-ctrls.c
24 @@ -17,6 +17,7 @@
25 #include <media/v4l2-ctrls.h>
26 #include <media/v4l2-event.h>
27 #include <media/v4l2-dev.h>
28 +#include <media/v4l2-fwnode.h>
29
30 #define dprintk(vdev, fmt, arg...) do { \
31 if (!WARN_ON(!(vdev)) && ((vdev)->dev_debug & V4L2_DEV_DEBUG_CTRL)) \
32 @@ -4577,3 +4578,42 @@ __poll_t v4l2_ctrl_poll(struct file *fil
33 return 0;
34 }
35 EXPORT_SYMBOL(v4l2_ctrl_poll);
36 +
37 +int v4l2_ctrl_new_fwnode_properties(struct v4l2_ctrl_handler *hdl,
38 + const struct v4l2_ctrl_ops *ctrl_ops,
39 + const struct v4l2_fwnode_device_properties *p)
40 +{
41 + if (p->orientation != V4L2_FWNODE_PROPERTY_UNSET) {
42 + u32 orientation_ctrl;
43 +
44 + switch (p->orientation) {
45 + case V4L2_FWNODE_ORIENTATION_FRONT:
46 + orientation_ctrl = V4L2_CAMERA_ORIENTATION_FRONT;
47 + break;
48 + case V4L2_FWNODE_ORIENTATION_BACK:
49 + orientation_ctrl = V4L2_CAMERA_ORIENTATION_BACK;
50 + break;
51 + case V4L2_FWNODE_ORIENTATION_EXTERNAL:
52 + orientation_ctrl = V4L2_CAMERA_ORIENTATION_EXTERNAL;
53 + break;
54 + default:
55 + return -EINVAL;
56 + }
57 + if (!v4l2_ctrl_new_std_menu(hdl, ctrl_ops,
58 + V4L2_CID_CAMERA_ORIENTATION,
59 + V4L2_CAMERA_ORIENTATION_EXTERNAL, 0,
60 + orientation_ctrl))
61 + return hdl->error;
62 + }
63 +
64 + if (p->rotation != V4L2_FWNODE_PROPERTY_UNSET) {
65 + if (!v4l2_ctrl_new_std(hdl, ctrl_ops,
66 + V4L2_CID_CAMERA_SENSOR_ROTATION,
67 + p->rotation, p->rotation, 1,
68 + p->rotation))
69 + return hdl->error;
70 + }
71 +
72 + return hdl->error;
73 +}
74 +EXPORT_SYMBOL(v4l2_ctrl_new_fwnode_properties);
75 --- a/include/media/v4l2-ctrls.h
76 +++ b/include/media/v4l2-ctrls.h
77 @@ -29,6 +29,7 @@ struct v4l2_ctrl_handler;
78 struct v4l2_ctrl_helper;
79 struct v4l2_ctrl;
80 struct video_device;
81 +struct v4l2_fwnode_device_properties;
82 struct v4l2_subdev;
83 struct v4l2_subscribed_event;
84 struct v4l2_fh;
85 @@ -1379,4 +1380,29 @@ int v4l2_ctrl_subdev_subscribe_event(str
86 */
87 int v4l2_ctrl_subdev_log_status(struct v4l2_subdev *sd);
88
89 +/**
90 + * v4l2_ctrl_new_fwnode_properties() - Register controls for the device
91 + * properties
92 + *
93 + * @hdl: pointer to &struct v4l2_ctrl_handler to register controls on
94 + * @ctrl_ops: pointer to &struct v4l2_ctrl_ops to register controls with
95 + * @p: pointer to &struct v4l2_fwnode_device_properties
96 + *
97 + * This function registers controls associated to device properties, using the
98 + * property values contained in @p parameter, if the property has been set to
99 + * a value.
100 + *
101 + * Currently the following v4l2 controls are parsed and registered:
102 + * - V4L2_CID_CAMERA_ORIENTATION
103 + * - V4L2_CID_CAMERA_SENSOR_ROTATION;
104 + *
105 + * Controls already registered by the caller with the @hdl control handler are
106 + * not overwritten. Callers should register the controls they want to handle
107 + * themselves before calling this function.
108 + *
109 + * Return: 0 on success, a negative error code on failure.
110 + */
111 +int v4l2_ctrl_new_fwnode_properties(struct v4l2_ctrl_handler *hdl,
112 + const struct v4l2_ctrl_ops *ctrl_ops,
113 + const struct v4l2_fwnode_device_properties *p);
114 #endif