blob: 7034bc6e5d21465f8683e84a6a617c78ab369a62 [file] [log] [blame]
Tom Rini10e47792018-05-06 17:58:06 -04001// SPDX-License-Identifier: GPL-2.0+
Prabhakar Kushwahab0b41892015-05-28 14:53:54 +05302/*
3 * Copyright 2015 Freescale Semiconductor, Inc.
4 *
Prabhakar Kushwahab0b41892015-05-28 14:53:54 +05305 */
6
7#include <common.h>
8#include <command.h>
Simon Glass0c364412019-12-28 10:44:48 -07009#include <net.h>
Prabhakar Kushwahab0b41892015-05-28 14:53:54 +053010#include <netdev.h>
11#include <malloc.h>
12#include <fsl_mdio.h>
13#include <miiphy.h>
14#include <phy.h>
15#include <fm_eth.h>
Simon Glass3ba929a2020-10-30 21:38:53 -060016#include <asm/global_data.h>
Prabhakar Kushwahab0b41892015-05-28 14:53:54 +053017#include <asm/io.h>
Prabhakar Kushwaha7b3a6bc2015-06-28 11:03:59 +053018#include <exports.h>
Prabhakar Kushwahab0b41892015-05-28 14:53:54 +053019#include <asm/arch/fsl_serdes.h>
Bogdan Purcareata08bc0142017-05-24 16:40:21 +000020#include <fsl-mc/fsl_mc.h>
Prabhakar Kushwahab0b41892015-05-28 14:53:54 +053021#include <fsl-mc/ldpaa_wriop.h>
22
Prabhakar Kushwaha7b3a6bc2015-06-28 11:03:59 +053023DECLARE_GLOBAL_DATA_PTR;
24
Masahiro Yamadaf7ed78b2020-06-26 15:13:33 +090025int board_eth_init(struct bd_info *bis)
Prabhakar Kushwahab0b41892015-05-28 14:53:54 +053026{
Ioana Ciorneicfa114a2020-03-18 16:47:40 +020027#ifndef CONFIG_DM_ETH
Prabhakar Kushwahab0b41892015-05-28 14:53:54 +053028#if defined(CONFIG_FSL_MC_ENET)
29 int i, interface;
30 struct memac_mdio_info mdio_info;
31 struct mii_dev *dev;
Tom Rini376b88a2022-10-28 20:27:13 -040032 struct ccsr_gur *gur = (void *)(CFG_SYS_FSL_GUTS_ADDR);
Prabhakar Kushwahab0b41892015-05-28 14:53:54 +053033 u32 srds_s1;
34 struct memac_mdio_controller *reg;
35
36 srds_s1 = in_le32(&gur->rcwsr[28]) &
37 FSL_CHASSIS3_RCWSR28_SRDS1_PRTCL_MASK;
38 srds_s1 >>= FSL_CHASSIS3_RCWSR28_SRDS1_PRTCL_SHIFT;
39
Tom Rini376b88a2022-10-28 20:27:13 -040040 reg = (struct memac_mdio_controller *)CFG_SYS_FSL_WRIOP1_MDIO1;
Prabhakar Kushwahab0b41892015-05-28 14:53:54 +053041 mdio_info.regs = reg;
42 mdio_info.name = DEFAULT_WRIOP_MDIO1_NAME;
43
44 /* Register the EMI 1 */
45 fm_memac_mdio_init(bis, &mdio_info);
46
Tom Rini376b88a2022-10-28 20:27:13 -040047 reg = (struct memac_mdio_controller *)CFG_SYS_FSL_WRIOP1_MDIO2;
Prabhakar Kushwahab0b41892015-05-28 14:53:54 +053048 mdio_info.regs = reg;
49 mdio_info.name = DEFAULT_WRIOP_MDIO2_NAME;
50
51 /* Register the EMI 2 */
52 fm_memac_mdio_init(bis, &mdio_info);
53
54 switch (srds_s1) {
55 case 0x2A:
Pankaj Bansal50adb5e2018-10-10 14:08:34 +053056 wriop_set_phy_address(WRIOP1_DPMAC1, 0, CORTINA_PHY_ADDR1);
57 wriop_set_phy_address(WRIOP1_DPMAC2, 0, CORTINA_PHY_ADDR2);
58 wriop_set_phy_address(WRIOP1_DPMAC3, 0, CORTINA_PHY_ADDR3);
59 wriop_set_phy_address(WRIOP1_DPMAC4, 0, CORTINA_PHY_ADDR4);
60 wriop_set_phy_address(WRIOP1_DPMAC5, 0, AQ_PHY_ADDR1);
61 wriop_set_phy_address(WRIOP1_DPMAC6, 0, AQ_PHY_ADDR2);
62 wriop_set_phy_address(WRIOP1_DPMAC7, 0, AQ_PHY_ADDR3);
63 wriop_set_phy_address(WRIOP1_DPMAC8, 0, AQ_PHY_ADDR4);
Prabhakar Kushwahab0b41892015-05-28 14:53:54 +053064
65 break;
Santan Kumarff138e52017-04-13 15:31:09 +053066 case 0x4B:
Pankaj Bansal50adb5e2018-10-10 14:08:34 +053067 wriop_set_phy_address(WRIOP1_DPMAC1, 0, CORTINA_PHY_ADDR1);
68 wriop_set_phy_address(WRIOP1_DPMAC2, 0, CORTINA_PHY_ADDR2);
69 wriop_set_phy_address(WRIOP1_DPMAC3, 0, CORTINA_PHY_ADDR3);
70 wriop_set_phy_address(WRIOP1_DPMAC4, 0, CORTINA_PHY_ADDR4);
Santan Kumarff138e52017-04-13 15:31:09 +053071
72 break;
Prabhakar Kushwahab0b41892015-05-28 14:53:54 +053073 default:
Prabhakar Kushwaha122bcfd2015-11-09 16:42:07 +053074 printf("SerDes1 protocol 0x%x is not supported on LS2080aRDB\n",
Prabhakar Kushwahab0b41892015-05-28 14:53:54 +053075 srds_s1);
76 break;
77 }
78
79 for (i = WRIOP1_DPMAC1; i <= WRIOP1_DPMAC4; i++) {
80 interface = wriop_get_enet_if(i);
81 switch (interface) {
82 case PHY_INTERFACE_MODE_XGMII:
83 dev = miiphy_get_dev_by_name(DEFAULT_WRIOP_MDIO1_NAME);
84 wriop_set_mdio(i, dev);
85 break;
86 default:
87 break;
88 }
89 }
90
91 for (i = WRIOP1_DPMAC5; i <= WRIOP1_DPMAC8; i++) {
92 switch (wriop_get_enet_if(i)) {
93 case PHY_INTERFACE_MODE_XGMII:
94 dev = miiphy_get_dev_by_name(DEFAULT_WRIOP_MDIO2_NAME);
95 wriop_set_mdio(i, dev);
96 break;
97 default:
98 break;
99 }
100 }
101
Prabhakar Kushwahab0b41892015-05-28 14:53:54 +0530102 cpu_eth_init(bis);
Bogdan Purcareata08bc0142017-05-24 16:40:21 +0000103#endif /* CONFIG_FSL_MC_ENET */
Ioana Ciorneicfa114a2020-03-18 16:47:40 +0200104#endif /* !CONFIG_DM_ETH */
Prabhakar Kushwahab0b41892015-05-28 14:53:54 +0530105
Prabhakar Kushwaha7b3a6bc2015-06-28 11:03:59 +0530106#ifdef CONFIG_PHY_AQUANTIA
107 /*
108 * Export functions to be used by AQ firmware
109 * upload application
110 */
111 gd->jt->strcpy = strcpy;
112 gd->jt->mdelay = mdelay;
113 gd->jt->mdio_get_current_dev = mdio_get_current_dev;
114 gd->jt->phy_find_by_mask = phy_find_by_mask;
115 gd->jt->mdio_phydev_for_ethname = mdio_phydev_for_ethname;
116 gd->jt->miiphy_set_current_dev = miiphy_set_current_dev;
117#endif
Ioana Ciorneicfa114a2020-03-18 16:47:40 +0200118
119#ifdef CONFIG_DM_ETH
120 return 0;
121#else
Prabhakar Kushwahab0b41892015-05-28 14:53:54 +0530122 return pci_eth_init(bis);
Ioana Ciorneicfa114a2020-03-18 16:47:40 +0200123#endif
Prabhakar Kushwahab0b41892015-05-28 14:53:54 +0530124}
Bogdan Purcareata08bc0142017-05-24 16:40:21 +0000125
126#if defined(CONFIG_RESET_PHY_R)
127void reset_phy(void)
128{
129 mc_env_boot();
130}
131#endif /* CONFIG_RESET_PHY_R */