blob: f06d27717de0daaf92b4a3cb1b5da9126e8cfdd4 [file] [log] [blame]
Tom Rini10e47792018-05-06 17:58:06 -04001// SPDX-License-Identifier: GPL-2.0+
Andreas Färber9e3ad682017-05-15 17:51:18 +08002/*
3 * Copyright (c) 2016 Rockchip Electronics Co., Ltd
4 * Copyright (c) 2016 Andreas Färber
Andreas Färber9e3ad682017-05-15 17:51:18 +08005 */
6
7#include <common.h>
8#include <asm/armv8/mmu.h>
9#include <asm/io.h>
Kever Yang9fbe17c2019-03-28 11:01:23 +080010#include <asm/arch-rockchip/clock.h>
11#include <asm/arch-rockchip/cru_rk3368.h>
12#include <asm/arch-rockchip/grf_rk3368.h>
Andreas Färber9e3ad682017-05-15 17:51:18 +080013#include <syscon.h>
14
Kever Yangc2053262017-06-23 16:11:11 +080015DECLARE_GLOBAL_DATA_PTR;
16
Andreas Färber9e3ad682017-05-15 17:51:18 +080017#define IMEM_BASE 0xFF8C0000
18
19/* Max MCU's SRAM value is 8K, begin at (IMEM_BASE + 4K) */
20#define MCU_SRAM_BASE (IMEM_BASE + 1024 * 4)
21#define MCU_SRAM_BASE_BIT31_BIT28 ((MCU_SRAM_BASE & GENMASK(31, 28)) >> 28)
22#define MCU_SRAM_BASE_BIT27_BIT12 ((MCU_SRAM_BASE & GENMASK(27, 12)) >> 12)
23/* exsram may using by mcu to accessing dram(0x0-0x20000000) */
24#define MCU_EXSRAM_BASE (0)
25#define MCU_EXSRAM_BASE_BIT31_BIT28 ((MCU_EXSRAM_BASE & GENMASK(31, 28)) >> 28)
26#define MCU_EXSRAM_BASE_BIT27_BIT12 ((MCU_EXSRAM_BASE & GENMASK(27, 12)) >> 12)
27/* experi no used, reserved value = 0 */
28#define MCU_EXPERI_BASE (0)
29#define MCU_EXPERI_BASE_BIT31_BIT28 ((MCU_EXPERI_BASE & GENMASK(31, 28)) >> 28)
30#define MCU_EXPERI_BASE_BIT27_BIT12 ((MCU_EXPERI_BASE & GENMASK(27, 12)) >> 12)
31
32static struct mm_region rk3368_mem_map[] = {
33 {
34 .virt = 0x0UL,
35 .phys = 0x0UL,
36 .size = 0x80000000UL,
37 .attrs = PTE_BLOCK_MEMTYPE(MT_NORMAL) |
38 PTE_BLOCK_INNER_SHARE
39 }, {
40 .virt = 0xf0000000UL,
41 .phys = 0xf0000000UL,
42 .size = 0x10000000UL,
43 .attrs = PTE_BLOCK_MEMTYPE(MT_DEVICE_NGNRNE) |
44 PTE_BLOCK_NON_SHARE |
45 PTE_BLOCK_PXN | PTE_BLOCK_UXN
46 }, {
47 /* List terminator */
48 0,
49 }
50};
51
52struct mm_region *mem_map = rk3368_mem_map;
53
Kever Yangc2053262017-06-23 16:11:11 +080054int dram_init_banksize(void)
55{
56 size_t max_size = min((unsigned long)gd->ram_size, gd->ram_top);
57
58 /* Reserve 0x200000 for ATF bl31 */
59 gd->bd->bi_dram[0].start = 0x200000;
60 gd->bd->bi_dram[0].size = max_size - gd->bd->bi_dram[0].start;
61
62 return 0;
63}
64
Andreas Färber9e3ad682017-05-15 17:51:18 +080065#ifdef CONFIG_ARCH_EARLY_INIT_R
66static int mcu_init(void)
67{
68 struct rk3368_grf *grf = syscon_get_first_range(ROCKCHIP_SYSCON_GRF);
69 struct rk3368_cru *cru = rockchip_get_cru();
70
71 rk_clrsetreg(&grf->soc_con14, MCU_SRAM_BASE_BIT31_BIT28_MASK,
72 MCU_SRAM_BASE_BIT31_BIT28 << MCU_SRAM_BASE_BIT31_BIT28_SHIFT);
73 rk_clrsetreg(&grf->soc_con11, MCU_SRAM_BASE_BIT27_BIT12_MASK,
74 MCU_SRAM_BASE_BIT27_BIT12 << MCU_SRAM_BASE_BIT27_BIT12_SHIFT);
75 rk_clrsetreg(&grf->soc_con14, MCU_EXSRAM_BASE_BIT31_BIT28_MASK,
76 MCU_EXSRAM_BASE_BIT31_BIT28 << MCU_EXSRAM_BASE_BIT31_BIT28_SHIFT);
77 rk_clrsetreg(&grf->soc_con12, MCU_EXSRAM_BASE_BIT27_BIT12_MASK,
78 MCU_EXSRAM_BASE_BIT27_BIT12 << MCU_EXSRAM_BASE_BIT27_BIT12_SHIFT);
79 rk_clrsetreg(&grf->soc_con14, MCU_EXPERI_BASE_BIT31_BIT28_MASK,
80 MCU_EXPERI_BASE_BIT31_BIT28 << MCU_EXPERI_BASE_BIT31_BIT28_SHIFT);
81 rk_clrsetreg(&grf->soc_con13, MCU_EXPERI_BASE_BIT27_BIT12_MASK,
82 MCU_EXPERI_BASE_BIT27_BIT12 << MCU_EXPERI_BASE_BIT27_BIT12_SHIFT);
83
84 rk_clrsetreg(&cru->clksel_con[12], MCU_PLL_SEL_MASK | MCU_CLK_DIV_MASK,
85 (MCU_PLL_SEL_GPLL << MCU_PLL_SEL_SHIFT) |
86 (5 << MCU_CLK_DIV_SHIFT));
87
88 /* mcu dereset, for start running */
89 rk_clrreg(&cru->softrst_con[1], MCU_PO_SRST_MASK | MCU_SYS_SRST_MASK);
90
91 return 0;
92}
93
94int arch_early_init_r(void)
95{
96 return mcu_init();
97}
98#endif
Kever Yang93417782019-03-29 09:09:05 +080099
100#ifdef CONFIG_DEBUG_UART_BOARD_INIT
101void board_debug_uart_init(void)
102{
103 /*
104 * N.B.: This is called before the device-model has been
105 * initialised. For this reason, we can not access
106 * the GRF address range using the syscon API.
107 */
108#if defined(CONFIG_DEBUG_UART_BASE) && (CONFIG_DEBUG_UART_BASE == 0xff180000)
109 struct rk3368_grf * const grf =
110 (struct rk3368_grf * const)0xff770000;
111
112 enum {
113 GPIO2D1_MASK = GENMASK(3, 2),
114 GPIO2D1_GPIO = 0,
115 GPIO2D1_UART0_SOUT = (1 << 2),
116
117 GPIO2D0_MASK = GENMASK(1, 0),
118 GPIO2D0_GPIO = 0,
119 GPIO2D0_UART0_SIN = (1 << 0),
120 };
121
122 /* Enable early UART0 on the RK3368 */
123 rk_clrsetreg(&grf->gpio2d_iomux,
124 GPIO2D0_MASK, GPIO2D0_UART0_SIN);
125 rk_clrsetreg(&grf->gpio2d_iomux,
126 GPIO2D1_MASK, GPIO2D1_UART0_SOUT);
Kever Yang5d68a222019-03-29 22:48:24 +0800127#elif defined(CONFIG_DEBUG_UART_BASE) && (CONFIG_DEBUG_UART_BASE == 0xff1c0000)
128 struct rk3368_pmu_grf * const pmugrf __maybe_unused =
129 (struct rk3368_pmu_grf * const)0xff738000;
130
131 enum {
132 /* UART4 */
133 GPIO0D2_MASK = GENMASK(5, 4),
134 GPIO0D2_GPIO = 0,
135 GPIO0D2_UART4_SOUT = (3 << 4),
136
137 GPIO0D3_MASK = GENMASK(7, 6),
138 GPIO0D3_GPIO = 0,
139 GPIO0D3_UART4_SIN = (3 << 6),
140 };
141
142 /* Enable early UART4 on the PX5 */
143 rk_clrsetreg(&pmugrf->gpio0d_iomux,
144 GPIO0D2_MASK | GPIO0D3_MASK,
145 GPIO0D2_UART4_SOUT | GPIO0D3_UART4_SIN);
146#elif defined(CONFIG_DEBUG_UART_BASE) && (CONFIG_DEBUG_UART_BASE == 0xff690000)
147 struct rk3368_grf * const grf =
148 (struct rk3368_grf * const)0xff770000;
149
150 enum {
151 GPIO2A6_SHIFT = 12,
152 GPIO2A6_MASK = GENMASK(13, 12),
153 GPIO2A6_GPIO = 0,
154 GPIO2A6_UART2_SIN = (2 << GPIO2A6_SHIFT),
155
156 GPIO2A5_SHIFT = 10,
157 GPIO2A5_MASK = GENMASK(11, 10),
158 GPIO2A5_GPIO = 0,
159 GPIO2A5_UART2_SOUT = (2 << GPIO2A5_SHIFT),
160 };
161
162 /* Enable early UART2 on the RK3368 */
163 rk_clrsetreg(&grf->gpio2a_iomux,
164 GPIO2A6_MASK, GPIO2A6_UART2_SIN);
165 rk_clrsetreg(&grf->gpio2a_iomux,
166 GPIO2A5_MASK, GPIO2A5_UART2_SOUT);
Kever Yang93417782019-03-29 09:09:05 +0800167#endif
168}
169#endif