Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1 | /* |
| 2 | * drivers/base/power/main.c - Where the driver meets power management. |
| 3 | * |
| 4 | * Copyright (c) 2003 Patrick Mochel |
| 5 | * Copyright (c) 2003 Open Source Development Lab |
| 6 | * |
| 7 | * This file is released under the GPLv2 |
| 8 | * |
| 9 | * |
| 10 | * The driver model core calls device_pm_add() when a device is registered. |
Uwe Kleine-König | b595076 | 2010-11-01 15:38:34 -0400 | [diff] [blame] | 11 | * This will initialize the embedded device_pm_info object in the device |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 12 | * and add it to the list of power-controlled devices. sysfs entries for |
| 13 | * controlling device power management will also be added. |
| 14 | * |
Rafael J. Wysocki | 1eede07 | 2008-05-20 23:00:01 +0200 | [diff] [blame] | 15 | * A separate list is used for keeping track of power info, because the power |
| 16 | * domain dependencies may differ from the ancestral dependencies that the |
| 17 | * subsystem list maintains. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 18 | */ |
| 19 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 20 | #include <linux/device.h> |
Alan Stern | cd59abf | 2007-09-21 15:36:56 -0400 | [diff] [blame] | 21 | #include <linux/kallsyms.h> |
Matthias Kaehlcke | 11048dc | 2007-05-23 14:19:41 -0700 | [diff] [blame] | 22 | #include <linux/mutex.h> |
Alan Stern | cd59abf | 2007-09-21 15:36:56 -0400 | [diff] [blame] | 23 | #include <linux/pm.h> |
Rafael J. Wysocki | 5e928f7 | 2009-08-18 23:38:32 +0200 | [diff] [blame] | 24 | #include <linux/pm_runtime.h> |
Alan Stern | cd59abf | 2007-09-21 15:36:56 -0400 | [diff] [blame] | 25 | #include <linux/resume-trace.h> |
Rafael J. Wysocki | 2ed8d2b | 2009-03-16 22:34:06 +0100 | [diff] [blame] | 26 | #include <linux/interrupt.h> |
Arjan van de Ven | f251177 | 2009-12-13 20:29:01 +0100 | [diff] [blame] | 27 | #include <linux/sched.h> |
Rafael J. Wysocki | 5af84b8 | 2010-01-23 22:23:32 +0100 | [diff] [blame] | 28 | #include <linux/async.h> |
Rafael J. Wysocki | 1e75227 | 2010-12-03 22:58:05 +0100 | [diff] [blame] | 29 | #include <linux/suspend.h> |
Matthias Kaehlcke | 11048dc | 2007-05-23 14:19:41 -0700 | [diff] [blame] | 30 | |
Alan Stern | cd59abf | 2007-09-21 15:36:56 -0400 | [diff] [blame] | 31 | #include "../base.h" |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 32 | #include "power.h" |
| 33 | |
Rafael J. Wysocki | 775b64d | 2008-01-12 20:40:46 +0100 | [diff] [blame] | 34 | /* |
Rafael J. Wysocki | 1eede07 | 2008-05-20 23:00:01 +0200 | [diff] [blame] | 35 | * The entries in the dpm_list list are in a depth first order, simply |
Rafael J. Wysocki | 775b64d | 2008-01-12 20:40:46 +0100 | [diff] [blame] | 36 | * because children are guaranteed to be discovered after parents, and |
| 37 | * are inserted at the back of the list on discovery. |
| 38 | * |
Greg Kroah-Hartman | 8e9394c | 2010-02-17 10:57:05 -0800 | [diff] [blame] | 39 | * Since device_pm_add() may be called with a device lock held, |
| 40 | * we must never try to acquire a device lock while holding |
Rafael J. Wysocki | 775b64d | 2008-01-12 20:40:46 +0100 | [diff] [blame] | 41 | * dpm_list_mutex. |
| 42 | */ |
| 43 | |
Rafael J. Wysocki | 1eede07 | 2008-05-20 23:00:01 +0200 | [diff] [blame] | 44 | LIST_HEAD(dpm_list); |
Rafael J. Wysocki | 8a43a9a | 2010-12-16 00:50:30 +0100 | [diff] [blame] | 45 | LIST_HEAD(dpm_prepared_list); |
| 46 | LIST_HEAD(dpm_suspended_list); |
| 47 | LIST_HEAD(dpm_noirq_list); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 48 | |
Alan Stern | cd59abf | 2007-09-21 15:36:56 -0400 | [diff] [blame] | 49 | static DEFINE_MUTEX(dpm_list_mtx); |
Rafael J. Wysocki | 5af84b8 | 2010-01-23 22:23:32 +0100 | [diff] [blame] | 50 | static pm_message_t pm_transition; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 51 | |
Rafael J. Wysocki | 098dff7 | 2010-09-22 22:10:57 +0200 | [diff] [blame] | 52 | static int async_error; |
| 53 | |
Rafael J. Wysocki | 1eede07 | 2008-05-20 23:00:01 +0200 | [diff] [blame] | 54 | /** |
Rafael J. Wysocki | 20d652d | 2009-08-20 20:25:52 +0200 | [diff] [blame] | 55 | * device_pm_init - Initialize the PM-related part of a device object. |
Rafael J. Wysocki | 5e928f7 | 2009-08-18 23:38:32 +0200 | [diff] [blame] | 56 | * @dev: Device object being initialized. |
| 57 | */ |
| 58 | void device_pm_init(struct device *dev) |
| 59 | { |
Alan Stern | f76b168 | 2011-06-18 20:22:23 +0200 | [diff] [blame] | 60 | dev->power.is_prepared = false; |
Alan Stern | 6d0e0e8 | 2011-06-18 22:42:09 +0200 | [diff] [blame] | 61 | dev->power.is_suspended = false; |
Rafael J. Wysocki | 5af84b8 | 2010-01-23 22:23:32 +0100 | [diff] [blame] | 62 | init_completion(&dev->power.completion); |
Colin Cross | 152e1d5 | 2010-09-03 01:24:07 +0200 | [diff] [blame] | 63 | complete_all(&dev->power.completion); |
Rafael J. Wysocki | 074037e | 2010-09-22 22:09:10 +0200 | [diff] [blame] | 64 | dev->power.wakeup = NULL; |
| 65 | spin_lock_init(&dev->power.lock); |
Rafael J. Wysocki | 5e928f7 | 2009-08-18 23:38:32 +0200 | [diff] [blame] | 66 | pm_runtime_init(dev); |
Rafael J. Wysocki | 22110fa | 2011-04-26 11:33:09 +0200 | [diff] [blame] | 67 | INIT_LIST_HEAD(&dev->power.entry); |
Rafael J. Wysocki | 5e928f7 | 2009-08-18 23:38:32 +0200 | [diff] [blame] | 68 | } |
| 69 | |
| 70 | /** |
Rafael J. Wysocki | 20d652d | 2009-08-20 20:25:52 +0200 | [diff] [blame] | 71 | * device_pm_lock - Lock the list of active devices used by the PM core. |
Rafael J. Wysocki | 1eede07 | 2008-05-20 23:00:01 +0200 | [diff] [blame] | 72 | */ |
| 73 | void device_pm_lock(void) |
| 74 | { |
| 75 | mutex_lock(&dpm_list_mtx); |
| 76 | } |
| 77 | |
| 78 | /** |
Rafael J. Wysocki | 20d652d | 2009-08-20 20:25:52 +0200 | [diff] [blame] | 79 | * device_pm_unlock - Unlock the list of active devices used by the PM core. |
Rafael J. Wysocki | 1eede07 | 2008-05-20 23:00:01 +0200 | [diff] [blame] | 80 | */ |
| 81 | void device_pm_unlock(void) |
| 82 | { |
| 83 | mutex_unlock(&dpm_list_mtx); |
| 84 | } |
Rafael J. Wysocki | 775b64d | 2008-01-12 20:40:46 +0100 | [diff] [blame] | 85 | |
Rafael J. Wysocki | 775b64d | 2008-01-12 20:40:46 +0100 | [diff] [blame] | 86 | /** |
Rafael J. Wysocki | 20d652d | 2009-08-20 20:25:52 +0200 | [diff] [blame] | 87 | * device_pm_add - Add a device to the PM core's list of active devices. |
| 88 | * @dev: Device to add to the list. |
Rafael J. Wysocki | 775b64d | 2008-01-12 20:40:46 +0100 | [diff] [blame] | 89 | */ |
Alan Stern | 3b98aea | 2008-08-07 13:06:12 -0400 | [diff] [blame] | 90 | void device_pm_add(struct device *dev) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 91 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 92 | pr_debug("PM: Adding info for %s:%s\n", |
Rafael J. Wysocki | 5c1a07a | 2010-12-24 15:03:34 +0100 | [diff] [blame] | 93 | dev->bus ? dev->bus->name : "No Bus", dev_name(dev)); |
Matthias Kaehlcke | 11048dc | 2007-05-23 14:19:41 -0700 | [diff] [blame] | 94 | mutex_lock(&dpm_list_mtx); |
Alan Stern | f76b168 | 2011-06-18 20:22:23 +0200 | [diff] [blame] | 95 | if (dev->parent && dev->parent->power.is_prepared) |
Rafael J. Wysocki | b64959e | 2010-12-16 17:11:45 +0100 | [diff] [blame] | 96 | dev_warn(dev, "parent %s should not be sleeping\n", |
| 97 | dev_name(dev->parent)); |
Alan Stern | 3b98aea | 2008-08-07 13:06:12 -0400 | [diff] [blame] | 98 | list_add_tail(&dev->power.entry, &dpm_list); |
Matthias Kaehlcke | 11048dc | 2007-05-23 14:19:41 -0700 | [diff] [blame] | 99 | mutex_unlock(&dpm_list_mtx); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 100 | } |
| 101 | |
Rafael J. Wysocki | 775b64d | 2008-01-12 20:40:46 +0100 | [diff] [blame] | 102 | /** |
Rafael J. Wysocki | 20d652d | 2009-08-20 20:25:52 +0200 | [diff] [blame] | 103 | * device_pm_remove - Remove a device from the PM core's list of active devices. |
| 104 | * @dev: Device to be removed from the list. |
Rafael J. Wysocki | 775b64d | 2008-01-12 20:40:46 +0100 | [diff] [blame] | 105 | */ |
Rafael J. Wysocki | 9cddad7 | 2007-06-13 15:53:34 +0200 | [diff] [blame] | 106 | void device_pm_remove(struct device *dev) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 107 | { |
| 108 | pr_debug("PM: Removing info for %s:%s\n", |
Rafael J. Wysocki | 5c1a07a | 2010-12-24 15:03:34 +0100 | [diff] [blame] | 109 | dev->bus ? dev->bus->name : "No Bus", dev_name(dev)); |
Rafael J. Wysocki | 5af84b8 | 2010-01-23 22:23:32 +0100 | [diff] [blame] | 110 | complete_all(&dev->power.completion); |
Matthias Kaehlcke | 11048dc | 2007-05-23 14:19:41 -0700 | [diff] [blame] | 111 | mutex_lock(&dpm_list_mtx); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 112 | list_del_init(&dev->power.entry); |
Matthias Kaehlcke | 11048dc | 2007-05-23 14:19:41 -0700 | [diff] [blame] | 113 | mutex_unlock(&dpm_list_mtx); |
Rafael J. Wysocki | 074037e | 2010-09-22 22:09:10 +0200 | [diff] [blame] | 114 | device_wakeup_disable(dev); |
Rafael J. Wysocki | 5e928f7 | 2009-08-18 23:38:32 +0200 | [diff] [blame] | 115 | pm_runtime_remove(dev); |
Rafael J. Wysocki | 775b64d | 2008-01-12 20:40:46 +0100 | [diff] [blame] | 116 | } |
| 117 | |
Rafael J. Wysocki | 1eede07 | 2008-05-20 23:00:01 +0200 | [diff] [blame] | 118 | /** |
Rafael J. Wysocki | 20d652d | 2009-08-20 20:25:52 +0200 | [diff] [blame] | 119 | * device_pm_move_before - Move device in the PM core's list of active devices. |
| 120 | * @deva: Device to move in dpm_list. |
| 121 | * @devb: Device @deva should come before. |
Cornelia Huck | ffa6a70 | 2009-03-04 12:44:00 +0100 | [diff] [blame] | 122 | */ |
| 123 | void device_pm_move_before(struct device *deva, struct device *devb) |
| 124 | { |
| 125 | pr_debug("PM: Moving %s:%s before %s:%s\n", |
Rafael J. Wysocki | 5c1a07a | 2010-12-24 15:03:34 +0100 | [diff] [blame] | 126 | deva->bus ? deva->bus->name : "No Bus", dev_name(deva), |
| 127 | devb->bus ? devb->bus->name : "No Bus", dev_name(devb)); |
Cornelia Huck | ffa6a70 | 2009-03-04 12:44:00 +0100 | [diff] [blame] | 128 | /* Delete deva from dpm_list and reinsert before devb. */ |
| 129 | list_move_tail(&deva->power.entry, &devb->power.entry); |
| 130 | } |
| 131 | |
| 132 | /** |
Rafael J. Wysocki | 20d652d | 2009-08-20 20:25:52 +0200 | [diff] [blame] | 133 | * device_pm_move_after - Move device in the PM core's list of active devices. |
| 134 | * @deva: Device to move in dpm_list. |
| 135 | * @devb: Device @deva should come after. |
Cornelia Huck | ffa6a70 | 2009-03-04 12:44:00 +0100 | [diff] [blame] | 136 | */ |
| 137 | void device_pm_move_after(struct device *deva, struct device *devb) |
| 138 | { |
| 139 | pr_debug("PM: Moving %s:%s after %s:%s\n", |
Rafael J. Wysocki | 5c1a07a | 2010-12-24 15:03:34 +0100 | [diff] [blame] | 140 | deva->bus ? deva->bus->name : "No Bus", dev_name(deva), |
| 141 | devb->bus ? devb->bus->name : "No Bus", dev_name(devb)); |
Cornelia Huck | ffa6a70 | 2009-03-04 12:44:00 +0100 | [diff] [blame] | 142 | /* Delete deva from dpm_list and reinsert after devb. */ |
| 143 | list_move(&deva->power.entry, &devb->power.entry); |
| 144 | } |
| 145 | |
| 146 | /** |
Rafael J. Wysocki | 20d652d | 2009-08-20 20:25:52 +0200 | [diff] [blame] | 147 | * device_pm_move_last - Move device to end of the PM core's list of devices. |
| 148 | * @dev: Device to move in dpm_list. |
Cornelia Huck | ffa6a70 | 2009-03-04 12:44:00 +0100 | [diff] [blame] | 149 | */ |
| 150 | void device_pm_move_last(struct device *dev) |
| 151 | { |
| 152 | pr_debug("PM: Moving %s:%s to end of list\n", |
Rafael J. Wysocki | 5c1a07a | 2010-12-24 15:03:34 +0100 | [diff] [blame] | 153 | dev->bus ? dev->bus->name : "No Bus", dev_name(dev)); |
Cornelia Huck | ffa6a70 | 2009-03-04 12:44:00 +0100 | [diff] [blame] | 154 | list_move_tail(&dev->power.entry, &dpm_list); |
| 155 | } |
| 156 | |
Rafael J. Wysocki | 875ab0b | 2009-12-18 01:57:31 +0100 | [diff] [blame] | 157 | static ktime_t initcall_debug_start(struct device *dev) |
| 158 | { |
| 159 | ktime_t calltime = ktime_set(0, 0); |
| 160 | |
| 161 | if (initcall_debug) { |
| 162 | pr_info("calling %s+ @ %i\n", |
| 163 | dev_name(dev), task_pid_nr(current)); |
| 164 | calltime = ktime_get(); |
| 165 | } |
| 166 | |
| 167 | return calltime; |
| 168 | } |
| 169 | |
| 170 | static void initcall_debug_report(struct device *dev, ktime_t calltime, |
| 171 | int error) |
| 172 | { |
| 173 | ktime_t delta, rettime; |
| 174 | |
| 175 | if (initcall_debug) { |
| 176 | rettime = ktime_get(); |
| 177 | delta = ktime_sub(rettime, calltime); |
| 178 | pr_info("call %s+ returned %d after %Ld usecs\n", dev_name(dev), |
| 179 | error, (unsigned long long)ktime_to_ns(delta) >> 10); |
| 180 | } |
| 181 | } |
| 182 | |
Cornelia Huck | ffa6a70 | 2009-03-04 12:44:00 +0100 | [diff] [blame] | 183 | /** |
Rafael J. Wysocki | 5af84b8 | 2010-01-23 22:23:32 +0100 | [diff] [blame] | 184 | * dpm_wait - Wait for a PM operation to complete. |
| 185 | * @dev: Device to wait for. |
| 186 | * @async: If unset, wait only if the device's power.async_suspend flag is set. |
| 187 | */ |
| 188 | static void dpm_wait(struct device *dev, bool async) |
| 189 | { |
| 190 | if (!dev) |
| 191 | return; |
| 192 | |
Rafael J. Wysocki | 0e06b4a | 2010-01-23 22:25:15 +0100 | [diff] [blame] | 193 | if (async || (pm_async_enabled && dev->power.async_suspend)) |
Rafael J. Wysocki | 5af84b8 | 2010-01-23 22:23:32 +0100 | [diff] [blame] | 194 | wait_for_completion(&dev->power.completion); |
| 195 | } |
| 196 | |
| 197 | static int dpm_wait_fn(struct device *dev, void *async_ptr) |
| 198 | { |
| 199 | dpm_wait(dev, *((bool *)async_ptr)); |
| 200 | return 0; |
| 201 | } |
| 202 | |
| 203 | static void dpm_wait_for_children(struct device *dev, bool async) |
| 204 | { |
| 205 | device_for_each_child(dev, &async, dpm_wait_fn); |
| 206 | } |
| 207 | |
| 208 | /** |
Rafael J. Wysocki | 20d652d | 2009-08-20 20:25:52 +0200 | [diff] [blame] | 209 | * pm_op - Execute the PM operation appropriate for given PM event. |
| 210 | * @dev: Device to handle. |
| 211 | * @ops: PM operations to choose from. |
| 212 | * @state: PM transition of the system being carried out. |
Rafael J. Wysocki | 1eede07 | 2008-05-20 23:00:01 +0200 | [diff] [blame] | 213 | */ |
Dmitry Torokhov | d9ab771 | 2009-07-22 00:37:25 +0200 | [diff] [blame] | 214 | static int pm_op(struct device *dev, |
| 215 | const struct dev_pm_ops *ops, |
| 216 | pm_message_t state) |
Rafael J. Wysocki | 1eede07 | 2008-05-20 23:00:01 +0200 | [diff] [blame] | 217 | { |
| 218 | int error = 0; |
Rafael J. Wysocki | 875ab0b | 2009-12-18 01:57:31 +0100 | [diff] [blame] | 219 | ktime_t calltime; |
Arjan van de Ven | f251177 | 2009-12-13 20:29:01 +0100 | [diff] [blame] | 220 | |
Rafael J. Wysocki | 875ab0b | 2009-12-18 01:57:31 +0100 | [diff] [blame] | 221 | calltime = initcall_debug_start(dev); |
Rafael J. Wysocki | 1eede07 | 2008-05-20 23:00:01 +0200 | [diff] [blame] | 222 | |
| 223 | switch (state.event) { |
| 224 | #ifdef CONFIG_SUSPEND |
| 225 | case PM_EVENT_SUSPEND: |
| 226 | if (ops->suspend) { |
| 227 | error = ops->suspend(dev); |
| 228 | suspend_report_result(ops->suspend, error); |
| 229 | } |
| 230 | break; |
| 231 | case PM_EVENT_RESUME: |
| 232 | if (ops->resume) { |
| 233 | error = ops->resume(dev); |
| 234 | suspend_report_result(ops->resume, error); |
| 235 | } |
| 236 | break; |
| 237 | #endif /* CONFIG_SUSPEND */ |
Rafael J. Wysocki | 1f112ce | 2011-04-11 22:54:42 +0200 | [diff] [blame] | 238 | #ifdef CONFIG_HIBERNATE_CALLBACKS |
Rafael J. Wysocki | 1eede07 | 2008-05-20 23:00:01 +0200 | [diff] [blame] | 239 | case PM_EVENT_FREEZE: |
| 240 | case PM_EVENT_QUIESCE: |
| 241 | if (ops->freeze) { |
| 242 | error = ops->freeze(dev); |
| 243 | suspend_report_result(ops->freeze, error); |
| 244 | } |
| 245 | break; |
| 246 | case PM_EVENT_HIBERNATE: |
| 247 | if (ops->poweroff) { |
| 248 | error = ops->poweroff(dev); |
| 249 | suspend_report_result(ops->poweroff, error); |
| 250 | } |
| 251 | break; |
| 252 | case PM_EVENT_THAW: |
| 253 | case PM_EVENT_RECOVER: |
| 254 | if (ops->thaw) { |
| 255 | error = ops->thaw(dev); |
| 256 | suspend_report_result(ops->thaw, error); |
| 257 | } |
| 258 | break; |
| 259 | case PM_EVENT_RESTORE: |
| 260 | if (ops->restore) { |
| 261 | error = ops->restore(dev); |
| 262 | suspend_report_result(ops->restore, error); |
| 263 | } |
| 264 | break; |
Rafael J. Wysocki | 1f112ce | 2011-04-11 22:54:42 +0200 | [diff] [blame] | 265 | #endif /* CONFIG_HIBERNATE_CALLBACKS */ |
Rafael J. Wysocki | 1eede07 | 2008-05-20 23:00:01 +0200 | [diff] [blame] | 266 | default: |
| 267 | error = -EINVAL; |
| 268 | } |
Arjan van de Ven | f251177 | 2009-12-13 20:29:01 +0100 | [diff] [blame] | 269 | |
Rafael J. Wysocki | 875ab0b | 2009-12-18 01:57:31 +0100 | [diff] [blame] | 270 | initcall_debug_report(dev, calltime, error); |
Arjan van de Ven | f251177 | 2009-12-13 20:29:01 +0100 | [diff] [blame] | 271 | |
Rafael J. Wysocki | 1eede07 | 2008-05-20 23:00:01 +0200 | [diff] [blame] | 272 | return error; |
| 273 | } |
| 274 | |
| 275 | /** |
Rafael J. Wysocki | 20d652d | 2009-08-20 20:25:52 +0200 | [diff] [blame] | 276 | * pm_noirq_op - Execute the PM operation appropriate for given PM event. |
| 277 | * @dev: Device to handle. |
| 278 | * @ops: PM operations to choose from. |
| 279 | * @state: PM transition of the system being carried out. |
Rafael J. Wysocki | 1eede07 | 2008-05-20 23:00:01 +0200 | [diff] [blame] | 280 | * |
Rafael J. Wysocki | 20d652d | 2009-08-20 20:25:52 +0200 | [diff] [blame] | 281 | * The driver of @dev will not receive interrupts while this function is being |
| 282 | * executed. |
Rafael J. Wysocki | 1eede07 | 2008-05-20 23:00:01 +0200 | [diff] [blame] | 283 | */ |
Dmitry Torokhov | d9ab771 | 2009-07-22 00:37:25 +0200 | [diff] [blame] | 284 | static int pm_noirq_op(struct device *dev, |
| 285 | const struct dev_pm_ops *ops, |
Rafael J. Wysocki | 1eede07 | 2008-05-20 23:00:01 +0200 | [diff] [blame] | 286 | pm_message_t state) |
| 287 | { |
| 288 | int error = 0; |
Rafael J. Wysocki | 2cbb3ce | 2010-12-15 00:17:29 +0100 | [diff] [blame] | 289 | ktime_t calltime = ktime_set(0, 0), delta, rettime; |
Arjan van de Ven | f251177 | 2009-12-13 20:29:01 +0100 | [diff] [blame] | 290 | |
| 291 | if (initcall_debug) { |
Rafael J. Wysocki | 8cc6b39 | 2010-01-23 22:03:29 +0100 | [diff] [blame] | 292 | pr_info("calling %s+ @ %i, parent: %s\n", |
| 293 | dev_name(dev), task_pid_nr(current), |
| 294 | dev->parent ? dev_name(dev->parent) : "none"); |
Arjan van de Ven | f251177 | 2009-12-13 20:29:01 +0100 | [diff] [blame] | 295 | calltime = ktime_get(); |
| 296 | } |
Rafael J. Wysocki | 1eede07 | 2008-05-20 23:00:01 +0200 | [diff] [blame] | 297 | |
| 298 | switch (state.event) { |
| 299 | #ifdef CONFIG_SUSPEND |
| 300 | case PM_EVENT_SUSPEND: |
| 301 | if (ops->suspend_noirq) { |
| 302 | error = ops->suspend_noirq(dev); |
| 303 | suspend_report_result(ops->suspend_noirq, error); |
| 304 | } |
| 305 | break; |
| 306 | case PM_EVENT_RESUME: |
| 307 | if (ops->resume_noirq) { |
| 308 | error = ops->resume_noirq(dev); |
| 309 | suspend_report_result(ops->resume_noirq, error); |
| 310 | } |
| 311 | break; |
| 312 | #endif /* CONFIG_SUSPEND */ |
Rafael J. Wysocki | 1f112ce | 2011-04-11 22:54:42 +0200 | [diff] [blame] | 313 | #ifdef CONFIG_HIBERNATE_CALLBACKS |
Rafael J. Wysocki | 1eede07 | 2008-05-20 23:00:01 +0200 | [diff] [blame] | 314 | case PM_EVENT_FREEZE: |
| 315 | case PM_EVENT_QUIESCE: |
| 316 | if (ops->freeze_noirq) { |
| 317 | error = ops->freeze_noirq(dev); |
| 318 | suspend_report_result(ops->freeze_noirq, error); |
| 319 | } |
| 320 | break; |
| 321 | case PM_EVENT_HIBERNATE: |
| 322 | if (ops->poweroff_noirq) { |
| 323 | error = ops->poweroff_noirq(dev); |
| 324 | suspend_report_result(ops->poweroff_noirq, error); |
| 325 | } |
| 326 | break; |
| 327 | case PM_EVENT_THAW: |
| 328 | case PM_EVENT_RECOVER: |
| 329 | if (ops->thaw_noirq) { |
| 330 | error = ops->thaw_noirq(dev); |
| 331 | suspend_report_result(ops->thaw_noirq, error); |
| 332 | } |
| 333 | break; |
| 334 | case PM_EVENT_RESTORE: |
| 335 | if (ops->restore_noirq) { |
| 336 | error = ops->restore_noirq(dev); |
| 337 | suspend_report_result(ops->restore_noirq, error); |
| 338 | } |
| 339 | break; |
Rafael J. Wysocki | 1f112ce | 2011-04-11 22:54:42 +0200 | [diff] [blame] | 340 | #endif /* CONFIG_HIBERNATE_CALLBACKS */ |
Rafael J. Wysocki | 1eede07 | 2008-05-20 23:00:01 +0200 | [diff] [blame] | 341 | default: |
| 342 | error = -EINVAL; |
| 343 | } |
Arjan van de Ven | f251177 | 2009-12-13 20:29:01 +0100 | [diff] [blame] | 344 | |
| 345 | if (initcall_debug) { |
| 346 | rettime = ktime_get(); |
| 347 | delta = ktime_sub(rettime, calltime); |
Rafael J. Wysocki | 875ab0b | 2009-12-18 01:57:31 +0100 | [diff] [blame] | 348 | printk("initcall %s_i+ returned %d after %Ld usecs\n", |
| 349 | dev_name(dev), error, |
| 350 | (unsigned long long)ktime_to_ns(delta) >> 10); |
Arjan van de Ven | f251177 | 2009-12-13 20:29:01 +0100 | [diff] [blame] | 351 | } |
| 352 | |
Rafael J. Wysocki | 1eede07 | 2008-05-20 23:00:01 +0200 | [diff] [blame] | 353 | return error; |
| 354 | } |
| 355 | |
| 356 | static char *pm_verb(int event) |
| 357 | { |
| 358 | switch (event) { |
| 359 | case PM_EVENT_SUSPEND: |
| 360 | return "suspend"; |
| 361 | case PM_EVENT_RESUME: |
| 362 | return "resume"; |
| 363 | case PM_EVENT_FREEZE: |
| 364 | return "freeze"; |
| 365 | case PM_EVENT_QUIESCE: |
| 366 | return "quiesce"; |
| 367 | case PM_EVENT_HIBERNATE: |
| 368 | return "hibernate"; |
| 369 | case PM_EVENT_THAW: |
| 370 | return "thaw"; |
| 371 | case PM_EVENT_RESTORE: |
| 372 | return "restore"; |
| 373 | case PM_EVENT_RECOVER: |
| 374 | return "recover"; |
| 375 | default: |
| 376 | return "(unknown PM event)"; |
| 377 | } |
| 378 | } |
| 379 | |
| 380 | static void pm_dev_dbg(struct device *dev, pm_message_t state, char *info) |
| 381 | { |
| 382 | dev_dbg(dev, "%s%s%s\n", info, pm_verb(state.event), |
| 383 | ((state.event & PM_EVENT_SLEEP) && device_may_wakeup(dev)) ? |
| 384 | ", may wakeup" : ""); |
| 385 | } |
| 386 | |
| 387 | static void pm_dev_err(struct device *dev, pm_message_t state, char *info, |
| 388 | int error) |
| 389 | { |
| 390 | printk(KERN_ERR "PM: Device %s failed to %s%s: error %d\n", |
Rafael J. Wysocki | 5c1a07a | 2010-12-24 15:03:34 +0100 | [diff] [blame] | 391 | dev_name(dev), pm_verb(state.event), info, error); |
Rafael J. Wysocki | 1eede07 | 2008-05-20 23:00:01 +0200 | [diff] [blame] | 392 | } |
| 393 | |
Rafael J. Wysocki | ecf762b | 2009-12-18 01:57:47 +0100 | [diff] [blame] | 394 | static void dpm_show_time(ktime_t starttime, pm_message_t state, char *info) |
| 395 | { |
| 396 | ktime_t calltime; |
Kevin Cernekee | 0702d9e | 2010-09-20 22:32:10 +0200 | [diff] [blame] | 397 | u64 usecs64; |
Rafael J. Wysocki | ecf762b | 2009-12-18 01:57:47 +0100 | [diff] [blame] | 398 | int usecs; |
| 399 | |
| 400 | calltime = ktime_get(); |
| 401 | usecs64 = ktime_to_ns(ktime_sub(calltime, starttime)); |
| 402 | do_div(usecs64, NSEC_PER_USEC); |
| 403 | usecs = usecs64; |
| 404 | if (usecs == 0) |
| 405 | usecs = 1; |
| 406 | pr_info("PM: %s%s%s of devices complete after %ld.%03ld msecs\n", |
| 407 | info ?: "", info ? " " : "", pm_verb(state.event), |
| 408 | usecs / USEC_PER_MSEC, usecs % USEC_PER_MSEC); |
| 409 | } |
| 410 | |
Alan Stern | cd59abf | 2007-09-21 15:36:56 -0400 | [diff] [blame] | 411 | /*------------------------- Resume routines -------------------------*/ |
| 412 | |
| 413 | /** |
Rafael J. Wysocki | 20d652d | 2009-08-20 20:25:52 +0200 | [diff] [blame] | 414 | * device_resume_noirq - Execute an "early resume" callback for given device. |
| 415 | * @dev: Device to handle. |
| 416 | * @state: PM transition of the system being carried out. |
Alan Stern | cd59abf | 2007-09-21 15:36:56 -0400 | [diff] [blame] | 417 | * |
Rafael J. Wysocki | 20d652d | 2009-08-20 20:25:52 +0200 | [diff] [blame] | 418 | * The driver of @dev will not receive interrupts while this function is being |
| 419 | * executed. |
Alan Stern | cd59abf | 2007-09-21 15:36:56 -0400 | [diff] [blame] | 420 | */ |
Alan Stern | d161630 | 2009-05-24 22:05:42 +0200 | [diff] [blame] | 421 | static int device_resume_noirq(struct device *dev, pm_message_t state) |
Alan Stern | cd59abf | 2007-09-21 15:36:56 -0400 | [diff] [blame] | 422 | { |
| 423 | int error = 0; |
| 424 | |
| 425 | TRACE_DEVICE(dev); |
| 426 | TRACE_RESUME(0); |
| 427 | |
Rafael J. Wysocki | 564b905 | 2011-06-23 01:52:55 +0200 | [diff] [blame] | 428 | if (dev->pm_domain) { |
Rafael J. Wysocki | 7538e3d | 2011-02-16 21:53:17 +0100 | [diff] [blame] | 429 | pm_dev_dbg(dev, state, "EARLY power domain "); |
Rafael J. Wysocki | 564b905 | 2011-06-23 01:52:55 +0200 | [diff] [blame] | 430 | error = pm_noirq_op(dev, &dev->pm_domain->ops, state); |
Rafael J. Wysocki | 4d27e9d | 2011-04-29 00:35:50 +0200 | [diff] [blame] | 431 | } else if (dev->type && dev->type->pm) { |
Dominik Brodowski | e7176a3 | 2010-03-15 21:43:11 +0100 | [diff] [blame] | 432 | pm_dev_dbg(dev, state, "EARLY type "); |
| 433 | error = pm_noirq_op(dev, dev->type->pm, state); |
Rafael J. Wysocki | 9659cc0 | 2011-02-18 23:20:21 +0100 | [diff] [blame] | 434 | } else if (dev->class && dev->class->pm) { |
Dominik Brodowski | e7176a3 | 2010-03-15 21:43:11 +0100 | [diff] [blame] | 435 | pm_dev_dbg(dev, state, "EARLY class "); |
| 436 | error = pm_noirq_op(dev, dev->class->pm, state); |
Rafael J. Wysocki | 9659cc0 | 2011-02-18 23:20:21 +0100 | [diff] [blame] | 437 | } else if (dev->bus && dev->bus->pm) { |
| 438 | pm_dev_dbg(dev, state, "EARLY "); |
| 439 | error = pm_noirq_op(dev, dev->bus->pm, state); |
Dominik Brodowski | e7176a3 | 2010-03-15 21:43:11 +0100 | [diff] [blame] | 440 | } |
| 441 | |
Rafael J. Wysocki | 775b64d | 2008-01-12 20:40:46 +0100 | [diff] [blame] | 442 | TRACE_RESUME(error); |
| 443 | return error; |
| 444 | } |
| 445 | |
| 446 | /** |
Rafael J. Wysocki | 20d652d | 2009-08-20 20:25:52 +0200 | [diff] [blame] | 447 | * dpm_resume_noirq - Execute "early resume" callbacks for non-sysdev devices. |
| 448 | * @state: PM transition of the system being carried out. |
Rafael J. Wysocki | 775b64d | 2008-01-12 20:40:46 +0100 | [diff] [blame] | 449 | * |
Rafael J. Wysocki | 20d652d | 2009-08-20 20:25:52 +0200 | [diff] [blame] | 450 | * Call the "noirq" resume handlers for all devices marked as DPM_OFF_IRQ and |
| 451 | * enable device drivers to receive interrupts. |
Rafael J. Wysocki | 775b64d | 2008-01-12 20:40:46 +0100 | [diff] [blame] | 452 | */ |
Alan Stern | d161630 | 2009-05-24 22:05:42 +0200 | [diff] [blame] | 453 | void dpm_resume_noirq(pm_message_t state) |
Rafael J. Wysocki | 775b64d | 2008-01-12 20:40:46 +0100 | [diff] [blame] | 454 | { |
Rafael J. Wysocki | ecf762b | 2009-12-18 01:57:47 +0100 | [diff] [blame] | 455 | ktime_t starttime = ktime_get(); |
Rafael J. Wysocki | 775b64d | 2008-01-12 20:40:46 +0100 | [diff] [blame] | 456 | |
Rafael J. Wysocki | 32bdfac | 2009-05-24 21:15:07 +0200 | [diff] [blame] | 457 | mutex_lock(&dpm_list_mtx); |
Rafael J. Wysocki | 8a43a9a | 2010-12-16 00:50:30 +0100 | [diff] [blame] | 458 | while (!list_empty(&dpm_noirq_list)) { |
| 459 | struct device *dev = to_device(dpm_noirq_list.next); |
Rafael J. Wysocki | 5b219a5 | 2010-12-16 00:51:08 +0100 | [diff] [blame] | 460 | int error; |
Rafael J. Wysocki | d08a5ac | 2010-11-11 01:50:53 +0100 | [diff] [blame] | 461 | |
| 462 | get_device(dev); |
Rafael J. Wysocki | 5b219a5 | 2010-12-16 00:51:08 +0100 | [diff] [blame] | 463 | list_move_tail(&dev->power.entry, &dpm_suspended_list); |
| 464 | mutex_unlock(&dpm_list_mtx); |
Rafael J. Wysocki | 775b64d | 2008-01-12 20:40:46 +0100 | [diff] [blame] | 465 | |
Rafael J. Wysocki | 5b219a5 | 2010-12-16 00:51:08 +0100 | [diff] [blame] | 466 | error = device_resume_noirq(dev, state); |
| 467 | if (error) |
| 468 | pm_dev_err(dev, state, " early", error); |
Rafael J. Wysocki | d08a5ac | 2010-11-11 01:50:53 +0100 | [diff] [blame] | 469 | |
Rafael J. Wysocki | 5b219a5 | 2010-12-16 00:51:08 +0100 | [diff] [blame] | 470 | mutex_lock(&dpm_list_mtx); |
Rafael J. Wysocki | d08a5ac | 2010-11-11 01:50:53 +0100 | [diff] [blame] | 471 | put_device(dev); |
| 472 | } |
Rafael J. Wysocki | 32bdfac | 2009-05-24 21:15:07 +0200 | [diff] [blame] | 473 | mutex_unlock(&dpm_list_mtx); |
Rafael J. Wysocki | ecf762b | 2009-12-18 01:57:47 +0100 | [diff] [blame] | 474 | dpm_show_time(starttime, state, "early"); |
Rafael J. Wysocki | 2ed8d2b | 2009-03-16 22:34:06 +0100 | [diff] [blame] | 475 | resume_device_irqs(); |
Rafael J. Wysocki | 775b64d | 2008-01-12 20:40:46 +0100 | [diff] [blame] | 476 | } |
Alan Stern | d161630 | 2009-05-24 22:05:42 +0200 | [diff] [blame] | 477 | EXPORT_SYMBOL_GPL(dpm_resume_noirq); |
Rafael J. Wysocki | 775b64d | 2008-01-12 20:40:46 +0100 | [diff] [blame] | 478 | |
| 479 | /** |
Rafael J. Wysocki | 875ab0b | 2009-12-18 01:57:31 +0100 | [diff] [blame] | 480 | * legacy_resume - Execute a legacy (bus or class) resume callback for device. |
Randy Dunlap | 0a88422 | 2010-01-08 14:42:57 -0800 | [diff] [blame] | 481 | * @dev: Device to resume. |
| 482 | * @cb: Resume callback to execute. |
Rafael J. Wysocki | 875ab0b | 2009-12-18 01:57:31 +0100 | [diff] [blame] | 483 | */ |
| 484 | static int legacy_resume(struct device *dev, int (*cb)(struct device *dev)) |
| 485 | { |
| 486 | int error; |
| 487 | ktime_t calltime; |
| 488 | |
| 489 | calltime = initcall_debug_start(dev); |
| 490 | |
| 491 | error = cb(dev); |
| 492 | suspend_report_result(cb, error); |
| 493 | |
| 494 | initcall_debug_report(dev, calltime, error); |
| 495 | |
| 496 | return error; |
| 497 | } |
| 498 | |
| 499 | /** |
Rafael J. Wysocki | 97df8c1 | 2010-01-23 22:25:31 +0100 | [diff] [blame] | 500 | * device_resume - Execute "resume" callbacks for given device. |
Rafael J. Wysocki | 20d652d | 2009-08-20 20:25:52 +0200 | [diff] [blame] | 501 | * @dev: Device to handle. |
| 502 | * @state: PM transition of the system being carried out. |
Rafael J. Wysocki | 5af84b8 | 2010-01-23 22:23:32 +0100 | [diff] [blame] | 503 | * @async: If true, the device is being resumed asynchronously. |
Rafael J. Wysocki | 775b64d | 2008-01-12 20:40:46 +0100 | [diff] [blame] | 504 | */ |
Rafael J. Wysocki | 97df8c1 | 2010-01-23 22:25:31 +0100 | [diff] [blame] | 505 | static int device_resume(struct device *dev, pm_message_t state, bool async) |
Rafael J. Wysocki | 775b64d | 2008-01-12 20:40:46 +0100 | [diff] [blame] | 506 | { |
| 507 | int error = 0; |
Rafael J. Wysocki | 1e2ef05 | 2011-07-06 10:51:58 +0200 | [diff] [blame^] | 508 | bool put = false; |
Rafael J. Wysocki | 775b64d | 2008-01-12 20:40:46 +0100 | [diff] [blame] | 509 | |
| 510 | TRACE_DEVICE(dev); |
| 511 | TRACE_RESUME(0); |
Alan Stern | cd59abf | 2007-09-21 15:36:56 -0400 | [diff] [blame] | 512 | |
Rafael J. Wysocki | 5af84b8 | 2010-01-23 22:23:32 +0100 | [diff] [blame] | 513 | dpm_wait(dev->parent, async); |
Greg Kroah-Hartman | 8e9394c | 2010-02-17 10:57:05 -0800 | [diff] [blame] | 514 | device_lock(dev); |
Rafael J. Wysocki | 7a8d37a | 2008-02-25 00:35:04 +0100 | [diff] [blame] | 515 | |
Alan Stern | f76b168 | 2011-06-18 20:22:23 +0200 | [diff] [blame] | 516 | /* |
| 517 | * This is a fib. But we'll allow new children to be added below |
| 518 | * a resumed device, even if the device hasn't been completed yet. |
| 519 | */ |
| 520 | dev->power.is_prepared = false; |
Rafael J. Wysocki | 97df8c1 | 2010-01-23 22:25:31 +0100 | [diff] [blame] | 521 | |
Alan Stern | 6d0e0e8 | 2011-06-18 22:42:09 +0200 | [diff] [blame] | 522 | if (!dev->power.is_suspended) |
| 523 | goto Unlock; |
| 524 | |
Rafael J. Wysocki | 1e2ef05 | 2011-07-06 10:51:58 +0200 | [diff] [blame^] | 525 | pm_runtime_enable(dev); |
| 526 | put = true; |
| 527 | |
Rafael J. Wysocki | 564b905 | 2011-06-23 01:52:55 +0200 | [diff] [blame] | 528 | if (dev->pm_domain) { |
Rafael J. Wysocki | 7538e3d | 2011-02-16 21:53:17 +0100 | [diff] [blame] | 529 | pm_dev_dbg(dev, state, "power domain "); |
Rafael J. Wysocki | 564b905 | 2011-06-23 01:52:55 +0200 | [diff] [blame] | 530 | error = pm_op(dev, &dev->pm_domain->ops, state); |
Rafael J. Wysocki | 4d27e9d | 2011-04-29 00:35:50 +0200 | [diff] [blame] | 531 | goto End; |
Rafael J. Wysocki | 7538e3d | 2011-02-16 21:53:17 +0100 | [diff] [blame] | 532 | } |
| 533 | |
Rafael J. Wysocki | 9659cc0 | 2011-02-18 23:20:21 +0100 | [diff] [blame] | 534 | if (dev->type && dev->type->pm) { |
| 535 | pm_dev_dbg(dev, state, "type "); |
| 536 | error = pm_op(dev, dev->type->pm, state); |
| 537 | goto End; |
| 538 | } |
| 539 | |
| 540 | if (dev->class) { |
| 541 | if (dev->class->pm) { |
| 542 | pm_dev_dbg(dev, state, "class "); |
| 543 | error = pm_op(dev, dev->class->pm, state); |
| 544 | goto End; |
| 545 | } else if (dev->class->resume) { |
| 546 | pm_dev_dbg(dev, state, "legacy class "); |
| 547 | error = legacy_resume(dev, dev->class->resume); |
| 548 | goto End; |
| 549 | } |
| 550 | } |
| 551 | |
Rafael J. Wysocki | 1eede07 | 2008-05-20 23:00:01 +0200 | [diff] [blame] | 552 | if (dev->bus) { |
| 553 | if (dev->bus->pm) { |
| 554 | pm_dev_dbg(dev, state, ""); |
Rafael J. Wysocki | adf0949 | 2008-10-06 22:46:05 +0200 | [diff] [blame] | 555 | error = pm_op(dev, dev->bus->pm, state); |
Rafael J. Wysocki | 1eede07 | 2008-05-20 23:00:01 +0200 | [diff] [blame] | 556 | } else if (dev->bus->resume) { |
| 557 | pm_dev_dbg(dev, state, "legacy "); |
Rafael J. Wysocki | 875ab0b | 2009-12-18 01:57:31 +0100 | [diff] [blame] | 558 | error = legacy_resume(dev, dev->bus->resume); |
Rafael J. Wysocki | 1eede07 | 2008-05-20 23:00:01 +0200 | [diff] [blame] | 559 | } |
Alan Stern | cd59abf | 2007-09-21 15:36:56 -0400 | [diff] [blame] | 560 | } |
| 561 | |
Rafael J. Wysocki | 1eede07 | 2008-05-20 23:00:01 +0200 | [diff] [blame] | 562 | End: |
Alan Stern | 6d0e0e8 | 2011-06-18 22:42:09 +0200 | [diff] [blame] | 563 | dev->power.is_suspended = false; |
| 564 | |
| 565 | Unlock: |
Greg Kroah-Hartman | 8e9394c | 2010-02-17 10:57:05 -0800 | [diff] [blame] | 566 | device_unlock(dev); |
Rafael J. Wysocki | 5af84b8 | 2010-01-23 22:23:32 +0100 | [diff] [blame] | 567 | complete_all(&dev->power.completion); |
Rafael J. Wysocki | 7a8d37a | 2008-02-25 00:35:04 +0100 | [diff] [blame] | 568 | |
Alan Stern | cd59abf | 2007-09-21 15:36:56 -0400 | [diff] [blame] | 569 | TRACE_RESUME(error); |
Rafael J. Wysocki | 1e2ef05 | 2011-07-06 10:51:58 +0200 | [diff] [blame^] | 570 | |
| 571 | if (put) |
| 572 | pm_runtime_put_sync(dev); |
| 573 | |
Alan Stern | cd59abf | 2007-09-21 15:36:56 -0400 | [diff] [blame] | 574 | return error; |
| 575 | } |
| 576 | |
Rafael J. Wysocki | 5af84b8 | 2010-01-23 22:23:32 +0100 | [diff] [blame] | 577 | static void async_resume(void *data, async_cookie_t cookie) |
| 578 | { |
| 579 | struct device *dev = (struct device *)data; |
| 580 | int error; |
| 581 | |
Rafael J. Wysocki | 97df8c1 | 2010-01-23 22:25:31 +0100 | [diff] [blame] | 582 | error = device_resume(dev, pm_transition, true); |
Rafael J. Wysocki | 5af84b8 | 2010-01-23 22:23:32 +0100 | [diff] [blame] | 583 | if (error) |
| 584 | pm_dev_err(dev, pm_transition, " async", error); |
| 585 | put_device(dev); |
| 586 | } |
| 587 | |
Rafael J. Wysocki | 97df8c1 | 2010-01-23 22:25:31 +0100 | [diff] [blame] | 588 | static bool is_async(struct device *dev) |
Rafael J. Wysocki | 5af84b8 | 2010-01-23 22:23:32 +0100 | [diff] [blame] | 589 | { |
Rafael J. Wysocki | 97df8c1 | 2010-01-23 22:25:31 +0100 | [diff] [blame] | 590 | return dev->power.async_suspend && pm_async_enabled |
| 591 | && !pm_trace_is_enabled(); |
Rafael J. Wysocki | 5af84b8 | 2010-01-23 22:23:32 +0100 | [diff] [blame] | 592 | } |
| 593 | |
Rafael J. Wysocki | 775b64d | 2008-01-12 20:40:46 +0100 | [diff] [blame] | 594 | /** |
Rafael J. Wysocki | 20d652d | 2009-08-20 20:25:52 +0200 | [diff] [blame] | 595 | * dpm_resume - Execute "resume" callbacks for non-sysdev devices. |
| 596 | * @state: PM transition of the system being carried out. |
Rafael J. Wysocki | 775b64d | 2008-01-12 20:40:46 +0100 | [diff] [blame] | 597 | * |
Rafael J. Wysocki | 20d652d | 2009-08-20 20:25:52 +0200 | [diff] [blame] | 598 | * Execute the appropriate "resume" callback for all devices whose status |
| 599 | * indicates that they are suspended. |
Alan Stern | cd59abf | 2007-09-21 15:36:56 -0400 | [diff] [blame] | 600 | */ |
Rafael J. Wysocki | 91e7c75 | 2011-05-17 23:26:00 +0200 | [diff] [blame] | 601 | void dpm_resume(pm_message_t state) |
Alan Stern | cd59abf | 2007-09-21 15:36:56 -0400 | [diff] [blame] | 602 | { |
Rafael J. Wysocki | 97df8c1 | 2010-01-23 22:25:31 +0100 | [diff] [blame] | 603 | struct device *dev; |
Rafael J. Wysocki | ecf762b | 2009-12-18 01:57:47 +0100 | [diff] [blame] | 604 | ktime_t starttime = ktime_get(); |
Alan Stern | cd59abf | 2007-09-21 15:36:56 -0400 | [diff] [blame] | 605 | |
Rafael J. Wysocki | 91e7c75 | 2011-05-17 23:26:00 +0200 | [diff] [blame] | 606 | might_sleep(); |
| 607 | |
Rafael J. Wysocki | 1eede07 | 2008-05-20 23:00:01 +0200 | [diff] [blame] | 608 | mutex_lock(&dpm_list_mtx); |
Rafael J. Wysocki | 5af84b8 | 2010-01-23 22:23:32 +0100 | [diff] [blame] | 609 | pm_transition = state; |
Rafael J. Wysocki | 098dff7 | 2010-09-22 22:10:57 +0200 | [diff] [blame] | 610 | async_error = 0; |
Rafael J. Wysocki | 1eede07 | 2008-05-20 23:00:01 +0200 | [diff] [blame] | 611 | |
Rafael J. Wysocki | 8a43a9a | 2010-12-16 00:50:30 +0100 | [diff] [blame] | 612 | list_for_each_entry(dev, &dpm_suspended_list, power.entry) { |
Rafael J. Wysocki | 97df8c1 | 2010-01-23 22:25:31 +0100 | [diff] [blame] | 613 | INIT_COMPLETION(dev->power.completion); |
| 614 | if (is_async(dev)) { |
| 615 | get_device(dev); |
| 616 | async_schedule(async_resume, dev); |
| 617 | } |
| 618 | } |
| 619 | |
Rafael J. Wysocki | 8a43a9a | 2010-12-16 00:50:30 +0100 | [diff] [blame] | 620 | while (!list_empty(&dpm_suspended_list)) { |
| 621 | dev = to_device(dpm_suspended_list.next); |
Rafael J. Wysocki | 1eede07 | 2008-05-20 23:00:01 +0200 | [diff] [blame] | 622 | get_device(dev); |
Rafael J. Wysocki | 5b219a5 | 2010-12-16 00:51:08 +0100 | [diff] [blame] | 623 | if (!is_async(dev)) { |
Rafael J. Wysocki | 1eede07 | 2008-05-20 23:00:01 +0200 | [diff] [blame] | 624 | int error; |
| 625 | |
Rafael J. Wysocki | 1eede07 | 2008-05-20 23:00:01 +0200 | [diff] [blame] | 626 | mutex_unlock(&dpm_list_mtx); |
| 627 | |
Rafael J. Wysocki | 97df8c1 | 2010-01-23 22:25:31 +0100 | [diff] [blame] | 628 | error = device_resume(dev, state, false); |
Rafael J. Wysocki | 1eede07 | 2008-05-20 23:00:01 +0200 | [diff] [blame] | 629 | if (error) |
| 630 | pm_dev_err(dev, state, "", error); |
Rafael J. Wysocki | 5b219a5 | 2010-12-16 00:51:08 +0100 | [diff] [blame] | 631 | |
| 632 | mutex_lock(&dpm_list_mtx); |
Rafael J. Wysocki | 1eede07 | 2008-05-20 23:00:01 +0200 | [diff] [blame] | 633 | } |
| 634 | if (!list_empty(&dev->power.entry)) |
Rafael J. Wysocki | 8a43a9a | 2010-12-16 00:50:30 +0100 | [diff] [blame] | 635 | list_move_tail(&dev->power.entry, &dpm_prepared_list); |
Rafael J. Wysocki | 1eede07 | 2008-05-20 23:00:01 +0200 | [diff] [blame] | 636 | put_device(dev); |
Alan Stern | cd59abf | 2007-09-21 15:36:56 -0400 | [diff] [blame] | 637 | } |
Rafael J. Wysocki | 1eede07 | 2008-05-20 23:00:01 +0200 | [diff] [blame] | 638 | mutex_unlock(&dpm_list_mtx); |
Rafael J. Wysocki | 5af84b8 | 2010-01-23 22:23:32 +0100 | [diff] [blame] | 639 | async_synchronize_full(); |
Rafael J. Wysocki | ecf762b | 2009-12-18 01:57:47 +0100 | [diff] [blame] | 640 | dpm_show_time(starttime, state, NULL); |
Rafael J. Wysocki | 1eede07 | 2008-05-20 23:00:01 +0200 | [diff] [blame] | 641 | } |
| 642 | |
| 643 | /** |
Rafael J. Wysocki | 20d652d | 2009-08-20 20:25:52 +0200 | [diff] [blame] | 644 | * device_complete - Complete a PM transition for given device. |
| 645 | * @dev: Device to handle. |
| 646 | * @state: PM transition of the system being carried out. |
Rafael J. Wysocki | 1eede07 | 2008-05-20 23:00:01 +0200 | [diff] [blame] | 647 | */ |
Alan Stern | d161630 | 2009-05-24 22:05:42 +0200 | [diff] [blame] | 648 | static void device_complete(struct device *dev, pm_message_t state) |
Rafael J. Wysocki | 1eede07 | 2008-05-20 23:00:01 +0200 | [diff] [blame] | 649 | { |
Greg Kroah-Hartman | 8e9394c | 2010-02-17 10:57:05 -0800 | [diff] [blame] | 650 | device_lock(dev); |
Rafael J. Wysocki | 1eede07 | 2008-05-20 23:00:01 +0200 | [diff] [blame] | 651 | |
Rafael J. Wysocki | 564b905 | 2011-06-23 01:52:55 +0200 | [diff] [blame] | 652 | if (dev->pm_domain) { |
Rafael J. Wysocki | 7538e3d | 2011-02-16 21:53:17 +0100 | [diff] [blame] | 653 | pm_dev_dbg(dev, state, "completing power domain "); |
Rafael J. Wysocki | 564b905 | 2011-06-23 01:52:55 +0200 | [diff] [blame] | 654 | if (dev->pm_domain->ops.complete) |
| 655 | dev->pm_domain->ops.complete(dev); |
Rafael J. Wysocki | 4d27e9d | 2011-04-29 00:35:50 +0200 | [diff] [blame] | 656 | } else if (dev->type && dev->type->pm) { |
Rafael J. Wysocki | 1eede07 | 2008-05-20 23:00:01 +0200 | [diff] [blame] | 657 | pm_dev_dbg(dev, state, "completing type "); |
Rafael J. Wysocki | 9659cc0 | 2011-02-18 23:20:21 +0100 | [diff] [blame] | 658 | if (dev->type->pm->complete) |
| 659 | dev->type->pm->complete(dev); |
| 660 | } else if (dev->class && dev->class->pm) { |
| 661 | pm_dev_dbg(dev, state, "completing class "); |
| 662 | if (dev->class->pm->complete) |
| 663 | dev->class->pm->complete(dev); |
| 664 | } else if (dev->bus && dev->bus->pm) { |
Rafael J. Wysocki | 1eede07 | 2008-05-20 23:00:01 +0200 | [diff] [blame] | 665 | pm_dev_dbg(dev, state, "completing "); |
Rafael J. Wysocki | 9659cc0 | 2011-02-18 23:20:21 +0100 | [diff] [blame] | 666 | if (dev->bus->pm->complete) |
| 667 | dev->bus->pm->complete(dev); |
Rafael J. Wysocki | 1eede07 | 2008-05-20 23:00:01 +0200 | [diff] [blame] | 668 | } |
| 669 | |
Greg Kroah-Hartman | 8e9394c | 2010-02-17 10:57:05 -0800 | [diff] [blame] | 670 | device_unlock(dev); |
Rafael J. Wysocki | 1eede07 | 2008-05-20 23:00:01 +0200 | [diff] [blame] | 671 | } |
| 672 | |
| 673 | /** |
Rafael J. Wysocki | 20d652d | 2009-08-20 20:25:52 +0200 | [diff] [blame] | 674 | * dpm_complete - Complete a PM transition for all non-sysdev devices. |
| 675 | * @state: PM transition of the system being carried out. |
Rafael J. Wysocki | 1eede07 | 2008-05-20 23:00:01 +0200 | [diff] [blame] | 676 | * |
Rafael J. Wysocki | 20d652d | 2009-08-20 20:25:52 +0200 | [diff] [blame] | 677 | * Execute the ->complete() callbacks for all devices whose PM status is not |
| 678 | * DPM_ON (this allows new devices to be registered). |
Rafael J. Wysocki | 1eede07 | 2008-05-20 23:00:01 +0200 | [diff] [blame] | 679 | */ |
Rafael J. Wysocki | 91e7c75 | 2011-05-17 23:26:00 +0200 | [diff] [blame] | 680 | void dpm_complete(pm_message_t state) |
Rafael J. Wysocki | 1eede07 | 2008-05-20 23:00:01 +0200 | [diff] [blame] | 681 | { |
| 682 | struct list_head list; |
| 683 | |
Rafael J. Wysocki | 91e7c75 | 2011-05-17 23:26:00 +0200 | [diff] [blame] | 684 | might_sleep(); |
| 685 | |
Rafael J. Wysocki | 1eede07 | 2008-05-20 23:00:01 +0200 | [diff] [blame] | 686 | INIT_LIST_HEAD(&list); |
| 687 | mutex_lock(&dpm_list_mtx); |
Rafael J. Wysocki | 8a43a9a | 2010-12-16 00:50:30 +0100 | [diff] [blame] | 688 | while (!list_empty(&dpm_prepared_list)) { |
| 689 | struct device *dev = to_device(dpm_prepared_list.prev); |
Rafael J. Wysocki | 1eede07 | 2008-05-20 23:00:01 +0200 | [diff] [blame] | 690 | |
| 691 | get_device(dev); |
Alan Stern | f76b168 | 2011-06-18 20:22:23 +0200 | [diff] [blame] | 692 | dev->power.is_prepared = false; |
Rafael J. Wysocki | 5b219a5 | 2010-12-16 00:51:08 +0100 | [diff] [blame] | 693 | list_move(&dev->power.entry, &list); |
| 694 | mutex_unlock(&dpm_list_mtx); |
Rafael J. Wysocki | 1eede07 | 2008-05-20 23:00:01 +0200 | [diff] [blame] | 695 | |
Rafael J. Wysocki | 5b219a5 | 2010-12-16 00:51:08 +0100 | [diff] [blame] | 696 | device_complete(dev, state); |
Rafael J. Wysocki | 1eede07 | 2008-05-20 23:00:01 +0200 | [diff] [blame] | 697 | |
Rafael J. Wysocki | 5b219a5 | 2010-12-16 00:51:08 +0100 | [diff] [blame] | 698 | mutex_lock(&dpm_list_mtx); |
Rafael J. Wysocki | 1eede07 | 2008-05-20 23:00:01 +0200 | [diff] [blame] | 699 | put_device(dev); |
| 700 | } |
| 701 | list_splice(&list, &dpm_list); |
Alan Stern | cd59abf | 2007-09-21 15:36:56 -0400 | [diff] [blame] | 702 | mutex_unlock(&dpm_list_mtx); |
| 703 | } |
| 704 | |
Rafael J. Wysocki | 775b64d | 2008-01-12 20:40:46 +0100 | [diff] [blame] | 705 | /** |
Rafael J. Wysocki | 20d652d | 2009-08-20 20:25:52 +0200 | [diff] [blame] | 706 | * dpm_resume_end - Execute "resume" callbacks and complete system transition. |
| 707 | * @state: PM transition of the system being carried out. |
Alan Stern | cd59abf | 2007-09-21 15:36:56 -0400 | [diff] [blame] | 708 | * |
Rafael J. Wysocki | 20d652d | 2009-08-20 20:25:52 +0200 | [diff] [blame] | 709 | * Execute "resume" callbacks for all devices and complete the PM transition of |
| 710 | * the system. |
Alan Stern | cd59abf | 2007-09-21 15:36:56 -0400 | [diff] [blame] | 711 | */ |
Alan Stern | d161630 | 2009-05-24 22:05:42 +0200 | [diff] [blame] | 712 | void dpm_resume_end(pm_message_t state) |
Alan Stern | cd59abf | 2007-09-21 15:36:56 -0400 | [diff] [blame] | 713 | { |
Rafael J. Wysocki | 1eede07 | 2008-05-20 23:00:01 +0200 | [diff] [blame] | 714 | dpm_resume(state); |
| 715 | dpm_complete(state); |
Alan Stern | cd59abf | 2007-09-21 15:36:56 -0400 | [diff] [blame] | 716 | } |
Alan Stern | d161630 | 2009-05-24 22:05:42 +0200 | [diff] [blame] | 717 | EXPORT_SYMBOL_GPL(dpm_resume_end); |
Alan Stern | cd59abf | 2007-09-21 15:36:56 -0400 | [diff] [blame] | 718 | |
| 719 | |
Alan Stern | cd59abf | 2007-09-21 15:36:56 -0400 | [diff] [blame] | 720 | /*------------------------- Suspend routines -------------------------*/ |
| 721 | |
Rafael J. Wysocki | 1eede07 | 2008-05-20 23:00:01 +0200 | [diff] [blame] | 722 | /** |
Rafael J. Wysocki | 20d652d | 2009-08-20 20:25:52 +0200 | [diff] [blame] | 723 | * resume_event - Return a "resume" message for given "suspend" sleep state. |
| 724 | * @sleep_state: PM message representing a sleep state. |
| 725 | * |
| 726 | * Return a PM message representing the resume event corresponding to given |
| 727 | * sleep state. |
Rafael J. Wysocki | 1eede07 | 2008-05-20 23:00:01 +0200 | [diff] [blame] | 728 | */ |
| 729 | static pm_message_t resume_event(pm_message_t sleep_state) |
Alan Stern | cd59abf | 2007-09-21 15:36:56 -0400 | [diff] [blame] | 730 | { |
Rafael J. Wysocki | 1eede07 | 2008-05-20 23:00:01 +0200 | [diff] [blame] | 731 | switch (sleep_state.event) { |
| 732 | case PM_EVENT_SUSPEND: |
| 733 | return PMSG_RESUME; |
| 734 | case PM_EVENT_FREEZE: |
| 735 | case PM_EVENT_QUIESCE: |
| 736 | return PMSG_RECOVER; |
| 737 | case PM_EVENT_HIBERNATE: |
| 738 | return PMSG_RESTORE; |
Alan Stern | cd59abf | 2007-09-21 15:36:56 -0400 | [diff] [blame] | 739 | } |
Rafael J. Wysocki | 1eede07 | 2008-05-20 23:00:01 +0200 | [diff] [blame] | 740 | return PMSG_ON; |
Alan Stern | cd59abf | 2007-09-21 15:36:56 -0400 | [diff] [blame] | 741 | } |
| 742 | |
| 743 | /** |
Rafael J. Wysocki | 20d652d | 2009-08-20 20:25:52 +0200 | [diff] [blame] | 744 | * device_suspend_noirq - Execute a "late suspend" callback for given device. |
| 745 | * @dev: Device to handle. |
| 746 | * @state: PM transition of the system being carried out. |
Rafael J. Wysocki | 775b64d | 2008-01-12 20:40:46 +0100 | [diff] [blame] | 747 | * |
Rafael J. Wysocki | 20d652d | 2009-08-20 20:25:52 +0200 | [diff] [blame] | 748 | * The driver of @dev will not receive interrupts while this function is being |
| 749 | * executed. |
Rafael J. Wysocki | 775b64d | 2008-01-12 20:40:46 +0100 | [diff] [blame] | 750 | */ |
Alan Stern | d161630 | 2009-05-24 22:05:42 +0200 | [diff] [blame] | 751 | static int device_suspend_noirq(struct device *dev, pm_message_t state) |
Rafael J. Wysocki | 775b64d | 2008-01-12 20:40:46 +0100 | [diff] [blame] | 752 | { |
Rafael J. Wysocki | 9659cc0 | 2011-02-18 23:20:21 +0100 | [diff] [blame] | 753 | int error; |
Dominik Brodowski | e7176a3 | 2010-03-15 21:43:11 +0100 | [diff] [blame] | 754 | |
Rafael J. Wysocki | 564b905 | 2011-06-23 01:52:55 +0200 | [diff] [blame] | 755 | if (dev->pm_domain) { |
Rafael J. Wysocki | 4d27e9d | 2011-04-29 00:35:50 +0200 | [diff] [blame] | 756 | pm_dev_dbg(dev, state, "LATE power domain "); |
Rafael J. Wysocki | 564b905 | 2011-06-23 01:52:55 +0200 | [diff] [blame] | 757 | error = pm_noirq_op(dev, &dev->pm_domain->ops, state); |
Rafael J. Wysocki | 4d27e9d | 2011-04-29 00:35:50 +0200 | [diff] [blame] | 758 | if (error) |
| 759 | return error; |
| 760 | } else if (dev->type && dev->type->pm) { |
Dominik Brodowski | e7176a3 | 2010-03-15 21:43:11 +0100 | [diff] [blame] | 761 | pm_dev_dbg(dev, state, "LATE type "); |
| 762 | error = pm_noirq_op(dev, dev->type->pm, state); |
| 763 | if (error) |
Rafael J. Wysocki | 9659cc0 | 2011-02-18 23:20:21 +0100 | [diff] [blame] | 764 | return error; |
| 765 | } else if (dev->class && dev->class->pm) { |
| 766 | pm_dev_dbg(dev, state, "LATE class "); |
| 767 | error = pm_noirq_op(dev, dev->class->pm, state); |
| 768 | if (error) |
| 769 | return error; |
| 770 | } else if (dev->bus && dev->bus->pm) { |
Rafael J. Wysocki | 1eede07 | 2008-05-20 23:00:01 +0200 | [diff] [blame] | 771 | pm_dev_dbg(dev, state, "LATE "); |
| 772 | error = pm_noirq_op(dev, dev->bus->pm, state); |
Rafael J. Wysocki | 7538e3d | 2011-02-16 21:53:17 +0100 | [diff] [blame] | 773 | if (error) |
Rafael J. Wysocki | 9659cc0 | 2011-02-18 23:20:21 +0100 | [diff] [blame] | 774 | return error; |
Rafael J. Wysocki | 7538e3d | 2011-02-16 21:53:17 +0100 | [diff] [blame] | 775 | } |
| 776 | |
Rafael J. Wysocki | 9659cc0 | 2011-02-18 23:20:21 +0100 | [diff] [blame] | 777 | return 0; |
Rafael J. Wysocki | 775b64d | 2008-01-12 20:40:46 +0100 | [diff] [blame] | 778 | } |
| 779 | |
| 780 | /** |
Rafael J. Wysocki | 20d652d | 2009-08-20 20:25:52 +0200 | [diff] [blame] | 781 | * dpm_suspend_noirq - Execute "late suspend" callbacks for non-sysdev devices. |
| 782 | * @state: PM transition of the system being carried out. |
Rafael J. Wysocki | 775b64d | 2008-01-12 20:40:46 +0100 | [diff] [blame] | 783 | * |
Rafael J. Wysocki | 20d652d | 2009-08-20 20:25:52 +0200 | [diff] [blame] | 784 | * Prevent device drivers from receiving interrupts and call the "noirq" suspend |
| 785 | * handlers for all non-sysdev devices. |
Rafael J. Wysocki | 775b64d | 2008-01-12 20:40:46 +0100 | [diff] [blame] | 786 | */ |
Alan Stern | d161630 | 2009-05-24 22:05:42 +0200 | [diff] [blame] | 787 | int dpm_suspend_noirq(pm_message_t state) |
Rafael J. Wysocki | 775b64d | 2008-01-12 20:40:46 +0100 | [diff] [blame] | 788 | { |
Rafael J. Wysocki | ecf762b | 2009-12-18 01:57:47 +0100 | [diff] [blame] | 789 | ktime_t starttime = ktime_get(); |
Rafael J. Wysocki | 775b64d | 2008-01-12 20:40:46 +0100 | [diff] [blame] | 790 | int error = 0; |
| 791 | |
Rafael J. Wysocki | 2ed8d2b | 2009-03-16 22:34:06 +0100 | [diff] [blame] | 792 | suspend_device_irqs(); |
Rafael J. Wysocki | 32bdfac | 2009-05-24 21:15:07 +0200 | [diff] [blame] | 793 | mutex_lock(&dpm_list_mtx); |
Rafael J. Wysocki | 8a43a9a | 2010-12-16 00:50:30 +0100 | [diff] [blame] | 794 | while (!list_empty(&dpm_suspended_list)) { |
| 795 | struct device *dev = to_device(dpm_suspended_list.prev); |
Rafael J. Wysocki | d08a5ac | 2010-11-11 01:50:53 +0100 | [diff] [blame] | 796 | |
| 797 | get_device(dev); |
| 798 | mutex_unlock(&dpm_list_mtx); |
| 799 | |
Alan Stern | d161630 | 2009-05-24 22:05:42 +0200 | [diff] [blame] | 800 | error = device_suspend_noirq(dev, state); |
Rafael J. Wysocki | d08a5ac | 2010-11-11 01:50:53 +0100 | [diff] [blame] | 801 | |
| 802 | mutex_lock(&dpm_list_mtx); |
Rafael J. Wysocki | 775b64d | 2008-01-12 20:40:46 +0100 | [diff] [blame] | 803 | if (error) { |
Rafael J. Wysocki | 1eede07 | 2008-05-20 23:00:01 +0200 | [diff] [blame] | 804 | pm_dev_err(dev, state, " late", error); |
Rafael J. Wysocki | d08a5ac | 2010-11-11 01:50:53 +0100 | [diff] [blame] | 805 | put_device(dev); |
Rafael J. Wysocki | 775b64d | 2008-01-12 20:40:46 +0100 | [diff] [blame] | 806 | break; |
| 807 | } |
Rafael J. Wysocki | d08a5ac | 2010-11-11 01:50:53 +0100 | [diff] [blame] | 808 | if (!list_empty(&dev->power.entry)) |
Rafael J. Wysocki | 8a43a9a | 2010-12-16 00:50:30 +0100 | [diff] [blame] | 809 | list_move(&dev->power.entry, &dpm_noirq_list); |
Rafael J. Wysocki | d08a5ac | 2010-11-11 01:50:53 +0100 | [diff] [blame] | 810 | put_device(dev); |
Rafael J. Wysocki | 775b64d | 2008-01-12 20:40:46 +0100 | [diff] [blame] | 811 | } |
Rafael J. Wysocki | 32bdfac | 2009-05-24 21:15:07 +0200 | [diff] [blame] | 812 | mutex_unlock(&dpm_list_mtx); |
Rafael J. Wysocki | 775b64d | 2008-01-12 20:40:46 +0100 | [diff] [blame] | 813 | if (error) |
Alan Stern | d161630 | 2009-05-24 22:05:42 +0200 | [diff] [blame] | 814 | dpm_resume_noirq(resume_event(state)); |
Rafael J. Wysocki | ecf762b | 2009-12-18 01:57:47 +0100 | [diff] [blame] | 815 | else |
| 816 | dpm_show_time(starttime, state, "late"); |
Rafael J. Wysocki | 775b64d | 2008-01-12 20:40:46 +0100 | [diff] [blame] | 817 | return error; |
| 818 | } |
Alan Stern | d161630 | 2009-05-24 22:05:42 +0200 | [diff] [blame] | 819 | EXPORT_SYMBOL_GPL(dpm_suspend_noirq); |
Rafael J. Wysocki | 775b64d | 2008-01-12 20:40:46 +0100 | [diff] [blame] | 820 | |
| 821 | /** |
Rafael J. Wysocki | 875ab0b | 2009-12-18 01:57:31 +0100 | [diff] [blame] | 822 | * legacy_suspend - Execute a legacy (bus or class) suspend callback for device. |
Randy Dunlap | 0a88422 | 2010-01-08 14:42:57 -0800 | [diff] [blame] | 823 | * @dev: Device to suspend. |
| 824 | * @state: PM transition of the system being carried out. |
| 825 | * @cb: Suspend callback to execute. |
Rafael J. Wysocki | 875ab0b | 2009-12-18 01:57:31 +0100 | [diff] [blame] | 826 | */ |
| 827 | static int legacy_suspend(struct device *dev, pm_message_t state, |
| 828 | int (*cb)(struct device *dev, pm_message_t state)) |
| 829 | { |
| 830 | int error; |
| 831 | ktime_t calltime; |
| 832 | |
| 833 | calltime = initcall_debug_start(dev); |
| 834 | |
| 835 | error = cb(dev, state); |
| 836 | suspend_report_result(cb, error); |
| 837 | |
| 838 | initcall_debug_report(dev, calltime, error); |
| 839 | |
| 840 | return error; |
| 841 | } |
| 842 | |
| 843 | /** |
Rafael J. Wysocki | 20d652d | 2009-08-20 20:25:52 +0200 | [diff] [blame] | 844 | * device_suspend - Execute "suspend" callbacks for given device. |
| 845 | * @dev: Device to handle. |
| 846 | * @state: PM transition of the system being carried out. |
Rafael J. Wysocki | 5af84b8 | 2010-01-23 22:23:32 +0100 | [diff] [blame] | 847 | * @async: If true, the device is being suspended asynchronously. |
Alan Stern | cd59abf | 2007-09-21 15:36:56 -0400 | [diff] [blame] | 848 | */ |
Rafael J. Wysocki | 5af84b8 | 2010-01-23 22:23:32 +0100 | [diff] [blame] | 849 | static int __device_suspend(struct device *dev, pm_message_t state, bool async) |
Alan Stern | cd59abf | 2007-09-21 15:36:56 -0400 | [diff] [blame] | 850 | { |
| 851 | int error = 0; |
| 852 | |
Rafael J. Wysocki | 5af84b8 | 2010-01-23 22:23:32 +0100 | [diff] [blame] | 853 | dpm_wait_for_children(dev, async); |
Rafael J. Wysocki | 7a8d37a | 2008-02-25 00:35:04 +0100 | [diff] [blame] | 854 | |
Rafael J. Wysocki | 5af84b8 | 2010-01-23 22:23:32 +0100 | [diff] [blame] | 855 | if (async_error) |
Rafael J. Wysocki | 1e2ef05 | 2011-07-06 10:51:58 +0200 | [diff] [blame^] | 856 | return 0; |
| 857 | |
| 858 | pm_runtime_get_noresume(dev); |
| 859 | if (pm_runtime_barrier(dev) && device_may_wakeup(dev)) |
| 860 | pm_wakeup_event(dev, 0); |
Rafael J. Wysocki | 5af84b8 | 2010-01-23 22:23:32 +0100 | [diff] [blame] | 861 | |
Rafael J. Wysocki | d83f905 | 2010-12-03 23:14:26 +0100 | [diff] [blame] | 862 | if (pm_wakeup_pending()) { |
Rafael J. Wysocki | 1e2ef05 | 2011-07-06 10:51:58 +0200 | [diff] [blame^] | 863 | pm_runtime_put_sync(dev); |
Rafael J. Wysocki | d83f905 | 2010-12-03 23:14:26 +0100 | [diff] [blame] | 864 | async_error = -EBUSY; |
Rafael J. Wysocki | 1e2ef05 | 2011-07-06 10:51:58 +0200 | [diff] [blame^] | 865 | return 0; |
Rafael J. Wysocki | d83f905 | 2010-12-03 23:14:26 +0100 | [diff] [blame] | 866 | } |
| 867 | |
Rafael J. Wysocki | 1e2ef05 | 2011-07-06 10:51:58 +0200 | [diff] [blame^] | 868 | device_lock(dev); |
| 869 | |
Rafael J. Wysocki | 564b905 | 2011-06-23 01:52:55 +0200 | [diff] [blame] | 870 | if (dev->pm_domain) { |
Rafael J. Wysocki | 4d27e9d | 2011-04-29 00:35:50 +0200 | [diff] [blame] | 871 | pm_dev_dbg(dev, state, "power domain "); |
Rafael J. Wysocki | 564b905 | 2011-06-23 01:52:55 +0200 | [diff] [blame] | 872 | error = pm_op(dev, &dev->pm_domain->ops, state); |
Rafael J. Wysocki | 4d27e9d | 2011-04-29 00:35:50 +0200 | [diff] [blame] | 873 | goto End; |
| 874 | } |
| 875 | |
Rafael J. Wysocki | 9659cc0 | 2011-02-18 23:20:21 +0100 | [diff] [blame] | 876 | if (dev->type && dev->type->pm) { |
| 877 | pm_dev_dbg(dev, state, "type "); |
| 878 | error = pm_op(dev, dev->type->pm, state); |
Rafael J. Wysocki | 4d27e9d | 2011-04-29 00:35:50 +0200 | [diff] [blame] | 879 | goto End; |
Rafael J. Wysocki | 9659cc0 | 2011-02-18 23:20:21 +0100 | [diff] [blame] | 880 | } |
| 881 | |
Rafael J. Wysocki | 1eede07 | 2008-05-20 23:00:01 +0200 | [diff] [blame] | 882 | if (dev->class) { |
| 883 | if (dev->class->pm) { |
| 884 | pm_dev_dbg(dev, state, "class "); |
| 885 | error = pm_op(dev, dev->class->pm, state); |
Rafael J. Wysocki | 4d27e9d | 2011-04-29 00:35:50 +0200 | [diff] [blame] | 886 | goto End; |
Rafael J. Wysocki | 1eede07 | 2008-05-20 23:00:01 +0200 | [diff] [blame] | 887 | } else if (dev->class->suspend) { |
| 888 | pm_dev_dbg(dev, state, "legacy class "); |
Rafael J. Wysocki | 875ab0b | 2009-12-18 01:57:31 +0100 | [diff] [blame] | 889 | error = legacy_suspend(dev, state, dev->class->suspend); |
Rafael J. Wysocki | 4d27e9d | 2011-04-29 00:35:50 +0200 | [diff] [blame] | 890 | goto End; |
Rafael J. Wysocki | 1eede07 | 2008-05-20 23:00:01 +0200 | [diff] [blame] | 891 | } |
Alan Stern | cd59abf | 2007-09-21 15:36:56 -0400 | [diff] [blame] | 892 | } |
| 893 | |
Rafael J. Wysocki | 1eede07 | 2008-05-20 23:00:01 +0200 | [diff] [blame] | 894 | if (dev->bus) { |
| 895 | if (dev->bus->pm) { |
| 896 | pm_dev_dbg(dev, state, ""); |
Rafael J. Wysocki | adf0949 | 2008-10-06 22:46:05 +0200 | [diff] [blame] | 897 | error = pm_op(dev, dev->bus->pm, state); |
Rafael J. Wysocki | 1eede07 | 2008-05-20 23:00:01 +0200 | [diff] [blame] | 898 | } else if (dev->bus->suspend) { |
| 899 | pm_dev_dbg(dev, state, "legacy "); |
Rafael J. Wysocki | 875ab0b | 2009-12-18 01:57:31 +0100 | [diff] [blame] | 900 | error = legacy_suspend(dev, state, dev->bus->suspend); |
Rafael J. Wysocki | 1eede07 | 2008-05-20 23:00:01 +0200 | [diff] [blame] | 901 | } |
Rafael J. Wysocki | 7538e3d | 2011-02-16 21:53:17 +0100 | [diff] [blame] | 902 | } |
| 903 | |
Rafael J. Wysocki | 1eede07 | 2008-05-20 23:00:01 +0200 | [diff] [blame] | 904 | End: |
Alan Stern | 6d0e0e8 | 2011-06-18 22:42:09 +0200 | [diff] [blame] | 905 | dev->power.is_suspended = !error; |
| 906 | |
Greg Kroah-Hartman | 8e9394c | 2010-02-17 10:57:05 -0800 | [diff] [blame] | 907 | device_unlock(dev); |
Rafael J. Wysocki | 5af84b8 | 2010-01-23 22:23:32 +0100 | [diff] [blame] | 908 | complete_all(&dev->power.completion); |
Rafael J. Wysocki | 7a8d37a | 2008-02-25 00:35:04 +0100 | [diff] [blame] | 909 | |
Rafael J. Wysocki | 1e2ef05 | 2011-07-06 10:51:58 +0200 | [diff] [blame^] | 910 | if (error) { |
| 911 | pm_runtime_put_sync(dev); |
Rafael J. Wysocki | 098dff7 | 2010-09-22 22:10:57 +0200 | [diff] [blame] | 912 | async_error = error; |
Rafael J. Wysocki | 1e2ef05 | 2011-07-06 10:51:58 +0200 | [diff] [blame^] | 913 | } else if (dev->power.is_suspended) { |
| 914 | __pm_runtime_disable(dev, false); |
| 915 | } |
Rafael J. Wysocki | 098dff7 | 2010-09-22 22:10:57 +0200 | [diff] [blame] | 916 | |
Alan Stern | cd59abf | 2007-09-21 15:36:56 -0400 | [diff] [blame] | 917 | return error; |
| 918 | } |
| 919 | |
Rafael J. Wysocki | 5af84b8 | 2010-01-23 22:23:32 +0100 | [diff] [blame] | 920 | static void async_suspend(void *data, async_cookie_t cookie) |
| 921 | { |
| 922 | struct device *dev = (struct device *)data; |
| 923 | int error; |
| 924 | |
| 925 | error = __device_suspend(dev, pm_transition, true); |
Rafael J. Wysocki | 098dff7 | 2010-09-22 22:10:57 +0200 | [diff] [blame] | 926 | if (error) |
Rafael J. Wysocki | 5af84b8 | 2010-01-23 22:23:32 +0100 | [diff] [blame] | 927 | pm_dev_err(dev, pm_transition, " async", error); |
Rafael J. Wysocki | 5af84b8 | 2010-01-23 22:23:32 +0100 | [diff] [blame] | 928 | |
| 929 | put_device(dev); |
| 930 | } |
| 931 | |
| 932 | static int device_suspend(struct device *dev) |
| 933 | { |
| 934 | INIT_COMPLETION(dev->power.completion); |
| 935 | |
Rafael J. Wysocki | 0e06b4a | 2010-01-23 22:25:15 +0100 | [diff] [blame] | 936 | if (pm_async_enabled && dev->power.async_suspend) { |
Rafael J. Wysocki | 5af84b8 | 2010-01-23 22:23:32 +0100 | [diff] [blame] | 937 | get_device(dev); |
| 938 | async_schedule(async_suspend, dev); |
| 939 | return 0; |
| 940 | } |
| 941 | |
| 942 | return __device_suspend(dev, pm_transition, false); |
| 943 | } |
| 944 | |
Alan Stern | cd59abf | 2007-09-21 15:36:56 -0400 | [diff] [blame] | 945 | /** |
Rafael J. Wysocki | 20d652d | 2009-08-20 20:25:52 +0200 | [diff] [blame] | 946 | * dpm_suspend - Execute "suspend" callbacks for all non-sysdev devices. |
| 947 | * @state: PM transition of the system being carried out. |
Alan Stern | cd59abf | 2007-09-21 15:36:56 -0400 | [diff] [blame] | 948 | */ |
Rafael J. Wysocki | 91e7c75 | 2011-05-17 23:26:00 +0200 | [diff] [blame] | 949 | int dpm_suspend(pm_message_t state) |
Alan Stern | cd59abf | 2007-09-21 15:36:56 -0400 | [diff] [blame] | 950 | { |
Rafael J. Wysocki | ecf762b | 2009-12-18 01:57:47 +0100 | [diff] [blame] | 951 | ktime_t starttime = ktime_get(); |
Alan Stern | cd59abf | 2007-09-21 15:36:56 -0400 | [diff] [blame] | 952 | int error = 0; |
| 953 | |
Rafael J. Wysocki | 91e7c75 | 2011-05-17 23:26:00 +0200 | [diff] [blame] | 954 | might_sleep(); |
| 955 | |
Alan Stern | cd59abf | 2007-09-21 15:36:56 -0400 | [diff] [blame] | 956 | mutex_lock(&dpm_list_mtx); |
Rafael J. Wysocki | 5af84b8 | 2010-01-23 22:23:32 +0100 | [diff] [blame] | 957 | pm_transition = state; |
| 958 | async_error = 0; |
Rafael J. Wysocki | 8a43a9a | 2010-12-16 00:50:30 +0100 | [diff] [blame] | 959 | while (!list_empty(&dpm_prepared_list)) { |
| 960 | struct device *dev = to_device(dpm_prepared_list.prev); |
Alan Stern | cd59abf | 2007-09-21 15:36:56 -0400 | [diff] [blame] | 961 | |
Rafael J. Wysocki | 1eede07 | 2008-05-20 23:00:01 +0200 | [diff] [blame] | 962 | get_device(dev); |
Rafael J. Wysocki | 775b64d | 2008-01-12 20:40:46 +0100 | [diff] [blame] | 963 | mutex_unlock(&dpm_list_mtx); |
Rafael J. Wysocki | 1eede07 | 2008-05-20 23:00:01 +0200 | [diff] [blame] | 964 | |
Rafael J. Wysocki | 5af84b8 | 2010-01-23 22:23:32 +0100 | [diff] [blame] | 965 | error = device_suspend(dev); |
Rafael J. Wysocki | 1eede07 | 2008-05-20 23:00:01 +0200 | [diff] [blame] | 966 | |
Alan Stern | 1b3cbec | 2008-02-29 11:50:22 -0500 | [diff] [blame] | 967 | mutex_lock(&dpm_list_mtx); |
Rafael J. Wysocki | 775b64d | 2008-01-12 20:40:46 +0100 | [diff] [blame] | 968 | if (error) { |
Rafael J. Wysocki | 1eede07 | 2008-05-20 23:00:01 +0200 | [diff] [blame] | 969 | pm_dev_err(dev, state, "", error); |
| 970 | put_device(dev); |
Rafael J. Wysocki | 775b64d | 2008-01-12 20:40:46 +0100 | [diff] [blame] | 971 | break; |
| 972 | } |
Rafael J. Wysocki | 7a8d37a | 2008-02-25 00:35:04 +0100 | [diff] [blame] | 973 | if (!list_empty(&dev->power.entry)) |
Rafael J. Wysocki | 8a43a9a | 2010-12-16 00:50:30 +0100 | [diff] [blame] | 974 | list_move(&dev->power.entry, &dpm_suspended_list); |
Rafael J. Wysocki | 1eede07 | 2008-05-20 23:00:01 +0200 | [diff] [blame] | 975 | put_device(dev); |
Rafael J. Wysocki | 5af84b8 | 2010-01-23 22:23:32 +0100 | [diff] [blame] | 976 | if (async_error) |
| 977 | break; |
Rafael J. Wysocki | 775b64d | 2008-01-12 20:40:46 +0100 | [diff] [blame] | 978 | } |
| 979 | mutex_unlock(&dpm_list_mtx); |
Rafael J. Wysocki | 5af84b8 | 2010-01-23 22:23:32 +0100 | [diff] [blame] | 980 | async_synchronize_full(); |
| 981 | if (!error) |
| 982 | error = async_error; |
Rafael J. Wysocki | ecf762b | 2009-12-18 01:57:47 +0100 | [diff] [blame] | 983 | if (!error) |
| 984 | dpm_show_time(starttime, state, NULL); |
Rafael J. Wysocki | 1eede07 | 2008-05-20 23:00:01 +0200 | [diff] [blame] | 985 | return error; |
| 986 | } |
| 987 | |
| 988 | /** |
Rafael J. Wysocki | 20d652d | 2009-08-20 20:25:52 +0200 | [diff] [blame] | 989 | * device_prepare - Prepare a device for system power transition. |
| 990 | * @dev: Device to handle. |
| 991 | * @state: PM transition of the system being carried out. |
| 992 | * |
| 993 | * Execute the ->prepare() callback(s) for given device. No new children of the |
| 994 | * device may be registered after this function has returned. |
Rafael J. Wysocki | 1eede07 | 2008-05-20 23:00:01 +0200 | [diff] [blame] | 995 | */ |
Alan Stern | d161630 | 2009-05-24 22:05:42 +0200 | [diff] [blame] | 996 | static int device_prepare(struct device *dev, pm_message_t state) |
Rafael J. Wysocki | 1eede07 | 2008-05-20 23:00:01 +0200 | [diff] [blame] | 997 | { |
| 998 | int error = 0; |
| 999 | |
Greg Kroah-Hartman | 8e9394c | 2010-02-17 10:57:05 -0800 | [diff] [blame] | 1000 | device_lock(dev); |
Rafael J. Wysocki | 1eede07 | 2008-05-20 23:00:01 +0200 | [diff] [blame] | 1001 | |
Rafael J. Wysocki | 564b905 | 2011-06-23 01:52:55 +0200 | [diff] [blame] | 1002 | if (dev->pm_domain) { |
Rafael J. Wysocki | 4d27e9d | 2011-04-29 00:35:50 +0200 | [diff] [blame] | 1003 | pm_dev_dbg(dev, state, "preparing power domain "); |
Rafael J. Wysocki | 564b905 | 2011-06-23 01:52:55 +0200 | [diff] [blame] | 1004 | if (dev->pm_domain->ops.prepare) |
| 1005 | error = dev->pm_domain->ops.prepare(dev); |
| 1006 | suspend_report_result(dev->pm_domain->ops.prepare, error); |
Rafael J. Wysocki | 4d27e9d | 2011-04-29 00:35:50 +0200 | [diff] [blame] | 1007 | if (error) |
| 1008 | goto End; |
| 1009 | } else if (dev->type && dev->type->pm) { |
Rafael J. Wysocki | 1eede07 | 2008-05-20 23:00:01 +0200 | [diff] [blame] | 1010 | pm_dev_dbg(dev, state, "preparing type "); |
Rafael J. Wysocki | 9659cc0 | 2011-02-18 23:20:21 +0100 | [diff] [blame] | 1011 | if (dev->type->pm->prepare) |
| 1012 | error = dev->type->pm->prepare(dev); |
Rafael J. Wysocki | 1eede07 | 2008-05-20 23:00:01 +0200 | [diff] [blame] | 1013 | suspend_report_result(dev->type->pm->prepare, error); |
| 1014 | if (error) |
| 1015 | goto End; |
Rafael J. Wysocki | 9659cc0 | 2011-02-18 23:20:21 +0100 | [diff] [blame] | 1016 | } else if (dev->class && dev->class->pm) { |
Rafael J. Wysocki | 1eede07 | 2008-05-20 23:00:01 +0200 | [diff] [blame] | 1017 | pm_dev_dbg(dev, state, "preparing class "); |
Rafael J. Wysocki | 9659cc0 | 2011-02-18 23:20:21 +0100 | [diff] [blame] | 1018 | if (dev->class->pm->prepare) |
| 1019 | error = dev->class->pm->prepare(dev); |
Rafael J. Wysocki | 1eede07 | 2008-05-20 23:00:01 +0200 | [diff] [blame] | 1020 | suspend_report_result(dev->class->pm->prepare, error); |
Rafael J. Wysocki | 7538e3d | 2011-02-16 21:53:17 +0100 | [diff] [blame] | 1021 | if (error) |
| 1022 | goto End; |
Rafael J. Wysocki | 9659cc0 | 2011-02-18 23:20:21 +0100 | [diff] [blame] | 1023 | } else if (dev->bus && dev->bus->pm) { |
| 1024 | pm_dev_dbg(dev, state, "preparing "); |
| 1025 | if (dev->bus->pm->prepare) |
| 1026 | error = dev->bus->pm->prepare(dev); |
| 1027 | suspend_report_result(dev->bus->pm->prepare, error); |
Rafael J. Wysocki | 7538e3d | 2011-02-16 21:53:17 +0100 | [diff] [blame] | 1028 | } |
| 1029 | |
Rafael J. Wysocki | 1eede07 | 2008-05-20 23:00:01 +0200 | [diff] [blame] | 1030 | End: |
Greg Kroah-Hartman | 8e9394c | 2010-02-17 10:57:05 -0800 | [diff] [blame] | 1031 | device_unlock(dev); |
Rafael J. Wysocki | 775b64d | 2008-01-12 20:40:46 +0100 | [diff] [blame] | 1032 | |
| 1033 | return error; |
| 1034 | } |
| 1035 | |
| 1036 | /** |
Rafael J. Wysocki | 20d652d | 2009-08-20 20:25:52 +0200 | [diff] [blame] | 1037 | * dpm_prepare - Prepare all non-sysdev devices for a system PM transition. |
| 1038 | * @state: PM transition of the system being carried out. |
Alan Stern | cd59abf | 2007-09-21 15:36:56 -0400 | [diff] [blame] | 1039 | * |
Rafael J. Wysocki | 20d652d | 2009-08-20 20:25:52 +0200 | [diff] [blame] | 1040 | * Execute the ->prepare() callback(s) for all devices. |
Rafael J. Wysocki | 1eede07 | 2008-05-20 23:00:01 +0200 | [diff] [blame] | 1041 | */ |
Rafael J. Wysocki | 91e7c75 | 2011-05-17 23:26:00 +0200 | [diff] [blame] | 1042 | int dpm_prepare(pm_message_t state) |
Rafael J. Wysocki | 1eede07 | 2008-05-20 23:00:01 +0200 | [diff] [blame] | 1043 | { |
Rafael J. Wysocki | 1eede07 | 2008-05-20 23:00:01 +0200 | [diff] [blame] | 1044 | int error = 0; |
| 1045 | |
Rafael J. Wysocki | 91e7c75 | 2011-05-17 23:26:00 +0200 | [diff] [blame] | 1046 | might_sleep(); |
| 1047 | |
Rafael J. Wysocki | 1eede07 | 2008-05-20 23:00:01 +0200 | [diff] [blame] | 1048 | mutex_lock(&dpm_list_mtx); |
Rafael J. Wysocki | 1eede07 | 2008-05-20 23:00:01 +0200 | [diff] [blame] | 1049 | while (!list_empty(&dpm_list)) { |
| 1050 | struct device *dev = to_device(dpm_list.next); |
| 1051 | |
| 1052 | get_device(dev); |
Rafael J. Wysocki | 1eede07 | 2008-05-20 23:00:01 +0200 | [diff] [blame] | 1053 | mutex_unlock(&dpm_list_mtx); |
| 1054 | |
Rafael J. Wysocki | 1e2ef05 | 2011-07-06 10:51:58 +0200 | [diff] [blame^] | 1055 | error = device_prepare(dev, state); |
Rafael J. Wysocki | 1eede07 | 2008-05-20 23:00:01 +0200 | [diff] [blame] | 1056 | |
| 1057 | mutex_lock(&dpm_list_mtx); |
| 1058 | if (error) { |
Rafael J. Wysocki | 1eede07 | 2008-05-20 23:00:01 +0200 | [diff] [blame] | 1059 | if (error == -EAGAIN) { |
| 1060 | put_device(dev); |
Sebastian Ott | 886a7a3 | 2009-07-08 13:26:05 +0200 | [diff] [blame] | 1061 | error = 0; |
Rafael J. Wysocki | 1eede07 | 2008-05-20 23:00:01 +0200 | [diff] [blame] | 1062 | continue; |
| 1063 | } |
Rafael J. Wysocki | 1e75227 | 2010-12-03 22:58:05 +0100 | [diff] [blame] | 1064 | printk(KERN_INFO "PM: Device %s not prepared " |
| 1065 | "for power transition: code %d\n", |
Rafael J. Wysocki | 5c1a07a | 2010-12-24 15:03:34 +0100 | [diff] [blame] | 1066 | dev_name(dev), error); |
Rafael J. Wysocki | 1eede07 | 2008-05-20 23:00:01 +0200 | [diff] [blame] | 1067 | put_device(dev); |
| 1068 | break; |
| 1069 | } |
Alan Stern | f76b168 | 2011-06-18 20:22:23 +0200 | [diff] [blame] | 1070 | dev->power.is_prepared = true; |
Rafael J. Wysocki | 1eede07 | 2008-05-20 23:00:01 +0200 | [diff] [blame] | 1071 | if (!list_empty(&dev->power.entry)) |
Rafael J. Wysocki | 8a43a9a | 2010-12-16 00:50:30 +0100 | [diff] [blame] | 1072 | list_move_tail(&dev->power.entry, &dpm_prepared_list); |
Rafael J. Wysocki | 1eede07 | 2008-05-20 23:00:01 +0200 | [diff] [blame] | 1073 | put_device(dev); |
| 1074 | } |
Rafael J. Wysocki | 1eede07 | 2008-05-20 23:00:01 +0200 | [diff] [blame] | 1075 | mutex_unlock(&dpm_list_mtx); |
| 1076 | return error; |
| 1077 | } |
| 1078 | |
| 1079 | /** |
Rafael J. Wysocki | 20d652d | 2009-08-20 20:25:52 +0200 | [diff] [blame] | 1080 | * dpm_suspend_start - Prepare devices for PM transition and suspend them. |
| 1081 | * @state: PM transition of the system being carried out. |
Rafael J. Wysocki | 1eede07 | 2008-05-20 23:00:01 +0200 | [diff] [blame] | 1082 | * |
Rafael J. Wysocki | 20d652d | 2009-08-20 20:25:52 +0200 | [diff] [blame] | 1083 | * Prepare all non-sysdev devices for system PM transition and execute "suspend" |
| 1084 | * callbacks for them. |
Alan Stern | cd59abf | 2007-09-21 15:36:56 -0400 | [diff] [blame] | 1085 | */ |
Alan Stern | d161630 | 2009-05-24 22:05:42 +0200 | [diff] [blame] | 1086 | int dpm_suspend_start(pm_message_t state) |
Alan Stern | cd59abf | 2007-09-21 15:36:56 -0400 | [diff] [blame] | 1087 | { |
Rafael J. Wysocki | 775b64d | 2008-01-12 20:40:46 +0100 | [diff] [blame] | 1088 | int error; |
Alan Stern | cd59abf | 2007-09-21 15:36:56 -0400 | [diff] [blame] | 1089 | |
Rafael J. Wysocki | 1eede07 | 2008-05-20 23:00:01 +0200 | [diff] [blame] | 1090 | error = dpm_prepare(state); |
| 1091 | if (!error) |
| 1092 | error = dpm_suspend(state); |
Alan Stern | cd59abf | 2007-09-21 15:36:56 -0400 | [diff] [blame] | 1093 | return error; |
Alan Stern | cd59abf | 2007-09-21 15:36:56 -0400 | [diff] [blame] | 1094 | } |
Alan Stern | d161630 | 2009-05-24 22:05:42 +0200 | [diff] [blame] | 1095 | EXPORT_SYMBOL_GPL(dpm_suspend_start); |
Alan Stern | cd59abf | 2007-09-21 15:36:56 -0400 | [diff] [blame] | 1096 | |
| 1097 | void __suspend_report_result(const char *function, void *fn, int ret) |
| 1098 | { |
Bjorn Helgaas | c80cfb0 | 2008-10-15 22:01:35 -0700 | [diff] [blame] | 1099 | if (ret) |
| 1100 | printk(KERN_ERR "%s(): %pF returns %d\n", function, fn, ret); |
Alan Stern | cd59abf | 2007-09-21 15:36:56 -0400 | [diff] [blame] | 1101 | } |
| 1102 | EXPORT_SYMBOL_GPL(__suspend_report_result); |
Rafael J. Wysocki | f8824ce | 2010-01-27 23:47:38 +0100 | [diff] [blame] | 1103 | |
| 1104 | /** |
| 1105 | * device_pm_wait_for_dev - Wait for suspend/resume of a device to complete. |
| 1106 | * @dev: Device to wait for. |
| 1107 | * @subordinate: Device that needs to wait for @dev. |
| 1108 | */ |
Rafael J. Wysocki | 098dff7 | 2010-09-22 22:10:57 +0200 | [diff] [blame] | 1109 | int device_pm_wait_for_dev(struct device *subordinate, struct device *dev) |
Rafael J. Wysocki | f8824ce | 2010-01-27 23:47:38 +0100 | [diff] [blame] | 1110 | { |
| 1111 | dpm_wait(dev, subordinate->power.async_suspend); |
Rafael J. Wysocki | 098dff7 | 2010-09-22 22:10:57 +0200 | [diff] [blame] | 1112 | return async_error; |
Rafael J. Wysocki | f8824ce | 2010-01-27 23:47:38 +0100 | [diff] [blame] | 1113 | } |
| 1114 | EXPORT_SYMBOL_GPL(device_pm_wait_for_dev); |