OMAP: pm.c correct the initcall for an early init.
[linux-2.6/linux-acpi-2.6/ibm-acpi-2.6.git] / arch / arm / mach-omap2 / pm.c
blob6ec2ee12272a31eb3774501e60ff78832b38111e
1 /*
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>
14 #include <linux/io.h>
15 #include <linux/err.h>
17 #include <plat/omap-pm.h>
18 #include <plat/omap_device.h>
19 #include <plat/common.h>
21 #include <plat/powerdomain.h>
22 #include <plat/clockdomain.h>
24 static struct omap_device_pm_latency *pm_lats;
26 static struct device *mpu_dev;
27 static struct device *iva_dev;
28 static struct device *l3_dev;
29 static struct device *dsp_dev;
31 struct device *omap2_get_mpuss_device(void)
33 WARN_ON_ONCE(!mpu_dev);
34 return mpu_dev;
37 struct device *omap2_get_iva_device(void)
39 WARN_ON_ONCE(!iva_dev);
40 return iva_dev;
43 struct device *omap2_get_l3_device(void)
45 WARN_ON_ONCE(!l3_dev);
46 return l3_dev;
49 struct device *omap4_get_dsp_device(void)
51 WARN_ON_ONCE(!dsp_dev);
52 return dsp_dev;
54 EXPORT_SYMBOL(omap4_get_dsp_device);
56 /* static int _init_omap_device(struct omap_hwmod *oh, void *user) */
57 static int _init_omap_device(char *name, struct device **new_dev)
59 struct omap_hwmod *oh;
60 struct omap_device *od;
62 oh = omap_hwmod_lookup(name);
63 if (WARN(!oh, "%s: could not find omap_hwmod for %s\n",
64 __func__, name))
65 return -ENODEV;
67 od = omap_device_build(oh->name, 0, oh, NULL, 0, pm_lats, 0, false);
68 if (WARN(IS_ERR(od), "%s: could not build omap_device for %s\n",
69 __func__, name))
70 return -ENODEV;
72 *new_dev = &od->pdev.dev;
74 return 0;
78 * Build omap_devices for processors and bus.
80 static void omap2_init_processor_devices(void)
82 _init_omap_device("mpu", &mpu_dev);
83 _init_omap_device("iva", &iva_dev);
84 if (cpu_is_omap44xx()) {
85 _init_omap_device("l3_main_1", &l3_dev);
86 _init_omap_device("dsp", &dsp_dev);
87 } else {
88 _init_omap_device("l3_main", &l3_dev);
93 * This sets pwrdm state (other than mpu & core. Currently only ON &
94 * RET are supported. Function is assuming that clkdm doesn't have
95 * hw_sup mode enabled.
97 int omap_set_pwrdm_state(struct powerdomain *pwrdm, u32 state)
99 u32 cur_state;
100 int sleep_switch = 0;
101 int ret = 0;
103 if (pwrdm == NULL || IS_ERR(pwrdm))
104 return -EINVAL;
106 while (!(pwrdm->pwrsts & (1 << state))) {
107 if (state == PWRDM_POWER_OFF)
108 return ret;
109 state--;
112 cur_state = pwrdm_read_next_pwrst(pwrdm);
113 if (cur_state == state)
114 return ret;
116 if (pwrdm_read_pwrst(pwrdm) < PWRDM_POWER_ON) {
117 omap2_clkdm_wakeup(pwrdm->pwrdm_clkdms[0]);
118 sleep_switch = 1;
119 pwrdm_wait_transition(pwrdm);
122 ret = pwrdm_set_next_pwrst(pwrdm, state);
123 if (ret) {
124 printk(KERN_ERR "Unable to set state of powerdomain: %s\n",
125 pwrdm->name);
126 goto err;
129 if (sleep_switch) {
130 omap2_clkdm_allow_idle(pwrdm->pwrdm_clkdms[0]);
131 pwrdm_wait_transition(pwrdm);
132 pwrdm_state_switch(pwrdm);
135 err:
136 return ret;
139 static int __init omap2_common_pm_init(void)
141 omap2_init_processor_devices();
142 omap_pm_if_init();
144 return 0;
146 postcore_initcall(omap2_common_pm_init);