blob: ef9f4bcce4dd728c245434c6e90d70dff0017218 [file] [log] [blame]
Tom Rini10e47792018-05-06 17:58:06 -04001// SPDX-License-Identifier: GPL-2.0+
Timur Tabi04b4a882012-10-23 09:40:22 +00002/*
3 * Copyright 2011 Freescale Semiconductor, Inc.
Timur Tabi04b4a882012-10-23 09:40:22 +00004 */
Tom Riniabb9a042024-05-18 20:20:43 -06005#include <common.h>
Timur Tabi04b4a882012-10-23 09:40:22 +00006#include <phy.h>
7#include <fm_eth.h>
8#include <asm/io.h>
9#include <asm/immap_85xx.h>
10#include <asm/fsl_serdes.h>
11
12u32 port_to_devdisr[] = {
13 [FM1_DTSEC1] = FSL_CORENET_DEVDISR2_DTSEC1_1,
14 [FM1_DTSEC2] = FSL_CORENET_DEVDISR2_DTSEC1_2,
15 [FM1_DTSEC3] = FSL_CORENET_DEVDISR2_DTSEC1_3,
16 [FM1_DTSEC4] = FSL_CORENET_DEVDISR2_DTSEC1_4,
17 [FM1_DTSEC5] = FSL_CORENET_DEVDISR2_DTSEC1_5,
18 [FM1_10GEC1] = FSL_CORENET_DEVDISR2_10GEC1,
19 [FM2_DTSEC1] = FSL_CORENET_DEVDISR2_DTSEC2_1,
20 [FM2_DTSEC2] = FSL_CORENET_DEVDISR2_DTSEC2_2,
21 [FM2_DTSEC3] = FSL_CORENET_DEVDISR2_DTSEC2_3,
22 [FM2_DTSEC4] = FSL_CORENET_DEVDISR2_DTSEC2_4,
23 [FM2_DTSEC5] = FSL_CORENET_DEVDISR2_DTSEC2_5,
24 [FM2_10GEC1] = FSL_CORENET_DEVDISR2_10GEC2,
25};
26
27static int is_device_disabled(enum fm_port port)
28{
Tom Rinid5c3bf22022-10-28 20:27:12 -040029 ccsr_gur_t *gur = (void *)(CFG_SYS_MPC85xx_GUTS_ADDR);
Timur Tabi04b4a882012-10-23 09:40:22 +000030 u32 devdisr2 = in_be32(&gur->devdisr2);
31
32 return port_to_devdisr[port] & devdisr2;
33}
34
35void fman_disable_port(enum fm_port port)
36{
Tom Rinid5c3bf22022-10-28 20:27:12 -040037 ccsr_gur_t *gur = (void *)(CFG_SYS_MPC85xx_GUTS_ADDR);
Timur Tabi04b4a882012-10-23 09:40:22 +000038
39 /* don't allow disabling of DTSEC1 as its needed for MDIO */
40 if (port == FM1_DTSEC1)
41 return;
42
43 setbits_be32(&gur->devdisr2, port_to_devdisr[port]);
44}
45
Valentin Longchamp51b2ca32013-10-18 11:47:21 +020046void fman_enable_port(enum fm_port port)
47{
Tom Rinid5c3bf22022-10-28 20:27:12 -040048 ccsr_gur_t *gur = (void *)(CFG_SYS_MPC85xx_GUTS_ADDR);
Valentin Longchamp51b2ca32013-10-18 11:47:21 +020049
50 clrbits_be32(&gur->devdisr2, port_to_devdisr[port]);
51}
52
Timur Tabi04b4a882012-10-23 09:40:22 +000053phy_interface_t fman_port_enet_if(enum fm_port port)
54{
Tom Rinid5c3bf22022-10-28 20:27:12 -040055 ccsr_gur_t *gur = (void *)(CFG_SYS_MPC85xx_GUTS_ADDR);
Timur Tabi04b4a882012-10-23 09:40:22 +000056 u32 rcwsr11 = in_be32(&gur->rcwsr[11]);
57
58 if (is_device_disabled(port))
Marek Behún48631e42022-04-07 00:33:03 +020059 return PHY_INTERFACE_MODE_NA;
Timur Tabi04b4a882012-10-23 09:40:22 +000060
61 if ((port == FM1_10GEC1) && (is_serdes_configured(XAUI_FM1)))
62 return PHY_INTERFACE_MODE_XGMII;
63
64 if ((port == FM2_10GEC1) && (is_serdes_configured(XAUI_FM2)))
65 return PHY_INTERFACE_MODE_XGMII;
66
67 /* handle RGMII first */
68 if ((port == FM1_DTSEC5) && ((rcwsr11 & FSL_CORENET_RCWSR11_EC1) ==
69 FSL_CORENET_RCWSR11_EC1_FM1_DTSEC5_RGMII))
70 return PHY_INTERFACE_MODE_RGMII;
71
72 if ((port == FM1_DTSEC5) && ((rcwsr11 & FSL_CORENET_RCWSR11_EC1) ==
73 FSL_CORENET_RCWSR11_EC1_FM1_DTSEC5_MII))
74 return PHY_INTERFACE_MODE_MII;
75
76 if ((port == FM2_DTSEC5) && ((rcwsr11 & FSL_CORENET_RCWSR11_EC2) ==
77 FSL_CORENET_RCWSR11_EC2_FM2_DTSEC5_RGMII))
78 return PHY_INTERFACE_MODE_RGMII;
79
80 if ((port == FM2_DTSEC5) && ((rcwsr11 & FSL_CORENET_RCWSR11_EC2) ==
81 FSL_CORENET_RCWSR11_EC2_FM2_DTSEC5_MII))
82 return PHY_INTERFACE_MODE_MII;
83
84 switch (port) {
85 case FM1_DTSEC1:
86 case FM1_DTSEC2:
87 case FM1_DTSEC3:
88 case FM1_DTSEC4:
89 case FM1_DTSEC5:
90 if (is_serdes_configured(SGMII_FM1_DTSEC1 + port - FM1_DTSEC1))
91 return PHY_INTERFACE_MODE_SGMII;
92 break;
93 case FM2_DTSEC1:
94 case FM2_DTSEC2:
95 case FM2_DTSEC3:
96 case FM2_DTSEC4:
97 case FM2_DTSEC5:
98 if (is_serdes_configured(SGMII_FM2_DTSEC1 + port - FM2_DTSEC1))
99 return PHY_INTERFACE_MODE_SGMII;
100 break;
101 default:
Marek Behún48631e42022-04-07 00:33:03 +0200102 return PHY_INTERFACE_MODE_NA;
Timur Tabi04b4a882012-10-23 09:40:22 +0000103 }
104
Marek Behún48631e42022-04-07 00:33:03 +0200105 return PHY_INTERFACE_MODE_NA;
Timur Tabi04b4a882012-10-23 09:40:22 +0000106}