1f56348afSSteve Sakoman/* 2f56348afSSteve Sakoman * armboot - Startup Code for OMAP3530/ARM Cortex CPU-core 3f56348afSSteve Sakoman * 4f56348afSSteve Sakoman * Copyright (c) 2004 Texas Instruments <r-woodruff2@ti.com> 5f56348afSSteve Sakoman * 6f56348afSSteve Sakoman * Copyright (c) 2001 Marius Gröger <mag@sysgo.de> 7f56348afSSteve Sakoman * Copyright (c) 2002 Alex Züpke <azu@sysgo.de> 8f56348afSSteve Sakoman * Copyright (c) 2002 Gary Jennejohn <garyj@denx.de> 9f56348afSSteve Sakoman * Copyright (c) 2003 Richard Woodruff <r-woodruff2@ti.com> 10f56348afSSteve Sakoman * Copyright (c) 2003 Kshitij <kshitij@ti.com> 11f56348afSSteve Sakoman * Copyright (c) 2006-2008 Syed Mohammed Khasim <x0khasim@ti.com> 12f56348afSSteve Sakoman * 131a459660SWolfgang Denk * SPDX-License-Identifier: GPL-2.0+ 14f56348afSSteve Sakoman */ 15f56348afSSteve Sakoman 1625ddd1fbSWolfgang Denk#include <asm-offsets.h> 17f56348afSSteve Sakoman#include <config.h> 18a8c68639SAneesh V#include <asm/system.h> 1974236acaSAneesh V#include <linux/linkage.h> 20d31d4a2dSKeerthy#include <asm/armv7.h> 21f56348afSSteve Sakoman 22f56348afSSteve Sakoman/************************************************************************* 23f56348afSSteve Sakoman * 24f56348afSSteve Sakoman * Startup Code (reset vector) 25f56348afSSteve Sakoman * 26003b09daSPavel Machek * Do important init only if we don't start from memory! 27003b09daSPavel Machek * Setup memory and board specific bits prior to relocation. 28003b09daSPavel Machek * Relocate armboot to ram. Setup stack. 29f56348afSSteve Sakoman * 30f56348afSSteve Sakoman *************************************************************************/ 31f56348afSSteve Sakoman 3241623c91SAlbert ARIBAUD .globl reset 33e11c6c27SSimon Glass .globl save_boot_params_ret 34*b04bb64bSPhilipp Tomsich .type save_boot_params_ret,%function 35d31d4a2dSKeerthy#ifdef CONFIG_ARMV7_LPAE 36d31d4a2dSKeerthy .global switch_to_hypervisor_ret 37d31d4a2dSKeerthy#endif 38561142afSHeiko Schocher 39561142afSHeiko Schocherreset: 40e11c6c27SSimon Glass /* Allow the board to save important registers */ 41e11c6c27SSimon Glass b save_boot_params 42e11c6c27SSimon Glasssave_boot_params_ret: 43d31d4a2dSKeerthy#ifdef CONFIG_ARMV7_LPAE 44d31d4a2dSKeerthy/* 45d31d4a2dSKeerthy * check for Hypervisor support 46d31d4a2dSKeerthy */ 47d31d4a2dSKeerthy mrc p15, 0, r0, c0, c1, 1 @ read ID_PFR1 48d31d4a2dSKeerthy and r0, r0, #CPUID_ARM_VIRT_MASK @ mask virtualization bits 49d31d4a2dSKeerthy cmp r0, #(1 << CPUID_ARM_VIRT_SHIFT) 50d31d4a2dSKeerthy beq switch_to_hypervisor 51d31d4a2dSKeerthyswitch_to_hypervisor_ret: 52d31d4a2dSKeerthy#endif 53561142afSHeiko Schocher /* 54c4a4e2e2SAndre Przywara * disable interrupts (FIQ and IRQ), also set the cpu to SVC32 mode, 55c4a4e2e2SAndre Przywara * except if in HYP mode already 56561142afSHeiko Schocher */ 57561142afSHeiko Schocher mrs r0, cpsr 58c4a4e2e2SAndre Przywara and r1, r0, #0x1f @ mask mode bits 59c4a4e2e2SAndre Przywara teq r1, #0x1a @ test for HYP mode 60c4a4e2e2SAndre Przywara bicne r0, r0, #0x1f @ clear all mode bits 61c4a4e2e2SAndre Przywara orrne r0, r0, #0x13 @ set SVC mode 62c4a4e2e2SAndre Przywara orr r0, r0, #0xc0 @ disable FIQ and IRQ 63561142afSHeiko Schocher msr cpsr,r0 64561142afSHeiko Schocher 65a8c68639SAneesh V/* 66a8c68639SAneesh V * Setup vector: 67a8c68639SAneesh V * (OMAP4 spl TEXT_BASE is not 32 byte aligned. 68a8c68639SAneesh V * Continue to use ROM code vector only in OMAP4 spl) 69a8c68639SAneesh V */ 70840fe95cSSiarhei Siamashka#if !(defined(CONFIG_OMAP44XX) && defined(CONFIG_SPL_BUILD)) 710f274f53SPeng Fan /* Set V=0 in CP15 SCTLR register - for VBAR to point to vector */ 720f274f53SPeng Fan mrc p15, 0, r0, c1, c0, 0 @ Read CP15 SCTLR Register 73a8c68639SAneesh V bic r0, #CR_V @ V = 0 740f274f53SPeng Fan mcr p15, 0, r0, c1, c0, 0 @ Write CP15 SCTLR Register 75a8c68639SAneesh V 76a8c68639SAneesh V /* Set vector address in CP15 VBAR register */ 77a8c68639SAneesh V ldr r0, =_start 78a8c68639SAneesh V mcr p15, 0, r0, c12, c0, 0 @Set VBAR 79a8c68639SAneesh V#endif 80a8c68639SAneesh V 81561142afSHeiko Schocher /* the mask ROM code should have PLL and others stable */ 82561142afSHeiko Schocher#ifndef CONFIG_SKIP_LOWLEVEL_INIT 8380433c9aSSimon Glass bl cpu_init_cp15 84b5bd0982SSimon Glass#ifndef CONFIG_SKIP_LOWLEVEL_INIT_ONLY 85561142afSHeiko Schocher bl cpu_init_crit 86561142afSHeiko Schocher#endif 87b5bd0982SSimon Glass#endif 88561142afSHeiko Schocher 89e05e5de7SAlbert ARIBAUD bl _main 90561142afSHeiko Schocher 91561142afSHeiko Schocher/*------------------------------------------------------------------------------*/ 92561142afSHeiko Schocher 93e05e5de7SAlbert ARIBAUDENTRY(c_runtime_cpu_setup) 94c2dd0d45SAneesh V/* 95c2dd0d45SAneesh V * If I-cache is enabled invalidate it 96c2dd0d45SAneesh V */ 97c2dd0d45SAneesh V#ifndef CONFIG_SYS_ICACHE_OFF 98c2dd0d45SAneesh V mcr p15, 0, r0, c7, c5, 0 @ invalidate icache 99c2dd0d45SAneesh V mcr p15, 0, r0, c7, c10, 4 @ DSB 100c2dd0d45SAneesh V mcr p15, 0, r0, c7, c5, 4 @ ISB 101c2dd0d45SAneesh V#endif 102f8b9d1d3STetsuyuki Kobayashi 103e05e5de7SAlbert ARIBAUD bx lr 104561142afSHeiko Schocher 105e05e5de7SAlbert ARIBAUDENDPROC(c_runtime_cpu_setup) 106c3d3a541SHeiko Schocher 107f56348afSSteve Sakoman/************************************************************************* 108f56348afSSteve Sakoman * 1096f0dba85STetsuyuki Kobayashi * void save_boot_params(u32 r0, u32 r1, u32 r2, u32 r3) 1106f0dba85STetsuyuki Kobayashi * __attribute__((weak)); 1116f0dba85STetsuyuki Kobayashi * 1126f0dba85STetsuyuki Kobayashi * Stack pointer is not yet initialized at this moment 1136f0dba85STetsuyuki Kobayashi * Don't save anything to stack even if compiled with -O0 1146f0dba85STetsuyuki Kobayashi * 1156f0dba85STetsuyuki Kobayashi *************************************************************************/ 1166f0dba85STetsuyuki KobayashiENTRY(save_boot_params) 117e11c6c27SSimon Glass b save_boot_params_ret @ back to my caller 1186f0dba85STetsuyuki KobayashiENDPROC(save_boot_params) 1196f0dba85STetsuyuki Kobayashi .weak save_boot_params 1206f0dba85STetsuyuki Kobayashi 121d31d4a2dSKeerthy#ifdef CONFIG_ARMV7_LPAE 122d31d4a2dSKeerthyENTRY(switch_to_hypervisor) 123d31d4a2dSKeerthy b switch_to_hypervisor_ret 124d31d4a2dSKeerthyENDPROC(switch_to_hypervisor) 125d31d4a2dSKeerthy .weak switch_to_hypervisor 126d31d4a2dSKeerthy#endif 127d31d4a2dSKeerthy 1286f0dba85STetsuyuki Kobayashi/************************************************************************* 1296f0dba85STetsuyuki Kobayashi * 13080433c9aSSimon Glass * cpu_init_cp15 131f56348afSSteve Sakoman * 13280433c9aSSimon Glass * Setup CP15 registers (cache, MMU, TLBs). The I-cache is turned on unless 13380433c9aSSimon Glass * CONFIG_SYS_ICACHE_OFF is defined. 134f56348afSSteve Sakoman * 135f56348afSSteve Sakoman *************************************************************************/ 13674236acaSAneesh VENTRY(cpu_init_cp15) 137f56348afSSteve Sakoman /* 138f56348afSSteve Sakoman * Invalidate L1 I/D 139f56348afSSteve Sakoman */ 140f56348afSSteve Sakoman mov r0, #0 @ set up for MCR 141f56348afSSteve Sakoman mcr p15, 0, r0, c8, c7, 0 @ invalidate TLBs 142f56348afSSteve Sakoman mcr p15, 0, r0, c7, c5, 0 @ invalidate icache 143c2dd0d45SAneesh V mcr p15, 0, r0, c7, c5, 6 @ invalidate BP array 144c2dd0d45SAneesh V mcr p15, 0, r0, c7, c10, 4 @ DSB 145c2dd0d45SAneesh V mcr p15, 0, r0, c7, c5, 4 @ ISB 146f56348afSSteve Sakoman 147f56348afSSteve Sakoman /* 148f56348afSSteve Sakoman * disable MMU stuff and caches 149f56348afSSteve Sakoman */ 150f56348afSSteve Sakoman mrc p15, 0, r0, c1, c0, 0 151f56348afSSteve Sakoman bic r0, r0, #0x00002000 @ clear bits 13 (--V-) 152f56348afSSteve Sakoman bic r0, r0, #0x00000007 @ clear bits 2:0 (-CAM) 153f56348afSSteve Sakoman orr r0, r0, #0x00000002 @ set bit 1 (--A-) Align 154c2dd0d45SAneesh V orr r0, r0, #0x00000800 @ set bit 11 (Z---) BTB 155c2dd0d45SAneesh V#ifdef CONFIG_SYS_ICACHE_OFF 156c2dd0d45SAneesh V bic r0, r0, #0x00001000 @ clear bit 12 (I) I-cache 157c2dd0d45SAneesh V#else 158c2dd0d45SAneesh V orr r0, r0, #0x00001000 @ set bit 12 (I) I-cache 159c2dd0d45SAneesh V#endif 160f56348afSSteve Sakoman mcr p15, 0, r0, c1, c0, 0 1610678587fSStephen Warren 162c5d4752cSStephen Warren#ifdef CONFIG_ARM_ERRATA_716044 163c5d4752cSStephen Warren mrc p15, 0, r0, c1, c0, 0 @ read system control register 164c5d4752cSStephen Warren orr r0, r0, #1 << 11 @ set bit #11 165c5d4752cSStephen Warren mcr p15, 0, r0, c1, c0, 0 @ write system control register 166c5d4752cSStephen Warren#endif 167c5d4752cSStephen Warren 168f71cbfe3SNitin Garg#if (defined(CONFIG_ARM_ERRATA_742230) || defined(CONFIG_ARM_ERRATA_794072)) 1690678587fSStephen Warren mrc p15, 0, r0, c15, c0, 1 @ read diagnostic register 1700678587fSStephen Warren orr r0, r0, #1 << 4 @ set bit #4 1710678587fSStephen Warren mcr p15, 0, r0, c15, c0, 1 @ write diagnostic register 1720678587fSStephen Warren#endif 1730678587fSStephen Warren 1740678587fSStephen Warren#ifdef CONFIG_ARM_ERRATA_743622 1750678587fSStephen Warren mrc p15, 0, r0, c15, c0, 1 @ read diagnostic register 1760678587fSStephen Warren orr r0, r0, #1 << 6 @ set bit #6 1770678587fSStephen Warren mcr p15, 0, r0, c15, c0, 1 @ write diagnostic register 1780678587fSStephen Warren#endif 1790678587fSStephen Warren 1800678587fSStephen Warren#ifdef CONFIG_ARM_ERRATA_751472 1810678587fSStephen Warren mrc p15, 0, r0, c15, c0, 1 @ read diagnostic register 1820678587fSStephen Warren orr r0, r0, #1 << 11 @ set bit #11 1830678587fSStephen Warren mcr p15, 0, r0, c15, c0, 1 @ write diagnostic register 1840678587fSStephen Warren#endif 185b7588e3bSNitin Garg#ifdef CONFIG_ARM_ERRATA_761320 186b7588e3bSNitin Garg mrc p15, 0, r0, c15, c0, 1 @ read diagnostic register 187b7588e3bSNitin Garg orr r0, r0, #1 << 21 @ set bit #21 188b7588e3bSNitin Garg mcr p15, 0, r0, c15, c0, 1 @ write diagnostic register 189b7588e3bSNitin Garg#endif 1900678587fSStephen Warren 19111d94319SPeng Fan#ifdef CONFIG_ARM_ERRATA_845369 19211d94319SPeng Fan mrc p15, 0, r0, c15, c0, 1 @ read diagnostic register 19311d94319SPeng Fan orr r0, r0, #1 << 22 @ set bit #22 19411d94319SPeng Fan mcr p15, 0, r0, c15, c0, 1 @ write diagnostic register 19511d94319SPeng Fan#endif 19611d94319SPeng Fan 197c616a0dfSNishanth Menon mov r5, lr @ Store my Caller 198c616a0dfSNishanth Menon mrc p15, 0, r1, c0, c0, 0 @ r1 has Read Main ID Register (MIDR) 199c616a0dfSNishanth Menon mov r3, r1, lsr #20 @ get variant field 200c616a0dfSNishanth Menon and r3, r3, #0xf @ r3 has CPU variant 201c616a0dfSNishanth Menon and r4, r1, #0xf @ r4 has CPU revision 202c616a0dfSNishanth Menon mov r2, r3, lsl #4 @ shift variant field for combined value 203c616a0dfSNishanth Menon orr r2, r4, r2 @ r2 has combined CPU variant + revision 204c616a0dfSNishanth Menon 205c616a0dfSNishanth Menon#ifdef CONFIG_ARM_ERRATA_798870 206c616a0dfSNishanth Menon cmp r2, #0x30 @ Applies to lower than R3p0 207c616a0dfSNishanth Menon bge skip_errata_798870 @ skip if not affected rev 208c616a0dfSNishanth Menon cmp r2, #0x20 @ Applies to including and above R2p0 209c616a0dfSNishanth Menon blt skip_errata_798870 @ skip if not affected rev 210c616a0dfSNishanth Menon 211c616a0dfSNishanth Menon mrc p15, 1, r0, c15, c0, 0 @ read l2 aux ctrl reg 212c616a0dfSNishanth Menon orr r0, r0, #1 << 7 @ Enable hazard-detect timeout 213c616a0dfSNishanth Menon push {r1-r5} @ Save the cpu info registers 214c616a0dfSNishanth Menon bl v7_arch_cp15_set_l2aux_ctrl 215c616a0dfSNishanth Menon isb @ Recommended ISB after l2actlr update 216c616a0dfSNishanth Menon pop {r1-r5} @ Restore the cpu info - fall through 217c616a0dfSNishanth Menonskip_errata_798870: 218c616a0dfSNishanth Menon#endif 219c616a0dfSNishanth Menon 220a615d0beSNishanth Menon#ifdef CONFIG_ARM_ERRATA_801819 221a615d0beSNishanth Menon cmp r2, #0x24 @ Applies to lt including R2p4 222a615d0beSNishanth Menon bgt skip_errata_801819 @ skip if not affected rev 223a615d0beSNishanth Menon cmp r2, #0x20 @ Applies to including and above R2p0 224a615d0beSNishanth Menon blt skip_errata_801819 @ skip if not affected rev 225a615d0beSNishanth Menon mrc p15, 0, r0, c0, c0, 6 @ pick up REVIDR reg 226a615d0beSNishanth Menon and r0, r0, #1 << 3 @ check REVIDR[3] 227a615d0beSNishanth Menon cmp r0, #1 << 3 228a615d0beSNishanth Menon beq skip_errata_801819 @ skip erratum if REVIDR[3] is set 229a615d0beSNishanth Menon 230a615d0beSNishanth Menon mrc p15, 0, r0, c1, c0, 1 @ read auxilary control register 231a615d0beSNishanth Menon orr r0, r0, #3 << 27 @ Disables streaming. All write-allocate 232a615d0beSNishanth Menon @ lines allocate in the L1 or L2 cache. 233a615d0beSNishanth Menon orr r0, r0, #3 << 25 @ Disables streaming. All write-allocate 234a615d0beSNishanth Menon @ lines allocate in the L1 cache. 235a615d0beSNishanth Menon push {r1-r5} @ Save the cpu info registers 236a615d0beSNishanth Menon bl v7_arch_cp15_set_acr 237a615d0beSNishanth Menon pop {r1-r5} @ Restore the cpu info - fall through 238a615d0beSNishanth Menonskip_errata_801819: 239a615d0beSNishanth Menon#endif 240a615d0beSNishanth Menon 241b45c48a7SNishanth Menon#ifdef CONFIG_ARM_ERRATA_454179 242b45c48a7SNishanth Menon cmp r2, #0x21 @ Only on < r2p1 243b45c48a7SNishanth Menon bge skip_errata_454179 244b45c48a7SNishanth Menon 245b45c48a7SNishanth Menon mrc p15, 0, r0, c1, c0, 1 @ Read ACR 246b45c48a7SNishanth Menon orr r0, r0, #(0x3 << 6) @ Set DBSM(BIT7) and IBE(BIT6) bits 247b45c48a7SNishanth Menon push {r1-r5} @ Save the cpu info registers 248b45c48a7SNishanth Menon bl v7_arch_cp15_set_acr 249b45c48a7SNishanth Menon pop {r1-r5} @ Restore the cpu info - fall through 250b45c48a7SNishanth Menon 251b45c48a7SNishanth Menonskip_errata_454179: 252b45c48a7SNishanth Menon#endif 253b45c48a7SNishanth Menon 2545902f4ceSNishanth Menon#ifdef CONFIG_ARM_ERRATA_430973 2555902f4ceSNishanth Menon cmp r2, #0x21 @ Only on < r2p1 2565902f4ceSNishanth Menon bge skip_errata_430973 2575902f4ceSNishanth Menon 2585902f4ceSNishanth Menon mrc p15, 0, r0, c1, c0, 1 @ Read ACR 2595902f4ceSNishanth Menon orr r0, r0, #(0x1 << 6) @ Set IBE bit 2605902f4ceSNishanth Menon push {r1-r5} @ Save the cpu info registers 2615902f4ceSNishanth Menon bl v7_arch_cp15_set_acr 2625902f4ceSNishanth Menon pop {r1-r5} @ Restore the cpu info - fall through 2635902f4ceSNishanth Menon 2645902f4ceSNishanth Menonskip_errata_430973: 2655902f4ceSNishanth Menon#endif 2665902f4ceSNishanth Menon 2679b4d65f9SNishanth Menon#ifdef CONFIG_ARM_ERRATA_621766 2689b4d65f9SNishanth Menon cmp r2, #0x21 @ Only on < r2p1 2699b4d65f9SNishanth Menon bge skip_errata_621766 2709b4d65f9SNishanth Menon 2719b4d65f9SNishanth Menon mrc p15, 0, r0, c1, c0, 1 @ Read ACR 2729b4d65f9SNishanth Menon orr r0, r0, #(0x1 << 5) @ Set L1NEON bit 2739b4d65f9SNishanth Menon push {r1-r5} @ Save the cpu info registers 2749b4d65f9SNishanth Menon bl v7_arch_cp15_set_acr 2759b4d65f9SNishanth Menon pop {r1-r5} @ Restore the cpu info - fall through 2769b4d65f9SNishanth Menon 2779b4d65f9SNishanth Menonskip_errata_621766: 2789b4d65f9SNishanth Menon#endif 2799b4d65f9SNishanth Menon 28019a75b8cSSiarhei Siamashka#ifdef CONFIG_ARM_ERRATA_725233 28119a75b8cSSiarhei Siamashka cmp r2, #0x21 @ Only on < r2p1 (Cortex A8) 28219a75b8cSSiarhei Siamashka bge skip_errata_725233 28319a75b8cSSiarhei Siamashka 28419a75b8cSSiarhei Siamashka mrc p15, 1, r0, c9, c0, 2 @ Read L2ACR 28519a75b8cSSiarhei Siamashka orr r0, r0, #(0x1 << 27) @ L2 PLD data forwarding disable 28619a75b8cSSiarhei Siamashka push {r1-r5} @ Save the cpu info registers 28719a75b8cSSiarhei Siamashka bl v7_arch_cp15_set_l2aux_ctrl 28819a75b8cSSiarhei Siamashka pop {r1-r5} @ Restore the cpu info - fall through 28919a75b8cSSiarhei Siamashka 29019a75b8cSSiarhei Siamashkaskip_errata_725233: 29119a75b8cSSiarhei Siamashka#endif 29219a75b8cSSiarhei Siamashka 2938776350dSNisal Menuka#ifdef CONFIG_ARM_ERRATA_852421 2948776350dSNisal Menuka mrc p15, 0, r0, c15, c0, 1 @ read diagnostic register 2958776350dSNisal Menuka orr r0, r0, #1 << 24 @ set bit #24 2968776350dSNisal Menuka mcr p15, 0, r0, c15, c0, 1 @ write diagnostic register 2978776350dSNisal Menuka#endif 2988776350dSNisal Menuka 2998776350dSNisal Menuka#ifdef CONFIG_ARM_ERRATA_852423 3008776350dSNisal Menuka mrc p15, 0, r0, c15, c0, 1 @ read diagnostic register 3018776350dSNisal Menuka orr r0, r0, #1 << 12 @ set bit #12 3028776350dSNisal Menuka mcr p15, 0, r0, c15, c0, 1 @ write diagnostic register 3038776350dSNisal Menuka#endif 3048776350dSNisal Menuka 305c616a0dfSNishanth Menon mov pc, r5 @ back to my caller 30674236acaSAneesh VENDPROC(cpu_init_cp15) 30780433c9aSSimon Glass 308b5bd0982SSimon Glass#if !defined(CONFIG_SKIP_LOWLEVEL_INIT) && \ 309b5bd0982SSimon Glass !defined(CONFIG_SKIP_LOWLEVEL_INIT_ONLY) 31080433c9aSSimon Glass/************************************************************************* 31180433c9aSSimon Glass * 31280433c9aSSimon Glass * CPU_init_critical registers 31380433c9aSSimon Glass * 31480433c9aSSimon Glass * setup important registers 31580433c9aSSimon Glass * setup memory timing 31680433c9aSSimon Glass * 31780433c9aSSimon Glass *************************************************************************/ 31874236acaSAneesh VENTRY(cpu_init_crit) 319f56348afSSteve Sakoman /* 320f56348afSSteve Sakoman * Jump to board specific initialization... 321f56348afSSteve Sakoman * The Mask ROM will have already initialized 322f56348afSSteve Sakoman * basic memory. Go here to bump up clock rate and handle 323f56348afSSteve Sakoman * wake up conditions. 324f56348afSSteve Sakoman */ 32563ee53a7SBenoît Thébaudeau b lowlevel_init @ go setup pll,mux,memory 32674236acaSAneesh VENDPROC(cpu_init_crit) 32722193540SRob Herring#endif 328