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