linux-gpio.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH v3 0/9] gpiolib: Add GPIO name support
@ 2015-08-14 14:10 Markus Pargmann
  2015-08-14 14:10 ` [PATCH v3 1/9] gpiolib-of: Rename gpio_hog functions to be generic Markus Pargmann
                   ` (9 more replies)
  0 siblings, 10 replies; 22+ messages in thread
From: Markus Pargmann @ 2015-08-14 14:10 UTC (permalink / raw)
  To: Linus Walleij
  Cc: Alexandre Courbot, Arun Bharadwaj, Uwe Kleine-König,
	Johan Hovold, linux-gpio, linux-arm-kernel, kernel,
	Markus Pargmann

Changes in v3:
As discussed in the v2 thread, we are using the already existing gpiochip names
now. To avoid races between kernel and userspace, the setup of gpio names in
the gpio descriptors has to happen right before the gpiochip is added for use
and after the gpio descriptors are available. Unfortunately this is exactly in
the function gpiochip_add().

So we can't use a a function as proposed in the discussion like
gpiochip_set_names(), as this function would only be possible after we executed
gpiochip_add(). Before that point the gpio descriptors are not available. But
this can potentially lead to races between userspace and the gpio chip.

That is the reason why I left the names array in the gpioscript. But this array
is now only used to initialize the GPIO descriptors. The named sysfs
directories are now created using the name stored in the gpio descriptor.

As the name is now directly represented through the sysfs directory name, I am
not sure if it makes sense to keep the patch which adds a 'name' property to
the sysfs GPIO directories. For the moment it is still in this series.

Other changes in v3:
 - Renamed generic of_parse_gpio() to of_parse_own_gpio()
 - Replaced pr_warn with dev_warn as the device is available in the parsing code
   in gpiolib-of
 - Introduced name collision checks when adding the names from gpiochip->names
   to the gpio descriptors
 - Added documentation about /sys/class/gpio/<GPIO>/name
 - Added check for DT in case the GPIO already has a name. This may happen as
   there are different ways to set a name, through 'line-name' property and
   node name

Best Regards,

Markus


Changes in v2:
 - Removed patch 'gpiolib: Fix possible use of wrong name'
 - Removed discussed patch 'gpio: Allow hogged gpios to be requested' from this
   series
 - Fixed show gpio name patch (locks, (null) printing, and getting the descriptor)
 - Merged gpio name patch into gpio_name_to_desc() patch

Description from v1:

This is a proposal to add GPIO names to the kernel based on devicetree
descriptions.

This series adds GPIO name support. Until now it is only possible to use names
for already requested GPIOs (for example what they are used for). It is not
possible to identify GPIOs by a name although most of them have a name for
example in the schematics of the board. This makes it difficult to identify
a specific GPIO from userspace.

As the GPIO name information is a hardware description this series uses the
devicetree bindings introduced by the GPIO hogging mechanism, specifically
'line-name', to identify GPIOs. The sysfs 'export' file is changed to accept
names as fallback. The gpio numbers still have a higher priority to ensure
backwards compatibility.

Exported GPIOs are still using their number as directory name (gpio<ID>). But the
directories now contain a 'name' file which is '' for non-existent names and
the name otherwise.

This series can be used to have an easy name mapping for udev with a quite
simple rule similar to this:
	SUBSYSTEM=="gpio", KERNEL=="gpio*", ATTR{name}!="(null)", ACTION=="add", \
	PROGRAM+="/bin/sh -c 'mkdir -p /dev/gpios; rm -f /dev/gpios/$attr{name}; ln -s /sys%p/ /dev/gpios/$attr{name}"
With this rule udev adds a link for each exported GPIO with a name into
/dev/gpios/. This way it is not necessary to know the number of a GPIO to use
it.


Markus Pargmann (9):
  gpiolib-of: Rename gpio_hog functions to be generic
  gpio: Introduce gpio descriptor 'name'
  gpiolib: Use GPIO name from names array for gpio descriptor
  gpio-sysfs: Use gpio descriptor name instead of gpiochip names array
  gpiolib: Add gpio name information to /sys/kernel/debug/gpio
  gpiolib-sysfs: Show gpio-name in /sys/class/gpio/gpio*/name
  gpiolib-sysfs: Add gpio name parsing for sysfs export
  gpiolib-of: Reuse 'line-name' from DT as gpio descriptor name
  gpiolib-of: Use dev_warn instead of pr_warn

 Documentation/ABI/testing/sysfs-gpio |  1 +
 drivers/gpio/gpiolib-of.c            | 50 +++++++++++++---------
 drivers/gpio/gpiolib-sysfs.c         | 67 +++++++++++++++++++++---------
 drivers/gpio/gpiolib.c               | 80 ++++++++++++++++++++++++++++++++++--
 drivers/gpio/gpiolib.h               |  3 ++
 include/linux/gpio/consumer.h        |  7 ++++
 6 files changed, 166 insertions(+), 42 deletions(-)

-- 
2.4.6


^ permalink raw reply	[flat|nested] 22+ messages in thread

* [PATCH v3 1/9] gpiolib-of: Rename gpio_hog functions to be generic
  2015-08-14 14:10 [PATCH v3 0/9] gpiolib: Add GPIO name support Markus Pargmann
@ 2015-08-14 14:10 ` Markus Pargmann
  2015-09-22  0:48   ` Linus Walleij
  2015-08-14 14:10 ` [PATCH v3 2/9] gpio: Introduce gpio descriptor 'name' Markus Pargmann
                   ` (8 subsequent siblings)
  9 siblings, 1 reply; 22+ messages in thread
From: Markus Pargmann @ 2015-08-14 14:10 UTC (permalink / raw)
  To: Linus Walleij
  Cc: Alexandre Courbot, Arun Bharadwaj, Uwe Kleine-König,
	Johan Hovold, linux-gpio, linux-arm-kernel, kernel,
	Markus Pargmann

The gpio hogging functions are currently only used for gpio-hogging. But
these functions are widely generic ones which parse gpio device nodes in
the DT.

Signed-off-by: Markus Pargmann <mpa@pengutronix.de>
---
 drivers/gpio/gpiolib-of.c | 20 ++++++++++----------
 1 file changed, 10 insertions(+), 10 deletions(-)

