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 struct device
*mpu_dev
;
31 static struct device
*iva_dev
;
32 static struct device
*l3_dev
;
33 static struct device
*dsp_dev
;
35 struct device
*omap2_get_mpuss_device(void)
37 WARN_ON_ONCE(!mpu_dev
);
41 struct device
*omap2_get_iva_device(void)
43 WARN_ON_ONCE(!iva_dev
);
47 struct device
*omap2_get_l3_device(void)
49 WARN_ON_ONCE(!l3_dev
);
53 struct device
*omap4_get_dsp_device(void)
55 WARN_ON_ONCE(!dsp_dev
);
58 EXPORT_SYMBOL(omap4_get_dsp_device
);
60 /* static int _init_omap_device(struct omap_hwmod *oh, void *user) */
61 static int _init_omap_device(char *name
, struct device
**new_dev
)
63 struct omap_hwmod
*oh
;
64 struct omap_device
*od
;
66 oh
= omap_hwmod_lookup(name
);
67 if (WARN(!oh
, "%s: could not find omap_hwmod for %s\n",
71 od
= omap_device_build(oh
->name
, 0, oh
, NULL
, 0, pm_lats
, 0, false);
72 if (WARN(IS_ERR(od
), "%s: could not build omap_device for %s\n",
76 *new_dev
= &od
->pdev
.dev
;
82 * Build omap_devices for processors and bus.
84 static void omap2_init_processor_devices(void)
86 _init_omap_device("mpu", &mpu_dev
);
88 _init_omap_device("iva", &iva_dev
);
90 if (cpu_is_omap44xx()) {
91 _init_omap_device("l3_main_1", &l3_dev
);
92 _init_omap_device("dsp", &dsp_dev
);
93 _init_omap_device("iva", &iva_dev
);
95 _init_omap_device("l3_main", &l3_dev
);
99 /* Types of sleep_switch used in omap_set_pwrdm_state */
100 #define FORCEWAKEUP_SWITCH 0
101 #define LOWPOWERSTATE_SWITCH 1
104 * This sets pwrdm state (other than mpu & core. Currently only ON &
107 int omap_set_pwrdm_state(struct powerdomain
*pwrdm
, u32 state
)
110 int sleep_switch
= -1;
114 if (pwrdm
== NULL
|| IS_ERR(pwrdm
))
117 while (!(pwrdm
->pwrsts
& (1 << state
))) {
118 if (state
== PWRDM_POWER_OFF
)
123 cur_state
= pwrdm_read_next_pwrst(pwrdm
);
124 if (cur_state
== state
)
127 if (pwrdm_read_pwrst(pwrdm
) < PWRDM_POWER_ON
) {
128 if ((pwrdm_read_pwrst(pwrdm
) > state
) &&
129 (pwrdm
->flags
& PWRDM_HAS_LOWPOWERSTATECHANGE
)) {
130 sleep_switch
= LOWPOWERSTATE_SWITCH
;
132 hwsup
= clkdm_in_hwsup(pwrdm
->pwrdm_clkdms
[0]);
133 clkdm_wakeup(pwrdm
->pwrdm_clkdms
[0]);
134 pwrdm_wait_transition(pwrdm
);
135 sleep_switch
= FORCEWAKEUP_SWITCH
;
139 ret
= pwrdm_set_next_pwrst(pwrdm
, state
);
141 printk(KERN_ERR
"Unable to set state of powerdomain: %s\n",
146 switch (sleep_switch
) {
147 case FORCEWAKEUP_SWITCH
:
149 clkdm_allow_idle(pwrdm
->pwrdm_clkdms
[0]);
151 clkdm_sleep(pwrdm
->pwrdm_clkdms
[0]);
153 case LOWPOWERSTATE_SWITCH
:
154 pwrdm_set_lowpwrstchange(pwrdm
);
160 pwrdm_wait_transition(pwrdm
);
161 pwrdm_state_switch(pwrdm
);
167 * This API is to be called during init to put the various voltage
168 * domains to the voltage as per the opp table. Typically we boot up
169 * at the nominal voltage. So this function finds out the rate of
170 * the clock associated with the voltage domain, finds out the correct
171 * opp entry and puts the voltage domain to the voltage specifies
174 static int __init
omap2_set_init_voltage(char *vdd_name
, char *clk_name
,
177 struct voltagedomain
*voltdm
;
180 unsigned long freq
, bootup_volt
;
182 if (!vdd_name
|| !clk_name
|| !dev
) {
183 printk(KERN_ERR
"%s: Invalid parameters!\n", __func__
);
187 voltdm
= omap_voltage_domain_lookup(vdd_name
);
188 if (IS_ERR(voltdm
)) {
189 printk(KERN_ERR
"%s: Unable to get vdd pointer for vdd_%s\n",
194 clk
= clk_get(NULL
, clk_name
);
196 printk(KERN_ERR
"%s: unable to get clk %s\n",
204 opp
= opp_find_freq_ceil(dev
, &freq
);
206 printk(KERN_ERR
"%s: unable to find boot up OPP for vdd_%s\n",
211 bootup_volt
= opp_get_voltage(opp
);
213 printk(KERN_ERR
"%s: unable to find voltage corresponding"
214 "to the bootup OPP for vdd_%s\n", __func__
, vdd_name
);
218 omap_voltage_scale_vdd(voltdm
, bootup_volt
);
222 printk(KERN_ERR
"%s: Unable to put vdd_%s to its init voltage\n\n",
227 static void __init
omap3_init_voltages(void)
229 if (!cpu_is_omap34xx())
232 omap2_set_init_voltage("mpu", "dpll1_ck", mpu_dev
);
233 omap2_set_init_voltage("core", "l3_ick", l3_dev
);
236 static void __init
omap4_init_voltages(void)
238 if (!cpu_is_omap44xx())
241 omap2_set_init_voltage("mpu", "dpll_mpu_ck", mpu_dev
);
242 omap2_set_init_voltage("core", "l3_div_ck", l3_dev
);
243 omap2_set_init_voltage("iva", "dpll_iva_m5x2_ck", iva_dev
);
246 static int __init
omap2_common_pm_init(void)
248 omap2_init_processor_devices();
253 postcore_initcall(omap2_common_pm_init
);
255 static int __init
omap2_common_pm_late_init(void)
257 /* Init the OMAP TWL parameters */
261 /* Init the voltage layer */
262 omap_voltage_late_init();
264 /* Initialize the voltages */
265 omap3_init_voltages();
266 omap4_init_voltages();
268 /* Smartreflex device init */
269 omap_devinit_smartreflex();
273 late_initcall(omap2_common_pm_late_init
);