2 * wakeup.c - support wakeup devices
3 * Copyright (C) 2004 Li Shaohua <shaohua.li@intel.com>
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>
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
20 #define _COMPONENT ACPI_SYSTEM_COMPONENT
21 ACPI_MODULE_NAME("wakeup_devices")
24 * acpi_enable_wakeup_device_prep - Prepare wake-up devices.
25 * @sleep_state: ACPI system sleep state.
27 * Enable all wake-up devices' power, unless the requested system sleep state is
30 void acpi_enable_wakeup_device_prep(u8 sleep_state
)
32 struct list_head
*node
, *next
;
34 list_for_each_safe(node
, next
, &acpi_wakeup_device_list
) {
35 struct acpi_device
*dev
= container_of(node
,
39 if (!dev
->wakeup
.flags
.valid
|| !dev
->wakeup
.state
.enabled
40 || (sleep_state
> (u32
) dev
->wakeup
.sleep_state
))
43 acpi_enable_wakeup_device_power(dev
, sleep_state
);
48 * acpi_enable_wakeup_device - Enable wake-up device GPEs.
49 * @sleep_state: ACPI system sleep state.
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
55 void acpi_enable_wakeup_device(u8 sleep_state
)
57 struct list_head
*node
, *next
;
60 * Caution: this routine must be invoked when interrupt is disabled
63 list_for_each_safe(node
, next
, &acpi_wakeup_device_list
) {
64 struct acpi_device
*dev
=
65 container_of(node
, struct acpi_device
, wakeup_list
);
67 if (!dev
->wakeup
.flags
.valid
)
70 if ((!dev
->wakeup
.state
.enabled
&& !dev
->wakeup
.prepare_count
)
71 || sleep_state
> (u32
) dev
->wakeup
.sleep_state
)
74 /* The wake-up power should have been enabled already. */
75 acpi_set_gpe(dev
->wakeup
.gpe_device
, dev
->wakeup
.gpe_number
,
81 * acpi_disable_wakeup_device - Disable devices' wakeup capability.
82 * @sleep_state: ACPI system sleep state.
84 * This function only affects devices with wakeup.state.enabled set, which means
85 * that it reverses the changes made by acpi_enable_wakeup_device_prep().
87 void acpi_disable_wakeup_device(u8 sleep_state
)
89 struct list_head
*node
, *next
;
91 list_for_each_safe(node
, next
, &acpi_wakeup_device_list
) {
92 struct acpi_device
*dev
=
93 container_of(node
, struct acpi_device
, wakeup_list
);
95 if (!dev
->wakeup
.flags
.valid
|| !dev
->wakeup
.state
.enabled
96 || (sleep_state
> (u32
) dev
->wakeup
.sleep_state
))
99 acpi_disable_wakeup_device_power(dev
);
103 int __init
acpi_wakeup_device_init(void)
105 struct list_head
*node
, *next
;
107 mutex_lock(&acpi_device_lock
);
108 list_for_each_safe(node
, next
, &acpi_wakeup_device_list
) {
109 struct acpi_device
*dev
= container_of(node
,
112 /* In case user doesn't load button driver */
113 if (!dev
->wakeup
.flags
.always_enabled
||
114 dev
->wakeup
.state
.enabled
)
116 acpi_enable_gpe(dev
->wakeup
.gpe_device
, dev
->wakeup
.gpe_number
,
118 dev
->wakeup
.state
.enabled
= 1;
120 mutex_unlock(&acpi_device_lock
);