Kever Yang | 49105fb | 2019-07-22 19:59:12 +0800 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0+ |
| 2 | /* |
| 3 | * (C) Copyright 2019 Rockchip Electronics Co., Ltd |
| 4 | */ |
| 5 | |
| 6 | #include <common.h> |
| 7 | #include <debug_uart.h> |
| 8 | #include <dm.h> |
Simon Glass | db41d65 | 2019-12-28 10:45:07 -0700 | [diff] [blame] | 9 | #include <hang.h> |
Kever Yang | 49105fb | 2019-07-22 19:59:12 +0800 | [diff] [blame] | 10 | #include <ram.h> |
| 11 | #include <spl.h> |
| 12 | #include <asm/arch-rockchip/bootrom.h> |
Kever Yang | 49105fb | 2019-07-22 19:59:12 +0800 | [diff] [blame] | 13 | #include <asm/io.h> |
| 14 | |
| 15 | DECLARE_GLOBAL_DATA_PTR; |
| 16 | |
Peng Fan | cda789a | 2019-08-07 06:40:53 +0000 | [diff] [blame] | 17 | int board_return_to_bootrom(struct spl_image_info *spl_image, |
| 18 | struct spl_boot_device *bootdev) |
Kever Yang | 49105fb | 2019-07-22 19:59:12 +0800 | [diff] [blame] | 19 | { |
| 20 | back_to_bootrom(BROM_BOOT_NEXTSTAGE); |
Peng Fan | cda789a | 2019-08-07 06:40:53 +0000 | [diff] [blame] | 21 | |
| 22 | return 0; |
Kever Yang | 49105fb | 2019-07-22 19:59:12 +0800 | [diff] [blame] | 23 | } |
| 24 | |
| 25 | __weak const char * const boot_devices[BROM_LAST_BOOTSOURCE + 1] = { |
| 26 | }; |
| 27 | |
| 28 | const char *board_spl_was_booted_from(void) |
| 29 | { |
| 30 | u32 bootdevice_brom_id = readl(BROM_BOOTSOURCE_ID_ADDR); |
| 31 | const char *bootdevice_ofpath = NULL; |
| 32 | |
| 33 | if (bootdevice_brom_id < ARRAY_SIZE(boot_devices)) |
| 34 | bootdevice_ofpath = boot_devices[bootdevice_brom_id]; |
| 35 | |
| 36 | if (bootdevice_ofpath) |
| 37 | debug("%s: brom_bootdevice_id %x maps to '%s'\n", |
| 38 | __func__, bootdevice_brom_id, bootdevice_ofpath); |
| 39 | else |
| 40 | debug("%s: failed to resolve brom_bootdevice_id %x\n", |
| 41 | __func__, bootdevice_brom_id); |
| 42 | |
| 43 | return bootdevice_ofpath; |
| 44 | } |
| 45 | |
| 46 | u32 spl_boot_device(void) |
| 47 | { |
| 48 | u32 boot_device = BOOT_DEVICE_MMC1; |
| 49 | |
| 50 | #if defined(CONFIG_TARGET_CHROMEBOOK_JERRY) || \ |
| 51 | defined(CONFIG_TARGET_CHROMEBIT_MICKEY) || \ |
| 52 | defined(CONFIG_TARGET_CHROMEBOOK_MINNIE) |
| 53 | return BOOT_DEVICE_SPI; |
| 54 | #endif |
| 55 | if (CONFIG_IS_ENABLED(ROCKCHIP_BACK_TO_BROM)) |
| 56 | return BOOT_DEVICE_BOOTROM; |
| 57 | |
| 58 | return boot_device; |
| 59 | } |
| 60 | |
Harald Seiler | e975906 | 2020-04-15 11:33:30 +0200 | [diff] [blame] | 61 | u32 spl_mmc_boot_mode(const u32 boot_device) |
Kever Yang | 49105fb | 2019-07-22 19:59:12 +0800 | [diff] [blame] | 62 | { |
| 63 | return MMCSD_MODE_RAW; |
| 64 | } |
| 65 | |
| 66 | #if !defined(CONFIG_ROCKCHIP_RK3188) |
| 67 | #define TIMER_LOAD_COUNT_L 0x00 |
| 68 | #define TIMER_LOAD_COUNT_H 0x04 |
| 69 | #define TIMER_CONTROL_REG 0x10 |
| 70 | #define TIMER_EN 0x1 |
| 71 | #define TIMER_FMODE BIT(0) |
| 72 | #define TIMER_RMODE BIT(1) |
| 73 | |
| 74 | __weak void rockchip_stimer_init(void) |
| 75 | { |
| 76 | /* If Timer already enabled, don't re-init it */ |
| 77 | u32 reg = readl(CONFIG_ROCKCHIP_STIMER_BASE + TIMER_CONTROL_REG); |
| 78 | |
| 79 | if (reg & TIMER_EN) |
| 80 | return; |
| 81 | #ifndef CONFIG_ARM64 |
| 82 | asm volatile("mcr p15, 0, %0, c14, c0, 0" |
| 83 | : : "r"(COUNTER_FREQUENCY)); |
| 84 | #endif |
| 85 | writel(0, CONFIG_ROCKCHIP_STIMER_BASE + TIMER_CONTROL_REG); |
| 86 | writel(0xffffffff, CONFIG_ROCKCHIP_STIMER_BASE); |
| 87 | writel(0xffffffff, CONFIG_ROCKCHIP_STIMER_BASE + 4); |
| 88 | writel(TIMER_EN | TIMER_FMODE, CONFIG_ROCKCHIP_STIMER_BASE + |
| 89 | TIMER_CONTROL_REG); |
| 90 | } |
| 91 | #endif |
| 92 | |
| 93 | __weak int board_early_init_f(void) |
| 94 | { |
| 95 | return 0; |
| 96 | } |
| 97 | |
| 98 | __weak int arch_cpu_init(void) |
| 99 | { |
| 100 | return 0; |
| 101 | } |
| 102 | |
| 103 | void board_init_f(ulong dummy) |
| 104 | { |
| 105 | int ret; |
Thomas Hebb | 857d638 | 2019-11-15 08:48:56 -0800 | [diff] [blame] | 106 | #if !defined(CONFIG_TPL) || defined(CONFIG_SPL_OS_BOOT) |
Kever Yang | 49105fb | 2019-07-22 19:59:12 +0800 | [diff] [blame] | 107 | struct udevice *dev; |
| 108 | #endif |
| 109 | |
| 110 | #ifdef CONFIG_DEBUG_UART |
| 111 | /* |
| 112 | * Debug UART can be used from here if required: |
| 113 | * |
| 114 | * debug_uart_init(); |
| 115 | * printch('a'); |
| 116 | * printhex8(0x1234); |
| 117 | * printascii("string"); |
| 118 | */ |
| 119 | debug_uart_init(); |
| 120 | debug("\nspl:debug uart enabled in %s\n", __func__); |
| 121 | #endif |
| 122 | |
| 123 | board_early_init_f(); |
| 124 | |
| 125 | ret = spl_early_init(); |
| 126 | if (ret) { |
| 127 | printf("spl_early_init() failed: %d\n", ret); |
| 128 | hang(); |
| 129 | } |
| 130 | arch_cpu_init(); |
Thomas Hebb | 220697a | 2019-11-15 08:48:55 -0800 | [diff] [blame] | 131 | #if !defined(CONFIG_ROCKCHIP_RK3188) |
| 132 | rockchip_stimer_init(); |
| 133 | #endif |
| 134 | #ifdef CONFIG_SYS_ARCH_TIMER |
| 135 | /* Init ARM arch timer in arch/arm/cpu/armv7/arch_timer.c */ |
| 136 | timer_init(); |
| 137 | #endif |
Thomas Hebb | 857d638 | 2019-11-15 08:48:56 -0800 | [diff] [blame] | 138 | #if !defined(CONFIG_TPL) || defined(CONFIG_SPL_OS_BOOT) |
Kever Yang | 49105fb | 2019-07-22 19:59:12 +0800 | [diff] [blame] | 139 | debug("\nspl:init dram\n"); |
| 140 | ret = uclass_get_device(UCLASS_RAM, 0, &dev); |
| 141 | if (ret) { |
| 142 | printf("DRAM init failed: %d\n", ret); |
| 143 | return; |
| 144 | } |
| 145 | #endif |
Kever Yang | 49105fb | 2019-07-22 19:59:12 +0800 | [diff] [blame] | 146 | preloader_console_init(); |
| 147 | } |
| 148 | |
| 149 | #ifdef CONFIG_SPL_LOAD_FIT |
Heiko Stuebner | 552e7cc | 2020-01-17 21:37:09 +0100 | [diff] [blame] | 150 | int __weak board_fit_config_name_match(const char *name) |
Kever Yang | 49105fb | 2019-07-22 19:59:12 +0800 | [diff] [blame] | 151 | { |
| 152 | /* Just empty function now - can't decide what to choose */ |
| 153 | debug("%s: %s\n", __func__, name); |
| 154 | |
| 155 | return 0; |
| 156 | } |
| 157 | #endif |