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>
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>
24 #include "omap_device.h"
28 #include "prcm-common.h"
30 #include "powerdomain.h"
31 #include "clockdomain.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
41 int (*omap_pm_suspend)(void);
44 * struct omap2_oscillator - Describe the board main oscillator latencies
45 * @startup_time: oscillator startup latency
46 * @shutdown_time: oscillator shutdown latency
48 struct omap2_oscillator {
53 static struct omap2_oscillator oscillator = {
54 .startup_time = ULONG_MAX,
55 .shutdown_time = ULONG_MAX,
58 void omap_pm_setup_oscillator(u32 tstart, u32 tshut)
60 oscillator.startup_time = tstart;
61 oscillator.shutdown_time = tshut;
64 void omap_pm_get_oscillator(u32 *tstart, u32 *tshut)
66 if (!tstart || !tshut)
69 *tstart = oscillator.startup_time;
70 *tshut = oscillator.shutdown_time;
73 static int __init _init_omap_device(char *name)
75 struct omap_hwmod *oh;
76 struct platform_device *pdev;
78 oh = omap_hwmod_lookup(name);
79 if (WARN(!oh, "%s: could not find omap_hwmod for %s\n",
83 pdev = omap_device_build(oh->name, 0, oh, NULL, 0, pm_lats, 0, false);
84 if (WARN(IS_ERR(pdev), "%s: could not build omap_device for %s\n",
92 * Build omap_devices for processors and bus.
94 static void __init omap2_init_processor_devices(void)
96 _init_omap_device("mpu");
98 _init_omap_device("iva");
100 if (cpu_is_omap44xx()) {
101 _init_omap_device("l3_main_1");
102 _init_omap_device("dsp");
103 _init_omap_device("iva");
105 _init_omap_device("l3_main");
109 /* Types of sleep_switch used in omap_set_pwrdm_state */
110 #define FORCEWAKEUP_SWITCH 0
111 #define LOWPOWERSTATE_SWITCH 1
113 int __init omap_pm_clkdms_setup(struct clockdomain *clkdm, void *unused)
115 if ((clkdm->flags & CLKDM_CAN_ENABLE_AUTO) &&
116 !(clkdm->flags & CLKDM_MISSING_IDLE_REPORTING))
117 clkdm_allow_idle(clkdm);
118 else if (clkdm->flags & CLKDM_CAN_FORCE_SLEEP &&
119 atomic_read(&clkdm->usecount) == 0)
125 * This sets pwrdm state (other than mpu & core. Currently only ON &
128 int omap_set_pwrdm_state(struct powerdomain *pwrdm, u32 pwrst)
130 u8 curr_pwrst, next_pwrst;
131 int sleep_switch = -1, ret = 0, hwsup = 0;
133 if (!pwrdm || IS_ERR(pwrdm))
136 while (!(pwrdm->pwrsts & (1 << pwrst))) {
137 if (pwrst == PWRDM_POWER_OFF)
142 next_pwrst = pwrdm_read_next_pwrst(pwrdm);
143 if (next_pwrst == pwrst)
146 curr_pwrst = pwrdm_read_pwrst(pwrdm);
147 if (curr_pwrst < PWRDM_POWER_ON) {
148 if ((curr_pwrst > pwrst) &&
149 (pwrdm->flags & PWRDM_HAS_LOWPOWERSTATECHANGE)) {
150 sleep_switch = LOWPOWERSTATE_SWITCH;
152 hwsup = clkdm_in_hwsup(pwrdm->pwrdm_clkdms[0]);
153 clkdm_wakeup(pwrdm->pwrdm_clkdms[0]);
154 sleep_switch = FORCEWAKEUP_SWITCH;
158 ret = pwrdm_set_next_pwrst(pwrdm, pwrst);
160 pr_err("%s: unable to set power state of powerdomain: %s\n",
161 __func__, pwrdm->name);
163 switch (sleep_switch) {
164 case FORCEWAKEUP_SWITCH:
166 clkdm_allow_idle(pwrdm->pwrdm_clkdms[0]);
168 clkdm_sleep(pwrdm->pwrdm_clkdms[0]);
170 case LOWPOWERSTATE_SWITCH:
171 pwrdm_set_lowpwrstchange(pwrdm);
172 pwrdm_wait_transition(pwrdm);
173 pwrdm_state_switch(pwrdm);
183 * This API is to be called during init to set the various voltage
184 * domains to the voltage as per the opp table. Typically we boot up
185 * at the nominal voltage. So this function finds out the rate of
186 * the clock associated with the voltage domain, finds out the correct
187 * opp entry and sets the voltage domain to the voltage specified
190 static int __init omap2_set_init_voltage(char *vdd_name, char *clk_name,
193 struct voltagedomain *voltdm;
196 unsigned long freq, bootup_volt;
199 if (!vdd_name || !clk_name || !oh_name) {
200 pr_err("%s: invalid parameters\n", __func__);
204 if (!strncmp(oh_name, "mpu", 3))
206 * All current OMAPs share voltage rail and clock
207 * source, so CPU0 is used to represent the MPU-SS.
209 dev = get_cpu_device(0);
211 dev = omap_device_get_by_hwmod_name(oh_name);
214 pr_err("%s: Unable to get dev pointer for hwmod %s\n",
219 voltdm = voltdm_lookup(vdd_name);
221 pr_err("%s: unable to get vdd pointer for vdd_%s\n",
226 clk = clk_get(NULL, clk_name);
228 pr_err("%s: unable to get clk %s\n", __func__, clk_name);
232 freq = clk_get_rate(clk);
236 opp = opp_find_freq_ceil(dev, &freq);
239 pr_err("%s: unable to find boot up OPP for vdd_%s\n",
244 bootup_volt = opp_get_voltage(opp);
247 pr_err("%s: unable to find voltage corresponding to the bootup OPP for vdd_%s\n",
252 voltdm_scale(voltdm, bootup_volt);
256 pr_err("%s: unable to set vdd_%s\n", __func__, vdd_name);
260 #ifdef CONFIG_SUSPEND
261 static int omap_pm_enter(suspend_state_t suspend_state)
265 if (!omap_pm_suspend)
266 return -ENOENT; /* XXX doublecheck */
268 switch (suspend_state) {
269 case PM_SUSPEND_STANDBY:
271 ret = omap_pm_suspend();
280 static int omap_pm_begin(suspend_state_t state)
283 if (cpu_is_omap34xx())
284 omap_prcm_irq_prepare();
288 static void omap_pm_end(void)
294 static void omap_pm_finish(void)
296 if (cpu_is_omap34xx())
297 omap_prcm_irq_complete();
300 static const struct platform_suspend_ops omap_pm_ops = {
301 .begin = omap_pm_begin,
303 .enter = omap_pm_enter,
304 .finish = omap_pm_finish,
305 .valid = suspend_valid_only_mem,
308 #endif /* CONFIG_SUSPEND */
310 static void __init omap3_init_voltages(void)
312 if (!cpu_is_omap34xx())
315 omap2_set_init_voltage("mpu_iva", "dpll1_ck", "mpu");
316 omap2_set_init_voltage("core", "l3_ick", "l3_main");
319 static void __init omap4_init_voltages(void)
321 if (!cpu_is_omap44xx())
324 omap2_set_init_voltage("mpu", "dpll_mpu_ck", "mpu");
325 omap2_set_init_voltage("core", "l3_div_ck", "l3_main_1");
326 omap2_set_init_voltage("iva", "dpll_iva_m5x2_ck", "iva");
329 static int __init omap2_common_pm_init(void)
331 if (!of_have_populated_dt())
332 omap2_init_processor_devices();
337 postcore_initcall(omap2_common_pm_init);
339 int __init omap2_common_pm_late_init(void)
342 * In the case of DT, the PMIC and SR initialization will be done using
343 * a completely different mechanism.
344 * Disable this part if a DT blob is available.
346 if (of_have_populated_dt())
349 /* Init the voltage layer */
350 omap_pmic_late_init();
351 omap_voltage_late_init();
353 /* Initialize the voltages */
354 omap3_init_voltages();
355 omap4_init_voltages();
357 /* Smartreflex device init */
358 omap_devinit_smartreflex();
360 #ifdef CONFIG_SUSPEND
361 suspend_set_ops(&omap_pm_ops);