1
2
3
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
17
18
19
20#define _COMPONENT ACPI_SYSTEM_COMPONENT
21ACPI_MODULE_NAME("wakeup_devices")
22
23
24
25
26
27
28
29
30
31void acpi_enable_wakeup_devices(u8 sleep_state)
32{
33 struct list_head *node, *next;
34
35 list_for_each_safe(node, next, &acpi_wakeup_device_list) {
36 struct acpi_device *dev =
37 container_of(node, struct acpi_device, wakeup_list);
38
39 if (!dev->wakeup.flags.valid
40 || sleep_state > (u32) dev->wakeup.sleep_state
41 || !(device_may_wakeup(&dev->dev)
42 || dev->wakeup.prepare_count))
43 continue;
44
45 if (device_may_wakeup(&dev->dev))
46 acpi_enable_wakeup_device_power(dev, sleep_state);
47
48
49 acpi_set_gpe_wake_mask(dev->wakeup.gpe_device, dev->wakeup.gpe_number,
50 ACPI_GPE_ENABLE);
51 }
52}
53
54
55
56
57
58void acpi_disable_wakeup_devices(u8 sleep_state)
59{
60 struct list_head *node, *next;
61
62 list_for_each_safe(node, next, &acpi_wakeup_device_list) {
63 struct acpi_device *dev =
64 container_of(node, struct acpi_device, wakeup_list);
65
66 if (!dev->wakeup.flags.valid
67 || sleep_state > (u32) dev->wakeup.sleep_state
68 || !(device_may_wakeup(&dev->dev)
69 || dev->wakeup.prepare_count))
70 continue;
71
72 acpi_set_gpe_wake_mask(dev->wakeup.gpe_device, dev->wakeup.gpe_number,
73 ACPI_GPE_DISABLE);
74
75 if (device_may_wakeup(&dev->dev))
76 acpi_disable_wakeup_device_power(dev);
77 }
78}
79
80int __init acpi_wakeup_device_init(void)
81{
82 struct list_head *node, *next;
83
84 mutex_lock(&acpi_device_lock);
85 list_for_each_safe(node, next, &acpi_wakeup_device_list) {
86 struct acpi_device *dev = container_of(node,
87 struct acpi_device,
88 wakeup_list);
89 if (device_can_wakeup(&dev->dev)) {
90
91 acpi_enable_gpe(dev->wakeup.gpe_device,
92 dev->wakeup.gpe_number);
93 device_set_wakeup_enable(&dev->dev, true);
94 }
95 }
96 mutex_unlock(&acpi_device_lock);
97 return 0;
98}
99