mbox series

[v2,0/7] Add support for MT6331 and MT6332 LEDs

Message ID 20230412153310.241046-1-angelogioacchino.delregno@collabora.com
Headers show
Series Add support for MT6331 and MT6332 LEDs | expand

Message

AngeloGioacchino Del Regno April 12, 2023, 3:33 p.m. UTC
Changes in v2:
 - Rebase over next-20230412

NOTE: Since v1 of this series was sent in Semptember 2022 and got
ignored for *7 months* with no feedback, I'm retrying the upstreaming
of this same series.
There are no changes, if not just a simple rebase and another test
run on the same hardware.


MT6323 is not the only PMIC that has a LEDs controller IP and it was
found that the others do have a compatible register layout, except
for some register offsets.
The logic contained in this driver can be totally reused for other
PMICs as well, so I can't see any reason to keep this specific to
the MT6323 part.

This series brings meaningful platform data to this driver, giving
it flexibility and adding support for LED controllers found in the
MT6331 and MT6332 PMICs.

Tested on MT6795 Sony Xperia M5 smartphone.

AngeloGioacchino Del Regno (7):
  dt-bindings: leds: leds-mt6323: Document mt6331 compatible
  dt-bindings: leds: leds-mt6323: Document mt6332 compatible
  leds: leds-mt6323: Specify registers and specs in platform data
  leds: leds-mt6323: Open code and drop MT6323_CAL_HW_DUTY macro
  leds: leds-mt6323: Drop MT6323_ prefix from macros and defines
  leds: leds-mt6323: Add support for MT6331 leds
  leds: leds-mt6323: Add support for WLEDs and MT6332

 .../devicetree/bindings/leds/leds-mt6323.txt  |   5 +-
 drivers/leds/leds-mt6323.c                    | 444 ++++++++++++++----
 2 files changed, 350 insertions(+), 99 deletions(-)

Comments

Alexandre Mergnat April 13, 2023, 8:35 a.m. UTC | #1
On 12/04/2023 17:33, AngeloGioacchino Del Regno wrote:
> Add mediatek,mt6331-led compatible for the LED controller found
> in the MT6331 PMIC.
> 
> Signed-off-by: AngeloGioacchino Del Regno<angelogioacchino.delregno@collabora.com>
> Acked-by: Krzysztof Kozlowski<krzysztof.kozlowski@linaro.org>

Reviewed-by: Alexandre Mergnat <amergnat@baylibre.com>
Alexandre Mergnat April 13, 2023, 10:11 a.m. UTC | #2
On 12/04/2023 17:33, AngeloGioacchino Del Regno wrote:
> In order to enhance the flexibility of this driver and let it support
> more than just one MediaTek LEDs IP for more than just one PMIC,
> add platform data structure specifying the register offsets and
> data that commonly varies between different IPs.
> 
> This commit brings no functional changes.
> 
> Signed-off-by: AngeloGioacchino Del Regno <angelogioacchino.delregno@collabora.com>
> ---
>   drivers/leds/leds-mt6323.c | 145 ++++++++++++++++++++++++++++---------
>   1 file changed, 112 insertions(+), 33 deletions(-)
> 
> diff --git a/drivers/leds/leds-mt6323.c b/drivers/leds/leds-mt6323.c
> index 17ee88043f52..a5b2d06e9d63 100644
> --- a/drivers/leds/leds-mt6323.c
> +++ b/drivers/leds/leds-mt6323.c
> @@ -37,18 +37,16 @@
>    * Register for MT6323_ISINK_CON0 to setup the

Comment should be changed.

>    * duty cycle of the blink.
>    */
> -#define MT6323_ISINK_CON0(i)		(MT6323_ISINK0_CON0 + 0x8 * (i))
> +#define MT6323_ISINK_CON(r, i)		(r + 0x8 * (i))
>   #define MT6323_ISINK_DIM_DUTY_MASK	(0x1f << 8)
>   #define MT6323_ISINK_DIM_DUTY(i)	(((i) << 8) & \
>   					MT6323_ISINK_DIM_DUTY_MASK)
>   


After that, it should be ok.

Reviewed-by: Alexandre Mergnat <amergnat@baylibre.com>

Regards,
Alexandre
Pavel Machek April 13, 2023, 10:49 a.m. UTC | #3
Hi!

