aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJohannes Berg <johannes@sipsolutions.net>2007-04-30 18:09:54 -0400
committerLinus Torvalds <torvalds@woody.linux-foundation.org>2007-04-30 19:40:40 -0400
commite8c9c502690efd24b7055bf608e7a3c34216848b (patch)
tree1583f34ec9cac07ddfdcb24de66e49718b107436
parent11d77d0c01b80e44c7aceb21928508dafce774f9 (diff)
power management: implement pm_ops.valid for everybody
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>
-rw-r--r--arch/arm/common/sharpsl_pm.c1
-rw-r--r--arch/arm/mach-omap1/pm.c1
-rw-r--r--arch/arm/mach-omap2/pm.c1
-rw-r--r--arch/arm/mach-pnx4008/pm.c39
-rw-r--r--arch/arm/mach-pxa/pm.c1
-rw-r--r--arch/arm/mach-sa1100/pm.c1
-rw-r--r--arch/arm/plat-s3c24xx/pm.c19
-rw-r--r--arch/sh/boards/hp6xx/pm.c1
-rw-r--r--drivers/acpi/sleep/main.c13
-rw-r--r--include/linux/pm.h4
-rw-r--r--kernel/power/main.c13
11 files changed, 39 insertions, 55 deletions
diff --git a/arch/arm/common/sharpsl_pm.c b/arch/arm/common/sharpsl_pm.c
index 4cb895d4ae5b..5972df2b9af4 100644
--- a/arch/arm/common/sharpsl_pm.c
+++ b/arch/arm/common/sharpsl_pm.c
@@ -769,6 +769,7 @@ static struct pm_ops sharpsl_pm_ops = {
769 .prepare = pxa_pm_prepare, 769 .prepare = pxa_pm_prepare,
770 .enter = corgi_pxa_pm_enter, 770 .enter = corgi_pxa_pm_enter,
771 .finish = pxa_pm_finish, 771 .finish = pxa_pm_finish,
772 .valid = pm_valid_only_mem,
772}; 773};
773 774
774static int __init sharpsl_pm_probe(struct platform_device *pdev) 775static int __init sharpsl_pm_probe(struct platform_device *pdev)
diff --git a/arch/arm/mach-omap1/pm.c b/arch/arm/mach-omap1/pm.c
index 4248117e5e3f..0383ab334270 100644
--- a/arch/arm/mach-omap1/pm.c
+++ b/arch/arm/mach-omap1/pm.c
@@ -701,6 +701,7 @@ static struct pm_ops omap_pm_ops ={
701 .prepare = omap_pm_prepare, 701 .prepare = omap_pm_prepare,
702 .enter = omap_pm_enter, 702 .enter = omap_pm_enter,
703 .finish = omap_pm_finish, 703 .finish = omap_pm_finish,
704 .valid = pm_valid_only_mem,
704}; 705};
705 706
706static int __init omap_pm_init(void) 707static int __init omap_pm_init(void)
diff --git a/arch/arm/mach-omap2/pm.c b/arch/arm/mach-omap2/pm.c
index 3e9a128feea1..6f4a5436d0ce 100644
--- a/arch/arm/mach-omap2/pm.c
+++ b/arch/arm/mach-omap2/pm.c
@@ -373,6 +373,7 @@ static struct pm_ops omap_pm_ops = {
373 .prepare = omap2_pm_prepare, 373 .prepare = omap2_pm_prepare,
374 .enter = omap2_pm_enter, 374 .enter = omap2_pm_enter,
375 .finish = omap2_pm_finish, 375 .finish = omap2_pm_finish,
376 .valid = pm_valid_only_mem,
376}; 377};
377 378
378int __init omap2_pm_init(void) 379int __init omap2_pm_init(void)
diff --git a/arch/arm/mach-pnx4008/pm.c b/arch/arm/mach-pnx4008/pm.c
index 3649cd3dfc9a..2a137f33f752 100644
--- a/arch/arm/mach-pnx4008/pm.c
+++ b/arch/arm/mach-pnx4008/pm.c
@@ -107,50 +107,19 @@ static int pnx4008_pm_enter(suspend_state_t state)
107 case PM_SUSPEND_MEM: 107 case PM_SUSPEND_MEM:
108 pnx4008_suspend(); 108 pnx4008_suspend();
109 break; 109 break;
110 case PM_SUSPEND_DISK:
111 return -ENOTSUPP;
112 default:
113 return -EINVAL;
114 } 110 }
115 return 0; 111 return 0;
116} 112}
117 113
118/* 114static int pnx4008_pm_valid(suspend_state_t state)
119 * Called after processes are frozen, but before we shut down devices.
120 */
121static int pnx4008_pm_prepare(suspend_state_t state)
122{
123 switch (state) {
124 case PM_SUSPEND_STANDBY:
125 case PM_SUSPEND_MEM:
126 break;
127
128 case PM_SUSPEND_DISK:
129 return -ENOTSUPP;
130 break;
131
132 default:
133 return -EINVAL;
134 break;
135 }
136 return 0;
137}
138
139/*
140 * Called after devices are re-setup, but before processes are thawed.
141 */
142static int pnx4008_pm_finish(suspend_state_t state)
143{ 115{
144 return 0; 116 return (state == PM_SUSPEND_STANDBY) ||
117 (state == PM_SUSPEND_MEM);
145} 118}
146 119
147/*
148 * Set to PM_DISK_FIRMWARE so we can quickly veto suspend-to-disk.
149 */
150static struct pm_ops pnx4008_pm_ops = { 120static struct pm_ops pnx4008_pm_ops = {
151 .prepare = pnx4008_pm_prepare,
152 .enter = pnx4008_pm_enter, 121 .enter = pnx4008_pm_enter,
153 .finish = pnx4008_pm_finish, 122 .valid = pnx4008_pm_valid,
154}; 123};
155 124
156static int __init pnx4008_pm_init(void) 125static int __init pnx4008_pm_init(void)
diff --git a/arch/arm/mach-pxa/pm.c b/arch/arm/mach-pxa/pm.c
index 0a99ef43b36f..6bf15ae73848 100644
--- a/arch/arm/mach-pxa/pm.c
+++ b/arch/arm/mach-pxa/pm.c
@@ -227,6 +227,7 @@ static struct pm_ops pxa_pm_ops = {
227 .prepare = pxa_pm_prepare, 227 .prepare = pxa_pm_prepare,
228 .enter = pxa_pm_enter, 228 .enter = pxa_pm_enter,
229 .finish = pxa_pm_finish, 229 .finish = pxa_pm_finish,
230 .valid = pm_valid_only_mem,
230}; 231};
231 232
232static int __init pxa_pm_init(void) 233static int __init pxa_pm_init(void)
diff --git a/arch/arm/mach-sa1100/pm.c b/arch/arm/mach-sa1100/pm.c
index b0837113b2aa..d674cf343156 100644
--- a/arch/arm/mach-sa1100/pm.c
+++ b/arch/arm/mach-sa1100/pm.c
@@ -133,6 +133,7 @@ unsigned long sleep_phys_sp(void *sp)
133 133
134static struct pm_ops sa11x0_pm_ops = { 134static struct pm_ops sa11x0_pm_ops = {
135 .enter = sa11x0_pm_enter, 135 .enter = sa11x0_pm_enter,
136 .valid = pm_valid_only_mem,
136}; 137};
137 138
138static int __init sa11x0_pm_init(void) 139static int __init sa11x0_pm_init(void)
diff --git a/arch/arm/plat-s3c24xx/pm.c b/arch/arm/plat-s3c24xx/pm.c
index d6af3082af30..c6b03f8ab260 100644
--- a/arch/arm/plat-s3c24xx/pm.c
+++ b/arch/arm/plat-s3c24xx/pm.c
@@ -612,26 +612,9 @@ static int s3c2410_pm_enter(suspend_state_t state)
612 return 0; 612 return 0;
613} 613}
614 614
615/*
616 * Called after processes are frozen, but before we shut down devices.
617 */
618static int s3c2410_pm_prepare(suspend_state_t state)
619{
620 return 0;
621}
622
623/*
624 * Called after devices are re-setup, but before processes are thawed.
625 */
626static int s3c2410_pm_finish(suspend_state_t state)
627{
628 return 0;
629}
630
631static struct pm_ops s3c2410_pm_ops = { 615static struct pm_ops s3c2410_pm_ops = {
632 .prepare = s3c2410_pm_prepare,
633 .enter = s3c2410_pm_enter, 616 .enter = s3c2410_pm_enter,
634 .finish = s3c2410_pm_finish, 617 .valid = pm_valid_only_mem,
635}; 618};
636 619
637/* s3c2410_pm_init 620/* s3c2410_pm_init
diff --git a/arch/sh/boards/hp6xx/pm.c b/arch/sh/boards/hp6xx/pm.c
index 4b2f29a4bde9..8143d1b948e7 100644
--- a/arch/sh/boards/hp6xx/pm.c
+++ b/arch/sh/boards/hp6xx/pm.c
@@ -69,6 +69,7 @@ static int hp6x0_pm_enter(suspend_state_t state)
69 69
70static struct pm_ops hp6x0_pm_ops = { 70static struct pm_ops hp6x0_pm_ops = {
71 .enter = hp6x0_pm_enter, 71 .enter = hp6x0_pm_enter,
72 .valid = pm_valid_only_mem,
72}; 73};
73 74
74static int __init hp6x0_pm_init(void) 75static int __init hp6x0_pm_init(void)
diff --git a/drivers/acpi/sleep/main.c b/drivers/acpi/sleep/main.c
index 37a0930fc0a6..f8c63410bcbf 100644
--- a/drivers/acpi/sleep/main.c
+++ b/drivers/acpi/sleep/main.c
@@ -168,9 +168,18 @@ int acpi_suspend(u32 acpi_state)
168 168
169static int acpi_pm_state_valid(suspend_state_t pm_state) 169static int acpi_pm_state_valid(suspend_state_t pm_state)
170{ 170{
171 u32 acpi_state = acpi_suspend_states[pm_state]; 171 u32 acpi_state;
172
173 switch (pm_state) {
174 case PM_SUSPEND_ON:
175 case PM_SUSPEND_STANDBY:
176 case PM_SUSPEND_MEM:
177 acpi_state = acpi_suspend_states[pm_state];
172 178
173 return sleep_states[acpi_state]; 179 return sleep_states[acpi_state];
180 default:
181 return 0;
182 }
174} 183}
175 184
176static struct pm_ops acpi_pm_ops = { 185static struct pm_ops acpi_pm_ops = {
diff --git a/include/linux/pm.h b/include/linux/pm.h
index c2a55f94c29a..6035209cf31e 100644
--- a/include/linux/pm.h
+++ b/include/linux/pm.h
@@ -128,6 +128,9 @@ typedef int __bitwise suspend_disk_method_t;
128 * always valid and never passed to this call. 128 * always valid and never passed to this call.
129 * If not assigned, all suspend states are advertised as valid 129 * If not assigned, all suspend states are advertised as valid
130 * in /sys/power/state (but can still be rejected by prepare or enter.) 130 * in /sys/power/state (but can still be rejected by prepare or enter.)
131 * Since new states can be added for other platforms, you should
132 * assign this callback. There is a %pm_valid_only_mem function
133 * available if you only implemented mem sleep.
131 * 134 *
132 * @prepare: Prepare the platform for the given suspend state. Can return a 135 * @prepare: Prepare the platform for the given suspend state. Can return a
133 * negative error code if necessary. 136 * negative error code if necessary.
@@ -165,6 +168,7 @@ extern void pm_set_ops(struct pm_ops *pm_ops);
165extern struct pm_ops *pm_ops; 168extern struct pm_ops *pm_ops;
166extern int pm_suspend(suspend_state_t state); 169extern int pm_suspend(suspend_state_t state);
167 170
171extern int pm_valid_only_mem(suspend_state_t state);
168 172
169/** 173/**
170 * arch_suspend_disable_irqs - disable IRQs for suspend 174 * arch_suspend_disable_irqs - disable IRQs for suspend
diff --git a/kernel/power/main.c b/kernel/power/main.c
index 053c0a7d7f57..f94f4e20115a 100644
--- a/kernel/power/main.c
+++ b/kernel/power/main.c
@@ -48,6 +48,19 @@ void pm_set_ops(struct pm_ops * ops)
48 mutex_unlock(&pm_mutex); 48 mutex_unlock(&pm_mutex);
49} 49}
50 50
51/**
52 * pm_valid_only_mem - generic memory-only valid callback
53 *
54 * pm_ops drivers that implement mem suspend only and only need
55 * to check for that in their .valid callback can use this instead
56 * of rolling their own .valid callback.
57 */
58int pm_valid_only_mem(suspend_state_t state)
59{
60 return state == PM_SUSPEND_MEM;
61}
62
63
51static inline void pm_finish(suspend_state_t state) 64static inline void pm_finish(suspend_state_t state)
52{ 65{
53 if (pm_ops->finish) 66 if (pm_ops->finish)