wakeup.c 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  1. /*
  2. * wakeup.c - support wakeup devices
  3. * Copyright (C) 2004 Li Shaohua <shaohua.li@intel.com>
  4. */
  5. #include <linux/init.h>
  6. #include <linux/acpi.h>
  7. #include <acpi/acpi_drivers.h>
  8. #include <linux/kernel.h>
  9. #include <linux/types.h>
  10. #include "internal.h"
  11. #include "sleep.h"
  12. /*
  13. * We didn't lock acpi_device_lock in the file, because it invokes oops in
  14. * suspend/resume and isn't really required as this is called in S-state. At
  15. * that time, there is no device hotplug
  16. **/
  17. #define _COMPONENT ACPI_SYSTEM_COMPONENT
  18. ACPI_MODULE_NAME("wakeup_devices")
  19. /**
  20. * acpi_enable_wakeup_devices - Enable wake-up device GPEs.
  21. * @sleep_state: ACPI system sleep state.
  22. *
  23. * Enable wakeup device power of devices with the state.enable flag set and set
  24. * the wakeup enable mask bits in the GPE registers that correspond to wakeup
  25. * devices.
  26. */
  27. void acpi_enable_wakeup_devices(u8 sleep_state)
  28. {
  29. struct list_head *node, *next;
  30. list_for_each_safe(node, next, &acpi_wakeup_device_list) {
  31. struct acpi_device *dev =
  32. container_of(node, struct acpi_device, wakeup_list);
  33. if (!dev->wakeup.flags.valid
  34. || sleep_state > (u32) dev->wakeup.sleep_state
  35. || !(device_may_wakeup(&dev->dev)
  36. || dev->wakeup.prepare_count))
  37. continue;
  38. if (device_may_wakeup(&dev->dev))
  39. acpi_enable_wakeup_device_power(dev, sleep_state);
  40. /* The wake-up power should have been enabled already. */
  41. acpi_set_gpe_wake_mask(dev->wakeup.gpe_device, dev->wakeup.gpe_number,
  42. ACPI_GPE_ENABLE);
  43. }
  44. }
  45. /**
  46. * acpi_disable_wakeup_devices - Disable devices' wakeup capability.
  47. * @sleep_state: ACPI system sleep state.
  48. */
  49. void acpi_disable_wakeup_devices(u8 sleep_state)
  50. {
  51. struct list_head *node, *next;
  52. list_for_each_safe(node, next, &acpi_wakeup_device_list) {
  53. struct acpi_device *dev =
  54. container_of(node, struct acpi_device, wakeup_list);
  55. if (!dev->wakeup.flags.valid
  56. || sleep_state > (u32) dev->wakeup.sleep_state
  57. || !(device_may_wakeup(&dev->dev)
  58. || dev->wakeup.prepare_count))
  59. continue;
  60. acpi_set_gpe_wake_mask(dev->wakeup.gpe_device, dev->wakeup.gpe_number,
  61. ACPI_GPE_DISABLE);
  62. if (device_may_wakeup(&dev->dev))
  63. acpi_disable_wakeup_device_power(dev);
  64. }
  65. }
  66. int __init acpi_wakeup_device_init(void)
  67. {
  68. struct list_head *node, *next;
  69. mutex_lock(&acpi_device_lock);
  70. list_for_each_safe(node, next, &acpi_wakeup_device_list) {
  71. struct acpi_device *dev = container_of(node,
  72. struct acpi_device,
  73. wakeup_list);
  74. if (device_can_wakeup(&dev->dev)) {
  75. /* Button GPEs are supposed to be always enabled. */
  76. acpi_enable_gpe(dev->wakeup.gpe_device,
  77. dev->wakeup.gpe_number);
  78. device_set_wakeup_enable(&dev->dev, true);
  79. }
  80. }
  81. mutex_unlock(&acpi_device_lock);
  82. return 0;
  83. }