* [PATCH v1 0/2] Add PWM support for JHB100 SoC
@ 2026-10-19 11:08 Changhuang Liang
2026-10-19 11:08 ` [PATCH v1 1/2] dt-bindings: pwm: opencores: Add starfive,jhb100-pwm Changhuang Liang
2026-10-19 11:08 ` [PATCH v1 2/2] pwm: ocores: Add support for StarFive JHB100 PWM polarity Changhuang Liang
0 siblings, 2 replies; 7+ messages in thread
From: Changhuang Liang @ 2026-10-19 11:08 UTC (permalink / raw)
To: Uwe Kleine-König, Rob Herring, Krzysztof Kozlowski,
Conor Dooley
Cc: linux-pwm, linux-kernel, devicetree, Hal Feng, Changhuang Liang
The StarFive JHB100 PWM is based on the OpenCores PWM v1 controller
but with a modification: the polarity has been changed from inverted
to normal.
This series has been tested on the JHB100 EVB1 board.
This series depends on series:
https://lore.kernel.org/all/20261014110429.52762-1-hal.feng@starfivetech.com/
Changhuang Liang (2):
dt-bindings: pwm: opencores: Add starfive,jhb100-pwm
pwm: ocores: Add support for StarFive JHB100 PWM polarity
.../bindings/pwm/opencores,pwm.yaml | 12 ++++++----
drivers/pwm/pwm-ocores.c | 24 ++++++++++++++++---
2 files changed, 28 insertions(+), 8 deletions(-)
--
2.25.1
^ permalink raw reply [flat|nested] 7+ messages in thread
* [PATCH v1 1/2] dt-bindings: pwm: opencores: Add starfive,jhb100-pwm
2026-10-19 11:08 [PATCH v1 0/2] Add PWM support for JHB100 SoC Changhuang Liang
@ 2026-10-19 11:08 ` Changhuang Liang
2026-10-22 9:54 ` Krzysztof Kozlowski
2026-11-30 10:42 ` Uwe Kleine-König
2026-10-19 11:08 ` [PATCH v1 2/2] pwm: ocores: Add support for StarFive JHB100 PWM polarity Changhuang Liang
1 sibling, 2 replies; 7+ messages in thread
From: Changhuang Liang @ 2026-10-19 11:08 UTC (permalink / raw)
To: Uwe Kleine-König, Rob Herring, Krzysztof Kozlowski,
Conor Dooley
Cc: linux-pwm, linux-kernel, devicetree, Hal Feng, Changhuang Liang
Add a new compatible string "starfive,jhb100-pwm" for the PWM
controller found on the StarFive JHB100 SoC.
The StarFive JHB100 PWM is based on the OpenCores PWM v1 controller
but with a modification: the polarity has been changed from inverted
to normal. The generic opencores,pwm-v1 hardware only supports
inverted polarity, so the JHB100 variant cannot reuse the
"opencores,pwm-v1" fallback and must be described with a standalone
compatible string.
Signed-off-by: Changhuang Liang <changhuang.liang@starfivetech.com>
---
.../devicetree/bindings/pwm/opencores,pwm.yaml | 12 +++++++-----
1 file changed, 7 insertions(+), 5 deletions(-)
diff --git a/Documentation/devicetree/bindings/pwm/opencores,pwm.yaml b/Documentation/devicetree/bindings/pwm/opencores,pwm.yaml
index b15468f97b59..a7798310d350 100644
--- a/Documentation/devicetree/bindings/pwm/opencores,pwm.yaml
+++ b/Documentation/devicetree/bindings/pwm/opencores,pwm.yaml
@@ -19,11 +19,13 @@ allOf:
properties:
compatible:
- items:
- - enum:
- - starfive,jh7100-pwm
- - starfive,jh7110-pwm
- - const: opencores,pwm-v1
+ oneOf:
+ - items:
+ - enum:
+ - starfive,jh7100-pwm
+ - starfive,jh7110-pwm
+ - const: opencores,pwm-v1
+ - const: starfive,jhb100-pwm
reg:
maxItems: 1
--
2.25.1
^ permalink raw reply related [flat|nested] 7+ messages in thread
* [PATCH v1 2/2] pwm: ocores: Add support for StarFive JHB100 PWM polarity
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-19 11:08 ` Changhuang Liang
2026-11-30 10:58 ` Uwe Kleine-König
1 sibling, 1 reply; 7+ messages in thread
From: Changhuang Liang @ 2026-10-19 11:08 UTC (permalink / raw)
To: Uwe Kleine-König, Rob Herring, Krzysztof Kozlowski,
Conor Dooley
Cc: linux-pwm, linux-kernel, devicetree, Hal Feng, Changhuang Liang
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>
#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;
+ }
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
+ },
{ /* sentinel */ }
};
MODULE_DEVICE_TABLE(of, ocores_pwm_of_match);
--
2.25.1
^ permalink raw reply related [flat|nested] 7+ messages in thread
* Re: [PATCH v1 1/2] dt-bindings: pwm: opencores: Add starfive,jhb100-pwm
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
1 sibling, 0 replies; 7+ messages in thread
From: Krzysztof Kozlowski @ 2026-10-22 9:54 UTC (permalink / raw)
To: Changhuang Liang
Cc: Uwe Kleine-König, Rob Herring, Krzysztof Kozlowski,
Conor Dooley, linux-pwm, linux-kernel, devicetree, Hal Feng
On Mon, Oct 19, 2026 at 04:08:54AM -0700, Changhuang Liang wrote:
> Add a new compatible string "starfive,jhb100-pwm" for the PWM
> controller found on the StarFive JHB100 SoC.
>
> The StarFive JHB100 PWM is based on the OpenCores PWM v1 controller
> but with a modification: the polarity has been changed from inverted
> to normal. The generic opencores,pwm-v1 hardware only supports
> inverted polarity, so the JHB100 variant cannot reuse the
> "opencores,pwm-v1" fallback and must be described with a standalone
> compatible string.
>
> Signed-off-by: Changhuang Liang <changhuang.liang@starfivetech.com>
> ---
> .../devicetree/bindings/pwm/opencores,pwm.yaml | 12 +++++++-----
> 1 file changed, 7 insertions(+), 5 deletions(-)
>
Reviewed-by: Krzysztof Kozlowski <krzysztof.kozlowski@oss.qualcomm.com>
Best regards,
Krzysztof
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [PATCH v1 1/2] dt-bindings: pwm: opencores: Add starfive,jhb100-pwm
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
1 sibling, 1 reply; 7+ messages in thread
From: Uwe Kleine-König @ 2026-11-30 10:42 UTC (permalink / raw)
To: Changhuang Liang
Cc: Rob Herring, Krzysztof Kozlowski, Conor Dooley, linux-pwm,
linux-kernel, devicetree, Hal Feng
[-- Attachment #1: Type: text/plain, Size: 2031 bytes --]
On Mon, Oct 19, 2026 at 04:08:54AM -0700, Changhuang Liang wrote:
> Add a new compatible string "starfive,jhb100-pwm" for the PWM
> controller found on the StarFive JHB100 SoC.
>
> The StarFive JHB100 PWM is based on the OpenCores PWM v1 controller
> but with a modification: the polarity has been changed from inverted
> to normal. The generic opencores,pwm-v1 hardware only supports
> inverted polarity, so the JHB100 variant cannot reuse the
> "opencores,pwm-v1" fallback and must be described with a standalone
> compatible string.
>
> Signed-off-by: Changhuang Liang <changhuang.liang@starfivetech.com>
> ---
> .../devicetree/bindings/pwm/opencores,pwm.yaml | 12 +++++++-----
> 1 file changed, 7 insertions(+), 5 deletions(-)
>
> diff --git a/Documentation/devicetree/bindings/pwm/opencores,pwm.yaml b/Documentation/devicetree/bindings/pwm/opencores,pwm.yaml
> index b15468f97b59..a7798310d350 100644
I tried to `git am` this patch series, but it fails to apply and git
wails:
error: sha1 information is lacking or useless (Documentation/devicetree/bindings/pwm/opencores,pwm.yaml).
Indeed I don't have b15468f97b59 in my linux.git.
Please use a known tree as base for your changes and ideally use the
--base option for format-patch to document that.
> --- a/Documentation/devicetree/bindings/pwm/opencores,pwm.yaml
> +++ b/Documentation/devicetree/bindings/pwm/opencores,pwm.yaml
> @@ -19,11 +19,13 @@ allOf:
>
> properties:
> compatible:
> - items:
> - - enum:
> - - starfive,jh7100-pwm
> - - starfive,jh7110-pwm
> - - const: opencores,pwm-v1
> + oneOf:
> + - items:
> + - enum:
> + - starfive,jh7100-pwm
> + - starfive,jh7110-pwm
> + - const: opencores,pwm-v1
> + - const: starfive,jhb100-pwm
The starfive,jhb100-pwm variant isn't v2 as it is a modification that
Starfive implemented for that SoC only and opencores isn't involved,
right?
Best regards
Uwe
[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 488 bytes --]
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [PATCH v1 1/2] dt-bindings: pwm: opencores: Add starfive,jhb100-pwm
2026-11-30 10:42 ` Uwe Kleine-König
@ 2026-11-30 10:52 ` Uwe Kleine-König
0 siblings, 0 replies; 7+ messages in thread
From: Uwe Kleine-König @ 2026-11-30 10:52 UTC (permalink / raw)
To: Changhuang Liang
Cc: Rob Herring, Krzysztof Kozlowski, Conor Dooley, linux-pwm,
linux-kernel, devicetree, Hal Feng
[-- Attachment #1: Type: text/plain, Size: 1661 bytes --]
On Mon, Nov 30, 2026 at 11:42:42AM +0100, Uwe Kleine-König wrote:
> On Mon, Oct 19, 2026 at 04:08:54AM -0700, Changhuang Liang wrote:
> > Add a new compatible string "starfive,jhb100-pwm" for the PWM
> > controller found on the StarFive JHB100 SoC.
> >
> > The StarFive JHB100 PWM is based on the OpenCores PWM v1 controller
> > but with a modification: the polarity has been changed from inverted
> > to normal. The generic opencores,pwm-v1 hardware only supports
> > inverted polarity, so the JHB100 variant cannot reuse the
> > "opencores,pwm-v1" fallback and must be described with a standalone
> > compatible string.
> >
> > Signed-off-by: Changhuang Liang <changhuang.liang@starfivetech.com>
> > ---
> > .../devicetree/bindings/pwm/opencores,pwm.yaml | 12 +++++++-----
> > 1 file changed, 7 insertions(+), 5 deletions(-)
> >
> > diff --git a/Documentation/devicetree/bindings/pwm/opencores,pwm.yaml b/Documentation/devicetree/bindings/pwm/opencores,pwm.yaml
> > index b15468f97b59..a7798310d350 100644
>
> I tried to `git am` this patch series, but it fails to apply and git
> wails:
>
> error: sha1 information is lacking or useless (Documentation/devicetree/bindings/pwm/opencores,pwm.yaml).
>
> Indeed I don't have b15468f97b59 in my linux.git.
>
> Please use a known tree as base for your changes and ideally use the
> --base option for format-patch to document that.
Ah, I missed
This series depends on series:
https://lore.kernel.org/all/20261014110429.52762-1-hal.feng@starfivetech.com/
in the cover letter. So that's fine (though using --base would still be
awesome).
Best regards
Uwe
[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 488 bytes --]
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [PATCH v1 2/2] pwm: ocores: Add support for StarFive JHB100 PWM polarity
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
0 siblings, 0 replies; 7+ messages in thread
From: Uwe Kleine-König @ 2026-11-30 10:58 UTC (permalink / raw)
To: Changhuang Liang
Cc: Rob Herring, Krzysztof Kozlowski, Conor Dooley, linux-pwm,
linux-kernel, devicetree, Hal Feng
[-- 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 --]
^ permalink raw reply [flat|nested] 7+ messages in thread
end of thread, other threads:[~2026-11-30 10:58 UTC | newest]
Thread overview: 7+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
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-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 is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox