Tom Rini | 10e4779 | 2018-05-06 17:58:06 -0400 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0+ |
Kumar Gala | 2683c53 | 2011-04-13 08:37:44 -0500 | [diff] [blame] | 2 | /* |
| 3 | * Copyright 2011 Freescale Semiconductor, Inc. |
Kumar Gala | 2683c53 | 2011-04-13 08:37:44 -0500 | [diff] [blame] | 4 | */ |
Tom Rini | abb9a04 | 2024-05-18 20:20:43 -0600 | [diff] [blame] | 5 | #include <common.h> |
Kumar Gala | 2683c53 | 2011-04-13 08:37:44 -0500 | [diff] [blame] | 6 | #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 | |
Kim Phillips | 914b078 | 2012-10-29 13:34:34 +0000 | [diff] [blame] | 12 | static u32 port_to_devdisr[] = { |
Kumar Gala | 2683c53 | 2011-04-13 08:37:44 -0500 | [diff] [blame] | 13 | [FM1_DTSEC1] = MPC85xx_DEVDISR_TSEC1, |
| 14 | [FM1_DTSEC2] = MPC85xx_DEVDISR_TSEC2, |
| 15 | }; |
| 16 | |
| 17 | static int is_device_disabled(enum fm_port port) |
| 18 | { |
Tom Rini | d5c3bf2 | 2022-10-28 20:27:12 -0400 | [diff] [blame] | 19 | ccsr_gur_t *gur = (void *)(CFG_SYS_MPC85xx_GUTS_ADDR); |
Kumar Gala | 2683c53 | 2011-04-13 08:37:44 -0500 | [diff] [blame] | 20 | u32 devdisr = in_be32(&gur->devdisr); |
| 21 | |
| 22 | return port_to_devdisr[port] & devdisr; |
| 23 | } |
| 24 | |
Kumar Gala | 5536d92 | 2011-09-14 12:01:35 -0500 | [diff] [blame] | 25 | void fman_disable_port(enum fm_port port) |
| 26 | { |
Tom Rini | d5c3bf2 | 2022-10-28 20:27:12 -0400 | [diff] [blame] | 27 | ccsr_gur_t *gur = (void *)(CFG_SYS_MPC85xx_GUTS_ADDR); |
Kumar Gala | 213c7b1 | 2011-10-14 03:17:56 -0500 | [diff] [blame] | 28 | |
| 29 | /* don't allow disabling of DTSEC1 as its needed for MDIO */ |
| 30 | if (port == FM1_DTSEC1) |
| 31 | return; |
| 32 | |
Kumar Gala | 5536d92 | 2011-09-14 12:01:35 -0500 | [diff] [blame] | 33 | setbits_be32(&gur->devdisr, port_to_devdisr[port]); |
| 34 | } |
| 35 | |
Valentin Longchamp | 51b2ca3 | 2013-10-18 11:47:21 +0200 | [diff] [blame] | 36 | void fman_enable_port(enum fm_port port) |
| 37 | { |
Tom Rini | d5c3bf2 | 2022-10-28 20:27:12 -0400 | [diff] [blame] | 38 | ccsr_gur_t *gur = (void *)(CFG_SYS_MPC85xx_GUTS_ADDR); |
Valentin Longchamp | 51b2ca3 | 2013-10-18 11:47:21 +0200 | [diff] [blame] | 39 | |
| 40 | clrbits_be32(&gur->devdisr, port_to_devdisr[port]); |
| 41 | } |
| 42 | |
Kumar Gala | 2683c53 | 2011-04-13 08:37:44 -0500 | [diff] [blame] | 43 | phy_interface_t fman_port_enet_if(enum fm_port port) |
| 44 | { |
Tom Rini | d5c3bf2 | 2022-10-28 20:27:12 -0400 | [diff] [blame] | 45 | ccsr_gur_t *gur = (void *)(CFG_SYS_MPC85xx_GUTS_ADDR); |
Kumar Gala | 2683c53 | 2011-04-13 08:37:44 -0500 | [diff] [blame] | 46 | u32 pordevsr = in_be32(&gur->pordevsr); |
| 47 | |
| 48 | if (is_device_disabled(port)) |
Marek BehĂșn | 48631e4 | 2022-04-07 00:33:03 +0200 | [diff] [blame] | 49 | return PHY_INTERFACE_MODE_NA; |
Kumar Gala | 2683c53 | 2011-04-13 08:37:44 -0500 | [diff] [blame] | 50 | |
| 51 | /* DTSEC1 can be SGMII, RGMII or RMII */ |
| 52 | if (port == FM1_DTSEC1) { |
| 53 | if (is_serdes_configured(SGMII_FM1_DTSEC1)) |
| 54 | return PHY_INTERFACE_MODE_SGMII; |
| 55 | if (pordevsr & MPC85xx_PORDEVSR_SGMII1_DIS) { |
| 56 | if (pordevsr & MPC85xx_PORDEVSR_TSEC1_PRTC) |
| 57 | return PHY_INTERFACE_MODE_RGMII; |
| 58 | else |
| 59 | return PHY_INTERFACE_MODE_RMII; |
| 60 | } |
| 61 | } |
| 62 | |
| 63 | /* DTSEC2 only supports SGMII or RGMII */ |
| 64 | if (port == FM1_DTSEC2) { |
| 65 | if (is_serdes_configured(SGMII_FM1_DTSEC2)) |
| 66 | return PHY_INTERFACE_MODE_SGMII; |
| 67 | if (pordevsr & MPC85xx_PORDEVSR_SGMII2_DIS) |
| 68 | return PHY_INTERFACE_MODE_RGMII; |
| 69 | } |
| 70 | |
Marek BehĂșn | 48631e4 | 2022-04-07 00:33:03 +0200 | [diff] [blame] | 71 | return PHY_INTERFACE_MODE_NA; |
Kumar Gala | 2683c53 | 2011-04-13 08:37:44 -0500 | [diff] [blame] | 72 | } |