Back to home page

OSCL-LXR

 
 

    


0001 /* SPDX-License-Identifier: GPL-2.0-or-later */
0002 /*
0003  * (C) Copyright 2007
0004  * Texas Instruments
0005  * Karthik Dasu <karthik-dp@ti.com>
0006  *
0007  * (C) Copyright 2004
0008  * Texas Instruments, <www.ti.com>
0009  * Richard Woodruff <r-woodruff2@ti.com>
0010  */
0011 #include <linux/linkage.h>
0012 
0013 #include <asm/assembler.h>
0014 
0015 #include "omap34xx.h"
0016 #include "iomap.h"
0017 #include "cm3xxx.h"
0018 #include "prm3xxx.h"
0019 #include "sdrc.h"
0020 #include "sram.h"
0021 #include "control.h"
0022 
0023 /*
0024  * Registers access definitions
0025  */
0026 #define SDRC_SCRATCHPAD_SEM_OFFS    0xc
0027 #define SDRC_SCRATCHPAD_SEM_V   OMAP343X_SCRATCHPAD_REGADDR\
0028                     (SDRC_SCRATCHPAD_SEM_OFFS)
0029 #define PM_PREPWSTST_CORE_P OMAP3430_PRM_BASE + CORE_MOD +\
0030                     OMAP3430_PM_PREPWSTST
0031 #define PM_PWSTCTRL_MPU_P   OMAP3430_PRM_BASE + MPU_MOD + OMAP2_PM_PWSTCTRL
0032 #define CM_IDLEST1_CORE_V   OMAP34XX_CM_REGADDR(CORE_MOD, CM_IDLEST1)
0033 #define CM_IDLEST_CKGEN_V   OMAP34XX_CM_REGADDR(PLL_MOD, CM_IDLEST)
0034 #define SRAM_BASE_P     OMAP3_SRAM_PA
0035 #define CONTROL_STAT        OMAP343X_CTRL_BASE + OMAP343X_CONTROL_STATUS
0036 #define CONTROL_MEM_RTA_CTRL    (OMAP343X_CTRL_BASE +\
0037                     OMAP36XX_CONTROL_MEM_RTA_CTRL)
0038 
0039 /* Move this as correct place is available */
0040 #define SCRATCHPAD_MEM_OFFS 0x310
0041 #define SCRATCHPAD_BASE_P   (OMAP343X_CTRL_BASE +\
0042                     OMAP343X_CONTROL_MEM_WKUP +\
0043                     SCRATCHPAD_MEM_OFFS)
0044 #define SDRC_POWER_V        OMAP34XX_SDRC_REGADDR(SDRC_POWER)
0045 #define SDRC_SYSCONFIG_P    (OMAP343X_SDRC_BASE + SDRC_SYSCONFIG)
0046 #define SDRC_MR_0_P     (OMAP343X_SDRC_BASE + SDRC_MR_0)
0047 #define SDRC_EMR2_0_P       (OMAP343X_SDRC_BASE + SDRC_EMR2_0)
0048 #define SDRC_MANUAL_0_P     (OMAP343X_SDRC_BASE + SDRC_MANUAL_0)
0049 #define SDRC_MR_1_P     (OMAP343X_SDRC_BASE + SDRC_MR_1)
0050 #define SDRC_EMR2_1_P       (OMAP343X_SDRC_BASE + SDRC_EMR2_1)
0051 #define SDRC_MANUAL_1_P     (OMAP343X_SDRC_BASE + SDRC_MANUAL_1)
0052 #define SDRC_DLLA_STATUS_V  OMAP34XX_SDRC_REGADDR(SDRC_DLLA_STATUS)
0053 #define SDRC_DLLA_CTRL_V    OMAP34XX_SDRC_REGADDR(SDRC_DLLA_CTRL)
0054 
0055 /*
0056  * This file needs be built unconditionally as ARM to interoperate correctly
0057  * with non-Thumb-2-capable firmware.
0058  */
0059     .arm
0060 
0061 /*
0062  * API functions
0063  */
0064 
0065     .text
0066 /*
0067  * L2 cache needs to be toggled for stable OFF mode functionality on 3630.
0068  * This function sets up a flag that will allow for this toggling to take
0069  * place on 3630. Hopefully some version in the future may not need this.
0070  */
0071 ENTRY(enable_omap3630_toggle_l2_on_restore)
0072     stmfd   sp!, {lr}   @ save registers on stack
0073     /* Setup so that we will disable and enable l2 */
0074     mov r1, #0x1
0075     adr r3, l2dis_3630_offset
0076     ldr r2, [r3]        @ value for offset
0077     str r1, [r2, r3]        @ write to l2dis_3630
0078     ldmfd   sp!, {pc}   @ restore regs and return
0079 ENDPROC(enable_omap3630_toggle_l2_on_restore)
0080 
0081 /*
0082  * Function to call rom code to save secure ram context.
0083  *
0084  * r0 = physical address of the parameters
0085  */
0086     .arch armv7-a
0087     .arch_extension sec
0088 ENTRY(save_secure_ram_context)
0089     stmfd   sp!, {r4 - r11, lr} @ save registers on stack
0090     mov r3, r0          @ physical address of parameters
0091     mov r0, #25         @ set service ID for PPA
0092     mov r12, r0         @ copy secure service ID in r12
0093     mov r1, #0          @ set task id for ROM code in r1
0094     mov r2, #4          @ set some flags in r2, r6
0095     mov r6, #0xff
0096     dsb             @ data write barrier
0097     dmb             @ data memory barrier
0098     smc #1          @ call SMI monitor (smi #1)
0099     nop
0100     nop
0101     nop
0102     nop
0103     ldmfd   sp!, {r4 - r11, pc}
0104 ENDPROC(save_secure_ram_context)
0105 
0106 /*
0107  * ======================
0108  * == Idle entry point ==
0109  * ======================
0110  */
0111 
0112 /*
0113  * Forces OMAP into idle state
0114  *
0115  * omap34xx_cpu_suspend() - This bit of code saves the CPU context if needed
0116  * and executes the WFI instruction. Calling WFI effectively changes the
0117  * power domains states to the desired target power states.
0118  *
0119  *
0120  * Notes:
0121  * - only the minimum set of functions gets copied to internal SRAM at boot
0122  *   and after wake-up from OFF mode, cf. omap_push_sram_idle. The function
0123  *   pointers in SDRAM or SRAM are called depending on the desired low power
0124  *   target state.
0125  * - when the OMAP wakes up it continues at different execution points
0126  *   depending on the low power mode (non-OFF vs OFF modes),
0127  *   cf. 'Resume path for xxx mode' comments.
0128  */
0129     .align  3
0130 ENTRY(omap34xx_cpu_suspend)
0131     stmfd   sp!, {r4 - r11, lr} @ save registers on stack
0132 
0133     /*
0134      * r0 contains information about saving context:
0135      *   0 - No context lost
0136      *   1 - Only L1 and logic lost
0137      *   2 - Only L2 lost (Even L1 is retained we clean it along with L2)
0138      *   3 - Both L1 and L2 lost and logic lost
0139      */
0140 
0141     /*
0142      * For OFF mode: save context and jump to WFI in SDRAM (omap3_do_wfi)
0143      * For non-OFF modes: jump to the WFI code in SRAM (omap3_do_wfi_sram)
0144      */
0145     ldr r4, omap3_do_wfi_sram_addr
0146     ldr r5, [r4]
0147     cmp r0, #0x0        @ If no context save required,
0148     bxeq    r5          @  jump to the WFI code in SRAM
0149 
0150 
0151     /* Otherwise fall through to the save context code */
0152 save_context_wfi:
0153     /*
0154      * jump out to kernel flush routine
0155      *  - reuse that code is better
0156      *  - it executes in a cached space so is faster than refetch per-block
0157      *  - should be faster and will change with kernel
0158      *  - 'might' have to copy address, load and jump to it
0159      * Flush all data from the L1 data cache before disabling
0160      * SCTLR.C bit.
0161      */
0162     ldr r1, kernel_flush
0163     mov lr, pc
0164     bx  r1
0165 
0166     /*
0167      * Clear the SCTLR.C bit to prevent further data cache
0168      * allocation. Clearing SCTLR.C would make all the data accesses
0169      * strongly ordered and would not hit the cache.
0170      */
0171     mrc p15, 0, r0, c1, c0, 0
0172     bic r0, r0, #(1 << 2)   @ Disable the C bit
0173     mcr p15, 0, r0, c1, c0, 0
0174     isb
0175 
0176     /*
0177      * Invalidate L1 data cache. Even though only invalidate is
0178      * necessary exported flush API is used here. Doing clean
0179      * on already clean cache would be almost NOP.
0180      */
0181     ldr r1, kernel_flush
0182     blx r1
0183     b   omap3_do_wfi
0184 ENDPROC(omap34xx_cpu_suspend)
0185 omap3_do_wfi_sram_addr:
0186     .word omap3_do_wfi_sram
0187 kernel_flush:
0188     .word v7_flush_dcache_all
0189 
0190 /* ===================================
0191  * == WFI instruction => Enter idle ==
0192  * ===================================
0193  */
0194 
0195 /*
0196  * Do WFI instruction
0197  * Includes the resume path for non-OFF modes
0198  *
0199  * This code gets copied to internal SRAM and is accessible
0200  * from both SDRAM and SRAM:
0201  * - executed from SRAM for non-off modes (omap3_do_wfi_sram),
0202  * - executed from SDRAM for OFF mode (omap3_do_wfi).
0203  */
0204     .align  3
0205 ENTRY(omap3_do_wfi)
0206     ldr r4, sdrc_power      @ read the SDRC_POWER register
0207     ldr r5, [r4]        @ read the contents of SDRC_POWER
0208     orr r5, r5, #0x40       @ enable self refresh on idle req
0209     str r5, [r4]        @ write back to SDRC_POWER register
0210 
0211     /* Data memory barrier and Data sync barrier */
0212     dsb
0213     dmb
0214 
0215 /*
0216  * ===================================
0217  * == WFI instruction => Enter idle ==
0218  * ===================================
0219  */
0220     wfi             @ wait for interrupt
0221 
0222 /*
0223  * ===================================
0224  * == Resume path for non-OFF modes ==
0225  * ===================================
0226  */
0227     nop
0228     nop
0229     nop
0230     nop
0231     nop
0232     nop
0233     nop
0234     nop
0235     nop
0236     nop
0237 
0238 /*
0239  * This function implements the erratum ID i581 WA:
0240  *  SDRC state restore before accessing the SDRAM
0241  *
0242  * Only used at return from non-OFF mode. For OFF
0243  * mode the ROM code configures the SDRC and
0244  * the DPLL before calling the restore code directly
0245  * from DDR.
0246  */
0247 
0248 /* Make sure SDRC accesses are ok */
0249 wait_sdrc_ok:
0250 
0251 /* DPLL3 must be locked before accessing the SDRC. Maybe the HW ensures this */
0252     ldr r4, cm_idlest_ckgen
0253 wait_dpll3_lock:
0254     ldr r5, [r4]
0255     tst r5, #1
0256     beq wait_dpll3_lock
0257 
0258     ldr r4, cm_idlest1_core
0259 wait_sdrc_ready:
0260     ldr r5, [r4]
0261     tst r5, #0x2
0262     bne wait_sdrc_ready
0263     /* allow DLL powerdown upon hw idle req */
0264     ldr r4, sdrc_power
0265     ldr r5, [r4]
0266     bic r5, r5, #0x40
0267     str r5, [r4]
0268 
0269 is_dll_in_lock_mode:
0270     /* Is dll in lock mode? */
0271     ldr r4, sdrc_dlla_ctrl
0272     ldr r5, [r4]
0273     tst r5, #0x4
0274     bne exit_nonoff_modes   @ Return if locked
0275     /* wait till dll locks */
0276 wait_dll_lock_timed:
0277     ldr r4, sdrc_dlla_status
0278     /* Wait 20uS for lock */
0279     mov r6, #8
0280 wait_dll_lock:
0281     subs    r6, r6, #0x1
0282     beq kick_dll
0283     ldr r5, [r4]
0284     and r5, r5, #0x4
0285     cmp r5, #0x4
0286     bne wait_dll_lock
0287     b   exit_nonoff_modes   @ Return when locked
0288 
0289     /* disable/reenable DLL if not locked */
0290 kick_dll:
0291     ldr r4, sdrc_dlla_ctrl
0292     ldr r5, [r4]
0293     mov r6, r5
0294     bic r6, #(1<<3)     @ disable dll
0295     str r6, [r4]
0296     dsb
0297     orr r6, r6, #(1<<3)     @ enable dll
0298     str r6, [r4]
0299     dsb
0300     b   wait_dll_lock_timed
0301 
0302 exit_nonoff_modes:
0303     /* Re-enable C-bit if needed */
0304     mrc p15, 0, r0, c1, c0, 0
0305     tst r0, #(1 << 2)       @ Check C bit enabled?
0306     orreq   r0, r0, #(1 << 2)   @ Enable the C bit if cleared
0307     mcreq   p15, 0, r0, c1, c0, 0
0308     isb
0309 
0310 /*
0311  * ===================================
0312  * == Exit point from non-OFF modes ==
0313  * ===================================
0314  */
0315     ldmfd   sp!, {r4 - r11, pc} @ restore regs and return
0316 ENDPROC(omap3_do_wfi)
0317 sdrc_power:
0318     .word   SDRC_POWER_V
0319 cm_idlest1_core:
0320     .word   CM_IDLEST1_CORE_V
0321 cm_idlest_ckgen:
0322     .word   CM_IDLEST_CKGEN_V
0323 sdrc_dlla_status:
0324     .word   SDRC_DLLA_STATUS_V
0325 sdrc_dlla_ctrl:
0326     .word   SDRC_DLLA_CTRL_V
0327 ENTRY(omap3_do_wfi_sz)
0328     .word   . - omap3_do_wfi
0329 
0330 
0331 /*
0332  * ==============================
0333  * == Resume path for OFF mode ==
0334  * ==============================
0335  */
0336 
0337 /*
0338  * The restore_* functions are called by the ROM code
0339  *  when back from WFI in OFF mode.
0340  * Cf. the get_*restore_pointer functions.
0341  *
0342  *  restore_es3: applies to 34xx >= ES3.0
0343  *  restore_3630: applies to 36xx
0344  *  restore: common code for 3xxx
0345  *
0346  * Note: when back from CORE and MPU OFF mode we are running
0347  *  from SDRAM, without MMU, without the caches and prediction.
0348  *  Also the SRAM content has been cleared.
0349  */
0350 ENTRY(omap3_restore_es3)
0351     ldr r5, pm_prepwstst_core_p
0352     ldr r4, [r5]
0353     and r4, r4, #0x3
0354     cmp r4, #0x0    @ Check if previous power state of CORE is OFF
0355     bne omap3_restore   @ Fall through to OMAP3 common code
0356     adr r0, es3_sdrc_fix
0357     ldr r1, sram_base
0358     ldr r2, es3_sdrc_fix_sz
0359     mov r2, r2, ror #2
0360 copy_to_sram:
0361     ldmia   r0!, {r3}   @ val = *src
0362     stmia   r1!, {r3}   @ *dst = val
0363     subs    r2, r2, #0x1    @ num_words--
0364     bne copy_to_sram
0365     ldr r1, sram_base
0366     blx r1
0367     b   omap3_restore   @ Fall through to OMAP3 common code
0368 ENDPROC(omap3_restore_es3)
0369 
0370 ENTRY(omap3_restore_3630)
0371     ldr r1, pm_prepwstst_core_p
0372     ldr r2, [r1]
0373     and r2, r2, #0x3
0374     cmp r2, #0x0    @ Check if previous power state of CORE is OFF
0375     bne omap3_restore   @ Fall through to OMAP3 common code
0376     /* Disable RTA before giving control */
0377     ldr r1, control_mem_rta
0378     mov r2, #OMAP36XX_RTA_DISABLE
0379     str r2, [r1]
0380 ENDPROC(omap3_restore_3630)
0381 
0382     /* Fall through to common code for the remaining logic */
0383 
0384 ENTRY(omap3_restore)
0385     /*
0386      * Read the pwstctrl register to check the reason for mpu reset.
0387      * This tells us what was lost.
0388      */
0389     ldr r1, pm_pwstctrl_mpu
0390     ldr r2, [r1]
0391     and r2, r2, #0x3
0392     cmp r2, #0x0    @ Check if target power state was OFF or RET
0393     bne logic_l1_restore
0394 
0395     adr r1, l2dis_3630_offset   @ address for offset
0396     ldr r0, [r1]        @ value for offset
0397     ldr r0, [r1, r0]        @ value at l2dis_3630
0398     cmp r0, #0x1    @ should we disable L2 on 3630?
0399     bne skipl2dis
0400     mrc p15, 0, r0, c1, c0, 1
0401     bic r0, r0, #2  @ disable L2 cache
0402     mcr p15, 0, r0, c1, c0, 1
0403 skipl2dis:
0404     ldr r0, control_stat
0405     ldr r1, [r0]
0406     and r1, #0x700
0407     cmp r1, #0x300
0408     beq l2_inv_gp
0409     adr r0, l2_inv_api_params_offset
0410     ldr r3, [r0]
0411     add r3, r3, r0      @ r3 points to dummy parameters
0412     mov r0, #40         @ set service ID for PPA
0413     mov r12, r0         @ copy secure Service ID in r12
0414     mov r1, #0          @ set task id for ROM code in r1
0415     mov r2, #4          @ set some flags in r2, r6
0416     mov r6, #0xff
0417     dsb             @ data write barrier
0418     dmb             @ data memory barrier
0419     smc #1          @ call SMI monitor (smi #1)
0420     /* Write to Aux control register to set some bits */
0421     mov r0, #42         @ set service ID for PPA
0422     mov r12, r0         @ copy secure Service ID in r12
0423     mov r1, #0          @ set task id for ROM code in r1
0424     mov r2, #4          @ set some flags in r2, r6
0425     mov r6, #0xff
0426     ldr r4, scratchpad_base
0427     ldr r3, [r4, #0xBC]     @ r3 points to parameters
0428     dsb             @ data write barrier
0429     dmb             @ data memory barrier
0430     smc #1          @ call SMI monitor (smi #1)
0431 
0432 #ifdef CONFIG_OMAP3_L2_AUX_SECURE_SAVE_RESTORE
0433     /* Restore L2 aux control register */
0434                     @ set service ID for PPA
0435     mov r0, #CONFIG_OMAP3_L2_AUX_SECURE_SERVICE_SET_ID
0436     mov r12, r0         @ copy service ID in r12
0437     mov r1, #0          @ set task ID for ROM code in r1
0438     mov r2, #4          @ set some flags in r2, r6
0439     mov r6, #0xff
0440     ldr r4, scratchpad_base
0441     ldr r3, [r4, #0xBC]
0442     adds    r3, r3, #8      @ r3 points to parameters
0443     dsb             @ data write barrier
0444     dmb             @ data memory barrier
0445     smc #1          @ call SMI monitor (smi #1)
0446 #endif
0447     b   logic_l1_restore
0448 
0449     .align
0450 l2_inv_api_params_offset:
0451     .long   l2_inv_api_params - .
0452 l2_inv_gp:
0453     /* Execute smi to invalidate L2 cache */
0454     mov r12, #0x1           @ set up to invalidate L2
0455     smc #0          @ Call SMI monitor (smieq)
0456     /* Write to Aux control register to set some bits */
0457     ldr r4, scratchpad_base
0458     ldr r3, [r4,#0xBC]
0459     ldr r0, [r3,#4]
0460     mov r12, #0x3
0461     smc #0          @ Call SMI monitor (smieq)
0462     ldr r4, scratchpad_base
0463     ldr r3, [r4,#0xBC]
0464     ldr r0, [r3,#12]
0465     mov r12, #0x2
0466     smc #0          @ Call SMI monitor (smieq)
0467 logic_l1_restore:
0468     adr r0, l2dis_3630_offset   @ adress for offset
0469     ldr r1, [r0]        @ value for offset
0470     ldr r1, [r0, r1]        @ value at l2dis_3630
0471     cmp r1, #0x1        @ Test if L2 re-enable needed on 3630
0472     bne skipl2reen
0473     mrc p15, 0, r1, c1, c0, 1
0474     orr r1, r1, #2      @ re-enable L2 cache
0475     mcr p15, 0, r1, c1, c0, 1
0476 skipl2reen:
0477 
0478     /* Now branch to the common CPU resume function */
0479     b   cpu_resume
0480 ENDPROC(omap3_restore)
0481 
0482     .ltorg
0483 
0484 /*
0485  * Local variables
0486  */
0487 pm_prepwstst_core_p:
0488     .word   PM_PREPWSTST_CORE_P
0489 pm_pwstctrl_mpu:
0490     .word   PM_PWSTCTRL_MPU_P
0491 scratchpad_base:
0492     .word   SCRATCHPAD_BASE_P
0493 sram_base:
0494     .word   SRAM_BASE_P + 0x8000
0495 control_stat:
0496     .word   CONTROL_STAT
0497 control_mem_rta:
0498     .word   CONTROL_MEM_RTA_CTRL
0499 l2dis_3630_offset:
0500     .long   l2dis_3630 - .
0501 
0502     .data
0503     .align  2
0504 l2dis_3630:
0505     .word   0
0506 
0507     .data
0508     .align  2
0509 l2_inv_api_params:
0510     .word   0x1, 0x00
0511 
0512 /*
0513  * Internal functions
0514  */
0515 
0516 /*
0517  * This function implements the erratum ID i443 WA, applies to 34xx >= ES3.0
0518  * Copied to and run from SRAM in order to reconfigure the SDRC parameters.
0519  */
0520     .text
0521     .align  3
0522 ENTRY(es3_sdrc_fix)
0523     ldr r4, sdrc_syscfg     @ get config addr
0524     ldr r5, [r4]        @ get value
0525     tst r5, #0x100      @ is part access blocked
0526     it  eq
0527     biceq   r5, r5, #0x100      @ clear bit if set
0528     str r5, [r4]        @ write back change
0529     ldr r4, sdrc_mr_0       @ get config addr
0530     ldr r5, [r4]        @ get value
0531     str r5, [r4]        @ write back change
0532     ldr r4, sdrc_emr2_0     @ get config addr
0533     ldr r5, [r4]        @ get value
0534     str r5, [r4]        @ write back change
0535     ldr r4, sdrc_manual_0   @ get config addr
0536     mov r5, #0x2        @ autorefresh command
0537     str r5, [r4]        @ kick off refreshes
0538     ldr r4, sdrc_mr_1       @ get config addr
0539     ldr r5, [r4]        @ get value
0540     str r5, [r4]        @ write back change
0541     ldr r4, sdrc_emr2_1     @ get config addr
0542     ldr r5, [r4]        @ get value
0543     str r5, [r4]        @ write back change
0544     ldr r4, sdrc_manual_1   @ get config addr
0545     mov r5, #0x2        @ autorefresh command
0546     str r5, [r4]        @ kick off refreshes
0547     bx  lr
0548 
0549 /*
0550  * Local variables
0551  */
0552     .align
0553 sdrc_syscfg:
0554     .word   SDRC_SYSCONFIG_P
0555 sdrc_mr_0:
0556     .word   SDRC_MR_0_P
0557 sdrc_emr2_0:
0558     .word   SDRC_EMR2_0_P
0559 sdrc_manual_0:
0560     .word   SDRC_MANUAL_0_P
0561 sdrc_mr_1:
0562     .word   SDRC_MR_1_P
0563 sdrc_emr2_1:
0564     .word   SDRC_EMR2_1_P
0565 sdrc_manual_1:
0566     .word   SDRC_MANUAL_1_P
0567 ENDPROC(es3_sdrc_fix)
0568 ENTRY(es3_sdrc_fix_sz)
0569     .word   . - es3_sdrc_fix