Paul Walmsley | cf21405 | 2010-09-21 10:34:10 -0600 | [diff] [blame] | 1 | /* |
| 2 | * OMAP2/3 PRM module functions |
| 3 | * |
| 4 | * Copyright (C) 2010 Texas Instruments, Inc. |
| 5 | * Copyright (C) 2010 Nokia Corporation |
| 6 | * BenoƮt Cousson |
| 7 | * Paul Walmsley |
| 8 | * |
| 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. |
| 12 | */ |
| 13 | |
| 14 | #include <linux/kernel.h> |
Paul Walmsley | cf21405 | 2010-09-21 10:34:10 -0600 | [diff] [blame] | 15 | #include <linux/errno.h> |
| 16 | #include <linux/err.h> |
Paul Walmsley | 59fb659 | 2010-12-21 15:30:55 -0700 | [diff] [blame] | 17 | #include <linux/io.h> |
Paul Walmsley | cf21405 | 2010-09-21 10:34:10 -0600 | [diff] [blame] | 18 | |
| 19 | #include <plat/common.h> |
| 20 | #include <plat/cpu.h> |
| 21 | #include <plat/prcm.h> |
| 22 | |
Kevin Hilman | 58aaa59 | 2011-03-28 10:52:04 -0700 | [diff] [blame^] | 23 | #include "vp.h" |
| 24 | |
Paul Walmsley | 59fb659 | 2010-12-21 15:30:55 -0700 | [diff] [blame] | 25 | #include "prm2xxx_3xxx.h" |
| 26 | #include "cm2xxx_3xxx.h" |
Paul Walmsley | cf21405 | 2010-09-21 10:34:10 -0600 | [diff] [blame] | 27 | #include "prm-regbits-24xx.h" |
| 28 | #include "prm-regbits-34xx.h" |
| 29 | |
Paul Walmsley | c4d7e58 | 2010-12-21 21:05:14 -0700 | [diff] [blame] | 30 | u32 omap2_prm_read_mod_reg(s16 module, u16 idx) |
Paul Walmsley | 59fb659 | 2010-12-21 15:30:55 -0700 | [diff] [blame] | 31 | { |
| 32 | return __raw_readl(prm_base + module + idx); |
| 33 | } |
| 34 | |
Paul Walmsley | c4d7e58 | 2010-12-21 21:05:14 -0700 | [diff] [blame] | 35 | void omap2_prm_write_mod_reg(u32 val, s16 module, u16 idx) |
Paul Walmsley | 59fb659 | 2010-12-21 15:30:55 -0700 | [diff] [blame] | 36 | { |
| 37 | __raw_writel(val, prm_base + module + idx); |
| 38 | } |
| 39 | |
| 40 | /* Read-modify-write a register in a PRM module. Caller must lock */ |
Paul Walmsley | c4d7e58 | 2010-12-21 21:05:14 -0700 | [diff] [blame] | 41 | u32 omap2_prm_rmw_mod_reg_bits(u32 mask, u32 bits, s16 module, s16 idx) |
Paul Walmsley | 59fb659 | 2010-12-21 15:30:55 -0700 | [diff] [blame] | 42 | { |
| 43 | u32 v; |
| 44 | |
Paul Walmsley | c4d7e58 | 2010-12-21 21:05:14 -0700 | [diff] [blame] | 45 | v = omap2_prm_read_mod_reg(module, idx); |
Paul Walmsley | 59fb659 | 2010-12-21 15:30:55 -0700 | [diff] [blame] | 46 | v &= ~mask; |
| 47 | v |= bits; |
Paul Walmsley | c4d7e58 | 2010-12-21 21:05:14 -0700 | [diff] [blame] | 48 | omap2_prm_write_mod_reg(v, module, idx); |
Paul Walmsley | 59fb659 | 2010-12-21 15:30:55 -0700 | [diff] [blame] | 49 | |
| 50 | return v; |
| 51 | } |
| 52 | |
| 53 | /* Read a PRM register, AND it, and shift the result down to bit 0 */ |
Paul Walmsley | c4d7e58 | 2010-12-21 21:05:14 -0700 | [diff] [blame] | 54 | u32 omap2_prm_read_mod_bits_shift(s16 domain, s16 idx, u32 mask) |
Paul Walmsley | 59fb659 | 2010-12-21 15:30:55 -0700 | [diff] [blame] | 55 | { |
| 56 | u32 v; |
| 57 | |
Paul Walmsley | c4d7e58 | 2010-12-21 21:05:14 -0700 | [diff] [blame] | 58 | v = omap2_prm_read_mod_reg(domain, idx); |
Paul Walmsley | 59fb659 | 2010-12-21 15:30:55 -0700 | [diff] [blame] | 59 | v &= mask; |
| 60 | v >>= __ffs(mask); |
| 61 | |
| 62 | return v; |
| 63 | } |
| 64 | |
Paul Walmsley | c4d7e58 | 2010-12-21 21:05:14 -0700 | [diff] [blame] | 65 | u32 omap2_prm_set_mod_reg_bits(u32 bits, s16 module, s16 idx) |
Paul Walmsley | 59fb659 | 2010-12-21 15:30:55 -0700 | [diff] [blame] | 66 | { |
Paul Walmsley | c4d7e58 | 2010-12-21 21:05:14 -0700 | [diff] [blame] | 67 | return omap2_prm_rmw_mod_reg_bits(bits, bits, module, idx); |
Paul Walmsley | 59fb659 | 2010-12-21 15:30:55 -0700 | [diff] [blame] | 68 | } |
| 69 | |
Paul Walmsley | c4d7e58 | 2010-12-21 21:05:14 -0700 | [diff] [blame] | 70 | u32 omap2_prm_clear_mod_reg_bits(u32 bits, s16 module, s16 idx) |
Paul Walmsley | 59fb659 | 2010-12-21 15:30:55 -0700 | [diff] [blame] | 71 | { |
Paul Walmsley | c4d7e58 | 2010-12-21 21:05:14 -0700 | [diff] [blame] | 72 | return omap2_prm_rmw_mod_reg_bits(bits, 0x0, module, idx); |
Paul Walmsley | 59fb659 | 2010-12-21 15:30:55 -0700 | [diff] [blame] | 73 | } |
| 74 | |
| 75 | |
Paul Walmsley | cf21405 | 2010-09-21 10:34:10 -0600 | [diff] [blame] | 76 | /** |
| 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 |
| 81 | * |
| 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. |
| 85 | */ |
| 86 | int omap2_prm_is_hardreset_asserted(s16 prm_mod, u8 shift) |
| 87 | { |
| 88 | if (!(cpu_is_omap24xx() || cpu_is_omap34xx())) |
| 89 | return -EINVAL; |
| 90 | |
Paul Walmsley | c4d7e58 | 2010-12-21 21:05:14 -0700 | [diff] [blame] | 91 | return omap2_prm_read_mod_bits_shift(prm_mod, OMAP2_RM_RSTCTRL, |
Paul Walmsley | cf21405 | 2010-09-21 10:34:10 -0600 | [diff] [blame] | 92 | (1 << shift)); |
| 93 | } |
| 94 | |
| 95 | /** |
| 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 |
| 99 | * |
| 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. |
| 106 | */ |
| 107 | int omap2_prm_assert_hardreset(s16 prm_mod, u8 shift) |
| 108 | { |
| 109 | u32 mask; |
| 110 | |
| 111 | if (!(cpu_is_omap24xx() || cpu_is_omap34xx())) |
| 112 | return -EINVAL; |
| 113 | |
| 114 | mask = 1 << shift; |
Paul Walmsley | c4d7e58 | 2010-12-21 21:05:14 -0700 | [diff] [blame] | 115 | omap2_prm_rmw_mod_reg_bits(mask, mask, prm_mod, OMAP2_RM_RSTCTRL); |
Paul Walmsley | cf21405 | 2010-09-21 10:34:10 -0600 | [diff] [blame] | 116 | |
| 117 | return 0; |
| 118 | } |
| 119 | |
| 120 | /** |
| 121 | * omap2_prm_deassert_hardreset - deassert a submodule hardreset line and wait |
| 122 | * @prm_mod: PRM submodule base (e.g. CORE_MOD) |
omar ramirez | cc1226e | 2011-03-04 13:32:44 -0700 | [diff] [blame] | 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 |
Paul Walmsley | cf21405 | 2010-09-21 10:34:10 -0600 | [diff] [blame] | 125 | * |
| 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. |
| 134 | */ |
omar ramirez | cc1226e | 2011-03-04 13:32:44 -0700 | [diff] [blame] | 135 | int omap2_prm_deassert_hardreset(s16 prm_mod, u8 rst_shift, u8 st_shift) |
Paul Walmsley | cf21405 | 2010-09-21 10:34:10 -0600 | [diff] [blame] | 136 | { |
omar ramirez | cc1226e | 2011-03-04 13:32:44 -0700 | [diff] [blame] | 137 | u32 rst, st; |
Paul Walmsley | cf21405 | 2010-09-21 10:34:10 -0600 | [diff] [blame] | 138 | int c; |
| 139 | |
| 140 | if (!(cpu_is_omap24xx() || cpu_is_omap34xx())) |
| 141 | return -EINVAL; |
| 142 | |
omar ramirez | cc1226e | 2011-03-04 13:32:44 -0700 | [diff] [blame] | 143 | rst = 1 << rst_shift; |
| 144 | st = 1 << st_shift; |
Paul Walmsley | cf21405 | 2010-09-21 10:34:10 -0600 | [diff] [blame] | 145 | |
| 146 | /* Check the current status to avoid de-asserting the line twice */ |
omar ramirez | cc1226e | 2011-03-04 13:32:44 -0700 | [diff] [blame] | 147 | if (omap2_prm_read_mod_bits_shift(prm_mod, OMAP2_RM_RSTCTRL, rst) == 0) |
Paul Walmsley | cf21405 | 2010-09-21 10:34:10 -0600 | [diff] [blame] | 148 | return -EEXIST; |
| 149 | |
| 150 | /* Clear the reset status by writing 1 to the status bit */ |
omar ramirez | cc1226e | 2011-03-04 13:32:44 -0700 | [diff] [blame] | 151 | omap2_prm_rmw_mod_reg_bits(0xffffffff, st, prm_mod, OMAP2_RM_RSTST); |
Paul Walmsley | cf21405 | 2010-09-21 10:34:10 -0600 | [diff] [blame] | 152 | /* de-assert the reset control line */ |
omar ramirez | cc1226e | 2011-03-04 13:32:44 -0700 | [diff] [blame] | 153 | omap2_prm_rmw_mod_reg_bits(rst, 0, prm_mod, OMAP2_RM_RSTCTRL); |
Paul Walmsley | cf21405 | 2010-09-21 10:34:10 -0600 | [diff] [blame] | 154 | /* wait the status to be set */ |
Paul Walmsley | c4d7e58 | 2010-12-21 21:05:14 -0700 | [diff] [blame] | 155 | omap_test_timeout(omap2_prm_read_mod_bits_shift(prm_mod, OMAP2_RM_RSTST, |
omar ramirez | cc1226e | 2011-03-04 13:32:44 -0700 | [diff] [blame] | 156 | st), |
Paul Walmsley | cf21405 | 2010-09-21 10:34:10 -0600 | [diff] [blame] | 157 | MAX_MODULE_HARDRESET_WAIT, c); |
| 158 | |
| 159 | return (c == MAX_MODULE_HARDRESET_WAIT) ? -EBUSY : 0; |
| 160 | } |
Kevin Hilman | 58aaa59 | 2011-03-28 10:52:04 -0700 | [diff] [blame^] | 161 | |
| 162 | /* PRM VP */ |
| 163 | |
| 164 | /* |
| 165 | * struct omap3_vp - OMAP3 VP register access description. |
| 166 | * @tranxdone_status: VP_TRANXDONE_ST bitmask in PRM_IRQSTATUS_MPU reg |
| 167 | */ |
| 168 | struct omap3_vp { |
| 169 | u32 tranxdone_status; |
| 170 | }; |
| 171 | |
| 172 | struct omap3_vp omap3_vp[] = { |
| 173 | [OMAP3_VP_VDD_MPU_ID] = { |
| 174 | .tranxdone_status = OMAP3430_VP1_TRANXDONE_ST_MASK, |
| 175 | }, |
| 176 | [OMAP3_VP_VDD_CORE_ID] = { |
| 177 | .tranxdone_status = OMAP3430_VP2_TRANXDONE_ST_MASK, |
| 178 | }, |
| 179 | }; |
| 180 | |
| 181 | #define MAX_VP_ID ARRAY_SIZE(omap3_vp); |
| 182 | |
| 183 | u32 omap3_prm_vp_check_txdone(u8 vp_id) |
| 184 | { |
| 185 | struct omap3_vp *vp = &omap3_vp[vp_id]; |
| 186 | u32 irqstatus; |
| 187 | |
| 188 | irqstatus = omap2_prm_read_mod_reg(OCP_MOD, |
| 189 | OMAP3_PRM_IRQSTATUS_MPU_OFFSET); |
| 190 | return irqstatus & vp->tranxdone_status; |
| 191 | } |
| 192 | |
| 193 | void omap3_prm_vp_clear_txdone(u8 vp_id) |
| 194 | { |
| 195 | struct omap3_vp *vp = &omap3_vp[vp_id]; |
| 196 | |
| 197 | omap2_prm_write_mod_reg(vp->tranxdone_status, |
| 198 | OCP_MOD, OMAP3_PRM_IRQSTATUS_MPU_OFFSET); |
| 199 | } |