1 // SPDX-License-Identifier: GPL-2.0+
3 * Copyright 2010-2011 Freescale Semiconductor, Inc.
9 #include <asm/processor.h>
11 #include <asm/cache.h>
12 #include <asm/immap_85xx.h>
16 #include <linux/libfdt.h>
17 #include <fdt_support.h>
23 #include <asm/fsl_serdes.h>
25 #include <asm/fsl_pci.h>
29 DECLARE_GLOBAL_DATA_PTR;
31 #define GPIO4_PCIE_RESET_SET 0x08000000
32 #define MUX_CPLD_CAN_UART 0x00
33 #define MUX_CPLD_TDM 0x01
34 #define MUX_CPLD_SPICS0_FLASH 0x00
35 #define MUX_CPLD_SPICS0_SLIC 0x02
36 #define PMUXCR1_IFC_MASK 0x00ffff00
37 #define PMUXCR1_SDHC_MASK 0x00fff000
38 #define PMUXCR1_SDHC_ENABLE 0x00555000
55 static uint sd_ifc_mux;
58 u8 cpld_ver; /* cpld revision */
59 #if defined(CONFIG_TARGET_P1010RDB_PA)
60 u8 pcba_ver; /* pcb revision number */
63 u8 bank_sel; /* NOR Flash bank */
69 u8 spi_cs0_sel; /* SPI CS0 SLIC/SPI Flash */
70 u8 por0; /* POR Options */
71 u8 por1; /* POR Options */
72 u8 por2; /* POR Options */
73 u8 por3; /* POR Options */
74 #elif defined(CONFIG_TARGET_P1010RDB_PB)
79 int board_early_init_f(void)
81 ccsr_gpio_t *pgpio = (void *)(CONFIG_SYS_MPC85xx_GPIO_ADDR);
82 struct fsl_ifc ifc = {(void *)CONFIG_SYS_IFC_ADDR, (void *)NULL};
83 /* Clock configuration to access CPLD using IFC(GPCM) */
84 setbits_be32(&ifc.gregs->ifc_gcr, 1 << IFC_GCR_TBCTL_TRN_TIME_SHIFT);
86 * Reset PCIe slots via GPIO4
88 setbits_be32(&pgpio->gpdir, GPIO4_PCIE_RESET_SET);
89 setbits_be32(&pgpio->gpdat, GPIO4_PCIE_RESET_SET);
94 int board_early_init_r(void)
96 const unsigned int flashbase = CONFIG_SYS_FLASH_BASE;
97 int flash_esel = find_tlb_idx((void *)flashbase, 1);
100 * Remap Boot flash region to caching-inhibited
101 * so that flash can be erased properly.
104 /* Flush d-cache and invalidate i-cache of any FLASH data */
108 if (flash_esel == -1) {
109 /* very unlikely unless something is messed up */
110 puts("Error: Could not find TLB for FLASH BASE\n");
111 flash_esel = 2; /* give our best effort to continue */
113 /* invalidate existing TLB entry for flash */
114 disable_tlb(flash_esel);
117 set_tlb(1, flashbase, CONFIG_SYS_FLASH_BASE_PHYS,
118 MAS3_SX|MAS3_SW|MAS3_SR, MAS2_I|MAS2_G,
119 0, flash_esel, BOOKE_PAGESZ_16M, 1);
121 set_tlb(1, flashbase + 0x1000000,
122 CONFIG_SYS_FLASH_BASE_PHYS + 0x1000000,
123 MAS3_SX|MAS3_SW|MAS3_SR, MAS2_I|MAS2_G,
124 0, flash_esel+1, BOOKE_PAGESZ_16M, 1);
129 void pci_init_board(void)
131 fsl_pcie_init_board(0);
133 #endif /* ifdef CONFIG_PCI */
135 int config_board_mux(int ctrl_type)
137 ccsr_gur_t __iomem *gur = (void *)(CONFIG_SYS_MPC85xx_GUTS_ADDR);
143 #if defined(CONFIG_TARGET_P1010RDB_PA)
144 struct cpld_data *cpld_data = (void *)(CONFIG_SYS_CPLD_BASE);
146 ret = i2c_get_chip_for_busnum(I2C_PCA9557_BUS_NUM,
147 I2C_PCA9557_ADDR1, 1, &dev);
149 printf("%s: Cannot find udev for a bus %d\n",
150 __func__, I2C_PCA9557_BUS_NUM);
156 dm_i2c_write(dev, 3, &tmp, 1);
158 dm_i2c_write(dev, 1, &tmp, 1);
159 sd_ifc_mux = MUX_TYPE_IFC;
160 clrbits_be32(&gur->pmuxcr, PMUXCR1_IFC_MASK);
164 dm_i2c_write(dev, 3, &tmp, 1);
166 dm_i2c_write(dev, 1, &tmp, 1);
167 sd_ifc_mux = MUX_TYPE_SDHC;
168 clrsetbits_be32(&gur->pmuxcr, PMUXCR1_SDHC_MASK,
169 PMUXCR1_SDHC_ENABLE);
171 case MUX_TYPE_SPIFLASH:
172 out_8(&cpld_data->spi_cs0_sel, MUX_CPLD_SPICS0_FLASH);
175 out_8(&cpld_data->tdm_can_sel, MUX_CPLD_TDM);
176 out_8(&cpld_data->spi_cs0_sel, MUX_CPLD_SPICS0_SLIC);
179 out_8(&cpld_data->tdm_can_sel, MUX_CPLD_CAN_UART);
184 #elif defined(CONFIG_TARGET_P1010RDB_PB)
185 ret = i2c_get_chip_for_busnum(I2C_PCA9557_BUS_NUM,
186 I2C_PCA9557_ADDR2, 1, &dev);
188 printf("%s: Cannot find udev for a bus %d\n",
189 __func__, I2C_PCA9557_BUS_NUM);
194 dm_i2c_read(dev, 0, &tmp, 1);
195 clrbits_8(&tmp, 0x04);
196 dm_i2c_write(dev, 1, &tmp, 1);
197 dm_i2c_read(dev, 3, &tmp, 1);
198 clrbits_8(&tmp, 0x04);
199 dm_i2c_write(dev, 3, &tmp, 1);
200 sd_ifc_mux = MUX_TYPE_IFC;
201 clrbits_be32(&gur->pmuxcr, PMUXCR1_IFC_MASK);
204 dm_i2c_read(dev, 0, &tmp, 1);
205 setbits_8(&tmp, 0x04);
206 dm_i2c_write(dev, 1, &tmp, 1);
207 dm_i2c_read(dev, 3, &tmp, 1);
208 clrbits_8(&tmp, 0x04);
209 dm_i2c_write(dev, 3, &tmp, 1);
210 sd_ifc_mux = MUX_TYPE_SDHC;
211 clrsetbits_be32(&gur->pmuxcr, PMUXCR1_SDHC_MASK,
212 PMUXCR1_SDHC_ENABLE);
214 case MUX_TYPE_SPIFLASH:
215 dm_i2c_read(dev, 0, &tmp, 1);
216 clrbits_8(&tmp, 0x80);
217 dm_i2c_write(dev, 1, &tmp, 1);
218 dm_i2c_read(dev, 3, &tmp, 1);
219 clrbits_8(&tmp, 0x80);
220 dm_i2c_write(dev, 3, &tmp, 1);
223 dm_i2c_read(dev, 0, &tmp, 1);
224 setbits_8(&tmp, 0x82);
225 dm_i2c_write(dev, 1, &tmp, 1);
226 dm_i2c_read(dev, 3, &tmp, 1);
227 clrbits_8(&tmp, 0x82);
228 dm_i2c_write(dev, 3, &tmp, 1);
231 dm_i2c_read(dev, 0, &tmp, 1);
232 clrbits_8(&tmp, 0x02);
233 dm_i2c_write(dev, 1, &tmp, 1);
234 dm_i2c_read(dev, 3, &tmp, 1);
235 clrbits_8(&tmp, 0x02);
236 dm_i2c_write(dev, 3, &tmp, 1);
238 case MUX_TYPE_CS0_NOR:
239 dm_i2c_read(dev, 0, &tmp, 1);
240 clrbits_8(&tmp, 0x08);
241 dm_i2c_write(dev, 1, &tmp, 1);
242 dm_i2c_read(dev, 3, &tmp, 1);
243 clrbits_8(&tmp, 0x08);
244 dm_i2c_write(dev, 3, &tmp, 1);
246 case MUX_TYPE_CS0_NAND:
247 dm_i2c_read(dev, 0, &tmp, 1);
248 setbits_8(&tmp, 0x08);
249 dm_i2c_write(dev, 1, &tmp, 1);
250 dm_i2c_read(dev, 3, &tmp, 1);
251 clrbits_8(&tmp, 0x08);
252 dm_i2c_write(dev, 3, &tmp, 1);
259 #if defined(CONFIG_TARGET_P1010RDB_PA)
260 struct cpld_data *cpld_data = (void *)(CONFIG_SYS_CPLD_BASE);
264 i2c_set_bus_num(I2C_PCA9557_BUS_NUM);
266 i2c_write(I2C_PCA9557_ADDR1, 3, 1, &tmp, 1);
268 i2c_write(I2C_PCA9557_ADDR1, 1, 1, &tmp, 1);
269 sd_ifc_mux = MUX_TYPE_IFC;
270 clrbits_be32(&gur->pmuxcr, PMUXCR1_IFC_MASK);
273 i2c_set_bus_num(I2C_PCA9557_BUS_NUM);
275 i2c_write(I2C_PCA9557_ADDR1, 3, 1, &tmp, 1);
277 i2c_write(I2C_PCA9557_ADDR1, 1, 1, &tmp, 1);
278 sd_ifc_mux = MUX_TYPE_SDHC;
279 clrsetbits_be32(&gur->pmuxcr, PMUXCR1_SDHC_MASK,
280 PMUXCR1_SDHC_ENABLE);
282 case MUX_TYPE_SPIFLASH:
283 out_8(&cpld_data->spi_cs0_sel, MUX_CPLD_SPICS0_FLASH);
286 out_8(&cpld_data->tdm_can_sel, MUX_CPLD_TDM);
287 out_8(&cpld_data->spi_cs0_sel, MUX_CPLD_SPICS0_SLIC);
290 out_8(&cpld_data->tdm_can_sel, MUX_CPLD_CAN_UART);
295 #elif defined(CONFIG_TARGET_P1010RDB_PB)
296 uint orig_bus = i2c_get_bus_num();
297 i2c_set_bus_num(I2C_PCA9557_BUS_NUM);
301 i2c_read(I2C_PCA9557_ADDR2, 0, 1, &tmp, 1);
302 clrbits_8(&tmp, 0x04);
303 i2c_write(I2C_PCA9557_ADDR2, 1, 1, &tmp, 1);
304 i2c_read(I2C_PCA9557_ADDR2, 3, 1, &tmp, 1);
305 clrbits_8(&tmp, 0x04);
306 i2c_write(I2C_PCA9557_ADDR2, 3, 1, &tmp, 1);
307 sd_ifc_mux = MUX_TYPE_IFC;
308 clrbits_be32(&gur->pmuxcr, PMUXCR1_IFC_MASK);
311 i2c_read(I2C_PCA9557_ADDR2, 0, 1, &tmp, 1);
312 setbits_8(&tmp, 0x04);
313 i2c_write(I2C_PCA9557_ADDR2, 1, 1, &tmp, 1);
314 i2c_read(I2C_PCA9557_ADDR2, 3, 1, &tmp, 1);
315 clrbits_8(&tmp, 0x04);
316 i2c_write(I2C_PCA9557_ADDR2, 3, 1, &tmp, 1);
317 sd_ifc_mux = MUX_TYPE_SDHC;
318 clrsetbits_be32(&gur->pmuxcr, PMUXCR1_SDHC_MASK,
319 PMUXCR1_SDHC_ENABLE);
321 case MUX_TYPE_SPIFLASH:
322 i2c_read(I2C_PCA9557_ADDR2, 0, 1, &tmp, 1);
323 clrbits_8(&tmp, 0x80);
324 i2c_write(I2C_PCA9557_ADDR2, 1, 1, &tmp, 1);
325 i2c_read(I2C_PCA9557_ADDR2, 3, 1, &tmp, 1);
326 clrbits_8(&tmp, 0x80);
327 i2c_write(I2C_PCA9557_ADDR2, 3, 1, &tmp, 1);
330 i2c_read(I2C_PCA9557_ADDR2, 0, 1, &tmp, 1);
331 setbits_8(&tmp, 0x82);
332 i2c_write(I2C_PCA9557_ADDR2, 1, 1, &tmp, 1);
333 i2c_read(I2C_PCA9557_ADDR2, 3, 1, &tmp, 1);
334 clrbits_8(&tmp, 0x82);
335 i2c_write(I2C_PCA9557_ADDR2, 3, 1, &tmp, 1);
338 i2c_read(I2C_PCA9557_ADDR2, 0, 1, &tmp, 1);
339 clrbits_8(&tmp, 0x02);
340 i2c_write(I2C_PCA9557_ADDR2, 1, 1, &tmp, 1);
341 i2c_read(I2C_PCA9557_ADDR2, 3, 1, &tmp, 1);
342 clrbits_8(&tmp, 0x02);
343 i2c_write(I2C_PCA9557_ADDR2, 3, 1, &tmp, 1);
345 case MUX_TYPE_CS0_NOR:
346 i2c_read(I2C_PCA9557_ADDR2, 0, 1, &tmp, 1);
347 clrbits_8(&tmp, 0x08);
348 i2c_write(I2C_PCA9557_ADDR2, 1, 1, &tmp, 1);
349 i2c_read(I2C_PCA9557_ADDR2, 3, 1, &tmp, 1);
350 clrbits_8(&tmp, 0x08);
351 i2c_write(I2C_PCA9557_ADDR2, 3, 1, &tmp, 1);
353 case MUX_TYPE_CS0_NAND:
354 i2c_read(I2C_PCA9557_ADDR2, 0, 1, &tmp, 1);
355 setbits_8(&tmp, 0x08);
356 i2c_write(I2C_PCA9557_ADDR2, 1, 1, &tmp, 1);
357 i2c_read(I2C_PCA9557_ADDR2, 3, 1, &tmp, 1);
358 clrbits_8(&tmp, 0x08);
359 i2c_write(I2C_PCA9557_ADDR2, 3, 1, &tmp, 1);
364 i2c_set_bus_num(orig_bus);
370 #ifdef CONFIG_TARGET_P1010RDB_PB
371 int i2c_pca9557_read(int type)
374 int bus_num = I2C_PCA9557_BUS_NUM;
380 ret = i2c_get_chip_for_busnum(bus_num, I2C_PCA9557_ADDR2, 1, &dev);
382 printf("%s: Cannot find udev for a bus %d\n",
386 dm_i2c_read(dev, 0, &val, 1);
388 i2c_set_bus_num(bus_num);
389 i2c_read(I2C_PCA9557_ADDR2, 0, 1, &val, 1);
394 val = (val & 0x10) >> 4;
396 case I2C_READ_PCB_VER:
397 val = ((val & 0x60) >> 5) + 1;
409 struct cpu_type *cpu;
410 struct cpld_data *cpld_data = (void *)(CONFIG_SYS_CPLD_BASE);
414 #if defined(CONFIG_TARGET_P1010RDB_PA)
415 printf("Board: %sRDB-PA, ", cpu->name);
416 #elif defined(CONFIG_TARGET_P1010RDB_PB)
417 printf("Board: %sRDB-PB, ", cpu->name);
422 ret = i2c_get_chip_for_busnum(I2C_PCA9557_BUS_NUM, I2C_PCA9557_ADDR2,
425 printf("%s: Cannot find udev for a bus %d\n", __func__,
426 I2C_PCA9557_BUS_NUM);
429 val = 0x0; /* no polarity inversion */
430 dm_i2c_write(dev, 2, &val, 1);
432 i2c_set_bus_num(I2C_PCA9557_BUS_NUM);
433 i2c_init(CONFIG_SYS_FSL_I2C_SPEED, CONFIG_SYS_FSL_I2C_SLAVE);
434 val = 0x0; /* no polarity inversion */
435 i2c_write(I2C_PCA9557_ADDR2, 2, 1, &val, 1);
440 /* switch to IFC to read info from CPLD */
441 config_board_mux(MUX_TYPE_IFC);
444 #if defined(CONFIG_TARGET_P1010RDB_PA)
445 val = (in_8(&cpld_data->pcba_ver) & 0xf);
446 printf("PCB: v%x.0\n", val);
447 #elif defined(CONFIG_TARGET_P1010RDB_PB)
448 val = in_8(&cpld_data->cpld_ver);
449 printf("CPLD: v%x.%x, ", val >> 4, val & 0xf);
450 printf("PCB: v%x.0, ", i2c_pca9557_read(I2C_READ_PCB_VER));
451 val = in_8(&cpld_data->rom_loc) & 0xf;
455 config_board_mux(MUX_TYPE_CS0_NOR);
456 printf("NOR vBank%d\n", i2c_pca9557_read(I2C_READ_BANK));
460 val = 0x60; /* set pca9557 pin input/output */
462 dm_i2c_write(dev, 3, &val, 1);
464 i2c_write(I2C_PCA9557_ADDR2, 3, 1, &val, 1);
468 config_board_mux(MUX_TYPE_IFC);
469 config_board_mux(MUX_TYPE_CS0_NAND);
473 config_board_mux(MUX_TYPE_IFC);
484 int board_eth_init(bd_t *bis)
486 #ifdef CONFIG_TSEC_ENET
487 struct fsl_pq_mdio_info mdio_info;
488 struct tsec_info_struct tsec_info[4];
489 struct cpu_type *cpu;
495 SET_STD_TSEC_INFO(tsec_info[num], 1);
499 SET_STD_TSEC_INFO(tsec_info[num], 2);
503 /* P1014 and it's derivatives do not support eTSEC3 */
504 if (cpu->soc_ver != SVR_P1014) {
505 SET_STD_TSEC_INFO(tsec_info[num], 3);
510 printf("No TSECs initialized\n");
514 mdio_info.regs = (struct tsec_mii_mng *)CONFIG_SYS_MDIO_BASE_ADDR;
515 mdio_info.name = DEFAULT_MII_NAME;
517 fsl_pq_mdio_init(bis, &mdio_info);
519 tsec_eth_init(bis, tsec_info, num);
522 return pci_eth_init(bis);
525 #if defined(CONFIG_OF_BOARD_SETUP)
526 void fdt_del_flexcan(void *blob)
530 while ((nodeoff = fdt_node_offset_by_compatible(blob, 0,
531 "fsl,p1010-flexcan")) >= 0) {
532 fdt_del_node(blob, nodeoff);
536 void fdt_del_spi_flash(void *blob)
540 while ((nodeoff = fdt_node_offset_by_compatible(blob, 0,
541 "spansion,s25sl12801")) >= 0) {
542 fdt_del_node(blob, nodeoff);
546 void fdt_del_spi_slic(void *blob)
550 while ((nodeoff = fdt_node_offset_by_compatible(blob, 0,
551 "zarlink,le88266")) >= 0) {
552 fdt_del_node(blob, nodeoff);
556 void fdt_del_tdm(void *blob)
560 while ((nodeoff = fdt_node_offset_by_compatible(blob, 0,
561 "fsl,starlite-tdm")) >= 0) {
562 fdt_del_node(blob, nodeoff);
566 void fdt_del_sdhc(void *blob)
570 while ((nodeoff = fdt_node_offset_by_compatible(blob, 0,
571 "fsl,esdhc")) >= 0) {
572 fdt_del_node(blob, nodeoff);
576 void fdt_del_ifc(void *blob)
580 while ((nodeoff = fdt_node_offset_by_compatible(blob, 0,
582 fdt_del_node(blob, nodeoff);
586 void fdt_disable_uart1(void *blob)
590 nodeoff = fdt_node_offset_by_compat_reg(blob, "fsl,ns16550",
591 CONFIG_SYS_NS16550_COM2);
594 fdt_status_disabled(blob, nodeoff);
596 printf("WARNING unable to set status for fsl,ns16550 "
597 "uart1: %s\n", fdt_strerror(nodeoff));
601 int ft_board_setup(void *blob, bd_t *bd)
605 struct cpu_type *cpu;
609 ft_cpu_setup(blob, bd);
611 base = env_get_bootm_low();
612 size = env_get_bootm_size();
614 #if defined(CONFIG_PCI)
618 fdt_fixup_memory(blob, (u64)base, (u64)size);
620 #if defined(CONFIG_HAS_FSL_DR_USB)
621 fsl_fdt_fixup_dr_usb(blob, bd);
624 /* P1014 and it's derivatives don't support CAN and eTSEC3 */
625 if (cpu->soc_ver == SVR_P1014) {
626 fdt_del_flexcan(blob);
627 fdt_del_node_and_alias(blob, "ethernet2");
630 /* Delete IFC node as IFC pins are multiplexing with SDHC */
631 if (sd_ifc_mux != MUX_TYPE_IFC)
636 if (hwconfig_subarg_cmp("fsl_p1010mux", "tdm_can", "can")) {
638 fdt_del_spi_slic(blob);
639 } else if (hwconfig_subarg_cmp("fsl_p1010mux", "tdm_can", "tdm")) {
640 fdt_del_flexcan(blob);
641 fdt_del_spi_flash(blob);
642 fdt_disable_uart1(blob);
645 * If we don't set fsl_p1010mux:tdm_can to "can" or "tdm"
646 * explicitly, defaultly spi_cs_sel to spi-flash instead of
650 fdt_del_flexcan(blob);
651 fdt_disable_uart1(blob);
659 int board_mmc_init(bd_t *bis)
661 config_board_mux(MUX_TYPE_SDHC);
665 void board_reset(void)
667 /* mux to IFC to enable CPLD for reset */
668 if (sd_ifc_mux != MUX_TYPE_IFC)
669 config_board_mux(MUX_TYPE_IFC);
674 int misc_init_r(void)
676 ccsr_gur_t *gur = (void *)(CONFIG_SYS_MPC85xx_GUTS_ADDR);
678 if (hwconfig_subarg_cmp("fsl_p1010mux", "tdm_can", "can")) {
679 clrbits_be32(&gur->pmuxcr, MPC85xx_PMUXCR_CAN1_TDM |
680 MPC85xx_PMUXCR_CAN1_UART |
681 MPC85xx_PMUXCR_CAN2_TDM |
682 MPC85xx_PMUXCR_CAN2_UART);
683 config_board_mux(MUX_TYPE_CAN);
684 } else if (hwconfig_subarg_cmp("fsl_p1010mux", "tdm_can", "tdm")) {
685 clrbits_be32(&gur->pmuxcr, MPC85xx_PMUXCR_CAN2_UART |
686 MPC85xx_PMUXCR_CAN1_UART);
687 setbits_be32(&gur->pmuxcr, MPC85xx_PMUXCR_CAN2_TDM |
688 MPC85xx_PMUXCR_CAN1_TDM);
689 clrbits_be32(&gur->pmuxcr2, MPC85xx_PMUXCR2_UART_GPIO);
690 setbits_be32(&gur->pmuxcr2, MPC85xx_PMUXCR2_UART_TDM);
691 config_board_mux(MUX_TYPE_TDM);
693 /* defaultly spi_cs_sel to flash */
694 config_board_mux(MUX_TYPE_SPIFLASH);
697 if (hwconfig("esdhc"))
698 config_board_mux(MUX_TYPE_SDHC);
699 else if (hwconfig("ifc"))
700 config_board_mux(MUX_TYPE_IFC);
702 #ifdef CONFIG_TARGET_P1010RDB_PB
703 setbits_be32(&gur->pmuxcr2, MPC85xx_PMUXCR2_GPIO01_DRVVBUS);
708 #ifndef CONFIG_SPL_BUILD
709 static int pin_mux_cmd(cmd_tbl_t *cmdtp, int flag, int argc,
713 return CMD_RET_USAGE;
714 if (strcmp(argv[1], "ifc") == 0)
715 config_board_mux(MUX_TYPE_IFC);
716 else if (strcmp(argv[1], "sdhc") == 0)
717 config_board_mux(MUX_TYPE_SDHC);
719 return CMD_RET_USAGE;
724 mux, 2, 0, pin_mux_cmd,
725 "configure multiplexing pin for IFC/SDHC bus in runtime",
726 "bus_type (e.g. mux sdhc)"