lp50xx: LED banking appears to be broken

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



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




[Index of Archives]     [Linux ARM Kernel]     [Linux ARM]     [Linux Omap]     [Fedora ARM]     [IETF Annouce]     [Security]     [Bugtraq]     [Linux OMAP]     [Linux MIPS]     [ECOS]     [Asterisk Internet PBX]     [Linux API]

  Powered by Linux