blob: ca623c0d3d031553a22efb50c9464459b24c0609 [file] [log] [blame]
Tom Rini83d290c2018-05-06 17:58:06 -04001// SPDX-License-Identifier: GPL-2.0+
Kever Yang85a3cfb2017-02-23 15:37:51 +08002/*
3 * Copyright (c) 2016 Rockchip Electronics Co., Ltd
Kever Yang85a3cfb2017-02-23 15:37:51 +08004 */
5
6#include <common.h>
Simon Glass691d7192020-05-10 11:40:02 -06007#include <init.h>
Kever Yang612fd9e2019-07-22 19:59:33 +08008#include <asm/arch-rockchip/bootrom.h>
Kever Yang15f09a12019-03-28 11:01:23 +08009#include <asm/arch-rockchip/hardware.h>
Kever Yang604814c2019-07-22 20:01:58 +080010#include <asm/arch-rockchip/grf_rk3328.h>
11#include <asm/arch-rockchip/uart.h>
Kever Yang85a3cfb2017-02-23 15:37:51 +080012#include <asm/armv8/mmu.h>
Simon Glass401d1c42020-10-30 21:38:53 -060013#include <asm/global_data.h>
Kever Yang85a3cfb2017-02-23 15:37:51 +080014#include <asm/io.h>
15
Kever Yang975e4ab2017-06-23 16:11:11 +080016DECLARE_GLOBAL_DATA_PTR;
17
Kever Yang604814c2019-07-22 20:01:58 +080018#define CRU_BASE 0xFF440000
19#define GRF_BASE 0xFF100000
20#define UART2_BASE 0xFF130000
Kever Yanga9775a82019-07-29 12:18:18 +030021#define FW_DDR_CON_REG 0xFF7C0040
Jonas Karlman5708e8e2024-01-07 18:18:33 +000022#define EFUSE_NS_BASE 0xFF260000
23
24#define EFUSE_MOD 0x0000
25#define EFUSE_INT_CON 0x0014
26#define EFUSE_T_CSB_P 0x0028
27#define EFUSE_T_PGENB_P 0x002C
28#define EFUSE_T_LOAD_P 0x0030
29#define EFUSE_T_ADDR_P 0x0034
30#define EFUSE_T_STROBE_P 0x0038
31#define EFUSE_T_CSB_R 0x003C
32#define EFUSE_T_PGENB_R 0x0040
33#define EFUSE_T_LOAD_R 0x0044
34#define EFUSE_T_ADDR_R 0x0048
35#define EFUSE_T_STROBE_R 0x004C
36
37#define EFUSE_USER_MODE 0x1
38#define EFUSE_TIMING(s, l) (((s) << 16) | (l))
Kever Yang604814c2019-07-22 20:01:58 +080039
Kever Yang612fd9e2019-07-22 19:59:33 +080040const char * const boot_devices[BROM_LAST_BOOTSOURCE + 1] = {
Johan Jonker5859bb22022-04-15 23:21:43 +020041 [BROM_BOOTSOURCE_EMMC] = "/mmc@ff520000",
42 [BROM_BOOTSOURCE_SD] = "/mmc@ff500000",
Kever Yang612fd9e2019-07-22 19:59:33 +080043};
44
Kever Yang85a3cfb2017-02-23 15:37:51 +080045static struct mm_region rk3328_mem_map[] = {
46 {
47 .virt = 0x0UL,
48 .phys = 0x0UL,
Kever Yangbe8da532017-06-13 21:00:12 +080049 .size = 0xff000000UL,
Kever Yang85a3cfb2017-02-23 15:37:51 +080050 .attrs = PTE_BLOCK_MEMTYPE(MT_NORMAL) |
51 PTE_BLOCK_INNER_SHARE
52 }, {
Kever Yangbe8da532017-06-13 21:00:12 +080053 .virt = 0xff000000UL,
54 .phys = 0xff000000UL,
55 .size = 0x1000000UL,
Kever Yang85a3cfb2017-02-23 15:37:51 +080056 .attrs = PTE_BLOCK_MEMTYPE(MT_DEVICE_NGNRNE) |
57 PTE_BLOCK_NON_SHARE |
58 PTE_BLOCK_PXN | PTE_BLOCK_UXN
59 }, {
60 /* List terminator */
61 0,
62 }
63};
64
65struct mm_region *mem_map = rk3328_mem_map;
66
Kever Yang85a3cfb2017-02-23 15:37:51 +080067int arch_cpu_init(void)
68{
Kever Yanga9775a82019-07-29 12:18:18 +030069#ifdef CONFIG_SPL_BUILD
Jonas Karlman5708e8e2024-01-07 18:18:33 +000070 u32 reg;
71
Kever Yang85a3cfb2017-02-23 15:37:51 +080072 /* We do some SoC one time setting here. */
73
Kever Yanga9775a82019-07-29 12:18:18 +030074 /* Disable the ddr secure region setting to make it non-secure */
75 rk_setreg(FW_DDR_CON_REG, 0x200);
Jonas Karlman5708e8e2024-01-07 18:18:33 +000076
77 /* Use efuse auto mode */
78 reg = readl(EFUSE_NS_BASE + EFUSE_MOD);
79 writel(reg & ~EFUSE_USER_MODE, EFUSE_NS_BASE + EFUSE_MOD);
80
81 /* Enable efuse finish and auto access err interrupt */
82 writel(0x07, EFUSE_NS_BASE + EFUSE_INT_CON);
83
84 /* Set efuse timing control */
85 writel(EFUSE_TIMING(1, 241), EFUSE_NS_BASE + EFUSE_T_CSB_P);
86 writel(EFUSE_TIMING(1, 241), EFUSE_NS_BASE + EFUSE_T_PGENB_P);
87 writel(EFUSE_TIMING(1, 241), EFUSE_NS_BASE + EFUSE_T_LOAD_P);
88 writel(EFUSE_TIMING(1, 241), EFUSE_NS_BASE + EFUSE_T_ADDR_P);
89 writel(EFUSE_TIMING(2, 240), EFUSE_NS_BASE + EFUSE_T_STROBE_P);
90 writel(EFUSE_TIMING(1, 4), EFUSE_NS_BASE + EFUSE_T_CSB_R);
91 writel(EFUSE_TIMING(1, 4), EFUSE_NS_BASE + EFUSE_T_PGENB_R);
92 writel(EFUSE_TIMING(1, 4), EFUSE_NS_BASE + EFUSE_T_LOAD_R);
93 writel(EFUSE_TIMING(1, 4), EFUSE_NS_BASE + EFUSE_T_ADDR_R);
94 writel(EFUSE_TIMING(2, 3), EFUSE_NS_BASE + EFUSE_T_STROBE_R);
Kever Yanga9775a82019-07-29 12:18:18 +030095#endif
Kever Yang85a3cfb2017-02-23 15:37:51 +080096 return 0;
97}
Kever Yang604814c2019-07-22 20:01:58 +080098
99void board_debug_uart_init(void)
100{
101 struct rk3328_grf_regs * const grf = (void *)GRF_BASE;
102 struct rk_uart * const uart = (void *)UART2_BASE;
103 enum{
104 GPIO2A0_SEL_SHIFT = 0,
105 GPIO2A0_SEL_MASK = 3 << GPIO2A0_SEL_SHIFT,
106 GPIO2A0_UART2_TX_M1 = 1,
107
108 GPIO2A1_SEL_SHIFT = 2,
109 GPIO2A1_SEL_MASK = 3 << GPIO2A1_SEL_SHIFT,
110 GPIO2A1_UART2_RX_M1 = 1,
111 };
112 enum {
113 IOMUX_SEL_UART2_SHIFT = 0,
114 IOMUX_SEL_UART2_MASK = 3 << IOMUX_SEL_UART2_SHIFT,
115 IOMUX_SEL_UART2_M0 = 0,
116 IOMUX_SEL_UART2_M1,
117 };
118
119 /* uart_sel_clk default select 24MHz */
120 writel((3 << (8 + 16)) | (2 << 8), CRU_BASE + 0x148);
121
122 /* init uart baud rate 1500000 */
123 writel(0x83, &uart->lcr);
124 writel(0x1, &uart->rbr);
125 writel(0x3, &uart->lcr);
126
127 /* Enable early UART2 */
128 rk_clrsetreg(&grf->com_iomux,
129 IOMUX_SEL_UART2_MASK,
130 IOMUX_SEL_UART2_M1 << IOMUX_SEL_UART2_SHIFT);
131 rk_clrsetreg(&grf->gpio2a_iomux,
132 GPIO2A0_SEL_MASK,
133 GPIO2A0_UART2_TX_M1 << GPIO2A0_SEL_SHIFT);
134 rk_clrsetreg(&grf->gpio2a_iomux,
135 GPIO2A1_SEL_MASK,
136 GPIO2A1_UART2_RX_M1 << GPIO2A1_SEL_SHIFT);
137
138 /* enable FIFO */
139 writel(0x1, &uart->sfe);
140}