PWM: PXA: add device tree support to PWM driver
Subsystems (2)
PATCH v4 1/1 PWM: PXA: add device tree support to PWM driver
This patch adds device tree support to the PXA's PWM driver. Only an OF match table is added; nothing needs to be extracted from the device tree node. The existing ID table is reused for the match table data.
Tested on a Palm Treo 680 (both platform data and DT cases).
---
Thanks Stephen for the reviews and explanations.
Changle log:
v4:
- add second "compatible" string to pxa27x.dtsi
- change phrasing in binding doc pxa-pwm.txt to "one or more of"
v3:
- remove support for the polarity flag
- remove per-chip pwm index cell; define custom of_xlate() (now #pwm-cells = <1>)
- "compatible" strings for all devices added to OF match table
- various stylistic changes recommended by reviewers
v2:
- of_match_table contains only the "pxa250-pwm" compatible string; require one device instance per pwm
- add Documentation/devicetree/bindings/pwm/pxa-pwm.txt
- add support for polarity flag in DT and implement set_polarity() method (the treo 680 inverts the signal between pwm out and backlight)
- return -EINVAL instead of -ENODEV if platform data or DT node not found
- output dev_info string if platform data missing
- expanded CC list of patch
Documentation/devicetree/bindings/pwm/pxa-pwm.txt | 31 ++++++++++++ arch/arm/boot/dts/pxa27x.dtsi | 24 +++++++++ drivers/pwm/pwm-pxa.c | 62 +++++++++++++++++++++++ 3 files changed, 117 insertions(+) create mode 100644 Documentation/devicetree/bindings/pwm/pxa-pwm.txt
Documentation/devicetree/bindings/pwm/pxa-pwm.txt new file +31 -0
@@ -0,0 +1,31 @@ +Marvell PWM controller + +Required properties: +- compatible: should be one or more of: + - "marvell,pxa250-pwm" + - "marvell,pxa270-pwm" + - "marvell,pxa168-pwm" + - "marvell,pxa910-pwm" +- reg: physical base address and length of the registers used by the PWM channel + NB: One device instance must be created for each PWM that is used, so the + length covers only the register window for one PWM output, not that of the + entire PWM controller. Currently length is 0x10 for all supported devices. +- #pwm-cells: should be 1. This cell is used to specify the period in + nanoseconds. (Because one device instance is created for each PWM output, + the per-chip index is superflous and not used.) + +Example PWM device node: + +pwm0: pwm at 40b00000 { + compatible = "marvell,pxa250-pwm"; + reg = <0x40b00000 0x10>; + #pwm-cells = <1>; +}; + +Example PWM client node: + +backlight { + compatible = "pwm-backlight"; + pwms = <&pwm0 5000000>; + ... +}
arch/arm/boot/dts/pxa27x.dtsi +24 -0
@@ -10,5 +10,29 @@ marvell,intc-priority; marvell,intc-nr-irqs = <34>; }; + + pwm0: pwm at 40b00000 { + compatible = "marvell,pxa270-pwm", "marvell,pxa250-pwm"; + reg = <0x40b00000 0x10>; + #pwm-cells = <1>; + }; + + pwm1: pwm at 40b00010 { + compatible = "marvell,pxa270-pwm", "marvell,pxa250-pwm"; + reg = <0x40b00010 0x10>; + #pwm-cells = <1>; + }; + + pwm2: pwm at 40c00000 { + compatible = "marvell,pxa270-pwm", "marvell,pxa250-pwm"; + reg = <0x40c00000 0x10>; + #pwm-cells = <1>; + }; + + pwm3: pwm at 40c00010 { + compatible = "marvell,pxa270-pwm", "marvell,pxa250-pwm"; + reg = <0x40c00010 0x10>; + #pwm-cells = <1>; + }; }; };
drivers/pwm/pwm-pxa.c +62 -0
92 lines not on this page · raw message
Signature · 1 line
1.8.1.5
PATCH v4 1/1 PWM: PXA: add device tree support to PWM driver
On Wed, Sep 18, 2013 at 08:59:42AM -0700, Mike Dunn wrote:
[...]
Quoted 1 line
Only an OF match table is added;
[...]
That's no longer true. You also add a custom .of_xlate() function.
Quoted 1 line
Documentation/devicetree/bindings/pwm/pxa-pwm.txt +0
-0
[...]
Documentation/devicetree/bindings/pwm/pxa-pwm.txt line 10
Quoted 8 lines
Documentation/devicetree/bindings/pwm/pxa-pwm.txt +8
-0+Required properties: +- compatible: should be one or more of: + - "marvell,pxa250-pwm" + - "marvell,pxa270-pwm" + - "marvell,pxa168-pwm" + - "marvell,pxa910-pwm" +- reg: physical base address and length of the registers used by the PWM channel + NB: One device instance must be created for each PWM that is used, so the
Nit: "NB:" looks like it starts a new property. Perhaps something like:
"Note that one device node must be present for each PWM ..."
would be less confusing to the eye.
Documentation/devicetree/bindings/pwm/pxa-pwm.txt line 12
Quoted 2 lines
Documentation/devicetree/bindings/pwm/pxa-pwm.txt +2
-0+ length covers only the register window for one PWM output, not that of the + entire PWM controller. Currently length is 0x10 for all supported devices.
So that again confuses me. If the controller really is one or two PWM channels, and four PWM channels, as given in the pxa27x.dtsi, are in fact two controllers (not four) then I wonder if this really is the correct binding for it.
That said, Stephen seems to be okay with it, and I'll yield to his authority on the matter.
Quoted 1 line
+- #pwm-cells: should be 1. This cell is used to specify the period in
Nit: "Should be 1." It's a sentence and therefore should start with a capital letter.
Documentation/devicetree/bindings/pwm/pxa-pwm.txt line 15
Quoted 2 lines
Documentation/devicetree/bindings/pwm/pxa-pwm.txt +2
-0+ nanoseconds. (Because one device instance is created for each PWM output, + the per-chip index is superflous and not used.)
I'd omit the parentheses (and their content). The description of the cell is plenty specific about what it should contain. No need to list what it shouldn't contain.
arch/arm/boot/dts/pxa27x.dtsi
Quoted 1 line
arch/arm/boot/dts/pxa27x.dtsi +0
-0
I think this belongs in a separate patch so it can go through the arm-soc tree.
Quoted 1 line
drivers/pwm/pwm-pxa.c +0
-0
[...]
Quoted 11 lines
drivers/pwm/pwm-pxa.c +11
-0+#ifdef CONFIG_OF +/* +* Device tree users must create one device instance for each pwm channel. +* Hence we dispense with the HAS_SECONDARY_PWM and "tell" the original driver +* code that this is a single channel pxa25x-pwm. Currently all devices are +* supported identically. +*/ +static struct of_device_id pwm_of_match[] = { + { .compatible ="marvell,pxa250-pwm" , .data = &pwm_id_table[0 ]}, + { .compatible ="marvell,pxa270-pwm" , .data = &pwm_id_table[0 ]}, + { .compatible = "marvell,pxa168-pwm", .data = &pwm_id_table[0]},
drivers/pwm/pwm-pxa.c static struct pwm_ops pxa_pwm_ops = { · line 148
Quoted 10 lines
drivers/pwm/pwm-pxa.c +10
-0+ { .compatible = "marvell,pxa910-pwm", .data = &pwm_id_table[0]}, + { } +}; +MODULE_DEVICE_TABLE (of, pwm_of_match); + +static const struct platform_device_id *pxa_pwm_get_id_dt (struct device *dev) +{ +const struct of_device_id *id =of_match_device (pwm_of_match, dev); +if (id) +return (const struct platform_device_id *)id->data;
Is that cast really necessary? id->data is const void *, so shouldn't need a cast.
drivers/pwm/pwm-pxa.c
Quoted 2 lines
drivers/pwm/pwm-pxa.c +2
-0+else +return NULL ;
Perhaps "return id ? id->data : NULL;"?
drivers/pwm/pwm-pxa.c
Quoted 2 lines
drivers/pwm/pwm-pxa.c +2
-0+struct pwm_device * +pxa_pwm_of_xlate (struct pwm_chip *pc,const struct of_phandle_args *args)
Should be static.
drivers/pwm/pwm-pxa.c static struct pwm_ops pxa_pwm_ops = { · line 157
Quoted 3 lines
drivers/pwm/pwm-pxa.c +3
-0+{ +struct pwm_device *pwm; +
You probably want to check that pc->of_pwm_n_cells at least 1 here.
Quoted 12 lines
drivers/pwm/pwm-pxa.c +12
-0+ pwm =pwm_request_from_chip (pc,0 ,NULL ); +if (IS_ERR (pwm)) +return pwm; + +pwm_set_period (pwm, args->args[0 ]); + + return pwm; +} + +#else /* !CONFIG_OF */ +static const struct platform_device_id *pxa_pwm_get_id_dt (struct device *dev) +{
drivers/pwm/pwm-pxa.c static struct pwm_ops pxa_pwm_ops = { · line 179
Quoted 10 lines
drivers/pwm/pwm-pxa.c +10
-0+dev_err (dev,"missing platform data\n" ); + return NULL; +} + +struct pwm_device * +pxa_pwm_of_xlate (struct pwm_chip *pc,const struct of_phandle_args *args) +{ +return NULL ; +} +#endif
I prefer not to have these dummy implementations for static functions. See below...
drivers/pwm/pwm-pxa.c static int pwm_probe(struct platform_device *pdev) · line 189
Quoted 9 lines
static int
pwm_probe(struct platform_device *pdev){drivers/pwm/pwm-pxa.c +2
-0const struct platform_device_id *id =platform_get_device_id (pdev);@@ -131,6 +185,11 @@ static int pwm_probe(struct platform_device *pdev)struct resource *r;int ret =0 ; +if (id ==NULL )/* using device tree */ + id =pxa_pwm_get_id_dt (&pdev->dev);
This could be replaced with:
if (IS_ENABLED(CONFIG_OF) && id == NULL) id = pxa_pwm_get_id_dt(&pdev->dev);
And pxa_pwm_get_id_dt() can be unconditionally defined. The compiler will automatically remove it for !OF because it is never used. Also the comment can then be dropped since the code is already explicit.
drivers/pwm/pwm-pxa.c static int pwm_probe(struct platform_device *pdev) · line 208
Quoted 9 lines
drivers/pwm/pwm-pxa.c +2
-0pwm =devm_kzalloc (&pdev->dev,sizeof (*pwm),GFP_KERNEL );if (pwm ==NULL ) {dev_err (&pdev->dev,"failed to allocate memory\n" );@@ -145,6 +204,8 @@ static int pwm_probe(struct platform_device *pdev) pwm->chip.ops = &pxa_pwm_ops; pwm->chip.base =-1 ; pwm->chip.npwm = (id->driver_data &HAS_SECONDARY_PWM ) ?2 :1 ; + pwm->chip.of_xlate = pxa_pwm_of_xlate; + pwm->chip.of_pwm_n_cells =1 ;
Similarly if you write this as:
if (IS_ENABLED(CONFIG_OF)) {
pwm->chip.of_xlate = pxa_pwm_of_xlate;
pwm->chip.of_pwm_n_cells = 1;
}Then the only thing that needs #ifdef CONFIG_OF protection will be the OF match table.
Thierry
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 836 bytes
Desc: not available
URL: <http://lists.infradead.org/pipermail/linux-arm-kernel/attachments/20130919/d80723d9/attachment-0001.sig>
PATCH v4 1/1 PWM: PXA: add device tree support to PWM driver
Quoted 6 lines · Thierry Reding
On Wed, Sep 18, 2013 at 08:59:42AM -0700, Mike Dunn wrote:
[...]Quoted 1 line
Only an OF match table is added;
[...]
That's no longer true. You also add a custom .of_xlate() function.
Is it acceptable to re-word the commit message in susbequent versions?
Quoted 12 lines
Quoted 2 lines
Documentation/devicetree/bindings/pwm/pxa-pwm.txt +0
-0[...]
Documentation/devicetree/bindings/pwm/pxa-pwm.txt line 10
Quoted 8 lines
Documentation/devicetree/bindings/pwm/pxa-pwm.txt +8
-0+Required properties: +- compatible: should be one or more of: + - "marvell,pxa250-pwm" + - "marvell,pxa270-pwm" + - "marvell,pxa168-pwm" + - "marvell,pxa910-pwm" +- reg: physical base address and length of the registers used by the PWM channel + NB: One device instance must be created for each PWM that is used, so the
Quoted 5 lines
Nit: "NB:" looks like it starts a new property. Perhaps something like:
"Note that one device node must be present for each PWM ..."
would be less confusing to the eye.
Yes, good point. I like clarity myself.
Quoted 9 lines
Documentation/devicetree/bindings/pwm/pxa-pwm.txt line 12
Quoted 3 lines
Documentation/devicetree/bindings/pwm/pxa-pwm.txt +2
-0+ length covers only the register window for one PWM output, not that of the + entire PWM controller. Currently length is 0x10 for all supported devices.So that again confuses me. If the controller really is one or two PWM channels, and four PWM channels, as given in the
pxa27x.dtsi, are in fact two controllers (not four) then I wonder if this really is the correct binding for it.
Quoted 7 lines
That said, Stephen seems to be okay with it, and I'll yield to his authority on the matter.
Quoted 1 line
+- #pwm-cells: should be 1. This cell is used to specify the period in
Nit: "Should be 1." It's a sentence and therefore should start with a capital letter.
OK
Quoted 7 lines
Documentation/devicetree/bindings/pwm/pxa-pwm.txt line 15
Quoted 3 lines
Documentation/devicetree/bindings/pwm/pxa-pwm.txt +2
-0+ nanoseconds. (Because one device instance is created for each PWM output, + the per-chip index is superflous and not used.)I'd omit the parentheses (and their content). The description of the cell is plenty specific about what it should contain. No need to list what it shouldn't contain.
OK.
Quoted 5 lines
arch/arm/boot/dts/pxa27x.dtsi
Quoted 2 lines
arch/arm/boot/dts/pxa27x.dtsi +0
-0I think this belongs in a separate patch so it can go through the arm-soc tree.
Is there anyone else or another list that should be CC'd in this case? Thanks.
Quoted 19 lines
Quoted 2 lines
drivers/pwm/pwm-pxa.c +0
-0[...]
Quoted 16 lines
drivers/pwm/pwm-pxa.c +16
-0+#ifdef CONFIG_OF +/* +* Device tree users must create one device instance for each pwm channel. +* Hence we dispense with the HAS_SECONDARY_PWM and "tell" the original driver +* code that this is a single channel pxa25x-pwm. Currently all devices are +* supported identically. +*/ +static struct of_device_id pwm_of_match[] = { + { .compatible ="marvell,pxa250-pwm" , .data = &pwm_id_table[0 ]}, + { .compatible ="marvell,pxa270-pwm" , .data = &pwm_id_table[0 ]}, + { .compatible ="marvell,pxa168-pwm" , .data = &pwm_id_table[0 ]}, + { .compatible ="marvell,pxa910-pwm" , .data = &pwm_id_table[0 ]}, + { } +}; +MODULE_DEVICE_TABLE (of, pwm_of_match); +
Quoted 8 lines
drivers/pwm/pwm-pxa.c static struct pwm_ops pxa_pwm_ops = { · line 148
Quoted 5 lines
drivers/pwm/pwm-pxa.c +5
-0+static const struct platform_device_id *pxa_pwm_get_id_dt (struct device *dev) +{ +const struct of_device_id *id =of_match_device (pwm_of_match, dev); +if (id) +return (const struct platform_device_id *)id->data;Is that cast really necessary?
id->datais const void *, so shouldn't need a cast.
You're right.
Quoted 5 lines
drivers/pwm/pwm-pxa.c
Quoted 3 lines
drivers/pwm/pwm-pxa.c +2
-0+else +return NULL ;Perhaps "return id ?
id->data: NULL;"?
OK
Quoted 5 lines
drivers/pwm/pwm-pxa.c
Quoted 3 lines
drivers/pwm/pwm-pxa.c +2
-0+struct pwm_device * +pxa_pwm_of_xlate (struct pwm_chip *pc,const struct of_phandle_args *args)Should be static.
Oops, yes.
Quoted 6 lines
drivers/pwm/pwm-pxa.c static struct pwm_ops pxa_pwm_ops = { · line 157
Quoted 4 lines
drivers/pwm/pwm-pxa.c +3
-0+{ +struct pwm_device *pwm; +You probably want to check that
pc->of_pwm_n_cellsat least 1 here.
Well OK, but I didn't bother because it's explicitly set to one elsewhere in this source file.
Quoted 58 lines
Quoted 13 lines
drivers/pwm/pwm-pxa.c +12
-0+ pwm =pwm_request_from_chip (pc,0 ,NULL ); +if (IS_ERR (pwm)) +return pwm; + +pwm_set_period (pwm, args->args[0 ]); + + return pwm; +} + +#else /* !CONFIG_OF */ +static const struct platform_device_id *pxa_pwm_get_id_dt (struct device *dev) +{drivers/pwm/pwm-pxa.c static struct pwm_ops pxa_pwm_ops = { · line 179
Quoted 10 lines
drivers/pwm/pwm-pxa.c +10
-0+dev_err (dev,"missing platform data\n" ); + return NULL; +} + +struct pwm_device * +pxa_pwm_of_xlate (struct pwm_chip *pc,const struct of_phandle_args *args) +{ +return NULL ; +} +#endif I prefer not to have these dummy implementations for static functions. See below...
drivers/pwm/pwm-pxa.c static int pwm_probe(struct platform_device *pdev) · line 189
Quoted 9 lines
static int
pwm_probe(struct platform_device *pdev){drivers/pwm/pwm-pxa.c +2
-0const struct platform_device_id *id =platform_get_device_id (pdev);@@ -131,6 +185,11 @@ static int pwm_probe(struct platform_device *pdev)struct resource *r;int ret =0 ; +if (id ==NULL )/* using device tree */ + id =pxa_pwm_get_id_dt (&pdev->dev);This could be replaced with:
if (IS_ENABLED(CONFIG_OF) && id == NULL) id = pxa_pwm_get_id_dt(&pdev->dev);And
pxa_pwm_get_id_dt()can be unconditionally defined. The compiler will automatically remove it for !OF because it is never used. Also the comment can then be dropped since the code is already explicit.drivers/pwm/pwm-pxa.c static int pwm_probe(struct platform_device *pdev) · line 208
Quoted 9 lines
drivers/pwm/pwm-pxa.c +2
-0pwm =devm_kzalloc (&pdev->dev,sizeof (*pwm),GFP_KERNEL );if (pwm ==NULL ) {dev_err (&pdev->dev,"failed to allocate memory\n" );@@ -145,6 +204,8 @@ static int pwm_probe(struct platform_device *pdev) pwm->chip.ops = &pxa_pwm_ops; pwm->chip.base =-1 ; pwm->chip.npwm = (id->driver_data &HAS_SECONDARY_PWM ) ?2 :1 ; + pwm->chip.of_xlate = pxa_pwm_of_xlate; + pwm->chip.of_pwm_n_cells =1 ;Similarly if you write this as:
Quoted 7 lines
if (IS_ENABLED(CONFIG_OF)) { pwm->chip.of_xlate = pxa_pwm_of_xlate; pwm->chip.of_pwm_n_cells = 1; }Then the only thing that needs #ifdef
CONFIG_OFprotection will be the OF match table.
Yes, much better. Thanks again Thierry.
Mike
PATCH v4 1/1 PWM: PXA: add device tree support to PWM driver
Quoted 10 lines · Mike Dunn
Quoted 6 lines · Thierry Reding
On Wed, Sep 18, 2013 at 08:59:42AM -0700, Mike Dunn wrote:
[...]Quoted 1 line
Only an OF match table is added;
[...]
That's no longer true. You also add a custom .of_xlate() function.
Is it acceptable to re-word the commit message in susbequent versions?
Yes, of course. The commit message should be an accurate description of the patch. If as a result of review the patch changes in ways that make the commit message wrong, then it must be updated as well.
Quoted 7 lines
Quoted 4 lines
arch/arm/boot/dts/pxa27x.dtsi
Quoted 1 line
arch/arm/boot/dts/pxa27x.dtsi +0
-0I think this belongs in a separate patch so it can go through the arm-soc tree.
Is there anyone else or another list that should be CC'd in this case? Thanks.
Well, the PXA maintainers would be the most likely to take the dtsi change through their tree. Usually the mach trees are merged into arm-soc, which then goes into Linus' tree.
Quoted 9 lines
Quoted 5 lines
arch/arm/boot/dts/pxa27x.dtsi
Quoted 3 lines
arch/arm/boot/dts/pxa27x.dtsi +3
-0+{ + struct pwm_device *pwm; +You probably want to check that
pc->of_pwm_n_cellsat least 1 here.Well OK, but I didn't bother because it's explicitly set to one elsewhere in this source file.
Okay, nevermind. It's probably fine as is.
Thierry
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 836 bytes
Desc: not available
URL: <http://lists.infradead.org/pipermail/linux-arm-kernel/attachments/20130920/a168bd46/attachment.sig>