bcm63xx.c 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141
  1. /*
  2. * Driver for Broadcom 63xx SOCs integrated PHYs
  3. *
  4. * This program is free software; you can redistribute it and/or
  5. * modify it under the terms of the GNU General Public License
  6. * as published by the Free Software Foundation; either version
  7. * 2 of the License, or (at your option) any later version.
  8. */
  9. #include <linux/module.h>
  10. #include <linux/phy.h>
  11. #define MII_BCM63XX_IR 0x1a /* interrupt register */
  12. #define MII_BCM63XX_IR_EN 0x4000 /* global interrupt enable */
  13. #define MII_BCM63XX_IR_DUPLEX 0x0800 /* duplex changed */
  14. #define MII_BCM63XX_IR_SPEED 0x0400 /* speed changed */
  15. #define MII_BCM63XX_IR_LINK 0x0200 /* link changed */
  16. #define MII_BCM63XX_IR_GMASK 0x0100 /* global interrupt mask */
  17. MODULE_DESCRIPTION("Broadcom 63xx internal PHY driver");
  18. MODULE_AUTHOR("Maxime Bizon <mbizon@freebox.fr>");
  19. MODULE_LICENSE("GPL");
  20. static int bcm63xx_config_init(struct phy_device *phydev)
  21. {
  22. int reg, err;
  23. reg = phy_read(phydev, MII_BCM63XX_IR);
  24. if (reg < 0)
  25. return reg;
  26. /* Mask interrupts globally. */
  27. reg |= MII_BCM63XX_IR_GMASK;
  28. err = phy_write(phydev, MII_BCM63XX_IR, reg);
  29. if (err < 0)
  30. return err;
  31. /* Unmask events we are interested in */
  32. reg = ~(MII_BCM63XX_IR_DUPLEX |
  33. MII_BCM63XX_IR_SPEED |
  34. MII_BCM63XX_IR_LINK) |
  35. MII_BCM63XX_IR_EN;
  36. err = phy_write(phydev, MII_BCM63XX_IR, reg);
  37. if (err < 0)
  38. return err;
  39. return 0;
  40. }
  41. static int bcm63xx_ack_interrupt(struct phy_device *phydev)
  42. {
  43. int reg;
  44. /* Clear pending interrupts. */
  45. reg = phy_read(phydev, MII_BCM63XX_IR);
  46. if (reg < 0)
  47. return reg;
  48. return 0;
  49. }
  50. static int bcm63xx_config_intr(struct phy_device *phydev)
  51. {
  52. int reg, err;
  53. reg = phy_read(phydev, MII_BCM63XX_IR);
  54. if (reg < 0)
  55. return reg;
  56. if (phydev->interrupts == PHY_INTERRUPT_ENABLED)
  57. reg &= ~MII_BCM63XX_IR_GMASK;
  58. else
  59. reg |= MII_BCM63XX_IR_GMASK;
  60. err = phy_write(phydev, MII_BCM63XX_IR, reg);
  61. return err;
  62. }
  63. static struct phy_driver bcm63xx_1_driver = {
  64. .phy_id = 0x00406000,
  65. .phy_id_mask = 0xfffffc00,
  66. .name = "Broadcom BCM63XX (1)",
  67. /* ASYM_PAUSE bit is marked RO in datasheet, so don't cheat */
  68. .features = (PHY_BASIC_FEATURES | SUPPORTED_Pause),
  69. .flags = PHY_HAS_INTERRUPT,
  70. .config_init = bcm63xx_config_init,
  71. .config_aneg = genphy_config_aneg,
  72. .read_status = genphy_read_status,
  73. .ack_interrupt = bcm63xx_ack_interrupt,
  74. .config_intr = bcm63xx_config_intr,
  75. .driver = { .owner = THIS_MODULE },
  76. };
  77. /* same phy as above, with just a different OUI */
  78. static struct phy_driver bcm63xx_2_driver = {
  79. .phy_id = 0x002bdc00,
  80. .phy_id_mask = 0xfffffc00,
  81. .name = "Broadcom BCM63XX (2)",
  82. .features = (PHY_BASIC_FEATURES | SUPPORTED_Pause),
  83. .flags = PHY_HAS_INTERRUPT,
  84. .config_init = bcm63xx_config_init,
  85. .config_aneg = genphy_config_aneg,
  86. .read_status = genphy_read_status,
  87. .ack_interrupt = bcm63xx_ack_interrupt,
  88. .config_intr = bcm63xx_config_intr,
  89. .driver = { .owner = THIS_MODULE },
  90. };
  91. static int __init bcm63xx_phy_init(void)
  92. {
  93. int ret;
  94. ret = phy_driver_register(&bcm63xx_1_driver);
  95. if (ret)
  96. goto out_63xx_1;
  97. ret = phy_driver_register(&bcm63xx_2_driver);
  98. if (ret)
  99. goto out_63xx_2;
  100. return ret;
  101. out_63xx_2:
  102. phy_driver_unregister(&bcm63xx_1_driver);
  103. out_63xx_1:
  104. return ret;
  105. }
  106. static void __exit bcm63xx_phy_exit(void)
  107. {
  108. phy_driver_unregister(&bcm63xx_1_driver);
  109. phy_driver_unregister(&bcm63xx_2_driver);
  110. }
  111. module_init(bcm63xx_phy_init);
  112. module_exit(bcm63xx_phy_exit);
  113. static struct mdio_device_id __maybe_unused bcm63xx_tbl[] = {
  114. { 0x00406000, 0xfffffc00 },
  115. { 0x002bdc00, 0xfffffc00 },
  116. { }
  117. };
  118. MODULE_DEVICE_TABLE(mdio, bcm63xx_tbl);