xref: /openbmc/linux/drivers/net/phy/micrel.c (revision 836384d2501dee87b1c437f3e268871980c857bf)
1d0507009SDavid J. Choi /*
2d0507009SDavid J. Choi  * drivers/net/phy/micrel.c
3d0507009SDavid J. Choi  *
4d0507009SDavid J. Choi  * Driver for Micrel PHYs
5d0507009SDavid J. Choi  *
6d0507009SDavid J. Choi  * Author: David J. Choi
7d0507009SDavid J. Choi  *
87ab59dc1SDavid J. Choi  * Copyright (c) 2010-2013 Micrel, Inc.
9ee0dc2fbSJohan Hovold  * Copyright (c) 2014 Johan Hovold <johan@kernel.org>
10d0507009SDavid J. Choi  *
11d0507009SDavid J. Choi  * This program is free software; you can redistribute  it and/or modify it
12d0507009SDavid J. Choi  * under  the terms of  the GNU General  Public License as published by the
13d0507009SDavid J. Choi  * Free Software Foundation;  either version 2 of the  License, or (at your
14d0507009SDavid J. Choi  * option) any later version.
15d0507009SDavid J. Choi  *
167ab59dc1SDavid J. Choi  * Support : Micrel Phys:
177ab59dc1SDavid J. Choi  *		Giga phys: ksz9021, ksz9031
187ab59dc1SDavid J. Choi  *		100/10 Phys : ksz8001, ksz8721, ksz8737, ksz8041
197ab59dc1SDavid J. Choi  *			   ksz8021, ksz8031, ksz8051,
207ab59dc1SDavid J. Choi  *			   ksz8081, ksz8091,
217ab59dc1SDavid J. Choi  *			   ksz8061,
227ab59dc1SDavid J. Choi  *		Switch : ksz8873, ksz886x
23d0507009SDavid J. Choi  */
24d0507009SDavid J. Choi 
25d0507009SDavid J. Choi #include <linux/kernel.h>
26d0507009SDavid J. Choi #include <linux/module.h>
27d0507009SDavid J. Choi #include <linux/phy.h>
28d606ef3fSBaruch Siach #include <linux/micrel_phy.h>
29954c3967SSean Cross #include <linux/of.h>
301fadee0cSSascha Hauer #include <linux/clk.h>
31d0507009SDavid J. Choi 
32212ea99aSMarek Vasut /* Operation Mode Strap Override */
33212ea99aSMarek Vasut #define MII_KSZPHY_OMSO				0x16
3400aee095SJohan Hovold #define KSZPHY_OMSO_B_CAST_OFF			BIT(9)
352b0ba96cSSylvain Rochet #define KSZPHY_OMSO_NAND_TREE_ON		BIT(5)
3600aee095SJohan Hovold #define KSZPHY_OMSO_RMII_OVERRIDE		BIT(1)
3700aee095SJohan Hovold #define KSZPHY_OMSO_MII_OVERRIDE		BIT(0)
38212ea99aSMarek Vasut 
3951f932c4SChoi, David /* general Interrupt control/status reg in vendor specific block. */
4051f932c4SChoi, David #define MII_KSZPHY_INTCS			0x1B
4100aee095SJohan Hovold #define	KSZPHY_INTCS_JABBER			BIT(15)
4200aee095SJohan Hovold #define	KSZPHY_INTCS_RECEIVE_ERR		BIT(14)
4300aee095SJohan Hovold #define	KSZPHY_INTCS_PAGE_RECEIVE		BIT(13)
4400aee095SJohan Hovold #define	KSZPHY_INTCS_PARELLEL			BIT(12)
4500aee095SJohan Hovold #define	KSZPHY_INTCS_LINK_PARTNER_ACK		BIT(11)
4600aee095SJohan Hovold #define	KSZPHY_INTCS_LINK_DOWN			BIT(10)
4700aee095SJohan Hovold #define	KSZPHY_INTCS_REMOTE_FAULT		BIT(9)
4800aee095SJohan Hovold #define	KSZPHY_INTCS_LINK_UP			BIT(8)
4951f932c4SChoi, David #define	KSZPHY_INTCS_ALL			(KSZPHY_INTCS_LINK_UP |\
5051f932c4SChoi, David 						KSZPHY_INTCS_LINK_DOWN)
5151f932c4SChoi, David 
525a16778eSJohan Hovold /* PHY Control 1 */
535a16778eSJohan Hovold #define	MII_KSZPHY_CTRL_1			0x1e
545a16778eSJohan Hovold 
555a16778eSJohan Hovold /* PHY Control 2 / PHY Control (if no PHY Control 1) */
565a16778eSJohan Hovold #define	MII_KSZPHY_CTRL_2			0x1f
575a16778eSJohan Hovold #define	MII_KSZPHY_CTRL				MII_KSZPHY_CTRL_2
5851f932c4SChoi, David /* bitmap of PHY register to set interrupt mode */
5900aee095SJohan Hovold #define KSZPHY_CTRL_INT_ACTIVE_HIGH		BIT(9)
6063f44b2bSJohan Hovold #define KSZPHY_RMII_REF_CLK_SEL			BIT(7)
6151f932c4SChoi, David 
62954c3967SSean Cross /* Write/read to/from extended registers */
63954c3967SSean Cross #define MII_KSZPHY_EXTREG                       0x0b
64954c3967SSean Cross #define KSZPHY_EXTREG_WRITE                     0x8000
65954c3967SSean Cross 
66954c3967SSean Cross #define MII_KSZPHY_EXTREG_WRITE                 0x0c
67954c3967SSean Cross #define MII_KSZPHY_EXTREG_READ                  0x0d
68954c3967SSean Cross 
69954c3967SSean Cross /* Extended registers */
70954c3967SSean Cross #define MII_KSZPHY_CLK_CONTROL_PAD_SKEW         0x104
71954c3967SSean Cross #define MII_KSZPHY_RX_DATA_PAD_SKEW             0x105
72954c3967SSean Cross #define MII_KSZPHY_TX_DATA_PAD_SKEW             0x106
73954c3967SSean Cross 
74954c3967SSean Cross #define PS_TO_REG				200
75954c3967SSean Cross 
762b2427d0SAndrew Lunn struct kszphy_hw_stat {
772b2427d0SAndrew Lunn 	const char *string;
782b2427d0SAndrew Lunn 	u8 reg;
792b2427d0SAndrew Lunn 	u8 bits;
802b2427d0SAndrew Lunn };
812b2427d0SAndrew Lunn 
822b2427d0SAndrew Lunn static struct kszphy_hw_stat kszphy_hw_stats[] = {
832b2427d0SAndrew Lunn 	{ "phy_receive_errors", 21, 16},
842b2427d0SAndrew Lunn 	{ "phy_idle_errors", 10, 8 },
852b2427d0SAndrew Lunn };
862b2427d0SAndrew Lunn 
87e6a423a8SJohan Hovold struct kszphy_type {
88e6a423a8SJohan Hovold 	u32 led_mode_reg;
89c6f9575cSJohan Hovold 	u16 interrupt_level_mask;
900f95903eSJohan Hovold 	bool has_broadcast_disable;
912b0ba96cSSylvain Rochet 	bool has_nand_tree_disable;
9263f44b2bSJohan Hovold 	bool has_rmii_ref_clk_sel;
93e6a423a8SJohan Hovold };
94e6a423a8SJohan Hovold 
95e6a423a8SJohan Hovold struct kszphy_priv {
96e6a423a8SJohan Hovold 	const struct kszphy_type *type;
97e7a792e9SJohan Hovold 	int led_mode;
9863f44b2bSJohan Hovold 	bool rmii_ref_clk_sel;
9963f44b2bSJohan Hovold 	bool rmii_ref_clk_sel_val;
1002b2427d0SAndrew Lunn 	u64 stats[ARRAY_SIZE(kszphy_hw_stats)];
101e6a423a8SJohan Hovold };
102e6a423a8SJohan Hovold 
103e6a423a8SJohan Hovold static const struct kszphy_type ksz8021_type = {
104e6a423a8SJohan Hovold 	.led_mode_reg		= MII_KSZPHY_CTRL_2,
105d0e1df9cSJohan Hovold 	.has_broadcast_disable	= true,
1062b0ba96cSSylvain Rochet 	.has_nand_tree_disable	= true,
10763f44b2bSJohan Hovold 	.has_rmii_ref_clk_sel	= true,
108e6a423a8SJohan Hovold };
109e6a423a8SJohan Hovold 
110e6a423a8SJohan Hovold static const struct kszphy_type ksz8041_type = {
111e6a423a8SJohan Hovold 	.led_mode_reg		= MII_KSZPHY_CTRL_1,
112e6a423a8SJohan Hovold };
113e6a423a8SJohan Hovold 
114e6a423a8SJohan Hovold static const struct kszphy_type ksz8051_type = {
115e6a423a8SJohan Hovold 	.led_mode_reg		= MII_KSZPHY_CTRL_2,
1162b0ba96cSSylvain Rochet 	.has_nand_tree_disable	= true,
117e6a423a8SJohan Hovold };
118e6a423a8SJohan Hovold 
119e6a423a8SJohan Hovold static const struct kszphy_type ksz8081_type = {
120e6a423a8SJohan Hovold 	.led_mode_reg		= MII_KSZPHY_CTRL_2,
1210f95903eSJohan Hovold 	.has_broadcast_disable	= true,
1222b0ba96cSSylvain Rochet 	.has_nand_tree_disable	= true,
12386dc1342SJohan Hovold 	.has_rmii_ref_clk_sel	= true,
124e6a423a8SJohan Hovold };
125e6a423a8SJohan Hovold 
126c6f9575cSJohan Hovold static const struct kszphy_type ks8737_type = {
127c6f9575cSJohan Hovold 	.interrupt_level_mask	= BIT(14),
128c6f9575cSJohan Hovold };
129c6f9575cSJohan Hovold 
130c6f9575cSJohan Hovold static const struct kszphy_type ksz9021_type = {
131c6f9575cSJohan Hovold 	.interrupt_level_mask	= BIT(14),
132c6f9575cSJohan Hovold };
133c6f9575cSJohan Hovold 
134954c3967SSean Cross static int kszphy_extended_write(struct phy_device *phydev,
135954c3967SSean Cross 				u32 regnum, u16 val)
136954c3967SSean Cross {
137954c3967SSean Cross 	phy_write(phydev, MII_KSZPHY_EXTREG, KSZPHY_EXTREG_WRITE | regnum);
138954c3967SSean Cross 	return phy_write(phydev, MII_KSZPHY_EXTREG_WRITE, val);
139954c3967SSean Cross }
140954c3967SSean Cross 
141954c3967SSean Cross static int kszphy_extended_read(struct phy_device *phydev,
142954c3967SSean Cross 				u32 regnum)
143954c3967SSean Cross {
144954c3967SSean Cross 	phy_write(phydev, MII_KSZPHY_EXTREG, regnum);
145954c3967SSean Cross 	return phy_read(phydev, MII_KSZPHY_EXTREG_READ);
146954c3967SSean Cross }
147954c3967SSean Cross 
14851f932c4SChoi, David static int kszphy_ack_interrupt(struct phy_device *phydev)
14951f932c4SChoi, David {
15051f932c4SChoi, David 	/* bit[7..0] int status, which is a read and clear register. */
15151f932c4SChoi, David 	int rc;
15251f932c4SChoi, David 
15351f932c4SChoi, David 	rc = phy_read(phydev, MII_KSZPHY_INTCS);
15451f932c4SChoi, David 
15551f932c4SChoi, David 	return (rc < 0) ? rc : 0;
15651f932c4SChoi, David }
15751f932c4SChoi, David 
15851f932c4SChoi, David static int kszphy_config_intr(struct phy_device *phydev)
15951f932c4SChoi, David {
160c6f9575cSJohan Hovold 	const struct kszphy_type *type = phydev->drv->driver_data;
161c6f9575cSJohan Hovold 	int temp;
162c6f9575cSJohan Hovold 	u16 mask;
163c6f9575cSJohan Hovold 
164c6f9575cSJohan Hovold 	if (type && type->interrupt_level_mask)
165c6f9575cSJohan Hovold 		mask = type->interrupt_level_mask;
166c6f9575cSJohan Hovold 	else
167c6f9575cSJohan Hovold 		mask = KSZPHY_CTRL_INT_ACTIVE_HIGH;
16851f932c4SChoi, David 
16951f932c4SChoi, David 	/* set the interrupt pin active low */
17051f932c4SChoi, David 	temp = phy_read(phydev, MII_KSZPHY_CTRL);
1715bb8fc0dSJohan Hovold 	if (temp < 0)
1725bb8fc0dSJohan Hovold 		return temp;
173c6f9575cSJohan Hovold 	temp &= ~mask;
17451f932c4SChoi, David 	phy_write(phydev, MII_KSZPHY_CTRL, temp);
17551f932c4SChoi, David 
176c6f9575cSJohan Hovold 	/* enable / disable interrupts */
177c6f9575cSJohan Hovold 	if (phydev->interrupts == PHY_INTERRUPT_ENABLED)
178c6f9575cSJohan Hovold 		temp = KSZPHY_INTCS_ALL;
179c6f9575cSJohan Hovold 	else
180c6f9575cSJohan Hovold 		temp = 0;
18151f932c4SChoi, David 
182c6f9575cSJohan Hovold 	return phy_write(phydev, MII_KSZPHY_INTCS, temp);
18351f932c4SChoi, David }
184d0507009SDavid J. Choi 
18563f44b2bSJohan Hovold static int kszphy_rmii_clk_sel(struct phy_device *phydev, bool val)
18663f44b2bSJohan Hovold {
18763f44b2bSJohan Hovold 	int ctrl;
18863f44b2bSJohan Hovold 
18963f44b2bSJohan Hovold 	ctrl = phy_read(phydev, MII_KSZPHY_CTRL);
19063f44b2bSJohan Hovold 	if (ctrl < 0)
19163f44b2bSJohan Hovold 		return ctrl;
19263f44b2bSJohan Hovold 
19363f44b2bSJohan Hovold 	if (val)
19463f44b2bSJohan Hovold 		ctrl |= KSZPHY_RMII_REF_CLK_SEL;
19563f44b2bSJohan Hovold 	else
19663f44b2bSJohan Hovold 		ctrl &= ~KSZPHY_RMII_REF_CLK_SEL;
19763f44b2bSJohan Hovold 
19863f44b2bSJohan Hovold 	return phy_write(phydev, MII_KSZPHY_CTRL, ctrl);
19963f44b2bSJohan Hovold }
20063f44b2bSJohan Hovold 
201e7a792e9SJohan Hovold static int kszphy_setup_led(struct phy_device *phydev, u32 reg, int val)
20220d8435aSBen Dooks {
2035a16778eSJohan Hovold 	int rc, temp, shift;
2048620546cSJohan Hovold 
2055a16778eSJohan Hovold 	switch (reg) {
2065a16778eSJohan Hovold 	case MII_KSZPHY_CTRL_1:
2075a16778eSJohan Hovold 		shift = 14;
2085a16778eSJohan Hovold 		break;
2095a16778eSJohan Hovold 	case MII_KSZPHY_CTRL_2:
2105a16778eSJohan Hovold 		shift = 4;
2115a16778eSJohan Hovold 		break;
2125a16778eSJohan Hovold 	default:
2135a16778eSJohan Hovold 		return -EINVAL;
2145a16778eSJohan Hovold 	}
2155a16778eSJohan Hovold 
21620d8435aSBen Dooks 	temp = phy_read(phydev, reg);
217b7035860SJohan Hovold 	if (temp < 0) {
218b7035860SJohan Hovold 		rc = temp;
219b7035860SJohan Hovold 		goto out;
220b7035860SJohan Hovold 	}
22120d8435aSBen Dooks 
22228bdc499SSergei Shtylyov 	temp &= ~(3 << shift);
22320d8435aSBen Dooks 	temp |= val << shift;
22420d8435aSBen Dooks 	rc = phy_write(phydev, reg, temp);
225b7035860SJohan Hovold out:
226b7035860SJohan Hovold 	if (rc < 0)
22772ba48beSAndrew Lunn 		phydev_err(phydev, "failed to set led mode\n");
22820d8435aSBen Dooks 
229b7035860SJohan Hovold 	return rc;
23020d8435aSBen Dooks }
23120d8435aSBen Dooks 
232bde15129SJohan Hovold /* Disable PHY address 0 as the broadcast address, so that it can be used as a
233bde15129SJohan Hovold  * unique (non-broadcast) address on a shared bus.
234bde15129SJohan Hovold  */
235bde15129SJohan Hovold static int kszphy_broadcast_disable(struct phy_device *phydev)
236bde15129SJohan Hovold {
237bde15129SJohan Hovold 	int ret;
238bde15129SJohan Hovold 
239bde15129SJohan Hovold 	ret = phy_read(phydev, MII_KSZPHY_OMSO);
240bde15129SJohan Hovold 	if (ret < 0)
241bde15129SJohan Hovold 		goto out;
242bde15129SJohan Hovold 
243bde15129SJohan Hovold 	ret = phy_write(phydev, MII_KSZPHY_OMSO, ret | KSZPHY_OMSO_B_CAST_OFF);
244bde15129SJohan Hovold out:
245bde15129SJohan Hovold 	if (ret)
24672ba48beSAndrew Lunn 		phydev_err(phydev, "failed to disable broadcast address\n");
247bde15129SJohan Hovold 
248bde15129SJohan Hovold 	return ret;
249bde15129SJohan Hovold }
250bde15129SJohan Hovold 
2512b0ba96cSSylvain Rochet static int kszphy_nand_tree_disable(struct phy_device *phydev)
2522b0ba96cSSylvain Rochet {
2532b0ba96cSSylvain Rochet 	int ret;
2542b0ba96cSSylvain Rochet 
2552b0ba96cSSylvain Rochet 	ret = phy_read(phydev, MII_KSZPHY_OMSO);
2562b0ba96cSSylvain Rochet 	if (ret < 0)
2572b0ba96cSSylvain Rochet 		goto out;
2582b0ba96cSSylvain Rochet 
2592b0ba96cSSylvain Rochet 	if (!(ret & KSZPHY_OMSO_NAND_TREE_ON))
2602b0ba96cSSylvain Rochet 		return 0;
2612b0ba96cSSylvain Rochet 
2622b0ba96cSSylvain Rochet 	ret = phy_write(phydev, MII_KSZPHY_OMSO,
2632b0ba96cSSylvain Rochet 			ret & ~KSZPHY_OMSO_NAND_TREE_ON);
2642b0ba96cSSylvain Rochet out:
2652b0ba96cSSylvain Rochet 	if (ret)
26672ba48beSAndrew Lunn 		phydev_err(phydev, "failed to disable NAND tree mode\n");
2672b0ba96cSSylvain Rochet 
2682b0ba96cSSylvain Rochet 	return ret;
2692b0ba96cSSylvain Rochet }
2702b0ba96cSSylvain Rochet 
271d0507009SDavid J. Choi static int kszphy_config_init(struct phy_device *phydev)
272d0507009SDavid J. Choi {
273e6a423a8SJohan Hovold 	struct kszphy_priv *priv = phydev->priv;
274e6a423a8SJohan Hovold 	const struct kszphy_type *type;
27563f44b2bSJohan Hovold 	int ret;
276d0507009SDavid J. Choi 
277e6a423a8SJohan Hovold 	if (!priv)
278e6a423a8SJohan Hovold 		return 0;
279e6a423a8SJohan Hovold 
280e6a423a8SJohan Hovold 	type = priv->type;
281e6a423a8SJohan Hovold 
2820f95903eSJohan Hovold 	if (type->has_broadcast_disable)
2830f95903eSJohan Hovold 		kszphy_broadcast_disable(phydev);
2840f95903eSJohan Hovold 
2852b0ba96cSSylvain Rochet 	if (type->has_nand_tree_disable)
2862b0ba96cSSylvain Rochet 		kszphy_nand_tree_disable(phydev);
2872b0ba96cSSylvain Rochet 
28863f44b2bSJohan Hovold 	if (priv->rmii_ref_clk_sel) {
28963f44b2bSJohan Hovold 		ret = kszphy_rmii_clk_sel(phydev, priv->rmii_ref_clk_sel_val);
29063f44b2bSJohan Hovold 		if (ret) {
29172ba48beSAndrew Lunn 			phydev_err(phydev,
29272ba48beSAndrew Lunn 				   "failed to set rmii reference clock\n");
29363f44b2bSJohan Hovold 			return ret;
29463f44b2bSJohan Hovold 		}
29563f44b2bSJohan Hovold 	}
29663f44b2bSJohan Hovold 
297e7a792e9SJohan Hovold 	if (priv->led_mode >= 0)
298e7a792e9SJohan Hovold 		kszphy_setup_led(phydev, type->led_mode_reg, priv->led_mode);
299e6a423a8SJohan Hovold 
30099f81afcSAlexandre Belloni 	if (phy_interrupt_is_valid(phydev)) {
30199f81afcSAlexandre Belloni 		int ctl = phy_read(phydev, MII_BMCR);
30299f81afcSAlexandre Belloni 
30399f81afcSAlexandre Belloni 		if (ctl < 0)
30499f81afcSAlexandre Belloni 			return ctl;
30599f81afcSAlexandre Belloni 
30699f81afcSAlexandre Belloni 		ret = phy_write(phydev, MII_BMCR, ctl & ~BMCR_ANENABLE);
30799f81afcSAlexandre Belloni 		if (ret < 0)
30899f81afcSAlexandre Belloni 			return ret;
30999f81afcSAlexandre Belloni 	}
31099f81afcSAlexandre Belloni 
311e6a423a8SJohan Hovold 	return 0;
31220d8435aSBen Dooks }
31320d8435aSBen Dooks 
31477501a79SPhilipp Zabel static int ksz8041_config_init(struct phy_device *phydev)
31577501a79SPhilipp Zabel {
31677501a79SPhilipp Zabel 	struct device_node *of_node = phydev->mdio.dev.of_node;
31777501a79SPhilipp Zabel 
31877501a79SPhilipp Zabel 	/* Limit supported and advertised modes in fiber mode */
31977501a79SPhilipp Zabel 	if (of_property_read_bool(of_node, "micrel,fiber-mode")) {
32077501a79SPhilipp Zabel 		phydev->dev_flags |= MICREL_PHY_FXEN;
32177501a79SPhilipp Zabel 		phydev->supported &= SUPPORTED_FIBRE |
32277501a79SPhilipp Zabel 				     SUPPORTED_100baseT_Full |
32377501a79SPhilipp Zabel 				     SUPPORTED_100baseT_Half;
32477501a79SPhilipp Zabel 		phydev->advertising &= ADVERTISED_FIBRE |
32577501a79SPhilipp Zabel 				       ADVERTISED_100baseT_Full |
32677501a79SPhilipp Zabel 				       ADVERTISED_100baseT_Half;
32777501a79SPhilipp Zabel 		phydev->autoneg = AUTONEG_DISABLE;
32877501a79SPhilipp Zabel 	}
32977501a79SPhilipp Zabel 
33077501a79SPhilipp Zabel 	return kszphy_config_init(phydev);
33177501a79SPhilipp Zabel }
33277501a79SPhilipp Zabel 
33377501a79SPhilipp Zabel static int ksz8041_config_aneg(struct phy_device *phydev)
33477501a79SPhilipp Zabel {
33577501a79SPhilipp Zabel 	/* Skip auto-negotiation in fiber mode */
33677501a79SPhilipp Zabel 	if (phydev->dev_flags & MICREL_PHY_FXEN) {
33777501a79SPhilipp Zabel 		phydev->speed = SPEED_100;
33877501a79SPhilipp Zabel 		return 0;
33977501a79SPhilipp Zabel 	}
34077501a79SPhilipp Zabel 
34177501a79SPhilipp Zabel 	return genphy_config_aneg(phydev);
34277501a79SPhilipp Zabel }
34377501a79SPhilipp Zabel 
344954c3967SSean Cross static int ksz9021_load_values_from_of(struct phy_device *phydev,
3453c9a9f7fSJaeden Amero 				       const struct device_node *of_node,
3463c9a9f7fSJaeden Amero 				       u16 reg,
3473c9a9f7fSJaeden Amero 				       const char *field1, const char *field2,
3483c9a9f7fSJaeden Amero 				       const char *field3, const char *field4)
349954c3967SSean Cross {
350954c3967SSean Cross 	int val1 = -1;
351954c3967SSean Cross 	int val2 = -2;
352954c3967SSean Cross 	int val3 = -3;
353954c3967SSean Cross 	int val4 = -4;
354954c3967SSean Cross 	int newval;
355954c3967SSean Cross 	int matches = 0;
356954c3967SSean Cross 
357954c3967SSean Cross 	if (!of_property_read_u32(of_node, field1, &val1))
358954c3967SSean Cross 		matches++;
359954c3967SSean Cross 
360954c3967SSean Cross 	if (!of_property_read_u32(of_node, field2, &val2))
361954c3967SSean Cross 		matches++;
362954c3967SSean Cross 
363954c3967SSean Cross 	if (!of_property_read_u32(of_node, field3, &val3))
364954c3967SSean Cross 		matches++;
365954c3967SSean Cross 
366954c3967SSean Cross 	if (!of_property_read_u32(of_node, field4, &val4))
367954c3967SSean Cross 		matches++;
368954c3967SSean Cross 
369954c3967SSean Cross 	if (!matches)
370954c3967SSean Cross 		return 0;
371954c3967SSean Cross 
372954c3967SSean Cross 	if (matches < 4)
373954c3967SSean Cross 		newval = kszphy_extended_read(phydev, reg);
374954c3967SSean Cross 	else
375954c3967SSean Cross 		newval = 0;
376954c3967SSean Cross 
377954c3967SSean Cross 	if (val1 != -1)
378954c3967SSean Cross 		newval = ((newval & 0xfff0) | ((val1 / PS_TO_REG) & 0xf) << 0);
379954c3967SSean Cross 
3806a119745SHubert Chaumette 	if (val2 != -2)
381954c3967SSean Cross 		newval = ((newval & 0xff0f) | ((val2 / PS_TO_REG) & 0xf) << 4);
382954c3967SSean Cross 
3836a119745SHubert Chaumette 	if (val3 != -3)
384954c3967SSean Cross 		newval = ((newval & 0xf0ff) | ((val3 / PS_TO_REG) & 0xf) << 8);
385954c3967SSean Cross 
3866a119745SHubert Chaumette 	if (val4 != -4)
387954c3967SSean Cross 		newval = ((newval & 0x0fff) | ((val4 / PS_TO_REG) & 0xf) << 12);
388954c3967SSean Cross 
389954c3967SSean Cross 	return kszphy_extended_write(phydev, reg, newval);
390954c3967SSean Cross }
391954c3967SSean Cross 
392954c3967SSean Cross static int ksz9021_config_init(struct phy_device *phydev)
393954c3967SSean Cross {
394e5a03bfdSAndrew Lunn 	const struct device *dev = &phydev->mdio.dev;
3953c9a9f7fSJaeden Amero 	const struct device_node *of_node = dev->of_node;
396651df218SAndrew Lunn 	const struct device *dev_walker;
397954c3967SSean Cross 
398651df218SAndrew Lunn 	/* The Micrel driver has a deprecated option to place phy OF
399651df218SAndrew Lunn 	 * properties in the MAC node. Walk up the tree of devices to
400651df218SAndrew Lunn 	 * find a device with an OF node.
401651df218SAndrew Lunn 	 */
402e5a03bfdSAndrew Lunn 	dev_walker = &phydev->mdio.dev;
403651df218SAndrew Lunn 	do {
404651df218SAndrew Lunn 		of_node = dev_walker->of_node;
405651df218SAndrew Lunn 		dev_walker = dev_walker->parent;
406651df218SAndrew Lunn 
407651df218SAndrew Lunn 	} while (!of_node && dev_walker);
408954c3967SSean Cross 
409954c3967SSean Cross 	if (of_node) {
410954c3967SSean Cross 		ksz9021_load_values_from_of(phydev, of_node,
411954c3967SSean Cross 				    MII_KSZPHY_CLK_CONTROL_PAD_SKEW,
412954c3967SSean Cross 				    "txen-skew-ps", "txc-skew-ps",
413954c3967SSean Cross 				    "rxdv-skew-ps", "rxc-skew-ps");
414954c3967SSean Cross 		ksz9021_load_values_from_of(phydev, of_node,
415954c3967SSean Cross 				    MII_KSZPHY_RX_DATA_PAD_SKEW,
416954c3967SSean Cross 				    "rxd0-skew-ps", "rxd1-skew-ps",
417954c3967SSean Cross 				    "rxd2-skew-ps", "rxd3-skew-ps");
418954c3967SSean Cross 		ksz9021_load_values_from_of(phydev, of_node,
419954c3967SSean Cross 				    MII_KSZPHY_TX_DATA_PAD_SKEW,
420954c3967SSean Cross 				    "txd0-skew-ps", "txd1-skew-ps",
421954c3967SSean Cross 				    "txd2-skew-ps", "txd3-skew-ps");
422954c3967SSean Cross 	}
423954c3967SSean Cross 	return 0;
424954c3967SSean Cross }
425954c3967SSean Cross 
4266e4b8273SHubert Chaumette #define MII_KSZ9031RN_MMD_CTRL_REG	0x0d
4276e4b8273SHubert Chaumette #define MII_KSZ9031RN_MMD_REGDATA_REG	0x0e
4286e4b8273SHubert Chaumette #define OP_DATA				1
4296e4b8273SHubert Chaumette #define KSZ9031_PS_TO_REG		60
4306e4b8273SHubert Chaumette 
4316e4b8273SHubert Chaumette /* Extended registers */
4326270e1aeSJaeden Amero /* MMD Address 0x0 */
4336270e1aeSJaeden Amero #define MII_KSZ9031RN_FLP_BURST_TX_LO	3
4346270e1aeSJaeden Amero #define MII_KSZ9031RN_FLP_BURST_TX_HI	4
4356270e1aeSJaeden Amero 
436ae6c97bbSJaeden Amero /* MMD Address 0x2 */
4376e4b8273SHubert Chaumette #define MII_KSZ9031RN_CONTROL_PAD_SKEW	4
4386e4b8273SHubert Chaumette #define MII_KSZ9031RN_RX_DATA_PAD_SKEW	5
4396e4b8273SHubert Chaumette #define MII_KSZ9031RN_TX_DATA_PAD_SKEW	6
4406e4b8273SHubert Chaumette #define MII_KSZ9031RN_CLK_PAD_SKEW	8
4416e4b8273SHubert Chaumette 
4426e4b8273SHubert Chaumette static int ksz9031_extended_write(struct phy_device *phydev,
4436e4b8273SHubert Chaumette 				  u8 mode, u32 dev_addr, u32 regnum, u16 val)
4446e4b8273SHubert Chaumette {
4456e4b8273SHubert Chaumette 	phy_write(phydev, MII_KSZ9031RN_MMD_CTRL_REG, dev_addr);
4466e4b8273SHubert Chaumette 	phy_write(phydev, MII_KSZ9031RN_MMD_REGDATA_REG, regnum);
4476e4b8273SHubert Chaumette 	phy_write(phydev, MII_KSZ9031RN_MMD_CTRL_REG, (mode << 14) | dev_addr);
4486e4b8273SHubert Chaumette 	return phy_write(phydev, MII_KSZ9031RN_MMD_REGDATA_REG, val);
4496e4b8273SHubert Chaumette }
4506e4b8273SHubert Chaumette 
4516e4b8273SHubert Chaumette static int ksz9031_extended_read(struct phy_device *phydev,
4526e4b8273SHubert Chaumette 				 u8 mode, u32 dev_addr, u32 regnum)
4536e4b8273SHubert Chaumette {
4546e4b8273SHubert Chaumette 	phy_write(phydev, MII_KSZ9031RN_MMD_CTRL_REG, dev_addr);
4556e4b8273SHubert Chaumette 	phy_write(phydev, MII_KSZ9031RN_MMD_REGDATA_REG, regnum);
4566e4b8273SHubert Chaumette 	phy_write(phydev, MII_KSZ9031RN_MMD_CTRL_REG, (mode << 14) | dev_addr);
4576e4b8273SHubert Chaumette 	return phy_read(phydev, MII_KSZ9031RN_MMD_REGDATA_REG);
4586e4b8273SHubert Chaumette }
4596e4b8273SHubert Chaumette 
4606e4b8273SHubert Chaumette static int ksz9031_of_load_skew_values(struct phy_device *phydev,
4613c9a9f7fSJaeden Amero 				       const struct device_node *of_node,
4626e4b8273SHubert Chaumette 				       u16 reg, size_t field_sz,
4633c9a9f7fSJaeden Amero 				       const char *field[], u8 numfields)
4646e4b8273SHubert Chaumette {
4656e4b8273SHubert Chaumette 	int val[4] = {-1, -2, -3, -4};
4666e4b8273SHubert Chaumette 	int matches = 0;
4676e4b8273SHubert Chaumette 	u16 mask;
4686e4b8273SHubert Chaumette 	u16 maxval;
4696e4b8273SHubert Chaumette 	u16 newval;
4706e4b8273SHubert Chaumette 	int i;
4716e4b8273SHubert Chaumette 
4726e4b8273SHubert Chaumette 	for (i = 0; i < numfields; i++)
4736e4b8273SHubert Chaumette 		if (!of_property_read_u32(of_node, field[i], val + i))
4746e4b8273SHubert Chaumette 			matches++;
4756e4b8273SHubert Chaumette 
4766e4b8273SHubert Chaumette 	if (!matches)
4776e4b8273SHubert Chaumette 		return 0;
4786e4b8273SHubert Chaumette 
4796e4b8273SHubert Chaumette 	if (matches < numfields)
4806e4b8273SHubert Chaumette 		newval = ksz9031_extended_read(phydev, OP_DATA, 2, reg);
4816e4b8273SHubert Chaumette 	else
4826e4b8273SHubert Chaumette 		newval = 0;
4836e4b8273SHubert Chaumette 
4846e4b8273SHubert Chaumette 	maxval = (field_sz == 4) ? 0xf : 0x1f;
4856e4b8273SHubert Chaumette 	for (i = 0; i < numfields; i++)
4866e4b8273SHubert Chaumette 		if (val[i] != -(i + 1)) {
4876e4b8273SHubert Chaumette 			mask = 0xffff;
4886e4b8273SHubert Chaumette 			mask ^= maxval << (field_sz * i);
4896e4b8273SHubert Chaumette 			newval = (newval & mask) |
4906e4b8273SHubert Chaumette 				(((val[i] / KSZ9031_PS_TO_REG) & maxval)
4916e4b8273SHubert Chaumette 					<< (field_sz * i));
4926e4b8273SHubert Chaumette 		}
4936e4b8273SHubert Chaumette 
4946e4b8273SHubert Chaumette 	return ksz9031_extended_write(phydev, OP_DATA, 2, reg, newval);
4956e4b8273SHubert Chaumette }
4966e4b8273SHubert Chaumette 
4976270e1aeSJaeden Amero static int ksz9031_center_flp_timing(struct phy_device *phydev)
4986270e1aeSJaeden Amero {
4996270e1aeSJaeden Amero 	int result;
5006270e1aeSJaeden Amero 
5016270e1aeSJaeden Amero 	/* Center KSZ9031RNX FLP timing at 16ms. */
5026270e1aeSJaeden Amero 	result = ksz9031_extended_write(phydev, OP_DATA, 0,
5036270e1aeSJaeden Amero 					MII_KSZ9031RN_FLP_BURST_TX_HI, 0x0006);
5046270e1aeSJaeden Amero 	result = ksz9031_extended_write(phydev, OP_DATA, 0,
5056270e1aeSJaeden Amero 					MII_KSZ9031RN_FLP_BURST_TX_LO, 0x1A80);
5066270e1aeSJaeden Amero 
5076270e1aeSJaeden Amero 	if (result)
5086270e1aeSJaeden Amero 		return result;
5096270e1aeSJaeden Amero 
5106270e1aeSJaeden Amero 	return genphy_restart_aneg(phydev);
5116270e1aeSJaeden Amero }
5126270e1aeSJaeden Amero 
5136e4b8273SHubert Chaumette static int ksz9031_config_init(struct phy_device *phydev)
5146e4b8273SHubert Chaumette {
515e5a03bfdSAndrew Lunn 	const struct device *dev = &phydev->mdio.dev;
5163c9a9f7fSJaeden Amero 	const struct device_node *of_node = dev->of_node;
5173c9a9f7fSJaeden Amero 	static const char *clk_skews[2] = {"rxc-skew-ps", "txc-skew-ps"};
5183c9a9f7fSJaeden Amero 	static const char *rx_data_skews[4] = {
5196e4b8273SHubert Chaumette 		"rxd0-skew-ps", "rxd1-skew-ps",
5206e4b8273SHubert Chaumette 		"rxd2-skew-ps", "rxd3-skew-ps"
5216e4b8273SHubert Chaumette 	};
5223c9a9f7fSJaeden Amero 	static const char *tx_data_skews[4] = {
5236e4b8273SHubert Chaumette 		"txd0-skew-ps", "txd1-skew-ps",
5246e4b8273SHubert Chaumette 		"txd2-skew-ps", "txd3-skew-ps"
5256e4b8273SHubert Chaumette 	};
5263c9a9f7fSJaeden Amero 	static const char *control_skews[2] = {"txen-skew-ps", "rxdv-skew-ps"};
527b4c19f71SRoosen Henri 	const struct device *dev_walker;
5286e4b8273SHubert Chaumette 
529b4c19f71SRoosen Henri 	/* The Micrel driver has a deprecated option to place phy OF
530b4c19f71SRoosen Henri 	 * properties in the MAC node. Walk up the tree of devices to
531b4c19f71SRoosen Henri 	 * find a device with an OF node.
532b4c19f71SRoosen Henri 	 */
5339d367eddSDavid S. Miller 	dev_walker = &phydev->mdio.dev;
534b4c19f71SRoosen Henri 	do {
535b4c19f71SRoosen Henri 		of_node = dev_walker->of_node;
536b4c19f71SRoosen Henri 		dev_walker = dev_walker->parent;
537b4c19f71SRoosen Henri 	} while (!of_node && dev_walker);
5386e4b8273SHubert Chaumette 
5396e4b8273SHubert Chaumette 	if (of_node) {
5406e4b8273SHubert Chaumette 		ksz9031_of_load_skew_values(phydev, of_node,
5416e4b8273SHubert Chaumette 				MII_KSZ9031RN_CLK_PAD_SKEW, 5,
5426e4b8273SHubert Chaumette 				clk_skews, 2);
5436e4b8273SHubert Chaumette 
5446e4b8273SHubert Chaumette 		ksz9031_of_load_skew_values(phydev, of_node,
5456e4b8273SHubert Chaumette 				MII_KSZ9031RN_CONTROL_PAD_SKEW, 4,
5466e4b8273SHubert Chaumette 				control_skews, 2);
5476e4b8273SHubert Chaumette 
5486e4b8273SHubert Chaumette 		ksz9031_of_load_skew_values(phydev, of_node,
5496e4b8273SHubert Chaumette 				MII_KSZ9031RN_RX_DATA_PAD_SKEW, 4,
5506e4b8273SHubert Chaumette 				rx_data_skews, 4);
5516e4b8273SHubert Chaumette 
5526e4b8273SHubert Chaumette 		ksz9031_of_load_skew_values(phydev, of_node,
5536e4b8273SHubert Chaumette 				MII_KSZ9031RN_TX_DATA_PAD_SKEW, 4,
5546e4b8273SHubert Chaumette 				tx_data_skews, 4);
5556e4b8273SHubert Chaumette 	}
5566270e1aeSJaeden Amero 
5576270e1aeSJaeden Amero 	return ksz9031_center_flp_timing(phydev);
5586e4b8273SHubert Chaumette }
5596e4b8273SHubert Chaumette 
56093272e07SJean-Christophe PLAGNIOL-VILLARD #define KSZ8873MLL_GLOBAL_CONTROL_4	0x06
56100aee095SJohan Hovold #define KSZ8873MLL_GLOBAL_CONTROL_4_DUPLEX	BIT(6)
56200aee095SJohan Hovold #define KSZ8873MLL_GLOBAL_CONTROL_4_SPEED	BIT(4)
56332d73b14SJingoo Han static int ksz8873mll_read_status(struct phy_device *phydev)
56493272e07SJean-Christophe PLAGNIOL-VILLARD {
56593272e07SJean-Christophe PLAGNIOL-VILLARD 	int regval;
56693272e07SJean-Christophe PLAGNIOL-VILLARD 
56793272e07SJean-Christophe PLAGNIOL-VILLARD 	/* dummy read */
56893272e07SJean-Christophe PLAGNIOL-VILLARD 	regval = phy_read(phydev, KSZ8873MLL_GLOBAL_CONTROL_4);
56993272e07SJean-Christophe PLAGNIOL-VILLARD 
57093272e07SJean-Christophe PLAGNIOL-VILLARD 	regval = phy_read(phydev, KSZ8873MLL_GLOBAL_CONTROL_4);
57193272e07SJean-Christophe PLAGNIOL-VILLARD 
57293272e07SJean-Christophe PLAGNIOL-VILLARD 	if (regval & KSZ8873MLL_GLOBAL_CONTROL_4_DUPLEX)
57393272e07SJean-Christophe PLAGNIOL-VILLARD 		phydev->duplex = DUPLEX_HALF;
57493272e07SJean-Christophe PLAGNIOL-VILLARD 	else
57593272e07SJean-Christophe PLAGNIOL-VILLARD 		phydev->duplex = DUPLEX_FULL;
57693272e07SJean-Christophe PLAGNIOL-VILLARD 
57793272e07SJean-Christophe PLAGNIOL-VILLARD 	if (regval & KSZ8873MLL_GLOBAL_CONTROL_4_SPEED)
57893272e07SJean-Christophe PLAGNIOL-VILLARD 		phydev->speed = SPEED_10;
57993272e07SJean-Christophe PLAGNIOL-VILLARD 	else
58093272e07SJean-Christophe PLAGNIOL-VILLARD 		phydev->speed = SPEED_100;
58193272e07SJean-Christophe PLAGNIOL-VILLARD 
58293272e07SJean-Christophe PLAGNIOL-VILLARD 	phydev->link = 1;
58393272e07SJean-Christophe PLAGNIOL-VILLARD 	phydev->pause = phydev->asym_pause = 0;
58493272e07SJean-Christophe PLAGNIOL-VILLARD 
58593272e07SJean-Christophe PLAGNIOL-VILLARD 	return 0;
58693272e07SJean-Christophe PLAGNIOL-VILLARD }
58793272e07SJean-Christophe PLAGNIOL-VILLARD 
588d2fd719bSNathan Sullivan static int ksz9031_read_status(struct phy_device *phydev)
589d2fd719bSNathan Sullivan {
590d2fd719bSNathan Sullivan 	int err;
591d2fd719bSNathan Sullivan 	int regval;
592d2fd719bSNathan Sullivan 
593d2fd719bSNathan Sullivan 	err = genphy_read_status(phydev);
594d2fd719bSNathan Sullivan 	if (err)
595d2fd719bSNathan Sullivan 		return err;
596d2fd719bSNathan Sullivan 
597d2fd719bSNathan Sullivan 	/* Make sure the PHY is not broken. Read idle error count,
598d2fd719bSNathan Sullivan 	 * and reset the PHY if it is maxed out.
599d2fd719bSNathan Sullivan 	 */
600d2fd719bSNathan Sullivan 	regval = phy_read(phydev, MII_STAT1000);
601d2fd719bSNathan Sullivan 	if ((regval & 0xFF) == 0xFF) {
602d2fd719bSNathan Sullivan 		phy_init_hw(phydev);
603d2fd719bSNathan Sullivan 		phydev->link = 0;
604d2fd719bSNathan Sullivan 	}
605d2fd719bSNathan Sullivan 
606d2fd719bSNathan Sullivan 	return 0;
607d2fd719bSNathan Sullivan }
608d2fd719bSNathan Sullivan 
60993272e07SJean-Christophe PLAGNIOL-VILLARD static int ksz8873mll_config_aneg(struct phy_device *phydev)
61093272e07SJean-Christophe PLAGNIOL-VILLARD {
61193272e07SJean-Christophe PLAGNIOL-VILLARD 	return 0;
61293272e07SJean-Christophe PLAGNIOL-VILLARD }
61393272e07SJean-Christophe PLAGNIOL-VILLARD 
61419936942SVince Bridgers /* This routine returns -1 as an indication to the caller that the
61519936942SVince Bridgers  * Micrel ksz9021 10/100/1000 PHY does not support standard IEEE
61619936942SVince Bridgers  * MMD extended PHY registers.
61719936942SVince Bridgers  */
61819936942SVince Bridgers static int
61919936942SVince Bridgers ksz9021_rd_mmd_phyreg(struct phy_device *phydev, int ptrad, int devnum,
62019936942SVince Bridgers 		      int regnum)
62119936942SVince Bridgers {
62219936942SVince Bridgers 	return -1;
62319936942SVince Bridgers }
62419936942SVince Bridgers 
62519936942SVince Bridgers /* This routine does nothing since the Micrel ksz9021 does not support
62619936942SVince Bridgers  * standard IEEE MMD extended PHY registers.
62719936942SVince Bridgers  */
62819936942SVince Bridgers static void
62919936942SVince Bridgers ksz9021_wr_mmd_phyreg(struct phy_device *phydev, int ptrad, int devnum,
63019936942SVince Bridgers 		      int regnum, u32 val)
63119936942SVince Bridgers {
63219936942SVince Bridgers }
63319936942SVince Bridgers 
6342b2427d0SAndrew Lunn static int kszphy_get_sset_count(struct phy_device *phydev)
6352b2427d0SAndrew Lunn {
6362b2427d0SAndrew Lunn 	return ARRAY_SIZE(kszphy_hw_stats);
6372b2427d0SAndrew Lunn }
6382b2427d0SAndrew Lunn 
6392b2427d0SAndrew Lunn static void kszphy_get_strings(struct phy_device *phydev, u8 *data)
6402b2427d0SAndrew Lunn {
6412b2427d0SAndrew Lunn 	int i;
6422b2427d0SAndrew Lunn 
6432b2427d0SAndrew Lunn 	for (i = 0; i < ARRAY_SIZE(kszphy_hw_stats); i++) {
6442b2427d0SAndrew Lunn 		memcpy(data + i * ETH_GSTRING_LEN,
6452b2427d0SAndrew Lunn 		       kszphy_hw_stats[i].string, ETH_GSTRING_LEN);
6462b2427d0SAndrew Lunn 	}
6472b2427d0SAndrew Lunn }
6482b2427d0SAndrew Lunn 
6492b2427d0SAndrew Lunn #ifndef UINT64_MAX
6502b2427d0SAndrew Lunn #define UINT64_MAX              (u64)(~((u64)0))
6512b2427d0SAndrew Lunn #endif
6522b2427d0SAndrew Lunn static u64 kszphy_get_stat(struct phy_device *phydev, int i)
6532b2427d0SAndrew Lunn {
6542b2427d0SAndrew Lunn 	struct kszphy_hw_stat stat = kszphy_hw_stats[i];
6552b2427d0SAndrew Lunn 	struct kszphy_priv *priv = phydev->priv;
656321b4d4bSAndrew Lunn 	int val;
657321b4d4bSAndrew Lunn 	u64 ret;
6582b2427d0SAndrew Lunn 
6592b2427d0SAndrew Lunn 	val = phy_read(phydev, stat.reg);
6602b2427d0SAndrew Lunn 	if (val < 0) {
661321b4d4bSAndrew Lunn 		ret = UINT64_MAX;
6622b2427d0SAndrew Lunn 	} else {
6632b2427d0SAndrew Lunn 		val = val & ((1 << stat.bits) - 1);
6642b2427d0SAndrew Lunn 		priv->stats[i] += val;
665321b4d4bSAndrew Lunn 		ret = priv->stats[i];
6662b2427d0SAndrew Lunn 	}
6672b2427d0SAndrew Lunn 
668321b4d4bSAndrew Lunn 	return ret;
6692b2427d0SAndrew Lunn }
6702b2427d0SAndrew Lunn 
6712b2427d0SAndrew Lunn static void kszphy_get_stats(struct phy_device *phydev,
6722b2427d0SAndrew Lunn 			     struct ethtool_stats *stats, u64 *data)
6732b2427d0SAndrew Lunn {
6742b2427d0SAndrew Lunn 	int i;
6752b2427d0SAndrew Lunn 
6762b2427d0SAndrew Lunn 	for (i = 0; i < ARRAY_SIZE(kszphy_hw_stats); i++)
6772b2427d0SAndrew Lunn 		data[i] = kszphy_get_stat(phydev, i);
6782b2427d0SAndrew Lunn }
6792b2427d0SAndrew Lunn 
680*836384d2SWenyou Yang static int kszphy_suspend(struct phy_device *phydev)
681*836384d2SWenyou Yang {
682*836384d2SWenyou Yang 	/* Disable PHY Interrupts */
683*836384d2SWenyou Yang 	if (phy_interrupt_is_valid(phydev)) {
684*836384d2SWenyou Yang 		phydev->interrupts = PHY_INTERRUPT_DISABLED;
685*836384d2SWenyou Yang 		if (phydev->drv->config_intr)
686*836384d2SWenyou Yang 			phydev->drv->config_intr(phydev);
687*836384d2SWenyou Yang 	}
688*836384d2SWenyou Yang 
689*836384d2SWenyou Yang 	return genphy_suspend(phydev);
690*836384d2SWenyou Yang }
691*836384d2SWenyou Yang 
692f5aba91dSAlexandre Belloni static int kszphy_resume(struct phy_device *phydev)
693f5aba91dSAlexandre Belloni {
694*836384d2SWenyou Yang 	genphy_resume(phydev);
695f5aba91dSAlexandre Belloni 
696*836384d2SWenyou Yang 	/* Enable PHY Interrupts */
697*836384d2SWenyou Yang 	if (phy_interrupt_is_valid(phydev)) {
698*836384d2SWenyou Yang 		phydev->interrupts = PHY_INTERRUPT_ENABLED;
699*836384d2SWenyou Yang 		if (phydev->drv->config_intr)
700*836384d2SWenyou Yang 			phydev->drv->config_intr(phydev);
701*836384d2SWenyou Yang 	}
702f5aba91dSAlexandre Belloni 
703f5aba91dSAlexandre Belloni 	return 0;
704f5aba91dSAlexandre Belloni }
705f5aba91dSAlexandre Belloni 
706e6a423a8SJohan Hovold static int kszphy_probe(struct phy_device *phydev)
707e6a423a8SJohan Hovold {
708e6a423a8SJohan Hovold 	const struct kszphy_type *type = phydev->drv->driver_data;
709e5a03bfdSAndrew Lunn 	const struct device_node *np = phydev->mdio.dev.of_node;
710e6a423a8SJohan Hovold 	struct kszphy_priv *priv;
71163f44b2bSJohan Hovold 	struct clk *clk;
712e7a792e9SJohan Hovold 	int ret;
713e6a423a8SJohan Hovold 
714e5a03bfdSAndrew Lunn 	priv = devm_kzalloc(&phydev->mdio.dev, sizeof(*priv), GFP_KERNEL);
715e6a423a8SJohan Hovold 	if (!priv)
716e6a423a8SJohan Hovold 		return -ENOMEM;
717e6a423a8SJohan Hovold 
718e6a423a8SJohan Hovold 	phydev->priv = priv;
719e6a423a8SJohan Hovold 
720e6a423a8SJohan Hovold 	priv->type = type;
721e6a423a8SJohan Hovold 
722e7a792e9SJohan Hovold 	if (type->led_mode_reg) {
723e7a792e9SJohan Hovold 		ret = of_property_read_u32(np, "micrel,led-mode",
724e7a792e9SJohan Hovold 				&priv->led_mode);
725e7a792e9SJohan Hovold 		if (ret)
726e7a792e9SJohan Hovold 			priv->led_mode = -1;
727e7a792e9SJohan Hovold 
728e7a792e9SJohan Hovold 		if (priv->led_mode > 3) {
72972ba48beSAndrew Lunn 			phydev_err(phydev, "invalid led mode: 0x%02x\n",
730e7a792e9SJohan Hovold 				   priv->led_mode);
731e7a792e9SJohan Hovold 			priv->led_mode = -1;
732e7a792e9SJohan Hovold 		}
733e7a792e9SJohan Hovold 	} else {
734e7a792e9SJohan Hovold 		priv->led_mode = -1;
735e7a792e9SJohan Hovold 	}
736e7a792e9SJohan Hovold 
737e5a03bfdSAndrew Lunn 	clk = devm_clk_get(&phydev->mdio.dev, "rmii-ref");
738bced8701SNiklas Cassel 	/* NOTE: clk may be NULL if building without CONFIG_HAVE_CLK */
739bced8701SNiklas Cassel 	if (!IS_ERR_OR_NULL(clk)) {
7401fadee0cSSascha Hauer 		unsigned long rate = clk_get_rate(clk);
74186dc1342SJohan Hovold 		bool rmii_ref_clk_sel_25_mhz;
7421fadee0cSSascha Hauer 
74363f44b2bSJohan Hovold 		priv->rmii_ref_clk_sel = type->has_rmii_ref_clk_sel;
74486dc1342SJohan Hovold 		rmii_ref_clk_sel_25_mhz = of_property_read_bool(np,
74586dc1342SJohan Hovold 				"micrel,rmii-reference-clock-select-25-mhz");
74663f44b2bSJohan Hovold 
7471fadee0cSSascha Hauer 		if (rate > 24500000 && rate < 25500000) {
74886dc1342SJohan Hovold 			priv->rmii_ref_clk_sel_val = rmii_ref_clk_sel_25_mhz;
7491fadee0cSSascha Hauer 		} else if (rate > 49500000 && rate < 50500000) {
75086dc1342SJohan Hovold 			priv->rmii_ref_clk_sel_val = !rmii_ref_clk_sel_25_mhz;
7511fadee0cSSascha Hauer 		} else {
75272ba48beSAndrew Lunn 			phydev_err(phydev, "Clock rate out of range: %ld\n",
75372ba48beSAndrew Lunn 				   rate);
7541fadee0cSSascha Hauer 			return -EINVAL;
7551fadee0cSSascha Hauer 		}
7561fadee0cSSascha Hauer 	}
7571fadee0cSSascha Hauer 
75863f44b2bSJohan Hovold 	/* Support legacy board-file configuration */
75963f44b2bSJohan Hovold 	if (phydev->dev_flags & MICREL_PHY_50MHZ_CLK) {
76063f44b2bSJohan Hovold 		priv->rmii_ref_clk_sel = true;
76163f44b2bSJohan Hovold 		priv->rmii_ref_clk_sel_val = true;
76263f44b2bSJohan Hovold 	}
76363f44b2bSJohan Hovold 
76463f44b2bSJohan Hovold 	return 0;
7651fadee0cSSascha Hauer }
7661fadee0cSSascha Hauer 
767d5bf9071SChristian Hohnstaedt static struct phy_driver ksphy_driver[] = {
768d5bf9071SChristian Hohnstaedt {
76951f932c4SChoi, David 	.phy_id		= PHY_ID_KS8737,
770f893a99eSFabio Estevam 	.phy_id_mask	= MICREL_PHY_ID_MASK,
77151f932c4SChoi, David 	.name		= "Micrel KS8737",
77251f932c4SChoi, David 	.features	= (PHY_BASIC_FEATURES | SUPPORTED_Pause),
77351f932c4SChoi, David 	.flags		= PHY_HAS_MAGICANEG | PHY_HAS_INTERRUPT,
774c6f9575cSJohan Hovold 	.driver_data	= &ks8737_type,
775d0507009SDavid J. Choi 	.config_init	= kszphy_config_init,
776d0507009SDavid J. Choi 	.config_aneg	= genphy_config_aneg,
777d0507009SDavid J. Choi 	.read_status	= genphy_read_status,
77851f932c4SChoi, David 	.ack_interrupt	= kszphy_ack_interrupt,
779c6f9575cSJohan Hovold 	.config_intr	= kszphy_config_intr,
7802b2427d0SAndrew Lunn 	.get_sset_count = kszphy_get_sset_count,
7812b2427d0SAndrew Lunn 	.get_strings	= kszphy_get_strings,
7822b2427d0SAndrew Lunn 	.get_stats	= kszphy_get_stats,
7831a5465f5SPatrice Vilchez 	.suspend	= genphy_suspend,
7841a5465f5SPatrice Vilchez 	.resume		= genphy_resume,
785d5bf9071SChristian Hohnstaedt }, {
786212ea99aSMarek Vasut 	.phy_id		= PHY_ID_KSZ8021,
787212ea99aSMarek Vasut 	.phy_id_mask	= 0x00ffffff,
7887ab59dc1SDavid J. Choi 	.name		= "Micrel KSZ8021 or KSZ8031",
789212ea99aSMarek Vasut 	.features	= (PHY_BASIC_FEATURES | SUPPORTED_Pause |
790212ea99aSMarek Vasut 			   SUPPORTED_Asym_Pause),
791212ea99aSMarek Vasut 	.flags		= PHY_HAS_MAGICANEG | PHY_HAS_INTERRUPT,
792e6a423a8SJohan Hovold 	.driver_data	= &ksz8021_type,
79363f44b2bSJohan Hovold 	.probe		= kszphy_probe,
794d0e1df9cSJohan Hovold 	.config_init	= kszphy_config_init,
795212ea99aSMarek Vasut 	.config_aneg	= genphy_config_aneg,
796212ea99aSMarek Vasut 	.read_status	= genphy_read_status,
797212ea99aSMarek Vasut 	.ack_interrupt	= kszphy_ack_interrupt,
798212ea99aSMarek Vasut 	.config_intr	= kszphy_config_intr,
7992b2427d0SAndrew Lunn 	.get_sset_count = kszphy_get_sset_count,
8002b2427d0SAndrew Lunn 	.get_strings	= kszphy_get_strings,
8012b2427d0SAndrew Lunn 	.get_stats	= kszphy_get_stats,
8021a5465f5SPatrice Vilchez 	.suspend	= genphy_suspend,
8031a5465f5SPatrice Vilchez 	.resume		= genphy_resume,
804212ea99aSMarek Vasut }, {
805b818d1a7SHector Palacios 	.phy_id		= PHY_ID_KSZ8031,
806b818d1a7SHector Palacios 	.phy_id_mask	= 0x00ffffff,
807b818d1a7SHector Palacios 	.name		= "Micrel KSZ8031",
808b818d1a7SHector Palacios 	.features	= (PHY_BASIC_FEATURES | SUPPORTED_Pause |
809b818d1a7SHector Palacios 			   SUPPORTED_Asym_Pause),
810b818d1a7SHector Palacios 	.flags		= PHY_HAS_MAGICANEG | PHY_HAS_INTERRUPT,
811e6a423a8SJohan Hovold 	.driver_data	= &ksz8021_type,
81263f44b2bSJohan Hovold 	.probe		= kszphy_probe,
813d0e1df9cSJohan Hovold 	.config_init	= kszphy_config_init,
814b818d1a7SHector Palacios 	.config_aneg	= genphy_config_aneg,
815b818d1a7SHector Palacios 	.read_status	= genphy_read_status,
816b818d1a7SHector Palacios 	.ack_interrupt	= kszphy_ack_interrupt,
817b818d1a7SHector Palacios 	.config_intr	= kszphy_config_intr,
8182b2427d0SAndrew Lunn 	.get_sset_count = kszphy_get_sset_count,
8192b2427d0SAndrew Lunn 	.get_strings	= kszphy_get_strings,
8202b2427d0SAndrew Lunn 	.get_stats	= kszphy_get_stats,
8211a5465f5SPatrice Vilchez 	.suspend	= genphy_suspend,
8221a5465f5SPatrice Vilchez 	.resume		= genphy_resume,
823b818d1a7SHector Palacios }, {
824510d573fSMarek Vasut 	.phy_id		= PHY_ID_KSZ8041,
825f893a99eSFabio Estevam 	.phy_id_mask	= MICREL_PHY_ID_MASK,
826510d573fSMarek Vasut 	.name		= "Micrel KSZ8041",
82751f932c4SChoi, David 	.features	= (PHY_BASIC_FEATURES | SUPPORTED_Pause
82851f932c4SChoi, David 				| SUPPORTED_Asym_Pause),
82951f932c4SChoi, David 	.flags		= PHY_HAS_MAGICANEG | PHY_HAS_INTERRUPT,
830e6a423a8SJohan Hovold 	.driver_data	= &ksz8041_type,
831e6a423a8SJohan Hovold 	.probe		= kszphy_probe,
83277501a79SPhilipp Zabel 	.config_init	= ksz8041_config_init,
83377501a79SPhilipp Zabel 	.config_aneg	= ksz8041_config_aneg,
834d0507009SDavid J. Choi 	.read_status	= genphy_read_status,
83551f932c4SChoi, David 	.ack_interrupt	= kszphy_ack_interrupt,
83651f932c4SChoi, David 	.config_intr	= kszphy_config_intr,
8372b2427d0SAndrew Lunn 	.get_sset_count = kszphy_get_sset_count,
8382b2427d0SAndrew Lunn 	.get_strings	= kszphy_get_strings,
8392b2427d0SAndrew Lunn 	.get_stats	= kszphy_get_stats,
8401a5465f5SPatrice Vilchez 	.suspend	= genphy_suspend,
8411a5465f5SPatrice Vilchez 	.resume		= genphy_resume,
842d5bf9071SChristian Hohnstaedt }, {
8434bd7b512SSergei Shtylyov 	.phy_id		= PHY_ID_KSZ8041RNLI,
844f893a99eSFabio Estevam 	.phy_id_mask	= MICREL_PHY_ID_MASK,
8454bd7b512SSergei Shtylyov 	.name		= "Micrel KSZ8041RNLI",
8464bd7b512SSergei Shtylyov 	.features	= PHY_BASIC_FEATURES |
8474bd7b512SSergei Shtylyov 			  SUPPORTED_Pause | SUPPORTED_Asym_Pause,
8484bd7b512SSergei Shtylyov 	.flags		= PHY_HAS_MAGICANEG | PHY_HAS_INTERRUPT,
849e6a423a8SJohan Hovold 	.driver_data	= &ksz8041_type,
850e6a423a8SJohan Hovold 	.probe		= kszphy_probe,
851e6a423a8SJohan Hovold 	.config_init	= kszphy_config_init,
8524bd7b512SSergei Shtylyov 	.config_aneg	= genphy_config_aneg,
8534bd7b512SSergei Shtylyov 	.read_status	= genphy_read_status,
8544bd7b512SSergei Shtylyov 	.ack_interrupt	= kszphy_ack_interrupt,
8554bd7b512SSergei Shtylyov 	.config_intr	= kszphy_config_intr,
8562b2427d0SAndrew Lunn 	.get_sset_count = kszphy_get_sset_count,
8572b2427d0SAndrew Lunn 	.get_strings	= kszphy_get_strings,
8582b2427d0SAndrew Lunn 	.get_stats	= kszphy_get_stats,
8594bd7b512SSergei Shtylyov 	.suspend	= genphy_suspend,
8604bd7b512SSergei Shtylyov 	.resume		= genphy_resume,
8614bd7b512SSergei Shtylyov }, {
862510d573fSMarek Vasut 	.phy_id		= PHY_ID_KSZ8051,
863f893a99eSFabio Estevam 	.phy_id_mask	= MICREL_PHY_ID_MASK,
864510d573fSMarek Vasut 	.name		= "Micrel KSZ8051",
86551f932c4SChoi, David 	.features	= (PHY_BASIC_FEATURES | SUPPORTED_Pause
86651f932c4SChoi, David 				| SUPPORTED_Asym_Pause),
86751f932c4SChoi, David 	.flags		= PHY_HAS_MAGICANEG | PHY_HAS_INTERRUPT,
868e6a423a8SJohan Hovold 	.driver_data	= &ksz8051_type,
869e6a423a8SJohan Hovold 	.probe		= kszphy_probe,
87063f44b2bSJohan Hovold 	.config_init	= kszphy_config_init,
87151f932c4SChoi, David 	.config_aneg	= genphy_config_aneg,
87251f932c4SChoi, David 	.read_status	= genphy_read_status,
87351f932c4SChoi, David 	.ack_interrupt	= kszphy_ack_interrupt,
87451f932c4SChoi, David 	.config_intr	= kszphy_config_intr,
8752b2427d0SAndrew Lunn 	.get_sset_count = kszphy_get_sset_count,
8762b2427d0SAndrew Lunn 	.get_strings	= kszphy_get_strings,
8772b2427d0SAndrew Lunn 	.get_stats	= kszphy_get_stats,
8781a5465f5SPatrice Vilchez 	.suspend	= genphy_suspend,
8791a5465f5SPatrice Vilchez 	.resume		= genphy_resume,
880d5bf9071SChristian Hohnstaedt }, {
881510d573fSMarek Vasut 	.phy_id		= PHY_ID_KSZ8001,
882510d573fSMarek Vasut 	.name		= "Micrel KSZ8001 or KS8721",
883ecd5a323SAlexander Stein 	.phy_id_mask	= 0x00fffffc,
88451f932c4SChoi, David 	.features	= (PHY_BASIC_FEATURES | SUPPORTED_Pause),
88551f932c4SChoi, David 	.flags		= PHY_HAS_MAGICANEG | PHY_HAS_INTERRUPT,
886e6a423a8SJohan Hovold 	.driver_data	= &ksz8041_type,
887e6a423a8SJohan Hovold 	.probe		= kszphy_probe,
888e6a423a8SJohan Hovold 	.config_init	= kszphy_config_init,
88951f932c4SChoi, David 	.config_aneg	= genphy_config_aneg,
89051f932c4SChoi, David 	.read_status	= genphy_read_status,
89151f932c4SChoi, David 	.ack_interrupt	= kszphy_ack_interrupt,
89251f932c4SChoi, David 	.config_intr	= kszphy_config_intr,
8932b2427d0SAndrew Lunn 	.get_sset_count = kszphy_get_sset_count,
8942b2427d0SAndrew Lunn 	.get_strings	= kszphy_get_strings,
8952b2427d0SAndrew Lunn 	.get_stats	= kszphy_get_stats,
8961a5465f5SPatrice Vilchez 	.suspend	= genphy_suspend,
8971a5465f5SPatrice Vilchez 	.resume		= genphy_resume,
898d5bf9071SChristian Hohnstaedt }, {
8997ab59dc1SDavid J. Choi 	.phy_id		= PHY_ID_KSZ8081,
9007ab59dc1SDavid J. Choi 	.name		= "Micrel KSZ8081 or KSZ8091",
901f893a99eSFabio Estevam 	.phy_id_mask	= MICREL_PHY_ID_MASK,
9027ab59dc1SDavid J. Choi 	.features	= (PHY_BASIC_FEATURES | SUPPORTED_Pause),
9037ab59dc1SDavid J. Choi 	.flags		= PHY_HAS_MAGICANEG | PHY_HAS_INTERRUPT,
904e6a423a8SJohan Hovold 	.driver_data	= &ksz8081_type,
905e6a423a8SJohan Hovold 	.probe		= kszphy_probe,
9060f95903eSJohan Hovold 	.config_init	= kszphy_config_init,
9077ab59dc1SDavid J. Choi 	.config_aneg	= genphy_config_aneg,
9087ab59dc1SDavid J. Choi 	.read_status	= genphy_read_status,
9097ab59dc1SDavid J. Choi 	.ack_interrupt	= kszphy_ack_interrupt,
9107ab59dc1SDavid J. Choi 	.config_intr	= kszphy_config_intr,
9112b2427d0SAndrew Lunn 	.get_sset_count = kszphy_get_sset_count,
9122b2427d0SAndrew Lunn 	.get_strings	= kszphy_get_strings,
9132b2427d0SAndrew Lunn 	.get_stats	= kszphy_get_stats,
914*836384d2SWenyou Yang 	.suspend	= kszphy_suspend,
915f5aba91dSAlexandre Belloni 	.resume		= kszphy_resume,
9167ab59dc1SDavid J. Choi }, {
9177ab59dc1SDavid J. Choi 	.phy_id		= PHY_ID_KSZ8061,
9187ab59dc1SDavid J. Choi 	.name		= "Micrel KSZ8061",
919f893a99eSFabio Estevam 	.phy_id_mask	= MICREL_PHY_ID_MASK,
9207ab59dc1SDavid J. Choi 	.features	= (PHY_BASIC_FEATURES | SUPPORTED_Pause),
9217ab59dc1SDavid J. Choi 	.flags		= PHY_HAS_MAGICANEG | PHY_HAS_INTERRUPT,
9227ab59dc1SDavid J. Choi 	.config_init	= kszphy_config_init,
9237ab59dc1SDavid J. Choi 	.config_aneg	= genphy_config_aneg,
9247ab59dc1SDavid J. Choi 	.read_status	= genphy_read_status,
9257ab59dc1SDavid J. Choi 	.ack_interrupt	= kszphy_ack_interrupt,
9267ab59dc1SDavid J. Choi 	.config_intr	= kszphy_config_intr,
9272b2427d0SAndrew Lunn 	.get_sset_count = kszphy_get_sset_count,
9282b2427d0SAndrew Lunn 	.get_strings	= kszphy_get_strings,
9292b2427d0SAndrew Lunn 	.get_stats	= kszphy_get_stats,
9301a5465f5SPatrice Vilchez 	.suspend	= genphy_suspend,
9311a5465f5SPatrice Vilchez 	.resume		= genphy_resume,
9327ab59dc1SDavid J. Choi }, {
933d0507009SDavid J. Choi 	.phy_id		= PHY_ID_KSZ9021,
93448d7d0adSJason Wang 	.phy_id_mask	= 0x000ffffe,
935d0507009SDavid J. Choi 	.name		= "Micrel KSZ9021 Gigabit PHY",
93632fcafbcSVlastimil Kosar 	.features	= (PHY_GBIT_FEATURES | SUPPORTED_Pause),
93751f932c4SChoi, David 	.flags		= PHY_HAS_MAGICANEG | PHY_HAS_INTERRUPT,
938c6f9575cSJohan Hovold 	.driver_data	= &ksz9021_type,
939954c3967SSean Cross 	.config_init	= ksz9021_config_init,
940d0507009SDavid J. Choi 	.config_aneg	= genphy_config_aneg,
941d0507009SDavid J. Choi 	.read_status	= genphy_read_status,
94251f932c4SChoi, David 	.ack_interrupt	= kszphy_ack_interrupt,
943c6f9575cSJohan Hovold 	.config_intr	= kszphy_config_intr,
9442b2427d0SAndrew Lunn 	.get_sset_count = kszphy_get_sset_count,
9452b2427d0SAndrew Lunn 	.get_strings	= kszphy_get_strings,
9462b2427d0SAndrew Lunn 	.get_stats	= kszphy_get_stats,
9471a5465f5SPatrice Vilchez 	.suspend	= genphy_suspend,
9481a5465f5SPatrice Vilchez 	.resume		= genphy_resume,
94919936942SVince Bridgers 	.read_mmd_indirect = ksz9021_rd_mmd_phyreg,
95019936942SVince Bridgers 	.write_mmd_indirect = ksz9021_wr_mmd_phyreg,
95193272e07SJean-Christophe PLAGNIOL-VILLARD }, {
9527ab59dc1SDavid J. Choi 	.phy_id		= PHY_ID_KSZ9031,
953f893a99eSFabio Estevam 	.phy_id_mask	= MICREL_PHY_ID_MASK,
9547ab59dc1SDavid J. Choi 	.name		= "Micrel KSZ9031 Gigabit PHY",
95595e8b103SMike Looijmans 	.features	= (PHY_GBIT_FEATURES | SUPPORTED_Pause),
9567ab59dc1SDavid J. Choi 	.flags		= PHY_HAS_MAGICANEG | PHY_HAS_INTERRUPT,
957c6f9575cSJohan Hovold 	.driver_data	= &ksz9021_type,
9586e4b8273SHubert Chaumette 	.config_init	= ksz9031_config_init,
9597ab59dc1SDavid J. Choi 	.config_aneg	= genphy_config_aneg,
960d2fd719bSNathan Sullivan 	.read_status	= ksz9031_read_status,
9617ab59dc1SDavid J. Choi 	.ack_interrupt	= kszphy_ack_interrupt,
962c6f9575cSJohan Hovold 	.config_intr	= kszphy_config_intr,
9632b2427d0SAndrew Lunn 	.get_sset_count = kszphy_get_sset_count,
9642b2427d0SAndrew Lunn 	.get_strings	= kszphy_get_strings,
9652b2427d0SAndrew Lunn 	.get_stats	= kszphy_get_stats,
9661a5465f5SPatrice Vilchez 	.suspend	= genphy_suspend,
9671a5465f5SPatrice Vilchez 	.resume		= genphy_resume,
9687ab59dc1SDavid J. Choi }, {
96993272e07SJean-Christophe PLAGNIOL-VILLARD 	.phy_id		= PHY_ID_KSZ8873MLL,
970f893a99eSFabio Estevam 	.phy_id_mask	= MICREL_PHY_ID_MASK,
97193272e07SJean-Christophe PLAGNIOL-VILLARD 	.name		= "Micrel KSZ8873MLL Switch",
97293272e07SJean-Christophe PLAGNIOL-VILLARD 	.features	= (SUPPORTED_Pause | SUPPORTED_Asym_Pause),
97393272e07SJean-Christophe PLAGNIOL-VILLARD 	.flags		= PHY_HAS_MAGICANEG,
97493272e07SJean-Christophe PLAGNIOL-VILLARD 	.config_init	= kszphy_config_init,
97593272e07SJean-Christophe PLAGNIOL-VILLARD 	.config_aneg	= ksz8873mll_config_aneg,
97693272e07SJean-Christophe PLAGNIOL-VILLARD 	.read_status	= ksz8873mll_read_status,
9772b2427d0SAndrew Lunn 	.get_sset_count = kszphy_get_sset_count,
9782b2427d0SAndrew Lunn 	.get_strings	= kszphy_get_strings,
9792b2427d0SAndrew Lunn 	.get_stats	= kszphy_get_stats,
9801a5465f5SPatrice Vilchez 	.suspend	= genphy_suspend,
9811a5465f5SPatrice Vilchez 	.resume		= genphy_resume,
9827ab59dc1SDavid J. Choi }, {
9837ab59dc1SDavid J. Choi 	.phy_id		= PHY_ID_KSZ886X,
984f893a99eSFabio Estevam 	.phy_id_mask	= MICREL_PHY_ID_MASK,
9857ab59dc1SDavid J. Choi 	.name		= "Micrel KSZ886X Switch",
9867ab59dc1SDavid J. Choi 	.features	= (PHY_BASIC_FEATURES | SUPPORTED_Pause),
9877ab59dc1SDavid J. Choi 	.flags		= PHY_HAS_MAGICANEG | PHY_HAS_INTERRUPT,
9887ab59dc1SDavid J. Choi 	.config_init	= kszphy_config_init,
9897ab59dc1SDavid J. Choi 	.config_aneg	= genphy_config_aneg,
9907ab59dc1SDavid J. Choi 	.read_status	= genphy_read_status,
9912b2427d0SAndrew Lunn 	.get_sset_count = kszphy_get_sset_count,
9922b2427d0SAndrew Lunn 	.get_strings	= kszphy_get_strings,
9932b2427d0SAndrew Lunn 	.get_stats	= kszphy_get_stats,
9941a5465f5SPatrice Vilchez 	.suspend	= genphy_suspend,
9951a5465f5SPatrice Vilchez 	.resume		= genphy_resume,
996d5bf9071SChristian Hohnstaedt } };
997d0507009SDavid J. Choi 
99850fd7150SJohan Hovold module_phy_driver(ksphy_driver);
999d0507009SDavid J. Choi 
1000d0507009SDavid J. Choi MODULE_DESCRIPTION("Micrel PHY driver");
1001d0507009SDavid J. Choi MODULE_AUTHOR("David J. Choi");
1002d0507009SDavid J. Choi MODULE_LICENSE("GPL");
100352a60ed2SDavid S. Miller 
1004cf93c945SUwe Kleine-König static struct mdio_device_id __maybe_unused micrel_tbl[] = {
100548d7d0adSJason Wang 	{ PHY_ID_KSZ9021, 0x000ffffe },
1006f893a99eSFabio Estevam 	{ PHY_ID_KSZ9031, MICREL_PHY_ID_MASK },
1007ecd5a323SAlexander Stein 	{ PHY_ID_KSZ8001, 0x00fffffc },
1008f893a99eSFabio Estevam 	{ PHY_ID_KS8737, MICREL_PHY_ID_MASK },
1009212ea99aSMarek Vasut 	{ PHY_ID_KSZ8021, 0x00ffffff },
1010b818d1a7SHector Palacios 	{ PHY_ID_KSZ8031, 0x00ffffff },
1011f893a99eSFabio Estevam 	{ PHY_ID_KSZ8041, MICREL_PHY_ID_MASK },
1012f893a99eSFabio Estevam 	{ PHY_ID_KSZ8051, MICREL_PHY_ID_MASK },
1013f893a99eSFabio Estevam 	{ PHY_ID_KSZ8061, MICREL_PHY_ID_MASK },
1014f893a99eSFabio Estevam 	{ PHY_ID_KSZ8081, MICREL_PHY_ID_MASK },
1015f893a99eSFabio Estevam 	{ PHY_ID_KSZ8873MLL, MICREL_PHY_ID_MASK },
1016f893a99eSFabio Estevam 	{ PHY_ID_KSZ886X, MICREL_PHY_ID_MASK },
101752a60ed2SDavid S. Miller 	{ }
101852a60ed2SDavid S. Miller };
101952a60ed2SDavid S. Miller 
102052a60ed2SDavid S. Miller MODULE_DEVICE_TABLE(mdio, micrel_tbl);
1021