0023-NET-PHY-adds-driver-for-lantiq-PHY11G.patch 8.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271
  1. From 0a63ab263725c427051a8bbaa0732b749627da27 Mon Sep 17 00:00:00 2001
  2. From: John Crispin <blogic@openwrt.org>
  3. Date: Thu, 7 Aug 2014 18:15:36 +0200
  4. Subject: [PATCH 23/36] NET: PHY: adds driver for lantiq PHY11G
  5. Signed-off-by: John Crispin <blogic@openwrt.org>
  6. ---
  7. drivers/net/phy/Kconfig | 5 +
  8. drivers/net/phy/Makefile | 1 +
  9. drivers/net/phy/lantiq.c | 231 ++++++++++++++++++++++++++++++++++++++++++++++
  10. 3 files changed, 237 insertions(+)
  11. create mode 100644 drivers/net/phy/lantiq.c
  12. --- a/drivers/net/phy/Kconfig
  13. +++ b/drivers/net/phy/Kconfig
  14. @@ -164,6 +164,11 @@ config RTL8306_PHY
  15. tristate "Driver for Realtek RTL8306S switches"
  16. select SWCONFIG
  17. +config LANTIQ_PHY
  18. + tristate "Driver for Lantiq PHYs"
  19. + ---help---
  20. + Supports the 11G and 22E PHYs.
  21. +
  22. config FIXED_PHY
  23. bool "Driver for MDIO Bus/PHY emulation with fixed speed/link PHYs"
  24. depends on PHYLIB=y
  25. --- a/drivers/net/phy/Makefile
  26. +++ b/drivers/net/phy/Makefile
  27. @@ -40,6 +40,7 @@ obj-$(CONFIG_NATIONAL_PHY) += national.o
  28. obj-$(CONFIG_DP83640_PHY) += dp83640.o
  29. obj-$(CONFIG_STE10XP) += ste10Xp.o
  30. obj-$(CONFIG_MICREL_PHY) += micrel.o
  31. +obj-$(CONFIG_LANTIQ_PHY) += lantiq.o
  32. obj-$(CONFIG_MDIO_OCTEON) += mdio-octeon.o
  33. obj-$(CONFIG_MICREL_KS8995MA) += spi_ks8995.o
  34. obj-$(CONFIG_AT803X_PHY) += at803x.o
  35. --- /dev/null
  36. +++ b/drivers/net/phy/lantiq.c
  37. @@ -0,0 +1,231 @@
  38. +/*
  39. + * This program is free software; you can redistribute it and/or modify
  40. + * it under the terms of the GNU General Public License as published by
  41. + * the Free Software Foundation; either version 2 of the License, or
  42. + * (at your option) any later version.
  43. + *
  44. + * This program is distributed in the hope that it will be useful,
  45. + * but WITHOUT ANY WARRANTY; without even the implied warranty of
  46. + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  47. + * GNU General Public License for more details.
  48. + *
  49. + * You should have received a copy of the GNU General Public License
  50. + * along with this program; if not, write to the Free Software
  51. + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA.
  52. + *
  53. + * Copyright (C) 2012 Daniel Schwierzeck <daniel.schwierzeck@googlemail.com>
  54. + */
  55. +
  56. +#include <linux/module.h>
  57. +#include <linux/phy.h>
  58. +
  59. +#define MII_MMDCTRL 0x0d
  60. +#define MII_MMDDATA 0x0e
  61. +
  62. +#define MII_VR9_11G_IMASK 0x19 /* interrupt mask */
  63. +#define MII_VR9_11G_ISTAT 0x1a /* interrupt status */
  64. +
  65. +#define INT_VR9_11G_WOL BIT(15) /* Wake-On-LAN */
  66. +#define INT_VR9_11G_ANE BIT(11) /* Auto-Neg error */
  67. +#define INT_VR9_11G_ANC BIT(10) /* Auto-Neg complete */
  68. +#define INT_VR9_11G_ADSC BIT(5) /* Link auto-downspeed detect */
  69. +#define INT_VR9_11G_DXMC BIT(2) /* Duplex mode change */
  70. +#define INT_VR9_11G_LSPC BIT(1) /* Link speed change */
  71. +#define INT_VR9_11G_LSTC BIT(0) /* Link state change */
  72. +#define INT_VR9_11G_MASK (INT_VR9_11G_LSTC | INT_VR9_11G_ADSC)
  73. +
  74. +#define ADVERTISED_MPD BIT(10) /* Multi-port device */
  75. +
  76. +#define MMD_DEVAD 0x1f
  77. +#define MMD_ACTYPE_SHIFT 14
  78. +#define MMD_ACTYPE_ADDRESS (0 << MMD_ACTYPE_SHIFT)
  79. +#define MMD_ACTYPE_DATA (1 << MMD_ACTYPE_SHIFT)
  80. +#define MMD_ACTYPE_DATA_PI (2 << MMD_ACTYPE_SHIFT)
  81. +#define MMD_ACTYPE_DATA_PIWR (3 << MMD_ACTYPE_SHIFT)
  82. +
  83. +static __maybe_unused int vr9_gphy_mmd_read(struct phy_device *phydev,
  84. + u16 regnum)
  85. +{
  86. + phy_write(phydev, MII_MMDCTRL, MMD_ACTYPE_ADDRESS | MMD_DEVAD);
  87. + phy_write(phydev, MII_MMDDATA, regnum);
  88. + phy_write(phydev, MII_MMDCTRL, MMD_ACTYPE_DATA | MMD_DEVAD);
  89. +
  90. + return phy_read(phydev, MII_MMDDATA);
  91. +}
  92. +
  93. +static __maybe_unused int vr9_gphy_mmd_write(struct phy_device *phydev,
  94. + u16 regnum, u16 val)
  95. +{
  96. + phy_write(phydev, MII_MMDCTRL, MMD_ACTYPE_ADDRESS | MMD_DEVAD);
  97. + phy_write(phydev, MII_MMDDATA, regnum);
  98. + phy_write(phydev, MII_MMDCTRL, MMD_ACTYPE_DATA | MMD_DEVAD);
  99. + phy_write(phydev, MII_MMDDATA, val);
  100. +
  101. + return 0;
  102. +}
  103. +
  104. +static int vr9_gphy_config_init(struct phy_device *phydev)
  105. +{
  106. + int err;
  107. +
  108. + dev_dbg(&phydev->dev, "%s\n", __func__);
  109. +
  110. + /* Mask all interrupts */
  111. + err = phy_write(phydev, MII_VR9_11G_IMASK, 0);
  112. + if (err)
  113. + return err;
  114. +
  115. + /* Clear all pending interrupts */
  116. + phy_read(phydev, MII_VR9_11G_ISTAT);
  117. +
  118. + vr9_gphy_mmd_write(phydev, 0x1e0, 0xc5);
  119. + vr9_gphy_mmd_write(phydev, 0x1e1, 0x67);
  120. + vr9_gphy_mmd_write(phydev, 0x1e2, 0x42);
  121. + vr9_gphy_mmd_write(phydev, 0x1e3, 0x10);
  122. + vr9_gphy_mmd_write(phydev, 0x1e4, 0x70);
  123. + vr9_gphy_mmd_write(phydev, 0x1e5, 0x03);
  124. + vr9_gphy_mmd_write(phydev, 0x1e6, 0x20);
  125. + vr9_gphy_mmd_write(phydev, 0x1e7, 0x00);
  126. + vr9_gphy_mmd_write(phydev, 0x1e8, 0x40);
  127. + vr9_gphy_mmd_write(phydev, 0x1e9, 0x20);
  128. +
  129. + return 0;
  130. +}
  131. +
  132. +static int vr9_gphy_config_aneg(struct phy_device *phydev)
  133. +{
  134. + int reg, err;
  135. +
  136. + /* Advertise as multi-port device */
  137. + reg = phy_read(phydev, MII_CTRL1000);
  138. + reg |= ADVERTISED_MPD;
  139. + err = phy_write(phydev, MII_CTRL1000, reg);
  140. + if (err)
  141. + return err;
  142. +
  143. + return genphy_config_aneg(phydev);
  144. +}
  145. +
  146. +static int vr9_gphy_ack_interrupt(struct phy_device *phydev)
  147. +{
  148. + int reg;
  149. +
  150. + /*
  151. + * Possible IRQ numbers:
  152. + * - IM3_IRL18 for GPHY0
  153. + * - IM3_IRL17 for GPHY1
  154. + *
  155. + * Due to a silicon bug IRQ lines are not really independent from
  156. + * each other. Sometimes the two lines are driven at the same time
  157. + * if only one GPHY core raises the interrupt.
  158. + */
  159. +
  160. + reg = phy_read(phydev, MII_VR9_11G_ISTAT);
  161. +
  162. + return (reg < 0) ? reg : 0;
  163. +}
  164. +
  165. +static int vr9_gphy_did_interrupt(struct phy_device *phydev)
  166. +{
  167. + int reg;
  168. +
  169. + reg = phy_read(phydev, MII_VR9_11G_ISTAT);
  170. +
  171. + return reg > 0;
  172. +}
  173. +
  174. +static int vr9_gphy_config_intr(struct phy_device *phydev)
  175. +{
  176. + int err;
  177. +
  178. + if (phydev->interrupts == PHY_INTERRUPT_ENABLED)
  179. + err = phy_write(phydev, MII_VR9_11G_IMASK, INT_VR9_11G_MASK);
  180. + else
  181. + err = phy_write(phydev, MII_VR9_11G_IMASK, 0);
  182. +
  183. + return err;
  184. +}
  185. +
  186. +static struct phy_driver lantiq_phy[] = {
  187. + {
  188. + .phy_id = 0xd565a400,
  189. + .phy_id_mask = 0xffffffff,
  190. + .name = "Lantiq XWAY PEF7071",
  191. + .features = (PHY_GBIT_FEATURES | SUPPORTED_Pause),
  192. + .flags = 0, /*PHY_HAS_INTERRUPT,*/
  193. + .config_init = vr9_gphy_config_init,
  194. + .config_aneg = vr9_gphy_config_aneg,
  195. + .read_status = genphy_read_status,
  196. + .ack_interrupt = vr9_gphy_ack_interrupt,
  197. + .did_interrupt = vr9_gphy_did_interrupt,
  198. + .config_intr = vr9_gphy_config_intr,
  199. + .driver = { .owner = THIS_MODULE },
  200. + }, {
  201. + .phy_id = 0x030260D0,
  202. + .phy_id_mask = 0xfffffff0,
  203. + .name = "Lantiq XWAY VR9 GPHY 11G v1.3",
  204. + .features = (PHY_GBIT_FEATURES | SUPPORTED_Pause),
  205. + .flags = 0, /*PHY_HAS_INTERRUPT,*/
  206. + .config_init = vr9_gphy_config_init,
  207. + .config_aneg = vr9_gphy_config_aneg,
  208. + .read_status = genphy_read_status,
  209. + .ack_interrupt = vr9_gphy_ack_interrupt,
  210. + .did_interrupt = vr9_gphy_did_interrupt,
  211. + .config_intr = vr9_gphy_config_intr,
  212. + .driver = { .owner = THIS_MODULE },
  213. + }, {
  214. + .phy_id = 0xd565a408,
  215. + .phy_id_mask = 0xfffffff8,
  216. + .name = "Lantiq XWAY VR9 GPHY 11G v1.4",
  217. + .features = (PHY_GBIT_FEATURES | SUPPORTED_Pause),
  218. + .flags = 0, /*PHY_HAS_INTERRUPT,*/
  219. + .config_init = vr9_gphy_config_init,
  220. + .config_aneg = vr9_gphy_config_aneg,
  221. + .read_status = genphy_read_status,
  222. + .ack_interrupt = vr9_gphy_ack_interrupt,
  223. + .did_interrupt = vr9_gphy_did_interrupt,
  224. + .config_intr = vr9_gphy_config_intr,
  225. + .driver = { .owner = THIS_MODULE },
  226. + }, {
  227. + .phy_id = 0xd565a418,
  228. + .phy_id_mask = 0xfffffff8,
  229. + .name = "Lantiq XWAY XRX PHY22F v1.4",
  230. + .features = (PHY_BASIC_FEATURES | SUPPORTED_Pause),
  231. + .flags = 0, /*PHY_HAS_INTERRUPT,*/
  232. + .config_init = vr9_gphy_config_init,
  233. + .config_aneg = vr9_gphy_config_aneg,
  234. + .read_status = genphy_read_status,
  235. + .ack_interrupt = vr9_gphy_ack_interrupt,
  236. + .did_interrupt = vr9_gphy_did_interrupt,
  237. + .config_intr = vr9_gphy_config_intr,
  238. + .driver = { .owner = THIS_MODULE },
  239. + },
  240. +};
  241. +
  242. +static int __init ltq_phy_init(void)
  243. +{
  244. + int i;
  245. +
  246. + for (i = 0; i < ARRAY_SIZE(lantiq_phy); i++) {
  247. + int err = phy_driver_register(&lantiq_phy[i]);
  248. + if (err)
  249. + pr_err("lantiq_phy: failed to load %s\n", lantiq_phy[i].name);
  250. + }
  251. +
  252. + return 0;
  253. +}
  254. +
  255. +static void __exit ltq_phy_exit(void)
  256. +{
  257. + int i;
  258. +
  259. + for (i = 0; i < ARRAY_SIZE(lantiq_phy); i++)
  260. + phy_driver_unregister(&lantiq_phy[i]);
  261. +}
  262. +
  263. +module_init(ltq_phy_init);
  264. +module_exit(ltq_phy_exit);
  265. +
  266. +MODULE_DESCRIPTION("Lantiq PHY drivers");
  267. +MODULE_AUTHOR("Daniel Schwierzeck <daniel.schwierzeck@googlemail.com>");
  268. +MODULE_LICENSE("GPL");