010-add_integrated_ethernet_phy_support.patch 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183
  1. From 7eefcb968019804e024c8243e28afb1eebd674a2 Mon Sep 17 00:00:00 2001
  2. From: Maxime Bizon <[email protected]>
  3. Date: Sun, 21 Sep 2008 02:20:53 +0200
  4. Subject: [PATCH] [MIPS] BCM63XX: Add integrated ethernet PHY support for phylib.
  5. Signed-off-by: Maxime Bizon <[email protected]>
  6. ---
  7. drivers/net/phy/Kconfig | 6 ++
  8. drivers/net/phy/Makefile | 1 +
  9. drivers/net/phy/bcm63xx.c | 132 +++++++++++++++++++++++++++++++++++++++++++++
  10. 3 files changed, 139 insertions(+), 0 deletions(-)
  11. create mode 100644 drivers/net/phy/bcm63xx.c
  12. diff --git a/drivers/net/phy/Kconfig b/drivers/net/phy/Kconfig
  13. index d55932a..a5d2c2d 100644
  14. --- a/drivers/net/phy/Kconfig
  15. +++ b/drivers/net/phy/Kconfig
  16. @@ -56,6 +56,12 @@ config BROADCOM_PHY
  17. Currently supports the BCM5411, BCM5421, BCM5461, BCM5464, BCM5481
  18. and BCM5482 PHYs.
  19. +config BCM63XX_PHY
  20. + tristate "Drivers for Broadcom 63xx SOCs internal PHY"
  21. + depends on BCM63XX
  22. + ---help---
  23. + Currently supports the 6348 and 6358 PHYs.
  24. +
  25. config ICPLUS_PHY
  26. tristate "Drivers for ICPlus PHYs"
  27. ---help---
  28. diff --git a/drivers/net/phy/Makefile b/drivers/net/phy/Makefile
  29. index eee329f..0d43f58 100644
  30. --- a/drivers/net/phy/Makefile
  31. +++ b/drivers/net/phy/Makefile
  32. @@ -11,6 +11,7 @@ obj-$(CONFIG_QSEMI_PHY) += qsemi.o
  33. obj-$(CONFIG_SMSC_PHY) += smsc.o
  34. obj-$(CONFIG_VITESSE_PHY) += vitesse.o
  35. obj-$(CONFIG_BROADCOM_PHY) += broadcom.o
  36. +obj-$(CONFIG_BCM63XX_PHY) += bcm63xx.o
  37. obj-$(CONFIG_ICPLUS_PHY) += icplus.o
  38. obj-$(CONFIG_REALTEK_PHY) += realtek.o
  39. obj-$(CONFIG_FIXED_PHY) += fixed.o
  40. diff --git a/drivers/net/phy/bcm63xx.c b/drivers/net/phy/bcm63xx.c
  41. new file mode 100644
  42. index 0000000..4fed95e
  43. --- /dev/null
  44. +++ b/drivers/net/phy/bcm63xx.c
  45. @@ -0,0 +1,132 @@
  46. +/*
  47. + * Driver for Broadcom 63xx SOCs integrated PHYs
  48. + *
  49. + * This program is free software; you can redistribute it and/or
  50. + * modify it under the terms of the GNU General Public License
  51. + * as published by the Free Software Foundation; either version
  52. + * 2 of the License, or (at your option) any later version.
  53. + */
  54. +#include <linux/module.h>
  55. +#include <linux/phy.h>
  56. +
  57. +#define MII_BCM63XX_IR 0x1a /* interrupt register */
  58. +#define MII_BCM63XX_IR_EN 0x4000 /* global interrupt enable */
  59. +#define MII_BCM63XX_IR_DUPLEX 0x0800 /* duplex changed */
  60. +#define MII_BCM63XX_IR_SPEED 0x0400 /* speed changed */
  61. +#define MII_BCM63XX_IR_LINK 0x0200 /* link changed */
  62. +#define MII_BCM63XX_IR_GMASK 0x0100 /* global interrupt mask */
  63. +
  64. +MODULE_DESCRIPTION("Broadcom 63xx internal PHY driver");
  65. +MODULE_AUTHOR("Maxime Bizon <[email protected]>");
  66. +MODULE_LICENSE("GPL");
  67. +
  68. +static int bcm63xx_config_init(struct phy_device *phydev)
  69. +{
  70. + int reg, err;
  71. +
  72. + reg = phy_read(phydev, MII_BCM63XX_IR);
  73. + if (reg < 0)
  74. + return reg;
  75. +
  76. + /* Mask interrupts globally. */
  77. + reg |= MII_BCM63XX_IR_GMASK;
  78. + err = phy_write(phydev, MII_BCM63XX_IR, reg);
  79. + if (err < 0)
  80. + return err;
  81. +
  82. + /* Unmask events we are interested in */
  83. + reg = ~(MII_BCM63XX_IR_DUPLEX |
  84. + MII_BCM63XX_IR_SPEED |
  85. + MII_BCM63XX_IR_LINK) |
  86. + MII_BCM63XX_IR_EN;
  87. + err = phy_write(phydev, MII_BCM63XX_IR, reg);
  88. + if (err < 0)
  89. + return err;
  90. + return 0;
  91. +}
  92. +
  93. +static int bcm63xx_ack_interrupt(struct phy_device *phydev)
  94. +{
  95. + int reg;
  96. +
  97. + /* Clear pending interrupts. */
  98. + reg = phy_read(phydev, MII_BCM63XX_IR);
  99. + if (reg < 0)
  100. + return reg;
  101. +
  102. + return 0;
  103. +}
  104. +
  105. +static int bcm63xx_config_intr(struct phy_device *phydev)
  106. +{
  107. + int reg, err;
  108. +
  109. + reg = phy_read(phydev, MII_BCM63XX_IR);
  110. + if (reg < 0)
  111. + return reg;
  112. +
  113. + if (phydev->interrupts == PHY_INTERRUPT_ENABLED)
  114. + reg &= ~MII_BCM63XX_IR_GMASK;
  115. + else
  116. + reg |= MII_BCM63XX_IR_GMASK;
  117. +
  118. + err = phy_write(phydev, MII_BCM63XX_IR, reg);
  119. + return err;
  120. +}
  121. +
  122. +static struct phy_driver bcm63xx_1_driver = {
  123. + .phy_id = 0x00406000,
  124. + .phy_id_mask = 0xfffffc00,
  125. + .name = "Broadcom BCM63XX (1)",
  126. + /* ASYM_PAUSE bit is marked RO in datasheet, so don't cheat */
  127. + .features = (PHY_BASIC_FEATURES | SUPPORTED_Pause),
  128. + .flags = PHY_HAS_INTERRUPT,
  129. + .config_init = bcm63xx_config_init,
  130. + .config_aneg = genphy_config_aneg,
  131. + .read_status = genphy_read_status,
  132. + .ack_interrupt = bcm63xx_ack_interrupt,
  133. + .config_intr = bcm63xx_config_intr,
  134. + .driver = { .owner = THIS_MODULE },
  135. +};
  136. +
  137. +/* same phy as above, with just a different OUI */
  138. +static struct phy_driver bcm63xx_2_driver = {
  139. + .phy_id = 0x002bdc00,
  140. + .phy_id_mask = 0xfffffc00,
  141. + .name = "Broadcom BCM63XX (2)",
  142. + .features = (PHY_BASIC_FEATURES | SUPPORTED_Pause),
  143. + .flags = PHY_HAS_INTERRUPT,
  144. + .config_init = bcm63xx_config_init,
  145. + .config_aneg = genphy_config_aneg,
  146. + .read_status = genphy_read_status,
  147. + .ack_interrupt = bcm63xx_ack_interrupt,
  148. + .config_intr = bcm63xx_config_intr,
  149. + .driver = { .owner = THIS_MODULE },
  150. +};
  151. +
  152. +static int __init bcm63xx_phy_init(void)
  153. +{
  154. + int ret;
  155. +
  156. + ret = phy_driver_register(&bcm63xx_1_driver);
  157. + if (ret)
  158. + goto out_63xx_1;
  159. + ret = phy_driver_register(&bcm63xx_2_driver);
  160. + if (ret)
  161. + goto out_63xx_2;
  162. + return ret;
  163. +
  164. +out_63xx_2:
  165. + phy_driver_unregister(&bcm63xx_1_driver);
  166. +out_63xx_1:
  167. + return ret;
  168. +}
  169. +
  170. +static void __exit bcm63xx_phy_exit(void)
  171. +{
  172. + phy_driver_unregister(&bcm63xx_1_driver);
  173. + phy_driver_unregister(&bcm63xx_2_driver);
  174. +}
  175. +
  176. +module_init(bcm63xx_phy_init);
  177. +module_exit(bcm63xx_phy_exit);
  178. --
  179. 1.5.4.3