xref: /openbmc/linux/drivers/net/phy/micrel.c (revision b866203d872d5deeafcecd25ea429d6748b5bd56)
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 
27179e498a9SLeonard Crestez /* Some config bits need to be set again on resume, handle them here. */
27279e498a9SLeonard Crestez static int kszphy_config_reset(struct phy_device *phydev)
27379e498a9SLeonard Crestez {
27479e498a9SLeonard Crestez 	struct kszphy_priv *priv = phydev->priv;
27579e498a9SLeonard Crestez 	int ret;
27679e498a9SLeonard Crestez 
27779e498a9SLeonard Crestez 	if (priv->rmii_ref_clk_sel) {
27879e498a9SLeonard Crestez 		ret = kszphy_rmii_clk_sel(phydev, priv->rmii_ref_clk_sel_val);
27979e498a9SLeonard Crestez 		if (ret) {
28079e498a9SLeonard Crestez 			phydev_err(phydev,
28179e498a9SLeonard Crestez 				   "failed to set rmii reference clock\n");
28279e498a9SLeonard Crestez 			return ret;
28379e498a9SLeonard Crestez 		}
28479e498a9SLeonard Crestez 	}
28579e498a9SLeonard Crestez 
28679e498a9SLeonard Crestez 	if (priv->led_mode >= 0)
28779e498a9SLeonard Crestez 		kszphy_setup_led(phydev, priv->type->led_mode_reg, priv->led_mode);
28879e498a9SLeonard Crestez 
28979e498a9SLeonard Crestez 	return 0;
29079e498a9SLeonard Crestez }
29179e498a9SLeonard Crestez 
292d0507009SDavid J. Choi static int kszphy_config_init(struct phy_device *phydev)
293d0507009SDavid J. Choi {
294e6a423a8SJohan Hovold 	struct kszphy_priv *priv = phydev->priv;
295e6a423a8SJohan Hovold 	const struct kszphy_type *type;
296d0507009SDavid J. Choi 
297e6a423a8SJohan Hovold 	if (!priv)
298e6a423a8SJohan Hovold 		return 0;
299e6a423a8SJohan Hovold 
300e6a423a8SJohan Hovold 	type = priv->type;
301e6a423a8SJohan Hovold 
3020f95903eSJohan Hovold 	if (type->has_broadcast_disable)
3030f95903eSJohan Hovold 		kszphy_broadcast_disable(phydev);
3040f95903eSJohan Hovold 
3052b0ba96cSSylvain Rochet 	if (type->has_nand_tree_disable)
3062b0ba96cSSylvain Rochet 		kszphy_nand_tree_disable(phydev);
3072b0ba96cSSylvain Rochet 
30879e498a9SLeonard Crestez 	return kszphy_config_reset(phydev);
30920d8435aSBen Dooks }
31020d8435aSBen Dooks 
31177501a79SPhilipp Zabel static int ksz8041_config_init(struct phy_device *phydev)
31277501a79SPhilipp Zabel {
31377501a79SPhilipp Zabel 	struct device_node *of_node = phydev->mdio.dev.of_node;
31477501a79SPhilipp Zabel 
31577501a79SPhilipp Zabel 	/* Limit supported and advertised modes in fiber mode */
31677501a79SPhilipp Zabel 	if (of_property_read_bool(of_node, "micrel,fiber-mode")) {
31777501a79SPhilipp Zabel 		phydev->dev_flags |= MICREL_PHY_FXEN;
318ffa54a23SKirill Esipov 		phydev->supported &= SUPPORTED_100baseT_Full |
31977501a79SPhilipp Zabel 				     SUPPORTED_100baseT_Half;
320ffa54a23SKirill Esipov 		phydev->supported |= SUPPORTED_FIBRE;
321ffa54a23SKirill Esipov 		phydev->advertising &= ADVERTISED_100baseT_Full |
32277501a79SPhilipp Zabel 				       ADVERTISED_100baseT_Half;
323ffa54a23SKirill Esipov 		phydev->advertising |= ADVERTISED_FIBRE;
32477501a79SPhilipp Zabel 		phydev->autoneg = AUTONEG_DISABLE;
32577501a79SPhilipp Zabel 	}
32677501a79SPhilipp Zabel 
32777501a79SPhilipp Zabel 	return kszphy_config_init(phydev);
32877501a79SPhilipp Zabel }
32977501a79SPhilipp Zabel 
33077501a79SPhilipp Zabel static int ksz8041_config_aneg(struct phy_device *phydev)
33177501a79SPhilipp Zabel {
33277501a79SPhilipp Zabel 	/* Skip auto-negotiation in fiber mode */
33377501a79SPhilipp Zabel 	if (phydev->dev_flags & MICREL_PHY_FXEN) {
33477501a79SPhilipp Zabel 		phydev->speed = SPEED_100;
33577501a79SPhilipp Zabel 		return 0;
33677501a79SPhilipp Zabel 	}
33777501a79SPhilipp Zabel 
33877501a79SPhilipp Zabel 	return genphy_config_aneg(phydev);
33977501a79SPhilipp Zabel }
34077501a79SPhilipp Zabel 
341954c3967SSean Cross static int ksz9021_load_values_from_of(struct phy_device *phydev,
3423c9a9f7fSJaeden Amero 				       const struct device_node *of_node,
3433c9a9f7fSJaeden Amero 				       u16 reg,
3443c9a9f7fSJaeden Amero 				       const char *field1, const char *field2,
3453c9a9f7fSJaeden Amero 				       const char *field3, const char *field4)
346954c3967SSean Cross {
347954c3967SSean Cross 	int val1 = -1;
348954c3967SSean Cross 	int val2 = -2;
349954c3967SSean Cross 	int val3 = -3;
350954c3967SSean Cross 	int val4 = -4;
351954c3967SSean Cross 	int newval;
352954c3967SSean Cross 	int matches = 0;
353954c3967SSean Cross 
354954c3967SSean Cross 	if (!of_property_read_u32(of_node, field1, &val1))
355954c3967SSean Cross 		matches++;
356954c3967SSean Cross 
357954c3967SSean Cross 	if (!of_property_read_u32(of_node, field2, &val2))
358954c3967SSean Cross 		matches++;
359954c3967SSean Cross 
360954c3967SSean Cross 	if (!of_property_read_u32(of_node, field3, &val3))
361954c3967SSean Cross 		matches++;
362954c3967SSean Cross 
363954c3967SSean Cross 	if (!of_property_read_u32(of_node, field4, &val4))
364954c3967SSean Cross 		matches++;
365954c3967SSean Cross 
366954c3967SSean Cross 	if (!matches)
367954c3967SSean Cross 		return 0;
368954c3967SSean Cross 
369954c3967SSean Cross 	if (matches < 4)
370954c3967SSean Cross 		newval = kszphy_extended_read(phydev, reg);
371954c3967SSean Cross 	else
372954c3967SSean Cross 		newval = 0;
373954c3967SSean Cross 
374954c3967SSean Cross 	if (val1 != -1)
375954c3967SSean Cross 		newval = ((newval & 0xfff0) | ((val1 / PS_TO_REG) & 0xf) << 0);
376954c3967SSean Cross 
3776a119745SHubert Chaumette 	if (val2 != -2)
378954c3967SSean Cross 		newval = ((newval & 0xff0f) | ((val2 / PS_TO_REG) & 0xf) << 4);
379954c3967SSean Cross 
3806a119745SHubert Chaumette 	if (val3 != -3)
381954c3967SSean Cross 		newval = ((newval & 0xf0ff) | ((val3 / PS_TO_REG) & 0xf) << 8);
382954c3967SSean Cross 
3836a119745SHubert Chaumette 	if (val4 != -4)
384954c3967SSean Cross 		newval = ((newval & 0x0fff) | ((val4 / PS_TO_REG) & 0xf) << 12);
385954c3967SSean Cross 
386954c3967SSean Cross 	return kszphy_extended_write(phydev, reg, newval);
387954c3967SSean Cross }
388954c3967SSean Cross 
389954c3967SSean Cross static int ksz9021_config_init(struct phy_device *phydev)
390954c3967SSean Cross {
391e5a03bfdSAndrew Lunn 	const struct device *dev = &phydev->mdio.dev;
3923c9a9f7fSJaeden Amero 	const struct device_node *of_node = dev->of_node;
393651df218SAndrew Lunn 	const struct device *dev_walker;
394954c3967SSean Cross 
395651df218SAndrew Lunn 	/* The Micrel driver has a deprecated option to place phy OF
396651df218SAndrew Lunn 	 * properties in the MAC node. Walk up the tree of devices to
397651df218SAndrew Lunn 	 * find a device with an OF node.
398651df218SAndrew Lunn 	 */
399e5a03bfdSAndrew Lunn 	dev_walker = &phydev->mdio.dev;
400651df218SAndrew Lunn 	do {
401651df218SAndrew Lunn 		of_node = dev_walker->of_node;
402651df218SAndrew Lunn 		dev_walker = dev_walker->parent;
403651df218SAndrew Lunn 
404651df218SAndrew Lunn 	} while (!of_node && dev_walker);
405954c3967SSean Cross 
406954c3967SSean Cross 	if (of_node) {
407954c3967SSean Cross 		ksz9021_load_values_from_of(phydev, of_node,
408954c3967SSean Cross 				    MII_KSZPHY_CLK_CONTROL_PAD_SKEW,
409954c3967SSean Cross 				    "txen-skew-ps", "txc-skew-ps",
410954c3967SSean Cross 				    "rxdv-skew-ps", "rxc-skew-ps");
411954c3967SSean Cross 		ksz9021_load_values_from_of(phydev, of_node,
412954c3967SSean Cross 				    MII_KSZPHY_RX_DATA_PAD_SKEW,
413954c3967SSean Cross 				    "rxd0-skew-ps", "rxd1-skew-ps",
414954c3967SSean Cross 				    "rxd2-skew-ps", "rxd3-skew-ps");
415954c3967SSean Cross 		ksz9021_load_values_from_of(phydev, of_node,
416954c3967SSean Cross 				    MII_KSZPHY_TX_DATA_PAD_SKEW,
417954c3967SSean Cross 				    "txd0-skew-ps", "txd1-skew-ps",
418954c3967SSean Cross 				    "txd2-skew-ps", "txd3-skew-ps");
419954c3967SSean Cross 	}
420954c3967SSean Cross 	return 0;
421954c3967SSean Cross }
422954c3967SSean Cross 
4236e4b8273SHubert Chaumette #define MII_KSZ9031RN_MMD_CTRL_REG	0x0d
4246e4b8273SHubert Chaumette #define MII_KSZ9031RN_MMD_REGDATA_REG	0x0e
4256e4b8273SHubert Chaumette #define OP_DATA				1
4266e4b8273SHubert Chaumette #define KSZ9031_PS_TO_REG		60
4276e4b8273SHubert Chaumette 
4286e4b8273SHubert Chaumette /* Extended registers */
4296270e1aeSJaeden Amero /* MMD Address 0x0 */
4306270e1aeSJaeden Amero #define MII_KSZ9031RN_FLP_BURST_TX_LO	3
4316270e1aeSJaeden Amero #define MII_KSZ9031RN_FLP_BURST_TX_HI	4
4326270e1aeSJaeden Amero 
433ae6c97bbSJaeden Amero /* MMD Address 0x2 */
4346e4b8273SHubert Chaumette #define MII_KSZ9031RN_CONTROL_PAD_SKEW	4
4356e4b8273SHubert Chaumette #define MII_KSZ9031RN_RX_DATA_PAD_SKEW	5
4366e4b8273SHubert Chaumette #define MII_KSZ9031RN_TX_DATA_PAD_SKEW	6
4376e4b8273SHubert Chaumette #define MII_KSZ9031RN_CLK_PAD_SKEW	8
4386e4b8273SHubert Chaumette 
439af70c1f9SMike Looijmans /* MMD Address 0x1C */
440af70c1f9SMike Looijmans #define MII_KSZ9031RN_EDPD		0x23
441af70c1f9SMike Looijmans #define MII_KSZ9031RN_EDPD_ENABLE	BIT(0)
442af70c1f9SMike Looijmans 
4436e4b8273SHubert Chaumette static int ksz9031_extended_write(struct phy_device *phydev,
4446e4b8273SHubert Chaumette 				  u8 mode, u32 dev_addr, u32 regnum, u16 val)
4456e4b8273SHubert Chaumette {
4466e4b8273SHubert Chaumette 	phy_write(phydev, MII_KSZ9031RN_MMD_CTRL_REG, dev_addr);
4476e4b8273SHubert Chaumette 	phy_write(phydev, MII_KSZ9031RN_MMD_REGDATA_REG, regnum);
4486e4b8273SHubert Chaumette 	phy_write(phydev, MII_KSZ9031RN_MMD_CTRL_REG, (mode << 14) | dev_addr);
4496e4b8273SHubert Chaumette 	return phy_write(phydev, MII_KSZ9031RN_MMD_REGDATA_REG, val);
4506e4b8273SHubert Chaumette }
4516e4b8273SHubert Chaumette 
4526e4b8273SHubert Chaumette static int ksz9031_extended_read(struct phy_device *phydev,
4536e4b8273SHubert Chaumette 				 u8 mode, u32 dev_addr, u32 regnum)
4546e4b8273SHubert Chaumette {
4556e4b8273SHubert Chaumette 	phy_write(phydev, MII_KSZ9031RN_MMD_CTRL_REG, dev_addr);
4566e4b8273SHubert Chaumette 	phy_write(phydev, MII_KSZ9031RN_MMD_REGDATA_REG, regnum);
4576e4b8273SHubert Chaumette 	phy_write(phydev, MII_KSZ9031RN_MMD_CTRL_REG, (mode << 14) | dev_addr);
4586e4b8273SHubert Chaumette 	return phy_read(phydev, MII_KSZ9031RN_MMD_REGDATA_REG);
4596e4b8273SHubert Chaumette }
4606e4b8273SHubert Chaumette 
4616e4b8273SHubert Chaumette static int ksz9031_of_load_skew_values(struct phy_device *phydev,
4623c9a9f7fSJaeden Amero 				       const struct device_node *of_node,
4636e4b8273SHubert Chaumette 				       u16 reg, size_t field_sz,
4643c9a9f7fSJaeden Amero 				       const char *field[], u8 numfields)
4656e4b8273SHubert Chaumette {
4666e4b8273SHubert Chaumette 	int val[4] = {-1, -2, -3, -4};
4676e4b8273SHubert Chaumette 	int matches = 0;
4686e4b8273SHubert Chaumette 	u16 mask;
4696e4b8273SHubert Chaumette 	u16 maxval;
4706e4b8273SHubert Chaumette 	u16 newval;
4716e4b8273SHubert Chaumette 	int i;
4726e4b8273SHubert Chaumette 
4736e4b8273SHubert Chaumette 	for (i = 0; i < numfields; i++)
4746e4b8273SHubert Chaumette 		if (!of_property_read_u32(of_node, field[i], val + i))
4756e4b8273SHubert Chaumette 			matches++;
4766e4b8273SHubert Chaumette 
4776e4b8273SHubert Chaumette 	if (!matches)
4786e4b8273SHubert Chaumette 		return 0;
4796e4b8273SHubert Chaumette 
4806e4b8273SHubert Chaumette 	if (matches < numfields)
4816e4b8273SHubert Chaumette 		newval = ksz9031_extended_read(phydev, OP_DATA, 2, reg);
4826e4b8273SHubert Chaumette 	else
4836e4b8273SHubert Chaumette 		newval = 0;
4846e4b8273SHubert Chaumette 
4856e4b8273SHubert Chaumette 	maxval = (field_sz == 4) ? 0xf : 0x1f;
4866e4b8273SHubert Chaumette 	for (i = 0; i < numfields; i++)
4876e4b8273SHubert Chaumette 		if (val[i] != -(i + 1)) {
4886e4b8273SHubert Chaumette 			mask = 0xffff;
4896e4b8273SHubert Chaumette 			mask ^= maxval << (field_sz * i);
4906e4b8273SHubert Chaumette 			newval = (newval & mask) |
4916e4b8273SHubert Chaumette 				(((val[i] / KSZ9031_PS_TO_REG) & maxval)
4926e4b8273SHubert Chaumette 					<< (field_sz * i));
4936e4b8273SHubert Chaumette 		}
4946e4b8273SHubert Chaumette 
4956e4b8273SHubert Chaumette 	return ksz9031_extended_write(phydev, OP_DATA, 2, reg, newval);
4966e4b8273SHubert Chaumette }
4976e4b8273SHubert Chaumette 
4986270e1aeSJaeden Amero static int ksz9031_center_flp_timing(struct phy_device *phydev)
4996270e1aeSJaeden Amero {
5006270e1aeSJaeden Amero 	int result;
5016270e1aeSJaeden Amero 
5026270e1aeSJaeden Amero 	/* Center KSZ9031RNX FLP timing at 16ms. */
5036270e1aeSJaeden Amero 	result = ksz9031_extended_write(phydev, OP_DATA, 0,
5046270e1aeSJaeden Amero 					MII_KSZ9031RN_FLP_BURST_TX_HI, 0x0006);
5056270e1aeSJaeden Amero 	result = ksz9031_extended_write(phydev, OP_DATA, 0,
5066270e1aeSJaeden Amero 					MII_KSZ9031RN_FLP_BURST_TX_LO, 0x1A80);
5076270e1aeSJaeden Amero 
5086270e1aeSJaeden Amero 	if (result)
5096270e1aeSJaeden Amero 		return result;
5106270e1aeSJaeden Amero 
5116270e1aeSJaeden Amero 	return genphy_restart_aneg(phydev);
5126270e1aeSJaeden Amero }
5136270e1aeSJaeden Amero 
514af70c1f9SMike Looijmans /* Enable energy-detect power-down mode */
515af70c1f9SMike Looijmans static int ksz9031_enable_edpd(struct phy_device *phydev)
516af70c1f9SMike Looijmans {
517af70c1f9SMike Looijmans 	int reg;
518af70c1f9SMike Looijmans 
519af70c1f9SMike Looijmans 	reg = ksz9031_extended_read(phydev, OP_DATA, 0x1C, MII_KSZ9031RN_EDPD);
520af70c1f9SMike Looijmans 	if (reg < 0)
521af70c1f9SMike Looijmans 		return reg;
522af70c1f9SMike Looijmans 	return ksz9031_extended_write(phydev, OP_DATA, 0x1C, MII_KSZ9031RN_EDPD,
523af70c1f9SMike Looijmans 				      reg | MII_KSZ9031RN_EDPD_ENABLE);
524af70c1f9SMike Looijmans }
525af70c1f9SMike Looijmans 
5266e4b8273SHubert Chaumette static int ksz9031_config_init(struct phy_device *phydev)
5276e4b8273SHubert Chaumette {
528e5a03bfdSAndrew Lunn 	const struct device *dev = &phydev->mdio.dev;
5293c9a9f7fSJaeden Amero 	const struct device_node *of_node = dev->of_node;
5303c9a9f7fSJaeden Amero 	static const char *clk_skews[2] = {"rxc-skew-ps", "txc-skew-ps"};
5313c9a9f7fSJaeden Amero 	static const char *rx_data_skews[4] = {
5326e4b8273SHubert Chaumette 		"rxd0-skew-ps", "rxd1-skew-ps",
5336e4b8273SHubert Chaumette 		"rxd2-skew-ps", "rxd3-skew-ps"
5346e4b8273SHubert Chaumette 	};
5353c9a9f7fSJaeden Amero 	static const char *tx_data_skews[4] = {
5366e4b8273SHubert Chaumette 		"txd0-skew-ps", "txd1-skew-ps",
5376e4b8273SHubert Chaumette 		"txd2-skew-ps", "txd3-skew-ps"
5386e4b8273SHubert Chaumette 	};
5393c9a9f7fSJaeden Amero 	static const char *control_skews[2] = {"txen-skew-ps", "rxdv-skew-ps"};
540b4c19f71SRoosen Henri 	const struct device *dev_walker;
541af70c1f9SMike Looijmans 	int result;
542af70c1f9SMike Looijmans 
543af70c1f9SMike Looijmans 	result = ksz9031_enable_edpd(phydev);
544af70c1f9SMike Looijmans 	if (result < 0)
545af70c1f9SMike Looijmans 		return result;
5466e4b8273SHubert Chaumette 
547b4c19f71SRoosen Henri 	/* The Micrel driver has a deprecated option to place phy OF
548b4c19f71SRoosen Henri 	 * properties in the MAC node. Walk up the tree of devices to
549b4c19f71SRoosen Henri 	 * find a device with an OF node.
550b4c19f71SRoosen Henri 	 */
5519d367eddSDavid S. Miller 	dev_walker = &phydev->mdio.dev;
552b4c19f71SRoosen Henri 	do {
553b4c19f71SRoosen Henri 		of_node = dev_walker->of_node;
554b4c19f71SRoosen Henri 		dev_walker = dev_walker->parent;
555b4c19f71SRoosen Henri 	} while (!of_node && dev_walker);
5566e4b8273SHubert Chaumette 
5576e4b8273SHubert Chaumette 	if (of_node) {
5586e4b8273SHubert Chaumette 		ksz9031_of_load_skew_values(phydev, of_node,
5596e4b8273SHubert Chaumette 				MII_KSZ9031RN_CLK_PAD_SKEW, 5,
5606e4b8273SHubert Chaumette 				clk_skews, 2);
5616e4b8273SHubert Chaumette 
5626e4b8273SHubert Chaumette 		ksz9031_of_load_skew_values(phydev, of_node,
5636e4b8273SHubert Chaumette 				MII_KSZ9031RN_CONTROL_PAD_SKEW, 4,
5646e4b8273SHubert Chaumette 				control_skews, 2);
5656e4b8273SHubert Chaumette 
5666e4b8273SHubert Chaumette 		ksz9031_of_load_skew_values(phydev, of_node,
5676e4b8273SHubert Chaumette 				MII_KSZ9031RN_RX_DATA_PAD_SKEW, 4,
5686e4b8273SHubert Chaumette 				rx_data_skews, 4);
5696e4b8273SHubert Chaumette 
5706e4b8273SHubert Chaumette 		ksz9031_of_load_skew_values(phydev, of_node,
5716e4b8273SHubert Chaumette 				MII_KSZ9031RN_TX_DATA_PAD_SKEW, 4,
5726e4b8273SHubert Chaumette 				tx_data_skews, 4);
5736e4b8273SHubert Chaumette 	}
5746270e1aeSJaeden Amero 
5756270e1aeSJaeden Amero 	return ksz9031_center_flp_timing(phydev);
5766e4b8273SHubert Chaumette }
5776e4b8273SHubert Chaumette 
57893272e07SJean-Christophe PLAGNIOL-VILLARD #define KSZ8873MLL_GLOBAL_CONTROL_4	0x06
57900aee095SJohan Hovold #define KSZ8873MLL_GLOBAL_CONTROL_4_DUPLEX	BIT(6)
58000aee095SJohan Hovold #define KSZ8873MLL_GLOBAL_CONTROL_4_SPEED	BIT(4)
58132d73b14SJingoo Han static int ksz8873mll_read_status(struct phy_device *phydev)
58293272e07SJean-Christophe PLAGNIOL-VILLARD {
58393272e07SJean-Christophe PLAGNIOL-VILLARD 	int regval;
58493272e07SJean-Christophe PLAGNIOL-VILLARD 
58593272e07SJean-Christophe PLAGNIOL-VILLARD 	/* dummy read */
58693272e07SJean-Christophe PLAGNIOL-VILLARD 	regval = phy_read(phydev, KSZ8873MLL_GLOBAL_CONTROL_4);
58793272e07SJean-Christophe PLAGNIOL-VILLARD 
58893272e07SJean-Christophe PLAGNIOL-VILLARD 	regval = phy_read(phydev, KSZ8873MLL_GLOBAL_CONTROL_4);
58993272e07SJean-Christophe PLAGNIOL-VILLARD 
59093272e07SJean-Christophe PLAGNIOL-VILLARD 	if (regval & KSZ8873MLL_GLOBAL_CONTROL_4_DUPLEX)
59193272e07SJean-Christophe PLAGNIOL-VILLARD 		phydev->duplex = DUPLEX_HALF;
59293272e07SJean-Christophe PLAGNIOL-VILLARD 	else
59393272e07SJean-Christophe PLAGNIOL-VILLARD 		phydev->duplex = DUPLEX_FULL;
59493272e07SJean-Christophe PLAGNIOL-VILLARD 
59593272e07SJean-Christophe PLAGNIOL-VILLARD 	if (regval & KSZ8873MLL_GLOBAL_CONTROL_4_SPEED)
59693272e07SJean-Christophe PLAGNIOL-VILLARD 		phydev->speed = SPEED_10;
59793272e07SJean-Christophe PLAGNIOL-VILLARD 	else
59893272e07SJean-Christophe PLAGNIOL-VILLARD 		phydev->speed = SPEED_100;
59993272e07SJean-Christophe PLAGNIOL-VILLARD 
60093272e07SJean-Christophe PLAGNIOL-VILLARD 	phydev->link = 1;
60193272e07SJean-Christophe PLAGNIOL-VILLARD 	phydev->pause = phydev->asym_pause = 0;
60293272e07SJean-Christophe PLAGNIOL-VILLARD 
60393272e07SJean-Christophe PLAGNIOL-VILLARD 	return 0;
60493272e07SJean-Christophe PLAGNIOL-VILLARD }
60593272e07SJean-Christophe PLAGNIOL-VILLARD 
606d2fd719bSNathan Sullivan static int ksz9031_read_status(struct phy_device *phydev)
607d2fd719bSNathan Sullivan {
608d2fd719bSNathan Sullivan 	int err;
609d2fd719bSNathan Sullivan 	int regval;
610d2fd719bSNathan Sullivan 
611d2fd719bSNathan Sullivan 	err = genphy_read_status(phydev);
612d2fd719bSNathan Sullivan 	if (err)
613d2fd719bSNathan Sullivan 		return err;
614d2fd719bSNathan Sullivan 
615d2fd719bSNathan Sullivan 	/* Make sure the PHY is not broken. Read idle error count,
616d2fd719bSNathan Sullivan 	 * and reset the PHY if it is maxed out.
617d2fd719bSNathan Sullivan 	 */
618d2fd719bSNathan Sullivan 	regval = phy_read(phydev, MII_STAT1000);
619d2fd719bSNathan Sullivan 	if ((regval & 0xFF) == 0xFF) {
620d2fd719bSNathan Sullivan 		phy_init_hw(phydev);
621d2fd719bSNathan Sullivan 		phydev->link = 0;
622*b866203dSZach Brown 		if (phydev->drv->config_intr && phy_interrupt_is_valid(phydev))
623*b866203dSZach Brown 			phydev->drv->config_intr(phydev);
624d2fd719bSNathan Sullivan 	}
625d2fd719bSNathan Sullivan 
626d2fd719bSNathan Sullivan 	return 0;
627d2fd719bSNathan Sullivan }
628d2fd719bSNathan Sullivan 
62993272e07SJean-Christophe PLAGNIOL-VILLARD static int ksz8873mll_config_aneg(struct phy_device *phydev)
63093272e07SJean-Christophe PLAGNIOL-VILLARD {
63193272e07SJean-Christophe PLAGNIOL-VILLARD 	return 0;
63293272e07SJean-Christophe PLAGNIOL-VILLARD }
63393272e07SJean-Christophe PLAGNIOL-VILLARD 
63419936942SVince Bridgers /* This routine returns -1 as an indication to the caller that the
63519936942SVince Bridgers  * Micrel ksz9021 10/100/1000 PHY does not support standard IEEE
63619936942SVince Bridgers  * MMD extended PHY registers.
63719936942SVince Bridgers  */
63819936942SVince Bridgers static int
639d11437e0SRussell King ksz9021_rd_mmd_phyreg(struct phy_device *phydev, int devad, u16 regnum)
64019936942SVince Bridgers {
64119936942SVince Bridgers 	return -1;
64219936942SVince Bridgers }
64319936942SVince Bridgers 
64419936942SVince Bridgers /* This routine does nothing since the Micrel ksz9021 does not support
64519936942SVince Bridgers  * standard IEEE MMD extended PHY registers.
64619936942SVince Bridgers  */
647d11437e0SRussell King static int
648d11437e0SRussell King ksz9021_wr_mmd_phyreg(struct phy_device *phydev, int devad, u16 regnum, u16 val)
64919936942SVince Bridgers {
650d11437e0SRussell King 	return -1;
65119936942SVince Bridgers }
65219936942SVince Bridgers 
6532b2427d0SAndrew Lunn static int kszphy_get_sset_count(struct phy_device *phydev)
6542b2427d0SAndrew Lunn {
6552b2427d0SAndrew Lunn 	return ARRAY_SIZE(kszphy_hw_stats);
6562b2427d0SAndrew Lunn }
6572b2427d0SAndrew Lunn 
6582b2427d0SAndrew Lunn static void kszphy_get_strings(struct phy_device *phydev, u8 *data)
6592b2427d0SAndrew Lunn {
6602b2427d0SAndrew Lunn 	int i;
6612b2427d0SAndrew Lunn 
6622b2427d0SAndrew Lunn 	for (i = 0; i < ARRAY_SIZE(kszphy_hw_stats); i++) {
6632b2427d0SAndrew Lunn 		memcpy(data + i * ETH_GSTRING_LEN,
6642b2427d0SAndrew Lunn 		       kszphy_hw_stats[i].string, ETH_GSTRING_LEN);
6652b2427d0SAndrew Lunn 	}
6662b2427d0SAndrew Lunn }
6672b2427d0SAndrew Lunn 
6682b2427d0SAndrew Lunn #ifndef UINT64_MAX
6692b2427d0SAndrew Lunn #define UINT64_MAX              (u64)(~((u64)0))
6702b2427d0SAndrew Lunn #endif
6712b2427d0SAndrew Lunn static u64 kszphy_get_stat(struct phy_device *phydev, int i)
6722b2427d0SAndrew Lunn {
6732b2427d0SAndrew Lunn 	struct kszphy_hw_stat stat = kszphy_hw_stats[i];
6742b2427d0SAndrew Lunn 	struct kszphy_priv *priv = phydev->priv;
675321b4d4bSAndrew Lunn 	int val;
676321b4d4bSAndrew Lunn 	u64 ret;
6772b2427d0SAndrew Lunn 
6782b2427d0SAndrew Lunn 	val = phy_read(phydev, stat.reg);
6792b2427d0SAndrew Lunn 	if (val < 0) {
680321b4d4bSAndrew Lunn 		ret = UINT64_MAX;
6812b2427d0SAndrew Lunn 	} else {
6822b2427d0SAndrew Lunn 		val = val & ((1 << stat.bits) - 1);
6832b2427d0SAndrew Lunn 		priv->stats[i] += val;
684321b4d4bSAndrew Lunn 		ret = priv->stats[i];
6852b2427d0SAndrew Lunn 	}
6862b2427d0SAndrew Lunn 
687321b4d4bSAndrew Lunn 	return ret;
6882b2427d0SAndrew Lunn }
6892b2427d0SAndrew Lunn 
6902b2427d0SAndrew Lunn static void kszphy_get_stats(struct phy_device *phydev,
6912b2427d0SAndrew Lunn 			     struct ethtool_stats *stats, u64 *data)
6922b2427d0SAndrew Lunn {
6932b2427d0SAndrew Lunn 	int i;
6942b2427d0SAndrew Lunn 
6952b2427d0SAndrew Lunn 	for (i = 0; i < ARRAY_SIZE(kszphy_hw_stats); i++)
6962b2427d0SAndrew Lunn 		data[i] = kszphy_get_stat(phydev, i);
6972b2427d0SAndrew Lunn }
6982b2427d0SAndrew Lunn 
699836384d2SWenyou Yang static int kszphy_suspend(struct phy_device *phydev)
700836384d2SWenyou Yang {
701836384d2SWenyou Yang 	/* Disable PHY Interrupts */
702836384d2SWenyou Yang 	if (phy_interrupt_is_valid(phydev)) {
703836384d2SWenyou Yang 		phydev->interrupts = PHY_INTERRUPT_DISABLED;
704836384d2SWenyou Yang 		if (phydev->drv->config_intr)
705836384d2SWenyou Yang 			phydev->drv->config_intr(phydev);
706836384d2SWenyou Yang 	}
707836384d2SWenyou Yang 
708836384d2SWenyou Yang 	return genphy_suspend(phydev);
709836384d2SWenyou Yang }
710836384d2SWenyou Yang 
711f5aba91dSAlexandre Belloni static int kszphy_resume(struct phy_device *phydev)
712f5aba91dSAlexandre Belloni {
71379e498a9SLeonard Crestez 	int ret;
71479e498a9SLeonard Crestez 
715836384d2SWenyou Yang 	genphy_resume(phydev);
716f5aba91dSAlexandre Belloni 
71779e498a9SLeonard Crestez 	ret = kszphy_config_reset(phydev);
71879e498a9SLeonard Crestez 	if (ret)
71979e498a9SLeonard Crestez 		return ret;
72079e498a9SLeonard Crestez 
721836384d2SWenyou Yang 	/* Enable PHY Interrupts */
722836384d2SWenyou Yang 	if (phy_interrupt_is_valid(phydev)) {
723836384d2SWenyou Yang 		phydev->interrupts = PHY_INTERRUPT_ENABLED;
724836384d2SWenyou Yang 		if (phydev->drv->config_intr)
725836384d2SWenyou Yang 			phydev->drv->config_intr(phydev);
726836384d2SWenyou Yang 	}
727f5aba91dSAlexandre Belloni 
728f5aba91dSAlexandre Belloni 	return 0;
729f5aba91dSAlexandre Belloni }
730f5aba91dSAlexandre Belloni 
731e6a423a8SJohan Hovold static int kszphy_probe(struct phy_device *phydev)
732e6a423a8SJohan Hovold {
733e6a423a8SJohan Hovold 	const struct kszphy_type *type = phydev->drv->driver_data;
734e5a03bfdSAndrew Lunn 	const struct device_node *np = phydev->mdio.dev.of_node;
735e6a423a8SJohan Hovold 	struct kszphy_priv *priv;
73663f44b2bSJohan Hovold 	struct clk *clk;
737e7a792e9SJohan Hovold 	int ret;
738e6a423a8SJohan Hovold 
739e5a03bfdSAndrew Lunn 	priv = devm_kzalloc(&phydev->mdio.dev, sizeof(*priv), GFP_KERNEL);
740e6a423a8SJohan Hovold 	if (!priv)
741e6a423a8SJohan Hovold 		return -ENOMEM;
742e6a423a8SJohan Hovold 
743e6a423a8SJohan Hovold 	phydev->priv = priv;
744e6a423a8SJohan Hovold 
745e6a423a8SJohan Hovold 	priv->type = type;
746e6a423a8SJohan Hovold 
747e7a792e9SJohan Hovold 	if (type->led_mode_reg) {
748e7a792e9SJohan Hovold 		ret = of_property_read_u32(np, "micrel,led-mode",
749e7a792e9SJohan Hovold 				&priv->led_mode);
750e7a792e9SJohan Hovold 		if (ret)
751e7a792e9SJohan Hovold 			priv->led_mode = -1;
752e7a792e9SJohan Hovold 
753e7a792e9SJohan Hovold 		if (priv->led_mode > 3) {
75472ba48beSAndrew Lunn 			phydev_err(phydev, "invalid led mode: 0x%02x\n",
755e7a792e9SJohan Hovold 				   priv->led_mode);
756e7a792e9SJohan Hovold 			priv->led_mode = -1;
757e7a792e9SJohan Hovold 		}
758e7a792e9SJohan Hovold 	} else {
759e7a792e9SJohan Hovold 		priv->led_mode = -1;
760e7a792e9SJohan Hovold 	}
761e7a792e9SJohan Hovold 
762e5a03bfdSAndrew Lunn 	clk = devm_clk_get(&phydev->mdio.dev, "rmii-ref");
763bced8701SNiklas Cassel 	/* NOTE: clk may be NULL if building without CONFIG_HAVE_CLK */
764bced8701SNiklas Cassel 	if (!IS_ERR_OR_NULL(clk)) {
7651fadee0cSSascha Hauer 		unsigned long rate = clk_get_rate(clk);
76686dc1342SJohan Hovold 		bool rmii_ref_clk_sel_25_mhz;
7671fadee0cSSascha Hauer 
76863f44b2bSJohan Hovold 		priv->rmii_ref_clk_sel = type->has_rmii_ref_clk_sel;
76986dc1342SJohan Hovold 		rmii_ref_clk_sel_25_mhz = of_property_read_bool(np,
77086dc1342SJohan Hovold 				"micrel,rmii-reference-clock-select-25-mhz");
77163f44b2bSJohan Hovold 
7721fadee0cSSascha Hauer 		if (rate > 24500000 && rate < 25500000) {
77386dc1342SJohan Hovold 			priv->rmii_ref_clk_sel_val = rmii_ref_clk_sel_25_mhz;
7741fadee0cSSascha Hauer 		} else if (rate > 49500000 && rate < 50500000) {
77586dc1342SJohan Hovold 			priv->rmii_ref_clk_sel_val = !rmii_ref_clk_sel_25_mhz;
7761fadee0cSSascha Hauer 		} else {
77772ba48beSAndrew Lunn 			phydev_err(phydev, "Clock rate out of range: %ld\n",
77872ba48beSAndrew Lunn 				   rate);
7791fadee0cSSascha Hauer 			return -EINVAL;
7801fadee0cSSascha Hauer 		}
7811fadee0cSSascha Hauer 	}
7821fadee0cSSascha Hauer 
78363f44b2bSJohan Hovold 	/* Support legacy board-file configuration */
78463f44b2bSJohan Hovold 	if (phydev->dev_flags & MICREL_PHY_50MHZ_CLK) {
78563f44b2bSJohan Hovold 		priv->rmii_ref_clk_sel = true;
78663f44b2bSJohan Hovold 		priv->rmii_ref_clk_sel_val = true;
78763f44b2bSJohan Hovold 	}
78863f44b2bSJohan Hovold 
78963f44b2bSJohan Hovold 	return 0;
7901fadee0cSSascha Hauer }
7911fadee0cSSascha Hauer 
792d5bf9071SChristian Hohnstaedt static struct phy_driver ksphy_driver[] = {
793d5bf9071SChristian Hohnstaedt {
79451f932c4SChoi, David 	.phy_id		= PHY_ID_KS8737,
795f893a99eSFabio Estevam 	.phy_id_mask	= MICREL_PHY_ID_MASK,
79651f932c4SChoi, David 	.name		= "Micrel KS8737",
797529ed127STimur Tabi 	.features	= PHY_BASIC_FEATURES,
79851f932c4SChoi, David 	.flags		= PHY_HAS_MAGICANEG | PHY_HAS_INTERRUPT,
799c6f9575cSJohan Hovold 	.driver_data	= &ks8737_type,
800d0507009SDavid J. Choi 	.config_init	= kszphy_config_init,
801d0507009SDavid J. Choi 	.config_aneg	= genphy_config_aneg,
802d0507009SDavid J. Choi 	.read_status	= genphy_read_status,
80351f932c4SChoi, David 	.ack_interrupt	= kszphy_ack_interrupt,
804c6f9575cSJohan Hovold 	.config_intr	= kszphy_config_intr,
8051a5465f5SPatrice Vilchez 	.suspend	= genphy_suspend,
8061a5465f5SPatrice Vilchez 	.resume		= genphy_resume,
807d5bf9071SChristian Hohnstaedt }, {
808212ea99aSMarek Vasut 	.phy_id		= PHY_ID_KSZ8021,
809212ea99aSMarek Vasut 	.phy_id_mask	= 0x00ffffff,
8107ab59dc1SDavid J. Choi 	.name		= "Micrel KSZ8021 or KSZ8031",
811529ed127STimur Tabi 	.features	= PHY_BASIC_FEATURES,
812212ea99aSMarek Vasut 	.flags		= PHY_HAS_MAGICANEG | PHY_HAS_INTERRUPT,
813e6a423a8SJohan Hovold 	.driver_data	= &ksz8021_type,
81463f44b2bSJohan Hovold 	.probe		= kszphy_probe,
815d0e1df9cSJohan Hovold 	.config_init	= kszphy_config_init,
816212ea99aSMarek Vasut 	.config_aneg	= genphy_config_aneg,
817212ea99aSMarek Vasut 	.read_status	= genphy_read_status,
818212ea99aSMarek Vasut 	.ack_interrupt	= kszphy_ack_interrupt,
819212ea99aSMarek Vasut 	.config_intr	= kszphy_config_intr,
8202b2427d0SAndrew Lunn 	.get_sset_count = kszphy_get_sset_count,
8212b2427d0SAndrew Lunn 	.get_strings	= kszphy_get_strings,
8222b2427d0SAndrew Lunn 	.get_stats	= kszphy_get_stats,
8231a5465f5SPatrice Vilchez 	.suspend	= genphy_suspend,
8241a5465f5SPatrice Vilchez 	.resume		= genphy_resume,
825212ea99aSMarek Vasut }, {
826b818d1a7SHector Palacios 	.phy_id		= PHY_ID_KSZ8031,
827b818d1a7SHector Palacios 	.phy_id_mask	= 0x00ffffff,
828b818d1a7SHector Palacios 	.name		= "Micrel KSZ8031",
829529ed127STimur Tabi 	.features	= PHY_BASIC_FEATURES,
830b818d1a7SHector Palacios 	.flags		= PHY_HAS_MAGICANEG | PHY_HAS_INTERRUPT,
831e6a423a8SJohan Hovold 	.driver_data	= &ksz8021_type,
83263f44b2bSJohan Hovold 	.probe		= kszphy_probe,
833d0e1df9cSJohan Hovold 	.config_init	= kszphy_config_init,
834b818d1a7SHector Palacios 	.config_aneg	= genphy_config_aneg,
835b818d1a7SHector Palacios 	.read_status	= genphy_read_status,
836b818d1a7SHector Palacios 	.ack_interrupt	= kszphy_ack_interrupt,
837b818d1a7SHector Palacios 	.config_intr	= kszphy_config_intr,
8382b2427d0SAndrew Lunn 	.get_sset_count = kszphy_get_sset_count,
8392b2427d0SAndrew Lunn 	.get_strings	= kszphy_get_strings,
8402b2427d0SAndrew Lunn 	.get_stats	= kszphy_get_stats,
8411a5465f5SPatrice Vilchez 	.suspend	= genphy_suspend,
8421a5465f5SPatrice Vilchez 	.resume		= genphy_resume,
843b818d1a7SHector Palacios }, {
844510d573fSMarek Vasut 	.phy_id		= PHY_ID_KSZ8041,
845f893a99eSFabio Estevam 	.phy_id_mask	= MICREL_PHY_ID_MASK,
846510d573fSMarek Vasut 	.name		= "Micrel KSZ8041",
847529ed127STimur Tabi 	.features	= PHY_BASIC_FEATURES,
84851f932c4SChoi, David 	.flags		= PHY_HAS_MAGICANEG | PHY_HAS_INTERRUPT,
849e6a423a8SJohan Hovold 	.driver_data	= &ksz8041_type,
850e6a423a8SJohan Hovold 	.probe		= kszphy_probe,
85177501a79SPhilipp Zabel 	.config_init	= ksz8041_config_init,
85277501a79SPhilipp Zabel 	.config_aneg	= ksz8041_config_aneg,
853d0507009SDavid J. Choi 	.read_status	= genphy_read_status,
85451f932c4SChoi, David 	.ack_interrupt	= kszphy_ack_interrupt,
85551f932c4SChoi, David 	.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,
8591a5465f5SPatrice Vilchez 	.suspend	= genphy_suspend,
8601a5465f5SPatrice Vilchez 	.resume		= genphy_resume,
861d5bf9071SChristian Hohnstaedt }, {
8624bd7b512SSergei Shtylyov 	.phy_id		= PHY_ID_KSZ8041RNLI,
863f893a99eSFabio Estevam 	.phy_id_mask	= MICREL_PHY_ID_MASK,
8644bd7b512SSergei Shtylyov 	.name		= "Micrel KSZ8041RNLI",
865529ed127STimur Tabi 	.features	= PHY_BASIC_FEATURES,
8664bd7b512SSergei Shtylyov 	.flags		= PHY_HAS_MAGICANEG | PHY_HAS_INTERRUPT,
867e6a423a8SJohan Hovold 	.driver_data	= &ksz8041_type,
868e6a423a8SJohan Hovold 	.probe		= kszphy_probe,
869e6a423a8SJohan Hovold 	.config_init	= kszphy_config_init,
8704bd7b512SSergei Shtylyov 	.config_aneg	= genphy_config_aneg,
8714bd7b512SSergei Shtylyov 	.read_status	= genphy_read_status,
8724bd7b512SSergei Shtylyov 	.ack_interrupt	= kszphy_ack_interrupt,
8734bd7b512SSergei Shtylyov 	.config_intr	= kszphy_config_intr,
8742b2427d0SAndrew Lunn 	.get_sset_count = kszphy_get_sset_count,
8752b2427d0SAndrew Lunn 	.get_strings	= kszphy_get_strings,
8762b2427d0SAndrew Lunn 	.get_stats	= kszphy_get_stats,
8774bd7b512SSergei Shtylyov 	.suspend	= genphy_suspend,
8784bd7b512SSergei Shtylyov 	.resume		= genphy_resume,
8794bd7b512SSergei Shtylyov }, {
880510d573fSMarek Vasut 	.phy_id		= PHY_ID_KSZ8051,
881f893a99eSFabio Estevam 	.phy_id_mask	= MICREL_PHY_ID_MASK,
882510d573fSMarek Vasut 	.name		= "Micrel KSZ8051",
883529ed127STimur Tabi 	.features	= PHY_BASIC_FEATURES,
88451f932c4SChoi, David 	.flags		= PHY_HAS_MAGICANEG | PHY_HAS_INTERRUPT,
885e6a423a8SJohan Hovold 	.driver_data	= &ksz8051_type,
886e6a423a8SJohan Hovold 	.probe		= kszphy_probe,
88763f44b2bSJohan Hovold 	.config_init	= kszphy_config_init,
88851f932c4SChoi, David 	.config_aneg	= genphy_config_aneg,
88951f932c4SChoi, David 	.read_status	= genphy_read_status,
89051f932c4SChoi, David 	.ack_interrupt	= kszphy_ack_interrupt,
89151f932c4SChoi, David 	.config_intr	= kszphy_config_intr,
8922b2427d0SAndrew Lunn 	.get_sset_count = kszphy_get_sset_count,
8932b2427d0SAndrew Lunn 	.get_strings	= kszphy_get_strings,
8942b2427d0SAndrew Lunn 	.get_stats	= kszphy_get_stats,
8951a5465f5SPatrice Vilchez 	.suspend	= genphy_suspend,
8961a5465f5SPatrice Vilchez 	.resume		= genphy_resume,
897d5bf9071SChristian Hohnstaedt }, {
898510d573fSMarek Vasut 	.phy_id		= PHY_ID_KSZ8001,
899510d573fSMarek Vasut 	.name		= "Micrel KSZ8001 or KS8721",
900ecd5a323SAlexander Stein 	.phy_id_mask	= 0x00fffffc,
901529ed127STimur Tabi 	.features	= PHY_BASIC_FEATURES,
90251f932c4SChoi, David 	.flags		= PHY_HAS_MAGICANEG | PHY_HAS_INTERRUPT,
903e6a423a8SJohan Hovold 	.driver_data	= &ksz8041_type,
904e6a423a8SJohan Hovold 	.probe		= kszphy_probe,
905e6a423a8SJohan Hovold 	.config_init	= kszphy_config_init,
90651f932c4SChoi, David 	.config_aneg	= genphy_config_aneg,
90751f932c4SChoi, David 	.read_status	= genphy_read_status,
90851f932c4SChoi, David 	.ack_interrupt	= kszphy_ack_interrupt,
90951f932c4SChoi, David 	.config_intr	= kszphy_config_intr,
9102b2427d0SAndrew Lunn 	.get_sset_count = kszphy_get_sset_count,
9112b2427d0SAndrew Lunn 	.get_strings	= kszphy_get_strings,
9122b2427d0SAndrew Lunn 	.get_stats	= kszphy_get_stats,
9131a5465f5SPatrice Vilchez 	.suspend	= genphy_suspend,
9141a5465f5SPatrice Vilchez 	.resume		= genphy_resume,
915d5bf9071SChristian Hohnstaedt }, {
9167ab59dc1SDavid J. Choi 	.phy_id		= PHY_ID_KSZ8081,
9177ab59dc1SDavid J. Choi 	.name		= "Micrel KSZ8081 or KSZ8091",
918f893a99eSFabio Estevam 	.phy_id_mask	= MICREL_PHY_ID_MASK,
919529ed127STimur Tabi 	.features	= PHY_BASIC_FEATURES,
9207ab59dc1SDavid J. Choi 	.flags		= PHY_HAS_MAGICANEG | PHY_HAS_INTERRUPT,
921e6a423a8SJohan Hovold 	.driver_data	= &ksz8081_type,
922e6a423a8SJohan Hovold 	.probe		= kszphy_probe,
9230f95903eSJohan Hovold 	.config_init	= kszphy_config_init,
9247ab59dc1SDavid J. Choi 	.config_aneg	= genphy_config_aneg,
9257ab59dc1SDavid J. Choi 	.read_status	= genphy_read_status,
9267ab59dc1SDavid J. Choi 	.ack_interrupt	= kszphy_ack_interrupt,
9277ab59dc1SDavid J. Choi 	.config_intr	= kszphy_config_intr,
9282b2427d0SAndrew Lunn 	.get_sset_count = kszphy_get_sset_count,
9292b2427d0SAndrew Lunn 	.get_strings	= kszphy_get_strings,
9302b2427d0SAndrew Lunn 	.get_stats	= kszphy_get_stats,
931836384d2SWenyou Yang 	.suspend	= kszphy_suspend,
932f5aba91dSAlexandre Belloni 	.resume		= kszphy_resume,
9337ab59dc1SDavid J. Choi }, {
9347ab59dc1SDavid J. Choi 	.phy_id		= PHY_ID_KSZ8061,
9357ab59dc1SDavid J. Choi 	.name		= "Micrel KSZ8061",
936f893a99eSFabio Estevam 	.phy_id_mask	= MICREL_PHY_ID_MASK,
937529ed127STimur Tabi 	.features	= PHY_BASIC_FEATURES,
9387ab59dc1SDavid J. Choi 	.flags		= PHY_HAS_MAGICANEG | PHY_HAS_INTERRUPT,
9397ab59dc1SDavid J. Choi 	.config_init	= kszphy_config_init,
9407ab59dc1SDavid J. Choi 	.config_aneg	= genphy_config_aneg,
9417ab59dc1SDavid J. Choi 	.read_status	= genphy_read_status,
9427ab59dc1SDavid J. Choi 	.ack_interrupt	= kszphy_ack_interrupt,
9437ab59dc1SDavid J. Choi 	.config_intr	= kszphy_config_intr,
9441a5465f5SPatrice Vilchez 	.suspend	= genphy_suspend,
9451a5465f5SPatrice Vilchez 	.resume		= genphy_resume,
9467ab59dc1SDavid J. Choi }, {
947d0507009SDavid J. Choi 	.phy_id		= PHY_ID_KSZ9021,
94848d7d0adSJason Wang 	.phy_id_mask	= 0x000ffffe,
949d0507009SDavid J. Choi 	.name		= "Micrel KSZ9021 Gigabit PHY",
950529ed127STimur Tabi 	.features	= PHY_GBIT_FEATURES,
95151f932c4SChoi, David 	.flags		= PHY_HAS_MAGICANEG | PHY_HAS_INTERRUPT,
952c6f9575cSJohan Hovold 	.driver_data	= &ksz9021_type,
953bfe72442SGrygorii Strashko 	.probe		= kszphy_probe,
954954c3967SSean Cross 	.config_init	= ksz9021_config_init,
955d0507009SDavid J. Choi 	.config_aneg	= genphy_config_aneg,
956d0507009SDavid J. Choi 	.read_status	= genphy_read_status,
95751f932c4SChoi, David 	.ack_interrupt	= kszphy_ack_interrupt,
958c6f9575cSJohan Hovold 	.config_intr	= kszphy_config_intr,
9592b2427d0SAndrew Lunn 	.get_sset_count = kszphy_get_sset_count,
9602b2427d0SAndrew Lunn 	.get_strings	= kszphy_get_strings,
9612b2427d0SAndrew Lunn 	.get_stats	= kszphy_get_stats,
9621a5465f5SPatrice Vilchez 	.suspend	= genphy_suspend,
9631a5465f5SPatrice Vilchez 	.resume		= genphy_resume,
964d11437e0SRussell King 	.read_mmd	= ksz9021_rd_mmd_phyreg,
965d11437e0SRussell King 	.write_mmd	= ksz9021_wr_mmd_phyreg,
96693272e07SJean-Christophe PLAGNIOL-VILLARD }, {
9677ab59dc1SDavid J. Choi 	.phy_id		= PHY_ID_KSZ9031,
968f893a99eSFabio Estevam 	.phy_id_mask	= MICREL_PHY_ID_MASK,
9697ab59dc1SDavid J. Choi 	.name		= "Micrel KSZ9031 Gigabit PHY",
970529ed127STimur Tabi 	.features	= PHY_GBIT_FEATURES,
9717ab59dc1SDavid J. Choi 	.flags		= PHY_HAS_MAGICANEG | PHY_HAS_INTERRUPT,
972c6f9575cSJohan Hovold 	.driver_data	= &ksz9021_type,
973bfe72442SGrygorii Strashko 	.probe		= kszphy_probe,
9746e4b8273SHubert Chaumette 	.config_init	= ksz9031_config_init,
9757ab59dc1SDavid J. Choi 	.config_aneg	= genphy_config_aneg,
976d2fd719bSNathan Sullivan 	.read_status	= ksz9031_read_status,
9777ab59dc1SDavid J. Choi 	.ack_interrupt	= kszphy_ack_interrupt,
978c6f9575cSJohan Hovold 	.config_intr	= kszphy_config_intr,
9792b2427d0SAndrew Lunn 	.get_sset_count = kszphy_get_sset_count,
9802b2427d0SAndrew Lunn 	.get_strings	= kszphy_get_strings,
9812b2427d0SAndrew Lunn 	.get_stats	= kszphy_get_stats,
9821a5465f5SPatrice Vilchez 	.suspend	= genphy_suspend,
983f64f1482SXander Huff 	.resume		= kszphy_resume,
9847ab59dc1SDavid J. Choi }, {
98593272e07SJean-Christophe PLAGNIOL-VILLARD 	.phy_id		= PHY_ID_KSZ8873MLL,
986f893a99eSFabio Estevam 	.phy_id_mask	= MICREL_PHY_ID_MASK,
98793272e07SJean-Christophe PLAGNIOL-VILLARD 	.name		= "Micrel KSZ8873MLL Switch",
98893272e07SJean-Christophe PLAGNIOL-VILLARD 	.flags		= PHY_HAS_MAGICANEG,
98993272e07SJean-Christophe PLAGNIOL-VILLARD 	.config_init	= kszphy_config_init,
99093272e07SJean-Christophe PLAGNIOL-VILLARD 	.config_aneg	= ksz8873mll_config_aneg,
99193272e07SJean-Christophe PLAGNIOL-VILLARD 	.read_status	= ksz8873mll_read_status,
9921a5465f5SPatrice Vilchez 	.suspend	= genphy_suspend,
9931a5465f5SPatrice Vilchez 	.resume		= genphy_resume,
9947ab59dc1SDavid J. Choi }, {
9957ab59dc1SDavid J. Choi 	.phy_id		= PHY_ID_KSZ886X,
996f893a99eSFabio Estevam 	.phy_id_mask	= MICREL_PHY_ID_MASK,
9977ab59dc1SDavid J. Choi 	.name		= "Micrel KSZ886X Switch",
998529ed127STimur Tabi 	.features	= PHY_BASIC_FEATURES,
9997ab59dc1SDavid J. Choi 	.flags		= PHY_HAS_MAGICANEG | PHY_HAS_INTERRUPT,
10007ab59dc1SDavid J. Choi 	.config_init	= kszphy_config_init,
10017ab59dc1SDavid J. Choi 	.config_aneg	= genphy_config_aneg,
10027ab59dc1SDavid J. Choi 	.read_status	= genphy_read_status,
10031a5465f5SPatrice Vilchez 	.suspend	= genphy_suspend,
10041a5465f5SPatrice Vilchez 	.resume		= genphy_resume,
10059d162ed6SSean Nyekjaer }, {
10069d162ed6SSean Nyekjaer 	.phy_id		= PHY_ID_KSZ8795,
10079d162ed6SSean Nyekjaer 	.phy_id_mask	= MICREL_PHY_ID_MASK,
10089d162ed6SSean Nyekjaer 	.name		= "Micrel KSZ8795",
1009cf626c3bSSean Nyekjaer 	.features	= PHY_BASIC_FEATURES,
10109d162ed6SSean Nyekjaer 	.flags		= PHY_HAS_MAGICANEG | PHY_HAS_INTERRUPT,
10119d162ed6SSean Nyekjaer 	.config_init	= kszphy_config_init,
10129d162ed6SSean Nyekjaer 	.config_aneg	= ksz8873mll_config_aneg,
10139d162ed6SSean Nyekjaer 	.read_status	= ksz8873mll_read_status,
10149d162ed6SSean Nyekjaer 	.suspend	= genphy_suspend,
10159d162ed6SSean Nyekjaer 	.resume		= genphy_resume,
1016d5bf9071SChristian Hohnstaedt } };
1017d0507009SDavid J. Choi 
101850fd7150SJohan Hovold module_phy_driver(ksphy_driver);
1019d0507009SDavid J. Choi 
1020d0507009SDavid J. Choi MODULE_DESCRIPTION("Micrel PHY driver");
1021d0507009SDavid J. Choi MODULE_AUTHOR("David J. Choi");
1022d0507009SDavid J. Choi MODULE_LICENSE("GPL");
102352a60ed2SDavid S. Miller 
1024cf93c945SUwe Kleine-König static struct mdio_device_id __maybe_unused micrel_tbl[] = {
102548d7d0adSJason Wang 	{ PHY_ID_KSZ9021, 0x000ffffe },
1026f893a99eSFabio Estevam 	{ PHY_ID_KSZ9031, MICREL_PHY_ID_MASK },
1027ecd5a323SAlexander Stein 	{ PHY_ID_KSZ8001, 0x00fffffc },
1028f893a99eSFabio Estevam 	{ PHY_ID_KS8737, MICREL_PHY_ID_MASK },
1029212ea99aSMarek Vasut 	{ PHY_ID_KSZ8021, 0x00ffffff },
1030b818d1a7SHector Palacios 	{ PHY_ID_KSZ8031, 0x00ffffff },
1031f893a99eSFabio Estevam 	{ PHY_ID_KSZ8041, MICREL_PHY_ID_MASK },
1032f893a99eSFabio Estevam 	{ PHY_ID_KSZ8051, MICREL_PHY_ID_MASK },
1033f893a99eSFabio Estevam 	{ PHY_ID_KSZ8061, MICREL_PHY_ID_MASK },
1034f893a99eSFabio Estevam 	{ PHY_ID_KSZ8081, MICREL_PHY_ID_MASK },
1035f893a99eSFabio Estevam 	{ PHY_ID_KSZ8873MLL, MICREL_PHY_ID_MASK },
1036f893a99eSFabio Estevam 	{ PHY_ID_KSZ886X, MICREL_PHY_ID_MASK },
103752a60ed2SDavid S. Miller 	{ }
103852a60ed2SDavid S. Miller };
103952a60ed2SDavid S. Miller 
104052a60ed2SDavid S. Miller MODULE_DEVICE_TABLE(mdio, micrel_tbl);
1041