1 // SPDX-License-Identifier: GPL-2.0+
3 * Copyright (c) 2016 Rockchip Electronics Co., Ltd
4 * Copyright (c) 2016 Andreas Färber
8 #include <asm/armv8/mmu.h>
10 #include <asm/arch-rockchip/clock.h>
11 #include <asm/arch-rockchip/cru_rk3368.h>
12 #include <asm/arch-rockchip/grf_rk3368.h>
15 DECLARE_GLOBAL_DATA_PTR;
17 #define IMEM_BASE 0xFF8C0000
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)
32 static struct mm_region rk3368_mem_map[] = {
37 .attrs = PTE_BLOCK_MEMTYPE(MT_NORMAL) |
43 .attrs = PTE_BLOCK_MEMTYPE(MT_DEVICE_NGNRNE) |
45 PTE_BLOCK_PXN | PTE_BLOCK_UXN
52 struct mm_region *mem_map = rk3368_mem_map;
54 int dram_init_banksize(void)
56 size_t max_size = min((unsigned long)gd->ram_size, gd->ram_top);
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;
65 #ifdef CONFIG_ARCH_EARLY_INIT_R
66 static int mcu_init(void)
68 struct rk3368_grf *grf = syscon_get_first_range(ROCKCHIP_SYSCON_GRF);
69 struct rk3368_cru *cru = rockchip_get_cru();
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);
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));
88 /* mcu dereset, for start running */
89 rk_clrreg(&cru->softrst_con[1], MCU_PO_SRST_MASK | MCU_SYS_SRST_MASK);
94 int arch_early_init_r(void)
100 #ifdef CONFIG_DEBUG_UART_BOARD_INIT
101 void board_debug_uart_init(void)
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.
108 #if defined(CONFIG_DEBUG_UART_BASE) && (CONFIG_DEBUG_UART_BASE == 0xff180000)
109 struct rk3368_grf * const grf =
110 (struct rk3368_grf * const)0xff770000;
113 GPIO2D1_MASK = GENMASK(3, 2),
115 GPIO2D1_UART0_SOUT = (1 << 2),
117 GPIO2D0_MASK = GENMASK(1, 0),
119 GPIO2D0_UART0_SIN = (1 << 0),
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);
127 #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;
133 GPIO0D2_MASK = GENMASK(5, 4),
135 GPIO0D2_UART4_SOUT = (3 << 4),
137 GPIO0D3_MASK = GENMASK(7, 6),
139 GPIO0D3_UART4_SIN = (3 << 6),
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;
152 GPIO2A6_MASK = GENMASK(13, 12),
154 GPIO2A6_UART2_SIN = (2 << GPIO2A6_SHIFT),
157 GPIO2A5_MASK = GENMASK(11, 10),
159 GPIO2A5_UART2_SOUT = (2 << GPIO2A5_SHIFT),
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);