blob: 3ce7e792b5a26a61bf9df09cc732b58975a87674 [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 Glass3ba929a2020-10-30 21:38:53 -060016#include <asm/global_data.h>
Kever Yang1d7cc72a2019-07-22 19:59:12 +080017#include <asm/io.h>
Simon Glass4dcacfc2020-05-10 11:40:13 -060018#include <linux/bitops.h>
Kever Yang1d7cc72a2019-07-22 19:59:12 +080019
20DECLARE_GLOBAL_DATA_PTR;
21
Peng Fanaa050c52019-08-07 06:40:53 +000022int board_return_to_bootrom(struct spl_image_info *spl_image,
23 struct spl_boot_device *bootdev)
Kever Yang1d7cc72a2019-07-22 19:59:12 +080024{
25 back_to_bootrom(BROM_BOOT_NEXTSTAGE);
Peng Fanaa050c52019-08-07 06:40:53 +000026
27 return 0;
Kever Yang1d7cc72a2019-07-22 19:59:12 +080028}
29
30__weak const char * const boot_devices[BROM_LAST_BOOTSOURCE + 1] = {
31};
32
33const char *board_spl_was_booted_from(void)
34{
Jonas Karlmana1a88d22024-03-22 20:50:21 +000035 static u32 brom_bootsource_id_cache = BROM_BOOTSOURCE_UNKNOWN;
36 u32 bootdevice_brom_id;
Kever Yang1d7cc72a2019-07-22 19:59:12 +080037 const char *bootdevice_ofpath = NULL;
38
Jonas Karlmana1a88d22024-03-22 20:50:21 +000039 if (brom_bootsource_id_cache != BROM_BOOTSOURCE_UNKNOWN)
40 bootdevice_brom_id = brom_bootsource_id_cache;
41 else
42 bootdevice_brom_id = readl(BROM_BOOTSOURCE_ID_ADDR);
43
Kever Yang1d7cc72a2019-07-22 19:59:12 +080044 if (bootdevice_brom_id < ARRAY_SIZE(boot_devices))
45 bootdevice_ofpath = boot_devices[bootdevice_brom_id];
46
Jonas Karlmana1a88d22024-03-22 20:50:21 +000047 if (bootdevice_ofpath) {
48 brom_bootsource_id_cache = bootdevice_brom_id;
Kever Yang1d7cc72a2019-07-22 19:59:12 +080049 debug("%s: brom_bootdevice_id %x maps to '%s'\n",
50 __func__, bootdevice_brom_id, bootdevice_ofpath);
Jonas Karlmana1a88d22024-03-22 20:50:21 +000051 } else {
Kever Yang1d7cc72a2019-07-22 19:59:12 +080052 debug("%s: failed to resolve brom_bootdevice_id %x\n",
53 __func__, bootdevice_brom_id);
Jonas Karlmana1a88d22024-03-22 20:50:21 +000054 }
Kever Yang1d7cc72a2019-07-22 19:59:12 +080055
56 return bootdevice_ofpath;
57}
58
59u32 spl_boot_device(void)
60{
61 u32 boot_device = BOOT_DEVICE_MMC1;
62
63#if defined(CONFIG_TARGET_CHROMEBOOK_JERRY) || \
64 defined(CONFIG_TARGET_CHROMEBIT_MICKEY) || \
Urja Rannikkoc22d8632020-05-13 19:15:20 +000065 defined(CONFIG_TARGET_CHROMEBOOK_MINNIE) || \
Simon Glass0b2f70c2020-07-19 13:55:53 -060066 defined(CONFIG_TARGET_CHROMEBOOK_SPEEDY) || \
Marty E. Plummerb20a8dac2021-12-24 16:43:46 +030067 defined(CONFIG_TARGET_CHROMEBOOK_BOB) || \
68 defined(CONFIG_TARGET_CHROMEBOOK_KEVIN)
Kever Yang1d7cc72a2019-07-22 19:59:12 +080069 return BOOT_DEVICE_SPI;
70#endif
71 if (CONFIG_IS_ENABLED(ROCKCHIP_BACK_TO_BROM))
72 return BOOT_DEVICE_BOOTROM;
73
74 return boot_device;
75}
76
Andre Przywara3cb12ef2021-07-12 11:06:49 +010077u32 spl_mmc_boot_mode(struct mmc *mmc, const u32 boot_device)
Kever Yang1d7cc72a2019-07-22 19:59:12 +080078{
79 return MMCSD_MODE_RAW;
80}
81
Kever Yang1d7cc72a2019-07-22 19:59:12 +080082#define TIMER_LOAD_COUNT_L 0x00
83#define TIMER_LOAD_COUNT_H 0x04
84#define TIMER_CONTROL_REG 0x10
85#define TIMER_EN 0x1
86#define TIMER_FMODE BIT(0)
87#define TIMER_RMODE BIT(1)
88
89__weak void rockchip_stimer_init(void)
90{
Johan Jonker87affc32022-04-09 18:55:03 +020091#if defined(CONFIG_ROCKCHIP_STIMER_BASE)
Kever Yang1d7cc72a2019-07-22 19:59:12 +080092 /* If Timer already enabled, don't re-init it */
93 u32 reg = readl(CONFIG_ROCKCHIP_STIMER_BASE + TIMER_CONTROL_REG);
94
95 if (reg & TIMER_EN)
96 return;
97#ifndef CONFIG_ARM64
98 asm volatile("mcr p15, 0, %0, c14, c0, 0"
Peng Fane7c59392022-04-13 17:47:22 +080099 : : "r"(CONFIG_COUNTER_FREQUENCY));
Kever Yang1d7cc72a2019-07-22 19:59:12 +0800100#endif
101 writel(0, CONFIG_ROCKCHIP_STIMER_BASE + TIMER_CONTROL_REG);
102 writel(0xffffffff, CONFIG_ROCKCHIP_STIMER_BASE);
103 writel(0xffffffff, CONFIG_ROCKCHIP_STIMER_BASE + 4);
104 writel(TIMER_EN | TIMER_FMODE, CONFIG_ROCKCHIP_STIMER_BASE +
105 TIMER_CONTROL_REG);
Kever Yang1d7cc72a2019-07-22 19:59:12 +0800106#endif
Johan Jonker87affc32022-04-09 18:55:03 +0200107}
Kever Yang1d7cc72a2019-07-22 19:59:12 +0800108
109__weak int board_early_init_f(void)
110{
111 return 0;
112}
113
114__weak int arch_cpu_init(void)
115{
116 return 0;
117}
118
119void board_init_f(ulong dummy)
120{
121 int ret;
Kever Yang1d7cc72a2019-07-22 19:59:12 +0800122
Kever Yang1d7cc72a2019-07-22 19:59:12 +0800123 board_early_init_f();
124
125 ret = spl_early_init();
126 if (ret) {
127 printf("spl_early_init() failed: %d\n", ret);
128 hang();
129 }
130 arch_cpu_init();
Johan Jonker87affc32022-04-09 18:55:03 +0200131
Thomas Hebb3fe4ec82019-11-15 08:48:55 -0800132 rockchip_stimer_init();
Johan Jonker87affc32022-04-09 18:55:03 +0200133
Thomas Hebb3fe4ec82019-11-15 08:48:55 -0800134#ifdef CONFIG_SYS_ARCH_TIMER
135 /* Init ARM arch timer in arch/arm/cpu/armv7/arch_timer.c */
136 timer_init();
137#endif
Heiko Stuebnerd14cd612020-05-25 19:57:24 +0200138#if !defined(CONFIG_TPL) || defined(CONFIG_SPL_RAM)
Kever Yang1d7cc72a2019-07-22 19:59:12 +0800139 debug("\nspl:init dram\n");
Heiko Stuebnerd14cd612020-05-25 19:57:24 +0200140 ret = dram_init();
Kever Yang1d7cc72a2019-07-22 19:59:12 +0800141 if (ret) {
142 printf("DRAM init failed: %d\n", ret);
143 return;
144 }
Heiko Stuebnerd14cd612020-05-25 19:57:24 +0200145 gd->ram_top = gd->ram_base + get_effective_memsize();
146 gd->ram_top = board_get_usable_ram_top(gd->ram_size);
Jonas Karlmanf582b542024-02-17 12:34:04 +0000147
148 if (IS_ENABLED(CONFIG_ARM64) && !CONFIG_IS_ENABLED(SYS_DCACHE_OFF)) {
149 gd->relocaddr = gd->ram_top;
150 arch_reserve_mmu();
151 enable_caches();
152 }
Kever Yang1d7cc72a2019-07-22 19:59:12 +0800153#endif
Kever Yang1d7cc72a2019-07-22 19:59:12 +0800154 preloader_console_init();
155}
Jonas Karlmanf582b542024-02-17 12:34:04 +0000156
157void spl_board_prepare_for_boot(void)
158{
159 if (!IS_ENABLED(CONFIG_ARM64) || CONFIG_IS_ENABLED(SYS_DCACHE_OFF))
160 return;
161
162 cleanup_before_linux();
163}