blob: 0731a795c87e47973422d3e19d8bc07824bc693e [file] [log] [blame]
Tom Rini10e47792018-05-06 17:58:06 -04001// SPDX-License-Identifier: GPL-2.0+
Prabhakar Kushwaha2dd335f2015-03-20 19:28:22 -07002/*
3 * Copyright (C) 2015 Freescale Semiconductor
Prabhakar Kushwaha2dd335f2015-03-20 19:28:22 -07004 */
5
6#include <common.h>
7#include <asm/io.h>
8#include <asm/types.h>
9#include <malloc.h>
10#include <net.h>
11#include <linux/compat.h>
12#include <asm/arch/fsl_serdes.h>
13#include <fsl-mc/ldpaa_wriop.h>
14
15struct wriop_dpmac_info dpmac_info[NUM_WRIOP_PORTS];
16
17__weak phy_interface_t wriop_dpmac_enet_if(int dpmac_id, int lane_prtc)
18{
19 return PHY_INTERFACE_MODE_NONE;
20}
21
22void wriop_init_dpmac(int sd, int dpmac_id, int lane_prtcl)
23{
24 phy_interface_t enet_if;
Prabhakar Kushwaha2dd335f2015-03-20 19:28:22 -070025
Prabhakar Kushwaha316de872015-11-04 12:25:52 +053026 dpmac_info[dpmac_id].enabled = 0;
27 dpmac_info[dpmac_id].id = 0;
Prabhakar Kushwahaef553102015-11-04 12:25:56 +053028 dpmac_info[dpmac_id].phy_addr = -1;
Prabhakar Kushwaha316de872015-11-04 12:25:52 +053029 dpmac_info[dpmac_id].enet_if = PHY_INTERFACE_MODE_NONE;
Prabhakar Kushwaha2dd335f2015-03-20 19:28:22 -070030
Prabhakar Kushwaha316de872015-11-04 12:25:52 +053031 enet_if = wriop_dpmac_enet_if(dpmac_id, lane_prtcl);
Prabhakar Kushwaha2dd335f2015-03-20 19:28:22 -070032 if (enet_if != PHY_INTERFACE_MODE_NONE) {
Prabhakar Kushwaha316de872015-11-04 12:25:52 +053033 dpmac_info[dpmac_id].enabled = 1;
34 dpmac_info[dpmac_id].id = dpmac_id;
35 dpmac_info[dpmac_id].enet_if = enet_if;
Prabhakar Kushwaha2dd335f2015-03-20 19:28:22 -070036 }
37}
38
Ashish Kumarec455e22017-08-31 16:37:31 +053039void wriop_init_dpmac_enet_if(int dpmac_id, phy_interface_t enet_if)
40{
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;
45}
46
47
Prabhakar Kushwaha2dd335f2015-03-20 19:28:22 -070048/*TODO what it do */
49static int wriop_dpmac_to_index(int dpmac_id)
50{
51 int i;
52
53 for (i = WRIOP1_DPMAC1; i < NUM_WRIOP_PORTS; i++) {
54 if (dpmac_info[i].id == dpmac_id)
55 return i;
56 }
57
58 return -1;
59}
60
61void wriop_disable_dpmac(int dpmac_id)
62{
63 int i = wriop_dpmac_to_index(dpmac_id);
64
65 if (i == -1)
66 return;
67
68 dpmac_info[i].enabled = 0;
69 wriop_dpmac_disable(dpmac_id);
70}
71
72void wriop_enable_dpmac(int dpmac_id)
73{
74 int i = wriop_dpmac_to_index(dpmac_id);
75
76 if (i == -1)
77 return;
78
79 dpmac_info[i].enabled = 1;
80 wriop_dpmac_enable(dpmac_id);
81}
82
Prabhakar Kushwahaef553102015-11-04 12:25:56 +053083u8 wriop_is_enabled_dpmac(int dpmac_id)
84{
85 int i = wriop_dpmac_to_index(dpmac_id);
86
87 if (i == -1)
88 return -1;
89
90 return dpmac_info[i].enabled;
91}
92
93
Prabhakar Kushwaha2dd335f2015-03-20 19:28:22 -070094void wriop_set_mdio(int dpmac_id, struct mii_dev *bus)
95{
96 int i = wriop_dpmac_to_index(dpmac_id);
97
98 if (i == -1)
99 return;
100
101 dpmac_info[i].bus = bus;
102}
103
104struct mii_dev *wriop_get_mdio(int dpmac_id)
105{
106 int i = wriop_dpmac_to_index(dpmac_id);
107
108 if (i == -1)
109 return NULL;
110
111 return dpmac_info[i].bus;
112}
113
114void wriop_set_phy_address(int dpmac_id, int address)
115{
116 int i = wriop_dpmac_to_index(dpmac_id);
117
118 if (i == -1)
119 return;
120
121 dpmac_info[i].phy_addr = address;
122}
123
124int wriop_get_phy_address(int dpmac_id)
125{
126 int i = wriop_dpmac_to_index(dpmac_id);
127
128 if (i == -1)
129 return -1;
130
131 return dpmac_info[i].phy_addr;
132}
133
134void wriop_set_phy_dev(int dpmac_id, struct phy_device *phydev)
135{
136 int i = wriop_dpmac_to_index(dpmac_id);
137
138 if (i == -1)
139 return;
140
141 dpmac_info[i].phydev = phydev;
142}
143
144struct phy_device *wriop_get_phy_dev(int dpmac_id)
145{
146 int i = wriop_dpmac_to_index(dpmac_id);
147
148 if (i == -1)
149 return NULL;
150
151 return dpmac_info[i].phydev;
152}
153
154phy_interface_t wriop_get_enet_if(int dpmac_id)
155{
156 int i = wriop_dpmac_to_index(dpmac_id);
157
158 if (i == -1)
159 return PHY_INTERFACE_MODE_NONE;
160
161 if (dpmac_info[i].enabled)
162 return dpmac_info[i].enet_if;
163
164 return PHY_INTERFACE_MODE_NONE;
165}