Skip to contentSkip to conversation

ASPEED AST2500 PWM support

PATCH In review Jaghathiswari Rankappagounder Natarajan 2 participants 9 messages Nov 9, 2016 – Nov 28, 2016

Subsystems (3)
lore
Share & tools
lore
#0 lore raw

v2 cover ASPEED AST2500 PWM support

Support for ASPEED AST2500 PWM driver.
The AST2500 PWM controller can support 8 PWM output ports. There can be three different PWM sources (Type M, N and O); each PWM source can have different settings.
Each PWM output port can have one of the three different PWM sources. There is a sysfs file through which the user can configure the duty cycle for the particular PWM output port.
Added devicetree binding documentation for ast2500 pwm support. Added support in Zaius platform for 4 PWM output ports since it has four fans.

Tested on Zaius board and observed that when duty cycle is lowered then the fan speed is lowered and when the duty cycle is increased then the fan speed increases.

Tested on AST2500 EVB board and observed the PWM output pulses come correctly based on the given settings using Logic Saleae Analyzer.

Jaghathiswari Rankappagounder Natarajan (3):
devicetree: binding documentation update for ASPEED AST2500 PWM driver
drivers: hwmon: ASPEED AST2500 PWM driver
devicetree : Add support in Zaius platform for 4 PWM output ports

 .../bindings/hwmon/aspeed,ast2500-pwm.txt          | 116 ++++
 arch/arm/boot/dts/aspeed-bmc-opp-zaius.dts         |  43 ++
 drivers/hwmon/Kconfig                              |   5 +
 drivers/hwmon/Makefile                             |   2 +-
 drivers/hwmon/aspeed_ast2500_pwm.c                 | 662 +++++++++++++++++++++
 drivers/hwmon/aspeed_ast2500_pwm.h                 | 128 ++++
 6 files changed, 955 insertions(+), 1 deletion(-)
 create mode 100644 Documentation/devicetree/bindings/hwmon/aspeed,ast2500-pwm.txt
 create mode 100644 drivers/hwmon/aspeed_ast2500_pwm.c
 create mode 100644 drivers/hwmon/aspeed_ast2500_pwm.h

--
2.8.0.rc3.226.g39d4020

#1 lore raw

PATCH v2 1/3 devicetree: binding documentation update for ASPEED AST2500 PWM driver

Add binding documentation update for ASPEED AST2500 PWM driver. The ASPEED AST2500 PWM driver supports 8 PWM output ports. The parent node indicates a PWM controller and has options to:
provide register set information, provide pinctrl information, enable PWM and Fan Tach clock, select clock source, provide settings for three different PWM sources (type M, N and O).

Each sub node indicates a PWM output port and has options to:
enable PWM port, select the PWM source for the PWM port, provide duty cycle values to be used at startup.

v2:
- Made binding documentation update as a separate patch.
- Included AST2500 in the description.
- Changed format to "aspeed,ast2500-pwm".
- Included explanation for types M ,N and O and calculation example to determine L, H, and period bits.

---
 .../bindings/hwmon/aspeed,ast2500-pwm.txt          | 116 +++++++++++++++++++++
 1 file changed, 116 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/hwmon/aspeed,ast2500-pwm.txt
Documentation/devicetree/bindings/hwmon/aspeed,ast2500-pwm.txt new file +116 -0
new file mode 100644
index 0000000..2c3f2b6
@@ -0,0 +1,116 @@
+ASPEED AST2500 PWM device driver
+
+The ASPEED AST2500 PWM controller can support 8 PWM outputs.
+
+Required properties:
+- #address-cells : should be 1.
+- #size-cells : should be 1.
+- reg : address and length of the register set for the device.
+- pinctrl-names : A pinctrl state named "default" must be defined.
+- pinctrl-0 : Phandle referencing pin configuration of the aspeed pwm ports.
+- compatible : should be "aspeed,ast2500-pwm".
+- clock_enable : option to enable PWM and fan tach clock. should be 1.
+  (D[0] in PTCR00).
+- clock_source : option for clock source selection. 0 indicates 24MHz clock
+  and 1 indicates MCLK (D[1] in PTCR00).
+- typem_pwm_clock : PWM types M, N and 0 are three types just to have three
+  independent PWM source. Each could be assigned to the 8 PWM channels
+  with it's own settings
+  This array contains 4 values.
+  The first value indicates if the values for type M PWM are valid.
+  If the first value is 1, then it indicates that the rest of the values
+  are valid. If it is 0, then invalid.
+  The second value indicates the type M PWM clock division L bit (D[3:0]
+  in PTCR04). (value 0 in D[3:0] indicates 1, value 1 in D[3:0] indicates 2,
+  value 2 in D[3:0] indicates 4, value 3 in D[3:0] indicates 6 and so on
+  with increments in multiples of two).
+  The third value indicates type M PWM clock divison H bit (D[7:4] in PTCR04).
+  (value 0 in D[7:4] indicates 1, value 1 in D[7:4] indicates 2,
+  value 2 in D[7:4] indicates 4, value 3 in D[7:4] indicates 8 and
+  so on with increments in powers of two).
+  The fourth value indicates type M PWM period bit (D[15:8] in PTCR04).
+  If type M is chosen and clock source is 24 MHz then:
+  The PWM base clock = 24Mhz / (type M clock division L bit *
+  type M clock division H bit).
+  The PWM frequency = The PWM base clock / (type M PWM period bit + 1)
+  If we plan to output 25Khz PWM frequency then we can use:
+  typem_pwm_clock = <1 5 0 95>
+  The PWM frequency = 24Mhz / (10 * 1  * (95 + 1)) = 25Khz
+- typen_pwm_clock : This array contains 4 values.
+  The first value indicates if the values for type N PWM are valid.
+  If the first value is 1, then it indicates that the rest of the values
+  are valid. If it is 0, then invalid.
+  The second value indicates the type N PWM clock division L bit (D[19:16]
+  in PTCR04).
+  The third value indicates type N PWM clock division H bit
+  (D[23:20] in PTCR04).
+  The fourth value indicates type N PWM period bit (D[31:24] in PTCR04).
+  Calculations similar as for type M.
+- typeo_pwm_clock : This array contains 4 values.
+  The first value indicates indicates if the values for type O PWM are valid.
+  If the first value is 1, then it indicates that the rest of the values
+  are valid. If it is 0, then invalid.
+  The second value indicates if the type O PWM clock division L bit
+  (D[3:0] in PTCR44).
+  The third value indicates type O PWM clock divison H bit (D[7:4] in PTCR44).
+  The fourth value indicates type O PWM period bit (D[15:8] in PTCR44).
+  Calculations similar as for type M.
+
+Each subnode represents a PWM output port.
+
+Subnode Format
+--------------
+Required properties:
+- pwm_port : Indicates the PWM port. Values 0 through 7 indicate PWM ports
+  A through H respectively.
+- pwm_enable : Option to enable the PWM port indicated above. 0 is enable
+  and 1 is disable.
+  D[8] in PTCR00 indicates enabling PWM port A,
+  D[9] in PTCR00 indicates enabling PWM port B,
+  D[10] in PTCR00 indicates enabling PWM port C,
+  D[11] in PTCR00 indicates enabling PWM port D,
+  D[8] in PTCR40 indicates enabling PWM port E,
+  D[9] in PTCR40 indicates enabling PWM port F,
+  D[10] in PTCR40 indicates enabling PWM port G,
+  D[11] in PTCR40 indicates enabling PWM port H.
+- pwm_type : Indicates the clock type for the PWM port. value 0 is type M
+  PWM clock. value 1 is type N PWM clock. value 2 is type O PWM clock.
+  D[12] in PTCR00 indicates type selection bit of PWM A port,
+  D[13] in PTCR00 indicates type selection bit of PWM B port,
+  D[14] in PTCR00 indicates type selection bit of PWM C port,
+  D[15] in PTCR00 indicates type selection bit of PWM D port,
+  D[12] in PTCR40 indicates type selection bit of PWM E port,
+  D[13] in PTCR40 indicates type selection bit of PWM F port,
+  D[14] in PTCR40 indicates type selection bit of PWM G port,
+  D[15] in PTCR40 indicates type selection bit of PWM H port.
+- pwm_duty_cycle_percent : duty cycle value.
+
+Examples:
+
+pwm: pwm-controller@1e786000 {
+	#address-cells = <1>;
+	#size-cells = <1>;
+	reg = <0x1E786000 0x78>;
+	pinctrl-names = "default";
+        pinctrl-0 = <&pinctrl_pwm0_default &pinctrl_pwm1_default
+	 		&pinctrl_pwm2_default &pinctrl_pwm3_default>;
+	compatible = "aspeed,ast2500-pwm";
+	clock_enable = /bits/ 8 <0x01>;
+	clock_source = /bits/ 8 <0x00>;
+	typem_pwm_clock = <1 5 0 95>;
+	typen_pwm_clock = <0 0 0 0>;
+	typeo_pwm_clock = <0 0 0 0>;
+	pwm_port0 {
+		pwm_port = /bits/ 8 <0x00>;
+		pwm_enable = /bits/ 8 <0x01>;
+		pwm_type = /bits/ 8 <0x00>;
+		pwm_duty_cycle_percent = /bits/ 8 <0x5A>;
+	};
+	pwm_port1 {
+		pwm_port = /bits/ 8 <0x01>;
+		pwm_enable = /bits/ 8 <0x01>;
+		pwm_type = /bits/ 8 <0x00>;
+		pwm_duty_cycle_percent = /bits/ 8 <0x5A>;
+	};
+};
+

--
2.8.0.rc3.226.g39d4020

maintainer
#2 lore raw

