2 * Copyright 2011 Freescale Semiconductor, Inc.
4 * SPDX-License-Identifier: GPL-2.0+
8 #include <asm/fsl_serdes.h>
13 struct fm_eth_info fm_info
[] = {
14 #if (CONFIG_SYS_NUM_FM1_DTSEC >= 1)
15 FM_DTSEC_INFO_INITIALIZER(1, 1),
17 #if (CONFIG_SYS_NUM_FM1_DTSEC >= 2)
18 FM_DTSEC_INFO_INITIALIZER(1, 2),
20 #if (CONFIG_SYS_NUM_FM1_DTSEC >= 3)
21 FM_DTSEC_INFO_INITIALIZER(1, 3),
23 #if (CONFIG_SYS_NUM_FM1_DTSEC >= 4)
24 FM_DTSEC_INFO_INITIALIZER(1, 4),
26 #if (CONFIG_SYS_NUM_FM1_DTSEC >= 5)
27 FM_DTSEC_INFO_INITIALIZER(1, 5),
29 #if (CONFIG_SYS_NUM_FM1_DTSEC >= 6)
30 FM_DTSEC_INFO_INITIALIZER(1, 6),
32 #if (CONFIG_SYS_NUM_FM1_DTSEC >= 7)
33 FM_DTSEC_INFO_INITIALIZER(1, 9),
35 #if (CONFIG_SYS_NUM_FM1_DTSEC >= 8)
36 FM_DTSEC_INFO_INITIALIZER(1, 10),
38 #if (CONFIG_SYS_NUM_FM2_DTSEC >= 1)
39 FM_DTSEC_INFO_INITIALIZER(2, 1),
41 #if (CONFIG_SYS_NUM_FM2_DTSEC >= 2)
42 FM_DTSEC_INFO_INITIALIZER(2, 2),
44 #if (CONFIG_SYS_NUM_FM2_DTSEC >= 3)
45 FM_DTSEC_INFO_INITIALIZER(2, 3),
47 #if (CONFIG_SYS_NUM_FM2_DTSEC >= 4)
48 FM_DTSEC_INFO_INITIALIZER(2, 4),
50 #if (CONFIG_SYS_NUM_FM2_DTSEC >= 5)
51 FM_DTSEC_INFO_INITIALIZER(2, 5),
53 #if (CONFIG_SYS_NUM_FM2_DTSEC >= 6)
54 FM_DTSEC_INFO_INITIALIZER(2, 6),
56 #if (CONFIG_SYS_NUM_FM2_DTSEC >= 7)
57 FM_DTSEC_INFO_INITIALIZER(2, 9),
59 #if (CONFIG_SYS_NUM_FM2_DTSEC >= 8)
60 FM_DTSEC_INFO_INITIALIZER(2, 10),
62 #if (CONFIG_SYS_NUM_FM1_10GEC >= 1)
63 FM_TGEC_INFO_INITIALIZER(1, 1),
65 #if (CONFIG_SYS_NUM_FM1_10GEC >= 2)
66 FM_TGEC_INFO_INITIALIZER(1, 2),
68 #if (CONFIG_SYS_NUM_FM1_10GEC >= 3)
69 FM_TGEC_INFO_INITIALIZER2(1, 3),
71 #if (CONFIG_SYS_NUM_FM1_10GEC >= 4)
72 FM_TGEC_INFO_INITIALIZER2(1, 4),
74 #if (CONFIG_SYS_NUM_FM2_10GEC >= 1)
75 FM_TGEC_INFO_INITIALIZER(2, 1),
77 #if (CONFIG_SYS_NUM_FM2_10GEC >= 2)
78 FM_TGEC_INFO_INITIALIZER(2, 2),
82 int fm_standard_init(bd_t
*bis
)
85 struct ccsr_fman
*reg
;
87 reg
= (void *)CONFIG_SYS_FSL_FM1_ADDR
;
88 if (fm_init_common(0, reg
))
91 for (i
= 0; i
< ARRAY_SIZE(fm_info
); i
++) {
92 if ((fm_info
[i
].enabled
) && (fm_info
[i
].index
== 1))
93 fm_eth_initialize(reg
, &fm_info
[i
]);
96 #if (CONFIG_SYS_NUM_FMAN == 2)
97 reg
= (void *)CONFIG_SYS_FSL_FM2_ADDR
;
98 if (fm_init_common(1, reg
))
101 for (i
= 0; i
< ARRAY_SIZE(fm_info
); i
++) {
102 if ((fm_info
[i
].enabled
) && (fm_info
[i
].index
== 2))
103 fm_eth_initialize(reg
, &fm_info
[i
]);
110 /* simple linear search to map from port to array index */
111 static int fm_port_to_index(enum fm_port port
)
115 for (i
= 0; i
< ARRAY_SIZE(fm_info
); i
++) {
116 if (fm_info
[i
].port
== port
)
124 * Determine if an interface is actually active based on HW config
125 * we expect fman_port_enet_if() to report PHY_INTERFACE_MODE_NONE if
126 * the interface is not active based on HW cfg of the SoC
128 void fman_enet_init(void)
132 for (i
= 0; i
< ARRAY_SIZE(fm_info
); i
++) {
133 phy_interface_t enet_if
;
135 enet_if
= fman_port_enet_if(fm_info
[i
].port
);
136 if (enet_if
!= PHY_INTERFACE_MODE_NONE
) {
137 fm_info
[i
].enabled
= 1;
138 fm_info
[i
].enet_if
= enet_if
;
140 fm_info
[i
].enabled
= 0;
147 void fm_disable_port(enum fm_port port
)
149 int i
= fm_port_to_index(port
);
154 fm_info
[i
].enabled
= 0;
155 fman_disable_port(port
);
158 void fm_enable_port(enum fm_port port
)
160 int i
= fm_port_to_index(port
);
165 fm_info
[i
].enabled
= 1;
166 fman_enable_port(port
);
169 void fm_info_set_mdio(enum fm_port port
, struct mii_dev
*bus
)
171 int i
= fm_port_to_index(port
);
176 fm_info
[i
].bus
= bus
;
179 void fm_info_set_phy_address(enum fm_port port
, int address
)
181 int i
= fm_port_to_index(port
);
186 fm_info
[i
].phy_addr
= address
;
190 * Returns the PHY address for a given Fman port
192 * The port must be set via a prior call to fm_info_set_phy_address().
193 * A negative error code is returned if the port is invalid.
195 int fm_info_get_phy_address(enum fm_port port
)
197 int i
= fm_port_to_index(port
);
202 return fm_info
[i
].phy_addr
;
206 * Returns the type of the data interface between the given MAC and its PHY.
207 * This is typically determined by the RCW.
209 phy_interface_t
fm_info_get_enet_if(enum fm_port port
)
211 int i
= fm_port_to_index(port
);
214 return PHY_INTERFACE_MODE_NONE
;
216 if (fm_info
[i
].enabled
)
217 return fm_info
[i
].enet_if
;
219 return PHY_INTERFACE_MODE_NONE
;
223 __def_board_ft_fman_fixup_port(void *blob
, char * prop
, phys_addr_t pa
,
224 enum fm_port port
, int offset
)
229 void board_ft_fman_fixup_port(void *blob
, char * prop
, phys_addr_t pa
,
230 enum fm_port port
, int offset
)
231 __attribute__((weak
, alias("__def_board_ft_fman_fixup_port")));
233 static void ft_fixup_port(void *blob
, struct fm_eth_info
*info
, char *prop
)
237 phys_addr_t paddr
= CONFIG_SYS_CCSRBAR_PHYS
+ info
->compat_offset
;
238 u64 dtsec1_addr
= (u64
)CONFIG_SYS_CCSRBAR_PHYS
+
239 CONFIG_SYS_FSL_FM1_DTSEC1_OFFSET
;
241 off
= fdt_node_offset_by_compat_reg(blob
, prop
, paddr
);
244 fdt_fixup_phy_connection(blob
, off
, info
->enet_if
);
245 board_ft_fman_fixup_port(blob
, prop
, paddr
, info
->port
, off
);
249 #ifdef CONFIG_SYS_FMAN_V3
251 * Physically FM1_DTSEC9 and FM1_10GEC1 use the same dual-role MAC, when
252 * FM1_10GEC1 is enabled and FM1_DTSEC9 is disabled, ensure that the
253 * dual-role MAC is not disabled, ditto for other dual-role MACs.
255 if (((info
->port
== FM1_DTSEC9
) && (PORT_IS_ENABLED(FM1_10GEC1
))) ||
256 ((info
->port
== FM1_DTSEC10
) && (PORT_IS_ENABLED(FM1_10GEC2
))) ||
257 ((info
->port
== FM1_DTSEC1
) && (PORT_IS_ENABLED(FM1_10GEC1
))) ||
258 ((info
->port
== FM1_DTSEC1
) && (PORT_IS_ENABLED(FM1_10GEC3
))) ||
259 ((info
->port
== FM1_DTSEC2
) && (PORT_IS_ENABLED(FM1_10GEC4
))) ||
260 ((info
->port
== FM1_10GEC1
) && (PORT_IS_ENABLED(FM1_DTSEC1
))) ||
261 ((info
->port
== FM1_10GEC1
) && (PORT_IS_ENABLED(FM1_DTSEC9
))) ||
262 ((info
->port
== FM1_10GEC2
) && (PORT_IS_ENABLED(FM1_DTSEC10
))) ||
263 ((info
->port
== FM1_10GEC3
) && (PORT_IS_ENABLED(FM1_DTSEC1
))) ||
264 ((info
->port
== FM1_10GEC4
) && (PORT_IS_ENABLED(FM1_DTSEC2
)))
265 #if (CONFIG_SYS_NUM_FMAN == 2)
267 ((info
->port
== FM2_DTSEC9
) && (PORT_IS_ENABLED(FM2_10GEC1
))) ||
268 ((info
->port
== FM2_DTSEC10
) && (PORT_IS_ENABLED(FM2_10GEC2
))) ||
269 ((info
->port
== FM2_10GEC1
) && (PORT_IS_ENABLED(FM2_DTSEC9
))) ||
270 ((info
->port
== FM2_10GEC2
) && (PORT_IS_ENABLED(FM2_DTSEC10
)))
275 /* board code might have caused offset to change */
276 off
= fdt_node_offset_by_compat_reg(blob
, prop
, paddr
);
278 /* Don't disable FM1-DTSEC1 MAC as its used for MDIO */
279 if (paddr
!= dtsec1_addr
)
280 fdt_status_disabled(blob
, off
); /* disable the MAC node */
282 /* disable the fsl,dpa-ethernet node that points to the MAC */
283 ph
= fdt_get_phandle(blob
, off
);
284 do_fixup_by_prop(blob
, "fsl,fman-mac", &ph
, sizeof(ph
),
285 "status", "disabled", strlen("disabled") + 1, 1);
288 void fdt_fixup_fman_ethernet(void *blob
)
292 #ifdef CONFIG_SYS_FMAN_V3
293 for (i
= 0; i
< ARRAY_SIZE(fm_info
); i
++)
294 ft_fixup_port(blob
, &fm_info
[i
], "fsl,fman-memac");
296 for (i
= 0; i
< ARRAY_SIZE(fm_info
); i
++) {
297 if (fm_info
[i
].type
== FM_ETH_1G_E
)
298 ft_fixup_port(blob
, &fm_info
[i
], "fsl,fman-1g-mac");
300 ft_fixup_port(blob
, &fm_info
[i
], "fsl,fman-10g-mac");
305 /*QSGMII Riser Card can work in SGMII mode, but the PHY address is different.
306 *This function scans which Riser Card being used(QSGMII or SGMII Riser Card),
307 *then set the correct PHY address
309 void set_sgmii_phy(struct mii_dev
*bus
, enum fm_port base_port
,
310 unsigned int port_num
, int phy_base_addr
)
312 unsigned int regnum
= 0;
317 qsgmii
= is_qsgmii_riser_card(bus
, phy_base_addr
, port_num
, regnum
);
322 for (i
= base_port
; i
< base_port
+ port_num
; i
++) {
323 if (fm_info_get_enet_if(i
) == PHY_INTERFACE_MODE_SGMII
) {
324 phy_real_addr
= phy_base_addr
+ i
- base_port
;
325 fm_info_set_phy_address(i
, phy_real_addr
);
330 /*to check whether qsgmii riser card is used*/
331 int is_qsgmii_riser_card(struct mii_dev
*bus
, int phy_base_addr
,
332 unsigned int port_num
, unsigned regnum
)
340 for (i
= phy_base_addr
; i
< phy_base_addr
+ port_num
; i
++) {
341 val
= bus
->read(bus
, i
, MDIO_DEVAD_NONE
, regnum
);
342 if (val
!= MIIM_TIMEOUT
)