aboutsummaryrefslogtreecommitdiffstats
path: root/arch/arm/mach-omap2/pm.c
diff options
context:
space:
mode:
Diffstat (limited to 'arch/arm/mach-omap2/pm.c')
-rw-r--r--arch/arm/mach-omap2/pm.c115
1 files changed, 92 insertions, 23 deletions
diff --git a/arch/arm/mach-omap2/pm.c b/arch/arm/mach-omap2/pm.c
index 1881fe915149..28706696a341 100644
--- a/arch/arm/mach-omap2/pm.c
+++ b/arch/arm/mach-omap2/pm.c
@@ -15,11 +15,13 @@
15#include <linux/err.h> 15#include <linux/err.h>
16#include <linux/opp.h> 16#include <linux/opp.h>
17#include <linux/export.h> 17#include <linux/export.h>
18#include <linux/suspend.h>
18 19
19#include <plat/omap-pm.h> 20#include <plat/omap-pm.h>
20#include <plat/omap_device.h> 21#include <plat/omap_device.h>
21#include "common.h" 22#include "common.h"
22 23
24#include "prcm-common.h"
23#include "voltage.h" 25#include "voltage.h"
24#include "powerdomain.h" 26#include "powerdomain.h"
25#include "clockdomain.h" 27#include "clockdomain.h"
@@ -28,7 +30,13 @@
28 30
29static struct omap_device_pm_latency *pm_lats; 31static struct omap_device_pm_latency *pm_lats;
30 32
31static int _init_omap_device(char *name) 33/*
34 * omap_pm_suspend: points to a function that does the SoC-specific
35 * suspend work
36 */
37int (*omap_pm_suspend)(void);
38
39static int __init _init_omap_device(char *name)
32{ 40{
33 struct omap_hwmod *oh; 41 struct omap_hwmod *oh;
34 struct platform_device *pdev; 42 struct platform_device *pdev;
@@ -68,32 +76,41 @@ static void omap2_init_processor_devices(void)
68#define FORCEWAKEUP_SWITCH 0 76#define FORCEWAKEUP_SWITCH 0
69#define LOWPOWERSTATE_SWITCH 1 77#define LOWPOWERSTATE_SWITCH 1
70 78
79int __init omap_pm_clkdms_setup(struct clockdomain *clkdm, void *unused)
80{
81 if (clkdm->flags & CLKDM_CAN_ENABLE_AUTO)
82 clkdm_allow_idle(clkdm);
83 else if (clkdm->flags & CLKDM_CAN_FORCE_SLEEP &&
84 atomic_read(&clkdm->usecount) == 0)
85 clkdm_sleep(clkdm);
86 return 0;
87}
88
71/* 89/*
72 * This sets pwrdm state (other than mpu & core. Currently only ON & 90 * This sets pwrdm state (other than mpu & core. Currently only ON &
73 * RET are supported. 91 * RET are supported.
74 */ 92 */
75int omap_set_pwrdm_state(struct powerdomain *pwrdm, u32 state) 93int omap_set_pwrdm_state(struct powerdomain *pwrdm, u32 pwrst)
76{ 94{
77 u32 cur_state; 95 u8 curr_pwrst, next_pwrst;
78 int sleep_switch = -1; 96 int sleep_switch = -1, ret = 0, hwsup = 0;
79 int ret = 0;
80 int hwsup = 0;
81 97
82 if (pwrdm == NULL || IS_ERR(pwrdm)) 98 if (!pwrdm || IS_ERR(pwrdm))
83 return -EINVAL; 99 return -EINVAL;
84 100
85 while (!(pwrdm->pwrsts & (1 << state))) { 101 while (!(pwrdm->pwrsts & (1 << pwrst))) {
86 if (state == PWRDM_POWER_OFF) 102 if (pwrst == PWRDM_POWER_OFF)
87 return ret; 103 return ret;
88 state--; 104 pwrst--;
89 } 105 }
90 106
91 cur_state = pwrdm_read_next_pwrst(pwrdm); 107 next_pwrst = pwrdm_read_next_pwrst(pwrdm);
92 if (cur_state == state) 108 if (next_pwrst == pwrst)
93 return ret; 109 return ret;
94 110
95 if (pwrdm_read_pwrst(pwrdm) < PWRDM_POWER_ON) { 111 curr_pwrst = pwrdm_read_pwrst(pwrdm);
96 if ((pwrdm_read_pwrst(pwrdm) > state) && 112 if (curr_pwrst < PWRDM_POWER_ON) {
113 if ((curr_pwrst > pwrst) &&
97 (pwrdm->flags & PWRDM_HAS_LOWPOWERSTATECHANGE)) { 114 (pwrdm->flags & PWRDM_HAS_LOWPOWERSTATECHANGE)) {
98 sleep_switch = LOWPOWERSTATE_SWITCH; 115 sleep_switch = LOWPOWERSTATE_SWITCH;
99 } else { 116 } else {
@@ -103,12 +120,10 @@ int omap_set_pwrdm_state(struct powerdomain *pwrdm, u32 state)
103 } 120 }
104 } 121 }
105 122
106 ret = pwrdm_set_next_pwrst(pwrdm, state); 123 ret = pwrdm_set_next_pwrst(pwrdm, pwrst);
107 if (ret) { 124 if (ret)
108 pr_err("%s: unable to set state of powerdomain: %s\n", 125 pr_err("%s: unable to set power state of powerdomain: %s\n",
109 __func__, pwrdm->name); 126 __func__, pwrdm->name);
110 goto err;
111 }
112 127
113 switch (sleep_switch) { 128 switch (sleep_switch) {
114 case FORCEWAKEUP_SWITCH: 129 case FORCEWAKEUP_SWITCH:
@@ -119,16 +134,16 @@ int omap_set_pwrdm_state(struct powerdomain *pwrdm, u32 state)
119 break; 134 break;
120 case LOWPOWERSTATE_SWITCH: 135 case LOWPOWERSTATE_SWITCH:
121 pwrdm_set_lowpwrstchange(pwrdm); 136 pwrdm_set_lowpwrstchange(pwrdm);
137 pwrdm_wait_transition(pwrdm);
138 pwrdm_state_switch(pwrdm);
122 break; 139 break;
123 default:
124 return ret;
125 } 140 }
126 141
127 pwrdm_state_switch(pwrdm);
128err:
129 return ret; 142 return ret;
130} 143}
131 144
145
146
132/* 147/*
133 * This API is to be called during init to set the various voltage 148 * This API is to be called during init to set the various voltage
134 * domains to the voltage as per the opp table. Typically we boot up 149 * domains to the voltage as per the opp table. Typically we boot up
@@ -196,6 +211,56 @@ exit:
196 return -EINVAL; 211 return -EINVAL;
197} 212}
198 213
214#ifdef CONFIG_SUSPEND
215static int omap_pm_enter(suspend_state_t suspend_state)
216{
217 int ret = 0;
218
219 if (!omap_pm_suspend)
220 return -ENOENT; /* XXX doublecheck */
221
222 switch (suspend_state) {
223 case PM_SUSPEND_STANDBY:
224 case PM_SUSPEND_MEM:
225 ret = omap_pm_suspend();
226 break;
227 default:
228 ret = -EINVAL;
229 }
230
231 return ret;
232}
233
234static int omap_pm_begin(suspend_state_t state)
235{
236 disable_hlt();
237 if (cpu_is_omap34xx())
238 omap_prcm_irq_prepare();
239 return 0;
240}
241
242static void omap_pm_end(void)
243{
244 enable_hlt();
245 return;
246}
247
248static void omap_pm_finish(void)
249{
250 if (cpu_is_omap34xx())
251 omap_prcm_irq_complete();
252}
253
254static const struct platform_suspend_ops omap_pm_ops = {
255 .begin = omap_pm_begin,
256 .end = omap_pm_end,
257 .enter = omap_pm_enter,
258 .finish = omap_pm_finish,
259 .valid = suspend_valid_only_mem,
260};
261
262#endif /* CONFIG_SUSPEND */
263
199static void __init omap3_init_voltages(void) 264static void __init omap3_init_voltages(void)
200{ 265{
201 if (!cpu_is_omap34xx()) 266 if (!cpu_is_omap34xx())
@@ -238,6 +303,10 @@ static int __init omap2_common_pm_late_init(void)
238 /* Smartreflex device init */ 303 /* Smartreflex device init */
239 omap_devinit_smartreflex(); 304 omap_devinit_smartreflex();
240 305
306#ifdef CONFIG_SUSPEND
307 suspend_set_ops(&omap_pm_ops);
308#endif
309
241 return 0; 310 return 0;
242} 311}
243late_initcall(omap2_common_pm_late_init); 312late_initcall(omap2_common_pm_late_init);