Skip to content

Commit df4878e

Browse files
author
Linus Walleij
committed
gpio: store reflect the label to userspace
The gpio_chip label is useful for userspace to understand what kind of GPIO chip it is dealing with. Let's store a copy of this label in the gpio_device, add it to the struct passed to userspace for GPIO_GET_CHIPINFO_IOCTL and modify lsgpio to show it. Signed-off-by: Linus Walleij <linus.walleij@linaro.org>
1 parent 0a7439e commit df4878e

5 files changed

Lines changed: 22 additions & 3 deletions

File tree

drivers/gpio/gpiolib.c

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -342,6 +342,9 @@ static long gpio_ioctl(struct file *filp, unsigned int cmd, unsigned long arg)
342342
strncpy(chipinfo.name, dev_name(&gdev->dev),
343343
sizeof(chipinfo.name));
344344
chipinfo.name[sizeof(chipinfo.name)-1] = '\0';
345+
strncpy(chipinfo.label, gdev->label,
346+
sizeof(chipinfo.label));
347+
chipinfo.label[sizeof(chipinfo.label)-1] = '\0';
345348
chipinfo.lines = gdev->ngpio;
346349
if (copy_to_user(ip, &chipinfo, sizeof(chipinfo)))
347350
return -EFAULT;
@@ -479,6 +482,16 @@ int gpiochip_add_data(struct gpio_chip *chip, void *data)
479482
status = -EINVAL;
480483
goto err_free_gdev;
481484
}
485+
486+
if (chip->label)
487+
gdev->label = devm_kstrdup(&gdev->dev, chip->label, GFP_KERNEL);
488+
else
489+
gdev->label = devm_kstrdup(&gdev->dev, "unknown", GFP_KERNEL);
490+
if (!gdev->label) {
491+
status = -ENOMEM;
492+
goto err_free_gdev;
493+
}
494+
482495
gdev->ngpio = chip->ngpio;
483496
gdev->data = data;
484497

drivers/gpio/gpiolib.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,8 @@ struct acpi_device;
3737
* of the @descs array.
3838
* @base: GPIO base in the DEPRECATED global Linux GPIO numberspace, assigned
3939
* at device creation time.
40+
* @label: a descriptive name for the GPIO device, such as the part number
41+
* or name of the IP component in a System on Chip.
4042
* @data: per-instance data assigned by the driver
4143
* @list: links gpio_device:s together for traversal
4244
*
@@ -55,6 +57,7 @@ struct gpio_device {
5557
struct gpio_desc *descs;
5658
int base;
5759
u16 ngpio;
60+
char *label;
5861
void *data;
5962
struct list_head list;
6063

include/linux/gpio/driver.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,8 @@ struct gpio_device;
2121

2222
/**
2323
* struct gpio_chip - abstract a GPIO controller
24-
* @label: for diagnostics
24+
* @label: a functional name for the GPIO device, such as a part
25+
* number or the name of the SoC IP-block implementing it.
2526
* @gpiodev: the internal state holder, opaque struct
2627
* @parent: optional parent device providing the GPIOs
2728
* @owner: helps prevent removal of modules exporting active GPIOs

include/uapi/linux/gpio.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,12 @@
1616
/**
1717
* struct gpiochip_info - Information about a certain GPIO chip
1818
* @name: the name of this GPIO chip
19+
* @label: a functional name for this GPIO chip
1920
* @lines: number of GPIO lines on this chip
2021
*/
2122
struct gpiochip_info {
2223
char name[32];
24+
char label[32];
2325
__u32 lines;
2426
};
2527

tools/gpio/lsgpio.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -54,8 +54,8 @@ int list_device(const char *device_name)
5454

5555
goto free_chrdev_name;
5656
}
57-
fprintf(stdout, "GPIO chip: %s, %u GPIO lines\n",
58-
cinfo.name, cinfo.lines);
57+
fprintf(stdout, "GPIO chip: %s, \"%s\", %u GPIO lines\n",
58+
cinfo.name, cinfo.label, cinfo.lines);
5959

6060
if (close(fd) == -1) {
6161
ret = -errno;

0 commit comments

Comments
 (0)