183d290c5STom 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
board_eth_init(bd_t * bis)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 */
58*1a048cd6SPankaj Bansal wriop_set_phy_address(WRIOP1_DPMAC1, 0, 0x0a);
59*1a048cd6SPankaj Bansal wriop_set_phy_address(WRIOP1_DPMAC2, 0, AQ_PHY_ADDR1);
60*1a048cd6SPankaj Bansal wriop_set_phy_address(WRIOP1_DPMAC3, 0, QSGMII1_PORT1_PHY_ADDR);
61*1a048cd6SPankaj Bansal wriop_set_phy_address(WRIOP1_DPMAC4, 0, QSGMII1_PORT2_PHY_ADDR);
62*1a048cd6SPankaj Bansal wriop_set_phy_address(WRIOP1_DPMAC5, 0, QSGMII1_PORT3_PHY_ADDR);
63*1a048cd6SPankaj Bansal wriop_set_phy_address(WRIOP1_DPMAC6, 0, QSGMII1_PORT4_PHY_ADDR);
64*1a048cd6SPankaj Bansal wriop_set_phy_address(WRIOP1_DPMAC7, 0, QSGMII2_PORT1_PHY_ADDR);
65*1a048cd6SPankaj Bansal wriop_set_phy_address(WRIOP1_DPMAC8, 0, QSGMII2_PORT2_PHY_ADDR);
66*1a048cd6SPankaj Bansal wriop_set_phy_address(WRIOP1_DPMAC9, 0, QSGMII2_PORT3_PHY_ADDR);
67*1a048cd6SPankaj Bansal wriop_set_phy_address(WRIOP1_DPMAC10, 0,
68*1a048cd6SPankaj Bansal QSGMII2_PORT4_PHY_ADDR);
69e84a324bSAshish Kumar
70e84a324bSAshish Kumar break;
71e84a324bSAshish Kumar default:
72e84a324bSAshish Kumar printf("SerDes1 protocol 0x%x is not supported on LS1088ARDB\n",
73e84a324bSAshish Kumar srds_s1);
74e84a324bSAshish Kumar break;
75e84a324bSAshish Kumar }
76e84a324bSAshish Kumar
77e84a324bSAshish Kumar for (i = WRIOP1_DPMAC3; i <= WRIOP1_DPMAC10; i++) {
78e84a324bSAshish Kumar interface = wriop_get_enet_if(i);
79e84a324bSAshish Kumar switch (interface) {
80e84a324bSAshish Kumar case PHY_INTERFACE_MODE_QSGMII:
81e84a324bSAshish Kumar dev = miiphy_get_dev_by_name(DEFAULT_WRIOP_MDIO1_NAME);
82e84a324bSAshish Kumar wriop_set_mdio(i, dev);
83e84a324bSAshish Kumar break;
84e84a324bSAshish Kumar default:
85e84a324bSAshish Kumar break;
86e84a324bSAshish Kumar }
87e84a324bSAshish Kumar }
88e84a324bSAshish Kumar
89e84a324bSAshish Kumar dev = miiphy_get_dev_by_name(DEFAULT_WRIOP_MDIO2_NAME);
90e84a324bSAshish Kumar wriop_set_mdio(WRIOP1_DPMAC2, dev);
91e84a324bSAshish Kumar
92e84a324bSAshish Kumar cpu_eth_init(bis);
93e84a324bSAshish Kumar #endif /* CONFIG_FMAN_ENET */
94e84a324bSAshish Kumar
95e84a324bSAshish Kumar return pci_eth_init(bis);
96e84a324bSAshish Kumar }
97c48deb90SBogdan Purcareata
98c48deb90SBogdan Purcareata #if defined(CONFIG_RESET_PHY_R)
reset_phy(void)99c48deb90SBogdan Purcareata void reset_phy(void)
100c48deb90SBogdan Purcareata {
101c48deb90SBogdan Purcareata mc_env_boot();
102c48deb90SBogdan Purcareata }
103c48deb90SBogdan Purcareata #endif /* CONFIG_RESET_PHY_R */
104