[PATCH v1 1/2] gpiolib: extend support for non-zero offset GPIO banks
Oleksij Rempel
o.rempel at pengutronix.de
Tue May 28 21:53:10 PDT 2024
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 at 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
More information about the barebox
mailing list