xref: /rk3399_rockchip-uboot/arch/arm/mach-rockchip/tpl.c (revision 37e5dcc8baea3dc897741e9be973d7d226f5edb4)
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 #include <asm/arch-rockchip/sys_proto.h>
18 
19 #ifndef CONFIG_TPL_LIBCOMMON_SUPPORT
20 #define CONFIG_SYS_NS16550_COM1 CONFIG_DEBUG_UART_BASE
21 void puts(const char *str)
22 {
23 	while (*str)
24 		putc(*str++);
25 }
26 
27 void putc(char c)
28 {
29 	if (c == '\n')
30 		NS16550_putc((NS16550_t)(CONFIG_SYS_NS16550_COM1), '\r');
31 
32 	NS16550_putc((NS16550_t)(CONFIG_SYS_NS16550_COM1), c);
33 }
34 #endif /* CONFIG_TPL_LIBCOMMON_SUPPORT */
35 
36 #ifndef CONFIG_TPL_LIBGENERIC_SUPPORT
37 void udelay(unsigned long usec)
38 {
39 	__udelay(usec);
40 }
41 
42 void hang(void)
43 {
44         bootstage_error(BOOTSTAGE_ID_NEED_RESET);
45         for (;;)
46                 ;
47 }
48 #endif
49 
50 u32 spl_boot_device(void)
51 {
52 	return BOOT_DEVICE_BOOTROM;
53 }
54 
55 __weak void rockchip_stimer_init(void)
56 {
57 #ifndef CONFIG_ARM64
58 	asm volatile("mcr p15, 0, %0, c14, c0, 0"
59 		     : : "r"(COUNTER_FREQUENCY));
60 #elif CONFIG_IS_ENABLED(TINY_FRAMEWORK)
61 	/*
62 	 * For ARM64,generally initialize CNTFRQ in start.S,
63 	 * but if defined CONFIG_TPL_TINY_FRAMEWORK should skip start.S.
64 	 * So initialize CNTFRQ to 24MHz here.
65 	 */
66 	asm volatile("msr CNTFRQ_EL0, %0"
67 		     : : "r" (COUNTER_FREQUENCY));
68 #endif
69 	writel(0, CONFIG_ROCKCHIP_STIMER_BASE + 0x10);
70 	writel(0xffffffff, CONFIG_ROCKCHIP_STIMER_BASE);
71 	writel(0xffffffff, CONFIG_ROCKCHIP_STIMER_BASE + 4);
72 	writel(1, CONFIG_ROCKCHIP_STIMER_BASE + 0x10);
73 }
74 
75 __weak int arch_cpu_init(void)
76 {
77 	return 0;
78 }
79 
80 void board_init_f(ulong dummy)
81 {
82 #if defined(CONFIG_SPL_FRAMEWORK) && !CONFIG_IS_ENABLED(TINY_FRAMEWORK)
83 	struct udevice *dev;
84 	int ret;
85 #endif
86 
87 	rockchip_stimer_init();
88 	arch_cpu_init();
89 #define EARLY_DEBUG
90 #ifdef EARLY_DEBUG
91 	/*
92 	 * Debug UART can be used from here if required:
93 	 *
94 	 * debug_uart_init();
95 	 * printch('a');
96 	 * printhex8(0x1234);
97 	 * printascii("string");
98 	 */
99 	debug_uart_init();
100 	printascii("\nU-Boot TPL " PLAIN_VERSION " (" U_BOOT_DATE " - " \
101 				U_BOOT_TIME ")\n");
102 #endif
103 
104 #if defined(CONFIG_SPL_FRAMEWORK) && !CONFIG_IS_ENABLED(TINY_FRAMEWORK)
105 	ret = spl_early_init();
106 	if (ret) {
107 		debug("spl_early_init() failed: %d\n", ret);
108 		hang();
109 	}
110 #endif
111 
112 	/* Init ARM arch timer */
113 	timer_init();
114 
115 #if defined(CONFIG_SPL_FRAMEWORK) && !CONFIG_IS_ENABLED(TINY_FRAMEWORK)
116 	ret = uclass_get_device(UCLASS_RAM, 0, &dev);
117 	if (ret) {
118 		printf("DRAM init failed: %d\n", ret);
119 		return;
120 	}
121 #else
122 	sdram_init();
123 #endif
124 
125 #if defined(CONFIG_TPL_ROCKCHIP_BACK_TO_BROM) && !defined(CONFIG_TPL_BOARD_INIT)
126 	back_to_bootrom(BROM_BOOT_NEXTSTAGE);
127 #endif
128 }
129 
130 #if !(defined(CONFIG_SPL_FRAMEWORK) && !CONFIG_IS_ENABLED(TINY_FRAMEWORK))
131 /* Place Holders */
132 void board_init_r(gd_t *id, ulong dest_addr)
133 {
134 	/*
135 	 * Function attribute is no-return
136 	 * This Function never executes
137 	 */
138 	while (1)
139 		;
140 }
141 #endif
142