blob: c80537bc3234dd012a3e047907ad0c572b2e6f6a [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. Wysocki9630bdd2010-02-17 23:41:07 +010024 * acpi_enable_wakeup_device_prep - Prepare wake-up devices.
25 * @sleep_state: ACPI system sleep state.
26 *
27 * Enable all wake-up devices' power, unless the requested system sleep state is
28 * too deep.
Linus Torvalds1da177e2005-04-16 15:20:36 -070029 */
Len Brown4be44fc2005-08-05 00:44:28 -040030void acpi_enable_wakeup_device_prep(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) {
Len Brown4be44fc2005-08-05 00:44:28 -040035 struct acpi_device *dev = container_of(node,
36 struct acpi_device,
37 wakeup_list);
38
Rafael J. Wysocki9630bdd2010-02-17 23:41:07 +010039 if (!dev->wakeup.flags.valid || !dev->wakeup.state.enabled
40 || (sleep_state > (u32) dev->wakeup.sleep_state))
Linus Torvalds1da177e2005-04-16 15:20:36 -070041 continue;
42
Rafael J. Wysocki77e76602008-07-07 03:33:34 +020043 acpi_enable_wakeup_device_power(dev, sleep_state);
Linus Torvalds1da177e2005-04-16 15:20:36 -070044 }
Linus Torvalds1da177e2005-04-16 15:20:36 -070045}
46
47/**
Rafael J. Wysocki9630bdd2010-02-17 23:41:07 +010048 * acpi_enable_wakeup_device - Enable wake-up device GPEs.
49 * @sleep_state: ACPI system sleep state.
50 *
51 * Enable all wake-up devices' GPEs, with the assumption that
52 * acpi_disable_all_gpes() was executed before, so we don't need to disable any
53 * GPEs here.
Linus Torvalds1da177e2005-04-16 15:20:36 -070054 */
Len Brown4be44fc2005-08-05 00:44:28 -040055void acpi_enable_wakeup_device(u8 sleep_state)
Linus Torvalds1da177e2005-04-16 15:20:36 -070056{
Len Brown4be44fc2005-08-05 00:44:28 -040057 struct list_head *node, *next;
Linus Torvalds1da177e2005-04-16 15:20:36 -070058
59 /*
60 * Caution: this routine must be invoked when interrupt is disabled
61 * Refer ACPI2.0: P212
62 */
Linus Torvalds1da177e2005-04-16 15:20:36 -070063 list_for_each_safe(node, next, &acpi_wakeup_device_list) {
Alexey Starikovskiy9b039332007-09-26 19:47:30 +040064 struct acpi_device *dev =
65 container_of(node, struct acpi_device, wakeup_list);
Rafael J. Wysockieb9d0fe2008-07-07 03:34:48 +020066
Rafael J. Wysockie8b6f972010-06-25 01:18:39 +020067 if (!dev->wakeup.flags.valid
68 || !(dev->wakeup.state.enabled || dev->wakeup.prepare_count)
Rafael J. Wysocki9630bdd2010-02-17 23:41:07 +010069 || sleep_state > (u32) dev->wakeup.sleep_state)
Linus Torvalds1da177e2005-04-16 15:20:36 -070070 continue;
Rafael J. Wysocki9630bdd2010-02-17 23:41:07 +010071
72 /* The wake-up power should have been enabled already. */
Rafael J. Wysockie8b6f972010-06-25 01:18:39 +020073 acpi_gpe_wakeup(dev->wakeup.gpe_device, dev->wakeup.gpe_number,
74 ACPI_GPE_ENABLE);
Linus Torvalds1da177e2005-04-16 15:20:36 -070075 }
Linus Torvalds1da177e2005-04-16 15:20:36 -070076}
77
78/**
Rafael J. Wysocki9630bdd2010-02-17 23:41:07 +010079 * acpi_disable_wakeup_device - Disable devices' wakeup capability.
80 * @sleep_state: ACPI system sleep state.
81 *
82 * This function only affects devices with wakeup.state.enabled set, which means
83 * that it reverses the changes made by acpi_enable_wakeup_device_prep().
Linus Torvalds1da177e2005-04-16 15:20:36 -070084 */
Len Brown4be44fc2005-08-05 00:44:28 -040085void acpi_disable_wakeup_device(u8 sleep_state)
Linus Torvalds1da177e2005-04-16 15:20:36 -070086{
Len Brown4be44fc2005-08-05 00:44:28 -040087 struct list_head *node, *next;
Linus Torvalds1da177e2005-04-16 15:20:36 -070088
Linus Torvalds1da177e2005-04-16 15:20:36 -070089 list_for_each_safe(node, next, &acpi_wakeup_device_list) {
Alexey Starikovskiy9b039332007-09-26 19:47:30 +040090 struct acpi_device *dev =
91 container_of(node, struct acpi_device, wakeup_list);
Linus Torvalds1da177e2005-04-16 15:20:36 -070092
Rafael J. Wysockie8b6f972010-06-25 01:18:39 +020093 if (!dev->wakeup.flags.valid
94 || !(dev->wakeup.state.enabled || dev->wakeup.prepare_count)
Rafael J. Wysocki9630bdd2010-02-17 23:41:07 +010095 || (sleep_state > (u32) dev->wakeup.sleep_state))
Alexey Starikovskiy9b039332007-09-26 19:47:30 +040096 continue;
Rafael J. Wysockieb9d0fe2008-07-07 03:34:48 +020097
Rafael J. Wysockie8b6f972010-06-25 01:18:39 +020098 acpi_gpe_wakeup(dev->wakeup.gpe_device, dev->wakeup.gpe_number,
99 ACPI_GPE_DISABLE);
100
101 if (dev->wakeup.state.enabled)
102 acpi_disable_wakeup_device_power(dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700103 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700104}
105
Bjorn Helgaas201b8c62009-03-24 16:50:19 -0600106int __init acpi_wakeup_device_init(void)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700107{
Len Brown4be44fc2005-08-05 00:44:28 -0400108 struct list_head *node, *next;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700109
Shaohua Li90905892009-04-07 10:24:29 +0800110 mutex_lock(&acpi_device_lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700111 list_for_each_safe(node, next, &acpi_wakeup_device_list) {
Len Brown4be44fc2005-08-05 00:44:28 -0400112 struct acpi_device *dev = container_of(node,
113 struct acpi_device,
114 wakeup_list);
Rafael J. Wysockicb1cb172010-06-17 17:40:57 +0200115 if (dev->wakeup.flags.always_enabled)
116 dev->wakeup.state.enabled = 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700117 }
Shaohua Li90905892009-04-07 10:24:29 +0800118 mutex_unlock(&acpi_device_lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700119 return 0;
120}