leds: core: add struct device_node pointer to the struct led_classdev
PATCH 1/2 leds: core: add struct device_node pointer to the struct led_classdev
From: Rafał Miłecki <[email protected]>
This allows every led_classdev_register user to set of_node before calling that function. Thanks to this LEDs core code may access DT node during LED registration (e.g. to read extra info).
A small disadvantage of this imlementation is keeping of_node pointer in two places: struct led_classdev and struct device.
Another solutions were:
1) Passing pointer with a led_classdev_register call
This would require changing & complicating the API.
2) Moving allocation part of led_classdev_register to separated function This would make registering LED even more complicated.
Having duplicated pointer semms like a reasonable trade-off.
--- drivers/leds/led-class.c | 1 + include/linux/leds.h | 1 + 2 files changed, 2 insertions(+)
drivers/leds/led-class.c +1 -0
@@ -199,6 +199,7 @@ int led_classdev_register(struct device *parent, struct led_classdev *led_cdev) led_cdev, led_cdev->groups, "%s", name);if (IS_ERR (led_cdev->dev))return PTR_ERR (led_cdev->dev); + led_cdev->dev->of_node = led_cdev->of_node;if (ret) dev_warn(parent, "Led %s renamed to %s due to name collision",
include/linux/leds.h +1 -0
@@ -85,6 +85,7 @@ struct led_classdev { unsigned long *delay_off);struct device *dev; +struct device_node *of_node;const struct attribute_group **groups;struct list_head node;/* LED Device list */
Signature · 1 line
2.11.0
Quoted 40 lines · Rafał Miłecki
From: Rafał Miłecki <[email protected]>
This allows every
led_classdev_registeruser to setof_nodebefore calling that function. Thanks to this LEDs core code may access DT node during LED registration (e.g. to read extra info).A small disadvantage of this imlementation is keeping
of_nodepointer in two places: structled_classdevand struct device.
Another solutions were:
1) Passing pointer with aled_classdev_registercall
This would require changing & complicating the API.
2) Moving allocation part ofled_classdev_registerto separated function This would make registering LED even more complicated.Having duplicated pointer semms like a reasonable trade-off.
Signed-off-by Rafał Miłecki <[email protected]>--- drivers/leds/led-class.c | 1 + include/linux/leds.h | 1 + 2 files changed, 2 insertions(+)drivers/leds/led-class.c +1
-0@@ -199,6 +199,7 @@ int led_classdev_register(struct device *parent, struct led_classdev *led_cdev) led_cdev, led_cdev->groups, "%s", name);if (IS_ERR (led_cdev->dev))return PTR_ERR (led_cdev->dev); + led_cdev->dev->of_node = led_cdev->of_node;if (ret) dev_warn(parent, "Led %s renamed to %s due to name collision",include/linux/leds.h +0
-0
include/linux/leds.h struct led_classdev { · line 91
Quoted 7 lines
include/linux/leds.h +1
-0@@ -85,6 +85,7 @@ struct led_classdev { unsigned long *delay_off);struct device *dev; +struct device_node *of_node;const struct attribute_group **groups;struct list_head node;/* LED Device list */
Sorry Jacek, I used your old e-mail accidentally. Hope you got this patchset.
PATCH 2/2 leds: gpio: set of_node before calling led_classdev_register
In reply to Rafał MiłeckiFrom: Rafał Miłecki <[email protected]>
This allows core code to access DT info earlier, during LED registration process. Thanks to this we will be able to support DT bindings in LEDs core code.
--- drivers/leds/leds-gpio.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-)
drivers/leds/leds-gpio.c +4 -4
@@ -172,7 +172,8 @@ static struct gpio_leds_priv *gpio_leds_create(struct platform_device *pdev)struct gpio_led_data *led_dat = &priv->leds[priv->num_leds];struct gpio_led led = {};const char *state =NULL ; -struct device_node *np =to_of_node (child); + + led_dat->cdev.of_node =to_of_node (child); led.gpiod =devm_get_gpiod_from_child (dev,NULL , child);if (IS_ERR (led.gpiod)) {
@@ -181,8 +182,8 @@ static struct gpio_leds_priv *gpio_leds_create(struct platform_device *pdev) } ret =fwnode_property_read_string (child,"label" , &led.name); -if (ret &&IS_ENABLED (CONFIG_OF ) && np) - led.name = np->name; +if (ret &&IS_ENABLED (CONFIG_OF ) && led_dat->cdev.of_node) + led.name = led_dat->cdev.of_node->name;if (!led.name) {fwnode_handle_put (child);return ERR_PTR (-EINVAL );
@@ -211,7 +212,6 @@ static struct gpio_leds_priv *gpio_leds_create(struct platform_device *pdev)fwnode_handle_put (child);return ERR_PTR (ret); } - led_dat->cdev.dev->of_node = np; priv->num_leds++; }
Signature · 1 line
2.11.0
Hi Rafał,
Thanks for the patch. How about following what has been already done for spi, i.e. adding a wrapper of_led_classdev_register() (please refer to of_register_spi_device() in drivers/spi/spi.c)?
Best regards,
Jacek Anaszewski
Quoted 47 lines · Rafał Miłecki
From: Rafał Miłecki <[email protected]>
This allows every
led_classdev_registeruser to setof_nodebefore calling that function. Thanks to this LEDs core code may access DT node during LED registration (e.g. to read extra info).A small disadvantage of this imlementation is keeping
of_nodepointer in two places: structled_classdevand struct device.
Another solutions were:
1) Passing pointer with aled_classdev_registercall
This would require changing & complicating the API.
2) Moving allocation part ofled_classdev_registerto separated function This would make registering LED even more complicated.Having duplicated pointer semms like a reasonable trade-off.
Signed-off-by Rafał Miłecki <[email protected]>--- drivers/leds/led-class.c | 1 + include/linux/leds.h | 1 + 2 files changed, 2 insertions(+)drivers/leds/led-class.c +1
-0@@ -199,6 +199,7 @@ int led_classdev_register(struct device *parent, struct led_classdev *led_cdev) led_cdev, led_cdev->groups, "%s", name);if (IS_ERR (led_cdev->dev))return PTR_ERR (led_cdev->dev); + led_cdev->dev->of_node = led_cdev->of_node;if (ret) dev_warn(parent, "Led %s renamed to %s due to name collision",include/linux/leds.h +1
-0@@ -85,6 +85,7 @@ struct led_classdev { unsigned long *delay_off);struct device *dev; +struct device_node *of_node;const struct attribute_group **groups;struct list_head node;/* LED Device list */
Quoted 3 lines · Jacek Anaszewski
Thanks for the patch. How about following what has been already done for spi, i.e. adding a wrapper
of_led_classdev_register()(please refer toof_register_spi_device()indrivers/spi/spi.c)?
I like this idea, but I'll need to split led_classdev_register into two functions: allocation & actual registering function. That way I can alloc, then read DT proprties and finally register LED (just like it's done in of_register_spi_device).
Does it sound OK?
Quoted 6 lines · Rafał Miłecki
Quoted 3 lines · Jacek Anaszewski
Thanks for the patch. How about following what has been already done for spi, i.e. adding a wrapper
of_led_classdev_register()(please refer toof_register_spi_device()indrivers/spi/spi.c)?
Quoted 6 lines
I like this idea, but I'll need to split
led_classdev_registerinto two functions: allocation & actual registering function. That way I can alloc, then read DT proprties and finally register LED (just like it's done inof_register_spi_device).Does it sound OK?
Yes, after thinking a bit more about that I came to the same conclusion.
Signature · 2 lines
Best regards, Jacek Anaszewski
Quoted 12 lines · Jacek Anaszewski
Quoted 11 lines · Rafał Miłecki
Quoted 3 lines · Jacek Anaszewski
Thanks for the patch. How about following what has been already done for spi, i.e. adding a wrapper
of_led_classdev_register()(please refer toof_register_spi_device()indrivers/spi/spi.c)?I like this idea, but I'll need to split
led_classdev_registerinto two functions: allocation & actual registering function. That way I can alloc, then read DT proprties and finally register LED (just like it's done inof_register_spi_device).
Quoted 4 lines
Quoted 1 line
Does it sound OK?
Yes, after thinking a bit more about that I came to the same conclusion.
OK, I spent some extra time on this today, this seem a bit more complex.
I was starring at of_register_spi_device for quite some time and it doesn't seem really related to this situation. In case of of_register_spi_device:
1) It's used internally in spi core code only
2) It handles DT controller child node totally on its own
This patch I sent is about interaction between drivers registering LEDs and LED core code. There are few drivers (that register LEDs) parsing DT on their own. I'm afraid comparing this situation to of_register_spi_device is a bit confusing for me. I really don't see a place for of_led_classdev_register that would be called for every child of LED controller (?!).
So I'd like to suggest not comparing this situation to of_register_spi_device and discussing this problem on our own.
My current problem is that led_classdev_register:
1) Allocates struct device & registers LED
2) It means drivers can't touch struct device before having LED registered
3) It doesn't allow passing of_node
4) It is used in so many places it's almost impossible to modify all callers at once
So maybe I could work on of_led_classdev_register that:
1) Would be almost identical to led_classdev_register
2) It would accept extra struct device_node argument
Does it make sense? Or maybe it's even what you meant from the beginning?
Two things I'll need to take in mind while working on this:
1) I'll need devm variant
2) I should share code between (of_)led_classdev_register functions
Signature · 1 line
Rafał
Quoted 43 lines · Rafał Miłecki
Quoted 12 lines · Jacek Anaszewski
Quoted 11 lines · Rafał Miłecki
Quoted 3 lines · Jacek Anaszewski
Thanks for the patch. How about following what has been already done for spi, i.e. adding a wrapper
of_led_classdev_register()(please refer toof_register_spi_device()indrivers/spi/spi.c)?I like this idea, but I'll need to split
led_classdev_registerinto two functions: allocation & actual registering function. That way I can alloc, then read DT proprties and finally register LED (just like it's done inof_register_spi_device).Quoted 4 lines
Quoted 1 line
Does it sound OK?
Yes, after thinking a bit more about that I came to the same conclusion.
OK, I spent some extra time on this today, this seem a bit more complex.
I was starring at
of_register_spi_devicefor quite some time and it doesn't seem really related to this situation. In case ofof_register_spi_device:
1) It's used internally in spi core code only
2) It handles DT controller child node totally on its ownThis patch I sent is about interaction between drivers registering LEDs and LED core code. There are few drivers (that register LEDs) parsing DT on their own. I'm afraid comparing this situation to
of_register_spi_deviceis a bit confusing for me. I really don't see a place forof_led_classdev_registerthat would be called for every child of LED controller (?!).So I'd like to suggest not comparing this situation to
of_register_spi_deviceand discussing this problem on our own.My current problem is that
led_classdev_register:
1) Allocates struct device & registers LED
2) It means drivers can't touch struct device before having LED registered
3) It doesn't allow passingof_node
4) It is used in so many places it's almost impossible to modify all callers at once
Quoted 5 lines
So maybe I could work on
of_led_classdev_registerthat:
1) Would be almost identical toled_classdev_register
2) It would accept extra structdevice_nodeargumentDoes it make sense? Or maybe it's even what you meant from the beginning?
I intended that of_led_classdev_register() was almost identical to led_classdev_register() but additionally had device_node parameter.
When agreeing with you on splitting led_classdev_register() to allocation and registering function I meant creating two helper functions that could be used as follows:
[pseudocode]
led_classdev_register(...):
led_cdev->dev = alloc_led_classdev
register_led_classdev(led_cdev)of_led_classdev_register(..., of_node):
led_cdev->dev = alloc_led_classdev
led_cdev->of_node = of_node
register_led_classdev(led_cdev)I didn't mean updating all existing drivers to use new of_ prefixed API.
Quoted 2 lines
Two things I'll need to take in mind while working on this:
1) I'll need devm variant
Right.
Quoted 1 line
2) I should share code between (of_)led_classdev_register functions
Exactly.
Signature · 2 lines
Best regards, Jacek Anaszewski