vitesse.c 9.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341
  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_VSC8601 0x00070420
  60. #define PHY_ID_VSC8662 0x00070660
  61. #define PHY_ID_VSC8221 0x000fc550
  62. #define PHY_ID_VSC8211 0x000fc4b0
  63. MODULE_DESCRIPTION("Vitesse PHY driver");
  64. MODULE_AUTHOR("Kriston Carson");
  65. MODULE_LICENSE("GPL");
  66. static int vsc824x_add_skew(struct phy_device *phydev)
  67. {
  68. int err;
  69. int extcon;
  70. extcon = phy_read(phydev, MII_VSC8244_EXT_CON1);
  71. if (extcon < 0)
  72. return extcon;
  73. extcon &= ~(MII_VSC8244_EXTCON1_TX_SKEW_MASK |
  74. MII_VSC8244_EXTCON1_RX_SKEW_MASK);
  75. extcon |= (MII_VSC8244_EXTCON1_TX_SKEW |
  76. MII_VSC8244_EXTCON1_RX_SKEW);
  77. err = phy_write(phydev, MII_VSC8244_EXT_CON1, extcon);
  78. return err;
  79. }
  80. static int vsc824x_config_init(struct phy_device *phydev)
  81. {
  82. int err;
  83. err = phy_write(phydev, MII_VSC8244_AUX_CONSTAT,
  84. MII_VSC8244_AUXCONSTAT_INIT);
  85. if (err < 0)
  86. return err;
  87. if (phydev->interface == PHY_INTERFACE_MODE_RGMII_ID)
  88. err = vsc824x_add_skew(phydev);
  89. return err;
  90. }
  91. static int vsc824x_ack_interrupt(struct phy_device *phydev)
  92. {
  93. int err = 0;
  94. /* Don't bother to ACK the interrupts if interrupts
  95. * are disabled. The 824x cannot clear the interrupts
  96. * if they are disabled.
  97. */
  98. if (phydev->interrupts == PHY_INTERRUPT_ENABLED)
  99. err = phy_read(phydev, MII_VSC8244_ISTAT);
  100. return (err < 0) ? err : 0;
  101. }
  102. static int vsc82xx_config_intr(struct phy_device *phydev)
  103. {
  104. int err;
  105. if (phydev->interrupts == PHY_INTERRUPT_ENABLED)
  106. err = phy_write(phydev, MII_VSC8244_IMASK,
  107. (phydev->drv->phy_id == PHY_ID_VSC8234 ||
  108. phydev->drv->phy_id == PHY_ID_VSC8244 ||
  109. phydev->drv->phy_id == PHY_ID_VSC8514 ||
  110. phydev->drv->phy_id == PHY_ID_VSC8574 ||
  111. phydev->drv->phy_id == PHY_ID_VSC8601) ?
  112. MII_VSC8244_IMASK_MASK :
  113. MII_VSC8221_IMASK_MASK);
  114. else {
  115. /* The Vitesse PHY cannot clear the interrupt
  116. * once it has disabled them, so we clear them first
  117. */
  118. err = phy_read(phydev, MII_VSC8244_ISTAT);
  119. if (err < 0)
  120. return err;
  121. err = phy_write(phydev, MII_VSC8244_IMASK, 0);
  122. }
  123. return err;
  124. }
  125. static int vsc8221_config_init(struct phy_device *phydev)
  126. {
  127. int err;
  128. err = phy_write(phydev, MII_VSC8244_AUX_CONSTAT,
  129. MII_VSC8221_AUXCONSTAT_INIT);
  130. return err;
  131. /* Perhaps we should set EXT_CON1 based on the interface?
  132. * Options are 802.3Z SerDes or SGMII
  133. */
  134. }
  135. /* vsc82x4_config_autocross_enable - Enable auto MDI/MDI-X for forced links
  136. * @phydev: target phy_device struct
  137. *
  138. * Enable auto MDI/MDI-X when in 10/100 forced link speeds by writing
  139. * special values in the VSC8234/VSC8244 extended reserved registers
  140. */
  141. static int vsc82x4_config_autocross_enable(struct phy_device *phydev)
  142. {
  143. int ret;
  144. if (phydev->autoneg == AUTONEG_ENABLE || phydev->speed > SPEED_100)
  145. return 0;
  146. /* map extended registers set 0x10 - 0x1e */
  147. ret = phy_write(phydev, MII_VSC82X4_EXT_PAGE_ACCESS, 0x52b5);
  148. if (ret >= 0)
  149. ret = phy_write(phydev, MII_VSC82X4_EXT_PAGE_18E, 0x0012);
  150. if (ret >= 0)
  151. ret = phy_write(phydev, MII_VSC82X4_EXT_PAGE_17E, 0x2803);
  152. if (ret >= 0)
  153. ret = phy_write(phydev, MII_VSC82X4_EXT_PAGE_16E, 0x87fa);
  154. /* map standard registers set 0x10 - 0x1e */
  155. if (ret >= 0)
  156. ret = phy_write(phydev, MII_VSC82X4_EXT_PAGE_ACCESS, 0x0000);
  157. else
  158. phy_write(phydev, MII_VSC82X4_EXT_PAGE_ACCESS, 0x0000);
  159. return ret;
  160. }
  161. /* vsc82x4_config_aneg - restart auto-negotiation or write BMCR
  162. * @phydev: target phy_device struct
  163. *
  164. * Description: If auto-negotiation is enabled, we configure the
  165. * advertising, and then restart auto-negotiation. If it is not
  166. * enabled, then we write the BMCR and also start the auto
  167. * MDI/MDI-X feature
  168. */
  169. static int vsc82x4_config_aneg(struct phy_device *phydev)
  170. {
  171. int ret;
  172. /* Enable auto MDI/MDI-X when in 10/100 forced link speeds by
  173. * writing special values in the VSC8234 extended reserved registers
  174. */
  175. if (phydev->autoneg != AUTONEG_ENABLE && phydev->speed <= SPEED_100) {
  176. ret = genphy_setup_forced(phydev);
  177. if (ret < 0) /* error */
  178. return ret;
  179. return vsc82x4_config_autocross_enable(phydev);
  180. }
  181. return genphy_config_aneg(phydev);
  182. }
  183. /* Vitesse 82xx */
  184. static struct phy_driver vsc82xx_driver[] = {
  185. {
  186. .phy_id = PHY_ID_VSC8234,
  187. .name = "Vitesse VSC8234",
  188. .phy_id_mask = 0x000ffff0,
  189. .features = PHY_GBIT_FEATURES,
  190. .flags = PHY_HAS_INTERRUPT,
  191. .config_init = &vsc824x_config_init,
  192. .config_aneg = &vsc82x4_config_aneg,
  193. .read_status = &genphy_read_status,
  194. .ack_interrupt = &vsc824x_ack_interrupt,
  195. .config_intr = &vsc82xx_config_intr,
  196. .driver = { .owner = THIS_MODULE,},
  197. }, {
  198. .phy_id = PHY_ID_VSC8244,
  199. .name = "Vitesse VSC8244",
  200. .phy_id_mask = 0x000fffc0,
  201. .features = PHY_GBIT_FEATURES,
  202. .flags = PHY_HAS_INTERRUPT,
  203. .config_init = &vsc824x_config_init,
  204. .config_aneg = &vsc82x4_config_aneg,
  205. .read_status = &genphy_read_status,
  206. .ack_interrupt = &vsc824x_ack_interrupt,
  207. .config_intr = &vsc82xx_config_intr,
  208. .driver = { .owner = THIS_MODULE,},
  209. }, {
  210. .phy_id = PHY_ID_VSC8514,
  211. .name = "Vitesse VSC8514",
  212. .phy_id_mask = 0x000ffff0,
  213. .features = PHY_GBIT_FEATURES,
  214. .flags = PHY_HAS_INTERRUPT,
  215. .config_init = &vsc824x_config_init,
  216. .config_aneg = &vsc82x4_config_aneg,
  217. .read_status = &genphy_read_status,
  218. .ack_interrupt = &vsc824x_ack_interrupt,
  219. .config_intr = &vsc82xx_config_intr,
  220. .driver = { .owner = THIS_MODULE,},
  221. }, {
  222. .phy_id = PHY_ID_VSC8574,
  223. .name = "Vitesse VSC8574",
  224. .phy_id_mask = 0x000ffff0,
  225. .features = PHY_GBIT_FEATURES,
  226. .flags = PHY_HAS_INTERRUPT,
  227. .config_init = &vsc824x_config_init,
  228. .config_aneg = &vsc82x4_config_aneg,
  229. .read_status = &genphy_read_status,
  230. .ack_interrupt = &vsc824x_ack_interrupt,
  231. .config_intr = &vsc82xx_config_intr,
  232. .driver = { .owner = THIS_MODULE,},
  233. }, {
  234. .phy_id = PHY_ID_VSC8601,
  235. .name = "Vitesse VSC8601",
  236. .phy_id_mask = 0x000ffff0,
  237. .features = PHY_GBIT_FEATURES,
  238. .flags = PHY_HAS_INTERRUPT,
  239. .config_init = &genphy_config_init,
  240. .config_aneg = &genphy_config_aneg,
  241. .read_status = &genphy_read_status,
  242. .ack_interrupt = &vsc824x_ack_interrupt,
  243. .config_intr = &vsc82xx_config_intr,
  244. .driver = { .owner = THIS_MODULE,},
  245. }, {
  246. .phy_id = PHY_ID_VSC8662,
  247. .name = "Vitesse VSC8662",
  248. .phy_id_mask = 0x000ffff0,
  249. .features = PHY_GBIT_FEATURES,
  250. .flags = PHY_HAS_INTERRUPT,
  251. .config_init = &vsc824x_config_init,
  252. .config_aneg = &vsc82x4_config_aneg,
  253. .read_status = &genphy_read_status,
  254. .ack_interrupt = &vsc824x_ack_interrupt,
  255. .config_intr = &vsc82xx_config_intr,
  256. .driver = { .owner = THIS_MODULE,},
  257. }, {
  258. /* Vitesse 8221 */
  259. .phy_id = PHY_ID_VSC8221,
  260. .phy_id_mask = 0x000ffff0,
  261. .name = "Vitesse VSC8221",
  262. .features = PHY_GBIT_FEATURES,
  263. .flags = PHY_HAS_INTERRUPT,
  264. .config_init = &vsc8221_config_init,
  265. .config_aneg = &genphy_config_aneg,
  266. .read_status = &genphy_read_status,
  267. .ack_interrupt = &vsc824x_ack_interrupt,
  268. .config_intr = &vsc82xx_config_intr,
  269. .driver = { .owner = THIS_MODULE,},
  270. }, {
  271. /* Vitesse 8211 */
  272. .phy_id = PHY_ID_VSC8211,
  273. .phy_id_mask = 0x000ffff0,
  274. .name = "Vitesse VSC8211",
  275. .features = PHY_GBIT_FEATURES,
  276. .flags = PHY_HAS_INTERRUPT,
  277. .config_init = &vsc8221_config_init,
  278. .config_aneg = &genphy_config_aneg,
  279. .read_status = &genphy_read_status,
  280. .ack_interrupt = &vsc824x_ack_interrupt,
  281. .config_intr = &vsc82xx_config_intr,
  282. .driver = { .owner = THIS_MODULE,},
  283. } };
  284. module_phy_driver(vsc82xx_driver);
  285. static struct mdio_device_id __maybe_unused vitesse_tbl[] = {
  286. { PHY_ID_VSC8234, 0x000ffff0 },
  287. { PHY_ID_VSC8244, 0x000fffc0 },
  288. { PHY_ID_VSC8514, 0x000ffff0 },
  289. { PHY_ID_VSC8574, 0x000ffff0 },
  290. { PHY_ID_VSC8662, 0x000ffff0 },
  291. { PHY_ID_VSC8221, 0x000ffff0 },
  292. { PHY_ID_VSC8211, 0x000ffff0 },
  293. { }
  294. };
  295. MODULE_DEVICE_TABLE(mdio, vitesse_tbl);