Skip to content

Commit 792aec4

Browse files
WoojungHuhdavem330
authored andcommitted
add microchip LAN88xx phy driver
Add Microchip LAN88XX phy driver for phylib. Signed-off-by: Woojung Huh <woojung.huh@microchip.com> Signed-off-by: David S. Miller <davem@davemloft.net>
1 parent dfc50fc commit 792aec4

File tree

4 files changed

+227
-0
lines changed

4 files changed

+227
-0
lines changed

drivers/net/phy/Kconfig

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -127,6 +127,11 @@ config DP83867_PHY
127127
---help---
128128
Currently supports the DP83867 PHY.
129129

130+
config MICROCHIP_PHY
131+
tristate "Drivers for Microchip PHYs"
132+
help
133+
Supports the LAN88XX PHYs.
134+
130135
config FIXED_PHY
131136
tristate "Driver for MDIO Bus/PHY emulation with fixed speed/link PHYs"
132137
depends on PHYLIB

drivers/net/phy/Makefile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,3 +37,4 @@ obj-$(CONFIG_MDIO_BUS_MUX_MMIOREG) += mdio-mux-mmioreg.o
3737
obj-$(CONFIG_MDIO_SUN4I) += mdio-sun4i.o
3838
obj-$(CONFIG_MDIO_MOXART) += mdio-moxart.o
3939
obj-$(CONFIG_MDIO_BCM_UNIMAC) += mdio-bcm-unimac.o
40+
obj-$(CONFIG_MICROCHIP_PHY) += microchip.o

drivers/net/phy/microchip.c

