natsemi.c 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  1. /*
  2. * National Semiconductor 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 <phy.h>
  24. /* DP83865 Link and Auto-Neg Status Register */
  25. #define MIIM_DP83865_LANR 0x11
  26. #define MIIM_DP83865_SPD_MASK 0x0018
  27. #define MIIM_DP83865_SPD_1000 0x0010
  28. #define MIIM_DP83865_SPD_100 0x0008
  29. #define MIIM_DP83865_DPX_FULL 0x0002
  30. /* NatSemi DP83865 */
  31. static int dp83865_config(struct phy_device *phydev)
  32. {
  33. phy_write(phydev, MDIO_DEVAD_NONE, MII_BMCR, BMCR_RESET);
  34. genphy_config_aneg(phydev);
  35. return 0;
  36. }
  37. static int dp83865_parse_status(struct phy_device *phydev)
  38. {
  39. int mii_reg;
  40. mii_reg = phy_read(phydev, MDIO_DEVAD_NONE, MIIM_DP83865_LANR);
  41. switch (mii_reg & MIIM_DP83865_SPD_MASK) {
  42. case MIIM_DP83865_SPD_1000:
  43. phydev->speed = SPEED_1000;
  44. break;
  45. case MIIM_DP83865_SPD_100:
  46. phydev->speed = SPEED_100;
  47. break;
  48. default:
  49. phydev->speed = SPEED_10;
  50. break;
  51. }
  52. if (mii_reg & MIIM_DP83865_DPX_FULL)
  53. phydev->duplex = DUPLEX_FULL;
  54. else
  55. phydev->duplex = DUPLEX_HALF;
  56. return 0;
  57. }
  58. static int dp83865_startup(struct phy_device *phydev)
  59. {
  60. genphy_update_link(phydev);
  61. dp83865_parse_status(phydev);
  62. return 0;
  63. }
  64. static struct phy_driver DP83865_driver = {
  65. .name = "NatSemi DP83865",
  66. .uid = 0x20005c70,
  67. .mask = 0xfffffff0,
  68. .features = PHY_GBIT_FEATURES,
  69. .config = &dp83865_config,
  70. .startup = &dp83865_startup,
  71. .shutdown = &genphy_shutdown,
  72. };
  73. int phy_natsemi_init(void)
  74. {
  75. phy_register(&DP83865_driver);
  76. return 0;
  77. }