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"
22 #include "cminst44xx.h"
25 #include "prminst44xx.h"
26 #include "prm-regbits-44xx.h"
27 #include "cm-regbits-44xx.h"
30 static int omap4_pwrdm_set_next_pwrst(struct powerdomain
*pwrdm
, u8 pwrst
)
32 omap4_prminst_rmw_inst_reg_bits(OMAP_POWERSTATE_MASK
,
33 (pwrst
<< OMAP_POWERSTATE_SHIFT
),
34 pwrdm
->prcm_partition
,
35 pwrdm
->prcm_offs
, OMAP4_PM_PWSTCTRL
);
39 static int omap4_pwrdm_read_next_pwrst(struct powerdomain
*pwrdm
)
43 v
= omap4_prminst_read_inst_reg(pwrdm
->prcm_partition
, pwrdm
->prcm_offs
,
45 v
&= OMAP_POWERSTATE_MASK
;
46 v
>>= OMAP_POWERSTATE_SHIFT
;
51 static int omap4_pwrdm_read_pwrst(struct powerdomain
*pwrdm
)
55 v
= omap4_prminst_read_inst_reg(pwrdm
->prcm_partition
, pwrdm
->prcm_offs
,
57 v
&= OMAP_POWERSTATEST_MASK
;
58 v
>>= OMAP_POWERSTATEST_SHIFT
;
63 static int omap4_pwrdm_read_prev_pwrst(struct powerdomain
*pwrdm
)
67 v
= omap4_prminst_read_inst_reg(pwrdm
->prcm_partition
, pwrdm
->prcm_offs
,
69 v
&= OMAP4430_LASTPOWERSTATEENTERED_MASK
;
70 v
>>= OMAP4430_LASTPOWERSTATEENTERED_SHIFT
;
75 static int omap4_pwrdm_set_lowpwrstchange(struct powerdomain
*pwrdm
)
77 omap4_prminst_rmw_inst_reg_bits(OMAP4430_LOWPOWERSTATECHANGE_MASK
,
78 (1 << OMAP4430_LOWPOWERSTATECHANGE_SHIFT
),
79 pwrdm
->prcm_partition
,
80 pwrdm
->prcm_offs
, OMAP4_PM_PWSTCTRL
);
84 static int omap4_pwrdm_clear_all_prev_pwrst(struct powerdomain
*pwrdm
)
86 omap4_prminst_rmw_inst_reg_bits(OMAP4430_LASTPOWERSTATEENTERED_MASK
,
87 OMAP4430_LASTPOWERSTATEENTERED_MASK
,
88 pwrdm
->prcm_partition
,
89 pwrdm
->prcm_offs
, OMAP4_PM_PWSTST
);
93 static int omap4_pwrdm_set_logic_retst(struct powerdomain
*pwrdm
, u8 pwrst
)
97 v
= pwrst
<< __ffs(OMAP4430_LOGICRETSTATE_MASK
);
98 omap4_prminst_rmw_inst_reg_bits(OMAP4430_LOGICRETSTATE_MASK
, v
,
99 pwrdm
->prcm_partition
, pwrdm
->prcm_offs
,
105 static int omap4_pwrdm_set_mem_onst(struct powerdomain
*pwrdm
, u8 bank
,
110 m
= omap2_pwrdm_get_mem_bank_onstate_mask(bank
);
112 omap4_prminst_rmw_inst_reg_bits(m
, (pwrst
<< __ffs(m
)),
113 pwrdm
->prcm_partition
, pwrdm
->prcm_offs
,
119 static int omap4_pwrdm_set_mem_retst(struct powerdomain
*pwrdm
, u8 bank
,
124 m
= omap2_pwrdm_get_mem_bank_retst_mask(bank
);
126 omap4_prminst_rmw_inst_reg_bits(m
, (pwrst
<< __ffs(m
)),
127 pwrdm
->prcm_partition
, pwrdm
->prcm_offs
,
133 static int omap4_pwrdm_read_logic_pwrst(struct powerdomain
*pwrdm
)
137 v
= omap4_prminst_read_inst_reg(pwrdm
->prcm_partition
, pwrdm
->prcm_offs
,
139 v
&= OMAP4430_LOGICSTATEST_MASK
;
140 v
>>= OMAP4430_LOGICSTATEST_SHIFT
;
145 static int omap4_pwrdm_read_logic_retst(struct powerdomain
*pwrdm
)
149 v
= omap4_prminst_read_inst_reg(pwrdm
->prcm_partition
, pwrdm
->prcm_offs
,
151 v
&= OMAP4430_LOGICRETSTATE_MASK
;
152 v
>>= OMAP4430_LOGICRETSTATE_SHIFT
;
157 static int omap4_pwrdm_read_mem_pwrst(struct powerdomain
*pwrdm
, u8 bank
)
161 m
= omap2_pwrdm_get_mem_bank_stst_mask(bank
);
163 v
= omap4_prminst_read_inst_reg(pwrdm
->prcm_partition
, pwrdm
->prcm_offs
,
171 static int omap4_pwrdm_read_mem_retst(struct powerdomain
*pwrdm
, u8 bank
)
175 m
= omap2_pwrdm_get_mem_bank_retst_mask(bank
);
177 v
= omap4_prminst_read_inst_reg(pwrdm
->prcm_partition
, pwrdm
->prcm_offs
,
185 static int omap4_pwrdm_wait_transition(struct powerdomain
*pwrdm
)
190 * REVISIT: pwrdm_wait_transition() may be better implemented
191 * via a callback and a periodic timer check -- how long do we expect
192 * powerdomain transitions to take?
195 /* XXX Is this udelay() value meaningful? */
196 while ((omap4_prminst_read_inst_reg(pwrdm
->prcm_partition
,
199 OMAP_INTRANSITION_MASK
) &&
200 (c
++ < PWRDM_TRANSITION_BAILOUT
))
203 if (c
> PWRDM_TRANSITION_BAILOUT
) {
204 printk(KERN_ERR
"powerdomain: waited too long for "
205 "powerdomain %s to complete transition\n", pwrdm
->name
);
209 pr_debug("powerdomain: completed transition in %d loops\n", c
);
214 static int omap4_pwrdm_enable_hdwr_sar(struct powerdomain
*pwrdm
)
217 * FIXME: This should be fixed right way by moving it into HWMOD
218 * or clock framework since sar control is moved to module level
220 omap4_cminst_rmw_inst_reg_bits(OMAP4430_SAR_MODE_MASK
,
221 1 << OMAP4430_SAR_MODE_SHIFT
, OMAP4430_CM2_PARTITION
,
222 OMAP4430_CM2_L3INIT_INST
,
223 OMAP4_CM_L3INIT_USB_HOST_CLKCTRL_OFFSET
);
224 omap4_cminst_rmw_inst_reg_bits(OMAP4430_SAR_MODE_MASK
,
225 1 << OMAP4430_SAR_MODE_SHIFT
, OMAP4430_CM2_PARTITION
,
226 OMAP4430_CM2_L3INIT_INST
,
227 OMAP4_CM_L3INIT_USB_TLL_CLKCTRL_OFFSET
);
231 static int omap4_pwrdm_disable_hdwr_sar(struct powerdomain
*pwrdm
)
234 * FIXME: This should be fixed right way by moving it into HWMOD
235 * or clock framework since sar control is moved to module level
237 omap4_cminst_rmw_inst_reg_bits(OMAP4430_SAR_MODE_MASK
,
238 0 << OMAP4430_SAR_MODE_SHIFT
, OMAP4430_CM2_PARTITION
,
239 OMAP4430_CM2_L3INIT_INST
,
240 OMAP4_CM_L3INIT_USB_HOST_CLKCTRL_OFFSET
);
241 omap4_cminst_rmw_inst_reg_bits(OMAP4430_SAR_MODE_MASK
,
242 0 << OMAP4430_SAR_MODE_SHIFT
, OMAP4430_CM2_PARTITION
,
243 OMAP4430_CM2_L3INIT_INST
,
244 OMAP4_CM_L3INIT_USB_TLL_CLKCTRL_OFFSET
);
249 struct pwrdm_ops omap4_pwrdm_operations
= {
250 .pwrdm_set_next_pwrst
= omap4_pwrdm_set_next_pwrst
,
251 .pwrdm_read_next_pwrst
= omap4_pwrdm_read_next_pwrst
,
252 .pwrdm_read_pwrst
= omap4_pwrdm_read_pwrst
,
253 .pwrdm_read_prev_pwrst
= omap4_pwrdm_read_prev_pwrst
,
254 .pwrdm_set_lowpwrstchange
= omap4_pwrdm_set_lowpwrstchange
,
255 .pwrdm_clear_all_prev_pwrst
= omap4_pwrdm_clear_all_prev_pwrst
,
256 .pwrdm_set_logic_retst
= omap4_pwrdm_set_logic_retst
,
257 .pwrdm_read_logic_pwrst
= omap4_pwrdm_read_logic_pwrst
,
258 .pwrdm_read_logic_retst
= omap4_pwrdm_read_logic_retst
,
259 .pwrdm_read_mem_pwrst
= omap4_pwrdm_read_mem_pwrst
,
260 .pwrdm_read_mem_retst
= omap4_pwrdm_read_mem_retst
,
261 .pwrdm_set_mem_onst
= omap4_pwrdm_set_mem_onst
,
262 .pwrdm_set_mem_retst
= omap4_pwrdm_set_mem_retst
,
263 .pwrdm_wait_transition
= omap4_pwrdm_wait_transition
,
264 .pwrdm_enable_hdwr_sar
= omap4_pwrdm_enable_hdwr_sar
,
265 .pwrdm_disable_hdwr_sar
= omap4_pwrdm_disable_hdwr_sar
,