blob: 0d74989adbaed7f23c89ae83f54e00aa27b6d8cc [file] [log] [blame]
Kever Yang49105fb2019-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 Glassdb41d652019-12-28 10:45:07 -07009#include <hang.h>
Simon Glass4d72caa2020-05-10 11:40:01 -060010#include <image.h>
Simon Glass691d7192020-05-10 11:40:02 -060011#include <init.h>
Kever Yang49105fb2019-07-22 19:59:12 +080012#include <ram.h>
13#include <spl.h>
14#include <asm/arch-rockchip/bootrom.h>
Kever Yang49105fb2019-07-22 19:59:12 +080015#include <asm/io.h>
16
17DECLARE_GLOBAL_DATA_PTR;
18
Peng Fancda789a2019-08-07 06:40:53 +000019int board_return_to_bootrom(struct spl_image_info *spl_image,
20 struct spl_boot_device *bootdev)
Kever Yang49105fb2019-07-22 19:59:12 +080021{
22 back_to_bootrom(BROM_BOOT_NEXTSTAGE);
Peng Fancda789a2019-08-07 06:40:53 +000023
24 return 0;
Kever Yang49105fb2019-07-22 19:59:12 +080025}
26
27__weak const char * const boot_devices[BROM_LAST_BOOTSOURCE + 1] = {
28};
29
30const char *board_spl_was_booted_from(void)
31{
32 u32 bootdevice_brom_id = readl(BROM_BOOTSOURCE_ID_ADDR);
33 const char *bootdevice_ofpath = NULL;
34
35 if (bootdevice_brom_id < ARRAY_SIZE(boot_devices))
36 bootdevice_ofpath = boot_devices[bootdevice_brom_id];
37
38 if (bootdevice_ofpath)
39 debug("%s: brom_bootdevice_id %x maps to '%s'\n",
40 __func__, bootdevice_brom_id, bootdevice_ofpath);
41 else
42 debug("%s: failed to resolve brom_bootdevice_id %x\n",
43 __func__, bootdevice_brom_id);
44
45 return bootdevice_ofpath;
46}
47
48u32 spl_boot_device(void)
49{
50 u32 boot_device = BOOT_DEVICE_MMC1;
51
52#if defined(CONFIG_TARGET_CHROMEBOOK_JERRY) || \
53 defined(CONFIG_TARGET_CHROMEBIT_MICKEY) || \
54 defined(CONFIG_TARGET_CHROMEBOOK_MINNIE)
55 return BOOT_DEVICE_SPI;
56#endif
57 if (CONFIG_IS_ENABLED(ROCKCHIP_BACK_TO_BROM))
58 return BOOT_DEVICE_BOOTROM;
59
60 return boot_device;
61}
62
Harald Seilere9759062020-04-15 11:33:30 +020063u32 spl_mmc_boot_mode(const u32 boot_device)
Kever Yang49105fb2019-07-22 19:59:12 +080064{
65 return MMCSD_MODE_RAW;
66}
67
68#if !defined(CONFIG_ROCKCHIP_RK3188)
69#define TIMER_LOAD_COUNT_L 0x00
70#define TIMER_LOAD_COUNT_H 0x04
71#define TIMER_CONTROL_REG 0x10
72#define TIMER_EN 0x1
73#define TIMER_FMODE BIT(0)
74#define TIMER_RMODE BIT(1)
75
76__weak void rockchip_stimer_init(void)
77{
78 /* If Timer already enabled, don't re-init it */
79 u32 reg = readl(CONFIG_ROCKCHIP_STIMER_BASE + TIMER_CONTROL_REG);
80
81 if (reg & TIMER_EN)
82 return;
83#ifndef CONFIG_ARM64
84 asm volatile("mcr p15, 0, %0, c14, c0, 0"
85 : : "r"(COUNTER_FREQUENCY));
86#endif
87 writel(0, CONFIG_ROCKCHIP_STIMER_BASE + TIMER_CONTROL_REG);
88 writel(0xffffffff, CONFIG_ROCKCHIP_STIMER_BASE);
89 writel(0xffffffff, CONFIG_ROCKCHIP_STIMER_BASE + 4);
90 writel(TIMER_EN | TIMER_FMODE, CONFIG_ROCKCHIP_STIMER_BASE +
91 TIMER_CONTROL_REG);
92}
93#endif
94
95__weak int board_early_init_f(void)
96{
97 return 0;
98}
99
100__weak int arch_cpu_init(void)
101{
102 return 0;
103}
104
105void board_init_f(ulong dummy)
106{
107 int ret;
Thomas Hebb857d6382019-11-15 08:48:56 -0800108#if !defined(CONFIG_TPL) || defined(CONFIG_SPL_OS_BOOT)
Kever Yang49105fb2019-07-22 19:59:12 +0800109 struct udevice *dev;
110#endif
111
112#ifdef CONFIG_DEBUG_UART
113 /*
114 * Debug UART can be used from here if required:
115 *
116 * debug_uart_init();
117 * printch('a');
118 * printhex8(0x1234);
119 * printascii("string");
120 */
121 debug_uart_init();
122 debug("\nspl:debug uart enabled in %s\n", __func__);
123#endif
124
125 board_early_init_f();
126
127 ret = spl_early_init();
128 if (ret) {
129 printf("spl_early_init() failed: %d\n", ret);
130 hang();
131 }
132 arch_cpu_init();
Thomas Hebb220697a2019-11-15 08:48:55 -0800133#if !defined(CONFIG_ROCKCHIP_RK3188)
134 rockchip_stimer_init();
135#endif
136#ifdef CONFIG_SYS_ARCH_TIMER
137 /* Init ARM arch timer in arch/arm/cpu/armv7/arch_timer.c */
138 timer_init();
139#endif
Thomas Hebb857d6382019-11-15 08:48:56 -0800140#if !defined(CONFIG_TPL) || defined(CONFIG_SPL_OS_BOOT)
Kever Yang49105fb2019-07-22 19:59:12 +0800141 debug("\nspl:init dram\n");
142 ret = uclass_get_device(UCLASS_RAM, 0, &dev);
143 if (ret) {
144 printf("DRAM init failed: %d\n", ret);
145 return;
146 }
147#endif
Kever Yang49105fb2019-07-22 19:59:12 +0800148 preloader_console_init();
149}
150
151#ifdef CONFIG_SPL_LOAD_FIT
Heiko Stuebner552e7cc2020-01-17 21:37:09 +0100152int __weak board_fit_config_name_match(const char *name)
Kever Yang49105fb2019-07-22 19:59:12 +0800153{
154 /* Just empty function now - can't decide what to choose */
155 debug("%s: %s\n", __func__, name);
156
157 return 0;
158}
159#endif