intel-xway.c 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376
  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 0xD565A409
  147. #define PHY_ID_PHY22F_VR9 0xD565A419
  148. static int xway_gphy_config_init(struct phy_device *phydev)
  149. {
  150. int err;
  151. u32 ledxh;
  152. u32 ledxl;
  153. /* Mask all interrupts */
  154. err = phy_write(phydev, XWAY_MDIO_IMASK, 0);
  155. if (err)
  156. return err;
  157. /* Clear all pending interrupts */
  158. phy_read(phydev, XWAY_MDIO_ISTAT);
  159. phy_write_mmd_indirect(phydev, XWAY_MMD_LEDCH, MDIO_MMD_VEND2,
  160. XWAY_MMD_LEDCH_NACS_NONE |
  161. XWAY_MMD_LEDCH_SBF_F02HZ |
  162. XWAY_MMD_LEDCH_FBF_F16HZ);
  163. phy_write_mmd_indirect(phydev, XWAY_MMD_LEDCL, MDIO_MMD_VEND2,
  164. XWAY_MMD_LEDCH_CBLINK_NONE |
  165. XWAY_MMD_LEDCH_SCAN_NONE);
  166. /**
  167. * In most cases only one LED is connected to this phy, so
  168. * configure them all to constant on and pulse mode. LED3 is
  169. * only available in some packages, leave it in its reset
  170. * configuration.
  171. */
  172. ledxh = XWAY_MMD_LEDxH_BLINKF_NONE | XWAY_MMD_LEDxH_CON_LINK10XX;
  173. ledxl = XWAY_MMD_LEDxL_PULSE_TXACT | XWAY_MMD_LEDxL_PULSE_RXACT |
  174. XWAY_MMD_LEDxL_BLINKS_NONE;
  175. phy_write_mmd_indirect(phydev, XWAY_MMD_LED0H, MDIO_MMD_VEND2, ledxh);
  176. phy_write_mmd_indirect(phydev, XWAY_MMD_LED0L, MDIO_MMD_VEND2, ledxl);
  177. phy_write_mmd_indirect(phydev, XWAY_MMD_LED1H, MDIO_MMD_VEND2, ledxh);
  178. phy_write_mmd_indirect(phydev, XWAY_MMD_LED1L, MDIO_MMD_VEND2, ledxl);
  179. phy_write_mmd_indirect(phydev, XWAY_MMD_LED2H, MDIO_MMD_VEND2, ledxh);
  180. phy_write_mmd_indirect(phydev, XWAY_MMD_LED2L, MDIO_MMD_VEND2, ledxl);
  181. return 0;
  182. }
  183. static int xway_gphy14_config_aneg(struct phy_device *phydev)
  184. {
  185. int reg, err;
  186. /* Advertise as multi-port device, see IEEE802.3-2002 40.5.1.1 */
  187. /* This is a workaround for an errata in rev < 1.5 devices */
  188. reg = phy_read(phydev, MII_CTRL1000);
  189. reg |= ADVERTISED_MPD;
  190. err = phy_write(phydev, MII_CTRL1000, reg);
  191. if (err)
  192. return err;
  193. return genphy_config_aneg(phydev);
  194. }
  195. static int xway_gphy_ack_interrupt(struct phy_device *phydev)
  196. {
  197. int reg;
  198. reg = phy_read(phydev, XWAY_MDIO_ISTAT);
  199. return (reg < 0) ? reg : 0;
  200. }
  201. static int xway_gphy_did_interrupt(struct phy_device *phydev)
  202. {
  203. int reg;
  204. reg = phy_read(phydev, XWAY_MDIO_ISTAT);
  205. return reg & XWAY_MDIO_INIT_MASK;
  206. }
  207. static int xway_gphy_config_intr(struct phy_device *phydev)
  208. {
  209. u16 mask = 0;
  210. if (phydev->interrupts == PHY_INTERRUPT_ENABLED)
  211. mask = XWAY_MDIO_INIT_MASK;
  212. return phy_write(phydev, XWAY_MDIO_IMASK, mask);
  213. }
  214. static struct phy_driver xway_gphy[] = {
  215. {
  216. .phy_id = PHY_ID_PHY11G_1_3,
  217. .phy_id_mask = 0xffffffff,
  218. .name = "Intel XWAY PHY11G (PEF 7071/PEF 7072) v1.3",
  219. .features = (PHY_GBIT_FEATURES | SUPPORTED_Pause |
  220. SUPPORTED_Asym_Pause),
  221. .flags = PHY_HAS_INTERRUPT,
  222. .config_init = xway_gphy_config_init,
  223. .config_aneg = xway_gphy14_config_aneg,
  224. .read_status = genphy_read_status,
  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 | SUPPORTED_Pause |
  235. SUPPORTED_Asym_Pause),
  236. .flags = PHY_HAS_INTERRUPT,
  237. .config_init = xway_gphy_config_init,
  238. .config_aneg = xway_gphy14_config_aneg,
  239. .read_status = genphy_read_status,
  240. .ack_interrupt = xway_gphy_ack_interrupt,
  241. .did_interrupt = xway_gphy_did_interrupt,
  242. .config_intr = xway_gphy_config_intr,
  243. .suspend = genphy_suspend,
  244. .resume = genphy_resume,
  245. }, {
  246. .phy_id = PHY_ID_PHY11G_1_4,
  247. .phy_id_mask = 0xffffffff,
  248. .name = "Intel XWAY PHY11G (PEF 7071/PEF 7072) v1.4",
  249. .features = (PHY_GBIT_FEATURES | SUPPORTED_Pause |
  250. SUPPORTED_Asym_Pause),
  251. .flags = PHY_HAS_INTERRUPT,
  252. .config_init = xway_gphy_config_init,
  253. .config_aneg = xway_gphy14_config_aneg,
  254. .read_status = genphy_read_status,
  255. .ack_interrupt = xway_gphy_ack_interrupt,
  256. .did_interrupt = xway_gphy_did_interrupt,
  257. .config_intr = xway_gphy_config_intr,
  258. .suspend = genphy_suspend,
  259. .resume = genphy_resume,
  260. }, {
  261. .phy_id = PHY_ID_PHY22F_1_4,
  262. .phy_id_mask = 0xffffffff,
  263. .name = "Intel XWAY PHY22F (PEF 7061) v1.4",
  264. .features = (PHY_BASIC_FEATURES | SUPPORTED_Pause |
  265. SUPPORTED_Asym_Pause),
  266. .flags = PHY_HAS_INTERRUPT,
  267. .config_init = xway_gphy_config_init,
  268. .config_aneg = xway_gphy14_config_aneg,
  269. .read_status = genphy_read_status,
  270. .ack_interrupt = xway_gphy_ack_interrupt,
  271. .did_interrupt = xway_gphy_did_interrupt,
  272. .config_intr = xway_gphy_config_intr,
  273. .suspend = genphy_suspend,
  274. .resume = genphy_resume,
  275. }, {
  276. .phy_id = PHY_ID_PHY11G_1_5,
  277. .phy_id_mask = 0xffffffff,
  278. .name = "Intel XWAY PHY11G (PEF 7071/PEF 7072) v1.5 / v1.6",
  279. .features = (PHY_GBIT_FEATURES | SUPPORTED_Pause |
  280. SUPPORTED_Asym_Pause),
  281. .flags = PHY_HAS_INTERRUPT,
  282. .config_init = xway_gphy_config_init,
  283. .config_aneg = genphy_config_aneg,
  284. .read_status = genphy_read_status,
  285. .ack_interrupt = xway_gphy_ack_interrupt,
  286. .did_interrupt = xway_gphy_did_interrupt,
  287. .config_intr = xway_gphy_config_intr,
  288. .suspend = genphy_suspend,
  289. .resume = genphy_resume,
  290. }, {
  291. .phy_id = PHY_ID_PHY22F_1_5,
  292. .phy_id_mask = 0xffffffff,
  293. .name = "Intel XWAY PHY22F (PEF 7061) v1.5 / v1.6",
  294. .features = (PHY_BASIC_FEATURES | SUPPORTED_Pause |
  295. SUPPORTED_Asym_Pause),
  296. .flags = PHY_HAS_INTERRUPT,
  297. .config_init = xway_gphy_config_init,
  298. .config_aneg = genphy_config_aneg,
  299. .read_status = genphy_read_status,
  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_PHY11G_VR9,
  307. .phy_id_mask = 0xffffffff,
  308. .name = "Intel XWAY PHY11G (xRX integrated)",
  309. .features = (PHY_GBIT_FEATURES | SUPPORTED_Pause |
  310. SUPPORTED_Asym_Pause),
  311. .flags = PHY_HAS_INTERRUPT,
  312. .config_init = xway_gphy_config_init,
  313. .config_aneg = genphy_config_aneg,
  314. .read_status = genphy_read_status,
  315. .ack_interrupt = xway_gphy_ack_interrupt,
  316. .did_interrupt = xway_gphy_did_interrupt,
  317. .config_intr = xway_gphy_config_intr,
  318. .suspend = genphy_suspend,
  319. .resume = genphy_resume,
  320. }, {
  321. .phy_id = PHY_ID_PHY22F_VR9,
  322. .phy_id_mask = 0xffffffff,
  323. .name = "Intel XWAY PHY22F (xRX integrated)",
  324. .features = (PHY_BASIC_FEATURES | SUPPORTED_Pause |
  325. SUPPORTED_Asym_Pause),
  326. .flags = PHY_HAS_INTERRUPT,
  327. .config_init = xway_gphy_config_init,
  328. .config_aneg = genphy_config_aneg,
  329. .read_status = genphy_read_status,
  330. .ack_interrupt = xway_gphy_ack_interrupt,
  331. .did_interrupt = xway_gphy_did_interrupt,
  332. .config_intr = xway_gphy_config_intr,
  333. .suspend = genphy_suspend,
  334. .resume = genphy_resume,
  335. },
  336. };
  337. module_phy_driver(xway_gphy);
  338. static struct mdio_device_id __maybe_unused xway_gphy_tbl[] = {
  339. { PHY_ID_PHY11G_1_3, 0xffffffff },
  340. { PHY_ID_PHY22F_1_3, 0xffffffff },
  341. { PHY_ID_PHY11G_1_4, 0xffffffff },
  342. { PHY_ID_PHY22F_1_4, 0xffffffff },
  343. { PHY_ID_PHY11G_1_5, 0xffffffff },
  344. { PHY_ID_PHY22F_1_5, 0xffffffff },
  345. { PHY_ID_PHY11G_VR9, 0xffffffff },
  346. { PHY_ID_PHY22F_VR9, 0xffffffff },
  347. { }
  348. };
  349. MODULE_DEVICE_TABLE(mdio, xway_gphy_tbl);
  350. MODULE_DESCRIPTION("Intel XWAY PHY driver");
  351. MODULE_LICENSE("GPL");