Re: [RESEND PATCH v17 00/17] Multi Color LED Framework

From: Dan Murphy
Date: Wed Feb 26 2020 - 17:15:42 EST


Hello

On 2/26/20 2:45 PM, Jacek Anaszewski wrote:
Hi Greg,

We have here long lasting discussion related to LED multicolor class
sysfs interface design. We went through several iterations and worked
out the solution with individual file per each color sub-LED in the
color directory as shown below:

/sys/class/leds/<led>/colors/<color>_intensity

This is in line with one-value-per-file sysfs rule, that is being
frequently highlighted, and we even had not so long ago a patch
for led cpu trigger solving the problem caused by this rule not
being adhered to.

Now we have the voice below bringing to attention another caveat
from sysfs documentation:

"it is socially acceptable to express an array of values of the same
type"

and proposing the interface in the form of two files:

channel_intensity (file containing array of u32's)
channel_names (usually containing "red green blue")

In order to have this clarified once and for all, could you please
provide us with guidance on whether the fragment from
Documentation/filesystems/sysfs.txt is still in force and we
can benefit from it for LED multicolor framework, or not and then
it should be removed from the doc then?

I spent some time trying to find the conversation on the array implementation for the multi color framework.

It is buried here

https://lore.kernel.org/patchwork/patch/1026515/

The response from GKH on array's was sited in the above here:

https://www.spinics.net/lists/devicetree/msg69730.html

Repeating my objections to using arrays.

Would this array of colors be fixed?  Well the answer is it would be fixed per DT entries.  So if a user populates 10 LEDs for color then we will have 10 entries in the array.  Another DT entry may only have 3.  So the array size is variable but bounded for now assuming no additional colors are added.

Another issue with this implementation is we expect channel_names and channel_intensity arrays to be aligned.  Two different arrays need to line up so that each element value in channel_intensity matches the color in the channel_name.   This can be very easily mixed up in the HLOS if the proper array tracking is not done. Can we guarantee that the values we are getting are for the LED they are targeted for?

Would this array be bounded?  Bounded yes by the number of supported color IDs we have defined in the LED file.  But the size of the array is completely variable from device to device

Specific LEDs cannot be updated without re-sending the whole array.  If the user would like to change just 1 color and it is the nth position (possibly 10th from above) then all color intensities need to be passed.  There would be no way to say I want "red" at the 10th position to be 128 without passing in all the other color values as well.  So the caller needs to keep a cache of the current values or call the framework to get the current values just to pass them back in. This seems more expensive then writing 2 sysfs files as writing to the color/<color> intensity file does not perform any I/O it merely caches the values.  With the array the framework would need to process all the elements in the array every time the array is passed.  And then still call the brightness file to update the color outputs.  So we still have at minimum two sysfs accesses.

Neither implementation is perfect.

Maybe we need to ask GKH to host this in the staging directory and actually get some feedback from users as opposed to imposing our will on people.

Not sure if the ABI's can change in staging.

Dan