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> |
Simon Glass | 4d72caa | 2020-05-10 11:40:01 -0600 | [diff] [blame] | 10 | #include <image.h> |
Simon Glass | 691d719 | 2020-05-10 11:40:02 -0600 | [diff] [blame] | 11 | #include <init.h> |
Simon Glass | f7ae49f | 2020-05-10 11:40:05 -0600 | [diff] [blame] | 12 | #include <log.h> |
Kever Yang | 49105fb | 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 | 49105fb | 2019-07-22 19:59:12 +0800 | [diff] [blame] | 16 | #include <asm/io.h> |
Simon Glass | cd93d62 | 2020-05-10 11:40:13 -0600 | [diff] [blame] | 17 | #include <linux/bitops.h> |
Kever Yang | 49105fb | 2019-07-22 19:59:12 +0800 | [diff] [blame] | 18 | |
| 19 | DECLARE_GLOBAL_DATA_PTR; |
| 20 | |
Peng Fan | cda789a | 2019-08-07 06:40:53 +0000 | [diff] [blame] | 21 | int board_return_to_bootrom(struct spl_image_info *spl_image, |
| 22 | struct spl_boot_device *bootdev) |
Kever Yang | 49105fb | 2019-07-22 19:59:12 +0800 | [diff] [blame] | 23 | { |
| 24 | back_to_bootrom(BROM_BOOT_NEXTSTAGE); |
Peng Fan | cda789a | 2019-08-07 06:40:53 +0000 | [diff] [blame] | 25 | |
| 26 | return 0; |
Kever Yang | 49105fb | 2019-07-22 19:59:12 +0800 | [diff] [blame] | 27 | } |
| 28 | |
| 29 | __weak const char * const boot_devices[BROM_LAST_BOOTSOURCE + 1] = { |
| 30 | }; |
| 31 | |
| 32 | const char *board_spl_was_booted_from(void) |
| 33 | { |
| 34 | u32 bootdevice_brom_id = readl(BROM_BOOTSOURCE_ID_ADDR); |
| 35 | const char *bootdevice_ofpath = NULL; |
| 36 | |
| 37 | if (bootdevice_brom_id < ARRAY_SIZE(boot_devices)) |
| 38 | bootdevice_ofpath = boot_devices[bootdevice_brom_id]; |
| 39 | |
| 40 | if (bootdevice_ofpath) |
| 41 | debug("%s: brom_bootdevice_id %x maps to '%s'\n", |
| 42 | __func__, bootdevice_brom_id, bootdevice_ofpath); |
| 43 | else |
| 44 | debug("%s: failed to resolve brom_bootdevice_id %x\n", |
| 45 | __func__, bootdevice_brom_id); |
| 46 | |
| 47 | return bootdevice_ofpath; |
| 48 | } |
| 49 | |
| 50 | u32 spl_boot_device(void) |
| 51 | { |
| 52 | u32 boot_device = BOOT_DEVICE_MMC1; |
| 53 | |
| 54 | #if defined(CONFIG_TARGET_CHROMEBOOK_JERRY) || \ |
| 55 | defined(CONFIG_TARGET_CHROMEBIT_MICKEY) || \ |
Urja Rannikko | 353ad95 | 2020-05-13 19:15:20 +0000 | [diff] [blame] | 56 | defined(CONFIG_TARGET_CHROMEBOOK_MINNIE) || \ |
Simon Glass | fab4f32 | 2020-07-19 13:55:53 -0600 | [diff] [blame] | 57 | defined(CONFIG_TARGET_CHROMEBOOK_SPEEDY) || \ |
| 58 | defined(CONFIG_TARGET_CHROMEBOOK_BOB) |
Kever Yang | 49105fb | 2019-07-22 19:59:12 +0800 | [diff] [blame] | 59 | return BOOT_DEVICE_SPI; |
| 60 | #endif |
| 61 | if (CONFIG_IS_ENABLED(ROCKCHIP_BACK_TO_BROM)) |
| 62 | return BOOT_DEVICE_BOOTROM; |
| 63 | |
| 64 | return boot_device; |
| 65 | } |
| 66 | |
Harald Seiler | e975906 | 2020-04-15 11:33:30 +0200 | [diff] [blame] | 67 | u32 spl_mmc_boot_mode(const u32 boot_device) |
Kever Yang | 49105fb | 2019-07-22 19:59:12 +0800 | [diff] [blame] | 68 | { |
| 69 | return MMCSD_MODE_RAW; |
| 70 | } |
| 71 | |
| 72 | #if !defined(CONFIG_ROCKCHIP_RK3188) |
| 73 | #define TIMER_LOAD_COUNT_L 0x00 |
| 74 | #define TIMER_LOAD_COUNT_H 0x04 |
| 75 | #define TIMER_CONTROL_REG 0x10 |
| 76 | #define TIMER_EN 0x1 |
| 77 | #define TIMER_FMODE BIT(0) |
| 78 | #define TIMER_RMODE BIT(1) |
| 79 | |
| 80 | __weak void rockchip_stimer_init(void) |
| 81 | { |
| 82 | /* If Timer already enabled, don't re-init it */ |
| 83 | u32 reg = readl(CONFIG_ROCKCHIP_STIMER_BASE + TIMER_CONTROL_REG); |
| 84 | |
| 85 | if (reg & TIMER_EN) |
| 86 | return; |
| 87 | #ifndef CONFIG_ARM64 |
| 88 | asm volatile("mcr p15, 0, %0, c14, c0, 0" |
| 89 | : : "r"(COUNTER_FREQUENCY)); |
| 90 | #endif |
| 91 | writel(0, CONFIG_ROCKCHIP_STIMER_BASE + TIMER_CONTROL_REG); |
| 92 | writel(0xffffffff, CONFIG_ROCKCHIP_STIMER_BASE); |
| 93 | writel(0xffffffff, CONFIG_ROCKCHIP_STIMER_BASE + 4); |
| 94 | writel(TIMER_EN | TIMER_FMODE, CONFIG_ROCKCHIP_STIMER_BASE + |
| 95 | TIMER_CONTROL_REG); |
| 96 | } |
| 97 | #endif |
| 98 | |
| 99 | __weak int board_early_init_f(void) |
| 100 | { |
| 101 | return 0; |
| 102 | } |
| 103 | |
| 104 | __weak int arch_cpu_init(void) |
| 105 | { |
| 106 | return 0; |
| 107 | } |
| 108 | |
| 109 | void board_init_f(ulong dummy) |
| 110 | { |
| 111 | int ret; |
Kever Yang | 49105fb | 2019-07-22 19:59:12 +0800 | [diff] [blame] | 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 | 220697a | 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 |
Heiko Stuebner | b6740fb | 2020-05-25 19:57:24 +0200 | [diff] [blame] | 141 | #if !defined(CONFIG_TPL) || defined(CONFIG_SPL_RAM) |
Kever Yang | 49105fb | 2019-07-22 19:59:12 +0800 | [diff] [blame] | 142 | debug("\nspl:init dram\n"); |
Heiko Stuebner | b6740fb | 2020-05-25 19:57:24 +0200 | [diff] [blame] | 143 | ret = dram_init(); |
Kever Yang | 49105fb | 2019-07-22 19:59:12 +0800 | [diff] [blame] | 144 | if (ret) { |
| 145 | printf("DRAM init failed: %d\n", ret); |
| 146 | return; |
| 147 | } |
Heiko Stuebner | b6740fb | 2020-05-25 19:57:24 +0200 | [diff] [blame] | 148 | gd->ram_top = gd->ram_base + get_effective_memsize(); |
| 149 | gd->ram_top = board_get_usable_ram_top(gd->ram_size); |
Kever Yang | 49105fb | 2019-07-22 19:59:12 +0800 | [diff] [blame] | 150 | #endif |
Kever Yang | 49105fb | 2019-07-22 19:59:12 +0800 | [diff] [blame] | 151 | preloader_console_init(); |
| 152 | } |
| 153 | |
| 154 | #ifdef CONFIG_SPL_LOAD_FIT |
Heiko Stuebner | 552e7cc | 2020-01-17 21:37:09 +0100 | [diff] [blame] | 155 | int __weak board_fit_config_name_match(const char *name) |
Kever Yang | 49105fb | 2019-07-22 19:59:12 +0800 | [diff] [blame] | 156 | { |
| 157 | /* Just empty function now - can't decide what to choose */ |
| 158 | debug("%s: %s\n", __func__, name); |
| 159 | |
| 160 | return 0; |
| 161 | } |
| 162 | #endif |