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: 34040 Received: from mail.tu-berlin.de ([130.149.7.33]) by www.linuxtv.org with esmtp (Exim 4.84_2) (envelope-from ) id 1auRJW-0007JN-At; Sun, 24 Apr 2016 21:11:34 +0000 X-tubIT-Incoming-IP: 209.132.180.67 Received: from vger.kernel.org ([209.132.180.67]) by mail.tu-berlin.de (exim-4.76/mailfrontend-5) with esmtp id 1auRJU-0001OP-7T; Sun, 24 Apr 2016 23:11:34 +0200 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753403AbcDXVLP (ORCPT + 1 other); 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-PMX-Version: 6.0.0.2142326, Antispam-Engine: 2.7.2.2107409, Antispam-Data: 2016.4.24.210315 X-PMX-Spam: Gauge=IIIIIIIII, Probability=9%, Report=' FORGED_FROM_GMAIL 0.1, MULTIPLE_RCPTS 0.1, HTML_00_01 0.05, HTML_00_10 0.05, BODY_SIZE_3000_3999 0, BODY_SIZE_5000_LESS 0, BODY_SIZE_7000_LESS 0, DKIM_SIGNATURE 0, NO_URI_HTTPS 0, REFERENCES 0, SINGLE_URI_IN_BODY 0, URI_ENDS_IN_HTML 0, __ANY_URI 0, __CP_URI_IN_BODY 0, __DATE_TZ_RU 0, __FRAUD_WEBMAIL 0, __FRAUD_WEBMAIL_FROM 0, __FROM_GMAIL 0, __HAS_FROM 0, __HAS_MSGID 0, __HAS_X_MAILER 0, __HAS_X_MAILING_LIST 0, __IN_REP_TO 0, __MIME_TEXT_ONLY 0, __MULTIPLE_RCPTS_CC_X2 0, __PHISH_SPEAR_STRUCTURE_1 0, __REFERENCES 0, __SANE_MSGID 0, __SINGLE_URI_TEXT 0, __SUBJ_ALPHA_END 0, __TO_MALFORMED_2 0, __TO_NO_NAME 0, __URI_IN_BODY 0, __URI_NO_WWW 0, __URI_NS , __URI_WITH_PATH 0, __YOUTUBE_RCVD 0' 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)