Thomas Gleixner | d2912cb | 2019-06-04 10:11:33 +0200 | [diff] [blame^] | 1 | // SPDX-License-Identifier: GPL-2.0-only |
Kevin Hilman | 6f88e9b | 2010-07-26 16:34:31 -0600 | [diff] [blame] | 2 | /* |
| 3 | * pm.c - Common OMAP2+ power management-related code |
| 4 | * |
| 5 | * Copyright (C) 2010 Texas Instruments, Inc. |
| 6 | * Copyright (C) 2010 Nokia Corporation |
Kevin Hilman | 6f88e9b | 2010-07-26 16:34:31 -0600 | [diff] [blame] | 7 | */ |
| 8 | |
| 9 | #include <linux/kernel.h> |
| 10 | #include <linux/init.h> |
| 11 | #include <linux/io.h> |
| 12 | #include <linux/err.h> |
Nishanth Menon | e4db1c7 | 2013-09-19 16:03:52 -0500 | [diff] [blame] | 13 | #include <linux/pm_opp.h> |
Paul Gortmaker | dc28094 | 2011-07-31 16:17:29 -0400 | [diff] [blame] | 14 | #include <linux/export.h> |
Paul Walmsley | 1416408 | 2012-02-02 02:30:50 -0700 | [diff] [blame] | 15 | #include <linux/suspend.h> |
Tony Lindgren | 44773ba | 2018-04-16 10:22:01 -0700 | [diff] [blame] | 16 | #include <linux/clk.h> |
Kevin Hilman | 24d7b40 | 2012-09-06 14:03:08 -0700 | [diff] [blame] | 17 | #include <linux/cpu.h> |
Kevin Hilman | 6f88e9b | 2010-07-26 16:34:31 -0600 | [diff] [blame] | 18 | |
Govindraj.R | 335aece | 2012-03-29 09:30:28 -0700 | [diff] [blame] | 19 | #include <asm/system_misc.h> |
| 20 | |
Tony Lindgren | 25c7d49 | 2012-10-02 17:25:48 -0700 | [diff] [blame] | 21 | #include "omap_device.h" |
Tony Lindgren | 4e65331 | 2011-11-10 22:45:17 +0100 | [diff] [blame] | 22 | #include "common.h" |
Kevin Hilman | 6f88e9b | 2010-07-26 16:34:31 -0600 | [diff] [blame] | 23 | |
Tony Lindgren | e4c060d | 2012-10-05 13:25:59 -0700 | [diff] [blame] | 24 | #include "soc.h" |
Paul Walmsley | 1416408 | 2012-02-02 02:30:50 -0700 | [diff] [blame] | 25 | #include "prcm-common.h" |
Paul Walmsley | e1d6f47 | 2011-02-25 15:54:33 -0700 | [diff] [blame] | 26 | #include "voltage.h" |
Paul Walmsley | 72e06d0 | 2010-12-21 21:05:16 -0700 | [diff] [blame] | 27 | #include "powerdomain.h" |
Paul Walmsley | 1540f214 | 2010-12-21 21:05:15 -0700 | [diff] [blame] | 28 | #include "clockdomain.h" |
Thara Gopinath | 0c0a5d6 | 2010-05-29 22:02:23 +0530 | [diff] [blame] | 29 | #include "pm.h" |
Santosh Shilimkar | eb6a2c7 | 2010-09-15 01:04:01 +0530 | [diff] [blame] | 30 | |
Dave Gerlach | 2e4b62d | 2014-05-12 13:33:21 -0500 | [diff] [blame] | 31 | #ifdef CONFIG_SUSPEND |
Paul Walmsley | 1416408 | 2012-02-02 02:30:50 -0700 | [diff] [blame] | 32 | /* |
| 33 | * omap_pm_suspend: points to a function that does the SoC-specific |
| 34 | * suspend work |
| 35 | */ |
Dave Gerlach | 2e4b62d | 2014-05-12 13:33:21 -0500 | [diff] [blame] | 36 | static int (*omap_pm_suspend)(void); |
| 37 | #endif |
Paul Walmsley | 1416408 | 2012-02-02 02:30:50 -0700 | [diff] [blame] | 38 | |
Kevin Hilman | 74d2916 | 2012-11-14 17:13:04 -0800 | [diff] [blame] | 39 | #ifdef CONFIG_PM |
Tero Kristo | 908b75e | 2012-09-25 19:33:39 +0300 | [diff] [blame] | 40 | /** |
| 41 | * struct omap2_oscillator - Describe the board main oscillator latencies |
| 42 | * @startup_time: oscillator startup latency |
| 43 | * @shutdown_time: oscillator shutdown latency |
| 44 | */ |
| 45 | struct omap2_oscillator { |
| 46 | u32 startup_time; |
| 47 | u32 shutdown_time; |
| 48 | }; |
| 49 | |
| 50 | static struct omap2_oscillator oscillator = { |
| 51 | .startup_time = ULONG_MAX, |
| 52 | .shutdown_time = ULONG_MAX, |
| 53 | }; |
| 54 | |
| 55 | void omap_pm_setup_oscillator(u32 tstart, u32 tshut) |
| 56 | { |
| 57 | oscillator.startup_time = tstart; |
| 58 | oscillator.shutdown_time = tshut; |
| 59 | } |
| 60 | |
| 61 | void omap_pm_get_oscillator(u32 *tstart, u32 *tshut) |
| 62 | { |
| 63 | if (!tstart || !tshut) |
| 64 | return; |
| 65 | |
| 66 | *tstart = oscillator.startup_time; |
| 67 | *tshut = oscillator.shutdown_time; |
| 68 | } |
Kevin Hilman | 74d2916 | 2012-11-14 17:13:04 -0800 | [diff] [blame] | 69 | #endif |
Tero Kristo | 908b75e | 2012-09-25 19:33:39 +0300 | [diff] [blame] | 70 | |
Dave Gerlach | 33d3842 | 2017-03-28 20:57:56 -0500 | [diff] [blame] | 71 | int omap_pm_clkdms_setup(struct clockdomain *clkdm, void *unused) |
Paul Walmsley | 92206fd | 2012-02-02 02:38:50 -0700 | [diff] [blame] | 72 | { |
Tero Kristo | 1d9a542 | 2016-06-30 16:15:02 +0300 | [diff] [blame] | 73 | clkdm_allow_idle(clkdm); |
Paul Walmsley | 92206fd | 2012-02-02 02:38:50 -0700 | [diff] [blame] | 74 | return 0; |
| 75 | } |
| 76 | |
Santosh Shilimkar | eb6a2c7 | 2010-09-15 01:04:01 +0530 | [diff] [blame] | 77 | /* |
Johan Hovold | 1e2d2df | 2011-08-30 18:48:16 +0200 | [diff] [blame] | 78 | * This API is to be called during init to set the various voltage |
Thara Gopinath | 1482d8b | 2010-05-29 22:02:25 +0530 | [diff] [blame] | 79 | * domains to the voltage as per the opp table. Typically we boot up |
| 80 | * at the nominal voltage. So this function finds out the rate of |
| 81 | * the clock associated with the voltage domain, finds out the correct |
Johan Hovold | 1e2d2df | 2011-08-30 18:48:16 +0200 | [diff] [blame] | 82 | * opp entry and sets the voltage domain to the voltage specified |
Thara Gopinath | 1482d8b | 2010-05-29 22:02:25 +0530 | [diff] [blame] | 83 | * in the opp entry |
| 84 | */ |
| 85 | static int __init omap2_set_init_voltage(char *vdd_name, char *clk_name, |
Benoit Cousson | 0f7aa00 | 2011-08-16 15:02:20 +0200 | [diff] [blame] | 86 | const char *oh_name) |
Thara Gopinath | 1482d8b | 2010-05-29 22:02:25 +0530 | [diff] [blame] | 87 | { |
| 88 | struct voltagedomain *voltdm; |
| 89 | struct clk *clk; |
Nishanth Menon | 47d43ba | 2013-09-19 16:03:51 -0500 | [diff] [blame] | 90 | struct dev_pm_opp *opp; |
Thara Gopinath | 1482d8b | 2010-05-29 22:02:25 +0530 | [diff] [blame] | 91 | unsigned long freq, bootup_volt; |
Benoit Cousson | 0f7aa00 | 2011-08-16 15:02:20 +0200 | [diff] [blame] | 92 | struct device *dev; |
Thara Gopinath | 1482d8b | 2010-05-29 22:02:25 +0530 | [diff] [blame] | 93 | |
Benoit Cousson | 0f7aa00 | 2011-08-16 15:02:20 +0200 | [diff] [blame] | 94 | if (!vdd_name || !clk_name || !oh_name) { |
Johan Hovold | e9a5190 | 2011-08-30 18:48:17 +0200 | [diff] [blame] | 95 | pr_err("%s: invalid parameters\n", __func__); |
Thara Gopinath | 1482d8b | 2010-05-29 22:02:25 +0530 | [diff] [blame] | 96 | goto exit; |
| 97 | } |
| 98 | |
Kevin Hilman | 24d7b40 | 2012-09-06 14:03:08 -0700 | [diff] [blame] | 99 | if (!strncmp(oh_name, "mpu", 3)) |
| 100 | /* |
| 101 | * All current OMAPs share voltage rail and clock |
| 102 | * source, so CPU0 is used to represent the MPU-SS. |
| 103 | */ |
| 104 | dev = get_cpu_device(0); |
| 105 | else |
| 106 | dev = omap_device_get_by_hwmod_name(oh_name); |
| 107 | |
Benoit Cousson | 0f7aa00 | 2011-08-16 15:02:20 +0200 | [diff] [blame] | 108 | if (IS_ERR(dev)) { |
| 109 | pr_err("%s: Unable to get dev pointer for hwmod %s\n", |
| 110 | __func__, oh_name); |
| 111 | goto exit; |
| 112 | } |
| 113 | |
Kevin Hilman | 81a6048 | 2011-03-16 14:25:45 -0700 | [diff] [blame] | 114 | voltdm = voltdm_lookup(vdd_name); |
Wei Yongjun | 93b44be | 2012-09-27 13:54:36 +0800 | [diff] [blame] | 115 | if (!voltdm) { |
Johan Hovold | e9a5190 | 2011-08-30 18:48:17 +0200 | [diff] [blame] | 116 | pr_err("%s: unable to get vdd pointer for vdd_%s\n", |
Thara Gopinath | 1482d8b | 2010-05-29 22:02:25 +0530 | [diff] [blame] | 117 | __func__, vdd_name); |
| 118 | goto exit; |
| 119 | } |
| 120 | |
| 121 | clk = clk_get(NULL, clk_name); |
| 122 | if (IS_ERR(clk)) { |
Johan Hovold | e9a5190 | 2011-08-30 18:48:17 +0200 | [diff] [blame] | 123 | pr_err("%s: unable to get clk %s\n", __func__, clk_name); |
Thara Gopinath | 1482d8b | 2010-05-29 22:02:25 +0530 | [diff] [blame] | 124 | goto exit; |
| 125 | } |
| 126 | |
Rajendra Nayak | 5dcc3b9 | 2012-09-22 02:24:17 -0600 | [diff] [blame] | 127 | freq = clk_get_rate(clk); |
Thara Gopinath | 1482d8b | 2010-05-29 22:02:25 +0530 | [diff] [blame] | 128 | clk_put(clk); |
| 129 | |
Nishanth Menon | 5d4879c | 2013-09-19 16:03:50 -0500 | [diff] [blame] | 130 | opp = dev_pm_opp_find_freq_ceil(dev, &freq); |
Thara Gopinath | 1482d8b | 2010-05-29 22:02:25 +0530 | [diff] [blame] | 131 | if (IS_ERR(opp)) { |
Johan Hovold | e9a5190 | 2011-08-30 18:48:17 +0200 | [diff] [blame] | 132 | pr_err("%s: unable to find boot up OPP for vdd_%s\n", |
Thara Gopinath | 1482d8b | 2010-05-29 22:02:25 +0530 | [diff] [blame] | 133 | __func__, vdd_name); |
| 134 | goto exit; |
| 135 | } |
| 136 | |
Nishanth Menon | 5d4879c | 2013-09-19 16:03:50 -0500 | [diff] [blame] | 137 | bootup_volt = dev_pm_opp_get_voltage(opp); |
Viresh Kumar | 8a31d9d9 | 2017-01-23 10:11:47 +0530 | [diff] [blame] | 138 | dev_pm_opp_put(opp); |
| 139 | |
Thara Gopinath | 1482d8b | 2010-05-29 22:02:25 +0530 | [diff] [blame] | 140 | if (!bootup_volt) { |
Paul Walmsley | 7852ec0 | 2012-07-26 00:54:26 -0600 | [diff] [blame] | 141 | pr_err("%s: unable to find voltage corresponding to the bootup OPP for vdd_%s\n", |
| 142 | __func__, vdd_name); |
Thara Gopinath | 1482d8b | 2010-05-29 22:02:25 +0530 | [diff] [blame] | 143 | goto exit; |
| 144 | } |
| 145 | |
Kevin Hilman | 5e5651b | 2011-04-05 16:27:21 -0700 | [diff] [blame] | 146 | voltdm_scale(voltdm, bootup_volt); |
Thara Gopinath | 1482d8b | 2010-05-29 22:02:25 +0530 | [diff] [blame] | 147 | return 0; |
| 148 | |
| 149 | exit: |
Johan Hovold | e9a5190 | 2011-08-30 18:48:17 +0200 | [diff] [blame] | 150 | pr_err("%s: unable to set vdd_%s\n", __func__, vdd_name); |
Thara Gopinath | 1482d8b | 2010-05-29 22:02:25 +0530 | [diff] [blame] | 151 | return -EINVAL; |
| 152 | } |
| 153 | |
Paul Walmsley | 1416408 | 2012-02-02 02:30:50 -0700 | [diff] [blame] | 154 | #ifdef CONFIG_SUSPEND |
| 155 | static int omap_pm_enter(suspend_state_t suspend_state) |
| 156 | { |
| 157 | int ret = 0; |
| 158 | |
| 159 | if (!omap_pm_suspend) |
| 160 | return -ENOENT; /* XXX doublecheck */ |
| 161 | |
| 162 | switch (suspend_state) { |
Paul Walmsley | 1416408 | 2012-02-02 02:30:50 -0700 | [diff] [blame] | 163 | case PM_SUSPEND_MEM: |
| 164 | ret = omap_pm_suspend(); |
| 165 | break; |
| 166 | default: |
| 167 | ret = -EINVAL; |
| 168 | } |
| 169 | |
| 170 | return ret; |
| 171 | } |
| 172 | |
| 173 | static int omap_pm_begin(suspend_state_t state) |
| 174 | { |
Thomas Gleixner | f7b861b | 2013-03-21 22:49:38 +0100 | [diff] [blame] | 175 | cpu_idle_poll_ctrl(true); |
Tony Lindgren | cb6675d | 2016-10-17 00:08:40 -0700 | [diff] [blame] | 176 | if (soc_is_omap34xx()) |
Paul Walmsley | 1416408 | 2012-02-02 02:30:50 -0700 | [diff] [blame] | 177 | omap_prcm_irq_prepare(); |
| 178 | return 0; |
| 179 | } |
| 180 | |
| 181 | static void omap_pm_end(void) |
| 182 | { |
Thomas Gleixner | f7b861b | 2013-03-21 22:49:38 +0100 | [diff] [blame] | 183 | cpu_idle_poll_ctrl(false); |
Paul Walmsley | 1416408 | 2012-02-02 02:30:50 -0700 | [diff] [blame] | 184 | } |
| 185 | |
Tony Lindgren | d3be6d2 | 2018-02-09 08:15:53 -0800 | [diff] [blame] | 186 | static void omap_pm_wake(void) |
Paul Walmsley | 1416408 | 2012-02-02 02:30:50 -0700 | [diff] [blame] | 187 | { |
Tony Lindgren | cb6675d | 2016-10-17 00:08:40 -0700 | [diff] [blame] | 188 | if (soc_is_omap34xx()) |
Paul Walmsley | 1416408 | 2012-02-02 02:30:50 -0700 | [diff] [blame] | 189 | omap_prcm_irq_complete(); |
| 190 | } |
| 191 | |
| 192 | static const struct platform_suspend_ops omap_pm_ops = { |
| 193 | .begin = omap_pm_begin, |
| 194 | .end = omap_pm_end, |
| 195 | .enter = omap_pm_enter, |
Tony Lindgren | d3be6d2 | 2018-02-09 08:15:53 -0800 | [diff] [blame] | 196 | .wake = omap_pm_wake, |
Paul Walmsley | 1416408 | 2012-02-02 02:30:50 -0700 | [diff] [blame] | 197 | .valid = suspend_valid_only_mem, |
| 198 | }; |
| 199 | |
Dave Gerlach | 2e4b62d | 2014-05-12 13:33:21 -0500 | [diff] [blame] | 200 | /** |
| 201 | * omap_common_suspend_init - Set common suspend routines for OMAP SoCs |
| 202 | * @pm_suspend: function pointer to SoC specific suspend function |
| 203 | */ |
| 204 | void omap_common_suspend_init(void *pm_suspend) |
| 205 | { |
| 206 | omap_pm_suspend = pm_suspend; |
| 207 | suspend_set_ops(&omap_pm_ops); |
| 208 | } |
Paul Walmsley | 1416408 | 2012-02-02 02:30:50 -0700 | [diff] [blame] | 209 | #endif /* CONFIG_SUSPEND */ |
| 210 | |
Thara Gopinath | 1482d8b | 2010-05-29 22:02:25 +0530 | [diff] [blame] | 211 | static void __init omap3_init_voltages(void) |
| 212 | { |
Tony Lindgren | cb6675d | 2016-10-17 00:08:40 -0700 | [diff] [blame] | 213 | if (!soc_is_omap34xx()) |
Thara Gopinath | 1482d8b | 2010-05-29 22:02:25 +0530 | [diff] [blame] | 214 | return; |
| 215 | |
Benoit Cousson | 0f7aa00 | 2011-08-16 15:02:20 +0200 | [diff] [blame] | 216 | omap2_set_init_voltage("mpu_iva", "dpll1_ck", "mpu"); |
| 217 | omap2_set_init_voltage("core", "l3_ick", "l3_main"); |
Thara Gopinath | 1482d8b | 2010-05-29 22:02:25 +0530 | [diff] [blame] | 218 | } |
| 219 | |
Thara Gopinath | 1376ee1 | 2010-05-29 22:02:25 +0530 | [diff] [blame] | 220 | static void __init omap4_init_voltages(void) |
| 221 | { |
Tony Lindgren | cb6675d | 2016-10-17 00:08:40 -0700 | [diff] [blame] | 222 | if (!soc_is_omap44xx()) |
Thara Gopinath | 1376ee1 | 2010-05-29 22:02:25 +0530 | [diff] [blame] | 223 | return; |
| 224 | |
Benoit Cousson | 0f7aa00 | 2011-08-16 15:02:20 +0200 | [diff] [blame] | 225 | omap2_set_init_voltage("mpu", "dpll_mpu_ck", "mpu"); |
| 226 | omap2_set_init_voltage("core", "l3_div_ck", "l3_main_1"); |
| 227 | omap2_set_init_voltage("iva", "dpll_iva_m5x2_ck", "iva"); |
Thara Gopinath | 1376ee1 | 2010-05-29 22:02:25 +0530 | [diff] [blame] | 228 | } |
| 229 | |
Tony Lindgren | 02b83dc | 2018-04-16 10:23:46 -0700 | [diff] [blame] | 230 | int __maybe_unused omap_pm_nop_init(void) |
| 231 | { |
| 232 | return 0; |
| 233 | } |
| 234 | |
| 235 | int (*omap_pm_soc_init)(void); |
| 236 | |
Shawn Guo | bbd707a | 2012-04-26 16:06:50 +0800 | [diff] [blame] | 237 | int __init omap2_common_pm_late_init(void) |
Thara Gopinath | 2f34ce8 | 2010-05-29 22:02:21 +0530 | [diff] [blame] | 238 | { |
Tony Lindgren | 02b83dc | 2018-04-16 10:23:46 -0700 | [diff] [blame] | 239 | int error; |
| 240 | |
| 241 | if (!omap_pm_soc_init) |
| 242 | return 0; |
| 243 | |
Tony Lindgren | 2ee5f52 | 2014-05-05 17:27:37 -0700 | [diff] [blame] | 244 | /* Init the voltage layer */ |
Tony Lindgren | cb6675d | 2016-10-17 00:08:40 -0700 | [diff] [blame] | 245 | omap3_twl_init(); |
| 246 | omap4_twl_init(); |
Tony Lindgren | 2ee5f52 | 2014-05-05 17:27:37 -0700 | [diff] [blame] | 247 | omap_voltage_late_init(); |
| 248 | |
| 249 | /* Initialize the voltages */ |
| 250 | omap3_init_voltages(); |
| 251 | omap4_init_voltages(); |
| 252 | |
| 253 | /* Smartreflex device init */ |
| 254 | omap_devinit_smartreflex(); |
| 255 | |
Tony Lindgren | 02b83dc | 2018-04-16 10:23:46 -0700 | [diff] [blame] | 256 | error = omap_pm_soc_init(); |
| 257 | if (error) |
| 258 | pr_warn("%s: pm soc init failed: %i\n", __func__, error); |
| 259 | |
| 260 | omap2_clk_enable_autoidle_all(); |
| 261 | |
Thara Gopinath | 2f34ce8 | 2010-05-29 22:02:21 +0530 | [diff] [blame] | 262 | return 0; |
| 263 | } |
Tony Lindgren | 02b83dc | 2018-04-16 10:23:46 -0700 | [diff] [blame] | 264 | omap_late_initcall(omap2_common_pm_late_init); |