Tom Rini | 83d290c | 2018-05-06 17:58:06 -0400 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0+ |
Marek Vasut | 8e535af | 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 | 8e535af | 2015-12-05 21:07:23 +0100 | [diff] [blame] | 6 | */ |
| 7 | |
| 8 | #include <common.h> |
Tien Fong Chee | c960ef2 | 2017-12-05 15:58:07 +0800 | [diff] [blame] | 9 | #include <asm/arch/clock_manager.h> |
Tien Fong Chee | 011fa5f | 2017-12-05 15:58:08 +0800 | [diff] [blame] | 10 | #include <asm/arch/misc.h> |
Siew Chin Lim | 1bc2089 | 2021-03-01 20:04:11 +0800 | [diff] [blame] | 11 | #include <asm/arch/reset_manager.h> |
| 12 | #include <asm/arch/secure_vab.h> |
Simon Glass | 401d1c4 | 2020-10-30 21:38:53 -0600 | [diff] [blame] | 13 | #include <asm/global_data.h> |
Marek Vasut | 8e535af | 2015-12-05 21:07:23 +0100 | [diff] [blame] | 14 | #include <asm/io.h> |
Siew Chin Lim | 1bc2089 | 2021-03-01 20:04:11 +0800 | [diff] [blame] | 15 | #include <errno.h> |
| 16 | #include <fdtdec.h> |
| 17 | #include <hang.h> |
| 18 | #include <image.h> |
| 19 | #include <init.h> |
Chee Hong Ang | acabb2a | 2020-12-24 18:20:56 +0800 | [diff] [blame] | 20 | #include <log.h> |
Marek Vasut | 8e535af | 2015-12-05 21:07:23 +0100 | [diff] [blame] | 21 | #include <usb.h> |
| 22 | #include <usb/dwc2_udc.h> |
| 23 | |
| 24 | DECLARE_GLOBAL_DATA_PTR; |
| 25 | |
Marek Vasut | 887a8b6 | 2018-05-29 16:16:46 +0200 | [diff] [blame] | 26 | void s_init(void) { |
Ley Foon Tan | 8c9f247 | 2018-07-12 19:13:34 +0800 | [diff] [blame] | 27 | #ifndef CONFIG_ARM64 |
Marek Vasut | 887a8b6 | 2018-05-29 16:16:46 +0200 | [diff] [blame] | 28 | /* |
Marek Vasut | 937db71 | 2018-07-12 15:07:46 +0200 | [diff] [blame] | 29 | * Preconfigure ACTLR and CPACR, make sure Write Full Line of Zeroes |
| 30 | * is disabled in ACTLR. |
Marek Vasut | 887a8b6 | 2018-05-29 16:16:46 +0200 | [diff] [blame] | 31 | * This is optional on CycloneV / ArriaV. |
| 32 | * This is mandatory on Arria10, otherwise Linux refuses to boot. |
| 33 | */ |
| 34 | asm volatile( |
| 35 | "mcr p15, 0, %0, c1, c0, 1\n" |
Marek Vasut | 937db71 | 2018-07-12 15:07:46 +0200 | [diff] [blame] | 36 | "mcr p15, 0, %0, c1, c0, 2\n" |
Marek Vasut | 887a8b6 | 2018-05-29 16:16:46 +0200 | [diff] [blame] | 37 | "isb\n" |
| 38 | "dsb\n" |
| 39 | ::"r"(0x0)); |
Ley Foon Tan | 8c9f247 | 2018-07-12 19:13:34 +0800 | [diff] [blame] | 40 | #endif |
Marek Vasut | 887a8b6 | 2018-05-29 16:16:46 +0200 | [diff] [blame] | 41 | } |
Marek Vasut | 8e535af | 2015-12-05 21:07:23 +0100 | [diff] [blame] | 42 | |
| 43 | /* |
| 44 | * Miscellaneous platform dependent initialisations |
| 45 | */ |
| 46 | int board_init(void) |
| 47 | { |
| 48 | /* Address of boot parameters for ATAG (if ATAG is used) */ |
| 49 | gd->bd->bi_boot_params = CONFIG_SYS_SDRAM_BASE + 0x100; |
| 50 | |
| 51 | return 0; |
| 52 | } |
| 53 | |
Tien Fong Chee | 53faef1 | 2017-12-05 15:58:01 +0800 | [diff] [blame] | 54 | int dram_init_banksize(void) |
| 55 | { |
| 56 | fdtdec_setup_memory_banksize(); |
| 57 | |
| 58 | return 0; |
| 59 | } |
| 60 | |
Marek Vasut | 8e535af | 2015-12-05 21:07:23 +0100 | [diff] [blame] | 61 | #ifdef CONFIG_USB_GADGET |
| 62 | struct dwc2_plat_otg_data socfpga_otg_data = { |
| 63 | .usb_gusbcfg = 0x1417, |
| 64 | }; |
| 65 | |
| 66 | int board_usb_init(int index, enum usb_init_type init) |
| 67 | { |
| 68 | int node[2], count; |
| 69 | fdt_addr_t addr; |
| 70 | |
| 71 | count = fdtdec_find_aliases_for_id(gd->fdt_blob, "udc", |
| 72 | COMPAT_ALTERA_SOCFPGA_DWC2USB, |
| 73 | node, 2); |
| 74 | if (count <= 0) /* No controller found. */ |
| 75 | return 0; |
| 76 | |
| 77 | addr = fdtdec_get_addr(gd->fdt_blob, node[0], "reg"); |
| 78 | if (addr == FDT_ADDR_T_NONE) { |
| 79 | printf("UDC Controller has no 'reg' property!\n"); |
| 80 | return -EINVAL; |
| 81 | } |
| 82 | |
| 83 | /* Patch the address from OF into the controller pdata. */ |
| 84 | socfpga_otg_data.regs_otg = addr; |
| 85 | |
| 86 | return dwc2_udc_probe(&socfpga_otg_data); |
| 87 | } |
| 88 | |
| 89 | int g_dnl_board_usb_cable_connected(void) |
| 90 | { |
| 91 | return 1; |
| 92 | } |
| 93 | #endif |
Chee Hong Ang | acabb2a | 2020-12-24 18:20:56 +0800 | [diff] [blame] | 94 | |
| 95 | #ifdef CONFIG_SPL_BUILD |
| 96 | __weak int board_fit_config_name_match(const char *name) |
| 97 | { |
| 98 | /* Just empty function now - can't decide what to choose */ |
| 99 | debug("%s: %s\n", __func__, name); |
| 100 | |
| 101 | return 0; |
| 102 | } |
| 103 | #endif |
Siew Chin Lim | 1bc2089 | 2021-03-01 20:04:11 +0800 | [diff] [blame] | 104 | |
| 105 | #if IS_ENABLED(CONFIG_FIT_IMAGE_POST_PROCESS) |
Lokesh Vutla | 481d394 | 2021-06-11 11:45:05 +0300 | [diff] [blame] | 106 | void board_fit_image_post_process(const void *fit, int node, void **p_image, |
| 107 | size_t *p_size) |
Siew Chin Lim | 1bc2089 | 2021-03-01 20:04:11 +0800 | [diff] [blame] | 108 | { |
| 109 | if (IS_ENABLED(CONFIG_SOCFPGA_SECURE_VAB_AUTH)) { |
| 110 | if (socfpga_vendor_authentication(p_image, p_size)) |
| 111 | hang(); |
| 112 | } |
| 113 | } |
| 114 | #endif |
| 115 | |
| 116 | #if !IS_ENABLED(CONFIG_SPL_BUILD) && IS_ENABLED(CONFIG_FIT) |
| 117 | void board_prep_linux(bootm_headers_t *images) |
| 118 | { |
Siew Chin Lim | 2dbcc03 | 2021-03-22 18:04:52 +0800 | [diff] [blame] | 119 | if (IS_ENABLED(CONFIG_SOCFPGA_SECURE_VAB_AUTH) && |
| 120 | !IS_ENABLED(CONFIG_SOCFPGA_SECURE_VAB_AUTH_ALLOW_NON_FIT_IMAGE)) { |
Siew Chin Lim | 1bc2089 | 2021-03-01 20:04:11 +0800 | [diff] [blame] | 121 | /* |
| 122 | * Ensure the OS is always booted from FIT and with |
| 123 | * VAB signed certificate |
| 124 | */ |
| 125 | if (!images->fit_uname_cfg) { |
| 126 | printf("Please use FIT with VAB signed images!\n"); |
| 127 | hang(); |
| 128 | } |
| 129 | |
| 130 | env_set_hex("fdt_addr", (ulong)images->ft_addr); |
| 131 | debug("images->ft_addr = 0x%08lx\n", (ulong)images->ft_addr); |
| 132 | } |
| 133 | |
| 134 | if (IS_ENABLED(CONFIG_CADENCE_QSPI)) { |
| 135 | if (env_get("linux_qspi_enable")) |
| 136 | run_command(env_get("linux_qspi_enable"), 0); |
| 137 | } |
| 138 | } |
| 139 | #endif |