]> git.karo-electronics.de Git - karo-tx-linux.git/commitdiff
leds: lp55xx: add support for Device Tree bindings
authorLinus Walleij <linus.walleij@linaro.org>
Tue, 23 Apr 2013 11:52:59 +0000 (04:52 -0700)
committerBryan Wu <cooloney@gmail.com>
Thu, 23 May 2013 18:23:22 +0000 (11:23 -0700)
This patch allows the lp5521 driver to be successfully probed and
initialised when Device Tree support is enabled.

Based on a patch by Gabriel Fernandez, rewritten in accordance
with review feedback.

Cc: Gabriel Fernandez <gabriel.fernandez@stericsson.com>
Signed-off-by: Linus Walleij <linus.walleij@linaro.org>
Acked-by: Milo Kim <milo.kim@ti.com>
Signed-off-by: Bryan Wu <cooloney@gmail.com>
Documentation/devicetree/bindings/leds/leds-lp55xx.txt [new file with mode: 0644]
drivers/leds/leds-lp5521.c
drivers/leds/leds-lp5523.c
drivers/leds/leds-lp55xx-common.c
drivers/leds/leds-lp55xx-common.h

diff --git a/Documentation/devicetree/bindings/leds/leds-lp55xx.txt b/Documentation/devicetree/bindings/leds/leds-lp55xx.txt
new file mode 100644 (file)
index 0000000..348c88e
--- /dev/null
@@ -0,0 +1,21 @@
+Binding for National Semiconductor LP55xx Led Drivers
+
+Required properties:
+- compatible: "national,lp5521" or "national,lp5523"
+- label: Used for naming LEDs
+- num-channel: Number of LED channels
+- led-cur: Current setting at each led channel (mA x10, 0 if led is not connected)
+- max-cur: Maximun current at each led channel.
+- clock-mode: Input clock mode, (0: automode, 1: internal, 2: external)
+
+example:
+
+lp5521@32 {
+       compatible = "national,lp5521";
+       reg = <0x32>;
+       label = "lp5521_pri";
+       num-channel = /bits/ 8 <3>;
+       led-cur = /bits/ 8 <0x2f 0x2f 0x2f>;
+       max-cur = /bits/ 8 <0x5f 0x5f 0x5f>;
+       clock-mode = /bits/8 <2>;
+};
index 19752c928aa2d6f99c2d15383fae905414f0bcdc..d461e2664b09f7e657da5efd428d2f6a1e38836b 100644 (file)
@@ -31,6 +31,7 @@
 #include <linux/mutex.h>
 #include <linux/platform_data/leds-lp55xx.h>
 #include <linux/slab.h>
+#include <linux/of.h>
 
 #include "leds-lp55xx-common.h"
 
