Skip to contentSkip to conversation

StarFive's Pulse Width Modulation driver support

PATCH Superseded William Qiu 4 participants 18 messages Nov 10, 2023 – Nov 24, 2023

Subsystems (4)

v7 of 10 Superseded Latest is v10 →

lore
Share & tools
lore
#0 lore raw

v7 cover StarFive's Pulse Width Modulation driver support

Hi,

This patchset adds initial rudimentary support for the StarFive Pulse Width Modulation controller driver. And this driver will be used in StarFive's VisionFive 2 board.The first patch add Documentations for the device and Patch 2 adds device probe for the module.

Changes v6->v7:
- Rebased to v6.6.
- Added dependency architecture.
- Adopted new rounding algorithm.
- Added limitation descripton.
- Used function interfaces instead of macro definitions.
- Followed the linux coding style.

Changes v5->v6:
- Rebased to v6.6rc5.
- Changed driver into a generic OpenCores driver.
- Modified dt-bindings description into OpenCores.
- Uesd the StarFive compatible string to parameterize.

Changes v4->v5:
- Rebased to v6.6rc2.
- Updated macro definition indent.
- Replaced the clock initializes the interface.
- Fixed patch description.

Changes v3->v4:
- Rebased to v6.5rc7.
- Sorted the header files in alphabetic order.
- Changed iowrite32() to writel().
- Added a way to turn off.
- Modified polarity inversion implementation.
- Added 7100 support.
- Added dts patches.
- Used the various helpers in linux/math.h.
- Corrected formatting problems.
- Renamed dtbinding to 'starfive,jh7100-pwm.yaml'.
- Dropped the redundant code.

Changes v2->v3:
- Fixed some formatting issues.

Changes v1->v2:
- Renamed the dt-binding 'pwm-starfive.yaml' to 'starfive,jh7110-pwm.yaml'.
- Dropped the compatible's Items.
- Dropped the unuse defines.
- Modified the code to follow the Linux coding style.
- Changed return value to dev_err_probe.
- Dropped the unnecessary local variable.

The patch series is based on v6.6.

William Qiu (4):
dt-bindings: pwm: Add OpenCores PWM module
pwm: opencores: Add PWM driver support
riscv: dts: starfive: jh7110: Add PWM node and pins configuration
riscv: dts: starfive: jh7100: Add PWM node and pins configuration

 .../bindings/pwm/opencores,pwm.yaml           |  56 +++++
 MAINTAINERS                                   |   7 +
 .../boot/dts/starfive/jh7100-common.dtsi      |  24 ++
 arch/riscv/boot/dts/starfive/jh7100.dtsi      |   9 +
 .../jh7110-starfive-visionfive-2.dtsi         |  22 ++
 arch/riscv/boot/dts/starfive/jh7110.dtsi      |   9 +
 drivers/pwm/Kconfig                           |  12 +
 drivers/pwm/Makefile                          |   1 +
 drivers/pwm/pwm-ocores.c                      | 236 ++++++++++++++++++
 9 files changed, 376 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/pwm/opencores,pwm.yaml
 create mode 100644 drivers/pwm/pwm-ocores.c

--
2.34.1

#1 lore raw

PATCH v7 1/4 dt-bindings: pwm: Add OpenCores PWM module

Add documentation to describe OpenCores Pulse Width Modulation controller driver.

---
 .../bindings/pwm/opencores,pwm.yaml           | 56 +++++++++++++++++++
 1 file changed, 56 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/pwm/opencores,pwm.yaml
Documentation/devicetree/bindings/pwm/opencores,pwm.yaml new file +56 -0
new file mode 100644
index 000000000000..8f776bbc1112
@@ -0,0 +1,56 @@
+# SPDX-License-Identifier: GPL-2.0-only OR BSD-2-Clause
+%YAML 1.2
+---
+$id: http://devicetree.org/schemas/pwm/opencores,pwm.yaml#
+$schema: http://devicetree.org/meta-schemas/core.yaml#
+
+title: OpenCores PWM controller
+
+maintainers:
+  - William Qiu <[email protected]>
+
+description:
+  OpenCores PTC ip core contains a PWM controller. When operating in PWM mode, the PTC core
+  generates binary signal with user-programmable low and high periods. All PTC counters and
+  registers are 32-bit.
+
+allOf:
+  - $ref: pwm.yaml#
+
+properties:
+  compatible:
+    oneOf:
+      - items:
+          - enum:
+              - starfive,jh7100-pwm
+              - starfive,jh7110-pwm
+          - const: opencores,pwm
+
+  reg:
+    maxItems: 1
+
+  clocks:
+    maxItems: 1
+
+  resets:
+    maxItems: 1
+
+  "#pwm-cells":
+    const: 3
+
+required:
+  - compatible
+  - reg
+  - clocks
+
+additionalProperties: false
+
+examples:
+  - |
+    pwm@12490000 {
+        compatible = "starfive,jh7110-pwm", "opencores,pwm";
+        reg = <0x12490000 0x10000>;
+        clocks = <&clkgen 181>;
+        resets = <&rstgen 109>;
+        #pwm-cells = <3>;
+    };
Signature · 1 line
2.34.1
#2 lore raw

