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-rockchip/sys_proto.h> 14 #include <asm/io.h> 15 16 DECLARE_GLOBAL_DATA_PTR; 17 18 #define BROM_BOOTSOURCE_ID_ADDR (CONFIG_ROCKCHIP_IRAM_START_ADDR + 0x10) 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 writel(0, CONFIG_ROCKCHIP_STIMER_BASE + 0x10); 68 writel(0xffffffff, CONFIG_ROCKCHIP_STIMER_BASE); 69 writel(0xffffffff, CONFIG_ROCKCHIP_STIMER_BASE + 4); 70 writel(1, CONFIG_ROCKCHIP_STIMER_BASE + 0x10); 71 } 72 73 __weak int arch_cpu_init(void) 74 { 75 return 0; 76 } 77 78 __weak int rk_board_init_f(void) 79 { 80 return 0; 81 } 82 83 void board_init_f(ulong dummy) 84 { 85 #ifdef CONFIG_SPL_FRAMEWORK 86 int ret; 87 #if !defined(CONFIG_SUPPORT_TPL) 88 struct udevice *dev; 89 #endif 90 #endif 91 92 #define EARLY_UART 93 #if defined(EARLY_UART) && defined(CONFIG_DEBUG_UART) 94 /* 95 * Debug UART can be used from here if required: 96 * 97 * debug_uart_init(); 98 * printch('a'); 99 * printhex8(0x1234); 100 * printascii("string"); 101 */ 102 debug_uart_init(); 103 printascii("U-Boot SPL board init"); 104 #endif 105 106 arch_cpu_init(); 107 rockchip_stimer_init(); 108 #ifdef CONFIG_SPL_FRAMEWORK 109 ret = spl_early_init(); 110 if (ret) { 111 printf("spl_early_init() failed: %d\n", ret); 112 hang(); 113 } 114 #if !defined(CONFIG_SUPPORT_TPL) 115 debug("\nspl:init dram\n"); 116 ret = uclass_get_device(UCLASS_RAM, 0, &dev); 117 if (ret) { 118 printf("DRAM init failed: %d\n", ret); 119 return; 120 } 121 #endif 122 preloader_console_init(); 123 #else 124 /* Some SoCs like rk3036 does not use any frame work */ 125 sdram_init(); 126 #endif 127 128 rk_board_init_f(); 129 #if CONFIG_IS_ENABLED(ROCKCHIP_BACK_TO_BROM) && !defined(CONFIG_SPL_BOARD_INIT) 130 back_to_bootrom(BROM_BOOT_NEXTSTAGE); 131 #endif 132 133 } 134 135 #ifdef CONFIG_SPL_LOAD_FIT 136 int board_fit_config_name_match(const char *name) 137 { 138 /* Just empty function now - can't decide what to choose */ 139 debug("%s: %s\n", __func__, name); 140 141 return 0; 142 } 143 #endif 144 145 #ifdef CONFIG_SPL_BOARD_INIT 146 __weak int rk_spl_board_init(void) 147 { 148 return 0; 149 } 150 151 static int setup_led(void) 152 { 153 #ifdef CONFIG_SPL_LED 154 struct udevice *dev; 155 char *led_name; 156 int ret; 157 158 led_name = fdtdec_get_config_string(gd->fdt_blob, "u-boot,boot-led"); 159 if (!led_name) 160 return 0; 161 ret = led_get_by_label(led_name, &dev); 162 if (ret) { 163 debug("%s: get=%d\n", __func__, ret); 164 return ret; 165 } 166 ret = led_set_on(dev, 1); 167 if (ret) 168 return ret; 169 #endif 170 171 return 0; 172 } 173 174 void spl_board_init(void) 175 { 176 int ret; 177 178 ret = setup_led(); 179 180 if (ret) { 181 debug("LED ret=%d\n", ret); 182 hang(); 183 } 184 185 rk_spl_board_init(); 186 #if CONFIG_IS_ENABLED(ROCKCHIP_BACK_TO_BROM) 187 back_to_bootrom(BROM_BOOT_NEXTSTAGE); 188 #endif 189 return; 190 } 191 #endif 192