1cf21405fSPaul Walmsley /* 2cf21405fSPaul Walmsley * OMAP2/3 PRM module functions 3cf21405fSPaul Walmsley * 4cf21405fSPaul Walmsley * Copyright (C) 2010 Texas Instruments, Inc. 5cf21405fSPaul Walmsley * Copyright (C) 2010 Nokia Corporation 6cf21405fSPaul Walmsley * Benoît Cousson 7cf21405fSPaul Walmsley * Paul Walmsley 8cf21405fSPaul Walmsley * 9cf21405fSPaul Walmsley * This program is free software; you can redistribute it and/or modify 10cf21405fSPaul Walmsley * it under the terms of the GNU General Public License version 2 as 11cf21405fSPaul Walmsley * published by the Free Software Foundation. 12cf21405fSPaul Walmsley */ 13cf21405fSPaul Walmsley 14cf21405fSPaul Walmsley #include <linux/kernel.h> 15cf21405fSPaul Walmsley #include <linux/errno.h> 16cf21405fSPaul Walmsley #include <linux/err.h> 1759fb659bSPaul Walmsley #include <linux/io.h> 18cf21405fSPaul Walmsley 19cf21405fSPaul Walmsley #include <plat/common.h> 20cf21405fSPaul Walmsley #include <plat/cpu.h> 21cf21405fSPaul Walmsley #include <plat/prcm.h> 22cf21405fSPaul Walmsley 2359fb659bSPaul Walmsley #include "prm2xxx_3xxx.h" 2459fb659bSPaul Walmsley #include "cm2xxx_3xxx.h" 25cf21405fSPaul Walmsley #include "prm-regbits-24xx.h" 26cf21405fSPaul Walmsley #include "prm-regbits-34xx.h" 27cf21405fSPaul Walmsley 28*c4d7e58fSPaul Walmsley u32 omap2_prm_read_mod_reg(s16 module, u16 idx) 2959fb659bSPaul Walmsley { 3059fb659bSPaul Walmsley return __raw_readl(prm_base + module + idx); 3159fb659bSPaul Walmsley } 3259fb659bSPaul Walmsley 33*c4d7e58fSPaul Walmsley void omap2_prm_write_mod_reg(u32 val, s16 module, u16 idx) 3459fb659bSPaul Walmsley { 3559fb659bSPaul Walmsley __raw_writel(val, prm_base + module + idx); 3659fb659bSPaul Walmsley } 3759fb659bSPaul Walmsley 3859fb659bSPaul Walmsley /* Read-modify-write a register in a PRM module. Caller must lock */ 39*c4d7e58fSPaul Walmsley u32 omap2_prm_rmw_mod_reg_bits(u32 mask, u32 bits, s16 module, s16 idx) 4059fb659bSPaul Walmsley { 4159fb659bSPaul Walmsley u32 v; 4259fb659bSPaul Walmsley 43*c4d7e58fSPaul Walmsley v = omap2_prm_read_mod_reg(module, idx); 4459fb659bSPaul Walmsley v &= ~mask; 4559fb659bSPaul Walmsley v |= bits; 46*c4d7e58fSPaul Walmsley omap2_prm_write_mod_reg(v, module, idx); 4759fb659bSPaul Walmsley 4859fb659bSPaul Walmsley return v; 4959fb659bSPaul Walmsley } 5059fb659bSPaul Walmsley 5159fb659bSPaul Walmsley /* Read a PRM register, AND it, and shift the result down to bit 0 */ 52*c4d7e58fSPaul Walmsley u32 omap2_prm_read_mod_bits_shift(s16 domain, s16 idx, u32 mask) 5359fb659bSPaul Walmsley { 5459fb659bSPaul Walmsley u32 v; 5559fb659bSPaul Walmsley 56*c4d7e58fSPaul Walmsley v = omap2_prm_read_mod_reg(domain, idx); 5759fb659bSPaul Walmsley v &= mask; 5859fb659bSPaul Walmsley v >>= __ffs(mask); 5959fb659bSPaul Walmsley 6059fb659bSPaul Walmsley return v; 6159fb659bSPaul Walmsley } 6259fb659bSPaul Walmsley 63*c4d7e58fSPaul Walmsley u32 omap2_prm_set_mod_reg_bits(u32 bits, s16 module, s16 idx) 6459fb659bSPaul Walmsley { 65*c4d7e58fSPaul Walmsley return omap2_prm_rmw_mod_reg_bits(bits, bits, module, idx); 6659fb659bSPaul Walmsley } 6759fb659bSPaul Walmsley 68*c4d7e58fSPaul Walmsley u32 omap2_prm_clear_mod_reg_bits(u32 bits, s16 module, s16 idx) 6959fb659bSPaul Walmsley { 70*c4d7e58fSPaul Walmsley return omap2_prm_rmw_mod_reg_bits(bits, 0x0, module, idx); 7159fb659bSPaul Walmsley } 7259fb659bSPaul Walmsley 7359fb659bSPaul Walmsley 74cf21405fSPaul Walmsley /** 75cf21405fSPaul Walmsley * omap2_prm_is_hardreset_asserted - read the HW reset line state of 76cf21405fSPaul Walmsley * submodules contained in the hwmod module 77cf21405fSPaul Walmsley * @prm_mod: PRM submodule base (e.g. CORE_MOD) 78cf21405fSPaul Walmsley * @shift: register bit shift corresponding to the reset line to check 79cf21405fSPaul Walmsley * 80cf21405fSPaul Walmsley * Returns 1 if the (sub)module hardreset line is currently asserted, 81cf21405fSPaul Walmsley * 0 if the (sub)module hardreset line is not currently asserted, or 82cf21405fSPaul Walmsley * -EINVAL if called while running on a non-OMAP2/3 chip. 83cf21405fSPaul Walmsley */ 84cf21405fSPaul Walmsley int omap2_prm_is_hardreset_asserted(s16 prm_mod, u8 shift) 85cf21405fSPaul Walmsley { 86cf21405fSPaul Walmsley if (!(cpu_is_omap24xx() || cpu_is_omap34xx())) 87cf21405fSPaul Walmsley return -EINVAL; 88cf21405fSPaul Walmsley 89*c4d7e58fSPaul Walmsley return omap2_prm_read_mod_bits_shift(prm_mod, OMAP2_RM_RSTCTRL, 90cf21405fSPaul Walmsley (1 << shift)); 91cf21405fSPaul Walmsley } 92cf21405fSPaul Walmsley 93cf21405fSPaul Walmsley /** 94cf21405fSPaul Walmsley * omap2_prm_assert_hardreset - assert the HW reset line of a submodule 95cf21405fSPaul Walmsley * @prm_mod: PRM submodule base (e.g. CORE_MOD) 96cf21405fSPaul Walmsley * @shift: register bit shift corresponding to the reset line to assert 97cf21405fSPaul Walmsley * 98cf21405fSPaul Walmsley * Some IPs like dsp or iva contain processors that require an HW 99cf21405fSPaul Walmsley * reset line to be asserted / deasserted in order to fully enable the 100cf21405fSPaul Walmsley * IP. These modules may have multiple hard-reset lines that reset 101cf21405fSPaul Walmsley * different 'submodules' inside the IP block. This function will 102cf21405fSPaul Walmsley * place the submodule into reset. Returns 0 upon success or -EINVAL 103cf21405fSPaul Walmsley * upon an argument error. 104cf21405fSPaul Walmsley */ 105cf21405fSPaul Walmsley int omap2_prm_assert_hardreset(s16 prm_mod, u8 shift) 106cf21405fSPaul Walmsley { 107cf21405fSPaul Walmsley u32 mask; 108cf21405fSPaul Walmsley 109cf21405fSPaul Walmsley if (!(cpu_is_omap24xx() || cpu_is_omap34xx())) 110cf21405fSPaul Walmsley return -EINVAL; 111cf21405fSPaul Walmsley 112cf21405fSPaul Walmsley mask = 1 << shift; 113*c4d7e58fSPaul Walmsley omap2_prm_rmw_mod_reg_bits(mask, mask, prm_mod, OMAP2_RM_RSTCTRL); 114cf21405fSPaul Walmsley 115cf21405fSPaul Walmsley return 0; 116cf21405fSPaul Walmsley } 117cf21405fSPaul Walmsley 118cf21405fSPaul Walmsley /** 119cf21405fSPaul Walmsley * omap2_prm_deassert_hardreset - deassert a submodule hardreset line and wait 120cf21405fSPaul Walmsley * @prm_mod: PRM submodule base (e.g. CORE_MOD) 121cf21405fSPaul Walmsley * @shift: register bit shift corresponding to the reset line to deassert 122cf21405fSPaul Walmsley * 123cf21405fSPaul Walmsley * Some IPs like dsp or iva contain processors that require an HW 124cf21405fSPaul Walmsley * reset line to be asserted / deasserted in order to fully enable the 125cf21405fSPaul Walmsley * IP. These modules may have multiple hard-reset lines that reset 126cf21405fSPaul Walmsley * different 'submodules' inside the IP block. This function will 127cf21405fSPaul Walmsley * take the submodule out of reset and wait until the PRCM indicates 128cf21405fSPaul Walmsley * that the reset has completed before returning. Returns 0 upon success or 129cf21405fSPaul Walmsley * -EINVAL upon an argument error, -EEXIST if the submodule was already out 130cf21405fSPaul Walmsley * of reset, or -EBUSY if the submodule did not exit reset promptly. 131cf21405fSPaul Walmsley */ 132cf21405fSPaul Walmsley int omap2_prm_deassert_hardreset(s16 prm_mod, u8 shift) 133cf21405fSPaul Walmsley { 134cf21405fSPaul Walmsley u32 mask; 135cf21405fSPaul Walmsley int c; 136cf21405fSPaul Walmsley 137cf21405fSPaul Walmsley if (!(cpu_is_omap24xx() || cpu_is_omap34xx())) 138cf21405fSPaul Walmsley return -EINVAL; 139cf21405fSPaul Walmsley 140cf21405fSPaul Walmsley mask = 1 << shift; 141cf21405fSPaul Walmsley 142cf21405fSPaul Walmsley /* Check the current status to avoid de-asserting the line twice */ 143*c4d7e58fSPaul Walmsley if (omap2_prm_read_mod_bits_shift(prm_mod, OMAP2_RM_RSTCTRL, mask) == 0) 144cf21405fSPaul Walmsley return -EEXIST; 145cf21405fSPaul Walmsley 146cf21405fSPaul Walmsley /* Clear the reset status by writing 1 to the status bit */ 147*c4d7e58fSPaul Walmsley omap2_prm_rmw_mod_reg_bits(0xffffffff, mask, prm_mod, OMAP2_RM_RSTST); 148cf21405fSPaul Walmsley /* de-assert the reset control line */ 149*c4d7e58fSPaul Walmsley omap2_prm_rmw_mod_reg_bits(mask, 0, prm_mod, OMAP2_RM_RSTCTRL); 150cf21405fSPaul Walmsley /* wait the status to be set */ 151*c4d7e58fSPaul Walmsley omap_test_timeout(omap2_prm_read_mod_bits_shift(prm_mod, OMAP2_RM_RSTST, 152cf21405fSPaul Walmsley mask), 153cf21405fSPaul Walmsley MAX_MODULE_HARDRESET_WAIT, c); 154cf21405fSPaul Walmsley 155cf21405fSPaul Walmsley return (c == MAX_MODULE_HARDRESET_WAIT) ? -EBUSY : 0; 156cf21405fSPaul Walmsley } 157