blob: c2b96902d2dd95085e5fb3c9836a4f1bb0208448 [file] [log] [blame]
Joseph Chen72cd8792021-06-02 15:58:25 +08001// SPDX-License-Identifier: GPL-2.0+
2/*
3 * (C) Copyright 2021 Rockchip Electronics Co., Ltd
4 */
5
Jonas Karlmana1c69252024-11-10 00:56:15 +00006#define LOG_CATEGORY LOGC_ARCH
7
Joseph Chen72cd8792021-06-02 15:58:25 +08008#include <dm.h>
Jonas Karlmana1c69252024-11-10 00:56:15 +00009#include <misc.h>
Joseph Chen72cd8792021-06-02 15:58:25 +080010#include <asm/armv8/mmu.h>
Chris Morgan673a6472023-02-13 16:27:38 -060011#include <asm/arch-rockchip/bootrom.h>
Joseph Chen72cd8792021-06-02 15:58:25 +080012#include <asm/arch-rockchip/grf_rk3568.h>
13#include <asm/arch-rockchip/hardware.h>
14#include <dt-bindings/clock/rk3568-cru.h>
15
Nico Cheng131e1ab2021-10-26 10:42:21 +080016#define PMUGRF_BASE 0xfdc20000
17#define GRF_BASE 0xfdc60000
18#define GRF_GPIO1B_DS_2 0x218
19#define GRF_GPIO1B_DS_3 0x21c
20#define GRF_GPIO1C_DS_0 0x220
21#define GRF_GPIO1C_DS_1 0x224
22#define GRF_GPIO1C_DS_2 0x228
23#define GRF_GPIO1C_DS_3 0x22c
24#define SGRF_BASE 0xFDD18000
25#define SGRF_SOC_CON4 0x10
26#define EMMC_HPROT_SECURE_CTRL 0x03
27#define SDMMC0_HPROT_SECURE_CTRL 0x01
Chris Morganba9a6062023-02-13 16:27:39 -060028
29#define PMU_BASE_ADDR 0xfdd90000
30#define PMU_NOC_AUTO_CON0 (0x70)
31#define PMU_NOC_AUTO_CON1 (0x74)
Chris Morgan26d841f2024-09-19 09:00:22 -050032#define PMU_PWR_GATE_SFTCON (0xa0)
33#define PMU_PD_VO_DWN_ENA BIT(7)
Chris Morganba9a6062023-02-13 16:27:39 -060034#define EDP_PHY_GRF_BASE 0xfdcb0000
35#define EDP_PHY_GRF_CON0 (EDP_PHY_GRF_BASE + 0x00)
36#define EDP_PHY_GRF_CON10 (EDP_PHY_GRF_BASE + 0x28)
37#define CPU_GRF_BASE 0xfdc30000
38#define GRF_CORE_PVTPLL_CON0 (0x10)
39
Joseph Chen72cd8792021-06-02 15:58:25 +080040/* PMU_GRF_GPIO0D_IOMUX_L */
41enum {
42 GPIO0D1_SHIFT = 4,
43 GPIO0D1_MASK = GENMASK(6, 4),
44 GPIO0D1_GPIO = 0,
45 GPIO0D1_UART2_TXM0,
46
47 GPIO0D0_SHIFT = 0,
48 GPIO0D0_MASK = GENMASK(2, 0),
49 GPIO0D0_GPIO = 0,
50 GPIO0D0_UART2_RXM0,
51};
52
53/* GRF_IOFUNC_SEL3 */
54enum {
55 UART2_IO_SEL_SHIFT = 10,
56 UART2_IO_SEL_MASK = GENMASK(11, 10),
57 UART2_IO_SEL_M0 = 0,
58};
59
60static struct mm_region rk3568_mem_map[] = {
61 {
62 .virt = 0x0UL,
63 .phys = 0x0UL,
64 .size = 0xf0000000UL,
65 .attrs = PTE_BLOCK_MEMTYPE(MT_NORMAL) |
66 PTE_BLOCK_INNER_SHARE
67 }, {
68 .virt = 0xf0000000UL,
69 .phys = 0xf0000000UL,
70 .size = 0x10000000UL,
71 .attrs = PTE_BLOCK_MEMTYPE(MT_DEVICE_NGNRNE) |
72 PTE_BLOCK_NON_SHARE |
73 PTE_BLOCK_PXN | PTE_BLOCK_UXN
74 }, {
75 .virt = 0x300000000,
76 .phys = 0x300000000,
77 .size = 0x0c0c00000,
78 .attrs = PTE_BLOCK_MEMTYPE(MT_DEVICE_NGNRNE) |
79 PTE_BLOCK_NON_SHARE |
80 PTE_BLOCK_PXN | PTE_BLOCK_UXN
81 }, {
82 /* List terminator */
83 0,
84 }
85};
86
Chris Morgan673a6472023-02-13 16:27:38 -060087const char * const boot_devices[BROM_LAST_BOOTSOURCE + 1] = {
Jonas Karlman980da012023-03-14 00:38:23 +000088 [BROM_BOOTSOURCE_EMMC] = "/mmc@fe310000",
Chris Morgan673a6472023-02-13 16:27:38 -060089 [BROM_BOOTSOURCE_SPINOR] = "/spi@fe300000/flash@0",
90 [BROM_BOOTSOURCE_SD] = "/mmc@fe2b0000",
91};
92
Joseph Chen72cd8792021-06-02 15:58:25 +080093struct mm_region *mem_map = rk3568_mem_map;
94
95void board_debug_uart_init(void)
96{
97 static struct rk3568_pmugrf * const pmugrf = (void *)PMUGRF_BASE;
98 static struct rk3568_grf * const grf = (void *)GRF_BASE;
99
100 /* UART2 M0 */
101 rk_clrsetreg(&grf->iofunc_sel3, UART2_IO_SEL_MASK,
102 UART2_IO_SEL_M0 << UART2_IO_SEL_SHIFT);
103
104 /* Switch iomux */
105 rk_clrsetreg(&pmugrf->pmu_gpio0d_iomux_l,
106 GPIO0D1_MASK | GPIO0D0_MASK,
107 GPIO0D1_UART2_TXM0 << GPIO0D1_SHIFT |
108 GPIO0D0_UART2_RXM0 << GPIO0D0_SHIFT);
109}
110
111int arch_cpu_init(void)
112{
Simon Glass85ed77d2024-09-29 19:49:46 -0600113#ifdef CONFIG_XPL_BUILD
Chris Morganba9a6062023-02-13 16:27:39 -0600114 /*
115 * When perform idle operation, corresponding clock can
116 * be opened or gated automatically.
117 */
118 writel(0xffffffff, PMU_BASE_ADDR + PMU_NOC_AUTO_CON0);
119 writel(0x000f000f, PMU_BASE_ADDR + PMU_NOC_AUTO_CON1);
120
121 /* Disable eDP phy by default */
122 writel(0x00070007, EDP_PHY_GRF_CON10);
123 writel(0x0ff10ff1, EDP_PHY_GRF_CON0);
124
125 /* Set core pvtpll ring length */
126 writel(0x00ff002b, CPU_GRF_BASE + GRF_CORE_PVTPLL_CON0);
127
Nico Cheng131e1ab2021-10-26 10:42:21 +0800128 /* Set the emmc sdmmc0 to secure */
129 rk_clrreg(SGRF_BASE + SGRF_SOC_CON4, (EMMC_HPROT_SECURE_CTRL << 11
130 | SDMMC0_HPROT_SECURE_CTRL << 4));
131 /* set the emmc driver strength to level 2 */
132 writel(0x3f3f0707, GRF_BASE + GRF_GPIO1B_DS_2);
133 writel(0x3f3f0707, GRF_BASE + GRF_GPIO1B_DS_3);
134 writel(0x3f3f0707, GRF_BASE + GRF_GPIO1C_DS_0);
135 writel(0x3f3f0707, GRF_BASE + GRF_GPIO1C_DS_1);
136 writel(0x3f3f0707, GRF_BASE + GRF_GPIO1C_DS_2);
137 writel(0x3f3f0707, GRF_BASE + GRF_GPIO1C_DS_3);
Chris Morgan26d841f2024-09-19 09:00:22 -0500138
139 /* Enable VO power domain for display */
140 writel((PMU_PD_VO_DWN_ENA << 16),
141 PMU_BASE_ADDR + PMU_PWR_GATE_SFTCON);
Nico Cheng131e1ab2021-10-26 10:42:21 +0800142#endif
Joseph Chen72cd8792021-06-02 15:58:25 +0800143 return 0;
144}
Jonas Karlmana1c69252024-11-10 00:56:15 +0000145
146#define RK3568_OTP_CPU_CODE_OFFSET 0x02
147#define RK3568_OTP_SPECIFICATION_OFFSET 0x07
148#define RK3568_OTP_PERFORMANCE_OFFSET 0x22
149
150int checkboard(void)
151{
152 u8 cpu_code[2], specification, package, performance;
153 struct udevice *dev;
154 char suffix[3];
155 int ret;
156
157 if (!IS_ENABLED(CONFIG_ROCKCHIP_OTP) || !CONFIG_IS_ENABLED(MISC))
158 return 0;
159
160 ret = uclass_get_device_by_driver(UCLASS_MISC,
161 DM_DRIVER_GET(rockchip_otp), &dev);
162 if (ret) {
163 log_debug("Could not find otp device, ret=%d\n", ret);
164 return 0;
165 }
166
167 /* cpu-code: SoC model, e.g. 0x35 0x66 or 0x35 0x68 */
168 ret = misc_read(dev, RK3568_OTP_CPU_CODE_OFFSET, cpu_code, 2);
169 if (ret < 0) {
170 log_debug("Could not read cpu-code, ret=%d\n", ret);
171 return 0;
172 }
173
174 /* specification: SoC variant, e.g. 0x2 for RK3568B2 and 0xA for RK3568J */
175 ret = misc_read(dev, RK3568_OTP_SPECIFICATION_OFFSET, &specification, 1);
176 if (ret < 0) {
177 log_debug("Could not read specification, ret=%d\n", ret);
178 return 0;
179 }
180 /* package: likely SoC variant revision, 0x2 for RK3568B2 */
181 package = specification >> 5;
182 specification &= 0x1f;
183
184 /* performance: used to identify RK3566T SoC variant */
185 ret = misc_read(dev, RK3568_OTP_PERFORMANCE_OFFSET, &performance, 1);
186 if (ret < 0) {
187 log_debug("Could not read performance, ret=%d\n", ret);
188 return 0;
189 }
190 if (performance & 0x0f)
191 specification = 0x14; /* T-variant */
192
193 /* for RK3568J i.e. '@' + 0xA = 'J' */
194 suffix[0] = specification > 1 ? '@' + specification : '\0';
195 /* for RK3568B2 i.e. '0' + 0x2 = '2' */
196 suffix[1] = package > 1 ? '0' + package : '\0';
197 suffix[2] = '\0';
198
199 printf("SoC: RK%02x%02x%s\n", cpu_code[0], cpu_code[1], suffix);
200
201 return 0;
202}