2 * OMAP powerdomain control
4 * Copyright (C) 2007-2008 Texas Instruments, Inc.
5 * Copyright (C) 2007-2009 Nokia Corporation
7 * Written by Paul Walmsley
8 * Added OMAP4 specific support by Abhijit Pagare <abhijitpagare@ti.com>
9 * State counting code by Tero Kristo <tero.kristo@nokia.com>
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.
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>
27 #include <asm/atomic.h>
30 #include "cm-regbits-34xx.h"
31 #include "cm-regbits-44xx.h"
33 #include "prm-regbits-34xx.h"
34 #include "prm-regbits-44xx.h"
37 #include <plat/powerdomain.h>
38 #include <plat/clockdomain.h>
39 #include <plat/prcm.h>
48 /* Variable holding value of the CPU dependent PWRSTCTRL Register Offset */
49 static u16 pwrstctrl_reg_offs
;
51 /* Variable holding value of the CPU dependent PWRSTST Register Offset */
52 static u16 pwrstst_reg_offs
;
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
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
66 /* OMAP3 and OMAP4 Memory Retstate Masks (common across all power domains) */
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
71 #define OMAP_MEM4_RETSTATE_MASK OMAP4430_OCP_NRET_BANK_RETSTATE_MASK
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
80 /* pwrdm_list contains all registered struct powerdomains */
81 static LIST_HEAD(pwrdm_list
);
83 /* Private functions */
85 static struct powerdomain
*_pwrdm_lookup(const char *name
)
87 struct powerdomain
*pwrdm
, *temp_pwrdm
;
91 list_for_each_entry(temp_pwrdm
, &pwrdm_list
, node
) {
92 if (!strcmp(name
, temp_pwrdm
->name
)) {
102 * _pwrdm_register - register a powerdomain
103 * @pwrdm: struct powerdomain * to register
105 * Adds a powerdomain to the internal powerdomain list. Returns
106 * -EINVAL if given a null pointer, -EEXIST if a powerdomain is
107 * already registered by the provided name, or 0 upon success.
109 static int _pwrdm_register(struct powerdomain
*pwrdm
)
116 if (!omap_chip_is(pwrdm
->omap_chip
))
119 if (_pwrdm_lookup(pwrdm
->name
))
122 list_add(&pwrdm
->node
, &pwrdm_list
);
124 /* Initialize the powerdomain's state counter */
125 for (i
= 0; i
< PWRDM_MAX_PWRSTS
; i
++)
126 pwrdm
->state_counter
[i
] = 0;
128 pwrdm
->ret_logic_off_counter
= 0;
129 for (i
= 0; i
< pwrdm
->banks
; i
++)
130 pwrdm
->ret_mem_off_counter
[i
] = 0;
132 pwrdm_wait_transition(pwrdm
);
133 pwrdm
->state
= pwrdm_read_pwrst(pwrdm
);
134 pwrdm
->state_counter
[pwrdm
->state
] = 1;
136 pr_debug("powerdomain: registered %s\n", pwrdm
->name
);
141 static void _update_logic_membank_counters(struct powerdomain
*pwrdm
)
144 u8 prev_logic_pwrst
, prev_mem_pwrst
;
146 prev_logic_pwrst
= pwrdm_read_prev_logic_pwrst(pwrdm
);
147 if ((pwrdm
->pwrsts_logic_ret
== PWRSTS_OFF_RET
) &&
148 (prev_logic_pwrst
== PWRDM_POWER_OFF
))
149 pwrdm
->ret_logic_off_counter
++;
151 for (i
= 0; i
< pwrdm
->banks
; i
++) {
152 prev_mem_pwrst
= pwrdm_read_prev_mem_pwrst(pwrdm
, i
);
154 if ((pwrdm
->pwrsts_mem_ret
[i
] == PWRSTS_OFF_RET
) &&
155 (prev_mem_pwrst
== PWRDM_POWER_OFF
))
156 pwrdm
->ret_mem_off_counter
[i
]++;
160 static int _pwrdm_state_switch(struct powerdomain
*pwrdm
, int flag
)
169 state
= pwrdm_read_pwrst(pwrdm
);
172 case PWRDM_STATE_NOW
:
175 case PWRDM_STATE_PREV
:
176 prev
= pwrdm_read_prev_pwrst(pwrdm
);
177 if (pwrdm
->state
!= prev
)
178 pwrdm
->state_counter
[prev
]++;
179 if (prev
== PWRDM_POWER_RET
)
180 _update_logic_membank_counters(pwrdm
);
187 pwrdm
->state_counter
[state
]++;
189 pm_dbg_update_time(pwrdm
, prev
);
191 pwrdm
->state
= state
;
196 static int _pwrdm_pre_transition_cb(struct powerdomain
*pwrdm
, void *unused
)
198 pwrdm_clear_all_prev_pwrst(pwrdm
);
199 _pwrdm_state_switch(pwrdm
, PWRDM_STATE_NOW
);
203 static int _pwrdm_post_transition_cb(struct powerdomain
*pwrdm
, void *unused
)
205 _pwrdm_state_switch(pwrdm
, PWRDM_STATE_PREV
);
209 /* Public functions */
212 * pwrdm_init - set up the powerdomain layer
213 * @pwrdm_list: array of struct powerdomain pointers to register
215 * Loop through the array of powerdomains @pwrdm_list, registering all
216 * that are available on the current CPU. If pwrdm_list is supplied
217 * and not null, all of the referenced powerdomains will be
218 * registered. No return value. XXX pwrdm_list is not really a
219 * "list"; it is an array. Rename appropriately.
221 void pwrdm_init(struct powerdomain
**pwrdm_list
)
223 struct powerdomain
**p
= NULL
;
225 if (cpu_is_omap24xx() || cpu_is_omap34xx()) {
226 pwrstctrl_reg_offs
= OMAP2_PM_PWSTCTRL
;
227 pwrstst_reg_offs
= OMAP2_PM_PWSTST
;
228 } else if (cpu_is_omap44xx()) {
229 pwrstctrl_reg_offs
= OMAP4_PM_PWSTCTRL
;
230 pwrstst_reg_offs
= OMAP4_PM_PWSTST
;
232 printk(KERN_ERR
"Power Domain struct not supported for " \
238 for (p
= pwrdm_list
; *p
; p
++)
244 * pwrdm_lookup - look up a powerdomain by name, return a pointer
245 * @name: name of powerdomain
247 * Find a registered powerdomain by its name @name. Returns a pointer
248 * to the struct powerdomain if found, or NULL otherwise.
250 struct powerdomain
*pwrdm_lookup(const char *name
)
252 struct powerdomain
*pwrdm
;
257 pwrdm
= _pwrdm_lookup(name
);
263 * pwrdm_for_each - call function on each registered clockdomain
264 * @fn: callback function *
266 * Call the supplied function @fn for each registered powerdomain.
267 * The callback function @fn can return anything but 0 to bail out
268 * early from the iterator. Returns the last return value of the
269 * callback function, which should be 0 for success or anything else
270 * to indicate failure; or -EINVAL if the function pointer is null.
272 int pwrdm_for_each(int (*fn
)(struct powerdomain
*pwrdm
, void *user
),
275 struct powerdomain
*temp_pwrdm
;
281 list_for_each_entry(temp_pwrdm
, &pwrdm_list
, node
) {
282 ret
= (*fn
)(temp_pwrdm
, user
);
291 * pwrdm_add_clkdm - add a clockdomain to a powerdomain
292 * @pwrdm: struct powerdomain * to add the clockdomain to
293 * @clkdm: struct clockdomain * to associate with a powerdomain
295 * Associate the clockdomain @clkdm with a powerdomain @pwrdm. This
296 * enables the use of pwrdm_for_each_clkdm(). Returns -EINVAL if
297 * presented with invalid pointers; -ENOMEM if memory could not be allocated;
300 int pwrdm_add_clkdm(struct powerdomain
*pwrdm
, struct clockdomain
*clkdm
)
305 if (!pwrdm
|| !clkdm
)
308 pr_debug("powerdomain: associating clockdomain %s with powerdomain "
309 "%s\n", clkdm
->name
, pwrdm
->name
);
311 for (i
= 0; i
< PWRDM_MAX_CLKDMS
; i
++) {
312 if (!pwrdm
->pwrdm_clkdms
[i
])
315 if (pwrdm
->pwrdm_clkdms
[i
] == clkdm
) {
322 if (i
== PWRDM_MAX_CLKDMS
) {
323 pr_debug("powerdomain: increase PWRDM_MAX_CLKDMS for "
324 "pwrdm %s clkdm %s\n", pwrdm
->name
, clkdm
->name
);
330 pwrdm
->pwrdm_clkdms
[i
] = clkdm
;
339 * pwrdm_del_clkdm - remove a clockdomain from a powerdomain
340 * @pwrdm: struct powerdomain * to add the clockdomain to
341 * @clkdm: struct clockdomain * to associate with a powerdomain
343 * Dissociate the clockdomain @clkdm from the powerdomain
344 * @pwrdm. Returns -EINVAL if presented with invalid pointers; -ENOENT
345 * if @clkdm was not associated with the powerdomain, or 0 upon
348 int pwrdm_del_clkdm(struct powerdomain
*pwrdm
, struct clockdomain
*clkdm
)
353 if (!pwrdm
|| !clkdm
)
356 pr_debug("powerdomain: dissociating clockdomain %s from powerdomain "
357 "%s\n", clkdm
->name
, pwrdm
->name
);
359 for (i
= 0; i
< PWRDM_MAX_CLKDMS
; i
++)
360 if (pwrdm
->pwrdm_clkdms
[i
] == clkdm
)
363 if (i
== PWRDM_MAX_CLKDMS
) {
364 pr_debug("powerdomain: clkdm %s not associated with pwrdm "
365 "%s ?!\n", clkdm
->name
, pwrdm
->name
);
370 pwrdm
->pwrdm_clkdms
[i
] = NULL
;
379 * pwrdm_for_each_clkdm - call function on each clkdm in a pwrdm
380 * @pwrdm: struct powerdomain * to iterate over
381 * @fn: callback function *
383 * Call the supplied function @fn for each clockdomain in the powerdomain
384 * @pwrdm. The callback function can return anything but 0 to bail
385 * out early from the iterator. Returns -EINVAL if presented with
386 * invalid pointers; or passes along the last return value of the
387 * callback function, which should be 0 for success or anything else
388 * to indicate failure.
390 int pwrdm_for_each_clkdm(struct powerdomain
*pwrdm
,
391 int (*fn
)(struct powerdomain
*pwrdm
,
392 struct clockdomain
*clkdm
))
400 for (i
= 0; i
< PWRDM_MAX_CLKDMS
&& !ret
; i
++)
401 ret
= (*fn
)(pwrdm
, pwrdm
->pwrdm_clkdms
[i
]);
407 * pwrdm_get_mem_bank_count - get number of memory banks in this powerdomain
408 * @pwrdm: struct powerdomain *
410 * Return the number of controllable memory banks in powerdomain @pwrdm,
411 * starting with 1. Returns -EINVAL if the powerdomain pointer is null.
413 int pwrdm_get_mem_bank_count(struct powerdomain
*pwrdm
)
422 * pwrdm_set_next_pwrst - set next powerdomain power state
423 * @pwrdm: struct powerdomain * to set
424 * @pwrst: one of the PWRDM_POWER_* macros
426 * Set the powerdomain @pwrdm's next power state to @pwrst. The powerdomain
427 * may not enter this state immediately if the preconditions for this state
428 * have not been satisfied. Returns -EINVAL if the powerdomain pointer is
429 * null or if the power state is invalid for the powerdomin, or returns 0
432 int pwrdm_set_next_pwrst(struct powerdomain
*pwrdm
, u8 pwrst
)
437 if (!(pwrdm
->pwrsts
& (1 << pwrst
)))
440 pr_debug("powerdomain: setting next powerstate for %s to %0x\n",
443 prm_rmw_mod_reg_bits(OMAP_POWERSTATE_MASK
,
444 (pwrst
<< OMAP_POWERSTATE_SHIFT
),
445 pwrdm
->prcm_offs
, pwrstctrl_reg_offs
);
451 * pwrdm_read_next_pwrst - get next powerdomain power state
452 * @pwrdm: struct powerdomain * to get power state
454 * Return the powerdomain @pwrdm's next power state. Returns -EINVAL
455 * if the powerdomain pointer is null or returns the next power state
458 int pwrdm_read_next_pwrst(struct powerdomain
*pwrdm
)
463 return prm_read_mod_bits_shift(pwrdm
->prcm_offs
,
464 pwrstctrl_reg_offs
, OMAP_POWERSTATE_MASK
);
468 * pwrdm_read_pwrst - get current powerdomain power state
469 * @pwrdm: struct powerdomain * to get power state
471 * Return the powerdomain @pwrdm's current power state. Returns -EINVAL
472 * if the powerdomain pointer is null or returns the current power state
475 int pwrdm_read_pwrst(struct powerdomain
*pwrdm
)
480 return prm_read_mod_bits_shift(pwrdm
->prcm_offs
,
481 pwrstst_reg_offs
, OMAP_POWERSTATEST_MASK
);
485 * pwrdm_read_prev_pwrst - get previous powerdomain power state
486 * @pwrdm: struct powerdomain * to get previous power state
488 * Return the powerdomain @pwrdm's previous power state. Returns -EINVAL
489 * if the powerdomain pointer is null or returns the previous power state
492 int pwrdm_read_prev_pwrst(struct powerdomain
*pwrdm
)
497 return prm_read_mod_bits_shift(pwrdm
->prcm_offs
, OMAP3430_PM_PREPWSTST
,
498 OMAP3430_LASTPOWERSTATEENTERED_MASK
);
502 * pwrdm_set_logic_retst - set powerdomain logic power state upon retention
503 * @pwrdm: struct powerdomain * to set
504 * @pwrst: one of the PWRDM_POWER_* macros
506 * Set the next power state @pwrst that the logic portion of the
507 * powerdomain @pwrdm will enter when the powerdomain enters retention.
508 * This will be either RETENTION or OFF, if supported. Returns
509 * -EINVAL if the powerdomain pointer is null or the target power
510 * state is not not supported, or returns 0 upon success.
512 int pwrdm_set_logic_retst(struct powerdomain
*pwrdm
, u8 pwrst
)
519 if (!(pwrdm
->pwrsts_logic_ret
& (1 << pwrst
)))
522 pr_debug("powerdomain: setting next logic powerstate for %s to %0x\n",
526 * The register bit names below may not correspond to the
527 * actual names of the bits in each powerdomain's register,
528 * but the type of value returned is the same for each
531 v
= pwrst
<< __ffs(OMAP3430_LOGICL1CACHERETSTATE_MASK
);
532 prm_rmw_mod_reg_bits(OMAP3430_LOGICL1CACHERETSTATE_MASK
, v
,
533 pwrdm
->prcm_offs
, pwrstctrl_reg_offs
);
539 * pwrdm_set_mem_onst - set memory power state while powerdomain ON
540 * @pwrdm: struct powerdomain * to set
541 * @bank: memory bank number to set (0-3)
542 * @pwrst: one of the PWRDM_POWER_* macros
544 * Set the next power state @pwrst that memory bank @bank of the
545 * powerdomain @pwrdm will enter when the powerdomain enters the ON
546 * state. @bank will be a number from 0 to 3, and represents different
547 * types of memory, depending on the powerdomain. Returns -EINVAL if
548 * the powerdomain pointer is null or the target power state is not
549 * not supported for this memory bank, -EEXIST if the target memory
550 * bank does not exist or is not controllable, or returns 0 upon
553 int pwrdm_set_mem_onst(struct powerdomain
*pwrdm
, u8 bank
, u8 pwrst
)
560 if (pwrdm
->banks
< (bank
+ 1))
563 if (!(pwrdm
->pwrsts_mem_on
[bank
] & (1 << pwrst
)))
566 pr_debug("powerdomain: setting next memory powerstate for domain %s "
567 "bank %0x while pwrdm-ON to %0x\n", pwrdm
->name
, bank
, pwrst
);
570 * The register bit names below may not correspond to the
571 * actual names of the bits in each powerdomain's register,
572 * but the type of value returned is the same for each
577 m
= OMAP_MEM0_ONSTATE_MASK
;
580 m
= OMAP_MEM1_ONSTATE_MASK
;
583 m
= OMAP_MEM2_ONSTATE_MASK
;
586 m
= OMAP_MEM3_ONSTATE_MASK
;
589 m
= OMAP_MEM4_ONSTATE_MASK
;
592 WARN_ON(1); /* should never happen */
596 prm_rmw_mod_reg_bits(m
, (pwrst
<< __ffs(m
)),
597 pwrdm
->prcm_offs
, pwrstctrl_reg_offs
);
603 * pwrdm_set_mem_retst - set memory power state while powerdomain in RET
604 * @pwrdm: struct powerdomain * to set
605 * @bank: memory bank number to set (0-3)
606 * @pwrst: one of the PWRDM_POWER_* macros
608 * Set the next power state @pwrst that memory bank @bank of the
609 * powerdomain @pwrdm will enter when the powerdomain enters the
610 * RETENTION state. Bank will be a number from 0 to 3, and represents
611 * different types of memory, depending on the powerdomain. @pwrst
612 * will be either RETENTION or OFF, if supported. Returns -EINVAL if
613 * the powerdomain pointer is null or the target power state is not
614 * not supported for this memory bank, -EEXIST if the target memory
615 * bank does not exist or is not controllable, or returns 0 upon
618 int pwrdm_set_mem_retst(struct powerdomain
*pwrdm
, u8 bank
, u8 pwrst
)
625 if (pwrdm
->banks
< (bank
+ 1))
628 if (!(pwrdm
->pwrsts_mem_ret
[bank
] & (1 << pwrst
)))
631 pr_debug("powerdomain: setting next memory powerstate for domain %s "
632 "bank %0x while pwrdm-RET to %0x\n", pwrdm
->name
, bank
, pwrst
);
635 * The register bit names below may not correspond to the
636 * actual names of the bits in each powerdomain's register,
637 * but the type of value returned is the same for each
642 m
= OMAP_MEM0_RETSTATE_MASK
;
645 m
= OMAP_MEM1_RETSTATE_MASK
;
648 m
= OMAP_MEM2_RETSTATE_MASK
;
651 m
= OMAP_MEM3_RETSTATE_MASK
;
654 m
= OMAP_MEM4_RETSTATE_MASK
;
657 WARN_ON(1); /* should never happen */
661 prm_rmw_mod_reg_bits(m
, (pwrst
<< __ffs(m
)), pwrdm
->prcm_offs
,
668 * pwrdm_read_logic_pwrst - get current powerdomain logic retention power state
669 * @pwrdm: struct powerdomain * to get current logic retention power state
671 * Return the power state that the logic portion of powerdomain @pwrdm
672 * will enter when the powerdomain enters retention. Returns -EINVAL
673 * if the powerdomain pointer is null or returns the logic retention
674 * power state upon success.
676 int pwrdm_read_logic_pwrst(struct powerdomain
*pwrdm
)
681 return prm_read_mod_bits_shift(pwrdm
->prcm_offs
, pwrstst_reg_offs
,
682 OMAP3430_LOGICSTATEST_MASK
);
686 * pwrdm_read_prev_logic_pwrst - get previous powerdomain logic power state
687 * @pwrdm: struct powerdomain * to get previous logic power state
689 * Return the powerdomain @pwrdm's previous logic power state. Returns
690 * -EINVAL if the powerdomain pointer is null or returns the previous
691 * logic power state upon success.
693 int pwrdm_read_prev_logic_pwrst(struct powerdomain
*pwrdm
)
699 * The register bit names below may not correspond to the
700 * actual names of the bits in each powerdomain's register,
701 * but the type of value returned is the same for each
704 return prm_read_mod_bits_shift(pwrdm
->prcm_offs
, OMAP3430_PM_PREPWSTST
,
705 OMAP3430_LASTLOGICSTATEENTERED_MASK
);
709 * pwrdm_read_logic_retst - get next powerdomain logic power state
710 * @pwrdm: struct powerdomain * to get next logic power state
712 * Return the powerdomain pwrdm's logic power state. Returns -EINVAL
713 * if the powerdomain pointer is null or returns the next logic
714 * power state upon success.
716 int pwrdm_read_logic_retst(struct powerdomain
*pwrdm
)
722 * The register bit names below may not correspond to the
723 * actual names of the bits in each powerdomain's register,
724 * but the type of value returned is the same for each
727 return prm_read_mod_bits_shift(pwrdm
->prcm_offs
, pwrstctrl_reg_offs
,
728 OMAP3430_LOGICSTATEST_MASK
);
732 * pwrdm_read_mem_pwrst - get current memory bank power state
733 * @pwrdm: struct powerdomain * to get current memory bank power state
734 * @bank: memory bank number (0-3)
736 * Return the powerdomain @pwrdm's current memory power state for bank
737 * @bank. Returns -EINVAL if the powerdomain pointer is null, -EEXIST if
738 * the target memory bank does not exist or is not controllable, or
739 * returns the current memory power state upon success.
741 int pwrdm_read_mem_pwrst(struct powerdomain
*pwrdm
, u8 bank
)
748 if (pwrdm
->banks
< (bank
+ 1))
751 if (pwrdm
->flags
& PWRDM_HAS_MPU_QUIRK
)
755 * The register bit names below may not correspond to the
756 * actual names of the bits in each powerdomain's register,
757 * but the type of value returned is the same for each
762 m
= OMAP_MEM0_STATEST_MASK
;
765 m
= OMAP_MEM1_STATEST_MASK
;
768 m
= OMAP_MEM2_STATEST_MASK
;
771 m
= OMAP_MEM3_STATEST_MASK
;
774 m
= OMAP_MEM4_STATEST_MASK
;
777 WARN_ON(1); /* should never happen */
781 return prm_read_mod_bits_shift(pwrdm
->prcm_offs
,
782 pwrstst_reg_offs
, m
);
786 * pwrdm_read_prev_mem_pwrst - get previous memory bank power state
787 * @pwrdm: struct powerdomain * to get previous memory bank power state
788 * @bank: memory bank number (0-3)
790 * Return the powerdomain @pwrdm's previous memory power state for
791 * bank @bank. Returns -EINVAL if the powerdomain pointer is null,
792 * -EEXIST if the target memory bank does not exist or is not
793 * controllable, or returns the previous memory power state upon
796 int pwrdm_read_prev_mem_pwrst(struct powerdomain
*pwrdm
, u8 bank
)
803 if (pwrdm
->banks
< (bank
+ 1))
806 if (pwrdm
->flags
& PWRDM_HAS_MPU_QUIRK
)
810 * The register bit names below may not correspond to the
811 * actual names of the bits in each powerdomain's register,
812 * but the type of value returned is the same for each
817 m
= OMAP3430_LASTMEM1STATEENTERED_MASK
;
820 m
= OMAP3430_LASTMEM2STATEENTERED_MASK
;
823 m
= OMAP3430_LASTSHAREDL2CACHEFLATSTATEENTERED_MASK
;
826 m
= OMAP3430_LASTL2FLATMEMSTATEENTERED_MASK
;
829 WARN_ON(1); /* should never happen */
833 return prm_read_mod_bits_shift(pwrdm
->prcm_offs
,
834 OMAP3430_PM_PREPWSTST
, m
);
838 * pwrdm_read_mem_retst - get next memory bank power state
839 * @pwrdm: struct powerdomain * to get mext memory bank power state
840 * @bank: memory bank number (0-3)
842 * Return the powerdomain pwrdm's next memory power state for bank
843 * x. Returns -EINVAL if the powerdomain pointer is null, -EEXIST if
844 * the target memory bank does not exist or is not controllable, or
845 * returns the next memory power state upon success.
847 int pwrdm_read_mem_retst(struct powerdomain
*pwrdm
, u8 bank
)
854 if (pwrdm
->banks
< (bank
+ 1))
858 * The register bit names below may not correspond to the
859 * actual names of the bits in each powerdomain's register,
860 * but the type of value returned is the same for each
865 m
= OMAP_MEM0_RETSTATE_MASK
;
868 m
= OMAP_MEM1_RETSTATE_MASK
;
871 m
= OMAP_MEM2_RETSTATE_MASK
;
874 m
= OMAP_MEM3_RETSTATE_MASK
;
877 m
= OMAP_MEM4_RETSTATE_MASK
;
879 WARN_ON(1); /* should never happen */
883 return prm_read_mod_bits_shift(pwrdm
->prcm_offs
,
884 pwrstctrl_reg_offs
, m
);
888 * pwrdm_clear_all_prev_pwrst - clear previous powerstate register for a pwrdm
889 * @pwrdm: struct powerdomain * to clear
891 * Clear the powerdomain's previous power state register @pwrdm.
892 * Clears the entire register, including logic and memory bank
893 * previous power states. Returns -EINVAL if the powerdomain pointer
894 * is null, or returns 0 upon success.
896 int pwrdm_clear_all_prev_pwrst(struct powerdomain
*pwrdm
)
902 * XXX should get the powerdomain's current state here;
903 * warn & fail if it is not ON.
906 pr_debug("powerdomain: clearing previous power state reg for %s\n",
909 prm_write_mod_reg(0, pwrdm
->prcm_offs
, OMAP3430_PM_PREPWSTST
);
915 * pwrdm_enable_hdwr_sar - enable automatic hardware SAR for a pwrdm
916 * @pwrdm: struct powerdomain *
918 * Enable automatic context save-and-restore upon power state change
919 * for some devices in the powerdomain @pwrdm. Warning: this only
920 * affects a subset of devices in a powerdomain; check the TRM
921 * closely. Returns -EINVAL if the powerdomain pointer is null or if
922 * the powerdomain does not support automatic save-and-restore, or
923 * returns 0 upon success.
925 int pwrdm_enable_hdwr_sar(struct powerdomain
*pwrdm
)
930 if (!(pwrdm
->flags
& PWRDM_HAS_HDWR_SAR
))
933 pr_debug("powerdomain: %s: setting SAVEANDRESTORE bit\n",
936 prm_rmw_mod_reg_bits(0, 1 << OMAP3430ES2_SAVEANDRESTORE_SHIFT
,
937 pwrdm
->prcm_offs
, pwrstctrl_reg_offs
);
943 * pwrdm_disable_hdwr_sar - disable automatic hardware SAR for a pwrdm
944 * @pwrdm: struct powerdomain *
946 * Disable automatic context save-and-restore upon power state change
947 * for some devices in the powerdomain @pwrdm. Warning: this only
948 * affects a subset of devices in a powerdomain; check the TRM
949 * closely. Returns -EINVAL if the powerdomain pointer is null or if
950 * the powerdomain does not support automatic save-and-restore, or
951 * returns 0 upon success.
953 int pwrdm_disable_hdwr_sar(struct powerdomain
*pwrdm
)
958 if (!(pwrdm
->flags
& PWRDM_HAS_HDWR_SAR
))
961 pr_debug("powerdomain: %s: clearing SAVEANDRESTORE bit\n",
964 prm_rmw_mod_reg_bits(1 << OMAP3430ES2_SAVEANDRESTORE_SHIFT
, 0,
965 pwrdm
->prcm_offs
, pwrstctrl_reg_offs
);
971 * pwrdm_has_hdwr_sar - test whether powerdomain supports hardware SAR
972 * @pwrdm: struct powerdomain *
974 * Returns 1 if powerdomain @pwrdm supports hardware save-and-restore
975 * for some devices, or 0 if it does not.
977 bool pwrdm_has_hdwr_sar(struct powerdomain
*pwrdm
)
979 return (pwrdm
&& pwrdm
->flags
& PWRDM_HAS_HDWR_SAR
) ? 1 : 0;
983 * pwrdm_set_lowpwrstchange - Request a low power state change
984 * @pwrdm: struct powerdomain *
986 * Allows a powerdomain to transtion to a lower power sleep state
987 * from an existing sleep state without waking up the powerdomain.
988 * Returns -EINVAL if the powerdomain pointer is null or if the
989 * powerdomain does not support LOWPOWERSTATECHANGE, or returns 0
992 int pwrdm_set_lowpwrstchange(struct powerdomain
*pwrdm
)
997 if (!(pwrdm
->flags
& PWRDM_HAS_LOWPOWERSTATECHANGE
))
1000 pr_debug("powerdomain: %s: setting LOWPOWERSTATECHANGE bit\n",
1003 prm_rmw_mod_reg_bits(OMAP4430_LOWPOWERSTATECHANGE_MASK
,
1004 (1 << OMAP4430_LOWPOWERSTATECHANGE_SHIFT
),
1005 pwrdm
->prcm_offs
, pwrstctrl_reg_offs
);
1011 * pwrdm_wait_transition - wait for powerdomain power transition to finish
1012 * @pwrdm: struct powerdomain * to wait for
1014 * If the powerdomain @pwrdm is in the process of a state transition,
1015 * spin until it completes the power transition, or until an iteration
1016 * bailout value is reached. Returns -EINVAL if the powerdomain
1017 * pointer is null, -EAGAIN if the bailout value was reached, or
1018 * returns 0 upon success.
1020 int pwrdm_wait_transition(struct powerdomain
*pwrdm
)
1028 * REVISIT: pwrdm_wait_transition() may be better implemented
1029 * via a callback and a periodic timer check -- how long do we expect
1030 * powerdomain transitions to take?
1033 /* XXX Is this udelay() value meaningful? */
1034 while ((prm_read_mod_reg(pwrdm
->prcm_offs
, pwrstst_reg_offs
) &
1035 OMAP_INTRANSITION_MASK
) &&
1036 (c
++ < PWRDM_TRANSITION_BAILOUT
))
1039 if (c
> PWRDM_TRANSITION_BAILOUT
) {
1040 printk(KERN_ERR
"powerdomain: waited too long for "
1041 "powerdomain %s to complete transition\n", pwrdm
->name
);
1045 pr_debug("powerdomain: completed transition in %d loops\n", c
);
1050 int pwrdm_state_switch(struct powerdomain
*pwrdm
)
1052 return _pwrdm_state_switch(pwrdm
, PWRDM_STATE_NOW
);
1055 int pwrdm_clkdm_state_switch(struct clockdomain
*clkdm
)
1057 if (clkdm
!= NULL
&& clkdm
->pwrdm
.ptr
!= NULL
) {
1058 pwrdm_wait_transition(clkdm
->pwrdm
.ptr
);
1059 return pwrdm_state_switch(clkdm
->pwrdm
.ptr
);
1065 int pwrdm_pre_transition(void)
1067 pwrdm_for_each(_pwrdm_pre_transition_cb
, NULL
);
1071 int pwrdm_post_transition(void)
1073 pwrdm_for_each(_pwrdm_post_transition_cb
, NULL
);