Re: [PATCH linux v2 1/3] devicetree: binding documentation update for ASPEED AST2500 PWM driver

Quoted 54 lines · Jaghathiswari Rankappagounder Natarajan

Add binding documentation update for ASPEED AST2500 PWM driver. The ASPEED AST2500 PWM driver supports 8 PWM output ports. The parent node indicates a PWM controller and has options to:
provide register set information, provide pinctrl information, enable PWM and Fan Tach clock, select clock source, provide settings for three different PWM sources (type M, N and O).

Each sub node indicates a PWM output port and has options to:
enable PWM port, select the PWM source for the PWM port, provide duty cycle values to be used at startup.

v2:
- Made binding documentation update as a separate patch.
- Included AST2500 in the description.
- Changed format to "aspeed,ast2500-pwm".
- Included explanation for types M ,N and O and calculation example to determine L, H, and period bits.

---
 .../bindings/hwmon/aspeed,ast2500-pwm.txt          | 116 +++++++++++++++++++++
 1 file changed, 116 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/hwmon/aspeed,ast2500-pwm.txt
Documentation/devicetree/bindings/hwmon/aspeed,ast2500-pwm.txt new file +24 -0
new file mode 100644
index 0000000..2c3f2b6
@@ -0,0 +1,116 @@
+ASPEED AST2500 PWM device driver
+
+The ASPEED AST2500 PWM controller can support 8 PWM outputs.
+
+Required properties:
+- #address-cells : should be 1.
+- #size-cells : should be 1.
+- reg : address and length of the register set for the device.
+- pinctrl-names : A pinctrl state named "default" must be defined.
+- pinctrl-0 : Phandle referencing pin configuration of the aspeed pwm ports.
+- compatible : should be "aspeed,ast2500-pwm".
+- clock_enable : option to enable PWM and fan tach clock. should be 1.
+  (D[0] in PTCR00).
+- clock_source : option for clock source selection. 0 indicates 24MHz clock
+  and 1 indicates MCLK (D[1] in PTCR00).
+- typem_pwm_clock : PWM types M, N and 0 are three types just to have three
+  independent PWM source. Each could be assigned to the 8 PWM channels
+  with it's own settings
+  This array contains 4 values.
+  The first value indicates if the values for type M PWM are valid.
+  If the first value is 1, then it indicates that the rest of the values
+  are valid. If it is 0, then invalid.
+  The second value indicates the type M PWM clock division L bit (D[3:0]
+  in PTCR04). (value 0 in D[3:0] indicates 1, value 1 in D[3:0] indicates 2,

Documentation/devicetree/bindings/hwmon/aspeed,ast2500-pwm.txt line 34

Quoted 10 lines
Documentation/devicetree/bindings/hwmon/aspeed,ast2500-pwm.txt new file +10 -0
+  value 2 in D[3:0] indicates 4, value 3 in D[3:0] indicates 6 and so on
+  with increments in multiples of two).
+  The third value indicates type M PWM clock divison H bit (D[7:4] in PTCR04).
+  (value 0 in D[7:4] indicates 1, value 1 in D[7:4] indicates 2,
+  value 2 in D[7:4] indicates 4, value 3 in D[7:4] indicates 8 and
+  so on with increments in powers of two).
+  The fourth value indicates type M PWM period bit (D[15:8] in PTCR04).
+  If type M is chosen and clock source is 24 MHz then:
+  The PWM base clock = 24Mhz / (type M clock division L bit *
+  type M clock division H bit).

We should request the APB struct clk and calculate the PWM base clock from that. See drivers that do of_clk_get. This means the binding would require a phandle to the clock node that we have in our device tree.

We don't need to describe the clock calculation in the bindings document.

Quoted 13 lines
Documentation/devicetree/bindings/hwmon/aspeed,ast2500-pwm.txt new file +13 -0
+  The PWM frequency = The PWM base clock / (type M PWM period bit + 1)
+  If we plan to output 25Khz PWM frequency then we can use:
+  typem_pwm_clock = <1 5 0 95>
+  The PWM frequency = 24Mhz / (10 * 1  * (95 + 1)) = 25Khz
+- typen_pwm_clock : This array contains 4 values.
+  The first value indicates if the values for type N PWM are valid.
+  If the first value is 1, then it indicates that the rest of the values
+  are valid. If it is 0, then invalid.
+  The second value indicates the type N PWM clock division L bit (D[19:16]
+  in PTCR04).
+  The third value indicates type N PWM clock division H bit
+  (D[23:20] in PTCR04).
+  The fourth value indicates type N PWM period bit (D[31:24] in PTCR04).

Documentation/devicetree/bindings/hwmon/aspeed,ast2500-pwm.txt line 57

Quoted 10 lines
Documentation/devicetree/bindings/hwmon/aspeed,ast2500-pwm.txt new file +10 -0
+  Calculations similar as for type M.
+- typeo_pwm_clock : This array contains 4 values.
+  The first value indicates indicates if the values for type O PWM are valid.
+  If the first value is 1, then it indicates that the rest of the values
+  are valid. If it is 0, then invalid.
+  The second value indicates if the type O PWM clock division L bit
+  (D[3:0] in PTCR44).
+  The third value indicates type O PWM clock divison H bit (D[7:4] in PTCR44).
+  The fourth value indicates type O PWM period bit (D[15:8] in PTCR44).
+  Calculations similar as for type M.

This large block is hard to read. Try adding some whitespace :)

Spend some time comparing your bindings to others in the tree for the style of both the documentation and the bindings themselves.

Quoted 8 lines
Documentation/devicetree/bindings/hwmon/aspeed,ast2500-pwm.txt new file +8 -0
+
+Each subnode represents a PWM output port.
+
+Subnode Format
+--------------
+Required properties:
+- pwm_port : Indicates the PWM port. Values 0 through 7 indicate PWM ports
+  A through H respectively.

Documentation/devicetree/bindings/hwmon/aspeed,ast2500-pwm.txt line 75

Quoted 10 lines
Documentation/devicetree/bindings/hwmon/aspeed,ast2500-pwm.txt new file +10 -0
+- pwm_enable : Option to enable the PWM port indicated above. 0 is enable
+  and 1 is disable.
+  D[8] in PTCR00 indicates enabling PWM port A,
+  D[9] in PTCR00 indicates enabling PWM port B,
+  D[10] in PTCR00 indicates enabling PWM port C,
+  D[11] in PTCR00 indicates enabling PWM port D,
+  D[8] in PTCR40 indicates enabling PWM port E,
+  D[9] in PTCR40 indicates enabling PWM port F,
+  D[10] in PTCR40 indicates enabling PWM port G,
+  D[11] in PTCR40 indicates enabling PWM port H.

This appears to be describing the register layout, not the bindings.

Quoted 44 lines
Documentation/devicetree/bindings/hwmon/aspeed,ast2500-pwm.txt new file +41 -1
+- pwm_type : Indicates the clock type for the PWM port. value 0 is type M
+  PWM clock. value 1 is type N PWM clock. value 2 is type O PWM clock.
+  D[12] in PTCR00 indicates type selection bit of PWM A port,
+  D[13] in PTCR00 indicates type selection bit of PWM B port,
+  D[14] in PTCR00 indicates type selection bit of PWM C port,
+  D[15] in PTCR00 indicates type selection bit of PWM D port,
+  D[12] in PTCR40 indicates type selection bit of PWM E port,
+  D[13] in PTCR40 indicates type selection bit of PWM F port,
+  D[14] in PTCR40 indicates type selection bit of PWM G port,
+  D[15] in PTCR40 indicates type selection bit of PWM H port.
+- pwm_duty_cycle_percent : duty cycle value.
+
+Examples:
+
+pwm: pwm-controller@1e786000 {
+       #address-cells = <1>;
+       #size-cells = <1>;
+       reg = <0x1E786000 0x78>;
+       pinctrl-names = "default";
+        pinctrl-0 = <&pinctrl_pwm0_default &pinctrl_pwm1_default
+                       &pinctrl_pwm2_default &pinctrl_pwm3_default>;
+       compatible = "aspeed,ast2500-pwm";
+       clock_enable = /bits/ 8 <0x01>;
+       clock_source = /bits/ 8 <0x00>;
+       typem_pwm_clock = <1 5 0 95>;
+       typen_pwm_clock = <0 0 0 0>;
+       typeo_pwm_clock = <0 0 0 0>;
+       pwm_port0 {
+               pwm_port = /bits/ 8 <0x00>;
+               pwm_enable = /bits/ 8 <0x01>;
+               pwm_type = /bits/ 8 <0x00>;
+               pwm_duty_cycle_percent = /bits/ 8 <0x5A>;
+       };
+       pwm_port1 {
+               pwm_port = /bits/ 8 <0x01>;
+               pwm_enable = /bits/ 8 <0x01>;
+               pwm_type = /bits/ 8 <0x00>;
+               pwm_duty_cycle_percent = /bits/ 8 <0x5A>;
+       };
+};
+
--

2.8.0.rc3.226.g39d4020

#3 lore raw

Re: [PATCH linux v2 1/3] devicetree: binding documentation update for ASPEED AST2500 PWM driver

Quoted 76 lines · Joel Stanley
Quoted 18 lines · Jaghathiswari Rankappagounder Natarajan

Add binding documentation update for ASPEED AST2500 PWM driver. The ASPEED AST2500 PWM driver supports 8 PWM output ports. The parent node indicates a PWM controller and has options to:
provide register set information, provide pinctrl information, enable PWM and Fan Tach clock, select clock source, provide settings for three different PWM sources (type M, N and O).

