vitesse.c 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216
  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. #define PHY_ID_VSC8211 0x000fc4b0
  52. MODULE_DESCRIPTION("Vitesse PHY driver");
  53. MODULE_AUTHOR("Kriston Carson");
  54. MODULE_LICENSE("GPL");
  55. static int vsc824x_add_skew(struct phy_device *phydev)
  56. {
  57. int err;
  58. int extcon;
  59. extcon = phy_read(phydev, MII_VSC8244_EXT_CON1);
  60. if (extcon < 0)
  61. return extcon;
  62. extcon &= ~(MII_VSC8244_EXTCON1_TX_SKEW_MASK |
  63. MII_VSC8244_EXTCON1_RX_SKEW_MASK);
  64. extcon |= (MII_VSC8244_EXTCON1_TX_SKEW |
  65. MII_VSC8244_EXTCON1_RX_SKEW);
  66. err = phy_write(phydev, MII_VSC8244_EXT_CON1, extcon);
  67. return err;
  68. }
  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. /* Don't bother to ACK the interrupts if interrupts
  84. * are disabled. The 824x cannot clear the interrupts
  85. * if they are disabled.
  86. */
  87. if (phydev->interrupts == PHY_INTERRUPT_ENABLED)
  88. err = phy_read(phydev, MII_VSC8244_ISTAT);
  89. return (err < 0) ? err : 0;
  90. }
  91. static int vsc82xx_config_intr(struct phy_device *phydev)
  92. {
  93. int err;
  94. if (phydev->interrupts == PHY_INTERRUPT_ENABLED)
  95. err = phy_write(phydev, MII_VSC8244_IMASK,
  96. phydev->drv->phy_id == PHY_ID_VSC8244 ?
  97. MII_VSC8244_IMASK_MASK :
  98. MII_VSC8221_IMASK_MASK);
  99. else {
  100. /* The Vitesse PHY cannot clear the interrupt
  101. * once it has disabled them, so we clear them first
  102. */
  103. err = phy_read(phydev, MII_VSC8244_ISTAT);
  104. if (err < 0)
  105. return err;
  106. err = phy_write(phydev, MII_VSC8244_IMASK, 0);
  107. }
  108. return err;
  109. }
  110. static int vsc8221_config_init(struct phy_device *phydev)
  111. {
  112. int err;
  113. err = phy_write(phydev, MII_VSC8244_AUX_CONSTAT,
  114. MII_VSC8221_AUXCONSTAT_INIT);
  115. return err;
  116. /* Perhaps we should set EXT_CON1 based on the interface?
  117. * Options are 802.3Z SerDes or SGMII
  118. */
  119. }
  120. /* Vitesse 824x */
  121. static struct phy_driver vsc82xx_driver[] = {
  122. {
  123. .phy_id = PHY_ID_VSC8244,
  124. .name = "Vitesse VSC8244",
  125. .phy_id_mask = 0x000fffc0,
  126. .features = PHY_GBIT_FEATURES,
  127. .flags = PHY_HAS_INTERRUPT,
  128. .config_init = &vsc824x_config_init,
  129. .config_aneg = &genphy_config_aneg,
  130. .read_status = &genphy_read_status,
  131. .ack_interrupt = &vsc824x_ack_interrupt,
  132. .config_intr = &vsc82xx_config_intr,
  133. .driver = { .owner = THIS_MODULE,},
  134. }, {
  135. /* Vitesse 8221 */
  136. .phy_id = PHY_ID_VSC8221,
  137. .phy_id_mask = 0x000ffff0,
  138. .name = "Vitesse VSC8221",
  139. .features = PHY_GBIT_FEATURES,
  140. .flags = PHY_HAS_INTERRUPT,
  141. .config_init = &vsc8221_config_init,
  142. .config_aneg = &genphy_config_aneg,
  143. .read_status = &genphy_read_status,
  144. .ack_interrupt = &vsc824x_ack_interrupt,
  145. .config_intr = &vsc82xx_config_intr,
  146. .driver = { .owner = THIS_MODULE,},
  147. }, {
  148. /* Vitesse 8211 */
  149. .phy_id = PHY_ID_VSC8211,
  150. .phy_id_mask = 0x000ffff0,
  151. .name = "Vitesse VSC8211",
  152. .features = PHY_GBIT_FEATURES,
  153. .flags = PHY_HAS_INTERRUPT,
  154. .config_init = &vsc8221_config_init,
  155. .config_aneg = &genphy_config_aneg,
  156. .read_status = &genphy_read_status,
  157. .ack_interrupt = &vsc824x_ack_interrupt,
  158. .config_intr = &vsc82xx_config_intr,
  159. .driver = { .owner = THIS_MODULE,},
  160. } };
  161. static int __init vsc82xx_init(void)
  162. {
  163. return phy_drivers_register(vsc82xx_driver,
  164. ARRAY_SIZE(vsc82xx_driver));
  165. }
  166. static void __exit vsc82xx_exit(void)
  167. {
  168. return phy_drivers_unregister(vsc82xx_driver,
  169. ARRAY_SIZE(vsc82xx_driver));
  170. }
  171. module_init(vsc82xx_init);
  172. module_exit(vsc82xx_exit);
  173. static struct mdio_device_id __maybe_unused vitesse_tbl[] = {
  174. { PHY_ID_VSC8244, 0x000fffc0 },
  175. { PHY_ID_VSC8221, 0x000ffff0 },
  176. { PHY_ID_VSC8211, 0x000ffff0 },
  177. { }
  178. };
  179. MODULE_DEVICE_TABLE(mdio, vitesse_tbl);