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
7 Add an helper function to parse common device properties in the same
8 way as v4l2_fwnode_endpoint_parse() parses common endpoint properties.
10 Parse the 'rotation' and 'orientation' properties from the firmware
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>
17 Commit 344897ef1d9b33e246b64e255d807ca6c053f349 upstream
19 Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
21 drivers/media/v4l2-core/v4l2-fwnode.c | 42 ++++++++++++++++++++++++
22 include/media/v4l2-fwnode.h | 47 +++++++++++++++++++++++++++
23 2 files changed, 89 insertions(+)
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
29 EXPORT_SYMBOL_GPL(v4l2_fwnode_put_link);
31 +int v4l2_fwnode_device_parse(struct device *dev,
32 + struct v4l2_fwnode_device_properties *props)
34 + struct fwnode_handle *fwnode = dev_fwnode(dev);
38 + memset(props, 0, sizeof(*props));
40 + props->orientation = V4L2_FWNODE_PROPERTY_UNSET;
41 + ret = fwnode_property_read_u32(fwnode, "orientation", &val);
44 + case V4L2_FWNODE_ORIENTATION_FRONT:
45 + case V4L2_FWNODE_ORIENTATION_BACK:
46 + case V4L2_FWNODE_ORIENTATION_EXTERNAL:
49 + dev_warn(dev, "Unsupported device orientation: %u\n", val);
53 + props->orientation = val;
54 + dev_dbg(dev, "device orientation: %u\n", val);
57 + props->rotation = V4L2_FWNODE_PROPERTY_UNSET;
58 + ret = fwnode_property_read_u32(fwnode, "rotation", &val);
61 + dev_warn(dev, "Unsupported device rotation: %u\n", val);
65 + props->rotation = val;
66 + dev_dbg(dev, "device rotation: %u\n", val);
71 +EXPORT_SYMBOL_GPL(v4l2_fwnode_device_parse);
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 {
82 + * V4L2_FWNODE_PROPERTY_UNSET - identify a non initialized property
84 + * All properties in &struct v4l2_fwnode_device_properties are initialized
87 +#define V4L2_FWNODE_PROPERTY_UNSET (-1U)
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
95 +enum v4l2_fwnode_orientation {
96 + V4L2_FWNODE_ORIENTATION_FRONT,
97 + V4L2_FWNODE_ORIENTATION_BACK,
98 + V4L2_FWNODE_ORIENTATION_EXTERNAL
102 + * struct v4l2_fwnode_device_properties - fwnode device properties
103 + * @orientation: device orientation. See &enum v4l2_fwnode_orientation
104 + * @rotation: device rotation
106 +struct v4l2_fwnode_device_properties {
107 + enum v4l2_fwnode_orientation orientation;
108 + unsigned int rotation;
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);
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
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.
130 + * %-EINVAL if a parsed property value is not valid
132 +int v4l2_fwnode_device_parse(struct device *dev,
133 + struct v4l2_fwnode_device_properties *props);
136 * typedef parse_endpoint_func - Driver's callback function to be called on
137 * each V4L2 fwnode endpoint.