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 #endif 61 writel(0, CONFIG_ROCKCHIP_STIMER_BASE + 0x10); 62 writel(0xffffffff, CONFIG_ROCKCHIP_STIMER_BASE); 63 writel(0xffffffff, CONFIG_ROCKCHIP_STIMER_BASE + 4); 64 writel(1, CONFIG_ROCKCHIP_STIMER_BASE + 0x10); 65 } 66 67 __weak int arch_cpu_init(void) 68 { 69 return 0; 70 } 71 72 void board_init_f(ulong dummy) 73 { 74 #if defined(CONFIG_SPL_FRAMEWORK) && !defined(CONFIG_TINY_TPL) 75 struct udevice *dev; 76 int ret; 77 #endif 78 79 rockchip_stimer_init(); 80 arch_cpu_init(); 81 #define EARLY_DEBUG 82 #ifdef EARLY_DEBUG 83 /* 84 * Debug UART can be used from here if required: 85 * 86 * debug_uart_init(); 87 * printch('a'); 88 * printhex8(0x1234); 89 * printascii("string"); 90 */ 91 debug_uart_init(); 92 printascii("\nU-Boot TPL " PLAIN_VERSION " (" U_BOOT_DATE " - " \ 93 U_BOOT_TIME ")\n"); 94 #endif 95 96 #if defined(CONFIG_SPL_FRAMEWORK) && !defined(CONFIG_TINY_TPL) 97 ret = spl_early_init(); 98 if (ret) { 99 debug("spl_early_init() failed: %d\n", ret); 100 hang(); 101 } 102 #endif 103 104 /* Init ARM arch timer */ 105 timer_init(); 106 107 #if defined(CONFIG_SPL_FRAMEWORK) && !defined(CONFIG_TINY_TPL) 108 ret = uclass_get_device(UCLASS_RAM, 0, &dev); 109 if (ret) { 110 printf("DRAM init failed: %d\n", ret); 111 return; 112 } 113 #else 114 sdram_init(); 115 #endif 116 117 #if defined(CONFIG_TPL_ROCKCHIP_BACK_TO_BROM) && !defined(CONFIG_TPL_BOARD_INIT) 118 back_to_bootrom(BROM_BOOT_NEXTSTAGE); 119 #endif 120 } 121 122 #if !(defined(CONFIG_SPL_FRAMEWORK) && !defined(CONFIG_TINY_TPL)) 123 /* Place Holders */ 124 void board_init_r(gd_t *id, ulong dest_addr) 125 { 126 /* 127 * Function attribute is no-return 128 * This Function never executes 129 */ 130 while (1) 131 ; 132 } 133 #endif 134