blob: 83358f920e4cc4913f760c22a3438c2673e55c43 [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"
Thara Gopinath0c0a5d62010-05-29 22:02:23 +053024#include "pm.h"
Santosh Shilimkareb6a2c72010-09-15 01:04:01 +053025
Kevin Hilman6f88e9b2010-07-26 16:34:31 -060026static struct omap_device_pm_latency *pm_lats;
27
28static struct device *mpu_dev;
Thara Gopinathb3294e22010-09-01 13:44:53 +053029static struct device *iva_dev;
Kevin Hilman6f88e9b2010-07-26 16:34:31 -060030static struct device *l3_dev;
Thara Gopinathb3294e22010-09-01 13:44:53 +053031static struct device *dsp_dev;
Kevin Hilman6f88e9b2010-07-26 16:34:31 -060032
33struct device *omap2_get_mpuss_device(void)
34{
35 WARN_ON_ONCE(!mpu_dev);
36 return mpu_dev;
37}
38
Thara Gopinathb3294e22010-09-01 13:44:53 +053039struct device *omap2_get_iva_device(void)
Kevin Hilman6f88e9b2010-07-26 16:34:31 -060040{
Thara Gopinathb3294e22010-09-01 13:44:53 +053041 WARN_ON_ONCE(!iva_dev);
42 return iva_dev;
Kevin Hilman6f88e9b2010-07-26 16:34:31 -060043}
44
45struct device *omap2_get_l3_device(void)
46{
47 WARN_ON_ONCE(!l3_dev);
48 return l3_dev;
49}
50
Thara Gopinathb3294e22010-09-01 13:44:53 +053051struct device *omap4_get_dsp_device(void)
52{
53 WARN_ON_ONCE(!dsp_dev);
54 return dsp_dev;
55}
56EXPORT_SYMBOL(omap4_get_dsp_device);
57
Kevin Hilman6f88e9b2010-07-26 16:34:31 -060058/* static int _init_omap_device(struct omap_hwmod *oh, void *user) */
59static int _init_omap_device(char *name, struct device **new_dev)
60{
61 struct omap_hwmod *oh;
62 struct omap_device *od;
63
64 oh = omap_hwmod_lookup(name);
65 if (WARN(!oh, "%s: could not find omap_hwmod for %s\n",
66 __func__, name))
67 return -ENODEV;
68
69 od = omap_device_build(oh->name, 0, oh, NULL, 0, pm_lats, 0, false);
70 if (WARN(IS_ERR(od), "%s: could not build omap_device for %s\n",
71 __func__, name))
72 return -ENODEV;
73
74 *new_dev = &od->pdev.dev;
75
76 return 0;
77}
78
79/*
80 * Build omap_devices for processors and bus.
81 */
82static void omap2_init_processor_devices(void)
83{
84 _init_omap_device("mpu", &mpu_dev);
Thara Gopinathb3294e22010-09-01 13:44:53 +053085 _init_omap_device("iva", &iva_dev);
Benoit Coussoncbf27662010-08-05 15:22:35 +020086 if (cpu_is_omap44xx()) {
87 _init_omap_device("l3_main_1", &l3_dev);
Thara Gopinathb3294e22010-09-01 13:44:53 +053088 _init_omap_device("dsp", &dsp_dev);
Benoit Coussoncbf27662010-08-05 15:22:35 +020089 } else {
90 _init_omap_device("l3_main", &l3_dev);
91 }
Kevin Hilman6f88e9b2010-07-26 16:34:31 -060092}
93
Rajendra Nayak71a488d2010-12-21 22:37:27 -070094/* Types of sleep_switch used in omap_set_pwrdm_state */
95#define FORCEWAKEUP_SWITCH 0
96#define LOWPOWERSTATE_SWITCH 1
97
Santosh Shilimkareb6a2c72010-09-15 01:04:01 +053098/*
99 * This sets pwrdm state (other than mpu & core. Currently only ON &
Rajendra Nayak33de32b2010-12-21 22:37:28 -0700100 * RET are supported.
Santosh Shilimkareb6a2c72010-09-15 01:04:01 +0530101 */
102int omap_set_pwrdm_state(struct powerdomain *pwrdm, u32 state)
103{
104 u32 cur_state;
105 int sleep_switch = 0;
106 int ret = 0;
107
108 if (pwrdm == NULL || IS_ERR(pwrdm))
109 return -EINVAL;
110
111 while (!(pwrdm->pwrsts & (1 << state))) {
112 if (state == PWRDM_POWER_OFF)
113 return ret;
114 state--;
115 }
116
117 cur_state = pwrdm_read_next_pwrst(pwrdm);
118 if (cur_state == state)
119 return ret;
120
121 if (pwrdm_read_pwrst(pwrdm) < PWRDM_POWER_ON) {
Rajendra Nayak71a488d2010-12-21 22:37:27 -0700122 if ((pwrdm_read_pwrst(pwrdm) > state) &&
123 (pwrdm->flags & PWRDM_HAS_LOWPOWERSTATECHANGE)) {
124 sleep_switch = LOWPOWERSTATE_SWITCH;
125 } else {
126 omap2_clkdm_wakeup(pwrdm->pwrdm_clkdms[0]);
127 pwrdm_wait_transition(pwrdm);
128 sleep_switch = FORCEWAKEUP_SWITCH;
129 }
Santosh Shilimkareb6a2c72010-09-15 01:04:01 +0530130 }
131
132 ret = pwrdm_set_next_pwrst(pwrdm, state);
133 if (ret) {
134 printk(KERN_ERR "Unable to set state of powerdomain: %s\n",
135 pwrdm->name);
136 goto err;
137 }
138
Rajendra Nayak71a488d2010-12-21 22:37:27 -0700139 switch (sleep_switch) {
140 case FORCEWAKEUP_SWITCH:
Rajendra Nayak33de32b2010-12-21 22:37:28 -0700141 if (pwrdm->pwrdm_clkdms[0]->flags & CLKDM_CAN_ENABLE_AUTO)
142 omap2_clkdm_allow_idle(pwrdm->pwrdm_clkdms[0]);
143 else
144 omap2_clkdm_sleep(pwrdm->pwrdm_clkdms[0]);
Rajendra Nayak71a488d2010-12-21 22:37:27 -0700145 break;
146 case LOWPOWERSTATE_SWITCH:
147 pwrdm_set_lowpwrstchange(pwrdm);
148 break;
149 default:
150 return ret;
Santosh Shilimkareb6a2c72010-09-15 01:04:01 +0530151 }
152
Rajendra Nayak71a488d2010-12-21 22:37:27 -0700153 pwrdm_wait_transition(pwrdm);
154 pwrdm_state_switch(pwrdm);
Santosh Shilimkareb6a2c72010-09-15 01:04:01 +0530155err:
156 return ret;
157}
158
Kevin Hilman6f88e9b2010-07-26 16:34:31 -0600159static int __init omap2_common_pm_init(void)
160{
161 omap2_init_processor_devices();
162 omap_pm_if_init();
163
164 return 0;
165}
Thara Gopinath1cbbe372010-12-20 21:17:21 +0530166postcore_initcall(omap2_common_pm_init);
Kevin Hilman6f88e9b2010-07-26 16:34:31 -0600167
Thara Gopinath2f34ce82010-05-29 22:02:21 +0530168static int __init omap2_common_pm_late_init(void)
169{
Thara Gopinathfbc319f2010-12-10 22:51:05 +0530170 /* Init the OMAP TWL parameters */
171 omap3_twl_init();
172 /* Init the voltage layer */
Thara Gopinath2f34ce82010-05-29 22:02:21 +0530173 omap_voltage_late_init();
Thara Gopinathfbc319f2010-12-10 22:51:05 +0530174 /* Smartreflex device init */
Thara Gopinath0c0a5d62010-05-29 22:02:23 +0530175 omap_devinit_smartreflex();
Thara Gopinath2f34ce82010-05-29 22:02:21 +0530176
177 return 0;
178}
179late_initcall(omap2_common_pm_late_init);