Commit 78fbd8ba authored by Len Brown's avatar Len Brown Committed by Len Brown

[ACPI] Create /proc/acpi/wakeup to allow enabling

the optional wakeup event sources. (David Shaohua Li)
http://bugzilla.kernel.org/show_bug.cgi?id=1415
parent e227e152
obj-y := poweroff.o
obj-$(CONFIG_ACPI_SLEEP) += main.o
obj-$(CONFIG_ACPI_SLEEP) += main.o wakeup.o
obj-$(CONFIG_ACPI_SLEEP_PROC_FS) += proc.o
EXTRA_CFLAGS += $(ACPI_CFLAGS)
......@@ -56,6 +56,7 @@ static int acpi_pm_prepare(u32 pm_state)
(acpi_physical_address) acpi_wakeup_address);
}
ACPI_FLUSH_CPU_CACHE();
acpi_enable_wakeup_device_prep(acpi_state);
acpi_enter_sleep_state_prep(acpi_state);
return 0;
}
......@@ -87,6 +88,7 @@ static int acpi_pm_enter(u32 pm_state)
local_irq_save(flags);
acpi_enable_wakeup_device(acpi_state);
switch (pm_state)
{
case PM_SUSPEND_STANDBY:
......@@ -136,6 +138,7 @@ static int acpi_pm_finish(u32 pm_state)
u32 acpi_state = acpi_suspend_states[pm_state];
acpi_leave_sleep_state(acpi_state);
acpi_disable_wakeup_device(acpi_state);
/* reset firmware waking vector */
acpi_set_firmware_waking_vector((acpi_physical_address) 0);
......
......@@ -15,6 +15,7 @@
#define ACPI_SYSTEM_FILE_SLEEP "sleep"
#define ACPI_SYSTEM_FILE_ALARM "alarm"
#define ACPI_SYSTEM_FILE_WAKEUP_DEVICE "wakeup"
#define _COMPONENT ACPI_SYSTEM_COMPONENT
ACPI_MODULE_NAME ("sleep")
......@@ -352,6 +353,84 @@ acpi_system_write_alarm (
return_VALUE(result ? result : count);
}
extern struct list_head acpi_wakeup_device_list;
extern spinlock_t acpi_device_lock;
static int
acpi_system_wakeup_device_seq_show(struct seq_file *seq, void *offset)
{
struct list_head * node, * next;
seq_printf(seq, "Device Sleep state Status\n");
spin_lock(&acpi_device_lock);
list_for_each_safe(node, next, &acpi_wakeup_device_list) {
struct acpi_device * dev = container_of(node, struct acpi_device, wakeup_list);
if (!dev->wakeup.flags.valid)
continue;
spin_unlock(&acpi_device_lock);
if (dev->wakeup.flags.run_wake)
seq_printf(seq, "%4s %4d %8s\n",
dev->pnp.bus_id, (u32) dev->wakeup.sleep_state,
dev->wakeup.state.enabled ? "*enabled" : "*disabled");
else
seq_printf(seq, "%4s %4d %8s\n",
dev->pnp.bus_id, (u32) dev->wakeup.sleep_state,
dev->wakeup.state.enabled ? "enabled" : "disabled");
spin_lock(&acpi_device_lock);
}
spin_unlock(&acpi_device_lock);
return 0;
}
static int
acpi_system_write_wakeup_device (
struct file *file,
const char *buffer,
size_t count,
loff_t *ppos)
{
struct list_head * node, * next;
char strbuf[5];
char str[5] = "";
int len = count;
if (len > 4) len = 4;
if (copy_from_user(strbuf, buffer, len))
return -EFAULT;
strbuf[len] = '\0';
sscanf(strbuf, "%s", str);
spin_lock(&acpi_device_lock);
list_for_each_safe(node, next, &acpi_wakeup_device_list) {
struct acpi_device * dev = container_of(node, struct acpi_device, wakeup_list);
if (!dev->wakeup.flags.valid)
continue;
if (!strncmp(dev->pnp.bus_id, str, 4)) {
dev->wakeup.state.enabled = dev->wakeup.state.enabled ? 0:1;
break;
}
}
spin_unlock(&acpi_device_lock);
return count;
}
static int
acpi_system_wakeup_device_open_fs(struct inode *inode, struct file *file)
{
return single_open(file, acpi_system_wakeup_device_seq_show, PDE(inode)->data);
}
static struct file_operations acpi_system_wakeup_device_fops = {
.open = acpi_system_wakeup_device_open_fs,
.read = seq_read,
.write = acpi_system_write_wakeup_device,
.llseek = seq_lseek,
.release = single_release,
};
static struct file_operations acpi_system_sleep_fops = {
.open = acpi_system_sleep_open_fs,
......@@ -388,6 +467,13 @@ static int acpi_sleep_proc_init(void)
S_IFREG|S_IRUGO|S_IWUSR, acpi_root_dir);
if (entry)
entry->proc_fops = &acpi_system_alarm_fops;
/* 'wakeup device' [R/W]*/
entry = create_proc_entry(ACPI_SYSTEM_FILE_WAKEUP_DEVICE,
S_IFREG|S_IRUGO|S_IWUSR, acpi_root_dir);
if (entry)
entry->proc_fops = &acpi_system_wakeup_device_fops;
return 0;
}
......
......@@ -2,3 +2,6 @@
extern u8 sleep_states[];
extern int acpi_suspend (u32 state);
extern void acpi_enable_wakeup_device_prep(u8 sleep_state);
extern void acpi_enable_wakeup_device(u8 sleep_state);
extern void acpi_disable_wakeup_device(u8 sleep_state);
/*
* wakeup.c - support wakeup devices
*/
#include <linux/init.h>
#include <linux/acpi.h>
#include <acpi/acpi_drivers.h>
#include <linux/kernel.h>
#include <linux/types.h>
#include <acpi/acevents.h>
#include "sleep.h"
#define _COMPONENT ACPI_SYSTEM_COMPONENT
ACPI_MODULE_NAME ("wakeup_devices")
/**
* acpi_enable_wakeup_device_prep - prepare wakeup devices
* @sleep_state: ACPI state
* Enable all wakup devices power if the devices' wakeup level
* is higher than requested sleep level
*/
extern struct list_head acpi_wakeup_device_list;
extern spinlock_t acpi_device_lock;
void
acpi_enable_wakeup_device_prep(
u8 sleep_state)
{
struct list_head * node, * next;
ACPI_FUNCTION_TRACE("acpi_enable_wakeup_device_prep");
spin_lock(&acpi_device_lock);
list_for_each_safe(node, next, &acpi_wakeup_device_list) {
struct acpi_device * dev = container_of(node,
struct acpi_device, wakeup_list);
if (!dev->wakeup.flags.valid ||
!dev->wakeup.state.enabled ||
(sleep_state > (u32) dev->wakeup.sleep_state))
continue;
spin_unlock(&acpi_device_lock);
acpi_enable_wakeup_device_power(dev);
spin_lock(&acpi_device_lock);
}
spin_unlock(&acpi_device_lock);
}
/**
* acpi_enable_wakeup_device - enable wakeup devices
* @sleep_state: ACPI state
* Enable all wakup devices's GPE
*/
void
acpi_enable_wakeup_device(
u8 sleep_state)
{
struct list_head * node, * next;
/*
* Caution: this routine must be invoked when interrupt is disabled
* Refer ACPI2.0: P212
*/
ACPI_FUNCTION_TRACE("acpi_enable_wakeup_device");
spin_lock(&acpi_device_lock);
list_for_each_safe(node, next, &acpi_wakeup_device_list) {
struct acpi_device * dev = container_of(node,
struct acpi_device, wakeup_list);
if (!dev->wakeup.flags.valid ||
!dev->wakeup.state.enabled ||
(sleep_state > (u32) dev->wakeup.sleep_state))
continue;
spin_unlock(&acpi_device_lock);
acpi_enable_gpe(dev->wakeup.gpe_device,
dev->wakeup.gpe_number, ACPI_ISR);
dev->wakeup.state.active = 1;
spin_lock(&acpi_device_lock);
}
spin_unlock(&acpi_device_lock);
}
/**
* acpi_disable_wakeup_device - disable devices' wakeup capability
* @sleep_state: ACPI state
* Disable all wakup devices's GPE and wakeup capability
*/
void
acpi_disable_wakeup_device (
u8 sleep_state)
{
struct list_head * node, * next;
ACPI_FUNCTION_TRACE("acpi_disable_wakeup_device");
spin_lock(&acpi_device_lock);
list_for_each_safe(node, next, &acpi_wakeup_device_list) {
struct acpi_device * dev = container_of(node,
struct acpi_device, wakeup_list);
if (!dev->wakeup.flags.valid ||
!dev->wakeup.state.active ||
(sleep_state > (u32) dev->wakeup.sleep_state))
continue;
spin_unlock(&acpi_device_lock);
acpi_disable_wakeup_device_power(dev);
acpi_disable_gpe(dev->wakeup.gpe_device,
dev->wakeup.gpe_number, ACPI_NOT_ISR);
acpi_clear_gpe(dev->wakeup.gpe_device,
dev->wakeup.gpe_number, ACPI_NOT_ISR);
dev->wakeup.state.active = 0;
spin_lock(&acpi_device_lock);
}
spin_unlock(&acpi_device_lock);
}
static int __init acpi_wakeup_device_init(void)
{
struct list_head * node, * next;
printk("ACPI wakeup devices: \n");
spin_lock(&acpi_device_lock);
list_for_each_safe(node, next, &acpi_wakeup_device_list) {
struct acpi_device * dev = container_of(node,
struct acpi_device, wakeup_list);
/* Enable wakeup GPE for Lid/sleep button by default */
if (dev->wakeup.flags.run_wake) {
spin_unlock(&acpi_device_lock);
acpi_set_gpe_type(dev->wakeup.gpe_device,
dev->wakeup.gpe_number, ACPI_GPE_TYPE_WAKE_RUN);
dev->wakeup.state.enabled = 1;
spin_lock(&acpi_device_lock);
}
printk("%4s ", dev->pnp.bus_id);
}
spin_unlock(&acpi_device_lock);
printk("\n");
return 0;
}
late_initcall(acpi_wakeup_device_init);
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment