Skip to contentSkip to conversation

dt-bindings: pwm: st,pwm: convert to DT schema

PATCH Superseded Charan Pedumuru 3 participants 6 messages Jun 18 – Jun 23

Subsystems (2)

v2 of 5 Superseded Latest is v5 →

lore
Share & tools
lore
#0 lore raw

PATCH v2 1/1 dt-bindings: pwm: st,pwm: convert to DT schema

Convert STMicroelectronics STiH41x PWM/Capture controller binding to DT schema.
Changes during conversion:
- Add 'interrupts' to the required list. The text binding listed it as required and the driver unconditionally calls platform_get_irq().
- Drop pinctrl-0 from the required list as pinctrl properties are inherited and validated by the pinctrl schema.

---
Changes in v2:
- Add the missing interrupts to the required following the old binding.
- Modify commit message to explain the changes made.
- Link to v1: https://patch.msgid.link/[email protected]

---
 Documentation/devicetree/bindings/pwm/pwm-st.txt  | 43 -----------
 Documentation/devicetree/bindings/pwm/st,pwm.yaml | 93 +++++++++++++++++++++++
 2 files changed, 93 insertions(+), 43 deletions(-)
Documentation/devicetree/bindings/pwm/pwm-st.txt deleted +0 -43
deleted file mode 100644
index 19fce774cafa..000000000000
@@ -1,43 +0,0 @@
-STMicroelectronics PWM driver bindings
---------------------------------------
-
-Required parameters:
-- compatible :		"st,pwm"
-- #pwm-cells : 		Number of cells used to specify a PWM. First cell
-			specifies the per-chip index of the PWM to use and the
-			second cell is the period in nanoseconds - fixed to 2
-			for STiH41x.
-- reg :			Physical base address and length of the controller's
-			registers.
-- pinctrl-names: 	Set to "default".
-- pinctrl-0: 		List of phandles pointing to pin configuration nodes
-			for PWM module.
-			For Pinctrl properties, please refer to [1].
-- clock-names: 		Valid entries are "pwm" and/or "capture".
-- clocks: 		phandle of the clock used by the PWM module.
-			For Clk properties, please refer to [2].
-- interrupts:		IRQ for the Capture device
-
-Optional properties:
-- st,pwm-num-chan:	Number of available PWM channels.  Default is 0.
-- st,capture-num-chan:	Number of available Capture channels.  Default is 0.
-
-[1] Documentation/devicetree/bindings/pinctrl/pinctrl-bindings.txt
-[2] Documentation/devicetree/bindings/clock/clock-bindings.txt
-
-Example:
-
-pwm1: pwm@fe510000 {
-	compatible = "st,pwm";
-	reg = <0xfe510000 0x68>;
-	#pwm-cells = <2>;
-	pinctrl-names = "default";
-	pinctrl-0 = <&pinctrl_pwm1_chan0_default
-		     &pinctrl_pwm1_chan1_default
-		     &pinctrl_pwm1_chan2_default
-		     &pinctrl_pwm1_chan3_default>;
-	clocks = <&clk_sysin>;
-	clock-names = "pwm";
-	st,pwm-num-chan = <4>;
-	st,capture-num-chan = <2>;
-};
Documentation/devicetree/bindings/pwm/st,pwm.yaml new file +93 -0

93 lines not on this page · raw message

---
base-commit: c425609d6ac4012c8bbf01ec2e10e801b1923a7b
change-id: 20260613-st-pwm-1feade6cfea3

Best regards,

Signature · 1 line
Charan Pedumuru <[email protected]>
#1 lore raw
Thank you for your contribution! Sashiko AI review found 3 potential issue(s) to consider:

Thank you for your contribution! Sashiko AI review found 3 potential issue(s) to consider:

New issues:
- [High] The YAML binding strictly validates against st,pwm, but the hardware driver and actual device trees use st,sti-pwm.
- [Medium] The schema drops pinctrl-0 from the required list but keeps pinctrl-names as required, creating an inconsistent configuration requirement.

