blob: c86d11943d6dbb42f4a56a601a0f2c470f977162 [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
Simon Glass97589732020-05-10 11:40:02 -06006#include <init.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>
Kever Yangec02b3c2017-02-23 15:37:51 +080012
Kever Yang5a9a2aa2019-07-22 20:01:58 +080013#define CRU_BASE 0xFF440000
14#define GRF_BASE 0xFF100000
15#define UART2_BASE 0xFF130000
Kever Yanga18a6452019-07-29 12:18:18 +030016#define FW_DDR_CON_REG 0xFF7C0040
Jonas Karlmancac33112024-01-07 18:18:33 +000017#define EFUSE_NS_BASE 0xFF260000
18
19#define EFUSE_MOD 0x0000
20#define EFUSE_INT_CON 0x0014
21#define EFUSE_T_CSB_P 0x0028
22#define EFUSE_T_PGENB_P 0x002C
23#define EFUSE_T_LOAD_P 0x0030
24#define EFUSE_T_ADDR_P 0x0034
25#define EFUSE_T_STROBE_P 0x0038
26#define EFUSE_T_CSB_R 0x003C
27#define EFUSE_T_PGENB_R 0x0040
28#define EFUSE_T_LOAD_R 0x0044
29#define EFUSE_T_ADDR_R 0x0048
30#define EFUSE_T_STROBE_R 0x004C
31
32#define EFUSE_USER_MODE 0x1
33#define EFUSE_TIMING(s, l) (((s) << 16) | (l))
Kever Yang5a9a2aa2019-07-22 20:01:58 +080034
Kever Yangb04029e2019-07-22 19:59:33 +080035const char * const boot_devices[BROM_LAST_BOOTSOURCE + 1] = {
Johan Jonkerf05aa9d2022-04-15 23:21:43 +020036 [BROM_BOOTSOURCE_EMMC] = "/mmc@ff520000",
Jonas Karlmane4b50e02024-02-17 00:22:39 +000037 [BROM_BOOTSOURCE_SPINOR] = "/spi@ff190000/flash@0",
Johan Jonkerf05aa9d2022-04-15 23:21:43 +020038 [BROM_BOOTSOURCE_SD] = "/mmc@ff500000",
Kever Yangb04029e2019-07-22 19:59:33 +080039};
40
Kever Yangec02b3c2017-02-23 15:37:51 +080041static struct mm_region rk3328_mem_map[] = {
42 {
43 .virt = 0x0UL,
44 .phys = 0x0UL,
Kever Yang6cd0cab2017-06-13 21:00:12 +080045 .size = 0xff000000UL,
Kever Yangec02b3c2017-02-23 15:37:51 +080046 .attrs = PTE_BLOCK_MEMTYPE(MT_NORMAL) |
47 PTE_BLOCK_INNER_SHARE
48 }, {
Kever Yang6cd0cab2017-06-13 21:00:12 +080049 .virt = 0xff000000UL,
50 .phys = 0xff000000UL,
51 .size = 0x1000000UL,
Kever Yangec02b3c2017-02-23 15:37:51 +080052 .attrs = PTE_BLOCK_MEMTYPE(MT_DEVICE_NGNRNE) |
53 PTE_BLOCK_NON_SHARE |
54 PTE_BLOCK_PXN | PTE_BLOCK_UXN
55 }, {
56 /* List terminator */
57 0,
58 }
59};
60
61struct mm_region *mem_map = rk3328_mem_map;
62
Kever Yangec02b3c2017-02-23 15:37:51 +080063int arch_cpu_init(void)
64{
Kever Yanga18a6452019-07-29 12:18:18 +030065#ifdef CONFIG_SPL_BUILD
Jonas Karlmancac33112024-01-07 18:18:33 +000066 u32 reg;
67
Kever Yangec02b3c2017-02-23 15:37:51 +080068 /* We do some SoC one time setting here. */
69
Kever Yanga18a6452019-07-29 12:18:18 +030070 /* Disable the ddr secure region setting to make it non-secure */
71 rk_setreg(FW_DDR_CON_REG, 0x200);
Jonas Karlmancac33112024-01-07 18:18:33 +000072
73 /* Use efuse auto mode */
74 reg = readl(EFUSE_NS_BASE + EFUSE_MOD);
75 writel(reg & ~EFUSE_USER_MODE, EFUSE_NS_BASE + EFUSE_MOD);
76
77 /* Enable efuse finish and auto access err interrupt */
78 writel(0x07, EFUSE_NS_BASE + EFUSE_INT_CON);
79
80 /* Set efuse timing control */
81 writel(EFUSE_TIMING(1, 241), EFUSE_NS_BASE + EFUSE_T_CSB_P);
82 writel(EFUSE_TIMING(1, 241), EFUSE_NS_BASE + EFUSE_T_PGENB_P);
83 writel(EFUSE_TIMING(1, 241), EFUSE_NS_BASE + EFUSE_T_LOAD_P);
84 writel(EFUSE_TIMING(1, 241), EFUSE_NS_BASE + EFUSE_T_ADDR_P);
85 writel(EFUSE_TIMING(2, 240), EFUSE_NS_BASE + EFUSE_T_STROBE_P);
86 writel(EFUSE_TIMING(1, 4), EFUSE_NS_BASE + EFUSE_T_CSB_R);
87 writel(EFUSE_TIMING(1, 4), EFUSE_NS_BASE + EFUSE_T_PGENB_R);
88 writel(EFUSE_TIMING(1, 4), EFUSE_NS_BASE + EFUSE_T_LOAD_R);
89 writel(EFUSE_TIMING(1, 4), EFUSE_NS_BASE + EFUSE_T_ADDR_R);
90 writel(EFUSE_TIMING(2, 3), EFUSE_NS_BASE + EFUSE_T_STROBE_R);
Kever Yanga18a6452019-07-29 12:18:18 +030091#endif
Kever Yangec02b3c2017-02-23 15:37:51 +080092 return 0;
93}
Kever Yang5a9a2aa2019-07-22 20:01:58 +080094
95void board_debug_uart_init(void)
96{
97 struct rk3328_grf_regs * const grf = (void *)GRF_BASE;
98 struct rk_uart * const uart = (void *)UART2_BASE;
99 enum{
100 GPIO2A0_SEL_SHIFT = 0,
101 GPIO2A0_SEL_MASK = 3 << GPIO2A0_SEL_SHIFT,
102 GPIO2A0_UART2_TX_M1 = 1,
103
104 GPIO2A1_SEL_SHIFT = 2,
105 GPIO2A1_SEL_MASK = 3 << GPIO2A1_SEL_SHIFT,
106 GPIO2A1_UART2_RX_M1 = 1,
107 };
108 enum {
109 IOMUX_SEL_UART2_SHIFT = 0,
110 IOMUX_SEL_UART2_MASK = 3 << IOMUX_SEL_UART2_SHIFT,
111 IOMUX_SEL_UART2_M0 = 0,
112 IOMUX_SEL_UART2_M1,
113 };
114
115 /* uart_sel_clk default select 24MHz */
116 writel((3 << (8 + 16)) | (2 << 8), CRU_BASE + 0x148);
117
118 /* init uart baud rate 1500000 */
119 writel(0x83, &uart->lcr);
120 writel(0x1, &uart->rbr);
121 writel(0x3, &uart->lcr);
122
123 /* Enable early UART2 */
124 rk_clrsetreg(&grf->com_iomux,
125 IOMUX_SEL_UART2_MASK,
126 IOMUX_SEL_UART2_M1 << IOMUX_SEL_UART2_SHIFT);
127 rk_clrsetreg(&grf->gpio2a_iomux,
128 GPIO2A0_SEL_MASK,
129 GPIO2A0_UART2_TX_M1 << GPIO2A0_SEL_SHIFT);
130 rk_clrsetreg(&grf->gpio2a_iomux,
131 GPIO2A1_SEL_MASK,
132 GPIO2A1_UART2_RX_M1 << GPIO2A1_SEL_SHIFT);
133
134 /* enable FIFO */
135 writel(0x1, &uart->sfe);
136}