4 * Derived from Linux kernel driver by Chaithrika U S
5 * Copyright (C) 2013, Texas Instruments, Incorporated - http://www.ti.com/
7 * This program is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU General Public License as
9 * published by the Free Software Foundation; either version 2 of
10 * the License, or (at your option) any later version.
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
21 #define ET1011C_CONFIG_REG (0x16)
22 #define ET1011C_TX_FIFO_MASK (0x3 << 12)
23 #define ET1011C_TX_FIFO_DEPTH_8 (0x0 << 12)
24 #define ET1011C_TX_FIFO_DEPTH_16 (0x1 << 12)
25 #define ET1011C_INTERFACE_MASK (0x7 << 0)
26 #define ET1011C_GMII_INTERFACE (0x2 << 0)
27 #define ET1011C_SYS_CLK_EN (0x1 << 4)
28 #define ET1011C_TX_CLK_EN (0x1 << 5)
30 #define ET1011C_STATUS_REG (0x1A)
31 #define ET1011C_DUPLEX_STATUS (0x1 << 7)
32 #define ET1011C_SPEED_MASK (0x3 << 8)
33 #define ET1011C_SPEED_1000 (0x2 << 8)
34 #define ET1011C_SPEED_100 (0x1 << 8)
35 #define ET1011C_SPEED_10 (0x0 << 8)
37 static int et1011c_config(struct phy_device *phydev)
40 ctl = phy_read(phydev, MDIO_DEVAD_NONE, MII_BMCR);
43 ctl &= ~(BMCR_FULLDPLX | BMCR_SPEED100 | BMCR_SPEED1000 |
45 /* First clear the PHY */
46 phy_write(phydev, MDIO_DEVAD_NONE, MII_BMCR, ctl | BMCR_RESET);
48 return genphy_config_aneg(phydev);
51 static int et1011c_parse_status(struct phy_device *phydev)
56 mii_reg = phy_read(phydev, MDIO_DEVAD_NONE, ET1011C_STATUS_REG);
58 if (mii_reg & ET1011C_DUPLEX_STATUS)
59 phydev->duplex = DUPLEX_FULL;
61 phydev->duplex = DUPLEX_HALF;
63 speed = mii_reg & ET1011C_SPEED_MASK;
65 case ET1011C_SPEED_1000:
66 phydev->speed = SPEED_1000;
67 mii_reg = phy_read(phydev, MDIO_DEVAD_NONE, ET1011C_CONFIG_REG);
68 mii_reg &= ~ET1011C_TX_FIFO_MASK;
69 phy_write(phydev, MDIO_DEVAD_NONE, ET1011C_CONFIG_REG,
71 ET1011C_GMII_INTERFACE |
73 #ifdef CONFIG_PHY_ET1011C_TX_CLK_FIX
76 ET1011C_TX_FIFO_DEPTH_16);
78 case ET1011C_SPEED_100:
79 phydev->speed = SPEED_100;
81 case ET1011C_SPEED_10:
82 phydev->speed = SPEED_10;
89 static int et1011c_startup(struct phy_device *phydev)
91 genphy_update_link(phydev);
92 et1011c_parse_status(phydev);
96 static struct phy_driver et1011c_driver = {
100 .features = PHY_GBIT_FEATURES,
101 .config = &et1011c_config,
102 .startup = &et1011c_startup,
105 int phy_et1011c_init(void)
107 phy_register(&et1011c_driver);