x86, efi: Set runtime_version to the EFI spec revision
[linux/fpc-iii.git] / arch / arm / mach-omap2 / pm.c
blobf4b3143a8b1d23f104419181c0d266b07e31ad78
1 /*
2 * pm.c - Common OMAP2+ power management-related code
4 * Copyright (C) 2010 Texas Instruments, Inc.
5 * Copyright (C) 2010 Nokia Corporation
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License version 2 as
9 * published by the Free Software Foundation.
12 #include <linux/kernel.h>
13 #include <linux/init.h>
14 #include <linux/io.h>
15 #include <linux/err.h>
16 #include <linux/opp.h>
17 #include <linux/export.h>
18 #include <linux/suspend.h>
19 #include <linux/cpu.h>
21 #include <asm/system_misc.h>
23 #include "omap-pm.h"
24 #include "omap_device.h"
25 #include "common.h"
27 #include "soc.h"
28 #include "prcm-common.h"
29 #include "voltage.h"
30 #include "powerdomain.h"
31 #include "clockdomain.h"
32 #include "pm.h"
33 #include "twl-common.h"
35 static struct omap_device_pm_latency *pm_lats;
38 * omap_pm_suspend: points to a function that does the SoC-specific
39 * suspend work
41 int (*omap_pm_suspend)(void);
43 #ifdef CONFIG_PM
44 /**
45 * struct omap2_oscillator - Describe the board main oscillator latencies
46 * @startup_time: oscillator startup latency
47 * @shutdown_time: oscillator shutdown latency
49 struct omap2_oscillator {
50 u32 startup_time;
51 u32 shutdown_time;
54 static struct omap2_oscillator oscillator = {
55 .startup_time = ULONG_MAX,
56 .shutdown_time = ULONG_MAX,
59 void omap_pm_setup_oscillator(u32 tstart, u32 tshut)
61 oscillator.startup_time = tstart;
62 oscillator.shutdown_time = tshut;
65 void omap_pm_get_oscillator(u32 *tstart, u32 *tshut)
67 if (!tstart || !tshut)
68 return;
70 *tstart = oscillator.startup_time;
71 *tshut = oscillator.shutdown_time;
73 #endif
75 static int __init _init_omap_device(char *name)
77 struct omap_hwmod *oh;
78 struct platform_device *pdev;
80 oh = omap_hwmod_lookup(name);
81 if (WARN(!oh, "%s: could not find omap_hwmod for %s\n",
82 __func__, name))
83 return -ENODEV;
85 pdev = omap_device_build(oh->name, 0, oh, NULL, 0, pm_lats, 0, false);
86 if (WARN(IS_ERR(pdev), "%s: could not build omap_device for %s\n",
87 __func__, name))
88 return -ENODEV;
90 return 0;
94 * Build omap_devices for processors and bus.
96 static void __init omap2_init_processor_devices(void)
98 _init_omap_device("mpu");
99 if (omap3_has_iva())
100 _init_omap_device("iva");
102 if (cpu_is_omap44xx()) {
103 _init_omap_device("l3_main_1");
104 _init_omap_device("dsp");
105 _init_omap_device("iva");
106 } else {
107 _init_omap_device("l3_main");
111 /* Types of sleep_switch used in omap_set_pwrdm_state */
112 #define FORCEWAKEUP_SWITCH 0
113 #define LOWPOWERSTATE_SWITCH 1
115 int __init omap_pm_clkdms_setup(struct clockdomain *clkdm, void *unused)
117 if ((clkdm->flags & CLKDM_CAN_ENABLE_AUTO) &&
118 !(clkdm->flags & CLKDM_MISSING_IDLE_REPORTING))
119 clkdm_allow_idle(clkdm);
120 else if (clkdm->flags & CLKDM_CAN_FORCE_SLEEP &&
121 atomic_read(&clkdm->usecount) == 0)
122 clkdm_sleep(clkdm);
123 return 0;
127 * This sets pwrdm state (other than mpu & core. Currently only ON &
128 * RET are supported.
130 int omap_set_pwrdm_state(struct powerdomain *pwrdm, u32 pwrst)
132 u8 curr_pwrst, next_pwrst;
133 int sleep_switch = -1, ret = 0, hwsup = 0;
135 if (!pwrdm || IS_ERR(pwrdm))
136 return -EINVAL;
138 while (!(pwrdm->pwrsts & (1 << pwrst))) {
139 if (pwrst == PWRDM_POWER_OFF)
140 return ret;
141 pwrst--;
144 next_pwrst = pwrdm_read_next_pwrst(pwrdm);
145 if (next_pwrst == pwrst)
146 return ret;
148 curr_pwrst = pwrdm_read_pwrst(pwrdm);
149 if (curr_pwrst < PWRDM_POWER_ON) {
150 if ((curr_pwrst > pwrst) &&
151 (pwrdm->flags & PWRDM_HAS_LOWPOWERSTATECHANGE)) {
152 sleep_switch = LOWPOWERSTATE_SWITCH;
153 } else {
154 hwsup = clkdm_in_hwsup(pwrdm->pwrdm_clkdms[0]);
155 clkdm_wakeup(pwrdm->pwrdm_clkdms[0]);
156 sleep_switch = FORCEWAKEUP_SWITCH;
160 ret = pwrdm_set_next_pwrst(pwrdm, pwrst);
161 if (ret)
162 pr_err("%s: unable to set power state of powerdomain: %s\n",
163 __func__, pwrdm->name);
165 switch (sleep_switch) {
166 case FORCEWAKEUP_SWITCH:
167 if (hwsup)
168 clkdm_allow_idle(pwrdm->pwrdm_clkdms[0]);
169 else
170 clkdm_sleep(pwrdm->pwrdm_clkdms[0]);
171 break;
172 case LOWPOWERSTATE_SWITCH:
173 pwrdm_set_lowpwrstchange(pwrdm);
174 pwrdm_wait_transition(pwrdm);
175 pwrdm_state_switch(pwrdm);
176 break;
179 return ret;
185 * This API is to be called during init to set the various voltage
186 * domains to the voltage as per the opp table. Typically we boot up
187 * at the nominal voltage. So this function finds out the rate of
188 * the clock associated with the voltage domain, finds out the correct
189 * opp entry and sets the voltage domain to the voltage specified
190 * in the opp entry
192 static int __init omap2_set_init_voltage(char *vdd_name, char *clk_name,
193 const char *oh_name)
195 struct voltagedomain *voltdm;
196 struct clk *clk;
197 struct opp *opp;
198 unsigned long freq, bootup_volt;
199 struct device *dev;
201 if (!vdd_name || !clk_name || !oh_name) {
202 pr_err("%s: invalid parameters\n", __func__);
203 goto exit;
206 if (!strncmp(oh_name, "mpu", 3))
208 * All current OMAPs share voltage rail and clock
209 * source, so CPU0 is used to represent the MPU-SS.
211 dev = get_cpu_device(0);
212 else
213 dev = omap_device_get_by_hwmod_name(oh_name);
215 if (IS_ERR(dev)) {
216 pr_err("%s: Unable to get dev pointer for hwmod %s\n",
217 __func__, oh_name);
218 goto exit;
221 voltdm = voltdm_lookup(vdd_name);
222 if (!voltdm) {
223 pr_err("%s: unable to get vdd pointer for vdd_%s\n",
224 __func__, vdd_name);
225 goto exit;
228 clk = clk_get(NULL, clk_name);
229 if (IS_ERR(clk)) {
230 pr_err("%s: unable to get clk %s\n", __func__, clk_name);
231 goto exit;
234 freq = clk_get_rate(clk);
235 clk_put(clk);
237 rcu_read_lock();
238 opp = opp_find_freq_ceil(dev, &freq);
239 if (IS_ERR(opp)) {
240 rcu_read_unlock();
241 pr_err("%s: unable to find boot up OPP for vdd_%s\n",
242 __func__, vdd_name);
243 goto exit;
246 bootup_volt = opp_get_voltage(opp);
247 rcu_read_unlock();
248 if (!bootup_volt) {
249 pr_err("%s: unable to find voltage corresponding to the bootup OPP for vdd_%s\n",
250 __func__, vdd_name);
251 goto exit;
254 voltdm_scale(voltdm, bootup_volt);
255 return 0;
257 exit:
258 pr_err("%s: unable to set vdd_%s\n", __func__, vdd_name);
259 return -EINVAL;
262 #ifdef CONFIG_SUSPEND
263 static int omap_pm_enter(suspend_state_t suspend_state)
265 int ret = 0;
267 if (!omap_pm_suspend)
268 return -ENOENT; /* XXX doublecheck */
270 switch (suspend_state) {
271 case PM_SUSPEND_STANDBY:
272 case PM_SUSPEND_MEM:
273 ret = omap_pm_suspend();
274 break;
275 default:
276 ret = -EINVAL;
279 return ret;
282 static int omap_pm_begin(suspend_state_t state)
284 disable_hlt();
285 if (cpu_is_omap34xx())
286 omap_prcm_irq_prepare();
287 return 0;
290 static void omap_pm_end(void)
292 enable_hlt();
293 return;
296 static void omap_pm_finish(void)
298 if (cpu_is_omap34xx())
299 omap_prcm_irq_complete();
302 static const struct platform_suspend_ops omap_pm_ops = {
303 .begin = omap_pm_begin,
304 .end = omap_pm_end,
305 .enter = omap_pm_enter,
306 .finish = omap_pm_finish,
307 .valid = suspend_valid_only_mem,
310 #endif /* CONFIG_SUSPEND */
312 static void __init omap3_init_voltages(void)
314 if (!cpu_is_omap34xx())
315 return;
317 omap2_set_init_voltage("mpu_iva", "dpll1_ck", "mpu");
318 omap2_set_init_voltage("core", "l3_ick", "l3_main");
321 static void __init omap4_init_voltages(void)
323 if (!cpu_is_omap44xx())
324 return;
326 omap2_set_init_voltage("mpu", "dpll_mpu_ck", "mpu");
327 omap2_set_init_voltage("core", "l3_div_ck", "l3_main_1");
328 omap2_set_init_voltage("iva", "dpll_iva_m5x2_ck", "iva");
331 static int __init omap2_common_pm_init(void)
333 if (!of_have_populated_dt())
334 omap2_init_processor_devices();
335 omap_pm_if_init();
337 return 0;
339 postcore_initcall(omap2_common_pm_init);
341 int __init omap2_common_pm_late_init(void)
344 * In the case of DT, the PMIC and SR initialization will be done using
345 * a completely different mechanism.
346 * Disable this part if a DT blob is available.
348 if (of_have_populated_dt())
349 return 0;
351 /* Init the voltage layer */
352 omap_pmic_late_init();
353 omap_voltage_late_init();
355 /* Initialize the voltages */
356 omap3_init_voltages();
357 omap4_init_voltages();
359 /* Smartreflex device init */
360 omap_devinit_smartreflex();
362 #ifdef CONFIG_SUSPEND
363 suspend_set_ops(&omap_pm_ops);
364 #endif
366 return 0;