4 * This program is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU General Public License as
6 * published by the Free Software Foundation; either version 2 of
7 * the License, or (at your option) any later version.
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
14 * You should have received a copy of the GNU General Public License
15 * along with this program; if not, write to the Free Software
16 * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
19 * Copyright 2010-2011 Freescale Semiconductor, Inc.
27 #define PHY_AUTONEGOTIATE_TIMEOUT 5000
29 /* RTL8211B PHY Status Register */
30 #define MIIM_RTL8211B_PHY_STATUS 0x11
31 #define MIIM_RTL8211B_PHYSTAT_SPEED 0xc000
32 #define MIIM_RTL8211B_PHYSTAT_GBIT 0x8000
33 #define MIIM_RTL8211B_PHYSTAT_100 0x4000
34 #define MIIM_RTL8211B_PHYSTAT_DUPLEX 0x2000
35 #define MIIM_RTL8211B_PHYSTAT_SPDDONE 0x0800
36 #define MIIM_RTL8211B_PHYSTAT_LINK 0x0400
39 /* RealTek RTL8211B */
40 static int rtl8211b_config(struct phy_device *phydev)
42 phy_write(phydev, MDIO_DEVAD_NONE, MII_BMCR, BMCR_RESET);
44 genphy_config_aneg(phydev);
49 static int rtl8211b_parse_status(struct phy_device *phydev)
54 mii_reg = phy_read(phydev, MDIO_DEVAD_NONE, MIIM_RTL8211B_PHY_STATUS);
56 if (!(mii_reg & MIIM_RTL8211B_PHYSTAT_SPDDONE)) {
59 /* in case of timeout ->link is cleared */
61 puts("Waiting for PHY realtime link");
62 while (!(mii_reg & MIIM_RTL8211B_PHYSTAT_SPDDONE)) {
63 /* Timeout reached ? */
64 if (i > PHY_AUTONEGOTIATE_TIMEOUT) {
70 if ((i++ % 1000) == 0)
72 udelay(1000); /* 1 ms */
73 mii_reg = phy_read(phydev, MDIO_DEVAD_NONE,
74 MIIM_RTL8211B_PHY_STATUS);
77 udelay(500000); /* another 500 ms (results in faster booting) */
79 if (mii_reg & MIIM_RTL8211B_PHYSTAT_LINK)
85 if (mii_reg & MIIM_RTL8211B_PHYSTAT_DUPLEX)
86 phydev->duplex = DUPLEX_FULL;
88 phydev->duplex = DUPLEX_HALF;
90 speed = (mii_reg & MIIM_RTL8211B_PHYSTAT_SPEED);
93 case MIIM_RTL8211B_PHYSTAT_GBIT:
94 phydev->speed = SPEED_1000;
96 case MIIM_RTL8211B_PHYSTAT_100:
97 phydev->speed = SPEED_100;
100 phydev->speed = SPEED_10;
106 static int rtl8211b_startup(struct phy_device *phydev)
108 /* Read the Status (2x to make sure link is right) */
109 genphy_update_link(phydev);
110 rtl8211b_parse_status(phydev);
115 static struct phy_driver RTL8211B_driver = {
116 .name = "RealTek RTL8211B",
119 .features = PHY_GBIT_FEATURES,
120 .config = &rtl8211b_config,
121 .startup = &rtl8211b_startup,
122 .shutdown = &genphy_shutdown,
125 int phy_realtek_init(void)
127 phy_register(&RTL8211B_driver);