* [PATCH 0/2] leds: gpio: Add devlink between the leds-gpio device and the gpio used.
@ 2024-02-20 11:11 Herve Codina
2024-02-20 11:11 ` [PATCH 1/2] gpiolib: Introduce gpiod_device_add_link() Herve Codina
` (2 more replies)
0 siblings, 3 replies; 8+ messages in thread
From: Herve Codina @ 2024-02-20 11:11 UTC (permalink / raw)
To: Linus Walleij, Bartosz Golaszewski, Pavel Machek, Lee Jones
Cc: linux-gpio, linux-kernel, linux-leds, Luca Ceresoli,
Thomas Petazzoni, Herve Codina
Hi,
When a gpio used by the leds-gpio device is removed, the leds-gpio
device continues to use this gpio. Also, when the gpio is back, the
leds-gpio still uses the old removed gpio.
A consumer/supplier relationship is missing between the leds-gpio device
(consumer) and the gpio used (supplier).
This series adds an addionnal devlink between this two device.
With this link when the gpio is removed, the leds-gpio device is also
removed.
Best regards,
Hervé Codina
Herve Codina (2):
gpiolib: Introduce gpiod_device_add_link()
leds: gpio: Add devlinks between the gpio consumed and the gpio leds
device
drivers/gpio/gpiolib.c | 32 ++++++++++++++++++++++++++++++++
drivers/leds/leds-gpio.c | 15 +++++++++++++++
include/linux/gpio/consumer.h | 5 +++++
3 files changed, 52 insertions(+)
--
2.43.0
^ permalink raw reply [flat|nested] 8+ messages in thread
* [PATCH 1/2] gpiolib: Introduce gpiod_device_add_link()
2024-02-20 11:11 [PATCH 0/2] leds: gpio: Add devlink between the leds-gpio device and the gpio used Herve Codina
@ 2024-02-20 11:11 ` Herve Codina
2024-02-21 22:44 ` Linus Walleij
2024-02-20 11:11 ` [PATCH 2/2] leds: gpio: Add devlinks between the gpio consumed and the gpio leds device Herve Codina
2024-02-20 11:40 ` [PATCH 0/2] leds: gpio: Add devlink between the leds-gpio device and the gpio used Bartosz Golaszewski
2 siblings, 1 reply; 8+ messages in thread
From: Herve Codina @ 2024-02-20 11:11 UTC (permalink / raw)
To: Linus Walleij, Bartosz Golaszewski, Pavel Machek, Lee Jones
Cc: linux-gpio, linux-kernel, linux-leds, Luca Ceresoli,
Thomas Petazzoni, Herve Codina
With device-tree, some devlink related to gpios are automatically added
when a consumer device is added and the attached node has phandles
related to GPIOs.
In some cases, the real device used to get the gpio during a probe() can
be related to an of-node parent of the of-node used for the already done
automatically devlink creation.
For instance, a driver can be bound to a device and, during the
probe(), the driver can walk its of-node children to get the GPIO
described in these children nodes.
In that case, an additional devlink between the device attached to the
driver and the gpio consumer need to be created.
Indeed, if the GPIO is removed, the consumer/supplier dependency should
lead to remove first the consuming driver before removing the supplier.
In order to give the possibility to this kind of driver to add additional
devlinks, introduce gpiod_device_add_link().
Signed-off-by: Herve Codina <herve.codina@bootlin.com>
---
drivers/gpio/gpiolib.c | 32 ++++++++++++++++++++++++++++++++
include/linux/gpio/consumer.h | 5 +++++
2 files changed, 37 insertions(+)
diff --git a/drivers/gpio/gpiolib.c b/drivers/gpio/gpiolib.c
index 8b3a0f45b574..416ab334b02d 100644
--- a/drivers/gpio/gpiolib.c
+++ b/drivers/gpio/gpiolib.c
@@ -4195,6 +4195,38 @@ static struct gpio_desc *gpiod_find_and_request(struct device *consumer,
return desc;
}
+/**
+ * gpiod_device_add_link - Add a link between a GPIO consumer and a GPIO.
+ * @consumer: GPIO consumer.
+ * @desc: GPIO consumed.
+ * @flags: Link flags, see device_link_add().
+ *
+ * This function can be used for drivers that need to add an additional
+ * consumer/supplier device link to a GPIO.
+ *
+ * Returns:
+ * On successful, the link created.
+ * NULL if the link was not created due to a missing GPIO parent.
+ *
+ * In case of error an ERR_PTR() is returned.
+ */
+struct device_link *gpiod_device_add_link(struct device *consumer,
+ struct gpio_desc *desc,
+ u32 flags)
+{
+ struct device_link *link;
+
+ if (!desc->gdev->dev.parent)
+ return NULL;
+
+ link = device_link_add(consumer, desc->gdev->dev.parent, flags);
+ if (!link)
+ return ERR_PTR(-EINVAL);
+
+ return link;
+}
+EXPORT_SYMBOL_GPL(gpiod_device_add_link);
+
/**
* fwnode_gpiod_get_index - obtain a GPIO from firmware node
* @fwnode: handle of the firmware node
diff --git a/include/linux/gpio/consumer.h b/include/linux/gpio/consumer.h
index db2dfbae8edb..4feed4e166b0 100644
--- a/include/linux/gpio/consumer.h
+++ b/include/linux/gpio/consumer.h
@@ -7,6 +7,7 @@
struct acpi_device;
struct device;
+struct device_link;
struct fwnode_handle;
struct gpio_array;
@@ -106,6 +107,10 @@ void devm_gpiod_put(struct device *dev, struct gpio_desc *desc);
void devm_gpiod_unhinge(struct device *dev, struct gpio_desc *desc);
void devm_gpiod_put_array(struct device *dev, struct gpio_descs *descs);
+struct device_link *gpiod_device_add_link(struct device *consumer,
+ struct gpio_desc *desc,
+ u32 flags);
+
int gpiod_get_direction(struct gpio_desc *desc);
int gpiod_direction_input(struct gpio_desc *desc);
int gpiod_direction_output(struct gpio_desc *desc, int value);
--
2.43.0
^ permalink raw reply related [flat|nested] 8+ messages in thread
* [PATCH 2/2] leds: gpio: Add devlinks between the gpio consumed and the gpio leds device
2024-02-20 11:11 [PATCH 0/2] leds: gpio: Add devlink between the leds-gpio device and the gpio used Herve Codina
2024-02-20 11:11 ` [PATCH 1/2] gpiolib: Introduce gpiod_device_add_link() Herve Codina
@ 2024-02-20 11:11 ` Herve Codina
2024-02-21 22:45 ` Linus Walleij
2024-02-20 11:40 ` [PATCH 0/2] leds: gpio: Add devlink between the leds-gpio device and the gpio used Bartosz Golaszewski
2 siblings, 1 reply; 8+ messages in thread
From: Herve Codina @ 2024-02-20 11:11 UTC (permalink / raw)
To: Linus Walleij, Bartosz Golaszewski, Pavel Machek, Lee Jones
Cc: linux-gpio, linux-kernel, linux-leds, Luca Ceresoli,
Thomas Petazzoni, Herve Codina
When a gpio is removed, the gpio leds consumer need to be removed first.
This dependency consumer/supplier can be described by devlink links.
In case of device-tree, even if some devlinks are created due to the
presence of gpio phandles in the gpio leds children, these links do not
help in removing the gpio leds device (i.e. the real consumer) before
the consumed gpio.
We can reach cases where the gpio are no more present and the gpio leds
driver continue to have leds using these gpio.
Further more, when the gpio come back, the gpio leds still use the old
removed one.
Indeed, the gpio are consumed by the parent of the consumer used in the
devlink creation due to phandles. A link is missing between the gpio and
the real gpio consumer, the gpio leds device itself.
Use the newly introduced gpiod_device_add_link() to create this
missing link between the gpio leds devices and the gpios.
With that done, if a gpio is removed, the gpio leds is removed and the
resources are correctly released.
Signed-off-by: Herve Codina <herve.codina@bootlin.com>
---
drivers/leds/leds-gpio.c | 15 +++++++++++++++
1 file changed, 15 insertions(+)
diff --git a/drivers/leds/leds-gpio.c b/drivers/leds/leds-gpio.c
index 83fcd7b6afff..b3ec8ecbe5da 100644
--- a/drivers/leds/leds-gpio.c
+++ b/drivers/leds/leds-gpio.c
@@ -150,6 +150,7 @@ static struct gpio_leds_priv *gpio_leds_create(struct device *dev)
{
struct fwnode_handle *child;
struct gpio_leds_priv *priv;
+ struct device_link *link;
int count, ret;
count = device_get_child_node_count(dev);
@@ -197,6 +198,20 @@ static struct gpio_leds_priv *gpio_leds_create(struct device *dev)
/* Set gpiod label to match the corresponding LED name. */
gpiod_set_consumer_name(led_dat->gpiod,
led_dat->cdev.dev->kobj.name);
+
+ /*
+ * Create a link between the GPIO and the gpio-leds device.
+ * This allow to have a relationship between the gpio used and
+ * the gpio-leds device in order to automatically remove the
+ * gpio-leds device (consumer) when a GPIO (supplier) is removed.
+ */
+ link = gpiod_device_add_link(dev, led_dat->gpiod,
+ DL_FLAG_AUTOREMOVE_CONSUMER);
+ if (IS_ERR(link)) {
+ fwnode_handle_put(child);
+ return ERR_CAST(link);
+ }
+
priv->num_leds++;
}
--
2.43.0
^ permalink raw reply related [flat|nested] 8+ messages in thread
* Re: [PATCH 0/2] leds: gpio: Add devlink between the leds-gpio device and the gpio used.
2024-02-20 11:11 [PATCH 0/2] leds: gpio: Add devlink between the leds-gpio device and the gpio used Herve Codina
2024-02-20 11:11 ` [PATCH 1/2] gpiolib: Introduce gpiod_device_add_link() Herve Codina
2024-02-20 11:11 ` [PATCH 2/2] leds: gpio: Add devlinks between the gpio consumed and the gpio leds device Herve Codina
@ 2024-02-20 11:40 ` Bartosz Golaszewski
2024-02-20 13:36 ` Herve Codina
2 siblings, 1 reply; 8+ messages in thread
From: Bartosz Golaszewski @ 2024-02-20 11:40 UTC (permalink / raw)
To: Herve Codina, Saravana Kannan
Cc: Linus Walleij, Pavel Machek, Lee Jones, linux-gpio, linux-kernel,
linux-leds, Luca Ceresoli, Thomas Petazzoni
On Tue, Feb 20, 2024 at 12:11 PM Herve Codina <herve.codina@bootlin.com> wrote:
>
> Hi,
>
> When a gpio used by the leds-gpio device is removed, the leds-gpio
> device continues to use this gpio. Also, when the gpio is back, the
> leds-gpio still uses the old removed gpio.
>
> A consumer/supplier relationship is missing between the leds-gpio device
> (consumer) and the gpio used (supplier).
>
> This series adds an addionnal devlink between this two device.
> With this link when the gpio is removed, the leds-gpio device is also
> removed.
>
> Best regards,
> Hervé Codina
>
> Herve Codina (2):
> gpiolib: Introduce gpiod_device_add_link()
> leds: gpio: Add devlinks between the gpio consumed and the gpio leds
> device
>
> drivers/gpio/gpiolib.c | 32 ++++++++++++++++++++++++++++++++
> drivers/leds/leds-gpio.c | 15 +++++++++++++++
> include/linux/gpio/consumer.h | 5 +++++
> 3 files changed, 52 insertions(+)
>
> --
> 2.43.0
>
You should probably Cc Saravana on anything devlink related.
Bart
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: [PATCH 0/2] leds: gpio: Add devlink between the leds-gpio device and the gpio used.
2024-02-20 11:40 ` [PATCH 0/2] leds: gpio: Add devlink between the leds-gpio device and the gpio used Bartosz Golaszewski
@ 2024-02-20 13:36 ` Herve Codina
0 siblings, 0 replies; 8+ messages in thread
From: Herve Codina @ 2024-02-20 13:36 UTC (permalink / raw)
To: Bartosz Golaszewski
Cc: Saravana Kannan, Linus Walleij, Pavel Machek, Lee Jones,
linux-gpio, linux-kernel, linux-leds, Luca Ceresoli,
Thomas Petazzoni
Hi Bartosz,
On Tue, 20 Feb 2024 12:40:17 +0100
Bartosz Golaszewski <brgl@bgdev.pl> wrote:
> On Tue, Feb 20, 2024 at 12:11 PM Herve Codina <herve.codina@bootlin.com> wrote:
> >
> > Hi,
> >
> > When a gpio used by the leds-gpio device is removed, the leds-gpio
> > device continues to use this gpio. Also, when the gpio is back, the
> > leds-gpio still uses the old removed gpio.
> >
> > A consumer/supplier relationship is missing between the leds-gpio device
> > (consumer) and the gpio used (supplier).
> >
> > This series adds an addionnal devlink between this two device.
> > With this link when the gpio is removed, the leds-gpio device is also
> > removed.
> >
> > Best regards,
> > Hervé Codina
> >
> > Herve Codina (2):
> > gpiolib: Introduce gpiod_device_add_link()
> > leds: gpio: Add devlinks between the gpio consumed and the gpio leds
> > device
> >
> > drivers/gpio/gpiolib.c | 32 ++++++++++++++++++++++++++++++++
> > drivers/leds/leds-gpio.c | 15 +++++++++++++++
> > include/linux/gpio/consumer.h | 5 +++++
> > 3 files changed, 52 insertions(+)
> >
> > --
> > 2.43.0
> >
>
> You should probably Cc Saravana on anything devlink related.
>
Sure, I am going to resend the whole series adding Saravana.
Regards,
Hervé
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: [PATCH 1/2] gpiolib: Introduce gpiod_device_add_link()
2024-02-20 11:11 ` [PATCH 1/2] gpiolib: Introduce gpiod_device_add_link() Herve Codina
@ 2024-02-21 22:44 ` Linus Walleij
2024-02-21 22:58 ` Saravana Kannan
0 siblings, 1 reply; 8+ messages in thread
From: Linus Walleij @ 2024-02-21 22:44 UTC (permalink / raw)
To: Herve Codina, Saravana Kannan
Cc: Bartosz Golaszewski, Pavel Machek, Lee Jones, linux-gpio,
linux-kernel, linux-leds, Luca Ceresoli, Thomas Petazzoni
Looping in Saravana, he should always look at patches like this.
On Tue, Feb 20, 2024 at 12:11 PM Herve Codina <herve.codina@bootlin.com> wrote:
>
> With device-tree, some devlink related to gpios are automatically added
> when a consumer device is added and the attached node has phandles
> related to GPIOs.
> In some cases, the real device used to get the gpio during a probe() can
> be related to an of-node parent of the of-node used for the already done
> automatically devlink creation.
> For instance, a driver can be bound to a device and, during the
> probe(), the driver can walk its of-node children to get the GPIO
> described in these children nodes.
> In that case, an additional devlink between the device attached to the
> driver and the gpio consumer need to be created.
> Indeed, if the GPIO is removed, the consumer/supplier dependency should
> lead to remove first the consuming driver before removing the supplier.
>
> In order to give the possibility to this kind of driver to add additional
> devlinks, introduce gpiod_device_add_link().
>
> Signed-off-by: Herve Codina <herve.codina@bootlin.com>
> ---
> drivers/gpio/gpiolib.c | 32 ++++++++++++++++++++++++++++++++
> include/linux/gpio/consumer.h | 5 +++++
> 2 files changed, 37 insertions(+)
>
> diff --git a/drivers/gpio/gpiolib.c b/drivers/gpio/gpiolib.c
> index 8b3a0f45b574..416ab334b02d 100644
> --- a/drivers/gpio/gpiolib.c
> +++ b/drivers/gpio/gpiolib.c
> @@ -4195,6 +4195,38 @@ static struct gpio_desc *gpiod_find_and_request(struct device *consumer,
> return desc;
> }
>
> +/**
> + * gpiod_device_add_link - Add a link between a GPIO consumer and a GPIO.
> + * @consumer: GPIO consumer.
> + * @desc: GPIO consumed.
> + * @flags: Link flags, see device_link_add().
> + *
> + * This function can be used for drivers that need to add an additional
> + * consumer/supplier device link to a GPIO.
> + *
> + * Returns:
> + * On successful, the link created.
> + * NULL if the link was not created due to a missing GPIO parent.
> + *
> + * In case of error an ERR_PTR() is returned.
> + */
> +struct device_link *gpiod_device_add_link(struct device *consumer,
> + struct gpio_desc *desc,
> + u32 flags)
> +{
> + struct device_link *link;
> +
> + if (!desc->gdev->dev.parent)
> + return NULL;
> +
> + link = device_link_add(consumer, desc->gdev->dev.parent, flags);
> + if (!link)
> + return ERR_PTR(-EINVAL);
> +
> + return link;
> +}
> +EXPORT_SYMBOL_GPL(gpiod_device_add_link);
> +
> /**
> * fwnode_gpiod_get_index - obtain a GPIO from firmware node
> * @fwnode: handle of the firmware node
> diff --git a/include/linux/gpio/consumer.h b/include/linux/gpio/consumer.h
> index db2dfbae8edb..4feed4e166b0 100644
> --- a/include/linux/gpio/consumer.h
> +++ b/include/linux/gpio/consumer.h
> @@ -7,6 +7,7 @@
>
> struct acpi_device;
> struct device;
> +struct device_link;
> struct fwnode_handle;
>
> struct gpio_array;
> @@ -106,6 +107,10 @@ void devm_gpiod_put(struct device *dev, struct gpio_desc *desc);
> void devm_gpiod_unhinge(struct device *dev, struct gpio_desc *desc);
> void devm_gpiod_put_array(struct device *dev, struct gpio_descs *descs);
>
> +struct device_link *gpiod_device_add_link(struct device *consumer,
> + struct gpio_desc *desc,
> + u32 flags);
> +
> int gpiod_get_direction(struct gpio_desc *desc);
> int gpiod_direction_input(struct gpio_desc *desc);
> int gpiod_direction_output(struct gpio_desc *desc, int value);
The function as such is pretty straight forward, but the cross call
here happens on instatiated
devices etc, and we need to know why this can't be done earlier when sorting out
the dependencies in the device tree e.g.
Yours,
Linus Walleij
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: [PATCH 2/2] leds: gpio: Add devlinks between the gpio consumed and the gpio leds device
2024-02-20 11:11 ` [PATCH 2/2] leds: gpio: Add devlinks between the gpio consumed and the gpio leds device Herve Codina
@ 2024-02-21 22:45 ` Linus Walleij
0 siblings, 0 replies; 8+ messages in thread
From: Linus Walleij @ 2024-02-21 22:45 UTC (permalink / raw)
To: Herve Codina, Saravana Kannan
Cc: Bartosz Golaszewski, Pavel Machek, Lee Jones, linux-gpio,
linux-kernel, linux-leds, Luca Ceresoli, Thomas Petazzoni
Saravana needs to look at this patch too, so I am top-posting.
Yours,
Linus Walleij
On Tue, Feb 20, 2024 at 12:11 PM Herve Codina <herve.codina@bootlin.com> wrote:
> When a gpio is removed, the gpio leds consumer need to be removed first.
> This dependency consumer/supplier can be described by devlink links.
> In case of device-tree, even if some devlinks are created due to the
> presence of gpio phandles in the gpio leds children, these links do not
> help in removing the gpio leds device (i.e. the real consumer) before
> the consumed gpio.
> We can reach cases where the gpio are no more present and the gpio leds
> driver continue to have leds using these gpio.
> Further more, when the gpio come back, the gpio leds still use the old
> removed one.
>
> Indeed, the gpio are consumed by the parent of the consumer used in the
> devlink creation due to phandles. A link is missing between the gpio and
> the real gpio consumer, the gpio leds device itself.
>
> Use the newly introduced gpiod_device_add_link() to create this
> missing link between the gpio leds devices and the gpios.
> With that done, if a gpio is removed, the gpio leds is removed and the
> resources are correctly released.
>
> Signed-off-by: Herve Codina <herve.codina@bootlin.com>
> ---
> drivers/leds/leds-gpio.c | 15 +++++++++++++++
> 1 file changed, 15 insertions(+)
>
> diff --git a/drivers/leds/leds-gpio.c b/drivers/leds/leds-gpio.c
> index 83fcd7b6afff..b3ec8ecbe5da 100644
> --- a/drivers/leds/leds-gpio.c
> +++ b/drivers/leds/leds-gpio.c
> @@ -150,6 +150,7 @@ static struct gpio_leds_priv *gpio_leds_create(struct device *dev)
> {
> struct fwnode_handle *child;
> struct gpio_leds_priv *priv;
> + struct device_link *link;
> int count, ret;
>
> count = device_get_child_node_count(dev);
> @@ -197,6 +198,20 @@ static struct gpio_leds_priv *gpio_leds_create(struct device *dev)
> /* Set gpiod label to match the corresponding LED name. */
> gpiod_set_consumer_name(led_dat->gpiod,
> led_dat->cdev.dev->kobj.name);
> +
> + /*
> + * Create a link between the GPIO and the gpio-leds device.
> + * This allow to have a relationship between the gpio used and
> + * the gpio-leds device in order to automatically remove the
> + * gpio-leds device (consumer) when a GPIO (supplier) is removed.
> + */
> + link = gpiod_device_add_link(dev, led_dat->gpiod,
> + DL_FLAG_AUTOREMOVE_CONSUMER);
> + if (IS_ERR(link)) {
> + fwnode_handle_put(child);
> + return ERR_CAST(link);
> + }
> +
> priv->num_leds++;
> }
>
> --
> 2.43.0
>
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: [PATCH 1/2] gpiolib: Introduce gpiod_device_add_link()
2024-02-21 22:44 ` Linus Walleij
@ 2024-02-21 22:58 ` Saravana Kannan
0 siblings, 0 replies; 8+ messages in thread
From: Saravana Kannan @ 2024-02-21 22:58 UTC (permalink / raw)
To: Linus Walleij
Cc: Herve Codina, Bartosz Golaszewski, Pavel Machek, Lee Jones,
linux-gpio, linux-kernel, linux-leds, Luca Ceresoli,
Thomas Petazzoni
On Wed, Feb 21, 2024 at 2:44 PM Linus Walleij <linus.walleij@linaro.org> wrote:
>
> Looping in Saravana, he should always look at patches like this.
Thanks Linus. Bartosz suggested a RESEND with me and I replied in that thread.
https://lore.kernel.org/all/20240220133950.138452-1-herve.codina@bootlin.com/
-Saravana
>
> On Tue, Feb 20, 2024 at 12:11 PM Herve Codina <herve.codina@bootlin.com> wrote:
> >
> > With device-tree, some devlink related to gpios are automatically added
> > when a consumer device is added and the attached node has phandles
> > related to GPIOs.
> > In some cases, the real device used to get the gpio during a probe() can
> > be related to an of-node parent of the of-node used for the already done
> > automatically devlink creation.
> > For instance, a driver can be bound to a device and, during the
> > probe(), the driver can walk its of-node children to get the GPIO
> > described in these children nodes.
> > In that case, an additional devlink between the device attached to the
> > driver and the gpio consumer need to be created.
> > Indeed, if the GPIO is removed, the consumer/supplier dependency should
> > lead to remove first the consuming driver before removing the supplier.
> >
> > In order to give the possibility to this kind of driver to add additional
> > devlinks, introduce gpiod_device_add_link().
> >
> > Signed-off-by: Herve Codina <herve.codina@bootlin.com>
> > ---
> > drivers/gpio/gpiolib.c | 32 ++++++++++++++++++++++++++++++++
> > include/linux/gpio/consumer.h | 5 +++++
> > 2 files changed, 37 insertions(+)
> >
> > diff --git a/drivers/gpio/gpiolib.c b/drivers/gpio/gpiolib.c
> > index 8b3a0f45b574..416ab334b02d 100644
> > --- a/drivers/gpio/gpiolib.c
> > +++ b/drivers/gpio/gpiolib.c
> > @@ -4195,6 +4195,38 @@ static struct gpio_desc *gpiod_find_and_request(struct device *consumer,
> > return desc;
> > }
> >
> > +/**
> > + * gpiod_device_add_link - Add a link between a GPIO consumer and a GPIO.
> > + * @consumer: GPIO consumer.
> > + * @desc: GPIO consumed.
> > + * @flags: Link flags, see device_link_add().
> > + *
> > + * This function can be used for drivers that need to add an additional
> > + * consumer/supplier device link to a GPIO.
> > + *
> > + * Returns:
> > + * On successful, the link created.
> > + * NULL if the link was not created due to a missing GPIO parent.
> > + *
> > + * In case of error an ERR_PTR() is returned.
> > + */
> > +struct device_link *gpiod_device_add_link(struct device *consumer,
> > + struct gpio_desc *desc,
> > + u32 flags)
> > +{
> > + struct device_link *link;
> > +
> > + if (!desc->gdev->dev.parent)
> > + return NULL;
> > +
> > + link = device_link_add(consumer, desc->gdev->dev.parent, flags);
> > + if (!link)
> > + return ERR_PTR(-EINVAL);
> > +
> > + return link;
> > +}
> > +EXPORT_SYMBOL_GPL(gpiod_device_add_link);
> > +
> > /**
> > * fwnode_gpiod_get_index - obtain a GPIO from firmware node
> > * @fwnode: handle of the firmware node
> > diff --git a/include/linux/gpio/consumer.h b/include/linux/gpio/consumer.h
> > index db2dfbae8edb..4feed4e166b0 100644
> > --- a/include/linux/gpio/consumer.h
> > +++ b/include/linux/gpio/consumer.h
> > @@ -7,6 +7,7 @@
> >
> > struct acpi_device;
> > struct device;
> > +struct device_link;
> > struct fwnode_handle;
> >
> > struct gpio_array;
> > @@ -106,6 +107,10 @@ void devm_gpiod_put(struct device *dev, struct gpio_desc *desc);
> > void devm_gpiod_unhinge(struct device *dev, struct gpio_desc *desc);
> > void devm_gpiod_put_array(struct device *dev, struct gpio_descs *descs);
> >
> > +struct device_link *gpiod_device_add_link(struct device *consumer,
> > + struct gpio_desc *desc,
> > + u32 flags);
> > +
> > int gpiod_get_direction(struct gpio_desc *desc);
> > int gpiod_direction_input(struct gpio_desc *desc);
> > int gpiod_direction_output(struct gpio_desc *desc, int value);
>
> The function as such is pretty straight forward, but the cross call
> here happens on instatiated
> devices etc, and we need to know why this can't be done earlier when sorting out
> the dependencies in the device tree e.g.
>
> Yours,
> Linus Walleij
^ permalink raw reply [flat|nested] 8+ messages in thread
end of thread, other threads:[~2024-02-21 22:59 UTC | newest]
Thread overview: 8+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2024-02-20 11:11 [PATCH 0/2] leds: gpio: Add devlink between the leds-gpio device and the gpio used Herve Codina
2024-02-20 11:11 ` [PATCH 1/2] gpiolib: Introduce gpiod_device_add_link() Herve Codina
2024-02-21 22:44 ` Linus Walleij
2024-02-21 22:58 ` Saravana Kannan
2024-02-20 11:11 ` [PATCH 2/2] leds: gpio: Add devlinks between the gpio consumed and the gpio leds device Herve Codina
2024-02-21 22:45 ` Linus Walleij
2024-02-20 11:40 ` [PATCH 0/2] leds: gpio: Add devlink between the leds-gpio device and the gpio used Bartosz Golaszewski
2024-02-20 13:36 ` Herve Codina
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).