x86/xen: resume timer irqs early
[linux/fpc-iii.git] / drivers / leds / leds-lm3533.c
blob027ede73b80da01d716aacd6dbd2d07e20b90092
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/init.h>
16 #include <linux/leds.h>
17 #include <linux/mfd/core.h>
18 #include <linux/mutex.h>
19 #include <linux/platform_device.h>
20 #include <linux/slab.h>
21 #include <linux/workqueue.h>
23 #include <linux/mfd/lm3533.h>
26 #define LM3533_LVCTRLBANK_MIN 2
27 #define LM3533_LVCTRLBANK_MAX 5
28 #define LM3533_LVCTRLBANK_COUNT 4
29 #define LM3533_RISEFALLTIME_MAX 7
30 #define LM3533_ALS_CHANNEL_LV_MIN 1
31 #define LM3533_ALS_CHANNEL_LV_MAX 2
33 #define LM3533_REG_CTRLBANK_BCONF_BASE 0x1b
34 #define LM3533_REG_PATTERN_ENABLE 0x28
35 #define LM3533_REG_PATTERN_LOW_TIME_BASE 0x71
36 #define LM3533_REG_PATTERN_HIGH_TIME_BASE 0x72
37 #define LM3533_REG_PATTERN_RISETIME_BASE 0x74
38 #define LM3533_REG_PATTERN_FALLTIME_BASE 0x75
40 #define LM3533_REG_PATTERN_STEP 0x10
42 #define LM3533_REG_CTRLBANK_BCONF_MAPPING_MASK 0x04
43 #define LM3533_REG_CTRLBANK_BCONF_ALS_EN_MASK 0x02
44 #define LM3533_REG_CTRLBANK_BCONF_ALS_CHANNEL_MASK 0x01
46 #define LM3533_LED_FLAG_PATTERN_ENABLE 1
49 struct lm3533_led {
50 struct lm3533 *lm3533;
51 struct lm3533_ctrlbank cb;
52 struct led_classdev cdev;
53 int id;
55 struct mutex mutex;
56 unsigned long flags;
58 struct work_struct work;
59 u8 new_brightness;
63 static inline struct lm3533_led *to_lm3533_led(struct led_classdev *cdev)
65 return container_of(cdev, struct lm3533_led, cdev);
68 static inline int lm3533_led_get_ctrlbank_id(struct lm3533_led *led)
70 return led->id + 2;
73 static inline u8 lm3533_led_get_lv_reg(struct lm3533_led *led, u8 base)
75 return base + led->id;
78 static inline u8 lm3533_led_get_pattern(struct lm3533_led *led)
80 return led->id;
83 static inline u8 lm3533_led_get_pattern_reg(struct lm3533_led *led,
84 u8 base)
86 return base + lm3533_led_get_pattern(led) * LM3533_REG_PATTERN_STEP;
89 static int lm3533_led_pattern_enable(struct lm3533_led *led, int enable)
91 u8 mask;
92 u8 val;
93 int pattern;
94 int state;
95 int ret = 0;
97 dev_dbg(led->cdev.dev, "%s - %d\n", __func__, enable);
99 mutex_lock(&led->mutex);
101 state = test_bit(LM3533_LED_FLAG_PATTERN_ENABLE, &led->flags);
102 if ((enable && state) || (!enable && !state))
103 goto out;
105 pattern = lm3533_led_get_pattern(led);
106 mask = 1 << (2 * pattern);
108 if (enable)
109 val = mask;
110 else
111 val = 0;
113 ret = lm3533_update(led->lm3533, LM3533_REG_PATTERN_ENABLE, val, mask);
114 if (ret) {
115 dev_err(led->cdev.dev, "failed to enable pattern %d (%d)\n",
116 pattern, enable);
117 goto out;
120 __change_bit(LM3533_LED_FLAG_PATTERN_ENABLE, &led->flags);
121 out:
122 mutex_unlock(&led->mutex);
124 return ret;
127 static void lm3533_led_work(struct work_struct *work)
129 struct lm3533_led *led = container_of(work, struct lm3533_led, work);
131 dev_dbg(led->cdev.dev, "%s - %u\n", __func__, led->new_brightness);
133 if (led->new_brightness == 0)
134 lm3533_led_pattern_enable(led, 0); /* disable blink */
136 lm3533_ctrlbank_set_brightness(&led->cb, led->new_brightness);
139 static void lm3533_led_set(struct led_classdev *cdev,
140 enum led_brightness value)
142 struct lm3533_led *led = to_lm3533_led(cdev);
144 dev_dbg(led->cdev.dev, "%s - %d\n", __func__, value);
146 led->new_brightness = value;
147 schedule_work(&led->work);
150 static enum led_brightness lm3533_led_get(struct led_classdev *cdev)
152 struct lm3533_led *led = to_lm3533_led(cdev);
153 u8 val;
154 int ret;
156 ret = lm3533_ctrlbank_get_brightness(&led->cb, &val);
157 if (ret)
158 return ret;
160 dev_dbg(led->cdev.dev, "%s - %u\n", __func__, val);
162 return val;
165 /* Pattern generator defines (delays in us). */
166 #define LM3533_LED_DELAY1_VMIN 0x00
167 #define LM3533_LED_DELAY2_VMIN 0x3d
168 #define LM3533_LED_DELAY3_VMIN 0x80
170 #define LM3533_LED_DELAY1_VMAX (LM3533_LED_DELAY2_VMIN - 1)
171 #define LM3533_LED_DELAY2_VMAX (LM3533_LED_DELAY3_VMIN - 1)
172 #define LM3533_LED_DELAY3_VMAX 0xff
174 #define LM3533_LED_DELAY1_TMIN 16384U
175 #define LM3533_LED_DELAY2_TMIN 1130496U
176 #define LM3533_LED_DELAY3_TMIN 10305536U
178 #define LM3533_LED_DELAY1_TMAX 999424U
179 #define LM3533_LED_DELAY2_TMAX 9781248U
180 #define LM3533_LED_DELAY3_TMAX 76890112U
182 /* t_step = (t_max - t_min) / (v_max - v_min) */
183 #define LM3533_LED_DELAY1_TSTEP 16384
184 #define LM3533_LED_DELAY2_TSTEP 131072
185 #define LM3533_LED_DELAY3_TSTEP 524288
187 /* Delay limits for hardware accelerated blinking (in ms). */
188 #define LM3533_LED_DELAY_ON_MAX \
189 ((LM3533_LED_DELAY2_TMAX + LM3533_LED_DELAY2_TSTEP / 2) / 1000)
190 #define LM3533_LED_DELAY_OFF_MAX \
191 ((LM3533_LED_DELAY3_TMAX + LM3533_LED_DELAY3_TSTEP / 2) / 1000)
194 * Returns linear map of *t from [t_min,t_max] to [v_min,v_max] with a step
195 * size of t_step, where
197 * t_step = (t_max - t_min) / (v_max - v_min)
199 * and updates *t to reflect the mapped value.
201 static u8 time_to_val(unsigned *t, unsigned t_min, unsigned t_step,
202 u8 v_min, u8 v_max)
204 unsigned val;
206 val = (*t + t_step / 2 - t_min) / t_step + v_min;
208 *t = t_step * (val - v_min) + t_min;
210 return (u8)val;
214 * Returns time code corresponding to *delay (in ms) and updates *delay to
215 * reflect actual hardware delay.
217 * Hardware supports 256 discrete delay times, divided into three groups with
218 * the following ranges and step-sizes:
220 * [ 16, 999] [0x00, 0x3e] step 16 ms
221 * [ 1130, 9781] [0x3d, 0x7f] step 131 ms
222 * [10306, 76890] [0x80, 0xff] step 524 ms
224 * Note that delay group 3 is only available for delay_off.
226 static u8 lm3533_led_get_hw_delay(unsigned *delay)
228 unsigned t;
229 u8 val;
231 t = *delay * 1000;
233 if (t >= (LM3533_LED_DELAY2_TMAX + LM3533_LED_DELAY3_TMIN) / 2) {
234 t = clamp(t, LM3533_LED_DELAY3_TMIN, LM3533_LED_DELAY3_TMAX);
235 val = time_to_val(&t, LM3533_LED_DELAY3_TMIN,
236 LM3533_LED_DELAY3_TSTEP,
237 LM3533_LED_DELAY3_VMIN,
238 LM3533_LED_DELAY3_VMAX);
239 } else if (t >= (LM3533_LED_DELAY1_TMAX + LM3533_LED_DELAY2_TMIN) / 2) {
240 t = clamp(t, LM3533_LED_DELAY2_TMIN, LM3533_LED_DELAY2_TMAX);
241 val = time_to_val(&t, LM3533_LED_DELAY2_TMIN,
242 LM3533_LED_DELAY2_TSTEP,
243 LM3533_LED_DELAY2_VMIN,
244 LM3533_LED_DELAY2_VMAX);
245 } else {
246 t = clamp(t, LM3533_LED_DELAY1_TMIN, LM3533_LED_DELAY1_TMAX);
247 val = time_to_val(&t, LM3533_LED_DELAY1_TMIN,
248 LM3533_LED_DELAY1_TSTEP,
249 LM3533_LED_DELAY1_VMIN,
250 LM3533_LED_DELAY1_VMAX);
253 *delay = (t + 500) / 1000;
255 return val;
259 * Set delay register base to *delay (in ms) and update *delay to reflect
260 * actual hardware delay used.
262 static u8 lm3533_led_delay_set(struct lm3533_led *led, u8 base,
263 unsigned long *delay)
265 unsigned t;
266 u8 val;
267 u8 reg;
268 int ret;
270 t = (unsigned)*delay;
272 /* Delay group 3 is only available for low time (delay off). */
273 if (base != LM3533_REG_PATTERN_LOW_TIME_BASE)
274 t = min(t, LM3533_LED_DELAY2_TMAX / 1000);
276 val = lm3533_led_get_hw_delay(&t);
278 dev_dbg(led->cdev.dev, "%s - %lu: %u (0x%02x)\n", __func__,
279 *delay, t, val);
280 reg = lm3533_led_get_pattern_reg(led, base);
281 ret = lm3533_write(led->lm3533, reg, val);
282 if (ret)
283 dev_err(led->cdev.dev, "failed to set delay (%02x)\n", reg);
285 *delay = t;
287 return ret;
290 static int lm3533_led_delay_on_set(struct lm3533_led *led, unsigned long *t)
292 return lm3533_led_delay_set(led, LM3533_REG_PATTERN_HIGH_TIME_BASE, t);
295 static int lm3533_led_delay_off_set(struct lm3533_led *led, unsigned long *t)
297 return lm3533_led_delay_set(led, LM3533_REG_PATTERN_LOW_TIME_BASE, t);
300 static int lm3533_led_blink_set(struct led_classdev *cdev,
301 unsigned long *delay_on,
302 unsigned long *delay_off)
304 struct lm3533_led *led = to_lm3533_led(cdev);
305 int ret;
307 dev_dbg(led->cdev.dev, "%s - on = %lu, off = %lu\n", __func__,
308 *delay_on, *delay_off);
310 if (*delay_on > LM3533_LED_DELAY_ON_MAX ||
311 *delay_off > LM3533_LED_DELAY_OFF_MAX)
312 return -EINVAL;
314 if (*delay_on == 0 && *delay_off == 0) {
315 *delay_on = 500;
316 *delay_off = 500;
319 ret = lm3533_led_delay_on_set(led, delay_on);
320 if (ret)
321 return ret;
323 ret = lm3533_led_delay_off_set(led, delay_off);
324 if (ret)
325 return ret;
327 return lm3533_led_pattern_enable(led, 1);
330 static ssize_t show_id(struct device *dev,
331 struct device_attribute *attr, char *buf)
333 struct led_classdev *led_cdev = dev_get_drvdata(dev);
334 struct lm3533_led *led = to_lm3533_led(led_cdev);
336 return scnprintf(buf, PAGE_SIZE, "%d\n", led->id);
340 * Pattern generator rise/fall times:
342 * 0 - 2048 us (default)
343 * 1 - 262 ms
344 * 2 - 524 ms
345 * 3 - 1.049 s
346 * 4 - 2.097 s
347 * 5 - 4.194 s
348 * 6 - 8.389 s
349 * 7 - 16.78 s
351 static ssize_t show_risefalltime(struct device *dev,
352 struct device_attribute *attr,
353 char *buf, u8 base)
355 struct led_classdev *led_cdev = dev_get_drvdata(dev);
356 struct lm3533_led *led = to_lm3533_led(led_cdev);
357 ssize_t ret;
358 u8 reg;
359 u8 val;
361 reg = lm3533_led_get_pattern_reg(led, base);
362 ret = lm3533_read(led->lm3533, reg, &val);
363 if (ret)
364 return ret;
366 return scnprintf(buf, PAGE_SIZE, "%x\n", val);
369 static ssize_t show_risetime(struct device *dev,
370 struct device_attribute *attr, char *buf)
372 return show_risefalltime(dev, attr, buf,
373 LM3533_REG_PATTERN_RISETIME_BASE);
376 static ssize_t show_falltime(struct device *dev,
377 struct device_attribute *attr, char *buf)
379 return show_risefalltime(dev, attr, buf,
380 LM3533_REG_PATTERN_FALLTIME_BASE);
383 static ssize_t store_risefalltime(struct device *dev,
384 struct device_attribute *attr,
385 const char *buf, size_t len, u8 base)
387 struct led_classdev *led_cdev = dev_get_drvdata(dev);
388 struct lm3533_led *led = to_lm3533_led(led_cdev);
389 u8 val;
390 u8 reg;
391 int ret;
393 if (kstrtou8(buf, 0, &val) || val > LM3533_RISEFALLTIME_MAX)
394 return -EINVAL;
396 reg = lm3533_led_get_pattern_reg(led, base);
397 ret = lm3533_write(led->lm3533, reg, val);
398 if (ret)
399 return ret;
401 return len;
404 static ssize_t store_risetime(struct device *dev,
405 struct device_attribute *attr,
406 const char *buf, size_t len)
408 return store_risefalltime(dev, attr, buf, len,
409 LM3533_REG_PATTERN_RISETIME_BASE);
412 static ssize_t store_falltime(struct device *dev,
413 struct device_attribute *attr,
414 const char *buf, size_t len)
416 return store_risefalltime(dev, attr, buf, len,
417 LM3533_REG_PATTERN_FALLTIME_BASE);
420 static ssize_t show_als_channel(struct device *dev,
421 struct device_attribute *attr, char *buf)
423 struct led_classdev *led_cdev = dev_get_drvdata(dev);
424 struct lm3533_led *led = to_lm3533_led(led_cdev);
425 unsigned channel;
426 u8 reg;
427 u8 val;
428 int ret;
430 reg = lm3533_led_get_lv_reg(led, LM3533_REG_CTRLBANK_BCONF_BASE);
431 ret = lm3533_read(led->lm3533, reg, &val);
432 if (ret)
433 return ret;
435 channel = (val & LM3533_REG_CTRLBANK_BCONF_ALS_CHANNEL_MASK) + 1;
437 return scnprintf(buf, PAGE_SIZE, "%u\n", channel);
440 static ssize_t store_als_channel(struct device *dev,
441 struct device_attribute *attr,
442 const char *buf, size_t len)
444 struct led_classdev *led_cdev = dev_get_drvdata(dev);
445 struct lm3533_led *led = to_lm3533_led(led_cdev);
446 unsigned channel;
447 u8 reg;
448 u8 val;
449 u8 mask;
450 int ret;
452 if (kstrtouint(buf, 0, &channel))
453 return -EINVAL;
455 if (channel < LM3533_ALS_CHANNEL_LV_MIN ||
456 channel > LM3533_ALS_CHANNEL_LV_MAX)
457 return -EINVAL;
459 reg = lm3533_led_get_lv_reg(led, LM3533_REG_CTRLBANK_BCONF_BASE);
460 mask = LM3533_REG_CTRLBANK_BCONF_ALS_CHANNEL_MASK;
461 val = channel - 1;
463 ret = lm3533_update(led->lm3533, reg, val, mask);
464 if (ret)
465 return ret;
467 return len;
470 static ssize_t show_als_en(struct device *dev,
471 struct device_attribute *attr, char *buf)
473 struct led_classdev *led_cdev = dev_get_drvdata(dev);
474 struct lm3533_led *led = to_lm3533_led(led_cdev);
475 bool enable;
476 u8 reg;
477 u8 val;
478 int ret;
480 reg = lm3533_led_get_lv_reg(led, LM3533_REG_CTRLBANK_BCONF_BASE);
481 ret = lm3533_read(led->lm3533, reg, &val);
482 if (ret)
483 return ret;
485 enable = val & LM3533_REG_CTRLBANK_BCONF_ALS_EN_MASK;
487 return scnprintf(buf, PAGE_SIZE, "%d\n", enable);
490 static ssize_t store_als_en(struct device *dev,
491 struct device_attribute *attr,
492 const char *buf, size_t len)
494 struct led_classdev *led_cdev = dev_get_drvdata(dev);
495 struct lm3533_led *led = to_lm3533_led(led_cdev);
496 unsigned enable;
497 u8 reg;
498 u8 mask;
499 u8 val;
500 int ret;
502 if (kstrtouint(buf, 0, &enable))
503 return -EINVAL;
505 reg = lm3533_led_get_lv_reg(led, LM3533_REG_CTRLBANK_BCONF_BASE);
506 mask = LM3533_REG_CTRLBANK_BCONF_ALS_EN_MASK;
508 if (enable)
509 val = mask;
510 else
511 val = 0;
513 ret = lm3533_update(led->lm3533, reg, val, mask);
514 if (ret)
515 return ret;
517 return len;
520 static ssize_t show_linear(struct device *dev,
521 struct device_attribute *attr, char *buf)
523 struct led_classdev *led_cdev = dev_get_drvdata(dev);
524 struct lm3533_led *led = to_lm3533_led(led_cdev);
525 u8 reg;
526 u8 val;
527 int linear;
528 int ret;
530 reg = lm3533_led_get_lv_reg(led, LM3533_REG_CTRLBANK_BCONF_BASE);
531 ret = lm3533_read(led->lm3533, reg, &val);
532 if (ret)
533 return ret;
535 if (val & LM3533_REG_CTRLBANK_BCONF_MAPPING_MASK)
536 linear = 1;
537 else
538 linear = 0;
540 return scnprintf(buf, PAGE_SIZE, "%x\n", linear);
543 static ssize_t store_linear(struct device *dev,
544 struct device_attribute *attr,
545 const char *buf, size_t len)
547 struct led_classdev *led_cdev = dev_get_drvdata(dev);
548 struct lm3533_led *led = to_lm3533_led(led_cdev);
549 unsigned long linear;
550 u8 reg;
551 u8 mask;
552 u8 val;
553 int ret;
555 if (kstrtoul(buf, 0, &linear))
556 return -EINVAL;
558 reg = lm3533_led_get_lv_reg(led, LM3533_REG_CTRLBANK_BCONF_BASE);
559 mask = LM3533_REG_CTRLBANK_BCONF_MAPPING_MASK;
561 if (linear)
562 val = mask;
563 else
564 val = 0;
566 ret = lm3533_update(led->lm3533, reg, val, mask);
567 if (ret)
568 return ret;
570 return len;
573 static ssize_t show_pwm(struct device *dev,
574 struct device_attribute *attr,
575 char *buf)
577 struct led_classdev *led_cdev = dev_get_drvdata(dev);
578 struct lm3533_led *led = to_lm3533_led(led_cdev);
579 u8 val;
580 int ret;
582 ret = lm3533_ctrlbank_get_pwm(&led->cb, &val);
583 if (ret)
584 return ret;
586 return scnprintf(buf, PAGE_SIZE, "%u\n", val);
589 static ssize_t store_pwm(struct device *dev,
590 struct device_attribute *attr,
591 const char *buf, size_t len)
593 struct led_classdev *led_cdev = dev_get_drvdata(dev);
594 struct lm3533_led *led = to_lm3533_led(led_cdev);
595 u8 val;
596 int ret;
598 if (kstrtou8(buf, 0, &val))
599 return -EINVAL;
601 ret = lm3533_ctrlbank_set_pwm(&led->cb, val);
602 if (ret)
603 return ret;
605 return len;
608 static LM3533_ATTR_RW(als_channel);
609 static LM3533_ATTR_RW(als_en);
610 static LM3533_ATTR_RW(falltime);
611 static LM3533_ATTR_RO(id);
612 static LM3533_ATTR_RW(linear);
613 static LM3533_ATTR_RW(pwm);
614 static LM3533_ATTR_RW(risetime);
616 static struct attribute *lm3533_led_attributes[] = {
617 &dev_attr_als_channel.attr,
618 &dev_attr_als_en.attr,
619 &dev_attr_falltime.attr,
620 &dev_attr_id.attr,
621 &dev_attr_linear.attr,
622 &dev_attr_pwm.attr,
623 &dev_attr_risetime.attr,
624 NULL,
627 static umode_t lm3533_led_attr_is_visible(struct kobject *kobj,
628 struct attribute *attr, int n)
630 struct device *dev = container_of(kobj, struct device, kobj);
631 struct led_classdev *led_cdev = dev_get_drvdata(dev);
632 struct lm3533_led *led = to_lm3533_led(led_cdev);
633 umode_t mode = attr->mode;
635 if (attr == &dev_attr_als_channel.attr ||
636 attr == &dev_attr_als_en.attr) {
637 if (!led->lm3533->have_als)
638 mode = 0;
641 return mode;
644 static struct attribute_group lm3533_led_attribute_group = {
645 .is_visible = lm3533_led_attr_is_visible,
646 .attrs = lm3533_led_attributes
649 static int lm3533_led_setup(struct lm3533_led *led,
650 struct lm3533_led_platform_data *pdata)
652 int ret;
654 ret = lm3533_ctrlbank_set_max_current(&led->cb, pdata->max_current);
655 if (ret)
656 return ret;
658 return lm3533_ctrlbank_set_pwm(&led->cb, pdata->pwm);
661 static int lm3533_led_probe(struct platform_device *pdev)
663 struct lm3533 *lm3533;
664 struct lm3533_led_platform_data *pdata;
665 struct lm3533_led *led;
666 int ret;
668 dev_dbg(&pdev->dev, "%s\n", __func__);
670 lm3533 = dev_get_drvdata(pdev->dev.parent);
671 if (!lm3533)
672 return -EINVAL;
674 pdata = dev_get_platdata(&pdev->dev);
675 if (!pdata) {
676 dev_err(&pdev->dev, "no platform data\n");
677 return -EINVAL;
680 if (pdev->id < 0 || pdev->id >= LM3533_LVCTRLBANK_COUNT) {
681 dev_err(&pdev->dev, "illegal LED id %d\n", pdev->id);
682 return -EINVAL;
685 led = devm_kzalloc(&pdev->dev, sizeof(*led), GFP_KERNEL);
686 if (!led)
687 return -ENOMEM;
689 led->lm3533 = lm3533;
690 led->cdev.name = pdata->name;
691 led->cdev.default_trigger = pdata->default_trigger;
692 led->cdev.brightness_set = lm3533_led_set;
693 led->cdev.brightness_get = lm3533_led_get;
694 led->cdev.blink_set = lm3533_led_blink_set;
695 led->cdev.brightness = LED_OFF;
696 led->id = pdev->id;
698 mutex_init(&led->mutex);
699 INIT_WORK(&led->work, lm3533_led_work);
701 /* The class framework makes a callback to get brightness during
702 * registration so use parent device (for error reporting) until
703 * registered.
705 led->cb.lm3533 = lm3533;
706 led->cb.id = lm3533_led_get_ctrlbank_id(led);
707 led->cb.dev = lm3533->dev;
709 platform_set_drvdata(pdev, led);
711 ret = led_classdev_register(pdev->dev.parent, &led->cdev);
712 if (ret) {
713 dev_err(&pdev->dev, "failed to register LED %d\n", pdev->id);
714 return ret;
717 led->cb.dev = led->cdev.dev;
719 ret = sysfs_create_group(&led->cdev.dev->kobj,
720 &lm3533_led_attribute_group);
721 if (ret < 0) {
722 dev_err(&pdev->dev, "failed to create sysfs attributes\n");
723 goto err_unregister;
726 ret = lm3533_led_setup(led, pdata);
727 if (ret)
728 goto err_sysfs_remove;
730 ret = lm3533_ctrlbank_enable(&led->cb);
731 if (ret)
732 goto err_sysfs_remove;
734 return 0;
736 err_sysfs_remove:
737 sysfs_remove_group(&led->cdev.dev->kobj, &lm3533_led_attribute_group);
738 err_unregister:
739 led_classdev_unregister(&led->cdev);
740 flush_work(&led->work);
742 return ret;
745 static int lm3533_led_remove(struct platform_device *pdev)
747 struct lm3533_led *led = platform_get_drvdata(pdev);
749 dev_dbg(&pdev->dev, "%s\n", __func__);
751 lm3533_ctrlbank_disable(&led->cb);
752 sysfs_remove_group(&led->cdev.dev->kobj, &lm3533_led_attribute_group);
753 led_classdev_unregister(&led->cdev);
754 flush_work(&led->work);
756 return 0;
759 static void lm3533_led_shutdown(struct platform_device *pdev)
762 struct lm3533_led *led = platform_get_drvdata(pdev);
764 dev_dbg(&pdev->dev, "%s\n", __func__);
766 lm3533_ctrlbank_disable(&led->cb);
767 lm3533_led_set(&led->cdev, LED_OFF); /* disable blink */
768 flush_work(&led->work);
771 static struct platform_driver lm3533_led_driver = {
772 .driver = {
773 .name = "lm3533-leds",
774 .owner = THIS_MODULE,
776 .probe = lm3533_led_probe,
777 .remove = lm3533_led_remove,
778 .shutdown = lm3533_led_shutdown,
780 module_platform_driver(lm3533_led_driver);
782 MODULE_AUTHOR("Johan Hovold <jhovold@gmail.com>");
783 MODULE_DESCRIPTION("LM3533 LED driver");
784 MODULE_LICENSE("GPL");
785 MODULE_ALIAS("platform:lm3533-leds");