mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: "Uwe Kleine-König" <ukleinek@kernel.org>
To: keguang.zhang@gmail.com
Cc: Binbin Zhou <zhoubinbin@loongson.cn>,
	linux-pwm@vger.kernel.org,  linux-kernel@vger.kernel.org,
	stable@vger.kernel.org
Subject: Re: [PATCH v4 2/3] pwm: loongson: Reset the counters before enabling PWM
Date: Mon, 30 Nov 2026 17:10:43 +0100	[thread overview]
Message-ID: <aw2e2gUE75XjJhv9@monoceros> (raw)
In-Reply-To: <20260920-pwm-loongson-fix-v4-2-41b36b3c6497@gmail.com>

[-- Attachment #1: Type: text/plain, Size: 2127 bytes --]

On Sun, Sep 20, 2026 at 08:02:07PM +0800, Keguang Zhang via B4 Relay wrote:
> From: Keguang Zhang <keguang.zhang@gmail.com>
> 
> The PWM controller may retain its initial hardware state when the driver
> binds. Reset the counters before enabling to ensure that the PWM starts
> from a known state.
> 
> Fixes: 2b62c89448dd ("pwm: Add Loongson PWM controller support")
> Fixes: 0de9b836a3bc ("pwm: loongson: Reload PWM configuration through counter reset")
> Cc: stable@vger.kernel.org
> Suggested-by: Uwe Kleine-König <ukleinek@kernel.org>
> Signed-off-by: Keguang Zhang <keguang.zhang@gmail.com>
> ---
>  drivers/pwm/pwm-loongson.c | 8 ++++++++
>  1 file changed, 8 insertions(+)
> 
> diff --git a/drivers/pwm/pwm-loongson.c b/drivers/pwm/pwm-loongson.c
> index 7af5d4ce1060..977d867bdb8a 100644
> --- a/drivers/pwm/pwm-loongson.c
> +++ b/drivers/pwm/pwm-loongson.c
> @@ -110,6 +110,14 @@ static int pwm_loongson_enable(struct pwm_chip *chip, struct pwm_device *pwm)
>  	struct pwm_loongson_ddata *ddata = to_pwm_loongson_ddata(chip);
>  
>  	val = pwm_loongson_readl(ddata, LOONGSON_PWM_REG_CTRL);
> +
> +	/*
> +	 * Ensure that the values of LOW and PERIOD are sampled into
> +	 * the shadow register when the hardware starts running.
> +	 */
> +	if (!(val & LOONGSON_PWM_CTRL_REG_RST))
> +		pwm_loongson_writel(ddata, val | LOONGSON_PWM_CTRL_REG_RST, LOONGSON_PWM_REG_CTRL);
> +

When the PWM transitions from one enabled state to another the driver
doesn't go through pwm_loongson_disable() + pwm_loongson_enable(). The
reference manual specifies to do that though (as I already noted in my
review of patch #3). If this is kept (which might be ok if verified
properly, and pointed out in a comment that this is against the
recommendation of the docs), I wonder about

	If the register is reconfigured while PWM is running, it does
	not complete the currently running period.

which is written at the top of the header. If the internel counter is
not reset but stays at the current value it might happen to be bigger
than the new period. What happens then?

Best regards
Uwe

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 488 bytes --]

  reply	other threads:[~2026-11-30 16:10 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-09-20 12:02 [PATCH v4 0/3] pwm: loongson: Fix PWM configuration handling Keguang Zhang via B4 Relay
2026-09-20 12:02 ` [PATCH v4 1/3] pwm: loongson: Fix low pulse buffer register handling Keguang Zhang via B4 Relay
2026-11-30 15:55   ` Uwe Kleine-König
2026-09-20 12:02 ` [PATCH v4 2/3] pwm: loongson: Reset the counters before enabling PWM Keguang Zhang via B4 Relay
2026-11-30 16:10   ` Uwe Kleine-König [this message]
2026-09-20 12:02 ` [PATCH v4 3/3] pwm: loongson: Use field helpers for period validation Keguang Zhang via B4 Relay
2026-11-30 16:03   ` Uwe Kleine-König
2026-11-30 16:04     ` Uwe Kleine-König

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=aw2e2gUE75XjJhv9@monoceros \
    --to=ukleinek@kernel.org \
    --cc=keguang.zhang@gmail.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-pwm@vger.kernel.org \
    --cc=stable@vger.kernel.org \
    --cc=zhoubinbin@loongson.cn \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®