Tom Rini | 83d290c | 2018-05-06 17:58:06 -0400 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0+ |
Shengzhou Liu | 48c6f32 | 2014-11-24 17:11:56 +0800 | [diff] [blame] | 2 | /* |
| 3 | * Copyright 2014 Freescale Semiconductor, Inc. |
Biwen Li | 9e9771a | 2020-05-01 20:04:11 +0800 | [diff] [blame] | 4 | * Copyright 2020 NXP |
Shengzhou Liu | 48c6f32 | 2014-11-24 17:11:56 +0800 | [diff] [blame] | 5 | */ |
| 6 | |
| 7 | #include <common.h> |
| 8 | #include <command.h> |
Simon Glass | 7b51b57 | 2019-08-01 09:46:52 -0600 | [diff] [blame] | 9 | #include <env.h> |
Simon Glass | 807765b | 2019-12-28 10:44:54 -0700 | [diff] [blame] | 10 | #include <fdt_support.h> |
Shengzhou Liu | 48c6f32 | 2014-11-24 17:11:56 +0800 | [diff] [blame] | 11 | #include <i2c.h> |
Simon Glass | 4d72caa | 2020-05-10 11:40:01 -0600 | [diff] [blame] | 12 | #include <image.h> |
Simon Glass | 5255932 | 2019-11-14 12:57:46 -0700 | [diff] [blame] | 13 | #include <init.h> |
Shengzhou Liu | 48c6f32 | 2014-11-24 17:11:56 +0800 | [diff] [blame] | 14 | #include <netdev.h> |
Simon Glass | 401d1c4 | 2020-10-30 21:38:53 -0600 | [diff] [blame] | 15 | #include <asm/global_data.h> |
Shengzhou Liu | 48c6f32 | 2014-11-24 17:11:56 +0800 | [diff] [blame] | 16 | #include <linux/compiler.h> |
| 17 | #include <asm/mmu.h> |
| 18 | #include <asm/processor.h> |
| 19 | #include <asm/immap_85xx.h> |
| 20 | #include <asm/fsl_law.h> |
| 21 | #include <asm/fsl_serdes.h> |
Shengzhou Liu | 48c6f32 | 2014-11-24 17:11:56 +0800 | [diff] [blame] | 22 | #include <asm/fsl_liodn.h> |
Shengzhou Liu | 48c6f32 | 2014-11-24 17:11:56 +0800 | [diff] [blame] | 23 | #include <fm_eth.h> |
| 24 | #include "t102xrdb.h" |
York Sun | 960286b | 2016-12-28 08:43:34 -0800 | [diff] [blame] | 25 | #ifdef CONFIG_TARGET_T1024RDB |
Shengzhou Liu | 48c6f32 | 2014-11-24 17:11:56 +0800 | [diff] [blame] | 26 | #include "cpld.h" |
York Sun | 9082405 | 2016-12-28 08:43:33 -0800 | [diff] [blame] | 27 | #elif defined(CONFIG_TARGET_T1023RDB) |
Shengzhou Liu | ff7ea2d | 2015-06-17 16:37:01 +0800 | [diff] [blame] | 28 | #include <i2c.h> |
| 29 | #include <mmc.h> |
Shengzhou Liu | e8a7f1c | 2015-03-27 15:48:34 +0800 | [diff] [blame] | 30 | #endif |
tang yuantian | f49b8c1 | 2014-12-17 15:42:54 +0800 | [diff] [blame] | 31 | #include "../common/sleep.h" |
Shengzhou Liu | 48c6f32 | 2014-11-24 17:11:56 +0800 | [diff] [blame] | 32 | |
| 33 | DECLARE_GLOBAL_DATA_PTR; |
| 34 | |
York Sun | 9082405 | 2016-12-28 08:43:33 -0800 | [diff] [blame] | 35 | #ifdef CONFIG_TARGET_T1023RDB |
Shengzhou Liu | e8a7f1c | 2015-03-27 15:48:34 +0800 | [diff] [blame] | 36 | enum { |
Shengzhou Liu | ff7ea2d | 2015-06-17 16:37:01 +0800 | [diff] [blame] | 37 | GPIO1_SD_SEL = 0x00020000, /* GPIO1_14, 0: eMMC, 1:SD/MMC */ |
Shengzhou Liu | e8a7f1c | 2015-03-27 15:48:34 +0800 | [diff] [blame] | 38 | GPIO1_EMMC_SEL, |
Shengzhou Liu | ff7ea2d | 2015-06-17 16:37:01 +0800 | [diff] [blame] | 39 | GPIO3_GET_VERSION, /* GPIO3_4/5, 00:RevB, 01: RevC */ |
| 40 | GPIO3_BRD_VER_MASK = 0x0c000000, |
| 41 | GPIO3_OFFSET = 0x2000, |
| 42 | I2C_GET_BANK, |
| 43 | I2C_SET_BANK0, |
| 44 | I2C_SET_BANK4, |
Shengzhou Liu | e8a7f1c | 2015-03-27 15:48:34 +0800 | [diff] [blame] | 45 | }; |
| 46 | #endif |
| 47 | |
Shengzhou Liu | 48c6f32 | 2014-11-24 17:11:56 +0800 | [diff] [blame] | 48 | int checkboard(void) |
| 49 | { |
| 50 | struct cpu_type *cpu = gd->arch.cpu; |
| 51 | static const char *freq[3] = {"100.00MHZ", "125.00MHz", "156.25MHZ"}; |
Shengzhou Liu | e26416a | 2014-12-17 16:51:08 +0800 | [diff] [blame] | 52 | ccsr_gur_t __iomem *gur = (void *)(CONFIG_SYS_MPC85xx_GUTS_ADDR); |
| 53 | u32 srds_s1; |
| 54 | |
| 55 | srds_s1 = in_be32(&gur->rcwsr[4]) & FSL_CORENET2_RCWSR4_SRDS1_PRTCL; |
| 56 | srds_s1 >>= FSL_CORENET2_RCWSR4_SRDS1_PRTCL_SHIFT; |
Shengzhou Liu | 48c6f32 | 2014-11-24 17:11:56 +0800 | [diff] [blame] | 57 | |
| 58 | printf("Board: %sRDB, ", cpu->name); |
York Sun | 960286b | 2016-12-28 08:43:34 -0800 | [diff] [blame] | 59 | #if defined(CONFIG_TARGET_T1024RDB) |
Shengzhou Liu | e8a7f1c | 2015-03-27 15:48:34 +0800 | [diff] [blame] | 60 | printf("Board rev: 0x%02x CPLD ver: 0x%02x, ", |
Shengzhou Liu | 48c6f32 | 2014-11-24 17:11:56 +0800 | [diff] [blame] | 61 | CPLD_READ(hw_ver), CPLD_READ(sw_ver)); |
York Sun | 9082405 | 2016-12-28 08:43:33 -0800 | [diff] [blame] | 62 | #elif defined(CONFIG_TARGET_T1023RDB) |
Shengzhou Liu | ff7ea2d | 2015-06-17 16:37:01 +0800 | [diff] [blame] | 63 | printf("Rev%c, ", t1023rdb_ctrl(GPIO3_GET_VERSION) + 'B'); |
Shengzhou Liu | e8a7f1c | 2015-03-27 15:48:34 +0800 | [diff] [blame] | 64 | #endif |
| 65 | printf("boot from "); |
Shengzhou Liu | 48c6f32 | 2014-11-24 17:11:56 +0800 | [diff] [blame] | 66 | |
| 67 | #ifdef CONFIG_SDCARD |
| 68 | puts("SD/MMC\n"); |
| 69 | #elif CONFIG_SPIFLASH |
| 70 | puts("SPI\n"); |
York Sun | 960286b | 2016-12-28 08:43:34 -0800 | [diff] [blame] | 71 | #elif defined(CONFIG_TARGET_T1024RDB) |
Shengzhou Liu | 48c6f32 | 2014-11-24 17:11:56 +0800 | [diff] [blame] | 72 | u8 reg; |
| 73 | |
| 74 | reg = CPLD_READ(flash_csr); |
| 75 | |
| 76 | if (reg & CPLD_BOOT_SEL) { |
| 77 | puts("NAND\n"); |
| 78 | } else { |
| 79 | reg = ((reg & CPLD_LBMAP_MASK) >> CPLD_LBMAP_SHIFT); |
| 80 | printf("NOR vBank%d\n", reg); |
| 81 | } |
York Sun | 9082405 | 2016-12-28 08:43:33 -0800 | [diff] [blame] | 82 | #elif defined(CONFIG_TARGET_T1023RDB) |
Miquel Raynal | 88718be | 2019-10-03 19:50:03 +0200 | [diff] [blame] | 83 | #ifdef CONFIG_MTD_RAW_NAND |
Shengzhou Liu | e8a7f1c | 2015-03-27 15:48:34 +0800 | [diff] [blame] | 84 | puts("NAND\n"); |
| 85 | #else |
Shengzhou Liu | ff7ea2d | 2015-06-17 16:37:01 +0800 | [diff] [blame] | 86 | printf("NOR vBank%d\n", t1023rdb_ctrl(I2C_GET_BANK)); |
Shengzhou Liu | e8a7f1c | 2015-03-27 15:48:34 +0800 | [diff] [blame] | 87 | #endif |
Shengzhou Liu | 48c6f32 | 2014-11-24 17:11:56 +0800 | [diff] [blame] | 88 | #endif |
| 89 | |
| 90 | puts("SERDES Reference Clocks:\n"); |
Shengzhou Liu | e26416a | 2014-12-17 16:51:08 +0800 | [diff] [blame] | 91 | if (srds_s1 == 0x95) |
| 92 | printf("SD1_CLK1=%s, SD1_CLK2=%s\n", freq[2], freq[0]); |
| 93 | else |
Shengzhou Liu | e8a7f1c | 2015-03-27 15:48:34 +0800 | [diff] [blame] | 94 | printf("SD1_CLK1=%s, SD1_CLK2=%s\n", freq[0], freq[1]); |
Shengzhou Liu | 48c6f32 | 2014-11-24 17:11:56 +0800 | [diff] [blame] | 95 | |
| 96 | return 0; |
| 97 | } |
| 98 | |
York Sun | 960286b | 2016-12-28 08:43:34 -0800 | [diff] [blame] | 99 | #ifdef CONFIG_TARGET_T1024RDB |
Shengzhou Liu | e26416a | 2014-12-17 16:51:08 +0800 | [diff] [blame] | 100 | static void board_mux_lane(void) |
| 101 | { |
| 102 | ccsr_gur_t __iomem *gur = (void *)(CONFIG_SYS_MPC85xx_GUTS_ADDR); |
| 103 | u32 srds_prtcl_s1; |
| 104 | u8 reg = CPLD_READ(misc_ctl_status); |
| 105 | |
| 106 | srds_prtcl_s1 = in_be32(&gur->rcwsr[4]) & |
| 107 | FSL_CORENET2_RCWSR4_SRDS1_PRTCL; |
| 108 | srds_prtcl_s1 >>= FSL_CORENET2_RCWSR4_SRDS1_PRTCL_SHIFT; |
| 109 | |
| 110 | if (srds_prtcl_s1 == 0x95) { |
| 111 | /* Route Lane B to PCIE */ |
| 112 | CPLD_WRITE(misc_ctl_status, reg & ~CPLD_PCIE_SGMII_MUX); |
| 113 | } else { |
| 114 | /* Route Lane B to SGMII */ |
| 115 | CPLD_WRITE(misc_ctl_status, reg | CPLD_PCIE_SGMII_MUX); |
| 116 | } |
| 117 | CPLD_WRITE(boot_override, CPLD_OVERRIDE_MUX_EN); |
| 118 | } |
Shengzhou Liu | e8a7f1c | 2015-03-27 15:48:34 +0800 | [diff] [blame] | 119 | #endif |
Shengzhou Liu | e26416a | 2014-12-17 16:51:08 +0800 | [diff] [blame] | 120 | |
tang yuantian | f49b8c1 | 2014-12-17 15:42:54 +0800 | [diff] [blame] | 121 | int board_early_init_f(void) |
| 122 | { |
| 123 | #if defined(CONFIG_DEEP_SLEEP) |
| 124 | if (is_warm_boot()) |
| 125 | fsl_dp_disable_console(); |
| 126 | #endif |
| 127 | |
| 128 | return 0; |
| 129 | } |
| 130 | |
Shengzhou Liu | 48c6f32 | 2014-11-24 17:11:56 +0800 | [diff] [blame] | 131 | int board_early_init_r(void) |
| 132 | { |
| 133 | #ifdef CONFIG_SYS_FLASH_BASE |
| 134 | const unsigned int flashbase = CONFIG_SYS_FLASH_BASE; |
| 135 | int flash_esel = find_tlb_idx((void *)flashbase, 1); |
| 136 | /* |
| 137 | * Remap Boot flash region to caching-inhibited |
| 138 | * so that flash can be erased properly. |
| 139 | */ |
| 140 | |
| 141 | /* Flush d-cache and invalidate i-cache of any FLASH data */ |
| 142 | flush_dcache(); |
| 143 | invalidate_icache(); |
| 144 | if (flash_esel == -1) { |
| 145 | /* very unlikely unless something is messed up */ |
| 146 | puts("Error: Could not find TLB for FLASH BASE\n"); |
| 147 | flash_esel = 2; /* give our best effort to continue */ |
| 148 | } else { |
| 149 | /* invalidate existing TLB entry for flash + promjet */ |
| 150 | disable_tlb(flash_esel); |
| 151 | } |
| 152 | |
| 153 | set_tlb(1, flashbase, CONFIG_SYS_FLASH_BASE_PHYS, |
| 154 | MAS3_SX|MAS3_SW|MAS3_SR, MAS2_I|MAS2_G, |
| 155 | 0, flash_esel, BOOKE_PAGESZ_256M, 1); |
| 156 | #endif |
| 157 | |
York Sun | 960286b | 2016-12-28 08:43:34 -0800 | [diff] [blame] | 158 | #ifdef CONFIG_TARGET_T1024RDB |
Shengzhou Liu | e26416a | 2014-12-17 16:51:08 +0800 | [diff] [blame] | 159 | board_mux_lane(); |
Shengzhou Liu | e8a7f1c | 2015-03-27 15:48:34 +0800 | [diff] [blame] | 160 | #endif |
Shengzhou Liu | 48c6f32 | 2014-11-24 17:11:56 +0800 | [diff] [blame] | 161 | |
| 162 | return 0; |
| 163 | } |
| 164 | |
| 165 | unsigned long get_board_sys_clk(void) |
| 166 | { |
| 167 | return CONFIG_SYS_CLK_FREQ; |
| 168 | } |
| 169 | |
Shengzhou Liu | e0dfec8 | 2017-04-10 16:00:08 +0800 | [diff] [blame] | 170 | #ifdef CONFIG_TARGET_T1024RDB |
| 171 | void board_reset(void) |
| 172 | { |
| 173 | CPLD_WRITE(reset_ctl1, CPLD_LBMAP_RESET); |
| 174 | } |
| 175 | #endif |
| 176 | |
Shengzhou Liu | 48c6f32 | 2014-11-24 17:11:56 +0800 | [diff] [blame] | 177 | int misc_init_r(void) |
| 178 | { |
| 179 | return 0; |
| 180 | } |
| 181 | |
Masahiro Yamada | b75d8dc | 2020-06-26 15:13:33 +0900 | [diff] [blame] | 182 | int ft_board_setup(void *blob, struct bd_info *bd) |
Shengzhou Liu | 48c6f32 | 2014-11-24 17:11:56 +0800 | [diff] [blame] | 183 | { |
| 184 | phys_addr_t base; |
| 185 | phys_size_t size; |
| 186 | |
| 187 | ft_cpu_setup(blob, bd); |
| 188 | |
Simon Glass | 723806c | 2017-08-03 12:22:15 -0600 | [diff] [blame] | 189 | base = env_get_bootm_low(); |
| 190 | size = env_get_bootm_size(); |
Shengzhou Liu | 48c6f32 | 2014-11-24 17:11:56 +0800 | [diff] [blame] | 191 | |
| 192 | fdt_fixup_memory(blob, (u64)base, (u64)size); |
| 193 | |
| 194 | #ifdef CONFIG_PCI |
| 195 | pci_of_setup(blob, bd); |
| 196 | #endif |
| 197 | |
| 198 | fdt_fixup_liodn(blob); |
Sriram Dash | a5c289b | 2016-09-16 17:12:15 +0530 | [diff] [blame] | 199 | fsl_fdt_fixup_dr_usb(blob, bd); |
Shengzhou Liu | 48c6f32 | 2014-11-24 17:11:56 +0800 | [diff] [blame] | 200 | |
| 201 | #ifdef CONFIG_SYS_DPAA_FMAN |
Madalin Bucur | 564637a | 2020-04-30 15:59:58 +0300 | [diff] [blame] | 202 | #ifndef CONFIG_DM_ETH |
Shengzhou Liu | 48c6f32 | 2014-11-24 17:11:56 +0800 | [diff] [blame] | 203 | fdt_fixup_fman_ethernet(blob); |
Madalin Bucur | 564637a | 2020-04-30 15:59:58 +0300 | [diff] [blame] | 204 | #endif |
Shengzhou Liu | 48c6f32 | 2014-11-24 17:11:56 +0800 | [diff] [blame] | 205 | fdt_fixup_board_enet(blob); |
| 206 | #endif |
| 207 | |
York Sun | 9082405 | 2016-12-28 08:43:33 -0800 | [diff] [blame] | 208 | #ifdef CONFIG_TARGET_T1023RDB |
Shengzhou Liu | ff7ea2d | 2015-06-17 16:37:01 +0800 | [diff] [blame] | 209 | if (t1023rdb_ctrl(GPIO3_GET_VERSION) > 0) |
| 210 | fdt_enable_nor(blob); |
| 211 | #endif |
| 212 | |
Shengzhou Liu | 48c6f32 | 2014-11-24 17:11:56 +0800 | [diff] [blame] | 213 | return 0; |
| 214 | } |
Shengzhou Liu | e8a7f1c | 2015-03-27 15:48:34 +0800 | [diff] [blame] | 215 | |
York Sun | 9082405 | 2016-12-28 08:43:33 -0800 | [diff] [blame] | 216 | #ifdef CONFIG_TARGET_T1023RDB |
Shengzhou Liu | ff7ea2d | 2015-06-17 16:37:01 +0800 | [diff] [blame] | 217 | /* Enable NOR flash for RevC */ |
| 218 | static void fdt_enable_nor(void *blob) |
Shengzhou Liu | e8a7f1c | 2015-03-27 15:48:34 +0800 | [diff] [blame] | 219 | { |
Shengzhou Liu | ff7ea2d | 2015-06-17 16:37:01 +0800 | [diff] [blame] | 220 | int nodeoff = fdt_node_offset_by_compatible(blob, 0, "cfi-flash"); |
Shengzhou Liu | e8a7f1c | 2015-03-27 15:48:34 +0800 | [diff] [blame] | 221 | |
Shengzhou Liu | ff7ea2d | 2015-06-17 16:37:01 +0800 | [diff] [blame] | 222 | if (nodeoff >= 0) |
| 223 | fdt_status_okay(blob, nodeoff); |
| 224 | else |
| 225 | printf("WARNING unable to set status for NOR\n"); |
| 226 | } |
| 227 | |
| 228 | int board_mmc_getcd(struct mmc *mmc) |
| 229 | { |
| 230 | ccsr_gpio_t __iomem *pgpio = (void *)(CONFIG_SYS_MPC85xx_GPIO_ADDR); |
| 231 | u32 val = in_be32(&pgpio->gpdat); |
| 232 | |
| 233 | /* GPIO1_14, 0: eMMC, 1: SD/MMC */ |
| 234 | val &= GPIO1_SD_SEL; |
| 235 | |
| 236 | return val ? -1 : 1; |
| 237 | } |
| 238 | |
| 239 | int board_mmc_getwp(struct mmc *mmc) |
| 240 | { |
| 241 | ccsr_gpio_t __iomem *pgpio = (void *)(CONFIG_SYS_MPC85xx_GPIO_ADDR); |
| 242 | u32 val = in_be32(&pgpio->gpdat); |
| 243 | |
| 244 | val &= GPIO1_SD_SEL; |
| 245 | |
| 246 | return val ? -1 : 0; |
| 247 | } |
| 248 | |
| 249 | static u32 t1023rdb_ctrl(u32 ctrl_type) |
| 250 | { |
| 251 | ccsr_gpio_t __iomem *pgpio = (void *)(CONFIG_SYS_MPC85xx_GPIO_ADDR); |
| 252 | ccsr_gur_t __iomem *gur = (void *)(CONFIG_SYS_MPC85xx_GUTS_ADDR); |
Biwen Li | 9e9771a | 2020-05-01 20:04:11 +0800 | [diff] [blame] | 253 | u32 val; |
Shengzhou Liu | ff7ea2d | 2015-06-17 16:37:01 +0800 | [diff] [blame] | 254 | u8 tmp; |
Biwen Li | 9e9771a | 2020-05-01 20:04:11 +0800 | [diff] [blame] | 255 | int bus_num = I2C_PCA6408_BUS_NUM; |
| 256 | |
Igor Opaniuk | 2147a16 | 2021-02-09 13:52:45 +0200 | [diff] [blame] | 257 | #if CONFIG_IS_ENABLED(DM_I2C) |
Biwen Li | 9e9771a | 2020-05-01 20:04:11 +0800 | [diff] [blame] | 258 | struct udevice *dev; |
| 259 | int ret; |
| 260 | |
| 261 | ret = i2c_get_chip_for_busnum(bus_num, I2C_PCA6408_ADDR, |
| 262 | 1, &dev); |
| 263 | if (ret) { |
| 264 | printf("%s: Cannot find udev for a bus %d\n", __func__, |
| 265 | bus_num); |
| 266 | return ret; |
| 267 | } |
| 268 | switch (ctrl_type) { |
| 269 | case GPIO1_SD_SEL: |
| 270 | val = in_be32(&pgpio->gpdat); |
| 271 | val |= GPIO1_SD_SEL; |
| 272 | out_be32(&pgpio->gpdat, val); |
| 273 | setbits_be32(&pgpio->gpdir, GPIO1_SD_SEL); |
| 274 | break; |
| 275 | case GPIO1_EMMC_SEL: |
| 276 | val = in_be32(&pgpio->gpdat); |
| 277 | val &= ~GPIO1_SD_SEL; |
| 278 | out_be32(&pgpio->gpdat, val); |
| 279 | setbits_be32(&pgpio->gpdir, GPIO1_SD_SEL); |
| 280 | break; |
| 281 | case GPIO3_GET_VERSION: |
| 282 | pgpio = (ccsr_gpio_t *)(CONFIG_SYS_MPC85xx_GPIO_ADDR |
| 283 | + GPIO3_OFFSET); |
| 284 | val = in_be32(&pgpio->gpdat); |
| 285 | val = ((val & GPIO3_BRD_VER_MASK) >> 26) & 0x3; |
| 286 | if (val == 0x3) /* GPIO3_4/5 not used on RevB */ |
| 287 | val = 0; |
| 288 | return val; |
| 289 | case I2C_GET_BANK: |
| 290 | dm_i2c_read(dev, 0, &tmp, 1); |
| 291 | tmp &= 0x7; |
| 292 | tmp = ((tmp & 1) << 2) | (tmp & 2) | ((tmp & 4) >> 2); |
| 293 | return tmp; |
| 294 | case I2C_SET_BANK0: |
| 295 | tmp = 0x0; |
| 296 | dm_i2c_write(dev, 1, &tmp, 1); |
| 297 | tmp = 0xf8; |
| 298 | dm_i2c_write(dev, 3, &tmp, 1); |
| 299 | /* asserting HRESET_REQ */ |
| 300 | out_be32(&gur->rstcr, 0x2); |
| 301 | break; |
| 302 | case I2C_SET_BANK4: |
| 303 | tmp = 0x1; |
| 304 | dm_i2c_write(dev, 1, &tmp, 1); |
| 305 | tmp = 0xf8; |
| 306 | dm_i2c_write(dev, 3, &tmp, 1); |
| 307 | out_be32(&gur->rstcr, 0x2); |
| 308 | break; |
| 309 | default: |
| 310 | break; |
| 311 | } |
| 312 | #else |
| 313 | u32 orig_bus; |
| 314 | |
| 315 | orig_bus = i2c_get_bus_num(); |
Shengzhou Liu | e8a7f1c | 2015-03-27 15:48:34 +0800 | [diff] [blame] | 316 | |
| 317 | switch (ctrl_type) { |
| 318 | case GPIO1_SD_SEL: |
Shengzhou Liu | ff7ea2d | 2015-06-17 16:37:01 +0800 | [diff] [blame] | 319 | val = in_be32(&pgpio->gpdat); |
| 320 | val |= GPIO1_SD_SEL; |
| 321 | out_be32(&pgpio->gpdat, val); |
| 322 | setbits_be32(&pgpio->gpdir, GPIO1_SD_SEL); |
Shengzhou Liu | e8a7f1c | 2015-03-27 15:48:34 +0800 | [diff] [blame] | 323 | break; |
| 324 | case GPIO1_EMMC_SEL: |
Shengzhou Liu | ff7ea2d | 2015-06-17 16:37:01 +0800 | [diff] [blame] | 325 | val = in_be32(&pgpio->gpdat); |
| 326 | val &= ~GPIO1_SD_SEL; |
| 327 | out_be32(&pgpio->gpdat, val); |
| 328 | setbits_be32(&pgpio->gpdir, GPIO1_SD_SEL); |
Shengzhou Liu | e8a7f1c | 2015-03-27 15:48:34 +0800 | [diff] [blame] | 329 | break; |
Shengzhou Liu | ff7ea2d | 2015-06-17 16:37:01 +0800 | [diff] [blame] | 330 | case GPIO3_GET_VERSION: |
| 331 | pgpio = (ccsr_gpio_t *)(CONFIG_SYS_MPC85xx_GPIO_ADDR |
| 332 | + GPIO3_OFFSET); |
| 333 | val = in_be32(&pgpio->gpdat); |
| 334 | val = ((val & GPIO3_BRD_VER_MASK) >> 26) & 0x3; |
| 335 | if (val == 0x3) /* GPIO3_4/5 not used on RevB */ |
| 336 | val = 0; |
| 337 | return val; |
| 338 | case I2C_GET_BANK: |
Biwen Li | 9e9771a | 2020-05-01 20:04:11 +0800 | [diff] [blame] | 339 | i2c_set_bus_num(bus_num); |
Shengzhou Liu | ff7ea2d | 2015-06-17 16:37:01 +0800 | [diff] [blame] | 340 | i2c_read(I2C_PCA6408_ADDR, 0, 1, &tmp, 1); |
| 341 | tmp &= 0x7; |
| 342 | tmp = ((tmp & 1) << 2) | (tmp & 2) | ((tmp & 4) >> 2); |
| 343 | i2c_set_bus_num(orig_bus); |
| 344 | return tmp; |
| 345 | case I2C_SET_BANK0: |
Biwen Li | 9e9771a | 2020-05-01 20:04:11 +0800 | [diff] [blame] | 346 | i2c_set_bus_num(bus_num); |
Shengzhou Liu | ff7ea2d | 2015-06-17 16:37:01 +0800 | [diff] [blame] | 347 | tmp = 0x0; |
| 348 | i2c_write(I2C_PCA6408_ADDR, 1, 1, &tmp, 1); |
| 349 | tmp = 0xf8; |
| 350 | i2c_write(I2C_PCA6408_ADDR, 3, 1, &tmp, 1); |
| 351 | /* asserting HRESET_REQ */ |
| 352 | out_be32(&gur->rstcr, 0x2); |
Shengzhou Liu | e8a7f1c | 2015-03-27 15:48:34 +0800 | [diff] [blame] | 353 | break; |
Shengzhou Liu | ff7ea2d | 2015-06-17 16:37:01 +0800 | [diff] [blame] | 354 | case I2C_SET_BANK4: |
Biwen Li | 9e9771a | 2020-05-01 20:04:11 +0800 | [diff] [blame] | 355 | i2c_set_bus_num(bus_num); |
Shengzhou Liu | ff7ea2d | 2015-06-17 16:37:01 +0800 | [diff] [blame] | 356 | tmp = 0x1; |
| 357 | i2c_write(I2C_PCA6408_ADDR, 1, 1, &tmp, 1); |
| 358 | tmp = 0xf8; |
| 359 | i2c_write(I2C_PCA6408_ADDR, 3, 1, &tmp, 1); |
| 360 | out_be32(&gur->rstcr, 0x2); |
Shengzhou Liu | e8a7f1c | 2015-03-27 15:48:34 +0800 | [diff] [blame] | 361 | break; |
Shengzhou Liu | e8a7f1c | 2015-03-27 15:48:34 +0800 | [diff] [blame] | 362 | default: |
| 363 | break; |
| 364 | } |
Biwen Li | 9e9771a | 2020-05-01 20:04:11 +0800 | [diff] [blame] | 365 | #endif |
Shengzhou Liu | e8a7f1c | 2015-03-27 15:48:34 +0800 | [diff] [blame] | 366 | return 0; |
| 367 | } |
| 368 | |
Simon Glass | 0914011 | 2020-05-10 11:40:03 -0600 | [diff] [blame] | 369 | static int switch_cmd(struct cmd_tbl *cmdtp, int flag, int argc, |
| 370 | char *const argv[]) |
Shengzhou Liu | e8a7f1c | 2015-03-27 15:48:34 +0800 | [diff] [blame] | 371 | { |
| 372 | if (argc < 2) |
| 373 | return CMD_RET_USAGE; |
Shengzhou Liu | ff7ea2d | 2015-06-17 16:37:01 +0800 | [diff] [blame] | 374 | if (!strcmp(argv[1], "bank0")) |
| 375 | t1023rdb_ctrl(I2C_SET_BANK0); |
| 376 | else if (!strcmp(argv[1], "bank4") || !strcmp(argv[1], "altbank")) |
| 377 | t1023rdb_ctrl(I2C_SET_BANK4); |
Shengzhou Liu | e8a7f1c | 2015-03-27 15:48:34 +0800 | [diff] [blame] | 378 | else if (!strcmp(argv[1], "sd")) |
Shengzhou Liu | ff7ea2d | 2015-06-17 16:37:01 +0800 | [diff] [blame] | 379 | t1023rdb_ctrl(GPIO1_SD_SEL); |
| 380 | else if (!strcmp(argv[1], "emmc")) |
| 381 | t1023rdb_ctrl(GPIO1_EMMC_SEL); |
Shengzhou Liu | e8a7f1c | 2015-03-27 15:48:34 +0800 | [diff] [blame] | 382 | else |
| 383 | return CMD_RET_USAGE; |
| 384 | return 0; |
| 385 | } |
| 386 | |
| 387 | U_BOOT_CMD( |
Shengzhou Liu | ff7ea2d | 2015-06-17 16:37:01 +0800 | [diff] [blame] | 388 | switch, 2, 0, switch_cmd, |
| 389 | "for bank0/bank4/sd/emmc switch control in runtime", |
| 390 | "command (e.g. switch bank4)" |
Shengzhou Liu | e8a7f1c | 2015-03-27 15:48:34 +0800 | [diff] [blame] | 391 | ); |
| 392 | #endif |