blob: 81b5b9eaf7d25cbfb93c85bf5d24ca0ea9b31b78 [file] [log] [blame]
Tom Rini10e47792018-05-06 17:58:06 -04001// SPDX-License-Identifier: GPL-2.0+
Prabhakar Kushwahac158fad2015-03-20 19:28:26 -07002/*
3 * Copyright 2015 Freescale Semiconductor, Inc.
Prabhakar Kushwahac158fad2015-03-20 19:28:26 -07004 */
5
6#include <common.h>
Simon Glass0af6e2d2019-08-01 09:46:52 -06007#include <env.h>
Simon Glass0f2af882020-05-10 11:40:05 -06008#include <log.h>
Simon Glass0c364412019-12-28 10:44:48 -07009#include <net.h>
Prabhakar Kushwahac158fad2015-03-20 19:28:26 -070010#include <netdev.h>
11#include <asm/io.h>
12#include <asm/arch/fsl_serdes.h>
Prabhakar Kushwaha35f93f62015-08-07 18:01:51 +053013#include <hwconfig.h>
Prabhakar Kushwahac158fad2015-03-20 19:28:26 -070014#include <fsl_mdio.h>
15#include <malloc.h>
16#include <fm_eth.h>
Prabhakar Kushwaha35f93f62015-08-07 18:01:51 +053017#include <i2c.h>
18#include <miiphy.h>
Bogdan Purcareata08bc0142017-05-24 16:40:21 +000019#include <fsl-mc/fsl_mc.h>
Prabhakar Kushwahac158fad2015-03-20 19:28:26 -070020#include <fsl-mc/ldpaa_wriop.h>
Simon Glassdbd79542020-05-10 11:40:11 -060021#include <linux/delay.h>
Prabhakar Kushwahac158fad2015-03-20 19:28:26 -070022
23#include "../common/qixis.h"
24
Prabhakar Kushwaha122bcfd2015-11-09 16:42:07 +053025#include "ls2080aqds_qixis.h"
Prabhakar Kushwahac158fad2015-03-20 19:28:26 -070026
Pratiyush Mohan Srivastava9abba112016-01-20 12:29:03 +053027#define MC_BOOT_ENV_VAR "mcinitcmd"
Prabhakar Kushwahac158fad2015-03-20 19:28:26 -070028
Santan Kumar1afa9002017-05-05 15:42:29 +053029#if defined(CONFIG_FSL_MC_ENET) && !defined(CONFIG_SPL_BUILD)
Prabhakar Kushwaha122bcfd2015-11-09 16:42:07 +053030 /* - In LS2080A there are only 16 SERDES lanes, spread across 2 SERDES banks.
Prabhakar Kushwahac158fad2015-03-20 19:28:26 -070031 * Bank 1 -> Lanes A, B, C, D, E, F, G, H
32 * Bank 2 -> Lanes A,B, C, D, E, F, G, H
33 */
34
Prabhakar Kushwaha122bcfd2015-11-09 16:42:07 +053035 /* Mapping of 16 SERDES lanes to LS2080A QDS board slots. A value of '0' here
Prabhakar Kushwahac158fad2015-03-20 19:28:26 -070036 * means that the mapping must be determined dynamically, or that the lane
37 * maps to something other than a board slot.
38 */
39
Prabhakar Kushwaha35f93f62015-08-07 18:01:51 +053040static u8 lane_to_slot_fsm1[] = {
41 0, 0, 0, 0, 0, 0, 0, 0
42};
43
Prabhakar Kushwahac158fad2015-03-20 19:28:26 -070044static u8 lane_to_slot_fsm2[] = {
45 0, 0, 0, 0, 0, 0, 0, 0
46};
47
48/* On the Vitesse VSC8234XHG SGMII riser card there are 4 SGMII PHYs
49 * housed.
50 */
Prabhakar Kushwaha35f93f62015-08-07 18:01:51 +053051
52static int xqsgii_riser_phy_addr[] = {
53 XQSGMII_CARD_PHY1_PORT0_ADDR,
54 XQSGMII_CARD_PHY2_PORT0_ADDR,
55 XQSGMII_CARD_PHY3_PORT0_ADDR,
56 XQSGMII_CARD_PHY4_PORT0_ADDR,
57 XQSGMII_CARD_PHY3_PORT2_ADDR,
58 XQSGMII_CARD_PHY1_PORT2_ADDR,
59 XQSGMII_CARD_PHY4_PORT2_ADDR,
60 XQSGMII_CARD_PHY2_PORT2_ADDR,
61};
62
63static int sgmii_riser_phy_addr[] = {
Prabhakar Kushwahac158fad2015-03-20 19:28:26 -070064 SGMII_CARD_PORT1_PHY_ADDR,
65 SGMII_CARD_PORT2_PHY_ADDR,
66 SGMII_CARD_PORT3_PHY_ADDR,
67 SGMII_CARD_PORT4_PHY_ADDR,
68};
69
70/* Slot2 does not have EMI connections */
Priyanka Jaine2da6232016-11-03 17:50:51 +053071#define EMI_NONE 0xFF
Prabhakar Kushwahac158fad2015-03-20 19:28:26 -070072#define EMI1_SLOT1 0
73#define EMI1_SLOT2 1
74#define EMI1_SLOT3 2
75#define EMI1_SLOT4 3
76#define EMI1_SLOT5 4
77#define EMI1_SLOT6 5
78#define EMI2 6
Prabhakar Kushwaha782d6662015-05-28 14:54:00 +053079#define SFP_TX 0
Prabhakar Kushwahac158fad2015-03-20 19:28:26 -070080
81static const char * const mdio_names[] = {
Prabhakar Kushwaha122bcfd2015-11-09 16:42:07 +053082 "LS2080A_QDS_MDIO0",
83 "LS2080A_QDS_MDIO1",
84 "LS2080A_QDS_MDIO2",
85 "LS2080A_QDS_MDIO3",
86 "LS2080A_QDS_MDIO4",
87 "LS2080A_QDS_MDIO5",
Prabhakar Kushwahac158fad2015-03-20 19:28:26 -070088 DEFAULT_WRIOP_MDIO2_NAME,
89};
90
Prabhakar Kushwaha122bcfd2015-11-09 16:42:07 +053091struct ls2080a_qds_mdio {
Prabhakar Kushwahac158fad2015-03-20 19:28:26 -070092 u8 muxval;
93 struct mii_dev *realbus;
94};
95
Chuanhua Han1ab68c72019-07-26 19:24:01 +080096struct reg_pair {
97 uint addr;
98 u8 *val;
99};
100
Prabhakar Kushwaha35f93f62015-08-07 18:01:51 +0530101static void sgmii_configure_repeater(int serdes_port)
102{
103 struct mii_dev *bus;
104 uint8_t a = 0xf;
Chuanhua Han1ab68c72019-07-26 19:24:01 +0800105 int i, j, k, ret;
Prabhakar Kushwaha35f93f62015-08-07 18:01:51 +0530106 int dpmac_id = 0, dpmac, mii_bus = 0;
107 unsigned short value;
Prabhakar Kushwaha122bcfd2015-11-09 16:42:07 +0530108 char dev[2][20] = {"LS2080A_QDS_MDIO0", "LS2080A_QDS_MDIO3"};
Prabhakar Kushwaha35f93f62015-08-07 18:01:51 +0530109 uint8_t i2c_addr[] = {0x58, 0x59, 0x5a, 0x5b, 0x5c, 0x5d, 0x5f, 0x60};
110
111 uint8_t ch_a_eq[] = {0x1, 0x2, 0x3, 0x7};
112 uint8_t ch_a_ctl2[] = {0x81, 0x82, 0x83, 0x84};
113 uint8_t ch_b_eq[] = {0x1, 0x2, 0x3, 0x7};
114 uint8_t ch_b_ctl2[] = {0x81, 0x82, 0x83, 0x84};
115
Chuanhua Han1ab68c72019-07-26 19:24:01 +0800116 u8 reg_val[6] = {0x18, 0x38, 0x4, 0x14, 0xb5, 0x20};
117 struct reg_pair reg_pair[10] = {
118 {6, &reg_val[0]}, {4, &reg_val[1]},
119 {8, &reg_val[2]}, {0xf, NULL},
120 {0x11, NULL}, {0x16, NULL},
121 {0x18, NULL}, {0x23, &reg_val[3]},
122 {0x2d, &reg_val[4]}, {4, &reg_val[5]},
123 };
124
Prabhakar Kushwaha35f93f62015-08-07 18:01:51 +0530125 int *riser_phy_addr = &xqsgii_riser_phy_addr[0];
Chuanhua Han1ab68c72019-07-26 19:24:01 +0800126#ifdef CONFIG_DM_I2C
127 struct udevice *udev;
128#endif
Prabhakar Kushwaha35f93f62015-08-07 18:01:51 +0530129
130 /* Set I2c to Slot 1 */
Chuanhua Han1ab68c72019-07-26 19:24:01 +0800131#ifndef CONFIG_DM_I2C
132 ret = i2c_write(0x77, 0, 0, &a, 1);
133#else
134 ret = i2c_get_chip_for_busnum(0, 0x77, 1, &udev);
135 if (!ret)
136 ret = dm_i2c_write(udev, 0, &a, 1);
137#endif
138 if (ret)
139 goto error;
Prabhakar Kushwaha35f93f62015-08-07 18:01:51 +0530140
141 for (dpmac = 0; dpmac < 8; dpmac++) {
142 /* Check the PHY status */
143 switch (serdes_port) {
144 case 1:
145 mii_bus = 0;
146 dpmac_id = dpmac + 1;
147 break;
148 case 2:
149 mii_bus = 1;
150 dpmac_id = dpmac + 9;
151 a = 0xb;
Chuanhua Han1ab68c72019-07-26 19:24:01 +0800152#ifndef CONFIG_DM_I2C
153 ret = i2c_write(0x76, 0, 0, &a, 1);
154#else
155 ret = i2c_get_chip_for_busnum(0, 0x76, 1, &udev);
156 if (!ret)
157 ret = dm_i2c_write(udev, 0, &a, 1);
158#endif
159 if (ret)
160 goto error;
Prabhakar Kushwaha35f93f62015-08-07 18:01:51 +0530161 break;
162 }
163
164 ret = miiphy_set_current_dev(dev[mii_bus]);
165 if (ret > 0)
166 goto error;
167
168 bus = mdio_get_current_dev();
169 debug("Reading from bus %s\n", bus->name);
170
171 ret = miiphy_write(dev[mii_bus], riser_phy_addr[dpmac], 0x1f,
172 3);
173 if (ret > 0)
174 goto error;
175
176 mdelay(10);
177 ret = miiphy_read(dev[mii_bus], riser_phy_addr[dpmac], 0x11,
178 &value);
179 if (ret > 0)
180 goto error;
181
182 mdelay(10);
183
Shaohui Xie84900b52016-10-17 16:20:48 +0800184 if ((value & 0xfff) == 0x401) {
Prabhakar Kushwaha35f93f62015-08-07 18:01:51 +0530185 printf("DPMAC %d:PHY is ..... Configured\n", dpmac_id);
Shaohui Xie84900b52016-10-17 16:20:48 +0800186 miiphy_write(dev[mii_bus], riser_phy_addr[dpmac],
187 0x1f, 0);
Prabhakar Kushwaha35f93f62015-08-07 18:01:51 +0530188 continue;
189 }
190
191 for (i = 0; i < 4; i++) {
192 for (j = 0; j < 4; j++) {
Chuanhua Han1ab68c72019-07-26 19:24:01 +0800193 reg_pair[3].val = &ch_a_eq[i];
194 reg_pair[4].val = &ch_a_ctl2[j];
195 reg_pair[5].val = &ch_b_eq[i];
196 reg_pair[6].val = &ch_b_ctl2[j];
Prabhakar Kushwaha35f93f62015-08-07 18:01:51 +0530197
Chuanhua Han1ab68c72019-07-26 19:24:01 +0800198 for (k = 0; k < 10; k++) {
199#ifndef CONFIG_DM_I2C
200 ret = i2c_write(i2c_addr[dpmac],
201 reg_pair[k].addr,
202 1, reg_pair[k].val, 1);
203#else
204 ret = i2c_get_chip_for_busnum(0,
205 i2c_addr[dpmac],
206 1, &udev);
207 if (!ret)
208 ret = dm_i2c_write(udev,
209 reg_pair[k].addr,
210 reg_pair[k].val, 1);
211#endif
212 if (ret)
213 goto error;
214 }
Prabhakar Kushwaha35f93f62015-08-07 18:01:51 +0530215
Prabhakar Kushwaha35f93f62015-08-07 18:01:51 +0530216 mdelay(100);
217 ret = miiphy_read(dev[mii_bus],
218 riser_phy_addr[dpmac],
219 0x11, &value);
220 if (ret > 0)
221 goto error;
222
Shaohui Xie84900b52016-10-17 16:20:48 +0800223 mdelay(100);
Prabhakar Kushwaha35f93f62015-08-07 18:01:51 +0530224 ret = miiphy_read(dev[mii_bus],
225 riser_phy_addr[dpmac],
226 0x11, &value);
227 if (ret > 0)
228 goto error;
Prabhakar Kushwaha35f93f62015-08-07 18:01:51 +0530229
Shaohui Xie84900b52016-10-17 16:20:48 +0800230 if ((value & 0xfff) == 0x401) {
Prabhakar Kushwaha35f93f62015-08-07 18:01:51 +0530231 printf("DPMAC %d :PHY is configured ",
232 dpmac_id);
233 printf("after setting repeater 0x%x\n",
234 value);
235 i = 5;
236 j = 5;
Shaohui Xie84900b52016-10-17 16:20:48 +0800237 } else {
Prabhakar Kushwaha35f93f62015-08-07 18:01:51 +0530238 printf("DPMAC %d :PHY is failed to ",
239 dpmac_id);
240 printf("configure the repeater 0x%x\n",
241 value);
242 }
Shaohui Xie84900b52016-10-17 16:20:48 +0800243 }
Prabhakar Kushwaha35f93f62015-08-07 18:01:51 +0530244 }
Shaohui Xie84900b52016-10-17 16:20:48 +0800245 miiphy_write(dev[mii_bus], riser_phy_addr[dpmac], 0x1f, 0);
Prabhakar Kushwaha35f93f62015-08-07 18:01:51 +0530246 }
247error:
248 if (ret)
249 printf("DPMAC %d ..... FAILED to configure PHY\n", dpmac_id);
250 return;
251}
252
253static void qsgmii_configure_repeater(int dpmac)
254{
255 uint8_t a = 0xf;
Chuanhua Han1ab68c72019-07-26 19:24:01 +0800256 int i, j, k;
Prabhakar Kushwaha35f93f62015-08-07 18:01:51 +0530257 int i2c_phy_addr = 0;
258 int phy_addr = 0;
259 int i2c_addr[] = {0x58, 0x59, 0x5a, 0x5b};
260
261 uint8_t ch_a_eq[] = {0x1, 0x2, 0x3, 0x7};
262 uint8_t ch_a_ctl2[] = {0x81, 0x82, 0x83, 0x84};
263 uint8_t ch_b_eq[] = {0x1, 0x2, 0x3, 0x7};
264 uint8_t ch_b_ctl2[] = {0x81, 0x82, 0x83, 0x84};
265
Chuanhua Han1ab68c72019-07-26 19:24:01 +0800266 u8 reg_val[6] = {0x18, 0x38, 0x4, 0x14, 0xb5, 0x20};
267 struct reg_pair reg_pair[10] = {
268 {6, &reg_val[0]}, {4, &reg_val[1]},
269 {8, &reg_val[2]}, {0xf, NULL},
270 {0x11, NULL}, {0x16, NULL},
271 {0x18, NULL}, {0x23, &reg_val[3]},
272 {0x2d, &reg_val[4]}, {4, &reg_val[5]},
273 };
274
Prabhakar Kushwaha122bcfd2015-11-09 16:42:07 +0530275 const char *dev = "LS2080A_QDS_MDIO0";
Prabhakar Kushwaha35f93f62015-08-07 18:01:51 +0530276 int ret = 0;
277 unsigned short value;
Chuanhua Han1ab68c72019-07-26 19:24:01 +0800278#ifdef CONFIG_DM_I2C
279 struct udevice *udev;
280#endif
Prabhakar Kushwaha35f93f62015-08-07 18:01:51 +0530281
282 /* Set I2c to Slot 1 */
Chuanhua Han1ab68c72019-07-26 19:24:01 +0800283#ifndef CONFIG_DM_I2C
284 ret = i2c_write(0x77, 0, 0, &a, 1);
285#else
286 ret = i2c_get_chip_for_busnum(0, 0x77, 1, &udev);
287 if (!ret)
288 ret = dm_i2c_write(udev, 0, &a, 1);
289#endif
290 if (ret)
291 goto error;
Prabhakar Kushwaha35f93f62015-08-07 18:01:51 +0530292
293 switch (dpmac) {
294 case 1:
295 case 2:
296 case 3:
297 case 4:
298 i2c_phy_addr = i2c_addr[0];
299 phy_addr = 0;
300 break;
301
302 case 5:
303 case 6:
304 case 7:
305 case 8:
306 i2c_phy_addr = i2c_addr[1];
307 phy_addr = 4;
308 break;
309
310 case 9:
311 case 10:
312 case 11:
313 case 12:
314 i2c_phy_addr = i2c_addr[2];
315 phy_addr = 8;
316 break;
317
318 case 13:
319 case 14:
320 case 15:
321 case 16:
322 i2c_phy_addr = i2c_addr[3];
323 phy_addr = 0xc;
324 break;
325 }
326
327 /* Check the PHY status */
328 ret = miiphy_set_current_dev(dev);
329 ret = miiphy_write(dev, phy_addr, 0x1f, 3);
330 mdelay(10);
331 ret = miiphy_read(dev, phy_addr, 0x11, &value);
332 mdelay(10);
333 ret = miiphy_read(dev, phy_addr, 0x11, &value);
334 mdelay(10);
335 if ((value & 0xf) == 0xf) {
336 printf("DPMAC %d :PHY is ..... Configured\n", dpmac);
337 return;
338 }
339
340 for (i = 0; i < 4; i++) {
341 for (j = 0; j < 4; j++) {
Chuanhua Han1ab68c72019-07-26 19:24:01 +0800342 reg_pair[3].val = &ch_a_eq[i];
343 reg_pair[4].val = &ch_a_ctl2[j];
344 reg_pair[5].val = &ch_b_eq[i];
345 reg_pair[6].val = &ch_b_ctl2[j];
Prabhakar Kushwaha35f93f62015-08-07 18:01:51 +0530346
Chuanhua Han1ab68c72019-07-26 19:24:01 +0800347 for (k = 0; k < 10; k++) {
348#ifndef CONFIG_DM_I2C
349 ret = i2c_write(i2c_phy_addr,
350 reg_pair[k].addr,
351 1, reg_pair[k].val, 1);
352#else
353 ret = i2c_get_chip_for_busnum(0,
354 i2c_phy_addr,
355 1, &udev);
356 if (!ret)
357 ret = dm_i2c_write(udev,
358 reg_pair[k].addr,
359 reg_pair[k].val, 1);
360#endif
361 if (ret)
362 goto error;
363 }
Prabhakar Kushwaha35f93f62015-08-07 18:01:51 +0530364
Prabhakar Kushwaha35f93f62015-08-07 18:01:51 +0530365 mdelay(100);
366 ret = miiphy_read(dev, phy_addr, 0x11, &value);
367 if (ret > 0)
368 goto error;
369 mdelay(1);
370 ret = miiphy_read(dev, phy_addr, 0x11, &value);
371 if (ret > 0)
372 goto error;
373 mdelay(10);
374 if ((value & 0xf) == 0xf) {
375 printf("DPMAC %d :PHY is ..... Configured\n",
376 dpmac);
377 return;
378 }
379 }
380 }
381error:
382 printf("DPMAC %d :PHY ..... FAILED to configure PHY\n", dpmac);
383 return;
384}
385
Prabhakar Kushwaha122bcfd2015-11-09 16:42:07 +0530386static const char *ls2080a_qds_mdio_name_for_muxval(u8 muxval)
Prabhakar Kushwahac158fad2015-03-20 19:28:26 -0700387{
388 return mdio_names[muxval];
389}
390
391struct mii_dev *mii_dev_for_muxval(u8 muxval)
392{
393 struct mii_dev *bus;
Prabhakar Kushwaha122bcfd2015-11-09 16:42:07 +0530394 const char *name = ls2080a_qds_mdio_name_for_muxval(muxval);
Prabhakar Kushwahac158fad2015-03-20 19:28:26 -0700395
396 if (!name) {
397 printf("No bus for muxval %x\n", muxval);
398 return NULL;
399 }
400
401 bus = miiphy_get_dev_by_name(name);
402
403 if (!bus) {
404 printf("No bus by name %s\n", name);
405 return NULL;
406 }
407
408 return bus;
409}
410
Prabhakar Kushwaha122bcfd2015-11-09 16:42:07 +0530411static void ls2080a_qds_enable_SFP_TX(u8 muxval)
Prabhakar Kushwahac158fad2015-03-20 19:28:26 -0700412{
413 u8 brdcfg9;
414
415 brdcfg9 = QIXIS_READ(brdcfg[9]);
416 brdcfg9 &= ~BRDCFG9_SFPTX_MASK;
417 brdcfg9 |= (muxval << BRDCFG9_SFPTX_SHIFT);
418 QIXIS_WRITE(brdcfg[9], brdcfg9);
419}
420
Prabhakar Kushwaha122bcfd2015-11-09 16:42:07 +0530421static void ls2080a_qds_mux_mdio(u8 muxval)
Prabhakar Kushwahac158fad2015-03-20 19:28:26 -0700422{
423 u8 brdcfg4;
424
425 if (muxval <= 5) {
426 brdcfg4 = QIXIS_READ(brdcfg[4]);
427 brdcfg4 &= ~BRDCFG4_EMISEL_MASK;
428 brdcfg4 |= (muxval << BRDCFG4_EMISEL_SHIFT);
429 QIXIS_WRITE(brdcfg[4], brdcfg4);
430 }
431}
432
Prabhakar Kushwaha122bcfd2015-11-09 16:42:07 +0530433static int ls2080a_qds_mdio_read(struct mii_dev *bus, int addr,
Prabhakar Kushwahac158fad2015-03-20 19:28:26 -0700434 int devad, int regnum)
435{
Prabhakar Kushwaha122bcfd2015-11-09 16:42:07 +0530436 struct ls2080a_qds_mdio *priv = bus->priv;
Prabhakar Kushwahac158fad2015-03-20 19:28:26 -0700437
Prabhakar Kushwaha122bcfd2015-11-09 16:42:07 +0530438 ls2080a_qds_mux_mdio(priv->muxval);
Prabhakar Kushwahac158fad2015-03-20 19:28:26 -0700439
440 return priv->realbus->read(priv->realbus, addr, devad, regnum);
441}
442
Prabhakar Kushwaha122bcfd2015-11-09 16:42:07 +0530443static int ls2080a_qds_mdio_write(struct mii_dev *bus, int addr, int devad,
Prabhakar Kushwahac158fad2015-03-20 19:28:26 -0700444 int regnum, u16 value)
445{
Prabhakar Kushwaha122bcfd2015-11-09 16:42:07 +0530446 struct ls2080a_qds_mdio *priv = bus->priv;
Prabhakar Kushwahac158fad2015-03-20 19:28:26 -0700447
Prabhakar Kushwaha122bcfd2015-11-09 16:42:07 +0530448 ls2080a_qds_mux_mdio(priv->muxval);
Prabhakar Kushwahac158fad2015-03-20 19:28:26 -0700449
450 return priv->realbus->write(priv->realbus, addr, devad, regnum, value);
451}
452
Prabhakar Kushwaha122bcfd2015-11-09 16:42:07 +0530453static int ls2080a_qds_mdio_reset(struct mii_dev *bus)
Prabhakar Kushwahac158fad2015-03-20 19:28:26 -0700454{
Prabhakar Kushwaha122bcfd2015-11-09 16:42:07 +0530455 struct ls2080a_qds_mdio *priv = bus->priv;
Prabhakar Kushwahac158fad2015-03-20 19:28:26 -0700456
457 return priv->realbus->reset(priv->realbus);
458}
459
Prabhakar Kushwaha122bcfd2015-11-09 16:42:07 +0530460static int ls2080a_qds_mdio_init(char *realbusname, u8 muxval)
Prabhakar Kushwahac158fad2015-03-20 19:28:26 -0700461{
Prabhakar Kushwaha122bcfd2015-11-09 16:42:07 +0530462 struct ls2080a_qds_mdio *pmdio;
Prabhakar Kushwahac158fad2015-03-20 19:28:26 -0700463 struct mii_dev *bus = mdio_alloc();
464
465 if (!bus) {
Prabhakar Kushwaha122bcfd2015-11-09 16:42:07 +0530466 printf("Failed to allocate ls2080a_qds MDIO bus\n");
Prabhakar Kushwahac158fad2015-03-20 19:28:26 -0700467 return -1;
468 }
469
470 pmdio = malloc(sizeof(*pmdio));
471 if (!pmdio) {
Prabhakar Kushwaha122bcfd2015-11-09 16:42:07 +0530472 printf("Failed to allocate ls2080a_qds private data\n");
Prabhakar Kushwahac158fad2015-03-20 19:28:26 -0700473 free(bus);
474 return -1;
475 }
476
Prabhakar Kushwaha122bcfd2015-11-09 16:42:07 +0530477 bus->read = ls2080a_qds_mdio_read;
478 bus->write = ls2080a_qds_mdio_write;
479 bus->reset = ls2080a_qds_mdio_reset;
Ben Whitten34fd6c92015-12-30 13:05:58 +0000480 strcpy(bus->name, ls2080a_qds_mdio_name_for_muxval(muxval));
Prabhakar Kushwahac158fad2015-03-20 19:28:26 -0700481
482 pmdio->realbus = miiphy_get_dev_by_name(realbusname);
483
484 if (!pmdio->realbus) {
485 printf("No bus with name %s\n", realbusname);
486 free(bus);
487 free(pmdio);
488 return -1;
489 }
490
491 pmdio->muxval = muxval;
492 bus->priv = pmdio;
493
494 return mdio_register(bus);
495}
496
497/*
498 * Initialize the dpmac_info array.
499 *
500 */
501static void initialize_dpmac_to_slot(void)
502{
503 struct ccsr_gur __iomem *gur = (void *)CONFIG_SYS_FSL_GUTS_ADDR;
504 int serdes1_prtcl = (in_le32(&gur->rcwsr[28]) &
505 FSL_CHASSIS3_RCWSR28_SRDS1_PRTCL_MASK)
506 >> FSL_CHASSIS3_RCWSR28_SRDS1_PRTCL_SHIFT;
507 int serdes2_prtcl = (in_le32(&gur->rcwsr[28]) &
508 FSL_CHASSIS3_RCWSR28_SRDS2_PRTCL_MASK)
509 >> FSL_CHASSIS3_RCWSR28_SRDS2_PRTCL_SHIFT;
510
Prabhakar Kushwaha35f93f62015-08-07 18:01:51 +0530511 char *env_hwconfig;
Simon Glass64b723f2017-08-03 12:22:12 -0600512 env_hwconfig = env_get("hwconfig");
Prabhakar Kushwahac158fad2015-03-20 19:28:26 -0700513
514 switch (serdes1_prtcl) {
Prabhakar Kushwaha35f93f62015-08-07 18:01:51 +0530515 case 0x07:
516 case 0x09:
517 case 0x33:
518 printf("qds: WRIOP: Supported SerDes1 Protocol 0x%02x\n",
519 serdes1_prtcl);
520 lane_to_slot_fsm1[0] = EMI1_SLOT1;
521 lane_to_slot_fsm1[1] = EMI1_SLOT1;
522 lane_to_slot_fsm1[2] = EMI1_SLOT1;
523 lane_to_slot_fsm1[3] = EMI1_SLOT1;
524 if (hwconfig_f("xqsgmii", env_hwconfig)) {
525 lane_to_slot_fsm1[4] = EMI1_SLOT1;
526 lane_to_slot_fsm1[5] = EMI1_SLOT1;
527 lane_to_slot_fsm1[6] = EMI1_SLOT1;
528 lane_to_slot_fsm1[7] = EMI1_SLOT1;
529 } else {
530 lane_to_slot_fsm1[4] = EMI1_SLOT2;
531 lane_to_slot_fsm1[5] = EMI1_SLOT2;
532 lane_to_slot_fsm1[6] = EMI1_SLOT2;
533 lane_to_slot_fsm1[7] = EMI1_SLOT2;
534 }
535 break;
536
Priyanka Jaine2da6232016-11-03 17:50:51 +0530537 case 0x39:
538 printf("qds: WRIOP: Supported SerDes1 Protocol 0x%02x\n",
539 serdes1_prtcl);
540 if (hwconfig_f("xqsgmii", env_hwconfig)) {
541 lane_to_slot_fsm1[0] = EMI1_SLOT3;
542 lane_to_slot_fsm1[1] = EMI1_SLOT3;
543 lane_to_slot_fsm1[2] = EMI1_SLOT3;
544 lane_to_slot_fsm1[3] = EMI_NONE;
545 } else {
546 lane_to_slot_fsm1[0] = EMI_NONE;
547 lane_to_slot_fsm1[1] = EMI_NONE;
548 lane_to_slot_fsm1[2] = EMI_NONE;
549 lane_to_slot_fsm1[3] = EMI_NONE;
550 }
551 lane_to_slot_fsm1[4] = EMI1_SLOT3;
552 lane_to_slot_fsm1[5] = EMI1_SLOT3;
553 lane_to_slot_fsm1[6] = EMI1_SLOT3;
554 lane_to_slot_fsm1[7] = EMI_NONE;
555 break;
556
557 case 0x4D:
558 printf("qds: WRIOP: Supported SerDes1 Protocol 0x%02x\n",
559 serdes1_prtcl);
560 if (hwconfig_f("xqsgmii", env_hwconfig)) {
561 lane_to_slot_fsm1[0] = EMI1_SLOT3;
562 lane_to_slot_fsm1[1] = EMI1_SLOT3;
563 lane_to_slot_fsm1[2] = EMI_NONE;
564 lane_to_slot_fsm1[3] = EMI_NONE;
565 } else {
566 lane_to_slot_fsm1[0] = EMI_NONE;
567 lane_to_slot_fsm1[1] = EMI_NONE;
568 lane_to_slot_fsm1[2] = EMI_NONE;
569 lane_to_slot_fsm1[3] = EMI_NONE;
570 }
571 lane_to_slot_fsm1[4] = EMI1_SLOT3;
572 lane_to_slot_fsm1[5] = EMI1_SLOT3;
573 lane_to_slot_fsm1[6] = EMI_NONE;
574 lane_to_slot_fsm1[7] = EMI_NONE;
575 break;
576
Prabhakar Kushwahac158fad2015-03-20 19:28:26 -0700577 case 0x2A:
Priyanka Jaine2da6232016-11-03 17:50:51 +0530578 case 0x4B:
579 case 0x4C:
Prabhakar Kushwaha35f93f62015-08-07 18:01:51 +0530580 printf("qds: WRIOP: Supported SerDes1 Protocol 0x%02x\n",
Prabhakar Kushwahac158fad2015-03-20 19:28:26 -0700581 serdes1_prtcl);
582 break;
583 default:
Prabhakar Kushwahac5aa4ff2015-11-04 12:25:55 +0530584 printf("%s qds: WRIOP: Unsupported SerDes1 Protocol 0x%02x\n",
585 __func__, serdes1_prtcl);
Prabhakar Kushwahac158fad2015-03-20 19:28:26 -0700586 break;
587 }
588
589 switch (serdes2_prtcl) {
590 case 0x07:
591 case 0x08:
Prabhakar Kushwaha35f93f62015-08-07 18:01:51 +0530592 case 0x09:
Prabhakar Kushwaha2a6e5dc2015-05-28 14:53:57 +0530593 case 0x49:
Prabhakar Kushwaha35f93f62015-08-07 18:01:51 +0530594 printf("qds: WRIOP: Supported SerDes2 Protocol 0x%02x\n",
Prabhakar Kushwahac158fad2015-03-20 19:28:26 -0700595 serdes2_prtcl);
596 lane_to_slot_fsm2[0] = EMI1_SLOT4;
597 lane_to_slot_fsm2[1] = EMI1_SLOT4;
598 lane_to_slot_fsm2[2] = EMI1_SLOT4;
599 lane_to_slot_fsm2[3] = EMI1_SLOT4;
Prabhakar Kushwaha35f93f62015-08-07 18:01:51 +0530600
601 if (hwconfig_f("xqsgmii", env_hwconfig)) {
602 lane_to_slot_fsm2[4] = EMI1_SLOT4;
603 lane_to_slot_fsm2[5] = EMI1_SLOT4;
604 lane_to_slot_fsm2[6] = EMI1_SLOT4;
605 lane_to_slot_fsm2[7] = EMI1_SLOT4;
606 } else {
607 /* No MDIO physical connection */
608 lane_to_slot_fsm2[4] = EMI1_SLOT6;
609 lane_to_slot_fsm2[5] = EMI1_SLOT6;
610 lane_to_slot_fsm2[6] = EMI1_SLOT6;
611 lane_to_slot_fsm2[7] = EMI1_SLOT6;
612 }
Priyanka Jaine2da6232016-11-03 17:50:51 +0530613 break;
614
615 case 0x47:
616 printf("qds: WRIOP: Supported SerDes2 Protocol 0x%02x\n",
617 serdes2_prtcl);
618 lane_to_slot_fsm2[0] = EMI_NONE;
619 lane_to_slot_fsm2[1] = EMI1_SLOT5;
620 lane_to_slot_fsm2[2] = EMI1_SLOT5;
621 lane_to_slot_fsm2[3] = EMI1_SLOT5;
622
623 if (hwconfig_f("xqsgmii", env_hwconfig)) {
624 lane_to_slot_fsm2[4] = EMI_NONE;
625 lane_to_slot_fsm2[5] = EMI1_SLOT5;
626 lane_to_slot_fsm2[6] = EMI1_SLOT5;
627 lane_to_slot_fsm2[7] = EMI1_SLOT5;
628 }
629 break;
630
631 case 0x57:
632 printf("qds: WRIOP: Supported SerDes2 Protocol 0x%02x\n",
633 serdes2_prtcl);
634 if (hwconfig_f("xqsgmii", env_hwconfig)) {
635 lane_to_slot_fsm2[0] = EMI_NONE;
636 lane_to_slot_fsm2[1] = EMI_NONE;
637 lane_to_slot_fsm2[2] = EMI_NONE;
638 lane_to_slot_fsm2[3] = EMI_NONE;
639 }
640 lane_to_slot_fsm2[4] = EMI_NONE;
641 lane_to_slot_fsm2[5] = EMI_NONE;
642 lane_to_slot_fsm2[6] = EMI1_SLOT5;
643 lane_to_slot_fsm2[7] = EMI1_SLOT5;
Prabhakar Kushwahac158fad2015-03-20 19:28:26 -0700644 break;
Priyanka Jaine2da6232016-11-03 17:50:51 +0530645
Prabhakar Kushwahac158fad2015-03-20 19:28:26 -0700646 default:
Prabhakar Kushwahac5aa4ff2015-11-04 12:25:55 +0530647 printf(" %s qds: WRIOP: Unsupported SerDes2 Protocol 0x%02x\n",
648 __func__ , serdes2_prtcl);
Prabhakar Kushwahac158fad2015-03-20 19:28:26 -0700649 break;
650 }
651}
652
Prabhakar Kushwaha122bcfd2015-11-09 16:42:07 +0530653void ls2080a_handle_phy_interface_sgmii(int dpmac_id)
Prabhakar Kushwahac158fad2015-03-20 19:28:26 -0700654{
655 int lane, slot;
656 struct mii_dev *bus;
657 struct ccsr_gur __iomem *gur = (void *)CONFIG_SYS_FSL_GUTS_ADDR;
658 int serdes1_prtcl = (in_le32(&gur->rcwsr[28]) &
659 FSL_CHASSIS3_RCWSR28_SRDS1_PRTCL_MASK)
660 >> FSL_CHASSIS3_RCWSR28_SRDS1_PRTCL_SHIFT;
661 int serdes2_prtcl = (in_le32(&gur->rcwsr[28]) &
662 FSL_CHASSIS3_RCWSR28_SRDS2_PRTCL_MASK)
663 >> FSL_CHASSIS3_RCWSR28_SRDS2_PRTCL_SHIFT;
664
Prabhakar Kushwaha35f93f62015-08-07 18:01:51 +0530665 int *riser_phy_addr;
Simon Glass64b723f2017-08-03 12:22:12 -0600666 char *env_hwconfig = env_get("hwconfig");
Prabhakar Kushwaha35f93f62015-08-07 18:01:51 +0530667
668 if (hwconfig_f("xqsgmii", env_hwconfig))
669 riser_phy_addr = &xqsgii_riser_phy_addr[0];
670 else
671 riser_phy_addr = &sgmii_riser_phy_addr[0];
672
673 if (dpmac_id > WRIOP1_DPMAC9)
674 goto serdes2;
675
Prabhakar Kushwahac158fad2015-03-20 19:28:26 -0700676 switch (serdes1_prtcl) {
Prabhakar Kushwaha35f93f62015-08-07 18:01:51 +0530677 case 0x07:
Priyanka Jaine2da6232016-11-03 17:50:51 +0530678 case 0x39:
679 case 0x4D:
680 lane = serdes_get_first_lane(FSL_SRDS_1, SGMII1 + dpmac_id - 1);
Prabhakar Kushwaha35f93f62015-08-07 18:01:51 +0530681
Prabhakar Kushwaha35f93f62015-08-07 18:01:51 +0530682 slot = lane_to_slot_fsm1[lane];
683
684 switch (++slot) {
685 case 1:
686 /* Slot housing a SGMII riser card? */
Pankaj Bansal50adb5e2018-10-10 14:08:34 +0530687 wriop_set_phy_address(dpmac_id, 0,
Prabhakar Kushwaha35f93f62015-08-07 18:01:51 +0530688 riser_phy_addr[dpmac_id - 1]);
689 dpmac_info[dpmac_id].board_mux = EMI1_SLOT1;
690 bus = mii_dev_for_muxval(EMI1_SLOT1);
691 wriop_set_mdio(dpmac_id, bus);
Prabhakar Kushwaha35f93f62015-08-07 18:01:51 +0530692 break;
693 case 2:
694 /* Slot housing a SGMII riser card? */
Pankaj Bansal50adb5e2018-10-10 14:08:34 +0530695 wriop_set_phy_address(dpmac_id, 0,
Prabhakar Kushwaha35f93f62015-08-07 18:01:51 +0530696 riser_phy_addr[dpmac_id - 1]);
697 dpmac_info[dpmac_id].board_mux = EMI1_SLOT2;
698 bus = mii_dev_for_muxval(EMI1_SLOT2);
699 wriop_set_mdio(dpmac_id, bus);
Prabhakar Kushwaha35f93f62015-08-07 18:01:51 +0530700 break;
701 case 3:
Priyanka Jaine2da6232016-11-03 17:50:51 +0530702 if (slot == EMI_NONE)
703 return;
704 if (serdes1_prtcl == 0x39) {
Pankaj Bansal50adb5e2018-10-10 14:08:34 +0530705 wriop_set_phy_address(dpmac_id, 0,
Priyanka Jaine2da6232016-11-03 17:50:51 +0530706 riser_phy_addr[dpmac_id - 2]);
707 if (dpmac_id >= 6 && hwconfig_f("xqsgmii",
708 env_hwconfig))
Pankaj Bansal50adb5e2018-10-10 14:08:34 +0530709 wriop_set_phy_address(dpmac_id, 0,
Priyanka Jaine2da6232016-11-03 17:50:51 +0530710 riser_phy_addr[dpmac_id - 3]);
711 } else {
Pankaj Bansal50adb5e2018-10-10 14:08:34 +0530712 wriop_set_phy_address(dpmac_id, 0,
Priyanka Jaine2da6232016-11-03 17:50:51 +0530713 riser_phy_addr[dpmac_id - 2]);
714 if (dpmac_id >= 7 && hwconfig_f("xqsgmii",
715 env_hwconfig))
Pankaj Bansal50adb5e2018-10-10 14:08:34 +0530716 wriop_set_phy_address(dpmac_id, 0,
Priyanka Jaine2da6232016-11-03 17:50:51 +0530717 riser_phy_addr[dpmac_id - 3]);
718 }
719 dpmac_info[dpmac_id].board_mux = EMI1_SLOT3;
720 bus = mii_dev_for_muxval(EMI1_SLOT3);
721 wriop_set_mdio(dpmac_id, bus);
Prabhakar Kushwaha35f93f62015-08-07 18:01:51 +0530722 break;
723 case 4:
724 break;
725 case 5:
726 break;
727 case 6:
728 break;
729 }
730 break;
731 default:
Prabhakar Kushwahac5aa4ff2015-11-04 12:25:55 +0530732 printf("%s qds: WRIOP: Unsupported SerDes1 Protocol 0x%02x\n",
733 __func__ , serdes1_prtcl);
Prabhakar Kushwaha35f93f62015-08-07 18:01:51 +0530734 break;
Prabhakar Kushwahac158fad2015-03-20 19:28:26 -0700735 }
736
Prabhakar Kushwaha35f93f62015-08-07 18:01:51 +0530737serdes2:
Prabhakar Kushwahac158fad2015-03-20 19:28:26 -0700738 switch (serdes2_prtcl) {
739 case 0x07:
740 case 0x08:
Prabhakar Kushwaha2a6e5dc2015-05-28 14:53:57 +0530741 case 0x49:
Priyanka Jaine2da6232016-11-03 17:50:51 +0530742 case 0x47:
743 case 0x57:
Prabhakar Kushwahac158fad2015-03-20 19:28:26 -0700744 lane = serdes_get_first_lane(FSL_SRDS_2, SGMII9 +
745 (dpmac_id - 9));
746 slot = lane_to_slot_fsm2[lane];
747
748 switch (++slot) {
749 case 1:
750 break;
751 case 3:
752 break;
753 case 4:
754 /* Slot housing a SGMII riser card? */
Pankaj Bansal50adb5e2018-10-10 14:08:34 +0530755 wriop_set_phy_address(dpmac_id, 0,
Prabhakar Kushwahac158fad2015-03-20 19:28:26 -0700756 riser_phy_addr[dpmac_id - 9]);
757 dpmac_info[dpmac_id].board_mux = EMI1_SLOT4;
758 bus = mii_dev_for_muxval(EMI1_SLOT4);
759 wriop_set_mdio(dpmac_id, bus);
Prabhakar Kushwahac158fad2015-03-20 19:28:26 -0700760 break;
761 case 5:
Priyanka Jaine2da6232016-11-03 17:50:51 +0530762 if (slot == EMI_NONE)
763 return;
764 if (serdes2_prtcl == 0x47) {
Pankaj Bansal50adb5e2018-10-10 14:08:34 +0530765 wriop_set_phy_address(dpmac_id, 0,
Priyanka Jaine2da6232016-11-03 17:50:51 +0530766 riser_phy_addr[dpmac_id - 10]);
767 if (dpmac_id >= 14 && hwconfig_f("xqsgmii",
768 env_hwconfig))
Pankaj Bansal50adb5e2018-10-10 14:08:34 +0530769 wriop_set_phy_address(dpmac_id, 0,
Priyanka Jaine2da6232016-11-03 17:50:51 +0530770 riser_phy_addr[dpmac_id - 11]);
771 } else {
Pankaj Bansal50adb5e2018-10-10 14:08:34 +0530772 wriop_set_phy_address(dpmac_id, 0,
Priyanka Jaine2da6232016-11-03 17:50:51 +0530773 riser_phy_addr[dpmac_id - 11]);
774 }
775 dpmac_info[dpmac_id].board_mux = EMI1_SLOT5;
776 bus = mii_dev_for_muxval(EMI1_SLOT5);
777 wriop_set_mdio(dpmac_id, bus);
778 break;
Prabhakar Kushwahac158fad2015-03-20 19:28:26 -0700779 case 6:
780 /* Slot housing a SGMII riser card? */
Pankaj Bansal50adb5e2018-10-10 14:08:34 +0530781 wriop_set_phy_address(dpmac_id, 0,
Prabhakar Kushwahac158fad2015-03-20 19:28:26 -0700782 riser_phy_addr[dpmac_id - 13]);
783 dpmac_info[dpmac_id].board_mux = EMI1_SLOT6;
784 bus = mii_dev_for_muxval(EMI1_SLOT6);
785 wriop_set_mdio(dpmac_id, bus);
786 break;
787 }
788 break;
789 default:
Prabhakar Kushwahac5aa4ff2015-11-04 12:25:55 +0530790 printf("%s qds: WRIOP: Unsupported SerDes2 Protocol 0x%02x\n",
791 __func__, serdes2_prtcl);
Prabhakar Kushwahac158fad2015-03-20 19:28:26 -0700792 break;
793 }
Prabhakar Kushwaha35f93f62015-08-07 18:01:51 +0530794}
795
Prabhakar Kushwaha122bcfd2015-11-09 16:42:07 +0530796void ls2080a_handle_phy_interface_qsgmii(int dpmac_id)
Prabhakar Kushwaha35f93f62015-08-07 18:01:51 +0530797{
798 int lane = 0, slot;
799 struct mii_dev *bus;
800 struct ccsr_gur __iomem *gur = (void *)CONFIG_SYS_FSL_GUTS_ADDR;
801 int serdes1_prtcl = (in_le32(&gur->rcwsr[28]) &
802 FSL_CHASSIS3_RCWSR28_SRDS1_PRTCL_MASK)
803 >> FSL_CHASSIS3_RCWSR28_SRDS1_PRTCL_SHIFT;
804
805 switch (serdes1_prtcl) {
806 case 0x33:
807 switch (dpmac_id) {
808 case 1:
809 case 2:
810 case 3:
811 case 4:
812 lane = serdes_get_first_lane(FSL_SRDS_1, QSGMII_A);
813 break;
814 case 5:
815 case 6:
816 case 7:
817 case 8:
818 lane = serdes_get_first_lane(FSL_SRDS_1, QSGMII_B);
819 break;
820 case 9:
821 case 10:
822 case 11:
823 case 12:
824 lane = serdes_get_first_lane(FSL_SRDS_1, QSGMII_C);
825 break;
826 case 13:
827 case 14:
828 case 15:
829 case 16:
830 lane = serdes_get_first_lane(FSL_SRDS_1, QSGMII_D);
831 break;
832 }
833
834 slot = lane_to_slot_fsm1[lane];
835
836 switch (++slot) {
837 case 1:
838 /* Slot housing a QSGMII riser card? */
Pankaj Bansal50adb5e2018-10-10 14:08:34 +0530839 wriop_set_phy_address(dpmac_id, 0, dpmac_id - 1);
Prabhakar Kushwaha35f93f62015-08-07 18:01:51 +0530840 dpmac_info[dpmac_id].board_mux = EMI1_SLOT1;
841 bus = mii_dev_for_muxval(EMI1_SLOT1);
842 wriop_set_mdio(dpmac_id, bus);
Prabhakar Kushwaha35f93f62015-08-07 18:01:51 +0530843 break;
844 case 3:
845 break;
846 case 4:
847 break;
848 case 5:
849 break;
850 case 6:
851 break;
852 }
853 break;
854 default:
855 printf("qds: WRIOP: Unsupported SerDes Protocol 0x%02x\n",
856 serdes1_prtcl);
857 break;
858 }
859
860 qsgmii_configure_repeater(dpmac_id);
Prabhakar Kushwahac158fad2015-03-20 19:28:26 -0700861}
Prabhakar Kushwaha35f93f62015-08-07 18:01:51 +0530862
Prabhakar Kushwaha122bcfd2015-11-09 16:42:07 +0530863void ls2080a_handle_phy_interface_xsgmii(int i)
Prabhakar Kushwahac158fad2015-03-20 19:28:26 -0700864{
865 struct ccsr_gur __iomem *gur = (void *)CONFIG_SYS_FSL_GUTS_ADDR;
866 int serdes1_prtcl = (in_le32(&gur->rcwsr[28]) &
867 FSL_CHASSIS3_RCWSR28_SRDS1_PRTCL_MASK)
868 >> FSL_CHASSIS3_RCWSR28_SRDS1_PRTCL_SHIFT;
869
870 switch (serdes1_prtcl) {
871 case 0x2A:
Priyanka Jaine2da6232016-11-03 17:50:51 +0530872 case 0x4B:
873 case 0x4C:
Prabhakar Kushwahac158fad2015-03-20 19:28:26 -0700874 /*
Bin Meng75574052016-02-05 19:30:11 -0800875 * XFI does not need a PHY to work, but to avoid U-Boot use
Prabhakar Kushwahac158fad2015-03-20 19:28:26 -0700876 * default PHY address which is zero to a MAC when it found
877 * a MAC has no PHY address, we give a PHY address to XFI
878 * MAC, and should not use a real XAUI PHY address, since
879 * MDIO can access it successfully, and then MDIO thinks
880 * the XAUI card is used for the XFI MAC, which will cause
881 * error.
882 */
Pankaj Bansal50adb5e2018-10-10 14:08:34 +0530883 wriop_set_phy_address(i, 0, i + 4);
Prabhakar Kushwaha122bcfd2015-11-09 16:42:07 +0530884 ls2080a_qds_enable_SFP_TX(SFP_TX);
Prabhakar Kushwahac158fad2015-03-20 19:28:26 -0700885
886 break;
887 default:
888 printf("qds: WRIOP: Unsupported SerDes Protocol 0x%02x\n",
889 serdes1_prtcl);
890 break;
891 }
892}
893#endif
894
895int board_eth_init(bd_t *bis)
896{
897 int error;
Santan Kumar1afa9002017-05-05 15:42:29 +0530898#if defined(CONFIG_FSL_MC_ENET) && !defined(CONFIG_SPL_BUILD)
Prabhakar Kushwaha35f93f62015-08-07 18:01:51 +0530899 struct ccsr_gur __iomem *gur = (void *)CONFIG_SYS_FSL_GUTS_ADDR;
900 int serdes1_prtcl = (in_le32(&gur->rcwsr[28]) &
901 FSL_CHASSIS3_RCWSR28_SRDS1_PRTCL_MASK)
902 >> FSL_CHASSIS3_RCWSR28_SRDS1_PRTCL_SHIFT;
903 int serdes2_prtcl = (in_le32(&gur->rcwsr[28]) &
904 FSL_CHASSIS3_RCWSR28_SRDS2_PRTCL_MASK)
905 >> FSL_CHASSIS3_RCWSR28_SRDS2_PRTCL_SHIFT;
906
Prabhakar Kushwahac158fad2015-03-20 19:28:26 -0700907 struct memac_mdio_info *memac_mdio0_info;
908 struct memac_mdio_info *memac_mdio1_info;
909 unsigned int i;
Prabhakar Kushwaha35f93f62015-08-07 18:01:51 +0530910 char *env_hwconfig;
911
Simon Glass64b723f2017-08-03 12:22:12 -0600912 env_hwconfig = env_get("hwconfig");
Prabhakar Kushwahac158fad2015-03-20 19:28:26 -0700913
914 initialize_dpmac_to_slot();
915
916 memac_mdio0_info = (struct memac_mdio_info *)malloc(
917 sizeof(struct memac_mdio_info));
918 memac_mdio0_info->regs =
919 (struct memac_mdio_controller *)
920 CONFIG_SYS_FSL_WRIOP1_MDIO1;
921 memac_mdio0_info->name = DEFAULT_WRIOP_MDIO1_NAME;
922
923 /* Register the real MDIO1 bus */
924 fm_memac_mdio_init(bis, memac_mdio0_info);
925
926 memac_mdio1_info = (struct memac_mdio_info *)malloc(
927 sizeof(struct memac_mdio_info));
928 memac_mdio1_info->regs =
929 (struct memac_mdio_controller *)
930 CONFIG_SYS_FSL_WRIOP1_MDIO2;
931 memac_mdio1_info->name = DEFAULT_WRIOP_MDIO2_NAME;
932
933 /* Register the real MDIO2 bus */
934 fm_memac_mdio_init(bis, memac_mdio1_info);
935
936 /* Register the muxing front-ends to the MDIO buses */
Prabhakar Kushwaha122bcfd2015-11-09 16:42:07 +0530937 ls2080a_qds_mdio_init(DEFAULT_WRIOP_MDIO1_NAME, EMI1_SLOT1);
938 ls2080a_qds_mdio_init(DEFAULT_WRIOP_MDIO1_NAME, EMI1_SLOT2);
939 ls2080a_qds_mdio_init(DEFAULT_WRIOP_MDIO1_NAME, EMI1_SLOT3);
940 ls2080a_qds_mdio_init(DEFAULT_WRIOP_MDIO1_NAME, EMI1_SLOT4);
941 ls2080a_qds_mdio_init(DEFAULT_WRIOP_MDIO1_NAME, EMI1_SLOT5);
942 ls2080a_qds_mdio_init(DEFAULT_WRIOP_MDIO1_NAME, EMI1_SLOT6);
Prabhakar Kushwahac158fad2015-03-20 19:28:26 -0700943
Prabhakar Kushwaha122bcfd2015-11-09 16:42:07 +0530944 ls2080a_qds_mdio_init(DEFAULT_WRIOP_MDIO2_NAME, EMI2);
Prabhakar Kushwahac158fad2015-03-20 19:28:26 -0700945
946 for (i = WRIOP1_DPMAC1; i < NUM_WRIOP_PORTS; i++) {
947 switch (wriop_get_enet_if(i)) {
948 case PHY_INTERFACE_MODE_QSGMII:
Prabhakar Kushwaha122bcfd2015-11-09 16:42:07 +0530949 ls2080a_handle_phy_interface_qsgmii(i);
Prabhakar Kushwahac158fad2015-03-20 19:28:26 -0700950 break;
951 case PHY_INTERFACE_MODE_SGMII:
Prabhakar Kushwaha122bcfd2015-11-09 16:42:07 +0530952 ls2080a_handle_phy_interface_sgmii(i);
Prabhakar Kushwahac158fad2015-03-20 19:28:26 -0700953 break;
954 case PHY_INTERFACE_MODE_XGMII:
Prabhakar Kushwaha122bcfd2015-11-09 16:42:07 +0530955 ls2080a_handle_phy_interface_xsgmii(i);
Prabhakar Kushwahac158fad2015-03-20 19:28:26 -0700956 break;
957 default:
958 break;
Prabhakar Kushwaha35f93f62015-08-07 18:01:51 +0530959
960 if (i == 16)
961 i = NUM_WRIOP_PORTS;
Prabhakar Kushwahac158fad2015-03-20 19:28:26 -0700962 }
963 }
964
965 error = cpu_eth_init(bis);
Prabhakar Kushwaha35f93f62015-08-07 18:01:51 +0530966
967 if (hwconfig_f("xqsgmii", env_hwconfig)) {
968 if (serdes1_prtcl == 0x7)
969 sgmii_configure_repeater(1);
970 if (serdes2_prtcl == 0x7 || serdes2_prtcl == 0x8 ||
971 serdes2_prtcl == 0x49)
972 sgmii_configure_repeater(2);
973 }
Prabhakar Kushwahac158fad2015-03-20 19:28:26 -0700974#endif
975 error = pci_eth_init(bis);
976 return error;
977}
Prabhakar Kushwaha35f93f62015-08-07 18:01:51 +0530978
Bogdan Purcareata08bc0142017-05-24 16:40:21 +0000979#if defined(CONFIG_RESET_PHY_R)
980void reset_phy(void)
981{
982 mc_env_boot();
983}
984#endif /* CONFIG_RESET_PHY_R */