blob: 02c40fb37ed64d78a6f5b5e077f39d3076972a8b [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>
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{
35 u32 bootdevice_brom_id = readl(BROM_BOOTSOURCE_ID_ADDR);
36 const char *bootdevice_ofpath = NULL;
37
38 if (bootdevice_brom_id < ARRAY_SIZE(boot_devices))
39 bootdevice_ofpath = boot_devices[bootdevice_brom_id];
40
41 if (bootdevice_ofpath)
42 debug("%s: brom_bootdevice_id %x maps to '%s'\n",
43 __func__, bootdevice_brom_id, bootdevice_ofpath);
44 else
45 debug("%s: failed to resolve brom_bootdevice_id %x\n",
46 __func__, bootdevice_brom_id);
47
48 return bootdevice_ofpath;
49}
50
51u32 spl_boot_device(void)
52{
53 u32 boot_device = BOOT_DEVICE_MMC1;
54
55#if defined(CONFIG_TARGET_CHROMEBOOK_JERRY) || \
56 defined(CONFIG_TARGET_CHROMEBIT_MICKEY) || \
Urja Rannikkoc22d8632020-05-13 19:15:20 +000057 defined(CONFIG_TARGET_CHROMEBOOK_MINNIE) || \
Simon Glass0b2f70c2020-07-19 13:55:53 -060058 defined(CONFIG_TARGET_CHROMEBOOK_SPEEDY) || \
59 defined(CONFIG_TARGET_CHROMEBOOK_BOB)
Kever Yang1d7cc72a2019-07-22 19:59:12 +080060 return BOOT_DEVICE_SPI;
61#endif
62 if (CONFIG_IS_ENABLED(ROCKCHIP_BACK_TO_BROM))
63 return BOOT_DEVICE_BOOTROM;
64
65 return boot_device;
66}
67
Harald Seiler0bf7ab12020-04-15 11:33:30 +020068u32 spl_mmc_boot_mode(const u32 boot_device)
Kever Yang1d7cc72a2019-07-22 19:59:12 +080069{
70 return MMCSD_MODE_RAW;
71}
72
73#if !defined(CONFIG_ROCKCHIP_RK3188)
74#define TIMER_LOAD_COUNT_L 0x00
75#define TIMER_LOAD_COUNT_H 0x04
76#define TIMER_CONTROL_REG 0x10
77#define TIMER_EN 0x1
78#define TIMER_FMODE BIT(0)
79#define TIMER_RMODE BIT(1)
80
81__weak void rockchip_stimer_init(void)
82{
83 /* If Timer already enabled, don't re-init it */
84 u32 reg = readl(CONFIG_ROCKCHIP_STIMER_BASE + TIMER_CONTROL_REG);
85
86 if (reg & TIMER_EN)
87 return;
88#ifndef CONFIG_ARM64
89 asm volatile("mcr p15, 0, %0, c14, c0, 0"
90 : : "r"(COUNTER_FREQUENCY));
91#endif
92 writel(0, CONFIG_ROCKCHIP_STIMER_BASE + TIMER_CONTROL_REG);
93 writel(0xffffffff, CONFIG_ROCKCHIP_STIMER_BASE);
94 writel(0xffffffff, CONFIG_ROCKCHIP_STIMER_BASE + 4);
95 writel(TIMER_EN | TIMER_FMODE, CONFIG_ROCKCHIP_STIMER_BASE +
96 TIMER_CONTROL_REG);
97}
98#endif
99
100__weak int board_early_init_f(void)
101{
102 return 0;
103}
104
105__weak int arch_cpu_init(void)
106{
107 return 0;
108}
109
110void board_init_f(ulong dummy)
111{
112 int ret;
Kever Yang1d7cc72a2019-07-22 19:59:12 +0800113
114#ifdef CONFIG_DEBUG_UART
115 /*
116 * Debug UART can be used from here if required:
117 *
118 * debug_uart_init();
119 * printch('a');
120 * printhex8(0x1234);
121 * printascii("string");
122 */
123 debug_uart_init();
124 debug("\nspl:debug uart enabled in %s\n", __func__);
125#endif
126
127 board_early_init_f();
128
129 ret = spl_early_init();
130 if (ret) {
131 printf("spl_early_init() failed: %d\n", ret);
132 hang();
133 }
134 arch_cpu_init();
Thomas Hebb3fe4ec82019-11-15 08:48:55 -0800135#if !defined(CONFIG_ROCKCHIP_RK3188)
136 rockchip_stimer_init();
137#endif
138#ifdef CONFIG_SYS_ARCH_TIMER
139 /* Init ARM arch timer in arch/arm/cpu/armv7/arch_timer.c */
140 timer_init();
141#endif
Heiko Stuebnerd14cd612020-05-25 19:57:24 +0200142#if !defined(CONFIG_TPL) || defined(CONFIG_SPL_RAM)
Kever Yang1d7cc72a2019-07-22 19:59:12 +0800143 debug("\nspl:init dram\n");
Heiko Stuebnerd14cd612020-05-25 19:57:24 +0200144 ret = dram_init();
Kever Yang1d7cc72a2019-07-22 19:59:12 +0800145 if (ret) {
146 printf("DRAM init failed: %d\n", ret);
147 return;
148 }
Heiko Stuebnerd14cd612020-05-25 19:57:24 +0200149 gd->ram_top = gd->ram_base + get_effective_memsize();
150 gd->ram_top = board_get_usable_ram_top(gd->ram_size);
Kever Yang1d7cc72a2019-07-22 19:59:12 +0800151#endif
Kever Yang1d7cc72a2019-07-22 19:59:12 +0800152 preloader_console_init();
153}