From patchwork Wed Sep 12 21:29:32 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sakari Ailus X-Patchwork-Id: 10598395 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 5EFAF14F9 for ; Wed, 12 Sep 2018 21:30:42 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 4F6642ACA2 for ; Wed, 12 Sep 2018 21:30:42 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 439E12ACAB; Wed, 12 Sep 2018 21:30:42 +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 DEC212ACA2 for ; Wed, 12 Sep 2018 21:30:41 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id A02B76E56D; 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 7109B6E4FF 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 B0266634C94; Thu, 13 Sep 2018 00:29:43 +0300 (EEST) From: Sakari Ailus To: linux-media@vger.kernel.org Subject: [PATCH v3 13/23] v4l: fwnode: Support default CSI-2 lane mapping for drivers Date: Thu, 13 Sep 2018 00:29:32 +0300 Message-Id: <20180912212942.19641-14-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 Most hardware doesn't support re-mapping of the CSI-2 lanes. Especially sensor drivers have a default number of lanes. Instead of requiring the caller (the driver) to provide such a unit mapping, provide one if no mapping is configured. Signed-off-by: Sakari Ailus Tested-by: Steve Longerbeam --- drivers/media/v4l2-core/v4l2-fwnode.c | 60 +++++++++++++++++++++++++++-------- 1 file changed, 46 insertions(+), 14 deletions(-) diff --git a/drivers/media/v4l2-core/v4l2-fwnode.c b/drivers/media/v4l2-core/v4l2-fwnode.c index 64c23cbf6f0b..dbe0ada74c63 100644 --- a/drivers/media/v4l2-core/v4l2-fwnode.c +++ b/drivers/media/v4l2-core/v4l2-fwnode.c @@ -47,20 +47,35 @@ static int v4l2_fwnode_endpoint_parse_csi2_bus(struct fwnode_handle *fwnode, enum v4l2_fwnode_bus_type bus_type) { struct v4l2_fwnode_bus_mipi_csi2 *bus = &vep->bus.mipi_csi2; - bool have_clk_lane = false, have_lane_polarities = false; + bool have_clk_lane = false, have_data_lanes = false, + have_lane_polarities = false; unsigned int flags = 0, lanes_used = 0; u32 array[1 + V4L2_FWNODE_CSI2_MAX_DATA_LANES]; + u32 clock_lane = 0; unsigned int num_data_lanes = 0; + bool use_default_lane_mapping = false; unsigned int i; u32 v; int rval; if (bus_type == V4L2_FWNODE_BUS_TYPE_CSI2_DPHY) { + use_default_lane_mapping = true; + num_data_lanes = min_t(u32, bus->num_data_lanes, V4L2_FWNODE_CSI2_MAX_DATA_LANES); - for (i = 0; i < num_data_lanes; i++) + clock_lane = bus->clock_lane; + if (clock_lane) + use_default_lane_mapping = false; + + for (i = 0; i < num_data_lanes; i++) { array[i] = bus->data_lanes[i]; + if (array[i]) + use_default_lane_mapping = false; + } + + if (use_default_lane_mapping) + pr_debug("using default lane mapping\n"); } rval = fwnode_property_read_u32_array(fwnode, "data-lanes", NULL, 0); @@ -70,15 +85,21 @@ static int v4l2_fwnode_endpoint_parse_csi2_bus(struct fwnode_handle *fwnode, fwnode_property_read_u32_array(fwnode, "data-lanes", array, num_data_lanes); + + have_data_lanes = true; } 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]); + if (lanes_used & BIT(array[i])) { + if (have_data_lanes || !use_default_lane_mapping) + pr_warn("duplicated lane %u in data-lanes, using defaults\n", + array[i]); + use_default_lane_mapping = true; + } lanes_used |= BIT(array[i]); - pr_debug("lane %u position %u\n", i, array[i]); + if (have_data_lanes) + pr_debug("lane %u position %u\n", i, array[i]); } rval = fwnode_property_read_u32_array(fwnode, "lane-polarities", NULL, @@ -94,13 +115,16 @@ static int v4l2_fwnode_endpoint_parse_csi2_bus(struct fwnode_handle *fwnode, } if (!fwnode_property_read_u32(fwnode, "clock-lanes", &v)) { - if (lanes_used & BIT(v)) - pr_warn("duplicated lane %u in clock-lanes\n", v); - lanes_used |= BIT(v); - - bus->clock_lane = v; - have_clk_lane = true; + clock_lane = v; pr_debug("clock lane position %u\n", v); + have_clk_lane = true; + } + + if (lanes_used & BIT(clock_lane)) { + if (have_clk_lane || !use_default_lane_mapping) + pr_warn("duplicated lane %u in clock-lanes, using defaults\n", + v); + use_default_lane_mapping = true; } if (fwnode_property_present(fwnode, "clock-noncontinuous")) { @@ -115,8 +139,16 @@ static int v4l2_fwnode_endpoint_parse_csi2_bus(struct fwnode_handle *fwnode, bus->flags = flags; vep->bus_type = V4L2_MBUS_CSI2_DPHY; bus->num_data_lanes = num_data_lanes; - for (i = 0; i < num_data_lanes; i++) - bus->data_lanes[i] = array[i]; + + if (use_default_lane_mapping) { + bus->clock_lane = 0; + for (i = 0; i < num_data_lanes; i++) + bus->data_lanes[i] = 1 + i; + } else { + bus->clock_lane = clock_lane; + for (i = 0; i < num_data_lanes; i++) + bus->data_lanes[i] = array[i]; + } if (have_lane_polarities) { fwnode_property_read_u32_array(fwnode,