1 // SPDX-License-Identifier: GPL-2.0-only
5 * Copyright (C) 2011-2012 Texas Instruments Incorporated - https://www.ti.com/
8 #include <linux/kernel.h>
9 #include <linux/types.h>
10 #include <linux/errno.h>
11 #include <linux/err.h>
13 #include <linux/reboot.h>
15 #include "powerdomain.h"
17 #include "prm-regbits-33xx.h"
19 /* Read a register in a PRM instance */
20 static u32
am33xx_prm_read_reg(s16 inst
, u16 idx
)
22 return readl_relaxed(prm_base
.va
+ inst
+ idx
);
25 /* Write into a register in a PRM instance */
26 static void am33xx_prm_write_reg(u32 val
, s16 inst
, u16 idx
)
28 writel_relaxed(val
, prm_base
.va
+ inst
+ idx
);
31 /* Read-modify-write a register in PRM. Caller must lock */
32 static u32
am33xx_prm_rmw_reg_bits(u32 mask
, u32 bits
, s16 inst
, s16 idx
)
36 v
= am33xx_prm_read_reg(inst
, idx
);
39 am33xx_prm_write_reg(v
, inst
, idx
);
45 * am33xx_prm_is_hardreset_asserted - read the HW reset line state of
46 * submodules contained in the hwmod module
47 * @shift: register bit shift corresponding to the reset line to check
48 * @part: PRM partition, ignored for AM33xx
49 * @inst: CM instance register offset (*_INST macro)
50 * @rstctrl_offs: RM_RSTCTRL register address offset for this module
52 * Returns 1 if the (sub)module hardreset line is currently asserted,
53 * 0 if the (sub)module hardreset line is not currently asserted, or
54 * -EINVAL upon parameter error.
56 static int am33xx_prm_is_hardreset_asserted(u8 shift
, u8 part
, s16 inst
,
61 v
= am33xx_prm_read_reg(inst
, rstctrl_offs
);
69 * am33xx_prm_assert_hardreset - assert the HW reset line of a submodule
70 * @shift: register bit shift corresponding to the reset line to assert
71 * @part: CM partition, ignored for AM33xx
72 * @inst: CM instance register offset (*_INST macro)
73 * @rstctrl_reg: RM_RSTCTRL register address for this module
75 * Some IPs like dsp, ipu or iva contain processors that require an HW
76 * reset line to be asserted / deasserted in order to fully enable the
77 * IP. These modules may have multiple hard-reset lines that reset
78 * different 'submodules' inside the IP block. This function will
79 * place the submodule into reset. Returns 0 upon success or -EINVAL
80 * upon an argument error.
82 static int am33xx_prm_assert_hardreset(u8 shift
, u8 part
, s16 inst
,
85 u32 mask
= 1 << shift
;
87 am33xx_prm_rmw_reg_bits(mask
, mask
, inst
, rstctrl_offs
);
93 * am33xx_prm_deassert_hardreset - deassert a submodule hardreset line and
95 * @shift: register bit shift corresponding to the reset line to deassert
96 * @st_shift: reset status register bit shift corresponding to the reset line
97 * @part: PRM partition, not used for AM33xx
98 * @inst: CM instance register offset (*_INST macro)
99 * @rstctrl_reg: RM_RSTCTRL register address for this module
100 * @rstst_reg: RM_RSTST register address for this module
102 * Some IPs like dsp, ipu or iva contain processors that require an HW
103 * reset line to be asserted / deasserted in order to fully enable the
104 * IP. These modules may have multiple hard-reset lines that reset
105 * different 'submodules' inside the IP block. This function will
106 * take the submodule out of reset and wait until the PRCM indicates
107 * that the reset has completed before returning. Returns 0 upon success or
108 * -EINVAL upon an argument error, -EEXIST if the submodule was already out
109 * of reset, or -EBUSY if the submodule did not exit reset promptly.
111 static int am33xx_prm_deassert_hardreset(u8 shift
, u8 st_shift
, u8 part
,
112 s16 inst
, u16 rstctrl_offs
,
116 u32 mask
= 1 << st_shift
;
118 /* Check the current status to avoid de-asserting the line twice */
119 if (am33xx_prm_is_hardreset_asserted(shift
, 0, inst
, rstctrl_offs
) == 0)
122 /* Clear the reset status by writing 1 to the status bit */
123 am33xx_prm_rmw_reg_bits(0xffffffff, mask
, inst
, rstst_offs
);
125 /* de-assert the reset control line */
128 am33xx_prm_rmw_reg_bits(mask
, 0, inst
, rstctrl_offs
);
130 /* wait the status to be set */
131 omap_test_timeout(am33xx_prm_is_hardreset_asserted(st_shift
, 0, inst
,
133 MAX_MODULE_HARDRESET_WAIT
, c
);
135 return (c
== MAX_MODULE_HARDRESET_WAIT
) ? -EBUSY
: 0;
138 static int am33xx_pwrdm_set_next_pwrst(struct powerdomain
*pwrdm
, u8 pwrst
)
140 am33xx_prm_rmw_reg_bits(OMAP_POWERSTATE_MASK
,
141 (pwrst
<< OMAP_POWERSTATE_SHIFT
),
142 pwrdm
->prcm_offs
, pwrdm
->pwrstctrl_offs
);
146 static int am33xx_pwrdm_read_next_pwrst(struct powerdomain
*pwrdm
)
150 v
= am33xx_prm_read_reg(pwrdm
->prcm_offs
, pwrdm
->pwrstctrl_offs
);
151 v
&= OMAP_POWERSTATE_MASK
;
152 v
>>= OMAP_POWERSTATE_SHIFT
;
157 static int am33xx_pwrdm_read_pwrst(struct powerdomain
*pwrdm
)
161 v
= am33xx_prm_read_reg(pwrdm
->prcm_offs
, pwrdm
->pwrstst_offs
);
162 v
&= OMAP_POWERSTATEST_MASK
;
163 v
>>= OMAP_POWERSTATEST_SHIFT
;
168 static int am33xx_pwrdm_set_lowpwrstchange(struct powerdomain
*pwrdm
)
170 am33xx_prm_rmw_reg_bits(AM33XX_LOWPOWERSTATECHANGE_MASK
,
171 (1 << AM33XX_LOWPOWERSTATECHANGE_SHIFT
),
172 pwrdm
->prcm_offs
, pwrdm
->pwrstctrl_offs
);
176 static int am33xx_pwrdm_clear_all_prev_pwrst(struct powerdomain
*pwrdm
)
178 am33xx_prm_rmw_reg_bits(AM33XX_LASTPOWERSTATEENTERED_MASK
,
179 AM33XX_LASTPOWERSTATEENTERED_MASK
,
180 pwrdm
->prcm_offs
, pwrdm
->pwrstst_offs
);
184 static int am33xx_pwrdm_set_logic_retst(struct powerdomain
*pwrdm
, u8 pwrst
)
188 m
= pwrdm
->logicretstate_mask
;
192 am33xx_prm_rmw_reg_bits(m
, (pwrst
<< __ffs(m
)),
193 pwrdm
->prcm_offs
, pwrdm
->pwrstctrl_offs
);
198 static int am33xx_pwrdm_read_logic_pwrst(struct powerdomain
*pwrdm
)
202 v
= am33xx_prm_read_reg(pwrdm
->prcm_offs
, pwrdm
->pwrstst_offs
);
203 v
&= AM33XX_LOGICSTATEST_MASK
;
204 v
>>= AM33XX_LOGICSTATEST_SHIFT
;
209 static int am33xx_pwrdm_read_logic_retst(struct powerdomain
*pwrdm
)
213 m
= pwrdm
->logicretstate_mask
;
217 v
= am33xx_prm_read_reg(pwrdm
->prcm_offs
, pwrdm
->pwrstctrl_offs
);
224 static int am33xx_pwrdm_set_mem_onst(struct powerdomain
*pwrdm
, u8 bank
,
229 m
= pwrdm
->mem_on_mask
[bank
];
233 am33xx_prm_rmw_reg_bits(m
, (pwrst
<< __ffs(m
)),
234 pwrdm
->prcm_offs
, pwrdm
->pwrstctrl_offs
);
239 static int am33xx_pwrdm_set_mem_retst(struct powerdomain
*pwrdm
, u8 bank
,
244 m
= pwrdm
->mem_ret_mask
[bank
];
248 am33xx_prm_rmw_reg_bits(m
, (pwrst
<< __ffs(m
)),
249 pwrdm
->prcm_offs
, pwrdm
->pwrstctrl_offs
);
254 static int am33xx_pwrdm_read_mem_pwrst(struct powerdomain
*pwrdm
, u8 bank
)
258 m
= pwrdm
->mem_pwrst_mask
[bank
];
262 v
= am33xx_prm_read_reg(pwrdm
->prcm_offs
, pwrdm
->pwrstst_offs
);
269 static int am33xx_pwrdm_read_mem_retst(struct powerdomain
*pwrdm
, u8 bank
)
273 m
= pwrdm
->mem_retst_mask
[bank
];
277 v
= am33xx_prm_read_reg(pwrdm
->prcm_offs
, pwrdm
->pwrstctrl_offs
);
284 static int am33xx_pwrdm_wait_transition(struct powerdomain
*pwrdm
)
289 * REVISIT: pwrdm_wait_transition() may be better implemented
290 * via a callback and a periodic timer check -- how long do we expect
291 * powerdomain transitions to take?
294 /* XXX Is this udelay() value meaningful? */
295 while ((am33xx_prm_read_reg(pwrdm
->prcm_offs
, pwrdm
->pwrstst_offs
)
296 & OMAP_INTRANSITION_MASK
) &&
297 (c
++ < PWRDM_TRANSITION_BAILOUT
))
300 if (c
> PWRDM_TRANSITION_BAILOUT
) {
301 pr_err("powerdomain: %s: waited too long to complete transition\n",
306 pr_debug("powerdomain: completed transition in %d loops\n", c
);
311 static int am33xx_check_vcvp(void)
313 /* No VC/VP on am33xx devices */
318 * am33xx_prm_global_warm_sw_reset - reboot the device via warm reset
320 * Immediately reboots the device through warm reset.
322 static void am33xx_prm_global_sw_reset(void)
325 * Historically AM33xx performed warm reset for all requested reboot_mode.
326 * Keep this behaviour unchanged for all except newly added REBOOT_COLD.
328 u32 mask
= AM33XX_RST_GLOBAL_WARM_SW_MASK
;
330 if (prm_reboot_mode
== REBOOT_COLD
)
331 mask
= AM33XX_RST_GLOBAL_COLD_SW_MASK
;
333 am33xx_prm_rmw_reg_bits(mask
,
335 AM33XX_PRM_DEVICE_MOD
,
336 AM33XX_PRM_RSTCTRL_OFFSET
);
339 (void)am33xx_prm_read_reg(AM33XX_PRM_DEVICE_MOD
,
340 AM33XX_PRM_RSTCTRL_OFFSET
);
343 static void am33xx_pwrdm_save_context(struct powerdomain
*pwrdm
)
345 pwrdm
->context
= am33xx_prm_read_reg(pwrdm
->prcm_offs
,
346 pwrdm
->pwrstctrl_offs
);
348 * Do not save LOWPOWERSTATECHANGE, writing a 1 indicates a request,
349 * reading back a 1 indicates a request in progress.
351 pwrdm
->context
&= ~AM33XX_LOWPOWERSTATECHANGE_MASK
;
354 static void am33xx_pwrdm_restore_context(struct powerdomain
*pwrdm
)
358 st
= am33xx_prm_read_reg(pwrdm
->prcm_offs
,
359 pwrdm
->pwrstst_offs
);
361 am33xx_prm_write_reg(pwrdm
->context
, pwrdm
->prcm_offs
,
362 pwrdm
->pwrstctrl_offs
);
364 /* Make sure we only wait for a transition if there is one */
365 st
&= OMAP_POWERSTATEST_MASK
;
366 ctrl
= OMAP_POWERSTATEST_MASK
& pwrdm
->context
;
369 am33xx_pwrdm_wait_transition(pwrdm
);
372 struct pwrdm_ops am33xx_pwrdm_operations
= {
373 .pwrdm_set_next_pwrst
= am33xx_pwrdm_set_next_pwrst
,
374 .pwrdm_read_next_pwrst
= am33xx_pwrdm_read_next_pwrst
,
375 .pwrdm_read_pwrst
= am33xx_pwrdm_read_pwrst
,
376 .pwrdm_set_logic_retst
= am33xx_pwrdm_set_logic_retst
,
377 .pwrdm_read_logic_pwrst
= am33xx_pwrdm_read_logic_pwrst
,
378 .pwrdm_read_logic_retst
= am33xx_pwrdm_read_logic_retst
,
379 .pwrdm_clear_all_prev_pwrst
= am33xx_pwrdm_clear_all_prev_pwrst
,
380 .pwrdm_set_lowpwrstchange
= am33xx_pwrdm_set_lowpwrstchange
,
381 .pwrdm_read_mem_pwrst
= am33xx_pwrdm_read_mem_pwrst
,
382 .pwrdm_read_mem_retst
= am33xx_pwrdm_read_mem_retst
,
383 .pwrdm_set_mem_onst
= am33xx_pwrdm_set_mem_onst
,
384 .pwrdm_set_mem_retst
= am33xx_pwrdm_set_mem_retst
,
385 .pwrdm_wait_transition
= am33xx_pwrdm_wait_transition
,
386 .pwrdm_has_voltdm
= am33xx_check_vcvp
,
387 .pwrdm_save_context
= am33xx_pwrdm_save_context
,
388 .pwrdm_restore_context
= am33xx_pwrdm_restore_context
,
391 static struct prm_ll_data am33xx_prm_ll_data
= {
392 .assert_hardreset
= am33xx_prm_assert_hardreset
,
393 .deassert_hardreset
= am33xx_prm_deassert_hardreset
,
394 .is_hardreset_asserted
= am33xx_prm_is_hardreset_asserted
,
395 .reset_system
= am33xx_prm_global_sw_reset
,
398 int __init
am33xx_prm_init(const struct omap_prcm_init_data
*data
)
400 return prm_register(&am33xx_prm_ll_data
);
403 static void __exit
am33xx_prm_exit(void)
405 prm_unregister(&am33xx_prm_ll_data
);
407 __exitcall(am33xx_prm_exit
);