Received: by 2002:a05:6358:9144:b0:117:f937:c515 with SMTP id r4csp7220021rwr; Wed, 10 May 2023 05:41:38 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ5Yxuj6wAUSLRe0mV+fzfE3MvPn+u1dkyRhYcuzMlSyxwCki0NgXicovwtGIRm+vJ/jxysx X-Received: by 2002:a05:6a00:14ce:b0:640:f313:efba with SMTP id w14-20020a056a0014ce00b00640f313efbamr23897467pfu.19.1683722498418; Wed, 10 May 2023 05:41:38 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1683722498; cv=none; d=google.com; s=arc-20160816; b=L0t6hllJFfbA717MEHm6snIqRbi3Vi/MIYFQ5xp2c6zwnIX/ZtJ7VVhAb2ghtu0CBU GN925/6EsDtdjzu8btba414Rhjn6/3nlan+xxgHGJ4tXN1ALF6McclNLW1t5vS78Ak7C cRq6A5d5RgOoGnN1hi0ggoXS2mrr4/Nhh5RYkSSvVwq9PxC5WoFDlRJk+GN9giLf/mG4 b1fJ2N94HUfzIyei9nzIflEy1+NFt4hqpibYNBIybRtaZ1AMWxkI+hKSWHmn/OJGj/yf VKJjaJ4axZ99GBmy+f3YgUrr+XWGrTFFLBTLeI7YlU5nd5RwykwC/nSvjha9y22vu/rm kjrw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-disposition:mime-version :references:message-id:subject:cc:to:from:date:dkim-signature; bh=1u21EgrVe1mbhCqk/BYORJb3V3qyKh1H63Bv4N/ch+M=; b=gld3zSE50ZPG/KYWRvpbZLb8mlZjDVqclltAu7sj5g1i/RAPXYG5KbSFb1s0aOZA9E SqG7CIVsIGhHC8XGve6uIQ4FBox+UAU2a/a/dTKBjQyLFM9DHQ7bIh0BtzZoo5du7HD9 +gU+ugSASILjsZgZC1naCstBn68d95CnLsk+5kSFNva+I+yqdH/FcxX0yUtst0mQRO87 v9lp31e6ilfaXVF9GenGVOH1MIHkWX6xmz0nC6OOY79qKDlD6vLDfSQ2k0EQy4XetubV /5lsWHCklh47dmcIdcNph0EVbS1F6Te0Vin8tm+5TWQX4I+HHhB4OXWaDcv144iDZr6N Slpg== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@earth.li header.s=the header.b=WnsnSvmk; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id z2-20020aa79582000000b006438db1b969si4791013pfj.29.2023.05.10.05.41.26; Wed, 10 May 2023 05:41:38 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=fail header.i=@earth.li header.s=the header.b=WnsnSvmk; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S237084AbjEJMgz (ORCPT + 99 others); Wed, 10 May 2023 08:36:55 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:37382 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S237096AbjEJMge (ORCPT ); Wed, 10 May 2023 08:36:34 -0400 Received: from the.earth.li (the.earth.li [IPv6:2a00:1098:86:4d:c0ff:ee:15:900d]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id D7CEBA5FB; Wed, 10 May 2023 05:36:15 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=earth.li; s=the; h=In-Reply-To:Content-Type:MIME-Version:References:Message-ID:Subject: Cc:To:From:Date:Sender:Reply-To:Content-Transfer-Encoding:Content-ID: Content-Description:Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc :Resent-Message-ID:List-Id:List-Help:List-Unsubscribe:List-Subscribe: List-Post:List-Owner:List-Archive; bh=1u21EgrVe1mbhCqk/BYORJb3V3qyKh1H63Bv4N/ch+M=; b=WnsnSvmkHYLNWWOhx1CJhmbR+A KsmPd5JHJIxztGWv2ZtBJurZb8vpzoz0ahKwDq3AvINTaxKOn0mNvl5+pMEDVeQaHOurjUJzoKJoD eJRCEBgyq2GHMvAres6z49rqNi74RNFv6LUiyHt/cSwFDl+2uSeRPZJWwaJkeIdg1BvH8xHrm6BCN vy47MrVOyURzUXNqpaD5Jlr92IA0Ghz2oTXcEsUJ425Q7QW4BPfDoeyXbEYGqbWHGF+/HJrAEgKTC mM/0O1z0I2Jm6WHno/RG45tQrlbWAYo4ZVNqK4Q71GDMNGqxlPDnOCSrjHUbsFJ58O3ifCIvQ2luL 8baLTsCA==; Received: from [2001:4d48:ad59:1403::16a3] (helo=earth.li) by the.earth.li with esmtpsa (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1pwiVh-007ufr-D5; Wed, 10 May 2023 13:01:33 +0100 Date: Wed, 10 May 2023 13:01:27 +0100 From: Jonathan McDowell To: Rob Herring , Krzysztof Kozlowski , Chen-Yu Tsai , Jernej Skrabec , Samuel Holland , Linus Walleij , Bartosz Golaszewski , Conor Dooley Cc: devicetree@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-sunxi@lists.linux.dev, linux-kernel@vger.kernel.org, linux-gpio@vger.kernel.org Subject: [PATCH v2 2/5] pinctrl: axp209: Add support for GPIO3 on the AXP209 Message-ID: References: MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,SPF_HELO_NONE,SPF_PASS, T_SCC_BODY_TEXT_LINE,URIBL_BLOCKED autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org The AXP209 device has a 4th GPIO which has a slightly different register setup, where the control + status bits are held in a single register rather than sharing AXP20X_GPIO20_SS with GPIOs 0-2. Signed-off-by: Jonathan McDowell --- drivers/pinctrl/pinctrl-axp209.c | 42 ++++++++++++++++++++++++++++++++ 1 file changed, 42 insertions(+) diff --git a/drivers/pinctrl/pinctrl-axp209.c b/drivers/pinctrl/pinctrl-axp209.c index 0bc1b381a2b8..317691aee86b 100644 --- a/drivers/pinctrl/pinctrl-axp209.c +++ b/drivers/pinctrl/pinctrl-axp209.c @@ -30,6 +30,11 @@ #define AXP20X_GPIO_FUNCTION_OUT_HIGH 1 #define AXP20X_GPIO_FUNCTION_INPUT 2 +#define AXP20X_GPIO3_FUNCTIONS (BIT(2) | BIT(1)) +#define AXP20X_GPIO3_FUNCTION_OUT_LOW 0 +#define AXP20X_GPIO3_FUNCTION_OUT_HIGH BIT(1) +#define AXP20X_GPIO3_FUNCTION_INPUT BIT(2) + #define AXP20X_FUNC_GPIO_OUT 0 #define AXP20X_FUNC_GPIO_IN 1 #define AXP20X_FUNC_LDO 2 @@ -73,6 +78,7 @@ static const struct pinctrl_pin_desc axp209_pins[] = { PINCTRL_PIN(0, "GPIO0"), PINCTRL_PIN(1, "GPIO1"), PINCTRL_PIN(2, "GPIO2"), + PINCTRL_PIN(3, "GPIO3"), }; static const struct pinctrl_pin_desc axp22x_pins[] = { @@ -130,6 +136,14 @@ static int axp20x_gpio_get(struct gpio_chip *chip, unsigned int offset) unsigned int val; int ret; + /* AXP209 has GPIO3 status sharing the settings register */ + if (offset == 3) { + ret = regmap_read(pctl->regmap, AXP20X_GPIO3_CTRL, &val); + if (ret) + return ret; + return !!(val & BIT(0)); + } + ret = regmap_read(pctl->regmap, AXP20X_GPIO20_SS, &val); if (ret) return ret; @@ -144,6 +158,17 @@ static int axp20x_gpio_get_direction(struct gpio_chip *chip, unsigned int val; int reg, ret; + /* AXP209 GPIO3 settings have a different layout */ + if (offset == 3) { + ret = regmap_read(pctl->regmap, AXP20X_GPIO3_CTRL, &val); + if (ret) + return ret; + if (val & AXP20X_GPIO3_FUNCTION_INPUT) + return GPIO_LINE_DIRECTION_IN; + else + return GPIO_LINE_DIRECTION_OUT; + } + reg = axp20x_gpio_get_reg(offset); if (reg < 0) return reg; @@ -184,6 +209,15 @@ static void axp20x_gpio_set(struct gpio_chip *chip, unsigned int offset, struct axp20x_pctl *pctl = gpiochip_get_data(chip); int reg; + /* AXP209 has GPIO3 status sharing the settings register */ + if (offset == 3) { + regmap_update_bits(pctl->regmap, AXP20X_GPIO3_CTRL, + AXP20X_GPIO3_FUNCTIONS, + value ? AXP20X_GPIO3_FUNCTION_OUT_HIGH : + AXP20X_GPIO3_FUNCTION_OUT_LOW); + return; + } + reg = axp20x_gpio_get_reg(offset); if (reg < 0) return; @@ -200,6 +234,14 @@ static int axp20x_pmx_set(struct pinctrl_dev *pctldev, unsigned int offset, struct axp20x_pctl *pctl = pinctrl_dev_get_drvdata(pctldev); int reg; + /* AXP209 GPIO3 settings have a different layout */ + if (offset == 3) { + return regmap_update_bits(pctl->regmap, AXP20X_GPIO3_CTRL, + AXP20X_GPIO3_FUNCTIONS, + config == AXP20X_MUX_GPIO_OUT ? AXP20X_GPIO3_FUNCTION_OUT_LOW : + AXP20X_GPIO3_FUNCTION_INPUT); + } + reg = axp20x_gpio_get_reg(offset); if (reg < 0) return reg; -- 2.39.2