From patchwork Fri Feb 27 12:24:42 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sebastian Hesselbarth X-Patchwork-Id: 5900421 Return-Path: X-Original-To: patchwork-linux-arm@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 C99C49F269 for ; Fri, 27 Feb 2015 12:30:21 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id A30A5202EC for ; Fri, 27 Feb 2015 12:30:20 +0000 (UTC) Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.9]) (using TLSv1.2 with cipher DHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 8DAFC202E9 for ; Fri, 27 Feb 2015 12:30:19 +0000 (UTC) Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.80.1 #2 (Red Hat Linux)) id 1YRK1N-0007BY-TF; Fri, 27 Feb 2015 12:27:57 +0000 Received: from mail-wg0-x232.google.com ([2a00:1450:400c:c00::232]) by bombadil.infradead.org with esmtps (Exim 4.80.1 #2 (Red Hat Linux)) id 1YRJyn-0004PO-HJ for linux-arm-kernel@lists.infradead.org; Fri, 27 Feb 2015 12:25:23 +0000 Received: by wggy19 with SMTP id y19so19999257wgg.10 for ; Fri, 27 Feb 2015 04:24:53 -0800 (PST) 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=Pvu5/1rS5HzVGOyCMox5n9uu0wAEV911jkU5XnO9reo=; b=FeSmtrmpFS4QtwVfUfgbYN9XMgRepJNBTDAGInGHQ/AAxJWEzEuK3FaCHiT/N8BpLI z//dHrkMVmlcGo2JEfbqYVi3r2kWu8orW/tACEMHlODa9sfS94xNPX7KzccSe6BbXKNC wS6LHMgJoVtwh1MSo4bhr5xBS26nIcdSbm8O3QPCEoEwGS+wkeDiUeLwsrOZ8SlD60br npGJhg9mNkysaaG447gDNt0P+VS5x1Vx7BVf02tzk2EqUUmR5HT3H/NeIqZBRJqDhSJ8 5xGgArNXWYF0BrZ2EyTY1+sxIJTTbA8ohykC3sfLBSKJdlfIWQMvwaIT0+wGN6OjqGNg CHqA== X-Received: by 10.194.134.68 with SMTP id pi4mr27373140wjb.101.1425039893701; Fri, 27 Feb 2015 04:24:53 -0800 (PST) Received: from topkick.lan (f051102214.adsl.alicedsl.de. [78.51.102.214]) by mx.google.com with ESMTPSA id q6sm2603973wix.13.2015.02.27.04.24.51 (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 27 Feb 2015 04:24:52 -0800 (PST) From: Sebastian Hesselbarth To: Sebastian Hesselbarth Subject: [PATCH v2 1/4] i2c: mux-pinctrl: Rework to honor disabled child nodes Date: Fri, 27 Feb 2015 13:24:42 +0100 Message-Id: <1425039885-5137-2-git-send-email-sebastian.hesselbarth@gmail.com> In-Reply-To: <1425039885-5137-1-git-send-email-sebastian.hesselbarth@gmail.com> References: <1424199129-22099-1-git-send-email-sebastian.hesselbarth@gmail.com> <1425039885-5137-1-git-send-email-sebastian.hesselbarth@gmail.com> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20150227_042517_960159_723E7320 X-CRM114-Status: GOOD ( 19.86 ) X-Spam-Score: -0.8 (/) Cc: Andrew Lunn , Jason Cooper , Stephen Warren , Wolfram Sang , linux-kernel@vger.kernel.org, devicetree@vger.kernel.org, Gabriel Dobato , linux-i2c@vger.kernel.org, Gregory Clement , linux-arm-kernel@lists.infradead.org X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.18-1 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org X-Spam-Status: No, score=-4.1 required=5.0 tests=BAYES_00, DKIM_ADSP_CUSTOM_MED, DKIM_SIGNED, FREEMAIL_FROM, RCVD_IN_DNSWL_MED, T_DKIM_INVALID, T_RP_MATCHES_RCVD, 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 I2C mux pinctrl driver currently determines the number of sub-busses by counting available pinctrl-names. Unfortunately, this requires each incarnation of the devicetree node with different available sub-busses to be rewritten. This patch reworks i2c-mux-pinctrl driver to count the number of available sub-nodes instead. The rework should be compatible to the old way of probing for sub-busses and additionally allows to disable unused sub-busses with standard DT property status = "disabled". This also amends the corresponding devicetree binding documentation to reflect the new functionality to disable unused sub-nodes. While at it, also fix two references to binding documentation files that miss an "i2c-" prefix. Signed-off-by: Sebastian Hesselbarth Tested-by: Stephen Warren --- Cc: Jason Cooper Cc: Andrew Lunn Cc: Gregory Clement Cc: Gabriel Dobato Cc: Wolfram Sang Cc: Stephen Warren Cc: linux-i2c@vger.kernel.org Cc: devicetree@vger.kernel.org Cc: linux-arm-kernel@lists.infradead.org Cc: linux-kernel@vger.kernel.org --- .../devicetree/bindings/i2c/i2c-mux-pinctrl.txt | 25 ++++---- drivers/i2c/muxes/i2c-mux-pinctrl.c | 70 ++++++++++++++-------- 2 files changed, 59 insertions(+), 36 deletions(-) diff --git a/Documentation/devicetree/bindings/i2c/i2c-mux-pinctrl.txt b/Documentation/devicetree/bindings/i2c/i2c-mux-pinctrl.txt index ae8af1694e95..40cf6d86f935 100644 --- a/Documentation/devicetree/bindings/i2c/i2c-mux-pinctrl.txt +++ b/Documentation/devicetree/bindings/i2c/i2c-mux-pinctrl.txt @@ -28,21 +28,21 @@ Also required are: * Standard pinctrl properties that specify the pin mux state for each child bus. See ../pinctrl/pinctrl-bindings.txt. -* Standard I2C mux properties. See mux.txt in this directory. +* Standard I2C mux properties. See i2c-mux.txt in this directory. -* I2C child bus nodes. See mux.txt in this directory. +* I2C child bus nodes. See i2c-mux.txt in this directory. -For each named state defined in the pinctrl-names property, an I2C child bus -will be created. I2C child bus numbers are assigned based on the index into -the pinctrl-names property. +For each enabled child node an I2C child bus will be created. I2C child bus +numbers are assigned based on the order of child nodes. -The only exception is that no bus will be created for a state named "idle". If -such a state is defined, it must be the last entry in pinctrl-names. For -example: +There must be a corresponding pinctrl-names entry for each enabled child +node at the position of the child node's "reg" property. Also, there can be +an idle pinctrl state defined at the end of possible pinctrl states. If such +a state is defined, it must be the last entry in pinctrl-names. For example: - pinctrl-names = "ddc", "pta", "idle" -> ddc = bus 0, pta = bus 1 - pinctrl-names = "ddc", "idle", "pta" -> Invalid ("idle" not last) - pinctrl-names = "idle", "ddc", "pta" -> Invalid ("idle" not last) + pinctrl-names = "ddc", "pta", "idle" -> ddc = bus 0, pta = bus 1 + pinctrl-names = "ddc", "idle", "pta" -> Invalid ("idle" not last) + pinctrl-names = "idle", "ddc", "pta" -> Invalid ("idle" not last) Whenever an access is made to a device on a child bus, the relevant pinctrl state will be programmed into hardware. @@ -68,6 +68,7 @@ Example: pinctrl-1 = <&state_i2cmux_pta>; pinctrl-2 = <&state_i2cmux_idle>; + /* Enabled child bus 0 */ i2c@0 { reg = <0>; #address-cells = <1>; @@ -79,10 +80,12 @@ Example: }; }; + /* Disabled child bus 1 */ i2c@1 { reg = <1>; #address-cells = <1>; #size-cells = <0>; + status = "disabled"; eeprom { compatible = "eeprom"; diff --git a/drivers/i2c/muxes/i2c-mux-pinctrl.c b/drivers/i2c/muxes/i2c-mux-pinctrl.c index b48378c4b40d..033dacfabfdf 100644 --- a/drivers/i2c/muxes/i2c-mux-pinctrl.c +++ b/drivers/i2c/muxes/i2c-mux-pinctrl.c @@ -56,9 +56,12 @@ static int i2c_mux_pinctrl_parse_dt(struct i2c_mux_pinctrl *mux, struct platform_device *pdev) { struct device_node *np = pdev->dev.of_node; - int num_names, i, ret; + struct device_node *child; + struct property *prop; + int num_names, num_children, ret; struct device_node *adapter_np; struct i2c_adapter *adapter; + const char *state; if (!np) return 0; @@ -77,32 +80,16 @@ static int i2c_mux_pinctrl_parse_dt(struct i2c_mux_pinctrl *mux, return num_names; } - mux->pdata->pinctrl_states = devm_kzalloc(&pdev->dev, - sizeof(*mux->pdata->pinctrl_states) * num_names, - GFP_KERNEL); - if (!mux->pdata->pinctrl_states) { - dev_err(mux->dev, "Cannot allocate pinctrl_states\n"); - return -ENOMEM; + num_children = of_get_available_child_count(np); + if (num_children < 0) { + dev_err(mux->dev, "Unable to count available children: %d\n", + num_children); + return num_children; } - for (i = 0; i < num_names; i++) { - ret = of_property_read_string_index(np, "pinctrl-names", i, - &mux->pdata->pinctrl_states[mux->pdata->bus_count]); - if (ret < 0) { - dev_err(mux->dev, "Cannot parse pinctrl-names: %d\n", - ret); - return ret; - } - if (!strcmp(mux->pdata->pinctrl_states[mux->pdata->bus_count], - "idle")) { - if (i != num_names - 1) { - dev_err(mux->dev, "idle state must be last\n"); - return -EINVAL; - } - mux->pdata->pinctrl_state_idle = "idle"; - } else { - mux->pdata->bus_count++; - } + if (num_names < num_children) { + dev_err(mux->dev, "Found less pinctrl states than children\n"); + return -EINVAL; } adapter_np = of_parse_phandle(np, "i2c-parent", 0); @@ -118,6 +105,39 @@ static int i2c_mux_pinctrl_parse_dt(struct i2c_mux_pinctrl *mux, mux->pdata->parent_bus_num = i2c_adapter_id(adapter); put_device(&adapter->dev); + mux->pdata->pinctrl_states = devm_kzalloc(&pdev->dev, + sizeof(*mux->pdata->pinctrl_states) * num_children, + GFP_KERNEL); + if (!mux->pdata->pinctrl_states) { + dev_err(mux->dev, "Cannot allocate pinctrl_states\n"); + return -ENOMEM; + } + + of_property_for_each_string(np, "pinctrl-names", prop, state) + if (!strcmp(state, "idle")) + mux->pdata->pinctrl_state_idle = "idle"; + + for_each_available_child_of_node(np, child) { + u32 reg; + + ret = of_property_read_u32(child, "reg", ®); + if (ret < 0) { + dev_err(mux->dev, "Missing reg property for child node: %d\n", + ret); + return ret; + } + + ret = of_property_read_string_index(np, + "pinctrl-names", reg, &state); + if (ret < 0) { + dev_err(mux->dev, "Cannot parse pinctrl-names for mux %d: %d\n", + reg, ret); + return ret; + } + + mux->pdata->pinctrl_states[mux->pdata->bus_count++] = state; + } + return 0; } #else