Hai Pham | ff3812c | 2023-02-28 22:37:08 +0100 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0+ |
| 2 | /* |
Marek Vasut | 10a37c8 | 2024-12-12 14:37:34 +0100 | [diff] [blame] | 3 | * board/renesas/rcar-common/gen4-common.c |
Hai Pham | ff3812c | 2023-02-28 22:37:08 +0100 | [diff] [blame] | 4 | * |
Marek Vasut | 10a37c8 | 2024-12-12 14:37:34 +0100 | [diff] [blame] | 5 | * Copyright (C) 2021-2024 Renesas Electronics Corp. |
Hai Pham | ff3812c | 2023-02-28 22:37:08 +0100 | [diff] [blame] | 6 | */ |
| 7 | |
Marek Vasut | 97a070b | 2024-02-27 17:05:54 +0100 | [diff] [blame] | 8 | #include <asm/arch/renesas.h> |
Hai Pham | ff3812c | 2023-02-28 22:37:08 +0100 | [diff] [blame] | 9 | #include <asm/arch/sys_proto.h> |
| 10 | #include <asm/global_data.h> |
| 11 | #include <asm/io.h> |
| 12 | #include <asm/mach-types.h> |
| 13 | #include <asm/processor.h> |
Hai Pham | ff3812c | 2023-02-28 22:37:08 +0100 | [diff] [blame] | 14 | #include <asm/system.h> |
Marek Vasut | 10a37c8 | 2024-12-12 14:37:34 +0100 | [diff] [blame] | 15 | #include <linux/errno.h> |
| 16 | |
| 17 | #define RST_BASE 0xE6160000 /* Domain0 */ |
| 18 | #define RST_WDTRSTCR (RST_BASE + 0x10) |
| 19 | #define RST_RWDT 0xA55A8002 |
Hai Pham | ff3812c | 2023-02-28 22:37:08 +0100 | [diff] [blame] | 20 | |
| 21 | DECLARE_GLOBAL_DATA_PTR; |
| 22 | |
| 23 | static void init_generic_timer(void) |
| 24 | { |
| 25 | const u32 freq = CONFIG_SYS_CLK_FREQ; |
| 26 | |
| 27 | /* Update memory mapped and register based freqency */ |
| 28 | asm volatile ("msr cntfrq_el0, %0" :: "r" (freq)); |
| 29 | writel(freq, CNTFID0); |
| 30 | |
| 31 | /* Enable counter */ |
| 32 | setbits_le32(CNTCR_BASE, CNTCR_EN); |
| 33 | } |
| 34 | |
| 35 | static void init_gic_v3(void) |
| 36 | { |
Marek Vasut | 00eed1e | 2024-01-21 18:33:12 +0100 | [diff] [blame] | 37 | /* GIC v3 power on */ |
Hai Pham | ff3812c | 2023-02-28 22:37:08 +0100 | [diff] [blame] | 38 | writel(BIT(1), GICR_LPI_PWRR); |
| 39 | |
| 40 | /* Wait till the WAKER_CA_BIT changes to 0 */ |
| 41 | clrbits_le32(GICR_LPI_WAKER, BIT(1)); |
| 42 | while (readl(GICR_LPI_WAKER) & BIT(2)) |
| 43 | ; |
| 44 | |
| 45 | writel(0xffffffff, GICR_SGI_BASE + GICR_IGROUPR0); |
| 46 | } |
| 47 | |
| 48 | void s_init(void) |
| 49 | { |
| 50 | if (current_el() == 3) |
| 51 | init_generic_timer(); |
| 52 | } |
| 53 | |
| 54 | int board_early_init_f(void) |
| 55 | { |
| 56 | /* Unlock CPG access */ |
| 57 | writel(0x5A5AFFFF, CPGWPR); |
| 58 | writel(0xA5A50000, CPGWPCR); |
| 59 | |
| 60 | return 0; |
| 61 | } |
| 62 | |
| 63 | int board_init(void) |
| 64 | { |
Marek Vasut | 10a37c8 | 2024-12-12 14:37:34 +0100 | [diff] [blame] | 65 | if (current_el() != 3) |
| 66 | return 0; |
| 67 | init_gic_v3(); |
| 68 | |
| 69 | /* Enable RWDT reset on V3U in EL3 */ |
| 70 | if (IS_ENABLED(CONFIG_R8A779A0) && |
| 71 | renesas_get_cpu_type() == RENESAS_CPU_TYPE_R8A779A0) { |
| 72 | writel(RST_RWDT, RST_WDTRSTCR); |
| 73 | } |
Hai Pham | ff3812c | 2023-02-28 22:37:08 +0100 | [diff] [blame] | 74 | |
| 75 | return 0; |
| 76 | } |
Marek Vasut | f48b133 | 2024-12-12 14:38:27 +0100 | [diff] [blame] | 77 | |
| 78 | #define RST_BASE 0xE6160000 /* Domain0 */ |
| 79 | #define RST_SRESCR0 (RST_BASE + 0x18) |
| 80 | #define RST_SPRES 0x5AA58000 |
| 81 | |
| 82 | void __weak reset_cpu(void) |
| 83 | { |
| 84 | writel(RST_SPRES, RST_SRESCR0); |
| 85 | } |
| 86 | |
| 87 | int ft_board_setup(void *blob, struct bd_info *bd) |
| 88 | { |
| 89 | return 0; |
| 90 | } |