blob: f16404212152c8c42765e51a5c6053384f1b2b90 [file] [log] [blame]
Arve Hjønnevågd3bf8ae2008-03-30 21:47:13 -07001/* drivers/leds/ledtrig-sleep.c
2 *
3 * Copyright (C) 2007 Google, Inc.
4 *
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.
8 *
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.
13 *
14 */
15
16#include <linux/earlysuspend.h>
17#include <linux/leds.h>
18#include <linux/suspend.h>
19
20static int ledtrig_sleep_pm_callback(struct notifier_block *nfb,
21 unsigned long action,
22 void *ignored);
23
24DEFINE_LED_TRIGGER(ledtrig_sleep)
25static struct notifier_block ledtrig_sleep_pm_notifier = {
26 .notifier_call = ledtrig_sleep_pm_callback,
27 .priority = 0,
28};
29
30static void ledtrig_sleep_early_suspend(struct early_suspend *h)
31{
32 led_trigger_event(ledtrig_sleep, LED_FULL);
33}
34
35static void ledtrig_sleep_early_resume(struct early_suspend *h)
36{
37 led_trigger_event(ledtrig_sleep, LED_OFF);
38}
39
40static struct early_suspend ledtrig_sleep_early_suspend_handler = {
41 .suspend = ledtrig_sleep_early_suspend,
42 .resume = ledtrig_sleep_early_resume,
43};
44
45static int ledtrig_sleep_pm_callback(struct notifier_block *nfb,
46 unsigned long action,
47 void *ignored)
48{
49 switch (action) {
50 case PM_HIBERNATION_PREPARE:
51 case PM_SUSPEND_PREPARE:
52 led_trigger_event(ledtrig_sleep, LED_OFF);
53 return NOTIFY_OK;
54 case PM_POST_HIBERNATION:
55 case PM_POST_SUSPEND:
56 led_trigger_event(ledtrig_sleep, LED_FULL);
57 return NOTIFY_OK;
58 }
59
60 return NOTIFY_DONE;
61}
62
63static int __init ledtrig_sleep_init(void)
64{
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);
68 return 0;
69}
70
71static void __exit ledtrig_sleep_exit(void)
72{
73 unregister_early_suspend(&ledtrig_sleep_early_suspend_handler);
74 unregister_pm_notifier(&ledtrig_sleep_pm_notifier);
75 led_trigger_unregister_simple(ledtrig_sleep);
76}
77
78module_init(ledtrig_sleep_init);
79module_exit(ledtrig_sleep_exit);
80