blob: 831a3300701ea6dc9813334b213ad83d5701254f [file] [log] [blame]
Prabhakar Kushwaha2dd335f2015-03-20 19:28:22 -07001/*
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
16struct 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
23void wriop_init_dpmac(int sd, int dpmac_id, int lane_prtcl)
24{
25 phy_interface_t enet_if;
Prabhakar Kushwaha2dd335f2015-03-20 19:28:22 -070026
Prabhakar Kushwaha316de872015-11-04 12:25:52 +053027 dpmac_info[dpmac_id].enabled = 0;
28 dpmac_info[dpmac_id].id = 0;
Prabhakar Kushwahaef553102015-11-04 12:25:56 +053029 dpmac_info[dpmac_id].phy_addr = -1;
Prabhakar Kushwaha316de872015-11-04 12:25:52 +053030 dpmac_info[dpmac_id].enet_if = PHY_INTERFACE_MODE_NONE;
Prabhakar Kushwaha2dd335f2015-03-20 19:28:22 -070031
Prabhakar Kushwaha316de872015-11-04 12:25:52 +053032 enet_if = wriop_dpmac_enet_if(dpmac_id, lane_prtcl);
Prabhakar Kushwaha2dd335f2015-03-20 19:28:22 -070033 if (enet_if != PHY_INTERFACE_MODE_NONE) {
Prabhakar Kushwaha316de872015-11-04 12:25:52 +053034 dpmac_info[dpmac_id].enabled = 1;
35 dpmac_info[dpmac_id].id = dpmac_id;
36 dpmac_info[dpmac_id].enet_if = enet_if;
Prabhakar Kushwaha2dd335f2015-03-20 19:28:22 -070037 }
38}
39
Ashish Kumarec455e22017-08-31 16:37:31 +053040void wriop_init_dpmac_enet_if(int dpmac_id, phy_interface_t enet_if)
41{
42 dpmac_info[dpmac_id].enabled = 1;
43 dpmac_info[dpmac_id].id = dpmac_id;
44 dpmac_info[dpmac_id].phy_addr = -1;
45 dpmac_info[dpmac_id].enet_if = enet_if;
46}
47
48
Prabhakar Kushwaha2dd335f2015-03-20 19:28:22 -070049/*TODO what it do */
50static int wriop_dpmac_to_index(int dpmac_id)
51{
52 int i;
53
54 for (i = WRIOP1_DPMAC1; i < NUM_WRIOP_PORTS; i++) {
55 if (dpmac_info[i].id == dpmac_id)
56 return i;
57 }
58
59 return -1;
60}
61
62void wriop_disable_dpmac(int dpmac_id)
63{
64 int i = wriop_dpmac_to_index(dpmac_id);
65
66 if (i == -1)
67 return;
68
69 dpmac_info[i].enabled = 0;
70 wriop_dpmac_disable(dpmac_id);
71}
72
73void wriop_enable_dpmac(int dpmac_id)
74{
75 int i = wriop_dpmac_to_index(dpmac_id);
76
77 if (i == -1)
78 return;
79
80 dpmac_info[i].enabled = 1;
81 wriop_dpmac_enable(dpmac_id);
82}
83
Prabhakar Kushwahaef553102015-11-04 12:25:56 +053084u8 wriop_is_enabled_dpmac(int dpmac_id)
85{
86 int i = wriop_dpmac_to_index(dpmac_id);
87
88 if (i == -1)
89 return -1;
90
91 return dpmac_info[i].enabled;
92}
93
94
Prabhakar Kushwaha2dd335f2015-03-20 19:28:22 -070095void wriop_set_mdio(int dpmac_id, struct mii_dev *bus)
96{
97 int i = wriop_dpmac_to_index(dpmac_id);
98
99 if (i == -1)
100 return;
101
102 dpmac_info[i].bus = bus;
103}
104
105struct mii_dev *wriop_get_mdio(int dpmac_id)
106{
107 int i = wriop_dpmac_to_index(dpmac_id);
108
109 if (i == -1)
110 return NULL;
111
112 return dpmac_info[i].bus;
113}
114
115void wriop_set_phy_address(int dpmac_id, int address)
116{
117 int i = wriop_dpmac_to_index(dpmac_id);
118
119 if (i == -1)
120 return;
121
122 dpmac_info[i].phy_addr = address;
123}
124
125int wriop_get_phy_address(int dpmac_id)
126{
127 int i = wriop_dpmac_to_index(dpmac_id);
128
129 if (i == -1)
130 return -1;
131
132 return dpmac_info[i].phy_addr;
133}
134
135void wriop_set_phy_dev(int dpmac_id, struct phy_device *phydev)
136{
137 int i = wriop_dpmac_to_index(dpmac_id);
138
139 if (i == -1)
140 return;
141
142 dpmac_info[i].phydev = phydev;
143}
144
145struct phy_device *wriop_get_phy_dev(int dpmac_id)
146{
147 int i = wriop_dpmac_to_index(dpmac_id);
148
149 if (i == -1)
150 return NULL;
151
152 return dpmac_info[i].phydev;
153}
154
155phy_interface_t wriop_get_enet_if(int dpmac_id)
156{
157 int i = wriop_dpmac_to_index(dpmac_id);
158
159 if (i == -1)
160 return PHY_INTERFACE_MODE_NONE;
161
162 if (dpmac_info[i].enabled)
163 return dpmac_info[i].enet_if;
164
165 return PHY_INTERFACE_MODE_NONE;
166}