pwm: atmel-tcb: rework device tree binding
Alexandre Belloni
maintainerv2 cover pwm: atmel-tcb: rework device tree binding
Hello,
This was sent as part of a 58 patches series back in 2017. The bindings were agreed upon back then:
https://lore.kernel.org/linux-arm-kernel/20170607211752.avts3cofvac7ks3q@rob-hp-laptop/
There is still only one user of atmel,tcb-pwm in the tree and I still think it is worth doing that change now.
The various dependencies are now in v5.9-rc1 so it is ready to be applied.
I have another series removing atmel_tclib once this is applied.
Changes in v2:
- rework binding commit message
- use enum for the pwm node reg values
Alexandre Belloni (4):
dt-bindings: microchip: atmel,at91rm9200-tcb: add atmel,tcb-pwm
pwm: atmel-tcb: switch to new binding
pwm: atmel-tcb: add sama5d2 support
ARM: dts: at91: kizbox: switch to new pwm-atmel-tcb binding
.../devicetree/bindings/pwm/atmel-tcb-pwm.txt | 16 -- .../soc/microchip/atmel,at91rm9200-tcb.yaml | 34 ++- arch/arm/boot/dts/at91-kizbox.dts | 45 ++- drivers/pwm/Kconfig | 3 +- drivers/pwm/pwm-atmel-tcb.c | 264 ++++++++++-------- 5 files changed, 220 insertions(+), 142 deletions(-) delete mode 100644 Documentation/devicetree/bindings/pwm/atmel-tcb-pwm.txt
Signature · 1 line
2.26.2
Alexandre Belloni
maintainerPATCH v2 1/4 dt-bindings: microchip: atmel,at91rm9200-tcb: add atmel,tcb-pwm
Move the TCB pwm nodes under their parent. This removes the need for the tc-block property as there is now a child-parent relationship between the TC channel and the TC block.
Move the documentation to the main file.
---
Changes in v2:
- rework commit message
- use enum for the pwm node reg values as suggested by Rob.
.../devicetree/bindings/pwm/atmel-tcb-pwm.txt | 16 --------- .../soc/microchip/atmel,at91rm9200-tcb.yaml | 34 ++++++++++++++++++- 2 files changed, 33 insertions(+), 17 deletions(-) delete mode 100644 Documentation/devicetree/bindings/pwm/atmel-tcb-pwm.txt
Documentation/devicetree/bindings/pwm/atmel-tcb-pwm.txt deleted +0 -16
@@ -1,16 +0,0 @@ -Atmel TCB PWM controller - -Required properties: -- compatible: should be "atmel,tcb-pwm" -- #pwm-cells: should be 3. See pwm.yaml in this directory for a description of - the cells format. The only third cell flag supported by this binding is - PWM_POLARITY_INVERTED. -- tc-block: The Timer Counter block to use as a PWM chip. - -Example: - -pwm { - compatible = "atmel,tcb-pwm"; - #pwm-cells = <3>; - tc-block = <1>; -};
Documentation/devicetree/bindings/soc/microchip/atmel,at91rm9200-tcb.yaml +33 -1
@@ -59,6 +59,7 @@ patternProperties: items: - enum: - atmel,tcb-timer + - atmel,tcb-pwm - microchip,tcb-capture reg: description:
@@ -68,10 +69,35 @@ patternProperties: minItems: 1 maxItems: 3 + required: + - compatible + - reg + + "^pwm@[0-2]$": + description: The timer block channels that are used as PWMs. + $ref: ../../pwm/pwm.yaml# + type: object + properties: + compatible: + const: atmel,tcb-pwm + reg: + description: + TCB channel to use for this PWM. + enum: [ 0, 1, 2 ] + + "#pwm-cells": + description: + The only third cell flag supported by this binding is + PWM_POLARITY_INVERTED. + const: 3 required: - compatible - reg + - "#pwm-cells" + + additionalProperties: false + allOf: - if:
@@ -158,7 +184,13 @@ examples: compatible = "atmel,tcb-timer"; reg = <1>; }; - }; + + pwm@2 { + compatible = "atmel,tcb-pwm"; + reg = <2>; + #pwm-cells = <3>; + }; + }; /* TCB0 Capture with QDEC: */ timer@f800c000 { compatible = "atmel,at91rm9200-tcb", "simple-mfd", "syscon";
Signature · 1 line
2.26.2
Re: [PATCH v2 1/4] dt-bindings: microchip: atmel, at91rm9200-tcb: add atmel, tcb-pwm
Quoted 12 lines · Alexandre Belloni
Move the TCB pwm nodes under their parent. This removes the need for the tc-block property as there is now a child-parent relationship between the TC channel and the TC block.
Move the documentation to the main file.
Signed-off-by Alexandre Belloni <[email protected]>---
Changes in v2:
- rework commit message
- use enum for the pwm node reg values as suggested by Rob.
Quoted 5 lines
.../devicetree/bindings/pwm/atmel-tcb-pwm.txt | 16 --------- .../soc/microchip/atmel,at91rm9200-tcb.yaml | 34 ++++++++++++++++++- 2 files changed, 33 insertions(+), 17 deletions(-) delete mode 100644 Documentation/devicetree/bindings/pwm/atmel-tcb-pwm.txt
Alexandre Belloni
maintainerPATCH v2 2/4 pwm: atmel-tcb: switch to new binding
In reply to Alexandre BelloniThe PWM is now a subnode of the used TCB. This is cleaner and it mainly allows to stop wasting TCB channels when only 2 or 4 PWMs are used.
This also removes the atmel_tclib dependency
--- drivers/pwm/Kconfig | 3 +- drivers/pwm/pwm-atmel-tcb.c | 241 ++++++++++++++++++++---------------- 2 files changed, 137 insertions(+), 107 deletions(-)
drivers/pwm/Kconfig +2 -1
@@ -75,7 +75,8 @@ config PWM_ATMEL_HLCDC_PWM config PWM_ATMEL_TCB tristate "Atmel TC Block PWM support" - depends on ATMEL_TCLIB && OF + depends on OF + select REGMAP_MMIO help Generic PWM framework driver for Atmel Timer Counter Block.
drivers/pwm/pwm-atmel-tcb.c +135 -106
462 lines not on this page · raw message
Signature · 1 line
2.26.2
Alexandre Belloni
maintainerPATCH v2 3/4 pwm: atmel-tcb: add sama5d2 support
In reply to Alexandre BelloniAdd sama5d2 support. The sama5d2 has a new clock input, its gclk. Index 0 of the clock selector is the gclk instead of the peripheral clock divided by 2.
For now, the gclk is not used because the peripheral clock divided by 8 already gives a 9.6ns resolution which is enough for most use cases.
--- drivers/pwm/pwm-atmel-tcb.c | 23 ++++++++++++++++++++--- 1 file changed, 20 insertions(+), 3 deletions(-)
drivers/pwm/pwm-atmel-tcb.c +20 -3
@@ -55,6 +55,7 @@ struct atmel_tcb_pwm_chip {u8 width;struct regmap *regmap;struct clk *clk; +struct clk *gclk;struct clk *slow_clk;struct atmel_tcb_pwm_device *pwms[NPWM ];struct atmel_tcb_channel bkup;
@@ -292,7 +293,7 @@ static int atmel_tcb_pwm_config(struct pwm_chip *chip, struct pwm_device *pwm,struct atmel_tcb_pwm_chip *tcbpwmc =to_tcb_chip (chip);struct atmel_tcb_pwm_device *tcbpwm =pwm_get_chip_data (pwm);struct atmel_tcb_pwm_device *atcbpwm =NULL ; -int i; +int i =0 ;int slowclk =0 ;unsigned period;unsigned duty;
@@ -303,8 +304,11 @@ static int atmel_tcb_pwm_config(struct pwm_chip *chip, struct pwm_device *pwm,/* * Find best clk divisor: * the smallest divisor which can fulfill the period_ns requirements. +* If there is a gclk, the first divisor is actuallly the gclk selector */ -for (i =0 ; i <ARRAY_SIZE (atmel_tcb_divisors); ++i) { +if (tcbpwmc->gclk) + i =1 ; +for (; i <ARRAY_SIZE (atmel_tcb_divisors); ++i) {if (atmel_tcb_divisors[i] ==0 ) { slowclk = i;continue ;
@@ -383,9 +387,15 @@ static struct atmel_tcb_config tcb_sam9x5_config = { .counter_width = 32, }; +static struct atmel_tcb_config tcb_sama5d2_config = { + .counter_width =32 , + .has_gclk =1 , +}; +static const struct of_device_id atmel_tcb_of_match[] = { { .compatible ="atmel,at91rm9200-tcb" , .data = &tcb_rm9200_config, }, { .compatible ="atmel,at91sam9x5-tcb" , .data = &tcb_sam9x5_config, }, + { .compatible ="atmel,sama5d2-tcb" , .data = &tcb_sama5d2_config, }, {/* sentinel */ } };
@@ -396,7 +406,7 @@ static int atmel_tcb_pwm_probe(struct platform_device *pdev)const struct atmel_tcb_config *config;struct device_node *np = pdev->dev.of_node;struct regmap *regmap; -struct clk *clk; +struct clk *clk, *gclk =NULL ;struct clk *slow_clk;char clk_name[] ="t0_clk" ;int err;
@@ -428,6 +438,12 @@ static int atmel_tcb_pwm_probe(struct platform_device *pdev) match =of_match_node (atmel_tcb_of_match, np->parent); config = match->data; +if (config->has_gclk) { + gclk =of_clk_get_by_name (np->parent,"gclk" ); +if (IS_ERR (gclk)) +return PTR_ERR (gclk); + } + tcbpwm =devm_kzalloc (&pdev->dev,sizeof (*tcbpwm),GFP_KERNEL );if (tcbpwm ==NULL ) { err = -ENOMEM ;
@@ -443,6 +459,7 @@ static int atmel_tcb_pwm_probe(struct platform_device *pdev) tcbpwm->channel = channel; tcbpwm->regmap = regmap; tcbpwm->clk = clk; + tcbpwm->gclk = gclk; tcbpwm->slow_clk = slow_clk; tcbpwm->width = config->counter_width;
Signature · 1 line
2.26.2
Alexandre Belloni
maintainerPATCH v2 4/4 ARM: dts: at91: kizbox: switch to new pwm-atmel-tcb binding
In reply to Alexandre BelloniSwitch to the new pwm-atmel-tcb binding that avoid wasting TCB channels.
--- arch/arm/boot/dts/at91-kizbox.dts | 45 ++++++++++++++++++++----------- 1 file changed, 30 insertions(+), 15 deletions(-)
arch/arm/boot/dts/at91-kizbox.dts +30 -15
@@ -53,43 +53,32 @@ pwm_leds { network_green { label = "pwm:green:network"; - pwms = <&tcb_pwm 2 10000000 PWM_POLARITY_INVERTED>; + pwms = <&tcb1_pwm1 0 10000000 PWM_POLARITY_INVERTED>; max-brightness = <255>; linux,default-trigger = "default-on"; }; network_red { label = "pwm:red:network"; - pwms = <&tcb_pwm 4 10000000 PWM_POLARITY_INVERTED>; + pwms = <&tcb1_pwm2 0 10000000 PWM_POLARITY_INVERTED>; max-brightness = <255>; linux,default-trigger = "default-on"; }; user_green { label = "pwm:green:user"; - pwms = <&tcb_pwm 0 10000000 PWM_POLARITY_INVERTED>; + pwms = <&tcb1_pwm0 0 10000000 PWM_POLARITY_INVERTED>; max-brightness = <255>; linux,default-trigger = "default-on"; }; user_red { label = "pwm:red:user"; - pwms = <&tcb_pwm 1 10000000 PWM_POLARITY_INVERTED>; + pwms = <&tcb1_pwm0 1 10000000 PWM_POLARITY_INVERTED>; max-brightness = <255>; linux,default-trigger = "default-on"; }; }; - - tcb_pwm: pwm { - compatible = "atmel,tcb-pwm"; - #pwm-cells = <3>; - tc-block = <1>; - pinctrl-names = "default"; - pinctrl-0 = <&pinctrl_tcb1_tioa0 - &pinctrl_tcb1_tioa1 - &pinctrl_tcb1_tioa2 - &pinctrl_tcb1_tiob0>; - }; }; &tcb0 {
@@ -104,6 +93,32 @@ timer@2 { }; }; +&tcb1 { + tcb1_pwm0: pwm@0 { + compatible = "atmel,tcb-pwm"; + reg = <0>; + #pwm-cells = <3>; + pinctrl-names = "default"; + pinctrl-0 = <&pinctrl_tcb1_tioa0 &pinctrl_tcb1_tiob0>; + }; + + tcb1_pwm1: pwm@1 { + compatible = "atmel,tcb-pwm"; + reg = <1>; + #pwm-cells = <3>; + pinctrl-names = "default"; + pinctrl-0 = <&pinctrl_tcb1_tioa1>; + }; + + tcb1_pwm2: pwm@2 { + compatible = "atmel,tcb-pwm"; + reg = <2>; + #pwm-cells = <3>; + pinctrl-names = "default"; + pinctrl-0 = <&pinctrl_tcb1_tioa2>; + }; +}; + &ebi { status = "okay"; };
Signature · 1 line
2.26.2
Quoted 25 lines · Alexandre Belloni
Hello,
This was sent as part of a 58 patches series back in 2017. The bindings were agreed upon back then:
https://lore.kernel.org/linux-arm-kernel/20170607211752.avts3cofvac7ks3q@rob-hp-laptop/
There is still only one user of atmel,tcb-pwm in the tree and I still think it is worth doing that change now.
The various dependencies are now in v5.9-rc1 so it is ready to be applied.
I have another series removing
atmel_tclibonce this is applied.Changes in v2:
- rework binding commit message
- use enum for the pwm node reg valuesAlexandre Belloni (4):
dt-bindings: microchip: atmel,at91rm9200-tcb: add atmel,tcb-pwm
pwm: atmel-tcb: switch to new binding
pwm: atmel-tcb: add sama5d2 support
ARM: dts: at91: kizbox: switch to new pwm-atmel-tcb binding
Quoted 7 lines
.../devicetree/bindings/pwm/atmel-tcb-pwm.txt | 16 -- .../soc/microchip/atmel,at91rm9200-tcb.yaml | 34 ++- arch/arm/boot/dts/at91-kizbox.dts | 45 ++- drivers/pwm/Kconfig | 3 +- drivers/pwm/pwm-atmel-tcb.c | 264 ++++++++++-------- 5 files changed, 220 insertions(+), 142 deletions(-) delete mode 100644 Documentation/devicetree/bindings/pwm/atmel-tcb-pwm.txt
Patches 1-3 applied, thanks.
Thierry