Commit | Line | Data |
---|---|---|
1da177e4 LT |
1 | /* |
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> | |
e60cc7a6 BH |
11 | |
12 | #include "internal.h" | |
1da177e4 LT |
13 | #include "sleep.h" |
14 | ||
15 | #define _COMPONENT ACPI_SYSTEM_COMPONENT | |
4be44fcd | 16 | ACPI_MODULE_NAME("wakeup_devices") |
1da177e4 | 17 | |
4be44fcd | 18 | extern struct list_head acpi_wakeup_device_list; |
1da177e4 LT |
19 | extern spinlock_t acpi_device_lock; |
20 | ||
1da177e4 LT |
21 | /** |
22 | * acpi_enable_wakeup_device_prep - prepare wakeup devices | |
23 | * @sleep_state: ACPI state | |
24 | * Enable all wakup devices power if the devices' wakeup level | |
25 | * is higher than requested sleep level | |
26 | */ | |
27 | ||
4be44fcd | 28 | void acpi_enable_wakeup_device_prep(u8 sleep_state) |
1da177e4 | 29 | { |
4be44fcd | 30 | struct list_head *node, *next; |
1da177e4 | 31 | |
1da177e4 LT |
32 | spin_lock(&acpi_device_lock); |
33 | list_for_each_safe(node, next, &acpi_wakeup_device_list) { | |
4be44fcd LB |
34 | struct acpi_device *dev = container_of(node, |
35 | struct acpi_device, | |
36 | wakeup_list); | |
37 | ||
38 | if (!dev->wakeup.flags.valid || | |
39 | !dev->wakeup.state.enabled || | |
40 | (sleep_state > (u32) dev->wakeup.sleep_state)) | |
1da177e4 LT |
41 | continue; |
42 | ||
43 | spin_unlock(&acpi_device_lock); | |
77e76609 | 44 | acpi_enable_wakeup_device_power(dev, sleep_state); |
1da177e4 LT |
45 | spin_lock(&acpi_device_lock); |
46 | } | |
47 | spin_unlock(&acpi_device_lock); | |
48 | } | |
49 | ||
50 | /** | |
51 | * acpi_enable_wakeup_device - enable wakeup devices | |
52 | * @sleep_state: ACPI state | |
53 | * Enable all wakup devices's GPE | |
54 | */ | |
4be44fcd | 55 | void acpi_enable_wakeup_device(u8 sleep_state) |
1da177e4 | 56 | { |
4be44fcd | 57 | struct list_head *node, *next; |
1da177e4 LT |
58 | |
59 | /* | |
60 | * Caution: this routine must be invoked when interrupt is disabled | |
61 | * Refer ACPI2.0: P212 | |
62 | */ | |
1da177e4 LT |
63 | spin_lock(&acpi_device_lock); |
64 | list_for_each_safe(node, next, &acpi_wakeup_device_list) { | |
9b039330 AS |
65 | struct acpi_device *dev = |
66 | container_of(node, struct acpi_device, wakeup_list); | |
eb9d0fe4 | 67 | |
9b039330 AS |
68 | if (!dev->wakeup.flags.valid) |
69 | continue; | |
eb9d0fe4 | 70 | |
1da177e4 LT |
71 | /* If users want to disable run-wake GPE, |
72 | * we only disable it for wake and leave it for runtime | |
73 | */ | |
eb9d0fe4 RW |
74 | if ((!dev->wakeup.state.enabled && !dev->wakeup.flags.prepared) |
75 | || sleep_state > (u32) dev->wakeup.sleep_state) { | |
9b039330 AS |
76 | if (dev->wakeup.flags.run_wake) { |
77 | spin_unlock(&acpi_device_lock); | |
78 | /* set_gpe_type will disable GPE, leave it like that */ | |
79 | acpi_set_gpe_type(dev->wakeup.gpe_device, | |
80 | dev->wakeup.gpe_number, | |
81 | ACPI_GPE_TYPE_RUNTIME); | |
82 | spin_lock(&acpi_device_lock); | |
83 | } | |
1da177e4 LT |
84 | continue; |
85 | } | |
1da177e4 | 86 | spin_unlock(&acpi_device_lock); |
1da177e4 | 87 | if (!dev->wakeup.flags.run_wake) |
4be44fcd | 88 | acpi_enable_gpe(dev->wakeup.gpe_device, |
0b7084ac | 89 | dev->wakeup.gpe_number); |
1da177e4 LT |
90 | spin_lock(&acpi_device_lock); |
91 | } | |
92 | spin_unlock(&acpi_device_lock); | |
93 | } | |
94 | ||
95 | /** | |
96 | * acpi_disable_wakeup_device - disable devices' wakeup capability | |
97 | * @sleep_state: ACPI state | |
98 | * Disable all wakup devices's GPE and wakeup capability | |
99 | */ | |
4be44fcd | 100 | void acpi_disable_wakeup_device(u8 sleep_state) |
1da177e4 | 101 | { |
4be44fcd | 102 | struct list_head *node, *next; |
1da177e4 | 103 | |
1da177e4 LT |
104 | spin_lock(&acpi_device_lock); |
105 | list_for_each_safe(node, next, &acpi_wakeup_device_list) { | |
9b039330 AS |
106 | struct acpi_device *dev = |
107 | container_of(node, struct acpi_device, wakeup_list); | |
1da177e4 | 108 | |
9b039330 | 109 | if (!dev->wakeup.flags.valid) |
1da177e4 | 110 | continue; |
eb9d0fe4 RW |
111 | |
112 | if ((!dev->wakeup.state.enabled && !dev->wakeup.flags.prepared) | |
113 | || sleep_state > (u32) dev->wakeup.sleep_state) { | |
9b039330 AS |
114 | if (dev->wakeup.flags.run_wake) { |
115 | spin_unlock(&acpi_device_lock); | |
116 | acpi_set_gpe_type(dev->wakeup.gpe_device, | |
117 | dev->wakeup.gpe_number, | |
118 | ACPI_GPE_TYPE_WAKE_RUN); | |
119 | /* Re-enable it, since set_gpe_type will disable it */ | |
120 | acpi_enable_gpe(dev->wakeup.gpe_device, | |
0b7084ac | 121 | dev->wakeup.gpe_number); |
9b039330 AS |
122 | spin_lock(&acpi_device_lock); |
123 | } | |
1da177e4 | 124 | continue; |
9b039330 | 125 | } |
1da177e4 LT |
126 | |
127 | spin_unlock(&acpi_device_lock); | |
128 | acpi_disable_wakeup_device_power(dev); | |
129 | /* Never disable run-wake GPE */ | |
130 | if (!dev->wakeup.flags.run_wake) { | |
4be44fcd | 131 | acpi_disable_gpe(dev->wakeup.gpe_device, |
0b7084ac | 132 | dev->wakeup.gpe_number); |
4be44fcd LB |
133 | acpi_clear_gpe(dev->wakeup.gpe_device, |
134 | dev->wakeup.gpe_number, ACPI_NOT_ISR); | |
1da177e4 | 135 | } |
1da177e4 LT |
136 | spin_lock(&acpi_device_lock); |
137 | } | |
138 | spin_unlock(&acpi_device_lock); | |
139 | } | |
140 | ||
141 | static int __init acpi_wakeup_device_init(void) | |
142 | { | |
4be44fcd | 143 | struct list_head *node, *next; |
1da177e4 LT |
144 | |
145 | if (acpi_disabled) | |
146 | return 0; | |
1da177e4 LT |
147 | |
148 | spin_lock(&acpi_device_lock); | |
149 | list_for_each_safe(node, next, &acpi_wakeup_device_list) { | |
4be44fcd LB |
150 | struct acpi_device *dev = container_of(node, |
151 | struct acpi_device, | |
152 | wakeup_list); | |
1da177e4 | 153 | /* In case user doesn't load button driver */ |
9b039330 AS |
154 | if (!dev->wakeup.flags.run_wake || dev->wakeup.state.enabled) |
155 | continue; | |
156 | spin_unlock(&acpi_device_lock); | |
157 | acpi_set_gpe_type(dev->wakeup.gpe_device, | |
158 | dev->wakeup.gpe_number, | |
159 | ACPI_GPE_TYPE_WAKE_RUN); | |
160 | acpi_enable_gpe(dev->wakeup.gpe_device, | |
0b7084ac | 161 | dev->wakeup.gpe_number); |
9b039330 AS |
162 | dev->wakeup.state.enabled = 1; |
163 | spin_lock(&acpi_device_lock); | |
1da177e4 LT |
164 | } |
165 | spin_unlock(&acpi_device_lock); | |
1da177e4 LT |
166 | return 0; |
167 | } | |
168 | ||
169 | late_initcall(acpi_wakeup_device_init); |