2005-04-17 00:20:36 +02:00
|
|
|
/*
|
|
|
|
* resume.c - Functions for waking devices up.
|
|
|
|
*
|
|
|
|
* Copyright (c) 2003 Patrick Mochel
|
|
|
|
* Copyright (c) 2003 Open Source Development Labs
|
|
|
|
*
|
|
|
|
* This file is released under the GPLv2
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <linux/device.h>
|
2006-06-24 23:32:18 +02:00
|
|
|
#include <linux/resume-trace.h>
|
2006-01-19 17:30:17 +01:00
|
|
|
#include "../base.h"
|
2005-04-17 00:20:36 +02:00
|
|
|
#include "power.h"
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* resume_device - Restore state for one device.
|
|
|
|
* @dev: Device.
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
|
|
|
int resume_device(struct device * dev)
|
|
|
|
{
|
2005-03-21 19:41:04 +01:00
|
|
|
int error = 0;
|
|
|
|
|
2006-06-24 23:32:18 +02:00
|
|
|
TRACE_DEVICE(dev);
|
|
|
|
TRACE_RESUME(0);
|
2005-03-21 19:41:04 +01:00
|
|
|
down(&dev->sem);
|
2005-05-09 17:07:00 +02:00
|
|
|
if (dev->power.pm_parent
|
2005-09-04 00:56:57 +02:00
|
|
|
&& dev->power.pm_parent->power.power_state.event) {
|
2005-05-09 17:07:00 +02:00
|
|
|
dev_err(dev, "PM: resume from %d, parent %s still %d\n",
|
2005-09-04 00:56:57 +02:00
|
|
|
dev->power.power_state.event,
|
2005-05-09 17:07:00 +02:00
|
|
|
dev->power.pm_parent->bus_id,
|
2005-09-04 00:56:57 +02:00
|
|
|
dev->power.pm_parent->power.power_state.event);
|
2005-05-09 17:07:00 +02:00
|
|
|
}
|
|
|
|
if (dev->bus && dev->bus->resume) {
|
|
|
|
dev_dbg(dev,"resuming\n");
|
2005-03-21 19:41:04 +01:00
|
|
|
error = dev->bus->resume(dev);
|
2005-05-09 17:07:00 +02:00
|
|
|
}
|
2006-06-24 23:50:29 +02:00
|
|
|
if (dev->class && dev->class->resume) {
|
|
|
|
dev_dbg(dev,"class resume\n");
|
|
|
|
error = dev->class->resume(dev);
|
|
|
|
}
|
2005-03-21 19:41:04 +01:00
|
|
|
up(&dev->sem);
|
2006-06-24 23:32:18 +02:00
|
|
|
TRACE_RESUME(error);
|
2005-03-21 19:41:04 +01:00
|
|
|
return error;
|
2005-04-17 00:20:36 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2006-06-24 23:50:29 +02:00
|
|
|
static int resume_device_early(struct device * dev)
|
|
|
|
{
|
|
|
|
int error = 0;
|
2005-04-17 00:20:36 +02:00
|
|
|
|
2006-06-24 23:50:29 +02:00
|
|
|
TRACE_DEVICE(dev);
|
|
|
|
TRACE_RESUME(0);
|
|
|
|
if (dev->bus && dev->bus->resume_early) {
|
|
|
|
dev_dbg(dev,"EARLY resume\n");
|
|
|
|
error = dev->bus->resume_early(dev);
|
|
|
|
}
|
|
|
|
TRACE_RESUME(error);
|
|
|
|
return error;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Resume the devices that have either not gone through
|
|
|
|
* the late suspend, or that did go through it but also
|
|
|
|
* went through the early resume
|
|
|
|
*/
|
2005-04-17 00:20:36 +02:00
|
|
|
void dpm_resume(void)
|
|
|
|
{
|
|
|
|
down(&dpm_list_sem);
|
|
|
|
while(!list_empty(&dpm_off)) {
|
|
|
|
struct list_head * entry = dpm_off.next;
|
|
|
|
struct device * dev = to_device(entry);
|
|
|
|
|
|
|
|
get_device(dev);
|
2006-06-26 09:24:40 +02:00
|
|
|
list_move_tail(entry, &dpm_active);
|
2005-04-17 00:20:36 +02:00
|
|
|
|
|
|
|
up(&dpm_list_sem);
|
2005-09-04 00:56:57 +02:00
|
|
|
if (!dev->power.prev_state.event)
|
2005-04-17 00:20:36 +02:00
|
|
|
resume_device(dev);
|
|
|
|
down(&dpm_list_sem);
|
|
|
|
put_device(dev);
|
|
|
|
}
|
|
|
|
up(&dpm_list_sem);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* device_resume - Restore state of each device in system.
|
|
|
|
*
|
|
|
|
* Walk the dpm_off list, remove each entry, resume the device,
|
|
|
|
* then add it to the dpm_active list.
|
|
|
|
*/
|
|
|
|
|
|
|
|
void device_resume(void)
|
|
|
|
{
|
2006-09-01 07:02:11 +02:00
|
|
|
might_sleep();
|
2005-04-17 00:20:36 +02:00
|
|
|
down(&dpm_sem);
|
|
|
|
dpm_resume();
|
|
|
|
up(&dpm_sem);
|
|
|
|
}
|
|
|
|
|
|
|
|
EXPORT_SYMBOL_GPL(device_resume);
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
2006-07-15 06:31:54 +02:00
|
|
|
* dpm_power_up - Power on some devices.
|
2005-04-17 00:20:36 +02:00
|
|
|
*
|
|
|
|
* Walk the dpm_off_irq list and power each device up. This
|
|
|
|
* is used for devices that required they be powered down with
|
2006-07-15 06:31:54 +02:00
|
|
|
* interrupts disabled. As devices are powered on, they are moved
|
|
|
|
* to the dpm_active list.
|
2005-04-17 00:20:36 +02:00
|
|
|
*
|
|
|
|
* Interrupts must be disabled when calling this.
|
|
|
|
*/
|
|
|
|
|
|
|
|
void dpm_power_up(void)
|
|
|
|
{
|
|
|
|
while(!list_empty(&dpm_off_irq)) {
|
|
|
|
struct list_head * entry = dpm_off_irq.next;
|
|
|
|
struct device * dev = to_device(entry);
|
|
|
|
|
2006-06-24 23:50:29 +02:00
|
|
|
list_move_tail(entry, &dpm_off);
|
|
|
|
resume_device_early(dev);
|
2005-04-17 00:20:36 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
2006-07-15 06:31:54 +02:00
|
|
|
* device_power_up - Turn on all devices that need special attention.
|
2005-04-17 00:20:36 +02:00
|
|
|
*
|
|
|
|
* Power on system devices then devices that required we shut them down
|
|
|
|
* with interrupts disabled.
|
|
|
|
* Called with interrupts disabled.
|
|
|
|
*/
|
|
|
|
|
|
|
|
void device_power_up(void)
|
|
|
|
{
|
|
|
|
sysdev_resume();
|
|
|
|
dpm_power_up();
|
|
|
|
}
|
|
|
|
|
|
|
|
EXPORT_SYMBOL_GPL(device_power_up);
|
|
|
|
|
|
|
|
|