2 * OMAP2/3 PRM module functions
4 * Copyright (C) 2010 Texas Instruments, Inc.
5 * Copyright (C) 2010 Nokia Corporation
9 * This program is free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License version 2 as
11 * published by the Free Software Foundation.
14 #include <linux/kernel.h>
15 #include <linux/errno.h>
16 #include <linux/err.h>
19 #include <plat/common.h>
21 #include <plat/prcm.h>
25 #include "prm2xxx_3xxx.h"
26 #include "cm2xxx_3xxx.h"
27 #include "prm-regbits-24xx.h"
28 #include "prm-regbits-34xx.h"
30 u32
omap2_prm_read_mod_reg(s16 module
, u16 idx
)
32 return __raw_readl(prm_base
+ module
+ idx
);
35 void omap2_prm_write_mod_reg(u32 val
, s16 module
, u16 idx
)
37 __raw_writel(val
, prm_base
+ module
+ idx
);
40 /* Read-modify-write a register in a PRM module. Caller must lock */
41 u32
omap2_prm_rmw_mod_reg_bits(u32 mask
, u32 bits
, s16 module
, s16 idx
)
45 v
= omap2_prm_read_mod_reg(module
, idx
);
48 omap2_prm_write_mod_reg(v
, module
, idx
);
53 /* Read a PRM register, AND it, and shift the result down to bit 0 */
54 u32
omap2_prm_read_mod_bits_shift(s16 domain
, s16 idx
, u32 mask
)
58 v
= omap2_prm_read_mod_reg(domain
, idx
);
65 u32
omap2_prm_set_mod_reg_bits(u32 bits
, s16 module
, s16 idx
)
67 return omap2_prm_rmw_mod_reg_bits(bits
, bits
, module
, idx
);
70 u32
omap2_prm_clear_mod_reg_bits(u32 bits
, s16 module
, s16 idx
)
72 return omap2_prm_rmw_mod_reg_bits(bits
, 0x0, module
, idx
);
77 * omap2_prm_is_hardreset_asserted - read the HW reset line state of
78 * submodules contained in the hwmod module
79 * @prm_mod: PRM submodule base (e.g. CORE_MOD)
80 * @shift: register bit shift corresponding to the reset line to check
82 * Returns 1 if the (sub)module hardreset line is currently asserted,
83 * 0 if the (sub)module hardreset line is not currently asserted, or
84 * -EINVAL if called while running on a non-OMAP2/3 chip.
86 int omap2_prm_is_hardreset_asserted(s16 prm_mod
, u8 shift
)
88 if (!(cpu_is_omap24xx() || cpu_is_omap34xx()))
91 return omap2_prm_read_mod_bits_shift(prm_mod
, OMAP2_RM_RSTCTRL
,
96 * omap2_prm_assert_hardreset - assert the HW reset line of a submodule
97 * @prm_mod: PRM submodule base (e.g. CORE_MOD)
98 * @shift: register bit shift corresponding to the reset line to assert
100 * Some IPs like dsp or iva contain processors that require an HW
101 * reset line to be asserted / deasserted in order to fully enable the
102 * IP. These modules may have multiple hard-reset lines that reset
103 * different 'submodules' inside the IP block. This function will
104 * place the submodule into reset. Returns 0 upon success or -EINVAL
105 * upon an argument error.
107 int omap2_prm_assert_hardreset(s16 prm_mod
, u8 shift
)
111 if (!(cpu_is_omap24xx() || cpu_is_omap34xx()))
115 omap2_prm_rmw_mod_reg_bits(mask
, mask
, prm_mod
, OMAP2_RM_RSTCTRL
);
121 * omap2_prm_deassert_hardreset - deassert a submodule hardreset line and wait
122 * @prm_mod: PRM submodule base (e.g. CORE_MOD)
123 * @rst_shift: register bit shift corresponding to the reset line to deassert
124 * @st_shift: register bit shift for the status of the deasserted submodule
126 * Some IPs like dsp or iva contain processors that require an HW
127 * reset line to be asserted / deasserted in order to fully enable the
128 * IP. These modules may have multiple hard-reset lines that reset
129 * different 'submodules' inside the IP block. This function will
130 * take the submodule out of reset and wait until the PRCM indicates
131 * that the reset has completed before returning. Returns 0 upon success or
132 * -EINVAL upon an argument error, -EEXIST if the submodule was already out
133 * of reset, or -EBUSY if the submodule did not exit reset promptly.
135 int omap2_prm_deassert_hardreset(s16 prm_mod
, u8 rst_shift
, u8 st_shift
)
140 if (!(cpu_is_omap24xx() || cpu_is_omap34xx()))
143 rst
= 1 << rst_shift
;
146 /* Check the current status to avoid de-asserting the line twice */
147 if (omap2_prm_read_mod_bits_shift(prm_mod
, OMAP2_RM_RSTCTRL
, rst
) == 0)
150 /* Clear the reset status by writing 1 to the status bit */
151 omap2_prm_rmw_mod_reg_bits(0xffffffff, st
, prm_mod
, OMAP2_RM_RSTST
);
152 /* de-assert the reset control line */
153 omap2_prm_rmw_mod_reg_bits(rst
, 0, prm_mod
, OMAP2_RM_RSTCTRL
);
154 /* wait the status to be set */
155 omap_test_timeout(omap2_prm_read_mod_bits_shift(prm_mod
, OMAP2_RM_RSTST
,
157 MAX_MODULE_HARDRESET_WAIT
, c
);
159 return (c
== MAX_MODULE_HARDRESET_WAIT
) ? -EBUSY
: 0;
165 * struct omap3_prm_irq - OMAP3 PRM IRQ register access description.
166 * @vp_tranxdone_status: VP_TRANXDONE_ST bitmask in PRM_IRQSTATUS_MPU reg
167 * @abb_tranxdone_status: ABB_TRANXDONE_ST bitmask in PRM_IRQSTATUS_MPU reg
168 * (ONLY for OMAP3630)
170 struct omap3_prm_irq
{
171 u32 vp_tranxdone_status
;
172 u32 abb_tranxdone_status
;
175 static struct omap3_prm_irq omap3_prm_irqs
[] = {
176 [OMAP3_PRM_IRQ_VDD_MPU_ID
] = {
177 .vp_tranxdone_status
= OMAP3430_VP1_TRANXDONE_ST_MASK
,
178 .abb_tranxdone_status
= OMAP3630_ABB_LDO_TRANXDONE_ST_MASK
,
180 [OMAP3_PRM_IRQ_VDD_CORE_ID
] = {
181 .vp_tranxdone_status
= OMAP3430_VP2_TRANXDONE_ST_MASK
,
182 /* no abb for core */
186 #define MAX_VP_ID ARRAY_SIZE(omap3_vp);
188 u32
omap3_prm_vp_check_txdone(u8 irq_id
)
190 struct omap3_prm_irq
*irq
= &omap3_prm_irqs
[irq_id
];
193 irqstatus
= omap2_prm_read_mod_reg(OCP_MOD
,
194 OMAP3_PRM_IRQSTATUS_MPU_OFFSET
);
195 return irqstatus
& irq
->vp_tranxdone_status
;
198 void omap3_prm_vp_clear_txdone(u8 irq_id
)
200 struct omap3_prm_irq
*irq
= &omap3_prm_irqs
[irq_id
];
202 omap2_prm_write_mod_reg(irq
->vp_tranxdone_status
,
203 OCP_MOD
, OMAP3_PRM_IRQSTATUS_MPU_OFFSET
);
206 u32
omap36xx_prm_abb_check_txdone(u8 irq_id
)
208 struct omap3_prm_irq
*irq
= &omap3_prm_irqs
[irq_id
];
211 irqstatus
= omap2_prm_read_mod_reg(OCP_MOD
,
212 OMAP3_PRM_IRQSTATUS_MPU_OFFSET
);
213 return irqstatus
& irq
->abb_tranxdone_status
;
216 void omap36xx_prm_abb_clear_txdone(u8 irq_id
)
218 struct omap3_prm_irq
*irq
= &omap3_prm_irqs
[irq_id
];
220 omap2_prm_write_mod_reg(irq
->abb_tranxdone_status
,
221 OCP_MOD
, OMAP3_PRM_IRQSTATUS_MPU_OFFSET
);
224 u32
omap3_prm_vcvp_read(u8 offset
)
226 return omap2_prm_read_mod_reg(OMAP3430_GR_MOD
, offset
);
229 void omap3_prm_vcvp_write(u32 val
, u8 offset
)
231 omap2_prm_write_mod_reg(val
, OMAP3430_GR_MOD
, offset
);
234 u32
omap3_prm_vcvp_rmw(u32 mask
, u32 bits
, u8 offset
)
236 return omap2_prm_rmw_mod_reg_bits(mask
, bits
, OMAP3430_GR_MOD
, offset
);