Re: [PATCH v7 1/4] dt-bindings: pwm: Add OpenCores PWM module

Quoted 21 lines · William Qiu

Add documentation to describe OpenCores Pulse Width Modulation controller driver.

---
 .../bindings/pwm/opencores,pwm.yaml           | 56 +++++++++++++++++++
 1 file changed, 56 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/pwm/opencores,pwm.yaml
Documentation/devicetree/bindings/pwm/opencores,pwm.yaml new file +5 -0
new file mode 100644
index 000000000000..8f776bbc1112
@@ -0,0 +1,56 @@
+# SPDX-License-Identifier: GPL-2.0-only OR BSD-2-Clause
+%YAML 1.2
+---
+$id: http://devicetree.org/schemas/pwm/opencores,pwm.yaml#
+$schema: http://devicetree.org/meta-schemas/core.yaml#

Documentation/devicetree/bindings/pwm/opencores,pwm.yaml line 15

Quoted 10 lines
Documentation/devicetree/bindings/pwm/opencores,pwm.yaml new file +10 -0
+
+title: OpenCores PWM controller
+
+maintainers:
+  - William Qiu <[email protected]>
+
+description:
+  OpenCores PTC ip core contains a PWM controller. When operating in PWM mode, the PTC core
+  generates binary signal with user-programmable low and high periods. All PTC counters and
+  registers are 32-bit.

Wrap at 80 (as Coding Style asks)

Documentation/devicetree/bindings/pwm/opencores,pwm.yaml line 27

Quoted 12 lines
Documentation/devicetree/bindings/pwm/opencores,pwm.yaml new file +12 -0
+
+allOf:
+  - $ref: pwm.yaml#
+
+properties:
+  compatible:
+    oneOf:
+      - items:
+          - enum:
+              - starfive,jh7100-pwm
+              - starfive,jh7110-pwm
+          - const: opencores,pwm

That's a very, very generic compatible. Are you sure, 100% sure, that all designs from OpenCores from now till next 100 years will be 100% compatible?

Best regards,
Krzysztof

#3 lore raw

Re: [PATCH v7 1/4] dt-bindings: pwm: Add OpenCores PWM module

Quoted 26 lines · Krzysztof Kozlowski
Quoted 25 lines · William Qiu

Add documentation to describe OpenCores Pulse Width Modulation controller driver.

---
 .../bindings/pwm/opencores,pwm.yaml           | 56 +++++++++++++++++++
 1 file changed, 56 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/pwm/opencores,pwm.yaml
Documentation/devicetree/bindings/pwm/opencores,pwm.yaml new file +9 -0
new file mode 100644
index 000000000000..8f776bbc1112
@@ -0,0 +1,56 @@
+# SPDX-License-Identifier: GPL-2.0-only OR BSD-2-Clause
+%YAML 1.2
+---
+$id: http://devicetree.org/schemas/pwm/opencores,pwm.yaml#
+$schema: http://devicetree.org/meta-schemas/core.yaml#
+
+title: OpenCores PWM controller
+
+maintainers:
Quoted 9 lines

Documentation/devicetree/bindings/pwm/opencores,pwm.yaml line 15

Quoted 6 lines
Documentation/devicetree/bindings/pwm/opencores,pwm.yaml new file +6 -0
+  - William Qiu <[email protected]>
+
+description:
+  OpenCores PTC ip core contains a PWM controller. When operating in PWM mode, the PTC core
+  generates binary signal with user-programmable low and high periods. All PTC counters and
+  registers are 32-bit.

Wrap at 80 (as Coding Style asks)

Will update.

Quoted 8 lines
Quoted 8 lines
Documentation/devicetree/bindings/pwm/opencores,pwm.yaml new file +8 -0
+
+allOf:
+  - $ref: pwm.yaml#
+
+properties:
+  compatible:
+    oneOf:
+      - items:
Quoted 9 lines

Documentation/devicetree/bindings/pwm/opencores,pwm.yaml line 27

Quoted 4 lines
Documentation/devicetree/bindings/pwm/opencores,pwm.yaml new file +4 -0
+          - enum:
+              - starfive,jh7100-pwm
+              - starfive,jh7110-pwm
+          - const: opencores,pwm

That's a very, very generic compatible. Are you sure, 100% sure, that all designs from OpenCores from now till next 100 years will be 100% compatible?

My description is not accurate enough, this is OpenCores PTC IP, and PWM is one of those modes, so it might be better to replace compatible with "opencores, ptc-pwm"

What do you think?

Best Regrads,
William

Quoted 4 lines

Best regards,
Krzysztof

#4 lore raw

Re: [PATCH v7 1/4] dt-bindings: pwm: Add OpenCores PWM module

Quoted 18 lines · William Qiu

Will update.