diff --git a/drivers/gpio/gpiolib-of.c b/drivers/gpio/gpiolib-of.c
index 9a0ec48a4737..fea80bbccf12 100644
--- a/drivers/gpio/gpiolib-of.c
+++ b/drivers/gpio/gpiolib-of.c
@@ -119,20 +119,20 @@ int of_get_named_gpio_flags(struct device_node *np, const char *list_name,
 EXPORT_SYMBOL(of_get_named_gpio_flags);
 
 /**
- * of_get_gpio_hog() - Get a GPIO hog descriptor, names and flags for GPIO API
+ * of_parse_own_gpio() - Get a GPIO hog descriptor, names and flags for GPIO API
  * @np:		device node to get GPIO from
  * @name:	GPIO line name
  * @lflags:	gpio_lookup_flags - returned from of_find_gpio() or
- *		of_get_gpio_hog()
+ *		of_parse_own_gpio()
  * @dflags:	gpiod_flags - optional GPIO initialization flags
  *
  * Returns GPIO descriptor to use with Linux GPIO API, or one of the errno
  * value on the error condition.
  */
-static struct gpio_desc *of_get_gpio_hog(struct device_node *np,
-				  const char **name,
-				  enum gpio_lookup_flags *lflags,
-				  enum gpiod_flags *dflags)
+static struct gpio_desc *of_parse_own_gpio(struct device_node *np,
+					   const char **name,
+					   enum gpio_lookup_flags *lflags,
+					   enum gpiod_flags *dflags)
 {
 	struct device_node *chip_np;
 	enum of_gpio_flags xlate_flags;
@@ -199,13 +199,13 @@ static struct gpio_desc *of_get_gpio_hog(struct device_node *np,
 }
 
 /**
- * of_gpiochip_scan_hogs - Scan gpio-controller and apply GPIO hog as requested
+ * of_gpiochip_scan_gpios - Scan gpio-controller for gpio definitions
  * @chip:	gpio chip to act on
  *
  * This is only used by of_gpiochip_add to request/set GPIO initial
  * configuration.
  */
-static void of_gpiochip_scan_hogs(struct gpio_chip *chip)
+static void of_gpiochip_scan_gpios(struct gpio_chip *chip)
 {
 	struct gpio_desc *desc = NULL;
 	struct device_node *np;
@@ -217,7 +217,7 @@ static void of_gpiochip_scan_hogs(struct gpio_chip *chip)
 		if (!of_property_read_bool(np, "gpio-hog"))
 			continue;
 
-		desc = of_get_gpio_hog(np, &name, &lflags, &dflags);
+		desc = of_parse_own_gpio(np, &name, &lflags, &dflags);
 		if (IS_ERR(desc))
 			continue;
 
@@ -436,7 +436,7 @@ void of_gpiochip_add(struct gpio_chip *chip)
 	of_gpiochip_add_pin_range(chip);
 	of_node_get(chip->of_node);
 
-	of_gpiochip_scan_hogs(chip);
+	of_gpiochip_scan_gpios(chip);
 }
 
 void of_gpiochip_remove(struct gpio_chip *chip)
-- 
2.4.6


^ permalink raw reply related	[flat|nested] 22+ messages in thread

* [PATCH v3 2/9] gpio: Introduce gpio descriptor 'name'
  2015-08-14 14:10 [PATCH v3 0/9] gpiolib: Add GPIO name support Markus Pargmann
  2015-08-14 14:10 ` [PATCH v3 1/9] gpiolib-of: Rename gpio_hog functions to be generic Markus Pargmann
@ 2015-08-14 14:10 ` Markus Pargmann
  2015-09-22  0:51   ` Linus Walleij
  2015-08-14 14:11 ` [PATCH v3 3/9] gpiolib: Use GPIO name from names array for gpio descriptor Markus Pargmann
                   ` (7 subsequent siblings)
  9 siblings, 1 reply; 22+ messages in thread
From: Markus Pargmann @ 2015-08-14 14:10 UTC (permalink / raw)
  To: Linus Walleij
  Cc: Alexandre Courbot, Arun Bharadwaj, Uwe Kleine-König,
	Johan Hovold, linux-gpio, linux-arm-kernel, kernel,
	Markus Pargmann

The latest gpio hogging mechanism assigns each gpio a 'line-name' in the
devicetree. The 'name' field is different from the 'label' field.
'label' is only used for requested GPIOs to describe its current use by
driver or userspace.

The 'name' field describes the GPIO itself, not the use. This is most
likely identical to the label in the schematic on the GPIO line and
should help to find this particular GPIO.

This is equivalent to the gpiochip->names array. However names should be
stored in the GPIO descriptor. We will use gpiochip->names in the future
only as initializer for the GPIO descriptors for drivers that assign
GPIO names hardcoded. All other GPIO names will be parsed from DT and
directly assigned to the GPIO descriptor.

This patch adds a helper function to find gpio descriptors by name
instead of gpio number.

Signed-off-by: Markus Pargmann <mpa@pengutronix.de>
---
 drivers/gpio/gpiolib.c        | 32 ++++++++++++++++++++++++++++++++
 drivers/gpio/gpiolib.h        |  3 +++
 include/linux/gpio/consumer.h |  7 +++++++
 3 files changed, 42 insertions(+)

diff --git a/drivers/gpio/gpiolib.c b/drivers/gpio/gpiolib.c
index bf4bd1d120c3..eed3751fe14f 100644
--- a/drivers/gpio/gpiolib.c
+++ b/drivers/gpio/gpiolib.c
@@ -90,6 +90,38 @@ struct gpio_desc *gpio_to_desc(unsigned gpio)
 EXPORT_SYMBOL_GPL(gpio_to_desc);
 
 /**
+ * Convert a GPIO name to its descriptor
+ */
+struct gpio_desc *gpio_name_to_desc(const char * const name)
+{
+	struct gpio_chip *chip;
+	unsigned long flags;
+
+	spin_lock_irqsave(&gpio_lock, flags);
+
+	list_for_each_entry(chip, &gpio_chips, list) {
+		int i;
+
+		for (i = 0; i != chip->ngpio; ++i) {
+			struct gpio_desc *gpio = &chip->desc[i];
+
+			if (!gpio->name)
+				continue;
+
+			if (!strcmp(gpio->name, name)) {
+				spin_unlock_irqrestore(&gpio_lock, flags);
+				return gpio;
+			}
+		}
+	}
+
+	spin_unlock_irqrestore(&gpio_lock, flags);
+
+	return NULL;
+}
+EXPORT_SYMBOL_GPL(gpio_name_to_desc);
+
+/**
  * Get the GPIO descriptor corresponding to the given hw number for this chip.
  */
 struct gpio_desc *gpiochip_get_desc(struct gpio_chip *chip,
diff --git a/drivers/gpio/gpiolib.h b/drivers/gpio/gpiolib.h
index bf343004b008..78e634d1c719 100644
--- a/drivers/gpio/gpiolib.h
+++ b/drivers/gpio/gpiolib.h
@@ -89,7 +89,10 @@ struct gpio_desc {
 #define FLAG_USED_AS_IRQ 9	/* GPIO is connected to an IRQ */
 #define FLAG_IS_HOGGED	11	/* GPIO is hogged */
 
+	/* Connection label */
 	const char		*label;
+	/* Name of the GPIO */
+	const char		*name;
 };
 
 int gpiod_request(struct gpio_desc *desc, const char *label);
diff --git a/include/linux/gpio/consumer.h b/include/linux/gpio/consumer.h
index adac255aee86..a873b8b47ab3 100644
--- a/include/linux/gpio/consumer.h
+++ b/include/linux/gpio/consumer.h
@@ -130,6 +130,7 @@ int gpiod_to_irq(const struct gpio_desc *desc);
 /* Convert between the old gpio_ and new gpiod_ interfaces */
 struct gpio_desc *gpio_to_desc(unsigned gpio);
 int desc_to_gpio(const struct gpio_desc *desc);
+struct gpio_desc *gpio_name_to_desc(const char *name);
 
 /* Child properties interface */
 struct fwnode_handle;
@@ -400,6 +401,12 @@ static inline struct gpio_desc *gpio_to_desc(unsigned gpio)
 {
 	return ERR_PTR(-EINVAL);
 }
+
+static inline struct gpio_desc *gpio_name_to_desc(const char *name)
+{
+	return ERR_PTR(-EINVAL);
+}
+
 static inline int desc_to_gpio(const struct gpio_desc *desc)
 {
 	/* GPIO can never have been requested */
-- 
2.4.6


^ permalink raw reply related	[flat|nested] 22+ messages in thread

* [PATCH v3 3/9] gpiolib: Use GPIO name from names array for gpio descriptor
  2015-08-14 14:10 [PATCH v3 0/9] gpiolib: Add GPIO name support Markus Pargmann
  2015-08-14 14:10 ` [PATCH v3 1/9] gpiolib-of: Rename gpio_hog functions to be generic Markus Pargmann
  2015-08-14 14:10 ` [PATCH v3 2/9] gpio: Introduce gpio descriptor 'name' Markus Pargmann
@ 2015-08-14 14:11 ` Markus Pargmann
  2015-09-22  0:56   ` Linus Walleij
  2015-09-23 22:02   ` Johan Hovold
  2015-08-14 14:11 ` [PATCH v3 4/9] gpio-sysfs: Use gpio descriptor name instead of gpiochip names array Markus Pargmann
                   ` (6 subsequent siblings)
  9 siblings, 2 replies; 22+ messages in thread
From: Markus Pargmann @ 2015-08-14 14:11 UTC (permalink / raw)
  To: Linus Walleij
  Cc: Alexandre Courbot, Arun Bharadwaj, Uwe Kleine-König,
	Johan Hovold, linux-gpio, linux-arm-kernel, kernel,
	Markus Pargmann

This patch adds GPIO names to the GPIO descriptors when initializing the
gpiochip. It also introduces a check whether any of the new names will
conflict with an existing GPIO name.

Signed-off-by: Markus Pargmann <mpa@pengutronix.de>
---
 drivers/gpio/gpiolib.c | 37 +++++++++++++++++++++++++++++++++++++
 1 file changed, 37 insertions(+)

diff --git a/drivers/gpio/gpiolib.c b/drivers/gpio/gpiolib.c
index eed3751fe14f..3908503bebfe 100644
--- a/drivers/gpio/gpiolib.c
+++ b/drivers/gpio/gpiolib.c
@@ -250,6 +250,38 @@ static int gpiochip_add_to_list(struct gpio_chip *chip)
 	return err;
 }
 
+/*
+ * Takes the names from gc->names and checks if they are all unique. If they
+ * are, they are assigned to their gpio descriptors.
+ *
+ * Returns -EEXIST if one of the names is already used for a different GPIO.
+ */
+static int gpiochip_set_desc_names(struct gpio_chip *gc)
+{
+	int i;
+
+	if (!gc->names)
+		return 0;
+
+	/* First check all names if they are unique */
+	for (i = 0; i != gc->ngpio; ++i) {
+		struct gpio_desc *gpio;
+
+		gpio = gpio_name_to_desc(gc->names[i]);
+		if (gpio) {
+			dev_err(gc->dev, "Detected name collision for GPIO name '%s'\n",
+				gc->names[i]);
+			return -EEXIST;
+		}
+	}
+
+	/* Then add all names to the GPIO descriptors */
+	for (i = 0; i != gc->ngpio; ++i)
+		gc->desc[i].name = gc->names[i];
+
+	return 0;
+}
+
 /**
  * gpiochip_add() - register a gpio_chip
  * @chip: the chip to register, with chip->base initialized
@@ -319,6 +351,10 @@ int gpiochip_add(struct gpio_chip *chip)
 	INIT_LIST_HEAD(&chip->pin_ranges);
 #endif
 
+	status = gpiochip_set_desc_names(chip);
+	if (status)
+		goto err_remove_from_list;
+
 	of_gpiochip_add(chip);
 	acpi_gpiochip_add(chip);
 
@@ -336,6 +372,7 @@ err_remove_chip:
 	acpi_gpiochip_remove(chip);
 	gpiochip_free_hogs(chip);
 	of_gpiochip_remove(chip);
+err_remove_from_list:
 	spin_lock_irqsave(&gpio_lock, flags);
 	list_del(&chip->list);
 	spin_unlock_irqrestore(&gpio_lock, flags);
-- 
2.4.6


^ permalink raw reply related	[flat|nested] 22+ messages in thread

* [PATCH v3 4/9] gpio-sysfs: Use gpio descriptor name instead of gpiochip names array
  2015-08-14 14:10 [PATCH v3 0/9] gpiolib: Add GPIO name support Markus Pargmann
                   ` (2 preceding siblings ...)
  2015-08-14 14:11 ` [PATCH v3 3/9] gpiolib: Use GPIO name from names array for gpio descriptor Markus Pargmann
@ 2015-08-14 14:11 ` Markus Pargmann
  2015-09-22  0:57   ` Linus Walleij
  2015-08-14 14:11 ` [PATCH v3 5/9] gpiolib: Add gpio name information to /sys/kernel/debug/gpio Markus Pargmann
                   ` (5 subsequent siblings)
  9 siblings, 1 reply; 22+ messages in thread
From: Markus Pargmann @ 2015-08-14 14:11 UTC (permalink / raw)
  To: Linus Walleij
  Cc: Alexandre Courbot, Arun Bharadwaj, Uwe Kleine-König,
	Johan Hovold, linux-gpio, linux-arm-kernel, kernel,
	Markus Pargmann

The name is now stored in the gpio descriptor as well, for example to
allow to store names from DT. This patch changes the sysfs gpio files
to use the gpio descriptor name.

Signed-off-by: Markus Pargmann <mpa@pengutronix.de>
---
 drivers/gpio/gpiolib-sysfs.c | 8 +-------
 1 file changed, 1 insertion(+), 7 deletions(-)

diff --git a/drivers/gpio/gpiolib-sysfs.c b/drivers/gpio/gpiolib-sysfs.c
index b57ed8e55ab5..3e81f28e3aee 100644
--- a/drivers/gpio/gpiolib-sysfs.c
+++ b/drivers/gpio/gpiolib-sysfs.c
@@ -550,9 +550,7 @@ int gpiod_export(struct gpio_desc *desc, bool direction_may_change)
 	struct gpiod_data	*data;
 	unsigned long		flags;
 	int			status;
-	const char		*ioname = NULL;
 	struct device		*dev;
-	int			offset;
 
 	/* can't export until sysfs is available ... */
 	if (!gpio_class.p) {
@@ -601,13 +599,9 @@ int gpiod_export(struct gpio_desc *desc, bool direction_may_change)
 	else
 		data->direction_can_change = false;
 
-	offset = gpio_chip_hwgpio(desc);
-	if (chip->names && chip->names[offset])
-		ioname = chip->names[offset];
-
 	dev = device_create_with_groups(&gpio_class, chip->dev,
 					MKDEV(0, 0), data, gpio_groups,
-					ioname ? ioname : "gpio%u",
+					desc->name ? desc->name : "gpio%u",
 					desc_to_gpio(desc));
 	if (IS_ERR(dev)) {
 		status = PTR_ERR(dev);
-- 
2.4.6


^ permalink raw reply related	[flat|nested] 22+ messages in thread

* [PATCH v3 5/9] gpiolib: Add gpio name information to /sys/kernel/debug/gpio
  2015-08-14 14:10 [PATCH v3 0/9] gpiolib: Add GPIO name support Markus Pargmann
                   ` (3 preceding siblings ...)
  2015-08-14 14:11 ` [PATCH v3 4/9] gpio-sysfs: Use gpio descriptor name instead of gpiochip names array Markus Pargmann
@ 2015-08-14 14:11 ` Markus Pargmann
  2015-09-22  1:05   ` Linus Walleij
  2015-08-14 14:11 ` [PATCH v3 6/9] gpiolib-sysfs: Show gpio-name in /sys/class/gpio/gpio*/name Markus Pargmann
                   ` (4 subsequent siblings)
  9 siblings, 1 reply; 22+ messages in thread
From: Markus Pargmann @ 2015-08-14 14:11 UTC (permalink / raw)
  To: Linus Walleij
  Cc: Alexandre Courbot, Arun Bharadwaj, Uwe Kleine-König,
	Johan Hovold, linux-gpio, linux-arm-kernel, kernel,
	Markus Pargmann

Add some information about gpio names to the debugfs gpio file. name and
label of a GPIO are then displayed next to each other. This way it is
easy to see what the real name of GPIO is and what the driver requested
it for.

Signed-off-by: Markus Pargmann <mpa@pengutronix.de>
---
 Documentation/ABI/testing/sysfs-gpio |  1 +
 drivers/gpio/gpiolib.c               | 11 ++++++++---
 2 files changed, 9 insertions(+), 3 deletions(-)

diff --git a/Documentation/ABI/testing/sysfs-gpio b/Documentation/ABI/testing/sysfs-gpio
index 55ffa2df1c10..2c1e199fd4e1 100644
--- a/Documentation/ABI/testing/sysfs-gpio
+++ b/Documentation/ABI/testing/sysfs-gpio
@@ -21,6 +21,7 @@ Description:
 	    /value ... always readable, writes fail for input GPIOs
 	    /direction ... r/w as: in, out (default low); write: high, low
 	    /edge ... r/w as: none, falling, rising, both
+	    /name ... r/o, unique name of the GPIO
 	/gpiochipN ... for each gpiochip; #N is its first GPIO
 	    /base ... (r/o) same as N
 	    /label ... (r/o) descriptive, not necessarily unique
diff --git a/drivers/gpio/gpiolib.c b/drivers/gpio/gpiolib.c
index 3908503bebfe..79a0b41ce57b 100644
--- a/drivers/gpio/gpiolib.c
+++ b/drivers/gpio/gpiolib.c
@@ -2344,14 +2344,19 @@ static void gpiolib_dbg_show(struct seq_file *s, struct gpio_chip *chip)
 	int			is_irq;
 
 	for (i = 0; i < chip->ngpio; i++, gpio++, gdesc++) {
-		if (!test_bit(FLAG_REQUESTED, &gdesc->flags))
+		if (!test_bit(FLAG_REQUESTED, &gdesc->flags)) {
+			if (gdesc->name) {
+				seq_printf(s, " gpio-%-3d (%-20.20s)\n",
+					   gpio, gdesc->name);
+			}
 			continue;
+		}
 
 		gpiod_get_direction(gdesc);
 		is_out = test_bit(FLAG_IS_OUT, &gdesc->flags);
 		is_irq = test_bit(FLAG_USED_AS_IRQ, &gdesc->flags);
-		seq_printf(s, " gpio-%-3d (%-20.20s) %s %s %s",
-			gpio, gdesc->label,
+		seq_printf(s, " gpio-%-3d (%-20.20s|%-20.20s) %s %s %s",
+			gpio, gdesc->name ? gdesc->name : "", gdesc->label,
 			is_out ? "out" : "in ",
 			chip->get
 				? (chip->get(chip, i) ? "hi" : "lo")
-- 
2.4.6


^ permalink raw reply related	[flat|nested] 22+ messages in thread

* [PATCH v3 6/9] gpiolib-sysfs: Show gpio-name in /sys/class/gpio/gpio*/name
  2015-08-14 14:10 [PATCH v3 0/9] gpiolib: Add GPIO name support Markus Pargmann
                   ` (4 preceding siblings ...)
  2015-08-14 14:11 ` [PATCH v3 5/9] gpiolib: Add gpio name information to /sys/kernel/debug/gpio Markus Pargmann
@ 2015-08-14 14:11 ` Markus Pargmann
  2015-09-22  1:07   ` Linus Walleij
  2015-08-14 14:11 ` [PATCH v3 7/9] gpiolib-sysfs: Add gpio name parsing for sysfs export Markus Pargmann
                   ` (3 subsequent siblings)
  9 siblings, 1 reply; 22+ messages in thread
From: Markus Pargmann @ 2015-08-14 14:11 UTC (permalink / raw)
  To: Linus Walleij
  Cc: Alexandre Courbot, Arun Bharadwaj, Uwe Kleine-König,
	Johan Hovold, linux-gpio, linux-arm-kernel, kernel,
	Markus Pargmann

This patch adds a sysfs attribute 'name' to gpios that were exported. It
exposes the newly added name property of gpio descriptors.

Signed-off-by: Markus Pargmann <mpa@pengutronix.de>
---
 drivers/gpio/gpiolib-sysfs.c | 12 ++++++++++++
 1 file changed, 12 insertions(+)

diff --git a/drivers/gpio/gpiolib-sysfs.c b/drivers/gpio/gpiolib-sysfs.c
index 3e81f28e3aee..2022cfb00aeb 100644
--- a/drivers/gpio/gpiolib-sysfs.c
+++ b/drivers/gpio/gpiolib-sysfs.c
@@ -139,6 +139,17 @@ static ssize_t value_store(struct device *dev,
 }
 static DEVICE_ATTR_RW(value);
 
+static ssize_t name_show(struct device *dev, struct device_attribute *attr,
+			 char *buf)
+{
+	struct gpiod_data *data = dev_get_drvdata(dev);
+	struct gpio_desc *desc = data->desc;
+
+	return sprintf(buf, "%s\n", desc->name ? : "");
+}
+
+static DEVICE_ATTR_RO(name);
+
 static irqreturn_t gpio_sysfs_irq(int irq, void *priv)
 {
 	struct gpiod_data *data = priv;
@@ -377,6 +388,7 @@ static struct attribute *gpio_attrs[] = {
 	&dev_attr_edge.attr,
 	&dev_attr_value.attr,
 	&dev_attr_active_low.attr,
+	&dev_attr_name.attr,
 	NULL,
 };
 
-- 
2.4.6


^ permalink raw reply related	[flat|nested] 22+ messages in thread

* [PATCH v3 7/9] gpiolib-sysfs: Add gpio name parsing for sysfs export
  2015-08-14 14:10 [PATCH v3 0/9] gpiolib: Add GPIO name support Markus Pargmann
                   ` (5 preceding siblings ...)
  2015-08-14 14:11 ` [PATCH v3 6/9] gpiolib-sysfs: Show gpio-name in /sys/class/gpio/gpio*/name Markus Pargmann
@ 2015-08-14 14:11 ` Markus Pargmann
  2015-09-22  1:09   ` Linus Walleij
  2015-08-14 14:11 ` [PATCH v3 8/9] gpiolib-of: Reuse 'line-name' from DT as gpio descriptor name Markus Pargmann
                   ` (2 subsequent siblings)
  9 siblings, 1 reply; 22+ messages in thread
From: Markus Pargmann @ 2015-08-14 14:11 UTC (permalink / raw)
  To: Linus Walleij
  Cc: Alexandre Courbot, Arun Bharadwaj, Uwe Kleine-König,
	Johan Hovold, linux-gpio, linux-arm-kernel, kernel,
	Markus Pargmann

Signed-off-by: Markus Pargmann <mpa@pengutronix.de>
---
 drivers/gpio/gpiolib-sysfs.c | 47 ++++++++++++++++++++++++++++++++------------
 1 file changed, 34 insertions(+), 13 deletions(-)

diff --git a/drivers/gpio/gpiolib-sysfs.c b/drivers/gpio/gpiolib-sysfs.c
index 2022cfb00aeb..e401878d05ce 100644
--- a/drivers/gpio/gpiolib-sysfs.c
+++ b/drivers/gpio/gpiolib-sysfs.c
@@ -455,18 +455,28 @@ static ssize_t export_store(struct class *class,
 				const char *buf, size_t len)
 {
 	long			gpio;
-	struct gpio_desc	*desc;
+	struct gpio_desc	*desc = NULL;
 	int			status;
 
 	status = kstrtol(buf, 0, &gpio);
-	if (status < 0)
-		goto done;
+	if (!status)
+		desc = gpio_to_desc(gpio);
 
-	desc = gpio_to_desc(gpio);
-	/* reject invalid GPIOs */
+	/* Fall back on detection by name */
 	if (!desc) {
-		pr_warn("%s: invalid GPIO %ld\n", __func__, gpio);
-		return -EINVAL;
+		char *gpio_name = kstrdup(buf, GFP_KERNEL);
+
+		if (!gpio_name)
+			return -ENOMEM;
+
+		desc = gpio_name_to_desc(strim(gpio_name));
+		kfree(gpio_name);
+
+		/* reject invalid GPIOs */
+		if (!desc) {
+			pr_warn("%s: invalid GPIO %s\n", __func__, buf);
+			return -EINVAL;
+		}
 	}
 
 	/* No extra locking here; FLAG_SYSFS just signifies that the
@@ -497,17 +507,28 @@ static ssize_t unexport_store(struct class *class,
 				const char *buf, size_t len)
 {
 	long			gpio;
-	struct gpio_desc	*desc;
+	struct gpio_desc	*desc = NULL;
 	int			status;
 
 	status = kstrtol(buf, 0, &gpio);
-	if (status < 0)
-		goto done;
+	if (!status)
+		desc = gpio_to_desc(gpio);
+
+	/* Fall back on detection by name */
+	if (!desc) {
+		char *gpio_name = kstrdup(buf, GFP_KERNEL);
+
+		if (!gpio_name)
+			return -ENOMEM;
+
+		desc = gpio_name_to_desc(strim(gpio_name));
+		kfree(gpio_name);
+	}
+
 
-	desc = gpio_to_desc(gpio);
 	/* reject bogus commands (gpio_unexport ignores them) */
 	if (!desc) {
-		pr_warn("%s: invalid GPIO %ld\n", __func__, gpio);
+		pr_warn("%s: invalid GPIO %s\n", __func__, buf);
 		return -EINVAL;
 	}
 
@@ -521,7 +542,7 @@ static ssize_t unexport_store(struct class *class,
 		status = 0;
 		gpiod_free(desc);
 	}
-done:
+
 	if (status)
 		pr_debug("%s: status %d\n", __func__, status);
 	return status ? : len;
-- 
2.4.6


^ permalink raw reply related	[flat|nested] 22+ messages in thread

* [PATCH v3 8/9] gpiolib-of: Reuse 'line-name' from DT as gpio descriptor name
  2015-08-14 14:10 [PATCH v3 0/9] gpiolib: Add GPIO name support Markus Pargmann
                   ` (6 preceding siblings ...)
  2015-08-14 14:11 ` [PATCH v3 7/9] gpiolib-sysfs: Add gpio name parsing for sysfs export Markus Pargmann
@ 2015-08-14 14:11 ` Markus Pargmann
  2015-08-14 14:11 ` [PATCH v3 9/9] gpiolib-of: Use dev_warn instead of pr_warn Markus Pargmann
  2015-09-21 10:58 ` [PATCH v3 0/9] gpiolib: Add GPIO name support Markus Pargmann
  9 siblings, 0 replies; 22+ messages in thread
From: Markus Pargmann @ 2015-08-14 14:11 UTC (permalink / raw)
  To: Linus Walleij
  Cc: Alexandre Courbot, Arun Bharadwaj, Uwe Kleine-König,
	Johan Hovold, linux-gpio, linux-arm-kernel, kernel,
	Markus Pargmann

The DT describes gpios with subnodes. These subnodes can contain a
property 'line-name'. This information can be useful in other areas
where we want to identify a GPIO by its name.

This patch stores the line-name in the gpio descriptor.

Signed-off-by: Markus Pargmann <mpa@pengutronix.de>
---
 drivers/gpio/gpiolib-of.c | 30 +++++++++++++++++++++---------
 1 file changed, 21 insertions(+), 9 deletions(-)

diff --git a/drivers/gpio/gpiolib-of.c b/drivers/gpio/gpiolib-of.c
index fea80bbccf12..1911b692f735 100644
--- a/drivers/gpio/gpiolib-of.c
+++ b/drivers/gpio/gpiolib-of.c
@@ -184,11 +184,6 @@ static struct gpio_desc *of_parse_own_gpio(struct device_node *np,
 		*dflags |= GPIOD_OUT_LOW;
 	else if (of_property_read_bool(np, "output-high"))
 		*dflags |= GPIOD_OUT_HIGH;
-	else {
-		pr_warn("GPIO line %d (%s): no hogging state specified, bailing out\n",
-			desc_to_gpio(gg_data.out_gpio), np->name);
-		return ERR_PTR(-EINVAL);
-	}
 
 	if (name && of_property_read_string(np, "line-name", name))
 		*name = np->name;
@@ -214,15 +209,32 @@ static void of_gpiochip_scan_gpios(struct gpio_chip *chip)
 	enum gpiod_flags dflags;
 
 	for_each_child_of_node(chip->of_node, np) {
-		if (!of_property_read_bool(np, "gpio-hog"))
-			continue;
+		struct gpio_desc *name_desc;
 
 		desc = of_parse_own_gpio(np, &name, &lflags, &dflags);
 		if (IS_ERR(desc))
 			continue;
 
-		if (gpiod_hog(desc, name, lflags, dflags))
-			continue;
+		name_desc = gpio_name_to_desc(name);
+		if (name_desc)
+			dev_warn(chip->dev, "GPIO name collision for '%s' detected at GPIO line %d (%s)\n",
+				 name, desc_to_gpio(desc), np->name);
+		else if (desc->name)
+			dev_warn(chip->dev, "GPIO has already a name '%s' new name would be '%s' at GPIO %d\n",
+				 desc->name, name, desc_to_gpio(desc));
+		else
+			desc->name = name;
+
+		if (of_property_read_bool(np, "gpio-hog")) {
+			if (!dflags) {
+				pr_warn("GPIO line %d (%s): no hogging state specified, bailing out\n",
+					desc_to_gpio(desc), np->name);
+				continue;
+			}
+
+			if (gpiod_hog(desc, name, lflags, dflags))
+				continue;
+		}
 	}
 }
 
-- 
2.4.6


^ permalink raw reply related	[flat|nested] 22+ messages in thread

* [PATCH v3 9/9] gpiolib-of: Use dev_warn instead of pr_warn
  2015-08-14 14:10 [PATCH v3 0/9] gpiolib: Add GPIO name support Markus Pargmann
                   ` (7 preceding siblings ...)
  2015-08-14 14:11 ` [PATCH v3 8/9] gpiolib-of: Reuse 'line-name' from DT as gpio descriptor name Markus Pargmann
@ 2015-08-14 14:11 ` Markus Pargmann
  2015-09-21 10:58 ` [PATCH v3 0/9] gpiolib: Add GPIO name support Markus Pargmann
  9 siblings, 0 replies; 22+ messages in thread
From: Markus Pargmann @ 2015-08-14 14:11 UTC (permalink / raw)
  To: Linus Walleij
  Cc: Alexandre Courbot, Arun Bharadwaj, Uwe Kleine-König,
	Johan Hovold, linux-gpio, linux-arm-kernel, kernel,
	Markus Pargmann

chip->dev should be initialized at this point so we can use dev_* here
instead of pr_warn.

Signed-off-by: Markus Pargmann <mpa@pengutronix.de>
---
 drivers/gpio/gpiolib-of.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/drivers/gpio/gpiolib-of.c b/drivers/gpio/gpiolib-of.c
index 1911b692f735..48a7579dd62d 100644
--- a/drivers/gpio/gpiolib-of.c
+++ b/drivers/gpio/gpiolib-of.c
@@ -227,8 +227,8 @@ static void of_gpiochip_scan_gpios(struct gpio_chip *chip)
 
 		if (of_property_read_bool(np, "gpio-hog")) {
 			if (!dflags) {
-				pr_warn("GPIO line %d (%s): no hogging state specified, bailing out\n",
-					desc_to_gpio(desc), np->name);
+				dev_warn(chip->dev, "GPIO line %d (%s): no hogging state specified, bailing out\n",
+					 desc_to_gpio(desc), np->name);
 				continue;
 			}
 
-- 
2.4.6


^ permalink raw reply related	[flat|nested] 22+ messages in thread

* Re: [PATCH v3 0/9] gpiolib: Add GPIO name support
  2015-08-14 14:10 [PATCH v3 0/9] gpiolib: Add GPIO name support Markus Pargmann
                   ` (8 preceding siblings ...)
  2015-08-14 14:11 ` [PATCH v3 9/9] gpiolib-of: Use dev_warn instead of pr_warn Markus Pargmann
@ 2015-09-21 10:58 ` Markus Pargmann
  9 siblings, 0 replies; 22+ messages in thread
From: Markus Pargmann @ 2015-09-21 10:58 UTC (permalink / raw)
  To: Linus Walleij
  Cc: Alexandre Courbot, Arun Bharadwaj, Johan Hovold, linux-gpio,
	kernel, Uwe Kleine-König, linux-arm-kernel

[-- Attachment #1: Type: text/plain, Size: 5232 bytes --]

Hi,

On Fri, Aug 14, 2015 at 04:10:57PM +0200, Markus Pargmann wrote:
> Changes in v3:
> As discussed in the v2 thread, we are using the already existing gpiochip names
> now. To avoid races between kernel and userspace, the setup of gpio names in
> the gpio descriptors has to happen right before the gpiochip is added for use
> and after the gpio descriptors are available. Unfortunately this is exactly in
> the function gpiochip_add().
> 
> So we can't use a a function as proposed in the discussion like
> gpiochip_set_names(), as this function would only be possible after we executed
> gpiochip_add(). Before that point the gpio descriptors are not available. But
> this can potentially lead to races between userspace and the gpio chip.
> 
> That is the reason why I left the names array in the gpioscript. But this array
> is now only used to initialize the GPIO descriptors. The named sysfs
> directories are now created using the name stored in the gpio descriptor.
> 
> As the name is now directly represented through the sysfs directory name, I am
> not sure if it makes sense to keep the patch which adds a 'name' property to
> the sysfs GPIO directories. For the moment it is still in this series.

Any feedback on this series?

Thanks,

Markus

> 
> Other changes in v3:
>  - Renamed generic of_parse_gpio() to of_parse_own_gpio()
>  - Replaced pr_warn with dev_warn as the device is available in the parsing code
>    in gpiolib-of
>  - Introduced name collision checks when adding the names from gpiochip->names
>    to the gpio descriptors
>  - Added documentation about /sys/class/gpio/<GPIO>/name
>  - Added check for DT in case the GPIO already has a name. This may happen as
>    there are different ways to set a name, through 'line-name' property and
>    node name
> 
> Best Regards,
> 
> Markus
> 
> 
> Changes in v2:
>  - Removed patch 'gpiolib: Fix possible use of wrong name'
>  - Removed discussed patch 'gpio: Allow hogged gpios to be requested' from this
>    series
>  - Fixed show gpio name patch (locks, (null) printing, and getting the descriptor)
>  - Merged gpio name patch into gpio_name_to_desc() patch
> 
> Description from v1:
> 
> This is a proposal to add GPIO names to the kernel based on devicetree
> descriptions.
> 
> This series adds GPIO name support. Until now it is only possible to use names
> for already requested GPIOs (for example what they are used for). It is not
> possible to identify GPIOs by a name although most of them have a name for
> example in the schematics of the board. This makes it difficult to identify
> a specific GPIO from userspace.
> 
> As the GPIO name information is a hardware description this series uses the
> devicetree bindings introduced by the GPIO hogging mechanism, specifically
> 'line-name', to identify GPIOs. The sysfs 'export' file is changed to accept
> names as fallback. The gpio numbers still have a higher priority to ensure
> backwards compatibility.
> 
> Exported GPIOs are still using their number as directory name (gpio<ID>). But the
> directories now contain a 'name' file which is '' for non-existent names and
> the name otherwise.
> 
> This series can be used to have an easy name mapping for udev with a quite
> simple rule similar to this:
> 	SUBSYSTEM=="gpio", KERNEL=="gpio*", ATTR{name}!="(null)", ACTION=="add", \
> 	PROGRAM+="/bin/sh -c 'mkdir -p /dev/gpios; rm -f /dev/gpios/$attr{name}; ln -s /sys%p/ /dev/gpios/$attr{name}"
> With this rule udev adds a link for each exported GPIO with a name into
> /dev/gpios/. This way it is not necessary to know the number of a GPIO to use
> it.
> 
> 
> Markus Pargmann (9):
>   gpiolib-of: Rename gpio_hog functions to be generic
>   gpio: Introduce gpio descriptor 'name'
>   gpiolib: Use GPIO name from names array for gpio descriptor
>   gpio-sysfs: Use gpio descriptor name instead of gpiochip names array
>   gpiolib: Add gpio name information to /sys/kernel/debug/gpio
>   gpiolib-sysfs: Show gpio-name in /sys/class/gpio/gpio*/name
>   gpiolib-sysfs: Add gpio name parsing for sysfs export
>   gpiolib-of: Reuse 'line-name' from DT as gpio descriptor name
>   gpiolib-of: Use dev_warn instead of pr_warn
> 
>  Documentation/ABI/testing/sysfs-gpio |  1 +
>  drivers/gpio/gpiolib-of.c            | 50 +++++++++++++---------
>  drivers/gpio/gpiolib-sysfs.c         | 67 +++++++++++++++++++++---------
>  drivers/gpio/gpiolib.c               | 80 ++++++++++++++++++++++++++++++++++--
>  drivers/gpio/gpiolib.h               |  3 ++
>  include/linux/gpio/consumer.h        |  7 ++++
>  6 files changed, 166 insertions(+), 42 deletions(-)
> 
> -- 
> 2.4.6
> 
> 
> _______________________________________________
> linux-arm-kernel mailing list
> linux-arm-kernel@lists.infradead.org
> http://lists.infradead.org/mailman/listinfo/linux-arm-kernel
> 

-- 
Pengutronix e.K.                           |                             |
Industrial Linux Solutions                 | http://www.pengutronix.de/  |
Peiner Str. 6-8, 31137 Hildesheim, Germany | Phone: +49-5121-206917-0    |
Amtsgericht Hildesheim, HRA 2686           | Fax:   +49-5121-206917-5555 |

[-- Attachment #2: Digital signature --]
[-- Type: application/pgp-signature, Size: 819 bytes --]

^ permalink raw reply	[flat|nested] 22+ messages in thread

* Re: [PATCH v3 1/9] gpiolib-of: Rename gpio_hog functions to be generic
  2015-08-14 14:10 ` [PATCH v3 1/9] gpiolib-of: Rename gpio_hog functions to be generic Markus Pargmann
@ 2015-09-22  0:48   ` Linus Walleij
  0 siblings, 0 replies; 22+ messages in thread
From: Linus Walleij @ 2015-09-22  0:48 UTC (permalink / raw)
  To: Markus Pargmann
  Cc: Alexandre Courbot, Arun Bharadwaj, Uwe Kleine-König,
	Johan Hovold, linux-gpio@vger.kernel.org,
	linux-arm-kernel@lists.infradead.org, Sascha Hauer

On Fri, Aug 14, 2015 at 7:10 AM, Markus Pargmann <mpa@pengutronix.de> wrote:

> The gpio hogging functions are currently only used for gpio-hogging. But
> these functions are widely generic ones which parse gpio device nodes in
> the DT.
>
> Signed-off-by: Markus Pargmann <mpa@pengutronix.de>

This patch applied after a small rebasing.

BTW: at this point, please base your subsequent submissions on my
"devel" branch from linux-gpio as I am starting to apply some stuff.

Yours,
Linus Walleij

^ permalink raw reply	[flat|nested] 22+ messages in thread

* Re: [PATCH v3 2/9] gpio: Introduce gpio descriptor 'name'
  2015-08-14 14:10 ` [PATCH v3 2/9] gpio: Introduce gpio descriptor 'name' Markus Pargmann
@ 2015-09-22  0:51   ` Linus Walleij
  0 siblings, 0 replies; 22+ messages in thread
From: Linus Walleij @ 2015-09-22  0:51 UTC (permalink / raw)
  To: Markus Pargmann
  Cc: Alexandre Courbot, Arun Bharadwaj, Uwe Kleine-König,
	Johan Hovold, linux-gpio@vger.kernel.org,
	linux-arm-kernel@lists.infradead.org, Sascha Hauer

On Fri, Aug 14, 2015 at 7:10 AM, Markus Pargmann <mpa@pengutronix.de> wrote:

> The latest gpio hogging mechanism assigns each gpio a 'line-name' in the
> devicetree. The 'name' field is different from the 'label' field.
> 'label' is only used for requested GPIOs to describe its current use by
> driver or userspace.
>
> The 'name' field describes the GPIO itself, not the use. This is most
> likely identical to the label in the schematic on the GPIO line and
> should help to find this particular GPIO.
>
> This is equivalent to the gpiochip->names array. However names should be
> stored in the GPIO descriptor. We will use gpiochip->names in the future
> only as initializer for the GPIO descriptors for drivers that assign
> GPIO names hardcoded. All other GPIO names will be parsed from DT and
> directly assigned to the GPIO descriptor.
>
> This patch adds a helper function to find gpio descriptors by name
> instead of gpio number.
>
> Signed-off-by: Markus Pargmann <mpa@pengutronix.de>

Patch applied.

Yours,
Linus Walleij

^ permalink raw reply	[flat|nested] 22+ messages in thread

* Re: [PATCH v3 3/9] gpiolib: Use GPIO name from names array for gpio descriptor
  2015-08-14 14:11 ` [PATCH v3 3/9] gpiolib: Use GPIO name from names array for gpio descriptor Markus Pargmann
@ 2015-09-22  0:56   ` Linus Walleij
  2015-09-23 22:02   ` Johan Hovold
  1 sibling, 0 replies; 22+ messages in thread
From: Linus Walleij @ 2015-09-22  0:56 UTC (permalink / raw)
  To: Markus Pargmann
  Cc: Alexandre Courbot, Arun Bharadwaj, Uwe Kleine-König,
	Johan Hovold, linux-gpio@vger.kernel.org,
	linux-arm-kernel@lists.infradead.org, Sascha Hauer

On Fri, Aug 14, 2015 at 7:11 AM, Markus Pargmann <mpa@pengutronix.de> wrote:

> This patch adds GPIO names to the GPIO descriptors when initializing the
> gpiochip. It also introduces a check whether any of the new names will
> conflict with an existing GPIO name.
>
> Signed-off-by: Markus Pargmann <mpa@pengutronix.de>

Patch applied. To me this is the magic transition patch that make
things really smooth.

Yours,
Linus Walleij

^ permalink raw reply	[flat|nested] 22+ messages in thread

* Re: [PATCH v3 4/9] gpio-sysfs: Use gpio descriptor name instead of gpiochip names array
  2015-08-14 14:11 ` [PATCH v3 4/9] gpio-sysfs: Use gpio descriptor name instead of gpiochip names array Markus Pargmann
@ 2015-09-22  0:57   ` Linus Walleij
  0 siblings, 0 replies; 22+ messages in thread
From: Linus Walleij @ 2015-09-22  0:57 UTC (permalink / raw)
  To: Markus Pargmann
  Cc: Alexandre Courbot, Arun Bharadwaj, Uwe Kleine-König,
	Johan Hovold, linux-gpio@vger.kernel.org,
	linux-arm-kernel@lists.infradead.org, Sascha Hauer

On Fri, Aug 14, 2015 at 7:11 AM, Markus Pargmann <mpa@pengutronix.de> wrote:

> The name is now stored in the gpio descriptor as well, for example to
> allow to store names from DT. This patch changes the sysfs gpio files
> to use the gpio descriptor name.
>
> Signed-off-by: Markus Pargmann <mpa@pengutronix.de>

Patch applied. This is a very nice patch too.

Yours,
Linus Walleij

^ permalink raw reply	[flat|nested] 22+ messages in thread

* Re: [PATCH v3 5/9] gpiolib: Add gpio name information to /sys/kernel/debug/gpio
  2015-08-14 14:11 ` [PATCH v3 5/9] gpiolib: Add gpio name information to /sys/kernel/debug/gpio Markus Pargmann
@ 2015-09-22  1:05   ` Linus Walleij
  0 siblings, 0 replies; 22+ messages in thread
From: Linus Walleij @ 2015-09-22  1:05 UTC (permalink / raw)
  To: Markus Pargmann
  Cc: Alexandre Courbot, Arun Bharadwaj, Uwe Kleine-König,
	Johan Hovold, linux-gpio@vger.kernel.org,
	linux-arm-kernel@lists.infradead.org, Sascha Hauer

On Fri, Aug 14, 2015 at 7:11 AM, Markus Pargmann <mpa@pengutronix.de> wrote:

> Add some information about gpio names to the debugfs gpio file. name and
> label of a GPIO are then displayed next to each other. This way it is
> easy to see what the real name of GPIO is and what the driver requested
> it for.
>
> Signed-off-by: Markus Pargmann <mpa@pengutronix.de>

PARTLY applied.

> +++ b/Documentation/ABI/testing/sysfs-gpio
> @@ -21,6 +21,7 @@ Description:
>             /value ... always readable, writes fail for input GPIOs
>             /direction ... r/w as: in, out (default low); write: high, low
>             /edge ... r/w as: none, falling, rising, both
> +           /name ... r/o, unique name of the GPIO

This patch has nothing to do with sysfs and this is not added to the ABI.
I removed this hunk from the patch.

The rest is applied.

Yours,
Linus Walleij

^ permalink raw reply	[flat|nested] 22+ messages in thread

* Re: [PATCH v3 6/9] gpiolib-sysfs: Show gpio-name in /sys/class/gpio/gpio*/name
  2015-08-14 14:11 ` [PATCH v3 6/9] gpiolib-sysfs: Show gpio-name in /sys/class/gpio/gpio*/name Markus Pargmann
@ 2015-09-22  1:07   ` Linus Walleij
  2015-09-24  7:14     ` Markus Pargmann
  0 siblings, 1 reply; 22+ messages in thread
From: Linus Walleij @ 2015-09-22  1:07 UTC (permalink / raw)
  To: Markus Pargmann
  Cc: Alexandre Courbot, Arun Bharadwaj, Uwe Kleine-König,
	Johan Hovold, linux-gpio@vger.kernel.org,
	linux-arm-kernel@lists.infradead.org, Sascha Hauer

On Fri, Aug 14, 2015 at 7:11 AM, Markus Pargmann <mpa@pengutronix.de> wrote:

> This patch adds a sysfs attribute 'name' to gpios that were exported. It
> exposes the newly added name property of gpio descriptors.
>
> Signed-off-by: Markus Pargmann <mpa@pengutronix.de>

The previous hunk adding the name to the sysfs ABI should
be in this patch.

But I have a problem with this. What is the rationale? The directory
that contains the file already has this name. Why should this
information be duplicated?

Yours,
Linus Walleij

^ permalink raw reply	[flat|nested] 22+ messages in thread

* Re: [PATCH v3 7/9] gpiolib-sysfs: Add gpio name parsing for sysfs export
  2015-08-14 14:11 ` [PATCH v3 7/9] gpiolib-sysfs: Add gpio name parsing for sysfs export Markus Pargmann
@ 2015-09-22  1:09   ` Linus Walleij
  2015-09-24  7:23     ` Markus Pargmann
  0 siblings, 1 reply; 22+ messages in thread
From: Linus Walleij @ 2015-09-22  1:09 UTC (permalink / raw)
  To: Markus Pargmann
  Cc: Alexandre Courbot, Arun Bharadwaj, Uwe Kleine-König,
	Johan Hovold, linux-gpio@vger.kernel.org,
	linux-arm-kernel@lists.infradead.org, Sascha Hauer

On Fri, Aug 14, 2015 at 7:11 AM, Markus Pargmann <mpa@pengutronix.de> wrote:

> Signed-off-by: Markus Pargmann <mpa@pengutronix.de>

This has too terse commit description. I don't understand the patch or
what it is supposed to do.

Yours,
Linus Walleij

^ permalink raw reply	[flat|nested] 22+ messages in thread

* Re: [PATCH v3 3/9] gpiolib: Use GPIO name from names array for gpio descriptor
  2015-08-14 14:11 ` [PATCH v3 3/9] gpiolib: Use GPIO name from names array for gpio descriptor Markus Pargmann
  2015-09-22  0:56   ` Linus Walleij
@ 2015-09-23 22:02   ` Johan Hovold
  2015-09-24 21:50     ` Linus Walleij
  1 sibling, 1 reply; 22+ messages in thread
From: Johan Hovold @ 2015-09-23 22:02 UTC (permalink / raw)
  To: Markus Pargmann
  Cc: Linus Walleij, Alexandre Courbot, Arun Bharadwaj,
	Uwe Kleine-König, Johan Hovold, linux-gpio, linux-arm-kernel,
	kernel

On Fri, Aug 14, 2015 at 04:11:00PM +0200, Markus Pargmann wrote:
> This patch adds GPIO names to the GPIO descriptors when initializing the
> gpiochip. It also introduces a check whether any of the new names will
> conflict with an existing GPIO name.

And this is why we should not do this. I've said it it before: we need
to consider dynamic buses, not just static device trees.

We have USB and Greybus that will soon be exposing gpiochips and their
line-names can not be globally unique.

Before figuring out what a sane userspace interface should look like we
should not make ABI changes that we need to support indefinitely. The
legacy sysfs interface should instead be frozen.

Exposing a name attribute for a not-necessarily globally unique name
could perhaps be ok, but by enforcing uniqueness at this point we will
then need to come up with another mechanism for naming gpios on dynamic
buses (while maintaining this one indefinitely in parallel).

Linus, please consider dropping these changes for now.

Thanks,
Johan

^ permalink raw reply	[flat|nested] 22+ messages in thread

* Re: [PATCH v3 6/9] gpiolib-sysfs: Show gpio-name in /sys/class/gpio/gpio*/name
  2015-09-22  1:07   ` Linus Walleij
@ 2015-09-24  7:14     ` Markus Pargmann
  0 siblings, 0 replies; 22+ messages in thread
From: Markus Pargmann @ 2015-09-24  7:14 UTC (permalink / raw)
  To: Linus Walleij
  Cc: Alexandre Courbot, Arun Bharadwaj, Uwe Kleine-König,
	Johan Hovold, linux-gpio@vger.kernel.org,
	linux-arm-kernel@lists.infradead.org, Sascha Hauer

[-- Attachment #1: Type: text/plain, Size: 1111 bytes --]

On Mon, Sep 21, 2015 at 06:07:51PM -0700, Linus Walleij wrote:
> On Fri, Aug 14, 2015 at 7:11 AM, Markus Pargmann <mpa@pengutronix.de> wrote:
> 
> > This patch adds a sysfs attribute 'name' to gpios that were exported. It
> > exposes the newly added name property of gpio descriptors.
> >
> > Signed-off-by: Markus Pargmann <mpa@pengutronix.de>
> 
> The previous hunk adding the name to the sysfs ABI should
> be in this patch.
> 
> But I have a problem with this. What is the rationale? The directory
> that contains the file already has this name. Why should this
> information be duplicated?

No reason for that. As described in the summary, I wasn't sure if this
makes sense but included it anyway from the last series version. So it
can simply be dropped.

Thanks,

Markus

-- 
Pengutronix e.K.                           |                             |
Industrial Linux Solutions                 | http://www.pengutronix.de/  |
Peiner Str. 6-8, 31137 Hildesheim, Germany | Phone: +49-5121-206917-0    |
Amtsgericht Hildesheim, HRA 2686           | Fax:   +49-5121-206917-5555 |

[-- Attachment #2: Digital signature --]
[-- Type: application/pgp-signature, Size: 819 bytes --]

^ permalink raw reply	[flat|nested] 22+ messages in thread

* Re: [PATCH v3 7/9] gpiolib-sysfs: Add gpio name parsing for sysfs export
  2015-09-22  1:09   ` Linus Walleij
@ 2015-09-24  7:23     ` Markus Pargmann
  0 siblings, 0 replies; 22+ messages in thread
From: Markus Pargmann @ 2015-09-24  7:23 UTC (permalink / raw)
  To: Linus Walleij
  Cc: Alexandre Courbot, Arun Bharadwaj, Uwe Kleine-König,
	Johan Hovold, linux-gpio@vger.kernel.org,
	linux-arm-kernel@lists.infradead.org, Sascha Hauer

[-- Attachment #1: Type: text/plain, Size: 1543 bytes --]

On Mon, Sep 21, 2015 at 06:09:15PM -0700, Linus Walleij wrote:
> On Fri, Aug 14, 2015 at 7:11 AM, Markus Pargmann <mpa@pengutronix.de> wrote:
> 
> > Signed-off-by: Markus Pargmann <mpa@pengutronix.de>
> 
> This has too terse commit description. I don't understand the patch or
> what it is supposed to do.

Sorry, indeed, this requires a commit description. I would add something
like this:

In '/sys/class/gpio/' GPIOs can be exported by using their GPIO number.
If the exported GPIO has a name, it will show up as a new directory in
'/sys/class/gpio/<GPIO_NAME>'. It is somehow inconsistent to use a
number for exporting and the name for accessing the GPIO.

This patch adds the possibility to use the GPIO name to export it. This
introduces a consistent behaviour for exporting and accessing a GPIO
from userspace.

The mechanism of parsing the GPIO name is a fallback mechanism. This
ensures backwards compatibility of the gpio interface. If the string
passed to '/sys/class/gpio/export' can not be parsed as number, it tries
to match a GPIO name. The same behaviour is implemented for the
'unexport' file.

The implementation uses the previously defined gpio_name_to_desc().



Thanks,

Markus

-- 
Pengutronix e.K.                           |                             |
Industrial Linux Solutions                 | http://www.pengutronix.de/  |
Peiner Str. 6-8, 31137 Hildesheim, Germany | Phone: +49-5121-206917-0    |
Amtsgericht Hildesheim, HRA 2686           | Fax:   +49-5121-206917-5555 |

[-- Attachment #2: Digital signature --]
[-- Type: application/pgp-signature, Size: 819 bytes --]

^ permalink raw reply	[flat|nested] 22+ messages in thread

* Re: [PATCH v3 3/9] gpiolib: Use GPIO name from names array for gpio descriptor
  2015-09-23 22:02   ` Johan Hovold
@ 2015-09-24 21:50     ` Linus Walleij
  0 siblings, 0 replies; 22+ messages in thread
From: Linus Walleij @ 2015-09-24 21:50 UTC (permalink / raw)
  To: Johan Hovold
  Cc: Markus Pargmann, Alexandre Courbot, Arun Bharadwaj,
	Uwe Kleine-König, linux-gpio@vger.kernel.org,
	linux-arm-kernel@lists.infradead.org, Sascha Hauer

On Wed, Sep 23, 2015 at 3:02 PM, Johan Hovold <johan@kernel.org> wrote:

> Before figuring out what a sane userspace interface should look like we
> should not make ABI changes that we need to support indefinitely. The
> legacy sysfs interface should instead be frozen.
>
> Exposing a name attribute for a not-necessarily globally unique name
> could perhaps be ok, but by enforcing uniqueness at this point we will
> then need to come up with another mechanism for naming gpios on dynamic
> buses (while maintaining this one indefinitely in parallel).
>
> Linus, please consider dropping these changes for now.

I rounded off the series after moving the name attribute to the descriptor
before doing any ABI changes, as it seems we need to discuss this.

This patch concludes that part of the series, sent a separate patch
concluding this first half of the series.

Yours,
Linus Walleij

^ permalink raw reply	[flat|nested] 22+ messages in thread

end of thread, other threads:[~2015-09-24 21:50 UTC | newest]

Thread overview: 22+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2015-08-14 14:10 [PATCH v3 0/9] gpiolib: Add GPIO name support Markus Pargmann
2015-08-14 14:10 ` [PATCH v3 1/9] gpiolib-of: Rename gpio_hog functions to be generic Markus Pargmann
2015-09-22  0:48   ` Linus Walleij
2015-08-14 14:10 ` [PATCH v3 2/9] gpio: Introduce gpio descriptor 'name' Markus Pargmann
2015-09-22  0:51   ` Linus Walleij
2015-08-14 14:11 ` [PATCH v3 3/9] gpiolib: Use GPIO name from names array for gpio descriptor Markus Pargmann
2015-09-22  0:56   ` Linus Walleij
2015-09-23 22:02   ` Johan Hovold
2015-09-24 21:50     ` Linus Walleij
2015-08-14 14:11 ` [PATCH v3 4/9] gpio-sysfs: Use gpio descriptor name instead of gpiochip names array Markus Pargmann
2015-09-22  0:57   ` Linus Walleij
2015-08-14 14:11 ` [PATCH v3 5/9] gpiolib: Add gpio name information to /sys/kernel/debug/gpio Markus Pargmann
2015-09-22  1:05   ` Linus Walleij
2015-08-14 14:11 ` [PATCH v3 6/9] gpiolib-sysfs: Show gpio-name in /sys/class/gpio/gpio*/name Markus Pargmann
2015-09-22  1:07   ` Linus Walleij
2015-09-24  7:14     ` Markus Pargmann
2015-08-14 14:11 ` [PATCH v3 7/9] gpiolib-sysfs: Add gpio name parsing for sysfs export Markus Pargmann
2015-09-22  1:09   ` Linus Walleij
2015-09-24  7:23     ` Markus Pargmann
2015-08-14 14:11 ` [PATCH v3 8/9] gpiolib-of: Reuse 'line-name' from DT as gpio descriptor name Markus Pargmann
2015-08-14 14:11 ` [PATCH v3 9/9] gpiolib-of: Use dev_warn instead of pr_warn Markus Pargmann
2015-09-21 10:58 ` [PATCH v3 0/9] gpiolib: Add GPIO name support Markus Pargmann

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).