1 /* drivers/leds/ledtrig-sleep.c
3 * Copyright (C) 2007 Google, Inc.
5 * This software is licensed under the terms of the GNU General Public
6 * License version 2, as published by the Free Software Foundation, and
7 * may be copied, distributed, and modified under those terms.
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
16 #include <linux/earlysuspend.h>
17 #include <linux/leds.h>
18 #include <linux/suspend.h>
20 static int ledtrig_sleep_pm_callback(struct notifier_block *nfb,
24 DEFINE_LED_TRIGGER(ledtrig_sleep)
25 static struct notifier_block ledtrig_sleep_pm_notifier = {
26 .notifier_call = ledtrig_sleep_pm_callback,
30 static void ledtrig_sleep_early_suspend(struct early_suspend *h)
32 led_trigger_event(ledtrig_sleep, LED_FULL);
35 static void ledtrig_sleep_early_resume(struct early_suspend *h)
37 led_trigger_event(ledtrig_sleep, LED_OFF);
40 static struct early_suspend ledtrig_sleep_early_suspend_handler = {
41 .suspend = ledtrig_sleep_early_suspend,
42 .resume = ledtrig_sleep_early_resume,
45 static int ledtrig_sleep_pm_callback(struct notifier_block *nfb,
50 case PM_HIBERNATION_PREPARE:
51 case PM_SUSPEND_PREPARE:
52 led_trigger_event(ledtrig_sleep, LED_OFF);
54 case PM_POST_HIBERNATION:
56 led_trigger_event(ledtrig_sleep, LED_FULL);
63 static int __init ledtrig_sleep_init(void)
65 led_trigger_register_simple("sleep", &ledtrig_sleep);
66 register_pm_notifier(&ledtrig_sleep_pm_notifier);
67 register_early_suspend(&ledtrig_sleep_early_suspend_handler);
71 static void __exit ledtrig_sleep_exit(void)
73 unregister_early_suspend(&ledtrig_sleep_early_suspend_handler);
74 unregister_pm_notifier(&ledtrig_sleep_pm_notifier);
75 led_trigger_unregister_simple(ledtrig_sleep);
78 module_init(ledtrig_sleep_init);
79 module_exit(ledtrig_sleep_exit);