Add PWM support for JHB100 SoC
Subsystems (2)
cover Add PWM support for 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.
This series has been tested on the JHB100 EVB1 board.
This series depends on series:
https://lore.kernel.org/all/[email protected]/
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
PATCH 1/2 dt-bindings: pwm: opencores: Add starfive,jhb100-pwm
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.
--- .../devicetree/bindings/pwm/opencores,pwm.yaml | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-)
Documentation/devicetree/bindings/pwm/opencores,pwm.yaml +7 -5
@@ -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
Signature · 1 line
2.25.1
Re: [PATCH v1 1/2] dt-bindings: pwm: opencores: Add starfive,jhb100-pwm
Quoted 10 lines · 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.
Quoted 5 lines
Signed-off-by Changhuang Liang <[email protected]>--- .../devicetree/bindings/pwm/opencores,pwm.yaml | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-)
Best regards,
Krzysztof
Uwe Kleine-König
maintainerRe: [PATCH v1 1/2] dt-bindings: pwm: opencores: Add starfive,jhb100-pwm
In reply to Changhuang LiangDocumentation/devicetree/bindings/pwm/opencores,pwm.yaml
Quoted 17 lines · 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 <[email protected]>--- .../devicetree/bindings/pwm/opencores,pwm.yaml | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-)Documentation/devicetree/bindings/pwm/opencores,pwm.yaml +0
-0
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.
Quoted 8 lines
Documentation/devicetree/bindings/pwm/opencores,pwm.yaml +0
-2@@ -19,11 +19,13 @@ allOf: properties: compatible: - items: - - enum:
Documentation/devicetree/bindings/pwm/opencores,pwm.yaml allOf: · line 28
Quoted 10 lines
Documentation/devicetree/bindings/pwm/opencores,pwm.yaml +7
-3- - 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
Uwe Kleine-König
maintainerRe: [PATCH v1 1/2] dt-bindings: pwm: opencores: Add starfive,jhb100-pwm
Quoted 22 lines · Uwe Kleine-König
Documentation/devicetree/bindings/pwm/opencores,pwm.yaml
Quoted 17 lines · 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 <[email protected]>--- .../devicetree/bindings/pwm/opencores,pwm.yaml | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-)Documentation/devicetree/bindings/pwm/opencores,pwm.yaml +0
-0I tried to
git amthis patch series, but it fails to apply and git wails:
Quoted 6 lines
error: sha1 information is lacking or useless (
Documentation/devicetree/bindings/pwm/opencores,pwm.yaml).Indeed I don't have
b15468f97b59in 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/[email protected]/
in the cover letter. So that's fine (though using --base would still be awesome).
Best regards
Uwe
Re: [PATCH v1 1/2] dt-bindings: pwm: opencores: Add starfive,jhb100-pwm
In reply to Uwe Kleine-KönigHi, Uwe
Thanks for the review.
Quoted 45 lines · Changhuang Liang
Quoted 10 lines
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.
Quoted 3 lines
Signed-off-by Changhuang Liang <[email protected]>--- .../devicetree/bindings/pwm/opencores,pwm.yaml | 12+++++++-----
Documentation/devicetree/bindings/pwm/opencores,pwm.yaml
Quoted 5 lines
1 file changed, 7 insertions(+), 5 deletions(-)Documentation/devicetree/bindings/pwm/opencores,pwm.yaml +0
-0I tried to
git amthis 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
b15468f97b59in 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.
Quoted 13 lines
Documentation/devicetree/bindings/pwm/opencores,pwm.yaml +2
-5@@ -19,11 +19,13 @@ allOf: properties: compatible: - items: - - enum: - - starfive,jh7100-pwm - - starfive,jh7110-pwm - - const: opencores,pwm-v1 + oneOf: + - items:
Quoted 8 lines
Documentation/devicetree/bindings/pwm/opencores,pwm.yaml allOf: · line 28
Quoted 5 lines
Documentation/devicetree/bindings/pwm/opencores,pwm.yaml +5
-0+ - enum: + - starfive,jh7100-pwm + - starfive,jh7110-pwm + - const: opencores,pwm-v1 + - const: starfive,jhb100-pwmThe 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?
Yes, you're right.
Best Regards,
Changhuang
PATCH 2/2 pwm: ocores: Add support for StarFive JHB100 PWM polarity
In reply to Changhuang LiangThe 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.
--- drivers/pwm/pwm-ocores.c | 24 +++++++++++++++++++++--- 1 file changed, 21 insertions(+), 3 deletions(-)
drivers/pwm/pwm-ocores.c +21 -3
@@ -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);
Signature · 1 line
2.25.1
Uwe Kleine-König
maintainerRe: [PATCH v1 2/2] pwm: ocores: Add support for StarFive JHB100 PWM polarity
Quoted 27 lines · 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_INVERSEDand rejects any other polarity, which makes the JHB100 unusable.Add a per-device
OCPWM_FLAG_POLARITY_NORMALflag 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 inocores_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 <[email protected]>--- drivers/pwm/pwm-ocores.c | 24 +++++++++++++++++++++--- 1 file changed, 21 insertions(+), 3 deletions(-)drivers/pwm/pwm-ocores.c +0
-0
drivers/pwm/pwm-ocores.c line 21
Quoted 4 lines
drivers/pwm/pwm-ocores.c +1
-0@@ -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?
Quoted 35 lines
drivers/pwm/pwm-ocores.c +8
-1#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 ; }
drivers/pwm/pwm-ocores.c static int ocores_pwm_apply(struct pwm_chip *chip, · line 102
Quoted 10 lines
drivers/pwm/pwm-ocores.c +7
-2-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;
Quoted 11 lines
drivers/pwm/pwm-ocores.c +1
-0period_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))
drivers/pwm/pwm-ocores.c static int ocores_pwm_probe(struct platform_device *pdev) · line 299
Quoted 7 lines
drivers/pwm/pwm-ocores.c +4
-0@@ -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.
drivers/pwm/pwm-ocores.c static int ocores_pwm_probe(struct platform_device *pdev) · line 302
Quoted 3 lines
drivers/pwm/pwm-ocores.c +0
-0{/* sentinel */ } };MODULE_DEVICE_TABLE (of, ocores_pwm_of_match);
Best regards
Uwe
Re: [PATCH v1 2/2] pwm: ocores: Add support for StarFive JHB100 PWM polarity
Hi, Uwe
Thanks for the review.
Quoted 24 lines · Changhuang Liang
Quoted 4 lines
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_INVERSEDand rejects anyother
Quoted 18 lines
polarity, which makes the JHB100 unusable.
Add a per-device
OCPWM_FLAG_POLARITY_NORMALflag 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 inocores_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 <[email protected]>--- drivers/pwm/pwm-ocores.c | 24 +++++++++++++++++++++--- 1 file changed, 21 insertions(+), 3 deletions(-)
Quoted 12 lines
drivers/pwm/pwm-ocores.c line 21
Quoted 9 lines
drivers/pwm/pwm-ocores.c index renamed from drivers/pwm/pwm-ocores.c +0
-0
4c7e87cb009f..1c69b856bd80100644drivers/pwm/pwm-ocores.c +1
-0@@ -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?
The patch adds a call to device_get_match_data(), which is declared in <linux/property.h>. You're right that it also builds without the explicit include, because <linux/pwm.h> pulls it in through <linux/of.h> and <linux/gpio/driver.h>. I added it to not rely on these indirect includes, following item 1 of Documentation/process/submit-checklist.rst.
So I'd prefer to keep it, but I can drop it if you like that better.
Quoted 71 lines
Quoted 35 lines
drivers/pwm/pwm-ocores.c +9
-1#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 ; }drivers/pwm/pwm-ocores.c static int ocores_pwm_apply(struct pwm_chip *chip, · line 102
Quoted 10 lines
drivers/pwm/pwm-ocores.c +7
-2-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;drivers/pwm/pwm-ocores.c static int ocores_pwm_apply(struct pwm_chip *chip, · line 103
Quoted 1 line
drivers/pwm/pwm-ocores.c +0
-0period_data = mul_u64_u32_div(state->period, ddata->clk_rate,
NSEC_PER_SEC);drivers/pwm/pwm-ocores.c static int ocores_pwm_probe(struct
Quoted 2 lines
drivers/pwm/pwm-ocores.c +0
-0if (period_data >U32_MAX )@@ -218,6 +231,7 @@ static int ocores_pwm_probe(struct
platform_deviceQuoted 11 lines
drivers/pwm/pwm-ocores.c +1
-0*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 );drivers/pwm/pwm-ocores.c +0
-0if (IS_ERR (ddata->base))@@ -279,6 +293,10 @@ static int ocores_pwm_probe(struct platform_device *pdev)
Quoted 10 lines
drivers/pwm/pwm-ocores.c static int ocores_pwm_probe(struct platform_device *pdev) · line 299
Quoted 6 lines
drivers/pwm/pwm-ocores.c +4
-0static 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.
Will do.
Quoted 6 lines
Quoted 3 lines
drivers/pwm/pwm-ocores.c +0
-0{/* sentinel */ } };
MODULE_DEVICE_TABLE(of, ocores_pwm_of_match);Best regards
Uwe
Best Regards,
Changhuang