All of lore.kernel.org
 help / color / mirror / Atom feed
* lp50xx: LED banking appears to be broken
@ 2021-07-31  8:14 Jan Kundrát
  2021-08-02 22:17 ` Jacek Anaszewski
  0 siblings, 1 reply; 2+ messages in thread
From: Jan Kundrát @ 2021-07-31  8:14 UTC (permalink / raw)
  To: linux-leds
  Cc: Dan Murphy, Pavel Machek, Andy Shevchenko, Christophe JAILLET,
	Marek Behún

Hi there,
I'm trying to use the LP5009 chip with the following HW setup:

- channels 1-6 drive a big, 20mm LED module which internally consists of 
six independent LEDs
- channels 7, 8 and 9 drive a RGB LED as usual.

I thought that a DT bindings like this will work:

	led-controller@0c {
		compatible = "ti,lp5009";
		reg = <0x0c>;
		#address-cells = <1>;
		#size-cells = <0>;
		status = "okay";

		multi-led@1 {
			#address-cells = <1>;
			#size-cells = <0>;
			reg = <1>;
			label = "tally:1";
			led {
				color = <LED_COLOR_ID_RED>;
			};
		};
		multi-led@2 {
			#address-cells = <1>;
			#size-cells = <0>;
			reg = <2>;
			label = "tally:2";
			led {
				color = <LED_COLOR_ID_RED>;
			};
		};
		multi-led@3 {
			#address-cells = <1>;
			#size-cells = <0>;
			reg = <3>;
			label = "tally:3";
			led {
				color = <LED_COLOR_ID_RED>;
			};
		};
		multi-led@4 {
			#address-cells = <1>;
			#size-cells = <0>;
			reg = <4>;
			label = "tally:4";
			led {
				color = <LED_COLOR_ID_RED>;
			};
		};
		multi-led@5 {
			#address-cells = <1>;
			#size-cells = <0>;
			reg = <5>;
			label = "tally:5";
			led {
				color = <LED_COLOR_ID_RED>;
			};
		};
		multi-led@6 {
			#address-cells = <1>;
			#size-cells = <0>;
			reg = <6>;
			label = "tally:6";
			led {
				color = <LED_COLOR_ID_RED>;
			};
		};

		multi-led@7 {
			#address-cells = <1>;
			#size-cells = <2>;
			reg = <7 8 9>;
			color = <LED_COLOR_ID_RGB>;
			label = "preview";

			led@7 {
				color = <LED_COLOR_ID_RED>;
			};
			led@8 {
				color = <LED_COLOR_ID_GREEN>;
			};
			led@9 {
				color = <LED_COLOR_ID_BLUE>;
			};
		};
	};

This has drawbacks:

- I get a multicolor sysfs entry for each of the six red sub-LEDs, which 
probably doesn't make much sense. I cannot do a one "multicolor" LED with 
six channels because there appears to be a limit of 3 channels, and because 
the order of channels is documented to be non-deterministic, so that would 
require me to come up with fake names or something. Also, driving this from 
userspace means two writes for each sub-LED.

- The sysfs entries do not appear to drive correct LEDs. For example, a 
write to tally:5 or tally:6 results in an error:

 lp50xx 1-000c: Cannot write intensity value -5
 leds tally:6: Setting an LED's brightness failed (-5)

I tried to simplify this, and kept just the one RGB LED (that is, the 
multi-led@7 and led@7, led@8 and led@9 stanzas). This resulted in the 
following regmap entries after init:

# cat /sys/kernel/debug/regmap/1-000c/registers 
00: 40
01: 3c
02: 80
03: ff
04: 0f
05: 0f
06: 0f
07: 0f
08: ff
09: ff
0a: ff
0b: 0f
0c: 00
0d: 00
0e: 00
0f: 00
10: 00
11: 00
12: 00
13: 00
14: 00
15: 00
16: 00
17: ff

Clearly, that's wrong because it sets register's 0x02 reserved bits to 
non-zero. It looks as if the LED's channel number gets translated to the 
bank number, which is wrong. There are nine LEDs on LP5009, but only three 
individual banks.

Also, I don't think that the concept of "banks" as defined in LP50xx chips 
should be used in the Linux driver. The datasheet is not terribly specific 
on details, but it looks to me that the "banks" are for a use case where 
multiple physical LEDs are to, e.g., "breathe together". The chip indeed 
imposes some limitations when banking is enabled:

- LED0 will always be on channels 1-3. That's incompatible with the current 
code which uses the `reg` DT property and allows arbitrary assigning of 
channels to a LED's color inputs. I can have a Linux RGB LED which uses 
channels 1, 5 and 9 just fine, but I cannot use banking for that.

- Bank A always drives the first color of all LEDs that have banking 
enabled. Bank B is always for the second color, and bank C always applies 
to the third color.

As far as I can tell, there's no support for cross-LED control in Linux, so 
I think that we can just rip support for banking from this driver. The main 
motivation appears to be saving some I2C bandwidth and MCU cycles. If the 
driver was serious about this, it would use register auto-increment as a 
first step I suppose, but the regmap subsystem as-is updates all registers 
independently.

Before I send a patch which implements all that, I wanted to ask if I 
understood everything right, and to check whether these suggestions make 
sense to the maintainer and to the original author of the driver (and, 
hopefully, to the users as well).

With kind regards,
Jan

^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: lp50xx: LED banking appears to be broken
  2021-07-31  8:14 lp50xx: LED banking appears to be broken Jan Kundrát
@ 2021-08-02 22:17 ` Jacek Anaszewski
  0 siblings, 0 replies; 2+ messages in thread
From: Jacek Anaszewski @ 2021-08-02 22:17 UTC (permalink / raw)
  To: Jan Kundrát, linux-leds
  Cc: Dan Murphy, Pavel Machek, Andy Shevchenko, Christophe JAILLET,
	Marek Behún

Hi Jan,

On 7/31/21 10:14 AM, Jan Kundrát wrote:
> Hi there,
> I'm trying to use the LP5009 chip with the following HW setup:
> 
> - channels 1-6 drive a big, 20mm LED module which internally consists of 
> six independent LEDs
> - channels 7, 8 and 9 drive a RGB LED as usual.
> 
> I thought that a DT bindings like this will work:
> 
>      led-controller@0c {
>          compatible = "ti,lp5009";
>          reg = <0x0c>;
>          #address-cells = <1>;
>          #size-cells = <0>;
>          status = "okay";
> 
>          multi-led@1 {
>              #address-cells = <1>;
>              #size-cells = <0>;
>              reg = <1>;
>              label = "tally:1";
>              led {
>                  color = <LED_COLOR_ID_RED>;
>              };
>          };
>          multi-led@2 {
>              #address-cells = <1>;
>              #size-cells = <0>;
>              reg = <2>;
>              label = "tally:2";
>              led {
>                  color = <LED_COLOR_ID_RED>;
>              };
>          };
>          multi-led@3 {
>              #address-cells = <1>;
>              #size-cells = <0>;
>              reg = <3>;
>              label = "tally:3";
>              led {
>                  color = <LED_COLOR_ID_RED>;
>              };
>          };
>          multi-led@4 {
>              #address-cells = <1>;
>              #size-cells = <0>;
>              reg = <4>;
>              label = "tally:4";
>              led {
>                  color = <LED_COLOR_ID_RED>;
>              };
>          };
>          multi-led@5 {
>              #address-cells = <1>;
>              #size-cells = <0>;
>              reg = <5>;
>              label = "tally:5";
>              led {
>                  color = <LED_COLOR_ID_RED>;
>              };
>          };
>          multi-led@6 {
>              #address-cells = <1>;
>              #size-cells = <0>;
>              reg = <6>;
>              label = "tally:6";
>              led {
>                  color = <LED_COLOR_ID_RED>;
>              };
>          };
> 
>          multi-led@7 {
>              #address-cells = <1>;
>              #size-cells = <2>;
>              reg = <7 8 9>;
>              color = <LED_COLOR_ID_RGB>;
>              label = "preview";
> 
>              led@7 {
>                  color = <LED_COLOR_ID_RED>;
>              };
>              led@8 {
>                  color = <LED_COLOR_ID_GREEN>;
>              };
>              led@9 {
>                  color = <LED_COLOR_ID_BLUE>;
>              };
>          };
>      };
> 
> This has drawbacks:
> 
> - I get a multicolor sysfs entry for each of the six red sub-LEDs, which 
> probably doesn't make much sense.

