]> www.pilppa.org Git - linux-2.6-omap-h63xx.git/blobdiff - kernel/power/main.c
Introduce new top level suspend and hibernation callbacks
[linux-2.6-omap-h63xx.git] / kernel / power / main.c
index 7fb805de19a85fd6272a6562f0ccc0e9f38fa0e7..d023b6b584e58bf8e8e1d14a83a6f85a13640a8f 100644 (file)
@@ -53,10 +53,6 @@ int pm_notifier_call_chain(unsigned long val)
                        == NOTIFY_BAD) ? -EINVAL : 0;
 }
 
-#endif /* CONFIG_PM_SLEEP */
-
-#ifdef CONFIG_SUSPEND
-
 #ifdef CONFIG_PM_DEBUG
 int pm_test_level = TEST_NONE;
 
@@ -132,6 +128,7 @@ power_attr(pm_test);
 static inline int suspend_test(int level) { return 0; }
 #endif /* !CONFIG_PM_DEBUG */
 
+#endif /* CONFIG_PM_SLEEP */
 
 #ifdef CONFIG_SUSPEND
 
@@ -178,13 +175,13 @@ static int suspend_prepare(void)
        if (!suspend_ops || !suspend_ops->enter)
                return -EPERM;
 
+       pm_prepare_console();
+
        error = pm_notifier_call_chain(PM_SUSPEND_PREPARE);
        if (error)
                goto Finish;
 
-       pm_prepare_console();
-
-       if (freeze_processes()) {
+       if (suspend_freeze_processes()) {
                error = -EAGAIN;
                goto Thaw;
        }
@@ -202,10 +199,10 @@ static int suspend_prepare(void)
                return 0;
 
  Thaw:
-       thaw_processes();
-       pm_restore_console();
+       suspend_thaw_processes();
  Finish:
        pm_notifier_call_chain(PM_POST_SUSPEND);
+       pm_restore_console();
        return error;
 }
 
@@ -231,27 +228,29 @@ static int suspend_enter(suspend_state_t state)
 {
        int error = 0;
 
+       device_pm_lock();
        arch_suspend_disable_irqs();
        BUG_ON(!irqs_disabled());
 
        if ((error = device_power_down(PMSG_SUSPEND))) {
-               printk(KERN_ERR "Some devices failed to power down\n");
+               printk(KERN_ERR "PM: Some devices failed to power down\n");
                goto Done;
        }
 
        if (!suspend_test(TEST_CORE))
                error = suspend_ops->enter(state);
 
-       device_power_up();
+       device_power_up(PMSG_RESUME);
  Done:
        arch_suspend_enable_irqs();
        BUG_ON(irqs_disabled());
+       device_pm_unlock();
        return error;
 }
 
 /**
- *     suspend_devices_and_enter - suspend devices and enter the desired system sleep
- *                       state.
+ *     suspend_devices_and_enter - suspend devices and enter the desired system
+ *                                 sleep state.
  *     @state:           state to enter
  */
 int suspend_devices_and_enter(suspend_state_t state)
@@ -261,15 +260,15 @@ int suspend_devices_and_enter(suspend_state_t state)
        if (!suspend_ops)
                return -ENOSYS;
 
-       if (suspend_ops->set_target) {
-               error = suspend_ops->set_target(state);
+       if (suspend_ops->begin) {
+               error = suspend_ops->begin(state);
                if (error)
-                       return error;
+                       goto Close;
        }
        suspend_console();
        error = device_suspend(PMSG_SUSPEND);
        if (error) {
-               printk(KERN_ERR "Some devices failed to suspend\n");
+               printk(KERN_ERR "PM: Some devices failed to suspend\n");
                goto Resume_console;
        }
 
@@ -294,9 +293,12 @@ int suspend_devices_and_enter(suspend_state_t state)
        if (suspend_ops->finish)
                suspend_ops->finish();
  Resume_devices:
-       device_resume();
+       device_resume(PMSG_RESUME);
  Resume_console:
        resume_console();
+ Close:
+       if (suspend_ops->end)
+               suspend_ops->end();
        return error;
 }
 
@@ -308,9 +310,9 @@ int suspend_devices_and_enter(suspend_state_t state)
  */
 static void suspend_finish(void)
 {
-       thaw_processes();
-       pm_restore_console();
+       suspend_thaw_processes();
        pm_notifier_call_chain(PM_POST_SUSPEND);
+       pm_restore_console();
 }
 
 
@@ -352,7 +354,7 @@ static int enter_state(suspend_state_t state)
        if (!mutex_trylock(&pm_mutex))
                return -EBUSY;
 
-       printk("Syncing filesystems ... ");
+       printk(KERN_INFO "PM: Syncing filesystems ... ");
        sys_sync();
        printk("done.\n");
 
@@ -495,7 +497,7 @@ static struct attribute * g[] = {
 #ifdef CONFIG_PM_TRACE
        &pm_trace_attr.attr,
 #endif
-#ifdef CONFIG_PM_DEBUG
+#if defined(CONFIG_PM_SLEEP) && defined(CONFIG_PM_DEBUG)
        &pm_test_attr.attr,
 #endif
        NULL,