blob: 758759240e078b3b9a34cb3725daaf1c5173c331 [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
Prabhakar Kushwaha2dd335f2015-03-20 19:28:22 -07006#include <asm/io.h>
7#include <asm/types.h>
8#include <malloc.h>
9#include <net.h>
10#include <linux/compat.h>
11#include <asm/arch/fsl_serdes.h>
12#include <fsl-mc/ldpaa_wriop.h>
13
14struct wriop_dpmac_info dpmac_info[NUM_WRIOP_PORTS];
15
16__weak phy_interface_t wriop_dpmac_enet_if(int dpmac_id, int lane_prtc)
17{
Marek Behún48631e42022-04-07 00:33:03 +020018 return PHY_INTERFACE_MODE_NA;
Prabhakar Kushwaha2dd335f2015-03-20 19:28:22 -070019}
20
21void wriop_init_dpmac(int sd, int dpmac_id, int lane_prtcl)
22{
23 phy_interface_t enet_if;
Pankaj Bansal50adb5e2018-10-10 14:08:34 +053024 int phy_num;
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;
Marek Behún48631e42022-04-07 00:33:03 +020028 dpmac_info[dpmac_id].enet_if = PHY_INTERFACE_MODE_NA;
Prabhakar Kushwaha2dd335f2015-03-20 19:28:22 -070029
Prabhakar Kushwaha316de872015-11-04 12:25:52 +053030 enet_if = wriop_dpmac_enet_if(dpmac_id, lane_prtcl);
Marek Behún48631e42022-04-07 00:33:03 +020031 if (enet_if != PHY_INTERFACE_MODE_NA) {
Prabhakar Kushwaha316de872015-11-04 12:25:52 +053032 dpmac_info[dpmac_id].enabled = 1;
33 dpmac_info[dpmac_id].id = dpmac_id;
34 dpmac_info[dpmac_id].enet_if = enet_if;
Prabhakar Kushwaha2dd335f2015-03-20 19:28:22 -070035 }
Pankaj Bansal50adb5e2018-10-10 14:08:34 +053036 for (phy_num = 0; phy_num < WRIOP_MAX_PHY_NUM; phy_num++) {
37 dpmac_info[dpmac_id].phydev[phy_num] = NULL;
38 dpmac_info[dpmac_id].phy_addr[phy_num] = -1;
39 }
Prabhakar Kushwaha2dd335f2015-03-20 19:28:22 -070040}
41
Ashish Kumarec455e22017-08-31 16:37:31 +053042void wriop_init_dpmac_enet_if(int dpmac_id, phy_interface_t enet_if)
43{
Pankaj Bansal50adb5e2018-10-10 14:08:34 +053044 int phy_num;
45
Ashish Kumarec455e22017-08-31 16:37:31 +053046 dpmac_info[dpmac_id].enabled = 1;
47 dpmac_info[dpmac_id].id = dpmac_id;
Ashish Kumarec455e22017-08-31 16:37:31 +053048 dpmac_info[dpmac_id].enet_if = enet_if;
Pankaj Bansal50adb5e2018-10-10 14:08:34 +053049 for (phy_num = 0; phy_num < WRIOP_MAX_PHY_NUM; phy_num++) {
50 dpmac_info[dpmac_id].phydev[phy_num] = NULL;
51 dpmac_info[dpmac_id].phy_addr[phy_num] = -1;
52 }
Ashish Kumarec455e22017-08-31 16:37:31 +053053}
54
Prabhakar Kushwaha2dd335f2015-03-20 19:28:22 -070055/*TODO what it do */
56static int wriop_dpmac_to_index(int dpmac_id)
57{
58 int i;
59
60 for (i = WRIOP1_DPMAC1; i < NUM_WRIOP_PORTS; i++) {
61 if (dpmac_info[i].id == dpmac_id)
62 return i;
63 }
64
65 return -1;
66}
67
Pankaj Bansal50adb5e2018-10-10 14:08:34 +053068int wriop_disable_dpmac(int dpmac_id)
Prabhakar Kushwaha2dd335f2015-03-20 19:28:22 -070069{
70 int i = wriop_dpmac_to_index(dpmac_id);
71
72 if (i == -1)
Pankaj Bansal50adb5e2018-10-10 14:08:34 +053073 return -ENODEV;
Prabhakar Kushwaha2dd335f2015-03-20 19:28:22 -070074
75 dpmac_info[i].enabled = 0;
76 wriop_dpmac_disable(dpmac_id);
Pankaj Bansal50adb5e2018-10-10 14:08:34 +053077
78 return 0;
Prabhakar Kushwaha2dd335f2015-03-20 19:28:22 -070079}
80
Pankaj Bansal50adb5e2018-10-10 14:08:34 +053081int wriop_enable_dpmac(int dpmac_id)
Prabhakar Kushwaha2dd335f2015-03-20 19:28:22 -070082{
83 int i = wriop_dpmac_to_index(dpmac_id);
84
85 if (i == -1)
Pankaj Bansal50adb5e2018-10-10 14:08:34 +053086 return -ENODEV;
Prabhakar Kushwaha2dd335f2015-03-20 19:28:22 -070087
88 dpmac_info[i].enabled = 1;
89 wriop_dpmac_enable(dpmac_id);
Pankaj Bansal50adb5e2018-10-10 14:08:34 +053090
91 return 0;
Prabhakar Kushwaha2dd335f2015-03-20 19:28:22 -070092}
93
Pankaj Bansal50adb5e2018-10-10 14:08:34 +053094int wriop_is_enabled_dpmac(int dpmac_id)
Prabhakar Kushwahaef553102015-11-04 12:25:56 +053095{
96 int i = wriop_dpmac_to_index(dpmac_id);
97
98 if (i == -1)
Pankaj Bansal50adb5e2018-10-10 14:08:34 +053099 return -ENODEV;
Prabhakar Kushwahaef553102015-11-04 12:25:56 +0530100
101 return dpmac_info[i].enabled;
102}
103
Pankaj Bansal50adb5e2018-10-10 14:08:34 +0530104int wriop_set_mdio(int dpmac_id, struct mii_dev *bus)
Prabhakar Kushwaha2dd335f2015-03-20 19:28:22 -0700105{
106 int i = wriop_dpmac_to_index(dpmac_id);
107
108 if (i == -1)
Pankaj Bansal50adb5e2018-10-10 14:08:34 +0530109 return -ENODEV;
Prabhakar Kushwaha2dd335f2015-03-20 19:28:22 -0700110
111 dpmac_info[i].bus = bus;
Pankaj Bansal50adb5e2018-10-10 14:08:34 +0530112
113 return 0;
Prabhakar Kushwaha2dd335f2015-03-20 19:28:22 -0700114}
115
116struct mii_dev *wriop_get_mdio(int dpmac_id)
117{
118 int i = wriop_dpmac_to_index(dpmac_id);
119
120 if (i == -1)
121 return NULL;
122
123 return dpmac_info[i].bus;
124}
125
Pankaj Bansal50adb5e2018-10-10 14:08:34 +0530126int wriop_set_phy_address(int dpmac_id, int phy_num, int address)
Prabhakar Kushwaha2dd335f2015-03-20 19:28:22 -0700127{
128 int i = wriop_dpmac_to_index(dpmac_id);
129
130 if (i == -1)
Pankaj Bansal50adb5e2018-10-10 14:08:34 +0530131 return -ENODEV;
132 if (phy_num < 0 || phy_num >= WRIOP_MAX_PHY_NUM)
133 return -EINVAL;
134
135 dpmac_info[i].phy_addr[phy_num] = address;
Prabhakar Kushwaha2dd335f2015-03-20 19:28:22 -0700136
Pankaj Bansal50adb5e2018-10-10 14:08:34 +0530137 return 0;
Prabhakar Kushwaha2dd335f2015-03-20 19:28:22 -0700138}
139
Pankaj Bansal50adb5e2018-10-10 14:08:34 +0530140int wriop_get_phy_address(int dpmac_id, int phy_num)
Prabhakar Kushwaha2dd335f2015-03-20 19:28:22 -0700141{
142 int i = wriop_dpmac_to_index(dpmac_id);
143
144 if (i == -1)
Pankaj Bansal50adb5e2018-10-10 14:08:34 +0530145 return -ENODEV;
146 if (phy_num < 0 || phy_num >= WRIOP_MAX_PHY_NUM)
147 return -EINVAL;
Prabhakar Kushwaha2dd335f2015-03-20 19:28:22 -0700148
Pankaj Bansal50adb5e2018-10-10 14:08:34 +0530149 return dpmac_info[i].phy_addr[phy_num];
Prabhakar Kushwaha2dd335f2015-03-20 19:28:22 -0700150}
151
Pankaj Bansal50adb5e2018-10-10 14:08:34 +0530152int wriop_set_phy_dev(int dpmac_id, int phy_num, struct phy_device *phydev)
Prabhakar Kushwaha2dd335f2015-03-20 19:28:22 -0700153{
154 int i = wriop_dpmac_to_index(dpmac_id);
155
156 if (i == -1)
Pankaj Bansal50adb5e2018-10-10 14:08:34 +0530157 return -ENODEV;
158 if (phy_num < 0 || phy_num >= WRIOP_MAX_PHY_NUM)
159 return -EINVAL;
Prabhakar Kushwaha2dd335f2015-03-20 19:28:22 -0700160
Pankaj Bansal50adb5e2018-10-10 14:08:34 +0530161 dpmac_info[i].phydev[phy_num] = phydev;
162
163 return 0;
Prabhakar Kushwaha2dd335f2015-03-20 19:28:22 -0700164}
165
Pankaj Bansal50adb5e2018-10-10 14:08:34 +0530166struct phy_device *wriop_get_phy_dev(int dpmac_id, int phy_num)
Prabhakar Kushwaha2dd335f2015-03-20 19:28:22 -0700167{
168 int i = wriop_dpmac_to_index(dpmac_id);
169
170 if (i == -1)
171 return NULL;
Pankaj Bansal50adb5e2018-10-10 14:08:34 +0530172 if (phy_num < 0 || phy_num >= WRIOP_MAX_PHY_NUM)
173 return NULL;
Prabhakar Kushwaha2dd335f2015-03-20 19:28:22 -0700174
Pankaj Bansal50adb5e2018-10-10 14:08:34 +0530175 return dpmac_info[i].phydev[phy_num];
Prabhakar Kushwaha2dd335f2015-03-20 19:28:22 -0700176}
177
178phy_interface_t wriop_get_enet_if(int dpmac_id)
179{
180 int i = wriop_dpmac_to_index(dpmac_id);
181
182 if (i == -1)
Marek Behún48631e42022-04-07 00:33:03 +0200183 return PHY_INTERFACE_MODE_NA;
Prabhakar Kushwaha2dd335f2015-03-20 19:28:22 -0700184
185 if (dpmac_info[i].enabled)
186 return dpmac_info[i].enet_if;
187
Marek Behún48631e42022-04-07 00:33:03 +0200188 return PHY_INTERFACE_MODE_NA;
Prabhakar Kushwaha2dd335f2015-03-20 19:28:22 -0700189}