blob: e0b2b4237e171d6d9610a9e3c21ac9b9a72a01ae [file] [log] [blame]
Ley Foon Tanf80cb342018-05-24 00:17:24 +08001// SPDX-License-Identifier: GPL-2.0
2/*
3 * Copyright (C) 2016-2018 Intel Corporation <www.intel.com>
Alif Zakuan Yuslaimi61f598d2025-02-18 16:35:00 +08004 * Copyright (C) 2025 Altera Corporation <www.altera.com>
Ley Foon Tanf80cb342018-05-24 00:17:24 +08005 *
6 */
7
8#include <altera.h>
Tingting Menga1a24f12025-02-21 21:49:41 +08009#include <env.h>
10#include <errno.h>
11#include <init.h>
12#include <log.h>
Alif Zakuan Yuslaimi71257822025-02-18 16:35:01 +080013#include <asm/arch/board.h>
Chee Hong Angf18fe842020-07-10 23:52:32 +080014#include <asm/arch/mailbox_s10.h>
15#include <asm/arch/misc.h>
Ley Foon Tanf80cb342018-05-24 00:17:24 +080016#include <asm/arch/reset_manager.h>
17#include <asm/arch/system_manager.h>
Siew Chin Lime377bf22021-08-10 11:26:35 +080018#include <asm/io.h>
Tingting Menga1a24f12025-02-21 21:49:41 +080019#include <asm/system.h>
Siew Chin Lime377bf22021-08-10 11:26:35 +080020#include <asm/global_data.h>
Tom Rini3fb5b2f2022-03-30 18:07:23 -040021#include <mach/clock_manager.h>
Ley Foon Tanf80cb342018-05-24 00:17:24 +080022
23DECLARE_GLOBAL_DATA_PTR;
24
Ley Foon Tanf80cb342018-05-24 00:17:24 +080025/*
Ang, Chee Hongff14f162018-12-19 18:35:15 -080026 * FPGA programming support for SoC FPGA Stratix 10
27 */
28static Altera_desc altera_fpga[] = {
29 {
30 /* Family */
Chee Hong Ang14192452020-08-07 11:50:03 +080031 Intel_FPGA_SDM_Mailbox,
Ang, Chee Hongff14f162018-12-19 18:35:15 -080032 /* 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 Tanf80cb342018-05-24 00:17:24 +080045/*
Tingting Menga1a24f12025-02-21 21:49:41 +080046 * 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 */
52void 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 Tanf80cb342018-05-24 00:17:24 +080059 * Print CPU information
60 */
61#if defined(CONFIG_DISPLAY_CPUINFO)
62int print_cpuinfo(void)
63{
Alif Zakuan Yuslaimi61f598d2025-02-18 16:35:00 +080064 printf("CPU: Intel FPGA SoCFPGA Platform (ARMv8 64bit Cortex-%s)\n",
65 IS_ENABLED(CONFIG_TARGET_SOCFPGA_AGILEX5) ? "A55/A76" : "A53");
Ley Foon Tanf80cb342018-05-24 00:17:24 +080066
67 return 0;
68}
69#endif
70
71#ifdef CONFIG_ARCH_MISC_INIT
72int arch_misc_init(void)
73{
74 char qspi_string[13];
Alif Zakuan Yuslaimi71257822025-02-18 16:35:01 +080075 unsigned long id;
Ley Foon Tanf80cb342018-05-24 00:17:24 +080076
77 sprintf(qspi_string, "<0x%08x>", cm_get_qspi_controller_clk_hz());
78 env_set("qspi_clock", qspi_string);
79
Alif Zakuan Yuslaimi71257822025-02-18 16:35:01 +080080 /* Export board_id as environment variable */
81 id = socfpga_get_board_id();
82 env_set_ulong("board_id", id);
83
Ley Foon Tanf80cb342018-05-24 00:17:24 +080084 return 0;
85}
86#endif
87
88int arch_early_init_r(void)
89{
Ang, Chee Hongff14f162018-12-19 18:35:15 -080090 socfpga_fpga_add(&altera_fpga[0]);
91
Ley Foon Tanf80cb342018-05-24 00:17:24 +080092 return 0;
93}
94
Chee Hong Ang61e91992020-08-06 11:56:29 +080095/* Return 1 if FPGA is ready otherwise return 0 */
96int 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 Vasut713a8a22019-04-16 22:28:08 +0200102void do_bridge_reset(int enable, unsigned int mask)
Ley Foon Tanf80cb342018-05-24 00:17:24 +0800103{
Ang, Chee Hongd7404452019-05-03 01:18:27 -0700104 /* Check FPGA status before bridge enable */
Chee Hong Ang61e91992020-08-06 11:56:29 +0800105 if (!is_fpga_config_ready()) {
106 puts("FPGA not ready. Bridge reset aborted!\n");
107 return;
Ang, Chee Hongd7404452019-05-03 01:18:27 -0700108 }
109
Ley Foon Tanf80cb342018-05-24 00:17:24 +0800110 socfpga_bridges_reset(enable);
111}