Re: [PATCH v4 6/9] leds: multicolor: Introduce a multicolor class definition

From: Jacek Anaszewski
Date: Fri Aug 02 2019 - 15:27:45 EST


Dan,

On 8/2/19 4:14 PM, Dan Murphy wrote:
> Jacek
>
> On 7/31/19 3:44 PM, Jacek Anaszewski wrote:
>> Dan,
>>
> [...]
>> +ÂÂÂ for (i = 0; i < mcled_cdev->num_leds; i++) {
>> +ÂÂÂÂÂÂÂ ret = sscanf(buf + offset, "%i%n", &value[i], &nrchars);
>> +ÂÂÂÂÂÂÂ if (ret != 1)
>> +ÂÂÂÂÂÂÂÂÂÂÂ break;
>> +
>> +ÂÂÂÂÂÂÂ offset += nrchars;
>> +ÂÂÂ }
>> +
>> +ÂÂÂ if (i != mcled_cdev->num_leds) {
>>>> Shouldn't we return error if i != mcled_cdev->num_leds - 1 ?
>>>> How can we know which color the value will be for if there is less
>>>> values passed than the total number of colors in the cluster?
>>> Ok so during my testing if I had the monochrome array as <R G B>
>>>
>>> When I wrote only <R G> and no blue I was getting random values in the
>>> array for the
>>>
>>> remaining indexes and the blue LED would randomly turn on/off at
>>> different levels.
>>>
>>> So if the user passes in less then expected only ids with data will be
>>> written and the other colors will be turned off by the for loop below.
>> ÂFrom what I see it will lead to wrong mapping of given color to the
>> value array element in the following case:
>>
>> echo "<green> <blue>" > color_mix
>>
>> Then green intensity will be assigned to value[0] (expects red) and blue
>> to value[1] (expects green). Unless I don't get something.
>> Your ABI documentation doesn't mention any way to redefine the color_id
>> returned by <color>/color_id file. And that is good.
>>
> This is exactly the issue I had previously brought up. The user would
> need to
>
> write all leading colors with a value, even if 0, to correctly set the
> target LEDs.
>
> We can protect against the trailing colors but not leading colors.
>
> The expectation is that the user space would read the color_id from the
> file and align
>
> the array accordingly. This is also why I exposed the intensity under
> the color so if the
>
> user wanted to not use color_mix file they can update the intensity per
> LED color.
>

I can't see the problem. Just require user to _always_ pass the number
of values equal to the number of colors under LED multicolor class
device. No more, no less. And fail it this condition is not met.

>>>>> +ÂÂÂÂÂÂÂ for (; i < LED_COLOR_ID_MAX; i++)
>>>>> +ÂÂÂÂÂÂÂÂÂÂÂ value[i] = 0;
>>>> What use case is it for?
>>> See above but this should be
>>>
>>> for (; i < mcled_cdev->num_leds; i++)
>>>
> I might be able to eliminate this loop by initializing the array to 0.
>
>
>>>>> +ÂÂÂ }
>>>>> +
>>>>> +ÂÂÂ list_for_each_entry(priv, &data->color_list, list) {
>>>>> +ÂÂÂÂÂÂÂ if (data->cluster_brightness) {
>>>>> +ÂÂÂÂÂÂÂÂÂÂÂ adj_brightness =
>>>>> calculate_brightness(data->cluster_brightness,
>>>>> +ÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂ value[priv->color_index],
>>>>> +ÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂ priv->max_intensity);
>>>>> +ÂÂÂÂÂÂÂÂÂÂÂ ret = ops->set_color_brightness(priv->mcled_cdev,
>>>>> +ÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂ priv->color_id,
>>>>> +ÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂ adj_brightness);
>>>>> +ÂÂÂÂÂÂÂÂÂÂÂ if (ret < 0)
>>>>> +ÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂ goto done;
>>>>> +ÂÂÂÂÂÂÂ }
>>>>> +
>>>>> +ÂÂÂÂÂÂÂ priv->intensity = value[priv->color_index];
>>>>> +ÂÂÂ }
>>>> Here we could use just brightness_set op as a single call. We should
>>>> always write all colors as a result of write to color_mix anyway.
>>> I guess what is gained by just passing the array down to the device
>>> driver and having it
>>>
>>> parse the array and do the peripheral call?
>> Those array values would not be directly written to the device,
>> but used for calculating the actual iout intensities. Driver
>> will just have to call calculate_brightness() (sticking to the naming
>> from this patch) and write the results calculated basing on brightness
>> and max_brightness.
>
> I would expect that we would do the same behavior for the color_mix file
> then.

Yes, this is what I meant while mentioning use of brightness_set op
for that. The final effect will be always the same - write of the
altered iout intensity registers. What will differ will be factors
of the equation that calculates iout intensity: for the call
originating from color_mix file the changing factor will be color
intensity and for the call originating from brightness file
it will be brightness. In both cases on the driver side we need
to call the same function to calculate iout values using the same
equation.

>
>> [...]
>>>>> +
>>>>> +ÂÂÂ priv->new_intensity = value;
>>>>> +
>>>>> +ÂÂÂ if (data->cluster_brightness) {
>>>>> +ÂÂÂÂÂÂÂ adj_value = calculate_brightness(data->cluster_brightness,
>>>>> +ÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂ priv->new_intensity,
>>>>> +ÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂ priv->max_intensity);
>>>>> +ÂÂÂÂÂÂÂ ret = ops->set_color_brightness(priv->mcled_cdev,
>>>>> +ÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂ priv->color_id, adj_value);
>>>>> +ÂÂÂÂÂÂÂ if (ret < 0) {
>>>>> +ÂÂÂÂÂÂÂÂÂÂÂ priv->new_intensity = priv->intensity;
>>>> This is unnecessary complication. Just write the calculated iout
>>>> intensity.
>>> Not sure what complication you are referring to.
>> The whole need for new_intensity and cluster_brightness, and then
>> bringing back old intensity value on set_color_brightness() failure.
>
> OK
>
>>
>>>> We need to highlight it in the documentation that exact requested color
>>>> intensity values are written to the hardware only when
>>>> brightness == max_brightness.
>>> But that is not a true statement. Thats not really how it was designed.
>> But it probably should be. It would simplify the design.
>>
>> So my idea is like I previously described the way I had first understood
>> this design:
>>
>> The colors set under colors directory don't reflect the iout
>> intensities, but are only used for calculating them, basing on the
>> brightness and max_intensity values.
>>
>> Effectively, after changing the colors/<color>/intensity the global
>> (legacy monochrome) brightness value will be still valid, since iout
>> color will be recalculated basing on it and the new color intensity.
>>
> OK. This this would remove the ops from the driver as it is no longer
> needed.
>
> The color_mix file will work the same way.

I've been pondering over the need for color_set, but it should be
indeed not needed too. Write to <color>/intensity file will also
call brightness_set - it will be comparing anyway old intensities
and new ones and will write only the affected register.


> What is the trigger then to update the LEDs?
>
> We cannot write the same brightness value to trigger as the class blocks
> calling down
>
> to the driver if brightness_in == brightness_current.

All files (intensity, color_mix and brightness) will use the same
brightness_set op for changing the iout values.

--
Best regards,
Jacek Anaszewski