1*83d290c5STom Rini // SPDX-License-Identifier: GPL-2.0+
20b2e13d9SChunhe Lan /*
30b2e13d9SChunhe Lan * Copyright 2014 Freescale Semiconductor, Inc.
40b2e13d9SChunhe Lan *
50b2e13d9SChunhe Lan * Chunhe Lan <Chunhe.Lan@freescale.com>
60b2e13d9SChunhe Lan */
70b2e13d9SChunhe Lan
80b2e13d9SChunhe Lan #include <common.h>
90b2e13d9SChunhe Lan #include <command.h>
100b2e13d9SChunhe Lan #include <netdev.h>
110b2e13d9SChunhe Lan #include <asm/mmu.h>
120b2e13d9SChunhe Lan #include <asm/processor.h>
130b2e13d9SChunhe Lan #include <asm/cache.h>
140b2e13d9SChunhe Lan #include <asm/immap_85xx.h>
150b2e13d9SChunhe Lan #include <asm/fsl_law.h>
160b2e13d9SChunhe Lan #include <fsl_ddr_sdram.h>
170b2e13d9SChunhe Lan #include <asm/fsl_serdes.h>
180b2e13d9SChunhe Lan #include <asm/fsl_portals.h>
190b2e13d9SChunhe Lan #include <asm/fsl_liodn.h>
200b2e13d9SChunhe Lan #include <malloc.h>
210b2e13d9SChunhe Lan #include <fm_eth.h>
220b2e13d9SChunhe Lan #include <fsl_mdio.h>
230b2e13d9SChunhe Lan #include <miiphy.h>
240b2e13d9SChunhe Lan #include <phy.h>
258225b2fdSShaohui Xie #include <fsl_dtsec.h>
260b2e13d9SChunhe Lan #include <asm/fsl_serdes.h>
270b2e13d9SChunhe Lan #include <hwconfig.h>
280b2e13d9SChunhe Lan
290b2e13d9SChunhe Lan #include "../common/fman.h"
300b2e13d9SChunhe Lan #include "t4rdb.h"
310b2e13d9SChunhe Lan
fdt_fixup_board_enet(void * fdt)320b2e13d9SChunhe Lan void fdt_fixup_board_enet(void *fdt)
330b2e13d9SChunhe Lan {
340b2e13d9SChunhe Lan return;
350b2e13d9SChunhe Lan }
360b2e13d9SChunhe Lan
board_eth_init(bd_t * bis)370b2e13d9SChunhe Lan int board_eth_init(bd_t *bis)
380b2e13d9SChunhe Lan {
390b2e13d9SChunhe Lan #if defined(CONFIG_FMAN_ENET)
400b2e13d9SChunhe Lan int i, interface;
410b2e13d9SChunhe Lan struct memac_mdio_info dtsec_mdio_info;
420b2e13d9SChunhe Lan struct memac_mdio_info tgec_mdio_info;
430b2e13d9SChunhe Lan struct mii_dev *dev;
440b2e13d9SChunhe Lan ccsr_gur_t *gur = (void *)(CONFIG_SYS_MPC85xx_GUTS_ADDR);
450b2e13d9SChunhe Lan u32 srds_prtcl_s1, srds_prtcl_s2;
460b2e13d9SChunhe Lan
470b2e13d9SChunhe Lan srds_prtcl_s1 = in_be32(&gur->rcwsr[4]) &
480b2e13d9SChunhe Lan FSL_CORENET2_RCWSR4_SRDS1_PRTCL;
490b2e13d9SChunhe Lan srds_prtcl_s1 >>= FSL_CORENET2_RCWSR4_SRDS1_PRTCL_SHIFT;
500b2e13d9SChunhe Lan srds_prtcl_s2 = in_be32(&gur->rcwsr[4]) &
510b2e13d9SChunhe Lan FSL_CORENET2_RCWSR4_SRDS2_PRTCL;
520b2e13d9SChunhe Lan srds_prtcl_s2 >>= FSL_CORENET2_RCWSR4_SRDS2_PRTCL_SHIFT;
530b2e13d9SChunhe Lan
540b2e13d9SChunhe Lan dtsec_mdio_info.regs =
550b2e13d9SChunhe Lan (struct memac_mdio_controller *)CONFIG_SYS_FM2_DTSEC_MDIO_ADDR;
560b2e13d9SChunhe Lan
570b2e13d9SChunhe Lan dtsec_mdio_info.name = DEFAULT_FM_MDIO_NAME;
580b2e13d9SChunhe Lan
590b2e13d9SChunhe Lan /* Register the 1G MDIO bus */
600b2e13d9SChunhe Lan fm_memac_mdio_init(bis, &dtsec_mdio_info);
610b2e13d9SChunhe Lan
620b2e13d9SChunhe Lan tgec_mdio_info.regs =
630b2e13d9SChunhe Lan (struct memac_mdio_controller *)CONFIG_SYS_FM2_TGEC_MDIO_ADDR;
640b2e13d9SChunhe Lan tgec_mdio_info.name = DEFAULT_FM_TGEC_MDIO_NAME;
650b2e13d9SChunhe Lan
660b2e13d9SChunhe Lan /* Register the 10G MDIO bus */
670b2e13d9SChunhe Lan fm_memac_mdio_init(bis, &tgec_mdio_info);
680b2e13d9SChunhe Lan
69e6c334a7SChunhe Lan if ((srds_prtcl_s1 == 28) || (srds_prtcl_s1 == 27)) {
700b2e13d9SChunhe Lan /* SGMII */
710b2e13d9SChunhe Lan fm_info_set_phy_address(FM1_DTSEC1, SGMII_PHY_ADDR1);
720b2e13d9SChunhe Lan fm_info_set_phy_address(FM1_DTSEC2, SGMII_PHY_ADDR2);
730b2e13d9SChunhe Lan fm_info_set_phy_address(FM1_DTSEC3, SGMII_PHY_ADDR3);
740b2e13d9SChunhe Lan fm_info_set_phy_address(FM1_DTSEC4, SGMII_PHY_ADDR4);
750b2e13d9SChunhe Lan } else {
760b2e13d9SChunhe Lan puts("Invalid SerDes1 protocol for T4240RDB\n");
770b2e13d9SChunhe Lan }
780b2e13d9SChunhe Lan
79d1fc8ed4SYing Zhang fm_disable_port(FM1_DTSEC5);
80d1fc8ed4SYing Zhang fm_disable_port(FM1_DTSEC6);
81d1fc8ed4SYing Zhang
820b2e13d9SChunhe Lan for (i = FM1_DTSEC1; i < FM1_DTSEC1 + CONFIG_SYS_NUM_FM1_DTSEC; i++) {
830b2e13d9SChunhe Lan interface = fm_info_get_enet_if(i);
840b2e13d9SChunhe Lan switch (interface) {
850b2e13d9SChunhe Lan case PHY_INTERFACE_MODE_SGMII:
860b2e13d9SChunhe Lan dev = miiphy_get_dev_by_name(DEFAULT_FM_MDIO_NAME);
870b2e13d9SChunhe Lan fm_info_set_mdio(i, dev);
880b2e13d9SChunhe Lan break;
890b2e13d9SChunhe Lan default:
900b2e13d9SChunhe Lan break;
910b2e13d9SChunhe Lan }
920b2e13d9SChunhe Lan }
930b2e13d9SChunhe Lan
940b2e13d9SChunhe Lan for (i = FM1_10GEC1; i < FM1_10GEC1 + CONFIG_SYS_NUM_FM1_10GEC; i++) {
950b2e13d9SChunhe Lan switch (fm_info_get_enet_if(i)) {
960b2e13d9SChunhe Lan case PHY_INTERFACE_MODE_XGMII:
970b2e13d9SChunhe Lan dev = miiphy_get_dev_by_name(DEFAULT_FM_TGEC_MDIO_NAME);
980b2e13d9SChunhe Lan fm_info_set_mdio(i, dev);
990b2e13d9SChunhe Lan break;
1000b2e13d9SChunhe Lan default:
1010b2e13d9SChunhe Lan break;
1020b2e13d9SChunhe Lan }
1030b2e13d9SChunhe Lan }
1040b2e13d9SChunhe Lan
1050b2e13d9SChunhe Lan #if (CONFIG_SYS_NUM_FMAN == 2)
1063bcf047dSChunhe Lan if ((srds_prtcl_s2 == 56) || (srds_prtcl_s2 == 55)) {
1070b2e13d9SChunhe Lan /* SGMII && XFI */
1080b2e13d9SChunhe Lan fm_info_set_phy_address(FM2_DTSEC1, SGMII_PHY_ADDR5);
1090b2e13d9SChunhe Lan fm_info_set_phy_address(FM2_DTSEC2, SGMII_PHY_ADDR6);
1100b2e13d9SChunhe Lan fm_info_set_phy_address(FM2_DTSEC3, SGMII_PHY_ADDR7);
1110b2e13d9SChunhe Lan fm_info_set_phy_address(FM2_DTSEC4, SGMII_PHY_ADDR8);
1120b2e13d9SChunhe Lan fm_info_set_phy_address(FM1_10GEC1, FM1_10GEC1_PHY_ADDR);
1130b2e13d9SChunhe Lan fm_info_set_phy_address(FM1_10GEC2, FM1_10GEC2_PHY_ADDR);
1140b2e13d9SChunhe Lan fm_info_set_phy_address(FM2_10GEC1, FM2_10GEC2_PHY_ADDR);
1150b2e13d9SChunhe Lan fm_info_set_phy_address(FM2_10GEC2, FM2_10GEC1_PHY_ADDR);
1160b2e13d9SChunhe Lan } else {
1170b2e13d9SChunhe Lan puts("Invalid SerDes2 protocol for T4240RDB\n");
1180b2e13d9SChunhe Lan }
1190b2e13d9SChunhe Lan
120d1fc8ed4SYing Zhang fm_disable_port(FM2_DTSEC5);
121d1fc8ed4SYing Zhang fm_disable_port(FM2_DTSEC6);
1220b2e13d9SChunhe Lan for (i = FM2_DTSEC1; i < FM2_DTSEC1 + CONFIG_SYS_NUM_FM2_DTSEC; i++) {
1230b2e13d9SChunhe Lan interface = fm_info_get_enet_if(i);
1240b2e13d9SChunhe Lan switch (interface) {
1250b2e13d9SChunhe Lan case PHY_INTERFACE_MODE_SGMII:
1260b2e13d9SChunhe Lan dev = miiphy_get_dev_by_name(DEFAULT_FM_MDIO_NAME);
1270b2e13d9SChunhe Lan fm_info_set_mdio(i, dev);
1280b2e13d9SChunhe Lan break;
1290b2e13d9SChunhe Lan default:
1300b2e13d9SChunhe Lan break;
1310b2e13d9SChunhe Lan }
1320b2e13d9SChunhe Lan }
1330b2e13d9SChunhe Lan
1340b2e13d9SChunhe Lan for (i = FM2_10GEC1; i < FM2_10GEC1 + CONFIG_SYS_NUM_FM2_10GEC; i++) {
1350b2e13d9SChunhe Lan switch (fm_info_get_enet_if(i)) {
1360b2e13d9SChunhe Lan case PHY_INTERFACE_MODE_XGMII:
1370b2e13d9SChunhe Lan dev = miiphy_get_dev_by_name(DEFAULT_FM_TGEC_MDIO_NAME);
1380b2e13d9SChunhe Lan fm_info_set_mdio(i, dev);
1390b2e13d9SChunhe Lan break;
1400b2e13d9SChunhe Lan default:
1410b2e13d9SChunhe Lan break;
1420b2e13d9SChunhe Lan }
1430b2e13d9SChunhe Lan }
1440b2e13d9SChunhe Lan #endif /* CONFIG_SYS_NUM_FMAN */
1450b2e13d9SChunhe Lan
1460b2e13d9SChunhe Lan cpu_eth_init(bis);
1470b2e13d9SChunhe Lan #endif /* CONFIG_FMAN_ENET */
1480b2e13d9SChunhe Lan
1490b2e13d9SChunhe Lan return pci_eth_init(bis);
1500b2e13d9SChunhe Lan }
151