Lines changed: 148 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,148 @@
1+
/*
2+
* Copyright (C) 2015 Microchip Technology
3+
*
4+
* This program is free software; you can redistribute it and/or
5+
* modify it under the terms of the GNU General Public License
6+
* as published by the Free Software Foundation; either version 2
7+
* of the License, or (at your option) any later version.
8+
*
9+
* This program is distributed in the hope that it will be useful,
10+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
11+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12+
* GNU General Public License for more details.
13+
*
14+
* You should have received a copy of the GNU General Public License
15+
* along with this program; if not, see <http://www.gnu.org/licenses/>.
16+
*/
17+
#include <linux/kernel.h>
18+
#include <linux/module.h>
19+
#include <linux/mii.h>
20+
#include <linux/ethtool.h>
21+
#include <linux/phy.h>
22+
#include <linux/microchipphy.h>
23+
24+
#define DRIVER_AUTHOR "WOOJUNG HUH <woojung.huh@microchip.com>"
25+
#define DRIVER_DESC "Microchip LAN88XX PHY driver"
26+
27+
struct lan88xx_priv {
28+
int chip_id;
29+
int chip_rev;
30+
__u32 wolopts;
31+
};
32+
33+
static int lan88xx_phy_config_intr(struct phy_device *phydev)
34+
{
35+
int rc;
36+
37+
if (phydev->interrupts == PHY_INTERRUPT_ENABLED) {
38+
/* unmask all source and clear them before enable */
39+
rc = phy_write(phydev, LAN88XX_INT_MASK, 0x7FFF);
40+
rc = phy_read(phydev, LAN88XX_INT_STS);
41+
rc = phy_write(phydev, LAN88XX_INT_MASK,
42+
LAN88XX_INT_MASK_MDINTPIN_EN_ |
43+
LAN88XX_INT_MASK_LINK_CHANGE_);
44+
} else {
45+
rc = phy_write(phydev, LAN88XX_INT_MASK, 0);
46+
}
47+
48+
return rc < 0 ? rc : 0;
49+
}
50+
51+
static int lan88xx_phy_ack_interrupt(struct phy_device *phydev)
52+
{
53+
int rc = phy_read(phydev, LAN88XX_INT_STS);
54+
55+
return rc < 0 ? rc : 0;
56+
}
57+
58+
int lan88xx_suspend(struct phy_device *phydev)
59+
{
60+
struct lan88xx_priv *priv = phydev->priv;
61+
62+
/* do not power down PHY when WOL is enabled */
63+
if (!priv->wolopts)
64+
genphy_suspend(phydev);
65+
66+
return 0;
67+
}
68+
69+
static int lan88xx_probe(struct phy_device *phydev)
70+
{
71+
struct device *dev = &phydev->dev;
72+
struct lan88xx_priv *priv;
73+
74+
priv = devm_kzalloc(dev, sizeof(*priv), GFP_KERNEL);
75+
if (!priv)
76+
return -ENOMEM;
77+
78+
priv->wolopts = 0;
79+
80+
/* these values can be used to identify internal PHY */
81+
priv->chip_id = phy_read_mmd_indirect(phydev, LAN88XX_MMD3_CHIP_ID,
82+
3, phydev->addr);
83+
priv->chip_rev = phy_read_mmd_indirect(phydev, LAN88XX_MMD3_CHIP_REV,
84+
3, phydev->addr);
85+
86+
phydev->priv = priv;
87+
88+
return 0;
89+
}
90+
91+
static void lan88xx_remove(struct phy_device *phydev)
92+
{
93+
struct device *dev = &phydev->dev;
94+
struct lan88xx_priv *priv = phydev->priv;
95+
96+
if (priv)
97+
devm_kfree(dev, priv);
98+
}
99+
100+
static int lan88xx_set_wol(struct phy_device *phydev,
101+
struct ethtool_wolinfo *wol)
102+
{
103+
struct lan88xx_priv *priv = phydev->priv;
104+
105+
priv->wolopts = wol->wolopts;
106+
107+
return 0;
108+
}
109+
110+
static struct phy_driver microchip_phy_driver[] = {
111+
{
112+
.phy_id = 0x0007c130,
113+
.phy_id_mask = 0xfffffff0,
114+
.name = "Microchip LAN88xx",
115+
116+
.features = (PHY_GBIT_FEATURES |
117+
SUPPORTED_Pause | SUPPORTED_Asym_Pause),
118+
.flags = PHY_HAS_INTERRUPT | PHY_HAS_MAGICANEG,
119+
120+
.probe = lan88xx_probe,
121+
.remove = lan88xx_remove,
122+
123+
.config_init = genphy_config_init,
124+
.config_aneg = genphy_config_aneg,
125+
.read_status = genphy_read_status,
126+
127+
.ack_interrupt = lan88xx_phy_ack_interrupt,
128+
.config_intr = lan88xx_phy_config_intr,
129+
130+
.suspend = lan88xx_suspend,
131+
.resume = genphy_resume,
132+
.set_wol = lan88xx_set_wol,
133+
134+
.driver = { .owner = THIS_MODULE, }
135+
} };
136+
137+
module_phy_driver(microchip_phy_driver);
138+
139+
static struct mdio_device_id __maybe_unused microchip_tbl[] = {
140+
{ 0x0007c130, 0xfffffff0 },
141+
{ }
142+
};
143+
144+
MODULE_DEVICE_TABLE(mdio, microchip_tbl);
145+
146+
MODULE_AUTHOR(DRIVER_AUTHOR);
147+
MODULE_DESCRIPTION(DRIVER_DESC);
148+
MODULE_LICENSE("GPL");

