new file mode 100644
@@ -0,0 +1,22 @@
+Binding for LP55xx Led Driver
+
+Required properties:
+- compatible: "lp5521" or "lp5523"
+- label: Used for naming LEDs
+- num-chanel: 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 = "lp5521";
+ reg = <0x32>;
+ label = "lp5521_pri";
+ num-chanel = /bits/ 8 <3>;
+ led-cur = /bits/ 8 <0x2f 0x2f 0x2f>;
+ max-cur = /bits/ 8 <0x5f 0x5f 0x5f>;
+
+ clock-mode = /bits/8 <2>;
+};
@@ -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"
@@ -394,18 +395,68 @@ static struct lp55xx_device_config lp5521_cfg = {
.dev_attr_group = &lp5521_group,
};
+static int lp5521_of_probe(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 i;
+
+ pdata = devm_kzalloc(dev, sizeof(*pdata), GFP_KERNEL);
+ if (!pdata)
+ return -ENOMEM;
+
+ of_property_read_u8(np, "num-chanel", &num_channel);
+ of_property_read_u8_array(np, "led-cur", led_cur, num_channel);
+ of_property_read_u8_array(np, "max-cur", max_cur, num_channel);
+ of_property_read_string(np, "label", &label);
+ of_property_read_u8_array(np, "clock-mode", &clock_mode, 1);
+
+ 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;
+}
+
static int lp5521_probe(struct i2c_client *client,
const struct i2c_device_id *id)
{
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 = lp5521_of_probe(&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)