Skip to contentSkip to conversation

Update designware pwm driver

PATCH Superseded [email protected] 4 participants 10 messages Mar 6 – Mar 17

Subsystems (2)

v2 of 14 Superseded Latest is v14 →

lore
Share & tools
lore
#0 lore raw

v2 cover Update designware pwm driver

From: Xuyang Dong <[email protected]>

There is already a patch [1] for the DesignWare PWM driver, which is posted by Ben and still under review. Based on this patch, this series is a continuation of [1] to add support for IP versions 2.11a and later, which includes support for "Pulse Width Modulation with 0% and 100% Duty Cycle".

Supported chips:
ESWIN EIC7700 series SoC.

Test:
Tested this patch on the Sifive HiFive Premier P550 (which uses the EIC7700 SoC).

[1] https://lore.kernel.org/lkml/[email protected]/

Updates:
Change in v2:
- YAML:
- Remove eswin,eic7700-pwm.yaml. Use snps,dw-apb-timers-pwm2.yaml. The description in snps,dw-apb-timers-pwm2.yaml is better.
- Add the resets property as optional, as defined in the databook.
- Remove snps,pwm-full-range-enable as no additional property is needed.
- Driver:
- Change the file from pwm-dwc-eic7700.c to pwm-dwc-of.c from [1].
- Define DWC_TIM_VERSION_ID_2_11A 2.11a as the baseline version.
- Enable the 0% and 100% duty cycle mode by setting dwc->feature if the version read from the TIMERS_COMP_VERSION register is later than or equal to DWC_TIM_VERSION_ID_2_11A.
- Use the DIV_ROUND_UP_ULL() to calculate width in the .apply and .get_state.
- Additionally, Power Management (PM) support has been added to the pwm-dwc-of.c driver.
- Drop the headers that are not used.
- Use devm_clk_get_enabled() instead of devm_clk_get().
- Drop of_match_ptr.
- Fix build error with 1ULL << 32.

- Link to v1: https://lore.kernel.org/all/[email protected]/
- Link to v9: https://lore.kernel.org/lkml/[email protected]/

Xuyang Dong (2):
dt-bindings: pwm: dwc: add reset optional
pwm: dwc: add of/platform support

 .../bindings/pwm/snps,dw-apb-timers-pwm2.yaml |   3 +
 drivers/pwm/Kconfig                           |  10 +
 drivers/pwm/Makefile                          |   1 +
 drivers/pwm/pwm-dwc-core.c                    | 101 ++++++--
 drivers/pwm/pwm-dwc-of.c                      | 216 ++++++++++++++++++
 drivers/pwm/pwm-dwc.h                         |  25 +-
 6 files changed, 327 insertions(+), 29 deletions(-)
 create mode 100644 drivers/pwm/pwm-dwc-of.c

--
2.34.1

#1 lore raw

PATCH v2 1/2 dt-bindings: pwm: dwc: add reset optional

From: Xuyang Dong <[email protected]>

Add the optional resets property.

---
 .../devicetree/bindings/pwm/snps,dw-apb-timers-pwm2.yaml       | 3 +++
 1 file changed, 3 insertions(+)
Documentation/devicetree/bindings/pwm/snps,dw-apb-timers-pwm2.yaml +3 -0
index 7523a89a1773..fd9f73c75121 100644
@@ -43,6 +43,9 @@ properties:
       - const: bus
       - const: timer
 
+  resets:
+    maxItems: 1
+
   snps,pwm-number:
     $ref: /schemas/types.yaml#/definitions/uint32
     description: The number of PWM channels configured for this instance
Signature · 1 line
2.34.1
#5 lore raw

PATCH v2 2/2 pwm: dwc: add of/platform support

In reply to [email protected]

From: Xuyang Dong <[email protected]>

The dwc pwm controller can be used in non-PCI systems, so allow either platform or OF based probing.

---
 drivers/pwm/Kconfig        |  10 ++
 drivers/pwm/Makefile       |   1 +
 drivers/pwm/pwm-dwc-core.c | 101 +++++++++++++----
 drivers/pwm/pwm-dwc-of.c   | 216 +++++++++++++++++++++++++++++++++++++
 drivers/pwm/pwm-dwc.h      |  25 +++--
 5 files changed, 324 insertions(+), 29 deletions(-)
 create mode 100644 drivers/pwm/pwm-dwc-of.c
drivers/pwm/Kconfig +10 -0
index 6f3147518376..50aea24b6168 100644
@@ -249,6 +249,16 @@ config PWM_DWC
 	  To compile this driver as a module, choose M here: the module
 	  will be called pwm-dwc.
 
