Merge branch 'master' of git://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux-2.6
[linux-2.6] / drivers / base / power / main.c
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.
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  *
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.
18  */
19
20 #include <linux/device.h>
21 #include <linux/kallsyms.h>
22 #include <linux/mutex.h>
23 #include <linux/pm.h>
24 #include <linux/resume-trace.h>
25 #include <linux/rwsem.h>
26
27 #include "../base.h"
28 #include "power.h"
29
30 /*
31  * The entries in the dpm_list list are in a depth first order, simply
32  * because children are guaranteed to be discovered after parents, and
33  * are inserted at the back of the list on discovery.
34  *
35  * Since device_pm_add() may be called with a device semaphore held,
36  * we must never try to acquire a device semaphore while holding
37  * dpm_list_mutex.
38  */
39
40 LIST_HEAD(dpm_list);
41
42 static DEFINE_MUTEX(dpm_list_mtx);
43
44 /*
45  * Set once the preparation of devices for a PM transition has started, reset
46  * before starting to resume devices.  Protected by dpm_list_mtx.
47  */
48 static bool transition_started;
49
50 /**
51  *      device_pm_lock - lock the list of active devices used by the PM core
52  */
53 void device_pm_lock(void)
54 {
55         mutex_lock(&dpm_list_mtx);
56 }
57
58 /**
59  *      device_pm_unlock - unlock the list of active devices used by the PM core
60  */
61 void device_pm_unlock(void)
62 {
63         mutex_unlock(&dpm_list_mtx);
64 }
65
66 /**
67  *      device_pm_add - add a device to the list of active devices
68  *      @dev:   Device to be added to the list
69  */
70 void device_pm_add(struct device *dev)
71 {
72         pr_debug("PM: Adding info for %s:%s\n",
73                  dev->bus ? dev->bus->name : "No Bus",
74                  kobject_name(&dev->kobj));
75         mutex_lock(&dpm_list_mtx);
76         if (dev->parent) {
77                 if (dev->parent->power.status >= DPM_SUSPENDING)
78                         dev_warn(dev, "parent %s should not be sleeping\n",
79                                  dev_name(dev->parent));
80         } else if (transition_started) {
81                 /*
82                  * We refuse to register parentless devices while a PM
83                  * transition is in progress in order to avoid leaving them
84                  * unhandled down the road
85                  */
86                 dev_WARN(dev, "Parentless device registered during a PM transaction\n");
87         }
88
89         list_add_tail(&dev->power.entry, &dpm_list);
90         mutex_unlock(&dpm_list_mtx);
91 }
92
93 /**
94  *      device_pm_remove - remove a device from the list of active devices
95  *      @dev:   Device to be removed from the list
96  *
97  *      This function also removes the device's PM-related sysfs attributes.
98  */
99 void device_pm_remove(struct device *dev)
100 {
101         pr_debug("PM: Removing info for %s:%s\n",
102                  dev->bus ? dev->bus->name : "No Bus",
103                  kobject_name(&dev->kobj));
104         mutex_lock(&dpm_list_mtx);
105         list_del_init(&dev->power.entry);
106         mutex_unlock(&dpm_list_mtx);
107 }
108
109 /**
110  *      pm_op - execute the PM operation appropiate for given PM event
111  *      @dev:   Device.
112  *      @ops:   PM operations to choose from.
113  *      @state: PM transition of the system being carried out.
114  */
115 static int pm_op(struct device *dev, struct dev_pm_ops *ops,
116                         pm_message_t state)
117 {
118         int error = 0;
119
120         switch (state.event) {
121 #ifdef CONFIG_SUSPEND
122         case PM_EVENT_SUSPEND:
123                 if (ops->suspend) {
124                         error = ops->suspend(dev);
125                         suspend_report_result(ops->suspend, error);
126                 }
127                 break;
128         case PM_EVENT_RESUME:
129                 if (ops->resume) {
130                         error = ops->resume(dev);
131                         suspend_report_result(ops->resume, error);
132                 }
133                 break;
134 #endif /* CONFIG_SUSPEND */
135 #ifdef CONFIG_HIBERNATION
136         case PM_EVENT_FREEZE:
137         case PM_EVENT_QUIESCE:
138                 if (ops->freeze) {
139                         error = ops->freeze(dev);
140                         suspend_report_result(ops->freeze, error);
141                 }
142                 break;
143         case PM_EVENT_HIBERNATE:
144                 if (ops->poweroff) {
145                         error = ops->poweroff(dev);
146                         suspend_report_result(ops->poweroff, error);
147                 }
148                 break;
149         case PM_EVENT_THAW:
150         case PM_EVENT_RECOVER:
151                 if (ops->thaw) {
152                         error = ops->thaw(dev);
153                         suspend_report_result(ops->thaw, error);
154                 }
155                 break;
156         case PM_EVENT_RESTORE:
157                 if (ops->restore) {
158                         error = ops->restore(dev);
159                         suspend_report_result(ops->restore, error);
160                 }
161                 break;
162 #endif /* CONFIG_HIBERNATION */
163         default:
164                 error = -EINVAL;
165         }
166         return error;
167 }
168
169 /**
170  *      pm_noirq_op - execute the PM operation appropiate for given PM event
171  *      @dev:   Device.
172  *      @ops:   PM operations to choose from.
173  *      @state: PM transition of the system being carried out.
174  *
175  *      The operation is executed with interrupts disabled by the only remaining
176  *      functional CPU in the system.
177  */
178 static int pm_noirq_op(struct device *dev, struct dev_pm_ops *ops,
179                         pm_message_t state)
180 {
181         int error = 0;
182
183         switch (state.event) {
184 #ifdef CONFIG_SUSPEND
185         case PM_EVENT_SUSPEND:
186                 if (ops->suspend_noirq) {
187                         error = ops->suspend_noirq(dev);
188                         suspend_report_result(ops->suspend_noirq, error);
189                 }
190                 break;
191         case PM_EVENT_RESUME:
192                 if (ops->resume_noirq) {
193                         error = ops->resume_noirq(dev);
194                         suspend_report_result(ops->resume_noirq, error);
195                 }
196                 break;
197 #endif /* CONFIG_SUSPEND */
198 #ifdef CONFIG_HIBERNATION
199         case PM_EVENT_FREEZE:
200         case PM_EVENT_QUIESCE:
201                 if (ops->freeze_noirq) {
202                         error = ops->freeze_noirq(dev);
203                         suspend_report_result(ops->freeze_noirq, error);
204                 }
205                 break;
206         case PM_EVENT_HIBERNATE:
207                 if (ops->poweroff_noirq) {
208                         error = ops->poweroff_noirq(dev);
209                         suspend_report_result(ops->poweroff_noirq, error);
210                 }
211                 break;
212         case PM_EVENT_THAW:
213         case PM_EVENT_RECOVER:
214                 if (ops->thaw_noirq) {
215                         error = ops->thaw_noirq(dev);
216                         suspend_report_result(ops->thaw_noirq, error);
217                 }
218                 break;
219         case PM_EVENT_RESTORE:
220                 if (ops->restore_noirq) {
221                         error = ops->restore_noirq(dev);
222                         suspend_report_result(ops->restore_noirq, error);
223                 }
224                 break;
225 #endif /* CONFIG_HIBERNATION */
226         default:
227                 error = -EINVAL;
228         }
229         return error;
230 }
231
232 static char *pm_verb(int event)
233 {
234         switch (event) {
235         case PM_EVENT_SUSPEND:
236                 return "suspend";
237         case PM_EVENT_RESUME:
238                 return "resume";
239         case PM_EVENT_FREEZE:
240                 return "freeze";
241         case PM_EVENT_QUIESCE:
242                 return "quiesce";
243         case PM_EVENT_HIBERNATE:
244                 return "hibernate";
245         case PM_EVENT_THAW:
246                 return "thaw";
247         case PM_EVENT_RESTORE:
248                 return "restore";
249         case PM_EVENT_RECOVER:
250                 return "recover";
251         default:
252                 return "(unknown PM event)";
253         }
254 }
255
256 static void pm_dev_dbg(struct device *dev, pm_message_t state, char *info)
257 {
258         dev_dbg(dev, "%s%s%s\n", info, pm_verb(state.event),
259                 ((state.event & PM_EVENT_SLEEP) && device_may_wakeup(dev)) ?
260                 ", may wakeup" : "");
261 }
262
263 static void pm_dev_err(struct device *dev, pm_message_t state, char *info,
264                         int error)
265 {
266         printk(KERN_ERR "PM: Device %s failed to %s%s: error %d\n",
267                 kobject_name(&dev->kobj), pm_verb(state.event), info, error);
268 }
269
270 /*------------------------- Resume routines -------------------------*/
271
272 /**
273  *      resume_device_noirq - Power on one device (early resume).
274  *      @dev:   Device.
275  *      @state: PM transition of the system being carried out.
276  *
277  *      Must be called with interrupts disabled.
278  */
279 static int resume_device_noirq(struct device *dev, pm_message_t state)
280 {
281         int error = 0;
282
283         TRACE_DEVICE(dev);
284         TRACE_RESUME(0);
285
286         if (!dev->bus)
287                 goto End;
288
289         if (dev->bus->pm) {
290                 pm_dev_dbg(dev, state, "EARLY ");
291                 error = pm_noirq_op(dev, dev->bus->pm, state);
292         } else if (dev->bus->resume_early) {
293                 pm_dev_dbg(dev, state, "legacy EARLY ");
294                 error = dev->bus->resume_early(dev);
295         }
296  End:
297         TRACE_RESUME(error);
298         return error;
299 }
300
301 /**
302  *      dpm_power_up - Power on all regular (non-sysdev) devices.
303  *      @state: PM transition of the system being carried out.
304  *
305  *      Execute the appropriate "noirq resume" callback for all devices marked
306  *      as DPM_OFF_IRQ.
307  *
308  *      Must be called with interrupts disabled and only one CPU running.
309  */
310 static void dpm_power_up(pm_message_t state)
311 {
312         struct device *dev;
313
314         list_for_each_entry(dev, &dpm_list, power.entry)
315                 if (dev->power.status > DPM_OFF) {
316                         int error;
317
318                         dev->power.status = DPM_OFF;
319                         error = resume_device_noirq(dev, state);
320                         if (error)
321                                 pm_dev_err(dev, state, " early", error);
322                 }
323 }
324
325 /**
326  *      device_power_up - Turn on all devices that need special attention.
327  *      @state: PM transition of the system being carried out.
328  *
329  *      Power on system devices, then devices that required we shut them down
330  *      with interrupts disabled.
331  *
332  *      Must be called with interrupts disabled.
333  */
334 void device_power_up(pm_message_t state)
335 {
336         dpm_power_up(state);
337 }
338 EXPORT_SYMBOL_GPL(device_power_up);
339
340 /**
341  *      resume_device - Restore state for one device.
342  *      @dev:   Device.
343  *      @state: PM transition of the system being carried out.
344  */
345 static int resume_device(struct device *dev, pm_message_t state)
346 {
347         int error = 0;
348
349         TRACE_DEVICE(dev);
350         TRACE_RESUME(0);
351
352         down(&dev->sem);
353
354         if (dev->bus) {
355                 if (dev->bus->pm) {
356                         pm_dev_dbg(dev, state, "");
357                         error = pm_op(dev, dev->bus->pm, state);
358                 } else if (dev->bus->resume) {
359                         pm_dev_dbg(dev, state, "legacy ");
360                         error = dev->bus->resume(dev);
361                 }
362                 if (error)
363                         goto End;
364         }
365
366         if (dev->type) {
367                 if (dev->type->pm) {
368                         pm_dev_dbg(dev, state, "type ");
369                         error = pm_op(dev, dev->type->pm, state);
370                 } else if (dev->type->resume) {
371                         pm_dev_dbg(dev, state, "legacy type ");
372                         error = dev->type->resume(dev);
373                 }
374                 if (error)
375                         goto End;
376         }
377
378         if (dev->class) {
379                 if (dev->class->pm) {
380                         pm_dev_dbg(dev, state, "class ");
381                         error = pm_op(dev, dev->class->pm, state);
382                 } else if (dev->class->resume) {
383                         pm_dev_dbg(dev, state, "legacy class ");
384                         error = dev->class->resume(dev);
385                 }
386         }
387  End:
388         up(&dev->sem);
389
390         TRACE_RESUME(error);
391         return error;
392 }
393
394 /**
395  *      dpm_resume - Resume every device.
396  *      @state: PM transition of the system being carried out.
397  *
398  *      Execute the appropriate "resume" callback for all devices the status of
399  *      which indicates that they are inactive.
400  */
401 static void dpm_resume(pm_message_t state)
402 {
403         struct list_head list;
404
405         INIT_LIST_HEAD(&list);
406         mutex_lock(&dpm_list_mtx);
407         transition_started = false;
408         while (!list_empty(&dpm_list)) {
409                 struct device *dev = to_device(dpm_list.next);
410
411                 get_device(dev);
412                 if (dev->power.status >= DPM_OFF) {
413                         int error;
414
415                         dev->power.status = DPM_RESUMING;
416                         mutex_unlock(&dpm_list_mtx);
417
418                         error = resume_device(dev, state);
419
420                         mutex_lock(&dpm_list_mtx);
421                         if (error)
422                                 pm_dev_err(dev, state, "", error);
423                 } else if (dev->power.status == DPM_SUSPENDING) {
424                         /* Allow new children of the device to be registered */
425                         dev->power.status = DPM_RESUMING;
426                 }
427                 if (!list_empty(&dev->power.entry))
428                         list_move_tail(&dev->power.entry, &list);
429                 put_device(dev);
430         }
431         list_splice(&list, &dpm_list);
432         mutex_unlock(&dpm_list_mtx);
433 }
434
435 /**
436  *      complete_device - Complete a PM transition for given device
437  *      @dev:   Device.
438  *      @state: PM transition of the system being carried out.
439  */
440 static void complete_device(struct device *dev, pm_message_t state)
441 {
442         down(&dev->sem);
443
444         if (dev->class && dev->class->pm && dev->class->pm->complete) {
445                 pm_dev_dbg(dev, state, "completing class ");
446                 dev->class->pm->complete(dev);
447         }
448
449         if (dev->type && dev->type->pm && dev->type->pm->complete) {
450                 pm_dev_dbg(dev, state, "completing type ");
451                 dev->type->pm->complete(dev);
452         }
453
454         if (dev->bus && dev->bus->pm && dev->bus->pm->complete) {
455                 pm_dev_dbg(dev, state, "completing ");
456                 dev->bus->pm->complete(dev);
457         }
458
459         up(&dev->sem);
460 }
461
462 /**
463  *      dpm_complete - Complete a PM transition for all devices.
464  *      @state: PM transition of the system being carried out.
465  *
466  *      Execute the ->complete() callbacks for all devices that are not marked
467  *      as DPM_ON.
468  */
469 static void dpm_complete(pm_message_t state)
470 {
471         struct list_head list;
472
473         INIT_LIST_HEAD(&list);
474         mutex_lock(&dpm_list_mtx);
475         while (!list_empty(&dpm_list)) {
476                 struct device *dev = to_device(dpm_list.prev);
477
478                 get_device(dev);
479                 if (dev->power.status > DPM_ON) {
480                         dev->power.status = DPM_ON;
481                         mutex_unlock(&dpm_list_mtx);
482
483                         complete_device(dev, state);
484
485                         mutex_lock(&dpm_list_mtx);
486                 }
487                 if (!list_empty(&dev->power.entry))
488                         list_move(&dev->power.entry, &list);
489                 put_device(dev);
490         }
491         list_splice(&list, &dpm_list);
492         mutex_unlock(&dpm_list_mtx);
493 }
494
495 /**
496  *      device_resume - Restore state of each device in system.
497  *      @state: PM transition of the system being carried out.
498  *
499  *      Resume all the devices, unlock them all, and allow new
500  *      devices to be registered once again.
501  */
502 void device_resume(pm_message_t state)
503 {
504         might_sleep();
505         dpm_resume(state);
506         dpm_complete(state);
507 }
508 EXPORT_SYMBOL_GPL(device_resume);
509
510
511 /*------------------------- Suspend routines -------------------------*/
512
513 /**
514  *      resume_event - return a PM message representing the resume event
515  *                     corresponding to given sleep state.
516  *      @sleep_state: PM message representing a sleep state.
517  */
518 static pm_message_t resume_event(pm_message_t sleep_state)
519 {
520         switch (sleep_state.event) {
521         case PM_EVENT_SUSPEND:
522                 return PMSG_RESUME;
523         case PM_EVENT_FREEZE:
524         case PM_EVENT_QUIESCE:
525                 return PMSG_RECOVER;
526         case PM_EVENT_HIBERNATE:
527                 return PMSG_RESTORE;
528         }
529         return PMSG_ON;
530 }
531
532 /**
533  *      suspend_device_noirq - Shut down one device (late suspend).
534  *      @dev:   Device.
535  *      @state: PM transition of the system being carried out.
536  *
537  *      This is called with interrupts off and only a single CPU running.
538  */
539 static int suspend_device_noirq(struct device *dev, pm_message_t state)
540 {
541         int error = 0;
542
543         if (!dev->bus)
544                 return 0;
545
546         if (dev->bus->pm) {
547                 pm_dev_dbg(dev, state, "LATE ");
548                 error = pm_noirq_op(dev, dev->bus->pm, state);
549         } else if (dev->bus->suspend_late) {
550                 pm_dev_dbg(dev, state, "legacy LATE ");
551                 error = dev->bus->suspend_late(dev, state);
552                 suspend_report_result(dev->bus->suspend_late, error);
553         }
554         return error;
555 }
556
557 /**
558  *      device_power_down - Shut down special devices.
559  *      @state: PM transition of the system being carried out.
560  *
561  *      Power down devices that require interrupts to be disabled.
562  *      Then power down system devices.
563  *
564  *      Must be called with interrupts disabled and only one CPU running.
565  */
566 int device_power_down(pm_message_t state)
567 {
568         struct device *dev;
569         int error = 0;
570
571         list_for_each_entry_reverse(dev, &dpm_list, power.entry) {
572                 error = suspend_device_noirq(dev, state);
573                 if (error) {
574                         pm_dev_err(dev, state, " late", error);
575                         break;
576                 }
577                 dev->power.status = DPM_OFF_IRQ;
578         }
579         if (error)
580                 dpm_power_up(resume_event(state));
581         return error;
582 }
583 EXPORT_SYMBOL_GPL(device_power_down);
584
585 /**
586  *      suspend_device - Save state of one device.
587  *      @dev:   Device.
588  *      @state: PM transition of the system being carried out.
589  */
590 static int suspend_device(struct device *dev, pm_message_t state)
591 {
592         int error = 0;
593
594         down(&dev->sem);
595
596         if (dev->class) {
597                 if (dev->class->pm) {
598                         pm_dev_dbg(dev, state, "class ");
599                         error = pm_op(dev, dev->class->pm, state);
600                 } else if (dev->class->suspend) {
601                         pm_dev_dbg(dev, state, "legacy class ");
602                         error = dev->class->suspend(dev, state);
603                         suspend_report_result(dev->class->suspend, error);
604                 }
605                 if (error)
606                         goto End;
607         }
608
609         if (dev->type) {
610                 if (dev->type->pm) {
611                         pm_dev_dbg(dev, state, "type ");
612                         error = pm_op(dev, dev->type->pm, state);
613                 } else if (dev->type->suspend) {
614                         pm_dev_dbg(dev, state, "legacy type ");
615                         error = dev->type->suspend(dev, state);
616                         suspend_report_result(dev->type->suspend, error);
617                 }
618                 if (error)
619                         goto End;
620         }
621
622         if (dev->bus) {
623                 if (dev->bus->pm) {
624                         pm_dev_dbg(dev, state, "");
625                         error = pm_op(dev, dev->bus->pm, state);
626                 } else if (dev->bus->suspend) {
627                         pm_dev_dbg(dev, state, "legacy ");
628                         error = dev->bus->suspend(dev, state);
629                         suspend_report_result(dev->bus->suspend, error);
630                 }
631         }
632  End:
633         up(&dev->sem);
634
635         return error;
636 }
637
638 /**
639  *      dpm_suspend - Suspend every device.
640  *      @state: PM transition of the system being carried out.
641  *
642  *      Execute the appropriate "suspend" callbacks for all devices.
643  */
644 static int dpm_suspend(pm_message_t state)
645 {
646         struct list_head list;
647         int error = 0;
648
649         INIT_LIST_HEAD(&list);
650         mutex_lock(&dpm_list_mtx);
651         while (!list_empty(&dpm_list)) {
652                 struct device *dev = to_device(dpm_list.prev);
653
654                 get_device(dev);
655                 mutex_unlock(&dpm_list_mtx);
656
657                 error = suspend_device(dev, state);
658
659                 mutex_lock(&dpm_list_mtx);
660                 if (error) {
661                         pm_dev_err(dev, state, "", error);
662                         put_device(dev);
663                         break;
664                 }
665                 dev->power.status = DPM_OFF;
666                 if (!list_empty(&dev->power.entry))
667                         list_move(&dev->power.entry, &list);
668                 put_device(dev);
669         }
670         list_splice(&list, dpm_list.prev);
671         mutex_unlock(&dpm_list_mtx);
672         return error;
673 }
674
675 /**
676  *      prepare_device - Execute the ->prepare() callback(s) for given device.
677  *      @dev:   Device.
678  *      @state: PM transition of the system being carried out.
679  */
680 static int prepare_device(struct device *dev, pm_message_t state)
681 {
682         int error = 0;
683
684         down(&dev->sem);
685
686         if (dev->bus && dev->bus->pm && dev->bus->pm->prepare) {
687                 pm_dev_dbg(dev, state, "preparing ");
688                 error = dev->bus->pm->prepare(dev);
689                 suspend_report_result(dev->bus->pm->prepare, error);
690                 if (error)
691                         goto End;
692         }
693
694         if (dev->type && dev->type->pm && dev->type->pm->prepare) {
695                 pm_dev_dbg(dev, state, "preparing type ");
696                 error = dev->type->pm->prepare(dev);
697                 suspend_report_result(dev->type->pm->prepare, error);
698                 if (error)
699                         goto End;
700         }
701
702         if (dev->class && dev->class->pm && dev->class->pm->prepare) {
703                 pm_dev_dbg(dev, state, "preparing class ");
704                 error = dev->class->pm->prepare(dev);
705                 suspend_report_result(dev->class->pm->prepare, error);
706         }
707  End:
708         up(&dev->sem);
709
710         return error;
711 }
712
713 /**
714  *      dpm_prepare - Prepare all devices for a PM transition.
715  *      @state: PM transition of the system being carried out.
716  *
717  *      Execute the ->prepare() callback for all devices.
718  */
719 static int dpm_prepare(pm_message_t state)
720 {
721         struct list_head list;
722         int error = 0;
723
724         INIT_LIST_HEAD(&list);
725         mutex_lock(&dpm_list_mtx);
726         transition_started = true;
727         while (!list_empty(&dpm_list)) {
728                 struct device *dev = to_device(dpm_list.next);
729
730                 get_device(dev);
731                 dev->power.status = DPM_PREPARING;
732                 mutex_unlock(&dpm_list_mtx);
733
734                 error = prepare_device(dev, state);
735
736                 mutex_lock(&dpm_list_mtx);
737                 if (error) {
738                         dev->power.status = DPM_ON;
739                         if (error == -EAGAIN) {
740                                 put_device(dev);
741                                 continue;
742                         }
743                         printk(KERN_ERR "PM: Failed to prepare device %s "
744                                 "for power transition: error %d\n",
745                                 kobject_name(&dev->kobj), error);
746                         put_device(dev);
747                         break;
748                 }
749                 dev->power.status = DPM_SUSPENDING;
750                 if (!list_empty(&dev->power.entry))
751                         list_move_tail(&dev->power.entry, &list);
752                 put_device(dev);
753         }
754         list_splice(&list, &dpm_list);
755         mutex_unlock(&dpm_list_mtx);
756         return error;
757 }
758
759 /**
760  *      device_suspend - Save state and stop all devices in system.
761  *      @state: PM transition of the system being carried out.
762  *
763  *      Prepare and suspend all devices.
764  */
765 int device_suspend(pm_message_t state)
766 {
767         int error;
768
769         might_sleep();
770         error = dpm_prepare(state);
771         if (!error)
772                 error = dpm_suspend(state);
773         return error;
774 }
775 EXPORT_SYMBOL_GPL(device_suspend);
776
777 void __suspend_report_result(const char *function, void *fn, int ret)
778 {
779         if (ret)
780                 printk(KERN_ERR "%s(): %pF returns %d\n", function, fn, ret);
781 }
782 EXPORT_SYMBOL_GPL(__suspend_report_result);