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