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: 469065 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by ozlabs.org (Postfix) with ESMTP id 81B6B1402C2 for ; Thu, 7 May 2015 03:11:27 +1000 (AEST) Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.b=CG1bAxek; dkim-atps=neutral Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751537AbbEFRL0 (ORCPT ); Wed, 6 May 2015 13:11:26 -0400 Received: from mail-la0-f41.google.com ([209.85.215.41]:34812 "EHLO mail-la0-f41.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1750776AbbEFRLZ (ORCPT ); Wed, 6 May 2015 13:11:25 -0400 Received: by laat2 with SMTP id t2so12384118laa.1 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 Cc: linux-gpio@vger.kernel.org, linux-arm-kernel@lists.infradead.org, Joachim Eastwood 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 Sender: linux-gpio-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-gpio@vger.kernel.org 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++) {