dp83848.c 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124
  1. // SPDX-License-Identifier: GPL-2.0
  2. /*
  3. * Driver for the Texas Instruments DP83848 PHY
  4. *
  5. * Copyright (C) 2015-2016 Texas Instruments Incorporated - http://www.ti.com/
  6. */
  7. #include <linux/module.h>
  8. #include <linux/phy.h>
  9. #define TI_DP83848C_PHY_ID 0x20005ca0
  10. #define TI_DP83620_PHY_ID 0x20005ce0
  11. #define NS_DP83848C_PHY_ID 0x20005c90
  12. #define TLK10X_PHY_ID 0x2000a210
  13. /* Registers */
  14. #define DP83848_MICR 0x11 /* MII Interrupt Control Register */
  15. #define DP83848_MISR 0x12 /* MII Interrupt Status Register */
  16. /* MICR Register Fields */
  17. #define DP83848_MICR_INT_OE BIT(0) /* Interrupt Output Enable */
  18. #define DP83848_MICR_INTEN BIT(1) /* Interrupt Enable */
  19. /* MISR Register Fields */
  20. #define DP83848_MISR_RHF_INT_EN BIT(0) /* Receive Error Counter */
  21. #define DP83848_MISR_FHF_INT_EN BIT(1) /* False Carrier Counter */
  22. #define DP83848_MISR_ANC_INT_EN BIT(2) /* Auto-negotiation complete */
  23. #define DP83848_MISR_DUP_INT_EN BIT(3) /* Duplex Status */
  24. #define DP83848_MISR_SPD_INT_EN BIT(4) /* Speed status */
  25. #define DP83848_MISR_LINK_INT_EN BIT(5) /* Link status */
  26. #define DP83848_MISR_ED_INT_EN BIT(6) /* Energy detect */
  27. #define DP83848_MISR_LQM_INT_EN BIT(7) /* Link Quality Monitor */
  28. #define DP83848_INT_EN_MASK \
  29. (DP83848_MISR_ANC_INT_EN | \
  30. DP83848_MISR_DUP_INT_EN | \
  31. DP83848_MISR_SPD_INT_EN | \
  32. DP83848_MISR_LINK_INT_EN)
  33. static int dp83848_ack_interrupt(struct phy_device *phydev)
  34. {
  35. int err = phy_read(phydev, DP83848_MISR);
  36. return err < 0 ? err : 0;
  37. }
  38. static int dp83848_config_intr(struct phy_device *phydev)
  39. {
  40. int control, ret;
  41. control = phy_read(phydev, DP83848_MICR);
  42. if (control < 0)
  43. return control;
  44. if (phydev->interrupts == PHY_INTERRUPT_ENABLED) {
  45. control |= DP83848_MICR_INT_OE;
  46. control |= DP83848_MICR_INTEN;
  47. ret = phy_write(phydev, DP83848_MISR, DP83848_INT_EN_MASK);
  48. if (ret < 0)
  49. return ret;
  50. } else {
  51. control &= ~DP83848_MICR_INTEN;
  52. }
  53. return phy_write(phydev, DP83848_MICR, control);
  54. }
  55. static int dp83848_config_init(struct phy_device *phydev)
  56. {
  57. int val;
  58. /* DP83620 always reports Auto Negotiation Ability on BMSR. Instead,
  59. * we check initial value of BMCR Auto negotiation enable bit
  60. */
  61. val = phy_read(phydev, MII_BMCR);
  62. if (!(val & BMCR_ANENABLE))
  63. phydev->autoneg = AUTONEG_DISABLE;
  64. return 0;
  65. }
  66. static struct mdio_device_id __maybe_unused dp83848_tbl[] = {
  67. { TI_DP83848C_PHY_ID, 0xfffffff0 },
  68. { NS_DP83848C_PHY_ID, 0xfffffff0 },
  69. { TI_DP83620_PHY_ID, 0xfffffff0 },
  70. { TLK10X_PHY_ID, 0xfffffff0 },
  71. { }
  72. };
  73. MODULE_DEVICE_TABLE(mdio, dp83848_tbl);
  74. #define DP83848_PHY_DRIVER(_id, _name, _config_init) \
  75. { \
  76. .phy_id = _id, \
  77. .phy_id_mask = 0xfffffff0, \
  78. .name = _name, \
  79. /* PHY_BASIC_FEATURES */ \
  80. \
  81. .soft_reset = genphy_soft_reset, \
  82. .config_init = _config_init, \
  83. .suspend = genphy_suspend, \
  84. .resume = genphy_resume, \
  85. \
  86. /* IRQ related */ \
  87. .ack_interrupt = dp83848_ack_interrupt, \
  88. .config_intr = dp83848_config_intr, \
  89. }
  90. static struct phy_driver dp83848_driver[] = {
  91. DP83848_PHY_DRIVER(TI_DP83848C_PHY_ID, "TI DP83848C 10/100 Mbps PHY",
  92. NULL),
  93. DP83848_PHY_DRIVER(NS_DP83848C_PHY_ID, "NS DP83848C 10/100 Mbps PHY",
  94. NULL),
  95. DP83848_PHY_DRIVER(TI_DP83620_PHY_ID, "TI DP83620 10/100 Mbps PHY",
  96. dp83848_config_init),
  97. DP83848_PHY_DRIVER(TLK10X_PHY_ID, "TI TLK10X 10/100 Mbps PHY",
  98. NULL),
  99. };
  100. module_phy_driver(dp83848_driver);
  101. MODULE_DESCRIPTION("Texas Instruments DP83848 PHY driver");
  102. MODULE_AUTHOR("Andrew F. Davis <afd@ti.com>");
  103. MODULE_LICENSE("GPL v2");