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