Use gpiochip label for sysfs entries
RFC PATCH 1/1 Use gpiochip label for sysfs entries
At least on the ep93xx, the gpio banks have names (A, B, etc), which are used for gpiochip->label. However, banks C and F are swapped which makes the names of the gpiochip directories in /sys/class/gpio confusing. For many SoC chips, it would be useful to have the gpio label on the sysfs entries.
The following patch registers the gpiochip devices using gpiochip->label. If label is not set, or the registration fails, it falls back to using gpiochip->base.
Signed-off-by Ryan Mallon <[email protected]>
---
drivers/gpio/gpiolib.c +10 -4
@@ -536,7 +536,7 @@ EXPORT_SYMBOL_GPL(gpio_unexport);static int gpiochip_export (struct gpio_chip *chip) {int status; -struct device *dev; +struct device *dev =NULL ;/* Many systems register gpio chips for SOC support very early, * before driver model support is available. In those cases we
@@ -546,10 +546,16 @@ static int gpiochip_export(struct gpio_chip *chip)if (!gpio_class.p)return 0 ; -/* use chip->base for the ID; it's already known to be unique */ mutex_lock (&sysfs_lock); - dev =device_create (&gpio_class, chip->dev,MKDEV (0 ,0 ), chip, -"gpiochip%d" , chip->base); +if (chip->label) +/* Attempt to register the device using the gpiochip label */ + dev =device_create (&gpio_class, chip->dev,MKDEV (0 ,0 ), chip, +"gpiochip-%s" , chip->label); + +if (!dev) +/* Use chip->base for the ID; it's already known to be unique */ + dev =device_create (&gpio_class, chip->dev,MKDEV (0 ,0 ), chip, +"gpiochip%d" , chip->base);if (dev) { status =sysfs_create_group (&dev->kobj, &gpiochip_attr_group);