et1011c.c 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110
  1. /*
  2. * ET1011C PHY driver
  3. *
  4. * Derived from Linux kernel driver by Chaithrika U S
  5. * Copyright (C) 2013, Texas Instruments, Incorporated - http://www.ti.com/
  6. *
  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.
  11. *
  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.
  16. *
  17. */
  18. #include <config.h>
  19. #include <phy.h>
  20. #define ET1011C_CONFIG_REG (0x16)
  21. #define ET1011C_TX_FIFO_MASK (0x3 << 12)
  22. #define ET1011C_TX_FIFO_DEPTH_8 (0x0 << 12)
  23. #define ET1011C_TX_FIFO_DEPTH_16 (0x1 << 12)
  24. #define ET1011C_INTERFACE_MASK (0x7 << 0)
  25. #define ET1011C_GMII_INTERFACE (0x2 << 0)
  26. #define ET1011C_SYS_CLK_EN (0x1 << 4)
  27. #define ET1011C_TX_CLK_EN (0x1 << 5)
  28. #define ET1011C_STATUS_REG (0x1A)
  29. #define ET1011C_DUPLEX_STATUS (0x1 << 7)
  30. #define ET1011C_SPEED_MASK (0x3 << 8)
  31. #define ET1011C_SPEED_1000 (0x2 << 8)
  32. #define ET1011C_SPEED_100 (0x1 << 8)
  33. #define ET1011C_SPEED_10 (0x0 << 8)
  34. static int et1011c_config(struct phy_device *phydev)
  35. {
  36. int ctl = 0;
  37. ctl = phy_read(phydev, MDIO_DEVAD_NONE, MII_BMCR);
  38. if (ctl < 0)
  39. return ctl;
  40. ctl &= ~(BMCR_FULLDPLX | BMCR_SPEED100 | BMCR_SPEED1000 |
  41. BMCR_ANENABLE);
  42. /* First clear the PHY */
  43. phy_write(phydev, MDIO_DEVAD_NONE, MII_BMCR, ctl | BMCR_RESET);
  44. return genphy_config_aneg(phydev);
  45. }
  46. static int et1011c_parse_status(struct phy_device *phydev)
  47. {
  48. int mii_reg;
  49. int speed;
  50. mii_reg = phy_read(phydev, MDIO_DEVAD_NONE, ET1011C_STATUS_REG);
  51. if (mii_reg & ET1011C_DUPLEX_STATUS)
  52. phydev->duplex = DUPLEX_FULL;
  53. else
  54. phydev->duplex = DUPLEX_HALF;
  55. speed = mii_reg & ET1011C_SPEED_MASK;
  56. switch (speed) {
  57. case ET1011C_SPEED_1000:
  58. phydev->speed = SPEED_1000;
  59. mii_reg = phy_read(phydev, MDIO_DEVAD_NONE, ET1011C_CONFIG_REG);
  60. mii_reg &= ~ET1011C_TX_FIFO_MASK;
  61. phy_write(phydev, MDIO_DEVAD_NONE, ET1011C_CONFIG_REG,
  62. mii_reg |
  63. ET1011C_GMII_INTERFACE |
  64. ET1011C_SYS_CLK_EN |
  65. #ifdef CONFIG_PHY_ET1011C_TX_CLK_FIX
  66. ET1011C_TX_CLK_EN |
  67. #endif
  68. ET1011C_TX_FIFO_DEPTH_16);
  69. break;
  70. case ET1011C_SPEED_100:
  71. phydev->speed = SPEED_100;
  72. break;
  73. case ET1011C_SPEED_10:
  74. phydev->speed = SPEED_10;
  75. break;
  76. }
  77. return 0;
  78. }
  79. static int et1011c_startup(struct phy_device *phydev)
  80. {
  81. genphy_update_link(phydev);
  82. et1011c_parse_status(phydev);
  83. return 0;
  84. }
  85. static struct phy_driver et1011c_driver = {
  86. .name = "ET1011C",
  87. .uid = 0x0282f014,
  88. .mask = 0xfffffff0,
  89. .features = PHY_GBIT_FEATURES,
  90. .config = &et1011c_config,
  91. .startup = &et1011c_startup,
  92. };
  93. int phy_et1011c_init(void)
  94. {
  95. phy_register(&et1011c_driver);
  96. return 0;
  97. }