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