Paul Walmsley | 139563a | 2012-10-21 01:01:10 -0600 | [diff] [blame] | 1 | /* |
| 2 | * OMAP3xxx PRM module functions |
| 3 | * |
| 4 | * Copyright (C) 2010-2012 Texas Instruments, Inc. |
| 5 | * Copyright (C) 2010 Nokia Corporation |
| 6 | * BenoƮt Cousson |
| 7 | * Paul Walmsley |
Paul Walmsley | 4981539 | 2012-10-21 01:01:10 -0600 | [diff] [blame^] | 8 | * Rajendra Nayak <rnayak@ti.com> |
Paul Walmsley | 139563a | 2012-10-21 01:01:10 -0600 | [diff] [blame] | 9 | * |
| 10 | * This program is free software; you can redistribute it and/or modify |
| 11 | * it under the terms of the GNU General Public License version 2 as |
| 12 | * published by the Free Software Foundation. |
| 13 | */ |
| 14 | |
| 15 | #include <linux/kernel.h> |
| 16 | #include <linux/errno.h> |
| 17 | #include <linux/err.h> |
| 18 | #include <linux/io.h> |
| 19 | #include <linux/irq.h> |
| 20 | |
| 21 | #include "common.h" |
| 22 | #include <plat/cpu.h> |
| 23 | #include <plat/prcm.h> |
| 24 | |
| 25 | #include "vp.h" |
Paul Walmsley | 4981539 | 2012-10-21 01:01:10 -0600 | [diff] [blame^] | 26 | #include "powerdomain.h" |
Paul Walmsley | 139563a | 2012-10-21 01:01:10 -0600 | [diff] [blame] | 27 | #include "prm3xxx.h" |
Paul Walmsley | 4981539 | 2012-10-21 01:01:10 -0600 | [diff] [blame^] | 28 | #include "prm2xxx_3xxx.h" |
Paul Walmsley | 139563a | 2012-10-21 01:01:10 -0600 | [diff] [blame] | 29 | #include "cm2xxx_3xxx.h" |
| 30 | #include "prm-regbits-34xx.h" |
| 31 | |
| 32 | static const struct omap_prcm_irq omap3_prcm_irqs[] = { |
| 33 | OMAP_PRCM_IRQ("wkup", 0, 0), |
| 34 | OMAP_PRCM_IRQ("io", 9, 1), |
| 35 | }; |
| 36 | |
| 37 | static struct omap_prcm_irq_setup omap3_prcm_irq_setup = { |
| 38 | .ack = OMAP3_PRM_IRQSTATUS_MPU_OFFSET, |
| 39 | .mask = OMAP3_PRM_IRQENABLE_MPU_OFFSET, |
| 40 | .nr_regs = 1, |
| 41 | .irqs = omap3_prcm_irqs, |
| 42 | .nr_irqs = ARRAY_SIZE(omap3_prcm_irqs), |
| 43 | .irq = 11 + OMAP_INTC_START, |
| 44 | .read_pending_irqs = &omap3xxx_prm_read_pending_irqs, |
| 45 | .ocp_barrier = &omap3xxx_prm_ocp_barrier, |
| 46 | .save_and_clear_irqen = &omap3xxx_prm_save_and_clear_irqen, |
| 47 | .restore_irqen = &omap3xxx_prm_restore_irqen, |
| 48 | }; |
| 49 | |
| 50 | /* PRM VP */ |
| 51 | |
| 52 | /* |
| 53 | * struct omap3_vp - OMAP3 VP register access description. |
| 54 | * @tranxdone_status: VP_TRANXDONE_ST bitmask in PRM_IRQSTATUS_MPU reg |
| 55 | */ |
| 56 | struct omap3_vp { |
| 57 | u32 tranxdone_status; |
| 58 | }; |
| 59 | |
| 60 | static struct omap3_vp omap3_vp[] = { |
| 61 | [OMAP3_VP_VDD_MPU_ID] = { |
| 62 | .tranxdone_status = OMAP3430_VP1_TRANXDONE_ST_MASK, |
| 63 | }, |
| 64 | [OMAP3_VP_VDD_CORE_ID] = { |
| 65 | .tranxdone_status = OMAP3430_VP2_TRANXDONE_ST_MASK, |
| 66 | }, |
| 67 | }; |
| 68 | |
| 69 | #define MAX_VP_ID ARRAY_SIZE(omap3_vp); |
| 70 | |
| 71 | u32 omap3_prm_vp_check_txdone(u8 vp_id) |
| 72 | { |
| 73 | struct omap3_vp *vp = &omap3_vp[vp_id]; |
| 74 | u32 irqstatus; |
| 75 | |
| 76 | irqstatus = omap2_prm_read_mod_reg(OCP_MOD, |
| 77 | OMAP3_PRM_IRQSTATUS_MPU_OFFSET); |
| 78 | return irqstatus & vp->tranxdone_status; |
| 79 | } |
| 80 | |
| 81 | void omap3_prm_vp_clear_txdone(u8 vp_id) |
| 82 | { |
| 83 | struct omap3_vp *vp = &omap3_vp[vp_id]; |
| 84 | |
| 85 | omap2_prm_write_mod_reg(vp->tranxdone_status, |
| 86 | OCP_MOD, OMAP3_PRM_IRQSTATUS_MPU_OFFSET); |
| 87 | } |
| 88 | |
| 89 | u32 omap3_prm_vcvp_read(u8 offset) |
| 90 | { |
| 91 | return omap2_prm_read_mod_reg(OMAP3430_GR_MOD, offset); |
| 92 | } |
| 93 | |
| 94 | void omap3_prm_vcvp_write(u32 val, u8 offset) |
| 95 | { |
| 96 | omap2_prm_write_mod_reg(val, OMAP3430_GR_MOD, offset); |
| 97 | } |
| 98 | |
| 99 | u32 omap3_prm_vcvp_rmw(u32 mask, u32 bits, u8 offset) |
| 100 | { |
| 101 | return omap2_prm_rmw_mod_reg_bits(mask, bits, OMAP3430_GR_MOD, offset); |
| 102 | } |
| 103 | |
| 104 | /** |
| 105 | * omap3xxx_prm_read_pending_irqs - read pending PRM MPU IRQs into @events |
| 106 | * @events: ptr to a u32, preallocated by caller |
| 107 | * |
| 108 | * Read PRM_IRQSTATUS_MPU bits, AND'ed with the currently-enabled PRM |
| 109 | * MPU IRQs, and store the result into the u32 pointed to by @events. |
| 110 | * No return value. |
| 111 | */ |
| 112 | void omap3xxx_prm_read_pending_irqs(unsigned long *events) |
| 113 | { |
| 114 | u32 mask, st; |
| 115 | |
| 116 | /* XXX Can the mask read be avoided (e.g., can it come from RAM?) */ |
| 117 | mask = omap2_prm_read_mod_reg(OCP_MOD, OMAP3_PRM_IRQENABLE_MPU_OFFSET); |
| 118 | st = omap2_prm_read_mod_reg(OCP_MOD, OMAP3_PRM_IRQSTATUS_MPU_OFFSET); |
| 119 | |
| 120 | events[0] = mask & st; |
| 121 | } |
| 122 | |
| 123 | /** |
| 124 | * omap3xxx_prm_ocp_barrier - force buffered MPU writes to the PRM to complete |
| 125 | * |
| 126 | * Force any buffered writes to the PRM IP block to complete. Needed |
| 127 | * by the PRM IRQ handler, which reads and writes directly to the IP |
| 128 | * block, to avoid race conditions after acknowledging or clearing IRQ |
| 129 | * bits. No return value. |
| 130 | */ |
| 131 | void omap3xxx_prm_ocp_barrier(void) |
| 132 | { |
| 133 | omap2_prm_read_mod_reg(OCP_MOD, OMAP3_PRM_REVISION_OFFSET); |
| 134 | } |
| 135 | |
| 136 | /** |
| 137 | * omap3xxx_prm_save_and_clear_irqen - save/clear PRM_IRQENABLE_MPU reg |
| 138 | * @saved_mask: ptr to a u32 array to save IRQENABLE bits |
| 139 | * |
| 140 | * Save the PRM_IRQENABLE_MPU register to @saved_mask. @saved_mask |
| 141 | * must be allocated by the caller. Intended to be used in the PRM |
| 142 | * interrupt handler suspend callback. The OCP barrier is needed to |
| 143 | * ensure the write to disable PRM interrupts reaches the PRM before |
| 144 | * returning; otherwise, spurious interrupts might occur. No return |
| 145 | * value. |
| 146 | */ |
| 147 | void omap3xxx_prm_save_and_clear_irqen(u32 *saved_mask) |
| 148 | { |
| 149 | saved_mask[0] = omap2_prm_read_mod_reg(OCP_MOD, |
| 150 | OMAP3_PRM_IRQENABLE_MPU_OFFSET); |
| 151 | omap2_prm_write_mod_reg(0, OCP_MOD, OMAP3_PRM_IRQENABLE_MPU_OFFSET); |
| 152 | |
| 153 | /* OCP barrier */ |
| 154 | omap2_prm_read_mod_reg(OCP_MOD, OMAP3_PRM_REVISION_OFFSET); |
| 155 | } |
| 156 | |
| 157 | /** |
| 158 | * omap3xxx_prm_restore_irqen - set PRM_IRQENABLE_MPU register from args |
| 159 | * @saved_mask: ptr to a u32 array of IRQENABLE bits saved previously |
| 160 | * |
| 161 | * Restore the PRM_IRQENABLE_MPU register from @saved_mask. Intended |
| 162 | * to be used in the PRM interrupt handler resume callback to restore |
| 163 | * values saved by omap3xxx_prm_save_and_clear_irqen(). No OCP |
| 164 | * barrier should be needed here; any pending PRM interrupts will fire |
| 165 | * once the writes reach the PRM. No return value. |
| 166 | */ |
| 167 | void omap3xxx_prm_restore_irqen(u32 *saved_mask) |
| 168 | { |
| 169 | omap2_prm_write_mod_reg(saved_mask[0], OCP_MOD, |
| 170 | OMAP3_PRM_IRQENABLE_MPU_OFFSET); |
| 171 | } |
| 172 | |
| 173 | /** |
| 174 | * omap3xxx_prm_reconfigure_io_chain - clear latches and reconfigure I/O chain |
| 175 | * |
| 176 | * Clear any previously-latched I/O wakeup events and ensure that the |
| 177 | * I/O wakeup gates are aligned with the current mux settings. Works |
| 178 | * by asserting WUCLKIN, waiting for WUCLKOUT to be asserted, and then |
| 179 | * deasserting WUCLKIN and clearing the ST_IO_CHAIN WKST bit. No |
| 180 | * return value. |
| 181 | */ |
| 182 | void omap3xxx_prm_reconfigure_io_chain(void) |
| 183 | { |
| 184 | int i = 0; |
| 185 | |
| 186 | omap2_prm_set_mod_reg_bits(OMAP3430_EN_IO_CHAIN_MASK, WKUP_MOD, |
| 187 | PM_WKEN); |
| 188 | |
| 189 | omap_test_timeout(omap2_prm_read_mod_reg(WKUP_MOD, PM_WKST) & |
| 190 | OMAP3430_ST_IO_CHAIN_MASK, |
| 191 | MAX_IOPAD_LATCH_TIME, i); |
| 192 | if (i == MAX_IOPAD_LATCH_TIME) |
| 193 | pr_warn("PRM: I/O chain clock line assertion timed out\n"); |
| 194 | |
| 195 | omap2_prm_clear_mod_reg_bits(OMAP3430_EN_IO_CHAIN_MASK, WKUP_MOD, |
| 196 | PM_WKEN); |
| 197 | |
| 198 | omap2_prm_set_mod_reg_bits(OMAP3430_ST_IO_CHAIN_MASK, WKUP_MOD, |
| 199 | PM_WKST); |
| 200 | |
| 201 | omap2_prm_read_mod_reg(WKUP_MOD, PM_WKST); |
| 202 | } |
| 203 | |
| 204 | /** |
| 205 | * omap3xxx_prm_enable_io_wakeup - enable wakeup events from I/O wakeup latches |
| 206 | * |
| 207 | * Activates the I/O wakeup event latches and allows events logged by |
| 208 | * those latches to signal a wakeup event to the PRCM. For I/O |
| 209 | * wakeups to occur, WAKEUPENABLE bits must be set in the pad mux |
| 210 | * registers, and omap3xxx_prm_reconfigure_io_chain() must be called. |
| 211 | * No return value. |
| 212 | */ |
| 213 | static void __init omap3xxx_prm_enable_io_wakeup(void) |
| 214 | { |
| 215 | if (omap3_has_io_wakeup()) |
| 216 | omap2_prm_set_mod_reg_bits(OMAP3430_EN_IO_MASK, WKUP_MOD, |
| 217 | PM_WKEN); |
| 218 | } |
| 219 | |
Paul Walmsley | 4981539 | 2012-10-21 01:01:10 -0600 | [diff] [blame^] | 220 | /* Powerdomain low-level functions */ |
| 221 | |
| 222 | /* Applicable only for OMAP3. Not supported on OMAP2 */ |
| 223 | static int omap3_pwrdm_read_prev_pwrst(struct powerdomain *pwrdm) |
| 224 | { |
| 225 | return omap2_prm_read_mod_bits_shift(pwrdm->prcm_offs, |
| 226 | OMAP3430_PM_PREPWSTST, |
| 227 | OMAP3430_LASTPOWERSTATEENTERED_MASK); |
| 228 | } |
| 229 | |
| 230 | static int omap3_pwrdm_read_logic_pwrst(struct powerdomain *pwrdm) |
| 231 | { |
| 232 | return omap2_prm_read_mod_bits_shift(pwrdm->prcm_offs, |
| 233 | OMAP2_PM_PWSTST, |
| 234 | OMAP3430_LOGICSTATEST_MASK); |
| 235 | } |
| 236 | |
| 237 | static int omap3_pwrdm_read_logic_retst(struct powerdomain *pwrdm) |
| 238 | { |
| 239 | return omap2_prm_read_mod_bits_shift(pwrdm->prcm_offs, |
| 240 | OMAP2_PM_PWSTCTRL, |
| 241 | OMAP3430_LOGICSTATEST_MASK); |
| 242 | } |
| 243 | |
| 244 | static int omap3_pwrdm_read_prev_logic_pwrst(struct powerdomain *pwrdm) |
| 245 | { |
| 246 | return omap2_prm_read_mod_bits_shift(pwrdm->prcm_offs, |
| 247 | OMAP3430_PM_PREPWSTST, |
| 248 | OMAP3430_LASTLOGICSTATEENTERED_MASK); |
| 249 | } |
| 250 | |
| 251 | static int omap3_get_mem_bank_lastmemst_mask(u8 bank) |
| 252 | { |
| 253 | switch (bank) { |
| 254 | case 0: |
| 255 | return OMAP3430_LASTMEM1STATEENTERED_MASK; |
| 256 | case 1: |
| 257 | return OMAP3430_LASTMEM2STATEENTERED_MASK; |
| 258 | case 2: |
| 259 | return OMAP3430_LASTSHAREDL2CACHEFLATSTATEENTERED_MASK; |
| 260 | case 3: |
| 261 | return OMAP3430_LASTL2FLATMEMSTATEENTERED_MASK; |
| 262 | default: |
| 263 | WARN_ON(1); /* should never happen */ |
| 264 | return -EEXIST; |
| 265 | } |
| 266 | return 0; |
| 267 | } |
| 268 | |
| 269 | static int omap3_pwrdm_read_prev_mem_pwrst(struct powerdomain *pwrdm, u8 bank) |
| 270 | { |
| 271 | u32 m; |
| 272 | |
| 273 | m = omap3_get_mem_bank_lastmemst_mask(bank); |
| 274 | |
| 275 | return omap2_prm_read_mod_bits_shift(pwrdm->prcm_offs, |
| 276 | OMAP3430_PM_PREPWSTST, m); |
| 277 | } |
| 278 | |
| 279 | static int omap3_pwrdm_clear_all_prev_pwrst(struct powerdomain *pwrdm) |
| 280 | { |
| 281 | omap2_prm_write_mod_reg(0, pwrdm->prcm_offs, OMAP3430_PM_PREPWSTST); |
| 282 | return 0; |
| 283 | } |
| 284 | |
| 285 | static int omap3_pwrdm_enable_hdwr_sar(struct powerdomain *pwrdm) |
| 286 | { |
| 287 | return omap2_prm_rmw_mod_reg_bits(0, |
| 288 | 1 << OMAP3430ES2_SAVEANDRESTORE_SHIFT, |
| 289 | pwrdm->prcm_offs, OMAP2_PM_PWSTCTRL); |
| 290 | } |
| 291 | |
| 292 | static int omap3_pwrdm_disable_hdwr_sar(struct powerdomain *pwrdm) |
| 293 | { |
| 294 | return omap2_prm_rmw_mod_reg_bits(1 << OMAP3430ES2_SAVEANDRESTORE_SHIFT, |
| 295 | 0, pwrdm->prcm_offs, |
| 296 | OMAP2_PM_PWSTCTRL); |
| 297 | } |
| 298 | |
| 299 | struct pwrdm_ops omap3_pwrdm_operations = { |
| 300 | .pwrdm_set_next_pwrst = omap2_pwrdm_set_next_pwrst, |
| 301 | .pwrdm_read_next_pwrst = omap2_pwrdm_read_next_pwrst, |
| 302 | .pwrdm_read_pwrst = omap2_pwrdm_read_pwrst, |
| 303 | .pwrdm_read_prev_pwrst = omap3_pwrdm_read_prev_pwrst, |
| 304 | .pwrdm_set_logic_retst = omap2_pwrdm_set_logic_retst, |
| 305 | .pwrdm_read_logic_pwrst = omap3_pwrdm_read_logic_pwrst, |
| 306 | .pwrdm_read_logic_retst = omap3_pwrdm_read_logic_retst, |
| 307 | .pwrdm_read_prev_logic_pwrst = omap3_pwrdm_read_prev_logic_pwrst, |
| 308 | .pwrdm_set_mem_onst = omap2_pwrdm_set_mem_onst, |
| 309 | .pwrdm_set_mem_retst = omap2_pwrdm_set_mem_retst, |
| 310 | .pwrdm_read_mem_pwrst = omap2_pwrdm_read_mem_pwrst, |
| 311 | .pwrdm_read_mem_retst = omap2_pwrdm_read_mem_retst, |
| 312 | .pwrdm_read_prev_mem_pwrst = omap3_pwrdm_read_prev_mem_pwrst, |
| 313 | .pwrdm_clear_all_prev_pwrst = omap3_pwrdm_clear_all_prev_pwrst, |
| 314 | .pwrdm_enable_hdwr_sar = omap3_pwrdm_enable_hdwr_sar, |
| 315 | .pwrdm_disable_hdwr_sar = omap3_pwrdm_disable_hdwr_sar, |
| 316 | .pwrdm_wait_transition = omap2_pwrdm_wait_transition, |
| 317 | }; |
| 318 | |
| 319 | /* |
| 320 | * |
| 321 | */ |
| 322 | |
Paul Walmsley | 139563a | 2012-10-21 01:01:10 -0600 | [diff] [blame] | 323 | static int __init omap3xxx_prm_init(void) |
| 324 | { |
| 325 | int ret; |
| 326 | |
| 327 | if (!cpu_is_omap34xx()) |
| 328 | return 0; |
| 329 | |
| 330 | omap3xxx_prm_enable_io_wakeup(); |
| 331 | ret = omap_prcm_register_chain_handler(&omap3_prcm_irq_setup); |
| 332 | if (!ret) |
| 333 | irq_set_status_flags(omap_prcm_event_to_irq("io"), |
| 334 | IRQ_NOAUTOEN); |
| 335 | |
| 336 | return ret; |
| 337 | } |
| 338 | subsys_initcall(omap3xxx_prm_init); |