2022-12-19 19:28:46

by Dmitry Torokhov

[permalink] [raw]
Subject: [PATCH 1/5] gpiolib: of: remove of_gpio_count()

There are no more users of of_gpio_count() in the mainline kernel,
remove it.

Signed-off-by: Dmitry Torokhov <[email protected]>
---

After 6.2-rc1 there should be no more users of the APIs mentioned in
this series.

include/linux/of_gpio.h | 11 -----------
1 file changed, 11 deletions(-)

diff --git a/include/linux/of_gpio.h b/include/linux/of_gpio.h
index 6db627257a7b..39f16a960565 100644
--- a/include/linux/of_gpio.h
+++ b/include/linux/of_gpio.h
@@ -105,17 +105,6 @@ static inline int of_gpio_named_count(const struct device_node *np,
return of_count_phandle_with_args(np, propname, "#gpio-cells");
}

-/**
- * of_gpio_count() - Count GPIOs for a device
- * @np: device node to count GPIOs for
- *
- * Same as of_gpio_named_count, but hard coded to use the 'gpios' property
- */
-static inline int of_gpio_count(const struct device_node *np)
-{
- return of_gpio_named_count(np, "gpios");
-}
-
static inline int of_get_gpio_flags(const struct device_node *np, int index,
enum of_gpio_flags *flags)
{
--
2.39.0.314.g84b9a713c41-goog


2022-12-19 19:36:27

by Dmitry Torokhov

[permalink] [raw]
Subject: [PATCH 2/5] gpiolib: of: stop exporting of_gpio_named_count()

The only user of this function is gpiolib-of.c so move it there.

Signed-off-by: Dmitry Torokhov <[email protected]>
---
drivers/gpio/gpiolib-of.c | 26 ++++++++++++++++++++++++++
include/linux/of_gpio.h | 26 --------------------------
2 files changed, 26 insertions(+), 26 deletions(-)

diff --git a/drivers/gpio/gpiolib-of.c b/drivers/gpio/gpiolib-of.c
index 4fff7258ee41..6724e375678d 100644
--- a/drivers/gpio/gpiolib-of.c
+++ b/drivers/gpio/gpiolib-of.c
@@ -23,6 +23,32 @@
#include "gpiolib.h"
#include "gpiolib-of.h"

+/**
+ * of_gpio_named_count() - Count GPIOs for a device
+ * @np: device node to count GPIOs for
+ * @propname: property name containing gpio specifier(s)
+ *
+ * The function returns the count of GPIOs specified for a node.
+ * Note that the empty GPIO specifiers count too. Returns either
+ * Number of gpios defined in property,
+ * -EINVAL for an incorrectly formed gpios property, or
+ * -ENOENT for a missing gpios property
+ *
+ * Example:
+ * gpios = <0
+ * &gpio1 1 2
+ * 0
+ * &gpio2 3 4>;
+ *
+ * The above example defines four GPIOs, two of which are not specified.
+ * This function will return '4'
+ */
+static int of_gpio_named_count(const struct device_node *np,
+ const char *propname)
+{
+ return of_count_phandle_with_args(np, propname, "#gpio-cells");
+}
+
/**
* of_gpio_spi_cs_get_count() - special GPIO counting for SPI
* @dev: Consuming device
diff --git a/include/linux/of_gpio.h b/include/linux/of_gpio.h
index 39f16a960565..680025c1a55b 100644
--- a/include/linux/of_gpio.h
+++ b/include/linux/of_gpio.h
@@ -79,32 +79,6 @@ static inline int of_get_named_gpio_flags(const struct device_node *np,

#endif /* CONFIG_OF_GPIO */

-/**
- * of_gpio_named_count() - Count GPIOs for a device
- * @np: device node to count GPIOs for
- * @propname: property name containing gpio specifier(s)
- *
- * The function returns the count of GPIOs specified for a node.
- * Note that the empty GPIO specifiers count too. Returns either
- * Number of gpios defined in property,
- * -EINVAL for an incorrectly formed gpios property, or
- * -ENOENT for a missing gpios property
- *
- * Example:
- * gpios = <0
- * &gpio1 1 2
- * 0
- * &gpio2 3 4>;
- *
- * The above example defines four GPIOs, two of which are not specified.
- * This function will return '4'
- */
-static inline int of_gpio_named_count(const struct device_node *np,
- const char *propname)
-{
- return of_count_phandle_with_args(np, propname, "#gpio-cells");
-}
-
static inline int of_get_gpio_flags(const struct device_node *np, int index,
enum of_gpio_flags *flags)
{
--
2.39.0.314.g84b9a713c41-goog

2022-12-19 19:37:13

by Dmitry Torokhov

[permalink] [raw]
Subject: [PATCH 3/5] gpiolib: of: remove obsolete comment for of_gpio_get_count()

The function is only being called form the main gpiolib module, so
remove comment saying that it is also used by external callers.

Signed-off-by: Dmitry Torokhov <[email protected]>
---
drivers/gpio/gpiolib-of.c | 6 ------
1 file changed, 6 deletions(-)

diff --git a/drivers/gpio/gpiolib-of.c b/drivers/gpio/gpiolib-of.c
index 6724e375678d..6114c5b3d2ce 100644
--- a/drivers/gpio/gpiolib-of.c
+++ b/drivers/gpio/gpiolib-of.c
@@ -76,12 +76,6 @@ static int of_gpio_spi_cs_get_count(struct device *dev, const char *con_id)
return of_gpio_named_count(np, "gpios");
}

-/*
- * This is used by external users of of_gpio_count() from <linux/of_gpio.h>
- *
- * FIXME: get rid of those external users by converting them to GPIO
- * descriptors and let them all use gpiod_count()
- */
int of_gpio_get_count(struct device *dev, const char *con_id)
{
int ret;
--
2.39.0.314.g84b9a713c41-goog

2022-12-19 19:37:47

by Dmitry Torokhov

[permalink] [raw]
Subject: [PATCH 4/5] gpiolib: of: remove of_get_gpio[_flags]() and of_get_named_gpio_flags()

There are no more users of these APIs in the mainline kernel, remove
them. This leaves of_get_named_gpio() as the only legacy OF-specific
API.

Signed-off-by: Dmitry Torokhov <[email protected]>
---
drivers/gpio/gpiolib-of.c | 17 +++++++++++----
include/linux/of_gpio.h | 45 ++++-----------------------------------
2 files changed, 17 insertions(+), 45 deletions(-)

diff --git a/drivers/gpio/gpiolib-of.c b/drivers/gpio/gpiolib-of.c
index 6114c5b3d2ce..fdf443310442 100644
--- a/drivers/gpio/gpiolib-of.c
+++ b/drivers/gpio/gpiolib-of.c
@@ -365,19 +365,28 @@ static struct gpio_desc *of_get_named_gpiod_flags(const struct device_node *np,
return desc;
}

-int of_get_named_gpio_flags(const struct device_node *np, const char *list_name,
- int index, enum of_gpio_flags *flags)
+/**
+ * of_get_named_gpio() - Get a GPIO number to use with GPIO API
+ * @np: device node to get GPIO from
+ * @propname: Name of property containing gpio specifier(s)
+ * @index: index of the GPIO
+ *
+ * Returns GPIO number to use with Linux generic GPIO API, or one of the errno
+ * value on the error condition.
+ */
+int of_get_named_gpio(const struct device_node *np, const char *propname,
+ int index)
{
struct gpio_desc *desc;

- desc = of_get_named_gpiod_flags(np, list_name, index, flags);
+ desc = of_get_named_gpiod_flags(np, propname, index, NULL);

if (IS_ERR(desc))
return PTR_ERR(desc);
else
return desc_to_gpio(desc);
}
-EXPORT_SYMBOL_GPL(of_get_named_gpio_flags);
+EXPORT_SYMBOL_GPL(of_get_named_gpio);

/* Converts gpio_lookup_flags into bitmask of GPIO_* values */
static unsigned long of_convert_gpio_flags(enum of_gpio_flags flags)
diff --git a/include/linux/of_gpio.h b/include/linux/of_gpio.h
index 680025c1a55b..e27a9187c0c6 100644
--- a/include/linux/of_gpio.h
+++ b/include/linux/of_gpio.h
@@ -50,8 +50,8 @@ static inline struct of_mm_gpio_chip *to_of_mm_gpio_chip(struct gpio_chip *gc)
return container_of(gc, struct of_mm_gpio_chip, gc);
}

-extern int of_get_named_gpio_flags(const struct device_node *np,
- const char *list_name, int index, enum of_gpio_flags *flags);
+extern int of_get_named_gpio(const struct device_node *np,
+ const char *list_name, int index);

extern int of_mm_gpiochip_add_data(struct device_node *np,
struct of_mm_gpio_chip *mm_gc,
@@ -68,49 +68,12 @@ extern void of_mm_gpiochip_remove(struct of_mm_gpio_chip *mm_gc);
#include <linux/errno.h>

/* Drivers may not strictly depend on the GPIO support, so let them link. */
-static inline int of_get_named_gpio_flags(const struct device_node *np,
- const char *list_name, int index, enum of_gpio_flags *flags)
-{
- if (flags)
- *flags = 0;
-
- return -ENOSYS;
-}
-
-#endif /* CONFIG_OF_GPIO */
-
-static inline int of_get_gpio_flags(const struct device_node *np, int index,
- enum of_gpio_flags *flags)
-{
- return of_get_named_gpio_flags(np, "gpios", index, flags);
-}
-
-/**
- * of_get_named_gpio() - Get a GPIO number to use with GPIO API
- * @np: device node to get GPIO from
- * @propname: Name of property containing gpio specifier(s)
- * @index: index of the GPIO
- *
- * Returns GPIO number to use with Linux generic GPIO API, or one of the errno
- * value on the error condition.
- */
static inline int of_get_named_gpio(const struct device_node *np,
const char *propname, int index)
{
- return of_get_named_gpio_flags(np, propname, index, NULL);
+ return -ENOSYS;
}

-/**
- * of_get_gpio() - Get a GPIO number to use with GPIO API
- * @np: device node to get GPIO from
- * @index: index of the GPIO
- *
- * Returns GPIO number to use with Linux generic GPIO API, or one of the errno
- * value on the error condition.
- */
-static inline int of_get_gpio(const struct device_node *np, int index)
-{
- return of_get_gpio_flags(np, index, NULL);
-}
+#endif /* CONFIG_OF_GPIO */

#endif /* __LINUX_OF_GPIO_H */
--
2.39.0.314.g84b9a713c41-goog

2022-12-19 19:39:13

by Dmitry Torokhov

[permalink] [raw]
Subject: [PATCH 5/5] gpiolib: of: remove [devm_]gpiod_get_from_of_node() APIs

Now that everyone is using [devm_]fwnode_gpiod_get[_index]() APIs,
remove OF-specific [devm_]gpiod_get_from_of_node().

Signed-off-by: Dmitry Torokhov <[email protected]>
---
drivers/gpio/gpiolib-devres.c | 55 -----------------------------------
drivers/gpio/gpiolib-of.c | 46 -----------------------------
include/linux/gpio/consumer.h | 48 ------------------------------
3 files changed, 149 deletions(-)

diff --git a/drivers/gpio/gpiolib-devres.c b/drivers/gpio/gpiolib-devres.c
index 16a696249229..fe9ce6b19f15 100644
--- a/drivers/gpio/gpiolib-devres.c
+++ b/drivers/gpio/gpiolib-devres.c
@@ -129,61 +129,6 @@ struct gpio_desc *__must_check devm_gpiod_get_index(struct device *dev,
}
EXPORT_SYMBOL_GPL(devm_gpiod_get_index);

-/**
- * devm_gpiod_get_from_of_node() - obtain a GPIO from an OF node
- * @dev: device for lifecycle management
- * @node: handle of the OF node
- * @propname: name of the DT 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
- *
- * 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 *devm_gpiod_get_from_of_node(struct device *dev,
- const struct device_node *node,
- const char *propname, int index,
- enum gpiod_flags dflags,
- const char *label)
-{
- struct gpio_desc **dr;
- struct gpio_desc *desc;
-
- desc = gpiod_get_from_of_node(node, propname, index, dflags, label);
- if (IS_ERR(desc))
- return desc;
-
- /*
- * For non-exclusive GPIO descriptors, check if this descriptor is
- * already under resource management by this device.
- */
- if (dflags & GPIOD_FLAGS_BIT_NONEXCLUSIVE) {
- struct devres *dres;
-
- dres = devres_find(dev, devm_gpiod_release,
- devm_gpiod_match, &desc);
- if (dres)
- return desc;
- }
-
- dr = devres_alloc(devm_gpiod_release, sizeof(struct gpio_desc *),
- GFP_KERNEL);
- if (!dr) {
- gpiod_put(desc);
- return ERR_PTR(-ENOMEM);
- }
-
- *dr = desc;
- devres_add(dev, dr);
-
- return desc;
-}
-EXPORT_SYMBOL_GPL(devm_gpiod_get_from_of_node);
-
/**
* devm_fwnode_gpiod_get_index - get a GPIO descriptor from a given node
* @dev: GPIO consumer
diff --git a/drivers/gpio/gpiolib-of.c b/drivers/gpio/gpiolib-of.c
index fdf443310442..4a47e71782f3 100644
--- a/drivers/gpio/gpiolib-of.c
+++ b/drivers/gpio/gpiolib-of.c
@@ -418,52 +418,6 @@ static unsigned long of_convert_gpio_flags(enum of_gpio_flags flags)
return lflags;
}

-/**
- * gpiod_get_from_of_node() - obtain a GPIO from an OF node
- * @node: handle of the OF node
- * @propname: name of the DT 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
- *
- * 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 *gpiod_get_from_of_node(const struct device_node *node,
- const char *propname, int index,
- enum gpiod_flags dflags,
- const char *label)
-{
- unsigned long lflags;
- struct gpio_desc *desc;
- enum of_gpio_flags of_flags;
- int ret;
-
- desc = of_get_named_gpiod_flags(node, propname, index, &of_flags);
- if (!desc || IS_ERR(desc))
- return desc;
-
- ret = gpiod_request(desc, label);
- if (ret == -EBUSY && (dflags & GPIOD_FLAGS_BIT_NONEXCLUSIVE))
- return desc;
- if (ret)
- return ERR_PTR(ret);
-
- lflags = of_convert_gpio_flags(of_flags);
-
- ret = gpiod_configure_flags(desc, propname, lflags, dflags);
- if (ret < 0) {
- gpiod_put(desc);
- return ERR_PTR(ret);
- }
-
- return desc;
-}
-EXPORT_SYMBOL_GPL(gpiod_get_from_of_node);
-
static struct gpio_desc *of_find_gpio_rename(struct device_node *np,
const char *con_id,
unsigned int idx,
diff --git a/include/linux/gpio/consumer.h b/include/linux/gpio/consumer.h
index 45da8f137fe5..59cb20cfac3d 100644
--- a/include/linux/gpio/consumer.h
+++ b/include/linux/gpio/consumer.h
@@ -581,54 +581,6 @@ struct gpio_desc *devm_fwnode_gpiod_get(struct device *dev,
flags, label);
}

-#if IS_ENABLED(CONFIG_GPIOLIB) && IS_ENABLED(CONFIG_OF_GPIO)
-struct device_node;
-
-struct gpio_desc *gpiod_get_from_of_node(const struct device_node *node,
- const char *propname, int index,
- enum gpiod_flags dflags,
- const char *label);
-
-#else /* CONFIG_GPIOLIB && CONFIG_OF_GPIO */
-
-struct device_node;
-
-static inline
-struct gpio_desc *gpiod_get_from_of_node(const struct device_node *node,
- const char *propname, int index,
- enum gpiod_flags dflags,
- const char *label)
-{
- return ERR_PTR(-ENOSYS);
-}
-
-#endif /* CONFIG_GPIOLIB && CONFIG_OF_GPIO */
-
-#ifdef CONFIG_GPIOLIB
-struct device_node;
-
-struct gpio_desc *devm_gpiod_get_from_of_node(struct device *dev,
- const struct device_node *node,
- const char *propname, int index,
- enum gpiod_flags dflags,
- const char *label);
-
-#else /* CONFIG_GPIOLIB */
-
-struct device_node;
-
-static inline
-struct gpio_desc *devm_gpiod_get_from_of_node(struct device *dev,
- const struct device_node *node,
- const char *propname, int index,
- enum gpiod_flags dflags,
- const char *label)
-{
- return ERR_PTR(-ENOSYS);
-}
-
-#endif /* CONFIG_GPIOLIB */
-
struct acpi_gpio_params {
unsigned int crs_entry_index;
unsigned int line_index;
--
2.39.0.314.g84b9a713c41-goog

2022-12-20 14:03:31

by Andy Shevchenko

[permalink] [raw]
Subject: Re: [PATCH 2/5] gpiolib: of: stop exporting of_gpio_named_count()

On Mon, Dec 19, 2022 at 11:20:13AM -0800, Dmitry Torokhov wrote:
> The only user of this function is gpiolib-of.c so move it there.

It's one liner used a single file, can we kill it completely?

--
With Best Regards,
Andy Shevchenko


2022-12-20 14:07:36

by Andy Shevchenko

[permalink] [raw]
Subject: Re: [PATCH 1/5] gpiolib: of: remove of_gpio_count()

On Mon, Dec 19, 2022 at 11:20:12AM -0800, Dmitry Torokhov wrote:
> There are no more users of of_gpio_count() in the mainline kernel,
> remove it.

Reviewed-by: Andy Shevchenko <[email protected]>

> Signed-off-by: Dmitry Torokhov <[email protected]>
> ---
>
> After 6.2-rc1 there should be no more users of the APIs mentioned in
> this series.

I believe you probably want to have this patch applied immediately to the GPIO
subsystem after v6.2-rc1 to avoid new users.

> include/linux/of_gpio.h | 11 -----------
> 1 file changed, 11 deletions(-)
>
> diff --git a/include/linux/of_gpio.h b/include/linux/of_gpio.h
> index 6db627257a7b..39f16a960565 100644
> --- a/include/linux/of_gpio.h
> +++ b/include/linux/of_gpio.h
> @@ -105,17 +105,6 @@ static inline int of_gpio_named_count(const struct device_node *np,
> return of_count_phandle_with_args(np, propname, "#gpio-cells");
> }
>
> -/**
> - * of_gpio_count() - Count GPIOs for a device
> - * @np: device node to count GPIOs for
> - *
> - * Same as of_gpio_named_count, but hard coded to use the 'gpios' property
> - */
> -static inline int of_gpio_count(const struct device_node *np)
> -{
> - return of_gpio_named_count(np, "gpios");
> -}
> -
> static inline int of_get_gpio_flags(const struct device_node *np, int index,
> enum of_gpio_flags *flags)
> {
> --
> 2.39.0.314.g84b9a713c41-goog
>

--
With Best Regards,
Andy Shevchenko


2022-12-20 14:08:32

by Andy Shevchenko

[permalink] [raw]
Subject: Re: [PATCH 4/5] gpiolib: of: remove of_get_gpio[_flags]() and of_get_named_gpio_flags()

On Mon, Dec 19, 2022 at 11:20:15AM -0800, Dmitry Torokhov wrote:
> There are no more users of these APIs in the mainline kernel, remove
> them. This leaves of_get_named_gpio() as the only legacy OF-specific
> API.

...

> - desc = of_get_named_gpiod_flags(np, list_name, index, flags);
> + desc = of_get_named_gpiod_flags(np, propname, index, NULL);

I didn't get it. The commit message and the subject says there are no more
users of these APIs, why is it still here? How is it compiled?

--
With Best Regards,
Andy Shevchenko


2022-12-20 14:08:44

by Andy Shevchenko

[permalink] [raw]
Subject: Re: [PATCH 3/5] gpiolib: of: remove obsolete comment for of_gpio_get_count()

On Mon, Dec 19, 2022 at 11:20:14AM -0800, Dmitry Torokhov wrote:
> The function is only being called form the main gpiolib module, so
> remove comment saying that it is also used by external callers.

Reviewed-by: Andy Shevchenko <[email protected]>

> Signed-off-by: Dmitry Torokhov <[email protected]>
> ---
> drivers/gpio/gpiolib-of.c | 6 ------
> 1 file changed, 6 deletions(-)
>
> diff --git a/drivers/gpio/gpiolib-of.c b/drivers/gpio/gpiolib-of.c
> index 6724e375678d..6114c5b3d2ce 100644
> --- a/drivers/gpio/gpiolib-of.c
> +++ b/drivers/gpio/gpiolib-of.c
> @@ -76,12 +76,6 @@ static int of_gpio_spi_cs_get_count(struct device *dev, const char *con_id)
> return of_gpio_named_count(np, "gpios");
> }
>
> -/*
> - * This is used by external users of of_gpio_count() from <linux/of_gpio.h>
> - *
> - * FIXME: get rid of those external users by converting them to GPIO
> - * descriptors and let them all use gpiod_count()
> - */
> int of_gpio_get_count(struct device *dev, const char *con_id)
> {
> int ret;
> --
> 2.39.0.314.g84b9a713c41-goog
>

--
With Best Regards,
Andy Shevchenko


2022-12-20 14:50:24

by Andy Shevchenko

[permalink] [raw]
Subject: Re: [PATCH 5/5] gpiolib: of: remove [devm_]gpiod_get_from_of_node() APIs

On Mon, Dec 19, 2022 at 11:20:16AM -0800, Dmitry Torokhov wrote:
> Now that everyone is using [devm_]fwnode_gpiod_get[_index]() APIs,
> remove OF-specific [devm_]gpiod_get_from_of_node().

I very much in favour of this change!

Reviewed-by: Andy Shevchenko <[email protected]>

But the same question reminds, how this is possible to exists with the removed
of_get_named_gpiod_flags()?

> Signed-off-by: Dmitry Torokhov <[email protected]>
> ---
> drivers/gpio/gpiolib-devres.c | 55 -----------------------------------
> drivers/gpio/gpiolib-of.c | 46 -----------------------------
> include/linux/gpio/consumer.h | 48 ------------------------------
> 3 files changed, 149 deletions(-)
>
> diff --git a/drivers/gpio/gpiolib-devres.c b/drivers/gpio/gpiolib-devres.c
> index 16a696249229..fe9ce6b19f15 100644
> --- a/drivers/gpio/gpiolib-devres.c
> +++ b/drivers/gpio/gpiolib-devres.c
> @@ -129,61 +129,6 @@ struct gpio_desc *__must_check devm_gpiod_get_index(struct device *dev,
> }
> EXPORT_SYMBOL_GPL(devm_gpiod_get_index);
>
> -/**
> - * devm_gpiod_get_from_of_node() - obtain a GPIO from an OF node
> - * @dev: device for lifecycle management
> - * @node: handle of the OF node
> - * @propname: name of the DT 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
> - *
> - * 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 *devm_gpiod_get_from_of_node(struct device *dev,
> - const struct device_node *node,
> - const char *propname, int index,
> - enum gpiod_flags dflags,
> - const char *label)
> -{
> - struct gpio_desc **dr;
> - struct gpio_desc *desc;
> -
> - desc = gpiod_get_from_of_node(node, propname, index, dflags, label);
> - if (IS_ERR(desc))
> - return desc;
> -
> - /*
> - * For non-exclusive GPIO descriptors, check if this descriptor is
> - * already under resource management by this device.
> - */
> - if (dflags & GPIOD_FLAGS_BIT_NONEXCLUSIVE) {
> - struct devres *dres;
> -
> - dres = devres_find(dev, devm_gpiod_release,
> - devm_gpiod_match, &desc);
> - if (dres)
> - return desc;
> - }
> -
> - dr = devres_alloc(devm_gpiod_release, sizeof(struct gpio_desc *),
> - GFP_KERNEL);
> - if (!dr) {
> - gpiod_put(desc);
> - return ERR_PTR(-ENOMEM);
> - }
> -
> - *dr = desc;
> - devres_add(dev, dr);
> -
> - return desc;
> -}
> -EXPORT_SYMBOL_GPL(devm_gpiod_get_from_of_node);
> -
> /**
> * devm_fwnode_gpiod_get_index - get a GPIO descriptor from a given node
> * @dev: GPIO consumer
> diff --git a/drivers/gpio/gpiolib-of.c b/drivers/gpio/gpiolib-of.c
> index fdf443310442..4a47e71782f3 100644
> --- a/drivers/gpio/gpiolib-of.c
> +++ b/drivers/gpio/gpiolib-of.c
> @@ -418,52 +418,6 @@ static unsigned long of_convert_gpio_flags(enum of_gpio_flags flags)
> return lflags;
> }
>
> -/**
> - * gpiod_get_from_of_node() - obtain a GPIO from an OF node
> - * @node: handle of the OF node
> - * @propname: name of the DT 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
> - *
> - * 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 *gpiod_get_from_of_node(const struct device_node *node,
> - const char *propname, int index,
> - enum gpiod_flags dflags,
> - const char *label)
> -{
> - unsigned long lflags;
> - struct gpio_desc *desc;
> - enum of_gpio_flags of_flags;
> - int ret;
> -
> - desc = of_get_named_gpiod_flags(node, propname, index, &of_flags);
> - if (!desc || IS_ERR(desc))
> - return desc;
> -
> - ret = gpiod_request(desc, label);
> - if (ret == -EBUSY && (dflags & GPIOD_FLAGS_BIT_NONEXCLUSIVE))
> - return desc;
> - if (ret)
> - return ERR_PTR(ret);
> -
> - lflags = of_convert_gpio_flags(of_flags);
> -
> - ret = gpiod_configure_flags(desc, propname, lflags, dflags);
> - if (ret < 0) {
> - gpiod_put(desc);
> - return ERR_PTR(ret);
> - }
> -
> - return desc;
> -}
> -EXPORT_SYMBOL_GPL(gpiod_get_from_of_node);
> -
> static struct gpio_desc *of_find_gpio_rename(struct device_node *np,
> const char *con_id,
> unsigned int idx,
> diff --git a/include/linux/gpio/consumer.h b/include/linux/gpio/consumer.h
> index 45da8f137fe5..59cb20cfac3d 100644
> --- a/include/linux/gpio/consumer.h
> +++ b/include/linux/gpio/consumer.h
> @@ -581,54 +581,6 @@ struct gpio_desc *devm_fwnode_gpiod_get(struct device *dev,
> flags, label);
> }
>
> -#if IS_ENABLED(CONFIG_GPIOLIB) && IS_ENABLED(CONFIG_OF_GPIO)
> -struct device_node;
> -
> -struct gpio_desc *gpiod_get_from_of_node(const struct device_node *node,
> - const char *propname, int index,
> - enum gpiod_flags dflags,
> - const char *label);
> -
> -#else /* CONFIG_GPIOLIB && CONFIG_OF_GPIO */
> -
> -struct device_node;
> -
> -static inline
> -struct gpio_desc *gpiod_get_from_of_node(const struct device_node *node,
> - const char *propname, int index,
> - enum gpiod_flags dflags,
> - const char *label)
> -{
> - return ERR_PTR(-ENOSYS);
> -}
> -
> -#endif /* CONFIG_GPIOLIB && CONFIG_OF_GPIO */
> -
> -#ifdef CONFIG_GPIOLIB
> -struct device_node;
> -
> -struct gpio_desc *devm_gpiod_get_from_of_node(struct device *dev,
> - const struct device_node *node,
> - const char *propname, int index,
> - enum gpiod_flags dflags,
> - const char *label);
> -
> -#else /* CONFIG_GPIOLIB */
> -
> -struct device_node;
> -
> -static inline
> -struct gpio_desc *devm_gpiod_get_from_of_node(struct device *dev,
> - const struct device_node *node,
> - const char *propname, int index,
> - enum gpiod_flags dflags,
> - const char *label)
> -{
> - return ERR_PTR(-ENOSYS);
> -}
> -
> -#endif /* CONFIG_GPIOLIB */
> -
> struct acpi_gpio_params {
> unsigned int crs_entry_index;
> unsigned int line_index;
> --
> 2.39.0.314.g84b9a713c41-goog
>

--
With Best Regards,
Andy Shevchenko


2022-12-20 18:48:51

by Dmitry Torokhov

[permalink] [raw]
Subject: Re: [PATCH 2/5] gpiolib: of: stop exporting of_gpio_named_count()

On Tue, Dec 20, 2022 at 03:50:40PM +0200, Andy Shevchenko wrote:
> On Mon, Dec 19, 2022 at 11:20:13AM -0800, Dmitry Torokhov wrote:
> > The only user of this function is gpiolib-of.c so move it there.
>
> It's one liner used a single file, can we kill it completely?

It is being called from a couple of places there and documents how
exactly we are counting GPIOs, so I would prefer to leave this helper as
is.

Thanks.

--
Dmitry

2022-12-20 18:48:52

by Dmitry Torokhov

[permalink] [raw]
Subject: Re: [PATCH 5/5] gpiolib: of: remove [devm_]gpiod_get_from_of_node() APIs

On Tue, Dec 20, 2022 at 04:01:08PM +0200, Andy Shevchenko wrote:
> On Mon, Dec 19, 2022 at 11:20:16AM -0800, Dmitry Torokhov wrote:
> > Now that everyone is using [devm_]fwnode_gpiod_get[_index]() APIs,
> > remove OF-specific [devm_]gpiod_get_from_of_node().
>
> I very much in favour of this change!
>
> Reviewed-by: Andy Shevchenko <[email protected]>
>
> But the same question reminds, how this is possible to exists with the removed
> of_get_named_gpiod_flags()?

As I mentioned in the other email of_get_named_gpiod_flags() is still
present, it is of_get_named_gpio_flags (without the "d") that was
removed.

Thanks.

--
Dmitry

2022-12-20 18:51:16

by Dmitry Torokhov

[permalink] [raw]
Subject: Re: [PATCH 4/5] gpiolib: of: remove of_get_gpio[_flags]() and of_get_named_gpio_flags()

On Tue, Dec 20, 2022 at 03:58:11PM +0200, Andy Shevchenko wrote:
> On Mon, Dec 19, 2022 at 11:20:15AM -0800, Dmitry Torokhov wrote:
> > There are no more users of these APIs in the mainline kernel, remove
> > them. This leaves of_get_named_gpio() as the only legacy OF-specific
> > API.
>
> ...
>
> > - desc = of_get_named_gpiod_flags(np, list_name, index, flags);
> > + desc = of_get_named_gpiod_flags(np, propname, index, NULL);
>
> I didn't get it. The commit message and the subject says there are no more
> users of these APIs, why is it still here? How is it compiled?

gpio vs gpiod strikes again ;) We are removing
of_get_named_gpio_flags(), but of_get_named_gpiod_flags() is a local
helper in gpiolib-of.c and is still very much in use there and I have no
plans removing it.

Thanks.

--
Dmitry

2022-12-20 18:57:59

by Dmitry Torokhov

[permalink] [raw]
Subject: Re: [PATCH 1/5] gpiolib: of: remove of_gpio_count()

On Tue, Dec 20, 2022 at 03:51:43PM +0200, Andy Shevchenko wrote:
> On Mon, Dec 19, 2022 at 11:20:12AM -0800, Dmitry Torokhov wrote:
> > There are no more users of of_gpio_count() in the mainline kernel,
> > remove it.
>
> Reviewed-by: Andy Shevchenko <[email protected]>
>
> > Signed-off-by: Dmitry Torokhov <[email protected]>
> > ---
> >
> > After 6.2-rc1 there should be no more users of the APIs mentioned in
> > this series.
>
> I believe you probably want to have this patch applied immediately to the GPIO
> subsystem after v6.2-rc1 to avoid new users.

Thanks for the reviews Andy.

I think Linus pulled all the changes removing these all APIs into
mainline, so it is possible to get it into 6.2 right away. Since
everything is supposed to go through 'next' we will probably catch new
users regardless, but I indeed would not mind having this in 6.2 and not
wait for 6.3.

Thanks.

--
Dmitry

2022-12-20 19:41:08

by Andy Shevchenko

[permalink] [raw]
Subject: Re: [PATCH 2/5] gpiolib: of: stop exporting of_gpio_named_count()

On Tue, Dec 20, 2022 at 10:27:28AM -0800, Dmitry Torokhov wrote:
> On Tue, Dec 20, 2022 at 03:50:40PM +0200, Andy Shevchenko wrote:
> > On Mon, Dec 19, 2022 at 11:20:13AM -0800, Dmitry Torokhov wrote:
> > > The only user of this function is gpiolib-of.c so move it there.
> >
> > It's one liner used a single file, can we kill it completely?
>
> It is being called from a couple of places there and documents how
> exactly we are counting GPIOs, so I would prefer to leave this helper as
> is.

Fair enough. However I think that even so it may be killed in the future.

Reviewed-by: Andy Shevchenko <[email protected]>

--
With Best Regards,
Andy Shevchenko


2022-12-20 20:14:10

by Andy Shevchenko

[permalink] [raw]
Subject: Re: [PATCH 4/5] gpiolib: of: remove of_get_gpio[_flags]() and of_get_named_gpio_flags()

On Tue, Dec 20, 2022 at 10:29:06AM -0800, Dmitry Torokhov wrote:
> On Tue, Dec 20, 2022 at 03:58:11PM +0200, Andy Shevchenko wrote:
> > On Mon, Dec 19, 2022 at 11:20:15AM -0800, Dmitry Torokhov wrote:
> > > There are no more users of these APIs in the mainline kernel, remove
> > > them. This leaves of_get_named_gpio() as the only legacy OF-specific
> > > API.

...

> > > - desc = of_get_named_gpiod_flags(np, list_name, index, flags);
> > > + desc = of_get_named_gpiod_flags(np, propname, index, NULL);
> >
> > I didn't get it. The commit message and the subject says there are no more
> > users of these APIs, why is it still here? How is it compiled?
>
> gpio vs gpiod strikes again ;) We are removing
> of_get_named_gpio_flags(), but of_get_named_gpiod_flags() is a local
> helper in gpiolib-of.c and is still very much in use there and I have no
> plans removing it.

Right, thank you for clarification.
Reviewed-by: Andy Shevchenko <[email protected]>

--
With Best Regards,
Andy Shevchenko


2022-12-30 16:03:44

by Bartosz Golaszewski

[permalink] [raw]
Subject: Re: [PATCH 1/5] gpiolib: of: remove of_gpio_count()

On Mon, Dec 19, 2022 at 8:20 PM Dmitry Torokhov
<[email protected]> wrote:
>
> There are no more users of of_gpio_count() in the mainline kernel,
> remove it.
>
> Signed-off-by: Dmitry Torokhov <[email protected]>
> ---
>
> After 6.2-rc1 there should be no more users of the APIs mentioned in
> this series.
>
> include/linux/of_gpio.h | 11 -----------
> 1 file changed, 11 deletions(-)
>
> diff --git a/include/linux/of_gpio.h b/include/linux/of_gpio.h
> index 6db627257a7b..39f16a960565 100644
> --- a/include/linux/of_gpio.h
> +++ b/include/linux/of_gpio.h
> @@ -105,17 +105,6 @@ static inline int of_gpio_named_count(const struct device_node *np,
> return of_count_phandle_with_args(np, propname, "#gpio-cells");
> }
>
> -/**
> - * of_gpio_count() - Count GPIOs for a device
> - * @np: device node to count GPIOs for
> - *
> - * Same as of_gpio_named_count, but hard coded to use the 'gpios' property
> - */
> -static inline int of_gpio_count(const struct device_node *np)
> -{
> - return of_gpio_named_count(np, "gpios");
> -}
> -
> static inline int of_get_gpio_flags(const struct device_node *np, int index,
> enum of_gpio_flags *flags)
> {
> --
> 2.39.0.314.g84b9a713c41-goog
>

I applied the entire series, thanks a lot for doing that!

Bart

2023-01-09 13:51:36

by Linus Walleij

[permalink] [raw]
Subject: Re: [PATCH 3/5] gpiolib: of: remove obsolete comment for of_gpio_get_count()

On Mon, Dec 19, 2022 at 8:20 PM Dmitry Torokhov
<[email protected]> wrote:

> The function is only being called form the main gpiolib module, so
> remove comment saying that it is also used by external callers.
>
> Signed-off-by: Dmitry Torokhov <[email protected]>

Reviewed-by: Linus Walleij <[email protected]>

BTW: good work on this, much appreciated!

Yours,
Linus Walleij