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