diff options
author | Ahmad Fatoum <a.fatoum@pengutronix.de> | 2022-09-05 12:35:46 +0200 |
---|---|---|
committer | Sascha Hauer <s.hauer@pengutronix.de> | 2022-09-13 12:07:55 +0200 |
commit | a30ae2921a78d68eee4cd526e9e200aba28aadc3 (patch) | |
tree | d70e6f784228dec21b3337da853745fa8fcf6443 /drivers | |
parent | 04443dc5fc0ea0b0bd7eb40408774b6db8a0c399 (diff) | |
download | barebox-a30ae2921a78d68eee4cd526e9e200aba28aadc3.tar.gz barebox-a30ae2921a78d68eee4cd526e9e200aba28aadc3.tar.xz |
gpiolib: gpioinfo: add optional CONTROLLER command line argument
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>
Link: https://lore.barebox.org/20220905103546.1476277-6-a.fatoum@pengutronix.de
Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
Diffstat (limited to 'drivers')
-rw-r--r-- | drivers/gpio/gpiolib.c | 31 |
1 files changed, 26 insertions, 5 deletions
diff --git a/drivers/gpio/gpiolib.c b/drivers/gpio/gpiolib.c index cf61213ca1..7f20709035 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 |