wakeup.c 2.7 KB

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