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>
19 #include <plat/omap-pm.h>
20 #include <plat/omap_device.h>
21 #include <plat/common.h>
24 #include "powerdomain.h"
25 #include "clockdomain.h"
28 static struct omap_device_pm_latency
*pm_lats
;
30 static int _init_omap_device(char *name
)
32 struct omap_hwmod
*oh
;
33 struct platform_device
*pdev
;
35 oh
= omap_hwmod_lookup(name
);
36 if (WARN(!oh
, "%s: could not find omap_hwmod for %s\n",
40 pdev
= omap_device_build(oh
->name
, 0, oh
, NULL
, 0, pm_lats
, 0, false);
41 if (WARN(IS_ERR(pdev
), "%s: could not build omap_device for %s\n",
49 * Build omap_devices for processors and bus.
51 static void omap2_init_processor_devices(void)
53 _init_omap_device("mpu");
55 _init_omap_device("iva");
57 if (cpu_is_omap44xx()) {
58 _init_omap_device("l3_main_1");
59 _init_omap_device("dsp");
60 _init_omap_device("iva");
62 _init_omap_device("l3_main");
66 /* Types of sleep_switch used in omap_set_pwrdm_state */
67 #define FORCEWAKEUP_SWITCH 0
68 #define LOWPOWERSTATE_SWITCH 1
71 * This sets pwrdm state (other than mpu & core. Currently only ON &
74 int omap_set_pwrdm_state(struct powerdomain
*pwrdm
, u32 state
)
77 int sleep_switch
= -1;
81 if (pwrdm
== NULL
|| IS_ERR(pwrdm
))
84 while (!(pwrdm
->pwrsts
& (1 << state
))) {
85 if (state
== PWRDM_POWER_OFF
)
90 cur_state
= pwrdm_read_next_pwrst(pwrdm
);
91 if (cur_state
== state
)
94 if (pwrdm_read_pwrst(pwrdm
) < PWRDM_POWER_ON
) {
95 if ((pwrdm_read_pwrst(pwrdm
) > state
) &&
96 (pwrdm
->flags
& PWRDM_HAS_LOWPOWERSTATECHANGE
)) {
97 sleep_switch
= LOWPOWERSTATE_SWITCH
;
99 hwsup
= clkdm_in_hwsup(pwrdm
->pwrdm_clkdms
[0]);
100 clkdm_wakeup(pwrdm
->pwrdm_clkdms
[0]);
101 sleep_switch
= FORCEWAKEUP_SWITCH
;
105 ret
= pwrdm_set_next_pwrst(pwrdm
, state
);
107 pr_err("%s: unable to set state of powerdomain: %s\n",
108 __func__
, pwrdm
->name
);
112 switch (sleep_switch
) {
113 case FORCEWAKEUP_SWITCH
:
115 clkdm_allow_idle(pwrdm
->pwrdm_clkdms
[0]);
117 clkdm_sleep(pwrdm
->pwrdm_clkdms
[0]);
119 case LOWPOWERSTATE_SWITCH
:
120 pwrdm_set_lowpwrstchange(pwrdm
);
126 pwrdm_state_switch(pwrdm
);
132 * This API is to be called during init to set the various voltage
133 * domains to the voltage as per the opp table. Typically we boot up
134 * at the nominal voltage. So this function finds out the rate of
135 * the clock associated with the voltage domain, finds out the correct
136 * opp entry and sets the voltage domain to the voltage specified
139 static int __init
omap2_set_init_voltage(char *vdd_name
, char *clk_name
,
142 struct voltagedomain
*voltdm
;
145 unsigned long freq
, bootup_volt
;
148 if (!vdd_name
|| !clk_name
|| !oh_name
) {
149 pr_err("%s: invalid parameters\n", __func__
);
153 dev
= omap_device_get_by_hwmod_name(oh_name
);
155 pr_err("%s: Unable to get dev pointer for hwmod %s\n",
160 voltdm
= voltdm_lookup(vdd_name
);
161 if (IS_ERR(voltdm
)) {
162 pr_err("%s: unable to get vdd pointer for vdd_%s\n",
167 clk
= clk_get(NULL
, clk_name
);
169 pr_err("%s: unable to get clk %s\n", __func__
, clk_name
);
176 opp
= opp_find_freq_ceil(dev
, &freq
);
178 pr_err("%s: unable to find boot up OPP for vdd_%s\n",
183 bootup_volt
= opp_get_voltage(opp
);
185 pr_err("%s: unable to find voltage corresponding "
186 "to the bootup OPP for vdd_%s\n", __func__
, vdd_name
);
190 voltdm_scale(voltdm
, bootup_volt
);
194 pr_err("%s: unable to set vdd_%s\n", __func__
, vdd_name
);
198 static void __init
omap3_init_voltages(void)
200 if (!cpu_is_omap34xx())
203 omap2_set_init_voltage("mpu_iva", "dpll1_ck", "mpu");
204 omap2_set_init_voltage("core", "l3_ick", "l3_main");
207 static void __init
omap4_init_voltages(void)
209 if (!cpu_is_omap44xx())
212 omap2_set_init_voltage("mpu", "dpll_mpu_ck", "mpu");
213 omap2_set_init_voltage("core", "l3_div_ck", "l3_main_1");
214 omap2_set_init_voltage("iva", "dpll_iva_m5x2_ck", "iva");
217 static int __init
omap2_common_pm_init(void)
219 if (!of_have_populated_dt())
220 omap2_init_processor_devices();
225 postcore_initcall(omap2_common_pm_init
);
227 static int __init
omap2_common_pm_late_init(void)
229 /* Init the OMAP TWL parameters */
233 /* Init the voltage layer */
234 omap_voltage_late_init();
236 /* Initialize the voltages */
237 omap3_init_voltages();
238 omap4_init_voltages();
240 /* Smartreflex device init */
241 omap_devinit_smartreflex();
245 late_initcall(omap2_common_pm_late_init
);