Re: [PATCH v2 7/7] leds: leds-mt6323: Add support for WLEDs and MT6332

AngeloGioacchino Del Regno
2023-04-14T10:20:47Z

Il 13/04/23 16:15, Alexandre Mergnat ha scritto:
> On 12/04/2023 17:33, AngeloGioacchino Del Regno wrote:
>> Add basic code to turn on and off WLEDs and wire up MT6332 support
>> to take advantage of it.
>> This is a simple approach due to to the aforementioned PMIC supporting
>> only on/off status so, at the time of writing, it is impossible for me
>> to validate more advanced functionality due to lack of hardware.
>>
>> Signed-off-by: AngeloGioacchino Del Regno <angelogioacchino.delregno@collabora.com>
>> ---
>>   drivers/leds/leds-mt6323.c | 171 +++++++++++++++++++++++++++++++++++--
>>   1 file changed, 164 insertions(+), 7 deletions(-)
>>
>> diff --git a/drivers/leds/leds-mt6323.c b/drivers/leds/leds-mt6323.c
>> index 5d95dbd9a761..202b38ac32f6 100644
>> --- a/drivers/leds/leds-mt6323.c
>> +++ b/drivers/leds/leds-mt6323.c

..snip..

>> @@ -418,6 +538,7 @@ static int mt6323_led_probe(struct platform_device *pdev)
>>       int ret;
>>       unsigned int status;
>>       u32 reg;
>> +    u8 max_leds;
>>       leds = devm_kzalloc(dev, sizeof(*leds), GFP_KERNEL);
>>       if (!leds)
>> @@ -428,6 +549,7 @@ static int mt6323_led_probe(struct platform_device *pdev)
>>       leds->pdata = device_get_match_data(dev);
>>       regs = leds->pdata->regs;
>>       spec = leds->pdata->spec;
>> +    max_leds = spec->max_leds + spec->max_wleds;
>
> I haven't access to the datasheet so I have to ask you:
> Why the max leds value is the addition of max led and wled ?
>
> IMO, the datasheed give you the max supported led OR wled on its bus function to
> the maximum supplied current by the PMIC (I assume LED or WLED have different
> need). Or the PMIC has 2 bus, one for led and another for wled ?
>

I don't have access to the datasheet for MT6332 as well - but anyway, the only
purpose of the max_leds variable is to validate the maximum number of 'reg'
spaces that we're supposed to read from devicetree, that's all.

The alternative would've been to check if there's any led, then any wled in the
mt6323_hwspec from platform data - then:

if only wleds, max_leds = wleds;
else if only leds, max_leds = leds;
else if leds and wleds, max_leds = leds + wleds;

You see that it doesn't make any sense to do such check, and we can go with
just adding wleds+leds.

Regards,
Angelo