blob: d6bf74f7ad7a35095231cf3c99d85c8efdef359a [file] [log] [blame]
Kever Yang441a6d32017-02-23 16:09:05 +08001/*
2 * (C) Copyright 2016 Rockchip Electronics Co., Ltd
3 *
4 * SPDX-License-Identifier: GPL-2.0+
5 */
6
7#include <common.h>
8#include <debug_uart.h>
9#include <dm.h>
Kever Yang441a6d32017-02-23 16:09:05 +080010#include <ram.h>
11#include <spl.h>
12#include <asm/gpio.h>
13#include <asm/io.h>
14#include <asm/arch/clock.h>
15#include <asm/arch/hardware.h>
16#include <asm/arch/periph.h>
17#include <asm/arch/sdram.h>
18#include <asm/arch/timer.h>
19#include <dm/pinctrl.h>
Kever Yang441a6d32017-02-23 16:09:05 +080020#include <power/regulator.h>
21
22DECLARE_GLOBAL_DATA_PTR;
23
24u32 spl_boot_device(void)
25{
26 return BOOT_DEVICE_MMC1;
27}
28
29u32 spl_boot_mode(const u32 boot_device)
30{
31 return MMCSD_MODE_RAW;
32}
33
34#define TIMER_CHN10_BASE 0xff8680a0
35#define TIMER_END_COUNT_L 0x00
36#define TIMER_END_COUNT_H 0x04
37#define TIMER_INIT_COUNT_L 0x10
38#define TIMER_INIT_COUNT_H 0x14
39#define TIMER_CONTROL_REG 0x1c
40
41#define TIMER_EN 0x1
42#define TIMER_FMODE (0 << 1)
43#define TIMER_RMODE (1 << 1)
44
45void secure_timer_init(void)
46{
47 writel(0xffffffff, TIMER_CHN10_BASE + TIMER_END_COUNT_L);
48 writel(0xffffffff, TIMER_CHN10_BASE + TIMER_END_COUNT_H);
49 writel(0, TIMER_CHN10_BASE + TIMER_INIT_COUNT_L);
50 writel(0, TIMER_CHN10_BASE + TIMER_INIT_COUNT_H);
51 writel(TIMER_EN | TIMER_FMODE, TIMER_CHN10_BASE + TIMER_CONTROL_REG);
52}
53
Philipp Tomsich41029e62017-04-01 12:59:25 +020054void board_debug_uart_init(void)
55{
Kever Yang441a6d32017-02-23 16:09:05 +080056#include <asm/arch/grf_rk3399.h>
Kever Yang441a6d32017-02-23 16:09:05 +080057#define GRF_BASE 0xff770000
58 struct rk3399_grf_regs * const grf = (void *)GRF_BASE;
59
Philipp Tomsich41029e62017-04-01 12:59:25 +020060#if defined(CONFIG_DEBUG_UART_BASE) && (CONFIG_DEBUG_UART_BASE == 0xff180000)
61 /* Enable early UART0 on the RK3399 */
62 rk_clrsetreg(&grf->gpio2c_iomux,
63 GRF_GPIO2C0_SEL_MASK,
64 GRF_UART0BT_SIN << GRF_GPIO2C0_SEL_SHIFT);
65 rk_clrsetreg(&grf->gpio2c_iomux,
66 GRF_GPIO2C1_SEL_MASK,
67 GRF_UART0BT_SOUT << GRF_GPIO2C1_SEL_SHIFT);
68#else
69 /* Enable early UART2 channel C on the RK3399 */
Kever Yang441a6d32017-02-23 16:09:05 +080070 rk_clrsetreg(&grf->gpio4c_iomux,
71 GRF_GPIO4C3_SEL_MASK,
72 GRF_UART2DGBC_SIN << GRF_GPIO4C3_SEL_SHIFT);
73 rk_clrsetreg(&grf->gpio4c_iomux,
74 GRF_GPIO4C4_SEL_MASK,
75 GRF_UART2DBGC_SOUT << GRF_GPIO4C4_SEL_SHIFT);
76 /* Set channel C as UART2 input */
77 rk_clrsetreg(&grf->soc_con7,
78 GRF_UART_DBG_SEL_MASK,
79 GRF_UART_DBG_SEL_C << GRF_UART_DBG_SEL_SHIFT);
Philipp Tomsich41029e62017-04-01 12:59:25 +020080#endif
81}
82
83#define GRF_EMMCCORE_CON11 0xff77f02c
Kever Yanga6697732017-05-05 11:01:43 +080084#define SGRF_DDR_RGN_CON16 0xff330040
85#define SGRF_SLV_SECURE_CON4 0xff33e3d0
Philipp Tomsich41029e62017-04-01 12:59:25 +020086void board_init_f(ulong dummy)
87{
88 struct udevice *pinctrl;
89 struct udevice *dev;
90 int ret;
91
Kever Yang441a6d32017-02-23 16:09:05 +080092#define EARLY_UART
93#ifdef EARLY_UART
94 /*
95 * Debug UART can be used from here if required:
96 *
97 * debug_uart_init();
98 * printch('a');
99 * printhex8(0x1234);
100 * printascii("string");
101 */
102 debug_uart_init();
103 printascii("U-Boot SPL board init");
104#endif
Kever Yanga6697732017-05-05 11:01:43 +0800105
Kever Yang441a6d32017-02-23 16:09:05 +0800106 /* Emmc clock generator: disable the clock multipilier */
107 rk_clrreg(GRF_EMMCCORE_CON11, 0x0ff);
108
Kever Yange603a3d2017-03-20 14:47:16 +0800109 ret = spl_early_init();
Kever Yang441a6d32017-02-23 16:09:05 +0800110 if (ret) {
Kever Yange603a3d2017-03-20 14:47:16 +0800111 debug("spl_early_init() failed: %d\n", ret);
Kever Yang441a6d32017-02-23 16:09:05 +0800112 hang();
113 }
114
Philipp Tomsich2a34cbb2017-03-29 21:20:28 +0200115 /*
Kever Yanga6697732017-05-05 11:01:43 +0800116 * Disable DDR and SRAM security regions.
Philipp Tomsich2a34cbb2017-03-29 21:20:28 +0200117 *
118 * As we are entered from the BootROM, the region from
119 * 0x0 through 0xfffff (i.e. the first MB of memory) will
120 * be protected. This will cause issues with the DW_MMC
121 * driver, which tries to DMA from/to the stack (likely)
122 * located in this range.
123 */
124 rk_clrsetreg(SGRF_DDR_RGN_CON16, 0x1FF, 0);
Kever Yanga6697732017-05-05 11:01:43 +0800125 rk_clrreg(SGRF_SLV_SECURE_CON4, 0x2000);
Philipp Tomsich2a34cbb2017-03-29 21:20:28 +0200126
Kever Yang441a6d32017-02-23 16:09:05 +0800127 secure_timer_init();
128
129 ret = uclass_get_device(UCLASS_PINCTRL, 0, &pinctrl);
130 if (ret) {
131 debug("Pinctrl init failed: %d\n", ret);
132 return;
133 }
134
135 ret = uclass_get_device(UCLASS_RAM, 0, &dev);
136 if (ret) {
137 debug("DRAM init failed: %d\n", ret);
138 return;
139 }
140}
141
142void spl_board_init(void)
143{
144 struct udevice *pinctrl;
145 int ret;
146
147 ret = uclass_get_device(UCLASS_PINCTRL, 0, &pinctrl);
148 if (ret) {
149 debug("%s: Cannot find pinctrl device\n", __func__);
150 goto err;
151 }
152
153 /* Enable debug UART */
154 ret = pinctrl_request_noflags(pinctrl, PERIPH_ID_UART_DBG);
155 if (ret) {
156 debug("%s: Failed to set up console UART\n", __func__);
157 goto err;
158 }
159
160 preloader_console_init();
Philipp Tomsich798370f2017-06-29 11:21:15 +0200161#if CONFIG_IS_ENABLED(ROCKCHIP_BACK_TO_BROM)
Kever Yang441a6d32017-02-23 16:09:05 +0800162 back_to_bootrom();
163#endif
Philipp Tomsich2a34cbb2017-03-29 21:20:28 +0200164
Kever Yang441a6d32017-02-23 16:09:05 +0800165 return;
166err:
167 printf("spl_board_init: Error %d\n", ret);
168
169 /* No way to report error here */
170 hang();
171}
172
173#ifdef CONFIG_SPL_LOAD_FIT
174int board_fit_config_name_match(const char *name)
175{
176 /* Just empty function now - can't decide what to choose */
177 debug("%s: %s\n", __func__, name);
178
179 return 0;
180}
181#endif