Quoted 8 lines
Quoted 8 lines
Documentation/devicetree/bindings/pwm/opencores,pwm.yaml new file +8 -0
+
+allOf:
+  - $ref: pwm.yaml#
+
+properties:
+  compatible:
+    oneOf:
+      - items:
Quoted 9 lines

Documentation/devicetree/bindings/pwm/opencores,pwm.yaml line 27

Quoted 4 lines
Documentation/devicetree/bindings/pwm/opencores,pwm.yaml new file +4 -0
+          - enum:
+              - starfive,jh7100-pwm
+              - starfive,jh7110-pwm
+          - const: opencores,pwm

That's a very, very generic compatible. Are you sure, 100% sure, that all designs from OpenCores from now till next 100 years will be 100% compatible?

Quoted 5 lines

My description is not accurate enough, this is OpenCores PTC IP, and PWM is one of those modes, so it might be better to replace compatible with "opencores, ptc-pwm"

What do you think?

Sorry, maybe this answers maybe doesn't. What is "PTC"?

Best regards,
Krzysztof

maintainer
#5 lore raw

Re: [PATCH v7 1/4] dt-bindings: pwm: Add OpenCores PWM module

Quoted 19 lines · Krzysztof Kozlowski
Quoted 18 lines · William Qiu

Will update.

Quoted 17 lines

Documentation/devicetree/bindings/pwm/opencores,pwm.yaml line 27

Quoted 12 lines
Documentation/devicetree/bindings/pwm/opencores,pwm.yaml new file +12 -0
+
+allOf:
+  - $ref: pwm.yaml#
+
+properties:
+  compatible:
+    oneOf:
+      - items:
+          - enum:
+              - starfive,jh7100-pwm
+              - starfive,jh7110-pwm
+          - const: opencores,pwm

That's a very, very generic compatible. Are you sure, 100% sure, that all designs from OpenCores from now till next 100 years will be 100% compatible?

Quoted 7 lines
Quoted 5 lines

My description is not accurate enough, this is OpenCores PTC IP, and PWM is one of those modes, so it might be better to replace compatible with "opencores, ptc-pwm"

What do you think?

Sorry, maybe this answers maybe doesn't. What is "PTC"?

"pwm timer counter". AFAIU, the IP can be configured to provide all 3. I think that William pointed out on an earlier revision that they have only implemented the pwm on their hardware.
I don't think putting in "ptc" is a sufficient differentiator though, as clearly there could be several different versions of "ptc-pwm" that have the same concern about "all designs from OpenCores for now till the next 100 years" being compatible.

Cheers.
Conor.

#6 lore raw

Re: [PATCH v7 1/4] dt-bindings: pwm: Add OpenCores PWM module

Quoted 36 lines · Conor Dooley
Quoted 19 lines · Krzysztof Kozlowski
Quoted 18 lines · William Qiu

Will update.

Quoted 17 lines

Documentation/devicetree/bindings/pwm/opencores,pwm.yaml line 27

Quoted 12 lines
Documentation/devicetree/bindings/pwm/opencores,pwm.yaml new file +12 -0
+
+allOf:
+  - $ref: pwm.yaml#
+
+properties:
+  compatible:
+    oneOf:
+      - items:
+          - enum:
+              - starfive,jh7100-pwm
+              - starfive,jh7110-pwm
+          - const: opencores,pwm

That's a very, very generic compatible. Are you sure, 100% sure, that all designs from OpenCores from now till next 100 years will be 100% compatible?

Quoted 7 lines
Quoted 5 lines

My description is not accurate enough, this is OpenCores PTC IP, and PWM is one of those modes, so it might be better to replace compatible with "opencores, ptc-pwm"

What do you think?

Sorry, maybe this answers maybe doesn't. What is "PTC"?

"pwm timer counter". AFAIU, the IP can be configured to provide all 3. I think that William pointed out on an earlier revision that they have only implemented the pwm on their hardware.
I don't think putting in "ptc" is a sufficient differentiator though, as clearly there could be several different versions of "ptc-pwm" that have the same concern about "all designs from OpenCores for now till the next 100 years" being compatible.

Quoted 2 lines

Cheers.
Conor.

Hi,Conor and Krzysztof,

After discussion and review of materials, we plan to use "opencores,ptc-pwm-v1" as this version of compatible, so that it can also be compatible in the future.

What do you think?

Best regards,
William

maintainer
#7 lore raw

Re: [PATCH v7 1/4] dt-bindings: pwm: Add OpenCores PWM module

Quoted 31 lines · William Qiu
Quoted 28 lines · Conor Dooley
Quoted 26 lines · Krzysztof Kozlowski
Quoted 18 lines · William Qiu

Will update.

Quoted 8 lines
Quoted 8 lines
Documentation/devicetree/bindings/pwm/opencores,pwm.yaml new file +8 -0
+
+allOf:
+  - $ref: pwm.yaml#
+
+properties:
+  compatible:
+    oneOf:
+      - items:
Quoted 9 lines

Documentation/devicetree/bindings/pwm/opencores,pwm.yaml line 27