Pre-existing issues:
- [High] The driver requests the IRQ before fully initializing the regmap fields used by the interrupt handler, creating a race condition that can lead to a NULL pointer dereference. --

commit e38e89bd06d5e023d198bb6e9fb8add957cdf8e9
Author: Charan Pedumuru <[email protected]>

dt-bindings: pwm: st,pwm: convert to DT schema

This commit converts the STMicroelectronics STiH41x PWM/Capture controller text binding to DT schema. It updates the required list by adding 'interrupts' and dropping 'pinctrl-0'.

Quoted 6 lines
Documentation/devicetree/bindings/pwm/st,pwm.yaml new file +0 -0
new file mode 100644
index 0000000000000..a045502e0e704
@@ -0,0 +1,93 @@

[ ... ]

Documentation/devicetree/bindings/pwm/st,pwm.yaml line 25

Quoted 3 lines
Documentation/devicetree/bindings/pwm/st,pwm.yaml new file +3 -0
+properties:
+  compatible:
+    const: st,pwm

[Severity: High]
Does this compatible string match the hardware driver and actual device trees?

If existing in-kernel device trees and the matching driver (drivers/pwm/pwm-sti.c) use "st,sti-pwm" instead of "st,pwm", will make dtbs_check silently skip validation for them?

[ ... ]

Documentation/devicetree/bindings/pwm/st,pwm.yaml line 68

Quoted 12 lines
Documentation/devicetree/bindings/pwm/st,pwm.yaml new file +12 -0
+  st,capture-num-chan:
+    $ref: /schemas/types.yaml#/definitions/uint32
+    description: Number of available input capture channels.
+    minimum: 0
+    maximum: 4
+    default: 0
+
+required:
+  - reg
+  - compatible
+  - "#pwm-cells"
+  - pinctrl-names

[Severity: Medium]
Since 'pinctrl-0' was dropped from the required list, should 'pinctrl-names' also be removed?

Retaining 'pinctrl-names' in the required list while making 'pinctrl-0' optional forces device trees that do not define any pinctrl configuration to include a meaningless pinctrl-names = "default"; just to pass schema validation.

Quoted 3 lines
Documentation/devicetree/bindings/pwm/st,pwm.yaml new file +3 -0
+  - clock-names
+  - clocks
+  - interrupts

[ ... ]

Documentation/devicetree/bindings/pwm/st,pwm.yaml line 79

