blob: e7646365d7d4000c6059677992f165a72ecafc79 [file] [log] [blame]
Tom Rini83d290c2018-05-06 17:58:06 -04001// SPDX-License-Identifier: GPL-2.0+
Chunhe Lan0b2e13d2014-04-14 18:42:06 +08002/*
3 * Copyright 2014 Freescale Semiconductor, Inc.
4 *
5 * Chunhe Lan <Chunhe.Lan@freescale.com>
Chunhe Lan0b2e13d2014-04-14 18:42:06 +08006 */
7
Tom Rini03de3052024-05-20 13:35:03 -06008#include <config.h>
Chunhe Lan0b2e13d2014-04-14 18:42:06 +08009#include <command.h>
Simon Glass4d72caa2020-05-10 11:40:01 -060010#include <fdt_support.h>
Simon Glass90526e92020-05-10 11:39:56 -060011#include <net.h>
Chunhe Lan0b2e13d2014-04-14 18:42:06 +080012#include <netdev.h>
13#include <asm/mmu.h>
14#include <asm/processor.h>
15#include <asm/cache.h>
16#include <asm/immap_85xx.h>
17#include <asm/fsl_law.h>
18#include <fsl_ddr_sdram.h>
19#include <asm/fsl_serdes.h>
20#include <asm/fsl_portals.h>
21#include <asm/fsl_liodn.h>
22#include <malloc.h>
23#include <fm_eth.h>
24#include <fsl_mdio.h>
25#include <miiphy.h>
26#include <phy.h>
Shaohui Xie8225b2f2015-10-26 19:47:47 +080027#include <fsl_dtsec.h>
Chunhe Lan0b2e13d2014-04-14 18:42:06 +080028#include <asm/fsl_serdes.h>
29#include <hwconfig.h>
30
31#include "../common/fman.h"
32#include "t4rdb.h"
33
34void fdt_fixup_board_enet(void *fdt)
35{
36 return;
37}
38
Masahiro Yamadab75d8dc2020-06-26 15:13:33 +090039int board_eth_init(struct bd_info *bis)
Chunhe Lan0b2e13d2014-04-14 18:42:06 +080040{
41#if defined(CONFIG_FMAN_ENET)
42 int i, interface;
43 struct memac_mdio_info dtsec_mdio_info;
44 struct memac_mdio_info tgec_mdio_info;
45 struct mii_dev *dev;
Tom Rini51552072022-10-28 20:27:12 -040046 ccsr_gur_t *gur = (void *)(CFG_SYS_MPC85xx_GUTS_ADDR);
Chunhe Lan0b2e13d2014-04-14 18:42:06 +080047 u32 srds_prtcl_s1, srds_prtcl_s2;
48
49 srds_prtcl_s1 = in_be32(&gur->rcwsr[4]) &
50 FSL_CORENET2_RCWSR4_SRDS1_PRTCL;
51 srds_prtcl_s1 >>= FSL_CORENET2_RCWSR4_SRDS1_PRTCL_SHIFT;
52 srds_prtcl_s2 = in_be32(&gur->rcwsr[4]) &
53 FSL_CORENET2_RCWSR4_SRDS2_PRTCL;
54 srds_prtcl_s2 >>= FSL_CORENET2_RCWSR4_SRDS2_PRTCL_SHIFT;
55
56 dtsec_mdio_info.regs =
Tom Rini6e7df1d2023-01-10 11:19:45 -050057 (struct memac_mdio_controller *)CFG_SYS_FM2_DTSEC_MDIO_ADDR;
Chunhe Lan0b2e13d2014-04-14 18:42:06 +080058
59 dtsec_mdio_info.name = DEFAULT_FM_MDIO_NAME;
60
61 /* Register the 1G MDIO bus */
62 fm_memac_mdio_init(bis, &dtsec_mdio_info);
63
64 tgec_mdio_info.regs =
Tom Rini6e7df1d2023-01-10 11:19:45 -050065 (struct memac_mdio_controller *)CFG_SYS_FM2_TGEC_MDIO_ADDR;
Chunhe Lan0b2e13d2014-04-14 18:42:06 +080066 tgec_mdio_info.name = DEFAULT_FM_TGEC_MDIO_NAME;
67
68 /* Register the 10G MDIO bus */
69 fm_memac_mdio_init(bis, &tgec_mdio_info);
70
Chunhe Lane6c334a2014-05-20 13:34:28 +080071 if ((srds_prtcl_s1 == 28) || (srds_prtcl_s1 == 27)) {
Chunhe Lan0b2e13d2014-04-14 18:42:06 +080072 /* SGMII */
73 fm_info_set_phy_address(FM1_DTSEC1, SGMII_PHY_ADDR1);
74 fm_info_set_phy_address(FM1_DTSEC2, SGMII_PHY_ADDR2);
75 fm_info_set_phy_address(FM1_DTSEC3, SGMII_PHY_ADDR3);
76 fm_info_set_phy_address(FM1_DTSEC4, SGMII_PHY_ADDR4);
77 } else {
78 puts("Invalid SerDes1 protocol for T4240RDB\n");
79 }
80
Ying Zhangd1fc8ed2016-04-21 14:23:46 +080081 fm_disable_port(FM1_DTSEC5);
82 fm_disable_port(FM1_DTSEC6);
83
Tom Rinicdc5ed82022-11-16 13:10:29 -050084 for (i = FM1_DTSEC1; i < FM1_DTSEC1 + CFG_SYS_NUM_FM1_DTSEC; i++) {
Chunhe Lan0b2e13d2014-04-14 18:42:06 +080085 interface = fm_info_get_enet_if(i);
86 switch (interface) {
87 case PHY_INTERFACE_MODE_SGMII:
88 dev = miiphy_get_dev_by_name(DEFAULT_FM_MDIO_NAME);
89 fm_info_set_mdio(i, dev);
90 break;
91 default:
92 break;
93 }
94 }
95
Tom Rinicdc5ed82022-11-16 13:10:29 -050096 for (i = FM1_10GEC1; i < FM1_10GEC1 + CFG_SYS_NUM_FM1_10GEC; i++) {
Chunhe Lan0b2e13d2014-04-14 18:42:06 +080097 switch (fm_info_get_enet_if(i)) {
98 case PHY_INTERFACE_MODE_XGMII:
99 dev = miiphy_get_dev_by_name(DEFAULT_FM_TGEC_MDIO_NAME);
100 fm_info_set_mdio(i, dev);
101 break;
102 default:
103 break;
104 }
105 }
106
Tom Rinicdc5ed82022-11-16 13:10:29 -0500107#if (CFG_SYS_NUM_FMAN == 2)
Chunhe Lan3bcf0472014-12-10 20:00:39 +0800108 if ((srds_prtcl_s2 == 56) || (srds_prtcl_s2 == 55)) {
Vladimir Oltean77b11f72021-09-18 15:32:34 +0300109 /* SGMII && 10GBase-R */
Chunhe Lan0b2e13d2014-04-14 18:42:06 +0800110 fm_info_set_phy_address(FM2_DTSEC1, SGMII_PHY_ADDR5);
111 fm_info_set_phy_address(FM2_DTSEC2, SGMII_PHY_ADDR6);
112 fm_info_set_phy_address(FM2_DTSEC3, SGMII_PHY_ADDR7);
113 fm_info_set_phy_address(FM2_DTSEC4, SGMII_PHY_ADDR8);
114 fm_info_set_phy_address(FM1_10GEC1, FM1_10GEC1_PHY_ADDR);
115 fm_info_set_phy_address(FM1_10GEC2, FM1_10GEC2_PHY_ADDR);
116 fm_info_set_phy_address(FM2_10GEC1, FM2_10GEC2_PHY_ADDR);
117 fm_info_set_phy_address(FM2_10GEC2, FM2_10GEC1_PHY_ADDR);
118 } else {
119 puts("Invalid SerDes2 protocol for T4240RDB\n");
120 }
121
Ying Zhangd1fc8ed2016-04-21 14:23:46 +0800122 fm_disable_port(FM2_DTSEC5);
123 fm_disable_port(FM2_DTSEC6);
Tom Rinicdc5ed82022-11-16 13:10:29 -0500124 for (i = FM2_DTSEC1; i < FM2_DTSEC1 + CFG_SYS_NUM_FM2_DTSEC; i++) {
Chunhe Lan0b2e13d2014-04-14 18:42:06 +0800125 interface = fm_info_get_enet_if(i);
126 switch (interface) {
127 case PHY_INTERFACE_MODE_SGMII:
128 dev = miiphy_get_dev_by_name(DEFAULT_FM_MDIO_NAME);
129 fm_info_set_mdio(i, dev);
130 break;
131 default:
132 break;
133 }
134 }
135
Tom Rinicdc5ed82022-11-16 13:10:29 -0500136 for (i = FM2_10GEC1; i < FM2_10GEC1 + CFG_SYS_NUM_FM2_10GEC; i++) {
Chunhe Lan0b2e13d2014-04-14 18:42:06 +0800137 switch (fm_info_get_enet_if(i)) {
138 case PHY_INTERFACE_MODE_XGMII:
139 dev = miiphy_get_dev_by_name(DEFAULT_FM_TGEC_MDIO_NAME);
140 fm_info_set_mdio(i, dev);
141 break;
142 default:
143 break;
144 }
145 }
Tom Rinicdc5ed82022-11-16 13:10:29 -0500146#endif /* CFG_SYS_NUM_FMAN */
Chunhe Lan0b2e13d2014-04-14 18:42:06 +0800147
148 cpu_eth_init(bis);
149#endif /* CONFIG_FMAN_ENET */
150
151 return pci_eth_init(bis);
152}