Tom Rini | 83d290c | 2018-05-06 17:58:06 -0400 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0+ |
Prabhakar Kushwaha | 3b6e389 | 2016-06-03 18:41:35 +0530 | [diff] [blame] | 2 | /* |
| 3 | * Copyright 2016 Freescale Semiconductor, Inc. |
Prabhakar Kushwaha | 3b6e389 | 2016-06-03 18:41:35 +0530 | [diff] [blame] | 4 | */ |
| 5 | |
| 6 | #include <common.h> |
Simon Glass | 807765b | 2019-12-28 10:44:54 -0700 | [diff] [blame] | 7 | #include <fdt_support.h> |
Simon Glass | db41d65 | 2019-12-28 10:45:07 -0700 | [diff] [blame] | 8 | #include <hang.h> |
Prabhakar Kushwaha | 3b6e389 | 2016-06-03 18:41:35 +0530 | [diff] [blame] | 9 | #include <i2c.h> |
| 10 | #include <asm/io.h> |
| 11 | #include <asm/arch/clock.h> |
| 12 | #include <asm/arch/fsl_serdes.h> |
Prabhakar Kushwaha | 5b404be | 2017-01-30 17:05:35 +0530 | [diff] [blame] | 13 | #ifdef CONFIG_FSL_LS_PPA |
| 14 | #include <asm/arch/ppa.h> |
| 15 | #endif |
York Sun | 4961eaf | 2017-03-06 09:02:34 -0800 | [diff] [blame] | 16 | #include <asm/arch/mmu.h> |
Prabhakar Kushwaha | 3b6e389 | 2016-06-03 18:41:35 +0530 | [diff] [blame] | 17 | #include <asm/arch/soc.h> |
| 18 | #include <hwconfig.h> |
| 19 | #include <ahci.h> |
| 20 | #include <mmc.h> |
| 21 | #include <scsi.h> |
Prabhakar Kushwaha | 3b6e389 | 2016-06-03 18:41:35 +0530 | [diff] [blame] | 22 | #include <fsl_esdhc.h> |
Simon Glass | f3998fd | 2019-08-02 09:44:25 -0600 | [diff] [blame] | 23 | #include <env_internal.h> |
Prabhakar Kushwaha | 3b6e389 | 2016-06-03 18:41:35 +0530 | [diff] [blame] | 24 | #include <fsl_mmdc.h> |
| 25 | #include <netdev.h> |
Vinitha Pillai-B57223 | 11d14bf | 2017-03-23 13:48:20 +0530 | [diff] [blame] | 26 | #include <fsl_sec.h> |
Prabhakar Kushwaha | 3b6e389 | 2016-06-03 18:41:35 +0530 | [diff] [blame] | 27 | |
| 28 | DECLARE_GLOBAL_DATA_PTR; |
| 29 | |
Jagdish Gediya | 3fa48f0 | 2018-04-13 00:18:22 +0530 | [diff] [blame] | 30 | #define BOOT_FROM_UPPER_BANK 0x2 |
| 31 | #define BOOT_FROM_LOWER_BANK 0x1 |
| 32 | |
Prabhakar Kushwaha | 3b6e389 | 2016-06-03 18:41:35 +0530 | [diff] [blame] | 33 | int checkboard(void) |
| 34 | { |
Bhaskar Upadhaya | b0ce187 | 2018-01-11 20:03:31 +0530 | [diff] [blame] | 35 | #ifdef CONFIG_TARGET_LS1012ARDB |
Prabhakar Kushwaha | 3b6e389 | 2016-06-03 18:41:35 +0530 | [diff] [blame] | 36 | u8 in1; |
| 37 | |
| 38 | puts("Board: LS1012ARDB "); |
| 39 | |
| 40 | /* Initialize i2c early for Serial flash bank information */ |
| 41 | i2c_set_bus_num(0); |
| 42 | |
Yangbo Lu | 481fb01 | 2017-12-08 15:35:35 +0800 | [diff] [blame] | 43 | if (i2c_read(I2C_MUX_IO_ADDR, I2C_MUX_IO_1, 1, &in1, 1) < 0) { |
Prabhakar Kushwaha | 3b6e389 | 2016-06-03 18:41:35 +0530 | [diff] [blame] | 44 | printf("Error reading i2c boot information!\n"); |
| 45 | return 0; /* Don't want to hang() on this error */ |
| 46 | } |
| 47 | |
| 48 | puts("Version"); |
Yangbo Lu | 4a47bf8 | 2017-12-08 15:35:36 +0800 | [diff] [blame] | 49 | switch (in1 & SW_REV_MASK) { |
| 50 | case SW_REV_A: |
Prabhakar Kushwaha | 3b6e389 | 2016-06-03 18:41:35 +0530 | [diff] [blame] | 51 | puts(": RevA"); |
Yangbo Lu | 4a47bf8 | 2017-12-08 15:35:36 +0800 | [diff] [blame] | 52 | break; |
| 53 | case SW_REV_B: |
Prabhakar Kushwaha | 3b6e389 | 2016-06-03 18:41:35 +0530 | [diff] [blame] | 54 | puts(": RevB"); |
Yangbo Lu | 4a47bf8 | 2017-12-08 15:35:36 +0800 | [diff] [blame] | 55 | break; |
| 56 | case SW_REV_C: |
| 57 | puts(": RevC"); |
| 58 | break; |
| 59 | case SW_REV_C1: |
| 60 | puts(": RevC1"); |
| 61 | break; |
| 62 | case SW_REV_C2: |
| 63 | puts(": RevC2"); |
| 64 | break; |
| 65 | case SW_REV_D: |
| 66 | puts(": RevD"); |
| 67 | break; |
| 68 | case SW_REV_E: |
| 69 | puts(": RevE"); |
| 70 | break; |
| 71 | default: |
Prabhakar Kushwaha | 3b6e389 | 2016-06-03 18:41:35 +0530 | [diff] [blame] | 72 | puts(": unknown"); |
Yangbo Lu | 4a47bf8 | 2017-12-08 15:35:36 +0800 | [diff] [blame] | 73 | break; |
| 74 | } |
Prabhakar Kushwaha | 3b6e389 | 2016-06-03 18:41:35 +0530 | [diff] [blame] | 75 | |
| 76 | printf(", boot from QSPI"); |
Yangbo Lu | 481fb01 | 2017-12-08 15:35:35 +0800 | [diff] [blame] | 77 | if ((in1 & SW_BOOT_MASK) == SW_BOOT_EMU) |
Prabhakar Kushwaha | 3b6e389 | 2016-06-03 18:41:35 +0530 | [diff] [blame] | 78 | puts(": emu\n"); |
Yangbo Lu | 481fb01 | 2017-12-08 15:35:35 +0800 | [diff] [blame] | 79 | else if ((in1 & SW_BOOT_MASK) == SW_BOOT_BANK1) |
Prabhakar Kushwaha | 3b6e389 | 2016-06-03 18:41:35 +0530 | [diff] [blame] | 80 | puts(": bank1\n"); |
Yangbo Lu | 481fb01 | 2017-12-08 15:35:35 +0800 | [diff] [blame] | 81 | else if ((in1 & SW_BOOT_MASK) == SW_BOOT_BANK2) |
Prabhakar Kushwaha | 3b6e389 | 2016-06-03 18:41:35 +0530 | [diff] [blame] | 82 | puts(": bank2\n"); |
| 83 | else |
| 84 | puts("unknown\n"); |
Bhaskar Upadhaya | b0ce187 | 2018-01-11 20:03:31 +0530 | [diff] [blame] | 85 | #else |
Prabhakar Kushwaha | 3b6e389 | 2016-06-03 18:41:35 +0530 | [diff] [blame] | 86 | |
Bhaskar Upadhaya | b0ce187 | 2018-01-11 20:03:31 +0530 | [diff] [blame] | 87 | puts("Board: LS1012A2G5RDB "); |
| 88 | #endif |
Prabhakar Kushwaha | 3b6e389 | 2016-06-03 18:41:35 +0530 | [diff] [blame] | 89 | return 0; |
| 90 | } |
| 91 | |
Rajesh Bhagat | 1f6180d | 2018-11-05 18:02:53 +0000 | [diff] [blame] | 92 | #ifdef CONFIG_TFABOOT |
Prabhakar Kushwaha | 3b6e389 | 2016-06-03 18:41:35 +0530 | [diff] [blame] | 93 | int dram_init(void) |
| 94 | { |
Rajesh Bhagat | 1f6180d | 2018-11-05 18:02:53 +0000 | [diff] [blame] | 95 | gd->ram_size = tfa_get_dram_size(); |
| 96 | if (!gd->ram_size) |
| 97 | gd->ram_size = CONFIG_SYS_SDRAM_SIZE; |
| 98 | |
| 99 | return 0; |
| 100 | } |
| 101 | #else |
| 102 | int dram_init(void) |
| 103 | { |
| 104 | #ifndef CONFIG_TFABOOT |
York Sun | 1fdcc8d | 2016-09-26 08:09:25 -0700 | [diff] [blame] | 105 | static const struct fsl_mmdc_info mparam = { |
| 106 | 0x05180000, /* mdctl */ |
| 107 | 0x00030035, /* mdpdc */ |
| 108 | 0x12554000, /* mdotc */ |
| 109 | 0xbabf7954, /* mdcfg0 */ |
| 110 | 0xdb328f64, /* mdcfg1 */ |
| 111 | 0x01ff00db, /* mdcfg2 */ |
| 112 | 0x00001680, /* mdmisc */ |
| 113 | 0x0f3c8000, /* mdref */ |
| 114 | 0x00002000, /* mdrwd */ |
| 115 | 0x00bf1023, /* mdor */ |
| 116 | 0x0000003f, /* mdasp */ |
| 117 | 0x0000022a, /* mpodtctrl */ |
| 118 | 0xa1390003, /* mpzqhwctrl */ |
| 119 | }; |
| 120 | |
| 121 | mmdc_init(&mparam); |
Rajesh Bhagat | 1f6180d | 2018-11-05 18:02:53 +0000 | [diff] [blame] | 122 | #endif |
Prabhakar Kushwaha | 3b6e389 | 2016-06-03 18:41:35 +0530 | [diff] [blame] | 123 | |
| 124 | gd->ram_size = CONFIG_SYS_SDRAM_SIZE; |
York Sun | 4961eaf | 2017-03-06 09:02:34 -0800 | [diff] [blame] | 125 | #if !defined(CONFIG_SPL) || defined(CONFIG_SPL_BUILD) |
| 126 | /* This will break-before-make MMU for DDR */ |
| 127 | update_early_mmu_table(); |
| 128 | #endif |
Prabhakar Kushwaha | 3b6e389 | 2016-06-03 18:41:35 +0530 | [diff] [blame] | 129 | |
| 130 | return 0; |
| 131 | } |
Rajesh Bhagat | 1f6180d | 2018-11-05 18:02:53 +0000 | [diff] [blame] | 132 | #endif |
Prabhakar Kushwaha | 3b6e389 | 2016-06-03 18:41:35 +0530 | [diff] [blame] | 133 | |
Prabhakar Kushwaha | 3b6e389 | 2016-06-03 18:41:35 +0530 | [diff] [blame] | 134 | |
| 135 | int board_early_init_f(void) |
| 136 | { |
| 137 | fsl_lsch2_early_init_f(); |
| 138 | |
| 139 | return 0; |
| 140 | } |
| 141 | |
| 142 | int board_init(void) |
| 143 | { |
Ashish Kumar | 63b2316 | 2017-08-11 11:09:14 +0530 | [diff] [blame] | 144 | struct ccsr_cci400 *cci = (struct ccsr_cci400 *)(CONFIG_SYS_IMMR + |
| 145 | CONFIG_SYS_CCI400_OFFSET); |
Prabhakar Kushwaha | 3b6e389 | 2016-06-03 18:41:35 +0530 | [diff] [blame] | 146 | /* |
| 147 | * Set CCI-400 control override register to enable barrier |
| 148 | * transaction |
| 149 | */ |
Rajesh Bhagat | 1f6180d | 2018-11-05 18:02:53 +0000 | [diff] [blame] | 150 | if (current_el() == 3) |
| 151 | out_le32(&cci->ctrl_ord, CCI400_CTRLORD_EN_BARRIER); |
Prabhakar Kushwaha | 3b6e389 | 2016-06-03 18:41:35 +0530 | [diff] [blame] | 152 | |
Hou Zhiqiang | b392a6d | 2016-08-02 19:03:27 +0800 | [diff] [blame] | 153 | #ifdef CONFIG_SYS_FSL_ERRATUM_A010315 |
| 154 | erratum_a010315(); |
| 155 | #endif |
| 156 | |
Prabhakar Kushwaha | 3b6e389 | 2016-06-03 18:41:35 +0530 | [diff] [blame] | 157 | #ifdef CONFIG_ENV_IS_NOWHERE |
| 158 | gd->env_addr = (ulong)&default_environment[0]; |
| 159 | #endif |
| 160 | |
Vinitha Pillai-B57223 | 11d14bf | 2017-03-23 13:48:20 +0530 | [diff] [blame] | 161 | #ifdef CONFIG_FSL_CAAM |
| 162 | sec_init(); |
| 163 | #endif |
| 164 | |
Prabhakar Kushwaha | 5b404be | 2017-01-30 17:05:35 +0530 | [diff] [blame] | 165 | #ifdef CONFIG_FSL_LS_PPA |
| 166 | ppa_init(); |
| 167 | #endif |
Prabhakar Kushwaha | 3b6e389 | 2016-06-03 18:41:35 +0530 | [diff] [blame] | 168 | return 0; |
| 169 | } |
| 170 | |
Bhaskar Upadhaya | b0ce187 | 2018-01-11 20:03:31 +0530 | [diff] [blame] | 171 | #ifdef CONFIG_TARGET_LS1012ARDB |
Yangbo Lu | 5e4a6db | 2017-01-17 10:43:56 +0800 | [diff] [blame] | 172 | int esdhc_status_fixup(void *blob, const char *compat) |
| 173 | { |
Yangbo Lu | 5e4a6db | 2017-01-17 10:43:56 +0800 | [diff] [blame] | 174 | char esdhc1_path[] = "/soc/esdhc@1580000"; |
Yangbo Lu | 6aaa539 | 2017-12-08 15:35:37 +0800 | [diff] [blame] | 175 | bool sdhc2_en = false; |
Yangbo Lu | 5e4a6db | 2017-01-17 10:43:56 +0800 | [diff] [blame] | 176 | u8 mux_sdhc2; |
Yangbo Lu | 6aaa539 | 2017-12-08 15:35:37 +0800 | [diff] [blame] | 177 | u8 io = 0; |
Yangbo Lu | 5e4a6db | 2017-01-17 10:43:56 +0800 | [diff] [blame] | 178 | |
| 179 | i2c_set_bus_num(0); |
| 180 | |
Yangbo Lu | 6aaa539 | 2017-12-08 15:35:37 +0800 | [diff] [blame] | 181 | /* IO1[7:3] is the field of board revision info. */ |
| 182 | if (i2c_read(I2C_MUX_IO_ADDR, I2C_MUX_IO_1, 1, &io, 1) < 0) { |
Yangbo Lu | 5e4a6db | 2017-01-17 10:43:56 +0800 | [diff] [blame] | 183 | printf("Error reading i2c boot information!\n"); |
Yangbo Lu | 6aaa539 | 2017-12-08 15:35:37 +0800 | [diff] [blame] | 184 | return 0; |
Yangbo Lu | 5e4a6db | 2017-01-17 10:43:56 +0800 | [diff] [blame] | 185 | } |
| 186 | |
Yangbo Lu | 6aaa539 | 2017-12-08 15:35:37 +0800 | [diff] [blame] | 187 | /* hwconfig method is used for RevD and later versions. */ |
| 188 | if ((io & SW_REV_MASK) <= SW_REV_D) { |
| 189 | #ifdef CONFIG_HWCONFIG |
| 190 | if (hwconfig("esdhc1")) |
| 191 | sdhc2_en = true; |
| 192 | #endif |
| 193 | } else { |
| 194 | /* |
| 195 | * The I2C IO-expander for mux select is used to control |
| 196 | * the muxing of various onboard interfaces. |
| 197 | * |
| 198 | * IO0[3:2] indicates SDHC2 interface demultiplexer |
| 199 | * select lines. |
| 200 | * 00 - SDIO wifi |
| 201 | * 01 - GPIO (to Arduino) |
| 202 | * 10 - eMMC Memory |
| 203 | * 11 - SPI |
| 204 | */ |
| 205 | if (i2c_read(I2C_MUX_IO_ADDR, I2C_MUX_IO_0, 1, &io, 1) < 0) { |
| 206 | printf("Error reading i2c boot information!\n"); |
| 207 | return 0; |
| 208 | } |
| 209 | |
| 210 | mux_sdhc2 = (io & 0x0c) >> 2; |
| 211 | /* Enable SDHC2 only when use SDIO wifi and eMMC */ |
| 212 | if (mux_sdhc2 == 2 || mux_sdhc2 == 0) |
| 213 | sdhc2_en = true; |
| 214 | } |
Yangbo Lu | 6aaa539 | 2017-12-08 15:35:37 +0800 | [diff] [blame] | 215 | if (sdhc2_en) |
Yangbo Lu | 5e4a6db | 2017-01-17 10:43:56 +0800 | [diff] [blame] | 216 | do_fixup_by_path(blob, esdhc1_path, "status", "okay", |
| 217 | sizeof("okay"), 1); |
| 218 | else |
| 219 | do_fixup_by_path(blob, esdhc1_path, "status", "disabled", |
| 220 | sizeof("disabled"), 1); |
| 221 | return 0; |
| 222 | } |
Bhaskar Upadhaya | b0ce187 | 2018-01-11 20:03:31 +0530 | [diff] [blame] | 223 | #endif |
Yangbo Lu | 5e4a6db | 2017-01-17 10:43:56 +0800 | [diff] [blame] | 224 | |
Prabhakar Kushwaha | 3b6e389 | 2016-06-03 18:41:35 +0530 | [diff] [blame] | 225 | int ft_board_setup(void *blob, bd_t *bd) |
| 226 | { |
| 227 | arch_fixup_fdt(blob); |
| 228 | |
| 229 | ft_cpu_setup(blob, bd); |
| 230 | |
| 231 | return 0; |
| 232 | } |
Jagdish Gediya | 3fa48f0 | 2018-04-13 00:18:22 +0530 | [diff] [blame] | 233 | |
| 234 | static int switch_to_bank1(void) |
| 235 | { |
| 236 | u8 data; |
| 237 | int ret; |
| 238 | |
| 239 | i2c_set_bus_num(0); |
| 240 | |
| 241 | data = 0xf4; |
| 242 | ret = i2c_write(0x24, 0x3, 1, &data, 1); |
| 243 | if (ret) { |
| 244 | printf("i2c write error to chip : %u, addr : %u, data : %u\n", |
| 245 | 0x24, 0x3, data); |
| 246 | } |
| 247 | |
| 248 | return ret; |
| 249 | } |
| 250 | |
| 251 | static int switch_to_bank2(void) |
| 252 | { |
| 253 | u8 data; |
| 254 | int ret; |
| 255 | |
| 256 | i2c_set_bus_num(0); |
| 257 | |
| 258 | data = 0xfc; |
| 259 | ret = i2c_write(0x24, 0x7, 1, &data, 1); |
| 260 | if (ret) { |
| 261 | printf("i2c write error to chip : %u, addr : %u, data : %u\n", |
| 262 | 0x24, 0x7, data); |
| 263 | goto err; |
| 264 | } |
| 265 | |
| 266 | data = 0xf5; |
| 267 | ret = i2c_write(0x24, 0x3, 1, &data, 1); |
| 268 | if (ret) { |
| 269 | printf("i2c write error to chip : %u, addr : %u, data : %u\n", |
| 270 | 0x24, 0x3, data); |
| 271 | } |
| 272 | err: |
| 273 | return ret; |
| 274 | } |
| 275 | |
| 276 | static int convert_flash_bank(int bank) |
| 277 | { |
| 278 | int ret = 0; |
| 279 | |
| 280 | switch (bank) { |
| 281 | case BOOT_FROM_UPPER_BANK: |
| 282 | ret = switch_to_bank2(); |
| 283 | break; |
| 284 | case BOOT_FROM_LOWER_BANK: |
| 285 | ret = switch_to_bank1(); |
| 286 | break; |
| 287 | default: |
| 288 | ret = CMD_RET_USAGE; |
| 289 | break; |
| 290 | }; |
| 291 | |
| 292 | return ret; |
| 293 | } |
| 294 | |
| 295 | static int flash_bank_cmd(cmd_tbl_t *cmdtp, int flag, int argc, |
| 296 | char * const argv[]) |
| 297 | { |
| 298 | if (argc != 2) |
| 299 | return CMD_RET_USAGE; |
| 300 | if (strcmp(argv[1], "1") == 0) |
| 301 | convert_flash_bank(BOOT_FROM_LOWER_BANK); |
| 302 | else if (strcmp(argv[1], "2") == 0) |
| 303 | convert_flash_bank(BOOT_FROM_UPPER_BANK); |
| 304 | else |
| 305 | return CMD_RET_USAGE; |
| 306 | |
| 307 | return 0; |
| 308 | } |
| 309 | |
| 310 | U_BOOT_CMD( |
| 311 | boot_bank, 2, 0, flash_bank_cmd, |
| 312 | "Flash bank Selection Control", |
| 313 | "bank[1-lower bank/2-upper bank] (e.g. boot_bank 1)" |
| 314 | ); |