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