From patchwork Tue Jan 31 12:08:31 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Niklas_S=C3=B6derlund?= X-Patchwork-Id: 9547005 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 2B285604A0 for ; Tue, 31 Jan 2017 12:08:56 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 1C58F28236 for ; Tue, 31 Jan 2017 12:08:56 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 1031328338; Tue, 31 Jan 2017 12:08:56 +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=-6.9 required=2.0 tests=BAYES_00,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id B8DF228236 for ; Tue, 31 Jan 2017 12:08:55 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751776AbdAaMIy (ORCPT ); Tue, 31 Jan 2017 07:08:54 -0500 Received: from smtp-4.sys.kth.se ([130.237.48.193]:49322 "EHLO smtp-4.sys.kth.se" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751042AbdAaMIx (ORCPT ); Tue, 31 Jan 2017 07:08:53 -0500 Received: from smtp-4.sys.kth.se (localhost.localdomain [127.0.0.1]) by smtp-4.sys.kth.se (Postfix) with ESMTP id 1E4412664; Tue, 31 Jan 2017 13:08:51 +0100 (CET) X-Virus-Scanned: by amavisd-new at kth.se Received: from smtp-4.sys.kth.se ([127.0.0.1]) by smtp-4.sys.kth.se (smtp-4.sys.kth.se [127.0.0.1]) (amavisd-new, port 10024) with LMTP id jaMb4Yb4ft6M; Tue, 31 Jan 2017 13:08:50 +0100 (CET) X-KTH-Auth: niso [89.233.230.99] X-KTH-mail-from: niklas.soderlund+renesas@ragnatech.se Received: from bismarck.berto.se (unknown [89.233.230.99]) by smtp-4.sys.kth.se (Postfix) with ESMTPSA id 865BCA4E; Tue, 31 Jan 2017 13:08:46 +0100 (CET) From: =?UTF-8?q?Niklas=20S=C3=B6derlund?= To: Mauro Carvalho Chehab , Laurent Pinchart Cc: Geert Uytterhoeven , linux-media@vger.kernel.org, linux-renesas-soc@vger.kernel.org, =?UTF-8?q?Niklas=20S=C3=B6derlund?= Subject: [PATCHv2] v4l: of: check for unique lanes in data-lanes and clock-lanes Date: Tue, 31 Jan 2017 13:08:31 +0100 Message-Id: <20170131120831.11283-1-niklas.soderlund+renesas@ragnatech.se> X-Mailer: git-send-email 2.11.0 MIME-Version: 1.0 Sender: linux-media-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-media@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP All lanes in data-lanes and clock-lanes properties should be unique. Add a check for this in v4l2_of_parse_csi_bus() and print a warning if duplicated lanes are found. Signed-off-by: Niklas Söderlund Acked-by: Sakari Ailus Reviewed-by: Laurent Pinchart --- Changes since v1: - Do not return -EINVAL if a duplicate is found. Sakari pointed out there are drivers where the number of lanes matter but not the actual lane numbers. Updated commit message to highlight that only a warning is printed. - Switched to a bitmask to track lanes used instead of a nested loop, thanks Laurent for the suggestion. drivers/media/v4l2-core/v4l2-of.c | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/drivers/media/v4l2-core/v4l2-of.c b/drivers/media/v4l2-core/v4l2-of.c index 93b33681776ca427..4f59f442dd0a64c9 100644 --- a/drivers/media/v4l2-core/v4l2-of.c +++ b/drivers/media/v4l2-core/v4l2-of.c @@ -26,7 +26,7 @@ static int v4l2_of_parse_csi_bus(const struct device_node *node, struct v4l2_of_bus_mipi_csi2 *bus = &endpoint->bus.mipi_csi2; struct property *prop; bool have_clk_lane = false; - unsigned int flags = 0; + unsigned int flags = 0, lanes_used = 0; u32 v; prop = of_find_property(node, "data-lanes", NULL); @@ -38,6 +38,12 @@ static int v4l2_of_parse_csi_bus(const struct device_node *node, lane = of_prop_next_u32(prop, lane, &v); if (!lane) break; + + if (lanes_used & BIT(v)) + pr_warn("%s: duplicated lane %u in data-lanes\n", + node->full_name, v); + lanes_used |= BIT(v); + bus->data_lanes[i] = v; } bus->num_data_lanes = i; @@ -63,6 +69,11 @@ static int v4l2_of_parse_csi_bus(const struct device_node *node, } if (!of_property_read_u32(node, "clock-lanes", &v)) { + if (lanes_used & BIT(v)) + pr_warn("%s: duplicated lane %u in clock-lanes\n", + node->full_name, v); + lanes_used |= BIT(v); + bus->clock_lane = v; have_clk_lane = true; }