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 5/5] gpiolib: gpioinfo: add optional CONTROLLER command line argument
Date: Mon,  5 Sep 2022 12:35:46 +0200	[thread overview]
Message-ID: <20220905103546.1476277-6-a.fatoum@pengutronix.de> (raw)
In-Reply-To: <20220905103546.1476277-1-a.fatoum@pengutronix.de>

Like done with gpio setter/getter functions in the previous commit,
extend the gpioinfo command to accept an optional argument that
restricts output to the supplied gpio controller instead of printing
all GPIOs at once.

Signed-off-by: Ahmad Fatoum <a.fatoum@pengutronix.de>
---
 drivers/gpio/gpiolib.c | 31 ++++++++++++++++++++++++++-----
 1 file changed, 26 insertions(+), 5 deletions(-)

diff --git a/drivers/gpio/gpiolib.c b/drivers/gpio/gpiolib.c
index cf61213ca12d..7f2070903501 100644
--- a/drivers/gpio/gpiolib.c
+++ b/drivers/gpio/gpiolib.c
@@ -675,15 +675,35 @@ struct gpio_chip *gpio_get_chip(int gpio)
 #ifdef CONFIG_CMD_GPIO
 static int do_gpiolib(int argc, char *argv[])
 {
+	struct gpio_chip *chip = NULL;
 	int i;
 
+	if (argc > 2)
+		return COMMAND_ERROR_USAGE;
+
+	if (argc == 1) {
+		struct device_d *dev;
+
+		dev = find_device(argv[1]);
+		if (!dev)
+			return -ENODEV;
+
+		chip = gpio_get_chip_by_dev(dev);
+		if (!chip)
+			return -EINVAL;
+	}
+
 	for (i = 0; i < ARCH_NR_GPIOS; i++) {
 		struct gpio_info *gi = &gpio_desc[i];
 		int val = -1, dir = -1;
+		int idx;
 
 		if (!gi->chip)
 			continue;
 
+		if (chip && chip != gi->chip)
+			continue;
+
 		/* print chip information and header on first gpio */
 		if (gi->chip->base == i) {
 			printf("\nGPIOs %u-%u, chip %s:\n",
@@ -693,14 +713,14 @@ static int do_gpiolib(int argc, char *argv[])
 			printf("             %-3s %-3s %-9s %-20s %-20s\n", "dir", "val", "requested", "name", "label");
 		}
 
+		idx = i - gi->chip->base;
+
 		if (gi->chip->ops->get_direction)
-			dir = gi->chip->ops->get_direction(gi->chip,
-						i - gi->chip->base);
+			dir = gi->chip->ops->get_direction(gi->chip, idx);
 		if (gi->chip->ops->get)
-			val = gi->chip->ops->get(gi->chip,
-						i - gi->chip->base);
+			val = gi->chip->ops->get(gi->chip, idx);
 
-		printf("  GPIO %4d: %-3s %-3s %-9s %-20s %-20s\n", i,
+		printf("  GPIO %4d: %-3s %-3s %-9s %-20s %-20s\n", chip ? idx : i,
 			(dir < 0) ? "unk" : ((dir == GPIOF_DIR_IN) ? "in" : "out"),
 			(val < 0) ? "unk" : ((val == 0) ? "lo" : "hi"),
 		        gi->requested ? (gi->active_low ? "active low" : "true") : "false",
@@ -714,6 +734,7 @@ static int do_gpiolib(int argc, char *argv[])
 BAREBOX_CMD_START(gpioinfo)
 	.cmd		= do_gpiolib,
 	BAREBOX_CMD_DESC("list registered GPIOs")
+	BAREBOX_CMD_OPTS("[CONTROLLER]")
 	BAREBOX_CMD_GROUP(CMD_GRP_INFO)
 	BAREBOX_CMD_COMPLETE(empty_complete)
 BAREBOX_CMD_END
-- 
2.30.2




  parent 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 ` [PATCH 1/5] gpiolib: implement gpio_get_chip_by_dev() Ahmad Fatoum
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 ` Ahmad Fatoum [this message]
2022-09-28 13:22   ` [PATCH 5/5] gpiolib: gpioinfo: add optional CONTROLLER command line argument 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-6-a.fatoum@pengutronix.de \
    --to=a.fatoum@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