1 /* 2 * (C) Copyright 2018 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 <ram.h> 11 #include <spl.h> 12 #include <asm/arch/bootrom.h> 13 #include <asm/arch/sdram_common.h> 14 #include <asm/arch-rockchip/sys_proto.h> 15 #include <asm/io.h> 16 17 DECLARE_GLOBAL_DATA_PTR; 18 19 void board_return_to_bootrom(void) 20 { 21 back_to_bootrom(BROM_BOOT_NEXTSTAGE); 22 } 23 24 __weak const char * const boot_devices[BROM_LAST_BOOTSOURCE + 1] = { 25 }; 26 27 const char *board_spl_was_booted_from(void) 28 { 29 u32 bootdevice_brom_id = readl(BROM_BOOTSOURCE_ID_ADDR); 30 const char *bootdevice_ofpath = NULL; 31 32 if (bootdevice_brom_id < ARRAY_SIZE(boot_devices)) 33 bootdevice_ofpath = boot_devices[bootdevice_brom_id]; 34 35 if (bootdevice_ofpath) 36 debug("%s: brom_bootdevice_id %x maps to '%s'\n", 37 __func__, bootdevice_brom_id, bootdevice_ofpath); 38 else 39 debug("%s: failed to resolve brom_bootdevice_id %x\n", 40 __func__, bootdevice_brom_id); 41 42 return bootdevice_ofpath; 43 } 44 45 u32 spl_boot_device(void) 46 { 47 u32 boot_device = BOOT_DEVICE_MMC1; 48 49 #if defined(CONFIG_TARGET_CHROMEBOOK_JERRY) || \ 50 defined(CONFIG_TARGET_CHROMEBIT_MICKEY) || \ 51 defined(CONFIG_TARGET_CHROMEBOOK_MINNIE) 52 return BOOT_DEVICE_SPI; 53 #endif 54 if (CONFIG_IS_ENABLED(ROCKCHIP_BACK_TO_BROM)) 55 return BOOT_DEVICE_BOOTROM; 56 57 return boot_device; 58 } 59 60 u32 spl_boot_mode(const u32 boot_device) 61 { 62 return MMCSD_MODE_RAW; 63 } 64 65 __weak void rockchip_stimer_init(void) 66 { 67 #ifdef CONFIG_SYS_ARCH_TIMER 68 #ifndef CONFIG_ARM64 69 asm volatile("mcr p15, 0, %0, c14, c0, 0" 70 : : "r"(COUNTER_FREQUENCY)); 71 #endif 72 writel(0, CONFIG_ROCKCHIP_STIMER_BASE + 0x10); 73 writel(0xffffffff, CONFIG_ROCKCHIP_STIMER_BASE); 74 writel(0xffffffff, CONFIG_ROCKCHIP_STIMER_BASE + 4); 75 writel(1, CONFIG_ROCKCHIP_STIMER_BASE + 0x10); 76 #endif 77 } 78 79 __weak int arch_cpu_init(void) 80 { 81 return 0; 82 } 83 84 __weak int rk_board_init_f(void) 85 { 86 return 0; 87 } 88 89 void board_init_f(ulong dummy) 90 { 91 #ifdef CONFIG_SPL_FRAMEWORK 92 int ret; 93 #if !defined(CONFIG_SUPPORT_TPL) 94 struct udevice *dev; 95 #endif 96 #endif 97 98 #if !defined(CONFIG_SUPPORT_TPL) 99 rockchip_stimer_init(); 100 arch_cpu_init(); 101 #endif 102 #define EARLY_UART 103 #if defined(EARLY_UART) && defined(CONFIG_DEBUG_UART) 104 /* 105 * Debug UART can be used from here if required: 106 * 107 * debug_uart_init(); 108 * printch('a'); 109 * printhex8(0x1234); 110 * printascii("string"); 111 */ 112 debug_uart_init(); 113 printascii("U-Boot SPL board init"); 114 #endif 115 116 #ifdef CONFIG_SPL_FRAMEWORK 117 ret = spl_early_init(); 118 if (ret) { 119 printf("spl_early_init() failed: %d\n", ret); 120 hang(); 121 } 122 #if !defined(CONFIG_SUPPORT_TPL) 123 debug("\nspl:init dram\n"); 124 ret = uclass_get_device(UCLASS_RAM, 0, &dev); 125 if (ret) { 126 printf("DRAM init failed: %d\n", ret); 127 return; 128 } 129 #endif 130 preloader_console_init(); 131 #else 132 /* Some SoCs like rk3036 does not use any frame work */ 133 sdram_init(); 134 #endif 135 136 rk_board_init_f(); 137 #if CONFIG_IS_ENABLED(ROCKCHIP_BACK_TO_BROM) && !defined(CONFIG_SPL_BOARD_INIT) 138 back_to_bootrom(BROM_BOOT_NEXTSTAGE); 139 #endif 140 141 } 142 143 #ifdef CONFIG_SPL_LOAD_FIT 144 int board_fit_config_name_match(const char *name) 145 { 146 /* Just empty function now - can't decide what to choose */ 147 debug("%s: %s\n", __func__, name); 148 149 return 0; 150 } 151 #endif 152 153 #ifdef CONFIG_SPL_BOARD_INIT 154 __weak int rk_spl_board_init(void) 155 { 156 return 0; 157 } 158 159 static int setup_led(void) 160 { 161 #ifdef CONFIG_SPL_LED 162 struct udevice *dev; 163 char *led_name; 164 int ret; 165 166 led_name = fdtdec_get_config_string(gd->fdt_blob, "u-boot,boot-led"); 167 if (!led_name) 168 return 0; 169 ret = led_get_by_label(led_name, &dev); 170 if (ret) { 171 debug("%s: get=%d\n", __func__, ret); 172 return ret; 173 } 174 ret = led_set_on(dev, 1); 175 if (ret) 176 return ret; 177 #endif 178 179 return 0; 180 } 181 182 void spl_board_init(void) 183 { 184 int ret; 185 186 ret = setup_led(); 187 188 if (ret) { 189 debug("LED ret=%d\n", ret); 190 hang(); 191 } 192 193 rk_spl_board_init(); 194 #if CONFIG_IS_ENABLED(ROCKCHIP_BACK_TO_BROM) 195 back_to_bootrom(BROM_BOOT_NEXTSTAGE); 196 #endif 197 return; 198 } 199 #endif 200