aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorLinus Walleij <linus.walleij@linaro.org>2016-02-12 08:48:23 -0500
committerLinus Walleij <linus.walleij@linaro.org>2016-02-19 03:48:41 -0500
commitdf4878e969ccc047da45d2cd3af5d08031da1593 (patch)
tree2677387492b60fd5c6a42a317bde0e7e965aa8fa
parent0a7439ef755d46a2e61d460d7a440f7fa65d7182 (diff)
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>
-rw-r--r--drivers/gpio/gpiolib.c13
-rw-r--r--drivers/gpio/gpiolib.h3
-rw-r--r--include/linux/gpio/driver.h3
-rw-r--r--include/uapi/linux/gpio.h2
-rw-r--r--tools/gpio/lsgpio.c4
5 files changed, 22 insertions, 3 deletions
diff --git a/drivers/gpio/gpiolib.c b/drivers/gpio/gpiolib.c
index 59f0045c5950..797c790aa750 100644
--- a/drivers/gpio/gpiolib.c
+++ b/drivers/gpio/gpiolib.c
@@ -342,6 +342,9 @@ static long gpio_ioctl(struct file *filp, unsigned int cmd, unsigned long arg)
342 strncpy(chipinfo.name, dev_name(&gdev->dev), 342 strncpy(chipinfo.name, dev_name(&gdev->dev),
343 sizeof(chipinfo.name)); 343 sizeof(chipinfo.name));
344 chipinfo.name[sizeof(chipinfo.name)-1] = '\0'; 344 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';
345 chipinfo.lines = gdev->ngpio; 348 chipinfo.lines = gdev->ngpio;
346 if (copy_to_user(ip, &chipinfo, sizeof(chipinfo))) 349 if (copy_to_user(ip, &chipinfo, sizeof(chipinfo)))
347 return -EFAULT; 350 return -EFAULT;
@@ -479,6 +482,16 @@ int gpiochip_add_data(struct gpio_chip *chip, void *data)
479 status = -EINVAL; 482 status = -EINVAL;
480 goto err_free_gdev; 483 goto err_free_gdev;
481 } 484 }
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
482 gdev->ngpio = chip->ngpio; 495 gdev->ngpio = chip->ngpio;
483 gdev->data = data; 496 gdev->data = data;
484 497
diff --git a/drivers/gpio/gpiolib.h b/drivers/gpio/gpiolib.h
index ddbe409ad48f..e30e5fdb1214 100644
--- a/drivers/gpio/gpiolib.h
+++ b/drivers/gpio/gpiolib.h
@@ -37,6 +37,8 @@ struct acpi_device;
37 * of the @descs array. 37 * of the @descs array.
38 * @base: GPIO base in the DEPRECATED global Linux GPIO numberspace, assigned 38 * @base: GPIO base in the DEPRECATED global Linux GPIO numberspace, assigned
39 * at device creation time. 39 * 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.
40 * @data: per-instance data assigned by the driver 42 * @data: per-instance data assigned by the driver
41 * @list: links gpio_device:s together for traversal 43 * @list: links gpio_device:s together for traversal
42 * 44 *
@@ -55,6 +57,7 @@ struct gpio_device {
55 struct gpio_desc *descs; 57 struct gpio_desc *descs;
56 int base; 58 int base;
57 u16 ngpio; 59 u16 ngpio;
60 char *label;
58 void *data; 61 void *data;
59 struct list_head list; 62 struct list_head list;
60 63
diff --git a/include/linux/gpio/driver.h b/include/linux/gpio/driver.h
index ff96d0f9fceb..639607658ed8 100644
--- a/include/linux/gpio/driver.h
+++ b/include/linux/gpio/driver.h
@@ -21,7 +21,8 @@ struct gpio_device;
21 21
22/** 22/**
23 * struct gpio_chip - abstract a GPIO controller 23 * 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.
25 * @gpiodev: the internal state holder, opaque struct 26 * @gpiodev: the internal state holder, opaque struct
26 * @parent: optional parent device providing the GPIOs 27 * @parent: optional parent device providing the GPIOs
27 * @owner: helps prevent removal of modules exporting active GPIOs 28 * @owner: helps prevent removal of modules exporting active GPIOs
diff --git a/include/uapi/linux/gpio.h b/include/uapi/linux/gpio.h
index 3188a87bdaa0..3f93e1bcd3dd 100644
--- a/include/uapi/linux/gpio.h
+++ b/include/uapi/linux/gpio.h
@@ -16,10 +16,12 @@
16/** 16/**
17 * struct gpiochip_info - Information about a certain GPIO chip 17 * struct gpiochip_info - Information about a certain GPIO chip
18 * @name: the name of this GPIO chip 18 * @name: the name of this GPIO chip
19 * @label: a functional name for this GPIO chip
19 * @lines: number of GPIO lines on this chip 20 * @lines: number of GPIO lines on this chip
20 */ 21 */
21struct gpiochip_info { 22struct gpiochip_info {
22 char name[32]; 23 char name[32];
24 char label[32];
23 __u32 lines; 25 __u32 lines;
24}; 26};
25 27
diff --git a/tools/gpio/lsgpio.c b/tools/gpio/lsgpio.c
index 4cfe29da279b..692233f561fb 100644
--- a/tools/gpio/lsgpio.c
+++ b/tools/gpio/lsgpio.c
@@ -54,8 +54,8 @@ int list_device(const char *device_name)
54 54
55 goto free_chrdev_name; 55 goto free_chrdev_name;
56 } 56 }
57 fprintf(stdout, "GPIO chip: %s, %u GPIO lines\n", 57 fprintf(stdout, "GPIO chip: %s, \"%s\", %u GPIO lines\n",
58 cinfo.name, cinfo.lines); 58 cinfo.name, cinfo.label, cinfo.lines);
59 59
60 if (close(fd) == -1) { 60 if (close(fd) == -1) {
61 ret = -errno; 61 ret = -errno;