linux-gpio.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH 00/11] Add support for software nodes to gpiolib
@ 2019-09-11  7:52 Dmitry Torokhov
  2019-09-11  7:52 ` [PATCH 01/11] gpiolib: of: add a fallback for wlf,reset GPIO name Dmitry Torokhov
                   ` (12 more replies)
  0 siblings, 13 replies; 39+ messages in thread
From: Dmitry Torokhov @ 2019-09-11  7:52 UTC (permalink / raw)
  To: Linus Walleij
  Cc: Andy Shevchenko, Mika Westerberg, linux-kernel, linux-gpio,
	Andrew Lunn, Andrzej Hajda, Bartosz Golaszewski, Daniel Vetter,
	David Airlie, David S. Miller, Florian Fainelli, Heiner Kallweit,
	Jernej Skrabec, Jonas Karlman, Laurent Pinchart, Neil Armstrong,
	Russell King, dri-devel, linux-acpi, netdev

This series attempts to add support for software nodes to gpiolib, using
software node references that were introduced recently. This allows us
to convert more drivers to the generic device properties and drop
support for custom platform data:

static const struct software_node gpio_bank_b_node = {
|-------.name = "B",
};

static const struct property_entry simone_key_enter_props[] = {
|-------PROPERTY_ENTRY_U32("linux,code", KEY_ENTER),
|-------PROPERTY_ENTRY_STRING("label", "enter"),
|-------PROPERTY_ENTRY_REF("gpios", &gpio_bank_b_node, 123, GPIO_ACTIVE_LOW),
|-------{ }
};

If we agree in principle, I would like to have the very first 3 patches
in an immutable branch off maybe -rc8 so that it can be pulled into
individual subsystems so that patches switching various drivers to
fwnode_gpiod_get_index() could be applied.

Thanks,
Dmitry

Dmitry Torokhov (11):
  gpiolib: of: add a fallback for wlf,reset GPIO name
  gpiolib: introduce devm_fwnode_gpiod_get_index()
  gpiolib: introduce fwnode_gpiod_get_index()
  net: phylink: switch to using fwnode_gpiod_get_index()
  net: mdio: switch to using fwnode_gpiod_get_index()
  drm/bridge: ti-tfp410: switch to using fwnode_gpiod_get_index()
  gpliolib: make fwnode_get_named_gpiod() static
  gpiolib: of: tease apart of_find_gpio()
  gpiolib: of: tease apart acpi_find_gpio()
  gpiolib: consolidate fwnode GPIO lookups
  gpiolib: add support for software nodes

 drivers/gpio/Makefile              |   1 +
 drivers/gpio/gpiolib-acpi.c        | 153 ++++++++++++++----------
 drivers/gpio/gpiolib-acpi.h        |  21 ++--
 drivers/gpio/gpiolib-devres.c      |  33 ++----
 drivers/gpio/gpiolib-of.c          | 159 ++++++++++++++-----------
 drivers/gpio/gpiolib-of.h          |  26 ++--
 drivers/gpio/gpiolib-swnode.c      |  92 +++++++++++++++
 drivers/gpio/gpiolib-swnode.h      |  13 ++
 drivers/gpio/gpiolib.c             | 184 ++++++++++++++++-------------
 drivers/gpu/drm/bridge/ti-tfp410.c |   4 +-
 drivers/net/phy/mdio_bus.c         |   4 +-
 drivers/net/phy/phylink.c          |   4 +-
 include/linux/gpio/consumer.h      |  53 ++++++---
 13 files changed, 471 insertions(+), 276 deletions(-)
 create mode 100644 drivers/gpio/gpiolib-swnode.c
 create mode 100644 drivers/gpio/gpiolib-swnode.h

-- 
2.23.0.162.g0b9fbb3734-goog


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

* [PATCH 01/11] gpiolib: of: add a fallback for wlf,reset GPIO name
  2019-09-11  7:52 [PATCH 00/11] Add support for software nodes to gpiolib Dmitry Torokhov
@ 2019-09-11  7:52 ` Dmitry Torokhov
  2019-09-12  9:30   ` Linus Walleij
  2019-09-11  7:52 ` [PATCH 02/11] gpiolib: introduce devm_fwnode_gpiod_get_index() Dmitry Torokhov
                   ` (11 subsequent siblings)
  12 siblings, 1 reply; 39+ messages in thread
From: Dmitry Torokhov @ 2019-09-11  7:52 UTC (permalink / raw)
  To: Linus Walleij
  Cc: Andy Shevchenko, Mika Westerberg, linux-kernel, linux-gpio,
	Bartosz Golaszewski

The old Arizona binding did not use -gpio or -gpios suffix, so
devm_gpiod_get() does not work for it. As it is the one of a few users
of devm_gpiod_get_from_of_node() API that I want to remove, I'd rather
have a small quirk in the gpiolib OF handler, and switch Arizona
driver to devm_gpiod_get().

Signed-off-by: Dmitry Torokhov <dmitry.torokhov@gmail.com>
---

 drivers/gpio/gpiolib-of.c | 16 ++++++++++++++++
 1 file changed, 16 insertions(+)

diff --git a/drivers/gpio/gpiolib-of.c b/drivers/gpio/gpiolib-of.c
index b45b39c48a34..8b773f7d7724 100644
--- a/drivers/gpio/gpiolib-of.c
+++ b/drivers/gpio/gpiolib-of.c
@@ -438,6 +438,19 @@ static struct gpio_desc *of_find_regulator_gpio(struct device *dev, const char *
 	return desc;
 }
 
