Hai Pham | 747a7ab | 2020-05-21 20:14:05 +0700 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0+ |
| 2 | /* |
| 3 | * board/renesas/falcon/falcon.c |
| 4 | * This file is Falcon board support. |
| 5 | * |
| 6 | * Copyright (C) 2020 Renesas Electronics Corp. |
| 7 | */ |
| 8 | |
Marek Vasut | 97a070b | 2024-02-27 17:05:54 +0100 | [diff] [blame] | 9 | #include <asm/arch/renesas.h> |
Hai Pham | 747a7ab | 2020-05-21 20:14:05 +0700 | [diff] [blame] | 10 | #include <asm/arch/sys_proto.h> |
| 11 | #include <asm/global_data.h> |
| 12 | #include <asm/io.h> |
| 13 | #include <asm/mach-types.h> |
| 14 | #include <asm/processor.h> |
| 15 | #include <linux/errno.h> |
Hai Pham | 89b45d4 | 2023-02-28 00:02:18 +0100 | [diff] [blame] | 16 | #include <asm/system.h> |
Hai Pham | 747a7ab | 2020-05-21 20:14:05 +0700 | [diff] [blame] | 17 | |
| 18 | DECLARE_GLOBAL_DATA_PTR; |
| 19 | |
| 20 | #define CPGWPR 0xE6150000 |
| 21 | #define CPGWPCR 0xE6150004 |
| 22 | |
Koji Matsuoka | 3528c7a | 2020-07-21 15:21:53 +0900 | [diff] [blame] | 23 | #define EXTAL_CLK 16666600u |
| 24 | #define CNTCR_BASE 0xE6080000 |
| 25 | #define CNTFID0 (CNTCR_BASE + 0x020) |
| 26 | #define CNTCR_EN BIT(0) |
| 27 | |
| 28 | static void init_generic_timer(void) |
| 29 | { |
| 30 | u32 freq; |
| 31 | |
| 32 | /* Set frequency data in CNTFID0 */ |
| 33 | freq = EXTAL_CLK; |
| 34 | |
| 35 | /* Update memory mapped and register based freqency */ |
| 36 | asm volatile ("msr cntfrq_el0, %0" :: "r" (freq)); |
| 37 | writel(freq, CNTFID0); |
| 38 | |
| 39 | /* Enable counter */ |
| 40 | setbits_le32(CNTCR_BASE, CNTCR_EN); |
| 41 | } |
| 42 | |
Koji Matsuoka | 69b7cc0 | 2020-07-16 12:11:16 +0900 | [diff] [blame] | 43 | /* Distributor Registers */ |
| 44 | #define GICD_BASE 0xF1000000 |
| 45 | |
| 46 | /* ReDistributor Registers for Control and Physical LPIs */ |
| 47 | #define GICR_LPI_BASE 0xF1060000 |
| 48 | #define GICR_WAKER 0x0014 |
| 49 | #define GICR_PWRR 0x0024 |
| 50 | #define GICR_LPI_WAKER (GICR_LPI_BASE + GICR_WAKER) |
| 51 | #define GICR_LPI_PWRR (GICR_LPI_BASE + GICR_PWRR) |
| 52 | |
| 53 | /* ReDistributor Registers for SGIs and PPIs */ |
| 54 | #define GICR_SGI_BASE 0xF1070000 |
| 55 | #define GICR_IGROUPR0 0x0080 |
| 56 | |
| 57 | static void init_gic_v3(void) |
| 58 | { |
| 59 | /* GIC v3 power on */ |
| 60 | writel(0x00000002, (GICR_LPI_PWRR)); |
| 61 | |
| 62 | /* Wait till the WAKER_CA_BIT changes to 0 */ |
| 63 | writel(readl(GICR_LPI_WAKER) & ~0x00000002, (GICR_LPI_WAKER)); |
| 64 | while (readl(GICR_LPI_WAKER) & 0x00000004) |
| 65 | ; |
| 66 | |
| 67 | writel(0xffffffff, GICR_SGI_BASE + GICR_IGROUPR0); |
| 68 | } |
| 69 | |
Koji Matsuoka | 3528c7a | 2020-07-21 15:21:53 +0900 | [diff] [blame] | 70 | void s_init(void) |
| 71 | { |
Hai Pham | 89b45d4 | 2023-02-28 00:02:18 +0100 | [diff] [blame] | 72 | if (current_el() == 3) |
| 73 | init_generic_timer(); |
Koji Matsuoka | 3528c7a | 2020-07-21 15:21:53 +0900 | [diff] [blame] | 74 | } |
| 75 | |
Hai Pham | 747a7ab | 2020-05-21 20:14:05 +0700 | [diff] [blame] | 76 | int board_early_init_f(void) |
| 77 | { |
| 78 | /* Unlock CPG access */ |
| 79 | writel(0x5A5AFFFF, CPGWPR); |
| 80 | writel(0xA5A50000, CPGWPCR); |
| 81 | |
| 82 | return 0; |
| 83 | } |
| 84 | |
Hai Pham | 8872b48 | 2023-02-28 00:02:19 +0100 | [diff] [blame] | 85 | #define RST_BASE 0xE6160000 /* Domain0 */ |
Hai Pham | 8872b48 | 2023-02-28 00:02:19 +0100 | [diff] [blame] | 86 | #define RST_WDTRSTCR (RST_BASE + 0x10) |
| 87 | #define RST_RWDT 0xA55A8002 |
| 88 | |
Hai Pham | 747a7ab | 2020-05-21 20:14:05 +0700 | [diff] [blame] | 89 | int board_init(void) |
| 90 | { |
| 91 | /* address of boot parameters */ |
Simon Glass | 72cc538 | 2022-10-20 18:22:39 -0600 | [diff] [blame] | 92 | gd->bd->bi_boot_params = CONFIG_TEXT_BASE + 0x50000; |
Hai Pham | 747a7ab | 2020-05-21 20:14:05 +0700 | [diff] [blame] | 93 | |
Hai Pham | 8872b48 | 2023-02-28 00:02:19 +0100 | [diff] [blame] | 94 | if (current_el() == 3) { |
Hai Pham | 89b45d4 | 2023-02-28 00:02:18 +0100 | [diff] [blame] | 95 | init_gic_v3(); |
Koji Matsuoka | 69b7cc0 | 2020-07-16 12:11:16 +0900 | [diff] [blame] | 96 | |
Hai Pham | 8872b48 | 2023-02-28 00:02:19 +0100 | [diff] [blame] | 97 | /* Enable RWDT reset */ |
| 98 | writel(RST_RWDT, RST_WDTRSTCR); |
| 99 | } |
| 100 | |
Hai Pham | 747a7ab | 2020-05-21 20:14:05 +0700 | [diff] [blame] | 101 | return 0; |
| 102 | } |