include/linux/microchipphy.h

Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
/*
2+
* Copyright (C) 2015 Microchip Technology
3+
*
4+
* This program is free software; you can redistribute it and/or
5+
* modify it under the terms of the GNU General Public License
6+
* as published by the Free Software Foundation; either version 2
7+
* of the License, or (at your option) any later version.
8+
*
9+
* This program is distributed in the hope that it will be useful,
10+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
11+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12+
* GNU General Public License for more details.
13+
*
14+
* You should have received a copy of the GNU General Public License
15+
* along with this program; if not, see <http://www.gnu.org/licenses/>.
16+
*/
17+
18+
#ifndef _MICROCHIPPHY_H
19+
#define _MICROCHIPPHY_H
20+
21+
#define LAN88XX_INT_MASK (0x19)
22+
#define LAN88XX_INT_MASK_MDINTPIN_EN_ (0x8000)
23+
#define LAN88XX_INT_MASK_SPEED_CHANGE_ (0x4000)
24+
#define LAN88XX_INT_MASK_LINK_CHANGE_ (0x2000)
25+
#define LAN88XX_INT_MASK_FDX_CHANGE_ (0x1000)
26+
#define LAN88XX_INT_MASK_AUTONEG_ERR_ (0x0800)
27+
#define LAN88XX_INT_MASK_AUTONEG_DONE_ (0x0400)
28+
#define LAN88XX_INT_MASK_POE_DETECT_ (0x0200)
29+
#define LAN88XX_INT_MASK_SYMBOL_ERR_ (0x0100)
30+
#define LAN88XX_INT_MASK_FAST_LINK_FAIL_ (0x0080)
31+
#define LAN88XX_INT_MASK_WOL_EVENT_ (0x0040)
32+
#define LAN88XX_INT_MASK_EXTENDED_INT_ (0x0020)
33+
#define LAN88XX_INT_MASK_RESERVED_ (0x0010)
34+
#define LAN88XX_INT_MASK_FALSE_CARRIER_ (0x0008)
35+
#define LAN88XX_INT_MASK_LINK_SPEED_DS_ (0x0004)
36+
#define LAN88XX_INT_MASK_MASTER_SLAVE_DONE_ (0x0002)
37+
#define LAN88XX_INT_MASK_RX__ER_ (0x0001)
38+
39+
#define LAN88XX_INT_STS (0x1A)
40+
#define LAN88XX_INT_STS_INT_ACTIVE_ (0x8000)
41+
#define LAN88XX_INT_STS_SPEED_CHANGE_ (0x4000)
42+
#define LAN88XX_INT_STS_LINK_CHANGE_ (0x2000)
43+
#define LAN88XX_INT_STS_FDX_CHANGE_ (0x1000)
44+
#define LAN88XX_INT_STS_AUTONEG_ERR_ (0x0800)
45+
#define LAN88XX_INT_STS_AUTONEG_DONE_ (0x0400)
46+
#define LAN88XX_INT_STS_POE_DETECT_ (0x0200)
47+
#define LAN88XX_INT_STS_SYMBOL_ERR_ (0x0100)
48+
#define LAN88XX_INT_STS_FAST_LINK_FAIL_ (0x0080)
49+
#define LAN88XX_INT_STS_WOL_EVENT_ (0x0040)
50+
#define LAN88XX_INT_STS_EXTENDED_INT_ (0x0020)
51+
#define LAN88XX_INT_STS_RESERVED_ (0x0010)
52+
#define LAN88XX_INT_STS_FALSE_CARRIER_ (0x0008)
53+
#define LAN88XX_INT_STS_LINK_SPEED_DS_ (0x0004)
54+
#define LAN88XX_INT_STS_MASTER_SLAVE_DONE_ (0x0002)
55+
#define LAN88XX_INT_STS_RX_ER_ (0x0001)
56+
57+
#define LAN88XX_EXT_PAGE_ACCESS (0x1F)
58+
#define LAN88XX_EXT_PAGE_SPACE_0 (0x0000)
59+
#define LAN88XX_EXT_PAGE_SPACE_1 (0x0001)
60+
#define LAN88XX_EXT_PAGE_SPACE_2 (0x0002)
61+
62+
/* Extended Register Page 1 space */
63+
#define LAN88XX_EXT_MODE_CTRL (0x13)
64+
#define LAN88XX_EXT_MODE_CTRL_MDIX_MASK_ (0x000C)
65+
#define LAN88XX_EXT_MODE_CTRL_AUTO_MDIX_ (0x0000)
66+
#define LAN88XX_EXT_MODE_CTRL_MDI_ (0x0008)
67+
#define LAN88XX_EXT_MODE_CTRL_MDI_X_ (0x000C)
68+
69+
/* MMD 3 Registers */
70+
#define LAN88XX_MMD3_CHIP_ID (32877)
71+
#define LAN88XX_MMD3_CHIP_REV (32878)
72+
73+
#endif /* _MICROCHIPPHY_H */

0 commit comments

Comments
 (0)