firmware-utils: bump to git HEAD
[openwrt/openwrt.git] / target / linux / bcm27xx / patches-5.4 / 950-0907-media-v4l2-fwnode-Add-helper-to-parse-device-propert.patch
1 From 1cc9056759e1f500de5e401afd4b0acff90cc653 Mon Sep 17 00:00:00 2001
2 From: Jacopo Mondi <jacopo@jmondi.org>
3 Date: Sat, 9 May 2020 11:04:49 +0200
4 Subject: [PATCH] media: v4l2-fwnode: Add helper to parse device
5 properties
6
7 Add an helper function to parse common device properties in the same
8 way as v4l2_fwnode_endpoint_parse() parses common endpoint properties.
9
10 Parse the 'rotation' and 'orientation' properties from the firmware
11 interface.
12
13 Signed-off-by: Jacopo Mondi <jacopo@jmondi.org>
14 Signed-off-by: Hans Verkuil <hverkuil-cisco@xs4all.nl>
15 Signed-off-by: Mauro Carvalho Chehab <mchehab+huawei@kernel.org>
16
17 Commit 344897ef1d9b33e246b64e255d807ca6c053f349 upstream
18
19 Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
20 ---
21 drivers/media/v4l2-core/v4l2-fwnode.c | 42 ++++++++++++++++++++++++
22 include/media/v4l2-fwnode.h | 47 +++++++++++++++++++++++++++
23 2 files changed, 89 insertions(+)
24
25 --- a/drivers/media/v4l2-core/v4l2-fwnode.c
26 +++ b/drivers/media/v4l2-core/v4l2-fwnode.c
27 @@ -599,6 +599,48 @@ void v4l2_fwnode_put_link(struct v4l2_fw
28 }
29 EXPORT_SYMBOL_GPL(v4l2_fwnode_put_link);
30
31 +int v4l2_fwnode_device_parse(struct device *dev,
32 + struct v4l2_fwnode_device_properties *props)
33 +{
34 + struct fwnode_handle *fwnode = dev_fwnode(dev);
35 + u32 val;
36 + int ret;
37 +
38 + memset(props, 0, sizeof(*props));
39 +
40 + props->orientation = V4L2_FWNODE_PROPERTY_UNSET;
41 + ret = fwnode_property_read_u32(fwnode, "orientation", &val);
42 + if (!ret) {
43 + switch (val) {
44 + case V4L2_FWNODE_ORIENTATION_FRONT:
45 + case V4L2_FWNODE_ORIENTATION_BACK:
46 + case V4L2_FWNODE_ORIENTATION_EXTERNAL:
47 + break;
48 + default:
49 + dev_warn(dev, "Unsupported device orientation: %u\n", val);
50 + return -EINVAL;
51 + }
52 +
53 + props->orientation = val;
54 + dev_dbg(dev, "device orientation: %u\n", val);
55 + }
56 +
57 + props->rotation = V4L2_FWNODE_PROPERTY_UNSET;
58 + ret = fwnode_property_read_u32(fwnode, "rotation", &val);
59 + if (!ret) {
60 + if (val >= 360) {
61 + dev_warn(dev, "Unsupported device rotation: %u\n", val);
62 + return -EINVAL;
63 + }
64 +
65 + props->rotation = val;
66 + dev_dbg(dev, "device rotation: %u\n", val);
67 + }
68 +
69 + return 0;
70 +}
71 +EXPORT_SYMBOL_GPL(v4l2_fwnode_device_parse);
72 +
73 static int
74 v4l2_async_notifier_fwnode_parse_endpoint(struct device *dev,
75 struct v4l2_async_notifier *notifier,
76 --- a/include/media/v4l2-fwnode.h
77 +++ b/include/media/v4l2-fwnode.h
78 @@ -110,6 +110,36 @@ struct v4l2_fwnode_endpoint {
79 };
80
81 /**
82 + * V4L2_FWNODE_PROPERTY_UNSET - identify a non initialized property
83 + *
84 + * All properties in &struct v4l2_fwnode_device_properties are initialized
85 + * to this value.
86 + */
87 +#define V4L2_FWNODE_PROPERTY_UNSET (-1U)
88 +
89 +/**
90 + * enum v4l2_fwnode_orientation - possible device orientation
91 + * @V4L2_FWNODE_ORIENTATION_FRONT: device installed on the front side
92 + * @V4L2_FWNODE_ORIENTATION_BACK: device installed on the back side
93 + * @V4L2_FWNODE_ORIENTATION_EXTERNAL: device externally located
94 + */
95 +enum v4l2_fwnode_orientation {
96 + V4L2_FWNODE_ORIENTATION_FRONT,
97 + V4L2_FWNODE_ORIENTATION_BACK,
98 + V4L2_FWNODE_ORIENTATION_EXTERNAL
99 +};
100 +
101 +/**
102 + * struct v4l2_fwnode_device_properties - fwnode device properties
103 + * @orientation: device orientation. See &enum v4l2_fwnode_orientation
104 + * @rotation: device rotation
105 + */
106 +struct v4l2_fwnode_device_properties {
107 + enum v4l2_fwnode_orientation orientation;
108 + unsigned int rotation;
109 +};
110 +
111 +/**
112 * struct v4l2_fwnode_link - a link between two endpoints
113 * @local_node: pointer to device_node of this endpoint
114 * @local_port: identifier of the port this endpoint belongs to
115 @@ -234,6 +264,23 @@ int v4l2_fwnode_parse_link(struct fwnode
116 void v4l2_fwnode_put_link(struct v4l2_fwnode_link *link);
117
118 /**
119 + * v4l2_fwnode_device_parse() - parse fwnode device properties
120 + * @dev: pointer to &struct device
121 + * @props: pointer to &struct v4l2_fwnode_device_properties where to store the
122 + * parsed properties values
123 + *
124 + * This function parses and validates the V4L2 fwnode device properties from the
125 + * firmware interface, and fills the @struct v4l2_fwnode_device_properties
126 + * provided by the caller.
127 + *
128 + * Return:
129 + * % 0 on success
130 + * %-EINVAL if a parsed property value is not valid
131 + */
132 +int v4l2_fwnode_device_parse(struct device *dev,
133 + struct v4l2_fwnode_device_properties *props);
134 +
135 +/**
136 * typedef parse_endpoint_func - Driver's callback function to be called on
137 * each V4L2 fwnode endpoint.
138 *