Each sub node indicates a PWM output port and has options to:
enable PWM port, select the PWM source for the PWM port, provide duty cycle values to be used at startup.

v2:
- Made binding documentation update as a separate patch.
- Included AST2500 in the description.
- Changed format to "aspeed,ast2500-pwm".
- Included explanation for types M ,N and O and calculation example to determine L, H, and period bits.

Quoted 4 lines
---
 .../bindings/hwmon/aspeed,ast2500-pwm.txt          | 116

+++++++++++++++++++++

Quoted 2 lines
 1 file changed, 116 insertions(+)
 create mode 100644 Documentation/devicetree/

bindings/hwmon/aspeed,ast2500-pwm.txt

Review

Quoted 2 lines
(quoted diff) +0 -0

b/Documentation/devicetree/bindings/hwmon/aspeed,ast2500-pwm.txt

Quoted 5 lines

new file mode 100644
index 0000000..2c3f2b6

Documentation/devicetree/bindings/hwmon/aspeed,ast2500-pwm.txt line 10

Quoted 10 lines
Documentation/devicetree/bindings/hwmon/aspeed,ast2500-pwm.txt new file +10 -0
@@ -0,0 +1,116 @@
+ASPEED AST2500 PWM device driver
+
+The ASPEED AST2500 PWM controller can support 8 PWM outputs.
+
+Required properties:
+- #address-cells : should be 1.
+- #size-cells : should be 1.
+- reg : address and length of the register set for the device.
+- pinctrl-names : A pinctrl state named "default" must be defined.
+- pinctrl-0 : Phandle referencing pin configuration of the aspeed pwm

ports.

Documentation/devicetree/bindings/hwmon/aspeed,ast2500-pwm.txt

Quoted 4 lines
Documentation/devicetree/bindings/hwmon/aspeed,ast2500-pwm.txt new file +4 -0
+- compatible : should be "aspeed,ast2500-pwm".
+- clock_enable : option to enable PWM and fan tach clock. should be 1.
+  (D[0] in PTCR00).
+- clock_source : option for clock source selection. 0 indicates 24MHz

clock

Documentation/devicetree/bindings/hwmon/aspeed,ast2500-pwm.txt line 16

Quoted 2 lines
Documentation/devicetree/bindings/hwmon/aspeed,ast2500-pwm.txt new file +2 -0
+  and 1 indicates MCLK (D[1] in PTCR00).
+- typem_pwm_clock : PWM types M, N and 0 are three types just to have

three

Documentation/devicetree/bindings/hwmon/aspeed,ast2500-pwm.txt

Quoted 8 lines
Documentation/devicetree/bindings/hwmon/aspeed,ast2500-pwm.txt new file +8 -0
+  independent PWM source. Each could be assigned to the 8 PWM channels
+  with it's own settings
+  This array contains 4 values.
+  The first value indicates if the values for type M PWM are valid.
+  If the first value is 1, then it indicates that the rest of the values
+  are valid. If it is 0, then invalid.
+  The second value indicates the type M PWM clock division L bit (D[3:0]
+  in PTCR04). (value 0 in D[3:0] indicates 1, value 1 in D[3:0]

indicates 2,

Documentation/devicetree/bindings/hwmon/aspeed,ast2500-pwm.txt

Quoted 3 lines
Documentation/devicetree/bindings/hwmon/aspeed,ast2500-pwm.txt new file +3 -0
+  value 2 in D[3:0] indicates 4, value 3 in D[3:0] indicates 6 and so on
+  with increments in multiples of two).
+  The third value indicates type M PWM clock divison H bit (D[7:4] in

PTCR04).

Documentation/devicetree/bindings/hwmon/aspeed,ast2500-pwm.txt line 34

Quoted 7 lines
Documentation/devicetree/bindings/hwmon/aspeed,ast2500-pwm.txt new file +7 -0
+  (value 0 in D[7:4] indicates 1, value 1 in D[7:4] indicates 2,
+  value 2 in D[7:4] indicates 4, value 3 in D[7:4] indicates 8 and
+  so on with increments in powers of two).
+  The fourth value indicates type M PWM period bit (D[15:8] in PTCR04).
+  If type M is chosen and clock source is 24 MHz then:
+  The PWM base clock = 24Mhz / (type M clock division L bit *
+  type M clock division H bit).
Quoted 8 lines

We should request the APB struct clk and calculate the PWM base clock from that. See drivers that do of_clk_get. This means the binding would require a phandle to the clock node that we have in our device tree.

We don't need to describe the clock calculation in the bindings document.

Should I indicate the clock-frequency (desired PWM base clock) in the

devicetree clock node , get that clock-frequency using clk_get_rate and calculate type M clock division L bit and type M clock division H bit to match that clock-frequency (having fixed clock source and type M clock period bit values from the devicetree) ?

Quoted 101 lines

+ The PWM frequency = The PWM base clock / (type M PWM period bit + 1)

Documentation/devicetree/bindings/hwmon/aspeed,ast2500-pwm.txt

Quoted 8 lines
Documentation/devicetree/bindings/hwmon/aspeed,ast2500-pwm.txt new file +8 -0
+  If we plan to output 25Khz PWM frequency then we can use:
+  typem_pwm_clock = <1 5 0 95>
+  The PWM frequency = 24Mhz / (10 * 1  * (95 + 1)) = 25Khz
+- typen_pwm_clock : This array contains 4 values.
+  The first value indicates if the values for type N PWM are valid.
+  If the first value is 1, then it indicates that the rest of the values
+  are valid. If it is 0, then invalid.
+  The second value indicates the type N PWM clock division L bit

(D[19:16]

Documentation/devicetree/bindings/hwmon/aspeed,ast2500-pwm.txt

Quoted 7 lines
Documentation/devicetree/bindings/hwmon/aspeed,ast2500-pwm.txt new file +7 -0
+  in PTCR04).
+  The third value indicates type N PWM clock division H bit
+  (D[23:20] in PTCR04).
+  The fourth value indicates type N PWM period bit (D[31:24] in PTCR04).
+  Calculations similar as for type M.
+- typeo_pwm_clock : This array contains 4 values.
+  The first value indicates indicates if the values for type O PWM are

valid.

Documentation/devicetree/bindings/hwmon/aspeed,ast2500-pwm.txt

Quoted 5 lines
Documentation/devicetree/bindings/hwmon/aspeed,ast2500-pwm.txt new file +5 -0
+  If the first value is 1, then it indicates that the rest of the values
+  are valid. If it is 0, then invalid.
+  The second value indicates if the type O PWM clock division L bit
+  (D[3:0] in PTCR44).
+  The third value indicates type O PWM clock divison H bit (D[7:4] in

PTCR44).

Documentation/devicetree/bindings/hwmon/aspeed,ast2500-pwm.txt line 57

Quoted 2 lines
Documentation/devicetree/bindings/hwmon/aspeed,ast2500-pwm.txt new file +2 -0
+  The fourth value indicates type O PWM period bit (D[15:8] in PTCR44).
+  Calculations similar as for type M.

This large block is hard to read. Try adding some whitespace :)

Spend some time comparing your bindings to others in the tree for the style of both the documentation and the bindings themselves.

Documentation/devicetree/bindings/hwmon/aspeed,ast2500-pwm.txt

Quoted 7 lines
Documentation/devicetree/bindings/hwmon/aspeed,ast2500-pwm.txt new file +7 -0
+
+Each subnode represents a PWM output port.
+
+Subnode Format
+--------------
+Required properties:
+- pwm_port : Indicates the PWM port. Values 0 through 7 indicate PWM

ports

Documentation/devicetree/bindings/hwmon/aspeed,ast2500-pwm.txt line 65

Quoted 2 lines
Documentation/devicetree/bindings/hwmon/aspeed,ast2500-pwm.txt new file +2 -0
+  A through H respectively.
+- pwm_enable : Option to enable the PWM port indicated above. 0 is

enable

Documentation/devicetree/bindings/hwmon/aspeed,ast2500-pwm.txt line 75

Quoted 9 lines
Documentation/devicetree/bindings/hwmon/aspeed,ast2500-pwm.txt new file +9 -0
+  and 1 is disable.
+  D[8] in PTCR00 indicates enabling PWM port A,
+  D[9] in PTCR00 indicates enabling PWM port B,
+  D[10] in PTCR00 indicates enabling PWM port C,
+  D[11] in PTCR00 indicates enabling PWM port D,
+  D[8] in PTCR40 indicates enabling PWM port E,
+  D[9] in PTCR40 indicates enabling PWM port F,
+  D[10] in PTCR40 indicates enabling PWM port G,
+  D[11] in PTCR40 indicates enabling PWM port H.

This appears to be describing the register layout, not the bindings.

Documentation/devicetree/bindings/hwmon/aspeed,ast2500-pwm.txt line 75

Quoted 1 line
Documentation/devicetree/bindings/hwmon/aspeed,ast2500-pwm.txt new file +1 -0
+- pwm_type : Indicates the clock type for the PWM port. value 0 is type

M

