2 * drivers/base/power/main.c - Where the driver meets power management.
4 * Copyright (c) 2003 Patrick Mochel
5 * Copyright (c) 2003 Open Source Development Lab
7 * This file is released under the GPLv2
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.
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.
20 #include <linux/device.h>
21 #include <linux/kallsyms.h>
22 #include <linux/mutex.h>
24 #include <linux/pm_runtime.h>
25 #include <linux/resume-trace.h>
26 #include <linux/interrupt.h>
27 #include <linux/sched.h>
28 #include <linux/async.h>
34 * The entries in the dpm_list list are in a depth first order, simply
35 * because children are guaranteed to be discovered after parents, and
36 * are inserted at the back of the list on discovery.
38 * Since device_pm_add() may be called with a device semaphore held,
39 * we must never try to acquire a device semaphore while holding
45 static DEFINE_MUTEX(dpm_list_mtx);
46 static pm_message_t pm_transition;
49 * Set once the preparation of devices for a PM transition has started, reset
50 * before starting to resume devices. Protected by dpm_list_mtx.
52 static bool transition_started;
55 * device_pm_init - Initialize the PM-related part of a device object.
56 * @dev: Device object being initialized.
58 void device_pm_init(struct device *dev)
60 dev->power.status = DPM_ON;
61 init_completion(&dev->power.completion);
66 * device_pm_lock - Lock the list of active devices used by the PM core.
68 void device_pm_lock(void)
70 mutex_lock(&dpm_list_mtx);
74 * device_pm_unlock - Unlock the list of active devices used by the PM core.
76 void device_pm_unlock(void)
78 mutex_unlock(&dpm_list_mtx);
82 * device_pm_add - Add a device to the PM core's list of active devices.
83 * @dev: Device to add to the list.
85 void device_pm_add(struct device *dev)
87 pr_debug("PM: Adding info for %s:%s\n",
88 dev->bus ? dev->bus->name : "No Bus",
89 kobject_name(&dev->kobj));
90 mutex_lock(&dpm_list_mtx);
92 if (dev->parent->power.status >= DPM_SUSPENDING)
93 dev_warn(dev, "parent %s should not be sleeping\n",
94 dev_name(dev->parent));
95 } else if (transition_started) {
97 * We refuse to register parentless devices while a PM
98 * transition is in progress in order to avoid leaving them
99 * unhandled down the road
101 dev_WARN(dev, "Parentless device registered during a PM transaction\n");
104 list_add_tail(&dev->power.entry, &dpm_list);
105 mutex_unlock(&dpm_list_mtx);
109 * device_pm_remove - Remove a device from the PM core's list of active devices.
110 * @dev: Device to be removed from the list.
112 void device_pm_remove(struct device *dev)
114 pr_debug("PM: Removing info for %s:%s\n",
115 dev->bus ? dev->bus->name : "No Bus",
116 kobject_name(&dev->kobj));
117 complete_all(&dev->power.completion);
118 mutex_lock(&dpm_list_mtx);
119 list_del_init(&dev->power.entry);
120 mutex_unlock(&dpm_list_mtx);
121 pm_runtime_remove(dev);
125 * device_pm_move_before - Move device in the PM core's list of active devices.
126 * @deva: Device to move in dpm_list.
127 * @devb: Device @deva should come before.
129 void device_pm_move_before(struct device *deva, struct device *devb)
131 pr_debug("PM: Moving %s:%s before %s:%s\n",
132 deva->bus ? deva->bus->name : "No Bus",
133 kobject_name(&deva->kobj),
134 devb->bus ? devb->bus->name : "No Bus",
135 kobject_name(&devb->kobj));
136 /* Delete deva from dpm_list and reinsert before devb. */
137 list_move_tail(&deva->power.entry, &devb->power.entry);
141 * device_pm_move_after - Move device in the PM core's list of active devices.
142 * @deva: Device to move in dpm_list.
143 * @devb: Device @deva should come after.
145 void device_pm_move_after(struct device *deva, struct device *devb)
147 pr_debug("PM: Moving %s:%s after %s:%s\n",
148 deva->bus ? deva->bus->name : "No Bus",
149 kobject_name(&deva->kobj),
150 devb->bus ? devb->bus->name : "No Bus",
151 kobject_name(&devb->kobj));
152 /* Delete deva from dpm_list and reinsert after devb. */
153 list_move(&deva->power.entry, &devb->power.entry);
157 * device_pm_move_last - Move device to end of the PM core's list of devices.
158 * @dev: Device to move in dpm_list.
160 void device_pm_move_last(struct device *dev)
162 pr_debug("PM: Moving %s:%s to end of list\n",
163 dev->bus ? dev->bus->name : "No Bus",
164 kobject_name(&dev->kobj));
165 list_move_tail(&dev->power.entry, &dpm_list);
168 static ktime_t initcall_debug_start(struct device *dev)
170 ktime_t calltime = ktime_set(0, 0);
172 if (initcall_debug) {
173 pr_info("calling %s+ @ %i\n",
174 dev_name(dev), task_pid_nr(current));
175 calltime = ktime_get();
181 static void initcall_debug_report(struct device *dev, ktime_t calltime,
184 ktime_t delta, rettime;
186 if (initcall_debug) {
187 rettime = ktime_get();
188 delta = ktime_sub(rettime, calltime);
189 pr_info("call %s+ returned %d after %Ld usecs\n", dev_name(dev),
190 error, (unsigned long long)ktime_to_ns(delta) >> 10);
195 * dpm_wait - Wait for a PM operation to complete.
196 * @dev: Device to wait for.
197 * @async: If unset, wait only if the device's power.async_suspend flag is set.
199 static void dpm_wait(struct device *dev, bool async)
204 if (async || (pm_async_enabled && dev->power.async_suspend))
205 wait_for_completion(&dev->power.completion);
208 static int dpm_wait_fn(struct device *dev, void *async_ptr)
210 dpm_wait(dev, *((bool *)async_ptr));
214 static void dpm_wait_for_children(struct device *dev, bool async)
216 device_for_each_child(dev, &async, dpm_wait_fn);
220 * pm_op - Execute the PM operation appropriate for given PM event.
221 * @dev: Device to handle.
222 * @ops: PM operations to choose from.
223 * @state: PM transition of the system being carried out.
225 static int pm_op(struct device *dev,
226 const struct dev_pm_ops *ops,
232 calltime = initcall_debug_start(dev);
234 switch (state.event) {
235 #ifdef CONFIG_SUSPEND
236 case PM_EVENT_SUSPEND:
238 error = ops->suspend(dev);
239 suspend_report_result(ops->suspend, error);
242 case PM_EVENT_RESUME:
244 error = ops->resume(dev);
245 suspend_report_result(ops->resume, error);
248 #endif /* CONFIG_SUSPEND */
249 #ifdef CONFIG_HIBERNATION
250 case PM_EVENT_FREEZE:
251 case PM_EVENT_QUIESCE:
253 error = ops->freeze(dev);
254 suspend_report_result(ops->freeze, error);
257 case PM_EVENT_HIBERNATE:
259 error = ops->poweroff(dev);
260 suspend_report_result(ops->poweroff, error);
264 case PM_EVENT_RECOVER:
266 error = ops->thaw(dev);
267 suspend_report_result(ops->thaw, error);
270 case PM_EVENT_RESTORE:
272 error = ops->restore(dev);
273 suspend_report_result(ops->restore, error);
276 #endif /* CONFIG_HIBERNATION */
281 initcall_debug_report(dev, calltime, error);
287 * pm_noirq_op - Execute the PM operation appropriate for given PM event.
288 * @dev: Device to handle.
289 * @ops: PM operations to choose from.
290 * @state: PM transition of the system being carried out.
292 * The driver of @dev will not receive interrupts while this function is being
295 static int pm_noirq_op(struct device *dev,
296 const struct dev_pm_ops *ops,
300 ktime_t calltime, delta, rettime;
302 if (initcall_debug) {
303 pr_info("calling %s+ @ %i, parent: %s\n",
304 dev_name(dev), task_pid_nr(current),
305 dev->parent ? dev_name(dev->parent) : "none");
306 calltime = ktime_get();
309 switch (state.event) {
310 #ifdef CONFIG_SUSPEND
311 case PM_EVENT_SUSPEND:
312 if (ops->suspend_noirq) {
313 error = ops->suspend_noirq(dev);
314 suspend_report_result(ops->suspend_noirq, error);
317 case PM_EVENT_RESUME:
318 if (ops->resume_noirq) {
319 error = ops->resume_noirq(dev);
320 suspend_report_result(ops->resume_noirq, error);
323 #endif /* CONFIG_SUSPEND */
324 #ifdef CONFIG_HIBERNATION
325 case PM_EVENT_FREEZE:
326 case PM_EVENT_QUIESCE:
327 if (ops->freeze_noirq) {
328 error = ops->freeze_noirq(dev);
329 suspend_report_result(ops->freeze_noirq, error);
332 case PM_EVENT_HIBERNATE:
333 if (ops->poweroff_noirq) {
334 error = ops->poweroff_noirq(dev);
335 suspend_report_result(ops->poweroff_noirq, error);
339 case PM_EVENT_RECOVER:
340 if (ops->thaw_noirq) {
341 error = ops->thaw_noirq(dev);
342 suspend_report_result(ops->thaw_noirq, error);
345 case PM_EVENT_RESTORE:
346 if (ops->restore_noirq) {
347 error = ops->restore_noirq(dev);
348 suspend_report_result(ops->restore_noirq, error);
351 #endif /* CONFIG_HIBERNATION */
356 if (initcall_debug) {
357 rettime = ktime_get();
358 delta = ktime_sub(rettime, calltime);
359 printk("initcall %s_i+ returned %d after %Ld usecs\n",
360 dev_name(dev), error,
361 (unsigned long long)ktime_to_ns(delta) >> 10);
367 static char *pm_verb(int event)
370 case PM_EVENT_SUSPEND:
372 case PM_EVENT_RESUME:
374 case PM_EVENT_FREEZE:
376 case PM_EVENT_QUIESCE:
378 case PM_EVENT_HIBERNATE:
382 case PM_EVENT_RESTORE:
384 case PM_EVENT_RECOVER:
387 return "(unknown PM event)";
391 static void pm_dev_dbg(struct device *dev, pm_message_t state, char *info)
393 dev_dbg(dev, "%s%s%s\n", info, pm_verb(state.event),
394 ((state.event & PM_EVENT_SLEEP) && device_may_wakeup(dev)) ?
395 ", may wakeup" : "");
398 static void pm_dev_err(struct device *dev, pm_message_t state, char *info,
401 printk(KERN_ERR "PM: Device %s failed to %s%s: error %d\n",
402 kobject_name(&dev->kobj), pm_verb(state.event), info, error);
405 static void dpm_show_time(ktime_t starttime, pm_message_t state, char *info)
411 calltime = ktime_get();
412 usecs64 = ktime_to_ns(ktime_sub(calltime, starttime));
413 do_div(usecs64, NSEC_PER_USEC);
417 pr_info("PM: %s%s%s of devices complete after %ld.%03ld msecs\n",
418 info ?: "", info ? " " : "", pm_verb(state.event),
419 usecs / USEC_PER_MSEC, usecs % USEC_PER_MSEC);
422 /*------------------------- Resume routines -------------------------*/
425 * device_resume_noirq - Execute an "early resume" callback for given device.
426 * @dev: Device to handle.
427 * @state: PM transition of the system being carried out.
429 * The driver of @dev will not receive interrupts while this function is being
432 static int device_resume_noirq(struct device *dev, pm_message_t state)
439 if (dev->bus && dev->bus->pm) {
440 pm_dev_dbg(dev, state, "EARLY ");
441 error = pm_noirq_op(dev, dev->bus->pm, state);
449 * dpm_resume_noirq - Execute "early resume" callbacks for non-sysdev devices.
450 * @state: PM transition of the system being carried out.
452 * Call the "noirq" resume handlers for all devices marked as DPM_OFF_IRQ and
453 * enable device drivers to receive interrupts.
455 void dpm_resume_noirq(pm_message_t state)
458 ktime_t starttime = ktime_get();
460 mutex_lock(&dpm_list_mtx);
461 transition_started = false;
462 list_for_each_entry(dev, &dpm_list, power.entry)
463 if (dev->power.status > DPM_OFF) {
466 dev->power.status = DPM_OFF;
467 error = device_resume_noirq(dev, state);
469 pm_dev_err(dev, state, " early", error);
471 mutex_unlock(&dpm_list_mtx);
472 dpm_show_time(starttime, state, "early");
473 resume_device_irqs();
475 EXPORT_SYMBOL_GPL(dpm_resume_noirq);
478 * legacy_resume - Execute a legacy (bus or class) resume callback for device.
479 * @dev: Device to resume.
480 * @cb: Resume callback to execute.
482 static int legacy_resume(struct device *dev, int (*cb)(struct device *dev))
487 calltime = initcall_debug_start(dev);
490 suspend_report_result(cb, error);
492 initcall_debug_report(dev, calltime, error);
498 * __device_resume - Execute "resume" callbacks for given device.
499 * @dev: Device to handle.
500 * @state: PM transition of the system being carried out.
501 * @async: If true, the device is being resumed asynchronously.
503 static int __device_resume(struct device *dev, pm_message_t state, bool async)
510 dpm_wait(dev->parent, async);
515 pm_dev_dbg(dev, state, "");
516 error = pm_op(dev, dev->bus->pm, state);
517 } else if (dev->bus->resume) {
518 pm_dev_dbg(dev, state, "legacy ");
519 error = legacy_resume(dev, dev->bus->resume);
527 pm_dev_dbg(dev, state, "type ");
528 error = pm_op(dev, dev->type->pm, state);
535 if (dev->class->pm) {
536 pm_dev_dbg(dev, state, "class ");
537 error = pm_op(dev, dev->class->pm, state);
538 } else if (dev->class->resume) {
539 pm_dev_dbg(dev, state, "legacy class ");
540 error = legacy_resume(dev, dev->class->resume);
545 complete_all(&dev->power.completion);
551 static void async_resume(void *data, async_cookie_t cookie)
553 struct device *dev = (struct device *)data;
556 error = __device_resume(dev, pm_transition, true);
558 pm_dev_err(dev, pm_transition, " async", error);
562 static int device_resume(struct device *dev)
564 INIT_COMPLETION(dev->power.completion);
566 if (pm_async_enabled && dev->power.async_suspend
567 && !pm_trace_is_enabled()) {
569 async_schedule(async_resume, dev);
573 return __device_resume(dev, pm_transition, false);
577 * dpm_resume - Execute "resume" callbacks for non-sysdev devices.
578 * @state: PM transition of the system being carried out.
580 * Execute the appropriate "resume" callback for all devices whose status
581 * indicates that they are suspended.
583 static void dpm_resume(pm_message_t state)
585 struct list_head list;
586 ktime_t starttime = ktime_get();
588 INIT_LIST_HEAD(&list);
589 mutex_lock(&dpm_list_mtx);
590 pm_transition = state;
591 while (!list_empty(&dpm_list)) {
592 struct device *dev = to_device(dpm_list.next);
595 if (dev->power.status >= DPM_OFF) {
598 dev->power.status = DPM_RESUMING;
599 mutex_unlock(&dpm_list_mtx);
601 error = device_resume(dev);
603 mutex_lock(&dpm_list_mtx);
605 pm_dev_err(dev, state, "", error);
606 } else if (dev->power.status == DPM_SUSPENDING) {
607 /* Allow new children of the device to be registered */
608 dev->power.status = DPM_RESUMING;
610 if (!list_empty(&dev->power.entry))
611 list_move_tail(&dev->power.entry, &list);
614 list_splice(&list, &dpm_list);
615 mutex_unlock(&dpm_list_mtx);
616 async_synchronize_full();
617 dpm_show_time(starttime, state, NULL);
621 * device_complete - Complete a PM transition for given device.
622 * @dev: Device to handle.
623 * @state: PM transition of the system being carried out.
625 static void device_complete(struct device *dev, pm_message_t state)
629 if (dev->class && dev->class->pm && dev->class->pm->complete) {
630 pm_dev_dbg(dev, state, "completing class ");
631 dev->class->pm->complete(dev);
634 if (dev->type && dev->type->pm && dev->type->pm->complete) {
635 pm_dev_dbg(dev, state, "completing type ");
636 dev->type->pm->complete(dev);
639 if (dev->bus && dev->bus->pm && dev->bus->pm->complete) {
640 pm_dev_dbg(dev, state, "completing ");
641 dev->bus->pm->complete(dev);
648 * dpm_complete - Complete a PM transition for all non-sysdev devices.
649 * @state: PM transition of the system being carried out.
651 * Execute the ->complete() callbacks for all devices whose PM status is not
652 * DPM_ON (this allows new devices to be registered).
654 static void dpm_complete(pm_message_t state)
656 struct list_head list;
658 INIT_LIST_HEAD(&list);
659 mutex_lock(&dpm_list_mtx);
660 transition_started = false;
661 while (!list_empty(&dpm_list)) {
662 struct device *dev = to_device(dpm_list.prev);
665 if (dev->power.status > DPM_ON) {
666 dev->power.status = DPM_ON;
667 mutex_unlock(&dpm_list_mtx);
669 device_complete(dev, state);
670 pm_runtime_put_sync(dev);
672 mutex_lock(&dpm_list_mtx);
674 if (!list_empty(&dev->power.entry))
675 list_move(&dev->power.entry, &list);
678 list_splice(&list, &dpm_list);
679 mutex_unlock(&dpm_list_mtx);
683 * dpm_resume_end - Execute "resume" callbacks and complete system transition.
684 * @state: PM transition of the system being carried out.
686 * Execute "resume" callbacks for all devices and complete the PM transition of
689 void dpm_resume_end(pm_message_t state)
695 EXPORT_SYMBOL_GPL(dpm_resume_end);
698 /*------------------------- Suspend routines -------------------------*/
701 * resume_event - Return a "resume" message for given "suspend" sleep state.
702 * @sleep_state: PM message representing a sleep state.
704 * Return a PM message representing the resume event corresponding to given
707 static pm_message_t resume_event(pm_message_t sleep_state)
709 switch (sleep_state.event) {
710 case PM_EVENT_SUSPEND:
712 case PM_EVENT_FREEZE:
713 case PM_EVENT_QUIESCE:
715 case PM_EVENT_HIBERNATE:
722 * device_suspend_noirq - Execute a "late suspend" callback for given device.
723 * @dev: Device to handle.
724 * @state: PM transition of the system being carried out.
726 * The driver of @dev will not receive interrupts while this function is being
729 static int device_suspend_noirq(struct device *dev, pm_message_t state)
733 if (dev->bus && dev->bus->pm) {
734 pm_dev_dbg(dev, state, "LATE ");
735 error = pm_noirq_op(dev, dev->bus->pm, state);
741 * dpm_suspend_noirq - Execute "late suspend" callbacks for non-sysdev devices.
742 * @state: PM transition of the system being carried out.
744 * Prevent device drivers from receiving interrupts and call the "noirq" suspend
745 * handlers for all non-sysdev devices.
747 int dpm_suspend_noirq(pm_message_t state)
750 ktime_t starttime = ktime_get();
753 suspend_device_irqs();
754 mutex_lock(&dpm_list_mtx);
755 list_for_each_entry_reverse(dev, &dpm_list, power.entry) {
756 error = device_suspend_noirq(dev, state);
758 pm_dev_err(dev, state, " late", error);
761 dev->power.status = DPM_OFF_IRQ;
763 mutex_unlock(&dpm_list_mtx);
765 dpm_resume_noirq(resume_event(state));
767 dpm_show_time(starttime, state, "late");
770 EXPORT_SYMBOL_GPL(dpm_suspend_noirq);
773 * legacy_suspend - Execute a legacy (bus or class) suspend callback for device.
774 * @dev: Device to suspend.
775 * @state: PM transition of the system being carried out.
776 * @cb: Suspend callback to execute.
778 static int legacy_suspend(struct device *dev, pm_message_t state,
779 int (*cb)(struct device *dev, pm_message_t state))
784 calltime = initcall_debug_start(dev);
786 error = cb(dev, state);
787 suspend_report_result(cb, error);
789 initcall_debug_report(dev, calltime, error);
794 static int async_error;
797 * device_suspend - Execute "suspend" callbacks for given device.
798 * @dev: Device to handle.
799 * @state: PM transition of the system being carried out.
800 * @async: If true, the device is being suspended asynchronously.
802 static int __device_suspend(struct device *dev, pm_message_t state, bool async)
806 dpm_wait_for_children(dev, async);
813 if (dev->class->pm) {
814 pm_dev_dbg(dev, state, "class ");
815 error = pm_op(dev, dev->class->pm, state);
816 } else if (dev->class->suspend) {
817 pm_dev_dbg(dev, state, "legacy class ");
818 error = legacy_suspend(dev, state, dev->class->suspend);
826 pm_dev_dbg(dev, state, "type ");
827 error = pm_op(dev, dev->type->pm, state);
835 pm_dev_dbg(dev, state, "");
836 error = pm_op(dev, dev->bus->pm, state);
837 } else if (dev->bus->suspend) {
838 pm_dev_dbg(dev, state, "legacy ");
839 error = legacy_suspend(dev, state, dev->bus->suspend);
844 dev->power.status = DPM_OFF;
848 complete_all(&dev->power.completion);
853 static void async_suspend(void *data, async_cookie_t cookie)
855 struct device *dev = (struct device *)data;
858 error = __device_suspend(dev, pm_transition, true);
860 pm_dev_err(dev, pm_transition, " async", error);
867 static int device_suspend(struct device *dev)
869 INIT_COMPLETION(dev->power.completion);
871 if (pm_async_enabled && dev->power.async_suspend) {
873 async_schedule(async_suspend, dev);
877 return __device_suspend(dev, pm_transition, false);
881 * dpm_suspend - Execute "suspend" callbacks for all non-sysdev devices.
882 * @state: PM transition of the system being carried out.
884 static int dpm_suspend(pm_message_t state)
886 struct list_head list;
887 ktime_t starttime = ktime_get();
890 INIT_LIST_HEAD(&list);
891 mutex_lock(&dpm_list_mtx);
892 pm_transition = state;
894 while (!list_empty(&dpm_list)) {
895 struct device *dev = to_device(dpm_list.prev);
898 mutex_unlock(&dpm_list_mtx);
900 error = device_suspend(dev);
902 mutex_lock(&dpm_list_mtx);
904 pm_dev_err(dev, state, "", error);
908 if (!list_empty(&dev->power.entry))
909 list_move(&dev->power.entry, &list);
914 list_splice(&list, dpm_list.prev);
915 mutex_unlock(&dpm_list_mtx);
916 async_synchronize_full();
920 dpm_show_time(starttime, state, NULL);
925 * device_prepare - Prepare a device for system power transition.
926 * @dev: Device to handle.
927 * @state: PM transition of the system being carried out.
929 * Execute the ->prepare() callback(s) for given device. No new children of the
930 * device may be registered after this function has returned.
932 static int device_prepare(struct device *dev, pm_message_t state)
938 if (dev->bus && dev->bus->pm && dev->bus->pm->prepare) {
939 pm_dev_dbg(dev, state, "preparing ");
940 error = dev->bus->pm->prepare(dev);
941 suspend_report_result(dev->bus->pm->prepare, error);
946 if (dev->type && dev->type->pm && dev->type->pm->prepare) {
947 pm_dev_dbg(dev, state, "preparing type ");
948 error = dev->type->pm->prepare(dev);
949 suspend_report_result(dev->type->pm->prepare, error);
954 if (dev->class && dev->class->pm && dev->class->pm->prepare) {
955 pm_dev_dbg(dev, state, "preparing class ");
956 error = dev->class->pm->prepare(dev);
957 suspend_report_result(dev->class->pm->prepare, error);
966 * dpm_prepare - Prepare all non-sysdev devices for a system PM transition.
967 * @state: PM transition of the system being carried out.
969 * Execute the ->prepare() callback(s) for all devices.
971 static int dpm_prepare(pm_message_t state)
973 struct list_head list;
976 INIT_LIST_HEAD(&list);
977 mutex_lock(&dpm_list_mtx);
978 transition_started = true;
979 while (!list_empty(&dpm_list)) {
980 struct device *dev = to_device(dpm_list.next);
983 dev->power.status = DPM_PREPARING;
984 mutex_unlock(&dpm_list_mtx);
986 pm_runtime_get_noresume(dev);
987 if (pm_runtime_barrier(dev) && device_may_wakeup(dev)) {
988 /* Wake-up requested during system sleep transition. */
989 pm_runtime_put_sync(dev);
992 error = device_prepare(dev, state);
995 mutex_lock(&dpm_list_mtx);
997 dev->power.status = DPM_ON;
998 if (error == -EAGAIN) {
1003 printk(KERN_ERR "PM: Failed to prepare device %s "
1004 "for power transition: error %d\n",
1005 kobject_name(&dev->kobj), error);
1009 dev->power.status = DPM_SUSPENDING;
1010 if (!list_empty(&dev->power.entry))
1011 list_move_tail(&dev->power.entry, &list);
1014 list_splice(&list, &dpm_list);
1015 mutex_unlock(&dpm_list_mtx);
1020 * dpm_suspend_start - Prepare devices for PM transition and suspend them.
1021 * @state: PM transition of the system being carried out.
1023 * Prepare all non-sysdev devices for system PM transition and execute "suspend"
1024 * callbacks for them.
1026 int dpm_suspend_start(pm_message_t state)
1031 error = dpm_prepare(state);
1033 error = dpm_suspend(state);
1036 EXPORT_SYMBOL_GPL(dpm_suspend_start);
1038 void __suspend_report_result(const char *function, void *fn, int ret)
1041 printk(KERN_ERR "%s(): %pF returns %d\n", function, fn, ret);
1043 EXPORT_SYMBOL_GPL(__suspend_report_result);