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);
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
{
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
)
70 *tstart
= oscillator
.startup_time
;
71 *tshut
= oscillator
.shutdown_time
;
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",
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",
94 * Build omap_devices for processors and bus.
96 static void __init
omap2_init_processor_devices(void)
98 _init_omap_device("mpu");
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");
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)
127 * This sets pwrdm state (other than mpu & core. Currently only ON &
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
))
138 while (!(pwrdm
->pwrsts
& (1 << pwrst
))) {
139 if (pwrst
== PWRDM_POWER_OFF
)
144 next_pwrst
= pwrdm_read_next_pwrst(pwrdm
);
145 if (next_pwrst
== pwrst
)
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
;
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
);
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
:
168 clkdm_allow_idle(pwrdm
->pwrdm_clkdms
[0]);
170 clkdm_sleep(pwrdm
->pwrdm_clkdms
[0]);
172 case LOWPOWERSTATE_SWITCH
:
173 pwrdm_set_lowpwrstchange(pwrdm
);
174 pwrdm_wait_transition(pwrdm
);
175 pwrdm_state_switch(pwrdm
);
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
192 static int __init
omap2_set_init_voltage(char *vdd_name
, char *clk_name
,
195 struct voltagedomain
*voltdm
;
198 unsigned long freq
, bootup_volt
;
201 if (!vdd_name
|| !clk_name
|| !oh_name
) {
202 pr_err("%s: invalid parameters\n", __func__
);
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);
213 dev
= omap_device_get_by_hwmod_name(oh_name
);
216 pr_err("%s: Unable to get dev pointer for hwmod %s\n",
221 voltdm
= voltdm_lookup(vdd_name
);
223 pr_err("%s: unable to get vdd pointer for vdd_%s\n",
228 clk
= clk_get(NULL
, clk_name
);
230 pr_err("%s: unable to get clk %s\n", __func__
, clk_name
);
234 freq
= clk_get_rate(clk
);
238 opp
= opp_find_freq_ceil(dev
, &freq
);
241 pr_err("%s: unable to find boot up OPP for vdd_%s\n",
246 bootup_volt
= opp_get_voltage(opp
);
249 pr_err("%s: unable to find voltage corresponding to the bootup OPP for vdd_%s\n",
254 voltdm_scale(voltdm
, bootup_volt
);
258 pr_err("%s: unable to set vdd_%s\n", __func__
, vdd_name
);
262 #ifdef CONFIG_SUSPEND
263 static int omap_pm_enter(suspend_state_t suspend_state
)
267 if (!omap_pm_suspend
)
268 return -ENOENT
; /* XXX doublecheck */
270 switch (suspend_state
) {
271 case PM_SUSPEND_STANDBY
:
273 ret
= omap_pm_suspend();
282 static int omap_pm_begin(suspend_state_t state
)
285 if (cpu_is_omap34xx())
286 omap_prcm_irq_prepare();
290 static void omap_pm_end(void)
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
,
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())
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())
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();
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())
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
);