Tom Rini | 10e4779 | 2018-05-06 17:58:06 -0400 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0+ |
Shengzhou Liu | e6fb770 | 2014-11-24 17:11:54 +0800 | [diff] [blame] | 2 | /* Copyright 2014 Freescale Semiconductor, Inc. |
| 3 | * |
| 4 | * Shengzhou Liu <Shengzhou.Liu@freescale.com> |
Shengzhou Liu | e6fb770 | 2014-11-24 17:11:54 +0800 | [diff] [blame] | 5 | */ |
| 6 | |
Tom Rini | 6a1ea38 | 2024-05-01 19:31:02 -0600 | [diff] [blame] | 7 | #include <config.h> |
Shengzhou Liu | e6fb770 | 2014-11-24 17:11:54 +0800 | [diff] [blame] | 8 | #include <phy.h> |
| 9 | #include <fm_eth.h> |
| 10 | #include <asm/immap_85xx.h> |
| 11 | #include <asm/fsl_serdes.h> |
| 12 | |
| 13 | u32 port_to_devdisr[] = { |
| 14 | [FM1_DTSEC1] = FSL_CORENET_DEVDISR2_DTSEC1_1, |
| 15 | [FM1_DTSEC2] = FSL_CORENET_DEVDISR2_DTSEC1_2, |
| 16 | [FM1_DTSEC3] = FSL_CORENET_DEVDISR2_DTSEC1_3, |
| 17 | [FM1_DTSEC4] = FSL_CORENET_DEVDISR2_DTSEC1_4, |
| 18 | [FM1_10GEC1] = FSL_CORENET_DEVDISR2_10GEC1_1, /* MAC1 */ |
| 19 | }; |
| 20 | |
| 21 | static int is_device_disabled(enum fm_port port) |
| 22 | { |
Tom Rini | d5c3bf2 | 2022-10-28 20:27:12 -0400 | [diff] [blame] | 23 | ccsr_gur_t *gur = (void __iomem *)(CFG_SYS_MPC85xx_GUTS_ADDR); |
Shengzhou Liu | e6fb770 | 2014-11-24 17:11:54 +0800 | [diff] [blame] | 24 | u32 devdisr2 = in_be32(&gur->devdisr2); |
| 25 | |
| 26 | return port_to_devdisr[port] & devdisr2; |
| 27 | } |
| 28 | |
| 29 | void fman_disable_port(enum fm_port port) |
| 30 | { |
Tom Rini | d5c3bf2 | 2022-10-28 20:27:12 -0400 | [diff] [blame] | 31 | ccsr_gur_t *gur = (void __iomem *)(CFG_SYS_MPC85xx_GUTS_ADDR); |
Shengzhou Liu | e6fb770 | 2014-11-24 17:11:54 +0800 | [diff] [blame] | 32 | |
| 33 | setbits_be32(&gur->devdisr2, port_to_devdisr[port]); |
| 34 | } |
| 35 | |
| 36 | phy_interface_t fman_port_enet_if(enum fm_port port) |
| 37 | { |
Tom Rini | d5c3bf2 | 2022-10-28 20:27:12 -0400 | [diff] [blame] | 38 | ccsr_gur_t *gur = (void __iomem *)(CFG_SYS_MPC85xx_GUTS_ADDR); |
Shengzhou Liu | e6fb770 | 2014-11-24 17:11:54 +0800 | [diff] [blame] | 39 | u32 rcwsr13 = in_be32(&gur->rcwsr[13]); |
| 40 | |
| 41 | if (is_device_disabled(port)) |
Marek BehĂșn | 48631e4 | 2022-04-07 00:33:03 +0200 | [diff] [blame] | 42 | return PHY_INTERFACE_MODE_NA; |
Shengzhou Liu | e6fb770 | 2014-11-24 17:11:54 +0800 | [diff] [blame] | 43 | |
| 44 | if ((port == FM1_10GEC1) && (is_serdes_configured(XFI_FM1_MAC1))) |
| 45 | return PHY_INTERFACE_MODE_XGMII; |
| 46 | |
| 47 | if ((port == FM1_DTSEC3) && ((rcwsr13 & FSL_CORENET_RCWSR13_EC2) == |
| 48 | FSL_CORENET_RCWSR13_EC2_RGMII) && |
| 49 | (!is_serdes_configured(QSGMII_FM1_A))) |
| 50 | return PHY_INTERFACE_MODE_RGMII; |
| 51 | |
| 52 | if ((port == FM1_DTSEC4) && ((rcwsr13 & FSL_CORENET_RCWSR13_EC1) == |
| 53 | FSL_CORENET_RCWSR13_EC1_RGMII) && |
| 54 | (!is_serdes_configured(QSGMII_FM1_A))) |
| 55 | return PHY_INTERFACE_MODE_RGMII; |
| 56 | |
| 57 | /* handle SGMII */ |
| 58 | switch (port) { |
| 59 | case FM1_DTSEC1: |
| 60 | case FM1_DTSEC2: |
| 61 | case FM1_DTSEC3: |
| 62 | if (is_serdes_configured(SGMII_FM1_DTSEC1 + port - FM1_DTSEC1)) |
| 63 | return PHY_INTERFACE_MODE_SGMII; |
| 64 | else if (is_serdes_configured(SGMII_2500_FM1_DTSEC1 |
| 65 | + port - FM1_DTSEC1)) |
Vladimir Oltean | 6caef97 | 2021-09-18 15:32:35 +0300 | [diff] [blame] | 66 | return PHY_INTERFACE_MODE_2500BASEX; |
Shengzhou Liu | e6fb770 | 2014-11-24 17:11:54 +0800 | [diff] [blame] | 67 | break; |
| 68 | default: |
| 69 | break; |
| 70 | } |
| 71 | |
| 72 | /* handle QSGMII */ |
| 73 | switch (port) { |
| 74 | case FM1_DTSEC1: |
| 75 | case FM1_DTSEC2: |
| 76 | case FM1_DTSEC3: |
| 77 | case FM1_DTSEC4: |
| 78 | /* check lane A on SerDes1 */ |
| 79 | if (is_serdes_configured(QSGMII_FM1_A)) |
| 80 | return PHY_INTERFACE_MODE_QSGMII; |
| 81 | break; |
| 82 | default: |
| 83 | break; |
| 84 | } |
| 85 | |
Marek BehĂșn | 48631e4 | 2022-04-07 00:33:03 +0200 | [diff] [blame] | 86 | return PHY_INTERFACE_MODE_NA; |
Shengzhou Liu | e6fb770 | 2014-11-24 17:11:54 +0800 | [diff] [blame] | 87 | } |