xref: /openbmc/linux/drivers/net/phy/micrel.c (revision b4c19f71252e3b6b8c6478fd712c592f00b11438)
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 
76e6a423a8SJohan Hovold struct kszphy_type {
77e6a423a8SJohan Hovold 	u32 led_mode_reg;
78c6f9575cSJohan Hovold 	u16 interrupt_level_mask;
790f95903eSJohan Hovold 	bool has_broadcast_disable;
802b0ba96cSSylvain Rochet 	bool has_nand_tree_disable;
8163f44b2bSJohan Hovold 	bool has_rmii_ref_clk_sel;
82e6a423a8SJohan Hovold };
83e6a423a8SJohan Hovold 
84e6a423a8SJohan Hovold struct kszphy_priv {
85e6a423a8SJohan Hovold 	const struct kszphy_type *type;
86e7a792e9SJohan Hovold 	int led_mode;
8763f44b2bSJohan Hovold 	bool rmii_ref_clk_sel;
8863f44b2bSJohan Hovold 	bool rmii_ref_clk_sel_val;
89e6a423a8SJohan Hovold };
90e6a423a8SJohan Hovold 
91e6a423a8SJohan Hovold static const struct kszphy_type ksz8021_type = {
92e6a423a8SJohan Hovold 	.led_mode_reg		= MII_KSZPHY_CTRL_2,
93d0e1df9cSJohan Hovold 	.has_broadcast_disable	= true,
942b0ba96cSSylvain Rochet 	.has_nand_tree_disable	= true,
9563f44b2bSJohan Hovold 	.has_rmii_ref_clk_sel	= true,
96e6a423a8SJohan Hovold };
97e6a423a8SJohan Hovold 
98e6a423a8SJohan Hovold static const struct kszphy_type ksz8041_type = {
99e6a423a8SJohan Hovold 	.led_mode_reg		= MII_KSZPHY_CTRL_1,
100e6a423a8SJohan Hovold };
101e6a423a8SJohan Hovold 
102e6a423a8SJohan Hovold static const struct kszphy_type ksz8051_type = {
103e6a423a8SJohan Hovold 	.led_mode_reg		= MII_KSZPHY_CTRL_2,
1042b0ba96cSSylvain Rochet 	.has_nand_tree_disable	= true,
105e6a423a8SJohan Hovold };
106e6a423a8SJohan Hovold 
107e6a423a8SJohan Hovold static const struct kszphy_type ksz8081_type = {
108e6a423a8SJohan Hovold 	.led_mode_reg		= MII_KSZPHY_CTRL_2,
1090f95903eSJohan Hovold 	.has_broadcast_disable	= true,
1102b0ba96cSSylvain Rochet 	.has_nand_tree_disable	= true,
11186dc1342SJohan Hovold 	.has_rmii_ref_clk_sel	= true,
112e6a423a8SJohan Hovold };
113e6a423a8SJohan Hovold 
114c6f9575cSJohan Hovold static const struct kszphy_type ks8737_type = {
115c6f9575cSJohan Hovold 	.interrupt_level_mask	= BIT(14),
116c6f9575cSJohan Hovold };
117c6f9575cSJohan Hovold 
118c6f9575cSJohan Hovold static const struct kszphy_type ksz9021_type = {
119c6f9575cSJohan Hovold 	.interrupt_level_mask	= BIT(14),
120c6f9575cSJohan Hovold };
121c6f9575cSJohan Hovold 
122954c3967SSean Cross static int kszphy_extended_write(struct phy_device *phydev,
123954c3967SSean Cross 				u32 regnum, u16 val)
124954c3967SSean Cross {
125954c3967SSean Cross 	phy_write(phydev, MII_KSZPHY_EXTREG, KSZPHY_EXTREG_WRITE | regnum);
126954c3967SSean Cross 	return phy_write(phydev, MII_KSZPHY_EXTREG_WRITE, val);
127954c3967SSean Cross }
128954c3967SSean Cross 
129954c3967SSean Cross static int kszphy_extended_read(struct phy_device *phydev,
130954c3967SSean Cross 				u32 regnum)
131954c3967SSean Cross {
132954c3967SSean Cross 	phy_write(phydev, MII_KSZPHY_EXTREG, regnum);
133954c3967SSean Cross 	return phy_read(phydev, MII_KSZPHY_EXTREG_READ);
134954c3967SSean Cross }
135954c3967SSean Cross 
13651f932c4SChoi, David static int kszphy_ack_interrupt(struct phy_device *phydev)
13751f932c4SChoi, David {
13851f932c4SChoi, David 	/* bit[7..0] int status, which is a read and clear register. */
13951f932c4SChoi, David 	int rc;
14051f932c4SChoi, David 
14151f932c4SChoi, David 	rc = phy_read(phydev, MII_KSZPHY_INTCS);
14251f932c4SChoi, David 
14351f932c4SChoi, David 	return (rc < 0) ? rc : 0;
14451f932c4SChoi, David }
14551f932c4SChoi, David 
14651f932c4SChoi, David static int kszphy_config_intr(struct phy_device *phydev)
14751f932c4SChoi, David {
148c6f9575cSJohan Hovold 	const struct kszphy_type *type = phydev->drv->driver_data;
149c6f9575cSJohan Hovold 	int temp;
150c6f9575cSJohan Hovold 	u16 mask;
151c6f9575cSJohan Hovold 
152c6f9575cSJohan Hovold 	if (type && type->interrupt_level_mask)
153c6f9575cSJohan Hovold 		mask = type->interrupt_level_mask;
154c6f9575cSJohan Hovold 	else
155c6f9575cSJohan Hovold 		mask = KSZPHY_CTRL_INT_ACTIVE_HIGH;
15651f932c4SChoi, David 
15751f932c4SChoi, David 	/* set the interrupt pin active low */
15851f932c4SChoi, David 	temp = phy_read(phydev, MII_KSZPHY_CTRL);
1595bb8fc0dSJohan Hovold 	if (temp < 0)
1605bb8fc0dSJohan Hovold 		return temp;
161c6f9575cSJohan Hovold 	temp &= ~mask;
16251f932c4SChoi, David 	phy_write(phydev, MII_KSZPHY_CTRL, temp);
16351f932c4SChoi, David 
164c6f9575cSJohan Hovold 	/* enable / disable interrupts */
165c6f9575cSJohan Hovold 	if (phydev->interrupts == PHY_INTERRUPT_ENABLED)
166c6f9575cSJohan Hovold 		temp = KSZPHY_INTCS_ALL;
167c6f9575cSJohan Hovold 	else
168c6f9575cSJohan Hovold 		temp = 0;
16951f932c4SChoi, David 
170c6f9575cSJohan Hovold 	return phy_write(phydev, MII_KSZPHY_INTCS, temp);
17151f932c4SChoi, David }
172d0507009SDavid J. Choi 
17363f44b2bSJohan Hovold static int kszphy_rmii_clk_sel(struct phy_device *phydev, bool val)
17463f44b2bSJohan Hovold {
17563f44b2bSJohan Hovold 	int ctrl;
17663f44b2bSJohan Hovold 
17763f44b2bSJohan Hovold 	ctrl = phy_read(phydev, MII_KSZPHY_CTRL);
17863f44b2bSJohan Hovold 	if (ctrl < 0)
17963f44b2bSJohan Hovold 		return ctrl;
18063f44b2bSJohan Hovold 
18163f44b2bSJohan Hovold 	if (val)
18263f44b2bSJohan Hovold 		ctrl |= KSZPHY_RMII_REF_CLK_SEL;
18363f44b2bSJohan Hovold 	else
18463f44b2bSJohan Hovold 		ctrl &= ~KSZPHY_RMII_REF_CLK_SEL;
18563f44b2bSJohan Hovold 
18663f44b2bSJohan Hovold 	return phy_write(phydev, MII_KSZPHY_CTRL, ctrl);
18763f44b2bSJohan Hovold }
18863f44b2bSJohan Hovold 
189e7a792e9SJohan Hovold static int kszphy_setup_led(struct phy_device *phydev, u32 reg, int val)
19020d8435aSBen Dooks {
1915a16778eSJohan Hovold 	int rc, temp, shift;
1928620546cSJohan Hovold 
1935a16778eSJohan Hovold 	switch (reg) {
1945a16778eSJohan Hovold 	case MII_KSZPHY_CTRL_1:
1955a16778eSJohan Hovold 		shift = 14;
1965a16778eSJohan Hovold 		break;
1975a16778eSJohan Hovold 	case MII_KSZPHY_CTRL_2:
1985a16778eSJohan Hovold 		shift = 4;
1995a16778eSJohan Hovold 		break;
2005a16778eSJohan Hovold 	default:
2015a16778eSJohan Hovold 		return -EINVAL;
2025a16778eSJohan Hovold 	}
2035a16778eSJohan Hovold 
20420d8435aSBen Dooks 	temp = phy_read(phydev, reg);
205b7035860SJohan Hovold 	if (temp < 0) {
206b7035860SJohan Hovold 		rc = temp;
207b7035860SJohan Hovold 		goto out;
208b7035860SJohan Hovold 	}
20920d8435aSBen Dooks 
21028bdc499SSergei Shtylyov 	temp &= ~(3 << shift);
21120d8435aSBen Dooks 	temp |= val << shift;
21220d8435aSBen Dooks 	rc = phy_write(phydev, reg, temp);
213b7035860SJohan Hovold out:
214b7035860SJohan Hovold 	if (rc < 0)
215b7035860SJohan Hovold 		dev_err(&phydev->dev, "failed to set led mode\n");
21620d8435aSBen Dooks 
217b7035860SJohan Hovold 	return rc;
21820d8435aSBen Dooks }
21920d8435aSBen Dooks 
220bde15129SJohan Hovold /* Disable PHY address 0 as the broadcast address, so that it can be used as a
221bde15129SJohan Hovold  * unique (non-broadcast) address on a shared bus.
222bde15129SJohan Hovold  */
223bde15129SJohan Hovold static int kszphy_broadcast_disable(struct phy_device *phydev)
224bde15129SJohan Hovold {
225bde15129SJohan Hovold 	int ret;
226bde15129SJohan Hovold 
227bde15129SJohan Hovold 	ret = phy_read(phydev, MII_KSZPHY_OMSO);
228bde15129SJohan Hovold 	if (ret < 0)
229bde15129SJohan Hovold 		goto out;
230bde15129SJohan Hovold 
231bde15129SJohan Hovold 	ret = phy_write(phydev, MII_KSZPHY_OMSO, ret | KSZPHY_OMSO_B_CAST_OFF);
232bde15129SJohan Hovold out:
233bde15129SJohan Hovold 	if (ret)
234bde15129SJohan Hovold 		dev_err(&phydev->dev, "failed to disable broadcast address\n");
235bde15129SJohan Hovold 
236bde15129SJohan Hovold 	return ret;
237bde15129SJohan Hovold }
238bde15129SJohan Hovold 
2392b0ba96cSSylvain Rochet static int kszphy_nand_tree_disable(struct phy_device *phydev)
2402b0ba96cSSylvain Rochet {
2412b0ba96cSSylvain Rochet 	int ret;
2422b0ba96cSSylvain Rochet 
2432b0ba96cSSylvain Rochet 	ret = phy_read(phydev, MII_KSZPHY_OMSO);
2442b0ba96cSSylvain Rochet 	if (ret < 0)
2452b0ba96cSSylvain Rochet 		goto out;
2462b0ba96cSSylvain Rochet 
2472b0ba96cSSylvain Rochet 	if (!(ret & KSZPHY_OMSO_NAND_TREE_ON))
2482b0ba96cSSylvain Rochet 		return 0;
2492b0ba96cSSylvain Rochet 
2502b0ba96cSSylvain Rochet 	ret = phy_write(phydev, MII_KSZPHY_OMSO,
2512b0ba96cSSylvain Rochet 			ret & ~KSZPHY_OMSO_NAND_TREE_ON);
2522b0ba96cSSylvain Rochet out:
2532b0ba96cSSylvain Rochet 	if (ret)
2542b0ba96cSSylvain Rochet 		dev_err(&phydev->dev, "failed to disable NAND tree mode\n");
2552b0ba96cSSylvain Rochet 
2562b0ba96cSSylvain Rochet 	return ret;
2572b0ba96cSSylvain Rochet }
2582b0ba96cSSylvain Rochet 
259d0507009SDavid J. Choi static int kszphy_config_init(struct phy_device *phydev)
260d0507009SDavid J. Choi {
261e6a423a8SJohan Hovold 	struct kszphy_priv *priv = phydev->priv;
262e6a423a8SJohan Hovold 	const struct kszphy_type *type;
26363f44b2bSJohan Hovold 	int ret;
264d0507009SDavid J. Choi 
265e6a423a8SJohan Hovold 	if (!priv)
266e6a423a8SJohan Hovold 		return 0;
267e6a423a8SJohan Hovold 
268e6a423a8SJohan Hovold 	type = priv->type;
269e6a423a8SJohan Hovold 
2700f95903eSJohan Hovold 	if (type->has_broadcast_disable)
2710f95903eSJohan Hovold 		kszphy_broadcast_disable(phydev);
2720f95903eSJohan Hovold 
2732b0ba96cSSylvain Rochet 	if (type->has_nand_tree_disable)
2742b0ba96cSSylvain Rochet 		kszphy_nand_tree_disable(phydev);
2752b0ba96cSSylvain Rochet 
27663f44b2bSJohan Hovold 	if (priv->rmii_ref_clk_sel) {
27763f44b2bSJohan Hovold 		ret = kszphy_rmii_clk_sel(phydev, priv->rmii_ref_clk_sel_val);
27863f44b2bSJohan Hovold 		if (ret) {
27963f44b2bSJohan Hovold 			dev_err(&phydev->dev, "failed to set rmii reference clock\n");
28063f44b2bSJohan Hovold 			return ret;
28163f44b2bSJohan Hovold 		}
28263f44b2bSJohan Hovold 	}
28363f44b2bSJohan Hovold 
284e7a792e9SJohan Hovold 	if (priv->led_mode >= 0)
285e7a792e9SJohan Hovold 		kszphy_setup_led(phydev, type->led_mode_reg, priv->led_mode);
286e6a423a8SJohan Hovold 
287e6a423a8SJohan Hovold 	return 0;
28820d8435aSBen Dooks }
28920d8435aSBen Dooks 
290954c3967SSean Cross static int ksz9021_load_values_from_of(struct phy_device *phydev,
2913c9a9f7fSJaeden Amero 				       const struct device_node *of_node,
2923c9a9f7fSJaeden Amero 				       u16 reg,
2933c9a9f7fSJaeden Amero 				       const char *field1, const char *field2,
2943c9a9f7fSJaeden Amero 				       const char *field3, const char *field4)
295954c3967SSean Cross {
296954c3967SSean Cross 	int val1 = -1;
297954c3967SSean Cross 	int val2 = -2;
298954c3967SSean Cross 	int val3 = -3;
299954c3967SSean Cross 	int val4 = -4;
300954c3967SSean Cross 	int newval;
301954c3967SSean Cross 	int matches = 0;
302954c3967SSean Cross 
303954c3967SSean Cross 	if (!of_property_read_u32(of_node, field1, &val1))
304954c3967SSean Cross 		matches++;
305954c3967SSean Cross 
306954c3967SSean Cross 	if (!of_property_read_u32(of_node, field2, &val2))
307954c3967SSean Cross 		matches++;
308954c3967SSean Cross 
309954c3967SSean Cross 	if (!of_property_read_u32(of_node, field3, &val3))
310954c3967SSean Cross 		matches++;
311954c3967SSean Cross 
312954c3967SSean Cross 	if (!of_property_read_u32(of_node, field4, &val4))
313954c3967SSean Cross 		matches++;
314954c3967SSean Cross 
315954c3967SSean Cross 	if (!matches)
316954c3967SSean Cross 		return 0;
317954c3967SSean Cross 
318954c3967SSean Cross 	if (matches < 4)
319954c3967SSean Cross 		newval = kszphy_extended_read(phydev, reg);
320954c3967SSean Cross 	else
321954c3967SSean Cross 		newval = 0;
322954c3967SSean Cross 
323954c3967SSean Cross 	if (val1 != -1)
324954c3967SSean Cross 		newval = ((newval & 0xfff0) | ((val1 / PS_TO_REG) & 0xf) << 0);
325954c3967SSean Cross 
3266a119745SHubert Chaumette 	if (val2 != -2)
327954c3967SSean Cross 		newval = ((newval & 0xff0f) | ((val2 / PS_TO_REG) & 0xf) << 4);
328954c3967SSean Cross 
3296a119745SHubert Chaumette 	if (val3 != -3)
330954c3967SSean Cross 		newval = ((newval & 0xf0ff) | ((val3 / PS_TO_REG) & 0xf) << 8);
331954c3967SSean Cross 
3326a119745SHubert Chaumette 	if (val4 != -4)
333954c3967SSean Cross 		newval = ((newval & 0x0fff) | ((val4 / PS_TO_REG) & 0xf) << 12);
334954c3967SSean Cross 
335954c3967SSean Cross 	return kszphy_extended_write(phydev, reg, newval);
336954c3967SSean Cross }
337954c3967SSean Cross 
338954c3967SSean Cross static int ksz9021_config_init(struct phy_device *phydev)
339954c3967SSean Cross {
3403c9a9f7fSJaeden Amero 	const struct device *dev = &phydev->dev;
3413c9a9f7fSJaeden Amero 	const struct device_node *of_node = dev->of_node;
342651df218SAndrew Lunn 	const struct device *dev_walker;
343954c3967SSean Cross 
344651df218SAndrew Lunn 	/* The Micrel driver has a deprecated option to place phy OF
345651df218SAndrew Lunn 	 * properties in the MAC node. Walk up the tree of devices to
346651df218SAndrew Lunn 	 * find a device with an OF node.
347651df218SAndrew Lunn 	 */
348651df218SAndrew Lunn 	dev_walker = &phydev->dev;
349651df218SAndrew Lunn 	do {
350651df218SAndrew Lunn 		of_node = dev_walker->of_node;
351651df218SAndrew Lunn 		dev_walker = dev_walker->parent;
352651df218SAndrew Lunn 
353651df218SAndrew Lunn 	} while (!of_node && dev_walker);
354954c3967SSean Cross 
355954c3967SSean Cross 	if (of_node) {
356954c3967SSean Cross 		ksz9021_load_values_from_of(phydev, of_node,
357954c3967SSean Cross 				    MII_KSZPHY_CLK_CONTROL_PAD_SKEW,
358954c3967SSean Cross 				    "txen-skew-ps", "txc-skew-ps",
359954c3967SSean Cross 				    "rxdv-skew-ps", "rxc-skew-ps");
360954c3967SSean Cross 		ksz9021_load_values_from_of(phydev, of_node,
361954c3967SSean Cross 				    MII_KSZPHY_RX_DATA_PAD_SKEW,
362954c3967SSean Cross 				    "rxd0-skew-ps", "rxd1-skew-ps",
363954c3967SSean Cross 				    "rxd2-skew-ps", "rxd3-skew-ps");
364954c3967SSean Cross 		ksz9021_load_values_from_of(phydev, of_node,
365954c3967SSean Cross 				    MII_KSZPHY_TX_DATA_PAD_SKEW,
366954c3967SSean Cross 				    "txd0-skew-ps", "txd1-skew-ps",
367954c3967SSean Cross 				    "txd2-skew-ps", "txd3-skew-ps");
368954c3967SSean Cross 	}
369954c3967SSean Cross 	return 0;
370954c3967SSean Cross }
371954c3967SSean Cross 
3726e4b8273SHubert Chaumette #define MII_KSZ9031RN_MMD_CTRL_REG	0x0d
3736e4b8273SHubert Chaumette #define MII_KSZ9031RN_MMD_REGDATA_REG	0x0e
3746e4b8273SHubert Chaumette #define OP_DATA				1
3756e4b8273SHubert Chaumette #define KSZ9031_PS_TO_REG		60
3766e4b8273SHubert Chaumette 
3776e4b8273SHubert Chaumette /* Extended registers */
3786270e1aeSJaeden Amero /* MMD Address 0x0 */
3796270e1aeSJaeden Amero #define MII_KSZ9031RN_FLP_BURST_TX_LO	3
3806270e1aeSJaeden Amero #define MII_KSZ9031RN_FLP_BURST_TX_HI	4
3816270e1aeSJaeden Amero 
382ae6c97bbSJaeden Amero /* MMD Address 0x2 */
3836e4b8273SHubert Chaumette #define MII_KSZ9031RN_CONTROL_PAD_SKEW	4
3846e4b8273SHubert Chaumette #define MII_KSZ9031RN_RX_DATA_PAD_SKEW	5
3856e4b8273SHubert Chaumette #define MII_KSZ9031RN_TX_DATA_PAD_SKEW	6
3866e4b8273SHubert Chaumette #define MII_KSZ9031RN_CLK_PAD_SKEW	8
3876e4b8273SHubert Chaumette 
3886e4b8273SHubert Chaumette static int ksz9031_extended_write(struct phy_device *phydev,
3896e4b8273SHubert Chaumette 				  u8 mode, u32 dev_addr, u32 regnum, u16 val)
3906e4b8273SHubert Chaumette {
3916e4b8273SHubert Chaumette 	phy_write(phydev, MII_KSZ9031RN_MMD_CTRL_REG, dev_addr);
3926e4b8273SHubert Chaumette 	phy_write(phydev, MII_KSZ9031RN_MMD_REGDATA_REG, regnum);
3936e4b8273SHubert Chaumette 	phy_write(phydev, MII_KSZ9031RN_MMD_CTRL_REG, (mode << 14) | dev_addr);
3946e4b8273SHubert Chaumette 	return phy_write(phydev, MII_KSZ9031RN_MMD_REGDATA_REG, val);
3956e4b8273SHubert Chaumette }
3966e4b8273SHubert Chaumette 
3976e4b8273SHubert Chaumette static int ksz9031_extended_read(struct phy_device *phydev,
3986e4b8273SHubert Chaumette 				 u8 mode, u32 dev_addr, u32 regnum)
3996e4b8273SHubert Chaumette {
4006e4b8273SHubert Chaumette 	phy_write(phydev, MII_KSZ9031RN_MMD_CTRL_REG, dev_addr);
4016e4b8273SHubert Chaumette 	phy_write(phydev, MII_KSZ9031RN_MMD_REGDATA_REG, regnum);
4026e4b8273SHubert Chaumette 	phy_write(phydev, MII_KSZ9031RN_MMD_CTRL_REG, (mode << 14) | dev_addr);
4036e4b8273SHubert Chaumette 	return phy_read(phydev, MII_KSZ9031RN_MMD_REGDATA_REG);
4046e4b8273SHubert Chaumette }
4056e4b8273SHubert Chaumette 
4066e4b8273SHubert Chaumette static int ksz9031_of_load_skew_values(struct phy_device *phydev,
4073c9a9f7fSJaeden Amero 				       const struct device_node *of_node,
4086e4b8273SHubert Chaumette 				       u16 reg, size_t field_sz,
4093c9a9f7fSJaeden Amero 				       const char *field[], u8 numfields)
4106e4b8273SHubert Chaumette {
4116e4b8273SHubert Chaumette 	int val[4] = {-1, -2, -3, -4};
4126e4b8273SHubert Chaumette 	int matches = 0;
4136e4b8273SHubert Chaumette 	u16 mask;
4146e4b8273SHubert Chaumette 	u16 maxval;
4156e4b8273SHubert Chaumette 	u16 newval;
4166e4b8273SHubert Chaumette 	int i;
4176e4b8273SHubert Chaumette 
4186e4b8273SHubert Chaumette 	for (i = 0; i < numfields; i++)
4196e4b8273SHubert Chaumette 		if (!of_property_read_u32(of_node, field[i], val + i))
4206e4b8273SHubert Chaumette 			matches++;
4216e4b8273SHubert Chaumette 
4226e4b8273SHubert Chaumette 	if (!matches)
4236e4b8273SHubert Chaumette 		return 0;
4246e4b8273SHubert Chaumette 
4256e4b8273SHubert Chaumette 	if (matches < numfields)
4266e4b8273SHubert Chaumette 		newval = ksz9031_extended_read(phydev, OP_DATA, 2, reg);
4276e4b8273SHubert Chaumette 	else
4286e4b8273SHubert Chaumette 		newval = 0;
4296e4b8273SHubert Chaumette 
4306e4b8273SHubert Chaumette 	maxval = (field_sz == 4) ? 0xf : 0x1f;
4316e4b8273SHubert Chaumette 	for (i = 0; i < numfields; i++)
4326e4b8273SHubert Chaumette 		if (val[i] != -(i + 1)) {
4336e4b8273SHubert Chaumette 			mask = 0xffff;
4346e4b8273SHubert Chaumette 			mask ^= maxval << (field_sz * i);
4356e4b8273SHubert Chaumette 			newval = (newval & mask) |
4366e4b8273SHubert Chaumette 				(((val[i] / KSZ9031_PS_TO_REG) & maxval)
4376e4b8273SHubert Chaumette 					<< (field_sz * i));
4386e4b8273SHubert Chaumette 		}
4396e4b8273SHubert Chaumette 
4406e4b8273SHubert Chaumette 	return ksz9031_extended_write(phydev, OP_DATA, 2, reg, newval);
4416e4b8273SHubert Chaumette }
4426e4b8273SHubert Chaumette 
4436270e1aeSJaeden Amero static int ksz9031_center_flp_timing(struct phy_device *phydev)
4446270e1aeSJaeden Amero {
4456270e1aeSJaeden Amero 	int result;
4466270e1aeSJaeden Amero 
4476270e1aeSJaeden Amero 	/* Center KSZ9031RNX FLP timing at 16ms. */
4486270e1aeSJaeden Amero 	result = ksz9031_extended_write(phydev, OP_DATA, 0,
4496270e1aeSJaeden Amero 					MII_KSZ9031RN_FLP_BURST_TX_HI, 0x0006);
4506270e1aeSJaeden Amero 	result = ksz9031_extended_write(phydev, OP_DATA, 0,
4516270e1aeSJaeden Amero 					MII_KSZ9031RN_FLP_BURST_TX_LO, 0x1A80);
4526270e1aeSJaeden Amero 
4536270e1aeSJaeden Amero 	if (result)
4546270e1aeSJaeden Amero 		return result;
4556270e1aeSJaeden Amero 
4566270e1aeSJaeden Amero 	return genphy_restart_aneg(phydev);
4576270e1aeSJaeden Amero }
4586270e1aeSJaeden Amero 
4596e4b8273SHubert Chaumette static int ksz9031_config_init(struct phy_device *phydev)
4606e4b8273SHubert Chaumette {
4613c9a9f7fSJaeden Amero 	const struct device *dev = &phydev->dev;
4623c9a9f7fSJaeden Amero 	const struct device_node *of_node = dev->of_node;
4633c9a9f7fSJaeden Amero 	static const char *clk_skews[2] = {"rxc-skew-ps", "txc-skew-ps"};
4643c9a9f7fSJaeden Amero 	static const char *rx_data_skews[4] = {
4656e4b8273SHubert Chaumette 		"rxd0-skew-ps", "rxd1-skew-ps",
4666e4b8273SHubert Chaumette 		"rxd2-skew-ps", "rxd3-skew-ps"
4676e4b8273SHubert Chaumette 	};
4683c9a9f7fSJaeden Amero 	static const char *tx_data_skews[4] = {
4696e4b8273SHubert Chaumette 		"txd0-skew-ps", "txd1-skew-ps",
4706e4b8273SHubert Chaumette 		"txd2-skew-ps", "txd3-skew-ps"
4716e4b8273SHubert Chaumette 	};
4723c9a9f7fSJaeden Amero 	static const char *control_skews[2] = {"txen-skew-ps", "rxdv-skew-ps"};
473*b4c19f71SRoosen Henri 	const struct device *dev_walker;
4746e4b8273SHubert Chaumette 
475*b4c19f71SRoosen Henri 	/* The Micrel driver has a deprecated option to place phy OF
476*b4c19f71SRoosen Henri 	 * properties in the MAC node. Walk up the tree of devices to
477*b4c19f71SRoosen Henri 	 * find a device with an OF node.
478*b4c19f71SRoosen Henri 	 */
479*b4c19f71SRoosen Henri 	dev_walker = &phydev->dev;
480*b4c19f71SRoosen Henri 	do {
481*b4c19f71SRoosen Henri 		of_node = dev_walker->of_node;
482*b4c19f71SRoosen Henri 		dev_walker = dev_walker->parent;
483*b4c19f71SRoosen Henri 	} while (!of_node && dev_walker);
4846e4b8273SHubert Chaumette 
4856e4b8273SHubert Chaumette 	if (of_node) {
4866e4b8273SHubert Chaumette 		ksz9031_of_load_skew_values(phydev, of_node,
4876e4b8273SHubert Chaumette 				MII_KSZ9031RN_CLK_PAD_SKEW, 5,
4886e4b8273SHubert Chaumette 				clk_skews, 2);
4896e4b8273SHubert Chaumette 
4906e4b8273SHubert Chaumette 		ksz9031_of_load_skew_values(phydev, of_node,
4916e4b8273SHubert Chaumette 				MII_KSZ9031RN_CONTROL_PAD_SKEW, 4,
4926e4b8273SHubert Chaumette 				control_skews, 2);
4936e4b8273SHubert Chaumette 
4946e4b8273SHubert Chaumette 		ksz9031_of_load_skew_values(phydev, of_node,
4956e4b8273SHubert Chaumette 				MII_KSZ9031RN_RX_DATA_PAD_SKEW, 4,
4966e4b8273SHubert Chaumette 				rx_data_skews, 4);
4976e4b8273SHubert Chaumette 
4986e4b8273SHubert Chaumette 		ksz9031_of_load_skew_values(phydev, of_node,
4996e4b8273SHubert Chaumette 				MII_KSZ9031RN_TX_DATA_PAD_SKEW, 4,
5006e4b8273SHubert Chaumette 				tx_data_skews, 4);
5016e4b8273SHubert Chaumette 	}
5026270e1aeSJaeden Amero 
5036270e1aeSJaeden Amero 	return ksz9031_center_flp_timing(phydev);
5046e4b8273SHubert Chaumette }
5056e4b8273SHubert Chaumette 
50693272e07SJean-Christophe PLAGNIOL-VILLARD #define KSZ8873MLL_GLOBAL_CONTROL_4	0x06
50700aee095SJohan Hovold #define KSZ8873MLL_GLOBAL_CONTROL_4_DUPLEX	BIT(6)
50800aee095SJohan Hovold #define KSZ8873MLL_GLOBAL_CONTROL_4_SPEED	BIT(4)
50932d73b14SJingoo Han static int ksz8873mll_read_status(struct phy_device *phydev)
51093272e07SJean-Christophe PLAGNIOL-VILLARD {
51193272e07SJean-Christophe PLAGNIOL-VILLARD 	int regval;
51293272e07SJean-Christophe PLAGNIOL-VILLARD 
51393272e07SJean-Christophe PLAGNIOL-VILLARD 	/* dummy read */
51493272e07SJean-Christophe PLAGNIOL-VILLARD 	regval = phy_read(phydev, KSZ8873MLL_GLOBAL_CONTROL_4);
51593272e07SJean-Christophe PLAGNIOL-VILLARD 
51693272e07SJean-Christophe PLAGNIOL-VILLARD 	regval = phy_read(phydev, KSZ8873MLL_GLOBAL_CONTROL_4);
51793272e07SJean-Christophe PLAGNIOL-VILLARD 
51893272e07SJean-Christophe PLAGNIOL-VILLARD 	if (regval & KSZ8873MLL_GLOBAL_CONTROL_4_DUPLEX)
51993272e07SJean-Christophe PLAGNIOL-VILLARD 		phydev->duplex = DUPLEX_HALF;
52093272e07SJean-Christophe PLAGNIOL-VILLARD 	else
52193272e07SJean-Christophe PLAGNIOL-VILLARD 		phydev->duplex = DUPLEX_FULL;
52293272e07SJean-Christophe PLAGNIOL-VILLARD 
52393272e07SJean-Christophe PLAGNIOL-VILLARD 	if (regval & KSZ8873MLL_GLOBAL_CONTROL_4_SPEED)
52493272e07SJean-Christophe PLAGNIOL-VILLARD 		phydev->speed = SPEED_10;
52593272e07SJean-Christophe PLAGNIOL-VILLARD 	else
52693272e07SJean-Christophe PLAGNIOL-VILLARD 		phydev->speed = SPEED_100;
52793272e07SJean-Christophe PLAGNIOL-VILLARD 
52893272e07SJean-Christophe PLAGNIOL-VILLARD 	phydev->link = 1;
52993272e07SJean-Christophe PLAGNIOL-VILLARD 	phydev->pause = phydev->asym_pause = 0;
53093272e07SJean-Christophe PLAGNIOL-VILLARD 
53193272e07SJean-Christophe PLAGNIOL-VILLARD 	return 0;
53293272e07SJean-Christophe PLAGNIOL-VILLARD }
53393272e07SJean-Christophe PLAGNIOL-VILLARD 
534d2fd719bSNathan Sullivan static int ksz9031_read_status(struct phy_device *phydev)
535d2fd719bSNathan Sullivan {
536d2fd719bSNathan Sullivan 	int err;
537d2fd719bSNathan Sullivan 	int regval;
538d2fd719bSNathan Sullivan 
539d2fd719bSNathan Sullivan 	err = genphy_read_status(phydev);
540d2fd719bSNathan Sullivan 	if (err)
541d2fd719bSNathan Sullivan 		return err;
542d2fd719bSNathan Sullivan 
543d2fd719bSNathan Sullivan 	/* Make sure the PHY is not broken. Read idle error count,
544d2fd719bSNathan Sullivan 	 * and reset the PHY if it is maxed out.
545d2fd719bSNathan Sullivan 	 */
546d2fd719bSNathan Sullivan 	regval = phy_read(phydev, MII_STAT1000);
547d2fd719bSNathan Sullivan 	if ((regval & 0xFF) == 0xFF) {
548d2fd719bSNathan Sullivan 		phy_init_hw(phydev);
549d2fd719bSNathan Sullivan 		phydev->link = 0;
550d2fd719bSNathan Sullivan 	}
551d2fd719bSNathan Sullivan 
552d2fd719bSNathan Sullivan 	return 0;
553d2fd719bSNathan Sullivan }
554d2fd719bSNathan Sullivan 
55593272e07SJean-Christophe PLAGNIOL-VILLARD static int ksz8873mll_config_aneg(struct phy_device *phydev)
55693272e07SJean-Christophe PLAGNIOL-VILLARD {
55793272e07SJean-Christophe PLAGNIOL-VILLARD 	return 0;
55893272e07SJean-Christophe PLAGNIOL-VILLARD }
55993272e07SJean-Christophe PLAGNIOL-VILLARD 
56019936942SVince Bridgers /* This routine returns -1 as an indication to the caller that the
56119936942SVince Bridgers  * Micrel ksz9021 10/100/1000 PHY does not support standard IEEE
56219936942SVince Bridgers  * MMD extended PHY registers.
56319936942SVince Bridgers  */
56419936942SVince Bridgers static int
56519936942SVince Bridgers ksz9021_rd_mmd_phyreg(struct phy_device *phydev, int ptrad, int devnum,
56619936942SVince Bridgers 		      int regnum)
56719936942SVince Bridgers {
56819936942SVince Bridgers 	return -1;
56919936942SVince Bridgers }
57019936942SVince Bridgers 
57119936942SVince Bridgers /* This routine does nothing since the Micrel ksz9021 does not support
57219936942SVince Bridgers  * standard IEEE MMD extended PHY registers.
57319936942SVince Bridgers  */
57419936942SVince Bridgers static void
57519936942SVince Bridgers ksz9021_wr_mmd_phyreg(struct phy_device *phydev, int ptrad, int devnum,
57619936942SVince Bridgers 		      int regnum, u32 val)
57719936942SVince Bridgers {
57819936942SVince Bridgers }
57919936942SVince Bridgers 
580e6a423a8SJohan Hovold static int kszphy_probe(struct phy_device *phydev)
581e6a423a8SJohan Hovold {
582e6a423a8SJohan Hovold 	const struct kszphy_type *type = phydev->drv->driver_data;
5833c9a9f7fSJaeden Amero 	const struct device_node *np = phydev->dev.of_node;
584e6a423a8SJohan Hovold 	struct kszphy_priv *priv;
58563f44b2bSJohan Hovold 	struct clk *clk;
586e7a792e9SJohan Hovold 	int ret;
587e6a423a8SJohan Hovold 
588e6a423a8SJohan Hovold 	priv = devm_kzalloc(&phydev->dev, sizeof(*priv), GFP_KERNEL);
589e6a423a8SJohan Hovold 	if (!priv)
590e6a423a8SJohan Hovold 		return -ENOMEM;
591e6a423a8SJohan Hovold 
592e6a423a8SJohan Hovold 	phydev->priv = priv;
593e6a423a8SJohan Hovold 
594e6a423a8SJohan Hovold 	priv->type = type;
595e6a423a8SJohan Hovold 
596e7a792e9SJohan Hovold 	if (type->led_mode_reg) {
597e7a792e9SJohan Hovold 		ret = of_property_read_u32(np, "micrel,led-mode",
598e7a792e9SJohan Hovold 				&priv->led_mode);
599e7a792e9SJohan Hovold 		if (ret)
600e7a792e9SJohan Hovold 			priv->led_mode = -1;
601e7a792e9SJohan Hovold 
602e7a792e9SJohan Hovold 		if (priv->led_mode > 3) {
603e7a792e9SJohan Hovold 			dev_err(&phydev->dev, "invalid led mode: 0x%02x\n",
604e7a792e9SJohan Hovold 					priv->led_mode);
605e7a792e9SJohan Hovold 			priv->led_mode = -1;
606e7a792e9SJohan Hovold 		}
607e7a792e9SJohan Hovold 	} else {
608e7a792e9SJohan Hovold 		priv->led_mode = -1;
609e7a792e9SJohan Hovold 	}
610e7a792e9SJohan Hovold 
6111fadee0cSSascha Hauer 	clk = devm_clk_get(&phydev->dev, "rmii-ref");
612bced8701SNiklas Cassel 	/* NOTE: clk may be NULL if building without CONFIG_HAVE_CLK */
613bced8701SNiklas Cassel 	if (!IS_ERR_OR_NULL(clk)) {
6141fadee0cSSascha Hauer 		unsigned long rate = clk_get_rate(clk);
61586dc1342SJohan Hovold 		bool rmii_ref_clk_sel_25_mhz;
6161fadee0cSSascha Hauer 
61763f44b2bSJohan Hovold 		priv->rmii_ref_clk_sel = type->has_rmii_ref_clk_sel;
61886dc1342SJohan Hovold 		rmii_ref_clk_sel_25_mhz = of_property_read_bool(np,
61986dc1342SJohan Hovold 				"micrel,rmii-reference-clock-select-25-mhz");
62063f44b2bSJohan Hovold 
6211fadee0cSSascha Hauer 		if (rate > 24500000 && rate < 25500000) {
62286dc1342SJohan Hovold 			priv->rmii_ref_clk_sel_val = rmii_ref_clk_sel_25_mhz;
6231fadee0cSSascha Hauer 		} else if (rate > 49500000 && rate < 50500000) {
62486dc1342SJohan Hovold 			priv->rmii_ref_clk_sel_val = !rmii_ref_clk_sel_25_mhz;
6251fadee0cSSascha Hauer 		} else {
6261fadee0cSSascha Hauer 			dev_err(&phydev->dev, "Clock rate out of range: %ld\n", rate);
6271fadee0cSSascha Hauer 			return -EINVAL;
6281fadee0cSSascha Hauer 		}
6291fadee0cSSascha Hauer 	}
6301fadee0cSSascha Hauer 
63163f44b2bSJohan Hovold 	/* Support legacy board-file configuration */
63263f44b2bSJohan Hovold 	if (phydev->dev_flags & MICREL_PHY_50MHZ_CLK) {
63363f44b2bSJohan Hovold 		priv->rmii_ref_clk_sel = true;
63463f44b2bSJohan Hovold 		priv->rmii_ref_clk_sel_val = true;
63563f44b2bSJohan Hovold 	}
63663f44b2bSJohan Hovold 
63763f44b2bSJohan Hovold 	return 0;
6381fadee0cSSascha Hauer }
6391fadee0cSSascha Hauer 
640d5bf9071SChristian Hohnstaedt static struct phy_driver ksphy_driver[] = {
641d5bf9071SChristian Hohnstaedt {
64251f932c4SChoi, David 	.phy_id		= PHY_ID_KS8737,
643d0507009SDavid J. Choi 	.phy_id_mask	= 0x00fffff0,
64451f932c4SChoi, David 	.name		= "Micrel KS8737",
64551f932c4SChoi, David 	.features	= (PHY_BASIC_FEATURES | SUPPORTED_Pause),
64651f932c4SChoi, David 	.flags		= PHY_HAS_MAGICANEG | PHY_HAS_INTERRUPT,
647c6f9575cSJohan Hovold 	.driver_data	= &ks8737_type,
648d0507009SDavid J. Choi 	.config_init	= kszphy_config_init,
649d0507009SDavid J. Choi 	.config_aneg	= genphy_config_aneg,
650d0507009SDavid J. Choi 	.read_status	= genphy_read_status,
65151f932c4SChoi, David 	.ack_interrupt	= kszphy_ack_interrupt,
652c6f9575cSJohan Hovold 	.config_intr	= kszphy_config_intr,
6531a5465f5SPatrice Vilchez 	.suspend	= genphy_suspend,
6541a5465f5SPatrice Vilchez 	.resume		= genphy_resume,
655d0507009SDavid J. Choi 	.driver		= { .owner = THIS_MODULE,},
656d5bf9071SChristian Hohnstaedt }, {
657212ea99aSMarek Vasut 	.phy_id		= PHY_ID_KSZ8021,
658212ea99aSMarek Vasut 	.phy_id_mask	= 0x00ffffff,
6597ab59dc1SDavid J. Choi 	.name		= "Micrel KSZ8021 or KSZ8031",
660212ea99aSMarek Vasut 	.features	= (PHY_BASIC_FEATURES | SUPPORTED_Pause |
661212ea99aSMarek Vasut 			   SUPPORTED_Asym_Pause),
662212ea99aSMarek Vasut 	.flags		= PHY_HAS_MAGICANEG | PHY_HAS_INTERRUPT,
663e6a423a8SJohan Hovold 	.driver_data	= &ksz8021_type,
66463f44b2bSJohan Hovold 	.probe		= kszphy_probe,
665d0e1df9cSJohan Hovold 	.config_init	= kszphy_config_init,
666212ea99aSMarek Vasut 	.config_aneg	= genphy_config_aneg,
667212ea99aSMarek Vasut 	.read_status	= genphy_read_status,
668212ea99aSMarek Vasut 	.ack_interrupt	= kszphy_ack_interrupt,
669212ea99aSMarek Vasut 	.config_intr	= kszphy_config_intr,
6701a5465f5SPatrice Vilchez 	.suspend	= genphy_suspend,
6711a5465f5SPatrice Vilchez 	.resume		= genphy_resume,
672212ea99aSMarek Vasut 	.driver		= { .owner = THIS_MODULE,},
673212ea99aSMarek Vasut }, {
674b818d1a7SHector Palacios 	.phy_id		= PHY_ID_KSZ8031,
675b818d1a7SHector Palacios 	.phy_id_mask	= 0x00ffffff,
676b818d1a7SHector Palacios 	.name		= "Micrel KSZ8031",
677b818d1a7SHector Palacios 	.features	= (PHY_BASIC_FEATURES | SUPPORTED_Pause |
678b818d1a7SHector Palacios 			   SUPPORTED_Asym_Pause),
679b818d1a7SHector Palacios 	.flags		= PHY_HAS_MAGICANEG | PHY_HAS_INTERRUPT,
680e6a423a8SJohan Hovold 	.driver_data	= &ksz8021_type,
68163f44b2bSJohan Hovold 	.probe		= kszphy_probe,
682d0e1df9cSJohan Hovold 	.config_init	= kszphy_config_init,
683b818d1a7SHector Palacios 	.config_aneg	= genphy_config_aneg,
684b818d1a7SHector Palacios 	.read_status	= genphy_read_status,
685b818d1a7SHector Palacios 	.ack_interrupt	= kszphy_ack_interrupt,
686b818d1a7SHector Palacios 	.config_intr	= kszphy_config_intr,
6871a5465f5SPatrice Vilchez 	.suspend	= genphy_suspend,
6881a5465f5SPatrice Vilchez 	.resume		= genphy_resume,
689b818d1a7SHector Palacios 	.driver		= { .owner = THIS_MODULE,},
690b818d1a7SHector Palacios }, {
691510d573fSMarek Vasut 	.phy_id		= PHY_ID_KSZ8041,
692d0507009SDavid J. Choi 	.phy_id_mask	= 0x00fffff0,
693510d573fSMarek Vasut 	.name		= "Micrel KSZ8041",
69451f932c4SChoi, David 	.features	= (PHY_BASIC_FEATURES | SUPPORTED_Pause
69551f932c4SChoi, David 				| SUPPORTED_Asym_Pause),
69651f932c4SChoi, David 	.flags		= PHY_HAS_MAGICANEG | PHY_HAS_INTERRUPT,
697e6a423a8SJohan Hovold 	.driver_data	= &ksz8041_type,
698e6a423a8SJohan Hovold 	.probe		= kszphy_probe,
699e6a423a8SJohan Hovold 	.config_init	= kszphy_config_init,
700d0507009SDavid J. Choi 	.config_aneg	= genphy_config_aneg,
701d0507009SDavid J. Choi 	.read_status	= genphy_read_status,
70251f932c4SChoi, David 	.ack_interrupt	= kszphy_ack_interrupt,
70351f932c4SChoi, David 	.config_intr	= kszphy_config_intr,
7041a5465f5SPatrice Vilchez 	.suspend	= genphy_suspend,
7051a5465f5SPatrice Vilchez 	.resume		= genphy_resume,
70651f932c4SChoi, David 	.driver		= { .owner = THIS_MODULE,},
707d5bf9071SChristian Hohnstaedt }, {
7084bd7b512SSergei Shtylyov 	.phy_id		= PHY_ID_KSZ8041RNLI,
7094bd7b512SSergei Shtylyov 	.phy_id_mask	= 0x00fffff0,
7104bd7b512SSergei Shtylyov 	.name		= "Micrel KSZ8041RNLI",
7114bd7b512SSergei Shtylyov 	.features	= PHY_BASIC_FEATURES |
7124bd7b512SSergei Shtylyov 			  SUPPORTED_Pause | SUPPORTED_Asym_Pause,
7134bd7b512SSergei Shtylyov 	.flags		= PHY_HAS_MAGICANEG | PHY_HAS_INTERRUPT,
714e6a423a8SJohan Hovold 	.driver_data	= &ksz8041_type,
715e6a423a8SJohan Hovold 	.probe		= kszphy_probe,
716e6a423a8SJohan Hovold 	.config_init	= kszphy_config_init,
7174bd7b512SSergei Shtylyov 	.config_aneg	= genphy_config_aneg,
7184bd7b512SSergei Shtylyov 	.read_status	= genphy_read_status,
7194bd7b512SSergei Shtylyov 	.ack_interrupt	= kszphy_ack_interrupt,
7204bd7b512SSergei Shtylyov 	.config_intr	= kszphy_config_intr,
7214bd7b512SSergei Shtylyov 	.suspend	= genphy_suspend,
7224bd7b512SSergei Shtylyov 	.resume		= genphy_resume,
7234bd7b512SSergei Shtylyov 	.driver		= { .owner = THIS_MODULE,},
7244bd7b512SSergei Shtylyov }, {
725510d573fSMarek Vasut 	.phy_id		= PHY_ID_KSZ8051,
72651f932c4SChoi, David 	.phy_id_mask	= 0x00fffff0,
727510d573fSMarek Vasut 	.name		= "Micrel KSZ8051",
72851f932c4SChoi, David 	.features	= (PHY_BASIC_FEATURES | SUPPORTED_Pause
72951f932c4SChoi, David 				| SUPPORTED_Asym_Pause),
73051f932c4SChoi, David 	.flags		= PHY_HAS_MAGICANEG | PHY_HAS_INTERRUPT,
731e6a423a8SJohan Hovold 	.driver_data	= &ksz8051_type,
732e6a423a8SJohan Hovold 	.probe		= kszphy_probe,
73363f44b2bSJohan Hovold 	.config_init	= kszphy_config_init,
73451f932c4SChoi, David 	.config_aneg	= genphy_config_aneg,
73551f932c4SChoi, David 	.read_status	= genphy_read_status,
73651f932c4SChoi, David 	.ack_interrupt	= kszphy_ack_interrupt,
73751f932c4SChoi, David 	.config_intr	= kszphy_config_intr,
7381a5465f5SPatrice Vilchez 	.suspend	= genphy_suspend,
7391a5465f5SPatrice Vilchez 	.resume		= genphy_resume,
74051f932c4SChoi, David 	.driver		= { .owner = THIS_MODULE,},
741d5bf9071SChristian Hohnstaedt }, {
742510d573fSMarek Vasut 	.phy_id		= PHY_ID_KSZ8001,
743510d573fSMarek Vasut 	.name		= "Micrel KSZ8001 or KS8721",
74448d7d0adSJason Wang 	.phy_id_mask	= 0x00ffffff,
74551f932c4SChoi, David 	.features	= (PHY_BASIC_FEATURES | SUPPORTED_Pause),
74651f932c4SChoi, David 	.flags		= PHY_HAS_MAGICANEG | PHY_HAS_INTERRUPT,
747e6a423a8SJohan Hovold 	.driver_data	= &ksz8041_type,
748e6a423a8SJohan Hovold 	.probe		= kszphy_probe,
749e6a423a8SJohan Hovold 	.config_init	= kszphy_config_init,
75051f932c4SChoi, David 	.config_aneg	= genphy_config_aneg,
75151f932c4SChoi, David 	.read_status	= genphy_read_status,
75251f932c4SChoi, David 	.ack_interrupt	= kszphy_ack_interrupt,
75351f932c4SChoi, David 	.config_intr	= kszphy_config_intr,
7541a5465f5SPatrice Vilchez 	.suspend	= genphy_suspend,
7551a5465f5SPatrice Vilchez 	.resume		= genphy_resume,
756d0507009SDavid J. Choi 	.driver		= { .owner = THIS_MODULE,},
757d5bf9071SChristian Hohnstaedt }, {
7587ab59dc1SDavid J. Choi 	.phy_id		= PHY_ID_KSZ8081,
7597ab59dc1SDavid J. Choi 	.name		= "Micrel KSZ8081 or KSZ8091",
7607ab59dc1SDavid J. Choi 	.phy_id_mask	= 0x00fffff0,
7617ab59dc1SDavid J. Choi 	.features	= (PHY_BASIC_FEATURES | SUPPORTED_Pause),
7627ab59dc1SDavid J. Choi 	.flags		= PHY_HAS_MAGICANEG | PHY_HAS_INTERRUPT,
763e6a423a8SJohan Hovold 	.driver_data	= &ksz8081_type,
764e6a423a8SJohan Hovold 	.probe		= kszphy_probe,
7650f95903eSJohan Hovold 	.config_init	= kszphy_config_init,
7667ab59dc1SDavid J. Choi 	.config_aneg	= genphy_config_aneg,
7677ab59dc1SDavid J. Choi 	.read_status	= genphy_read_status,
7687ab59dc1SDavid J. Choi 	.ack_interrupt	= kszphy_ack_interrupt,
7697ab59dc1SDavid J. Choi 	.config_intr	= kszphy_config_intr,
7701a5465f5SPatrice Vilchez 	.suspend	= genphy_suspend,
7711a5465f5SPatrice Vilchez 	.resume		= genphy_resume,
7727ab59dc1SDavid J. Choi 	.driver		= { .owner = THIS_MODULE,},
7737ab59dc1SDavid J. Choi }, {
7747ab59dc1SDavid J. Choi 	.phy_id		= PHY_ID_KSZ8061,
7757ab59dc1SDavid J. Choi 	.name		= "Micrel KSZ8061",
7767ab59dc1SDavid J. Choi 	.phy_id_mask	= 0x00fffff0,
7777ab59dc1SDavid J. Choi 	.features	= (PHY_BASIC_FEATURES | SUPPORTED_Pause),
7787ab59dc1SDavid J. Choi 	.flags		= PHY_HAS_MAGICANEG | PHY_HAS_INTERRUPT,
7797ab59dc1SDavid J. Choi 	.config_init	= kszphy_config_init,
7807ab59dc1SDavid J. Choi 	.config_aneg	= genphy_config_aneg,
7817ab59dc1SDavid J. Choi 	.read_status	= genphy_read_status,
7827ab59dc1SDavid J. Choi 	.ack_interrupt	= kszphy_ack_interrupt,
7837ab59dc1SDavid J. Choi 	.config_intr	= kszphy_config_intr,
7841a5465f5SPatrice Vilchez 	.suspend	= genphy_suspend,
7851a5465f5SPatrice Vilchez 	.resume		= genphy_resume,
7867ab59dc1SDavid J. Choi 	.driver		= { .owner = THIS_MODULE,},
7877ab59dc1SDavid J. Choi }, {
788d0507009SDavid J. Choi 	.phy_id		= PHY_ID_KSZ9021,
78948d7d0adSJason Wang 	.phy_id_mask	= 0x000ffffe,
790d0507009SDavid J. Choi 	.name		= "Micrel KSZ9021 Gigabit PHY",
79132fcafbcSVlastimil Kosar 	.features	= (PHY_GBIT_FEATURES | SUPPORTED_Pause),
79251f932c4SChoi, David 	.flags		= PHY_HAS_MAGICANEG | PHY_HAS_INTERRUPT,
793c6f9575cSJohan Hovold 	.driver_data	= &ksz9021_type,
794954c3967SSean Cross 	.config_init	= ksz9021_config_init,
795d0507009SDavid J. Choi 	.config_aneg	= genphy_config_aneg,
796d0507009SDavid J. Choi 	.read_status	= genphy_read_status,
79751f932c4SChoi, David 	.ack_interrupt	= kszphy_ack_interrupt,
798c6f9575cSJohan Hovold 	.config_intr	= kszphy_config_intr,
7991a5465f5SPatrice Vilchez 	.suspend	= genphy_suspend,
8001a5465f5SPatrice Vilchez 	.resume		= genphy_resume,
80119936942SVince Bridgers 	.read_mmd_indirect = ksz9021_rd_mmd_phyreg,
80219936942SVince Bridgers 	.write_mmd_indirect = ksz9021_wr_mmd_phyreg,
803d0507009SDavid J. Choi 	.driver		= { .owner = THIS_MODULE, },
80493272e07SJean-Christophe PLAGNIOL-VILLARD }, {
8057ab59dc1SDavid J. Choi 	.phy_id		= PHY_ID_KSZ9031,
8067ab59dc1SDavid J. Choi 	.phy_id_mask	= 0x00fffff0,
8077ab59dc1SDavid J. Choi 	.name		= "Micrel KSZ9031 Gigabit PHY",
80895e8b103SMike Looijmans 	.features	= (PHY_GBIT_FEATURES | SUPPORTED_Pause),
8097ab59dc1SDavid J. Choi 	.flags		= PHY_HAS_MAGICANEG | PHY_HAS_INTERRUPT,
810c6f9575cSJohan Hovold 	.driver_data	= &ksz9021_type,
8116e4b8273SHubert Chaumette 	.config_init	= ksz9031_config_init,
8127ab59dc1SDavid J. Choi 	.config_aneg	= genphy_config_aneg,
813d2fd719bSNathan Sullivan 	.read_status	= ksz9031_read_status,
8147ab59dc1SDavid J. Choi 	.ack_interrupt	= kszphy_ack_interrupt,
815c6f9575cSJohan Hovold 	.config_intr	= kszphy_config_intr,
8161a5465f5SPatrice Vilchez 	.suspend	= genphy_suspend,
8171a5465f5SPatrice Vilchez 	.resume		= genphy_resume,
8187ab59dc1SDavid J. Choi 	.driver		= { .owner = THIS_MODULE, },
8197ab59dc1SDavid J. Choi }, {
82093272e07SJean-Christophe PLAGNIOL-VILLARD 	.phy_id		= PHY_ID_KSZ8873MLL,
82193272e07SJean-Christophe PLAGNIOL-VILLARD 	.phy_id_mask	= 0x00fffff0,
82293272e07SJean-Christophe PLAGNIOL-VILLARD 	.name		= "Micrel KSZ8873MLL Switch",
82393272e07SJean-Christophe PLAGNIOL-VILLARD 	.features	= (SUPPORTED_Pause | SUPPORTED_Asym_Pause),
82493272e07SJean-Christophe PLAGNIOL-VILLARD 	.flags		= PHY_HAS_MAGICANEG,
82593272e07SJean-Christophe PLAGNIOL-VILLARD 	.config_init	= kszphy_config_init,
82693272e07SJean-Christophe PLAGNIOL-VILLARD 	.config_aneg	= ksz8873mll_config_aneg,
82793272e07SJean-Christophe PLAGNIOL-VILLARD 	.read_status	= ksz8873mll_read_status,
8281a5465f5SPatrice Vilchez 	.suspend	= genphy_suspend,
8291a5465f5SPatrice Vilchez 	.resume		= genphy_resume,
83093272e07SJean-Christophe PLAGNIOL-VILLARD 	.driver		= { .owner = THIS_MODULE, },
8317ab59dc1SDavid J. Choi }, {
8327ab59dc1SDavid J. Choi 	.phy_id		= PHY_ID_KSZ886X,
8337ab59dc1SDavid J. Choi 	.phy_id_mask	= 0x00fffff0,
8347ab59dc1SDavid J. Choi 	.name		= "Micrel KSZ886X Switch",
8357ab59dc1SDavid J. Choi 	.features	= (PHY_BASIC_FEATURES | SUPPORTED_Pause),
8367ab59dc1SDavid J. Choi 	.flags		= PHY_HAS_MAGICANEG | PHY_HAS_INTERRUPT,
8377ab59dc1SDavid J. Choi 	.config_init	= kszphy_config_init,
8387ab59dc1SDavid J. Choi 	.config_aneg	= genphy_config_aneg,
8397ab59dc1SDavid J. Choi 	.read_status	= genphy_read_status,
8401a5465f5SPatrice Vilchez 	.suspend	= genphy_suspend,
8411a5465f5SPatrice Vilchez 	.resume		= genphy_resume,
8427ab59dc1SDavid J. Choi 	.driver		= { .owner = THIS_MODULE, },
843d5bf9071SChristian Hohnstaedt } };
844d0507009SDavid J. Choi 
84550fd7150SJohan Hovold module_phy_driver(ksphy_driver);
846d0507009SDavid J. Choi 
847d0507009SDavid J. Choi MODULE_DESCRIPTION("Micrel PHY driver");
848d0507009SDavid J. Choi MODULE_AUTHOR("David J. Choi");
849d0507009SDavid J. Choi MODULE_LICENSE("GPL");
85052a60ed2SDavid S. Miller 
851cf93c945SUwe Kleine-König static struct mdio_device_id __maybe_unused micrel_tbl[] = {
85248d7d0adSJason Wang 	{ PHY_ID_KSZ9021, 0x000ffffe },
8537ab59dc1SDavid J. Choi 	{ PHY_ID_KSZ9031, 0x00fffff0 },
854510d573fSMarek Vasut 	{ PHY_ID_KSZ8001, 0x00ffffff },
85551f932c4SChoi, David 	{ PHY_ID_KS8737, 0x00fffff0 },
856212ea99aSMarek Vasut 	{ PHY_ID_KSZ8021, 0x00ffffff },
857b818d1a7SHector Palacios 	{ PHY_ID_KSZ8031, 0x00ffffff },
858510d573fSMarek Vasut 	{ PHY_ID_KSZ8041, 0x00fffff0 },
859510d573fSMarek Vasut 	{ PHY_ID_KSZ8051, 0x00fffff0 },
8607ab59dc1SDavid J. Choi 	{ PHY_ID_KSZ8061, 0x00fffff0 },
8617ab59dc1SDavid J. Choi 	{ PHY_ID_KSZ8081, 0x00fffff0 },
86293272e07SJean-Christophe PLAGNIOL-VILLARD 	{ PHY_ID_KSZ8873MLL, 0x00fffff0 },
8637ab59dc1SDavid J. Choi 	{ PHY_ID_KSZ886X, 0x00fffff0 },
86452a60ed2SDavid S. Miller 	{ }
86552a60ed2SDavid S. Miller };
86652a60ed2SDavid S. Miller 
86752a60ed2SDavid S. Miller MODULE_DEVICE_TABLE(mdio, micrel_tbl);
868