smsc.c 5.8 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@smsc.com
  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. static struct phy_driver lan83c185_driver = {
  55. .phy_id = 0x0007c0a0, /* OUI=0x00800f, Model#=0x0a */
  56. .phy_id_mask = 0xfffffff0,
  57. .name = "SMSC LAN83C185",
  58. .features = (PHY_BASIC_FEATURES | SUPPORTED_Pause
  59. | SUPPORTED_Asym_Pause),
  60. .flags = PHY_HAS_INTERRUPT | PHY_HAS_MAGICANEG,
  61. /* basic functions */
  62. .config_aneg = genphy_config_aneg,
  63. .read_status = genphy_read_status,
  64. .config_init = smsc_phy_config_init,
  65. /* IRQ related */
  66. .ack_interrupt = smsc_phy_ack_interrupt,
  67. .config_intr = smsc_phy_config_intr,
  68. .suspend = genphy_suspend,
  69. .resume = genphy_resume,
  70. .driver = { .owner = THIS_MODULE, }
  71. };
  72. static struct phy_driver lan8187_driver = {
  73. .phy_id = 0x0007c0b0, /* OUI=0x00800f, Model#=0x0b */
  74. .phy_id_mask = 0xfffffff0,
  75. .name = "SMSC LAN8187",
  76. .features = (PHY_BASIC_FEATURES | SUPPORTED_Pause
  77. | SUPPORTED_Asym_Pause),
  78. .flags = PHY_HAS_INTERRUPT | PHY_HAS_MAGICANEG,
  79. /* basic functions */
  80. .config_aneg = genphy_config_aneg,
  81. .read_status = genphy_read_status,
  82. .config_init = smsc_phy_config_init,
  83. /* IRQ related */
  84. .ack_interrupt = smsc_phy_ack_interrupt,
  85. .config_intr = smsc_phy_config_intr,
  86. .suspend = genphy_suspend,
  87. .resume = genphy_resume,
  88. .driver = { .owner = THIS_MODULE, }
  89. };
  90. static struct phy_driver lan8700_driver = {
  91. .phy_id = 0x0007c0c0, /* OUI=0x00800f, Model#=0x0c */
  92. .phy_id_mask = 0xfffffff0,
  93. .name = "SMSC LAN8700",
  94. .features = (PHY_BASIC_FEATURES | SUPPORTED_Pause
  95. | SUPPORTED_Asym_Pause),
  96. .flags = PHY_HAS_INTERRUPT | PHY_HAS_MAGICANEG,
  97. /* basic functions */
  98. .config_aneg = genphy_config_aneg,
  99. .read_status = genphy_read_status,
  100. .config_init = smsc_phy_config_init,
  101. /* IRQ related */
  102. .ack_interrupt = smsc_phy_ack_interrupt,
  103. .config_intr = smsc_phy_config_intr,
  104. .suspend = genphy_suspend,
  105. .resume = genphy_resume,
  106. .driver = { .owner = THIS_MODULE, }
  107. };
  108. static struct phy_driver lan911x_int_driver = {
  109. .phy_id = 0x0007c0d0, /* OUI=0x00800f, Model#=0x0d */
  110. .phy_id_mask = 0xfffffff0,
  111. .name = "SMSC LAN911x Internal PHY",
  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 = lan911x_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. static struct phy_driver lan8710_driver = {
  127. .phy_id = 0x0007c0f0, /* OUI=0x00800f, Model#=0x0f */
  128. .phy_id_mask = 0xfffffff0,
  129. .name = "SMSC LAN8710/LAN8720",
  130. .features = (PHY_BASIC_FEATURES | SUPPORTED_Pause
  131. | SUPPORTED_Asym_Pause),
  132. .flags = PHY_HAS_INTERRUPT | PHY_HAS_MAGICANEG,
  133. /* basic functions */
  134. .config_aneg = genphy_config_aneg,
  135. .read_status = genphy_read_status,
  136. .config_init = smsc_phy_config_init,
  137. /* IRQ related */
  138. .ack_interrupt = smsc_phy_ack_interrupt,
  139. .config_intr = smsc_phy_config_intr,
  140. .suspend = genphy_suspend,
  141. .resume = genphy_resume,
  142. .driver = { .owner = THIS_MODULE, }
  143. };
  144. static int __init smsc_init(void)
  145. {
  146. int ret;
  147. ret = phy_driver_register (&lan83c185_driver);
  148. if (ret)
  149. goto err1;
  150. ret = phy_driver_register (&lan8187_driver);
  151. if (ret)
  152. goto err2;
  153. ret = phy_driver_register (&lan8700_driver);
  154. if (ret)
  155. goto err3;
  156. ret = phy_driver_register (&lan911x_int_driver);
  157. if (ret)
  158. goto err4;
  159. ret = phy_driver_register (&lan8710_driver);
  160. if (ret)
  161. goto err5;
  162. return 0;
  163. err5:
  164. phy_driver_unregister (&lan911x_int_driver);
  165. err4:
  166. phy_driver_unregister (&lan8700_driver);
  167. err3:
  168. phy_driver_unregister (&lan8187_driver);
  169. err2:
  170. phy_driver_unregister (&lan83c185_driver);
  171. err1:
  172. return ret;
  173. }
  174. static void __exit smsc_exit(void)
  175. {
  176. phy_driver_unregister (&lan8710_driver);
  177. phy_driver_unregister (&lan911x_int_driver);
  178. phy_driver_unregister (&lan8700_driver);
  179. phy_driver_unregister (&lan8187_driver);
  180. phy_driver_unregister (&lan83c185_driver);
  181. }
  182. MODULE_DESCRIPTION("SMSC PHY driver");
  183. MODULE_AUTHOR("Herbert Valerio Riedel");
  184. MODULE_LICENSE("GPL");
  185. module_init(smsc_init);
  186. module_exit(smsc_exit);
  187. static struct mdio_device_id __maybe_unused smsc_tbl[] = {
  188. { 0x0007c0a0, 0xfffffff0 },
  189. { 0x0007c0b0, 0xfffffff0 },
  190. { 0x0007c0c0, 0xfffffff0 },
  191. { 0x0007c0d0, 0xfffffff0 },
  192. { 0x0007c0f0, 0xfffffff0 },
  193. { }
  194. };
  195. MODULE_DEVICE_TABLE(mdio, smsc_tbl);