Quoted 4 lines
Documentation/devicetree/bindings/pwm/opencores,pwm.yaml new file +4 -0
+          - enum:
+              - starfive,jh7100-pwm
+              - starfive,jh7110-pwm
+          - const: opencores,pwm

That's a very, very generic compatible. Are you sure, 100% sure, that all designs from OpenCores from now till next 100 years will be 100% compatible?

Quoted 5 lines

My description is not accurate enough, this is OpenCores PTC IP, and PWM is one of those modes, so it might be better to replace compatible with "opencores, ptc-pwm"

What do you think?

Sorry, maybe this answers maybe doesn't. What is "PTC"?

Quoted 7 lines
Quoted 7 lines

"pwm timer counter". AFAIU, the IP can be configured to provide all 3. I think that William pointed out on an earlier revision that they have only implemented the pwm on their hardware.
I don't think putting in "ptc" is a sufficient differentiator though, as clearly there could be several different versions of "ptc-pwm" that have the same concern about "all designs from OpenCores for now till the next 100 years" being compatible.

Perhaps noting what "ptc" stands for in the description field would be a good idea.

Quoted 4 lines

After discussion and review of materials, we plan to use "opencores,ptc-pwm-v1" as this version of compatible, so that it can also be compatible in the future.

What do you think?

Do we know that it is actually "v1" of the IP? I would suggest using the version that actually matches the version of the IP that you are using in your SoC.

Thanks,
Conor.

#8 lore raw

Re: [PATCH v7 1/4] dt-bindings: pwm: Add OpenCores PWM module

Quoted 40 lines · Conor Dooley
Quoted 31 lines · William Qiu
Quoted 28 lines · Conor Dooley
Quoted 26 lines · Krzysztof Kozlowski
Quoted 18 lines · William Qiu

Will update.

Quoted 8 lines
Quoted 8 lines
(quoted diff) +8 -0
+
+allOf:
+  - $ref: pwm.yaml#
+
+properties:
+  compatible:
+    oneOf:
+      - items:
Quoted 9 lines

Review

Quoted 4 lines
(quoted diff) +4 -0
+          - enum:
+              - starfive,jh7100-pwm
+              - starfive,jh7110-pwm
+          - const: opencores,pwm

That's a very, very generic compatible. Are you sure, 100% sure, that all designs from OpenCores from now till next 100 years will be 100% compatible?

Quoted 5 lines

My description is not accurate enough, this is OpenCores PTC IP, and PWM is one of those modes, so it might be better to replace compatible with "opencores, ptc-pwm"

What do you think?

Sorry, maybe this answers maybe doesn't. What is "PTC"?

Quoted 7 lines
Quoted 7 lines

"pwm timer counter". AFAIU, the IP can be configured to provide all 3. I think that William pointed out on an earlier revision that they have only implemented the pwm on their hardware.
I don't think putting in "ptc" is a sufficient differentiator though, as clearly there could be several different versions of "ptc-pwm" that have the same concern about "all designs from OpenCores for now till the next 100 years" being compatible.

Quoted 3 lines

Perhaps noting what "ptc" stands for in the description field would be a good idea.

I will add.

Quoted 11 lines
Quoted 4 lines

After discussion and review of materials, we plan to use "opencores,ptc-pwm-v1" as this version of compatible, so that it can also be compatible in the future.

What do you think?

Do we know that it is actually "v1" of the IP? I would suggest using the version that actually matches the version of the IP that you are using in your SoC.

Thanks,
Conor.

There is no version list on their official website, so it is not certain whether it is v1, but at least the driver is the first version.

What do you think is the best way?

Thanks,
William

maintainer
#9 lore raw

Re: [PATCH v7 1/4] dt-bindings: pwm: Add OpenCores PWM module

Quoted 56 lines · William Qiu
Quoted 40 lines · Conor Dooley
Quoted 31 lines · William Qiu
Quoted 28 lines · Conor Dooley
Quoted 26 lines · Krzysztof Kozlowski
Quoted 18 lines · William Qiu

Will update.

Quoted 8 lines
Quoted 8 lines
(quoted diff) +8 -0
+
+allOf:
+  - $ref: pwm.yaml#
+
+properties:
+  compatible:
+    oneOf:
+      - items:
Quoted 9 lines

Review

Quoted 4 lines
(quoted diff) +4 -0
+          - enum:
+              - starfive,jh7100-pwm
+              - starfive,jh7110-pwm
+          - const: opencores,pwm

That's a very, very generic compatible. Are you sure, 100% sure, that all designs from OpenCores from now till next 100 years will be 100% compatible?

Quoted 5 lines

My description is not accurate enough, this is OpenCores PTC IP, and PWM is one of those modes, so it might be better to replace compatible with "opencores, ptc-pwm"

What do you think?

Sorry, maybe this answers maybe doesn't. What is "PTC"?

Quoted 7 lines
Quoted 7 lines

"pwm timer counter". AFAIU, the IP can be configured to provide all 3. I think that William pointed out on an earlier revision that they have only implemented the pwm on their hardware.
I don't think putting in "ptc" is a sufficient differentiator though, as clearly there could be several different versions of "ptc-pwm" that have the same concern about "all designs from OpenCores for now till the next 100 years" being compatible.

