Add Freescale FTM PWM driver.
Subsystems (2)
v4 cover Add Freescale FTM PWM driver.
Hello,
This patch series is the Freescale FTM PWM implementation. And there are 8 channels most supported by the FTM PWM. This implementation is only compatible with device tree definition.
This patch series is based on linux-next and has been tested on Vybrid VF610 Tower board using device tree.
Changes in v4:
- Check for the result and return an error for devm_kzalloc().
- Move pinmux setting from the SoC file to the board specific file.
- Revise the written mistake of 'ret |= FTMSC_CLKEXT;' --> 'reg |= FTMSC_CLKEXT;'.
Changes in v3:
- Remove "availabe" field.
- Remove "fsl,pwm-avaliable-chs" property.
- ...
Changes in v2:
- Remove PWM CPWM/EPWM feature and sysfs.
- Remove some redundant code.
- Revise some code for more readable.
- Remove "fsl,pwm-clk-ps", "fsl,pwm-number", "fsl,pwm-channels",etc.
- Add "fsl,pwm-avaliable-chs", "fsl,pwm-counter-clk", etc.
- Support 8 channels default in dtsi file.
- Add counter clock source selection.
- Rename some function name, macro name, etc.
- Use PWM's and OF's existing function interfaces.
- Split clk_unprepare_enable to clk_unprepare and clk_enable,etc.
- ...
Added in v1:
- Add Freescale FTM PWM driver support.
- Add Freescale FTM PWM node for VF610.
- Enable Enables FTM PWM device for Vybrid VF610 TOWER.
- Add device tree bindings for Freescale.
PATCH v4 1/4 pwm: Add Freescale FTM PWM driver support
The FTM PWM device can be found on Vybrid VF610 Tower and Layerscape LS-1 SoCs.
--- drivers/pwm/Kconfig | 10 + drivers/pwm/Makefile | 1 + drivers/pwm/pwm-fsl-ftm.c | 507 ++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 518 insertions(+) create mode 100644 drivers/pwm/pwm-fsl-ftm.c
drivers/pwm/Kconfig +10 -0
@@ -62,6 +62,16 @@ config PWM_BFIN To compile this driver as a module, choose M here: the module will be called pwm-bfin. +config PWM_FSL_FTM + tristate "Freescale FTM PWM support" + depends on OF + help + Generic FTM PWM framework driver for Freescale VF610 and + Layerscape LS-1 SoCs. + + To compile this driver as a module, choose M here: the module + will be called pwm-fsl-ftm. + config PWM_IMX tristate "i.MX PWM support" depends on ARCH_MXC
drivers/pwm/Makefile +1 -0
@@ -3,6 +3,7 @@ obj-$(CONFIG_PWM_SYSFS) += sysfs.o obj-$(CONFIG_PWM_AB8500) += pwm-ab8500.o obj-$(CONFIG_PWM_ATMEL_TCB) += pwm-atmel-tcb.o obj-$(CONFIG_PWM_BFIN) += pwm-bfin.o +obj-$(CONFIG_PWM_FSL_FTM) += pwm-fsl-ftm.o obj-$(CONFIG_PWM_IMX) += pwm-imx.o obj-$(CONFIG_PWM_JZ4740) += pwm-jz4740.o obj-$(CONFIG_PWM_LPC32XX) += pwm-lpc32xx.o
drivers/pwm/pwm-fsl-ftm.c new file +507 -0
507 lines not on this page · raw message
Signature · 1 line
1.8.0
PATCH v4 2/4 ARM: dts: Add Freescale FTM PWM node for VF610.
In reply to Xiubo LiThis adds devicetree node for VF610, and there are 8 channels supported by default.
--- arch/arm/boot/dts/vf610.dtsi | 83 +++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 82 insertions(+), 1 deletion(-)
arch/arm/boot/dts/vf610.dtsi +82 -1
@@ -140,6 +140,17 @@ clock-names = "pit"; }; + pwm0: pwm at 40038000 { + compatible = "fsl,vf610-ftm-pwm"; + #pwm-cells = <3>; + reg = <0x40038000 0x1000>; + clock-names = "ftm0", "ftm0_fix_sel", "ftm0_ext_sel"; + clocks = <&clks VF610_CLK_FTM0>, + <&clks VF610_CLK_FTM0_FIX_SEL>, + <&clks VF610_CLK_FTM0_EXT_SEL>; + status = "disabled"; + }; + wdog at 4003e000 { compatible = "fsl,vf610-wdt", "fsl,imx21-wdt"; reg = <0x4003e000 0x1000>;
@@ -270,16 +281,86 @@ }; pwm0 { - pinctrl_pwm0_1: pwm0grp_1 { + pinctrl_pwm0_ch0_active: pwm0grp_ch0_active { fsl,pins = < VF610_PAD_PTB0__FTM0_CH0 0x1582 + >; + }; + pinctrl_pwm0_ch0_idle: pwm0grp_ch0_idle { + fsl,pins = < + VF610_PAD_PTB0__FTM0_CH0 0x0000 + >; + }; + pinctrl_pwm0_ch1_active: pwm0grp_ch1_active { + fsl,pins = < VF610_PAD_PTB1__FTM0_CH1 0x1582 + >; + }; + pinctrl_pwm0_ch1_idle: pwm0grp_ch1_idle { + fsl,pins = < + VF610_PAD_PTB1__FTM0_CH1 0x0000 + >; + }; + pinctrl_pwm0_ch2_active: pwm0grp_ch2_active { + fsl,pins = < VF610_PAD_PTB2__FTM0_CH2 0x1582 + >; + }; + pinctrl_pwm0_ch2_idle: pwm0grp_ch2_idle { + fsl,pins = < + VF610_PAD_PTB2__FTM0_CH2 0x0000 + >; + }; + pinctrl_pwm0_ch3_active: pwm0grp_ch3_active { + fsl,pins = < VF610_PAD_PTB3__FTM0_CH3 0x1582 + >; + }; + pinctrl_pwm0_ch3_idle: pwm0grp_ch3_idle { + fsl,pins = < + VF610_PAD_PTB3__FTM0_CH3 0x0000 + >; + }; + pinctrl_pwm0_ch4_active: pwm0grp_ch4_active { + fsl,pins = < + VF610_PAD_PTB4__FTM0_CH4 0x1582 + >; + }; + pinctrl_pwm0_ch4_idle: pwm0grp_ch4_idle { + fsl,pins = < + VF610_PAD_PTB4__FTM0_CH4 0x0000 + >; + }; + pinctrl_pwm0_ch5_active: pwm0grp_ch5_active { + fsl,pins = < + VF610_PAD_PTB5__FTM0_CH5 0x1582 + >; + }; + pinctrl_pwm0_ch5_idle: pwm0grp_ch5_idle { + fsl,pins = < + VF610_PAD_PTB5__FTM0_CH5 0x0000 + >; + }; + pinctrl_pwm0_ch6_active: pwm0grp_ch6_active { + fsl,pins = < VF610_PAD_PTB6__FTM0_CH6 0x1582 + >; + }; + pinctrl_pwm0_ch6_idle: pwm0grp_ch6_idle { + fsl,pins = < + VF610_PAD_PTB6__FTM0_CH6 0x0000 + >; + }; + pinctrl_pwm0_ch7_active: pwm0grp_ch7_active { + fsl,pins = < VF610_PAD_PTB7__FTM0_CH7 0x1582 >; }; + pinctrl_pwm0_ch7_idle: pwm0grp_ch7_idle { + fsl,pins = < + VF610_PAD_PTB7__FTM0_CH7 0x0000 + >; + }; }; qspi0 {
Signature · 1 line
1.8.0
PATCH v4 3/4 ARM: dts: Enables FTM PWM device for Vybrid VF610 TOWER board.
In reply to Xiubo LiSelecting system clock as the counter source clock by default.
--- arch/arm/boot/dts/vf610-twr.dts | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+)
arch/arm/boot/dts/vf610-twr.dts +25 -0
@@ -57,6 +57,31 @@ status = "okay"; }; +&pwm0 { + fsl,pwm-counter-clk = "ftm0"; + pinctrl-names = "ch0-active", "ch0-idle", "ch1-active", "ch1-idle", + "ch2-active", "ch2-idle", "ch3-active", "ch3-idle", + "ch4-active", "ch4-idle", "ch5-active", "ch5-idle", + "ch6-active", "ch6-idle", "ch7-active", "ch7-idle"; + pinctrl-0 = <&pinctrl_pwm0_ch0_active>; + pinctrl-1 = <&pinctrl_pwm0_ch0_idle>; + pinctrl-2 = <&pinctrl_pwm0_ch1_active>; + pinctrl-3 = <&pinctrl_pwm0_ch1_idle>; + pinctrl-4 = <&pinctrl_pwm0_ch2_active>; + pinctrl-5 = <&pinctrl_pwm0_ch2_idle>; + pinctrl-6 = <&pinctrl_pwm0_ch3_active>; + pinctrl-7 = <&pinctrl_pwm0_ch3_idle>; + pinctrl-8 = <&pinctrl_pwm0_ch4_active>; + pinctrl-9 = <&pinctrl_pwm0_ch4_idle>; + pinctrl-10 = <&pinctrl_pwm0_ch5_active>; + pinctrl-11 = <&pinctrl_pwm0_ch5_idle>; + pinctrl-12 = <&pinctrl_pwm0_ch6_active>; + pinctrl-13 = <&pinctrl_pwm0_ch6_idle>; + pinctrl-14 = <&pinctrl_pwm0_ch7_active>; + pinctrl-15 = <&pinctrl_pwm0_ch7_idle>; + status = "okay"; +}; + &uart1 { pinctrl-names = "default"; pinctrl-0 = <&pinctrl_uart1_1>;
Signature · 1 line
1.8.0
PATCH v4 4/4 Documentation: Add device tree bindings for Freescale FTM PWM.
In reply to Xiubo LiThis adds the Document for Freescale FTM PWM driver under Documentation/devicetree/bindings/pwm/.
--- .../devicetree/bindings/pwm/pwm-fsl-ftm.txt | 36 ++++++++++++++++++++++ 1 file changed, 36 insertions(+) create mode 100644 Documentation/devicetree/bindings/pwm/pwm-fsl-ftm.txt
Documentation/devicetree/bindings/pwm/pwm-fsl-ftm.txt new file +36 -0
@@ -0,0 +1,36 @@ +Freescale FTM PWM controller + +Required properties: +- compatible: Should be "fsl,vf610-ftm-pwm" +- reg: Physical base address and length of the controller's registers +- #pwm-cells: Should be 3. See pwm.txt in this directory for a description of + the cells format. +- clock-names : Includes the following module clock source entries: + "ftm0" (system clock), + "ftm0_fix_sel" (fixed frequency clock), + "ftm0_ext_sel" (external clock) +- clocks : Must contain an entry list for entries in clock-names. +- fsl,pwm-counter-clk: The FTM PWM counter clock source, should be one of the + entries in clock-names. +- For each channel's pinctrl, the "chN-active" and "chN-idle" states should be + implemented at the same time. + +Example: + +pwm0: pwm at 40038000 { + compatible = "fsl,vf610-ftm-pwm"; + reg = <0x40038000 0x1000>; + #pwm-cells = <3>; + clock-names = "ftm0", "ftm0_fix_sel", "ftm0_ext_sel"; + clocks = <&clks VF610_CLK_FTM0>, + <&clks VF610_CLK_FTM0_FIX_SEL>, + <&clks VF610_CLK_FTM0_EXT_SEL>; + pinctrl-names = "ch0-active", "ch0-idle", "ch1-active", "ch1-idle", + ....; + pinctrl-0 = <&pinctrl_pwm0_ch0_active>; + pinctrl-1 = <&pinctrl_pwm0_ch0_idle>; + pinctrl-2 = <&pinctrl_pwm0_ch1_active>; + pinctrl-3 = <&pinctrl_pwm0_ch1_idle>; + ... + fsl,pwm-counter-clk = "ftm0_ext_sel"; +};
Signature · 1 line
1.8.0
Re: [PATCHv4 4/4] Documentation: Add device tree bindings for Freescale FTM PWM.
Documentation/devicetree/bindings/pwm/pwm-fsl-ftm.txt line 12
Quoted 12 lines · Xiubo Li
This adds the Document for Freescale FTM PWM driver under
Documentation/devicetree/bindings/pwm/.Documentation/devicetree/bindings/pwm/pwm-fsl-ftm.txt +6
-0+Required properties: +- clock-names : Includes the following module clock source entries: + "ftm0" (system clock), + "ftm0_fix_sel" (fixed frequency clock), + "ftm0_ext_sel" (external clock) +- clocks : Must contain an entry list for entries in clock-names.
s/an entry list/a clock specifier/
s/for entries/for each entry/
Quoted 2 lines
+- fsl,pwm-counter-clk: The FTM PWM counter clock source, should be one of the + entries in clock-names.
So the IP block has 3 input clocks, and also a mux to select which one to use? That sounds slightly unusual, but possible.
If there is really only 1 clock input to the IP block, and the mux is part of some other module, then this binding should have only 1 entry in clocks.
Quoted 2 lines
+- For each channel's pinctrl, the "chN-active" and "chN-idle" states should be + implemented at the same time.
I still don't believe that multiple pinctrl states active at once is something that the pinctrl bindings conceptually support. CC+=LinusW, do we want to allow this?
Assuming this is allowed, you'd want to write something more like the following:
pinctrl-names: Must include "chN-active" and "chN-idle" for each channel ID N in range 0..7.
pinctrl-NNN: One property must exist for each entry in pinctrl-names. See ../pinctrl/pinctrl-bindings.txt for details of the property values.
Quoted 19 lines
Documentation/devicetree/bindings/pwm/pwm-fsl-ftm.txt +19
-0+Example: + +pwm0: pwm at 40038000 { + compatible = "fsl,vf610-ftm-pwm"; + reg = <0x40038000 0x1000>; + #pwm-cells = <3>; + clock-names = "ftm0", "ftm0_fix_sel", "ftm0_ext_sel"; + clocks = <&clks VF610_CLK_FTM0>, + <&clks VF610_CLK_FTM0_FIX_SEL>, + <&clks VF610_CLK_FTM0_EXT_SEL>; + pinctrl-names = "ch0-active", "ch0-idle", "ch1-active", "ch1-idle", + ....; + pinctrl-0 = <&pinctrl_pwm0_ch0_active>; + pinctrl-1 = <&pinctrl_pwm0_ch0_idle>; + pinctrl-2 = <&pinctrl_pwm0_ch1_active>; + pinctrl-3 = <&pinctrl_pwm0_ch1_idle>; + ... + fsl,pwm-counter-clk = "ftm0_ext_sel"; +};
RE: [PATCHv4 4/4] Documentation: Add device tree bindings for Freescale FTM PWM.
Quoted 11 lines
Review
Quoted 3 lines
+- fsl,pwm-counter-clk: The FTM PWM counter clock source, should be
(quoted diff) +2
-0+one of the + entries in clock-names.So the IP block has 3 input clocks, and also a mux to select which one to use? That sounds slightly unusual, but possible.
If there is really only 1 clock input to the IP block, and the mux is part of some other module, then this binding should have only 1 entry in clocks.
Yes, there are 3 input clocks that can be selectable, and the mux is inside the FTM IP block.
Thanks.
--
Best Regard,
Xiubo
Re: [PATCHv4 4/4] Documentation: Add device tree bindings for Freescale FTM PWM.
In reply to Xiubo LiQuoted 21 lines · Xiubo Li
This adds the Document for Freescale FTM PWM driver under
Documentation/devicetree/bindings/pwm/.Signed-off-by Xiubo Li <[email protected]>--- .../devicetree/bindings/pwm/pwm-fsl-ftm.txt | 36 ++++++++++++++++++++++ 1 file changed, 36 insertions(+) create mode 100644 Documentation/devicetree/bindings/pwm/pwm-fsl-ftm.txtDocumentation/devicetree/bindings/pwm/pwm-fsl-ftm.txt new file +6
-0@@ -0,0 +1,36 @@ +Freescale FTM PWM controller + +Required properties: +- compatible: Should be "fsl,vf610-ftm-pwm" +- reg: Physical base address and length of the controller's registers +- #pwm-cells: Should be 3. See pwm.txt in this directory for a description of
Documentation/devicetree/bindings/pwm/pwm-fsl-ftm.txt line 16
Quoted 10 lines
Documentation/devicetree/bindings/pwm/pwm-fsl-ftm.txt new file +10
-0+ the cells format. +- clock-names : Includes the following module clock source entries: + "ftm0" (system clock), + "ftm0_fix_sel" (fixed frequency clock), + "ftm0_ext_sel" (external clock) +- clocks : Must contain an entry list for entries in clock-names. +- fsl,pwm-counter-clk: The FTM PWM counter clock source, should be one of the + entries in clock-names. +- For each channel's pinctrl, the "chN-active" and "chN-idle" states should be + implemented at the same time.
I thought about this active/idle pinctrl stuff again. It should be removed from the PWM driver. The above is used to control the PWM output state when the PWM is disabled, so that for example a backlight stays disabled after a call to pwm_disable.
IMO this is wrong. Instead, the pwm client drivers (pwm_backlight) shouldn't assume a particular output state of the PWM after a pwm disable. Instead they should simply set the PWM to a duty cycle of 0% (or 100% for inverted) to effectively disable it. If then a PWM driver can optimize this to actually disabling the PWM completely, then fine, but that's an optimization.
If the handoff of PWM pins from bootloader state to regular state causes problems like flashing backlights or LEDs due to the pinctrl framework configuring the iomux before the PWM driver takes over, then the pinctrl should be done from the client drivers (pwm_backlight, pwm_led), not from the pwm driver and not from the pinctrl framework before initializing the clients.
So NACK to this complex pinctrl setup in this pwm driver.
Sascha
Signature · 4 lines
Pengutronix e.K. | | Industrial Linux Solutions | http://www.pengutronix.de/ | Peiner Str. 6-8, 31137 Hildesheim, Germany | Phone: +49-5121-206917-0 | Amtsgericht Hildesheim, HRA 2686 | Fax: +49-5121-206917-5555 |