mail archive of the barebox mailing list
 help / color / mirror / Atom feed
* [PATCH v1 1/2] gpiolib: extend support for non-zero offset GPIO banks
@ 2024-05-29  4:53 Oleksij Rempel
  2024-05-29  4:53 ` [PATCH v1 2/2] pinctrl: stm32: extract and set GPIO offset from devicetree Oleksij Rempel
  2024-05-29  6:19 ` [PATCH v1 1/2] gpiolib: extend support for non-zero offset GPIO banks Sascha Hauer
  0 siblings, 2 replies; 3+ messages in thread
From: Oleksij Rempel @ 2024-05-29  4:53 UTC (permalink / raw)
  To: barebox; +Cc: Oleksij Rempel

Introduce gpio_offset variable in gpiolib to handle GPIO controllers
with non-zero starting indices. This is necessary for stm32mp151aad3,
which includes GPIO banks with 6 and 10 lines that do not start from 0.

Signed-off-by: Oleksij Rempel <o.rempel@pengutronix.de>
---
 drivers/gpio/gpiolib.c | 8 +++++---
 include/gpio.h         | 2 ++
 2 files changed, 7 insertions(+), 3 deletions(-)

diff --git a/drivers/gpio/gpiolib.c b/drivers/gpio/gpiolib.c
index a70e13eafc..520ffed2ee 100644
--- a/drivers/gpio/gpiolib.c
+++ b/drivers/gpio/gpiolib.c
@@ -83,7 +83,7 @@ static struct gpio_desc *gpio_to_desc(unsigned gpio)
 
 static unsigned gpiodesc_chip_offset(const struct gpio_desc *desc)
 {
-	return (desc - gpio_desc) - desc->chip->base;
+	return (desc - gpio_desc) - desc->chip->base + desc->chip->gpio_offset;
 }
 
 static int gpio_adjust_value(const struct gpio_desc *desc,
@@ -770,6 +770,8 @@ static int of_gpio_simple_xlate(struct gpio_chip *gc,
 				const struct of_phandle_args *gpiospec,
 				u32 *flags)
 {
+	int gpio = gpiospec->args[0] - gc->gpio_offset;
+
 	/*
 	 * We're discouraging gpio_cells < 2, since that way you'll have to
 	 * write your own xlate function (that will have to retrieve the GPIO
@@ -782,13 +784,13 @@ static int of_gpio_simple_xlate(struct gpio_chip *gc,
 	if (WARN_ON(gpiospec->args_count < gc->of_gpio_n_cells))
 		return -EINVAL;
 
-	if (gpiospec->args[0] >= gc->ngpio)
+	if (gpio < 0 || gpio >= gc->ngpio)
 		return -EINVAL;
 
 	if (flags)
 		*flags = gpiospec->args[1];
 
-	return gc->base + gpiospec->args[0];
+	return gc->base + gpio;
 }
 
 static int of_gpiochip_add(struct gpio_chip *chip)
diff --git a/include/gpio.h b/include/gpio.h
index adc1eb39ac..71896c9d6b 100644
--- a/include/gpio.h
+++ b/include/gpio.h
@@ -208,6 +208,8 @@ struct gpio_chip {
 	struct device *dev;
 
 	int base;
+	/* GPIO controller specific GPIO offset */
+	int gpio_offset;
 	int ngpio;
 
 #if defined(CONFIG_OF_GPIO)
-- 
2.39.2




^ permalink raw reply	[flat|nested] 3+ messages in thread

* [PATCH v1 2/2] pinctrl: stm32: extract and set GPIO offset from devicetree
  2024-05-29  4:53 [PATCH v1 1/2] gpiolib: extend support for non-zero offset GPIO banks Oleksij Rempel
@ 2024-05-29  4:53 ` Oleksij Rempel
  2024-05-29  6:19 ` [PATCH v1 1/2] gpiolib: extend support for non-zero offset GPIO banks Sascha Hauer
  1 sibling, 0 replies; 3+ messages in thread
From: Oleksij Rempel @ 2024-05-29  4:53 UTC (permalink / raw)
  To: barebox; +Cc: Oleksij Rempel

Update pinctrl-stm32 driver to read gpio_offset from the devicetree
and set it in gpiolib. This enables correct handling of GPIO banks
on stm32mp151aad3, which have non-zero starting indices for some
banks.

Signed-off-by: Oleksij Rempel <o.rempel@pengutronix.de>
---
 drivers/pinctrl/pinctrl-stm32.c | 1 +
 1 file changed, 1 insertion(+)

diff --git a/drivers/pinctrl/pinctrl-stm32.c b/drivers/pinctrl/pinctrl-stm32.c
index 63a01b6ec6..4a4b03ac0e 100644
--- a/drivers/pinctrl/pinctrl-stm32.c
+++ b/drivers/pinctrl/pinctrl-stm32.c
@@ -319,6 +319,7 @@ static int stm32_gpiochip_add(struct stm32_gpio_bank *bank,
 	bank->base = IOMEM(iores->start);
 
 	bank->chip.base = be32_to_cpu(gpio_ranges[PINCTRL_OFFSET]);
+	bank->chip.gpio_offset = be32_to_cpu(gpio_ranges[GPIOCTRL_OFFSET]);
 	bank->chip.ops  = &stm32_gpio_ops;
 	bank->chip.dev  = dev;
 
-- 
2.39.2




^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH v1 1/2] gpiolib: extend support for non-zero offset GPIO banks
  2024-05-29  4:53 [PATCH v1 1/2] gpiolib: extend support for non-zero offset GPIO banks Oleksij Rempel
  2024-05-29  4:53 ` [PATCH v1 2/2] pinctrl: stm32: extract and set GPIO offset from devicetree Oleksij Rempel
@ 2024-05-29  6:19 ` Sascha Hauer
  1 sibling, 0 replies; 3+ messages in thread
From: Sascha Hauer @ 2024-05-29  6:19 UTC (permalink / raw)
  To: barebox, Oleksij Rempel


On Wed, 29 May 2024 06:53:10 +0200, Oleksij Rempel wrote:
> Introduce gpio_offset variable in gpiolib to handle GPIO controllers
> with non-zero starting indices. This is necessary for stm32mp151aad3,
> which includes GPIO banks with 6 and 10 lines that do not start from 0.
> 
> 

Applied, thanks!

[1/2] gpiolib: extend support for non-zero offset GPIO banks
      https://git.pengutronix.de/cgit/barebox/commit/?id=9fdb89b620c0 (link may not be stable)
[2/2] pinctrl: stm32: extract and set GPIO offset from devicetree
      https://git.pengutronix.de/cgit/barebox/commit/?id=1f5bdfbdae27 (link may not be stable)

Best regards,
-- 
Sascha Hauer <s.hauer@pengutronix.de>




^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2024-05-29  6:19 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2024-05-29  4:53 [PATCH v1 1/2] gpiolib: extend support for non-zero offset GPIO banks Oleksij Rempel
2024-05-29  4:53 ` [PATCH v1 2/2] pinctrl: stm32: extract and set GPIO offset from devicetree Oleksij Rempel
2024-05-29  6:19 ` [PATCH v1 1/2] gpiolib: extend support for non-zero offset GPIO banks Sascha Hauer

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox