blob: 9acc6bb7deef01f153e5c71044ac93be7e983ba9 [file] [log] [blame]
Milo(Woogyom) Kimc93d08f2013-02-05 18:01:23 +09001/*
Kim, Miloff45262a2013-02-18 21:10:14 -08002 * LP5521/LP5523/LP55231/LP5562 Common Driver
Milo(Woogyom) Kimc93d08f2013-02-05 18:01:23 +09003 *
4 * Copyright 2012 Texas Instruments
5 *
6 * Author: Milo(Woogyom) Kim <milo.kim@ti.com>
7 *
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License version 2 as
10 * published by the Free Software Foundation.
11 *
12 * Derived from leds-lp5521.c, leds-lp5523.c
13 */
14
Kim, Milo53b41922013-03-20 17:37:00 -070015#include <linux/clk.h>
Milo(Woogyom) Kima85908d2013-02-05 18:07:20 +090016#include <linux/delay.h>
Milo(Woogyom) Kim10c06d12013-02-05 19:17:20 +090017#include <linux/firmware.h>
Milo(Woogyom) Kimc93d08f2013-02-05 18:01:23 +090018#include <linux/i2c.h>
19#include <linux/leds.h>
20#include <linux/module.h>
21#include <linux/platform_data/leds-lp55xx.h>
Linus Walleij7542a042013-04-23 04:52:59 -070022#include <linux/slab.h>
Sebastian Reichel30dae2f2013-10-22 11:02:56 -070023#include <linux/gpio.h>
24#include <linux/of_gpio.h>
Milo(Woogyom) Kimc93d08f2013-02-05 18:01:23 +090025
26#include "leds-lp55xx-common.h"
27
Kim, Milo53b41922013-03-20 17:37:00 -070028/* External clock rate */
29#define LP55XX_CLK_32K 32768
30
Milo(Woogyom) Kima6e46792013-02-05 19:08:40 +090031static struct lp55xx_led *cdev_to_lp55xx_led(struct led_classdev *cdev)
32{
33 return container_of(cdev, struct lp55xx_led, cdev);
34}
35
Milo(Woogyom) Kima96bfa12013-02-05 19:09:32 +090036static struct lp55xx_led *dev_to_lp55xx_led(struct device *dev)
37{
38 return cdev_to_lp55xx_led(dev_get_drvdata(dev));
39}
40
Milo(Woogyom) Kim48068d52013-02-05 18:08:49 +090041static void lp55xx_reset_device(struct lp55xx_chip *chip)
42{
43 struct lp55xx_device_config *cfg = chip->cfg;
44 u8 addr = cfg->reset.addr;
45 u8 val = cfg->reset.val;
46
47 /* no error checking here because no ACK from the device after reset */
48 lp55xx_write(chip, addr, val);
49}
50
Milo(Woogyom) Kime3a700d2013-02-05 18:09:56 +090051static int lp55xx_detect_device(struct lp55xx_chip *chip)
52{
53 struct lp55xx_device_config *cfg = chip->cfg;
54 u8 addr = cfg->enable.addr;
55 u8 val = cfg->enable.val;
56 int ret;
57
58 ret = lp55xx_write(chip, addr, val);
59 if (ret)
60 return ret;
61
62 usleep_range(1000, 2000);
63
64 ret = lp55xx_read(chip, addr, &val);
65 if (ret)
66 return ret;
67
68 if (val != cfg->enable.val)
69 return -ENODEV;
70
71 return 0;
72}
73
Milo(Woogyom) Kimffbdccd2013-02-05 18:57:36 +090074static int lp55xx_post_init_device(struct lp55xx_chip *chip)
75{
76 struct lp55xx_device_config *cfg = chip->cfg;
77
78 if (!cfg->post_init_device)
79 return 0;
80
81 return cfg->post_init_device(chip);
82}
83
Milo(Woogyom) Kima96bfa12013-02-05 19:09:32 +090084static ssize_t lp55xx_show_current(struct device *dev,
85 struct device_attribute *attr,
86 char *buf)
87{
88 struct lp55xx_led *led = dev_to_lp55xx_led(dev);
89
Kim, Milo24d32122013-03-14 17:19:36 -070090 return scnprintf(buf, PAGE_SIZE, "%d\n", led->led_current);
Milo(Woogyom) Kima96bfa12013-02-05 19:09:32 +090091}
92
93static ssize_t lp55xx_store_current(struct device *dev,
94 struct device_attribute *attr,
95 const char *buf, size_t len)
96{
97 struct lp55xx_led *led = dev_to_lp55xx_led(dev);
98 struct lp55xx_chip *chip = led->chip;
99 unsigned long curr;
100
101 if (kstrtoul(buf, 0, &curr))
102 return -EINVAL;
103
104 if (curr > led->max_current)
105 return -EINVAL;
106
107 if (!chip->cfg->set_led_current)
108 return len;
109
110 mutex_lock(&chip->lock);
111 chip->cfg->set_led_current(led, (u8)curr);
112 mutex_unlock(&chip->lock);
113
114 return len;
115}
116
117static ssize_t lp55xx_show_max_current(struct device *dev,
118 struct device_attribute *attr,
119 char *buf)
120{
121 struct lp55xx_led *led = dev_to_lp55xx_led(dev);
122
Kim, Milo24d32122013-03-14 17:19:36 -0700123 return scnprintf(buf, PAGE_SIZE, "%d\n", led->max_current);
Milo(Woogyom) Kima96bfa12013-02-05 19:09:32 +0900124}
125
126static DEVICE_ATTR(led_current, S_IRUGO | S_IWUSR, lp55xx_show_current,
127 lp55xx_store_current);
128static DEVICE_ATTR(max_current, S_IRUGO , lp55xx_show_max_current, NULL);
129
Milo(Woogyom) Kim0e202342013-02-05 19:07:34 +0900130static struct attribute *lp55xx_led_attributes[] = {
Milo(Woogyom) Kima96bfa12013-02-05 19:09:32 +0900131 &dev_attr_led_current.attr,
132 &dev_attr_max_current.attr,
Milo(Woogyom) Kim0e202342013-02-05 19:07:34 +0900133 NULL,
134};
135
136static struct attribute_group lp55xx_led_attr_group = {
137 .attrs = lp55xx_led_attributes
138};
139
140static void lp55xx_set_brightness(struct led_classdev *cdev,
141 enum led_brightness brightness)
142{
Milo(Woogyom) Kima6e46792013-02-05 19:08:40 +0900143 struct lp55xx_led *led = cdev_to_lp55xx_led(cdev);
144
145 led->brightness = (u8)brightness;
146 schedule_work(&led->brightness_work);
Milo(Woogyom) Kim0e202342013-02-05 19:07:34 +0900147}
148
Milo(Woogyom) Kim9e9b3db2013-02-05 19:06:27 +0900149static int lp55xx_init_led(struct lp55xx_led *led,
150 struct lp55xx_chip *chip, int chan)
151{
Milo(Woogyom) Kim0e202342013-02-05 19:07:34 +0900152 struct lp55xx_platform_data *pdata = chip->pdata;
153 struct lp55xx_device_config *cfg = chip->cfg;
154 struct device *dev = &chip->cl->dev;
155 char name[32];
156 int ret;
157 int max_channel = cfg->max_channel;
158
159 if (chan >= max_channel) {
160 dev_err(dev, "invalid channel: %d / %d\n", chan, max_channel);
161 return -EINVAL;
162 }
163
164 if (pdata->led_config[chan].led_current == 0)
165 return 0;
166
167 led->led_current = pdata->led_config[chan].led_current;
168 led->max_current = pdata->led_config[chan].max_current;
169 led->chan_nr = pdata->led_config[chan].chan_nr;
Linus Walleijf65f0a12013-09-15 03:50:17 -0700170 led->cdev.default_trigger = pdata->led_config[chan].default_trigger;
Milo(Woogyom) Kim0e202342013-02-05 19:07:34 +0900171
172 if (led->chan_nr >= max_channel) {
173 dev_err(dev, "Use channel numbers between 0 and %d\n",
174 max_channel - 1);
175 return -EINVAL;
176 }
177
178 led->cdev.brightness_set = lp55xx_set_brightness;
179
180 if (pdata->led_config[chan].name) {
181 led->cdev.name = pdata->led_config[chan].name;
182 } else {
183 snprintf(name, sizeof(name), "%s:channel%d",
184 pdata->label ? : chip->cl->name, chan);
185 led->cdev.name = name;
186 }
187
188 /*
189 * register led class device for each channel and
190 * add device attributes
191 */
192
193 ret = led_classdev_register(dev, &led->cdev);
194 if (ret) {
195 dev_err(dev, "led register err: %d\n", ret);
196 return ret;
197 }
198
199 ret = sysfs_create_group(&led->cdev.dev->kobj, &lp55xx_led_attr_group);
200 if (ret) {
201 dev_err(dev, "led sysfs err: %d\n", ret);
202 led_classdev_unregister(&led->cdev);
203 return ret;
204 }
205
Milo(Woogyom) Kim9e9b3db2013-02-05 19:06:27 +0900206 return 0;
207}
208
Milo(Woogyom) Kim10c06d12013-02-05 19:17:20 +0900209static void lp55xx_firmware_loaded(const struct firmware *fw, void *context)
210{
211 struct lp55xx_chip *chip = context;
212 struct device *dev = &chip->cl->dev;
213
214 if (!fw) {
215 dev_err(dev, "firmware request failed\n");
216 goto out;
217 }
218
219 /* handling firmware data is chip dependent */
220 mutex_lock(&chip->lock);
221
222 chip->fw = fw;
223 if (chip->cfg->firmware_cb)
224 chip->cfg->firmware_cb(chip);
225
226 mutex_unlock(&chip->lock);
227
228out:
229 /* firmware should be released for other channel use */
230 release_firmware(chip->fw);
231}
232
233static int lp55xx_request_firmware(struct lp55xx_chip *chip)
234{
235 const char *name = chip->cl->name;
236 struct device *dev = &chip->cl->dev;
237
238 return request_firmware_nowait(THIS_MODULE, true, name, dev,
239 GFP_KERNEL, chip, lp55xx_firmware_loaded);
240}
241
242static ssize_t lp55xx_show_engine_select(struct device *dev,
243 struct device_attribute *attr,
244 char *buf)
245{
246 struct lp55xx_led *led = i2c_get_clientdata(to_i2c_client(dev));
247 struct lp55xx_chip *chip = led->chip;
248
249 return sprintf(buf, "%d\n", chip->engine_idx);
250}
251
252static ssize_t lp55xx_store_engine_select(struct device *dev,
253 struct device_attribute *attr,
254 const char *buf, size_t len)
255{
256 struct lp55xx_led *led = i2c_get_clientdata(to_i2c_client(dev));
257 struct lp55xx_chip *chip = led->chip;
258 unsigned long val;
259 int ret;
260
261 if (kstrtoul(buf, 0, &val))
262 return -EINVAL;
263
264 /* select the engine to be run */
265
266 switch (val) {
267 case LP55XX_ENGINE_1:
268 case LP55XX_ENGINE_2:
269 case LP55XX_ENGINE_3:
270 mutex_lock(&chip->lock);
271 chip->engine_idx = val;
272 ret = lp55xx_request_firmware(chip);
273 mutex_unlock(&chip->lock);
274 break;
275 default:
276 dev_err(dev, "%lu: invalid engine index. (1, 2, 3)\n", val);
277 return -EINVAL;
278 }
279
280 if (ret) {
281 dev_err(dev, "request firmware err: %d\n", ret);
282 return ret;
283 }
284
285 return len;
286}
287
288static inline void lp55xx_run_engine(struct lp55xx_chip *chip, bool start)
289{
290 if (chip->cfg->run_engine)
291 chip->cfg->run_engine(chip, start);
292}
293
294static ssize_t lp55xx_store_engine_run(struct device *dev,
295 struct device_attribute *attr,
296 const char *buf, size_t len)
297{
298 struct lp55xx_led *led = i2c_get_clientdata(to_i2c_client(dev));
299 struct lp55xx_chip *chip = led->chip;
300 unsigned long val;
301
302 if (kstrtoul(buf, 0, &val))
303 return -EINVAL;
304
305 /* run or stop the selected engine */
306
307 if (val <= 0) {
308 lp55xx_run_engine(chip, false);
309 return len;
310 }
311
312 mutex_lock(&chip->lock);
313 lp55xx_run_engine(chip, true);
314 mutex_unlock(&chip->lock);
315
316 return len;
317}
318
319static DEVICE_ATTR(select_engine, S_IRUGO | S_IWUSR,
320 lp55xx_show_engine_select, lp55xx_store_engine_select);
321static DEVICE_ATTR(run_engine, S_IWUSR, NULL, lp55xx_store_engine_run);
322
Milo(Woogyom) Kimb3b6f812013-02-05 19:15:27 +0900323static struct attribute *lp55xx_engine_attributes[] = {
Milo(Woogyom) Kim10c06d12013-02-05 19:17:20 +0900324 &dev_attr_select_engine.attr,
325 &dev_attr_run_engine.attr,
Milo(Woogyom) Kimb3b6f812013-02-05 19:15:27 +0900326 NULL,
327};
328
329static const struct attribute_group lp55xx_engine_attr_group = {
330 .attrs = lp55xx_engine_attributes,
331};
332
Milo(Woogyom) Kimc93d08f2013-02-05 18:01:23 +0900333int lp55xx_write(struct lp55xx_chip *chip, u8 reg, u8 val)
334{
335 return i2c_smbus_write_byte_data(chip->cl, reg, val);
336}
337EXPORT_SYMBOL_GPL(lp55xx_write);
338
339int lp55xx_read(struct lp55xx_chip *chip, u8 reg, u8 *val)
340{
341 s32 ret;
342
343 ret = i2c_smbus_read_byte_data(chip->cl, reg);
344 if (ret < 0)
345 return ret;
346
347 *val = ret;
348 return 0;
349}
350EXPORT_SYMBOL_GPL(lp55xx_read);
351
352int lp55xx_update_bits(struct lp55xx_chip *chip, u8 reg, u8 mask, u8 val)
353{
354 int ret;
355 u8 tmp;
356
357 ret = lp55xx_read(chip, reg, &tmp);
358 if (ret)
359 return ret;
360
361 tmp &= ~mask;
362 tmp |= val & mask;
363
364 return lp55xx_write(chip, reg, tmp);
365}
366EXPORT_SYMBOL_GPL(lp55xx_update_bits);
367
Kim, Milo53b41922013-03-20 17:37:00 -0700368bool lp55xx_is_extclk_used(struct lp55xx_chip *chip)
369{
370 struct clk *clk;
371 int err;
372
373 clk = devm_clk_get(&chip->cl->dev, "32k_clk");
374 if (IS_ERR(clk))
375 goto use_internal_clk;
376
377 err = clk_prepare_enable(clk);
378 if (err)
379 goto use_internal_clk;
380
381 if (clk_get_rate(clk) != LP55XX_CLK_32K) {
382 clk_disable_unprepare(clk);
383 goto use_internal_clk;
384 }
385
386 dev_info(&chip->cl->dev, "%dHz external clock used\n", LP55XX_CLK_32K);
387
388 chip->clk = clk;
389 return true;
390
391use_internal_clk:
392 dev_info(&chip->cl->dev, "internal clock used\n");
393 return false;
394}
395EXPORT_SYMBOL_GPL(lp55xx_is_extclk_used);
396
Milo(Woogyom) Kima85908d2013-02-05 18:07:20 +0900397int lp55xx_init_device(struct lp55xx_chip *chip)
398{
399 struct lp55xx_platform_data *pdata;
Milo(Woogyom) Kim48068d52013-02-05 18:08:49 +0900400 struct lp55xx_device_config *cfg;
Milo(Woogyom) Kima85908d2013-02-05 18:07:20 +0900401 struct device *dev = &chip->cl->dev;
402 int ret = 0;
403
404 WARN_ON(!chip);
405
406 pdata = chip->pdata;
Milo(Woogyom) Kim48068d52013-02-05 18:08:49 +0900407 cfg = chip->cfg;
Milo(Woogyom) Kima85908d2013-02-05 18:07:20 +0900408
Milo(Woogyom) Kim48068d52013-02-05 18:08:49 +0900409 if (!pdata || !cfg)
Milo(Woogyom) Kima85908d2013-02-05 18:07:20 +0900410 return -EINVAL;
411
Sebastian Reichel30dae2f2013-10-22 11:02:56 -0700412 if (gpio_is_valid(pdata->enable_gpio)) {
413 ret = devm_gpio_request_one(dev, pdata->enable_gpio,
414 GPIOF_DIR_OUT, "lp5523_enable");
Milo(Woogyom) Kima85908d2013-02-05 18:07:20 +0900415 if (ret < 0) {
Sebastian Reichel30dae2f2013-10-22 11:02:56 -0700416 dev_err(dev, "could not acquire enable gpio (err=%d)\n",
417 ret);
Milo(Woogyom) Kima85908d2013-02-05 18:07:20 +0900418 goto err;
419 }
Milo(Woogyom) Kima85908d2013-02-05 18:07:20 +0900420
Sebastian Reichel30dae2f2013-10-22 11:02:56 -0700421 gpio_set_value(pdata->enable_gpio, 0);
Milo(Woogyom) Kima85908d2013-02-05 18:07:20 +0900422 usleep_range(1000, 2000); /* Keep enable down at least 1ms */
Sebastian Reichel30dae2f2013-10-22 11:02:56 -0700423 gpio_set_value(pdata->enable_gpio, 1);
Milo(Woogyom) Kima85908d2013-02-05 18:07:20 +0900424 usleep_range(1000, 2000); /* 500us abs min. */
425 }
426
Milo(Woogyom) Kim48068d52013-02-05 18:08:49 +0900427 lp55xx_reset_device(chip);
428
429 /*
430 * Exact value is not available. 10 - 20ms
431 * appears to be enough for reset.
432 */
433 usleep_range(10000, 20000);
434
Milo(Woogyom) Kime3a700d2013-02-05 18:09:56 +0900435 ret = lp55xx_detect_device(chip);
436 if (ret) {
437 dev_err(dev, "device detection err: %d\n", ret);
438 goto err;
439 }
440
Milo(Woogyom) Kimffbdccd2013-02-05 18:57:36 +0900441 /* chip specific initialization */
442 ret = lp55xx_post_init_device(chip);
Milo(Woogyom) Kim22ebeb42013-02-05 18:58:35 +0900443 if (ret) {
444 dev_err(dev, "post init device err: %d\n", ret);
445 goto err_post_init;
446 }
Milo(Woogyom) Kimffbdccd2013-02-05 18:57:36 +0900447
448 return 0;
449
Milo(Woogyom) Kim22ebeb42013-02-05 18:58:35 +0900450err_post_init:
Milo(Woogyom) Kim6ce61762013-02-05 19:03:02 +0900451 lp55xx_deinit_device(chip);
Milo(Woogyom) Kima85908d2013-02-05 18:07:20 +0900452err:
453 return ret;
454}
455EXPORT_SYMBOL_GPL(lp55xx_init_device);
456
Milo(Woogyom) Kim6ce61762013-02-05 19:03:02 +0900457void lp55xx_deinit_device(struct lp55xx_chip *chip)
458{
459 struct lp55xx_platform_data *pdata = chip->pdata;
460
Kim, Milo53b41922013-03-20 17:37:00 -0700461 if (chip->clk)
462 clk_disable_unprepare(chip->clk);
463
Sebastian Reichel30dae2f2013-10-22 11:02:56 -0700464 if (gpio_is_valid(pdata->enable_gpio))
465 gpio_set_value(pdata->enable_gpio, 0);
Milo(Woogyom) Kim6ce61762013-02-05 19:03:02 +0900466}
467EXPORT_SYMBOL_GPL(lp55xx_deinit_device);
468
Milo(Woogyom) Kim9e9b3db2013-02-05 19:06:27 +0900469int lp55xx_register_leds(struct lp55xx_led *led, struct lp55xx_chip *chip)
470{
471 struct lp55xx_platform_data *pdata = chip->pdata;
472 struct lp55xx_device_config *cfg = chip->cfg;
473 int num_channels = pdata->num_channels;
474 struct lp55xx_led *each;
475 u8 led_current;
476 int ret;
477 int i;
478
479 if (!cfg->brightness_work_fn) {
480 dev_err(&chip->cl->dev, "empty brightness configuration\n");
481 return -EINVAL;
482 }
483
484 for (i = 0; i < num_channels; i++) {
485
486 /* do not initialize channels that are not connected */
487 if (pdata->led_config[i].led_current == 0)
488 continue;
489
490 led_current = pdata->led_config[i].led_current;
491 each = led + i;
492 ret = lp55xx_init_led(each, chip, i);
493 if (ret)
494 goto err_init_led;
495
496 INIT_WORK(&each->brightness_work, cfg->brightness_work_fn);
497
498 chip->num_leds++;
499 each->chip = chip;
500
501 /* setting led current at each channel */
502 if (cfg->set_led_current)
503 cfg->set_led_current(each, led_current);
504 }
505
506 return 0;
507
508err_init_led:
Milo(Woogyom) Kimd9067d22013-02-05 19:12:47 +0900509 lp55xx_unregister_leds(led, chip);
Milo(Woogyom) Kim9e9b3db2013-02-05 19:06:27 +0900510 return ret;
511}
512EXPORT_SYMBOL_GPL(lp55xx_register_leds);
513
Milo(Woogyom) Kimc3a68eb2013-02-05 19:11:18 +0900514void lp55xx_unregister_leds(struct lp55xx_led *led, struct lp55xx_chip *chip)
515{
516 int i;
517 struct lp55xx_led *each;
Milo(Woogyom) Kimc3a68eb2013-02-05 19:11:18 +0900518
519 for (i = 0; i < chip->num_leds; i++) {
520 each = led + i;
Milo(Woogyom) Kimc3a68eb2013-02-05 19:11:18 +0900521 led_classdev_unregister(&each->cdev);
522 flush_work(&each->brightness_work);
523 }
524}
525EXPORT_SYMBOL_GPL(lp55xx_unregister_leds);
526
Milo(Woogyom) Kimb3b6f812013-02-05 19:15:27 +0900527int lp55xx_register_sysfs(struct lp55xx_chip *chip)
528{
529 struct device *dev = &chip->cl->dev;
Milo(Woogyom) Kim240085e2013-02-05 19:20:01 +0900530 struct lp55xx_device_config *cfg = chip->cfg;
531 int ret;
Milo(Woogyom) Kimb3b6f812013-02-05 19:15:27 +0900532
Milo(Woogyom) Kim240085e2013-02-05 19:20:01 +0900533 if (!cfg->run_engine || !cfg->firmware_cb)
534 goto dev_specific_attrs;
535
536 ret = sysfs_create_group(&dev->kobj, &lp55xx_engine_attr_group);
537 if (ret)
538 return ret;
539
540dev_specific_attrs:
541 return cfg->dev_attr_group ?
542 sysfs_create_group(&dev->kobj, cfg->dev_attr_group) : 0;
Milo(Woogyom) Kimb3b6f812013-02-05 19:15:27 +0900543}
544EXPORT_SYMBOL_GPL(lp55xx_register_sysfs);
545
Milo(Woogyom) Kimba6fa842013-02-05 19:23:04 +0900546void lp55xx_unregister_sysfs(struct lp55xx_chip *chip)
547{
548 struct device *dev = &chip->cl->dev;
549 struct lp55xx_device_config *cfg = chip->cfg;
550
551 if (cfg->dev_attr_group)
552 sysfs_remove_group(&dev->kobj, cfg->dev_attr_group);
553
554 sysfs_remove_group(&dev->kobj, &lp55xx_engine_attr_group);
555}
556EXPORT_SYMBOL_GPL(lp55xx_unregister_sysfs);
557
Linus Walleij7542a042013-04-23 04:52:59 -0700558int lp55xx_of_populate_pdata(struct device *dev, struct device_node *np)
559{
Kim, Milo2dac9122013-05-07 00:14:48 -0700560 struct device_node *child;
Linus Walleij7542a042013-04-23 04:52:59 -0700561 struct lp55xx_platform_data *pdata;
Kim, Milo2dac9122013-05-07 00:14:48 -0700562 struct lp55xx_led_config *cfg;
563 int num_channels;
564 int i = 0;
Linus Walleij7542a042013-04-23 04:52:59 -0700565
566 pdata = devm_kzalloc(dev, sizeof(*pdata), GFP_KERNEL);
567 if (!pdata)
568 return -ENOMEM;
569
Kim, Milo2dac9122013-05-07 00:14:48 -0700570 num_channels = of_get_child_count(np);
571 if (num_channels == 0) {
572 dev_err(dev, "no LED channels\n");
573 return -EINVAL;
574 }
Linus Walleij7542a042013-04-23 04:52:59 -0700575
Kim, Milo2dac9122013-05-07 00:14:48 -0700576 cfg = devm_kzalloc(dev, sizeof(*cfg) * num_channels, GFP_KERNEL);
577 if (!cfg)
Linus Walleij7542a042013-04-23 04:52:59 -0700578 return -ENOMEM;
579
Kim, Milo2dac9122013-05-07 00:14:48 -0700580 pdata->led_config = &cfg[0];
581 pdata->num_channels = num_channels;
582
583 for_each_child_of_node(np, child) {
584 cfg[i].chan_nr = i;
585
586 of_property_read_string(child, "chan-name", &cfg[i].name);
587 of_property_read_u8(child, "led-cur", &cfg[i].led_current);
588 of_property_read_u8(child, "max-cur", &cfg[i].max_current);
Linus Walleijf65f0a12013-09-15 03:50:17 -0700589 cfg[i].default_trigger =
590 of_get_property(child, "linux,default-trigger", NULL);
Kim, Milo2dac9122013-05-07 00:14:48 -0700591
592 i++;
Linus Walleij7542a042013-04-23 04:52:59 -0700593 }
Kim, Milo2dac9122013-05-07 00:14:48 -0700594
595 of_property_read_string(np, "label", &pdata->label);
596 of_property_read_u8(np, "clock-mode", &pdata->clock_mode);
597
Sebastian Reichel30dae2f2013-10-22 11:02:56 -0700598 pdata->enable_gpio = of_get_named_gpio(np, "enable-gpio", 0);
599
Kim, Milo33b3a562013-07-09 02:11:37 -0700600 /* LP8501 specific */
601 of_property_read_u8(np, "pwr-sel", (u8 *)&pdata->pwr_sel);
602
Linus Walleij7542a042013-04-23 04:52:59 -0700603 dev->platform_data = pdata;
604
605 return 0;
606}
607EXPORT_SYMBOL_GPL(lp55xx_of_populate_pdata);
608
Milo(Woogyom) Kimc93d08f2013-02-05 18:01:23 +0900609MODULE_AUTHOR("Milo Kim <milo.kim@ti.com>");
610MODULE_DESCRIPTION("LP55xx Common Driver");
611MODULE_LICENSE("GPL");