blob: f5a0ac473b7a18ea9b9422000705ef10dee3986a [file] [log] [blame]
Kever Yang1d7cc72a2019-07-22 19:59:12 +08001// SPDX-License-Identifier: GPL-2.0+
2/*
3 * (C) Copyright 2019 Rockchip Electronics Co., Ltd
4 */
5
6#include <common.h>
7#include <debug_uart.h>
8#include <dm.h>
Simon Glassf11478f2019-12-28 10:45:07 -07009#include <hang.h>
Simon Glass2dc9c342020-05-10 11:40:01 -060010#include <image.h>
Simon Glass97589732020-05-10 11:40:02 -060011#include <init.h>
Simon Glass0f2af882020-05-10 11:40:05 -060012#include <log.h>
Kever Yang1d7cc72a2019-07-22 19:59:12 +080013#include <ram.h>
14#include <spl.h>
15#include <asm/arch-rockchip/bootrom.h>
Kever Yang1d7cc72a2019-07-22 19:59:12 +080016#include <asm/io.h>
17
18DECLARE_GLOBAL_DATA_PTR;
19
Peng Fanaa050c52019-08-07 06:40:53 +000020int board_return_to_bootrom(struct spl_image_info *spl_image,
21 struct spl_boot_device *bootdev)
Kever Yang1d7cc72a2019-07-22 19:59:12 +080022{
23 back_to_bootrom(BROM_BOOT_NEXTSTAGE);
Peng Fanaa050c52019-08-07 06:40:53 +000024
25 return 0;
Kever Yang1d7cc72a2019-07-22 19:59:12 +080026}
27
28__weak const char * const boot_devices[BROM_LAST_BOOTSOURCE + 1] = {
29};
30
31const char *board_spl_was_booted_from(void)
32{
33 u32 bootdevice_brom_id = readl(BROM_BOOTSOURCE_ID_ADDR);
34 const char *bootdevice_ofpath = NULL;
35
36 if (bootdevice_brom_id < ARRAY_SIZE(boot_devices))
37 bootdevice_ofpath = boot_devices[bootdevice_brom_id];
38
39 if (bootdevice_ofpath)
40 debug("%s: brom_bootdevice_id %x maps to '%s'\n",
41 __func__, bootdevice_brom_id, bootdevice_ofpath);
42 else
43 debug("%s: failed to resolve brom_bootdevice_id %x\n",
44 __func__, bootdevice_brom_id);
45
46 return bootdevice_ofpath;
47}
48
49u32 spl_boot_device(void)
50{
51 u32 boot_device = BOOT_DEVICE_MMC1;
52
53#if defined(CONFIG_TARGET_CHROMEBOOK_JERRY) || \
54 defined(CONFIG_TARGET_CHROMEBIT_MICKEY) || \
55 defined(CONFIG_TARGET_CHROMEBOOK_MINNIE)
56 return BOOT_DEVICE_SPI;
57#endif
58 if (CONFIG_IS_ENABLED(ROCKCHIP_BACK_TO_BROM))
59 return BOOT_DEVICE_BOOTROM;
60
61 return boot_device;
62}
63
Harald Seiler0bf7ab12020-04-15 11:33:30 +020064u32 spl_mmc_boot_mode(const u32 boot_device)
Kever Yang1d7cc72a2019-07-22 19:59:12 +080065{
66 return MMCSD_MODE_RAW;
67}
68
69#if !defined(CONFIG_ROCKCHIP_RK3188)
70#define TIMER_LOAD_COUNT_L 0x00
71#define TIMER_LOAD_COUNT_H 0x04
72#define TIMER_CONTROL_REG 0x10
73#define TIMER_EN 0x1
74#define TIMER_FMODE BIT(0)
75#define TIMER_RMODE BIT(1)
76
77__weak void rockchip_stimer_init(void)
78{
79 /* If Timer already enabled, don't re-init it */
80 u32 reg = readl(CONFIG_ROCKCHIP_STIMER_BASE + TIMER_CONTROL_REG);
81
82 if (reg & TIMER_EN)
83 return;
84#ifndef CONFIG_ARM64
85 asm volatile("mcr p15, 0, %0, c14, c0, 0"
86 : : "r"(COUNTER_FREQUENCY));
87#endif
88 writel(0, CONFIG_ROCKCHIP_STIMER_BASE + TIMER_CONTROL_REG);
89 writel(0xffffffff, CONFIG_ROCKCHIP_STIMER_BASE);
90 writel(0xffffffff, CONFIG_ROCKCHIP_STIMER_BASE + 4);
91 writel(TIMER_EN | TIMER_FMODE, CONFIG_ROCKCHIP_STIMER_BASE +
92 TIMER_CONTROL_REG);
93}
94#endif
95
96__weak int board_early_init_f(void)
97{
98 return 0;
99}
100
101__weak int arch_cpu_init(void)
102{
103 return 0;
104}
105
106void board_init_f(ulong dummy)
107{
108 int ret;
Thomas Hebb14ac1242019-11-15 08:48:56 -0800109#if !defined(CONFIG_TPL) || defined(CONFIG_SPL_OS_BOOT)
Kever Yang1d7cc72a2019-07-22 19:59:12 +0800110 struct udevice *dev;
111#endif
112
113#ifdef CONFIG_DEBUG_UART
114 /*
115 * Debug UART can be used from here if required:
116 *
117 * debug_uart_init();
118 * printch('a');
119 * printhex8(0x1234);
120 * printascii("string");
121 */
122 debug_uart_init();
123 debug("\nspl:debug uart enabled in %s\n", __func__);
124#endif
125
126 board_early_init_f();
127
128 ret = spl_early_init();
129 if (ret) {
130 printf("spl_early_init() failed: %d\n", ret);
131 hang();
132 }
133 arch_cpu_init();
Thomas Hebb3fe4ec82019-11-15 08:48:55 -0800134#if !defined(CONFIG_ROCKCHIP_RK3188)
135 rockchip_stimer_init();
136#endif
137#ifdef CONFIG_SYS_ARCH_TIMER
138 /* Init ARM arch timer in arch/arm/cpu/armv7/arch_timer.c */
139 timer_init();
140#endif
Thomas Hebb14ac1242019-11-15 08:48:56 -0800141#if !defined(CONFIG_TPL) || defined(CONFIG_SPL_OS_BOOT)
Kever Yang1d7cc72a2019-07-22 19:59:12 +0800142 debug("\nspl:init dram\n");
143 ret = uclass_get_device(UCLASS_RAM, 0, &dev);
144 if (ret) {
145 printf("DRAM init failed: %d\n", ret);
146 return;
147 }
148#endif
Kever Yang1d7cc72a2019-07-22 19:59:12 +0800149 preloader_console_init();
150}
151
152#ifdef CONFIG_SPL_LOAD_FIT
Heiko Stuebner7d110942020-01-17 21:37:09 +0100153int __weak board_fit_config_name_match(const char *name)
Kever Yang1d7cc72a2019-07-22 19:59:12 +0800154{
155 /* Just empty function now - can't decide what to choose */
156 debug("%s: %s\n", __func__, name);
157
158 return 0;
159}
160#endif