Quoted 3 lines

Perhaps noting what "ptc" stands for in the description field would be a good idea.

I will add.

Quoted 9 lines
Quoted 4 lines

After discussion and review of materials, we plan to use "opencores,ptc-pwm-v1" as this version of compatible, so that it can also be compatible in the future.

What do you think?

Do we know that it is actually "v1" of the IP? I would suggest using the version that actually matches the version of the IP that you are using in your SoC.

Quoted 7 lines
Quoted 2 lines

Thanks,
Conor.

There is no version list on their official website, so it is not certain whether it is v1, but at least the driver is the first version.

What do you think is the best way?

I don't have an account, so I cannot open the "ptc_spec.pdf at this link:
https://opencores.org/projects/ptc/downloads
but I would take whatever documentation you have for the spec and see what it says as the revision on the front cover.

#10 lore raw

Re: [PATCH v7 1/4] dt-bindings: pwm: Add OpenCores PWM module

In reply to William Qiu
Quoted 2 lines · William Qiu

Add documentation to describe OpenCores Pulse Width Modulation controller driver.

Please describe the hardware, not the driver.

Best regards,
Krzysztof

#11 lore raw

Re: [PATCH v7 1/4] dt-bindings: pwm: Add OpenCores PWM module

Quoted 6 lines · Krzysztof Kozlowski
Quoted 2 lines · William Qiu

Add documentation to describe OpenCores Pulse Width Modulation controller driver.

Please describe the hardware, not the driver.

Will modify the description.

Thanks.

Best Regards,
William

Quoted 3 lines

Best regards,
Krzysztof

#12 lore raw

PATCH v7 2/4 pwm: opencores: Add PWM driver support

In reply to William Qiu

Add Pulse Width Modulation driver support for OpenCores.

---
 MAINTAINERS              |   7 ++
 drivers/pwm/Kconfig      |  12 ++
 drivers/pwm/Makefile     |   1 +
 drivers/pwm/pwm-ocores.c | 236 +++++++++++++++++++++++++++++++++++++++
 4 files changed, 256 insertions(+)
 create mode 100644 drivers/pwm/pwm-ocores.c
MAINTAINERS +7 -0
index dd5de540ec0b..1861067cf385 100644
@@ -16006,6 +16006,13 @@ F:	Documentation/i2c/busses/i2c-ocores.rst
 F:	drivers/i2c/busses/i2c-ocores.c
 F:	include/linux/platform_data/i2c-ocores.h
 
+OPENCORES PWM DRIVER
+M:	William Qiu <[email protected]>
+M:	Hal Feng <[email protected]>
+S:	Supported
+F:	Documentation/devicetree/bindings/pwm/opencores,pwm-ocores.yaml
+F:	drivers/pwm/pwm-ocores.c
+
 OPENRISC ARCHITECTURE
 M:	Jonas Bonn <[email protected]>
 M:	Stefan Kristiansson <[email protected]>
drivers/pwm/Kconfig +12 -0
index 8ebcddf91f7b..a9db2d7ab294 100644
@@ -434,6 +434,18 @@ config PWM_NTXEC
 	  controller found in certain e-book readers designed by the original
 	  design manufacturer Netronix.
 
+config PWM_OCORES
+	tristate "OpenCores PWM support"
+	depends on HAS_IOMEM && OF
+	depends on COMMON_CLK && RESET_CONTROLLER
+	depends on ARCH_STARFIVE || COMPILE_TEST
+	help
+	  If you say yes to this option, support will be included for the
+	  OpenCores PWM. For details see https://opencores.org/projects/ptc.
+
+	  To compile this driver as a module, choose M here: the module
+	  will be called pwm-ocores.
+
 config PWM_OMAP_DMTIMER
 	tristate "OMAP Dual-Mode Timer PWM support"
 	depends on OF
drivers/pwm/Makefile +1 -0
index c822389c2a24..542b98202153 100644
@@ -39,6 +39,7 @@ obj-$(CONFIG_PWM_MICROCHIP_CORE)	+= pwm-microchip-core.o
 obj-$(CONFIG_PWM_MTK_DISP)	+= pwm-mtk-disp.o
 obj-$(CONFIG_PWM_MXS)		+= pwm-mxs.o
 obj-$(CONFIG_PWM_NTXEC)		+= pwm-ntxec.o
+obj-$(CONFIG_PWM_OCORES)	+= pwm-ocores.o
 obj-$(CONFIG_PWM_OMAP_DMTIMER)	+= pwm-omap-dmtimer.o
 obj-$(CONFIG_PWM_PCA9685)	+= pwm-pca9685.o
 obj-$(CONFIG_PWM_PXA)		+= pwm-pxa.o
drivers/pwm/pwm-ocores.c new file +236 -0

236 lines not on this page · raw message

Signature · 1 line
2.34.1
#13 lore raw

Re: [PATCH v7 2/4] pwm: opencores: Add PWM driver support

