intel-xway.c 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368
  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,
  220. .flags = PHY_HAS_INTERRUPT,
  221. .config_init = xway_gphy_config_init,
  222. .config_aneg = xway_gphy14_config_aneg,
  223. .read_status = genphy_read_status,
  224. .ack_interrupt = xway_gphy_ack_interrupt,
  225. .did_interrupt = xway_gphy_did_interrupt,
  226. .config_intr = xway_gphy_config_intr,
  227. .suspend = genphy_suspend,
  228. .resume = genphy_resume,
  229. }, {
  230. .phy_id = PHY_ID_PHY22F_1_3,
  231. .phy_id_mask = 0xffffffff,
  232. .name = "Intel XWAY PHY22F (PEF 7061) v1.3",
  233. .features = PHY_BASIC_FEATURES,
  234. .flags = PHY_HAS_INTERRUPT,
  235. .config_init = xway_gphy_config_init,
  236. .config_aneg = xway_gphy14_config_aneg,
  237. .read_status = genphy_read_status,
  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. .read_status = genphy_read_status,
  252. .ack_interrupt = xway_gphy_ack_interrupt,
  253. .did_interrupt = xway_gphy_did_interrupt,
  254. .config_intr = xway_gphy_config_intr,
  255. .suspend = genphy_suspend,
  256. .resume = genphy_resume,
  257. }, {
  258. .phy_id = PHY_ID_PHY22F_1_4,
  259. .phy_id_mask = 0xffffffff,
  260. .name = "Intel XWAY PHY22F (PEF 7061) v1.4",
  261. .features = PHY_BASIC_FEATURES,
  262. .flags = PHY_HAS_INTERRUPT,
  263. .config_init = xway_gphy_config_init,
  264. .config_aneg = xway_gphy14_config_aneg,
  265. .read_status = genphy_read_status,
  266. .ack_interrupt = xway_gphy_ack_interrupt,
  267. .did_interrupt = xway_gphy_did_interrupt,
  268. .config_intr = xway_gphy_config_intr,
  269. .suspend = genphy_suspend,
  270. .resume = genphy_resume,
  271. }, {
  272. .phy_id = PHY_ID_PHY11G_1_5,
  273. .phy_id_mask = 0xffffffff,
  274. .name = "Intel XWAY PHY11G (PEF 7071/PEF 7072) v1.5 / v1.6",
  275. .features = PHY_GBIT_FEATURES,
  276. .flags = PHY_HAS_INTERRUPT,
  277. .config_init = xway_gphy_config_init,
  278. .config_aneg = genphy_config_aneg,
  279. .read_status = genphy_read_status,
  280. .ack_interrupt = xway_gphy_ack_interrupt,
  281. .did_interrupt = xway_gphy_did_interrupt,
  282. .config_intr = xway_gphy_config_intr,
  283. .suspend = genphy_suspend,
  284. .resume = genphy_resume,
  285. }, {
  286. .phy_id = PHY_ID_PHY22F_1_5,
  287. .phy_id_mask = 0xffffffff,
  288. .name = "Intel XWAY PHY22F (PEF 7061) v1.5 / v1.6",
  289. .features = PHY_BASIC_FEATURES,
  290. .flags = PHY_HAS_INTERRUPT,
  291. .config_init = xway_gphy_config_init,
  292. .config_aneg = genphy_config_aneg,
  293. .read_status = genphy_read_status,
  294. .ack_interrupt = xway_gphy_ack_interrupt,
  295. .did_interrupt = xway_gphy_did_interrupt,
  296. .config_intr = xway_gphy_config_intr,
  297. .suspend = genphy_suspend,
  298. .resume = genphy_resume,
  299. }, {
  300. .phy_id = PHY_ID_PHY11G_VR9,
  301. .phy_id_mask = 0xffffffff,
  302. .name = "Intel XWAY PHY11G (xRX integrated)",
  303. .features = PHY_GBIT_FEATURES,
  304. .flags = PHY_HAS_INTERRUPT,
  305. .config_init = xway_gphy_config_init,
  306. .config_aneg = genphy_config_aneg,
  307. .read_status = genphy_read_status,
  308. .ack_interrupt = xway_gphy_ack_interrupt,
  309. .did_interrupt = xway_gphy_did_interrupt,
  310. .config_intr = xway_gphy_config_intr,
  311. .suspend = genphy_suspend,
  312. .resume = genphy_resume,
  313. }, {
  314. .phy_id = PHY_ID_PHY22F_VR9,
  315. .phy_id_mask = 0xffffffff,
  316. .name = "Intel XWAY PHY22F (xRX integrated)",
  317. .features = PHY_BASIC_FEATURES,
  318. .flags = PHY_HAS_INTERRUPT,
  319. .config_init = xway_gphy_config_init,
  320. .config_aneg = genphy_config_aneg,
  321. .read_status = genphy_read_status,
  322. .ack_interrupt = xway_gphy_ack_interrupt,
  323. .did_interrupt = xway_gphy_did_interrupt,
  324. .config_intr = xway_gphy_config_intr,
  325. .suspend = genphy_suspend,
  326. .resume = genphy_resume,
  327. },
  328. };
  329. module_phy_driver(xway_gphy);
  330. static struct mdio_device_id __maybe_unused xway_gphy_tbl[] = {
  331. { PHY_ID_PHY11G_1_3, 0xffffffff },
  332. { PHY_ID_PHY22F_1_3, 0xffffffff },
  333. { PHY_ID_PHY11G_1_4, 0xffffffff },
  334. { PHY_ID_PHY22F_1_4, 0xffffffff },
  335. { PHY_ID_PHY11G_1_5, 0xffffffff },
  336. { PHY_ID_PHY22F_1_5, 0xffffffff },
  337. { PHY_ID_PHY11G_VR9, 0xffffffff },
  338. { PHY_ID_PHY22F_VR9, 0xffffffff },
  339. { }
  340. };
  341. MODULE_DEVICE_TABLE(mdio, xway_gphy_tbl);
  342. MODULE_DESCRIPTION("Intel XWAY PHY driver");
  343. MODULE_LICENSE("GPL");