aboutsummaryrefslogtreecommitdiffstats
path: root/kernel/power/disk.c
diff options
context:
space:
mode:
Diffstat (limited to 'kernel/power/disk.c')
-rw-r--r--kernel/power/disk.c45
1 files changed, 16 insertions, 29 deletions
diff --git a/kernel/power/disk.c b/kernel/power/disk.c
index 88beec6dcd11..2d8bf054d036 100644
--- a/kernel/power/disk.c
+++ b/kernel/power/disk.c
@@ -112,24 +112,12 @@ static inline void platform_finish(void)
112 } 112 }
113} 113}
114 114
115static void finish(void)
116{
117 device_resume();
118 platform_finish();
119 thaw_processes();
120 enable_nonboot_cpus();
121 pm_restore_console();
122}
123
124
125static int prepare_processes(void) 115static int prepare_processes(void)
126{ 116{
127 int error; 117 int error;
128 118
129 pm_prepare_console(); 119 pm_prepare_console();
130
131 sys_sync(); 120 sys_sync();
132
133 disable_nonboot_cpus(); 121 disable_nonboot_cpus();
134 122
135 if (freeze_processes()) { 123 if (freeze_processes()) {
@@ -162,15 +150,6 @@ static void unprepare_processes(void)
162 pm_restore_console(); 150 pm_restore_console();
163} 151}
164 152
165static int prepare_devices(void)
166{
167 int error;
168
169 if ((error = device_suspend(PMSG_FREEZE)))
170 printk("Some devices failed to suspend\n");
171 return error;
172}
173
174/** 153/**
175 * pm_suspend_disk - The granpappy of power management. 154 * pm_suspend_disk - The granpappy of power management.
176 * 155 *
@@ -187,17 +166,14 @@ int pm_suspend_disk(void)
187 error = prepare_processes(); 166 error = prepare_processes();
188 if (error) 167 if (error)
189 return error; 168 return error;
190 error = prepare_devices();
191 169
170 error = device_suspend(PMSG_FREEZE);
192 if (error) { 171 if (error) {
172 printk("Some devices failed to suspend\n");
193 unprepare_processes(); 173 unprepare_processes();
194 return error; 174 return error;
195 } 175 }
196 176
197 pr_debug("PM: Attempting to suspend to disk.\n");
198 if (pm_disk_mode == PM_DISK_FIRMWARE)
199 return pm_ops->enter(PM_SUSPEND_DISK);
200
201 pr_debug("PM: snapshotting memory.\n"); 177 pr_debug("PM: snapshotting memory.\n");
202 in_suspend = 1; 178 in_suspend = 1;
203 if ((error = swsusp_suspend())) 179 if ((error = swsusp_suspend()))
@@ -208,11 +184,20 @@ int pm_suspend_disk(void)
208 error = swsusp_write(); 184 error = swsusp_write();
209 if (!error) 185 if (!error)
210 power_down(pm_disk_mode); 186 power_down(pm_disk_mode);
187 else {
188 /* swsusp_write can not fail in device_resume,
189 no need to do second device_resume */
190 swsusp_free();
191 unprepare_processes();
192 return error;
193 }
211 } else 194 } else
212 pr_debug("PM: Image restored successfully.\n"); 195 pr_debug("PM: Image restored successfully.\n");
196
213 swsusp_free(); 197 swsusp_free();
214 Done: 198 Done:
215 finish(); 199 device_resume();
200 unprepare_processes();
216 return error; 201 return error;
217} 202}
218 203
@@ -274,15 +259,17 @@ static int software_resume(void)
274 259
275 pr_debug("PM: Preparing devices for restore.\n"); 260 pr_debug("PM: Preparing devices for restore.\n");
276 261
277 if ((error = prepare_devices())) 262 if ((error = device_suspend(PMSG_FREEZE))) {
263 printk("Some devices failed to suspend\n");
278 goto Free; 264 goto Free;
265 }
279 266
280 mb(); 267 mb();
281 268
282 pr_debug("PM: Restoring saved image.\n"); 269 pr_debug("PM: Restoring saved image.\n");
283 swsusp_resume(); 270 swsusp_resume();
284 pr_debug("PM: Restore failed, recovering.n"); 271 pr_debug("PM: Restore failed, recovering.n");
285 finish(); 272 device_resume();
286 Free: 273 Free:
287 swsusp_free(); 274 swsusp_free();
288 Cleanup: 275 Cleanup: