2 * OMAP powerdomain control
4 * Copyright (C) 2007-2008 Texas Instruments, Inc.
5 * Copyright (C) 2007-2009 Nokia Corporation
7 * Written by Paul Walmsley
9 * Added OMAP4 specific support by Abhijit Pagare <abhijitpagare@ti.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
68 #define OMAP_MEM1_RETSTATE_MASK OMAP3430_L1FLATMEMRETSTATE
69 #define OMAP_MEM2_RETSTATE_MASK OMAP3430_SHAREDL2CACHEFLATRETSTATE
70 #define OMAP_MEM3_RETSTATE_MASK OMAP3430_L2FLATMEMRETSTATE
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 < 4; i++)
126 pwrdm->state_counter[i] = 0;
128 pwrdm_wait_transition(pwrdm);
129 pwrdm->state = pwrdm_read_pwrst(pwrdm);
130 pwrdm->state_counter[pwrdm->state] = 1;
132 pr_debug("powerdomain: registered %s\n", pwrdm->name);
137 static int _pwrdm_state_switch(struct powerdomain *pwrdm, int flag)
146 state = pwrdm_read_pwrst(pwrdm);
149 case PWRDM_STATE_NOW:
152 case PWRDM_STATE_PREV:
153 prev = pwrdm_read_prev_pwrst(pwrdm);
154 if (pwrdm->state != prev)
155 pwrdm->state_counter[prev]++;
162 pwrdm->state_counter[state]++;
164 pm_dbg_update_time(pwrdm, prev);
166 pwrdm->state = state;
171 static int _pwrdm_pre_transition_cb(struct powerdomain *pwrdm, void *unused)
173 pwrdm_clear_all_prev_pwrst(pwrdm);
174 _pwrdm_state_switch(pwrdm, PWRDM_STATE_NOW);
178 static int _pwrdm_post_transition_cb(struct powerdomain *pwrdm, void *unused)
180 _pwrdm_state_switch(pwrdm, PWRDM_STATE_PREV);
184 /* Public functions */
187 * pwrdm_init - set up the powerdomain layer
189 * Loop through the list of powerdomains, registering all that are
190 * available on the current CPU. If pwrdm_list is supplied and not
191 * null, all of the referenced powerdomains will be registered. No
194 void pwrdm_init(struct powerdomain **pwrdm_list)
196 struct powerdomain **p = NULL;
198 if (cpu_is_omap24xx() | cpu_is_omap34xx()) {
199 pwrstctrl_reg_offs = OMAP2_PM_PWSTCTRL;
200 pwrstst_reg_offs = OMAP2_PM_PWSTST;
201 } else if (cpu_is_omap44xx()) {
202 pwrstctrl_reg_offs = OMAP4_PM_PWSTCTRL;
203 pwrstst_reg_offs = OMAP4_PM_PWSTST;
205 printk(KERN_ERR "Power Domain struct not supported for " \
211 for (p = pwrdm_list; *p; p++)
217 * pwrdm_lookup - look up a powerdomain by name, return a pointer
218 * @name: name of powerdomain
220 * Find a registered powerdomain by its name. Returns a pointer to the
221 * struct powerdomain if found, or NULL otherwise.
223 struct powerdomain *pwrdm_lookup(const char *name)
225 struct powerdomain *pwrdm;
230 pwrdm = _pwrdm_lookup(name);
236 * pwrdm_for_each - call function on each registered clockdomain
237 * @fn: callback function *
239 * Call the supplied function for each registered powerdomain. The
240 * callback function can return anything but 0 to bail out early from
241 * the iterator. Returns the last return value of the callback function, which
242 * should be 0 for success or anything else to indicate failure; or -EINVAL if
243 * the function pointer is null.
245 int pwrdm_for_each(int (*fn)(struct powerdomain *pwrdm, void *user),
248 struct powerdomain *temp_pwrdm;
254 list_for_each_entry(temp_pwrdm, &pwrdm_list, node) {
255 ret = (*fn)(temp_pwrdm, user);
264 * pwrdm_add_clkdm - add a clockdomain to a powerdomain
265 * @pwrdm: struct powerdomain * to add the clockdomain to
266 * @clkdm: struct clockdomain * to associate with a powerdomain
268 * Associate the clockdomain 'clkdm' with a powerdomain 'pwrdm'. This
269 * enables the use of pwrdm_for_each_clkdm(). Returns -EINVAL if
270 * presented with invalid pointers; -ENOMEM if memory could not be allocated;
273 int pwrdm_add_clkdm(struct powerdomain *pwrdm, struct clockdomain *clkdm)
278 if (!pwrdm || !clkdm)
281 pr_debug("powerdomain: associating clockdomain %s with powerdomain "
282 "%s\n", clkdm->name, pwrdm->name);
284 for (i = 0; i < PWRDM_MAX_CLKDMS; i++) {
285 if (!pwrdm->pwrdm_clkdms[i])
288 if (pwrdm->pwrdm_clkdms[i] == clkdm) {
295 if (i == PWRDM_MAX_CLKDMS) {
296 pr_debug("powerdomain: increase PWRDM_MAX_CLKDMS for "
297 "pwrdm %s clkdm %s\n", pwrdm->name, clkdm->name);
303 pwrdm->pwrdm_clkdms[i] = clkdm;
312 * pwrdm_del_clkdm - remove a clockdomain from a powerdomain
313 * @pwrdm: struct powerdomain * to add the clockdomain to
314 * @clkdm: struct clockdomain * to associate with a powerdomain
316 * Dissociate the clockdomain 'clkdm' from the powerdomain
317 * 'pwrdm'. Returns -EINVAL if presented with invalid pointers;
318 * -ENOENT if the clkdm was not associated with the powerdomain, or 0
321 int pwrdm_del_clkdm(struct powerdomain *pwrdm, struct clockdomain *clkdm)
326 if (!pwrdm || !clkdm)
329 pr_debug("powerdomain: dissociating clockdomain %s from powerdomain "
330 "%s\n", clkdm->name, pwrdm->name);
332 for (i = 0; i < PWRDM_MAX_CLKDMS; i++)
333 if (pwrdm->pwrdm_clkdms[i] == clkdm)
336 if (i == PWRDM_MAX_CLKDMS) {
337 pr_debug("powerdomain: clkdm %s not associated with pwrdm "
338 "%s ?!\n", clkdm->name, pwrdm->name);
343 pwrdm->pwrdm_clkdms[i] = NULL;
352 * pwrdm_for_each_clkdm - call function on each clkdm in a pwrdm
353 * @pwrdm: struct powerdomain * to iterate over
354 * @fn: callback function *
356 * Call the supplied function for each clockdomain in the powerdomain
357 * 'pwrdm'. The callback function can return anything but 0 to bail
358 * out early from the iterator. Returns -EINVAL if presented with
359 * invalid pointers; or passes along the last return value of the
360 * callback function, which should be 0 for success or anything else
361 * to indicate failure.
363 int pwrdm_for_each_clkdm(struct powerdomain *pwrdm,
364 int (*fn)(struct powerdomain *pwrdm,
365 struct clockdomain *clkdm))
373 for (i = 0; i < PWRDM_MAX_CLKDMS && !ret; i++)
374 ret = (*fn)(pwrdm, pwrdm->pwrdm_clkdms[i]);
380 * pwrdm_get_mem_bank_count - get number of memory banks in this powerdomain
381 * @pwrdm: struct powerdomain *
383 * Return the number of controllable memory banks in powerdomain pwrdm,
384 * starting with 1. Returns -EINVAL if the powerdomain pointer is null.
386 int pwrdm_get_mem_bank_count(struct powerdomain *pwrdm)
395 * pwrdm_set_next_pwrst - set next powerdomain power state
396 * @pwrdm: struct powerdomain * to set
397 * @pwrst: one of the PWRDM_POWER_* macros
399 * Set the powerdomain pwrdm's next power state to pwrst. The powerdomain
400 * may not enter this state immediately if the preconditions for this state
401 * have not been satisfied. Returns -EINVAL if the powerdomain pointer is
402 * null or if the power state is invalid for the powerdomin, or returns 0
405 int pwrdm_set_next_pwrst(struct powerdomain *pwrdm, u8 pwrst)
410 if (!(pwrdm->pwrsts & (1 << pwrst)))
413 pr_debug("powerdomain: setting next powerstate for %s to %0x\n",
416 prm_rmw_mod_reg_bits(OMAP_POWERSTATE_MASK,
417 (pwrst << OMAP_POWERSTATE_SHIFT),
418 pwrdm->prcm_offs, pwrstctrl_reg_offs);
424 * pwrdm_read_next_pwrst - get next powerdomain power state
425 * @pwrdm: struct powerdomain * to get power state
427 * Return the powerdomain pwrdm's next power state. Returns -EINVAL
428 * if the powerdomain pointer is null or returns the next power state
431 int pwrdm_read_next_pwrst(struct powerdomain *pwrdm)
436 return prm_read_mod_bits_shift(pwrdm->prcm_offs,
437 pwrstctrl_reg_offs, OMAP_POWERSTATE_MASK);
441 * pwrdm_read_pwrst - get current powerdomain power state
442 * @pwrdm: struct powerdomain * to get power state
444 * Return the powerdomain pwrdm's current power state. Returns -EINVAL
445 * if the powerdomain pointer is null or returns the current power state
448 int pwrdm_read_pwrst(struct powerdomain *pwrdm)
453 return prm_read_mod_bits_shift(pwrdm->prcm_offs,
454 pwrstst_reg_offs, OMAP_POWERSTATEST_MASK);
458 * pwrdm_read_prev_pwrst - get previous powerdomain power state
459 * @pwrdm: struct powerdomain * to get previous power state
461 * Return the powerdomain pwrdm's previous power state. Returns -EINVAL
462 * if the powerdomain pointer is null or returns the previous power state
465 int pwrdm_read_prev_pwrst(struct powerdomain *pwrdm)
470 return prm_read_mod_bits_shift(pwrdm->prcm_offs, OMAP3430_PM_PREPWSTST,
471 OMAP3430_LASTPOWERSTATEENTERED_MASK);
475 * pwrdm_set_logic_retst - set powerdomain logic power state upon retention
476 * @pwrdm: struct powerdomain * to set
477 * @pwrst: one of the PWRDM_POWER_* macros
479 * Set the next power state that the logic portion of the powerdomain
480 * pwrdm will enter when the powerdomain enters retention. This will
481 * be either RETENTION or OFF, if supported. Returns -EINVAL if the
482 * powerdomain pointer is null or the target power state is not not
483 * supported, or returns 0 upon success.
485 int pwrdm_set_logic_retst(struct powerdomain *pwrdm, u8 pwrst)
490 if (!(pwrdm->pwrsts_logic_ret & (1 << pwrst)))
493 pr_debug("powerdomain: setting next logic powerstate for %s to %0x\n",
497 * The register bit names below may not correspond to the
498 * actual names of the bits in each powerdomain's register,
499 * but the type of value returned is the same for each
502 prm_rmw_mod_reg_bits(OMAP3430_LOGICL1CACHERETSTATE,
503 (pwrst << __ffs(OMAP3430_LOGICL1CACHERETSTATE)),
504 pwrdm->prcm_offs, pwrstctrl_reg_offs);
510 * pwrdm_set_mem_onst - set memory power state while powerdomain ON
511 * @pwrdm: struct powerdomain * to set
512 * @bank: memory bank number to set (0-3)
513 * @pwrst: one of the PWRDM_POWER_* macros
515 * Set the next power state that memory bank x of the powerdomain
516 * pwrdm will enter when the powerdomain enters the ON state. Bank
517 * will be a number from 0 to 3, and represents different types of
518 * memory, depending on the powerdomain. Returns -EINVAL if the
519 * powerdomain pointer is null or the target power state is not not
520 * supported for this memory bank, -EEXIST if the target memory bank
521 * does not exist or is not controllable, or returns 0 upon success.
523 int pwrdm_set_mem_onst(struct powerdomain *pwrdm, u8 bank, u8 pwrst)
530 if (pwrdm->banks < (bank + 1))
533 if (!(pwrdm->pwrsts_mem_on[bank] & (1 << pwrst)))
536 pr_debug("powerdomain: setting next memory powerstate for domain %s "
537 "bank %0x while pwrdm-ON to %0x\n", pwrdm->name, bank, pwrst);
540 * The register bit names below may not correspond to the
541 * actual names of the bits in each powerdomain's register,
542 * but the type of value returned is the same for each
547 m = OMAP_MEM0_ONSTATE_MASK;
550 m = OMAP_MEM1_ONSTATE_MASK;
553 m = OMAP_MEM2_ONSTATE_MASK;
556 m = OMAP_MEM3_ONSTATE_MASK;
559 m = OMAP_MEM4_ONSTATE_MASK;
562 WARN_ON(1); /* should never happen */
566 prm_rmw_mod_reg_bits(m, (pwrst << __ffs(m)),
567 pwrdm->prcm_offs, pwrstctrl_reg_offs);
573 * pwrdm_set_mem_retst - set memory power state while powerdomain in RET
574 * @pwrdm: struct powerdomain * to set
575 * @bank: memory bank number to set (0-3)
576 * @pwrst: one of the PWRDM_POWER_* macros
578 * Set the next power state that memory bank x of the powerdomain
579 * pwrdm will enter when the powerdomain enters the RETENTION state.
580 * Bank will be a number from 0 to 3, and represents different types
581 * of memory, depending on the powerdomain. pwrst will be either
582 * RETENTION or OFF, if supported. Returns -EINVAL if the powerdomain
583 * pointer is null or the target power state is not not supported for
584 * this memory bank, -EEXIST if the target memory bank does not exist
585 * or is not controllable, or returns 0 upon success.
587 int pwrdm_set_mem_retst(struct powerdomain *pwrdm, u8 bank, u8 pwrst)
594 if (pwrdm->banks < (bank + 1))
597 if (!(pwrdm->pwrsts_mem_ret[bank] & (1 << pwrst)))
600 pr_debug("powerdomain: setting next memory powerstate for domain %s "
601 "bank %0x while pwrdm-RET to %0x\n", pwrdm->name, bank, pwrst);
604 * The register bit names below may not correspond to the
605 * actual names of the bits in each powerdomain's register,
606 * but the type of value returned is the same for each
611 m = OMAP_MEM0_RETSTATE_MASK;
614 m = OMAP_MEM1_RETSTATE_MASK;
617 m = OMAP_MEM2_RETSTATE_MASK;
620 m = OMAP_MEM3_RETSTATE_MASK;
623 m = OMAP_MEM4_RETSTATE_MASK;
626 WARN_ON(1); /* should never happen */
630 prm_rmw_mod_reg_bits(m, (pwrst << __ffs(m)), pwrdm->prcm_offs,
637 * pwrdm_read_logic_pwrst - get current powerdomain logic retention power state
638 * @pwrdm: struct powerdomain * to get current logic retention power state
640 * Return the current power state that the logic portion of
641 * powerdomain pwrdm will enter
642 * Returns -EINVAL if the powerdomain pointer is null or returns the
643 * current logic retention power state upon success.
645 int pwrdm_read_logic_pwrst(struct powerdomain *pwrdm)
650 return prm_read_mod_bits_shift(pwrdm->prcm_offs,
651 pwrstst_reg_offs, OMAP3430_LOGICSTATEST);
655 * pwrdm_read_prev_logic_pwrst - get previous powerdomain logic power state
656 * @pwrdm: struct powerdomain * to get previous logic power state
658 * Return the powerdomain pwrdm's logic power state. Returns -EINVAL
659 * if the powerdomain pointer is null or returns the previous logic
660 * power state upon success.
662 int pwrdm_read_prev_logic_pwrst(struct powerdomain *pwrdm)
668 * The register bit names below may not correspond to the
669 * actual names of the bits in each powerdomain's register,
670 * but the type of value returned is the same for each
673 return prm_read_mod_bits_shift(pwrdm->prcm_offs, OMAP3430_PM_PREPWSTST,
674 OMAP3430_LASTLOGICSTATEENTERED);
678 * pwrdm_read_mem_pwrst - get current memory bank power state
679 * @pwrdm: struct powerdomain * to get current memory bank power state
680 * @bank: memory bank number (0-3)
682 * Return the powerdomain pwrdm's current memory power state for bank
683 * x. Returns -EINVAL if the powerdomain pointer is null, -EEXIST if
684 * the target memory bank does not exist or is not controllable, or
685 * returns the current memory power state upon success.
687 int pwrdm_read_mem_pwrst(struct powerdomain *pwrdm, u8 bank)
694 if (pwrdm->banks < (bank + 1))
697 if (pwrdm->flags & PWRDM_HAS_MPU_QUIRK)
701 * The register bit names below may not correspond to the
702 * actual names of the bits in each powerdomain's register,
703 * but the type of value returned is the same for each
708 m = OMAP_MEM0_STATEST_MASK;
711 m = OMAP_MEM1_STATEST_MASK;
714 m = OMAP_MEM2_STATEST_MASK;
717 m = OMAP_MEM3_STATEST_MASK;
720 m = OMAP_MEM4_STATEST_MASK;
723 WARN_ON(1); /* should never happen */
727 return prm_read_mod_bits_shift(pwrdm->prcm_offs,
728 pwrstst_reg_offs, m);
732 * pwrdm_read_prev_mem_pwrst - get previous memory bank power state
733 * @pwrdm: struct powerdomain * to get previous memory bank power state
734 * @bank: memory bank number (0-3)
736 * Return the powerdomain pwrdm's previous memory power state for bank
737 * x. 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 previous memory power state upon success.
741 int pwrdm_read_prev_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 = OMAP3430_LASTMEM1STATEENTERED_MASK;
765 m = OMAP3430_LASTMEM2STATEENTERED_MASK;
768 m = OMAP3430_LASTSHAREDL2CACHEFLATSTATEENTERED_MASK;
771 m = OMAP3430_LASTL2FLATMEMSTATEENTERED_MASK;
774 WARN_ON(1); /* should never happen */
778 return prm_read_mod_bits_shift(pwrdm->prcm_offs,
779 OMAP3430_PM_PREPWSTST, m);
783 * pwrdm_clear_all_prev_pwrst - clear previous powerstate register for a pwrdm
784 * @pwrdm: struct powerdomain * to clear
786 * Clear the powerdomain's previous power state register. Clears the
787 * entire register, including logic and memory bank previous power states.
788 * Returns -EINVAL if the powerdomain pointer is null, or returns 0 upon
791 int pwrdm_clear_all_prev_pwrst(struct powerdomain *pwrdm)
797 * XXX should get the powerdomain's current state here;
798 * warn & fail if it is not ON.
801 pr_debug("powerdomain: clearing previous power state reg for %s\n",
804 prm_write_mod_reg(0, pwrdm->prcm_offs, OMAP3430_PM_PREPWSTST);
810 * pwrdm_enable_hdwr_sar - enable automatic hardware SAR for a pwrdm
811 * @pwrdm: struct powerdomain *
813 * Enable automatic context save-and-restore upon power state change
814 * for some devices in a powerdomain. Warning: this only affects a
815 * subset of devices in a powerdomain; check the TRM closely. Returns
816 * -EINVAL if the powerdomain pointer is null or if the powerdomain
817 * does not support automatic save-and-restore, or returns 0 upon
820 int pwrdm_enable_hdwr_sar(struct powerdomain *pwrdm)
825 if (!(pwrdm->flags & PWRDM_HAS_HDWR_SAR))
828 pr_debug("powerdomain: %s: setting SAVEANDRESTORE bit\n",
831 prm_rmw_mod_reg_bits(0, 1 << OMAP3430ES2_SAVEANDRESTORE_SHIFT,
832 pwrdm->prcm_offs, pwrstctrl_reg_offs);
838 * pwrdm_disable_hdwr_sar - disable automatic hardware SAR for a pwrdm
839 * @pwrdm: struct powerdomain *
841 * Disable automatic context save-and-restore upon power state change
842 * for some devices in a powerdomain. Warning: this only affects a
843 * subset of devices in a powerdomain; check the TRM closely. Returns
844 * -EINVAL if the powerdomain pointer is null or if the powerdomain
845 * does not support automatic save-and-restore, or returns 0 upon
848 int pwrdm_disable_hdwr_sar(struct powerdomain *pwrdm)
853 if (!(pwrdm->flags & PWRDM_HAS_HDWR_SAR))
856 pr_debug("powerdomain: %s: clearing SAVEANDRESTORE bit\n",
859 prm_rmw_mod_reg_bits(1 << OMAP3430ES2_SAVEANDRESTORE_SHIFT, 0,
860 pwrdm->prcm_offs, pwrstctrl_reg_offs);
866 * pwrdm_has_hdwr_sar - test whether powerdomain supports hardware SAR
867 * @pwrdm: struct powerdomain *
869 * Returns 1 if powerdomain 'pwrdm' supports hardware save-and-restore
870 * for some devices, or 0 if it does not.
872 bool pwrdm_has_hdwr_sar(struct powerdomain *pwrdm)
874 return (pwrdm && pwrdm->flags & PWRDM_HAS_HDWR_SAR) ? 1 : 0;
878 * pwrdm_wait_transition - wait for powerdomain power transition to finish
879 * @pwrdm: struct powerdomain * to wait for
881 * If the powerdomain pwrdm is in the process of a state transition,
882 * spin until it completes the power transition, or until an iteration
883 * bailout value is reached. Returns -EINVAL if the powerdomain
884 * pointer is null, -EAGAIN if the bailout value was reached, or
885 * returns 0 upon success.
887 int pwrdm_wait_transition(struct powerdomain *pwrdm)
895 * REVISIT: pwrdm_wait_transition() may be better implemented
896 * via a callback and a periodic timer check -- how long do we expect
897 * powerdomain transitions to take?
900 /* XXX Is this udelay() value meaningful? */
901 while ((prm_read_mod_reg(pwrdm->prcm_offs, pwrstst_reg_offs) &
902 OMAP_INTRANSITION) &&
903 (c++ < PWRDM_TRANSITION_BAILOUT))
906 if (c > PWRDM_TRANSITION_BAILOUT) {
907 printk(KERN_ERR "powerdomain: waited too long for "
908 "powerdomain %s to complete transition\n", pwrdm->name);
912 pr_debug("powerdomain: completed transition in %d loops\n", c);
917 int pwrdm_state_switch(struct powerdomain *pwrdm)
919 return _pwrdm_state_switch(pwrdm, PWRDM_STATE_NOW);
922 int pwrdm_clkdm_state_switch(struct clockdomain *clkdm)
924 if (clkdm != NULL && clkdm->pwrdm.ptr != NULL) {
925 pwrdm_wait_transition(clkdm->pwrdm.ptr);
926 return pwrdm_state_switch(clkdm->pwrdm.ptr);
931 int pwrdm_clk_state_switch(struct clk *clk)
933 if (clk != NULL && clk->clkdm != NULL)
934 return pwrdm_clkdm_state_switch(clk->clkdm);
938 int pwrdm_pre_transition(void)
940 pwrdm_for_each(_pwrdm_pre_transition_cb, NULL);
944 int pwrdm_post_transition(void)
946 pwrdm_for_each(_pwrdm_post_transition_cb, NULL);