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