microchip_t1.c 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  1. // SPDX-License-Identifier: GPL-2.0
  2. // Copyright (C) 2018 Microchip Technology
  3. #include <linux/kernel.h>
  4. #include <linux/module.h>
  5. #include <linux/mii.h>
  6. #include <linux/phy.h>
  7. /* Interrupt Source Register */
  8. #define LAN87XX_INTERRUPT_SOURCE (0x18)
  9. /* Interrupt Mask Register */
  10. #define LAN87XX_INTERRUPT_MASK (0x19)
  11. #define LAN87XX_MASK_LINK_UP (0x0004)
  12. #define LAN87XX_MASK_LINK_DOWN (0x0002)
  13. #define DRIVER_AUTHOR "Nisar Sayed <nisar.sayed@microchip.com>"
  14. #define DRIVER_DESC "Microchip LAN87XX T1 PHY driver"
  15. static int lan87xx_phy_config_intr(struct phy_device *phydev)
  16. {
  17. int rc, val = 0;
  18. if (phydev->interrupts == PHY_INTERRUPT_ENABLED) {
  19. /* unmask all source and clear them before enable */
  20. rc = phy_write(phydev, LAN87XX_INTERRUPT_MASK, 0x7FFF);
  21. rc = phy_read(phydev, LAN87XX_INTERRUPT_SOURCE);
  22. val = LAN87XX_MASK_LINK_UP | LAN87XX_MASK_LINK_DOWN;
  23. }
  24. rc = phy_write(phydev, LAN87XX_INTERRUPT_MASK, val);
  25. return rc < 0 ? rc : 0;
  26. }
  27. static int lan87xx_phy_ack_interrupt(struct phy_device *phydev)
  28. {
  29. int rc = phy_read(phydev, LAN87XX_INTERRUPT_SOURCE);
  30. return rc < 0 ? rc : 0;
  31. }
  32. static struct phy_driver microchip_t1_phy_driver[] = {
  33. {
  34. .phy_id = 0x0007c150,
  35. .phy_id_mask = 0xfffffff0,
  36. .name = "Microchip LAN87xx T1",
  37. .features = SUPPORTED_100baseT_Full,
  38. .flags = PHY_HAS_INTERRUPT,
  39. .config_init = genphy_config_init,
  40. .config_aneg = genphy_config_aneg,
  41. .ack_interrupt = lan87xx_phy_ack_interrupt,
  42. .config_intr = lan87xx_phy_config_intr,
  43. .suspend = genphy_suspend,
  44. .resume = genphy_resume,
  45. }
  46. };
  47. module_phy_driver(microchip_t1_phy_driver);
  48. static struct mdio_device_id __maybe_unused microchip_t1_tbl[] = {
  49. { 0x0007c150, 0xfffffff0 },
  50. { }
  51. };
  52. MODULE_DEVICE_TABLE(mdio, microchip_t1_tbl);
  53. MODULE_AUTHOR(DRIVER_AUTHOR);
  54. MODULE_DESCRIPTION(DRIVER_DESC);
  55. MODULE_LICENSE("GPL");