blob: 9013b276bc954fb03ce3d3260b8ca5f30fa5e37a [file] [log] [blame]
Tom Rini10e47792018-05-06 17:58:06 -04001// SPDX-License-Identifier: GPL-2.0+
Kumar Gala2683c532011-04-13 08:37:44 -05002/*
3 * Copyright 2011 Freescale Semiconductor, Inc.
Kumar Gala2683c532011-04-13 08:37:44 -05004 */
5#include <common.h>
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 Phillips914b0782012-10-29 13:34:34 +000012static u32 port_to_devdisr[] = {
Kumar Gala2683c532011-04-13 08:37:44 -050013 [FM1_DTSEC1] = MPC85xx_DEVDISR_TSEC1,
14 [FM1_DTSEC2] = MPC85xx_DEVDISR_TSEC2,
15};
16
17static int is_device_disabled(enum fm_port port)
18{
Tom Rinid5c3bf22022-10-28 20:27:12 -040019 ccsr_gur_t *gur = (void *)(CFG_SYS_MPC85xx_GUTS_ADDR);
Kumar Gala2683c532011-04-13 08:37:44 -050020 u32 devdisr = in_be32(&gur->devdisr);
21
22 return port_to_devdisr[port] & devdisr;
23}
24
Kumar Gala5536d922011-09-14 12:01:35 -050025void fman_disable_port(enum fm_port port)
26{
Tom Rinid5c3bf22022-10-28 20:27:12 -040027 ccsr_gur_t *gur = (void *)(CFG_SYS_MPC85xx_GUTS_ADDR);
Kumar Gala213c7b12011-10-14 03:17:56 -050028
29 /* don't allow disabling of DTSEC1 as its needed for MDIO */
30 if (port == FM1_DTSEC1)
31 return;
32
Kumar Gala5536d922011-09-14 12:01:35 -050033 setbits_be32(&gur->devdisr, port_to_devdisr[port]);
34}
35
Valentin Longchamp51b2ca32013-10-18 11:47:21 +020036void fman_enable_port(enum fm_port port)
37{
Tom Rinid5c3bf22022-10-28 20:27:12 -040038 ccsr_gur_t *gur = (void *)(CFG_SYS_MPC85xx_GUTS_ADDR);
Valentin Longchamp51b2ca32013-10-18 11:47:21 +020039
40 clrbits_be32(&gur->devdisr, port_to_devdisr[port]);
41}
42
Kumar Gala2683c532011-04-13 08:37:44 -050043phy_interface_t fman_port_enet_if(enum fm_port port)
44{
Tom Rinid5c3bf22022-10-28 20:27:12 -040045 ccsr_gur_t *gur = (void *)(CFG_SYS_MPC85xx_GUTS_ADDR);
Kumar Gala2683c532011-04-13 08:37:44 -050046 u32 pordevsr = in_be32(&gur->pordevsr);
47
48 if (is_device_disabled(port))
Marek BehĂșn48631e42022-04-07 00:33:03 +020049 return PHY_INTERFACE_MODE_NA;
Kumar Gala2683c532011-04-13 08:37:44 -050050
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Ășn48631e42022-04-07 00:33:03 +020071 return PHY_INTERFACE_MODE_NA;
Kumar Gala2683c532011-04-13 08:37:44 -050072}