lxt.c 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234
  1. /*
  2. * drivers/net/phy/lxt.c
  3. *
  4. * Driver for Intel LXT PHYs
  5. *
  6. * Author: Andy Fleming
  7. *
  8. * Copyright (c) 2004 Freescale Semiconductor, Inc.
  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. */
  16. #include <linux/kernel.h>
  17. #include <linux/string.h>
  18. #include <linux/errno.h>
  19. #include <linux/unistd.h>
  20. #include <linux/interrupt.h>
  21. #include <linux/init.h>
  22. #include <linux/delay.h>
  23. #include <linux/netdevice.h>
  24. #include <linux/etherdevice.h>
  25. #include <linux/skbuff.h>
  26. #include <linux/spinlock.h>
  27. #include <linux/mm.h>
  28. #include <linux/module.h>
  29. #include <linux/mii.h>
  30. #include <linux/ethtool.h>
  31. #include <linux/phy.h>
  32. #include <asm/io.h>
  33. #include <asm/irq.h>
  34. #include <asm/uaccess.h>
  35. /* The Level one LXT970 is used by many boards */
  36. #define MII_LXT970_IER 17 /* Interrupt Enable Register */
  37. #define MII_LXT970_IER_IEN 0x0002
  38. #define MII_LXT970_ISR 18 /* Interrupt Status Register */
  39. #define MII_LXT970_CONFIG 19 /* Configuration Register */
  40. /* ------------------------------------------------------------------------- */
  41. /* The Level one LXT971 is used on some of my custom boards */
  42. /* register definitions for the 971 */
  43. #define MII_LXT971_IER 18 /* Interrupt Enable Register */
  44. #define MII_LXT971_IER_IEN 0x00f2
  45. #define MII_LXT971_ISR 19 /* Interrupt Status Register */
  46. /* register definitions for the 973 */
  47. #define MII_LXT973_PCR 16 /* Port Configuration Register */
  48. #define PCR_FIBER_SELECT 1
  49. MODULE_DESCRIPTION("Intel LXT PHY driver");
  50. MODULE_AUTHOR("Andy Fleming");
  51. MODULE_LICENSE("GPL");
  52. static int lxt970_ack_interrupt(struct phy_device *phydev)
  53. {
  54. int err;
  55. err = phy_read(phydev, MII_BMSR);
  56. if (err < 0)
  57. return err;
  58. err = phy_read(phydev, MII_LXT970_ISR);
  59. if (err < 0)
  60. return err;
  61. return 0;
  62. }
  63. static int lxt970_config_intr(struct phy_device *phydev)
  64. {
  65. int err;
  66. if(phydev->interrupts == PHY_INTERRUPT_ENABLED)
  67. err = phy_write(phydev, MII_LXT970_IER, MII_LXT970_IER_IEN);
  68. else
  69. err = phy_write(phydev, MII_LXT970_IER, 0);
  70. return err;
  71. }
  72. static int lxt970_config_init(struct phy_device *phydev)
  73. {
  74. int err;
  75. err = phy_write(phydev, MII_LXT970_CONFIG, 0);
  76. return err;
  77. }
  78. static int lxt971_ack_interrupt(struct phy_device *phydev)
  79. {
  80. int err = phy_read(phydev, MII_LXT971_ISR);
  81. if (err < 0)
  82. return err;
  83. return 0;
  84. }
  85. static int lxt971_config_intr(struct phy_device *phydev)
  86. {
  87. int err;
  88. if(phydev->interrupts == PHY_INTERRUPT_ENABLED)
  89. err = phy_write(phydev, MII_LXT971_IER, MII_LXT971_IER_IEN);
  90. else
  91. err = phy_write(phydev, MII_LXT971_IER, 0);
  92. return err;
  93. }
  94. static int lxt973_probe(struct phy_device *phydev)
  95. {
  96. int val = phy_read(phydev, MII_LXT973_PCR);
  97. if (val & PCR_FIBER_SELECT) {
  98. /*
  99. * If fiber is selected, then the only correct setting
  100. * is 100Mbps, full duplex, and auto negotiation off.
  101. */
  102. val = phy_read(phydev, MII_BMCR);
  103. val |= (BMCR_SPEED100 | BMCR_FULLDPLX);
  104. val &= ~BMCR_ANENABLE;
  105. phy_write(phydev, MII_BMCR, val);
  106. /* Remember that the port is in fiber mode. */
  107. phydev->priv = lxt973_probe;
  108. } else {
  109. phydev->priv = NULL;
  110. }
  111. return 0;
  112. }
  113. static int lxt973_config_aneg(struct phy_device *phydev)
  114. {
  115. /* Do nothing if port is in fiber mode. */
  116. return phydev->priv ? 0 : genphy_config_aneg(phydev);
  117. }
  118. static struct phy_driver lxt970_driver = {
  119. .phy_id = 0x78100000,
  120. .name = "LXT970",
  121. .phy_id_mask = 0xfffffff0,
  122. .features = PHY_BASIC_FEATURES,
  123. .flags = PHY_HAS_INTERRUPT,
  124. .config_init = lxt970_config_init,
  125. .config_aneg = genphy_config_aneg,
  126. .read_status = genphy_read_status,
  127. .ack_interrupt = lxt970_ack_interrupt,
  128. .config_intr = lxt970_config_intr,
  129. .driver = { .owner = THIS_MODULE,},
  130. };
  131. static struct phy_driver lxt971_driver = {
  132. .phy_id = 0x001378e0,
  133. .name = "LXT971",
  134. .phy_id_mask = 0xfffffff0,
  135. .features = PHY_BASIC_FEATURES,
  136. .flags = PHY_HAS_INTERRUPT,
  137. .config_aneg = genphy_config_aneg,
  138. .read_status = genphy_read_status,
  139. .ack_interrupt = lxt971_ack_interrupt,
  140. .config_intr = lxt971_config_intr,
  141. .driver = { .owner = THIS_MODULE,},
  142. };
  143. static struct phy_driver lxt973_driver = {
  144. .phy_id = 0x00137a10,
  145. .name = "LXT973",
  146. .phy_id_mask = 0xfffffff0,
  147. .features = PHY_BASIC_FEATURES,
  148. .flags = 0,
  149. .probe = lxt973_probe,
  150. .config_aneg = lxt973_config_aneg,
  151. .read_status = genphy_read_status,
  152. .driver = { .owner = THIS_MODULE,},
  153. };
  154. static int __init lxt_init(void)
  155. {
  156. int ret;
  157. ret = phy_driver_register(&lxt970_driver);
  158. if (ret)
  159. goto err1;
  160. ret = phy_driver_register(&lxt971_driver);
  161. if (ret)
  162. goto err2;
  163. ret = phy_driver_register(&lxt973_driver);
  164. if (ret)
  165. goto err3;
  166. return 0;
  167. err3:
  168. phy_driver_unregister(&lxt971_driver);
  169. err2:
  170. phy_driver_unregister(&lxt970_driver);
  171. err1:
  172. return ret;
  173. }
  174. static void __exit lxt_exit(void)
  175. {
  176. phy_driver_unregister(&lxt970_driver);
  177. phy_driver_unregister(&lxt971_driver);
  178. phy_driver_unregister(&lxt973_driver);
  179. }
  180. module_init(lxt_init);
  181. module_exit(lxt_exit);
  182. static struct mdio_device_id __maybe_unused lxt_tbl[] = {
  183. { 0x78100000, 0xfffffff0 },
  184. { 0x001378e0, 0xfffffff0 },
  185. { 0x00137a10, 0xfffffff0 },
  186. { }
  187. };
  188. MODULE_DEVICE_TABLE(mdio, lxt_tbl);