1*52e6676eSThomas Gleixner // SPDX-License-Identifier: GPL-2.0-only
2ddd04b98SVaibhav Hiremath /*
3ddd04b98SVaibhav Hiremath * AM33XX PRM functions
4ddd04b98SVaibhav Hiremath *
53aa36fddSAlexander A. Klimov * Copyright (C) 2011-2012 Texas Instruments Incorporated - https://www.ti.com/
6ddd04b98SVaibhav Hiremath */
7ddd04b98SVaibhav Hiremath
8ddd04b98SVaibhav Hiremath #include <linux/kernel.h>
9ddd04b98SVaibhav Hiremath #include <linux/types.h>
10ddd04b98SVaibhav Hiremath #include <linux/errno.h>
11ddd04b98SVaibhav Hiremath #include <linux/err.h>
12ddd04b98SVaibhav Hiremath #include <linux/io.h>
13ddd04b98SVaibhav Hiremath
1449815399SPaul Walmsley #include "powerdomain.h"
15ddd04b98SVaibhav Hiremath #include "prm33xx.h"
16ddd04b98SVaibhav Hiremath #include "prm-regbits-33xx.h"
17ddd04b98SVaibhav Hiremath
18840b7eb8STero Kristo #define AM33XX_PRM_RSTCTRL_OFFSET 0x0000
19840b7eb8STero Kristo
20840b7eb8STero Kristo #define AM33XX_RST_GLOBAL_WARM_SW_MASK (1 << 0)
21840b7eb8STero Kristo
22ddd04b98SVaibhav Hiremath /* Read a register in a PRM instance */
am33xx_prm_read_reg(s16 inst,u16 idx)2385d6670fSTero Kristo static u32 am33xx_prm_read_reg(s16 inst, u16 idx)
24ddd04b98SVaibhav Hiremath {
2590129336STero Kristo return readl_relaxed(prm_base.va + inst + idx);
26ddd04b98SVaibhav Hiremath }
27ddd04b98SVaibhav Hiremath
28ddd04b98SVaibhav Hiremath /* Write into a register in a PRM instance */
am33xx_prm_write_reg(u32 val,s16 inst,u16 idx)2985d6670fSTero Kristo static void am33xx_prm_write_reg(u32 val, s16 inst, u16 idx)
30ddd04b98SVaibhav Hiremath {
3190129336STero Kristo writel_relaxed(val, prm_base.va + inst + idx);
32ddd04b98SVaibhav Hiremath }
33ddd04b98SVaibhav Hiremath
34ddd04b98SVaibhav Hiremath /* Read-modify-write a register in PRM. Caller must lock */
am33xx_prm_rmw_reg_bits(u32 mask,u32 bits,s16 inst,s16 idx)3585d6670fSTero Kristo static u32 am33xx_prm_rmw_reg_bits(u32 mask, u32 bits, s16 inst, s16 idx)
36ddd04b98SVaibhav Hiremath {
37ddd04b98SVaibhav Hiremath u32 v;
38ddd04b98SVaibhav Hiremath
39ddd04b98SVaibhav Hiremath v = am33xx_prm_read_reg(inst, idx);
40ddd04b98SVaibhav Hiremath v &= ~mask;
41ddd04b98SVaibhav Hiremath v |= bits;
42ddd04b98SVaibhav Hiremath am33xx_prm_write_reg(v, inst, idx);
43ddd04b98SVaibhav Hiremath
44ddd04b98SVaibhav Hiremath return v;
45ddd04b98SVaibhav Hiremath }
46ddd04b98SVaibhav Hiremath
47ddd04b98SVaibhav Hiremath /**
48ddd04b98SVaibhav Hiremath * am33xx_prm_is_hardreset_asserted - read the HW reset line state of
49ddd04b98SVaibhav Hiremath * submodules contained in the hwmod module
50ddd04b98SVaibhav Hiremath * @shift: register bit shift corresponding to the reset line to check
511bc28b34STero Kristo * @part: PRM partition, ignored for AM33xx
52ddd04b98SVaibhav Hiremath * @inst: CM instance register offset (*_INST macro)
53ddd04b98SVaibhav Hiremath * @rstctrl_offs: RM_RSTCTRL register address offset for this module
54ddd04b98SVaibhav Hiremath *
55ddd04b98SVaibhav Hiremath * Returns 1 if the (sub)module hardreset line is currently asserted,
56ddd04b98SVaibhav Hiremath * 0 if the (sub)module hardreset line is not currently asserted, or
57ddd04b98SVaibhav Hiremath * -EINVAL upon parameter error.
58ddd04b98SVaibhav Hiremath */
am33xx_prm_is_hardreset_asserted(u8 shift,u8 part,s16 inst,u16 rstctrl_offs)591bc28b34STero Kristo static int am33xx_prm_is_hardreset_asserted(u8 shift, u8 part, s16 inst,
601bc28b34STero Kristo u16 rstctrl_offs)
61ddd04b98SVaibhav Hiremath {
62ddd04b98SVaibhav Hiremath u32 v;
63ddd04b98SVaibhav Hiremath
64ddd04b98SVaibhav Hiremath v = am33xx_prm_read_reg(inst, rstctrl_offs);
65ddd04b98SVaibhav Hiremath v &= 1 << shift;
66ddd04b98SVaibhav Hiremath v >>= shift;
67ddd04b98SVaibhav Hiremath
68ddd04b98SVaibhav Hiremath return v;
69ddd04b98SVaibhav Hiremath }
70ddd04b98SVaibhav Hiremath
71ddd04b98SVaibhav Hiremath /**
72ddd04b98SVaibhav Hiremath * am33xx_prm_assert_hardreset - assert the HW reset line of a submodule
73ddd04b98SVaibhav Hiremath * @shift: register bit shift corresponding to the reset line to assert
74efd44dc3STero Kristo * @part: CM partition, ignored for AM33xx
75ddd04b98SVaibhav Hiremath * @inst: CM instance register offset (*_INST macro)
76ddd04b98SVaibhav Hiremath * @rstctrl_reg: RM_RSTCTRL register address for this module
77ddd04b98SVaibhav Hiremath *
78ddd04b98SVaibhav Hiremath * Some IPs like dsp, ipu or iva contain processors that require an HW
79ddd04b98SVaibhav Hiremath * reset line to be asserted / deasserted in order to fully enable the
80ddd04b98SVaibhav Hiremath * IP. These modules may have multiple hard-reset lines that reset
81ddd04b98SVaibhav Hiremath * different 'submodules' inside the IP block. This function will
82ddd04b98SVaibhav Hiremath * place the submodule into reset. Returns 0 upon success or -EINVAL
83ddd04b98SVaibhav Hiremath * upon an argument error.
84ddd04b98SVaibhav Hiremath */
am33xx_prm_assert_hardreset(u8 shift,u8 part,s16 inst,u16 rstctrl_offs)85efd44dc3STero Kristo static int am33xx_prm_assert_hardreset(u8 shift, u8 part, s16 inst,
86efd44dc3STero Kristo u16 rstctrl_offs)
87ddd04b98SVaibhav Hiremath {
88ddd04b98SVaibhav Hiremath u32 mask = 1 << shift;
89ddd04b98SVaibhav Hiremath
90ddd04b98SVaibhav Hiremath am33xx_prm_rmw_reg_bits(mask, mask, inst, rstctrl_offs);
91ddd04b98SVaibhav Hiremath
92ddd04b98SVaibhav Hiremath return 0;
93ddd04b98SVaibhav Hiremath }
94ddd04b98SVaibhav Hiremath
95ddd04b98SVaibhav Hiremath /**
96ddd04b98SVaibhav Hiremath * am33xx_prm_deassert_hardreset - deassert a submodule hardreset line and
97ddd04b98SVaibhav Hiremath * wait
98ddd04b98SVaibhav Hiremath * @shift: register bit shift corresponding to the reset line to deassert
9937fb59d7STero Kristo * @st_shift: reset status register bit shift corresponding to the reset line
10037fb59d7STero Kristo * @part: PRM partition, not used for AM33xx
101ddd04b98SVaibhav Hiremath * @inst: CM instance register offset (*_INST macro)
102ddd04b98SVaibhav Hiremath * @rstctrl_reg: RM_RSTCTRL register address for this module
103ddd04b98SVaibhav Hiremath * @rstst_reg: RM_RSTST register address for this module
104ddd04b98SVaibhav Hiremath *
105ddd04b98SVaibhav Hiremath * Some IPs like dsp, ipu or iva contain processors that require an HW
106ddd04b98SVaibhav Hiremath * reset line to be asserted / deasserted in order to fully enable the
107ddd04b98SVaibhav Hiremath * IP. These modules may have multiple hard-reset lines that reset
108ddd04b98SVaibhav Hiremath * different 'submodules' inside the IP block. This function will
109ddd04b98SVaibhav Hiremath * take the submodule out of reset and wait until the PRCM indicates
110ddd04b98SVaibhav Hiremath * that the reset has completed before returning. Returns 0 upon success or
111ddd04b98SVaibhav Hiremath * -EINVAL upon an argument error, -EEXIST if the submodule was already out
112ddd04b98SVaibhav Hiremath * of reset, or -EBUSY if the submodule did not exit reset promptly.
113ddd04b98SVaibhav Hiremath */
am33xx_prm_deassert_hardreset(u8 shift,u8 st_shift,u8 part,s16 inst,u16 rstctrl_offs,u16 rstst_offs)11437fb59d7STero Kristo static int am33xx_prm_deassert_hardreset(u8 shift, u8 st_shift, u8 part,
11537fb59d7STero Kristo s16 inst, u16 rstctrl_offs,
11637fb59d7STero Kristo u16 rstst_offs)
117ddd04b98SVaibhav Hiremath {
118ddd04b98SVaibhav Hiremath int c;
1193c06f1b8SVaibhav Bedia u32 mask = 1 << st_shift;
120ddd04b98SVaibhav Hiremath
121ddd04b98SVaibhav Hiremath /* Check the current status to avoid de-asserting the line twice */
1221bc28b34STero Kristo if (am33xx_prm_is_hardreset_asserted(shift, 0, inst, rstctrl_offs) == 0)
123ddd04b98SVaibhav Hiremath return -EEXIST;
124ddd04b98SVaibhav Hiremath
125ddd04b98SVaibhav Hiremath /* Clear the reset status by writing 1 to the status bit */
126ddd04b98SVaibhav Hiremath am33xx_prm_rmw_reg_bits(0xffffffff, mask, inst, rstst_offs);
127ddd04b98SVaibhav Hiremath
1283c06f1b8SVaibhav Bedia /* de-assert the reset control line */
1293c06f1b8SVaibhav Bedia mask = 1 << shift;
1303c06f1b8SVaibhav Bedia
1313c06f1b8SVaibhav Bedia am33xx_prm_rmw_reg_bits(mask, 0, inst, rstctrl_offs);
1323c06f1b8SVaibhav Bedia
1333c06f1b8SVaibhav Bedia /* wait the status to be set */
1341bc28b34STero Kristo omap_test_timeout(am33xx_prm_is_hardreset_asserted(st_shift, 0, inst,
135ddd04b98SVaibhav Hiremath rstst_offs),
136ddd04b98SVaibhav Hiremath MAX_MODULE_HARDRESET_WAIT, c);
137ddd04b98SVaibhav Hiremath
138ddd04b98SVaibhav Hiremath return (c == MAX_MODULE_HARDRESET_WAIT) ? -EBUSY : 0;
139ddd04b98SVaibhav Hiremath }
14049815399SPaul Walmsley
am33xx_pwrdm_set_next_pwrst(struct powerdomain * pwrdm,u8 pwrst)14149815399SPaul Walmsley static int am33xx_pwrdm_set_next_pwrst(struct powerdomain *pwrdm, u8 pwrst)
14249815399SPaul Walmsley {
14349815399SPaul Walmsley am33xx_prm_rmw_reg_bits(OMAP_POWERSTATE_MASK,
14449815399SPaul Walmsley (pwrst << OMAP_POWERSTATE_SHIFT),
14549815399SPaul Walmsley pwrdm->prcm_offs, pwrdm->pwrstctrl_offs);
14649815399SPaul Walmsley return 0;
14749815399SPaul Walmsley }
14849815399SPaul Walmsley
am33xx_pwrdm_read_next_pwrst(struct powerdomain * pwrdm)14949815399SPaul Walmsley static int am33xx_pwrdm_read_next_pwrst(struct powerdomain *pwrdm)
15049815399SPaul Walmsley {
15149815399SPaul Walmsley u32 v;
15249815399SPaul Walmsley
15349815399SPaul Walmsley v = am33xx_prm_read_reg(pwrdm->prcm_offs, pwrdm->pwrstctrl_offs);
15449815399SPaul Walmsley v &= OMAP_POWERSTATE_MASK;
15549815399SPaul Walmsley v >>= OMAP_POWERSTATE_SHIFT;
15649815399SPaul Walmsley
15749815399SPaul Walmsley return v;
15849815399SPaul Walmsley }
15949815399SPaul Walmsley
am33xx_pwrdm_read_pwrst(struct powerdomain * pwrdm)16049815399SPaul Walmsley static int am33xx_pwrdm_read_pwrst(struct powerdomain *pwrdm)
16149815399SPaul Walmsley {
16249815399SPaul Walmsley u32 v;
16349815399SPaul Walmsley
16449815399SPaul Walmsley v = am33xx_prm_read_reg(pwrdm->prcm_offs, pwrdm->pwrstst_offs);
16549815399SPaul Walmsley v &= OMAP_POWERSTATEST_MASK;
16649815399SPaul Walmsley v >>= OMAP_POWERSTATEST_SHIFT;
16749815399SPaul Walmsley
16849815399SPaul Walmsley return v;
16949815399SPaul Walmsley }
17049815399SPaul Walmsley
am33xx_pwrdm_set_lowpwrstchange(struct powerdomain * pwrdm)17149815399SPaul Walmsley static int am33xx_pwrdm_set_lowpwrstchange(struct powerdomain *pwrdm)
17249815399SPaul Walmsley {
17349815399SPaul Walmsley am33xx_prm_rmw_reg_bits(AM33XX_LOWPOWERSTATECHANGE_MASK,
17449815399SPaul Walmsley (1 << AM33XX_LOWPOWERSTATECHANGE_SHIFT),
17549815399SPaul Walmsley pwrdm->prcm_offs, pwrdm->pwrstctrl_offs);
17649815399SPaul Walmsley return 0;
17749815399SPaul Walmsley }
17849815399SPaul Walmsley
am33xx_pwrdm_clear_all_prev_pwrst(struct powerdomain * pwrdm)17949815399SPaul Walmsley static int am33xx_pwrdm_clear_all_prev_pwrst(struct powerdomain *pwrdm)
18049815399SPaul Walmsley {
18149815399SPaul Walmsley am33xx_prm_rmw_reg_bits(AM33XX_LASTPOWERSTATEENTERED_MASK,
18249815399SPaul Walmsley AM33XX_LASTPOWERSTATEENTERED_MASK,
18349815399SPaul Walmsley pwrdm->prcm_offs, pwrdm->pwrstst_offs);
18449815399SPaul Walmsley return 0;
18549815399SPaul Walmsley }
18649815399SPaul Walmsley
am33xx_pwrdm_set_logic_retst(struct powerdomain * pwrdm,u8 pwrst)18749815399SPaul Walmsley static int am33xx_pwrdm_set_logic_retst(struct powerdomain *pwrdm, u8 pwrst)
18849815399SPaul Walmsley {
18949815399SPaul Walmsley u32 m;
19049815399SPaul Walmsley
19149815399SPaul Walmsley m = pwrdm->logicretstate_mask;
19249815399SPaul Walmsley if (!m)
19349815399SPaul Walmsley return -EINVAL;
19449815399SPaul Walmsley
19549815399SPaul Walmsley am33xx_prm_rmw_reg_bits(m, (pwrst << __ffs(m)),
19649815399SPaul Walmsley pwrdm->prcm_offs, pwrdm->pwrstctrl_offs);
19749815399SPaul Walmsley
19849815399SPaul Walmsley return 0;
19949815399SPaul Walmsley }
20049815399SPaul Walmsley
am33xx_pwrdm_read_logic_pwrst(struct powerdomain * pwrdm)20149815399SPaul Walmsley static int am33xx_pwrdm_read_logic_pwrst(struct powerdomain *pwrdm)
20249815399SPaul Walmsley {
20349815399SPaul Walmsley u32 v;
20449815399SPaul Walmsley
20549815399SPaul Walmsley v = am33xx_prm_read_reg(pwrdm->prcm_offs, pwrdm->pwrstst_offs);
20649815399SPaul Walmsley v &= AM33XX_LOGICSTATEST_MASK;
20749815399SPaul Walmsley v >>= AM33XX_LOGICSTATEST_SHIFT;
20849815399SPaul Walmsley
20949815399SPaul Walmsley return v;
21049815399SPaul Walmsley }
21149815399SPaul Walmsley
am33xx_pwrdm_read_logic_retst(struct powerdomain * pwrdm)21249815399SPaul Walmsley static int am33xx_pwrdm_read_logic_retst(struct powerdomain *pwrdm)
21349815399SPaul Walmsley {
21449815399SPaul Walmsley u32 v, m;
21549815399SPaul Walmsley
21649815399SPaul Walmsley m = pwrdm->logicretstate_mask;
21749815399SPaul Walmsley if (!m)
21849815399SPaul Walmsley return -EINVAL;
21949815399SPaul Walmsley
22049815399SPaul Walmsley v = am33xx_prm_read_reg(pwrdm->prcm_offs, pwrdm->pwrstctrl_offs);
22149815399SPaul Walmsley v &= m;
22249815399SPaul Walmsley v >>= __ffs(m);
22349815399SPaul Walmsley
22449815399SPaul Walmsley return v;
22549815399SPaul Walmsley }
22649815399SPaul Walmsley
am33xx_pwrdm_set_mem_onst(struct powerdomain * pwrdm,u8 bank,u8 pwrst)22749815399SPaul Walmsley static int am33xx_pwrdm_set_mem_onst(struct powerdomain *pwrdm, u8 bank,
22849815399SPaul Walmsley u8 pwrst)
22949815399SPaul Walmsley {
23049815399SPaul Walmsley u32 m;
23149815399SPaul Walmsley
23249815399SPaul Walmsley m = pwrdm->mem_on_mask[bank];
23349815399SPaul Walmsley if (!m)
23449815399SPaul Walmsley return -EINVAL;
23549815399SPaul Walmsley
23649815399SPaul Walmsley am33xx_prm_rmw_reg_bits(m, (pwrst << __ffs(m)),
23749815399SPaul Walmsley pwrdm->prcm_offs, pwrdm->pwrstctrl_offs);
23849815399SPaul Walmsley
23949815399SPaul Walmsley return 0;
24049815399SPaul Walmsley }
24149815399SPaul Walmsley
am33xx_pwrdm_set_mem_retst(struct powerdomain * pwrdm,u8 bank,u8 pwrst)24249815399SPaul Walmsley static int am33xx_pwrdm_set_mem_retst(struct powerdomain *pwrdm, u8 bank,
24349815399SPaul Walmsley u8 pwrst)
24449815399SPaul Walmsley {
24549815399SPaul Walmsley u32 m;
24649815399SPaul Walmsley
24749815399SPaul Walmsley m = pwrdm->mem_ret_mask[bank];
24849815399SPaul Walmsley if (!m)
24949815399SPaul Walmsley return -EINVAL;
25049815399SPaul Walmsley
25149815399SPaul Walmsley am33xx_prm_rmw_reg_bits(m, (pwrst << __ffs(m)),
25249815399SPaul Walmsley pwrdm->prcm_offs, pwrdm->pwrstctrl_offs);
25349815399SPaul Walmsley
25449815399SPaul Walmsley return 0;
25549815399SPaul Walmsley }
25649815399SPaul Walmsley
am33xx_pwrdm_read_mem_pwrst(struct powerdomain * pwrdm,u8 bank)25749815399SPaul Walmsley static int am33xx_pwrdm_read_mem_pwrst(struct powerdomain *pwrdm, u8 bank)
25849815399SPaul Walmsley {
25949815399SPaul Walmsley u32 m, v;
26049815399SPaul Walmsley
26149815399SPaul Walmsley m = pwrdm->mem_pwrst_mask[bank];
26249815399SPaul Walmsley if (!m)
26349815399SPaul Walmsley return -EINVAL;
26449815399SPaul Walmsley
26549815399SPaul Walmsley v = am33xx_prm_read_reg(pwrdm->prcm_offs, pwrdm->pwrstst_offs);
26649815399SPaul Walmsley v &= m;
26749815399SPaul Walmsley v >>= __ffs(m);
26849815399SPaul Walmsley
26949815399SPaul Walmsley return v;
27049815399SPaul Walmsley }
27149815399SPaul Walmsley
am33xx_pwrdm_read_mem_retst(struct powerdomain * pwrdm,u8 bank)27249815399SPaul Walmsley static int am33xx_pwrdm_read_mem_retst(struct powerdomain *pwrdm, u8 bank)
27349815399SPaul Walmsley {
27449815399SPaul Walmsley u32 m, v;
27549815399SPaul Walmsley
27649815399SPaul Walmsley m = pwrdm->mem_retst_mask[bank];
27749815399SPaul Walmsley if (!m)
27849815399SPaul Walmsley return -EINVAL;
27949815399SPaul Walmsley
28049815399SPaul Walmsley v = am33xx_prm_read_reg(pwrdm->prcm_offs, pwrdm->pwrstctrl_offs);
28149815399SPaul Walmsley v &= m;
28249815399SPaul Walmsley v >>= __ffs(m);
28349815399SPaul Walmsley
28449815399SPaul Walmsley return v;
28549815399SPaul Walmsley }
28649815399SPaul Walmsley
am33xx_pwrdm_wait_transition(struct powerdomain * pwrdm)28749815399SPaul Walmsley static int am33xx_pwrdm_wait_transition(struct powerdomain *pwrdm)
28849815399SPaul Walmsley {
28949815399SPaul Walmsley u32 c = 0;
29049815399SPaul Walmsley
29149815399SPaul Walmsley /*
29249815399SPaul Walmsley * REVISIT: pwrdm_wait_transition() may be better implemented
29349815399SPaul Walmsley * via a callback and a periodic timer check -- how long do we expect
29449815399SPaul Walmsley * powerdomain transitions to take?
29549815399SPaul Walmsley */
29649815399SPaul Walmsley
29749815399SPaul Walmsley /* XXX Is this udelay() value meaningful? */
29849815399SPaul Walmsley while ((am33xx_prm_read_reg(pwrdm->prcm_offs, pwrdm->pwrstst_offs)
29949815399SPaul Walmsley & OMAP_INTRANSITION_MASK) &&
30049815399SPaul Walmsley (c++ < PWRDM_TRANSITION_BAILOUT))
30149815399SPaul Walmsley udelay(1);
30249815399SPaul Walmsley
30349815399SPaul Walmsley if (c > PWRDM_TRANSITION_BAILOUT) {
30449815399SPaul Walmsley pr_err("powerdomain: %s: waited too long to complete transition\n",
30549815399SPaul Walmsley pwrdm->name);
30649815399SPaul Walmsley return -EAGAIN;
30749815399SPaul Walmsley }
30849815399SPaul Walmsley
30949815399SPaul Walmsley pr_debug("powerdomain: completed transition in %d loops\n", c);
31049815399SPaul Walmsley
31149815399SPaul Walmsley return 0;
31249815399SPaul Walmsley }
31349815399SPaul Walmsley
am33xx_check_vcvp(void)31463b0420cSRajendra Nayak static int am33xx_check_vcvp(void)
31563b0420cSRajendra Nayak {
31663b0420cSRajendra Nayak /* No VC/VP on am33xx devices */
31763b0420cSRajendra Nayak return 0;
31863b0420cSRajendra Nayak }
31963b0420cSRajendra Nayak
320840b7eb8STero Kristo /**
321840b7eb8STero Kristo * am33xx_prm_global_warm_sw_reset - reboot the device via warm reset
322840b7eb8STero Kristo *
323840b7eb8STero Kristo * Immediately reboots the device through warm reset.
324840b7eb8STero Kristo */
am33xx_prm_global_warm_sw_reset(void)32561c8621eSTero Kristo static void am33xx_prm_global_warm_sw_reset(void)
326840b7eb8STero Kristo {
327840b7eb8STero Kristo am33xx_prm_rmw_reg_bits(AM33XX_RST_GLOBAL_WARM_SW_MASK,
328840b7eb8STero Kristo AM33XX_RST_GLOBAL_WARM_SW_MASK,
329840b7eb8STero Kristo AM33XX_PRM_DEVICE_MOD,
330840b7eb8STero Kristo AM33XX_PRM_RSTCTRL_OFFSET);
331840b7eb8STero Kristo
332840b7eb8STero Kristo /* OCP barrier */
333840b7eb8STero Kristo (void)am33xx_prm_read_reg(AM33XX_PRM_DEVICE_MOD,
334840b7eb8STero Kristo AM33XX_PRM_RSTCTRL_OFFSET);
335840b7eb8STero Kristo }
336840b7eb8STero Kristo
am33xx_pwrdm_save_context(struct powerdomain * pwrdm)337485995b0SRuss Dill static void am33xx_pwrdm_save_context(struct powerdomain *pwrdm)
338485995b0SRuss Dill {
339485995b0SRuss Dill pwrdm->context = am33xx_prm_read_reg(pwrdm->prcm_offs,
340485995b0SRuss Dill pwrdm->pwrstctrl_offs);
341485995b0SRuss Dill /*
342485995b0SRuss Dill * Do not save LOWPOWERSTATECHANGE, writing a 1 indicates a request,
343485995b0SRuss Dill * reading back a 1 indicates a request in progress.
344485995b0SRuss Dill */
345485995b0SRuss Dill pwrdm->context &= ~AM33XX_LOWPOWERSTATECHANGE_MASK;
346485995b0SRuss Dill }
347485995b0SRuss Dill
am33xx_pwrdm_restore_context(struct powerdomain * pwrdm)348485995b0SRuss Dill static void am33xx_pwrdm_restore_context(struct powerdomain *pwrdm)
349485995b0SRuss Dill {
350485995b0SRuss Dill int st, ctrl;
351485995b0SRuss Dill
352485995b0SRuss Dill st = am33xx_prm_read_reg(pwrdm->prcm_offs,
353485995b0SRuss Dill pwrdm->pwrstst_offs);
354485995b0SRuss Dill
355485995b0SRuss Dill am33xx_prm_write_reg(pwrdm->context, pwrdm->prcm_offs,
356485995b0SRuss Dill pwrdm->pwrstctrl_offs);
357485995b0SRuss Dill
358485995b0SRuss Dill /* Make sure we only wait for a transition if there is one */
359485995b0SRuss Dill st &= OMAP_POWERSTATEST_MASK;
360485995b0SRuss Dill ctrl = OMAP_POWERSTATEST_MASK & pwrdm->context;
361485995b0SRuss Dill
362485995b0SRuss Dill if (st != ctrl)
363485995b0SRuss Dill am33xx_pwrdm_wait_transition(pwrdm);
364485995b0SRuss Dill }
365485995b0SRuss Dill
36649815399SPaul Walmsley struct pwrdm_ops am33xx_pwrdm_operations = {
36749815399SPaul Walmsley .pwrdm_set_next_pwrst = am33xx_pwrdm_set_next_pwrst,
36849815399SPaul Walmsley .pwrdm_read_next_pwrst = am33xx_pwrdm_read_next_pwrst,
36949815399SPaul Walmsley .pwrdm_read_pwrst = am33xx_pwrdm_read_pwrst,
37049815399SPaul Walmsley .pwrdm_set_logic_retst = am33xx_pwrdm_set_logic_retst,
37149815399SPaul Walmsley .pwrdm_read_logic_pwrst = am33xx_pwrdm_read_logic_pwrst,
37249815399SPaul Walmsley .pwrdm_read_logic_retst = am33xx_pwrdm_read_logic_retst,
37349815399SPaul Walmsley .pwrdm_clear_all_prev_pwrst = am33xx_pwrdm_clear_all_prev_pwrst,
37449815399SPaul Walmsley .pwrdm_set_lowpwrstchange = am33xx_pwrdm_set_lowpwrstchange,
37549815399SPaul Walmsley .pwrdm_read_mem_pwrst = am33xx_pwrdm_read_mem_pwrst,
37649815399SPaul Walmsley .pwrdm_read_mem_retst = am33xx_pwrdm_read_mem_retst,
37749815399SPaul Walmsley .pwrdm_set_mem_onst = am33xx_pwrdm_set_mem_onst,
37849815399SPaul Walmsley .pwrdm_set_mem_retst = am33xx_pwrdm_set_mem_retst,
37949815399SPaul Walmsley .pwrdm_wait_transition = am33xx_pwrdm_wait_transition,
38063b0420cSRajendra Nayak .pwrdm_has_voltdm = am33xx_check_vcvp,
381485995b0SRuss Dill .pwrdm_save_context = am33xx_pwrdm_save_context,
382485995b0SRuss Dill .pwrdm_restore_context = am33xx_pwrdm_restore_context,
38349815399SPaul Walmsley };
384d9bbe84fSTero Kristo
385efd44dc3STero Kristo static struct prm_ll_data am33xx_prm_ll_data = {
386efd44dc3STero Kristo .assert_hardreset = am33xx_prm_assert_hardreset,
38737fb59d7STero Kristo .deassert_hardreset = am33xx_prm_deassert_hardreset,
3881bc28b34STero Kristo .is_hardreset_asserted = am33xx_prm_is_hardreset_asserted,
38961c8621eSTero Kristo .reset_system = am33xx_prm_global_warm_sw_reset,
390efd44dc3STero Kristo };
391d9bbe84fSTero Kristo
am33xx_prm_init(const struct omap_prcm_init_data * data)392ab7b2ffcSTero Kristo int __init am33xx_prm_init(const struct omap_prcm_init_data *data)
393d9bbe84fSTero Kristo {
394d9bbe84fSTero Kristo return prm_register(&am33xx_prm_ll_data);
395d9bbe84fSTero Kristo }
396d9bbe84fSTero Kristo
am33xx_prm_exit(void)397d9bbe84fSTero Kristo static void __exit am33xx_prm_exit(void)
398d9bbe84fSTero Kristo {
399d9bbe84fSTero Kristo prm_unregister(&am33xx_prm_ll_data);
400d9bbe84fSTero Kristo }
401d9bbe84fSTero Kristo __exitcall(am33xx_prm_exit);
402