linux-sunxi.lists.linux.dev archive mirror
 help / color / mirror / Atom feed
From: Jonathan McDowell <noodles@earth.li>
To: Rob Herring <robh+dt@kernel.org>,
	Krzysztof Kozlowski <krzysztof.kozlowski+dt@linaro.org>,
	Chen-Yu Tsai <wens@csie.org>,
	Jernej Skrabec <jernej.skrabec@gmail.com>,
	Samuel Holland <samuel@sholland.org>,
	Linus Walleij <linus.walleij@linaro.org>,
	Bartosz Golaszewski <brgl@bgdev.pl>,
	Conor Dooley <conor+dt@kernel.org>,
	andy.shevchenko@gmail.com
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 v3 2/5] pinctrl: axp209: Add support for GPIO3 on the AXP209
Date: Tue, 16 May 2023 18:47:29 +0100	[thread overview]
Message-ID: <dde40307f0ebc23b9841c32e702b481ab5193dc4.1684258957.git.noodles@earth.li> (raw)
In-Reply-To: <cover.1684258957.git.noodles@earth.li>

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 <noodles@earth.li>
---
 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..b3ba25435c34 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		GENMASK(2, 1)
+#define AXP20X_GPIO3_FUNCTION_OUT_LOW	0
+#define AXP20X_GPIO3_FUNCTION_OUT_HIGH	2
+#define AXP20X_GPIO3_FUNCTION_INPUT	4
+
 #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;
+
+		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


  parent reply	other threads:[~2023-05-16 17:47 UTC|newest]

Thread overview: 44+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-04-15 17:45 [PATCH 0/3] Minor device-tree additions for C.H.I.P Jonathan McDowell
2023-04-15 17:46 ` [PATCH 1/3] ARM: dts: sun5i: chip: Enable bluetooth Jonathan McDowell
2023-04-15 20:36   ` kernel test robot
2023-04-16  0:24   ` Andre Przywara
2023-04-20 19:12     ` Jonathan McDowell
2023-04-21  1:43       ` Saravana Kannan
2023-04-21  8:28         ` Jonathan McDowell
2023-04-21 22:45           ` Saravana Kannan
2023-04-24 17:34             ` Jonathan McDowell
2023-05-01 21:12               ` Saravana Kannan
2023-05-10 11:34                 ` Jonathan McDowell
2023-04-15 17:46 ` [PATCH 2/3] ARM: dts: sun5i: Add port E pinmux settings for mmc2 Jonathan McDowell
2023-04-16  0:47   ` Andre Przywara
2023-04-20 19:13     ` Jonathan McDowell
2023-04-15 17:47 ` [PATCH 3/3] ARM: dts: axp209: Add iio-hwmon node for internal temperature Jonathan McDowell
2023-04-16  7:27   ` Krzysztof Kozlowski
2023-04-20 19:06     ` Jonathan McDowell
2023-05-10 12:00 ` [PATCH v2 0/5] Minor device-tree additions for C.H.I.P Jonathan McDowell
2023-05-10 12:01   ` [PATCH v2 1/5] dt-bindings: gpio: Add GPIO3 for AXP209 GPIO binding schema Jonathan McDowell
2023-05-11 15:41     ` Jernej Škrabec
2023-05-11 18:55     ` Conor Dooley
2023-05-10 12:01   ` [PATCH v2 2/5] pinctrl: axp209: Add support for GPIO3 on the AXP209 Jonathan McDowell
2023-05-10 14:15     ` andy.shevchenko
2023-05-29  9:51     ` Linus Walleij
2023-06-01  7:30       ` Jonathan McDowell
2023-05-10 12:01   ` [PATCH v2 3/5] ARM: dts: sun5i: chip: Enable bluetooth Jonathan McDowell
2023-05-11 15:41     ` Jernej Škrabec
2023-05-10 12:02   ` [PATCH v2 4/5] ARM: dts: sun5i: Add port E pinmux settings for mmc2 Jonathan McDowell
2023-05-11 15:45     ` Jernej Škrabec
2023-05-10 12:02   ` [PATCH v2 5/5] ARM: dts: axp209: Add iio-hwmon node for internal temperature Jonathan McDowell
2023-05-11 16:11     ` Jernej Škrabec
2023-05-12 10:30       ` Jonathan McDowell
2023-05-12 16:37         ` Jernej Škrabec
2023-05-16 17:46   ` [PATCH v3 0/5] Minor device-tree additions for C.H.I.P Jonathan McDowell
2023-05-16 17:47     ` [PATCH v3 1/5] dt-bindings: gpio: Add GPIO3 for AXP209 GPIO binding schema Jonathan McDowell
2023-05-22  7:37       ` Linus Walleij
2023-05-26 12:24       ` Bartosz Golaszewski
2023-05-16 17:47     ` Jonathan McDowell [this message]
2023-05-16 18:55       ` [PATCH v3 2/5] pinctrl: axp209: Add support for GPIO3 on the AXP209 Andy Shevchenko
2023-05-18 21:21       ` Jernej Škrabec
2023-05-16 17:47     ` [PATCH v3 3/5] ARM: dts: sun5i: chip: Enable bluetooth Jonathan McDowell
2023-05-16 17:48     ` [PATCH v3 4/5] ARM: dts: sun5i: Add port E pinmux settings for mmc2 Jonathan McDowell
2023-05-16 17:48     ` [PATCH v3 5/5] ARM: dts: axp209: Add iio-hwmon node for internal temperature Jonathan McDowell
2023-05-31 21:20     ` [PATCH v3 0/5] Minor device-tree additions for C.H.I.P Jernej Škrabec

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=dde40307f0ebc23b9841c32e702b481ab5193dc4.1684258957.git.noodles@earth.li \
    --to=noodles@earth.li \
    --cc=andy.shevchenko@gmail.com \
    --cc=brgl@bgdev.pl \
    --cc=conor+dt@kernel.org \
    --cc=devicetree@vger.kernel.org \
    --cc=jernej.skrabec@gmail.com \
    --cc=krzysztof.kozlowski+dt@linaro.org \
    --cc=linus.walleij@linaro.org \
    --cc=linux-arm-kernel@lists.infradead.org \
    --cc=linux-gpio@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-sunxi@lists.linux.dev \
    --cc=robh+dt@kernel.org \
    --cc=samuel@sholland.org \
    --cc=wens@csie.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).