xref: /openbmc/u-boot/drivers/net/fm/p5040.c (revision 83d290c5)
1*83d290c5STom Rini // SPDX-License-Identifier: GPL-2.0+
2d31e53b4STimur Tabi /*
3d31e53b4STimur Tabi  * Copyright 2011 Freescale Semiconductor, Inc.
4d31e53b4STimur Tabi  */
5d31e53b4STimur Tabi #include <common.h>
6d31e53b4STimur Tabi #include <phy.h>
7d31e53b4STimur Tabi #include <fm_eth.h>
8d31e53b4STimur Tabi #include <asm/io.h>
9d31e53b4STimur Tabi #include <asm/immap_85xx.h>
10d31e53b4STimur Tabi #include <asm/fsl_serdes.h>
11d31e53b4STimur Tabi 
12d31e53b4STimur Tabi u32 port_to_devdisr[] = {
13d31e53b4STimur Tabi 	[FM1_DTSEC1] = FSL_CORENET_DEVDISR2_DTSEC1_1,
14d31e53b4STimur Tabi 	[FM1_DTSEC2] = FSL_CORENET_DEVDISR2_DTSEC1_2,
15d31e53b4STimur Tabi 	[FM1_DTSEC3] = FSL_CORENET_DEVDISR2_DTSEC1_3,
16d31e53b4STimur Tabi 	[FM1_DTSEC4] = FSL_CORENET_DEVDISR2_DTSEC1_4,
17d31e53b4STimur Tabi 	[FM1_DTSEC5] = FSL_CORENET_DEVDISR2_DTSEC1_5,
18d31e53b4STimur Tabi 	[FM1_10GEC1] = FSL_CORENET_DEVDISR2_10GEC1,
19d31e53b4STimur Tabi 	[FM2_DTSEC1] = FSL_CORENET_DEVDISR2_DTSEC2_1,
20d31e53b4STimur Tabi 	[FM2_DTSEC2] = FSL_CORENET_DEVDISR2_DTSEC2_2,
21d31e53b4STimur Tabi 	[FM2_DTSEC3] = FSL_CORENET_DEVDISR2_DTSEC2_3,
22d31e53b4STimur Tabi 	[FM2_DTSEC4] = FSL_CORENET_DEVDISR2_DTSEC2_4,
23d31e53b4STimur Tabi 	[FM2_DTSEC5] = FSL_CORENET_DEVDISR2_DTSEC2_5,
24d31e53b4STimur Tabi 	[FM2_10GEC1] = FSL_CORENET_DEVDISR2_10GEC2,
25d31e53b4STimur Tabi };
26d31e53b4STimur Tabi 
27d31e53b4STimur Tabi static int is_device_disabled(enum fm_port port)
28d31e53b4STimur Tabi {
29d31e53b4STimur Tabi 	ccsr_gur_t *gur = (void *)(CONFIG_SYS_MPC85xx_GUTS_ADDR);
30d31e53b4STimur Tabi 	u32 devdisr2 = in_be32(&gur->devdisr2);
31d31e53b4STimur Tabi 
32d31e53b4STimur Tabi 	return port_to_devdisr[port] & devdisr2;
33d31e53b4STimur Tabi }
34d31e53b4STimur Tabi 
35d31e53b4STimur Tabi void fman_disable_port(enum fm_port port)
36d31e53b4STimur Tabi {
37d31e53b4STimur Tabi 	ccsr_gur_t *gur = (void *)(CONFIG_SYS_MPC85xx_GUTS_ADDR);
38d31e53b4STimur Tabi 
39d31e53b4STimur Tabi 	/* don't allow disabling of DTSEC1 as its needed for MDIO */
40d31e53b4STimur Tabi 	if (port == FM1_DTSEC1)
41d31e53b4STimur Tabi 		return;
42d31e53b4STimur Tabi 
43d31e53b4STimur Tabi 	setbits_be32(&gur->devdisr2, port_to_devdisr[port]);
44d31e53b4STimur Tabi }
45d31e53b4STimur Tabi 
46f51d3b71SValentin Longchamp void fman_enable_port(enum fm_port port)
47f51d3b71SValentin Longchamp {
48f51d3b71SValentin Longchamp 	ccsr_gur_t *gur = (void *)(CONFIG_SYS_MPC85xx_GUTS_ADDR);
49f51d3b71SValentin Longchamp 
50f51d3b71SValentin Longchamp 	clrbits_be32(&gur->devdisr2, port_to_devdisr[port]);
51f51d3b71SValentin Longchamp }
52f51d3b71SValentin Longchamp 
53d31e53b4STimur Tabi phy_interface_t fman_port_enet_if(enum fm_port port)
54d31e53b4STimur Tabi {
55d31e53b4STimur Tabi 	ccsr_gur_t *gur = (void *)(CONFIG_SYS_MPC85xx_GUTS_ADDR);
56d31e53b4STimur Tabi 	u32 rcwsr11 = in_be32(&gur->rcwsr[11]);
57d31e53b4STimur Tabi 
58d31e53b4STimur Tabi 	if (is_device_disabled(port))
59d31e53b4STimur Tabi 		return PHY_INTERFACE_MODE_NONE;
60d31e53b4STimur Tabi 
61d31e53b4STimur Tabi 	if ((port == FM1_10GEC1) && (is_serdes_configured(XAUI_FM1)))
62d31e53b4STimur Tabi 		return PHY_INTERFACE_MODE_XGMII;
63d31e53b4STimur Tabi 
64d31e53b4STimur Tabi 	if ((port == FM2_10GEC1) && (is_serdes_configured(XAUI_FM2)))
65d31e53b4STimur Tabi 		return PHY_INTERFACE_MODE_XGMII;
66d31e53b4STimur Tabi 
67d31e53b4STimur Tabi 	/* handle RGMII first */
68d31e53b4STimur Tabi 	if ((port == FM1_DTSEC5) && ((rcwsr11 & FSL_CORENET_RCWSR11_EC1) ==
69d31e53b4STimur Tabi 		FSL_CORENET_RCWSR11_EC1_FM1_DTSEC5_RGMII))
70d31e53b4STimur Tabi 		return PHY_INTERFACE_MODE_RGMII;
71d31e53b4STimur Tabi 
72d31e53b4STimur Tabi 	if ((port == FM1_DTSEC5) && ((rcwsr11 & FSL_CORENET_RCWSR11_EC1) ==
73d31e53b4STimur Tabi 		FSL_CORENET_RCWSR11_EC1_FM1_DTSEC5_MII))
74d31e53b4STimur Tabi 		return PHY_INTERFACE_MODE_MII;
75d31e53b4STimur Tabi 
76d31e53b4STimur Tabi 	if ((port == FM2_DTSEC5) && ((rcwsr11 & FSL_CORENET_RCWSR11_EC2) ==
77d31e53b4STimur Tabi 		FSL_CORENET_RCWSR11_EC2_FM2_DTSEC5_RGMII))
78d31e53b4STimur Tabi 		return PHY_INTERFACE_MODE_RGMII;
79d31e53b4STimur Tabi 
80d31e53b4STimur Tabi 	if ((port == FM2_DTSEC5) && ((rcwsr11 & FSL_CORENET_RCWSR11_EC2) ==
81d31e53b4STimur Tabi 		FSL_CORENET_RCWSR11_EC2_FM2_DTSEC5_MII))
82d31e53b4STimur Tabi 		return PHY_INTERFACE_MODE_MII;
83d31e53b4STimur Tabi 
84d31e53b4STimur Tabi 	switch (port) {
85d31e53b4STimur Tabi 	case FM1_DTSEC1:
86d31e53b4STimur Tabi 	case FM1_DTSEC2:
87d31e53b4STimur Tabi 	case FM1_DTSEC3:
88d31e53b4STimur Tabi 	case FM1_DTSEC4:
89d31e53b4STimur Tabi 	case FM1_DTSEC5:
90d31e53b4STimur Tabi 		if (is_serdes_configured(SGMII_FM1_DTSEC1 + port - FM1_DTSEC1))
91d31e53b4STimur Tabi 			return PHY_INTERFACE_MODE_SGMII;
92d31e53b4STimur Tabi 		break;
93d31e53b4STimur Tabi 	case FM2_DTSEC1:
94d31e53b4STimur Tabi 	case FM2_DTSEC2:
95d31e53b4STimur Tabi 	case FM2_DTSEC3:
96d31e53b4STimur Tabi 	case FM2_DTSEC4:
97d31e53b4STimur Tabi 	case FM2_DTSEC5:
98d31e53b4STimur Tabi 		if (is_serdes_configured(SGMII_FM2_DTSEC1 + port - FM2_DTSEC1))
99d31e53b4STimur Tabi 			return PHY_INTERFACE_MODE_SGMII;
100d31e53b4STimur Tabi 		break;
101d31e53b4STimur Tabi 	default:
102d31e53b4STimur Tabi 		return PHY_INTERFACE_MODE_NONE;
103d31e53b4STimur Tabi 	}
104d31e53b4STimur Tabi 
105d31e53b4STimur Tabi 	return PHY_INTERFACE_MODE_NONE;
106d31e53b4STimur Tabi }
107