blob: 3aa3eb3354165de03374d7d593efff22e8617c9a [file] [log] [blame]
Paul Walmsleyad67ef62008-08-19 11:08:40 +03001/*
2 * OMAP powerdomain control
3 *
4 * Copyright (C) 2007-2008 Texas Instruments, Inc.
Paul Walmsley55ed9692010-01-26 20:12:59 -07005 * Copyright (C) 2007-2009 Nokia Corporation
Paul Walmsleyad67ef62008-08-19 11:08:40 +03006 *
7 * Written by Paul Walmsley
Abhijit Pagare3a759f02010-01-26 20:12:53 -07008 * Added OMAP4 specific support by Abhijit Pagare <abhijitpagare@ti.com>
Paul Walmsley4788da22010-05-18 20:24:05 -06009 * State counting code by Tero Kristo <tero.kristo@nokia.com>
Abhijit Pagare3a759f02010-01-26 20:12:53 -070010 *
Paul Walmsleyad67ef62008-08-19 11:08:40 +030011 * 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 Walmsley33903eb2009-12-08 16:33:10 -070015#undef DEBUG
Paul Walmsleyad67ef62008-08-19 11:08:40 +030016
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 Pagare3a759f02010-01-26 20:12:53 -070031#include "cm-regbits-44xx.h"
Paul Walmsleyad67ef62008-08-19 11:08:40 +030032#include "prm.h"
33#include "prm-regbits-34xx.h"
Abhijit Pagare3a759f02010-01-26 20:12:53 -070034#include "prm-regbits-44xx.h"
Paul Walmsleyad67ef62008-08-19 11:08:40 +030035
Tony Lindgrence491cf2009-10-20 09:40:47 -070036#include <plat/cpu.h>
37#include <plat/powerdomain.h>
38#include <plat/clockdomain.h>
Paul Walmsley55ed9692010-01-26 20:12:59 -070039#include <plat/prcm.h>
Paul Walmsleyad67ef62008-08-19 11:08:40 +030040
Peter 'p2' De Schrijver6199ab22008-10-15 18:13:49 +030041#include "pm.h"
42
Peter 'p2' De Schrijverba20bb12008-10-15 17:48:43 +030043enum {
44 PWRDM_STATE_NOW = 0,
45 PWRDM_STATE_PREV,
46};
47
Abhijit Pagare3a759f02010-01-26 20:12:53 -070048/* Variable holding value of the CPU dependent PWRSTCTRL Register Offset */
49static u16 pwrstctrl_reg_offs;
50
51/* Variable holding value of the CPU dependent PWRSTST Register Offset */
52static 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 Walmsley2bc4ef72010-05-18 18:47:24 -060067#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 Pagare3a759f02010-01-26 20:12:53 -070071#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 Walmsleyad67ef62008-08-19 11:08:40 +030080/* pwrdm_list contains all registered struct powerdomains */
81static LIST_HEAD(pwrdm_list);
82
Rajendra Nayak3b1e8b22010-12-21 20:01:18 -070083static struct pwrdm_ops *arch_pwrdm;
84
Paul Walmsleyad67ef62008-08-19 11:08:40 +030085/* Private functions */
86
Paul Walmsleyad67ef62008-08-19 11:08:40 +030087static 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 Walmsleye909d62a82010-01-26 20:13:00 -0700103/**
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 */
111static 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 Walmsleycf57aa72010-01-26 20:13:01 -0700127 for (i = 0; i < PWRDM_MAX_PWRSTS; i++)
Paul Walmsleye909d62a82010-01-26 20:13:00 -0700128 pwrdm->state_counter[i] = 0;
129
Thara Gopinathcde08f82010-02-24 12:05:50 -0700130 pwrdm->ret_logic_off_counter = 0;
131 for (i = 0; i < pwrdm->banks; i++)
132 pwrdm->ret_mem_off_counter[i] = 0;
133
Paul Walmsleye909d62a82010-01-26 20:13:00 -0700134 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 Gopinathcde08f82010-02-24 12:05:50 -0700143static 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 Schrijverba20bb12008-10-15 17:48:43 +0300162static 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 Gopinathcde08f82010-02-24 12:05:50 -0700181 if (prev == PWRDM_POWER_RET)
182 _update_logic_membank_counters(pwrdm);
Peter 'p2' De Schrijverba20bb12008-10-15 17:48:43 +0300183 break;
184 default:
185 return -EINVAL;
186 }
187
188 if (state != prev)
189 pwrdm->state_counter[state]++;
190
Peter 'p2' De Schrijver6199ab22008-10-15 18:13:49 +0300191 pm_dbg_update_time(pwrdm, prev);
192
Peter 'p2' De Schrijverba20bb12008-10-15 17:48:43 +0300193 pwrdm->state = state;
194
195 return 0;
196}
197
Peter 'p2' De Schrijver6199ab22008-10-15 18:13:49 +0300198static int _pwrdm_pre_transition_cb(struct powerdomain *pwrdm, void *unused)
Peter 'p2' De Schrijverba20bb12008-10-15 17:48:43 +0300199{
200 pwrdm_clear_all_prev_pwrst(pwrdm);
201 _pwrdm_state_switch(pwrdm, PWRDM_STATE_NOW);
202 return 0;
203}
204
Peter 'p2' De Schrijver6199ab22008-10-15 18:13:49 +0300205static int _pwrdm_post_transition_cb(struct powerdomain *pwrdm, void *unused)
Peter 'p2' De Schrijverba20bb12008-10-15 17:48:43 +0300206{
207 _pwrdm_state_switch(pwrdm, PWRDM_STATE_PREV);
208 return 0;
209}
210
Paul Walmsleyad67ef62008-08-19 11:08:40 +0300211/* Public functions */
212
213/**
214 * pwrdm_init - set up the powerdomain layer
Paul Walmsleyf0271d62010-01-26 20:13:02 -0700215 * @pwrdm_list: array of struct powerdomain pointers to register
Rajendra Nayak3b1e8b22010-12-21 20:01:18 -0700216 * @custom_funcs: func pointers for arch specfic implementations
Paul Walmsleyad67ef62008-08-19 11:08:40 +0300217 *
Paul Walmsleyf0271d62010-01-26 20:13:02 -0700218 * 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 Walmsleyad67ef62008-08-19 11:08:40 +0300223 */
Rajendra Nayak3b1e8b22010-12-21 20:01:18 -0700224void pwrdm_init(struct powerdomain **pwrdm_list, struct pwrdm_ops *custom_funcs)
Paul Walmsleyad67ef62008-08-19 11:08:40 +0300225{
226 struct powerdomain **p = NULL;
227
Rajendra Nayak766d3052010-03-31 04:16:30 -0600228 if (cpu_is_omap24xx() || cpu_is_omap34xx()) {
Abhijit Pagare3a759f02010-01-26 20:12:53 -0700229 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 Nayak3b1e8b22010-12-21 20:01:18 -0700240 if (!custom_funcs)
241 WARN(1, "powerdomain: No custom pwrdm functions registered\n");
242 else
243 arch_pwrdm = custom_funcs;
244
Peter 'p2' De Schrijverba20bb12008-10-15 17:48:43 +0300245 if (pwrdm_list) {
Paul Walmsleye909d62a82010-01-26 20:13:00 -0700246 for (p = pwrdm_list; *p; p++)
247 _pwrdm_register(*p);
Peter 'p2' De Schrijverba20bb12008-10-15 17:48:43 +0300248 }
Paul Walmsleyad67ef62008-08-19 11:08:40 +0300249}
250
251/**
Paul Walmsleyad67ef62008-08-19 11:08:40 +0300252 * pwrdm_lookup - look up a powerdomain by name, return a pointer
253 * @name: name of powerdomain
254 *
Paul Walmsleyf0271d62010-01-26 20:13:02 -0700255 * Find a registered powerdomain by its name @name. Returns a pointer
256 * to the struct powerdomain if found, or NULL otherwise.
Paul Walmsleyad67ef62008-08-19 11:08:40 +0300257 */
258struct powerdomain *pwrdm_lookup(const char *name)
259{
260 struct powerdomain *pwrdm;
Paul Walmsleyad67ef62008-08-19 11:08:40 +0300261
262 if (!name)
263 return NULL;
264
Paul Walmsleyad67ef62008-08-19 11:08:40 +0300265 pwrdm = _pwrdm_lookup(name);
Paul Walmsleyad67ef62008-08-19 11:08:40 +0300266
267 return pwrdm;
268}
269
270/**
Paul Walmsleye909d62a82010-01-26 20:13:00 -0700271 * pwrdm_for_each - call function on each registered clockdomain
Paul Walmsleyad67ef62008-08-19 11:08:40 +0300272 * @fn: callback function *
273 *
Paul Walmsleyf0271d62010-01-26 20:13:02 -0700274 * 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 Walmsleyad67ef62008-08-19 11:08:40 +0300279 */
Paul Walmsleye909d62a82010-01-26 20:13:00 -0700280int pwrdm_for_each(int (*fn)(struct powerdomain *pwrdm, void *user),
281 void *user)
Paul Walmsleyad67ef62008-08-19 11:08:40 +0300282{
283 struct powerdomain *temp_pwrdm;
Paul Walmsleyad67ef62008-08-19 11:08:40 +0300284 int ret = 0;
285
286 if (!fn)
287 return -EINVAL;
288
Paul Walmsleyad67ef62008-08-19 11:08:40 +0300289 list_for_each_entry(temp_pwrdm, &pwrdm_list, node) {
Peter 'p2' De Schrijver6199ab22008-10-15 18:13:49 +0300290 ret = (*fn)(temp_pwrdm, user);
Paul Walmsleyad67ef62008-08-19 11:08:40 +0300291 if (ret)
292 break;
293 }
Artem Bityutskiyee894b12009-10-01 10:01:55 +0300294
295 return ret;
296}
297
298/**
Paul Walmsley8420bb12008-08-19 11:08:44 +0300299 * 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 Walmsleyf0271d62010-01-26 20:13:02 -0700303 * Associate the clockdomain @clkdm with a powerdomain @pwrdm. This
Paul Walmsley8420bb12008-08-19 11:08:44 +0300304 * 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 */
308int pwrdm_add_clkdm(struct powerdomain *pwrdm, struct clockdomain *clkdm)
309{
Paul Walmsley8420bb12008-08-19 11:08:44 +0300310 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 Walmsley8420bb12008-08-19 11:08:44 +0300319 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
342pac_exit:
Paul Walmsley8420bb12008-08-19 11:08:44 +0300343 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 Walmsleyf0271d62010-01-26 20:13:02 -0700351 * 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 Walmsley8420bb12008-08-19 11:08:44 +0300355 */
356int pwrdm_del_clkdm(struct powerdomain *pwrdm, struct clockdomain *clkdm)
357{
Paul Walmsley8420bb12008-08-19 11:08:44 +0300358 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 Walmsley8420bb12008-08-19 11:08:44 +0300367 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
382pdc_exit:
Paul Walmsley8420bb12008-08-19 11:08:44 +0300383 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 Walmsleyf0271d62010-01-26 20:13:02 -0700391 * Call the supplied function @fn for each clockdomain in the powerdomain
392 * @pwrdm. The callback function can return anything but 0 to bail
Paul Walmsleye909d62a82010-01-26 20:13:00 -0700393 * 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 Walmsley8420bb12008-08-19 11:08:44 +0300397 */
398int pwrdm_for_each_clkdm(struct powerdomain *pwrdm,
399 int (*fn)(struct powerdomain *pwrdm,
400 struct clockdomain *clkdm))
401{
Paul Walmsley8420bb12008-08-19 11:08:44 +0300402 int ret = 0;
403 int i;
404
405 if (!fn)
406 return -EINVAL;
407
Paul Walmsley8420bb12008-08-19 11:08:44 +0300408 for (i = 0; i < PWRDM_MAX_CLKDMS && !ret; i++)
409 ret = (*fn)(pwrdm, pwrdm->pwrdm_clkdms[i]);
410
Paul Walmsley8420bb12008-08-19 11:08:44 +0300411 return ret;
412}
413
Paul Walmsleyad67ef62008-08-19 11:08:40 +0300414/**
415 * pwrdm_get_mem_bank_count - get number of memory banks in this powerdomain
416 * @pwrdm: struct powerdomain *
417 *
Paul Walmsleyf0271d62010-01-26 20:13:02 -0700418 * Return the number of controllable memory banks in powerdomain @pwrdm,
Paul Walmsleyad67ef62008-08-19 11:08:40 +0300419 * starting with 1. Returns -EINVAL if the powerdomain pointer is null.
420 */
421int 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 Walmsleyf0271d62010-01-26 20:13:02 -0700434 * Set the powerdomain @pwrdm's next power state to @pwrst. The powerdomain
Paul Walmsleyad67ef62008-08-19 11:08:40 +0300435 * 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 */
440int 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 Pagare3a759f02010-01-26 20:12:53 -0700453 pwrdm->prcm_offs, pwrstctrl_reg_offs);
Paul Walmsleyad67ef62008-08-19 11:08:40 +0300454
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 Walmsleyf0271d62010-01-26 20:13:02 -0700462 * Return the powerdomain @pwrdm's next power state. Returns -EINVAL
Paul Walmsleyad67ef62008-08-19 11:08:40 +0300463 * if the powerdomain pointer is null or returns the next power state
464 * upon success.
465 */
466int pwrdm_read_next_pwrst(struct powerdomain *pwrdm)
467{
468 if (!pwrdm)
469 return -EINVAL;
470
Abhijit Pagare3a759f02010-01-26 20:12:53 -0700471 return prm_read_mod_bits_shift(pwrdm->prcm_offs,
472 pwrstctrl_reg_offs, OMAP_POWERSTATE_MASK);
Paul Walmsleyad67ef62008-08-19 11:08:40 +0300473}
474
475/**
476 * pwrdm_read_pwrst - get current powerdomain power state
477 * @pwrdm: struct powerdomain * to get power state
478 *
Paul Walmsleyf0271d62010-01-26 20:13:02 -0700479 * Return the powerdomain @pwrdm's current power state. Returns -EINVAL
Paul Walmsleyad67ef62008-08-19 11:08:40 +0300480 * if the powerdomain pointer is null or returns the current power state
481 * upon success.
482 */
483int pwrdm_read_pwrst(struct powerdomain *pwrdm)
484{
485 if (!pwrdm)
486 return -EINVAL;
487
Abhijit Pagare3a759f02010-01-26 20:12:53 -0700488 return prm_read_mod_bits_shift(pwrdm->prcm_offs,
489 pwrstst_reg_offs, OMAP_POWERSTATEST_MASK);
Paul Walmsleyad67ef62008-08-19 11:08:40 +0300490}
491
492/**
493 * pwrdm_read_prev_pwrst - get previous powerdomain power state
494 * @pwrdm: struct powerdomain * to get previous power state
495 *
Paul Walmsleyf0271d62010-01-26 20:13:02 -0700496 * Return the powerdomain @pwrdm's previous power state. Returns -EINVAL
Paul Walmsleyad67ef62008-08-19 11:08:40 +0300497 * if the powerdomain pointer is null or returns the previous power state
498 * upon success.
499 */
500int 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 Walmsleyf0271d62010-01-26 20:13:02 -0700514 * 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 Walmsleyad67ef62008-08-19 11:08:40 +0300519 */
520int pwrdm_set_logic_retst(struct powerdomain *pwrdm, u8 pwrst)
521{
Paul Walmsley2bc4ef72010-05-18 18:47:24 -0600522 u32 v;
523
Paul Walmsleyad67ef62008-08-19 11:08:40 +0300524 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 Walmsley2bc4ef72010-05-18 18:47:24 -0600539 v = pwrst << __ffs(OMAP3430_LOGICL1CACHERETSTATE_MASK);
540 prm_rmw_mod_reg_bits(OMAP3430_LOGICL1CACHERETSTATE_MASK, v,
541 pwrdm->prcm_offs, pwrstctrl_reg_offs);
Paul Walmsleyad67ef62008-08-19 11:08:40 +0300542
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 Walmsleyf0271d62010-01-26 20:13:02 -0700552 * 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 Walmsleyad67ef62008-08-19 11:08:40 +0300560 */
561int 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 Pagare3a759f02010-01-26 20:12:53 -0700585 m = OMAP_MEM0_ONSTATE_MASK;
Paul Walmsleyad67ef62008-08-19 11:08:40 +0300586 break;
587 case 1:
Abhijit Pagare3a759f02010-01-26 20:12:53 -0700588 m = OMAP_MEM1_ONSTATE_MASK;
Paul Walmsleyad67ef62008-08-19 11:08:40 +0300589 break;
590 case 2:
Abhijit Pagare3a759f02010-01-26 20:12:53 -0700591 m = OMAP_MEM2_ONSTATE_MASK;
Paul Walmsleyad67ef62008-08-19 11:08:40 +0300592 break;
593 case 3:
Abhijit Pagare3a759f02010-01-26 20:12:53 -0700594 m = OMAP_MEM3_ONSTATE_MASK;
595 break;
596 case 4:
597 m = OMAP_MEM4_ONSTATE_MASK;
Paul Walmsleyad67ef62008-08-19 11:08:40 +0300598 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 Pagare3a759f02010-01-26 20:12:53 -0700605 pwrdm->prcm_offs, pwrstctrl_reg_offs);
Paul Walmsleyad67ef62008-08-19 11:08:40 +0300606
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 Walmsleyf0271d62010-01-26 20:13:02 -0700616 * 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 Walmsleyad67ef62008-08-19 11:08:40 +0300625 */
626int 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 Pagare3a759f02010-01-26 20:12:53 -0700650 m = OMAP_MEM0_RETSTATE_MASK;
Paul Walmsleyad67ef62008-08-19 11:08:40 +0300651 break;
652 case 1:
Abhijit Pagare3a759f02010-01-26 20:12:53 -0700653 m = OMAP_MEM1_RETSTATE_MASK;
Paul Walmsleyad67ef62008-08-19 11:08:40 +0300654 break;
655 case 2:
Abhijit Pagare3a759f02010-01-26 20:12:53 -0700656 m = OMAP_MEM2_RETSTATE_MASK;
Paul Walmsleyad67ef62008-08-19 11:08:40 +0300657 break;
658 case 3:
Abhijit Pagare3a759f02010-01-26 20:12:53 -0700659 m = OMAP_MEM3_RETSTATE_MASK;
660 break;
661 case 4:
662 m = OMAP_MEM4_RETSTATE_MASK;
Paul Walmsleyad67ef62008-08-19 11:08:40 +0300663 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 Pagare3a759f02010-01-26 20:12:53 -0700670 pwrstctrl_reg_offs);
Paul Walmsleyad67ef62008-08-19 11:08:40 +0300671
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 Walmsleyf0271d62010-01-26 20:13:02 -0700679 * 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 Walmsleyad67ef62008-08-19 11:08:40 +0300683 */
684int pwrdm_read_logic_pwrst(struct powerdomain *pwrdm)
685{
686 if (!pwrdm)
687 return -EINVAL;
688
Paul Walmsley2bc4ef72010-05-18 18:47:24 -0600689 return prm_read_mod_bits_shift(pwrdm->prcm_offs, pwrstst_reg_offs,
690 OMAP3430_LOGICSTATEST_MASK);
Paul Walmsleyad67ef62008-08-19 11:08:40 +0300691}
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 Walmsleyf0271d62010-01-26 20:13:02 -0700697 * 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 Walmsleyad67ef62008-08-19 11:08:40 +0300700 */
701int 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 Walmsley2bc4ef72010-05-18 18:47:24 -0600713 OMAP3430_LASTLOGICSTATEENTERED_MASK);
Paul Walmsleyad67ef62008-08-19 11:08:40 +0300714}
715
716/**
Thara Gopinath1e3d0d22010-02-24 12:05:49 -0700717 * 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 */
724int 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 Walmsley2bc4ef72010-05-18 18:47:24 -0600736 OMAP3430_LOGICSTATEST_MASK);
Thara Gopinath1e3d0d22010-02-24 12:05:49 -0700737}
738
739/**
Paul Walmsleyad67ef62008-08-19 11:08:40 +0300740 * 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 Walmsleyf0271d62010-01-26 20:13:02 -0700744 * Return the powerdomain @pwrdm's current memory power state for bank
745 * @bank. Returns -EINVAL if the powerdomain pointer is null, -EEXIST if
Paul Walmsleyad67ef62008-08-19 11:08:40 +0300746 * the target memory bank does not exist or is not controllable, or
747 * returns the current memory power state upon success.
748 */
749int 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 Gopinath3863c742009-12-08 16:33:15 -0700759 if (pwrdm->flags & PWRDM_HAS_MPU_QUIRK)
760 bank = 1;
761
Paul Walmsleyad67ef62008-08-19 11:08:40 +0300762 /*
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 Pagare3a759f02010-01-26 20:12:53 -0700770 m = OMAP_MEM0_STATEST_MASK;
Paul Walmsleyad67ef62008-08-19 11:08:40 +0300771 break;
772 case 1:
Abhijit Pagare3a759f02010-01-26 20:12:53 -0700773 m = OMAP_MEM1_STATEST_MASK;
Paul Walmsleyad67ef62008-08-19 11:08:40 +0300774 break;
775 case 2:
Abhijit Pagare3a759f02010-01-26 20:12:53 -0700776 m = OMAP_MEM2_STATEST_MASK;
Paul Walmsleyad67ef62008-08-19 11:08:40 +0300777 break;
778 case 3:
Abhijit Pagare3a759f02010-01-26 20:12:53 -0700779 m = OMAP_MEM3_STATEST_MASK;
780 break;
781 case 4:
782 m = OMAP_MEM4_STATEST_MASK;
Paul Walmsleyad67ef62008-08-19 11:08:40 +0300783 break;
784 default:
785 WARN_ON(1); /* should never happen */
786 return -EEXIST;
787 }
788
Abhijit Pagare3a759f02010-01-26 20:12:53 -0700789 return prm_read_mod_bits_shift(pwrdm->prcm_offs,
790 pwrstst_reg_offs, m);
Paul Walmsleyad67ef62008-08-19 11:08:40 +0300791}
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 Walmsleyf0271d62010-01-26 20:13:02 -0700798 * 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 Walmsleyad67ef62008-08-19 11:08:40 +0300803 */
804int 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 Gopinath3863c742009-12-08 16:33:15 -0700814 if (pwrdm->flags & PWRDM_HAS_MPU_QUIRK)
815 bank = 1;
816
Paul Walmsleyad67ef62008-08-19 11:08:40 +0300817 /*
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 Gopinath1e3d0d22010-02-24 12:05:49 -0700846 * 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 */
855int 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 Weber047b51f2010-07-09 07:40:53 +0000886 break;
Thara Gopinath1e3d0d22010-02-24 12:05:49 -0700887 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 Walmsleyad67ef62008-08-19 11:08:40 +0300897 * pwrdm_clear_all_prev_pwrst - clear previous powerstate register for a pwrdm
898 * @pwrdm: struct powerdomain * to clear
899 *
Paul Walmsleyf0271d62010-01-26 20:13:02 -0700900 * 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 Walmsleyad67ef62008-08-19 11:08:40 +0300904 */
905int 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 Walmsley0b7cbfb2008-06-25 18:09:37 -0600924 * 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 Walmsleyf0271d62010-01-26 20:13:02 -0700928 * 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 Walmsley0b7cbfb2008-06-25 18:09:37 -0600933 */
934int 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 Pagare3a759f02010-01-26 20:12:53 -0700946 pwrdm->prcm_offs, pwrstctrl_reg_offs);
Paul Walmsley0b7cbfb2008-06-25 18:09:37 -0600947
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 Walmsleyf0271d62010-01-26 20:13:02 -0700956 * 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 Walmsley0b7cbfb2008-06-25 18:09:37 -0600961 */
962int 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 Pagare3a759f02010-01-26 20:12:53 -0700974 pwrdm->prcm_offs, pwrstctrl_reg_offs);
Paul Walmsley0b7cbfb2008-06-25 18:09:37 -0600975
976 return 0;
977}
978
979/**
980 * pwrdm_has_hdwr_sar - test whether powerdomain supports hardware SAR
981 * @pwrdm: struct powerdomain *
982 *
Paul Walmsleyf0271d62010-01-26 20:13:02 -0700983 * Returns 1 if powerdomain @pwrdm supports hardware save-and-restore
Paul Walmsley0b7cbfb2008-06-25 18:09:37 -0600984 * for some devices, or 0 if it does not.
985 */
986bool pwrdm_has_hdwr_sar(struct powerdomain *pwrdm)
987{
988 return (pwrdm && pwrdm->flags & PWRDM_HAS_HDWR_SAR) ? 1 : 0;
989}
990
991/**
Rajendra Nayak90dbc7b2010-05-18 20:24:03 -0600992 * 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 */
1001int 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 Walmsleyad67ef62008-08-19 11:08:40 +03001020 * pwrdm_wait_transition - wait for powerdomain power transition to finish
1021 * @pwrdm: struct powerdomain * to wait for
1022 *
Paul Walmsleyf0271d62010-01-26 20:13:02 -07001023 * If the powerdomain @pwrdm is in the process of a state transition,
Paul Walmsleyad67ef62008-08-19 11:08:40 +03001024 * 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 */
1029int 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 Pagare3a759f02010-01-26 20:12:53 -07001043 while ((prm_read_mod_reg(pwrdm->prcm_offs, pwrstst_reg_offs) &
Paul Walmsley2fd0f752010-05-18 18:40:23 -06001044 OMAP_INTRANSITION_MASK) &&
Paul Walmsleyad67ef62008-08-19 11:08:40 +03001045 (c++ < PWRDM_TRANSITION_BAILOUT))
Abhijit Pagare3a759f02010-01-26 20:12:53 -07001046 udelay(1);
Paul Walmsleyad67ef62008-08-19 11:08:40 +03001047
Roel Kluin26870692009-06-19 19:08:30 -06001048 if (c > PWRDM_TRANSITION_BAILOUT) {
Paul Walmsleyad67ef62008-08-19 11:08:40 +03001049 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 Schrijverba20bb12008-10-15 17:48:43 +03001059int pwrdm_state_switch(struct powerdomain *pwrdm)
1060{
1061 return _pwrdm_state_switch(pwrdm, PWRDM_STATE_NOW);
1062}
1063
1064int 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 Schrijverba20bb12008-10-15 17:48:43 +03001073
1074int pwrdm_pre_transition(void)
1075{
Peter 'p2' De Schrijver6199ab22008-10-15 18:13:49 +03001076 pwrdm_for_each(_pwrdm_pre_transition_cb, NULL);
Peter 'p2' De Schrijverba20bb12008-10-15 17:48:43 +03001077 return 0;
1078}
1079
1080int pwrdm_post_transition(void)
1081{
Peter 'p2' De Schrijver6199ab22008-10-15 18:13:49 +03001082 pwrdm_for_each(_pwrdm_post_transition_cb, NULL);
Peter 'p2' De Schrijverba20bb12008-10-15 17:48:43 +03001083 return 0;
1084}