Re: [PATCH v2 1/2] pwm: loongson: Fix low pulse buffer register handling
From: Keguang Zhang
Date: Fri Jul 10 2026 - 07:47:39 EST
On Fri, Jul 10, 2026 at 1:52 PM Uwe Kleine-König <ukleinek@xxxxxxxxxx> wrote:
>
> 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.
>
Thanks for the clarification. I'll handle the low > period case in the
next version.
> Best regards
> Uwe
--
Best regards,
Keguang Zhang