blob: fdd0c592b3eb9e43a7a7f1b21d17c383dbca73da [file] [log] [blame]
Kever Yang18f85082019-07-09 22:05:55 +08001// SPDX-License-Identifier: GPL-2.0+
2/*
3 * (C) Copyright 2019 Rockchip Electronics Co., Ltd
4 */
5
6#include <common.h>
Simon Glassb2412dd2023-01-07 14:57:30 -07007#include <bootstage.h>
Kever Yang18f85082019-07-09 22:05:55 +08008#include <debug_uart.h>
9#include <dm.h>
Simon Glassdb41d652019-12-28 10:45:07 -070010#include <hang.h>
Simon Glass691d7192020-05-10 11:40:02 -060011#include <init.h>
Simon Glassf7ae49f2020-05-10 11:40:05 -060012#include <log.h>
Kever Yang18f85082019-07-09 22:05:55 +080013#include <ram.h>
14#include <spl.h>
15#include <version.h>
16#include <asm/io.h>
17#include <asm/arch-rockchip/bootrom.h>
Simon Glasscd93d622020-05-10 11:40:13 -060018#include <linux/bitops.h>
Johan Jonker30a7b822022-04-09 18:55:05 +020019#include <linux/kconfig.h>
Kever Yang18f85082019-07-09 22:05:55 +080020
Pali Rohár121a1652021-08-02 15:18:38 +020021#if CONFIG_IS_ENABLED(BANNER_PRINT)
22#include <timestamp.h>
23#endif
24
Kever Yang18f85082019-07-09 22:05:55 +080025#define TIMER_LOAD_COUNT_L 0x00
26#define TIMER_LOAD_COUNT_H 0x04
27#define TIMER_CONTROL_REG 0x10
28#define TIMER_EN 0x1
29#define TIMER_FMODE BIT(0)
30#define TIMER_RMODE BIT(1)
31
32__weak void rockchip_stimer_init(void)
33{
Johan Jonkerd23f55d2022-04-09 18:55:04 +020034#if defined(CONFIG_ROCKCHIP_STIMER_BASE)
Kever Yang18f85082019-07-09 22:05:55 +080035 /* If Timer already enabled, don't re-init it */
36 u32 reg = readl(CONFIG_ROCKCHIP_STIMER_BASE + TIMER_CONTROL_REG);
37
38 if (reg & TIMER_EN)
39 return;
40
41#ifndef CONFIG_ARM64
42 asm volatile("mcr p15, 0, %0, c14, c0, 0"
Peng Fan151a0302022-04-13 17:47:22 +080043 : : "r"(CONFIG_COUNTER_FREQUENCY));
Kever Yang18f85082019-07-09 22:05:55 +080044#endif
45
46 writel(0, CONFIG_ROCKCHIP_STIMER_BASE + TIMER_CONTROL_REG);
47 writel(0xffffffff, CONFIG_ROCKCHIP_STIMER_BASE);
48 writel(0xffffffff, CONFIG_ROCKCHIP_STIMER_BASE + 4);
49 writel(TIMER_EN | TIMER_FMODE, CONFIG_ROCKCHIP_STIMER_BASE +
50 TIMER_CONTROL_REG);
Johan Jonkerd23f55d2022-04-09 18:55:04 +020051#endif
Kever Yang18f85082019-07-09 22:05:55 +080052}
53
54void board_init_f(ulong dummy)
55{
56 struct udevice *dev;
57 int ret;
58
Simon Glass2a736062021-08-08 12:20:12 -060059#if defined(CONFIG_DEBUG_UART) && defined(CONFIG_TPL_SERIAL)
Kever Yang18f85082019-07-09 22:05:55 +080060 /*
61 * Debug UART can be used from here if required:
62 *
63 * debug_uart_init();
64 * printch('a');
65 * printhex8(0x1234);
66 * printascii("string");
67 */
68 debug_uart_init();
Chris Webb89e39172019-07-19 14:23:55 +010069#ifdef CONFIG_TPL_BANNER_PRINT
Kever Yang18f85082019-07-09 22:05:55 +080070 printascii("\nU-Boot TPL " PLAIN_VERSION " (" U_BOOT_DATE " - " \
71 U_BOOT_TIME ")\n");
72#endif
Chris Webb89e39172019-07-19 14:23:55 +010073#endif
Simon Glassb2412dd2023-01-07 14:57:30 -070074 /* Init secure timer */
75 rockchip_stimer_init();
76
Kever Yang18f85082019-07-09 22:05:55 +080077 ret = spl_early_init();
78 if (ret) {
79 debug("spl_early_init() failed: %d\n", ret);
80 hang();
81 }
82
Johan Jonker30a7b822022-04-09 18:55:05 +020083 /* Init ARM arch timer */
84 if (IS_ENABLED(CONFIG_SYS_ARCH_TIMER))
85 timer_init();
Kever Yang18f85082019-07-09 22:05:55 +080086
87 ret = uclass_get_device(UCLASS_RAM, 0, &dev);
88 if (ret) {
89 printf("DRAM init failed: %d\n", ret);
90 return;
91 }
92}
93
Peng Fancda789a2019-08-07 06:40:53 +000094int board_return_to_bootrom(struct spl_image_info *spl_image,
95 struct spl_boot_device *bootdev)
Kever Yang18f85082019-07-09 22:05:55 +080096{
Simon Glassb2412dd2023-01-07 14:57:30 -070097#ifdef CONFIG_BOOTSTAGE_STASH
98 int ret;
99
100 bootstage_mark_name(BOOTSTAGE_ID_END_TPL, "end tpl");
101 ret = bootstage_stash((void *)CONFIG_BOOTSTAGE_STASH_ADDR,
102 CONFIG_BOOTSTAGE_STASH_SIZE);
103 if (ret)
104 debug("Failed to stash bootstage: err=%d\n", ret);
105#endif
Kever Yang18f85082019-07-09 22:05:55 +0800106 back_to_bootrom(BROM_BOOT_NEXTSTAGE);
Peng Fancda789a2019-08-07 06:40:53 +0000107
108 return 0;
Kever Yang18f85082019-07-09 22:05:55 +0800109}
110
111u32 spl_boot_device(void)
112{
113 return BOOT_DEVICE_BOOTROM;
114}