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