From patchwork Tue Sep 26 12:17:13 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Quentin Schulz X-Patchwork-Id: 9971829 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 871666037F for ; Tue, 26 Sep 2017 12:18:40 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 6BFFF28B45 for ; Tue, 26 Sep 2017 12:18:40 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 5FF3B28F52; Tue, 26 Sep 2017 12:18:40 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-4.2 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,RCVD_IN_DNSWL_MED autolearn=ham version=3.3.1 Received: from bombadil.infradead.org (bombadil.infradead.org [65.50.211.133]) (using TLSv1.2 with cipher AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id D397B28B45 for ; Tue, 26 Sep 2017 12:18:39 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20170209; h=Sender: Content-Transfer-Encoding:Content-Type:MIME-Version:Cc:List-Subscribe: List-Help:List-Post:List-Archive:List-Unsubscribe:List-Id:References: In-Reply-To:Message-Id:Date:Subject:To:From:Reply-To:Content-ID: Content-Description:Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc :Resent-Message-ID:List-Owner; bh=YrxLySh7Yorjaj8la2Op5rOXcirjWOYcRRolDhDJue0=; b=BeAmcKnhPfu8orD8Kv8KGbCd0V WMYI9Zsj+kEl+269iUQQJFyrctixELTbimIN75w58LqEzp5+o6RsV123iMuxml7iSIX1TzRhsmIM/ b1aspNh6lWGAHrJZ10xeo59Uo3D0NdzVUlsXpoVNpkBjeIXZ62LOOYExvFsBBr/zrsyotcU8FaaTz 8bc+UfmXxqX/fxKvncKY7lEJZUuQvJbQp1ppIgPVtBsPuntazwS8BifBEt7MZzre1NKKnx9gwkmBq vYTGhBwIdev20IfIzbb4HDZlckJ1GmBZMuEowdo/INLszCltU21CeQzCliEFeEu7f4yKAHLKcj4CT s12nOhHw==; Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.87 #1 (Red Hat Linux)) id 1dwoop-0006SU-H0; Tue, 26 Sep 2017 12:18:31 +0000 Received: from mail.free-electrons.com ([62.4.15.54]) by bombadil.infradead.org with esmtp (Exim 4.87 #1 (Red Hat Linux)) id 1dwool-000631-5r for linux-arm-kernel@lists.infradead.org; Tue, 26 Sep 2017 12:18:29 +0000 Received: by mail.free-electrons.com (Postfix, from userid 110) id 3615320846; Tue, 26 Sep 2017 14:18:05 +0200 (CEST) Received: from localhost.localdomain (LStLambert-657-1-97-87.w90-63.abo.wanadoo.fr [90.63.216.87]) by mail.free-electrons.com (Postfix) with ESMTPSA id D7C7E20860; Tue, 26 Sep 2017 14:17:54 +0200 (CEST) From: Quentin Schulz To: linus.walleij@linaro.org, robh+dt@kernel.org, mark.rutland@arm.com, wens@csie.org, linux@armlinux.org.uk, maxime.ripard@free-electrons.com, lee.jones@linaro.org Subject: [PATCH v2 03/10] pinctrl: axp209: use drv_data of pinctrl_pin_desc to store pin reg Date: Tue, 26 Sep 2017 14:17:13 +0200 Message-Id: <7993a30fbc2e50a2d228fa0c8fad643c4034b101.1506428208.git-series.quentin.schulz@free-electrons.com> X-Mailer: git-send-email 2.11.0 In-Reply-To: References: In-Reply-To: References: X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20170926_051827_565135_4ACAE74C X-CRM114-Status: GOOD ( 14.19 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: thomas.petazzoni@free-electrons.com, devicetree@vger.kernel.org, Quentin Schulz , linux-kernel@vger.kernel.org, linux-gpio@vger.kernel.org, linux-sunxi@googlegroups.com, linux-arm-kernel@lists.infradead.org MIME-Version: 1.0 Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org X-Virus-Scanned: ClamAV using ClamSMTP Instead of using a function to retrieve each pin's correct control register, use drv_data within pinctrl_pin_desc to store the ctrl reg. Remove axp20x_gpio_get_reg and replace every occurrence by a get from drv_data. Signed-off-by: Quentin Schulz --- drivers/pinctrl/pinctrl-axp209.c | 42 +++++++-------------------------- 1 file changed, 9 insertions(+), 33 deletions(-) diff --git a/drivers/pinctrl/pinctrl-axp209.c b/drivers/pinctrl/pinctrl-axp209.c index b35e8dd..4bbcba2 100644 --- a/drivers/pinctrl/pinctrl-axp209.c +++ b/drivers/pinctrl/pinctrl-axp209.c @@ -32,10 +32,11 @@ #define AXP20X_GPIO_FUNCTION_OUT_HIGH 1 #define AXP20X_GPIO_FUNCTION_INPUT 2 -#define AXP20X_PINCTRL_PIN(_pin_num, _pin) \ +#define AXP20X_PINCTRL_PIN(_pin_num, _pin, _regs) \ { \ .number = _pin_num, \ .name = _pin, \ + .drv_data = _regs, \ } #define AXP20X_PIN(_pin, ...) \ @@ -91,17 +92,17 @@ struct axp20x_gpio { }; static const struct axp20x_desc_pin axp209_pins[] = { - AXP20X_PIN(AXP20X_PINCTRL_PIN(0, "GPIO0"), + AXP20X_PIN(AXP20X_PINCTRL_PIN(0, "GPIO0", (void *)AXP20X_GPIO0_CTRL), AXP20X_FUNCTION(0x0, "gpio_out"), AXP20X_FUNCTION(0x2, "gpio_in"), AXP20X_FUNCTION(0x3, "ldo"), AXP20X_FUNCTION(0x4, "adc")), - AXP20X_PIN(AXP20X_PINCTRL_PIN(1, "GPIO1"), + AXP20X_PIN(AXP20X_PINCTRL_PIN(1, "GPIO1", (void *)AXP20X_GPIO1_CTRL), AXP20X_FUNCTION(0x0, "gpio_out"), AXP20X_FUNCTION(0x2, "gpio_in"), AXP20X_FUNCTION(0x3, "ldo"), AXP20X_FUNCTION(0x4, "adc")), - AXP20X_PIN(AXP20X_PINCTRL_PIN(2, "GPIO2"), + AXP20X_PIN(AXP20X_PINCTRL_PIN(2, "GPIO2", (void *)AXP20X_GPIO2_CTRL), AXP20X_FUNCTION(0x0, "gpio_out"), AXP20X_FUNCTION(0x2, "gpio_in")), }; @@ -111,20 +112,6 @@ static const struct axp20x_pinctrl_desc axp20x_pinctrl_data = { .npins = ARRAY_SIZE(axp209_pins), }; -static int axp20x_gpio_get_reg(unsigned offset) -{ - switch (offset) { - case 0: - return AXP20X_GPIO0_CTRL; - case 1: - return AXP20X_GPIO1_CTRL; - case 2: - return AXP20X_GPIO2_CTRL; - } - - return -EINVAL; -} - static int axp20x_gpio_input(struct gpio_chip *chip, unsigned offset) { return pinctrl_gpio_direction_input(chip->base + offset); @@ -146,12 +133,9 @@ static int axp20x_gpio_get(struct gpio_chip *chip, unsigned offset) static int axp20x_gpio_get_direction(struct gpio_chip *chip, unsigned offset) { struct axp20x_gpio *gpio = gpiochip_get_data(chip); + int reg = (int)gpio->desc->pins[offset].pin.drv_data; unsigned int val; - int reg, ret; - - reg = axp20x_gpio_get_reg(offset); - if (reg < 0) - return reg; + int ret; ret = regmap_read(gpio->regmap, reg, &val); if (ret) @@ -184,11 +168,7 @@ static void axp20x_gpio_set(struct gpio_chip *chip, unsigned offset, int value) { struct axp20x_gpio *gpio = gpiochip_get_data(chip); - int reg; - - reg = axp20x_gpio_get_reg(offset); - if (reg < 0) - return; + int reg = (int)gpio->desc->pins[offset].pin.drv_data; regmap_update_bits(gpio->regmap, reg, AXP20X_GPIO_FUNCTIONS, @@ -200,11 +180,7 @@ static int axp20x_pmx_set(struct pinctrl_dev *pctldev, unsigned int offset, u8 config) { struct axp20x_gpio *gpio = pinctrl_dev_get_drvdata(pctldev); - int reg; - - reg = axp20x_gpio_get_reg(offset); - if (reg < 0) - return reg; + int reg = (int)gpio->desc->pins[offset].pin.drv_data; return regmap_update_bits(gpio->regmap, reg, AXP20X_GPIO_FUNCTIONS, config);