+config PWM_DWC_OF
+	tristate "DesignWare PWM Controller (OF bus)"
+	depends on HAS_IOMEM && (OF || COMPILE_TEST)
+	select PWM_DWC_CORE
+	help
+	  PWM driver for Synopsys DWC PWM Controller on an OF bus or
+	  a platform bus.
+	  To compile this driver as a module, choose M here: the module
+	  will be called pwm-dwc-of.
+
 config PWM_EP93XX
 	tristate "Cirrus Logic EP93xx PWM support"
 	depends on ARCH_EP93XX || COMPILE_TEST
drivers/pwm/Makefile +1 -0
index 0dc0d2b69025..470411a7e5ea 100644
@@ -20,6 +20,7 @@ obj-$(CONFIG_PWM_CRC)		+= pwm-crc.o
 obj-$(CONFIG_PWM_CROS_EC)	+= pwm-cros-ec.o
 obj-$(CONFIG_PWM_DWC_CORE)	+= pwm-dwc-core.o
 obj-$(CONFIG_PWM_DWC)		+= pwm-dwc.o
+obj-$(CONFIG_PWM_DWC_OF)	+= pwm-dwc-of.o
 obj-$(CONFIG_PWM_EP93XX)	+= pwm-ep93xx.o
 obj-$(CONFIG_PWM_FSL_FTM)	+= pwm-fsl-ftm.o
 obj-$(CONFIG_PWM_GPIO)		+= pwm-gpio.o
drivers/pwm/pwm-dwc-core.c +79 -22

153 lines not on this page · raw message

drivers/pwm/pwm-dwc-of.c new file +216 -0

216 lines not on this page · raw message

drivers/pwm/pwm-dwc.h +18 -7
index 1562594e7f85..75f7c2d031c4 100644
@@ -26,12 +26,19 @@ MODULE_IMPORT_NS("dwc_pwm");
 #define DWC_TIMERS_TOTAL	8
 
 /* Timer Control Register */
