Kevin Hilman | 6f88e9b | 2010-07-26 16:34:31 -0600 | [diff] [blame] | 1 | /* |
| 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 Menon | e4db1c7 | 2013-09-19 16:03:52 -0500 | [diff] [blame] | 16 | #include <linux/pm_opp.h> |
Paul Gortmaker | dc28094 | 2011-07-31 16:17:29 -0400 | [diff] [blame] | 17 | #include <linux/export.h> |
Paul Walmsley | 1416408 | 2012-02-02 02:30:50 -0700 | [diff] [blame] | 18 | #include <linux/suspend.h> |
Kevin Hilman | 24d7b40 | 2012-09-06 14:03:08 -0700 | [diff] [blame] | 19 | #include <linux/cpu.h> |
Kevin Hilman | 6f88e9b | 2010-07-26 16:34:31 -0600 | [diff] [blame] | 20 | |
Govindraj.R | 335aece | 2012-03-29 09:30:28 -0700 | [diff] [blame] | 21 | #include <asm/system_misc.h> |
| 22 | |
Tony Lindgren | 1d5aef4 | 2012-10-03 16:36:40 -0700 | [diff] [blame] | 23 | #include "omap-pm.h" |
Tony Lindgren | 25c7d49 | 2012-10-02 17:25:48 -0700 | [diff] [blame] | 24 | #include "omap_device.h" |
Tony Lindgren | 4e65331 | 2011-11-10 22:45:17 +0100 | [diff] [blame] | 25 | #include "common.h" |
Kevin Hilman | 6f88e9b | 2010-07-26 16:34:31 -0600 | [diff] [blame] | 26 | |
Tony Lindgren | e4c060d | 2012-10-05 13:25:59 -0700 | [diff] [blame] | 27 | #include "soc.h" |
Paul Walmsley | 1416408 | 2012-02-02 02:30:50 -0700 | [diff] [blame] | 28 | #include "prcm-common.h" |
Paul Walmsley | e1d6f47 | 2011-02-25 15:54:33 -0700 | [diff] [blame] | 29 | #include "voltage.h" |
Paul Walmsley | 72e06d0 | 2010-12-21 21:05:16 -0700 | [diff] [blame] | 30 | #include "powerdomain.h" |
Paul Walmsley | 1540f214 | 2010-12-21 21:05:15 -0700 | [diff] [blame] | 31 | #include "clockdomain.h" |
Thara Gopinath | 0c0a5d6 | 2010-05-29 22:02:23 +0530 | [diff] [blame] | 32 | #include "pm.h" |
Santosh Shilimkar | eb6a2c7 | 2010-09-15 01:04:01 +0530 | [diff] [blame] | 33 | |
Dave Gerlach | 2e4b62d | 2014-05-12 13:33:21 -0500 | [diff] [blame] | 34 | #ifdef CONFIG_SUSPEND |
Paul Walmsley | 1416408 | 2012-02-02 02:30:50 -0700 | [diff] [blame] | 35 | /* |
| 36 | * omap_pm_suspend: points to a function that does the SoC-specific |
| 37 | * suspend work |
| 38 | */ |
Dave Gerlach | 2e4b62d | 2014-05-12 13:33:21 -0500 | [diff] [blame] | 39 | static int (*omap_pm_suspend)(void); |
| 40 | #endif |
Paul Walmsley | 1416408 | 2012-02-02 02:30:50 -0700 | [diff] [blame] | 41 | |
Kevin Hilman | 74d2916 | 2012-11-14 17:13:04 -0800 | [diff] [blame] | 42 | #ifdef CONFIG_PM |
Tero Kristo | 908b75e | 2012-09-25 19:33:39 +0300 | [diff] [blame] | 43 | /** |
| 44 | * struct omap2_oscillator - Describe the board main oscillator latencies |
| 45 | * @startup_time: oscillator startup latency |
| 46 | * @shutdown_time: oscillator shutdown latency |
| 47 | */ |
| 48 | struct omap2_oscillator { |
| 49 | u32 startup_time; |
| 50 | u32 shutdown_time; |
| 51 | }; |
| 52 | |
| 53 | static struct omap2_oscillator oscillator = { |
| 54 | .startup_time = ULONG_MAX, |
| 55 | .shutdown_time = ULONG_MAX, |
| 56 | }; |
| 57 | |
| 58 | void omap_pm_setup_oscillator(u32 tstart, u32 tshut) |
| 59 | { |
| 60 | oscillator.startup_time = tstart; |
| 61 | oscillator.shutdown_time = tshut; |
| 62 | } |
| 63 | |
| 64 | void 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 Hilman | 74d2916 | 2012-11-14 17:13:04 -0800 | [diff] [blame] | 72 | #endif |
Tero Kristo | 908b75e | 2012-09-25 19:33:39 +0300 | [diff] [blame] | 73 | |
Paul Walmsley | 92206fd | 2012-02-02 02:38:50 -0700 | [diff] [blame] | 74 | int __init omap_pm_clkdms_setup(struct clockdomain *clkdm, void *unused) |
| 75 | { |
Tero Kristo | 1d9a542 | 2016-06-30 16:15:02 +0300 | [diff] [blame] | 76 | clkdm_allow_idle(clkdm); |
Paul Walmsley | 92206fd | 2012-02-02 02:38:50 -0700 | [diff] [blame] | 77 | return 0; |
| 78 | } |
| 79 | |
Santosh Shilimkar | eb6a2c7 | 2010-09-15 01:04:01 +0530 | [diff] [blame] | 80 | /* |
Johan Hovold | 1e2d2df | 2011-08-30 18:48:16 +0200 | [diff] [blame] | 81 | * 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] | 82 | * 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 Hovold | 1e2d2df | 2011-08-30 18:48:16 +0200 | [diff] [blame] | 85 | * opp entry and sets the voltage domain to the voltage specified |
Thara Gopinath | 1482d8b | 2010-05-29 22:02:25 +0530 | [diff] [blame] | 86 | * in the opp entry |
| 87 | */ |
| 88 | 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] | 89 | const char *oh_name) |
Thara Gopinath | 1482d8b | 2010-05-29 22:02:25 +0530 | [diff] [blame] | 90 | { |
| 91 | struct voltagedomain *voltdm; |
| 92 | struct clk *clk; |
Nishanth Menon | 47d43ba | 2013-09-19 16:03:51 -0500 | [diff] [blame] | 93 | struct dev_pm_opp *opp; |
Thara Gopinath | 1482d8b | 2010-05-29 22:02:25 +0530 | [diff] [blame] | 94 | unsigned long freq, bootup_volt; |
Benoit Cousson | 0f7aa00 | 2011-08-16 15:02:20 +0200 | [diff] [blame] | 95 | struct device *dev; |
Thara Gopinath | 1482d8b | 2010-05-29 22:02:25 +0530 | [diff] [blame] | 96 | |
Benoit Cousson | 0f7aa00 | 2011-08-16 15:02:20 +0200 | [diff] [blame] | 97 | if (!vdd_name || !clk_name || !oh_name) { |
Johan Hovold | e9a5190 | 2011-08-30 18:48:17 +0200 | [diff] [blame] | 98 | pr_err("%s: invalid parameters\n", __func__); |
Thara Gopinath | 1482d8b | 2010-05-29 22:02:25 +0530 | [diff] [blame] | 99 | goto exit; |
| 100 | } |
| 101 | |
Kevin Hilman | 24d7b40 | 2012-09-06 14:03:08 -0700 | [diff] [blame] | 102 | 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 Cousson | 0f7aa00 | 2011-08-16 15:02:20 +0200 | [diff] [blame] | 111 | 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 Hilman | 81a6048 | 2011-03-16 14:25:45 -0700 | [diff] [blame] | 117 | voltdm = voltdm_lookup(vdd_name); |
Wei Yongjun | 93b44be | 2012-09-27 13:54:36 +0800 | [diff] [blame] | 118 | if (!voltdm) { |
Johan Hovold | e9a5190 | 2011-08-30 18:48:17 +0200 | [diff] [blame] | 119 | pr_err("%s: unable to get vdd pointer for vdd_%s\n", |
Thara Gopinath | 1482d8b | 2010-05-29 22:02:25 +0530 | [diff] [blame] | 120 | __func__, vdd_name); |
| 121 | goto exit; |
| 122 | } |
| 123 | |
| 124 | clk = clk_get(NULL, clk_name); |
| 125 | if (IS_ERR(clk)) { |
Johan Hovold | e9a5190 | 2011-08-30 18:48:17 +0200 | [diff] [blame] | 126 | pr_err("%s: unable to get clk %s\n", __func__, clk_name); |
Thara Gopinath | 1482d8b | 2010-05-29 22:02:25 +0530 | [diff] [blame] | 127 | goto exit; |
| 128 | } |
| 129 | |
Rajendra Nayak | 5dcc3b9 | 2012-09-22 02:24:17 -0600 | [diff] [blame] | 130 | freq = clk_get_rate(clk); |
Thara Gopinath | 1482d8b | 2010-05-29 22:02:25 +0530 | [diff] [blame] | 131 | clk_put(clk); |
| 132 | |
NeilBrown | 6369fd4 | 2012-01-09 13:14:12 +1100 | [diff] [blame] | 133 | rcu_read_lock(); |
Nishanth Menon | 5d4879c | 2013-09-19 16:03:50 -0500 | [diff] [blame] | 134 | opp = dev_pm_opp_find_freq_ceil(dev, &freq); |
Thara Gopinath | 1482d8b | 2010-05-29 22:02:25 +0530 | [diff] [blame] | 135 | if (IS_ERR(opp)) { |
NeilBrown | 6369fd4 | 2012-01-09 13:14:12 +1100 | [diff] [blame] | 136 | rcu_read_unlock(); |
Johan Hovold | e9a5190 | 2011-08-30 18:48:17 +0200 | [diff] [blame] | 137 | 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] | 138 | __func__, vdd_name); |
| 139 | goto exit; |
| 140 | } |
| 141 | |
Nishanth Menon | 5d4879c | 2013-09-19 16:03:50 -0500 | [diff] [blame] | 142 | bootup_volt = dev_pm_opp_get_voltage(opp); |
NeilBrown | 6369fd4 | 2012-01-09 13:14:12 +1100 | [diff] [blame] | 143 | rcu_read_unlock(); |
Thara Gopinath | 1482d8b | 2010-05-29 22:02:25 +0530 | [diff] [blame] | 144 | if (!bootup_volt) { |
Paul Walmsley | 7852ec0 | 2012-07-26 00:54:26 -0600 | [diff] [blame] | 145 | pr_err("%s: unable to find voltage corresponding to the bootup OPP for vdd_%s\n", |
| 146 | __func__, vdd_name); |
Thara Gopinath | 1482d8b | 2010-05-29 22:02:25 +0530 | [diff] [blame] | 147 | goto exit; |
| 148 | } |
| 149 | |
Kevin Hilman | 5e5651b | 2011-04-05 16:27:21 -0700 | [diff] [blame] | 150 | voltdm_scale(voltdm, bootup_volt); |
Thara Gopinath | 1482d8b | 2010-05-29 22:02:25 +0530 | [diff] [blame] | 151 | return 0; |
| 152 | |
| 153 | exit: |
Johan Hovold | e9a5190 | 2011-08-30 18:48:17 +0200 | [diff] [blame] | 154 | pr_err("%s: unable to set vdd_%s\n", __func__, vdd_name); |
Thara Gopinath | 1482d8b | 2010-05-29 22:02:25 +0530 | [diff] [blame] | 155 | return -EINVAL; |
| 156 | } |
| 157 | |
Paul Walmsley | 1416408 | 2012-02-02 02:30:50 -0700 | [diff] [blame] | 158 | #ifdef CONFIG_SUSPEND |
| 159 | static 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 | |
| 178 | static int omap_pm_begin(suspend_state_t state) |
| 179 | { |
Thomas Gleixner | f7b861b | 2013-03-21 22:49:38 +0100 | [diff] [blame] | 180 | cpu_idle_poll_ctrl(true); |
Tony Lindgren | cb6675d | 2016-10-17 00:08:40 -0700 | [diff] [blame] | 181 | if (soc_is_omap34xx()) |
Paul Walmsley | 1416408 | 2012-02-02 02:30:50 -0700 | [diff] [blame] | 182 | omap_prcm_irq_prepare(); |
| 183 | return 0; |
| 184 | } |
| 185 | |
| 186 | static void omap_pm_end(void) |
| 187 | { |
Thomas Gleixner | f7b861b | 2013-03-21 22:49:38 +0100 | [diff] [blame] | 188 | cpu_idle_poll_ctrl(false); |
Paul Walmsley | 1416408 | 2012-02-02 02:30:50 -0700 | [diff] [blame] | 189 | } |
| 190 | |
| 191 | static void omap_pm_finish(void) |
| 192 | { |
Tony Lindgren | cb6675d | 2016-10-17 00:08:40 -0700 | [diff] [blame] | 193 | if (soc_is_omap34xx()) |
Paul Walmsley | 1416408 | 2012-02-02 02:30:50 -0700 | [diff] [blame] | 194 | omap_prcm_irq_complete(); |
| 195 | } |
| 196 | |
| 197 | static 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 Gerlach | 2e4b62d | 2014-05-12 13:33:21 -0500 | [diff] [blame] | 205 | /** |
| 206 | * omap_common_suspend_init - Set common suspend routines for OMAP SoCs |
| 207 | * @pm_suspend: function pointer to SoC specific suspend function |
| 208 | */ |
| 209 | void omap_common_suspend_init(void *pm_suspend) |
| 210 | { |
| 211 | omap_pm_suspend = pm_suspend; |
| 212 | suspend_set_ops(&omap_pm_ops); |
| 213 | } |
Paul Walmsley | 1416408 | 2012-02-02 02:30:50 -0700 | [diff] [blame] | 214 | #endif /* CONFIG_SUSPEND */ |
| 215 | |
Thara Gopinath | 1482d8b | 2010-05-29 22:02:25 +0530 | [diff] [blame] | 216 | static void __init omap3_init_voltages(void) |
| 217 | { |
Tony Lindgren | cb6675d | 2016-10-17 00:08:40 -0700 | [diff] [blame] | 218 | if (!soc_is_omap34xx()) |
Thara Gopinath | 1482d8b | 2010-05-29 22:02:25 +0530 | [diff] [blame] | 219 | return; |
| 220 | |
Benoit Cousson | 0f7aa00 | 2011-08-16 15:02:20 +0200 | [diff] [blame] | 221 | omap2_set_init_voltage("mpu_iva", "dpll1_ck", "mpu"); |
| 222 | omap2_set_init_voltage("core", "l3_ick", "l3_main"); |
Thara Gopinath | 1482d8b | 2010-05-29 22:02:25 +0530 | [diff] [blame] | 223 | } |
| 224 | |
Thara Gopinath | 1376ee1 | 2010-05-29 22:02:25 +0530 | [diff] [blame] | 225 | static void __init omap4_init_voltages(void) |
| 226 | { |
Tony Lindgren | cb6675d | 2016-10-17 00:08:40 -0700 | [diff] [blame] | 227 | if (!soc_is_omap44xx()) |
Thara Gopinath | 1376ee1 | 2010-05-29 22:02:25 +0530 | [diff] [blame] | 228 | return; |
| 229 | |
Benoit Cousson | 0f7aa00 | 2011-08-16 15:02:20 +0200 | [diff] [blame] | 230 | 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 Gopinath | 1376ee1 | 2010-05-29 22:02:25 +0530 | [diff] [blame] | 233 | } |
| 234 | |
Kevin Hilman | 6f88e9b | 2010-07-26 16:34:31 -0600 | [diff] [blame] | 235 | static int __init omap2_common_pm_init(void) |
| 236 | { |
Kevin Hilman | 6f88e9b | 2010-07-26 16:34:31 -0600 | [diff] [blame] | 237 | omap_pm_if_init(); |
| 238 | |
| 239 | return 0; |
| 240 | } |
Tony Lindgren | b76c8b19 | 2013-01-11 11:24:18 -0800 | [diff] [blame] | 241 | omap_postcore_initcall(omap2_common_pm_init); |
Kevin Hilman | 6f88e9b | 2010-07-26 16:34:31 -0600 | [diff] [blame] | 242 | |
Shawn Guo | bbd707a | 2012-04-26 16:06:50 +0800 | [diff] [blame] | 243 | int __init omap2_common_pm_late_init(void) |
Thara Gopinath | 2f34ce8 | 2010-05-29 22:02:21 +0530 | [diff] [blame] | 244 | { |
Tony Lindgren | 2ee5f52 | 2014-05-05 17:27:37 -0700 | [diff] [blame] | 245 | /* Init the voltage layer */ |
Tony Lindgren | cb6675d | 2016-10-17 00:08:40 -0700 | [diff] [blame] | 246 | omap3_twl_init(); |
| 247 | omap4_twl_init(); |
Tony Lindgren | 2ee5f52 | 2014-05-05 17:27:37 -0700 | [diff] [blame] | 248 | 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 Gopinath | 2f34ce8 | 2010-05-29 22:02:21 +0530 | [diff] [blame] | 257 | return 0; |
| 258 | } |