blob: 697c23b03886084b6ab64a31760f351342b28cb9 [file] [log] [blame]
Tom Rini83d290c2018-05-06 17:58:06 -04001// SPDX-License-Identifier: GPL-2.0+
Shengzhou Liuc4d0e812013-11-22 17:39:11 +08002/*
3 * Copyright 2013 Freescale Semiconductor, Inc.
Florinel Iordachee174fb72020-03-16 15:36:02 +02004 * Copyright 2020 NXP
Shengzhou Liuc4d0e812013-11-22 17:39:11 +08005 *
6 * Shengzhou Liu <Shengzhou.Liu@freescale.com>
Shengzhou Liuc4d0e812013-11-22 17:39:11 +08007 */
8
9#include <common.h>
10#include <command.h>
11#include <netdev.h>
12#include <asm/mmu.h>
13#include <asm/processor.h>
14#include <asm/immap_85xx.h>
15#include <asm/fsl_law.h>
16#include <asm/fsl_serdes.h>
17#include <asm/fsl_portals.h>
18#include <asm/fsl_liodn.h>
19#include <malloc.h>
20#include <fm_eth.h>
21#include <fsl_mdio.h>
22#include <miiphy.h>
23#include <phy.h>
Shaohui Xie8225b2f2015-10-26 19:47:47 +080024#include <fsl_dtsec.h>
Shengzhou Liuc4d0e812013-11-22 17:39:11 +080025#include <asm/fsl_serdes.h>
shaohui xief0644da2014-10-20 19:48:19 +080026#include <hwconfig.h>
Shengzhou Liuc4d0e812013-11-22 17:39:11 +080027#include "../common/qixis.h"
28#include "../common/fman.h"
Shengzhou Liu254887a2014-02-21 13:16:19 +080029#include "t208xqds_qixis.h"
Shengzhou Liuc4d0e812013-11-22 17:39:11 +080030
31#define EMI_NONE 0xFFFFFFFF
32#define EMI1_RGMII1 0
33#define EMI1_RGMII2 1
34#define EMI1_SLOT1 2
York Sun80d26182016-12-28 08:43:36 -080035#if defined(CONFIG_TARGET_T2080QDS)
Shengzhou Liuc4d0e812013-11-22 17:39:11 +080036#define EMI1_SLOT2 6
37#define EMI1_SLOT3 3
38#define EMI1_SLOT4 4
39#define EMI1_SLOT5 5
Shengzhou Liu6b7679c2014-03-06 15:07:39 +080040#define EMI2 7
York Sun146ded42016-12-28 08:43:38 -080041#elif defined(CONFIG_TARGET_T2081QDS)
Shengzhou Liu254887a2014-02-21 13:16:19 +080042#define EMI1_SLOT2 3
43#define EMI1_SLOT3 4
44#define EMI1_SLOT5 5
45#define EMI1_SLOT6 6
46#define EMI1_SLOT7 7
Shengzhou Liu254887a2014-02-21 13:16:19 +080047#define EMI2 8
Shengzhou Liu6b7679c2014-03-06 15:07:39 +080048#endif
Shengzhou Liuc4d0e812013-11-22 17:39:11 +080049
Shaohui Xie3ce21c82014-10-20 19:51:21 +080050#define PCCR1_SGMIIA_KX_MASK 0x00008000
51#define PCCR1_SGMIIB_KX_MASK 0x00004000
52#define PCCR1_SGMIIC_KX_MASK 0x00002000
53#define PCCR1_SGMIID_KX_MASK 0x00001000
54#define PCCR1_SGMIIE_KX_MASK 0x00000800
55#define PCCR1_SGMIIF_KX_MASK 0x00000400
56#define PCCR1_SGMIIG_KX_MASK 0x00000200
57#define PCCR1_SGMIIH_KX_MASK 0x00000100
58
Shengzhou Liuc4d0e812013-11-22 17:39:11 +080059static int mdio_mux[NUM_FM_PORTS];
60
61static const char * const mdio_names[] = {
York Sun80d26182016-12-28 08:43:36 -080062#if defined(CONFIG_TARGET_T2080QDS)
Shengzhou Liuc4d0e812013-11-22 17:39:11 +080063 "T2080QDS_MDIO_RGMII1",
64 "T2080QDS_MDIO_RGMII2",
65 "T2080QDS_MDIO_SLOT1",
66 "T2080QDS_MDIO_SLOT3",
67 "T2080QDS_MDIO_SLOT4",
68 "T2080QDS_MDIO_SLOT5",
69 "T2080QDS_MDIO_SLOT2",
70 "T2080QDS_MDIO_10GC",
York Sun146ded42016-12-28 08:43:38 -080071#elif defined(CONFIG_TARGET_T2081QDS)
Shengzhou Liu254887a2014-02-21 13:16:19 +080072 "T2081QDS_MDIO_RGMII1",
73 "T2081QDS_MDIO_RGMII2",
74 "T2081QDS_MDIO_SLOT1",
75 "T2081QDS_MDIO_SLOT2",
76 "T2081QDS_MDIO_SLOT3",
77 "T2081QDS_MDIO_SLOT5",
78 "T2081QDS_MDIO_SLOT6",
79 "T2081QDS_MDIO_SLOT7",
80 "T2081QDS_MDIO_10GC",
81#endif
Shengzhou Liuc4d0e812013-11-22 17:39:11 +080082};
83
84/* Map SerDes1 8 lanes to default slot, will be initialized dynamically */
York Sun80d26182016-12-28 08:43:36 -080085#if defined(CONFIG_TARGET_T2080QDS)
Shengzhou Liuc4d0e812013-11-22 17:39:11 +080086static u8 lane_to_slot[] = {3, 3, 3, 3, 1, 1, 1, 1};
York Sun146ded42016-12-28 08:43:38 -080087#elif defined(CONFIG_TARGET_T2081QDS)
Shengzhou Liu254887a2014-02-21 13:16:19 +080088static u8 lane_to_slot[] = {2, 2, 2, 2, 1, 1, 1, 1};
89#endif
Shengzhou Liuc4d0e812013-11-22 17:39:11 +080090
Shengzhou Liu254887a2014-02-21 13:16:19 +080091static const char *t208xqds_mdio_name_for_muxval(u8 muxval)
Shengzhou Liuc4d0e812013-11-22 17:39:11 +080092{
93 return mdio_names[muxval];
94}
95
96struct mii_dev *mii_dev_for_muxval(u8 muxval)
97{
98 struct mii_dev *bus;
Shengzhou Liu254887a2014-02-21 13:16:19 +080099 const char *name = t208xqds_mdio_name_for_muxval(muxval);
Shengzhou Liuc4d0e812013-11-22 17:39:11 +0800100
101 if (!name) {
102 printf("No bus for muxval %x\n", muxval);
103 return NULL;
104 }
105
106 bus = miiphy_get_dev_by_name(name);
107
108 if (!bus) {
109 printf("No bus by name %s\n", name);
110 return NULL;
111 }
112
113 return bus;
114}
115
Shengzhou Liu254887a2014-02-21 13:16:19 +0800116struct t208xqds_mdio {
Shengzhou Liuc4d0e812013-11-22 17:39:11 +0800117 u8 muxval;
118 struct mii_dev *realbus;
119};
120
Shengzhou Liu254887a2014-02-21 13:16:19 +0800121static void t208xqds_mux_mdio(u8 muxval)
Shengzhou Liuc4d0e812013-11-22 17:39:11 +0800122{
123 u8 brdcfg4;
Shengzhou Liu254887a2014-02-21 13:16:19 +0800124 if (muxval < 8) {
Shengzhou Liuc4d0e812013-11-22 17:39:11 +0800125 brdcfg4 = QIXIS_READ(brdcfg[4]);
126 brdcfg4 &= ~BRDCFG4_EMISEL_MASK;
127 brdcfg4 |= (muxval << BRDCFG4_EMISEL_SHIFT);
128 QIXIS_WRITE(brdcfg[4], brdcfg4);
129 }
130}
131
Shengzhou Liu254887a2014-02-21 13:16:19 +0800132static int t208xqds_mdio_read(struct mii_dev *bus, int addr, int devad,
Shengzhou Liuc4d0e812013-11-22 17:39:11 +0800133 int regnum)
134{
Shengzhou Liu254887a2014-02-21 13:16:19 +0800135 struct t208xqds_mdio *priv = bus->priv;
Shengzhou Liuc4d0e812013-11-22 17:39:11 +0800136
Shengzhou Liu254887a2014-02-21 13:16:19 +0800137 t208xqds_mux_mdio(priv->muxval);
Shengzhou Liuc4d0e812013-11-22 17:39:11 +0800138
139 return priv->realbus->read(priv->realbus, addr, devad, regnum);
140}
141
Shengzhou Liu254887a2014-02-21 13:16:19 +0800142static int t208xqds_mdio_write(struct mii_dev *bus, int addr, int devad,
Shengzhou Liuc4d0e812013-11-22 17:39:11 +0800143 int regnum, u16 value)
144{
Shengzhou Liu254887a2014-02-21 13:16:19 +0800145 struct t208xqds_mdio *priv = bus->priv;
Shengzhou Liuc4d0e812013-11-22 17:39:11 +0800146
Shengzhou Liu254887a2014-02-21 13:16:19 +0800147 t208xqds_mux_mdio(priv->muxval);
Shengzhou Liuc4d0e812013-11-22 17:39:11 +0800148
149 return priv->realbus->write(priv->realbus, addr, devad, regnum, value);
150}
151
Shengzhou Liu254887a2014-02-21 13:16:19 +0800152static int t208xqds_mdio_reset(struct mii_dev *bus)
Shengzhou Liuc4d0e812013-11-22 17:39:11 +0800153{
Shengzhou Liu254887a2014-02-21 13:16:19 +0800154 struct t208xqds_mdio *priv = bus->priv;
Shengzhou Liuc4d0e812013-11-22 17:39:11 +0800155
156 return priv->realbus->reset(priv->realbus);
157}
158
Shengzhou Liu254887a2014-02-21 13:16:19 +0800159static int t208xqds_mdio_init(char *realbusname, u8 muxval)
Shengzhou Liuc4d0e812013-11-22 17:39:11 +0800160{
Shengzhou Liu254887a2014-02-21 13:16:19 +0800161 struct t208xqds_mdio *pmdio;
Shengzhou Liuc4d0e812013-11-22 17:39:11 +0800162 struct mii_dev *bus = mdio_alloc();
163
164 if (!bus) {
Shengzhou Liu254887a2014-02-21 13:16:19 +0800165 printf("Failed to allocate t208xqds MDIO bus\n");
Shengzhou Liuc4d0e812013-11-22 17:39:11 +0800166 return -1;
167 }
168
169 pmdio = malloc(sizeof(*pmdio));
170 if (!pmdio) {
Shengzhou Liu254887a2014-02-21 13:16:19 +0800171 printf("Failed to allocate t208xqds private data\n");
Shengzhou Liuc4d0e812013-11-22 17:39:11 +0800172 free(bus);
173 return -1;
174 }
175
Shengzhou Liu254887a2014-02-21 13:16:19 +0800176 bus->read = t208xqds_mdio_read;
177 bus->write = t208xqds_mdio_write;
178 bus->reset = t208xqds_mdio_reset;
Ben Whitten192bc692015-12-30 13:05:58 +0000179 strcpy(bus->name, t208xqds_mdio_name_for_muxval(muxval));
Shengzhou Liuc4d0e812013-11-22 17:39:11 +0800180
181 pmdio->realbus = miiphy_get_dev_by_name(realbusname);
182
183 if (!pmdio->realbus) {
184 printf("No bus with name %s\n", realbusname);
185 free(bus);
186 free(pmdio);
187 return -1;
188 }
189
190 pmdio->muxval = muxval;
191 bus->priv = pmdio;
Shengzhou Liuc4d0e812013-11-22 17:39:11 +0800192 return mdio_register(bus);
193}
194
195void board_ft_fman_fixup_port(void *fdt, char *compat, phys_addr_t addr,
196 enum fm_port port, int offset)
197{
198 int phy;
199 char alias[20];
shaohui xief0644da2014-10-20 19:48:19 +0800200 char lane_mode[2][20] = {"1000BASE-KX", "10GBASE-KR"};
201 char buf[32] = "serdes-1,";
Shengzhou Liuc4d0e812013-11-22 17:39:11 +0800202 struct fixed_link f_link;
shaohui xief0644da2014-10-20 19:48:19 +0800203 int media_type = 0;
Florinel Iordachee174fb72020-03-16 15:36:02 +0200204 const char *phyconn;
shaohui xief0644da2014-10-20 19:48:19 +0800205 int off;
206
Shengzhou Liuc4d0e812013-11-22 17:39:11 +0800207 ccsr_gur_t *gur = (void *)(CONFIG_SYS_MPC85xx_GUTS_ADDR);
York Sun80d26182016-12-28 08:43:36 -0800208#ifdef CONFIG_TARGET_T2080QDS
Shaohui Xie3ce21c82014-10-20 19:51:21 +0800209 serdes_corenet_t *srds_regs =
210 (void *)CONFIG_SYS_FSL_CORENET_SERDES_ADDR;
211 u32 srds1_pccr1 = in_be32(&srds_regs->srdspccr1);
212#endif
Shengzhou Liuc4d0e812013-11-22 17:39:11 +0800213 u32 srds_s1 = in_be32(&gur->rcwsr[4]) &
214 FSL_CORENET2_RCWSR4_SRDS1_PRTCL;
215
216 srds_s1 >>= FSL_CORENET2_RCWSR4_SRDS1_PRTCL_SHIFT;
217
218 if (fm_info_get_enet_if(port) == PHY_INTERFACE_MODE_SGMII) {
219 phy = fm_info_get_phy_address(port);
220 switch (port) {
York Sun80d26182016-12-28 08:43:36 -0800221#if defined(CONFIG_TARGET_T2080QDS)
Shengzhou Liuc4d0e812013-11-22 17:39:11 +0800222 case FM1_DTSEC1:
Shaohui Xie3ce21c82014-10-20 19:51:21 +0800223 if (hwconfig_sub("fsl_1gkx", "fm1_1g1")) {
224 media_type = 1;
225 fdt_set_phy_handle(fdt, compat, addr,
226 "phy_1gkx1");
227 fdt_status_okay_by_alias(fdt, "1gkx_pcs_mdio1");
228 sprintf(buf, "%s%s%s", buf, "lane-c,",
229 (char *)lane_mode[0]);
230 out_be32(&srds_regs->srdspccr1, srds1_pccr1 |
231 PCCR1_SGMIIH_KX_MASK);
232 break;
233 }
Shengzhou Liuc4d0e812013-11-22 17:39:11 +0800234 case FM1_DTSEC2:
Shaohui Xie3ce21c82014-10-20 19:51:21 +0800235 if (hwconfig_sub("fsl_1gkx", "fm1_1g2")) {
236 media_type = 1;
237 fdt_set_phy_handle(fdt, compat, addr,
238 "phy_1gkx2");
239 fdt_status_okay_by_alias(fdt, "1gkx_pcs_mdio2");
240 sprintf(buf, "%s%s%s", buf, "lane-d,",
241 (char *)lane_mode[0]);
242 out_be32(&srds_regs->srdspccr1, srds1_pccr1 |
243 PCCR1_SGMIIG_KX_MASK);
244 break;
245 }
Shengzhou Liuc4d0e812013-11-22 17:39:11 +0800246 case FM1_DTSEC9:
Shaohui Xie3ce21c82014-10-20 19:51:21 +0800247 if (hwconfig_sub("fsl_1gkx", "fm1_1g9")) {
248 media_type = 1;
249 fdt_set_phy_handle(fdt, compat, addr,
250 "phy_1gkx9");
251 fdt_status_okay_by_alias(fdt, "1gkx_pcs_mdio9");
252 sprintf(buf, "%s%s%s", buf, "lane-a,",
253 (char *)lane_mode[0]);
254 out_be32(&srds_regs->srdspccr1, srds1_pccr1 |
255 PCCR1_SGMIIE_KX_MASK);
256 break;
257 }
Shengzhou Liuc4d0e812013-11-22 17:39:11 +0800258 case FM1_DTSEC10:
Shaohui Xie3ce21c82014-10-20 19:51:21 +0800259 if (hwconfig_sub("fsl_1gkx", "fm1_1g10")) {
260 media_type = 1;
261 fdt_set_phy_handle(fdt, compat, addr,
262 "phy_1gkx10");
263 fdt_status_okay_by_alias(fdt,
264 "1gkx_pcs_mdio10");
265 sprintf(buf, "%s%s%s", buf, "lane-b,",
266 (char *)lane_mode[0]);
267 out_be32(&srds_regs->srdspccr1, srds1_pccr1 |
268 PCCR1_SGMIIF_KX_MASK);
269 break;
270 }
Shengzhou Liu254887a2014-02-21 13:16:19 +0800271 if (mdio_mux[port] == EMI1_SLOT2) {
272 sprintf(alias, "phy_sgmii_s2_%x", phy);
273 fdt_set_phy_handle(fdt, compat, addr, alias);
274 fdt_status_okay_by_alias(fdt, "emi1_slot2");
275 } else if (mdio_mux[port] == EMI1_SLOT3) {
276 sprintf(alias, "phy_sgmii_s3_%x", phy);
277 fdt_set_phy_handle(fdt, compat, addr, alias);
278 fdt_status_okay_by_alias(fdt, "emi1_slot3");
279 }
Shengzhou Liuc4d0e812013-11-22 17:39:11 +0800280 break;
281 case FM1_DTSEC5:
Shaohui Xie3ce21c82014-10-20 19:51:21 +0800282 if (hwconfig_sub("fsl_1gkx", "fm1_1g5")) {
283 media_type = 1;
284 fdt_set_phy_handle(fdt, compat, addr,
285 "phy_1gkx5");
286 fdt_status_okay_by_alias(fdt, "1gkx_pcs_mdio5");
287 sprintf(buf, "%s%s%s", buf, "lane-g,",
288 (char *)lane_mode[0]);
289 out_be32(&srds_regs->srdspccr1, srds1_pccr1 |
290 PCCR1_SGMIIC_KX_MASK);
291 break;
292 }
Shengzhou Liuc4d0e812013-11-22 17:39:11 +0800293 case FM1_DTSEC6:
Shaohui Xie3ce21c82014-10-20 19:51:21 +0800294 if (hwconfig_sub("fsl_1gkx", "fm1_1g6")) {
295 media_type = 1;
296 fdt_set_phy_handle(fdt, compat, addr,
297 "phy_1gkx6");
298 fdt_status_okay_by_alias(fdt, "1gkx_pcs_mdio6");
299 sprintf(buf, "%s%s%s", buf, "lane-h,",
300 (char *)lane_mode[0]);
301 out_be32(&srds_regs->srdspccr1, srds1_pccr1 |
302 PCCR1_SGMIID_KX_MASK);
303 break;
304 }
Shengzhou Liuc4d0e812013-11-22 17:39:11 +0800305 if (mdio_mux[port] == EMI1_SLOT1) {
306 sprintf(alias, "phy_sgmii_s1_%x", phy);
307 fdt_set_phy_handle(fdt, compat, addr, alias);
308 fdt_status_okay_by_alias(fdt, "emi1_slot1");
309 } else if (mdio_mux[port] == EMI1_SLOT2) {
310 sprintf(alias, "phy_sgmii_s2_%x", phy);
311 fdt_set_phy_handle(fdt, compat, addr, alias);
312 fdt_status_okay_by_alias(fdt, "emi1_slot2");
313 }
314 break;
York Sun146ded42016-12-28 08:43:38 -0800315#elif defined(CONFIG_TARGET_T2081QDS)
Shengzhou Liu254887a2014-02-21 13:16:19 +0800316 case FM1_DTSEC1:
317 case FM1_DTSEC2:
318 case FM1_DTSEC5:
319 case FM1_DTSEC6:
320 case FM1_DTSEC9:
321 case FM1_DTSEC10:
322 if (mdio_mux[port] == EMI1_SLOT2) {
323 sprintf(alias, "phy_sgmii_s2_%x", phy);
324 fdt_set_phy_handle(fdt, compat, addr, alias);
325 fdt_status_okay_by_alias(fdt, "emi1_slot2");
326 } else if (mdio_mux[port] == EMI1_SLOT3) {
327 sprintf(alias, "phy_sgmii_s3_%x", phy);
328 fdt_set_phy_handle(fdt, compat, addr, alias);
329 fdt_status_okay_by_alias(fdt, "emi1_slot3");
330 } else if (mdio_mux[port] == EMI1_SLOT5) {
331 sprintf(alias, "phy_sgmii_s5_%x", phy);
332 fdt_set_phy_handle(fdt, compat, addr, alias);
333 fdt_status_okay_by_alias(fdt, "emi1_slot5");
334 } else if (mdio_mux[port] == EMI1_SLOT6) {
335 sprintf(alias, "phy_sgmii_s6_%x", phy);
336 fdt_set_phy_handle(fdt, compat, addr, alias);
337 fdt_status_okay_by_alias(fdt, "emi1_slot6");
338 } else if (mdio_mux[port] == EMI1_SLOT7) {
339 sprintf(alias, "phy_sgmii_s7_%x", phy);
340 fdt_set_phy_handle(fdt, compat, addr, alias);
341 fdt_status_okay_by_alias(fdt, "emi1_slot7");
342 }
343 break;
344#endif
Shengzhou Liuc4d0e812013-11-22 17:39:11 +0800345 default:
346 break;
347 }
Shaohui Xie3ce21c82014-10-20 19:51:21 +0800348 if (media_type) {
349 /* set property for 1000BASE-KX in dtb */
350 off = fdt_node_offset_by_compat_reg(fdt,
351 "fsl,fman-memac-mdio", addr + 0x1000);
352 fdt_setprop_string(fdt, off, "lane-instance", buf);
353 }
Shengzhou Liuc4d0e812013-11-22 17:39:11 +0800354
355 } else if (fm_info_get_enet_if(port) == PHY_INTERFACE_MODE_XGMII) {
356 switch (srds_s1) {
357 case 0x66: /* XFI interface */
358 case 0x6b:
359 case 0x6c:
360 case 0x6d:
361 case 0x71:
shaohui xief0644da2014-10-20 19:48:19 +0800362 /*
363 * if the 10G is XFI, check hwconfig to see what is the
364 * media type, there are two types, fiber or copper,
365 * fix the dtb accordingly.
366 */
367 switch (port) {
368 case FM1_10GEC1:
369 if (hwconfig_sub("fsl_10gkr_copper", "fm1_10g1")) {
370 /* it's MAC9 */
371 media_type = 1;
372 fdt_set_phy_handle(fdt, compat, addr,
373 "phy_xfi9");
374 fdt_status_okay_by_alias(fdt, "xfi_pcs_mdio9");
375 sprintf(buf, "%s%s%s", buf, "lane-a,",
376 (char *)lane_mode[1]);
377 }
378 break;
379 case FM1_10GEC2:
380 if (hwconfig_sub("fsl_10gkr_copper", "fm1_10g2")) {
381 /* it's MAC10 */
382 media_type = 1;
383 fdt_set_phy_handle(fdt, compat, addr,
384 "phy_xfi10");
385 fdt_status_okay_by_alias(fdt, "xfi_pcs_mdio10");
386 sprintf(buf, "%s%s%s", buf, "lane-b,",
387 (char *)lane_mode[1]);
388 }
389 break;
390 case FM1_10GEC3:
391 if (hwconfig_sub("fsl_10gkr_copper", "fm1_10g3")) {
392 /* it's MAC1 */
393 media_type = 1;
394 fdt_set_phy_handle(fdt, compat, addr,
395 "phy_xfi1");
396 fdt_status_okay_by_alias(fdt, "xfi_pcs_mdio1");
397 sprintf(buf, "%s%s%s", buf, "lane-c,",
398 (char *)lane_mode[1]);
399 }
400 break;
401 case FM1_10GEC4:
402 if (hwconfig_sub("fsl_10gkr_copper", "fm1_10g4")) {
403 /* it's MAC2 */
404 media_type = 1;
405 fdt_set_phy_handle(fdt, compat, addr,
406 "phy_xfi2");
407 fdt_status_okay_by_alias(fdt, "xfi_pcs_mdio2");
408 sprintf(buf, "%s%s%s", buf, "lane-d,",
409 (char *)lane_mode[1]);
410 }
411 break;
412 default:
413 return;
414 }
415
416 if (!media_type) {
Florinel Iordachee174fb72020-03-16 15:36:02 +0200417 phyconn = fdt_getprop(fdt, offset,
418 "phy-connection-type",
419 NULL);
420 if (is_backplane_mode(phyconn)) {
421 /* Backplane KR mode: skip fixups */
422 printf("Interface %d in backplane KR mode\n",
423 port);
424 } else {
425 /* fixed-link for XFI fiber cable */
426 f_link.phy_id = port;
427 f_link.duplex = 1;
428 f_link.link_speed = 10000;
429 f_link.pause = 0;
430 f_link.asym_pause = 0;
431 fdt_delprop(fdt, offset, "phy-handle");
432 fdt_setprop(fdt, offset, "fixed-link",
433 &f_link, sizeof(f_link));
434 }
shaohui xief0644da2014-10-20 19:48:19 +0800435 } else {
436 /* set property for copper cable */
437 off = fdt_node_offset_by_compat_reg(fdt,
438 "fsl,fman-memac-mdio", addr + 0x1000);
439 fdt_setprop_string(fdt, off,
440 "lane-instance", buf);
441 }
Shengzhou Liuc4d0e812013-11-22 17:39:11 +0800442 break;
443 default:
444 break;
445 }
446 }
447}
448
449void fdt_fixup_board_enet(void *fdt)
450{
451 return;
452}
453
454/*
Shengzhou Liu254887a2014-02-21 13:16:19 +0800455 * This function reads RCW to check if Serdes1{A:H} is configured
456 * to slot 1/2/3/4/5/6/7 and update the lane_to_slot[] array accordingly
Shengzhou Liuc4d0e812013-11-22 17:39:11 +0800457 */
458static void initialize_lane_to_slot(void)
459{
460 ccsr_gur_t *gur = (void *)(CONFIG_SYS_MPC85xx_GUTS_ADDR);
461 u32 srds_s1 = in_be32(&gur->rcwsr[4]) &
462 FSL_CORENET2_RCWSR4_SRDS1_PRTCL;
463
464 srds_s1 >>= FSL_CORENET2_RCWSR4_SRDS1_PRTCL_SHIFT;
465
466 switch (srds_s1) {
York Sun80d26182016-12-28 08:43:36 -0800467#if defined(CONFIG_TARGET_T2080QDS)
Shengzhou Liuc4d0e812013-11-22 17:39:11 +0800468 case 0x51:
469 case 0x5f:
470 case 0x65:
471 case 0x6b:
472 case 0x71:
473 lane_to_slot[5] = 2;
474 lane_to_slot[6] = 2;
475 lane_to_slot[7] = 2;
476 break;
477 case 0xa6:
478 case 0x8e:
479 case 0x8f:
480 case 0x82:
481 case 0x83:
482 case 0xd3:
483 case 0xd9:
484 case 0xcb:
485 lane_to_slot[6] = 2;
486 lane_to_slot[7] = 2;
487 break;
488 case 0xda:
489 lane_to_slot[4] = 3;
490 lane_to_slot[5] = 3;
491 lane_to_slot[6] = 3;
492 lane_to_slot[7] = 3;
493 break;
York Sun146ded42016-12-28 08:43:38 -0800494#elif defined(CONFIG_TARGET_T2081QDS)
Shengzhou Liu254887a2014-02-21 13:16:19 +0800495 case 0x6b:
496 lane_to_slot[4] = 1;
497 lane_to_slot[5] = 3;
498 lane_to_slot[6] = 3;
499 lane_to_slot[7] = 3;
500 break;
501 case 0xca:
502 case 0xcb:
503 lane_to_slot[1] = 7;
504 lane_to_slot[2] = 6;
505 lane_to_slot[3] = 5;
506 lane_to_slot[5] = 3;
507 lane_to_slot[6] = 3;
508 lane_to_slot[7] = 3;
509 break;
510 case 0xf2:
511 lane_to_slot[1] = 7;
512 lane_to_slot[2] = 7;
513 lane_to_slot[3] = 7;
514 lane_to_slot[5] = 4;
515 lane_to_slot[6] = 3;
516 lane_to_slot[7] = 7;
517 break;
518#endif
Shengzhou Liuc4d0e812013-11-22 17:39:11 +0800519 default:
520 break;
521 }
522}
523
524int board_eth_init(bd_t *bis)
525{
526#if defined(CONFIG_FMAN_ENET)
527 int i, idx, lane, slot, interface;
528 struct memac_mdio_info dtsec_mdio_info;
529 struct memac_mdio_info tgec_mdio_info;
530 ccsr_gur_t *gur = (void *)(CONFIG_SYS_MPC85xx_GUTS_ADDR);
531 u32 rcwsr13 = in_be32(&gur->rcwsr[13]);
532 u32 srds_s1;
533
534 srds_s1 = in_be32(&gur->rcwsr[4]) &
535 FSL_CORENET2_RCWSR4_SRDS1_PRTCL;
536 srds_s1 >>= FSL_CORENET2_RCWSR4_SRDS1_PRTCL_SHIFT;
537
538 initialize_lane_to_slot();
539
540 /* Initialize the mdio_mux array so we can recognize empty elements */
541 for (i = 0; i < NUM_FM_PORTS; i++)
542 mdio_mux[i] = EMI_NONE;
543
544 dtsec_mdio_info.regs =
545 (struct memac_mdio_controller *)CONFIG_SYS_FM1_DTSEC_MDIO_ADDR;
546
547 dtsec_mdio_info.name = DEFAULT_FM_MDIO_NAME;
548
549 /* Register the 1G MDIO bus */
550 fm_memac_mdio_init(bis, &dtsec_mdio_info);
551
552 tgec_mdio_info.regs =
553 (struct memac_mdio_controller *)CONFIG_SYS_FM1_TGEC_MDIO_ADDR;
554 tgec_mdio_info.name = DEFAULT_FM_TGEC_MDIO_NAME;
555
556 /* Register the 10G MDIO bus */
557 fm_memac_mdio_init(bis, &tgec_mdio_info);
558
559 /* Register the muxing front-ends to the MDIO buses */
Shengzhou Liu254887a2014-02-21 13:16:19 +0800560 t208xqds_mdio_init(DEFAULT_FM_MDIO_NAME, EMI1_RGMII1);
561 t208xqds_mdio_init(DEFAULT_FM_MDIO_NAME, EMI1_RGMII2);
562 t208xqds_mdio_init(DEFAULT_FM_MDIO_NAME, EMI1_SLOT1);
563 t208xqds_mdio_init(DEFAULT_FM_MDIO_NAME, EMI1_SLOT2);
564 t208xqds_mdio_init(DEFAULT_FM_MDIO_NAME, EMI1_SLOT3);
York Sun80d26182016-12-28 08:43:36 -0800565#if defined(CONFIG_TARGET_T2080QDS)
Shengzhou Liu254887a2014-02-21 13:16:19 +0800566 t208xqds_mdio_init(DEFAULT_FM_MDIO_NAME, EMI1_SLOT4);
567#endif
568 t208xqds_mdio_init(DEFAULT_FM_MDIO_NAME, EMI1_SLOT5);
York Sun146ded42016-12-28 08:43:38 -0800569#if defined(CONFIG_TARGET_T2081QDS)
Shengzhou Liu254887a2014-02-21 13:16:19 +0800570 t208xqds_mdio_init(DEFAULT_FM_MDIO_NAME, EMI1_SLOT6);
571 t208xqds_mdio_init(DEFAULT_FM_MDIO_NAME, EMI1_SLOT7);
572#endif
573 t208xqds_mdio_init(DEFAULT_FM_TGEC_MDIO_NAME, EMI2);
Shengzhou Liuc4d0e812013-11-22 17:39:11 +0800574
575 /* Set the two on-board RGMII PHY address */
576 fm_info_set_phy_address(FM1_DTSEC3, RGMII_PHY1_ADDR);
577 if ((rcwsr13 & FSL_CORENET_RCWSR13_EC2) ==
578 FSL_CORENET_RCWSR13_EC2_DTSEC4_RGMII)
579 fm_info_set_phy_address(FM1_DTSEC4, RGMII_PHY2_ADDR);
580 else
581 fm_info_set_phy_address(FM1_DTSEC10, RGMII_PHY2_ADDR);
582
583 switch (srds_s1) {
Shengzhou Liu9752eb62014-05-15 19:24:11 +0800584 case 0x1b:
Shengzhou Liuc4d0e812013-11-22 17:39:11 +0800585 case 0x1c:
586 case 0x95:
587 case 0xa2:
588 case 0x94:
Shengzhou Liu254887a2014-02-21 13:16:19 +0800589 /* T2080QDS: SGMII in Slot3; T2081QDS: SGMII in Slot2 */
Shengzhou Liuc4d0e812013-11-22 17:39:11 +0800590 fm_info_set_phy_address(FM1_DTSEC9, SGMII_CARD_PORT1_PHY_ADDR);
591 fm_info_set_phy_address(FM1_DTSEC10, SGMII_CARD_PORT2_PHY_ADDR);
592 fm_info_set_phy_address(FM1_DTSEC1, SGMII_CARD_PORT3_PHY_ADDR);
593 fm_info_set_phy_address(FM1_DTSEC2, SGMII_CARD_PORT4_PHY_ADDR);
Shengzhou Liu254887a2014-02-21 13:16:19 +0800594 /* T2080QDS: SGMII in Slot2; T2081QDS: SGMII in Slot1 */
Shengzhou Liuc4d0e812013-11-22 17:39:11 +0800595 fm_info_set_phy_address(FM1_DTSEC5, SGMII_CARD_PORT3_PHY_ADDR);
596 fm_info_set_phy_address(FM1_DTSEC6, SGMII_CARD_PORT4_PHY_ADDR);
597 break;
Shengzhou Liu9752eb62014-05-15 19:24:11 +0800598 case 0x50:
Shengzhou Liuc4d0e812013-11-22 17:39:11 +0800599 case 0x51:
Shengzhou Liu9752eb62014-05-15 19:24:11 +0800600 case 0x5e:
Shengzhou Liuc4d0e812013-11-22 17:39:11 +0800601 case 0x5f:
Shengzhou Liu9752eb62014-05-15 19:24:11 +0800602 case 0x64:
Shengzhou Liuc4d0e812013-11-22 17:39:11 +0800603 case 0x65:
Shengzhou Liu254887a2014-02-21 13:16:19 +0800604 /* T2080QDS: XAUI/HiGig in Slot3; T2081QDS: in Slot2 */
Shengzhou Liuc4d0e812013-11-22 17:39:11 +0800605 fm_info_set_phy_address(FM1_10GEC1, FM1_10GEC1_PHY_ADDR);
Shengzhou Liu254887a2014-02-21 13:16:19 +0800606 /* T2080QDS: SGMII in Slot2; T2081QDS: in Slot3 */
Shengzhou Liuc4d0e812013-11-22 17:39:11 +0800607 fm_info_set_phy_address(FM1_DTSEC5, SGMII_CARD_PORT3_PHY_ADDR);
608 fm_info_set_phy_address(FM1_DTSEC6, SGMII_CARD_PORT4_PHY_ADDR);
609 break;
610 case 0x66:
Shengzhou Liu9752eb62014-05-15 19:24:11 +0800611 case 0x67:
Shengzhou Liuc4d0e812013-11-22 17:39:11 +0800612 /*
Bin Menga1875592016-02-05 19:30:11 -0800613 * XFI does not need a PHY to work, but to avoid U-Boot use
Shengzhou Liuc4d0e812013-11-22 17:39:11 +0800614 * default PHY address which is zero to a MAC when it found
615 * a MAC has no PHY address, we give a PHY address to XFI
616 * MAC, and should not use a real XAUI PHY address, since
617 * MDIO can access it successfully, and then MDIO thinks
618 * the XAUI card is used for the XFI MAC, which will cause
619 * error.
620 */
621 fm_info_set_phy_address(FM1_10GEC1, 4);
622 fm_info_set_phy_address(FM1_10GEC2, 5);
623 fm_info_set_phy_address(FM1_10GEC3, 6);
624 fm_info_set_phy_address(FM1_10GEC4, 7);
625 break;
Shengzhou Liu9752eb62014-05-15 19:24:11 +0800626 case 0x6a:
Shengzhou Liuc4d0e812013-11-22 17:39:11 +0800627 case 0x6b:
628 fm_info_set_phy_address(FM1_10GEC1, 4);
629 fm_info_set_phy_address(FM1_10GEC2, 5);
630 fm_info_set_phy_address(FM1_10GEC3, 6);
631 fm_info_set_phy_address(FM1_10GEC4, 7);
Shengzhou Liu254887a2014-02-21 13:16:19 +0800632 /* T2080QDS: SGMII in Slot2; T2081QDS: in Slot3 */
Shengzhou Liuc4d0e812013-11-22 17:39:11 +0800633 fm_info_set_phy_address(FM1_DTSEC5, SGMII_CARD_PORT3_PHY_ADDR);
634 fm_info_set_phy_address(FM1_DTSEC6, SGMII_CARD_PORT2_PHY_ADDR);
635 break;
636 case 0x6c:
637 case 0x6d:
Shengzhou Liu1576b552014-01-03 14:48:44 +0800638 fm_info_set_phy_address(FM1_10GEC1, 4);
639 fm_info_set_phy_address(FM1_10GEC2, 5);
Shengzhou Liu254887a2014-02-21 13:16:19 +0800640 /* T2080QDS: SGMII in Slot3; T2081QDS: in Slot2 */
Shengzhou Liuc4d0e812013-11-22 17:39:11 +0800641 fm_info_set_phy_address(FM1_DTSEC1, SGMII_CARD_PORT3_PHY_ADDR);
Shengzhou Liu1576b552014-01-03 14:48:44 +0800642 fm_info_set_phy_address(FM1_DTSEC2, SGMII_CARD_PORT4_PHY_ADDR);
Shengzhou Liuc4d0e812013-11-22 17:39:11 +0800643 break;
Shengzhou Liu9752eb62014-05-15 19:24:11 +0800644 case 0x70:
Shengzhou Liuc4d0e812013-11-22 17:39:11 +0800645 case 0x71:
646 /* SGMII in Slot3 */
647 fm_info_set_phy_address(FM1_DTSEC1, SGMII_CARD_PORT3_PHY_ADDR);
648 fm_info_set_phy_address(FM1_DTSEC2, SGMII_CARD_PORT4_PHY_ADDR);
649 /* SGMII in Slot2 */
650 fm_info_set_phy_address(FM1_DTSEC5, SGMII_CARD_PORT3_PHY_ADDR);
651 fm_info_set_phy_address(FM1_DTSEC6, SGMII_CARD_PORT2_PHY_ADDR);
652 break;
653 case 0xa6:
654 case 0x8e:
655 case 0x8f:
656 case 0x82:
657 case 0x83:
658 /* SGMII in Slot3 */
659 fm_info_set_phy_address(FM1_DTSEC9, SGMII_CARD_PORT1_PHY_ADDR);
660 fm_info_set_phy_address(FM1_DTSEC10, SGMII_CARD_PORT2_PHY_ADDR);
661 fm_info_set_phy_address(FM1_DTSEC1, SGMII_CARD_PORT3_PHY_ADDR);
662 fm_info_set_phy_address(FM1_DTSEC2, SGMII_CARD_PORT4_PHY_ADDR);
663 /* SGMII in Slot2 */
664 fm_info_set_phy_address(FM1_DTSEC5, SGMII_CARD_PORT3_PHY_ADDR);
665 fm_info_set_phy_address(FM1_DTSEC6, SGMII_CARD_PORT2_PHY_ADDR);
666 break;
667 case 0xa4:
668 case 0x96:
669 case 0x8a:
670 /* SGMII in Slot3 */
671 fm_info_set_phy_address(FM1_DTSEC9, SGMII_CARD_PORT1_PHY_ADDR);
672 fm_info_set_phy_address(FM1_DTSEC10, SGMII_CARD_PORT2_PHY_ADDR);
673 fm_info_set_phy_address(FM1_DTSEC1, SGMII_CARD_PORT3_PHY_ADDR);
674 fm_info_set_phy_address(FM1_DTSEC2, SGMII_CARD_PORT4_PHY_ADDR);
675 break;
York Sun80d26182016-12-28 08:43:36 -0800676#if defined(CONFIG_TARGET_T2080QDS)
Shengzhou Liuc4d0e812013-11-22 17:39:11 +0800677 case 0xd9:
678 case 0xd3:
679 case 0xcb:
680 /* SGMII in Slot3 */
681 fm_info_set_phy_address(FM1_DTSEC10, SGMII_CARD_PORT2_PHY_ADDR);
682 fm_info_set_phy_address(FM1_DTSEC1, SGMII_CARD_PORT3_PHY_ADDR);
683 fm_info_set_phy_address(FM1_DTSEC2, SGMII_CARD_PORT4_PHY_ADDR);
684 /* SGMII in Slot2 */
685 fm_info_set_phy_address(FM1_DTSEC5, SGMII_CARD_PORT3_PHY_ADDR);
686 fm_info_set_phy_address(FM1_DTSEC6, SGMII_CARD_PORT2_PHY_ADDR);
687 break;
York Sun146ded42016-12-28 08:43:38 -0800688#elif defined(CONFIG_TARGET_T2081QDS)
Shengzhou Liu254887a2014-02-21 13:16:19 +0800689 case 0xca:
690 case 0xcb:
691 /* SGMII in Slot3 */
692 fm_info_set_phy_address(FM1_DTSEC5, SGMII_CARD_PORT1_PHY_ADDR);
693 fm_info_set_phy_address(FM1_DTSEC6, SGMII_CARD_PORT2_PHY_ADDR);
694 /* SGMII in Slot5 */
695 fm_info_set_phy_address(FM1_DTSEC2, SGMII_CARD_PORT1_PHY_ADDR);
696 /* SGMII in Slot6 */
697 fm_info_set_phy_address(FM1_DTSEC1, SGMII_CARD_PORT1_PHY_ADDR);
698 /* SGMII in Slot7 */
699 fm_info_set_phy_address(FM1_DTSEC10, SGMII_CARD_PORT3_PHY_ADDR);
700 break;
701#endif
702 case 0xf2:
703 /* T2080QDS: SGMII in Slot3; T2081QDS: SGMII in Slot7 */
704 fm_info_set_phy_address(FM1_DTSEC1, SGMII_CARD_PORT1_PHY_ADDR);
705 fm_info_set_phy_address(FM1_DTSEC2, SGMII_CARD_PORT2_PHY_ADDR);
706 fm_info_set_phy_address(FM1_DTSEC10, SGMII_CARD_PORT3_PHY_ADDR);
707 fm_info_set_phy_address(FM1_DTSEC6, SGMII_CARD_PORT4_PHY_ADDR);
708 break;
Shengzhou Liuc4d0e812013-11-22 17:39:11 +0800709 default:
Shengzhou Liuc4d0e812013-11-22 17:39:11 +0800710 break;
711 }
712
713 for (i = FM1_DTSEC1; i < FM1_DTSEC1 + CONFIG_SYS_NUM_FM1_DTSEC; i++) {
714 idx = i - FM1_DTSEC1;
715 interface = fm_info_get_enet_if(i);
716 switch (interface) {
717 case PHY_INTERFACE_MODE_SGMII:
718 lane = serdes_get_first_lane(FSL_SRDS_1,
719 SGMII_FM1_DTSEC1 + idx);
720 if (lane < 0)
721 break;
722 slot = lane_to_slot[lane];
723 debug("FM1@DTSEC%u expects SGMII in slot %u\n",
724 idx + 1, slot);
725 if (QIXIS_READ(present2) & (1 << (slot - 1)))
726 fm_disable_port(i);
727
728 switch (slot) {
729 case 1:
730 mdio_mux[i] = EMI1_SLOT1;
731 fm_info_set_mdio(i, mii_dev_for_muxval(
732 mdio_mux[i]));
733 break;
734 case 2:
735 mdio_mux[i] = EMI1_SLOT2;
736 fm_info_set_mdio(i, mii_dev_for_muxval(
737 mdio_mux[i]));
738 break;
Shengzhou Liu1576b552014-01-03 14:48:44 +0800739 case 3:
740 mdio_mux[i] = EMI1_SLOT3;
741 fm_info_set_mdio(i, mii_dev_for_muxval(
Shengzhou Liu254887a2014-02-21 13:16:19 +0800742 mdio_mux[i]));
Shengzhou Liu1576b552014-01-03 14:48:44 +0800743 break;
York Sun146ded42016-12-28 08:43:38 -0800744#if defined(CONFIG_TARGET_T2081QDS)
Shengzhou Liu254887a2014-02-21 13:16:19 +0800745 case 5:
746 mdio_mux[i] = EMI1_SLOT5;
747 fm_info_set_mdio(i, mii_dev_for_muxval(
748 mdio_mux[i]));
749 break;
750 case 6:
751 mdio_mux[i] = EMI1_SLOT6;
752 fm_info_set_mdio(i, mii_dev_for_muxval(
753 mdio_mux[i]));
754 break;
755 case 7:
756 mdio_mux[i] = EMI1_SLOT7;
757 fm_info_set_mdio(i, mii_dev_for_muxval(
758 mdio_mux[i]));
759 break;
760#endif
Shengzhou Liu1576b552014-01-03 14:48:44 +0800761 }
Shengzhou Liuc4d0e812013-11-22 17:39:11 +0800762 break;
763 case PHY_INTERFACE_MODE_RGMII:
764 if (i == FM1_DTSEC3)
765 mdio_mux[i] = EMI1_RGMII1;
766 else if (i == FM1_DTSEC4 || FM1_DTSEC10)
767 mdio_mux[i] = EMI1_RGMII2;
768 fm_info_set_mdio(i, mii_dev_for_muxval(mdio_mux[i]));
769 break;
770 default:
771 break;
772 }
773 }
774
775 for (i = FM1_10GEC1; i < FM1_10GEC1 + CONFIG_SYS_NUM_FM1_10GEC; i++) {
776 idx = i - FM1_10GEC1;
777 switch (fm_info_get_enet_if(i)) {
778 case PHY_INTERFACE_MODE_XGMII:
779 if (srds_s1 == 0x51) {
780 lane = serdes_get_first_lane(FSL_SRDS_1,
781 XAUI_FM1_MAC9 + idx);
782 } else if ((srds_s1 == 0x5f) || (srds_s1 == 0x65)) {
783 lane = serdes_get_first_lane(FSL_SRDS_1,
784 HIGIG_FM1_MAC9 + idx);
785 } else {
786 if (i == FM1_10GEC1 || i == FM1_10GEC2)
787 lane = serdes_get_first_lane(FSL_SRDS_1,
788 XFI_FM1_MAC9 + idx);
789 else
790 lane = serdes_get_first_lane(FSL_SRDS_1,
791 XFI_FM1_MAC1 + idx);
792 }
793
794 if (lane < 0)
795 break;
796 mdio_mux[i] = EMI2;
797 fm_info_set_mdio(i, mii_dev_for_muxval(mdio_mux[i]));
798
799 if ((srds_s1 == 0x66) || (srds_s1 == 0x6b) ||
Shengzhou Liu9752eb62014-05-15 19:24:11 +0800800 (srds_s1 == 0x6a) || (srds_s1 == 0x70) ||
Shengzhou Liuc4d0e812013-11-22 17:39:11 +0800801 (srds_s1 == 0x6c) || (srds_s1 == 0x6d) ||
802 (srds_s1 == 0x71)) {
803 /* As XFI is in cage intead of a slot, so
804 * ensure doesn't disable the corresponding port
805 */
806 break;
807 }
808
809 slot = lane_to_slot[lane];
810 if (QIXIS_READ(present2) & (1 << (slot - 1)))
811 fm_disable_port(i);
812 break;
813 default:
814 break;
815 }
816 }
817
818 cpu_eth_init(bis);
819#endif /* CONFIG_FMAN_ENET */
820
821 return pci_eth_init(bis);
822}