smsc.c 6.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248
  1. /*
  2. * drivers/net/phy/smsc.c
  3. *
  4. * Driver for SMSC PHYs
  5. *
  6. * Author: Herbert Valerio Riedel
  7. *
  8. * Copyright (c) 2006 Herbert Valerio Riedel <hvr@gnu.org>
  9. *
  10. * This program is free software; you can redistribute it and/or modify it
  11. * under the terms of the GNU General Public License as published by the
  12. * Free Software Foundation; either version 2 of the License, or (at your
  13. * option) any later version.
  14. *
  15. * Support added for SMSC LAN8187 and LAN8700 by steve.glendinning@shawell.net
  16. *
  17. */
  18. #include <linux/kernel.h>
  19. #include <linux/module.h>
  20. #include <linux/mii.h>
  21. #include <linux/ethtool.h>
  22. #include <linux/phy.h>
  23. #include <linux/netdevice.h>
  24. #include <linux/smscphy.h>
  25. static int smsc_phy_config_intr(struct phy_device *phydev)
  26. {
  27. int rc = phy_write (phydev, MII_LAN83C185_IM,
  28. ((PHY_INTERRUPT_ENABLED == phydev->interrupts)
  29. ? MII_LAN83C185_ISF_INT_PHYLIB_EVENTS
  30. : 0));
  31. return rc < 0 ? rc : 0;
  32. }
  33. static int smsc_phy_ack_interrupt(struct phy_device *phydev)
  34. {
  35. int rc = phy_read (phydev, MII_LAN83C185_ISF);
  36. return rc < 0 ? rc : 0;
  37. }
  38. static int smsc_phy_config_init(struct phy_device *phydev)
  39. {
  40. int rc = phy_read(phydev, MII_LAN83C185_CTRL_STATUS);
  41. if (rc < 0)
  42. return rc;
  43. /* Enable energy detect mode for this SMSC Transceivers */
  44. rc = phy_write(phydev, MII_LAN83C185_CTRL_STATUS,
  45. rc | MII_LAN83C185_EDPWRDOWN);
  46. if (rc < 0)
  47. return rc;
  48. return smsc_phy_ack_interrupt (phydev);
  49. }
  50. static int lan911x_config_init(struct phy_device *phydev)
  51. {
  52. return smsc_phy_ack_interrupt(phydev);
  53. }
  54. /*
  55. * The LAN8710/LAN8720 requires a minimum of 2 link pulses within 64ms of each
  56. * other in order to set the ENERGYON bit and exit EDPD mode. If a link partner
  57. * does send the pulses within this interval, the PHY will remained powered
  58. * down.
  59. *
  60. * This workaround will manually toggle the PHY on/off upon calls to read_status
  61. * in order to generate link test pulses if the link is down. If a link partner
  62. * is present, it will respond to the pulses, which will cause the ENERGYON bit
  63. * to be set and will cause the EDPD mode to be exited.
  64. */
  65. static int lan87xx_read_status(struct phy_device *phydev)
  66. {
  67. int err = genphy_read_status(phydev);
  68. if (!phydev->link) {
  69. /* Disable EDPD to wake up PHY */
  70. int rc = phy_read(phydev, MII_LAN83C185_CTRL_STATUS);
  71. if (rc < 0)
  72. return rc;
  73. rc = phy_write(phydev, MII_LAN83C185_CTRL_STATUS,
  74. rc & ~MII_LAN83C185_EDPWRDOWN);
  75. if (rc < 0)
  76. return rc;
  77. /* Sleep 64 ms to allow ~5 link test pulses to be sent */
  78. msleep(64);
  79. /* Re-enable EDPD */
  80. rc = phy_read(phydev, MII_LAN83C185_CTRL_STATUS);
  81. if (rc < 0)
  82. return rc;
  83. rc = phy_write(phydev, MII_LAN83C185_CTRL_STATUS,
  84. rc | MII_LAN83C185_EDPWRDOWN);
  85. if (rc < 0)
  86. return rc;
  87. }
  88. return err;
  89. }
  90. static struct phy_driver smsc_phy_driver[] = {
  91. {
  92. .phy_id = 0x0007c0a0, /* OUI=0x00800f, Model#=0x0a */
  93. .phy_id_mask = 0xfffffff0,
  94. .name = "SMSC LAN83C185",
  95. .features = (PHY_BASIC_FEATURES | SUPPORTED_Pause
  96. | SUPPORTED_Asym_Pause),
  97. .flags = PHY_HAS_INTERRUPT | PHY_HAS_MAGICANEG,
  98. /* basic functions */
  99. .config_aneg = genphy_config_aneg,
  100. .read_status = genphy_read_status,
  101. .config_init = smsc_phy_config_init,
  102. /* IRQ related */
  103. .ack_interrupt = smsc_phy_ack_interrupt,
  104. .config_intr = smsc_phy_config_intr,
  105. .suspend = genphy_suspend,
  106. .resume = genphy_resume,
  107. .driver = { .owner = THIS_MODULE, }
  108. }, {
  109. .phy_id = 0x0007c0b0, /* OUI=0x00800f, Model#=0x0b */
  110. .phy_id_mask = 0xfffffff0,
  111. .name = "SMSC LAN8187",
  112. .features = (PHY_BASIC_FEATURES | SUPPORTED_Pause
  113. | SUPPORTED_Asym_Pause),
  114. .flags = PHY_HAS_INTERRUPT | PHY_HAS_MAGICANEG,
  115. /* basic functions */
  116. .config_aneg = genphy_config_aneg,
  117. .read_status = genphy_read_status,
  118. .config_init = smsc_phy_config_init,
  119. /* IRQ related */
  120. .ack_interrupt = smsc_phy_ack_interrupt,
  121. .config_intr = smsc_phy_config_intr,
  122. .suspend = genphy_suspend,
  123. .resume = genphy_resume,
  124. .driver = { .owner = THIS_MODULE, }
  125. }, {
  126. .phy_id = 0x0007c0c0, /* OUI=0x00800f, Model#=0x0c */
  127. .phy_id_mask = 0xfffffff0,
  128. .name = "SMSC LAN8700",
  129. .features = (PHY_BASIC_FEATURES | SUPPORTED_Pause
  130. | SUPPORTED_Asym_Pause),
  131. .flags = PHY_HAS_INTERRUPT | PHY_HAS_MAGICANEG,
  132. /* basic functions */
  133. .config_aneg = genphy_config_aneg,
  134. .read_status = genphy_read_status,
  135. .config_init = smsc_phy_config_init,
  136. /* IRQ related */
  137. .ack_interrupt = smsc_phy_ack_interrupt,
  138. .config_intr = smsc_phy_config_intr,
  139. .suspend = genphy_suspend,
  140. .resume = genphy_resume,
  141. .driver = { .owner = THIS_MODULE, }
  142. }, {
  143. .phy_id = 0x0007c0d0, /* OUI=0x00800f, Model#=0x0d */
  144. .phy_id_mask = 0xfffffff0,
  145. .name = "SMSC LAN911x Internal PHY",
  146. .features = (PHY_BASIC_FEATURES | SUPPORTED_Pause
  147. | SUPPORTED_Asym_Pause),
  148. .flags = PHY_HAS_INTERRUPT | PHY_HAS_MAGICANEG,
  149. /* basic functions */
  150. .config_aneg = genphy_config_aneg,
  151. .read_status = genphy_read_status,
  152. .config_init = lan911x_config_init,
  153. /* IRQ related */
  154. .ack_interrupt = smsc_phy_ack_interrupt,
  155. .config_intr = smsc_phy_config_intr,
  156. .suspend = genphy_suspend,
  157. .resume = genphy_resume,
  158. .driver = { .owner = THIS_MODULE, }
  159. }, {
  160. .phy_id = 0x0007c0f0, /* OUI=0x00800f, Model#=0x0f */
  161. .phy_id_mask = 0xfffffff0,
  162. .name = "SMSC LAN8710/LAN8720",
  163. .features = (PHY_BASIC_FEATURES | SUPPORTED_Pause
  164. | SUPPORTED_Asym_Pause),
  165. .flags = PHY_HAS_INTERRUPT | PHY_HAS_MAGICANEG,
  166. /* basic functions */
  167. .config_aneg = genphy_config_aneg,
  168. .read_status = lan87xx_read_status,
  169. .config_intr = smsc_phy_config_intr,
  170. /* IRQ related */
  171. .ack_interrupt = smsc_phy_ack_interrupt,
  172. .config_intr = smsc_phy_config_intr,
  173. .suspend = genphy_suspend,
  174. .resume = genphy_resume,
  175. .driver = { .owner = THIS_MODULE, }
  176. } };
  177. static int __init smsc_init(void)
  178. {
  179. return phy_drivers_register(smsc_phy_driver,
  180. ARRAY_SIZE(smsc_phy_driver));
  181. }
  182. static void __exit smsc_exit(void)
  183. {
  184. return phy_drivers_unregister(smsc_phy_driver,
  185. ARRAY_SIZE(smsc_phy_driver));
  186. }
  187. MODULE_DESCRIPTION("SMSC PHY driver");
  188. MODULE_AUTHOR("Herbert Valerio Riedel");
  189. MODULE_LICENSE("GPL");
  190. module_init(smsc_init);
  191. module_exit(smsc_exit);
  192. static struct mdio_device_id __maybe_unused smsc_tbl[] = {
  193. { 0x0007c0a0, 0xfffffff0 },
  194. { 0x0007c0b0, 0xfffffff0 },
  195. { 0x0007c0c0, 0xfffffff0 },
  196. { 0x0007c0d0, 0xfffffff0 },
  197. { 0x0007c0f0, 0xfffffff0 },
  198. { }
  199. };
  200. MODULE_DEVICE_TABLE(mdio, smsc_tbl);