Quoted 43 lines
Documentation/devicetree/bindings/hwmon/aspeed,ast2500-pwm.txt new file +40 -1
+  PWM clock. value 1 is type N PWM clock. value 2 is type O PWM clock.
+  D[12] in PTCR00 indicates type selection bit of PWM A port,
+  D[13] in PTCR00 indicates type selection bit of PWM B port,
+  D[14] in PTCR00 indicates type selection bit of PWM C port,
+  D[15] in PTCR00 indicates type selection bit of PWM D port,
+  D[12] in PTCR40 indicates type selection bit of PWM E port,
+  D[13] in PTCR40 indicates type selection bit of PWM F port,
+  D[14] in PTCR40 indicates type selection bit of PWM G port,
+  D[15] in PTCR40 indicates type selection bit of PWM H port.
+- pwm_duty_cycle_percent : duty cycle value.
+
+Examples:
+
+pwm: pwm-controller@1e786000 {
+       #address-cells = <1>;
+       #size-cells = <1>;
+       reg = <0x1E786000 0x78>;
+       pinctrl-names = "default";
+        pinctrl-0 = <&pinctrl_pwm0_default &pinctrl_pwm1_default
+                       &pinctrl_pwm2_default &pinctrl_pwm3_default>;
+       compatible = "aspeed,ast2500-pwm";
+       clock_enable = /bits/ 8 <0x01>;
+       clock_source = /bits/ 8 <0x00>;
+       typem_pwm_clock = <1 5 0 95>;
+       typen_pwm_clock = <0 0 0 0>;
+       typeo_pwm_clock = <0 0 0 0>;
+       pwm_port0 {
+               pwm_port = /bits/ 8 <0x00>;
+               pwm_enable = /bits/ 8 <0x01>;
+               pwm_type = /bits/ 8 <0x00>;
+               pwm_duty_cycle_percent = /bits/ 8 <0x5A>;
+       };
+       pwm_port1 {
+               pwm_port = /bits/ 8 <0x01>;
+               pwm_enable = /bits/ 8 <0x01>;
+               pwm_type = /bits/ 8 <0x00>;
+               pwm_duty_cycle_percent = /bits/ 8 <0x5A>;
+       };
+};
+
--

2.8.0.rc3.226.g39d4020

#4 lore raw

PATCH v2 2/3 drivers: hwmon: ASPEED AST2500 PWM driver

In reply to Jaghathiswari Rankappagounder Natarajan

The ASPEED AST2500 PWM controller can support upto 8 PWM output ports. There are three different PWM sources(types M, N and O)
and each PWM output port can be assigned a particular PWM source. There is a sysfs file through which the user can control
the duty cycle of a particular PWM port. The duty cycle can range from 0 to 100 percent.

v2:
- Merged the drivers for PWM controller and PWM device as one PWM driver.

---
 drivers/hwmon/Kconfig              |   5 +
 drivers/hwmon/Makefile             |   2 +-
 drivers/hwmon/aspeed_ast2500_pwm.c | 662 +++++++++++++++++++++++++++++++++++++
 drivers/hwmon/aspeed_ast2500_pwm.h | 128 +++++++
 4 files changed, 796 insertions(+), 1 deletion(-)
 create mode 100644 drivers/hwmon/aspeed_ast2500_pwm.c
 create mode 100644 drivers/hwmon/aspeed_ast2500_pwm.h
drivers/hwmon/Kconfig +5 -0
index 3b34ba9..7edd94e 100644
@@ -1800,6 +1800,11 @@ config SENSORS_ULTRA45
 	  This driver provides support for the Ultra45 workstation environmental
 	  sensors.
 
+config ASPEED_AST2500_PWM
+	tristate "ASPEED AST2500 PWM driver"
+	help
+	  This driver provides support for ASPEED AST2500 PWM output ports.
+
 if ACPI
 
 comment "ACPI drivers"
drivers/hwmon/Makefile +1 -1
index c0f3201..23529c2 100644
@@ -163,7 +163,7 @@ obj-$(CONFIG_SENSORS_W83L785TS)	+= w83l785ts.o
 obj-$(CONFIG_SENSORS_W83L786NG)	+= w83l786ng.o
 obj-$(CONFIG_SENSORS_WM831X)	+= wm831x-hwmon.o
 obj-$(CONFIG_SENSORS_WM8350)	+= wm8350-hwmon.o
-
+obj-$(CONFIG_ASPEED_AST2500_PWM)	+= aspeed_ast2500_pwm.o
 obj-$(CONFIG_PMBUS)		+= pmbus/
 
 ccflags-$(CONFIG_HWMON_DEBUG_CHIP) := -DDEBUG
drivers/hwmon/aspeed_ast2500_pwm.c new file +662 -0

662 lines not on this page · raw message

drivers/hwmon/aspeed_ast2500_pwm.h new file +128 -0

128 lines not on this page · raw message

--
2.8.0.rc3.226.g39d4020

maintainer
#5 lore raw

Re: [PATCH linux v2 2/3] drivers: hwmon: ASPEED AST2500 PWM driver

Hello Jaghu,

Quoted 1 line · Jaghathiswari Rankappagounder Natarajan

The ASPEED AST2500 PWM controller can support upto 8 PWM output ports.

I noticed that the ast2500 and ast2400 share the same PWM IP, so we can use the same driver for both. You should reflect this in the naming of the Kconfig, filename, commit message and the code itself.

Quoted 5 lines

There are three different PWM sources(types M, N and O)
and each PWM output port can be assigned a particular PWM source. There is a sysfs file through which the user can control
the duty cycle of a particular PWM port. The duty cycle can range from 0 to 100 percent.

Can you explain why this is a hwmon driver and not a pwm driver?

Quoted 3 lines

v2:
- Merged the drivers for PWM controller and PWM device as one PWM driver.

Thanks for adding the changelog. This should go below the --, two lines lower. We do this to ensure the changelog is not part of the committed patch.

Quoted 46 lines
---
 drivers/hwmon/Kconfig              |   5 +
 drivers/hwmon/Makefile             |   2 +-
 drivers/hwmon/aspeed_ast2500_pwm.c | 662 +++++++++++++++++++++++++++++++++++++
 drivers/hwmon/aspeed_ast2500_pwm.h | 128 +++++++
 4 files changed, 796 insertions(+), 1 deletion(-)
 create mode 100644 drivers/hwmon/aspeed_ast2500_pwm.c
 create mode 100644 drivers/hwmon/aspeed_ast2500_pwm.h
drivers/hwmon/Kconfig +5 -0
index 3b34ba9..7edd94e 100644
@@ -1800,6 +1800,11 @@ config SENSORS_ULTRA45
          This driver provides support for the Ultra45 workstation environmental
          sensors.
 
+config ASPEED_AST2500_PWM
+       tristate "ASPEED AST2500 PWM driver"
+       help
+         This driver provides support for ASPEED AST2500 PWM output ports.
+
 if ACPI
 
 comment "ACPI drivers"
drivers/hwmon/Makefile +1 -1
index c0f3201..23529c2 100644
@@ -163,7 +163,7 @@ obj-$(CONFIG_SENSORS_W83L785TS)     += w83l785ts.o
 obj-$(CONFIG_SENSORS_W83L786NG)        += w83l786ng.o
 obj-$(CONFIG_SENSORS_WM831X)   += wm831x-hwmon.o
 obj-$(CONFIG_SENSORS_WM8350)   += wm8350-hwmon.o
-
+obj-$(CONFIG_ASPEED_AST2500_PWM)       += aspeed_ast2500_pwm.o
 obj-$(CONFIG_PMBUS)            += pmbus/
 
 ccflags-$(CONFIG_HWMON_DEBUG_CHIP) := -DDEBUG
drivers/hwmon/aspeed_ast2500_pwm.c new file +0 -0
new file mode 100644
index 0000000..fda49d7

drivers/hwmon/aspeed_ast2500_pwm.c line 2

Quoted 2 lines
drivers/hwmon/aspeed_ast2500_pwm.c new file +2 -0
@@ -0,0 +1,662 @@
+/*
+ * Aspeed AST2500 PWM device driver

most of the time we don't add the name at the top of hte file.

drivers/hwmon/aspeed_ast2500_pwm.c line 7

Quoted 5 lines
drivers/hwmon/aspeed_ast2500_pwm.c new file +5 -0
+ * * Copyright (c) 2016 Google, Inc
+ *
+ * * This program is free software; you can redistribute it and/or modify
+ * * it under the terms of the GNU General Public License version 2 as
+ * * published by the Free Software Foundation.

Lose the second row of stars.

The new drivers we contribute are v2 or later. This is your choice, but if there's no issue adding the or later it would be nice for all of the Aspeed code to be consistent.

Quoted 6 lines
drivers/hwmon/aspeed_ast2500_pwm.c new file +6 -0
+ *
+ */
+
+#include <linux/platform_device.h>
+#include <linux/kernel.h>
+#include <linux/module.h>

drivers/hwmon/aspeed_ast2500_pwm.c line 23

Quoted 10 lines
drivers/hwmon/aspeed_ast2500_pwm.c new file +10 -0
+#include <linux/of_platform.h>
+#include <linux/of_device.h>
+#include <linux/io.h>
+#include <linux/hwmon-sysfs.h>
+#include <linux/hwmon.h>
+#include <linux/sysfs.h>
+
+#include "aspeed_pwm.h"
+
+struct ast_pwm_port_data {

For better or worse, we've settled on "aspeed" as the prefix for all of the drivers. Please use that instead of ast.

Quoted 16 lines
drivers/hwmon/aspeed_ast2500_pwm.c new file +16 -0
+       u8 pwm_port;
+       u8 pwm_enable;
+       u8 pwm_type;
+       u8 pwm_duty_cycle;
+       void __iomem *base;
+};
+
+struct ast_pwm_controller_data {
+       void __iomem *base;
+};
+
+static inline void
+ast_pwm_write(void __iomem *base, u32 val, u32 reg)
+{
+       writel(val, base + reg);
+}

drivers/hwmon/aspeed_ast2500_pwm.c line 49

Quoted 10 lines
drivers/hwmon/aspeed_ast2500_pwm.c new file +10 -0
+
+static inline u32
+ast_pwm_read(void __iomem *base, u32 reg)
+{
+       u32 val = readl(base + reg);
+       return val;
+}
+
+static void
+ast_set_pwm_clock_enable(struct ast_pwm_controller_data *priv, u8 val)

