lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-Id: <D9XLOWTZPRC4.EHVI8W16H3J9@bootlin.com>
Date: Fri, 16 May 2025 14:57:29 +0200
From: "Mathieu Dubois-Briand" <mathieu.dubois-briand@...tlin.com>
To: Uwe Kleine-König <ukleinek@...nel.org>
Cc: "Lee Jones" <lee@...nel.org>, "Rob Herring" <robh@...nel.org>,
 "Krzysztof Kozlowski" <krzk+dt@...nel.org>, "Conor Dooley"
 <conor+dt@...nel.org>, "Kamel Bouhara" <kamel.bouhara@...tlin.com>, "Linus
 Walleij" <linus.walleij@...aro.org>, "Bartosz Golaszewski" <brgl@...ev.pl>,
 "Dmitry Torokhov" <dmitry.torokhov@...il.com>, "Michael Walle"
 <mwalle@...nel.org>, "Mark Brown" <broonie@...nel.org>, "Greg
 Kroah-Hartman" <gregkh@...uxfoundation.org>, "Rafael J. Wysocki"
 <rafael@...nel.org>, "Danilo Krummrich" <dakr@...nel.org>,
 <devicetree@...r.kernel.org>, <linux-kernel@...r.kernel.org>,
 <linux-gpio@...r.kernel.org>, <linux-input@...r.kernel.org>,
 <linux-pwm@...r.kernel.org>, <andriy.shevchenko@...el.com>,
 Grégory Clement <gregory.clement@...tlin.com>, "Thomas
 Petazzoni" <thomas.petazzoni@...tlin.com>
Subject: Re: [PATCH v8 04/11] pwm: max7360: Add MAX7360 PWM support

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@...tlin.com wrote:
>>> From: Kamel Bouhara <kamel.bouhara@...tlin.com>
>>> ...
>>>
>>> +
>>> +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


Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