gpio: store reflect the label to userspace
authorLinus Walleij <linus.walleij@linaro.org>
Fri, 12 Feb 2016 13:48:23 +0000 (14:48 +0100)
committerLinus Walleij <linus.walleij@linaro.org>
Fri, 19 Feb 2016 08:48:41 +0000 (09:48 +0100)
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>
drivers/gpio/gpiolib.c
drivers/gpio/gpiolib.h
include/linux/gpio/driver.h
include/uapi/linux/gpio.h
tools/gpio/lsgpio.c

index 59f0045c5950f4d3a7d076dba321287410ac13c9..797c790aa7506c42ea748e2c030b5f692f82f2e8 100644 (file)
@@ -342,6 +342,9 @@ static long gpio_ioctl(struct file *filp, unsigned int cmd, unsigned long arg)
                strncpy(chipinfo.name, dev_name(&gdev->dev),
                        sizeof(chipinfo.name));
                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;
                if (copy_to_user(ip, &chipinfo, sizeof(chipinfo)))
                        return -EFAULT;
@@ -479,6 +482,16 @@ int gpiochip_add_data(struct gpio_chip *chip, void *data)
                status = -EINVAL;
                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->data = data;
 
index ddbe409ad48fc1a41f82eb7cbd5b583c3f4519bc..e30e5fdb12140383ab3259b33b2c2921be1356f9 100644 (file)
@@ -37,6 +37,8 @@ struct acpi_device;
  * of the @descs array.
  * @base: GPIO base in the DEPRECATED global Linux GPIO numberspace, assigned
  * 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
  * @list: links gpio_device:s together for traversal
  *
@@ -55,6 +57,7 @@ struct gpio_device {
        struct gpio_desc        *descs;
        int                     base;
        u16                     ngpio;
+       char                    *label;
        void                    *data;
        struct list_head        list;
 
index ff96d0f9fceb1dd0d9ae52ab38b8675e00ff05f4..639607658ed892ce35e259a3f5fcf1c44540b35d 100644 (file)
@@ -21,7 +21,8 @@ struct gpio_device;
 
 /**
  * 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
  * @parent: optional parent device providing the GPIOs
  * @owner: helps prevent removal of modules exporting active GPIOs
index 3188a87bdaa0fab9ea2b35f4f7a37829cb252f10..3f93e1bcd3ddae4632952bdd9a3382d0821e900b 100644 (file)
 /**
  * struct gpiochip_info - Information about a certain 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
  */
 struct gpiochip_info {
        char name[32];
+       char label[32];
        __u32 lines;
 };
 
index 4cfe29da279bbf3d7da3c3a3b9063b7ce73056cc..692233f561fbd7abd59db6c6c985a9b7c82de891 100644 (file)
@@ -54,8 +54,8 @@ int list_device(const char *device_name)
 
                goto free_chrdev_name;
        }
-       fprintf(stdout, "GPIO chip: %s, %u GPIO lines\n",
-               cinfo.name, cinfo.lines);
+       fprintf(stdout, "GPIO chip: %s, \"%s\", %u GPIO lines\n",
+               cinfo.name, cinfo.label, cinfo.lines);
 
        if (close(fd) == -1)  {
                ret = -errno;
This page took 0.031304 seconds and 5 git commands to generate.