Jianchao Wang | e5332ba | 2019-07-19 00:30:01 +0300 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0 |
Gaurav Jain | 476c639 | 2022-03-24 11:50:35 +0530 | [diff] [blame] | 2 | /* Copyright 2016-2019, 2021 NXP |
Jianchao Wang | e5332ba | 2019-07-19 00:30:01 +0300 | [diff] [blame] | 3 | */ |
| 4 | #include <common.h> |
Simon Glass | 85d6531 | 2019-12-28 10:44:58 -0700 | [diff] [blame] | 5 | #include <clock_legacy.h> |
Simon Glass | 3bbe70c | 2019-12-28 10:44:54 -0700 | [diff] [blame] | 6 | #include <fdt_support.h> |
Simon Glass | a7b5130 | 2019-11-14 12:57:46 -0700 | [diff] [blame] | 7 | #include <init.h> |
Simon Glass | 274e0b0 | 2020-05-10 11:39:56 -0600 | [diff] [blame] | 8 | #include <net.h> |
Jianchao Wang | e5332ba | 2019-07-19 00:30:01 +0300 | [diff] [blame] | 9 | #include <asm/arch-ls102xa/ls102xa_soc.h> |
| 10 | #include <asm/arch/ls102xa_devdis.h> |
| 11 | #include <asm/arch/immap_ls102xa.h> |
| 12 | #include <asm/arch/ls102xa_soc.h> |
| 13 | #include <asm/arch/fsl_serdes.h> |
Simon Glass | 3ba929a | 2020-10-30 21:38:53 -0600 | [diff] [blame] | 14 | #include <asm/global_data.h> |
Shiji Yang | bb11234 | 2023-08-03 09:47:16 +0800 | [diff] [blame] | 15 | #include <asm/sections.h> |
Simon Glass | dbd7954 | 2020-05-10 11:40:11 -0600 | [diff] [blame] | 16 | #include <linux/delay.h> |
Jianchao Wang | e5332ba | 2019-07-19 00:30:01 +0300 | [diff] [blame] | 17 | #include "../common/sleep.h" |
| 18 | #include <fsl_validate.h> |
| 19 | #include <fsl_immap.h> |
| 20 | #include <fsl_csu.h> |
| 21 | #include <netdev.h> |
| 22 | #include <spl.h> |
| 23 | #ifdef CONFIG_U_QE |
| 24 | #include <fsl_qe.h> |
| 25 | #endif |
| 26 | |
| 27 | DECLARE_GLOBAL_DATA_PTR; |
| 28 | |
| 29 | static void ddrmc_init(void) |
| 30 | { |
| 31 | #if (!defined(CONFIG_SPL) || defined(CONFIG_SPL_BUILD)) |
Tom Rini | 376b88a | 2022-10-28 20:27:13 -0400 | [diff] [blame] | 32 | struct ccsr_ddr *ddr = (struct ccsr_ddr *)CFG_SYS_FSL_DDR_ADDR; |
Jianchao Wang | e5332ba | 2019-07-19 00:30:01 +0300 | [diff] [blame] | 33 | u32 temp_sdram_cfg, tmp; |
| 34 | |
| 35 | out_be32(&ddr->sdram_cfg, DDR_SDRAM_CFG); |
| 36 | |
| 37 | out_be32(&ddr->cs0_bnds, DDR_CS0_BNDS); |
| 38 | out_be32(&ddr->cs0_config, DDR_CS0_CONFIG); |
| 39 | |
| 40 | out_be32(&ddr->timing_cfg_0, DDR_TIMING_CFG_0); |
| 41 | out_be32(&ddr->timing_cfg_1, DDR_TIMING_CFG_1); |
| 42 | out_be32(&ddr->timing_cfg_2, DDR_TIMING_CFG_2); |
| 43 | out_be32(&ddr->timing_cfg_3, DDR_TIMING_CFG_3); |
| 44 | out_be32(&ddr->timing_cfg_4, DDR_TIMING_CFG_4); |
| 45 | out_be32(&ddr->timing_cfg_5, DDR_TIMING_CFG_5); |
| 46 | |
| 47 | #ifdef CONFIG_DEEP_SLEEP |
| 48 | if (is_warm_boot()) { |
| 49 | out_be32(&ddr->sdram_cfg_2, |
| 50 | DDR_SDRAM_CFG_2 & ~SDRAM_CFG2_D_INIT); |
Tom Rini | bb4dd96 | 2022-11-16 13:10:37 -0500 | [diff] [blame] | 51 | out_be32(&ddr->init_addr, CFG_SYS_SDRAM_BASE); |
Jianchao Wang | e5332ba | 2019-07-19 00:30:01 +0300 | [diff] [blame] | 52 | out_be32(&ddr->init_ext_addr, (1 << 31)); |
| 53 | |
| 54 | /* DRAM VRef will not be trained */ |
| 55 | out_be32(&ddr->ddr_cdr2, |
| 56 | DDR_DDR_CDR2 & ~DDR_CDR2_VREF_TRAIN_EN); |
| 57 | } else |
| 58 | #endif |
| 59 | { |
| 60 | out_be32(&ddr->sdram_cfg_2, DDR_SDRAM_CFG_2); |
| 61 | out_be32(&ddr->ddr_cdr2, DDR_DDR_CDR2); |
| 62 | } |
| 63 | |
| 64 | out_be32(&ddr->sdram_mode, DDR_SDRAM_MODE); |
| 65 | out_be32(&ddr->sdram_mode_2, DDR_SDRAM_MODE_2); |
| 66 | |
| 67 | out_be32(&ddr->sdram_interval, DDR_SDRAM_INTERVAL); |
| 68 | |
| 69 | out_be32(&ddr->ddr_wrlvl_cntl, DDR_DDR_WRLVL_CNTL); |
| 70 | |
| 71 | out_be32(&ddr->ddr_wrlvl_cntl_2, DDR_DDR_WRLVL_CNTL_2); |
| 72 | out_be32(&ddr->ddr_wrlvl_cntl_3, DDR_DDR_WRLVL_CNTL_3); |
| 73 | |
| 74 | out_be32(&ddr->ddr_cdr1, DDR_DDR_CDR1); |
| 75 | |
| 76 | out_be32(&ddr->sdram_clk_cntl, DDR_SDRAM_CLK_CNTL); |
| 77 | out_be32(&ddr->ddr_zq_cntl, DDR_DDR_ZQ_CNTL); |
| 78 | |
| 79 | out_be32(&ddr->cs0_config_2, DDR_CS0_CONFIG_2); |
| 80 | |
| 81 | /* DDR erratum A-009942 */ |
| 82 | tmp = in_be32(&ddr->debug[28]); |
| 83 | out_be32(&ddr->debug[28], tmp | 0x0070006f); |
| 84 | |
| 85 | udelay(1); |
| 86 | |
| 87 | #ifdef CONFIG_DEEP_SLEEP |
| 88 | if (is_warm_boot()) { |
| 89 | /* enter self-refresh */ |
| 90 | temp_sdram_cfg = in_be32(&ddr->sdram_cfg_2); |
| 91 | temp_sdram_cfg |= SDRAM_CFG2_FRC_SR; |
| 92 | out_be32(&ddr->sdram_cfg_2, temp_sdram_cfg); |
| 93 | |
| 94 | temp_sdram_cfg = (DDR_SDRAM_CFG_MEM_EN | SDRAM_CFG_BI); |
| 95 | } else |
| 96 | #endif |
| 97 | temp_sdram_cfg = (DDR_SDRAM_CFG_MEM_EN & ~SDRAM_CFG_BI); |
| 98 | |
| 99 | out_be32(&ddr->sdram_cfg, DDR_SDRAM_CFG | temp_sdram_cfg); |
| 100 | |
| 101 | #ifdef CONFIG_DEEP_SLEEP |
| 102 | if (is_warm_boot()) { |
| 103 | /* exit self-refresh */ |
| 104 | temp_sdram_cfg = in_be32(&ddr->sdram_cfg_2); |
| 105 | temp_sdram_cfg &= ~SDRAM_CFG2_FRC_SR; |
| 106 | out_be32(&ddr->sdram_cfg_2, temp_sdram_cfg); |
| 107 | } |
| 108 | #endif |
| 109 | #endif /* !defined(CONFIG_SPL) || defined(CONFIG_SPL_BUILD) */ |
| 110 | } |
| 111 | |
| 112 | int dram_init(void) |
| 113 | { |
| 114 | ddrmc_init(); |
| 115 | |
| 116 | erratum_a008850_post(); |
| 117 | |
| 118 | gd->ram_size = get_ram_size((void *)PHYS_SDRAM, PHYS_SDRAM_SIZE); |
| 119 | |
| 120 | #if defined(CONFIG_DEEP_SLEEP) && !defined(CONFIG_SPL_BUILD) |
| 121 | fsl_dp_resume(); |
| 122 | #endif |
| 123 | |
| 124 | return 0; |
| 125 | } |
| 126 | |
Masahiro Yamada | f7ed78b | 2020-06-26 15:13:33 +0900 | [diff] [blame] | 127 | int board_eth_init(struct bd_info *bis) |
Jianchao Wang | e5332ba | 2019-07-19 00:30:01 +0300 | [diff] [blame] | 128 | { |
| 129 | return pci_eth_init(bis); |
| 130 | } |
| 131 | |
| 132 | int board_early_init_f(void) |
| 133 | { |
Tom Rini | 376b88a | 2022-10-28 20:27:13 -0400 | [diff] [blame] | 134 | struct ccsr_scfg *scfg = (struct ccsr_scfg *)CFG_SYS_FSL_SCFG_ADDR; |
Jianchao Wang | e5332ba | 2019-07-19 00:30:01 +0300 | [diff] [blame] | 135 | |
| 136 | #ifdef CONFIG_TSEC_ENET |
| 137 | /* |
| 138 | * Clear BD & FR bits for big endian BD's and frame data (aka set |
| 139 | * correct eTSEC endianness). This is crucial in ensuring that it does |
| 140 | * not report Data Parity Errors in its RX/TX FIFOs when attempting to |
| 141 | * send traffic. |
| 142 | */ |
| 143 | clrbits_be32(&scfg->etsecdmamcr, SCFG_ETSECDMAMCR_LE_BD_FR); |
| 144 | /* EC3_GTX_CLK125 (of enet2) used for all RGMII interfaces */ |
| 145 | out_be32(&scfg->etsecmcr, SCFG_ETSECCMCR_GE2_CLK125); |
| 146 | #endif |
| 147 | |
| 148 | arch_soc_init(); |
| 149 | |
| 150 | #if defined(CONFIG_DEEP_SLEEP) |
| 151 | if (is_warm_boot()) { |
| 152 | timer_init(); |
| 153 | dram_init(); |
| 154 | } |
| 155 | #endif |
| 156 | |
| 157 | return 0; |
| 158 | } |
| 159 | |
| 160 | #ifdef CONFIG_SPL_BUILD |
| 161 | void board_init_f(ulong dummy) |
| 162 | { |
| 163 | void (*second_uboot)(void); |
| 164 | |
| 165 | /* Clear the BSS */ |
| 166 | memset(__bss_start, 0, __bss_end - __bss_start); |
| 167 | |
| 168 | get_clocks(); |
| 169 | |
| 170 | #if defined(CONFIG_DEEP_SLEEP) |
| 171 | if (is_warm_boot()) |
| 172 | fsl_dp_disable_console(); |
| 173 | #endif |
| 174 | |
| 175 | preloader_console_init(); |
| 176 | |
| 177 | dram_init(); |
| 178 | |
| 179 | /* Allow OCRAM access permission as R/W */ |
| 180 | #ifdef CONFIG_LAYERSCAPE_NS_ACCESS |
| 181 | enable_layerscape_ns_access(); |
| 182 | enable_layerscape_ns_access(); |
| 183 | #endif |
| 184 | |
| 185 | /* |
| 186 | * if it is woken up from deep sleep, then jump to second |
| 187 | * stage U-Boot and continue executing without recopying |
| 188 | * it from SD since it has already been reserved in memory |
| 189 | * in last boot. |
| 190 | */ |
| 191 | if (is_warm_boot()) { |
Simon Glass | 72cc538 | 2022-10-20 18:22:39 -0600 | [diff] [blame] | 192 | second_uboot = (void (*)(void))CONFIG_TEXT_BASE; |
Jianchao Wang | e5332ba | 2019-07-19 00:30:01 +0300 | [diff] [blame] | 193 | second_uboot(); |
| 194 | } |
| 195 | |
| 196 | board_init_r(NULL, 0); |
| 197 | } |
| 198 | #endif |
| 199 | |
| 200 | int board_init(void) |
| 201 | { |
| 202 | #ifndef CONFIG_SYS_FSL_NO_SERDES |
| 203 | fsl_serdes_init(); |
| 204 | #endif |
| 205 | ls102xa_smmu_stream_id_init(); |
| 206 | |
| 207 | #ifdef CONFIG_LAYERSCAPE_NS_ACCESS |
| 208 | enable_layerscape_ns_access(); |
| 209 | #endif |
| 210 | |
| 211 | #ifdef CONFIG_U_QE |
| 212 | u_qe_init(); |
| 213 | #endif |
| 214 | |
| 215 | return 0; |
| 216 | } |
| 217 | |
| 218 | #if defined(CONFIG_SPL_BUILD) |
| 219 | void spl_board_init(void) |
| 220 | { |
| 221 | ls102xa_smmu_stream_id_init(); |
| 222 | } |
| 223 | #endif |
| 224 | |
| 225 | #ifdef CONFIG_BOARD_LATE_INIT |
| 226 | int board_late_init(void) |
| 227 | { |
| 228 | #ifdef CONFIG_CHAIN_OF_TRUST |
| 229 | fsl_setenv_chain_of_trust(); |
| 230 | #endif |
| 231 | |
| 232 | return 0; |
| 233 | } |
| 234 | #endif |
| 235 | |
| 236 | #if defined(CONFIG_MISC_INIT_R) |
| 237 | int misc_init_r(void) |
| 238 | { |
| 239 | #ifdef CONFIG_FSL_DEVICE_DISABLE |
| 240 | device_disable(devdis_tbl, ARRAY_SIZE(devdis_tbl)); |
| 241 | #endif |
Gaurav Jain | 476c639 | 2022-03-24 11:50:35 +0530 | [diff] [blame] | 242 | return 0; |
Jianchao Wang | e5332ba | 2019-07-19 00:30:01 +0300 | [diff] [blame] | 243 | } |
| 244 | #endif |
| 245 | |
| 246 | #if defined(CONFIG_DEEP_SLEEP) |
| 247 | void board_sleep_prepare(void) |
| 248 | { |
| 249 | #ifdef CONFIG_LAYERSCAPE_NS_ACCESS |
| 250 | enable_layerscape_ns_access(); |
| 251 | #endif |
| 252 | } |
| 253 | #endif |
| 254 | |
Masahiro Yamada | f7ed78b | 2020-06-26 15:13:33 +0900 | [diff] [blame] | 255 | int ft_board_setup(void *blob, struct bd_info *bd) |
Jianchao Wang | e5332ba | 2019-07-19 00:30:01 +0300 | [diff] [blame] | 256 | { |
| 257 | ft_cpu_setup(blob, bd); |
| 258 | |
| 259 | #ifdef CONFIG_PCI |
| 260 | ft_pci_setup(blob, bd); |
| 261 | #endif |
| 262 | |
| 263 | return 0; |
| 264 | } |