Tom Rini | 10e4779 | 2018-05-06 17:58:06 -0400 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0+ |
Feng Li | 39e112d | 2016-11-03 14:15:17 +0800 | [diff] [blame] | 2 | /* |
| 3 | * Copyright 2016 Freescale Semiconductor, Inc. |
Gaurav Jain | 476c639 | 2022-03-24 11:50:35 +0530 | [diff] [blame] | 4 | * Copyright 2021 NXP |
Feng Li | 39e112d | 2016-11-03 14:15:17 +0800 | [diff] [blame] | 5 | */ |
| 6 | |
| 7 | #include <common.h> |
Simon Glass | 85d6531 | 2019-12-28 10:44:58 -0700 | [diff] [blame] | 8 | #include <clock_legacy.h> |
Simon Glass | 3bbe70c | 2019-12-28 10:44:54 -0700 | [diff] [blame] | 9 | #include <fdt_support.h> |
Simon Glass | a7b5130 | 2019-11-14 12:57:46 -0700 | [diff] [blame] | 10 | #include <init.h> |
Simon Glass | 274e0b0 | 2020-05-10 11:39:56 -0600 | [diff] [blame] | 11 | #include <net.h> |
Feng Li | 39e112d | 2016-11-03 14:15:17 +0800 | [diff] [blame] | 12 | #include <asm/arch/immap_ls102xa.h> |
| 13 | #include <asm/arch/clock.h> |
| 14 | #include <asm/arch/fsl_serdes.h> |
| 15 | #include <asm/arch/ls102xa_stream_id.h> |
Simon Glass | 3ba929a | 2020-10-30 21:38:53 -0600 | [diff] [blame] | 16 | #include <asm/global_data.h> |
Simon Glass | dbd7954 | 2020-05-10 11:40:11 -0600 | [diff] [blame] | 17 | #include <linux/delay.h> |
Feng Li | 39e112d | 2016-11-03 14:15:17 +0800 | [diff] [blame] | 18 | |
| 19 | #include <asm/arch/ls102xa_devdis.h> |
| 20 | #include <asm/arch/ls102xa_soc.h> |
Feng Li | 39e112d | 2016-11-03 14:15:17 +0800 | [diff] [blame] | 21 | #include <fsl_csu.h> |
Feng Li | 39e112d | 2016-11-03 14:15:17 +0800 | [diff] [blame] | 22 | #include <fsl_immap.h> |
| 23 | #include <netdev.h> |
| 24 | #include <fsl_mdio.h> |
| 25 | #include <tsec.h> |
| 26 | #include <spl.h> |
| 27 | |
| 28 | #include <fsl_validate.h> |
| 29 | #include "../common/sleep.h" |
| 30 | |
| 31 | DECLARE_GLOBAL_DATA_PTR; |
| 32 | |
| 33 | #define DDR_SIZE 0x40000000 |
| 34 | |
| 35 | |
| 36 | int checkboard(void) |
| 37 | { |
| 38 | puts("Board: LS1021AIOT\n"); |
| 39 | |
| 40 | #ifndef CONFIG_QSPI_BOOT |
| 41 | struct ccsr_gur *dcfg = (struct ccsr_gur *)CONFIG_SYS_FSL_GUTS_ADDR; |
| 42 | u32 cpldrev; |
| 43 | |
| 44 | cpldrev = in_be32(&dcfg->gpporcr1); |
| 45 | |
| 46 | printf("CPLD: V%d.%d\n", ((cpldrev >> 28) & 0xf), ((cpldrev >> 24) & |
| 47 | 0xf)); |
| 48 | #endif |
| 49 | return 0; |
| 50 | } |
| 51 | |
| 52 | void ddrmc_init(void) |
| 53 | { |
| 54 | struct ccsr_ddr *ddr = (struct ccsr_ddr *)CONFIG_SYS_FSL_DDR_ADDR; |
| 55 | u32 temp_sdram_cfg, tmp; |
| 56 | |
| 57 | out_be32(&ddr->sdram_cfg, DDR_SDRAM_CFG); |
| 58 | |
| 59 | out_be32(&ddr->cs0_bnds, DDR_CS0_BNDS); |
| 60 | out_be32(&ddr->cs0_config, DDR_CS0_CONFIG); |
| 61 | |
| 62 | out_be32(&ddr->timing_cfg_0, DDR_TIMING_CFG_0); |
| 63 | out_be32(&ddr->timing_cfg_1, DDR_TIMING_CFG_1); |
| 64 | out_be32(&ddr->timing_cfg_2, DDR_TIMING_CFG_2); |
| 65 | out_be32(&ddr->timing_cfg_3, DDR_TIMING_CFG_3); |
| 66 | out_be32(&ddr->timing_cfg_4, DDR_TIMING_CFG_4); |
| 67 | out_be32(&ddr->timing_cfg_5, DDR_TIMING_CFG_5); |
| 68 | |
| 69 | out_be32(&ddr->sdram_cfg_2, DDR_SDRAM_CFG_2); |
| 70 | out_be32(&ddr->ddr_cdr2, DDR_DDR_CDR2); |
| 71 | |
| 72 | out_be32(&ddr->sdram_mode, DDR_SDRAM_MODE); |
| 73 | out_be32(&ddr->sdram_mode_2, DDR_SDRAM_MODE_2); |
| 74 | |
| 75 | out_be32(&ddr->sdram_interval, DDR_SDRAM_INTERVAL); |
| 76 | |
| 77 | out_be32(&ddr->ddr_wrlvl_cntl, DDR_DDR_WRLVL_CNTL); |
| 78 | |
| 79 | out_be32(&ddr->ddr_wrlvl_cntl_2, DDR_DDR_WRLVL_CNTL_2); |
| 80 | out_be32(&ddr->ddr_wrlvl_cntl_3, DDR_DDR_WRLVL_CNTL_3); |
| 81 | |
| 82 | out_be32(&ddr->ddr_cdr1, DDR_DDR_CDR1); |
| 83 | |
| 84 | out_be32(&ddr->sdram_clk_cntl, DDR_SDRAM_CLK_CNTL); |
| 85 | out_be32(&ddr->ddr_zq_cntl, DDR_DDR_ZQ_CNTL); |
| 86 | |
| 87 | out_be32(&ddr->cs0_config_2, DDR_CS0_CONFIG_2); |
| 88 | |
| 89 | /* DDR erratum A-009942 */ |
| 90 | tmp = in_be32(&ddr->debug[28]); |
| 91 | out_be32(&ddr->debug[28], tmp | 0x0070006f); |
| 92 | |
| 93 | udelay(500); |
| 94 | |
| 95 | temp_sdram_cfg = (DDR_SDRAM_CFG_MEM_EN & ~SDRAM_CFG_BI); |
| 96 | |
| 97 | out_be32(&ddr->sdram_cfg, DDR_SDRAM_CFG | temp_sdram_cfg); |
| 98 | } |
| 99 | |
| 100 | int dram_init(void) |
| 101 | { |
| 102 | #if (!defined(CONFIG_SPL) || defined(CONFIG_SPL_BUILD)) |
| 103 | ddrmc_init(); |
| 104 | #endif |
| 105 | |
Alison Wang | d6be97b | 2019-03-06 14:49:14 +0800 | [diff] [blame] | 106 | erratum_a008850_post(); |
| 107 | |
Feng Li | 39e112d | 2016-11-03 14:15:17 +0800 | [diff] [blame] | 108 | gd->ram_size = DDR_SIZE; |
| 109 | return 0; |
| 110 | } |
| 111 | |
Feng Li | 39e112d | 2016-11-03 14:15:17 +0800 | [diff] [blame] | 112 | #ifdef CONFIG_TSEC_ENET |
Masahiro Yamada | f7ed78b | 2020-06-26 15:13:33 +0900 | [diff] [blame] | 113 | int board_eth_init(struct bd_info *bis) |
Feng Li | 39e112d | 2016-11-03 14:15:17 +0800 | [diff] [blame] | 114 | { |
| 115 | struct fsl_pq_mdio_info mdio_info; |
| 116 | struct tsec_info_struct tsec_info[4]; |
| 117 | int num = 0; |
| 118 | |
| 119 | #ifdef CONFIG_TSEC1 |
| 120 | SET_STD_TSEC_INFO(tsec_info[num], 1); |
| 121 | if (is_serdes_configured(SGMII_TSEC1)) { |
| 122 | puts("eTSEC1 is in sgmii mode.\n"); |
| 123 | tsec_info[num].flags |= TSEC_SGMII; |
| 124 | } |
| 125 | num++; |
| 126 | #endif |
| 127 | #ifdef CONFIG_TSEC2 |
| 128 | SET_STD_TSEC_INFO(tsec_info[num], 2); |
| 129 | if (is_serdes_configured(SGMII_TSEC2)) { |
| 130 | puts("eTSEC2 is in sgmii mode.\n"); |
| 131 | tsec_info[num].flags |= TSEC_SGMII; |
| 132 | } |
| 133 | num++; |
| 134 | #endif |
| 135 | if (!num) { |
| 136 | printf("No TSECs initialized\n"); |
| 137 | return 0; |
| 138 | } |
| 139 | |
| 140 | mdio_info.regs = (struct tsec_mii_mng *)CONFIG_SYS_MDIO_BASE_ADDR; |
| 141 | mdio_info.name = DEFAULT_MII_NAME; |
| 142 | fsl_pq_mdio_init(bis, &mdio_info); |
| 143 | |
| 144 | tsec_eth_init(bis, tsec_info, num); |
| 145 | |
| 146 | return pci_eth_init(bis); |
| 147 | } |
| 148 | #endif |
| 149 | |
| 150 | int board_early_init_f(void) |
| 151 | { |
| 152 | struct ccsr_scfg *scfg = (struct ccsr_scfg *)CONFIG_SYS_FSL_SCFG_ADDR; |
| 153 | |
| 154 | #ifdef CONFIG_TSEC_ENET |
| 155 | /* clear BD & FR bits for BE BD's and frame data */ |
| 156 | clrbits_be32(&scfg->etsecdmamcr, SCFG_ETSECDMAMCR_LE_BD_FR); |
| 157 | out_be32(&scfg->etsecmcr, SCFG_ETSECCMCR_GE2_CLK125); |
| 158 | |
| 159 | #endif |
| 160 | |
| 161 | arch_soc_init(); |
| 162 | |
| 163 | return 0; |
| 164 | } |
| 165 | |
| 166 | #ifdef CONFIG_SPL_BUILD |
| 167 | void board_init_f(ulong dummy) |
| 168 | { |
| 169 | /* Clear the BSS */ |
| 170 | memset(__bss_start, 0, __bss_end - __bss_start); |
| 171 | |
| 172 | get_clocks(); |
| 173 | |
| 174 | preloader_console_init(); |
| 175 | |
| 176 | dram_init(); |
| 177 | |
| 178 | /* Allow OCRAM access permission as R/W */ |
| 179 | |
| 180 | #ifdef CONFIG_LAYERSCAPE_NS_ACCESS |
| 181 | enable_layerscape_ns_access(); |
| 182 | #endif |
| 183 | |
| 184 | board_init_r(NULL, 0); |
| 185 | } |
| 186 | #endif |
| 187 | |
| 188 | int board_init(void) |
| 189 | { |
| 190 | #ifndef CONFIG_SYS_FSL_NO_SERDES |
| 191 | fsl_serdes_init(); |
| 192 | #endif |
| 193 | |
| 194 | ls102xa_smmu_stream_id_init(); |
| 195 | |
Feng Li | 39e112d | 2016-11-03 14:15:17 +0800 | [diff] [blame] | 196 | return 0; |
| 197 | } |
| 198 | |
| 199 | #ifdef CONFIG_BOARD_LATE_INIT |
| 200 | int board_late_init(void) |
| 201 | { |
Feng Li | 39e112d | 2016-11-03 14:15:17 +0800 | [diff] [blame] | 202 | return 0; |
| 203 | } |
| 204 | #endif |
| 205 | |
| 206 | #if defined(CONFIG_MISC_INIT_R) |
| 207 | int misc_init_r(void) |
| 208 | { |
| 209 | #ifdef CONFIG_FSL_DEVICE_DISABLE |
| 210 | device_disable(devdis_tbl, ARRAY_SIZE(devdis_tbl)); |
| 211 | |
| 212 | #endif |
Gaurav Jain | 476c639 | 2022-03-24 11:50:35 +0530 | [diff] [blame] | 213 | return 0; |
Feng Li | 39e112d | 2016-11-03 14:15:17 +0800 | [diff] [blame] | 214 | } |
| 215 | #endif |
| 216 | |
Masahiro Yamada | f7ed78b | 2020-06-26 15:13:33 +0900 | [diff] [blame] | 217 | int ft_board_setup(void *blob, struct bd_info *bd) |
Feng Li | 39e112d | 2016-11-03 14:15:17 +0800 | [diff] [blame] | 218 | { |
| 219 | ft_cpu_setup(blob, bd); |
| 220 | |
| 221 | #ifdef CONFIG_PCI |
| 222 | ft_pci_setup(blob, bd); |
| 223 | #endif |
| 224 | |
| 225 | return 0; |
| 226 | } |
| 227 | |
| 228 | void flash_write16(u16 val, void *addr) |
| 229 | { |
| 230 | u16 shftval = (((val >> 8) & 0xff) | ((val << 8) & 0xff00)); |
| 231 | |
| 232 | __raw_writew(shftval, addr); |
| 233 | } |
| 234 | |
| 235 | u16 flash_read16(void *addr) |
| 236 | { |
| 237 | u16 val = __raw_readw(addr); |
| 238 | |
| 239 | return (((val) >> 8) & 0x00ff) | (((val) << 8) & 0xff00); |
| 240 | } |