blob: dc6d1d9112fb58809a6db021a6eba031d7d2315b [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/*
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 Helgaase60cc7a2009-03-13 12:08:26 -060011
12#include "internal.h"
Linus Torvalds1da177e2005-04-16 15:20:36 -070013#include "sleep.h"
14
Shaohua Li90905892009-04-07 10:24:29 +080015/*
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 Torvalds1da177e2005-04-16 15:20:36 -070020#define _COMPONENT ACPI_SYSTEM_COMPONENT
Len Brown4be44fc2005-08-05 00:44:28 -040021ACPI_MODULE_NAME("wakeup_devices")
Linus Torvalds1da177e2005-04-16 15:20:36 -070022
Linus Torvalds1da177e2005-04-16 15:20:36 -070023/**
Rafael J. Wysocki78f5f022010-07-06 22:09:38 -040024 * acpi_enable_wakeup_devices - Enable wake-up device GPEs.
Rafael J. Wysocki9630bdd2010-02-17 23:41:07 +010025 * @sleep_state: ACPI system sleep state.
26 *
Rafael J. Wysocki78f5f022010-07-06 22:09:38 -040027 * Enable wakeup device power of devices with the state.enable flag set and set
28 * the wakeup enable mask bits in the GPE registers that correspond to wakeup
29 * devices.
Linus Torvalds1da177e2005-04-16 15:20:36 -070030 */
Rafael J. Wysocki78f5f022010-07-06 22:09:38 -040031void acpi_enable_wakeup_devices(u8 sleep_state)
Linus Torvalds1da177e2005-04-16 15:20:36 -070032{
Len Brown4be44fc2005-08-05 00:44:28 -040033 struct list_head *node, *next;
Linus Torvalds1da177e2005-04-16 15:20:36 -070034
Linus Torvalds1da177e2005-04-16 15:20:36 -070035 list_for_each_safe(node, next, &acpi_wakeup_device_list) {
Alexey Starikovskiy9b039332007-09-26 19:47:30 +040036 struct acpi_device *dev =
37 container_of(node, struct acpi_device, wakeup_list);
Rafael J. Wysockieb9d0fe2008-07-07 03:34:48 +020038
Rafael J. Wysockicb1cb172010-06-17 17:40:57 +020039 if (!dev->wakeup.flags.valid || !dev->wakeup.state.enabled
Rafael J. Wysocki9630bdd2010-02-17 23:41:07 +010040 || sleep_state > (u32) dev->wakeup.sleep_state)
Linus Torvalds1da177e2005-04-16 15:20:36 -070041 continue;
Rafael J. Wysocki9630bdd2010-02-17 23:41:07 +010042
Rafael J. Wysocki78f5f022010-07-06 22:09:38 -040043 if (dev->wakeup.state.enabled)
44 acpi_enable_wakeup_device_power(dev, sleep_state);
45
Rafael J. Wysocki9630bdd2010-02-17 23:41:07 +010046 /* The wake-up power should have been enabled already. */
Rafael J. Wysockicb1cb172010-06-17 17:40:57 +020047 acpi_enable_gpe(dev->wakeup.gpe_device, dev->wakeup.gpe_number,
48 ACPI_GPE_TYPE_WAKE);
Linus Torvalds1da177e2005-04-16 15:20:36 -070049 }
Linus Torvalds1da177e2005-04-16 15:20:36 -070050}
51
52/**
Rafael J. Wysocki78f5f022010-07-06 22:09:38 -040053 * acpi_disable_wakeup_devices - Disable devices' wakeup capability.
Rafael J. Wysocki9630bdd2010-02-17 23:41:07 +010054 * @sleep_state: ACPI system sleep state.
Linus Torvalds1da177e2005-04-16 15:20:36 -070055 */
Rafael J. Wysocki78f5f022010-07-06 22:09:38 -040056void acpi_disable_wakeup_devices(u8 sleep_state)
Linus Torvalds1da177e2005-04-16 15:20:36 -070057{
Len Brown4be44fc2005-08-05 00:44:28 -040058 struct list_head *node, *next;
Linus Torvalds1da177e2005-04-16 15:20:36 -070059
Linus Torvalds1da177e2005-04-16 15:20:36 -070060 list_for_each_safe(node, next, &acpi_wakeup_device_list) {
Alexey Starikovskiy9b039332007-09-26 19:47:30 +040061 struct acpi_device *dev =
62 container_of(node, struct acpi_device, wakeup_list);
Linus Torvalds1da177e2005-04-16 15:20:36 -070063
Rafael J. Wysocki9630bdd2010-02-17 23:41:07 +010064 if (!dev->wakeup.flags.valid || !dev->wakeup.state.enabled
65 || (sleep_state > (u32) dev->wakeup.sleep_state))
Alexey Starikovskiy9b039332007-09-26 19:47:30 +040066 continue;
Rafael J. Wysockieb9d0fe2008-07-07 03:34:48 +020067
Rafael J. Wysockicb1cb172010-06-17 17:40:57 +020068 acpi_disable_gpe(dev->wakeup.gpe_device, dev->wakeup.gpe_number,
69 ACPI_GPE_TYPE_WAKE);
Linus Torvalds1da177e2005-04-16 15:20:36 -070070 acpi_disable_wakeup_device_power(dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -070071 }
Linus Torvalds1da177e2005-04-16 15:20:36 -070072}
73
Bjorn Helgaas201b8c62009-03-24 16:50:19 -060074int __init acpi_wakeup_device_init(void)
Linus Torvalds1da177e2005-04-16 15:20:36 -070075{
Len Brown4be44fc2005-08-05 00:44:28 -040076 struct list_head *node, *next;
Linus Torvalds1da177e2005-04-16 15:20:36 -070077
Shaohua Li90905892009-04-07 10:24:29 +080078 mutex_lock(&acpi_device_lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -070079 list_for_each_safe(node, next, &acpi_wakeup_device_list) {
Len Brown4be44fc2005-08-05 00:44:28 -040080 struct acpi_device *dev = container_of(node,
81 struct acpi_device,
82 wakeup_list);
Rafael J. Wysockicb1cb172010-06-17 17:40:57 +020083 if (dev->wakeup.flags.always_enabled)
84 dev->wakeup.state.enabled = 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -070085 }
Shaohua Li90905892009-04-07 10:24:29 +080086 mutex_unlock(&acpi_device_lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -070087 return 0;
88}