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> |
Simon Glass | ed38aef | 2020-05-10 11:40:03 -0600 | [diff] [blame] | 7 | #include <command.h> |
Simon Glass | 3bbe70c | 2019-12-28 10:44:54 -0700 | [diff] [blame] | 8 | #include <fdt_support.h> |
Simon Glass | f11478f | 2019-12-28 10:45:07 -0700 | [diff] [blame] | 9 | #include <hang.h> |
Prabhakar Kushwaha | a315c66 | 2016-06-03 18:41:35 +0530 | [diff] [blame] | 10 | #include <i2c.h> |
Simon Glass | 274e0b0 | 2020-05-10 11:39:56 -0600 | [diff] [blame] | 11 | #include <asm/cache.h> |
Simon Glass | 9758973 | 2020-05-10 11:40:02 -0600 | [diff] [blame] | 12 | #include <init.h> |
Prabhakar Kushwaha | a315c66 | 2016-06-03 18:41:35 +0530 | [diff] [blame] | 13 | #include <asm/io.h> |
| 14 | #include <asm/arch/clock.h> |
| 15 | #include <asm/arch/fsl_serdes.h> |
Prabhakar Kushwaha | 74d129b | 2017-01-30 17:05:35 +0530 | [diff] [blame] | 16 | #ifdef CONFIG_FSL_LS_PPA |
| 17 | #include <asm/arch/ppa.h> |
| 18 | #endif |
York Sun | 729f2d1 | 2017-03-06 09:02:34 -0800 | [diff] [blame] | 19 | #include <asm/arch/mmu.h> |
Prabhakar Kushwaha | a315c66 | 2016-06-03 18:41:35 +0530 | [diff] [blame] | 20 | #include <asm/arch/soc.h> |
| 21 | #include <hwconfig.h> |
| 22 | #include <ahci.h> |
| 23 | #include <mmc.h> |
| 24 | #include <scsi.h> |
Prabhakar Kushwaha | a315c66 | 2016-06-03 18:41:35 +0530 | [diff] [blame] | 25 | #include <fsl_esdhc.h> |
Simon Glass | 9d1f619 | 2019-08-02 09:44:25 -0600 | [diff] [blame] | 26 | #include <env_internal.h> |
Prabhakar Kushwaha | a315c66 | 2016-06-03 18:41:35 +0530 | [diff] [blame] | 27 | #include <fsl_mmdc.h> |
| 28 | #include <netdev.h> |
Vinitha Pillai-B57223 | eea4a32 | 2017-03-23 13:48:20 +0530 | [diff] [blame] | 29 | #include <fsl_sec.h> |
Prabhakar Kushwaha | a315c66 | 2016-06-03 18:41:35 +0530 | [diff] [blame] | 30 | |
| 31 | DECLARE_GLOBAL_DATA_PTR; |
| 32 | |
Jagdish Gediya | f9cb31e | 2018-04-13 00:18:22 +0530 | [diff] [blame] | 33 | #define BOOT_FROM_UPPER_BANK 0x2 |
| 34 | #define BOOT_FROM_LOWER_BANK 0x1 |
| 35 | |
Prabhakar Kushwaha | a315c66 | 2016-06-03 18:41:35 +0530 | [diff] [blame] | 36 | int checkboard(void) |
| 37 | { |
Bhaskar Upadhaya | 7fff22a | 2018-01-11 20:03:31 +0530 | [diff] [blame] | 38 | #ifdef CONFIG_TARGET_LS1012ARDB |
Prabhakar Kushwaha | a315c66 | 2016-06-03 18:41:35 +0530 | [diff] [blame] | 39 | u8 in1; |
Biwen Li | 0a759bb | 2019-12-31 15:33:41 +0800 | [diff] [blame] | 40 | int ret, bus_num = 0; |
Prabhakar Kushwaha | a315c66 | 2016-06-03 18:41:35 +0530 | [diff] [blame] | 41 | |
| 42 | puts("Board: LS1012ARDB "); |
| 43 | |
| 44 | /* Initialize i2c early for Serial flash bank information */ |
Biwen Li | 0a759bb | 2019-12-31 15:33:41 +0800 | [diff] [blame] | 45 | #if defined(CONFIG_DM_I2C) |
| 46 | struct udevice *dev; |
Prabhakar Kushwaha | a315c66 | 2016-06-03 18:41:35 +0530 | [diff] [blame] | 47 | |
Biwen Li | 0a759bb | 2019-12-31 15:33:41 +0800 | [diff] [blame] | 48 | ret = i2c_get_chip_for_busnum(bus_num, I2C_MUX_IO_ADDR, |
| 49 | 1, &dev); |
| 50 | if (ret) { |
| 51 | printf("%s: Cannot find udev for a bus %d\n", __func__, |
| 52 | bus_num); |
| 53 | return -ENXIO; |
| 54 | } |
| 55 | ret = dm_i2c_read(dev, I2C_MUX_IO_1, &in1, 1); |
| 56 | #else /* Non DM I2C support - will be removed */ |
| 57 | i2c_set_bus_num(bus_num); |
| 58 | ret = i2c_read(I2C_MUX_IO_ADDR, I2C_MUX_IO_1, 1, &in1, 1); |
| 59 | #endif |
| 60 | if (ret < 0) { |
Prabhakar Kushwaha | a315c66 | 2016-06-03 18:41:35 +0530 | [diff] [blame] | 61 | printf("Error reading i2c boot information!\n"); |
| 62 | return 0; /* Don't want to hang() on this error */ |
| 63 | } |
| 64 | |
| 65 | puts("Version"); |
Yangbo Lu | 13acb0d | 2017-12-08 15:35:36 +0800 | [diff] [blame] | 66 | switch (in1 & SW_REV_MASK) { |
| 67 | case SW_REV_A: |
Prabhakar Kushwaha | a315c66 | 2016-06-03 18:41:35 +0530 | [diff] [blame] | 68 | puts(": RevA"); |
Yangbo Lu | 13acb0d | 2017-12-08 15:35:36 +0800 | [diff] [blame] | 69 | break; |
| 70 | case SW_REV_B: |
Prabhakar Kushwaha | a315c66 | 2016-06-03 18:41:35 +0530 | [diff] [blame] | 71 | puts(": RevB"); |
Yangbo Lu | 13acb0d | 2017-12-08 15:35:36 +0800 | [diff] [blame] | 72 | break; |
| 73 | case SW_REV_C: |
| 74 | puts(": RevC"); |
| 75 | break; |
| 76 | case SW_REV_C1: |
| 77 | puts(": RevC1"); |
| 78 | break; |
| 79 | case SW_REV_C2: |
| 80 | puts(": RevC2"); |
| 81 | break; |
| 82 | case SW_REV_D: |
| 83 | puts(": RevD"); |
| 84 | break; |
| 85 | case SW_REV_E: |
| 86 | puts(": RevE"); |
| 87 | break; |
| 88 | default: |
Prabhakar Kushwaha | a315c66 | 2016-06-03 18:41:35 +0530 | [diff] [blame] | 89 | puts(": unknown"); |
Yangbo Lu | 13acb0d | 2017-12-08 15:35:36 +0800 | [diff] [blame] | 90 | break; |
| 91 | } |
Prabhakar Kushwaha | a315c66 | 2016-06-03 18:41:35 +0530 | [diff] [blame] | 92 | |
| 93 | printf(", boot from QSPI"); |
Yangbo Lu | 2786f90 | 2017-12-08 15:35:35 +0800 | [diff] [blame] | 94 | if ((in1 & SW_BOOT_MASK) == SW_BOOT_EMU) |
Prabhakar Kushwaha | a315c66 | 2016-06-03 18:41:35 +0530 | [diff] [blame] | 95 | puts(": emu\n"); |
Yangbo Lu | 2786f90 | 2017-12-08 15:35:35 +0800 | [diff] [blame] | 96 | else if ((in1 & SW_BOOT_MASK) == SW_BOOT_BANK1) |
Prabhakar Kushwaha | a315c66 | 2016-06-03 18:41:35 +0530 | [diff] [blame] | 97 | puts(": bank1\n"); |
Yangbo Lu | 2786f90 | 2017-12-08 15:35:35 +0800 | [diff] [blame] | 98 | else if ((in1 & SW_BOOT_MASK) == SW_BOOT_BANK2) |
Prabhakar Kushwaha | a315c66 | 2016-06-03 18:41:35 +0530 | [diff] [blame] | 99 | puts(": bank2\n"); |
| 100 | else |
| 101 | puts("unknown\n"); |
Bhaskar Upadhaya | 7fff22a | 2018-01-11 20:03:31 +0530 | [diff] [blame] | 102 | #else |
Prabhakar Kushwaha | a315c66 | 2016-06-03 18:41:35 +0530 | [diff] [blame] | 103 | |
Bhaskar Upadhaya | 7fff22a | 2018-01-11 20:03:31 +0530 | [diff] [blame] | 104 | puts("Board: LS1012A2G5RDB "); |
| 105 | #endif |
Prabhakar Kushwaha | a315c66 | 2016-06-03 18:41:35 +0530 | [diff] [blame] | 106 | return 0; |
| 107 | } |
| 108 | |
Rajesh Bhagat | fcafef6 | 2018-11-05 18:02:53 +0000 | [diff] [blame] | 109 | #ifdef CONFIG_TFABOOT |
Prabhakar Kushwaha | a315c66 | 2016-06-03 18:41:35 +0530 | [diff] [blame] | 110 | int dram_init(void) |
| 111 | { |
Rajesh Bhagat | fcafef6 | 2018-11-05 18:02:53 +0000 | [diff] [blame] | 112 | gd->ram_size = tfa_get_dram_size(); |
| 113 | if (!gd->ram_size) |
| 114 | gd->ram_size = CONFIG_SYS_SDRAM_SIZE; |
| 115 | |
| 116 | return 0; |
| 117 | } |
| 118 | #else |
| 119 | int dram_init(void) |
| 120 | { |
| 121 | #ifndef CONFIG_TFABOOT |
York Sun | c1e979b | 2016-09-26 08:09:25 -0700 | [diff] [blame] | 122 | static const struct fsl_mmdc_info mparam = { |
| 123 | 0x05180000, /* mdctl */ |
| 124 | 0x00030035, /* mdpdc */ |
| 125 | 0x12554000, /* mdotc */ |
| 126 | 0xbabf7954, /* mdcfg0 */ |
| 127 | 0xdb328f64, /* mdcfg1 */ |
| 128 | 0x01ff00db, /* mdcfg2 */ |
| 129 | 0x00001680, /* mdmisc */ |
| 130 | 0x0f3c8000, /* mdref */ |
| 131 | 0x00002000, /* mdrwd */ |
| 132 | 0x00bf1023, /* mdor */ |
| 133 | 0x0000003f, /* mdasp */ |
| 134 | 0x0000022a, /* mpodtctrl */ |
| 135 | 0xa1390003, /* mpzqhwctrl */ |
| 136 | }; |
| 137 | |
| 138 | mmdc_init(&mparam); |
Rajesh Bhagat | fcafef6 | 2018-11-05 18:02:53 +0000 | [diff] [blame] | 139 | #endif |
Prabhakar Kushwaha | a315c66 | 2016-06-03 18:41:35 +0530 | [diff] [blame] | 140 | |
| 141 | gd->ram_size = CONFIG_SYS_SDRAM_SIZE; |
York Sun | 729f2d1 | 2017-03-06 09:02:34 -0800 | [diff] [blame] | 142 | #if !defined(CONFIG_SPL) || defined(CONFIG_SPL_BUILD) |
| 143 | /* This will break-before-make MMU for DDR */ |
| 144 | update_early_mmu_table(); |
| 145 | #endif |
Prabhakar Kushwaha | a315c66 | 2016-06-03 18:41:35 +0530 | [diff] [blame] | 146 | |
| 147 | return 0; |
| 148 | } |
Rajesh Bhagat | fcafef6 | 2018-11-05 18:02:53 +0000 | [diff] [blame] | 149 | #endif |
Prabhakar Kushwaha | a315c66 | 2016-06-03 18:41:35 +0530 | [diff] [blame] | 150 | |
Prabhakar Kushwaha | a315c66 | 2016-06-03 18:41:35 +0530 | [diff] [blame] | 151 | |
| 152 | int board_early_init_f(void) |
| 153 | { |
| 154 | fsl_lsch2_early_init_f(); |
| 155 | |
| 156 | return 0; |
| 157 | } |
| 158 | |
| 159 | int board_init(void) |
| 160 | { |
Ashish Kumar | 1123406 | 2017-08-11 11:09:14 +0530 | [diff] [blame] | 161 | struct ccsr_cci400 *cci = (struct ccsr_cci400 *)(CONFIG_SYS_IMMR + |
| 162 | CONFIG_SYS_CCI400_OFFSET); |
Prabhakar Kushwaha | a315c66 | 2016-06-03 18:41:35 +0530 | [diff] [blame] | 163 | /* |
| 164 | * Set CCI-400 control override register to enable barrier |
| 165 | * transaction |
| 166 | */ |
Rajesh Bhagat | fcafef6 | 2018-11-05 18:02:53 +0000 | [diff] [blame] | 167 | if (current_el() == 3) |
| 168 | out_le32(&cci->ctrl_ord, CCI400_CTRLORD_EN_BARRIER); |
Prabhakar Kushwaha | a315c66 | 2016-06-03 18:41:35 +0530 | [diff] [blame] | 169 | |
Hou Zhiqiang | 4b23ca8 | 2016-08-02 19:03:27 +0800 | [diff] [blame] | 170 | #ifdef CONFIG_SYS_FSL_ERRATUM_A010315 |
| 171 | erratum_a010315(); |
| 172 | #endif |
| 173 | |
Prabhakar Kushwaha | a315c66 | 2016-06-03 18:41:35 +0530 | [diff] [blame] | 174 | #ifdef CONFIG_ENV_IS_NOWHERE |
| 175 | gd->env_addr = (ulong)&default_environment[0]; |
| 176 | #endif |
| 177 | |
Vinitha Pillai-B57223 | eea4a32 | 2017-03-23 13:48:20 +0530 | [diff] [blame] | 178 | #ifdef CONFIG_FSL_CAAM |
| 179 | sec_init(); |
| 180 | #endif |
| 181 | |
Prabhakar Kushwaha | 74d129b | 2017-01-30 17:05:35 +0530 | [diff] [blame] | 182 | #ifdef CONFIG_FSL_LS_PPA |
| 183 | ppa_init(); |
| 184 | #endif |
Prabhakar Kushwaha | a315c66 | 2016-06-03 18:41:35 +0530 | [diff] [blame] | 185 | return 0; |
| 186 | } |
| 187 | |
Bhaskar Upadhaya | 7fff22a | 2018-01-11 20:03:31 +0530 | [diff] [blame] | 188 | #ifdef CONFIG_TARGET_LS1012ARDB |
Yangbo Lu | b2495c0 | 2017-01-17 10:43:56 +0800 | [diff] [blame] | 189 | int esdhc_status_fixup(void *blob, const char *compat) |
| 190 | { |
Yangbo Lu | b2495c0 | 2017-01-17 10:43:56 +0800 | [diff] [blame] | 191 | char esdhc1_path[] = "/soc/esdhc@1580000"; |
Yangbo Lu | 878c978 | 2017-12-08 15:35:37 +0800 | [diff] [blame] | 192 | bool sdhc2_en = false; |
Yangbo Lu | b2495c0 | 2017-01-17 10:43:56 +0800 | [diff] [blame] | 193 | u8 mux_sdhc2; |
Yangbo Lu | 878c978 | 2017-12-08 15:35:37 +0800 | [diff] [blame] | 194 | u8 io = 0; |
Biwen Li | 0a759bb | 2019-12-31 15:33:41 +0800 | [diff] [blame] | 195 | int ret, bus_num = 0; |
Yangbo Lu | b2495c0 | 2017-01-17 10:43:56 +0800 | [diff] [blame] | 196 | |
Biwen Li | 0a759bb | 2019-12-31 15:33:41 +0800 | [diff] [blame] | 197 | #if defined(CONFIG_DM_I2C) |
| 198 | struct udevice *dev; |
Yangbo Lu | b2495c0 | 2017-01-17 10:43:56 +0800 | [diff] [blame] | 199 | |
Biwen Li | 0a759bb | 2019-12-31 15:33:41 +0800 | [diff] [blame] | 200 | ret = i2c_get_chip_for_busnum(bus_num, I2C_MUX_IO_ADDR, |
| 201 | 1, &dev); |
| 202 | if (ret) { |
| 203 | printf("%s: Cannot find udev for a bus %d\n", __func__, |
| 204 | bus_num); |
| 205 | return -ENXIO; |
| 206 | } |
| 207 | ret = dm_i2c_read(dev, I2C_MUX_IO_1, &io, 1); |
| 208 | #else |
| 209 | i2c_set_bus_num(bus_num); |
Yangbo Lu | 878c978 | 2017-12-08 15:35:37 +0800 | [diff] [blame] | 210 | /* IO1[7:3] is the field of board revision info. */ |
Biwen Li | 0a759bb | 2019-12-31 15:33:41 +0800 | [diff] [blame] | 211 | ret = i2c_read(I2C_MUX_IO_ADDR, I2C_MUX_IO_1, 1, &io, 1); |
| 212 | #endif |
| 213 | if (ret < 0) { |
Yangbo Lu | b2495c0 | 2017-01-17 10:43:56 +0800 | [diff] [blame] | 214 | printf("Error reading i2c boot information!\n"); |
Yangbo Lu | 878c978 | 2017-12-08 15:35:37 +0800 | [diff] [blame] | 215 | return 0; |
Yangbo Lu | b2495c0 | 2017-01-17 10:43:56 +0800 | [diff] [blame] | 216 | } |
| 217 | |
Yangbo Lu | 878c978 | 2017-12-08 15:35:37 +0800 | [diff] [blame] | 218 | /* hwconfig method is used for RevD and later versions. */ |
| 219 | if ((io & SW_REV_MASK) <= SW_REV_D) { |
| 220 | #ifdef CONFIG_HWCONFIG |
| 221 | if (hwconfig("esdhc1")) |
| 222 | sdhc2_en = true; |
| 223 | #endif |
| 224 | } else { |
| 225 | /* |
| 226 | * The I2C IO-expander for mux select is used to control |
| 227 | * the muxing of various onboard interfaces. |
| 228 | * |
| 229 | * IO0[3:2] indicates SDHC2 interface demultiplexer |
| 230 | * select lines. |
| 231 | * 00 - SDIO wifi |
| 232 | * 01 - GPIO (to Arduino) |
| 233 | * 10 - eMMC Memory |
| 234 | * 11 - SPI |
| 235 | */ |
Biwen Li | 0a759bb | 2019-12-31 15:33:41 +0800 | [diff] [blame] | 236 | #if defined(CONFIG_DM_I2C) |
| 237 | ret = dm_i2c_read(dev, I2C_MUX_IO_0, &io, 1); |
| 238 | #else |
| 239 | ret = i2c_read(I2C_MUX_IO_ADDR, I2C_MUX_IO_0, 1, &io, 1); |
| 240 | #endif |
| 241 | if (ret < 0) { |
Yangbo Lu | 878c978 | 2017-12-08 15:35:37 +0800 | [diff] [blame] | 242 | printf("Error reading i2c boot information!\n"); |
| 243 | return 0; |
| 244 | } |
| 245 | |
| 246 | mux_sdhc2 = (io & 0x0c) >> 2; |
| 247 | /* Enable SDHC2 only when use SDIO wifi and eMMC */ |
| 248 | if (mux_sdhc2 == 2 || mux_sdhc2 == 0) |
| 249 | sdhc2_en = true; |
| 250 | } |
Yangbo Lu | 878c978 | 2017-12-08 15:35:37 +0800 | [diff] [blame] | 251 | if (sdhc2_en) |
Yangbo Lu | b2495c0 | 2017-01-17 10:43:56 +0800 | [diff] [blame] | 252 | do_fixup_by_path(blob, esdhc1_path, "status", "okay", |
| 253 | sizeof("okay"), 1); |
| 254 | else |
| 255 | do_fixup_by_path(blob, esdhc1_path, "status", "disabled", |
| 256 | sizeof("disabled"), 1); |
| 257 | return 0; |
| 258 | } |
Bhaskar Upadhaya | 7fff22a | 2018-01-11 20:03:31 +0530 | [diff] [blame] | 259 | #endif |
Yangbo Lu | b2495c0 | 2017-01-17 10:43:56 +0800 | [diff] [blame] | 260 | |
Prabhakar Kushwaha | a315c66 | 2016-06-03 18:41:35 +0530 | [diff] [blame] | 261 | int ft_board_setup(void *blob, bd_t *bd) |
| 262 | { |
| 263 | arch_fixup_fdt(blob); |
| 264 | |
| 265 | ft_cpu_setup(blob, bd); |
| 266 | |
| 267 | return 0; |
| 268 | } |
Jagdish Gediya | f9cb31e | 2018-04-13 00:18:22 +0530 | [diff] [blame] | 269 | |
| 270 | static int switch_to_bank1(void) |
| 271 | { |
Biwen Li | 0a759bb | 2019-12-31 15:33:41 +0800 | [diff] [blame] | 272 | u8 data = 0xf4, chip_addr = 0x24, offset_addr = 0x03; |
| 273 | int ret, bus_num = 0; |
Jagdish Gediya | f9cb31e | 2018-04-13 00:18:22 +0530 | [diff] [blame] | 274 | |
Biwen Li | 0a759bb | 2019-12-31 15:33:41 +0800 | [diff] [blame] | 275 | #if defined(CONFIG_DM_I2C) |
| 276 | struct udevice *dev; |
| 277 | |
| 278 | ret = i2c_get_chip_for_busnum(bus_num, chip_addr, |
| 279 | 1, &dev); |
| 280 | if (ret) { |
| 281 | printf("%s: Cannot find udev for a bus %d\n", __func__, |
| 282 | bus_num); |
| 283 | return -ENXIO; |
| 284 | } |
| 285 | /* |
| 286 | * -------------------------------------------------------------------- |
| 287 | * |bus |I2C address| Device | Notes | |
| 288 | * -------------------------------------------------------------------- |
| 289 | * |I2C1|0x24, 0x25,| IO expander (CFG,| Provides 16bits of General | |
| 290 | * | |0x26 | RESET, and INT/ | Purpose parallel Input/Output| |
| 291 | * | | | KW41GPIO) - NXP | (GPIO) expansion for the | |
| 292 | * | | | PCAL9555AHF | I2C bus | |
| 293 | * ----- -------------------------------------------------------------- |
| 294 | * - mount three IO expander(PCAL9555AHF) on I2C1 |
| 295 | * |
| 296 | * PCAL9555A device address |
| 297 | * slave address |
| 298 | * -------------------------------------- |
| 299 | * | 0 | 1 | 0 | 0 | A2 | A1 | A0 | R/W | |
| 300 | * -------------------------------------- |
| 301 | * | fixed | hardware selectable| |
| 302 | * |
| 303 | * Output port 1(Pinter register bits = 0x03) |
| 304 | * |
| 305 | * P1_[7~0] = 0xf4 |
| 306 | * P1_0 <---> CFG_MUX_QSPI_S0 |
| 307 | * P1_1 <---> CFG_MUX_QSPI_S1 |
| 308 | * CFG_MUX_QSPI_S[1:0] = 0b00 |
| 309 | * |
| 310 | * QSPI chip-select demultiplexer select |
| 311 | * --------------------------------------------------------------------- |
| 312 | * CFG_MUX_QSPI_S1|CFG_MUX_QSPI_S0| Values |
| 313 | * --------------------------------------------------------------------- |
| 314 | * 0 | 0 |CS routed to SPI memory bank1(default) |
| 315 | * --------------------------------------------------------------------- |
| 316 | * 0 | 1 |CS routed to SPI memory bank2 |
| 317 | * --------------------------------------------------------------------- |
| 318 | * |
| 319 | */ |
| 320 | ret = dm_i2c_write(dev, offset_addr, &data, 1); |
| 321 | #else /* Non DM I2C support - will be removed */ |
| 322 | i2c_set_bus_num(bus_num); |
| 323 | ret = i2c_write(chip_addr, offset_addr, 1, &data, 1); |
| 324 | #endif |
Jagdish Gediya | f9cb31e | 2018-04-13 00:18:22 +0530 | [diff] [blame] | 325 | |
Jagdish Gediya | f9cb31e | 2018-04-13 00:18:22 +0530 | [diff] [blame] | 326 | if (ret) { |
| 327 | printf("i2c write error to chip : %u, addr : %u, data : %u\n", |
Biwen Li | 0a759bb | 2019-12-31 15:33:41 +0800 | [diff] [blame] | 328 | chip_addr, offset_addr, data); |
Jagdish Gediya | f9cb31e | 2018-04-13 00:18:22 +0530 | [diff] [blame] | 329 | } |
| 330 | |
| 331 | return ret; |
| 332 | } |
| 333 | |
| 334 | static int switch_to_bank2(void) |
| 335 | { |
Biwen Li | 0a759bb | 2019-12-31 15:33:41 +0800 | [diff] [blame] | 336 | u8 data[2] = {0xfc, 0xf5}, offset_addr[2] = {0x7, 0x3}; |
| 337 | u8 chip_addr = 0x24; |
| 338 | int ret, i, bus_num = 0; |
Jagdish Gediya | f9cb31e | 2018-04-13 00:18:22 +0530 | [diff] [blame] | 339 | |
Biwen Li | 0a759bb | 2019-12-31 15:33:41 +0800 | [diff] [blame] | 340 | #if defined(CONFIG_DM_I2C) |
| 341 | struct udevice *dev; |
Jagdish Gediya | f9cb31e | 2018-04-13 00:18:22 +0530 | [diff] [blame] | 342 | |
Biwen Li | 0a759bb | 2019-12-31 15:33:41 +0800 | [diff] [blame] | 343 | ret = i2c_get_chip_for_busnum(bus_num, chip_addr, |
| 344 | 1, &dev); |
Jagdish Gediya | f9cb31e | 2018-04-13 00:18:22 +0530 | [diff] [blame] | 345 | if (ret) { |
Biwen Li | 0a759bb | 2019-12-31 15:33:41 +0800 | [diff] [blame] | 346 | printf("%s: Cannot find udev for a bus %d\n", __func__, |
| 347 | bus_num); |
| 348 | return -ENXIO; |
Jagdish Gediya | f9cb31e | 2018-04-13 00:18:22 +0530 | [diff] [blame] | 349 | } |
Biwen Li | 0a759bb | 2019-12-31 15:33:41 +0800 | [diff] [blame] | 350 | #else /* Non DM I2C support - will be removed */ |
| 351 | i2c_set_bus_num(bus_num); |
| 352 | #endif |
Jagdish Gediya | f9cb31e | 2018-04-13 00:18:22 +0530 | [diff] [blame] | 353 | |
Biwen Li | 0a759bb | 2019-12-31 15:33:41 +0800 | [diff] [blame] | 354 | /* |
| 355 | * 1th step: config port 1 |
| 356 | * - the port 1 pin is enabled as an output |
| 357 | * 2th step: output port 1 |
| 358 | * - P1_[7:0] output 0xf5, |
| 359 | * then CFG_MUX_QSPI_S[1:0] equal to 0b01, |
| 360 | * CS routed to SPI memory bank2 |
| 361 | */ |
| 362 | for (i = 0; i < sizeof(data); i++) { |
| 363 | #if defined(CONFIG_DM_I2C) |
| 364 | ret = dm_i2c_write(dev, offset_addr[i], &data[i], 1); |
| 365 | #else /* Non DM I2C support - will be removed */ |
| 366 | ret = i2c_write(chip_addr, offset_addr[i], 1, &data[i], 1); |
| 367 | #endif |
| 368 | if (ret) { |
| 369 | printf("i2c write error to chip : %u, addr : %u, data : %u\n", |
| 370 | chip_addr, offset_addr[i], data[i]); |
| 371 | goto err; |
| 372 | } |
Jagdish Gediya | f9cb31e | 2018-04-13 00:18:22 +0530 | [diff] [blame] | 373 | } |
Biwen Li | 0a759bb | 2019-12-31 15:33:41 +0800 | [diff] [blame] | 374 | |
Jagdish Gediya | f9cb31e | 2018-04-13 00:18:22 +0530 | [diff] [blame] | 375 | err: |
| 376 | return ret; |
| 377 | } |
| 378 | |
| 379 | static int convert_flash_bank(int bank) |
| 380 | { |
| 381 | int ret = 0; |
| 382 | |
| 383 | switch (bank) { |
| 384 | case BOOT_FROM_UPPER_BANK: |
| 385 | ret = switch_to_bank2(); |
| 386 | break; |
| 387 | case BOOT_FROM_LOWER_BANK: |
| 388 | ret = switch_to_bank1(); |
| 389 | break; |
| 390 | default: |
| 391 | ret = CMD_RET_USAGE; |
| 392 | break; |
| 393 | }; |
| 394 | |
| 395 | return ret; |
| 396 | } |
| 397 | |
Simon Glass | ed38aef | 2020-05-10 11:40:03 -0600 | [diff] [blame] | 398 | static int flash_bank_cmd(struct cmd_tbl *cmdtp, int flag, int argc, |
| 399 | char *const argv[]) |
Jagdish Gediya | f9cb31e | 2018-04-13 00:18:22 +0530 | [diff] [blame] | 400 | { |
| 401 | if (argc != 2) |
| 402 | return CMD_RET_USAGE; |
| 403 | if (strcmp(argv[1], "1") == 0) |
| 404 | convert_flash_bank(BOOT_FROM_LOWER_BANK); |
| 405 | else if (strcmp(argv[1], "2") == 0) |
| 406 | convert_flash_bank(BOOT_FROM_UPPER_BANK); |
| 407 | else |
| 408 | return CMD_RET_USAGE; |
| 409 | |
| 410 | return 0; |
| 411 | } |
| 412 | |
| 413 | U_BOOT_CMD( |
| 414 | boot_bank, 2, 0, flash_bank_cmd, |
| 415 | "Flash bank Selection Control", |
| 416 | "bank[1-lower bank/2-upper bank] (e.g. boot_bank 1)" |
| 417 | ); |