-#define DWC_TIM_CTRL_EN		BIT(0)
-#define DWC_TIM_CTRL_MODE	BIT(1)
-#define DWC_TIM_CTRL_MODE_FREE	(0 << 1)
-#define DWC_TIM_CTRL_MODE_USER	(1 << 1)
-#define DWC_TIM_CTRL_INT_MASK	BIT(2)
-#define DWC_TIM_CTRL_PWM	BIT(3)
+#define DWC_TIM_CTRL_EN			BIT(0)
+#define DWC_TIM_CTRL_MODE		BIT(1)
+#define DWC_TIM_CTRL_MODE_FREE		(0 << 1)
+#define DWC_TIM_CTRL_MODE_USER		BIT(1)
+#define DWC_TIM_CTRL_INT_MASK		BIT(2)
+#define DWC_TIM_CTRL_PWM		BIT(3)
+#define DWC_TIM_CTRL_0N100PWM_EN	BIT(4)
+
+/*
+ * The version 2.11a and later add "Pulse Width Modulation with
+ * 0% and 100% Duty Cycle".
+ */
+#define DWC_TIM_VERSION_ID_2_11A	0x3231312a
 
 struct dwc_pwm_info {
 	unsigned int nr;
@@ -52,8 +59,12 @@ struct dwc_pwm_ctx {
 
 struct dwc_pwm {
 	void __iomem *base;
-	unsigned int clk_ns;
+	struct clk *bus_clk;
+	struct clk *clk;
+	unsigned long clk_rate;
+	struct reset_control *rst;
 	struct dwc_pwm_ctx ctx[DWC_TIMERS_TOTAL];
+	u32 features;
 };
 
 static inline struct dwc_pwm *to_dwc_pwm(struct pwm_chip *chip)
Signature · 1 line
2.34.1
#6 lore raw
In reply to [email protected]
Quoted 3 lines · On Fri, Mar 06, 2026 at 05:30:00PM +0800, [email protected] wrote:

From: Xuyang Dong <[email protected]>

There is already a patch [1] for the DesignWare PWM driver,

So provide review there instead of allowing Ben to post incomplete hardware description which you want to correct here...

I don't understand why posting this change.

Quoted 5 lines

which is posted by Ben and still under review. Based on this patch, this series is a continuation of [1] to add support for IP versions 2.11a and later, which includes support for "Pulse Width Modulation with 0% and 100% Duty Cycle".

Best regards,
Krzysztof

#7 lore raw
Quoted 9 lines · Krzysztof Kozlowski
Quoted 3 lines · On Fri, Mar 06, 2026 at 05:30:00PM +0800, [email protected] wrote:

From: Xuyang Dong <[email protected]>

There is already a patch [1] for the DesignWare PWM driver,

So provide review there instead of allowing Ben to post incomplete hardware description which you want to correct here...

I don't understand why posting this change.

I see now Ben did not post the bindings change, so this message here just confused me.

Quoted 8 lines
Quoted 8 lines

which is posted by Ben and still under review. Based on this patch, this series is a continuation of [1] to add support for IP versions 2.11a and later, which includes support for "Pulse Width Modulation with 0% and 100% Duty Cycle".

But does this mean the patchset cannot be even tested?

Quoted 4 lines

Best regards,
Krzysztof

Best regards,
Krzysztof

#3 lore raw

Re: Re: [PATCH v2 1/2] dt-bindings: pwm: dwc: add reset optional

In reply to Krzysztof Kozlowski
Quoted 5 lines
Quoted 2 lines

Add the optional resets property.

Why?

Hi Krzysztof,

The DesignWare PWM controller provides separate reset signals dedicated to each clock domain, as specified in the hardware documentation. Without asserting and deasserting these resets during probe, the PWM output may remain in an undefined state after system reboot.

Add optional reset control handling to ensure the controller is properly initialized.

We will update the commit message in the next version.

Best regards,
Xuyang Dong

Quoted 5 lines
Quoted 2 lines

Best regards,
Krzysztof

#8 lore raw
In reply to Krzysztof Kozlowski

Hi Krzysztof,

Quoted 10 lines
Quoted 7 lines
Quoted 2 lines

There is already a patch [1] for the DesignWare PWM driver,

So provide review there instead of allowing Ben to post incomplete hardware description which you want to correct here...

I don't understand why posting this change.

I see now Ben did not post the bindings change, so this message here just confused me.

We noticed Ben’s DesignWare PWM driver series on lore [1]. The patches for the DT bindings, pwm-dwc.c and pwm-dwc-core.c have already been merged into the kernel, for example, patches 1/6, 2/6, and 3/6.
However, the pwm-dwc-of.c patch has not yet been accepted, for example, patches 4/6, 5/6, and 6/6.
We discussed the status of this PWM series with Ben on lore. Given the lack of recent updates following Ben’s message in [2], we’d like to step in and help move this forward.

This series is based on v9 and includes the following updates:
1. Migrated to the latest PWM subsystem structure and APIs.
2. Added support for 0% and 100% duty cycle modes.
3. Implemented basic power management (runtime PM) support.

The previous series (v1) has been deprecated. Would it be more appropriate to send this as v2 rather than v10?

[1] https://lore.kernel.org/lkml/[email protected]/
[2] https://lore.kernel.org/lkml/[email protected]/

The binding file 'snps,dw-apb-timers-pwm2.yaml' has already been merged, but the current driver lacks reset support.
Therefore, patch 1 adds an optional reset property to address this.

We will update the commit message in the next version.

Quoted 10 lines
Quoted 8 lines
Quoted 8 lines

which is posted by Ben and still under review. Based on this patch, this series is a continuation of [1] to add support for IP versions 2.11a and later, which includes support for "Pulse Width Modulation with 0% and 100% Duty Cycle".

But does this mean the patchset cannot be even tested?

Support for 0% and 100% duty cycle mode (available in DesignWare PWM IP version 2.11a and later) has been tested on the EIC7700 SoC, which integrates IP version 2.13a.

For Ben's implementation, which does not support this mode, testing can still be done by setting dwc->features to 0 after reading the version register, effectively disabling 0% and 100% duty cycle support.

Regards,
Xuyang Dong

#4 lore raw

Re: [PATCH v2 1/2] dt-bindings: pwm: dwc: add reset optional

In reply to Xuyang Dong

Hello,

Quoted 4 lines · Xuyang Dong

The DesignWare PWM controller provides separate reset signals dedicated to each clock domain, as specified in the hardware documentation. Without asserting and deasserting these resets during probe, the PWM output may remain in an undefined state after system reboot.

Note there is an additional difficulty: A usual wish for machines with a display is that the bootloader sets up a splash screen that is smoothly taken over by Linux during boot. A reset of the PWM driving the backlight then most probably results in a short dark display which doesn't qualify for smooth.

So if you have a way to distinguish between "random state after power-on" and "already programmed by the bootloader" this would be great.

Best regards
Uwe

#9 lore raw
In reply to Krzysztof Kozlowski
Quoted 9 lines · Krzysztof Kozlowski
Quoted 3 lines · On Fri, Mar 06, 2026 at 05:30:00PM +0800, [email protected] wrote:

From: Xuyang Dong <[email protected]>

There is already a patch [1] for the DesignWare PWM driver,

So provide review there instead of allowing Ben to post incomplete hardware description which you want to correct here...

I don't understand why posting this change.

I think the binding got merged a while ago whilst we ended up never getting the go-ahead to finish the driver changes. Unfortunately all the client hardware was returned and we had to destroy all the data from them.

Signature · 4 lines
Ben Dooks				http://www.codethink.co.uk/
Senior Engineer				Codethink - Providing Genius

https://www.codethink.co.uk/privacy.html