Skip to content

drivers: led: lp50xx fix write_channels #92176

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed

Conversation

allemanm
Copy link
Contributor

Fix implementation of write_channels of the lp50xx driver.

Fix implementation of write_channels of the lp50xx driver.

Signed-off-by: Matthias Alleman <[email protected]>
@github-actions github-actions bot added the area: LED Label to identify LED subsystem label Jun 25, 2025
Copy link

@pdgendt pdgendt added this to the v4.2.0 milestone Jun 27, 2025
@pdgendt pdgendt modified the milestones: v4.2.0, v4.3.0 Jul 18, 2025
@pdgendt pdgendt added the backport v4.2-branch Request backport to the v4.2-branch label Jul 18, 2025
@pdgendt
Copy link
Contributor

pdgendt commented Jul 23, 2025

Ping @Mani-Sadhasivam @simonguinot

@simonguinot
Copy link
Contributor

Ping @Mani-Sadhasivam @simonguinot

pong @pdgendt :)

Did you test it with the lp50xx sample ?

@pdgendt
Copy link
Contributor

pdgendt commented Jul 24, 2025

Did you test it with the lp50xx sample ?

The sample isn't really useful. We simply use the channels to control the different outputs of the LP5018 controller.

	lp5018@3c {
		compatible = "ti,lp5018";
		reg = <0x3c>;
		enable-gpios = <&gpio1 14 (GPIO_ACTIVE_HIGH | GPIO_PULL_DOWN)>;
		log-scale-en;
	};

And confirmed that we can control the individual out# pins

uart:~$ led set_channel lp5018@3c 0 255
lp5018@3c: setting channel 0 to 255
uart:~$ led set_channel lp5018@3c 5 123
lp5018@3c: setting channel 5 to 123
uart:~$ led write_channels lp5018@3c 8 128 128 128 128
lp5018@3c: writing from channel 8: 128 128 128 128

Which isn't possible without this PR.

Copy link
Contributor

@simonguinot simonguinot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi @allemanm,

First, let me apologize for the delay. When I saw this patch, I thought it was suspect and that I should do some testing in order to check it. But unfortunately, I never got to the stage where I look through my cabinet full of boards to find an LP50xx evaluation board :)

And I still haven't. But as I said, I find this patch suspect. Please see my comment below.

In addition, at the very least, you should explain the bug or behavior you are trying to fix. "fix write_channel" is way to vague.

@@ -39,7 +39,7 @@ LOG_MODULE_REGISTER(lp50xx, CONFIG_LED_LOG_LEVEL);

/* Maximum number of channels */
#define LP50XX_MAX_CHANNELS(nmodules) \
((LP50XX_COLORS_PER_LED + 1) * ((nmodules) + 1))
(LP50XX_COLORS_PER_LED * nmodules)
Copy link
Contributor

@simonguinot simonguinot Jul 24, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please can you explain what you are fixing ?

I find this change highly suspicious. For each module, there are three color registers and one brightness register, so LP50XX_COLORS_PER_LED + 1 makes sense. And the ->write_channels() API also exposes the bank registers. And that's (nmodules) + 1.

So I don't understand :)

@simonguinot
Copy link
Contributor

simonguinot commented Jul 24, 2025

Did you test it with the lp50xx sample ?

The sample isn't really useful. We simply use the channels to control the different outputs of the LP5018 controller.

	lp5018@3c {
		compatible = "ti,lp5018";
		reg = <0x3c>;
		enable-gpios = <&gpio1 14 (GPIO_ACTIVE_HIGH | GPIO_PULL_DOWN)>;
		log-scale-en;
	};

And confirmed that we can control the individual out# pins

uart:~$ led set_channel lp5018@3c 0 255
lp5018@3c: setting channel 0 to 255
uart:~$ led set_channel lp5018@3c 5 123
lp5018@3c: setting channel 5 to 123
uart:~$ led write_channels lp5018@3c 8 128 128 128 128
lp5018@3c: writing from channel 8: 128 128 128 128

Which isn't possible without this PR.

Well, there is something wrong with this patch I think. The LP50XX_MAX_CHANNELS macro in the current code looks correct. Note that the bank registers are also exposed by the ->write_channel() API. So probably that an offset (of 4 ?) is needed with led shell commands to access the LED color registers. Did you take this into account with your testing ?

Note that the lp50xx sample provides a run_channel_test function. It relies on the LP50XX_LED_BRIGHT_CHAN_BASE and LP50{12,24,36}_LED_COL_CHAN_BASE macros defined in lp50xx.h. So it is probably the right way to test...

@pdgendt
Copy link
Contributor

pdgendt commented Jul 24, 2025

Well, there is something wrong with this patch I think. The LP50XX_MAX_CHANNELS macro in the current code looks correct. Note that the bank registers are also exposed by the ->write_channel() API. So probably that an offset (of 4 ?) is needed with led shell commands to access the LED color registers. Did you take this into account with your testing ?

Maybe we're just failing to understand how the API is supposed to work with this controller. We are under the impression that channels map directly to the OUT# pins of the IC, is this a false assumption?

Note that the lp50xx sample provides a run_channel_test function. It relies on the LP50XX_LED_BRIGHT_CHAN_BASE and LP50{12,24,36}_LED_COL_CHAN_BASE macros defined in lp50xx.h. So it is probably the right way to test...

This might be part of what we fail to understand.

We could go with adding individual LED nodes to the device tree, but we're not controlling color LEDs, but simple white LEDs. Is that possible with the current implementation to define this?

@simonguinot
Copy link
Contributor

simonguinot commented Jul 24, 2025

Well, there is something wrong with this patch I think. The LP50XX_MAX_CHANNELS macro in the current code looks correct. Note that the bank registers are also exposed by the ->write_channel() API. So probably that an offset (of 4 ?) is needed with led shell commands to access the LED color registers. Did you take this into account with your testing ?

Maybe we're just failing to understand how the API is supposed to work with this controller. We are under the impression that channels map directly to the OUT# pins of the IC, is this a false assumption?

I think that the ->write_channels API is not well documented for the lp50xx driver. That's the issue. The only information is in lp50xx.h.

So yes, your assumption is wrong :) This driver exposes all the registers, starting with the bank registers (LP50XX_BANK_CHAN_BASE). The idea was to use the ->write_channels API to give control to users over bank registers, which are quite powerful but not accessible through other LED API methods.

Note that the lp50xx sample provides a run_channel_test function. It relies on the LP50XX_LED_BRIGHT_CHAN_BASE and LP50{12,24,36}_LED_COL_CHAN_BASE macros defined in lp50xx.h. So it is probably the right way to test...

This might be part of what we fail to understand.

We could go with adding individual LED nodes to the device tree, but we're not controlling color LEDs, but simple white LEDs. Is that possible with the current implementation to define this?

Is that related with #85208 ? And yes you can use the ->write_channels API to handle that case.

@pdgendt
Copy link
Contributor

pdgendt commented Jul 24, 2025

Closing as it is clear this limits the (ab)use of write_channels in the LP50XX driver.

Adding an offset of 12 (LP5024_LED_COL_CHAN_BASE) allows for setting the individual OUT# pins.

@pdgendt pdgendt closed this Jul 24, 2025
@pdgendt pdgendt removed the backport v4.2-branch Request backport to the v4.2-branch label Jul 24, 2025
@simonguinot
Copy link
Contributor

Sorry again for the delay...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area: LED Label to identify LED subsystem
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants