Linux 4.1.16
[linux/fpc-iii.git] / drivers / leds / leds-lm3533.c
blob6e2e02035dd7b9c43c00e4bf19145152efdacc0c
1 /*
2 * leds-lm3533.c -- LM3533 LED driver
4 * Copyright (C) 2011-2012 Texas Instruments
6 * Author: Johan Hovold <jhovold@gmail.com>
8 * This program is free software; you can redistribute it and/or modify it
9 * under the terms of the GNU General Public License as published by the
10 * Free Software Foundation; either version 2 of the License, or (at your
11 * option) any later version.
14 #include <linux/module.h>
15 #include <linux/leds.h>
16 #include <linux/mfd/core.h>
17 #include <linux/mutex.h>
18 #include <linux/platform_device.h>
19 #include <linux/slab.h>
20 #include <linux/workqueue.h>
22 #include <linux/mfd/lm3533.h>
25 #define LM3533_LVCTRLBANK_MIN 2
26 #define LM3533_LVCTRLBANK_MAX 5
27 #define LM3533_LVCTRLBANK_COUNT 4
28 #define LM3533_RISEFALLTIME_MAX 7
29 #define LM3533_ALS_CHANNEL_LV_MIN 1
30 #define LM3533_ALS_CHANNEL_LV_MAX 2
32 #define LM3533_REG_CTRLBANK_BCONF_BASE 0x1b
33 #define LM3533_REG_PATTERN_ENABLE 0x28
34 #define LM3533_REG_PATTERN_LOW_TIME_BASE 0x71
35 #define LM3533_REG_PATTERN_HIGH_TIME_BASE 0x72
36 #define LM3533_REG_PATTERN_RISETIME_BASE 0x74
37 #define LM3533_REG_PATTERN_FALLTIME_BASE 0x75
39 #define LM3533_REG_PATTERN_STEP 0x10
41 #define LM3533_REG_CTRLBANK_BCONF_MAPPING_MASK 0x04
42 #define LM3533_REG_CTRLBANK_BCONF_ALS_EN_MASK 0x02
43 #define LM3533_REG_CTRLBANK_BCONF_ALS_CHANNEL_MASK 0x01
45 #define LM3533_LED_FLAG_PATTERN_ENABLE 1
48 struct lm3533_led {
49 struct lm3533 *lm3533;
50 struct lm3533_ctrlbank cb;
51 struct led_classdev cdev;
52 int id;
54 struct mutex mutex;
55 unsigned long flags;
57 struct work_struct work;
58 u8 new_brightness;
62 static inline struct lm3533_led *to_lm3533_led(struct led_classdev *cdev)
64 return container_of(cdev, struct lm3533_led, cdev);
67 static inline int lm3533_led_get_ctrlbank_id(struct lm3533_led *led)
69 return led->id + 2;
72 static inline u8 lm3533_led_get_lv_reg(struct lm3533_led *led, u8 base)
74 return base + led->id;
77 static inline u8 lm3533_led_get_pattern(struct lm3533_led *led)
79 return led->id;
82 static inline u8 lm3533_led_get_pattern_reg(struct lm3533_led *led,
83 u8 base)
85 return base + lm3533_led_get_pattern(led) * LM3533_REG_PATTERN_STEP;
88 static int lm3533_led_pattern_enable(struct lm3533_led *led, int enable)
90 u8 mask;
91 u8 val;
92 int pattern;
93 int state;
94 int ret = 0;
96 dev_dbg(led->cdev.dev, "%s - %d\n", __func__, enable);
98 mutex_lock(&led->mutex);
100 state = test_bit(LM3533_LED_FLAG_PATTERN_ENABLE, &led->flags);
101 if ((enable && state) || (!enable && !state))
102 goto out;
104 pattern = lm3533_led_get_pattern(led);
105 mask = 1 << (2 * pattern);
107 if (enable)
108 val = mask;
109 else
110 val = 0;
112 ret = lm3533_update(led->lm3533, LM3533_REG_PATTERN_ENABLE, val, mask);
113 if (ret) {
114 dev_err(led->cdev.dev, "failed to enable pattern %d (%d)\n",
115 pattern, enable);
116 goto out;
119 __change_bit(LM3533_LED_FLAG_PATTERN_ENABLE, &led->flags);
120 out:
121 mutex_unlock(&led->mutex);
123 return ret;
126 static void lm3533_led_work(struct work_struct *work)
128 struct lm3533_led *led = container_of(work, struct lm3533_led, work);
130 dev_dbg(led->cdev.dev, "%s - %u\n", __func__, led->new_brightness);
132 if (led->new_brightness == 0)
133 lm3533_led_pattern_enable(led, 0); /* disable blink */
135 lm3533_ctrlbank_set_brightness(&led->cb, led->new_brightness);
138 static void lm3533_led_set(struct led_classdev *cdev,
139 enum led_brightness value)
141 struct lm3533_led *led = to_lm3533_led(cdev);
143 dev_dbg(led->cdev.dev, "%s - %d\n", __func__, value);
145 led->new_brightness = value;
146 schedule_work(&led->work);
149 static enum led_brightness lm3533_led_get(struct led_classdev *cdev)
151 struct lm3533_led *led = to_lm3533_led(cdev);
152 u8 val;
153 int ret;
155 ret = lm3533_ctrlbank_get_brightness(&led->cb, &val);
156 if (ret)
157 return ret;
159 dev_dbg(led->cdev.dev, "%s - %u\n", __func__, val);
161 return val;
164 /* Pattern generator defines (delays in us). */
165 #define LM3533_LED_DELAY1_VMIN 0x00
166 #define LM3533_LED_DELAY2_VMIN 0x3d
167 #define LM3533_LED_DELAY3_VMIN 0x80
169 #define LM3533_LED_DELAY1_VMAX (LM3533_LED_DELAY2_VMIN - 1)
170 #define LM3533_LED_DELAY2_VMAX (LM3533_LED_DELAY3_VMIN - 1)
171 #define LM3533_LED_DELAY3_VMAX 0xff
173 #define LM3533_LED_DELAY1_TMIN 16384U
174 #define LM3533_LED_DELAY2_TMIN 1130496U
175 #define LM3533_LED_DELAY3_TMIN 10305536U
177 #define LM3533_LED_DELAY1_TMAX 999424U
178 #define LM3533_LED_DELAY2_TMAX 9781248U
179 #define LM3533_LED_DELAY3_TMAX 76890112U
181 /* t_step = (t_max - t_min) / (v_max - v_min) */
182 #define LM3533_LED_DELAY1_TSTEP 16384
183 #define LM3533_LED_DELAY2_TSTEP 131072
184 #define LM3533_LED_DELAY3_TSTEP 524288
186 /* Delay limits for hardware accelerated blinking (in ms). */
187 #define LM3533_LED_DELAY_ON_MAX \
188 ((LM3533_LED_DELAY2_TMAX + LM3533_LED_DELAY2_TSTEP / 2) / 1000)
189 #define LM3533_LED_DELAY_OFF_MAX \
190 ((LM3533_LED_DELAY3_TMAX + LM3533_LED_DELAY3_TSTEP / 2) / 1000)
193 * Returns linear map of *t from [t_min,t_max] to [v_min,v_max] with a step
194 * size of t_step, where
196 * t_step = (t_max - t_min) / (v_max - v_min)
198 * and updates *t to reflect the mapped value.
200 static u8 time_to_val(unsigned *t, unsigned t_min, unsigned t_step,
201 u8 v_min, u8 v_max)
203 unsigned val;
205 val = (*t + t_step / 2 - t_min) / t_step + v_min;
207 *t = t_step * (val - v_min) + t_min;
209 return (u8)val;
213 * Returns time code corresponding to *delay (in ms) and updates *delay to
214 * reflect actual hardware delay.
216 * Hardware supports 256 discrete delay times, divided into three groups with
217 * the following ranges and step-sizes:
219 * [ 16, 999] [0x00, 0x3e] step 16 ms
220 * [ 1130, 9781] [0x3d, 0x7f] step 131 ms
221 * [10306, 76890] [0x80, 0xff] step 524 ms
223 * Note that delay group 3 is only available for delay_off.
225 static u8 lm3533_led_get_hw_delay(unsigned *delay)
227 unsigned t;
228 u8 val;
230 t = *delay * 1000;
232 if (t >= (LM3533_LED_DELAY2_TMAX + LM3533_LED_DELAY3_TMIN) / 2) {
233 t = clamp(t, LM3533_LED_DELAY3_TMIN, LM3533_LED_DELAY3_TMAX);
234 val = time_to_val(&t, LM3533_LED_DELAY3_TMIN,
235 LM3533_LED_DELAY3_TSTEP,
236 LM3533_LED_DELAY3_VMIN,
237 LM3533_LED_DELAY3_VMAX);
238 } else if (t >= (LM3533_LED_DELAY1_TMAX + LM3533_LED_DELAY2_TMIN) / 2) {
239 t = clamp(t, LM3533_LED_DELAY2_TMIN, LM3533_LED_DELAY2_TMAX);
240 val = time_to_val(&t, LM3533_LED_DELAY2_TMIN,
241 LM3533_LED_DELAY2_TSTEP,
242 LM3533_LED_DELAY2_VMIN,
243 LM3533_LED_DELAY2_VMAX);
244 } else {
245 t = clamp(t, LM3533_LED_DELAY1_TMIN, LM3533_LED_DELAY1_TMAX);
246 val = time_to_val(&t, LM3533_LED_DELAY1_TMIN,
247 LM3533_LED_DELAY1_TSTEP,
248 LM3533_LED_DELAY1_VMIN,
249 LM3533_LED_DELAY1_VMAX);
252 *delay = (t + 500) / 1000;
254 return val;
258 * Set delay register base to *delay (in ms) and update *delay to reflect
259 * actual hardware delay used.
261 static u8 lm3533_led_delay_set(struct lm3533_led *led, u8 base,
262 unsigned long *delay)
264 unsigned t;
265 u8 val;
266 u8 reg;
267 int ret;
269 t = (unsigned)*delay;
271 /* Delay group 3 is only available for low time (delay off). */
272 if (base != LM3533_REG_PATTERN_LOW_TIME_BASE)
273 t = min(t, LM3533_LED_DELAY2_TMAX / 1000);
275 val = lm3533_led_get_hw_delay(&t);
277 dev_dbg(led->cdev.dev, "%s - %lu: %u (0x%02x)\n", __func__,
278 *delay, t, val);
279 reg = lm3533_led_get_pattern_reg(led, base);
280 ret = lm3533_write(led->lm3533, reg, val);
281 if (ret)
282 dev_err(led->cdev.dev, "failed to set delay (%02x)\n", reg);
284 *delay = t;
286 return ret;
289 static int lm3533_led_delay_on_set(struct lm3533_led *led, unsigned long *t)
291 return lm3533_led_delay_set(led, LM3533_REG_PATTERN_HIGH_TIME_BASE, t);
294 static int lm3533_led_delay_off_set(struct lm3533_led *led, unsigned long *t)
296 return lm3533_led_delay_set(led, LM3533_REG_PATTERN_LOW_TIME_BASE, t);
299 static int lm3533_led_blink_set(struct led_classdev *cdev,
300 unsigned long *delay_on,
301 unsigned long *delay_off)
303 struct lm3533_led *led = to_lm3533_led(cdev);
304 int ret;
306 dev_dbg(led->cdev.dev, "%s - on = %lu, off = %lu\n", __func__,
307 *delay_on, *delay_off);
309 if (*delay_on > LM3533_LED_DELAY_ON_MAX ||
310 *delay_off > LM3533_LED_DELAY_OFF_MAX)
311 return -EINVAL;
313 if (*delay_on == 0 && *delay_off == 0) {
314 *delay_on = 500;
315 *delay_off = 500;
318 ret = lm3533_led_delay_on_set(led, delay_on);
319 if (ret)
320 return ret;
322 ret = lm3533_led_delay_off_set(led, delay_off);
323 if (ret)
324 return ret;
326 return lm3533_led_pattern_enable(led, 1);
329 static ssize_t show_id(struct device *dev,
330 struct device_attribute *attr, char *buf)
332 struct led_classdev *led_cdev = dev_get_drvdata(dev);
333 struct lm3533_led *led = to_lm3533_led(led_cdev);
335 return scnprintf(buf, PAGE_SIZE, "%d\n", led->id);
339 * Pattern generator rise/fall times:
341 * 0 - 2048 us (default)
342 * 1 - 262 ms
343 * 2 - 524 ms
344 * 3 - 1.049 s
345 * 4 - 2.097 s
346 * 5 - 4.194 s
347 * 6 - 8.389 s
348 * 7 - 16.78 s
350 static ssize_t show_risefalltime(struct device *dev,
351 struct device_attribute *attr,
352 char *buf, u8 base)
354 struct led_classdev *led_cdev = dev_get_drvdata(dev);
355 struct lm3533_led *led = to_lm3533_led(led_cdev);
356 ssize_t ret;
357 u8 reg;
358 u8 val;
360 reg = lm3533_led_get_pattern_reg(led, base);
361 ret = lm3533_read(led->lm3533, reg, &val);
362 if (ret)
363 return ret;
365 return scnprintf(buf, PAGE_SIZE, "%x\n", val);
368 static ssize_t show_risetime(struct device *dev,
369 struct device_attribute *attr, char *buf)
371 return show_risefalltime(dev, attr, buf,
372 LM3533_REG_PATTERN_RISETIME_BASE);
375 static ssize_t show_falltime(struct device *dev,
376 struct device_attribute *attr, char *buf)
378 return show_risefalltime(dev, attr, buf,
379 LM3533_REG_PATTERN_FALLTIME_BASE);
382 static ssize_t store_risefalltime(struct device *dev,
383 struct device_attribute *attr,
384 const char *buf, size_t len, u8 base)
386 struct led_classdev *led_cdev = dev_get_drvdata(dev);
387 struct lm3533_led *led = to_lm3533_led(led_cdev);
388 u8 val;
389 u8 reg;
390 int ret;
392 if (kstrtou8(buf, 0, &val) || val > LM3533_RISEFALLTIME_MAX)
393 return -EINVAL;
395 reg = lm3533_led_get_pattern_reg(led, base);
396 ret = lm3533_write(led->lm3533, reg, val);
397 if (ret)
398 return ret;
400 return len;
403 static ssize_t store_risetime(struct device *dev,
404 struct device_attribute *attr,
405 const char *buf, size_t len)
407 return store_risefalltime(dev, attr, buf, len,
408 LM3533_REG_PATTERN_RISETIME_BASE);
411 static ssize_t store_falltime(struct device *dev,
412 struct device_attribute *attr,
413 const char *buf, size_t len)
415 return store_risefalltime(dev, attr, buf, len,
416 LM3533_REG_PATTERN_FALLTIME_BASE);
419 static ssize_t show_als_channel(struct device *dev,
420 struct device_attribute *attr, char *buf)
422 struct led_classdev *led_cdev = dev_get_drvdata(dev);
423 struct lm3533_led *led = to_lm3533_led(led_cdev);
424 unsigned channel;
425 u8 reg;
426 u8 val;
427 int ret;
429 reg = lm3533_led_get_lv_reg(led, LM3533_REG_CTRLBANK_BCONF_BASE);
430 ret = lm3533_read(led->lm3533, reg, &val);
431 if (ret)
432 return ret;
434 channel = (val & LM3533_REG_CTRLBANK_BCONF_ALS_CHANNEL_MASK) + 1;
436 return scnprintf(buf, PAGE_SIZE, "%u\n", channel);
439 static ssize_t store_als_channel(struct device *dev,
440 struct device_attribute *attr,
441 const char *buf, size_t len)
443 struct led_classdev *led_cdev = dev_get_drvdata(dev);
444 struct lm3533_led *led = to_lm3533_led(led_cdev);
445 unsigned channel;
446 u8 reg;
447 u8 val;
448 u8 mask;
449 int ret;
451 if (kstrtouint(buf, 0, &channel))
452 return -EINVAL;
454 if (channel < LM3533_ALS_CHANNEL_LV_MIN ||
455 channel > LM3533_ALS_CHANNEL_LV_MAX)
456 return -EINVAL;
458 reg = lm3533_led_get_lv_reg(led, LM3533_REG_CTRLBANK_BCONF_BASE);
459 mask = LM3533_REG_CTRLBANK_BCONF_ALS_CHANNEL_MASK;
460 val = channel - 1;
462 ret = lm3533_update(led->lm3533, reg, val, mask);
463 if (ret)
464 return ret;
466 return len;
469 static ssize_t show_als_en(struct device *dev,
470 struct device_attribute *attr, char *buf)
472 struct led_classdev *led_cdev = dev_get_drvdata(dev);
473 struct lm3533_led *led = to_lm3533_led(led_cdev);
474 bool enable;
475 u8 reg;
476 u8 val;
477 int ret;
479 reg = lm3533_led_get_lv_reg(led, LM3533_REG_CTRLBANK_BCONF_BASE);
480 ret = lm3533_read(led->lm3533, reg, &val);
481 if (ret)
482 return ret;
484 enable = val & LM3533_REG_CTRLBANK_BCONF_ALS_EN_MASK;
486 return scnprintf(buf, PAGE_SIZE, "%d\n", enable);
489 static ssize_t store_als_en(struct device *dev,
490 struct device_attribute *attr,
491 const char *buf, size_t len)
493 struct led_classdev *led_cdev = dev_get_drvdata(dev);
494 struct lm3533_led *led = to_lm3533_led(led_cdev);
495 unsigned enable;
496 u8 reg;
497 u8 mask;
498 u8 val;
499 int ret;
501 if (kstrtouint(buf, 0, &enable))
502 return -EINVAL;
504 reg = lm3533_led_get_lv_reg(led, LM3533_REG_CTRLBANK_BCONF_BASE);
505 mask = LM3533_REG_CTRLBANK_BCONF_ALS_EN_MASK;
507 if (enable)
508 val = mask;
509 else
510 val = 0;
512 ret = lm3533_update(led->lm3533, reg, val, mask);
513 if (ret)
514 return ret;
516 return len;
519 static ssize_t show_linear(struct device *dev,
520 struct device_attribute *attr, char *buf)
522 struct led_classdev *led_cdev = dev_get_drvdata(dev);
523 struct lm3533_led *led = to_lm3533_led(led_cdev);
524 u8 reg;
525 u8 val;
526 int linear;
527 int ret;
529 reg = lm3533_led_get_lv_reg(led, LM3533_REG_CTRLBANK_BCONF_BASE);
530 ret = lm3533_read(led->lm3533, reg, &val);
531 if (ret)
532 return ret;
534 if (val & LM3533_REG_CTRLBANK_BCONF_MAPPING_MASK)
535 linear = 1;
536 else
537 linear = 0;
539 return scnprintf(buf, PAGE_SIZE, "%x\n", linear);
542 static ssize_t store_linear(struct device *dev,
543 struct device_attribute *attr,
544 const char *buf, size_t len)
546 struct led_classdev *led_cdev = dev_get_drvdata(dev);
547 struct lm3533_led *led = to_lm3533_led(led_cdev);
548 unsigned long linear;
549 u8 reg;
550 u8 mask;
551 u8 val;
552 int ret;
554 if (kstrtoul(buf, 0, &linear))
555 return -EINVAL;
557 reg = lm3533_led_get_lv_reg(led, LM3533_REG_CTRLBANK_BCONF_BASE);
558 mask = LM3533_REG_CTRLBANK_BCONF_MAPPING_MASK;
560 if (linear)
561 val = mask;
562 else
563 val = 0;
565 ret = lm3533_update(led->lm3533, reg, val, mask);
566 if (ret)
567 return ret;
569 return len;
572 static ssize_t show_pwm(struct device *dev,
573 struct device_attribute *attr,
574 char *buf)
576 struct led_classdev *led_cdev = dev_get_drvdata(dev);
577 struct lm3533_led *led = to_lm3533_led(led_cdev);
578 u8 val;
579 int ret;
581 ret = lm3533_ctrlbank_get_pwm(&led->cb, &val);
582 if (ret)
583 return ret;
585 return scnprintf(buf, PAGE_SIZE, "%u\n", val);
588 static ssize_t store_pwm(struct device *dev,
589 struct device_attribute *attr,
590 const char *buf, size_t len)
592 struct led_classdev *led_cdev = dev_get_drvdata(dev);
593 struct lm3533_led *led = to_lm3533_led(led_cdev);
594 u8 val;
595 int ret;
597 if (kstrtou8(buf, 0, &val))
598 return -EINVAL;
600 ret = lm3533_ctrlbank_set_pwm(&led->cb, val);
601 if (ret)
602 return ret;
604 return len;
607 static LM3533_ATTR_RW(als_channel);
608 static LM3533_ATTR_RW(als_en);
609 static LM3533_ATTR_RW(falltime);
610 static LM3533_ATTR_RO(id);
611 static LM3533_ATTR_RW(linear);
612 static LM3533_ATTR_RW(pwm);
613 static LM3533_ATTR_RW(risetime);
615 static struct attribute *lm3533_led_attributes[] = {
616 &dev_attr_als_channel.attr,
617 &dev_attr_als_en.attr,
618 &dev_attr_falltime.attr,
619 &dev_attr_id.attr,
620 &dev_attr_linear.attr,
621 &dev_attr_pwm.attr,
622 &dev_attr_risetime.attr,
623 NULL,
626 static umode_t lm3533_led_attr_is_visible(struct kobject *kobj,
627 struct attribute *attr, int n)
629 struct device *dev = container_of(kobj, struct device, kobj);
630 struct led_classdev *led_cdev = dev_get_drvdata(dev);
631 struct lm3533_led *led = to_lm3533_led(led_cdev);
632 umode_t mode = attr->mode;
634 if (attr == &dev_attr_als_channel.attr ||
635 attr == &dev_attr_als_en.attr) {
636 if (!led->lm3533->have_als)
637 mode = 0;
640 return mode;
643 static struct attribute_group lm3533_led_attribute_group = {
644 .is_visible = lm3533_led_attr_is_visible,
645 .attrs = lm3533_led_attributes
648 static const struct attribute_group *lm3533_led_attribute_groups[] = {
649 &lm3533_led_attribute_group,
650 NULL
653 static int lm3533_led_setup(struct lm3533_led *led,
654 struct lm3533_led_platform_data *pdata)
656 int ret;
658 ret = lm3533_ctrlbank_set_max_current(&led->cb, pdata->max_current);
659 if (ret)
660 return ret;
662 return lm3533_ctrlbank_set_pwm(&led->cb, pdata->pwm);
665 static int lm3533_led_probe(struct platform_device *pdev)
667 struct lm3533 *lm3533;
668 struct lm3533_led_platform_data *pdata;
669 struct lm3533_led *led;
670 int ret;
672 dev_dbg(&pdev->dev, "%s\n", __func__);
674 lm3533 = dev_get_drvdata(pdev->dev.parent);
675 if (!lm3533)
676 return -EINVAL;
678 pdata = dev_get_platdata(&pdev->dev);
679 if (!pdata) {
680 dev_err(&pdev->dev, "no platform data\n");
681 return -EINVAL;
684 if (pdev->id < 0 || pdev->id >= LM3533_LVCTRLBANK_COUNT) {
685 dev_err(&pdev->dev, "illegal LED id %d\n", pdev->id);
686 return -EINVAL;
689 led = devm_kzalloc(&pdev->dev, sizeof(*led), GFP_KERNEL);
690 if (!led)
691 return -ENOMEM;
693 led->lm3533 = lm3533;
694 led->cdev.name = pdata->name;
695 led->cdev.default_trigger = pdata->default_trigger;
696 led->cdev.brightness_set = lm3533_led_set;
697 led->cdev.brightness_get = lm3533_led_get;
698 led->cdev.blink_set = lm3533_led_blink_set;
699 led->cdev.brightness = LED_OFF;
700 led->cdev.groups = lm3533_led_attribute_groups,
701 led->id = pdev->id;
703 mutex_init(&led->mutex);
704 INIT_WORK(&led->work, lm3533_led_work);
706 /* The class framework makes a callback to get brightness during
707 * registration so use parent device (for error reporting) until
708 * registered.
710 led->cb.lm3533 = lm3533;
711 led->cb.id = lm3533_led_get_ctrlbank_id(led);
712 led->cb.dev = lm3533->dev;
714 platform_set_drvdata(pdev, led);
716 ret = led_classdev_register(pdev->dev.parent, &led->cdev);
717 if (ret) {
718 dev_err(&pdev->dev, "failed to register LED %d\n", pdev->id);
719 return ret;
722 led->cb.dev = led->cdev.dev;
724 ret = lm3533_led_setup(led, pdata);
725 if (ret)
726 goto err_unregister;
728 ret = lm3533_ctrlbank_enable(&led->cb);
729 if (ret)
730 goto err_unregister;
732 return 0;
734 err_unregister:
735 led_classdev_unregister(&led->cdev);
736 flush_work(&led->work);
738 return ret;
741 static int lm3533_led_remove(struct platform_device *pdev)
743 struct lm3533_led *led = platform_get_drvdata(pdev);
745 dev_dbg(&pdev->dev, "%s\n", __func__);
747 lm3533_ctrlbank_disable(&led->cb);
748 led_classdev_unregister(&led->cdev);
749 flush_work(&led->work);
751 return 0;
754 static void lm3533_led_shutdown(struct platform_device *pdev)
757 struct lm3533_led *led = platform_get_drvdata(pdev);
759 dev_dbg(&pdev->dev, "%s\n", __func__);
761 lm3533_ctrlbank_disable(&led->cb);
762 lm3533_led_set(&led->cdev, LED_OFF); /* disable blink */
763 flush_work(&led->work);
766 static struct platform_driver lm3533_led_driver = {
767 .driver = {
768 .name = "lm3533-leds",
770 .probe = lm3533_led_probe,
771 .remove = lm3533_led_remove,
772 .shutdown = lm3533_led_shutdown,
774 module_platform_driver(lm3533_led_driver);
776 MODULE_AUTHOR("Johan Hovold <jhovold@gmail.com>");
777 MODULE_DESCRIPTION("LM3533 LED driver");
778 MODULE_LICENSE("GPL");
779 MODULE_ALIAS("platform:lm3533-leds");