diff --git a/commands/gpio.c b/commands/gpio.c index 951ad2c..6d88ab6 100644 --- a/commands/gpio.c +++ b/commands/gpio.c @@ -25,7 +25,9 @@ if (argc < count) return COMMAND_ERROR_USAGE; - *gpio = gpio_find_by_label(argv[1]); + *gpio = gpio_find_by_name(argv[1]); + if (*gpio < 0) + *gpio = gpio_find_by_label(argv[1]); if (*gpio < 0) { ret = kstrtoint(argv[1], 0, gpio); if (ret < 0) diff --git a/drivers/gpio/gpiolib.c b/drivers/gpio/gpiolib.c index f960098..057cea4 100644 --- a/drivers/gpio/gpiolib.c +++ b/drivers/gpio/gpiolib.c @@ -16,6 +16,7 @@ bool requested; bool active_low; char *label; + char *name; }; static struct gpio_info *gpio_desc; @@ -108,6 +109,23 @@ return -ENOENT; } +int gpio_find_by_name(const char *name) +{ + int i; + + for (i = 0; i < ARCH_NR_GPIOS; i++) { + struct gpio_info *info = &gpio_desc[i]; + + if (!info->chip || !info->name) + continue; + + if (!strcmp(info->name, name)) + return i; + } + + return -ENOENT; +} + void gpio_free(unsigned gpio) { struct gpio_info *gi = gpio_to_desc(gpio); @@ -500,7 +518,7 @@ gi->chip->base, gi->chip->base + gi->chip->ngpio - 1, gi->chip->dev->name); - printf("%*cdir val requested label\n", 13, ' '); + printf(" %-3s %-3s %-9s %-20s %-20s\n", "dir", "val", "requested", "name", "label"); } if (gi->chip->ops->get_direction) @@ -510,11 +528,12 @@ val = gi->chip->ops->get(gi->chip, i - gi->chip->base); - printf(" GPIO %*d: %*s %*s %*s %s\n", 4, i, - 3, (dir < 0) ? "unk" : ((dir == GPIOF_DIR_IN) ? "in" : "out"), - 3, (val < 0) ? "unk" : ((val == 0) ? "lo" : "hi"), - 12, gi->requested ? (gi->active_low ? "active low" : "true") : "false", - (gi->requested && gi->label) ? gi->label : ""); + printf(" GPIO %4d: %-3s %-3s %-9s %-20s %-20s\n", 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", + gi->name ? gi->name : "", + gi->label ? gi->label : ""); } return 0; diff --git a/include/gpio.h b/include/gpio.h index 4d5f2c2..0c0c033 100644 --- a/include/gpio.h +++ b/include/gpio.h @@ -114,6 +114,11 @@ return 0; } +static inline int gpio_find_by_name(const char *name) +{ + return -ENOSYS; +} + static inline int gpio_find_by_label(const char *label) { return -ENOSYS; @@ -141,6 +146,7 @@ } #else int gpio_request(unsigned gpio, const char *label); +int gpio_find_by_name(const char *name); int gpio_find_by_label(const char *label); void gpio_free(unsigned gpio); int gpio_request_one(unsigned gpio, unsigned long flags, const char *label);