From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=100.103.45.18 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796054138; b=Zv+P7kSPJLvfw19dGijVRCmlBFQJrXlO5yZB4bqnDFT1eTy+GJukrhLGuvvyRjChIRj4 U/cJJDYQk7yw5oLmVa0QHqjQKHuXCta5OKNB7Tu3HVoErqHprjlihwgcg1dLStUE0RrSl Z4F48yTj/qNM0ZnwAsM8skYqtiAy+Zgyvrl2CarPFkHJHVgR9r4k4mGdhzyh6JJVC0e4o ncu5mamtsiC4T0RpFP6VWYZeSU9mRugsXFzbs9LhPrjza+Xtx7HibgFnhkWLLeRrmgZ6z 9/DyUsYPEjv1i7KZVkiqqdvCrV4sz46KbFQrOAnDPymGFxTjf/chxvLs9BxVdSdbNag== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796054138; h=Received:DKIM-Signature:Date:From:To:Cc:Subject:Message-ID: References:MIME-Version:Content-Type:Content-Disposition:In-Reply-To; bh=v94VAuox5D8/MbXGkpQXEslkeh8HDEGn8XE/wKDB5ec=; b=BIj/Rt8q6Fi2w79zKL+GmeJ5BGLVXgkfbMwT+j7pU0+D7kwK910C53+wMxbnPBvALSgU gl58TT6WBmgljALXJpH7m9NWeoY2NKb2Nyd1sjcy1snXzPs20cNTiDjK4SeQl/fJEBDNC keb6a3GDbuek+nxEGnAIutywhZvtyAYwA5ZhzFrFLptKHS5O6OPhgsVPaBI2MNiTFzY7x +wQjnCpM3sS7fF6japQCWDYWXB0gkILpPjFp15tuWHzq1b7523l1tmDgMkDKuALdX+AO+ X4HiApYHWe7siJ/Fl68xJpG0ms4+/8fdhrNGl1gmr8Tc589/tfZtLWzWie7X40LR0Zw== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=J9HzELRe; arc=none smtp.remote-ip=100.103.45.18 Received: from smtp.kernel.org (quasi.space.kernel.org [100.103.45.18]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (prime256v1)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with UTF8SMTPS id 93DDD606A327; Mon, 30 Nov 2026 15:55:38 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=J9HzELRe Received: by smtp.kernel.org (Postfix) with UTF8SMTPSA id 742091F000C1; Mon, 30 Nov 2026 15:55:37 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1796054138; bh=v94VAuox5D8/MbXGkpQXEslkeh8HDEGn8XE/wKDB5ec=; h=Date:From:To:Cc:Subject:References:In-Reply-To; b=J9HzELRe7f8kfby8iPqYzoXcfbiUGi8owzc4UeqMs2eM/8bmuTwCyzAam56RutMGh 3Shhc5EhftCIDf0woF6kP6DjX0MMHwjUN9JQLZ4zhNfEzx0M9DOK8lo6MwnOe+mUqm L2/xEtbYSwDGDE9vEDjEL/mVYuyF8w5vOuezRZ3ZHuLAKgwKtZQ9RNbxVy8r98ip/J rIdYhc5bRUb2WfJ9Q/q/70IQ7dt+2IjWhwKDIolikZDXvHCIDKEvTsGjY5LpsXtGf6 qntIgUq8cuSCAYOBhpYxsisvmqVkaRPv/hxhxjzKqZs/2ynLtksim543IYlZXJ64Gp YYlWqqGnKXMzg== Date: Mon, 30 Nov 2026 16:55:35 +0100 From: Uwe =?utf-8?Q?Kleine-K=C3=B6nig?= To: keguang.zhang@gmail.com Cc: Binbin Zhou , linux-pwm@vger.kernel.org, linux-kernel@vger.kernel.org, stable@vger.kernel.org Subject: Re: [PATCH v4 1/3] pwm: loongson: Fix low pulse buffer register handling Message-ID: References: <20260920-pwm-loongson-fix-v4-0-41b36b3c6497@gmail.com> <20260920-pwm-loongson-fix-v4-1-41b36b3c6497@gmail.com> X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 Content-Type: multipart/signed; micalg=pgp-sha512; protocol="application/pgp-signature"; boundary="ueyivfbkv22bk7vb" Content-Disposition: inline In-Reply-To: <20260920-pwm-loongson-fix-v4-1-41b36b3c6497@gmail.com> --ueyivfbkv22bk7vb Content-Type: text/plain; protected-headers=v1; charset=us-ascii Content-Disposition: inline Content-Transfer-Encoding: quoted-printable Subject: Re: [PATCH v4 1/3] pwm: loongson: Fix low pulse buffer register handling MIME-Version: 1.0 Hello, On Sun, Sep 20, 2026 at 08:02:06PM +0800, Keguang Zhang via B4 Relay wrote: > From: Keguang Zhang >=20 > The Loongson PWM register at offset 0x4 is documented as the Low > Pulse Buffer Register, which stores the low pulse width rather than > the duty cycle. >=20 > However, this register was incorrectly defined and treated as a > duty-cycle register. As a result, the duty cycle and low pulse cycle > are swapped in the generated PWM waveform. >=20 > Program the low pulse (period - duty) into the register and > adjust pwm_loongson_get_state() accordingly when reconstructing the > duty cycle. >=20 > Fixes: 2b62c89448dd ("pwm: Add Loongson PWM controller support") > Cc: stable@vger.kernel.org > Signed-off-by: Keguang Zhang > --- > drivers/pwm/pwm-loongson.c | 29 +++++++++++++++++------------ > 1 file changed, 17 insertions(+), 12 deletions(-) >=20 > diff --git a/drivers/pwm/pwm-loongson.c b/drivers/pwm/pwm-loongson.c > index 98c809bde2b3..7af5d4ce1060 100644 > --- a/drivers/pwm/pwm-loongson.c > +++ b/drivers/pwm/pwm-loongson.c > @@ -33,7 +33,7 @@ > #include > =20 > /* Loongson PWM registers */ > -#define LOONGSON_PWM_REG_DUTY 0x4 /* Low Pulse Buffer Register */ > +#define LOONGSON_PWM_REG_LOW 0x4 /* Low Pulse Buffer Register */ > #define LOONGSON_PWM_REG_PERIOD 0x8 /* Pulse Period Buffer Register */ > #define LOONGSON_PWM_REG_CTRL 0xc /* Control Register */ > =20 > @@ -120,20 +120,20 @@ static int pwm_loongson_enable(struct pwm_chip *chi= p, struct pwm_device *pwm) > static int pwm_loongson_config(struct pwm_chip *chip, struct pwm_device = *pwm, > u64 duty_ns, u64 period_ns) > { > - u64 duty, period; > + u64 low, duty, period; > struct pwm_loongson_ddata *ddata =3D to_pwm_loongson_ddata(chip); > =20 > - /* duty =3D duty_ns * ddata->clk_rate / NSEC_PER_SEC */ > - duty =3D mul_u64_u64_div_u64(duty_ns, ddata->clk_rate, NSEC_PER_SEC); > - if (duty > U32_MAX) > - duty =3D U32_MAX; > - > /* period =3D period_ns * ddata->clk_rate / NSEC_PER_SEC */ > period =3D mul_u64_u64_div_u64(period_ns, ddata->clk_rate, NSEC_PER_SEC= ); > if (period > U32_MAX) > period =3D U32_MAX; > =20 > - pwm_loongson_writel(ddata, duty, LOONGSON_PWM_REG_DUTY); > + /* duty =3D duty_ns * ddata->clk_rate / NSEC_PER_SEC */ > + duty =3D mul_u64_u64_div_u64_roundup(duty_ns, ddata->clk_rate, NSEC_PER= _SEC); > + duty =3D min(duty, period); > + low =3D period - duty; That semantic of the register at offset 4 made me wonder if the hardware emits an inverted signal by default. Looking at the reference manual linked at the top of the header describes the INVERT bit of the control register as: 1: .. period starts at high level 0: .. period starts at low level So for a pwm_state with polarity =3D=3D PWM_POLARITY_NORMAL the bit must be set. That's wrong in pwm_loongson_set_polarity() and probably deserves to be fixed in the same commit. Also the reference manual isn't very explicit, but if the low_buffer register (named LOONGSON_PWM_REG_LOW here now) describes the low pulse length for both settings of the INVERT bit, the fix must look different. Best regards Uwe --ueyivfbkv22bk7vb Content-Type: application/pgp-signature; name="signature.asc" -----BEGIN PGP SIGNATURE----- iQEzBAABCgAdFiEEP4GsaTp6HlmJrf7Tj4D7WH0S/k4FAmsNnHUACgkQj4D7WH0S /k7I2Af+POLzPDRGN1wtV4f4ZgCw5Jrs1KM3eHbLUJ+IiNkN000XMJxYNnn2AneD dMvS+C12vE1J3Oq0dYXLyFYIz9btxBY5Ook/Vtxc79m18QxHD7OLEXEJCyW4GEDY pQQHb+atoqae/AxB43kcCkr+RykT0i0RsFIWMbEHIRtZcVg9rUFOL0E0beavlHlt gPw3kQjw1t1YhBYN8zYcyKeXPOb1AhjryZ3sWJEYfuXm1st3PxaOGy7vL+AOZIRW ti37TaNh5NBiLKLNcYcN2+I6iPEBqvC6VSJhP8QsSp5OxH6lWGmbEKssCWlJcXFU 6IXHNxdOlOXc9wuo3LYD/xCeWMke1w== =3eEd -----END PGP SIGNATURE----- --ueyivfbkv22bk7vb--