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