blob: 366158a54fcd8beae9ff50d712e1b5c63f87d456 [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
Dave Gerlach33d38422017-03-28 20:57:56 -050074int omap_pm_clkdms_setup(struct clockdomain *clkdm, void *unused)
Paul Walmsley92206fd2012-02-02 02:38:50 -070075{
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
Nishanth Menon5d4879c2013-09-19 16:03:50 -0500133 opp = dev_pm_opp_find_freq_ceil(dev, &freq);
Thara Gopinath1482d8b2010-05-29 22:02:25 +0530134 if (IS_ERR(opp)) {
Johan Hovolde9a51902011-08-30 18:48:17 +0200135 pr_err("%s: unable to find boot up OPP for vdd_%s\n",
Thara Gopinath1482d8b2010-05-29 22:02:25 +0530136 __func__, vdd_name);
137 goto exit;
138 }
139
Nishanth Menon5d4879c2013-09-19 16:03:50 -0500140 bootup_volt = dev_pm_opp_get_voltage(opp);
Viresh Kumar8a31d9d92017-01-23 10:11:47 +0530141 dev_pm_opp_put(opp);
142
Thara Gopinath1482d8b2010-05-29 22:02:25 +0530143 if (!bootup_volt) {
Paul Walmsley7852ec02012-07-26 00:54:26 -0600144 pr_err("%s: unable to find voltage corresponding to the bootup OPP for vdd_%s\n",
145 __func__, vdd_name);
Thara Gopinath1482d8b2010-05-29 22:02:25 +0530146 goto exit;
147 }
148
Kevin Hilman5e5651b2011-04-05 16:27:21 -0700149 voltdm_scale(voltdm, bootup_volt);
Thara Gopinath1482d8b2010-05-29 22:02:25 +0530150 return 0;
151
152exit:
Johan Hovolde9a51902011-08-30 18:48:17 +0200153 pr_err("%s: unable to set vdd_%s\n", __func__, vdd_name);
Thara Gopinath1482d8b2010-05-29 22:02:25 +0530154 return -EINVAL;
155}
156
Paul Walmsley14164082012-02-02 02:30:50 -0700157#ifdef CONFIG_SUSPEND
158static int omap_pm_enter(suspend_state_t suspend_state)
159{
160 int ret = 0;
161
162 if (!omap_pm_suspend)
163 return -ENOENT; /* XXX doublecheck */
164
165 switch (suspend_state) {
Paul Walmsley14164082012-02-02 02:30:50 -0700166 case PM_SUSPEND_MEM:
167 ret = omap_pm_suspend();
168 break;
169 default:
170 ret = -EINVAL;
171 }
172
173 return ret;
174}
175
176static int omap_pm_begin(suspend_state_t state)
177{
Thomas Gleixnerf7b861b2013-03-21 22:49:38 +0100178 cpu_idle_poll_ctrl(true);
Tony Lindgrencb6675d2016-10-17 00:08:40 -0700179 if (soc_is_omap34xx())
Paul Walmsley14164082012-02-02 02:30:50 -0700180 omap_prcm_irq_prepare();
181 return 0;
182}
183
184static void omap_pm_end(void)
185{
Thomas Gleixnerf7b861b2013-03-21 22:49:38 +0100186 cpu_idle_poll_ctrl(false);
Paul Walmsley14164082012-02-02 02:30:50 -0700187}
188
189static void omap_pm_finish(void)
190{
Tony Lindgrencb6675d2016-10-17 00:08:40 -0700191 if (soc_is_omap34xx())
Paul Walmsley14164082012-02-02 02:30:50 -0700192 omap_prcm_irq_complete();
193}
194
195static const struct platform_suspend_ops omap_pm_ops = {
196 .begin = omap_pm_begin,
197 .end = omap_pm_end,
198 .enter = omap_pm_enter,
199 .finish = omap_pm_finish,
200 .valid = suspend_valid_only_mem,
201};
202
Dave Gerlach2e4b62d2014-05-12 13:33:21 -0500203/**
204 * omap_common_suspend_init - Set common suspend routines for OMAP SoCs
205 * @pm_suspend: function pointer to SoC specific suspend function
206 */
207void omap_common_suspend_init(void *pm_suspend)
208{
209 omap_pm_suspend = pm_suspend;
210 suspend_set_ops(&omap_pm_ops);
211}
Paul Walmsley14164082012-02-02 02:30:50 -0700212#endif /* CONFIG_SUSPEND */
213
Thara Gopinath1482d8b2010-05-29 22:02:25 +0530214static void __init omap3_init_voltages(void)
215{
Tony Lindgrencb6675d2016-10-17 00:08:40 -0700216 if (!soc_is_omap34xx())
Thara Gopinath1482d8b2010-05-29 22:02:25 +0530217 return;
218
Benoit Cousson0f7aa002011-08-16 15:02:20 +0200219 omap2_set_init_voltage("mpu_iva", "dpll1_ck", "mpu");
220 omap2_set_init_voltage("core", "l3_ick", "l3_main");
Thara Gopinath1482d8b2010-05-29 22:02:25 +0530221}
222
Thara Gopinath1376ee12010-05-29 22:02:25 +0530223static void __init omap4_init_voltages(void)
224{
Tony Lindgrencb6675d2016-10-17 00:08:40 -0700225 if (!soc_is_omap44xx())
Thara Gopinath1376ee12010-05-29 22:02:25 +0530226 return;
227
Benoit Cousson0f7aa002011-08-16 15:02:20 +0200228 omap2_set_init_voltage("mpu", "dpll_mpu_ck", "mpu");
229 omap2_set_init_voltage("core", "l3_div_ck", "l3_main_1");
230 omap2_set_init_voltage("iva", "dpll_iva_m5x2_ck", "iva");
Thara Gopinath1376ee12010-05-29 22:02:25 +0530231}
232
Kevin Hilman6f88e9b2010-07-26 16:34:31 -0600233static int __init omap2_common_pm_init(void)
234{
Kevin Hilman6f88e9b2010-07-26 16:34:31 -0600235 omap_pm_if_init();
236
237 return 0;
238}
Tony Lindgrenb76c8b192013-01-11 11:24:18 -0800239omap_postcore_initcall(omap2_common_pm_init);
Kevin Hilman6f88e9b2010-07-26 16:34:31 -0600240
Shawn Guobbd707a2012-04-26 16:06:50 +0800241int __init omap2_common_pm_late_init(void)
Thara Gopinath2f34ce82010-05-29 22:02:21 +0530242{
Tony Lindgren2ee5f522014-05-05 17:27:37 -0700243 /* Init the voltage layer */
Tony Lindgrencb6675d2016-10-17 00:08:40 -0700244 omap3_twl_init();
245 omap4_twl_init();
Tony Lindgren2ee5f522014-05-05 17:27:37 -0700246 omap_voltage_late_init();
247
248 /* Initialize the voltages */
249 omap3_init_voltages();
250 omap4_init_voltages();
251
252 /* Smartreflex device init */
253 omap_devinit_smartreflex();
254
Thara Gopinath2f34ce82010-05-29 22:02:21 +0530255 return 0;
256}