mail archive of the barebox mailing list
 help / color / mirror / Atom feed
From: Sascha Hauer <s.hauer@pengutronix.de>
To: Barebox List <barebox@lists.infradead.org>
Subject: [PATCH 1/4] gpio: allow -gpio suffix for gpio property names
Date: Tue,  8 Jun 2021 11:36:32 +0200	[thread overview]
Message-ID: <20210608093635.5749-2-s.hauer@pengutronix.de> (raw)
In-Reply-To: <20210608093635.5749-1-s.hauer@pengutronix.de>

GPIO properties in the device tree can have a -gpios suffix or a -gpio
suffix. The latter was not handled, this patch changes that.

Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
---
 drivers/gpio/gpiolib.c | 30 +++++++++++++++++++++---------
 1 file changed, 21 insertions(+), 9 deletions(-)

diff --git a/drivers/gpio/gpiolib.c b/drivers/gpio/gpiolib.c
index 7b7261d01f..387b410f12 100644
--- a/drivers/gpio/gpiolib.c
+++ b/drivers/gpio/gpiolib.c
@@ -555,27 +555,39 @@ static int of_gpiochip_scan_hogs(struct gpio_chip *chip)
 	return 0;
 }
 
+static const char *gpio_suffixes[] = {
+	"gpios",
+	"gpio",
+};
+
 /* Linux compatibility helper: Get a GPIO descriptor from device tree */
 int gpiod_get(struct device_d *dev, const char *_con_id, enum gpiod_flags flags)
 {
 	struct device_node *np = dev->device_node;
 	enum of_gpio_flags of_flags;
-	const char *con_id = "gpios", *label = dev_name(dev);
-	char *buf = NULL;
+	const char *label = dev_name(dev);
+	char *buf = NULL, *con_id;
 	int gpio;
-	int ret;
+	int ret, i;
 
 	if (!IS_ENABLED(CONFIG_OFDEVICE) || !dev->device_node)
 		return -ENODEV;
 
-	if (_con_id) {
-		con_id = buf = basprintf("%s-gpios", _con_id);
-		if (!buf)
+	for (i = 0; i < ARRAY_SIZE(gpio_suffixes); i++) {
+		if (_con_id)
+			con_id = basprintf("%s-%s", _con_id, gpio_suffixes[i]);
+		else
+			con_id = basprintf("%s", gpio_suffixes[i]);
+
+		if (!con_id)
 			return -ENOMEM;
-	}
 
-	gpio = of_get_named_gpio_flags(np, con_id, 0, &of_flags);
-	free(buf);
+		gpio = of_get_named_gpio_flags(np, con_id, 0, &of_flags);
+		free(con_id);
+
+		if (gpio_is_valid(gpio))
+			break;
+	}
 
 	if (!gpio_is_valid(gpio))
 		return gpio < 0 ? gpio : -EINVAL;
-- 
2.29.2


_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox


  reply	other threads:[~2021-06-08  9:38 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-06-08  9:36 [PATCH v2 0/4] Rockchip eqos support Sascha Hauer
2021-06-08  9:36 ` Sascha Hauer [this message]
2021-06-08  9:36 ` [PATCH 2/4] net: designware: eqos: reset phy Sascha Hauer
2021-06-08  9:36 ` [PATCH 3/4] net: designware: eqos: set mdio bus device node Sascha Hauer
2021-06-08  9:36 ` [PATCH 4/4] net: eqos: Rockchip support 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=20210608093635.5749-2-s.hauer@pengutronix.de \
    --to=s.hauer@pengutronix.de \
    --cc=barebox@lists.infradead.org \
    --subject='Re: [PATCH 1/4] gpio: allow -gpio suffix for gpio property names' \
    /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