]> rtime.felk.cvut.cz Git - lisovros/linux_canprio.git/blob - drivers/acpi/wakeup.c
ACPI / ACPICA: Fix reference counting problems with GPE handlers
[lisovros/linux_canprio.git] / drivers / acpi / 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
12 #include "internal.h"
13 #include "sleep.h"
14
15 /*
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  **/
20 #define _COMPONENT              ACPI_SYSTEM_COMPONENT
21 ACPI_MODULE_NAME("wakeup_devices")
22
23 /**
24  * 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.
29  */
30 void acpi_enable_wakeup_device_prep(u8 sleep_state)
31 {
32         struct list_head *node, *next;
33
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 || !dev->wakeup.state.enabled
40                     || (sleep_state > (u32) dev->wakeup.sleep_state))
41                         continue;
42
43                 acpi_enable_wakeup_device_power(dev, sleep_state);
44         }
45 }
46
47 /**
48  * 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.
54  */
55 void acpi_enable_wakeup_device(u8 sleep_state)
56 {
57         struct list_head *node, *next;
58
59         /* 
60          * Caution: this routine must be invoked when interrupt is disabled 
61          * Refer ACPI2.0: P212
62          */
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);
66
67                 if (!dev->wakeup.flags.valid
68                     || !(dev->wakeup.state.enabled || dev->wakeup.prepare_count)
69                     || sleep_state > (u32) dev->wakeup.sleep_state)
70                         continue;
71
72                 /* The wake-up power should have been enabled already. */
73                 acpi_gpe_wakeup(dev->wakeup.gpe_device, dev->wakeup.gpe_number,
74                                 ACPI_GPE_ENABLE);
75         }
76 }
77
78 /**
79  * 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().
84  */
85 void acpi_disable_wakeup_device(u8 sleep_state)
86 {
87         struct list_head *node, *next;
88
89         list_for_each_safe(node, next, &acpi_wakeup_device_list) {
90                 struct acpi_device *dev =
91                         container_of(node, struct acpi_device, wakeup_list);
92
93                 if (!dev->wakeup.flags.valid
94                     || !(dev->wakeup.state.enabled || dev->wakeup.prepare_count)
95                     || (sleep_state > (u32) dev->wakeup.sleep_state))
96                         continue;
97
98                 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);
103         }
104 }
105
106 int __init acpi_wakeup_device_init(void)
107 {
108         struct list_head *node, *next;
109
110         mutex_lock(&acpi_device_lock);
111         list_for_each_safe(node, next, &acpi_wakeup_device_list) {
112                 struct acpi_device *dev = container_of(node,
113                                                        struct acpi_device,
114                                                        wakeup_list);
115                 if (dev->wakeup.flags.always_enabled)
116                         dev->wakeup.state.enabled = 1;
117         }
118         mutex_unlock(&acpi_device_lock);
119         return 0;
120 }