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