blob: c448d5972a0bd0ea443c759fc6b9413a417211e2 [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/*
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.
11 * This will intialize the embedded device_pm_info object in the device
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. Wysocki1eede072008-05-20 23:00:01 +020015 * 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 Torvalds1da177e2005-04-16 15:20:36 -070018 */
19
Linus Torvalds1da177e2005-04-16 15:20:36 -070020#include <linux/device.h>
Alan Sterncd59abf2007-09-21 15:36:56 -040021#include <linux/kallsyms.h>
Matthias Kaehlcke11048dc2007-05-23 14:19:41 -070022#include <linux/mutex.h>
Alan Sterncd59abf2007-09-21 15:36:56 -040023#include <linux/pm.h>
Rafael J. Wysocki5e928f72009-08-18 23:38:32 +020024#include <linux/pm_runtime.h>
Alan Sterncd59abf2007-09-21 15:36:56 -040025#include <linux/resume-trace.h>
Rafael J. Wysocki2ed8d2b32009-03-16 22:34:06 +010026#include <linux/interrupt.h>
Arjan van de Venf2511772009-12-13 20:29:01 +010027#include <linux/sched.h>
Matthias Kaehlcke11048dc2007-05-23 14:19:41 -070028
Alan Sterncd59abf2007-09-21 15:36:56 -040029#include "../base.h"
Linus Torvalds1da177e2005-04-16 15:20:36 -070030#include "power.h"
31
Rafael J. Wysocki775b64d2008-01-12 20:40:46 +010032/*
Rafael J. Wysocki1eede072008-05-20 23:00:01 +020033 * The entries in the dpm_list list are in a depth first order, simply
Rafael J. Wysocki775b64d2008-01-12 20:40:46 +010034 * because children are guaranteed to be discovered after parents, and
35 * are inserted at the back of the list on discovery.
36 *
Rafael J. Wysocki775b64d2008-01-12 20:40:46 +010037 * Since device_pm_add() may be called with a device semaphore held,
38 * we must never try to acquire a device semaphore while holding
39 * dpm_list_mutex.
40 */
41
Rafael J. Wysocki1eede072008-05-20 23:00:01 +020042LIST_HEAD(dpm_list);
Linus Torvalds1da177e2005-04-16 15:20:36 -070043
Alan Sterncd59abf2007-09-21 15:36:56 -040044static DEFINE_MUTEX(dpm_list_mtx);
Linus Torvalds1da177e2005-04-16 15:20:36 -070045
Rafael J. Wysocki1eede072008-05-20 23:00:01 +020046/*
47 * Set once the preparation of devices for a PM transition has started, reset
48 * before starting to resume devices. Protected by dpm_list_mtx.
49 */
50static bool transition_started;
51
52/**
Rafael J. Wysocki20d652d2009-08-20 20:25:52 +020053 * device_pm_init - Initialize the PM-related part of a device object.
Rafael J. Wysocki5e928f72009-08-18 23:38:32 +020054 * @dev: Device object being initialized.
55 */
56void device_pm_init(struct device *dev)
57{
58 dev->power.status = DPM_ON;
59 pm_runtime_init(dev);
60}
61
62/**
Rafael J. Wysocki20d652d2009-08-20 20:25:52 +020063 * device_pm_lock - Lock the list of active devices used by the PM core.
Rafael J. Wysocki1eede072008-05-20 23:00:01 +020064 */
65void device_pm_lock(void)
66{
67 mutex_lock(&dpm_list_mtx);
68}
69
70/**
Rafael J. Wysocki20d652d2009-08-20 20:25:52 +020071 * device_pm_unlock - Unlock the list of active devices used by the PM core.
Rafael J. Wysocki1eede072008-05-20 23:00:01 +020072 */
73void device_pm_unlock(void)
74{
75 mutex_unlock(&dpm_list_mtx);
76}
Rafael J. Wysocki775b64d2008-01-12 20:40:46 +010077
Rafael J. Wysocki775b64d2008-01-12 20:40:46 +010078/**
Rafael J. Wysocki20d652d2009-08-20 20:25:52 +020079 * device_pm_add - Add a device to the PM core's list of active devices.
80 * @dev: Device to add to the list.
Rafael J. Wysocki775b64d2008-01-12 20:40:46 +010081 */
Alan Stern3b98aea2008-08-07 13:06:12 -040082void device_pm_add(struct device *dev)
Linus Torvalds1da177e2005-04-16 15:20:36 -070083{
Linus Torvalds1da177e2005-04-16 15:20:36 -070084 pr_debug("PM: Adding info for %s:%s\n",
Dmitry Torokhovc48ea602007-04-11 01:37:18 -040085 dev->bus ? dev->bus->name : "No Bus",
86 kobject_name(&dev->kobj));
Matthias Kaehlcke11048dc2007-05-23 14:19:41 -070087 mutex_lock(&dpm_list_mtx);
Rafael J. Wysocki1eede072008-05-20 23:00:01 +020088 if (dev->parent) {
Rafael J. Wysockif5a6d952008-08-09 01:05:13 +020089 if (dev->parent->power.status >= DPM_SUSPENDING)
90 dev_warn(dev, "parent %s should not be sleeping\n",
Kay Sievers1e0b2cf2008-10-30 01:36:48 +010091 dev_name(dev->parent));
Rafael J. Wysocki1eede072008-05-20 23:00:01 +020092 } else if (transition_started) {
93 /*
94 * We refuse to register parentless devices while a PM
95 * transition is in progress in order to avoid leaving them
96 * unhandled down the road
97 */
Arjan van de Ven728f0892008-09-20 19:09:00 -070098 dev_WARN(dev, "Parentless device registered during a PM transaction\n");
Rafael J. Wysocki58aca232008-03-12 00:57:22 +010099 }
Alan Stern3b98aea2008-08-07 13:06:12 -0400100
101 list_add_tail(&dev->power.entry, &dpm_list);
Matthias Kaehlcke11048dc2007-05-23 14:19:41 -0700102 mutex_unlock(&dpm_list_mtx);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700103}
104
Rafael J. Wysocki775b64d2008-01-12 20:40:46 +0100105/**
Rafael J. Wysocki20d652d2009-08-20 20:25:52 +0200106 * device_pm_remove - Remove a device from the PM core's list of active devices.
107 * @dev: Device to be removed from the list.
Rafael J. Wysocki775b64d2008-01-12 20:40:46 +0100108 */
Rafael J. Wysocki9cddad72007-06-13 15:53:34 +0200109void device_pm_remove(struct device *dev)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700110{
111 pr_debug("PM: Removing info for %s:%s\n",
Dmitry Torokhovc48ea602007-04-11 01:37:18 -0400112 dev->bus ? dev->bus->name : "No Bus",
113 kobject_name(&dev->kobj));
Matthias Kaehlcke11048dc2007-05-23 14:19:41 -0700114 mutex_lock(&dpm_list_mtx);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700115 list_del_init(&dev->power.entry);
Matthias Kaehlcke11048dc2007-05-23 14:19:41 -0700116 mutex_unlock(&dpm_list_mtx);
Rafael J. Wysocki5e928f72009-08-18 23:38:32 +0200117 pm_runtime_remove(dev);
Rafael J. Wysocki775b64d2008-01-12 20:40:46 +0100118}
119
Rafael J. Wysocki1eede072008-05-20 23:00:01 +0200120/**
Rafael J. Wysocki20d652d2009-08-20 20:25:52 +0200121 * device_pm_move_before - Move device in the PM core's list of active devices.
122 * @deva: Device to move in dpm_list.
123 * @devb: Device @deva should come before.
Cornelia Huckffa6a702009-03-04 12:44:00 +0100124 */
125void device_pm_move_before(struct device *deva, struct device *devb)
126{
127 pr_debug("PM: Moving %s:%s before %s:%s\n",
128 deva->bus ? deva->bus->name : "No Bus",
129 kobject_name(&deva->kobj),
130 devb->bus ? devb->bus->name : "No Bus",
131 kobject_name(&devb->kobj));
132 /* Delete deva from dpm_list and reinsert before devb. */
133 list_move_tail(&deva->power.entry, &devb->power.entry);
134}
135
136/**
Rafael J. Wysocki20d652d2009-08-20 20:25:52 +0200137 * device_pm_move_after - Move device in the PM core's list of active devices.
138 * @deva: Device to move in dpm_list.
139 * @devb: Device @deva should come after.
Cornelia Huckffa6a702009-03-04 12:44:00 +0100140 */
141void device_pm_move_after(struct device *deva, struct device *devb)
142{
143 pr_debug("PM: Moving %s:%s after %s:%s\n",
144 deva->bus ? deva->bus->name : "No Bus",
145 kobject_name(&deva->kobj),
146 devb->bus ? devb->bus->name : "No Bus",
147 kobject_name(&devb->kobj));
148 /* Delete deva from dpm_list and reinsert after devb. */
149 list_move(&deva->power.entry, &devb->power.entry);
150}
151
152/**
Rafael J. Wysocki20d652d2009-08-20 20:25:52 +0200153 * device_pm_move_last - Move device to end of the PM core's list of devices.
154 * @dev: Device to move in dpm_list.
Cornelia Huckffa6a702009-03-04 12:44:00 +0100155 */
156void device_pm_move_last(struct device *dev)
157{
158 pr_debug("PM: Moving %s:%s to end of list\n",
159 dev->bus ? dev->bus->name : "No Bus",
160 kobject_name(&dev->kobj));
161 list_move_tail(&dev->power.entry, &dpm_list);
162}
163
Rafael J. Wysocki875ab0b2009-12-18 01:57:31 +0100164static ktime_t initcall_debug_start(struct device *dev)
165{
166 ktime_t calltime = ktime_set(0, 0);
167
168 if (initcall_debug) {
169 pr_info("calling %s+ @ %i\n",
170 dev_name(dev), task_pid_nr(current));
171 calltime = ktime_get();
172 }
173
174 return calltime;
175}
176
177static void initcall_debug_report(struct device *dev, ktime_t calltime,
178 int error)
179{
180 ktime_t delta, rettime;
181
182 if (initcall_debug) {
183 rettime = ktime_get();
184 delta = ktime_sub(rettime, calltime);
185 pr_info("call %s+ returned %d after %Ld usecs\n", dev_name(dev),
186 error, (unsigned long long)ktime_to_ns(delta) >> 10);
187 }
188}
189
Cornelia Huckffa6a702009-03-04 12:44:00 +0100190/**
Rafael J. Wysocki20d652d2009-08-20 20:25:52 +0200191 * pm_op - Execute the PM operation appropriate for given PM event.
192 * @dev: Device to handle.
193 * @ops: PM operations to choose from.
194 * @state: PM transition of the system being carried out.
Rafael J. Wysocki1eede072008-05-20 23:00:01 +0200195 */
Dmitry Torokhovd9ab7712009-07-22 00:37:25 +0200196static int pm_op(struct device *dev,
197 const struct dev_pm_ops *ops,
198 pm_message_t state)
Rafael J. Wysocki1eede072008-05-20 23:00:01 +0200199{
200 int error = 0;
Rafael J. Wysocki875ab0b2009-12-18 01:57:31 +0100201 ktime_t calltime;
Arjan van de Venf2511772009-12-13 20:29:01 +0100202
Rafael J. Wysocki875ab0b2009-12-18 01:57:31 +0100203 calltime = initcall_debug_start(dev);
Rafael J. Wysocki1eede072008-05-20 23:00:01 +0200204
205 switch (state.event) {
206#ifdef CONFIG_SUSPEND
207 case PM_EVENT_SUSPEND:
208 if (ops->suspend) {
209 error = ops->suspend(dev);
210 suspend_report_result(ops->suspend, error);
211 }
212 break;
213 case PM_EVENT_RESUME:
214 if (ops->resume) {
215 error = ops->resume(dev);
216 suspend_report_result(ops->resume, error);
217 }
218 break;
219#endif /* CONFIG_SUSPEND */
220#ifdef CONFIG_HIBERNATION
221 case PM_EVENT_FREEZE:
222 case PM_EVENT_QUIESCE:
223 if (ops->freeze) {
224 error = ops->freeze(dev);
225 suspend_report_result(ops->freeze, error);
226 }
227 break;
228 case PM_EVENT_HIBERNATE:
229 if (ops->poweroff) {
230 error = ops->poweroff(dev);
231 suspend_report_result(ops->poweroff, error);
232 }
233 break;
234 case PM_EVENT_THAW:
235 case PM_EVENT_RECOVER:
236 if (ops->thaw) {
237 error = ops->thaw(dev);
238 suspend_report_result(ops->thaw, error);
239 }
240 break;
241 case PM_EVENT_RESTORE:
242 if (ops->restore) {
243 error = ops->restore(dev);
244 suspend_report_result(ops->restore, error);
245 }
246 break;
247#endif /* CONFIG_HIBERNATION */
248 default:
249 error = -EINVAL;
250 }
Arjan van de Venf2511772009-12-13 20:29:01 +0100251
Rafael J. Wysocki875ab0b2009-12-18 01:57:31 +0100252 initcall_debug_report(dev, calltime, error);
Arjan van de Venf2511772009-12-13 20:29:01 +0100253
Rafael J. Wysocki1eede072008-05-20 23:00:01 +0200254 return error;
255}
256
257/**
Rafael J. Wysocki20d652d2009-08-20 20:25:52 +0200258 * pm_noirq_op - Execute the PM operation appropriate for given PM event.
259 * @dev: Device to handle.
260 * @ops: PM operations to choose from.
261 * @state: PM transition of the system being carried out.
Rafael J. Wysocki1eede072008-05-20 23:00:01 +0200262 *
Rafael J. Wysocki20d652d2009-08-20 20:25:52 +0200263 * The driver of @dev will not receive interrupts while this function is being
264 * executed.
Rafael J. Wysocki1eede072008-05-20 23:00:01 +0200265 */
Dmitry Torokhovd9ab7712009-07-22 00:37:25 +0200266static int pm_noirq_op(struct device *dev,
267 const struct dev_pm_ops *ops,
Rafael J. Wysocki1eede072008-05-20 23:00:01 +0200268 pm_message_t state)
269{
270 int error = 0;
Arjan van de Venf2511772009-12-13 20:29:01 +0100271 ktime_t calltime, delta, rettime;
272
273 if (initcall_debug) {
274 pr_info("calling %s_i+ @ %i\n",
275 dev_name(dev), task_pid_nr(current));
276 calltime = ktime_get();
277 }
Rafael J. Wysocki1eede072008-05-20 23:00:01 +0200278
279 switch (state.event) {
280#ifdef CONFIG_SUSPEND
281 case PM_EVENT_SUSPEND:
282 if (ops->suspend_noirq) {
283 error = ops->suspend_noirq(dev);
284 suspend_report_result(ops->suspend_noirq, error);
285 }
286 break;
287 case PM_EVENT_RESUME:
288 if (ops->resume_noirq) {
289 error = ops->resume_noirq(dev);
290 suspend_report_result(ops->resume_noirq, error);
291 }
292 break;
293#endif /* CONFIG_SUSPEND */
294#ifdef CONFIG_HIBERNATION
295 case PM_EVENT_FREEZE:
296 case PM_EVENT_QUIESCE:
297 if (ops->freeze_noirq) {
298 error = ops->freeze_noirq(dev);
299 suspend_report_result(ops->freeze_noirq, error);
300 }
301 break;
302 case PM_EVENT_HIBERNATE:
303 if (ops->poweroff_noirq) {
304 error = ops->poweroff_noirq(dev);
305 suspend_report_result(ops->poweroff_noirq, error);
306 }
307 break;
308 case PM_EVENT_THAW:
309 case PM_EVENT_RECOVER:
310 if (ops->thaw_noirq) {
311 error = ops->thaw_noirq(dev);
312 suspend_report_result(ops->thaw_noirq, error);
313 }
314 break;
315 case PM_EVENT_RESTORE:
316 if (ops->restore_noirq) {
317 error = ops->restore_noirq(dev);
318 suspend_report_result(ops->restore_noirq, error);
319 }
320 break;
321#endif /* CONFIG_HIBERNATION */
322 default:
323 error = -EINVAL;
324 }
Arjan van de Venf2511772009-12-13 20:29:01 +0100325
326 if (initcall_debug) {
327 rettime = ktime_get();
328 delta = ktime_sub(rettime, calltime);
Rafael J. Wysocki875ab0b2009-12-18 01:57:31 +0100329 printk("initcall %s_i+ returned %d after %Ld usecs\n",
330 dev_name(dev), error,
331 (unsigned long long)ktime_to_ns(delta) >> 10);
Arjan van de Venf2511772009-12-13 20:29:01 +0100332 }
333
Rafael J. Wysocki1eede072008-05-20 23:00:01 +0200334 return error;
335}
336
337static char *pm_verb(int event)
338{
339 switch (event) {
340 case PM_EVENT_SUSPEND:
341 return "suspend";
342 case PM_EVENT_RESUME:
343 return "resume";
344 case PM_EVENT_FREEZE:
345 return "freeze";
346 case PM_EVENT_QUIESCE:
347 return "quiesce";
348 case PM_EVENT_HIBERNATE:
349 return "hibernate";
350 case PM_EVENT_THAW:
351 return "thaw";
352 case PM_EVENT_RESTORE:
353 return "restore";
354 case PM_EVENT_RECOVER:
355 return "recover";
356 default:
357 return "(unknown PM event)";
358 }
359}
360
361static void pm_dev_dbg(struct device *dev, pm_message_t state, char *info)
362{
363 dev_dbg(dev, "%s%s%s\n", info, pm_verb(state.event),
364 ((state.event & PM_EVENT_SLEEP) && device_may_wakeup(dev)) ?
365 ", may wakeup" : "");
366}
367
368static void pm_dev_err(struct device *dev, pm_message_t state, char *info,
369 int error)
370{
371 printk(KERN_ERR "PM: Device %s failed to %s%s: error %d\n",
372 kobject_name(&dev->kobj), pm_verb(state.event), info, error);
373}
374
Alan Sterncd59abf2007-09-21 15:36:56 -0400375/*------------------------- Resume routines -------------------------*/
376
377/**
Rafael J. Wysocki20d652d2009-08-20 20:25:52 +0200378 * device_resume_noirq - Execute an "early resume" callback for given device.
379 * @dev: Device to handle.
380 * @state: PM transition of the system being carried out.
Alan Sterncd59abf2007-09-21 15:36:56 -0400381 *
Rafael J. Wysocki20d652d2009-08-20 20:25:52 +0200382 * The driver of @dev will not receive interrupts while this function is being
383 * executed.
Alan Sterncd59abf2007-09-21 15:36:56 -0400384 */
Alan Sternd1616302009-05-24 22:05:42 +0200385static int device_resume_noirq(struct device *dev, pm_message_t state)
Alan Sterncd59abf2007-09-21 15:36:56 -0400386{
387 int error = 0;
388
389 TRACE_DEVICE(dev);
390 TRACE_RESUME(0);
391
Rafael J. Wysocki33c33742009-12-13 20:31:12 +0100392 if (dev->bus && dev->bus->pm) {
Rafael J. Wysocki1eede072008-05-20 23:00:01 +0200393 pm_dev_dbg(dev, state, "EARLY ");
394 error = pm_noirq_op(dev, dev->bus->pm, state);
Rafael J. Wysocki775b64d2008-01-12 20:40:46 +0100395 }
Rafael J. Wysocki33c33742009-12-13 20:31:12 +0100396
Rafael J. Wysocki775b64d2008-01-12 20:40:46 +0100397 TRACE_RESUME(error);
398 return error;
399}
400
401/**
Rafael J. Wysocki20d652d2009-08-20 20:25:52 +0200402 * dpm_resume_noirq - Execute "early resume" callbacks for non-sysdev devices.
403 * @state: PM transition of the system being carried out.
Rafael J. Wysocki775b64d2008-01-12 20:40:46 +0100404 *
Rafael J. Wysocki20d652d2009-08-20 20:25:52 +0200405 * Call the "noirq" resume handlers for all devices marked as DPM_OFF_IRQ and
406 * enable device drivers to receive interrupts.
Rafael J. Wysocki775b64d2008-01-12 20:40:46 +0100407 */
Alan Sternd1616302009-05-24 22:05:42 +0200408void dpm_resume_noirq(pm_message_t state)
Rafael J. Wysocki775b64d2008-01-12 20:40:46 +0100409{
Rafael J. Wysocki1eede072008-05-20 23:00:01 +0200410 struct device *dev;
Rafael J. Wysocki775b64d2008-01-12 20:40:46 +0100411
Rafael J. Wysocki32bdfac2009-05-24 21:15:07 +0200412 mutex_lock(&dpm_list_mtx);
Xiaotian Feng3eb132c2009-08-20 20:28:33 +0200413 transition_started = false;
Rafael J. Wysocki1eede072008-05-20 23:00:01 +0200414 list_for_each_entry(dev, &dpm_list, power.entry)
415 if (dev->power.status > DPM_OFF) {
416 int error;
Rafael J. Wysocki775b64d2008-01-12 20:40:46 +0100417
Rafael J. Wysocki1eede072008-05-20 23:00:01 +0200418 dev->power.status = DPM_OFF;
Alan Sternd1616302009-05-24 22:05:42 +0200419 error = device_resume_noirq(dev, state);
Rafael J. Wysocki1eede072008-05-20 23:00:01 +0200420 if (error)
421 pm_dev_err(dev, state, " early", error);
422 }
Rafael J. Wysocki32bdfac2009-05-24 21:15:07 +0200423 mutex_unlock(&dpm_list_mtx);
Rafael J. Wysocki2ed8d2b32009-03-16 22:34:06 +0100424 resume_device_irqs();
Rafael J. Wysocki775b64d2008-01-12 20:40:46 +0100425}
Alan Sternd1616302009-05-24 22:05:42 +0200426EXPORT_SYMBOL_GPL(dpm_resume_noirq);
Rafael J. Wysocki775b64d2008-01-12 20:40:46 +0100427
428/**
Rafael J. Wysocki875ab0b2009-12-18 01:57:31 +0100429 * legacy_resume - Execute a legacy (bus or class) resume callback for device.
430 * dev: Device to resume.
431 * cb: Resume callback to execute.
432 */
433static int legacy_resume(struct device *dev, int (*cb)(struct device *dev))
434{
435 int error;
436 ktime_t calltime;
437
438 calltime = initcall_debug_start(dev);
439
440 error = cb(dev);
441 suspend_report_result(cb, error);
442
443 initcall_debug_report(dev, calltime, error);
444
445 return error;
446}
447
448/**
Rafael J. Wysocki20d652d2009-08-20 20:25:52 +0200449 * device_resume - Execute "resume" callbacks for given device.
450 * @dev: Device to handle.
451 * @state: PM transition of the system being carried out.
Rafael J. Wysocki775b64d2008-01-12 20:40:46 +0100452 */
Alan Sternd1616302009-05-24 22:05:42 +0200453static int device_resume(struct device *dev, pm_message_t state)
Rafael J. Wysocki775b64d2008-01-12 20:40:46 +0100454{
455 int error = 0;
456
457 TRACE_DEVICE(dev);
458 TRACE_RESUME(0);
Alan Sterncd59abf2007-09-21 15:36:56 -0400459
Rafael J. Wysocki7a8d37a2008-02-25 00:35:04 +0100460 down(&dev->sem);
461
Rafael J. Wysocki1eede072008-05-20 23:00:01 +0200462 if (dev->bus) {
463 if (dev->bus->pm) {
464 pm_dev_dbg(dev, state, "");
Rafael J. Wysockiadf09492008-10-06 22:46:05 +0200465 error = pm_op(dev, dev->bus->pm, state);
Rafael J. Wysocki1eede072008-05-20 23:00:01 +0200466 } else if (dev->bus->resume) {
467 pm_dev_dbg(dev, state, "legacy ");
Rafael J. Wysocki875ab0b2009-12-18 01:57:31 +0100468 error = legacy_resume(dev, dev->bus->resume);
Rafael J. Wysocki1eede072008-05-20 23:00:01 +0200469 }
470 if (error)
471 goto End;
Alan Sterncd59abf2007-09-21 15:36:56 -0400472 }
473
Rafael J. Wysocki1eede072008-05-20 23:00:01 +0200474 if (dev->type) {
475 if (dev->type->pm) {
476 pm_dev_dbg(dev, state, "type ");
477 error = pm_op(dev, dev->type->pm, state);
Rafael J. Wysocki1eede072008-05-20 23:00:01 +0200478 }
479 if (error)
480 goto End;
Alan Sterncd59abf2007-09-21 15:36:56 -0400481 }
482
Rafael J. Wysocki1eede072008-05-20 23:00:01 +0200483 if (dev->class) {
484 if (dev->class->pm) {
485 pm_dev_dbg(dev, state, "class ");
486 error = pm_op(dev, dev->class->pm, state);
487 } else if (dev->class->resume) {
488 pm_dev_dbg(dev, state, "legacy class ");
Rafael J. Wysocki875ab0b2009-12-18 01:57:31 +0100489 error = legacy_resume(dev, dev->class->resume);
Rafael J. Wysocki1eede072008-05-20 23:00:01 +0200490 }
Alan Sterncd59abf2007-09-21 15:36:56 -0400491 }
Rafael J. Wysocki1eede072008-05-20 23:00:01 +0200492 End:
Rafael J. Wysocki7a8d37a2008-02-25 00:35:04 +0100493 up(&dev->sem);
494
Alan Sterncd59abf2007-09-21 15:36:56 -0400495 TRACE_RESUME(error);
496 return error;
497}
498
Rafael J. Wysocki775b64d2008-01-12 20:40:46 +0100499/**
Rafael J. Wysocki20d652d2009-08-20 20:25:52 +0200500 * dpm_resume - Execute "resume" callbacks for non-sysdev devices.
501 * @state: PM transition of the system being carried out.
Rafael J. Wysocki775b64d2008-01-12 20:40:46 +0100502 *
Rafael J. Wysocki20d652d2009-08-20 20:25:52 +0200503 * Execute the appropriate "resume" callback for all devices whose status
504 * indicates that they are suspended.
Alan Sterncd59abf2007-09-21 15:36:56 -0400505 */
Rafael J. Wysocki1eede072008-05-20 23:00:01 +0200506static void dpm_resume(pm_message_t state)
Alan Sterncd59abf2007-09-21 15:36:56 -0400507{
Rafael J. Wysocki1eede072008-05-20 23:00:01 +0200508 struct list_head list;
Alan Sterncd59abf2007-09-21 15:36:56 -0400509
Rafael J. Wysocki1eede072008-05-20 23:00:01 +0200510 INIT_LIST_HEAD(&list);
511 mutex_lock(&dpm_list_mtx);
Rafael J. Wysocki1eede072008-05-20 23:00:01 +0200512 while (!list_empty(&dpm_list)) {
513 struct device *dev = to_device(dpm_list.next);
514
515 get_device(dev);
516 if (dev->power.status >= DPM_OFF) {
517 int error;
518
519 dev->power.status = DPM_RESUMING;
520 mutex_unlock(&dpm_list_mtx);
521
Alan Sternd1616302009-05-24 22:05:42 +0200522 error = device_resume(dev, state);
Rafael J. Wysocki1eede072008-05-20 23:00:01 +0200523
524 mutex_lock(&dpm_list_mtx);
525 if (error)
526 pm_dev_err(dev, state, "", error);
527 } else if (dev->power.status == DPM_SUSPENDING) {
528 /* Allow new children of the device to be registered */
529 dev->power.status = DPM_RESUMING;
530 }
531 if (!list_empty(&dev->power.entry))
532 list_move_tail(&dev->power.entry, &list);
533 put_device(dev);
Alan Sterncd59abf2007-09-21 15:36:56 -0400534 }
Rafael J. Wysocki1eede072008-05-20 23:00:01 +0200535 list_splice(&list, &dpm_list);
536 mutex_unlock(&dpm_list_mtx);
537}
538
539/**
Rafael J. Wysocki20d652d2009-08-20 20:25:52 +0200540 * device_complete - Complete a PM transition for given device.
541 * @dev: Device to handle.
542 * @state: PM transition of the system being carried out.
Rafael J. Wysocki1eede072008-05-20 23:00:01 +0200543 */
Alan Sternd1616302009-05-24 22:05:42 +0200544static void device_complete(struct device *dev, pm_message_t state)
Rafael J. Wysocki1eede072008-05-20 23:00:01 +0200545{
546 down(&dev->sem);
547
548 if (dev->class && dev->class->pm && dev->class->pm->complete) {
549 pm_dev_dbg(dev, state, "completing class ");
550 dev->class->pm->complete(dev);
551 }
552
553 if (dev->type && dev->type->pm && dev->type->pm->complete) {
554 pm_dev_dbg(dev, state, "completing type ");
555 dev->type->pm->complete(dev);
556 }
557
Rafael J. Wysockiadf09492008-10-06 22:46:05 +0200558 if (dev->bus && dev->bus->pm && dev->bus->pm->complete) {
Rafael J. Wysocki1eede072008-05-20 23:00:01 +0200559 pm_dev_dbg(dev, state, "completing ");
Rafael J. Wysockiadf09492008-10-06 22:46:05 +0200560 dev->bus->pm->complete(dev);
Rafael J. Wysocki1eede072008-05-20 23:00:01 +0200561 }
562
563 up(&dev->sem);
564}
565
566/**
Rafael J. Wysocki20d652d2009-08-20 20:25:52 +0200567 * dpm_complete - Complete a PM transition for all non-sysdev devices.
568 * @state: PM transition of the system being carried out.
Rafael J. Wysocki1eede072008-05-20 23:00:01 +0200569 *
Rafael J. Wysocki20d652d2009-08-20 20:25:52 +0200570 * Execute the ->complete() callbacks for all devices whose PM status is not
571 * DPM_ON (this allows new devices to be registered).
Rafael J. Wysocki1eede072008-05-20 23:00:01 +0200572 */
573static void dpm_complete(pm_message_t state)
574{
575 struct list_head list;
576
577 INIT_LIST_HEAD(&list);
578 mutex_lock(&dpm_list_mtx);
Romit Dasguptae528e872009-10-28 22:56:02 +0100579 transition_started = false;
Rafael J. Wysocki1eede072008-05-20 23:00:01 +0200580 while (!list_empty(&dpm_list)) {
581 struct device *dev = to_device(dpm_list.prev);
582
583 get_device(dev);
584 if (dev->power.status > DPM_ON) {
585 dev->power.status = DPM_ON;
586 mutex_unlock(&dpm_list_mtx);
587
Alan Sternd1616302009-05-24 22:05:42 +0200588 device_complete(dev, state);
Rafael J. Wysocki5e928f72009-08-18 23:38:32 +0200589 pm_runtime_put_noidle(dev);
Rafael J. Wysocki1eede072008-05-20 23:00:01 +0200590
591 mutex_lock(&dpm_list_mtx);
592 }
593 if (!list_empty(&dev->power.entry))
594 list_move(&dev->power.entry, &list);
595 put_device(dev);
596 }
597 list_splice(&list, &dpm_list);
Alan Sterncd59abf2007-09-21 15:36:56 -0400598 mutex_unlock(&dpm_list_mtx);
599}
600
Rafael J. Wysocki775b64d2008-01-12 20:40:46 +0100601/**
Rafael J. Wysocki20d652d2009-08-20 20:25:52 +0200602 * dpm_resume_end - Execute "resume" callbacks and complete system transition.
603 * @state: PM transition of the system being carried out.
Alan Sterncd59abf2007-09-21 15:36:56 -0400604 *
Rafael J. Wysocki20d652d2009-08-20 20:25:52 +0200605 * Execute "resume" callbacks for all devices and complete the PM transition of
606 * the system.
Alan Sterncd59abf2007-09-21 15:36:56 -0400607 */
Alan Sternd1616302009-05-24 22:05:42 +0200608void dpm_resume_end(pm_message_t state)
Alan Sterncd59abf2007-09-21 15:36:56 -0400609{
610 might_sleep();
Rafael J. Wysocki1eede072008-05-20 23:00:01 +0200611 dpm_resume(state);
612 dpm_complete(state);
Alan Sterncd59abf2007-09-21 15:36:56 -0400613}
Alan Sternd1616302009-05-24 22:05:42 +0200614EXPORT_SYMBOL_GPL(dpm_resume_end);
Alan Sterncd59abf2007-09-21 15:36:56 -0400615
616
Alan Sterncd59abf2007-09-21 15:36:56 -0400617/*------------------------- Suspend routines -------------------------*/
618
Rafael J. Wysocki1eede072008-05-20 23:00:01 +0200619/**
Rafael J. Wysocki20d652d2009-08-20 20:25:52 +0200620 * resume_event - Return a "resume" message for given "suspend" sleep state.
621 * @sleep_state: PM message representing a sleep state.
622 *
623 * Return a PM message representing the resume event corresponding to given
624 * sleep state.
Rafael J. Wysocki1eede072008-05-20 23:00:01 +0200625 */
626static pm_message_t resume_event(pm_message_t sleep_state)
Alan Sterncd59abf2007-09-21 15:36:56 -0400627{
Rafael J. Wysocki1eede072008-05-20 23:00:01 +0200628 switch (sleep_state.event) {
629 case PM_EVENT_SUSPEND:
630 return PMSG_RESUME;
631 case PM_EVENT_FREEZE:
632 case PM_EVENT_QUIESCE:
633 return PMSG_RECOVER;
634 case PM_EVENT_HIBERNATE:
635 return PMSG_RESTORE;
Alan Sterncd59abf2007-09-21 15:36:56 -0400636 }
Rafael J. Wysocki1eede072008-05-20 23:00:01 +0200637 return PMSG_ON;
Alan Sterncd59abf2007-09-21 15:36:56 -0400638}
639
640/**
Rafael J. Wysocki20d652d2009-08-20 20:25:52 +0200641 * device_suspend_noirq - Execute a "late suspend" callback for given device.
642 * @dev: Device to handle.
643 * @state: PM transition of the system being carried out.
Rafael J. Wysocki775b64d2008-01-12 20:40:46 +0100644 *
Rafael J. Wysocki20d652d2009-08-20 20:25:52 +0200645 * The driver of @dev will not receive interrupts while this function is being
646 * executed.
Rafael J. Wysocki775b64d2008-01-12 20:40:46 +0100647 */
Alan Sternd1616302009-05-24 22:05:42 +0200648static int device_suspend_noirq(struct device *dev, pm_message_t state)
Rafael J. Wysocki775b64d2008-01-12 20:40:46 +0100649{
650 int error = 0;
651
Rafael J. Wysocki33c33742009-12-13 20:31:12 +0100652 if (dev->bus && dev->bus->pm) {
Rafael J. Wysocki1eede072008-05-20 23:00:01 +0200653 pm_dev_dbg(dev, state, "LATE ");
654 error = pm_noirq_op(dev, dev->bus->pm, state);
Rafael J. Wysocki775b64d2008-01-12 20:40:46 +0100655 }
656 return error;
657}
658
659/**
Rafael J. Wysocki20d652d2009-08-20 20:25:52 +0200660 * dpm_suspend_noirq - Execute "late suspend" callbacks for non-sysdev devices.
661 * @state: PM transition of the system being carried out.
Rafael J. Wysocki775b64d2008-01-12 20:40:46 +0100662 *
Rafael J. Wysocki20d652d2009-08-20 20:25:52 +0200663 * Prevent device drivers from receiving interrupts and call the "noirq" suspend
664 * handlers for all non-sysdev devices.
Rafael J. Wysocki775b64d2008-01-12 20:40:46 +0100665 */
Alan Sternd1616302009-05-24 22:05:42 +0200666int dpm_suspend_noirq(pm_message_t state)
Rafael J. Wysocki775b64d2008-01-12 20:40:46 +0100667{
Rafael J. Wysocki1eede072008-05-20 23:00:01 +0200668 struct device *dev;
Rafael J. Wysocki775b64d2008-01-12 20:40:46 +0100669 int error = 0;
670
Rafael J. Wysocki2ed8d2b32009-03-16 22:34:06 +0100671 suspend_device_irqs();
Rafael J. Wysocki32bdfac2009-05-24 21:15:07 +0200672 mutex_lock(&dpm_list_mtx);
Rafael J. Wysocki1eede072008-05-20 23:00:01 +0200673 list_for_each_entry_reverse(dev, &dpm_list, power.entry) {
Alan Sternd1616302009-05-24 22:05:42 +0200674 error = device_suspend_noirq(dev, state);
Rafael J. Wysocki775b64d2008-01-12 20:40:46 +0100675 if (error) {
Rafael J. Wysocki1eede072008-05-20 23:00:01 +0200676 pm_dev_err(dev, state, " late", error);
Rafael J. Wysocki775b64d2008-01-12 20:40:46 +0100677 break;
678 }
Rafael J. Wysocki1eede072008-05-20 23:00:01 +0200679 dev->power.status = DPM_OFF_IRQ;
Rafael J. Wysocki775b64d2008-01-12 20:40:46 +0100680 }
Rafael J. Wysocki32bdfac2009-05-24 21:15:07 +0200681 mutex_unlock(&dpm_list_mtx);
Rafael J. Wysocki775b64d2008-01-12 20:40:46 +0100682 if (error)
Alan Sternd1616302009-05-24 22:05:42 +0200683 dpm_resume_noirq(resume_event(state));
Rafael J. Wysocki775b64d2008-01-12 20:40:46 +0100684 return error;
685}
Alan Sternd1616302009-05-24 22:05:42 +0200686EXPORT_SYMBOL_GPL(dpm_suspend_noirq);
Rafael J. Wysocki775b64d2008-01-12 20:40:46 +0100687
688/**
Rafael J. Wysocki875ab0b2009-12-18 01:57:31 +0100689 * legacy_suspend - Execute a legacy (bus or class) suspend callback for device.
690 * dev: Device to suspend.
691 * cb: Suspend callback to execute.
692 */
693static int legacy_suspend(struct device *dev, pm_message_t state,
694 int (*cb)(struct device *dev, pm_message_t state))
695{
696 int error;
697 ktime_t calltime;
698
699 calltime = initcall_debug_start(dev);
700
701 error = cb(dev, state);
702 suspend_report_result(cb, error);
703
704 initcall_debug_report(dev, calltime, error);
705
706 return error;
707}
708
709/**
Rafael J. Wysocki20d652d2009-08-20 20:25:52 +0200710 * device_suspend - Execute "suspend" callbacks for given device.
711 * @dev: Device to handle.
712 * @state: PM transition of the system being carried out.
Alan Sterncd59abf2007-09-21 15:36:56 -0400713 */
Alan Sternd1616302009-05-24 22:05:42 +0200714static int device_suspend(struct device *dev, pm_message_t state)
Alan Sterncd59abf2007-09-21 15:36:56 -0400715{
716 int error = 0;
717
Rafael J. Wysocki7a8d37a2008-02-25 00:35:04 +0100718 down(&dev->sem);
719
Rafael J. Wysocki1eede072008-05-20 23:00:01 +0200720 if (dev->class) {
721 if (dev->class->pm) {
722 pm_dev_dbg(dev, state, "class ");
723 error = pm_op(dev, dev->class->pm, state);
724 } else if (dev->class->suspend) {
725 pm_dev_dbg(dev, state, "legacy class ");
Rafael J. Wysocki875ab0b2009-12-18 01:57:31 +0100726 error = legacy_suspend(dev, state, dev->class->suspend);
Rafael J. Wysocki1eede072008-05-20 23:00:01 +0200727 }
728 if (error)
729 goto End;
Alan Sterncd59abf2007-09-21 15:36:56 -0400730 }
731
Rafael J. Wysocki1eede072008-05-20 23:00:01 +0200732 if (dev->type) {
733 if (dev->type->pm) {
734 pm_dev_dbg(dev, state, "type ");
735 error = pm_op(dev, dev->type->pm, state);
Rafael J. Wysocki1eede072008-05-20 23:00:01 +0200736 }
737 if (error)
738 goto End;
Alan Sterncd59abf2007-09-21 15:36:56 -0400739 }
740
Rafael J. Wysocki1eede072008-05-20 23:00:01 +0200741 if (dev->bus) {
742 if (dev->bus->pm) {
743 pm_dev_dbg(dev, state, "");
Rafael J. Wysockiadf09492008-10-06 22:46:05 +0200744 error = pm_op(dev, dev->bus->pm, state);
Rafael J. Wysocki1eede072008-05-20 23:00:01 +0200745 } else if (dev->bus->suspend) {
746 pm_dev_dbg(dev, state, "legacy ");
Rafael J. Wysocki875ab0b2009-12-18 01:57:31 +0100747 error = legacy_suspend(dev, state, dev->bus->suspend);
Rafael J. Wysocki1eede072008-05-20 23:00:01 +0200748 }
Alan Sterncd59abf2007-09-21 15:36:56 -0400749 }
Rafael J. Wysocki1eede072008-05-20 23:00:01 +0200750 End:
Rafael J. Wysocki7a8d37a2008-02-25 00:35:04 +0100751 up(&dev->sem);
752
Alan Sterncd59abf2007-09-21 15:36:56 -0400753 return error;
754}
755
756/**
Rafael J. Wysocki20d652d2009-08-20 20:25:52 +0200757 * dpm_suspend - Execute "suspend" callbacks for all non-sysdev devices.
758 * @state: PM transition of the system being carried out.
Alan Sterncd59abf2007-09-21 15:36:56 -0400759 */
Rafael J. Wysocki775b64d2008-01-12 20:40:46 +0100760static int dpm_suspend(pm_message_t state)
Alan Sterncd59abf2007-09-21 15:36:56 -0400761{
Rafael J. Wysocki1eede072008-05-20 23:00:01 +0200762 struct list_head list;
Alan Sterncd59abf2007-09-21 15:36:56 -0400763 int error = 0;
764
Rafael J. Wysocki1eede072008-05-20 23:00:01 +0200765 INIT_LIST_HEAD(&list);
Alan Sterncd59abf2007-09-21 15:36:56 -0400766 mutex_lock(&dpm_list_mtx);
Rafael J. Wysocki1eede072008-05-20 23:00:01 +0200767 while (!list_empty(&dpm_list)) {
768 struct device *dev = to_device(dpm_list.prev);
Alan Sterncd59abf2007-09-21 15:36:56 -0400769
Rafael J. Wysocki1eede072008-05-20 23:00:01 +0200770 get_device(dev);
Rafael J. Wysocki775b64d2008-01-12 20:40:46 +0100771 mutex_unlock(&dpm_list_mtx);
Rafael J. Wysocki1eede072008-05-20 23:00:01 +0200772
Alan Sternd1616302009-05-24 22:05:42 +0200773 error = device_suspend(dev, state);
Rafael J. Wysocki1eede072008-05-20 23:00:01 +0200774
Alan Stern1b3cbec2008-02-29 11:50:22 -0500775 mutex_lock(&dpm_list_mtx);
Rafael J. Wysocki775b64d2008-01-12 20:40:46 +0100776 if (error) {
Rafael J. Wysocki1eede072008-05-20 23:00:01 +0200777 pm_dev_err(dev, state, "", error);
778 put_device(dev);
Rafael J. Wysocki775b64d2008-01-12 20:40:46 +0100779 break;
780 }
Rafael J. Wysocki1eede072008-05-20 23:00:01 +0200781 dev->power.status = DPM_OFF;
Rafael J. Wysocki7a8d37a2008-02-25 00:35:04 +0100782 if (!list_empty(&dev->power.entry))
Rafael J. Wysocki1eede072008-05-20 23:00:01 +0200783 list_move(&dev->power.entry, &list);
784 put_device(dev);
Rafael J. Wysocki775b64d2008-01-12 20:40:46 +0100785 }
Rafael J. Wysocki1eede072008-05-20 23:00:01 +0200786 list_splice(&list, dpm_list.prev);
Rafael J. Wysocki775b64d2008-01-12 20:40:46 +0100787 mutex_unlock(&dpm_list_mtx);
Rafael J. Wysocki1eede072008-05-20 23:00:01 +0200788 return error;
789}
790
791/**
Rafael J. Wysocki20d652d2009-08-20 20:25:52 +0200792 * device_prepare - Prepare a device for system power transition.
793 * @dev: Device to handle.
794 * @state: PM transition of the system being carried out.
795 *
796 * Execute the ->prepare() callback(s) for given device. No new children of the
797 * device may be registered after this function has returned.
Rafael J. Wysocki1eede072008-05-20 23:00:01 +0200798 */
Alan Sternd1616302009-05-24 22:05:42 +0200799static int device_prepare(struct device *dev, pm_message_t state)
Rafael J. Wysocki1eede072008-05-20 23:00:01 +0200800{
801 int error = 0;
802
803 down(&dev->sem);
804
Rafael J. Wysockiadf09492008-10-06 22:46:05 +0200805 if (dev->bus && dev->bus->pm && dev->bus->pm->prepare) {
Rafael J. Wysocki1eede072008-05-20 23:00:01 +0200806 pm_dev_dbg(dev, state, "preparing ");
Rafael J. Wysockiadf09492008-10-06 22:46:05 +0200807 error = dev->bus->pm->prepare(dev);
808 suspend_report_result(dev->bus->pm->prepare, error);
Rafael J. Wysocki1eede072008-05-20 23:00:01 +0200809 if (error)
810 goto End;
811 }
812
813 if (dev->type && dev->type->pm && dev->type->pm->prepare) {
814 pm_dev_dbg(dev, state, "preparing type ");
815 error = dev->type->pm->prepare(dev);
816 suspend_report_result(dev->type->pm->prepare, error);
817 if (error)
818 goto End;
819 }
820
821 if (dev->class && dev->class->pm && dev->class->pm->prepare) {
822 pm_dev_dbg(dev, state, "preparing class ");
823 error = dev->class->pm->prepare(dev);
824 suspend_report_result(dev->class->pm->prepare, error);
825 }
826 End:
827 up(&dev->sem);
Rafael J. Wysocki775b64d2008-01-12 20:40:46 +0100828
829 return error;
830}
831
832/**
Rafael J. Wysocki20d652d2009-08-20 20:25:52 +0200833 * dpm_prepare - Prepare all non-sysdev devices for a system PM transition.
834 * @state: PM transition of the system being carried out.
Alan Sterncd59abf2007-09-21 15:36:56 -0400835 *
Rafael J. Wysocki20d652d2009-08-20 20:25:52 +0200836 * Execute the ->prepare() callback(s) for all devices.
Rafael J. Wysocki1eede072008-05-20 23:00:01 +0200837 */
838static int dpm_prepare(pm_message_t state)
839{
840 struct list_head list;
841 int error = 0;
842
843 INIT_LIST_HEAD(&list);
844 mutex_lock(&dpm_list_mtx);
845 transition_started = true;
846 while (!list_empty(&dpm_list)) {
847 struct device *dev = to_device(dpm_list.next);
848
849 get_device(dev);
850 dev->power.status = DPM_PREPARING;
851 mutex_unlock(&dpm_list_mtx);
852
Rafael J. Wysocki5e928f72009-08-18 23:38:32 +0200853 pm_runtime_get_noresume(dev);
854 if (pm_runtime_barrier(dev) && device_may_wakeup(dev)) {
855 /* Wake-up requested during system sleep transition. */
856 pm_runtime_put_noidle(dev);
857 error = -EBUSY;
858 } else {
859 error = device_prepare(dev, state);
860 }
Rafael J. Wysocki1eede072008-05-20 23:00:01 +0200861
862 mutex_lock(&dpm_list_mtx);
863 if (error) {
864 dev->power.status = DPM_ON;
865 if (error == -EAGAIN) {
866 put_device(dev);
Sebastian Ott886a7a32009-07-08 13:26:05 +0200867 error = 0;
Rafael J. Wysocki1eede072008-05-20 23:00:01 +0200868 continue;
869 }
870 printk(KERN_ERR "PM: Failed to prepare device %s "
871 "for power transition: error %d\n",
872 kobject_name(&dev->kobj), error);
873 put_device(dev);
874 break;
875 }
876 dev->power.status = DPM_SUSPENDING;
877 if (!list_empty(&dev->power.entry))
878 list_move_tail(&dev->power.entry, &list);
879 put_device(dev);
880 }
881 list_splice(&list, &dpm_list);
882 mutex_unlock(&dpm_list_mtx);
883 return error;
884}
885
886/**
Rafael J. Wysocki20d652d2009-08-20 20:25:52 +0200887 * dpm_suspend_start - Prepare devices for PM transition and suspend them.
888 * @state: PM transition of the system being carried out.
Rafael J. Wysocki1eede072008-05-20 23:00:01 +0200889 *
Rafael J. Wysocki20d652d2009-08-20 20:25:52 +0200890 * Prepare all non-sysdev devices for system PM transition and execute "suspend"
891 * callbacks for them.
Alan Sterncd59abf2007-09-21 15:36:56 -0400892 */
Alan Sternd1616302009-05-24 22:05:42 +0200893int dpm_suspend_start(pm_message_t state)
Alan Sterncd59abf2007-09-21 15:36:56 -0400894{
Rafael J. Wysocki775b64d2008-01-12 20:40:46 +0100895 int error;
Alan Sterncd59abf2007-09-21 15:36:56 -0400896
Rafael J. Wysocki775b64d2008-01-12 20:40:46 +0100897 might_sleep();
Rafael J. Wysocki1eede072008-05-20 23:00:01 +0200898 error = dpm_prepare(state);
899 if (!error)
900 error = dpm_suspend(state);
Alan Sterncd59abf2007-09-21 15:36:56 -0400901 return error;
Alan Sterncd59abf2007-09-21 15:36:56 -0400902}
Alan Sternd1616302009-05-24 22:05:42 +0200903EXPORT_SYMBOL_GPL(dpm_suspend_start);
Alan Sterncd59abf2007-09-21 15:36:56 -0400904
905void __suspend_report_result(const char *function, void *fn, int ret)
906{
Bjorn Helgaasc80cfb02008-10-15 22:01:35 -0700907 if (ret)
908 printk(KERN_ERR "%s(): %pF returns %d\n", function, fn, ret);
Alan Sterncd59abf2007-09-21 15:36:56 -0400909}
910EXPORT_SYMBOL_GPL(__suspend_report_result);