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