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> |
Thara Gopinath | 1482d8b | 2010-05-29 22:02:25 +0530 | [diff] [blame] | 16 | #include <linux/opp.h> |
Paul Gortmaker | dc28094 | 2011-07-31 16:17:29 -0400 | [diff] [blame] | 17 | #include <linux/export.h> |
Kevin Hilman | 6f88e9b | 2010-07-26 16:34:31 -0600 | [diff] [blame] | 18 | |
| 19 | #include <plat/omap-pm.h> |
| 20 | #include <plat/omap_device.h> |
| 21 | #include <plat/common.h> |
| 22 | |
Paul Walmsley | e1d6f47 | 2011-02-25 15:54:33 -0700 | [diff] [blame] | 23 | #include "voltage.h" |
Paul Walmsley | 72e06d0 | 2010-12-21 21:05:16 -0700 | [diff] [blame] | 24 | #include "powerdomain.h" |
Paul Walmsley | 1540f214 | 2010-12-21 21:05:15 -0700 | [diff] [blame] | 25 | #include "clockdomain.h" |
Thara Gopinath | 0c0a5d6 | 2010-05-29 22:02:23 +0530 | [diff] [blame] | 26 | #include "pm.h" |
Santosh Shilimkar | eb6a2c7 | 2010-09-15 01:04:01 +0530 | [diff] [blame] | 27 | |
Kevin Hilman | 6f88e9b | 2010-07-26 16:34:31 -0600 | [diff] [blame] | 28 | static struct omap_device_pm_latency *pm_lats; |
| 29 | |
Benoit Cousson | 766e7af | 2011-08-16 15:03:59 +0200 | [diff] [blame] | 30 | static int _init_omap_device(char *name) |
Kevin Hilman | 6f88e9b | 2010-07-26 16:34:31 -0600 | [diff] [blame] | 31 | { |
| 32 | struct omap_hwmod *oh; |
Kevin Hilman | 3528c58 | 2011-07-21 13:48:45 -0700 | [diff] [blame] | 33 | struct platform_device *pdev; |
Kevin Hilman | 6f88e9b | 2010-07-26 16:34:31 -0600 | [diff] [blame] | 34 | |
| 35 | oh = omap_hwmod_lookup(name); |
| 36 | if (WARN(!oh, "%s: could not find omap_hwmod for %s\n", |
| 37 | __func__, name)) |
| 38 | return -ENODEV; |
| 39 | |
Kevin Hilman | 3528c58 | 2011-07-21 13:48:45 -0700 | [diff] [blame] | 40 | pdev = omap_device_build(oh->name, 0, oh, NULL, 0, pm_lats, 0, false); |
| 41 | if (WARN(IS_ERR(pdev), "%s: could not build omap_device for %s\n", |
Kevin Hilman | 6f88e9b | 2010-07-26 16:34:31 -0600 | [diff] [blame] | 42 | __func__, name)) |
| 43 | return -ENODEV; |
| 44 | |
Kevin Hilman | 6f88e9b | 2010-07-26 16:34:31 -0600 | [diff] [blame] | 45 | return 0; |
| 46 | } |
| 47 | |
| 48 | /* |
| 49 | * Build omap_devices for processors and bus. |
| 50 | */ |
| 51 | static void omap2_init_processor_devices(void) |
| 52 | { |
Benoit Cousson | 766e7af | 2011-08-16 15:03:59 +0200 | [diff] [blame] | 53 | _init_omap_device("mpu"); |
Sanjeev Premi | 2de0bae | 2011-02-25 18:57:20 +0530 | [diff] [blame] | 54 | if (omap3_has_iva()) |
Benoit Cousson | 766e7af | 2011-08-16 15:03:59 +0200 | [diff] [blame] | 55 | _init_omap_device("iva"); |
Sanjeev Premi | 2de0bae | 2011-02-25 18:57:20 +0530 | [diff] [blame] | 56 | |
Benoit Cousson | cbf2766 | 2010-08-05 15:22:35 +0200 | [diff] [blame] | 57 | if (cpu_is_omap44xx()) { |
Benoit Cousson | 766e7af | 2011-08-16 15:03:59 +0200 | [diff] [blame] | 58 | _init_omap_device("l3_main_1"); |
| 59 | _init_omap_device("dsp"); |
| 60 | _init_omap_device("iva"); |
Benoit Cousson | cbf2766 | 2010-08-05 15:22:35 +0200 | [diff] [blame] | 61 | } else { |
Benoit Cousson | 766e7af | 2011-08-16 15:03:59 +0200 | [diff] [blame] | 62 | _init_omap_device("l3_main"); |
Benoit Cousson | cbf2766 | 2010-08-05 15:22:35 +0200 | [diff] [blame] | 63 | } |
Kevin Hilman | 6f88e9b | 2010-07-26 16:34:31 -0600 | [diff] [blame] | 64 | } |
| 65 | |
Rajendra Nayak | 71a488d | 2010-12-21 22:37:27 -0700 | [diff] [blame] | 66 | /* Types of sleep_switch used in omap_set_pwrdm_state */ |
| 67 | #define FORCEWAKEUP_SWITCH 0 |
| 68 | #define LOWPOWERSTATE_SWITCH 1 |
| 69 | |
Santosh Shilimkar | eb6a2c7 | 2010-09-15 01:04:01 +0530 | [diff] [blame] | 70 | /* |
| 71 | * This sets pwrdm state (other than mpu & core. Currently only ON & |
Rajendra Nayak | 33de32b | 2010-12-21 22:37:28 -0700 | [diff] [blame] | 72 | * RET are supported. |
Santosh Shilimkar | eb6a2c7 | 2010-09-15 01:04:01 +0530 | [diff] [blame] | 73 | */ |
| 74 | int omap_set_pwrdm_state(struct powerdomain *pwrdm, u32 state) |
| 75 | { |
| 76 | u32 cur_state; |
Rajendra Nayak | 6349b96 | 2011-07-09 20:42:11 -0600 | [diff] [blame] | 77 | int sleep_switch = -1; |
Santosh Shilimkar | eb6a2c7 | 2010-09-15 01:04:01 +0530 | [diff] [blame] | 78 | int ret = 0; |
Rajendra Nayak | b86cfb5 | 2011-07-10 05:56:54 -0600 | [diff] [blame] | 79 | int hwsup = 0; |
Santosh Shilimkar | eb6a2c7 | 2010-09-15 01:04:01 +0530 | [diff] [blame] | 80 | |
| 81 | if (pwrdm == NULL || IS_ERR(pwrdm)) |
| 82 | return -EINVAL; |
| 83 | |
| 84 | while (!(pwrdm->pwrsts & (1 << state))) { |
| 85 | if (state == PWRDM_POWER_OFF) |
| 86 | return ret; |
| 87 | state--; |
| 88 | } |
| 89 | |
| 90 | cur_state = pwrdm_read_next_pwrst(pwrdm); |
| 91 | if (cur_state == state) |
| 92 | return ret; |
| 93 | |
| 94 | if (pwrdm_read_pwrst(pwrdm) < PWRDM_POWER_ON) { |
Rajendra Nayak | 71a488d | 2010-12-21 22:37:27 -0700 | [diff] [blame] | 95 | if ((pwrdm_read_pwrst(pwrdm) > state) && |
| 96 | (pwrdm->flags & PWRDM_HAS_LOWPOWERSTATECHANGE)) { |
| 97 | sleep_switch = LOWPOWERSTATE_SWITCH; |
| 98 | } else { |
Rajendra Nayak | b86cfb5 | 2011-07-10 05:56:54 -0600 | [diff] [blame] | 99 | hwsup = clkdm_in_hwsup(pwrdm->pwrdm_clkdms[0]); |
Rajendra Nayak | 68b921a | 2011-02-25 16:06:47 -0700 | [diff] [blame] | 100 | clkdm_wakeup(pwrdm->pwrdm_clkdms[0]); |
Rajendra Nayak | 71a488d | 2010-12-21 22:37:27 -0700 | [diff] [blame] | 101 | sleep_switch = FORCEWAKEUP_SWITCH; |
| 102 | } |
Santosh Shilimkar | eb6a2c7 | 2010-09-15 01:04:01 +0530 | [diff] [blame] | 103 | } |
| 104 | |
| 105 | ret = pwrdm_set_next_pwrst(pwrdm, state); |
| 106 | if (ret) { |
Johan Hovold | e9a5190 | 2011-08-30 18:48:17 +0200 | [diff] [blame] | 107 | pr_err("%s: unable to set state of powerdomain: %s\n", |
| 108 | __func__, pwrdm->name); |
Santosh Shilimkar | eb6a2c7 | 2010-09-15 01:04:01 +0530 | [diff] [blame] | 109 | goto err; |
| 110 | } |
| 111 | |
Rajendra Nayak | 71a488d | 2010-12-21 22:37:27 -0700 | [diff] [blame] | 112 | switch (sleep_switch) { |
| 113 | case FORCEWAKEUP_SWITCH: |
Rajendra Nayak | b86cfb5 | 2011-07-10 05:56:54 -0600 | [diff] [blame] | 114 | if (hwsup) |
Rajendra Nayak | 5cd1937 | 2011-02-25 16:06:48 -0700 | [diff] [blame] | 115 | clkdm_allow_idle(pwrdm->pwrdm_clkdms[0]); |
Rajendra Nayak | 33de32b | 2010-12-21 22:37:28 -0700 | [diff] [blame] | 116 | else |
Rajendra Nayak | 68b921a | 2011-02-25 16:06:47 -0700 | [diff] [blame] | 117 | clkdm_sleep(pwrdm->pwrdm_clkdms[0]); |
Rajendra Nayak | 71a488d | 2010-12-21 22:37:27 -0700 | [diff] [blame] | 118 | break; |
| 119 | case LOWPOWERSTATE_SWITCH: |
| 120 | pwrdm_set_lowpwrstchange(pwrdm); |
| 121 | break; |
| 122 | default: |
| 123 | return ret; |
Santosh Shilimkar | eb6a2c7 | 2010-09-15 01:04:01 +0530 | [diff] [blame] | 124 | } |
| 125 | |
Rajendra Nayak | 71a488d | 2010-12-21 22:37:27 -0700 | [diff] [blame] | 126 | pwrdm_state_switch(pwrdm); |
Santosh Shilimkar | eb6a2c7 | 2010-09-15 01:04:01 +0530 | [diff] [blame] | 127 | err: |
| 128 | return ret; |
| 129 | } |
| 130 | |
Thara Gopinath | 1482d8b | 2010-05-29 22:02:25 +0530 | [diff] [blame] | 131 | /* |
Johan Hovold | 1e2d2df | 2011-08-30 18:48:16 +0200 | [diff] [blame] | 132 | * 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] | 133 | * domains to the voltage as per the opp table. Typically we boot up |
| 134 | * at the nominal voltage. So this function finds out the rate of |
| 135 | * the clock associated with the voltage domain, finds out the correct |
Johan Hovold | 1e2d2df | 2011-08-30 18:48:16 +0200 | [diff] [blame] | 136 | * opp entry and sets the voltage domain to the voltage specified |
Thara Gopinath | 1482d8b | 2010-05-29 22:02:25 +0530 | [diff] [blame] | 137 | * in the opp entry |
| 138 | */ |
| 139 | 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] | 140 | const char *oh_name) |
Thara Gopinath | 1482d8b | 2010-05-29 22:02:25 +0530 | [diff] [blame] | 141 | { |
| 142 | struct voltagedomain *voltdm; |
| 143 | struct clk *clk; |
| 144 | struct opp *opp; |
| 145 | unsigned long freq, bootup_volt; |
Benoit Cousson | 0f7aa00 | 2011-08-16 15:02:20 +0200 | [diff] [blame] | 146 | struct device *dev; |
Thara Gopinath | 1482d8b | 2010-05-29 22:02:25 +0530 | [diff] [blame] | 147 | |
Benoit Cousson | 0f7aa00 | 2011-08-16 15:02:20 +0200 | [diff] [blame] | 148 | if (!vdd_name || !clk_name || !oh_name) { |
Johan Hovold | e9a5190 | 2011-08-30 18:48:17 +0200 | [diff] [blame] | 149 | pr_err("%s: invalid parameters\n", __func__); |
Thara Gopinath | 1482d8b | 2010-05-29 22:02:25 +0530 | [diff] [blame] | 150 | goto exit; |
| 151 | } |
| 152 | |
Benoit Cousson | 0f7aa00 | 2011-08-16 15:02:20 +0200 | [diff] [blame] | 153 | dev = omap_device_get_by_hwmod_name(oh_name); |
| 154 | if (IS_ERR(dev)) { |
| 155 | pr_err("%s: Unable to get dev pointer for hwmod %s\n", |
| 156 | __func__, oh_name); |
| 157 | goto exit; |
| 158 | } |
| 159 | |
Kevin Hilman | 81a6048 | 2011-03-16 14:25:45 -0700 | [diff] [blame] | 160 | voltdm = voltdm_lookup(vdd_name); |
Thara Gopinath | 1482d8b | 2010-05-29 22:02:25 +0530 | [diff] [blame] | 161 | if (IS_ERR(voltdm)) { |
Johan Hovold | e9a5190 | 2011-08-30 18:48:17 +0200 | [diff] [blame] | 162 | pr_err("%s: unable to get vdd pointer for vdd_%s\n", |
Thara Gopinath | 1482d8b | 2010-05-29 22:02:25 +0530 | [diff] [blame] | 163 | __func__, vdd_name); |
| 164 | goto exit; |
| 165 | } |
| 166 | |
| 167 | clk = clk_get(NULL, clk_name); |
| 168 | if (IS_ERR(clk)) { |
Johan Hovold | e9a5190 | 2011-08-30 18:48:17 +0200 | [diff] [blame] | 169 | pr_err("%s: unable to get clk %s\n", __func__, clk_name); |
Thara Gopinath | 1482d8b | 2010-05-29 22:02:25 +0530 | [diff] [blame] | 170 | goto exit; |
| 171 | } |
| 172 | |
| 173 | freq = clk->rate; |
| 174 | clk_put(clk); |
| 175 | |
| 176 | opp = opp_find_freq_ceil(dev, &freq); |
| 177 | if (IS_ERR(opp)) { |
Johan Hovold | e9a5190 | 2011-08-30 18:48:17 +0200 | [diff] [blame] | 178 | 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] | 179 | __func__, vdd_name); |
| 180 | goto exit; |
| 181 | } |
| 182 | |
| 183 | bootup_volt = opp_get_voltage(opp); |
| 184 | if (!bootup_volt) { |
Johan Hovold | e9a5190 | 2011-08-30 18:48:17 +0200 | [diff] [blame] | 185 | pr_err("%s: unable to find voltage corresponding " |
Thara Gopinath | 1482d8b | 2010-05-29 22:02:25 +0530 | [diff] [blame] | 186 | "to the bootup OPP for vdd_%s\n", __func__, vdd_name); |
| 187 | goto exit; |
| 188 | } |
| 189 | |
Kevin Hilman | 5e5651b | 2011-04-05 16:27:21 -0700 | [diff] [blame] | 190 | voltdm_scale(voltdm, bootup_volt); |
Thara Gopinath | 1482d8b | 2010-05-29 22:02:25 +0530 | [diff] [blame] | 191 | return 0; |
| 192 | |
| 193 | exit: |
Johan Hovold | e9a5190 | 2011-08-30 18:48:17 +0200 | [diff] [blame] | 194 | pr_err("%s: unable to set vdd_%s\n", __func__, vdd_name); |
Thara Gopinath | 1482d8b | 2010-05-29 22:02:25 +0530 | [diff] [blame] | 195 | return -EINVAL; |
| 196 | } |
| 197 | |
| 198 | static void __init omap3_init_voltages(void) |
| 199 | { |
| 200 | if (!cpu_is_omap34xx()) |
| 201 | return; |
| 202 | |
Benoit Cousson | 0f7aa00 | 2011-08-16 15:02:20 +0200 | [diff] [blame] | 203 | omap2_set_init_voltage("mpu_iva", "dpll1_ck", "mpu"); |
| 204 | omap2_set_init_voltage("core", "l3_ick", "l3_main"); |
Thara Gopinath | 1482d8b | 2010-05-29 22:02:25 +0530 | [diff] [blame] | 205 | } |
| 206 | |
Thara Gopinath | 1376ee1 | 2010-05-29 22:02:25 +0530 | [diff] [blame] | 207 | static void __init omap4_init_voltages(void) |
| 208 | { |
| 209 | if (!cpu_is_omap44xx()) |
| 210 | return; |
| 211 | |
Benoit Cousson | 0f7aa00 | 2011-08-16 15:02:20 +0200 | [diff] [blame] | 212 | omap2_set_init_voltage("mpu", "dpll_mpu_ck", "mpu"); |
| 213 | omap2_set_init_voltage("core", "l3_div_ck", "l3_main_1"); |
| 214 | omap2_set_init_voltage("iva", "dpll_iva_m5x2_ck", "iva"); |
Thara Gopinath | 1376ee1 | 2010-05-29 22:02:25 +0530 | [diff] [blame] | 215 | } |
| 216 | |
Kevin Hilman | 6f88e9b | 2010-07-26 16:34:31 -0600 | [diff] [blame] | 217 | static int __init omap2_common_pm_init(void) |
| 218 | { |
Benoit Cousson | 476b679 | 2011-08-16 11:49:08 +0200 | [diff] [blame] | 219 | if (!of_have_populated_dt()) |
| 220 | omap2_init_processor_devices(); |
Kevin Hilman | 6f88e9b | 2010-07-26 16:34:31 -0600 | [diff] [blame] | 221 | omap_pm_if_init(); |
| 222 | |
| 223 | return 0; |
| 224 | } |
Thara Gopinath | 1cbbe37 | 2010-12-20 21:17:21 +0530 | [diff] [blame] | 225 | postcore_initcall(omap2_common_pm_init); |
Kevin Hilman | 6f88e9b | 2010-07-26 16:34:31 -0600 | [diff] [blame] | 226 | |
Thara Gopinath | 2f34ce8 | 2010-05-29 22:02:21 +0530 | [diff] [blame] | 227 | static int __init omap2_common_pm_late_init(void) |
| 228 | { |
Thara Gopinath | fbc319f | 2010-12-10 22:51:05 +0530 | [diff] [blame] | 229 | /* Init the OMAP TWL parameters */ |
| 230 | omap3_twl_init(); |
Thara Gopinath | 7bc3ed9 | 2010-12-10 23:15:16 +0530 | [diff] [blame] | 231 | omap4_twl_init(); |
Thara Gopinath | 1482d8b | 2010-05-29 22:02:25 +0530 | [diff] [blame] | 232 | |
Thara Gopinath | fbc319f | 2010-12-10 22:51:05 +0530 | [diff] [blame] | 233 | /* Init the voltage layer */ |
Thara Gopinath | 2f34ce8 | 2010-05-29 22:02:21 +0530 | [diff] [blame] | 234 | omap_voltage_late_init(); |
Thara Gopinath | 1482d8b | 2010-05-29 22:02:25 +0530 | [diff] [blame] | 235 | |
| 236 | /* Initialize the voltages */ |
| 237 | omap3_init_voltages(); |
Thara Gopinath | 1376ee1 | 2010-05-29 22:02:25 +0530 | [diff] [blame] | 238 | omap4_init_voltages(); |
Thara Gopinath | 1482d8b | 2010-05-29 22:02:25 +0530 | [diff] [blame] | 239 | |
Thara Gopinath | fbc319f | 2010-12-10 22:51:05 +0530 | [diff] [blame] | 240 | /* Smartreflex device init */ |
Thara Gopinath | 0c0a5d6 | 2010-05-29 22:02:23 +0530 | [diff] [blame] | 241 | omap_devinit_smartreflex(); |
Thara Gopinath | 2f34ce8 | 2010-05-29 22:02:21 +0530 | [diff] [blame] | 242 | |
| 243 | return 0; |
| 244 | } |
| 245 | late_initcall(omap2_common_pm_late_init); |