Feel free to add support for monochrome LED class to the driver,
similarly like it was done for drivers/leds/leds-lp55xx-common.c.

> I cannot do a one "multicolor" LED

This is due to the limitation imposed by Pavel Machek in the LED core:

BUG_ON(props.color == LED_COLOR_ID_MULTI);

You'd have to convince him that having multi color LED other than RGB
is reasonable :-)

> with six channels because there appears to be a limit of 3 channels, and 
> because the order of channels is documented to be non-deterministic, so 

You can determine the order of LEDs via multi_index file.
See Documentation/ABI/testing/sysfs-class-led-multicolor.

> that would require me to come up with fake names or something. Also, 
> driving this from userspace means two writes for each sub-LED.
> 
> - The sysfs entries do not appear to drive correct LEDs. For example, a 
> write to tally:5 or tally:6 results in an error:
> 
> lp50xx 1-000c: Cannot write intensity value -5
> leds tally:6: Setting an LED's brightness failed (-5)

You mixed deprecated 'label' DT property with 'color' in your DT nodes.
I haven't tracked down that in detail, but it may certainly have some
negative impact on how LEDs are named and presented in sysfs.
Please first sort it out, and let's see if something gets better
afterwards.

> I tried to simplify this, and kept just the one RGB LED (that is, the 
> multi-led@7 and led@7, led@8 and led@9 stanzas). This resulted in the 
> following regmap entries after init:
> 
> # cat /sys/kernel/debug/regmap/1-000c/registers 00: 40
> 01: 3c
> 02: 80
> 03: ff
> 04: 0f
> 05: 0f
> 06: 0f
> 07: 0f
> 08: ff
> 09: ff
> 0a: ff
> 0b: 0f
> 0c: 00
> 0d: 00
> 0e: 00
> 0f: 00
> 10: 00
> 11: 00
> 12: 00
> 13: 00
> 14: 00
> 15: 00
> 16: 00
> 17: ff
> 
> Clearly, that's wrong because it sets register's 0x02 reserved bits to 
> non-zero. It looks as if the LED's channel number gets translated to the 
> bank number, which is wrong. There are nine LEDs on LP5009, but only 
> three individual banks.
> 
> Also, I don't think that the concept of "banks" as defined in LP50xx 
> chips should be used in the Linux driver. The datasheet is not terribly 
> specific on details, but it looks to me that the "banks" are for a use 
> case where multiple physical LEDs are to, e.g., "breathe together". The 
> chip indeed imposes some limitations when banking is enabled:
> 
> - LED0 will always be on channels 1-3. That's incompatible with the 
> current code which uses the `reg` DT property and allows arbitrary 
> assigning of channels to a LED's color inputs. I can have a Linux RGB 
> LED which uses channels 1, 5 and 9 just fine, but I cannot use banking 
> for that.
> 
> - Bank A always drives the first color of all LEDs that have banking 
> enabled. Bank B is always for the second color, and bank C always 
> applies to the third color.
> 
> As far as I can tell, there's no support for cross-LED control in Linux, 

That's for LED multicolor class was designed for.

> so I think that we can just rip support for banking from this driver. 
> The main motivation appears to be saving some I2C bandwidth and MCU 
> cycles. If the driver was serious about this, it would use register 
> auto-increment as a first step I suppose, but the regmap subsystem as-is 
> updates all registers independently.

The main motivation for having support for banking was taking
advantage of hardware support for synchronous setting of intensity
on multiple iouts.

> Before I send a patch which implements all that, I wanted to ask if I 
> understood everything right, and to check whether these suggestions make 
> sense to the maintainer and to the original author of the driver (and, 
> hopefully, to the users as well).

As I mentioned above, adding a support for monochrome LEDs to the driver
would be probably welcome, but you would need to hear the final word on
that from Pavel.

-- 
Best regards,
Jacek Anaszewski

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2021-08-02 22:17 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-07-31  8:14 lp50xx: LED banking appears to be broken Jan Kundrát
2021-08-02 22:17 ` Jacek Anaszewski

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.