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> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 8 | #include <linux/kernel.h> |
| 9 | #include <linux/types.h> |
Bjorn Helgaas | e60cc7a | 2009-03-13 12:08:26 -0600 | [diff] [blame] | 10 | |
| 11 | #include "internal.h" |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 12 | #include "sleep.h" |
| 13 | |
Shaohua Li | 9090589 | 2009-04-07 10:24:29 +0800 | [diff] [blame] | 14 | /* |
| 15 | * We didn't lock acpi_device_lock in the file, because it invokes oops in |
| 16 | * suspend/resume and isn't really required as this is called in S-state. At |
| 17 | * that time, there is no device hotplug |
| 18 | **/ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 19 | #define _COMPONENT ACPI_SYSTEM_COMPONENT |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 20 | ACPI_MODULE_NAME("wakeup_devices") |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 21 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 22 | /** |
Rafael J. Wysocki | 78f5f02 | 2010-07-06 22:09:38 -0400 | [diff] [blame] | 23 | * acpi_enable_wakeup_devices - Enable wake-up device GPEs. |
Rafael J. Wysocki | 9630bdd | 2010-02-17 23:41:07 +0100 | [diff] [blame] | 24 | * @sleep_state: ACPI system sleep state. |
| 25 | * |
Rafael J. Wysocki | 78f5f02 | 2010-07-06 22:09:38 -0400 | [diff] [blame] | 26 | * Enable wakeup device power of devices with the state.enable flag set and set |
| 27 | * the wakeup enable mask bits in the GPE registers that correspond to wakeup |
| 28 | * devices. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 29 | */ |
Rafael J. Wysocki | 78f5f02 | 2010-07-06 22:09:38 -0400 | [diff] [blame] | 30 | void acpi_enable_wakeup_devices(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) { |
Alexey Starikovskiy | 9b03933 | 2007-09-26 19:47:30 +0400 | [diff] [blame] | 35 | struct acpi_device *dev = |
| 36 | container_of(node, struct acpi_device, wakeup_list); |
Rafael J. Wysocki | eb9d0fe | 2008-07-07 03:34:48 +0200 | [diff] [blame] | 37 | |
Rafael J. Wysocki | e8b6f97 | 2010-06-25 01:18:39 +0200 | [diff] [blame] | 38 | if (!dev->wakeup.flags.valid |
Rafael J. Wysocki | f2b56bc | 2011-01-06 23:34:22 +0100 | [diff] [blame] | 39 | || sleep_state > (u32) dev->wakeup.sleep_state |
| 40 | || !(device_may_wakeup(&dev->dev) |
| 41 | || dev->wakeup.prepare_count)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 42 | continue; |
Rafael J. Wysocki | 9630bdd | 2010-02-17 23:41:07 +0100 | [diff] [blame] | 43 | |
Rafael J. Wysocki | f2b56bc | 2011-01-06 23:34:22 +0100 | [diff] [blame] | 44 | if (device_may_wakeup(&dev->dev)) |
Rafael J. Wysocki | 78f5f02 | 2010-07-06 22:09:38 -0400 | [diff] [blame] | 45 | acpi_enable_wakeup_device_power(dev, sleep_state); |
| 46 | |
Rafael J. Wysocki | 9630bdd | 2010-02-17 23:41:07 +0100 | [diff] [blame] | 47 | /* The wake-up power should have been enabled already. */ |
Lin Ming | 3a37898 | 2010-12-13 13:36:15 +0800 | [diff] [blame] | 48 | acpi_set_gpe_wake_mask(dev->wakeup.gpe_device, dev->wakeup.gpe_number, |
Rafael J. Wysocki | e8b6f97 | 2010-06-25 01:18:39 +0200 | [diff] [blame] | 49 | ACPI_GPE_ENABLE); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 50 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 51 | } |
| 52 | |
| 53 | /** |
Rafael J. Wysocki | 78f5f02 | 2010-07-06 22:09:38 -0400 | [diff] [blame] | 54 | * acpi_disable_wakeup_devices - Disable devices' wakeup capability. |
Rafael J. Wysocki | 9630bdd | 2010-02-17 23:41:07 +0100 | [diff] [blame] | 55 | * @sleep_state: ACPI system sleep state. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 56 | */ |
Rafael J. Wysocki | 78f5f02 | 2010-07-06 22:09:38 -0400 | [diff] [blame] | 57 | void acpi_disable_wakeup_devices(u8 sleep_state) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 58 | { |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 59 | struct list_head *node, *next; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 60 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 61 | list_for_each_safe(node, next, &acpi_wakeup_device_list) { |
Alexey Starikovskiy | 9b03933 | 2007-09-26 19:47:30 +0400 | [diff] [blame] | 62 | struct acpi_device *dev = |
| 63 | container_of(node, struct acpi_device, wakeup_list); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 64 | |
Rafael J. Wysocki | e8b6f97 | 2010-06-25 01:18:39 +0200 | [diff] [blame] | 65 | if (!dev->wakeup.flags.valid |
Rafael J. Wysocki | f2b56bc | 2011-01-06 23:34:22 +0100 | [diff] [blame] | 66 | || sleep_state > (u32) dev->wakeup.sleep_state |
| 67 | || !(device_may_wakeup(&dev->dev) |
| 68 | || dev->wakeup.prepare_count)) |
Alexey Starikovskiy | 9b03933 | 2007-09-26 19:47:30 +0400 | [diff] [blame] | 69 | continue; |
Rafael J. Wysocki | eb9d0fe | 2008-07-07 03:34:48 +0200 | [diff] [blame] | 70 | |
Lin Ming | 3a37898 | 2010-12-13 13:36:15 +0800 | [diff] [blame] | 71 | acpi_set_gpe_wake_mask(dev->wakeup.gpe_device, dev->wakeup.gpe_number, |
Rafael J. Wysocki | e8b6f97 | 2010-06-25 01:18:39 +0200 | [diff] [blame] | 72 | ACPI_GPE_DISABLE); |
| 73 | |
Rafael J. Wysocki | f2b56bc | 2011-01-06 23:34:22 +0100 | [diff] [blame] | 74 | if (device_may_wakeup(&dev->dev)) |
Rafael J. Wysocki | e8b6f97 | 2010-06-25 01:18:39 +0200 | [diff] [blame] | 75 | acpi_disable_wakeup_device_power(dev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 76 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 77 | } |
| 78 | |
Bjorn Helgaas | 201b8c6 | 2009-03-24 16:50:19 -0600 | [diff] [blame] | 79 | int __init acpi_wakeup_device_init(void) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 80 | { |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 81 | struct list_head *node, *next; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 82 | |
Shaohua Li | 9090589 | 2009-04-07 10:24:29 +0800 | [diff] [blame] | 83 | mutex_lock(&acpi_device_lock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 84 | list_for_each_safe(node, next, &acpi_wakeup_device_list) { |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 85 | struct acpi_device *dev = container_of(node, |
| 86 | struct acpi_device, |
| 87 | wakeup_list); |
Rafael J. Wysocki | 2a5d242 | 2011-02-12 01:39:53 +0100 | [diff] [blame] | 88 | if (device_can_wakeup(&dev->dev)) { |
| 89 | /* Button GPEs are supposed to be always enabled. */ |
| 90 | acpi_enable_gpe(dev->wakeup.gpe_device, |
| 91 | dev->wakeup.gpe_number); |
Rafael J. Wysocki | f2b56bc | 2011-01-06 23:34:22 +0100 | [diff] [blame] | 92 | device_set_wakeup_enable(&dev->dev, true); |
Rafael J. Wysocki | 2a5d242 | 2011-02-12 01:39:53 +0100 | [diff] [blame] | 93 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 94 | } |
Shaohua Li | 9090589 | 2009-04-07 10:24:29 +0800 | [diff] [blame] | 95 | mutex_unlock(&acpi_device_lock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 96 | return 0; |
| 97 | } |