teranetics.c 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  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_aneg_done(struct phy_device *phydev)
  33. {
  34. /* auto negotiation state can only be checked when using copper
  35. * port, if using fiber port, just lie it's done.
  36. */
  37. if (!phy_read_mmd(phydev, MDIO_MMD_VEND1, 93))
  38. return genphy_c45_aneg_done(phydev);
  39. return 1;
  40. }
  41. static int teranetics_read_status(struct phy_device *phydev)
  42. {
  43. int reg;
  44. phydev->link = 1;
  45. phydev->speed = SPEED_10000;
  46. phydev->duplex = DUPLEX_FULL;
  47. if (!phy_read_mmd(phydev, MDIO_MMD_VEND1, 93)) {
  48. reg = phy_read_mmd(phydev, MDIO_MMD_PHYXS, MDIO_PHYXS_LNSTAT);
  49. if (reg < 0 ||
  50. !((reg & MDIO_PHYXS_LANE_READY) == MDIO_PHYXS_LANE_READY)) {
  51. phydev->link = 0;
  52. return 0;
  53. }
  54. reg = phy_read_mmd(phydev, MDIO_MMD_AN, MDIO_STAT1);
  55. if (reg < 0 || !(reg & MDIO_STAT1_LSTATUS))
  56. phydev->link = 0;
  57. }
  58. return 0;
  59. }
  60. static int teranetics_match_phy_device(struct phy_device *phydev)
  61. {
  62. return phydev->c45_ids.device_ids[3] == PHY_ID_TN2020;
  63. }
  64. static struct phy_driver teranetics_driver[] = {
  65. {
  66. .phy_id = PHY_ID_TN2020,
  67. .phy_id_mask = 0xffffffff,
  68. .name = "Teranetics TN2020",
  69. .soft_reset = gen10g_no_soft_reset,
  70. .aneg_done = teranetics_aneg_done,
  71. .config_init = gen10g_config_init,
  72. .config_aneg = gen10g_config_aneg,
  73. .read_status = teranetics_read_status,
  74. .match_phy_device = teranetics_match_phy_device,
  75. },
  76. };
  77. module_phy_driver(teranetics_driver);
  78. static struct mdio_device_id __maybe_unused teranetics_tbl[] = {
  79. { PHY_ID_TN2020, 0xffffffff },
  80. { }
  81. };
  82. MODULE_DEVICE_TABLE(mdio, teranetics_tbl);