{"id":8812,"url":"https://patchwork.libcamera.org/api/1.1/patches/8812/?format=json","web_url":"https://patchwork.libcamera.org/patch/8812/","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":"<20200715011833.24600-7-laurent.pinchart@ideasonboard.com>","date":"2020-07-15T01:18:26","name":"[libcamera-devel,v2,06/13] media: v4l2-fwnode: Add helper to parse device properties","commit_ref":null,"pull_url":null,"state":"accepted","archived":false,"hash":"343936f09a58a2fe4d590673c260bf68185eb646","submitter":{"id":2,"url":"https://patchwork.libcamera.org/api/1.1/people/2/?format=json","name":"Laurent Pinchart","email":"laurent.pinchart@ideasonboard.com"},"delegate":{"id":14,"url":"https://patchwork.libcamera.org/api/1.1/users/14/?format=json","username":"pinchartl","first_name":"Laurent","last_name":"Pinchart","email":"laurent.pinchart@ideasonboard.com"},"mbox":"https://patchwork.libcamera.org/patch/8812/mbox/","series":[{"id":1108,"url":"https://patchwork.libcamera.org/api/1.1/series/1108/?format=json","web_url":"https://patchwork.libcamera.org/project/libcamera/list/?series=1108","date":"2020-07-15T01:18:21","name":"raspberrypi: Report sensor orientation through DT","version":2,"mbox":"https://patchwork.libcamera.org/series/1108/mbox/"}],"comments":"https://patchwork.libcamera.org/api/patches/8812/comments/","check":"pending","checks":"https://patchwork.libcamera.org/api/patches/8812/checks/","tags":{},"headers":{"Return-Path":"<libcamera-devel-bounces@lists.libcamera.org>","X-Original-To":"parsemail@patchwork.libcamera.org","Delivered-To":"parsemail@patchwork.libcamera.org","Received":["from lancelot.ideasonboard.com (lancelot.ideasonboard.com\n\t[92.243.16.209])\n\tby patchwork.libcamera.org (Postfix) with ESMTPS id BF274BD790\n\tfor <parsemail@patchwork.libcamera.org>;\n\tWed, 15 Jul 2020 01:18:54 +0000 (UTC)","from lancelot.ideasonboard.com (localhost [IPv6:::1])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTP id 8F53760987;\n\tWed, 15 Jul 2020 03:18:54 +0200 (CEST)","from perceval.ideasonboard.com (perceval.ideasonboard.com\n\t[IPv6:2001:4b98:dc2:55:216:3eff:fef7:d647])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id BF7C16092F\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tWed, 15 Jul 2020 03:18:47 +0200 (CEST)","from pendragon.bb.dnainternet.fi (81-175-216-236.bb.dnainternet.fi\n\t[81.175.216.236])\n\tby perceval.ideasonboard.com (Postfix) with ESMTPSA id 4024811F0;\n\tWed, 15 Jul 2020 03:18:47 +0200 (CEST)"],"Authentication-Results":"lancelot.ideasonboard.com;\n\tdkim=fail reason=\"signature verification failed\" (1024-bit key;\n\tunprotected) header.d=ideasonboard.com header.i=@ideasonboard.com\n\theader.b=\"nMM5z2Rw\"; dkim-atps=neutral","DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com;\n\ts=mail; t=1594775927;\n\tbh=XAiz1E0pSrmetZbDkLJDLoxe0rcdenQMu8A0qof58QA=;\n\th=From:To:Cc:Subject:Date:In-Reply-To:References:From;\n\tb=nMM5z2Rwa0oR0VfDctFVXC+1k/JJ8yCcNJN0oncZmwxbmL8dVVVw8ypNalHCES/K7\n\tJd+hqVHSku+C8usYDeGEd7uKWfqdwyZDbzRwZoKVx7ioXO4mkwx043i16P/GVkkgtO\n\tAYpjn63iPjFlOMghiG62qS+vd9ciVHIUajjIswaM=","From":"Laurent Pinchart <laurent.pinchart@ideasonboard.com>","To":"Dave Stevenson <dave.stevenson@raspberrypi.com>","Date":"Wed, 15 Jul 2020 04:18:26 +0300","Message-Id":"<20200715011833.24600-7-laurent.pinchart@ideasonboard.com>","X-Mailer":"git-send-email 2.27.0","In-Reply-To":"<20200715011833.24600-1-laurent.pinchart@ideasonboard.com>","References":"<20200715011833.24600-1-laurent.pinchart@ideasonboard.com>","MIME-Version":"1.0","Subject":"[libcamera-devel] [PATCH v2 06/13] 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>","Cc":"libcamera-devel@lists.libcamera.org","Content-Type":"text/plain; charset=\"us-ascii\"","Content-Transfer-Encoding":"7bit","Errors-To":"libcamera-devel-bounces@lists.libcamera.org","Sender":"\"libcamera-devel\" <libcamera-devel-bounces@lists.libcamera.org>"},"content":"From: Jacopo Mondi <jacopo@jmondi.org>\n\nAdd 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 'orientation' properties from the firmware\ninterface.\n\nSigned-off-by: Jacopo Mondi <jacopo@jmondi.org>\nSigned-off-by: Hans Verkuil <hverkuil-cisco@xs4all.nl>\nSigned-off-by: Mauro Carvalho Chehab <mchehab+huawei@kernel.org>\n\nCommit 344897ef1d9b33e246b64e255d807ca6c053f349 upstream\n\nSigned-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>\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 3bd1888787eb..856045356302 100644\n--- a/drivers/media/v4l2-core/v4l2-fwnode.c\n+++ b/drivers/media/v4l2-core/v4l2-fwnode.c\n@@ -595,6 +595,48 @@ void v4l2_fwnode_put_link(struct v4l2_fwnode_link *link)\n }\n EXPORT_SYMBOL_GPL(v4l2_fwnode_put_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->orientation = V4L2_FWNODE_PROPERTY_UNSET;\n+\tret = fwnode_property_read_u32(fwnode, \"orientation\", &val);\n+\tif (!ret) {\n+\t\tswitch (val) {\n+\t\tcase V4L2_FWNODE_ORIENTATION_FRONT:\n+\t\tcase V4L2_FWNODE_ORIENTATION_BACK:\n+\t\tcase V4L2_FWNODE_ORIENTATION_EXTERNAL:\n+\t\t\tbreak;\n+\t\tdefault:\n+\t\t\tdev_warn(dev, \"Unsupported device orientation: %u\\n\", val);\n+\t\t\treturn -EINVAL;\n+\t\t}\n+\n+\t\tprops->orientation = val;\n+\t\tdev_dbg(dev, \"device orientation: %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) {\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 f6a7bcd13197..7bb8da2092f6 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_PROPERTY_UNSET - 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_orientation - possible device orientation\n+ * @V4L2_FWNODE_ORIENTATION_FRONT: device installed on the front side\n+ * @V4L2_FWNODE_ORIENTATION_BACK: device installed on the back side\n+ * @V4L2_FWNODE_ORIENTATION_EXTERNAL: device externally located\n+ */\n+enum v4l2_fwnode_orientation {\n+\tV4L2_FWNODE_ORIENTATION_FRONT,\n+\tV4L2_FWNODE_ORIENTATION_BACK,\n+\tV4L2_FWNODE_ORIENTATION_EXTERNAL\n+};\n+\n+/**\n+ * struct v4l2_fwnode_device_properties - fwnode device properties\n+ * @orientation: device orientation. See &enum v4l2_fwnode_orientation\n+ * @rotation: device rotation\n+ */\n+struct v4l2_fwnode_device_properties {\n+\tenum v4l2_fwnode_orientation orientation;\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@@ -233,6 +263,23 @@ int v4l2_fwnode_parse_link(struct fwnode_handle *fwnode,\n  */\n void v4l2_fwnode_put_link(struct v4l2_fwnode_link *link);\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","v2","06/13"]}