aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/base
diff options
context:
space:
mode:
authorAlan Stern <stern@rowland.harvard.edu>2007-09-21 15:36:56 -0400
committerGreg Kroah-Hartman <gregkh@suse.de>2007-10-12 17:51:12 -0400
commitcd59abfcc441b2abb4cf2cd62c1eb0f02a60e8dd (patch)
tree35b31fd683115cc7bc7dfcb2a7867469193cb17b /drivers/base
parent6d66f5cd26e4c482e986130b7572f2735a0f7e8b (diff)
PM: merge device power-management source files
This patch (as993) merges the suspend.c and resume.c files in drivers/base/power into main.c, making some public symbols private. Signed-off-by: Alan Stern <stern@rowland.harvard.edu> Acked-by: Rafael J. Wysocki <rjw@sisk.pl> Signed-off-by: Greg Kroah-Hartman <gregkh@suse.de>
Diffstat (limited to 'drivers/base')
-rw-r--r--drivers/base/power/Makefile2
-rw-r--r--drivers/base/power/main.c344
-rw-r--r--drivers/base/power/power.h32
-rw-r--r--drivers/base/power/resume.c149
-rw-r--r--drivers/base/power/suspend.c210
5 files changed, 343 insertions, 394 deletions
diff --git a/drivers/base/power/Makefile b/drivers/base/power/Makefile
index 9caeaea753a3..a803733c839e 100644
--- a/drivers/base/power/Makefile
+++ b/drivers/base/power/Makefile
@@ -1,5 +1,5 @@
1obj-y := shutdown.o 1obj-y := shutdown.o
2obj-$(CONFIG_PM_SLEEP) += main.o suspend.o resume.o sysfs.o 2obj-$(CONFIG_PM_SLEEP) += main.o sysfs.o
3obj-$(CONFIG_PM_TRACE) += trace.o 3obj-$(CONFIG_PM_TRACE) += trace.o
4 4
5ifeq ($(CONFIG_DEBUG_DRIVER),y) 5ifeq ($(CONFIG_DEBUG_DRIVER),y)
diff --git a/drivers/base/power/main.c b/drivers/base/power/main.c
index eb9f38d0aa58..0ab4ab21f564 100644
--- a/drivers/base/power/main.c
+++ b/drivers/base/power/main.c
@@ -20,19 +20,24 @@
20 */ 20 */
21 21
22#include <linux/device.h> 22#include <linux/device.h>
23#include <linux/kallsyms.h>
23#include <linux/mutex.h> 24#include <linux/mutex.h>
25#include <linux/pm.h>
26#include <linux/resume-trace.h>
24 27
28#include "../base.h"
25#include "power.h" 29#include "power.h"
26 30
27LIST_HEAD(dpm_active); 31LIST_HEAD(dpm_active);
28LIST_HEAD(dpm_off); 32static LIST_HEAD(dpm_off);
29LIST_HEAD(dpm_off_irq); 33static LIST_HEAD(dpm_off_irq);
30 34
31DEFINE_MUTEX(dpm_mtx); 35static DEFINE_MUTEX(dpm_mtx);
32DEFINE_MUTEX(dpm_list_mtx); 36static DEFINE_MUTEX(dpm_list_mtx);
33 37
34int (*platform_enable_wakeup)(struct device *dev, int is_on); 38int (*platform_enable_wakeup)(struct device *dev, int is_on);
35 39
40
36int device_pm_add(struct device *dev) 41int device_pm_add(struct device *dev)
37{ 42{
38 int error; 43 int error;
@@ -61,3 +66,334 @@ void device_pm_remove(struct device *dev)
61} 66}
62 67
63 68
69/*------------------------- Resume routines -------------------------*/
70
71/**
72 * resume_device - Restore state for one device.
73 * @dev: Device.
74 *
75 */
76
77static int resume_device(struct device * dev)
78{
79 int error = 0;
80
81 TRACE_DEVICE(dev);
82 TRACE_RESUME(0);
83
84 down(&dev->sem);
85
86 if (dev->bus && dev->bus->resume) {
87 dev_dbg(dev,"resuming\n");
88 error = dev->bus->resume(dev);
89 }
90
91 if (!error && dev->type && dev->type->resume) {
92 dev_dbg(dev,"resuming\n");
93 error = dev->type->resume(dev);
94 }
95
96 if (!error && dev->class && dev->class->resume) {
97 dev_dbg(dev,"class resume\n");
98 error = dev->class->resume(dev);
99 }
100
101 up(&dev->sem);
102
103 TRACE_RESUME(error);
104 return error;
105}
106
107
108static int resume_device_early(struct device * dev)
109{
110 int error = 0;
111
112 TRACE_DEVICE(dev);
113 TRACE_RESUME(0);
114 if (dev->bus && dev->bus->resume_early) {
115 dev_dbg(dev,"EARLY resume\n");
116 error = dev->bus->resume_early(dev);
117 }
118 TRACE_RESUME(error);
119 return error;
120}
121
122/*
123 * Resume the devices that have either not gone through
124 * the late suspend, or that did go through it but also
125 * went through the early resume
126 */
127static void dpm_resume(void)
128{
129 mutex_lock(&dpm_list_mtx);
130 while(!list_empty(&dpm_off)) {
131 struct list_head * entry = dpm_off.next;
132 struct device * dev = to_device(entry);
133
134 get_device(dev);
135 list_move_tail(entry, &dpm_active);
136
137 mutex_unlock(&dpm_list_mtx);
138 resume_device(dev);
139 mutex_lock(&dpm_list_mtx);
140 put_device(dev);
141 }
142 mutex_unlock(&dpm_list_mtx);
143}
144
145
146/**
147 * device_resume - Restore state of each device in system.
148 *
149 * Walk the dpm_off list, remove each entry, resume the device,
150 * then add it to the dpm_active list.
151 */
152
153void device_resume(void)
154{
155 might_sleep();
156 mutex_lock(&dpm_mtx);
157 dpm_resume();
158 mutex_unlock(&dpm_mtx);
159}
160
161EXPORT_SYMBOL_GPL(device_resume);
162
163
164/**
165 * dpm_power_up - Power on some devices.
166 *
167 * Walk the dpm_off_irq list and power each device up. This
168 * is used for devices that required they be powered down with
169 * interrupts disabled. As devices are powered on, they are moved
170 * to the dpm_active list.
171 *
172 * Interrupts must be disabled when calling this.
173 */
174
175static void dpm_power_up(void)
176{
177 while(!list_empty(&dpm_off_irq)) {
178 struct list_head * entry = dpm_off_irq.next;
179 struct device * dev = to_device(entry);
180
181 list_move_tail(entry, &dpm_off);
182 resume_device_early(dev);
183 }
184}
185
186
187/**
188 * device_power_up - Turn on all devices that need special attention.
189 *
190 * Power on system devices then devices that required we shut them down
191 * with interrupts disabled.
192 * Called with interrupts disabled.
193 */
194
195void device_power_up(void)
196{
197 sysdev_resume();
198 dpm_power_up();
199}
200
201EXPORT_SYMBOL_GPL(device_power_up);
202
203
204/*------------------------- Suspend routines -------------------------*/
205
206/*
207 * The entries in the dpm_active list are in a depth first order, simply
208 * because children are guaranteed to be discovered after parents, and
209 * are inserted at the back of the list on discovery.
210 *
211 * All list on the suspend path are done in reverse order, so we operate
212 * on the leaves of the device tree (or forests, depending on how you want
213 * to look at it ;) first. As nodes are removed from the back of the list,