micrel.c 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138
  1. /*
  2. * Micrel PHY drivers
  3. *
  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.
  8. *
  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.
  13. *
  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,
  17. * MA 02111-1307 USA
  18. *
  19. * Copyright 2010-2011 Freescale Semiconductor, Inc.
  20. * author Andy Fleming
  21. *
  22. */
  23. #include <config.h>
  24. #include <common.h>
  25. #include <micrel.h>
  26. #include <phy.h>
  27. static struct phy_driver KSZ804_driver = {
  28. .name = "Micrel KSZ804",
  29. .uid = 0x221510,
  30. .mask = 0xfffff0,
  31. .features = PHY_BASIC_FEATURES,
  32. .config = &genphy_config,
  33. .startup = &genphy_startup,
  34. .shutdown = &genphy_shutdown,
  35. };
  36. static struct phy_driver KS8721_driver = {
  37. .name = "Micrel KS8721BL",
  38. .uid = 0x221610,
  39. .mask = 0xfffff0,
  40. .features = PHY_BASIC_FEATURES,
  41. .config = &genphy_config,
  42. .startup = &genphy_startup,
  43. .shutdown = &genphy_shutdown,
  44. };
  45. /* ksz9021 PHY Registers */
  46. #define MII_KSZ9021_EXTENDED_CTRL 0x0b
  47. #define MII_KSZ9021_EXTENDED_DATAW 0x0c
  48. #define MII_KSZ9021_EXTENDED_DATAR 0x0d
  49. #define MII_KSZ9021_PHY_CTL 0x1f
  50. #define MIIM_KSZ9021_PHYCTL_1000 (1 << 6)
  51. #define MIIM_KSZ9021_PHYCTL_100 (1 << 5)
  52. #define MIIM_KSZ9021_PHYCTL_10 (1 << 4)
  53. #define MIIM_KSZ9021_PHYCTL_DUPLEX (1 << 3)
  54. #define CTRL1000_PREFER_MASTER (1 << 10)
  55. #define CTRL1000_CONFIG_MASTER (1 << 11)
  56. #define CTRL1000_MANUAL_CONFIG (1 << 12)
  57. int ksz9021_phy_extended_write(struct phy_device *phydev, int regnum, u16 val)
  58. {
  59. /* extended registers */
  60. phy_write(phydev, MDIO_DEVAD_NONE,
  61. MII_KSZ9021_EXTENDED_CTRL, regnum | 0x8000);
  62. return phy_write(phydev, MDIO_DEVAD_NONE,
  63. MII_KSZ9021_EXTENDED_DATAW, val);
  64. }
  65. int ksz9021_phy_extended_read(struct phy_device *phydev, int regnum)
  66. {
  67. /* extended registers */
  68. phy_write(phydev, MDIO_DEVAD_NONE, MII_KSZ9021_EXTENDED_CTRL, regnum);
  69. return phy_read(phydev, MDIO_DEVAD_NONE, MII_KSZ9021_EXTENDED_DATAR);
  70. }
  71. /* Micrel ksz9021 */
  72. static int ksz9021_config(struct phy_device *phydev)
  73. {
  74. unsigned ctrl1000 = 0;
  75. const unsigned master = CTRL1000_PREFER_MASTER |
  76. CTRL1000_CONFIG_MASTER | CTRL1000_MANUAL_CONFIG;
  77. unsigned features = phydev->drv->features;
  78. if (getenv("disable_giga"))
  79. features &= ~(SUPPORTED_1000baseT_Half |
  80. SUPPORTED_1000baseT_Full);
  81. /* force master mode for 1000BaseT due to chip errata */
  82. if (features & SUPPORTED_1000baseT_Half)
  83. ctrl1000 |= ADVERTISE_1000HALF | master;
  84. if (features & SUPPORTED_1000baseT_Full)
  85. ctrl1000 |= ADVERTISE_1000FULL | master;
  86. phydev->advertising = phydev->supported = features;
  87. phy_write(phydev, MDIO_DEVAD_NONE, MII_CTRL1000, ctrl1000);
  88. genphy_config_aneg(phydev);
  89. genphy_restart_aneg(phydev);
  90. return 0;
  91. }
  92. static int ksz9021_startup(struct phy_device *phydev)
  93. {
  94. unsigned phy_ctl;
  95. genphy_update_link(phydev);
  96. phy_ctl = phy_read(phydev, MDIO_DEVAD_NONE, MII_KSZ9021_PHY_CTL);
  97. if (phy_ctl & MIIM_KSZ9021_PHYCTL_DUPLEX)
  98. phydev->duplex = DUPLEX_FULL;
  99. else
  100. phydev->duplex = DUPLEX_HALF;
  101. if (phy_ctl & MIIM_KSZ9021_PHYCTL_1000)
  102. phydev->speed = SPEED_1000;
  103. else if (phy_ctl & MIIM_KSZ9021_PHYCTL_100)
  104. phydev->speed = SPEED_100;
  105. else if (phy_ctl & MIIM_KSZ9021_PHYCTL_10)
  106. phydev->speed = SPEED_10;
  107. return 0;
  108. }
  109. static struct phy_driver ksz9021_driver = {
  110. .name = "Micrel ksz9021",
  111. .uid = 0x221610,
  112. .mask = 0xfffff0,
  113. .features = PHY_GBIT_FEATURES,
  114. .config = &ksz9021_config,
  115. .startup = &ksz9021_startup,
  116. .shutdown = &genphy_shutdown,
  117. };
  118. int phy_micrel_init(void)
  119. {
  120. phy_register(&KSZ804_driver);
  121. phy_register(&KS8721_driver);
  122. phy_register(&ksz9021_driver);
  123. return 0;
  124. }