2 * AM33XX Powerdomain control
4 * Copyright (C) 2011-2012 Texas Instruments Incorporated - http://www.ti.com/
6 * Derived from mach-omap2/powerdomain44xx.c written by Rajendra Nayak
9 * This program is free software; you can redistribute it and/or
10 * modify it under the terms of the GNU General Public License as
11 * published by the Free Software Foundation version 2.
13 * This program is distributed "as is" WITHOUT ANY WARRANTY of any
14 * kind, whether express or implied; without even the implied warranty
15 * of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
20 #include <linux/errno.h>
21 #include <linux/delay.h>
23 #include <plat/prcm.h>
25 #include "powerdomain.h"
27 #include "prm-regbits-33xx.h"
30 static int am33xx_pwrdm_set_next_pwrst(struct powerdomain
*pwrdm
, u8 pwrst
)
32 am33xx_prm_rmw_reg_bits(OMAP_POWERSTATE_MASK
,
33 (pwrst
<< OMAP_POWERSTATE_SHIFT
),
34 pwrdm
->prcm_offs
, pwrdm
->pwrstctrl_offs
);
38 static int am33xx_pwrdm_read_next_pwrst(struct powerdomain
*pwrdm
)
42 v
= am33xx_prm_read_reg(pwrdm
->prcm_offs
, pwrdm
->pwrstctrl_offs
);
43 v
&= OMAP_POWERSTATE_MASK
;
44 v
>>= OMAP_POWERSTATE_SHIFT
;
49 static int am33xx_pwrdm_read_pwrst(struct powerdomain
*pwrdm
)
53 v
= am33xx_prm_read_reg(pwrdm
->prcm_offs
, pwrdm
->pwrstst_offs
);
54 v
&= OMAP_POWERSTATEST_MASK
;
55 v
>>= OMAP_POWERSTATEST_SHIFT
;
60 static int am33xx_pwrdm_read_prev_pwrst(struct powerdomain
*pwrdm
)
64 v
= am33xx_prm_read_reg(pwrdm
->prcm_offs
, pwrdm
->pwrstst_offs
);
65 v
&= AM33XX_LASTPOWERSTATEENTERED_MASK
;
66 v
>>= AM33XX_LASTPOWERSTATEENTERED_SHIFT
;
71 static int am33xx_pwrdm_set_lowpwrstchange(struct powerdomain
*pwrdm
)
73 am33xx_prm_rmw_reg_bits(AM33XX_LOWPOWERSTATECHANGE_MASK
,
74 (1 << AM33XX_LOWPOWERSTATECHANGE_SHIFT
),
75 pwrdm
->prcm_offs
, pwrdm
->pwrstctrl_offs
);
79 static int am33xx_pwrdm_clear_all_prev_pwrst(struct powerdomain
*pwrdm
)
81 am33xx_prm_rmw_reg_bits(AM33XX_LASTPOWERSTATEENTERED_MASK
,
82 AM33XX_LASTPOWERSTATEENTERED_MASK
,
83 pwrdm
->prcm_offs
, pwrdm
->pwrstst_offs
);
87 static int am33xx_pwrdm_set_logic_retst(struct powerdomain
*pwrdm
, u8 pwrst
)
91 m
= pwrdm
->logicretstate_mask
;
95 am33xx_prm_rmw_reg_bits(m
, (pwrst
<< __ffs(m
)),
96 pwrdm
->prcm_offs
, pwrdm
->pwrstctrl_offs
);
101 static int am33xx_pwrdm_read_logic_pwrst(struct powerdomain
*pwrdm
)
105 v
= am33xx_prm_read_reg(pwrdm
->prcm_offs
, pwrdm
->pwrstst_offs
);
106 v
&= AM33XX_LOGICSTATEST_MASK
;
107 v
>>= AM33XX_LOGICSTATEST_SHIFT
;
112 static int am33xx_pwrdm_read_logic_retst(struct powerdomain
*pwrdm
)
116 m
= pwrdm
->logicretstate_mask
;
120 v
= am33xx_prm_read_reg(pwrdm
->prcm_offs
, pwrdm
->pwrstctrl_offs
);
127 static int am33xx_pwrdm_set_mem_onst(struct powerdomain
*pwrdm
, u8 bank
,
132 m
= pwrdm
->mem_on_mask
[bank
];
136 am33xx_prm_rmw_reg_bits(m
, (pwrst
<< __ffs(m
)),
137 pwrdm
->prcm_offs
, pwrdm
->pwrstctrl_offs
);
142 static int am33xx_pwrdm_set_mem_retst(struct powerdomain
*pwrdm
, u8 bank
,
147 m
= pwrdm
->mem_ret_mask
[bank
];
151 am33xx_prm_rmw_reg_bits(m
, (pwrst
<< __ffs(m
)),
152 pwrdm
->prcm_offs
, pwrdm
->pwrstctrl_offs
);
157 static int am33xx_pwrdm_read_mem_pwrst(struct powerdomain
*pwrdm
, u8 bank
)
161 m
= pwrdm
->mem_pwrst_mask
[bank
];
165 v
= am33xx_prm_read_reg(pwrdm
->prcm_offs
, pwrdm
->pwrstst_offs
);
172 static int am33xx_pwrdm_read_mem_retst(struct powerdomain
*pwrdm
, u8 bank
)
176 m
= pwrdm
->mem_retst_mask
[bank
];
180 v
= am33xx_prm_read_reg(pwrdm
->prcm_offs
, pwrdm
->pwrstctrl_offs
);
187 static int am33xx_pwrdm_wait_transition(struct powerdomain
*pwrdm
)
192 * REVISIT: pwrdm_wait_transition() may be better implemented
193 * via a callback and a periodic timer check -- how long do we expect
194 * powerdomain transitions to take?
197 /* XXX Is this udelay() value meaningful? */
198 while ((am33xx_prm_read_reg(pwrdm
->prcm_offs
, pwrdm
->pwrstst_offs
)
199 & OMAP_INTRANSITION_MASK
) &&
200 (c
++ < PWRDM_TRANSITION_BAILOUT
))
203 if (c
> PWRDM_TRANSITION_BAILOUT
) {
204 pr_err("powerdomain: %s: waited too long to complete transition\n",
209 pr_debug("powerdomain: completed transition in %d loops\n", c
);
214 struct pwrdm_ops am33xx_pwrdm_operations
= {
215 .pwrdm_set_next_pwrst
= am33xx_pwrdm_set_next_pwrst
,
216 .pwrdm_read_next_pwrst
= am33xx_pwrdm_read_next_pwrst
,
217 .pwrdm_read_pwrst
= am33xx_pwrdm_read_pwrst
,
218 .pwrdm_read_prev_pwrst
= am33xx_pwrdm_read_prev_pwrst
,
219 .pwrdm_set_logic_retst
= am33xx_pwrdm_set_logic_retst
,
220 .pwrdm_read_logic_pwrst
= am33xx_pwrdm_read_logic_pwrst
,
221 .pwrdm_read_logic_retst
= am33xx_pwrdm_read_logic_retst
,
222 .pwrdm_clear_all_prev_pwrst
= am33xx_pwrdm_clear_all_prev_pwrst
,
223 .pwrdm_set_lowpwrstchange
= am33xx_pwrdm_set_lowpwrstchange
,
224 .pwrdm_read_mem_pwrst
= am33xx_pwrdm_read_mem_pwrst
,
225 .pwrdm_read_mem_retst
= am33xx_pwrdm_read_mem_retst
,
226 .pwrdm_set_mem_onst
= am33xx_pwrdm_set_mem_onst
,
227 .pwrdm_set_mem_retst
= am33xx_pwrdm_set_mem_retst
,
228 .pwrdm_wait_transition
= am33xx_pwrdm_wait_transition
,