leds: leds-mc13783: Add devicetree support
Subsystems (3)
PATCH v2 5/5 leds: leds-mc13783: Add devicetree support
This patch adds devicetree support for the MC13XXX LED driver.
--- Documentation/devicetree/bindings/mfd/mc13xxx.txt | 47 ++++++++ drivers/leds/leds-mc13783.c | 134 +++++++++++++++++++--- 2 files changed, 162 insertions(+), 19 deletions(-)
Documentation/devicetree/bindings/mfd/mc13xxx.txt +47 -0
@@ -10,9 +10,44 @@ Optional properties: - fsl,mc13xxx-uses-touch : Indicate the touchscreen controller is being used Sub-nodes: +- leds : Contain the led nodes and initial register values in property + "led-control". Number of register depends of used IC, for MC13783 is 6, + for MC13892 is 4, for MC34708 is 1. See datasheet for bits definitions of + these registers. + - #address-cells: Must be 1. + - #size-cells: Must be 0. + Each led node should contain "reg", which used as LED ID (described below). + Optional properties "label" and "linux,default-trigger" is described in + Documentation/devicetree/bindings/leds/common.txt. - regulators : Contain the regulator nodes. The regulators are bound using their names as listed below with their registers and bits for enabling. +MC13783 LED IDs: + 0 : Main display + 1 : AUX display + 2 : Keypad + 3 : Red 1 + 4 : Green 1 + 5 : Blue 1 + 6 : Red 2 + 7 : Green 2 + 8 : Blue 2 + 9 : Red 3 + 10 : Green 3 + 11 : Blue 3 + +MC13892 LED IDs: + 0 : Main display + 1 : AUX display + 2 : Keypad + 3 : Red + 4 : Green + 5 : Blue + +MC34708 LED IDs: + 0 : Charger Red + 1 : Charger Green + MC13783 regulators: sw1a : regulator SW1A (register 24, bit 0) sw1b : regulator SW1B (register 25, bit 0)
@@ -89,6 +124,18 @@ ecspi@70010000 { /* ECSPI1 */ interrupt-parent = <&gpio0>; interrupts = <8>; + leds { + #address-cells = <1>; + #size-cells = <0>; + led-control = <0x000 0x000 0x0e0 0x000>; + + sysled { + reg = <3>; + label = "system:red:live"; + linux,default-trigger = "heartbeat"; + }; + }; + regulators { sw1_reg: mc13892__sw1 { regulator-min-microvolt = <600000>;
drivers/leds/leds-mc13783.c +115 -19
173 lines not on this page · raw message
Signature · 6 lines
1.8.3.2 -- To unsubscribe from this list: send the line "unsubscribe devicetree" in the body of a message to [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.html
A message that is not in the archive (sent off-list or not yet received): 1387600347-22673-1-git-send-email-shc_work-JGs/[email protected]
Hello,
Quoted 58 lines · Alexander Shiyan
This patch adds devicetree support for the MC13XXX LED driver.
Signed-off-by Alexander Shiyan <shc_work-JGs/[email protected]>--- Documentation/devicetree/bindings/mfd/mc13xxx.txt | 47 ++++++++ drivers/leds/leds-mc13783.c | 134 +++++++++++++++++++--- 2 files changed, 162 insertions(+), 19 deletions(-)Documentation/devicetree/bindings/mfd/mc13xxx.txt +35
-0@@ -10,9 +10,44 @@ Optional properties: - fsl,mc13xxx-uses-touch : Indicate the touchscreen controller is being used Sub-nodes: +- leds : Contain the led nodes and initial register values in property + "led-control". Number of register depends of used IC, for MC13783 is 6, + for MC13892 is 4, for MC34708 is 1. See datasheet for bits definitions of + these registers. + - #address-cells: Must be 1. + - #size-cells: Must be 0. + Each led node should contain "reg", which used as LED ID (described below). + Optional properties "label" and "linux,default-trigger" is described in + Documentation/devicetree/bindings/leds/common.txt. - regulators : Contain the regulator nodes. The regulators are bound using their names as listed below with their registers and bits for enabling. +MC13783 LED IDs: + 0 : Main display + 1 : AUX display + 2 : Keypad + 3 : Red 1 + 4 : Green 1 + 5 : Blue 1 + 6 : Red 2 + 7 : Green 2 + 8 : Blue 2 + 9 : Red 3 + 10 : Green 3 + 11 : Blue 3 + +MC13892 LED IDs: + 0 : Main display + 1 : AUX display + 2 : Keypad + 3 : Red + 4 : Green + 5 : Blue + +MC34708 LED IDs: + 0 : Charger Red + 1 : Charger Green + MC13783 regulators: sw1a : regulator SW1A (register 24, bit 0) sw1b : regulator SW1B (register 25, bit 0)
Documentation/devicetree/bindings/mfd/mc13xxx.txt ecspi@70010000 { /* ECSPI1 */ · line 127
Quoted 4 lines
Documentation/devicetree/bindings/mfd/mc13xxx.txt +1
-0@@ -89,6 +124,18 @@ ecspi@70010000 { /* ECSPI1 */ interrupt-parent = <&gpio0>; interrupts = <8>; + leds {
compatible string?
Quoted 27 lines
Documentation/devicetree/bindings/mfd/mc13xxx.txt +11
-0+ #address-cells = <1>; + #size-cells = <0>; + led-control = <0x000 0x000 0x0e0 0x000>; + + sysled { + reg = <3>; + label = "system:red:live"; + linux,default-trigger = "heartbeat"; + }; + }; + regulators { sw1_reg: mc13892__sw1 { regulator-min-microvolt = <600000>;drivers/leds/leds-mc13783.c +1
-0@@ -20,6 +20,7 @@#include <linux/init.h> #include <linux/platform_device.h> #include <linux/leds.h> +#include <linux/of.h> #include <linux/workqueue.h> #include <linux/mfd/mc13xxx.h>
drivers/leds/leds-mc13783.c struct mc13xxx_leds { · line 46
Quoted 5 lines
drivers/leds/leds-mc13783.c +1
-1@@ -42,7 +43,7 @@ struct mc13xxx_leds {struct mc13xxx *master;struct mc13xxx_led_devtype *devtype;int num_leds; -struct mc13xxx_led led[0 ]; +struct mc13xxx_led *led;
This is not related to the DT conversion, so please roll out the change into another patch.
Quoted 27 lines
drivers/leds/leds-mc13783.c +20
-0};static unsigned int mc13xxx_max_brightness (int id)@@ -120,6 +121,98 @@ static void mc13xxx_led_set(struct led_classdev *led_cdev,schedule_work (&led->work); } +#ifdef CONFIG_OF +static int __init mc13xxx_led_probe_dt (struct platform_device *pdev) +{ +struct mc13xxx_leds *leds =platform_get_drvdata (pdev); +struct mc13xxx *mcdev = leds->master; +struct device_node *parent, *child; +struct device *dev = &pdev->dev; +u32 *ctrls, init_led =0 ; +int i, ret; + + ctrls =devm_kzalloc (dev, leds->devtype->num_regs *sizeof (*ctrls), +GFP_KERNEL ); +if (!ctrls) +return -ENOMEM ; + +of_node_get (dev->parent->of_node); + parent =of_find_node_by_name (dev->parent->of_node,"leds" ); +if (!parent) { + ret = -ENODATA ; + goto out_node_put;
drivers/leds/leds-mc13783.c static void mc13xxx_led_set(struct led_classdev *led_cdev, · line 153
Quoted 10 lines
drivers/leds/leds-mc13783.c +10
-0+ } + + ret =of_property_read_u32_array (parent,"led-control" , ctrls, + leds->devtype->num_regs); +if (ret) + goto out_node_put; + +for (i =0 ; i < leds->devtype->num_regs; i++) { + ret =mc13xxx_reg_write (mcdev, leds->devtype->ledctrl_base + i, + ctrls[i]);
Code duplicated from the regular probe.
Quoted 8 lines
drivers/leds/leds-mc13783.c +8
-0+if (ret) + goto out_node_put; + } + + leds->led =devm_kzalloc (dev,of_get_child_count (parent) * +sizeof (*leds->led),GFP_KERNEL ); +if (!leds->led) +return -ENOMEM ;
drivers/leds/leds-mc13783.c static void mc13xxx_led_set(struct led_classdev *led_cdev, · line 171
Quoted 10 lines
drivers/leds/leds-mc13783.c +10
-0+ + i =0 ; + +for_each_child_of_node (parent, child) { +u32 id; + +if (of_property_read_u32 (child,"reg" , &id)) + continue;convert to + +if (id > (leds->devtype->led_max - leds->devtype->led_min)) {
This is slightly changed from the original driver:
if ((id > devtype->led_max) || (id < devtype->led_min)) {
So if you feel that it is a bug, please provide a proper bug fix as a separate patch.
Quoted 10 lines
drivers/leds/leds-mc13783.c +10
-0+dev_warn (dev,"Invalid reg ID %i\n" , id); +continue ; + } + +if (init_led & (1 << id)) { +dev_warn (dev,"LED %i already initialized\n" , id); +continue ; + } + + leds->led[i].id = id + leds->devtype->led_min;
drivers/leds/leds-mc13783.c static void mc13xxx_led_set(struct led_classdev *led_cdev, · line 191
Quoted 10 lines
drivers/leds/leds-mc13783.c +10
-0+ leds->led[i].leds = leds; + leds->led[i].cdev.name =of_get_property (child,"label" ,NULL ); + leds->led[i].cdev.default_trigger = +of_get_property (child,"linux,default-trigger" ,NULL ); + leds->led[i].cdev.flags =LED_CORE_SUSPENDRESUME ; + leds->led[i].cdev.brightness_set = mc13xxx_led_set; + leds->led[i].cdev.max_brightness =mc13xxx_max_brightness (id); + +INIT_WORK (&leds->led[i].work, mc13xxx_led_work); +
- The chunck above is just copy-pasted from the probe, so you end up with a _ton_ of duplicated
code. Please do not do that.
- The original probe calls mc13xxx_led_setup() here. Why are you removing this call?
Quoted 11 lines
drivers/leds/leds-mc13783.c +11
-0+if (led_classdev_register (dev, &leds->led[i].cdev)) { +dev_warn (dev,"Failed to register LED %i\n" , id); +continue ; + } + + init_led |=1 << id; + i++; + }; + + leds->num_leds = i; + ret = (i >0 ) ?0 : -ENODATA ;
drivers/leds/leds-mc13783.c static void mc13xxx_led_set(struct led_classdev *led_cdev, · line 212
Quoted 10 lines
drivers/leds/leds-mc13783.c +10
-0+ +out_node_put: +of_node_put (parent); + + return ret; +} +#else +static inline int __init mc13xxx_led_probe_dt (struct platform_device *pdev) +{ +return -ENOTSUPP ;
ENODEV usually?
Quoted 20 lines
drivers/leds/leds-mc13783.c +4
-7+} +#endif +static int __init mc13xxx_led_probe (struct platform_device *pdev) {struct device *dev = &pdev->dev;@@ -128,32 +221,35 @@ static int __init mc13xxx_led_probe(struct platform_device *pdev)struct mc13xxx_led_devtype *devtype = (struct mc13xxx_led_devtype *)pdev->id_entry->driver_data;struct mc13xxx_leds *leds; -int i, id, num_leds, ret = -ENODATA ; +int i, id, ret = -ENODATA ;u32 init_led =0 ; -if (!pdata) { -dev_err (dev,"Missing platform data\n" ); -return -ENODEV ; - } - - num_leds = pdata->num_leds;
drivers/leds/leds-mc13783.c static int __init mc13xxx_led_probe(struct platform_device *pdev) · line 227
Quoted 10 lines
drivers/leds/leds-mc13783.c +1
-9- -if ((num_leds <1 ) || - (num_leds > (devtype->led_max - devtype->led_min +1 ))) { -dev_err (dev,"Invalid LED count %d\n" , num_leds); -return -EINVAL ; - } - - leds =devm_kzalloc (dev, num_leds *sizeof (struct mc13xxx_led ) + -sizeof (struct mc13xxx_leds ),GFP_KERNEL ); + leds =devm_kzalloc (dev,sizeof (*leds),GFP_KERNEL );
As said in my first comment, this is not related to the DT conversion.
drivers/leds/leds-mc13783.c static int __init mc13xxx_led_probe(struct platform_device *pdev) · line 236
Quoted 10 lines
drivers/leds/leds-mc13783.c +2
-1if (!leds)return -ENOMEM ; leds->devtype = devtype; - leds->num_leds = num_leds; leds->master = mcdev;platform_set_drvdata (pdev, leds); +if (dev->parent->of_node) +return mc13xxx_led_probe_dt (pdev);
Why are you returning here? This is not a common way of doing the DT conversion, as you end up
with a lot of duplicated code. Your mc13xxx_led_probe_dt() should populate the missing fields
in your platform data, so that your probe logic remains untouched and common to both logics.
Quoted 21 lines
drivers/leds/leds-mc13783.c +16
-0+else if (!pdata) +return -ENODATA ; + + leds->num_leds = pdata->num_leds; + +if ((leds->num_leds <1 ) || + (leds->num_leds > (devtype->led_max - devtype->led_min +1 ))) { +dev_err (dev,"Invalid LED count %d\n" , leds->num_leds); +return -EINVAL ; + } + + leds->led =devm_kzalloc (dev, leds->num_leds *sizeof (*leds->led), +GFP_KERNEL ); +if (!leds->led) +return -ENOMEM ; +for (i =0 ; i < devtype->num_regs; i++) { ret =mc13xxx_reg_write (mcdev, leds->devtype->ledctrl_base + i, pdata->led_control[i]);
drivers/leds/leds-mc13783.c static int __init mc13xxx_led_probe(struct platform_device *pdev) · line 263
Quoted 8 lines
drivers/leds/leds-mc13783.c +1
-1@@ -161,7 +257,7 @@ static int __init mc13xxx_led_probe(struct platform_device *pdev)return ret; } -for (i =0 ; i < num_leds; i++) { +for (i =0 ; i < leds->num_leds; i++) {const char *name, *trig; ret = -EINVAL ;
Where is the of_match_table?
Regards,
Florian
--
To unsubscribe from this list: send the line "unsubscribe devicetree" in the body of a message to [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.html
Quoted 64 lines
Hello,
Quoted 61 lines · Alexander Shiyan
This patch adds devicetree support for the MC13XXX LED driver.
Signed-off-by Alexander Shiyan <[email protected]>--- Documentation/devicetree/bindings/mfd/mc13xxx.txt | 47 ++++++++ drivers/leds/leds-mc13783.c | 134 +++++++++++++++++++--- 2 files changed, 162 insertions(+), 19 deletions(-)Documentation/devicetree/bindings/mfd/mc13xxx.txt +35
-0@@ -10,9 +10,44 @@ Optional properties: - fsl,mc13xxx-uses-touch : Indicate the touchscreen controller is being used Sub-nodes: +- leds : Contain the led nodes and initial register values in property + "led-control". Number of register depends of used IC, for MC13783 is 6, + for MC13892 is 4, for MC34708 is 1. See datasheet for bits definitions of + these registers. + - #address-cells: Must be 1. + - #size-cells: Must be 0. + Each led node should contain "reg", which used as LED ID (described below). + Optional properties "label" and "linux,default-trigger" is described in + Documentation/devicetree/bindings/leds/common.txt. - regulators : Contain the regulator nodes. The regulators are bound using their names as listed below with their registers and bits for enabling. +MC13783 LED IDs: + 0 : Main display + 1 : AUX display + 2 : Keypad + 3 : Red 1 + 4 : Green 1 + 5 : Blue 1 + 6 : Red 2 + 7 : Green 2 + 8 : Blue 2 + 9 : Red 3 + 10 : Green 3 + 11 : Blue 3 + +MC13892 LED IDs: + 0 : Main display + 1 : AUX display + 2 : Keypad + 3 : Red + 4 : Green + 5 : Blue + +MC34708 LED IDs: + 0 : Charger Red + 1 : Charger Green + MC13783 regulators: sw1a : regulator SW1A (register 24, bit 0) sw1b : regulator SW1B (register 25, bit 0)@@ -89,6 +124,18 @@ ecspi@70010000 { /* ECSPI1 */ interrupt-parent = <&gpio0>; interrupts = <8>;
Quoted 3 lines
Documentation/devicetree/bindings/mfd/mc13xxx.txt ecspi@70010000 { /* ECSPI1 */ · line 127
Quoted 1 line
Documentation/devicetree/bindings/mfd/mc13xxx.txt +1
-0+ leds {compatible string?
Not need. This is a child for PMIC and it is probed from PMIC core.
...
Quoted 24 lines
Quoted 24 lines
Documentation/devicetree/bindings/mfd/mc13xxx.txt +24
-0+#ifdef CONFIG_OF +static int __init mc13xxx_led_probe_dt(struct platform_device *pdev) +{ + struct mc13xxx_leds *leds = platform_get_drvdata(pdev); + struct mc13xxx *mcdev = leds->master; + struct device_node *parent, *child; + struct device *dev = &pdev->dev; + u32 *ctrls, init_led = 0; + int i, ret; + + ctrls = devm_kzalloc(dev, leds->devtype->num_regs * sizeof(*ctrls), + GFP_KERNEL); + if (!ctrls) + return -ENOMEM; + + of_node_get(dev->parent->of_node); + parent = of_find_node_by_name(dev->parent->of_node, "leds"); + if (!parent) { + ret = -ENODATA; + goto out_node_put; + } + + ret = of_property_read_u32_array(parent, "led-control", ctrls, + leds->devtype->num_regs);
Quoted 8 lines
Documentation/devicetree/bindings/mfd/mc13xxx.txt
Quoted 6 lines
Documentation/devicetree/bindings/mfd/mc13xxx.txt +6
-0+ if (ret) + goto out_node_put; + + for (i = 0; i < leds->devtype->num_regs; i++) { + ret = mc13xxx_reg_write(mcdev, leds->devtype->ledctrl_base + i, + ctrls[i]);Code duplicated from the regular probe.
Yes. This was done based on the comments to the previous version:
http://www.spinics.net/lists/devicetree/msg14933.html
Thanks.
---
Hello,
Quoted 64 lines · Alexander Shiyan
Quoted 64 lines
Hello,
Quoted 61 lines · Alexander Shiyan
This patch adds devicetree support for the MC13XXX LED driver.
Signed-off-by Alexander Shiyan <[email protected]>--- Documentation/devicetree/bindings/mfd/mc13xxx.txt | 47 ++++++++ drivers/leds/leds-mc13783.c | 134 +++++++++++++++++++--- 2 files changed, 162 insertions(+), 19 deletions(-)Documentation/devicetree/bindings/mfd/mc13xxx.txt +35
-0@@ -10,9 +10,44 @@ Optional properties: - fsl,mc13xxx-uses-touch : Indicate the touchscreen controller is being used Sub-nodes: +- leds : Contain the led nodes and initial register values in property + "led-control". Number of register depends of used IC, for MC13783 is 6, + for MC13892 is 4, for MC34708 is 1. See datasheet for bits definitions of + these registers. + - #address-cells: Must be 1. + - #size-cells: Must be 0. + Each led node should contain "reg", which used as LED ID (described below). + Optional properties "label" and "linux,default-trigger" is described in + Documentation/devicetree/bindings/leds/common.txt. - regulators : Contain the regulator nodes. The regulators are bound using their names as listed below with their registers and bits for enabling. +MC13783 LED IDs: + 0 : Main display + 1 : AUX display + 2 : Keypad + 3 : Red 1 + 4 : Green 1 + 5 : Blue 1 + 6 : Red 2 + 7 : Green 2 + 8 : Blue 2 + 9 : Red 3 + 10 : Green 3 + 11 : Blue 3 + +MC13892 LED IDs: + 0 : Main display + 1 : AUX display + 2 : Keypad + 3 : Red + 4 : Green + 5 : Blue + +MC34708 LED IDs: + 0 : Charger Red + 1 : Charger Green + MC13783 regulators: sw1a : regulator SW1A (register 24, bit 0) sw1b : regulator SW1B (register 25, bit 0)@@ -89,6 +124,18 @@ ecspi@70010000 { /* ECSPI1 */ interrupt-parent = <&gpio0>; interrupts = <8>;
Quoted 6 lines
Quoted 3 lines
Documentation/devicetree/bindings/mfd/mc13xxx.txt ecspi@70010000 { /* ECSPI1 */ · line 127
Quoted 1 line
Documentation/devicetree/bindings/mfd/mc13xxx.txt +1
-0+ leds {compatible string?
Not need. This is a child for PMIC and it is probed from PMIC core.
Ok, so this is probably an oddity of the PMIC that I am using.
Quoted 34 lines
...
Quoted 24 lines
Quoted 24 lines
Documentation/devicetree/bindings/mfd/mc13xxx.txt +24
-0+#ifdef CONFIG_OF +static int __init mc13xxx_led_probe_dt(struct platform_device *pdev) +{ + struct mc13xxx_leds *leds = platform_get_drvdata(pdev); + struct mc13xxx *mcdev = leds->master; + struct device_node *parent, *child; + struct device *dev = &pdev->dev; + u32 *ctrls, init_led = 0; + int i, ret; + + ctrls = devm_kzalloc(dev, leds->devtype->num_regs * sizeof(*ctrls), + GFP_KERNEL); + if (!ctrls) + return -ENOMEM; + + of_node_get(dev->parent->of_node); + parent = of_find_node_by_name(dev->parent->of_node, "leds"); + if (!parent) { + ret = -ENODATA; + goto out_node_put; + } + + ret = of_property_read_u32_array(parent, "led-control", ctrls, + leds->devtype->num_regs);Quoted 8 lines
Documentation/devicetree/bindings/mfd/mc13xxx.txt
Quoted 6 lines
Documentation/devicetree/bindings/mfd/mc13xxx.txt +6
-0+ if (ret) + goto out_node_put; + + for (i = 0; i < leds->devtype->num_regs; i++) { + ret = mc13xxx_reg_write(mcdev, leds->devtype->ledctrl_base + i, + ctrls[i]);Code duplicated from the regular probe.
Quoted 5 lines
Yes. This was done based on the comments to the previous version:
http://www.spinics.net/lists/devicetree/msg14933.htmlFrom what I understand, Tomasz is suggesting exactly the same as
what I am saying:
"what about makingmc13xxx_led_setup_of() allocate a platform data structure and fill it in with data parsed from DT, so the driver would then proceed normally as if the platform data were available? IMHO this should make the code much simpler and more readable."
This is not what you have done IMHO, you are cloning the probe into a separate DT-only function.
Regards,
Florian
A message that is not in the archive (sent off-list or not yet received): [email protected]
PiA+PiBPbiAxMi8yMS8yMDEzIDA1OjMyIEFNLCBBbGV4YW5kZXIgU2hpeWFuIHdyb3RlOgo+ID4+ PiBUaGlzIHBhdGNoIGFkZHMgZGV2aWNldHJlZSBzdXBwb3J0IGZvciB0aGUgTUMxM1hYWCBMRUQg ZHJpdmVyLgouLi4KPiA+Pj4gKwlyZXQgPSBvZl9wcm9wZXJ0eV9yZWFkX3UzMl9hcnJheShwYXJl bnQsICJsZWQtY29udHJvbCIsIGN0cmxzLAo+ID4+PiArCQkJCQkgbGVkcy0+ZGV2dHlwZS0+bnVt X3JlZ3MpOwo+ID4+PiArCWlmIChyZXQpCj4gPj4+ICsJCWdvdG8gb3V0X25vZGVfcHV0Owo+ID4+ PiArCj4gPj4+ICsJZm9yIChpID0gMDsgaSA8IGxlZHMtPmRldnR5cGUtPm51bV9yZWdzOyBpKysp IHsKPiA+Pj4gKwkJcmV0ID0gbWMxM3h4eF9yZWdfd3JpdGUobWNkZXYsIGxlZHMtPmRldnR5cGUt PmxlZGN0cmxfYmFzZSArIGksCj4gPj4+ICsJCQkJCWN0cmxzW2ldKTsKPiA+Pgo+ID4+IENvZGUg ZHVwbGljYXRlZCBmcm9tIHRoZSByZWd1bGFyIHByb2JlLgo+ID4gCj4gPiBZZXMuIFRoaXMgd2Fz IGRvbmUgYmFzZWQgb24gdGhlIGNvbW1lbnRzIHRvIHRoZSBwcmV2aW91cyB2ZXJzaW9uOgo+ID4g aHR0cDovL3d3dy5zcGluaWNzLm5ldC9saXN0cy9kZXZpY2V0cmVlL21zZzE0OTMzLmh0bWwKPiA+ IAo+IAo+IEZyb20gd2hhdCBJIHVuZGVyc3RhbmQsIFRvbWFzeiBpcyBzdWdnZXN0aW5nIGV4YWN0 bHkgdGhlIHNhbWUgYXMKPiB3aGF0IEkgYW0gc2F5aW5nOgo+IAo+ICJ3aGF0IGFib3V0IG1ha2lu Zwo+IG1jMTN4eHhfbGVkX3NldHVwX29mKCkgYWxsb2NhdGUgYSBwbGF0Zm9ybSBkYXRhIHN0cnVj dHVyZSBhbmQgZmlsbCBpdAo+IGluIHdpdGggZGF0YSBwYXJzZWQgZnJvbSBEVCwgc28gdGhlIGRy aXZlciB3b3VsZCB0aGVuIHByb2NlZWQgbm9ybWFsbHkgYXMKPiBpZiB0aGUgcGxhdGZvcm0gZGF0 YSB3ZXJlIGF2YWlsYWJsZT8gSU1ITyB0aGlzIHNob3VsZCBtYWtlIHRoZSBjb2RlIG11Y2gKPiBz aW1wbGVyIGFuZCBtb3JlIHJlYWRhYmxlLiIKPiAKPiBUaGlzIGlzIG5vdCB3aGF0IHlvdSBoYXZl IGRvbmUgSU1ITywgeW91IGFyZSBjbG9uaW5nIHRoZSBwcm9iZQo+IGludG8gYSBzZXBhcmF0ZSBE VC1vbmx5IGZ1bmN0aW9uLgoKSSBkbyBub3QgZnVsbHkgdW5kZXJzdGFuZCB3aGF0IHlvdSBtZWFu LiBXaGVuIHdlIGhhZCBhbiB1bml2ZXJzYWwgcHJvY2VkdXJlLApJIHdhcyB0b2xkIHRvIGRpdmlk ZSB0aGVtIGludG8gRFQgYW5kIG5vbi1EVC4gSSBzZXBhcmF0ZWQgaXQgLSBub3cgd2UgaGF2ZSBk dXBsaWNhdGUgY29kZS4KTWVyZ2UgYmFjaz8KCi0tLQo=
--
To unsubscribe from this list: send the line "unsubscribe devicetree" in the body of a message to [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.html
Quoted 27 lines · Alexander Shiyan
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines · Alexander Shiyan
Quoted 1 line
This patch adds devicetree support for the MC13XXX LED driver.
...
Quoted 24 lines
Quoted 11 lines
Quoted 10 lines
Review
Quoted 8 lines
(quoted diff) +8
-0+ ret = of_property_read_u32_array(parent, "led-control", ctrls, + leds->devtype->num_regs); + if (ret) + goto out_node_put; + + for (i = 0; i < leds->devtype->num_regs; i++) { + ret = mc13xxx_reg_write(mcdev, leds->devtype->ledctrl_base + i, + ctrls[i]);Code duplicated from the regular probe.
Quoted 3 lines
Yes. This was done based on the comments to the previous version:
http://www.spinics.net/lists/devicetree/msg14933.htmlFrom what I understand, Tomasz is suggesting exactly the same as what I am saying:
"what about making
mc13xxx_led_setup_of()allocate a platform data structure and fill it in with data parsed from DT, so the driver would then proceed normally as if the platform data were available? IMHO this should make the code much simpler and more readable."
Quoted 7 lines
Quoted 2 lines
This is not what you have done IMHO, you are cloning the probe into a separate DT-only function.
I do not fully understand what you mean. When we had an universal procedure, I was told to divide them into DT and non-DT. I separated it - now we have duplicate code. Merge back?
No, do in-between. Look at leds-lp5521.c for example. What you have to do is roughly:
mc13xxx_led_probe
{
struct mc13xxx_leds_platform_data *pdata = NULL;
if (devicetree)
mc13xxx_of_populate_pdata(pdev->dev.of_node, &pdata);
else
pdata = dev_get_platdata(&pdev->dev);
if (!pdata)
oops...
-> regular probe here <-
}Your function mc13xxx_of_populate_pdata() will look for DT properties, and only fill the platform data. All the rest is done as usual by your probe function. No code is duplicated, but the DT logic is encapsulated inside its own function.
Look at other drivers if you are not familiar with such an approach, it is pretty common.
Regards,
Florian
Quoted 53 lines
Quoted 27 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines · Alexander Shiyan
Quoted 1 line
This patch adds devicetree support for the MC13XXX LED driver.
...
Quoted 24 lines
Quoted 11 lines
Quoted 10 lines
Review
Quoted 8 lines
(quoted diff) +8
-0+ ret = of_property_read_u32_array(parent, "led-control", ctrls, + leds->devtype->num_regs); + if (ret) + goto out_node_put; + + for (i = 0; i < leds->devtype->num_regs; i++) { + ret = mc13xxx_reg_write(mcdev, leds->devtype->ledctrl_base + i, + ctrls[i]);Code duplicated from the regular probe.
Quoted 3 lines
Yes. This was done based on the comments to the previous version:
http://www.spinics.net/lists/devicetree/msg14933.htmlFrom what I understand, Tomasz is suggesting exactly the same as what I am saying:
"what about making
mc13xxx_led_setup_of()allocate a platform data structure and fill it in with data parsed from DT, so the driver would then proceed normally as if the platform data were available? IMHO this should make the code much simpler and more readable."Quoted 7 lines
Quoted 2 lines
This is not what you have done IMHO, you are cloning the probe into a separate DT-only function.
I do not fully understand what you mean. When we had an universal procedure, I was told to divide them into DT and non-DT. I separated it - now we have duplicate code. Merge back?
No, do in-between. Look at
leds-lp5521.cfor example. What you have to do is roughly:
mc13xxx_led_probe{ struct mc13xxx_leds_platform_data *pdata = NULL; if (devicetree) mc13xxx_of_populate_pdata(pdev->dev.of_node, &pdata); else pdata = dev_get_platdata(&pdev->dev); if (!pdata) oops... -> regular probe here <- }
Quoted 4 lines
Your function
mc13xxx_of_populate_pdata()will look for DT properties, and only fill the platform data. All the rest is done as usual by your probe function. No code is duplicated, but the DT logic is encapsulated inside its own function.
pdata is the excess variable for DT-case, but OK, will do.
Bryan, can parts 1-4 be applied?
---