blob: 46b32eb345845d2eae6889bcdb798b82cf7c4c86 [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>
Simon Glassf7ae49f2020-05-10 11:40:05 -060012#include <log.h>
Kever Yang49105fb2019-07-22 19:59:12 +080013#include <ram.h>
14#include <spl.h>
15#include <asm/arch-rockchip/bootrom.h>
Kever Yang49105fb2019-07-22 19:59:12 +080016#include <asm/io.h>
Simon Glasscd93d622020-05-10 11:40:13 -060017#include <linux/bitops.h>
Kever Yang49105fb2019-07-22 19:59:12 +080018
19DECLARE_GLOBAL_DATA_PTR;
20
Peng Fancda789a2019-08-07 06:40:53 +000021int board_return_to_bootrom(struct spl_image_info *spl_image,
22 struct spl_boot_device *bootdev)
Kever Yang49105fb2019-07-22 19:59:12 +080023{
24 back_to_bootrom(BROM_BOOT_NEXTSTAGE);
Peng Fancda789a2019-08-07 06:40:53 +000025
26 return 0;
Kever Yang49105fb2019-07-22 19:59:12 +080027}
28
29__weak const char * const boot_devices[BROM_LAST_BOOTSOURCE + 1] = {
30};
31
32const char *board_spl_was_booted_from(void)
33{
34 u32 bootdevice_brom_id = readl(BROM_BOOTSOURCE_ID_ADDR);
35 const char *bootdevice_ofpath = NULL;
36
37 if (bootdevice_brom_id < ARRAY_SIZE(boot_devices))
38 bootdevice_ofpath = boot_devices[bootdevice_brom_id];
39
40 if (bootdevice_ofpath)
41 debug("%s: brom_bootdevice_id %x maps to '%s'\n",
42 __func__, bootdevice_brom_id, bootdevice_ofpath);
43 else
44 debug("%s: failed to resolve brom_bootdevice_id %x\n",
45 __func__, bootdevice_brom_id);
46
47 return bootdevice_ofpath;
48}
49
50u32 spl_boot_device(void)
51{
52 u32 boot_device = BOOT_DEVICE_MMC1;
53
54#if defined(CONFIG_TARGET_CHROMEBOOK_JERRY) || \
55 defined(CONFIG_TARGET_CHROMEBIT_MICKEY) || \
Urja Rannikko353ad952020-05-13 19:15:20 +000056 defined(CONFIG_TARGET_CHROMEBOOK_MINNIE) || \
57 defined(CONFIG_TARGET_CHROMEBOOK_SPEEDY)
Kever Yang49105fb2019-07-22 19:59:12 +080058 return BOOT_DEVICE_SPI;
59#endif
60 if (CONFIG_IS_ENABLED(ROCKCHIP_BACK_TO_BROM))
61 return BOOT_DEVICE_BOOTROM;
62
63 return boot_device;
64}
65
Harald Seilere9759062020-04-15 11:33:30 +020066u32 spl_mmc_boot_mode(const u32 boot_device)
Kever Yang49105fb2019-07-22 19:59:12 +080067{
68 return MMCSD_MODE_RAW;
69}
70
71#if !defined(CONFIG_ROCKCHIP_RK3188)
72#define TIMER_LOAD_COUNT_L 0x00
73#define TIMER_LOAD_COUNT_H 0x04
74#define TIMER_CONTROL_REG 0x10
75#define TIMER_EN 0x1
76#define TIMER_FMODE BIT(0)
77#define TIMER_RMODE BIT(1)
78
79__weak void rockchip_stimer_init(void)
80{
81 /* If Timer already enabled, don't re-init it */
82 u32 reg = readl(CONFIG_ROCKCHIP_STIMER_BASE + TIMER_CONTROL_REG);
83
84 if (reg & TIMER_EN)
85 return;
86#ifndef CONFIG_ARM64
87 asm volatile("mcr p15, 0, %0, c14, c0, 0"
88 : : "r"(COUNTER_FREQUENCY));
89#endif
90 writel(0, CONFIG_ROCKCHIP_STIMER_BASE + TIMER_CONTROL_REG);
91 writel(0xffffffff, CONFIG_ROCKCHIP_STIMER_BASE);
92 writel(0xffffffff, CONFIG_ROCKCHIP_STIMER_BASE + 4);
93 writel(TIMER_EN | TIMER_FMODE, CONFIG_ROCKCHIP_STIMER_BASE +
94 TIMER_CONTROL_REG);
95}
96#endif
97
98__weak int board_early_init_f(void)
99{
100 return 0;
101}
102
103__weak int arch_cpu_init(void)
104{
105 return 0;
106}
107
108void board_init_f(ulong dummy)
109{
110 int ret;
Thomas Hebb857d6382019-11-15 08:48:56 -0800111#if !defined(CONFIG_TPL) || defined(CONFIG_SPL_OS_BOOT)
Kever Yang49105fb2019-07-22 19:59:12 +0800112 struct udevice *dev;
113#endif
114
115#ifdef CONFIG_DEBUG_UART
116 /*
117 * Debug UART can be used from here if required:
118 *
119 * debug_uart_init();
120 * printch('a');
121 * printhex8(0x1234);
122 * printascii("string");
123 */
124 debug_uart_init();
125 debug("\nspl:debug uart enabled in %s\n", __func__);
126#endif
127
128 board_early_init_f();
129
130 ret = spl_early_init();
131 if (ret) {
132 printf("spl_early_init() failed: %d\n", ret);
133 hang();
134 }
135 arch_cpu_init();
Thomas Hebb220697a2019-11-15 08:48:55 -0800136#if !defined(CONFIG_ROCKCHIP_RK3188)
137 rockchip_stimer_init();
138#endif
139#ifdef CONFIG_SYS_ARCH_TIMER
140 /* Init ARM arch timer in arch/arm/cpu/armv7/arch_timer.c */
141 timer_init();
142#endif
Thomas Hebb857d6382019-11-15 08:48:56 -0800143#if !defined(CONFIG_TPL) || defined(CONFIG_SPL_OS_BOOT)
Kever Yang49105fb2019-07-22 19:59:12 +0800144 debug("\nspl:init dram\n");
145 ret = uclass_get_device(UCLASS_RAM, 0, &dev);
146 if (ret) {
147 printf("DRAM init failed: %d\n", ret);
148 return;
149 }
150#endif
Kever Yang49105fb2019-07-22 19:59:12 +0800151 preloader_console_init();
152}
153
154#ifdef CONFIG_SPL_LOAD_FIT
Heiko Stuebner552e7cc2020-01-17 21:37:09 +0100155int __weak board_fit_config_name_match(const char *name)
Kever Yang49105fb2019-07-22 19:59:12 +0800156{
157 /* Just empty function now - can't decide what to choose */
158 debug("%s: %s\n", __func__, name);
159
160 return 0;
161}
162#endif