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