bcm63xx.c 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  1. // SPDX-License-Identifier: GPL-2.0+
  2. /*
  3. * Driver for Broadcom 63xx SOCs integrated PHYs
  4. */
  5. #include "bcm-phy-lib.h"
  6. #include <linux/module.h>
  7. #include <linux/phy.h>
  8. #define MII_BCM63XX_IR 0x1a /* interrupt register */
  9. #define MII_BCM63XX_IR_EN 0x4000 /* global interrupt enable */
  10. #define MII_BCM63XX_IR_DUPLEX 0x0800 /* duplex changed */
  11. #define MII_BCM63XX_IR_SPEED 0x0400 /* speed changed */
  12. #define MII_BCM63XX_IR_LINK 0x0200 /* link changed */
  13. #define MII_BCM63XX_IR_GMASK 0x0100 /* global interrupt mask */
  14. MODULE_DESCRIPTION("Broadcom 63xx internal PHY driver");
  15. MODULE_AUTHOR("Maxime Bizon <mbizon@freebox.fr>");
  16. MODULE_LICENSE("GPL");
  17. static int bcm63xx_config_intr(struct phy_device *phydev)
  18. {
  19. int reg, err;
  20. reg = phy_read(phydev, MII_BCM63XX_IR);
  21. if (reg < 0)
  22. return reg;
  23. if (phydev->interrupts == PHY_INTERRUPT_ENABLED)
  24. reg &= ~MII_BCM63XX_IR_GMASK;
  25. else
  26. reg |= MII_BCM63XX_IR_GMASK;
  27. err = phy_write(phydev, MII_BCM63XX_IR, reg);
  28. return err;
  29. }
  30. static int bcm63xx_config_init(struct phy_device *phydev)
  31. {
  32. int reg, err;
  33. /* ASYM_PAUSE bit is marked RO in datasheet, so don't cheat */
  34. linkmode_set_bit(ETHTOOL_LINK_MODE_Pause_BIT, phydev->supported);
  35. reg = phy_read(phydev, MII_BCM63XX_IR);
  36. if (reg < 0)
  37. return reg;
  38. /* Mask interrupts globally. */
  39. reg |= MII_BCM63XX_IR_GMASK;
  40. err = phy_write(phydev, MII_BCM63XX_IR, reg);
  41. if (err < 0)
  42. return err;
  43. /* Unmask events we are interested in */
  44. reg = ~(MII_BCM63XX_IR_DUPLEX |
  45. MII_BCM63XX_IR_SPEED |
  46. MII_BCM63XX_IR_LINK) |
  47. MII_BCM63XX_IR_EN;
  48. return phy_write(phydev, MII_BCM63XX_IR, reg);
  49. }
  50. static struct phy_driver bcm63xx_driver[] = {
  51. {
  52. .phy_id = 0x00406000,
  53. .phy_id_mask = 0xfffffc00,
  54. .name = "Broadcom BCM63XX (1)",
  55. /* PHY_BASIC_FEATURES */
  56. .flags = PHY_IS_INTERNAL,
  57. .config_init = bcm63xx_config_init,
  58. .ack_interrupt = bcm_phy_ack_intr,
  59. .config_intr = bcm63xx_config_intr,
  60. }, {
  61. /* same phy as above, with just a different OUI */
  62. .phy_id = 0x002bdc00,
  63. .phy_id_mask = 0xfffffc00,
  64. .name = "Broadcom BCM63XX (2)",
  65. /* PHY_BASIC_FEATURES */
  66. .flags = PHY_IS_INTERNAL,
  67. .config_init = bcm63xx_config_init,
  68. .ack_interrupt = bcm_phy_ack_intr,
  69. .config_intr = bcm63xx_config_intr,
  70. } };
  71. module_phy_driver(bcm63xx_driver);
  72. static struct mdio_device_id __maybe_unused bcm63xx_tbl[] = {
  73. { 0x00406000, 0xfffffc00 },
  74. { 0x002bdc00, 0xfffffc00 },
  75. { }
  76. };
  77. MODULE_DEVICE_TABLE(mdio, bcm63xx_tbl);