> Changes in v2:
>  - Rebase over next-20230412
> 
> NOTE: Since v1 of this series was sent in Semptember 2022 and got
> ignored for *7 months* with no feedback, I'm retrying the upstreaming
> of this same series.
> There are no changes, if not just a simple rebase and another test
> run on the same hardware.
> 
> 
> MT6323 is not the only PMIC that has a LEDs controller IP and it was
> found that the others do have a compatible register layout, except
> for some register offsets.
> The logic contained in this driver can be totally reused for other
> PMICs as well, so I can't see any reason to keep this specific to
> the MT6323 part.
> 
> This series brings meaningful platform data to this driver, giving
> it flexibility and adding support for LED controllers found in the
> MT6331 and MT6332 PMICs.
> 
> Tested on MT6795 Sony Xperia M5 smartphone.

Please cc phone-devel with phone related stuff.

Can I get ls /sys/class/leds on that machine?

BR,
								Pavel
Pavel Machek April 13, 2023, 10:57 a.m. UTC | #4
Hi!

> In order to enhance the flexibility of this driver and let it support
> more than just one MediaTek LEDs IP for more than just one PMIC,
> add platform data structure specifying the register offsets and
> data that commonly varies between different IPs.
> 
> This commit brings no functional changes.

> @@ -63,12 +61,9 @@
>  #define MT6323_ISINK_CH_EN_MASK(i)	BIT(i)
>  #define MT6323_ISINK_CH_EN(i)		BIT(i)
>  
> -#define MT6323_MAX_PERIOD		10000
> -#define MT6323_MAX_LEDS			4
> -#define MT6323_MAX_BRIGHTNESS		6
> -#define MT6323_UNIT_DUTY		3125
> -#define MT6323_CAL_HW_DUTY(o, p)	DIV_ROUND_CLOSEST((o) * 100000ul,\
> -					(p) * MT6323_UNIT_DUTY)
> +#define MAX_SUPPORTED_LEDS		8
> +#define MT6323_CAL_HW_DUTY(o, p, u)	DIV_ROUND_CLOSEST((o) * 100000ul,\
> +					(p) * (u))
>

You increase number of supported leds from 4 to 8. That's ok, but I'd
not call it "no functional changes".

> +/**
> + * struct mt6323_regs - register spec for the LED device
> + * @top_ckpdn:		Offset to ISINK_CKPDN[0..x] registers
> + * @num_top_ckpdn:	Number of ISINK_CKPDN registers
> + * @top_ckcon:		Offset to ISINK_CKCON[0..x] registers
> + * @num_top_ckcon:	Number of ISINK_CKCON registers
> + * @isink_con:		Offset to ISINKx_CON[0..x] registers
> + * @num_isink_con:	Number of ISINKx_CON registers
> + * @isink_max_regs:	Number of ISINK[0..x] registers
> + * @isink_en_ctrl:	Offset to ISINK_EN_CTRL register
> + */
> +struct mt6323_regs {
> +	const u16 *top_ckpdn;
> +	u8 num_top_ckpdn;
> +	const u16 *top_ckcon;
> +	u8 num_top_ckcon;
> +	const u16 *isink_con;
> +	u8 num_isink_con;
> +	u8 isink_max_regs;
> +	u16 isink_en_ctrl;
> +};

I'd use ints here. Should get similar memory usage and maybe less code
size. But ... no need to resubmit just for this.

> @@ -469,8 +525,31 @@ static int mt6323_led_remove(struct platform_device *pdev)
>  	return 0;
>  }
>  
> +static const struct mt6323_regs mt6323_registers = {
> +	.top_ckpdn = (const u16[]){ 0x102, 0x106, 0x10e },
> +	.num_top_ckpdn = 3,
> +	.top_ckcon = (const u16[]){ 0x120, 0x126 },
> +	.num_top_ckcon = 2,
> +	.isink_con = (const u16[]){ 0x330, 0x332, 0x334 },
> +	.num_isink_con = 3,
> +	.isink_max_regs = 4, /* ISINK[0..3] */
> +	.isink_en_ctrl = 0x356,
> +};
> +
> +static const struct mt6323_hwspec mt6323_spec = {
> +	.max_period = 10000,
> +	.max_leds = 4,
> +	.max_brightness = 6,
> +	.unit_duty = 3125,
> +};
> +
> +static const struct mt6323_data mt6323_pdata = {
> +	.regs = &mt6323_registers,
> +	.spec = &mt6323_spec,
> +};
> +

Acked-by: Pavel Machek <pavel@ucw.cz>

