blob: 8e32b357235ce2ec215aec7e0ea623b5d02f6c88 [file] [log] [blame]
Masahiro Yamadabb2ff9d2014-10-03 19:21:06 +09001/*
Masahiro Yamadaa7c901f2016-07-22 13:38:31 +09002 * Copyright (C) 2012-2015 Panasonic Corporation
3 * Copyright (C) 2015-2016 Socionext Inc.
4 * Author: Masahiro Yamada <yamada.masahiro@socionext.com>
Masahiro Yamadabb2ff9d2014-10-03 19:21:06 +09005 *
6 * SPDX-License-Identifier: GPL-2.0+
7 */
8
9#include <config.h>
10#include <linux/linkage.h>
Masahiro Yamada951ed552015-02-27 02:27:06 +090011#include <linux/sizes.h>
Masahiro Yamadabb2ff9d2014-10-03 19:21:06 +090012#include <asm/system.h>
Masahiro Yamadaefdf3402016-01-09 01:51:13 +090013
14#include "ssc-regs.h"
Masahiro Yamadabb2ff9d2014-10-03 19:21:06 +090015
16ENTRY(lowlevel_init)
17 mov r8, lr @ persevere link reg across call
18
19 /*
20 * The UniPhier Boot ROM loads SPL code to the L2 cache.
21 * But CPUs can only do instruction fetch now because start.S has
22 * cleared C and M bits.
23 * First we need to turn on MMU and Dcache again to get back
24 * data access to L2.
25 */
Masahiro Yamada5d3d9962015-03-23 00:07:30 +090026 mrc p15, 0, r0, c1, c0, 0 @ SCTLR (System Control Register)
27 orr r0, r0, #(CR_C | CR_M) @ enable MMU and Dcache
Masahiro Yamadabb2ff9d2014-10-03 19:21:06 +090028 mcr p15, 0, r0, c1, c0, 0
29
Masahiro Yamada978bc652015-01-06 14:28:16 +090030#ifdef CONFIG_DEBUG_LL
Masahiro Yamadac7432492015-09-22 00:27:37 +090031 bl debug_ll_init
Masahiro Yamada978bc652015-01-06 14:28:16 +090032#endif
33
Masahiro Yamada3a1e4422016-06-24 11:51:38 +090034 bl setup_init_ram @ RAM area for stack and page table
Masahiro Yamada1c1646a2016-02-02 21:11:29 +090035
Masahiro Yamadabb2ff9d2014-10-03 19:21:06 +090036 /*
37 * Now we are using the page table embedded in the Boot ROM.
38 * It is not handy since it is not a straight mapped table for sLD3.
Masahiro Yamada1c1646a2016-02-02 21:11:29 +090039 * Also, the access to the external bus is prohibited. What we need
40 * to do next is to create a page table and switch over to it.
Masahiro Yamadabb2ff9d2014-10-03 19:21:06 +090041 */
Masahiro Yamada1c1646a2016-02-02 21:11:29 +090042 bl create_page_table
Hans de Goede076e8412016-04-09 13:53:48 +020043 bl __v7_flush_dcache_all
Masahiro Yamadabb2ff9d2014-10-03 19:21:06 +090044
45 /* Disable MMU and Dcache before switching Page Table */
Masahiro Yamada5d3d9962015-03-23 00:07:30 +090046 mrc p15, 0, r0, c1, c0, 0 @ SCTLR (System Control Register)
Masahiro Yamadabb2ff9d2014-10-03 19:21:06 +090047 bic r0, r0, #(CR_C | CR_M) @ disable MMU and Dcache
48 mcr p15, 0, r0, c1, c0, 0
49
50 bl enable_mmu
51
Masahiro Yamadabb2ff9d2014-10-03 19:21:06 +090052 mov lr, r8 @ restore link
53 mov pc, lr @ back to my caller
54ENDPROC(lowlevel_init)
55
56ENTRY(enable_mmu)
57 mrc p15, 0, r0, c2, c0, 2 @ TTBCR (Translation Table Base Control Register)
58 bic r0, r0, #0x37
59 orr r0, r0, #0x20 @ disable TTBR1
60 mcr p15, 0, r0, c2, c0, 2
61
Masahiro Yamada1c1646a2016-02-02 21:11:29 +090062 orr r0, r12, #0x8 @ Outer Cacheability for table walks: WBWA
Masahiro Yamadabb2ff9d2014-10-03 19:21:06 +090063 mcr p15, 0, r0, c2, c0, 0 @ TTBR0
64
65 mov r0, #0
66 mcr p15, 0, r0, c8, c7, 0 @ invalidate TLBs
67
68 mov r0, #-1 @ manager for all domains (No permission check)
69 mcr p15, 0, r0, c3, c0, 0 @ DACR (Domain Access Control Register)
70
71 dsb
72 isb
73 /*
74 * MMU on:
75 * TLBs was already invalidated in "../start.S"
76 * So, we don't need to invalidate it here.
77 */
Masahiro Yamada5d3d9962015-03-23 00:07:30 +090078 mrc p15, 0, r0, c1, c0, 0 @ SCTLR (System Control Register)
Masahiro Yamadabb2ff9d2014-10-03 19:21:06 +090079 orr r0, r0, #(CR_C | CR_M) @ MMU and Dcache enable
80 mcr p15, 0, r0, c1, c0, 0
81
82 mov pc, lr
83ENDPROC(enable_mmu)
84
Masahiro Yamada951ed552015-02-27 02:27:06 +090085/*
86 * For PH1-Pro4 or older SoCs, the size of WAY is 32KB.
87 * It is large enough for tmp RAM.
88 */
Masahiro Yamada1c1646a2016-02-02 21:11:29 +090089#define BOOT_RAM_SIZE (SZ_32K)
90#define BOOT_RAM_BASE ((CONFIG_SPL_STACK) - (BOOT_RAM_SIZE))
91#define BOOT_WAY_BITS (0x00000100) /* way 8 */
Masahiro Yamadabb2ff9d2014-10-03 19:21:06 +090092
93ENTRY(setup_init_ram)
94 /*
95 * Touch to zero for the boot way
96 */
970:
98 /*
Masahiro Yamadaa7c901f2016-07-22 13:38:31 +090099 * set UNIPHIER_SSCOQM, UNIPHIER_SSCOQAD, UNIPHIER_SSCOQSZ, UNIPHIER_SSCOQWN in this order
Masahiro Yamadabb2ff9d2014-10-03 19:21:06 +0900100 */
101 ldr r0, = 0x00408006 @ touch to zero with address range
Masahiro Yamadaa7c901f2016-07-22 13:38:31 +0900102 ldr r1, = UNIPHIER_SSCOQM
Masahiro Yamadabb2ff9d2014-10-03 19:21:06 +0900103 str r0, [r1]
Masahiro Yamada1c1646a2016-02-02 21:11:29 +0900104 ldr r0, = BOOT_RAM_BASE
Masahiro Yamadaa7c901f2016-07-22 13:38:31 +0900105 ldr r1, = UNIPHIER_SSCOQAD
Masahiro Yamadabb2ff9d2014-10-03 19:21:06 +0900106 str r0, [r1]
107 ldr r0, = BOOT_RAM_SIZE
Masahiro Yamadaa7c901f2016-07-22 13:38:31 +0900108 ldr r1, = UNIPHIER_SSCOQSZ
Masahiro Yamadabb2ff9d2014-10-03 19:21:06 +0900109 str r0, [r1]
110 ldr r0, = BOOT_WAY_BITS
Masahiro Yamadaa7c901f2016-07-22 13:38:31 +0900111 ldr r1, = UNIPHIER_SSCOQWN
Masahiro Yamadabb2ff9d2014-10-03 19:21:06 +0900112 str r0, [r1]
Masahiro Yamadaa7c901f2016-07-22 13:38:31 +0900113 ldr r1, = UNIPHIER_SSCOPPQSEF
Masahiro Yamadabb2ff9d2014-10-03 19:21:06 +0900114 ldr r0, [r1]
115 cmp r0, #0 @ check if the command is successfully set
Masahiro Yamada5d3d9962015-03-23 00:07:30 +0900116 bne 0b @ try again if an error occurs
Masahiro Yamadabb2ff9d2014-10-03 19:21:06 +0900117
Masahiro Yamadaa7c901f2016-07-22 13:38:31 +0900118 ldr r1, = UNIPHIER_SSCOLPQS
Masahiro Yamadabb2ff9d2014-10-03 19:21:06 +09001191:
120 ldr r0, [r1]
121 cmp r0, #0x4
122 bne 1b @ wait until the operation is completed
123 str r0, [r1] @ clear the complete notification flag
124
125 mov pc, lr
126ENDPROC(setup_init_ram)
Masahiro Yamada1c1646a2016-02-02 21:11:29 +0900127
128#define DEVICE 0x00002002 /* Non-shareable Device */
129#define NORMAL 0x0000000e /* Normal Memory Write-Back, No Write-Allocate */
130
131ENTRY(create_page_table)
132 ldr r0, = DEVICE
133 ldr r1, = BOOT_RAM_BASE
134 mov r12, r1 @ r12 is preserved during D-cache flush
1350: str r0, [r1], #4 @ specify all the sections as Device
136 adds r0, r0, #0x00100000
137 bcc 0b
138
139 ldr r0, = NORMAL
140 str r0, [r12] @ mark the first section as Normal
141 add r0, r0, #0x00100000
142 str r0, [r12, #4] @ mark the second section as Normal
143 mov pc, lr
144ENDPROC(create_page_table)