From patchwork Wed Sep 12 21:29:29 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sakari Ailus X-Patchwork-Id: 10598393 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id DE8E314F9 for ; Wed, 12 Sep 2018 21:30:37 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id CF1612ACA2 for ; Wed, 12 Sep 2018 21:30:37 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id C350B2ACAB; Wed, 12 Sep 2018 21:30:37 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-5.2 required=2.0 tests=BAYES_00,MAILING_LIST_MULTI, RCVD_IN_DNSWL_MED autolearn=ham version=3.3.1 Received: from gabe.freedesktop.org (gabe.freedesktop.org [131.252.210.177]) (using TLSv1.2 with cipher DHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 637062ACA2 for ; Wed, 12 Sep 2018 21:30:37 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 1540C6E523; Wed, 12 Sep 2018 21:30:10 +0000 (UTC) X-Original-To: dri-devel@lists.freedesktop.org Delivered-To: dri-devel@lists.freedesktop.org Received: from hillosipuli.retiisi.org.uk (hillosipuli.retiisi.org.uk [IPv6:2001:1bc8:1a6:d3d5::81:2]) by gabe.freedesktop.org (Postfix) with ESMTPS id 284BE6E4DF for ; Wed, 12 Sep 2018 21:29:49 +0000 (UTC) Received: from lanttu.localdomain (lanttu-e.localdomain [192.168.1.64]) by hillosipuli.retiisi.org.uk (Postfix) with ESMTP id 75577634C91; Thu, 13 Sep 2018 00:29:43 +0300 (EEST) From: Sakari Ailus To: linux-media@vger.kernel.org Subject: [PATCH v3 10/23] v4l: fwnode: Read lane inversion information despite lane numbering Date: Thu, 13 Sep 2018 00:29:29 +0300 Message-Id: <20180912212942.19641-11-sakari.ailus@linux.intel.com> X-Mailer: git-send-email 2.11.0 In-Reply-To: <20180912212942.19641-1-sakari.ailus@linux.intel.com> References: <20180912212942.19641-1-sakari.ailus@linux.intel.com> X-BeenThere: dri-devel@lists.freedesktop.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: Direct Rendering Infrastructure - Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: devicetree@vger.kernel.org, jacopo@jmondi.org, dri-devel@lists.freedesktop.org, slongerbeam@gmail.com, niklas.soderlund@ragnatech.se MIME-Version: 1.0 Errors-To: dri-devel-bounces@lists.freedesktop.org Sender: "dri-devel" X-Virus-Scanned: ClamAV using ClamSMTP Read the lane inversion independently of whether the "data-lanes" property exists. This makes sense since the caller may pass the number of lanes as the default configuration while the lane inversion configuration may still be available in firmware. Signed-off-by: Sakari Ailus Tested-by: Steve Longerbeam --- drivers/media/v4l2-core/v4l2-fwnode.c | 65 +++++++++++++++++++---------------- 1 file changed, 35 insertions(+), 30 deletions(-) diff --git a/drivers/media/v4l2-core/v4l2-fwnode.c b/drivers/media/v4l2-core/v4l2-fwnode.c index 74c2f4e03e52..cb0b12eefe7f 100644 --- a/drivers/media/v4l2-core/v4l2-fwnode.c +++ b/drivers/media/v4l2-core/v4l2-fwnode.c @@ -43,26 +43,31 @@ enum v4l2_fwnode_bus_type { }; static int v4l2_fwnode_endpoint_parse_csi2_bus(struct fwnode_handle *fwnode, - struct v4l2_fwnode_endpoint *vep) + struct v4l2_fwnode_endpoint *vep, + enum v4l2_fwnode_bus_type bus_type) { struct v4l2_fwnode_bus_mipi_csi2 *bus = &vep->bus.mipi_csi2; bool have_clk_lane = false; unsigned int flags = 0, lanes_used = 0; + u32 array[1 + V4L2_FWNODE_CSI2_MAX_DATA_LANES]; + unsigned int num_data_lanes = 0; unsigned int i; u32 v; int rval; + if (bus_type == V4L2_FWNODE_BUS_TYPE_CSI2_DPHY) + num_data_lanes = min_t(u32, bus->num_data_lanes, + V4L2_FWNODE_CSI2_MAX_DATA_LANES); + rval = fwnode_property_read_u32_array(fwnode, "data-lanes", NULL, 0); if (rval > 0) { - u32 array[1 + V4L2_FWNODE_CSI2_MAX_DATA_LANES]; - - bus->num_data_lanes = + num_data_lanes = min_t(int, V4L2_FWNODE_CSI2_MAX_DATA_LANES, rval); fwnode_property_read_u32_array(fwnode, "data-lanes", array, - bus->num_data_lanes); + num_data_lanes); - for (i = 0; i < bus->num_data_lanes; i++) { + for (i = 0; i < num_data_lanes; i++) { if (lanes_used & BIT(array[i])) pr_warn("duplicated lane %u in data-lanes\n", array[i]); @@ -71,30 +76,27 @@ static int v4l2_fwnode_endpoint_parse_csi2_bus(struct fwnode_handle *fwnode, bus->data_lanes[i] = array[i]; pr_debug("lane %u position %u\n", i, array[i]); } + } - rval = fwnode_property_read_u32_array(fwnode, - "lane-polarities", NULL, - 0); - if (rval > 0) { - if (rval != 1 + bus->num_data_lanes /* clock+data */) { - pr_warn("invalid number of lane-polarities entries (need %u, got %u)\n", - 1 + bus->num_data_lanes, rval); - return -EINVAL; - } + rval = fwnode_property_read_u32_array(fwnode, "lane-polarities", NULL, + 0); + if (rval > 0) { + if (rval != 1 + num_data_lanes /* clock+data */) { + pr_warn("invalid number of lane-polarities entries (need %u, got %u)\n", + 1 + num_data_lanes, rval); + return -EINVAL; + } - fwnode_property_read_u32_array(fwnode, - "lane-polarities", array, - 1 + bus->num_data_lanes); + fwnode_property_read_u32_array(fwnode, "lane-polarities", array, + 1 + num_data_lanes); - for (i = 0; i < 1 + bus->num_data_lanes; i++) { - bus->lane_polarities[i] = array[i]; - pr_debug("lane %u polarity %sinverted", - i, array[i] ? "" : "not "); - } - } else { - pr_debug("no lane polarities defined, assuming not inverted\n"); + for (i = 0; i < 1 + num_data_lanes; i++) { + bus->lane_polarities[i] = array[i]; + pr_debug("lane %u polarity %sinverted", + i, array[i] ? "" : "not "); } - + } else { + pr_debug("no lane polarities defined, assuming not inverted\n"); } if (!fwnode_property_read_u32(fwnode, "clock-lanes", &v)) { @@ -114,10 +116,11 @@ static int v4l2_fwnode_endpoint_parse_csi2_bus(struct fwnode_handle *fwnode, flags |= V4L2_MBUS_CSI2_CONTINUOUS_CLOCK; } - if (lanes_used || have_clk_lane || - (flags & ~V4L2_MBUS_CSI2_CONTINUOUS_CLOCK)) { + if (bus_type == V4L2_FWNODE_BUS_TYPE_CSI2_DPHY || lanes_used || + have_clk_lane || (flags & ~V4L2_MBUS_CSI2_CONTINUOUS_CLOCK)) { bus->flags = flags; vep->bus_type = V4L2_MBUS_CSI2_DPHY; + bus->num_data_lanes = num_data_lanes; } return 0; @@ -273,7 +276,8 @@ static int __v4l2_fwnode_endpoint_parse(struct fwnode_handle *fwnode, switch (bus_type) { case V4L2_FWNODE_BUS_TYPE_GUESS: - rval = v4l2_fwnode_endpoint_parse_csi2_bus(fwnode, vep); + rval = v4l2_fwnode_endpoint_parse_csi2_bus(fwnode, vep, + bus_type); if (rval) return rval; @@ -289,7 +293,8 @@ static int __v4l2_fwnode_endpoint_parse(struct fwnode_handle *fwnode, break; case V4L2_FWNODE_BUS_TYPE_CSI2_DPHY: vep->bus_type = V4L2_MBUS_CSI2_DPHY; - rval = v4l2_fwnode_endpoint_parse_csi2_bus(fwnode, vep); + rval = v4l2_fwnode_endpoint_parse_csi2_bus(fwnode, vep, + bus_type); if (rval) return rval;