dp83848.c 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  1. /*
  2. * Driver for the Texas Instruments DP83848 PHY
  3. *
  4. * Copyright (C) 2015 Texas Instruments Inc.
  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 DP83848_PHY_ID 0x20005c90
  18. /* Registers */
  19. #define DP83848_MICR 0x11
  20. #define DP83848_MISR 0x12
  21. /* MICR Register Fields */
  22. #define DP83848_MICR_INT_OE BIT(0) /* Interrupt Output Enable */
  23. #define DP83848_MICR_INTEN BIT(1) /* Interrupt Enable */
  24. /* MISR Register Fields */
  25. #define DP83848_MISR_RHF_INT_EN BIT(0) /* Receive Error Counter */
  26. #define DP83848_MISR_FHF_INT_EN BIT(1) /* False Carrier Counter */
  27. #define DP83848_MISR_ANC_INT_EN BIT(2) /* Auto-negotiation complete */
  28. #define DP83848_MISR_DUP_INT_EN BIT(3) /* Duplex Status */
  29. #define DP83848_MISR_SPD_INT_EN BIT(4) /* Speed status */
  30. #define DP83848_MISR_LINK_INT_EN BIT(5) /* Link status */
  31. #define DP83848_MISR_ED_INT_EN BIT(6) /* Energy detect */
  32. #define DP83848_MISR_LQM_INT_EN BIT(7) /* Link Quality Monitor */
  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 err;
  41. if (phydev->interrupts == PHY_INTERRUPT_ENABLED) {
  42. err = phy_write(phydev, DP83848_MICR,
  43. DP83848_MICR_INT_OE |
  44. DP83848_MICR_INTEN);
  45. if (err < 0)
  46. return err;
  47. return phy_write(phydev, DP83848_MISR,
  48. DP83848_MISR_ANC_INT_EN |
  49. DP83848_MISR_DUP_INT_EN |
  50. DP83848_MISR_SPD_INT_EN |
  51. DP83848_MISR_LINK_INT_EN);
  52. }
  53. return phy_write(phydev, DP83848_MICR, 0x0);
  54. }
  55. static struct mdio_device_id __maybe_unused dp83848_tbl[] = {
  56. { DP83848_PHY_ID, 0xfffffff0 },
  57. { }
  58. };
  59. MODULE_DEVICE_TABLE(mdio, dp83848_tbl);
  60. static struct phy_driver dp83848_driver[] = {
  61. {
  62. .phy_id = DP83848_PHY_ID,
  63. .phy_id_mask = 0xfffffff0,
  64. .name = "TI DP83848",
  65. .features = PHY_BASIC_FEATURES,
  66. .flags = PHY_HAS_INTERRUPT,
  67. .soft_reset = genphy_soft_reset,
  68. .config_init = genphy_config_init,
  69. .suspend = genphy_suspend,
  70. .resume = genphy_resume,
  71. .config_aneg = genphy_config_aneg,
  72. .read_status = genphy_read_status,
  73. /* IRQ related */
  74. .ack_interrupt = dp83848_ack_interrupt,
  75. .config_intr = dp83848_config_intr,
  76. .driver = { .owner = THIS_MODULE, },
  77. },
  78. };
  79. module_phy_driver(dp83848_driver);
  80. MODULE_DESCRIPTION("Texas Instruments DP83848 PHY driver");
  81. MODULE_AUTHOR("Andrew F. Davis <afd@ti.com");
  82. MODULE_LICENSE("GPL");