[PATCH v2] gpios: palmas: add get_direction op

From: Andreas Kemnade

Date: Sat Jul 04 2026 - 04:41:43 EST


Accessing debug/gpio is quite noisy without a get_direction()
implementation. To calm that down add an implementation.

Fixes: 3d50a2785271 ("gpio: palmas: Add support for Palmas GPIO")
Cc: stable@xxxxxxxxxxxxxxx
Reviewed-by: Linus Walleij <linusw@xxxxxxxxxx>
Signed-off-by: Andreas Kemnade <andreas@xxxxxxxxxxxx>
---
Changes in v2:
- add a proper fixes tag
- Link to v1: https://patch.msgid.link/20260703-palmas-getdirection-v1-1-046c155961c4@xxxxxxxxxxxx

To: Linus Walleij <linusw@xxxxxxxxxx>
To: Bartosz Golaszewski <brgl@xxxxxxxxxx>
To: Laxman Dewangan <ldewangan@xxxxxxxxxx>
To: Samuel Ortiz <sameo@xxxxxxxxxxxxxxx>
Cc: linux-gpio@xxxxxxxxxxxxxxx
Cc: linux-kernel@xxxxxxxxxxxxxxx
---
drivers/gpio/gpio-palmas.c | 19 +++++++++++++++++++
1 file changed, 19 insertions(+)

diff --git a/drivers/gpio/gpio-palmas.c b/drivers/gpio/gpio-palmas.c
index e377f6dd4ccf..e64ee0487718 100644
--- a/drivers/gpio/gpio-palmas.c
+++ b/drivers/gpio/gpio-palmas.c
@@ -116,6 +116,24 @@ static int palmas_gpio_input(struct gpio_chip *gc, unsigned offset)
return ret;
}

+static int palmas_gpio_get_direction(struct gpio_chip *gc, unsigned int offset)
+{
+ struct palmas_gpio *pg = gpiochip_get_data(gc);
+ struct palmas *palmas = pg->palmas;
+ unsigned int val;
+ unsigned int reg;
+ int ret;
+ int gpio16 = (offset/8);
+
+ offset %= 8;
+ reg = (gpio16) ? PALMAS_GPIO_DATA_DIR2 : PALMAS_GPIO_DATA_DIR;
+ ret = palmas_read(palmas, PALMAS_GPIO_BASE, reg, &val);
+ if (ret)
+ return ret;
+
+ return (val & BIT(offset)) ? GPIO_LINE_DIRECTION_OUT : GPIO_LINE_DIRECTION_IN;
+}
+
static int palmas_gpio_to_irq(struct gpio_chip *gc, unsigned offset)
{
struct palmas_gpio *pg = gpiochip_get_data(gc);
@@ -165,6 +183,7 @@ static int palmas_gpio_probe(struct platform_device *pdev)
palmas_gpio->gpio_chip.can_sleep = true;
palmas_gpio->gpio_chip.direction_input = palmas_gpio_input;
palmas_gpio->gpio_chip.direction_output = palmas_gpio_output;
+ palmas_gpio->gpio_chip.get_direction = palmas_gpio_get_direction;
palmas_gpio->gpio_chip.to_irq = palmas_gpio_to_irq;
palmas_gpio->gpio_chip.set = palmas_gpio_set;
palmas_gpio->gpio_chip.get = palmas_gpio_get;

---
base-commit: dc59e4fea9d83f03bad6bddf3fa2e52491777482
change-id: 20260703-palmas-getdirection-914eddf30b00

Best regards,
--
Andreas Kemnade <andreas@xxxxxxxxxxxx>