Masahiro Yamada | bb2ff9d | 2014-10-03 19:21:06 +0900 | [diff] [blame] | 1 | /* |
Masahiro Yamada | 2c75201 | 2015-05-29 17:30:03 +0900 | [diff] [blame] | 2 | * Copyright (C) 2012-2015 Masahiro Yamada <yamada.masahiro@socionext.com> |
Masahiro Yamada | bb2ff9d | 2014-10-03 19:21:06 +0900 | [diff] [blame] | 3 | * |
| 4 | * SPDX-License-Identifier: GPL-2.0+ |
| 5 | */ |
| 6 | |
| 7 | #include <config.h> |
| 8 | #include <linux/linkage.h> |
Masahiro Yamada | 951ed55 | 2015-02-27 02:27:06 +0900 | [diff] [blame] | 9 | #include <linux/sizes.h> |
Masahiro Yamada | bb2ff9d | 2014-10-03 19:21:06 +0900 | [diff] [blame] | 10 | #include <asm/system.h> |
Masahiro Yamada | 95387e2 | 2015-02-27 02:26:44 +0900 | [diff] [blame] | 11 | #include <mach/arm-mpcore.h> |
| 12 | #include <mach/sbc-regs.h> |
Masahiro Yamada | 951ed55 | 2015-02-27 02:27:06 +0900 | [diff] [blame] | 13 | #include <mach/ssc-regs.h> |
Masahiro Yamada | bb2ff9d | 2014-10-03 19:21:06 +0900 | [diff] [blame] | 14 | |
| 15 | ENTRY(lowlevel_init) |
| 16 | mov r8, lr @ persevere link reg across call |
| 17 | |
| 18 | /* |
| 19 | * The UniPhier Boot ROM loads SPL code to the L2 cache. |
| 20 | * But CPUs can only do instruction fetch now because start.S has |
| 21 | * cleared C and M bits. |
| 22 | * First we need to turn on MMU and Dcache again to get back |
| 23 | * data access to L2. |
| 24 | */ |
Masahiro Yamada | 5d3d996 | 2015-03-23 00:07:30 +0900 | [diff] [blame] | 25 | mrc p15, 0, r0, c1, c0, 0 @ SCTLR (System Control Register) |
| 26 | orr r0, r0, #(CR_C | CR_M) @ enable MMU and Dcache |
Masahiro Yamada | bb2ff9d | 2014-10-03 19:21:06 +0900 | [diff] [blame] | 27 | mcr p15, 0, r0, c1, c0, 0 |
| 28 | |
Masahiro Yamada | 978bc65 | 2015-01-06 14:28:16 +0900 | [diff] [blame] | 29 | #ifdef CONFIG_DEBUG_LL |
Masahiro Yamada | c743249 | 2015-09-22 00:27:37 +0900 | [diff] [blame] | 30 | bl debug_ll_init |
Masahiro Yamada | 978bc65 | 2015-01-06 14:28:16 +0900 | [diff] [blame] | 31 | #endif |
| 32 | |
Masahiro Yamada | bb2ff9d | 2014-10-03 19:21:06 +0900 | [diff] [blame] | 33 | /* |
| 34 | * Now we are using the page table embedded in the Boot ROM. |
| 35 | * It is not handy since it is not a straight mapped table for sLD3. |
| 36 | * What we need to do next is to switch over to the page table in SPL. |
| 37 | */ |
| 38 | ldr r3, =init_page_table @ page table must be 16KB aligned |
| 39 | |
| 40 | /* Disable MMU and Dcache before switching Page Table */ |
Masahiro Yamada | 5d3d996 | 2015-03-23 00:07:30 +0900 | [diff] [blame] | 41 | mrc p15, 0, r0, c1, c0, 0 @ SCTLR (System Control Register) |
Masahiro Yamada | bb2ff9d | 2014-10-03 19:21:06 +0900 | [diff] [blame] | 42 | bic r0, r0, #(CR_C | CR_M) @ disable MMU and Dcache |
| 43 | mcr p15, 0, r0, c1, c0, 0 |
| 44 | |
| 45 | bl enable_mmu |
| 46 | |
Masahiro Yamada | bb2ff9d | 2014-10-03 19:21:06 +0900 | [diff] [blame] | 47 | bl setup_init_ram @ RAM area for temporary stack pointer |
| 48 | |
| 49 | mov lr, r8 @ restore link |
| 50 | mov pc, lr @ back to my caller |
| 51 | ENDPROC(lowlevel_init) |
| 52 | |
| 53 | ENTRY(enable_mmu) |
| 54 | mrc p15, 0, r0, c2, c0, 2 @ TTBCR (Translation Table Base Control Register) |
| 55 | bic r0, r0, #0x37 |
| 56 | orr r0, r0, #0x20 @ disable TTBR1 |
| 57 | mcr p15, 0, r0, c2, c0, 2 |
| 58 | |
| 59 | orr r0, r3, #0x8 @ Outer Cacheability for table walks: WBWA |
| 60 | mcr p15, 0, r0, c2, c0, 0 @ TTBR0 |
| 61 | |
| 62 | mov r0, #0 |
| 63 | mcr p15, 0, r0, c8, c7, 0 @ invalidate TLBs |
| 64 | |
| 65 | mov r0, #-1 @ manager for all domains (No permission check) |
| 66 | mcr p15, 0, r0, c3, c0, 0 @ DACR (Domain Access Control Register) |
| 67 | |
| 68 | dsb |
| 69 | isb |
| 70 | /* |
| 71 | * MMU on: |
| 72 | * TLBs was already invalidated in "../start.S" |
| 73 | * So, we don't need to invalidate it here. |
| 74 | */ |
Masahiro Yamada | 5d3d996 | 2015-03-23 00:07:30 +0900 | [diff] [blame] | 75 | mrc p15, 0, r0, c1, c0, 0 @ SCTLR (System Control Register) |
Masahiro Yamada | bb2ff9d | 2014-10-03 19:21:06 +0900 | [diff] [blame] | 76 | orr r0, r0, #(CR_C | CR_M) @ MMU and Dcache enable |
| 77 | mcr p15, 0, r0, c1, c0, 0 |
| 78 | |
| 79 | mov pc, lr |
| 80 | ENDPROC(enable_mmu) |
| 81 | |
Masahiro Yamada | 951ed55 | 2015-02-27 02:27:06 +0900 | [diff] [blame] | 82 | /* |
| 83 | * For PH1-Pro4 or older SoCs, the size of WAY is 32KB. |
| 84 | * It is large enough for tmp RAM. |
| 85 | */ |
| 86 | #define BOOT_RAM_SIZE (SZ_32K) |
Masahiro Yamada | bb2ff9d | 2014-10-03 19:21:06 +0900 | [diff] [blame] | 87 | #define BOOT_WAY_BITS (0x00000100) /* way 8 */ |
| 88 | |
| 89 | ENTRY(setup_init_ram) |
| 90 | /* |
| 91 | * Touch to zero for the boot way |
| 92 | */ |
| 93 | 0: |
| 94 | /* |
| 95 | * set SSCOQM, SSCOQAD, SSCOQSZ, SSCOQWN in this order |
| 96 | */ |
| 97 | ldr r0, = 0x00408006 @ touch to zero with address range |
| 98 | ldr r1, = SSCOQM |
| 99 | str r0, [r1] |
Masahiro Yamada | 5b01ec4 | 2015-03-23 00:07:26 +0900 | [diff] [blame] | 100 | ldr r0, = (CONFIG_SPL_STACK - BOOT_RAM_SIZE) @ base address |
Masahiro Yamada | bb2ff9d | 2014-10-03 19:21:06 +0900 | [diff] [blame] | 101 | ldr r1, = SSCOQAD |
| 102 | str r0, [r1] |
| 103 | ldr r0, = BOOT_RAM_SIZE |
| 104 | ldr r1, = SSCOQSZ |
| 105 | str r0, [r1] |
| 106 | ldr r0, = BOOT_WAY_BITS |
| 107 | ldr r1, = SSCOQWN |
| 108 | str r0, [r1] |
| 109 | ldr r1, = SSCOPPQSEF |
| 110 | ldr r0, [r1] |
| 111 | cmp r0, #0 @ check if the command is successfully set |
Masahiro Yamada | 5d3d996 | 2015-03-23 00:07:30 +0900 | [diff] [blame] | 112 | bne 0b @ try again if an error occurs |
Masahiro Yamada | bb2ff9d | 2014-10-03 19:21:06 +0900 | [diff] [blame] | 113 | |
| 114 | ldr r1, = SSCOLPQS |
| 115 | 1: |
| 116 | ldr r0, [r1] |
| 117 | cmp r0, #0x4 |
| 118 | bne 1b @ wait until the operation is completed |
| 119 | str r0, [r1] @ clear the complete notification flag |
| 120 | |
| 121 | mov pc, lr |
| 122 | ENDPROC(setup_init_ram) |