drm/i915: initialize fence registers to zero when loading GEM
[linux-2.6/mini2440.git] / drivers / leds / leds-bd2802.c
blob4149ecb3a9b2fda0a22cb93c2575ea16096c4bcd
1 /*
2 * leds-bd2802.c - RGB LED Driver
4 * Copyright (C) 2009 Samsung Electronics
5 * Kim Kyuwon <q1.kim@samsung.com>
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License version 2 as
9 * published by the Free Software Foundation.
11 * Datasheet: http://www.rohm.com/products/databook/driver/pdf/bd2802gu-e.pdf
15 #include <linux/module.h>
16 #include <linux/i2c.h>
17 #include <linux/gpio.h>
18 #include <linux/delay.h>
19 #include <linux/leds.h>
20 #include <linux/leds-bd2802.h>
23 #define LED_CTL(rgb2en, rgb1en) ((rgb2en) << 4 | ((rgb1en) << 0))
25 #define BD2802_LED_OFFSET 0xa
26 #define BD2802_COLOR_OFFSET 0x3
28 #define BD2802_REG_CLKSETUP 0x00
29 #define BD2802_REG_CONTROL 0x01
30 #define BD2802_REG_HOURSETUP 0x02
31 #define BD2802_REG_CURRENT1SETUP 0x03
32 #define BD2802_REG_CURRENT2SETUP 0x04
33 #define BD2802_REG_WAVEPATTERN 0x05
35 #define BD2802_CURRENT_032 0x10 /* 3.2mA */
36 #define BD2802_CURRENT_000 0x00 /* 0.0mA */
38 #define BD2802_PATTERN_FULL 0x07
39 #define BD2802_PATTERN_HALF 0x03
41 enum led_ids {
42 LED1,
43 LED2,
44 LED_NUM,
47 enum led_colors {
48 RED,
49 GREEN,
50 BLUE,
53 enum led_bits {
54 BD2802_OFF,
55 BD2802_BLINK,
56 BD2802_ON,
60 * State '0' : 'off'
61 * State '1' : 'blink'
62 * State '2' : 'on'.
64 struct led_state {
65 unsigned r:2;
66 unsigned g:2;
67 unsigned b:2;
70 struct bd2802_led {
71 struct bd2802_led_platform_data *pdata;
72 struct i2c_client *client;
73 struct rw_semaphore rwsem;
74 struct work_struct work;
76 struct led_state led[2];
79 * Making led_classdev as array is not recommended, because array
80 * members prevent using 'container_of' macro. So repetitive works
81 * are needed.
83 struct led_classdev cdev_led1r;
84 struct led_classdev cdev_led1g;
85 struct led_classdev cdev_led1b;
86 struct led_classdev cdev_led2r;
87 struct led_classdev cdev_led2g;
88 struct led_classdev cdev_led2b;
91 * Advanced Configuration Function(ADF) mode:
92 * In ADF mode, user can set registers of BD2802GU directly,
93 * therefore BD2802GU doesn't enter reset state.
95 int adf_on;
97 enum led_ids led_id;
98 enum led_colors color;
99 enum led_bits state;
103 /*--------------------------------------------------------------*/
104 /* BD2802GU helper functions */
105 /*--------------------------------------------------------------*/
107 static inline int bd2802_is_rgb_off(struct bd2802_led *led, enum led_ids id,
108 enum led_colors color)
110 switch (color) {
111 case RED:
112 return !led->led[id].r;
113 case GREEN:
114 return !led->led[id].g;
115 case BLUE:
116 return !led->led[id].b;
117 default:
118 dev_err(&led->client->dev, "%s: Invalid color\n", __func__);
119 return -EINVAL;
123 static inline int bd2802_is_led_off(struct bd2802_led *led, enum led_ids id)
125 if (led->led[id].r || led->led[id].g || led->led[id].b)
126 return 0;
128 return 1;
131 static inline int bd2802_is_all_off(struct bd2802_led *led)
133 int i;
135 for (i = 0; i < LED_NUM; i++)
136 if (!bd2802_is_led_off(led, i))
137 return 0;
139 return 1;
142 static inline u8 bd2802_get_base_offset(enum led_ids id, enum led_colors color)
144 return id * BD2802_LED_OFFSET + color * BD2802_COLOR_OFFSET;
147 static inline u8 bd2802_get_reg_addr(enum led_ids id, enum led_colors color,
148 u8 reg_offset)
150 return reg_offset + bd2802_get_base_offset(id, color);
154 /*--------------------------------------------------------------*/
155 /* BD2802GU core functions */
156 /*--------------------------------------------------------------*/
158 static int bd2802_write_byte(struct i2c_client *client, u8 reg, u8 val)
160 int ret = i2c_smbus_write_byte_data(client, reg, val);
161 if (ret >= 0)
162 return 0;
164 dev_err(&client->dev, "%s: reg 0x%x, val 0x%x, err %d\n",
165 __func__, reg, val, ret);
167 return ret;
170 static void bd2802_update_state(struct bd2802_led *led, enum led_ids id,
171 enum led_colors color, enum led_bits led_bit)
173 int i;
174 u8 value;
176 for (i = 0; i < LED_NUM; i++) {
177 if (i == id) {
178 switch (color) {
179 case RED:
180 led->led[i].r = led_bit;
181 break;
182 case GREEN:
183 led->led[i].g = led_bit;
184 break;
185 case BLUE:
186 led->led[i].b = led_bit;
187 break;
188 default:
189 dev_err(&led->client->dev,
190 "%s: Invalid color\n", __func__);
191 return;
196 if (led_bit == BD2802_BLINK || led_bit == BD2802_ON)
197 return;
199 if (!bd2802_is_led_off(led, id))
200 return;
202 if (bd2802_is_all_off(led) && !led->adf_on) {
203 gpio_set_value(led->pdata->reset_gpio, 0);
204 return;
208 * In this case, other led is turned on, and current led is turned
209 * off. So set RGB LED Control register to stop the current RGB LED
211 value = (id == LED1) ? LED_CTL(1, 0) : LED_CTL(0, 1);
212 bd2802_write_byte(led->client, BD2802_REG_CONTROL, value);
215 static void bd2802_configure(struct bd2802_led *led)
217 struct bd2802_led_platform_data *pdata = led->pdata;
218 u8 reg;
220 reg = bd2802_get_reg_addr(LED1, RED, BD2802_REG_HOURSETUP);
221 bd2802_write_byte(led->client, reg, pdata->rgb_time);
223 reg = bd2802_get_reg_addr(LED2, RED, BD2802_REG_HOURSETUP);
224 bd2802_write_byte(led->client, reg, pdata->rgb_time);
227 static void bd2802_reset_cancel(struct bd2802_led *led)
229 gpio_set_value(led->pdata->reset_gpio, 1);
230 udelay(100);
231 bd2802_configure(led);
234 static void bd2802_enable(struct bd2802_led *led, enum led_ids id)
236 enum led_ids other_led = (id == LED1) ? LED2 : LED1;
237 u8 value, other_led_on;
239 other_led_on = !bd2802_is_led_off(led, other_led);
240 if (id == LED1)
241 value = LED_CTL(other_led_on, 1);
242 else
243 value = LED_CTL(1 , other_led_on);
245 bd2802_write_byte(led->client, BD2802_REG_CONTROL, value);
248 static void bd2802_set_on(struct bd2802_led *led, enum led_ids id,
249 enum led_colors color)
251 u8 reg;
253 if (bd2802_is_all_off(led) && !led->adf_on)
254 bd2802_reset_cancel(led);
256 reg = bd2802_get_reg_addr(id, color, BD2802_REG_CURRENT1SETUP);
257 bd2802_write_byte(led->client, reg, BD2802_CURRENT_032);
258 reg = bd2802_get_reg_addr(id, color, BD2802_REG_CURRENT2SETUP);
259 bd2802_write_byte(led->client, reg, BD2802_CURRENT_000);
260 reg = bd2802_get_reg_addr(id, color, BD2802_REG_WAVEPATTERN);
261 bd2802_write_byte(led->client, reg, BD2802_PATTERN_FULL);
263 bd2802_enable(led, id);
264 bd2802_update_state(led, id, color, BD2802_ON);
267 static void bd2802_set_blink(struct bd2802_led *led, enum led_ids id,
268 enum led_colors color)
270 u8 reg;
272 if (bd2802_is_all_off(led) && !led->adf_on)
273 bd2802_reset_cancel(led);
275 reg = bd2802_get_reg_addr(id, color, BD2802_REG_CURRENT1SETUP);
276 bd2802_write_byte(led->client, reg, BD2802_CURRENT_000);
277 reg = bd2802_get_reg_addr(id, color, BD2802_REG_CURRENT2SETUP);
278 bd2802_write_byte(led->client, reg, BD2802_CURRENT_032);
279 reg = bd2802_get_reg_addr(id, color, BD2802_REG_WAVEPATTERN);
280 bd2802_write_byte(led->client, reg, BD2802_PATTERN_HALF);
282 bd2802_enable(led, id);
283 bd2802_update_state(led, id, color, BD2802_BLINK);
286 static void bd2802_turn_on(struct bd2802_led *led, enum led_ids id,
287 enum led_colors color, enum led_bits led_bit)
289 if (led_bit == BD2802_OFF) {
290 dev_err(&led->client->dev,
291 "Only 'blink' and 'on' are allowed\n");
292 return;
295 if (led_bit == BD2802_BLINK)
296 bd2802_set_blink(led, id, color);
297 else
298 bd2802_set_on(led, id, color);
301 static void bd2802_turn_off(struct bd2802_led *led, enum led_ids id,
302 enum led_colors color)
304 u8 reg;
306 if (bd2802_is_rgb_off(led, id, color))
307 return;
309 reg = bd2802_get_reg_addr(id, color, BD2802_REG_CURRENT1SETUP);
310 bd2802_write_byte(led->client, reg, BD2802_CURRENT_000);
311 reg = bd2802_get_reg_addr(id, color, BD2802_REG_CURRENT2SETUP);
312 bd2802_write_byte(led->client, reg, BD2802_CURRENT_000);
314 bd2802_update_state(led, id, color, BD2802_OFF);
317 static void bd2802_restore_state(struct bd2802_led *led)
319 int i;
321 for (i = 0; i < LED_NUM; i++) {
322 if (led->led[i].r)
323 bd2802_turn_on(led, i, RED, led->led[i].r);
324 if (led->led[i].g)
325 bd2802_turn_on(led, i, GREEN, led->led[i].g);
326 if (led->led[i].b)
327 bd2802_turn_on(led, i, BLUE, led->led[i].b);
331 #define BD2802_SET_REGISTER(reg_addr, reg_name) \
332 static ssize_t bd2802_store_reg##reg_addr(struct device *dev, \
333 struct device_attribute *attr, const char *buf, size_t count) \
335 struct bd2802_led *led = i2c_get_clientdata(to_i2c_client(dev));\
336 unsigned long val; \
337 int ret; \
338 if (!count) \
339 return -EINVAL; \
340 ret = strict_strtoul(buf, 16, &val); \
341 if (ret) \
342 return ret; \
343 down_write(&led->rwsem); \
344 bd2802_write_byte(led->client, reg_addr, (u8) val); \
345 up_write(&led->rwsem); \
346 return count; \
348 static struct device_attribute bd2802_reg##reg_addr##_attr = { \
349 .attr = {.name = reg_name, .mode = 0644, .owner = THIS_MODULE}, \
350 .store = bd2802_store_reg##reg_addr, \
353 BD2802_SET_REGISTER(0x00, "0x00");
354 BD2802_SET_REGISTER(0x01, "0x01");
355 BD2802_SET_REGISTER(0x02, "0x02");
356 BD2802_SET_REGISTER(0x03, "0x03");
357 BD2802_SET_REGISTER(0x04, "0x04");
358 BD2802_SET_REGISTER(0x05, "0x05");
359 BD2802_SET_REGISTER(0x06, "0x06");
360 BD2802_SET_REGISTER(0x07, "0x07");
361 BD2802_SET_REGISTER(0x08, "0x08");
362 BD2802_SET_REGISTER(0x09, "0x09");
363 BD2802_SET_REGISTER(0x0a, "0x0a");
364 BD2802_SET_REGISTER(0x0b, "0x0b");
365 BD2802_SET_REGISTER(0x0c, "0x0c");
366 BD2802_SET_REGISTER(0x0d, "0x0d");
367 BD2802_SET_REGISTER(0x0e, "0x0e");
368 BD2802_SET_REGISTER(0x0f, "0x0f");
369 BD2802_SET_REGISTER(0x10, "0x10");
370 BD2802_SET_REGISTER(0x11, "0x11");
371 BD2802_SET_REGISTER(0x12, "0x12");
372 BD2802_SET_REGISTER(0x13, "0x13");
373 BD2802_SET_REGISTER(0x14, "0x14");
374 BD2802_SET_REGISTER(0x15, "0x15");
376 static struct device_attribute *bd2802_addr_attributes[] = {
377 &bd2802_reg0x00_attr,
378 &bd2802_reg0x01_attr,
379 &bd2802_reg0x02_attr,
380 &bd2802_reg0x03_attr,
381 &bd2802_reg0x04_attr,
382 &bd2802_reg0x05_attr,
383 &bd2802_reg0x06_attr,
384 &bd2802_reg0x07_attr,
385 &bd2802_reg0x08_attr,
386 &bd2802_reg0x09_attr,
387 &bd2802_reg0x0a_attr,
388 &bd2802_reg0x0b_attr,
389 &bd2802_reg0x0c_attr,
390 &bd2802_reg0x0d_attr,
391 &bd2802_reg0x0e_attr,
392 &bd2802_reg0x0f_attr,
393 &bd2802_reg0x10_attr,
394 &bd2802_reg0x11_attr,
395 &bd2802_reg0x12_attr,
396 &bd2802_reg0x13_attr,
397 &bd2802_reg0x14_attr,
398 &bd2802_reg0x15_attr,
401 static void bd2802_enable_adv_conf(struct bd2802_led *led)
403 int i, ret;
405 for (i = 0; i < ARRAY_SIZE(bd2802_addr_attributes); i++) {
406 ret = device_create_file(&led->client->dev,
407 bd2802_addr_attributes[i]);
408 if (ret) {
409 dev_err(&led->client->dev, "failed to sysfs file %s\n",
410 bd2802_addr_attributes[i]->attr.name);
411 goto failed_remove_files;
415 if (bd2802_is_all_off(led))
416 bd2802_reset_cancel(led);
418 led->adf_on = 1;
420 return;
422 failed_remove_files:
423 for (i--; i >= 0; i--)
424 device_remove_file(&led->client->dev,
425 bd2802_addr_attributes[i]);
428 static void bd2802_disable_adv_conf(struct bd2802_led *led)
430 int i;
432 for (i = 0; i < ARRAY_SIZE(bd2802_addr_attributes); i++)
433 device_remove_file(&led->client->dev,
434 bd2802_addr_attributes[i]);
436 if (bd2802_is_all_off(led))
437 gpio_set_value(led->pdata->reset_gpio, 0);
439 led->adf_on = 0;
442 static ssize_t bd2802_show_adv_conf(struct device *dev,
443 struct device_attribute *attr, char *buf)
445 struct bd2802_led *led = i2c_get_clientdata(to_i2c_client(dev));
446 ssize_t ret;
448 down_read(&led->rwsem);
449 if (led->adf_on)
450 ret = sprintf(buf, "on\n");
451 else
452 ret = sprintf(buf, "off\n");
453 up_read(&led->rwsem);
455 return ret;
458 static ssize_t bd2802_store_adv_conf(struct device *dev,
459 struct device_attribute *attr, const char *buf, size_t count)
461 struct bd2802_led *led = i2c_get_clientdata(to_i2c_client(dev));
463 if (!count)
464 return -EINVAL;
466 down_write(&led->rwsem);
467 if (!led->adf_on && !strncmp(buf, "on", 2))
468 bd2802_enable_adv_conf(led);
469 else if (led->adf_on && !strncmp(buf, "off", 3))
470 bd2802_disable_adv_conf(led);
471 up_write(&led->rwsem);
473 return count;
476 static struct device_attribute bd2802_adv_conf_attr = {
477 .attr = {
478 .name = "advanced_configuration",
479 .mode = 0644,
480 .owner = THIS_MODULE
482 .show = bd2802_show_adv_conf,
483 .store = bd2802_store_adv_conf,
486 static void bd2802_led_work(struct work_struct *work)
488 struct bd2802_led *led = container_of(work, struct bd2802_led, work);
490 if (led->state)
491 bd2802_turn_on(led, led->led_id, led->color, led->state);
492 else
493 bd2802_turn_off(led, led->led_id, led->color);
496 #define BD2802_CONTROL_RGBS(name, id, clr) \
497 static void bd2802_set_##name##_brightness(struct led_classdev *led_cdev,\
498 enum led_brightness value) \
500 struct bd2802_led *led = \
501 container_of(led_cdev, struct bd2802_led, cdev_##name); \
502 led->led_id = id; \
503 led->color = clr; \
504 if (value == LED_OFF) \
505 led->state = BD2802_OFF; \
506 else \
507 led->state = BD2802_ON; \
508 schedule_work(&led->work); \
510 static int bd2802_set_##name##_blink(struct led_classdev *led_cdev, \
511 unsigned long *delay_on, unsigned long *delay_off) \
513 struct bd2802_led *led = \
514 container_of(led_cdev, struct bd2802_led, cdev_##name); \
515 if (*delay_on == 0 || *delay_off == 0) \
516 return -EINVAL; \
517 led->led_id = id; \
518 led->color = clr; \
519 led->state = BD2802_BLINK; \
520 schedule_work(&led->work); \
521 return 0; \
524 BD2802_CONTROL_RGBS(led1r, LED1, RED);
525 BD2802_CONTROL_RGBS(led1g, LED1, GREEN);
526 BD2802_CONTROL_RGBS(led1b, LED1, BLUE);
527 BD2802_CONTROL_RGBS(led2r, LED2, RED);
528 BD2802_CONTROL_RGBS(led2g, LED2, GREEN);
529 BD2802_CONTROL_RGBS(led2b, LED2, BLUE);
531 static int bd2802_register_led_classdev(struct bd2802_led *led)
533 int ret;
535 INIT_WORK(&led->work, bd2802_led_work);
537 led->cdev_led1r.name = "led1_R";
538 led->cdev_led1r.brightness = LED_OFF;
539 led->cdev_led1r.brightness_set = bd2802_set_led1r_brightness;
540 led->cdev_led1r.blink_set = bd2802_set_led1r_blink;
541 led->cdev_led1r.flags |= LED_CORE_SUSPENDRESUME;
543 ret = led_classdev_register(&led->client->dev, &led->cdev_led1r);
544 if (ret < 0) {
545 dev_err(&led->client->dev, "couldn't register LED %s\n",
546 led->cdev_led1r.name);
547 goto failed_unregister_led1_R;
550 led->cdev_led1g.name = "led1_G";
551 led->cdev_led1g.brightness = LED_OFF;
552 led->cdev_led1g.brightness_set = bd2802_set_led1g_brightness;
553 led->cdev_led1g.blink_set = bd2802_set_led1g_blink;
554 led->cdev_led1g.flags |= LED_CORE_SUSPENDRESUME;
556 ret = led_classdev_register(&led->client->dev, &led->cdev_led1g);
557 if (ret < 0) {
558 dev_err(&led->client->dev, "couldn't register LED %s\n",
559 led->cdev_led1g.name);
560 goto failed_unregister_led1_G;
563 led->cdev_led1b.name = "led1_B";
564 led->cdev_led1b.brightness = LED_OFF;
565 led->cdev_led1b.brightness_set = bd2802_set_led1b_brightness;
566 led->cdev_led1b.blink_set = bd2802_set_led1b_blink;
567 led->cdev_led1b.flags |= LED_CORE_SUSPENDRESUME;
569 ret = led_classdev_register(&led->client->dev, &led->cdev_led1b);
570 if (ret < 0) {
571 dev_err(&led->client->dev, "couldn't register LED %s\n",
572 led->cdev_led1b.name);
573 goto failed_unregister_led1_B;
576 led->cdev_led2r.name = "led2_R";
577 led->cdev_led2r.brightness = LED_OFF;
578 led->cdev_led2r.brightness_set = bd2802_set_led2r_brightness;
579 led->cdev_led2r.blink_set = bd2802_set_led2r_blink;
580 led->cdev_led2r.flags |= LED_CORE_SUSPENDRESUME;
582 ret = led_classdev_register(&led->client->dev, &led->cdev_led2r);
583 if (ret < 0) {
584 dev_err(&led->client->dev, "couldn't register LED %s\n",
585 led->cdev_led2r.name);
586 goto failed_unregister_led2_R;
589 led->cdev_led2g.name = "led2_G";
590 led->cdev_led2g.brightness = LED_OFF;
591 led->cdev_led2g.brightness_set = bd2802_set_led2g_brightness;
592 led->cdev_led2g.blink_set = bd2802_set_led2g_blink;
593 led->cdev_led2g.flags |= LED_CORE_SUSPENDRESUME;
595 ret = led_classdev_register(&led->client->dev, &led->cdev_led2g);
596 if (ret < 0) {
597 dev_err(&led->client->dev, "couldn't register LED %s\n",
598 led->cdev_led2g.name);
599 goto failed_unregister_led2_G;
602 led->cdev_led2b.name = "led2_B";
603 led->cdev_led2b.brightness = LED_OFF;
604 led->cdev_led2b.brightness_set = bd2802_set_led2b_brightness;
605 led->cdev_led2b.blink_set = bd2802_set_led2b_blink;
606 led->cdev_led2b.flags |= LED_CORE_SUSPENDRESUME;
608 ret = led_classdev_register(&led->client->dev, &led->cdev_led2b);
609 if (ret < 0) {
610 dev_err(&led->client->dev, "couldn't register LED %s\n",
611 led->cdev_led2b.name);
612 goto failed_unregister_led2_B;
615 return 0;
617 failed_unregister_led2_B:
618 led_classdev_unregister(&led->cdev_led2g);
619 failed_unregister_led2_G:
620 led_classdev_unregister(&led->cdev_led2r);
621 failed_unregister_led2_R:
622 led_classdev_unregister(&led->cdev_led1b);
623 failed_unregister_led1_B:
624 led_classdev_unregister(&led->cdev_led1g);
625 failed_unregister_led1_G:
626 led_classdev_unregister(&led->cdev_led1r);
627 failed_unregister_led1_R:
629 return ret;
632 static void bd2802_unregister_led_classdev(struct bd2802_led *led)
634 cancel_work_sync(&led->work);
635 led_classdev_unregister(&led->cdev_led1r);
638 static int __devinit bd2802_probe(struct i2c_client *client,
639 const struct i2c_device_id *id)
641 struct bd2802_led *led;
642 struct bd2802_led_platform_data *pdata;
643 int ret;
645 led = kzalloc(sizeof(struct bd2802_led), GFP_KERNEL);
646 if (!led) {
647 dev_err(&client->dev, "failed to allocate driver data\n");
648 return -ENOMEM;
651 led->client = client;
652 pdata = led->pdata = client->dev.platform_data;
653 i2c_set_clientdata(client, led);
655 /* Configure RESET GPIO (L: RESET, H: RESET cancel) */
656 gpio_request(pdata->reset_gpio, "RGB_RESETB");
657 gpio_direction_output(pdata->reset_gpio, 1);
659 /* Tacss = min 0.1ms */
660 udelay(100);
662 /* Detect BD2802GU */
663 ret = bd2802_write_byte(client, BD2802_REG_CLKSETUP, 0x00);
664 if (ret < 0) {
665 dev_err(&client->dev, "failed to detect device\n");
666 goto failed_free;
667 } else
668 dev_info(&client->dev, "return 0x%02x\n", ret);
670 /* To save the power, reset BD2802 after detecting */
671 gpio_set_value(led->pdata->reset_gpio, 0);
673 init_rwsem(&led->rwsem);
675 ret = device_create_file(&client->dev, &bd2802_adv_conf_attr);
676 if (ret) {
677 dev_err(&client->dev, "failed to create sysfs file %s\n",
678 bd2802_adv_conf_attr.attr.name);
679 goto failed_free;
682 ret = bd2802_register_led_classdev(led);
683 if (ret < 0)
684 goto failed_unregister_dev_file;
686 return 0;
688 failed_unregister_dev_file:
689 device_remove_file(&client->dev, &bd2802_adv_conf_attr);
690 failed_free:
691 i2c_set_clientdata(client, NULL);
692 kfree(led);
694 return ret;
697 static int __exit bd2802_remove(struct i2c_client *client)
699 struct bd2802_led *led = i2c_get_clientdata(client);
701 bd2802_unregister_led_classdev(led);
702 gpio_set_value(led->pdata->reset_gpio, 0);
703 if (led->adf_on)
704 bd2802_disable_adv_conf(led);
705 device_remove_file(&client->dev, &bd2802_adv_conf_attr);
706 i2c_set_clientdata(client, NULL);
707 kfree(led);
709 return 0;
712 static int bd2802_suspend(struct i2c_client *client, pm_message_t mesg)
714 struct bd2802_led *led = i2c_get_clientdata(client);
716 gpio_set_value(led->pdata->reset_gpio, 0);
718 return 0;
721 static int bd2802_resume(struct i2c_client *client)
723 struct bd2802_led *led = i2c_get_clientdata(client);
725 if (!bd2802_is_all_off(led) || led->adf_on) {
726 gpio_set_value(led->pdata->reset_gpio, 1);
727 udelay(100);
728 bd2802_restore_state(led);
731 return 0;
734 static const struct i2c_device_id bd2802_id[] = {
735 { "BD2802", 0 },
738 MODULE_DEVICE_TABLE(i2c, bd2802_id);
740 static struct i2c_driver bd2802_i2c_driver = {
741 .driver = {
742 .name = "BD2802",
744 .probe = bd2802_probe,
745 .remove = __exit_p(bd2802_remove),
746 .suspend = bd2802_suspend,
747 .resume = bd2802_resume,
748 .id_table = bd2802_id,
751 static int __init bd2802_init(void)
753 return i2c_add_driver(&bd2802_i2c_driver);
755 module_init(bd2802_init);
757 static void __exit bd2802_exit(void)
759 i2c_del_driver(&bd2802_i2c_driver);
761 module_exit(bd2802_exit);
763 MODULE_AUTHOR("Kim Kyuwon <q1.kim@samsung.com>");
764 MODULE_DESCRIPTION("BD2802 LED driver");
765 MODULE_LICENSE("GPL");