vitesse.c 9.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342
  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_VSC8641 0x00070431
  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. MII_VSC8244_IMASK_MASK :
  112. MII_VSC8221_IMASK_MASK);
  113. else {
  114. /* The Vitesse PHY cannot clear the interrupt
  115. * once it has disabled them, so we clear them first
  116. */
  117. err = phy_read(phydev, MII_VSC8244_ISTAT);
  118. if (err < 0)
  119. return err;
  120. err = phy_write(phydev, MII_VSC8244_IMASK, 0);
  121. }
  122. return err;
  123. }
  124. static int vsc8221_config_init(struct phy_device *phydev)
  125. {
  126. int err;
  127. err = phy_write(phydev, MII_VSC8244_AUX_CONSTAT,
  128. MII_VSC8221_AUXCONSTAT_INIT);
  129. return err;
  130. /* Perhaps we should set EXT_CON1 based on the interface?
  131. * Options are 802.3Z SerDes or SGMII
  132. */
  133. }
  134. /* vsc82x4_config_autocross_enable - Enable auto MDI/MDI-X for forced links
  135. * @phydev: target phy_device struct
  136. *
  137. * Enable auto MDI/MDI-X when in 10/100 forced link speeds by writing
  138. * special values in the VSC8234/VSC8244 extended reserved registers
  139. */
  140. static int vsc82x4_config_autocross_enable(struct phy_device *phydev)
  141. {
  142. int ret;
  143. if (phydev->autoneg == AUTONEG_ENABLE || phydev->speed > SPEED_100)
  144. return 0;
  145. /* map extended registers set 0x10 - 0x1e */
  146. ret = phy_write(phydev, MII_VSC82X4_EXT_PAGE_ACCESS, 0x52b5);
  147. if (ret >= 0)
  148. ret = phy_write(phydev, MII_VSC82X4_EXT_PAGE_18E, 0x0012);
  149. if (ret >= 0)
  150. ret = phy_write(phydev, MII_VSC82X4_EXT_PAGE_17E, 0x2803);
  151. if (ret >= 0)
  152. ret = phy_write(phydev, MII_VSC82X4_EXT_PAGE_16E, 0x87fa);
  153. /* map standard registers set 0x10 - 0x1e */
  154. if (ret >= 0)
  155. ret = phy_write(phydev, MII_VSC82X4_EXT_PAGE_ACCESS, 0x0000);
  156. else
  157. phy_write(phydev, MII_VSC82X4_EXT_PAGE_ACCESS, 0x0000);
  158. return ret;
  159. }
  160. /* vsc82x4_config_aneg - restart auto-negotiation or write BMCR
  161. * @phydev: target phy_device struct
  162. *
  163. * Description: If auto-negotiation is enabled, we configure the
  164. * advertising, and then restart auto-negotiation. If it is not
  165. * enabled, then we write the BMCR and also start the auto
  166. * MDI/MDI-X feature
  167. */
  168. static int vsc82x4_config_aneg(struct phy_device *phydev)
  169. {
  170. int ret;
  171. /* Enable auto MDI/MDI-X when in 10/100 forced link speeds by
  172. * writing special values in the VSC8234 extended reserved registers
  173. */
  174. if (phydev->autoneg != AUTONEG_ENABLE && phydev->speed <= SPEED_100) {
  175. ret = genphy_setup_forced(phydev);
  176. if (ret < 0) /* error */
  177. return ret;
  178. return vsc82x4_config_autocross_enable(phydev);
  179. }
  180. return genphy_config_aneg(phydev);
  181. }
  182. /* Vitesse 82xx */
  183. static struct phy_driver vsc82xx_driver[] = {
  184. {
  185. .phy_id = PHY_ID_VSC8234,
  186. .name = "Vitesse VSC8234",
  187. .phy_id_mask = 0x000ffff0,
  188. .features = PHY_GBIT_FEATURES,
  189. .flags = PHY_HAS_INTERRUPT,
  190. .config_init = &vsc824x_config_init,
  191. .config_aneg = &vsc82x4_config_aneg,
  192. .read_status = &genphy_read_status,
  193. .ack_interrupt = &vsc824x_ack_interrupt,
  194. .config_intr = &vsc82xx_config_intr,
  195. .driver = { .owner = THIS_MODULE,},
  196. }, {
  197. .phy_id = PHY_ID_VSC8244,
  198. .name = "Vitesse VSC8244",
  199. .phy_id_mask = 0x000fffc0,
  200. .features = PHY_GBIT_FEATURES,
  201. .flags = PHY_HAS_INTERRUPT,
  202. .config_init = &vsc824x_config_init,
  203. .config_aneg = &vsc82x4_config_aneg,
  204. .read_status = &genphy_read_status,
  205. .ack_interrupt = &vsc824x_ack_interrupt,
  206. .config_intr = &vsc82xx_config_intr,
  207. .driver = { .owner = THIS_MODULE,},
  208. }, {
  209. .phy_id = PHY_ID_VSC8514,
  210. .name = "Vitesse VSC8514",
  211. .phy_id_mask = 0x000ffff0,
  212. .features = PHY_GBIT_FEATURES,
  213. .flags = PHY_HAS_INTERRUPT,
  214. .config_init = &vsc824x_config_init,
  215. .config_aneg = &vsc82x4_config_aneg,
  216. .read_status = &genphy_read_status,
  217. .ack_interrupt = &vsc824x_ack_interrupt,
  218. .config_intr = &vsc82xx_config_intr,
  219. .driver = { .owner = THIS_MODULE,},
  220. }, {
  221. .phy_id = PHY_ID_VSC8574,
  222. .name = "Vitesse VSC8574",
  223. .phy_id_mask = 0x000ffff0,
  224. .features = PHY_GBIT_FEATURES,
  225. .flags = PHY_HAS_INTERRUPT,
  226. .config_init = &vsc824x_config_init,
  227. .config_aneg = &vsc82x4_config_aneg,
  228. .read_status = &genphy_read_status,
  229. .ack_interrupt = &vsc824x_ack_interrupt,
  230. .config_intr = &vsc82xx_config_intr,
  231. .driver = { .owner = THIS_MODULE,},
  232. }, {
  233. .phy_id = PHY_ID_VSC8641,
  234. .name = "Vitesse VSC8641",
  235. .phy_id_mask = 0x000ffff0,
  236. .features = PHY_GBIT_FEATURES,
  237. .flags = PHY_HAS_INTERRUPT,
  238. .config_init = &vsc824x_config_init,
  239. .config_aneg = &vsc82x4_config_aneg,
  240. .read_status = &genphy_read_status,
  241. .ack_interrupt = &vsc824x_ack_interrupt,
  242. .config_intr = &vsc82xx_config_intr,
  243. .driver = { .owner = THIS_MODULE,},
  244. }, {
  245. .phy_id = PHY_ID_VSC8662,
  246. .name = "Vitesse VSC8662",
  247. .phy_id_mask = 0x000ffff0,
  248. .features = PHY_GBIT_FEATURES,
  249. .flags = PHY_HAS_INTERRUPT,
  250. .config_init = &vsc824x_config_init,
  251. .config_aneg = &vsc82x4_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 8221 */
  258. .phy_id = PHY_ID_VSC8221,
  259. .phy_id_mask = 0x000ffff0,
  260. .name = "Vitesse VSC8221",
  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. /* Vitesse 8211 */
  271. .phy_id = PHY_ID_VSC8211,
  272. .phy_id_mask = 0x000ffff0,
  273. .name = "Vitesse VSC8211",
  274. .features = PHY_GBIT_FEATURES,
  275. .flags = PHY_HAS_INTERRUPT,
  276. .config_init = &vsc8221_config_init,
  277. .config_aneg = &genphy_config_aneg,
  278. .read_status = &genphy_read_status,
  279. .ack_interrupt = &vsc824x_ack_interrupt,
  280. .config_intr = &vsc82xx_config_intr,
  281. .driver = { .owner = THIS_MODULE,},
  282. } };
  283. module_phy_driver(vsc82xx_driver);
  284. static struct mdio_device_id __maybe_unused vitesse_tbl[] = {
  285. { PHY_ID_VSC8234, 0x000ffff0 },
  286. { PHY_ID_VSC8244, 0x000fffc0 },
  287. { PHY_ID_VSC8514, 0x000ffff0 },
  288. { PHY_ID_VSC8574, 0x000ffff0 },
  289. { PHY_ID_VSC8641, 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);