val is a boolean.

Quoted 7 lines
drivers/hwmon/aspeed_ast2500_pwm.c new file +7 -0
+{
+       if (val) {
+               ast_pwm_write(priv->base,
+                       ast_pwm_read(priv->base, AST_PTCR_CTRL) |
+                       AST_PTCR_CTRL_CLK_EN, AST_PTCR_CTRL);
+       } else {
+               ast_pwm_write(priv->base,

drivers/hwmon/aspeed_ast2500_pwm.c line 75

Quoted 10 lines
drivers/hwmon/aspeed_ast2500_pwm.c new file +9 -0
+                       ast_pwm_read(priv->base, AST_PTCR_CTRL) &
+                       ~AST_PTCR_CTRL_CLK_EN, AST_PTCR_CTRL);
+       }
+}
 
+static void
+ast_set_pwm_enable(struct ast_pwm_port_data *priv, u8 enable)
+{
+       u8 pwm_ch = priv->pwm_port;
+

The switch statements where you read-modify-write are hard to read. I suggest reading the register value into a variable, modify it in your switch statement, and write it at the end. This makes it easier to read what operations you're performing on the bits.

u32 reg = ast_pwm_read(priv->base, AST_PTCR_CTRL);

switch (pwm_ch) {
case PWMA:

     port = AST_PTCR_CTRL_PWMA_EN;
     break;
case PWMB:
     port = AST_PTCR_CTRL_PWMB_EN;
     break;

...
}

if (enable)
reg |= port;
else
reg &= ~port;

ast_pwm_write(priv->base, reg, AST_PTCR_CTRL);

I think this structure will make this more readable. You could store the AST_PTCR_CTRL_PWMx_EN value as priv->pwm_port, and lose the switch statement all together.

This suggestion wont work for the other switch statements obviously. Can you think of a representation that would allow you to look up the values without requiring a switch statement? Take a look at some of the other pwm drivers for inspiration.

Quoted 7 lines
drivers/hwmon/aspeed_ast2500_pwm.c new file +7 -0
+       switch (pwm_ch) {
+       case PWMA:
+               if (enable)
+                       ast_pwm_write(priv->base,
+                               ast_pwm_read(priv->base,
+                               AST_PTCR_CTRL) |
+                               AST_PTCR_CTRL_PWMA_EN,

drivers/hwmon/aspeed_ast2500_pwm.c line 291

Quoted 10 lines
drivers/hwmon/aspeed_ast2500_pwm.c new file +9 -0
+                               AST_PTCR_CTRL);
 
+static void
+ast_set_pwm_type(struct ast_pwm_port_data *priv, u8 type)
+{
+       u32 tmp1, tmp2;
+       u8 pwm_ch = priv->pwm_port;
+
+       tmp1 = ast_pwm_read(priv->base, AST_PTCR_CTRL);
+       tmp2 = ast_pwm_read(priv->base, AST_PTCR_CTRL_EXT);

I think we can do better than tmp1 and tmp2. perhaps ctrl and ctrl_ext?

drivers/hwmon/aspeed_ast2500_pwm.c

Quoted 2 lines
drivers/hwmon/aspeed_ast2500_pwm.c new file +2 -0
+
+       switch (pwm_ch) {

As with pwm_type, pwm_ch could be an enum. That way you get warnings if you omit an option in your switch statement.

Quoted 10 lines
drivers/hwmon/aspeed_ast2500_pwm.c new file +9 -0
+       case PWMA:
+               tmp1 &= ~AST_PTCR_CTRL_SET_PWMA_TYPE_MASK;
+               tmp1 |= AST_PTCR_CTRL_SET_PWMA_TYPE(type);
+               ast_pwm_write(priv->base, tmp1, AST_PTCR_CTRL);
+
+               break;
 
+static int
+aspeed_create_pwm_port(struct device *dev, struct device_node *child,
+               void __iomem *base)

drivers/hwmon/aspeed_ast2500_pwm.c line 550

Quoted 10 lines
drivers/hwmon/aspeed_ast2500_pwm.c new file +10 -0
+{
+       struct device *hwmon;
+       u8 val;
+       struct ast_pwm_port_data *priv;
+
+       priv = devm_kzalloc(dev, sizeof(*priv), GFP_KERNEL);
+       if (!priv)
+               return -ENOMEM;
+
+       hwmon = devm_hwmon_device_register_with_groups(dev, "pwm_port",

"aspeed_pwm"?

Quoted 30 lines
drivers/hwmon/aspeed_ast2500_pwm.c new file +30 -0
+               priv, pwm_dev_groups);
+       if (IS_ERR(hwmon)) {
+               dev_err(dev, "Failed to register hwmon device\n");
+               return PTR_ERR(hwmon);
+       }
+       priv->base = base;
+
+       of_property_read_u8(child, "pwm_port", &val);
+       priv->pwm_port = val;
+
+       of_property_read_u8(child, "pwm_enable", &val);
+       priv->pwm_enable = val;
+       ast_set_pwm_enable(priv, val);
+
+       of_property_read_u8(child, "pwm_type", &val);
+       priv->pwm_type = val;
+       ast_set_pwm_type(priv, val);
+
+       of_property_read_u8(child, "pwm_duty_cycle_percent", &val);
+       priv->pwm_duty_cycle = val;
+       ast_set_pwm_duty_cycle(priv, val);
+       return 0;
+}
+
+static int
+aspeed_ast2500_pwm_probe(struct platform_device *pdev)
+{
+       u32 buf[4];
+       struct device_node *np, *child;
+       struct resource *res;

drivers/hwmon/aspeed_ast2500_pwm.c line 590

Quoted 10 lines
drivers/hwmon/aspeed_ast2500_pwm.c new file +10 -0
+       u8 val;
+       int err;
+       struct ast_pwm_controller_data *priv;
+
+       np = pdev->dev.of_node;
+
+       priv = devm_kzalloc(&pdev->dev, sizeof(struct ast_pwm_controller_data),
+                       GFP_KERNEL);
+       if (!priv)
+               return -ENOMEM;

Can you explain why you chose to allocate structure here? You don't seem to use it outside of the probe function which suggests it's unnecessary.

You can just get the base address, map it in (ioremap) to configure the state and then discard the mapping in the probe.

Quoted 4 lines
drivers/hwmon/aspeed_ast2500_pwm.c new file +4 -0
+
+       res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
+       if (res == NULL) {
+               return -ENOENT;

drivers/hwmon/aspeed_ast2500_pwm.c line 604

Quoted 10 lines
drivers/hwmon/aspeed_ast2500_pwm.c new file +10 -0
+       }
+
+       priv->base = devm_ioremap(&pdev->dev, res->start, resource_size(res));
+       if (!priv->base)
+               return -ENOMEM;
+
+       of_property_read_u8(np, "clock_enable", &val);
+       ast_set_pwm_clock_enable(priv, val);
+       of_property_read_u8(np, "clock_source", &val);
+       ast_set_pwm_clock_source(priv, val);

This needs reworking. I will comment on the bindings which will lead to changes in this code.

Quoted 29 lines
drivers/hwmon/aspeed_ast2500_pwm.c new file +29 -0
+
+       of_property_read_u32_array(np, "typem_pwm_clock", buf, 4);
+       if (buf[0] == 1) {
+               ast_set_pwm_clock_division_l(priv, PWM_TYPE_M, buf[1]);
+               ast_set_pwm_clock_division_h(priv, PWM_TYPE_M, buf[2]);
+               ast_set_pwm_clock_unit(priv, PWM_TYPE_M, buf[3]);
+       }
+
+       of_property_read_u32_array(np, "typen_pwm_clock", buf, 4);
+       if (buf[0] == 1) {
+               ast_set_pwm_clock_division_l(priv, PWM_TYPE_N, buf[1]);
+               ast_set_pwm_clock_division_h(priv, PWM_TYPE_N, buf[2]);
+               ast_set_pwm_clock_unit(priv, PWM_TYPE_N, buf[3]);
+       }
+
+       of_property_read_u32_array(np, "typeo_pwm_clock", buf, 4);
+       if (buf[0] == 1) {
+               ast_set_pwm_clock_division_l(priv, PWM_TYPE_O, buf[1]);
+               ast_set_pwm_clock_division_h(priv, PWM_TYPE_O, buf[2]);
+               ast_set_pwm_clock_unit(priv, PWM_TYPE_O, buf[3]);
+       }
+
+       for_each_child_of_node(np, child) {
+               aspeed_create_pwm_port(&pdev->dev,
+                               child, priv->base);
+               of_node_put(child);
+       }
+       of_node_put(np);
+       return 0;

drivers/hwmon/aspeed_ast2500_pwm.c line 643

Quoted 10 lines
drivers/hwmon/aspeed_ast2500_pwm.c new file +10 -0
+}
+
+static int
+aspeed_ast2500_pwm_remove(struct platform_device *pdev)
+{
+       return 0;
+}
+
+static const struct of_device_id of_pwm_match_table[] = {
+       { .compatible = "aspeed,ast2500-pwm", },

As discussed above, this should contain the ast2400 string as well.

drivers/hwmon/aspeed_ast2500_pwm.c line 650

Quoted 7 lines
drivers/hwmon/aspeed_ast2500_pwm.c new file +7 -0
+       {},
+};
+MODULE_DEVICE_TABLE(of, of_pwm_match_table);
+
+static struct platform_driver aspeed_ast2500_pwm_driver = {
+       .probe          = aspeed_ast2500_pwm_probe,
+       .remove         = aspeed_ast2500_pwm_remove,

Your remove does nothing, you can omit it.

drivers/hwmon/aspeed_ast2500_pwm.h

Quoted 17 lines
drivers/hwmon/aspeed_ast2500_pwm.c new file +12 -0
+       .driver         = {
+               .name   = "aspeed_ast2500_pwm",
+               .owner  = THIS_MODULE,
+               .of_match_table = of_pwm_match_table,
+       },
+};
+
+module_platform_driver(aspeed_ast2500_pwm_driver);
+
+MODULE_AUTHOR("Jaghathiswari Rankappagounder Natarajan <[email protected]>");
+MODULE_DESCRIPTION("ASPEED AST2500 PWM device driver");
+MODULE_LICENSE("GPL");
drivers/hwmon/aspeed_ast2500_pwm.h new file +0 -0
new file mode 100644
index 0000000..1986fd2

Headers in the kernel are generally only used when we need to share details between parts of the kernel. Given there isn't a lot here, I think these definitions should be in the c file.

drivers/hwmon/aspeed_ast2500_pwm.h line 43

Quoted 6 lines
drivers/hwmon/aspeed_ast2500_pwm.h new file +6 -0
+#define DUTY_CTRL_PWM2_FALL_POINT                      (24)
+#define DUTY_CTRL_PWM2_FALL_POINT_MASK                 (0xff<<24)
+#define DUTY_CTRL_PWM2_RISE_POINT                      (16)
+#define DUTY_CTRL_PWM2_RISE_POINT_MASK                 (0xff<<16)
+#define DUTY_CTRL_PWM1_FALL_POINT                      (8)
+#define DUTY_CTRL_PWM1_FALL_POINT_MASK                 (0xff<<8)

Try using GENMASK. For this it would be GENMASK(15, 8).

Do you really need the mask definitions?

drivers/hwmon/aspeed_ast2500_pwm.h line 50

Quoted 7 lines
drivers/hwmon/aspeed_ast2500_pwm.h new file +7 -0
+#define DUTY_CTRL_PWM1_RISE_POINT                      (0)
+#define DUTY_CTRL_PWM1_RISE_POINT_MASK                 (0xff)
+
+/* AST_PTCR_CTRL : 0x00 - General Control Register */
+#define AST_PTCR_CTRL_SET_PWMD_TYPE(x)         ((x & 0x1) << 15 | \
+                                               (x & 0x2) << 6)
+#define AST_PTCR_CTRL_SET_PWMD_TYPE_MASK       ((0x1 << 7) | (0x1 << 15))

You can use BIT(7) | BIT(15).

drivers/hwmon/aspeed_ast2500_pwm.h line 71

Quoted 12 lines
drivers/hwmon/aspeed_ast2500_pwm.h new file +11 -0
+
+#define AST_PTCR_CTRL_SET_PWMC_TYPE(x)         ((x & 0x1) << 14 | \
+                                               (x & 0x2) << 5)
 
+#define        AST_PTCR_CTRL_PWMD                      (11)
+#define        AST_PTCR_CTRL_PWMD_EN           (0x1 << 11)
+#define        AST_PTCR_CTRL_PWMC                      (10)
+#define        AST_PTCR_CTRL_PWMC_EN           (0x1 << 10)
+#define        AST_PTCR_CTRL_PWMB                      (9)
+#define        AST_PTCR_CTRL_PWMB_EN           (0x1 << 9)
+#define        AST_PTCR_CTRL_PWMA                      (8)
+#define        AST_PTCR_CTRL_PWMA_EN           (0x1 << 8)

Consider only having the bit defintiions or the _EN. One can be derived from the other.

You don't need to guard the integers with ( ).

Quoted 4 lines
drivers/hwmon/aspeed_ast2500_pwm.h new file +4 -0
+
+/*0:24Mhz, 1:MCLK */
+#define        AST_PTCR_CTRL_CLK_SRC           0x2
+#define        AST_PTCR_CTRL_CLK_EN            0x1
#6 lore raw

Re: [PATCH linux v2 2/3] drivers: hwmon: ASPEED AST2500 PWM driver

Quoted 10 lines · Joel Stanley

Hello Jaghu,

Quoted 1 line · Jaghathiswari Rankappagounder Natarajan

The ASPEED AST2500 PWM controller can support upto 8 PWM output ports.

I noticed that the ast2500 and ast2400 share the same PWM IP, so we can use the same driver for both. You should reflect this in the naming of the Kconfig, filename, commit message and the code itself.

Quoted 8 lines
Quoted 4 lines

There are three different PWM sources(types M, N and O)
and each PWM output port can be assigned a particular PWM source. There is a sysfs file through which the user can control
the duty cycle of a particular PWM port. The duty cycle can range from 0

to

Quoted 1 line

100 percent.

Can you explain why this is a hwmon driver and not a pwm driver?

The fan tacho controller shares some common registers with PWM controller; the fan tacho controller needs to be a hwmon driver; so if PWM controller driver is a hwmon driver, then there is flexibility to add fan tacho controller functionality to the same PWM driver and make it as common driver for PWM and fan tacho controller.
The duty_cycle value available in pwm sysfs interface needs to be configured in nano seconds and the duty_cycle value available in hwmon sysfs interface can be configured with a integer value (ranging from 0 to 255; with 255 being 100 percent). So thought that hwmon sysfs interface is easier.

Quoted 418 lines
Quoted 4 lines

v2:
- Merged the drivers for PWM controller and PWM device as one PWM driver.

Thanks for adding the changelog. This should go below the --, two lines lower. We do this to ensure the changelog is not part of the committed patch.

Quoted 7 lines
---
 drivers/hwmon/Kconfig              |   5 +
 drivers/hwmon/Makefile             |   2 +-
 drivers/hwmon/aspeed_ast2500_pwm.c | 662 ++++++++++++++++++++++++++++++

+++++++

drivers/hwmon/Kconfig config SENSORS_ULTRA45 · line 1800

Quoted 11 lines
 drivers/hwmon/aspeed_ast2500_pwm.h | 128 +++++++
 4 files changed, 796 insertions(+), 1 deletion(-)
 create mode 100644 drivers/hwmon/aspeed_ast2500_pwm.c
 create mode 100644 drivers/hwmon/aspeed_ast2500_pwm.h
drivers/hwmon/Kconfig +0 -0
index 3b34ba9..7edd94e 100644
@@ -1800,6 +1800,11 @@ config SENSORS_ULTRA45
          This driver provides support for the Ultra45 workstation

environmental

drivers/hwmon/Kconfig config SENSORS_ULTRA45

Quoted 6 lines
drivers/hwmon/Kconfig +4 -0
          sensors.
 
+config ASPEED_AST2500_PWM
+       tristate "ASPEED AST2500 PWM driver"
+       help
+         This driver provides support for ASPEED AST2500 PWM output

ports.

drivers/hwmon/aspeed_

Quoted 18 lines
drivers/hwmon/Kconfig +1 -0
+
 if ACPI
 
 comment "ACPI drivers"
drivers/hwmon/Makefile +1 -1
index c0f3201..23529c2 100644
@@ -163,7 +163,7 @@ obj-$(CONFIG_SENSORS_W83L785TS)     += w83l785ts.o
 obj-$(CONFIG_SENSORS_W83L786NG)        += w83l786ng.o
 obj-$(CONFIG_SENSORS_WM831X)   += wm831x-hwmon.o
 obj-$(CONFIG_SENSORS_WM8350)   += wm8350-hwmon.o
-
+obj-$(CONFIG_ASPEED_AST2500_PWM)       += aspeed_ast2500_pwm.o
 obj-$(CONFIG_PMBUS)            += pmbus/
 
 ccflags-$(CONFIG_HWMON_DEBUG_CHIP) := -DDEBUG
drivers/hwmon/aspeed_ renamed from drivers/hwmon/aspeed_ast2500_pwm.c +0 -0

ast2500_pwm.c

drivers/hwmon/aspeed_ast2500_pwm.c line 2

Quoted 7 lines

new file mode 100644
index 0000000..fda49d7

drivers/hwmon/aspeed_ast2500_pwm.c new file +2 -0
@@ -0,0 +1,662 @@
+/*
+ * Aspeed AST2500 PWM device driver

most of the time we don't add the name at the top of hte file.

drivers/hwmon/aspeed_ast2500_pwm.c

Quoted 3 lines
drivers/hwmon/aspeed_ast2500_pwm.c new file +3 -0
+ * * Copyright (c) 2016 Google, Inc
+ *
+ * * This program is free software; you can redistribute it and/or

modify

drivers/hwmon/aspeed_ast2500_pwm.c line 7

Quoted 2 lines
drivers/hwmon/aspeed_ast2500_pwm.c new file +2 -0
+ * * it under the terms of the GNU General Public License version 2 as
+ * * published by the Free Software Foundation.

Lose the second row of stars.

The new drivers we contribute are v2 or later. This is your choice, but if there's no issue adding the or later it would be nice for all of the Aspeed code to be consistent.

Quoted 6 lines
drivers/hwmon/aspeed_ast2500_pwm.c new file +6 -0
+ *
+ */
+
+#include <linux/platform_device.h>
+#include <linux/kernel.h>
+#include <linux/module.h>

drivers/hwmon/aspeed_ast2500_pwm.c line 23

Quoted 10 lines
drivers/hwmon/aspeed_ast2500_pwm.c new file +10 -0
+#include <linux/of_platform.h>
+#include <linux/of_device.h>
+#include <linux/io.h>
+#include <linux/hwmon-sysfs.h>
+#include <linux/hwmon.h>
+#include <linux/sysfs.h>
+
+#include "aspeed_pwm.h"
+
+struct ast_pwm_port_data {

For better or worse, we've settled on "aspeed" as the prefix for all of the drivers. Please use that instead of ast.

Quoted 16 lines
drivers/hwmon/aspeed_ast2500_pwm.c new file +16 -0
+       u8 pwm_port;
+       u8 pwm_enable;
+       u8 pwm_type;
+       u8 pwm_duty_cycle;
+       void __iomem *base;
+};
+
+struct ast_pwm_controller_data {
+       void __iomem *base;
+};
+
+static inline void
+ast_pwm_write(void __iomem *base, u32 val, u32 reg)
+{
+       writel(val, base + reg);
+}

drivers/hwmon/aspeed_ast2500_pwm.c line 49

Quoted 10 lines
drivers/hwmon/aspeed_ast2500_pwm.c new file +10 -0
+
+static inline u32
+ast_pwm_read(void __iomem *base, u32 reg)
+{
+       u32 val = readl(base + reg);
+       return val;
+}
+
+static void
+ast_set_pwm_clock_enable(struct ast_pwm_controller_data *priv, u8 val)

val is a boolean.

Quoted 7 lines
drivers/hwmon/aspeed_ast2500_pwm.c new file +7 -0
+{
+       if (val) {
+               ast_pwm_write(priv->base,
+                       ast_pwm_read(priv->base, AST_PTCR_CTRL) |
+                       AST_PTCR_CTRL_CLK_EN, AST_PTCR_CTRL);
+       } else {
+               ast_pwm_write(priv->base,

drivers/hwmon/aspeed_ast2500_pwm.c line 75

Quoted 10 lines
drivers/hwmon/aspeed_ast2500_pwm.c new file +9 -0
+                       ast_pwm_read(priv->base, AST_PTCR_CTRL) &
+                       ~AST_PTCR_CTRL_CLK_EN, AST_PTCR_CTRL);
+       }
+}
 
+static void
+ast_set_pwm_enable(struct ast_pwm_port_data *priv, u8 enable)
+{
+       u8 pwm_ch = priv->pwm_port;
+

The switch statements where you read-modify-write are hard to read. I suggest reading the register value into a variable, modify it in your switch statement, and write it at the end. This makes it easier to read what operations you're performing on the bits.

u32 reg = ast_pwm_read(priv->base, AST_PTCR_CTRL);

switch (pwm_ch) {
case PWMA:

     port = AST_PTCR_CTRL_PWMA_EN;
     break;
case PWMB:
     port = AST_PTCR_CTRL_PWMB_EN;
     break;

...
}

if (enable)
reg |= port;
else
reg &= ~port;

ast_pwm_write(priv->base, reg, AST_PTCR_CTRL);

I think this structure will make this more readable. You could store the AST_PTCR_CTRL_PWMx_EN value as priv->pwm_port, and lose the switch statement all together.

This suggestion wont work for the other switch statements obviously. Can you think of a representation that would allow you to look up the values without requiring a switch statement? Take a look at some of the other pwm drivers for inspiration.

Quoted 7 lines
drivers/hwmon/aspeed_ast2500_pwm.c new file +7 -0
+       switch (pwm_ch) {
+       case PWMA:
+               if (enable)
+                       ast_pwm_write(priv->base,
+                               ast_pwm_read(priv->base,
+                               AST_PTCR_CTRL) |
+                               AST_PTCR_CTRL_PWMA_EN,

drivers/hwmon/aspeed_ast2500_pwm.c line 291

Quoted 10 lines
drivers/hwmon/aspeed_ast2500_pwm.c new file +9 -0
+                               AST_PTCR_CTRL);
 
+static void
+ast_set_pwm_type(struct ast_pwm_port_data *priv, u8 type)
+{
+       u32 tmp1, tmp2;
+       u8 pwm_ch = priv->pwm_port;
+
+       tmp1 = ast_pwm_read(priv->base, AST_PTCR_CTRL);
+       tmp2 = ast_pwm_read(priv->base, AST_PTCR_CTRL_EXT);

I think we can do better than tmp1 and tmp2. perhaps ctrl and ctrl_ext?

drivers/hwmon/aspeed_ast2500_pwm.c

Quoted 2 lines
drivers/hwmon/aspeed_ast2500_pwm.c new file +2 -0
+
+       switch (pwm_ch) {

As with pwm_type, pwm_ch could be an enum. That way you get warnings if you omit an option in your switch statement.

Quoted 10 lines
drivers/hwmon/aspeed_ast2500_pwm.c new file +9 -0
+       case PWMA:
+               tmp1 &= ~AST_PTCR_CTRL_SET_PWMA_TYPE_MASK;
+               tmp1 |= AST_PTCR_CTRL_SET_PWMA_TYPE(type);
+               ast_pwm_write(priv->base, tmp1, AST_PTCR_CTRL);
+
+               break;
 
+static int
+aspeed_create_pwm_port(struct device *dev, struct device_node *child,
+               void __iomem *base)

drivers/hwmon/aspeed_ast2500_pwm.c line 550

Quoted 10 lines
drivers/hwmon/aspeed_ast2500_pwm.c new file +10 -0
+{
+       struct device *hwmon;
+       u8 val;
+       struct ast_pwm_port_data *priv;
+
+       priv = devm_kzalloc(dev, sizeof(*priv), GFP_KERNEL);
+       if (!priv)
+               return -ENOMEM;
+
+       hwmon = devm_hwmon_device_register_with_groups(dev, "pwm_port",

"aspeed_pwm"?

Quoted 27 lines
drivers/hwmon/aspeed_ast2500_pwm.c new file +27 -0
+               priv, pwm_dev_groups);
+       if (IS_ERR(hwmon)) {
+               dev_err(dev, "Failed to register hwmon device\n");
+               return PTR_ERR(hwmon);
+       }
+       priv->base = base;
+
+       of_property_read_u8(child, "pwm_port", &val);
+       priv->pwm_port = val;
+
+       of_property_read_u8(child, "pwm_enable", &val);
+       priv->pwm_enable = val;
+       ast_set_pwm_enable(priv, val);
+
+       of_property_read_u8(child, "pwm_type", &val);
+       priv->pwm_type = val;
+       ast_set_pwm_type(priv, val);
+
+       of_property_read_u8(child, "pwm_duty_cycle_percent", &val);
+       priv->pwm_duty_cycle = val;
+       ast_set_pwm_duty_cycle(priv, val);
+       return 0;
+}
+
+static int
+aspeed_ast2500_pwm_probe(struct platform_device *pdev)
+{

drivers/hwmon/aspeed_ast2500_pwm.c

Quoted 10 lines
drivers/hwmon/aspeed_ast2500_pwm.c new file +10 -0
+       u32 buf[4];
+       struct device_node *np, *child;
+       struct resource *res;
+       u8 val;
+       int err;
+       struct ast_pwm_controller_data *priv;
+
+       np = pdev->dev.of_node;
+
+       priv = devm_kzalloc(&pdev->dev, sizeof(struct

ast_pwm_controller_data),

drivers/hwmon/aspeed_ast2500_pwm.c line 590

Quoted 3 lines
drivers/hwmon/aspeed_ast2500_pwm.c new file +3 -0
+                       GFP_KERNEL);
+       if (!priv)
+               return -ENOMEM;

Can you explain why you chose to allocate structure here? You don't seem to use it outside of the probe function which suggests it's unnecessary.

You can just get the base address, map it in (ioremap) to configure the state and then discard the mapping in the probe.

drivers/hwmon/aspeed_ast2500_pwm.c

Quoted 7 lines
drivers/hwmon/aspeed_ast2500_pwm.c new file +7 -0
+
+       res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
+       if (res == NULL) {
+               return -ENOENT;
+       }
+
+       priv->base = devm_ioremap(&pdev->dev, res->start,

resource_size(res));

drivers/hwmon/aspeed_ast2500_pwm.c line 604

Quoted 7 lines
drivers/hwmon/aspeed_ast2500_pwm.c new file +7 -0
+       if (!priv->base)
+               return -ENOMEM;
+
+       of_property_read_u8(np, "clock_enable", &val);
+       ast_set_pwm_clock_enable(priv, val);
+       of_property_read_u8(np, "clock_source", &val);
+       ast_set_pwm_clock_source(priv, val);

This needs reworking. I will comment on the bindings which will lead to changes in this code.

Quoted 29 lines
drivers/hwmon/aspeed_ast2500_pwm.c new file +29 -0
+
+       of_property_read_u32_array(np, "typem_pwm_clock", buf, 4);
+       if (buf[0] == 1) {
+               ast_set_pwm_clock_division_l(priv, PWM_TYPE_M, buf[1]);
+               ast_set_pwm_clock_division_h(priv, PWM_TYPE_M, buf[2]);
+               ast_set_pwm_clock_unit(priv, PWM_TYPE_M, buf[3]);
+       }
+
+       of_property_read_u32_array(np, "typen_pwm_clock", buf, 4);
+       if (buf[0] == 1) {
+               ast_set_pwm_clock_division_l(priv, PWM_TYPE_N, buf[1]);
+               ast_set_pwm_clock_division_h(priv, PWM_TYPE_N, buf[2]);
+               ast_set_pwm_clock_unit(priv, PWM_TYPE_N, buf[3]);
+       }
+
+       of_property_read_u32_array(np, "typeo_pwm_clock", buf, 4);
+       if (buf[0] == 1) {
+               ast_set_pwm_clock_division_l(priv, PWM_TYPE_O, buf[1]);
+               ast_set_pwm_clock_division_h(priv, PWM_TYPE_O, buf[2]);
+               ast_set_pwm_clock_unit(priv, PWM_TYPE_O, buf[3]);
+       }
+
+       for_each_child_of_node(np, child) {
+               aspeed_create_pwm_port(&pdev->dev,
+                               child, priv->base);
+               of_node_put(child);
+       }
+       of_node_put(np);
+       return 0;

drivers/hwmon/aspeed_ast2500_pwm.c line 643

Quoted 10 lines
drivers/hwmon/aspeed_ast2500_pwm.c new file +10 -0
+}
+
+static int
+aspeed_ast2500_pwm_remove(struct platform_device *pdev)
+{
+       return 0;
+}
+
+static const struct of_device_id of_pwm_match_table[] = {
+       { .compatible = "aspeed,ast2500-pwm", },

As discussed above, this should contain the ast2400 string as well.

drivers/hwmon/aspeed_ast2500_pwm.c line 650

Quoted 7 lines
drivers/hwmon/aspeed_ast2500_pwm.c new file +7 -0
+       {},
+};
+MODULE_DEVICE_TABLE(of, of_pwm_match_table);
+
+static struct platform_driver aspeed_ast2500_pwm_driver = {
+       .probe          = aspeed_ast2500_pwm_probe,
+       .remove         = aspeed_ast2500_pwm_remove,

Your remove does nothing, you can omit it.

drivers/hwmon/aspeed_ast2500_pwm.c

Quoted 10 lines
drivers/hwmon/aspeed_ast2500_pwm.c new file +10 -0
+       .driver         = {
+               .name   = "aspeed_ast2500_pwm",
+               .owner  = THIS_MODULE,
+               .of_match_table = of_pwm_match_table,
+       },
+};
+
+module_platform_driver(aspeed_ast2500_pwm_driver);
+
+MODULE_AUTHOR("Jaghathiswari Rankappagounder Natarajan <

[email protected]>");

drivers/hwmon/aspeed_

Quoted 3 lines
drivers/hwmon/aspeed_ast2500_pwm.c new file +2 -0
+MODULE_DESCRIPTION("ASPEED AST2500 PWM device driver");
+MODULE_LICENSE("GPL");
drivers/hwmon/aspeed_ renamed from drivers/hwmon/aspeed_ast2500_pwm.h +0 -0

ast2500_pwm.h

drivers/hwmon/aspeed_ast2500_pwm.h

Quoted 4 lines

new file mode 100644
index 0000000..1986fd2

drivers/hwmon/aspeed_ast2500_pwm.h new file +0 -0

Headers in the kernel are generally only used when we need to share details between parts of the kernel. Given there isn't a lot here, I think these definitions should be in the c file.

drivers/hwmon/aspeed_ast2500_pwm.h line 43

Quoted 6 lines
drivers/hwmon/aspeed_ast2500_pwm.h new file +6 -0
+#define DUTY_CTRL_PWM2_FALL_POINT                      (24)
+#define DUTY_CTRL_PWM2_FALL_POINT_MASK                 (0xff<<24)
+#define DUTY_CTRL_PWM2_RISE_POINT                      (16)
+#define DUTY_CTRL_PWM2_RISE_POINT_MASK                 (0xff<<16)
+#define DUTY_CTRL_PWM1_FALL_POINT                      (8)
+#define DUTY_CTRL_PWM1_FALL_POINT_MASK                 (0xff<<8)

Try using GENMASK. For this it would be GENMASK(15, 8).

Do you really need the mask definitions?

drivers/hwmon/aspeed_ast2500_pwm.h

Quoted 7 lines
drivers/hwmon/aspeed_ast2500_pwm.h new file +7 -0
+#define DUTY_CTRL_PWM1_RISE_POINT                      (0)
+#define DUTY_CTRL_PWM1_RISE_POINT_MASK                 (0xff)
+
+/* AST_PTCR_CTRL : 0x00 - General Control Register */
+#define AST_PTCR_CTRL_SET_PWMD_TYPE(x)         ((x & 0x1) << 15 | \
+                                               (x & 0x2) << 6)
+#define AST_PTCR_CTRL_SET_PWMD_TYPE_MASK       ((0x1 << 7) | (0x1 <<

15))

You can use BIT(7) | BIT(15).

drivers/hwmon/aspeed_ast2500_pwm.h line 71

Quoted 12 lines
drivers/hwmon/aspeed_ast2500_pwm.h new file +11 -0
+
+#define AST_PTCR_CTRL_SET_PWMC_TYPE(x)         ((x & 0x1) << 14 | \
+                                               (x & 0x2) << 5)
 
+#define        AST_PTCR_CTRL_PWMD                      (11)
+#define        AST_PTCR_CTRL_PWMD_EN           (0x1 << 11)
+#define        AST_PTCR_CTRL_PWMC                      (10)
+#define        AST_PTCR_CTRL_PWMC_EN           (0x1 << 10)
+#define        AST_PTCR_CTRL_PWMB                      (9)
+#define        AST_PTCR_CTRL_PWMB_EN           (0x1 << 9)
+#define        AST_PTCR_CTRL_PWMA                      (8)
+#define        AST_PTCR_CTRL_PWMA_EN           (0x1 << 8)

Consider only having the bit defintiions or the _EN. One can be derived from the other.

You don't need to guard the integers with ( ).

Quoted 4 lines
drivers/hwmon/aspeed_ast2500_pwm.h new file +4 -0
+
+/*0:24Mhz, 1:MCLK */
+#define        AST_PTCR_CTRL_CLK_SRC           0x2
+#define        AST_PTCR_CTRL_CLK_EN            0x1
maintainer
#7 lore raw

Re: [PATCH linux v2 2/3] drivers: hwmon: ASPEED AST2500 PWM driver

Quoted 23 lines · Jaghathiswari Rankappagounder Natarajan
Quoted 11 lines · Joel Stanley

Hello Jaghu,

Quoted 1 line · Jaghathiswari Rankappagounder Natarajan

The ASPEED AST2500 PWM controller can support upto 8 PWM output ports.

I noticed that the ast2500 and ast2400 share the same PWM IP, so we can use the same driver for both. You should reflect this in the naming of the Kconfig, filename, commit message and the code itself.

Quoted 8 lines
Quoted 6 lines

There are three different PWM sources(types M, N and O)
and each PWM output port can be assigned a particular PWM source. There is a sysfs file through which the user can control
the duty cycle of a particular PWM port. The duty cycle can range from 0 to
100 percent.

Can you explain why this is a hwmon driver and not a pwm driver?

Quoted 10 lines

The fan tacho controller shares some common registers with PWM controller; the fan tacho controller needs to be a hwmon driver; so if PWM controller driver is a hwmon driver, then there is flexibility to add fan tacho controller functionality to the same PWM driver and make it as common driver for PWM and fan tacho controller.
The duty_cycle value available in pwm sysfs interface needs to be configured in nano seconds and the duty_cycle value available in hwmon sysfs interface can be configured with a integer value (ranging from 0 to 255; with 255 being 100 percent). So thought that hwmon sysfs interface is easier.

Okay. Make sure you include this information in your cover letter and the commit message for the driver.

#8 lore raw

PATCH v2 3/3 devicetree : Add support in Zaius platform for 4 PWM output ports

In reply to Jaghathiswari Rankappagounder Natarajan

Zaius has four fans. Add support for four PWM output ports in Zaius.

v2:
- make the pwmX entries children of the pwm_controller entry.

---
 arch/arm/boot/dts/aspeed-bmc-opp-zaius.dts | 43 ++++++++++++++++++++++++++++++
 1 file changed, 43 insertions(+)
arch/arm/boot/dts/aspeed-bmc-opp-zaius.dts +43 -0
index 4c4754b..5ba8fed 100644
@@ -58,6 +58,49 @@
 			};
 		};
 	};
