blob: de17b8868273b6e7a8b12ccc8e357fdf6ae407cf [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
Kever Yang604814c2019-07-22 20:01:58 +080022
Kever Yang612fd9e2019-07-22 19:59:33 +080023const char * const boot_devices[BROM_LAST_BOOTSOURCE + 1] = {
Johan Jonker5859bb22022-04-15 23:21:43 +020024 [BROM_BOOTSOURCE_EMMC] = "/mmc@ff520000",
25 [BROM_BOOTSOURCE_SD] = "/mmc@ff500000",
Kever Yang612fd9e2019-07-22 19:59:33 +080026};
27
Kever Yang85a3cfb2017-02-23 15:37:51 +080028static struct mm_region rk3328_mem_map[] = {
29 {
30 .virt = 0x0UL,
31 .phys = 0x0UL,
Kever Yangbe8da532017-06-13 21:00:12 +080032 .size = 0xff000000UL,
Kever Yang85a3cfb2017-02-23 15:37:51 +080033 .attrs = PTE_BLOCK_MEMTYPE(MT_NORMAL) |
34 PTE_BLOCK_INNER_SHARE
35 }, {
Kever Yangbe8da532017-06-13 21:00:12 +080036 .virt = 0xff000000UL,
37 .phys = 0xff000000UL,
38 .size = 0x1000000UL,
Kever Yang85a3cfb2017-02-23 15:37:51 +080039 .attrs = PTE_BLOCK_MEMTYPE(MT_DEVICE_NGNRNE) |
40 PTE_BLOCK_NON_SHARE |
41 PTE_BLOCK_PXN | PTE_BLOCK_UXN
42 }, {
43 /* List terminator */
44 0,
45 }
46};
47
48struct mm_region *mem_map = rk3328_mem_map;
49
Kever Yang85a3cfb2017-02-23 15:37:51 +080050int arch_cpu_init(void)
51{
Kever Yanga9775a82019-07-29 12:18:18 +030052#ifdef CONFIG_SPL_BUILD
Kever Yang85a3cfb2017-02-23 15:37:51 +080053 /* We do some SoC one time setting here. */
54
Kever Yanga9775a82019-07-29 12:18:18 +030055 /* Disable the ddr secure region setting to make it non-secure */
56 rk_setreg(FW_DDR_CON_REG, 0x200);
57#endif
Kever Yang85a3cfb2017-02-23 15:37:51 +080058 return 0;
59}
Kever Yang604814c2019-07-22 20:01:58 +080060
61void board_debug_uart_init(void)
62{
63 struct rk3328_grf_regs * const grf = (void *)GRF_BASE;
64 struct rk_uart * const uart = (void *)UART2_BASE;
65 enum{
66 GPIO2A0_SEL_SHIFT = 0,
67 GPIO2A0_SEL_MASK = 3 << GPIO2A0_SEL_SHIFT,
68 GPIO2A0_UART2_TX_M1 = 1,
69
70 GPIO2A1_SEL_SHIFT = 2,
71 GPIO2A1_SEL_MASK = 3 << GPIO2A1_SEL_SHIFT,
72 GPIO2A1_UART2_RX_M1 = 1,
73 };
74 enum {
75 IOMUX_SEL_UART2_SHIFT = 0,
76 IOMUX_SEL_UART2_MASK = 3 << IOMUX_SEL_UART2_SHIFT,
77 IOMUX_SEL_UART2_M0 = 0,
78 IOMUX_SEL_UART2_M1,
79 };
80
81 /* uart_sel_clk default select 24MHz */
82 writel((3 << (8 + 16)) | (2 << 8), CRU_BASE + 0x148);
83
84 /* init uart baud rate 1500000 */
85 writel(0x83, &uart->lcr);
86 writel(0x1, &uart->rbr);
87 writel(0x3, &uart->lcr);
88
89 /* Enable early UART2 */
90 rk_clrsetreg(&grf->com_iomux,
91 IOMUX_SEL_UART2_MASK,
92 IOMUX_SEL_UART2_M1 << IOMUX_SEL_UART2_SHIFT);
93 rk_clrsetreg(&grf->gpio2a_iomux,
94 GPIO2A0_SEL_MASK,
95 GPIO2A0_UART2_TX_M1 << GPIO2A0_SEL_SHIFT);
96 rk_clrsetreg(&grf->gpio2a_iomux,
97 GPIO2A1_SEL_MASK,
98 GPIO2A1_UART2_RX_M1 << GPIO2A1_SEL_SHIFT);
99
100 /* enable FIFO */
101 writel(0x1, &uart->sfe);
102}