wakeup.c 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116
  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_device_prep - Prepare wake-up devices.
  21. * @sleep_state: ACPI system sleep state.
  22. *
  23. * Enable all wake-up devices' power, unless the requested system sleep state is
  24. * too deep.
  25. */
  26. void acpi_enable_wakeup_device_prep(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 = container_of(node,
  31. struct acpi_device,
  32. wakeup_list);
  33. if (!dev->wakeup.flags.valid || !dev->wakeup.state.enabled
  34. || (sleep_state > (u32) dev->wakeup.sleep_state))
  35. continue;
  36. acpi_enable_wakeup_device_power(dev, sleep_state);
  37. }
  38. }
  39. /**
  40. * acpi_enable_wakeup_device - Enable wake-up device GPEs.
  41. * @sleep_state: ACPI system sleep state.
  42. *
  43. * Enable all wake-up devices' GPEs, with the assumption that
  44. * acpi_disable_all_gpes() was executed before, so we don't need to disable any
  45. * GPEs here.
  46. */
  47. void acpi_enable_wakeup_device(u8 sleep_state)
  48. {
  49. struct list_head *node, *next;
  50. /*
  51. * Caution: this routine must be invoked when interrupt is disabled
  52. * Refer ACPI2.0: P212
  53. */
  54. list_for_each_safe(node, next, &acpi_wakeup_device_list) {
  55. struct acpi_device *dev =
  56. container_of(node, struct acpi_device, wakeup_list);
  57. if (!dev->wakeup.flags.valid || !dev->wakeup.state.enabled
  58. || sleep_state > (u32) dev->wakeup.sleep_state)
  59. continue;
  60. /* The wake-up power should have been enabled already. */
  61. acpi_enable_gpe(dev->wakeup.gpe_device, dev->wakeup.gpe_number,
  62. ACPI_GPE_TYPE_WAKE);
  63. }
  64. }
  65. /**
  66. * acpi_disable_wakeup_device - Disable devices' wakeup capability.
  67. * @sleep_state: ACPI system sleep state.
  68. *
  69. * This function only affects devices with wakeup.state.enabled set, which means
  70. * that it reverses the changes made by acpi_enable_wakeup_device_prep().
  71. */
  72. void acpi_disable_wakeup_device(u8 sleep_state)
  73. {
  74. struct list_head *node, *next;
  75. list_for_each_safe(node, next, &acpi_wakeup_device_list) {
  76. struct acpi_device *dev =
  77. container_of(node, struct acpi_device, wakeup_list);
  78. if (!dev->wakeup.flags.valid || !dev->wakeup.state.enabled
  79. || (sleep_state > (u32) dev->wakeup.sleep_state))
  80. continue;
  81. acpi_disable_gpe(dev->wakeup.gpe_device, dev->wakeup.gpe_number,
  82. ACPI_GPE_TYPE_WAKE);
  83. acpi_disable_wakeup_device_power(dev);
  84. }
  85. }
  86. int __init acpi_wakeup_device_init(void)
  87. {
  88. struct list_head *node, *next;
  89. mutex_lock(&acpi_device_lock);
  90. list_for_each_safe(node, next, &acpi_wakeup_device_list) {
  91. struct acpi_device *dev = container_of(node,
  92. struct acpi_device,
  93. wakeup_list);
  94. if (dev->wakeup.flags.always_enabled)
  95. dev->wakeup.state.enabled = 1;
  96. }
  97. mutex_unlock(&acpi_device_lock);
  98. return 0;
  99. }