blob: c3734cb07082a358de11bca738f0c3bac0bced13 [file] [log] [blame]
Kever Yang34ead0f2019-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>
7#include <debug_uart.h>
8#include <dm.h>
9#include <ram.h>
10#include <spl.h>
11#include <version.h>
12#include <asm/io.h>
13#include <asm/arch-rockchip/bootrom.h>
14
15#define TIMER_LOAD_COUNT_L 0x00
16#define TIMER_LOAD_COUNT_H 0x04
17#define TIMER_CONTROL_REG 0x10
18#define TIMER_EN 0x1
19#define TIMER_FMODE BIT(0)
20#define TIMER_RMODE BIT(1)
21
22__weak void rockchip_stimer_init(void)
23{
24 /* If Timer already enabled, don't re-init it */
25 u32 reg = readl(CONFIG_ROCKCHIP_STIMER_BASE + TIMER_CONTROL_REG);
26
27 if (reg & TIMER_EN)
28 return;
29
30#ifndef CONFIG_ARM64
31 asm volatile("mcr p15, 0, %0, c14, c0, 0"
32 : : "r"(COUNTER_FREQUENCY));
33#endif
34
35 writel(0, CONFIG_ROCKCHIP_STIMER_BASE + TIMER_CONTROL_REG);
36 writel(0xffffffff, CONFIG_ROCKCHIP_STIMER_BASE);
37 writel(0xffffffff, CONFIG_ROCKCHIP_STIMER_BASE + 4);
38 writel(TIMER_EN | TIMER_FMODE, CONFIG_ROCKCHIP_STIMER_BASE +
39 TIMER_CONTROL_REG);
40}
41
42void board_init_f(ulong dummy)
43{
44 struct udevice *dev;
45 int ret;
46
Chris Webba88cbf92019-07-19 14:23:11 +010047#if defined(CONFIG_DEBUG_UART) && defined(CONFIG_TPL_SERIAL_SUPPORT)
Kever Yang34ead0f2019-07-09 22:05:55 +080048 /*
49 * Debug UART can be used from here if required:
50 *
51 * debug_uart_init();
52 * printch('a');
53 * printhex8(0x1234);
54 * printascii("string");
55 */
56 debug_uart_init();
Chris Webb45dd8012019-07-19 14:23:55 +010057#ifdef CONFIG_TPL_BANNER_PRINT
Kever Yang34ead0f2019-07-09 22:05:55 +080058 printascii("\nU-Boot TPL " PLAIN_VERSION " (" U_BOOT_DATE " - " \
59 U_BOOT_TIME ")\n");
60#endif
Chris Webb45dd8012019-07-19 14:23:55 +010061#endif
Kever Yang34ead0f2019-07-09 22:05:55 +080062 ret = spl_early_init();
63 if (ret) {
64 debug("spl_early_init() failed: %d\n", ret);
65 hang();
66 }
67
68 /* Init secure timer */
69 rockchip_stimer_init();
70 /* Init ARM arch timer in arch/arm/cpu/ */
71 timer_init();
72
73 ret = uclass_get_device(UCLASS_RAM, 0, &dev);
74 if (ret) {
75 printf("DRAM init failed: %d\n", ret);
76 return;
77 }
78}
79
Peng Fanaa050c52019-08-07 06:40:53 +000080int board_return_to_bootrom(struct spl_image_info *spl_image,
81 struct spl_boot_device *bootdev)
Kever Yang34ead0f2019-07-09 22:05:55 +080082{
83 back_to_bootrom(BROM_BOOT_NEXTSTAGE);
Peng Fanaa050c52019-08-07 06:40:53 +000084
85 return 0;
Kever Yang34ead0f2019-07-09 22:05:55 +080086}
87
88u32 spl_boot_device(void)
89{
90 return BOOT_DEVICE_BOOTROM;
91}