4 * Copyright (C) 2011-2012 Texas Instruments Incorporated - http://www.ti.com/
6 * This program is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU General Public License as
8 * published by the Free Software Foundation version 2.
10 * This program is distributed "as is" WITHOUT ANY WARRANTY of any
11 * kind, whether express or implied; without even the implied warranty
12 * of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
16 #include <linux/kernel.h>
17 #include <linux/types.h>
18 #include <linux/errno.h>
19 #include <linux/err.h>
23 #include "powerdomain.h"
25 #include "prm-regbits-33xx.h"
27 /* Read a register in a PRM instance */
28 u32
am33xx_prm_read_reg(s16 inst
, u16 idx
)
30 return __raw_readl(prm_base
+ inst
+ idx
);
33 /* Write into a register in a PRM instance */
34 void am33xx_prm_write_reg(u32 val
, s16 inst
, u16 idx
)
36 __raw_writel(val
, prm_base
+ inst
+ idx
);
39 /* Read-modify-write a register in PRM. Caller must lock */
40 u32
am33xx_prm_rmw_reg_bits(u32 mask
, u32 bits
, s16 inst
, s16 idx
)
44 v
= am33xx_prm_read_reg(inst
, idx
);
47 am33xx_prm_write_reg(v
, inst
, idx
);
53 * am33xx_prm_is_hardreset_asserted - read the HW reset line state of
54 * submodules contained in the hwmod module
55 * @shift: register bit shift corresponding to the reset line to check
56 * @inst: CM instance register offset (*_INST macro)
57 * @rstctrl_offs: RM_RSTCTRL register address offset for this module
59 * Returns 1 if the (sub)module hardreset line is currently asserted,
60 * 0 if the (sub)module hardreset line is not currently asserted, or
61 * -EINVAL upon parameter error.
63 int am33xx_prm_is_hardreset_asserted(u8 shift
, s16 inst
, u16 rstctrl_offs
)
67 v
= am33xx_prm_read_reg(inst
, rstctrl_offs
);
75 * am33xx_prm_assert_hardreset - assert the HW reset line of a submodule
76 * @shift: register bit shift corresponding to the reset line to assert
77 * @inst: CM instance register offset (*_INST macro)
78 * @rstctrl_reg: RM_RSTCTRL register address for this module
80 * Some IPs like dsp, ipu or iva contain processors that require an HW
81 * reset line to be asserted / deasserted in order to fully enable the
82 * IP. These modules may have multiple hard-reset lines that reset
83 * different 'submodules' inside the IP block. This function will
84 * place the submodule into reset. Returns 0 upon success or -EINVAL
85 * upon an argument error.
87 int am33xx_prm_assert_hardreset(u8 shift
, s16 inst
, u16 rstctrl_offs
)
89 u32 mask
= 1 << shift
;
91 am33xx_prm_rmw_reg_bits(mask
, mask
, inst
, rstctrl_offs
);
97 * am33xx_prm_deassert_hardreset - deassert a submodule hardreset line and
99 * @shift: register bit shift corresponding to the reset line to deassert
100 * @inst: CM instance register offset (*_INST macro)
101 * @rstctrl_reg: RM_RSTCTRL register address for this module
102 * @rstst_reg: RM_RSTST register address for this module
104 * Some IPs like dsp, ipu or iva contain processors that require an HW
105 * reset line to be asserted / deasserted in order to fully enable the
106 * IP. These modules may have multiple hard-reset lines that reset
107 * different 'submodules' inside the IP block. This function will
108 * take the submodule out of reset and wait until the PRCM indicates
109 * that the reset has completed before returning. Returns 0 upon success or
110 * -EINVAL upon an argument error, -EEXIST if the submodule was already out
111 * of reset, or -EBUSY if the submodule did not exit reset promptly.
113 int am33xx_prm_deassert_hardreset(u8 shift
, u8 st_shift
, s16 inst
,
114 u16 rstctrl_offs
, u16 rstst_offs
)
117 u32 mask
= 1 << st_shift
;
119 /* Check the current status to avoid de-asserting the line twice */
120 if (am33xx_prm_is_hardreset_asserted(shift
, inst
, rstctrl_offs
) == 0)
123 /* Clear the reset status by writing 1 to the status bit */
124 am33xx_prm_rmw_reg_bits(0xffffffff, mask
, inst
, rstst_offs
);
126 /* de-assert the reset control line */
129 am33xx_prm_rmw_reg_bits(mask
, 0, inst
, rstctrl_offs
);
131 /* wait the status to be set */
132 omap_test_timeout(am33xx_prm_is_hardreset_asserted(st_shift
, inst
,
134 MAX_MODULE_HARDRESET_WAIT
, c
);
136 return (c
== MAX_MODULE_HARDRESET_WAIT
) ? -EBUSY
: 0;
139 static int am33xx_pwrdm_set_next_pwrst(struct powerdomain
*pwrdm
, u8 pwrst
)
141 am33xx_prm_rmw_reg_bits(OMAP_POWERSTATE_MASK
,
142 (pwrst
<< OMAP_POWERSTATE_SHIFT
),
143 pwrdm
->prcm_offs
, pwrdm
->pwrstctrl_offs
);
147 static int am33xx_pwrdm_read_next_pwrst(struct powerdomain
*pwrdm
)
151 v
= am33xx_prm_read_reg(pwrdm
->prcm_offs
, pwrdm
->pwrstctrl_offs
);
152 v
&= OMAP_POWERSTATE_MASK
;
153 v
>>= OMAP_POWERSTATE_SHIFT
;
158 static int am33xx_pwrdm_read_pwrst(struct powerdomain
*pwrdm
)
162 v
= am33xx_prm_read_reg(pwrdm
->prcm_offs
, pwrdm
->pwrstst_offs
);
163 v
&= OMAP_POWERSTATEST_MASK
;
164 v
>>= OMAP_POWERSTATEST_SHIFT
;
169 static int am33xx_pwrdm_read_prev_pwrst(struct powerdomain
*pwrdm
)
173 v
= am33xx_prm_read_reg(pwrdm
->prcm_offs
, pwrdm
->pwrstst_offs
);
174 v
&= AM33XX_LASTPOWERSTATEENTERED_MASK
;
175 v
>>= AM33XX_LASTPOWERSTATEENTERED_SHIFT
;
180 static int am33xx_pwrdm_set_lowpwrstchange(struct powerdomain
*pwrdm
)
182 am33xx_prm_rmw_reg_bits(AM33XX_LOWPOWERSTATECHANGE_MASK
,
183 (1 << AM33XX_LOWPOWERSTATECHANGE_SHIFT
),
184 pwrdm
->prcm_offs
, pwrdm
->pwrstctrl_offs
);
188 static int am33xx_pwrdm_clear_all_prev_pwrst(struct powerdomain
*pwrdm
)
190 am33xx_prm_rmw_reg_bits(AM33XX_LASTPOWERSTATEENTERED_MASK
,
191 AM33XX_LASTPOWERSTATEENTERED_MASK
,
192 pwrdm
->prcm_offs
, pwrdm
->pwrstst_offs
);
196 static int am33xx_pwrdm_set_logic_retst(struct powerdomain
*pwrdm
, u8 pwrst
)
200 m
= pwrdm
->logicretstate_mask
;
204 am33xx_prm_rmw_reg_bits(m
, (pwrst
<< __ffs(m
)),
205 pwrdm
->prcm_offs
, pwrdm
->pwrstctrl_offs
);
210 static int am33xx_pwrdm_read_logic_pwrst(struct powerdomain
*pwrdm
)
214 v
= am33xx_prm_read_reg(pwrdm
->prcm_offs
, pwrdm
->pwrstst_offs
);
215 v
&= AM33XX_LOGICSTATEST_MASK
;
216 v
>>= AM33XX_LOGICSTATEST_SHIFT
;
221 static int am33xx_pwrdm_read_logic_retst(struct powerdomain
*pwrdm
)
225 m
= pwrdm
->logicretstate_mask
;
229 v
= am33xx_prm_read_reg(pwrdm
->prcm_offs
, pwrdm
->pwrstctrl_offs
);
236 static int am33xx_pwrdm_set_mem_onst(struct powerdomain
*pwrdm
, u8 bank
,
241 m
= pwrdm
->mem_on_mask
[bank
];
245 am33xx_prm_rmw_reg_bits(m
, (pwrst
<< __ffs(m
)),
246 pwrdm
->prcm_offs
, pwrdm
->pwrstctrl_offs
);
251 static int am33xx_pwrdm_set_mem_retst(struct powerdomain
*pwrdm
, u8 bank
,
256 m
= pwrdm
->mem_ret_mask
[bank
];
260 am33xx_prm_rmw_reg_bits(m
, (pwrst
<< __ffs(m
)),
261 pwrdm
->prcm_offs
, pwrdm
->pwrstctrl_offs
);
266 static int am33xx_pwrdm_read_mem_pwrst(struct powerdomain
*pwrdm
, u8 bank
)
270 m
= pwrdm
->mem_pwrst_mask
[bank
];
274 v
= am33xx_prm_read_reg(pwrdm
->prcm_offs
, pwrdm
->pwrstst_offs
);
281 static int am33xx_pwrdm_read_mem_retst(struct powerdomain
*pwrdm
, u8 bank
)
285 m
= pwrdm
->mem_retst_mask
[bank
];
289 v
= am33xx_prm_read_reg(pwrdm
->prcm_offs
, pwrdm
->pwrstctrl_offs
);
296 static int am33xx_pwrdm_wait_transition(struct powerdomain
*pwrdm
)
301 * REVISIT: pwrdm_wait_transition() may be better implemented
302 * via a callback and a periodic timer check -- how long do we expect
303 * powerdomain transitions to take?
306 /* XXX Is this udelay() value meaningful? */
307 while ((am33xx_prm_read_reg(pwrdm
->prcm_offs
, pwrdm
->pwrstst_offs
)
308 & OMAP_INTRANSITION_MASK
) &&
309 (c
++ < PWRDM_TRANSITION_BAILOUT
))
312 if (c
> PWRDM_TRANSITION_BAILOUT
) {
313 pr_err("powerdomain: %s: waited too long to complete transition\n",
318 pr_debug("powerdomain: completed transition in %d loops\n", c
);
323 static int am33xx_check_vcvp(void)
325 /* No VC/VP on am33xx devices */
329 struct pwrdm_ops am33xx_pwrdm_operations
= {
330 .pwrdm_set_next_pwrst
= am33xx_pwrdm_set_next_pwrst
,
331 .pwrdm_read_next_pwrst
= am33xx_pwrdm_read_next_pwrst
,
332 .pwrdm_read_pwrst
= am33xx_pwrdm_read_pwrst
,
333 .pwrdm_read_prev_pwrst
= am33xx_pwrdm_read_prev_pwrst
,
334 .pwrdm_set_logic_retst
= am33xx_pwrdm_set_logic_retst
,
335 .pwrdm_read_logic_pwrst
= am33xx_pwrdm_read_logic_pwrst
,
336 .pwrdm_read_logic_retst
= am33xx_pwrdm_read_logic_retst
,
337 .pwrdm_clear_all_prev_pwrst
= am33xx_pwrdm_clear_all_prev_pwrst
,
338 .pwrdm_set_lowpwrstchange
= am33xx_pwrdm_set_lowpwrstchange
,
339 .pwrdm_read_mem_pwrst
= am33xx_pwrdm_read_mem_pwrst
,
340 .pwrdm_read_mem_retst
= am33xx_pwrdm_read_mem_retst
,
341 .pwrdm_set_mem_onst
= am33xx_pwrdm_set_mem_onst
,
342 .pwrdm_set_mem_retst
= am33xx_pwrdm_set_mem_retst
,
343 .pwrdm_wait_transition
= am33xx_pwrdm_wait_transition
,
344 .pwrdm_has_voltdm
= am33xx_check_vcvp
,