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