blob: adecb8135764f97087d7f79c419a86784c16e16f [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
Tom Riniabb9a042024-05-18 20:20:43 -06006#include <common.h>
Prabhakar Kushwaha2dd335f2015-03-20 19:28:22 -07007#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{
Marek Behún48631e42022-04-07 00:33:03 +020019 return PHY_INTERFACE_MODE_NA;
Prabhakar Kushwaha2dd335f2015-03-20 19:28:22 -070020}
21
22void wriop_init_dpmac(int sd, int dpmac_id, int lane_prtcl)
23{
24 phy_interface_t enet_if;
Pankaj Bansal50adb5e2018-10-10 14:08:34 +053025 int phy_num;
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;
Marek Behún48631e42022-04-07 00:33:03 +020029 dpmac_info[dpmac_id].enet_if = PHY_INTERFACE_MODE_NA;
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);
Marek Behún48631e42022-04-07 00:33:03 +020032 if (enet_if != PHY_INTERFACE_MODE_NA) {
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 }
Pankaj Bansal50adb5e2018-10-10 14:08:34 +053037 for (phy_num = 0; phy_num < WRIOP_MAX_PHY_NUM; phy_num++) {
38 dpmac_info[dpmac_id].phydev[phy_num] = NULL;
39 dpmac_info[dpmac_id].phy_addr[phy_num] = -1;
40 }
Prabhakar Kushwaha2dd335f2015-03-20 19:28:22 -070041}
42
Ashish Kumarec455e22017-08-31 16:37:31 +053043void wriop_init_dpmac_enet_if(int dpmac_id, phy_interface_t enet_if)
44{
Pankaj Bansal50adb5e2018-10-10 14:08:34 +053045 int phy_num;
46
Ashish Kumarec455e22017-08-31 16:37:31 +053047 dpmac_info[dpmac_id].enabled = 1;
48 dpmac_info[dpmac_id].id = dpmac_id;
Ashish Kumarec455e22017-08-31 16:37:31 +053049 dpmac_info[dpmac_id].enet_if = enet_if;
Pankaj Bansal50adb5e2018-10-10 14:08:34 +053050 for (phy_num = 0; phy_num < WRIOP_MAX_PHY_NUM; phy_num++) {
51 dpmac_info[dpmac_id].phydev[phy_num] = NULL;
52 dpmac_info[dpmac_id].phy_addr[phy_num] = -1;
53 }
Ashish Kumarec455e22017-08-31 16:37:31 +053054}
55
56
Prabhakar Kushwaha2dd335f2015-03-20 19:28:22 -070057/*TODO what it do */
58static int wriop_dpmac_to_index(int dpmac_id)
59{
60 int i;
61
62 for (i = WRIOP1_DPMAC1; i < NUM_WRIOP_PORTS; i++) {
63 if (dpmac_info[i].id == dpmac_id)
64 return i;
65 }
66
67 return -1;
68}
69
Pankaj Bansal50adb5e2018-10-10 14:08:34 +053070int wriop_disable_dpmac(int dpmac_id)
Prabhakar Kushwaha2dd335f2015-03-20 19:28:22 -070071{
72 int i = wriop_dpmac_to_index(dpmac_id);
73
74 if (i == -1)
Pankaj Bansal50adb5e2018-10-10 14:08:34 +053075 return -ENODEV;
Prabhakar Kushwaha2dd335f2015-03-20 19:28:22 -070076
77 dpmac_info[i].enabled = 0;
78 wriop_dpmac_disable(dpmac_id);
Pankaj Bansal50adb5e2018-10-10 14:08:34 +053079
80 return 0;
Prabhakar Kushwaha2dd335f2015-03-20 19:28:22 -070081}
82
Pankaj Bansal50adb5e2018-10-10 14:08:34 +053083int wriop_enable_dpmac(int dpmac_id)
Prabhakar Kushwaha2dd335f2015-03-20 19:28:22 -070084{
85 int i = wriop_dpmac_to_index(dpmac_id);
86
87 if (i == -1)
Pankaj Bansal50adb5e2018-10-10 14:08:34 +053088 return -ENODEV;
Prabhakar Kushwaha2dd335f2015-03-20 19:28:22 -070089
90 dpmac_info[i].enabled = 1;
91 wriop_dpmac_enable(dpmac_id);
Pankaj Bansal50adb5e2018-10-10 14:08:34 +053092
93 return 0;
Prabhakar Kushwaha2dd335f2015-03-20 19:28:22 -070094}
95
Pankaj Bansal50adb5e2018-10-10 14:08:34 +053096int wriop_is_enabled_dpmac(int dpmac_id)
Prabhakar Kushwahaef553102015-11-04 12:25:56 +053097{
98 int i = wriop_dpmac_to_index(dpmac_id);
99
100 if (i == -1)
Pankaj Bansal50adb5e2018-10-10 14:08:34 +0530101 return -ENODEV;
Prabhakar Kushwahaef553102015-11-04 12:25:56 +0530102
103 return dpmac_info[i].enabled;
104}
105
106
Pankaj Bansal50adb5e2018-10-10 14:08:34 +0530107int wriop_set_mdio(int dpmac_id, struct mii_dev *bus)
Prabhakar Kushwaha2dd335f2015-03-20 19:28:22 -0700108{
109 int i = wriop_dpmac_to_index(dpmac_id);
110
111 if (i == -1)
Pankaj Bansal50adb5e2018-10-10 14:08:34 +0530112 return -ENODEV;
Prabhakar Kushwaha2dd335f2015-03-20 19:28:22 -0700113
114 dpmac_info[i].bus = bus;
Pankaj Bansal50adb5e2018-10-10 14:08:34 +0530115
116 return 0;
Prabhakar Kushwaha2dd335f2015-03-20 19:28:22 -0700117}
118
119struct mii_dev *wriop_get_mdio(int dpmac_id)
120{
121 int i = wriop_dpmac_to_index(dpmac_id);
122
123 if (i == -1)
124 return NULL;
125
126 return dpmac_info[i].bus;
127}
128
Pankaj Bansal50adb5e2018-10-10 14:08:34 +0530129int wriop_set_phy_address(int dpmac_id, int phy_num, int address)
Prabhakar Kushwaha2dd335f2015-03-20 19:28:22 -0700130{
131 int i = wriop_dpmac_to_index(dpmac_id);
132
133 if (i == -1)
Pankaj Bansal50adb5e2018-10-10 14:08:34 +0530134 return -ENODEV;
135 if (phy_num < 0 || phy_num >= WRIOP_MAX_PHY_NUM)
136 return -EINVAL;
137
138 dpmac_info[i].phy_addr[phy_num] = address;
Prabhakar Kushwaha2dd335f2015-03-20 19:28:22 -0700139
Pankaj Bansal50adb5e2018-10-10 14:08:34 +0530140 return 0;
Prabhakar Kushwaha2dd335f2015-03-20 19:28:22 -0700141}
142
Pankaj Bansal50adb5e2018-10-10 14:08:34 +0530143int wriop_get_phy_address(int dpmac_id, int phy_num)
Prabhakar Kushwaha2dd335f2015-03-20 19:28:22 -0700144{
145 int i = wriop_dpmac_to_index(dpmac_id);
146
147 if (i == -1)
Pankaj Bansal50adb5e2018-10-10 14:08:34 +0530148 return -ENODEV;
149 if (phy_num < 0 || phy_num >= WRIOP_MAX_PHY_NUM)
150 return -EINVAL;
Prabhakar Kushwaha2dd335f2015-03-20 19:28:22 -0700151
Pankaj Bansal50adb5e2018-10-10 14:08:34 +0530152 return dpmac_info[i].phy_addr[phy_num];
Prabhakar Kushwaha2dd335f2015-03-20 19:28:22 -0700153}
154
Pankaj Bansal50adb5e2018-10-10 14:08:34 +0530155int wriop_set_phy_dev(int dpmac_id, int phy_num, struct phy_device *phydev)
Prabhakar Kushwaha2dd335f2015-03-20 19:28:22 -0700156{
157 int i = wriop_dpmac_to_index(dpmac_id);
158
159 if (i == -1)
Pankaj Bansal50adb5e2018-10-10 14:08:34 +0530160 return -ENODEV;
161 if (phy_num < 0 || phy_num >= WRIOP_MAX_PHY_NUM)
162 return -EINVAL;
Prabhakar Kushwaha2dd335f2015-03-20 19:28:22 -0700163
Pankaj Bansal50adb5e2018-10-10 14:08:34 +0530164 dpmac_info[i].phydev[phy_num] = phydev;
165
166 return 0;
Prabhakar Kushwaha2dd335f2015-03-20 19:28:22 -0700167}
168
Pankaj Bansal50adb5e2018-10-10 14:08:34 +0530169struct phy_device *wriop_get_phy_dev(int dpmac_id, int phy_num)
Prabhakar Kushwaha2dd335f2015-03-20 19:28:22 -0700170{
171 int i = wriop_dpmac_to_index(dpmac_id);
172
173 if (i == -1)
174 return NULL;
Pankaj Bansal50adb5e2018-10-10 14:08:34 +0530175 if (phy_num < 0 || phy_num >= WRIOP_MAX_PHY_NUM)
176 return NULL;
Prabhakar Kushwaha2dd335f2015-03-20 19:28:22 -0700177
Pankaj Bansal50adb5e2018-10-10 14:08:34 +0530178 return dpmac_info[i].phydev[phy_num];
Prabhakar Kushwaha2dd335f2015-03-20 19:28:22 -0700179}
180
181phy_interface_t wriop_get_enet_if(int dpmac_id)
182{
183 int i = wriop_dpmac_to_index(dpmac_id);
184
185 if (i == -1)
Marek Behún48631e42022-04-07 00:33:03 +0200186 return PHY_INTERFACE_MODE_NA;
Prabhakar Kushwaha2dd335f2015-03-20 19:28:22 -0700187
188 if (dpmac_info[i].enabled)
189 return dpmac_info[i].enet_if;
190
Marek Behún48631e42022-04-07 00:33:03 +0200191 return PHY_INTERFACE_MODE_NA;
Prabhakar Kushwaha2dd335f2015-03-20 19:28:22 -0700192}