poweroff.c 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  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. if (acpi_state == ACPI_STATE_S5) {
  34. acpi_wakeup_gpe_poweroff_prepare();
  35. }
  36. acpi_enter_sleep_state_prep(acpi_state);
  37. return 0;
  38. }
  39. #ifdef CONFIG_PM
  40. void acpi_power_off(void)
  41. {
  42. /* acpi_sleep_prepare(ACPI_STATE_S5) should have already been called */
  43. printk("%s called\n", __FUNCTION__);
  44. local_irq_disable();
  45. /* Some SMP machines only can poweroff in boot CPU */
  46. acpi_enter_sleep_state(ACPI_STATE_S5);
  47. }
  48. static int acpi_shutdown(struct sys_device *x)
  49. {
  50. if (system_state == SYSTEM_POWER_OFF) {
  51. /* Prepare if we are going to power off the system */
  52. return acpi_sleep_prepare(ACPI_STATE_S5);
  53. }
  54. return 0;
  55. }
  56. static struct sysdev_class acpi_sysclass = {
  57. set_kset_name("acpi"),
  58. .shutdown = acpi_shutdown
  59. };
  60. static struct sys_device device_acpi = {
  61. .id = 0,
  62. .cls = &acpi_sysclass,
  63. };
  64. static int acpi_poweroff_init(void)
  65. {
  66. if (!acpi_disabled) {
  67. u8 type_a, type_b;
  68. acpi_status status;
  69. status =
  70. acpi_get_sleep_type_data(ACPI_STATE_S5, &type_a, &type_b);
  71. if (ACPI_SUCCESS(status)) {
  72. int error;
  73. error = sysdev_class_register(&acpi_sysclass);
  74. if (!error)
  75. error = sysdev_register(&device_acpi);
  76. if (!error)
  77. pm_power_off = acpi_power_off;
  78. return error;
  79. }
  80. }
  81. return 0;
  82. }
  83. late_initcall(acpi_poweroff_init);
  84. #endif /* CONFIG_PM */