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 lock held,
39 * we must never try to acquire a device lock 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;
54 static int async_error;
57 * device_pm_init - Initialize the PM-related part of a device object.
58 * @dev: Device object being initialized.
60 void device_pm_init(struct device *dev)
62 dev->power.status = DPM_ON;
63 init_completion(&dev->power.completion);
64 complete_all(&dev->power.completion);
65 dev->power.wakeup = NULL;
66 spin_lock_init(&dev->power.lock);
71 * device_pm_lock - Lock the list of active devices used by the PM core.
73 void device_pm_lock(void)
75 mutex_lock(&dpm_list_mtx);
79 * device_pm_unlock - Unlock the list of active devices used by the PM core.
81 void device_pm_unlock(void)
83 mutex_unlock(&dpm_list_mtx);
87 * device_pm_add - Add a device to the PM core's list of active devices.
88 * @dev: Device to add to the list.
90 void device_pm_add(struct device *dev)
92 pr_debug("PM: Adding info for %s:%s\n",
93 dev->bus ? dev->bus->name : "No Bus",
94 kobject_name(&dev->kobj));
95 mutex_lock(&dpm_list_mtx);
97 if (dev->parent->power.status >= DPM_SUSPENDING)
98 dev_warn(dev, "parent %s should not be sleeping\n",
99 dev_name(dev->parent));
100 } else if (transition_started) {
102 * We refuse to register parentless devices while a PM
103 * transition is in progress in order to avoid leaving them
104 * unhandled down the road
106 dev_WARN(dev, "Parentless device registered during a PM transaction\n");
109 list_add_tail(&dev->power.entry, &dpm_list);
110 mutex_unlock(&dpm_list_mtx);
114 * device_pm_remove - Remove a device from the PM core's list of active devices.
115 * @dev: Device to be removed from the list.
117 void device_pm_remove(struct device *dev)
119 pr_debug("PM: Removing info for %s:%s\n",
120 dev->bus ? dev->bus->name : "No Bus",
121 kobject_name(&dev->kobj));
122 complete_all(&dev->power.completion);
123 mutex_lock(&dpm_list_mtx);
124 list_del_init(&dev->power.entry);
125 mutex_unlock(&dpm_list_mtx);
126 device_wakeup_disable(dev);
127 pm_runtime_remove(dev);
131 * device_pm_move_before - Move device in the PM core's list of active devices.
132 * @deva: Device to move in dpm_list.
133 * @devb: Device @deva should come before.
135 void device_pm_move_before(struct device *deva, struct device *devb)
137 pr_debug("PM: Moving %s:%s before %s:%s\n",
138 deva->bus ? deva->bus->name : "No Bus",
139 kobject_name(&deva->kobj),
140 devb->bus ? devb->bus->name : "No Bus",
141 kobject_name(&devb->kobj));
142 /* Delete deva from dpm_list and reinsert before devb. */
143 list_move_tail(&deva->power.entry, &devb->power.entry);
147 * device_pm_move_after - Move device in the PM core's list of active devices.
148 * @deva: Device to move in dpm_list.
149 * @devb: Device @deva should come after.
151 void device_pm_move_after(struct device *deva, struct device *devb)
153 pr_debug("PM: Moving %s:%s after %s:%s\n",
154 deva->bus ? deva->bus->name : "No Bus",
155 kobject_name(&deva->kobj),
156 devb->bus ? devb->bus->name : "No Bus",
157 kobject_name(&devb->kobj));
158 /* Delete deva from dpm_list and reinsert after devb. */
159 list_move(&deva->power.entry, &devb->power.entry);
163 * device_pm_move_last - Move device to end of the PM core's list of devices.
164 * @dev: Device to move in dpm_list.
166 void device_pm_move_last(struct device *dev)
168 pr_debug("PM: Moving %s:%s to end of list\n",
169 dev->bus ? dev->bus->name : "No Bus",
170 kobject_name(&dev->kobj));
171 list_move_tail(&dev->power.entry, &dpm_list);
174 static ktime_t initcall_debug_start(struct device *dev)
176 ktime_t calltime = ktime_set(0, 0);
178 if (initcall_debug) {
179 pr_info("calling %s+ @ %i\n",
180 dev_name(dev), task_pid_nr(current));
181 calltime = ktime_get();
187 static void initcall_debug_report(struct device *dev, ktime_t calltime,
190 ktime_t delta, rettime;
192 if (initcall_debug) {
193 rettime = ktime_get();
194 delta = ktime_sub(rettime, calltime);
195 pr_info("call %s+ returned %d after %Ld usecs\n", dev_name(dev),
196 error, (unsigned long long)ktime_to_ns(delta) >> 10);
201 * dpm_wait - Wait for a PM operation to complete.
202 * @dev: Device to wait for.
203 * @async: If unset, wait only if the device's power.async_suspend flag is set.
205 static void dpm_wait(struct device *dev, bool async)
210 if (async || (pm_async_enabled && dev->power.async_suspend))
211 wait_for_completion(&dev->power.completion);
214 static int dpm_wait_fn(struct device *dev, void *async_ptr)
216 dpm_wait(dev, *((bool *)async_ptr));
220 static void dpm_wait_for_children(struct device *dev, bool async)
222 device_for_each_child(dev, &async, dpm_wait_fn);
226 * pm_op - Execute the PM operation appropriate for given PM event.
227 * @dev: Device to handle.
228 * @ops: PM operations to choose from.
229 * @state: PM transition of the system being carried out.
231 static int pm_op(struct device *dev,
232 const struct dev_pm_ops *ops,
238 calltime = initcall_debug_start(dev);
240 switch (state.event) {
241 #ifdef CONFIG_SUSPEND
242 case PM_EVENT_SUSPEND:
244 error = ops->suspend(dev);
245 suspend_report_result(ops->suspend, error);
248 case PM_EVENT_RESUME:
250 error = ops->resume(dev);
251 suspend_report_result(ops->resume, error);
254 #endif /* CONFIG_SUSPEND */
255 #ifdef CONFIG_HIBERNATION
256 case PM_EVENT_FREEZE:
257 case PM_EVENT_QUIESCE:
259 error = ops->freeze(dev);
260 suspend_report_result(ops->freeze, error);
263 case PM_EVENT_HIBERNATE:
265 error = ops->poweroff(dev);
266 suspend_report_result(ops->poweroff, error);
270 case PM_EVENT_RECOVER:
272 error = ops->thaw(dev);
273 suspend_report_result(ops->thaw, error);
276 case PM_EVENT_RESTORE:
278 error = ops->restore(dev);
279 suspend_report_result(ops->restore, error);
282 #endif /* CONFIG_HIBERNATION */
287 initcall_debug_report(dev, calltime, error);
293 * pm_noirq_op - Execute the PM operation appropriate for given PM event.
294 * @dev: Device to handle.
295 * @ops: PM operations to choose from.
296 * @state: PM transition of the system being carried out.
298 * The driver of @dev will not receive interrupts while this function is being
301 static int pm_noirq_op(struct device *dev,
302 const struct dev_pm_ops *ops,
306 ktime_t calltime, delta, rettime;
308 if (initcall_debug) {
309 pr_info("calling %s+ @ %i, parent: %s\n",
310 dev_name(dev), task_pid_nr(current),
311 dev->parent ? dev_name(dev->parent) : "none");
312 calltime = ktime_get();
315 switch (state.event) {
316 #ifdef CONFIG_SUSPEND
317 case PM_EVENT_SUSPEND:
318 if (ops->suspend_noirq) {
319 error = ops->suspend_noirq(dev);
320 suspend_report_result(ops->suspend_noirq, error);
323 case PM_EVENT_RESUME:
324 if (ops->resume_noirq) {
325 error = ops->resume_noirq(dev);
326 suspend_report_result(ops->resume_noirq, error);
329 #endif /* CONFIG_SUSPEND */
330 #ifdef CONFIG_HIBERNATION
331 case PM_EVENT_FREEZE:
332 case PM_EVENT_QUIESCE:
333 if (ops->freeze_noirq) {
334 error = ops->freeze_noirq(dev);
335 suspend_report_result(ops->freeze_noirq, error);
338 case PM_EVENT_HIBERNATE:
339 if (ops->poweroff_noirq) {
340 error = ops->poweroff_noirq(dev);
341 suspend_report_result(ops->poweroff_noirq, error);
345 case PM_EVENT_RECOVER:
346 if (ops->thaw_noirq) {
347 error = ops->thaw_noirq(dev);
348 suspend_report_result(ops->thaw_noirq, error);
351 case PM_EVENT_RESTORE:
352 if (ops->restore_noirq) {
353 error = ops->restore_noirq(dev);
354 suspend_report_result(ops->restore_noirq, error);
357 #endif /* CONFIG_HIBERNATION */
362 if (initcall_debug) {
363 rettime = ktime_get();
364 delta = ktime_sub(rettime, calltime);
365 printk("initcall %s_i+ returned %d after %Ld usecs\n",
366 dev_name(dev), error,
367 (unsigned long long)ktime_to_ns(delta) >> 10);
373 static char *pm_verb(int event)
376 case PM_EVENT_SUSPEND:
378 case PM_EVENT_RESUME:
380 case PM_EVENT_FREEZE:
382 case PM_EVENT_QUIESCE:
384 case PM_EVENT_HIBERNATE:
388 case PM_EVENT_RESTORE:
390 case PM_EVENT_RECOVER:
393 return "(unknown PM event)";
397 static void pm_dev_dbg(struct device *dev, pm_message_t state, char *info)
399 dev_dbg(dev, "%s%s%s\n", info, pm_verb(state.event),
400 ((state.event & PM_EVENT_SLEEP) && device_may_wakeup(dev)) ?
401 ", may wakeup" : "");
404 static void pm_dev_err(struct device *dev, pm_message_t state, char *info,
407 printk(KERN_ERR "PM: Device %s failed to %s%s: error %d\n",
408 kobject_name(&dev->kobj), pm_verb(state.event), info, error);
411 static void dpm_show_time(ktime_t starttime, pm_message_t state, char *info)
417 calltime = ktime_get();
418 usecs64 = ktime_to_ns(ktime_sub(calltime, starttime));
419 do_div(usecs64, NSEC_PER_USEC);
423 pr_info("PM: %s%s%s of devices complete after %ld.%03ld msecs\n",
424 info ?: "", info ? " " : "", pm_verb(state.event),
425 usecs / USEC_PER_MSEC, usecs % USEC_PER_MSEC);
428 /*------------------------- Resume routines -------------------------*/
431 * device_resume_noirq - Execute an "early resume" callback for given device.
432 * @dev: Device to handle.
433 * @state: PM transition of the system being carried out.
435 * The driver of @dev will not receive interrupts while this function is being
438 static int device_resume_noirq(struct device *dev, pm_message_t state)
445 if (dev->bus && dev->bus->pm) {
446 pm_dev_dbg(dev, state, "EARLY ");
447 error = pm_noirq_op(dev, dev->bus->pm, state);
452 if (dev->type && dev->type->pm) {
453 pm_dev_dbg(dev, state, "EARLY type ");
454 error = pm_noirq_op(dev, dev->type->pm, state);
459 if (dev->class && dev->class->pm) {
460 pm_dev_dbg(dev, state, "EARLY class ");
461 error = pm_noirq_op(dev, dev->class->pm, state);
470 * dpm_resume_noirq - Execute "early resume" callbacks for non-sysdev devices.
471 * @state: PM transition of the system being carried out.
473 * Call the "noirq" resume handlers for all devices marked as DPM_OFF_IRQ and
474 * enable device drivers to receive interrupts.
476 void dpm_resume_noirq(pm_message_t state)
479 ktime_t starttime = ktime_get();
481 mutex_lock(&dpm_list_mtx);
482 transition_started = false;
483 list_for_each_entry(dev, &dpm_list, power.entry)
484 if (dev->power.status > DPM_OFF) {
487 dev->power.status = DPM_OFF;
488 error = device_resume_noirq(dev, state);
490 pm_dev_err(dev, state, " early", error);
492 mutex_unlock(&dpm_list_mtx);
493 dpm_show_time(starttime, state, "early");
494 resume_device_irqs();
496 EXPORT_SYMBOL_GPL(dpm_resume_noirq);
499 * legacy_resume - Execute a legacy (bus or class) resume callback for device.
500 * @dev: Device to resume.
501 * @cb: Resume callback to execute.
503 static int legacy_resume(struct device *dev, int (*cb)(struct device *dev))
508 calltime = initcall_debug_start(dev);
511 suspend_report_result(cb, error);
513 initcall_debug_report(dev, calltime, error);
519 * device_resume - Execute "resume" callbacks for given device.
520 * @dev: Device to handle.
521 * @state: PM transition of the system being carried out.
522 * @async: If true, the device is being resumed asynchronously.
524 static int device_resume(struct device *dev, pm_message_t state, bool async)
531 dpm_wait(dev->parent, async);
534 dev->power.status = DPM_RESUMING;
538 pm_dev_dbg(dev, state, "");
539 error = pm_op(dev, dev->bus->pm, state);
540 } else if (dev->bus->resume) {
541 pm_dev_dbg(dev, state, "legacy ");
542 error = legacy_resume(dev, dev->bus->resume);
550 pm_dev_dbg(dev, state, "type ");
551 error = pm_op(dev, dev->type->pm, state);
558 if (dev->class->pm) {
559 pm_dev_dbg(dev, state, "class ");
560 error = pm_op(dev, dev->class->pm, state);
561 } else if (dev->class->resume) {
562 pm_dev_dbg(dev, state, "legacy class ");
563 error = legacy_resume(dev, dev->class->resume);
568 complete_all(&dev->power.completion);
574 static void async_resume(void *data, async_cookie_t cookie)
576 struct device *dev = (struct device *)data;
579 error = device_resume(dev, pm_transition, true);
581 pm_dev_err(dev, pm_transition, " async", error);
585 static bool is_async(struct device *dev)
587 return dev->power.async_suspend && pm_async_enabled
588 && !pm_trace_is_enabled();
592 * dpm_resume - Execute "resume" callbacks for non-sysdev devices.
593 * @state: PM transition of the system being carried out.
595 * Execute the appropriate "resume" callback for all devices whose status
596 * indicates that they are suspended.
598 static void dpm_resume(pm_message_t state)
600 struct list_head list;
602 ktime_t starttime = ktime_get();
604 INIT_LIST_HEAD(&list);
605 mutex_lock(&dpm_list_mtx);
606 pm_transition = state;
609 list_for_each_entry(dev, &dpm_list, power.entry) {
610 if (dev->power.status < DPM_OFF)
613 INIT_COMPLETION(dev->power.completion);
616 async_schedule(async_resume, dev);
620 while (!list_empty(&dpm_list)) {
621 dev = to_device(dpm_list.next);
623 if (dev->power.status >= DPM_OFF && !is_async(dev)) {
626 mutex_unlock(&dpm_list_mtx);
628 error = device_resume(dev, state, false);
630 mutex_lock(&dpm_list_mtx);
632 pm_dev_err(dev, state, "", error);
633 } else if (dev->power.status == DPM_SUSPENDING) {
634 /* Allow new children of the device to be registered */
635 dev->power.status = DPM_RESUMING;
637 if (!list_empty(&dev->power.entry))
638 list_move_tail(&dev->power.entry, &list);
641 list_splice(&list, &dpm_list);
642 mutex_unlock(&dpm_list_mtx);
643 async_synchronize_full();
644 dpm_show_time(starttime, state, NULL);
648 * device_complete - Complete a PM transition for given device.
649 * @dev: Device to handle.
650 * @state: PM transition of the system being carried out.
652 static void device_complete(struct device *dev, pm_message_t state)
656 if (dev->class && dev->class->pm && dev->class->pm->complete) {
657 pm_dev_dbg(dev, state, "completing class ");
658 dev->class->pm->complete(dev);
661 if (dev->type && dev->type->pm && dev->type->pm->complete) {
662 pm_dev_dbg(dev, state, "completing type ");
663 dev->type->pm->complete(dev);
666 if (dev->bus && dev->bus->pm && dev->bus->pm->complete) {
667 pm_dev_dbg(dev, state, "completing ");
668 dev->bus->pm->complete(dev);
675 * dpm_complete - Complete a PM transition for all non-sysdev devices.
676 * @state: PM transition of the system being carried out.
678 * Execute the ->complete() callbacks for all devices whose PM status is not
679 * DPM_ON (this allows new devices to be registered).
681 static void dpm_complete(pm_message_t state)
683 struct list_head list;
685 INIT_LIST_HEAD(&list);
686 mutex_lock(&dpm_list_mtx);
687 transition_started = false;
688 while (!list_empty(&dpm_list)) {
689 struct device *dev = to_device(dpm_list.prev);
692 if (dev->power.status > DPM_ON) {
693 dev->power.status = DPM_ON;
694 mutex_unlock(&dpm_list_mtx);
696 device_complete(dev, state);
697 pm_runtime_put_sync(dev);
699 mutex_lock(&dpm_list_mtx);
701 if (!list_empty(&dev->power.entry))
702 list_move(&dev->power.entry, &list);
705 list_splice(&list, &dpm_list);
706 mutex_unlock(&dpm_list_mtx);
710 * dpm_resume_end - Execute "resume" callbacks and complete system transition.
711 * @state: PM transition of the system being carried out.
713 * Execute "resume" callbacks for all devices and complete the PM transition of
716 void dpm_resume_end(pm_message_t state)
722 EXPORT_SYMBOL_GPL(dpm_resume_end);
725 /*------------------------- Suspend routines -------------------------*/
728 * resume_event - Return a "resume" message for given "suspend" sleep state.
729 * @sleep_state: PM message representing a sleep state.
731 * Return a PM message representing the resume event corresponding to given
734 static pm_message_t resume_event(pm_message_t sleep_state)
736 switch (sleep_state.event) {
737 case PM_EVENT_SUSPEND:
739 case PM_EVENT_FREEZE:
740 case PM_EVENT_QUIESCE:
742 case PM_EVENT_HIBERNATE:
749 * device_suspend_noirq - Execute a "late suspend" callback for given device.
750 * @dev: Device to handle.
751 * @state: PM transition of the system being carried out.
753 * The driver of @dev will not receive interrupts while this function is being
756 static int device_suspend_noirq(struct device *dev, pm_message_t state)
760 if (dev->class && dev->class->pm) {
761 pm_dev_dbg(dev, state, "LATE class ");
762 error = pm_noirq_op(dev, dev->class->pm, state);
767 if (dev->type && dev->type->pm) {
768 pm_dev_dbg(dev, state, "LATE type ");
769 error = pm_noirq_op(dev, dev->type->pm, state);
774 if (dev->bus && dev->bus->pm) {
775 pm_dev_dbg(dev, state, "LATE ");
776 error = pm_noirq_op(dev, dev->bus->pm, state);
784 * dpm_suspend_noirq - Execute "late suspend" callbacks for non-sysdev devices.
785 * @state: PM transition of the system being carried out.
787 * Prevent device drivers from receiving interrupts and call the "noirq" suspend
788 * handlers for all non-sysdev devices.
790 int dpm_suspend_noirq(pm_message_t state)
793 ktime_t starttime = ktime_get();
796 suspend_device_irqs();
797 mutex_lock(&dpm_list_mtx);
798 list_for_each_entry_reverse(dev, &dpm_list, power.entry) {
799 error = device_suspend_noirq(dev, state);
801 pm_dev_err(dev, state, " late", error);
804 dev->power.status = DPM_OFF_IRQ;
806 mutex_unlock(&dpm_list_mtx);
808 dpm_resume_noirq(resume_event(state));
810 dpm_show_time(starttime, state, "late");
813 EXPORT_SYMBOL_GPL(dpm_suspend_noirq);
816 * legacy_suspend - Execute a legacy (bus or class) suspend callback for device.
817 * @dev: Device to suspend.
818 * @state: PM transition of the system being carried out.
819 * @cb: Suspend callback to execute.
821 static int legacy_suspend(struct device *dev, pm_message_t state,
822 int (*cb)(struct device *dev, pm_message_t state))
827 calltime = initcall_debug_start(dev);
829 error = cb(dev, state);
830 suspend_report_result(cb, error);
832 initcall_debug_report(dev, calltime, error);
838 * device_suspend - Execute "suspend" callbacks for given device.
839 * @dev: Device to handle.
840 * @state: PM transition of the system being carried out.
841 * @async: If true, the device is being suspended asynchronously.
843 static int __device_suspend(struct device *dev, pm_message_t state, bool async)
847 dpm_wait_for_children(dev, async);
854 if (dev->class->pm) {
855 pm_dev_dbg(dev, state, "class ");
856 error = pm_op(dev, dev->class->pm, state);
857 } else if (dev->class->suspend) {
858 pm_dev_dbg(dev, state, "legacy class ");
859 error = legacy_suspend(dev, state, dev->class->suspend);
867 pm_dev_dbg(dev, state, "type ");
868 error = pm_op(dev, dev->type->pm, state);
876 pm_dev_dbg(dev, state, "");
877 error = pm_op(dev, dev->bus->pm, state);
878 } else if (dev->bus->suspend) {
879 pm_dev_dbg(dev, state, "legacy ");
880 error = legacy_suspend(dev, state, dev->bus->suspend);
885 dev->power.status = DPM_OFF;
889 complete_all(&dev->power.completion);
897 static void async_suspend(void *data, async_cookie_t cookie)
899 struct device *dev = (struct device *)data;
902 error = __device_suspend(dev, pm_transition, true);
904 pm_dev_err(dev, pm_transition, " async", error);
909 static int device_suspend(struct device *dev)
911 INIT_COMPLETION(dev->power.completion);
913 if (pm_async_enabled && dev->power.async_suspend) {
915 async_schedule(async_suspend, dev);
919 return __device_suspend(dev, pm_transition, false);
923 * dpm_suspend - Execute "suspend" callbacks for all non-sysdev devices.
924 * @state: PM transition of the system being carried out.
926 static int dpm_suspend(pm_message_t state)
928 struct list_head list;
929 ktime_t starttime = ktime_get();
932 INIT_LIST_HEAD(&list);
933 mutex_lock(&dpm_list_mtx);
934 pm_transition = state;
936 while (!list_empty(&dpm_list)) {
937 struct device *dev = to_device(dpm_list.prev);
940 mutex_unlock(&dpm_list_mtx);
942 error = device_suspend(dev);
944 mutex_lock(&dpm_list_mtx);
946 pm_dev_err(dev, state, "", error);
950 if (!list_empty(&dev->power.entry))
951 list_move(&dev->power.entry, &list);
956 list_splice(&list, dpm_list.prev);
957 mutex_unlock(&dpm_list_mtx);
958 async_synchronize_full();
962 dpm_show_time(starttime, state, NULL);
967 * device_prepare - Prepare a device for system power transition.
968 * @dev: Device to handle.
969 * @state: PM transition of the system being carried out.
971 * Execute the ->prepare() callback(s) for given device. No new children of the
972 * device may be registered after this function has returned.
974 static int device_prepare(struct device *dev, pm_message_t state)
980 if (dev->bus && dev->bus->pm && dev->bus->pm->prepare) {
981 pm_dev_dbg(dev, state, "preparing ");
982 error = dev->bus->pm->prepare(dev);
983 suspend_report_result(dev->bus->pm->prepare, error);
988 if (dev->type && dev->type->pm && dev->type->pm->prepare) {
989 pm_dev_dbg(dev, state, "preparing type ");
990 error = dev->type->pm->prepare(dev);
991 suspend_report_result(dev->type->pm->prepare, error);
996 if (dev->class && dev->class->pm && dev->class->pm->prepare) {
997 pm_dev_dbg(dev, state, "preparing class ");
998 error = dev->class->pm->prepare(dev);
999 suspend_report_result(dev->class->pm->prepare, error);
1008 * dpm_prepare - Prepare all non-sysdev devices for a system PM transition.
1009 * @state: PM transition of the system being carried out.
1011 * Execute the ->prepare() callback(s) for all devices.
1013 static int dpm_prepare(pm_message_t state)
1015 struct list_head list;
1018 INIT_LIST_HEAD(&list);
1019 mutex_lock(&dpm_list_mtx);
1020 transition_started = true;
1021 while (!list_empty(&dpm_list)) {
1022 struct device *dev = to_device(dpm_list.next);
1025 dev->power.status = DPM_PREPARING;
1026 mutex_unlock(&dpm_list_mtx);
1028 pm_runtime_get_noresume(dev);
1029 if (pm_runtime_barrier(dev) && device_may_wakeup(dev)) {
1030 /* Wake-up requested during system sleep transition. */
1031 pm_runtime_put_sync(dev);
1034 error = device_prepare(dev, state);
1037 mutex_lock(&dpm_list_mtx);
1039 dev->power.status = DPM_ON;
1040 if (error == -EAGAIN) {
1045 printk(KERN_ERR "PM: Failed to prepare device %s "
1046 "for power transition: error %d\n",
1047 kobject_name(&dev->kobj), error);
1051 dev->power.status = DPM_SUSPENDING;
1052 if (!list_empty(&dev->power.entry))
1053 list_move_tail(&dev->power.entry, &list);
1056 list_splice(&list, &dpm_list);
1057 mutex_unlock(&dpm_list_mtx);
1062 * dpm_suspend_start - Prepare devices for PM transition and suspend them.
1063 * @state: PM transition of the system being carried out.
1065 * Prepare all non-sysdev devices for system PM transition and execute "suspend"
1066 * callbacks for them.
1068 int dpm_suspend_start(pm_message_t state)
1073 error = dpm_prepare(state);
1075 error = dpm_suspend(state);
1078 EXPORT_SYMBOL_GPL(dpm_suspend_start);
1080 void __suspend_report_result(const char *function, void *fn, int ret)
1083 printk(KERN_ERR "%s(): %pF returns %d\n", function, fn, ret);
1085 EXPORT_SYMBOL_GPL(__suspend_report_result);
1088 * device_pm_wait_for_dev - Wait for suspend/resume of a device to complete.
1089 * @dev: Device to wait for.
1090 * @subordinate: Device that needs to wait for @dev.
1092 int device_pm_wait_for_dev(struct device *subordinate, struct device *dev)
1094 dpm_wait(dev, subordinate->power.async_suspend);
1097 EXPORT_SYMBOL_GPL(device_pm_wait_for_dev);