From patchwork Wed May 6 17:11:21 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Joachim Eastwood X-Patchwork-Id: 6351621 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.29.136]) by patchwork2.web.kernel.org (Postfix) with ESMTP id BE46FBEEE1 for ; Wed, 6 May 2015 17:14:09 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id DDA7A20268 for ; Wed, 6 May 2015 17:14:07 +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 16AC9201FE for ; Wed, 6 May 2015 17:14:07 +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 1Yq2rP-000871-OV; Wed, 06 May 2015 17:11:51 +0000 Received: from mail-lb0-x22f.google.com ([2a00:1450:4010:c04::22f]) by bombadil.infradead.org with esmtps (Exim 4.80.1 #2 (Red Hat Linux)) id 1Yq2rK-0007x7-Og for linux-arm-kernel@lists.infradead.org; Wed, 06 May 2015 17:11:48 +0000 Received: by lbbuc2 with SMTP id uc2so12561797lbb.2 for ; Wed, 06 May 2015 10:11:24 -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; bh=+oksCkCl3SC2Ko47mWlEYKp4pKW/u/m66IBviGgseKM=; b=CG1bAxekAsLb4b6X0kch9XklwIIt4Cn2SvjC+GevDQzzqag2EZhbRN/YOnL2VWYFY3 AoTLLX4lXcrs1Zk1st/yW01xaiOkYAqx2xElslYEMwGJWypZYN7Cjjr/YHEnlImwrngM cKamE7dhqzStORHrC/ArpugDO8yLtgeBIbw+Zy3MC/DfL/ODi+kyQCrOdri/Ul8J9uy+ kP9t1/9r51f3k8/u6/xj+gLr72WM57xC8AmGs/oFJkd2SwG3MMqRj29qOIqLn6MaOofL Sqh4FqcXgeE1MmVbivPx8QOur68tnhFcbptKdTmVjof2burlzyyCai5lC8nSSu9DTRWf 5qiA== X-Received: by 10.152.37.228 with SMTP id b4mr28804569lak.117.1430932284184; Wed, 06 May 2015 10:11:24 -0700 (PDT) Received: from localhost.localdomain ([90.149.48.183]) by mx.google.com with ESMTPSA id tp10sm486132lbb.4.2015.05.06.10.11.23 (version=TLSv1.1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Wed, 06 May 2015 10:11:23 -0700 (PDT) From: Joachim Eastwood To: linus.walleij@linaro.org Subject: [PATCH] pinctrl: lpc18xx: create pin cap lookup helper Date: Wed, 6 May 2015 19:11:21 +0200 Message-Id: <1430932281-3432-1-git-send-email-manabian@gmail.com> X-Mailer: git-send-email 1.8.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20150506_101147_389314_A3141D0F X-CRM114-Status: GOOD ( 15.51 ) X-Spam-Score: -0.8 (/) Cc: linux-gpio@vger.kernel.org, Joachim Eastwood , 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 Both pconf_get_pin and pconf_set_pin needs to lookup pin cap based on the pin number. Create a common helper function that both functions can use that also handles the case where no pin number is found in the pins array. This also fixes a small bug in pconf_get_pin where pconf_get_i2c0 would use the pins array index rather than the pin number. Signed-off-by: Joachim Eastwood --- Hi Linus, Patch is based on your linux-pinctrl devel branch. Since it's a new driver feel free to squash it with the initial commit. regards, Joachim Eastwood drivers/pinctrl/pinctrl-lpc18xx.c | 29 ++++++++++++++++++----------- 1 file changed, 18 insertions(+), 11 deletions(-) diff --git a/drivers/pinctrl/pinctrl-lpc18xx.c b/drivers/pinctrl/pinctrl-lpc18xx.c index 15fe1e2535c2..0facb7e64fef 100644 --- a/drivers/pinctrl/pinctrl-lpc18xx.c +++ b/drivers/pinctrl/pinctrl-lpc18xx.c @@ -729,6 +729,18 @@ static int lpc18xx_pconf_get_pin(enum pin_config_param param, int *arg, u32 reg, return 0; } +static struct lpc18xx_pin_caps *lpc18xx_get_pin_caps(unsigned pin) +{ + int i; + + for (i = 0; i < ARRAY_SIZE(lpc18xx_pins); i++) { + if (lpc18xx_pins[i].number == pin) + return lpc18xx_pins[i].drv_data; + } + + return NULL; +} + static int lpc18xx_pconf_get(struct pinctrl_dev *pctldev, unsigned pin, unsigned long *config) { @@ -737,14 +749,11 @@ static int lpc18xx_pconf_get(struct pinctrl_dev *pctldev, unsigned pin, struct lpc18xx_pin_caps *pin_cap; int ret, arg = 0; u32 reg; - int i; - for (i = 0; i < ARRAY_SIZE(lpc18xx_pins); i++) { - if (lpc18xx_pins[i].number == pin) - pin = i; - } + pin_cap = lpc18xx_get_pin_caps(pin); + if (!pin_cap) + return -EINVAL; - pin_cap = lpc18xx_pins[pin].drv_data; reg = readl(scu->base + pin_cap->offset); if (pin_cap->type == TYPE_I2C0) @@ -905,12 +914,10 @@ static int lpc18xx_pconf_set(struct pinctrl_dev *pctldev, unsigned pin, int ret; int i; - for (i = 0; i < ARRAY_SIZE(lpc18xx_pins); i++) { - if (lpc18xx_pins[i].number == pin) - break; - } + pin_cap = lpc18xx_get_pin_caps(pin); + if (!pin_cap) + return -EINVAL; - pin_cap = lpc18xx_pins[i].drv_data; reg = readl(scu->base + pin_cap->offset); for (i = 0; i < num_configs; i++) {