BR,
								Pavel
Pavel Machek April 13, 2023, 11:06 a.m. UTC | #5
Hi!

> 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.


> @@ -467,14 +590,24 @@ static int mt6323_led_probe(struct platform_device *pdev)
>  			goto put_child_node;
>  		}
>  
> +		is_wled = of_property_read_bool(child, "mediatek,is-wled");
> +

This needs documenting in the binding, no?

> +static const struct mt6323_hwspec mt6332_spec = {
> +	/* There are no LEDs in MT6332. Only WLEDs are present. */

"Only WLED is present"? 

> +	.max_leds = 0,
> +	.max_wleds = 1,
> +	.max_brightness = 1024,
> +};
> +

Is there chip with both LED and WLEDs? (I'm wondering if this makes
sense in single driver).

Best regards,
								Pavel
AngeloGioacchino Del Regno April 13, 2023, 11:29 a.m. UTC | #6
Il 13/04/23 13:06, Pavel Machek ha scritto:
> Hi!
> 
>> 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.
> 
> 
>> @@ -467,14 +590,24 @@ static int mt6323_led_probe(struct platform_device *pdev)
>>   			goto put_child_node;
>>   		}
>>   
>> +		is_wled = of_property_read_bool(child, "mediatek,is-wled");
>> +
> 
> This needs documenting in the binding, no?
> 
>> +static const struct mt6323_hwspec mt6332_spec = {
>> +	/* There are no LEDs in MT6332. Only WLEDs are present. */
> 
> "Only WLED is present"?
> 
>> +	.max_leds = 0,
>> +	.max_wleds = 1,
>> +	.max_brightness = 1024,
>> +};
>> +
> 
> Is there chip with both LED and WLEDs? (I'm wondering if this makes
> sense in single driver).
> 

Some PMICs have got both LED(s) and WLED(s), yes - this is only on smartphone
designs though.

Regards,
Angelo
AngeloGioacchino Del Regno April 13, 2023, 11:31 a.m. UTC | #7
Il 13/04/23 12:49, Pavel Machek ha scritto:
> Hi!
> 
>> Changes in v2:
>>   - Rebase over next-20230412
>>
>> NOTE: Since v1 of this series was sent in Semptember 2022 and got
>> ignored for *7 months* with no feedback, I'm retrying the upstreaming
>> of this same series.
>> There are no changes, if not just a simple rebase and another test
>> run on the same hardware.
>>
>>
>> MT6323 is not the only PMIC that has a LEDs controller IP and it was
>> found that the others do have a compatible register layout, except
>> for some register offsets.
>> The logic contained in this driver can be totally reused for other
>> PMICs as well, so I can't see any reason to keep this specific to
>> the MT6323 part.
>>
>> This series brings meaningful platform data to this driver, giving
>> it flexibility and adding support for LED controllers found in the
>> MT6331 and MT6332 PMICs.
>>
>> Tested on MT6795 Sony Xperia M5 smartphone.
> 
> Please cc phone-devel with phone related stuff.

Sorry, I completely forgot to :-(

> 
> Can I get ls /sys/class/leds on that machine?

Yes you can, but that will require some time, as I'm on other tasks.
I should be able to provide that next week, sorry for the delay!

Regards,
Angelo
AngeloGioacchino Del Regno April 13, 2023, 11:32 a.m. UTC | #8
Il 13/04/23 13:06, Pavel Machek ha scritto:
> Hi!
> 
>> 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.
> 
> 
>> @@ -467,14 +590,24 @@ static int mt6323_led_probe(struct platform_device *pdev)
>>   			goto put_child_node;
>>   		}
>>   
>> +		is_wled = of_property_read_bool(child, "mediatek,is-wled");
>> +
> 
> This needs documenting in the binding, no?

Yes, and I forgot to. Would it be okay if I send a supplementary patch out
of this series to document that since the bindings are already acked?

Regards,
Angelo
Alexandre Mergnat April 13, 2023, 1:06 p.m. UTC | #9
On 12/04/2023 17:33, AngeloGioacchino Del Regno wrote:
> There is only one instance of using this macro and it's anyway not
> simplifying the flow, or increasing the readability of this driver.
> 
> Drop this macro by open coding it in mt6323_led_set_blink().
> 
> No functional changes.
> 
> Signed-off-by: AngeloGioacchino Del Regno<angelogioacchino.delregno@collabora.com>

Reviewed-by: Alexandre Mergnat <amergnat@baylibre.com>
Alexandre Mergnat April 13, 2023, 2:15 p.m. UTC | #10
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
> @@ -20,6 +20,11 @@
>   #define RG_DRV_32K_CK_PDN		BIT(11)
>   #define RG_DRV_32K_CK_PDN_MASK		BIT(11)
>   
> +/* 32K/1M/6M clock common for WLED device */
> +#define RG_VWLED_1M_CK_PDN		BIT(0)
> +#define RG_VWLED_32K_CK_PDN		BIT(12)
> +#define RG_VWLED_6M_CK_PDN		BIT(13)
> +
>   /*
>    * Register field for TOP_CKPDN2 to enable
>    * individual clock for LED device.
> @@ -73,7 +78,7 @@ struct mt6323_led {
>   	int			id;
>   	struct mt6323_leds	*parent;
>   	struct led_classdev	cdev;
> -	enum led_brightness	current_brightness;
> +	unsigned int		current_brightness;
>   };
>   
>   /**
> @@ -86,6 +91,7 @@ struct mt6323_led {
>    * @num_isink_con:	Number of ISINKx_CON registers
>    * @isink_max_regs:	Number of ISINK[0..x] registers
>    * @isink_en_ctrl:	Offset to ISINK_EN_CTRL register
> + * @iwled_en_ctrl:	Offset to IWLED_EN_CTRL register
>    */
>   struct mt6323_regs {
>   	const u16 *top_ckpdn;
> @@ -96,18 +102,21 @@ struct mt6323_regs {
>   	u8 num_isink_con;
>   	u8 isink_max_regs;
>   	u16 isink_en_ctrl;
> +	u16 iwled_en_ctrl;
>   };
>   
>   /**
>    * struct mt6323_hwspec - hardware specific parameters
>    * @max_period:		Maximum period for all LEDs
>    * @max_leds:		Maximum number of supported LEDs
> + * @max_wleds:		Maximum number of WLEDs
>    * @max_brightness:	Maximum brightness for all LEDs
>    * @unit_duty:		Steps of duty per period
>    */
>   struct mt6323_hwspec {
>   	u16 max_period;
>   	u8 max_leds;
> +	u8 max_wleds;
>   	u16 max_brightness;
>   	u16 unit_duty;
>   };
> @@ -379,6 +388,117 @@ static int mt6323_led_set_brightness(struct led_classdev *cdev,
>   	return ret;
>   }
>   
> +static int mtk_wled_hw_on(struct led_classdev *cdev)
> +{
> +	struct mt6323_led *led = container_of(cdev, struct mt6323_led, cdev);
> +	struct mt6323_leds *leds = led->parent;
> +	const struct mt6323_regs *regs = leds->pdata->regs;
> +	struct regmap *regmap = leds->hw->regmap;
> +	int ret;
> +
> +	ret = regmap_clear_bits(regmap, regs->top_ckpdn[0], RG_VWLED_32K_CK_PDN);
> +	if (ret)
> +		return ret;
> +
> +	ret = regmap_clear_bits(regmap, regs->top_ckpdn[0], RG_VWLED_6M_CK_PDN);
> +	if (ret)
> +		return ret;
> +
> +	ret = regmap_clear_bits(regmap, regs->top_ckpdn[0], RG_VWLED_1M_CK_PDN);
> +	if (ret)
> +		return ret;
> +
> +	usleep_range(5000, 6000);
> +
> +	/* Enable WLED channel pair */
> +	ret = regmap_set_bits(regmap, regs->iwled_en_ctrl, BIT(led->id));
> +	if (ret)
> +		return ret;
> +
> +	ret = regmap_set_bits(regmap, regs->iwled_en_ctrl, BIT(led->id + 1));
> +	if (ret)
> +		return ret;
> +
> +	return 0;
> +}
> +
> +static int mtk_wled_hw_off(struct led_classdev *cdev)
> +{
> +	struct mt6323_led *led = container_of(cdev, struct mt6323_led, cdev);
> +	struct mt6323_leds *leds = led->parent;
> +	const struct mt6323_regs *regs = leds->pdata->regs;
> +	struct regmap *regmap = leds->hw->regmap;
> +	int ret;
> +
> +	ret = regmap_clear_bits(regmap, regs->iwled_en_ctrl, BIT(led->id + 1));
> +	if (ret)
> +		return ret;
> +
> +	ret = regmap_clear_bits(regmap, regs->iwled_en_ctrl, BIT(led->id));
> +	if (ret)
> +		return ret;
> +
> +	ret = regmap_set_bits(regmap, regs->top_ckpdn[0], RG_VWLED_32K_CK_PDN);
> +	if (ret)
> +		return ret;
> +
> +	ret = regmap_set_bits(regmap, regs->top_ckpdn[0], RG_VWLED_6M_CK_PDN);
> +	if (ret)
> +		return ret;
> +
> +	ret = regmap_set_bits(regmap, regs->top_ckpdn[0], RG_VWLED_1M_CK_PDN);
> +	if (ret)
> +		return ret;
> +
> +	return 0;
> +}
> +
> +static unsigned int mt6323_get_wled_brightness(struct led_classdev *cdev)
> +{
> +	struct mt6323_led *led = container_of(cdev, struct mt6323_led, cdev);
> +	struct mt6323_leds *leds = led->parent;
> +	const struct mt6323_regs *regs = leds->pdata->regs;
> +	struct regmap *regmap = leds->hw->regmap;
> +	unsigned int status;
> +	int ret;
> +
> +	ret = regmap_read(regmap, regs->iwled_en_ctrl, &status);
> +	if (ret)
> +		return 0;
> +
> +	/* Always two channels per WLED */
> +	status &= BIT(led->id) | BIT(led->id + 1);
> +
> +	return status ? led->current_brightness : 0;
> +}
> +
> +static int mt6323_wled_set_brightness(struct led_classdev *cdev,
> +				      unsigned int brightness)
> +{
> +	struct mt6323_led *led = container_of(cdev, struct mt6323_led, cdev);
> +	struct mt6323_leds *leds = led->parent;
> +	int ret = 0;
> +
> +	mutex_lock(&leds->lock);
> +
> +	if (brightness) {
> +		if (!led->current_brightness)
> +			ret = mtk_wled_hw_on(cdev);
> +		if (ret)
> +			goto out;
> +	} else {
> +		ret = mtk_wled_hw_off(cdev);
> +		if (ret)
> +			goto out;
> +	}
> +
> +	led->current_brightness = brightness;
> +out:
> +	mutex_unlock(&leds->lock);
> +
> +	return ret;
> +}
> +
>   static int mt6323_led_set_dt_default(struct led_classdev *cdev,
>   				     struct device_node *np)
>   {
> @@ -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 ?

>   
>   	/*
>   	 * leds->hw points to the underlying bus for the register
> @@ -447,6 +569,7 @@ static int mt6323_led_probe(struct platform_device *pdev)
>   
>   	for_each_available_child_of_node(np, child) {
>   		struct led_init_data init_data = {};
> +		bool is_wled;
>   
>   		ret = of_property_read_u32(child, "reg", &reg);
>   		if (ret) {
> @@ -454,7 +577,7 @@ static int mt6323_led_probe(struct platform_device *pdev)
>   			goto put_child_node;
>   		}
>   
> -		if (reg >= spec->max_leds || reg >= MAX_SUPPORTED_LEDS ||
> +		if (reg >= max_leds || reg >= MAX_SUPPORTED_LEDS ||
>   		    leds->led[reg]) {
>   			dev_err(dev, "Invalid led reg %u\n", reg);
>   			ret = -EINVAL;
> @@ -467,14 +590,24 @@ static int mt6323_led_probe(struct platform_device *pdev)
>   			goto put_child_node;
>   		}
>   
> +		is_wled = of_property_read_bool(child, "mediatek,is-wled");
> +
>   		leds->led[reg] = led;
>   		leds->led[reg]->id = reg;
>   		leds->led[reg]->cdev.max_brightness = spec->max_brightness;
> -		leds->led[reg]->cdev.brightness_set_blocking =
> -					mt6323_led_set_brightness;
> -		leds->led[reg]->cdev.blink_set = mt6323_led_set_blink;
> -		leds->led[reg]->cdev.brightness_get =
> -					mt6323_get_led_hw_brightness;
> +
> +		if (is_wled) {
> +			leds->led[reg]->cdev.brightness_set_blocking =
> +						mt6323_wled_set_brightness;
> +			leds->led[reg]->cdev.brightness_get =
> +						mt6323_get_wled_brightness;
> +		} else {
> +			leds->led[reg]->cdev.brightness_set_blocking =
> +						mt6323_led_set_brightness;
> +			leds->led[reg]->cdev.blink_set = mt6323_led_set_blink;
> +			leds->led[reg]->cdev.brightness_get =
> +						mt6323_get_led_hw_brightness;
> +		}
>   		leds->led[reg]->parent = leds;
>   
>   		ret = mt6323_led_set_dt_default(&leds->led[reg]->cdev, child);
> @@ -542,6 +675,17 @@ static const struct mt6323_regs mt6331_registers = {
>   	.isink_en_ctrl = 0x43a,
>   };
>   
> +static const struct mt6323_regs mt6332_registers = {
> +	.top_ckpdn = (const u16[]){ 0x8094, 0x809a, 0x80a0 },
> +	.num_top_ckpdn = 3,
> +	.top_ckcon = (const u16[]){ 0x80a6, 0x80ac },
> +	.num_top_ckcon = 2,
> +	.isink_con = (const u16[]){ 0x8cd4 },
> +	.num_isink_con = 1,
> +	.isink_max_regs = 12, /* IWLED[0..2, 3..9] */
> +	.iwled_en_ctrl = 0x8cda,
> +};
> +
>   static const struct mt6323_hwspec mt6323_spec = {
>   	.max_period = 10000,
>   	.max_leds = 4,
> @@ -549,6 +693,13 @@ static const struct mt6323_hwspec mt6323_spec = {
>   	.unit_duty = 3125,
>   };
>   
> +static const struct mt6323_hwspec mt6332_spec = {
> +	/* There are no LEDs in MT6332. Only WLEDs are present. */
> +	.max_leds = 0,
> +	.max_wleds = 1,
> +	.max_brightness = 1024,
> +};
> +
>   static const struct mt6323_data mt6323_pdata = {
>   	.regs = &mt6323_registers,
>   	.spec = &mt6323_spec,
> @@ -559,9 +710,15 @@ static const struct mt6323_data mt6331_pdata = {
>   	.spec = &mt6323_spec,
>   };
>   
> +static const struct mt6323_data mt6332_pdata = {
> +	.regs = &mt6332_registers,
> +	.spec = &mt6332_spec,
> +};
> +
>   static const struct of_device_id mt6323_led_dt_match[] = {
>   	{ .compatible = "mediatek,mt6323-led", .data = &mt6323_pdata},
>   	{ .compatible = "mediatek,mt6331-led", .data = &mt6331_pdata },
> +	{ .compatible = "mediatek,mt6332-led", .data = &mt6332_pdata },
>   	{},
>   };
>   MODULE_DEVICE_TABLE(of, mt6323_led_dt_match);
Lee Jones April 14, 2023, 7:07 a.m. UTC | #11
On Thu, 13 Apr 2023, AngeloGioacchino Del Regno wrote:

> Il 13/04/23 13:06, Pavel Machek ha scritto:
> > Hi!
> >
> > > 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.
> >
> >
> > > @@ -467,14 +590,24 @@ static int mt6323_led_probe(struct platform_device *pdev)
> > >   			goto put_child_node;
> > >   		}
> > > +		is_wled = of_property_read_bool(child, "mediatek,is-wled");
> > > +
> >
> > This needs documenting in the binding, no?
>
> Yes, and I forgot to. Would it be okay if I send a supplementary patch out
> of this series to document that since the bindings are already acked?

You can add the support as part of a new patch.

Please resend this series with it attached.

--
Lee Jones [李琼斯]
AngeloGioacchino Del Regno April 14, 2023, 7:09 a.m. UTC | #12
Il 14/04/23 09:07, Lee Jones ha scritto:
> On Thu, 13 Apr 2023, AngeloGioacchino Del Regno wrote:
> 
>> Il 13/04/23 13:06, Pavel Machek ha scritto:
>>> Hi!
>>>
>>>> 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.
>>>
>>>
>>>> @@ -467,14 +590,24 @@ static int mt6323_led_probe(struct platform_device *pdev)
>>>>    			goto put_child_node;
>>>>    		}
>>>> +		is_wled = of_property_read_bool(child, "mediatek,is-wled");
>>>> +
>>>
>>> This needs documenting in the binding, no?
>>
>> Yes, and I forgot to. Would it be okay if I send a supplementary patch out
>> of this series to document that since the bindings are already acked?
> 
> You can add the support as part of a new patch.
> 
> Please resend this series with it attached.
> 
Perfect - will do!

Thanks,
Angelo
AngeloGioacchino Del Regno April 14, 2023, 10:19 a.m. UTC | #13
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