blob: 1638401ab282ef2dc554fff498ebaba8babf8daf [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>
Linus Torvalds1da177e2005-04-16 15:20:36 -07008#include <linux/kernel.h>
9#include <linux/types.h>
Bjorn Helgaase60cc7a2009-03-13 12:08:26 -060010
11#include "internal.h"
Linus Torvalds1da177e2005-04-16 15:20:36 -070012#include "sleep.h"
13
Shaohua Li90905892009-04-07 10:24:29 +080014/*
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 Torvalds1da177e2005-04-16 15:20:36 -070019#define _COMPONENT ACPI_SYSTEM_COMPONENT
Len Brown4be44fc2005-08-05 00:44:28 -040020ACPI_MODULE_NAME("wakeup_devices")
Linus Torvalds1da177e2005-04-16 15:20:36 -070021
Linus Torvalds1da177e2005-04-16 15:20:36 -070022/**
Rafael J. Wysocki78f5f022010-07-06 22:09:38 -040023 * acpi_enable_wakeup_devices - Enable wake-up device GPEs.
Rafael J. Wysocki9630bdd2010-02-17 23:41:07 +010024 * @sleep_state: ACPI system sleep state.
25 *
Rafael J. Wysocki78f5f022010-07-06 22:09:38 -040026 * 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 Torvalds1da177e2005-04-16 15:20:36 -070029 */
Rafael J. Wysocki78f5f022010-07-06 22:09:38 -040030void acpi_enable_wakeup_devices(u8 sleep_state)
Linus Torvalds1da177e2005-04-16 15:20:36 -070031{
Len Brown4be44fc2005-08-05 00:44:28 -040032 struct list_head *node, *next;
Linus Torvalds1da177e2005-04-16 15:20:36 -070033
Linus Torvalds1da177e2005-04-16 15:20:36 -070034 list_for_each_safe(node, next, &acpi_wakeup_device_list) {
Alexey Starikovskiy9b039332007-09-26 19:47:30 +040035 struct acpi_device *dev =
36 container_of(node, struct acpi_device, wakeup_list);
Rafael J. Wysockieb9d0fe2008-07-07 03:34:48 +020037
Rafael J. Wysockie8b6f972010-06-25 01:18:39 +020038 if (!dev->wakeup.flags.valid
Rafael J. Wysockif2b56bc2011-01-06 23:34:22 +010039 || sleep_state > (u32) dev->wakeup.sleep_state
40 || !(device_may_wakeup(&dev->dev)
41 || dev->wakeup.prepare_count))
Linus Torvalds1da177e2005-04-16 15:20:36 -070042 continue;
Rafael J. Wysocki9630bdd2010-02-17 23:41:07 +010043
Rafael J. Wysockif2b56bc2011-01-06 23:34:22 +010044 if (device_may_wakeup(&dev->dev))
Rafael J. Wysocki78f5f022010-07-06 22:09:38 -040045 acpi_enable_wakeup_device_power(dev, sleep_state);
46
Rafael J. Wysocki9630bdd2010-02-17 23:41:07 +010047 /* The wake-up power should have been enabled already. */
Lin Ming3a378982010-12-13 13:36:15 +080048 acpi_set_gpe_wake_mask(dev->wakeup.gpe_device, dev->wakeup.gpe_number,
Rafael J. Wysockie8b6f972010-06-25 01:18:39 +020049 ACPI_GPE_ENABLE);
Linus Torvalds1da177e2005-04-16 15:20:36 -070050 }
Linus Torvalds1da177e2005-04-16 15:20:36 -070051}
52
53/**
Rafael J. Wysocki78f5f022010-07-06 22:09:38 -040054 * acpi_disable_wakeup_devices - Disable devices' wakeup capability.
Rafael J. Wysocki9630bdd2010-02-17 23:41:07 +010055 * @sleep_state: ACPI system sleep state.
Linus Torvalds1da177e2005-04-16 15:20:36 -070056 */
Rafael J. Wysocki78f5f022010-07-06 22:09:38 -040057void acpi_disable_wakeup_devices(u8 sleep_state)
Linus Torvalds1da177e2005-04-16 15:20:36 -070058{
Len Brown4be44fc2005-08-05 00:44:28 -040059 struct list_head *node, *next;
Linus Torvalds1da177e2005-04-16 15:20:36 -070060
Linus Torvalds1da177e2005-04-16 15:20:36 -070061 list_for_each_safe(node, next, &acpi_wakeup_device_list) {
Alexey Starikovskiy9b039332007-09-26 19:47:30 +040062 struct acpi_device *dev =
63 container_of(node, struct acpi_device, wakeup_list);
Linus Torvalds1da177e2005-04-16 15:20:36 -070064
Rafael J. Wysockie8b6f972010-06-25 01:18:39 +020065 if (!dev->wakeup.flags.valid
Rafael J. Wysockif2b56bc2011-01-06 23:34:22 +010066 || sleep_state > (u32) dev->wakeup.sleep_state
67 || !(device_may_wakeup(&dev->dev)
68 || dev->wakeup.prepare_count))
Alexey Starikovskiy9b039332007-09-26 19:47:30 +040069 continue;
Rafael J. Wysockieb9d0fe2008-07-07 03:34:48 +020070
Lin Ming3a378982010-12-13 13:36:15 +080071 acpi_set_gpe_wake_mask(dev->wakeup.gpe_device, dev->wakeup.gpe_number,
Rafael J. Wysockie8b6f972010-06-25 01:18:39 +020072 ACPI_GPE_DISABLE);
73
Rafael J. Wysockif2b56bc2011-01-06 23:34:22 +010074 if (device_may_wakeup(&dev->dev))
Rafael J. Wysockie8b6f972010-06-25 01:18:39 +020075 acpi_disable_wakeup_device_power(dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -070076 }
Linus Torvalds1da177e2005-04-16 15:20:36 -070077}
78
Bjorn Helgaas201b8c62009-03-24 16:50:19 -060079int __init acpi_wakeup_device_init(void)
Linus Torvalds1da177e2005-04-16 15:20:36 -070080{
Len Brown4be44fc2005-08-05 00:44:28 -040081 struct list_head *node, *next;
Linus Torvalds1da177e2005-04-16 15:20:36 -070082
Shaohua Li90905892009-04-07 10:24:29 +080083 mutex_lock(&acpi_device_lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -070084 list_for_each_safe(node, next, &acpi_wakeup_device_list) {
Len Brown4be44fc2005-08-05 00:44:28 -040085 struct acpi_device *dev = container_of(node,
86 struct acpi_device,
87 wakeup_list);
Rafael J. Wysocki2a5d2422011-02-12 01:39:53 +010088 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. Wysockif2b56bc2011-01-06 23:34:22 +010092 device_set_wakeup_enable(&dev->dev, true);
Rafael J. Wysocki2a5d2422011-02-12 01:39:53 +010093 }
Linus Torvalds1da177e2005-04-16 15:20:36 -070094 }
Shaohua Li90905892009-04-07 10:24:29 +080095 mutex_unlock(&acpi_device_lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -070096 return 0;
97}