2 * OMAP powerdomain control
4 * Copyright (C) 2007-2008 Texas Instruments, Inc.
5 * Copyright (C) 2007-2008 Nokia Corporation
7 * Written by Paul Walmsley
9 * This program is free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License version 2 as
11 * published by the Free Software Foundation.
13 #ifdef CONFIG_OMAP_DEBUG_POWERDOMAIN
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"
32 #include "prm-regbits-34xx.h"
35 #include <mach/powerdomain.h>
36 #include <mach/clockdomain.h>
45 /* pwrdm_list contains all registered struct powerdomains */
46 static LIST_HEAD(pwrdm_list
);
49 * pwrdm_rwlock protects pwrdm_list add and del ops - also reused to
50 * protect pwrdm_clkdms[] during clkdm add/del ops
52 static DEFINE_RWLOCK(pwrdm_rwlock
);
55 /* Private functions */
57 static u32
prm_read_mod_bits_shift(s16 domain
, s16 idx
, u32 mask
)
61 v
= prm_read_mod_reg(domain
, idx
);
68 static struct powerdomain
*_pwrdm_lookup(const char *name
)
70 struct powerdomain
*pwrdm
, *temp_pwrdm
;
74 list_for_each_entry(temp_pwrdm
, &pwrdm_list
, node
) {
75 if (!strcmp(name
, temp_pwrdm
->name
)) {
84 /* _pwrdm_deps_lookup - look up the specified powerdomain in a pwrdm list */
85 static struct powerdomain
*_pwrdm_deps_lookup(struct powerdomain
*pwrdm
,
86 struct pwrdm_dep
*deps
)
90 if (!pwrdm
|| !deps
|| !omap_chip_is(pwrdm
->omap_chip
))
91 return ERR_PTR(-EINVAL
);
93 for (pd
= deps
; pd
->pwrdm_name
; pd
++) {
95 if (!omap_chip_is(pd
->omap_chip
))
98 if (!pd
->pwrdm
&& pd
->pwrdm_name
)
99 pd
->pwrdm
= pwrdm_lookup(pd
->pwrdm_name
);
101 if (pd
->pwrdm
== pwrdm
)
107 return ERR_PTR(-ENOENT
);
112 static int _pwrdm_state_switch(struct powerdomain
*pwrdm
, int flag
)
121 state
= pwrdm_read_pwrst(pwrdm
);
124 case PWRDM_STATE_NOW
:
127 case PWRDM_STATE_PREV
:
128 prev
= pwrdm_read_prev_pwrst(pwrdm
);
129 if (pwrdm
->state
!= prev
)
130 pwrdm
->state_counter
[prev
]++;
137 pwrdm
->state_counter
[state
]++;
139 pm_dbg_update_time(pwrdm
, prev
);
141 pwrdm
->state
= state
;
146 static int _pwrdm_pre_transition_cb(struct powerdomain
*pwrdm
, void *unused
)
148 pwrdm_clear_all_prev_pwrst(pwrdm
);
149 _pwrdm_state_switch(pwrdm
, PWRDM_STATE_NOW
);
153 static int _pwrdm_post_transition_cb(struct powerdomain
*pwrdm
, void *unused
)
155 _pwrdm_state_switch(pwrdm
, PWRDM_STATE_PREV
);
159 static __init
void _pwrdm_setup(struct powerdomain
*pwrdm
)
163 for (i
= 0; i
< 4; i
++)
164 pwrdm
->state_counter
[i
] = 0;
166 pwrdm_wait_transition(pwrdm
);
167 pwrdm
->state
= pwrdm_read_pwrst(pwrdm
);
168 pwrdm
->state_counter
[pwrdm
->state
] = 1;
172 /* Public functions */
175 * pwrdm_init - set up the powerdomain layer
177 * Loop through the list of powerdomains, registering all that are
178 * available on the current CPU. If pwrdm_list is supplied and not
179 * null, all of the referenced powerdomains will be registered. No
182 void pwrdm_init(struct powerdomain
**pwrdm_list
)
184 struct powerdomain
**p
= NULL
;
187 for (p
= pwrdm_list
; *p
; p
++) {
195 * pwrdm_register - register a powerdomain
196 * @pwrdm: struct powerdomain * to register
198 * Adds a powerdomain to the internal powerdomain list. Returns
199 * -EINVAL if given a null pointer, -EEXIST if a powerdomain is
200 * already registered by the provided name, or 0 upon success.
202 int pwrdm_register(struct powerdomain
*pwrdm
)
210 if (!omap_chip_is(pwrdm
->omap_chip
))
213 write_lock_irqsave(&pwrdm_rwlock
, flags
);
214 if (_pwrdm_lookup(pwrdm
->name
)) {
219 list_add(&pwrdm
->node
, &pwrdm_list
);
221 pr_debug("powerdomain: registered %s\n", pwrdm
->name
);
225 write_unlock_irqrestore(&pwrdm_rwlock
, flags
);
231 * pwrdm_unregister - unregister a powerdomain
232 * @pwrdm: struct powerdomain * to unregister
234 * Removes a powerdomain from the internal powerdomain list. Returns
235 * -EINVAL if pwrdm argument is NULL.
237 int pwrdm_unregister(struct powerdomain
*pwrdm
)
244 write_lock_irqsave(&pwrdm_rwlock
, flags
);
245 list_del(&pwrdm
->node
);
246 write_unlock_irqrestore(&pwrdm_rwlock
, flags
);
248 pr_debug("powerdomain: unregistered %s\n", pwrdm
->name
);
254 * pwrdm_lookup - look up a powerdomain by name, return a pointer
255 * @name: name of powerdomain
257 * Find a registered powerdomain by its name. Returns a pointer to the
258 * struct powerdomain if found, or NULL otherwise.
260 struct powerdomain
*pwrdm_lookup(const char *name
)
262 struct powerdomain
*pwrdm
;
268 read_lock_irqsave(&pwrdm_rwlock
, flags
);
269 pwrdm
= _pwrdm_lookup(name
);
270 read_unlock_irqrestore(&pwrdm_rwlock
, flags
);
276 * pwrdm_for_each_nolock - call function on each registered clockdomain
277 * @fn: callback function *
279 * Call the supplied function for each registered powerdomain. The
280 * callback function can return anything but 0 to bail out early from
281 * the iterator. Returns the last return value of the callback function, which
282 * should be 0 for success or anything else to indicate failure; or -EINVAL if
283 * the function pointer is null.
285 int pwrdm_for_each_nolock(int (*fn
)(struct powerdomain
*pwrdm
, void *user
),
288 struct powerdomain
*temp_pwrdm
;
294 list_for_each_entry(temp_pwrdm
, &pwrdm_list
, node
) {
295 ret
= (*fn
)(temp_pwrdm
, user
);
304 * pwrdm_for_each - call function on each registered clockdomain
305 * @fn: callback function *
307 * This function is the same as 'pwrdm_for_each_nolock()', but keeps the
308 * &pwrdm_rwlock locked for reading, so no powerdomain structure manipulation
309 * functions should be called from the callback, although hardware powerdomain
310 * control functions are fine.
312 int pwrdm_for_each(int (*fn
)(struct powerdomain
*pwrdm
, void *user
),
318 read_lock_irqsave(&pwrdm_rwlock
, flags
);
319 ret
= pwrdm_for_each_nolock(fn
, user
);
320 read_unlock_irqrestore(&pwrdm_rwlock
, flags
);
326 * pwrdm_add_clkdm - add a clockdomain to a powerdomain
327 * @pwrdm: struct powerdomain * to add the clockdomain to
328 * @clkdm: struct clockdomain * to associate with a powerdomain
330 * Associate the clockdomain 'clkdm' with a powerdomain 'pwrdm'. This
331 * enables the use of pwrdm_for_each_clkdm(). Returns -EINVAL if
332 * presented with invalid pointers; -ENOMEM if memory could not be allocated;
335 int pwrdm_add_clkdm(struct powerdomain
*pwrdm
, struct clockdomain
*clkdm
)
341 if (!pwrdm
|| !clkdm
)
344 pr_debug("powerdomain: associating clockdomain %s with powerdomain "
345 "%s\n", clkdm
->name
, pwrdm
->name
);
347 write_lock_irqsave(&pwrdm_rwlock
, flags
);
349 for (i
= 0; i
< PWRDM_MAX_CLKDMS
; i
++) {
350 if (!pwrdm
->pwrdm_clkdms
[i
])
353 if (pwrdm
->pwrdm_clkdms
[i
] == clkdm
) {
360 if (i
== PWRDM_MAX_CLKDMS
) {
361 pr_debug("powerdomain: increase PWRDM_MAX_CLKDMS for "
362 "pwrdm %s clkdm %s\n", pwrdm
->name
, clkdm
->name
);
368 pwrdm
->pwrdm_clkdms
[i
] = clkdm
;
373 write_unlock_irqrestore(&pwrdm_rwlock
, flags
);
379 * pwrdm_del_clkdm - remove a clockdomain from a powerdomain
380 * @pwrdm: struct powerdomain * to add the clockdomain to
381 * @clkdm: struct clockdomain * to associate with a powerdomain
383 * Dissociate the clockdomain 'clkdm' from the powerdomain
384 * 'pwrdm'. Returns -EINVAL if presented with invalid pointers;
385 * -ENOENT if the clkdm was not associated with the powerdomain, or 0
388 int pwrdm_del_clkdm(struct powerdomain
*pwrdm
, struct clockdomain
*clkdm
)
394 if (!pwrdm
|| !clkdm
)
397 pr_debug("powerdomain: dissociating clockdomain %s from powerdomain "
398 "%s\n", clkdm
->name
, pwrdm
->name
);
400 write_lock_irqsave(&pwrdm_rwlock
, flags
);
402 for (i
= 0; i
< PWRDM_MAX_CLKDMS
; i
++)
403 if (pwrdm
->pwrdm_clkdms
[i
] == clkdm
)
406 if (i
== PWRDM_MAX_CLKDMS
) {
407 pr_debug("powerdomain: clkdm %s not associated with pwrdm "
408 "%s ?!\n", clkdm
->name
, pwrdm
->name
);
413 pwrdm
->pwrdm_clkdms
[i
] = NULL
;
418 write_unlock_irqrestore(&pwrdm_rwlock
, flags
);
424 * pwrdm_for_each_clkdm - call function on each clkdm in a pwrdm
425 * @pwrdm: struct powerdomain * to iterate over
426 * @fn: callback function *
428 * Call the supplied function for each clockdomain in the powerdomain
429 * 'pwrdm'. The callback function can return anything but 0 to bail
430 * out early from the iterator. The callback function is called with
431 * the pwrdm_rwlock held for reading, so no powerdomain structure
432 * manipulation functions should be called from the callback, although
433 * hardware powerdomain control functions are fine. Returns -EINVAL
434 * if presented with invalid pointers; or passes along the last return
435 * value of the callback function, which should be 0 for success or
436 * anything else to indicate failure.
438 int pwrdm_for_each_clkdm(struct powerdomain
*pwrdm
,
439 int (*fn
)(struct powerdomain
*pwrdm
,
440 struct clockdomain
*clkdm
))
449 read_lock_irqsave(&pwrdm_rwlock
, flags
);
451 for (i
= 0; i
< PWRDM_MAX_CLKDMS
&& !ret
; i
++)
452 ret
= (*fn
)(pwrdm
, pwrdm
->pwrdm_clkdms
[i
]);
454 read_unlock_irqrestore(&pwrdm_rwlock
, flags
);
461 * pwrdm_add_wkdep - add a wakeup dependency from pwrdm2 to pwrdm1
462 * @pwrdm1: wake this struct powerdomain * up (dependent)
463 * @pwrdm2: when this struct powerdomain * wakes up (source)
465 * When the powerdomain represented by pwrdm2 wakes up (due to an
466 * interrupt), wake up pwrdm1. Implemented in hardware on the OMAP,
467 * this feature is designed to reduce wakeup latency of the dependent
468 * powerdomain. Returns -EINVAL if presented with invalid powerdomain
469 * pointers, -ENOENT if pwrdm2 cannot wake up pwrdm1 in hardware, or
472 int pwrdm_add_wkdep(struct powerdomain
*pwrdm1
, struct powerdomain
*pwrdm2
)
474 struct powerdomain
*p
;
479 p
= _pwrdm_deps_lookup(pwrdm2
, pwrdm1
->wkdep_srcs
);
481 pr_debug("powerdomain: hardware cannot set/clear wake up of "
482 "%s when %s wakes up\n", pwrdm1
->name
, pwrdm2
->name
);
486 pr_debug("powerdomain: hardware will wake up %s when %s wakes up\n",
487 pwrdm1
->name
, pwrdm2
->name
);
489 prm_set_mod_reg_bits((1 << pwrdm2
->dep_bit
),
490 pwrdm1
->prcm_offs
, PM_WKDEP
);
496 * pwrdm_del_wkdep - remove a wakeup dependency from pwrdm2 to pwrdm1
497 * @pwrdm1: wake this struct powerdomain * up (dependent)
498 * @pwrdm2: when this struct powerdomain * wakes up (source)
500 * Remove a wakeup dependency that causes pwrdm1 to wake up when pwrdm2
501 * wakes up. Returns -EINVAL if presented with invalid powerdomain
502 * pointers, -ENOENT if pwrdm2 cannot wake up pwrdm1 in hardware, or
505 int pwrdm_del_wkdep(struct powerdomain
*pwrdm1
, struct powerdomain
*pwrdm2
)
507 struct powerdomain
*p
;
512 p
= _pwrdm_deps_lookup(pwrdm2
, pwrdm1
->wkdep_srcs
);
514 pr_debug("powerdomain: hardware cannot set/clear wake up of "
515 "%s when %s wakes up\n", pwrdm1
->name
, pwrdm2
->name
);
519 pr_debug("powerdomain: hardware will no longer wake up %s after %s "
520 "wakes up\n", pwrdm1
->name
, pwrdm2
->name
);
522 prm_clear_mod_reg_bits((1 << pwrdm2
->dep_bit
),
523 pwrdm1
->prcm_offs
, PM_WKDEP
);
529 * pwrdm_read_wkdep - read wakeup dependency state from pwrdm2 to pwrdm1
530 * @pwrdm1: wake this struct powerdomain * up (dependent)
531 * @pwrdm2: when this struct powerdomain * wakes up (source)
533 * Return 1 if a hardware wakeup dependency exists wherein pwrdm1 will be
534 * awoken when pwrdm2 wakes up; 0 if dependency is not set; -EINVAL
535 * if either powerdomain pointer is invalid; or -ENOENT if the hardware
538 * REVISIT: Currently this function only represents software-controllable
539 * wakeup dependencies. Wakeup dependencies fixed in hardware are not
542 int pwrdm_read_wkdep(struct powerdomain
*pwrdm1
, struct powerdomain
*pwrdm2
)
544 struct powerdomain
*p
;
549 p
= _pwrdm_deps_lookup(pwrdm2
, pwrdm1
->wkdep_srcs
);
551 pr_debug("powerdomain: hardware cannot set/clear wake up of "
552 "%s when %s wakes up\n", pwrdm1
->name
, pwrdm2
->name
);
556 return prm_read_mod_bits_shift(pwrdm1
->prcm_offs
, PM_WKDEP
,
557 (1 << pwrdm2
->dep_bit
));
561 * pwrdm_add_sleepdep - add a sleep dependency from pwrdm2 to pwrdm1
562 * @pwrdm1: prevent this struct powerdomain * from sleeping (dependent)
563 * @pwrdm2: when this struct powerdomain * is active (source)
565 * Prevent pwrdm1 from automatically going inactive (and then to
566 * retention or off) if pwrdm2 is still active. Returns -EINVAL if
567 * presented with invalid powerdomain pointers or called on a machine
568 * that does not support software-configurable hardware sleep dependencies,
569 * -ENOENT if the specified dependency cannot be set in hardware, or
572 int pwrdm_add_sleepdep(struct powerdomain
*pwrdm1
, struct powerdomain
*pwrdm2
)
574 struct powerdomain
*p
;
579 if (!cpu_is_omap34xx())
582 p
= _pwrdm_deps_lookup(pwrdm2
, pwrdm1
->sleepdep_srcs
);
584 pr_debug("powerdomain: hardware cannot set/clear sleep "
585 "dependency affecting %s from %s\n", pwrdm1
->name
,
590 pr_debug("powerdomain: will prevent %s from sleeping if %s is active\n",
591 pwrdm1
->name
, pwrdm2
->name
);
593 cm_set_mod_reg_bits((1 << pwrdm2
->dep_bit
),
594 pwrdm1
->prcm_offs
, OMAP3430_CM_SLEEPDEP
);
600 * pwrdm_del_sleepdep - remove a sleep dependency from pwrdm2 to pwrdm1
601 * @pwrdm1: prevent this struct powerdomain * from sleeping (dependent)
602 * @pwrdm2: when this struct powerdomain * is active (source)
604 * Allow pwrdm1 to automatically go inactive (and then to retention or
605 * off), independent of the activity state of pwrdm2. Returns -EINVAL
606 * if presented with invalid powerdomain pointers or called on a machine
607 * that does not support software-configurable hardware sleep dependencies,
608 * -ENOENT if the specified dependency cannot be cleared in hardware, or
611 int pwrdm_del_sleepdep(struct powerdomain
*pwrdm1
, struct powerdomain
*pwrdm2
)
613 struct powerdomain
*p
;
618 if (!cpu_is_omap34xx())
621 p
= _pwrdm_deps_lookup(pwrdm2
, pwrdm1
->sleepdep_srcs
);
623 pr_debug("powerdomain: hardware cannot set/clear sleep "
624 "dependency affecting %s from %s\n", pwrdm1
->name
,
629 pr_debug("powerdomain: will no longer prevent %s from sleeping if "
630 "%s is active\n", pwrdm1
->name
, pwrdm2
->name
);
632 cm_clear_mod_reg_bits((1 << pwrdm2
->dep_bit
),
633 pwrdm1
->prcm_offs
, OMAP3430_CM_SLEEPDEP
);
639 * pwrdm_read_sleepdep - read sleep dependency state from pwrdm2 to pwrdm1
640 * @pwrdm1: prevent this struct powerdomain * from sleeping (dependent)
641 * @pwrdm2: when this struct powerdomain * is active (source)
643 * Return 1 if a hardware sleep dependency exists wherein pwrdm1 will
644 * not be allowed to automatically go inactive if pwrdm2 is active;
645 * 0 if pwrdm1's automatic power state inactivity transition is independent
646 * of pwrdm2's; -EINVAL if either powerdomain pointer is invalid or called
647 * on a machine that does not support software-configurable hardware sleep
648 * dependencies; or -ENOENT if the hardware is incapable.
650 * REVISIT: Currently this function only represents software-controllable
651 * sleep dependencies. Sleep dependencies fixed in hardware are not
654 int pwrdm_read_sleepdep(struct powerdomain
*pwrdm1
, struct powerdomain
*pwrdm2
)
656 struct powerdomain
*p
;
661 if (!cpu_is_omap34xx())
664 p
= _pwrdm_deps_lookup(pwrdm2
, pwrdm1
->sleepdep_srcs
);
666 pr_debug("powerdomain: hardware cannot set/clear sleep "
667 "dependency affecting %s from %s\n", pwrdm1
->name
,
672 return prm_read_mod_bits_shift(pwrdm1
->prcm_offs
, OMAP3430_CM_SLEEPDEP
,
673 (1 << pwrdm2
->dep_bit
));
677 * pwrdm_get_mem_bank_count - get number of memory banks in this powerdomain
678 * @pwrdm: struct powerdomain *
680 * Return the number of controllable memory banks in powerdomain pwrdm,
681 * starting with 1. Returns -EINVAL if the powerdomain pointer is null.
683 int pwrdm_get_mem_bank_count(struct powerdomain
*pwrdm
)
692 * pwrdm_set_next_pwrst - set next powerdomain power state
693 * @pwrdm: struct powerdomain * to set
694 * @pwrst: one of the PWRDM_POWER_* macros
696 * Set the powerdomain pwrdm's next power state to pwrst. The powerdomain
697 * may not enter this state immediately if the preconditions for this state
698 * have not been satisfied. Returns -EINVAL if the powerdomain pointer is
699 * null or if the power state is invalid for the powerdomin, or returns 0
702 int pwrdm_set_next_pwrst(struct powerdomain
*pwrdm
, u8 pwrst
)
707 if (!(pwrdm
->pwrsts
& (1 << pwrst
)))
710 pr_debug("powerdomain: setting next powerstate for %s to %0x\n",
713 prm_rmw_mod_reg_bits(OMAP_POWERSTATE_MASK
,
714 (pwrst
<< OMAP_POWERSTATE_SHIFT
),
715 pwrdm
->prcm_offs
, PM_PWSTCTRL
);
721 * pwrdm_read_next_pwrst - get next powerdomain power state
722 * @pwrdm: struct powerdomain * to get power state
724 * Return the powerdomain pwrdm's next power state. Returns -EINVAL
725 * if the powerdomain pointer is null or returns the next power state
728 int pwrdm_read_next_pwrst(struct powerdomain
*pwrdm
)
733 return prm_read_mod_bits_shift(pwrdm
->prcm_offs
, PM_PWSTCTRL
,
734 OMAP_POWERSTATE_MASK
);
738 * pwrdm_read_pwrst - get current powerdomain power state
739 * @pwrdm: struct powerdomain * to get power state
741 * Return the powerdomain pwrdm's current power state. Returns -EINVAL
742 * if the powerdomain pointer is null or returns the current power state
745 int pwrdm_read_pwrst(struct powerdomain
*pwrdm
)
750 return prm_read_mod_bits_shift(pwrdm
->prcm_offs
, PM_PWSTST
,
751 OMAP_POWERSTATEST_MASK
);
755 * pwrdm_read_prev_pwrst - get previous powerdomain power state
756 * @pwrdm: struct powerdomain * to get previous power state
758 * Return the powerdomain pwrdm's previous power state. Returns -EINVAL
759 * if the powerdomain pointer is null or returns the previous power state
762 int pwrdm_read_prev_pwrst(struct powerdomain
*pwrdm
)
767 return prm_read_mod_bits_shift(pwrdm
->prcm_offs
, OMAP3430_PM_PREPWSTST
,
768 OMAP3430_LASTPOWERSTATEENTERED_MASK
);
772 * pwrdm_set_logic_retst - set powerdomain logic power state upon retention
773 * @pwrdm: struct powerdomain * to set
774 * @pwrst: one of the PWRDM_POWER_* macros
776 * Set the next power state that the logic portion of the powerdomain
777 * pwrdm will enter when the powerdomain enters retention. This will
778 * be either RETENTION or OFF, if supported. Returns -EINVAL if the
779 * powerdomain pointer is null or the target power state is not not
780 * supported, or returns 0 upon success.
782 int pwrdm_set_logic_retst(struct powerdomain
*pwrdm
, u8 pwrst
)
787 if (!(pwrdm
->pwrsts_logic_ret
& (1 << pwrst
)))
790 pr_debug("powerdomain: setting next logic powerstate for %s to %0x\n",
794 * The register bit names below may not correspond to the
795 * actual names of the bits in each powerdomain's register,
796 * but the type of value returned is the same for each
799 prm_rmw_mod_reg_bits(OMAP3430_LOGICL1CACHERETSTATE
,
800 (pwrst
<< __ffs(OMAP3430_LOGICL1CACHERETSTATE
)),
801 pwrdm
->prcm_offs
, PM_PWSTCTRL
);
807 * pwrdm_set_mem_onst - set memory power state while powerdomain ON
808 * @pwrdm: struct powerdomain * to set
809 * @bank: memory bank number to set (0-3)
810 * @pwrst: one of the PWRDM_POWER_* macros
812 * Set the next power state that memory bank x of the powerdomain
813 * pwrdm will enter when the powerdomain enters the ON state. Bank
814 * will be a number from 0 to 3, and represents different types of
815 * memory, depending on the powerdomain. Returns -EINVAL if the
816 * powerdomain pointer is null or the target power state is not not
817 * supported for this memory bank, -EEXIST if the target memory bank
818 * does not exist or is not controllable, or returns 0 upon success.
820 int pwrdm_set_mem_onst(struct powerdomain
*pwrdm
, u8 bank
, u8 pwrst
)
827 if (pwrdm
->banks
< (bank
+ 1))
830 if (!(pwrdm
->pwrsts_mem_on
[bank
] & (1 << pwrst
)))
833 pr_debug("powerdomain: setting next memory powerstate for domain %s "
834 "bank %0x while pwrdm-ON to %0x\n", pwrdm
->name
, bank
, pwrst
);
837 * The register bit names below may not correspond to the
838 * actual names of the bits in each powerdomain's register,
839 * but the type of value returned is the same for each
844 m
= OMAP3430_SHAREDL1CACHEFLATONSTATE_MASK
;
847 m
= OMAP3430_L1FLATMEMONSTATE_MASK
;
850 m
= OMAP3430_SHAREDL2CACHEFLATONSTATE_MASK
;
853 m
= OMAP3430_L2FLATMEMONSTATE_MASK
;
856 WARN_ON(1); /* should never happen */
860 prm_rmw_mod_reg_bits(m
, (pwrst
<< __ffs(m
)),
861 pwrdm
->prcm_offs
, PM_PWSTCTRL
);
867 * pwrdm_set_mem_retst - set memory power state while powerdomain in RET
868 * @pwrdm: struct powerdomain * to set
869 * @bank: memory bank number to set (0-3)
870 * @pwrst: one of the PWRDM_POWER_* macros
872 * Set the next power state that memory bank x of the powerdomain
873 * pwrdm will enter when the powerdomain enters the RETENTION state.
874 * Bank will be a number from 0 to 3, and represents different types
875 * of memory, depending on the powerdomain. pwrst will be either
876 * RETENTION or OFF, if supported. Returns -EINVAL if the powerdomain
877 * pointer is null or the target power state is not not supported for
878 * this memory bank, -EEXIST if the target memory bank does not exist
879 * or is not controllable, or returns 0 upon success.
881 int pwrdm_set_mem_retst(struct powerdomain
*pwrdm
, u8 bank
, u8 pwrst
)
888 if (pwrdm
->banks
< (bank
+ 1))
891 if (!(pwrdm
->pwrsts_mem_ret
[bank
] & (1 << pwrst
)))
894 pr_debug("powerdomain: setting next memory powerstate for domain %s "
895 "bank %0x while pwrdm-RET to %0x\n", pwrdm
->name
, bank
, pwrst
);
898 * The register bit names below may not correspond to the
899 * actual names of the bits in each powerdomain's register,
900 * but the type of value returned is the same for each
905 m
= OMAP3430_SHAREDL1CACHEFLATRETSTATE
;
908 m
= OMAP3430_L1FLATMEMRETSTATE
;
911 m
= OMAP3430_SHAREDL2CACHEFLATRETSTATE
;
914 m
= OMAP3430_L2FLATMEMRETSTATE
;
917 WARN_ON(1); /* should never happen */
921 prm_rmw_mod_reg_bits(m
, (pwrst
<< __ffs(m
)), pwrdm
->prcm_offs
,
928 * pwrdm_read_logic_pwrst - get current powerdomain logic retention power state
929 * @pwrdm: struct powerdomain * to get current logic retention power state
931 * Return the current power state that the logic portion of
932 * powerdomain pwrdm will enter
933 * Returns -EINVAL if the powerdomain pointer is null or returns the
934 * current logic retention power state upon success.
936 int pwrdm_read_logic_pwrst(struct powerdomain
*pwrdm
)
941 return prm_read_mod_bits_shift(pwrdm
->prcm_offs
, PM_PWSTST
,
942 OMAP3430_LOGICSTATEST
);
946 * pwrdm_read_prev_logic_pwrst - get previous powerdomain logic power state
947 * @pwrdm: struct powerdomain * to get previous logic power state
949 * Return the powerdomain pwrdm's logic power state. Returns -EINVAL
950 * if the powerdomain pointer is null or returns the previous logic
951 * power state upon success.
953 int pwrdm_read_prev_logic_pwrst(struct powerdomain
*pwrdm
)
959 * The register bit names below may not correspond to the
960 * actual names of the bits in each powerdomain's register,
961 * but the type of value returned is the same for each
964 return prm_read_mod_bits_shift(pwrdm
->prcm_offs
, OMAP3430_PM_PREPWSTST
,
965 OMAP3430_LASTLOGICSTATEENTERED
);
969 * pwrdm_read_mem_pwrst - get current memory bank power state
970 * @pwrdm: struct powerdomain * to get current memory bank power state
971 * @bank: memory bank number (0-3)
973 * Return the powerdomain pwrdm's current memory power state for bank
974 * x. Returns -EINVAL if the powerdomain pointer is null, -EEXIST if
975 * the target memory bank does not exist or is not controllable, or
976 * returns the current memory power state upon success.
978 int pwrdm_read_mem_pwrst(struct powerdomain
*pwrdm
, u8 bank
)
985 if (pwrdm
->banks
< (bank
+ 1))
989 * The register bit names below may not correspond to the
990 * actual names of the bits in each powerdomain's register,
991 * but the type of value returned is the same for each
996 m
= OMAP3430_SHAREDL1CACHEFLATSTATEST_MASK
;
999 m
= OMAP3430_L1FLATMEMSTATEST_MASK
;
1002 m
= OMAP3430_SHAREDL2CACHEFLATSTATEST_MASK
;
1005 m
= OMAP3430_L2FLATMEMSTATEST_MASK
;
1008 WARN_ON(1); /* should never happen */
1012 return prm_read_mod_bits_shift(pwrdm
->prcm_offs
, PM_PWSTST
, m
);
1016 * pwrdm_read_prev_mem_pwrst - get previous memory bank power state
1017 * @pwrdm: struct powerdomain * to get previous memory bank power state
1018 * @bank: memory bank number (0-3)
1020 * Return the powerdomain pwrdm's previous memory power state for bank
1021 * x. Returns -EINVAL if the powerdomain pointer is null, -EEXIST if
1022 * the target memory bank does not exist or is not controllable, or
1023 * returns the previous memory power state upon success.
1025 int pwrdm_read_prev_mem_pwrst(struct powerdomain
*pwrdm
, u8 bank
)
1032 if (pwrdm
->banks
< (bank
+ 1))
1036 * The register bit names below may not correspond to the
1037 * actual names of the bits in each powerdomain's register,
1038 * but the type of value returned is the same for each
1043 m
= OMAP3430_LASTMEM1STATEENTERED_MASK
;
1046 m
= OMAP3430_LASTMEM2STATEENTERED_MASK
;
1049 m
= OMAP3430_LASTSHAREDL2CACHEFLATSTATEENTERED_MASK
;
1052 m
= OMAP3430_LASTL2FLATMEMSTATEENTERED_MASK
;
1055 WARN_ON(1); /* should never happen */
1059 return prm_read_mod_bits_shift(pwrdm
->prcm_offs
,
1060 OMAP3430_PM_PREPWSTST
, m
);
1064 * pwrdm_clear_all_prev_pwrst - clear previous powerstate register for a pwrdm
1065 * @pwrdm: struct powerdomain * to clear
1067 * Clear the powerdomain's previous power state register. Clears the
1068 * entire register, including logic and memory bank previous power states.
1069 * Returns -EINVAL if the powerdomain pointer is null, or returns 0 upon
1072 int pwrdm_clear_all_prev_pwrst(struct powerdomain
*pwrdm
)
1078 * XXX should get the powerdomain's current state here;
1079 * warn & fail if it is not ON.
1082 pr_debug("powerdomain: clearing previous power state reg for %s\n",
1085 prm_write_mod_reg(0, pwrdm
->prcm_offs
, OMAP3430_PM_PREPWSTST
);
1091 * pwrdm_enable_hdwr_sar - enable automatic hardware SAR for a pwrdm
1092 * @pwrdm: struct powerdomain *
1094 * Enable automatic context save-and-restore upon power state change
1095 * for some devices in a powerdomain. Warning: this only affects a
1096 * subset of devices in a powerdomain; check the TRM closely. Returns
1097 * -EINVAL if the powerdomain pointer is null or if the powerdomain
1098 * does not support automatic save-and-restore, or returns 0 upon
1101 int pwrdm_enable_hdwr_sar(struct powerdomain
*pwrdm
)
1106 if (!(pwrdm
->flags
& PWRDM_HAS_HDWR_SAR
))
1109 pr_debug("powerdomain: %s: setting SAVEANDRESTORE bit\n",
1112 prm_rmw_mod_reg_bits(0, 1 << OMAP3430ES2_SAVEANDRESTORE_SHIFT
,
1113 pwrdm
->prcm_offs
, PM_PWSTCTRL
);
1119 * pwrdm_disable_hdwr_sar - disable automatic hardware SAR for a pwrdm
1120 * @pwrdm: struct powerdomain *
1122 * Disable automatic context save-and-restore upon power state change
1123 * for some devices in a powerdomain. Warning: this only affects a
1124 * subset of devices in a powerdomain; check the TRM closely. Returns
1125 * -EINVAL if the powerdomain pointer is null or if the powerdomain
1126 * does not support automatic save-and-restore, or returns 0 upon
1129 int pwrdm_disable_hdwr_sar(struct powerdomain
*pwrdm
)
1134 if (!(pwrdm
->flags
& PWRDM_HAS_HDWR_SAR
))
1137 pr_debug("powerdomain: %s: clearing SAVEANDRESTORE bit\n",
1140 prm_rmw_mod_reg_bits(1 << OMAP3430ES2_SAVEANDRESTORE_SHIFT
, 0,
1141 pwrdm
->prcm_offs
, PM_PWSTCTRL
);
1147 * pwrdm_has_hdwr_sar - test whether powerdomain supports hardware SAR
1148 * @pwrdm: struct powerdomain *
1150 * Returns 1 if powerdomain 'pwrdm' supports hardware save-and-restore
1151 * for some devices, or 0 if it does not.
1153 bool pwrdm_has_hdwr_sar(struct powerdomain
*pwrdm
)
1155 return (pwrdm
&& pwrdm
->flags
& PWRDM_HAS_HDWR_SAR
) ? 1 : 0;
1159 * pwrdm_wait_transition - wait for powerdomain power transition to finish
1160 * @pwrdm: struct powerdomain * to wait for
1162 * If the powerdomain pwrdm is in the process of a state transition,
1163 * spin until it completes the power transition, or until an iteration
1164 * bailout value is reached. Returns -EINVAL if the powerdomain
1165 * pointer is null, -EAGAIN if the bailout value was reached, or
1166 * returns 0 upon success.
1168 int pwrdm_wait_transition(struct powerdomain
*pwrdm
)
1176 * REVISIT: pwrdm_wait_transition() may be better implemented
1177 * via a callback and a periodic timer check -- how long do we expect
1178 * powerdomain transitions to take?
1181 /* XXX Is this udelay() value meaningful? */
1182 while ((prm_read_mod_reg(pwrdm
->prcm_offs
, PM_PWSTST
) &
1183 OMAP_INTRANSITION
) &&
1184 (c
++ < PWRDM_TRANSITION_BAILOUT
))
1187 if (c
> PWRDM_TRANSITION_BAILOUT
) {
1188 printk(KERN_ERR
"powerdomain: waited too long for "
1189 "powerdomain %s to complete transition\n", pwrdm
->name
);
1193 pr_debug("powerdomain: completed transition in %d loops\n", c
);
1198 int pwrdm_state_switch(struct powerdomain
*pwrdm
)
1200 return _pwrdm_state_switch(pwrdm
, PWRDM_STATE_NOW
);
1203 int pwrdm_clkdm_state_switch(struct clockdomain
*clkdm
)
1205 if (clkdm
!= NULL
&& clkdm
->pwrdm
.ptr
!= NULL
) {
1206 pwrdm_wait_transition(clkdm
->pwrdm
.ptr
);
1207 return pwrdm_state_switch(clkdm
->pwrdm
.ptr
);
1212 int pwrdm_clk_state_switch(struct clk
*clk
)
1214 if (clk
!= NULL
&& clk
->clkdm
!= NULL
)
1215 return pwrdm_clkdm_state_switch(clk
->clkdm
);
1219 int pwrdm_pre_transition(void)
1221 pwrdm_for_each(_pwrdm_pre_transition_cb
, NULL
);
1225 int pwrdm_post_transition(void)
1227 pwrdm_for_each(_pwrdm_post_transition_cb
, NULL
);