Re: [PATCH v2 1/2] pwm: loongson: Fix low pulse buffer register handling

From: Uwe Kleine-König

Date: Fri Jul 10 2026 - 01:52:16 EST


Hello,

On Thu, Jul 09, 2026 at 03:25:38PM +0800, Keguang Zhang wrote:
> On Mon, Jul 6, 2026 at 4:00 PM Uwe Kleine-König <ukleinek@xxxxxxxxxx> wrote:
> > > - /* duty & period have a max of 2^32, so we can't overflow */
> > > - state->duty_cycle = DIV64_U64_ROUND_UP((u64)duty * NSEC_PER_SEC, ddata->clk_rate);
> > > + /* low & period have a max of 2^32, so we can't overflow */
> > > + state->duty_cycle = DIV64_U64_ROUND_UP((u64)(period - low) * NSEC_PER_SEC, ddata->clk_rate);
> >
> > What happens if low > period?
>
> pwm_state_valid() in drivers/pwm/core.c ensures that duty_cycle <=
> period before the framework calls the driver's .apply(). Since this
> driver always programs low = period - duty, low cannot exceed period
> when configured through the PWM framework.

But this is only the case when .get_state() is called after the hardware
was programmed by Linux. The function should also work for the state the
bootloader left the hardware in.

Best regards
Uwe

Attachment: signature.asc
Description: PGP signature