Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1 | /* |
| 2 | * drivers/base/power/runtime.c - Handling dynamic device power management. |
| 3 | * |
| 4 | * Copyright (c) 2003 Patrick Mochel |
| 5 | * Copyright (c) 2003 Open Source Development Lab |
| 6 | * |
| 7 | */ |
| 8 | |
| 9 | #include <linux/device.h> |
| 10 | #include "power.h" |
| 11 | |
| 12 | |
| 13 | static void runtime_resume(struct device * dev) |
| 14 | { |
| 15 | dev_dbg(dev, "resuming\n"); |
Pavel Machek | ca078ba | 2005-09-03 15:56:57 -0700 | [diff] [blame] | 16 | if (!dev->power.power_state.event) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 17 | return; |
| 18 | if (!resume_device(dev)) |
Pavel Machek | ca078ba | 2005-09-03 15:56:57 -0700 | [diff] [blame] | 19 | dev->power.power_state = PMSG_ON; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 20 | } |
| 21 | |
| 22 | |
| 23 | /** |
| 24 | * dpm_runtime_resume - Power one device back on. |
| 25 | * @dev: Device. |
| 26 | * |
| 27 | * Bring one device back to the on state by first powering it |
| 28 | * on, then restoring state. We only operate on devices that aren't |
| 29 | * already on. |
| 30 | * FIXME: We need to handle devices that are in an unknown state. |
| 31 | */ |
| 32 | |
| 33 | void dpm_runtime_resume(struct device * dev) |
| 34 | { |
| 35 | down(&dpm_sem); |
| 36 | runtime_resume(dev); |
| 37 | up(&dpm_sem); |
| 38 | } |
David Brownell | 979d519 | 2005-09-22 22:32:24 -0700 | [diff] [blame] | 39 | EXPORT_SYMBOL(dpm_runtime_resume); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 40 | |
| 41 | |
| 42 | /** |
| 43 | * dpm_runtime_suspend - Put one device in low-power state. |
| 44 | * @dev: Device. |
| 45 | * @state: State to enter. |
| 46 | */ |
| 47 | |
| 48 | int dpm_runtime_suspend(struct device * dev, pm_message_t state) |
| 49 | { |
| 50 | int error = 0; |
| 51 | |
| 52 | down(&dpm_sem); |
Pavel Machek | ca078ba | 2005-09-03 15:56:57 -0700 | [diff] [blame] | 53 | if (dev->power.power_state.event == state.event) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 54 | goto Done; |
| 55 | |
Pavel Machek | ca078ba | 2005-09-03 15:56:57 -0700 | [diff] [blame] | 56 | if (dev->power.power_state.event) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 57 | runtime_resume(dev); |
| 58 | |
| 59 | if (!(error = suspend_device(dev, state))) |
| 60 | dev->power.power_state = state; |
| 61 | Done: |
| 62 | up(&dpm_sem); |
| 63 | return error; |
| 64 | } |
Dominik Brodowski | 8e9e793 | 2006-01-06 00:02:03 +0100 | [diff] [blame] | 65 | EXPORT_SYMBOL(dpm_runtime_suspend); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 66 | |
| 67 | |
Adrian Bunk | 1f1bf13 | 2005-12-12 01:31:03 -0800 | [diff] [blame] | 68 | #if 0 |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 69 | /** |
| 70 | * dpm_set_power_state - Update power_state field. |
| 71 | * @dev: Device. |
| 72 | * @state: Power state device is in. |
| 73 | * |
| 74 | * This is an update mechanism for drivers to notify the core |
| 75 | * what power state a device is in. Device probing code may not |
| 76 | * always be able to tell, but we need accurate information to |
| 77 | * work reliably. |
| 78 | */ |
| 79 | void dpm_set_power_state(struct device * dev, pm_message_t state) |
| 80 | { |
| 81 | down(&dpm_sem); |
| 82 | dev->power.power_state = state; |
| 83 | up(&dpm_sem); |
| 84 | } |
Adrian Bunk | 1f1bf13 | 2005-12-12 01:31:03 -0800 | [diff] [blame] | 85 | #endif /* 0 */ |