2020-09-11 15:54:17

by Alexander Dahl

[permalink] [raw]
Subject: [PATCH v4 0/3] leds: pwm: Make automatic labels work

Hei hei,

for leds-gpio you can use the properties 'function' and 'color' in the
devicetree node and omit 'label', the label is constructed
automatically. This is a common feature supposed to be working for all
LED drivers. However it did not yet work for the 'leds-pwm' driver.

This series changes led-core a bit to add a non-ugly fix for the
leds-pwm driver and takes the opportunity to update the leds-pwm
dt-bindings accordingly.

v4 was tested on a at91 sama5d2 based platform with LEDs connected to
GPIO and PWM.

Greets
Alex

v4:
- added led-class patch handling fwnode passing differently (patch 1/3)
- adapted leds-pwm patch to new led-class (patch 2/3)
- contacted original author of leds-pwm dt binding on license issue
(patch 3/3)

v3:
- series rebased on v5.9-rc4
- changed license of .yaml file to recommended one (patch 2/2)
- added Acked-by to both patches

v2:
- series rebased on v5.9-rc3
- added the dt-bindings update patch (2/2)

v1:
- based on v5.9-rc2
- backport on v5.4.59 tested and working

Alexander Dahl (3):
leds: Require valid fwnode pointer for composing name
leds: pwm: Allow automatic labels for DT based devices
dt-bindings: leds: Convert pwm to yaml

.../devicetree/bindings/leds/leds-pwm.txt | 50 -----------
.../devicetree/bindings/leds/leds-pwm.yaml | 85 +++++++++++++++++++
drivers/leds/led-class.c | 2 +-
drivers/leds/leds-pwm.c | 3 +-
4 files changed, 88 insertions(+), 52 deletions(-)
delete mode 100644 Documentation/devicetree/bindings/leds/leds-pwm.txt
create mode 100644 Documentation/devicetree/bindings/leds/leds-pwm.yaml

--
2.20.1


2020-09-11 16:12:22

by Alexander Dahl

[permalink] [raw]
Subject: [PATCH v4 1/3] leds: Require valid fwnode pointer for composing name

The function 'led_compose_name()' is called in
'led_classdev_register_ext(()' only and in its implementation it always
parses the fwnode passed with the init_data struct. If there's no
fwnode, EINVAL is returned and 'led_classdev_register_ext()' returns
early.

If this is detected early the same fallback mechanism can be used , as
if init_data itself is NULL. This will allow drivers to pass fully
populated 'init_data' or sparse initialized 'init_data' with a NULL
fwnode in a more elegant way with only one function call.

Fixes: bb4e9af0348d ("leds: core: Add support for composing LED class device names")
Suggested-by: Pavel Machek <[email protected]>
Signed-off-by: Alexander Dahl <[email protected]>
---

Notes:
v4:
* added this patch to series (Suggested-by: Pavel Machek)

drivers/leds/led-class.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/leds/led-class.c b/drivers/leds/led-class.c
index cc3929f858b6..3da50c7ecfe7 100644
--- a/drivers/leds/led-class.c
+++ b/drivers/leds/led-class.c
@@ -346,7 +346,7 @@ int led_classdev_register_ext(struct device *parent,
const char *proposed_name = composed_name;
int ret;

- if (init_data) {
+ if (init_data && init_data->fwnode) {
if (init_data->devname_mandatory && !init_data->devicename) {
dev_err(parent, "Mandatory device name is missing");
return -EINVAL;
--
2.20.1

2020-09-11 21:28:12

by Jacek Anaszewski

[permalink] [raw]
Subject: Re: [PATCH v4 1/3] leds: Require valid fwnode pointer for composing name

Hi Alexander,

On 9/11/20 5:40 PM, Alexander Dahl wrote:
> The function 'led_compose_name()' is called in
> 'led_classdev_register_ext(()' only and in its implementation it always
> parses the fwnode passed with the init_data struct. If there's no
> fwnode, EINVAL is returned and 'led_classdev_register_ext()' returns
> early.
>
> If this is detected early the same fallback mechanism can be used , as
> if init_data itself is NULL. This will allow drivers to pass fully
> populated 'init_data' or sparse initialized 'init_data' with a NULL
> fwnode in a more elegant way with only one function call.
>
> Fixes: bb4e9af0348d ("leds: core: Add support for composing LED class device names")
> Suggested-by: Pavel Machek <[email protected]>
> Signed-off-by: Alexander Dahl <[email protected]>
> ---
>
> Notes:
> v4:
> * added this patch to series (Suggested-by: Pavel Machek)
>
> drivers/leds/led-class.c | 2 +-
> 1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/drivers/leds/led-class.c b/drivers/leds/led-class.c
> index cc3929f858b6..3da50c7ecfe7 100644
> --- a/drivers/leds/led-class.c
> +++ b/drivers/leds/led-class.c
> @@ -346,7 +346,7 @@ int led_classdev_register_ext(struct device *parent,
> const char *proposed_name = composed_name;
> int ret;
>
> - if (init_data) {
> + if (init_data && init_data->fwnode) {

This does not cover the case when we don't have fwnode but we
have init_data->default_label that led_compose_name() can make use of.

> if (init_data->devname_mandatory && !init_data->devicename) {
> dev_err(parent, "Mandatory device name is missing");
> return -EINVAL;
>

--
Best regards,
Jacek Anaszewski

2020-09-15 09:17:26

by Alexander Dahl

[permalink] [raw]
Subject: Re: [PATCH v4 1/3] leds: Require valid fwnode pointer for composing name

Hello Jacek,

thanks for your feedback. See below.

Am Freitag, 11. September 2020, 23:26:43 CEST schrieb Jacek Anaszewski:
> On 9/11/20 5:40 PM, Alexander Dahl wrote:
> > The function 'led_compose_name()' is called in
> > 'led_classdev_register_ext(()' only and in its implementation it always
> > parses the fwnode passed with the init_data struct. If there's no
> > fwnode, EINVAL is returned and 'led_classdev_register_ext()' returns
> > early.
> >
> > If this is detected early the same fallback mechanism can be used , as
> > if init_data itself is NULL. This will allow drivers to pass fully
> > populated 'init_data' or sparse initialized 'init_data' with a NULL
> > fwnode in a more elegant way with only one function call.
> >
> > Fixes: bb4e9af0348d ("leds: core: Add support for composing LED class
> > device names") Suggested-by: Pavel Machek <[email protected]>
> > Signed-off-by: Alexander Dahl <[email protected]>
> > ---
> >
> > Notes:
> > v4:
> > * added this patch to series (Suggested-by: Pavel Machek)
> >
> > drivers/leds/led-class.c | 2 +-
> > 1 file changed, 1 insertion(+), 1 deletion(-)
> >
> > diff --git a/drivers/leds/led-class.c b/drivers/leds/led-class.c
> > index cc3929f858b6..3da50c7ecfe7 100644
> > --- a/drivers/leds/led-class.c
> > +++ b/drivers/leds/led-class.c
> > @@ -346,7 +346,7 @@ int led_classdev_register_ext(struct device *parent,
> >
> > const char *proposed_name = composed_name;
> > int ret;
> >
> > - if (init_data) {
> > + if (init_data && init_data->fwnode) {
>
> This does not cover the case when we don't have fwnode but we
> have init_data->default_label that led_compose_name() can make use of.
>
> > if (init_data->devname_mandatory && !init_data->devicename) {
> >
> > dev_err(parent, "Mandatory device name is missing");
> > return -EINVAL;

You're right, I missed that part in that if/else if construct in
led_compose_name() … I looked at the code for some more time now and could not
come up with an elegant change to the led-core or led-class. :-/

However I also had another look at leds-pwm and for me it seems that it is
used by fwnode (DT, ACPI, ??) based devices only. I could not find a single
user of leds-pwm as a platform driver, which is probably why 141f15c66d94
("leds: pwm: remove header") was possible?

I had a look at the history of the leds-pwm driver and when introduced in 2009
platform based board files where a thing, no dt, of, or fwnode yet, at least
for arm, right? Device tree support for leds-pwm was added in 2012 by Peter
Ujfalusi.

So if those code paths in leds-pwm are not used anymore, what about dropping
that platform support in leds-pwm driver? That would mean we always have
fwnode non-null and would not require a change in led-class at all?

Greets
Alex



2020-09-15 21:20:45

by Jacek Anaszewski

[permalink] [raw]
Subject: Re: [PATCH v4 1/3] leds: Require valid fwnode pointer for composing name

Hi Alexander,

On 9/15/20 11:14 AM, Alexander Dahl wrote:
> Hello Jacek,
>
> thanks for your feedback. See below.
>
> Am Freitag, 11. September 2020, 23:26:43 CEST schrieb Jacek Anaszewski:
>> On 9/11/20 5:40 PM, Alexander Dahl wrote:
>>> The function 'led_compose_name()' is called in
>>> 'led_classdev_register_ext(()' only and in its implementation it always
>>> parses the fwnode passed with the init_data struct. If there's no
>>> fwnode, EINVAL is returned and 'led_classdev_register_ext()' returns
>>> early.
>>>
>>> If this is detected early the same fallback mechanism can be used , as
>>> if init_data itself is NULL. This will allow drivers to pass fully
>>> populated 'init_data' or sparse initialized 'init_data' with a NULL
>>> fwnode in a more elegant way with only one function call.
>>>
>>> Fixes: bb4e9af0348d ("leds: core: Add support for composing LED class
>>> device names") Suggested-by: Pavel Machek <[email protected]>
>>> Signed-off-by: Alexander Dahl <[email protected]>
>>> ---
>>>
>>> Notes:
>>> v4:
>>> * added this patch to series (Suggested-by: Pavel Machek)
>>>
>>> drivers/leds/led-class.c | 2 +-
>>> 1 file changed, 1 insertion(+), 1 deletion(-)
>>>
>>> diff --git a/drivers/leds/led-class.c b/drivers/leds/led-class.c
>>> index cc3929f858b6..3da50c7ecfe7 100644
>>> --- a/drivers/leds/led-class.c
>>> +++ b/drivers/leds/led-class.c
>>> @@ -346,7 +346,7 @@ int led_classdev_register_ext(struct device *parent,
>>>
>>> const char *proposed_name = composed_name;
>>> int ret;
>>>
>>> - if (init_data) {
>>> + if (init_data && init_data->fwnode) {
>>
>> This does not cover the case when we don't have fwnode but we
>> have init_data->default_label that led_compose_name() can make use of.
>>
>>> if (init_data->devname_mandatory && !init_data->devicename) {
>>>
>>> dev_err(parent, "Mandatory device name is missing");
>>> return -EINVAL;
>
> You're right, I missed that part in that if/else if construct in
> led_compose_name() … I looked at the code for some more time now and could not
> come up with an elegant change to the led-core or led-class. :-/
>
> However I also had another look at leds-pwm and for me it seems that it is
> used by fwnode (DT, ACPI, ??) based devices only. I could not find a single
> user of leds-pwm as a platform driver, which is probably why 141f15c66d94
> ("leds: pwm: remove header") was possible?

In fact it looks like that patch was pointless, since it precluded the
use of struct led_pwm_platform_data anywhere besides the leds-pwm
driver.

> I had a look at the history of the leds-pwm driver and when introduced in 2009
> platform based board files where a thing, no dt, of, or fwnode yet, at least
> for arm, right? Device tree support for leds-pwm was added in 2012 by Peter
> Ujfalusi.
>
> So if those code paths in leds-pwm are not used anymore, what about dropping
> that platform support in leds-pwm driver? That would mean we always have
> fwnode non-null and would not require a change in led-class at all?

git grep led_pwm_platform_data in fact shows only references in
leds-pwm.c, so yes, I think the platform support seems to be redundant.

--
Best regards,
Jacek Anaszewski