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 < PWRDM_MAX_PWRSTS; 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
188 * @pwrdm_list: array of struct powerdomain pointers to register
190 * Loop through the array of powerdomains @pwrdm_list, registering all
191 * that are available on the current CPU. If pwrdm_list is supplied
192 * and not null, all of the referenced powerdomains will be
193 * registered. No return value. XXX pwrdm_list is not really a
194 * "list"; it is an array. Rename appropriately.
196 void pwrdm_init(struct powerdomain **pwrdm_list)
198 struct powerdomain **p = NULL;
200 if (cpu_is_omap24xx() | cpu_is_omap34xx()) {
201 pwrstctrl_reg_offs = OMAP2_PM_PWSTCTRL;
202 pwrstst_reg_offs = OMAP2_PM_PWSTST;
203 } else if (cpu_is_omap44xx()) {
204 pwrstctrl_reg_offs = OMAP4_PM_PWSTCTRL;
205 pwrstst_reg_offs = OMAP4_PM_PWSTST;
207 printk(KERN_ERR "Power Domain struct not supported for " \
213 for (p = pwrdm_list; *p; p++)
219 * pwrdm_lookup - look up a powerdomain by name, return a pointer
220 * @name: name of powerdomain
222 * Find a registered powerdomain by its name @name. Returns a pointer
223 * to the struct powerdomain if found, or NULL otherwise.
225 struct powerdomain *pwrdm_lookup(const char *name)
227 struct powerdomain *pwrdm;
232 pwrdm = _pwrdm_lookup(name);
238 * pwrdm_for_each - call function on each registered clockdomain
239 * @fn: callback function *
241 * Call the supplied function @fn for each registered powerdomain.
242 * The callback function @fn can return anything but 0 to bail out
243 * early from the iterator. Returns the last return value of the
244 * callback function, which should be 0 for success or anything else
245 * to indicate failure; or -EINVAL if the function pointer is null.
247 int pwrdm_for_each(int (*fn)(struct powerdomain *pwrdm, void *user),
250 struct powerdomain *temp_pwrdm;
256 list_for_each_entry(temp_pwrdm, &pwrdm_list, node) {
257 ret = (*fn)(temp_pwrdm, user);
266 * pwrdm_add_clkdm - add a clockdomain to a powerdomain
267 * @pwrdm: struct powerdomain * to add the clockdomain to
268 * @clkdm: struct clockdomain * to associate with a powerdomain
270 * Associate the clockdomain @clkdm with a powerdomain @pwrdm. This
271 * enables the use of pwrdm_for_each_clkdm(). Returns -EINVAL if
272 * presented with invalid pointers; -ENOMEM if memory could not be allocated;
275 int pwrdm_add_clkdm(struct powerdomain *pwrdm, struct clockdomain *clkdm)
280 if (!pwrdm || !clkdm)
283 pr_debug("powerdomain: associating clockdomain %s with powerdomain "
284 "%s\n", clkdm->name, pwrdm->name);
286 for (i = 0; i < PWRDM_MAX_CLKDMS; i++) {
287 if (!pwrdm->pwrdm_clkdms[i])
290 if (pwrdm->pwrdm_clkdms[i] == clkdm) {
297 if (i == PWRDM_MAX_CLKDMS) {
298 pr_debug("powerdomain: increase PWRDM_MAX_CLKDMS for "
299 "pwrdm %s clkdm %s\n", pwrdm->name, clkdm->name);
305 pwrdm->pwrdm_clkdms[i] = clkdm;
314 * pwrdm_del_clkdm - remove a clockdomain from a powerdomain
315 * @pwrdm: struct powerdomain * to add the clockdomain to
316 * @clkdm: struct clockdomain * to associate with a powerdomain
318 * Dissociate the clockdomain @clkdm from the powerdomain
319 * @pwrdm. Returns -EINVAL if presented with invalid pointers; -ENOENT
320 * if @clkdm was not associated with the powerdomain, or 0 upon
323 int pwrdm_del_clkdm(struct powerdomain *pwrdm, struct clockdomain *clkdm)
328 if (!pwrdm || !clkdm)
331 pr_debug("powerdomain: dissociating clockdomain %s from powerdomain "
332 "%s\n", clkdm->name, pwrdm->name);
334 for (i = 0; i < PWRDM_MAX_CLKDMS; i++)
335 if (pwrdm->pwrdm_clkdms[i] == clkdm)
338 if (i == PWRDM_MAX_CLKDMS) {
339 pr_debug("powerdomain: clkdm %s not associated with pwrdm "
340 "%s ?!\n", clkdm->name, pwrdm->name);
345 pwrdm->pwrdm_clkdms[i] = NULL;
354 * pwrdm_for_each_clkdm - call function on each clkdm in a pwrdm
355 * @pwrdm: struct powerdomain * to iterate over
356 * @fn: callback function *
358 * Call the supplied function @fn for each clockdomain in the powerdomain
359 * @pwrdm. The callback function can return anything but 0 to bail
360 * out early from the iterator. Returns -EINVAL if presented with
361 * invalid pointers; or passes along the last return value of the
362 * callback function, which should be 0 for success or anything else
363 * to indicate failure.
365 int pwrdm_for_each_clkdm(struct powerdomain *pwrdm,
366 int (*fn)(struct powerdomain *pwrdm,
367 struct clockdomain *clkdm))
375 for (i = 0; i < PWRDM_MAX_CLKDMS && !ret; i++)
376 ret = (*fn)(pwrdm, pwrdm->pwrdm_clkdms[i]);
382 * pwrdm_get_mem_bank_count - get number of memory banks in this powerdomain
383 * @pwrdm: struct powerdomain *
385 * Return the number of controllable memory banks in powerdomain @pwrdm,
386 * starting with 1. Returns -EINVAL if the powerdomain pointer is null.
388 int pwrdm_get_mem_bank_count(struct powerdomain *pwrdm)
397 * pwrdm_set_next_pwrst - set next powerdomain power state
398 * @pwrdm: struct powerdomain * to set
399 * @pwrst: one of the PWRDM_POWER_* macros
401 * Set the powerdomain @pwrdm's next power state to @pwrst. The powerdomain
402 * may not enter this state immediately if the preconditions for this state
403 * have not been satisfied. Returns -EINVAL if the powerdomain pointer is
404 * null or if the power state is invalid for the powerdomin, or returns 0
407 int pwrdm_set_next_pwrst(struct powerdomain *pwrdm, u8 pwrst)
412 if (!(pwrdm->pwrsts & (1 << pwrst)))
415 pr_debug("powerdomain: setting next powerstate for %s to %0x\n",
418 prm_rmw_mod_reg_bits(OMAP_POWERSTATE_MASK,
419 (pwrst << OMAP_POWERSTATE_SHIFT),
420 pwrdm->prcm_offs, pwrstctrl_reg_offs);
426 * pwrdm_read_next_pwrst - get next powerdomain power state
427 * @pwrdm: struct powerdomain * to get power state
429 * Return the powerdomain @pwrdm's next power state. Returns -EINVAL
430 * if the powerdomain pointer is null or returns the next power state
433 int pwrdm_read_next_pwrst(struct powerdomain *pwrdm)
438 return prm_read_mod_bits_shift(pwrdm->prcm_offs,
439 pwrstctrl_reg_offs, OMAP_POWERSTATE_MASK);
443 * pwrdm_read_pwrst - get current powerdomain power state
444 * @pwrdm: struct powerdomain * to get power state
446 * Return the powerdomain @pwrdm's current power state. Returns -EINVAL
447 * if the powerdomain pointer is null or returns the current power state
450 int pwrdm_read_pwrst(struct powerdomain *pwrdm)
455 return prm_read_mod_bits_shift(pwrdm->prcm_offs,
456 pwrstst_reg_offs, OMAP_POWERSTATEST_MASK);
460 * pwrdm_read_prev_pwrst - get previous powerdomain power state
461 * @pwrdm: struct powerdomain * to get previous power state
463 * Return the powerdomain @pwrdm's previous power state. Returns -EINVAL
464 * if the powerdomain pointer is null or returns the previous power state
467 int pwrdm_read_prev_pwrst(struct powerdomain *pwrdm)
472 return prm_read_mod_bits_shift(pwrdm->prcm_offs, OMAP3430_PM_PREPWSTST,
473 OMAP3430_LASTPOWERSTATEENTERED_MASK);
477 * pwrdm_set_logic_retst - set powerdomain logic power state upon retention
478 * @pwrdm: struct powerdomain * to set
479 * @pwrst: one of the PWRDM_POWER_* macros
481 * Set the next power state @pwrst that the logic portion of the
482 * powerdomain @pwrdm will enter when the powerdomain enters retention.
483 * This will be either RETENTION or OFF, if supported. Returns
484 * -EINVAL if the powerdomain pointer is null or the target power
485 * state is not not supported, or returns 0 upon success.
487 int pwrdm_set_logic_retst(struct powerdomain *pwrdm, u8 pwrst)
492 if (!(pwrdm->pwrsts_logic_ret & (1 << pwrst)))
495 pr_debug("powerdomain: setting next logic powerstate for %s to %0x\n",
499 * The register bit names below may not correspond to the
500 * actual names of the bits in each powerdomain's register,
501 * but the type of value returned is the same for each
504 prm_rmw_mod_reg_bits(OMAP3430_LOGICL1CACHERETSTATE,
505 (pwrst << __ffs(OMAP3430_LOGICL1CACHERETSTATE)),
506 pwrdm->prcm_offs, pwrstctrl_reg_offs);
512 * pwrdm_set_mem_onst - set memory power state while powerdomain ON
513 * @pwrdm: struct powerdomain * to set
514 * @bank: memory bank number to set (0-3)
515 * @pwrst: one of the PWRDM_POWER_* macros
517 * Set the next power state @pwrst that memory bank @bank of the
518 * powerdomain @pwrdm will enter when the powerdomain enters the ON
519 * state. @bank will be a number from 0 to 3, and represents different
520 * types of memory, depending on the powerdomain. Returns -EINVAL if
521 * the powerdomain pointer is null or the target power state is not
522 * not supported for this memory bank, -EEXIST if the target memory
523 * bank does not exist or is not controllable, or returns 0 upon
526 int pwrdm_set_mem_onst(struct powerdomain *pwrdm, u8 bank, u8 pwrst)
533 if (pwrdm->banks < (bank + 1))
536 if (!(pwrdm->pwrsts_mem_on[bank] & (1 << pwrst)))
539 pr_debug("powerdomain: setting next memory powerstate for domain %s "
540 "bank %0x while pwrdm-ON to %0x\n", pwrdm->name, bank, pwrst);
543 * The register bit names below may not correspond to the
544 * actual names of the bits in each powerdomain's register,
545 * but the type of value returned is the same for each
550 m = OMAP_MEM0_ONSTATE_MASK;
553 m = OMAP_MEM1_ONSTATE_MASK;
556 m = OMAP_MEM2_ONSTATE_MASK;
559 m = OMAP_MEM3_ONSTATE_MASK;
562 m = OMAP_MEM4_ONSTATE_MASK;
565 WARN_ON(1); /* should never happen */
569 prm_rmw_mod_reg_bits(m, (pwrst << __ffs(m)),
570 pwrdm->prcm_offs, pwrstctrl_reg_offs);
576 * pwrdm_set_mem_retst - set memory power state while powerdomain in RET
577 * @pwrdm: struct powerdomain * to set
578 * @bank: memory bank number to set (0-3)
579 * @pwrst: one of the PWRDM_POWER_* macros
581 * Set the next power state @pwrst that memory bank @bank of the
582 * powerdomain @pwrdm will enter when the powerdomain enters the
583 * RETENTION state. Bank will be a number from 0 to 3, and represents
584 * different types of memory, depending on the powerdomain. @pwrst
585 * will be either RETENTION or OFF, if supported. Returns -EINVAL if
586 * the powerdomain pointer is null or the target power state is not
587 * not supported for this memory bank, -EEXIST if the target memory
588 * bank does not exist or is not controllable, or returns 0 upon
591 int pwrdm_set_mem_retst(struct powerdomain *pwrdm, u8 bank, u8 pwrst)
598 if (pwrdm->banks < (bank + 1))
601 if (!(pwrdm->pwrsts_mem_ret[bank] & (1 << pwrst)))
604 pr_debug("powerdomain: setting next memory powerstate for domain %s "
605 "bank %0x while pwrdm-RET to %0x\n", pwrdm->name, bank, pwrst);
608 * The register bit names below may not correspond to the
609 * actual names of the bits in each powerdomain's register,
610 * but the type of value returned is the same for each
615 m = OMAP_MEM0_RETSTATE_MASK;
618 m = OMAP_MEM1_RETSTATE_MASK;
621 m = OMAP_MEM2_RETSTATE_MASK;
624 m = OMAP_MEM3_RETSTATE_MASK;
627 m = OMAP_MEM4_RETSTATE_MASK;
630 WARN_ON(1); /* should never happen */
634 prm_rmw_mod_reg_bits(m, (pwrst << __ffs(m)), pwrdm->prcm_offs,
641 * pwrdm_read_logic_pwrst - get current powerdomain logic retention power state
642 * @pwrdm: struct powerdomain * to get current logic retention power state
644 * Return the power state that the logic portion of powerdomain @pwrdm
645 * will enter when the powerdomain enters retention. Returns -EINVAL
646 * if the powerdomain pointer is null or returns the logic retention
647 * power state upon success.
649 int pwrdm_read_logic_pwrst(struct powerdomain *pwrdm)
654 return prm_read_mod_bits_shift(pwrdm->prcm_offs,
655 pwrstst_reg_offs, OMAP3430_LOGICSTATEST);
659 * pwrdm_read_prev_logic_pwrst - get previous powerdomain logic power state
660 * @pwrdm: struct powerdomain * to get previous logic power state
662 * Return the powerdomain @pwrdm's previous logic power state. Returns
663 * -EINVAL if the powerdomain pointer is null or returns the previous
664 * logic power state upon success.
666 int pwrdm_read_prev_logic_pwrst(struct powerdomain *pwrdm)
672 * The register bit names below may not correspond to the
673 * actual names of the bits in each powerdomain's register,
674 * but the type of value returned is the same for each
677 return prm_read_mod_bits_shift(pwrdm->prcm_offs, OMAP3430_PM_PREPWSTST,
678 OMAP3430_LASTLOGICSTATEENTERED);
682 * pwrdm_read_logic_retst - get next powerdomain logic power state
683 * @pwrdm: struct powerdomain * to get next logic power state
685 * Return the powerdomain pwrdm's logic power state. Returns -EINVAL
686 * if the powerdomain pointer is null or returns the next logic
687 * power state upon success.
689 int pwrdm_read_logic_retst(struct powerdomain *pwrdm)
695 * The register bit names below may not correspond to the
696 * actual names of the bits in each powerdomain's register,
697 * but the type of value returned is the same for each
700 return prm_read_mod_bits_shift(pwrdm->prcm_offs, pwrstctrl_reg_offs,
701 OMAP3430_LOGICSTATEST);
705 * pwrdm_read_mem_pwrst - get current memory bank power state
706 * @pwrdm: struct powerdomain * to get current memory bank power state
707 * @bank: memory bank number (0-3)
709 * Return the powerdomain @pwrdm's current memory power state for bank
710 * @bank. Returns -EINVAL if the powerdomain pointer is null, -EEXIST if
711 * the target memory bank does not exist or is not controllable, or
712 * returns the current memory power state upon success.
714 int pwrdm_read_mem_pwrst(struct powerdomain *pwrdm, u8 bank)
721 if (pwrdm->banks < (bank + 1))
724 if (pwrdm->flags & PWRDM_HAS_MPU_QUIRK)
728 * The register bit names below may not correspond to the
729 * actual names of the bits in each powerdomain's register,
730 * but the type of value returned is the same for each
735 m = OMAP_MEM0_STATEST_MASK;
738 m = OMAP_MEM1_STATEST_MASK;
741 m = OMAP_MEM2_STATEST_MASK;
744 m = OMAP_MEM3_STATEST_MASK;
747 m = OMAP_MEM4_STATEST_MASK;
750 WARN_ON(1); /* should never happen */
754 return prm_read_mod_bits_shift(pwrdm->prcm_offs,
755 pwrstst_reg_offs, m);
759 * pwrdm_read_prev_mem_pwrst - get previous memory bank power state
760 * @pwrdm: struct powerdomain * to get previous memory bank power state
761 * @bank: memory bank number (0-3)
763 * Return the powerdomain @pwrdm's previous memory power state for
764 * bank @bank. Returns -EINVAL if the powerdomain pointer is null,
765 * -EEXIST if the target memory bank does not exist or is not
766 * controllable, or returns the previous memory power state upon
769 int pwrdm_read_prev_mem_pwrst(struct powerdomain *pwrdm, u8 bank)
776 if (pwrdm->banks < (bank + 1))
779 if (pwrdm->flags & PWRDM_HAS_MPU_QUIRK)
783 * The register bit names below may not correspond to the
784 * actual names of the bits in each powerdomain's register,
785 * but the type of value returned is the same for each
790 m = OMAP3430_LASTMEM1STATEENTERED_MASK;
793 m = OMAP3430_LASTMEM2STATEENTERED_MASK;
796 m = OMAP3430_LASTSHAREDL2CACHEFLATSTATEENTERED_MASK;
799 m = OMAP3430_LASTL2FLATMEMSTATEENTERED_MASK;
802 WARN_ON(1); /* should never happen */
806 return prm_read_mod_bits_shift(pwrdm->prcm_offs,
807 OMAP3430_PM_PREPWSTST, m);
811 * pwrdm_read_mem_retst - get next memory bank power state
812 * @pwrdm: struct powerdomain * to get mext memory bank power state
813 * @bank: memory bank number (0-3)
815 * Return the powerdomain pwrdm's next memory power state for bank
816 * x. Returns -EINVAL if the powerdomain pointer is null, -EEXIST if
817 * the target memory bank does not exist or is not controllable, or
818 * returns the next memory power state upon success.
820 int pwrdm_read_mem_retst(struct powerdomain *pwrdm, u8 bank)
827 if (pwrdm->banks < (bank + 1))
831 * The register bit names below may not correspond to the
832 * actual names of the bits in each powerdomain's register,
833 * but the type of value returned is the same for each
838 m = OMAP_MEM0_RETSTATE_MASK;
841 m = OMAP_MEM1_RETSTATE_MASK;
844 m = OMAP_MEM2_RETSTATE_MASK;
847 m = OMAP_MEM3_RETSTATE_MASK;
850 m = OMAP_MEM4_RETSTATE_MASK;
852 WARN_ON(1); /* should never happen */
856 return prm_read_mod_bits_shift(pwrdm->prcm_offs,
857 pwrstctrl_reg_offs, m);
861 * pwrdm_clear_all_prev_pwrst - clear previous powerstate register for a pwrdm
862 * @pwrdm: struct powerdomain * to clear
864 * Clear the powerdomain's previous power state register @pwrdm.
865 * Clears the entire register, including logic and memory bank
866 * previous power states. Returns -EINVAL if the powerdomain pointer
867 * is null, or returns 0 upon success.
869 int pwrdm_clear_all_prev_pwrst(struct powerdomain *pwrdm)
875 * XXX should get the powerdomain's current state here;
876 * warn & fail if it is not ON.
879 pr_debug("powerdomain: clearing previous power state reg for %s\n",
882 prm_write_mod_reg(0, pwrdm->prcm_offs, OMAP3430_PM_PREPWSTST);
888 * pwrdm_enable_hdwr_sar - enable automatic hardware SAR for a pwrdm
889 * @pwrdm: struct powerdomain *
891 * Enable automatic context save-and-restore upon power state change
892 * for some devices in the powerdomain @pwrdm. Warning: this only
893 * affects a subset of devices in a powerdomain; check the TRM
894 * closely. Returns -EINVAL if the powerdomain pointer is null or if
895 * the powerdomain does not support automatic save-and-restore, or
896 * returns 0 upon success.
898 int pwrdm_enable_hdwr_sar(struct powerdomain *pwrdm)
903 if (!(pwrdm->flags & PWRDM_HAS_HDWR_SAR))
906 pr_debug("powerdomain: %s: setting SAVEANDRESTORE bit\n",
909 prm_rmw_mod_reg_bits(0, 1 << OMAP3430ES2_SAVEANDRESTORE_SHIFT,
910 pwrdm->prcm_offs, pwrstctrl_reg_offs);
916 * pwrdm_disable_hdwr_sar - disable automatic hardware SAR for a pwrdm
917 * @pwrdm: struct powerdomain *
919 * Disable automatic context save-and-restore upon power state change
920 * for some devices in the powerdomain @pwrdm. Warning: this only
921 * affects a subset of devices in a powerdomain; check the TRM
922 * closely. Returns -EINVAL if the powerdomain pointer is null or if
923 * the powerdomain does not support automatic save-and-restore, or
924 * returns 0 upon success.
926 int pwrdm_disable_hdwr_sar(struct powerdomain *pwrdm)
931 if (!(pwrdm->flags & PWRDM_HAS_HDWR_SAR))
934 pr_debug("powerdomain: %s: clearing SAVEANDRESTORE bit\n",
937 prm_rmw_mod_reg_bits(1 << OMAP3430ES2_SAVEANDRESTORE_SHIFT, 0,
938 pwrdm->prcm_offs, pwrstctrl_reg_offs);
944 * pwrdm_has_hdwr_sar - test whether powerdomain supports hardware SAR
945 * @pwrdm: struct powerdomain *
947 * Returns 1 if powerdomain @pwrdm supports hardware save-and-restore
948 * for some devices, or 0 if it does not.
950 bool pwrdm_has_hdwr_sar(struct powerdomain *pwrdm)
952 return (pwrdm && pwrdm->flags & PWRDM_HAS_HDWR_SAR) ? 1 : 0;
956 * pwrdm_wait_transition - wait for powerdomain power transition to finish
957 * @pwrdm: struct powerdomain * to wait for
959 * If the powerdomain @pwrdm is in the process of a state transition,
960 * spin until it completes the power transition, or until an iteration
961 * bailout value is reached. Returns -EINVAL if the powerdomain
962 * pointer is null, -EAGAIN if the bailout value was reached, or
963 * returns 0 upon success.
965 int pwrdm_wait_transition(struct powerdomain *pwrdm)
973 * REVISIT: pwrdm_wait_transition() may be better implemented
974 * via a callback and a periodic timer check -- how long do we expect
975 * powerdomain transitions to take?
978 /* XXX Is this udelay() value meaningful? */
979 while ((prm_read_mod_reg(pwrdm->prcm_offs, pwrstst_reg_offs) &
980 OMAP_INTRANSITION) &&
981 (c++ < PWRDM_TRANSITION_BAILOUT))
984 if (c > PWRDM_TRANSITION_BAILOUT) {
985 printk(KERN_ERR "powerdomain: waited too long for "
986 "powerdomain %s to complete transition\n", pwrdm->name);
990 pr_debug("powerdomain: completed transition in %d loops\n", c);
995 int pwrdm_state_switch(struct powerdomain *pwrdm)
997 return _pwrdm_state_switch(pwrdm, PWRDM_STATE_NOW);
1000 int pwrdm_clkdm_state_switch(struct clockdomain *clkdm)
1002 if (clkdm != NULL && clkdm->pwrdm.ptr != NULL) {
1003 pwrdm_wait_transition(clkdm->pwrdm.ptr);
1004 return pwrdm_state_switch(clkdm->pwrdm.ptr);
1010 int pwrdm_pre_transition(void)
1012 pwrdm_for_each(_pwrdm_pre_transition_cb, NULL);
1016 int pwrdm_post_transition(void)
1018 pwrdm_for_each(_pwrdm_post_transition_cb, NULL);