smsc.c 6.8 KB

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