blob: f4d29bbdd17e8b57dc0b2fdd90a8600fba6ee866 [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
Jonas Karlmanf582b542024-02-17 12:34:04 +00006#include <cpu_func.h>
Kever Yang1d7cc72a2019-07-22 19:59:12 +08007#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>
Simon Glassbac075b2024-08-22 07:54:50 -060016#include <asm/arch-rockchip/timer.h>
Simon Glass3ba929a2020-10-30 21:38:53 -060017#include <asm/global_data.h>
Kever Yang1d7cc72a2019-07-22 19:59:12 +080018#include <asm/io.h>
Simon Glass4dcacfc2020-05-10 11:40:13 -060019#include <linux/bitops.h>
Kever Yang1d7cc72a2019-07-22 19:59:12 +080020
21DECLARE_GLOBAL_DATA_PTR;
22
Peng Fanaa050c52019-08-07 06:40:53 +000023int board_return_to_bootrom(struct spl_image_info *spl_image,
24 struct spl_boot_device *bootdev)
Kever Yang1d7cc72a2019-07-22 19:59:12 +080025{
26 back_to_bootrom(BROM_BOOT_NEXTSTAGE);
Peng Fanaa050c52019-08-07 06:40:53 +000027
28 return 0;
Kever Yang1d7cc72a2019-07-22 19:59:12 +080029}
30
31__weak const char * const boot_devices[BROM_LAST_BOOTSOURCE + 1] = {
32};
33
34const char *board_spl_was_booted_from(void)
35{
Jonas Karlmana1a88d22024-03-22 20:50:21 +000036 static u32 brom_bootsource_id_cache = BROM_BOOTSOURCE_UNKNOWN;
37 u32 bootdevice_brom_id;
Kever Yang1d7cc72a2019-07-22 19:59:12 +080038 const char *bootdevice_ofpath = NULL;
39
Jonas Karlmana1a88d22024-03-22 20:50:21 +000040 if (brom_bootsource_id_cache != BROM_BOOTSOURCE_UNKNOWN)
41 bootdevice_brom_id = brom_bootsource_id_cache;
42 else
43 bootdevice_brom_id = readl(BROM_BOOTSOURCE_ID_ADDR);
44
Kever Yang1d7cc72a2019-07-22 19:59:12 +080045 if (bootdevice_brom_id < ARRAY_SIZE(boot_devices))
46 bootdevice_ofpath = boot_devices[bootdevice_brom_id];
47
Jonas Karlmana1a88d22024-03-22 20:50:21 +000048 if (bootdevice_ofpath) {
49 brom_bootsource_id_cache = bootdevice_brom_id;
Kever Yang1d7cc72a2019-07-22 19:59:12 +080050 debug("%s: brom_bootdevice_id %x maps to '%s'\n",
51 __func__, bootdevice_brom_id, bootdevice_ofpath);
Jonas Karlmana1a88d22024-03-22 20:50:21 +000052 } else {
Kever Yang1d7cc72a2019-07-22 19:59:12 +080053 debug("%s: failed to resolve brom_bootdevice_id %x\n",
54 __func__, bootdevice_brom_id);
Jonas Karlmana1a88d22024-03-22 20:50:21 +000055 }
Kever Yang1d7cc72a2019-07-22 19:59:12 +080056
57 return bootdevice_ofpath;
58}
59
60u32 spl_boot_device(void)
61{
62 u32 boot_device = BOOT_DEVICE_MMC1;
63
64#if defined(CONFIG_TARGET_CHROMEBOOK_JERRY) || \
65 defined(CONFIG_TARGET_CHROMEBIT_MICKEY) || \
Urja Rannikkoc22d8632020-05-13 19:15:20 +000066 defined(CONFIG_TARGET_CHROMEBOOK_MINNIE) || \
Simon Glass0b2f70c2020-07-19 13:55:53 -060067 defined(CONFIG_TARGET_CHROMEBOOK_SPEEDY) || \
Marty E. Plummerb20a8dac2021-12-24 16:43:46 +030068 defined(CONFIG_TARGET_CHROMEBOOK_BOB) || \
69 defined(CONFIG_TARGET_CHROMEBOOK_KEVIN)
Kever Yang1d7cc72a2019-07-22 19:59:12 +080070 return BOOT_DEVICE_SPI;
71#endif
72 if (CONFIG_IS_ENABLED(ROCKCHIP_BACK_TO_BROM))
73 return BOOT_DEVICE_BOOTROM;
74
75 return boot_device;
76}
77
Andre Przywara3cb12ef2021-07-12 11:06:49 +010078u32 spl_mmc_boot_mode(struct mmc *mmc, const u32 boot_device)
Kever Yang1d7cc72a2019-07-22 19:59:12 +080079{
80 return MMCSD_MODE_RAW;
81}
82
Kever Yang1d7cc72a2019-07-22 19:59:12 +080083__weak int board_early_init_f(void)
84{
85 return 0;
86}
87
88__weak int arch_cpu_init(void)
89{
90 return 0;
91}
92
93void board_init_f(ulong dummy)
94{
95 int ret;
Kever Yang1d7cc72a2019-07-22 19:59:12 +080096
Kever Yang1d7cc72a2019-07-22 19:59:12 +080097 board_early_init_f();
98
99 ret = spl_early_init();
100 if (ret) {
101 printf("spl_early_init() failed: %d\n", ret);
102 hang();
103 }
104 arch_cpu_init();
Johan Jonker87affc32022-04-09 18:55:03 +0200105
Thomas Hebb3fe4ec82019-11-15 08:48:55 -0800106 rockchip_stimer_init();
Johan Jonker87affc32022-04-09 18:55:03 +0200107
Thomas Hebb3fe4ec82019-11-15 08:48:55 -0800108#ifdef CONFIG_SYS_ARCH_TIMER
109 /* Init ARM arch timer in arch/arm/cpu/armv7/arch_timer.c */
110 timer_init();
111#endif
Heiko Stuebnerd14cd612020-05-25 19:57:24 +0200112#if !defined(CONFIG_TPL) || defined(CONFIG_SPL_RAM)
Kever Yang1d7cc72a2019-07-22 19:59:12 +0800113 debug("\nspl:init dram\n");
Heiko Stuebnerd14cd612020-05-25 19:57:24 +0200114 ret = dram_init();
Kever Yang1d7cc72a2019-07-22 19:59:12 +0800115 if (ret) {
116 printf("DRAM init failed: %d\n", ret);
117 return;
118 }
Heiko Stuebnerd14cd612020-05-25 19:57:24 +0200119 gd->ram_top = gd->ram_base + get_effective_memsize();
120 gd->ram_top = board_get_usable_ram_top(gd->ram_size);
Jonas Karlmanf582b542024-02-17 12:34:04 +0000121
122 if (IS_ENABLED(CONFIG_ARM64) && !CONFIG_IS_ENABLED(SYS_DCACHE_OFF)) {
123 gd->relocaddr = gd->ram_top;
124 arch_reserve_mmu();
125 enable_caches();
126 }
Kever Yang1d7cc72a2019-07-22 19:59:12 +0800127#endif
Kever Yang1d7cc72a2019-07-22 19:59:12 +0800128 preloader_console_init();
129}
Jonas Karlmanf582b542024-02-17 12:34:04 +0000130
131void spl_board_prepare_for_boot(void)
132{
133 if (!IS_ENABLED(CONFIG_ARM64) || CONFIG_IS_ENABLED(SYS_DCACHE_OFF))
134 return;
135
136 cleanup_before_linux();
137}