Paul Walmsley | ad67ef6 | 2008-08-19 11:08:40 +0300 | [diff] [blame] | 1 | /* |
| 2 | * OMAP powerdomain control |
| 3 | * |
| 4 | * Copyright (C) 2007-2008 Texas Instruments, Inc. |
Paul Walmsley | 55ed969 | 2010-01-26 20:12:59 -0700 | [diff] [blame] | 5 | * Copyright (C) 2007-2009 Nokia Corporation |
Paul Walmsley | ad67ef6 | 2008-08-19 11:08:40 +0300 | [diff] [blame] | 6 | * |
| 7 | * Written by Paul Walmsley |
Abhijit Pagare | 3a759f0 | 2010-01-26 20:12:53 -0700 | [diff] [blame] | 8 | * Added OMAP4 specific support by Abhijit Pagare <abhijitpagare@ti.com> |
Paul Walmsley | 4788da2 | 2010-05-18 20:24:05 -0600 | [diff] [blame] | 9 | * State counting code by Tero Kristo <tero.kristo@nokia.com> |
Abhijit Pagare | 3a759f0 | 2010-01-26 20:12:53 -0700 | [diff] [blame] | 10 | * |
Paul Walmsley | ad67ef6 | 2008-08-19 11:08:40 +0300 | [diff] [blame] | 11 | * This program is free software; you can redistribute it and/or modify |
| 12 | * it under the terms of the GNU General Public License version 2 as |
| 13 | * published by the Free Software Foundation. |
| 14 | */ |
Paul Walmsley | 33903eb | 2009-12-08 16:33:10 -0700 | [diff] [blame] | 15 | #undef DEBUG |
Paul Walmsley | ad67ef6 | 2008-08-19 11:08:40 +0300 | [diff] [blame] | 16 | |
| 17 | #include <linux/kernel.h> |
Paul Walmsley | ad67ef6 | 2008-08-19 11:08:40 +0300 | [diff] [blame] | 18 | #include <linux/types.h> |
Paul Walmsley | ad67ef6 | 2008-08-19 11:08:40 +0300 | [diff] [blame] | 19 | #include <linux/list.h> |
| 20 | #include <linux/errno.h> |
Rajendra Nayak | 9b7fc90 | 2010-12-21 20:01:19 -0700 | [diff] [blame^] | 21 | #include <linux/string.h> |
Paul Walmsley | ad67ef6 | 2008-08-19 11:08:40 +0300 | [diff] [blame] | 22 | |
Tony Lindgren | ce491cf | 2009-10-20 09:40:47 -0700 | [diff] [blame] | 23 | #include <plat/cpu.h> |
| 24 | #include <plat/powerdomain.h> |
| 25 | #include <plat/clockdomain.h> |
Paul Walmsley | 55ed969 | 2010-01-26 20:12:59 -0700 | [diff] [blame] | 26 | #include <plat/prcm.h> |
Paul Walmsley | ad67ef6 | 2008-08-19 11:08:40 +0300 | [diff] [blame] | 27 | |
Peter 'p2' De Schrijver | 6199ab2 | 2008-10-15 18:13:49 +0300 | [diff] [blame] | 28 | #include "pm.h" |
| 29 | |
Peter 'p2' De Schrijver | ba20bb1 | 2008-10-15 17:48:43 +0300 | [diff] [blame] | 30 | enum { |
| 31 | PWRDM_STATE_NOW = 0, |
| 32 | PWRDM_STATE_PREV, |
| 33 | }; |
| 34 | |
Abhijit Pagare | 3a759f0 | 2010-01-26 20:12:53 -0700 | [diff] [blame] | 35 | |
Paul Walmsley | ad67ef6 | 2008-08-19 11:08:40 +0300 | [diff] [blame] | 36 | /* pwrdm_list contains all registered struct powerdomains */ |
| 37 | static LIST_HEAD(pwrdm_list); |
| 38 | |
Rajendra Nayak | 3b1e8b2 | 2010-12-21 20:01:18 -0700 | [diff] [blame] | 39 | static struct pwrdm_ops *arch_pwrdm; |
| 40 | |
Paul Walmsley | ad67ef6 | 2008-08-19 11:08:40 +0300 | [diff] [blame] | 41 | /* Private functions */ |
| 42 | |
Paul Walmsley | ad67ef6 | 2008-08-19 11:08:40 +0300 | [diff] [blame] | 43 | static struct powerdomain *_pwrdm_lookup(const char *name) |
| 44 | { |
| 45 | struct powerdomain *pwrdm, *temp_pwrdm; |
| 46 | |
| 47 | pwrdm = NULL; |
| 48 | |
| 49 | list_for_each_entry(temp_pwrdm, &pwrdm_list, node) { |
| 50 | if (!strcmp(name, temp_pwrdm->name)) { |
| 51 | pwrdm = temp_pwrdm; |
| 52 | break; |
| 53 | } |
| 54 | } |
| 55 | |
| 56 | return pwrdm; |
| 57 | } |
| 58 | |
Paul Walmsley | e909d62a8 | 2010-01-26 20:13:00 -0700 | [diff] [blame] | 59 | /** |
| 60 | * _pwrdm_register - register a powerdomain |
| 61 | * @pwrdm: struct powerdomain * to register |
| 62 | * |
| 63 | * Adds a powerdomain to the internal powerdomain list. Returns |
| 64 | * -EINVAL if given a null pointer, -EEXIST if a powerdomain is |
| 65 | * already registered by the provided name, or 0 upon success. |
| 66 | */ |
| 67 | static int _pwrdm_register(struct powerdomain *pwrdm) |
| 68 | { |
| 69 | int i; |
| 70 | |
| 71 | if (!pwrdm) |
| 72 | return -EINVAL; |
| 73 | |
| 74 | if (!omap_chip_is(pwrdm->omap_chip)) |
| 75 | return -EINVAL; |
| 76 | |
| 77 | if (_pwrdm_lookup(pwrdm->name)) |
| 78 | return -EEXIST; |
| 79 | |
| 80 | list_add(&pwrdm->node, &pwrdm_list); |
| 81 | |
| 82 | /* Initialize the powerdomain's state counter */ |
Paul Walmsley | cf57aa7 | 2010-01-26 20:13:01 -0700 | [diff] [blame] | 83 | for (i = 0; i < PWRDM_MAX_PWRSTS; i++) |
Paul Walmsley | e909d62a8 | 2010-01-26 20:13:00 -0700 | [diff] [blame] | 84 | pwrdm->state_counter[i] = 0; |
| 85 | |
Thara Gopinath | cde08f8 | 2010-02-24 12:05:50 -0700 | [diff] [blame] | 86 | pwrdm->ret_logic_off_counter = 0; |
| 87 | for (i = 0; i < pwrdm->banks; i++) |
| 88 | pwrdm->ret_mem_off_counter[i] = 0; |
| 89 | |
Paul Walmsley | e909d62a8 | 2010-01-26 20:13:00 -0700 | [diff] [blame] | 90 | pwrdm_wait_transition(pwrdm); |
| 91 | pwrdm->state = pwrdm_read_pwrst(pwrdm); |
| 92 | pwrdm->state_counter[pwrdm->state] = 1; |
| 93 | |
| 94 | pr_debug("powerdomain: registered %s\n", pwrdm->name); |
| 95 | |
| 96 | return 0; |
| 97 | } |
| 98 | |
Thara Gopinath | cde08f8 | 2010-02-24 12:05:50 -0700 | [diff] [blame] | 99 | static void _update_logic_membank_counters(struct powerdomain *pwrdm) |
| 100 | { |
| 101 | int i; |
| 102 | u8 prev_logic_pwrst, prev_mem_pwrst; |
| 103 | |
| 104 | prev_logic_pwrst = pwrdm_read_prev_logic_pwrst(pwrdm); |
| 105 | if ((pwrdm->pwrsts_logic_ret == PWRSTS_OFF_RET) && |
| 106 | (prev_logic_pwrst == PWRDM_POWER_OFF)) |
| 107 | pwrdm->ret_logic_off_counter++; |
| 108 | |
| 109 | for (i = 0; i < pwrdm->banks; i++) { |
| 110 | prev_mem_pwrst = pwrdm_read_prev_mem_pwrst(pwrdm, i); |
| 111 | |
| 112 | if ((pwrdm->pwrsts_mem_ret[i] == PWRSTS_OFF_RET) && |
| 113 | (prev_mem_pwrst == PWRDM_POWER_OFF)) |
| 114 | pwrdm->ret_mem_off_counter[i]++; |
| 115 | } |
| 116 | } |
| 117 | |
Peter 'p2' De Schrijver | ba20bb1 | 2008-10-15 17:48:43 +0300 | [diff] [blame] | 118 | static int _pwrdm_state_switch(struct powerdomain *pwrdm, int flag) |
| 119 | { |
| 120 | |
| 121 | int prev; |
| 122 | int state; |
| 123 | |
| 124 | if (pwrdm == NULL) |
| 125 | return -EINVAL; |
| 126 | |
| 127 | state = pwrdm_read_pwrst(pwrdm); |
| 128 | |
| 129 | switch (flag) { |
| 130 | case PWRDM_STATE_NOW: |
| 131 | prev = pwrdm->state; |
| 132 | break; |
| 133 | case PWRDM_STATE_PREV: |
| 134 | prev = pwrdm_read_prev_pwrst(pwrdm); |
| 135 | if (pwrdm->state != prev) |
| 136 | pwrdm->state_counter[prev]++; |
Thara Gopinath | cde08f8 | 2010-02-24 12:05:50 -0700 | [diff] [blame] | 137 | if (prev == PWRDM_POWER_RET) |
| 138 | _update_logic_membank_counters(pwrdm); |
Peter 'p2' De Schrijver | ba20bb1 | 2008-10-15 17:48:43 +0300 | [diff] [blame] | 139 | break; |
| 140 | default: |
| 141 | return -EINVAL; |
| 142 | } |
| 143 | |
| 144 | if (state != prev) |
| 145 | pwrdm->state_counter[state]++; |
| 146 | |
Peter 'p2' De Schrijver | 6199ab2 | 2008-10-15 18:13:49 +0300 | [diff] [blame] | 147 | pm_dbg_update_time(pwrdm, prev); |
| 148 | |
Peter 'p2' De Schrijver | ba20bb1 | 2008-10-15 17:48:43 +0300 | [diff] [blame] | 149 | pwrdm->state = state; |
| 150 | |
| 151 | return 0; |
| 152 | } |
| 153 | |
Peter 'p2' De Schrijver | 6199ab2 | 2008-10-15 18:13:49 +0300 | [diff] [blame] | 154 | 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] | 155 | { |
| 156 | pwrdm_clear_all_prev_pwrst(pwrdm); |
| 157 | _pwrdm_state_switch(pwrdm, PWRDM_STATE_NOW); |
| 158 | return 0; |
| 159 | } |
| 160 | |
Peter 'p2' De Schrijver | 6199ab2 | 2008-10-15 18:13:49 +0300 | [diff] [blame] | 161 | 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] | 162 | { |
| 163 | _pwrdm_state_switch(pwrdm, PWRDM_STATE_PREV); |
| 164 | return 0; |
| 165 | } |
| 166 | |
Paul Walmsley | ad67ef6 | 2008-08-19 11:08:40 +0300 | [diff] [blame] | 167 | /* Public functions */ |
| 168 | |
| 169 | /** |
| 170 | * pwrdm_init - set up the powerdomain layer |
Paul Walmsley | f0271d6 | 2010-01-26 20:13:02 -0700 | [diff] [blame] | 171 | * @pwrdm_list: array of struct powerdomain pointers to register |
Rajendra Nayak | 3b1e8b2 | 2010-12-21 20:01:18 -0700 | [diff] [blame] | 172 | * @custom_funcs: func pointers for arch specfic implementations |
Paul Walmsley | ad67ef6 | 2008-08-19 11:08:40 +0300 | [diff] [blame] | 173 | * |
Paul Walmsley | f0271d6 | 2010-01-26 20:13:02 -0700 | [diff] [blame] | 174 | * Loop through the array of powerdomains @pwrdm_list, registering all |
| 175 | * that are available on the current CPU. If pwrdm_list is supplied |
| 176 | * and not null, all of the referenced powerdomains will be |
| 177 | * registered. No return value. XXX pwrdm_list is not really a |
| 178 | * "list"; it is an array. Rename appropriately. |
Paul Walmsley | ad67ef6 | 2008-08-19 11:08:40 +0300 | [diff] [blame] | 179 | */ |
Rajendra Nayak | 3b1e8b2 | 2010-12-21 20:01:18 -0700 | [diff] [blame] | 180 | void pwrdm_init(struct powerdomain **pwrdm_list, struct pwrdm_ops *custom_funcs) |
Paul Walmsley | ad67ef6 | 2008-08-19 11:08:40 +0300 | [diff] [blame] | 181 | { |
| 182 | struct powerdomain **p = NULL; |
| 183 | |
Rajendra Nayak | 3b1e8b2 | 2010-12-21 20:01:18 -0700 | [diff] [blame] | 184 | if (!custom_funcs) |
| 185 | WARN(1, "powerdomain: No custom pwrdm functions registered\n"); |
| 186 | else |
| 187 | arch_pwrdm = custom_funcs; |
| 188 | |
Peter 'p2' De Schrijver | ba20bb1 | 2008-10-15 17:48:43 +0300 | [diff] [blame] | 189 | if (pwrdm_list) { |
Paul Walmsley | e909d62a8 | 2010-01-26 20:13:00 -0700 | [diff] [blame] | 190 | for (p = pwrdm_list; *p; p++) |
| 191 | _pwrdm_register(*p); |
Peter 'p2' De Schrijver | ba20bb1 | 2008-10-15 17:48:43 +0300 | [diff] [blame] | 192 | } |
Paul Walmsley | ad67ef6 | 2008-08-19 11:08:40 +0300 | [diff] [blame] | 193 | } |
| 194 | |
| 195 | /** |
Paul Walmsley | ad67ef6 | 2008-08-19 11:08:40 +0300 | [diff] [blame] | 196 | * pwrdm_lookup - look up a powerdomain by name, return a pointer |
| 197 | * @name: name of powerdomain |
| 198 | * |
Paul Walmsley | f0271d6 | 2010-01-26 20:13:02 -0700 | [diff] [blame] | 199 | * Find a registered powerdomain by its name @name. Returns a pointer |
| 200 | * to the struct powerdomain if found, or NULL otherwise. |
Paul Walmsley | ad67ef6 | 2008-08-19 11:08:40 +0300 | [diff] [blame] | 201 | */ |
| 202 | struct powerdomain *pwrdm_lookup(const char *name) |
| 203 | { |
| 204 | struct powerdomain *pwrdm; |
Paul Walmsley | ad67ef6 | 2008-08-19 11:08:40 +0300 | [diff] [blame] | 205 | |
| 206 | if (!name) |
| 207 | return NULL; |
| 208 | |
Paul Walmsley | ad67ef6 | 2008-08-19 11:08:40 +0300 | [diff] [blame] | 209 | pwrdm = _pwrdm_lookup(name); |
Paul Walmsley | ad67ef6 | 2008-08-19 11:08:40 +0300 | [diff] [blame] | 210 | |
| 211 | return pwrdm; |
| 212 | } |
| 213 | |
| 214 | /** |
Paul Walmsley | e909d62a8 | 2010-01-26 20:13:00 -0700 | [diff] [blame] | 215 | * pwrdm_for_each - call function on each registered clockdomain |
Paul Walmsley | ad67ef6 | 2008-08-19 11:08:40 +0300 | [diff] [blame] | 216 | * @fn: callback function * |
| 217 | * |
Paul Walmsley | f0271d6 | 2010-01-26 20:13:02 -0700 | [diff] [blame] | 218 | * Call the supplied function @fn for each registered powerdomain. |
| 219 | * The callback function @fn can return anything but 0 to bail out |
| 220 | * early from the iterator. Returns the last return value of the |
| 221 | * callback function, which should be 0 for success or anything else |
| 222 | * to indicate failure; or -EINVAL if the function pointer is null. |
Paul Walmsley | ad67ef6 | 2008-08-19 11:08:40 +0300 | [diff] [blame] | 223 | */ |
Paul Walmsley | e909d62a8 | 2010-01-26 20:13:00 -0700 | [diff] [blame] | 224 | int pwrdm_for_each(int (*fn)(struct powerdomain *pwrdm, void *user), |
| 225 | void *user) |
Paul Walmsley | ad67ef6 | 2008-08-19 11:08:40 +0300 | [diff] [blame] | 226 | { |
| 227 | struct powerdomain *temp_pwrdm; |
Paul Walmsley | ad67ef6 | 2008-08-19 11:08:40 +0300 | [diff] [blame] | 228 | int ret = 0; |
| 229 | |
| 230 | if (!fn) |
| 231 | return -EINVAL; |
| 232 | |
Paul Walmsley | ad67ef6 | 2008-08-19 11:08:40 +0300 | [diff] [blame] | 233 | list_for_each_entry(temp_pwrdm, &pwrdm_list, node) { |
Peter 'p2' De Schrijver | 6199ab2 | 2008-10-15 18:13:49 +0300 | [diff] [blame] | 234 | ret = (*fn)(temp_pwrdm, user); |
Paul Walmsley | ad67ef6 | 2008-08-19 11:08:40 +0300 | [diff] [blame] | 235 | if (ret) |
| 236 | break; |
| 237 | } |
Artem Bityutskiy | ee894b1 | 2009-10-01 10:01:55 +0300 | [diff] [blame] | 238 | |
| 239 | return ret; |
| 240 | } |
| 241 | |
| 242 | /** |
Paul Walmsley | 8420bb1 | 2008-08-19 11:08:44 +0300 | [diff] [blame] | 243 | * pwrdm_add_clkdm - add a clockdomain to a powerdomain |
| 244 | * @pwrdm: struct powerdomain * to add the clockdomain to |
| 245 | * @clkdm: struct clockdomain * to associate with a powerdomain |
| 246 | * |
Paul Walmsley | f0271d6 | 2010-01-26 20:13:02 -0700 | [diff] [blame] | 247 | * Associate the clockdomain @clkdm with a powerdomain @pwrdm. This |
Paul Walmsley | 8420bb1 | 2008-08-19 11:08:44 +0300 | [diff] [blame] | 248 | * enables the use of pwrdm_for_each_clkdm(). Returns -EINVAL if |
| 249 | * presented with invalid pointers; -ENOMEM if memory could not be allocated; |
| 250 | * or 0 upon success. |
| 251 | */ |
| 252 | int pwrdm_add_clkdm(struct powerdomain *pwrdm, struct clockdomain *clkdm) |
| 253 | { |
Paul Walmsley | 8420bb1 | 2008-08-19 11:08:44 +0300 | [diff] [blame] | 254 | int i; |
| 255 | int ret = -EINVAL; |
| 256 | |
| 257 | if (!pwrdm || !clkdm) |
| 258 | return -EINVAL; |
| 259 | |
| 260 | pr_debug("powerdomain: associating clockdomain %s with powerdomain " |
| 261 | "%s\n", clkdm->name, pwrdm->name); |
| 262 | |
Paul Walmsley | 8420bb1 | 2008-08-19 11:08:44 +0300 | [diff] [blame] | 263 | for (i = 0; i < PWRDM_MAX_CLKDMS; i++) { |
| 264 | if (!pwrdm->pwrdm_clkdms[i]) |
| 265 | break; |
| 266 | #ifdef DEBUG |
| 267 | if (pwrdm->pwrdm_clkdms[i] == clkdm) { |
| 268 | ret = -EINVAL; |
| 269 | goto pac_exit; |
| 270 | } |
| 271 | #endif |
| 272 | } |
| 273 | |
| 274 | if (i == PWRDM_MAX_CLKDMS) { |
| 275 | pr_debug("powerdomain: increase PWRDM_MAX_CLKDMS for " |
| 276 | "pwrdm %s clkdm %s\n", pwrdm->name, clkdm->name); |
| 277 | WARN_ON(1); |
| 278 | ret = -ENOMEM; |
| 279 | goto pac_exit; |
| 280 | } |
| 281 | |
| 282 | pwrdm->pwrdm_clkdms[i] = clkdm; |
| 283 | |
| 284 | ret = 0; |
| 285 | |
| 286 | pac_exit: |
Paul Walmsley | 8420bb1 | 2008-08-19 11:08:44 +0300 | [diff] [blame] | 287 | return ret; |
| 288 | } |
| 289 | |
| 290 | /** |
| 291 | * pwrdm_del_clkdm - remove a clockdomain from a powerdomain |
| 292 | * @pwrdm: struct powerdomain * to add the clockdomain to |
| 293 | * @clkdm: struct clockdomain * to associate with a powerdomain |
| 294 | * |
Paul Walmsley | f0271d6 | 2010-01-26 20:13:02 -0700 | [diff] [blame] | 295 | * Dissociate the clockdomain @clkdm from the powerdomain |
| 296 | * @pwrdm. Returns -EINVAL if presented with invalid pointers; -ENOENT |
| 297 | * if @clkdm was not associated with the powerdomain, or 0 upon |
| 298 | * success. |
Paul Walmsley | 8420bb1 | 2008-08-19 11:08:44 +0300 | [diff] [blame] | 299 | */ |
| 300 | int pwrdm_del_clkdm(struct powerdomain *pwrdm, struct clockdomain *clkdm) |
| 301 | { |
Paul Walmsley | 8420bb1 | 2008-08-19 11:08:44 +0300 | [diff] [blame] | 302 | int ret = -EINVAL; |
| 303 | int i; |
| 304 | |
| 305 | if (!pwrdm || !clkdm) |
| 306 | return -EINVAL; |
| 307 | |
| 308 | pr_debug("powerdomain: dissociating clockdomain %s from powerdomain " |
| 309 | "%s\n", clkdm->name, pwrdm->name); |
| 310 | |
Paul Walmsley | 8420bb1 | 2008-08-19 11:08:44 +0300 | [diff] [blame] | 311 | for (i = 0; i < PWRDM_MAX_CLKDMS; i++) |
| 312 | if (pwrdm->pwrdm_clkdms[i] == clkdm) |
| 313 | break; |
| 314 | |
| 315 | if (i == PWRDM_MAX_CLKDMS) { |
| 316 | pr_debug("powerdomain: clkdm %s not associated with pwrdm " |
| 317 | "%s ?!\n", clkdm->name, pwrdm->name); |
| 318 | ret = -ENOENT; |
| 319 | goto pdc_exit; |
| 320 | } |
| 321 | |
| 322 | pwrdm->pwrdm_clkdms[i] = NULL; |
| 323 | |
| 324 | ret = 0; |
| 325 | |
| 326 | pdc_exit: |
Paul Walmsley | 8420bb1 | 2008-08-19 11:08:44 +0300 | [diff] [blame] | 327 | return ret; |
| 328 | } |
| 329 | |
| 330 | /** |
| 331 | * pwrdm_for_each_clkdm - call function on each clkdm in a pwrdm |
| 332 | * @pwrdm: struct powerdomain * to iterate over |
| 333 | * @fn: callback function * |
| 334 | * |
Paul Walmsley | f0271d6 | 2010-01-26 20:13:02 -0700 | [diff] [blame] | 335 | * Call the supplied function @fn for each clockdomain in the powerdomain |
| 336 | * @pwrdm. The callback function can return anything but 0 to bail |
Paul Walmsley | e909d62a8 | 2010-01-26 20:13:00 -0700 | [diff] [blame] | 337 | * out early from the iterator. Returns -EINVAL if presented with |
| 338 | * invalid pointers; or passes along the last return value of the |
| 339 | * callback function, which should be 0 for success or anything else |
| 340 | * to indicate failure. |
Paul Walmsley | 8420bb1 | 2008-08-19 11:08:44 +0300 | [diff] [blame] | 341 | */ |
| 342 | int pwrdm_for_each_clkdm(struct powerdomain *pwrdm, |
| 343 | int (*fn)(struct powerdomain *pwrdm, |
| 344 | struct clockdomain *clkdm)) |
| 345 | { |
Paul Walmsley | 8420bb1 | 2008-08-19 11:08:44 +0300 | [diff] [blame] | 346 | int ret = 0; |
| 347 | int i; |
| 348 | |
| 349 | if (!fn) |
| 350 | return -EINVAL; |
| 351 | |
Paul Walmsley | 8420bb1 | 2008-08-19 11:08:44 +0300 | [diff] [blame] | 352 | for (i = 0; i < PWRDM_MAX_CLKDMS && !ret; i++) |
| 353 | ret = (*fn)(pwrdm, pwrdm->pwrdm_clkdms[i]); |
| 354 | |
Paul Walmsley | 8420bb1 | 2008-08-19 11:08:44 +0300 | [diff] [blame] | 355 | return ret; |
| 356 | } |
| 357 | |
Paul Walmsley | ad67ef6 | 2008-08-19 11:08:40 +0300 | [diff] [blame] | 358 | /** |
| 359 | * pwrdm_get_mem_bank_count - get number of memory banks in this powerdomain |
| 360 | * @pwrdm: struct powerdomain * |
| 361 | * |
Paul Walmsley | f0271d6 | 2010-01-26 20:13:02 -0700 | [diff] [blame] | 362 | * Return the number of controllable memory banks in powerdomain @pwrdm, |
Paul Walmsley | ad67ef6 | 2008-08-19 11:08:40 +0300 | [diff] [blame] | 363 | * starting with 1. Returns -EINVAL if the powerdomain pointer is null. |
| 364 | */ |
| 365 | int pwrdm_get_mem_bank_count(struct powerdomain *pwrdm) |
| 366 | { |
| 367 | if (!pwrdm) |
| 368 | return -EINVAL; |
| 369 | |
| 370 | return pwrdm->banks; |
| 371 | } |
| 372 | |
| 373 | /** |
| 374 | * pwrdm_set_next_pwrst - set next powerdomain power state |
| 375 | * @pwrdm: struct powerdomain * to set |
| 376 | * @pwrst: one of the PWRDM_POWER_* macros |
| 377 | * |
Paul Walmsley | f0271d6 | 2010-01-26 20:13:02 -0700 | [diff] [blame] | 378 | * Set the powerdomain @pwrdm's next power state to @pwrst. The powerdomain |
Paul Walmsley | ad67ef6 | 2008-08-19 11:08:40 +0300 | [diff] [blame] | 379 | * may not enter this state immediately if the preconditions for this state |
| 380 | * have not been satisfied. Returns -EINVAL if the powerdomain pointer is |
| 381 | * null or if the power state is invalid for the powerdomin, or returns 0 |
| 382 | * upon success. |
| 383 | */ |
| 384 | int pwrdm_set_next_pwrst(struct powerdomain *pwrdm, u8 pwrst) |
| 385 | { |
Rajendra Nayak | f327e07 | 2010-12-21 20:01:18 -0700 | [diff] [blame] | 386 | int ret = -EINVAL; |
| 387 | |
Paul Walmsley | ad67ef6 | 2008-08-19 11:08:40 +0300 | [diff] [blame] | 388 | if (!pwrdm) |
| 389 | return -EINVAL; |
| 390 | |
| 391 | if (!(pwrdm->pwrsts & (1 << pwrst))) |
| 392 | return -EINVAL; |
| 393 | |
| 394 | pr_debug("powerdomain: setting next powerstate for %s to %0x\n", |
| 395 | pwrdm->name, pwrst); |
| 396 | |
Rajendra Nayak | f327e07 | 2010-12-21 20:01:18 -0700 | [diff] [blame] | 397 | if (arch_pwrdm && arch_pwrdm->pwrdm_set_next_pwrst) |
| 398 | ret = arch_pwrdm->pwrdm_set_next_pwrst(pwrdm, pwrst); |
Paul Walmsley | ad67ef6 | 2008-08-19 11:08:40 +0300 | [diff] [blame] | 399 | |
Rajendra Nayak | f327e07 | 2010-12-21 20:01:18 -0700 | [diff] [blame] | 400 | return ret; |
Paul Walmsley | ad67ef6 | 2008-08-19 11:08:40 +0300 | [diff] [blame] | 401 | } |
| 402 | |
| 403 | /** |
| 404 | * pwrdm_read_next_pwrst - get next powerdomain power state |
| 405 | * @pwrdm: struct powerdomain * to get power state |
| 406 | * |
Paul Walmsley | f0271d6 | 2010-01-26 20:13:02 -0700 | [diff] [blame] | 407 | * Return the powerdomain @pwrdm's next power state. Returns -EINVAL |
Paul Walmsley | ad67ef6 | 2008-08-19 11:08:40 +0300 | [diff] [blame] | 408 | * if the powerdomain pointer is null or returns the next power state |
| 409 | * upon success. |
| 410 | */ |
| 411 | int pwrdm_read_next_pwrst(struct powerdomain *pwrdm) |
| 412 | { |
Rajendra Nayak | f327e07 | 2010-12-21 20:01:18 -0700 | [diff] [blame] | 413 | int ret = -EINVAL; |
| 414 | |
Paul Walmsley | ad67ef6 | 2008-08-19 11:08:40 +0300 | [diff] [blame] | 415 | if (!pwrdm) |
| 416 | return -EINVAL; |
| 417 | |
Rajendra Nayak | f327e07 | 2010-12-21 20:01:18 -0700 | [diff] [blame] | 418 | if (arch_pwrdm && arch_pwrdm->pwrdm_read_next_pwrst) |
| 419 | ret = arch_pwrdm->pwrdm_read_next_pwrst(pwrdm); |
| 420 | |
| 421 | return ret; |
Paul Walmsley | ad67ef6 | 2008-08-19 11:08:40 +0300 | [diff] [blame] | 422 | } |
| 423 | |
| 424 | /** |
| 425 | * pwrdm_read_pwrst - get current powerdomain power state |
| 426 | * @pwrdm: struct powerdomain * to get power state |
| 427 | * |
Paul Walmsley | f0271d6 | 2010-01-26 20:13:02 -0700 | [diff] [blame] | 428 | * Return the powerdomain @pwrdm's current power state. Returns -EINVAL |
Paul Walmsley | ad67ef6 | 2008-08-19 11:08:40 +0300 | [diff] [blame] | 429 | * if the powerdomain pointer is null or returns the current power state |
| 430 | * upon success. |
| 431 | */ |
| 432 | int pwrdm_read_pwrst(struct powerdomain *pwrdm) |
| 433 | { |
Rajendra Nayak | f327e07 | 2010-12-21 20:01:18 -0700 | [diff] [blame] | 434 | int ret = -EINVAL; |
| 435 | |
Paul Walmsley | ad67ef6 | 2008-08-19 11:08:40 +0300 | [diff] [blame] | 436 | if (!pwrdm) |
| 437 | return -EINVAL; |
| 438 | |
Rajendra Nayak | f327e07 | 2010-12-21 20:01:18 -0700 | [diff] [blame] | 439 | if (arch_pwrdm && arch_pwrdm->pwrdm_read_pwrst) |
| 440 | ret = arch_pwrdm->pwrdm_read_pwrst(pwrdm); |
| 441 | |
| 442 | return ret; |
Paul Walmsley | ad67ef6 | 2008-08-19 11:08:40 +0300 | [diff] [blame] | 443 | } |
| 444 | |
| 445 | /** |
| 446 | * pwrdm_read_prev_pwrst - get previous powerdomain power state |
| 447 | * @pwrdm: struct powerdomain * to get previous power state |
| 448 | * |
Paul Walmsley | f0271d6 | 2010-01-26 20:13:02 -0700 | [diff] [blame] | 449 | * Return the powerdomain @pwrdm's previous power state. Returns -EINVAL |
Paul Walmsley | ad67ef6 | 2008-08-19 11:08:40 +0300 | [diff] [blame] | 450 | * if the powerdomain pointer is null or returns the previous power state |
| 451 | * upon success. |
| 452 | */ |
| 453 | int pwrdm_read_prev_pwrst(struct powerdomain *pwrdm) |
| 454 | { |
Rajendra Nayak | f327e07 | 2010-12-21 20:01:18 -0700 | [diff] [blame] | 455 | int ret = -EINVAL; |
| 456 | |
Paul Walmsley | ad67ef6 | 2008-08-19 11:08:40 +0300 | [diff] [blame] | 457 | if (!pwrdm) |
| 458 | return -EINVAL; |
| 459 | |
Rajendra Nayak | f327e07 | 2010-12-21 20:01:18 -0700 | [diff] [blame] | 460 | if (arch_pwrdm && arch_pwrdm->pwrdm_read_prev_pwrst) |
| 461 | ret = arch_pwrdm->pwrdm_read_prev_pwrst(pwrdm); |
| 462 | |
| 463 | return ret; |
Paul Walmsley | ad67ef6 | 2008-08-19 11:08:40 +0300 | [diff] [blame] | 464 | } |
| 465 | |
| 466 | /** |
| 467 | * pwrdm_set_logic_retst - set powerdomain logic power state upon retention |
| 468 | * @pwrdm: struct powerdomain * to set |
| 469 | * @pwrst: one of the PWRDM_POWER_* macros |
| 470 | * |
Paul Walmsley | f0271d6 | 2010-01-26 20:13:02 -0700 | [diff] [blame] | 471 | * Set the next power state @pwrst that the logic portion of the |
| 472 | * powerdomain @pwrdm will enter when the powerdomain enters retention. |
| 473 | * This will be either RETENTION or OFF, if supported. Returns |
| 474 | * -EINVAL if the powerdomain pointer is null or the target power |
| 475 | * state is not not supported, or returns 0 upon success. |
Paul Walmsley | ad67ef6 | 2008-08-19 11:08:40 +0300 | [diff] [blame] | 476 | */ |
| 477 | int pwrdm_set_logic_retst(struct powerdomain *pwrdm, u8 pwrst) |
| 478 | { |
Rajendra Nayak | 1262757 | 2010-12-21 20:01:18 -0700 | [diff] [blame] | 479 | int ret = -EINVAL; |
Paul Walmsley | 2bc4ef7 | 2010-05-18 18:47:24 -0600 | [diff] [blame] | 480 | |
Paul Walmsley | ad67ef6 | 2008-08-19 11:08:40 +0300 | [diff] [blame] | 481 | if (!pwrdm) |
| 482 | return -EINVAL; |
| 483 | |
| 484 | if (!(pwrdm->pwrsts_logic_ret & (1 << pwrst))) |
| 485 | return -EINVAL; |
| 486 | |
| 487 | pr_debug("powerdomain: setting next logic powerstate for %s to %0x\n", |
| 488 | pwrdm->name, pwrst); |
| 489 | |
Rajendra Nayak | 1262757 | 2010-12-21 20:01:18 -0700 | [diff] [blame] | 490 | if (arch_pwrdm && arch_pwrdm->pwrdm_set_logic_retst) |
| 491 | ret = arch_pwrdm->pwrdm_set_logic_retst(pwrdm, pwrst); |
Paul Walmsley | ad67ef6 | 2008-08-19 11:08:40 +0300 | [diff] [blame] | 492 | |
Rajendra Nayak | 1262757 | 2010-12-21 20:01:18 -0700 | [diff] [blame] | 493 | return ret; |
Paul Walmsley | ad67ef6 | 2008-08-19 11:08:40 +0300 | [diff] [blame] | 494 | } |
| 495 | |
| 496 | /** |
| 497 | * pwrdm_set_mem_onst - set memory power state while powerdomain ON |
| 498 | * @pwrdm: struct powerdomain * to set |
| 499 | * @bank: memory bank number to set (0-3) |
| 500 | * @pwrst: one of the PWRDM_POWER_* macros |
| 501 | * |
Paul Walmsley | f0271d6 | 2010-01-26 20:13:02 -0700 | [diff] [blame] | 502 | * Set the next power state @pwrst that memory bank @bank of the |
| 503 | * powerdomain @pwrdm will enter when the powerdomain enters the ON |
| 504 | * state. @bank will be a number from 0 to 3, and represents different |
| 505 | * types of memory, depending on the powerdomain. Returns -EINVAL if |
| 506 | * the powerdomain pointer is null or the target power state is not |
| 507 | * not supported for this memory bank, -EEXIST if the target memory |
| 508 | * bank does not exist or is not controllable, or returns 0 upon |
| 509 | * success. |
Paul Walmsley | ad67ef6 | 2008-08-19 11:08:40 +0300 | [diff] [blame] | 510 | */ |
| 511 | int pwrdm_set_mem_onst(struct powerdomain *pwrdm, u8 bank, u8 pwrst) |
| 512 | { |
Rajendra Nayak | 9b7fc90 | 2010-12-21 20:01:19 -0700 | [diff] [blame^] | 513 | int ret = -EINVAL; |
Paul Walmsley | ad67ef6 | 2008-08-19 11:08:40 +0300 | [diff] [blame] | 514 | |
| 515 | if (!pwrdm) |
| 516 | return -EINVAL; |
| 517 | |
| 518 | if (pwrdm->banks < (bank + 1)) |
| 519 | return -EEXIST; |
| 520 | |
| 521 | if (!(pwrdm->pwrsts_mem_on[bank] & (1 << pwrst))) |
| 522 | return -EINVAL; |
| 523 | |
| 524 | pr_debug("powerdomain: setting next memory powerstate for domain %s " |
| 525 | "bank %0x while pwrdm-ON to %0x\n", pwrdm->name, bank, pwrst); |
| 526 | |
Rajendra Nayak | 9b7fc90 | 2010-12-21 20:01:19 -0700 | [diff] [blame^] | 527 | if (arch_pwrdm && arch_pwrdm->pwrdm_set_mem_onst) |
| 528 | ret = arch_pwrdm->pwrdm_set_mem_onst(pwrdm, bank, pwrst); |
Paul Walmsley | ad67ef6 | 2008-08-19 11:08:40 +0300 | [diff] [blame] | 529 | |
Rajendra Nayak | 9b7fc90 | 2010-12-21 20:01:19 -0700 | [diff] [blame^] | 530 | return ret; |
Paul Walmsley | ad67ef6 | 2008-08-19 11:08:40 +0300 | [diff] [blame] | 531 | } |
| 532 | |
| 533 | /** |
| 534 | * pwrdm_set_mem_retst - set memory power state while powerdomain in RET |
| 535 | * @pwrdm: struct powerdomain * to set |
| 536 | * @bank: memory bank number to set (0-3) |
| 537 | * @pwrst: one of the PWRDM_POWER_* macros |
| 538 | * |
Paul Walmsley | f0271d6 | 2010-01-26 20:13:02 -0700 | [diff] [blame] | 539 | * Set the next power state @pwrst that memory bank @bank of the |
| 540 | * powerdomain @pwrdm will enter when the powerdomain enters the |
| 541 | * RETENTION state. Bank will be a number from 0 to 3, and represents |
| 542 | * different types of memory, depending on the powerdomain. @pwrst |
| 543 | * will be either RETENTION or OFF, if supported. Returns -EINVAL if |
| 544 | * the powerdomain pointer is null or the target power state is not |
| 545 | * not supported for this memory bank, -EEXIST if the target memory |
| 546 | * bank does not exist or is not controllable, or returns 0 upon |
| 547 | * success. |
Paul Walmsley | ad67ef6 | 2008-08-19 11:08:40 +0300 | [diff] [blame] | 548 | */ |
| 549 | int pwrdm_set_mem_retst(struct powerdomain *pwrdm, u8 bank, u8 pwrst) |
| 550 | { |
Rajendra Nayak | 9b7fc90 | 2010-12-21 20:01:19 -0700 | [diff] [blame^] | 551 | int ret = -EINVAL; |
Paul Walmsley | ad67ef6 | 2008-08-19 11:08:40 +0300 | [diff] [blame] | 552 | |
| 553 | if (!pwrdm) |
| 554 | return -EINVAL; |
| 555 | |
| 556 | if (pwrdm->banks < (bank + 1)) |
| 557 | return -EEXIST; |
| 558 | |
| 559 | if (!(pwrdm->pwrsts_mem_ret[bank] & (1 << pwrst))) |
| 560 | return -EINVAL; |
| 561 | |
| 562 | pr_debug("powerdomain: setting next memory powerstate for domain %s " |
| 563 | "bank %0x while pwrdm-RET to %0x\n", pwrdm->name, bank, pwrst); |
| 564 | |
Rajendra Nayak | 9b7fc90 | 2010-12-21 20:01:19 -0700 | [diff] [blame^] | 565 | if (arch_pwrdm && arch_pwrdm->pwrdm_set_mem_retst) |
| 566 | ret = arch_pwrdm->pwrdm_set_mem_retst(pwrdm, bank, pwrst); |
Paul Walmsley | ad67ef6 | 2008-08-19 11:08:40 +0300 | [diff] [blame] | 567 | |
Rajendra Nayak | 9b7fc90 | 2010-12-21 20:01:19 -0700 | [diff] [blame^] | 568 | return ret; |
Paul Walmsley | ad67ef6 | 2008-08-19 11:08:40 +0300 | [diff] [blame] | 569 | } |
| 570 | |
| 571 | /** |
| 572 | * pwrdm_read_logic_pwrst - get current powerdomain logic retention power state |
| 573 | * @pwrdm: struct powerdomain * to get current logic retention power state |
| 574 | * |
Paul Walmsley | f0271d6 | 2010-01-26 20:13:02 -0700 | [diff] [blame] | 575 | * Return the power state that the logic portion of powerdomain @pwrdm |
| 576 | * will enter when the powerdomain enters retention. Returns -EINVAL |
| 577 | * if the powerdomain pointer is null or returns the logic retention |
| 578 | * power state upon success. |
Paul Walmsley | ad67ef6 | 2008-08-19 11:08:40 +0300 | [diff] [blame] | 579 | */ |
| 580 | int pwrdm_read_logic_pwrst(struct powerdomain *pwrdm) |
| 581 | { |
Rajendra Nayak | 1262757 | 2010-12-21 20:01:18 -0700 | [diff] [blame] | 582 | int ret = -EINVAL; |
| 583 | |
Paul Walmsley | ad67ef6 | 2008-08-19 11:08:40 +0300 | [diff] [blame] | 584 | if (!pwrdm) |
| 585 | return -EINVAL; |
| 586 | |
Rajendra Nayak | 1262757 | 2010-12-21 20:01:18 -0700 | [diff] [blame] | 587 | if (arch_pwrdm && arch_pwrdm->pwrdm_read_logic_pwrst) |
| 588 | ret = arch_pwrdm->pwrdm_read_logic_pwrst(pwrdm); |
| 589 | |
| 590 | return ret; |
Paul Walmsley | ad67ef6 | 2008-08-19 11:08:40 +0300 | [diff] [blame] | 591 | } |
| 592 | |
| 593 | /** |
| 594 | * pwrdm_read_prev_logic_pwrst - get previous powerdomain logic power state |
| 595 | * @pwrdm: struct powerdomain * to get previous logic power state |
| 596 | * |
Paul Walmsley | f0271d6 | 2010-01-26 20:13:02 -0700 | [diff] [blame] | 597 | * Return the powerdomain @pwrdm's previous logic power state. Returns |
| 598 | * -EINVAL if the powerdomain pointer is null or returns the previous |
| 599 | * logic power state upon success. |
Paul Walmsley | ad67ef6 | 2008-08-19 11:08:40 +0300 | [diff] [blame] | 600 | */ |
| 601 | int pwrdm_read_prev_logic_pwrst(struct powerdomain *pwrdm) |
| 602 | { |
Rajendra Nayak | 1262757 | 2010-12-21 20:01:18 -0700 | [diff] [blame] | 603 | int ret = -EINVAL; |
| 604 | |
Paul Walmsley | ad67ef6 | 2008-08-19 11:08:40 +0300 | [diff] [blame] | 605 | if (!pwrdm) |
| 606 | return -EINVAL; |
| 607 | |
Rajendra Nayak | 1262757 | 2010-12-21 20:01:18 -0700 | [diff] [blame] | 608 | if (arch_pwrdm && arch_pwrdm->pwrdm_read_prev_logic_pwrst) |
| 609 | ret = arch_pwrdm->pwrdm_read_prev_logic_pwrst(pwrdm); |
| 610 | |
| 611 | return ret; |
Paul Walmsley | ad67ef6 | 2008-08-19 11:08:40 +0300 | [diff] [blame] | 612 | } |
| 613 | |
| 614 | /** |
Thara Gopinath | 1e3d0d2 | 2010-02-24 12:05:49 -0700 | [diff] [blame] | 615 | * pwrdm_read_logic_retst - get next powerdomain logic power state |
| 616 | * @pwrdm: struct powerdomain * to get next logic power state |
| 617 | * |
| 618 | * Return the powerdomain pwrdm's logic power state. Returns -EINVAL |
| 619 | * if the powerdomain pointer is null or returns the next logic |
| 620 | * power state upon success. |
| 621 | */ |
| 622 | int pwrdm_read_logic_retst(struct powerdomain *pwrdm) |
| 623 | { |
Rajendra Nayak | 1262757 | 2010-12-21 20:01:18 -0700 | [diff] [blame] | 624 | int ret = -EINVAL; |
| 625 | |
Thara Gopinath | 1e3d0d2 | 2010-02-24 12:05:49 -0700 | [diff] [blame] | 626 | if (!pwrdm) |
| 627 | return -EINVAL; |
| 628 | |
Rajendra Nayak | 1262757 | 2010-12-21 20:01:18 -0700 | [diff] [blame] | 629 | if (arch_pwrdm && arch_pwrdm->pwrdm_read_logic_retst) |
| 630 | ret = arch_pwrdm->pwrdm_read_logic_retst(pwrdm); |
| 631 | |
| 632 | return ret; |
Thara Gopinath | 1e3d0d2 | 2010-02-24 12:05:49 -0700 | [diff] [blame] | 633 | } |
| 634 | |
| 635 | /** |
Paul Walmsley | ad67ef6 | 2008-08-19 11:08:40 +0300 | [diff] [blame] | 636 | * pwrdm_read_mem_pwrst - get current memory bank power state |
| 637 | * @pwrdm: struct powerdomain * to get current memory bank power state |
| 638 | * @bank: memory bank number (0-3) |
| 639 | * |
Paul Walmsley | f0271d6 | 2010-01-26 20:13:02 -0700 | [diff] [blame] | 640 | * Return the powerdomain @pwrdm's current memory power state for bank |
| 641 | * @bank. Returns -EINVAL if the powerdomain pointer is null, -EEXIST if |
Paul Walmsley | ad67ef6 | 2008-08-19 11:08:40 +0300 | [diff] [blame] | 642 | * the target memory bank does not exist or is not controllable, or |
| 643 | * returns the current memory power state upon success. |
| 644 | */ |
| 645 | int pwrdm_read_mem_pwrst(struct powerdomain *pwrdm, u8 bank) |
| 646 | { |
Rajendra Nayak | 9b7fc90 | 2010-12-21 20:01:19 -0700 | [diff] [blame^] | 647 | int ret = -EINVAL; |
Paul Walmsley | ad67ef6 | 2008-08-19 11:08:40 +0300 | [diff] [blame] | 648 | |
| 649 | if (!pwrdm) |
Rajendra Nayak | 9b7fc90 | 2010-12-21 20:01:19 -0700 | [diff] [blame^] | 650 | return ret; |
Paul Walmsley | ad67ef6 | 2008-08-19 11:08:40 +0300 | [diff] [blame] | 651 | |
| 652 | if (pwrdm->banks < (bank + 1)) |
Rajendra Nayak | 9b7fc90 | 2010-12-21 20:01:19 -0700 | [diff] [blame^] | 653 | return ret; |
Paul Walmsley | ad67ef6 | 2008-08-19 11:08:40 +0300 | [diff] [blame] | 654 | |
Thara Gopinath | 3863c74 | 2009-12-08 16:33:15 -0700 | [diff] [blame] | 655 | if (pwrdm->flags & PWRDM_HAS_MPU_QUIRK) |
| 656 | bank = 1; |
| 657 | |
Rajendra Nayak | 9b7fc90 | 2010-12-21 20:01:19 -0700 | [diff] [blame^] | 658 | if (arch_pwrdm && arch_pwrdm->pwrdm_read_mem_pwrst) |
| 659 | ret = arch_pwrdm->pwrdm_read_mem_pwrst(pwrdm, bank); |
Paul Walmsley | ad67ef6 | 2008-08-19 11:08:40 +0300 | [diff] [blame] | 660 | |
Rajendra Nayak | 9b7fc90 | 2010-12-21 20:01:19 -0700 | [diff] [blame^] | 661 | return ret; |
Paul Walmsley | ad67ef6 | 2008-08-19 11:08:40 +0300 | [diff] [blame] | 662 | } |
| 663 | |
| 664 | /** |
| 665 | * pwrdm_read_prev_mem_pwrst - get previous memory bank power state |
| 666 | * @pwrdm: struct powerdomain * to get previous memory bank power state |
| 667 | * @bank: memory bank number (0-3) |
| 668 | * |
Paul Walmsley | f0271d6 | 2010-01-26 20:13:02 -0700 | [diff] [blame] | 669 | * Return the powerdomain @pwrdm's previous memory power state for |
| 670 | * bank @bank. Returns -EINVAL if the powerdomain pointer is null, |
| 671 | * -EEXIST if the target memory bank does not exist or is not |
| 672 | * controllable, or returns the previous memory power state upon |
| 673 | * success. |
Paul Walmsley | ad67ef6 | 2008-08-19 11:08:40 +0300 | [diff] [blame] | 674 | */ |
| 675 | int pwrdm_read_prev_mem_pwrst(struct powerdomain *pwrdm, u8 bank) |
| 676 | { |
Rajendra Nayak | 9b7fc90 | 2010-12-21 20:01:19 -0700 | [diff] [blame^] | 677 | int ret = -EINVAL; |
Paul Walmsley | ad67ef6 | 2008-08-19 11:08:40 +0300 | [diff] [blame] | 678 | |
| 679 | if (!pwrdm) |
Rajendra Nayak | 9b7fc90 | 2010-12-21 20:01:19 -0700 | [diff] [blame^] | 680 | return ret; |
Paul Walmsley | ad67ef6 | 2008-08-19 11:08:40 +0300 | [diff] [blame] | 681 | |
| 682 | if (pwrdm->banks < (bank + 1)) |
Rajendra Nayak | 9b7fc90 | 2010-12-21 20:01:19 -0700 | [diff] [blame^] | 683 | return ret; |
Paul Walmsley | ad67ef6 | 2008-08-19 11:08:40 +0300 | [diff] [blame] | 684 | |
Thara Gopinath | 3863c74 | 2009-12-08 16:33:15 -0700 | [diff] [blame] | 685 | if (pwrdm->flags & PWRDM_HAS_MPU_QUIRK) |
| 686 | bank = 1; |
| 687 | |
Rajendra Nayak | 9b7fc90 | 2010-12-21 20:01:19 -0700 | [diff] [blame^] | 688 | if (arch_pwrdm && arch_pwrdm->pwrdm_read_prev_mem_pwrst) |
| 689 | ret = arch_pwrdm->pwrdm_read_prev_mem_pwrst(pwrdm, bank); |
Paul Walmsley | ad67ef6 | 2008-08-19 11:08:40 +0300 | [diff] [blame] | 690 | |
Rajendra Nayak | 9b7fc90 | 2010-12-21 20:01:19 -0700 | [diff] [blame^] | 691 | return ret; |
Paul Walmsley | ad67ef6 | 2008-08-19 11:08:40 +0300 | [diff] [blame] | 692 | } |
| 693 | |
| 694 | /** |
Thara Gopinath | 1e3d0d2 | 2010-02-24 12:05:49 -0700 | [diff] [blame] | 695 | * pwrdm_read_mem_retst - get next memory bank power state |
| 696 | * @pwrdm: struct powerdomain * to get mext memory bank power state |
| 697 | * @bank: memory bank number (0-3) |
| 698 | * |
| 699 | * Return the powerdomain pwrdm's next memory power state for bank |
| 700 | * x. Returns -EINVAL if the powerdomain pointer is null, -EEXIST if |
| 701 | * the target memory bank does not exist or is not controllable, or |
| 702 | * returns the next memory power state upon success. |
| 703 | */ |
| 704 | int pwrdm_read_mem_retst(struct powerdomain *pwrdm, u8 bank) |
| 705 | { |
Rajendra Nayak | 9b7fc90 | 2010-12-21 20:01:19 -0700 | [diff] [blame^] | 706 | int ret = -EINVAL; |
Thara Gopinath | 1e3d0d2 | 2010-02-24 12:05:49 -0700 | [diff] [blame] | 707 | |
| 708 | if (!pwrdm) |
Rajendra Nayak | 9b7fc90 | 2010-12-21 20:01:19 -0700 | [diff] [blame^] | 709 | return ret; |
Thara Gopinath | 1e3d0d2 | 2010-02-24 12:05:49 -0700 | [diff] [blame] | 710 | |
| 711 | if (pwrdm->banks < (bank + 1)) |
Rajendra Nayak | 9b7fc90 | 2010-12-21 20:01:19 -0700 | [diff] [blame^] | 712 | return ret; |
Thara Gopinath | 1e3d0d2 | 2010-02-24 12:05:49 -0700 | [diff] [blame] | 713 | |
Rajendra Nayak | 9b7fc90 | 2010-12-21 20:01:19 -0700 | [diff] [blame^] | 714 | if (arch_pwrdm && arch_pwrdm->pwrdm_read_mem_retst) |
| 715 | ret = arch_pwrdm->pwrdm_read_mem_retst(pwrdm, bank); |
Thara Gopinath | 1e3d0d2 | 2010-02-24 12:05:49 -0700 | [diff] [blame] | 716 | |
Rajendra Nayak | 9b7fc90 | 2010-12-21 20:01:19 -0700 | [diff] [blame^] | 717 | return ret; |
Thara Gopinath | 1e3d0d2 | 2010-02-24 12:05:49 -0700 | [diff] [blame] | 718 | } |
| 719 | |
| 720 | /** |
Paul Walmsley | ad67ef6 | 2008-08-19 11:08:40 +0300 | [diff] [blame] | 721 | * pwrdm_clear_all_prev_pwrst - clear previous powerstate register for a pwrdm |
| 722 | * @pwrdm: struct powerdomain * to clear |
| 723 | * |
Paul Walmsley | f0271d6 | 2010-01-26 20:13:02 -0700 | [diff] [blame] | 724 | * Clear the powerdomain's previous power state register @pwrdm. |
| 725 | * Clears the entire register, including logic and memory bank |
| 726 | * previous power states. Returns -EINVAL if the powerdomain pointer |
| 727 | * is null, or returns 0 upon success. |
Paul Walmsley | ad67ef6 | 2008-08-19 11:08:40 +0300 | [diff] [blame] | 728 | */ |
| 729 | int pwrdm_clear_all_prev_pwrst(struct powerdomain *pwrdm) |
| 730 | { |
Rajendra Nayak | 9b7fc90 | 2010-12-21 20:01:19 -0700 | [diff] [blame^] | 731 | int ret = -EINVAL; |
| 732 | |
Paul Walmsley | ad67ef6 | 2008-08-19 11:08:40 +0300 | [diff] [blame] | 733 | if (!pwrdm) |
Rajendra Nayak | 9b7fc90 | 2010-12-21 20:01:19 -0700 | [diff] [blame^] | 734 | return ret; |
Paul Walmsley | ad67ef6 | 2008-08-19 11:08:40 +0300 | [diff] [blame] | 735 | |
| 736 | /* |
| 737 | * XXX should get the powerdomain's current state here; |
| 738 | * warn & fail if it is not ON. |
| 739 | */ |
| 740 | |
| 741 | pr_debug("powerdomain: clearing previous power state reg for %s\n", |
| 742 | pwrdm->name); |
| 743 | |
Rajendra Nayak | 9b7fc90 | 2010-12-21 20:01:19 -0700 | [diff] [blame^] | 744 | if (arch_pwrdm && arch_pwrdm->pwrdm_clear_all_prev_pwrst) |
| 745 | ret = arch_pwrdm->pwrdm_clear_all_prev_pwrst(pwrdm); |
Paul Walmsley | ad67ef6 | 2008-08-19 11:08:40 +0300 | [diff] [blame] | 746 | |
Rajendra Nayak | 9b7fc90 | 2010-12-21 20:01:19 -0700 | [diff] [blame^] | 747 | return ret; |
Paul Walmsley | ad67ef6 | 2008-08-19 11:08:40 +0300 | [diff] [blame] | 748 | } |
| 749 | |
| 750 | /** |
Paul Walmsley | 0b7cbfb | 2008-06-25 18:09:37 -0600 | [diff] [blame] | 751 | * pwrdm_enable_hdwr_sar - enable automatic hardware SAR for a pwrdm |
| 752 | * @pwrdm: struct powerdomain * |
| 753 | * |
| 754 | * Enable automatic context save-and-restore upon power state change |
Paul Walmsley | f0271d6 | 2010-01-26 20:13:02 -0700 | [diff] [blame] | 755 | * for some devices in the powerdomain @pwrdm. Warning: this only |
| 756 | * affects a subset of devices in a powerdomain; check the TRM |
| 757 | * closely. Returns -EINVAL if the powerdomain pointer is null or if |
| 758 | * the powerdomain does not support automatic save-and-restore, or |
| 759 | * returns 0 upon success. |
Paul Walmsley | 0b7cbfb | 2008-06-25 18:09:37 -0600 | [diff] [blame] | 760 | */ |
| 761 | int pwrdm_enable_hdwr_sar(struct powerdomain *pwrdm) |
| 762 | { |
Rajendra Nayak | 9b7fc90 | 2010-12-21 20:01:19 -0700 | [diff] [blame^] | 763 | int ret = -EINVAL; |
| 764 | |
Paul Walmsley | 0b7cbfb | 2008-06-25 18:09:37 -0600 | [diff] [blame] | 765 | if (!pwrdm) |
Rajendra Nayak | 9b7fc90 | 2010-12-21 20:01:19 -0700 | [diff] [blame^] | 766 | return ret; |
Paul Walmsley | 0b7cbfb | 2008-06-25 18:09:37 -0600 | [diff] [blame] | 767 | |
| 768 | if (!(pwrdm->flags & PWRDM_HAS_HDWR_SAR)) |
Rajendra Nayak | 9b7fc90 | 2010-12-21 20:01:19 -0700 | [diff] [blame^] | 769 | return ret; |
Paul Walmsley | 0b7cbfb | 2008-06-25 18:09:37 -0600 | [diff] [blame] | 770 | |
| 771 | pr_debug("powerdomain: %s: setting SAVEANDRESTORE bit\n", |
| 772 | pwrdm->name); |
| 773 | |
Rajendra Nayak | 9b7fc90 | 2010-12-21 20:01:19 -0700 | [diff] [blame^] | 774 | if (arch_pwrdm && arch_pwrdm->pwrdm_enable_hdwr_sar) |
| 775 | ret = arch_pwrdm->pwrdm_enable_hdwr_sar(pwrdm); |
Paul Walmsley | 0b7cbfb | 2008-06-25 18:09:37 -0600 | [diff] [blame] | 776 | |
Rajendra Nayak | 9b7fc90 | 2010-12-21 20:01:19 -0700 | [diff] [blame^] | 777 | return ret; |
Paul Walmsley | 0b7cbfb | 2008-06-25 18:09:37 -0600 | [diff] [blame] | 778 | } |
| 779 | |
| 780 | /** |
| 781 | * pwrdm_disable_hdwr_sar - disable automatic hardware SAR for a pwrdm |
| 782 | * @pwrdm: struct powerdomain * |
| 783 | * |
| 784 | * Disable automatic context save-and-restore upon power state change |
Paul Walmsley | f0271d6 | 2010-01-26 20:13:02 -0700 | [diff] [blame] | 785 | * for some devices in the powerdomain @pwrdm. Warning: this only |
| 786 | * affects a subset of devices in a powerdomain; check the TRM |
| 787 | * closely. Returns -EINVAL if the powerdomain pointer is null or if |
| 788 | * the powerdomain does not support automatic save-and-restore, or |
| 789 | * returns 0 upon success. |
Paul Walmsley | 0b7cbfb | 2008-06-25 18:09:37 -0600 | [diff] [blame] | 790 | */ |
| 791 | int pwrdm_disable_hdwr_sar(struct powerdomain *pwrdm) |
| 792 | { |
Rajendra Nayak | 9b7fc90 | 2010-12-21 20:01:19 -0700 | [diff] [blame^] | 793 | int ret = -EINVAL; |
| 794 | |
Paul Walmsley | 0b7cbfb | 2008-06-25 18:09:37 -0600 | [diff] [blame] | 795 | if (!pwrdm) |
Rajendra Nayak | 9b7fc90 | 2010-12-21 20:01:19 -0700 | [diff] [blame^] | 796 | return ret; |
Paul Walmsley | 0b7cbfb | 2008-06-25 18:09:37 -0600 | [diff] [blame] | 797 | |
| 798 | if (!(pwrdm->flags & PWRDM_HAS_HDWR_SAR)) |
Rajendra Nayak | 9b7fc90 | 2010-12-21 20:01:19 -0700 | [diff] [blame^] | 799 | return ret; |
Paul Walmsley | 0b7cbfb | 2008-06-25 18:09:37 -0600 | [diff] [blame] | 800 | |
| 801 | pr_debug("powerdomain: %s: clearing SAVEANDRESTORE bit\n", |
| 802 | pwrdm->name); |
| 803 | |
Rajendra Nayak | 9b7fc90 | 2010-12-21 20:01:19 -0700 | [diff] [blame^] | 804 | if (arch_pwrdm && arch_pwrdm->pwrdm_disable_hdwr_sar) |
| 805 | ret = arch_pwrdm->pwrdm_disable_hdwr_sar(pwrdm); |
Paul Walmsley | 0b7cbfb | 2008-06-25 18:09:37 -0600 | [diff] [blame] | 806 | |
Rajendra Nayak | 9b7fc90 | 2010-12-21 20:01:19 -0700 | [diff] [blame^] | 807 | return ret; |
Paul Walmsley | 0b7cbfb | 2008-06-25 18:09:37 -0600 | [diff] [blame] | 808 | } |
| 809 | |
| 810 | /** |
| 811 | * pwrdm_has_hdwr_sar - test whether powerdomain supports hardware SAR |
| 812 | * @pwrdm: struct powerdomain * |
| 813 | * |
Paul Walmsley | f0271d6 | 2010-01-26 20:13:02 -0700 | [diff] [blame] | 814 | * Returns 1 if powerdomain @pwrdm supports hardware save-and-restore |
Paul Walmsley | 0b7cbfb | 2008-06-25 18:09:37 -0600 | [diff] [blame] | 815 | * for some devices, or 0 if it does not. |
| 816 | */ |
| 817 | bool pwrdm_has_hdwr_sar(struct powerdomain *pwrdm) |
| 818 | { |
| 819 | return (pwrdm && pwrdm->flags & PWRDM_HAS_HDWR_SAR) ? 1 : 0; |
| 820 | } |
| 821 | |
| 822 | /** |
Rajendra Nayak | 90dbc7b | 2010-05-18 20:24:03 -0600 | [diff] [blame] | 823 | * pwrdm_set_lowpwrstchange - Request a low power state change |
| 824 | * @pwrdm: struct powerdomain * |
| 825 | * |
| 826 | * Allows a powerdomain to transtion to a lower power sleep state |
| 827 | * from an existing sleep state without waking up the powerdomain. |
| 828 | * Returns -EINVAL if the powerdomain pointer is null or if the |
| 829 | * powerdomain does not support LOWPOWERSTATECHANGE, or returns 0 |
| 830 | * upon success. |
| 831 | */ |
| 832 | int pwrdm_set_lowpwrstchange(struct powerdomain *pwrdm) |
| 833 | { |
Rajendra Nayak | 9b7fc90 | 2010-12-21 20:01:19 -0700 | [diff] [blame^] | 834 | int ret = -EINVAL; |
| 835 | |
Rajendra Nayak | 90dbc7b | 2010-05-18 20:24:03 -0600 | [diff] [blame] | 836 | if (!pwrdm) |
| 837 | return -EINVAL; |
| 838 | |
| 839 | if (!(pwrdm->flags & PWRDM_HAS_LOWPOWERSTATECHANGE)) |
| 840 | return -EINVAL; |
| 841 | |
| 842 | pr_debug("powerdomain: %s: setting LOWPOWERSTATECHANGE bit\n", |
| 843 | pwrdm->name); |
| 844 | |
Rajendra Nayak | 9b7fc90 | 2010-12-21 20:01:19 -0700 | [diff] [blame^] | 845 | if (arch_pwrdm && arch_pwrdm->pwrdm_set_lowpwrstchange) |
| 846 | ret = arch_pwrdm->pwrdm_set_lowpwrstchange(pwrdm); |
Rajendra Nayak | 90dbc7b | 2010-05-18 20:24:03 -0600 | [diff] [blame] | 847 | |
Rajendra Nayak | 9b7fc90 | 2010-12-21 20:01:19 -0700 | [diff] [blame^] | 848 | return ret; |
Rajendra Nayak | 90dbc7b | 2010-05-18 20:24:03 -0600 | [diff] [blame] | 849 | } |
| 850 | |
| 851 | /** |
Paul Walmsley | ad67ef6 | 2008-08-19 11:08:40 +0300 | [diff] [blame] | 852 | * pwrdm_wait_transition - wait for powerdomain power transition to finish |
| 853 | * @pwrdm: struct powerdomain * to wait for |
| 854 | * |
Paul Walmsley | f0271d6 | 2010-01-26 20:13:02 -0700 | [diff] [blame] | 855 | * If the powerdomain @pwrdm is in the process of a state transition, |
Paul Walmsley | ad67ef6 | 2008-08-19 11:08:40 +0300 | [diff] [blame] | 856 | * spin until it completes the power transition, or until an iteration |
| 857 | * bailout value is reached. Returns -EINVAL if the powerdomain |
| 858 | * pointer is null, -EAGAIN if the bailout value was reached, or |
| 859 | * returns 0 upon success. |
| 860 | */ |
| 861 | int pwrdm_wait_transition(struct powerdomain *pwrdm) |
| 862 | { |
Rajendra Nayak | 9b7fc90 | 2010-12-21 20:01:19 -0700 | [diff] [blame^] | 863 | int ret = -EINVAL; |
Paul Walmsley | ad67ef6 | 2008-08-19 11:08:40 +0300 | [diff] [blame] | 864 | |
| 865 | if (!pwrdm) |
| 866 | return -EINVAL; |
| 867 | |
Rajendra Nayak | 9b7fc90 | 2010-12-21 20:01:19 -0700 | [diff] [blame^] | 868 | if (arch_pwrdm && arch_pwrdm->pwrdm_wait_transition) |
| 869 | ret = arch_pwrdm->pwrdm_wait_transition(pwrdm); |
Paul Walmsley | ad67ef6 | 2008-08-19 11:08:40 +0300 | [diff] [blame] | 870 | |
Rajendra Nayak | 9b7fc90 | 2010-12-21 20:01:19 -0700 | [diff] [blame^] | 871 | return ret; |
Paul Walmsley | ad67ef6 | 2008-08-19 11:08:40 +0300 | [diff] [blame] | 872 | } |
| 873 | |
Peter 'p2' De Schrijver | ba20bb1 | 2008-10-15 17:48:43 +0300 | [diff] [blame] | 874 | int pwrdm_state_switch(struct powerdomain *pwrdm) |
| 875 | { |
| 876 | return _pwrdm_state_switch(pwrdm, PWRDM_STATE_NOW); |
| 877 | } |
| 878 | |
| 879 | int pwrdm_clkdm_state_switch(struct clockdomain *clkdm) |
| 880 | { |
| 881 | if (clkdm != NULL && clkdm->pwrdm.ptr != NULL) { |
| 882 | pwrdm_wait_transition(clkdm->pwrdm.ptr); |
| 883 | return pwrdm_state_switch(clkdm->pwrdm.ptr); |
| 884 | } |
| 885 | |
| 886 | return -EINVAL; |
| 887 | } |
Peter 'p2' De Schrijver | ba20bb1 | 2008-10-15 17:48:43 +0300 | [diff] [blame] | 888 | |
| 889 | int pwrdm_pre_transition(void) |
| 890 | { |
Peter 'p2' De Schrijver | 6199ab2 | 2008-10-15 18:13:49 +0300 | [diff] [blame] | 891 | pwrdm_for_each(_pwrdm_pre_transition_cb, NULL); |
Peter 'p2' De Schrijver | ba20bb1 | 2008-10-15 17:48:43 +0300 | [diff] [blame] | 892 | return 0; |
| 893 | } |
| 894 | |
| 895 | int pwrdm_post_transition(void) |
| 896 | { |
Peter 'p2' De Schrijver | 6199ab2 | 2008-10-15 18:13:49 +0300 | [diff] [blame] | 897 | pwrdm_for_each(_pwrdm_post_transition_cb, NULL); |
Peter 'p2' De Schrijver | ba20bb1 | 2008-10-15 17:48:43 +0300 | [diff] [blame] | 898 | return 0; |
| 899 | } |