Tom Rini | 10e4779 | 2018-05-06 17:58:06 -0400 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0+ |
Marek Vasut | 05204f6 | 2015-12-05 21:07:23 +0100 | [diff] [blame] | 2 | /* |
| 3 | * Altera SoCFPGA common board code |
| 4 | * |
| 5 | * Copyright (C) 2015 Marek Vasut <marex@denx.de> |
Marek Vasut | 05204f6 | 2015-12-05 21:07:23 +0100 | [diff] [blame] | 6 | */ |
| 7 | |
Tom Rini | dec7ea0 | 2024-05-20 13:35:03 -0600 | [diff] [blame] | 8 | #include <config.h> |
Tien Fong Chee | a5bfce3 | 2017-12-05 15:58:07 +0800 | [diff] [blame] | 9 | #include <asm/arch/clock_manager.h> |
Jit Loon Lim | 977071e | 2024-03-12 22:01:03 +0800 | [diff] [blame] | 10 | #include <asm/arch/mailbox_s10.h> |
Tien Fong Chee | f3f525c | 2017-12-05 15:58:08 +0800 | [diff] [blame] | 11 | #include <asm/arch/misc.h> |
Siew Chin Lim | 2492d59 | 2021-03-01 20:04:11 +0800 | [diff] [blame] | 12 | #include <asm/arch/reset_manager.h> |
| 13 | #include <asm/arch/secure_vab.h> |
Jit Loon Lim | 977071e | 2024-03-12 22:01:03 +0800 | [diff] [blame] | 14 | #include <asm/arch/smc_api.h> |
Simon Glass | 3ba929a | 2020-10-30 21:38:53 -0600 | [diff] [blame] | 15 | #include <asm/global_data.h> |
Marek Vasut | 05204f6 | 2015-12-05 21:07:23 +0100 | [diff] [blame] | 16 | #include <asm/io.h> |
Siew Chin Lim | 2492d59 | 2021-03-01 20:04:11 +0800 | [diff] [blame] | 17 | #include <errno.h> |
| 18 | #include <fdtdec.h> |
| 19 | #include <hang.h> |
| 20 | #include <image.h> |
| 21 | #include <init.h> |
Chee Hong Ang | 7cfcc0c | 2020-12-24 18:20:56 +0800 | [diff] [blame] | 22 | #include <log.h> |
Marek Vasut | 05204f6 | 2015-12-05 21:07:23 +0100 | [diff] [blame] | 23 | #include <usb.h> |
| 24 | #include <usb/dwc2_udc.h> |
| 25 | |
| 26 | DECLARE_GLOBAL_DATA_PTR; |
| 27 | |
Jit Loon Lim | 977071e | 2024-03-12 22:01:03 +0800 | [diff] [blame] | 28 | #define DEFAULT_JTAG_USERCODE 0xFFFFFFFF |
| 29 | |
Marek Vasut | 72cc958 | 2018-05-29 16:16:46 +0200 | [diff] [blame] | 30 | void s_init(void) { |
Ley Foon Tan | 27f05ac | 2018-07-12 19:13:34 +0800 | [diff] [blame] | 31 | #ifndef CONFIG_ARM64 |
Marek Vasut | 72cc958 | 2018-05-29 16:16:46 +0200 | [diff] [blame] | 32 | /* |
Marek Vasut | 911a665 | 2018-07-12 15:07:46 +0200 | [diff] [blame] | 33 | * Preconfigure ACTLR and CPACR, make sure Write Full Line of Zeroes |
| 34 | * is disabled in ACTLR. |
Marek Vasut | 72cc958 | 2018-05-29 16:16:46 +0200 | [diff] [blame] | 35 | * 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 Vasut | 911a665 | 2018-07-12 15:07:46 +0200 | [diff] [blame] | 40 | "mcr p15, 0, %0, c1, c0, 2\n" |
Marek Vasut | 72cc958 | 2018-05-29 16:16:46 +0200 | [diff] [blame] | 41 | "isb\n" |
| 42 | "dsb\n" |
| 43 | ::"r"(0x0)); |
Ley Foon Tan | 27f05ac | 2018-07-12 19:13:34 +0800 | [diff] [blame] | 44 | #endif |
Marek Vasut | 72cc958 | 2018-05-29 16:16:46 +0200 | [diff] [blame] | 45 | } |
Marek Vasut | 05204f6 | 2015-12-05 21:07:23 +0100 | [diff] [blame] | 46 | |
| 47 | /* |
| 48 | * Miscellaneous platform dependent initialisations |
| 49 | */ |
| 50 | int board_init(void) |
| 51 | { |
| 52 | /* Address of boot parameters for ATAG (if ATAG is used) */ |
Tom Rini | bb4dd96 | 2022-11-16 13:10:37 -0500 | [diff] [blame] | 53 | gd->bd->bi_boot_params = CFG_SYS_SDRAM_BASE + 0x100; |
Marek Vasut | 05204f6 | 2015-12-05 21:07:23 +0100 | [diff] [blame] | 54 | |
| 55 | return 0; |
| 56 | } |
| 57 | |
Tien Fong Chee | 3710de7 | 2017-12-05 15:58:01 +0800 | [diff] [blame] | 58 | int dram_init_banksize(void) |
| 59 | { |
| 60 | fdtdec_setup_memory_banksize(); |
| 61 | |
| 62 | return 0; |
| 63 | } |
| 64 | |
Marek Vasut | 05204f6 | 2015-12-05 21:07:23 +0100 | [diff] [blame] | 65 | #ifdef CONFIG_USB_GADGET |
| 66 | struct dwc2_plat_otg_data socfpga_otg_data = { |
| 67 | .usb_gusbcfg = 0x1417, |
| 68 | }; |
| 69 | |
| 70 | int 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 | |
| 93 | int g_dnl_board_usb_cable_connected(void) |
| 94 | { |
| 95 | return 1; |
| 96 | } |
| 97 | #endif |
Chee Hong Ang | 7cfcc0c | 2020-12-24 18:20:56 +0800 | [diff] [blame] | 98 | |
Jit Loon Lim | 977071e | 2024-03-12 22:01:03 +0800 | [diff] [blame] | 99 | u8 socfpga_get_board_id(void) |
Chee Hong Ang | 7cfcc0c | 2020-12-24 18:20:56 +0800 | [diff] [blame] | 100 | { |
Jit Loon Lim | 977071e | 2024-03-12 22:01:03 +0800 | [diff] [blame] | 101 | u8 board_id = 0; |
| 102 | u32 jtag_usercode; |
| 103 | int err; |
Chee Hong Ang | 7cfcc0c | 2020-12-24 18:20:56 +0800 | [diff] [blame] | 104 | |
Jit Loon Lim | 977071e | 2024-03-12 22:01:03 +0800 | [diff] [blame] | 105 | #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) |
| 134 | int 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 Ang | 7cfcc0c | 2020-12-24 18:20:56 +0800 | [diff] [blame] | 143 | } |
| 144 | #endif |
Siew Chin Lim | 2492d59 | 2021-03-01 20:04:11 +0800 | [diff] [blame] | 145 | |
| 146 | #if IS_ENABLED(CONFIG_FIT_IMAGE_POST_PROCESS) |
Lokesh Vutla | b36dd3e | 2021-06-11 11:45:05 +0300 | [diff] [blame] | 147 | void board_fit_image_post_process(const void *fit, int node, void **p_image, |
| 148 | size_t *p_size) |
Siew Chin Lim | 2492d59 | 2021-03-01 20:04:11 +0800 | [diff] [blame] | 149 | { |
| 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 Glass | df00afa | 2022-09-06 20:26:50 -0600 | [diff] [blame] | 158 | void board_prep_linux(struct bootm_headers *images) |
Siew Chin Lim | 2492d59 | 2021-03-01 20:04:11 +0800 | [diff] [blame] | 159 | { |
Jit Loon Lim | 977071e | 2024-03-12 22:01:03 +0800 | [diff] [blame] | 160 | bool use_fit = false; |
| 161 | |
Siew Chin Lim | 0fc2377 | 2021-08-10 11:26:26 +0800 | [diff] [blame] | 162 | 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 Lim | 2492d59 | 2021-03-01 20:04:11 +0800 | [diff] [blame] | 169 | printf("Please use FIT with VAB signed images!\n"); |
| 170 | hang(); |
| 171 | } |
Siew Chin Lim | 0fc2377 | 2021-08-10 11:26:26 +0800 | [diff] [blame] | 172 | } else { |
Jit Loon Lim | 977071e | 2024-03-12 22:01:03 +0800 | [diff] [blame] | 173 | use_fit = true; |
Siew Chin Lim | 0fc2377 | 2021-08-10 11:26:26 +0800 | [diff] [blame] | 174 | /* Update fdt_addr in enviroment variable */ |
Siew Chin Lim | 2492d59 | 2021-03-01 20:04:11 +0800 | [diff] [blame] | 175 | 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 Lim | 977071e | 2024-03-12 22:01:03 +0800 | [diff] [blame] | 179 | if (use_fit && IS_ENABLED(CONFIG_CADENCE_QSPI)) { |
Siew Chin Lim | 2492d59 | 2021-03-01 20:04:11 +0800 | [diff] [blame] | 180 | if (env_get("linux_qspi_enable")) |
| 181 | run_command(env_get("linux_qspi_enable"), 0); |
| 182 | } |
| 183 | } |
| 184 | #endif |