intel-xway.c 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384
  1. /*
  2. * Copyright (C) 2012 Daniel Schwierzeck <daniel.schwierzeck@googlemail.com>
  3. * Copyright (C) 2016 Hauke Mehrtens <hauke@hauke-m.de>
  4. *
  5. * This program is free software; you can redistribute it and/or modify
  6. * it under the terms of the GNU General Public License as published by
  7. * the Free Software Foundation; either version 2 of the License, or
  8. * (at your option) any later version.
  9. *
  10. * This program is distributed in the hope that it will be useful,
  11. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. * GNU General Public License for more details.
  14. */
  15. #include <linux/mdio.h>
  16. #include <linux/module.h>
  17. #include <linux/phy.h>
  18. #include <linux/of.h>
  19. #define XWAY_MDIO_IMASK 0x19 /* interrupt mask */
  20. #define XWAY_MDIO_ISTAT 0x1A /* interrupt status */
  21. #define XWAY_MDIO_INIT_WOL BIT(15) /* Wake-On-LAN */
  22. #define XWAY_MDIO_INIT_MSRE BIT(14)
  23. #define XWAY_MDIO_INIT_NPRX BIT(13)
  24. #define XWAY_MDIO_INIT_NPTX BIT(12)
  25. #define XWAY_MDIO_INIT_ANE BIT(11) /* Auto-Neg error */
  26. #define XWAY_MDIO_INIT_ANC BIT(10) /* Auto-Neg complete */
  27. #define XWAY_MDIO_INIT_ADSC BIT(5) /* Link auto-downspeed detect */
  28. #define XWAY_MDIO_INIT_MPIPC BIT(4)
  29. #define XWAY_MDIO_INIT_MDIXC BIT(3)
  30. #define XWAY_MDIO_INIT_DXMC BIT(2) /* Duplex mode change */
  31. #define XWAY_MDIO_INIT_LSPC BIT(1) /* Link speed change */
  32. #define XWAY_MDIO_INIT_LSTC BIT(0) /* Link state change */
  33. #define XWAY_MDIO_INIT_MASK (XWAY_MDIO_INIT_LSTC | \
  34. XWAY_MDIO_INIT_ADSC)
  35. #define ADVERTISED_MPD BIT(10) /* Multi-port device */
  36. /* LED Configuration */
  37. #define XWAY_MMD_LEDCH 0x01E0
  38. /* Inverse of SCAN Function */
  39. #define XWAY_MMD_LEDCH_NACS_NONE 0x0000
  40. #define XWAY_MMD_LEDCH_NACS_LINK 0x0001
  41. #define XWAY_MMD_LEDCH_NACS_PDOWN 0x0002
  42. #define XWAY_MMD_LEDCH_NACS_EEE 0x0003
  43. #define XWAY_MMD_LEDCH_NACS_ANEG 0x0004
  44. #define XWAY_MMD_LEDCH_NACS_ABIST 0x0005
  45. #define XWAY_MMD_LEDCH_NACS_CDIAG 0x0006
  46. #define XWAY_MMD_LEDCH_NACS_TEST 0x0007
  47. /* Slow Blink Frequency */
  48. #define XWAY_MMD_LEDCH_SBF_F02HZ 0x0000
  49. #define XWAY_MMD_LEDCH_SBF_F04HZ 0x0010
  50. #define XWAY_MMD_LEDCH_SBF_F08HZ 0x0020
  51. #define XWAY_MMD_LEDCH_SBF_F16HZ 0x0030
  52. /* Fast Blink Frequency */
  53. #define XWAY_MMD_LEDCH_FBF_F02HZ 0x0000
  54. #define XWAY_MMD_LEDCH_FBF_F04HZ 0x0040
  55. #define XWAY_MMD_LEDCH_FBF_F08HZ 0x0080
  56. #define XWAY_MMD_LEDCH_FBF_F16HZ 0x00C0
  57. /* LED Configuration */
  58. #define XWAY_MMD_LEDCL 0x01E1
  59. /* Complex Blinking Configuration */
  60. #define XWAY_MMD_LEDCH_CBLINK_NONE 0x0000
  61. #define XWAY_MMD_LEDCH_CBLINK_LINK 0x0001
  62. #define XWAY_MMD_LEDCH_CBLINK_PDOWN 0x0002
  63. #define XWAY_MMD_LEDCH_CBLINK_EEE 0x0003
  64. #define XWAY_MMD_LEDCH_CBLINK_ANEG 0x0004
  65. #define XWAY_MMD_LEDCH_CBLINK_ABIST 0x0005
  66. #define XWAY_MMD_LEDCH_CBLINK_CDIAG 0x0006
  67. #define XWAY_MMD_LEDCH_CBLINK_TEST 0x0007
  68. /* Complex SCAN Configuration */
  69. #define XWAY_MMD_LEDCH_SCAN_NONE 0x0000
  70. #define XWAY_MMD_LEDCH_SCAN_LINK 0x0010
  71. #define XWAY_MMD_LEDCH_SCAN_PDOWN 0x0020
  72. #define XWAY_MMD_LEDCH_SCAN_EEE 0x0030
  73. #define XWAY_MMD_LEDCH_SCAN_ANEG 0x0040
  74. #define XWAY_MMD_LEDCH_SCAN_ABIST 0x0050
  75. #define XWAY_MMD_LEDCH_SCAN_CDIAG 0x0060
  76. #define XWAY_MMD_LEDCH_SCAN_TEST 0x0070
  77. /* Configuration for LED Pin x */
  78. #define XWAY_MMD_LED0H 0x01E2
  79. /* Fast Blinking Configuration */
  80. #define XWAY_MMD_LEDxH_BLINKF_MASK 0x000F
  81. #define XWAY_MMD_LEDxH_BLINKF_NONE 0x0000
  82. #define XWAY_MMD_LEDxH_BLINKF_LINK10 0x0001
  83. #define XWAY_MMD_LEDxH_BLINKF_LINK100 0x0002
  84. #define XWAY_MMD_LEDxH_BLINKF_LINK10X 0x0003
  85. #define XWAY_MMD_LEDxH_BLINKF_LINK1000 0x0004
  86. #define XWAY_MMD_LEDxH_BLINKF_LINK10_0 0x0005
  87. #define XWAY_MMD_LEDxH_BLINKF_LINK100X 0x0006
  88. #define XWAY_MMD_LEDxH_BLINKF_LINK10XX 0x0007
  89. #define XWAY_MMD_LEDxH_BLINKF_PDOWN 0x0008
  90. #define XWAY_MMD_LEDxH_BLINKF_EEE 0x0009
  91. #define XWAY_MMD_LEDxH_BLINKF_ANEG 0x000A
  92. #define XWAY_MMD_LEDxH_BLINKF_ABIST 0x000B
  93. #define XWAY_MMD_LEDxH_BLINKF_CDIAG 0x000C
  94. /* Constant On Configuration */
  95. #define XWAY_MMD_LEDxH_CON_MASK 0x00F0
  96. #define XWAY_MMD_LEDxH_CON_NONE 0x0000
  97. #define XWAY_MMD_LEDxH_CON_LINK10 0x0010
  98. #define XWAY_MMD_LEDxH_CON_LINK100 0x0020
  99. #define XWAY_MMD_LEDxH_CON_LINK10X 0x0030
  100. #define XWAY_MMD_LEDxH_CON_LINK1000 0x0040
  101. #define XWAY_MMD_LEDxH_CON_LINK10_0 0x0050
  102. #define XWAY_MMD_LEDxH_CON_LINK100X 0x0060
  103. #define XWAY_MMD_LEDxH_CON_LINK10XX 0x0070
  104. #define XWAY_MMD_LEDxH_CON_PDOWN 0x0080
  105. #define XWAY_MMD_LEDxH_CON_EEE 0x0090
  106. #define XWAY_MMD_LEDxH_CON_ANEG 0x00A0
  107. #define XWAY_MMD_LEDxH_CON_ABIST 0x00B0
  108. #define XWAY_MMD_LEDxH_CON_CDIAG 0x00C0
  109. #define XWAY_MMD_LEDxH_CON_COPPER 0x00D0
  110. #define XWAY_MMD_LEDxH_CON_FIBER 0x00E0
  111. /* Configuration for LED Pin x */
  112. #define XWAY_MMD_LED0L 0x01E3
  113. /* Pulsing Configuration */
  114. #define XWAY_MMD_LEDxL_PULSE_MASK 0x000F
  115. #define XWAY_MMD_LEDxL_PULSE_NONE 0x0000
  116. #define XWAY_MMD_LEDxL_PULSE_TXACT 0x0001
  117. #define XWAY_MMD_LEDxL_PULSE_RXACT 0x0002
  118. #define XWAY_MMD_LEDxL_PULSE_COL 0x0004
  119. /* Slow Blinking Configuration */
  120. #define XWAY_MMD_LEDxL_BLINKS_MASK 0x00F0
  121. #define XWAY_MMD_LEDxL_BLINKS_NONE 0x0000
  122. #define XWAY_MMD_LEDxL_BLINKS_LINK10 0x0010
  123. #define XWAY_MMD_LEDxL_BLINKS_LINK100 0x0020
  124. #define XWAY_MMD_LEDxL_BLINKS_LINK10X 0x0030
  125. #define XWAY_MMD_LEDxL_BLINKS_LINK1000 0x0040
  126. #define XWAY_MMD_LEDxL_BLINKS_LINK10_0 0x0050
  127. #define XWAY_MMD_LEDxL_BLINKS_LINK100X 0x0060
  128. #define XWAY_MMD_LEDxL_BLINKS_LINK10XX 0x0070
  129. #define XWAY_MMD_LEDxL_BLINKS_PDOWN 0x0080
  130. #define XWAY_MMD_LEDxL_BLINKS_EEE 0x0090
  131. #define XWAY_MMD_LEDxL_BLINKS_ANEG 0x00A0
  132. #define XWAY_MMD_LEDxL_BLINKS_ABIST 0x00B0
  133. #define XWAY_MMD_LEDxL_BLINKS_CDIAG 0x00C0
  134. #define XWAY_MMD_LED1H 0x01E4
  135. #define XWAY_MMD_LED1L 0x01E5
  136. #define XWAY_MMD_LED2H 0x01E6
  137. #define XWAY_MMD_LED2L 0x01E7
  138. #define XWAY_MMD_LED3H 0x01E8
  139. #define XWAY_MMD_LED3L 0x01E9
  140. #define PHY_ID_PHY11G_1_3 0x030260D1
  141. #define PHY_ID_PHY22F_1_3 0x030260E1
  142. #define PHY_ID_PHY11G_1_4 0xD565A400
  143. #define PHY_ID_PHY22F_1_4 0xD565A410
  144. #define PHY_ID_PHY11G_1_5 0xD565A401
  145. #define PHY_ID_PHY22F_1_5 0xD565A411
  146. #define PHY_ID_PHY11G_VR9_1_1 0xD565A408
  147. #define PHY_ID_PHY22F_VR9_1_1 0xD565A418
  148. #define PHY_ID_PHY11G_VR9_1_2 0xD565A409
  149. #define PHY_ID_PHY22F_VR9_1_2 0xD565A419
  150. static int xway_gphy_config_init(struct phy_device *phydev)
  151. {
  152. int err;
  153. u32 ledxh;
  154. u32 ledxl;
  155. /* Mask all interrupts */
  156. err = phy_write(phydev, XWAY_MDIO_IMASK, 0);
  157. if (err)
  158. return err;
  159. /* Clear all pending interrupts */
  160. phy_read(phydev, XWAY_MDIO_ISTAT);
  161. phy_write_mmd(phydev, MDIO_MMD_VEND2, XWAY_MMD_LEDCH,
  162. XWAY_MMD_LEDCH_NACS_NONE |
  163. XWAY_MMD_LEDCH_SBF_F02HZ |
  164. XWAY_MMD_LEDCH_FBF_F16HZ);
  165. phy_write_mmd(phydev, MDIO_MMD_VEND2, XWAY_MMD_LEDCL,
  166. XWAY_MMD_LEDCH_CBLINK_NONE |
  167. XWAY_MMD_LEDCH_SCAN_NONE);
  168. /**
  169. * In most cases only one LED is connected to this phy, so
  170. * configure them all to constant on and pulse mode. LED3 is
  171. * only available in some packages, leave it in its reset
  172. * configuration.
  173. */
  174. ledxh = XWAY_MMD_LEDxH_BLINKF_NONE | XWAY_MMD_LEDxH_CON_LINK10XX;
  175. ledxl = XWAY_MMD_LEDxL_PULSE_TXACT | XWAY_MMD_LEDxL_PULSE_RXACT |
  176. XWAY_MMD_LEDxL_BLINKS_NONE;
  177. phy_write_mmd(phydev, MDIO_MMD_VEND2, XWAY_MMD_LED0H, ledxh);
  178. phy_write_mmd(phydev, MDIO_MMD_VEND2, XWAY_MMD_LED0L, ledxl);
  179. phy_write_mmd(phydev, MDIO_MMD_VEND2, XWAY_MMD_LED1H, ledxh);
  180. phy_write_mmd(phydev, MDIO_MMD_VEND2, XWAY_MMD_LED1L, ledxl);
  181. phy_write_mmd(phydev, MDIO_MMD_VEND2, XWAY_MMD_LED2H, ledxh);
  182. phy_write_mmd(phydev, MDIO_MMD_VEND2, XWAY_MMD_LED2L, ledxl);
  183. return 0;
  184. }
  185. static int xway_gphy14_config_aneg(struct phy_device *phydev)
  186. {
  187. int reg, err;
  188. /* Advertise as multi-port device, see IEEE802.3-2002 40.5.1.1 */
  189. /* This is a workaround for an errata in rev < 1.5 devices */
  190. reg = phy_read(phydev, MII_CTRL1000);
  191. reg |= ADVERTISED_MPD;
  192. err = phy_write(phydev, MII_CTRL1000, reg);
  193. if (err)
  194. return err;
  195. return genphy_config_aneg(phydev);
  196. }
  197. static int xway_gphy_ack_interrupt(struct phy_device *phydev)
  198. {
  199. int reg;
  200. reg = phy_read(phydev, XWAY_MDIO_ISTAT);
  201. return (reg < 0) ? reg : 0;
  202. }
  203. static int xway_gphy_did_interrupt(struct phy_device *phydev)
  204. {
  205. int reg;
  206. reg = phy_read(phydev, XWAY_MDIO_ISTAT);
  207. return reg & XWAY_MDIO_INIT_MASK;
  208. }
  209. static int xway_gphy_config_intr(struct phy_device *phydev)
  210. {
  211. u16 mask = 0;
  212. if (phydev->interrupts == PHY_INTERRUPT_ENABLED)
  213. mask = XWAY_MDIO_INIT_MASK;
  214. return phy_write(phydev, XWAY_MDIO_IMASK, mask);
  215. }
  216. static struct phy_driver xway_gphy[] = {
  217. {
  218. .phy_id = PHY_ID_PHY11G_1_3,
  219. .phy_id_mask = 0xffffffff,
  220. .name = "Intel XWAY PHY11G (PEF 7071/PEF 7072) v1.3",
  221. .features = PHY_GBIT_FEATURES,
  222. .flags = PHY_HAS_INTERRUPT,
  223. .config_init = xway_gphy_config_init,
  224. .config_aneg = xway_gphy14_config_aneg,
  225. .ack_interrupt = xway_gphy_ack_interrupt,
  226. .did_interrupt = xway_gphy_did_interrupt,
  227. .config_intr = xway_gphy_config_intr,
  228. .suspend = genphy_suspend,
  229. .resume = genphy_resume,
  230. }, {
  231. .phy_id = PHY_ID_PHY22F_1_3,
  232. .phy_id_mask = 0xffffffff,
  233. .name = "Intel XWAY PHY22F (PEF 7061) v1.3",
  234. .features = PHY_BASIC_FEATURES,
  235. .flags = PHY_HAS_INTERRUPT,
  236. .config_init = xway_gphy_config_init,
  237. .config_aneg = xway_gphy14_config_aneg,
  238. .ack_interrupt = xway_gphy_ack_interrupt,
  239. .did_interrupt = xway_gphy_did_interrupt,
  240. .config_intr = xway_gphy_config_intr,
  241. .suspend = genphy_suspend,
  242. .resume = genphy_resume,
  243. }, {
  244. .phy_id = PHY_ID_PHY11G_1_4,
  245. .phy_id_mask = 0xffffffff,
  246. .name = "Intel XWAY PHY11G (PEF 7071/PEF 7072) v1.4",
  247. .features = PHY_GBIT_FEATURES,
  248. .flags = PHY_HAS_INTERRUPT,
  249. .config_init = xway_gphy_config_init,
  250. .config_aneg = xway_gphy14_config_aneg,
  251. .ack_interrupt = xway_gphy_ack_interrupt,
  252. .did_interrupt = xway_gphy_did_interrupt,
  253. .config_intr = xway_gphy_config_intr,
  254. .suspend = genphy_suspend,
  255. .resume = genphy_resume,
  256. }, {
  257. .phy_id = PHY_ID_PHY22F_1_4,
  258. .phy_id_mask = 0xffffffff,
  259. .name = "Intel XWAY PHY22F (PEF 7061) v1.4",
  260. .features = PHY_BASIC_FEATURES,
  261. .flags = PHY_HAS_INTERRUPT,
  262. .config_init = xway_gphy_config_init,
  263. .config_aneg = xway_gphy14_config_aneg,
  264. .ack_interrupt = xway_gphy_ack_interrupt,
  265. .did_interrupt = xway_gphy_did_interrupt,
  266. .config_intr = xway_gphy_config_intr,
  267. .suspend = genphy_suspend,
  268. .resume = genphy_resume,
  269. }, {
  270. .phy_id = PHY_ID_PHY11G_1_5,
  271. .phy_id_mask = 0xffffffff,
  272. .name = "Intel XWAY PHY11G (PEF 7071/PEF 7072) v1.5 / v1.6",
  273. .features = PHY_GBIT_FEATURES,
  274. .flags = PHY_HAS_INTERRUPT,
  275. .config_init = xway_gphy_config_init,
  276. .ack_interrupt = xway_gphy_ack_interrupt,
  277. .did_interrupt = xway_gphy_did_interrupt,
  278. .config_intr = xway_gphy_config_intr,
  279. .suspend = genphy_suspend,
  280. .resume = genphy_resume,
  281. }, {
  282. .phy_id = PHY_ID_PHY22F_1_5,
  283. .phy_id_mask = 0xffffffff,
  284. .name = "Intel XWAY PHY22F (PEF 7061) v1.5 / v1.6",
  285. .features = PHY_BASIC_FEATURES,
  286. .flags = PHY_HAS_INTERRUPT,
  287. .config_init = xway_gphy_config_init,
  288. .ack_interrupt = xway_gphy_ack_interrupt,
  289. .did_interrupt = xway_gphy_did_interrupt,
  290. .config_intr = xway_gphy_config_intr,
  291. .suspend = genphy_suspend,
  292. .resume = genphy_resume,
  293. }, {
  294. .phy_id = PHY_ID_PHY11G_VR9_1_1,
  295. .phy_id_mask = 0xffffffff,
  296. .name = "Intel XWAY PHY11G (xRX v1.1 integrated)",
  297. .features = PHY_GBIT_FEATURES,
  298. .flags = PHY_HAS_INTERRUPT,
  299. .config_init = xway_gphy_config_init,
  300. .ack_interrupt = xway_gphy_ack_interrupt,
  301. .did_interrupt = xway_gphy_did_interrupt,
  302. .config_intr = xway_gphy_config_intr,
  303. .suspend = genphy_suspend,
  304. .resume = genphy_resume,
  305. }, {
  306. .phy_id = PHY_ID_PHY22F_VR9_1_1,
  307. .phy_id_mask = 0xffffffff,
  308. .name = "Intel XWAY PHY22F (xRX v1.1 integrated)",
  309. .features = PHY_BASIC_FEATURES,
  310. .flags = PHY_HAS_INTERRUPT,
  311. .config_init = xway_gphy_config_init,
  312. .ack_interrupt = xway_gphy_ack_interrupt,
  313. .did_interrupt = xway_gphy_did_interrupt,
  314. .config_intr = xway_gphy_config_intr,
  315. .suspend = genphy_suspend,
  316. .resume = genphy_resume,
  317. }, {
  318. .phy_id = PHY_ID_PHY11G_VR9_1_2,
  319. .phy_id_mask = 0xffffffff,
  320. .name = "Intel XWAY PHY11G (xRX v1.2 integrated)",
  321. .features = PHY_GBIT_FEATURES,
  322. .flags = PHY_HAS_INTERRUPT,
  323. .config_init = xway_gphy_config_init,
  324. .ack_interrupt = xway_gphy_ack_interrupt,
  325. .did_interrupt = xway_gphy_did_interrupt,
  326. .config_intr = xway_gphy_config_intr,
  327. .suspend = genphy_suspend,
  328. .resume = genphy_resume,
  329. }, {
  330. .phy_id = PHY_ID_PHY22F_VR9_1_2,
  331. .phy_id_mask = 0xffffffff,
  332. .name = "Intel XWAY PHY22F (xRX v1.2 integrated)",
  333. .features = PHY_BASIC_FEATURES,
  334. .flags = PHY_HAS_INTERRUPT,
  335. .config_init = xway_gphy_config_init,
  336. .ack_interrupt = xway_gphy_ack_interrupt,
  337. .did_interrupt = xway_gphy_did_interrupt,
  338. .config_intr = xway_gphy_config_intr,
  339. .suspend = genphy_suspend,
  340. .resume = genphy_resume,
  341. },
  342. };
  343. module_phy_driver(xway_gphy);
  344. static struct mdio_device_id __maybe_unused xway_gphy_tbl[] = {
  345. { PHY_ID_PHY11G_1_3, 0xffffffff },
  346. { PHY_ID_PHY22F_1_3, 0xffffffff },
  347. { PHY_ID_PHY11G_1_4, 0xffffffff },
  348. { PHY_ID_PHY22F_1_4, 0xffffffff },
  349. { PHY_ID_PHY11G_1_5, 0xffffffff },
  350. { PHY_ID_PHY22F_1_5, 0xffffffff },
  351. { PHY_ID_PHY11G_VR9_1_1, 0xffffffff },
  352. { PHY_ID_PHY22F_VR9_1_1, 0xffffffff },
  353. { PHY_ID_PHY11G_VR9_1_2, 0xffffffff },
  354. { PHY_ID_PHY22F_VR9_1_2, 0xffffffff },
  355. { }
  356. };
  357. MODULE_DEVICE_TABLE(mdio, xway_gphy_tbl);
  358. MODULE_DESCRIPTION("Intel XWAY PHY driver");
  359. MODULE_LICENSE("GPL");