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

Uwe Kleine-König ukleinek at kernel.org
Tue Jun 17 01:14:52 PDT 2025


Hello Marek,

[Cc: += linux-pwm at vger.kernel.org]

On Tue, Jun 17, 2025 at 02:50:25AM +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 at mailbox.org>
> ---
> Cc: "Uwe Kleine-König" <ukleinek at kernel.org>
> Cc: Dave Stevenson <dave.stevenson at raspberrypi.com>
> Cc: Liam Girdwood <lgirdwood at gmail.com>
> Cc: Mark Brown <broonie at kernel.org>
> Cc: linux-renesas-soc at vger.kernel.org
> ---
>  drivers/regulator/rpi-panel-v2-regulator.c | 50 +++++++++++++++++-----
>  1 file changed, 39 insertions(+), 11 deletions(-)
> 
> diff --git a/drivers/regulator/rpi-panel-v2-regulator.c b/drivers/regulator/rpi-panel-v2-regulator.c
> index 30b78aa75ee3..be42afc81d72 100644
> --- a/drivers/regulator/rpi-panel-v2-regulator.c
> +++ b/drivers/regulator/rpi-panel-v2-regulator.c
> @@ -35,24 +35,52 @@ 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;
> +
> +	*wfhw = DIV_ROUND_CLOSEST_ULL(wf->duty_length_ns * PWM_BL_MASK, wf->period_length_ns);

To have this consistent with rpi_panel_v2_pwm_round_waveform_fromhw()
and not suffer from potential overflow this should be:

/* The actual value isn't known, so this is made up. */
#define RPI_PANEL_V2_FIXED_PERIOD_NS 100000


static int rpi_panel_v2_pwm_round_waveform_tohw(...)
{
	...

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

	return 0;
}

> +
> +	return 0;
> +}
>  
> -	if (state->polarity != PWM_POLARITY_NORMAL)
> -		return -EINVAL;
> +static int rpi_panel_v2_pwm_round_waveform_fromhw(struct pwm_chip *chip,
> +						  struct pwm_device *pwm,
> +						  const void *_wfhw,
> +						  struct pwm_waveform *wf)
> +{
> +	const u8 *wfhw = _wfhw;
> +
> +	/*
> +	 * These numbers here are utter fabrications, the device is sealed
> +	 * in metal casing and difficult to take apart and measure, so we
> +	 * pick some arbitrary values here, values which fit nicely.
> +	 */
> +	wf->period_length_ns = 100 * 1000;	/* 100 us ~= 10 kHz */
> +	wf->duty_length_ns = *wfhw * 1000;	/* 0..100us */
> +	wf->duty_offset_ns = 0;
> +
> +	return 0;
> +}
>  
> -	if (!state->enabled)
> -		return regmap_write(regmap, REG_PWM, 0);
> +static int rpi_panel_v2_pwm_write_waveform(struct pwm_chip *chip,
> +					   struct pwm_device *pwm,
> +					   const void *_wfhw)
> +{
> +	struct regmap *regmap = pwmchip_get_drvdata(chip);
> +	const u8 *wfhw = _wfhw;
>  
> -	duty = pwm_get_relative_duty_cycle(state, PWM_BL_MASK);
> -	return regmap_write(regmap, REG_PWM, duty | PWM_BL_ENABLE);
> +	return regmap_write(regmap, REG_PWM, *wfhw | (*wfhw ? PWM_BL_ENABLE : 0));

How does the PWM behave without PWM_BL_ENABLE set?

>  }
>  
>  static const struct pwm_ops rpi_panel_v2_pwm_ops = {
> -	.apply = rpi_panel_v2_pwm_apply,
> +	.sizeof_wfhw		= sizeof(u8),
> +	.round_waveform_fromhw	= rpi_panel_v2_pwm_round_waveform_fromhw,
> +	.round_waveform_tohw	= rpi_panel_v2_pwm_round_waveform_tohw,
> +	.write_waveform		= rpi_panel_v2_pwm_write_waveform,

Personally I don't like aligning the =. If this was a driver in
drivers/pwm I'd ask you to use a single space before the =.

Best regards
Uwe
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 488 bytes
Desc: not available
URL: <http://lists.infradead.org/pipermail/linux-arm-kernel/attachments/20250617/8adf203c/attachment.sig>


More information about the linux-arm-kernel mailing list