Commit df4878e9 authored by Linus Walleij's avatar Linus Walleij

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: default avatarLinus Walleij <linus.walleij@linaro.org>
parent 0a7439ef
...@@ -342,6 +342,9 @@ static long gpio_ioctl(struct file *filp, unsigned int cmd, unsigned long arg) ...@@ -342,6 +342,9 @@ static long gpio_ioctl(struct file *filp, unsigned int cmd, unsigned long arg)
strncpy(chipinfo.name, dev_name(&gdev->dev), strncpy(chipinfo.name, dev_name(&gdev->dev),
sizeof(chipinfo.name)); sizeof(chipinfo.name));
chipinfo.name[sizeof(chipinfo.name)-1] = '\0'; chipinfo.name[sizeof(chipinfo.name)-1] = '\0';
strncpy(chipinfo.label, gdev->label,
sizeof(chipinfo.label));
chipinfo.label[sizeof(chipinfo.label)-1] = '\0';
chipinfo.lines = gdev->ngpio; chipinfo.lines = gdev->ngpio;
if (copy_to_user(ip, &chipinfo, sizeof(chipinfo))) if (copy_to_user(ip, &chipinfo, sizeof(chipinfo)))
return -EFAULT; return -EFAULT;
...@@ -479,6 +482,16 @@ int gpiochip_add_data(struct gpio_chip *chip, void *data) ...@@ -479,6 +482,16 @@ int gpiochip_add_data(struct gpio_chip *chip, void *data)
status = -EINVAL; status = -EINVAL;
goto err_free_gdev; goto err_free_gdev;
} }
if (chip->label)
gdev->label = devm_kstrdup(&gdev->dev, chip->label, GFP_KERNEL);
else
gdev->label = devm_kstrdup(&gdev->dev, "unknown", GFP_KERNEL);
if (!gdev->label) {
status = -ENOMEM;
goto err_free_gdev;
}
gdev->ngpio = chip->ngpio; gdev->ngpio = chip->ngpio;
gdev->data = data; gdev->data = data;
......
...@@ -37,6 +37,8 @@ struct acpi_device; ...@@ -37,6 +37,8 @@ struct acpi_device;
* of the @descs array. * of the @descs array.
* @base: GPIO base in the DEPRECATED global Linux GPIO numberspace, assigned * @base: GPIO base in the DEPRECATED global Linux GPIO numberspace, assigned
* at device creation time. * at device creation time.
* @label: a descriptive name for the GPIO device, such as the part number
* or name of the IP component in a System on Chip.
* @data: per-instance data assigned by the driver * @data: per-instance data assigned by the driver
* @list: links gpio_device:s together for traversal * @list: links gpio_device:s together for traversal
* *
...@@ -55,6 +57,7 @@ struct gpio_device { ...@@ -55,6 +57,7 @@ struct gpio_device {
struct gpio_desc *descs; struct gpio_desc *descs;
int base; int base;
u16 ngpio; u16 ngpio;
char *label;
void *data; void *data;
struct list_head list; struct list_head list;
......
...@@ -21,7 +21,8 @@ struct gpio_device; ...@@ -21,7 +21,8 @@ struct gpio_device;
/** /**
* struct gpio_chip - abstract a GPIO controller * struct gpio_chip - abstract a GPIO controller
* @label: for diagnostics * @label: a functional name for the GPIO device, such as a part
* number or the name of the SoC IP-block implementing it.
* @gpiodev: the internal state holder, opaque struct * @gpiodev: the internal state holder, opaque struct
* @parent: optional parent device providing the GPIOs * @parent: optional parent device providing the GPIOs
* @owner: helps prevent removal of modules exporting active GPIOs * @owner: helps prevent removal of modules exporting active GPIOs
......
...@@ -16,10 +16,12 @@ ...@@ -16,10 +16,12 @@
/** /**
* struct gpiochip_info - Information about a certain GPIO chip * struct gpiochip_info - Information about a certain GPIO chip
* @name: the name of this GPIO chip * @name: the name of this GPIO chip
* @label: a functional name for this GPIO chip
* @lines: number of GPIO lines on this chip * @lines: number of GPIO lines on this chip
*/ */
struct gpiochip_info { struct gpiochip_info {
char name[32]; char name[32];
char label[32];
__u32 lines; __u32 lines;
}; };
......
...@@ -54,8 +54,8 @@ int list_device(const char *device_name) ...@@ -54,8 +54,8 @@ int list_device(const char *device_name)
goto free_chrdev_name; goto free_chrdev_name;
} }
fprintf(stdout, "GPIO chip: %s, %u GPIO lines\n", fprintf(stdout, "GPIO chip: %s, \"%s\", %u GPIO lines\n",
cinfo.name, cinfo.lines); cinfo.name, cinfo.label, cinfo.lines);
if (close(fd) == -1) { if (close(fd) == -1) {
ret = -errno; ret = -errno;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment