mail archive of the barebox mailing list
 help / color / mirror / Atom feed
From: Ahmad Fatoum <a.fatoum@pengutronix.de>
To: barebox@lists.infradead.org
Cc: Ahmad Fatoum <a.fatoum@pengutronix.de>
Subject: [PATCH 1/5] gpiolib: implement gpio_get_chip_by_dev()
Date: Mon,  5 Sep 2022 12:35:42 +0200	[thread overview]
Message-ID: <20220905103546.1476277-2-a.fatoum@pengutronix.de> (raw)
In-Reply-To: <20220905103546.1476277-1-a.fatoum@pengutronix.de>

gpio_of_xlate() already needs the ability to find a struct gpio_chip *
via a struct device_d. Exporting this functionality to elsewhere in the
code will allow restricting commands to manipulate only a single GPIO
bank.

Signed-off-by: Ahmad Fatoum <a.fatoum@pengutronix.de>
---
 drivers/gpio/gpiolib.c | 28 +++++++++++++++++++---------
 include/gpio.h         |  1 +
 2 files changed, 20 insertions(+), 9 deletions(-)

diff --git a/drivers/gpio/gpiolib.c b/drivers/gpio/gpiolib.c
index 97a99b84e32a..cf61213ca12d 100644
--- a/drivers/gpio/gpiolib.c
+++ b/drivers/gpio/gpiolib.c
@@ -636,6 +636,18 @@ static int of_gpio_simple_xlate(struct gpio_chip *chip,
 	return chip->base + gpiospec->args[0];
 }
 
+struct gpio_chip *gpio_get_chip_by_dev(struct device_d *dev)
+{
+	struct gpio_chip *chip;
+
+	list_for_each_entry(chip, &chip_list, list) {
+		if (chip->dev == dev)
+			return chip;
+	}
+
+	return NULL;
+}
+
 int gpio_of_xlate(struct device_d *dev, struct of_phandle_args *gpiospec, int *flags)
 {
 	struct gpio_chip *chip;
@@ -643,16 +655,14 @@ int gpio_of_xlate(struct device_d *dev, struct of_phandle_args *gpiospec, int *f
 	if (!dev)
 		return -ENODEV;
 
-	list_for_each_entry(chip, &chip_list, list) {
-		if (chip->dev != dev)
-			continue;
-		if (chip->ops->of_xlate)
-			return chip->ops->of_xlate(chip, gpiospec, flags);
-		else
-			return of_gpio_simple_xlate(chip, gpiospec, flags);
-	}
+	chip = gpio_get_chip_by_dev(dev);
+	if (!chip)
+		return -EPROBE_DEFER;
 
-	return -EPROBE_DEFER;
+	if (chip->ops->of_xlate)
+		return chip->ops->of_xlate(chip, gpiospec, flags);
+	else
+		return of_gpio_simple_xlate(chip, gpiospec, flags);
 }
 
 struct gpio_chip *gpio_get_chip(int gpio)
diff --git a/include/gpio.h b/include/gpio.h
index 8218722dcbf0..82f2eb6b8a34 100644
--- a/include/gpio.h
+++ b/include/gpio.h
@@ -190,5 +190,6 @@ void gpiochip_remove(struct gpio_chip *chip);
 
 int gpio_of_xlate(struct device_d *dev, struct of_phandle_args *gpiospec, int *flags);
 struct gpio_chip *gpio_get_chip(int gpio);
+struct gpio_chip *gpio_get_chip_by_dev(struct device_d *);
 
 #endif /* __GPIO_H */
-- 
2.30.2




  reply	other threads:[~2022-09-05 17:44 UTC|newest]

Thread overview: 12+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-09-05 10:35 [PATCH 0/5] commands: gpio: add controller as optional argument Ahmad Fatoum
2022-09-05 10:35 ` Ahmad Fatoum [this message]
2022-09-05 10:35 ` [PATCH 2/5] of: platform: optimize of_find_device_by_node when deep probing Ahmad Fatoum
2022-09-05 10:35 ` [PATCH 3/5] driver: implement find_device() helper Ahmad Fatoum
2022-09-05 10:35 ` [PATCH 4/5] commands: gpio: add -d argument to set/get commands Ahmad Fatoum
2022-09-28 13:37   ` Enrico Scholz
2022-09-28 14:36     ` Sascha Hauer
2022-09-29  9:50     ` Ahmad Fatoum
2022-09-05 10:35 ` [PATCH 5/5] gpiolib: gpioinfo: add optional CONTROLLER command line argument Ahmad Fatoum
2022-09-28 13:22   ` Enrico Scholz
2022-09-28 14:24     ` Sascha Hauer
2022-09-12  9:13 ` [PATCH 0/5] commands: gpio: add controller as optional argument 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=20220905103546.1476277-2-a.fatoum@pengutronix.de \
    --to=a.fatoum@pengutronix.de \
    --cc=barebox@lists.infradead.org \
    --subject='Re: [PATCH 1/5] gpiolib: implement gpio_get_chip_by_dev()' \
    /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

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