blob: a803b8fa7972dd55adfd0d9653d7e5f3e6d049eb [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
55
Prabhakar Kushwaha2dd335f2015-03-20 19:28:22 -070056/*TODO what it do */
57static int wriop_dpmac_to_index(int dpmac_id)
58{
59 int i;
60
61 for (i = WRIOP1_DPMAC1; i < NUM_WRIOP_PORTS; i++) {
62 if (dpmac_info[i].id == dpmac_id)
63 return i;
64 }
65
66 return -1;
67}
68
Pankaj Bansal50adb5e2018-10-10 14:08:34 +053069int wriop_disable_dpmac(int dpmac_id)
Prabhakar Kushwaha2dd335f2015-03-20 19:28:22 -070070{
71 int i = wriop_dpmac_to_index(dpmac_id);
72
73 if (i == -1)
Pankaj Bansal50adb5e2018-10-10 14:08:34 +053074 return -ENODEV;
Prabhakar Kushwaha2dd335f2015-03-20 19:28:22 -070075
76 dpmac_info[i].enabled = 0;
77 wriop_dpmac_disable(dpmac_id);
Pankaj Bansal50adb5e2018-10-10 14:08:34 +053078
79 return 0;
Prabhakar Kushwaha2dd335f2015-03-20 19:28:22 -070080}
81
Pankaj Bansal50adb5e2018-10-10 14:08:34 +053082int wriop_enable_dpmac(int dpmac_id)
Prabhakar Kushwaha2dd335f2015-03-20 19:28:22 -070083{
84 int i = wriop_dpmac_to_index(dpmac_id);
85
86 if (i == -1)
Pankaj Bansal50adb5e2018-10-10 14:08:34 +053087 return -ENODEV;
Prabhakar Kushwaha2dd335f2015-03-20 19:28:22 -070088
89 dpmac_info[i].enabled = 1;
90 wriop_dpmac_enable(dpmac_id);
Pankaj Bansal50adb5e2018-10-10 14:08:34 +053091
92 return 0;
Prabhakar Kushwaha2dd335f2015-03-20 19:28:22 -070093}
94
Pankaj Bansal50adb5e2018-10-10 14:08:34 +053095int wriop_is_enabled_dpmac(int dpmac_id)
Prabhakar Kushwahaef553102015-11-04 12:25:56 +053096{
97 int i = wriop_dpmac_to_index(dpmac_id);
98
99 if (i == -1)
Pankaj Bansal50adb5e2018-10-10 14:08:34 +0530100 return -ENODEV;
Prabhakar Kushwahaef553102015-11-04 12:25:56 +0530101
102 return dpmac_info[i].enabled;
103}
104
105
Pankaj Bansal50adb5e2018-10-10 14:08:34 +0530106int wriop_set_mdio(int dpmac_id, struct mii_dev *bus)
Prabhakar Kushwaha2dd335f2015-03-20 19:28:22 -0700107{
108 int i = wriop_dpmac_to_index(dpmac_id);
109
110 if (i == -1)
Pankaj Bansal50adb5e2018-10-10 14:08:34 +0530111 return -ENODEV;
Prabhakar Kushwaha2dd335f2015-03-20 19:28:22 -0700112
113 dpmac_info[i].bus = bus;
Pankaj Bansal50adb5e2018-10-10 14:08:34 +0530114
115 return 0;
Prabhakar Kushwaha2dd335f2015-03-20 19:28:22 -0700116}
117
118struct mii_dev *wriop_get_mdio(int dpmac_id)
119{
120 int i = wriop_dpmac_to_index(dpmac_id);
121
122 if (i == -1)
123 return NULL;
124
125 return dpmac_info[i].bus;
126}
127
Pankaj Bansal50adb5e2018-10-10 14:08:34 +0530128int wriop_set_phy_address(int dpmac_id, int phy_num, int address)
Prabhakar Kushwaha2dd335f2015-03-20 19:28:22 -0700129{
130 int i = wriop_dpmac_to_index(dpmac_id);
131
132 if (i == -1)
Pankaj Bansal50adb5e2018-10-10 14:08:34 +0530133 return -ENODEV;
134 if (phy_num < 0 || phy_num >= WRIOP_MAX_PHY_NUM)
135 return -EINVAL;
136
137 dpmac_info[i].phy_addr[phy_num] = address;
Prabhakar Kushwaha2dd335f2015-03-20 19:28:22 -0700138
Pankaj Bansal50adb5e2018-10-10 14:08:34 +0530139 return 0;
Prabhakar Kushwaha2dd335f2015-03-20 19:28:22 -0700140}
141
Pankaj Bansal50adb5e2018-10-10 14:08:34 +0530142int wriop_get_phy_address(int dpmac_id, int phy_num)
Prabhakar Kushwaha2dd335f2015-03-20 19:28:22 -0700143{
144 int i = wriop_dpmac_to_index(dpmac_id);
145
146 if (i == -1)
Pankaj Bansal50adb5e2018-10-10 14:08:34 +0530147 return -ENODEV;
148 if (phy_num < 0 || phy_num >= WRIOP_MAX_PHY_NUM)
149 return -EINVAL;
Prabhakar Kushwaha2dd335f2015-03-20 19:28:22 -0700150
Pankaj Bansal50adb5e2018-10-10 14:08:34 +0530151 return dpmac_info[i].phy_addr[phy_num];
Prabhakar Kushwaha2dd335f2015-03-20 19:28:22 -0700152}
153
Pankaj Bansal50adb5e2018-10-10 14:08:34 +0530154int wriop_set_phy_dev(int dpmac_id, int phy_num, struct phy_device *phydev)
Prabhakar Kushwaha2dd335f2015-03-20 19:28:22 -0700155{
156 int i = wriop_dpmac_to_index(dpmac_id);
157
158 if (i == -1)
Pankaj Bansal50adb5e2018-10-10 14:08:34 +0530159 return -ENODEV;
160 if (phy_num < 0 || phy_num >= WRIOP_MAX_PHY_NUM)
161 return -EINVAL;
Prabhakar Kushwaha2dd335f2015-03-20 19:28:22 -0700162
Pankaj Bansal50adb5e2018-10-10 14:08:34 +0530163 dpmac_info[i].phydev[phy_num] = phydev;
164
165 return 0;
Prabhakar Kushwaha2dd335f2015-03-20 19:28:22 -0700166}
167
Pankaj Bansal50adb5e2018-10-10 14:08:34 +0530168struct phy_device *wriop_get_phy_dev(int dpmac_id, int phy_num)
Prabhakar Kushwaha2dd335f2015-03-20 19:28:22 -0700169{
170 int i = wriop_dpmac_to_index(dpmac_id);
171
172 if (i == -1)
173 return NULL;
Pankaj Bansal50adb5e2018-10-10 14:08:34 +0530174 if (phy_num < 0 || phy_num >= WRIOP_MAX_PHY_NUM)
175 return NULL;
Prabhakar Kushwaha2dd335f2015-03-20 19:28:22 -0700176
Pankaj Bansal50adb5e2018-10-10 14:08:34 +0530177 return dpmac_info[i].phydev[phy_num];
Prabhakar Kushwaha2dd335f2015-03-20 19:28:22 -0700178}
179
180phy_interface_t wriop_get_enet_if(int dpmac_id)
181{
182 int i = wriop_dpmac_to_index(dpmac_id);
183
184 if (i == -1)
Marek Behún48631e42022-04-07 00:33:03 +0200185 return PHY_INTERFACE_MODE_NA;
Prabhakar Kushwaha2dd335f2015-03-20 19:28:22 -0700186
187 if (dpmac_info[i].enabled)
188 return dpmac_info[i].enet_if;
189
Marek Behún48631e42022-04-07 00:33:03 +0200190 return PHY_INTERFACE_MODE_NA;
Prabhakar Kushwaha2dd335f2015-03-20 19:28:22 -0700191}