1 From 12f4b99d63edc15849357c09e22a36445c2752cc Mon Sep 17 00:00:00 2001
2 From: John Crispin <blogic@openwrt.org>
3 Date: Mon, 22 Oct 2012 09:28:30 +0200
4 Subject: [PATCH 115/123] NET: PHY: adds driver for lantiq PHY11G
6 Signed-off-by: John Crispin <blogic@openwrt.org>
8 drivers/net/phy/Kconfig | 5 ++
9 drivers/net/phy/Makefile | 1 +
10 drivers/net/phy/lantiq.c | 178 ++++++++++++++++++++++++++++++++++++++++++++++
11 3 files changed, 184 insertions(+)
12 create mode 100644 drivers/net/phy/lantiq.c
14 diff --git a/drivers/net/phy/Kconfig b/drivers/net/phy/Kconfig
15 index 961f0b2..41a2992 100644
16 --- a/drivers/net/phy/Kconfig
17 +++ b/drivers/net/phy/Kconfig
18 @@ -107,6 +107,11 @@ config MICREL_PHY
20 Supports the KSZ9021, VSC8201, KS8001 PHYs.
23 + tristate "Driver for Lantiq PHYs"
25 + Supports the 11G and 22E PHYs.
28 bool "Driver for MDIO Bus/PHY emulation with fixed speed/link PHYs"
30 diff --git a/drivers/net/phy/Makefile b/drivers/net/phy/Makefile
31 index 9645e38..e2eeee3 100644
32 --- a/drivers/net/phy/Makefile
33 +++ b/drivers/net/phy/Makefile
34 @@ -23,6 +23,7 @@ obj-$(CONFIG_NATIONAL_PHY) += national.o
35 obj-$(CONFIG_DP83640_PHY) += dp83640.o
36 obj-$(CONFIG_STE10XP) += ste10Xp.o
37 obj-$(CONFIG_MICREL_PHY) += micrel.o
38 +obj-$(CONFIG_LANTIQ_PHY) += lantiq.o
39 obj-$(CONFIG_MDIO_OCTEON) += mdio-octeon.o
40 obj-$(CONFIG_MICREL_KS8995MA) += spi_ks8995.o
41 obj-$(CONFIG_AT803X_PHY) += at803x.o
42 diff --git a/drivers/net/phy/lantiq.c b/drivers/net/phy/lantiq.c
44 index 0000000..ba4d7b7
46 +++ b/drivers/net/phy/lantiq.c
49 + * This program is free software; you can redistribute it and/or modify
50 + * it under the terms of the GNU General Public License as published by
51 + * the Free Software Foundation; either version 2 of the License, or
52 + * (at your option) any later version.
54 + * This program is distributed in the hope that it will be useful,
55 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
56 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
57 + * GNU General Public License for more details.
59 + * You should have received a copy of the GNU General Public License
60 + * along with this program; if not, write to the Free Software
61 + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA.
63 + * Copyright (C) 2012 Daniel Schwierzeck <daniel.schwierzeck@googlemail.com>
66 +#include <linux/module.h>
67 +#include <linux/phy.h>
69 +#define MII_MMDCTRL 0x0d
70 +#define MII_MMDDATA 0x0e
72 +#define MII_VR9_11G_IMASK 0x19 /* interrupt mask */
73 +#define MII_VR9_11G_ISTAT 0x1a /* interrupt status */
75 +#define INT_VR9_11G_WOL BIT(15) /* Wake-On-LAN */
76 +#define INT_VR9_11G_ANE BIT(11) /* Auto-Neg error */
77 +#define INT_VR9_11G_ANC BIT(10) /* Auto-Neg complete */
78 +#define INT_VR9_11G_ADSC BIT(5) /* Link auto-downspeed detect */
79 +#define INT_VR9_11G_DXMC BIT(2) /* Duplex mode change */
80 +#define INT_VR9_11G_LSPC BIT(1) /* Link speed change */
81 +#define INT_VR9_11G_LSTC BIT(0) /* Link state change */
82 +#define INT_VR9_11G_MASK (INT_VR9_11G_LSTC | INT_VR9_11G_ADSC)
84 +#define ADVERTISED_MPD BIT(10) /* Multi-port device */
86 +#define MMD_DEVAD 0x1f
87 +#define MMD_ACTYPE_SHIFT 14
88 +#define MMD_ACTYPE_ADDRESS (0 << MMD_ACTYPE_SHIFT)
89 +#define MMD_ACTYPE_DATA (1 << MMD_ACTYPE_SHIFT)
90 +#define MMD_ACTYPE_DATA_PI (2 << MMD_ACTYPE_SHIFT)
91 +#define MMD_ACTYPE_DATA_PIWR (3 << MMD_ACTYPE_SHIFT)
93 +static __maybe_unused int vr9_gphy_mmd_read(struct phy_device *phydev,
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);
100 + return phy_read(phydev, MII_MMDDATA);
103 +static __maybe_unused int vr9_gphy_mmd_write(struct phy_device *phydev,
104 + u16 regnum, u16 val)
106 + phy_write(phydev, MII_MMDCTRL, MMD_ACTYPE_ADDRESS | MMD_DEVAD);
107 + phy_write(phydev, MII_MMDDATA, regnum);
108 + phy_write(phydev, MII_MMDCTRL, MMD_ACTYPE_DATA | MMD_DEVAD);
109 + phy_write(phydev, MII_MMDDATA, val);
114 +static int vr9_gphy_config_init(struct phy_device *phydev)
118 + dev_dbg(&phydev->dev, "%s\n", __func__);
120 + /* Mask all interrupts */
121 + err = phy_write(phydev, MII_VR9_11G_IMASK, 0);
125 + /* Clear all pending interrupts */
126 + phy_read(phydev, MII_VR9_11G_ISTAT);
131 +static int vr9_gphy_config_aneg(struct phy_device *phydev)
135 + /* Advertise as multi-port device */
136 + reg = phy_read(phydev, MII_CTRL1000);
137 + reg |= ADVERTISED_MPD;
138 + err = phy_write(phydev, MII_CTRL1000, reg);
142 + return genphy_config_aneg(phydev);
145 +static int vr9_gphy_ack_interrupt(struct phy_device *phydev)
150 + * Possible IRQ numbers:
151 + * - IM3_IRL18 for GPHY0
152 + * - IM3_IRL17 for GPHY1
154 + * Due to a silicon bug IRQ lines are not really independent from
155 + * each other. Sometimes the two lines are driven at the same time
156 + * if only one GPHY core raises the interrupt.
159 + reg = phy_read(phydev, MII_VR9_11G_ISTAT);
161 + return (reg < 0) ? reg : 0;
164 +static int vr9_gphy_did_interrupt(struct phy_device *phydev)
168 + reg = phy_read(phydev, MII_VR9_11G_ISTAT);
173 +static int vr9_gphy_config_intr(struct phy_device *phydev)
177 + if (phydev->interrupts == PHY_INTERRUPT_ENABLED)
178 + err = phy_write(phydev, MII_VR9_11G_IMASK, INT_VR9_11G_MASK);
180 + err = phy_write(phydev, MII_VR9_11G_IMASK, 0);
185 +/* TODO: add vr9_gphy_22f_driver and drivers for external Lantiq PEF7071 PHYs */
186 +static struct phy_driver vr9_gphy_11g_driver = {
187 + .phy_id = 0xd565a408,
188 + .phy_id_mask = 0xfffffff0,
189 + .name = "Lantiq XWAY VR9 GPHY 11G",
190 + .features = (PHY_GBIT_FEATURES | SUPPORTED_Pause),
191 + .flags = 0, /*PHY_HAS_INTERRUPT,*/
192 + .config_init = vr9_gphy_config_init,
193 + .config_aneg = vr9_gphy_config_aneg,
194 + .read_status = genphy_read_status,
195 + .ack_interrupt = vr9_gphy_ack_interrupt,
196 + .did_interrupt = vr9_gphy_did_interrupt,
197 + .config_intr = vr9_gphy_config_intr,
198 + .driver = { .owner = THIS_MODULE },
201 +static int __init ltq_phy_init(void)
205 + err = phy_driver_register(&vr9_gphy_11g_driver);
215 +static void __exit ltq_phy_exit(void)
217 + phy_driver_unregister(&vr9_gphy_11g_driver);
220 +module_init(ltq_phy_init);
221 +module_exit(ltq_phy_exit);
223 +MODULE_DESCRIPTION("Lantiq PHY drivers");
224 +MODULE_AUTHOR("Daniel Schwierzeck <daniel.schwierzeck@googlemail.com>");
225 +MODULE_LICENSE("GPL");