blob: 1d40e8bd17025a4cafa2903e4094674847061de3 [file] [log] [blame]
Tom Rini10e47792018-05-06 17:58:06 -04001// SPDX-License-Identifier: GPL-2.0+
Shaohui Xie085ac1c2016-09-07 17:56:14 +08002/*
3 * Copyright 2016 Freescale Semiconductor, Inc.
Florinel Iordache01082c32020-03-16 15:36:00 +02004 * Copyright 2018-2020 NXP
Shaohui Xie085ac1c2016-09-07 17:56:14 +08005 */
6
7#include <common.h>
8#include <asm/io.h>
9#include <netdev.h>
10#include <fdt_support.h>
11#include <fm_eth.h>
12#include <fsl_mdio.h>
13#include <fsl_dtsec.h>
14#include <malloc.h>
15#include <asm/arch/fsl_serdes.h>
16
17#include "../common/qixis.h"
18#include "../common/fman.h"
19#include "ls1046aqds_qixis.h"
20
21#define EMI_NONE 0xFF
22#define EMI1_RGMII1 0
23#define EMI1_RGMII2 1
24#define EMI1_SLOT1 2
25#define EMI1_SLOT2 3
26#define EMI1_SLOT4 4
27
28static int mdio_mux[NUM_FM_PORTS];
29
30static const char * const mdio_names[] = {
31 "LS1046AQDS_MDIO_RGMII1",
32 "LS1046AQDS_MDIO_RGMII2",
33 "LS1046AQDS_MDIO_SLOT1",
34 "LS1046AQDS_MDIO_SLOT2",
35 "LS1046AQDS_MDIO_SLOT4",
36 "NULL",
37};
38
39/* Map SerDes 1 & 2 lanes to default slot. */
40static u8 lane_to_slot[] = {1, 1, 1, 1, 0, 4, 0 , 0};
41
42static const char *ls1046aqds_mdio_name_for_muxval(u8 muxval)
43{
44 return mdio_names[muxval];
45}
46
47struct mii_dev *mii_dev_for_muxval(u8 muxval)
48{
49 struct mii_dev *bus;
50 const char *name;
51
52 if (muxval > EMI1_SLOT4)
53 return NULL;
54
55 name = ls1046aqds_mdio_name_for_muxval(muxval);
56
57 if (!name) {
58 printf("No bus for muxval %x\n", muxval);
59 return NULL;
60 }
61
62 bus = miiphy_get_dev_by_name(name);
63
64 if (!bus) {
65 printf("No bus by name %s\n", name);
66 return NULL;
67 }
68
69 return bus;
70}
71
72struct ls1046aqds_mdio {
73 u8 muxval;
74 struct mii_dev *realbus;
75};
76
77static void ls1046aqds_mux_mdio(u8 muxval)
78{
79 u8 brdcfg4;
80
81 if (muxval < 7) {
82 brdcfg4 = QIXIS_READ(brdcfg[4]);
83 brdcfg4 &= ~BRDCFG4_EMISEL_MASK;
84 brdcfg4 |= (muxval << BRDCFG4_EMISEL_SHIFT);
85 QIXIS_WRITE(brdcfg[4], brdcfg4);
86 }
87}
88
89static int ls1046aqds_mdio_read(struct mii_dev *bus, int addr, int devad,
90 int regnum)
91{
92 struct ls1046aqds_mdio *priv = bus->priv;
93
94 ls1046aqds_mux_mdio(priv->muxval);
95
96 return priv->realbus->read(priv->realbus, addr, devad, regnum);
97}
98
99static int ls1046aqds_mdio_write(struct mii_dev *bus, int addr, int devad,
100 int regnum, u16 value)
101{
102 struct ls1046aqds_mdio *priv = bus->priv;
103
104 ls1046aqds_mux_mdio(priv->muxval);
105
106 return priv->realbus->write(priv->realbus, addr, devad,
107 regnum, value);
108}
109
110static int ls1046aqds_mdio_reset(struct mii_dev *bus)
111{
112 struct ls1046aqds_mdio *priv = bus->priv;
113
114 return priv->realbus->reset(priv->realbus);
115}
116
117static int ls1046aqds_mdio_init(char *realbusname, u8 muxval)
118{
119 struct ls1046aqds_mdio *pmdio;
120 struct mii_dev *bus = mdio_alloc();
121
122 if (!bus) {
123 printf("Failed to allocate ls1046aqds MDIO bus\n");
124 return -1;
125 }
126
127 pmdio = malloc(sizeof(*pmdio));
128 if (!pmdio) {
129 printf("Failed to allocate ls1046aqds private data\n");
130 free(bus);
131 return -1;
132 }
133
134 bus->read = ls1046aqds_mdio_read;
135 bus->write = ls1046aqds_mdio_write;
136 bus->reset = ls1046aqds_mdio_reset;
137 sprintf(bus->name, ls1046aqds_mdio_name_for_muxval(muxval));
138
139 pmdio->realbus = miiphy_get_dev_by_name(realbusname);
140
141 if (!pmdio->realbus) {
142 printf("No bus with name %s\n", realbusname);
143 free(bus);
144 free(pmdio);
145 return -1;
146 }
147
148 pmdio->muxval = muxval;
149 bus->priv = pmdio;
150 return mdio_register(bus);
151}
152
153void board_ft_fman_fixup_port(void *fdt, char *compat, phys_addr_t addr,
154 enum fm_port port, int offset)
155{
156 struct fixed_link f_link;
Florinel Iordache01082c32020-03-16 15:36:00 +0200157 const char *phyconn;
Shaohui Xie085ac1c2016-09-07 17:56:14 +0800158
159 if (fm_info_get_enet_if(port) == PHY_INTERFACE_MODE_SGMII) {
160 switch (port) {
161 case FM1_DTSEC9:
Pankaj Bansalc8861b62019-04-22 06:31:42 +0000162 fdt_set_phy_handle(fdt, compat, addr, "sgmii-s1-p1");
Shaohui Xie085ac1c2016-09-07 17:56:14 +0800163 break;
164 case FM1_DTSEC10:
Pankaj Bansalc8861b62019-04-22 06:31:42 +0000165 fdt_set_phy_handle(fdt, compat, addr, "sgmii-s1-p2");
Shaohui Xie085ac1c2016-09-07 17:56:14 +0800166 break;
167 case FM1_DTSEC5:
Pankaj Bansalc8861b62019-04-22 06:31:42 +0000168 fdt_set_phy_handle(fdt, compat, addr, "sgmii-s1-p3");
Shaohui Xie085ac1c2016-09-07 17:56:14 +0800169 break;
170 case FM1_DTSEC6:
Pankaj Bansalc8861b62019-04-22 06:31:42 +0000171 fdt_set_phy_handle(fdt, compat, addr, "sgmii-s1-p4");
Shaohui Xie085ac1c2016-09-07 17:56:14 +0800172 break;
173 case FM1_DTSEC2:
Pankaj Bansalc8861b62019-04-22 06:31:42 +0000174 fdt_set_phy_handle(fdt, compat, addr, "sgmii-s4-p1");
Shaohui Xie085ac1c2016-09-07 17:56:14 +0800175 break;
176 default:
177 break;
178 }
179 } else if (fm_info_get_enet_if(port) == PHY_INTERFACE_MODE_SGMII_2500) {
180 /* 2.5G SGMII interface */
181 f_link.phy_id = cpu_to_fdt32(port);
182 f_link.duplex = cpu_to_fdt32(1);
183 f_link.link_speed = cpu_to_fdt32(1000);
184 f_link.pause = 0;
185 f_link.asym_pause = 0;
186 /* no PHY for 2.5G SGMII on QDS */
187 fdt_delprop(fdt, offset, "phy-handle");
188 fdt_setprop(fdt, offset, "fixed-link", &f_link, sizeof(f_link));
189 fdt_setprop_string(fdt, offset, "phy-connection-type",
190 "sgmii-2500");
191 } else if (fm_info_get_enet_if(port) == PHY_INTERFACE_MODE_QSGMII) {
192 switch (port) {
193 case FM1_DTSEC1:
Pankaj Bansalc8861b62019-04-22 06:31:42 +0000194 fdt_set_phy_handle(fdt, compat, addr, "qsgmii-s2-p4");
Shaohui Xie085ac1c2016-09-07 17:56:14 +0800195 break;
196 case FM1_DTSEC5:
Pankaj Bansalc8861b62019-04-22 06:31:42 +0000197 fdt_set_phy_handle(fdt, compat, addr, "qsgmii-s2-p2");
Shaohui Xie085ac1c2016-09-07 17:56:14 +0800198 break;
199 case FM1_DTSEC6:
Pankaj Bansalc8861b62019-04-22 06:31:42 +0000200 fdt_set_phy_handle(fdt, compat, addr, "qsgmii-s2-p1");
Shaohui Xie085ac1c2016-09-07 17:56:14 +0800201 break;
202 case FM1_DTSEC10:
Pankaj Bansalc8861b62019-04-22 06:31:42 +0000203 fdt_set_phy_handle(fdt, compat, addr, "qsgmii-s2-p3");
Shaohui Xie085ac1c2016-09-07 17:56:14 +0800204 break;
205 default:
206 break;
207 }
208 fdt_delprop(fdt, offset, "phy-connection-type");
209 fdt_setprop_string(fdt, offset, "phy-connection-type",
210 "qsgmii");
211 } else if (fm_info_get_enet_if(port) == PHY_INTERFACE_MODE_XGMII &&
212 (port == FM1_10GEC1 || port == FM1_10GEC2)) {
Florinel Iordache01082c32020-03-16 15:36:00 +0200213 phyconn = fdt_getprop(fdt, offset, "phy-connection-type", NULL);
214 if (is_backplane_mode(phyconn)) {
215 /* Backplane KR mode: skip fixups */
216 printf("Interface %d in backplane KR mode\n", port);
217 } else {
Florinel Iordache097ec7e2018-12-10 09:27:31 +0000218 /* XFI interface */
219 f_link.phy_id = cpu_to_fdt32(port);
220 f_link.duplex = cpu_to_fdt32(1);
221 f_link.link_speed = cpu_to_fdt32(10000);
222 f_link.pause = 0;
223 f_link.asym_pause = 0;
224 /* no PHY for XFI */
225 fdt_delprop(fdt, offset, "phy-handle");
226 fdt_setprop(fdt, offset, "fixed-link", &f_link,
227 sizeof(f_link));
228 fdt_setprop_string(fdt, offset, "phy-connection-type",
229 "xgmii");
230 }
Shaohui Xie085ac1c2016-09-07 17:56:14 +0800231 }
232}
233
234void fdt_fixup_board_enet(void *fdt)
235{
236 int i;
237
238 for (i = FM1_DTSEC1; i < NUM_FM_PORTS; i++) {
239 switch (fm_info_get_enet_if(i)) {
240 case PHY_INTERFACE_MODE_SGMII:
241 case PHY_INTERFACE_MODE_QSGMII:
242 switch (mdio_mux[i]) {
243 case EMI1_SLOT1:
Pankaj Bansalc8861b62019-04-22 06:31:42 +0000244 fdt_status_okay_by_alias(fdt, "emi1-slot1");
Shaohui Xie085ac1c2016-09-07 17:56:14 +0800245 break;
246 case EMI1_SLOT2:
Pankaj Bansalc8861b62019-04-22 06:31:42 +0000247 fdt_status_okay_by_alias(fdt, "emi1-slot2");
Shaohui Xie085ac1c2016-09-07 17:56:14 +0800248 break;
249 case EMI1_SLOT4:
Pankaj Bansalc8861b62019-04-22 06:31:42 +0000250 fdt_status_okay_by_alias(fdt, "emi1-slot4");
Shaohui Xie085ac1c2016-09-07 17:56:14 +0800251 break;
252 default:
253 break;
254 }
255 break;
256 default:
257 break;
258 }
259 }
260}
261
262int board_eth_init(bd_t *bis)
263{
264#ifdef CONFIG_FMAN_ENET
265 int i, idx, lane, slot, interface;
266 struct memac_mdio_info dtsec_mdio_info;
267 struct ccsr_gur *gur = (void *)(CONFIG_SYS_FSL_GUTS_ADDR);
268 u32 srds_s1, srds_s2;
269 u8 brdcfg12;
270
271 srds_s1 = in_be32(&gur->rcwsr[4]) &
272 FSL_CHASSIS2_RCWSR4_SRDS1_PRTCL_MASK;
273 srds_s1 >>= FSL_CHASSIS2_RCWSR4_SRDS1_PRTCL_SHIFT;
274
275 srds_s2 = in_be32(&gur->rcwsr[4]) &
276 FSL_CHASSIS2_RCWSR4_SRDS2_PRTCL_MASK;
277 srds_s2 >>= FSL_CHASSIS2_RCWSR4_SRDS2_PRTCL_SHIFT;
278
279 /* Initialize the mdio_mux array so we can recognize empty elements */
280 for (i = 0; i < NUM_FM_PORTS; i++)
281 mdio_mux[i] = EMI_NONE;
282
283 dtsec_mdio_info.regs =
284 (struct memac_mdio_controller *)CONFIG_SYS_FM1_DTSEC_MDIO_ADDR;
285
286 dtsec_mdio_info.name = DEFAULT_FM_MDIO_NAME;
287
288 /* Register the 1G MDIO bus */
289 fm_memac_mdio_init(bis, &dtsec_mdio_info);
290
291 /* Register the muxing front-ends to the MDIO buses */
292 ls1046aqds_mdio_init(DEFAULT_FM_MDIO_NAME, EMI1_RGMII1);
293 ls1046aqds_mdio_init(DEFAULT_FM_MDIO_NAME, EMI1_RGMII2);
294 ls1046aqds_mdio_init(DEFAULT_FM_MDIO_NAME, EMI1_SLOT1);
295 ls1046aqds_mdio_init(DEFAULT_FM_MDIO_NAME, EMI1_SLOT2);
296 ls1046aqds_mdio_init(DEFAULT_FM_MDIO_NAME, EMI1_SLOT4);
297
298 /* Set the two on-board RGMII PHY address */
299 fm_info_set_phy_address(FM1_DTSEC3, RGMII_PHY1_ADDR);
300 fm_info_set_phy_address(FM1_DTSEC4, RGMII_PHY2_ADDR);
301
302 switch (srds_s1) {
303 case 0x3333:
304 /* SGMII on slot 1, MAC 9 */
305 fm_info_set_phy_address(FM1_DTSEC9, SGMII_CARD_PORT1_PHY_ADDR);
306 case 0x1333:
307 case 0x2333:
308 /* SGMII on slot 1, MAC 10 */
309 fm_info_set_phy_address(FM1_DTSEC10, SGMII_CARD_PORT2_PHY_ADDR);
310 case 0x1133:
311 case 0x2233:
312 /* SGMII on slot 1, MAC 5/6 */
313 fm_info_set_phy_address(FM1_DTSEC5, SGMII_CARD_PORT3_PHY_ADDR);
314 fm_info_set_phy_address(FM1_DTSEC6, SGMII_CARD_PORT4_PHY_ADDR);
315 break;
316 case 0x1040:
317 case 0x2040:
318 /* QSGMII on lane B, MAC 6/5/10/1 */
319 fm_info_set_phy_address(FM1_DTSEC6,
320 QSGMII_CARD_PORT1_PHY_ADDR_S2);
321 fm_info_set_phy_address(FM1_DTSEC5,
322 QSGMII_CARD_PORT2_PHY_ADDR_S2);
323 fm_info_set_phy_address(FM1_DTSEC10,
324 QSGMII_CARD_PORT3_PHY_ADDR_S2);
325 fm_info_set_phy_address(FM1_DTSEC1,
326 QSGMII_CARD_PORT4_PHY_ADDR_S2);
327 break;
328 case 0x3363:
329 /* SGMII on slot 1, MAC 9/10 */
330 fm_info_set_phy_address(FM1_DTSEC9, SGMII_CARD_PORT1_PHY_ADDR);
331 fm_info_set_phy_address(FM1_DTSEC10, SGMII_CARD_PORT2_PHY_ADDR);
332 case 0x1163:
333 case 0x2263:
334 case 0x2223:
335 /* SGMII on slot 1, MAC 6 */
336 fm_info_set_phy_address(FM1_DTSEC6, SGMII_CARD_PORT4_PHY_ADDR);
337 break;
338 default:
339 printf("Invalid SerDes protocol 0x%x for LS1046AQDS\n",
340 srds_s1);
341 break;
342 }
343
344 if (srds_s2 == 0x5a59 || srds_s2 == 0x5a06)
345 /* SGMII on slot 4, MAC 2 */
346 fm_info_set_phy_address(FM1_DTSEC2, SGMII_CARD_PORT1_PHY_ADDR);
347
348 for (i = FM1_DTSEC1; i < FM1_DTSEC1 + CONFIG_SYS_NUM_FM1_DTSEC; i++) {
349 idx = i - FM1_DTSEC1;
350 interface = fm_info_get_enet_if(i);
351 switch (interface) {
352 case PHY_INTERFACE_MODE_SGMII:
353 case PHY_INTERFACE_MODE_QSGMII:
354 if (interface == PHY_INTERFACE_MODE_SGMII) {
355 if (i == FM1_DTSEC5) {
356 /* route lane 2 to slot1 so to have
357 * one sgmii riser card supports
358 * MAC5 and MAC6.
359 */
360 brdcfg12 = QIXIS_READ(brdcfg[12]);
361 QIXIS_WRITE(brdcfg[12],
362 brdcfg12 | 0x80);
363 }
364 lane = serdes_get_first_lane(FSL_SRDS_1,
365 SGMII_FM1_DTSEC1 + idx);
366 } else {
367 /* clear the bit 7 to route lane B on slot2. */
368 brdcfg12 = QIXIS_READ(brdcfg[12]);
369 QIXIS_WRITE(brdcfg[12], brdcfg12 & 0x7f);
370
371 lane = serdes_get_first_lane(FSL_SRDS_1,
372 QSGMII_FM1_A);
373 lane_to_slot[lane] = 2;
374 }
375
376 if (i == FM1_DTSEC2)
377 lane = 5;
378
379 if (lane < 0)
380 break;
381
382 slot = lane_to_slot[lane];
383 debug("FM1@DTSEC%u expects SGMII in slot %u\n",
384 idx + 1, slot);
385 if (QIXIS_READ(present2) & (1 << (slot - 1)))
386 fm_disable_port(i);
387
388 switch (slot) {
389 case 1:
390 mdio_mux[i] = EMI1_SLOT1;
391 fm_info_set_mdio(i, mii_dev_for_muxval(
392 mdio_mux[i]));
393 break;
394 case 2:
395 mdio_mux[i] = EMI1_SLOT2;
396 fm_info_set_mdio(i, mii_dev_for_muxval(
397 mdio_mux[i]));
398 break;
399 case 4:
400 mdio_mux[i] = EMI1_SLOT4;
401 fm_info_set_mdio(i, mii_dev_for_muxval(
402 mdio_mux[i]));
403 break;
404 default:
405 break;
406 }
407 break;
408 case PHY_INTERFACE_MODE_RGMII:
Madalin Bucured50c442017-08-18 11:37:20 +0300409 case PHY_INTERFACE_MODE_RGMII_TXID:
Shaohui Xie085ac1c2016-09-07 17:56:14 +0800410 if (i == FM1_DTSEC3)
411 mdio_mux[i] = EMI1_RGMII1;
412 else if (i == FM1_DTSEC4)
413 mdio_mux[i] = EMI1_RGMII2;
414 fm_info_set_mdio(i, mii_dev_for_muxval(mdio_mux[i]));
415 break;
416 default:
417 break;
418 }
419 }
420
421 cpu_eth_init(bis);
422#endif /* CONFIG_FMAN_ENET */
423
424 return pci_eth_init(bis);
425}