1 // SPDX-License-Identifier: GPL-2.0+
3 * Copyright (C) 2015 Freescale Semiconductor
11 #include <linux/compat.h>
12 #include <asm/arch/fsl_serdes.h>
13 #include <fsl-mc/ldpaa_wriop.h>
15 struct wriop_dpmac_info dpmac_info[NUM_WRIOP_PORTS];
17 __weak phy_interface_t wriop_dpmac_enet_if(int dpmac_id, int lane_prtc)
19 return PHY_INTERFACE_MODE_NONE;
22 void wriop_init_dpmac(int sd, int dpmac_id, int lane_prtcl)
24 phy_interface_t enet_if;
26 dpmac_info[dpmac_id].enabled = 0;
27 dpmac_info[dpmac_id].id = 0;
28 dpmac_info[dpmac_id].phy_addr = -1;
29 dpmac_info[dpmac_id].enet_if = PHY_INTERFACE_MODE_NONE;
31 enet_if = wriop_dpmac_enet_if(dpmac_id, lane_prtcl);
32 if (enet_if != PHY_INTERFACE_MODE_NONE) {
33 dpmac_info[dpmac_id].enabled = 1;
34 dpmac_info[dpmac_id].id = dpmac_id;
35 dpmac_info[dpmac_id].enet_if = enet_if;
39 void wriop_init_dpmac_enet_if(int dpmac_id, phy_interface_t enet_if)
41 dpmac_info[dpmac_id].enabled = 1;
42 dpmac_info[dpmac_id].id = dpmac_id;
43 dpmac_info[dpmac_id].phy_addr = -1;
44 dpmac_info[dpmac_id].enet_if = enet_if;
49 static int wriop_dpmac_to_index(int dpmac_id)
53 for (i = WRIOP1_DPMAC1; i < NUM_WRIOP_PORTS; i++) {
54 if (dpmac_info[i].id == dpmac_id)
61 void wriop_disable_dpmac(int dpmac_id)
63 int i = wriop_dpmac_to_index(dpmac_id);
68 dpmac_info[i].enabled = 0;
69 wriop_dpmac_disable(dpmac_id);
72 void wriop_enable_dpmac(int dpmac_id)
74 int i = wriop_dpmac_to_index(dpmac_id);
79 dpmac_info[i].enabled = 1;
80 wriop_dpmac_enable(dpmac_id);
83 u8 wriop_is_enabled_dpmac(int dpmac_id)
85 int i = wriop_dpmac_to_index(dpmac_id);
90 return dpmac_info[i].enabled;
94 void wriop_set_mdio(int dpmac_id, struct mii_dev *bus)
96 int i = wriop_dpmac_to_index(dpmac_id);
101 dpmac_info[i].bus = bus;
104 struct mii_dev *wriop_get_mdio(int dpmac_id)
106 int i = wriop_dpmac_to_index(dpmac_id);
111 return dpmac_info[i].bus;
114 void wriop_set_phy_address(int dpmac_id, int address)
116 int i = wriop_dpmac_to_index(dpmac_id);
121 dpmac_info[i].phy_addr = address;
124 int wriop_get_phy_address(int dpmac_id)
126 int i = wriop_dpmac_to_index(dpmac_id);
131 return dpmac_info[i].phy_addr;
134 void wriop_set_phy_dev(int dpmac_id, struct phy_device *phydev)
136 int i = wriop_dpmac_to_index(dpmac_id);
141 dpmac_info[i].phydev = phydev;
144 struct phy_device *wriop_get_phy_dev(int dpmac_id)
146 int i = wriop_dpmac_to_index(dpmac_id);
151 return dpmac_info[i].phydev;
154 phy_interface_t wriop_get_enet_if(int dpmac_id)
156 int i = wriop_dpmac_to_index(dpmac_id);
159 return PHY_INTERFACE_MODE_NONE;
161 if (dpmac_info[i].enabled)
162 return dpmac_info[i].enet_if;
164 return PHY_INTERFACE_MODE_NONE;