From patchwork Sun Apr 24 21:08:10 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ivaylo Dimitrov X-Patchwork-Id: 8921781 Return-Path: X-Original-To: patchwork-linux-media@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork1.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.136]) by patchwork1.web.kernel.org (Postfix) with ESMTP id D43029F1C1 for ; Sun, 24 Apr 2016 21:11:23 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id EB72420103 for ; Sun, 24 Apr 2016 21:11:22 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id F3E3B201C7 for ; Sun, 24 Apr 2016 21:11:21 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753403AbcDXVLP (ORCPT ); Sun, 24 Apr 2016 17:11:15 -0400 Received: from mail-wm0-f65.google.com ([74.125.82.65]:33171 "EHLO mail-wm0-f65.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753247AbcDXVKY (ORCPT ); Sun, 24 Apr 2016 17:10:24 -0400 Received: by mail-wm0-f65.google.com with SMTP id r12so17688381wme.0 for ; Sun, 24 Apr 2016 14:10:23 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=wYo0yrFxPpWtXQZ22QMnDIRA9ZawgphImMyepJeYpV8=; b=Nq6FtRbleCvexDD5Kuk8z+YY8eE3H9NCu42WmwADKHiWXvUxNr1uRr97sPE/BwDrT7 Ic6DNuryDy88DN6PvAn84m5zRxl+C53+iwPLc7qkTMAx8T1nX7YZ7TVp50wOMBiedm/q NrarYFe3ARHkTj8/26aYR5QHQbu8ea8F0oJT5K7Q8BmMLHPUaCb4C2hN2YLCNxq12X7b e8z2giV80UcDU98V6T+EMLNY0QSoVuRePK6wXg5yflmkePTNlIaJHbZVj6qd/Bqka0WT lE5a0p6/rLgd9J/05Wf41o+uEUkDvfIsjZdhRIXLNOZhWMtPrwo8CkXtOGESg7+/DpO8 FZiQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=wYo0yrFxPpWtXQZ22QMnDIRA9ZawgphImMyepJeYpV8=; b=AiZJ6mrhcPxRUAFGl7e5KdyPoiA61X6an4caJzC9GXrBOM/Q+kloO+qukyzO5oHr4i hSloDQ2XraPZZ+g9xe5oCaWWYtZajhOfSaPch/nCYuBYMHsij2UHv4BOLy4xUhVEKGoh KivpD5k68GIG7yQjf1KIhrcThfBfZaY+lueEho3CFqkawRh8INssQM4uJewa9PhLIQsz c1RZBm4a8+6kf7Hp9VTua98Q2GxUeq20wPAUyvEJvwm0N+AkGuzbh1vUweD/1L+4ryrs H4XOlnwnlJv71KGk6iLzLKNEqNss/hrZ10iMIa7kyI9asPvNCSzf/YNc+EKktdm5IzM8 msIg== X-Gm-Message-State: AOPr4FXCjTePocqJTCv/BCMz985xJNw7ADqrYEWnMY6olRYdLwtAvLvs6gJUpzILPp8kjg== X-Received: by 10.28.232.212 with SMTP id f81mr9061425wmi.27.1461532223060; Sun, 24 Apr 2016 14:10:23 -0700 (PDT) Received: from localhost.localdomain ([46.249.74.23]) by smtp.gmail.com with ESMTPSA id b2sm15440182wmb.9.2016.04.24.14.10.22 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Sun, 24 Apr 2016 14:10:22 -0700 (PDT) From: Ivaylo Dimitrov To: sakari.ailus@iki.fi Cc: sre@kernel.org, pali.rohar@gmail.com, pavel@ucw.cz, linux-media@vger.kernel.org Subject: [RFC PATCH 10/24] v4l: of: Separate lane parsing from CSI-2 bus parameter parsing Date: Mon, 25 Apr 2016 00:08:10 +0300 Message-Id: <1461532104-24032-11-git-send-email-ivo.g.dimitrov.75@gmail.com> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1461532104-24032-1-git-send-email-ivo.g.dimitrov.75@gmail.com> References: <20160420081427.GZ32125@valkosipuli.retiisi.org.uk> <1461532104-24032-1-git-send-email-ivo.g.dimitrov.75@gmail.com> Sender: linux-media-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-media@vger.kernel.org X-Spam-Status: No, score=-7.8 required=5.0 tests=BAYES_00, DKIM_ADSP_CUSTOM_MED, DKIM_SIGNED, FREEMAIL_FROM, RCVD_IN_DNSWL_HI, RP_MATCHES_RCVD, T_DKIM_INVALID, UNPARSEABLE_RELAY autolearn=unavailable version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP From: Sakari Ailus The CSI-1 will need these as well, separate them into a different function. have_clk_lane and num_data_lanes arguments may be NULL; the CSI-1 bus will have no use for them. Signed-off-by: Sakari Ailus --- drivers/media/v4l2-core/v4l2-of.c | 60 +++++++++++++++++++++++++++++---------- 1 file changed, 45 insertions(+), 15 deletions(-) diff --git a/drivers/media/v4l2-core/v4l2-of.c b/drivers/media/v4l2-core/v4l2-of.c index 5304137..60bbc5f 100644 --- a/drivers/media/v4l2-core/v4l2-of.c +++ b/drivers/media/v4l2-core/v4l2-of.c @@ -25,53 +25,83 @@ enum v4l2_of_bus_type { V4L2_OF_BUS_TYPE_PARALLEL, }; -static int v4l2_of_parse_csi2_bus(const struct device_node *node, - struct v4l2_of_endpoint *endpoint) +static int v4l2_of_parse_lanes(const struct device_node *node, + unsigned char *clock_lane, + bool *have_clk_lane, + unsigned char *data_lanes, + bool *lane_polarities, + unsigned short *__num_data_lanes, + unsigned int max_data_lanes) { - struct v4l2_of_bus_mipi_csi2 *bus = &endpoint->bus.mipi_csi2; struct property *prop; - bool have_clk_lane = false; - unsigned int flags = 0; + unsigned short num_data_lanes = 0; u32 v; prop = of_find_property(node, "data-lanes", NULL); if (prop) { const __be32 *lane = NULL; - unsigned int i; - for (i = 0; i < ARRAY_SIZE(bus->data_lanes); i++) { + for (num_data_lanes = 0; num_data_lanes < max_data_lanes; + num_data_lanes++) { lane = of_prop_next_u32(prop, lane, &v); if (!lane) break; - bus->data_lanes[i] = v; + data_lanes[num_data_lanes] = v; } - bus->num_data_lanes = i; } + if (__num_data_lanes) + *__num_data_lanes = num_data_lanes; prop = of_find_property(node, "lane-polarities", NULL); if (prop) { const __be32 *polarity = NULL; unsigned int i; - for (i = 0; i < ARRAY_SIZE(bus->lane_polarities); i++) { + for (i = 0; i < 1 + max_data_lanes; i++) { polarity = of_prop_next_u32(prop, polarity, &v); if (!polarity) break; - bus->lane_polarities[i] = v; + lane_polarities[i] = v; } - if (i < 1 + bus->num_data_lanes /* clock + data */) { + if (i < 1 + num_data_lanes /* clock + data */) { pr_warn("%s: too few lane-polarities entries (need %u, got %u)\n", - node->full_name, 1 + bus->num_data_lanes, i); + node->full_name, 1 + num_data_lanes, i); return -EINVAL; } } + if (have_clk_lane) + *have_clk_lane = false; + if (!of_property_read_u32(node, "clock-lanes", &v)) { - bus->clock_lane = v; - have_clk_lane = true; + *clock_lane = v; + if (have_clk_lane) + *have_clk_lane = true; } + return 0; +} + +static int v4l2_of_parse_csi2_bus(const struct device_node *node, + struct v4l2_of_endpoint *endpoint) +{ + struct v4l2_of_bus_mipi_csi2 *bus = &endpoint->bus.mipi_csi2; + bool have_clk_lane = false; + unsigned int flags = 0; + int rval; + u32 v; + + rval = v4l2_of_parse_lanes(node, &bus->clock_lane, &have_clk_lane, + bus->data_lanes, bus->lane_polarities, + &bus->num_data_lanes, + ARRAY_SIZE(bus->data_lanes)); + if (rval) + return rval; + + BUILD_BUG_ON(1 + ARRAY_SIZE(bus->data_lanes) + != ARRAY_SIZE(bus->lane_polarities)); + if (of_get_property(node, "clock-noncontinuous", &v)) flags |= V4L2_MBUS_CSI2_NONCONTINUOUS_CLOCK; else if (have_clk_lane || bus->num_data_lanes > 0)