Merge ../scsi-misc-2.6
[linux-2.6] / drivers / base / power / resume.c
1 /*
2  * resume.c - Functions for waking devices up.
3  *
4  * Copyright (c) 2003 Patrick Mochel
5  * Copyright (c) 2003 Open Source Development Labs
6  *
7  * This file is released under the GPLv2
8  *
9  */
10
11 #include <linux/device.h>
12 #include <linux/resume-trace.h>
13 #include "../base.h"
14 #include "power.h"
15
16
17 /**
18  *      resume_device - Restore state for one device.
19  *      @dev:   Device.
20  *
21  */
22
23 int resume_device(struct device * dev)
24 {
25         int error = 0;
26
27         TRACE_DEVICE(dev);
28         TRACE_RESUME(0);
29         down(&dev->sem);
30         if (dev->power.pm_parent
31                         && dev->power.pm_parent->power.power_state.event) {
32                 dev_err(dev, "PM: resume from %d, parent %s still %d\n",
33                         dev->power.power_state.event,
34                         dev->power.pm_parent->bus_id,
35                         dev->power.pm_parent->power.power_state.event);
36         }
37         if (dev->bus && dev->bus->resume) {
38                 dev_dbg(dev,"resuming\n");
39                 error = dev->bus->resume(dev);
40         }
41         up(&dev->sem);
42         TRACE_RESUME(error);
43         return error;
44 }
45
46
47
48 void dpm_resume(void)
49 {
50         down(&dpm_list_sem);
51         while(!list_empty(&dpm_off)) {
52                 struct list_head * entry = dpm_off.next;
53                 struct device * dev = to_device(entry);
54
55                 get_device(dev);
56                 list_move_tail(entry, &dpm_active);
57
58                 up(&dpm_list_sem);
59                 if (!dev->power.prev_state.event)
60                         resume_device(dev);
61                 down(&dpm_list_sem);
62                 put_device(dev);
63         }
64         up(&dpm_list_sem);
65 }
66
67
68 /**
69  *      device_resume - Restore state of each device in system.
70  *
71  *      Walk the dpm_off list, remove each entry, resume the device,
72  *      then add it to the dpm_active list.
73  */
74
75 void device_resume(void)
76 {
77         down(&dpm_sem);
78         dpm_resume();
79         up(&dpm_sem);
80 }
81
82 EXPORT_SYMBOL_GPL(device_resume);
83
84
85 /**
86  *      device_power_up_irq - Power on some devices.
87  *
88  *      Walk the dpm_off_irq list and power each device up. This
89  *      is used for devices that required they be powered down with
90  *      interrupts disabled. As devices are powered on, they are moved to
91  *      the dpm_suspended list.
92  *
93  *      Interrupts must be disabled when calling this.
94  */
95
96 void dpm_power_up(void)
97 {
98         while(!list_empty(&dpm_off_irq)) {
99                 struct list_head * entry = dpm_off_irq.next;
100                 struct device * dev = to_device(entry);
101
102                 get_device(dev);
103                 list_move_tail(entry, &dpm_active);
104                 resume_device(dev);
105                 put_device(dev);
106         }
107 }
108
109
110 /**
111  *      device_pm_power_up - Turn on all devices that need special attention.
112  *
113  *      Power on system devices then devices that required we shut them down
114  *      with interrupts disabled.
115  *      Called with interrupts disabled.
116  */
117
118 void device_power_up(void)
119 {
120         sysdev_resume();
121         dpm_power_up();
122 }
123
124 EXPORT_SYMBOL_GPL(device_power_up);
125
126