xref: /rk3399_rockchip-uboot/arch/arm/mach-rockchip/tpl.c (revision b283d2ae7bf9dec650d82c6b10cb92ddd9d9ce5d)
1 /*
2  * (C) Copyright 2017 Rockchip Electronics Co., Ltd
3  *
4  * SPDX-License-Identifier:     GPL-2.0+
5  */
6 
7 #include <common.h>
8 #include <debug_uart.h>
9 #include <dm.h>
10 #include <ns16550.h>
11 #include <ram.h>
12 #include <spl.h>
13 #include <version.h>
14 #include <asm/io.h>
15 #include <asm/arch/bootrom.h>
16 #include <asm/arch/uart.h>
17 
18 #ifndef CONFIG_SPL_LIBCOMMON_SUPPORT
19 void puts(const char *str)
20 {
21 	while (*str)
22 		putc(*str++);
23 }
24 
25 void putc(char c)
26 {
27 	if (c == '\n')
28 		NS16550_putc((NS16550_t)(CONFIG_SYS_NS16550_COM1), '\r');
29 
30 	NS16550_putc((NS16550_t)(CONFIG_SYS_NS16550_COM1), c);
31 }
32 #endif /* CONFIG_SPL_LIBCOMMON_SUPPORT */
33 
34 u32 spl_boot_device(void)
35 {
36 	return BOOT_DEVICE_BOOTROM;
37 }
38 
39 __weak void rockchip_stimer_init(void)
40 {
41 #ifndef CONFIG_ARM64
42 	asm volatile("mcr p15, 0, %0, c14, c0, 0"
43 		     : : "r"(COUNTER_FREQUENCY));
44 #endif
45 	writel(0, CONFIG_ROCKCHIP_STIMER_BASE + 0x10);
46 	writel(0xffffffff, CONFIG_ROCKCHIP_STIMER_BASE);
47 	writel(0xffffffff, CONFIG_ROCKCHIP_STIMER_BASE + 4);
48 	writel(1, CONFIG_ROCKCHIP_STIMER_BASE + 0x10);
49 }
50 
51 void board_init_f(ulong dummy)
52 {
53 	struct udevice *dev;
54 	int ret;
55 
56 #define EARLY_DEBUG
57 #ifdef EARLY_DEBUG
58 	/*
59 	 * Debug UART can be used from here if required:
60 	 *
61 	 * debug_uart_init();
62 	 * printch('a');
63 	 * printhex8(0x1234);
64 	 * printascii("string");
65 	 */
66 	debug_uart_init();
67 	printascii("\nU-Boot TPL " PLAIN_VERSION " (" U_BOOT_DATE " - " \
68 				U_BOOT_TIME ")\n");
69 
70 #endif
71 	ret = spl_early_init();
72 	if (ret) {
73 		debug("spl_early_init() failed: %d\n", ret);
74 		hang();
75 	}
76 
77 	rockchip_stimer_init();
78 	/* Init ARM arch timer */
79 	timer_init();
80 	ret = uclass_get_device(UCLASS_RAM, 0, &dev);
81 	if (ret) {
82 		printf("DRAM init failed: %d\n", ret);
83 		return;
84 	}
85 
86 #if defined(CONFIG_TPL_ROCKCHIP_BACK_TO_BROM) && !defined(CONFIG_TPL_BOARD_INIT)
87 	back_to_bootrom(BROM_BOOT_NEXTSTAGE);
88 #endif
89 }
90 
91 #ifndef CONFIG_SPL_FRAMEWORK
92 /* Place Holders */
93 void board_init_r(gd_t *id, ulong dest_addr)
94 {
95 	/*
96 	 * Function attribute is no-return
97 	 * This Function never executes
98 	 */
99 	while (1)
100 		;
101 }
102 #endif
103