Paul Walmsley | ad67ef6 | 2008-08-19 11:08:40 +0300 | [diff] [blame] | 1 | /* |
| 2 | * OMAP powerdomain control |
| 3 | * |
Paul Walmsley | 129c65e | 2011-09-14 16:01:21 -0600 | [diff] [blame] | 4 | * Copyright (C) 2007-2008, 2011 Texas Instruments, Inc. |
Paul Walmsley | 694606c | 2011-03-07 19:28:15 -0700 | [diff] [blame] | 5 | * Copyright (C) 2007-2011 Nokia Corporation |
Paul Walmsley | ad67ef6 | 2008-08-19 11:08:40 +0300 | [diff] [blame] | 6 | * |
| 7 | * Written by Paul Walmsley |
Abhijit Pagare | 3a759f0 | 2010-01-26 20:12:53 -0700 | [diff] [blame] | 8 | * Added OMAP4 specific support by Abhijit Pagare <abhijitpagare@ti.com> |
Paul Walmsley | 4788da2 | 2010-05-18 20:24:05 -0600 | [diff] [blame] | 9 | * State counting code by Tero Kristo <tero.kristo@nokia.com> |
Abhijit Pagare | 3a759f0 | 2010-01-26 20:12:53 -0700 | [diff] [blame] | 10 | * |
Paul Walmsley | ad67ef6 | 2008-08-19 11:08:40 +0300 | [diff] [blame] | 11 | * This program is free software; you can redistribute it and/or modify |
| 12 | * it under the terms of the GNU General Public License version 2 as |
| 13 | * published by the Free Software Foundation. |
| 14 | */ |
Paul Walmsley | 33903eb | 2009-12-08 16:33:10 -0700 | [diff] [blame] | 15 | #undef DEBUG |
Paul Walmsley | ad67ef6 | 2008-08-19 11:08:40 +0300 | [diff] [blame] | 16 | |
| 17 | #include <linux/kernel.h> |
Paul Walmsley | ad67ef6 | 2008-08-19 11:08:40 +0300 | [diff] [blame] | 18 | #include <linux/types.h> |
Paul Walmsley | ad67ef6 | 2008-08-19 11:08:40 +0300 | [diff] [blame] | 19 | #include <linux/list.h> |
| 20 | #include <linux/errno.h> |
Rajendra Nayak | 9b7fc90 | 2010-12-21 20:01:19 -0700 | [diff] [blame] | 21 | #include <linux/string.h> |
Paul Walmsley | 3a09028 | 2013-01-26 00:58:16 -0700 | [diff] [blame] | 22 | #include <linux/spinlock.h> |
Jean Pihet | 5e7c58d | 2011-03-03 11:25:43 +0100 | [diff] [blame] | 23 | #include <trace/events/power.h> |
| 24 | |
Paul Walmsley | 59fb659 | 2010-12-21 15:30:55 -0700 | [diff] [blame] | 25 | #include "cm2xxx_3xxx.h" |
Paul Walmsley | a64bb9c | 2010-12-21 21:05:14 -0700 | [diff] [blame] | 26 | #include "prcm44xx.h" |
Paul Walmsley | 59fb659 | 2010-12-21 15:30:55 -0700 | [diff] [blame] | 27 | #include "cm44xx.h" |
| 28 | #include "prm2xxx_3xxx.h" |
Paul Walmsley | d198b51 | 2010-12-21 15:30:54 -0700 | [diff] [blame] | 29 | #include "prm44xx.h" |
Paul Walmsley | ad67ef6 | 2008-08-19 11:08:40 +0300 | [diff] [blame] | 30 | |
Jean Pihet | 5e7c58d | 2011-03-03 11:25:43 +0100 | [diff] [blame] | 31 | #include <asm/cpu.h> |
Tony Lindgren | dbc0416 | 2012-08-31 10:59:07 -0700 | [diff] [blame] | 32 | |
Tony Lindgren | dbc0416 | 2012-08-31 10:59:07 -0700 | [diff] [blame] | 33 | #include "powerdomain.h" |
| 34 | #include "clockdomain.h" |
Tero Kristo | 4794208 | 2014-05-11 19:41:50 -0600 | [diff] [blame] | 35 | #include "voltage.h" |
Tony Lindgren | dbc0416 | 2012-08-31 10:59:07 -0700 | [diff] [blame] | 36 | |
| 37 | #include "soc.h" |
Peter 'p2' De Schrijver | 6199ab2 | 2008-10-15 18:13:49 +0300 | [diff] [blame] | 38 | #include "pm.h" |
| 39 | |
Jean Pihet | 5e7c58d | 2011-03-03 11:25:43 +0100 | [diff] [blame] | 40 | #define PWRDM_TRACE_STATES_FLAG (1<<31) |
| 41 | |
Peter 'p2' De Schrijver | ba20bb1 | 2008-10-15 17:48:43 +0300 | [diff] [blame] | 42 | enum { |
| 43 | PWRDM_STATE_NOW = 0, |
| 44 | PWRDM_STATE_PREV, |
| 45 | }; |
| 46 | |
Paul Walmsley | c4978fb | 2013-01-29 13:45:09 -0700 | [diff] [blame] | 47 | /* |
| 48 | * Types of sleep_switch used internally in omap_set_pwrdm_state() |
| 49 | * and its associated static functions |
| 50 | * |
| 51 | * XXX Better documentation is needed here |
| 52 | */ |
| 53 | #define ALREADYACTIVE_SWITCH 0 |
| 54 | #define FORCEWAKEUP_SWITCH 1 |
| 55 | #define LOWPOWERSTATE_SWITCH 2 |
Abhijit Pagare | 3a759f0 | 2010-01-26 20:12:53 -0700 | [diff] [blame] | 56 | |
Paul Walmsley | ad67ef6 | 2008-08-19 11:08:40 +0300 | [diff] [blame] | 57 | /* pwrdm_list contains all registered struct powerdomains */ |
| 58 | static LIST_HEAD(pwrdm_list); |
| 59 | |
Rajendra Nayak | 3b1e8b2 | 2010-12-21 20:01:18 -0700 | [diff] [blame] | 60 | static struct pwrdm_ops *arch_pwrdm; |
| 61 | |
Paul Walmsley | ad67ef6 | 2008-08-19 11:08:40 +0300 | [diff] [blame] | 62 | /* Private functions */ |
| 63 | |
Paul Walmsley | ad67ef6 | 2008-08-19 11:08:40 +0300 | [diff] [blame] | 64 | static struct powerdomain *_pwrdm_lookup(const char *name) |
| 65 | { |
| 66 | struct powerdomain *pwrdm, *temp_pwrdm; |
| 67 | |
| 68 | pwrdm = NULL; |
| 69 | |
| 70 | list_for_each_entry(temp_pwrdm, &pwrdm_list, node) { |
| 71 | if (!strcmp(name, temp_pwrdm->name)) { |
| 72 | pwrdm = temp_pwrdm; |
| 73 | break; |
| 74 | } |
| 75 | } |
| 76 | |
| 77 | return pwrdm; |
| 78 | } |
| 79 | |
Paul Walmsley | e909d62a8 | 2010-01-26 20:13:00 -0700 | [diff] [blame] | 80 | /** |
| 81 | * _pwrdm_register - register a powerdomain |
| 82 | * @pwrdm: struct powerdomain * to register |
| 83 | * |
| 84 | * Adds a powerdomain to the internal powerdomain list. Returns |
| 85 | * -EINVAL if given a null pointer, -EEXIST if a powerdomain is |
| 86 | * already registered by the provided name, or 0 upon success. |
| 87 | */ |
| 88 | static int _pwrdm_register(struct powerdomain *pwrdm) |
| 89 | { |
| 90 | int i; |
Kevin Hilman | 048a703 | 2011-03-16 15:52:47 -0700 | [diff] [blame] | 91 | struct voltagedomain *voltdm; |
Paul Walmsley | e909d62a8 | 2010-01-26 20:13:00 -0700 | [diff] [blame] | 92 | |
Paul Walmsley | a64bb9c | 2010-12-21 21:05:14 -0700 | [diff] [blame] | 93 | if (!pwrdm || !pwrdm->name) |
Paul Walmsley | e909d62a8 | 2010-01-26 20:13:00 -0700 | [diff] [blame] | 94 | return -EINVAL; |
| 95 | |
Paul Walmsley | a64bb9c | 2010-12-21 21:05:14 -0700 | [diff] [blame] | 96 | if (cpu_is_omap44xx() && |
| 97 | pwrdm->prcm_partition == OMAP4430_INVALID_PRCM_PARTITION) { |
| 98 | pr_err("powerdomain: %s: missing OMAP4 PRCM partition ID\n", |
| 99 | pwrdm->name); |
| 100 | return -EINVAL; |
| 101 | } |
| 102 | |
Paul Walmsley | e909d62a8 | 2010-01-26 20:13:00 -0700 | [diff] [blame] | 103 | if (_pwrdm_lookup(pwrdm->name)) |
| 104 | return -EEXIST; |
| 105 | |
Rajendra Nayak | cd8abed | 2013-06-17 18:46:22 +0530 | [diff] [blame] | 106 | if (arch_pwrdm && arch_pwrdm->pwrdm_has_voltdm) |
| 107 | if (!arch_pwrdm->pwrdm_has_voltdm()) |
| 108 | goto skip_voltdm; |
| 109 | |
Kevin Hilman | 048a703 | 2011-03-16 15:52:47 -0700 | [diff] [blame] | 110 | voltdm = voltdm_lookup(pwrdm->voltdm.name); |
| 111 | if (!voltdm) { |
| 112 | pr_err("powerdomain: %s: voltagedomain %s does not exist\n", |
| 113 | pwrdm->name, pwrdm->voltdm.name); |
| 114 | return -EINVAL; |
| 115 | } |
| 116 | pwrdm->voltdm.ptr = voltdm; |
Kevin Hilman | e69c22b | 2011-03-16 16:13:15 -0700 | [diff] [blame] | 117 | INIT_LIST_HEAD(&pwrdm->voltdm_node); |
| 118 | voltdm_add_pwrdm(voltdm, pwrdm); |
Rajendra Nayak | cd8abed | 2013-06-17 18:46:22 +0530 | [diff] [blame] | 119 | skip_voltdm: |
Paul Walmsley | 3a09028 | 2013-01-26 00:58:16 -0700 | [diff] [blame] | 120 | spin_lock_init(&pwrdm->_lock); |
Kevin Hilman | 048a703 | 2011-03-16 15:52:47 -0700 | [diff] [blame] | 121 | |
Paul Walmsley | e909d62a8 | 2010-01-26 20:13:00 -0700 | [diff] [blame] | 122 | list_add(&pwrdm->node, &pwrdm_list); |
| 123 | |
| 124 | /* Initialize the powerdomain's state counter */ |
Paul Walmsley | cf57aa7 | 2010-01-26 20:13:01 -0700 | [diff] [blame] | 125 | for (i = 0; i < PWRDM_MAX_PWRSTS; i++) |
Paul Walmsley | e909d62a8 | 2010-01-26 20:13:00 -0700 | [diff] [blame] | 126 | pwrdm->state_counter[i] = 0; |
| 127 | |
Thara Gopinath | cde08f8 | 2010-02-24 12:05:50 -0700 | [diff] [blame] | 128 | pwrdm->ret_logic_off_counter = 0; |
| 129 | for (i = 0; i < pwrdm->banks; i++) |
| 130 | pwrdm->ret_mem_off_counter[i] = 0; |
| 131 | |
Rajendra Nayak | 1cfc4bd | 2013-12-02 11:38:14 -0800 | [diff] [blame] | 132 | if (arch_pwrdm && arch_pwrdm->pwrdm_wait_transition) |
| 133 | arch_pwrdm->pwrdm_wait_transition(pwrdm); |
Paul Walmsley | e909d62a8 | 2010-01-26 20:13:00 -0700 | [diff] [blame] | 134 | pwrdm->state = pwrdm_read_pwrst(pwrdm); |
| 135 | pwrdm->state_counter[pwrdm->state] = 1; |
| 136 | |
| 137 | pr_debug("powerdomain: registered %s\n", pwrdm->name); |
| 138 | |
| 139 | return 0; |
| 140 | } |
| 141 | |
Thara Gopinath | cde08f8 | 2010-02-24 12:05:50 -0700 | [diff] [blame] | 142 | static void _update_logic_membank_counters(struct powerdomain *pwrdm) |
| 143 | { |
| 144 | int i; |
| 145 | u8 prev_logic_pwrst, prev_mem_pwrst; |
| 146 | |
| 147 | prev_logic_pwrst = pwrdm_read_prev_logic_pwrst(pwrdm); |
| 148 | if ((pwrdm->pwrsts_logic_ret == PWRSTS_OFF_RET) && |
| 149 | (prev_logic_pwrst == PWRDM_POWER_OFF)) |
| 150 | pwrdm->ret_logic_off_counter++; |
| 151 | |
| 152 | for (i = 0; i < pwrdm->banks; i++) { |
| 153 | prev_mem_pwrst = pwrdm_read_prev_mem_pwrst(pwrdm, i); |
| 154 | |
| 155 | if ((pwrdm->pwrsts_mem_ret[i] == PWRSTS_OFF_RET) && |
| 156 | (prev_mem_pwrst == PWRDM_POWER_OFF)) |
| 157 | pwrdm->ret_mem_off_counter[i]++; |
| 158 | } |
| 159 | } |
| 160 | |
Peter 'p2' De Schrijver | ba20bb1 | 2008-10-15 17:48:43 +0300 | [diff] [blame] | 161 | static int _pwrdm_state_switch(struct powerdomain *pwrdm, int flag) |
| 162 | { |
| 163 | |
Jean Pihet | c165a14 | 2013-01-26 00:58:13 -0700 | [diff] [blame] | 164 | int prev, next, state, trace_state = 0; |
Peter 'p2' De Schrijver | ba20bb1 | 2008-10-15 17:48:43 +0300 | [diff] [blame] | 165 | |
| 166 | if (pwrdm == NULL) |
| 167 | return -EINVAL; |
| 168 | |
| 169 | state = pwrdm_read_pwrst(pwrdm); |
| 170 | |
| 171 | switch (flag) { |
| 172 | case PWRDM_STATE_NOW: |
| 173 | prev = pwrdm->state; |
| 174 | break; |
| 175 | case PWRDM_STATE_PREV: |
| 176 | prev = pwrdm_read_prev_pwrst(pwrdm); |
| 177 | if (pwrdm->state != prev) |
| 178 | pwrdm->state_counter[prev]++; |
Thara Gopinath | cde08f8 | 2010-02-24 12:05:50 -0700 | [diff] [blame] | 179 | if (prev == PWRDM_POWER_RET) |
| 180 | _update_logic_membank_counters(pwrdm); |
Jean Pihet | 5e7c58d | 2011-03-03 11:25:43 +0100 | [diff] [blame] | 181 | /* |
| 182 | * If the power domain did not hit the desired state, |
| 183 | * generate a trace event with both the desired and hit states |
| 184 | */ |
Jean Pihet | c165a14 | 2013-01-26 00:58:13 -0700 | [diff] [blame] | 185 | next = pwrdm_read_next_pwrst(pwrdm); |
| 186 | if (next != prev) { |
Jean Pihet | 5e7c58d | 2011-03-03 11:25:43 +0100 | [diff] [blame] | 187 | trace_state = (PWRDM_TRACE_STATES_FLAG | |
Jean Pihet | c165a14 | 2013-01-26 00:58:13 -0700 | [diff] [blame] | 188 | ((next & OMAP_POWERSTATE_MASK) << 8) | |
Jean Pihet | 5e7c58d | 2011-03-03 11:25:43 +0100 | [diff] [blame] | 189 | ((prev & OMAP_POWERSTATE_MASK) << 0)); |
| 190 | trace_power_domain_target(pwrdm->name, trace_state, |
| 191 | smp_processor_id()); |
| 192 | } |
Peter 'p2' De Schrijver | ba20bb1 | 2008-10-15 17:48:43 +0300 | [diff] [blame] | 193 | break; |
| 194 | default: |
| 195 | return -EINVAL; |
| 196 | } |
| 197 | |
| 198 | if (state != prev) |
| 199 | pwrdm->state_counter[state]++; |
| 200 | |
Peter 'p2' De Schrijver | 6199ab2 | 2008-10-15 18:13:49 +0300 | [diff] [blame] | 201 | pm_dbg_update_time(pwrdm, prev); |
| 202 | |
Peter 'p2' De Schrijver | ba20bb1 | 2008-10-15 17:48:43 +0300 | [diff] [blame] | 203 | pwrdm->state = state; |
| 204 | |
| 205 | return 0; |
| 206 | } |
| 207 | |
Peter 'p2' De Schrijver | 6199ab2 | 2008-10-15 18:13:49 +0300 | [diff] [blame] | 208 | static int _pwrdm_pre_transition_cb(struct powerdomain *pwrdm, void *unused) |
Peter 'p2' De Schrijver | ba20bb1 | 2008-10-15 17:48:43 +0300 | [diff] [blame] | 209 | { |
| 210 | pwrdm_clear_all_prev_pwrst(pwrdm); |
| 211 | _pwrdm_state_switch(pwrdm, PWRDM_STATE_NOW); |
| 212 | return 0; |
| 213 | } |
| 214 | |
Peter 'p2' De Schrijver | 6199ab2 | 2008-10-15 18:13:49 +0300 | [diff] [blame] | 215 | static int _pwrdm_post_transition_cb(struct powerdomain *pwrdm, void *unused) |
Peter 'p2' De Schrijver | ba20bb1 | 2008-10-15 17:48:43 +0300 | [diff] [blame] | 216 | { |
| 217 | _pwrdm_state_switch(pwrdm, PWRDM_STATE_PREV); |
| 218 | return 0; |
| 219 | } |
| 220 | |
Paul Walmsley | c4978fb | 2013-01-29 13:45:09 -0700 | [diff] [blame] | 221 | /** |
| 222 | * _pwrdm_save_clkdm_state_and_activate - prepare for power state change |
| 223 | * @pwrdm: struct powerdomain * to operate on |
| 224 | * @curr_pwrst: current power state of @pwrdm |
| 225 | * @pwrst: power state to switch to |
| 226 | * @hwsup: ptr to a bool to return whether the clkdm is hardware-supervised |
| 227 | * |
| 228 | * Determine whether the powerdomain needs to be turned on before |
| 229 | * attempting to switch power states. Called by |
| 230 | * omap_set_pwrdm_state(). NOTE that if the powerdomain contains |
| 231 | * multiple clockdomains, this code assumes that the first clockdomain |
| 232 | * supports software-supervised wakeup mode - potentially a problem. |
| 233 | * Returns the power state switch mode currently in use (see the |
| 234 | * "Types of sleep_switch" comment above). |
| 235 | */ |
| 236 | static u8 _pwrdm_save_clkdm_state_and_activate(struct powerdomain *pwrdm, |
| 237 | u8 curr_pwrst, u8 pwrst, |
| 238 | bool *hwsup) |
| 239 | { |
| 240 | u8 sleep_switch; |
| 241 | |
Paul Walmsley | bd70f6e | 2013-03-31 20:22:22 -0600 | [diff] [blame] | 242 | if (curr_pwrst < PWRDM_POWER_ON) { |
Paul Walmsley | c4978fb | 2013-01-29 13:45:09 -0700 | [diff] [blame] | 243 | if (curr_pwrst > pwrst && |
| 244 | pwrdm->flags & PWRDM_HAS_LOWPOWERSTATECHANGE && |
| 245 | arch_pwrdm->pwrdm_set_lowpwrstchange) { |
| 246 | sleep_switch = LOWPOWERSTATE_SWITCH; |
| 247 | } else { |
| 248 | *hwsup = clkdm_in_hwsup(pwrdm->pwrdm_clkdms[0]); |
Paul Walmsley | 3a09028 | 2013-01-26 00:58:16 -0700 | [diff] [blame] | 249 | clkdm_wakeup_nolock(pwrdm->pwrdm_clkdms[0]); |
Paul Walmsley | c4978fb | 2013-01-29 13:45:09 -0700 | [diff] [blame] | 250 | sleep_switch = FORCEWAKEUP_SWITCH; |
| 251 | } |
| 252 | } else { |
| 253 | sleep_switch = ALREADYACTIVE_SWITCH; |
| 254 | } |
| 255 | |
| 256 | return sleep_switch; |
| 257 | } |
| 258 | |
| 259 | /** |
| 260 | * _pwrdm_restore_clkdm_state - restore the clkdm hwsup state after pwrst change |
| 261 | * @pwrdm: struct powerdomain * to operate on |
| 262 | * @sleep_switch: return value from _pwrdm_save_clkdm_state_and_activate() |
| 263 | * @hwsup: should @pwrdm's first clockdomain be set to hardware-supervised mode? |
| 264 | * |
| 265 | * Restore the clockdomain state perturbed by |
| 266 | * _pwrdm_save_clkdm_state_and_activate(), and call the power state |
| 267 | * bookkeeping code. Called by omap_set_pwrdm_state(). NOTE that if |
| 268 | * the powerdomain contains multiple clockdomains, this assumes that |
| 269 | * the first associated clockdomain supports either |
| 270 | * hardware-supervised idle control in the register, or |
| 271 | * software-supervised sleep. No return value. |
| 272 | */ |
| 273 | static void _pwrdm_restore_clkdm_state(struct powerdomain *pwrdm, |
| 274 | u8 sleep_switch, bool hwsup) |
| 275 | { |
| 276 | switch (sleep_switch) { |
| 277 | case FORCEWAKEUP_SWITCH: |
| 278 | if (hwsup) |
Paul Walmsley | 3a09028 | 2013-01-26 00:58:16 -0700 | [diff] [blame] | 279 | clkdm_allow_idle_nolock(pwrdm->pwrdm_clkdms[0]); |
Paul Walmsley | c4978fb | 2013-01-29 13:45:09 -0700 | [diff] [blame] | 280 | else |
Paul Walmsley | 3a09028 | 2013-01-26 00:58:16 -0700 | [diff] [blame] | 281 | clkdm_sleep_nolock(pwrdm->pwrdm_clkdms[0]); |
Paul Walmsley | c4978fb | 2013-01-29 13:45:09 -0700 | [diff] [blame] | 282 | break; |
| 283 | case LOWPOWERSTATE_SWITCH: |
| 284 | if (pwrdm->flags & PWRDM_HAS_LOWPOWERSTATECHANGE && |
| 285 | arch_pwrdm->pwrdm_set_lowpwrstchange) |
| 286 | arch_pwrdm->pwrdm_set_lowpwrstchange(pwrdm); |
Paul Walmsley | 3a09028 | 2013-01-26 00:58:16 -0700 | [diff] [blame] | 287 | pwrdm_state_switch_nolock(pwrdm); |
Paul Walmsley | c4978fb | 2013-01-29 13:45:09 -0700 | [diff] [blame] | 288 | break; |
| 289 | } |
| 290 | } |
| 291 | |
Paul Walmsley | ad67ef6 | 2008-08-19 11:08:40 +0300 | [diff] [blame] | 292 | /* Public functions */ |
| 293 | |
| 294 | /** |
Paul Walmsley | 129c65e | 2011-09-14 16:01:21 -0600 | [diff] [blame] | 295 | * pwrdm_register_platform_funcs - register powerdomain implementation fns |
| 296 | * @po: func pointers for arch specific implementations |
Paul Walmsley | ad67ef6 | 2008-08-19 11:08:40 +0300 | [diff] [blame] | 297 | * |
Paul Walmsley | 129c65e | 2011-09-14 16:01:21 -0600 | [diff] [blame] | 298 | * Register the list of function pointers used to implement the |
| 299 | * powerdomain functions on different OMAP SoCs. Should be called |
| 300 | * before any other pwrdm_register*() function. Returns -EINVAL if |
| 301 | * @po is null, -EEXIST if platform functions have already been |
| 302 | * registered, or 0 upon success. |
Paul Walmsley | ad67ef6 | 2008-08-19 11:08:40 +0300 | [diff] [blame] | 303 | */ |
Paul Walmsley | 129c65e | 2011-09-14 16:01:21 -0600 | [diff] [blame] | 304 | int pwrdm_register_platform_funcs(struct pwrdm_ops *po) |
| 305 | { |
| 306 | if (!po) |
| 307 | return -EINVAL; |
| 308 | |
| 309 | if (arch_pwrdm) |
| 310 | return -EEXIST; |
| 311 | |
| 312 | arch_pwrdm = po; |
| 313 | |
| 314 | return 0; |
| 315 | } |
| 316 | |
| 317 | /** |
| 318 | * pwrdm_register_pwrdms - register SoC powerdomains |
| 319 | * @ps: pointer to an array of struct powerdomain to register |
| 320 | * |
| 321 | * Register the powerdomains available on a particular OMAP SoC. Must |
| 322 | * be called after pwrdm_register_platform_funcs(). May be called |
| 323 | * multiple times. Returns -EACCES if called before |
| 324 | * pwrdm_register_platform_funcs(); -EINVAL if the argument @ps is |
| 325 | * null; or 0 upon success. |
| 326 | */ |
| 327 | int pwrdm_register_pwrdms(struct powerdomain **ps) |
Paul Walmsley | ad67ef6 | 2008-08-19 11:08:40 +0300 | [diff] [blame] | 328 | { |
| 329 | struct powerdomain **p = NULL; |
Paul Walmsley | 129c65e | 2011-09-14 16:01:21 -0600 | [diff] [blame] | 330 | |
| 331 | if (!arch_pwrdm) |
| 332 | return -EEXIST; |
| 333 | |
| 334 | if (!ps) |
| 335 | return -EINVAL; |
| 336 | |
| 337 | for (p = ps; *p; p++) |
| 338 | _pwrdm_register(*p); |
| 339 | |
| 340 | return 0; |
| 341 | } |
| 342 | |
| 343 | /** |
| 344 | * pwrdm_complete_init - set up the powerdomain layer |
| 345 | * |
| 346 | * Do whatever is necessary to initialize registered powerdomains and |
| 347 | * powerdomain code. Currently, this programs the next power state |
| 348 | * for each powerdomain to ON. This prevents powerdomains from |
| 349 | * unexpectedly losing context or entering high wakeup latency modes |
| 350 | * with non-power-management-enabled kernels. Must be called after |
| 351 | * pwrdm_register_pwrdms(). Returns -EACCES if called before |
| 352 | * pwrdm_register_pwrdms(), or 0 upon success. |
| 353 | */ |
| 354 | int pwrdm_complete_init(void) |
| 355 | { |
Rajendra Nayak | c956b75 | 2011-08-19 16:59:39 -0600 | [diff] [blame] | 356 | struct powerdomain *temp_p; |
Paul Walmsley | ad67ef6 | 2008-08-19 11:08:40 +0300 | [diff] [blame] | 357 | |
Paul Walmsley | 129c65e | 2011-09-14 16:01:21 -0600 | [diff] [blame] | 358 | if (list_empty(&pwrdm_list)) |
| 359 | return -EACCES; |
Rajendra Nayak | c956b75 | 2011-08-19 16:59:39 -0600 | [diff] [blame] | 360 | |
| 361 | list_for_each_entry(temp_p, &pwrdm_list, node) |
| 362 | pwrdm_set_next_pwrst(temp_p, PWRDM_POWER_ON); |
Paul Walmsley | 129c65e | 2011-09-14 16:01:21 -0600 | [diff] [blame] | 363 | |
| 364 | return 0; |
Paul Walmsley | ad67ef6 | 2008-08-19 11:08:40 +0300 | [diff] [blame] | 365 | } |
| 366 | |
| 367 | /** |
Paul Walmsley | 3a09028 | 2013-01-26 00:58:16 -0700 | [diff] [blame] | 368 | * pwrdm_lock - acquire a Linux spinlock on a powerdomain |
| 369 | * @pwrdm: struct powerdomain * to lock |
| 370 | * |
| 371 | * Acquire the powerdomain spinlock on @pwrdm. No return value. |
| 372 | */ |
| 373 | void pwrdm_lock(struct powerdomain *pwrdm) |
| 374 | __acquires(&pwrdm->_lock) |
| 375 | { |
| 376 | spin_lock_irqsave(&pwrdm->_lock, pwrdm->_lock_flags); |
| 377 | } |
| 378 | |
| 379 | /** |
| 380 | * pwrdm_unlock - release a Linux spinlock on a powerdomain |
| 381 | * @pwrdm: struct powerdomain * to unlock |
| 382 | * |
| 383 | * Release the powerdomain spinlock on @pwrdm. No return value. |
| 384 | */ |
| 385 | void pwrdm_unlock(struct powerdomain *pwrdm) |
| 386 | __releases(&pwrdm->_lock) |
| 387 | { |
| 388 | spin_unlock_irqrestore(&pwrdm->_lock, pwrdm->_lock_flags); |
| 389 | } |
| 390 | |
| 391 | /** |
Paul Walmsley | ad67ef6 | 2008-08-19 11:08:40 +0300 | [diff] [blame] | 392 | * pwrdm_lookup - look up a powerdomain by name, return a pointer |
| 393 | * @name: name of powerdomain |
| 394 | * |
Paul Walmsley | f0271d6 | 2010-01-26 20:13:02 -0700 | [diff] [blame] | 395 | * Find a registered powerdomain by its name @name. Returns a pointer |
| 396 | * to the struct powerdomain if found, or NULL otherwise. |
Paul Walmsley | ad67ef6 | 2008-08-19 11:08:40 +0300 | [diff] [blame] | 397 | */ |
| 398 | struct powerdomain *pwrdm_lookup(const char *name) |
| 399 | { |
| 400 | struct powerdomain *pwrdm; |
Paul Walmsley | ad67ef6 | 2008-08-19 11:08:40 +0300 | [diff] [blame] | 401 | |
| 402 | if (!name) |
| 403 | return NULL; |
| 404 | |
Paul Walmsley | ad67ef6 | 2008-08-19 11:08:40 +0300 | [diff] [blame] | 405 | pwrdm = _pwrdm_lookup(name); |
Paul Walmsley | ad67ef6 | 2008-08-19 11:08:40 +0300 | [diff] [blame] | 406 | |
| 407 | return pwrdm; |
| 408 | } |
| 409 | |
| 410 | /** |
Paul Walmsley | e909d62a8 | 2010-01-26 20:13:00 -0700 | [diff] [blame] | 411 | * pwrdm_for_each - call function on each registered clockdomain |
Paul Walmsley | ad67ef6 | 2008-08-19 11:08:40 +0300 | [diff] [blame] | 412 | * @fn: callback function * |
| 413 | * |
Paul Walmsley | f0271d6 | 2010-01-26 20:13:02 -0700 | [diff] [blame] | 414 | * Call the supplied function @fn for each registered powerdomain. |
| 415 | * The callback function @fn can return anything but 0 to bail out |
| 416 | * early from the iterator. Returns the last return value of the |
| 417 | * callback function, which should be 0 for success or anything else |
| 418 | * to indicate failure; or -EINVAL if the function pointer is null. |
Paul Walmsley | ad67ef6 | 2008-08-19 11:08:40 +0300 | [diff] [blame] | 419 | */ |
Paul Walmsley | e909d62a8 | 2010-01-26 20:13:00 -0700 | [diff] [blame] | 420 | int pwrdm_for_each(int (*fn)(struct powerdomain *pwrdm, void *user), |
| 421 | void *user) |
Paul Walmsley | ad67ef6 | 2008-08-19 11:08:40 +0300 | [diff] [blame] | 422 | { |
| 423 | struct powerdomain *temp_pwrdm; |
Paul Walmsley | ad67ef6 | 2008-08-19 11:08:40 +0300 | [diff] [blame] | 424 | int ret = 0; |
| 425 | |
| 426 | if (!fn) |
| 427 | return -EINVAL; |
| 428 | |
Paul Walmsley | ad67ef6 | 2008-08-19 11:08:40 +0300 | [diff] [blame] | 429 | list_for_each_entry(temp_pwrdm, &pwrdm_list, node) { |
Peter 'p2' De Schrijver | 6199ab2 | 2008-10-15 18:13:49 +0300 | [diff] [blame] | 430 | ret = (*fn)(temp_pwrdm, user); |
Paul Walmsley | ad67ef6 | 2008-08-19 11:08:40 +0300 | [diff] [blame] | 431 | if (ret) |
| 432 | break; |
| 433 | } |
Artem Bityutskiy | ee894b1 | 2009-10-01 10:01:55 +0300 | [diff] [blame] | 434 | |
| 435 | return ret; |
| 436 | } |
| 437 | |
| 438 | /** |
Paul Walmsley | 8420bb1 | 2008-08-19 11:08:44 +0300 | [diff] [blame] | 439 | * pwrdm_add_clkdm - add a clockdomain to a powerdomain |
| 440 | * @pwrdm: struct powerdomain * to add the clockdomain to |
| 441 | * @clkdm: struct clockdomain * to associate with a powerdomain |
| 442 | * |
Paul Walmsley | f0271d6 | 2010-01-26 20:13:02 -0700 | [diff] [blame] | 443 | * Associate the clockdomain @clkdm with a powerdomain @pwrdm. This |
Paul Walmsley | 8420bb1 | 2008-08-19 11:08:44 +0300 | [diff] [blame] | 444 | * enables the use of pwrdm_for_each_clkdm(). Returns -EINVAL if |
| 445 | * presented with invalid pointers; -ENOMEM if memory could not be allocated; |
| 446 | * or 0 upon success. |
| 447 | */ |
| 448 | int pwrdm_add_clkdm(struct powerdomain *pwrdm, struct clockdomain *clkdm) |
| 449 | { |
Paul Walmsley | 8420bb1 | 2008-08-19 11:08:44 +0300 | [diff] [blame] | 450 | int i; |
| 451 | int ret = -EINVAL; |
| 452 | |
| 453 | if (!pwrdm || !clkdm) |
| 454 | return -EINVAL; |
| 455 | |
Paul Walmsley | 7852ec0 | 2012-07-26 00:54:26 -0600 | [diff] [blame] | 456 | pr_debug("powerdomain: %s: associating clockdomain %s\n", |
| 457 | pwrdm->name, clkdm->name); |
Paul Walmsley | 8420bb1 | 2008-08-19 11:08:44 +0300 | [diff] [blame] | 458 | |
Paul Walmsley | 8420bb1 | 2008-08-19 11:08:44 +0300 | [diff] [blame] | 459 | for (i = 0; i < PWRDM_MAX_CLKDMS; i++) { |
| 460 | if (!pwrdm->pwrdm_clkdms[i]) |
| 461 | break; |
| 462 | #ifdef DEBUG |
| 463 | if (pwrdm->pwrdm_clkdms[i] == clkdm) { |
| 464 | ret = -EINVAL; |
| 465 | goto pac_exit; |
| 466 | } |
| 467 | #endif |
| 468 | } |
| 469 | |
| 470 | if (i == PWRDM_MAX_CLKDMS) { |
Paul Walmsley | 7852ec0 | 2012-07-26 00:54:26 -0600 | [diff] [blame] | 471 | pr_debug("powerdomain: %s: increase PWRDM_MAX_CLKDMS for clkdm %s\n", |
| 472 | pwrdm->name, clkdm->name); |
Paul Walmsley | 8420bb1 | 2008-08-19 11:08:44 +0300 | [diff] [blame] | 473 | WARN_ON(1); |
| 474 | ret = -ENOMEM; |
| 475 | goto pac_exit; |
| 476 | } |
| 477 | |
| 478 | pwrdm->pwrdm_clkdms[i] = clkdm; |
| 479 | |
| 480 | ret = 0; |
| 481 | |
| 482 | pac_exit: |
Paul Walmsley | 8420bb1 | 2008-08-19 11:08:44 +0300 | [diff] [blame] | 483 | return ret; |
| 484 | } |
| 485 | |
| 486 | /** |
| 487 | * pwrdm_del_clkdm - remove a clockdomain from a powerdomain |
| 488 | * @pwrdm: struct powerdomain * to add the clockdomain to |
| 489 | * @clkdm: struct clockdomain * to associate with a powerdomain |
| 490 | * |
Paul Walmsley | f0271d6 | 2010-01-26 20:13:02 -0700 | [diff] [blame] | 491 | * Dissociate the clockdomain @clkdm from the powerdomain |
| 492 | * @pwrdm. Returns -EINVAL if presented with invalid pointers; -ENOENT |
| 493 | * if @clkdm was not associated with the powerdomain, or 0 upon |
| 494 | * success. |
Paul Walmsley | 8420bb1 | 2008-08-19 11:08:44 +0300 | [diff] [blame] | 495 | */ |
| 496 | int pwrdm_del_clkdm(struct powerdomain *pwrdm, struct clockdomain *clkdm) |
| 497 | { |
Paul Walmsley | 8420bb1 | 2008-08-19 11:08:44 +0300 | [diff] [blame] | 498 | int ret = -EINVAL; |
| 499 | int i; |
| 500 | |
| 501 | if (!pwrdm || !clkdm) |
| 502 | return -EINVAL; |
| 503 | |
Paul Walmsley | 7852ec0 | 2012-07-26 00:54:26 -0600 | [diff] [blame] | 504 | pr_debug("powerdomain: %s: dissociating clockdomain %s\n", |
| 505 | pwrdm->name, clkdm->name); |
Paul Walmsley | 8420bb1 | 2008-08-19 11:08:44 +0300 | [diff] [blame] | 506 | |
Paul Walmsley | 8420bb1 | 2008-08-19 11:08:44 +0300 | [diff] [blame] | 507 | for (i = 0; i < PWRDM_MAX_CLKDMS; i++) |
| 508 | if (pwrdm->pwrdm_clkdms[i] == clkdm) |
| 509 | break; |
| 510 | |
| 511 | if (i == PWRDM_MAX_CLKDMS) { |
Paul Walmsley | 7852ec0 | 2012-07-26 00:54:26 -0600 | [diff] [blame] | 512 | pr_debug("powerdomain: %s: clkdm %s not associated?!\n", |
| 513 | pwrdm->name, clkdm->name); |
Paul Walmsley | 8420bb1 | 2008-08-19 11:08:44 +0300 | [diff] [blame] | 514 | ret = -ENOENT; |
| 515 | goto pdc_exit; |
| 516 | } |
| 517 | |
| 518 | pwrdm->pwrdm_clkdms[i] = NULL; |
| 519 | |
| 520 | ret = 0; |
| 521 | |
| 522 | pdc_exit: |
Paul Walmsley | 8420bb1 | 2008-08-19 11:08:44 +0300 | [diff] [blame] | 523 | return ret; |
| 524 | } |
| 525 | |
| 526 | /** |
| 527 | * pwrdm_for_each_clkdm - call function on each clkdm in a pwrdm |
| 528 | * @pwrdm: struct powerdomain * to iterate over |
| 529 | * @fn: callback function * |
| 530 | * |
Paul Walmsley | f0271d6 | 2010-01-26 20:13:02 -0700 | [diff] [blame] | 531 | * Call the supplied function @fn for each clockdomain in the powerdomain |
| 532 | * @pwrdm. The callback function can return anything but 0 to bail |
Paul Walmsley | e909d62a8 | 2010-01-26 20:13:00 -0700 | [diff] [blame] | 533 | * out early from the iterator. Returns -EINVAL if presented with |
| 534 | * invalid pointers; or passes along the last return value of the |
| 535 | * callback function, which should be 0 for success or anything else |
| 536 | * to indicate failure. |
Paul Walmsley | 8420bb1 | 2008-08-19 11:08:44 +0300 | [diff] [blame] | 537 | */ |
| 538 | int pwrdm_for_each_clkdm(struct powerdomain *pwrdm, |
| 539 | int (*fn)(struct powerdomain *pwrdm, |
| 540 | struct clockdomain *clkdm)) |
| 541 | { |
Paul Walmsley | 8420bb1 | 2008-08-19 11:08:44 +0300 | [diff] [blame] | 542 | int ret = 0; |
| 543 | int i; |
| 544 | |
| 545 | if (!fn) |
| 546 | return -EINVAL; |
| 547 | |
Paul Walmsley | 8420bb1 | 2008-08-19 11:08:44 +0300 | [diff] [blame] | 548 | for (i = 0; i < PWRDM_MAX_CLKDMS && !ret; i++) |
Nishanth Menon | 13bbffd | 2014-06-06 19:36:41 -0500 | [diff] [blame] | 549 | if (pwrdm->pwrdm_clkdms[i]) |
| 550 | ret = (*fn)(pwrdm, pwrdm->pwrdm_clkdms[i]); |
Paul Walmsley | 8420bb1 | 2008-08-19 11:08:44 +0300 | [diff] [blame] | 551 | |
Paul Walmsley | 8420bb1 | 2008-08-19 11:08:44 +0300 | [diff] [blame] | 552 | return ret; |
| 553 | } |
| 554 | |
Paul Walmsley | ad67ef6 | 2008-08-19 11:08:40 +0300 | [diff] [blame] | 555 | /** |
Kevin Hilman | 048a703 | 2011-03-16 15:52:47 -0700 | [diff] [blame] | 556 | * pwrdm_get_voltdm - return a ptr to the voltdm that this pwrdm resides in |
| 557 | * @pwrdm: struct powerdomain * |
| 558 | * |
| 559 | * Return a pointer to the struct voltageomain that the specified powerdomain |
| 560 | * @pwrdm exists in. |
| 561 | */ |
| 562 | struct voltagedomain *pwrdm_get_voltdm(struct powerdomain *pwrdm) |
| 563 | { |
| 564 | return pwrdm->voltdm.ptr; |
| 565 | } |
| 566 | |
| 567 | /** |
Paul Walmsley | ad67ef6 | 2008-08-19 11:08:40 +0300 | [diff] [blame] | 568 | * pwrdm_get_mem_bank_count - get number of memory banks in this powerdomain |
| 569 | * @pwrdm: struct powerdomain * |
| 570 | * |
Paul Walmsley | f0271d6 | 2010-01-26 20:13:02 -0700 | [diff] [blame] | 571 | * Return the number of controllable memory banks in powerdomain @pwrdm, |
Paul Walmsley | ad67ef6 | 2008-08-19 11:08:40 +0300 | [diff] [blame] | 572 | * starting with 1. Returns -EINVAL if the powerdomain pointer is null. |
| 573 | */ |
| 574 | int pwrdm_get_mem_bank_count(struct powerdomain *pwrdm) |
| 575 | { |
| 576 | if (!pwrdm) |
| 577 | return -EINVAL; |
| 578 | |
| 579 | return pwrdm->banks; |
| 580 | } |
| 581 | |
| 582 | /** |
| 583 | * pwrdm_set_next_pwrst - set next powerdomain power state |
| 584 | * @pwrdm: struct powerdomain * to set |
| 585 | * @pwrst: one of the PWRDM_POWER_* macros |
| 586 | * |
Paul Walmsley | f0271d6 | 2010-01-26 20:13:02 -0700 | [diff] [blame] | 587 | * Set the powerdomain @pwrdm's next power state to @pwrst. The powerdomain |
Paul Walmsley | ad67ef6 | 2008-08-19 11:08:40 +0300 | [diff] [blame] | 588 | * may not enter this state immediately if the preconditions for this state |
| 589 | * have not been satisfied. Returns -EINVAL if the powerdomain pointer is |
| 590 | * null or if the power state is invalid for the powerdomin, or returns 0 |
| 591 | * upon success. |
| 592 | */ |
| 593 | int pwrdm_set_next_pwrst(struct powerdomain *pwrdm, u8 pwrst) |
| 594 | { |
Rajendra Nayak | f327e07 | 2010-12-21 20:01:18 -0700 | [diff] [blame] | 595 | int ret = -EINVAL; |
| 596 | |
Paul Walmsley | ad67ef6 | 2008-08-19 11:08:40 +0300 | [diff] [blame] | 597 | if (!pwrdm) |
| 598 | return -EINVAL; |
| 599 | |
| 600 | if (!(pwrdm->pwrsts & (1 << pwrst))) |
| 601 | return -EINVAL; |
| 602 | |
Paul Walmsley | 7852ec0 | 2012-07-26 00:54:26 -0600 | [diff] [blame] | 603 | pr_debug("powerdomain: %s: setting next powerstate to %0x\n", |
Paul Walmsley | ad67ef6 | 2008-08-19 11:08:40 +0300 | [diff] [blame] | 604 | pwrdm->name, pwrst); |
| 605 | |
Jean Pihet | 5e7c58d | 2011-03-03 11:25:43 +0100 | [diff] [blame] | 606 | if (arch_pwrdm && arch_pwrdm->pwrdm_set_next_pwrst) { |
| 607 | /* Trace the pwrdm desired target state */ |
| 608 | trace_power_domain_target(pwrdm->name, pwrst, |
| 609 | smp_processor_id()); |
| 610 | /* Program the pwrdm desired target state */ |
Rajendra Nayak | f327e07 | 2010-12-21 20:01:18 -0700 | [diff] [blame] | 611 | ret = arch_pwrdm->pwrdm_set_next_pwrst(pwrdm, pwrst); |
Jean Pihet | 5e7c58d | 2011-03-03 11:25:43 +0100 | [diff] [blame] | 612 | } |
Paul Walmsley | ad67ef6 | 2008-08-19 11:08:40 +0300 | [diff] [blame] | 613 | |
Rajendra Nayak | f327e07 | 2010-12-21 20:01:18 -0700 | [diff] [blame] | 614 | return ret; |
Paul Walmsley | ad67ef6 | 2008-08-19 11:08:40 +0300 | [diff] [blame] | 615 | } |
| 616 | |
| 617 | /** |
| 618 | * pwrdm_read_next_pwrst - get next powerdomain power state |
| 619 | * @pwrdm: struct powerdomain * to get power state |
| 620 | * |
Paul Walmsley | f0271d6 | 2010-01-26 20:13:02 -0700 | [diff] [blame] | 621 | * Return the powerdomain @pwrdm's next power state. Returns -EINVAL |
Paul Walmsley | ad67ef6 | 2008-08-19 11:08:40 +0300 | [diff] [blame] | 622 | * if the powerdomain pointer is null or returns the next power state |
| 623 | * upon success. |
| 624 | */ |
| 625 | int pwrdm_read_next_pwrst(struct powerdomain *pwrdm) |
| 626 | { |
Rajendra Nayak | f327e07 | 2010-12-21 20:01:18 -0700 | [diff] [blame] | 627 | int ret = -EINVAL; |
| 628 | |
Paul Walmsley | ad67ef6 | 2008-08-19 11:08:40 +0300 | [diff] [blame] | 629 | if (!pwrdm) |
| 630 | return -EINVAL; |
| 631 | |
Rajendra Nayak | f327e07 | 2010-12-21 20:01:18 -0700 | [diff] [blame] | 632 | if (arch_pwrdm && arch_pwrdm->pwrdm_read_next_pwrst) |
| 633 | ret = arch_pwrdm->pwrdm_read_next_pwrst(pwrdm); |
| 634 | |
| 635 | return ret; |
Paul Walmsley | ad67ef6 | 2008-08-19 11:08:40 +0300 | [diff] [blame] | 636 | } |
| 637 | |
| 638 | /** |
| 639 | * pwrdm_read_pwrst - get current powerdomain power state |
| 640 | * @pwrdm: struct powerdomain * to get power state |
| 641 | * |
Paul Walmsley | f0271d6 | 2010-01-26 20:13:02 -0700 | [diff] [blame] | 642 | * Return the powerdomain @pwrdm's current power state. Returns -EINVAL |
Paul Walmsley | ad67ef6 | 2008-08-19 11:08:40 +0300 | [diff] [blame] | 643 | * if the powerdomain pointer is null or returns the current power state |
Jon Hunter | d49cae9 | 2012-06-29 16:04:52 -0500 | [diff] [blame] | 644 | * upon success. Note that if the power domain only supports the ON state |
| 645 | * then just return ON as the current state. |
Paul Walmsley | ad67ef6 | 2008-08-19 11:08:40 +0300 | [diff] [blame] | 646 | */ |
| 647 | int pwrdm_read_pwrst(struct powerdomain *pwrdm) |
| 648 | { |
Rajendra Nayak | f327e07 | 2010-12-21 20:01:18 -0700 | [diff] [blame] | 649 | int ret = -EINVAL; |
| 650 | |
Paul Walmsley | ad67ef6 | 2008-08-19 11:08:40 +0300 | [diff] [blame] | 651 | if (!pwrdm) |
| 652 | return -EINVAL; |
| 653 | |
Jon Hunter | d49cae9 | 2012-06-29 16:04:52 -0500 | [diff] [blame] | 654 | if (pwrdm->pwrsts == PWRSTS_ON) |
| 655 | return PWRDM_POWER_ON; |
| 656 | |
Rajendra Nayak | f327e07 | 2010-12-21 20:01:18 -0700 | [diff] [blame] | 657 | if (arch_pwrdm && arch_pwrdm->pwrdm_read_pwrst) |
| 658 | ret = arch_pwrdm->pwrdm_read_pwrst(pwrdm); |
| 659 | |
| 660 | return ret; |
Paul Walmsley | ad67ef6 | 2008-08-19 11:08:40 +0300 | [diff] [blame] | 661 | } |
| 662 | |
| 663 | /** |
| 664 | * pwrdm_read_prev_pwrst - get previous powerdomain power state |
| 665 | * @pwrdm: struct powerdomain * to get previous power state |
| 666 | * |
Paul Walmsley | f0271d6 | 2010-01-26 20:13:02 -0700 | [diff] [blame] | 667 | * Return the powerdomain @pwrdm's previous power state. Returns -EINVAL |
Paul Walmsley | ad67ef6 | 2008-08-19 11:08:40 +0300 | [diff] [blame] | 668 | * if the powerdomain pointer is null or returns the previous power state |
| 669 | * upon success. |
| 670 | */ |
| 671 | int pwrdm_read_prev_pwrst(struct powerdomain *pwrdm) |
| 672 | { |
Rajendra Nayak | f327e07 | 2010-12-21 20:01:18 -0700 | [diff] [blame] | 673 | int ret = -EINVAL; |
| 674 | |
Paul Walmsley | ad67ef6 | 2008-08-19 11:08:40 +0300 | [diff] [blame] | 675 | if (!pwrdm) |
| 676 | return -EINVAL; |
| 677 | |
Rajendra Nayak | f327e07 | 2010-12-21 20:01:18 -0700 | [diff] [blame] | 678 | if (arch_pwrdm && arch_pwrdm->pwrdm_read_prev_pwrst) |
| 679 | ret = arch_pwrdm->pwrdm_read_prev_pwrst(pwrdm); |
| 680 | |
| 681 | return ret; |
Paul Walmsley | ad67ef6 | 2008-08-19 11:08:40 +0300 | [diff] [blame] | 682 | } |
| 683 | |
| 684 | /** |
| 685 | * pwrdm_set_logic_retst - set powerdomain logic power state upon retention |
| 686 | * @pwrdm: struct powerdomain * to set |
| 687 | * @pwrst: one of the PWRDM_POWER_* macros |
| 688 | * |
Paul Walmsley | f0271d6 | 2010-01-26 20:13:02 -0700 | [diff] [blame] | 689 | * Set the next power state @pwrst that the logic portion of the |
| 690 | * powerdomain @pwrdm will enter when the powerdomain enters retention. |
| 691 | * This will be either RETENTION or OFF, if supported. Returns |
| 692 | * -EINVAL if the powerdomain pointer is null or the target power |
| 693 | * state is not not supported, or returns 0 upon success. |
Paul Walmsley | ad67ef6 | 2008-08-19 11:08:40 +0300 | [diff] [blame] | 694 | */ |
| 695 | int pwrdm_set_logic_retst(struct powerdomain *pwrdm, u8 pwrst) |
| 696 | { |
Rajendra Nayak | 1262757 | 2010-12-21 20:01:18 -0700 | [diff] [blame] | 697 | int ret = -EINVAL; |
Paul Walmsley | 2bc4ef7 | 2010-05-18 18:47:24 -0600 | [diff] [blame] | 698 | |
Paul Walmsley | ad67ef6 | 2008-08-19 11:08:40 +0300 | [diff] [blame] | 699 | if (!pwrdm) |
| 700 | return -EINVAL; |
| 701 | |
| 702 | if (!(pwrdm->pwrsts_logic_ret & (1 << pwrst))) |
| 703 | return -EINVAL; |
| 704 | |
Paul Walmsley | 7852ec0 | 2012-07-26 00:54:26 -0600 | [diff] [blame] | 705 | pr_debug("powerdomain: %s: setting next logic powerstate to %0x\n", |
Paul Walmsley | ad67ef6 | 2008-08-19 11:08:40 +0300 | [diff] [blame] | 706 | pwrdm->name, pwrst); |
| 707 | |
Rajendra Nayak | 1262757 | 2010-12-21 20:01:18 -0700 | [diff] [blame] | 708 | if (arch_pwrdm && arch_pwrdm->pwrdm_set_logic_retst) |
| 709 | ret = arch_pwrdm->pwrdm_set_logic_retst(pwrdm, pwrst); |
Paul Walmsley | ad67ef6 | 2008-08-19 11:08:40 +0300 | [diff] [blame] | 710 | |
Rajendra Nayak | 1262757 | 2010-12-21 20:01:18 -0700 | [diff] [blame] | 711 | return ret; |
Paul Walmsley | ad67ef6 | 2008-08-19 11:08:40 +0300 | [diff] [blame] | 712 | } |
| 713 | |
| 714 | /** |
| 715 | * pwrdm_set_mem_onst - set memory power state while powerdomain ON |
| 716 | * @pwrdm: struct powerdomain * to set |
| 717 | * @bank: memory bank number to set (0-3) |
| 718 | * @pwrst: one of the PWRDM_POWER_* macros |
| 719 | * |
Paul Walmsley | f0271d6 | 2010-01-26 20:13:02 -0700 | [diff] [blame] | 720 | * Set the next power state @pwrst that memory bank @bank of the |
| 721 | * powerdomain @pwrdm will enter when the powerdomain enters the ON |
| 722 | * state. @bank will be a number from 0 to 3, and represents different |
| 723 | * types of memory, depending on the powerdomain. Returns -EINVAL if |
| 724 | * the powerdomain pointer is null or the target power state is not |
| 725 | * not supported for this memory bank, -EEXIST if the target memory |
| 726 | * bank does not exist or is not controllable, or returns 0 upon |
| 727 | * success. |
Paul Walmsley | ad67ef6 | 2008-08-19 11:08:40 +0300 | [diff] [blame] | 728 | */ |
| 729 | int pwrdm_set_mem_onst(struct powerdomain *pwrdm, u8 bank, u8 pwrst) |
| 730 | { |
Rajendra Nayak | 9b7fc90 | 2010-12-21 20:01:19 -0700 | [diff] [blame] | 731 | int ret = -EINVAL; |
Paul Walmsley | ad67ef6 | 2008-08-19 11:08:40 +0300 | [diff] [blame] | 732 | |
| 733 | if (!pwrdm) |
| 734 | return -EINVAL; |
| 735 | |
| 736 | if (pwrdm->banks < (bank + 1)) |
| 737 | return -EEXIST; |
| 738 | |
| 739 | if (!(pwrdm->pwrsts_mem_on[bank] & (1 << pwrst))) |
| 740 | return -EINVAL; |
| 741 | |
Paul Walmsley | 7852ec0 | 2012-07-26 00:54:26 -0600 | [diff] [blame] | 742 | pr_debug("powerdomain: %s: setting next memory powerstate for bank %0x while pwrdm-ON to %0x\n", |
| 743 | pwrdm->name, bank, pwrst); |
Paul Walmsley | ad67ef6 | 2008-08-19 11:08:40 +0300 | [diff] [blame] | 744 | |
Rajendra Nayak | 9b7fc90 | 2010-12-21 20:01:19 -0700 | [diff] [blame] | 745 | if (arch_pwrdm && arch_pwrdm->pwrdm_set_mem_onst) |
| 746 | ret = arch_pwrdm->pwrdm_set_mem_onst(pwrdm, bank, pwrst); |
Paul Walmsley | ad67ef6 | 2008-08-19 11:08:40 +0300 | [diff] [blame] | 747 | |
Rajendra Nayak | 9b7fc90 | 2010-12-21 20:01:19 -0700 | [diff] [blame] | 748 | return ret; |
Paul Walmsley | ad67ef6 | 2008-08-19 11:08:40 +0300 | [diff] [blame] | 749 | } |
| 750 | |
| 751 | /** |
| 752 | * pwrdm_set_mem_retst - set memory power state while powerdomain in RET |
| 753 | * @pwrdm: struct powerdomain * to set |
| 754 | * @bank: memory bank number to set (0-3) |
| 755 | * @pwrst: one of the PWRDM_POWER_* macros |
| 756 | * |
Paul Walmsley | f0271d6 | 2010-01-26 20:13:02 -0700 | [diff] [blame] | 757 | * Set the next power state @pwrst that memory bank @bank of the |
| 758 | * powerdomain @pwrdm will enter when the powerdomain enters the |
| 759 | * RETENTION state. Bank will be a number from 0 to 3, and represents |
| 760 | * different types of memory, depending on the powerdomain. @pwrst |
| 761 | * will be either RETENTION or OFF, if supported. Returns -EINVAL if |
| 762 | * the powerdomain pointer is null or the target power state is not |
| 763 | * not supported for this memory bank, -EEXIST if the target memory |
| 764 | * bank does not exist or is not controllable, or returns 0 upon |
| 765 | * success. |
Paul Walmsley | ad67ef6 | 2008-08-19 11:08:40 +0300 | [diff] [blame] | 766 | */ |
| 767 | int pwrdm_set_mem_retst(struct powerdomain *pwrdm, u8 bank, u8 pwrst) |
| 768 | { |
Rajendra Nayak | 9b7fc90 | 2010-12-21 20:01:19 -0700 | [diff] [blame] | 769 | int ret = -EINVAL; |
Paul Walmsley | ad67ef6 | 2008-08-19 11:08:40 +0300 | [diff] [blame] | 770 | |
| 771 | if (!pwrdm) |
| 772 | return -EINVAL; |
| 773 | |
| 774 | if (pwrdm->banks < (bank + 1)) |
| 775 | return -EEXIST; |
| 776 | |
| 777 | if (!(pwrdm->pwrsts_mem_ret[bank] & (1 << pwrst))) |
| 778 | return -EINVAL; |
| 779 | |
Paul Walmsley | 7852ec0 | 2012-07-26 00:54:26 -0600 | [diff] [blame] | 780 | pr_debug("powerdomain: %s: setting next memory powerstate for bank %0x while pwrdm-RET to %0x\n", |
| 781 | pwrdm->name, bank, pwrst); |
Paul Walmsley | ad67ef6 | 2008-08-19 11:08:40 +0300 | [diff] [blame] | 782 | |
Rajendra Nayak | 9b7fc90 | 2010-12-21 20:01:19 -0700 | [diff] [blame] | 783 | if (arch_pwrdm && arch_pwrdm->pwrdm_set_mem_retst) |
| 784 | ret = arch_pwrdm->pwrdm_set_mem_retst(pwrdm, bank, pwrst); |
Paul Walmsley | ad67ef6 | 2008-08-19 11:08:40 +0300 | [diff] [blame] | 785 | |
Rajendra Nayak | 9b7fc90 | 2010-12-21 20:01:19 -0700 | [diff] [blame] | 786 | return ret; |
Paul Walmsley | ad67ef6 | 2008-08-19 11:08:40 +0300 | [diff] [blame] | 787 | } |
| 788 | |
| 789 | /** |
| 790 | * pwrdm_read_logic_pwrst - get current powerdomain logic retention power state |
| 791 | * @pwrdm: struct powerdomain * to get current logic retention power state |
| 792 | * |
Paul Walmsley | f0271d6 | 2010-01-26 20:13:02 -0700 | [diff] [blame] | 793 | * Return the power state that the logic portion of powerdomain @pwrdm |
| 794 | * will enter when the powerdomain enters retention. Returns -EINVAL |
| 795 | * if the powerdomain pointer is null or returns the logic retention |
| 796 | * power state upon success. |
Paul Walmsley | ad67ef6 | 2008-08-19 11:08:40 +0300 | [diff] [blame] | 797 | */ |
| 798 | int pwrdm_read_logic_pwrst(struct powerdomain *pwrdm) |
| 799 | { |
Rajendra Nayak | 1262757 | 2010-12-21 20:01:18 -0700 | [diff] [blame] | 800 | int ret = -EINVAL; |
| 801 | |
Paul Walmsley | ad67ef6 | 2008-08-19 11:08:40 +0300 | [diff] [blame] | 802 | if (!pwrdm) |
| 803 | return -EINVAL; |
| 804 | |
Rajendra Nayak | 1262757 | 2010-12-21 20:01:18 -0700 | [diff] [blame] | 805 | if (arch_pwrdm && arch_pwrdm->pwrdm_read_logic_pwrst) |
| 806 | ret = arch_pwrdm->pwrdm_read_logic_pwrst(pwrdm); |
| 807 | |
| 808 | return ret; |
Paul Walmsley | ad67ef6 | 2008-08-19 11:08:40 +0300 | [diff] [blame] | 809 | } |
| 810 | |
| 811 | /** |
| 812 | * pwrdm_read_prev_logic_pwrst - get previous powerdomain logic power state |
| 813 | * @pwrdm: struct powerdomain * to get previous logic power state |
| 814 | * |
Paul Walmsley | f0271d6 | 2010-01-26 20:13:02 -0700 | [diff] [blame] | 815 | * Return the powerdomain @pwrdm's previous logic power state. Returns |
| 816 | * -EINVAL if the powerdomain pointer is null or returns the previous |
| 817 | * logic power state upon success. |
Paul Walmsley | ad67ef6 | 2008-08-19 11:08:40 +0300 | [diff] [blame] | 818 | */ |
| 819 | int pwrdm_read_prev_logic_pwrst(struct powerdomain *pwrdm) |
| 820 | { |
Rajendra Nayak | 1262757 | 2010-12-21 20:01:18 -0700 | [diff] [blame] | 821 | int ret = -EINVAL; |
| 822 | |
Paul Walmsley | ad67ef6 | 2008-08-19 11:08:40 +0300 | [diff] [blame] | 823 | if (!pwrdm) |
| 824 | return -EINVAL; |
| 825 | |
Rajendra Nayak | 1262757 | 2010-12-21 20:01:18 -0700 | [diff] [blame] | 826 | if (arch_pwrdm && arch_pwrdm->pwrdm_read_prev_logic_pwrst) |
| 827 | ret = arch_pwrdm->pwrdm_read_prev_logic_pwrst(pwrdm); |
| 828 | |
| 829 | return ret; |
Paul Walmsley | ad67ef6 | 2008-08-19 11:08:40 +0300 | [diff] [blame] | 830 | } |
| 831 | |
| 832 | /** |
Thara Gopinath | 1e3d0d2 | 2010-02-24 12:05:49 -0700 | [diff] [blame] | 833 | * pwrdm_read_logic_retst - get next powerdomain logic power state |
| 834 | * @pwrdm: struct powerdomain * to get next logic power state |
| 835 | * |
| 836 | * Return the powerdomain pwrdm's logic power state. Returns -EINVAL |
| 837 | * if the powerdomain pointer is null or returns the next logic |
| 838 | * power state upon success. |
| 839 | */ |
| 840 | int pwrdm_read_logic_retst(struct powerdomain *pwrdm) |
| 841 | { |
Rajendra Nayak | 1262757 | 2010-12-21 20:01:18 -0700 | [diff] [blame] | 842 | int ret = -EINVAL; |
| 843 | |
Thara Gopinath | 1e3d0d2 | 2010-02-24 12:05:49 -0700 | [diff] [blame] | 844 | if (!pwrdm) |
| 845 | return -EINVAL; |
| 846 | |
Rajendra Nayak | 1262757 | 2010-12-21 20:01:18 -0700 | [diff] [blame] | 847 | if (arch_pwrdm && arch_pwrdm->pwrdm_read_logic_retst) |
| 848 | ret = arch_pwrdm->pwrdm_read_logic_retst(pwrdm); |
| 849 | |
| 850 | return ret; |
Thara Gopinath | 1e3d0d2 | 2010-02-24 12:05:49 -0700 | [diff] [blame] | 851 | } |
| 852 | |
| 853 | /** |
Paul Walmsley | ad67ef6 | 2008-08-19 11:08:40 +0300 | [diff] [blame] | 854 | * pwrdm_read_mem_pwrst - get current memory bank power state |
| 855 | * @pwrdm: struct powerdomain * to get current memory bank power state |
| 856 | * @bank: memory bank number (0-3) |
| 857 | * |
Paul Walmsley | f0271d6 | 2010-01-26 20:13:02 -0700 | [diff] [blame] | 858 | * Return the powerdomain @pwrdm's current memory power state for bank |
| 859 | * @bank. Returns -EINVAL if the powerdomain pointer is null, -EEXIST if |
Paul Walmsley | ad67ef6 | 2008-08-19 11:08:40 +0300 | [diff] [blame] | 860 | * the target memory bank does not exist or is not controllable, or |
| 861 | * returns the current memory power state upon success. |
| 862 | */ |
| 863 | int pwrdm_read_mem_pwrst(struct powerdomain *pwrdm, u8 bank) |
| 864 | { |
Rajendra Nayak | 9b7fc90 | 2010-12-21 20:01:19 -0700 | [diff] [blame] | 865 | int ret = -EINVAL; |
Paul Walmsley | ad67ef6 | 2008-08-19 11:08:40 +0300 | [diff] [blame] | 866 | |
| 867 | if (!pwrdm) |
Rajendra Nayak | 9b7fc90 | 2010-12-21 20:01:19 -0700 | [diff] [blame] | 868 | return ret; |
Paul Walmsley | ad67ef6 | 2008-08-19 11:08:40 +0300 | [diff] [blame] | 869 | |
| 870 | if (pwrdm->banks < (bank + 1)) |
Rajendra Nayak | 9b7fc90 | 2010-12-21 20:01:19 -0700 | [diff] [blame] | 871 | return ret; |
Paul Walmsley | ad67ef6 | 2008-08-19 11:08:40 +0300 | [diff] [blame] | 872 | |
Thara Gopinath | 3863c74 | 2009-12-08 16:33:15 -0700 | [diff] [blame] | 873 | if (pwrdm->flags & PWRDM_HAS_MPU_QUIRK) |
| 874 | bank = 1; |
| 875 | |
Rajendra Nayak | 9b7fc90 | 2010-12-21 20:01:19 -0700 | [diff] [blame] | 876 | if (arch_pwrdm && arch_pwrdm->pwrdm_read_mem_pwrst) |
| 877 | ret = arch_pwrdm->pwrdm_read_mem_pwrst(pwrdm, bank); |
Paul Walmsley | ad67ef6 | 2008-08-19 11:08:40 +0300 | [diff] [blame] | 878 | |
Rajendra Nayak | 9b7fc90 | 2010-12-21 20:01:19 -0700 | [diff] [blame] | 879 | return ret; |
Paul Walmsley | ad67ef6 | 2008-08-19 11:08:40 +0300 | [diff] [blame] | 880 | } |
| 881 | |
| 882 | /** |
| 883 | * pwrdm_read_prev_mem_pwrst - get previous memory bank power state |
| 884 | * @pwrdm: struct powerdomain * to get previous memory bank power state |
| 885 | * @bank: memory bank number (0-3) |
| 886 | * |
Paul Walmsley | f0271d6 | 2010-01-26 20:13:02 -0700 | [diff] [blame] | 887 | * Return the powerdomain @pwrdm's previous memory power state for |
| 888 | * bank @bank. Returns -EINVAL if the powerdomain pointer is null, |
| 889 | * -EEXIST if the target memory bank does not exist or is not |
| 890 | * controllable, or returns the previous memory power state upon |
| 891 | * success. |
Paul Walmsley | ad67ef6 | 2008-08-19 11:08:40 +0300 | [diff] [blame] | 892 | */ |
| 893 | int pwrdm_read_prev_mem_pwrst(struct powerdomain *pwrdm, u8 bank) |
| 894 | { |
Rajendra Nayak | 9b7fc90 | 2010-12-21 20:01:19 -0700 | [diff] [blame] | 895 | int ret = -EINVAL; |
Paul Walmsley | ad67ef6 | 2008-08-19 11:08:40 +0300 | [diff] [blame] | 896 | |
| 897 | if (!pwrdm) |
Rajendra Nayak | 9b7fc90 | 2010-12-21 20:01:19 -0700 | [diff] [blame] | 898 | return ret; |
Paul Walmsley | ad67ef6 | 2008-08-19 11:08:40 +0300 | [diff] [blame] | 899 | |
| 900 | if (pwrdm->banks < (bank + 1)) |
Rajendra Nayak | 9b7fc90 | 2010-12-21 20:01:19 -0700 | [diff] [blame] | 901 | return ret; |
Paul Walmsley | ad67ef6 | 2008-08-19 11:08:40 +0300 | [diff] [blame] | 902 | |
Thara Gopinath | 3863c74 | 2009-12-08 16:33:15 -0700 | [diff] [blame] | 903 | if (pwrdm->flags & PWRDM_HAS_MPU_QUIRK) |
| 904 | bank = 1; |
| 905 | |
Rajendra Nayak | 9b7fc90 | 2010-12-21 20:01:19 -0700 | [diff] [blame] | 906 | if (arch_pwrdm && arch_pwrdm->pwrdm_read_prev_mem_pwrst) |
| 907 | ret = arch_pwrdm->pwrdm_read_prev_mem_pwrst(pwrdm, bank); |
Paul Walmsley | ad67ef6 | 2008-08-19 11:08:40 +0300 | [diff] [blame] | 908 | |
Rajendra Nayak | 9b7fc90 | 2010-12-21 20:01:19 -0700 | [diff] [blame] | 909 | return ret; |
Paul Walmsley | ad67ef6 | 2008-08-19 11:08:40 +0300 | [diff] [blame] | 910 | } |
| 911 | |
| 912 | /** |
Thara Gopinath | 1e3d0d2 | 2010-02-24 12:05:49 -0700 | [diff] [blame] | 913 | * pwrdm_read_mem_retst - get next memory bank power state |
| 914 | * @pwrdm: struct powerdomain * to get mext memory bank power state |
| 915 | * @bank: memory bank number (0-3) |
| 916 | * |
| 917 | * Return the powerdomain pwrdm's next memory power state for bank |
| 918 | * x. Returns -EINVAL if the powerdomain pointer is null, -EEXIST if |
| 919 | * the target memory bank does not exist or is not controllable, or |
| 920 | * returns the next memory power state upon success. |
| 921 | */ |
| 922 | int pwrdm_read_mem_retst(struct powerdomain *pwrdm, u8 bank) |
| 923 | { |
Rajendra Nayak | 9b7fc90 | 2010-12-21 20:01:19 -0700 | [diff] [blame] | 924 | int ret = -EINVAL; |
Thara Gopinath | 1e3d0d2 | 2010-02-24 12:05:49 -0700 | [diff] [blame] | 925 | |
| 926 | if (!pwrdm) |
Rajendra Nayak | 9b7fc90 | 2010-12-21 20:01:19 -0700 | [diff] [blame] | 927 | return ret; |
Thara Gopinath | 1e3d0d2 | 2010-02-24 12:05:49 -0700 | [diff] [blame] | 928 | |
| 929 | if (pwrdm->banks < (bank + 1)) |
Rajendra Nayak | 9b7fc90 | 2010-12-21 20:01:19 -0700 | [diff] [blame] | 930 | return ret; |
Thara Gopinath | 1e3d0d2 | 2010-02-24 12:05:49 -0700 | [diff] [blame] | 931 | |
Rajendra Nayak | 9b7fc90 | 2010-12-21 20:01:19 -0700 | [diff] [blame] | 932 | if (arch_pwrdm && arch_pwrdm->pwrdm_read_mem_retst) |
| 933 | ret = arch_pwrdm->pwrdm_read_mem_retst(pwrdm, bank); |
Thara Gopinath | 1e3d0d2 | 2010-02-24 12:05:49 -0700 | [diff] [blame] | 934 | |
Rajendra Nayak | 9b7fc90 | 2010-12-21 20:01:19 -0700 | [diff] [blame] | 935 | return ret; |
Thara Gopinath | 1e3d0d2 | 2010-02-24 12:05:49 -0700 | [diff] [blame] | 936 | } |
| 937 | |
| 938 | /** |
Paul Walmsley | ad67ef6 | 2008-08-19 11:08:40 +0300 | [diff] [blame] | 939 | * pwrdm_clear_all_prev_pwrst - clear previous powerstate register for a pwrdm |
| 940 | * @pwrdm: struct powerdomain * to clear |
| 941 | * |
Paul Walmsley | f0271d6 | 2010-01-26 20:13:02 -0700 | [diff] [blame] | 942 | * Clear the powerdomain's previous power state register @pwrdm. |
| 943 | * Clears the entire register, including logic and memory bank |
| 944 | * previous power states. Returns -EINVAL if the powerdomain pointer |
| 945 | * is null, or returns 0 upon success. |
Paul Walmsley | ad67ef6 | 2008-08-19 11:08:40 +0300 | [diff] [blame] | 946 | */ |
| 947 | int pwrdm_clear_all_prev_pwrst(struct powerdomain *pwrdm) |
| 948 | { |
Rajendra Nayak | 9b7fc90 | 2010-12-21 20:01:19 -0700 | [diff] [blame] | 949 | int ret = -EINVAL; |
| 950 | |
Paul Walmsley | ad67ef6 | 2008-08-19 11:08:40 +0300 | [diff] [blame] | 951 | if (!pwrdm) |
Rajendra Nayak | 9b7fc90 | 2010-12-21 20:01:19 -0700 | [diff] [blame] | 952 | return ret; |
Paul Walmsley | ad67ef6 | 2008-08-19 11:08:40 +0300 | [diff] [blame] | 953 | |
| 954 | /* |
| 955 | * XXX should get the powerdomain's current state here; |
| 956 | * warn & fail if it is not ON. |
| 957 | */ |
| 958 | |
Paul Walmsley | 7852ec0 | 2012-07-26 00:54:26 -0600 | [diff] [blame] | 959 | pr_debug("powerdomain: %s: clearing previous power state reg\n", |
Paul Walmsley | ad67ef6 | 2008-08-19 11:08:40 +0300 | [diff] [blame] | 960 | pwrdm->name); |
| 961 | |
Rajendra Nayak | 9b7fc90 | 2010-12-21 20:01:19 -0700 | [diff] [blame] | 962 | if (arch_pwrdm && arch_pwrdm->pwrdm_clear_all_prev_pwrst) |
| 963 | ret = arch_pwrdm->pwrdm_clear_all_prev_pwrst(pwrdm); |
Paul Walmsley | ad67ef6 | 2008-08-19 11:08:40 +0300 | [diff] [blame] | 964 | |
Rajendra Nayak | 9b7fc90 | 2010-12-21 20:01:19 -0700 | [diff] [blame] | 965 | return ret; |
Paul Walmsley | ad67ef6 | 2008-08-19 11:08:40 +0300 | [diff] [blame] | 966 | } |
| 967 | |
| 968 | /** |
Paul Walmsley | 0b7cbfb | 2008-06-25 18:09:37 -0600 | [diff] [blame] | 969 | * pwrdm_enable_hdwr_sar - enable automatic hardware SAR for a pwrdm |
| 970 | * @pwrdm: struct powerdomain * |
| 971 | * |
| 972 | * Enable automatic context save-and-restore upon power state change |
Paul Walmsley | f0271d6 | 2010-01-26 20:13:02 -0700 | [diff] [blame] | 973 | * for some devices in the powerdomain @pwrdm. Warning: this only |
| 974 | * affects a subset of devices in a powerdomain; check the TRM |
| 975 | * closely. Returns -EINVAL if the powerdomain pointer is null or if |
| 976 | * the powerdomain does not support automatic save-and-restore, or |
| 977 | * returns 0 upon success. |
Paul Walmsley | 0b7cbfb | 2008-06-25 18:09:37 -0600 | [diff] [blame] | 978 | */ |
| 979 | int pwrdm_enable_hdwr_sar(struct powerdomain *pwrdm) |
| 980 | { |
Rajendra Nayak | 9b7fc90 | 2010-12-21 20:01:19 -0700 | [diff] [blame] | 981 | int ret = -EINVAL; |
| 982 | |
Paul Walmsley | 0b7cbfb | 2008-06-25 18:09:37 -0600 | [diff] [blame] | 983 | if (!pwrdm) |
Rajendra Nayak | 9b7fc90 | 2010-12-21 20:01:19 -0700 | [diff] [blame] | 984 | return ret; |
Paul Walmsley | 0b7cbfb | 2008-06-25 18:09:37 -0600 | [diff] [blame] | 985 | |
| 986 | if (!(pwrdm->flags & PWRDM_HAS_HDWR_SAR)) |
Rajendra Nayak | 9b7fc90 | 2010-12-21 20:01:19 -0700 | [diff] [blame] | 987 | return ret; |
Paul Walmsley | 0b7cbfb | 2008-06-25 18:09:37 -0600 | [diff] [blame] | 988 | |
Paul Walmsley | 7852ec0 | 2012-07-26 00:54:26 -0600 | [diff] [blame] | 989 | pr_debug("powerdomain: %s: setting SAVEANDRESTORE bit\n", pwrdm->name); |
Paul Walmsley | 0b7cbfb | 2008-06-25 18:09:37 -0600 | [diff] [blame] | 990 | |
Rajendra Nayak | 9b7fc90 | 2010-12-21 20:01:19 -0700 | [diff] [blame] | 991 | if (arch_pwrdm && arch_pwrdm->pwrdm_enable_hdwr_sar) |
| 992 | ret = arch_pwrdm->pwrdm_enable_hdwr_sar(pwrdm); |
Paul Walmsley | 0b7cbfb | 2008-06-25 18:09:37 -0600 | [diff] [blame] | 993 | |
Rajendra Nayak | 9b7fc90 | 2010-12-21 20:01:19 -0700 | [diff] [blame] | 994 | return ret; |
Paul Walmsley | 0b7cbfb | 2008-06-25 18:09:37 -0600 | [diff] [blame] | 995 | } |
| 996 | |
| 997 | /** |
| 998 | * pwrdm_disable_hdwr_sar - disable automatic hardware SAR for a pwrdm |
| 999 | * @pwrdm: struct powerdomain * |
| 1000 | * |
| 1001 | * Disable automatic context save-and-restore upon power state change |
Paul Walmsley | f0271d6 | 2010-01-26 20:13:02 -0700 | [diff] [blame] | 1002 | * for some devices in the powerdomain @pwrdm. Warning: this only |
| 1003 | * affects a subset of devices in a powerdomain; check the TRM |
| 1004 | * closely. Returns -EINVAL if the powerdomain pointer is null or if |
| 1005 | * the powerdomain does not support automatic save-and-restore, or |
| 1006 | * returns 0 upon success. |
Paul Walmsley | 0b7cbfb | 2008-06-25 18:09:37 -0600 | [diff] [blame] | 1007 | */ |
| 1008 | int pwrdm_disable_hdwr_sar(struct powerdomain *pwrdm) |
| 1009 | { |
Rajendra Nayak | 9b7fc90 | 2010-12-21 20:01:19 -0700 | [diff] [blame] | 1010 | int ret = -EINVAL; |
| 1011 | |
Paul Walmsley | 0b7cbfb | 2008-06-25 18:09:37 -0600 | [diff] [blame] | 1012 | if (!pwrdm) |
Rajendra Nayak | 9b7fc90 | 2010-12-21 20:01:19 -0700 | [diff] [blame] | 1013 | return ret; |
Paul Walmsley | 0b7cbfb | 2008-06-25 18:09:37 -0600 | [diff] [blame] | 1014 | |
| 1015 | if (!(pwrdm->flags & PWRDM_HAS_HDWR_SAR)) |
Rajendra Nayak | 9b7fc90 | 2010-12-21 20:01:19 -0700 | [diff] [blame] | 1016 | return ret; |
Paul Walmsley | 0b7cbfb | 2008-06-25 18:09:37 -0600 | [diff] [blame] | 1017 | |
Paul Walmsley | 7852ec0 | 2012-07-26 00:54:26 -0600 | [diff] [blame] | 1018 | pr_debug("powerdomain: %s: clearing SAVEANDRESTORE bit\n", pwrdm->name); |
Paul Walmsley | 0b7cbfb | 2008-06-25 18:09:37 -0600 | [diff] [blame] | 1019 | |
Rajendra Nayak | 9b7fc90 | 2010-12-21 20:01:19 -0700 | [diff] [blame] | 1020 | if (arch_pwrdm && arch_pwrdm->pwrdm_disable_hdwr_sar) |
| 1021 | ret = arch_pwrdm->pwrdm_disable_hdwr_sar(pwrdm); |
Paul Walmsley | 0b7cbfb | 2008-06-25 18:09:37 -0600 | [diff] [blame] | 1022 | |
Rajendra Nayak | 9b7fc90 | 2010-12-21 20:01:19 -0700 | [diff] [blame] | 1023 | return ret; |
Paul Walmsley | 0b7cbfb | 2008-06-25 18:09:37 -0600 | [diff] [blame] | 1024 | } |
| 1025 | |
| 1026 | /** |
| 1027 | * pwrdm_has_hdwr_sar - test whether powerdomain supports hardware SAR |
| 1028 | * @pwrdm: struct powerdomain * |
| 1029 | * |
Paul Walmsley | f0271d6 | 2010-01-26 20:13:02 -0700 | [diff] [blame] | 1030 | * Returns 1 if powerdomain @pwrdm supports hardware save-and-restore |
Paul Walmsley | 0b7cbfb | 2008-06-25 18:09:37 -0600 | [diff] [blame] | 1031 | * for some devices, or 0 if it does not. |
| 1032 | */ |
| 1033 | bool pwrdm_has_hdwr_sar(struct powerdomain *pwrdm) |
| 1034 | { |
| 1035 | return (pwrdm && pwrdm->flags & PWRDM_HAS_HDWR_SAR) ? 1 : 0; |
| 1036 | } |
| 1037 | |
Paul Walmsley | 3a09028 | 2013-01-26 00:58:16 -0700 | [diff] [blame] | 1038 | int pwrdm_state_switch_nolock(struct powerdomain *pwrdm) |
Peter 'p2' De Schrijver | ba20bb1 | 2008-10-15 17:48:43 +0300 | [diff] [blame] | 1039 | { |
Santosh Shilimkar | 8b8c3c7 | 2012-03-12 20:04:32 +0530 | [diff] [blame] | 1040 | int ret; |
| 1041 | |
Paul Walmsley | f8457c2 | 2013-01-26 00:58:15 -0700 | [diff] [blame] | 1042 | if (!pwrdm || !arch_pwrdm) |
| 1043 | return -EINVAL; |
| 1044 | |
| 1045 | ret = arch_pwrdm->pwrdm_wait_transition(pwrdm); |
Santosh Shilimkar | 8b8c3c7 | 2012-03-12 20:04:32 +0530 | [diff] [blame] | 1046 | if (!ret) |
| 1047 | ret = _pwrdm_state_switch(pwrdm, PWRDM_STATE_NOW); |
| 1048 | |
| 1049 | return ret; |
Peter 'p2' De Schrijver | ba20bb1 | 2008-10-15 17:48:43 +0300 | [diff] [blame] | 1050 | } |
| 1051 | |
Paul Walmsley | 3a09028 | 2013-01-26 00:58:16 -0700 | [diff] [blame] | 1052 | int __deprecated pwrdm_state_switch(struct powerdomain *pwrdm) |
| 1053 | { |
| 1054 | int ret; |
| 1055 | |
| 1056 | pwrdm_lock(pwrdm); |
| 1057 | ret = pwrdm_state_switch_nolock(pwrdm); |
| 1058 | pwrdm_unlock(pwrdm); |
| 1059 | |
| 1060 | return ret; |
| 1061 | } |
| 1062 | |
Kevin Hilman | e055548 | 2012-05-11 16:00:24 -0700 | [diff] [blame] | 1063 | int pwrdm_pre_transition(struct powerdomain *pwrdm) |
Peter 'p2' De Schrijver | ba20bb1 | 2008-10-15 17:48:43 +0300 | [diff] [blame] | 1064 | { |
Kevin Hilman | e055548 | 2012-05-11 16:00:24 -0700 | [diff] [blame] | 1065 | if (pwrdm) |
| 1066 | _pwrdm_pre_transition_cb(pwrdm, NULL); |
| 1067 | else |
| 1068 | pwrdm_for_each(_pwrdm_pre_transition_cb, NULL); |
| 1069 | |
Peter 'p2' De Schrijver | ba20bb1 | 2008-10-15 17:48:43 +0300 | [diff] [blame] | 1070 | return 0; |
| 1071 | } |
| 1072 | |
Kevin Hilman | e055548 | 2012-05-11 16:00:24 -0700 | [diff] [blame] | 1073 | int pwrdm_post_transition(struct powerdomain *pwrdm) |
Peter 'p2' De Schrijver | ba20bb1 | 2008-10-15 17:48:43 +0300 | [diff] [blame] | 1074 | { |
Kevin Hilman | e055548 | 2012-05-11 16:00:24 -0700 | [diff] [blame] | 1075 | if (pwrdm) |
| 1076 | _pwrdm_post_transition_cb(pwrdm, NULL); |
| 1077 | else |
| 1078 | pwrdm_for_each(_pwrdm_post_transition_cb, NULL); |
| 1079 | |
Peter 'p2' De Schrijver | ba20bb1 | 2008-10-15 17:48:43 +0300 | [diff] [blame] | 1080 | return 0; |
| 1081 | } |
Kevin Hilman | 7f59567 | 2010-12-21 21:31:55 -0700 | [diff] [blame] | 1082 | |
| 1083 | /** |
Nishanth Menon | bd002d7 | 2014-06-06 01:04:20 -0500 | [diff] [blame^] | 1084 | * pwrdm_get_valid_lp_state() - Find best match deep power state |
| 1085 | * @pwrdm: power domain for which we want to find best match |
| 1086 | * @is_logic_state: Are we looking for logic state match here? Should |
| 1087 | * be one of PWRDM_xxx macro values |
| 1088 | * @req_state: requested power state |
| 1089 | * |
| 1090 | * Returns: closest match for requested power state. default fallback |
| 1091 | * is RET for logic state and ON for power state. |
| 1092 | * |
| 1093 | * This does a search from the power domain data looking for the |
| 1094 | * closest valid power domain state that the hardware can achieve. |
| 1095 | * PRCM definitions for PWRSTCTRL allows us to program whatever |
| 1096 | * configuration we'd like, and PRCM will actually attempt such |
| 1097 | * a transition, however if the powerdomain does not actually support it, |
| 1098 | * we endup with a hung system. The valid power domain states are already |
| 1099 | * available in our powerdomain data files. So this function tries to do |
| 1100 | * the following: |
| 1101 | * a) find if we have an exact match to the request - no issues. |
| 1102 | * b) else find if a deeper power state is possible. |
| 1103 | * c) failing which, it tries to find closest higher power state for the |
| 1104 | * request. |
| 1105 | */ |
| 1106 | u8 pwrdm_get_valid_lp_state(struct powerdomain *pwrdm, |
| 1107 | bool is_logic_state, u8 req_state) |
| 1108 | { |
| 1109 | u8 pwrdm_states = is_logic_state ? pwrdm->pwrsts_logic_ret : |
| 1110 | pwrdm->pwrsts; |
| 1111 | /* For logic, ret is highest and others, ON is highest */ |
| 1112 | u8 default_pwrst = is_logic_state ? PWRDM_POWER_RET : PWRDM_POWER_ON; |
| 1113 | u8 new_pwrst; |
| 1114 | bool found; |
| 1115 | |
| 1116 | /* If it is already supported, nothing to search */ |
| 1117 | if (pwrdm_states & BIT(req_state)) |
| 1118 | return req_state; |
| 1119 | |
| 1120 | if (!req_state) |
| 1121 | goto up_search; |
| 1122 | |
| 1123 | /* |
| 1124 | * So, we dont have a exact match |
| 1125 | * Can we get a deeper power state match? |
| 1126 | */ |
| 1127 | new_pwrst = req_state - 1; |
| 1128 | found = true; |
| 1129 | while (!(pwrdm_states & BIT(new_pwrst))) { |
| 1130 | /* No match even at OFF? Not available */ |
| 1131 | if (new_pwrst == PWRDM_POWER_OFF) { |
| 1132 | found = false; |
| 1133 | break; |
| 1134 | } |
| 1135 | new_pwrst--; |
| 1136 | } |
| 1137 | |
| 1138 | if (found) |
| 1139 | goto done; |
| 1140 | |
| 1141 | up_search: |
| 1142 | /* OK, no deeper ones, can we get a higher match? */ |
| 1143 | new_pwrst = req_state + 1; |
| 1144 | while (!(pwrdm_states & BIT(new_pwrst))) { |
| 1145 | if (new_pwrst > PWRDM_POWER_ON) { |
| 1146 | WARN(1, "powerdomain: %s: Fix max powerstate to ON\n", |
| 1147 | pwrdm->name); |
| 1148 | return PWRDM_POWER_ON; |
| 1149 | } |
| 1150 | |
| 1151 | if (new_pwrst == default_pwrst) |
| 1152 | break; |
| 1153 | new_pwrst++; |
| 1154 | } |
| 1155 | done: |
| 1156 | return new_pwrst; |
| 1157 | } |
| 1158 | |
| 1159 | /** |
Paul Walmsley | c4978fb | 2013-01-29 13:45:09 -0700 | [diff] [blame] | 1160 | * omap_set_pwrdm_state - change a powerdomain's current power state |
| 1161 | * @pwrdm: struct powerdomain * to change the power state of |
| 1162 | * @pwrst: power state to change to |
| 1163 | * |
| 1164 | * Change the current hardware power state of the powerdomain |
| 1165 | * represented by @pwrdm to the power state represented by @pwrst. |
| 1166 | * Returns -EINVAL if @pwrdm is null or invalid or if the |
| 1167 | * powerdomain's current power state could not be read, or returns 0 |
| 1168 | * upon success or if @pwrdm does not support @pwrst or any |
| 1169 | * lower-power state. XXX Should not return 0 if the @pwrdm does not |
| 1170 | * support @pwrst or any lower-power state: this should be an error. |
| 1171 | */ |
| 1172 | int omap_set_pwrdm_state(struct powerdomain *pwrdm, u8 pwrst) |
| 1173 | { |
Paul Walmsley | bd70f6e | 2013-03-31 20:22:22 -0600 | [diff] [blame] | 1174 | u8 next_pwrst, sleep_switch; |
| 1175 | int curr_pwrst; |
Paul Walmsley | c4978fb | 2013-01-29 13:45:09 -0700 | [diff] [blame] | 1176 | int ret = 0; |
| 1177 | bool hwsup = false; |
| 1178 | |
| 1179 | if (!pwrdm || IS_ERR(pwrdm)) |
| 1180 | return -EINVAL; |
| 1181 | |
| 1182 | while (!(pwrdm->pwrsts & (1 << pwrst))) { |
| 1183 | if (pwrst == PWRDM_POWER_OFF) |
| 1184 | return ret; |
| 1185 | pwrst--; |
| 1186 | } |
| 1187 | |
Paul Walmsley | 3a09028 | 2013-01-26 00:58:16 -0700 | [diff] [blame] | 1188 | pwrdm_lock(pwrdm); |
| 1189 | |
Paul Walmsley | c4978fb | 2013-01-29 13:45:09 -0700 | [diff] [blame] | 1190 | curr_pwrst = pwrdm_read_pwrst(pwrdm); |
Paul Walmsley | bd70f6e | 2013-03-31 20:22:22 -0600 | [diff] [blame] | 1191 | if (curr_pwrst < 0) { |
| 1192 | ret = -EINVAL; |
| 1193 | goto osps_out; |
| 1194 | } |
| 1195 | |
Paul Walmsley | c4978fb | 2013-01-29 13:45:09 -0700 | [diff] [blame] | 1196 | next_pwrst = pwrdm_read_next_pwrst(pwrdm); |
| 1197 | if (curr_pwrst == pwrst && next_pwrst == pwrst) |
Paul Walmsley | 3a09028 | 2013-01-26 00:58:16 -0700 | [diff] [blame] | 1198 | goto osps_out; |
Paul Walmsley | c4978fb | 2013-01-29 13:45:09 -0700 | [diff] [blame] | 1199 | |
| 1200 | sleep_switch = _pwrdm_save_clkdm_state_and_activate(pwrdm, curr_pwrst, |
| 1201 | pwrst, &hwsup); |
Paul Walmsley | c4978fb | 2013-01-29 13:45:09 -0700 | [diff] [blame] | 1202 | |
| 1203 | ret = pwrdm_set_next_pwrst(pwrdm, pwrst); |
| 1204 | if (ret) |
| 1205 | pr_err("%s: unable to set power state of powerdomain: %s\n", |
| 1206 | __func__, pwrdm->name); |
| 1207 | |
| 1208 | _pwrdm_restore_clkdm_state(pwrdm, sleep_switch, hwsup); |
| 1209 | |
Paul Walmsley | 3a09028 | 2013-01-26 00:58:16 -0700 | [diff] [blame] | 1210 | osps_out: |
| 1211 | pwrdm_unlock(pwrdm); |
| 1212 | |
Paul Walmsley | c4978fb | 2013-01-29 13:45:09 -0700 | [diff] [blame] | 1213 | return ret; |
| 1214 | } |
| 1215 | |
| 1216 | /** |
Kevin Hilman | 7f59567 | 2010-12-21 21:31:55 -0700 | [diff] [blame] | 1217 | * pwrdm_get_context_loss_count - get powerdomain's context loss count |
| 1218 | * @pwrdm: struct powerdomain * to wait for |
| 1219 | * |
| 1220 | * Context loss count is the sum of powerdomain off-mode counter, the |
Tomi Valkeinen | fc01387 | 2011-06-09 16:56:23 +0300 | [diff] [blame] | 1221 | * logic off counter and the per-bank memory off counter. Returns negative |
Kevin Hilman | 7f59567 | 2010-12-21 21:31:55 -0700 | [diff] [blame] | 1222 | * (and WARNs) upon error, otherwise, returns the context loss count. |
| 1223 | */ |
Tomi Valkeinen | fc01387 | 2011-06-09 16:56:23 +0300 | [diff] [blame] | 1224 | int pwrdm_get_context_loss_count(struct powerdomain *pwrdm) |
Kevin Hilman | 7f59567 | 2010-12-21 21:31:55 -0700 | [diff] [blame] | 1225 | { |
| 1226 | int i, count; |
| 1227 | |
| 1228 | if (!pwrdm) { |
| 1229 | WARN(1, "powerdomain: %s: pwrdm is null\n", __func__); |
Tomi Valkeinen | fc01387 | 2011-06-09 16:56:23 +0300 | [diff] [blame] | 1230 | return -ENODEV; |
Kevin Hilman | 7f59567 | 2010-12-21 21:31:55 -0700 | [diff] [blame] | 1231 | } |
| 1232 | |
| 1233 | count = pwrdm->state_counter[PWRDM_POWER_OFF]; |
| 1234 | count += pwrdm->ret_logic_off_counter; |
| 1235 | |
| 1236 | for (i = 0; i < pwrdm->banks; i++) |
| 1237 | count += pwrdm->ret_mem_off_counter[i]; |
| 1238 | |
Tomi Valkeinen | fc01387 | 2011-06-09 16:56:23 +0300 | [diff] [blame] | 1239 | /* |
| 1240 | * Context loss count has to be a non-negative value. Clear the sign |
| 1241 | * bit to get a value range from 0 to INT_MAX. |
| 1242 | */ |
| 1243 | count &= INT_MAX; |
| 1244 | |
| 1245 | pr_debug("powerdomain: %s: context loss count = %d\n", |
Kevin Hilman | 7f59567 | 2010-12-21 21:31:55 -0700 | [diff] [blame] | 1246 | pwrdm->name, count); |
| 1247 | |
| 1248 | return count; |
| 1249 | } |
Paul Walmsley | 694606c | 2011-03-07 19:28:15 -0700 | [diff] [blame] | 1250 | |
| 1251 | /** |
| 1252 | * pwrdm_can_ever_lose_context - can this powerdomain ever lose context? |
| 1253 | * @pwrdm: struct powerdomain * |
| 1254 | * |
| 1255 | * Given a struct powerdomain * @pwrdm, returns 1 if the powerdomain |
| 1256 | * can lose either memory or logic context or if @pwrdm is invalid, or |
| 1257 | * returns 0 otherwise. This function is not concerned with how the |
| 1258 | * powerdomain registers are programmed (i.e., to go off or not); it's |
| 1259 | * concerned with whether it's ever possible for this powerdomain to |
| 1260 | * go off while some other part of the chip is active. This function |
| 1261 | * assumes that every powerdomain can go to either ON or INACTIVE. |
| 1262 | */ |
| 1263 | bool pwrdm_can_ever_lose_context(struct powerdomain *pwrdm) |
| 1264 | { |
| 1265 | int i; |
| 1266 | |
Russell King | 62f0f39 | 2013-02-24 10:55:24 +0000 | [diff] [blame] | 1267 | if (!pwrdm) { |
Paul Walmsley | 694606c | 2011-03-07 19:28:15 -0700 | [diff] [blame] | 1268 | pr_debug("powerdomain: %s: invalid powerdomain pointer\n", |
| 1269 | __func__); |
| 1270 | return 1; |
| 1271 | } |
| 1272 | |
| 1273 | if (pwrdm->pwrsts & PWRSTS_OFF) |
| 1274 | return 1; |
| 1275 | |
| 1276 | if (pwrdm->pwrsts & PWRSTS_RET) { |
| 1277 | if (pwrdm->pwrsts_logic_ret & PWRSTS_OFF) |
| 1278 | return 1; |
| 1279 | |
| 1280 | for (i = 0; i < pwrdm->banks; i++) |
| 1281 | if (pwrdm->pwrsts_mem_ret[i] & PWRSTS_OFF) |
| 1282 | return 1; |
| 1283 | } |
| 1284 | |
| 1285 | for (i = 0; i < pwrdm->banks; i++) |
| 1286 | if (pwrdm->pwrsts_mem_on[i] & PWRSTS_OFF) |
| 1287 | return 1; |
| 1288 | |
| 1289 | return 0; |
| 1290 | } |