xref: /openbmc/u-boot/board/freescale/ls1088a/eth_ls1088ardb.c (revision 83d290c56fab2d38cd1ab4c4cc7099559c1d5046)
1*83d290c5STom Rini // SPDX-License-Identifier: GPL-2.0+
2e84a324bSAshish Kumar /*
3e84a324bSAshish Kumar  * Copyright 2017 NXP
4e84a324bSAshish Kumar  */
5e84a324bSAshish Kumar 
6e84a324bSAshish Kumar #include <common.h>
7e84a324bSAshish Kumar #include <command.h>
8e84a324bSAshish Kumar #include <netdev.h>
9e84a324bSAshish Kumar #include <malloc.h>
10e84a324bSAshish Kumar #include <fsl_mdio.h>
11e84a324bSAshish Kumar #include <miiphy.h>
12e84a324bSAshish Kumar #include <phy.h>
13e84a324bSAshish Kumar #include <fm_eth.h>
14e84a324bSAshish Kumar #include <asm/io.h>
15e84a324bSAshish Kumar #include <exports.h>
16e84a324bSAshish Kumar #include <asm/arch/fsl_serdes.h>
17c48deb90SBogdan Purcareata #include <fsl-mc/fsl_mc.h>
18e84a324bSAshish Kumar #include <fsl-mc/ldpaa_wriop.h>
19e84a324bSAshish Kumar 
20e84a324bSAshish Kumar int board_eth_init(bd_t *bis)
21e84a324bSAshish Kumar {
22e84a324bSAshish Kumar #if defined(CONFIG_FSL_MC_ENET)
23e84a324bSAshish Kumar 	int i, interface;
24e84a324bSAshish Kumar 	struct memac_mdio_info mdio_info;
25e84a324bSAshish Kumar 	struct mii_dev *dev;
26e84a324bSAshish Kumar 	struct ccsr_gur *gur = (void *)(CONFIG_SYS_FSL_GUTS_ADDR);
27e84a324bSAshish Kumar 	struct memac_mdio_controller *reg;
28e84a324bSAshish Kumar 	u32 srds_s1, cfg;
29e84a324bSAshish Kumar 
30e84a324bSAshish Kumar 	cfg = in_le32(&gur->rcwsr[FSL_CHASSIS3_SRDS1_REGSR - 1]) &
31e84a324bSAshish Kumar 				FSL_CHASSIS3_SRDS1_PRTCL_MASK;
32e84a324bSAshish Kumar 	cfg >>= FSL_CHASSIS3_SRDS1_PRTCL_SHIFT;
33e84a324bSAshish Kumar 
34e84a324bSAshish Kumar 	srds_s1 = serdes_get_number(FSL_SRDS_1, cfg);
35e84a324bSAshish Kumar 
36e84a324bSAshish Kumar 	reg = (struct memac_mdio_controller *)CONFIG_SYS_FSL_WRIOP1_MDIO1;
37e84a324bSAshish Kumar 	mdio_info.regs = reg;
38e84a324bSAshish Kumar 	mdio_info.name = DEFAULT_WRIOP_MDIO1_NAME;
39e84a324bSAshish Kumar 
40e84a324bSAshish Kumar 	/* Register the EMI 1 */
41e84a324bSAshish Kumar 	fm_memac_mdio_init(bis, &mdio_info);
42e84a324bSAshish Kumar 
43e84a324bSAshish Kumar 	reg = (struct memac_mdio_controller *)CONFIG_SYS_FSL_WRIOP1_MDIO2;
44e84a324bSAshish Kumar 	mdio_info.regs = reg;
45e84a324bSAshish Kumar 	mdio_info.name = DEFAULT_WRIOP_MDIO2_NAME;
46e84a324bSAshish Kumar 
47e84a324bSAshish Kumar 	/* Register the EMI 2 */
48e84a324bSAshish Kumar 	fm_memac_mdio_init(bis, &mdio_info);
49e84a324bSAshish Kumar 
50e84a324bSAshish Kumar 	switch (srds_s1) {
51e84a324bSAshish Kumar 	case 0x1D:
52e84a324bSAshish Kumar 		/*
53e84a324bSAshish Kumar 		 * XFI does not need a PHY to work, but to avoid U-boot use
54e84a324bSAshish Kumar 		 * default PHY address which is zero to a MAC when it found
55e84a324bSAshish Kumar 		 * a MAC has no PHY address, we give a PHY address to XFI
56e84a324bSAshish Kumar 		 * MAC error.
57e84a324bSAshish Kumar 		 */
58e84a324bSAshish Kumar 		wriop_set_phy_address(WRIOP1_DPMAC1, 0x0a);
59e84a324bSAshish Kumar 		wriop_set_phy_address(WRIOP1_DPMAC2, AQ_PHY_ADDR1);
60e84a324bSAshish Kumar 		wriop_set_phy_address(WRIOP1_DPMAC3, QSGMII1_PORT1_PHY_ADDR);
61e84a324bSAshish Kumar 		wriop_set_phy_address(WRIOP1_DPMAC4, QSGMII1_PORT2_PHY_ADDR);
62e84a324bSAshish Kumar 		wriop_set_phy_address(WRIOP1_DPMAC5, QSGMII1_PORT3_PHY_ADDR);
63e84a324bSAshish Kumar 		wriop_set_phy_address(WRIOP1_DPMAC6, QSGMII1_PORT4_PHY_ADDR);
64e84a324bSAshish Kumar 		wriop_set_phy_address(WRIOP1_DPMAC7, QSGMII2_PORT1_PHY_ADDR);
65e84a324bSAshish Kumar 		wriop_set_phy_address(WRIOP1_DPMAC8, QSGMII2_PORT2_PHY_ADDR);
66e84a324bSAshish Kumar 		wriop_set_phy_address(WRIOP1_DPMAC9, QSGMII2_PORT3_PHY_ADDR);
67e84a324bSAshish Kumar 		wriop_set_phy_address(WRIOP1_DPMAC10, QSGMII2_PORT4_PHY_ADDR);
68e84a324bSAshish Kumar 
69e84a324bSAshish Kumar 		break;
70e84a324bSAshish Kumar 	default:
71e84a324bSAshish Kumar 		printf("SerDes1 protocol 0x%x is not supported on LS1088ARDB\n",
72e84a324bSAshish Kumar 		       srds_s1);
73e84a324bSAshish Kumar 		break;
74e84a324bSAshish Kumar 	}
75e84a324bSAshish Kumar 
76e84a324bSAshish Kumar 	for (i = WRIOP1_DPMAC3; i <= WRIOP1_DPMAC10; i++) {
77e84a324bSAshish Kumar 		interface = wriop_get_enet_if(i);
78e84a324bSAshish Kumar 		switch (interface) {
79e84a324bSAshish Kumar 		case PHY_INTERFACE_MODE_QSGMII:
80e84a324bSAshish Kumar 			dev = miiphy_get_dev_by_name(DEFAULT_WRIOP_MDIO1_NAME);
81e84a324bSAshish Kumar 			wriop_set_mdio(i, dev);
82e84a324bSAshish Kumar 			break;
83e84a324bSAshish Kumar 		default:
84e84a324bSAshish Kumar 			break;
85e84a324bSAshish Kumar 		}
86e84a324bSAshish Kumar 	}
87e84a324bSAshish Kumar 
88e84a324bSAshish Kumar 	dev = miiphy_get_dev_by_name(DEFAULT_WRIOP_MDIO2_NAME);
89e84a324bSAshish Kumar 	wriop_set_mdio(WRIOP1_DPMAC2, dev);
90e84a324bSAshish Kumar 
91e84a324bSAshish Kumar 	cpu_eth_init(bis);
92e84a324bSAshish Kumar #endif /* CONFIG_FMAN_ENET */
93e84a324bSAshish Kumar 
94e84a324bSAshish Kumar 	return pci_eth_init(bis);
95e84a324bSAshish Kumar }
96c48deb90SBogdan Purcareata 
97c48deb90SBogdan Purcareata #if defined(CONFIG_RESET_PHY_R)
98c48deb90SBogdan Purcareata void reset_phy(void)
99c48deb90SBogdan Purcareata {
100c48deb90SBogdan Purcareata 	mc_env_boot();
101c48deb90SBogdan Purcareata }
102c48deb90SBogdan Purcareata #endif /* CONFIG_RESET_PHY_R */
103