Quoted 1 line · William Qiu

Add Pulse Width Modulation driver support for OpenCores.

What is OpenCores? Why all your commit messages lack basic explanation of the hardware you are working on?

Quoted 5 lines
drivers/pwm/pwm-ocores.c new file +2 -0
+static const struct ocores_pwm_data jh7100_pwm_data = {
+	.get_ch_base = starfive_jh71x0_get_ch_base,

drivers/pwm/pwm-ocores.c line 153

Quoted 10 lines
drivers/pwm/pwm-ocores.c new file +10 -0
+};
+
+static const struct ocores_pwm_data jh7110_pwm_data = {
+	.get_ch_base = starfive_jh71x0_get_ch_base,
+};
+
+static const struct of_device_id ocores_pwm_of_match[] = {
+	{ .compatible = "opencores,pwm" },
+	{ .compatible = "starfive,jh7100-pwm", .data = &jh7100_pwm_data},
+	{ .compatible = "starfive,jh7110-pwm", .data = &jh7110_pwm_data},

Your bindings say something entirely else.

I don't understand what is happening with this patchset.

Quoted 2 lines
drivers/pwm/pwm-ocores.c new file +2 -0
+	{ /* sentinel */ }
+};

...

drivers/pwm/pwm-ocores.c line 193

Quoted 13 lines
drivers/pwm/pwm-ocores.c new file +13 -0
+	ddata->regs = devm_platform_ioremap_resource(pdev, 0);
+	if (IS_ERR(ddata->regs))
+		return dev_err_probe(dev, PTR_ERR(ddata->regs),
+				     "Unable to map IO resources\n");
+
+	ddata->clk = devm_clk_get(dev, NULL);
+	if (IS_ERR(ddata->clk))
+		return dev_err_probe(dev, PTR_ERR(ddata->clk),
+				     "Unable to get pwm's clock\n");
+
+	ret = clk_prepare_enable(ddata->clk);
+	if (ret)
+		return dev_err_probe(dev, ret, "Clock enable failed\n");

dev_clk_get_enabled() or whatever the API is called

Quoted 4 lines
drivers/pwm/pwm-ocores.c new file +4 -0
+
+	ddata->rst = devm_reset_control_get_optional_exclusive(dev, NULL);
+	reset_control_deassert(ddata->rst);
+

drivers/pwm/pwm-ocores.c line 207

Quoted 10 lines
drivers/pwm/pwm-ocores.c new file +10 -0
+	ddata->clk_rate = clk_get_rate(ddata->clk);
+	if (ddata->clk_rate <= 0)
+		return dev_err_probe(dev, ddata->clk_rate,
+				     "Unable to get clock's rate\n");
+
+	ret = devm_pwmchip_add(dev, chip);
+	if (ret < 0) {
+		dev_err_probe(dev, ret, "Could not register PWM chip\n");
+		clk_disable_unprepare(ddata->clk);
+		reset_control_assert(ddata->rst);

return dev_err_probe

drivers/pwm/pwm-ocores.c line 220

Quoted 13 lines
drivers/pwm/pwm-ocores.c new file +13 -0
+	}
+
+	platform_set_drvdata(pdev, ddata);
+
+	return ret;
+}
+
+static void ocores_pwm_remove(struct platform_device *dev)
+{
+	struct ocores_pwm_device *ddata = platform_get_drvdata(dev);
+
+	reset_control_assert(ddata->rst);
+	clk_disable_unprepare(ddata->clk);

You have confusing order of cleanups. It's like random, once clock then reset, in other place reset then clock.

Best regards,
Krzysztof

#14 lore raw

Re: [PATCH v7 2/4] pwm: opencores: Add PWM driver support

Quoted 6 lines · Krzysztof Kozlowski
Quoted 1 line · William Qiu

Add Pulse Width Modulation driver support for OpenCores.

What is OpenCores? Why all your commit messages lack basic explanation of the hardware you are working on?

Will modify.

Quoted 18 lines
Quoted 5 lines
drivers/pwm/pwm-ocores.c new file +2 -0
+static const struct ocores_pwm_data jh7100_pwm_data = {
+	.get_ch_base = starfive_jh71x0_get_ch_base,

drivers/pwm/pwm-ocores.c line 153

Quoted 10 lines
drivers/pwm/pwm-ocores.c new file +10 -0
+};
+
+static const struct ocores_pwm_data jh7110_pwm_data = {
+	.get_ch_base = starfive_jh71x0_get_ch_base,
+};
+
+static const struct of_device_id ocores_pwm_of_match[] = {
+	{ .compatible = "opencores,pwm" },
+	{ .compatible = "starfive,jh7100-pwm", .data = &jh7100_pwm_data},
+	{ .compatible = "starfive,jh7110-pwm", .data = &jh7110_pwm_data},

Your bindings say something entirely else.

Quoted 2 lines

I don't understand what is happening with this patchset.

Will update.

Quoted 6 lines
Quoted 3 lines
drivers/pwm/pwm-ocores.c new file +2 -0
+	{ /* sentinel */ }
+};

...

Quoted 16 lines

drivers/pwm/pwm-ocores.c line 193

Quoted 13 lines
drivers/pwm/pwm-ocores.c new file +13 -0
+	ddata->regs = devm_platform_ioremap_resource(pdev, 0);
+	if (IS_ERR(ddata->regs))
+		return dev_err_probe(dev, PTR_ERR(ddata->regs),
+				     "Unable to map IO resources\n");
+
+	ddata->clk = devm_clk_get(dev, NULL);
+	if (IS_ERR(ddata->clk))
+		return dev_err_probe(dev, PTR_ERR(ddata->clk),
+				     "Unable to get pwm's clock\n");
+
+	ret = clk_prepare_enable(ddata->clk);
+	if (ret)
+		return dev_err_probe(dev, ret, "Clock enable failed\n");

dev_clk_get_enabled() or whatever the API is called

You mean change devm_clk_get_enabled() instead of devm_clk_get()?

Quoted 8 lines
Quoted 8 lines
drivers/pwm/pwm-ocores.c new file +8 -0
+
+	ddata->rst = devm_reset_control_get_optional_exclusive(dev, NULL);
+	reset_control_deassert(ddata->rst);
+
+	ddata->clk_rate = clk_get_rate(ddata->clk);
+	if (ddata->clk_rate <= 0)
+		return dev_err_probe(dev, ddata->clk_rate,
+				     "Unable to get clock's rate\n");
Quoted 9 lines

drivers/pwm/pwm-ocores.c line 207

Quoted 6 lines
drivers/pwm/pwm-ocores.c new file +6 -0
+
+	ret = devm_pwmchip_add(dev, chip);
+	if (ret < 0) {
+		dev_err_probe(dev, ret, "Could not register PWM chip\n");
+		clk_disable_unprepare(ddata->clk);
+		reset_control_assert(ddata->rst);

return dev_err_probe

Will update.

Quoted 8 lines
Quoted 8 lines
drivers/pwm/pwm-ocores.c new file +8 -0
+	}
+
+	platform_set_drvdata(pdev, ddata);
+
+	return ret;
+}
+
+static void ocores_pwm_remove(struct platform_device *dev)
Quoted 9 lines

