Aleksandar Gerasimovski | 032bdbc | 2021-02-22 18:18:11 +0000 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0+ |
| 2 | /* |
| 3 | * Copyright 2020 Hitachi Power Grids. All rights reserved. |
| 4 | */ |
| 5 | |
Tom Rini | 1017b0c | 2023-11-01 12:28:15 -0400 | [diff] [blame] | 6 | #include <config.h> |
Simon Glass | f1c5191 | 2022-03-04 08:43:04 -0700 | [diff] [blame] | 7 | #include <event.h> |
Aleksandar Gerasimovski | 032bdbc | 2021-02-22 18:18:11 +0000 | [diff] [blame] | 8 | #include <asm/io.h> |
| 9 | #include <asm/arch/immap_ls102xa.h> |
| 10 | #include <asm/arch/clock.h> |
| 11 | #include <asm/arch/fsl_serdes.h> |
| 12 | #include <asm/arch/ls102xa_devdis.h> |
| 13 | #include <asm/arch/ls102xa_soc.h> |
| 14 | #include <hwconfig.h> |
| 15 | #include <mmc.h> |
| 16 | #include <fsl_csu.h> |
| 17 | #include <fsl_esdhc.h> |
| 18 | #include <fsl_ifc.h> |
| 19 | #include <fsl_immap.h> |
| 20 | #include <netdev.h> |
| 21 | #include <fsl_mdio.h> |
| 22 | #include <tsec.h> |
| 23 | #include <fsl_sec.h> |
| 24 | #include <fsl_devdis.h> |
| 25 | #include <fsl_ddr.h> |
| 26 | #include <spl.h> |
| 27 | #include <fdt_support.h> |
| 28 | #include <fsl_qe.h> |
| 29 | #include <fsl_validate.h> |
| 30 | |
| 31 | #include "../common/common.h" |
| 32 | #include "../common/qrio.h" |
| 33 | |
| 34 | DECLARE_GLOBAL_DATA_PTR; |
| 35 | |
| 36 | static uchar ivm_content[CONFIG_SYS_IVM_EEPROM_MAX_LEN]; |
| 37 | |
| 38 | int checkboard(void) |
| 39 | { |
| 40 | show_qrio(); |
| 41 | |
| 42 | return 0; |
| 43 | } |
| 44 | |
| 45 | int dram_init(void) |
| 46 | { |
| 47 | return fsl_initdram(); |
| 48 | } |
| 49 | |
| 50 | int board_early_init_f(void) |
| 51 | { |
Tom Rini | 376b88a | 2022-10-28 20:27:13 -0400 | [diff] [blame] | 52 | struct ccsr_scfg *scfg = (struct ccsr_scfg *)CFG_SYS_FSL_SCFG_ADDR; |
| 53 | struct ccsr_gur __iomem *gur = (void *)CFG_SYS_FSL_GUTS_ADDR; |
Tom Rini | 6a5dccc | 2022-11-16 13:10:41 -0500 | [diff] [blame] | 54 | struct fsl_ifc ifc = {(void *)CFG_SYS_IFC_ADDR, (void *)NULL}; |
Aleksandar Gerasimovski | 032bdbc | 2021-02-22 18:18:11 +0000 | [diff] [blame] | 55 | |
| 56 | /* Disable unused MCK1 */ |
| 57 | setbits_be32(&gur->ddrclkdr, 2); |
| 58 | |
| 59 | /* IFC Global Configuration */ |
| 60 | setbits_be32(&ifc.gregs->ifc_gcr, 12 << IFC_GCR_TBCTL_TRN_TIME_SHIFT); |
| 61 | setbits_be32(&ifc.gregs->ifc_ccr, IFC_CCR_CLK_DIV(3) | |
| 62 | IFC_CCR_INV_CLK_EN); |
| 63 | |
| 64 | /* clear BD & FR bits for BE BD's and frame data */ |
| 65 | clrbits_be32(&scfg->etsecdmamcr, SCFG_ETSECDMAMCR_LE_BD_FR); |
| 66 | out_be32(&scfg->etsecmcr, SCFG_ETSECCMCR_GE2_CLK125); |
| 67 | |
| 68 | init_early_memctl_regs(); |
| 69 | |
| 70 | /* QRIO Configuration */ |
| 71 | qrio_uprstreq(UPREQ_CORE_RST); |
| 72 | |
Simon Glass | 63dcf3a | 2023-02-05 15:44:16 -0700 | [diff] [blame] | 73 | #if IS_ENABLED(CONFIG_TARGET_PG_WCOM_SELI8) |
Aleksandar Gerasimovski | 3b24bbd | 2021-06-08 14:16:28 +0000 | [diff] [blame] | 74 | qrio_prstcfg(KM_LIU_RST, PRSTCFG_POWUP_UNIT_RST); |
| 75 | qrio_wdmask(KM_LIU_RST, true); |
Aleksandar Gerasimovski | 032bdbc | 2021-02-22 18:18:11 +0000 | [diff] [blame] | 76 | |
Aleksandar Gerasimovski | 3b24bbd | 2021-06-08 14:16:28 +0000 | [diff] [blame] | 77 | qrio_prstcfg(KM_PAXK_RST, PRSTCFG_POWUP_UNIT_RST); |
| 78 | qrio_wdmask(KM_PAXK_RST, true); |
| 79 | #endif |
| 80 | |
Simon Glass | c151a36 | 2023-02-05 15:41:00 -0700 | [diff] [blame] | 81 | #if IS_ENABLED(CONFIG_TARGET_PG_WCOM_EXPU1) |
Aleksandar Gerasimovski | 3b24bbd | 2021-06-08 14:16:28 +0000 | [diff] [blame] | 82 | qrio_prstcfg(WCOM_TMG_RST, PRSTCFG_POWUP_UNIT_RST); |
| 83 | qrio_wdmask(WCOM_TMG_RST, true); |
| 84 | |
| 85 | qrio_prstcfg(WCOM_PHY_RST, PRSTCFG_POWUP_UNIT_RST); |
| 86 | qrio_prst(WCOM_PHY_RST, false, false); |
| 87 | |
| 88 | qrio_prstcfg(WCOM_QSFP_RST, PRSTCFG_POWUP_UNIT_RST); |
| 89 | qrio_wdmask(WCOM_QSFP_RST, true); |
Aleksandar Gerasimovski | 032bdbc | 2021-02-22 18:18:11 +0000 | [diff] [blame] | 90 | |
Aleksandar Gerasimovski | 3b24bbd | 2021-06-08 14:16:28 +0000 | [diff] [blame] | 91 | qrio_prstcfg(WCOM_CLIPS_RST, PRSTCFG_POWUP_UNIT_RST); |
| 92 | qrio_prst(WCOM_CLIPS_RST, false, false); |
| 93 | #endif |
Aleksandar Gerasimovski | 3651431 | 2021-11-16 12:51:47 +0000 | [diff] [blame] | 94 | |
| 95 | /* deasset debug phy reset only if piggy is present */ |
Aleksandar Gerasimovski | 3b24bbd | 2021-06-08 14:16:28 +0000 | [diff] [blame] | 96 | qrio_prstcfg(KM_DBG_ETH_RST, PRSTCFG_POWUP_UNIT_CORE_RST); |
Aleksandar Gerasimovski | 3651431 | 2021-11-16 12:51:47 +0000 | [diff] [blame] | 97 | qrio_prst(KM_DBG_ETH_RST, !qrio_get_pgy_pres_pin(), false); |
Aleksandar Gerasimovski | 032bdbc | 2021-02-22 18:18:11 +0000 | [diff] [blame] | 98 | |
| 99 | i2c_deblock_gpio_cfg(); |
| 100 | |
Aleksandar Gerasimovski | 8e26562 | 2021-06-08 14:24:32 +0000 | [diff] [blame] | 101 | /* enable the Unit LED (red) & Boot LED (on) */ |
| 102 | qrio_set_leds(); |
| 103 | |
| 104 | /* enable Application Buffer */ |
| 105 | qrio_enable_app_buffer(); |
| 106 | |
Aleksandar Gerasimovski | 032bdbc | 2021-02-22 18:18:11 +0000 | [diff] [blame] | 107 | arch_soc_init(); |
| 108 | |
Anatolij Gustschin | 02d59e3 | 2024-07-20 01:24:22 +0200 | [diff] [blame] | 109 | /* |
| 110 | * Reset I2C bus. When the board is powercycled during a bus |
| 111 | * transfer it might hang; for details see doc/I2C_Edge_Conditions. |
| 112 | * Now run the AbortSequence() |
| 113 | */ |
| 114 | i2c_make_abort(); |
| 115 | |
Aleksandar Gerasimovski | 032bdbc | 2021-02-22 18:18:11 +0000 | [diff] [blame] | 116 | return 0; |
| 117 | } |
| 118 | |
Simon Glass | b8357c1 | 2023-08-21 21:16:56 -0600 | [diff] [blame] | 119 | static int pg_wcom_misc_init_f(void) |
Aleksandar Gerasimovski | 1cc133d | 2021-12-10 11:08:44 +0100 | [diff] [blame] | 120 | { |
| 121 | if (IS_ENABLED(CONFIG_PG_WCOM_UBOOT_UPDATE_SUPPORTED)) |
| 122 | check_for_uboot_update(); |
Simon Glass | f1c5191 | 2022-03-04 08:43:04 -0700 | [diff] [blame] | 123 | |
Aleksandar Gerasimovski | 1cc133d | 2021-12-10 11:08:44 +0100 | [diff] [blame] | 124 | return 0; |
| 125 | } |
Simon Glass | b8357c1 | 2023-08-21 21:16:56 -0600 | [diff] [blame] | 126 | EVENT_SPY_SIMPLE(EVT_MISC_INIT_F, pg_wcom_misc_init_f); |
Aleksandar Gerasimovski | 1cc133d | 2021-12-10 11:08:44 +0100 | [diff] [blame] | 127 | |
Aleksandar Gerasimovski | 032bdbc | 2021-02-22 18:18:11 +0000 | [diff] [blame] | 128 | int board_init(void) |
| 129 | { |
| 130 | if (IS_ENABLED(CONFIG_SYS_FSL_ERRATUM_A010315)) |
| 131 | erratum_a010315(); |
| 132 | |
| 133 | fsl_serdes_init(); |
| 134 | |
| 135 | ls102xa_smmu_stream_id_init(); |
| 136 | |
| 137 | u_qe_init(); |
| 138 | |
| 139 | return 0; |
| 140 | } |
| 141 | |
| 142 | int board_late_init(void) |
| 143 | { |
| 144 | return 0; |
| 145 | } |
| 146 | |
| 147 | int misc_init_r(void) |
| 148 | { |
Aleksandar Gerasimovski | fcaaa4f | 2021-11-16 13:06:31 +0000 | [diff] [blame] | 149 | device_disable(devdis_tbl, ARRAY_SIZE(devdis_tbl)); |
Aleksandar Gerasimovski | 032bdbc | 2021-02-22 18:18:11 +0000 | [diff] [blame] | 150 | |
| 151 | ivm_read_eeprom(ivm_content, CONFIG_SYS_IVM_EEPROM_MAX_LEN, |
| 152 | CONFIG_PIGGY_MAC_ADDRESS_OFFSET); |
| 153 | |
| 154 | return 0; |
| 155 | } |
| 156 | |
| 157 | int ft_board_setup(void *blob, struct bd_info *bd) |
| 158 | { |
| 159 | ft_cpu_setup(blob, bd); |
| 160 | |
| 161 | if (IS_ENABLED(CONFIG_PCI)) |
| 162 | ft_pci_setup(blob, bd); |
| 163 | |
| 164 | return 0; |
| 165 | } |
| 166 | |
Aleksandar Gerasimovski | bece73e | 2021-06-08 14:17:34 +0000 | [diff] [blame] | 167 | #if defined(CONFIG_POST) |
| 168 | int post_hotkeys_pressed(void) |
| 169 | { |
Aleksandar Gerasimovski | 83a4baa | 2021-11-16 12:49:46 +0000 | [diff] [blame] | 170 | /* DIC26_SELFTEST: QRIO, SLFTEST */ |
| 171 | return qrio_get_selftest_pin(); |
Aleksandar Gerasimovski | bece73e | 2021-06-08 14:17:34 +0000 | [diff] [blame] | 172 | } |
| 173 | |
Aleksandar Gerasimovski | f4993e8 | 2021-11-16 13:13:35 +0000 | [diff] [blame] | 174 | /* POST word is located in the unused SCRATCHRW4 register */ |
| 175 | #define CCSR_SCRATCHRW4_ADDR 0x1ee020c |
| 176 | |
Aleksandar Gerasimovski | bece73e | 2021-06-08 14:17:34 +0000 | [diff] [blame] | 177 | ulong post_word_load(void) |
| 178 | { |
Aleksandar Gerasimovski | f4993e8 | 2021-11-16 13:13:35 +0000 | [diff] [blame] | 179 | void *addr = (void *)CCSR_SCRATCHRW4_ADDR; |
Aleksandar Gerasimovski | bece73e | 2021-06-08 14:17:34 +0000 | [diff] [blame] | 180 | return in_le32(addr); |
| 181 | } |
| 182 | |
| 183 | void post_word_store(ulong value) |
| 184 | { |
Aleksandar Gerasimovski | f4993e8 | 2021-11-16 13:13:35 +0000 | [diff] [blame] | 185 | void *addr = (void *)CCSR_SCRATCHRW4_ADDR; |
Aleksandar Gerasimovski | bece73e | 2021-06-08 14:17:34 +0000 | [diff] [blame] | 186 | out_le32(addr, value); |
| 187 | } |
| 188 | |
| 189 | int arch_memory_test_prepare(u32 *vstart, u32 *size, phys_addr_t *phys_offset) |
| 190 | { |
| 191 | /* Define only 1MiB range for mem_regions at the middle of the RAM */ |
| 192 | /* For 1GiB range mem_regions takes approx. 4min */ |
Tom Rini | bb4dd96 | 2022-11-16 13:10:37 -0500 | [diff] [blame] | 193 | *vstart = CFG_SYS_SDRAM_BASE + (gd->ram_size >> 1); |
Aleksandar Gerasimovski | bece73e | 2021-06-08 14:17:34 +0000 | [diff] [blame] | 194 | *size = 1 << 20; |
| 195 | return 0; |
| 196 | } |
| 197 | #endif |
| 198 | |
Aleksandar Gerasimovski | 032bdbc | 2021-02-22 18:18:11 +0000 | [diff] [blame] | 199 | u8 flash_read8(void *addr) |
| 200 | { |
| 201 | return __raw_readb(addr + 1); |
| 202 | } |
| 203 | |
| 204 | void flash_write16(u16 val, void *addr) |
| 205 | { |
| 206 | u16 shftval = (((val >> 8) & 0xff) | ((val << 8) & 0xff00)); |
| 207 | |
| 208 | __raw_writew(shftval, addr); |
| 209 | } |
| 210 | |
| 211 | u16 flash_read16(void *addr) |
| 212 | { |
| 213 | u16 val = __raw_readw(addr); |
| 214 | |
| 215 | return (((val) >> 8) & 0x00ff) | (((val) << 8) & 0xff00); |
| 216 | } |
| 217 | |
| 218 | int hush_init_var(void) |
| 219 | { |
| 220 | ivm_analyze_eeprom(ivm_content, CONFIG_SYS_IVM_EEPROM_MAX_LEN); |
| 221 | return 0; |
| 222 | } |
| 223 | |
Simon Glass | 1cedca1 | 2023-08-21 21:17:01 -0600 | [diff] [blame] | 224 | EVENT_SPY_SIMPLE(EVT_LAST_STAGE_INIT, set_km_env); |