summaryrefslogtreecommitdiffstats
path: root/drivers
diff options
context:
space:
mode:
authorSascha Hauer <s.hauer@pengutronix.de>2019-11-22 09:41:24 +0100
committerSascha Hauer <s.hauer@pengutronix.de>2019-11-27 12:07:07 +0100
commit17a517c0fcf21cbd1882108c18fa845930927563 (patch)
treee51784330e1f1318709eba4a573493c2cef1c8d5 /drivers
parent6441dfa8307a564f797b868a74205fe9c2f42eb0 (diff)
downloadbarebox-17a517c0fcf21cbd1882108c18fa845930927563.tar.gz
barebox-17a517c0fcf21cbd1882108c18fa845930927563.tar.xz
gpio: Introduce GPIO names
This introduces GPIO names. So far we only have labels which are given by the requester. In contrast names are given by the provider and do not change depending on whoever requests a GPIO. The gpio commands now also accept to reference a GPIO by name. The printing of the gpioinfo command is adjusted to nicely print both the label and the name. Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
Diffstat (limited to 'drivers')
-rw-r--r--drivers/gpio/gpiolib.c31
1 files changed, 25 insertions, 6 deletions
diff --git a/drivers/gpio/gpiolib.c b/drivers/gpio/gpiolib.c
index f96009896a..057cea43cc 100644
--- a/drivers/gpio/gpiolib.c
+++ b/drivers/gpio/gpiolib.c
@@ -16,6 +16,7 @@ struct gpio_info {
bool requested;
bool active_low;
char *label;
+ char *name;
};
static struct gpio_info *gpio_desc;
@@ -108,6 +109,23 @@ int gpio_find_by_label(const char *label)
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 @@ static int do_gpiolib(int argc, char *argv[])
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 @@ static int do_gpiolib(int argc, char *argv[])
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;