dp83848.c 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137
  1. /*
  2. * Driver for the Texas Instruments DP83848 PHY
  3. *
  4. * Copyright (C) 2015-2016 Texas Instruments Incorporated - http://www.ti.com/
  5. *
  6. * This program is free software; you can redistribute it and/or modify
  7. * it under the terms of the GNU General Public License as published by
  8. * the Free Software Foundation; either version 2 of the License.
  9. *
  10. * This program is distributed in the hope that it will be useful,
  11. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. * GNU General Public License for more details.
  14. */
  15. #include <linux/module.h>
  16. #include <linux/phy.h>
  17. #define TI_DP83848C_PHY_ID 0x20005ca0
  18. #define TI_DP83620_PHY_ID 0x20005ce0
  19. #define NS_DP83848C_PHY_ID 0x20005c90
  20. #define TLK10X_PHY_ID 0x2000a210
  21. /* Registers */
  22. #define DP83848_MICR 0x11 /* MII Interrupt Control Register */
  23. #define DP83848_MISR 0x12 /* MII Interrupt Status Register */
  24. /* MICR Register Fields */
  25. #define DP83848_MICR_INT_OE BIT(0) /* Interrupt Output Enable */
  26. #define DP83848_MICR_INTEN BIT(1) /* Interrupt Enable */
  27. /* MISR Register Fields */
  28. #define DP83848_MISR_RHF_INT_EN BIT(0) /* Receive Error Counter */
  29. #define DP83848_MISR_FHF_INT_EN BIT(1) /* False Carrier Counter */
  30. #define DP83848_MISR_ANC_INT_EN BIT(2) /* Auto-negotiation complete */
  31. #define DP83848_MISR_DUP_INT_EN BIT(3) /* Duplex Status */
  32. #define DP83848_MISR_SPD_INT_EN BIT(4) /* Speed status */
  33. #define DP83848_MISR_LINK_INT_EN BIT(5) /* Link status */
  34. #define DP83848_MISR_ED_INT_EN BIT(6) /* Energy detect */
  35. #define DP83848_MISR_LQM_INT_EN BIT(7) /* Link Quality Monitor */
  36. #define DP83848_INT_EN_MASK \
  37. (DP83848_MISR_ANC_INT_EN | \
  38. DP83848_MISR_DUP_INT_EN | \
  39. DP83848_MISR_SPD_INT_EN | \
  40. DP83848_MISR_LINK_INT_EN)
  41. static int dp83848_ack_interrupt(struct phy_device *phydev)
  42. {
  43. int err = phy_read(phydev, DP83848_MISR);
  44. return err < 0 ? err : 0;
  45. }
  46. static int dp83848_config_intr(struct phy_device *phydev)
  47. {
  48. int control, ret;
  49. control = phy_read(phydev, DP83848_MICR);
  50. if (control < 0)
  51. return control;
  52. if (phydev->interrupts == PHY_INTERRUPT_ENABLED) {
  53. control |= DP83848_MICR_INT_OE;
  54. control |= DP83848_MICR_INTEN;
  55. ret = phy_write(phydev, DP83848_MISR, DP83848_INT_EN_MASK);
  56. if (ret < 0)
  57. return ret;
  58. } else {
  59. control &= ~DP83848_MICR_INTEN;
  60. }
  61. return phy_write(phydev, DP83848_MICR, control);
  62. }
  63. static int dp83848_config_init(struct phy_device *phydev)
  64. {
  65. int err;
  66. int val;
  67. err = genphy_config_init(phydev);
  68. if (err < 0)
  69. return err;
  70. /* DP83620 always reports Auto Negotiation Ability on BMSR. Instead,
  71. * we check initial value of BMCR Auto negotiation enable bit
  72. */
  73. val = phy_read(phydev, MII_BMCR);
  74. if (!(val & BMCR_ANENABLE))
  75. phydev->autoneg = AUTONEG_DISABLE;
  76. return 0;
  77. }
  78. static struct mdio_device_id __maybe_unused dp83848_tbl[] = {
  79. { TI_DP83848C_PHY_ID, 0xfffffff0 },
  80. { NS_DP83848C_PHY_ID, 0xfffffff0 },
  81. { TI_DP83620_PHY_ID, 0xfffffff0 },
  82. { TLK10X_PHY_ID, 0xfffffff0 },
  83. { }
  84. };
  85. MODULE_DEVICE_TABLE(mdio, dp83848_tbl);
  86. #define DP83848_PHY_DRIVER(_id, _name, _config_init) \
  87. { \
  88. .phy_id = _id, \
  89. .phy_id_mask = 0xfffffff0, \
  90. .name = _name, \
  91. .features = PHY_BASIC_FEATURES, \
  92. .flags = PHY_HAS_INTERRUPT, \
  93. \
  94. .soft_reset = genphy_soft_reset, \
  95. .config_init = _config_init, \
  96. .suspend = genphy_suspend, \
  97. .resume = genphy_resume, \
  98. \
  99. /* IRQ related */ \
  100. .ack_interrupt = dp83848_ack_interrupt, \
  101. .config_intr = dp83848_config_intr, \
  102. }
  103. static struct phy_driver dp83848_driver[] = {
  104. DP83848_PHY_DRIVER(TI_DP83848C_PHY_ID, "TI DP83848C 10/100 Mbps PHY",
  105. genphy_config_init),
  106. DP83848_PHY_DRIVER(NS_DP83848C_PHY_ID, "NS DP83848C 10/100 Mbps PHY",
  107. genphy_config_init),
  108. DP83848_PHY_DRIVER(TI_DP83620_PHY_ID, "TI DP83620 10/100 Mbps PHY",
  109. dp83848_config_init),
  110. DP83848_PHY_DRIVER(TLK10X_PHY_ID, "TI TLK10X 10/100 Mbps PHY",
  111. genphy_config_init),
  112. };
  113. module_phy_driver(dp83848_driver);
  114. MODULE_DESCRIPTION("Texas Instruments DP83848 PHY driver");
  115. MODULE_AUTHOR("Andrew F. Davis <afd@ti.com>");
  116. MODULE_LICENSE("GPL");