drivers/pwm/pwm-ocores.c line 220

Quoted 5 lines
drivers/pwm/pwm-ocores.c new file +5 -0
+{
+	struct ocores_pwm_device *ddata = platform_get_drvdata(dev);
+
+	reset_control_assert(ddata->rst);
+	clk_disable_unprepare(ddata->clk);

You have confusing order of cleanups. It's like random, once clock then reset, in other place reset then clock.

Will change it into a reasonable order.

Thank you for spending time on this patchset.

Best Regards,
William

Quoted 3 lines

Best regards,
Krzysztof

#15 lore raw

Re: [PATCH v7 2/4] pwm: opencores: Add PWM driver support

In reply to William Qiu
kernel test robot noticed the following build warnings:

Hi William,

kernel test robot noticed the following build warnings:

[auto build test WARNING on robh/for-next]
[also build test WARNING on thierry-reding-pwm/for-next linus/master v6.6 next-20231110] [If your patch is applied to the wrong git tree, kindly drop us a note. And when submitting patch, we suggest to use '--base' as documented in
https://git-scm.com/docs/git-format-patch#_base_tree_information]

url:    https://github.com/intel-lab-lkp/linux/commits/William-Qiu/dt-bindings-pwm-Add-OpenCores-PWM-module/20231110-142301
base:   https://git.kernel.org/pub/scm/linux/kernel/git/robh/linux.git for-next
patch link:    https://lore.kernel.org/r/20231110062039.103339-3-william.qiu%40starfivetech.com
patch subject: [PATCH v7 2/4] pwm: opencores: Add PWM driver support
reproduce: (https://download.01.org/0day-ci/archive/20231111/[email protected]/reproduce)

If you fix the issue in a separate patch/commit (i.e. not just a new version of the same patch/commit), kindly add following tags
| Reported-by: kernel test robot <[email protected]>
| Closes: https://lore.kernel.org/oe-kbuild-all/[email protected]/

All warnings (new ones prefixed by >>):

>> Warning: MAINTAINERS references a file that doesn't exist: Documentation/devicetree/bindings/pwm/opencores,pwm-ocores.yaml
Signature · 2 lines
0-DAY CI Kernel Test Service
https://github.com/intel/lkp-tests/wiki
#16 lore raw

PATCH v7 3/4 riscv: dts: starfive: jh7110: Add PWM node and pins configuration

In reply to William Qiu

Add OpenCores PWM controller node and add PWM pins configuration on VisionFive 2 board.

---
 .../jh7110-starfive-visionfive-2.dtsi         | 22 +++++++++++++++++++
 arch/riscv/boot/dts/starfive/jh7110.dtsi      |  9 ++++++++
 2 files changed, 31 insertions(+)
arch/riscv/boot/dts/starfive/jh7110-starfive-visionfive-2.dtsi +22 -0
index 2c02358abd71..823f298c3f4c 100644
@@ -268,6 +268,12 @@ reserved-data@600000 {
 	};
 };
 
+&pwm {
+	pinctrl-names = "default";
+	pinctrl-0 = <&pwm_pins>;
+	status = "okay";
+};
+
 &spi0 {
 	pinctrl-names = "default";
 	pinctrl-0 = <&spi0_pins>;
@@ -402,6 +408,22 @@ GPOEN_SYS_SDIO1_DATA3,
 		};
 	};
 
+	pwm_pins: pwm-0 {
+		pwm-pins {
+			pinmux = <GPIOMUX(46, GPOUT_SYS_PWM_CHANNEL0,
+					      GPOEN_SYS_PWM0_CHANNEL0,
+					      GPI_NONE)>,
+				 <GPIOMUX(59, GPOUT_SYS_PWM_CHANNEL1,
+					      GPOEN_SYS_PWM0_CHANNEL1,
+					      GPI_NONE)>;
+			bias-disable;
+			drive-strength = <12>;
+			input-disable;
+			input-schmitt-disable;
+			slew-rate = <0>;
+		};
+	};
+
 	spi0_pins: spi0-0 {
 		mosi-pins {
 			pinmux = <GPIOMUX(52, GPOUT_SYS_SPI0_TXD,
arch/riscv/boot/dts/starfive/jh7110.dtsi +9 -0
index e85464c328d0..74630feff7a8 100644
@@ -736,6 +736,15 @@ spi6: spi@120a0000 {
 			status = "disabled";
 		};
 
+		pwm: pwm@120d0000 {
+			compatible = "starfive,jh7110-pwm", "opencores,pwm";
+			reg = <0x0 0x120d0000 0x0 0x10000>;
+			clocks = <&syscrg JH7110_SYSCLK_PWM_APB>;
+			resets = <&syscrg JH7110_SYSRST_PWM_APB>;
+			#pwm-cells = <3>;
+			status = "disabled";
+		};
+
 		sfctemp: temperature-sensor@120e0000 {
 			compatible = "starfive,jh7110-temp";
 			reg = <0x0 0x120e0000 0x0 0x10000>;
Signature · 1 line
2.34.1
#17 lore raw

PATCH v7 4/4 riscv: dts: starfive: jh7100: Add PWM node and pins configuration

In reply to William Qiu

Add OpenCores PWM controller node and add PWM pins configuration on VisionFive 1 board.

---
 .../boot/dts/starfive/jh7100-common.dtsi      | 24 +++++++++++++++++++
 arch/riscv/boot/dts/starfive/jh7100.dtsi      |  9 +++++++
 2 files changed, 33 insertions(+)
arch/riscv/boot/dts/starfive/jh7100-common.dtsi +24 -0
index b93ce351a90f..11876906cc05 100644
@@ -84,6 +84,24 @@ GPO_I2C2_PAD_SDA_OEN,
 		};
 	};
 
+	pwm_pins: pwm-0 {
+		pwm-pins {
+			pinmux = <GPIOMUX(7,
+				  GPO_PWM_PAD_OUT_BIT0,
+				  GPO_PWM_PAD_OE_N_BIT0,
+				  GPI_NONE)>,
+				 <GPIOMUX(5,
+				  GPO_PWM_PAD_OUT_BIT1,
+				  GPO_PWM_PAD_OE_N_BIT1,
+				  GPI_NONE)>;
+			bias-disable;
+			drive-strength = <35>;
+			input-disable;
+			input-schmitt-disable;
+			slew-rate = <0>;
+		};
+	};
+
 	uart3_pins: uart3-0 {
 		rx-pins {
 			pinmux = <GPIOMUX(13, GPO_LOW, GPO_DISABLE,
@@ -154,6 +172,12 @@ &osc_aud {
 	clock-frequency = <27000000>;
 };
 
+&pwm {
+	pinctrl-names = "default";
+	pinctrl-0 = <&pwm_pins>;
+	status = "okay";
+};
+
 &uart3 {
 	pinctrl-names = "default";
 	pinctrl-0 = <&uart3_pins>;
arch/riscv/boot/dts/starfive/jh7100.dtsi +9 -0
index 35ab54fb235f..9a7192b0684c 100644
@@ -274,6 +274,15 @@ watchdog@12480000 {
 				 <&rstgen JH7100_RSTN_WDT>;
 		};
 
+		pwm: pwm@12490000 {
+			compatible = "starfive,jh7100-pwm", "opencores,pwm";
+			reg = <0x0 0x12490000 0x0 0x10000>;
+			clocks = <&clkgen JH7100_CLK_PWM_APB>;
+			resets = <&rstgen JH7100_RSTN_PWM_APB>;
+			#pwm-cells = <3>;
+			status = "disabled";
+		};
+
 		sfctemp: temperature-sensor@124a0000 {
 			compatible = "starfive,jh7100-temp";
 			reg = <0x0 0x124a0000 0x0 0x10000>;
Signature · 1 line
2.34.1