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