teranetics.c 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122
  1. /*
  2. * Driver for Teranetics PHY
  3. *
  4. * Author: Shaohui Xie <Shaohui.Xie@freescale.com>
  5. *
  6. * Copyright 2015 Freescale Semiconductor, Inc.
  7. *
  8. * This file is licensed under the terms of the GNU General Public License
  9. * version 2. This program is licensed "as is" without any warranty of any
  10. * kind, whether express or implied.
  11. */
  12. #include <linux/kernel.h>
  13. #include <linux/module.h>
  14. #include <linux/mii.h>
  15. #include <linux/ethtool.h>
  16. #include <linux/mdio.h>
  17. #include <linux/phy.h>
  18. MODULE_DESCRIPTION("Teranetics PHY driver");
  19. MODULE_AUTHOR("Shaohui Xie <Shaohui.Xie@freescale.com>");
  20. MODULE_LICENSE("GPL v2");
  21. #define PHY_ID_TN2020 0x00a19410
  22. #define MDIO_PHYXS_LNSTAT_SYNC0 0x0001
  23. #define MDIO_PHYXS_LNSTAT_SYNC1 0x0002
  24. #define MDIO_PHYXS_LNSTAT_SYNC2 0x0004
  25. #define MDIO_PHYXS_LNSTAT_SYNC3 0x0008
  26. #define MDIO_PHYXS_LNSTAT_ALIGN 0x1000
  27. #define MDIO_PHYXS_LANE_READY (MDIO_PHYXS_LNSTAT_SYNC0 | \
  28. MDIO_PHYXS_LNSTAT_SYNC1 | \
  29. MDIO_PHYXS_LNSTAT_SYNC2 | \
  30. MDIO_PHYXS_LNSTAT_SYNC3 | \
  31. MDIO_PHYXS_LNSTAT_ALIGN)
  32. static int teranetics_config_init(struct phy_device *phydev)
  33. {
  34. phydev->supported = SUPPORTED_10000baseT_Full;
  35. phydev->advertising = SUPPORTED_10000baseT_Full;
  36. return 0;
  37. }
  38. static int teranetics_soft_reset(struct phy_device *phydev)
  39. {
  40. return 0;
  41. }
  42. static int teranetics_aneg_done(struct phy_device *phydev)
  43. {
  44. int reg;
  45. /* auto negotiation state can only be checked when using copper
  46. * port, if using fiber port, just lie it's done.
  47. */
  48. if (!phy_read_mmd(phydev, MDIO_MMD_VEND1, 93)) {
  49. reg = phy_read_mmd(phydev, MDIO_MMD_AN, MDIO_STAT1);
  50. return (reg < 0) ? reg : (reg & BMSR_ANEGCOMPLETE);
  51. }
  52. return 1;
  53. }
  54. static int teranetics_config_aneg(struct phy_device *phydev)
  55. {
  56. return 0;
  57. }
  58. static int teranetics_read_status(struct phy_device *phydev)
  59. {
  60. int reg;
  61. phydev->link = 1;
  62. phydev->speed = SPEED_10000;
  63. phydev->duplex = DUPLEX_FULL;
  64. if (!phy_read_mmd(phydev, MDIO_MMD_VEND1, 93)) {
  65. reg = phy_read_mmd(phydev, MDIO_MMD_PHYXS, MDIO_PHYXS_LNSTAT);
  66. if (reg < 0 ||
  67. !((reg & MDIO_PHYXS_LANE_READY) == MDIO_PHYXS_LANE_READY)) {
  68. phydev->link = 0;
  69. return 0;
  70. }
  71. reg = phy_read_mmd(phydev, MDIO_MMD_AN, MDIO_STAT1);
  72. if (reg < 0 || !(reg & MDIO_STAT1_LSTATUS))
  73. phydev->link = 0;
  74. }
  75. return 0;
  76. }
  77. static int teranetics_match_phy_device(struct phy_device *phydev)
  78. {
  79. return phydev->c45_ids.device_ids[3] == PHY_ID_TN2020;
  80. }
  81. static struct phy_driver teranetics_driver[] = {
  82. {
  83. .phy_id = PHY_ID_TN2020,
  84. .phy_id_mask = 0xffffffff,
  85. .name = "Teranetics TN2020",
  86. .soft_reset = teranetics_soft_reset,
  87. .aneg_done = teranetics_aneg_done,
  88. .config_init = teranetics_config_init,
  89. .config_aneg = teranetics_config_aneg,
  90. .read_status = teranetics_read_status,
  91. .match_phy_device = teranetics_match_phy_device,
  92. .driver = { .owner = THIS_MODULE,},
  93. },
  94. };
  95. module_phy_driver(teranetics_driver);
  96. static struct mdio_device_id __maybe_unused teranetics_tbl[] = {
  97. { PHY_ID_TN2020, 0xffffffff },
  98. { }
  99. };
  100. MODULE_DEVICE_TABLE(mdio, teranetics_tbl);