diff options
| author | Patrick Mochel <mochel@osdl.org> | 2003-08-11 19:25:20 -0700 |
|---|---|---|
| committer | Patrick Mochel <mochel@osdl.org> | 2003-08-11 19:25:20 -0700 |
| commit | 86ccb7959cf7fde613da85a6b3484a71cd24fbf9 (patch) | |
| tree | c54ad5fb7c6a5e7d8acc242a37df02baea027035 /drivers/base/power/runtime.c | |
| parent | 98247e0a408b4b551441bee5068eaa59ee646a11 (diff) | |
[power] Add hooks for runtime device power control.
dpm_runtime_{suspend,resume} control the power state of a single device
while the system is running.
dpm_runtime_suspend() will save state of the device, then attempt to power
it down. This happens with interrupts enabled, so if the device does not
support that, the device's state is restored, and we continue on our merry
way.
dpm_runtime_resume() powers the device back on, then restores state of the
device.
dpm_set_power_state() simply notifies the core of the power state the
device is in. Drivers can use this, since they are the only ones that can
really tell.
Diffstat (limited to 'drivers/base/power/runtime.c')
| -rw-r--r-- | drivers/base/power/runtime.c | 89 |
1 files changed, 89 insertions, 0 deletions
diff --git a/drivers/base/power/runtime.c b/drivers/base/power/runtime.c new file mode 100644 index 000000000000..4a4ac9f7764d --- /dev/null +++ b/drivers/base/power/runtime.c @@ -0,0 +1,89 @@ +/* + * drivers/base/power/runtime.c - Handling dynamic device power management. + * + * Copyright (c) 2003 Patrick Mochel + * Copyright (c) 2003 Open Source Development Lab + * + */ + +#include <linux/device.h> +#include "power.h" + + +static void runtime_resume(struct device * dev) +{ + if (!dev->power.power_state) + return; + + power_up_device(dev); + resume_device(dev); +} + + +/** + * dpm_runtime_resume - Power one device back on. + * @dev: Device. + * + * Bring one device back to the on state by first powering it + * on, then restoring state. We only operate on devices that aren't + * already on. + * FIXME: We need to handle devices that are in an unknown state. + */ + +void dpm_runtime_resume(struct device * dev) +{ + down(&dpm_sem); + runtime_resume(dev); + up(&dpm_sem); +} + + +/** + * dpm_runtime_suspend - Put one device in low-power state. + * @dev: Device. + * @state: State to enter. + */ + +int dpm_runtime_suspend(struct device * dev, u32 state) +{ + int error = 0; + + down(&dpm_sem); + if (dev->power.power_state == state) + goto Done; + + if (dev->power.power_state) + dpm_runtime_resume(dev); + + error = suspend_device(dev,state); + if (!error) { + error = power_down_device(dev,state); + if (error) + goto ErrResume; + dev->power.power_state = state; + } + Done: + up(&dpm_sem); + return error; + ErrResume: + resume_device(dev); + goto Done; +} + + +/** + * dpm_set_power_state - Update power_state field. + * @dev: Device. + * @state: Power state device is in. + * + * This is an update mechanism for drivers to notify the core + * what power state a device is in. Device probing code may not + * always be able to tell, but we need accurate information to + * work reliably. + */ +void dpm_set_power_state(struct device * dev, u32 state) +{ + down(&dpm_sem); + dev->power.power_state = state; + up(&dpm_sem); +} |