+static struct gpio_desc *of_find_arizona_gpio(struct device *dev,
+					      const char *con_id,
+					      enum of_gpio_flags *of_flags)
+{
+	if (!IS_ENABLED(CONFIG_MFD_ARIZONA))
+		return ERR_PTR(-ENOENT);
+
+	if (!con_id || strcmp(con_id, "wlf,reset"))
+		return ERR_PTR(-ENOENT);
+
+	return of_get_named_gpiod_flags(dev->of_node, con_id, 0, of_flags);
+}
+
 struct gpio_desc *of_find_gpio(struct device *dev, const char *con_id,
 			       unsigned int idx, unsigned long *flags)
 {
@@ -479,6 +492,9 @@ struct gpio_desc *of_find_gpio(struct device *dev, const char *con_id,
 		desc = of_find_regulator_gpio(dev, con_id, &of_flags);
 	}
 
+	if (IS_ERR(desc) && PTR_ERR(desc) == -ENOENT)
+		desc = of_find_arizona_gpio(dev, con_id, &of_flags);
+
 	if (IS_ERR(desc))
 		return desc;
 
-- 
2.23.0.162.g0b9fbb3734-goog


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

* [PATCH 02/11] gpiolib: introduce devm_fwnode_gpiod_get_index()
  2019-09-11  7:52 [PATCH 00/11] Add support for software nodes to gpiolib Dmitry Torokhov
  2019-09-11  7:52 ` [PATCH 01/11] gpiolib: of: add a fallback for wlf,reset GPIO name Dmitry Torokhov
@ 2019-09-11  7:52 ` Dmitry Torokhov
  2019-09-11 17:01   ` Andy Shevchenko
  2019-09-12  9:48   ` Linus Walleij
  2019-09-11  7:52 ` [PATCH 03/11] gpiolib: introduce fwnode_gpiod_get_index() Dmitry Torokhov
                   ` (10 subsequent siblings)
  12 siblings, 2 replies; 39+ messages in thread
From: Dmitry Torokhov @ 2019-09-11  7:52 UTC (permalink / raw)
  To: Linus Walleij
  Cc: Andy Shevchenko, Mika Westerberg, linux-kernel, linux-gpio,
	Bartosz Golaszewski

devm_fwnode_get_index_gpiod_from_child() is too long, besides the fwnode
in question does not have to be a child of device node. Let's rename it
to devm_fwnode_gpiod_get_index() and keep the old name for compatibility
for now.

Also let's add a devm_fwnode_gpiod_get() wrapper as majority of the
callers need a single GPIO.

Signed-off-by: Dmitry Torokhov <dmitry.torokhov@gmail.com>
---

 drivers/gpio/gpiolib-devres.c | 19 ++++++++--------
 include/linux/gpio/consumer.h | 41 ++++++++++++++++++++++++++---------
 2 files changed, 40 insertions(+), 20 deletions(-)

diff --git a/drivers/gpio/gpiolib-devres.c b/drivers/gpio/gpiolib-devres.c
index 0acc2cc6e868..190ce7c43b4e 100644
--- a/drivers/gpio/gpiolib-devres.c
+++ b/drivers/gpio/gpiolib-devres.c
@@ -185,12 +185,11 @@ struct gpio_desc *devm_gpiod_get_from_of_node(struct device *dev,
 EXPORT_SYMBOL(devm_gpiod_get_from_of_node);
 
 /**
- * devm_fwnode_get_index_gpiod_from_child - get a GPIO descriptor from a
- *					    device's child node
+ * devm_fwnode_gpiod_get_index - get a GPIO descriptor from a given node
  * @dev:	GPIO consumer
+ * @fwnode:	firmware node containing GPIO reference
  * @con_id:	function within the GPIO consumer
  * @index:	index of the GPIO to obtain in the consumer
- * @child:	firmware node (child of @dev)
  * @flags:	GPIO initialization flags
  * @label:	label to attach to the requested GPIO
  *
@@ -200,11 +199,11 @@ EXPORT_SYMBOL(devm_gpiod_get_from_of_node);
  * On successful request the GPIO pin is configured in accordance with
  * provided @flags.
  */
-struct gpio_desc *devm_fwnode_get_index_gpiod_from_child(struct device *dev,
-						const char *con_id, int index,
-						struct fwnode_handle *child,
-						enum gpiod_flags flags,
-						const char *label)
+struct gpio_desc *devm_fwnode_gpiod_get_index(struct device *dev,
+					      struct fwnode_handle *fwnode,
+					      const char *con_id, int index,
+					      enum gpiod_flags flags,
+					      const char *label)
 {
 	char prop_name[32]; /* 32 is max size of property name */
 	struct gpio_desc **dr;
@@ -224,7 +223,7 @@ struct gpio_desc *devm_fwnode_get_index_gpiod_from_child(struct device *dev,
 			snprintf(prop_name, sizeof(prop_name), "%s",
 					    gpio_suffixes[i]);
 
-		desc = fwnode_get_named_gpiod(child, prop_name, index, flags,
+		desc = fwnode_get_named_gpiod(fwnode, prop_name, index, flags,
 					      label);
 		if (!IS_ERR(desc) || (PTR_ERR(desc) != -ENOENT))
 			break;
@@ -239,7 +238,7 @@ struct gpio_desc *devm_fwnode_get_index_gpiod_from_child(struct device *dev,
 
 	return desc;
 }
-EXPORT_SYMBOL(devm_fwnode_get_index_gpiod_from_child);
+EXPORT_SYMBOL(devm_fwnode_gpiod_get_index);
 
 /**
  * devm_gpiod_get_index_optional - Resource-managed gpiod_get_index_optional()
diff --git a/include/linux/gpio/consumer.h b/include/linux/gpio/consumer.h
index b70af921c614..dc0ddcd30515 100644
--- a/include/linux/gpio/consumer.h
+++ b/include/linux/gpio/consumer.h
@@ -176,11 +176,11 @@ struct gpio_desc *fwnode_get_named_gpiod(struct fwnode_handle *fwnode,
 					 const char *propname, int index,
 					 enum gpiod_flags dflags,
 					 const char *label);
-struct gpio_desc *devm_fwnode_get_index_gpiod_from_child(struct device *dev,
-						const char *con_id, int index,
-						struct fwnode_handle *child,
-						enum gpiod_flags flags,
-						const char *label);
+struct gpio_desc *devm_fwnode_gpiod_get_index(struct device *dev,
+					      struct fwnode_handle *child,
+					      const char *con_id, int index,
+					      enum gpiod_flags flags,
+					      const char *label);
 
 #else /* CONFIG_GPIOLIB */
 
@@ -531,6 +531,29 @@ struct gpio_desc *fwnode_get_named_gpiod(struct fwnode_handle *fwnode,
 	return ERR_PTR(-ENOSYS);
 }
 
+static inline
+struct gpio_desc *devm_fwnode_gpiod_get_index(struct device *dev,
+					      struct fwnode_handle *fwnode,
+					      const char *con_id, int index,
+					      enum gpiod_flags flags,
+					      const char *label)
+{
+	return ERR_PTR(-ENOSYS);
+}
+
+#endif /* CONFIG_GPIOLIB */
+
+static inline
+struct gpio_desc *devm_fwnode_gpiod_get(struct device *dev,
+					struct fwnode_handle *fwnode,
+					const char *con_id,
+					enum gpiod_flags flags,
+					const char *label)
+{
+	return devm_fwnode_gpiod_get_index(dev, fwnode, con_id, 0,
+					   flags, label);
+}
+
 static inline
 struct gpio_desc *devm_fwnode_get_index_gpiod_from_child(struct device *dev,
 						const char *con_id, int index,
@@ -538,11 +561,10 @@ struct gpio_desc *devm_fwnode_get_index_gpiod_from_child(struct device *dev,
 						enum gpiod_flags flags,
 						const char *label)
 {
-	return ERR_PTR(-ENOSYS);
+	return devm_fwnode_gpiod_get_index(dev, child, con_id, index,
+					   flags, label);
 }
 
-#endif /* CONFIG_GPIOLIB */
-
 static inline
 struct gpio_desc *devm_fwnode_get_gpiod_from_child(struct device *dev,
 						   const char *con_id,
@@ -550,8 +572,7 @@ struct gpio_desc *devm_fwnode_get_gpiod_from_child(struct device *dev,
 						   enum gpiod_flags flags,
 						   const char *label)
 {
-	return devm_fwnode_get_index_gpiod_from_child(dev, con_id, 0, child,
-						      flags, label);
+	return devm_fwnode_gpiod_get_index(dev, child, con_id, 0, flags, label);
 }
 
 #if IS_ENABLED(CONFIG_GPIOLIB) && IS_ENABLED(CONFIG_OF_GPIO)
-- 
2.23.0.162.g0b9fbb3734-goog


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

* [PATCH 03/11] gpiolib: introduce fwnode_gpiod_get_index()
  2019-09-11  7:52 [PATCH 00/11] Add support for software nodes to gpiolib Dmitry Torokhov
  2019-09-11  7:52 ` [PATCH 01/11] gpiolib: of: add a fallback for wlf,reset GPIO name Dmitry Torokhov
  2019-09-11  7:52 ` [PATCH 02/11] gpiolib: introduce devm_fwnode_gpiod_get_index() Dmitry Torokhov
@ 2019-09-11  7:52 ` Dmitry Torokhov
  2019-09-12  9:50   ` Linus Walleij
  2019-09-11  7:52 ` [PATCH 04/11] net: phylink: switch to using fwnode_gpiod_get_index() Dmitry Torokhov
                   ` (9 subsequent siblings)
  12 siblings, 1 reply; 39+ messages in thread
From: Dmitry Torokhov @ 2019-09-11  7:52 UTC (permalink / raw)
  To: Linus Walleij
  Cc: Andy Shevchenko, Mika Westerberg, linux-kernel, linux-gpio,
	Bartosz Golaszewski

This introduces fwnode_gpiod_get_index() that iterates through common gpio
suffixes when trying to locate a GPIO within a given firmware node.

We also switch devm_fwnode_gpiod_get_index() to call
fwnode_gpiod_get_index() instead of iterating through GPIO suffixes on
its own.

Signed-off-by: Dmitry Torokhov <dmitry.torokhov@gmail.com>
---

 drivers/gpio/gpiolib-devres.c | 16 +-----------
 drivers/gpio/gpiolib.c        | 48 +++++++++++++++++++++++++++++++++++
 include/linux/gpio/consumer.h | 13 ++++++++++
 3 files changed, 62 insertions(+), 15 deletions(-)

diff --git a/drivers/gpio/gpiolib-devres.c b/drivers/gpio/gpiolib-devres.c
index 190ce7c43b4e..693dcaf811bb 100644
--- a/drivers/gpio/gpiolib-devres.c
+++ b/drivers/gpio/gpiolib-devres.c
@@ -205,29 +205,15 @@ struct gpio_desc *devm_fwnode_gpiod_get_index(struct device *dev,
 					      enum gpiod_flags flags,
 					      const char *label)
 {
-	char prop_name[32]; /* 32 is max size of property name */
 	struct gpio_desc **dr;
 	struct gpio_desc *desc;
-	unsigned int i;
 
 	dr = devres_alloc(devm_gpiod_release, sizeof(struct gpio_desc *),
 			  GFP_KERNEL);
 	if (!dr)
 		return ERR_PTR(-ENOMEM);
 
-	for (i = 0; i < ARRAY_SIZE(gpio_suffixes); i++) {
-		if (con_id)
-			snprintf(prop_name, sizeof(prop_name), "%s-%s",
-					    con_id, gpio_suffixes[i]);
-		else
-			snprintf(prop_name, sizeof(prop_name), "%s",
-					    gpio_suffixes[i]);
-
-		desc = fwnode_get_named_gpiod(fwnode, prop_name, index, flags,
-					      label);
-		if (!IS_ERR(desc) || (PTR_ERR(desc) != -ENOENT))
-			break;
-	}
+	desc = fwnode_gpiod_get_index(fwnode, con_id, index, flags, label);
 	if (IS_ERR(desc)) {
 		devres_free(dr);
 		return desc;
diff --git a/drivers/gpio/gpiolib.c b/drivers/gpio/gpiolib.c
index edc1ea68db20..f15e3880aae5 100644
--- a/drivers/gpio/gpiolib.c
+++ b/drivers/gpio/gpiolib.c
@@ -4314,6 +4314,54 @@ static int platform_gpio_count(struct device *dev, const char *con_id)
 	return count;
 }
 
+/**
+ * fwnode_gpiod_get_index - obtain a GPIO from firmware node
+ * @fwnode:	handle of the firmware node
+ * @con_id:	function within the GPIO consumer
+ * @index:	index of the GPIO to obtain for the consumer
+ * @flags:	GPIO initialization flags
+ * @label:	label to attach to the requested GPIO
+ *
+ * This function can be used for drivers that get their configuration
+ * from opaque firmware.
+ *
+ * The function properly finds the corresponding GPIO using whatever is the
+ * underlying firmware interface and then makes sure that the GPIO
+ * descriptor is requested before it is returned to the caller.
+ *
+ * Returns:
+ * On successful request the GPIO pin is configured in accordance with
+ * provided @flags.
+ *
+ * In case of error an ERR_PTR() is returned.
+ */
+struct gpio_desc *fwnode_gpiod_get_index(struct fwnode_handle *fwnode,
+					 const char *con_id, int index,
+					 enum gpiod_flags flags,
+					 const char *label)
+{
+	struct gpio_desc *desc;
+	char prop_name[32]; /* 32 is max size of property name */
+	unsigned int i;
+
+	for (i = 0; i < ARRAY_SIZE(gpio_suffixes); i++) {
+		if (con_id)
+			snprintf(prop_name, sizeof(prop_name), "%s-%s",
+					    con_id, gpio_suffixes[i]);
+		else
+			snprintf(prop_name, sizeof(prop_name), "%s",
+					    gpio_suffixes[i]);
+
+		desc = fwnode_get_named_gpiod(fwnode, prop_name, index, flags,
+					      label);
+		if (!IS_ERR(desc) || (PTR_ERR(desc) != -ENOENT))
+			break;
+	}
+
+	return desc;
+}
+EXPORT_SYMBOL_GPL(fwnode_gpiod_get_index);
+
 /**
  * gpiod_count - return the number of GPIOs associated with a device / function
  *		or -ENOENT if no GPIO has been assigned to the requested function
diff --git a/include/linux/gpio/consumer.h b/include/linux/gpio/consumer.h
index dc0ddcd30515..5215fdba6b9a 100644
--- a/include/linux/gpio/consumer.h
+++ b/include/linux/gpio/consumer.h
@@ -176,6 +176,10 @@ struct gpio_desc *fwnode_get_named_gpiod(struct fwnode_handle *fwnode,
 					 const char *propname, int index,
 					 enum gpiod_flags dflags,
 					 const char *label);
+struct gpio_desc *fwnode_gpiod_get_index(struct fwnode_handle *fwnode,
+					 const char *con_id, int index,
+					 enum gpiod_flags flags,
+					 const char *label);
 struct gpio_desc *devm_fwnode_gpiod_get_index(struct device *dev,
 					      struct fwnode_handle *child,
 					      const char *con_id, int index,
@@ -531,6 +535,15 @@ struct gpio_desc *fwnode_get_named_gpiod(struct fwnode_handle *fwnode,
 	return ERR_PTR(-ENOSYS);
 }
 
+static inline
+struct gpio_desc *fwnode_gpiod_get_index(struct fwnode_handle *fwnode,
+					 const char *con_id, int index,
+					 enum gpiod_flags flags,
+					 const char *label)
+{
+	return ERR_PTR(-ENOSYS);
+}
+
 static inline
 struct gpio_desc *devm_fwnode_gpiod_get_index(struct device *dev,
 					      struct fwnode_handle *fwnode,
-- 
2.23.0.162.g0b9fbb3734-goog


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

* [PATCH 04/11] net: phylink: switch to using fwnode_gpiod_get_index()
  2019-09-11  7:52 [PATCH 00/11] Add support for software nodes to gpiolib Dmitry Torokhov
                   ` (2 preceding siblings ...)
  2019-09-11  7:52 ` [PATCH 03/11] gpiolib: introduce fwnode_gpiod_get_index() Dmitry Torokhov
@ 2019-09-11  7:52 ` Dmitry Torokhov
  2019-09-11  9:25   ` Andy Shevchenko
  2019-09-11  7:52 ` [PATCH 05/11] net: mdio: " Dmitry Torokhov
                   ` (8 subsequent siblings)
  12 siblings, 1 reply; 39+ messages in thread
From: Dmitry Torokhov @ 2019-09-11  7:52 UTC (permalink / raw)
  To: Linus Walleij
  Cc: Andy Shevchenko, Mika Westerberg, linux-kernel, linux-gpio,
	Andrew Lunn, David S. Miller, Florian Fainelli, Heiner Kallweit,
	Russell King, netdev

Instead of fwnode_get_named_gpiod() that I plan to hide away, let's use
the new fwnode_gpiod_get_index() that mimics gpiod_get_index(), bit
works with arbitrary firmware node.

Signed-off-by: Dmitry Torokhov <dmitry.torokhov@gmail.com>
---

 drivers/net/phy/phylink.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/drivers/net/phy/phylink.c b/drivers/net/phy/phylink.c
index a45c5de96ab1..14b608991445 100644
--- a/drivers/net/phy/phylink.c
+++ b/drivers/net/phy/phylink.c
@@ -168,8 +168,8 @@ static int phylink_parse_fixedlink(struct phylink *pl,
 			pl->link_config.pause |= MLO_PAUSE_ASYM;
 
 		if (ret == 0) {
-			desc = fwnode_get_named_gpiod(fixed_node, "link-gpios",
-						      0, GPIOD_IN, "?");
+			desc = fwnode_gpiod_get_index(fixed_node, "link", 0,
+						      GPIOD_IN, "?");
 
 			if (!IS_ERR(desc))
 				pl->link_gpio = desc;
-- 
2.23.0.162.g0b9fbb3734-goog


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

* [PATCH 05/11] net: mdio: switch to using fwnode_gpiod_get_index()
  2019-09-11  7:52 [PATCH 00/11] Add support for software nodes to gpiolib Dmitry Torokhov
                   ` (3 preceding siblings ...)
  2019-09-11  7:52 ` [PATCH 04/11] net: phylink: switch to using fwnode_gpiod_get_index() Dmitry Torokhov
@ 2019-09-11  7:52 ` Dmitry Torokhov
  2019-09-11  7:52 ` [PATCH 06/11] drm/bridge: ti-tfp410: " Dmitry Torokhov
                   ` (7 subsequent siblings)
  12 siblings, 0 replies; 39+ messages in thread
From: Dmitry Torokhov @ 2019-09-11  7:52 UTC (permalink / raw)
  To: Linus Walleij
  Cc: Andy Shevchenko, Mika Westerberg, linux-kernel, linux-gpio,
	Andrew Lunn, David S. Miller, Florian Fainelli, Heiner Kallweit,
	netdev

Instead of fwnode_get_named_gpiod() that I plan to hide away, let's use
the new fwnode_gpiod_get_index() that mimics gpiod_get_index(), bit
works with arbitrary firmware node.

Signed-off-by: Dmitry Torokhov <dmitry.torokhov@gmail.com>
---

 drivers/net/phy/mdio_bus.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/drivers/net/phy/mdio_bus.c b/drivers/net/phy/mdio_bus.c
index ce940871331e..9ca51d678123 100644
--- a/drivers/net/phy/mdio_bus.c
+++ b/drivers/net/phy/mdio_bus.c
@@ -46,8 +46,8 @@ static int mdiobus_register_gpiod(struct mdio_device *mdiodev)
 
 	/* Deassert the optional reset signal */
 	if (mdiodev->dev.of_node)
-		gpiod = fwnode_get_named_gpiod(&mdiodev->dev.of_node->fwnode,
-					       "reset-gpios", 0, GPIOD_OUT_LOW,
+		gpiod = fwnode_gpiod_get_index(&mdiodev->dev.of_node->fwnode,
+					       "reset", 0, GPIOD_OUT_LOW,
 					       "PHY reset");
 	if (IS_ERR(gpiod)) {
 		if (PTR_ERR(gpiod) == -ENOENT || PTR_ERR(gpiod) == -ENOSYS)
-- 
2.23.0.162.g0b9fbb3734-goog


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

* [PATCH 06/11] drm/bridge: ti-tfp410: switch to using fwnode_gpiod_get_index()
  2019-09-11  7:52 [PATCH 00/11] Add support for software nodes to gpiolib Dmitry Torokhov
                   ` (4 preceding siblings ...)
  2019-09-11  7:52 ` [PATCH 05/11] net: mdio: " Dmitry Torokhov
@ 2019-09-11  7:52 ` Dmitry Torokhov
  2019-09-20 23:12   ` Laurent Pinchart
  2019-09-11  7:52 ` [PATCH 07/11] gpliolib: make fwnode_get_named_gpiod() static Dmitry Torokhov
                   ` (6 subsequent siblings)
  12 siblings, 1 reply; 39+ messages in thread
From: Dmitry Torokhov @ 2019-09-11  7:52 UTC (permalink / raw)
  To: Linus Walleij
  Cc: Andy Shevchenko, Mika Westerberg, linux-kernel, linux-gpio,
	Andrzej Hajda, Daniel Vetter, David Airlie, Jernej Skrabec,
	Jonas Karlman, Laurent Pinchart, Neil Armstrong, dri-devel

Instead of fwnode_get_named_gpiod() that I plan to hide away, let's use
the new fwnode_gpiod_get_index() that mimics gpiod_get_index(), bit
works with arbitrary firmware node.

Signed-off-by: Dmitry Torokhov <dmitry.torokhov@gmail.com>
---

 drivers/gpu/drm/bridge/ti-tfp410.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/drivers/gpu/drm/bridge/ti-tfp410.c b/drivers/gpu/drm/bridge/ti-tfp410.c
index 61cc2354ef1b..d9c9c9ebad2b 100644
--- a/drivers/gpu/drm/bridge/ti-tfp410.c
+++ b/drivers/gpu/drm/bridge/ti-tfp410.c
@@ -284,8 +284,8 @@ static int tfp410_get_connector_properties(struct tfp410 *dvi)
 	else
 		dvi->connector_type = DRM_MODE_CONNECTOR_DVID;
 
-	dvi->hpd = fwnode_get_named_gpiod(&connector_node->fwnode,
-					"hpd-gpios", 0, GPIOD_IN, "hpd");
+	dvi->hpd = fwnode_gpiod_get_index(&connector_node->fwnode,
+					  "hpd", 0, GPIOD_IN, "hpd");
 	if (IS_ERR(dvi->hpd)) {
 		ret = PTR_ERR(dvi->hpd);
 		dvi->hpd = NULL;
-- 
2.23.0.162.g0b9fbb3734-goog


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

* [PATCH 07/11] gpliolib: make fwnode_get_named_gpiod() static
  2019-09-11  7:52 [PATCH 00/11] Add support for software nodes to gpiolib Dmitry Torokhov
                   ` (5 preceding siblings ...)
  2019-09-11  7:52 ` [PATCH 06/11] drm/bridge: ti-tfp410: " Dmitry Torokhov
@ 2019-09-11  7:52 ` Dmitry Torokhov
  2019-09-11  7:52 ` [PATCH 08/11] gpiolib: of: tease apart of_find_gpio() Dmitry Torokhov
                   ` (5 subsequent siblings)
  12 siblings, 0 replies; 39+ messages in thread
From: Dmitry Torokhov @ 2019-09-11  7:52 UTC (permalink / raw)
  To: Linus Walleij
  Cc: Andy Shevchenko, Mika Westerberg, linux-kernel, linux-gpio,
	Bartosz Golaszewski

Now that there are no external users of fwnode_get_named_gpiod() we can
make it static.

Signed-off-by: Dmitry Torokhov <dmitry.torokhov@gmail.com>
---

 drivers/gpio/gpiolib.c        | 108 ++++++++++++++--------------------
 include/linux/gpio/consumer.h |  13 ----
 2 files changed, 43 insertions(+), 78 deletions(-)

diff --git a/drivers/gpio/gpiolib.c b/drivers/gpio/gpiolib.c
index f15e3880aae5..54db2c42e9a0 100644
--- a/drivers/gpio/gpiolib.c
+++ b/drivers/gpio/gpiolib.c
@@ -4314,6 +4314,49 @@ static int platform_gpio_count(struct device *dev, const char *con_id)
 	return count;
 }
 
+static struct gpio_desc *fwnode_get_named_gpiod(struct fwnode_handle *fwnode,
+						const char *propname, int index,
+						enum gpiod_flags dflags,
+						const char *label)
+{
+	unsigned long lflags = GPIO_LOOKUP_FLAGS_DEFAULT;
+	struct gpio_desc *desc = ERR_PTR(-ENODEV);
+	int ret;
+
+	if (!fwnode)
+		return ERR_PTR(-EINVAL);
+
+	if (is_of_node(fwnode)) {
+		desc = gpiod_get_from_of_node(to_of_node(fwnode),
+					      propname, index,
+					      dflags,
+					      label);
+		return desc;
+	} else if (is_acpi_node(fwnode)) {
+		struct acpi_gpio_info info;
+
+		desc = acpi_node_get_gpiod(fwnode, propname, index, &info);
+		if (IS_ERR(desc))
+			return desc;
+
+		acpi_gpio_update_gpiod_flags(&dflags, &info);
+		acpi_gpio_update_gpiod_lookup_flags(&lflags, &info);
+	}
+
+	/* Currently only ACPI takes this path */
+	ret = gpiod_request(desc, label);
+	if (ret)
+		return ERR_PTR(ret);
+
+	ret = gpiod_configure_flags(desc, propname, lflags, dflags);
+	if (ret < 0) {
+		gpiod_put(desc);
+		return ERR_PTR(ret);
+	}
+
+	return desc;
+}
+
 /**
  * fwnode_gpiod_get_index - obtain a GPIO from firmware node
  * @fwnode:	handle of the firmware node
@@ -4574,71 +4617,6 @@ struct gpio_desc *__must_check gpiod_get_index(struct device *dev,
 }
 EXPORT_SYMBOL_GPL(gpiod_get_index);
 
-/**
- * fwnode_get_named_gpiod - obtain a GPIO from firmware node
- * @fwnode:	handle of the firmware node
- * @propname:	name of the firmware property representing the GPIO
- * @index:	index of the GPIO to obtain for the consumer
- * @dflags:	GPIO initialization flags
- * @label:	label to attach to the requested GPIO
- *
- * This function can be used for drivers that get their configuration
- * from opaque firmware.
- *
- * The function properly finds the corresponding GPIO using whatever is the
- * underlying firmware interface and then makes sure that the GPIO
- * descriptor is requested before it is returned to the caller.
- *
- * Returns:
- * On successful request the GPIO pin is configured in accordance with
- * provided @dflags.
- *
- * In case of error an ERR_PTR() is returned.
- */
-struct gpio_desc *fwnode_get_named_gpiod(struct fwnode_handle *fwnode,
-					 const char *propname, int index,
-					 enum gpiod_flags dflags,
-					 const char *label)
-{
-	unsigned long lflags = GPIO_LOOKUP_FLAGS_DEFAULT;
-	struct gpio_desc *desc = ERR_PTR(-ENODEV);
-	int ret;
-
-	if (!fwnode)
-		return ERR_PTR(-EINVAL);
-
-	if (is_of_node(fwnode)) {
-		desc = gpiod_get_from_of_node(to_of_node(fwnode),
-					      propname, index,
-					      dflags,
-					      label);
-		return desc;
-	} else if (is_acpi_node(fwnode)) {
-		struct acpi_gpio_info info;
-
-		desc = acpi_node_get_gpiod(fwnode, propname, index, &info);
-		if (IS_ERR(desc))
-			return desc;
-
-		acpi_gpio_update_gpiod_flags(&dflags, &info);
-		acpi_gpio_update_gpiod_lookup_flags(&lflags, &info);
-	}
-
-	/* Currently only ACPI takes this path */
-	ret = gpiod_request(desc, label);
-	if (ret)
-		return ERR_PTR(ret);
-
-	ret = gpiod_configure_flags(desc, propname, lflags, dflags);
-	if (ret < 0) {
-		gpiod_put(desc);
-		return ERR_PTR(ret);
-	}
-
-	return desc;
-}
-EXPORT_SYMBOL_GPL(fwnode_get_named_gpiod);
-
 /**
  * gpiod_get_index_optional - obtain an optional GPIO from a multi-index GPIO
  *                            function
diff --git a/include/linux/gpio/consumer.h b/include/linux/gpio/consumer.h
index 5215fdba6b9a..2f5e825f4601 100644
--- a/include/linux/gpio/consumer.h
+++ b/include/linux/gpio/consumer.h
@@ -172,10 +172,6 @@ int desc_to_gpio(const struct gpio_desc *desc);
 /* Child properties interface */
 struct fwnode_handle;
 
-struct gpio_desc *fwnode_get_named_gpiod(struct fwnode_handle *fwnode,
-					 const char *propname, int index,
-					 enum gpiod_flags dflags,
-					 const char *label);
 struct gpio_desc *fwnode_gpiod_get_index(struct fwnode_handle *fwnode,
 					 const char *con_id, int index,
 					 enum gpiod_flags flags,
@@ -526,15 +522,6 @@ static inline int desc_to_gpio(const struct gpio_desc *desc)
 /* Child properties interface */
 struct fwnode_handle;
 
-static inline
-struct gpio_desc *fwnode_get_named_gpiod(struct fwnode_handle *fwnode,
-					 const char *propname, int index,
-					 enum gpiod_flags dflags,
-					 const char *label)
-{
-	return ERR_PTR(-ENOSYS);
-}
-
 static inline
 struct gpio_desc *fwnode_gpiod_get_index(struct fwnode_handle *fwnode,
 					 const char *con_id, int index,
-- 
2.23.0.162.g0b9fbb3734-goog


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

* [PATCH 08/11] gpiolib: of: tease apart of_find_gpio()
  2019-09-11  7:52 [PATCH 00/11] Add support for software nodes to gpiolib Dmitry Torokhov
                   ` (6 preceding siblings ...)
  2019-09-11  7:52 ` [PATCH 07/11] gpliolib: make fwnode_get_named_gpiod() static Dmitry Torokhov
@ 2019-09-11  7:52 ` Dmitry Torokhov
  2019-09-11 17:10   ` Andy Shevchenko
  2019-09-11  7:52 ` [PATCH 09/11] gpiolib: of: tease apart acpi_find_gpio() Dmitry Torokhov
                   ` (4 subsequent siblings)
  12 siblings, 1 reply; 39+ messages in thread
From: Dmitry Torokhov @ 2019-09-11  7:52 UTC (permalink / raw)
  To: Linus Walleij
  Cc: Andy Shevchenko, Mika Westerberg, linux-kernel, linux-gpio,
	Bartosz Golaszewski

Tease apart of_find_gpio() into common function that works on the
firmware node, and a fallback handler that works on the device
structure, so that we can later use of_find_gpio() in
fwnode_gpiod_get_index().

Signed-off-by: Dmitry Torokhov <dmitry.torokhov@gmail.com>
---

 drivers/gpio/gpiolib-of.c | 149 +++++++++++++++++++-------------------
 drivers/gpio/gpiolib-of.h |  26 +++++--
 drivers/gpio/gpiolib.c    |   7 +-
 3 files changed, 99 insertions(+), 83 deletions(-)

diff --git a/drivers/gpio/gpiolib-of.c b/drivers/gpio/gpiolib-of.c
index 8b773f7d7724..1d1a18e0ad93 100644
--- a/drivers/gpio/gpiolib-of.c
+++ b/drivers/gpio/gpiolib-of.c
@@ -276,6 +276,28 @@ int of_get_named_gpio_flags(struct device_node *np, const char *list_name,
 }
 EXPORT_SYMBOL(of_get_named_gpio_flags);
 
+static void of_gpio_flags_to_lookup(enum of_gpio_flags of_flags,
+				    unsigned long *flags)
+{
+	if (of_flags & OF_GPIO_ACTIVE_LOW)
+		*flags |= GPIO_ACTIVE_LOW;
+
+	if (of_flags & OF_GPIO_SINGLE_ENDED) {
+		if (of_flags & OF_GPIO_OPEN_DRAIN)
+			*flags |= GPIO_OPEN_DRAIN;
+		else
+			*flags |= GPIO_OPEN_SOURCE;
+	}
+
+	if (of_flags & OF_GPIO_TRANSITORY)
+		*flags |= GPIO_TRANSITORY;
+
+	if (of_flags & OF_GPIO_PULL_UP)
+		*flags |= GPIO_PULL_UP;
+	if (of_flags & OF_GPIO_PULL_DOWN)
+		*flags |= GPIO_PULL_DOWN;
+}
+
 /**
  * gpiod_get_from_of_node() - obtain a GPIO from an OF node
  * @node:	handle of the OF node
@@ -298,10 +320,6 @@ struct gpio_desc *gpiod_get_from_of_node(struct device_node *node,
 	unsigned long lflags = GPIO_LOOKUP_FLAGS_DEFAULT;
 	struct gpio_desc *desc;
 	enum of_gpio_flags flags;
-	bool active_low = false;
-	bool single_ended = false;
-	bool open_drain = false;
-	bool transitory = false;
 	int ret;
 
 	desc = of_get_named_gpiod_flags(node, propname,
@@ -311,29 +329,13 @@ struct gpio_desc *gpiod_get_from_of_node(struct device_node *node,
 		return desc;
 	}
 
-	active_low = flags & OF_GPIO_ACTIVE_LOW;
-	single_ended = flags & OF_GPIO_SINGLE_ENDED;
-	open_drain = flags & OF_GPIO_OPEN_DRAIN;
-	transitory = flags & OF_GPIO_TRANSITORY;
-
 	ret = gpiod_request(desc, label);
 	if (ret == -EBUSY && (flags & GPIOD_FLAGS_BIT_NONEXCLUSIVE))
 		return desc;
 	if (ret)
 		return ERR_PTR(ret);
 
-	if (active_low)
-		lflags |= GPIO_ACTIVE_LOW;
-
-	if (single_ended) {
-		if (open_drain)
-			lflags |= GPIO_OPEN_DRAIN;
-		else
-			lflags |= GPIO_OPEN_SOURCE;
-	}
-
-	if (transitory)
-		lflags |= GPIO_TRANSITORY;
+	of_gpio_flags_to_lookup(flags, &lflags);
 
 	ret = gpiod_configure_flags(desc, propname, lflags, dflags);
 	if (ret < 0) {
@@ -345,6 +347,46 @@ struct gpio_desc *gpiod_get_from_of_node(struct device_node *node,
 }
 EXPORT_SYMBOL(gpiod_get_from_of_node);
 
+static struct gpio_desc *of_find_node_gpio(struct device_node *np,
+					   const char *con_id, unsigned int idx,
+					   enum of_gpio_flags *of_flags)
+{
+	struct gpio_desc *desc;
+	char prop_name[32]; /* 32 is max size of property name */
+	unsigned int i;
+
+	/* Try GPIO property "foo-gpios" and "foo-gpio" */
+	for (i = 0; i < ARRAY_SIZE(gpio_suffixes); i++) {
+		if (con_id)
+			snprintf(prop_name, sizeof(prop_name), "%s-%s", con_id,
+				 gpio_suffixes[i]);
+		else
+			snprintf(prop_name, sizeof(prop_name), "%s",
+				 gpio_suffixes[i]);
+
+		desc = of_get_named_gpiod_flags(np, prop_name, idx, of_flags);
+		if (!IS_ERR(desc) || PTR_ERR(desc) != -ENOENT)
+			break;
+	}
+
+	return desc;
+}
+
+struct gpio_desc *of_find_gpio(struct fwnode_handle *fwnode,
+			       const char *con_id, unsigned int idx,
+			       unsigned long *flags)
+{
+	struct device_node *np = to_of_node(fwnode);
+	struct gpio_desc *desc;
+	enum of_gpio_flags of_flags;
+
+	desc = of_find_node_gpio(np, con_id, idx, &of_flags);
+	if (!IS_ERR(desc))
+		of_gpio_flags_to_lookup(of_flags, flags);
+
+	return desc;
+}
+
 /*
  * The SPI GPIO bindings happened before we managed to establish that GPIO
  * properties should be named "foo-gpios" so we have this special kludge for
@@ -383,7 +425,7 @@ static struct gpio_desc *of_find_spi_gpio(struct device *dev, const char *con_id
 static struct gpio_desc *of_find_spi_cs_gpio(struct device *dev,
 					     const char *con_id,
 					     unsigned int idx,
-					     unsigned long *flags)
+					     enum of_gpio_flags *of_flags)
 {
 	struct device_node *np = dev->of_node;
 
@@ -403,7 +445,7 @@ static struct gpio_desc *of_find_spi_cs_gpio(struct device *dev,
 	 * uses just "gpios" so translate to that when "cs-gpios" is
 	 * requested.
 	 */
-	return of_find_gpio(dev, NULL, idx, flags);
+	return of_find_node_gpio(dev->of_node, NULL, idx, of_flags);
 }
 
 /*
@@ -451,41 +493,18 @@ static struct gpio_desc *of_find_arizona_gpio(struct device *dev,
 	return of_get_named_gpiod_flags(dev->of_node, con_id, 0, of_flags);
 }
 
-struct gpio_desc *of_find_gpio(struct device *dev, const char *con_id,
-			       unsigned int idx, unsigned long *flags)
+struct gpio_desc *of_find_gpio_fallback(struct device *dev,
+					const char *con_id, unsigned int idx,
+					unsigned long *flags)
 {
-	char prop_name[32]; /* 32 is max size of property name */
-	enum of_gpio_flags of_flags;
 	struct gpio_desc *desc;
-	unsigned int i;
-
-	/* Try GPIO property "foo-gpios" and "foo-gpio" */
-	for (i = 0; i < ARRAY_SIZE(gpio_suffixes); i++) {
-		if (con_id)
-			snprintf(prop_name, sizeof(prop_name), "%s-%s", con_id,
-				 gpio_suffixes[i]);
-		else
-			snprintf(prop_name, sizeof(prop_name), "%s",
-				 gpio_suffixes[i]);
-
-		desc = of_get_named_gpiod_flags(dev->of_node, prop_name, idx,
-						&of_flags);
-
-		if (!IS_ERR(desc) || PTR_ERR(desc) != -ENOENT)
-			break;
-	}
+	enum of_gpio_flags of_flags;
 
-	if (IS_ERR(desc) && PTR_ERR(desc) == -ENOENT) {
-		/* Special handling for SPI GPIOs if used */
-		desc = of_find_spi_gpio(dev, con_id, &of_flags);
-	}
+	/* Special handling for SPI GPIOs if used */
+	desc = of_find_spi_gpio(dev, con_id, &of_flags);
 
-	if (IS_ERR(desc) && PTR_ERR(desc) == -ENOENT) {
-		/* This quirk looks up flags and all */
-		desc = of_find_spi_cs_gpio(dev, con_id, idx, flags);
-		if (!IS_ERR(desc))
-			return desc;
-	}
+	if (IS_ERR(desc) && PTR_ERR(desc) == -ENOENT)
+		desc = of_find_spi_cs_gpio(dev, con_id, idx, &of_flags);
 
 	if (IS_ERR(desc) && PTR_ERR(desc) == -ENOENT) {
 		/* Special handling for regulator GPIOs if used */
@@ -495,26 +514,8 @@ struct gpio_desc *of_find_gpio(struct device *dev, const char *con_id,
 	if (IS_ERR(desc) && PTR_ERR(desc) == -ENOENT)
 		desc = of_find_arizona_gpio(dev, con_id, &of_flags);
 
-	if (IS_ERR(desc))
-		return desc;
-
-	if (of_flags & OF_GPIO_ACTIVE_LOW)
-		*flags |= GPIO_ACTIVE_LOW;
-
-	if (of_flags & OF_GPIO_SINGLE_ENDED) {
-		if (of_flags & OF_GPIO_OPEN_DRAIN)
-			*flags |= GPIO_OPEN_DRAIN;
-		else
-			*flags |= GPIO_OPEN_SOURCE;
-	}
-
-	if (of_flags & OF_GPIO_TRANSITORY)
-		*flags |= GPIO_TRANSITORY;
-
-	if (of_flags & OF_GPIO_PULL_UP)
-		*flags |= GPIO_PULL_UP;
-	if (of_flags & OF_GPIO_PULL_DOWN)
-		*flags |= GPIO_PULL_DOWN;
+	if (!IS_ERR(desc))
+		of_gpio_flags_to_lookup(of_flags, flags);
 
 	return desc;
 }
diff --git a/drivers/gpio/gpiolib-of.h b/drivers/gpio/gpiolib-of.h
index 454d1658ee2d..580539cd995f 100644
--- a/drivers/gpio/gpiolib-of.h
+++ b/drivers/gpio/gpiolib-of.h
@@ -3,14 +3,17 @@
 #ifndef GPIOLIB_OF_H
 #define GPIOLIB_OF_H
 
+struct fwnode_handle;
 struct gpio_chip;
 enum of_gpio_flags;
 
 #ifdef CONFIG_OF_GPIO
-struct gpio_desc *of_find_gpio(struct device *dev,
-			       const char *con_id,
-			       unsigned int idx,
-			       unsigned long *lookupflags);
+struct gpio_desc *of_find_gpio(struct fwnode_handle *fwnode,
+			       const char *con_id, unsigned int idx,
+			       unsigned long *flags);
+struct gpio_desc *of_find_gpio_fallback(struct device *dev,
+					const char *con_id, unsigned int idx,
+					unsigned long *flags);
 struct gpio_desc *of_get_named_gpiod_flags(struct device_node *np,
 		   const char *list_name, int index, enum of_gpio_flags *flags);
 int of_gpiochip_add(struct gpio_chip *gc);
@@ -18,10 +21,17 @@ void of_gpiochip_remove(struct gpio_chip *gc);
 int of_gpio_get_count(struct device *dev, const char *con_id);
 bool of_gpio_need_valid_mask(const struct gpio_chip *gc);
 #else
-static inline struct gpio_desc *of_find_gpio(struct device *dev,
-					     const char *con_id,
-					     unsigned int idx,
-					     unsigned long *lookupflags)
+static inline
+struct gpio_desc *of_find_gpio(struct fwnode_handle *fwnode,
+			       const char *con_id, unsigned int idx,
+			       unsigned long *flags)
+{
+	return ERR_PTR(-ENOENT);
+}
+static inline
+struct gpio_desc *of_find_gpio_fallback(struct device *dev,
+					const char *con_id, unsigned int idx,
+					unsigned long *flags)
 {
 	return ERR_PTR(-ENOENT);
 }
diff --git a/drivers/gpio/gpiolib.c b/drivers/gpio/gpiolib.c
index 54db2c42e9a0..1248e61f9a23 100644
--- a/drivers/gpio/gpiolib.c
+++ b/drivers/gpio/gpiolib.c
@@ -4562,7 +4562,12 @@ struct gpio_desc *__must_check gpiod_get_index(struct device *dev,
 		/* Using device tree? */
 		if (IS_ENABLED(CONFIG_OF) && dev->of_node) {
 			dev_dbg(dev, "using device tree for GPIO lookup\n");
-			desc = of_find_gpio(dev, con_id, idx, &lookupflags);
+			desc = of_find_gpio(dev_fwnode(dev),
+					    con_id, idx, &lookupflags);
+			if (desc == ERR_PTR(-ENOENT))
+				desc = of_find_gpio_fallback(dev, con_id, idx,
+							     &lookupflags);
+
 		} else if (ACPI_COMPANION(dev)) {
 			dev_dbg(dev, "using ACPI for GPIO lookup\n");
 			desc = acpi_find_gpio(dev, con_id, idx, &flags, &lookupflags);
-- 
2.23.0.162.g0b9fbb3734-goog


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

* [PATCH 09/11] gpiolib: of: tease apart acpi_find_gpio()
  2019-09-11  7:52 [PATCH 00/11] Add support for software nodes to gpiolib Dmitry Torokhov
                   ` (7 preceding siblings ...)
  2019-09-11  7:52 ` [PATCH 08/11] gpiolib: of: tease apart of_find_gpio() Dmitry Torokhov
@ 2019-09-11  7:52 ` Dmitry Torokhov
  2019-09-11 17:12   ` Andy Shevchenko
  2019-09-11  7:52 ` [PATCH 10/11] gpiolib: consolidate fwnode GPIO lookups Dmitry Torokhov
                   ` (3 subsequent siblings)
  12 siblings, 1 reply; 39+ messages in thread
From: Dmitry Torokhov @ 2019-09-11  7:52 UTC (permalink / raw)
  To: Linus Walleij
  Cc: Andy Shevchenko, Mika Westerberg, linux-kernel, linux-gpio,
	Bartosz Golaszewski, linux-acpi

Tease apart acpi_find_gpio() into common function that works on the
firmware node, and a fallback handler that works on the ACPI device
structure, so that we can later use acpi_find_gpio() in
fwnode_gpiod_get_index().

Signed-off-by: Dmitry Torokhov <dmitry.torokhov@gmail.com>
---

 drivers/gpio/gpiolib-acpi.c | 77 +++++++++++++++++++++++++------------
 drivers/gpio/gpiolib-acpi.h | 17 +++++++-
 drivers/gpio/gpiolib.c      |  8 +++-
 3 files changed, 74 insertions(+), 28 deletions(-)

diff --git a/drivers/gpio/gpiolib-acpi.c b/drivers/gpio/gpiolib-acpi.c
index 2b6fdc9947f7..8174db1bc02e 100644
--- a/drivers/gpio/gpiolib-acpi.c
+++ b/drivers/gpio/gpiolib-acpi.c
@@ -728,29 +728,35 @@ static struct gpio_desc *acpi_get_gpiod_by_index(struct acpi_device *adev,
 	return ret ? ERR_PTR(ret) : lookup.desc;
 }
 
-static bool acpi_can_fallback_to_crs(struct acpi_device *adev,
-				     const char *con_id)
+static int acpi_finalize_gpio_lookup(struct acpi_gpio_info *info,
+				     enum gpiod_flags *dflags,
+				     unsigned long *lookupflags)
 {
-	/* Never allow fallback if the device has properties */
-	if (acpi_dev_has_props(adev) || adev->driver_gpios)
-		return false;
+	if (info->gpioint &&
+	    (*dflags == GPIOD_OUT_LOW || *dflags == GPIOD_OUT_HIGH)) {
+		dev_dbg(&info->adev->dev,
+			"refusing GpioInt() entry when doing GPIOD_OUT_* lookup\n");
+		return -ENOENT;
+	}
 
-	return con_id == NULL;
+	acpi_gpio_update_gpiod_flags(dflags, info);
+	acpi_gpio_update_gpiod_lookup_flags(lookupflags, info);
+
+	return 0;
 }
 
-struct gpio_desc *acpi_find_gpio(struct device *dev,
-				 const char *con_id,
-				 unsigned int idx,
+struct gpio_desc *acpi_find_gpio(struct fwnode_handle *fwnode,
+				 const char *con_id, unsigned int idx,
 				 enum gpiod_flags *dflags,
 				 unsigned long *lookupflags)
 {
-	struct acpi_device *adev = ACPI_COMPANION(dev);
 	struct acpi_gpio_info info;
 	struct gpio_desc *desc;
 	char propname[32];
 	int i;
+	int error;
 
-	/* Try first from _DSD */
+	/* Try GPIOs from _DSD */
 	for (i = 0; i < ARRAY_SIZE(gpio_suffixes); i++) {
 		if (con_id) {
 			snprintf(propname, sizeof(propname), "%s-%s",
@@ -760,31 +766,52 @@ struct gpio_desc *acpi_find_gpio(struct device *dev,
 				 gpio_suffixes[i]);
 		}
 
-		desc = acpi_get_gpiod_by_index(adev, propname, idx, &info);
+		desc = acpi_node_get_gpiod(fwnode, propname, idx, &info);
 		if (!IS_ERR(desc))
 			break;
 		if (PTR_ERR(desc) == -EPROBE_DEFER)
 			return ERR_CAST(desc);
 	}
 
-	/* Then from plain _CRS GPIOs */
-	if (IS_ERR(desc)) {
-		if (!acpi_can_fallback_to_crs(adev, con_id))
-			return ERR_PTR(-ENOENT);
-
-		desc = acpi_get_gpiod_by_index(adev, NULL, idx, &info);
-		if (IS_ERR(desc))
-			return desc;
+	if (!IS_ERR(desc)) {
+		error = acpi_finalize_gpio_lookup(&info, dflags, lookupflags);
+		if (error)
+			return ERR_PTR(error);
 	}
 
-	if (info.gpioint &&
-	    (*dflags == GPIOD_OUT_LOW || *dflags == GPIOD_OUT_HIGH)) {
-		dev_dbg(dev, "refusing GpioInt() entry when doing GPIOD_OUT_* lookup\n");
+	return desc;
+}
+
+static bool acpi_can_fallback_to_crs(struct acpi_device *adev,
+				     const char *con_id)
+{
+	/* Never allow fallback if the device has properties */
+	if (acpi_dev_has_props(adev) || adev->driver_gpios)
+		return false;
+
+	return con_id == NULL;
+}
+
+struct gpio_desc *acpi_find_gpio_fallback(struct acpi_device *adev,
+					  const char *con_id, unsigned int idx,
+					  enum gpiod_flags *dflags,
+					  unsigned long *lookupflags)
+{
+	struct acpi_gpio_info info;
+	struct gpio_desc *desc;
+	int error;
+
+	/* Then from plain _CRS GPIOs */
+	if (!acpi_can_fallback_to_crs(adev, con_id))
 		return ERR_PTR(-ENOENT);
+
+	desc = acpi_get_gpiod_by_index(adev, NULL, idx, &info);
+	if (!IS_ERR(desc)) {
+		error = acpi_finalize_gpio_lookup(&info, dflags, lookupflags);
+		if (error)
+			return ERR_PTR(error);
 	}
 
-	acpi_gpio_update_gpiod_flags(dflags, &info);
-	acpi_gpio_update_gpiod_lookup_flags(lookupflags, &info);
 	return desc;
 }
 
diff --git a/drivers/gpio/gpiolib-acpi.h b/drivers/gpio/gpiolib-acpi.h
index 1c6d65cf0629..ea97a3822116 100644
--- a/drivers/gpio/gpiolib-acpi.h
+++ b/drivers/gpio/gpiolib-acpi.h
@@ -9,6 +9,7 @@
 #define GPIOLIB_ACPI_H
 
 struct acpi_device;
+struct fwnode_handle;
 
 /**
  * struct acpi_gpio_info - ACPI GPIO specific information
@@ -42,11 +43,16 @@ int acpi_gpio_update_gpiod_flags(enum gpiod_flags *flags,
 int acpi_gpio_update_gpiod_lookup_flags(unsigned long *lookupflags,
 					struct acpi_gpio_info *info);
 
-struct gpio_desc *acpi_find_gpio(struct device *dev,
+struct gpio_desc *acpi_find_gpio(struct fwnode_handle *fwnode,
 				 const char *con_id,
 				 unsigned int idx,
 				 enum gpiod_flags *dflags,
 				 unsigned long *lookupflags);
+struct gpio_desc *acpi_find_gpio_fallback(struct acpi_device *adev,
+					  const char *con_id,
+					  unsigned int idx,
+					  enum gpiod_flags *dflags,
+					  unsigned long *lookupflags);
 struct gpio_desc *acpi_node_get_gpiod(struct fwnode_handle *fwnode,
 				      const char *propname, int index,
 				      struct acpi_gpio_info *info);
@@ -75,13 +81,20 @@ acpi_gpio_update_gpiod_lookup_flags(unsigned long *lookupflags,
 }
 
 static inline struct gpio_desc *
-acpi_find_gpio(struct device *dev, const char *con_id,
+acpi_find_gpio(struct firmware_node *fwnode, const char *con_id,
 	       unsigned int idx, enum gpiod_flags *dflags,
 	       unsigned long *lookupflags)
 {
 	return ERR_PTR(-ENOENT);
 }
 static inline struct gpio_desc *
+acpi_find_gpio_fallback(struct acpi_device *adev, const char *con_id,
+			unsigned int idx, enum gpiod_flags *dflags,
+			unsigned long *lookupflags)
+{
+	return ERR_PTR(-ENOENT);
+}
+static inline struct gpio_desc *
 acpi_node_get_gpiod(struct fwnode_handle *fwnode, const char *propname,
 		    int index, struct acpi_gpio_info *info)
 {
diff --git a/drivers/gpio/gpiolib.c b/drivers/gpio/gpiolib.c
index 1248e61f9a23..2d8dd67ab03d 100644
--- a/drivers/gpio/gpiolib.c
+++ b/drivers/gpio/gpiolib.c
@@ -4570,7 +4570,13 @@ struct gpio_desc *__must_check gpiod_get_index(struct device *dev,
 
 		} else if (ACPI_COMPANION(dev)) {
 			dev_dbg(dev, "using ACPI for GPIO lookup\n");
-			desc = acpi_find_gpio(dev, con_id, idx, &flags, &lookupflags);
+			desc = acpi_find_gpio(dev_fwnode(dev), con_id, idx,
+					      &flags, &lookupflags);
+			if (desc == ERR_PTR(-ENOENT))
+				desc = acpi_find_gpio_fallback(
+						ACPI_COMPANION(dev),
+						con_id, idx,
+						&flags, &lookupflags);
 		}
 	}
 
-- 
2.23.0.162.g0b9fbb3734-goog


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

* [PATCH 10/11] gpiolib: consolidate fwnode GPIO lookups
  2019-09-11  7:52 [PATCH 00/11] Add support for software nodes to gpiolib Dmitry Torokhov
                   ` (8 preceding siblings ...)
  2019-09-11  7:52 ` [PATCH 09/11] gpiolib: of: tease apart acpi_find_gpio() Dmitry Torokhov
@ 2019-09-11  7:52 ` Dmitry Torokhov
  2019-09-11  7:52 ` [PATCH 11/11] gpiolib: add support for software nodes Dmitry Torokhov
                   ` (2 subsequent siblings)
  12 siblings, 0 replies; 39+ messages in thread
From: Dmitry Torokhov @ 2019-09-11  7:52 UTC (permalink / raw)
  To: Linus Walleij
  Cc: Andy Shevchenko, Mika Westerberg, linux-kernel, linux-gpio,
	Bartosz Golaszewski, linux-acpi

Ensure that all paths to obtain/look up GPIOD from generic
consumer-visible APIs go through the new fwnode_locate_gpiod(), so that
we can easily extend the support for new firmware mechanisms.

Signed-off-by: Dmitry Torokhov <dmitry.torokhov@gmail.com>
---

 drivers/gpio/gpiolib-acpi.c |  88 +++++++++++++++----------------
 drivers/gpio/gpiolib-acpi.h |  10 ----
 drivers/gpio/gpiolib.c      | 100 ++++++++++++------------------------
 3 files changed, 77 insertions(+), 121 deletions(-)

diff --git a/drivers/gpio/gpiolib-acpi.c b/drivers/gpio/gpiolib-acpi.c
index 8174db1bc02e..13907add5027 100644
--- a/drivers/gpio/gpiolib-acpi.c
+++ b/drivers/gpio/gpiolib-acpi.c
@@ -728,6 +728,50 @@ static struct gpio_desc *acpi_get_gpiod_by_index(struct acpi_device *adev,
 	return ret ? ERR_PTR(ret) : lookup.desc;
 }
 
+/**
+ * acpi_node_get_gpiod() - get a GPIO descriptor from ACPI resources
+ * @fwnode: pointer to an ACPI firmware node to get the GPIO information from
+ * @propname: Property name of the GPIO
+ * @index: index of GpioIo/GpioInt resource (starting from %0)
+ * @info: info pointer to fill in (optional)
+ *
+ * If @fwnode is an ACPI device object, call acpi_get_gpiod_by_index() for it.
+ * Otherwise (i.e. it is a data-only non-device object), use the property-based
+ * GPIO lookup to get to the GPIO resource with the relevant information and use
+ * that to obtain the GPIO descriptor to return.
+ *
+ * If the GPIO cannot be translated or there is an error an ERR_PTR is
+ * returned.
+ */
+static struct gpio_desc *acpi_node_get_gpiod(struct fwnode_handle *fwnode,
+					     const char *propname, int index,
+					     struct acpi_gpio_info *info)
+{
+	struct acpi_gpio_lookup lookup;
+	struct acpi_device *adev;
+	int ret;
+
+	adev = to_acpi_device_node(fwnode);
+	if (adev)
+		return acpi_get_gpiod_by_index(adev, propname, index, info);
+
+	if (!is_acpi_data_node(fwnode))
+		return ERR_PTR(-ENODEV);
+
+	if (!propname)
+		return ERR_PTR(-EINVAL);
+
+	memset(&lookup, 0, sizeof(lookup));
+	lookup.index = index;
+
+	ret = acpi_gpio_property_lookup(fwnode, propname, index, &lookup);
+	if (ret)
+		return ERR_PTR(ret);
+
+	ret = acpi_gpio_resource_lookup(&lookup, info);
+	return ret ? ERR_PTR(ret) : lookup.desc;
+}
+
 static int acpi_finalize_gpio_lookup(struct acpi_gpio_info *info,
 				     enum gpiod_flags *dflags,
 				     unsigned long *lookupflags)
@@ -815,50 +859,6 @@ struct gpio_desc *acpi_find_gpio_fallback(struct acpi_device *adev,
 	return desc;
 }
 
-/**
- * acpi_node_get_gpiod() - get a GPIO descriptor from ACPI resources
- * @fwnode: pointer to an ACPI firmware node to get the GPIO information from
- * @propname: Property name of the GPIO
- * @index: index of GpioIo/GpioInt resource (starting from %0)
- * @info: info pointer to fill in (optional)
- *
- * If @fwnode is an ACPI device object, call acpi_get_gpiod_by_index() for it.
- * Otherwise (i.e. it is a data-only non-device object), use the property-based
- * GPIO lookup to get to the GPIO resource with the relevant information and use
- * that to obtain the GPIO descriptor to return.
- *
- * If the GPIO cannot be translated or there is an error an ERR_PTR is
- * returned.
- */
-struct gpio_desc *acpi_node_get_gpiod(struct fwnode_handle *fwnode,
-				      const char *propname, int index,
-				      struct acpi_gpio_info *info)
-{
-	struct acpi_gpio_lookup lookup;
-	struct acpi_device *adev;
-	int ret;
-
-	adev = to_acpi_device_node(fwnode);
-	if (adev)
-		return acpi_get_gpiod_by_index(adev, propname, index, info);
-
-	if (!is_acpi_data_node(fwnode))
-		return ERR_PTR(-ENODEV);
-
-	if (!propname)
-		return ERR_PTR(-EINVAL);
-
-	memset(&lookup, 0, sizeof(lookup));
-	lookup.index = index;
-
-	ret = acpi_gpio_property_lookup(fwnode, propname, index, &lookup);
-	if (ret)
-		return ERR_PTR(ret);
-
-	ret = acpi_gpio_resource_lookup(&lookup, info);
-	return ret ? ERR_PTR(ret) : lookup.desc;
-}
-
 /**
  * acpi_dev_gpio_irq_get() - Find GpioInt and translate it to Linux IRQ number
  * @adev: pointer to a ACPI device to get IRQ from
diff --git a/drivers/gpio/gpiolib-acpi.h b/drivers/gpio/gpiolib-acpi.h
index ea97a3822116..047df1d5c7fa 100644
--- a/drivers/gpio/gpiolib-acpi.h
+++ b/drivers/gpio/gpiolib-acpi.h
@@ -53,10 +53,6 @@ struct gpio_desc *acpi_find_gpio_fallback(struct acpi_device *adev,
 					  unsigned int idx,
 					  enum gpiod_flags *dflags,
 					  unsigned long *lookupflags);
-struct gpio_desc *acpi_node_get_gpiod(struct fwnode_handle *fwnode,
-				      const char *propname, int index,
-				      struct acpi_gpio_info *info);
-
 int acpi_gpio_count(struct device *dev, const char *con_id);
 #else
 static inline void acpi_gpiochip_add(struct gpio_chip *chip) { }
@@ -94,12 +90,6 @@ acpi_find_gpio_fallback(struct acpi_device *adev, const char *con_id,
 {
 	return ERR_PTR(-ENOENT);
 }
-static inline struct gpio_desc *
-acpi_node_get_gpiod(struct fwnode_handle *fwnode, const char *propname,
-		    int index, struct acpi_gpio_info *info)
-{
-	return ERR_PTR(-ENXIO);
-}
 static inline int acpi_gpio_count(struct device *dev, const char *con_id)
 {
 	return -ENODEV;
diff --git a/drivers/gpio/gpiolib.c b/drivers/gpio/gpiolib.c
index 2d8dd67ab03d..6534dcd6e406 100644
--- a/drivers/gpio/gpiolib.c
+++ b/drivers/gpio/gpiolib.c
@@ -4314,44 +4314,27 @@ static int platform_gpio_count(struct device *dev, const char *con_id)
 	return count;
 }
 
-static struct gpio_desc *fwnode_get_named_gpiod(struct fwnode_handle *fwnode,
-						const char *propname, int index,
-						enum gpiod_flags dflags,
-						const char *label)
+static struct gpio_desc *fwnode_locate_gpiod(struct fwnode_handle *fwnode,
+					     struct device *dev,
+					     const char *con_id, int idx,
+					     enum gpiod_flags *flags,
+					     unsigned long *lookupflags)
 {
-	unsigned long lflags = GPIO_LOOKUP_FLAGS_DEFAULT;
 	struct gpio_desc *desc = ERR_PTR(-ENODEV);
-	int ret;
-
-	if (!fwnode)
-		return ERR_PTR(-EINVAL);
 
 	if (is_of_node(fwnode)) {
-		desc = gpiod_get_from_of_node(to_of_node(fwnode),
-					      propname, index,
-					      dflags,
-					      label);
-		return desc;
+		dev_dbg(dev, "using device tree for GPIO lookup\n");
+		desc = of_find_gpio(fwnode, con_id, idx, lookupflags);
+		if (desc == ERR_PTR(-ENOENT) && dev)
+			desc = of_find_gpio_fallback(dev, con_id, idx,
+						     lookupflags);
 	} else if (is_acpi_node(fwnode)) {
-		struct acpi_gpio_info info;
-
-		desc = acpi_node_get_gpiod(fwnode, propname, index, &info);
-		if (IS_ERR(desc))
-			return desc;
-
-		acpi_gpio_update_gpiod_flags(&dflags, &info);
-		acpi_gpio_update_gpiod_lookup_flags(&lflags, &info);
-	}
-
-	/* Currently only ACPI takes this path */
-	ret = gpiod_request(desc, label);
-	if (ret)
-		return ERR_PTR(ret);
-
-	ret = gpiod_configure_flags(desc, propname, lflags, dflags);
-	if (ret < 0) {
-		gpiod_put(desc);
-		return ERR_PTR(ret);
+		dev_dbg(dev, "using ACPI for GPIO lookup\n");
+		desc = acpi_find_gpio(fwnode, con_id, idx, flags, lookupflags);
+		if (desc == ERR_PTR(-ENOENT) && dev)
+			desc = acpi_find_gpio_fallback(ACPI_COMPANION(dev),
+						       con_id, idx,
+						       flags, lookupflags);
 	}
 
 	return desc;
@@ -4383,22 +4366,23 @@ struct gpio_desc *fwnode_gpiod_get_index(struct fwnode_handle *fwnode,
 					 enum gpiod_flags flags,
 					 const char *label)
 {
+	unsigned long lookupflags = GPIO_LOOKUP_FLAGS_DEFAULT;
 	struct gpio_desc *desc;
-	char prop_name[32]; /* 32 is max size of property name */
-	unsigned int i;
+	int error;
 
-	for (i = 0; i < ARRAY_SIZE(gpio_suffixes); i++) {
-		if (con_id)
-			snprintf(prop_name, sizeof(prop_name), "%s-%s",
-					    con_id, gpio_suffixes[i]);
-		else
-			snprintf(prop_name, sizeof(prop_name), "%s",
-					    gpio_suffixes[i]);
+	desc = fwnode_locate_gpiod(fwnode, NULL, con_id, index,
+				   &flags, &lookupflags);
+	if (IS_ERR(desc))
+		return desc;
 
-		desc = fwnode_get_named_gpiod(fwnode, prop_name, index, flags,
-					      label);
-		if (!IS_ERR(desc) || (PTR_ERR(desc) != -ENOENT))
-			break;
+	error = gpiod_request(desc, label);
+	if (error)
+		return ERR_PTR(error);
+
+	error = gpiod_configure_flags(desc, con_id, lookupflags, flags);
+	if (error < 0) {
+		gpiod_put(desc);
+		return ERR_PTR(error);
 	}
 
 	return desc;
@@ -4558,27 +4542,9 @@ struct gpio_desc *__must_check gpiod_get_index(struct device *dev,
 
 	dev_dbg(dev, "GPIO lookup for consumer %s\n", con_id);
 
-	if (dev) {
-		/* Using device tree? */
-		if (IS_ENABLED(CONFIG_OF) && dev->of_node) {
-			dev_dbg(dev, "using device tree for GPIO lookup\n");
-			desc = of_find_gpio(dev_fwnode(dev),
-					    con_id, idx, &lookupflags);
-			if (desc == ERR_PTR(-ENOENT))
-				desc = of_find_gpio_fallback(dev, con_id, idx,
-							     &lookupflags);
-
-		} else if (ACPI_COMPANION(dev)) {
-			dev_dbg(dev, "using ACPI for GPIO lookup\n");
-			desc = acpi_find_gpio(dev_fwnode(dev), con_id, idx,
-					      &flags, &lookupflags);
-			if (desc == ERR_PTR(-ENOENT))
-				desc = acpi_find_gpio_fallback(
-						ACPI_COMPANION(dev),
-						con_id, idx,
-						&flags, &lookupflags);
-		}
-	}
+	if (dev)
+		desc = fwnode_locate_gpiod(dev_fwnode(dev), dev, con_id, idx,
+					   &flags, &lookupflags);
 
 	/*
 	 * Either we are not using DT or ACPI, or their lookup did not return
-- 
2.23.0.162.g0b9fbb3734-goog


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

* [PATCH 11/11] gpiolib: add support for software nodes
  2019-09-11  7:52 [PATCH 00/11] Add support for software nodes to gpiolib Dmitry Torokhov
                   ` (9 preceding siblings ...)
  2019-09-11  7:52 ` [PATCH 10/11] gpiolib: consolidate fwnode GPIO lookups Dmitry Torokhov
@ 2019-09-11  7:52 ` Dmitry Torokhov
  2019-09-11 17:13 ` [PATCH 00/11] Add support for software nodes to gpiolib Andy Shevchenko
  2019-09-12  9:55 ` Linus Walleij
  12 siblings, 0 replies; 39+ messages in thread
From: Dmitry Torokhov @ 2019-09-11  7:52 UTC (permalink / raw)
  To: Linus Walleij
  Cc: Andy Shevchenko, Mika Westerberg, linux-kernel, linux-gpio,
	Bartosz Golaszewski

Now that static device properties understand notion of child nodes and
references, let's teach gpiolib to handle them:

- GPIOs are represented as a references to software nodes representing
  gpiochip
- references must have 2 arguments - GPIO number within the chip and
  GPIO flags (GPIO_ACTIVE_LOW/GPIO_ACTIVE_HIGH, etc).
- name of the software node representing gpiochip must match label of
  the gpiochip, as we use it to locate gpiochip structure at runtime.

const struct software_node gpio_bank_b_node = {
	.name = "B",
};

const struct property_entry simone_key_enter_props[] __initconst = {
	PROPERTY_ENTRY_U32("linux,code", KEY_ENTER),
	PROPERTY_ENTRY_STRING("label", "enter"),
	PROPERTY_ENTRY_REF("gpios", &gpio_bank_b_node, 123, GPIO_ACTIVE_LOW),
	{ }
};

Signed-off-by: Dmitry Torokhov <dmitry.torokhov@gmail.com>

---

 drivers/gpio/Makefile         |  1 +
 drivers/gpio/gpiolib-swnode.c | 92 +++++++++++++++++++++++++++++++++++
 drivers/gpio/gpiolib-swnode.h | 13 +++++
 drivers/gpio/gpiolib.c        | 31 ++++++++++--
 4 files changed, 133 insertions(+), 4 deletions(-)
 create mode 100644 drivers/gpio/gpiolib-swnode.c
 create mode 100644 drivers/gpio/gpiolib-swnode.h

diff --git a/drivers/gpio/Makefile b/drivers/gpio/Makefile
index d2fd19c15bae..41869ba725e2 100644
--- a/drivers/gpio/Makefile
+++ b/drivers/gpio/Makefile
@@ -7,6 +7,7 @@ obj-$(CONFIG_GPIOLIB)		+= gpiolib.o
 obj-$(CONFIG_GPIOLIB)		+= gpiolib-devres.o
 obj-$(CONFIG_GPIOLIB)		+= gpiolib-legacy.o
 obj-$(CONFIG_GPIOLIB)		+= gpiolib-devprop.o
+obj-$(CONFIG_GPIOLIB)		+= gpiolib-swnode.o
 obj-$(CONFIG_OF_GPIO)		+= gpiolib-of.o
 obj-$(CONFIG_GPIO_SYSFS)	+= gpiolib-sysfs.o
 obj-$(CONFIG_GPIO_ACPI)		+= gpiolib-acpi.o
diff --git a/drivers/gpio/gpiolib-swnode.c b/drivers/gpio/gpiolib-swnode.c
new file mode 100644
index 000000000000..a20d73cc9a3f
--- /dev/null
+++ b/drivers/gpio/gpiolib-swnode.c
@@ -0,0 +1,92 @@
+// SPDX-License-Identifier: GPL-2.0+
+/*
+ * Software Node helpers for the GPIO API
+ *
+ * Copyright 2019 Google LLC
+ */
+#include <linux/err.h>
+#include <linux/errno.h>
+#include <linux/gpio/consumer.h>
+
+#include "gpiolib.h"
+#include "gpiolib-swnode.h"
+
+static int swnode_gpiochip_match_name(struct gpio_chip *chip, void *data)
+{
+	return !strcmp(chip->label, data);
+}
+
+struct gpio_desc *swnode_find_gpio(struct fwnode_handle *fwnode,
+				   const char *con_id, unsigned int idx,
+				   unsigned long *flags)
+{
+	const struct software_node *chip_node;
+	const struct software_node *swnode;
+	struct fwnode_reference_args args;
+	struct gpio_chip *chip;
+	char prop_name[32]; /* 32 is max size of property name */
+	int error;
+
+	swnode = to_software_node(fwnode);
+	if (!swnode)
+		return ERR_PTR(-EINVAL);
+
+	/*
+	 * Note we do not need to try both -gpios and -gpio suffixes,
+	 * as, unlike OF and ACPI, we can fix software nodes to conform
+	 * to the proper binding.
+	 */
+	if (con_id)
+		snprintf(prop_name, sizeof(prop_name), "%s-gpios", con_id);
+	else
+		stracpy(prop_name, "gpios");
+
+	/*
+	 * We expect all swnode-described GPIOs have GPIO number and
+	 * polarity arguments, hence nargs is set to 2.
+	 */
+	error = fwnode_property_get_reference_args(fwnode, prop_name, NULL,
+						   2, idx, &args);
+	if (error) {
+		pr_debug("%s: can't parse '%s' property of node '%s[%d]'\n",
+			__func__, prop_name, swnode->name ?: "unnamed", idx);
+		return ERR_PTR(error);
+	}
+
+	chip_node = to_software_node(args.fwnode);
+	if (!chip_node || !chip_node->name)
+		return ERR_PTR(-EINVAL);
+
+	chip = gpiochip_find((void *)chip_node->name,
+			     swnode_gpiochip_match_name);
+	if (!chip)
+		return ERR_PTR(-EPROBE_DEFER);
+
+	/* We expect native GPIO flags */
+	*flags = args.args[1];
+
+	return gpiochip_get_desc(chip, args.args[0]);
+}
+
+int swnode_gpio_count(struct fwnode_handle *fwnode, const char *con_id)
+{
+	struct fwnode_reference_args args;
+	char prop_name[32];
+	int count;
+
+	if (con_id)
+		snprintf(prop_name, sizeof(prop_name), "%s-gpios", con_id);
+	else
+		stracpy(prop_name, "gpios");
+
+	/*
+	 * This is not very efficient, but GPIO lists usually have only
+	 * 1 or 2 entries.
+	 */
+	count = 0;
+	while (fwnode_property_get_reference_args(fwnode, prop_name, NULL,
+						  0, count, &args) == 0)
+		count++;
+
+	return count ? count : -ENOENT;
+}
diff --git a/drivers/gpio/gpiolib-swnode.h b/drivers/gpio/gpiolib-swnode.h
new file mode 100644
index 000000000000..afd51c9b6e34
--- /dev/null
+++ b/drivers/gpio/gpiolib-swnode.h
@@ -0,0 +1,13 @@
+/* SPDX-License-Identifier: GPL-2.0 */
+
+#ifndef GPIOLIB_SWNODE_H
+#define GPIOLIB_SWNODE_H
+
+struct fwnode_handle;
+
+struct gpio_desc *swnode_find_gpio(struct fwnode_handle *fwnode,
+				   const char *con_id, unsigned int idx,
+				   unsigned long *flags);
+int swnode_gpio_count(struct fwnode_handle *fwnode, const char *con_id);
+
+#endif /* GPIOLIB_SWNODE_H */
diff --git a/drivers/gpio/gpiolib.c b/drivers/gpio/gpiolib.c
index 6534dcd6e406..0f41b4b9b8ba 100644
--- a/drivers/gpio/gpiolib.c
+++ b/drivers/gpio/gpiolib.c
@@ -31,6 +31,7 @@
 #include "gpiolib.h"
 #include "gpiolib-of.h"
 #include "gpiolib-acpi.h"
+#include "gpiolib-swnode.h"
 
 #define CREATE_TRACE_POINTS
 #include <trace/events/gpio.h>
@@ -4335,6 +4336,16 @@ static struct gpio_desc *fwnode_locate_gpiod(struct fwnode_handle *fwnode,
 			desc = acpi_find_gpio_fallback(ACPI_COMPANION(dev),
 						       con_id, idx,
 						       flags, lookupflags);
+	} else if (is_software_node(fwnode)) {
+		dev_dbg(dev, "using software node for GPIO lookup\n");
+		desc = swnode_find_gpio(fwnode, con_id, idx, lookupflags);
+	}
+
+	if (IS_ERR(desc) &&
+	    !IS_ERR_OR_NULL(fwnode) &&
+	    is_software_node(fwnode->secondary)) {
+		desc = swnode_find_gpio(fwnode->secondary,
+					con_id, idx, lookupflags);
 	}
 
 	return desc;
@@ -4397,12 +4408,24 @@ EXPORT_SYMBOL_GPL(fwnode_gpiod_get_index);
  */
 int gpiod_count(struct device *dev, const char *con_id)
 {
+	struct fwnode_handle *fwnode;
 	int count = -ENOENT;
 
-	if (IS_ENABLED(CONFIG_OF) && dev && dev->of_node)
-		count = of_gpio_get_count(dev, con_id);
-	else if (IS_ENABLED(CONFIG_ACPI) && dev && ACPI_HANDLE(dev))
-		count = acpi_gpio_count(dev, con_id);
+	if (dev) {
+		fwnode = dev_fwnode(dev);
+		if (is_of_node(fwnode))
+			count = of_gpio_get_count(dev, con_id);
+		else if (is_acpi_device_node(fwnode))
+			count = acpi_gpio_count(dev, con_id);
+		else if (is_software_node(fwnode))
+			count = swnode_gpio_count(fwnode, con_id);
+
+		if (count < 0 &&
+		    !IS_ERR_OR_NULL(fwnode) &&
+		    is_software_node(fwnode->secondary)) {
+			count = swnode_gpio_count(fwnode, con_id);
+		}
+	}
 
 	if (count < 0)
 		count = platform_gpio_count(dev, con_id);
-- 
2.23.0.162.g0b9fbb3734-goog


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

* Re: [PATCH 04/11] net: phylink: switch to using fwnode_gpiod_get_index()
  2019-09-11  7:52 ` [PATCH 04/11] net: phylink: switch to using fwnode_gpiod_get_index() Dmitry Torokhov
@ 2019-09-11  9:25   ` Andy Shevchenko
  2019-09-11  9:39     ` Russell King - ARM Linux admin
  0 siblings, 1 reply; 39+ messages in thread
From: Andy Shevchenko @ 2019-09-11  9:25 UTC (permalink / raw)
  To: Dmitry Torokhov
  Cc: Linus Walleij, Mika Westerberg, linux-kernel, linux-gpio,
	Andrew Lunn, David S. Miller, Florian Fainelli, Heiner Kallweit,
	Russell King, netdev

On Wed, Sep 11, 2019 at 12:52:08AM -0700, Dmitry Torokhov wrote:
> Instead of fwnode_get_named_gpiod() that I plan to hide away, let's use
> the new fwnode_gpiod_get_index() that mimics gpiod_get_index(), bit
> works with arbitrary firmware node.

I'm wondering if it's possible to step forward and replace
fwnode_get_gpiod_index by gpiod_get() / gpiod_get_index() here and
in other cases in this series.

-- 
With Best Regards,
Andy Shevchenko



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

* Re: [PATCH 04/11] net: phylink: switch to using fwnode_gpiod_get_index()
  2019-09-11  9:25   ` Andy Shevchenko
@ 2019-09-11  9:39     ` Russell King - ARM Linux admin
  2019-09-11  9:46       ` Andy Shevchenko
  0 siblings, 1 reply; 39+ messages in thread
From: Russell King - ARM Linux admin @ 2019-09-11  9:39 UTC (permalink / raw)
  To: Andy Shevchenko
  Cc: Dmitry Torokhov, Linus Walleij, Mika Westerberg, linux-kernel,
	linux-gpio, Andrew Lunn, David S. Miller, Florian Fainelli,
	Heiner Kallweit, netdev

On Wed, Sep 11, 2019 at 12:25:14PM +0300, Andy Shevchenko wrote:
> On Wed, Sep 11, 2019 at 12:52:08AM -0700, Dmitry Torokhov wrote:
> > Instead of fwnode_get_named_gpiod() that I plan to hide away, let's use
> > the new fwnode_gpiod_get_index() that mimics gpiod_get_index(), bit
> > works with arbitrary firmware node.
> 
> I'm wondering if it's possible to step forward and replace
> fwnode_get_gpiod_index by gpiod_get() / gpiod_get_index() here and
> in other cases in this series.

No, those require a struct device, but we have none.  There are network
drivers where there is a struct device for the network complex, but only
DT nodes for the individual network interfaces.  So no, gpiod_* really
doesn't work.

-- 
RMK's Patch system: https://www.armlinux.org.uk/developer/patches/
FTTC broadband for 0.8mile line in suburbia: sync at 12.1Mbps down 622kbps up
According to speedtest.net: 11.9Mbps down 500kbps up

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

* Re: [PATCH 04/11] net: phylink: switch to using fwnode_gpiod_get_index()
  2019-09-11  9:39     ` Russell King - ARM Linux admin
@ 2019-09-11  9:46       ` Andy Shevchenko
  2019-09-11  9:49         ` Russell King - ARM Linux admin
  2019-09-11  9:51         ` Dmitry Torokhov
  0 siblings, 2 replies; 39+ messages in thread
From: Andy Shevchenko @ 2019-09-11  9:46 UTC (permalink / raw)
  To: Russell King - ARM Linux admin
  Cc: Dmitry Torokhov, Linus Walleij, Mika Westerberg, linux-kernel,
	linux-gpio, Andrew Lunn, David S. Miller, Florian Fainelli,
	Heiner Kallweit, netdev

On Wed, Sep 11, 2019 at 10:39:14AM +0100, Russell King - ARM Linux admin wrote:
> On Wed, Sep 11, 2019 at 12:25:14PM +0300, Andy Shevchenko wrote:
> > On Wed, Sep 11, 2019 at 12:52:08AM -0700, Dmitry Torokhov wrote:
> > > Instead of fwnode_get_named_gpiod() that I plan to hide away, let's use
> > > the new fwnode_gpiod_get_index() that mimics gpiod_get_index(), bit
> > > works with arbitrary firmware node.
> > 
> > I'm wondering if it's possible to step forward and replace
> > fwnode_get_gpiod_index by gpiod_get() / gpiod_get_index() here and
> > in other cases in this series.
> 
> No, those require a struct device, but we have none.  There are network
> drivers where there is a struct device for the network complex, but only
> DT nodes for the individual network interfaces.  So no, gpiod_* really
> doesn't work.

In the following patch the node is derived from struct device. So, I believe
some cases can be handled differently.

-- 
With Best Regards,
Andy Shevchenko



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

* Re: [PATCH 04/11] net: phylink: switch to using fwnode_gpiod_get_index()
  2019-09-11  9:46       ` Andy Shevchenko
@ 2019-09-11  9:49         ` Russell King - ARM Linux admin
  2019-09-11  9:55           ` Dmitry Torokhov
  2019-09-11  9:51         ` Dmitry Torokhov
  1 sibling, 1 reply; 39+ messages in thread
From: Russell King - ARM Linux admin @ 2019-09-11  9:49 UTC (permalink / raw)
  To: Andy Shevchenko
  Cc: Dmitry Torokhov, Linus Walleij, Mika Westerberg, linux-kernel,
	linux-gpio, Andrew Lunn, David S. Miller, Florian Fainelli,
	Heiner Kallweit, netdev

On Wed, Sep 11, 2019 at 12:46:19PM +0300, Andy Shevchenko wrote:
> On Wed, Sep 11, 2019 at 10:39:14AM +0100, Russell King - ARM Linux admin wrote:
> > On Wed, Sep 11, 2019 at 12:25:14PM +0300, Andy Shevchenko wrote:
> > > On Wed, Sep 11, 2019 at 12:52:08AM -0700, Dmitry Torokhov wrote:
> > > > Instead of fwnode_get_named_gpiod() that I plan to hide away, let's use
> > > > the new fwnode_gpiod_get_index() that mimics gpiod_get_index(), bit
> > > > works with arbitrary firmware node.
> > > 
> > > I'm wondering if it's possible to step forward and replace
> > > fwnode_get_gpiod_index by gpiod_get() / gpiod_get_index() here and
> > > in other cases in this series.
> > 
> > No, those require a struct device, but we have none.  There are network
> > drivers where there is a struct device for the network complex, but only
> > DT nodes for the individual network interfaces.  So no, gpiod_* really
> > doesn't work.
> 
> In the following patch the node is derived from struct device. So, I believe
> some cases can be handled differently.

phylink is not passed a struct device - it has no knowledge what the
parent device is.

In any case, I do not have "the following patch".

-- 
RMK's Patch system: https://www.armlinux.org.uk/developer/patches/
FTTC broadband for 0.8mile line in suburbia: sync at 12.1Mbps down 622kbps up
According to speedtest.net: 11.9Mbps down 500kbps up

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

* Re: [PATCH 04/11] net: phylink: switch to using fwnode_gpiod_get_index()
  2019-09-11  9:46       ` Andy Shevchenko
  2019-09-11  9:49         ` Russell King - ARM Linux admin
@ 2019-09-11  9:51         ` Dmitry Torokhov
  2019-09-12  9:41           ` Linus Walleij
  1 sibling, 1 reply; 39+ messages in thread
From: Dmitry Torokhov @ 2019-09-11  9:51 UTC (permalink / raw)
  To: Andy Shevchenko
  Cc: Russell King - ARM Linux admin, Linus Walleij, Mika Westerberg,
	linux-kernel, linux-gpio, Andrew Lunn, David S. Miller,
	Florian Fainelli, Heiner Kallweit, netdev

On Wed, Sep 11, 2019 at 12:46:19PM +0300, Andy Shevchenko wrote:
> On Wed, Sep 11, 2019 at 10:39:14AM +0100, Russell King - ARM Linux admin wrote:
> > On Wed, Sep 11, 2019 at 12:25:14PM +0300, Andy Shevchenko wrote:
> > > On Wed, Sep 11, 2019 at 12:52:08AM -0700, Dmitry Torokhov wrote:
> > > > Instead of fwnode_get_named_gpiod() that I plan to hide away, let's use
> > > > the new fwnode_gpiod_get_index() that mimics gpiod_get_index(), bit
> > > > works with arbitrary firmware node.
> > > 
> > > I'm wondering if it's possible to step forward and replace
> > > fwnode_get_gpiod_index by gpiod_get() / gpiod_get_index() here and
> > > in other cases in this series.
> > 
> > No, those require a struct device, but we have none.  There are network
> > drivers where there is a struct device for the network complex, but only
> > DT nodes for the individual network interfaces.  So no, gpiod_* really
> > doesn't work.
> 
> In the following patch the node is derived from struct device. So, I believe
> some cases can be handled differently.

If we are willing to sacrifice the custom label for the GPIO that
fwnode_gpiod_get_index() allows us to set, then there are several
drivers that could actually use gpiod_get() API.

This is up to the dirver's maintainers...

Thanks.

-- 
Dmitry

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

* Re: [PATCH 04/11] net: phylink: switch to using fwnode_gpiod_get_index()
  2019-09-11  9:49         ` Russell King - ARM Linux admin
@ 2019-09-11  9:55           ` Dmitry Torokhov
  2019-09-11 10:10             ` Russell King - ARM Linux admin
  0 siblings, 1 reply; 39+ messages in thread
From: Dmitry Torokhov @ 2019-09-11  9:55 UTC (permalink / raw)
  To: Russell King - ARM Linux admin
  Cc: Andy Shevchenko, Linus Walleij, Mika Westerberg, linux-kernel,
	linux-gpio, Andrew Lunn, David S. Miller, Florian Fainelli,
	Heiner Kallweit, netdev

On Wed, Sep 11, 2019 at 10:49:29AM +0100, Russell King - ARM Linux admin wrote:
> On Wed, Sep 11, 2019 at 12:46:19PM +0300, Andy Shevchenko wrote:
> > On Wed, Sep 11, 2019 at 10:39:14AM +0100, Russell King - ARM Linux admin wrote:
> > > On Wed, Sep 11, 2019 at 12:25:14PM +0300, Andy Shevchenko wrote:
> > > > On Wed, Sep 11, 2019 at 12:52:08AM -0700, Dmitry Torokhov wrote:
> > > > > Instead of fwnode_get_named_gpiod() that I plan to hide away, let's use
> > > > > the new fwnode_gpiod_get_index() that mimics gpiod_get_index(), bit
> > > > > works with arbitrary firmware node.
> e > > 
> > > > I'm wondering if it's possible to step forward and replace
> > > > fwnode_get_gpiod_index by gpiod_get() / gpiod_get_index() here and
> > > > in other cases in this series.
> > > 
> > > No, those require a struct device, but we have none.  There are network
> > > drivers where there is a struct device for the network complex, but only
> > > DT nodes for the individual network interfaces.  So no, gpiod_* really
> > > doesn't work.
> > 
> > In the following patch the node is derived from struct device. So, I believe
> > some cases can be handled differently.
> 
> phylink is not passed a struct device - it has no knowledge what the
> parent device is.
> 
> In any case, I do not have "the following patch".

Andy is talking about this one:

diff --git a/drivers/net/phy/mdio_bus.c b/drivers/net/phy/mdio_bus.c
index ce940871331e..9ca51d678123 100644
--- a/drivers/net/phy/mdio_bus.c
+++ b/drivers/net/phy/mdio_bus.c
@@ -46,8 +46,8 @@ static int mdiobus_register_gpiod(struct mdio_device *mdiodev)

        /* Deassert the optional reset signal */
        if (mdiodev->dev.of_node)
-               gpiod = fwnode_get_named_gpiod(&mdiodev->dev.of_node->fwnode,
-                                              "reset-gpios", 0,
                                               GPIOD_OUT_LOW,
+               gpiod = fwnode_gpiod_get_index(&mdiodev->dev.of_node->fwnode,
+                                              "reset", 0, GPIOD_OUT_LOW,
                                               "PHY reset");
Here if we do not care about "PHY reset" label, we could use
gpiod_get(&mdiodev->dev, "reset", GPIOD_OUT_LOW).

Thanks.

-- 
Dmitry

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

* Re: [PATCH 04/11] net: phylink: switch to using fwnode_gpiod_get_index()
  2019-09-11  9:55           ` Dmitry Torokhov
@ 2019-09-11 10:10             ` Russell King - ARM Linux admin
  2019-09-11 16:52               ` Andy Shevchenko
  0 siblings, 1 reply; 39+ messages in thread
From: Russell King - ARM Linux admin @ 2019-09-11 10:10 UTC (permalink / raw)
  To: Dmitry Torokhov
  Cc: Andy Shevchenko, Linus Walleij, Mika Westerberg, linux-kernel,
	linux-gpio, Andrew Lunn, David S. Miller, Florian Fainelli,
	Heiner Kallweit, netdev

On Wed, Sep 11, 2019 at 02:55:11AM -0700, Dmitry Torokhov wrote:
> On Wed, Sep 11, 2019 at 10:49:29AM +0100, Russell King - ARM Linux admin wrote:
> > On Wed, Sep 11, 2019 at 12:46:19PM +0300, Andy Shevchenko wrote:
> > > On Wed, Sep 11, 2019 at 10:39:14AM +0100, Russell King - ARM Linux admin wrote:
> > > > On Wed, Sep 11, 2019 at 12:25:14PM +0300, Andy Shevchenko wrote:
> > > > > On Wed, Sep 11, 2019 at 12:52:08AM -0700, Dmitry Torokhov wrote:
> > > > > > Instead of fwnode_get_named_gpiod() that I plan to hide away, let's use
> > > > > > the new fwnode_gpiod_get_index() that mimics gpiod_get_index(), bit
> > > > > > works with arbitrary firmware node.
> > e > > 
> > > > > I'm wondering if it's possible to step forward and replace
> > > > > fwnode_get_gpiod_index by gpiod_get() / gpiod_get_index() here and
> > > > > in other cases in this series.
> > > > 
> > > > No, those require a struct device, but we have none.  There are network
> > > > drivers where there is a struct device for the network complex, but only
> > > > DT nodes for the individual network interfaces.  So no, gpiod_* really
> > > > doesn't work.
> > > 
> > > In the following patch the node is derived from struct device. So, I believe
> > > some cases can be handled differently.
> > 
> > phylink is not passed a struct device - it has no knowledge what the
> > parent device is.
> > 
> > In any case, I do not have "the following patch".
> 
> Andy is talking about this one:
> 
> diff --git a/drivers/net/phy/mdio_bus.c b/drivers/net/phy/mdio_bus.c
> index ce940871331e..9ca51d678123 100644
> --- a/drivers/net/phy/mdio_bus.c
> +++ b/drivers/net/phy/mdio_bus.c
> @@ -46,8 +46,8 @@ static int mdiobus_register_gpiod(struct mdio_device *mdiodev)
> 
>         /* Deassert the optional reset signal */
>         if (mdiodev->dev.of_node)
> -               gpiod = fwnode_get_named_gpiod(&mdiodev->dev.of_node->fwnode,
> -                                              "reset-gpios", 0,
>                                                GPIOD_OUT_LOW,
> +               gpiod = fwnode_gpiod_get_index(&mdiodev->dev.of_node->fwnode,
> +                                              "reset", 0, GPIOD_OUT_LOW,
>                                                "PHY reset");
> Here if we do not care about "PHY reset" label, we could use
> gpiod_get(&mdiodev->dev, "reset", GPIOD_OUT_LOW).

Here, you have a struct device, so yes, it's possible.

Referring back to my comment, notice that I said we have none for the
phylink case, so it's not possible there.

I'm not sure why Andy replied the way he did, unless he mis-read my
comment.

-- 
RMK's Patch system: https://www.armlinux.org.uk/developer/patches/
FTTC broadband for 0.8mile line in suburbia: sync at 12.1Mbps down 622kbps up
According to speedtest.net: 11.9Mbps down 500kbps up

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

* Re: [PATCH 04/11] net: phylink: switch to using fwnode_gpiod_get_index()
  2019-09-11 10:10             ` Russell King - ARM Linux admin
@ 2019-09-11 16:52               ` Andy Shevchenko
  0 siblings, 0 replies; 39+ messages in thread
From: Andy Shevchenko @ 2019-09-11 16:52 UTC (permalink / raw)
  To: Russell King - ARM Linux admin
  Cc: Dmitry Torokhov, Linus Walleij, Mika Westerberg, linux-kernel,
	linux-gpio, Andrew Lunn, David S. Miller, Florian Fainelli,
	Heiner Kallweit, netdev

On Wed, Sep 11, 2019 at 11:10:16AM +0100, Russell King - ARM Linux admin wrote:
> On Wed, Sep 11, 2019 at 02:55:11AM -0700, Dmitry Torokhov wrote:
> > On Wed, Sep 11, 2019 at 10:49:29AM +0100, Russell King - ARM Linux admin wrote:
> > > On Wed, Sep 11, 2019 at 12:46:19PM +0300, Andy Shevchenko wrote:
> > > > On Wed, Sep 11, 2019 at 10:39:14AM +0100, Russell King - ARM Linux admin wrote:
> > > > > On Wed, Sep 11, 2019 at 12:25:14PM +0300, Andy Shevchenko wrote:
> > > > > > On Wed, Sep 11, 2019 at 12:52:08AM -0700, Dmitry Torokhov wrote:
> > > > > > > Instead of fwnode_get_named_gpiod() that I plan to hide away, let's use
> > > > > > > the new fwnode_gpiod_get_index() that mimics gpiod_get_index(), bit
> > > > > > > works with arbitrary firmware node.
> > > e > > 
> > > > > > I'm wondering if it's possible to step forward and replace
> > > > > > fwnode_get_gpiod_index by gpiod_get() / gpiod_get_index() here and
> > > > > > in other cases in this series.
> > > > > 
> > > > > No, those require a struct device, but we have none.  There are network
> > > > > drivers where there is a struct device for the network complex, but only
> > > > > DT nodes for the individual network interfaces.  So no, gpiod_* really
> > > > > doesn't work.
> > > > 
> > > > In the following patch the node is derived from struct device. So, I believe
> > > > some cases can be handled differently.

> Referring back to my comment, notice that I said we have none for the
> phylink case, so it's not possible there.
> 
> I'm not sure why Andy replied the way he did, unless he mis-read my
> comment.

It is a first patch which does the change. Mostly my reply was to Dmitry and
your comment clarifies the case with this patch, thanks!

-- 
With Best Regards,
Andy Shevchenko



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

* Re: [PATCH 02/11] gpiolib: introduce devm_fwnode_gpiod_get_index()
  2019-09-11  7:52 ` [PATCH 02/11] gpiolib: introduce devm_fwnode_gpiod_get_index() Dmitry Torokhov
@ 2019-09-11 17:01   ` Andy Shevchenko
  2019-09-12  9:35     ` Linus Walleij
  2019-09-12  9:48   ` Linus Walleij
  1 sibling, 1 reply; 39+ messages in thread
From: Andy Shevchenko @ 2019-09-11 17:01 UTC (permalink / raw)
  To: Dmitry Torokhov
  Cc: Linus Walleij, Mika Westerberg, linux-kernel, linux-gpio,
	Bartosz Golaszewski

On Wed, Sep 11, 2019 at 12:52:06AM -0700, Dmitry Torokhov wrote:
> devm_fwnode_get_index_gpiod_from_child() is too long, besides the fwnode
> in question does not have to be a child of device node. Let's rename it
> to devm_fwnode_gpiod_get_index() and keep the old name for compatibility
> for now.
> 
> Also let's add a devm_fwnode_gpiod_get() wrapper as majority of the
> callers need a single GPIO.

> +	return devm_fwnode_gpiod_get_index(dev, fwnode, con_id, 0,
> +					   flags, label);

At least one parameter can fit previous line, but taking into consideration
that moving second one makes it 81 character long, I would do it completely on
one line. I don't remember Linus' preferences.

> +}

> +	return devm_fwnode_gpiod_get_index(dev, child, con_id, index,
> +					   flags, label);

Ditto.

-- 
With Best Regards,
Andy Shevchenko



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

* Re: [PATCH 08/11] gpiolib: of: tease apart of_find_gpio()
  2019-09-11  7:52 ` [PATCH 08/11] gpiolib: of: tease apart of_find_gpio() Dmitry Torokhov
@ 2019-09-11 17:10   ` Andy Shevchenko
  0 siblings, 0 replies; 39+ messages in thread
From: Andy Shevchenko @ 2019-09-11 17:10 UTC (permalink / raw)
  To: Dmitry Torokhov
  Cc: Linus Walleij, Mika Westerberg, linux-kernel, linux-gpio,
	Bartosz Golaszewski

On Wed, Sep 11, 2019 at 12:52:12AM -0700, Dmitry Torokhov wrote:
> Tease apart of_find_gpio() into common function that works on the
> firmware node, and a fallback handler that works on the device
> structure, so that we can later use of_find_gpio() in
> fwnode_gpiod_get_index().

> +			desc = of_find_gpio(dev_fwnode(dev),
> +					    con_id, idx, &lookupflags);

Couple of parameters can be placed on previous line.

> +			if (desc == ERR_PTR(-ENOENT))
> +				desc = of_find_gpio_fallback(dev, con_id, idx,
> +							     &lookupflags);

> +

Do we need extra blank line?


-- 
With Best Regards,
Andy Shevchenko



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

* Re: [PATCH 09/11] gpiolib: of: tease apart acpi_find_gpio()
  2019-09-11  7:52 ` [PATCH 09/11] gpiolib: of: tease apart acpi_find_gpio() Dmitry Torokhov
@ 2019-09-11 17:12   ` Andy Shevchenko
  0 siblings, 0 replies; 39+ messages in thread
From: Andy Shevchenko @ 2019-09-11 17:12 UTC (permalink / raw)
  To: Dmitry Torokhov
  Cc: Linus Walleij, Mika Westerberg, linux-kernel, linux-gpio,
	Bartosz Golaszewski, linux-acpi

On Wed, Sep 11, 2019 at 12:52:13AM -0700, Dmitry Torokhov wrote:
> Tease apart acpi_find_gpio() into common function that works on the
> firmware node, and a fallback handler that works on the ACPI device
> structure, so that we can later use acpi_find_gpio() in
> fwnode_gpiod_get_index().

Title should start with "gpiolib: acpi:"


I review from this one later on.

-- 
With Best Regards,
Andy Shevchenko



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

* Re: [PATCH 00/11] Add support for software nodes to gpiolib
  2019-09-11  7:52 [PATCH 00/11] Add support for software nodes to gpiolib Dmitry Torokhov
                   ` (10 preceding siblings ...)
  2019-09-11  7:52 ` [PATCH 11/11] gpiolib: add support for software nodes Dmitry Torokhov
@ 2019-09-11 17:13 ` Andy Shevchenko
  2019-09-12  9:55 ` Linus Walleij
  12 siblings, 0 replies; 39+ messages in thread
From: Andy Shevchenko @ 2019-09-11 17:13 UTC (permalink / raw)
  To: Dmitry Torokhov
  Cc: Linus Walleij, Mika Westerberg, linux-kernel, linux-gpio,
	Andrew Lunn, Andrzej Hajda, Bartosz Golaszewski, Daniel Vetter,
	David Airlie, David S. Miller, Florian Fainelli, Heiner Kallweit,
	Jernej Skrabec, Jonas Karlman, Laurent Pinchart, Neil Armstrong,
	Russell King, dri-devel, linux-acpi, netdev

On Wed, Sep 11, 2019 at 12:52:04AM -0700, Dmitry Torokhov wrote:
> This series attempts to add support for software nodes to gpiolib, using
> software node references that were introduced recently. This allows us
> to convert more drivers to the generic device properties and drop
> support for custom platform data:
> 
> static const struct software_node gpio_bank_b_node = {
> |-------.name = "B",
> };
> 
> static const struct property_entry simone_key_enter_props[] = {
> |-------PROPERTY_ENTRY_U32("linux,code", KEY_ENTER),
> |-------PROPERTY_ENTRY_STRING("label", "enter"),
> |-------PROPERTY_ENTRY_REF("gpios", &gpio_bank_b_node, 123, GPIO_ACTIVE_LOW),
> |-------{ }
> };
> 
> If we agree in principle, I would like to have the very first 3 patches
> in an immutable branch off maybe -rc8 so that it can be pulled into
> individual subsystems so that patches switching various drivers to
> fwnode_gpiod_get_index() could be applied.

FWIW,
Reviewed-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>

for patches 1-8 after addressing minor issues.
I'll review the rest later on.

> 
> Thanks,
> Dmitry
> 
> Dmitry Torokhov (11):
>   gpiolib: of: add a fallback for wlf,reset GPIO name
>   gpiolib: introduce devm_fwnode_gpiod_get_index()
>   gpiolib: introduce fwnode_gpiod_get_index()
>   net: phylink: switch to using fwnode_gpiod_get_index()
>   net: mdio: switch to using fwnode_gpiod_get_index()
>   drm/bridge: ti-tfp410: switch to using fwnode_gpiod_get_index()
>   gpliolib: make fwnode_get_named_gpiod() static
>   gpiolib: of: tease apart of_find_gpio()
>   gpiolib: of: tease apart acpi_find_gpio()
>   gpiolib: consolidate fwnode GPIO lookups
>   gpiolib: add support for software nodes
> 
>  drivers/gpio/Makefile              |   1 +
>  drivers/gpio/gpiolib-acpi.c        | 153 ++++++++++++++----------
>  drivers/gpio/gpiolib-acpi.h        |  21 ++--
>  drivers/gpio/gpiolib-devres.c      |  33 ++----
>  drivers/gpio/gpiolib-of.c          | 159 ++++++++++++++-----------
>  drivers/gpio/gpiolib-of.h          |  26 ++--
>  drivers/gpio/gpiolib-swnode.c      |  92 +++++++++++++++
>  drivers/gpio/gpiolib-swnode.h      |  13 ++
>  drivers/gpio/gpiolib.c             | 184 ++++++++++++++++-------------
>  drivers/gpu/drm/bridge/ti-tfp410.c |   4 +-
>  drivers/net/phy/mdio_bus.c         |   4 +-
>  drivers/net/phy/phylink.c          |   4 +-
>  include/linux/gpio/consumer.h      |  53 ++++++---
>  13 files changed, 471 insertions(+), 276 deletions(-)
>  create mode 100644 drivers/gpio/gpiolib-swnode.c
>  create mode 100644 drivers/gpio/gpiolib-swnode.h
> 
> -- 
> 2.23.0.162.g0b9fbb3734-goog
> 

-- 
With Best Regards,
Andy Shevchenko



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

* Re: [PATCH 01/11] gpiolib: of: add a fallback for wlf,reset GPIO name
  2019-09-11  7:52 ` [PATCH 01/11] gpiolib: of: add a fallback for wlf,reset GPIO name Dmitry Torokhov
@ 2019-09-12  9:30   ` Linus Walleij
  0 siblings, 0 replies; 39+ messages in thread
From: Linus Walleij @ 2019-09-12  9:30 UTC (permalink / raw)
  To: Dmitry Torokhov
  Cc: Andy Shevchenko, Mika Westerberg, linux-kernel,
	open list:GPIO SUBSYSTEM, Bartosz Golaszewski

On Wed, Sep 11, 2019 at 8:52 AM Dmitry Torokhov
<dmitry.torokhov@gmail.com> wrote:

> The old Arizona binding did not use -gpio or -gpios suffix, so
> devm_gpiod_get() does not work for it. As it is the one of a few users
> of devm_gpiod_get_from_of_node() API that I want to remove, I'd rather
> have a small quirk in the gpiolib OF handler, and switch Arizona
> driver to devm_gpiod_get().
>
> Signed-off-by: Dmitry Torokhov <dmitry.torokhov@gmail.com>

Patch applied, good to have this in and it is completely in line
with my idea to handle all these quirks inside the gpiolib-of.

Yours,
Linus Walleij

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

* Re: [PATCH 02/11] gpiolib: introduce devm_fwnode_gpiod_get_index()
  2019-09-11 17:01   ` Andy Shevchenko
@ 2019-09-12  9:35     ` Linus Walleij
  0 siblings, 0 replies; 39+ messages in thread
From: Linus Walleij @ 2019-09-12  9:35 UTC (permalink / raw)
  To: Andy Shevchenko
  Cc: Dmitry Torokhov, Mika Westerberg, linux-kernel,
	open list:GPIO SUBSYSTEM, Bartosz Golaszewski

On Wed, Sep 11, 2019 at 6:01 PM Andy Shevchenko
<andriy.shevchenko@linux.intel.com> wrote:
> On Wed, Sep 11, 2019 at 12:52:06AM -0700, Dmitry Torokhov wrote:
> > devm_fwnode_get_index_gpiod_from_child() is too long, besides the fwnode
> > in question does not have to be a child of device node. Let's rename it
> > to devm_fwnode_gpiod_get_index() and keep the old name for compatibility
> > for now.
> >
> > Also let's add a devm_fwnode_gpiod_get() wrapper as majority of the
> > callers need a single GPIO.
>
> > +     return devm_fwnode_gpiod_get_index(dev, fwnode, con_id, 0,
> > +                                        flags, label);
>
> At least one parameter can fit previous line, but taking into consideration
> that moving second one makes it 81 character long, I would do it completely on
> one line. I don't remember Linus' preferences.

I don't really have one, I don't mind 80+ chars, I don't mind breaking lines
to avoid it.

Yours,
Linus Walleij

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

* Re: [PATCH 04/11] net: phylink: switch to using fwnode_gpiod_get_index()
  2019-09-11  9:51         ` Dmitry Torokhov
@ 2019-09-12  9:41           ` Linus Walleij
  2019-09-12 13:44             ` Andy Shevchenko
  0 siblings, 1 reply; 39+ messages in thread
From: Linus Walleij @ 2019-09-12  9:41 UTC (permalink / raw)
  To: Dmitry Torokhov
  Cc: Andy Shevchenko, Russell King - ARM Linux admin, Mika Westerberg,
	linux-kernel, open list:GPIO SUBSYSTEM, Andrew Lunn,
	David S. Miller, Florian Fainelli, Heiner Kallweit, netdev

On Wed, Sep 11, 2019 at 10:51 AM Dmitry Torokhov
<dmitry.torokhov@gmail.com> wrote:

> If we are willing to sacrifice the custom label for the GPIO that
> fwnode_gpiod_get_index() allows us to set, then there are several
> drivers that could actually use gpiod_get() API.

We have:
gpiod_set_consumer_name(gpiod, "name");
to deal with that so no sacrifice is needed.

Yours,
Linus Walleij

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

* Re: [PATCH 02/11] gpiolib: introduce devm_fwnode_gpiod_get_index()
  2019-09-11  7:52 ` [PATCH 02/11] gpiolib: introduce devm_fwnode_gpiod_get_index() Dmitry Torokhov
  2019-09-11 17:01   ` Andy Shevchenko
@ 2019-09-12  9:48   ` Linus Walleij
  2019-09-13 18:14     ` Dmitry Torokhov
  1 sibling, 1 reply; 39+ messages in thread
From: Linus Walleij @ 2019-09-12  9:48 UTC (permalink / raw)
  To: Dmitry Torokhov
  Cc: Andy Shevchenko, Mika Westerberg, linux-kernel,
	open list:GPIO SUBSYSTEM, Bartosz Golaszewski

On Wed, Sep 11, 2019 at 8:52 AM Dmitry Torokhov
<dmitry.torokhov@gmail.com> wrote:

> devm_fwnode_get_index_gpiod_from_child() is too long, besides the fwnode
> in question does not have to be a child of device node. Let's rename it
> to devm_fwnode_gpiod_get_index() and keep the old name for compatibility
> for now.
>
> Also let's add a devm_fwnode_gpiod_get() wrapper as majority of the
> callers need a single GPIO.
>
> Signed-off-by: Dmitry Torokhov <dmitry.torokhov@gmail.com>

The patch is good because this is in line with Rusty Russells API
manifesto:

7. The obvious use is (probably) the correct one.
6. The name tells you how to use it.

It doesn't apply to my "devel" branch as of now:
https://git.kernel.org/pub/scm/linux/kernel/git/linusw/linux-gpio.git/log/?h=devel

If you rebase this and the next patch and send them separately I
am willing to apply them already for v5.4 to easy your refactoring
work during the v5.5 cycle here, provided we try to fix up the old users
ASAP and delete the compatibility fallbacks in the near future.

Yours,
Linus Walleij

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

* Re: [PATCH 03/11] gpiolib: introduce fwnode_gpiod_get_index()
  2019-09-11  7:52 ` [PATCH 03/11] gpiolib: introduce fwnode_gpiod_get_index() Dmitry Torokhov
@ 2019-09-12  9:50   ` Linus Walleij
  0 siblings, 0 replies; 39+ messages in thread
From: Linus Walleij @ 2019-09-12  9:50 UTC (permalink / raw)
  To: Dmitry Torokhov
  Cc: Andy Shevchenko, Mika Westerberg, linux-kernel,
	open list:GPIO SUBSYSTEM, Bartosz Golaszewski

On Wed, Sep 11, 2019 at 8:52 AM Dmitry Torokhov
<dmitry.torokhov@gmail.com> wrote:

> This introduces fwnode_gpiod_get_index() that iterates through common gpio
> suffixes when trying to locate a GPIO within a given firmware node.
>
> We also switch devm_fwnode_gpiod_get_index() to call
> fwnode_gpiod_get_index() instead of iterating through GPIO suffixes on
> its own.
>
> Signed-off-by: Dmitry Torokhov <dmitry.torokhov@gmail.com>

So I'd like to merge this as well for v5.4 because I see where
you're going with this and it's nice to have these APIs in place
for that.

Please rebase this and the other one and resend!

Yours,
Linus Walleij

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

* Re: [PATCH 00/11] Add support for software nodes to gpiolib
  2019-09-11  7:52 [PATCH 00/11] Add support for software nodes to gpiolib Dmitry Torokhov
                   ` (11 preceding siblings ...)
  2019-09-11 17:13 ` [PATCH 00/11] Add support for software nodes to gpiolib Andy Shevchenko
@ 2019-09-12  9:55 ` Linus Walleij
  2019-09-17  0:22   ` Dmitry Torokhov
  12 siblings, 1 reply; 39+ messages in thread
From: Linus Walleij @ 2019-09-12  9:55 UTC (permalink / raw)
  To: Dmitry Torokhov
  Cc: Andy Shevchenko, Mika Westerberg, linux-kernel,
	open list:GPIO SUBSYSTEM, Andrew Lunn, Andrzej Hajda,
	Bartosz Golaszewski, Daniel Vetter, David Airlie,
	David S. Miller, Florian Fainelli, Heiner Kallweit,
	Jernej Skrabec, Jonas Karlman, Laurent Pinchart, Neil Armstrong,
	Russell King, open list:DRM PANEL DRIVERS,
	ACPI Devel Maling List, netdev

On Wed, Sep 11, 2019 at 8:52 AM Dmitry Torokhov
<dmitry.torokhov@gmail.com> wrote:

> If we agree in principle, I would like to have the very first 3 patches
> in an immutable branch off maybe -rc8 so that it can be pulled into
> individual subsystems so that patches switching various drivers to
> fwnode_gpiod_get_index() could be applied.

I think it seems a bit enthusiastic to have non-GPIO subsystems
pick up these changes this close to the merge window so my plan
is to merge patches 1.2.3 (1 already merged) and then you could
massage the other subsystems in v5.4-rc1.

But if other subsystems say "hey we want do fix this in like 3 days"
then I'm game for an immutable branch as well.

Yours,
Linus Walleij

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

* Re: [PATCH 04/11] net: phylink: switch to using fwnode_gpiod_get_index()
  2019-09-12  9:41           ` Linus Walleij
@ 2019-09-12 13:44             ` Andy Shevchenko
  2019-09-12 13:52               ` Russell King - ARM Linux admin
  0 siblings, 1 reply; 39+ messages in thread
From: Andy Shevchenko @ 2019-09-12 13:44 UTC (permalink / raw)
  To: Linus Walleij
  Cc: Dmitry Torokhov, Russell King - ARM Linux admin, Mika Westerberg,
	linux-kernel, open list:GPIO SUBSYSTEM, Andrew Lunn,
	David S. Miller, Florian Fainelli, Heiner Kallweit, netdev

On Thu, Sep 12, 2019 at 10:41:43AM +0100, Linus Walleij wrote:
> On Wed, Sep 11, 2019 at 10:51 AM Dmitry Torokhov
> <dmitry.torokhov@gmail.com> wrote:
> 
> > If we are willing to sacrifice the custom label for the GPIO that
> > fwnode_gpiod_get_index() allows us to set, then there are several
> > drivers that could actually use gpiod_get() API.
> 
> We have:
> gpiod_set_consumer_name(gpiod, "name");
> to deal with that so no sacrifice is needed.

Thank for this hint!

-- 
With Best Regards,
Andy Shevchenko



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

* Re: [PATCH 04/11] net: phylink: switch to using fwnode_gpiod_get_index()
  2019-09-12 13:44             ` Andy Shevchenko
@ 2019-09-12 13:52               ` Russell King - ARM Linux admin
  0 siblings, 0 replies; 39+ messages in thread
From: Russell King - ARM Linux admin @ 2019-09-12 13:52 UTC (permalink / raw)
  To: Andy Shevchenko
  Cc: Linus Walleij, Dmitry Torokhov, Mika Westerberg, linux-kernel,
	open list:GPIO SUBSYSTEM, Andrew Lunn, David S. Miller,
	Florian Fainelli, Heiner Kallweit, netdev

On Thu, Sep 12, 2019 at 04:44:29PM +0300, Andy Shevchenko wrote:
> On Thu, Sep 12, 2019 at 10:41:43AM +0100, Linus Walleij wrote:
> > On Wed, Sep 11, 2019 at 10:51 AM Dmitry Torokhov
> > <dmitry.torokhov@gmail.com> wrote:
> > 
> > > If we are willing to sacrifice the custom label for the GPIO that
> > > fwnode_gpiod_get_index() allows us to set, then there are several
> > > drivers that could actually use gpiod_get() API.
> > 
> > We have:
> > gpiod_set_consumer_name(gpiod, "name");
> > to deal with that so no sacrifice is needed.
> 
> Thank for this hint!

Would it be possible to improve your email etiquette, and move this
discussion to a more appropriate subject line, so I don't have to keep
checking these emails, in case you _do_ talk about something relevent
to the original patch that the subject line refers to?

Thanks.

-- 
RMK's Patch system: https://www.armlinux.org.uk/developer/patches/
FTTC broadband for 0.8mile line in suburbia: sync at 12.1Mbps down 622kbps up
According to speedtest.net: 11.9Mbps down 500kbps up

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

* Re: [PATCH 02/11] gpiolib: introduce devm_fwnode_gpiod_get_index()
  2019-09-12  9:48   ` Linus Walleij
@ 2019-09-13 18:14     ` Dmitry Torokhov
  0 siblings, 0 replies; 39+ messages in thread
From: Dmitry Torokhov @ 2019-09-13 18:14 UTC (permalink / raw)
  To: Linus Walleij
  Cc: Andy Shevchenko, Mika Westerberg, linux-kernel,
	open list:GPIO SUBSYSTEM, Bartosz Golaszewski

On Thu, Sep 12, 2019 at 10:48:13AM +0100, Linus Walleij wrote:
> On Wed, Sep 11, 2019 at 8:52 AM Dmitry Torokhov
> <dmitry.torokhov@gmail.com> wrote:
> 
> > devm_fwnode_get_index_gpiod_from_child() is too long, besides the fwnode
> > in question does not have to be a child of device node. Let's rename it
> > to devm_fwnode_gpiod_get_index() and keep the old name for compatibility
> > for now.
> >
> > Also let's add a devm_fwnode_gpiod_get() wrapper as majority of the
> > callers need a single GPIO.
> >
> > Signed-off-by: Dmitry Torokhov <dmitry.torokhov@gmail.com>
> 
> The patch is good because this is in line with Rusty Russells API
> manifesto:
> 
> 7. The obvious use is (probably) the correct one.
> 6. The name tells you how to use it.
> 
> It doesn't apply to my "devel" branch as of now:
> https://git.kernel.org/pub/scm/linux/kernel/git/linusw/linux-gpio.git/log/?h=devel
> 
> If you rebase this and the next patch and send them separately I
> am willing to apply them already for v5.4 to easy your refactoring
> work during the v5.5 cycle here, provided we try to fix up the old users
> ASAP and delete the compatibility fallbacks in the near future.

Done.

Thanks.

-- 
Dmitry

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

* Re: [PATCH 00/11] Add support for software nodes to gpiolib
  2019-09-12  9:55 ` Linus Walleij
@ 2019-09-17  0:22   ` Dmitry Torokhov
  2019-09-30 22:44     ` Dmitry Torokhov
  0 siblings, 1 reply; 39+ messages in thread
From: Dmitry Torokhov @ 2019-09-17  0:22 UTC (permalink / raw)
  To: Linus Walleij
  Cc: Andy Shevchenko, Mika Westerberg, linux-kernel,
	open list:GPIO SUBSYSTEM, Andrew Lunn, Andrzej Hajda,
	Bartosz Golaszewski, Daniel Vetter, David Airlie,
	David S. Miller, Florian Fainelli, Heiner Kallweit,
	Jernej Skrabec, Jonas Karlman, Laurent Pinchart, Neil Armstrong,
	Russell King, open list:DRM PANEL DRIVERS,
	ACPI Devel Maling List, netdev

On Thu, Sep 12, 2019 at 10:55:47AM +0100, Linus Walleij wrote:
> On Wed, Sep 11, 2019 at 8:52 AM Dmitry Torokhov
> <dmitry.torokhov@gmail.com> wrote:
> 
> > If we agree in principle, I would like to have the very first 3 patches
> > in an immutable branch off maybe -rc8 so that it can be pulled into
> > individual subsystems so that patches switching various drivers to
> > fwnode_gpiod_get_index() could be applied.
> 
> I think it seems a bit enthusiastic to have non-GPIO subsystems
> pick up these changes this close to the merge window so my plan
> is to merge patches 1.2.3 (1 already merged) and then you could
> massage the other subsystems in v5.4-rc1.
> 
> But if other subsystems say "hey we want do fix this in like 3 days"
> then I'm game for an immutable branch as well.

No, if it is still has a chance for -rc1 then I'm good. I was thinking
if it does not go into -rc1 I could convince some of them merge a
targeted immutable branch off -rc8 or 5.3 final and then apply patches
relevant to their subsystems so we do not have to wait till 5.6 to land
everything.

Thanks.

-- 
Dmitry

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

* Re: [PATCH 06/11] drm/bridge: ti-tfp410: switch to using fwnode_gpiod_get_index()
  2019-09-11  7:52 ` [PATCH 06/11] drm/bridge: ti-tfp410: " Dmitry Torokhov
@ 2019-09-20 23:12   ` Laurent Pinchart
  2019-09-23 15:03     ` Heikki Krogerus
  0 siblings, 1 reply; 39+ messages in thread
From: Laurent Pinchart @ 2019-09-20 23:12 UTC (permalink / raw)
  To: Dmitry Torokhov
  Cc: Linus Walleij, Andy Shevchenko, Mika Westerberg, linux-kernel,
	linux-gpio, Andrzej Hajda, Daniel Vetter, David Airlie,
	Jernej Skrabec, Jonas Karlman, Neil Armstrong, dri-devel,
	Heikki Krogerus

Hi Dmitry,

(CC'ing Heikki as the original author of software nodes support)

Thank you for the patch.

On Wed, Sep 11, 2019 at 12:52:10AM -0700, Dmitry Torokhov wrote:
> Instead of fwnode_get_named_gpiod() that I plan to hide away, let's use
> the new fwnode_gpiod_get_index() that mimics gpiod_get_index(), bit

s/bit/but/

> works with arbitrary firmware node.
> 
> Signed-off-by: Dmitry Torokhov <dmitry.torokhov@gmail.com>

Reviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>

On a side note, as I'm not very familiar with software nodes, I tried to
see how they are to be used, and it seems they are completely
undocumented :-( Heikki, is this something that could be fixed ?

> ---
> 
>  drivers/gpu/drm/bridge/ti-tfp410.c | 4 ++--
>  1 file changed, 2 insertions(+), 2 deletions(-)
> 
> diff --git a/drivers/gpu/drm/bridge/ti-tfp410.c b/drivers/gpu/drm/bridge/ti-tfp410.c
> index 61cc2354ef1b..d9c9c9ebad2b 100644
> --- a/drivers/gpu/drm/bridge/ti-tfp410.c
> +++ b/drivers/gpu/drm/bridge/ti-tfp410.c
> @@ -284,8 +284,8 @@ static int tfp410_get_connector_properties(struct tfp410 *dvi)
>  	else
>  		dvi->connector_type = DRM_MODE_CONNECTOR_DVID;
>  
> -	dvi->hpd = fwnode_get_named_gpiod(&connector_node->fwnode,
> -					"hpd-gpios", 0, GPIOD_IN, "hpd");
> +	dvi->hpd = fwnode_gpiod_get_index(&connector_node->fwnode,
> +					  "hpd", 0, GPIOD_IN, "hpd");
>  	if (IS_ERR(dvi->hpd)) {
>  		ret = PTR_ERR(dvi->hpd);
>  		dvi->hpd = NULL;

-- 
Regards,

Laurent Pinchart

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

* Re: [PATCH 06/11] drm/bridge: ti-tfp410: switch to using fwnode_gpiod_get_index()
  2019-09-20 23:12   ` Laurent Pinchart
@ 2019-09-23 15:03     ` Heikki Krogerus
  2019-09-23 16:00       ` Laurent Pinchart
  0 siblings, 1 reply; 39+ messages in thread
From: Heikki Krogerus @ 2019-09-23 15:03 UTC (permalink / raw)
  To: Laurent Pinchart
  Cc: Dmitry Torokhov, Linus Walleij, Andy Shevchenko, Mika Westerberg,
	linux-kernel, linux-gpio, Andrzej Hajda, Daniel Vetter,
	David Airlie, Jernej Skrabec, Jonas Karlman, Neil Armstrong,
	dri-devel

On Sat, Sep 21, 2019 at 02:12:28AM +0300, Laurent Pinchart wrote:
> Hi Dmitry,
> 
> (CC'ing Heikki as the original author of software nodes support)
> 
> Thank you for the patch.
> 
> On Wed, Sep 11, 2019 at 12:52:10AM -0700, Dmitry Torokhov wrote:
> > Instead of fwnode_get_named_gpiod() that I plan to hide away, let's use
> > the new fwnode_gpiod_get_index() that mimics gpiod_get_index(), bit
> 
> s/bit/but/
> 
> > works with arbitrary firmware node.
> > 
> > Signed-off-by: Dmitry Torokhov <dmitry.torokhov@gmail.com>
> 
> Reviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
> 
> On a side note, as I'm not very familiar with software nodes, I tried to
> see how they are to be used, and it seems they are completely
> undocumented :-( Heikki, is this something that could be fixed ?

OK. I'll start writing API documentation for it.

thanks,

-- 
heikki

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

* Re: [PATCH 06/11] drm/bridge: ti-tfp410: switch to using fwnode_gpiod_get_index()
  2019-09-23 15:03     ` Heikki Krogerus
@ 2019-09-23 16:00       ` Laurent Pinchart
  0 siblings, 0 replies; 39+ messages in thread
From: Laurent Pinchart @ 2019-09-23 16:00 UTC (permalink / raw)
  To: Heikki Krogerus
  Cc: Dmitry Torokhov, Linus Walleij, Andy Shevchenko, Mika Westerberg,
	linux-kernel, linux-gpio, Andrzej Hajda, Daniel Vetter,
	David Airlie, Jernej Skrabec, Jonas Karlman, Neil Armstrong,
	dri-devel

Hi Heikki,

On Mon, Sep 23, 2019 at 06:03:33PM +0300, Heikki Krogerus wrote:
> On Sat, Sep 21, 2019 at 02:12:28AM +0300, Laurent Pinchart wrote:
> > Hi Dmitry,
> > 
> > (CC'ing Heikki as the original author of software nodes support)
> > 
> > Thank you for the patch.
> > 
> > On Wed, Sep 11, 2019 at 12:52:10AM -0700, Dmitry Torokhov wrote:
> > > Instead of fwnode_get_named_gpiod() that I plan to hide away, let's use
> > > the new fwnode_gpiod_get_index() that mimics gpiod_get_index(), bit
> > 
> > s/bit/but/
> > 
> > > works with arbitrary firmware node.
> > > 
> > > Signed-off-by: Dmitry Torokhov <dmitry.torokhov@gmail.com>
> > 
> > Reviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
> > 
> > On a side note, as I'm not very familiar with software nodes, I tried to
> > see how they are to be used, and it seems they are completely
> > undocumented :-( Heikki, is this something that could be fixed ?
> 
> OK. I'll start writing API documentation for it.

That's great, thanks ! I'll do my best to review it if you CC me.

-- 
Regards,

Laurent Pinchart

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

* Re: [PATCH 00/11] Add support for software nodes to gpiolib
  2019-09-17  0:22   ` Dmitry Torokhov
@ 2019-09-30 22:44     ` Dmitry Torokhov
  2019-10-04 21:44       ` Linus Walleij
  0 siblings, 1 reply; 39+ messages in thread
From: Dmitry Torokhov @ 2019-09-30 22:44 UTC (permalink / raw)
  To: Linus Walleij
  Cc: Andy Shevchenko, Mika Westerberg, linux-kernel,
	open list:GPIO SUBSYSTEM, Andrew Lunn, Andrzej Hajda,
	Bartosz Golaszewski, Daniel Vetter, David Airlie,
	David S. Miller, Florian Fainelli, Heiner Kallweit,
	Jernej Skrabec, Jonas Karlman, Laurent Pinchart, Neil Armstrong,
	Russell King, open list:DRM PANEL DRIVERS,
	ACPI Devel Maling List, netdev

Hi Linus,

On Mon, Sep 16, 2019 at 05:22:07PM -0700, Dmitry Torokhov wrote:
> On Thu, Sep 12, 2019 at 10:55:47AM +0100, Linus Walleij wrote:
> > On Wed, Sep 11, 2019 at 8:52 AM Dmitry Torokhov
> > <dmitry.torokhov@gmail.com> wrote:
> > 
> > > If we agree in principle, I would like to have the very first 3 patches
> > > in an immutable branch off maybe -rc8 so that it can be pulled into
> > > individual subsystems so that patches switching various drivers to
> > > fwnode_gpiod_get_index() could be applied.
> > 
> > I think it seems a bit enthusiastic to have non-GPIO subsystems
> > pick up these changes this close to the merge window so my plan
> > is to merge patches 1.2.3 (1 already merged) and then you could
> > massage the other subsystems in v5.4-rc1.
> > 
> > But if other subsystems say "hey we want do fix this in like 3 days"
> > then I'm game for an immutable branch as well.
> 
> No, if it is still has a chance for -rc1 then I'm good. I was thinking
> if it does not go into -rc1 I could convince some of them merge a
> targeted immutable branch off -rc8 or 5.3 final and then apply patches
> relevant to their subsystems so we do not have to wait till 5.6 to land
> everything.

So I guess we missed -rc1. Any chance we could get an immutable branch
off -rc1 that you will pull into your main branch and I hopefully can
persuade other maintainers to pull as well so we do not need to drag it
over 2+ merge windows?

Thanks.

-- 
Dmitry

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

* Re: [PATCH 00/11] Add support for software nodes to gpiolib
  2019-09-30 22:44     ` Dmitry Torokhov
@ 2019-10-04 21:44       ` Linus Walleij
  0 siblings, 0 replies; 39+ messages in thread
From: Linus Walleij @ 2019-10-04 21:44 UTC (permalink / raw)
  To: Dmitry Torokhov
  Cc: Andy Shevchenko, Mika Westerberg, linux-kernel,
	open list:GPIO SUBSYSTEM, Andrew Lunn, Andrzej Hajda,
	Bartosz Golaszewski, Daniel Vetter, David Airlie,
	David S. Miller, Florian Fainelli, Heiner Kallweit,
	Jernej Skrabec, Jonas Karlman, Laurent Pinchart, Neil Armstrong,
	Russell King, open list:DRM PANEL DRIVERS,
	ACPI Devel Maling List, netdev

On Tue, Oct 1, 2019 at 12:45 AM Dmitry Torokhov
<dmitry.torokhov@gmail.com> wrote:

> So I guess we missed -rc1. Any chance we could get an immutable branch
> off -rc1 that you will pull into your main branch and I hopefully can
> persuade other maintainers to pull as well so we do not need to drag it
> over 2+ merge windows?

Yes I'm sorry. I was swamped with stabilizing the kernel.
I made an immutable branch and tried to use zeroday for testing
but it timed out so I folded it in for-next anyways after som basic
tests.

Yours,
Linus Walleij

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

end of thread, other threads:[~2019-10-04 21:44 UTC | newest]

Thread overview: 39+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-09-11  7:52 [PATCH 00/11] Add support for software nodes to gpiolib Dmitry Torokhov
2019-09-11  7:52 ` [PATCH 01/11] gpiolib: of: add a fallback for wlf,reset GPIO name Dmitry Torokhov
2019-09-12  9:30   ` Linus Walleij
2019-09-11  7:52 ` [PATCH 02/11] gpiolib: introduce devm_fwnode_gpiod_get_index() Dmitry Torokhov
2019-09-11 17:01   ` Andy Shevchenko
2019-09-12  9:35     ` Linus Walleij
2019-09-12  9:48   ` Linus Walleij
2019-09-13 18:14     ` Dmitry Torokhov
2019-09-11  7:52 ` [PATCH 03/11] gpiolib: introduce fwnode_gpiod_get_index() Dmitry Torokhov
2019-09-12  9:50   ` Linus Walleij
2019-09-11  7:52 ` [PATCH 04/11] net: phylink: switch to using fwnode_gpiod_get_index() Dmitry Torokhov
2019-09-11  9:25   ` Andy Shevchenko
2019-09-11  9:39     ` Russell King - ARM Linux admin
2019-09-11  9:46       ` Andy Shevchenko
2019-09-11  9:49         ` Russell King - ARM Linux admin
2019-09-11  9:55           ` Dmitry Torokhov
2019-09-11 10:10             ` Russell King - ARM Linux admin
2019-09-11 16:52               ` Andy Shevchenko
2019-09-11  9:51         ` Dmitry Torokhov
2019-09-12  9:41           ` Linus Walleij
2019-09-12 13:44             ` Andy Shevchenko
2019-09-12 13:52               ` Russell King - ARM Linux admin
2019-09-11  7:52 ` [PATCH 05/11] net: mdio: " Dmitry Torokhov
2019-09-11  7:52 ` [PATCH 06/11] drm/bridge: ti-tfp410: " Dmitry Torokhov
2019-09-20 23:12   ` Laurent Pinchart
2019-09-23 15:03     ` Heikki Krogerus
2019-09-23 16:00       ` Laurent Pinchart
2019-09-11  7:52 ` [PATCH 07/11] gpliolib: make fwnode_get_named_gpiod() static Dmitry Torokhov
2019-09-11  7:52 ` [PATCH 08/11] gpiolib: of: tease apart of_find_gpio() Dmitry Torokhov
2019-09-11 17:10   ` Andy Shevchenko
2019-09-11  7:52 ` [PATCH 09/11] gpiolib: of: tease apart acpi_find_gpio() Dmitry Torokhov
2019-09-11 17:12   ` Andy Shevchenko
2019-09-11  7:52 ` [PATCH 10/11] gpiolib: consolidate fwnode GPIO lookups Dmitry Torokhov
2019-09-11  7:52 ` [PATCH 11/11] gpiolib: add support for software nodes Dmitry Torokhov
2019-09-11 17:13 ` [PATCH 00/11] Add support for software nodes to gpiolib Andy Shevchenko
2019-09-12  9:55 ` Linus Walleij
2019-09-17  0:22   ` Dmitry Torokhov
2019-09-30 22:44     ` Dmitry Torokhov
2019-10-04 21:44       ` Linus Walleij

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).