blob: f62a50c3ed3401e20fe7c0af8555584110cecb8e [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
40 || !(dev->wakeup.state.enabled || dev->wakeup.prepare_count)
Rafael J. Wysocki9630bdd2010-02-17 23:41:07 +010041 || sleep_state > (u32) dev->wakeup.sleep_state)
Linus Torvalds1da177e2005-04-16 15:20:36 -070042 continue;
Rafael J. Wysocki9630bdd2010-02-17 23:41:07 +010043
Rafael J. Wysocki78f5f022010-07-06 22:09:38 -040044 if (dev->wakeup.state.enabled)
45 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. */
Rafael J. Wysockie8b6f972010-06-25 01:18:39 +020048 acpi_gpe_wakeup(dev->wakeup.gpe_device, dev->wakeup.gpe_number,
49 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
66 || !(dev->wakeup.state.enabled || dev->wakeup.prepare_count)
Rafael J. Wysocki9630bdd2010-02-17 23:41:07 +010067 || (sleep_state > (u32) dev->wakeup.sleep_state))
Alexey Starikovskiy9b039332007-09-26 19:47:30 +040068 continue;
Rafael J. Wysockieb9d0fe2008-07-07 03:34:48 +020069
Rafael J. Wysockie8b6f972010-06-25 01:18:39 +020070 acpi_gpe_wakeup(dev->wakeup.gpe_device, dev->wakeup.gpe_number,
71 ACPI_GPE_DISABLE);
72
73 if (dev->wakeup.state.enabled)
74 acpi_disable_wakeup_device_power(dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -070075 }
Linus Torvalds1da177e2005-04-16 15:20:36 -070076}
77
Bjorn Helgaas201b8c62009-03-24 16:50:19 -060078int __init acpi_wakeup_device_init(void)
Linus Torvalds1da177e2005-04-16 15:20:36 -070079{
Len Brown4be44fc2005-08-05 00:44:28 -040080 struct list_head *node, *next;
Linus Torvalds1da177e2005-04-16 15:20:36 -070081
Shaohua Li90905892009-04-07 10:24:29 +080082 mutex_lock(&acpi_device_lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -070083 list_for_each_safe(node, next, &acpi_wakeup_device_list) {
Len Brown4be44fc2005-08-05 00:44:28 -040084 struct acpi_device *dev = container_of(node,
85 struct acpi_device,
86 wakeup_list);
Rafael J. Wysockicb1cb172010-06-17 17:40:57 +020087 if (dev->wakeup.flags.always_enabled)
88 dev->wakeup.state.enabled = 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -070089 }
Shaohua Li90905892009-04-07 10:24:29 +080090 mutex_unlock(&acpi_device_lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -070091 return 0;
92}