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