blob: 1b3e40074e3b427e1d1ef97b97d2b7a9bb4025cd [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
Joseph Chen72cd8792021-06-02 15:58:25 +08006#include <dm.h>
7#include <asm/armv8/mmu.h>
Chris Morgan673a6472023-02-13 16:27:38 -06008#include <asm/arch-rockchip/bootrom.h>
Joseph Chen72cd8792021-06-02 15:58:25 +08009#include <asm/arch-rockchip/grf_rk3568.h>
10#include <asm/arch-rockchip/hardware.h>
11#include <dt-bindings/clock/rk3568-cru.h>
12
Nico Cheng131e1ab2021-10-26 10:42:21 +080013#define PMUGRF_BASE 0xfdc20000
14#define GRF_BASE 0xfdc60000
15#define GRF_GPIO1B_DS_2 0x218
16#define GRF_GPIO1B_DS_3 0x21c
17#define GRF_GPIO1C_DS_0 0x220
18#define GRF_GPIO1C_DS_1 0x224
19#define GRF_GPIO1C_DS_2 0x228
20#define GRF_GPIO1C_DS_3 0x22c
21#define SGRF_BASE 0xFDD18000
22#define SGRF_SOC_CON4 0x10
23#define EMMC_HPROT_SECURE_CTRL 0x03
24#define SDMMC0_HPROT_SECURE_CTRL 0x01
Chris Morganba9a6062023-02-13 16:27:39 -060025
26#define PMU_BASE_ADDR 0xfdd90000
27#define PMU_NOC_AUTO_CON0 (0x70)
28#define PMU_NOC_AUTO_CON1 (0x74)
29#define EDP_PHY_GRF_BASE 0xfdcb0000
30#define EDP_PHY_GRF_CON0 (EDP_PHY_GRF_BASE + 0x00)
31#define EDP_PHY_GRF_CON10 (EDP_PHY_GRF_BASE + 0x28)
32#define CPU_GRF_BASE 0xfdc30000
33#define GRF_CORE_PVTPLL_CON0 (0x10)
34
Joseph Chen72cd8792021-06-02 15:58:25 +080035/* PMU_GRF_GPIO0D_IOMUX_L */
36enum {
37 GPIO0D1_SHIFT = 4,
38 GPIO0D1_MASK = GENMASK(6, 4),
39 GPIO0D1_GPIO = 0,
40 GPIO0D1_UART2_TXM0,
41
42 GPIO0D0_SHIFT = 0,
43 GPIO0D0_MASK = GENMASK(2, 0),
44 GPIO0D0_GPIO = 0,
45 GPIO0D0_UART2_RXM0,
46};
47
48/* GRF_IOFUNC_SEL3 */
49enum {
50 UART2_IO_SEL_SHIFT = 10,
51 UART2_IO_SEL_MASK = GENMASK(11, 10),
52 UART2_IO_SEL_M0 = 0,
53};
54
55static struct mm_region rk3568_mem_map[] = {
56 {
57 .virt = 0x0UL,
58 .phys = 0x0UL,
59 .size = 0xf0000000UL,
60 .attrs = PTE_BLOCK_MEMTYPE(MT_NORMAL) |
61 PTE_BLOCK_INNER_SHARE
62 }, {
63 .virt = 0xf0000000UL,
64 .phys = 0xf0000000UL,
65 .size = 0x10000000UL,
66 .attrs = PTE_BLOCK_MEMTYPE(MT_DEVICE_NGNRNE) |
67 PTE_BLOCK_NON_SHARE |
68 PTE_BLOCK_PXN | PTE_BLOCK_UXN
69 }, {
70 .virt = 0x300000000,
71 .phys = 0x300000000,
72 .size = 0x0c0c00000,
73 .attrs = PTE_BLOCK_MEMTYPE(MT_DEVICE_NGNRNE) |
74 PTE_BLOCK_NON_SHARE |
75 PTE_BLOCK_PXN | PTE_BLOCK_UXN
76 }, {
77 /* List terminator */
78 0,
79 }
80};
81
Chris Morgan673a6472023-02-13 16:27:38 -060082const char * const boot_devices[BROM_LAST_BOOTSOURCE + 1] = {
Jonas Karlman980da012023-03-14 00:38:23 +000083 [BROM_BOOTSOURCE_EMMC] = "/mmc@fe310000",
Chris Morgan673a6472023-02-13 16:27:38 -060084 [BROM_BOOTSOURCE_SPINOR] = "/spi@fe300000/flash@0",
85 [BROM_BOOTSOURCE_SD] = "/mmc@fe2b0000",
86};
87
Joseph Chen72cd8792021-06-02 15:58:25 +080088struct mm_region *mem_map = rk3568_mem_map;
89
90void board_debug_uart_init(void)
91{
92 static struct rk3568_pmugrf * const pmugrf = (void *)PMUGRF_BASE;
93 static struct rk3568_grf * const grf = (void *)GRF_BASE;
94
95 /* UART2 M0 */
96 rk_clrsetreg(&grf->iofunc_sel3, UART2_IO_SEL_MASK,
97 UART2_IO_SEL_M0 << UART2_IO_SEL_SHIFT);
98
99 /* Switch iomux */
100 rk_clrsetreg(&pmugrf->pmu_gpio0d_iomux_l,
101 GPIO0D1_MASK | GPIO0D0_MASK,
102 GPIO0D1_UART2_TXM0 << GPIO0D1_SHIFT |
103 GPIO0D0_UART2_RXM0 << GPIO0D0_SHIFT);
104}
105
106int arch_cpu_init(void)
107{
Nico Cheng131e1ab2021-10-26 10:42:21 +0800108#ifdef CONFIG_SPL_BUILD
Chris Morganba9a6062023-02-13 16:27:39 -0600109 /*
110 * When perform idle operation, corresponding clock can
111 * be opened or gated automatically.
112 */
113 writel(0xffffffff, PMU_BASE_ADDR + PMU_NOC_AUTO_CON0);
114 writel(0x000f000f, PMU_BASE_ADDR + PMU_NOC_AUTO_CON1);
115
116 /* Disable eDP phy by default */
117 writel(0x00070007, EDP_PHY_GRF_CON10);
118 writel(0x0ff10ff1, EDP_PHY_GRF_CON0);
119
120 /* Set core pvtpll ring length */
121 writel(0x00ff002b, CPU_GRF_BASE + GRF_CORE_PVTPLL_CON0);
122
Nico Cheng131e1ab2021-10-26 10:42:21 +0800123 /* Set the emmc sdmmc0 to secure */
124 rk_clrreg(SGRF_BASE + SGRF_SOC_CON4, (EMMC_HPROT_SECURE_CTRL << 11
125 | SDMMC0_HPROT_SECURE_CTRL << 4));
126 /* set the emmc driver strength to level 2 */
127 writel(0x3f3f0707, GRF_BASE + GRF_GPIO1B_DS_2);
128 writel(0x3f3f0707, GRF_BASE + GRF_GPIO1B_DS_3);
129 writel(0x3f3f0707, GRF_BASE + GRF_GPIO1C_DS_0);
130 writel(0x3f3f0707, GRF_BASE + GRF_GPIO1C_DS_1);
131 writel(0x3f3f0707, GRF_BASE + GRF_GPIO1C_DS_2);
132 writel(0x3f3f0707, GRF_BASE + GRF_GPIO1C_DS_3);
133#endif
Joseph Chen72cd8792021-06-02 15:58:25 +0800134 return 0;
135}