lxt.c 3.8 KB

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