power management: implement pm_ops.valid for everybody
authorJohannes Berg <johannes@sipsolutions.net>
Mon, 30 Apr 2007 22:09:54 +0000 (15:09 -0700)
committerLinus Torvalds <torvalds@woody.linux-foundation.org>
Mon, 30 Apr 2007 23:40:40 +0000 (16:40 -0700)
Almost all users of pm_ops only support mem sleep, don't check in .valid and
don't reject any others in .prepare so users can be confused if they check
/sys/power/state, especially when new states are added (these would then
result in s-t-r although they're supposed to be something different).

This patch implements a generic pm_valid_only_mem function that is then
exported for users and puts it to use in almost all existing pm_ops.

Signed-off-by: Johannes Berg <johannes@sipsolutions.net>
Cc: David Brownell <david-b@pacbell.net>
Acked-by: Pavel Machek <pavel@ucw.cz>
Cc: linux-pm@lists.linux-foundation.org
Cc: Len Brown <lenb@kernel.org>
Acked-by: Russell King <rmk@arm.linux.org.uk>
Cc: Greg KH <greg@kroah.com>
Cc: "Rafael J. Wysocki" <rjw@sisk.pl>
Cc: Paul Mundt <lethal@linux-sh.org>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
arch/arm/common/sharpsl_pm.c
arch/arm/mach-omap1/pm.c
arch/arm/mach-omap2/pm.c
arch/arm/mach-pnx4008/pm.c
arch/arm/mach-pxa/pm.c
arch/arm/mach-sa1100/pm.c
arch/arm/plat-s3c24xx/pm.c
arch/sh/boards/hp6xx/pm.c
drivers/acpi/sleep/main.c
include/linux/pm.h
kernel/power/main.c

index 4cb895d4ae5be84ef9d777d2f3f62fc1d4177ffa..5972df2b9af479a6f54f770baddca6419ad5f3bd 100644 (file)
@@ -769,6 +769,7 @@ static struct pm_ops sharpsl_pm_ops = {
        .prepare        = pxa_pm_prepare,
        .enter          = corgi_pxa_pm_enter,
        .finish         = pxa_pm_finish,
+       .valid          = pm_valid_only_mem,
 };
 
 static int __init sharpsl_pm_probe(struct platform_device *pdev)
index 4248117e5e3f61502cc8157b056c9f0d978bbcb2..0383ab334270fe84174890fb1d21e8534b8bbde0 100644 (file)
@@ -701,6 +701,7 @@ static struct pm_ops omap_pm_ops ={
        .prepare        = omap_pm_prepare,
        .enter          = omap_pm_enter,
        .finish         = omap_pm_finish,
+       .valid          = pm_valid_only_mem,
 };
 
 static int __init omap_pm_init(void)
index 3e9a128feea1c002be11d8df078fca137ca08201..6f4a5436d0ce858f33598f3f6fb77800614a6318 100644 (file)
@@ -373,6 +373,7 @@ static struct pm_ops omap_pm_ops = {
        .prepare        = omap2_pm_prepare,
        .enter          = omap2_pm_enter,
        .finish         = omap2_pm_finish,
+       .valid          = pm_valid_only_mem,
 };
 
 int __init omap2_pm_init(void)
index 3649cd3dfc9af4abe0ffe07cf1bbd66dc352aef8..2a137f33f752698daac232049e4fcd3309d30581 100644 (file)
@@ -107,50 +107,19 @@ static int pnx4008_pm_enter(suspend_state_t state)
        case PM_SUSPEND_MEM:
                pnx4008_suspend();
                break;
-       case PM_SUSPEND_DISK:
-               return -ENOTSUPP;
-       default:
-               return -EINVAL;
        }
        return 0;
 }
 
-/*
- * Called after processes are frozen, but before we shut down devices.
- */
-static int pnx4008_pm_prepare(suspend_state_t state)
-{
-       switch (state) {
-       case PM_SUSPEND_STANDBY:
-       case PM_SUSPEND_MEM:
-               break;
-
-       case PM_SUSPEND_DISK:
-               return -ENOTSUPP;
-               break;
-
-       default:
-               return -EINVAL;
-               break;
-       }
-       return 0;
-}
-
-/*
- * Called after devices are re-setup, but before processes are thawed.
- */
-static int pnx4008_pm_finish(suspend_state_t state)
+static int pnx4008_pm_valid(suspend_state_t state)
 {
-       return 0;
+       return (state == PM_SUSPEND_STANDBY) ||
+              (state == PM_SUSPEND_MEM);
 }
 
-/*
- * Set to PM_DISK_FIRMWARE so we can quickly veto suspend-to-disk.
- */
 static struct pm_ops pnx4008_pm_ops = {
-       .prepare = pnx4008_pm_prepare,
        .enter = pnx4008_pm_enter,
-       .finish = pnx4008_pm_finish,
+       .valid = pnx4008_pm_valid,
 };
 
 static int __init pnx4008_pm_init(void)
