blob: 616e1afe5de68365d4c45cd5257107fc18276376 [file] [log] [blame]
Tom Rini10e47792018-05-06 17:58:06 -04001// SPDX-License-Identifier: GPL-2.0+
Marek Vasut05204f62015-12-05 21:07:23 +01002/*
3 * Altera SoCFPGA common board code
4 *
5 * Copyright (C) 2015 Marek Vasut <marex@denx.de>
Marek Vasut05204f62015-12-05 21:07:23 +01006 */
7
Tom Riniabb9a042024-05-18 20:20:43 -06008#include <common.h>
Tien Fong Cheea5bfce32017-12-05 15:58:07 +08009#include <asm/arch/clock_manager.h>
Jit Loon Lim977071e2024-03-12 22:01:03 +080010#include <asm/arch/mailbox_s10.h>
Tien Fong Cheef3f525c2017-12-05 15:58:08 +080011#include <asm/arch/misc.h>
Siew Chin Lim2492d592021-03-01 20:04:11 +080012#include <asm/arch/reset_manager.h>
13#include <asm/arch/secure_vab.h>
Jit Loon Lim977071e2024-03-12 22:01:03 +080014#include <asm/arch/smc_api.h>
Simon Glass3ba929a2020-10-30 21:38:53 -060015#include <asm/global_data.h>
Marek Vasut05204f62015-12-05 21:07:23 +010016#include <asm/io.h>
Siew Chin Lim2492d592021-03-01 20:04:11 +080017#include <errno.h>
18#include <fdtdec.h>
19#include <hang.h>
20#include <image.h>
21#include <init.h>
Chee Hong Ang7cfcc0c2020-12-24 18:20:56 +080022#include <log.h>
Marek Vasut05204f62015-12-05 21:07:23 +010023#include <usb.h>
24#include <usb/dwc2_udc.h>
25
26DECLARE_GLOBAL_DATA_PTR;
27
Jit Loon Lim977071e2024-03-12 22:01:03 +080028#define DEFAULT_JTAG_USERCODE 0xFFFFFFFF
29
Marek Vasut72cc9582018-05-29 16:16:46 +020030void s_init(void) {
Ley Foon Tan27f05ac2018-07-12 19:13:34 +080031#ifndef CONFIG_ARM64
Marek Vasut72cc9582018-05-29 16:16:46 +020032 /*
Marek Vasut911a6652018-07-12 15:07:46 +020033 * Preconfigure ACTLR and CPACR, make sure Write Full Line of Zeroes
34 * is disabled in ACTLR.
Marek Vasut72cc9582018-05-29 16:16:46 +020035 * This is optional on CycloneV / ArriaV.
36 * This is mandatory on Arria10, otherwise Linux refuses to boot.
37 */
38 asm volatile(
39 "mcr p15, 0, %0, c1, c0, 1\n"
Marek Vasut911a6652018-07-12 15:07:46 +020040 "mcr p15, 0, %0, c1, c0, 2\n"
Marek Vasut72cc9582018-05-29 16:16:46 +020041 "isb\n"
42 "dsb\n"
43 ::"r"(0x0));
Ley Foon Tan27f05ac2018-07-12 19:13:34 +080044#endif
Marek Vasut72cc9582018-05-29 16:16:46 +020045}
Marek Vasut05204f62015-12-05 21:07:23 +010046
47/*
48 * Miscellaneous platform dependent initialisations
49 */
50int board_init(void)
51{
52 /* Address of boot parameters for ATAG (if ATAG is used) */
Tom Rinibb4dd962022-11-16 13:10:37 -050053 gd->bd->bi_boot_params = CFG_SYS_SDRAM_BASE + 0x100;
Marek Vasut05204f62015-12-05 21:07:23 +010054
55 return 0;
56}
57
Tien Fong Chee3710de72017-12-05 15:58:01 +080058int dram_init_banksize(void)
59{
60 fdtdec_setup_memory_banksize();
61
62 return 0;
63}
64
Marek Vasut05204f62015-12-05 21:07:23 +010065#ifdef CONFIG_USB_GADGET
66struct dwc2_plat_otg_data socfpga_otg_data = {
67 .usb_gusbcfg = 0x1417,
68};
69
70int board_usb_init(int index, enum usb_init_type init)
71{
72 int node[2], count;
73 fdt_addr_t addr;
74
75 count = fdtdec_find_aliases_for_id(gd->fdt_blob, "udc",
76 COMPAT_ALTERA_SOCFPGA_DWC2USB,
77 node, 2);
78 if (count <= 0) /* No controller found. */
79 return 0;
80
81 addr = fdtdec_get_addr(gd->fdt_blob, node[0], "reg");
82 if (addr == FDT_ADDR_T_NONE) {
83 printf("UDC Controller has no 'reg' property!\n");
84 return -EINVAL;
85 }
86
87 /* Patch the address from OF into the controller pdata. */
88 socfpga_otg_data.regs_otg = addr;
89
90 return dwc2_udc_probe(&socfpga_otg_data);
91}
92
93int g_dnl_board_usb_cable_connected(void)
94{
95 return 1;
96}
97#endif
Chee Hong Ang7cfcc0c2020-12-24 18:20:56 +080098
Jit Loon Lim977071e2024-03-12 22:01:03 +080099u8 socfpga_get_board_id(void)
Chee Hong Ang7cfcc0c2020-12-24 18:20:56 +0800100{
Jit Loon Lim977071e2024-03-12 22:01:03 +0800101 u8 board_id = 0;
102 u32 jtag_usercode;
103 int err;
Chee Hong Ang7cfcc0c2020-12-24 18:20:56 +0800104
Jit Loon Lim977071e2024-03-12 22:01:03 +0800105#if !IS_ENABLED(CONFIG_SPL_BUILD) && IS_ENABLED(CONFIG_SPL_ATF)
106 err = smc_get_usercode(&jtag_usercode);
107#else
108 u32 resp_len = 1;
109
110 err = mbox_send_cmd(MBOX_ID_UBOOT, MBOX_GET_USERCODE, MBOX_CMD_DIRECT, 0,
111 NULL, 0, &resp_len, &jtag_usercode);
112#endif
113
114 if (err) {
115 puts("Fail to read JTAG Usercode. Default Board ID to 0\n");
116 return board_id;
117 }
118
119 debug("Valid JTAG Usercode: %u\n", jtag_usercode);
120
121 if (jtag_usercode == DEFAULT_JTAG_USERCODE) {
122 debug("JTAG Usercode is not set. Default Board ID to 0\n");
123 } else if (jtag_usercode >= 0 && jtag_usercode <= 255) {
124 board_id = jtag_usercode;
125 debug("Valid JTAG Usercode. Set Board ID to %u\n", board_id);
126 } else {
127 puts("Board ID is not in range 0 to 255\n");
128 }
129
130 return board_id;
131}
132
133#if IS_ENABLED(CONFIG_SPL_BUILD) && IS_ENABLED(CONFIG_TARGET_SOCFPGA_SOC64)
134int board_fit_config_name_match(const char *name)
135{
136 char board_name[10];
137
138 sprintf(board_name, "board_%u", socfpga_get_board_id());
139
140 debug("Board name: %s\n", board_name);
141
142 return strcmp(name, board_name);
Chee Hong Ang7cfcc0c2020-12-24 18:20:56 +0800143}
144#endif
Siew Chin Lim2492d592021-03-01 20:04:11 +0800145
146#if IS_ENABLED(CONFIG_FIT_IMAGE_POST_PROCESS)
Lokesh Vutlab36dd3e2021-06-11 11:45:05 +0300147void board_fit_image_post_process(const void *fit, int node, void **p_image,
148 size_t *p_size)
Siew Chin Lim2492d592021-03-01 20:04:11 +0800149{
150 if (IS_ENABLED(CONFIG_SOCFPGA_SECURE_VAB_AUTH)) {
151 if (socfpga_vendor_authentication(p_image, p_size))
152 hang();
153 }
154}
155#endif
156
157#if !IS_ENABLED(CONFIG_SPL_BUILD) && IS_ENABLED(CONFIG_FIT)
Simon Glassdf00afa2022-09-06 20:26:50 -0600158void board_prep_linux(struct bootm_headers *images)
Siew Chin Lim2492d592021-03-01 20:04:11 +0800159{
Jit Loon Lim977071e2024-03-12 22:01:03 +0800160 bool use_fit = false;
161
Siew Chin Lim0fc23772021-08-10 11:26:26 +0800162 if (!images->fit_uname_cfg) {
163 if (IS_ENABLED(CONFIG_SOCFPGA_SECURE_VAB_AUTH) &&
164 !IS_ENABLED(CONFIG_SOCFPGA_SECURE_VAB_AUTH_ALLOW_NON_FIT_IMAGE)) {
165 /*
166 * Ensure the OS is always booted from FIT and with
167 * VAB signed certificate
168 */
Siew Chin Lim2492d592021-03-01 20:04:11 +0800169 printf("Please use FIT with VAB signed images!\n");
170 hang();
171 }
Siew Chin Lim0fc23772021-08-10 11:26:26 +0800172 } else {
Jit Loon Lim977071e2024-03-12 22:01:03 +0800173 use_fit = true;
Siew Chin Lim0fc23772021-08-10 11:26:26 +0800174 /* Update fdt_addr in enviroment variable */
Siew Chin Lim2492d592021-03-01 20:04:11 +0800175 env_set_hex("fdt_addr", (ulong)images->ft_addr);
176 debug("images->ft_addr = 0x%08lx\n", (ulong)images->ft_addr);
177 }
178
Jit Loon Lim977071e2024-03-12 22:01:03 +0800179 if (use_fit && IS_ENABLED(CONFIG_CADENCE_QSPI)) {
Siew Chin Lim2492d592021-03-01 20:04:11 +0800180 if (env_get("linux_qspi_enable"))
181 run_command(env_get("linux_qspi_enable"), 0);
182 }
183}
184#endif