{"id":3415,"url":"https://patchwork.libcamera.org/api/1.1/patches/3415/?format=json","web_url":"https://patchwork.libcamera.org/patch/3415/","project":{"id":1,"url":"https://patchwork.libcamera.org/api/1.1/projects/1/?format=json","name":"libcamera","link_name":"libcamera","list_id":"libcamera_core","list_email":"libcamera-devel@lists.libcamera.org","web_url":"","scm_url":"","webscm_url":""},"msgid":"<20200407163825.1766483-7-jacopo@jmondi.org>","date":"2020-04-07T16:38:20","name":"[libcamera-devel,v8,06/11] media: v4l2-fwnode: Add helper to parse device properties","commit_ref":null,"pull_url":null,"state":"not-applicable","archived":false,"hash":"8599e36809d577e51c95b37d57fffd94ee8aac39","submitter":{"id":3,"url":"https://patchwork.libcamera.org/api/1.1/people/3/?format=json","name":"Jacopo Mondi","email":"jacopo@jmondi.org"},"delegate":{"id":15,"url":"https://patchwork.libcamera.org/api/1.1/users/15/?format=json","username":"jmondi","first_name":"Jacopo","last_name":"Mondi","email":"jacopo@jmondi.org"},"mbox":"https://patchwork.libcamera.org/patch/3415/mbox/","series":[{"id":801,"url":"https://patchwork.libcamera.org/api/1.1/series/801/?format=json","web_url":"https://patchwork.libcamera.org/project/libcamera/list/?series=801","date":"2020-04-07T16:38:14","name":"media: Report camera sensor properties","version":8,"mbox":"https://patchwork.libcamera.org/series/801/mbox/"}],"comments":"https://patchwork.libcamera.org/api/patches/3415/comments/","check":"pending","checks":"https://patchwork.libcamera.org/api/patches/3415/checks/","tags":{},"headers":{"Return-Path":"<jacopo@jmondi.org>","Received":["from relay2-d.mail.gandi.net (relay2-d.mail.gandi.net\n\t[217.70.183.194])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id DCEEE62826\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tTue,  7 Apr 2020 18:35:41 +0200 (CEST)","from localhost.localdomain (2-224-242-101.ip172.fastwebnet.it\n\t[2.224.242.101]) (Authenticated sender: jacopo@jmondi.org)\n\tby relay2-d.mail.gandi.net (Postfix) with ESMTPSA id 2179440016;\n\tTue,  7 Apr 2020 16:35:39 +0000 (UTC)"],"X-Originating-IP":"2.224.242.101","From":"Jacopo Mondi <jacopo@jmondi.org>","To":"Mauro Carvalho Chehab <mchehab@kernel.org>,\n\tHans Verkuil <hverkuil-cisco@xs4all.nl>,\n\tSakari Ailus <sakari.ailus@linux.intel.com>,\n\tLaurent Pinchart <laurent.pinchart@ideasonboard.com>, tfiga@google.com,\n\tpavel@ucw.cz","Cc":"Jacopo Mondi <jacopo@jmondi.org>,\n\tlinux-media@vger.kernel.org (open list:MEDIA INPUT INFRASTRUCTURE\n\t(V4L/DVB)), libcamera-devel@lists.libcamera.org","Date":"Tue,  7 Apr 2020 18:38:20 +0200","Message-Id":"<20200407163825.1766483-7-jacopo@jmondi.org>","X-Mailer":"git-send-email 2.26.0","In-Reply-To":"<20200407163825.1766483-1-jacopo@jmondi.org>","References":"<20200407163825.1766483-1-jacopo@jmondi.org>","MIME-Version":"1.0","Content-Transfer-Encoding":"8bit","Subject":"[libcamera-devel] [PATCH v8 06/11] media: v4l2-fwnode: Add helper\n\tto parse device properties","X-BeenThere":"libcamera-devel@lists.libcamera.org","X-Mailman-Version":"2.1.29","Precedence":"list","List-Id":"<libcamera-devel.lists.libcamera.org>","List-Unsubscribe":"<https://lists.libcamera.org/options/libcamera-devel>,\n\t<mailto:libcamera-devel-request@lists.libcamera.org?subject=unsubscribe>","List-Archive":"<https://lists.libcamera.org/pipermail/libcamera-devel/>","List-Post":"<mailto:libcamera-devel@lists.libcamera.org>","List-Help":"<mailto:libcamera-devel-request@lists.libcamera.org?subject=help>","List-Subscribe":"<https://lists.libcamera.org/listinfo/libcamera-devel>,\n\t<mailto:libcamera-devel-request@lists.libcamera.org?subject=subscribe>","X-List-Received-Date":"Tue, 07 Apr 2020 16:35:42 -0000"},"content":"Add an helper function to parse common device properties in the same\nway as v4l2_fwnode_endpoint_parse() parses common endpoint properties.\n\nParse the 'rotation' and 'location' properties from the firmware\ninterface.\n\nSigned-off-by: Jacopo Mondi <jacopo@jmondi.org>\n---\n drivers/media/v4l2-core/v4l2-fwnode.c | 42 ++++++++++++++++++++++++\n include/media/v4l2-fwnode.h           | 47 +++++++++++++++++++++++++++\n 2 files changed, 89 insertions(+)","diff":"diff --git a/drivers/media/v4l2-core/v4l2-fwnode.c b/drivers/media/v4l2-core/v4l2-fwnode.c\nindex 97f0f8b23b5d..1e074e1960a0 100644\n--- a/drivers/media/v4l2-core/v4l2-fwnode.c\n+++ b/drivers/media/v4l2-core/v4l2-fwnode.c\n@@ -756,6 +756,48 @@ int v4l2_fwnode_connector_add_link(struct fwnode_handle *fwnode,\n }\n EXPORT_SYMBOL_GPL(v4l2_fwnode_connector_add_link);\n \n+int v4l2_fwnode_device_parse(struct device *dev,\n+\t\t\t     struct v4l2_fwnode_device_properties *props)\n+{\n+\tstruct fwnode_handle *fwnode = dev_fwnode(dev);\n+\tu32 val;\n+\tint ret;\n+\n+\tmemset(props, 0, sizeof(*props));\n+\n+\tprops->location = V4L2_FWNODE_PROPERTY_UNSET;\n+\tret = fwnode_property_read_u32(fwnode, \"location\", &val);\n+\tif (!ret) {\n+\t\tswitch (val) {\n+\t\tcase V4L2_FWNODE_LOCATION_FRONT:\n+\t\tcase V4L2_FWNODE_LOCATION_BACK:\n+\t\tcase V4L2_FWNODE_LOCATION_EXTERNAL:\n+\t\t\tbreak;\n+\t\tdefault:\n+\t\t\tdev_warn(dev, \"Unsupported device location: %u\\n\", val);\n+\t\t\treturn -EINVAL;\n+\t\t}\n+\n+\t\tprops->location = val;\n+\t\tdev_dbg(dev, \"device location: %u\\n\", val);\n+\t}\n+\n+\tprops->rotation = V4L2_FWNODE_PROPERTY_UNSET;\n+\tret = fwnode_property_read_u32(fwnode, \"rotation\", &val);\n+\tif (!ret) {\n+\t\tif (val >= 360 || val % 90) {\n+\t\t\tdev_warn(dev, \"Unsupported device rotation: %u\\n\", val);\n+\t\t\treturn -EINVAL;\n+\t\t}\n+\n+\t\tprops->rotation = val;\n+\t\tdev_dbg(dev, \"device rotation: %u\\n\", val);\n+\t}\n+\n+\treturn 0;\n+}\n+EXPORT_SYMBOL_GPL(v4l2_fwnode_device_parse);\n+\n static int\n v4l2_async_notifier_fwnode_parse_endpoint(struct device *dev,\n \t\t\t\t\t  struct v4l2_async_notifier *notifier,\ndiff --git a/include/media/v4l2-fwnode.h b/include/media/v4l2-fwnode.h\nindex dd82d6d9764e..b37d0be8b28d 100644\n--- a/include/media/v4l2-fwnode.h\n+++ b/include/media/v4l2-fwnode.h\n@@ -109,6 +109,36 @@ struct v4l2_fwnode_endpoint {\n \tunsigned int nr_of_link_frequencies;\n };\n \n+/**\n+ * v4l2_fwnode_location - identify a non initialized property.\n+ *\n+ * All properties in &struct v4l2_fwnode_device_properties are initialized\n+ * to this value.\n+ */\n+#define V4L2_FWNODE_PROPERTY_UNSET   (-1U)\n+\n+/**\n+ * enum v4l2_fwnode_location - possible device locations\n+ * @V4L2_FWNODE_LOCATION_FRONT: device installed on the front side\n+ * @V4L2_FWNODE_LOCATION_BACK: device installed on the back side\n+ * @V4L2_FWNODE_LOCATION_EXTERNAL: device externally located\n+ */\n+enum v4l2_fwnode_location {\n+\tV4L2_FWNODE_LOCATION_FRONT,\n+\tV4L2_FWNODE_LOCATION_BACK,\n+\tV4L2_FWNODE_LOCATION_EXTERNAL\n+};\n+\n+/**\n+ * struct v4l2_fwnode_device_properties - fwnode device properties\n+ * @location: device location. See &enum v4l2_fwnode_location\n+ * @rotation: device rotation\n+ */\n+struct v4l2_fwnode_device_properties {\n+\tenum v4l2_fwnode_location location;\n+\tunsigned int rotation;\n+};\n+\n /**\n  * struct v4l2_fwnode_link - a link between two endpoints\n  * @local_node: pointer to device_node of this endpoint\n@@ -354,6 +384,23 @@ int v4l2_fwnode_connector_parse(struct fwnode_handle *fwnode,\n int v4l2_fwnode_connector_add_link(struct fwnode_handle *fwnode,\n \t\t\t\t   struct v4l2_fwnode_connector *connector);\n \n+/**\n+ * v4l2_fwnode_device_parse() - parse fwnode device properties\n+ * @dev: pointer to &struct device\n+ * @props: pointer to &struct v4l2_fwnode_device_properties where to store the\n+ *\t   parsed properties values\n+ *\n+ * This function parses and validates the V4L2 fwnode device properties from the\n+ * firmware interface, and fills the @struct v4l2_fwnode_device_properties\n+ * provided by the caller.\n+ *\n+ * Return:\n+ *\t% 0 on success\n+ *\t%-EINVAL if a parsed property value is not valid\n+ */\n+int v4l2_fwnode_device_parse(struct device *dev,\n+\t\t\t     struct v4l2_fwnode_device_properties *props);\n+\n /**\n  * typedef parse_endpoint_func - Driver's callback function to be called on\n  *\teach V4L2 fwnode endpoint.\n","prefixes":["libcamera-devel","v8","06/11"]}