pwm: pxa: add device tree support to pwm driver
Subsystems (2)
PATCH v2 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 platform_device id table is reused for the match table data. Support for inverted polarity is also added.
Tested on a Palm Treo 680 (both platform data and DT cases).
---
Changle log:
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 | 33 +++++++++++++ arch/arm/boot/dts/pxa27x.dtsi | 24 ++++++++++ drivers/pwm/pwm-pxa.c | 57 +++++++++++++++++++++++ 3 files changed, 114 insertions(+) create mode 100644 Documentation/devicetree/bindings/pwm/pxa-pwm.txt
Documentation/devicetree/bindings/pwm/pxa-pwm.txt new file +33 -0
@@ -0,0 +1,33 @@ +Marvell pwm controller + +Required properties: +- compatible: + for pxa25x, pxa27x, pxa168, pxa910: must be compatible = "marvell,pxa250-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 3. + cell 1: the per-chip index of the PWM to use, + cell 2: the period in nanoseconds, + cell 3: flags; set bit 0 to specify inverse polarity. The pwm controller + does not implement reverse polarity, but some boards may pass the pwm output + through an external inverter, which can cause problems if a client device + assumes that an increase in the duty cycle results in an increase in output + power. The pwm-backlight is an example of such a client. + +Example pwm device node: + +pwm0: pwm at 40b00000 { + compatible = "marvell,pxa250-pwm"; + reg = <0x40b00000 0x10>; + #pwm-cells = <3>; +}; + +Example pwm client node: + +backlight { + compatible = "pwm-backlight"; + pwms = <&pwm0 0 5000000 1>; /* pwm output is inverted */ + ... +}
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,pxa250-pwm"; + reg = <0x40b00000 0x10>; + #pwm-cells = <3>; + }; + + pwm1: pwm at 40b00010 { + compatible = "marvell,pxa250-pwm"; + reg = <0x40b00010 0x10>; + #pwm-cells = <3>; + }; + + pwm2: pwm at 40c00000 { + compatible = "marvell,pxa250-pwm"; + reg = <0x40c00000 0x10>; + #pwm-cells = <3>; + }; + + pwm3: pwm at 40c00010 { + compatible = "marvell,pxa250-pwm"; + reg = <0x40c00010 0x10>; + #pwm-cells = <3>; + }; }; };
drivers/pwm/pwm-pxa.c +57 -0
106 lines not on this page · raw message
Signature · 1 line
1.8.1.5
PATCH v2 1/1 pwm: pxa: add device tree support to pwm driver
Dear Mike Dunn,
Quoted 43 lines
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
platform_deviceid table is reused for the match table data. Support for inverted polarity is also added.Tested on a Palm Treo 680 (both platform data and DT cases).
Signed-off-by Mike Dunn <[email protected]>---
Changle log:
v2:
-of_match_tablecontains only the "pxa250-pwm" compatible string; require one device instance per pwm
- addDocumentation/devicetree/bindings/pwm/pxa-pwm.txt
- add support for polarity flag in DT and implementset_polarity()method (the treo 680 inverts the signal between pwm out and backlight)
- return-EINVALinstead of-ENODEVif platform data or DT node not found
- outputdev_infostring if platform data missing
- expanded CC list of patchDocumentation/devicetree/bindings/pwm/pxa-pwm.txt | 33 +++++++++++++ arch/arm/boot/dts/pxa27x.dtsi | 24 ++++++++++ drivers/pwm/pwm-pxa.c | 57 +++++++++++++++++++++++ 3 files changed, 114 insertions(+) create mode 100644 Documentation/devicetree/bindings/pwm/pxa-pwm.txt(quoted diff) +0
-0
b/Documentation/devicetree/bindings/pwm/pxa-pwm.txtnew file mode 100644 index 0000000..7b09bfaDocumentation/devicetree/bindings/pwm/pxa-pwm.txt new file +5
-0@@ -0,0 +1,33 @@ +Marvell pwm controller + +Required properties: +- compatible: + for pxa25x, pxa27x, pxa168, pxa910: must be compatible ="marvell,pxa250-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
0x10for all supported devices. +- #pwm-cells: should be 3.
Documentation/devicetree/bindings/pwm/pxa-pwm.txt line 12
Quoted 2 lines
Documentation/devicetree/bindings/pwm/pxa-pwm.txt new file +2
-0+ cell 1: the per-chip index of the PWM to use, + cell 2: the period in nanoseconds,
Is there no generic OF prop for this?
Quoted 1 line
+ cell 3: flags; set bit 0 to specify inverse polarity.
Do we not have some generic flag to indicate inverted PWM polarity?
[...]
Quoted 6 lines
Documentation/devicetree/bindings/pwm/pxa-pwm.txt new file +3
-0+#ifdef CONFIG_OF +/* + * Device tree users should create one device instance for each pwmchannel. + * Hence we dispense with the
HAS_SECONDARY_PWMand "tell" the original driver + * code that this is a single channel pxa25x-pwm.
+ */
Above ... pxa250-pwm , no ?
Documentation/devicetree/bindings/pwm/pxa-pwm.txt
Quoted 2 lines
Documentation/devicetree/bindings/pwm/pxa-pwm.txt new file +2
-0+static struct of_device_id pwm_of_match[] = { + { .compatible = "marvell,pxa250-pwm", .data = &pwm_id_table[0]},
Surely, data can be NULL, no ?
[...]
Documentation/devicetree/bindings/pwm/pxa-pwm.txt static int pwm_probe(struct platform_device *pdev) · line 203
Quoted 6 lines
Documentation/devicetree/bindings/pwm/pxa-pwm.txt new file +2
-0@@ -145,6 +199,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 = of_pwm_xlate_with_flags; + pwm->chip.of_pwm_n_cells = 3;
Are these two settings needed ?
[...]
Best regards,
Marek Vasut
PATCH v2 1/1 pwm: pxa: add device tree support to pwm driver
Quoted 41 lines · Marek Vasut
Dear Mike Dunn,
Quoted 39 lines
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
platform_deviceid table is reused for the match table data. Support for inverted polarity is also added.Tested on a Palm Treo 680 (both platform data and DT cases).
Signed-off-by Mike Dunn <[email protected]>---
Changle log:
v2:
-of_match_tablecontains only the "pxa250-pwm" compatible string; require one device instance per pwm
- addDocumentation/devicetree/bindings/pwm/pxa-pwm.txt
- add support for polarity flag in DT and implementset_polarity()method (the treo 680 inverts the signal between pwm out and backlight)
- return-EINVALinstead of-ENODEVif platform data or DT node not found
- outputdev_infostring if platform data missing
- expanded CC list of patchDocumentation/devicetree/bindings/pwm/pxa-pwm.txt | 33 +++++++++++++ arch/arm/boot/dts/pxa27x.dtsi | 24 ++++++++++ drivers/pwm/pwm-pxa.c | 57 +++++++++++++++++++++++ 3 files changed, 114 insertions(+) create mode 100644 Documentation/devicetree/bindings/pwm/pxa-pwm.txt(quoted diff) +0
-0
b/Documentation/devicetree/bindings/pwm/pxa-pwm.txtnew file mode 100644 index 0000000..7b09bfaDocumentation/devicetree/bindings/pwm/pxa-pwm.txt new file +5
-0@@ -0,0 +1,33 @@ +Marvell pwm controller + +Required properties: +- compatible: + for pxa25x, pxa27x, pxa168, pxa910: must be compatible ="marvell,pxa250-pwm"; +- reg: physical base address and length of the registers used by the pwm channel + NB: One device instance must be
Quoted 8 lines
Documentation/devicetree/bindings/pwm/pxa-pwm.txt line 12
Quoted 6 lines
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
0x10for all supported devices. +- #pwm-cells: should be 3.Documentation/devicetree/bindings/pwm/pxa-pwm.txt new file +2
-0+ cell 1: the per-chip index of the PWM to use, + cell 2: the period in nanoseconds,Is there no generic OF prop for this?
Yes, all the pwm drivers with DT support have the same definitions for cell 1 and 2. Many have #pwm-cells=2, but for those with #pwm-cells=3, all define cell 3 the same way also.
Quoted 4 lines
Quoted 2 lines
+ cell 3: flags; set bit 0 to specify inverse polarity.
Do we not have some generic flag to indicate inverted PWM polarity?
Yes, enum pwm_polarity, defined in include/linux/pwm.h. The pwm drivers with polarity support all define cell 3 the same way. The wording in the bindings documentation is a little different in each case, but all essentially say the same thing. In Documentation/devicetree/bindings/pwm/ see for example atmel-tcb-pwm.txt and pwm-tiecap.txt.
I'm new to device tree, so maybe I am not understanding correctly this and your previous question... All DT properties are described as integers lacking any type (aside from their bit width), no?
Quoted 12 lines
[...]
Quoted 6 lines
Documentation/devicetree/bindings/pwm/pxa-pwm.txt new file +3
-0+#ifdef CONFIG_OF +/* + * Device tree users should create one device instance for each pwmchannel. + * Hence we dispense with the
HAS_SECONDARY_PWMand "tell" the original driver + * code that this is a single channel pxa25x-pwm.
+ */Above ... pxa250-pwm , no ?
Quoted 4 lines
Documentation/devicetree/bindings/pwm/pxa-pwm.txt
Quoted 2 lines
Documentation/devicetree/bindings/pwm/pxa-pwm.txt new file +2
-0+static struct of_device_id pwm_of_match[] = { + { .compatible = "marvell,pxa250-pwm", .data = &pwm_id_table[0]},Surely, data can be NULL, no ?
It could, in which case pxa_pwm_get_id_dt() would explicitly return &pwm_id_table[0] instead of the .data element of the of_device_id. Not sure which way is better and why. That dumb platform_device_id table is causing all kinds of nuisance :)
Quoted 11 lines
[...]
Documentation/devicetree/bindings/pwm/pxa-pwm.txt static int pwm_probe(struct platform_device *pdev) · line 203
Quoted 6 lines
Documentation/devicetree/bindings/pwm/pxa-pwm.txt new file +2
-0@@ -145,6 +199,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 = of_pwm_xlate_with_flags; + pwm->chip.of_pwm_n_cells = 3;Are these two settings needed ?
Yes. See drivers/pwm/core.c:of_pwmchip_add(), where they are set to default values of of_pwm_simple_xlate and 2 if left uninitialized.
Thanks again Marek,
Mike
PATCH v2 1/1 pwm: pxa: add device tree support to pwm driver
Dear Mike Dunn,
[...]
Quoted 9 lines
Quoted 4 lines
drivers/pwm/pwm-pxa.c static void pxa_pwm_disable(struct pwm_chip *chip, struct pwm_device *pwm) · line 154
Quoted 2 lines
drivers/pwm/pwm-pxa.c +2
-0+static struct of_device_id pwm_of_match[] = { + { .compatible ="marvell,pxa250-pwm" , .data = &pwm_id_table[0 ]},Surely, data can be NULL, no ?
It could, in which case
pxa_pwm_get_id_dt()would explicitly return &pwm_id_table[0] instead of the .data element of theof_device_id. Not sure which way is better and why. That dumbplatform_device_idtable is causing all kinds of nuisance :)
Is the pwm_id_table needed at all anymore?
Quoted 8 lines
Quoted 8 lines
[...]
Quoted 6 lines
drivers/pwm/pwm-pxa.c +0
-0@@ -145,6 +199,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 ;
Quoted 7 lines
Quoted 4 lines
drivers/pwm/pwm-pxa.c static int pwm_probe(struct platform_device *pdev) · line 203
Quoted 2 lines
drivers/pwm/pwm-pxa.c +2
-0+ pwm->chip.of_xlate = of_pwm_xlate_with_flags; + pwm->chip.of_pwm_n_cells =3 ;Are these two settings needed ?
Yes. See drivers/pwm/core.c:of_pwmchip_add(), where they are set to default values of
of_pwm_simple_xlateand 2 if left uninitialized.
OK
Best regards,
Marek Vasut
PATCH v2 1/1 pwm: pxa: add device tree support to pwm driver
Quoted 9 lines · Marek Vasut
Dear Mike Dunn,
[...]
Quoted 5 lines
Quoted 4 lines
drivers/pwm/pwm-pxa.c static void pxa_pwm_disable(struct pwm_chip *chip, struct pwm_device *pwm) · line 154
Quoted 2 lines
drivers/pwm/pwm-pxa.c +2
-0+static struct of_device_id pwm_of_match[] = { + { .compatible ="marvell,pxa250-pwm" , .data = &pwm_id_table[0 ]},Surely, data can be NULL, no ?
Quoted 6 lines
Quoted 4 lines
It could, in which case
pxa_pwm_get_id_dt()would explicitly return &pwm_id_table[0] instead of the .data element of theof_device_id. Not sure which way is better and why. That dumbplatform_device_idtable is causing all kinds of nuisance :)Is the
pwm_id_tableneeded at all anymore?
If the original driver is modified to switch to the one-device-instance-per-pwm approach, it can be removed. But changing the original driver will require changes to all the client device instantiations. Ac case can be made for the change, though. It purports to identify the number of pwms on the processor, but in fact fails at it.
Quoted 14 lines
Quoted 14 lines
Quoted 13 lines
[...]
drivers/pwm/pwm-pxa.c static int pwm_probe(struct platform_device *pdev) · line 205
Quoted 8 lines
drivers/pwm/pwm-pxa.c +2
-0@@ -145,6 +199,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 = of_pwm_xlate_with_flags; + pwm->chip.of_pwm_n_cells =3 ;Are these two settings needed ?
Quoted 5 lines
Quoted 2 lines
Yes. See drivers/pwm/core.c:of_pwmchip_add(), where they are set to default values of
of_pwm_simple_xlateand 2 if left uninitialized.OK
Thanks,
Mike
PATCH v2 1/1 pwm: pxa: add device tree support to pwm driver
In reply to Mike DunnQuoted 1 line · Mike Dunn
This patch adds device tree support to the pxa's pwm driver. Only an OF match
"PXA" and "PWM"
Quoted 2 lines
table is added; nothing needs to be extracted from the device tree node. The existing
platform_deviceid table is reused for the match table data. Support
"ID table"
Quoted 10 lines
Changle log:
v2:
-of_match_tablecontains only the "pxa250-pwm" compatible string; require one device instance per pwm
- addDocumentation/devicetree/bindings/pwm/pxa-pwm.txt
- add support for polarity flag in DT and implementset_polarity()method (the treo 680 inverts the signal between pwm out and backlight)
- return-EINVALinstead of-ENODEVif platform data or DT node not found
- outputdev_infostring if platform data missing
- expanded CC list of patch
I think this needs to be reviewed by the device tree bindings maintainers (as listed in MAINTAINERS) as well. Would you mind resending the patch with all of them on Cc so that they have full context? Thanks.
Quoted 12 lines
Documentation/devicetree/bindings/pwm/pxa-pwm.txt | 33 +++++++++++++ arch/arm/boot/dts/pxa27x.dtsi | 24 ++++++++++ drivers/pwm/pwm-pxa.c | 57 +++++++++++++++++++++++ 3 files changed, 114 insertions(+) create mode 100644 Documentation/devicetree/bindings/pwm/pxa-pwm.txtDocumentation/devicetree/bindings/pwm/pxa-pwm.txt new file +0
-0
Documentation/devicetree/bindings/pwm/pxa-pwm.txt line 6
Quoted 6 lines
Documentation/devicetree/bindings/pwm/pxa-pwm.txt new file +6
-0@@ -0,0 +1,33 @@ +Marvell pwm controller + +Required properties: +- compatible: + for pxa25x, pxa27x, pxa168, pxa910: must be compatible = "marvell,pxa250-pwm"; +- reg: physical base address and length of the registers used by the pwm channel
"pwm" -> "PWM". There are a few more occurrences that I haven't explicitly pointed out.
Documentation/devicetree/bindings/pwm/pxa-pwm.txt line 9
Quoted 3 lines
Documentation/devicetree/bindings/pwm/pxa-pwm.txt new file +3
-0+ 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.
I'm not sure I like that very much. It seems a wrong representation of the hardware for the sake of modifying a smaller number of lines in the driver.
Documentation/devicetree/bindings/pwm/pxa-pwm.txt line 13
Quoted 4 lines
Documentation/devicetree/bindings/pwm/pxa-pwm.txt new file +4
-0+- #pwm-cells: should be 3. + cell 1: the per-chip index of the PWM to use, + cell 2: the period in nanoseconds, + cell 3: flags; set bit 0 to specify inverse polarity. The pwm controller
This is the standard binding, so you can just refer to the standard binding documentation instead, like so:
- #pwm-cells: Should be 2. See pwm.txt in this directory for a description of the cells format.
Documentation/devicetree/bindings/pwm/pxa-pwm.txt line 17
Quoted 4 lines
Documentation/devicetree/bindings/pwm/pxa-pwm.txt new file +4
-0+ does not implement reverse polarity, but some boards may pass the pwm output + through an external inverter, which can cause problems if a client device + assumes that an increase in the duty cycle results in an increase in output + power. The pwm-backlight is an example of such a client.
Please don't do that. Reverse polarity support should not be emulated. Either the hardware supports it or it doesn't. In the above case you should be able to achieve the same effect by adding the correct values in the pwm-backlight device node's brightness-levels property.
Documentation/devicetree/bindings/pwm/pxa-pwm.txt line 32
Quoted 6 lines
Documentation/devicetree/bindings/pwm/pxa-pwm.txt new file +6
-0+Example pwm client node: + +backlight { + compatible = "pwm-backlight"; + pwms = <&pwm0 0 5000000 1>; /* pwm output is inverted */ + ...
The indentation here is funky. You should be using only tabs to indent.
Quoted 6 lines
Documentation/devicetree/bindings/pwm/pxa-pwm.txt new file +6
-0+#ifdef CONFIG_OF +/* + * Device tree users should 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. + */
Documentation/devicetree/bindings/pwm/pxa-pwm.txt
Quoted 10 lines
Documentation/devicetree/bindings/pwm/pxa-pwm.txt new file +10
-0+static struct of_device_id pwm_of_match[] = { + { .compatible = "marvell,pxa250-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 *pwm_pxa_devid = + of_match_device(pwm_of_match, dev);
If you name this variable something much shorter, like "id", this will fit on a single line, and the code below will be slightly more readable as well.
Documentation/devicetree/bindings/pwm/pxa-pwm.txt
Quoted 5 lines
Documentation/devicetree/bindings/pwm/pxa-pwm.txt new file +5
-0+ if (pwm_pxa_devid) + return (const struct platform_device_id *)pwm_pxa_devid->data; + else + return NULL; +}
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/20130909/11a5bcaf/attachment.sig>
PATCH v2 1/1 pwm: pxa: add device tree support to pwm driver
Quoted 4 lines · Thierry Reding
Quoted 1 line · Mike Dunn
This patch adds device tree support to the pxa's pwm driver. Only an OF match
"PXA" and "PWM"
OK. And thank you for the review!
Quoted 5 lines
Quoted 3 lines
table is added; nothing needs to be extracted from the device tree node. The existing
platform_deviceid table is reused for the match table data. Support"ID table"
OK
Quoted 12 lines
Quoted 11 lines
Changle log:
v2:
-of_match_tablecontains only the "pxa250-pwm" compatible string; require one device instance per pwm
- addDocumentation/devicetree/bindings/pwm/pxa-pwm.txt
- add support for polarity flag in DT and implementset_polarity()method (the treo 680 inverts the signal between pwm out and backlight)
- return-EINVALinstead of-ENODEVif platform data or DT node not found
- outputdev_infostring if platform data missing
- expanded CC list of patch
Quoted 3 lines
I think this needs to be reviewed by the device tree bindings maintainers (as listed in
MAINTAINERS) as well. Would you mind resending the patch with all of them on Cc so that they have full context? Thanks.
You bet. Sorry... should have checked that. Adding them to this reply, and will resend original patch.
Quoted 23 lines
Quoted 13 lines
Documentation/devicetree/bindings/pwm/pxa-pwm.txt | 33 +++++++++++++ arch/arm/boot/dts/pxa27x.dtsi | 24 ++++++++++ drivers/pwm/pwm-pxa.c | 57 +++++++++++++++++++++++ 3 files changed, 114 insertions(+) create mode 100644 Documentation/devicetree/bindings/pwm/pxa-pwm.txtDocumentation/devicetree/bindings/pwm/pxa-pwm.txt new file +0
-0Documentation/devicetree/bindings/pwm/pxa-pwm.txt line 6
Quoted 6 lines
Documentation/devicetree/bindings/pwm/pxa-pwm.txt new file +6
-0@@ -0,0 +1,33 @@ +Marvell pwm controller + +Required properties: +- compatible: + for pxa25x, pxa27x, pxa168, pxa910: must be compatible = "marvell,pxa250-pwm"; +- reg: physical base address and length of the registers used by the pwm channel"pwm" -> "PWM". There are a few more occurrences that I haven't explicitly pointed out.
Quoted 7 lines
Documentation/devicetree/bindings/pwm/pxa-pwm.txt line 9
Quoted 3 lines
Documentation/devicetree/bindings/pwm/pxa-pwm.txt new file +3
-0+ 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.I'm not sure I like that very much. It seems a wrong representation of the hardware for the sake of modifying a smaller number of lines in the driver.
I don't like it either, but this is an existing driver defect that will need to be corrected. To do so, I will need to to survey all the supported processors to determine how many pwm outputs is posessed by each. And there may be some confusion in that regard; the driver says "pxa25x" has one, but my pxa255 developer's manual makes no mention of a pwm. The pxa270 I am testing on has four, but the driver says "pxa27x" has two, so currently (using platform_data with existing driver) two devices are instantiated, each with two pwms. It seems that there are many variations within a single generation of the processor family, so to correctly identify the number of pwms, processor identification will have to be made on a finer granularity than the current "pxa25x", for example. I'm guessing that the hardware designers had this one-device-instance-per-pwm approach in mind when they made the decision to segregate the register sets of each pwm. I really hope that this sin can be forgiven :)
Quoted 17 lines
Documentation/devicetree/bindings/pwm/pxa-pwm.txt line 13
Quoted 5 lines
Documentation/devicetree/bindings/pwm/pxa-pwm.txt new file +4
-0+- #pwm-cells: should be 3. + cell 1: the per-chip index of the PWM to use, + cell 2: the period in nanoseconds, + cell 3: flags; set bit 0 to specify inverse polarity. The pwm controllerThis is the standard binding, so you can just refer to the standard binding documentation instead, like so:
- #pwm-cells: Should be 2. See pwm.txt in this directory for a description of the cells format.
Documentation/devicetree/bindings/pwm/pxa-pwm.txt line 17
Quoted 4 lines
Documentation/devicetree/bindings/pwm/pxa-pwm.txt new file +4
-0+ does not implement reverse polarity, but some boards may pass the pwm output + through an external inverter, which can cause problems if a client device + assumes that an increase in the duty cycle results in an increase in output + power. The pwm-backlight is an example of such a client.
Quoted 4 lines
Please don't do that. Reverse polarity support should not be emulated. Either the hardware supports it or it doesn't. In the above case you should be able to achieve the same effect by adding the correct values in the pwm-backlight device node's brightness-levels property.
That was my initial thought too. But sadly, that is not the case. The pwm-backlight driver assumes that the brightness-levels increase when parsed from left to right (more specifically, it assumes the last one is max). If emulated polarity is unacceptable, the pwm-backlight driver will need some rework to be usable in my case. The change looks minor and straightforward at first glance, though.
Quoted 9 lines
Documentation/devicetree/bindings/pwm/pxa-pwm.txt line 32
Quoted 7 lines
Documentation/devicetree/bindings/pwm/pxa-pwm.txt new file +6
-0+Example pwm client node: + +backlight { + compatible = "pwm-backlight"; + pwms = <&pwm0 0 5000000 1>; /* pwm output is inverted */ + ...The indentation here is funky. You should be using only tabs to indent.
OK
Quoted 13 lines
Quoted 13 lines
Documentation/devicetree/bindings/pwm/pxa-pwm.txt new file +12
-0+#ifdef CONFIG_OF +/* + * Device tree users should 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. + */ +static struct of_device_id pwm_of_match[] = { + { .compatible = "marvell,pxa250-pwm", .data = &pwm_id_table[0]}, + { } +}; +MODULE_DEVICE_TABLE(of, pwm_of_match); +
Quoted 8 lines
Documentation/devicetree/bindings/pwm/pxa-pwm.txt
Quoted 4 lines
Documentation/devicetree/bindings/pwm/pxa-pwm.txt new file +4
-0+static const struct platform_device_id *pxa_pwm_get_id_dt(struct device *dev) +{ + const struct of_device_id *pwm_pxa_devid = + of_match_device(pwm_of_match, dev);If you name this variable something much shorter, like "id", this will fit on a single line, and the code below will be slightly more readable as well.
OK. I struggle not to be too verbose :)
Thanks again,
Mike
PATCH v2 1/1 pwm: pxa: add device tree support to pwm driver
Quoted 24 lines · Mike Dunn
Quoted 15 lines · Thierry Reding
Documentation/devicetree/bindings/pwm/pxa-pwm.txt line 6
Quoted 10 lines · Mike Dunn
This patch adds device tree support to the pxa's pwm driver. Only an OF match
Documentation/devicetree/bindings/pwm/pxa-pwm.txt +6
-0+Marvell pwm controller + +Required properties: +- compatible: + for pxa25x, pxa27x, pxa168, pxa910: must be compatible = "marvell,pxa250-pwm"; +- reg: physical base address and length of the registers used by the pwm channel"pwm" -> "PWM". There are a few more occurrences that I haven't explicitly pointed out.
Quoted 7 lines
Documentation/devicetree/bindings/pwm/pxa-pwm.txt line 9
Quoted 3 lines
Documentation/devicetree/bindings/pwm/pxa-pwm.txt +3
-0+ 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.I'm not sure I like that very much. It seems a wrong representation of the hardware for the sake of modifying a smaller number of lines in the driver.
Quoted 14 lines
I don't like it either, but this is an existing driver defect that will need to be corrected. To do so, I will need to to survey all the supported processors to determine how many pwm outputs is posessed by each. And there may be some confusion in that regard; the driver says "pxa25x" has one, but my pxa255 developer's manual makes no mention of a pwm. The pxa270 I am testing on has four, but the driver says "pxa27x" has two, so currently (using
platform_datawith existing driver) two devices are instantiated, each with two pwms. It seems that there are many variations within a single generation of the processor family, so to correctly identify the number of pwms, processor identification will have to be made on a finer granularity than the current "pxa25x", for example. I'm guessing that the hardware designers had this one-device-instance-per-pwm approach in mind when they made the decision to segregate the register sets of each pwm. I really hope that this sin can be forgiven :)
The DT binding is an ABI, so it needs to correctly represent the HW. As such, I'd say that if the binding is wrong, we need to fix it even if it means a lot of work.
That said, if each PWM truly is a *completely* independent block, with non-overlapping register spaces, there's certainly an argument that it's perfectly acceptable to represent each PWM as a separate DT node...
PATCH v2 1/1 pwm: pxa: add device tree support to pwm driver
Quoted 40 lines · Stephen Warren
Quoted 24 lines · Mike Dunn
Quoted 15 lines · Thierry Reding
Documentation/devicetree/bindings/pwm/pxa-pwm.txt line 6
Quoted 10 lines · Mike Dunn
This patch adds device tree support to the pxa's pwm driver. Only an OF match
Documentation/devicetree/bindings/pwm/pxa-pwm.txt +6
-0+Marvell pwm controller + +Required properties: +- compatible: + for pxa25x, pxa27x, pxa168, pxa910: must be compatible = "marvell,pxa250-pwm"; +- reg: physical base address and length of the registers used by the pwm channel"pwm" -> "PWM". There are a few more occurrences that I haven't explicitly pointed out.
Quoted 7 lines
Documentation/devicetree/bindings/pwm/pxa-pwm.txt line 9
Quoted 3 lines
Documentation/devicetree/bindings/pwm/pxa-pwm.txt +3
-0+ 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.I'm not sure I like that very much. It seems a wrong representation of the hardware for the sake of modifying a smaller number of lines in the driver.
Quoted 14 lines
I don't like it either, but this is an existing driver defect that will need to be corrected. To do so, I will need to to survey all the supported processors to determine how many pwm outputs is posessed by each. And there may be some confusion in that regard; the driver says "pxa25x" has one, but my pxa255 developer's manual makes no mention of a pwm. The pxa270 I am testing on has four, but the driver says "pxa27x" has two, so currently (using
platform_datawith existing driver) two devices are instantiated, each with two pwms. It seems that there are many variations within a single generation of the processor family, so to correctly identify the number of pwms, processor identification will have to be made on a finer granularity than the current "pxa25x", for example. I'm guessing that the hardware designers had this one-device-instance-per-pwm approach in mind when they made the decision to segregate the register sets of each pwm. I really hope that this sin can be forgiven :)
Quoted 7 lines
The DT binding is an ABI, so it needs to correctly represent the HW. As such, I'd say that if the binding is wrong, we need to fix it even if it means a lot of work.
That said, if each PWM truly is a *completely* independent block, with non-overlapping register spaces, there's certainly an argument that it's perfectly acceptable to represent each PWM as a separate DT node...
Thanks Stephen. Yes, each pwm output has its own registers with no common control registers. The only commonality is that they all share a clock in the clock unit. But this is handled in the clock manager.
Thanks,
Mike