wakeup.c 2.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  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. || !(dev->wakeup.state.enabled || dev->wakeup.prepare_count)
  35. || sleep_state > (u32) dev->wakeup.sleep_state)
  36. continue;
  37. if (dev->wakeup.state.enabled)
  38. acpi_enable_wakeup_device_power(dev, sleep_state);
  39. /* The wake-up power should have been enabled already. */
  40. acpi_gpe_wakeup(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. || !(dev->wakeup.state.enabled || dev->wakeup.prepare_count)
  56. || (sleep_state > (u32) dev->wakeup.sleep_state))
  57. continue;
  58. acpi_gpe_wakeup(dev->wakeup.gpe_device, dev->wakeup.gpe_number,
  59. ACPI_GPE_DISABLE);
  60. if (dev->wakeup.state.enabled)
  61. acpi_disable_wakeup_device_power(dev);
  62. }
  63. }
  64. int __init acpi_wakeup_device_init(void)
  65. {
  66. struct list_head *node, *next;
  67. mutex_lock(&acpi_device_lock);
  68. list_for_each_safe(node, next, &acpi_wakeup_device_list) {
  69. struct acpi_device *dev = container_of(node,
  70. struct acpi_device,
  71. wakeup_list);
  72. if (dev->wakeup.flags.always_enabled)
  73. dev->wakeup.state.enabled = 1;
  74. }
  75. mutex_unlock(&acpi_device_lock);
  76. return 0;
  77. }