Kever Yang | 18f8508 | 2019-07-09 22:05:55 +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> |
Simon Glass | b2412dd | 2023-01-07 14:57:30 -0700 | [diff] [blame] | 7 | #include <bootstage.h> |
Kever Yang | 18f8508 | 2019-07-09 22:05:55 +0800 | [diff] [blame] | 8 | #include <debug_uart.h> |
| 9 | #include <dm.h> |
Simon Glass | db41d65 | 2019-12-28 10:45:07 -0700 | [diff] [blame] | 10 | #include <hang.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 | 18f8508 | 2019-07-09 22:05:55 +0800 | [diff] [blame] | 13 | #include <ram.h> |
| 14 | #include <spl.h> |
| 15 | #include <version.h> |
| 16 | #include <asm/io.h> |
| 17 | #include <asm/arch-rockchip/bootrom.h> |
Simon Glass | cd93d62 | 2020-05-10 11:40:13 -0600 | [diff] [blame] | 18 | #include <linux/bitops.h> |
Johan Jonker | 30a7b82 | 2022-04-09 18:55:05 +0200 | [diff] [blame] | 19 | #include <linux/kconfig.h> |
Kever Yang | 18f8508 | 2019-07-09 22:05:55 +0800 | [diff] [blame] | 20 | |
Pali Rohár | 121a165 | 2021-08-02 15:18:38 +0200 | [diff] [blame] | 21 | #if CONFIG_IS_ENABLED(BANNER_PRINT) |
| 22 | #include <timestamp.h> |
| 23 | #endif |
| 24 | |
Kever Yang | 18f8508 | 2019-07-09 22:05:55 +0800 | [diff] [blame] | 25 | #define TIMER_LOAD_COUNT_L 0x00 |
| 26 | #define TIMER_LOAD_COUNT_H 0x04 |
| 27 | #define TIMER_CONTROL_REG 0x10 |
| 28 | #define TIMER_EN 0x1 |
| 29 | #define TIMER_FMODE BIT(0) |
| 30 | #define TIMER_RMODE BIT(1) |
| 31 | |
| 32 | __weak void rockchip_stimer_init(void) |
| 33 | { |
Johan Jonker | d23f55d | 2022-04-09 18:55:04 +0200 | [diff] [blame] | 34 | #if defined(CONFIG_ROCKCHIP_STIMER_BASE) |
Kever Yang | 18f8508 | 2019-07-09 22:05:55 +0800 | [diff] [blame] | 35 | /* If Timer already enabled, don't re-init it */ |
| 36 | u32 reg = readl(CONFIG_ROCKCHIP_STIMER_BASE + TIMER_CONTROL_REG); |
| 37 | |
| 38 | if (reg & TIMER_EN) |
| 39 | return; |
| 40 | |
| 41 | #ifndef CONFIG_ARM64 |
| 42 | asm volatile("mcr p15, 0, %0, c14, c0, 0" |
Peng Fan | 151a030 | 2022-04-13 17:47:22 +0800 | [diff] [blame] | 43 | : : "r"(CONFIG_COUNTER_FREQUENCY)); |
Kever Yang | 18f8508 | 2019-07-09 22:05:55 +0800 | [diff] [blame] | 44 | #endif |
| 45 | |
| 46 | writel(0, CONFIG_ROCKCHIP_STIMER_BASE + TIMER_CONTROL_REG); |
| 47 | writel(0xffffffff, CONFIG_ROCKCHIP_STIMER_BASE); |
| 48 | writel(0xffffffff, CONFIG_ROCKCHIP_STIMER_BASE + 4); |
| 49 | writel(TIMER_EN | TIMER_FMODE, CONFIG_ROCKCHIP_STIMER_BASE + |
| 50 | TIMER_CONTROL_REG); |
Johan Jonker | d23f55d | 2022-04-09 18:55:04 +0200 | [diff] [blame] | 51 | #endif |
Kever Yang | 18f8508 | 2019-07-09 22:05:55 +0800 | [diff] [blame] | 52 | } |
| 53 | |
| 54 | void board_init_f(ulong dummy) |
| 55 | { |
| 56 | struct udevice *dev; |
| 57 | int ret; |
| 58 | |
Simon Glass | 2a73606 | 2021-08-08 12:20:12 -0600 | [diff] [blame] | 59 | #if defined(CONFIG_DEBUG_UART) && defined(CONFIG_TPL_SERIAL) |
Kever Yang | 18f8508 | 2019-07-09 22:05:55 +0800 | [diff] [blame] | 60 | /* |
| 61 | * Debug UART can be used from here if required: |
| 62 | * |
| 63 | * debug_uart_init(); |
| 64 | * printch('a'); |
| 65 | * printhex8(0x1234); |
| 66 | * printascii("string"); |
| 67 | */ |
| 68 | debug_uart_init(); |
Chris Webb | 89e3917 | 2019-07-19 14:23:55 +0100 | [diff] [blame] | 69 | #ifdef CONFIG_TPL_BANNER_PRINT |
Kever Yang | 18f8508 | 2019-07-09 22:05:55 +0800 | [diff] [blame] | 70 | printascii("\nU-Boot TPL " PLAIN_VERSION " (" U_BOOT_DATE " - " \ |
| 71 | U_BOOT_TIME ")\n"); |
| 72 | #endif |
Chris Webb | 89e3917 | 2019-07-19 14:23:55 +0100 | [diff] [blame] | 73 | #endif |
Simon Glass | b2412dd | 2023-01-07 14:57:30 -0700 | [diff] [blame] | 74 | /* Init secure timer */ |
| 75 | rockchip_stimer_init(); |
| 76 | |
Kever Yang | 18f8508 | 2019-07-09 22:05:55 +0800 | [diff] [blame] | 77 | ret = spl_early_init(); |
| 78 | if (ret) { |
| 79 | debug("spl_early_init() failed: %d\n", ret); |
| 80 | hang(); |
| 81 | } |
| 82 | |
Johan Jonker | 30a7b82 | 2022-04-09 18:55:05 +0200 | [diff] [blame] | 83 | /* Init ARM arch timer */ |
| 84 | if (IS_ENABLED(CONFIG_SYS_ARCH_TIMER)) |
| 85 | timer_init(); |
Kever Yang | 18f8508 | 2019-07-09 22:05:55 +0800 | [diff] [blame] | 86 | |
| 87 | ret = uclass_get_device(UCLASS_RAM, 0, &dev); |
| 88 | if (ret) { |
| 89 | printf("DRAM init failed: %d\n", ret); |
| 90 | return; |
| 91 | } |
| 92 | } |
| 93 | |
Peng Fan | cda789a | 2019-08-07 06:40:53 +0000 | [diff] [blame] | 94 | int board_return_to_bootrom(struct spl_image_info *spl_image, |
| 95 | struct spl_boot_device *bootdev) |
Kever Yang | 18f8508 | 2019-07-09 22:05:55 +0800 | [diff] [blame] | 96 | { |
Simon Glass | b2412dd | 2023-01-07 14:57:30 -0700 | [diff] [blame] | 97 | #ifdef CONFIG_BOOTSTAGE_STASH |
| 98 | int ret; |
| 99 | |
| 100 | bootstage_mark_name(BOOTSTAGE_ID_END_TPL, "end tpl"); |
| 101 | ret = bootstage_stash((void *)CONFIG_BOOTSTAGE_STASH_ADDR, |
| 102 | CONFIG_BOOTSTAGE_STASH_SIZE); |
| 103 | if (ret) |
| 104 | debug("Failed to stash bootstage: err=%d\n", ret); |
| 105 | #endif |
Kever Yang | 18f8508 | 2019-07-09 22:05:55 +0800 | [diff] [blame] | 106 | back_to_bootrom(BROM_BOOT_NEXTSTAGE); |
Peng Fan | cda789a | 2019-08-07 06:40:53 +0000 | [diff] [blame] | 107 | |
| 108 | return 0; |
Kever Yang | 18f8508 | 2019-07-09 22:05:55 +0800 | [diff] [blame] | 109 | } |
| 110 | |
| 111 | u32 spl_boot_device(void) |
| 112 | { |
| 113 | return BOOT_DEVICE_BOOTROM; |
| 114 | } |