Re: [PATCH v8 04/11] pwm: max7360: Add MAX7360 PWM support

From: Mathieu Dubois-Briand
Date: Fri May 16 2025 - 08:57:48 EST


On Thu May 15, 2025 at 9:14 AM CEST, Mathieu Dubois-Briand wrote:
> On Tue May 13, 2025 at 12:08 PM CEST, Uwe Kleine-König wrote:
>> Hello,
>>
>> On Fri, May 09, 2025 at 11:14:38AM +0200, mathieu.dubois-briand@xxxxxxxxxxx wrote:
>>> From: Kamel Bouhara <kamel.bouhara@xxxxxxxxxxx>
>>> ...
>>>
>>> +
>>> +static int max7360_pwm_request(struct pwm_chip *chip, struct pwm_device *pwm)
>>> +{
>>> + struct regmap *regmap = pwmchip_get_drvdata(chip);
>>> + int ret;
>>> +
>>> + ret = regmap_write_bits(regmap, MAX7360_REG_PWMCFG(pwm->hwpwm),
>>> + MAX7360_PORT_CFG_COMMON_PWM, 0);
>>> + if (ret)
>>> + return ret;
>>> +
>>> + return regmap_write_bits(regmap, MAX7360_REG_PORTS, BIT(pwm->hwpwm), BIT(pwm->hwpwm));
>>
>> What is the effect of these writes? It doesn't need to be undone in a
>> matching .free()?
>>
>
> The first one (MAX7360_PORT_CFG_COMMON_PWM) asks to use a specific duty
> cycle for this PWM output and not a value shared across all PWMs. I
> believe this one have no reason to be ever reverted.
>
> About the second one, it does switch the output value. Reading the
> datasheet, it's not clear if and why setting this here is required. I
> will make some tests on the hardware a bit later this week. Still, I
> believe there is no need to revert it later.
>

I just tested it, I confirm we can remove the second one.

>>> +}
>>>
>>> ...
>>>
>>> +static int max7360_pwm_write_waveform(struct pwm_chip *chip,
>>> + struct pwm_device *pwm,
>>> + const void *_wfhw)
>>> +{
>>> + struct regmap *regmap = pwmchip_get_drvdata(chip);
>>> + const struct max7360_pwm_waveform *wfhw = _wfhw;
>>> + unsigned int val;
>>> + int ret;
>>> +
>>> + val = wfhw->enabled ? BIT(pwm->hwpwm) : 0;
>>> + ret = regmap_write_bits(regmap, MAX7360_REG_GPIOCTRL, BIT(pwm->hwpwm), val);
>>> + if (ret)
>>> + return ret;
>>> +
>>> + if (wfhw->duty_steps)
>>> + return regmap_write(regmap, MAX7360_REG_PWM(pwm->hwpwm), wfhw->duty_steps);
>>
>> Would it make sense to first write duty_steps and only then enable?
>> Otherwise it might happen that you enable and still have a wrong duty
>> configuration in the MAX7360_REG_PWM register and emit a wrong period?
>>
>
> Yes, I believe it does make sense: I will try to invert them.
>

Also tested, and everything seems to be working fine: I will go this
way.

>> Do you need to write duty_steps = 0 if enabled is false?
>>
>
> No, this is not needed: output will be in hi-Z mode. As we have
> "wfhw->enabled = !!wf->duty_length_ns", this should be correct here. But
> reading this, I believe I could modify above code to be more clear with:
>
> if (wfhw->enabled)
> return regmap_write(regmap, MAX7360_REG_PWM(pwm->hwpwm), wfhw->duty_steps);
>
>
>>> + return 0;
>>> +}
>>
>> Best regards
>> Uwe

Best regards,
Mathieu

--
Mathieu Dubois-Briand, Bootlin
Embedded Linux and Kernel engineering
https://bootlin.com