wakeup.c 3.2 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 25 26 27 28
 * acpi_enable_wakeup_device_prep - Prepare wake-up devices.
 * @sleep_state: ACPI system sleep state.
 *
 * Enable all wake-up devices' power, unless the requested system sleep state is
 * too deep.
L
Linus Torvalds 已提交
29
 */
L
Len Brown 已提交
30
void acpi_enable_wakeup_device_prep(u8 sleep_state)
L
Linus Torvalds 已提交
31
{
L
Len Brown 已提交
32
	struct list_head *node, *next;
L
Linus Torvalds 已提交
33 34

	list_for_each_safe(node, next, &acpi_wakeup_device_list) {
L
Len Brown 已提交
35 36 37 38
		struct acpi_device *dev = container_of(node,
						       struct acpi_device,
						       wakeup_list);

39 40
		if (!dev->wakeup.flags.valid || !dev->wakeup.state.enabled
		    || (sleep_state > (u32) dev->wakeup.sleep_state))
L
Linus Torvalds 已提交
41 42
			continue;

43
		acpi_enable_wakeup_device_power(dev, sleep_state);
L
Linus Torvalds 已提交
44 45 46 47
	}
}

/**
48 49 50 51 52 53
 * acpi_enable_wakeup_device - Enable wake-up device GPEs.
 * @sleep_state: ACPI system sleep state.
 *
 * Enable all wake-up devices' GPEs, with the assumption that
 * acpi_disable_all_gpes() was executed before, so we don't need to disable any
 * GPEs here.
L
Linus Torvalds 已提交
54
 */
L
Len Brown 已提交
55
void acpi_enable_wakeup_device(u8 sleep_state)
L
Linus Torvalds 已提交
56
{
L
Len Brown 已提交
57
	struct list_head *node, *next;
L
Linus Torvalds 已提交
58 59 60 61 62 63

	/* 
	 * Caution: this routine must be invoked when interrupt is disabled 
	 * Refer ACPI2.0: P212
	 */
	list_for_each_safe(node, next, &acpi_wakeup_device_list) {
64 65
		struct acpi_device *dev =
			container_of(node, struct acpi_device, wakeup_list);
66

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

		/* The wake-up power should have been enabled already. */
72 73
		acpi_enable_gpe(dev->wakeup.gpe_device, dev->wakeup.gpe_number,
				ACPI_GPE_TYPE_WAKE);
L
Linus Torvalds 已提交
74 75 76 77
	}
}

/**
78 79 80 81 82
 * acpi_disable_wakeup_device - Disable devices' wakeup capability.
 * @sleep_state: ACPI system sleep state.
 *
 * This function only affects devices with wakeup.state.enabled set, which means
 * that it reverses the changes made by acpi_enable_wakeup_device_prep().
L
Linus Torvalds 已提交
83
 */
L
Len Brown 已提交
84
void acpi_disable_wakeup_device(u8 sleep_state)
L
Linus Torvalds 已提交
85
{
L
Len Brown 已提交
86
	struct list_head *node, *next;
L
Linus Torvalds 已提交
87 88

	list_for_each_safe(node, next, &acpi_wakeup_device_list) {
89 90
		struct acpi_device *dev =
			container_of(node, struct acpi_device, wakeup_list);
L
Linus Torvalds 已提交
91

92 93
		if (!dev->wakeup.flags.valid || !dev->wakeup.state.enabled
		    || (sleep_state > (u32) dev->wakeup.sleep_state))
L
Linus Torvalds 已提交
94 95
			continue;

96 97
		acpi_disable_gpe(dev->wakeup.gpe_device, dev->wakeup.gpe_number,
				ACPI_GPE_TYPE_WAKE);
L
Linus Torvalds 已提交
98 99 100 101
		acpi_disable_wakeup_device_power(dev);
	}
}

102
int __init acpi_wakeup_device_init(void)
L
Linus Torvalds 已提交
103
{
L
Len Brown 已提交
104
	struct list_head *node, *next;
L
Linus Torvalds 已提交
105

106
	mutex_lock(&acpi_device_lock);
L
Linus Torvalds 已提交
107
	list_for_each_safe(node, next, &acpi_wakeup_device_list) {
L
Len Brown 已提交
108 109 110
		struct acpi_device *dev = container_of(node,
						       struct acpi_device,
						       wakeup_list);
111 112
		if (dev->wakeup.flags.always_enabled)
			dev->wakeup.state.enabled = 1;
L
Linus Torvalds 已提交
113
	}
114
	mutex_unlock(&acpi_device_lock);
L
Linus Torvalds 已提交
115 116
	return 0;
}