From: "Uwe Kleine-König" <ukleinek@kernel.org>
To: Changhuang Liang <changhuang.liang@starfivetech.com>
Cc: Rob Herring <robh@kernel.org>,
Krzysztof Kozlowski <krzk+dt@kernel.org>,
Conor Dooley <conor+dt@kernel.org>,
linux-pwm@vger.kernel.org, linux-kernel@vger.kernel.org,
devicetree@vger.kernel.org, Hal Feng <hal.feng@starfivetech.com>
Subject: Re: [PATCH v1 2/2] pwm: ocores: Add support for StarFive JHB100 PWM polarity
Date: Mon, 30 Nov 2026 11:58:12 +0100 [thread overview]
Message-ID: <aw1VmgUFapOeuVfL@monoceros> (raw)
In-Reply-To: <20261019110855.52420-3-changhuang.liang@starfivetech.com>
[-- Attachment #1: Type: text/plain, Size: 4054 bytes --]
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.
>
> 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.
>
> 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.
>
> Finally, add the "starfive,jhb100-pwm" compatible with the normal
> polarity flag set.
>
> Signed-off-by: Changhuang Liang <changhuang.liang@starfivetech.com>
> ---
> drivers/pwm/pwm-ocores.c | 24 +++++++++++++++++++++---
> 1 file changed, 21 insertions(+), 3 deletions(-)
>
> 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 <linux/module.h>
> #include <linux/platform_device.h>
> #include <linux/pm_runtime.h>
> +#include <linux/property.h>
The driver compiles fine without that addition (on arm64), why do you
think you need it?
> #include <linux/pwm.h>
> #include <linux/reset.h>
>
> @@ -31,12 +32,15 @@
>
> #define OCPWM_NUM_SAVED_REGS 3
>
> +#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;
> };
>
> 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 = state->period;
>
> - state->polarity = PWM_POLARITY_INVERSED;
> + if (ddata->flags & OCPWM_FLAG_POLARITY_NORMAL)
> + state->polarity = PWM_POLARITY_NORMAL;
> + else
> + state->polarity = PWM_POLARITY_INVERSED;
> +
> state->enabled = (ctrl_data & OCPWM_CTRL_EN) ? true : false;
>
> pm_runtime_put(pwmchip_parent(chip));
> @@ -85,8 +93,13 @@ static int ocores_pwm_apply(struct pwm_chip *chip,
> return 0;
> }
>
> - if (state->polarity != PWM_POLARITY_INVERSED)
> - return -EINVAL;
> + if (ddata->flags & OCPWM_FLAG_POLARITY_NORMAL) {
> + if (state->polarity != PWM_POLARITY_NORMAL)
> + return -EINVAL;
> + } else {
> + if (state->polarity != PWM_POLARITY_INVERSED)
> + return -EINVAL;
> + }
This could be simplified using something along the lines of:
enum pwm_polarity polarity =
ddata->flags & OCPWM_FLAG_POLARITY_NORMAL ?
PWM_POLARITY_NORMAL : PWM_POLARITY_INVERSED;
if (state->polarity != polarity)
return -EINVAL;
> period_data = mul_u64_u32_div(state->period, ddata->clk_rate, NSEC_PER_SEC);
> if (period_data > U32_MAX)
> @@ -218,6 +231,7 @@ static int ocores_pwm_probe(struct platform_device *pdev)
>
> chip->ops = &ocores_pwm_ops;
> ddata = pwmchip_get_drvdata(chip);
> + ddata->flags = (unsigned long)device_get_match_data(dev);
>
> ddata->base = devm_platform_ioremap_resource(pdev, 0);
> if (IS_ERR(ddata->base))
> @@ -279,6 +293,10 @@ static int ocores_pwm_probe(struct platform_device *pdev)
>
> static const struct of_device_id ocores_pwm_of_match[] = {
> { .compatible = "opencores,pwm-v1" },
> + {
> + .compatible = "starfive,jhb100-pwm",
> + .data = (void *)OCPWM_FLAG_POLARITY_NORMAL
> + },
Please also set .data = (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
[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 488 bytes --]
next prev parent reply other threads:[~2026-11-30 10:58 UTC|newest]
Thread overview: 9+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-10-19 11:08 [PATCH v1 0/2] Add PWM support for JHB100 SoC Changhuang Liang
2026-10-19 11:08 ` [PATCH v1 1/2] dt-bindings: pwm: opencores: Add starfive,jhb100-pwm Changhuang Liang
2026-10-22 9:54 ` Krzysztof Kozlowski
2026-11-30 10:42 ` Uwe Kleine-König
2026-11-30 10:52 ` Uwe Kleine-König
2026-12-01 1:47 ` Changhuang Liang
2026-10-19 11:08 ` [PATCH v1 2/2] pwm: ocores: Add support for StarFive JHB100 PWM polarity Changhuang Liang
2026-11-30 10:58 ` Uwe Kleine-König [this message]
2026-12-01 2:06 ` Changhuang Liang
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=aw1VmgUFapOeuVfL@monoceros \
--to=ukleinek@kernel.org \
--cc=changhuang.liang@starfivetech.com \
--cc=conor+dt@kernel.org \
--cc=devicetree@vger.kernel.org \
--cc=hal.feng@starfivetech.com \
--cc=krzk+dt@kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-pwm@vger.kernel.org \
--cc=robh@kernel.org \
/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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.