xref: /rk3399_rockchip-uboot/arch/arm/mach-rockchip/tpl.c (revision b33ebddfc88565975ea3dfa5b425f2aa45f2da80)
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 __weak int arch_cpu_init(void)
52 {
53 	return 0;
54 }
55 
56 void board_init_f(ulong dummy)
57 {
58 	struct udevice *dev;
59 	int ret;
60 
61 	rockchip_stimer_init();
62 	arch_cpu_init();
63 #define EARLY_DEBUG
64 #ifdef EARLY_DEBUG
65 	/*
66 	 * Debug UART can be used from here if required:
67 	 *
68 	 * debug_uart_init();
69 	 * printch('a');
70 	 * printhex8(0x1234);
71 	 * printascii("string");
72 	 */
73 	debug_uart_init();
74 	printascii("\nU-Boot TPL " PLAIN_VERSION " (" U_BOOT_DATE " - " \
75 				U_BOOT_TIME ")\n");
76 
77 #endif
78 	ret = spl_early_init();
79 	if (ret) {
80 		debug("spl_early_init() failed: %d\n", ret);
81 		hang();
82 	}
83 
84 	/* Init ARM arch timer */
85 	timer_init();
86 	ret = uclass_get_device(UCLASS_RAM, 0, &dev);
87 	if (ret) {
88 		printf("DRAM init failed: %d\n", ret);
89 		return;
90 	}
91 
92 #if defined(CONFIG_TPL_ROCKCHIP_BACK_TO_BROM) && !defined(CONFIG_TPL_BOARD_INIT)
93 	back_to_bootrom(BROM_BOOT_NEXTSTAGE);
94 #endif
95 }
96 
97 #ifndef CONFIG_SPL_FRAMEWORK
98 /* Place Holders */
99 void board_init_r(gd_t *id, ulong dest_addr)
100 {
101 	/*
102 	 * Function attribute is no-return
103 	 * This Function never executes
104 	 */
105 	while (1)
106 		;
107 }
108 #endif
109