lxt.c 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179
  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/config.h>
  17. #include <linux/kernel.h>
  18. #include <linux/sched.h>
  19. #include <linux/string.h>
  20. #include <linux/errno.h>
  21. #include <linux/unistd.h>
  22. #include <linux/slab.h>
  23. #include <linux/interrupt.h>
  24. #include <linux/init.h>
  25. #include <linux/delay.h>
  26. #include <linux/netdevice.h>
  27. #include <linux/etherdevice.h>
  28. #include <linux/skbuff.h>
  29. #include <linux/spinlock.h>
  30. #include <linux/mm.h>
  31. #include <linux/module.h>
  32. #include <linux/version.h>
  33. #include <linux/mii.h>
  34. #include <linux/ethtool.h>
  35. #include <linux/phy.h>
  36. #include <asm/io.h>
  37. #include <asm/irq.h>
  38. #include <asm/uaccess.h>
  39. /* The Level one LXT970 is used by many boards */
  40. #define MII_LXT970_IER 17 /* Interrupt Enable Register */
  41. #define MII_LXT970_IER_IEN 0x0002
  42. #define MII_LXT970_ISR 18 /* Interrupt Status Register */
  43. #define MII_LXT970_CONFIG 19 /* Configuration Register */
  44. /* ------------------------------------------------------------------------- */
  45. /* The Level one LXT971 is used on some of my custom boards */
  46. /* register definitions for the 971 */
  47. #define MII_LXT971_IER 18 /* Interrupt Enable Register */
  48. #define MII_LXT971_IER_IEN 0x00f2
  49. #define MII_LXT971_ISR 19 /* Interrupt Status Register */
  50. MODULE_DESCRIPTION("Intel LXT PHY driver");
  51. MODULE_AUTHOR("Andy Fleming");
  52. MODULE_LICENSE("GPL");
  53. static int lxt970_ack_interrupt(struct phy_device *phydev)
  54. {
  55. int err;
  56. err = phy_read(phydev, MII_BMSR);
  57. if (err < 0)
  58. return err;
  59. err = phy_read(phydev, MII_LXT970_ISR);
  60. if (err < 0)
  61. return err;
  62. return 0;
  63. }
  64. static int lxt970_config_intr(struct phy_device *phydev)
  65. {
  66. int err;
  67. if(phydev->interrupts == PHY_INTERRUPT_ENABLED)
  68. err = phy_write(phydev, MII_LXT970_IER, MII_LXT970_IER_IEN);
  69. else
  70. err = phy_write(phydev, MII_LXT970_IER, 0);
  71. return err;
  72. }
  73. static int lxt970_config_init(struct phy_device *phydev)
  74. {
  75. int err;
  76. err = phy_write(phydev, MII_LXT970_CONFIG, 0);
  77. return err;
  78. }
  79. static int lxt971_ack_interrupt(struct phy_device *phydev)
  80. {
  81. int err = phy_read(phydev, MII_LXT971_ISR);
  82. if (err < 0)
  83. return err;
  84. return 0;
  85. }
  86. static int lxt971_config_intr(struct phy_device *phydev)
  87. {
  88. int err;
  89. if(phydev->interrupts == PHY_INTERRUPT_ENABLED)
  90. err = phy_write(phydev, MII_LXT971_IER, MII_LXT971_IER_IEN);
  91. else
  92. err = phy_write(phydev, MII_LXT971_IER, 0);
  93. return err;
  94. }
  95. static struct phy_driver lxt970_driver = {
  96. .phy_id = 0x07810000,
  97. .name = "LXT970",
  98. .phy_id_mask = 0x0fffffff,
  99. .features = PHY_BASIC_FEATURES,
  100. .flags = PHY_HAS_INTERRUPT,
  101. .config_init = lxt970_config_init,
  102. .config_aneg = genphy_config_aneg,
  103. .read_status = genphy_read_status,
  104. .ack_interrupt = lxt970_ack_interrupt,
  105. .config_intr = lxt970_config_intr,
  106. .driver = { .owner = THIS_MODULE,},
  107. };
  108. static struct phy_driver lxt971_driver = {
  109. .phy_id = 0x0001378e,
  110. .name = "LXT971",
  111. .phy_id_mask = 0x0fffffff,
  112. .features = PHY_BASIC_FEATURES,
  113. .flags = PHY_HAS_INTERRUPT,
  114. .config_aneg = genphy_config_aneg,
  115. .read_status = genphy_read_status,
  116. .ack_interrupt = lxt971_ack_interrupt,
  117. .config_intr = lxt971_config_intr,
  118. .driver = { .owner = THIS_MODULE,},
  119. };
  120. static int __init lxt_init(void)
  121. {
  122. int ret;
  123. ret = phy_driver_register(&lxt970_driver);
  124. if (ret)
  125. goto err1;
  126. ret = phy_driver_register(&lxt971_driver);
  127. if (ret)
  128. goto err2;
  129. return 0;
  130. err2:
  131. phy_driver_unregister(&lxt970_driver);
  132. err1:
  133. return ret;
  134. }
  135. static void __exit lxt_exit(void)
  136. {
  137. phy_driver_unregister(&lxt970_driver);
  138. phy_driver_unregister(&lxt971_driver);
  139. }
  140. module_init(lxt_init);
  141. module_exit(lxt_exit);