Add support for H6 PWM
Subsystems (3)
v2 cover Add support for H6 PWM
Hi,
This is a rework of Jernej's previous work[1] taking account all the previous remarks.
Bindings is still strict but probe in the driver are now optionnals.
If someone could confirm that the PWM is not broken, as my board doesn't output it.
I didn't add the acked-tags as there are big changes.
Thanks,
Clément
Jernej's cover:
Allwinner H6 SoC has PWM core which is basically the same as that found in A20, it's just depends on additional bus clock and reset line.
This series adds support for it and extends PWM driver functionality in a way that it's now possible to bypass whole core and output PWM source clock directly as a PWM signal. This functionality is needed by AC200 chip, which is bundled in same physical package as H6 SoC, to serve as a clock source of 24 MHz. AC200 clock input pin is bonded internally to the second PWM channel.
I would be grateful if anyone can test this patch series for any kind of regression on other SoCs.
[1]: https://patchwork.kernel.org/cover/11061737/
Changes in v2:
- Remove allOf in Documentation
- Add H6 example in Documentation
- Change clock name from "pwm" to "mod"
- Change reset quirk to optional probe
- Change bus_clock quirk to optional probe
- Add limitation comment about mod_clk_output
- Add quirk for mod_clk_output
- Change bypass formula
Clément Péron (1):
[DO NOT MERGE] arm64: allwinner: h6: enable Beelink GS1 PWM
Jernej Skrabec (6):
dt-bindings: pwm: allwinner: Add H6 PWM description
pwm: sun4i: Add an optional probe for reset line
pwm: sun4i: Add an optional probe for bus clock
pwm: sun4i: Add support to output source clock directly
pwm: sun4i: Add support for H6 PWM
arm64: dts: allwinner: h6: Add PWM node
.../bindings/pwm/allwinner,sun4i-a10-pwm.yaml | 45 ++++++- .../dts/allwinner/sun50i-h6-beelink-gs1.dts | 4 + arch/arm64/boot/dts/allwinner/sun50i-h6.dtsi | 10 ++ drivers/pwm/pwm-sun4i.c | 116 +++++++++++++++++- 4 files changed, 171 insertions(+), 4 deletions(-)
Signature · 1 line
2.20.1
PATCH v2 1/7 dt-bindings: pwm: allwinner: Add H6 PWM description
From: Jernej Skrabec <[email protected]>
H6 PWM block is basically the same as A20 PWM, except that it also has bus clock and reset line which needs to be handled accordingly.
Expand Allwinner PWM binding with H6 PWM specifics.
--- .../bindings/pwm/allwinner,sun4i-a10-pwm.yaml | 45 ++++++++++++++++++- 1 file changed, 44 insertions(+), 1 deletion(-)
Documentation/devicetree/bindings/pwm/allwinner,sun4i-a10-pwm.yaml +44 -1
@@ -30,13 +30,46 @@ properties: - items: - const: allwinner,sun50i-h5-pwm - const: allwinner,sun5i-a13-pwm + - const: allwinner,sun50i-h6-pwm reg: maxItems: 1 - clocks: + # Even though it only applies to subschemas under the conditionals, + # not listing them here will trigger a warning because of the + # additionalsProperties set to false. + clocks: true + clock-names: true + resets: maxItems: 1 + if: + properties: + compatible: + contains: + const: allwinner,sun50i-h6-pwm + + then: + properties: + clocks: + items: + - description: Module Clock + - description: Bus Clock + + clock-names: + items: + - const: mod + - const: bus + + required: + - clock-names + - resets + + else: + properties: + clocks: + maxItems: 1 + required: - "#pwm-cells" - compatible
@@ -54,4 +87,14 @@ examples: #pwm-cells = <3>; }; + - | + pwm@300a000 { + compatible = "allwinner,sun50i-h6-pwm"; + reg = <0x0300a000 0x400>; + clocks = <&osc24M>, <&ccu CLK_BUS_PWM>; + clock-names = "mod", "bus"; + resets = <&ccu RST_BUS_PWM>; + #pwm-cells = <3>; + }; + ...
Signature · 1 line
2.20.1
Re: [PATCH v2 1/7] dt-bindings: pwm: allwinner: Add H6 PWM description
Quoted 52 lines · Clément Péron
From: Jernej Skrabec <[email protected]>
H6 PWM block is basically the same as A20 PWM, except that it also has bus clock and reset line which needs to be handled accordingly.
Expand Allwinner PWM binding with H6 PWM specifics.
Signed-off-by Jernej Skrabec <[email protected]>Signed-off-by Clément Péron <[email protected]>--- .../bindings/pwm/allwinner,sun4i-a10-pwm.yaml | 45 ++++++++++++++++++- 1 file changed, 44 insertions(+), 1 deletion(-)Documentation/devicetree/bindings/pwm/allwinner,sun4i-a10-pwm.yaml +24
-1@@ -30,13 +30,46 @@ properties: - items: - const: allwinner,sun50i-h5-pwm - const: allwinner,sun5i-a13-pwm + - const: allwinner,sun50i-h6-pwm reg: maxItems: 1 - clocks: + # Even though it only applies to subschemas under the conditionals, + # not listing them here will trigger a warning because of the + # additionalsProperties set to false. + clocks: true + clock-names: true + resets: maxItems: 1 + if: + properties: + compatible: + contains: + const: allwinner,sun50i-h6-pwm + + then: + properties: + clocks: + items: + - description: Module Clock + - description: Bus Clock + + clock-names: + items: + - const: mod + - const: bus
Documentation/devicetree/bindings/pwm/allwinner,sun4i-a10-pwm.yaml properties: · line 72
Quoted 10 lines
Documentation/devicetree/bindings/pwm/allwinner,sun4i-a10-pwm.yaml +10
-0+ + required: + - clock-names + - resets + + else: + properties: + clocks: + maxItems: 1 +
I guess this hunk says "If this is a allwinner,sun50i-h6-pwm, a mod and bus clock is required.", right?
I wonder if it is sensible to require a clock-names property in the else branch, too. This would make it obvious if the clock there corresponds to the "mod" or the "bus" clock on H6. (I guess it's "mod".)
Best regards
Uwe
Signature · 2 lines
Pengutronix e.K. | Uwe Kleine-König | Industrial Linux Solutions | http://www.pengutronix.de/ |
Re: [PATCH v2 1/7] dt-bindings: pwm: allwinner: Add H6 PWM description
Quoted 59 lines · Uwe Kleine-König
Quoted 57 lines · Clément Péron
From: Jernej Skrabec <[email protected]>
H6 PWM block is basically the same as A20 PWM, except that it also has bus clock and reset line which needs to be handled accordingly.
Expand Allwinner PWM binding with H6 PWM specifics.
Signed-off-by Jernej Skrabec <[email protected]>Signed-off-by Clément Péron <[email protected]>--- .../bindings/pwm/allwinner,sun4i-a10-pwm.yaml | 45 ++++++++++++++++++- 1 file changed, 44 insertions(+), 1 deletion(-)Documentation/devicetree/bindings/pwm/allwinner,sun4i-a10-pwm.yaml +29
-1@@ -30,13 +30,46 @@ properties: - items: - const: allwinner,sun50i-h5-pwm - const: allwinner,sun5i-a13-pwm + - const: allwinner,sun50i-h6-pwm reg: maxItems: 1 - clocks: + # Even though it only applies to subschemas under the conditionals, + # not listing them here will trigger a warning because of the + # additionalsProperties set to false. + clocks: true + clock-names: true + resets: maxItems: 1 + if: + properties: + compatible: + contains: + const: allwinner,sun50i-h6-pwm + + then: + properties: + clocks: + items: + - description: Module Clock + - description: Bus Clock + + clock-names: + items: + - const: mod + - const: bus + + required: + - clock-names + - resets +
Quoted 8 lines
Documentation/devicetree/bindings/pwm/allwinner,sun4i-a10-pwm.yaml properties: · line 72
Quoted 5 lines
Documentation/devicetree/bindings/pwm/allwinner,sun4i-a10-pwm.yaml +5
-0+ else: + properties: + clocks: + maxItems: 1 +I guess this hunk says "If this is a allwinner,sun50i-h6-pwm, a mod and bus clock is required.", right?
Correct.
Quoted 5 lines
I wonder if it is sensible to require a clock-names property in the else branch, too. This would make it obvious if the clock there corresponds to the "mod" or the "bus" clock on H6. (I guess it's "mod".)
This will also require to change example and all the current allwinner device-tree that have a PWM declared.
Regards,
Clément
Quoted 7 lines
Best regards
Uwe--
Pengutronix e.K. | Uwe Kleine-König |
Industrial Linux Solutions | http://www.pengutronix.de/ |
Re: [PATCH v2 1/7] dt-bindings: pwm: allwinner: Add H6 PWM description
In reply to Uwe Kleine-KönigHi Clement, Uwe,
Quoted 67 lines · Uwe Kleine-König
Quoted 52 lines · Clément Péron
From: Jernej Skrabec <[email protected]>
H6 PWM block is basically the same as A20 PWM, except that it also has bus clock and reset line which needs to be handled accordingly.
Expand Allwinner PWM binding with H6 PWM specifics.
Signed-off-by Jernej Skrabec <[email protected]>Signed-off-by Clément Péron <[email protected]>--- .../bindings/pwm/allwinner,sun4i-a10-pwm.yaml | 45 ++++++++++++++++++- 1 file changed, 44 insertions(+), 1 deletion(-)Documentation/devicetree/bindings/pwm/allwinner,sun4i-a10-pwm.yaml +24
-1@@ -30,13 +30,46 @@ properties: - items: - const: allwinner,sun50i-h5-pwm - const: allwinner,sun5i-a13-pwm + - const: allwinner,sun50i-h6-pwm reg: maxItems: 1 - clocks: + # Even though it only applies to subschemas under the conditionals, + # not listing them here will trigger a warning because of the + # additionalsProperties set to false. + clocks: true + clock-names: true + resets: maxItems: 1 + if: + properties: + compatible: + contains: + const: allwinner,sun50i-h6-pwm + + then: + properties: + clocks: + items: + - description: Module Clock + - description: Bus Clock + + clock-names: + items: + - const: mod + - const: busDocumentation/devicetree/bindings/pwm/allwinner,sun4i-a10-pwm.yaml properties: · line 72
Quoted 10 lines
Documentation/devicetree/bindings/pwm/allwinner,sun4i-a10-pwm.yaml +10
-0+ + required: + - clock-names + - resets + + else: + properties: + clocks: + maxItems: 1 +I guess this hunk says "If this is a allwinner,sun50i-h6-pwm, a mod and bus clock is required.", right?
Quoted 3 lines
I wonder if it is sensible to require a clock-names property in the else branch, too. This would make it obvious if the clock there corresponds to the "mod" or the "bus" clock on H6. (I guess it's "mod".)
This can be done a bit differently and could address your concerns
Something like
properties:
...
clocks:
minItems: 1
maxItems: 2
items:
- description: Bus Clock
- description: Module Clock
required:
- clocks
if:
...
then:
properties:
clocks:
maxItems: 2
clocks-names:
items:
- const: mod
- const: bus
required:
- clock-names
else:
properties:
clocks:
maxItems: 1
That way, the definition of the order and which clock is which is pretty obvious in both cases, and we don't get any weird warnings.
Maxime
Re: [PATCH v2 1/7] dt-bindings: pwm: allwinner: Add H6 PWM description
Hi Maxime,
Quoted 92 lines · Maxime Ripard
Hi Clement, Uwe,
Quoted 67 lines · Uwe Kleine-König
Quoted 52 lines · Clément Péron
From: Jernej Skrabec <[email protected]>
H6 PWM block is basically the same as A20 PWM, except that it also has bus clock and reset line which needs to be handled accordingly.
Expand Allwinner PWM binding with H6 PWM specifics.
Signed-off-by Jernej Skrabec <[email protected]>Signed-off-by Clément Péron <[email protected]>--- .../bindings/pwm/allwinner,sun4i-a10-pwm.yaml | 45 ++++++++++++++++++- 1 file changed, 44 insertions(+), 1 deletion(-)Documentation/devicetree/bindings/pwm/allwinner,sun4i-a10-pwm.yaml +24
-1@@ -30,13 +30,46 @@ properties: - items: - const: allwinner,sun50i-h5-pwm - const: allwinner,sun5i-a13-pwm + - const: allwinner,sun50i-h6-pwm reg: maxItems: 1 - clocks: + # Even though it only applies to subschemas under the conditionals, + # not listing them here will trigger a warning because of the + # additionalsProperties set to false. + clocks: true + clock-names: true + resets: maxItems: 1 + if: + properties: + compatible: + contains: + const: allwinner,sun50i-h6-pwm + + then: + properties: + clocks: + items: + - description: Module Clock + - description: Bus Clock + + clock-names: + items: + - const: mod + - const: busDocumentation/devicetree/bindings/pwm/allwinner,sun4i-a10-pwm.yaml properties: · line 72
Quoted 10 lines
Documentation/devicetree/bindings/pwm/allwinner,sun4i-a10-pwm.yaml +10
-0+ + required: + - clock-names + - resets + + else: + properties: + clocks: + maxItems: 1 +I guess this hunk says "If this is a allwinner,sun50i-h6-pwm, a mod and bus clock is required.", right?
Quoted 3 lines
I wonder if it is sensible to require a clock-names property in the else branch, too. This would make it obvious if the clock there corresponds to the "mod" or the "bus" clock on H6. (I guess it's "mod".)
This can be done a bit differently and could address your concerns
Something like
properties:
...clocks:
minItems: 1
maxItems: 2
items:
- description: Bus Clock
- description: Module Clockrequired:
- clocks
Quoted 7 lines
if:
...then:
properties:
clocks:
maxItems: 2
Here we should set minItems to 2 right ?
so Max = Min = 2
Regards,
Clément
Quoted 18 lines
clocks-names:
items:
- const: mod
- const: busrequired:
- clock-nameselse:
properties:
clocks:
maxItems: 1That way, the definition of the order and which clock is which is pretty obvious in both cases, and we don't get any weird warnings.
Maxime
Re: [PATCH v2 1/7] dt-bindings: pwm: allwinner: Add H6 PWM description
Quoted 96 lines · Clément Péron
Quoted 95 lines · Maxime Ripard
Hi Clement, Uwe,
Quoted 67 lines · Uwe Kleine-König
Quoted 52 lines · Clément Péron
From: Jernej Skrabec <[email protected]>
H6 PWM block is basically the same as A20 PWM, except that it also has bus clock and reset line which needs to be handled accordingly.
Expand Allwinner PWM binding with H6 PWM specifics.
Signed-off-by Jernej Skrabec <[email protected]>Signed-off-by Clément Péron <[email protected]>--- .../bindings/pwm/allwinner,sun4i-a10-pwm.yaml | 45 ++++++++++++++++++- 1 file changed, 44 insertions(+), 1 deletion(-)Documentation/devicetree/bindings/pwm/allwinner,sun4i-a10-pwm.yaml +24
-1@@ -30,13 +30,46 @@ properties: - items: - const: allwinner,sun50i-h5-pwm - const: allwinner,sun5i-a13-pwm + - const: allwinner,sun50i-h6-pwm reg: maxItems: 1 - clocks: + # Even though it only applies to subschemas under the conditionals, + # not listing them here will trigger a warning because of the + # additionalsProperties set to false. + clocks: true + clock-names: true + resets: maxItems: 1 + if: + properties: + compatible: + contains: + const: allwinner,sun50i-h6-pwm + + then: + properties: + clocks: + items: + - description: Module Clock + - description: Bus Clock + + clock-names: + items: + - const: mod + - const: busDocumentation/devicetree/bindings/pwm/allwinner,sun4i-a10-pwm.yaml properties: · line 72
Quoted 10 lines
Documentation/devicetree/bindings/pwm/allwinner,sun4i-a10-pwm.yaml +10
-0+ + required: + - clock-names + - resets + + else: + properties: + clocks: + maxItems: 1 +I guess this hunk says "If this is a allwinner,sun50i-h6-pwm, a mod and bus clock is required.", right?
Quoted 3 lines
I wonder if it is sensible to require a clock-names property in the else branch, too. This would make it obvious if the clock there corresponds to the "mod" or the "bus" clock on H6. (I guess it's "mod".)
This can be done a bit differently and could address your concerns
Something like
properties:
...clocks:
minItems: 1
maxItems: 2
items:
- description: Bus Clock
- description: Module Clockrequired:
- clocksif:
...
Quoted 7 lines
Quoted 4 lines
then:
properties:
clocks:
maxItems: 2Here we should set minItems to 2 right ?
so Max = Min = 2
It's done automatically by the tooling when the other is missing.
Maxime
Re: [PATCH v2 1/7] dt-bindings: pwm: allwinner: Add H6 PWM description
Hi,
Quoted 103 lines · Maxime Ripard
Quoted 101 lines · Clément Péron
Quoted 99 lines · Maxime Ripard
Hi Clement, Uwe,
Quoted 67 lines · Uwe Kleine-König
Quoted 52 lines · Clément Péron
From: Jernej Skrabec <[email protected]>
H6 PWM block is basically the same as A20 PWM, except that it also has bus clock and reset line which needs to be handled accordingly.
Expand Allwinner PWM binding with H6 PWM specifics.
Signed-off-by Jernej Skrabec <[email protected]>Signed-off-by Clément Péron <[email protected]>--- .../bindings/pwm/allwinner,sun4i-a10-pwm.yaml | 45 ++++++++++++++++++- 1 file changed, 44 insertions(+), 1 deletion(-)Documentation/devicetree/bindings/pwm/allwinner,sun4i-a10-pwm.yaml +24
-1@@ -30,13 +30,46 @@ properties: - items: - const: allwinner,sun50i-h5-pwm - const: allwinner,sun5i-a13-pwm + - const: allwinner,sun50i-h6-pwm reg: maxItems: 1 - clocks: + # Even though it only applies to subschemas under the conditionals, + # not listing them here will trigger a warning because of the + # additionalsProperties set to false. + clocks: true + clock-names: true + resets: maxItems: 1 + if: + properties: + compatible: + contains: + const: allwinner,sun50i-h6-pwm + + then: + properties: + clocks: + items: + - description: Module Clock + - description: Bus Clock + + clock-names: + items: + - const: mod + - const: busDocumentation/devicetree/bindings/pwm/allwinner,sun4i-a10-pwm.yaml properties: · line 72
Quoted 10 lines
Documentation/devicetree/bindings/pwm/allwinner,sun4i-a10-pwm.yaml +10
-0+ + required: + - clock-names + - resets + + else: + properties: + clocks: + maxItems: 1 +I guess this hunk says "If this is a allwinner,sun50i-h6-pwm, a mod and bus clock is required.", right?
Quoted 3 lines
I wonder if it is sensible to require a clock-names property in the else branch, too. This would make it obvious if the clock there corresponds to the "mod" or the "bus" clock on H6. (I guess it's "mod".)
This can be done a bit differently and could address your concerns
Something like
properties:
...clocks:
minItems: 1
maxItems: 2
items:
- description: Bus Clock
- description: Module Clockrequired:
- clocksif:
...then:
properties:
clocks:
maxItems: 2
Quoted 4 lines
Quoted 2 lines
Here we should set minItems to 2 right ?
so Max = Min = 2It's done automatically by the tooling when the other is missing.
Ok thanks,
I will update in v4.
Regards,
Clément
Quoted 2 lines
Maxime
PATCH v2 2/7 pwm: sun4i: Add an optional probe for reset line
In reply to Clément PéronFrom: Jernej Skrabec <[email protected]>
H6 PWM core needs deasserted reset line in order to work.
Add an optional probe for it.
--- drivers/pwm/pwm-sun4i.c | 32 ++++++++++++++++++++++++++++++-- 1 file changed, 30 insertions(+), 2 deletions(-)
drivers/pwm/pwm-sun4i.c +30 -2
@@ -16,6 +16,7 @@#include <linux/of_device.h> #include <linux/platform_device.h> #include <linux/pwm.h> +#include <linux/reset.h> #include <linux/slab.h> #include <linux/spinlock.h> #include <linux/time.h>
@@ -78,6 +79,7 @@ struct sun4i_pwm_data {struct sun4i_pwm_chip {struct pwm_chip chip;struct clk *clk; +struct reset_control *rst;void __iomem *base;spinlock_t ctrl_lock;const struct sun4i_pwm_data *data;
@@ -365,6 +367,20 @@ static int sun4i_pwm_probe(struct platform_device *pdev)if (IS_ERR (pwm->clk))return PTR_ERR (pwm->clk); + pwm->rst =devm_reset_control_get_optional (&pdev->dev,NULL ); +if (IS_ERR (pwm->rst)) { +if (PTR_ERR (pwm->rst) == -EPROBE_DEFER ) +return PTR_ERR (pwm->rst); +dev_info (&pdev->dev,"no reset control found\n" ); + } + +/* Deassert reset */ + ret =reset_control_deassert (pwm->rst); +if (ret) { +dev_err (&pdev->dev,"Cannot deassert reset control\n" ); +return ret; + } + pwm->chip.dev = &pdev->dev; pwm->chip.ops = &sun4i_pwm_ops; pwm->chip.base =-1 ;
@@ -377,19 +393,31 @@ static int sun4i_pwm_probe(struct platform_device *pdev) ret =pwmchip_add (&pwm->chip);if (ret <0 ) {dev_err (&pdev->dev,"failed to add PWM chip: %d\n" , ret); -return ret; + goto err_pwm_add; }platform_set_drvdata (pdev, pwm);return 0 ; + +err_pwm_add: +reset_control_assert (pwm->rst); + +return ret; }static int sun4i_pwm_remove (struct platform_device *pdev) {struct sun4i_pwm_chip *pwm =platform_get_drvdata (pdev); +int ret; + + ret =pwmchip_remove (&pwm->chip); +if (ret) +return ret; + +reset_control_assert (pwm->rst); -return pwmchip_remove (&pwm->chip); +return 0 ; }static struct platform_driver sun4i_pwm_driver = {
Signature · 1 line
2.20.1
Re: [PATCH v2 2/7] pwm: sun4i: Add an optional probe for reset line
Hello,
adding Philipp Zabel (= reset controller maintainer) to Cc: and so I'm not stripping the uncommented parts of the patch.
Quoted 33 lines · Clément Péron
From: Jernej Skrabec <[email protected]>
H6 PWM core needs deasserted reset line in order to work.
Add an optional probe for it.
Signed-off-by Jernej Skrabec <[email protected]>Signed-off-by Clément Péron <[email protected]>--- drivers/pwm/pwm-sun4i.c | 32 ++++++++++++++++++++++++++++++-- 1 file changed, 30 insertions(+), 2 deletions(-)drivers/pwm/pwm-sun4i.c +2
-0@@ -16,6 +16,7 @@#include <linux/of_device.h> #include <linux/platform_device.h> #include <linux/pwm.h> +#include <linux/reset.h> #include <linux/slab.h> #include <linux/spinlock.h> #include <linux/time.h> @@ -78,6 +79,7 @@ struct sun4i_pwm_data {struct sun4i_pwm_chip {struct pwm_chip chip;struct clk *clk; +struct reset_control *rst;void __iomem *base;spinlock_t ctrl_lock;const struct sun4i_pwm_data *data;
drivers/pwm/pwm-sun4i.c static int sun4i_pwm_probe(struct platform_device *pdev) · line 374
Quoted 8 lines
drivers/pwm/pwm-sun4i.c +5
-0@@ -365,6 +367,20 @@ static int sun4i_pwm_probe(struct platform_device *pdev)if (IS_ERR (pwm->clk))return PTR_ERR (pwm->clk); + pwm->rst =devm_reset_control_get_optional (&pdev->dev,NULL ); +if (IS_ERR (pwm->rst)) { +if (PTR_ERR (pwm->rst) == -EPROBE_DEFER ) +return PTR_ERR (pwm->rst); +dev_info (&pdev->dev,"no reset control found\n" );
I would degrade this to a dev_dbg. Otherwise this spams the log for all unaffected machines. devm_reset_control_get_optional() is defined in a section that has a comment "These inline function calls will be removed once all consumers have been moved over to the new explicit API.", so I guess you want devm_reset_control_get_optional_exclusive or even devm_reset_control_get_optional_shared here.
@Philipp: maybe a check in checkpatch that warns about introduction of such new instances would be good?!
Quoted 36 lines
drivers/pwm/pwm-sun4i.c +18
-1+ } + +/* Deassert reset */ + ret =reset_control_deassert (pwm->rst); +if (ret) { +dev_err (&pdev->dev,"Cannot deassert reset control\n" ); +return ret; + } + pwm->chip.dev = &pdev->dev; pwm->chip.ops = &sun4i_pwm_ops; pwm->chip.base =-1 ;@@ -377,19 +393,31 @@ static int sun4i_pwm_probe(struct platform_device *pdev) ret =pwmchip_add (&pwm->chip);if (ret <0 ) {dev_err (&pdev->dev,"failed to add PWM chip: %d\n" , ret); -return ret; + goto err_pwm_add; }platform_set_drvdata (pdev, pwm);return 0 ; + +err_pwm_add: +reset_control_assert (pwm->rst); + +return ret; }static int sun4i_pwm_remove (struct platform_device *pdev) {struct sun4i_pwm_chip *pwm =platform_get_drvdata (pdev); +int ret; + + ret =pwmchip_remove (&pwm->chip);
drivers/pwm/pwm-sun4i.c static int sun4i_pwm_probe(struct platform_device *pdev) · line 423
Quoted 10 lines
drivers/pwm/pwm-sun4i.c +5
-1+if (ret) +return ret; + +reset_control_assert (pwm->rst); -return pwmchip_remove (&pwm->chip); +return 0 ; }static struct platform_driver sun4i_pwm_driver = {
Best regards
Uwe
Signature · 2 lines
Pengutronix e.K. | Uwe Kleine-König | Industrial Linux Solutions | http://www.pengutronix.de/ |
Re: [PATCH v2 2/7] pwm: sun4i: Add an optional probe for reset line
Quoted 43 lines · Uwe Kleine-König
Hello,
adding Philipp Zabel (= reset controller maintainer) to Cc: and so I'm not stripping the uncommented parts of the patch.
Quoted 36 lines · Clément Péron
From: Jernej Skrabec <[email protected]>
H6 PWM core needs deasserted reset line in order to work.
Add an optional probe for it.
Signed-off-by Jernej Skrabec <[email protected]>Signed-off-by Clément Péron <[email protected]>--- drivers/pwm/pwm-sun4i.c | 32 ++++++++++++++++++++++++++++++-- 1 file changed, 30 insertions(+), 2 deletions(-)drivers/pwm/pwm-sun4i.c +2
-0@@ -16,6 +16,7 @@#include <linux/of_device.h> #include <linux/platform_device.h> #include <linux/pwm.h> +#include <linux/reset.h> #include <linux/slab.h> #include <linux/spinlock.h> #include <linux/time.h> @@ -78,6 +79,7 @@ struct sun4i_pwm_data {struct sun4i_pwm_chip {struct pwm_chip chip;struct clk *clk; +struct reset_control *rst;void __iomem *base;spinlock_t ctrl_lock;const struct sun4i_pwm_data *data;@@ -365,6 +367,20 @@ static int sun4i_pwm_probe(struct platform_device *pdev)if (IS_ERR (pwm->clk))return PTR_ERR (pwm->clk);
Quoted 12 lines
drivers/pwm/pwm-sun4i.c static int sun4i_pwm_probe(struct platform_device *pdev) · line 374
Quoted 5 lines
drivers/pwm/pwm-sun4i.c +5
-0+ pwm->rst =devm_reset_control_get_optional (&pdev->dev,NULL ); +if (IS_ERR (pwm->rst)) { +if (PTR_ERR (pwm->rst) == -EPROBE_DEFER ) +return PTR_ERR (pwm->rst); +dev_info (&pdev->dev,"no reset control found\n" );I would degrade this to a
dev_dbg. Otherwise this spams the log for all unaffected machines.devm_reset_control_get_optional()is defined in a section that has a comment "These inline function calls will be removed once all consumers have been moved over to the new explicit API.", so I guess you wantdevm_reset_control_get_optional_exclusiveor evendevm_reset_control_get_optional_sharedhere.
Thanks for pointing this, I will change it.
Quoted 57 lines
@Philipp: maybe a check in checkpatch that warns about introduction of such new instances would be good?!
Quoted 36 lines
drivers/pwm/pwm-sun4i.c +18
-1+ } + +/* Deassert reset */ + ret =reset_control_deassert (pwm->rst); +if (ret) { +dev_err (&pdev->dev,"Cannot deassert reset control\n" ); +return ret; + } + pwm->chip.dev = &pdev->dev; pwm->chip.ops = &sun4i_pwm_ops; pwm->chip.base =-1 ;@@ -377,19 +393,31 @@ static int sun4i_pwm_probe(struct platform_device *pdev) ret =pwmchip_add (&pwm->chip);if (ret <0 ) {dev_err (&pdev->dev,"failed to add PWM chip: %d\n" , ret); -return ret; + goto err_pwm_add; }platform_set_drvdata (pdev, pwm);return 0 ; + +err_pwm_add: +reset_control_assert (pwm->rst); + +return ret; }static int sun4i_pwm_remove (struct platform_device *pdev) {struct sun4i_pwm_chip *pwm =platform_get_drvdata (pdev); +int ret; + + ret =pwmchip_remove (&pwm->chip);drivers/pwm/pwm-sun4i.c static int sun4i_pwm_probe(struct platform_device *pdev) · line 423
Quoted 10 lines
drivers/pwm/pwm-sun4i.c +5
-1+if (ret) +return ret; + +reset_control_assert (pwm->rst); -return pwmchip_remove (&pwm->chip); +return 0 ; }static struct platform_driver sun4i_pwm_driver = {Best regards
Uwe--
Pengutronix e.K. | Uwe Kleine-König |
Industrial Linux Solutions | http://www.pengutronix.de/ |
Re: [PATCH v2 2/7] pwm: sun4i: Add an optional probe for reset line
In reply to Uwe Kleine-KönigQuoted 42 lines · Uwe Kleine-König
Hello,
adding Philipp Zabel (= reset controller maintainer) to Cc: and so I'm not stripping the uncommented parts of the patch.
Quoted 36 lines · Clément Péron
From: Jernej Skrabec <[email protected]>
H6 PWM core needs deasserted reset line in order to work.
Add an optional probe for it.
Signed-off-by Jernej Skrabec <[email protected]>Signed-off-by Clément Péron <[email protected]>--- drivers/pwm/pwm-sun4i.c | 32 ++++++++++++++++++++++++++++++-- 1 file changed, 30 insertions(+), 2 deletions(-)drivers/pwm/pwm-sun4i.c +2
-0@@ -16,6 +16,7 @@#include <linux/of_device.h> #include <linux/platform_device.h> #include <linux/pwm.h> +#include <linux/reset.h> #include <linux/slab.h> #include <linux/spinlock.h> #include <linux/time.h> @@ -78,6 +79,7 @@ struct sun4i_pwm_data {struct sun4i_pwm_chip {struct pwm_chip chip;struct clk *clk; +struct reset_control *rst;void __iomem *base;spinlock_t ctrl_lock;const struct sun4i_pwm_data *data;@@ -365,6 +367,20 @@ static int sun4i_pwm_probe(struct platform_device *pdev)if (IS_ERR (pwm->clk))return PTR_ERR (pwm->clk);
Quoted 8 lines
drivers/pwm/pwm-sun4i.c static int sun4i_pwm_probe(struct platform_device *pdev) · line 374
Quoted 5 lines
drivers/pwm/pwm-sun4i.c +5
-0+ pwm->rst =devm_reset_control_get_optional (&pdev->dev,NULL ); +if (IS_ERR (pwm->rst)) { +if (PTR_ERR (pwm->rst) == -EPROBE_DEFER ) +return PTR_ERR (pwm->rst); +dev_info (&pdev->dev,"no reset control found\n" );I would degrade this to a
dev_dbg. Otherwise this spams the log for all unaffected machines.
The _optional variants return NULL if the reset is not specified in the device tree, so this is not "no reset control found", but a real error that should be returned.
Quoted 5 lines
devm_reset_control_get_optional()is defined in a section that has a comment "These inline function calls will be removed once all consumers have been moved over to the new explicit API.", so I guess you wantdevm_reset_control_get_optional_exclusiveor evendevm_reset_control_get_optional_sharedhere.
Correct. If this driver deasserts in probe() and asserts the reset in remove(), this can use the refcounting _shared variant.
Quoted 2 lines
@Philipp: maybe a check in checkpatch that warns about introduction of such new instances would be good?!
Yes, that would be helpful.
regards
Philipp
Re: [PATCH v2 2/7] pwm: sun4i: Add an optional probe for reset line
Hi Philipp,
Quoted 53 lines · Philipp Zabel
Quoted 42 lines · Uwe Kleine-König
Hello,
adding Philipp Zabel (= reset controller maintainer) to Cc: and so I'm not stripping the uncommented parts of the patch.
Quoted 36 lines · Clément Péron
From: Jernej Skrabec <[email protected]>
H6 PWM core needs deasserted reset line in order to work.
Add an optional probe for it.
Signed-off-by Jernej Skrabec <[email protected]>Signed-off-by Clément Péron <[email protected]>--- drivers/pwm/pwm-sun4i.c | 32 ++++++++++++++++++++++++++++++-- 1 file changed, 30 insertions(+), 2 deletions(-)drivers/pwm/pwm-sun4i.c +2
-0@@ -16,6 +16,7 @@#include <linux/of_device.h> #include <linux/platform_device.h> #include <linux/pwm.h> +#include <linux/reset.h> #include <linux/slab.h> #include <linux/spinlock.h> #include <linux/time.h> @@ -78,6 +79,7 @@ struct sun4i_pwm_data {struct sun4i_pwm_chip {struct pwm_chip chip;struct clk *clk; +struct reset_control *rst;void __iomem *base;spinlock_t ctrl_lock;const struct sun4i_pwm_data *data;@@ -365,6 +367,20 @@ static int sun4i_pwm_probe(struct platform_device *pdev)if (IS_ERR (pwm->clk))return PTR_ERR (pwm->clk);Quoted 8 lines
drivers/pwm/pwm-sun4i.c static int sun4i_pwm_probe(struct platform_device *pdev) · line 374
Quoted 5 lines
drivers/pwm/pwm-sun4i.c +5
-0+ pwm->rst =devm_reset_control_get_optional (&pdev->dev,NULL ); +if (IS_ERR (pwm->rst)) { +if (PTR_ERR (pwm->rst) == -EPROBE_DEFER ) +return PTR_ERR (pwm->rst); +dev_info (&pdev->dev,"no reset control found\n" );I would degrade this to a
dev_dbg. Otherwise this spams the log for all unaffected machines.
Quoted 3 lines
The
_optionalvariants return NULL if the reset is not specified in the device tree, so this is not "no reset control found", but a real error that should be returned.
Correct,
Thanks for the catch,
Clément
Quoted 17 lines
Quoted 6 lines
devm_reset_control_get_optional()is defined in a section that has a comment "These inline function calls will be removed once all consumers have been moved over to the new explicit API.", so I guess you wantdevm_reset_control_get_optional_exclusiveor evendevm_reset_control_get_optional_sharedhere.Correct. If this driver deasserts in
probe()and asserts the reset inremove(), this can use the refcounting_sharedvariant.Quoted 2 lines
@Philipp: maybe a check in checkpatch that warns about introduction of such new instances would be good?!
Yes, that would be helpful.
regards
Philipp
PATCH v2 3/7 pwm: sun4i: Add an optional probe for bus clock
In reply to Clément PéronFrom: Jernej Skrabec <[email protected]>
H6 PWM core needs bus clock to be enabled in order to work.
Add an optional probe for it and a fallback for previous bindings without name on module clock.
--- drivers/pwm/pwm-sun4i.c | 36 ++++++++++++++++++++++++++++++++++++ 1 file changed, 36 insertions(+)
drivers/pwm/pwm-sun4i.c +36 -0
@@ -78,6 +78,7 @@ struct sun4i_pwm_data {struct sun4i_pwm_chip {struct pwm_chip chip; +struct clk *bus_clk;struct clk *clk;struct reset_control *rst;void __iomem *base;
@@ -367,6 +368,31 @@ static int sun4i_pwm_probe(struct platform_device *pdev)if (IS_ERR (pwm->clk))return PTR_ERR (pwm->clk); +/* Get all clocks and reset line */ + pwm->clk =devm_clk_get_optional (&pdev->dev,"mod" ); +if (IS_ERR (pwm->clk)) { +dev_err (&pdev->dev,"get clock failed %ld\n" , +PTR_ERR (pwm->clk)); +return PTR_ERR (pwm->clk); + } + +/* Fallback for old dtbs with a single clock and no name */ +if (!pwm->clk) { + pwm->clk =devm_clk_get (&pdev->dev,NULL ); +if (IS_ERR (pwm->clk)) { +dev_err (&pdev->dev,"get clock failed %ld\n" , +PTR_ERR (pwm->clk)); +return PTR_ERR (pwm->clk); + } + } + + pwm->bus_clk =devm_clk_get_optional (&pdev->dev,"bus" ); +if (IS_ERR (pwm->bus_clk)) { +dev_err (&pdev->dev,"get bus_clock failed %ld\n" , +PTR_ERR (pwm->bus_clk)); +return PTR_ERR (pwm->bus_clk); + } + pwm->rst =devm_reset_control_get_optional (&pdev->dev,NULL );if (IS_ERR (pwm->rst)) {if (PTR_ERR (pwm->rst) == -EPROBE_DEFER )
@@ -381,6 +407,13 @@ static int sun4i_pwm_probe(struct platform_device *pdev)return ret; } +/* Enable bus clock */ + ret =clk_prepare_enable (pwm->bus_clk); +if (ret) { +dev_err (&pdev->dev,"Cannot prepare_enable bus_clk\n" ); + goto err_bus; + } + pwm->chip.dev = &pdev->dev; pwm->chip.ops = &sun4i_pwm_ops; pwm->chip.base =-1 ;
@@ -401,6 +434,8 @@ static int sun4i_pwm_probe(struct platform_device *pdev)return 0 ; err_pwm_add: +clk_disable_unprepare (pwm->bus_clk); +err_bus:reset_control_assert (pwm->rst);return ret;
@@ -415,6 +450,7 @@ static int sun4i_pwm_remove(struct platform_device *pdev)if (ret)return ret; +clk_disable_unprepare (pwm->bus_clk);reset_control_assert (pwm->rst);return 0 ;
Signature · 1 line
2.20.1
Re: [PATCH v2 3/7] pwm: sun4i: Add an optional probe for bus clock
Hello,
drivers/pwm/pwm-sun4i.c static int sun4i_pwm_probe(struct platform_device *pdev)
Quoted 26 lines · Clément Péron
From: Jernej Skrabec <[email protected]>
H6 PWM core needs bus clock to be enabled in order to work.
Add an optional probe for it and a fallback for previous bindings without name on module clock.
Signed-off-by Jernej Skrabec <[email protected]>Signed-off-by Clément Péron <[email protected]>--- drivers/pwm/pwm-sun4i.c | 36 ++++++++++++++++++++++++++++++++++++ 1 file changed, 36 insertions(+)drivers/pwm/pwm-sun4i.c +1
-0@@ -78,6 +78,7 @@ struct sun4i_pwm_data {struct sun4i_pwm_chip {struct pwm_chip chip; +struct clk *bus_clk;struct clk *clk;struct reset_control *rst;void __iomem *base;@@ -367,6 +368,31 @@ static int sun4i_pwm_probe(struct platform_device *pdev)
Adding more context here:
| pwm->clk = devm_clk_get(&pdev->dev, NULL);
drivers/pwm/pwm-sun4i.c static int sun4i_pwm_probe(struct platform_device *pdev) · line 377
Quoted 10 lines
drivers/pwm/pwm-sun4i.c +7
-0if (IS_ERR (pwm->clk))return PTR_ERR (pwm->clk); +/* Get all clocks and reset line */ + pwm->clk =devm_clk_get_optional (&pdev->dev,"mod" ); +if (IS_ERR (pwm->clk)) { +dev_err (&pdev->dev,"get clock failed %ld\n" , +PTR_ERR (pwm->clk)); +return PTR_ERR (pwm->clk); + }
I guess you want to drop the first assignment to pwm->clk.
drivers/pwm/pwm-sun4i.c static int sun4i_pwm_probe(struct platform_device *pdev) · line 387
Quoted 9 lines
drivers/pwm/pwm-sun4i.c +9
-0+/* Fallback for old dtbs with a single clock and no name */ +if (!pwm->clk) { + pwm->clk =devm_clk_get (&pdev->dev,NULL ); +if (IS_ERR (pwm->clk)) { +dev_err (&pdev->dev,"get clock failed %ld\n" , +PTR_ERR (pwm->clk)); +return PTR_ERR (pwm->clk); + } + }
There is a slight change of behaviour if I'm not mistaken. If you have this:
clocks = <&clk1>;
clock-names = "mod";
pwm {
compatible = "allwinner,sun4i-a10-pwm"
clocks = <&clk2>;
}you now use clk1 instead of clk2 before.
Assuming this is only a theoretical problem, at least pointing this out in the commit log would be good I think.
Quoted 11 lines
drivers/pwm/pwm-sun4i.c +7
-0+ pwm->bus_clk =devm_clk_get_optional (&pdev->dev,"bus" ); +if (IS_ERR (pwm->bus_clk)) { +dev_err (&pdev->dev,"get bus_clock failed %ld\n" , +PTR_ERR (pwm->bus_clk)); +return PTR_ERR (pwm->bus_clk); + } + pwm->rst =devm_reset_control_get_optional (&pdev->dev,NULL );if (IS_ERR (pwm->rst)) {if (PTR_ERR (pwm->rst) == -EPROBE_DEFER )
drivers/pwm/pwm-sun4i.c static int sun4i_pwm_probe(struct platform_device *pdev) · line 413
Quoted 7 lines
drivers/pwm/pwm-sun4i.c +4
-0@@ -381,6 +407,13 @@ static int sun4i_pwm_probe(struct platform_device *pdev)return ret; } +/* Enable bus clock */ + ret =clk_prepare_enable (pwm->bus_clk); +if (ret) { +dev_err (&pdev->dev,"Cannot prepare_enable bus_clk\n" );
I'd do s/prepare_enable/prepare and enable/ here.
Quoted 7 lines
drivers/pwm/pwm-sun4i.c +3
-0+ goto err_bus; + } + pwm->chip.dev = &pdev->dev; pwm->chip.ops = &sun4i_pwm_ops; pwm->chip.base =-1 ;
drivers/pwm/pwm-sun4i.c static int sun4i_pwm_probe(struct platform_device *pdev) · line 441
Quoted 8 lines
drivers/pwm/pwm-sun4i.c +2
-0@@ -401,6 +434,8 @@ static int sun4i_pwm_probe(struct platform_device *pdev)return 0 ; err_pwm_add: +clk_disable_unprepare (pwm->bus_clk); +err_bus:reset_control_assert (pwm->rst);return ret;
What is that clock used for? Is it required to access the hardware registers? Or is it only required while the PWM is enabled? If so you could enable the clock more finegrainded.
Best regards
Uwe
Signature · 2 lines
Pengutronix e.K. | Uwe Kleine-König | Industrial Linux Solutions | http://www.pengutronix.de/ |
Re: [PATCH v2 3/7] pwm: sun4i: Add an optional probe for bus clock
Hi,
Quoted 45 lines · Uwe Kleine-König
Hello,
drivers/pwm/pwm-sun4i.c static int sun4i_pwm_probe(struct platform_device *pdev)
Quoted 26 lines · Clément Péron
From: Jernej Skrabec <[email protected]>
H6 PWM core needs bus clock to be enabled in order to work.
Add an optional probe for it and a fallback for previous bindings without name on module clock.
Signed-off-by Jernej Skrabec <[email protected]>Signed-off-by Clément Péron <[email protected]>--- drivers/pwm/pwm-sun4i.c | 36 ++++++++++++++++++++++++++++++++++++ 1 file changed, 36 insertions(+)drivers/pwm/pwm-sun4i.c +1
-0@@ -78,6 +78,7 @@ struct sun4i_pwm_data {struct sun4i_pwm_chip {struct pwm_chip chip; +struct clk *bus_clk;struct clk *clk;struct reset_control *rst;void __iomem *base;@@ -367,6 +368,31 @@ static int sun4i_pwm_probe(struct platform_device *pdev)Adding more context here:
|
pwm->clk=devm_clk_get(&pdev->dev, NULL);drivers/pwm/pwm-sun4i.c static int sun4i_pwm_probe(struct platform_device *pdev) · line 377
Quoted 10 lines
drivers/pwm/pwm-sun4i.c +7
-0if (IS_ERR (pwm->clk))return PTR_ERR (pwm->clk); +/* Get all clocks and reset line */ + pwm->clk =devm_clk_get_optional (&pdev->dev,"mod" ); +if (IS_ERR (pwm->clk)) { +dev_err (&pdev->dev,"get clock failed %ld\n" , +PTR_ERR (pwm->clk)); +return PTR_ERR (pwm->clk); + }
Quoted 1 line
I guess you want to drop the first assignment to
pwm->clk.
devm_clk_get_optional will return NULL if there is no entry, I don't get where I need to drop it assignment.
Quoted 22 lines
drivers/pwm/pwm-sun4i.c static int sun4i_pwm_probe(struct platform_device *pdev) · line 387
Quoted 10 lines
drivers/pwm/pwm-sun4i.c +9
-0+/* Fallback for old dtbs with a single clock and no name */ +if (!pwm->clk) { + pwm->clk =devm_clk_get (&pdev->dev,NULL ); +if (IS_ERR (pwm->clk)) { +dev_err (&pdev->dev,"get clock failed %ld\n" , +PTR_ERR (pwm->clk)); +return PTR_ERR (pwm->clk); + } + }There is a slight change of behaviour if I'm not mistaken. If you have this:
clocks = <&clk1>; clock-names = "mod"; pwm { compatible = "allwinner,sun4i-a10-pwm" clocks = <&clk2>; }
Quoted 4 lines
you now use clk1 instead of clk2 before.
Assuming this is only a theoretical problem, at least pointing this out in the commit log would be good I think.
Yes it's correct and as you said the driver don't check for a correct device tree,
that why it's now optional probe.
Let's assume that's the device-tree is correct, I will add a comment in the commit log.
Quoted 15 lines
Quoted 15 lines
drivers/pwm/pwm-sun4i.c +7
-0+ pwm->bus_clk =devm_clk_get_optional (&pdev->dev,"bus" ); +if (IS_ERR (pwm->bus_clk)) { +dev_err (&pdev->dev,"get bus_clock failed %ld\n" , +PTR_ERR (pwm->bus_clk)); +return PTR_ERR (pwm->bus_clk); + } + pwm->rst =devm_reset_control_get_optional (&pdev->dev,NULL );if (IS_ERR (pwm->rst)) {if (PTR_ERR (pwm->rst) == -EPROBE_DEFER )@@ -381,6 +407,13 @@ static int sun4i_pwm_probe(struct platform_device *pdev)return ret; }
Quoted 6 lines
drivers/pwm/pwm-sun4i.c static int sun4i_pwm_probe(struct platform_device *pdev) · line 413
Quoted 4 lines
drivers/pwm/pwm-sun4i.c +4
-0+/* Enable bus clock */ + ret =clk_prepare_enable (pwm->bus_clk); +if (ret) { +dev_err (&pdev->dev,"Cannot prepare_enable bus_clk\n" );I'd do s/prepare_enable/prepare and enable/ here.
Ok
Quoted 15 lines
Quoted 15 lines
drivers/pwm/pwm-sun4i.c +5
-0+ goto err_bus; + } + pwm->chip.dev = &pdev->dev; pwm->chip.ops = &sun4i_pwm_ops; pwm->chip.base =-1 ;@@ -401,6 +434,8 @@ static int sun4i_pwm_probe(struct platform_device *pdev)return 0 ; err_pwm_add: +clk_disable_unprepare (pwm->bus_clk); +err_bus:reset_control_assert (pwm->rst);
Quoted 5 lines
drivers/pwm/pwm-sun4i.c static int sun4i_pwm_probe(struct platform_device *pdev) · line 441
Quoted 1 line
drivers/pwm/pwm-sun4i.c +0
-0return ret;What is that clock used for? Is it required to access the hardware registers? Or is it only required while the PWM is enabled? If so you could enable the clock more finegrainded.
Regarding the datasheet it's required to access the hardware. page 261 : https://linux-sunxi.org/File:Allwinner_H6_V200_User_Manual_V1.1.pdf
Regards,
Clément
Quoted 7 lines
Best regards
Uwe--
Pengutronix e.K. | Uwe Kleine-König |
Industrial Linux Solutions | http://www.pengutronix.de/ |
Re: [PATCH v2 3/7] pwm: sun4i: Add an optional probe for bus clock
Hello Clément,
Quoted 44 lines · Clément Péron
Quoted 42 lines · Uwe Kleine-König
drivers/pwm/pwm-sun4i.c static int sun4i_pwm_probe(struct platform_device *pdev)
Quoted 26 lines · Clément Péron
From: Jernej Skrabec <[email protected]>
H6 PWM core needs bus clock to be enabled in order to work.
Add an optional probe for it and a fallback for previous bindings without name on module clock.
Signed-off-by Jernej Skrabec <[email protected]>Signed-off-by Clément Péron <[email protected]>--- drivers/pwm/pwm-sun4i.c | 36 ++++++++++++++++++++++++++++++++++++ 1 file changed, 36 insertions(+)drivers/pwm/pwm-sun4i.c +1
-0@@ -78,6 +78,7 @@ struct sun4i_pwm_data {struct sun4i_pwm_chip {struct pwm_chip chip; +struct clk *bus_clk;struct clk *clk;struct reset_control *rst;void __iomem *base;@@ -367,6 +368,31 @@ static int sun4i_pwm_probe(struct platform_device *pdev)Adding more context here:
|
pwm->clk=devm_clk_get(&pdev->dev, NULL);Quoted 10 lines
drivers/pwm/pwm-sun4i.c +7
-0if (IS_ERR (pwm->clk))return PTR_ERR (pwm->clk); +/* Get all clocks and reset line */ + pwm->clk =devm_clk_get_optional (&pdev->dev,"mod" ); +if (IS_ERR (pwm->clk)) { +dev_err (&pdev->dev,"get clock failed %ld\n" , +PTR_ERR (pwm->clk)); +return PTR_ERR (pwm->clk); + }
Quoted 4 lines
Quoted 1 line
I guess you want to drop the first assignment to
pwm->clk.
devm_clk_get_optionalwill return NULL if there is no entry, I don't get where I need to drop it assignment.
With your patch the code looks as follows:
pwm->clk = devm_clk_get(&pdev->dev, NULL); if (IS_ERR(pwm->clk)) return PTR_ERR(pwm->clk); /* Get all clocks and reset line */ pwm->clk = devm_clk_get_optional(&pdev->dev, "mod"); ...
The assignment to pwm->clk above the comment is the one I suggested to drop.
Quoted 23 lines
Quoted 23 lines
drivers/pwm/pwm-sun4i.c static int sun4i_pwm_probe(struct platform_device *pdev) · line 387
Quoted 9 lines
drivers/pwm/pwm-sun4i.c +9
-0+/* Fallback for old dtbs with a single clock and no name */ +if (!pwm->clk) { + pwm->clk =devm_clk_get (&pdev->dev,NULL ); +if (IS_ERR (pwm->clk)) { +dev_err (&pdev->dev,"get clock failed %ld\n" , +PTR_ERR (pwm->clk)); +return PTR_ERR (pwm->clk); + } + }There is a slight change of behaviour if I'm not mistaken. If you have this:
clocks = <&clk1>; clock-names = "mod"; pwm { compatible = "allwinner,sun4i-a10-pwm" clocks = <&clk2>; }you now use clk1 instead of clk2 before.
Quoted 7 lines
Quoted 2 lines
Assuming this is only a theoretical problem, at least pointing this out in the commit log would be good I think.
Yes it's correct and as you said the driver don't check for a correct device tree, that why it's now optional probe.
Let's assume that's the device-tree is correct, I will add a comment in the commit log.
If the mod clock was shared by all peripherals on the bus this would be IMHO quite elegant. Probably it depends on what you mean by saying "incorrect" if this snippet is incorrect. (It can be part of a valid dtb that even complies to the binding documentation. However that's not how any existing allwinner hardware looks like.) But let's stop arguing as we agree it's a corner case and if you mention it in the commit log we're both happy.
Quoted 6 lines
Quoted 3 lines
What is that clock used for? Is it required to access the hardware registers? Or is it only required while the PWM is enabled? If so you could enable the clock more finegrainded.
Regarding the datasheet it's required to access the hardware. page 261 : https://linux-sunxi.org/File:Allwinner_H6_V200_User_Manual_V1.1.pdf
So enabling the bus clock is called "open APB1 Bus gating" in that manual? If I understand that correctly the bus clock then only need to be on while accessing the registers and could be disabled once the hardware is programmed and running.
Can you please describe that in a comment. Something like:
/*
* We're keeping the bus clock on for the sake of simplicity.
* Actually it only needs to be on for hardware register
* accesses.
*/
should be fine. This way it's at least obvious that the handling could be improved.
Best regards
Uwe
Signature · 2 lines
Pengutronix e.K. | Uwe Kleine-König | Industrial Linux Solutions | http://www.pengutronix.de/ |
Re: [PATCH v2 3/7] pwm: sun4i: Add an optional probe for bus clock
Dne ponedeljek, 04. november 2019 ob 21:10:52 CET je Uwe Kleine-König napisal(a):
Quoted 59 lines
Hello Clément,
Quoted 51 lines · Clément Péron
On Mon, 4 Nov 2019 at 09:24, Uwe Kleine-König
Quoted 48 lines · <[email protected]> wrote:
Quoted 31 lines · Clément Péron
From: Jernej Skrabec <[email protected]>
H6 PWM core needs bus clock to be enabled in order to work.
Add an optional probe for it and a fallback for previous bindings without name on module clock.
Signed-off-by Jernej Skrabec <[email protected]>Signed-off-by Clément Péron <[email protected]>---
drivers/pwm/pwm-sun4i.c | 36 ++++++++++++++++++++++++++++++++++++ 1 file changed, 36 insertions(+)drivers/pwm/pwm-sun4i.c +1
-0@@ -78,6 +78,7 @@ struct sun4i_pwm_data {struct sun4i_pwm_chip {struct pwm_chip chip; +struct clk *bus_clk;struct clk *clk; struct reset_control *rst; void __iomem *base;drivers/pwm/pwm-sun4i.c static int sun4i_pwm_probe(struct platform_device · line 368
Quoted 1 line
drivers/pwm/pwm-sun4i.c +0
-0@@ -367,6 +368,31 @@ static int sun4i_pwm_probe(struct platform_device *pdev)> >Adding more context here:
|pwm->clk=devm_clk_get(&pdev->dev, NULL);
|Quoted 11 lines
drivers/pwm/pwm-sun4i.c +7
-0if (IS_ERR (pwm->clk))return PTR_ERR (pwm->clk); +/* Get all clocks and reset line */ + pwm->clk =devm_clk_get_optional (&pdev->dev,"mod" ); +if (IS_ERR (pwm->clk)) { +dev_err (&pdev->dev,"get clock failed %ld\n" , +PTR_ERR (pwm->clk)); +return PTR_ERR (pwm->clk); + }Quoted 4 lines
Quoted 1 line
I guess you want to drop the first assignment to
pwm->clk.
devm_clk_get_optionalwill return NULL if there is no entry, I don't get where I need to drop it assignment.
Quoted 8 lines
With your patch the code looks as follows:
pwm->clk = devm_clk_get(&pdev->dev, NULL); if (IS_ERR(pwm->clk)) return PTR_ERR(pwm->clk); /* Get all clocks and reset line */ pwm->clk = devm_clk_get_optional(&pdev->dev, "mod");
Actually, it's the other way around, e.g. "mod" clock is checked first.
Quoted 4 lines
...The assignment to
pwm->clkabove the comment is the one I suggested to drop.
Neither can be dropped. DT files for other SoCs don't have clock-names property, so search for "mod" clock will fail and then fallback option without name is used.
Best regards,
Jernej
Quoted 67 lines
Quoted 26 lines
Quoted 26 lines
drivers/pwm/pwm-sun4i.c static int sun4i_pwm_probe(struct platform_device *pdev) · line 387
Quoted 10 lines
drivers/pwm/pwm-sun4i.c +9
-0+/* Fallback for old dtbs with a single clock and no name */ +if (!pwm->clk) { + pwm->clk =devm_clk_get (&pdev->dev,NULL ); +if (IS_ERR (pwm->clk)) { +dev_err (&pdev->dev,"get clock failed %ld\n" , +PTR_ERR (pwm->clk)); +return PTR_ERR (pwm->clk); + } + }There is a slight change of behaviour if I'm not mistaken. If you have
this:
clocks = <&clk1>; clock-names = "mod"; pwm { compatible = "allwinner,sun4i-a10-pwm" clocks = <&clk2>; }you now use clk1 instead of clk2 before.
Quoted 7 lines
Quoted 2 lines
Assuming this is only a theoretical problem, at least pointing this out in the commit log would be good I think.
Yes it's correct and as you said the driver don't check for a correct device tree, that why it's now optional probe.
Let's assume that's the device-tree is correct, I will add a comment in the commit log.If the mod clock was shared by all peripherals on the bus this would be IMHO quite elegant. Probably it depends on what you mean by saying "incorrect" if this snippet is incorrect. (It can be part of a valid dtb that even complies to the binding documentation. However that's not how any existing allwinner hardware looks like.) But let's stop arguing as we agree it's a corner case and if you mention it in the commit log we're both happy.
Quoted 7 lines
Quoted 3 lines
What is that clock used for? Is it required to access the hardware registers? Or is it only required while the PWM is enabled? If so you could enable the clock more finegrainded.
Regarding the datasheet it's required to access the hardware. page 261 :
https://linux-sunxi.org/File:Allwinner_H6_V200_User_Manual_V1.1.pdfSo enabling the bus clock is called "open APB1 Bus gating" in that manual? If I understand that correctly the bus clock then only need to be on while accessing the registers and could be disabled once the hardware is programmed and running.
Can you please describe that in a comment. Something like:
/*
* We're keeping the bus clock on for the sake of simplicity.
* Actually it only needs to be on for hardware register
* accesses.
*/should be fine. This way it's at least obvious that the handling could be improved.
Best regards
Uwe
Re: [PATCH v2 3/7] pwm: sun4i: Add an optional probe for bus clock
Hi,
Quoted 64 lines · Jernej Škrabec
Dne ponedeljek, 04. november 2019 ob 21:10:52 CET je Uwe Kleine-König napisal(a):
Quoted 61 lines
Hello Clément,
Quoted 51 lines · Clément Péron
On Mon, 4 Nov 2019 at 09:24, Uwe Kleine-König
Quoted 48 lines · <[email protected]> wrote:
Quoted 31 lines · Clément Péron
From: Jernej Skrabec <[email protected]>
H6 PWM core needs bus clock to be enabled in order to work.
Add an optional probe for it and a fallback for previous bindings without name on module clock.
Signed-off-by Jernej Skrabec <[email protected]>Signed-off-by Clément Péron <[email protected]>---
drivers/pwm/pwm-sun4i.c | 36 ++++++++++++++++++++++++++++++++++++ 1 file changed, 36 insertions(+)drivers/pwm/pwm-sun4i.c +1
-0@@ -78,6 +78,7 @@ struct sun4i_pwm_data {struct sun4i_pwm_chip {struct pwm_chip chip; +struct clk *bus_clk;struct clk *clk; struct reset_control *rst; void __iomem *base;drivers/pwm/pwm-sun4i.c static int sun4i_pwm_probe(struct platform_device · line 368
Quoted 1 line
drivers/pwm/pwm-sun4i.c +0
-0@@ -367,6 +368,31 @@ static int sun4i_pwm_probe(struct platform_device *pdev)> >Adding more context here:
|pwm->clk=devm_clk_get(&pdev->dev, NULL);
|Quoted 11 lines
drivers/pwm/pwm-sun4i.c +7
-0if (IS_ERR (pwm->clk))return PTR_ERR (pwm->clk); +/* Get all clocks and reset line */ + pwm->clk =devm_clk_get_optional (&pdev->dev,"mod" ); +if (IS_ERR (pwm->clk)) { +dev_err (&pdev->dev,"get clock failed %ld\n" , +PTR_ERR (pwm->clk)); +return PTR_ERR (pwm->clk); + }Quoted 4 lines
Quoted 1 line
I guess you want to drop the first assignment to
pwm->clk.
devm_clk_get_optionalwill return NULL if there is no entry, I don't get where I need to drop it assignment.With your patch the code looks as follows:
Quoted 8 lines
Quoted 6 lines
pwm->clk = devm_clk_get(&pdev->dev, NULL); if (IS_ERR(pwm->clk)) return PTR_ERR(pwm->clk); /* Get all clocks and reset line */ pwm->clk = devm_clk_get_optional(&pdev->dev, "mod");Actually, it's the other way around, e.g. "mod" clock is checked first.
The first devm_clk_get is indeed wrong, I will remove it!
Quoted 84 lines
Quoted 5 lines
...The assignment to
pwm->clkabove the comment is the one I suggested to drop.Neither can be dropped. DT files for other SoCs don't have clock-names property, so search for "mod" clock will fail and then fallback option without name is used.
Best regards,
JernejQuoted 67 lines
Quoted 26 lines
Quoted 26 lines
drivers/pwm/pwm-sun4i.c static int sun4i_pwm_probe(struct platform_device *pdev) · line 387
Quoted 10 lines
drivers/pwm/pwm-sun4i.c +9
-0+/* Fallback for old dtbs with a single clock and no name */ +if (!pwm->clk) { + pwm->clk =devm_clk_get (&pdev->dev,NULL ); +if (IS_ERR (pwm->clk)) { +dev_err (&pdev->dev,"get clock failed %ld\n" , +PTR_ERR (pwm->clk)); +return PTR_ERR (pwm->clk); + } + }There is a slight change of behaviour if I'm not mistaken. If you have
this:
clocks = <&clk1>; clock-names = "mod"; pwm { compatible = "allwinner,sun4i-a10-pwm" clocks = <&clk2>; }you now use clk1 instead of clk2 before.
Quoted 7 lines
Quoted 2 lines
Assuming this is only a theoretical problem, at least pointing this out in the commit log would be good I think.
Yes it's correct and as you said the driver don't check for a correct device tree, that why it's now optional probe.
Let's assume that's the device-tree is correct, I will add a comment in the commit log.If the mod clock was shared by all peripherals on the bus this would be IMHO quite elegant. Probably it depends on what you mean by saying "incorrect" if this snippet is incorrect. (It can be part of a valid dtb that even complies to the binding documentation. However that's not how any existing allwinner hardware looks like.) But let's stop arguing as we agree it's a corner case and if you mention it in the commit log we're both happy.
Quoted 7 lines
Quoted 3 lines
What is that clock used for? Is it required to access the hardware registers? Or is it only required while the PWM is enabled? If so you could enable the clock more finegrainded.
Regarding the datasheet it's required to access the hardware. page 261 :
https://linux-sunxi.org/File:Allwinner_H6_V200_User_Manual_V1.1.pdfSo enabling the bus clock is called "open APB1 Bus gating" in that manual? If I understand that correctly the bus clock then only need to be on while accessing the registers and could be disabled once the hardware is programmed and running.
Can you please describe that in a comment. Something like:
/*
* We're keeping the bus clock on for the sake of simplicity.
* Actually it only needs to be on for hardware register
* accesses.
*/should be fine. This way it's at least obvious that the handling could be improved.
Best regards
Uwe
Re: [PATCH v2 3/7] pwm: sun4i: Add an optional probe for bus clock
Dne ponedeljek, 04. november 2019 ob 21:27:04 CET je Clément Péron napisal(a):
Quoted 71 lines
Hi,
Quoted 68 lines · Jernej Škrabec
Dne ponedeljek, 04. november 2019 ob 21:10:52 CET je Uwe Kleine-König
napisal(a):
Quoted 65 lines
Hello Clément,
Quoted 53 lines · Clément Péron
On Mon, 4 Nov 2019 at 09:24, Uwe Kleine-König
Quoted 50 lines · <[email protected]> wrote:
Quoted 31 lines · Clément Péron
From: Jernej Skrabec <[email protected]>
H6 PWM core needs bus clock to be enabled in order to work.
Add an optional probe for it and a fallback for previous bindings without name on module clock.
Signed-off-by Jernej Skrabec <[email protected]>Signed-off-by Clément Péron <[email protected]>---
drivers/pwm/pwm-sun4i.c | 36 ++++++++++++++++++++++++++++++++++++ 1 file changed, 36 insertions(+)drivers/pwm/pwm-sun4i.c +1
-0@@ -78,6 +78,7 @@ struct sun4i_pwm_data {struct sun4i_pwm_chip {struct pwm_chip chip; +struct clk *bus_clk;struct clk *clk; struct reset_control *rst; void __iomem *base;drivers/pwm/pwm-sun4i.c +0
-0@@ -367,6 +368,31 @@ static int sun4i_pwm_probe(structQuoted 2 lines
platform_device
*pdev)> >Adding more context here:
|pwm->clk=devm_clk_get(&pdev->dev, NULL);
|Quoted 11 lines
if (IS_ERR(pwm->clk)) return PTR_ERR(pwm->clk);drivers/pwm/pwm-sun4i.c +7
-0+/* Get all clocks and reset line */ + pwm->clk =devm_clk_get_optional (&pdev->dev,"mod" ); +if (IS_ERR (pwm->clk)) { +dev_err (&pdev->dev,"get clock failed %ld\n" , +PTR_ERR (pwm->clk)); +return PTR_ERR (pwm->clk); + }Quoted 4 lines
Quoted 1 line
I guess you want to drop the first assignment to
pwm->clk.
devm_clk_get_optionalwill return NULL if there is no entry, I don't get where I need to drop it assignment.With your patch the code looks as follows:
pwm->clk = devm_clk_get(&pdev->dev, NULL); if (IS_ERR(pwm->clk))
Quoted 8 lines
Quoted 6 lines
Quoted 4 lines
return PTR_ERR(pwm->clk); /* Get all clocks and reset line */ pwm->clk = devm_clk_get_optional(&pdev->dev, "mod");Actually, it's the other way around, e.g. "mod" clock is checked first.
The first
devm_clk_getis indeed wrong, I will remove it!
Sorry, I missed that too. Yeah, it should be removed.
Best regards,
Jernej
Quoted 84 lines
Quoted 84 lines
Quoted 5 lines
...The assignment to
pwm->clkabove the comment is the one I suggested to drop.Neither can be dropped. DT files for other SoCs don't have clock-names property, so search for "mod" clock will fail and then fallback option without name is used.
Best regards,
JernejQuoted 71 lines
Quoted 27 lines
Quoted 27 lines
drivers/pwm/pwm-sun4i.c static int sun4i_pwm_probe(struct platform_device *pdev) · line 386
Quoted 10 lines
drivers/pwm/pwm-sun4i.c +5
-0+/* Fallback for old dtbs with a single clock and no name */ +if (!pwm->clk) { + pwm->clk =devm_clk_get (&pdev->dev,NULL ); +if (IS_ERR (pwm->clk)) { + dev_err(&pdev->dev, "get clock failed%ld\n",
drivers/pwm/pwm-sun4i.c +4
-0+ PTR_ERR(pwm->clk)); +return PTR_ERR (pwm->clk); + } + }There is a slight change of behaviour if I'm not mistaken. If you have
this:
clocks = <&clk1>; clock-names = "mod"; pwm { compatible = "allwinner,sun4i-a10-pwm" clocks = <&clk2>; }you now use clk1 instead of clk2 before.
Quoted 8 lines
Quoted 3 lines
Assuming this is only a theoretical problem, at least pointing this out
in the commit log would be good I think.Yes it's correct and as you said the driver don't check for a correct device tree, that why it's now optional probe.
Let's assume that's the device-tree is correct, I will add a comment in the commit log.If the mod clock was shared by all peripherals on the bus this would be IMHO quite elegant. Probably it depends on what you mean by saying "incorrect" if this snippet is incorrect. (It can be part of a valid dtb that even complies to the binding documentation. However that's not how any existing allwinner hardware looks like.) But let's stop arguing as we agree it's a corner case and if you mention it in the commit log we're both happy.
Quoted 8 lines
Quoted 4 lines
What is that clock used for? Is it required to access the hardware registers? Or is it only required while the PWM is enabled? If so you
could enable the clock more finegrainded.Regarding the datasheet it's required to access the hardware. page 261 :
https://linux-sunxi.org/File:Allwinner_H6_V200_User_Manual_V1.1.pdfSo enabling the bus clock is called "open APB1 Bus gating" in that manual? If I understand that correctly the bus clock then only need to be on while accessing the registers and could be disabled once the hardware is programmed and running.
Can you please describe that in a comment. Something like:
/** We're keeping the bus clock on for the sake of simplicity.
* Actually it only needs to be on for hardware register
* accesses.
*/should be fine. This way it's at least obvious that the handling could be improved.
Best regards
Uwe
PATCH v2 4/7 pwm: sun4i: Add support to output source clock directly
In reply to Clément PéronFrom: Jernej Skrabec <[email protected]>
PWM core has an option to bypass whole logic and output unchanged source clock as PWM output. This is achieved by enabling bypass bit.
Note that when bypass is enabled, no other setting has any meaning, not even enable bit.
This mode of operation is needed to achieve high enough frequency to serve as clock source for AC200 chip, which is integrated into same package as H6 SoC.
--- drivers/pwm/pwm-sun4i.c | 39 ++++++++++++++++++++++++++++++++++++++- 1 file changed, 38 insertions(+), 1 deletion(-)
drivers/pwm/pwm-sun4i.c +38 -1
@@ -3,6 +3,10 @@* Driver for Allwinner sun4i Pulse Width Modulation Controller * * Copyright (C) 2014 Alexandre Belloni <[email protected]> +* +* Limitations: +* - When outputing the source clock directly, the PWM logic will be bypassed +* and the currently running period is not guaranted to be completed */ #include <linux/bitops.h>
@@ -73,6 +77,7 @@ static const u32 prescaler_table[] = {struct sun4i_pwm_data {bool has_prescaler_bypass; +bool has_direct_mod_clk_output;unsigned int npwm; };
@@ -118,6 +123,20 @@ static void sun4i_pwm_get_state(struct pwm_chip *chip, val =sun4i_pwm_readl (sun4i_pwm,PWM_CTRL_REG ); +/* +* PWM chapter in H6 manual has a diagram which explains that if bypass +* bit is set, no other setting has any meaning. Even more, experiment +* proved that also enable bit is ignored in this case. +*/ +if ((val &BIT_CH (PWM_BYPASS , pwm->hwpwm)) && + data->has_direct_mod_clk_output) { + state->period =DIV_ROUND_CLOSEST_ULL (NSEC_PER_SEC , clk_rate); + state->duty_cycle = state->period /2 ; + state->polarity =PWM_POLARITY_NORMAL ; + state->enabled = true; +return ; + } +if ((PWM_REG_PRESCAL (val, pwm->hwpwm) ==PWM_PRESCAL_MASK ) && sun4i_pwm->data->has_prescaler_bypass) prescaler =1 ;
@@ -203,7 +222,8 @@ static int sun4i_pwm_apply(struct pwm_chip *chip, struct pwm_device *pwm, {struct sun4i_pwm_chip *sun4i_pwm =to_sun4i_pwm_chip (chip);struct pwm_state cstate; -u32 ctrl; +u32 ctrl, clk_rate; +bool bypass;int ret;unsigned int delay_us;unsigned long now;
@@ -218,6 +238,16 @@ static int sun4i_pwm_apply(struct pwm_chip *chip, struct pwm_device *pwm, } } +/* +* Although it would make much more sense to check for bypass in +* sun4i_pwm_calculate(), value of bypass bit also depends on "enabled". +* Period is allowed to be rounded up or down. +*/ + clk_rate =clk_get_rate (sun4i_pwm->clk); + bypass = ((state->period * clk_rate >=NSEC_PER_SEC && + state->period * clk_rate <NSEC_PER_SEC + clk_rate) && + state->enabled); +spin_lock (&sun4i_pwm->ctrl_lock); ctrl =sun4i_pwm_readl (sun4i_pwm,PWM_CTRL_REG );
@@ -265,6 +295,13 @@ static int sun4i_pwm_apply(struct pwm_chip *chip, struct pwm_device *pwm, ctrl &= ~BIT_CH (PWM_CLK_GATING , pwm->hwpwm); } +if (sun4i_pwm->data->has_direct_mod_clk_output) { +if (bypass) + ctrl |=BIT_CH (PWM_BYPASS , pwm->hwpwm); +else + ctrl &= ~BIT_CH (PWM_BYPASS , pwm->hwpwm); + } +sun4i_pwm_writel (sun4i_pwm, ctrl,PWM_CTRL_REG );spin_unlock (&sun4i_pwm->ctrl_lock);
Signature · 1 line
2.20.1
kbuild test robot
build botRe: [PATCH v2 4/7] pwm: sun4i: Add support to output source clock directly
I love your patch! Yet something to improve:
Hi "Clément,
I love your patch! Yet something to improve:
[auto build test ERROR on sunxi/sunxi/for-next]
[also build test ERROR on v5.4-rc5 next-20191031]
[if your patch is applied to the wrong git tree, please drop us a note to help improve the system. BTW, we also suggest to use '--base' option to specify the base tree in git format-patch, please see https://stackoverflow.com/a/37406982]
url: https://github.com/0day-ci/linux/commits/Cl-ment-P-ron/Add-support-for-H6-PWM/20191104-043621 base: https://git.kernel.org/pub/scm/linux/kernel/git/sunxi/linux.git sunxi/for-next config: riscv-allmodconfig (attached as .config) compiler: riscv64-linux-gcc (GCC) 7.4.0
reproduce:
wget https://raw.githubusercontent.com/intel/lkp-tests/master/sbin/make.cross -O ~/bin/make.cross chmod +x ~/bin/make.cross
# save the attached .config to linux build tree
GCC_VERSION=7.4.0 make.cross ARCH=riscv
If you fix the issue, kindly add following tag
All errors (new ones prefixed by >>):
drivers//pwm/pwm-sun4i.c: In function 'sun4i_pwm_get_state':
>> drivers//pwm/pwm-sun4i.c:132:6: error: 'data' undeclared (first use in this function)
data->has_direct_mod_clk_output) {
^~~~ drivers//pwm/pwm-sun4i.c:132:6: note: each undeclared identifier is reported only once for each function it appears in
vim +/data +132 drivers//pwm/pwm-sun4i.c
112
113 static void sun4i_pwm_get_state(struct pwm_chip *chip,
114 struct pwm_device *pwm,
115 struct pwm_state *state)
116 {
117 struct sun4i_pwm_chip *sun4i_pwm = to_sun4i_pwm_chip(chip);
118 u64 clk_rate, tmp;
119 u32 val;
120 unsigned int prescaler;
121
122 clk_rate = clk_get_rate(sun4i_pwm->clk);
123
124 val = sun4i_pwm_readl(sun4i_pwm, PWM_CTRL_REG);
125
126 /*
127 * PWM chapter in H6 manual has a diagram which explains that if bypass
128 * bit is set, no other setting has any meaning. Even more, experiment
129 * proved that also enable bit is ignored in this case.
130 */
131 if ((val & BIT_CH(PWM_BYPASS, pwm->hwpwm)) &&
> 132 data->has_direct_mod_clk_output) { 133 state->period = DIV_ROUND_CLOSEST_ULL(NSEC_PER_SEC, clk_rate);
134 state->duty_cycle = state->period / 2;
135 state->polarity = PWM_POLARITY_NORMAL;
136 state->enabled = true;
137 return;
138 }
139
140 if ((PWM_REG_PRESCAL(val, pwm->hwpwm) == PWM_PRESCAL_MASK) &&
141 sun4i_pwm->data->has_prescaler_bypass)
142 prescaler = 1;
143 else
144 prescaler = prescaler_table[PWM_REG_PRESCAL(val, pwm->hwpwm)];
145
146 if (prescaler == 0)
147 return;
148
149 if (val & BIT_CH(PWM_ACT_STATE, pwm->hwpwm))
150 state->polarity = PWM_POLARITY_NORMAL;
151 else
152 state->polarity = PWM_POLARITY_INVERSED;
153
154 if ((val & BIT_CH(PWM_CLK_GATING | PWM_EN, pwm->hwpwm)) ==
155 BIT_CH(PWM_CLK_GATING | PWM_EN, pwm->hwpwm))
156 state->enabled = true;
157 else
158 state->enabled = false;
159
160 val = sun4i_pwm_readl(sun4i_pwm, PWM_CH_PRD(pwm->hwpwm));
161
162 tmp = prescaler * NSEC_PER_SEC * PWM_REG_DTY(val);
163 state->duty_cycle = DIV_ROUND_CLOSEST_ULL(tmp, clk_rate);
164
165 tmp = prescaler * NSEC_PER_SEC * PWM_REG_PRD(val);
166 state->period = DIV_ROUND_CLOSEST_ULL(tmp, clk_rate);
167 }
168
---
0-DAY kernel test infrastructure Open Source Technology Center
https://lists.01.org/pipermail/kbuild-all Intel Corporation
Re: [PATCH v2 4/7] pwm: sun4i: Add support to output source clock directly
Hi,
Quoted 22 lines · kbuild test robot
Hi "Clément,
I love your patch! Yet something to improve:
[auto build test ERROR on sunxi/sunxi/for-next]
[also build test ERROR on v5.4-rc5 next-20191031]
[if your patch is applied to the wrong git tree, please drop us a note to help improve the system. BTW, we also suggest to use '--base' option to specify the base tree in git format-patch, please see https://stackoverflow.com/a/37406982]url: https://github.com/0day-ci/linux/commits/Cl-ment-P-ron/Add-support-for-H6-PWM/20191104-043621 base: https://git.kernel.org/pub/scm/linux/kernel/git/sunxi/linux.git sunxi/for-next config: riscv-allmodconfig (attached as .config) compiler: riscv64-linux-gcc (GCC) 7.4.0reproduce:
wget https://raw.githubusercontent.com/intel/lkp-tests/master/sbin/make.cross -O ~/bin/make.cross chmod +x ~/bin/make.cross
# save the attached .config to linux build tree
GCC_VERSION=7.4.0 make.cross ARCH=riscvIf you fix the issue, kindly add following tag
Quoted 8 lines
Reported-by kbuild test robot <[email protected]>All errors (new ones prefixed by >>):
drivers//pwm/pwm-sun4i.c: In function 'sun4i_pwm_get_state':Quoted 1 line
Quoted 1 line
drivers//pwm/pwm-sun4i.c:132:6: error: 'data' undeclared (first use in this function)data->has_direct_mod_clk_output) { ^~~~
Arg, bad last minute indent fix :
This should be "sun4i_pwm->data->has_direct_mod_clk_output"
Sorry for that,
Clément
Quoted 62 lines
drivers//pwm/pwm-sun4i.c:132:6: note: each undeclared identifier is reported only once for each function it appears invim +/data +132
drivers//pwm/pwm-sun4i.c112 113 static void sun4i_pwm_get_state(struct pwm_chip *chip, 114 struct pwm_device *pwm, 115 struct pwm_state *state) 116 { 117 struct sun4i_pwm_chip *sun4i_pwm = to_sun4i_pwm_chip(chip); 118 u64 clk_rate, tmp; 119 u32 val; 120 unsigned int prescaler; 121 122 clk_rate = clk_get_rate(sun4i_pwm->clk); 123 124 val = sun4i_pwm_readl(sun4i_pwm, PWM_CTRL_REG); 125 126 /* 127 * PWM chapter in H6 manual has a diagram which explains that if bypass 128 * bit is set, no other setting has any meaning. Even more, experiment 129 * proved that also enable bit is ignored in this case. 130 */ 131 if ((val & BIT_CH(PWM_BYPASS, pwm->hwpwm)) &&Quoted 1 line
132
data->has_direct_mod_clk_output) {133 state->period = DIV_ROUND_CLOSEST_ULL(NSEC_PER_SEC, clk_rate); 134 state->duty_cycle = state->period / 2; 135 state->polarity = PWM_POLARITY_NORMAL; 136 state->enabled = true; 137 return; 138 } 139 140 if ((PWM_REG_PRESCAL(val, pwm->hwpwm) == PWM_PRESCAL_MASK) && 141 sun4i_pwm->data->has_prescaler_bypass) 142 prescaler = 1; 143 else 144 prescaler = prescaler_table[PWM_REG_PRESCAL(val, pwm->hwpwm)]; 145 146 if (prescaler == 0) 147 return; 148 149 if (val & BIT_CH(PWM_ACT_STATE, pwm->hwpwm)) 150 state->polarity = PWM_POLARITY_NORMAL; 151 else 152 state->polarity = PWM_POLARITY_INVERSED; 153 154 if ((val & BIT_CH(PWM_CLK_GATING | PWM_EN, pwm->hwpwm)) == 155 BIT_CH(PWM_CLK_GATING | PWM_EN, pwm->hwpwm)) 156 state->enabled = true; 157 else 158 state->enabled = false; 159 160 val = sun4i_pwm_readl(sun4i_pwm, PWM_CH_PRD(pwm->hwpwm)); 161 162 tmp = prescaler * NSEC_PER_SEC * PWM_REG_DTY(val); 163 state->duty_cycle = DIV_ROUND_CLOSEST_ULL(tmp, clk_rate); 164 165 tmp = prescaler * NSEC_PER_SEC * PWM_REG_PRD(val); 166 state->period = DIV_ROUND_CLOSEST_ULL(tmp, clk_rate); 167 } 168
Quoted 3 lines
---
0-DAY kernel test infrastructure Open Source Technology Center
https://lists.01.org/pipermail/kbuild-all Intel Corporation
_______________________________________________
linux-arm-kernel mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel
kbuild test robot
build botRe: [PATCH v2 4/7] pwm: sun4i: Add support to output source clock directly
In reply to Clément PéronI love your patch! Yet something to improve:
Hi "Clément,
I love your patch! Yet something to improve:
[auto build test ERROR on sunxi/sunxi/for-next]
[also build test ERROR on v5.4-rc5 next-20191031]
[if your patch is applied to the wrong git tree, please drop us a note to help improve the system. BTW, we also suggest to use '--base' option to specify the base tree in git format-patch, please see https://stackoverflow.com/a/37406982]
url: https://github.com/0day-ci/linux/commits/Cl-ment-P-ron/Add-support-for-H6-PWM/20191104-043621 base: https://git.kernel.org/pub/scm/linux/kernel/git/sunxi/linux.git sunxi/for-next config: mips-allmodconfig (attached as .config) compiler: mips-linux-gcc (GCC) 7.4.0
reproduce:
wget https://raw.githubusercontent.com/intel/lkp-tests/master/sbin/make.cross -O ~/bin/make.cross chmod +x ~/bin/make.cross
# save the attached .config to linux build tree
GCC_VERSION=7.4.0 make.cross ARCH=mips
If you fix the issue, kindly add following tag
All errors (new ones prefixed by >>):
drivers//pwm/pwm-sun4i.c: In function 'sun4i_pwm_get_state':
>> drivers//pwm/pwm-sun4i.c:132:6: error: 'data' undeclared (first use in this function); did you mean 'path'?
data->has_direct_mod_clk_output) {
^~~~
path drivers//pwm/pwm-sun4i.c:132:6: note: each undeclared identifier is reported only once for each function it appears in
vim +132 drivers//pwm/pwm-sun4i.c
112
113 static void sun4i_pwm_get_state(struct pwm_chip *chip,
114 struct pwm_device *pwm,
115 struct pwm_state *state)
116 {
117 struct sun4i_pwm_chip *sun4i_pwm = to_sun4i_pwm_chip(chip);
118 u64 clk_rate, tmp;
119 u32 val;
120 unsigned int prescaler;
121
122 clk_rate = clk_get_rate(sun4i_pwm->clk);
123
124 val = sun4i_pwm_readl(sun4i_pwm, PWM_CTRL_REG);
125
126 /*
127 * PWM chapter in H6 manual has a diagram which explains that if bypass
128 * bit is set, no other setting has any meaning. Even more, experiment
129 * proved that also enable bit is ignored in this case.
130 */
131 if ((val & BIT_CH(PWM_BYPASS, pwm->hwpwm)) &&
> 132 data->has_direct_mod_clk_output) { 133 state->period = DIV_ROUND_CLOSEST_ULL(NSEC_PER_SEC, clk_rate);
134 state->duty_cycle = state->period / 2;
135 state->polarity = PWM_POLARITY_NORMAL;
136 state->enabled = true;
137 return;
138 }
139
140 if ((PWM_REG_PRESCAL(val, pwm->hwpwm) == PWM_PRESCAL_MASK) &&
141 sun4i_pwm->data->has_prescaler_bypass)
142 prescaler = 1;
143 else
144 prescaler = prescaler_table[PWM_REG_PRESCAL(val, pwm->hwpwm)];
145
146 if (prescaler == 0)
147 return;
148
149 if (val & BIT_CH(PWM_ACT_STATE, pwm->hwpwm))
150 state->polarity = PWM_POLARITY_NORMAL;
151 else
152 state->polarity = PWM_POLARITY_INVERSED;
153
154 if ((val & BIT_CH(PWM_CLK_GATING | PWM_EN, pwm->hwpwm)) ==
155 BIT_CH(PWM_CLK_GATING | PWM_EN, pwm->hwpwm))
156 state->enabled = true;
157 else
158 state->enabled = false;
159
160 val = sun4i_pwm_readl(sun4i_pwm, PWM_CH_PRD(pwm->hwpwm));
161
162 tmp = prescaler * NSEC_PER_SEC * PWM_REG_DTY(val);
163 state->duty_cycle = DIV_ROUND_CLOSEST_ULL(tmp, clk_rate);
164
165 tmp = prescaler * NSEC_PER_SEC * PWM_REG_PRD(val);
166 state->period = DIV_ROUND_CLOSEST_ULL(tmp, clk_rate);
167 }
168
---
0-DAY kernel test infrastructure Open Source Technology Center
https://lists.01.org/pipermail/kbuild-all Intel Corporation
_______________________________________________
linux-arm-kernel mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel
Re: [PATCH v2 4/7] pwm: sun4i: Add support to output source clock directly
In reply to Clément PéronQuoted 11 lines · Clément Péron
From: Jernej Skrabec <[email protected]>
PWM core has an option to bypass whole logic and output unchanged source clock as PWM output. This is achieved by enabling bypass bit.
Note that when bypass is enabled, no other setting has any meaning, not even enable bit.
This mode of operation is needed to achieve high enough frequency to serve as clock source for AC200 chip, which is integrated into same package as H6 SoC.
I think the , should be dropped.
Quoted 11 lines
Signed-off-by Jernej Skrabec <[email protected]>Signed-off-by Clément Péron <[email protected]>--- drivers/pwm/pwm-sun4i.c | 39 ++++++++++++++++++++++++++++++++++++++- 1 file changed, 38 insertions(+), 1 deletion(-)drivers/pwm/pwm-sun4i.c +0
-0
drivers/pwm/pwm-sun4i.c line 9
Quoted 7 lines
drivers/pwm/pwm-sun4i.c +4
-0@@ -3,6 +3,10 @@* Driver for Allwinner sun4i Pulse Width Modulation Controller * * Copyright (C) 2014 Alexandre Belloni <[email protected]> +* +* Limitations: +* - When outputing the source clock directly, the PWM logic will be bypassed +* and the currently running period is not guaranted to be completed
Typo: guaranted -> guaranteed
Quoted 18 lines
drivers/pwm/pwm-sun4i.c +4
-0*/ #include <linux/bitops.h> @@ -73,6 +77,7 @@ static const u32 prescaler_table[] = {struct sun4i_pwm_data {bool has_prescaler_bypass; +bool has_direct_mod_clk_output;unsigned int npwm; };@@ -118,6 +123,20 @@ static void sun4i_pwm_get_state(struct pwm_chip *chip, val =sun4i_pwm_readl (sun4i_pwm,PWM_CTRL_REG ); +/* +* PWM chapter in H6 manual has a diagram which explains that if bypass +* bit is set, no other setting has any meaning. Even more, experiment
drivers/pwm/pwm-sun4i.c static void sun4i_pwm_get_state(struct pwm_chip *chip, · line 138
Quoted 10 lines
drivers/pwm/pwm-sun4i.c +10
-0+* proved that also enable bit is ignored in this case. +*/ +if ((val &BIT_CH (PWM_BYPASS , pwm->hwpwm)) && + data->has_direct_mod_clk_output) { + state->period =DIV_ROUND_CLOSEST_ULL (NSEC_PER_SEC , clk_rate); + state->duty_cycle = state->period /2 ; + state->polarity =PWM_POLARITY_NORMAL ; + state->enabled = true; +return ; + }
Not sure how the rest of sun4i_pwm_get_state behaves, but I would prefer to let .get_state() round up which together with .apply_state() rounding down yields sound behaviour.
Quoted 17 lines
drivers/pwm/pwm-sun4i.c +3
-1+if ((PWM_REG_PRESCAL (val, pwm->hwpwm) ==PWM_PRESCAL_MASK ) && sun4i_pwm->data->has_prescaler_bypass) prescaler =1 ;@@ -203,7 +222,8 @@ static int sun4i_pwm_apply(struct pwm_chip *chip, struct pwm_device *pwm, {struct sun4i_pwm_chip *sun4i_pwm =to_sun4i_pwm_chip (chip);struct pwm_state cstate; -u32 ctrl; +u32 ctrl, clk_rate; +bool bypass;int ret;unsigned int delay_us;unsigned long now;@@ -218,6 +238,16 @@ static int sun4i_pwm_apply(struct pwm_chip *chip, struct pwm_device *pwm, } }
drivers/pwm/pwm-sun4i.c static int sun4i_pwm_apply(struct pwm_chip *chip, struct pwm_device *pwm, · line 249
Quoted 10 lines
drivers/pwm/pwm-sun4i.c +9
-0+/* +* Although it would make much more sense to check for bypass in +* sun4i_pwm_calculate(), value of bypass bit also depends on "enabled". +* Period is allowed to be rounded up or down. +*/ + clk_rate =clk_get_rate (sun4i_pwm->clk); + bypass = ((state->period * clk_rate >=NSEC_PER_SEC && + state->period * clk_rate <NSEC_PER_SEC + clk_rate) && + state->enabled);
I guess the compiler is smart enough here, but checking for state->enabled is cheaper than the other checks, so putting this at the start of the expression seems sensible.
The comment doesn't match the code. You don't round up state->period. (This is good, please fix the comment.) I think dropping the check
state->period * clk_rate < NSEC_PER_SEC + clk_rate
would be fine, too.
I'd like to have a check for
state->duty_cycle * clk_rate >= NSEC_PER_SEC / 2 && state->duty_cycle * clk_rate < NSEC_PER_SEC
here. If this isn't true rather disable the PWM or output a 100% duty cycle with a larger period.
drivers/pwm/pwm-sun4i.c static int sun4i_pwm_apply(struct pwm_chip *chip, struct pwm_device *pwm, · line 253
Quoted 4 lines
drivers/pwm/pwm-sun4i.c +1
-0+spin_lock (&sun4i_pwm->ctrl_lock); ctrl =sun4i_pwm_readl (sun4i_pwm,PWM_CTRL_REG );
Best regards
Uwe
Signature · 2 lines
Pengutronix e.K. | Uwe Kleine-König | Industrial Linux Solutions | http://www.pengutronix.de/ |
Re: [PATCH v2 4/7] pwm: sun4i: Add support to output source clock directly
Hi Uwe
Quoted 61 lines · Uwe Kleine-König
Quoted 11 lines · Clément Péron
From: Jernej Skrabec <[email protected]>
PWM core has an option to bypass whole logic and output unchanged source clock as PWM output. This is achieved by enabling bypass bit.
Note that when bypass is enabled, no other setting has any meaning, not even enable bit.
This mode of operation is needed to achieve high enough frequency to serve as clock source for AC200 chip, which is integrated into same package as H6 SoC.
I think the , should be dropped.
Quoted 11 lines
Signed-off-by Jernej Skrabec <[email protected]>Signed-off-by Clément Péron <[email protected]>--- drivers/pwm/pwm-sun4i.c | 39 ++++++++++++++++++++++++++++++++++++++- 1 file changed, 38 insertions(+), 1 deletion(-)drivers/pwm/pwm-sun4i.c +0
-0drivers/pwm/pwm-sun4i.c line 9
Quoted 7 lines
drivers/pwm/pwm-sun4i.c +4
-0@@ -3,6 +3,10 @@* Driver for Allwinner sun4i Pulse Width Modulation Controller * * Copyright (C) 2014 Alexandre Belloni <[email protected]> +* +* Limitations: +* - When outputing the source clock directly, the PWM logic will be bypassed +* and the currently running period is not guaranted to be completed Typo: guaranted -> guaranteed
Quoted 24 lines
drivers/pwm/pwm-sun4i.c +10
-0*/ #include <linux/bitops.h> @@ -73,6 +77,7 @@ static const u32 prescaler_table[] = {struct sun4i_pwm_data {bool has_prescaler_bypass; +bool has_direct_mod_clk_output;unsigned int npwm; };@@ -118,6 +123,20 @@ static void sun4i_pwm_get_state(struct pwm_chip *chip, val =sun4i_pwm_readl (sun4i_pwm,PWM_CTRL_REG ); +/* +* PWM chapter in H6 manual has a diagram which explains that if bypass +* bit is set, no other setting has any meaning. Even more, experiment +* proved that also enable bit is ignored in this case. +*/ +if ((val &BIT_CH (PWM_BYPASS , pwm->hwpwm)) && + data->has_direct_mod_clk_output) { + state->period =DIV_ROUND_CLOSEST_ULL (NSEC_PER_SEC , clk_rate); + state->duty_cycle = state->period /2 ;
Quoted 8 lines
drivers/pwm/pwm-sun4i.c static void sun4i_pwm_get_state(struct pwm_chip *chip, · line 138
Quoted 4 lines
drivers/pwm/pwm-sun4i.c +4
-0+ state->polarity =PWM_POLARITY_NORMAL ; + state->enabled = true; +return ; + }Not sure how the rest of
sun4i_pwm_get_statebehaves, but I would prefer to let .get_state() round up which together with .apply_state() rounding down yields sound behaviour.
Ok
Quoted 33 lines
Quoted 18 lines
drivers/pwm/pwm-sun4i.c +3
-1+if ((PWM_REG_PRESCAL (val, pwm->hwpwm) ==PWM_PRESCAL_MASK ) && sun4i_pwm->data->has_prescaler_bypass) prescaler =1 ;@@ -203,7 +222,8 @@ static int sun4i_pwm_apply(struct pwm_chip *chip, struct pwm_device *pwm, {struct sun4i_pwm_chip *sun4i_pwm =to_sun4i_pwm_chip (chip);struct pwm_state cstate; -u32 ctrl; +u32 ctrl, clk_rate; +bool bypass;int ret;unsigned int delay_us;unsigned long now;@@ -218,6 +238,16 @@ static int sun4i_pwm_apply(struct pwm_chip *chip, struct pwm_device *pwm, } }drivers/pwm/pwm-sun4i.c static int sun4i_pwm_apply(struct pwm_chip *chip, struct pwm_device *pwm, · line 249
Quoted 10 lines
drivers/pwm/pwm-sun4i.c +9
-0+/* +* Although it would make much more sense to check for bypass in +* sun4i_pwm_calculate(), value of bypass bit also depends on "enabled". +* Period is allowed to be rounded up or down. +*/ + clk_rate =clk_get_rate (sun4i_pwm->clk); + bypass = ((state->period * clk_rate >=NSEC_PER_SEC && + state->period * clk_rate <NSEC_PER_SEC + clk_rate) && + state->enabled);I guess the compiler is smart enough here, but checking for
state->enabledis cheaper than the other checks, so putting this at the start of the expression seems sensible.
Quoted 6 lines
The comment doesn't match the code. You don't round up
state->period. (This is good, please fix the comment.) I think dropping the checkstate->period * clk_rate < NSEC_PER_SEC + clk_ratewould be fine, too.
Ok
Quoted 8 lines
I'd like to have a check for
state->duty_cycle * clk_rate >= NSEC_PER_SEC / 2 && state->duty_cycle * clk_rate < NSEC_PER_SEChere. If this isn't true rather disable the PWM or output a 100% duty cycle with a larger period.
Why not just having the duty_cycle is 50% only ?state->duty_cycle * 2 == state->period;
Regards,
Clement
Quoted 12 lines
drivers/pwm/pwm-sun4i.c static int sun4i_pwm_apply(struct pwm_chip *chip, struct pwm_device *pwm, · line 253
Quoted 5 lines
drivers/pwm/pwm-sun4i.c +1
-0+spin_lock (&sun4i_pwm->ctrl_lock); ctrl =sun4i_pwm_readl (sun4i_pwm,PWM_CTRL_REG );Best regards
Uwe--
Pengutronix e.K. | Uwe Kleine-König |
Industrial Linux Solutions | http://www.pengutronix.de/ |
Re: [PATCH v2 4/7] pwm: sun4i: Add support to output source clock directly
Hi Clément,
Quoted 115 lines · Clément Péron
Quoted 60 lines · Uwe Kleine-König
Quoted 11 lines · Clément Péron
From: Jernej Skrabec <[email protected]>
PWM core has an option to bypass whole logic and output unchanged source clock as PWM output. This is achieved by enabling bypass bit.
Note that when bypass is enabled, no other setting has any meaning, not even enable bit.
This mode of operation is needed to achieve high enough frequency to serve as clock source for AC200 chip, which is integrated into same package as H6 SoC.
I think the , should be dropped.
Quoted 11 lines
Signed-off-by Jernej Skrabec <[email protected]>Signed-off-by Clément Péron <[email protected]>--- drivers/pwm/pwm-sun4i.c | 39 ++++++++++++++++++++++++++++++++++++++- 1 file changed, 38 insertions(+), 1 deletion(-)drivers/pwm/pwm-sun4i.c +0
-0drivers/pwm/pwm-sun4i.c line 9
Quoted 7 lines
drivers/pwm/pwm-sun4i.c +4
-0@@ -3,6 +3,10 @@* Driver for Allwinner sun4i Pulse Width Modulation Controller * * Copyright (C) 2014 Alexandre Belloni <[email protected]> +* +* Limitations: +* - When outputing the source clock directly, the PWM logic will be bypassed +* and the currently running period is not guaranted to be completed Typo: guaranted -> guaranteed
Quoted 24 lines
drivers/pwm/pwm-sun4i.c +10
-0*/ #include <linux/bitops.h> @@ -73,6 +77,7 @@ static const u32 prescaler_table[] = {struct sun4i_pwm_data {bool has_prescaler_bypass; +bool has_direct_mod_clk_output;unsigned int npwm; };@@ -118,6 +123,20 @@ static void sun4i_pwm_get_state(struct pwm_chip *chip, val =sun4i_pwm_readl (sun4i_pwm,PWM_CTRL_REG ); +/* +* PWM chapter in H6 manual has a diagram which explains that if bypass +* bit is set, no other setting has any meaning. Even more, experiment +* proved that also enable bit is ignored in this case. +*/ +if ((val &BIT_CH (PWM_BYPASS , pwm->hwpwm)) && + data->has_direct_mod_clk_output) { + state->period =DIV_ROUND_CLOSEST_ULL (NSEC_PER_SEC , clk_rate); + state->duty_cycle = state->period /2 ;Quoted 8 lines
drivers/pwm/pwm-sun4i.c static void sun4i_pwm_get_state(struct pwm_chip *chip, · line 138
Quoted 4 lines
drivers/pwm/pwm-sun4i.c +4
-0+ state->polarity =PWM_POLARITY_NORMAL ; + state->enabled = true; +return ; + }Not sure how the rest of
sun4i_pwm_get_statebehaves, but I would prefer to let .get_state() round up which together with .apply_state() rounding down yields sound behaviour.Ok
Quoted 33 lines
Quoted 18 lines
drivers/pwm/pwm-sun4i.c +3
-1+if ((PWM_REG_PRESCAL (val, pwm->hwpwm) ==PWM_PRESCAL_MASK ) && sun4i_pwm->data->has_prescaler_bypass) prescaler =1 ;@@ -203,7 +222,8 @@ static int sun4i_pwm_apply(struct pwm_chip *chip, struct pwm_device *pwm, {struct sun4i_pwm_chip *sun4i_pwm =to_sun4i_pwm_chip (chip);struct pwm_state cstate; -u32 ctrl; +u32 ctrl, clk_rate; +bool bypass;int ret;unsigned int delay_us;unsigned long now;@@ -218,6 +238,16 @@ static int sun4i_pwm_apply(struct pwm_chip *chip, struct pwm_device *pwm, } }drivers/pwm/pwm-sun4i.c static int sun4i_pwm_apply(struct pwm_chip *chip, struct pwm_device *pwm, · line 249
Quoted 10 lines
drivers/pwm/pwm-sun4i.c +9
-0+/* +* Although it would make much more sense to check for bypass in +* sun4i_pwm_calculate(), value of bypass bit also depends on "enabled". +* Period is allowed to be rounded up or down. +*/ + clk_rate =clk_get_rate (sun4i_pwm->clk); + bypass = ((state->period * clk_rate >=NSEC_PER_SEC && + state->period * clk_rate <NSEC_PER_SEC + clk_rate) && + state->enabled);I guess the compiler is smart enough here, but checking for
state->enabledis cheaper than the other checks, so putting this at the start of the expression seems sensible.Quoted 6 lines
The comment doesn't match the code. You don't round up
state->period. (This is good, please fix the comment.) I think dropping the checkstate->period * clk_rate < NSEC_PER_SEC + clk_ratewould be fine, too.
Ok
Quoted 3 lines
I'd like to have a check for
Quoted 8 lines
Quoted 5 lines
state->duty_cycle * clk_rate >= NSEC_PER_SEC / 2 && state->duty_cycle * clk_rate < NSEC_PER_SEChere. If this isn't true rather disable the PWM or output a 100% duty cycle with a larger period.
Why not just having the
duty_cycleis 50% only ?state->duty_cycle* 2 ==state->period;
Yeah, for the bypass case you can only provide a 50% duty cycle. The problem you have to address is that you cannot rely on your consumer to request only 50% duty cycles. So you have to implement some behaviour if your consumer requests period = 1 / clk_rate and 20% duty cycle.
Where I want to get the pwm framework as a whole is to let lowlevel drivers round down both duty_cycle and period to the next possible values in their .apply callback to be able to provide a more uniform behaviour for consumers. So here this would mean:
- 1 / clk_rate <= state->period < smallest value without bypass && 0 <= state->duty_cycle < state->period / 2
=> provide a constant 0
- 1 / clk_rate <= state->period < smallest value without bypass && state->period / 2 <= state->duty_cycle < state->period => use bypass mode providing 50% duty cycle
- 1 / clk_rate <= state->period < smallest value without bypass && state->period == state->duty_cycle
=> provide a constant 1
Best regards
Uwe
Signature · 2 lines
Pengutronix e.K. | Uwe Kleine-König | Industrial Linux Solutions | http://www.pengutronix.de/ |
Re: [PATCH v2 4/7] pwm: sun4i: Add support to output source clock directly
Hi Uwe,
Quoted 125 lines · Uwe Kleine-König
Hi Clément,
Quoted 121 lines · Clément Péron
Quoted 60 lines · Uwe Kleine-König
Quoted 11 lines · Clément Péron
From: Jernej Skrabec <[email protected]>
PWM core has an option to bypass whole logic and output unchanged source clock as PWM output. This is achieved by enabling bypass bit.
Note that when bypass is enabled, no other setting has any meaning, not even enable bit.
This mode of operation is needed to achieve high enough frequency to serve as clock source for AC200 chip, which is integrated into same package as H6 SoC.
I think the , should be dropped.
Quoted 11 lines
Signed-off-by Jernej Skrabec <[email protected]>Signed-off-by Clément Péron <[email protected]>--- drivers/pwm/pwm-sun4i.c | 39 ++++++++++++++++++++++++++++++++++++++- 1 file changed, 38 insertions(+), 1 deletion(-)drivers/pwm/pwm-sun4i.c +0
-0drivers/pwm/pwm-sun4i.c line 9
Quoted 7 lines
drivers/pwm/pwm-sun4i.c +4
-0@@ -3,6 +3,10 @@* Driver for Allwinner sun4i Pulse Width Modulation Controller * * Copyright (C) 2014 Alexandre Belloni <[email protected]> +* +* Limitations: +* - When outputing the source clock directly, the PWM logic will be bypassed +* and the currently running period is not guaranted to be completed Typo: guaranted -> guaranteed
Quoted 24 lines
drivers/pwm/pwm-sun4i.c +10
-0*/ #include <linux/bitops.h> @@ -73,6 +77,7 @@ static const u32 prescaler_table[] = {struct sun4i_pwm_data {bool has_prescaler_bypass; +bool has_direct_mod_clk_output;unsigned int npwm; };@@ -118,6 +123,20 @@ static void sun4i_pwm_get_state(struct pwm_chip *chip, val =sun4i_pwm_readl (sun4i_pwm,PWM_CTRL_REG ); +/* +* PWM chapter in H6 manual has a diagram which explains that if bypass +* bit is set, no other setting has any meaning. Even more, experiment +* proved that also enable bit is ignored in this case. +*/ +if ((val &BIT_CH (PWM_BYPASS , pwm->hwpwm)) && + data->has_direct_mod_clk_output) { + state->period =DIV_ROUND_CLOSEST_ULL (NSEC_PER_SEC , clk_rate); + state->duty_cycle = state->period /2 ;Quoted 8 lines
drivers/pwm/pwm-sun4i.c static void sun4i_pwm_get_state(struct pwm_chip *chip, · line 138
Quoted 4 lines
drivers/pwm/pwm-sun4i.c +4
-0+ state->polarity =PWM_POLARITY_NORMAL ; + state->enabled = true; +return ; + }Not sure how the rest of
sun4i_pwm_get_statebehaves, but I would prefer to let .get_state() round up which together with .apply_state() rounding down yields sound behaviour.Ok
Quoted 33 lines
Quoted 18 lines
drivers/pwm/pwm-sun4i.c +3
-1+if ((PWM_REG_PRESCAL (val, pwm->hwpwm) ==PWM_PRESCAL_MASK ) && sun4i_pwm->data->has_prescaler_bypass) prescaler =1 ;@@ -203,7 +222,8 @@ static int sun4i_pwm_apply(struct pwm_chip *chip, struct pwm_device *pwm, {struct sun4i_pwm_chip *sun4i_pwm =to_sun4i_pwm_chip (chip);struct pwm_state cstate; -u32 ctrl; +u32 ctrl, clk_rate; +bool bypass;int ret;unsigned int delay_us;unsigned long now;@@ -218,6 +238,16 @@ static int sun4i_pwm_apply(struct pwm_chip *chip, struct pwm_device *pwm, } }drivers/pwm/pwm-sun4i.c static int sun4i_pwm_apply(struct pwm_chip *chip, struct pwm_device *pwm, · line 249
Quoted 10 lines
drivers/pwm/pwm-sun4i.c +9
-0+/* +* Although it would make much more sense to check for bypass in +* sun4i_pwm_calculate(), value of bypass bit also depends on "enabled". +* Period is allowed to be rounded up or down. +*/ + clk_rate =clk_get_rate (sun4i_pwm->clk); + bypass = ((state->period * clk_rate >=NSEC_PER_SEC && + state->period * clk_rate <NSEC_PER_SEC + clk_rate) && + state->enabled);I guess the compiler is smart enough here, but checking for
state->enabledis cheaper than the other checks, so putting this at the start of the expression seems sensible.Quoted 6 lines
The comment doesn't match the code. You don't round up
state->period. (This is good, please fix the comment.) I think dropping the checkstate->period * clk_rate < NSEC_PER_SEC + clk_ratewould be fine, too.
Ok
Quoted 8 lines
I'd like to have a check for
state->duty_cycle * clk_rate >= NSEC_PER_SEC / 2 && state->duty_cycle * clk_rate < NSEC_PER_SEChere. If this isn't true rather disable the PWM or output a 100% duty cycle with a larger period.
Quoted 7 lines
Quoted 2 lines
Why not just having the
duty_cycleis 50% only ?state->duty_cycle* 2 ==state->period;Yeah, for the bypass case you can only provide a 50% duty cycle. The problem you have to address is that you cannot rely on your consumer to request only 50% duty cycles. So you have to implement some behaviour if your consumer requests period = 1 /
clk_rateand 20% duty cycle.
So you request to add a new patch in this series for fixing the actual PWM behavior at corner case?
This series just want to add a new device and a new bypass functionality and I can't measure the output of PWM and testing it properly.
Can this be done in another patch/series ?
Regards,
Clément
Quoted 18 lines
Where I want to get the pwm framework as a whole is to let lowlevel drivers round down both
duty_cycleand period to the next possible values in their .apply callback to be able to provide a more uniform behaviour for consumers. So here this would mean:- 1 /
clk_rate<=state->period< smallest value without bypass && 0 <=state->duty_cycle<state->period/ 2
=> provide a constant 0- 1 /
clk_rate<=state->period< smallest value without bypass &&state->period/ 2 <=state->duty_cycle<state->period=> use bypass mode providing 50% duty cycle- 1 /
clk_rate<=state->period< smallest value without bypass &&state->period==state->duty_cycle
=> provide a constant 1
Quoted 6 lines
Best regards
Uwe--
Pengutronix e.K. | Uwe Kleine-König |
Industrial Linux Solutions | http://www.pengutronix.de/ |
_______________________________________________
linux-arm-kernel mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel
Re: [PATCH v2 4/7] pwm: sun4i: Add support to output source clock directly
Hello Clément,
Quoted 4 lines · Clément Péron
This series just want to add a new device and a new bypass functionality and I can't measure the output of PWM and testing it properly.
Can this be done in another patch/series ?
I'm fine if you implement the bypass stuff with this logic and keep the other stuff as is.
Best regards
Uwe
Signature · 2 lines
Pengutronix e.K. | Uwe Kleine-König | Industrial Linux Solutions | http://www.pengutronix.de/ |
Re: [PATCH v2 4/7] pwm: sun4i: Add support to output source clock directly
Quoted 11 lines · Uwe Kleine-König
Hello Clément,
Quoted 4 lines · Clément Péron
This series just want to add a new device and a new bypass functionality and I can't measure the output of PWM and testing it properly.
Can this be done in another patch/series ?I'm fine if you implement the bypass stuff with this logic and keep the other stuff as is.
Thanks,
Clément
Quoted 7 lines
Best regards
Uwe--
Pengutronix e.K. | Uwe Kleine-König |
Industrial Linux Solutions | http://www.pengutronix.de/ |
PATCH v2 5/7 pwm: sun4i: Add support for H6 PWM
In reply to Clément PéronFrom: Jernej Skrabec <[email protected]>
Now that sun4i PWM driver supports deasserting reset line and enabling bus clock, support for H6 PWM can be added.
Note that while H6 PWM has two channels, only first one is wired to output pin. Second channel is used as a clock source to companion AC200 chip which is bundled into same package.
--- drivers/pwm/pwm-sun4i.c | 9 +++++++++ 1 file changed, 9 insertions(+)
drivers/pwm/pwm-sun4i.c +9 -0
@@ -360,6 +360,12 @@ static const struct sun4i_pwm_data sun4i_pwm_single_bypass = { .npwm = 1, }; +static const struct sun4i_pwm_data sun50i_h6_pwm_data = { + .has_prescaler_bypass = true, + .has_direct_mod_clk_output = true, + .npwm =2 , +}; +static const struct of_device_id sun4i_pwm_dt_ids[] = { { .compatible ="allwinner,sun4i-a10-pwm" ,
@@ -376,6 +382,9 @@ static const struct of_device_id sun4i_pwm_dt_ids[] = { }, { .compatible = "allwinner,sun8i-h3-pwm", .data = &sun4i_pwm_single_bypass, + }, { + .compatible = "allwinner,sun50i-h6-pwm", + .data = &sun50i_h6_pwm_data, }, { /* sentinel */ },
Signature · 1 line
2.20.1
PATCH v2 6/7 arm64: dts: allwinner: h6: Add PWM node
In reply to Clément PéronFrom: Jernej Skrabec <[email protected]>
Allwinner H6 PWM is similar to that in A20 except that it has additional bus clock and reset line.
Note that first PWM channel is connected to output pin and second channel is used internally, as a clock source to AC200 co-packaged chip. This means that any combination of these two channels can be used and thus it doesn't make sense to add pinctrl nodes at this point.
--- arch/arm64/boot/dts/allwinner/sun50i-h6.dtsi | 10 ++++++++++ 1 file changed, 10 insertions(+)
arch/arm64/boot/dts/allwinner/sun50i-h6.dtsi +10 -0
@@ -222,6 +222,16 @@ status = "disabled"; }; + pwm: pwm@300a000 { + compatible = "allwinner,sun50i-h6-pwm"; + reg = <0x0300a000 0x400>; + clocks = <&osc24M>, <&ccu CLK_BUS_PWM>; + clock-names = "mod", "bus"; + resets = <&ccu RST_BUS_PWM>; + #pwm-cells = <3>; + status = "disabled"; + }; + pio: pinctrl@300b000 { compatible = "allwinner,sun50i-h6-pinctrl"; reg = <0x0300b000 0x400>;
Signature · 1 line
2.20.1
PATCH v2 7/7 arm64: allwinner: h6: enable Beelink GS1 PWM
In reply to Clément Péron--- arch/arm64/boot/dts/allwinner/sun50i-h6-beelink-gs1.dts | 4 ++++ 1 file changed, 4 insertions(+)
arch/arm64/boot/dts/allwinner/sun50i-h6-beelink-gs1.dts +4 -0
@@ -131,6 +131,10 @@ vcc-pg-supply = <®_aldo1>; }; +&pwm { + status = "okay"; +}; + &r_i2c { status = "okay";
Signature · 1 line
2.20.1