poweroff.c 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  1. /*
  2. * poweroff.c - ACPI handler for powering off the system.
  3. *
  4. * AKA S5, but it is independent of whether or not the kernel supports
  5. * any other sleep support in the system.
  6. *
  7. * Copyright (c) 2005 Alexey Starikovskiy <alexey.y.starikovskiy@intel.com>
  8. *
  9. * This file is released under the GPLv2.
  10. */
  11. #include <linux/pm.h>
  12. #include <linux/init.h>
  13. #include <acpi/acpi_bus.h>
  14. #include <linux/sched.h>
  15. #include <linux/sysdev.h>
  16. #include <asm/io.h>
  17. #include "sleep.h"
  18. int acpi_sleep_prepare(u32 acpi_state)
  19. {
  20. #ifdef CONFIG_ACPI_SLEEP
  21. /* do we have a wakeup address for S2 and S3? */
  22. if (acpi_state == ACPI_STATE_S3) {
  23. if (!acpi_wakeup_address) {
  24. return -EFAULT;
  25. }
  26. acpi_set_firmware_waking_vector((acpi_physical_address)
  27. virt_to_phys((void *)
  28. acpi_wakeup_address));
  29. }
  30. ACPI_FLUSH_CPU_CACHE();
  31. acpi_enable_wakeup_device_prep(acpi_state);
  32. #endif
  33. acpi_gpe_sleep_prepare(acpi_state);
  34. acpi_enter_sleep_state_prep(acpi_state);
  35. return 0;
  36. }
  37. #ifdef CONFIG_PM
  38. void acpi_power_off(void)
  39. {
  40. /* acpi_sleep_prepare(ACPI_STATE_S5) should have already been called */
  41. printk("%s called\n", __FUNCTION__);
  42. local_irq_disable();
  43. /* Some SMP machines only can poweroff in boot CPU */
  44. acpi_enter_sleep_state(ACPI_STATE_S5);
  45. }
  46. static int acpi_shutdown(struct sys_device *x)
  47. {
  48. switch (system_state) {
  49. case SYSTEM_POWER_OFF:
  50. /* Prepare to power off the system */
  51. return acpi_sleep_prepare(ACPI_STATE_S5);
  52. case SYSTEM_SUSPEND_DISK:
  53. /* Prepare to suspend the system to disk */
  54. return acpi_sleep_prepare(ACPI_STATE_S4);
  55. default:
  56. return 0;
  57. }
  58. }
  59. static struct sysdev_class acpi_sysclass = {
  60. set_kset_name("acpi"),
  61. .shutdown = acpi_shutdown
  62. };
  63. static struct sys_device device_acpi = {
  64. .id = 0,
  65. .cls = &acpi_sysclass,
  66. };
  67. static int acpi_poweroff_init(void)
  68. {
  69. if (!acpi_disabled) {
  70. u8 type_a, type_b;
  71. acpi_status status;
  72. status =
  73. acpi_get_sleep_type_data(ACPI_STATE_S5, &type_a, &type_b);
  74. if (ACPI_SUCCESS(status)) {
  75. int error;
  76. error = sysdev_class_register(&acpi_sysclass);
  77. if (!error)
  78. error = sysdev_register(&device_acpi);
  79. if (!error)
  80. pm_power_off = acpi_power_off;
  81. return error;
  82. }
  83. }
  84. return 0;
  85. }
  86. late_initcall(acpi_poweroff_init);
  87. #endif /* CONFIG_PM */