blob: 9b1db592759f4ec84bbad572d06a4f6767ae5eb3 [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>
20
Paul Walmsley72e06d02010-12-21 21:05:16 -070021#include "powerdomain.h"
Paul Walmsley1540f2142010-12-21 21:05:15 -070022#include "clockdomain.h"
Santosh Shilimkareb6a2c72010-09-15 01:04:01 +053023
Kevin Hilman6f88e9b2010-07-26 16:34:31 -060024static struct omap_device_pm_latency *pm_lats;
25
26static struct device *mpu_dev;
Thara Gopinathb3294e22010-09-01 13:44:53 +053027static struct device *iva_dev;
Kevin Hilman6f88e9b2010-07-26 16:34:31 -060028static struct device *l3_dev;
Thara Gopinathb3294e22010-09-01 13:44:53 +053029static struct device *dsp_dev;
Kevin Hilman6f88e9b2010-07-26 16:34:31 -060030
31struct device *omap2_get_mpuss_device(void)
32{
33 WARN_ON_ONCE(!mpu_dev);
34 return mpu_dev;
35}
36
Thara Gopinathb3294e22010-09-01 13:44:53 +053037struct device *omap2_get_iva_device(void)
Kevin Hilman6f88e9b2010-07-26 16:34:31 -060038{
Thara Gopinathb3294e22010-09-01 13:44:53 +053039 WARN_ON_ONCE(!iva_dev);
40 return iva_dev;
Kevin Hilman6f88e9b2010-07-26 16:34:31 -060041}
42
43struct device *omap2_get_l3_device(void)
44{
45 WARN_ON_ONCE(!l3_dev);
46 return l3_dev;
47}
48
Thara Gopinathb3294e22010-09-01 13:44:53 +053049struct device *omap4_get_dsp_device(void)
50{
51 WARN_ON_ONCE(!dsp_dev);
52 return dsp_dev;
53}
54EXPORT_SYMBOL(omap4_get_dsp_device);
55
Kevin Hilman6f88e9b2010-07-26 16:34:31 -060056/* static int _init_omap_device(struct omap_hwmod *oh, void *user) */
57static int _init_omap_device(char *name, struct device **new_dev)
58{
59 struct omap_hwmod *oh;
60 struct omap_device *od;
61
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;
66
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;
71
72 *new_dev = &od->pdev.dev;
73
74 return 0;
75}
76
77/*
78 * Build omap_devices for processors and bus.
79 */
80static void omap2_init_processor_devices(void)
81{
82 _init_omap_device("mpu", &mpu_dev);
Thara Gopinathb3294e22010-09-01 13:44:53 +053083 _init_omap_device("iva", &iva_dev);
Benoit Coussoncbf27662010-08-05 15:22:35 +020084 if (cpu_is_omap44xx()) {
85 _init_omap_device("l3_main_1", &l3_dev);
Thara Gopinathb3294e22010-09-01 13:44:53 +053086 _init_omap_device("dsp", &dsp_dev);
Benoit Coussoncbf27662010-08-05 15:22:35 +020087 } else {
88 _init_omap_device("l3_main", &l3_dev);
89 }
Kevin Hilman6f88e9b2010-07-26 16:34:31 -060090}
91
Rajendra Nayak71a488d2010-12-21 22:37:27 -070092/* Types of sleep_switch used in omap_set_pwrdm_state */
93#define FORCEWAKEUP_SWITCH 0
94#define LOWPOWERSTATE_SWITCH 1
95
Santosh Shilimkareb6a2c72010-09-15 01:04:01 +053096/*
97 * This sets pwrdm state (other than mpu & core. Currently only ON &
Rajendra Nayak33de32b2010-12-21 22:37:28 -070098 * RET are supported.
Santosh Shilimkareb6a2c72010-09-15 01:04:01 +053099 */
100int omap_set_pwrdm_state(struct powerdomain *pwrdm, u32 state)
101{
102 u32 cur_state;
103 int sleep_switch = 0;
104 int ret = 0;
105
106 if (pwrdm == NULL || IS_ERR(pwrdm))
107 return -EINVAL;
108
109 while (!(pwrdm->pwrsts & (1 << state))) {
110 if (state == PWRDM_POWER_OFF)
111 return ret;
112 state--;
113 }
114
115 cur_state = pwrdm_read_next_pwrst(pwrdm);
116 if (cur_state == state)
117 return ret;
118
119 if (pwrdm_read_pwrst(pwrdm) < PWRDM_POWER_ON) {
Rajendra Nayak71a488d2010-12-21 22:37:27 -0700120 if ((pwrdm_read_pwrst(pwrdm) > state) &&
121 (pwrdm->flags & PWRDM_HAS_LOWPOWERSTATECHANGE)) {
122 sleep_switch = LOWPOWERSTATE_SWITCH;
123 } else {
124 omap2_clkdm_wakeup(pwrdm->pwrdm_clkdms[0]);
125 pwrdm_wait_transition(pwrdm);
126 sleep_switch = FORCEWAKEUP_SWITCH;
127 }
Santosh Shilimkareb6a2c72010-09-15 01:04:01 +0530128 }
129
130 ret = pwrdm_set_next_pwrst(pwrdm, state);
131 if (ret) {
132 printk(KERN_ERR "Unable to set state of powerdomain: %s\n",
133 pwrdm->name);
134 goto err;
135 }
136
Rajendra Nayak71a488d2010-12-21 22:37:27 -0700137 switch (sleep_switch) {
138 case FORCEWAKEUP_SWITCH:
Rajendra Nayak33de32b2010-12-21 22:37:28 -0700139 if (pwrdm->pwrdm_clkdms[0]->flags & CLKDM_CAN_ENABLE_AUTO)
140 omap2_clkdm_allow_idle(pwrdm->pwrdm_clkdms[0]);
141 else
142 omap2_clkdm_sleep(pwrdm->pwrdm_clkdms[0]);
Rajendra Nayak71a488d2010-12-21 22:37:27 -0700143 break;
144 case LOWPOWERSTATE_SWITCH:
145 pwrdm_set_lowpwrstchange(pwrdm);
146 break;
147 default:
148 return ret;
Santosh Shilimkareb6a2c72010-09-15 01:04:01 +0530149 }
150
Rajendra Nayak71a488d2010-12-21 22:37:27 -0700151 pwrdm_wait_transition(pwrdm);
152 pwrdm_state_switch(pwrdm);
Santosh Shilimkareb6a2c72010-09-15 01:04:01 +0530153err:
154 return ret;
155}
156
Kevin Hilman6f88e9b2010-07-26 16:34:31 -0600157static int __init omap2_common_pm_init(void)
158{
159 omap2_init_processor_devices();
160 omap_pm_if_init();
161
162 return 0;
163}
Thara Gopinath1cbbe372010-12-20 21:17:21 +0530164postcore_initcall(omap2_common_pm_init);
Kevin Hilman6f88e9b2010-07-26 16:34:31 -0600165