1 /* 2 * Copyright 2014 Freescale Semiconductor, Inc. 3 * 4 * SPDX-License-Identifier: GPL-2.0+ 5 */ 6 7 #include <common.h> 8 #include <command.h> 9 #include <i2c.h> 10 #include <netdev.h> 11 #include <linux/compiler.h> 12 #include <asm/mmu.h> 13 #include <asm/processor.h> 14 #include <asm/cache.h> 15 #include <asm/immap_85xx.h> 16 #include <asm/fsl_law.h> 17 #include <asm/fsl_serdes.h> 18 #include <asm/fsl_portals.h> 19 #include <asm/fsl_liodn.h> 20 #include <fm_eth.h> 21 #include <hwconfig.h> 22 #include <asm/mpc85xx_gpio.h> 23 #include "../common/qixis.h" 24 #include "t102xqds.h" 25 #include "t102xqds_qixis.h" 26 27 DECLARE_GLOBAL_DATA_PTR; 28 29 int checkboard(void) 30 { 31 char buf[64]; 32 struct cpu_type *cpu = gd->arch.cpu; 33 static const char *const freq[] = {"100", "125", "156.25", "100.0"}; 34 int clock; 35 u8 sw = QIXIS_READ(arch); 36 37 printf("Board: %sQDS, ", cpu->name); 38 printf("Sys ID: 0x%02x, Board Arch: V%d, ", QIXIS_READ(id), sw >> 4); 39 printf("Board Version: %c, boot from ", (sw & 0xf) + 'A' - 1); 40 41 #ifdef CONFIG_SDCARD 42 puts("SD/MMC\n"); 43 #elif CONFIG_SPIFLASH 44 puts("SPI\n"); 45 #else 46 sw = QIXIS_READ(brdcfg[0]); 47 sw = (sw & QIXIS_LBMAP_MASK) >> QIXIS_LBMAP_SHIFT; 48 49 if (sw < 0x8) 50 printf("vBank: %d\n", sw); 51 else if (sw == 0x8) 52 puts("PromJet\n"); 53 else if (sw == 0x9) 54 puts("NAND\n"); 55 else if (sw == 0x15) 56 printf("IFC Card\n"); 57 else 58 printf("invalid setting of SW%u\n", QIXIS_LBMAP_SWITCH); 59 #endif 60 61 printf("FPGA: v%d (%s), build %d", 62 (int)QIXIS_READ(scver), qixis_read_tag(buf), 63 (int)qixis_read_minor()); 64 /* the timestamp string contains "\n" at the end */ 65 printf(" on %s", qixis_read_time(buf)); 66 67 puts("SERDES Reference: "); 68 sw = QIXIS_READ(brdcfg[2]); 69 clock = (sw >> 6) & 3; 70 printf("Clock1=%sMHz ", freq[clock]); 71 clock = (sw >> 4) & 3; 72 printf("Clock2=%sMHz\n", freq[clock]); 73 74 return 0; 75 } 76 77 int select_i2c_ch_pca9547(u8 ch) 78 { 79 int ret; 80 81 ret = i2c_write(I2C_MUX_PCA_ADDR_PRI, 0, 1, &ch, 1); 82 if (ret) { 83 puts("PCA: failed to select proper channel\n"); 84 return ret; 85 } 86 87 return 0; 88 } 89 90 static int board_mux_lane_to_slot(void) 91 { 92 ccsr_gur_t __iomem *gur = (void *)(CONFIG_SYS_MPC85xx_GUTS_ADDR); 93 u32 srds_prtcl_s1; 94 u8 brdcfg9; 95 96 srds_prtcl_s1 = in_be32(&gur->rcwsr[4]) & 97 FSL_CORENET2_RCWSR4_SRDS1_PRTCL; 98 srds_prtcl_s1 >>= FSL_CORENET2_RCWSR4_SRDS1_PRTCL_SHIFT; 99 100 101 brdcfg9 = QIXIS_READ(brdcfg[9]); 102 QIXIS_WRITE(brdcfg[9], brdcfg9 | BRDCFG9_XFI_TX_DISABLE); 103 104 switch (srds_prtcl_s1) { 105 case 0: 106 /* SerDes1 is not enabled */ 107 break; 108 case 0xd5: 109 case 0x5b: 110 case 0x6b: 111 case 0x77: 112 case 0x6f: 113 case 0x7f: 114 QIXIS_WRITE(brdcfg[12], 0x8c); 115 break; 116 case 0x40: 117 QIXIS_WRITE(brdcfg[12], 0xfc); 118 break; 119 case 0xd6: 120 case 0x5a: 121 case 0x6a: 122 case 0x56: 123 QIXIS_WRITE(brdcfg[12], 0x88); 124 break; 125 case 0x47: 126 QIXIS_WRITE(brdcfg[12], 0xcc); 127 break; 128 case 0x46: 129 QIXIS_WRITE(brdcfg[12], 0xc8); 130 break; 131 case 0x95: 132 case 0x99: 133 brdcfg9 &= ~BRDCFG9_XFI_TX_DISABLE; 134 QIXIS_WRITE(brdcfg[9], brdcfg9); 135 QIXIS_WRITE(brdcfg[12], 0x8c); 136 break; 137 case 0x116: 138 QIXIS_WRITE(brdcfg[12], 0x00); 139 break; 140 case 0x115: 141 case 0x119: 142 case 0x129: 143 case 0x12b: 144 /* Aurora, PCIe, SGMII, SATA */ 145 QIXIS_WRITE(brdcfg[12], 0x04); 146 break; 147 default: 148 printf("WARNING: unsupported for SerDes Protocol %d\n", 149 srds_prtcl_s1); 150 return -1; 151 } 152 153 return 0; 154 } 155 156 #ifdef CONFIG_PPC_T1024 157 static void board_mux_setup(void) 158 { 159 u8 brdcfg15; 160 161 brdcfg15 = QIXIS_READ(brdcfg[15]); 162 brdcfg15 &= ~BRDCFG15_DIUSEL_MASK; 163 164 if (hwconfig_arg_cmp("pin_mux", "tdm")) { 165 /* Route QE_TDM multiplexed signals to TDM Riser slot */ 166 QIXIS_WRITE(brdcfg[15], brdcfg15 | BRDCFG15_DIUSEL_TDM); 167 QIXIS_WRITE(brdcfg[13], BRDCFG13_TDM_INTERFACE << 2); 168 } else if (hwconfig_arg_cmp("pin_mux", "ucc")) { 169 /* to UCC (ProfiBus) interface */ 170 QIXIS_WRITE(brdcfg[15], brdcfg15 | BRDCFG15_DIUSEL_UCC); 171 } else if (hwconfig_arg_cmp("pin_mux", "hdmi")) { 172 /* to DVI (HDMI) encoder */ 173 QIXIS_WRITE(brdcfg[15], brdcfg15 | BRDCFG15_DIUSEL_HDMI); 174 } else if (hwconfig_arg_cmp("pin_mux", "lcd")) { 175 /* to DFP (LCD) encoder */ 176 QIXIS_WRITE(brdcfg[15], brdcfg15 | BRDCFG15_LCDFM | 177 BRDCFG15_LCDPD | BRDCFG15_DIUSEL_LCD); 178 } 179 } 180 #endif 181 182 int board_early_init_r(void) 183 { 184 #ifdef CONFIG_SYS_FLASH_BASE 185 const unsigned int flashbase = CONFIG_SYS_FLASH_BASE; 186 int flash_esel = find_tlb_idx((void *)flashbase, 1); 187 188 /* 189 * Remap Boot flash + PROMJET region to caching-inhibited 190 * so that flash can be erased properly. 191 */ 192 193 /* Flush d-cache and invalidate i-cache of any FLASH data */ 194 flush_dcache(); 195 invalidate_icache(); 196 197 if (flash_esel == -1) { 198 /* very unlikely unless something is messed up */ 199 puts("Error: Could not find TLB for FLASH BASE\n"); 200 flash_esel = 2; /* give our best effort to continue */ 201 } else { 202 /* invalidate existing TLB entry for flash + promjet */ 203 disable_tlb(flash_esel); 204 } 205 206 set_tlb(1, flashbase, CONFIG_SYS_FLASH_BASE_PHYS, 207 MAS3_SX|MAS3_SW|MAS3_SR, MAS2_I|MAS2_G, 208 0, flash_esel, BOOKE_PAGESZ_256M, 1); 209 #endif 210 set_liodns(); 211 #ifdef CONFIG_SYS_DPAA_QBMAN 212 setup_portals(); 213 #endif 214 select_i2c_ch_pca9547(I2C_MUX_CH_DEFAULT); 215 board_mux_lane_to_slot(); 216 return 0; 217 } 218 219 unsigned long get_board_sys_clk(void) 220 { 221 u8 sysclk_conf = QIXIS_READ(brdcfg[1]); 222 223 switch (sysclk_conf & 0x0F) { 224 case QIXIS_SYSCLK_64: 225 return 64000000; 226 case QIXIS_SYSCLK_83: 227 return 83333333; 228 case QIXIS_SYSCLK_100: 229 return 100000000; 230 case QIXIS_SYSCLK_125: 231 return 125000000; 232 case QIXIS_SYSCLK_133: 233 return 133333333; 234 case QIXIS_SYSCLK_150: 235 return 150000000; 236 case QIXIS_SYSCLK_160: 237 return 160000000; 238 case QIXIS_SYSCLK_166: 239 return 166666666; 240 } 241 return 66666666; 242 } 243 244 unsigned long get_board_ddr_clk(void) 245 { 246 u8 ddrclk_conf = QIXIS_READ(brdcfg[1]); 247 248 switch ((ddrclk_conf & 0x30) >> 4) { 249 case QIXIS_DDRCLK_100: 250 return 100000000; 251 case QIXIS_DDRCLK_125: 252 return 125000000; 253 case QIXIS_DDRCLK_133: 254 return 133333333; 255 } 256 return 66666666; 257 } 258 259 #define NUM_SRDS_PLL 2 260 int misc_init_r(void) 261 { 262 #ifdef CONFIG_PPC_T1024 263 board_mux_setup(); 264 #endif 265 return 0; 266 } 267 268 int ft_board_setup(void *blob, bd_t *bd) 269 { 270 phys_addr_t base; 271 phys_size_t size; 272 273 ft_cpu_setup(blob, bd); 274 275 base = getenv_bootm_low(); 276 size = getenv_bootm_size(); 277 278 fdt_fixup_memory(blob, (u64)base, (u64)size); 279 280 #ifdef CONFIG_PCI 281 pci_of_setup(blob, bd); 282 #endif 283 284 fdt_fixup_liodn(blob); 285 286 #ifdef CONFIG_HAS_FSL_DR_USB 287 fdt_fixup_dr_usb(blob, bd); 288 #endif 289 290 #ifdef CONFIG_SYS_DPAA_FMAN 291 fdt_fixup_fman_ethernet(blob); 292 fdt_fixup_board_enet(blob); 293 #endif 294 295 return 0; 296 } 297 298 void qixis_dump_switch(void) 299 { 300 int i, nr_of_cfgsw; 301 302 QIXIS_WRITE(cms[0], 0x00); 303 nr_of_cfgsw = QIXIS_READ(cms[1]); 304 305 puts("DIP switch settings dump:\n"); 306 for (i = 1; i <= nr_of_cfgsw; i++) { 307 QIXIS_WRITE(cms[0], i); 308 printf("SW%d = (0x%02x)\n", i, QIXIS_READ(cms[1])); 309 } 310 } 311 312 #ifdef CONFIG_DEEP_SLEEP 313 void board_mem_sleep_setup(void) 314 { 315 /* does not provide HW signals for power management */ 316 QIXIS_WRITE(pwr_ctl[1], (QIXIS_READ(pwr_ctl[1]) & ~0x2)); 317 /* Disable MCKE isolation */ 318 gpio_set_value(2, 0); 319 udelay(1); 320 } 321 #endif 322