@@ -416,12 +417,20 @@ static int lp5521_probe(struct i2c_client *client,
        int ret;
        struct lp55xx_chip *chip;
        struct lp55xx_led *led;
-       struct lp55xx_platform_data *pdata = client->dev.platform_data;
-
-       if (!pdata) {
-               dev_err(&client->dev, "no platform data\n");
-               return -EINVAL;
+       struct lp55xx_platform_data *pdata;
+       struct device_node *np = client->dev.of_node;
+
+       if (!client->dev.platform_data) {
+               if (np) {
+                       ret = lp55xx_of_populate_pdata(&client->dev, np);
+                       if (ret < 0)
+                               return ret;
+               } else {
+                       dev_err(&client->dev, "no platform data\n");
+                       return -EINVAL;
+               }
        }
+       pdata = client->dev.platform_data;
 
        chip = devm_kzalloc(&client->dev, sizeof(*chip), GFP_KERNEL);
        if (!chip)
@@ -481,6 +490,7 @@ static int lp5521_remove(struct i2c_client *client)
 
 static const struct i2c_device_id lp5521_id[] = {
        { "lp5521", 0 }, /* Three channel chip */
+       { "national,lp5521", 0 }, /* OF compatible */
        { }
 };
 MODULE_DEVICE_TABLE(i2c, lp5521_id);
index 229f734040af8a8669f029583aa8d739e266798f..365e9148e5e8fefd28499c3117a3ead57ee5ed90 100644 (file)
@@ -429,12 +429,20 @@ static int lp5523_probe(struct i2c_client *client,
        int ret;
        struct lp55xx_chip *chip;
        struct lp55xx_led *led;
-       struct lp55xx_platform_data *pdata = client->dev.platform_data;
-
-       if (!pdata) {
-               dev_err(&client->dev, "no platform data\n");
-               return -EINVAL;
+       struct lp55xx_platform_data *pdata;
+       struct device_node *np = client->dev.of_node;
+
+       if (!client->dev.platform_data) {
+               if (np) {
+                       ret = lp55xx_of_populate_pdata(&client->dev, np);
+                       if (ret < 0)
+                               return ret;
+               } else {
+                       dev_err(&client->dev, "no platform data\n");
+                       return -EINVAL;
+               }
        }
+       pdata = client->dev.platform_data;
 
        chip = devm_kzalloc(&client->dev, sizeof(*chip), GFP_KERNEL);
        if (!chip)
@@ -495,6 +503,7 @@ static int lp5523_remove(struct i2c_client *client)
 static const struct i2c_device_id lp5523_id[] = {
        { "lp5523",  LP5523 },
        { "lp55231", LP55231 },
+       { "national,lp5523", 0 }, /* OF compatible */
        { }
 };
 
index ba34199dc3d93e51a2b83526db61db2658f5e7b0..a0d2bd2fa23cc23aba71061acd24169ba25ef98b 100644 (file)
@@ -19,6 +19,7 @@
 #include <linux/leds.h>
 #include <linux/module.h>
 #include <linux/platform_data/leds-lp55xx.h>
+#include <linux/slab.h>
 
 #include "leds-lp55xx-common.h"
 
@@ -554,6 +555,59 @@ void lp55xx_unregister_sysfs(struct lp55xx_chip *chip)
 }
 EXPORT_SYMBOL_GPL(lp55xx_unregister_sysfs);
 
+int lp55xx_of_populate_pdata(struct device *dev, struct device_node *np)
+{
+       struct lp55xx_platform_data *pdata;
+       u8 led_cur[3];
+       u8 max_cur[3];
+       u8 clock_mode;
+       u8 num_channel;
+       const char *label;
+       struct lp55xx_led_config *led_config;
+       int ret;
+       int i;
+
+       pdata = devm_kzalloc(dev, sizeof(*pdata), GFP_KERNEL);
+       if (!pdata)
+               return -ENOMEM;
+
+       ret = of_property_read_u8(np, "num-channel", &num_channel);
+       if (ret < 0)
+               return ret;
+       ret = of_property_read_u8_array(np, "led-cur", led_cur, num_channel);
+       if (ret < 0)
+               return ret;
+       ret = of_property_read_u8_array(np, "max-cur", max_cur, num_channel);
+       if (ret < 0)
+               return ret;
+       ret = of_property_read_string(np, "label", &label);
+       if (ret < 0)
+               return ret;
+       ret = of_property_read_u8_array(np, "clock-mode", &clock_mode, 1);
+       if (ret < 0)
+               return ret;
+
+       led_config = devm_kzalloc(dev, sizeof(*led_config) * num_channel,
+                                 GFP_KERNEL);
+       if (!led_config)
+               return -ENOMEM;
+
+       for (i = 0; i < num_channel; i++) {
+               led_config[i].chan_nr = i;
+               led_config[i].led_current = led_cur[i];
+               led_config[i].max_current = max_cur[i];
+       }
+       pdata->label = kzalloc(sizeof(char) * 32, GFP_KERNEL);
+       strcpy((char *)pdata->label, (char *) label);
+       pdata->led_config = &led_config[0];
+       pdata->num_channels = num_channel;
+       pdata->clock_mode = clock_mode;
+       dev->platform_data = pdata;
+
+       return 0;
+}
+EXPORT_SYMBOL_GPL(lp55xx_of_populate_pdata);
+
 MODULE_AUTHOR("Milo Kim <milo.kim@ti.com>");
 MODULE_DESCRIPTION("LP55xx Common Driver");
 MODULE_LICENSE("GPL");
index fa6a078bf5471131f14ac1e4d7d1091fa87c36e4..dbbf86df0f1fcdbe4d14de589b7fc90ef85f1a24 100644 (file)
@@ -135,4 +135,8 @@ extern void lp55xx_unregister_leds(struct lp55xx_led *led,
 extern int lp55xx_register_sysfs(struct lp55xx_chip *chip);
 extern void lp55xx_unregister_sysfs(struct lp55xx_chip *chip);
 
+/* common device tree population function */
+extern int lp55xx_of_populate_pdata(struct device *dev,
+                                   struct device_node *np);
+
 #endif /* _LEDS_LP55XX_COMMON_H */