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=1796036294; b=a80lbBLjyA9BffiyDTTAnJ75V9EraxKKp4bPSNP/msyH+GQyz6JyAohkvtGK8e6VCWQE JrTmmHxCeulRjARdXm/mtCzA19G/U8c5SKl5UKyJI3J6GxUCOUbTsm0cGqxppNtKUK4GQ 5e/NrFmz8o4phU0s2y5zeMXTLoHxQ9e9yMreQtIqZyMtPrS6zpK315mxECseau+3+gpsn WpkrrGjhTJxtMjqbLpM3Zev0PdPcDi9VDj/oaGA0jXkb3a/e/yi38nCgAyQ+0/YtEnm3q kI41FZqYAlO/D4KmQXRsxhe0wVDY06kXPE1dlEvmiFXEg7mnEaOjUipCjQlw8+r+RJA== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796036294; h=Received:DKIM-Signature:Date:From:To:Cc:Subject:Message-ID: References:MIME-Version:Content-Type:Content-Disposition:In-Reply-To; bh=c5F8YxCTjYt9ycz8chPRdGhPC8EjLYJonRNYkOxDJVQ=; b=Sirn2nKjFKAvm0zHX8l7nxBfTqnB4LXkN7t2lhf0jsVnOlrSNLRd1OCI3YMC84RgGa65 x+W6JZg9aNmUb6EIrjZz7ZTZD27BpT8vtc33xJ5Q3jg+jzY+To4dONmpZcecHdJZeVC8l Y7b6urew1Wem0uRDikPAYdB0mGhFVepzyzau84Aid4U29EkmbQPxYrlTOZ/ZdRLMEDpgq o3+m2W3I+ZFKOY92YoQb7BWjPukkMbIIhWO+5mpOTUhJVER/M4mFx3n3fBnwgPlgwxf/s Fzb+D9pSc5PBxRiPwJz29TjOc3o47ROKYLfxXXwXrT7JSnh0162DLfnmfFp2Y+r4tSQ== 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=OkBzB8g3; 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 D9B14606A320; Mon, 30 Nov 2026 10:58:14 +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=OkBzB8g3 Received: by smtp.kernel.org (Postfix) with UTF8SMTPSA id BE5211F000C1; Mon, 30 Nov 2026 10:58:13 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1796036294; bh=c5F8YxCTjYt9ycz8chPRdGhPC8EjLYJonRNYkOxDJVQ=; h=Date:From:To:Cc:Subject:References:In-Reply-To; b=OkBzB8g3fy9QZIwfqswFgqKBi2wnQCXYrKrZ7Dp0sjySu1G/0H9hp3qs3lJ4r+8e2 gdx+ax+kgmsP9oGePfshXUOgkMEoUj4z0eC8nCC1qkRQaV4HYThp8SEAt8hUkwKw1M yRDKivNKgAOE5yo91DOB0Ax8vpZgYNYzphpGviYgQAjNt9OGqtlgzGjyftQ+a/pnbS kEBBUL8SclDdkc8UWIJQhJgPhpCbyR9K8VQndvxcprECp/Ahsn3cYofCxzlxHbHLGH sNvYbMRuuth+4XWvpoWun5dnuc4GUzg7tRNK2vBSJttuiUE4fnMG6MwMUPxHzWng5I 7tLLcrp7Ju4wg== Date: Mon, 30 Nov 2026 11:58:12 +0100 From: Uwe =?utf-8?Q?Kleine-K=C3=B6nig?= To: Changhuang Liang Cc: Rob Herring , Krzysztof Kozlowski , Conor Dooley , linux-pwm@vger.kernel.org, linux-kernel@vger.kernel.org, devicetree@vger.kernel.org, Hal Feng Subject: Re: [PATCH v1 2/2] pwm: ocores: Add support for StarFive JHB100 PWM polarity Message-ID: References: <20261019110855.52420-1-changhuang.liang@starfivetech.com> <20261019110855.52420-3-changhuang.liang@starfivetech.com> X-Mailing-List: devicetree@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="k72cvuq2gyxmdoo5" Content-Disposition: inline In-Reply-To: <20261019110855.52420-3-changhuang.liang@starfivetech.com> --k72cvuq2gyxmdoo5 Content-Type: text/plain; protected-headers=v1; charset=us-ascii Content-Disposition: inline Content-Transfer-Encoding: quoted-printable Subject: Re: [PATCH v1 2/2] pwm: ocores: Add support for StarFive JHB100 PWM polarity MIME-Version: 1.0 On Mon, Oct 19, 2026 at 04:08:55AM -0700, Changhuang Liang wrote: > The StarFive JHB100 PWM is based on the OpenCores PWM v1 controller, > but its polarity has been changed from inverted to normal. The generic > opencores,pwm-v1 hardware only supports inverted polarity, so the > driver currently hardcodes PWM_POLARITY_INVERSED and rejects any other > polarity, which makes the JHB100 unusable. >=20 > Add a per-device OCPWM_FLAG_POLARITY_NORMAL flag to describe the > polarity capability of the hardware. Devices without this flag keep > the existing inverted-polarity behavior. >=20 > Use the flag in ocores_pwm_get_state() to report the polarity actually > supported by the device, and in ocores_pwm_apply() to validate the > requested polarity accordingly. >=20 > Finally, add the "starfive,jhb100-pwm" compatible with the normal > polarity flag set. >=20 > Signed-off-by: Changhuang Liang > --- > drivers/pwm/pwm-ocores.c | 24 +++++++++++++++++++++--- > 1 file changed, 21 insertions(+), 3 deletions(-) >=20 > diff --git a/drivers/pwm/pwm-ocores.c b/drivers/pwm/pwm-ocores.c > index 4c7e87cb009f..1c69b856bd80 100644 > --- a/drivers/pwm/pwm-ocores.c > +++ b/drivers/pwm/pwm-ocores.c > @@ -18,6 +18,7 @@ > #include > #include > #include > +#include The driver compiles fine without that addition (on arm64), why do you think you need it? > #include > #include > =20 > @@ -31,12 +32,15 @@ > =20 > #define OCPWM_NUM_SAVED_REGS 3 > =20 > +#define OCPWM_FLAG_POLARITY_NORMAL BIT(0) > + > struct ocores_pwm_device { > void __iomem *base; > struct clk *clk; > unsigned long clk_rate; > struct reset_control *rst; > u32 saved_regs[OCPWM_NUM_SAVED_REGS]; > + unsigned long flags; > }; > =20 > static int ocores_pwm_get_state(struct pwm_chip *chip, > @@ -60,7 +64,11 @@ static int ocores_pwm_get_state(struct pwm_chip *chip, > if (state->duty_cycle > state->period) > state->duty_cycle =3D state->period; > =20 > - state->polarity =3D PWM_POLARITY_INVERSED; > + if (ddata->flags & OCPWM_FLAG_POLARITY_NORMAL) > + state->polarity =3D PWM_POLARITY_NORMAL; > + else > + state->polarity =3D PWM_POLARITY_INVERSED; > + > state->enabled =3D (ctrl_data & OCPWM_CTRL_EN) ? true : false; > =20 > pm_runtime_put(pwmchip_parent(chip)); > @@ -85,8 +93,13 @@ static int ocores_pwm_apply(struct pwm_chip *chip, > return 0; > } > =20 > - if (state->polarity !=3D PWM_POLARITY_INVERSED) > - return -EINVAL; > + if (ddata->flags & OCPWM_FLAG_POLARITY_NORMAL) { > + if (state->polarity !=3D PWM_POLARITY_NORMAL) > + return -EINVAL; > + } else { > + if (state->polarity !=3D PWM_POLARITY_INVERSED) > + return -EINVAL; > + } This could be simplified using something along the lines of: enum pwm_polarity polarity =3D ddata->flags & OCPWM_FLAG_POLARITY_NORMAL ? PWM_POLARITY_NORMAL : PWM_POLARITY_INVERSED; if (state->polarity !=3D polarity) return -EINVAL; > period_data =3D mul_u64_u32_div(state->period, ddata->clk_rate, NSEC_PE= R_SEC); > if (period_data > U32_MAX) > @@ -218,6 +231,7 @@ static int ocores_pwm_probe(struct platform_device *p= dev) > =20 > chip->ops =3D &ocores_pwm_ops; > ddata =3D pwmchip_get_drvdata(chip); > + ddata->flags =3D (unsigned long)device_get_match_data(dev); > =20 > ddata->base =3D devm_platform_ioremap_resource(pdev, 0); > if (IS_ERR(ddata->base)) > @@ -279,6 +293,10 @@ static int ocores_pwm_probe(struct platform_device *= pdev) > =20 > static const struct of_device_id ocores_pwm_of_match[] =3D { > { .compatible =3D "opencores,pwm-v1" }, > + { > + .compatible =3D "starfive,jhb100-pwm", > + .data =3D (void *)OCPWM_FLAG_POLARITY_NORMAL > + }, Please also set .data =3D (void *)0; for opencores,pwm-v1 to make the reader not wonder if that entry was forgotten to be added. > { /* sentinel */ } > }; > MODULE_DEVICE_TABLE(of, ocores_pwm_of_match); Best regards Uwe --k72cvuq2gyxmdoo5 Content-Type: application/pgp-signature; name="signature.asc" -----BEGIN PGP SIGNATURE----- iQEzBAABCgAdFiEEP4GsaTp6HlmJrf7Tj4D7WH0S/k4FAmsNVsAACgkQj4D7WH0S /k4HHAf8DV5cOxZENu6cRgQ20LMpA6P12GPtjpN62u+85Ct3eODTZo/P+RRlCcG/ JpCdZV+h0QCdCBA5aic7gndlzhdZhrP15qq/W2JWwf00Y2+XjFP4by0KJifxrz1x ptn89U/mc8YSLCVtL3Y/1E6OW9+sbkbhXxs1h2PpIKcgzZgLczcZKHlF2C1Uqy8u SCFHrItAUJJVTOoC0fYaG623WeHBHUI7zjqDv2x9uLhkJe2GaFPaQiMFGB01U0zA y54jyYMzgUI6cYACTOTDHqjx+6B6putfkwDzUoc4+baC+qKZRqoR5G1FB+CLa3qX pWWh3+3bwPpfRpexSxIvygtLyRfd5g== =8cmF -----END PGP SIGNATURE----- --k72cvuq2gyxmdoo5--