blob: febfdd4e874a285095ba38fe4a02ac1eb71bdf09 [file] [log] [blame]
Kumar Gala2683c532011-04-13 08:37:44 -05001/*
2 * Copyright 2011 Freescale Semiconductor, Inc.
3 *
Wolfgang Denkd79de1d2013-07-08 09:37:19 +02004 * SPDX-License-Identifier: GPL-2.0+
Kumar Gala2683c532011-04-13 08:37:44 -05005 */
6#include <common.h>
7#include <phy.h>
8#include <fm_eth.h>
9#include <asm/io.h>
10#include <asm/immap_85xx.h>
11#include <asm/fsl_serdes.h>
12
Kim Phillips914b0782012-10-29 13:34:34 +000013static u32 port_to_devdisr[] = {
Kumar Gala2683c532011-04-13 08:37:44 -050014 [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,
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_10GEC1] = FSL_CORENET_DEVDISR2_10GEC2,
24};
25
26static int is_device_disabled(enum fm_port port)
27{
28 ccsr_gur_t *gur = (void *)(CONFIG_SYS_MPC85xx_GUTS_ADDR);
29 u32 devdisr2 = in_be32(&gur->devdisr2);
30
31 return port_to_devdisr[port] & devdisr2;
32}
33
Kumar Gala5536d922011-09-14 12:01:35 -050034void fman_disable_port(enum fm_port port)
35{
36 ccsr_gur_t *gur = (void *)(CONFIG_SYS_MPC85xx_GUTS_ADDR);
Kumar Gala213c7b12011-10-14 03:17:56 -050037
38 /* don't allow disabling of DTSEC1 as its needed for MDIO */
39 if (port == FM1_DTSEC1)
40 return;
41
Kumar Gala5536d922011-09-14 12:01:35 -050042 setbits_be32(&gur->devdisr2, port_to_devdisr[port]);
43}
44
Kumar Gala2683c532011-04-13 08:37:44 -050045phy_interface_t fman_port_enet_if(enum fm_port port)
46{
47 ccsr_gur_t *gur = (void *)(CONFIG_SYS_MPC85xx_GUTS_ADDR);
48 u32 rcwsr11 = in_be32(&gur->rcwsr[11]);
49
50 if (is_device_disabled(port))
51 return PHY_INTERFACE_MODE_NONE;
52
53 if ((port == FM1_10GEC1) && (is_serdes_configured(XAUI_FM1)))
54 return PHY_INTERFACE_MODE_XGMII;
55
56 if ((port == FM2_10GEC1) && (is_serdes_configured(XAUI_FM2)))
57 return PHY_INTERFACE_MODE_XGMII;
58
59 /* handle RGMII first */
60 if ((port == FM1_DTSEC1) && ((rcwsr11 & FSL_CORENET_RCWSR11_EC1) ==
61 FSL_CORENET_RCWSR11_EC1_FM1_DTSEC1))
62 return PHY_INTERFACE_MODE_RGMII;
63
64 if ((port == FM1_DTSEC2) && ((rcwsr11 & FSL_CORENET_RCWSR11_EC2) ==
65 FSL_CORENET_RCWSR11_EC2_FM1_DTSEC2))
66 return PHY_INTERFACE_MODE_RGMII;
67
68 if ((port == FM2_DTSEC1) && ((rcwsr11 & FSL_CORENET_RCWSR11_EC2) ==
69 FSL_CORENET_RCWSR11_EC2_FM2_DTSEC1))
70 return PHY_INTERFACE_MODE_RGMII;
71
72 switch (port) {
73 case FM1_DTSEC1:
74 case FM1_DTSEC2:
75 case FM1_DTSEC3:
76 case FM1_DTSEC4:
77 if (is_serdes_configured(SGMII_FM1_DTSEC1 + port - FM1_DTSEC1))
78 return PHY_INTERFACE_MODE_SGMII;
79 break;
80 case FM2_DTSEC1:
81 case FM2_DTSEC2:
82 case FM2_DTSEC3:
83 case FM2_DTSEC4:
84 if (is_serdes_configured(SGMII_FM2_DTSEC1 + port - FM2_DTSEC1))
85 return PHY_INTERFACE_MODE_SGMII;
86 break;
87 default:
88 return PHY_INTERFACE_MODE_NONE;
89 }
90
91 return PHY_INTERFACE_MODE_NONE;
92}