index 0a99ef43b36fdc3cfe7d5c26f58b3c7bbb2a584b..6bf15ae73848efc667689d28661944e00a84d167 100644 (file)
@@ -227,6 +227,7 @@ static struct pm_ops pxa_pm_ops = {
        .prepare        = pxa_pm_prepare,
        .enter          = pxa_pm_enter,
        .finish         = pxa_pm_finish,
+       .valid          = pm_valid_only_mem,
 };
 
 static int __init pxa_pm_init(void)
index b0837113b2aa69f4b18bcc57a7ebccd52a685ca6..d674cf3431567c88bdf5181ef99a7ab17c04fb36 100644 (file)
@@ -133,6 +133,7 @@ unsigned long sleep_phys_sp(void *sp)
 
 static struct pm_ops sa11x0_pm_ops = {
        .enter          = sa11x0_pm_enter,
+       .valid          = pm_valid_only_mem,
 };
 
 static int __init sa11x0_pm_init(void)
index d6af3082af30d4c8a4a9ec1e95bbd1cd1f3269e2..c6b03f8ab2602076c58c86a7ae6d7a8318b095b7 100644 (file)
@@ -612,26 +612,9 @@ static int s3c2410_pm_enter(suspend_state_t state)
        return 0;
 }
 
-/*
- * Called after processes are frozen, but before we shut down devices.
- */
-static int s3c2410_pm_prepare(suspend_state_t state)
-{
-       return 0;
-}
-
-/*
- * Called after devices are re-setup, but before processes are thawed.
- */
-static int s3c2410_pm_finish(suspend_state_t state)
-{
-       return 0;
-}
-
 static struct pm_ops s3c2410_pm_ops = {
-       .prepare        = s3c2410_pm_prepare,
        .enter          = s3c2410_pm_enter,
-       .finish         = s3c2410_pm_finish,
+       .valid          = pm_valid_only_mem,
 };
 
 /* s3c2410_pm_init
index 4b2f29a4bde9e5ff496428a283dbfa60debc140b..8143d1b948e7e2b4d33820abba8d5984866c8eaf 100644 (file)
@@ -69,6 +69,7 @@ static int hp6x0_pm_enter(suspend_state_t state)
 
 static struct pm_ops hp6x0_pm_ops = {
        .enter          = hp6x0_pm_enter,
+       .valid          = pm_valid_only_mem,
 };
 
 static int __init hp6x0_pm_init(void)
index 37a0930fc0a6ac538fbb2407e3ebb6f71a203753..f8c63410bcbf55eb285e88f2d156ec95634d390f 100644 (file)
@@ -168,9 +168,18 @@ int acpi_suspend(u32 acpi_state)
 
 static int acpi_pm_state_valid(suspend_state_t pm_state)
 {
-       u32 acpi_state = acpi_suspend_states[pm_state];
+       u32 acpi_state;
+
+       switch (pm_state) {
+       case PM_SUSPEND_ON:
+       case PM_SUSPEND_STANDBY:
+       case PM_SUSPEND_MEM:
+               acpi_state = acpi_suspend_states[pm_state];
 
-       return sleep_states[acpi_state];
+               return sleep_states[acpi_state];
+       default:
+               return 0;
+       }
 }
 
 static struct pm_ops acpi_pm_ops = {
index c2a55f94c29afecc040ec744cbd060a13fdb487d..6035209cf31ebca6f1ff3da3a142808604f0979c 100644 (file)
@@ -128,6 +128,9 @@ typedef int __bitwise suspend_disk_method_t;
  *     always valid and never passed to this call.
  *     If not assigned, all suspend states are advertised as valid
  *     in /sys/power/state (but can still be rejected by prepare or enter.)
+ *     Since new states can be added for other platforms, you should
+ *     assign this callback. There is a %pm_valid_only_mem function
+ *     available if you only implemented mem sleep.
  *
  * @prepare: Prepare the platform for the given suspend state. Can return a
  *     negative error code if necessary.
@@ -165,6 +168,7 @@ extern void pm_set_ops(struct pm_ops *pm_ops);
 extern struct pm_ops *pm_ops;
 extern int pm_suspend(suspend_state_t state);
 
+extern int pm_valid_only_mem(suspend_state_t state);
 
 /**
  * arch_suspend_disable_irqs - disable IRQs for suspend
index 053c0a7d7f5754095866e4e31236816d667a0eee..f94f4e20115a665ae8cb20c3f6a7f0c4c0c9cd0e 100644 (file)
@@ -48,6 +48,19 @@ void pm_set_ops(struct pm_ops * ops)
        mutex_unlock(&pm_mutex);
 }
 
+/**
+ * pm_valid_only_mem - generic memory-only valid callback
+ *
+ * pm_ops drivers that implement mem suspend only and only need
+ * to check for that in their .valid callback can use this instead
+ * of rolling their own .valid callback.
+ */
+int pm_valid_only_mem(suspend_state_t state)
+{
+       return state == PM_SUSPEND_MEM;
+}
+
+
 static inline void pm_finish(suspend_state_t state)
 {
        if (pm_ops->finish)