Re: [PATCH v2] regulator: rpi-panel-v2: Convert to new PWM waveform ops

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Hello Marek,

On Thu, Sep 04, 2025 at 11:05:28PM +0200, Marek Vasut wrote:
> Convert the driver from legacy PWM apply ops to modern waveform ops.
> There is no functional change.
> 
> Signed-off-by: Marek Vasut <marek.vasut+renesas@xxxxxxxxxxx>
> ---
> Cc: "Uwe Kleine-König" <ukleinek@xxxxxxxxxx>
> Cc: Dave Stevenson <dave.stevenson@xxxxxxxxxxxxxxx>
> Cc: Liam Girdwood <lgirdwood@xxxxxxxxx>
> Cc: Mark Brown <broonie@xxxxxxxxxx>
> Cc: linux-pwm@xxxxxxxxxxxxxxx
> Cc: linux-renesas-soc@xxxxxxxxxxxxxxx
> ---
> V2: - Safeguard against wf->duty_length_ns > wf->period_length_ns
> ---
>  drivers/regulator/rpi-panel-v2-regulator.c | 53 +++++++++++++++++-----
>  1 file changed, 42 insertions(+), 11 deletions(-)
> 
> diff --git a/drivers/regulator/rpi-panel-v2-regulator.c b/drivers/regulator/rpi-panel-v2-regulator.c
> index 30b78aa75ee38..eb4c4e3ead364 100644
> --- a/drivers/regulator/rpi-panel-v2-regulator.c
> +++ b/drivers/regulator/rpi-panel-v2-regulator.c
> @@ -35,24 +35,55 @@ static const struct regmap_config rpi_panel_regmap_config = {
>  	.can_sleep = true,
>  };
>  
> -static int rpi_panel_v2_pwm_apply(struct pwm_chip *chip, struct pwm_device *pwm,
> -				  const struct pwm_state *state)
> +static int rpi_panel_v2_pwm_round_waveform_tohw(struct pwm_chip *chip,
> +						struct pwm_device *pwm,
> +						const struct pwm_waveform *wf,
> +						void *_wfhw)
>  {
> -	struct regmap *regmap = pwmchip_get_drvdata(chip);
> -	unsigned int duty;
> +	u8 *wfhw = _wfhw;
> +
> +	if (wf->duty_length_ns > wf->period_length_ns)
> +		*wfhw = 100;
> +	else
> +		*wfhw = mul_u64_u64_div_u64(wf->duty_length_ns, 100, wf->period_length_ns);

If I understand correctly the device has a fixed period length but the
actual length is unknown and so assumed to be 100 ms, right?

In this case the right incarnation for .round_waveform_tohw() is:

/*
 * The device has a fixed but unknown period length. To have something
 * to work with, we're assuming this fixed length is 100 ms.
 */
#define RPI_PANEL_V2_PERIOD_NS 100000

static int rpi_panel_v2_pwm_round_waveform_tohw(...)
{
	u8 *wfhw = _wfhw;

	if (wf->period_length_ns == 0) {
		*wfhw = 0;
		return 0;
	}

	if (wf->duty_length_ns >= RPI_PANEL_V2_PERIOD_NS)
		*wfhw = 100;
	else
		*wfhw = mul_u64_u64_div_u64(wf->duty_length_ns, 100, RPI_PANEL_V2_PERIOD_NS);

	if (wf->period_length_ns < RPI_PANEL_V2_PERIOD_NS)
		return 1;
	else
		return 0;
}

Extra points are awarded if you come up with a nice name for the plain
100 in here, maybe RPI_PANEL_V2_DUTY_STEPS?

Best regards
Uwe

Attachment: signature.asc
Description: PGP signature


[Index of Archives]     [Linux Samsung SOC]     [Linux Wireless]     [Linux Kernel]     [ATH6KL]     [Linux Bluetooth]     [Linux Netdev]     [Kernel Newbies]     [IDE]     [Security]     [Git]     [Netfilter]     [Bugtraq]     [Yosemite News]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Linux RAID]     [Linux ATA RAID]     [Samba]     [Device Mapper]

  Powered by Linux