smsc.c 6.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272
  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_SPECIAL_MODES);
  41. if (rc < 0)
  42. return rc;
  43. /* If the SMSC PHY is in power down mode, then set it
  44. * in all capable mode before using it.
  45. */
  46. if ((rc & MII_LAN83C185_MODE_MASK) == MII_LAN83C185_MODE_POWERDOWN) {
  47. int timeout = 50000;
  48. /* set "all capable" mode and reset the phy */
  49. rc |= MII_LAN83C185_MODE_ALL;
  50. phy_write(phydev, MII_LAN83C185_SPECIAL_MODES, rc);
  51. phy_write(phydev, MII_BMCR, BMCR_RESET);
  52. /* wait end of reset (max 500 ms) */
  53. do {
  54. udelay(10);
  55. if (timeout-- == 0)
  56. return -1;
  57. rc = phy_read(phydev, MII_BMCR);
  58. } while (rc & BMCR_RESET);
  59. }
  60. rc = phy_read(phydev, MII_LAN83C185_CTRL_STATUS);
  61. if (rc < 0)
  62. return rc;
  63. /* Enable energy detect mode for this SMSC Transceivers */
  64. rc = phy_write(phydev, MII_LAN83C185_CTRL_STATUS,
  65. rc | MII_LAN83C185_EDPWRDOWN);
  66. if (rc < 0)
  67. return rc;
  68. return smsc_phy_ack_interrupt (phydev);
  69. }
  70. static int lan911x_config_init(struct phy_device *phydev)
  71. {
  72. return smsc_phy_ack_interrupt(phydev);
  73. }
  74. /*
  75. * The LAN8710/LAN8720 requires a minimum of 2 link pulses within 64ms of each
  76. * other in order to set the ENERGYON bit and exit EDPD mode. If a link partner
  77. * does send the pulses within this interval, the PHY will remained powered
  78. * down.
  79. *
  80. * This workaround will manually toggle the PHY on/off upon calls to read_status
  81. * in order to generate link test pulses if the link is down. If a link partner
  82. * is present, it will respond to the pulses, which will cause the ENERGYON bit
  83. * to be set and will cause the EDPD mode to be exited.
  84. */
  85. static int lan87xx_read_status(struct phy_device *phydev)
  86. {
  87. int err = genphy_read_status(phydev);
  88. if (!phydev->link) {
  89. /* Disable EDPD to wake up PHY */
  90. int rc = phy_read(phydev, MII_LAN83C185_CTRL_STATUS);
  91. if (rc < 0)
  92. return rc;
  93. rc = phy_write(phydev, MII_LAN83C185_CTRL_STATUS,
  94. rc & ~MII_LAN83C185_EDPWRDOWN);
  95. if (rc < 0)
  96. return rc;
  97. /* Sleep 64 ms to allow ~5 link test pulses to be sent */
  98. msleep(64);
  99. /* Re-enable EDPD */
  100. rc = phy_read(phydev, MII_LAN83C185_CTRL_STATUS);
  101. if (rc < 0)
  102. return rc;
  103. rc = phy_write(phydev, MII_LAN83C185_CTRL_STATUS,
  104. rc | MII_LAN83C185_EDPWRDOWN);
  105. if (rc < 0)
  106. return rc;
  107. }
  108. return err;
  109. }
  110. static struct phy_driver smsc_phy_driver[] = {
  111. {
  112. .phy_id = 0x0007c0a0, /* OUI=0x00800f, Model#=0x0a */
  113. .phy_id_mask = 0xfffffff0,
  114. .name = "SMSC LAN83C185",
  115. .features = (PHY_BASIC_FEATURES | SUPPORTED_Pause
  116. | SUPPORTED_Asym_Pause),
  117. .flags = PHY_HAS_INTERRUPT | PHY_HAS_MAGICANEG,
  118. /* basic functions */
  119. .config_aneg = genphy_config_aneg,
  120. .read_status = genphy_read_status,
  121. .config_init = smsc_phy_config_init,
  122. /* IRQ related */
  123. .ack_interrupt = smsc_phy_ack_interrupt,
  124. .config_intr = smsc_phy_config_intr,
  125. .suspend = genphy_suspend,
  126. .resume = genphy_resume,
  127. .driver = { .owner = THIS_MODULE, }
  128. }, {
  129. .phy_id = 0x0007c0b0, /* OUI=0x00800f, Model#=0x0b */
  130. .phy_id_mask = 0xfffffff0,
  131. .name = "SMSC LAN8187",
  132. .features = (PHY_BASIC_FEATURES | SUPPORTED_Pause
  133. | SUPPORTED_Asym_Pause),
  134. .flags = PHY_HAS_INTERRUPT | PHY_HAS_MAGICANEG,
  135. /* basic functions */
  136. .config_aneg = genphy_config_aneg,
  137. .read_status = genphy_read_status,
  138. .config_init = smsc_phy_config_init,
  139. /* IRQ related */
  140. .ack_interrupt = smsc_phy_ack_interrupt,
  141. .config_intr = smsc_phy_config_intr,
  142. .suspend = genphy_suspend,
  143. .resume = genphy_resume,
  144. .driver = { .owner = THIS_MODULE, }
  145. }, {
  146. .phy_id = 0x0007c0c0, /* OUI=0x00800f, Model#=0x0c */
  147. .phy_id_mask = 0xfffffff0,
  148. .name = "SMSC LAN8700",
  149. .features = (PHY_BASIC_FEATURES | SUPPORTED_Pause
  150. | SUPPORTED_Asym_Pause),
  151. .flags = PHY_HAS_INTERRUPT | PHY_HAS_MAGICANEG,
  152. /* basic functions */
  153. .config_aneg = genphy_config_aneg,
  154. .read_status = genphy_read_status,
  155. .config_init = smsc_phy_config_init,
  156. /* IRQ related */
  157. .ack_interrupt = smsc_phy_ack_interrupt,
  158. .config_intr = smsc_phy_config_intr,
  159. .suspend = genphy_suspend,
  160. .resume = genphy_resume,
  161. .driver = { .owner = THIS_MODULE, }
  162. }, {
  163. .phy_id = 0x0007c0d0, /* OUI=0x00800f, Model#=0x0d */
  164. .phy_id_mask = 0xfffffff0,
  165. .name = "SMSC LAN911x Internal PHY",
  166. .features = (PHY_BASIC_FEATURES | SUPPORTED_Pause
  167. | SUPPORTED_Asym_Pause),
  168. .flags = PHY_HAS_INTERRUPT | PHY_HAS_MAGICANEG,
  169. /* basic functions */
  170. .config_aneg = genphy_config_aneg,
  171. .read_status = genphy_read_status,
  172. .config_init = lan911x_config_init,
  173. /* IRQ related */
  174. .ack_interrupt = smsc_phy_ack_interrupt,
  175. .config_intr = smsc_phy_config_intr,
  176. .suspend = genphy_suspend,
  177. .resume = genphy_resume,
  178. .driver = { .owner = THIS_MODULE, }
  179. }, {
  180. .phy_id = 0x0007c0f0, /* OUI=0x00800f, Model#=0x0f */
  181. .phy_id_mask = 0xfffffff0,
  182. .name = "SMSC LAN8710/LAN8720",
  183. .features = (PHY_BASIC_FEATURES | SUPPORTED_Pause
  184. | SUPPORTED_Asym_Pause),
  185. .flags = PHY_HAS_INTERRUPT | PHY_HAS_MAGICANEG,
  186. /* basic functions */
  187. .config_aneg = genphy_config_aneg,
  188. .read_status = lan87xx_read_status,
  189. .config_init = smsc_phy_config_init,
  190. /* IRQ related */
  191. .ack_interrupt = smsc_phy_ack_interrupt,
  192. .config_intr = smsc_phy_config_intr,
  193. .suspend = genphy_suspend,
  194. .resume = genphy_resume,
  195. .driver = { .owner = THIS_MODULE, }
  196. } };
  197. static int __init smsc_init(void)
  198. {
  199. return phy_drivers_register(smsc_phy_driver,
  200. ARRAY_SIZE(smsc_phy_driver));
  201. }
  202. static void __exit smsc_exit(void)
  203. {
  204. return phy_drivers_unregister(smsc_phy_driver,
  205. ARRAY_SIZE(smsc_phy_driver));
  206. }
  207. MODULE_DESCRIPTION("SMSC PHY driver");
  208. MODULE_AUTHOR("Herbert Valerio Riedel");
  209. MODULE_LICENSE("GPL");
  210. module_init(smsc_init);
  211. module_exit(smsc_exit);
  212. static struct mdio_device_id __maybe_unused smsc_tbl[] = {
  213. { 0x0007c0a0, 0xfffffff0 },
  214. { 0x0007c0b0, 0xfffffff0 },
  215. { 0x0007c0c0, 0xfffffff0 },
  216. { 0x0007c0d0, 0xfffffff0 },
  217. { 0x0007c0f0, 0xfffffff0 },
  218. { }
  219. };
  220. MODULE_DEVICE_TABLE(mdio, smsc_tbl);