blob: e828616fa8b9ee1e52d4f8dfe3ee71ed842bb9de [file] [log] [blame]
Kevin Hilman6f88e9b2010-07-26 16:34:31 -06001/*
2 * pm.c - Common OMAP2+ power management-related code
3 *
4 * Copyright (C) 2010 Texas Instruments, Inc.
5 * Copyright (C) 2010 Nokia Corporation
6 *
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.
10 */
11
12#include <linux/kernel.h>
13#include <linux/init.h>
14#include <linux/io.h>
15#include <linux/err.h>
16
17#include <plat/omap-pm.h>
18#include <plat/omap_device.h>
19#include <plat/common.h>
Thara Gopinath2f34ce82010-05-29 22:02:21 +053020#include <plat/voltage.h>
Kevin Hilman6f88e9b2010-07-26 16:34:31 -060021
Paul Walmsley72e06d02010-12-21 21:05:16 -070022#include "powerdomain.h"
Paul Walmsley1540f2142010-12-21 21:05:15 -070023#include "clockdomain.h"
Santosh Shilimkareb6a2c72010-09-15 01:04:01 +053024
Kevin Hilman6f88e9b2010-07-26 16:34:31 -060025static struct omap_device_pm_latency *pm_lats;
26
27static struct device *mpu_dev;
Thara Gopinathb3294e22010-09-01 13:44:53 +053028static struct device *iva_dev;
Kevin Hilman6f88e9b2010-07-26 16:34:31 -060029static struct device *l3_dev;
Thara Gopinathb3294e22010-09-01 13:44:53 +053030static struct device *dsp_dev;
Kevin Hilman6f88e9b2010-07-26 16:34:31 -060031
32struct device *omap2_get_mpuss_device(void)
33{
34 WARN_ON_ONCE(!mpu_dev);
35 return mpu_dev;
36}
37
Thara Gopinathb3294e22010-09-01 13:44:53 +053038struct device *omap2_get_iva_device(void)
Kevin Hilman6f88e9b2010-07-26 16:34:31 -060039{
Thara Gopinathb3294e22010-09-01 13:44:53 +053040 WARN_ON_ONCE(!iva_dev);
41 return iva_dev;
Kevin Hilman6f88e9b2010-07-26 16:34:31 -060042}
43
44struct device *omap2_get_l3_device(void)
45{
46 WARN_ON_ONCE(!l3_dev);
47 return l3_dev;
48}
49
Thara Gopinathb3294e22010-09-01 13:44:53 +053050struct device *omap4_get_dsp_device(void)
51{
52 WARN_ON_ONCE(!dsp_dev);
53 return dsp_dev;
54}
55EXPORT_SYMBOL(omap4_get_dsp_device);
56
Kevin Hilman6f88e9b2010-07-26 16:34:31 -060057/* static int _init_omap_device(struct omap_hwmod *oh, void *user) */
58static int _init_omap_device(char *name, struct device **new_dev)
59{
60 struct omap_hwmod *oh;
61 struct omap_device *od;
62
63 oh = omap_hwmod_lookup(name);
64 if (WARN(!oh, "%s: could not find omap_hwmod for %s\n",
65 __func__, name))
66 return -ENODEV;
67
68 od = omap_device_build(oh->name, 0, oh, NULL, 0, pm_lats, 0, false);
69 if (WARN(IS_ERR(od), "%s: could not build omap_device for %s\n",
70 __func__, name))
71 return -ENODEV;
72
73 *new_dev = &od->pdev.dev;
74
75 return 0;
76}
77
78/*
79 * Build omap_devices for processors and bus.
80 */
81static void omap2_init_processor_devices(void)
82{
83 _init_omap_device("mpu", &mpu_dev);
Thara Gopinathb3294e22010-09-01 13:44:53 +053084 _init_omap_device("iva", &iva_dev);
Benoit Coussoncbf27662010-08-05 15:22:35 +020085 if (cpu_is_omap44xx()) {
86 _init_omap_device("l3_main_1", &l3_dev);
Thara Gopinathb3294e22010-09-01 13:44:53 +053087 _init_omap_device("dsp", &dsp_dev);
Benoit Coussoncbf27662010-08-05 15:22:35 +020088 } else {
89 _init_omap_device("l3_main", &l3_dev);
90 }
Kevin Hilman6f88e9b2010-07-26 16:34:31 -060091}
92
Rajendra Nayak71a488d2010-12-21 22:37:27 -070093/* Types of sleep_switch used in omap_set_pwrdm_state */
94#define FORCEWAKEUP_SWITCH 0
95#define LOWPOWERSTATE_SWITCH 1
96
Santosh Shilimkareb6a2c72010-09-15 01:04:01 +053097/*
98 * This sets pwrdm state (other than mpu & core. Currently only ON &
Rajendra Nayak33de32b2010-12-21 22:37:28 -070099 * RET are supported.
Santosh Shilimkareb6a2c72010-09-15 01:04:01 +0530100 */
101int omap_set_pwrdm_state(struct powerdomain *pwrdm, u32 state)
102{
103 u32 cur_state;
104 int sleep_switch = 0;
105 int ret = 0;
106
107 if (pwrdm == NULL || IS_ERR(pwrdm))
108 return -EINVAL;
109
110 while (!(pwrdm->pwrsts & (1 << state))) {
111 if (state == PWRDM_POWER_OFF)
112 return ret;
113 state--;
114 }
115
116 cur_state = pwrdm_read_next_pwrst(pwrdm);
117 if (cur_state == state)
118 return ret;
119
120 if (pwrdm_read_pwrst(pwrdm) < PWRDM_POWER_ON) {
Rajendra Nayak71a488d2010-12-21 22:37:27 -0700121 if ((pwrdm_read_pwrst(pwrdm) > state) &&
122 (pwrdm->flags & PWRDM_HAS_LOWPOWERSTATECHANGE)) {
123 sleep_switch = LOWPOWERSTATE_SWITCH;
124 } else {
125 omap2_clkdm_wakeup(pwrdm->pwrdm_clkdms[0]);
126 pwrdm_wait_transition(pwrdm);
127 sleep_switch = FORCEWAKEUP_SWITCH;
128 }
Santosh Shilimkareb6a2c72010-09-15 01:04:01 +0530129 }
130
131 ret = pwrdm_set_next_pwrst(pwrdm, state);
132 if (ret) {
133 printk(KERN_ERR "Unable to set state of powerdomain: %s\n",
134 pwrdm->name);
135 goto err;
136 }
137
Rajendra Nayak71a488d2010-12-21 22:37:27 -0700138 switch (sleep_switch) {
139 case FORCEWAKEUP_SWITCH:
Rajendra Nayak33de32b2010-12-21 22:37:28 -0700140 if (pwrdm->pwrdm_clkdms[0]->flags & CLKDM_CAN_ENABLE_AUTO)
141 omap2_clkdm_allow_idle(pwrdm->pwrdm_clkdms[0]);
142 else
143 omap2_clkdm_sleep(pwrdm->pwrdm_clkdms[0]);
Rajendra Nayak71a488d2010-12-21 22:37:27 -0700144 break;
145 case LOWPOWERSTATE_SWITCH:
146 pwrdm_set_lowpwrstchange(pwrdm);
147 break;
148 default:
149 return ret;
Santosh Shilimkareb6a2c72010-09-15 01:04:01 +0530150 }
151
Rajendra Nayak71a488d2010-12-21 22:37:27 -0700152 pwrdm_wait_transition(pwrdm);
153 pwrdm_state_switch(pwrdm);
Santosh Shilimkareb6a2c72010-09-15 01:04:01 +0530154err:
155 return ret;
156}
157
Kevin Hilman6f88e9b2010-07-26 16:34:31 -0600158static int __init omap2_common_pm_init(void)
159{
160 omap2_init_processor_devices();
161 omap_pm_if_init();
162
163 return 0;
164}
Thara Gopinath1cbbe372010-12-20 21:17:21 +0530165postcore_initcall(omap2_common_pm_init);
Kevin Hilman6f88e9b2010-07-26 16:34:31 -0600166
Thara Gopinath2f34ce82010-05-29 22:02:21 +0530167static int __init omap2_common_pm_late_init(void)
168{
169 omap_voltage_late_init();
170
171 return 0;
172}
173late_initcall(omap2_common_pm_late_init);