blob: 76b0454ddc4994220c2e6a2680ab596824caf7f6 [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>
Nishanth Menone4db1c72013-09-19 16:03:52 -050016#include <linux/pm_opp.h>
Paul Gortmakerdc280942011-07-31 16:17:29 -040017#include <linux/export.h>
Paul Walmsley14164082012-02-02 02:30:50 -070018#include <linux/suspend.h>
Kevin Hilman24d7b402012-09-06 14:03:08 -070019#include <linux/cpu.h>
Kevin Hilman6f88e9b2010-07-26 16:34:31 -060020
Govindraj.R335aece2012-03-29 09:30:28 -070021#include <asm/system_misc.h>
22
Tony Lindgren1d5aef42012-10-03 16:36:40 -070023#include "omap-pm.h"
Tony Lindgren25c7d492012-10-02 17:25:48 -070024#include "omap_device.h"
Tony Lindgren4e653312011-11-10 22:45:17 +010025#include "common.h"
Kevin Hilman6f88e9b2010-07-26 16:34:31 -060026
Tony Lindgrene4c060d2012-10-05 13:25:59 -070027#include "soc.h"
Paul Walmsley14164082012-02-02 02:30:50 -070028#include "prcm-common.h"
Paul Walmsleye1d6f472011-02-25 15:54:33 -070029#include "voltage.h"
Paul Walmsley72e06d02010-12-21 21:05:16 -070030#include "powerdomain.h"
Paul Walmsley1540f2142010-12-21 21:05:15 -070031#include "clockdomain.h"
Thara Gopinath0c0a5d62010-05-29 22:02:23 +053032#include "pm.h"
Santosh Shilimkareb6a2c72010-09-15 01:04:01 +053033
Dave Gerlach2e4b62d2014-05-12 13:33:21 -050034#ifdef CONFIG_SUSPEND
Paul Walmsley14164082012-02-02 02:30:50 -070035/*
36 * omap_pm_suspend: points to a function that does the SoC-specific
37 * suspend work
38 */
Dave Gerlach2e4b62d2014-05-12 13:33:21 -050039static int (*omap_pm_suspend)(void);
40#endif
Paul Walmsley14164082012-02-02 02:30:50 -070041
Kevin Hilman74d29162012-11-14 17:13:04 -080042#ifdef CONFIG_PM
Tero Kristo908b75e2012-09-25 19:33:39 +030043/**
44 * struct omap2_oscillator - Describe the board main oscillator latencies
45 * @startup_time: oscillator startup latency
46 * @shutdown_time: oscillator shutdown latency
47 */
48struct omap2_oscillator {
49 u32 startup_time;
50 u32 shutdown_time;
51};
52
53static struct omap2_oscillator oscillator = {
54 .startup_time = ULONG_MAX,
55 .shutdown_time = ULONG_MAX,
56};
57
58void omap_pm_setup_oscillator(u32 tstart, u32 tshut)
59{
60 oscillator.startup_time = tstart;
61 oscillator.shutdown_time = tshut;
62}
63
64void omap_pm_get_oscillator(u32 *tstart, u32 *tshut)
65{
66 if (!tstart || !tshut)
67 return;
68
69 *tstart = oscillator.startup_time;
70 *tshut = oscillator.shutdown_time;
71}
Kevin Hilman74d29162012-11-14 17:13:04 -080072#endif
Tero Kristo908b75e2012-09-25 19:33:39 +030073
Paul Walmsley92206fd2012-02-02 02:38:50 -070074int __init omap_pm_clkdms_setup(struct clockdomain *clkdm, void *unused)
75{
Tero Kristo1d9a5422016-06-30 16:15:02 +030076 clkdm_allow_idle(clkdm);
Paul Walmsley92206fd2012-02-02 02:38:50 -070077 return 0;
78}
79
Santosh Shilimkareb6a2c72010-09-15 01:04:01 +053080/*
Johan Hovold1e2d2df2011-08-30 18:48:16 +020081 * This API is to be called during init to set the various voltage
Thara Gopinath1482d8b2010-05-29 22:02:25 +053082 * domains to the voltage as per the opp table. Typically we boot up
83 * at the nominal voltage. So this function finds out the rate of
84 * the clock associated with the voltage domain, finds out the correct
Johan Hovold1e2d2df2011-08-30 18:48:16 +020085 * opp entry and sets the voltage domain to the voltage specified
Thara Gopinath1482d8b2010-05-29 22:02:25 +053086 * in the opp entry
87 */
88static int __init omap2_set_init_voltage(char *vdd_name, char *clk_name,
Benoit Cousson0f7aa002011-08-16 15:02:20 +020089 const char *oh_name)
Thara Gopinath1482d8b2010-05-29 22:02:25 +053090{
91 struct voltagedomain *voltdm;
92 struct clk *clk;
Nishanth Menon47d43ba2013-09-19 16:03:51 -050093 struct dev_pm_opp *opp;
Thara Gopinath1482d8b2010-05-29 22:02:25 +053094 unsigned long freq, bootup_volt;
Benoit Cousson0f7aa002011-08-16 15:02:20 +020095 struct device *dev;
Thara Gopinath1482d8b2010-05-29 22:02:25 +053096
Benoit Cousson0f7aa002011-08-16 15:02:20 +020097 if (!vdd_name || !clk_name || !oh_name) {
Johan Hovolde9a51902011-08-30 18:48:17 +020098 pr_err("%s: invalid parameters\n", __func__);
Thara Gopinath1482d8b2010-05-29 22:02:25 +053099 goto exit;
100 }
101
Kevin Hilman24d7b402012-09-06 14:03:08 -0700102 if (!strncmp(oh_name, "mpu", 3))
103 /*
104 * All current OMAPs share voltage rail and clock
105 * source, so CPU0 is used to represent the MPU-SS.
106 */
107 dev = get_cpu_device(0);
108 else
109 dev = omap_device_get_by_hwmod_name(oh_name);
110
Benoit Cousson0f7aa002011-08-16 15:02:20 +0200111 if (IS_ERR(dev)) {
112 pr_err("%s: Unable to get dev pointer for hwmod %s\n",
113 __func__, oh_name);
114 goto exit;
115 }
116
Kevin Hilman81a60482011-03-16 14:25:45 -0700117 voltdm = voltdm_lookup(vdd_name);
Wei Yongjun93b44be2012-09-27 13:54:36 +0800118 if (!voltdm) {
Johan Hovolde9a51902011-08-30 18:48:17 +0200119 pr_err("%s: unable to get vdd pointer for vdd_%s\n",
Thara Gopinath1482d8b2010-05-29 22:02:25 +0530120 __func__, vdd_name);
121 goto exit;
122 }
123
124 clk = clk_get(NULL, clk_name);
125 if (IS_ERR(clk)) {
Johan Hovolde9a51902011-08-30 18:48:17 +0200126 pr_err("%s: unable to get clk %s\n", __func__, clk_name);
Thara Gopinath1482d8b2010-05-29 22:02:25 +0530127 goto exit;
128 }
129
Rajendra Nayak5dcc3b92012-09-22 02:24:17 -0600130 freq = clk_get_rate(clk);
Thara Gopinath1482d8b2010-05-29 22:02:25 +0530131 clk_put(clk);
132
NeilBrown6369fd42012-01-09 13:14:12 +1100133 rcu_read_lock();
Nishanth Menon5d4879c2013-09-19 16:03:50 -0500134 opp = dev_pm_opp_find_freq_ceil(dev, &freq);
Thara Gopinath1482d8b2010-05-29 22:02:25 +0530135 if (IS_ERR(opp)) {
NeilBrown6369fd42012-01-09 13:14:12 +1100136 rcu_read_unlock();
Johan Hovolde9a51902011-08-30 18:48:17 +0200137 pr_err("%s: unable to find boot up OPP for vdd_%s\n",
Thara Gopinath1482d8b2010-05-29 22:02:25 +0530138 __func__, vdd_name);
139 goto exit;
140 }
141
Nishanth Menon5d4879c2013-09-19 16:03:50 -0500142 bootup_volt = dev_pm_opp_get_voltage(opp);
NeilBrown6369fd42012-01-09 13:14:12 +1100143 rcu_read_unlock();
Thara Gopinath1482d8b2010-05-29 22:02:25 +0530144 if (!bootup_volt) {
Paul Walmsley7852ec02012-07-26 00:54:26 -0600145 pr_err("%s: unable to find voltage corresponding to the bootup OPP for vdd_%s\n",
146 __func__, vdd_name);
Thara Gopinath1482d8b2010-05-29 22:02:25 +0530147 goto exit;
148 }
149
Kevin Hilman5e5651b2011-04-05 16:27:21 -0700150 voltdm_scale(voltdm, bootup_volt);
Thara Gopinath1482d8b2010-05-29 22:02:25 +0530151 return 0;
152
153exit:
Johan Hovolde9a51902011-08-30 18:48:17 +0200154 pr_err("%s: unable to set vdd_%s\n", __func__, vdd_name);
Thara Gopinath1482d8b2010-05-29 22:02:25 +0530155 return -EINVAL;
156}
157
Paul Walmsley14164082012-02-02 02:30:50 -0700158#ifdef CONFIG_SUSPEND
159static int omap_pm_enter(suspend_state_t suspend_state)
160{
161 int ret = 0;
162
163 if (!omap_pm_suspend)
164 return -ENOENT; /* XXX doublecheck */
165
166 switch (suspend_state) {
167 case PM_SUSPEND_STANDBY:
168 case PM_SUSPEND_MEM:
169 ret = omap_pm_suspend();
170 break;
171 default:
172 ret = -EINVAL;
173 }
174
175 return ret;
176}
177
178static int omap_pm_begin(suspend_state_t state)
179{
Thomas Gleixnerf7b861b2013-03-21 22:49:38 +0100180 cpu_idle_poll_ctrl(true);
Tony Lindgrencb6675d2016-10-17 00:08:40 -0700181 if (soc_is_omap34xx())
Paul Walmsley14164082012-02-02 02:30:50 -0700182 omap_prcm_irq_prepare();
183 return 0;
184}
185
186static void omap_pm_end(void)
187{
Thomas Gleixnerf7b861b2013-03-21 22:49:38 +0100188 cpu_idle_poll_ctrl(false);
Paul Walmsley14164082012-02-02 02:30:50 -0700189}
190
191static void omap_pm_finish(void)
192{
Tony Lindgrencb6675d2016-10-17 00:08:40 -0700193 if (soc_is_omap34xx())
Paul Walmsley14164082012-02-02 02:30:50 -0700194 omap_prcm_irq_complete();
195}
196
197static const struct platform_suspend_ops omap_pm_ops = {
198 .begin = omap_pm_begin,
199 .end = omap_pm_end,
200 .enter = omap_pm_enter,
201 .finish = omap_pm_finish,
202 .valid = suspend_valid_only_mem,
203};
204
Dave Gerlach2e4b62d2014-05-12 13:33:21 -0500205/**
206 * omap_common_suspend_init - Set common suspend routines for OMAP SoCs
207 * @pm_suspend: function pointer to SoC specific suspend function
208 */
209void omap_common_suspend_init(void *pm_suspend)
210{
211 omap_pm_suspend = pm_suspend;
212 suspend_set_ops(&omap_pm_ops);
213}
Paul Walmsley14164082012-02-02 02:30:50 -0700214#endif /* CONFIG_SUSPEND */
215
Thara Gopinath1482d8b2010-05-29 22:02:25 +0530216static void __init omap3_init_voltages(void)
217{
Tony Lindgrencb6675d2016-10-17 00:08:40 -0700218 if (!soc_is_omap34xx())
Thara Gopinath1482d8b2010-05-29 22:02:25 +0530219 return;
220
Benoit Cousson0f7aa002011-08-16 15:02:20 +0200221 omap2_set_init_voltage("mpu_iva", "dpll1_ck", "mpu");
222 omap2_set_init_voltage("core", "l3_ick", "l3_main");
Thara Gopinath1482d8b2010-05-29 22:02:25 +0530223}
224
Thara Gopinath1376ee12010-05-29 22:02:25 +0530225static void __init omap4_init_voltages(void)
226{
Tony Lindgrencb6675d2016-10-17 00:08:40 -0700227 if (!soc_is_omap44xx())
Thara Gopinath1376ee12010-05-29 22:02:25 +0530228 return;
229
Benoit Cousson0f7aa002011-08-16 15:02:20 +0200230 omap2_set_init_voltage("mpu", "dpll_mpu_ck", "mpu");
231 omap2_set_init_voltage("core", "l3_div_ck", "l3_main_1");
232 omap2_set_init_voltage("iva", "dpll_iva_m5x2_ck", "iva");
Thara Gopinath1376ee12010-05-29 22:02:25 +0530233}
234
Kevin Hilman6f88e9b2010-07-26 16:34:31 -0600235static int __init omap2_common_pm_init(void)
236{
Kevin Hilman6f88e9b2010-07-26 16:34:31 -0600237 omap_pm_if_init();
238
239 return 0;
240}
Tony Lindgrenb76c8b192013-01-11 11:24:18 -0800241omap_postcore_initcall(omap2_common_pm_init);
Kevin Hilman6f88e9b2010-07-26 16:34:31 -0600242
Shawn Guobbd707a2012-04-26 16:06:50 +0800243int __init omap2_common_pm_late_init(void)
Thara Gopinath2f34ce82010-05-29 22:02:21 +0530244{
Tony Lindgren2ee5f522014-05-05 17:27:37 -0700245 /* Init the voltage layer */
Tony Lindgrencb6675d2016-10-17 00:08:40 -0700246 omap3_twl_init();
247 omap4_twl_init();
Tony Lindgren2ee5f522014-05-05 17:27:37 -0700248 omap_voltage_late_init();
249
250 /* Initialize the voltages */
251 omap3_init_voltages();
252 omap4_init_voltages();
253
254 /* Smartreflex device init */
255 omap_devinit_smartreflex();
256
Thara Gopinath2f34ce82010-05-29 22:02:21 +0530257 return 0;
258}