vitesse.c 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212
  1. /*
  2. * Driver for Vitesse PHYs
  3. *
  4. * Author: Kriston Carson
  5. *
  6. * Copyright (c) 2005, 2009 Freescale Semiconductor, Inc.
  7. *
  8. * This program is free software; you can redistribute it and/or modify it
  9. * under the terms of the GNU General Public License as published by the
  10. * Free Software Foundation; either version 2 of the License, or (at your
  11. * option) any later version.
  12. *
  13. */
  14. #include <linux/kernel.h>
  15. #include <linux/module.h>
  16. #include <linux/mii.h>
  17. #include <linux/ethtool.h>
  18. #include <linux/phy.h>
  19. /* Vitesse Extended Control Register 1 */
  20. #define MII_VSC8244_EXT_CON1 0x17
  21. #define MII_VSC8244_EXTCON1_INIT 0x0000
  22. #define MII_VSC8244_EXTCON1_TX_SKEW_MASK 0x0c00
  23. #define MII_VSC8244_EXTCON1_RX_SKEW_MASK 0x0300
  24. #define MII_VSC8244_EXTCON1_TX_SKEW 0x0800
  25. #define MII_VSC8244_EXTCON1_RX_SKEW 0x0200
  26. /* Vitesse Interrupt Mask Register */
  27. #define MII_VSC8244_IMASK 0x19
  28. #define MII_VSC8244_IMASK_IEN 0x8000
  29. #define MII_VSC8244_IMASK_SPEED 0x4000
  30. #define MII_VSC8244_IMASK_LINK 0x2000
  31. #define MII_VSC8244_IMASK_DUPLEX 0x1000
  32. #define MII_VSC8244_IMASK_MASK 0xf000
  33. #define MII_VSC8221_IMASK_MASK 0xa000
  34. /* Vitesse Interrupt Status Register */
  35. #define MII_VSC8244_ISTAT 0x1a
  36. #define MII_VSC8244_ISTAT_STATUS 0x8000
  37. #define MII_VSC8244_ISTAT_SPEED 0x4000
  38. #define MII_VSC8244_ISTAT_LINK 0x2000
  39. #define MII_VSC8244_ISTAT_DUPLEX 0x1000
  40. /* Vitesse Auxiliary Control/Status Register */
  41. #define MII_VSC8244_AUX_CONSTAT 0x1c
  42. #define MII_VSC8244_AUXCONSTAT_INIT 0x0000
  43. #define MII_VSC8244_AUXCONSTAT_DUPLEX 0x0020
  44. #define MII_VSC8244_AUXCONSTAT_SPEED 0x0018
  45. #define MII_VSC8244_AUXCONSTAT_GBIT 0x0010
  46. #define MII_VSC8244_AUXCONSTAT_100 0x0008
  47. #define MII_VSC8221_AUXCONSTAT_INIT 0x0004 /* need to set this bit? */
  48. #define MII_VSC8221_AUXCONSTAT_RESERVED 0x0004
  49. #define PHY_ID_VSC8244 0x000fc6c0
  50. #define PHY_ID_VSC8221 0x000fc550
  51. MODULE_DESCRIPTION("Vitesse PHY driver");
  52. MODULE_AUTHOR("Kriston Carson");
  53. MODULE_LICENSE("GPL");
  54. int vsc824x_add_skew(struct phy_device *phydev)
  55. {
  56. int err;
  57. int extcon;
  58. extcon = phy_read(phydev, MII_VSC8244_EXT_CON1);
  59. if (extcon < 0)
  60. return extcon;
  61. extcon &= ~(MII_VSC8244_EXTCON1_TX_SKEW_MASK |
  62. MII_VSC8244_EXTCON1_RX_SKEW_MASK);
  63. extcon |= (MII_VSC8244_EXTCON1_TX_SKEW |
  64. MII_VSC8244_EXTCON1_RX_SKEW);
  65. err = phy_write(phydev, MII_VSC8244_EXT_CON1, extcon);
  66. return err;
  67. }
  68. EXPORT_SYMBOL(vsc824x_add_skew);
  69. static int vsc824x_config_init(struct phy_device *phydev)
  70. {
  71. int err;
  72. err = phy_write(phydev, MII_VSC8244_AUX_CONSTAT,
  73. MII_VSC8244_AUXCONSTAT_INIT);
  74. if (err < 0)
  75. return err;
  76. if (phydev->interface == PHY_INTERFACE_MODE_RGMII_ID)
  77. err = vsc824x_add_skew(phydev);
  78. return err;
  79. }
  80. static int vsc824x_ack_interrupt(struct phy_device *phydev)
  81. {
  82. int err = 0;
  83. /*
  84. * Don't bother to ACK the interrupts if interrupts
  85. * are disabled. The 824x cannot clear the interrupts
  86. * if they are disabled.
  87. */
  88. if (phydev->interrupts == PHY_INTERRUPT_ENABLED)
  89. err = phy_read(phydev, MII_VSC8244_ISTAT);
  90. return (err < 0) ? err : 0;
  91. }
  92. static int vsc82xx_config_intr(struct phy_device *phydev)
  93. {
  94. int err;
  95. if (phydev->interrupts == PHY_INTERRUPT_ENABLED)
  96. err = phy_write(phydev, MII_VSC8244_IMASK,
  97. phydev->drv->phy_id == PHY_ID_VSC8244 ?
  98. MII_VSC8244_IMASK_MASK :
  99. MII_VSC8221_IMASK_MASK);
  100. else {
  101. /*
  102. * The Vitesse PHY cannot clear the interrupt
  103. * once it has disabled them, so we clear them first
  104. */
  105. err = phy_read(phydev, MII_VSC8244_ISTAT);
  106. if (err < 0)
  107. return err;
  108. err = phy_write(phydev, MII_VSC8244_IMASK, 0);
  109. }
  110. return err;
  111. }
  112. /* Vitesse 824x */
  113. static struct phy_driver vsc8244_driver = {
  114. .phy_id = PHY_ID_VSC8244,
  115. .name = "Vitesse VSC8244",
  116. .phy_id_mask = 0x000fffc0,
  117. .features = PHY_GBIT_FEATURES,
  118. .flags = PHY_HAS_INTERRUPT,
  119. .config_init = &vsc824x_config_init,
  120. .config_aneg = &genphy_config_aneg,
  121. .read_status = &genphy_read_status,
  122. .ack_interrupt = &vsc824x_ack_interrupt,
  123. .config_intr = &vsc82xx_config_intr,
  124. .driver = { .owner = THIS_MODULE,},
  125. };
  126. static int vsc8221_config_init(struct phy_device *phydev)
  127. {
  128. int err;
  129. err = phy_write(phydev, MII_VSC8244_AUX_CONSTAT,
  130. MII_VSC8221_AUXCONSTAT_INIT);
  131. return err;
  132. /* Perhaps we should set EXT_CON1 based on the interface?
  133. Options are 802.3Z SerDes or SGMII */
  134. }
  135. /* Vitesse 8221 */
  136. static struct phy_driver vsc8221_driver = {
  137. .phy_id = PHY_ID_VSC8221,
  138. .phy_id_mask = 0x000ffff0,
  139. .name = "Vitesse VSC8221",
  140. .features = PHY_GBIT_FEATURES,
  141. .flags = PHY_HAS_INTERRUPT,
  142. .config_init = &vsc8221_config_init,
  143. .config_aneg = &genphy_config_aneg,
  144. .read_status = &genphy_read_status,
  145. .ack_interrupt = &vsc824x_ack_interrupt,
  146. .config_intr = &vsc82xx_config_intr,
  147. .driver = { .owner = THIS_MODULE,},
  148. };
  149. static int __init vsc82xx_init(void)
  150. {
  151. int err;
  152. err = phy_driver_register(&vsc8244_driver);
  153. if (err < 0)
  154. return err;
  155. err = phy_driver_register(&vsc8221_driver);
  156. if (err < 0)
  157. phy_driver_unregister(&vsc8244_driver);
  158. return err;
  159. }
  160. static void __exit vsc82xx_exit(void)
  161. {
  162. phy_driver_unregister(&vsc8244_driver);
  163. phy_driver_unregister(&vsc8221_driver);
  164. }
  165. module_init(vsc82xx_init);
  166. module_exit(vsc82xx_exit);
  167. static struct mdio_device_id __maybe_unused vitesse_tbl[] = {
  168. { PHY_ID_VSC8244, 0x000fffc0 },
  169. { PHY_ID_VSC8221, 0x000ffff0 },
  170. { }
  171. };
  172. MODULE_DEVICE_TABLE(mdio, vitesse_tbl);