wakeup.c 3.3 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 68
		if (!dev->wakeup.flags.valid)
			continue;
69

70
		if ((!dev->wakeup.state.enabled && !dev->wakeup.prepare_count)
71
		    || sleep_state > (u32) dev->wakeup.sleep_state)
L
Linus Torvalds 已提交
72
			continue;
73 74 75 76

		/* The wake-up power should have been enabled already. */
		acpi_set_gpe(dev->wakeup.gpe_device, dev->wakeup.gpe_number,
				ACPI_GPE_ENABLE);
L
Linus Torvalds 已提交
77 78 79 80
	}
}

/**
81 82 83 84 85
 * 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 已提交
86
 */
L
Len Brown 已提交
87
void acpi_disable_wakeup_device(u8 sleep_state)
L
Linus Torvalds 已提交
88
{
L
Len Brown 已提交
89
	struct list_head *node, *next;
L
Linus Torvalds 已提交
90 91

	list_for_each_safe(node, next, &acpi_wakeup_device_list) {
92 93
		struct acpi_device *dev =
			container_of(node, struct acpi_device, wakeup_list);
L
Linus Torvalds 已提交
94

95 96
		if (!dev->wakeup.flags.valid || !dev->wakeup.state.enabled
		    || (sleep_state > (u32) dev->wakeup.sleep_state))
L
Linus Torvalds 已提交
97 98 99 100 101 102
			continue;

		acpi_disable_wakeup_device_power(dev);
	}
}

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

107
	mutex_lock(&acpi_device_lock);
L
Linus Torvalds 已提交
108
	list_for_each_safe(node, next, &acpi_wakeup_device_list) {
L
Len Brown 已提交
109 110 111
		struct acpi_device *dev = container_of(node,
						       struct acpi_device,
						       wakeup_list);
L
Linus Torvalds 已提交
112
		/* In case user doesn't load button driver */
113 114
		if (!dev->wakeup.flags.always_enabled ||
		    dev->wakeup.state.enabled)
115
			continue;
116 117
 		acpi_enable_gpe(dev->wakeup.gpe_device, dev->wakeup.gpe_number,
 				ACPI_GPE_TYPE_WAKE);
118
		dev->wakeup.state.enabled = 1;
L
Linus Torvalds 已提交
119
	}
120
	mutex_unlock(&acpi_device_lock);
L
Linus Torvalds 已提交
121 122
	return 0;
}