vitesse.c 9.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327
  1. /*
  2. * Driver for Vitesse PHYs
  3. *
  4. * Author: Kriston Carson
  5. *
  6. * Copyright (c) 2005, 2009, 2011 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 Page Magic Register(s) */
  20. #define MII_VSC82X4_EXT_PAGE_16E 0x10
  21. #define MII_VSC82X4_EXT_PAGE_17E 0x11
  22. #define MII_VSC82X4_EXT_PAGE_18E 0x12
  23. /* Vitesse Extended Control Register 1 */
  24. #define MII_VSC8244_EXT_CON1 0x17
  25. #define MII_VSC8244_EXTCON1_INIT 0x0000
  26. #define MII_VSC8244_EXTCON1_TX_SKEW_MASK 0x0c00
  27. #define MII_VSC8244_EXTCON1_RX_SKEW_MASK 0x0300
  28. #define MII_VSC8244_EXTCON1_TX_SKEW 0x0800
  29. #define MII_VSC8244_EXTCON1_RX_SKEW 0x0200
  30. /* Vitesse Interrupt Mask Register */
  31. #define MII_VSC8244_IMASK 0x19
  32. #define MII_VSC8244_IMASK_IEN 0x8000
  33. #define MII_VSC8244_IMASK_SPEED 0x4000
  34. #define MII_VSC8244_IMASK_LINK 0x2000
  35. #define MII_VSC8244_IMASK_DUPLEX 0x1000
  36. #define MII_VSC8244_IMASK_MASK 0xf000
  37. #define MII_VSC8221_IMASK_MASK 0xa000
  38. /* Vitesse Interrupt Status Register */
  39. #define MII_VSC8244_ISTAT 0x1a
  40. #define MII_VSC8244_ISTAT_STATUS 0x8000
  41. #define MII_VSC8244_ISTAT_SPEED 0x4000
  42. #define MII_VSC8244_ISTAT_LINK 0x2000
  43. #define MII_VSC8244_ISTAT_DUPLEX 0x1000
  44. /* Vitesse Auxiliary Control/Status Register */
  45. #define MII_VSC8244_AUX_CONSTAT 0x1c
  46. #define MII_VSC8244_AUXCONSTAT_INIT 0x0000
  47. #define MII_VSC8244_AUXCONSTAT_DUPLEX 0x0020
  48. #define MII_VSC8244_AUXCONSTAT_SPEED 0x0018
  49. #define MII_VSC8244_AUXCONSTAT_GBIT 0x0010
  50. #define MII_VSC8244_AUXCONSTAT_100 0x0008
  51. #define MII_VSC8221_AUXCONSTAT_INIT 0x0004 /* need to set this bit? */
  52. #define MII_VSC8221_AUXCONSTAT_RESERVED 0x0004
  53. /* Vitesse Extended Page Access Register */
  54. #define MII_VSC82X4_EXT_PAGE_ACCESS 0x1f
  55. #define PHY_ID_VSC8234 0x000fc620
  56. #define PHY_ID_VSC8244 0x000fc6c0
  57. #define PHY_ID_VSC8514 0x00070670
  58. #define PHY_ID_VSC8574 0x000704a0
  59. #define PHY_ID_VSC8662 0x00070660
  60. #define PHY_ID_VSC8221 0x000fc550
  61. #define PHY_ID_VSC8211 0x000fc4b0
  62. MODULE_DESCRIPTION("Vitesse PHY driver");
  63. MODULE_AUTHOR("Kriston Carson");
  64. MODULE_LICENSE("GPL");
  65. static int vsc824x_add_skew(struct phy_device *phydev)
  66. {
  67. int err;
  68. int extcon;
  69. extcon = phy_read(phydev, MII_VSC8244_EXT_CON1);
  70. if (extcon < 0)
  71. return extcon;
  72. extcon &= ~(MII_VSC8244_EXTCON1_TX_SKEW_MASK |
  73. MII_VSC8244_EXTCON1_RX_SKEW_MASK);
  74. extcon |= (MII_VSC8244_EXTCON1_TX_SKEW |
  75. MII_VSC8244_EXTCON1_RX_SKEW);
  76. err = phy_write(phydev, MII_VSC8244_EXT_CON1, extcon);
  77. return err;
  78. }
  79. static int vsc824x_config_init(struct phy_device *phydev)
  80. {
  81. int err;
  82. err = phy_write(phydev, MII_VSC8244_AUX_CONSTAT,
  83. MII_VSC8244_AUXCONSTAT_INIT);
  84. if (err < 0)
  85. return err;
  86. if (phydev->interface == PHY_INTERFACE_MODE_RGMII_ID)
  87. err = vsc824x_add_skew(phydev);
  88. return err;
  89. }
  90. static int vsc824x_ack_interrupt(struct phy_device *phydev)
  91. {
  92. int err = 0;
  93. /* Don't bother to ACK the interrupts if interrupts
  94. * are disabled. The 824x cannot clear the interrupts
  95. * if they are disabled.
  96. */
  97. if (phydev->interrupts == PHY_INTERRUPT_ENABLED)
  98. err = phy_read(phydev, MII_VSC8244_ISTAT);
  99. return (err < 0) ? err : 0;
  100. }
  101. static int vsc82xx_config_intr(struct phy_device *phydev)
  102. {
  103. int err;
  104. if (phydev->interrupts == PHY_INTERRUPT_ENABLED)
  105. err = phy_write(phydev, MII_VSC8244_IMASK,
  106. (phydev->drv->phy_id == PHY_ID_VSC8234 ||
  107. phydev->drv->phy_id == PHY_ID_VSC8244 ||
  108. phydev->drv->phy_id == PHY_ID_VSC8514 ||
  109. phydev->drv->phy_id == PHY_ID_VSC8574) ?
  110. MII_VSC8244_IMASK_MASK :
  111. MII_VSC8221_IMASK_MASK);
  112. else {
  113. /* The Vitesse PHY cannot clear the interrupt
  114. * once it has disabled them, so we clear them first
  115. */
  116. err = phy_read(phydev, MII_VSC8244_ISTAT);
  117. if (err < 0)
  118. return err;
  119. err = phy_write(phydev, MII_VSC8244_IMASK, 0);
  120. }
  121. return err;
  122. }
  123. static int vsc8221_config_init(struct phy_device *phydev)
  124. {
  125. int err;
  126. err = phy_write(phydev, MII_VSC8244_AUX_CONSTAT,
  127. MII_VSC8221_AUXCONSTAT_INIT);
  128. return err;
  129. /* Perhaps we should set EXT_CON1 based on the interface?
  130. * Options are 802.3Z SerDes or SGMII
  131. */
  132. }
  133. /* vsc82x4_config_autocross_enable - Enable auto MDI/MDI-X for forced links
  134. * @phydev: target phy_device struct
  135. *
  136. * Enable auto MDI/MDI-X when in 10/100 forced link speeds by writing
  137. * special values in the VSC8234/VSC8244 extended reserved registers
  138. */
  139. static int vsc82x4_config_autocross_enable(struct phy_device *phydev)
  140. {
  141. int ret;
  142. if (phydev->autoneg == AUTONEG_ENABLE || phydev->speed > SPEED_100)
  143. return 0;
  144. /* map extended registers set 0x10 - 0x1e */
  145. ret = phy_write(phydev, MII_VSC82X4_EXT_PAGE_ACCESS, 0x52b5);
  146. if (ret >= 0)
  147. ret = phy_write(phydev, MII_VSC82X4_EXT_PAGE_18E, 0x0012);
  148. if (ret >= 0)
  149. ret = phy_write(phydev, MII_VSC82X4_EXT_PAGE_17E, 0x2803);
  150. if (ret >= 0)
  151. ret = phy_write(phydev, MII_VSC82X4_EXT_PAGE_16E, 0x87fa);
  152. /* map standard registers set 0x10 - 0x1e */
  153. if (ret >= 0)
  154. ret = phy_write(phydev, MII_VSC82X4_EXT_PAGE_ACCESS, 0x0000);
  155. else
  156. phy_write(phydev, MII_VSC82X4_EXT_PAGE_ACCESS, 0x0000);
  157. return ret;
  158. }
  159. /* vsc82x4_config_aneg - restart auto-negotiation or write BMCR
  160. * @phydev: target phy_device struct
  161. *
  162. * Description: If auto-negotiation is enabled, we configure the
  163. * advertising, and then restart auto-negotiation. If it is not
  164. * enabled, then we write the BMCR and also start the auto
  165. * MDI/MDI-X feature
  166. */
  167. static int vsc82x4_config_aneg(struct phy_device *phydev)
  168. {
  169. int ret;
  170. /* Enable auto MDI/MDI-X when in 10/100 forced link speeds by
  171. * writing special values in the VSC8234 extended reserved registers
  172. */
  173. if (phydev->autoneg != AUTONEG_ENABLE && phydev->speed <= SPEED_100) {
  174. ret = genphy_setup_forced(phydev);
  175. if (ret < 0) /* error */
  176. return ret;
  177. return vsc82x4_config_autocross_enable(phydev);
  178. }
  179. return genphy_config_aneg(phydev);
  180. }
  181. /* Vitesse 82xx */
  182. static struct phy_driver vsc82xx_driver[] = {
  183. {
  184. .phy_id = PHY_ID_VSC8234,
  185. .name = "Vitesse VSC8234",
  186. .phy_id_mask = 0x000ffff0,
  187. .features = PHY_GBIT_FEATURES,
  188. .flags = PHY_HAS_INTERRUPT,
  189. .config_init = &vsc824x_config_init,
  190. .config_aneg = &vsc82x4_config_aneg,
  191. .read_status = &genphy_read_status,
  192. .ack_interrupt = &vsc824x_ack_interrupt,
  193. .config_intr = &vsc82xx_config_intr,
  194. .driver = { .owner = THIS_MODULE,},
  195. }, {
  196. .phy_id = PHY_ID_VSC8244,
  197. .name = "Vitesse VSC8244",
  198. .phy_id_mask = 0x000fffc0,
  199. .features = PHY_GBIT_FEATURES,
  200. .flags = PHY_HAS_INTERRUPT,
  201. .config_init = &vsc824x_config_init,
  202. .config_aneg = &vsc82x4_config_aneg,
  203. .read_status = &genphy_read_status,
  204. .ack_interrupt = &vsc824x_ack_interrupt,
  205. .config_intr = &vsc82xx_config_intr,
  206. .driver = { .owner = THIS_MODULE,},
  207. }, {
  208. .phy_id = PHY_ID_VSC8514,
  209. .name = "Vitesse VSC8514",
  210. .phy_id_mask = 0x000ffff0,
  211. .features = PHY_GBIT_FEATURES,
  212. .flags = PHY_HAS_INTERRUPT,
  213. .config_init = &vsc824x_config_init,
  214. .config_aneg = &vsc82x4_config_aneg,
  215. .read_status = &genphy_read_status,
  216. .ack_interrupt = &vsc824x_ack_interrupt,
  217. .config_intr = &vsc82xx_config_intr,
  218. .driver = { .owner = THIS_MODULE,},
  219. }, {
  220. .phy_id = PHY_ID_VSC8574,
  221. .name = "Vitesse VSC8574",
  222. .phy_id_mask = 0x000ffff0,
  223. .features = PHY_GBIT_FEATURES,
  224. .flags = PHY_HAS_INTERRUPT,
  225. .config_init = &vsc824x_config_init,
  226. .config_aneg = &vsc82x4_config_aneg,
  227. .read_status = &genphy_read_status,
  228. .ack_interrupt = &vsc824x_ack_interrupt,
  229. .config_intr = &vsc82xx_config_intr,
  230. .driver = { .owner = THIS_MODULE,},
  231. }, {
  232. .phy_id = PHY_ID_VSC8662,
  233. .name = "Vitesse VSC8662",
  234. .phy_id_mask = 0x000ffff0,
  235. .features = PHY_GBIT_FEATURES,
  236. .flags = PHY_HAS_INTERRUPT,
  237. .config_init = &vsc824x_config_init,
  238. .config_aneg = &vsc82x4_config_aneg,
  239. .read_status = &genphy_read_status,
  240. .ack_interrupt = &vsc824x_ack_interrupt,
  241. .config_intr = &vsc82xx_config_intr,
  242. .driver = { .owner = THIS_MODULE,},
  243. }, {
  244. /* Vitesse 8221 */
  245. .phy_id = PHY_ID_VSC8221,
  246. .phy_id_mask = 0x000ffff0,
  247. .name = "Vitesse VSC8221",
  248. .features = PHY_GBIT_FEATURES,
  249. .flags = PHY_HAS_INTERRUPT,
  250. .config_init = &vsc8221_config_init,
  251. .config_aneg = &genphy_config_aneg,
  252. .read_status = &genphy_read_status,
  253. .ack_interrupt = &vsc824x_ack_interrupt,
  254. .config_intr = &vsc82xx_config_intr,
  255. .driver = { .owner = THIS_MODULE,},
  256. }, {
  257. /* Vitesse 8211 */
  258. .phy_id = PHY_ID_VSC8211,
  259. .phy_id_mask = 0x000ffff0,
  260. .name = "Vitesse VSC8211",
  261. .features = PHY_GBIT_FEATURES,
  262. .flags = PHY_HAS_INTERRUPT,
  263. .config_init = &vsc8221_config_init,
  264. .config_aneg = &genphy_config_aneg,
  265. .read_status = &genphy_read_status,
  266. .ack_interrupt = &vsc824x_ack_interrupt,
  267. .config_intr = &vsc82xx_config_intr,
  268. .driver = { .owner = THIS_MODULE,},
  269. } };
  270. module_phy_driver(vsc82xx_driver);
  271. static struct mdio_device_id __maybe_unused vitesse_tbl[] = {
  272. { PHY_ID_VSC8234, 0x000ffff0 },
  273. { PHY_ID_VSC8244, 0x000fffc0 },
  274. { PHY_ID_VSC8514, 0x000ffff0 },
  275. { PHY_ID_VSC8574, 0x000ffff0 },
  276. { PHY_ID_VSC8662, 0x000ffff0 },
  277. { PHY_ID_VSC8221, 0x000ffff0 },
  278. { PHY_ID_VSC8211, 0x000ffff0 },
  279. { }
  280. };
  281. MODULE_DEVICE_TABLE(mdio, vitesse_tbl);