aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/leds/leds-lp55xx-common.c
diff options
context:
space:
mode:
Diffstat (limited to 'drivers/leds/leds-lp55xx-common.c')
-rw-r--r--drivers/leds/leds-lp55xx-common.c54
1 files changed, 54 insertions, 0 deletions
diff --git a/drivers/leds/leds-lp55xx-common.c b/drivers/leds/leds-lp55xx-common.c
index ba34199dc3d9..a0d2bd2fa23c 100644
--- a/drivers/leds/leds-lp55xx-common.c
+++ b/drivers/leds/leds-lp55xx-common.c
@@ -19,6 +19,7 @@
19#include <linux/leds.h> 19#include <linux/leds.h>
20#include <linux/module.h> 20#include <linux/module.h>
21#include <linux/platform_data/leds-lp55xx.h> 21#include <linux/platform_data/leds-lp55xx.h>
22#include <linux/slab.h>
22 23
23#include "leds-lp55xx-common.h" 24#include "leds-lp55xx-common.h"
24 25
@@ -554,6 +555,59 @@ void lp55xx_unregister_sysfs(struct lp55xx_chip *chip)
554} 555}
555EXPORT_SYMBOL_GPL(lp55xx_unregister_sysfs); 556EXPORT_SYMBOL_GPL(lp55xx_unregister_sysfs);
556 557
558int lp55xx_of_populate_pdata(struct device *dev, struct device_node *np)
559{
560 struct lp55xx_platform_data *pdata;
561 u8 led_cur[3];
562 u8 max_cur[3];
563 u8 clock_mode;
564 u8 num_channel;
565 const char *label;
566 struct lp55xx_led_config *led_config;
567 int ret;
568 int i;
569
570 pdata = devm_kzalloc(dev, sizeof(*pdata), GFP_KERNEL);
571 if (!pdata)
572 return -ENOMEM;
573
574 ret = of_property_read_u8(np, "num-channel", &num_channel);
575 if (ret < 0)
576 return ret;
577 ret = of_property_read_u8_array(np, "led-cur", led_cur, num_channel);
578 if (ret < 0)
579 return ret;
580 ret = of_property_read_u8_array(np, "max-cur", max_cur, num_channel);
581 if (ret < 0)
582 return ret;
583 ret = of_property_read_string(np, "label", &label);
584 if (ret < 0)
585 return ret;
586 ret = of_property_read_u8_array(np, "clock-mode", &clock_mode, 1);
587 if (ret < 0)
588 return ret;
589
590 led_config = devm_kzalloc(dev, sizeof(*led_config) * num_channel,
591 GFP_KERNEL);
592 if (!led_config)
593 return -ENOMEM;
594
595 for (i = 0; i < num_channel; i++) {
596 led_config[i].chan_nr = i;
597 led_config[i].led_current = led_cur[i];
598 led_config[i].max_current = max_cur[i];
599 }
600 pdata->label = kzalloc(sizeof(char) * 32, GFP_KERNEL);
601 strcpy((char *)pdata->label, (char *) label);
602 pdata->led_config = &led_config[0];
603 pdata->num_channels = num_channel;
604 pdata->clock_mode = clock_mode;
605 dev->platform_data = pdata;
606
607 return 0;
608}
609EXPORT_SYMBOL_GPL(lp55xx_of_populate_pdata);
610
557MODULE_AUTHOR("Milo Kim <milo.kim@ti.com>"); 611MODULE_AUTHOR("Milo Kim <milo.kim@ti.com>");
558MODULE_DESCRIPTION("LP55xx Common Driver"); 612MODULE_DESCRIPTION("LP55xx Common Driver");
559MODULE_LICENSE("GPL"); 613MODULE_LICENSE("GPL");