ledtrig-sleep.c 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  1. /* 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. #include <linux/earlysuspend.h>
  16. #include <linux/leds.h>
  17. #include <linux/suspend.h>
  18. static int ledtrig_sleep_pm_callback(struct notifier_block *nfb,
  19. unsigned long action,
  20. void *ignored);
  21. DEFINE_LED_TRIGGER(ledtrig_sleep)
  22. static struct notifier_block ledtrig_sleep_pm_notifier = {
  23. .notifier_call = ledtrig_sleep_pm_callback,
  24. .priority = 0,
  25. };
  26. static void ledtrig_sleep_early_suspend(struct early_suspend *h)
  27. {
  28. led_trigger_event(ledtrig_sleep, LED_FULL);
  29. }
  30. static void ledtrig_sleep_early_resume(struct early_suspend *h)
  31. {
  32. led_trigger_event(ledtrig_sleep, LED_OFF);
  33. }
  34. static struct early_suspend ledtrig_sleep_early_suspend_handler = {
  35. .suspend = ledtrig_sleep_early_suspend,
  36. .resume = ledtrig_sleep_early_resume,
  37. };
  38. static int ledtrig_sleep_pm_callback(struct notifier_block *nfb,
  39. unsigned long action,
  40. void *ignored)
  41. {
  42. switch (action) {
  43. case PM_HIBERNATION_PREPARE:
  44. case PM_SUSPEND_PREPARE:
  45. led_trigger_event(ledtrig_sleep, LED_OFF);
  46. return NOTIFY_OK;
  47. case PM_POST_HIBERNATION:
  48. case PM_POST_SUSPEND:
  49. led_trigger_event(ledtrig_sleep, LED_FULL);
  50. return NOTIFY_OK;
  51. }
  52. return NOTIFY_DONE;
  53. }
  54. static int __init ledtrig_sleep_init(void)
  55. {
  56. led_trigger_register_simple("sleep", &ledtrig_sleep);
  57. register_pm_notifier(&ledtrig_sleep_pm_notifier);
  58. register_early_suspend(&ledtrig_sleep_early_suspend_handler);
  59. return 0;
  60. }
  61. static void __exit ledtrig_sleep_exit(void)
  62. {
  63. unregister_early_suspend(&ledtrig_sleep_early_suspend_handler);
  64. unregister_pm_notifier(&ledtrig_sleep_pm_notifier);
  65. led_trigger_unregister_simple(ledtrig_sleep);
  66. }
  67. module_init(ledtrig_sleep_init);
  68. module_exit(ledtrig_sleep_exit);