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

Uwe Kleine-König <[email protected]> Fri, 10 Jul 2026 07:52:06 +0200
Newsgroups org.kernel.vger.linux-pwm,org.kernel.vger.linux-kernel
Message-ID <alCIB5nGfYlEZsMg@monoceros>
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 <[email protected]> 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
signature.asc (application/pgp-signature, 488 B)
-----BEGIN PGP SIGNATURE-----

iQEzBAABCgAdFiEEP4GsaTp6HlmJrf7Tj4D7WH0S/k4FAmpQiIMACgkQj4D7WH0S
/k6sKwf/bnIBymcZ/fJgylLmT3nJ/s8EtYF02hfFrxZA6aOX62BqWC4jM8sqBrAr
LF2Rvnyhs0JAgaqYUE75gRscrS8oLJgMjKpFQ/0PIPmsukVRRTKq6QRDKh4zRRF7
nOQ62cu1jzqjytxEX3rtoLMmCuzuNd9FhrgSIV3QYixkXAhxRnMU10BvHl6mKgYX
WDtMf0p2Yr0yJcvOn57zs+buCh9toA2cS4KFy36mSvyubipQRxNSrQ+gdzT7E+5q
Ft6ZZ4dQuJKsHOkrCyhflr5dG4PHXB9vpA7boSFZYfmtvHs3M08FRTl9k7I5SN8t
EN70pwOc/dAenzNuCjiaqKKBX0XHFw==
=NEj/
-----END PGP SIGNATURE-----