Re: [PATCH 2/2] pwm: loongson: Reload PWM configuration through counter reset
From: Keguang Zhang
Date: Sat Jun 20 2026 - 05:47:31 EST
On Thu, Jun 18, 2026 at 12:11 AM Uwe Kleine-König <ukleinek@xxxxxxxxxx> wrote:
>
> Hello,
>
> On Tue, Jun 16, 2026 at 07:13:18PM +0800, Keguang Zhang via B4 Relay wrote:
> > From: Keguang Zhang <keguang.zhang@xxxxxxxxx>
> >
> > By default, the Loongson PWM controller latches the LOW and PERIOD
> > registers only at the start of each PWM period, causing configuration
> > updates to be delayed until the next period.
> >
> > Reset the PWM counter when disabling the PWM and release it when enabling
> > the PWM to force the controller to re-latch the updated LOW and PERIOD
> > values, allowing configuration changes to take effect immediately.
>
> To get this right, so if the hardware runs with PERIOD = 17 and then is
> disabled with say the counter at 4, and later restarted with PERIOD =
> 12, the counter first goes up to 17 before the 12 becomes active, right?
>
Yes. This is exactly what happens when updating the configuration
without setting LOONGSON_PWM_CTRL_REG_RST.
Even with disabling and re-enabling the PWM, the counter still resumes
from the previous value and completes the current period. The only
difference is that the counter is paused while the PWM is disabled.
Therefore, setting LOONGSON_PWM_CTRL_REG_RST when disabling the PWM
forces the PWM controller to re-latch the updated LOW and PERIOD values,
allowing the updated configuration to take effect immediately when the
PWM is re-enabled.
> I think the commit log is a bit irritating, because (IIUC) you only
> change the behaviour when the PWM is disabled and then reenabled. If the
> configuration is changed while the PWM is running, the effect is still
> delayed until the current period ends (which is complete fine and even
> preferred).
>
That's exactly what I mean.
Sorry for the misleading commit log. I'll clarify it in the next version.
> Best regards
> Uwe
--
Best regards,
Keguang Zhang