From: James Hilliard <james.hilliard1@gmail.com>
To: linux-sunxi@lists.linux.dev, linux-gpio@vger.kernel.org
Cc: James Hilliard <james.hilliard1@gmail.com>,
Linus Walleij <linusw@kernel.org>, Chen-Yu Tsai <wens@kernel.org>,
Jernej Skrabec <jernej.skrabec@gmail.com>,
Samuel Holland <samuel@sholland.org>,
Bartosz Golaszewski <brgl@kernel.org>,
linux-arm-kernel@lists.infradead.org,
linux-kernel@vger.kernel.org
Subject: [PATCH 1/1] pinctrl: sunxi: add GPIO get_direction callback
Date: Tue, 10 Feb 2026 20:32:48 -0700 [thread overview]
Message-ID: <20260211033249.2770281-1-james.hilliard1@gmail.com> (raw)
Implement sunxi_pinctrl_gpio_get_direction() and wire it into
the sunxi gpio_chip setup.
The new callback reads the pin mux register and compares the mux
value against the pin descriptor gpio_in and gpio_out functions
to report GPIO_LINE_DIRECTION_IN or GPIO_LINE_DIRECTION_OUT.
If the pin is muxed to irq, report it as input.
Signed-off-by: James Hilliard <james.hilliard1@gmail.com>
---
drivers/pinctrl/sunxi/pinctrl-sunxi.c | 32 +++++++++++++++++++++++++++
1 file changed, 32 insertions(+)
diff --git a/drivers/pinctrl/sunxi/pinctrl-sunxi.c b/drivers/pinctrl/sunxi/pinctrl-sunxi.c
index 0fb057a07dcc..424f23be27b2 100644
--- a/drivers/pinctrl/sunxi/pinctrl-sunxi.c
+++ b/drivers/pinctrl/sunxi/pinctrl-sunxi.c
@@ -995,6 +995,37 @@ static int sunxi_pinctrl_gpio_direction_output(struct gpio_chip *chip,
chip->base + offset, false);
}
+static int sunxi_pinctrl_gpio_get_direction(struct gpio_chip *chip,
+ unsigned int offset)
+{
+ struct sunxi_pinctrl *pctl = gpiochip_get_data(chip);
+ struct sunxi_desc_function *in, *out, *irq;
+ u32 reg, shift, mask, val;
+ u16 pin = chip->base + offset;
+
+ in = sunxi_pinctrl_desc_find_function_by_pin(pctl, pin, "gpio_in");
+ out = sunxi_pinctrl_desc_find_function_by_pin(pctl, pin, "gpio_out");
+ if (!in || !out)
+ return -EINVAL;
+
+ irq = sunxi_pinctrl_desc_find_function_by_pin(pctl, pin, "irq");
+
+ sunxi_mux_reg(pctl, offset, ®, &shift, &mask);
+ val = (readl(pctl->membase + reg) & mask) >> shift;
+
+ if (val == in->muxval)
+ return GPIO_LINE_DIRECTION_IN;
+
+ if (val == out->muxval)
+ return GPIO_LINE_DIRECTION_OUT;
+
+ /* IRQ function is effectively input. */
+ if (irq && val == irq->muxval)
+ return GPIO_LINE_DIRECTION_IN;
+
+ return -EINVAL;
+}
+
static int sunxi_pinctrl_gpio_of_xlate(struct gpio_chip *gc,
const struct of_phandle_args *gpiospec,
u32 *flags)
@@ -1603,6 +1634,7 @@ int sunxi_pinctrl_init_with_flags(struct platform_device *pdev,
pctl->chip->set_config = gpiochip_generic_config;
pctl->chip->direction_input = sunxi_pinctrl_gpio_direction_input;
pctl->chip->direction_output = sunxi_pinctrl_gpio_direction_output;
+ pctl->chip->get_direction = sunxi_pinctrl_gpio_get_direction;
pctl->chip->get = sunxi_pinctrl_gpio_get;
pctl->chip->set = sunxi_pinctrl_gpio_set;
pctl->chip->of_xlate = sunxi_pinctrl_gpio_of_xlate;
--
2.43.0
next reply other threads:[~2026-02-11 3:33 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-02-11 3:32 James Hilliard [this message]
2026-02-11 3:49 ` Chen-Yu Tsai
2026-02-11 4:04 ` James Hilliard
2026-02-11 9:08 ` Andre Przywara
2026-02-11 9:54 ` Chen-Yu Tsai
2026-02-23 10:25 ` Linus Walleij
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=20260211033249.2770281-1-james.hilliard1@gmail.com \
--to=james.hilliard1@gmail.com \
--cc=brgl@kernel.org \
--cc=jernej.skrabec@gmail.com \
--cc=linusw@kernel.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=samuel@sholland.org \
--cc=wens@kernel.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
all inboxes | Powered by JetHome®