Merge branch 'merge' of git://git.kernel.org/pub/scm/linux/kernel/git/benh/powerpc
[linux/fpc-iii.git] / drivers / leds / led-core.c
blobd6860043f6f99f1fc0e4f819681d8fed9089c542
1 /*
2 * LED Class Core
4 * Copyright 2005-2006 Openedhand Ltd.
6 * Author: Richard Purdie <rpurdie@openedhand.com>
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.
14 #include <linux/kernel.h>
15 #include <linux/list.h>
16 #include <linux/module.h>
17 #include <linux/rwsem.h>
18 #include <linux/leds.h>
19 #include "leds.h"
21 DECLARE_RWSEM(leds_list_lock);
22 EXPORT_SYMBOL_GPL(leds_list_lock);
24 LIST_HEAD(leds_list);
25 EXPORT_SYMBOL_GPL(leds_list);
27 static void led_stop_software_blink(struct led_classdev *led_cdev)
29 /* deactivate previous settings */
30 del_timer_sync(&led_cdev->blink_timer);
31 led_cdev->blink_delay_on = 0;
32 led_cdev->blink_delay_off = 0;
35 static void led_set_software_blink(struct led_classdev *led_cdev,
36 unsigned long delay_on,
37 unsigned long delay_off)
39 int current_brightness;
41 current_brightness = led_get_brightness(led_cdev);
42 if (current_brightness)
43 led_cdev->blink_brightness = current_brightness;
44 if (!led_cdev->blink_brightness)
45 led_cdev->blink_brightness = led_cdev->max_brightness;
47 if (led_get_trigger_data(led_cdev) &&
48 delay_on == led_cdev->blink_delay_on &&
49 delay_off == led_cdev->blink_delay_off)
50 return;
52 led_stop_software_blink(led_cdev);
54 led_cdev->blink_delay_on = delay_on;
55 led_cdev->blink_delay_off = delay_off;
57 /* never on - don't blink */
58 if (!delay_on)
59 return;
61 /* never off - just set to brightness */
62 if (!delay_off) {
63 led_set_brightness(led_cdev, led_cdev->blink_brightness);
64 return;
67 mod_timer(&led_cdev->blink_timer, jiffies + 1);
71 void led_blink_set(struct led_classdev *led_cdev,
72 unsigned long *delay_on,
73 unsigned long *delay_off)
75 del_timer_sync(&led_cdev->blink_timer);
77 if (led_cdev->blink_set &&
78 !led_cdev->blink_set(led_cdev, delay_on, delay_off))
79 return;
81 /* blink with 1 Hz as default if nothing specified */
82 if (!*delay_on && !*delay_off)
83 *delay_on = *delay_off = 500;
85 led_set_software_blink(led_cdev, *delay_on, *delay_off);
87 EXPORT_SYMBOL(led_blink_set);
89 void led_brightness_set(struct led_classdev *led_cdev,
90 enum led_brightness brightness)
92 led_stop_software_blink(led_cdev);
93 led_cdev->brightness_set(led_cdev, brightness);
95 EXPORT_SYMBOL(led_brightness_set);