+
+	pwm: pwm-controller@1e786000 {
+		#address-cells = <1>;
+		#size-cells = <1>;
+		reg = <0x1E786000 0x78>;
+		pinctrl-names = "default";
+		pinctrl-0 = <&pinctrl_pwm0_default &pinctrl_pwm1_default
+				&pinctrl_pwm2_default &pinctrl_pwm3_default>;
+		compatible = "aspeed,ast2500-pwm";
+		clock_enable = /bits/ 8 <0x01>;
+		clock_source = /bits/ 8 <0x00>;
+		typem_pwm_clock = <1 5 0 95>;
+		typen_pwm_clock = <0 0 0 0>;
+		typeo_pwm_clock = <0 0 0 0>;
+
+		pwm_port0 {
+			pwm_port = /bits/ 8 <0x00>;
+			pwm_enable = /bits/ 8 <0x01>;
+			pwm_type = /bits/ 8 <0x00>;
+			pwm_duty_cycle_percent = /bits/ 8 <0x64>;
+		};
+
+		pwm_port1 {
+			pwm_port = /bits/ 8 <0x01>;
+			pwm_enable = /bits/ 8 <0x01>;
+			pwm_type = /bits/ 8 <0x00>;
+			pwm_duty_cycle_percent = /bits/ 8 <0x64>;
+		};
+
+		pwm_port2 {
+			pwm_port = /bits/ 8 <0x02>;
+			pwm_enable = /bits/ 8 <0x01>;
+			pwm_type = /bits/ 8 <0x00>;
+			pwm_duty_cycle_percent = /bits/ 8 <0x64>;
+		};
+
+		pwm_port3 {
+			pwm_port = /bits/ 8 <0x03>;
+			pwm_enable = /bits/ 8 <0x01>;
+			pwm_type = /bits/ 8 <0x00>;
+			pwm_duty_cycle_percent = /bits/ 8 <0x64>;
+		};
+	};
 };
 
 &uart5 {

--
2.8.0.rc3.226.g39d4020