smsc.c 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231
  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 lan87xx_config_init(struct phy_device *phydev)
  51. {
  52. /*
  53. * Make sure the EDPWRDOWN bit is NOT set. Setting this bit on
  54. * LAN8710/LAN8720 PHY causes the PHY to misbehave, likely due
  55. * to a bug on the chip.
  56. *
  57. * When the system is powered on with the network cable being
  58. * disconnected all the way until after ifconfig ethX up is
  59. * issued for the LAN port with this PHY, connecting the cable
  60. * afterwards does not cause LINK change detection, while the
  61. * expected behavior is the Link UP being detected.
  62. */
  63. int rc = phy_read(phydev, MII_LAN83C185_CTRL_STATUS);
  64. if (rc < 0)
  65. return rc;
  66. rc &= ~MII_LAN83C185_EDPWRDOWN;
  67. rc = phy_write(phydev, MII_LAN83C185_CTRL_STATUS, rc);
  68. if (rc < 0)
  69. return rc;
  70. return smsc_phy_ack_interrupt(phydev);
  71. }
  72. static int lan911x_config_init(struct phy_device *phydev)
  73. {
  74. return smsc_phy_ack_interrupt(phydev);
  75. }
  76. static struct phy_driver smsc_phy_driver[] = {
  77. {
  78. .phy_id = 0x0007c0a0, /* OUI=0x00800f, Model#=0x0a */
  79. .phy_id_mask = 0xfffffff0,
  80. .name = "SMSC LAN83C185",
  81. .features = (PHY_BASIC_FEATURES | SUPPORTED_Pause
  82. | SUPPORTED_Asym_Pause),
  83. .flags = PHY_HAS_INTERRUPT | PHY_HAS_MAGICANEG,
  84. /* basic functions */
  85. .config_aneg = genphy_config_aneg,
  86. .read_status = genphy_read_status,
  87. .config_init = smsc_phy_config_init,
  88. /* IRQ related */
  89. .ack_interrupt = smsc_phy_ack_interrupt,
  90. .config_intr = smsc_phy_config_intr,
  91. .suspend = genphy_suspend,
  92. .resume = genphy_resume,
  93. .driver = { .owner = THIS_MODULE, }
  94. }, {
  95. .phy_id = 0x0007c0b0, /* OUI=0x00800f, Model#=0x0b */
  96. .phy_id_mask = 0xfffffff0,
  97. .name = "SMSC LAN8187",
  98. .features = (PHY_BASIC_FEATURES | SUPPORTED_Pause
  99. | SUPPORTED_Asym_Pause),
  100. .flags = PHY_HAS_INTERRUPT | PHY_HAS_MAGICANEG,
  101. /* basic functions */
  102. .config_aneg = genphy_config_aneg,
  103. .read_status = genphy_read_status,
  104. .config_init = smsc_phy_config_init,
  105. /* IRQ related */
  106. .ack_interrupt = smsc_phy_ack_interrupt,
  107. .config_intr = smsc_phy_config_intr,
  108. .suspend = genphy_suspend,
  109. .resume = genphy_resume,
  110. .driver = { .owner = THIS_MODULE, }
  111. }, {
  112. .phy_id = 0x0007c0c0, /* OUI=0x00800f, Model#=0x0c */
  113. .phy_id_mask = 0xfffffff0,
  114. .name = "SMSC LAN8700",
  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 = 0x0007c0d0, /* OUI=0x00800f, Model#=0x0d */
  130. .phy_id_mask = 0xfffffff0,
  131. .name = "SMSC LAN911x Internal PHY",
  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 = lan911x_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 = 0x0007c0f0, /* OUI=0x00800f, Model#=0x0f */
  147. .phy_id_mask = 0xfffffff0,
  148. .name = "SMSC LAN8710/LAN8720",
  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 = lan87xx_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. static int __init smsc_init(void)
  164. {
  165. return phy_drivers_register(smsc_phy_driver,
  166. ARRAY_SIZE(smsc_phy_driver));
  167. }
  168. static void __exit smsc_exit(void)
  169. {
  170. return phy_drivers_unregister(smsc_phy_driver,
  171. ARRAY_SIZE(smsc_phy_driver));
  172. }
  173. MODULE_DESCRIPTION("SMSC PHY driver");
  174. MODULE_AUTHOR("Herbert Valerio Riedel");
  175. MODULE_LICENSE("GPL");
  176. module_init(smsc_init);
  177. module_exit(smsc_exit);
  178. static struct mdio_device_id __maybe_unused smsc_tbl[] = {
  179. { 0x0007c0a0, 0xfffffff0 },
  180. { 0x0007c0b0, 0xfffffff0 },
  181. { 0x0007c0c0, 0xfffffff0 },
  182. { 0x0007c0d0, 0xfffffff0 },
  183. { 0x0007c0f0, 0xfffffff0 },
  184. { }
  185. };
  186. MODULE_DEVICE_TABLE(mdio, smsc_tbl);