xref: /openbmc/u-boot/board/freescale/ls2080ardb/eth_ls2080rdb.c (revision 0223462b373b975d970fa86e5e1a7eadd1d41820)
183d290c5STom Rini // SPDX-License-Identifier: GPL-2.0+
244937214SPrabhakar Kushwaha /*
344937214SPrabhakar Kushwaha  * Copyright 2015 Freescale Semiconductor, Inc.
444937214SPrabhakar Kushwaha  *
544937214SPrabhakar Kushwaha  */
644937214SPrabhakar Kushwaha 
744937214SPrabhakar Kushwaha #include <common.h>
844937214SPrabhakar Kushwaha #include <command.h>
944937214SPrabhakar Kushwaha #include <netdev.h>
1044937214SPrabhakar Kushwaha #include <malloc.h>
1144937214SPrabhakar Kushwaha #include <fsl_mdio.h>
1244937214SPrabhakar Kushwaha #include <miiphy.h>
1344937214SPrabhakar Kushwaha #include <phy.h>
1444937214SPrabhakar Kushwaha #include <fm_eth.h>
1544937214SPrabhakar Kushwaha #include <asm/io.h>
1644937214SPrabhakar Kushwaha #include <exports.h>
1744937214SPrabhakar Kushwaha #include <asm/arch/fsl_serdes.h>
1833a8991aSBogdan Purcareata #include <fsl-mc/fsl_mc.h>
1944937214SPrabhakar Kushwaha #include <fsl-mc/ldpaa_wriop.h>
2044937214SPrabhakar Kushwaha 
2144937214SPrabhakar Kushwaha DECLARE_GLOBAL_DATA_PTR;
2244937214SPrabhakar Kushwaha 
board_eth_init(bd_t * bis)2344937214SPrabhakar Kushwaha int board_eth_init(bd_t *bis)
2444937214SPrabhakar Kushwaha {
2544937214SPrabhakar Kushwaha #if defined(CONFIG_FSL_MC_ENET)
2644937214SPrabhakar Kushwaha 	int i, interface;
2744937214SPrabhakar Kushwaha 	struct memac_mdio_info mdio_info;
2844937214SPrabhakar Kushwaha 	struct mii_dev *dev;
2944937214SPrabhakar Kushwaha 	struct ccsr_gur *gur = (void *)(CONFIG_SYS_FSL_GUTS_ADDR);
3044937214SPrabhakar Kushwaha 	u32 srds_s1;
3144937214SPrabhakar Kushwaha 	struct memac_mdio_controller *reg;
3244937214SPrabhakar Kushwaha 
3344937214SPrabhakar Kushwaha 	srds_s1 = in_le32(&gur->rcwsr[28]) &
3444937214SPrabhakar Kushwaha 				FSL_CHASSIS3_RCWSR28_SRDS1_PRTCL_MASK;
3544937214SPrabhakar Kushwaha 	srds_s1 >>= FSL_CHASSIS3_RCWSR28_SRDS1_PRTCL_SHIFT;
3644937214SPrabhakar Kushwaha 
3744937214SPrabhakar Kushwaha 	reg = (struct memac_mdio_controller *)CONFIG_SYS_FSL_WRIOP1_MDIO1;
3844937214SPrabhakar Kushwaha 	mdio_info.regs = reg;
3944937214SPrabhakar Kushwaha 	mdio_info.name = DEFAULT_WRIOP_MDIO1_NAME;
4044937214SPrabhakar Kushwaha 
4144937214SPrabhakar Kushwaha 	/* Register the EMI 1 */
4244937214SPrabhakar Kushwaha 	fm_memac_mdio_init(bis, &mdio_info);
4344937214SPrabhakar Kushwaha 
4444937214SPrabhakar Kushwaha 	reg = (struct memac_mdio_controller *)CONFIG_SYS_FSL_WRIOP1_MDIO2;
4544937214SPrabhakar Kushwaha 	mdio_info.regs = reg;
4644937214SPrabhakar Kushwaha 	mdio_info.name = DEFAULT_WRIOP_MDIO2_NAME;
4744937214SPrabhakar Kushwaha 
4844937214SPrabhakar Kushwaha 	/* Register the EMI 2 */
4944937214SPrabhakar Kushwaha 	fm_memac_mdio_init(bis, &mdio_info);
5044937214SPrabhakar Kushwaha 
5144937214SPrabhakar Kushwaha 	switch (srds_s1) {
5244937214SPrabhakar Kushwaha 	case 0x2A:
53*1a048cd6SPankaj Bansal 		wriop_set_phy_address(WRIOP1_DPMAC1, 0, CORTINA_PHY_ADDR1);
54*1a048cd6SPankaj Bansal 		wriop_set_phy_address(WRIOP1_DPMAC2, 0, CORTINA_PHY_ADDR2);
55*1a048cd6SPankaj Bansal 		wriop_set_phy_address(WRIOP1_DPMAC3, 0, CORTINA_PHY_ADDR3);
56*1a048cd6SPankaj Bansal 		wriop_set_phy_address(WRIOP1_DPMAC4, 0, CORTINA_PHY_ADDR4);
57*1a048cd6SPankaj Bansal 		wriop_set_phy_address(WRIOP1_DPMAC5, 0, AQ_PHY_ADDR1);
58*1a048cd6SPankaj Bansal 		wriop_set_phy_address(WRIOP1_DPMAC6, 0, AQ_PHY_ADDR2);
59*1a048cd6SPankaj Bansal 		wriop_set_phy_address(WRIOP1_DPMAC7, 0, AQ_PHY_ADDR3);
60*1a048cd6SPankaj Bansal 		wriop_set_phy_address(WRIOP1_DPMAC8, 0, AQ_PHY_ADDR4);
6144937214SPrabhakar Kushwaha 
6244937214SPrabhakar Kushwaha 		break;
6399fe76d0SSantan Kumar 	case 0x4B:
64*1a048cd6SPankaj Bansal 		wriop_set_phy_address(WRIOP1_DPMAC1, 0, CORTINA_PHY_ADDR1);
65*1a048cd6SPankaj Bansal 		wriop_set_phy_address(WRIOP1_DPMAC2, 0, CORTINA_PHY_ADDR2);
66*1a048cd6SPankaj Bansal 		wriop_set_phy_address(WRIOP1_DPMAC3, 0, CORTINA_PHY_ADDR3);
67*1a048cd6SPankaj Bansal 		wriop_set_phy_address(WRIOP1_DPMAC4, 0, CORTINA_PHY_ADDR4);
6899fe76d0SSantan Kumar 
6999fe76d0SSantan Kumar 		break;
7044937214SPrabhakar Kushwaha 	default:
7144937214SPrabhakar Kushwaha 		printf("SerDes1 protocol 0x%x is not supported on LS2080aRDB\n",
7244937214SPrabhakar Kushwaha 		       srds_s1);
7344937214SPrabhakar Kushwaha 		break;
7444937214SPrabhakar Kushwaha 	}
7544937214SPrabhakar Kushwaha 
7644937214SPrabhakar Kushwaha 	for (i = WRIOP1_DPMAC1; i <= WRIOP1_DPMAC4; i++) {
7744937214SPrabhakar Kushwaha 		interface = wriop_get_enet_if(i);
7844937214SPrabhakar Kushwaha 		switch (interface) {
7944937214SPrabhakar Kushwaha 		case PHY_INTERFACE_MODE_XGMII:
8044937214SPrabhakar Kushwaha 			dev = miiphy_get_dev_by_name(DEFAULT_WRIOP_MDIO1_NAME);
8144937214SPrabhakar Kushwaha 			wriop_set_mdio(i, dev);
8244937214SPrabhakar Kushwaha 			break;
8344937214SPrabhakar Kushwaha 		default:
8444937214SPrabhakar Kushwaha 			break;
8544937214SPrabhakar Kushwaha 		}
8644937214SPrabhakar Kushwaha 	}
8744937214SPrabhakar Kushwaha 
8844937214SPrabhakar Kushwaha 	for (i = WRIOP1_DPMAC5; i <= WRIOP1_DPMAC8; i++) {
8944937214SPrabhakar Kushwaha 		switch (wriop_get_enet_if(i)) {
9044937214SPrabhakar Kushwaha 		case PHY_INTERFACE_MODE_XGMII:
9144937214SPrabhakar Kushwaha 			dev = miiphy_get_dev_by_name(DEFAULT_WRIOP_MDIO2_NAME);
9244937214SPrabhakar Kushwaha 			wriop_set_mdio(i, dev);
9344937214SPrabhakar Kushwaha 			break;
9444937214SPrabhakar Kushwaha 		default:
9544937214SPrabhakar Kushwaha 			break;
9644937214SPrabhakar Kushwaha 		}
9744937214SPrabhakar Kushwaha 	}
9844937214SPrabhakar Kushwaha 
9944937214SPrabhakar Kushwaha 	cpu_eth_init(bis);
10033a8991aSBogdan Purcareata #endif /* CONFIG_FSL_MC_ENET */
10144937214SPrabhakar Kushwaha 
10244937214SPrabhakar Kushwaha #ifdef CONFIG_PHY_AQUANTIA
10344937214SPrabhakar Kushwaha 	/*
10444937214SPrabhakar Kushwaha 	 * Export functions to be used by AQ firmware
10544937214SPrabhakar Kushwaha 	 * upload application
10644937214SPrabhakar Kushwaha 	 */
10744937214SPrabhakar Kushwaha 	gd->jt->strcpy = strcpy;
10844937214SPrabhakar Kushwaha 	gd->jt->mdelay = mdelay;
10944937214SPrabhakar Kushwaha 	gd->jt->mdio_get_current_dev = mdio_get_current_dev;
11044937214SPrabhakar Kushwaha 	gd->jt->phy_find_by_mask = phy_find_by_mask;
11144937214SPrabhakar Kushwaha 	gd->jt->mdio_phydev_for_ethname = mdio_phydev_for_ethname;
11244937214SPrabhakar Kushwaha 	gd->jt->miiphy_set_current_dev = miiphy_set_current_dev;
11344937214SPrabhakar Kushwaha #endif
11444937214SPrabhakar Kushwaha 	return pci_eth_init(bis);
11544937214SPrabhakar Kushwaha }
11633a8991aSBogdan Purcareata 
11733a8991aSBogdan Purcareata #if defined(CONFIG_RESET_PHY_R)
reset_phy(void)11833a8991aSBogdan Purcareata void reset_phy(void)
11933a8991aSBogdan Purcareata {
12033a8991aSBogdan Purcareata 	mc_env_boot();
12133a8991aSBogdan Purcareata }
12233a8991aSBogdan Purcareata #endif /* CONFIG_RESET_PHY_R */
123