2 * OMAP4 powerdomain control
4 * Copyright (C) 2009-2010 Texas Instruments, Inc.
5 * Copyright (C) 2007-2009 Nokia Corporation
7 * Derived from mach-omap2/powerdomain.c written by Paul Walmsley
8 * Rajendra Nayak <rnayak@ti.com>
10 * This program is free software; you can redistribute it and/or modify
11 * it under the terms of the GNU General Public License version 2 as
12 * published by the Free Software Foundation.
16 #include <linux/errno.h>
17 #include <linux/delay.h>
19 #include "powerdomain.h"
20 #include <plat/prcm.h>
21 #include "prm2xxx_3xxx.h"
23 #include "prminst44xx.h"
24 #include "prm-regbits-44xx.h"
26 static int omap4_pwrdm_set_next_pwrst(struct powerdomain
*pwrdm
, u8 pwrst
)
28 omap4_prminst_rmw_inst_reg_bits(OMAP_POWERSTATE_MASK
,
29 (pwrst
<< OMAP_POWERSTATE_SHIFT
),
30 pwrdm
->prcm_partition
,
31 pwrdm
->prcm_offs
, OMAP4_PM_PWSTCTRL
);
35 static int omap4_pwrdm_read_next_pwrst(struct powerdomain
*pwrdm
)
39 v
= omap4_prminst_read_inst_reg(pwrdm
->prcm_partition
, pwrdm
->prcm_offs
,
41 v
&= OMAP_POWERSTATE_MASK
;
42 v
>>= OMAP_POWERSTATE_SHIFT
;
47 static int omap4_pwrdm_read_pwrst(struct powerdomain
*pwrdm
)
51 v
= omap4_prminst_read_inst_reg(pwrdm
->prcm_partition
, pwrdm
->prcm_offs
,
53 v
&= OMAP_POWERSTATEST_MASK
;
54 v
>>= OMAP_POWERSTATEST_SHIFT
;
59 static int omap4_pwrdm_read_prev_pwrst(struct powerdomain
*pwrdm
)
63 v
= omap4_prminst_read_inst_reg(pwrdm
->prcm_partition
, pwrdm
->prcm_offs
,
65 v
&= OMAP4430_LASTPOWERSTATEENTERED_MASK
;
66 v
>>= OMAP4430_LASTPOWERSTATEENTERED_SHIFT
;
71 static int omap4_pwrdm_set_lowpwrstchange(struct powerdomain
*pwrdm
)
73 omap4_prminst_rmw_inst_reg_bits(OMAP4430_LOWPOWERSTATECHANGE_MASK
,
74 (1 << OMAP4430_LOWPOWERSTATECHANGE_SHIFT
),
75 pwrdm
->prcm_partition
,
76 pwrdm
->prcm_offs
, OMAP4_PM_PWSTCTRL
);
80 static int omap4_pwrdm_clear_all_prev_pwrst(struct powerdomain
*pwrdm
)
82 omap4_prminst_rmw_inst_reg_bits(OMAP4430_LASTPOWERSTATEENTERED_MASK
,
83 OMAP4430_LASTPOWERSTATEENTERED_MASK
,
84 pwrdm
->prcm_partition
,
85 pwrdm
->prcm_offs
, OMAP4_PM_PWSTST
);
89 static int omap4_pwrdm_set_logic_retst(struct powerdomain
*pwrdm
, u8 pwrst
)
93 v
= pwrst
<< __ffs(OMAP4430_LOGICRETSTATE_MASK
);
94 omap4_prminst_rmw_inst_reg_bits(OMAP4430_LOGICRETSTATE_MASK
, v
,
95 pwrdm
->prcm_partition
, pwrdm
->prcm_offs
,
101 static int omap4_pwrdm_set_mem_onst(struct powerdomain
*pwrdm
, u8 bank
,
106 m
= omap2_pwrdm_get_mem_bank_onstate_mask(bank
);
108 omap4_prminst_rmw_inst_reg_bits(m
, (pwrst
<< __ffs(m
)),
109 pwrdm
->prcm_partition
, pwrdm
->prcm_offs
,
115 static int omap4_pwrdm_set_mem_retst(struct powerdomain
*pwrdm
, u8 bank
,
120 m
= omap2_pwrdm_get_mem_bank_retst_mask(bank
);
122 omap4_prminst_rmw_inst_reg_bits(m
, (pwrst
<< __ffs(m
)),
123 pwrdm
->prcm_partition
, pwrdm
->prcm_offs
,
129 static int omap4_pwrdm_read_logic_pwrst(struct powerdomain
*pwrdm
)
133 v
= omap4_prminst_read_inst_reg(pwrdm
->prcm_partition
, pwrdm
->prcm_offs
,
135 v
&= OMAP4430_LOGICSTATEST_MASK
;
136 v
>>= OMAP4430_LOGICSTATEST_SHIFT
;
141 static int omap4_pwrdm_read_logic_retst(struct powerdomain
*pwrdm
)
145 v
= omap4_prminst_read_inst_reg(pwrdm
->prcm_partition
, pwrdm
->prcm_offs
,
147 v
&= OMAP4430_LOGICRETSTATE_MASK
;
148 v
>>= OMAP4430_LOGICRETSTATE_SHIFT
;
153 static int omap4_pwrdm_read_mem_pwrst(struct powerdomain
*pwrdm
, u8 bank
)
157 m
= omap2_pwrdm_get_mem_bank_stst_mask(bank
);
159 v
= omap4_prminst_read_inst_reg(pwrdm
->prcm_partition
, pwrdm
->prcm_offs
,
167 static int omap4_pwrdm_read_mem_retst(struct powerdomain
*pwrdm
, u8 bank
)
171 m
= omap2_pwrdm_get_mem_bank_retst_mask(bank
);
173 v
= omap4_prminst_read_inst_reg(pwrdm
->prcm_partition
, pwrdm
->prcm_offs
,
181 static int omap4_pwrdm_wait_transition(struct powerdomain
*pwrdm
)
186 * REVISIT: pwrdm_wait_transition() may be better implemented
187 * via a callback and a periodic timer check -- how long do we expect
188 * powerdomain transitions to take?
191 /* XXX Is this udelay() value meaningful? */
192 while ((omap4_prminst_read_inst_reg(pwrdm
->prcm_partition
,
195 OMAP_INTRANSITION_MASK
) &&
196 (c
++ < PWRDM_TRANSITION_BAILOUT
))
199 if (c
> PWRDM_TRANSITION_BAILOUT
) {
200 printk(KERN_ERR
"powerdomain: waited too long for "
201 "powerdomain %s to complete transition\n", pwrdm
->name
);
205 pr_debug("powerdomain: completed transition in %d loops\n", c
);
210 struct pwrdm_ops omap4_pwrdm_operations
= {
211 .pwrdm_set_next_pwrst
= omap4_pwrdm_set_next_pwrst
,
212 .pwrdm_read_next_pwrst
= omap4_pwrdm_read_next_pwrst
,
213 .pwrdm_read_pwrst
= omap4_pwrdm_read_pwrst
,
214 .pwrdm_read_prev_pwrst
= omap4_pwrdm_read_prev_pwrst
,
215 .pwrdm_set_lowpwrstchange
= omap4_pwrdm_set_lowpwrstchange
,
216 .pwrdm_clear_all_prev_pwrst
= omap4_pwrdm_clear_all_prev_pwrst
,
217 .pwrdm_set_logic_retst
= omap4_pwrdm_set_logic_retst
,
218 .pwrdm_read_logic_pwrst
= omap4_pwrdm_read_logic_pwrst
,
219 .pwrdm_read_logic_retst
= omap4_pwrdm_read_logic_retst
,
220 .pwrdm_read_mem_pwrst
= omap4_pwrdm_read_mem_pwrst
,
221 .pwrdm_read_mem_retst
= omap4_pwrdm_read_mem_retst
,
222 .pwrdm_set_mem_onst
= omap4_pwrdm_set_mem_onst
,
223 .pwrdm_set_mem_retst
= omap4_pwrdm_set_mem_retst
,
224 .pwrdm_wait_transition
= omap4_pwrdm_wait_transition
,