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