blob: 5c158cd5dffc643780a7f22d61fdfe274de51584 [file] [log] [blame]
Kumar Galac916d7c2011-04-13 08:37:44 -05001/*
2 * Copyright 2011 Freescale Semiconductor, Inc.
3 *
Wolfgang Denk1a459662013-07-08 09:37:19 +02004 * SPDX-License-Identifier: GPL-2.0+
Kumar Galac916d7c2011-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 Phillips960d70c2012-10-29 13:34:34 +000013static u32 port_to_devdisr[] = {
Kumar Galac916d7c2011-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_DTSEC5] = FSL_CORENET_DEVDISR2_DTSEC1_5,
19 [FM1_10GEC1] = FSL_CORENET_DEVDISR2_10GEC1,
20};
21
22static int is_device_disabled(enum fm_port port)
23{
24 ccsr_gur_t *gur = (void *)(CONFIG_SYS_MPC85xx_GUTS_ADDR);
25 u32 devdisr2 = in_be32(&gur->devdisr2);
26
27 return port_to_devdisr[port] & devdisr2;
28}
29
Kumar Gala69a85242011-09-14 12:01:35 -050030void fman_disable_port(enum fm_port port)
31{
32 ccsr_gur_t *gur = (void *)(CONFIG_SYS_MPC85xx_GUTS_ADDR);
Kumar Galaf5b9e732011-10-14 03:17:56 -050033
34 /* don't allow disabling of DTSEC1 as its needed for MDIO */
35 if (port == FM1_DTSEC1)
36 return;
37
Kumar Gala69a85242011-09-14 12:01:35 -050038 setbits_be32(&gur->devdisr2, port_to_devdisr[port]);
39}
40
Valentin Longchampf51d3b72013-10-18 11:47:21 +020041void fman_enable_port(enum fm_port port)
42{
43 ccsr_gur_t *gur = (void *)(CONFIG_SYS_MPC85xx_GUTS_ADDR);
44
45 clrbits_be32(&gur->devdisr2, port_to_devdisr[port]);
46}
47
Kumar Galac916d7c2011-04-13 08:37:44 -050048phy_interface_t fman_port_enet_if(enum fm_port port)
49{
50 ccsr_gur_t *gur = (void *)(CONFIG_SYS_MPC85xx_GUTS_ADDR);
51 u32 rcwsr11 = in_be32(&gur->rcwsr[11]);
52
53 if (is_device_disabled(port))
54 return PHY_INTERFACE_MODE_NONE;
55
56 if ((port == FM1_10GEC1) && (is_serdes_configured(XAUI_FM1)))
57 return PHY_INTERFACE_MODE_XGMII;
58
59 /* handle RGMII first */
60 if ((port == FM1_DTSEC4) && ((rcwsr11 & FSL_CORENET_RCWSR11_EC1) ==
61 FSL_CORENET_RCWSR11_EC1_FM1_DTSEC4_RGMII))
62 return PHY_INTERFACE_MODE_RGMII;
63
64 if ((port == FM1_DTSEC4) && ((rcwsr11 & FSL_CORENET_RCWSR11_EC1) ==
65 FSL_CORENET_RCWSR11_EC1_FM1_DTSEC4_MII))
66 return PHY_INTERFACE_MODE_MII;
67
68 if ((port == FM1_DTSEC5) && ((rcwsr11 & FSL_CORENET_RCWSR11_EC2) ==
69 FSL_CORENET_RCWSR11_EC2_FM1_DTSEC5_RGMII))
70 return PHY_INTERFACE_MODE_RGMII;
71
72 if ((port == FM1_DTSEC5) && ((rcwsr11 & FSL_CORENET_RCWSR11_EC2) ==
73 FSL_CORENET_RCWSR11_EC2_FM1_DTSEC5_MII))
74 return PHY_INTERFACE_MODE_MII;
75
76 switch (port) {
77 case FM1_DTSEC1:
78 case FM1_DTSEC2:
79 case FM1_DTSEC3:
80 case FM1_DTSEC4:
81 case FM1_DTSEC5:
82 if (is_serdes_configured(SGMII_FM1_DTSEC1 + port - FM1_DTSEC1))
83 return PHY_INTERFACE_MODE_SGMII;
84 break;
85 default:
86 return PHY_INTERFACE_MODE_NONE;
87 }
88
89 return PHY_INTERFACE_MODE_NONE;
90}