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>
18 #include <plat/omap-pm.h>
19 #include <plat/omap_device.h>
20 #include <plat/common.h>
23 #include "powerdomain.h"
24 #include "clockdomain.h"
28 * struct omap2_pm_lp_description - Describe low power behavior of the system
29 * @oscillator_startup_time: Time rounded up to uSec for the oscillator to
30 * provide a stable clock from power on.
31 * @oscillator_shutdown_time: Time rounded up to uSec for oscillator to safely
33 * @pmic_startup_time: Time rounded up to uSec for the PMIC to
34 * provide be ready for operation from low power
35 * state. Note: this is not the same as voltage
36 * rampup time, instead, consider the PMIC to be
37 * in lowest power state(say OFF), this is the time
38 * required for it to become ready for it's DCDCs
39 * or LDOs to start operation.
40 * @pmic_shutdown_time: Time rounded up to uSec for the PMIC to
41 * go to low power after the LDOs are pulled to
42 * appropriate state. Note: this is not the same as
43 * voltage rampdown time, instead, consider the
44 * PMIC to have switched it's LDOs down, this is
45 * time taken to reach it's lowest power state(say
48 * With complex systems like OMAP, we need a generic description of system
49 * behavior beyond the normal description of device/peripheral operation
50 * which in conjunction with other parameters describe and control the low
51 * power operation of the device. This information tends to be specific
54 struct omap2_pm_lp_description
{
55 u32 oscillator_startup_time
;
56 u32 oscillator_shutdown_time
;
57 u32 pmic_startup_time
;
58 u32 pmic_shutdown_time
;
62 * Setup time to be the max... we want to err towards the worst
63 * as default. rest of the system can populate these with more
66 static struct omap2_pm_lp_description _pm_lp_desc
= {
67 .oscillator_startup_time
= ULONG_MAX
,
68 .oscillator_shutdown_time
= ULONG_MAX
,
69 .pmic_startup_time
= ULONG_MAX
,
70 .pmic_shutdown_time
= ULONG_MAX
,
73 static struct omap_device_pm_latency
*pm_lats
;
75 static struct device
*mpu_dev
;
76 static struct device
*iva_dev
;
77 static struct device
*l3_dev
;
78 static struct device
*dsp_dev
;
79 static struct device
*fdif_dev
;
81 bool omap_pm_is_ready_status
;
83 struct device
*omap2_get_mpuss_device(void)
85 WARN_ON_ONCE(!mpu_dev
);
88 EXPORT_SYMBOL(omap2_get_mpuss_device
);
90 struct device
*omap2_get_iva_device(void)
92 WARN_ON_ONCE(!iva_dev
);
95 EXPORT_SYMBOL(omap2_get_iva_device
);
97 struct device
*omap2_get_l3_device(void)
99 WARN_ON_ONCE(!l3_dev
);
102 EXPORT_SYMBOL(omap2_get_l3_device
);
104 struct device
*omap4_get_dsp_device(void)
106 WARN_ON_ONCE(!dsp_dev
);
109 EXPORT_SYMBOL(omap4_get_dsp_device
);
111 struct device
*omap4_get_fdif_device(void)
113 WARN_ON_ONCE(!fdif_dev
);
116 EXPORT_SYMBOL(omap4_get_fdif_device
);
119 * omap_pm_get_pmic_lp_time() - retrieve the oscillator time
120 * @tstart: pointer to startup time in uSec
121 * @tshut: pointer to shutdown time in uSec
123 * if the pointers are invalid, returns error, else
124 * populates the tstart and tshut values with the currently
127 int omap_pm_get_osc_lp_time(u32
*tstart
, u32
*tshut
)
129 if (!tstart
|| !tshut
)
132 *tstart
= _pm_lp_desc
.oscillator_startup_time
;
133 *tshut
= _pm_lp_desc
.oscillator_shutdown_time
;
139 * omap_pm_get_pmic_lp_time() - retrieve the PMIC time
140 * @tstart: pointer to startup time in uSec
141 * @tshut: pointer to shutdown time in uSec
143 * if the pointers are invalid, returns error, else
144 * populates the tstart and tshut values with the currently
147 int omap_pm_get_pmic_lp_time(u32
*tstart
, u32
*tshut
)
149 if (!tstart
|| !tshut
)
152 *tstart
= _pm_lp_desc
.pmic_startup_time
;
153 *tshut
= _pm_lp_desc
.pmic_shutdown_time
;
159 * omap_pm_set_osc_lp_time() - setup the system oscillator time
160 * @tstart: startup time rounded up to uSec
161 * @tshut: shutdown time rounded up to uSec
163 * All boards do need an oscillator for the device to function.
164 * The startup and stop time of these oscillators vary. Populate
165 * from the board file to optimize the timing.
166 * This function is meant to be used at boot-time configuration.
168 * NOTE: This API is intended to be invoked from board file
170 void __init
omap_pm_set_osc_lp_time(u32 tstart
, u32 tshut
)
172 _pm_lp_desc
.oscillator_startup_time
= tstart
;
173 _pm_lp_desc
.oscillator_shutdown_time
= tshut
;
177 * omap_pm_set_pmic_lp_time() - setup the pmic low power time
178 * @tstart: startup time rounded up to uSec
179 * @tshut: shutdown time rounded up to uSec
181 * Store the time for PMIC to enter to lowest state supported.
182 * in the case of multiple PMIC on a platform, choose the one
183 * that ends the sequence for LP state such as OFF and starts
184 * the sequence such as wakeup from OFF - e.g. a PMIC that
185 * controls core-domain.
186 * This function is meant to be used at boot-time configuration.
188 void __init
omap_pm_set_pmic_lp_time(u32 tstart
, u32 tshut
)
190 _pm_lp_desc
.pmic_startup_time
= tstart
;
191 _pm_lp_desc
.pmic_shutdown_time
= tshut
;
194 /* static int _init_omap_device(struct omap_hwmod *oh, void *user) */
195 static int _init_omap_device(char *name
, struct device
**new_dev
)
197 struct omap_hwmod
*oh
;
198 struct omap_device
*od
;
200 oh
= omap_hwmod_lookup(name
);
201 if (WARN(!oh
, "%s: could not find omap_hwmod for %s\n",
205 od
= omap_device_build(oh
->name
, 0, oh
, NULL
, 0, pm_lats
, 0, false);
206 if (WARN(IS_ERR(od
), "%s: could not build omap_device for %s\n",
210 *new_dev
= &od
->pdev
.dev
;
216 * Build omap_devices for processors and bus.
218 static void omap2_init_processor_devices(void)
220 _init_omap_device("mpu", &mpu_dev
);
222 _init_omap_device("iva", &iva_dev
);
224 if (cpu_is_omap44xx()) {
225 _init_omap_device("l3_main_1", &l3_dev
);
226 _init_omap_device("dsp", &dsp_dev
);
227 _init_omap_device("iva", &iva_dev
);
228 _init_omap_device("fdif", &fdif_dev
);
230 _init_omap_device("l3_main", &l3_dev
);
234 /* Types of sleep_switch used in omap_set_pwrdm_state */
235 #define FORCEWAKEUP_SWITCH 0
236 #define LOWPOWERSTATE_SWITCH 1
239 * This sets pwrdm state (other than mpu & core. Currently only ON &
242 int omap_set_pwrdm_state(struct powerdomain
*pwrdm
, u32 state
)
245 int sleep_switch
= -1;
249 if (pwrdm
== NULL
|| IS_ERR(pwrdm
))
252 while (!(pwrdm
->pwrsts
& (1 << state
))) {
253 if (state
== PWRDM_POWER_OFF
)
258 cur_state
= pwrdm_read_next_pwrst(pwrdm
);
259 if (cur_state
== state
)
262 if (pwrdm_read_pwrst(pwrdm
) < PWRDM_POWER_ON
) {
263 if ((pwrdm_read_pwrst(pwrdm
) > state
) &&
264 (pwrdm
->flags
& PWRDM_HAS_LOWPOWERSTATECHANGE
)) {
265 sleep_switch
= LOWPOWERSTATE_SWITCH
;
267 hwsup
= clkdm_is_idle(pwrdm
->pwrdm_clkdms
[0]);
268 clkdm_wakeup(pwrdm
->pwrdm_clkdms
[0]);
269 pwrdm_wait_transition(pwrdm
);
270 sleep_switch
= FORCEWAKEUP_SWITCH
;
274 ret
= pwrdm_set_next_pwrst(pwrdm
, state
);
276 printk(KERN_ERR
"Unable to set state of powerdomain: %s\n",
281 switch (sleep_switch
) {
282 case FORCEWAKEUP_SWITCH
:
284 clkdm_allow_idle(pwrdm
->pwrdm_clkdms
[0]);
286 clkdm_sleep(pwrdm
->pwrdm_clkdms
[0]);
288 case LOWPOWERSTATE_SWITCH
:
289 pwrdm_set_lowpwrstchange(pwrdm
);
295 pwrdm_wait_transition(pwrdm
);
296 pwrdm_state_switch(pwrdm
);
301 static int __init
boot_volt_scale(struct voltagedomain
*voltdm
,
302 unsigned long boot_v
)
304 struct omap_volt_data
*vdata
;
307 vdata
= omap_voltage_get_voltdata(voltdm
, boot_v
);
308 if (IS_ERR_OR_NULL(vdata
)) {
309 pr_err("%s:%s: Bad New voltage data for %ld\n",
310 __func__
, voltdm
->name
, boot_v
);
311 return PTR_ERR(vdata
);
314 * DO NOT DO abb prescale -
315 * case 1: OPP needs FBB, bootloader configured FBB
316 * - doing a prescale results in bypass -> system fail
317 * case 2: OPP needs FBB, bootloader does not configure FBB
318 * - FBB will be configured in postscale
319 * case 3: OPP needs bypass, bootloader configures FBB
320 * - bypass will be configured in postscale
321 * case 4: OPP needs bypass, bootloader configured in bypass
322 * - bypass programming in postscale skipped
324 ret
= voltdm_scale(voltdm
, vdata
);
326 pr_err("%s: Fail set voltage(v=%ld)on vdd%s\n",
327 __func__
, boot_v
, voltdm
->name
);
331 ret
= omap_ldo_abb_post_scale(voltdm
, vdata
);
333 pr_err("%s: Fail abb postscale(v=%ld)vdd%s\n",
334 __func__
, boot_v
, voltdm
->name
);
341 * This API is to be called during init to put the various voltage
342 * domains to the voltage as per the opp table. Typically we boot up
343 * at the nominal voltage. So this function finds out the rate of
344 * the clock associated with the voltage domain, finds out the correct
345 * opp entry and puts the voltage domain to the voltage specifies
348 static int __init
omap2_set_init_voltage(char *vdd_name
, char *clk_name
,
351 struct voltagedomain
*voltdm
;
354 unsigned long freq_cur
, freq_valid
, bootup_volt
;
357 if (!vdd_name
|| !clk_name
|| !dev
) {
358 printk(KERN_ERR
"%s: Invalid parameters!\n", __func__
);
362 voltdm
= voltdm_lookup(vdd_name
);
363 if (IS_ERR(voltdm
)) {
364 printk(KERN_ERR
"%s: Unable to get vdd pointer for vdd_%s\n",
369 clk
= clk_get(NULL
, clk_name
);
371 printk(KERN_ERR
"%s: unable to get clk %s\n",
376 freq_cur
= clk
->rate
;
377 freq_valid
= freq_cur
;
380 opp
= opp_find_freq_ceil(dev
, &freq_valid
);
382 opp
= opp_find_freq_floor(dev
, &freq_valid
);
385 pr_err("%s: no boot OPP match for %ld on vdd_%s\n",
386 __func__
, freq_cur
, vdd_name
);
392 bootup_volt
= opp_get_voltage(opp
);
395 printk(KERN_ERR
"%s: unable to find voltage corresponding"
396 "to the bootup OPP for vdd_%s\n", __func__
, vdd_name
);
402 * Frequency and Voltage have to be sequenced: if we move from
403 * a lower frequency to higher frequency, raise voltage, followed by
404 * frequency, and vice versa. we assume that the voltage at boot
405 * is the required voltage for the frequency it was set for.
407 * we can check the frequency, but there is numerous ways to set
408 * voltage. We play the safe path and just set the voltage.
411 if (freq_cur
< freq_valid
) {
412 ret
= boot_volt_scale(voltdm
, bootup_volt
);
414 pr_err("%s: Fail set voltage-%s(f=%ld v=%ld)on vdd%s\n",
415 __func__
, vdd_name
, freq_valid
,
416 bootup_volt
, vdd_name
);
421 /* Set freq only if there is a difference in freq */
422 if (freq_valid
!= freq_cur
) {
423 ret
= clk_set_rate(clk
, freq_valid
);
425 pr_err("%s: Fail set clk-%s(f=%ld v=%ld)on vdd%s\n",
426 __func__
, clk_name
, freq_valid
,
427 bootup_volt
, vdd_name
);
432 if (freq_cur
>= freq_valid
) {
433 ret
= boot_volt_scale(voltdm
, bootup_volt
);
435 pr_err("%s: Fail set voltage-%s(f=%ld v=%ld)on vdd%s\n",
436 __func__
, clk_name
, freq_valid
,
437 bootup_volt
, vdd_name
);
450 printk(KERN_ERR
"%s: Unable to put vdd_%s to its init voltage\n\n",
455 static void __init
omap3_init_voltages(void)
457 if (!cpu_is_omap34xx())
460 omap2_set_init_voltage("mpu_iva", "dpll1_ck", mpu_dev
);
461 omap2_set_init_voltage("core", "l3_ick", l3_dev
);
464 static void __init
omap4_init_voltages(void)
466 if (!cpu_is_omap44xx())
469 if (cpu_is_omap446x()) {
470 omap2_set_init_voltage("mpu", "virt_dpll_mpu_ck", mpu_dev
);
472 omap2_set_init_voltage("mpu", "dpll_mpu_ck", mpu_dev
);
474 omap2_set_init_voltage("core", "virt_l3_ck", l3_dev
);
475 omap2_set_init_voltage("iva", "dpll_iva_m5x2_ck", iva_dev
);
478 static int __init
omap2_common_pm_init(void)
480 omap2_init_processor_devices();
485 postcore_initcall(omap2_common_pm_init
);
487 static int __init
omap2_common_pm_late_init(void)
489 /* Init the OMAP PMIC parameters */
490 omap_pmic_data_init();
492 /* Init the voltage layer */
493 omap_voltage_late_init();
495 /* Initialize the voltages */
496 omap3_init_voltages();
497 omap4_init_voltages();
499 /* Smartreflex device init */
500 omap_devinit_smartreflex();
504 late_initcall(omap2_common_pm_late_init
);