Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1 | /* |
| 2 | * wakeup.c - support wakeup devices |
| 3 | * Copyright (C) 2004 Li Shaohua <shaohua.li@intel.com> |
| 4 | */ |
| 5 | |
| 6 | #include <linux/init.h> |
| 7 | #include <linux/acpi.h> |
| 8 | #include <acpi/acpi_drivers.h> |
| 9 | #include <linux/kernel.h> |
| 10 | #include <linux/types.h> |
Bjorn Helgaas | e60cc7a | 2009-03-13 12:08:26 -0600 | [diff] [blame] | 11 | |
| 12 | #include "internal.h" |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 13 | #include "sleep.h" |
| 14 | |
Shaohua Li | 9090589 | 2009-04-07 10:24:29 +0800 | [diff] [blame] | 15 | /* |
| 16 | * We didn't lock acpi_device_lock in the file, because it invokes oops in |
| 17 | * suspend/resume and isn't really required as this is called in S-state. At |
| 18 | * that time, there is no device hotplug |
| 19 | **/ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 20 | #define _COMPONENT ACPI_SYSTEM_COMPONENT |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 21 | ACPI_MODULE_NAME("wakeup_devices") |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 22 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 23 | /** |
Rafael J. Wysocki | 9630bdd | 2010-02-17 23:41:07 +0100 | [diff] [blame] | 24 | * acpi_enable_wakeup_device_prep - Prepare wake-up devices. |
| 25 | * @sleep_state: ACPI system sleep state. |
| 26 | * |
| 27 | * Enable all wake-up devices' power, unless the requested system sleep state is |
| 28 | * too deep. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 29 | */ |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 30 | void acpi_enable_wakeup_device_prep(u8 sleep_state) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 31 | { |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 32 | struct list_head *node, *next; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 33 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 34 | list_for_each_safe(node, next, &acpi_wakeup_device_list) { |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 35 | struct acpi_device *dev = container_of(node, |
| 36 | struct acpi_device, |
| 37 | wakeup_list); |
| 38 | |
Rafael J. Wysocki | 9630bdd | 2010-02-17 23:41:07 +0100 | [diff] [blame] | 39 | if (!dev->wakeup.flags.valid || !dev->wakeup.state.enabled |
| 40 | || (sleep_state > (u32) dev->wakeup.sleep_state)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 41 | continue; |
| 42 | |
Rafael J. Wysocki | 77e7660 | 2008-07-07 03:33:34 +0200 | [diff] [blame] | 43 | acpi_enable_wakeup_device_power(dev, sleep_state); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 44 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 45 | } |
| 46 | |
| 47 | /** |
Rafael J. Wysocki | 9630bdd | 2010-02-17 23:41:07 +0100 | [diff] [blame] | 48 | * acpi_enable_wakeup_device - Enable wake-up device GPEs. |
| 49 | * @sleep_state: ACPI system sleep state. |
| 50 | * |
| 51 | * Enable all wake-up devices' GPEs, with the assumption that |
| 52 | * acpi_disable_all_gpes() was executed before, so we don't need to disable any |
| 53 | * GPEs here. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 54 | */ |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 55 | void acpi_enable_wakeup_device(u8 sleep_state) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 56 | { |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 57 | struct list_head *node, *next; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 58 | |
| 59 | /* |
| 60 | * Caution: this routine must be invoked when interrupt is disabled |
| 61 | * Refer ACPI2.0: P212 |
| 62 | */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 63 | list_for_each_safe(node, next, &acpi_wakeup_device_list) { |
Alexey Starikovskiy | 9b03933 | 2007-09-26 19:47:30 +0400 | [diff] [blame] | 64 | struct acpi_device *dev = |
| 65 | container_of(node, struct acpi_device, wakeup_list); |
Rafael J. Wysocki | eb9d0fe | 2008-07-07 03:34:48 +0200 | [diff] [blame] | 66 | |
Alexey Starikovskiy | 9b03933 | 2007-09-26 19:47:30 +0400 | [diff] [blame] | 67 | if (!dev->wakeup.flags.valid) |
| 68 | continue; |
Rafael J. Wysocki | eb9d0fe | 2008-07-07 03:34:48 +0200 | [diff] [blame] | 69 | |
Rafael J. Wysocki | 9b83ccd | 2009-09-08 23:15:31 +0200 | [diff] [blame] | 70 | if ((!dev->wakeup.state.enabled && !dev->wakeup.prepare_count) |
Rafael J. Wysocki | 9630bdd | 2010-02-17 23:41:07 +0100 | [diff] [blame] | 71 | || sleep_state > (u32) dev->wakeup.sleep_state) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 72 | continue; |
Rafael J. Wysocki | 9630bdd | 2010-02-17 23:41:07 +0100 | [diff] [blame] | 73 | |
| 74 | /* The wake-up power should have been enabled already. */ |
| 75 | acpi_set_gpe(dev->wakeup.gpe_device, dev->wakeup.gpe_number, |
| 76 | ACPI_GPE_ENABLE); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 77 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 78 | } |
| 79 | |
| 80 | /** |
Rafael J. Wysocki | 9630bdd | 2010-02-17 23:41:07 +0100 | [diff] [blame] | 81 | * acpi_disable_wakeup_device - Disable devices' wakeup capability. |
| 82 | * @sleep_state: ACPI system sleep state. |
| 83 | * |
| 84 | * This function only affects devices with wakeup.state.enabled set, which means |
| 85 | * that it reverses the changes made by acpi_enable_wakeup_device_prep(). |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 86 | */ |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 87 | void acpi_disable_wakeup_device(u8 sleep_state) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 88 | { |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 89 | struct list_head *node, *next; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 90 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 91 | list_for_each_safe(node, next, &acpi_wakeup_device_list) { |
Alexey Starikovskiy | 9b03933 | 2007-09-26 19:47:30 +0400 | [diff] [blame] | 92 | struct acpi_device *dev = |
| 93 | container_of(node, struct acpi_device, wakeup_list); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 94 | |
Rafael J. Wysocki | 9630bdd | 2010-02-17 23:41:07 +0100 | [diff] [blame] | 95 | if (!dev->wakeup.flags.valid || !dev->wakeup.state.enabled |
| 96 | || (sleep_state > (u32) dev->wakeup.sleep_state)) |
Alexey Starikovskiy | 9b03933 | 2007-09-26 19:47:30 +0400 | [diff] [blame] | 97 | continue; |
Rafael J. Wysocki | eb9d0fe | 2008-07-07 03:34:48 +0200 | [diff] [blame] | 98 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 99 | acpi_disable_wakeup_device_power(dev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 100 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 101 | } |
| 102 | |
Bjorn Helgaas | 201b8c6 | 2009-03-24 16:50:19 -0600 | [diff] [blame] | 103 | int __init acpi_wakeup_device_init(void) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 104 | { |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 105 | struct list_head *node, *next; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 106 | |
Shaohua Li | 9090589 | 2009-04-07 10:24:29 +0800 | [diff] [blame] | 107 | mutex_lock(&acpi_device_lock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 108 | list_for_each_safe(node, next, &acpi_wakeup_device_list) { |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 109 | struct acpi_device *dev = container_of(node, |
| 110 | struct acpi_device, |
| 111 | wakeup_list); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 112 | /* In case user doesn't load button driver */ |
Rafael J. Wysocki | f517709 | 2010-02-17 23:41:49 +0100 | [diff] [blame] | 113 | if (!dev->wakeup.flags.always_enabled || |
| 114 | dev->wakeup.state.enabled) |
Alexey Starikovskiy | 9b03933 | 2007-09-26 19:47:30 +0400 | [diff] [blame] | 115 | continue; |
Rafael J. Wysocki | 9630bdd | 2010-02-17 23:41:07 +0100 | [diff] [blame] | 116 | acpi_enable_gpe(dev->wakeup.gpe_device, dev->wakeup.gpe_number, |
| 117 | ACPI_GPE_TYPE_WAKE); |
Alexey Starikovskiy | 9b03933 | 2007-09-26 19:47:30 +0400 | [diff] [blame] | 118 | dev->wakeup.state.enabled = 1; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 119 | } |
Shaohua Li | 9090589 | 2009-04-07 10:24:29 +0800 | [diff] [blame] | 120 | mutex_unlock(&acpi_device_lock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 121 | return 0; |
| 122 | } |