Quoted 5 lines
Documentation/devicetree/bindings/pwm/st,pwm.yaml new file +5 -0
+examples:
+  - |
+    #include <dt-bindings/interrupt-controller/arm-gic.h>
+    pwm@fe510000 {
+        compatible = "st,pwm";

[Severity: High]
Does this example propagate an incorrect compatible string?

If the hardware actually uses "st,sti-pwm", using "st,pwm" here might mislead future device tree authors.

[ ... ]

[Severity: High]
This is a pre-existing issue, but can the interrupt fire before the regmap fields are fully initialized?

Looking at drivers/pwm/pwm-sti.c:sti_pwm_probe(), the IRQ is requested early:

	ret = devm_request_irq(&pdev->dev, irq, sti_pwm_interrupt, 0, ...);

Later, the regmap fields crucial for the IRQ handler are initialized:

	ret = sti_pwm_probe_regmap(pc);

If a pending interrupt from the bootloader fires immediately after devm_request_irq(), sti_pwm_interrupt() will execute and call regmap_field_read(pc->pwm_cpt_int_stat, ...). Since pc->pwm_cpt_int_stat is NULL before sti_pwm_probe_regmap() initializes it, would this cause a kernel panic due to a NULL pointer dereference?

Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=1
#2 lore raw
In reply to Charan Pedumuru

Documentation/devicetree/bindings/pwm/st,pwm.yaml line 21

Quoted 10 lines · Charan Pedumuru
Documentation/devicetree/bindings/pwm/st,pwm.yaml new file +10 -0
+description:
+  The STiH41x PWM controller supports both PWM output and input capture
+  functionality. It provides multiple PWM output channels for generating
+  variable duty-cycle waveforms, and multiple input capture channels for
+  measuring external signal periods and pulse widths. PWM output channels
+  and input capture channels are configured independently via
+  st,pwm-num-chan and st,capture-num-chan respectively.
+
+allOf:
+  - $ref: pwm.yaml#

Where is this compatible used?

Best regards,
Krzysztof

#3 lore raw
Quoted 13 lines · Krzysztof Kozlowski

Documentation/devicetree/bindings/pwm/st,pwm.yaml line 21

Quoted 10 lines · Charan Pedumuru
Documentation/devicetree/bindings/pwm/st,pwm.yaml new file +10 -0
+description:
+  The STiH41x PWM controller supports both PWM output and input capture
+  functionality. It provides multiple PWM output channels for generating
+  variable duty-cycle waveforms, and multiple input capture channels for
+  measuring external signal periods and pulse widths. PWM output channels
+  and input capture channels are configured independently via
+  st,pwm-num-chan and st,capture-num-chan respectively.
+
+allOf:
+  - $ref: pwm.yaml#

Where is this compatible used?

I will remove this allof and redefine the YAML again

Quoted 4 lines

Best regards,
Krzysztof

Signature · 2 lines
Best Regards,
Charan.
#4 lore raw
Quoted 17 lines · Charan Pedumuru
Quoted 13 lines · Krzysztof Kozlowski

Documentation/devicetree/bindings/pwm/st,pwm.yaml line 21

Quoted 10 lines · Charan Pedumuru
Documentation/devicetree/bindings/pwm/st,pwm.yaml new file +10 -0
+description:
+  The STiH41x PWM controller supports both PWM output and input capture
+  functionality. It provides multiple PWM output channels for generating
+  variable duty-cycle waveforms, and multiple input capture channels for
+  measuring external signal periods and pulse widths. PWM output channels
+  and input capture channels are configured independently via
+  st,pwm-num-chan and st,capture-num-chan respectively.
+
+allOf:
+  - $ref: pwm.yaml#

Where is this compatible used?

Quoted 2 lines

I will remove this allof and redefine the YAML again

Sorry, I think I messed something so comment was incorrectly placed.

The comment should be under:

"+ const: st,pwm"

Best regards,
Krzysztof

#5 lore raw
Quoted 22 lines · Krzysztof Kozlowski
Quoted 17 lines · Charan Pedumuru
Quoted 13 lines · Krzysztof Kozlowski

Documentation/devicetree/bindings/pwm/st,pwm.yaml line 21

Quoted 10 lines · Charan Pedumuru
Documentation/devicetree/bindings/pwm/st,pwm.yaml new file +10 -0
+description:
+  The STiH41x PWM controller supports both PWM output and input capture
+  functionality. It provides multiple PWM output channels for generating
+  variable duty-cycle waveforms, and multiple input capture channels for
+  measuring external signal periods and pulse widths. PWM output channels
+  and input capture channels are configured independently via
+  st,pwm-num-chan and st,capture-num-chan respectively.
+
+allOf:
+  - $ref: pwm.yaml#

Where is this compatible used?

Quoted 2 lines

I will remove this allof and redefine the YAML again

Quoted 5 lines

Sorry, I think I messed something so comment was incorrectly placed.

The comment should be under:

"+ const: st,pwm"

Okay, this compatible is not used and there is a similar compatible "st,sti-pwm", AI bot detected it and I will rename it and modify the commit message with necessary explanation. Also the maintainer email doesn't exist now. I will change that too with other maintainer. Thank you.

Quoted 3 lines

Best regards,
Krzysztof

Signature · 2 lines
Best Regards,
Charan.