blob: 6d5d4cc760ae554a030faf43d4748a5584223404 [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>
10#include <asm/arch/clock.h>
11#include <asm/arch/cru_rk3368.h>
12#include <asm/arch/grf_rk3368.h>
13#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