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