linux-leds.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Jacek Anaszewski <jacek.anaszewski@gmail.com>
To: "Jan Kundrát" <jan.kundrat@cesnet.cz>, linux-leds@vger.kernel.org
Cc: "Dan Murphy" <dmurphy@ti.com>, "Pavel Machek" <pavel@ucw.cz>,
	"Andy Shevchenko" <andriy.shevchenko@linux.intel.com>,
	"Christophe JAILLET" <christophe.jaillet@wanadoo.fr>,
	"Marek Behún" <kabel@kernel.org>
Subject: Re: lp50xx: LED banking appears to be broken
Date: Tue, 3 Aug 2021 00:17:45 +0200	[thread overview]
Message-ID: <b3fc778d-c94e-c8a3-3f3b-84e146a08627@gmail.com> (raw)
In-Reply-To: <d049e22d-5ff8-4a68-a46c-3a1d533afcd0@cesnet.cz>

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

      reply	other threads:[~2021-08-02 22:17 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-07-31  8:14 lp50xx: LED banking appears to be broken Jan Kundrát
2021-08-02 22:17 ` Jacek Anaszewski [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=b3fc778d-c94e-c8a3-3f3b-84e146a08627@gmail.com \
    --to=jacek.anaszewski@gmail.com \
    --cc=andriy.shevchenko@linux.intel.com \
    --cc=christophe.jaillet@wanadoo.fr \
    --cc=dmurphy@ti.com \
    --cc=jan.kundrat@cesnet.cz \
    --cc=kabel@kernel.org \
    --cc=linux-leds@vger.kernel.org \
    --cc=pavel@ucw.cz \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).