blob: 8c81242e5d4b711733eb3534a3dbc1fe80f107f7 [file] [log] [blame]
Tom Rini10e47792018-05-06 17:58:06 -04001// SPDX-License-Identifier: GPL-2.0+
Kever Yangec02b3c2017-02-23 15:37:51 +08002/*
3 * Copyright (c) 2016 Rockchip Electronics Co., Ltd
Kever Yangec02b3c2017-02-23 15:37:51 +08004 */
5
6#include <common.h>
Kever Yangb04029e2019-07-22 19:59:33 +08007#include <asm/arch-rockchip/bootrom.h>
Kever Yang9fbe17c2019-03-28 11:01:23 +08008#include <asm/arch-rockchip/hardware.h>
Kever Yang5a9a2aa2019-07-22 20:01:58 +08009#include <asm/arch-rockchip/grf_rk3328.h>
10#include <asm/arch-rockchip/uart.h>
Kever Yangec02b3c2017-02-23 15:37:51 +080011#include <asm/armv8/mmu.h>
12#include <asm/io.h>
13
Kever Yangc2053262017-06-23 16:11:11 +080014DECLARE_GLOBAL_DATA_PTR;
15
Kever Yang5a9a2aa2019-07-22 20:01:58 +080016#define CRU_BASE 0xFF440000
17#define GRF_BASE 0xFF100000
18#define UART2_BASE 0xFF130000
Kever Yanga18a6452019-07-29 12:18:18 +030019#define FW_DDR_CON_REG 0xFF7C0040
Kever Yang5a9a2aa2019-07-22 20:01:58 +080020
Kever Yangb04029e2019-07-22 19:59:33 +080021const char * const boot_devices[BROM_LAST_BOOTSOURCE + 1] = {
Levin Du27df5072019-10-17 15:22:38 +080022 [BROM_BOOTSOURCE_EMMC] = "/rksdmmc@ff520000",
23 [BROM_BOOTSOURCE_SD] = "/rksdmmc@ff500000",
Kever Yangb04029e2019-07-22 19:59:33 +080024};
25
Kever Yangec02b3c2017-02-23 15:37:51 +080026static struct mm_region rk3328_mem_map[] = {
27 {
28 .virt = 0x0UL,
29 .phys = 0x0UL,
Kever Yang6cd0cab2017-06-13 21:00:12 +080030 .size = 0xff000000UL,
Kever Yangec02b3c2017-02-23 15:37:51 +080031 .attrs = PTE_BLOCK_MEMTYPE(MT_NORMAL) |
32 PTE_BLOCK_INNER_SHARE
33 }, {
Kever Yang6cd0cab2017-06-13 21:00:12 +080034 .virt = 0xff000000UL,
35 .phys = 0xff000000UL,
36 .size = 0x1000000UL,
Kever Yangec02b3c2017-02-23 15:37:51 +080037 .attrs = PTE_BLOCK_MEMTYPE(MT_DEVICE_NGNRNE) |
38 PTE_BLOCK_NON_SHARE |
39 PTE_BLOCK_PXN | PTE_BLOCK_UXN
40 }, {
41 /* List terminator */
42 0,
43 }
44};
45
46struct mm_region *mem_map = rk3328_mem_map;
47
Kever Yangec02b3c2017-02-23 15:37:51 +080048int arch_cpu_init(void)
49{
Kever Yanga18a6452019-07-29 12:18:18 +030050#ifdef CONFIG_SPL_BUILD
Kever Yangec02b3c2017-02-23 15:37:51 +080051 /* We do some SoC one time setting here. */
52
Kever Yanga18a6452019-07-29 12:18:18 +030053 /* Disable the ddr secure region setting to make it non-secure */
54 rk_setreg(FW_DDR_CON_REG, 0x200);
55#endif
Kever Yangec02b3c2017-02-23 15:37:51 +080056 return 0;
57}
Kever Yang5a9a2aa2019-07-22 20:01:58 +080058
59void board_debug_uart_init(void)
60{
61 struct rk3328_grf_regs * const grf = (void *)GRF_BASE;
62 struct rk_uart * const uart = (void *)UART2_BASE;
63 enum{
64 GPIO2A0_SEL_SHIFT = 0,
65 GPIO2A0_SEL_MASK = 3 << GPIO2A0_SEL_SHIFT,
66 GPIO2A0_UART2_TX_M1 = 1,
67
68 GPIO2A1_SEL_SHIFT = 2,
69 GPIO2A1_SEL_MASK = 3 << GPIO2A1_SEL_SHIFT,
70 GPIO2A1_UART2_RX_M1 = 1,
71 };
72 enum {
73 IOMUX_SEL_UART2_SHIFT = 0,
74 IOMUX_SEL_UART2_MASK = 3 << IOMUX_SEL_UART2_SHIFT,
75 IOMUX_SEL_UART2_M0 = 0,
76 IOMUX_SEL_UART2_M1,
77 };
78
79 /* uart_sel_clk default select 24MHz */
80 writel((3 << (8 + 16)) | (2 << 8), CRU_BASE + 0x148);
81
82 /* init uart baud rate 1500000 */
83 writel(0x83, &uart->lcr);
84 writel(0x1, &uart->rbr);
85 writel(0x3, &uart->lcr);
86
87 /* Enable early UART2 */
88 rk_clrsetreg(&grf->com_iomux,
89 IOMUX_SEL_UART2_MASK,
90 IOMUX_SEL_UART2_M1 << IOMUX_SEL_UART2_SHIFT);
91 rk_clrsetreg(&grf->gpio2a_iomux,
92 GPIO2A0_SEL_MASK,
93 GPIO2A0_UART2_TX_M1 << GPIO2A0_SEL_SHIFT);
94 rk_clrsetreg(&grf->gpio2a_iomux,
95 GPIO2A1_SEL_MASK,
96 GPIO2A1_UART2_RX_M1 << GPIO2A1_SEL_SHIFT);
97
98 /* enable FIFO */
99 writel(0x1, &uart->sfe);
100}