lxt.c 3.8 KB

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