Ley Foon Tan | f80cb34 | 2018-05-24 00:17:24 +0800 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0 |
| 2 | /* |
| 3 | * Copyright (C) 2016-2018 Intel Corporation <www.intel.com> |
Alif Zakuan Yuslaimi | 61f598d | 2025-02-18 16:35:00 +0800 | [diff] [blame] | 4 | * Copyright (C) 2025 Altera Corporation <www.altera.com> |
Ley Foon Tan | f80cb34 | 2018-05-24 00:17:24 +0800 | [diff] [blame] | 5 | * |
| 6 | */ |
| 7 | |
| 8 | #include <altera.h> |
Tingting Meng | a1a24f1 | 2025-02-21 21:49:41 +0800 | [diff] [blame^] | 9 | #include <env.h> |
| 10 | #include <errno.h> |
| 11 | #include <init.h> |
| 12 | #include <log.h> |
Alif Zakuan Yuslaimi | 7125782 | 2025-02-18 16:35:01 +0800 | [diff] [blame] | 13 | #include <asm/arch/board.h> |
Chee Hong Ang | f18fe84 | 2020-07-10 23:52:32 +0800 | [diff] [blame] | 14 | #include <asm/arch/mailbox_s10.h> |
| 15 | #include <asm/arch/misc.h> |
Ley Foon Tan | f80cb34 | 2018-05-24 00:17:24 +0800 | [diff] [blame] | 16 | #include <asm/arch/reset_manager.h> |
| 17 | #include <asm/arch/system_manager.h> |
Siew Chin Lim | e377bf2 | 2021-08-10 11:26:35 +0800 | [diff] [blame] | 18 | #include <asm/io.h> |
Tingting Meng | a1a24f1 | 2025-02-21 21:49:41 +0800 | [diff] [blame^] | 19 | #include <asm/system.h> |
Siew Chin Lim | e377bf2 | 2021-08-10 11:26:35 +0800 | [diff] [blame] | 20 | #include <asm/global_data.h> |
Tom Rini | 3fb5b2f | 2022-03-30 18:07:23 -0400 | [diff] [blame] | 21 | #include <mach/clock_manager.h> |
Ley Foon Tan | f80cb34 | 2018-05-24 00:17:24 +0800 | [diff] [blame] | 22 | |
| 23 | DECLARE_GLOBAL_DATA_PTR; |
| 24 | |
Ley Foon Tan | f80cb34 | 2018-05-24 00:17:24 +0800 | [diff] [blame] | 25 | /* |
Ang, Chee Hong | ff14f16 | 2018-12-19 18:35:15 -0800 | [diff] [blame] | 26 | * FPGA programming support for SoC FPGA Stratix 10 |
| 27 | */ |
| 28 | static Altera_desc altera_fpga[] = { |
| 29 | { |
| 30 | /* Family */ |
Chee Hong Ang | 1419245 | 2020-08-07 11:50:03 +0800 | [diff] [blame] | 31 | Intel_FPGA_SDM_Mailbox, |
Ang, Chee Hong | ff14f16 | 2018-12-19 18:35:15 -0800 | [diff] [blame] | 32 | /* Interface type */ |
| 33 | secure_device_manager_mailbox, |
| 34 | /* No limitation as additional data will be ignored */ |
| 35 | -1, |
| 36 | /* No device function table */ |
| 37 | NULL, |
| 38 | /* Base interface address specified in driver */ |
| 39 | NULL, |
| 40 | /* No cookie implementation */ |
| 41 | 0 |
| 42 | }, |
| 43 | }; |
| 44 | |
Ley Foon Tan | f80cb34 | 2018-05-24 00:17:24 +0800 | [diff] [blame] | 45 | /* |
Tingting Meng | a1a24f1 | 2025-02-21 21:49:41 +0800 | [diff] [blame^] | 46 | * The Agilex5 platform has enabled the bloblist feature, and the bloblist |
| 47 | * address and size are initialized based on the defconfig settings. |
| 48 | * During the SPL phase, this function is used to prevent the bloblist |
| 49 | * from initializing its address and size with the saved boot parameters, |
| 50 | * which may have been incorrectly set. |
| 51 | */ |
| 52 | void save_boot_params(unsigned long r0, unsigned long r1, unsigned long r2, |
| 53 | unsigned long r3) |
| 54 | { |
| 55 | save_boot_params_ret(); |
| 56 | } |
| 57 | |
| 58 | /* |
Ley Foon Tan | f80cb34 | 2018-05-24 00:17:24 +0800 | [diff] [blame] | 59 | * Print CPU information |
| 60 | */ |
| 61 | #if defined(CONFIG_DISPLAY_CPUINFO) |
| 62 | int print_cpuinfo(void) |
| 63 | { |
Alif Zakuan Yuslaimi | 61f598d | 2025-02-18 16:35:00 +0800 | [diff] [blame] | 64 | printf("CPU: Intel FPGA SoCFPGA Platform (ARMv8 64bit Cortex-%s)\n", |
| 65 | IS_ENABLED(CONFIG_TARGET_SOCFPGA_AGILEX5) ? "A55/A76" : "A53"); |
Ley Foon Tan | f80cb34 | 2018-05-24 00:17:24 +0800 | [diff] [blame] | 66 | |
| 67 | return 0; |
| 68 | } |
| 69 | #endif |
| 70 | |
| 71 | #ifdef CONFIG_ARCH_MISC_INIT |
| 72 | int arch_misc_init(void) |
| 73 | { |
| 74 | char qspi_string[13]; |
Alif Zakuan Yuslaimi | 7125782 | 2025-02-18 16:35:01 +0800 | [diff] [blame] | 75 | unsigned long id; |
Ley Foon Tan | f80cb34 | 2018-05-24 00:17:24 +0800 | [diff] [blame] | 76 | |
| 77 | sprintf(qspi_string, "<0x%08x>", cm_get_qspi_controller_clk_hz()); |
| 78 | env_set("qspi_clock", qspi_string); |
| 79 | |
Alif Zakuan Yuslaimi | 7125782 | 2025-02-18 16:35:01 +0800 | [diff] [blame] | 80 | /* Export board_id as environment variable */ |
| 81 | id = socfpga_get_board_id(); |
| 82 | env_set_ulong("board_id", id); |
| 83 | |
Ley Foon Tan | f80cb34 | 2018-05-24 00:17:24 +0800 | [diff] [blame] | 84 | return 0; |
| 85 | } |
| 86 | #endif |
| 87 | |
| 88 | int arch_early_init_r(void) |
| 89 | { |
Ang, Chee Hong | ff14f16 | 2018-12-19 18:35:15 -0800 | [diff] [blame] | 90 | socfpga_fpga_add(&altera_fpga[0]); |
| 91 | |
Ley Foon Tan | f80cb34 | 2018-05-24 00:17:24 +0800 | [diff] [blame] | 92 | return 0; |
| 93 | } |
| 94 | |
Chee Hong Ang | 61e9199 | 2020-08-06 11:56:29 +0800 | [diff] [blame] | 95 | /* Return 1 if FPGA is ready otherwise return 0 */ |
| 96 | int is_fpga_config_ready(void) |
| 97 | { |
| 98 | return (readl(socfpga_get_sysmgr_addr() + SYSMGR_SOC64_FPGA_CONFIG) & |
| 99 | SYSMGR_FPGACONFIG_READY_MASK) == SYSMGR_FPGACONFIG_READY_MASK; |
| 100 | } |
| 101 | |
Marek Vasut | 713a8a2 | 2019-04-16 22:28:08 +0200 | [diff] [blame] | 102 | void do_bridge_reset(int enable, unsigned int mask) |
Ley Foon Tan | f80cb34 | 2018-05-24 00:17:24 +0800 | [diff] [blame] | 103 | { |
Ang, Chee Hong | d740445 | 2019-05-03 01:18:27 -0700 | [diff] [blame] | 104 | /* Check FPGA status before bridge enable */ |
Chee Hong Ang | 61e9199 | 2020-08-06 11:56:29 +0800 | [diff] [blame] | 105 | if (!is_fpga_config_ready()) { |
| 106 | puts("FPGA not ready. Bridge reset aborted!\n"); |
| 107 | return; |
Ang, Chee Hong | d740445 | 2019-05-03 01:18:27 -0700 | [diff] [blame] | 108 | } |
| 109 | |
Ley Foon Tan | f80cb34 | 2018-05-24 00:17:24 +0800 | [diff] [blame] | 110 | socfpga_bridges_reset(enable); |
| 111 | } |