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> |
Simon Glass | 3ba929a | 2020-10-30 21:38:53 -0600 | [diff] [blame] | 16 | #include <asm/global_data.h> |
Kever Yang | 1d7cc72a | 2019-07-22 19:59:12 +0800 | [diff] [blame] | 17 | #include <asm/io.h> |
Simon Glass | 4dcacfc | 2020-05-10 11:40:13 -0600 | [diff] [blame] | 18 | #include <linux/bitops.h> |
Kever Yang | 1d7cc72a | 2019-07-22 19:59:12 +0800 | [diff] [blame] | 19 | |
| 20 | DECLARE_GLOBAL_DATA_PTR; |
| 21 | |
Peng Fan | aa050c5 | 2019-08-07 06:40:53 +0000 | [diff] [blame] | 22 | int board_return_to_bootrom(struct spl_image_info *spl_image, |
| 23 | struct spl_boot_device *bootdev) |
Kever Yang | 1d7cc72a | 2019-07-22 19:59:12 +0800 | [diff] [blame] | 24 | { |
| 25 | back_to_bootrom(BROM_BOOT_NEXTSTAGE); |
Peng Fan | aa050c5 | 2019-08-07 06:40:53 +0000 | [diff] [blame] | 26 | |
| 27 | return 0; |
Kever Yang | 1d7cc72a | 2019-07-22 19:59:12 +0800 | [diff] [blame] | 28 | } |
| 29 | |
| 30 | __weak const char * const boot_devices[BROM_LAST_BOOTSOURCE + 1] = { |
| 31 | }; |
| 32 | |
| 33 | const char *board_spl_was_booted_from(void) |
| 34 | { |
| 35 | u32 bootdevice_brom_id = readl(BROM_BOOTSOURCE_ID_ADDR); |
| 36 | const char *bootdevice_ofpath = NULL; |
| 37 | |
| 38 | if (bootdevice_brom_id < ARRAY_SIZE(boot_devices)) |
| 39 | bootdevice_ofpath = boot_devices[bootdevice_brom_id]; |
| 40 | |
| 41 | if (bootdevice_ofpath) |
| 42 | debug("%s: brom_bootdevice_id %x maps to '%s'\n", |
| 43 | __func__, bootdevice_brom_id, bootdevice_ofpath); |
| 44 | else |
| 45 | debug("%s: failed to resolve brom_bootdevice_id %x\n", |
| 46 | __func__, bootdevice_brom_id); |
| 47 | |
| 48 | return bootdevice_ofpath; |
| 49 | } |
| 50 | |
| 51 | u32 spl_boot_device(void) |
| 52 | { |
| 53 | u32 boot_device = BOOT_DEVICE_MMC1; |
| 54 | |
| 55 | #if defined(CONFIG_TARGET_CHROMEBOOK_JERRY) || \ |
| 56 | defined(CONFIG_TARGET_CHROMEBIT_MICKEY) || \ |
Urja Rannikko | c22d863 | 2020-05-13 19:15:20 +0000 | [diff] [blame] | 57 | defined(CONFIG_TARGET_CHROMEBOOK_MINNIE) || \ |
Simon Glass | 0b2f70c | 2020-07-19 13:55:53 -0600 | [diff] [blame] | 58 | defined(CONFIG_TARGET_CHROMEBOOK_SPEEDY) || \ |
Marty E. Plummer | b20a8dac | 2021-12-24 16:43:46 +0300 | [diff] [blame] | 59 | defined(CONFIG_TARGET_CHROMEBOOK_BOB) || \ |
| 60 | defined(CONFIG_TARGET_CHROMEBOOK_KEVIN) |
Kever Yang | 1d7cc72a | 2019-07-22 19:59:12 +0800 | [diff] [blame] | 61 | return BOOT_DEVICE_SPI; |
| 62 | #endif |
| 63 | if (CONFIG_IS_ENABLED(ROCKCHIP_BACK_TO_BROM)) |
| 64 | return BOOT_DEVICE_BOOTROM; |
| 65 | |
| 66 | return boot_device; |
| 67 | } |
| 68 | |
Andre Przywara | 3cb12ef | 2021-07-12 11:06:49 +0100 | [diff] [blame] | 69 | u32 spl_mmc_boot_mode(struct mmc *mmc, const u32 boot_device) |
Kever Yang | 1d7cc72a | 2019-07-22 19:59:12 +0800 | [diff] [blame] | 70 | { |
| 71 | return MMCSD_MODE_RAW; |
| 72 | } |
| 73 | |
Kever Yang | 1d7cc72a | 2019-07-22 19:59:12 +0800 | [diff] [blame] | 74 | #define TIMER_LOAD_COUNT_L 0x00 |
| 75 | #define TIMER_LOAD_COUNT_H 0x04 |
| 76 | #define TIMER_CONTROL_REG 0x10 |
| 77 | #define TIMER_EN 0x1 |
| 78 | #define TIMER_FMODE BIT(0) |
| 79 | #define TIMER_RMODE BIT(1) |
| 80 | |
| 81 | __weak void rockchip_stimer_init(void) |
| 82 | { |
Johan Jonker | 87affc3 | 2022-04-09 18:55:03 +0200 | [diff] [blame] | 83 | #if defined(CONFIG_ROCKCHIP_STIMER_BASE) |
Kever Yang | 1d7cc72a | 2019-07-22 19:59:12 +0800 | [diff] [blame] | 84 | /* If Timer already enabled, don't re-init it */ |
| 85 | u32 reg = readl(CONFIG_ROCKCHIP_STIMER_BASE + TIMER_CONTROL_REG); |
| 86 | |
| 87 | if (reg & TIMER_EN) |
| 88 | return; |
| 89 | #ifndef CONFIG_ARM64 |
| 90 | asm volatile("mcr p15, 0, %0, c14, c0, 0" |
Peng Fan | e7c5939 | 2022-04-13 17:47:22 +0800 | [diff] [blame] | 91 | : : "r"(CONFIG_COUNTER_FREQUENCY)); |
Kever Yang | 1d7cc72a | 2019-07-22 19:59:12 +0800 | [diff] [blame] | 92 | #endif |
| 93 | writel(0, CONFIG_ROCKCHIP_STIMER_BASE + TIMER_CONTROL_REG); |
| 94 | writel(0xffffffff, CONFIG_ROCKCHIP_STIMER_BASE); |
| 95 | writel(0xffffffff, CONFIG_ROCKCHIP_STIMER_BASE + 4); |
| 96 | writel(TIMER_EN | TIMER_FMODE, CONFIG_ROCKCHIP_STIMER_BASE + |
| 97 | TIMER_CONTROL_REG); |
Kever Yang | 1d7cc72a | 2019-07-22 19:59:12 +0800 | [diff] [blame] | 98 | #endif |
Johan Jonker | 87affc3 | 2022-04-09 18:55:03 +0200 | [diff] [blame] | 99 | } |
Kever Yang | 1d7cc72a | 2019-07-22 19:59:12 +0800 | [diff] [blame] | 100 | |
| 101 | __weak int board_early_init_f(void) |
| 102 | { |
| 103 | return 0; |
| 104 | } |
| 105 | |
| 106 | __weak int arch_cpu_init(void) |
| 107 | { |
| 108 | return 0; |
| 109 | } |
| 110 | |
| 111 | void board_init_f(ulong dummy) |
| 112 | { |
| 113 | int ret; |
Kever Yang | 1d7cc72a | 2019-07-22 19:59:12 +0800 | [diff] [blame] | 114 | |
Kever Yang | 1d7cc72a | 2019-07-22 19:59:12 +0800 | [diff] [blame] | 115 | board_early_init_f(); |
| 116 | |
| 117 | ret = spl_early_init(); |
| 118 | if (ret) { |
| 119 | printf("spl_early_init() failed: %d\n", ret); |
| 120 | hang(); |
| 121 | } |
| 122 | arch_cpu_init(); |
Johan Jonker | 87affc3 | 2022-04-09 18:55:03 +0200 | [diff] [blame] | 123 | |
Thomas Hebb | 3fe4ec8 | 2019-11-15 08:48:55 -0800 | [diff] [blame] | 124 | rockchip_stimer_init(); |
Johan Jonker | 87affc3 | 2022-04-09 18:55:03 +0200 | [diff] [blame] | 125 | |
Thomas Hebb | 3fe4ec8 | 2019-11-15 08:48:55 -0800 | [diff] [blame] | 126 | #ifdef CONFIG_SYS_ARCH_TIMER |
| 127 | /* Init ARM arch timer in arch/arm/cpu/armv7/arch_timer.c */ |
| 128 | timer_init(); |
| 129 | #endif |
Heiko Stuebner | d14cd61 | 2020-05-25 19:57:24 +0200 | [diff] [blame] | 130 | #if !defined(CONFIG_TPL) || defined(CONFIG_SPL_RAM) |
Kever Yang | 1d7cc72a | 2019-07-22 19:59:12 +0800 | [diff] [blame] | 131 | debug("\nspl:init dram\n"); |
Heiko Stuebner | d14cd61 | 2020-05-25 19:57:24 +0200 | [diff] [blame] | 132 | ret = dram_init(); |
Kever Yang | 1d7cc72a | 2019-07-22 19:59:12 +0800 | [diff] [blame] | 133 | if (ret) { |
| 134 | printf("DRAM init failed: %d\n", ret); |
| 135 | return; |
| 136 | } |
Heiko Stuebner | d14cd61 | 2020-05-25 19:57:24 +0200 | [diff] [blame] | 137 | gd->ram_top = gd->ram_base + get_effective_memsize(); |
| 138 | gd->ram_top = board_get_usable_ram_top(gd->ram_size); |
Kever Yang | 1d7cc72a | 2019-07-22 19:59:12 +0800 | [diff] [blame] | 139 | #endif |
Kever Yang | 1d7cc72a | 2019-07-22 19:59:12 +0800 | [diff] [blame] | 140 | preloader_console_init(); |
| 141 | } |