From patchwork Thu Jun 20 17:12:53 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Ithamar R. Adema" X-Patchwork-Id: 2757381 Return-Path: X-Original-To: patchwork-linux-arm@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork2.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.19.201]) by patchwork2.web.kernel.org (Postfix) with ESMTP id 74E30C0AB1 for ; Thu, 20 Jun 2013 17:13:47 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 3DBED20440 for ; Thu, 20 Jun 2013 17:13:46 +0000 (UTC) Received: from casper.infradead.org (casper.infradead.org [85.118.1.10]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 848E22042F for ; Thu, 20 Jun 2013 17:13:44 +0000 (UTC) Received: from merlin.infradead.org ([2001:4978:20e::2]) by casper.infradead.org with esmtps (Exim 4.80.1 #2 (Red Hat Linux)) id 1UpiPv-00044H-IU; Thu, 20 Jun 2013 17:13:04 +0000 Received: from localhost ([::1] helo=merlin.infradead.org) by merlin.infradead.org with esmtp (Exim 4.80.1 #2 (Red Hat Linux)) id 1UpiPi-0004gQ-BQ; Thu, 20 Jun 2013 17:12:50 +0000 Received: from mail-ea0-x22e.google.com ([2a00:1450:4013:c01::22e]) by merlin.infradead.org with esmtps (Exim 4.80.1 #2 (Red Hat Linux)) id 1UpiPf-0004ev-Gp for linux-arm-kernel@lists.infradead.org; Thu, 20 Jun 2013 17:12:48 +0000 Received: by mail-ea0-f174.google.com with SMTP id o10so4049911eaj.5 for ; Thu, 20 Jun 2013 10:12:23 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20120113; h=from:to:cc:subject:date:message-id:x-mailer:x-gm-message-state; bh=GCFN17Oy4XTUlpWW5etHmt4z3BvmnRCG1RsQh5OJ25U=; b=gjiQ76lh5LzFM1rTPnjHXtHBAc5v3f/4KLsnD3x0ymov4H7ZWOcRLPTm7K0/iIhnx8 R94phR0cAkbXozkhEJmiwfVqa1rjGc4gBESrHvp41fpWPnEW4L8vcLp1V9M6DIbjgjGu 1v51oUk/sEEt9pzTNyum9gm1iY5IaB7tdSdSSVY/0JP7pnlUTX9ySHWEFgxt/H6tLK0m SXYUlHplzyT+pSH6l454XsAxi6WpPN+wvEzGLXjJMorCKPOwuc02dM4YiG2B8Zvjduld eWsx1xXK+eabGHZrGsDJe+8xOsVUV+h8D3Hj/FxsYwPVyHgk03qg254M8GqkmHi1UKF9 cqEA== X-Received: by 10.15.42.72 with SMTP id t48mr8601099eev.105.1371748343716; Thu, 20 Jun 2013 10:12:23 -0700 (PDT) Received: from localhost.localdomain (f222020.upc-f.chello.nl. [80.56.222.20]) by mx.google.com with ESMTPSA id bj46sm1729811eeb.13.2013.06.20.10.12.21 for (version=TLSv1.1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Thu, 20 Jun 2013 10:12:22 -0700 (PDT) From: "Ithamar R. Adema" To: Maxime Ripard , Linux ARM Kernel Subject: [PATCH] pinctrl-sunxi: fix pin attribute handling. Date: Thu, 20 Jun 2013 19:12:53 +0200 Message-Id: <1371748373-10519-1-git-send-email-ithamar@upgrade-android.com> X-Mailer: git-send-email 1.7.9.5 X-Gm-Message-State: ALoCoQmgsONiYwlUXUiS7SAFRRugd1UTXO0lOhHXv7jrqeDnfzsGrBz2OZ3T/uecH9MDDLxdkfaT X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20130620_131247_683231_F8B68DE1 X-CRM114-Status: GOOD ( 13.40 ) X-Spam-Score: -1.9 (-) Cc: "Ithamar R. Adema" X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.15 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=-5.5 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_MED, 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 From: "Ithamar R. Adema" The configuration of pull up/down on pins does not allow disabling of the pins. PIN_CONFIG_BIAS_PULL_UP and PIN_CONFIG_BIAS_PULL_DOWN take an argument of 1 or 0 to specify enabling or disabling of the pull up/down, but the code does not take this into account. Also, default the pullup/downs to disabled if not specified, so no old state from e.g. the bootloader is still active after reconfiguration by the kernel. Signed-off-by: Ithamar R. Adema --- drivers/pinctrl/pinctrl-sunxi.c | 39 +++++++++++++++++---------------------- 1 file changed, 17 insertions(+), 22 deletions(-) diff --git a/drivers/pinctrl/pinctrl-sunxi.c b/drivers/pinctrl/pinctrl-sunxi.c index b7d8c89..a652061 100644 --- a/drivers/pinctrl/pinctrl-sunxi.c +++ b/drivers/pinctrl/pinctrl-sunxi.c @@ -1466,7 +1466,7 @@ static int sunxi_pctrl_dt_node_to_map(struct pinctrl_dev *pctldev, of_property_for_each_string(node, "allwinner,pins", prop, group) { struct sunxi_pinctrl_group *grp = sunxi_pinctrl_find_group_by_name(pctl, group); - int j = 0, configlen = 0; + u16 strength; if (!grp) { dev_err(pctl->dev, "unknown pin %s", group); @@ -1490,31 +1490,23 @@ static int sunxi_pctrl_dt_node_to_map(struct pinctrl_dev *pctldev, (*map)[i].type = PIN_MAP_TYPE_CONFIGS_GROUP; (*map)[i].data.configs.group_or_pin = group; - if (of_find_property(node, "allwinner,drive", NULL)) - configlen++; - if (of_find_property(node, "allwinner,pull", NULL)) - configlen++; - - pinconfig = kzalloc(configlen * sizeof(*pinconfig), GFP_KERNEL); + pinconfig = kzalloc(3 * sizeof(*pinconfig), GFP_KERNEL); + strength = 0; if (!of_property_read_u32(node, "allwinner,drive", &val)) { - u16 strength = (val + 1) * 10; - pinconfig[j++] = - pinconf_to_config_packed(PIN_CONFIG_DRIVE_STRENGTH, - strength); + strength = (val + 1) * 10; } + pinconfig[0] = + pinconf_to_config_packed(PIN_CONFIG_DRIVE_STRENGTH, + strength); - if (!of_property_read_u32(node, "allwinner,pull", &val)) { - enum pin_config_param pull = PIN_CONFIG_END; - if (val == 1) - pull = PIN_CONFIG_BIAS_PULL_UP; - else if (val == 2) - pull = PIN_CONFIG_BIAS_PULL_DOWN; - pinconfig[j++] = pinconf_to_config_packed(pull, 0); - } + val = 0; + of_property_read_u32(node, "allwinner,pull", &val); + pinconfig[1] = pinconf_to_config_packed(PIN_CONFIG_BIAS_PULL_UP, val == 1); + pinconfig[2] = pinconf_to_config_packed(PIN_CONFIG_BIAS_PULL_DOWN, val == 2); (*map)[i].data.configs.configs = pinconfig; - (*map)[i].data.configs.num_configs = configlen; + (*map)[i].data.configs.num_configs = 3; i++; } @@ -1563,6 +1555,7 @@ static int sunxi_pconf_group_set(struct pinctrl_dev *pctldev, { struct sunxi_pinctrl *pctl = pinctrl_dev_get_drvdata(pctldev); struct sunxi_pinctrl_group *g = &pctl->groups[group]; + u32 arg = pinconf_to_config_argument(config); u32 val, mask; u16 strength; u8 dlevel; @@ -1586,15 +1579,17 @@ static int sunxi_pconf_group_set(struct pinctrl_dev *pctldev, pctl->membase + sunxi_dlevel_reg(g->pin)); break; case PIN_CONFIG_BIAS_PULL_UP: + arg = !!arg; val = readl(pctl->membase + sunxi_pull_reg(g->pin)); mask = PULL_PINS_MASK << sunxi_pull_offset(g->pin); - writel((val & ~mask) | 1 << sunxi_pull_offset(g->pin), + writel((val & ~mask) | arg << sunxi_pull_offset(g->pin), pctl->membase + sunxi_pull_reg(g->pin)); break; case PIN_CONFIG_BIAS_PULL_DOWN: + arg = !!arg; val = readl(pctl->membase + sunxi_pull_reg(g->pin)); mask = PULL_PINS_MASK << sunxi_pull_offset(g->pin); - writel((val & ~mask) | 2 << sunxi_pull_offset(g->pin), + writel((val & ~mask) | (arg << 1) << sunxi_pull_offset(g->pin), pctl->membase + sunxi_pull_reg(g->pin)); break; default: