blob: 7bfbe40bc43bcb5e736c4c77788d4b7d577de160 [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. Wysockie8b6f972010-06-25 01:18:39 +020039 if (!dev->wakeup.flags.valid
Rafael J. Wysockif2b56bc2011-01-06 23:34:22 +010040 || sleep_state > (u32) dev->wakeup.sleep_state
41 || !(device_may_wakeup(&dev->dev)
42 || dev->wakeup.prepare_count))
Linus Torvalds1da177e2005-04-16 15:20:36 -070043 continue;
Rafael J. Wysocki9630bdd2010-02-17 23:41:07 +010044
Rafael J. Wysockif2b56bc2011-01-06 23:34:22 +010045 if (device_may_wakeup(&dev->dev))
Rafael J. Wysocki78f5f022010-07-06 22:09:38 -040046 acpi_enable_wakeup_device_power(dev, sleep_state);
47
Rafael J. Wysocki9630bdd2010-02-17 23:41:07 +010048 /* The wake-up power should have been enabled already. */
Lin Ming3a378982010-12-13 13:36:15 +080049 acpi_set_gpe_wake_mask(dev->wakeup.gpe_device, dev->wakeup.gpe_number,
Rafael J. Wysockie8b6f972010-06-25 01:18:39 +020050 ACPI_GPE_ENABLE);
Linus Torvalds1da177e2005-04-16 15:20:36 -070051 }
Linus Torvalds1da177e2005-04-16 15:20:36 -070052}
53
54/**
Rafael J. Wysocki78f5f022010-07-06 22:09:38 -040055 * acpi_disable_wakeup_devices - Disable devices' wakeup capability.
Rafael J. Wysocki9630bdd2010-02-17 23:41:07 +010056 * @sleep_state: ACPI system sleep state.
Linus Torvalds1da177e2005-04-16 15:20:36 -070057 */
Rafael J. Wysocki78f5f022010-07-06 22:09:38 -040058void acpi_disable_wakeup_devices(u8 sleep_state)
Linus Torvalds1da177e2005-04-16 15:20:36 -070059{
Len Brown4be44fc2005-08-05 00:44:28 -040060 struct list_head *node, *next;
Linus Torvalds1da177e2005-04-16 15:20:36 -070061
Linus Torvalds1da177e2005-04-16 15:20:36 -070062 list_for_each_safe(node, next, &acpi_wakeup_device_list) {
Alexey Starikovskiy9b039332007-09-26 19:47:30 +040063 struct acpi_device *dev =
64 container_of(node, struct acpi_device, wakeup_list);
Linus Torvalds1da177e2005-04-16 15:20:36 -070065
Rafael J. Wysockie8b6f972010-06-25 01:18:39 +020066 if (!dev->wakeup.flags.valid
Rafael J. Wysockif2b56bc2011-01-06 23:34:22 +010067 || sleep_state > (u32) dev->wakeup.sleep_state
68 || !(device_may_wakeup(&dev->dev)
69 || dev->wakeup.prepare_count))
Alexey Starikovskiy9b039332007-09-26 19:47:30 +040070 continue;
Rafael J. Wysockieb9d0fe2008-07-07 03:34:48 +020071
Lin Ming3a378982010-12-13 13:36:15 +080072 acpi_set_gpe_wake_mask(dev->wakeup.gpe_device, dev->wakeup.gpe_number,
Rafael J. Wysockie8b6f972010-06-25 01:18:39 +020073 ACPI_GPE_DISABLE);
74
Rafael J. Wysockif2b56bc2011-01-06 23:34:22 +010075 if (device_may_wakeup(&dev->dev))
Rafael J. Wysockie8b6f972010-06-25 01:18:39 +020076 acpi_disable_wakeup_device_power(dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -070077 }
Linus Torvalds1da177e2005-04-16 15:20:36 -070078}
79
Bjorn Helgaas201b8c62009-03-24 16:50:19 -060080int __init acpi_wakeup_device_init(void)
Linus Torvalds1da177e2005-04-16 15:20:36 -070081{
Len Brown4be44fc2005-08-05 00:44:28 -040082 struct list_head *node, *next;
Linus Torvalds1da177e2005-04-16 15:20:36 -070083
Shaohua Li90905892009-04-07 10:24:29 +080084 mutex_lock(&acpi_device_lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -070085 list_for_each_safe(node, next, &acpi_wakeup_device_list) {
Len Brown4be44fc2005-08-05 00:44:28 -040086 struct acpi_device *dev = container_of(node,
87 struct acpi_device,
88 wakeup_list);
Rafael J. Wysocki2a5d2422011-02-12 01:39:53 +010089 if (device_can_wakeup(&dev->dev)) {
90 /* Button GPEs are supposed to be always enabled. */
91 acpi_enable_gpe(dev->wakeup.gpe_device,
92 dev->wakeup.gpe_number);
Rafael J. Wysockif2b56bc2011-01-06 23:34:22 +010093 device_set_wakeup_enable(&dev->dev, true);
Rafael J. Wysocki2a5d2422011-02-12 01:39:53 +010094 }
Linus Torvalds1da177e2005-04-16 15:20:36 -070095 }
Shaohua Li90905892009-04-07 10:24:29 +080096 mutex_unlock(&acpi_device_lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -070097 return 0;
98}