wakeup.c 2.5 KB
Newer Older
L
Linus Torvalds 已提交
1 2 3 4 5 6 7 8 9 10
/*
 * wakeup.c - support wakeup devices
 * Copyright (C) 2004 Li Shaohua <shaohua.li@intel.com>
 */

#include <linux/init.h>
#include <linux/acpi.h>
#include <acpi/acpi_drivers.h>
#include <linux/kernel.h>
#include <linux/types.h>
11 12

#include "internal.h"
L
Linus Torvalds 已提交
13 14
#include "sleep.h"

15 16 17 18 19
/*
 * We didn't lock acpi_device_lock in the file, because it invokes oops in
 * suspend/resume and isn't really required as this is called in S-state. At
 * that time, there is no device hotplug
 **/
L
Linus Torvalds 已提交
20
#define _COMPONENT		ACPI_SYSTEM_COMPONENT
L
Len Brown 已提交
21
ACPI_MODULE_NAME("wakeup_devices")
L
Linus Torvalds 已提交
22 23

/**
24
 * acpi_enable_wakeup_devices - Enable wake-up device GPEs.
25 26
 * @sleep_state: ACPI system sleep state.
 *
27 28 29
 * Enable wakeup device power of devices with the state.enable flag set and set
 * the wakeup enable mask bits in the GPE registers that correspond to wakeup
 * devices.
L
Linus Torvalds 已提交
30
 */
31
void acpi_enable_wakeup_devices(u8 sleep_state)
L
Linus Torvalds 已提交
32
{
L
Len Brown 已提交
33
	struct list_head *node, *next;
L
Linus Torvalds 已提交
34 35

	list_for_each_safe(node, next, &acpi_wakeup_device_list) {
36 37
		struct acpi_device *dev =
			container_of(node, struct acpi_device, wakeup_list);
38

39
		if (!dev->wakeup.flags.valid
40 41 42
		    || sleep_state > (u32) dev->wakeup.sleep_state
		    || !(device_may_wakeup(&dev->dev)
		        || dev->wakeup.prepare_count))
L
Linus Torvalds 已提交
43
			continue;
44

45
		if (device_may_wakeup(&dev->dev))
46 47
			acpi_enable_wakeup_device_power(dev, sleep_state);

48
		/* The wake-up power should have been enabled already. */
49
		acpi_set_gpe_wake_mask(dev->wakeup.gpe_device, dev->wakeup.gpe_number,
50
				ACPI_GPE_ENABLE);
L
Linus Torvalds 已提交
51 52 53 54
	}
}

/**
55
 * acpi_disable_wakeup_devices - Disable devices' wakeup capability.
56
 * @sleep_state: ACPI system sleep state.
L
Linus Torvalds 已提交
57
 */
58
void acpi_disable_wakeup_devices(u8 sleep_state)
L
Linus Torvalds 已提交
59
{
L
Len Brown 已提交
60
	struct list_head *node, *next;
L
Linus Torvalds 已提交
61 62

	list_for_each_safe(node, next, &acpi_wakeup_device_list) {
63 64
		struct acpi_device *dev =
			container_of(node, struct acpi_device, wakeup_list);
L
Linus Torvalds 已提交
65

66
		if (!dev->wakeup.flags.valid
67 68 69
		    || sleep_state > (u32) dev->wakeup.sleep_state
		    || !(device_may_wakeup(&dev->dev)
		        || dev->wakeup.prepare_count))
L
Linus Torvalds 已提交
70 71
			continue;

72
		acpi_set_gpe_wake_mask(dev->wakeup.gpe_device, dev->wakeup.gpe_number,
73 74
				ACPI_GPE_DISABLE);

75
		if (device_may_wakeup(&dev->dev))
76
			acpi_disable_wakeup_device_power(dev);
L
Linus Torvalds 已提交
77 78 79
	}
}

80
int __init acpi_wakeup_device_init(void)
L
Linus Torvalds 已提交
81
{
L
Len Brown 已提交
82
	struct list_head *node, *next;
L
Linus Torvalds 已提交
83

84
	mutex_lock(&acpi_device_lock);
L
Linus Torvalds 已提交
85
	list_for_each_safe(node, next, &acpi_wakeup_device_list) {
L
Len Brown 已提交
86 87 88
		struct acpi_device *dev = container_of(node,
						       struct acpi_device,
						       wakeup_list);
89 90
		if (device_can_wakeup(&dev->dev))
			device_set_wakeup_enable(&dev->dev, true);
L
Linus Torvalds 已提交
91
	}
92
	mutex_unlock(&acpi_device_lock);
L
Linus Torvalds 已提交
93 94
	return 0;
}