xref: /rk3399_rockchip-uboot/drivers/net/ldpaa_eth/ldpaa_wriop.c (revision 1ebbe4fcf75b15ccf23234bb6a7d28895a7e6b11)
1 /*
2  * Copyright (C) 2015 Freescale Semiconductor
3  *
4  * SPDX-License-Identifier:	GPL-2.0+
5  */
6 
7 #include <common.h>
8 #include <asm/io.h>
9 #include <asm/types.h>
10 #include <malloc.h>
11 #include <net.h>
12 #include <linux/compat.h>
13 #include <asm/arch/fsl_serdes.h>
14 #include <fsl-mc/ldpaa_wriop.h>
15 
16 struct wriop_dpmac_info dpmac_info[NUM_WRIOP_PORTS];
17 
18 __weak phy_interface_t wriop_dpmac_enet_if(int dpmac_id, int lane_prtc)
19 {
20 	return PHY_INTERFACE_MODE_NONE;
21 }
22 
23 void wriop_init_dpmac(int sd, int dpmac_id, int lane_prtcl)
24 {
25 	phy_interface_t enet_if;
26 
27 	dpmac_info[dpmac_id].enabled = 0;
28 	dpmac_info[dpmac_id].id = 0;
29 	dpmac_info[dpmac_id].enet_if = PHY_INTERFACE_MODE_NONE;
30 
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;
36 	}
37 }
38 
39 /*TODO what it do */
40 static int wriop_dpmac_to_index(int dpmac_id)
41 {
42 	int i;
43 
44 	for (i = WRIOP1_DPMAC1; i < NUM_WRIOP_PORTS; i++) {
45 		if (dpmac_info[i].id == dpmac_id)
46 			return i;
47 	}
48 
49 	return -1;
50 }
51 
52 void wriop_disable_dpmac(int dpmac_id)
53 {
54 	int i = wriop_dpmac_to_index(dpmac_id);
55 
56 	if (i == -1)
57 		return;
58 
59 	dpmac_info[i].enabled = 0;
60 	wriop_dpmac_disable(dpmac_id);
61 }
62 
63 void wriop_enable_dpmac(int dpmac_id)
64 {
65 	int i = wriop_dpmac_to_index(dpmac_id);
66 
67 	if (i == -1)
68 		return;
69 
70 	dpmac_info[i].enabled = 1;
71 	wriop_dpmac_enable(dpmac_id);
72 }
73 
74 void wriop_set_mdio(int dpmac_id, struct mii_dev *bus)
75 {
76 	int i = wriop_dpmac_to_index(dpmac_id);
77 
78 	if (i == -1)
79 		return;
80 
81 	dpmac_info[i].bus = bus;
82 }
83 
84 struct mii_dev *wriop_get_mdio(int dpmac_id)
85 {
86 	int i = wriop_dpmac_to_index(dpmac_id);
87 
88 	if (i == -1)
89 		return NULL;
90 
91 	return dpmac_info[i].bus;
92 }
93 
94 void wriop_set_phy_address(int dpmac_id, int address)
95 {
96 	int i = wriop_dpmac_to_index(dpmac_id);
97 
98 	if (i == -1)
99 		return;
100 
101 	dpmac_info[i].phy_addr = address;
102 }
103 
104 int wriop_get_phy_address(int dpmac_id)
105 {
106 	int i = wriop_dpmac_to_index(dpmac_id);
107 
108 	if (i == -1)
109 		return -1;
110 
111 	return dpmac_info[i].phy_addr;
112 }
113 
114 void wriop_set_phy_dev(int dpmac_id, struct phy_device *phydev)
115 {
116 	int i = wriop_dpmac_to_index(dpmac_id);
117 
118 	if (i == -1)
119 		return;
120 
121 	dpmac_info[i].phydev = phydev;
122 }
123 
124 struct phy_device *wriop_get_phy_dev(int dpmac_id)
125 {
126 	int i = wriop_dpmac_to_index(dpmac_id);
127 
128 	if (i == -1)
129 		return NULL;
130 
131 	return dpmac_info[i].phydev;
132 }
133 
134 phy_interface_t wriop_get_enet_if(int dpmac_id)
135 {
136 	int i = wriop_dpmac_to_index(dpmac_id);
137 
138 	if (i == -1)
139 		return PHY_INTERFACE_MODE_NONE;
140 
141 	if (dpmac_info[i].enabled)
142 		return dpmac_info[i].enet_if;
143 
144 	return PHY_INTERFACE_MODE_NONE;
145 }
146