diff options
Diffstat (limited to 'drivers/leds/leds-lp55xx-common.c')
-rw-r--r-- | drivers/leds/leds-lp55xx-common.c | 54 |
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 | } |
555 | EXPORT_SYMBOL_GPL(lp55xx_unregister_sysfs); | 556 | EXPORT_SYMBOL_GPL(lp55xx_unregister_sysfs); |
556 | 557 | ||
558 | int 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 | } | ||
609 | EXPORT_SYMBOL_GPL(lp55xx_of_populate_pdata); | ||
610 | |||
557 | MODULE_AUTHOR("Milo Kim <milo.kim@ti.com>"); | 611 | MODULE_AUTHOR("Milo Kim <milo.kim@ti.com>"); |
558 | MODULE_DESCRIPTION("LP55xx Common Driver"); | 612 | MODULE_DESCRIPTION("LP55xx Common Driver"); |
559 | MODULE_LICENSE("GPL"); | 613 | MODULE_LICENSE("GPL"); |