blob: dc65a021c8124f81eeaebcb4095210c960a4ce6a [file] [log] [blame]
Tom Rini10e47792018-05-06 17:58:06 -04001// SPDX-License-Identifier: GPL-2.0+
Philipp Tomsich866a9e72017-07-04 14:40:01 +02002/*
3 * (C) Copyright 2017 Theobroma Systems Design und Consulting GmbH
Philipp Tomsich866a9e72017-07-04 14:40:01 +02004 */
5
6#include <common.h>
Philipp Tomsich866a9e72017-07-04 14:40:01 +02007#include <debug_uart.h>
8#include <dm.h>
9#include <ram.h>
10#include <spl.h>
Simon Glassf473eba2019-01-21 14:53:31 -070011#include <syscon.h>
Philipp Tomsich866a9e72017-07-04 14:40:01 +020012#include <asm/io.h>
Kever Yang9fbe17c2019-03-28 11:01:23 +080013#include <asm/arch-rockchip/bootrom.h>
14#include <asm/arch-rockchip/clock.h>
15#include <asm/arch-rockchip/cru_rk3368.h>
Kever Yang9fbe17c2019-03-28 11:01:23 +080016#include <asm/arch-rockchip/hardware.h>
17#include <asm/arch-rockchip/timer.h>
Philipp Tomsich866a9e72017-07-04 14:40:01 +020018
Philipp Tomsich866a9e72017-07-04 14:40:01 +020019/*
Philipp Tomsich866a9e72017-07-04 14:40:01 +020020 * The SPL (and also the full U-Boot stage on the RK3368) will run in
21 * secure mode (i.e. EL3) and an ATF will eventually be booted before
22 * starting up the operating system... so we can initialize the SGRF
23 * here and rely on the ATF installing the final (secure) policy
24 * later.
25 */
26static inline uintptr_t sgrf_soc_con_addr(unsigned no)
27{
28 const uintptr_t SGRF_BASE =
29 (uintptr_t)syscon_get_first_range(ROCKCHIP_SYSCON_SGRF);
30
31 return SGRF_BASE + sizeof(u32) * no;
32}
33
34static inline uintptr_t sgrf_busdmac_addr(unsigned no)
35{
36 const uintptr_t SGRF_BASE =
37 (uintptr_t)syscon_get_first_range(ROCKCHIP_SYSCON_SGRF);
38 const uintptr_t SGRF_BUSDMAC_OFFSET = 0x100;
39 const uintptr_t SGRF_BUSDMAC_BASE = SGRF_BASE + SGRF_BUSDMAC_OFFSET;
40
41 return SGRF_BUSDMAC_BASE + sizeof(u32) * no;
42}
43
44static void sgrf_init(void)
45{
46 struct rk3368_cru * const cru =
47 (struct rk3368_cru * const)rockchip_get_cru();
48 const u16 SGRF_SOC_CON_SEC = GENMASK(15, 0);
49 const u16 SGRF_BUSDMAC_CON0_SEC = BIT(2);
50 const u16 SGRF_BUSDMAC_CON1_SEC = GENMASK(15, 12);
51
52 /* Set all configurable IP to 'non secure'-mode */
53 rk_setreg(sgrf_soc_con_addr(5), SGRF_SOC_CON_SEC);
54 rk_setreg(sgrf_soc_con_addr(6), SGRF_SOC_CON_SEC);
55 rk_setreg(sgrf_soc_con_addr(7), SGRF_SOC_CON_SEC);
56
57 /*
58 * From rockchip-uboot/arch/arm/cpu/armv8/rk33xx/cpu.c
59 * Original comment: "ddr space set no secure mode"
60 */
61 rk_clrreg(sgrf_soc_con_addr(8), SGRF_SOC_CON_SEC);
62 rk_clrreg(sgrf_soc_con_addr(9), SGRF_SOC_CON_SEC);
63 rk_clrreg(sgrf_soc_con_addr(10), SGRF_SOC_CON_SEC);
64
65 /* Set 'secure dma' to 'non secure'-mode */
66 rk_setreg(sgrf_busdmac_addr(0), SGRF_BUSDMAC_CON0_SEC);
67 rk_setreg(sgrf_busdmac_addr(1), SGRF_BUSDMAC_CON1_SEC);
68
69 dsb(); /* barrier */
70
71 rk_setreg(&cru->softrst_con[1], DMA1_SRST_REQ);
72 rk_setreg(&cru->softrst_con[4], DMA2_SRST_REQ);
73
74 dsb(); /* barrier */
75 udelay(10);
76
77 rk_clrreg(&cru->softrst_con[1], DMA1_SRST_REQ);
78 rk_clrreg(&cru->softrst_con[4], DMA2_SRST_REQ);
79}
80
Philipp Tomsich866a9e72017-07-04 14:40:01 +020081void board_init_f(ulong dummy)
82{
83 struct udevice *dev;
84 int ret;
85
Kever Yang93417782019-03-29 09:09:05 +080086#ifdef CONFIG_DEBUG_UART
Philipp Tomsich866a9e72017-07-04 14:40:01 +020087 /*
88 * Debug UART can be used from here if required:
89 *
90 * debug_uart_init();
91 * printch('a');
92 * printhex8(0x1234);
93 * printascii("string");
94 */
95 debug_uart_init();
96 printascii("U-Boot TPL board init\n");
97#endif
98
99 ret = spl_early_init();
100 if (ret) {
101 debug("spl_early_init() failed: %d\n", ret);
102 hang();
103 }
104
Philipp Tomsich866a9e72017-07-04 14:40:01 +0200105 /* Reset security, so we can use DMA in the MMC drivers */
106 sgrf_init();
107
108 ret = uclass_get_device(UCLASS_RAM, 0, &dev);
109 if (ret) {
110 debug("DRAM init failed: %d\n", ret);
111 return;
112 }
113}
114
115void board_return_to_bootrom(void)
116{
Philipp Tomsich7234c732017-10-10 16:21:16 +0200117 back_to_bootrom(BROM_BOOT_NEXTSTAGE);
Philipp Tomsich866a9e72017-07-04 14:40:01 +0200118}
119
120u32 spl_boot_device(void)
121{
122 return BOOT_DEVICE_BOOTROM;
123}