1 // SPDX-License-Identifier: GPL-2.0+
3 * Copyright 2010-2011 Freescale Semiconductor, Inc.
12 #include <asm/processor.h>
14 #include <asm/cache.h>
15 #include <asm/immap_85xx.h>
19 #include <linux/libfdt.h>
20 #include <fdt_support.h>
26 #include <asm/fsl_serdes.h>
28 #include <asm/fsl_pci.h>
32 DECLARE_GLOBAL_DATA_PTR;
34 #define GPIO4_PCIE_RESET_SET 0x08000000
35 #define MUX_CPLD_CAN_UART 0x00
36 #define MUX_CPLD_TDM 0x01
37 #define MUX_CPLD_SPICS0_FLASH 0x00
38 #define MUX_CPLD_SPICS0_SLIC 0x02
39 #define PMUXCR1_IFC_MASK 0x00ffff00
40 #define PMUXCR1_SDHC_MASK 0x00fff000
41 #define PMUXCR1_SDHC_ENABLE 0x00555000
58 static uint sd_ifc_mux;
61 u8 cpld_ver; /* cpld revision */
62 #if defined(CONFIG_TARGET_P1010RDB_PA)
63 u8 pcba_ver; /* pcb revision number */
66 u8 bank_sel; /* NOR Flash bank */
72 u8 spi_cs0_sel; /* SPI CS0 SLIC/SPI Flash */
73 u8 por0; /* POR Options */
74 u8 por1; /* POR Options */
75 u8 por2; /* POR Options */
76 u8 por3; /* POR Options */
77 #elif defined(CONFIG_TARGET_P1010RDB_PB)
82 int board_early_init_f(void)
84 ccsr_gpio_t *pgpio = (void *)(CONFIG_SYS_MPC85xx_GPIO_ADDR);
85 struct fsl_ifc ifc = {(void *)CONFIG_SYS_IFC_ADDR, (void *)NULL};
86 /* Clock configuration to access CPLD using IFC(GPCM) */
87 setbits_be32(&ifc.gregs->ifc_gcr, 1 << IFC_GCR_TBCTL_TRN_TIME_SHIFT);
89 * Reset PCIe slots via GPIO4
91 setbits_be32(&pgpio->gpdir, GPIO4_PCIE_RESET_SET);
92 setbits_be32(&pgpio->gpdat, GPIO4_PCIE_RESET_SET);
97 int board_early_init_r(void)
99 const unsigned int flashbase = CONFIG_SYS_FLASH_BASE;
100 int flash_esel = find_tlb_idx((void *)flashbase, 1);
103 * Remap Boot flash region to caching-inhibited
104 * so that flash can be erased properly.
107 /* Flush d-cache and invalidate i-cache of any FLASH data */
111 if (flash_esel == -1) {
112 /* very unlikely unless something is messed up */
113 puts("Error: Could not find TLB for FLASH BASE\n");
114 flash_esel = 2; /* give our best effort to continue */
116 /* invalidate existing TLB entry for flash */
117 disable_tlb(flash_esel);
120 set_tlb(1, flashbase, CONFIG_SYS_FLASH_BASE_PHYS,
121 MAS3_SX|MAS3_SW|MAS3_SR, MAS2_I|MAS2_G,
122 0, flash_esel, BOOKE_PAGESZ_16M, 1);
124 set_tlb(1, flashbase + 0x1000000,
125 CONFIG_SYS_FLASH_BASE_PHYS + 0x1000000,
126 MAS3_SX|MAS3_SW|MAS3_SR, MAS2_I|MAS2_G,
127 0, flash_esel+1, BOOKE_PAGESZ_16M, 1);
131 #if defined(CONFIG_PCI) && !defined(CONFIG_DM_PCI)
132 void pci_init_board(void)
134 fsl_pcie_init_board(0);
136 #endif /* ifdef CONFIG_PCI */
138 int config_board_mux(int ctrl_type)
140 ccsr_gur_t __iomem *gur = (void *)(CONFIG_SYS_MPC85xx_GUTS_ADDR);
146 #if defined(CONFIG_TARGET_P1010RDB_PA)
147 struct cpld_data *cpld_data = (void *)(CONFIG_SYS_CPLD_BASE);
149 ret = i2c_get_chip_for_busnum(I2C_PCA9557_BUS_NUM,
150 I2C_PCA9557_ADDR1, 1, &dev);
152 printf("%s: Cannot find udev for a bus %d\n",
153 __func__, I2C_PCA9557_BUS_NUM);
159 dm_i2c_write(dev, 3, &tmp, 1);
161 dm_i2c_write(dev, 1, &tmp, 1);
162 sd_ifc_mux = MUX_TYPE_IFC;
163 clrbits_be32(&gur->pmuxcr, PMUXCR1_IFC_MASK);
167 dm_i2c_write(dev, 3, &tmp, 1);
169 dm_i2c_write(dev, 1, &tmp, 1);
170 sd_ifc_mux = MUX_TYPE_SDHC;
171 clrsetbits_be32(&gur->pmuxcr, PMUXCR1_SDHC_MASK,
172 PMUXCR1_SDHC_ENABLE);
174 case MUX_TYPE_SPIFLASH:
175 out_8(&cpld_data->spi_cs0_sel, MUX_CPLD_SPICS0_FLASH);
178 out_8(&cpld_data->tdm_can_sel, MUX_CPLD_TDM);
179 out_8(&cpld_data->spi_cs0_sel, MUX_CPLD_SPICS0_SLIC);
182 out_8(&cpld_data->tdm_can_sel, MUX_CPLD_CAN_UART);
187 #elif defined(CONFIG_TARGET_P1010RDB_PB)
188 ret = i2c_get_chip_for_busnum(I2C_PCA9557_BUS_NUM,
189 I2C_PCA9557_ADDR2, 1, &dev);
191 printf("%s: Cannot find udev for a bus %d\n",
192 __func__, I2C_PCA9557_BUS_NUM);
197 dm_i2c_read(dev, 0, &tmp, 1);
198 clrbits_8(&tmp, 0x04);
199 dm_i2c_write(dev, 1, &tmp, 1);
200 dm_i2c_read(dev, 3, &tmp, 1);
201 clrbits_8(&tmp, 0x04);
202 dm_i2c_write(dev, 3, &tmp, 1);
203 sd_ifc_mux = MUX_TYPE_IFC;
204 clrbits_be32(&gur->pmuxcr, PMUXCR1_IFC_MASK);
207 dm_i2c_read(dev, 0, &tmp, 1);
208 setbits_8(&tmp, 0x04);
209 dm_i2c_write(dev, 1, &tmp, 1);
210 dm_i2c_read(dev, 3, &tmp, 1);
211 clrbits_8(&tmp, 0x04);
212 dm_i2c_write(dev, 3, &tmp, 1);
213 sd_ifc_mux = MUX_TYPE_SDHC;
214 clrsetbits_be32(&gur->pmuxcr, PMUXCR1_SDHC_MASK,
215 PMUXCR1_SDHC_ENABLE);
217 case MUX_TYPE_SPIFLASH:
218 dm_i2c_read(dev, 0, &tmp, 1);
219 clrbits_8(&tmp, 0x80);
220 dm_i2c_write(dev, 1, &tmp, 1);
221 dm_i2c_read(dev, 3, &tmp, 1);
222 clrbits_8(&tmp, 0x80);
223 dm_i2c_write(dev, 3, &tmp, 1);
226 dm_i2c_read(dev, 0, &tmp, 1);
227 setbits_8(&tmp, 0x82);
228 dm_i2c_write(dev, 1, &tmp, 1);
229 dm_i2c_read(dev, 3, &tmp, 1);
230 clrbits_8(&tmp, 0x82);
231 dm_i2c_write(dev, 3, &tmp, 1);
234 dm_i2c_read(dev, 0, &tmp, 1);
235 clrbits_8(&tmp, 0x02);
236 dm_i2c_write(dev, 1, &tmp, 1);
237 dm_i2c_read(dev, 3, &tmp, 1);
238 clrbits_8(&tmp, 0x02);
239 dm_i2c_write(dev, 3, &tmp, 1);
241 case MUX_TYPE_CS0_NOR:
242 dm_i2c_read(dev, 0, &tmp, 1);
243 clrbits_8(&tmp, 0x08);
244 dm_i2c_write(dev, 1, &tmp, 1);
245 dm_i2c_read(dev, 3, &tmp, 1);
246 clrbits_8(&tmp, 0x08);
247 dm_i2c_write(dev, 3, &tmp, 1);
249 case MUX_TYPE_CS0_NAND:
250 dm_i2c_read(dev, 0, &tmp, 1);
251 setbits_8(&tmp, 0x08);
252 dm_i2c_write(dev, 1, &tmp, 1);
253 dm_i2c_read(dev, 3, &tmp, 1);
254 clrbits_8(&tmp, 0x08);
255 dm_i2c_write(dev, 3, &tmp, 1);
262 #if defined(CONFIG_TARGET_P1010RDB_PA)
263 struct cpld_data *cpld_data = (void *)(CONFIG_SYS_CPLD_BASE);
267 i2c_set_bus_num(I2C_PCA9557_BUS_NUM);
269 i2c_write(I2C_PCA9557_ADDR1, 3, 1, &tmp, 1);
271 i2c_write(I2C_PCA9557_ADDR1, 1, 1, &tmp, 1);
272 sd_ifc_mux = MUX_TYPE_IFC;
273 clrbits_be32(&gur->pmuxcr, PMUXCR1_IFC_MASK);
276 i2c_set_bus_num(I2C_PCA9557_BUS_NUM);
278 i2c_write(I2C_PCA9557_ADDR1, 3, 1, &tmp, 1);
280 i2c_write(I2C_PCA9557_ADDR1, 1, 1, &tmp, 1);
281 sd_ifc_mux = MUX_TYPE_SDHC;
282 clrsetbits_be32(&gur->pmuxcr, PMUXCR1_SDHC_MASK,
283 PMUXCR1_SDHC_ENABLE);
285 case MUX_TYPE_SPIFLASH:
286 out_8(&cpld_data->spi_cs0_sel, MUX_CPLD_SPICS0_FLASH);
289 out_8(&cpld_data->tdm_can_sel, MUX_CPLD_TDM);
290 out_8(&cpld_data->spi_cs0_sel, MUX_CPLD_SPICS0_SLIC);
293 out_8(&cpld_data->tdm_can_sel, MUX_CPLD_CAN_UART);
298 #elif defined(CONFIG_TARGET_P1010RDB_PB)
299 uint orig_bus = i2c_get_bus_num();
300 i2c_set_bus_num(I2C_PCA9557_BUS_NUM);
304 i2c_read(I2C_PCA9557_ADDR2, 0, 1, &tmp, 1);
305 clrbits_8(&tmp, 0x04);
306 i2c_write(I2C_PCA9557_ADDR2, 1, 1, &tmp, 1);
307 i2c_read(I2C_PCA9557_ADDR2, 3, 1, &tmp, 1);
308 clrbits_8(&tmp, 0x04);
309 i2c_write(I2C_PCA9557_ADDR2, 3, 1, &tmp, 1);
310 sd_ifc_mux = MUX_TYPE_IFC;
311 clrbits_be32(&gur->pmuxcr, PMUXCR1_IFC_MASK);
314 i2c_read(I2C_PCA9557_ADDR2, 0, 1, &tmp, 1);
315 setbits_8(&tmp, 0x04);
316 i2c_write(I2C_PCA9557_ADDR2, 1, 1, &tmp, 1);
317 i2c_read(I2C_PCA9557_ADDR2, 3, 1, &tmp, 1);
318 clrbits_8(&tmp, 0x04);
319 i2c_write(I2C_PCA9557_ADDR2, 3, 1, &tmp, 1);
320 sd_ifc_mux = MUX_TYPE_SDHC;
321 clrsetbits_be32(&gur->pmuxcr, PMUXCR1_SDHC_MASK,
322 PMUXCR1_SDHC_ENABLE);
324 case MUX_TYPE_SPIFLASH:
325 i2c_read(I2C_PCA9557_ADDR2, 0, 1, &tmp, 1);
326 clrbits_8(&tmp, 0x80);
327 i2c_write(I2C_PCA9557_ADDR2, 1, 1, &tmp, 1);
328 i2c_read(I2C_PCA9557_ADDR2, 3, 1, &tmp, 1);
329 clrbits_8(&tmp, 0x80);
330 i2c_write(I2C_PCA9557_ADDR2, 3, 1, &tmp, 1);
333 i2c_read(I2C_PCA9557_ADDR2, 0, 1, &tmp, 1);
334 setbits_8(&tmp, 0x82);
335 i2c_write(I2C_PCA9557_ADDR2, 1, 1, &tmp, 1);
336 i2c_read(I2C_PCA9557_ADDR2, 3, 1, &tmp, 1);
337 clrbits_8(&tmp, 0x82);
338 i2c_write(I2C_PCA9557_ADDR2, 3, 1, &tmp, 1);
341 i2c_read(I2C_PCA9557_ADDR2, 0, 1, &tmp, 1);
342 clrbits_8(&tmp, 0x02);
343 i2c_write(I2C_PCA9557_ADDR2, 1, 1, &tmp, 1);
344 i2c_read(I2C_PCA9557_ADDR2, 3, 1, &tmp, 1);
345 clrbits_8(&tmp, 0x02);
346 i2c_write(I2C_PCA9557_ADDR2, 3, 1, &tmp, 1);
348 case MUX_TYPE_CS0_NOR:
349 i2c_read(I2C_PCA9557_ADDR2, 0, 1, &tmp, 1);
350 clrbits_8(&tmp, 0x08);
351 i2c_write(I2C_PCA9557_ADDR2, 1, 1, &tmp, 1);
352 i2c_read(I2C_PCA9557_ADDR2, 3, 1, &tmp, 1);
353 clrbits_8(&tmp, 0x08);
354 i2c_write(I2C_PCA9557_ADDR2, 3, 1, &tmp, 1);
356 case MUX_TYPE_CS0_NAND:
357 i2c_read(I2C_PCA9557_ADDR2, 0, 1, &tmp, 1);
358 setbits_8(&tmp, 0x08);
359 i2c_write(I2C_PCA9557_ADDR2, 1, 1, &tmp, 1);
360 i2c_read(I2C_PCA9557_ADDR2, 3, 1, &tmp, 1);
361 clrbits_8(&tmp, 0x08);
362 i2c_write(I2C_PCA9557_ADDR2, 3, 1, &tmp, 1);
367 i2c_set_bus_num(orig_bus);
373 #ifdef CONFIG_TARGET_P1010RDB_PB
374 int i2c_pca9557_read(int type)
377 int bus_num = I2C_PCA9557_BUS_NUM;
383 ret = i2c_get_chip_for_busnum(bus_num, I2C_PCA9557_ADDR2, 1, &dev);
385 printf("%s: Cannot find udev for a bus %d\n",
389 dm_i2c_read(dev, 0, &val, 1);
391 i2c_set_bus_num(bus_num);
392 i2c_read(I2C_PCA9557_ADDR2, 0, 1, &val, 1);
397 val = (val & 0x10) >> 4;
399 case I2C_READ_PCB_VER:
400 val = ((val & 0x60) >> 5) + 1;
412 struct cpu_type *cpu;
413 struct cpld_data *cpld_data = (void *)(CONFIG_SYS_CPLD_BASE);
417 #if defined(CONFIG_TARGET_P1010RDB_PA)
418 printf("Board: %sRDB-PA, ", cpu->name);
419 #elif defined(CONFIG_TARGET_P1010RDB_PB)
420 printf("Board: %sRDB-PB, ", cpu->name);
425 ret = i2c_get_chip_for_busnum(I2C_PCA9557_BUS_NUM, I2C_PCA9557_ADDR2,
428 printf("%s: Cannot find udev for a bus %d\n", __func__,
429 I2C_PCA9557_BUS_NUM);
432 val = 0x0; /* no polarity inversion */
433 dm_i2c_write(dev, 2, &val, 1);
435 i2c_set_bus_num(I2C_PCA9557_BUS_NUM);
436 i2c_init(CONFIG_SYS_FSL_I2C_SPEED, CONFIG_SYS_FSL_I2C_SLAVE);
437 val = 0x0; /* no polarity inversion */
438 i2c_write(I2C_PCA9557_ADDR2, 2, 1, &val, 1);
443 /* switch to IFC to read info from CPLD */
444 config_board_mux(MUX_TYPE_IFC);
447 #if defined(CONFIG_TARGET_P1010RDB_PA)
448 val = (in_8(&cpld_data->pcba_ver) & 0xf);
449 printf("PCB: v%x.0\n", val);
450 #elif defined(CONFIG_TARGET_P1010RDB_PB)
451 val = in_8(&cpld_data->cpld_ver);
452 printf("CPLD: v%x.%x, ", val >> 4, val & 0xf);
453 printf("PCB: v%x.0, ", i2c_pca9557_read(I2C_READ_PCB_VER));
454 val = in_8(&cpld_data->rom_loc) & 0xf;
458 config_board_mux(MUX_TYPE_CS0_NOR);
459 printf("NOR vBank%d\n", i2c_pca9557_read(I2C_READ_BANK));
463 val = 0x60; /* set pca9557 pin input/output */
465 dm_i2c_write(dev, 3, &val, 1);
467 i2c_write(I2C_PCA9557_ADDR2, 3, 1, &val, 1);
471 config_board_mux(MUX_TYPE_IFC);
472 config_board_mux(MUX_TYPE_CS0_NAND);
476 config_board_mux(MUX_TYPE_IFC);
487 int board_eth_init(bd_t *bis)
489 #ifdef CONFIG_TSEC_ENET
490 struct fsl_pq_mdio_info mdio_info;
491 struct tsec_info_struct tsec_info[4];
492 struct cpu_type *cpu;
498 SET_STD_TSEC_INFO(tsec_info[num], 1);
502 SET_STD_TSEC_INFO(tsec_info[num], 2);
506 /* P1014 and it's derivatives do not support eTSEC3 */
507 if (cpu->soc_ver != SVR_P1014) {
508 SET_STD_TSEC_INFO(tsec_info[num], 3);
513 printf("No TSECs initialized\n");
517 mdio_info.regs = (struct tsec_mii_mng *)CONFIG_SYS_MDIO_BASE_ADDR;
518 mdio_info.name = DEFAULT_MII_NAME;
520 fsl_pq_mdio_init(bis, &mdio_info);
522 tsec_eth_init(bis, tsec_info, num);
525 return pci_eth_init(bis);
528 #if defined(CONFIG_OF_BOARD_SETUP)
529 void fdt_del_flexcan(void *blob)
533 while ((nodeoff = fdt_node_offset_by_compatible(blob, 0,
534 "fsl,p1010-flexcan")) >= 0) {
535 fdt_del_node(blob, nodeoff);
539 void fdt_del_spi_flash(void *blob)
543 while ((nodeoff = fdt_node_offset_by_compatible(blob, 0,
544 "spansion,s25sl12801")) >= 0) {
545 fdt_del_node(blob, nodeoff);
549 void fdt_del_spi_slic(void *blob)
553 while ((nodeoff = fdt_node_offset_by_compatible(blob, 0,
554 "zarlink,le88266")) >= 0) {
555 fdt_del_node(blob, nodeoff);
559 void fdt_del_tdm(void *blob)
563 while ((nodeoff = fdt_node_offset_by_compatible(blob, 0,
564 "fsl,starlite-tdm")) >= 0) {
565 fdt_del_node(blob, nodeoff);
569 void fdt_del_sdhc(void *blob)
573 while ((nodeoff = fdt_node_offset_by_compatible(blob, 0,
574 "fsl,esdhc")) >= 0) {
575 fdt_del_node(blob, nodeoff);
579 void fdt_del_ifc(void *blob)
583 while ((nodeoff = fdt_node_offset_by_compatible(blob, 0,
585 fdt_del_node(blob, nodeoff);
589 void fdt_disable_uart1(void *blob)
593 nodeoff = fdt_node_offset_by_compat_reg(blob, "fsl,ns16550",
594 CONFIG_SYS_NS16550_COM2);
597 fdt_status_disabled(blob, nodeoff);
599 printf("WARNING unable to set status for fsl,ns16550 "
600 "uart1: %s\n", fdt_strerror(nodeoff));
604 int ft_board_setup(void *blob, bd_t *bd)
608 struct cpu_type *cpu;
612 ft_cpu_setup(blob, bd);
614 base = env_get_bootm_low();
615 size = env_get_bootm_size();
617 #if defined(CONFIG_PCI) && !defined(CONFIG_DM_PCI)
621 fdt_fixup_memory(blob, (u64)base, (u64)size);
623 #if defined(CONFIG_HAS_FSL_DR_USB)
624 fsl_fdt_fixup_dr_usb(blob, bd);
627 /* P1014 and it's derivatives don't support CAN and eTSEC3 */
628 if (cpu->soc_ver == SVR_P1014) {
629 fdt_del_flexcan(blob);
630 fdt_del_node_and_alias(blob, "ethernet2");
633 /* Delete IFC node as IFC pins are multiplexing with SDHC */
634 if (sd_ifc_mux != MUX_TYPE_IFC)
639 if (hwconfig_subarg_cmp("fsl_p1010mux", "tdm_can", "can")) {
641 fdt_del_spi_slic(blob);
642 } else if (hwconfig_subarg_cmp("fsl_p1010mux", "tdm_can", "tdm")) {
643 fdt_del_flexcan(blob);
644 fdt_del_spi_flash(blob);
645 fdt_disable_uart1(blob);
648 * If we don't set fsl_p1010mux:tdm_can to "can" or "tdm"
649 * explicitly, defaultly spi_cs_sel to spi-flash instead of
653 fdt_del_flexcan(blob);
654 fdt_disable_uart1(blob);
662 int board_mmc_init(bd_t *bis)
664 config_board_mux(MUX_TYPE_SDHC);
668 void board_reset(void)
670 /* mux to IFC to enable CPLD for reset */
671 if (sd_ifc_mux != MUX_TYPE_IFC)
672 config_board_mux(MUX_TYPE_IFC);
677 int misc_init_r(void)
679 ccsr_gur_t *gur = (void *)(CONFIG_SYS_MPC85xx_GUTS_ADDR);
681 if (hwconfig_subarg_cmp("fsl_p1010mux", "tdm_can", "can")) {
682 clrbits_be32(&gur->pmuxcr, MPC85xx_PMUXCR_CAN1_TDM |
683 MPC85xx_PMUXCR_CAN1_UART |
684 MPC85xx_PMUXCR_CAN2_TDM |
685 MPC85xx_PMUXCR_CAN2_UART);
686 config_board_mux(MUX_TYPE_CAN);
687 } else if (hwconfig_subarg_cmp("fsl_p1010mux", "tdm_can", "tdm")) {
688 clrbits_be32(&gur->pmuxcr, MPC85xx_PMUXCR_CAN2_UART |
689 MPC85xx_PMUXCR_CAN1_UART);
690 setbits_be32(&gur->pmuxcr, MPC85xx_PMUXCR_CAN2_TDM |
691 MPC85xx_PMUXCR_CAN1_TDM);
692 clrbits_be32(&gur->pmuxcr2, MPC85xx_PMUXCR2_UART_GPIO);
693 setbits_be32(&gur->pmuxcr2, MPC85xx_PMUXCR2_UART_TDM);
694 config_board_mux(MUX_TYPE_TDM);
696 /* defaultly spi_cs_sel to flash */
697 config_board_mux(MUX_TYPE_SPIFLASH);
700 if (hwconfig("esdhc"))
701 config_board_mux(MUX_TYPE_SDHC);
702 else if (hwconfig("ifc"))
703 config_board_mux(MUX_TYPE_IFC);
705 #ifdef CONFIG_TARGET_P1010RDB_PB
706 setbits_be32(&gur->pmuxcr2, MPC85xx_PMUXCR2_GPIO01_DRVVBUS);
711 #ifndef CONFIG_SPL_BUILD
712 static int pin_mux_cmd(struct cmd_tbl *cmdtp, int flag, int argc,
716 return CMD_RET_USAGE;
717 if (strcmp(argv[1], "ifc") == 0)
718 config_board_mux(MUX_TYPE_IFC);
719 else if (strcmp(argv[1], "sdhc") == 0)
720 config_board_mux(MUX_TYPE_SDHC);
722 return CMD_RET_USAGE;
727 mux, 2, 0, pin_mux_cmd,
728 "configure multiplexing pin for IFC/SDHC bus in runtime",
729 "bus_type (e.g. mux sdhc)"