mail archive of the barebox mailing list
 help / color / mirror / Atom feed
From: Oleksij Rempel <o.rempel@pengutronix.de>
To: barebox@lists.infradead.org
Cc: Oleksij Rempel <o.rempel@pengutronix.de>
Subject: [PATCH v1 1/2] gpiolib: extend support for non-zero offset GPIO banks
Date: Wed, 29 May 2024 06:53:10 +0200	[thread overview]
Message-ID: <20240529045311.3227151-1-o.rempel@pengutronix.de> (raw)

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




             reply	other threads:[~2024-05-29  4:53 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-05-29  4:53 Oleksij Rempel [this message]
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

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=20240529045311.3227151-1-o.rempel@pengutronix.de \
    --to=o.rempel@pengutronix.de \
    --cc=barebox@lists.infradead.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