xref: /linux/drivers/net/phy/mscc/mscc_main.c (revision 37744feebc086908fd89760650f458ab19071750)
1 // SPDX-License-Identifier: (GPL-2.0 OR MIT)
2 /*
3  * Driver for Microsemi VSC85xx PHYs
4  *
5  * Author: Nagaraju Lakkaraju
6  * License: Dual MIT/GPL
7  * Copyright (c) 2016 Microsemi Corporation
8  */
9 
10 #include <linux/firmware.h>
11 #include <linux/jiffies.h>
12 #include <linux/kernel.h>
13 #include <linux/module.h>
14 #include <linux/mdio.h>
15 #include <linux/mii.h>
16 #include <linux/phy.h>
17 #include <linux/of.h>
18 #include <linux/netdevice.h>
19 #include <dt-bindings/net/mscc-phy-vsc8531.h>
20 
21 #include "mscc.h"
22 
23 static const struct vsc85xx_hw_stat vsc85xx_hw_stats[] = {
24 	{
25 		.string	= "phy_receive_errors",
26 		.reg	= MSCC_PHY_ERR_RX_CNT,
27 		.page	= MSCC_PHY_PAGE_STANDARD,
28 		.mask	= ERR_CNT_MASK,
29 	}, {
30 		.string	= "phy_false_carrier",
31 		.reg	= MSCC_PHY_ERR_FALSE_CARRIER_CNT,
32 		.page	= MSCC_PHY_PAGE_STANDARD,
33 		.mask	= ERR_CNT_MASK,
34 	}, {
35 		.string	= "phy_cu_media_link_disconnect",
36 		.reg	= MSCC_PHY_ERR_LINK_DISCONNECT_CNT,
37 		.page	= MSCC_PHY_PAGE_STANDARD,
38 		.mask	= ERR_CNT_MASK,
39 	}, {
40 		.string	= "phy_cu_media_crc_good_count",
41 		.reg	= MSCC_PHY_CU_MEDIA_CRC_VALID_CNT,
42 		.page	= MSCC_PHY_PAGE_EXTENDED,
43 		.mask	= VALID_CRC_CNT_CRC_MASK,
44 	}, {
45 		.string	= "phy_cu_media_crc_error_count",
46 		.reg	= MSCC_PHY_EXT_PHY_CNTL_4,
47 		.page	= MSCC_PHY_PAGE_EXTENDED,
48 		.mask	= ERR_CNT_MASK,
49 	},
50 };
51 
52 static const struct vsc85xx_hw_stat vsc8584_hw_stats[] = {
53 	{
54 		.string	= "phy_receive_errors",
55 		.reg	= MSCC_PHY_ERR_RX_CNT,
56 		.page	= MSCC_PHY_PAGE_STANDARD,
57 		.mask	= ERR_CNT_MASK,
58 	}, {
59 		.string	= "phy_false_carrier",
60 		.reg	= MSCC_PHY_ERR_FALSE_CARRIER_CNT,
61 		.page	= MSCC_PHY_PAGE_STANDARD,
62 		.mask	= ERR_CNT_MASK,
63 	}, {
64 		.string	= "phy_cu_media_link_disconnect",
65 		.reg	= MSCC_PHY_ERR_LINK_DISCONNECT_CNT,
66 		.page	= MSCC_PHY_PAGE_STANDARD,
67 		.mask	= ERR_CNT_MASK,
68 	}, {
69 		.string	= "phy_cu_media_crc_good_count",
70 		.reg	= MSCC_PHY_CU_MEDIA_CRC_VALID_CNT,
71 		.page	= MSCC_PHY_PAGE_EXTENDED,
72 		.mask	= VALID_CRC_CNT_CRC_MASK,
73 	}, {
74 		.string	= "phy_cu_media_crc_error_count",
75 		.reg	= MSCC_PHY_EXT_PHY_CNTL_4,
76 		.page	= MSCC_PHY_PAGE_EXTENDED,
77 		.mask	= ERR_CNT_MASK,
78 	}, {
79 		.string	= "phy_serdes_tx_good_pkt_count",
80 		.reg	= MSCC_PHY_SERDES_TX_VALID_CNT,
81 		.page	= MSCC_PHY_PAGE_EXTENDED_3,
82 		.mask	= VALID_CRC_CNT_CRC_MASK,
83 	}, {
84 		.string	= "phy_serdes_tx_bad_crc_count",
85 		.reg	= MSCC_PHY_SERDES_TX_CRC_ERR_CNT,
86 		.page	= MSCC_PHY_PAGE_EXTENDED_3,
87 		.mask	= ERR_CNT_MASK,
88 	}, {
89 		.string	= "phy_serdes_rx_good_pkt_count",
90 		.reg	= MSCC_PHY_SERDES_RX_VALID_CNT,
91 		.page	= MSCC_PHY_PAGE_EXTENDED_3,
92 		.mask	= VALID_CRC_CNT_CRC_MASK,
93 	}, {
94 		.string	= "phy_serdes_rx_bad_crc_count",
95 		.reg	= MSCC_PHY_SERDES_RX_CRC_ERR_CNT,
96 		.page	= MSCC_PHY_PAGE_EXTENDED_3,
97 		.mask	= ERR_CNT_MASK,
98 	},
99 };
100 
101 #ifdef CONFIG_OF_MDIO
102 static const struct vsc8531_edge_rate_table edge_table[] = {
103 	{MSCC_VDDMAC_3300, { 0, 2,  4,  7, 10, 17, 29, 53} },
104 	{MSCC_VDDMAC_2500, { 0, 3,  6, 10, 14, 23, 37, 63} },
105 	{MSCC_VDDMAC_1800, { 0, 5,  9, 16, 23, 35, 52, 76} },
106 	{MSCC_VDDMAC_1500, { 0, 6, 14, 21, 29, 42, 58, 77} },
107 };
108 #endif
109 
110 static int vsc85xx_phy_read_page(struct phy_device *phydev)
111 {
112 	return __phy_read(phydev, MSCC_EXT_PAGE_ACCESS);
113 }
114 
115 static int vsc85xx_phy_write_page(struct phy_device *phydev, int page)
116 {
117 	return __phy_write(phydev, MSCC_EXT_PAGE_ACCESS, page);
118 }
119 
120 static int vsc85xx_get_sset_count(struct phy_device *phydev)
121 {
122 	struct vsc8531_private *priv = phydev->priv;
123 
124 	if (!priv)
125 		return 0;
126 
127 	return priv->nstats;
128 }
129 
130 static void vsc85xx_get_strings(struct phy_device *phydev, u8 *data)
131 {
132 	struct vsc8531_private *priv = phydev->priv;
133 	int i;
134 
135 	if (!priv)
136 		return;
137 
138 	for (i = 0; i < priv->nstats; i++)
139 		strlcpy(data + i * ETH_GSTRING_LEN, priv->hw_stats[i].string,
140 			ETH_GSTRING_LEN);
141 }
142 
143 static u64 vsc85xx_get_stat(struct phy_device *phydev, int i)
144 {
145 	struct vsc8531_private *priv = phydev->priv;
146 	int val;
147 
148 	val = phy_read_paged(phydev, priv->hw_stats[i].page,
149 			     priv->hw_stats[i].reg);
150 	if (val < 0)
151 		return U64_MAX;
152 
153 	val = val & priv->hw_stats[i].mask;
154 	priv->stats[i] += val;
155 
156 	return priv->stats[i];
157 }
158 
159 static void vsc85xx_get_stats(struct phy_device *phydev,
160 			      struct ethtool_stats *stats, u64 *data)
161 {
162 	struct vsc8531_private *priv = phydev->priv;
163 	int i;
164 
165 	if (!priv)
166 		return;
167 
168 	for (i = 0; i < priv->nstats; i++)
169 		data[i] = vsc85xx_get_stat(phydev, i);
170 }
171 
172 static int vsc85xx_led_cntl_set(struct phy_device *phydev,
173 				u8 led_num,
174 				u8 mode)
175 {
176 	int rc;
177 	u16 reg_val;
178 
179 	mutex_lock(&phydev->lock);
180 	reg_val = phy_read(phydev, MSCC_PHY_LED_MODE_SEL);
181 	reg_val &= ~LED_MODE_SEL_MASK(led_num);
182 	reg_val |= LED_MODE_SEL(led_num, (u16)mode);
183 	rc = phy_write(phydev, MSCC_PHY_LED_MODE_SEL, reg_val);
184 	mutex_unlock(&phydev->lock);
185 
186 	return rc;
187 }
188 
189 static int vsc85xx_mdix_get(struct phy_device *phydev, u8 *mdix)
190 {
191 	u16 reg_val;
192 
193 	reg_val = phy_read(phydev, MSCC_PHY_DEV_AUX_CNTL);
194 	if (reg_val & HP_AUTO_MDIX_X_OVER_IND_MASK)
195 		*mdix = ETH_TP_MDI_X;
196 	else
197 		*mdix = ETH_TP_MDI;
198 
199 	return 0;
200 }
201 
202 static int vsc85xx_mdix_set(struct phy_device *phydev, u8 mdix)
203 {
204 	int rc;
205 	u16 reg_val;
206 
207 	reg_val = phy_read(phydev, MSCC_PHY_BYPASS_CONTROL);
208 	if (mdix == ETH_TP_MDI || mdix == ETH_TP_MDI_X) {
209 		reg_val |= (DISABLE_PAIR_SWAP_CORR_MASK |
210 			    DISABLE_POLARITY_CORR_MASK  |
211 			    DISABLE_HP_AUTO_MDIX_MASK);
212 	} else {
213 		reg_val &= ~(DISABLE_PAIR_SWAP_CORR_MASK |
214 			     DISABLE_POLARITY_CORR_MASK  |
215 			     DISABLE_HP_AUTO_MDIX_MASK);
216 	}
217 	rc = phy_write(phydev, MSCC_PHY_BYPASS_CONTROL, reg_val);
218 	if (rc)
219 		return rc;
220 
221 	reg_val = 0;
222 
223 	if (mdix == ETH_TP_MDI)
224 		reg_val = FORCE_MDI_CROSSOVER_MDI;
225 	else if (mdix == ETH_TP_MDI_X)
226 		reg_val = FORCE_MDI_CROSSOVER_MDIX;
227 
228 	rc = phy_modify_paged(phydev, MSCC_PHY_PAGE_EXTENDED,
229 			      MSCC_PHY_EXT_MODE_CNTL, FORCE_MDI_CROSSOVER_MASK,
230 			      reg_val);
231 	if (rc < 0)
232 		return rc;
233 
234 	return genphy_restart_aneg(phydev);
235 }
236 
237 static int vsc85xx_downshift_get(struct phy_device *phydev, u8 *count)
238 {
239 	int reg_val;
240 
241 	reg_val = phy_read_paged(phydev, MSCC_PHY_PAGE_EXTENDED,
242 				 MSCC_PHY_ACTIPHY_CNTL);
243 	if (reg_val < 0)
244 		return reg_val;
245 
246 	reg_val &= DOWNSHIFT_CNTL_MASK;
247 	if (!(reg_val & DOWNSHIFT_EN))
248 		*count = DOWNSHIFT_DEV_DISABLE;
249 	else
250 		*count = ((reg_val & ~DOWNSHIFT_EN) >> DOWNSHIFT_CNTL_POS) + 2;
251 
252 	return 0;
253 }
254 
255 static int vsc85xx_downshift_set(struct phy_device *phydev, u8 count)
256 {
257 	if (count == DOWNSHIFT_DEV_DEFAULT_COUNT) {
258 		/* Default downshift count 3 (i.e. Bit3:2 = 0b01) */
259 		count = ((1 << DOWNSHIFT_CNTL_POS) | DOWNSHIFT_EN);
260 	} else if (count > DOWNSHIFT_COUNT_MAX || count == 1) {
261 		phydev_err(phydev, "Downshift count should be 2,3,4 or 5\n");
262 		return -ERANGE;
263 	} else if (count) {
264 		/* Downshift count is either 2,3,4 or 5 */
265 		count = (((count - 2) << DOWNSHIFT_CNTL_POS) | DOWNSHIFT_EN);
266 	}
267 
268 	return phy_modify_paged(phydev, MSCC_PHY_PAGE_EXTENDED,
269 				MSCC_PHY_ACTIPHY_CNTL, DOWNSHIFT_CNTL_MASK,
270 				count);
271 }
272 
273 static int vsc85xx_wol_set(struct phy_device *phydev,
274 			   struct ethtool_wolinfo *wol)
275 {
276 	int rc;
277 	u16 reg_val;
278 	u8  i;
279 	u16 pwd[3] = {0, 0, 0};
280 	struct ethtool_wolinfo *wol_conf = wol;
281 	u8 *mac_addr = phydev->attached_dev->dev_addr;
282 
283 	mutex_lock(&phydev->lock);
284 	rc = phy_select_page(phydev, MSCC_PHY_PAGE_EXTENDED_2);
285 	if (rc < 0) {
286 		rc = phy_restore_page(phydev, rc, rc);
287 		goto out_unlock;
288 	}
289 
290 	if (wol->wolopts & WAKE_MAGIC) {
291 		/* Store the device address for the magic packet */
292 		for (i = 0; i < ARRAY_SIZE(pwd); i++)
293 			pwd[i] = mac_addr[5 - (i * 2 + 1)] << 8 |
294 				 mac_addr[5 - i * 2];
295 		__phy_write(phydev, MSCC_PHY_WOL_LOWER_MAC_ADDR, pwd[0]);
296 		__phy_write(phydev, MSCC_PHY_WOL_MID_MAC_ADDR, pwd[1]);
297 		__phy_write(phydev, MSCC_PHY_WOL_UPPER_MAC_ADDR, pwd[2]);
298 	} else {
299 		__phy_write(phydev, MSCC_PHY_WOL_LOWER_MAC_ADDR, 0);
300 		__phy_write(phydev, MSCC_PHY_WOL_MID_MAC_ADDR, 0);
301 		__phy_write(phydev, MSCC_PHY_WOL_UPPER_MAC_ADDR, 0);
302 	}
303 
304 	if (wol_conf->wolopts & WAKE_MAGICSECURE) {
305 		for (i = 0; i < ARRAY_SIZE(pwd); i++)
306 			pwd[i] = wol_conf->sopass[5 - (i * 2 + 1)] << 8 |
307 				 wol_conf->sopass[5 - i * 2];
308 		__phy_write(phydev, MSCC_PHY_WOL_LOWER_PASSWD, pwd[0]);
309 		__phy_write(phydev, MSCC_PHY_WOL_MID_PASSWD, pwd[1]);
310 		__phy_write(phydev, MSCC_PHY_WOL_UPPER_PASSWD, pwd[2]);
311 	} else {
312 		__phy_write(phydev, MSCC_PHY_WOL_LOWER_PASSWD, 0);
313 		__phy_write(phydev, MSCC_PHY_WOL_MID_PASSWD, 0);
314 		__phy_write(phydev, MSCC_PHY_WOL_UPPER_PASSWD, 0);
315 	}
316 
317 	reg_val = __phy_read(phydev, MSCC_PHY_WOL_MAC_CONTROL);
318 	if (wol_conf->wolopts & WAKE_MAGICSECURE)
319 		reg_val |= SECURE_ON_ENABLE;
320 	else
321 		reg_val &= ~SECURE_ON_ENABLE;
322 	__phy_write(phydev, MSCC_PHY_WOL_MAC_CONTROL, reg_val);
323 
324 	rc = phy_restore_page(phydev, rc, rc > 0 ? 0 : rc);
325 	if (rc < 0)
326 		goto out_unlock;
327 
328 	if (wol->wolopts & WAKE_MAGIC) {
329 		/* Enable the WOL interrupt */
330 		reg_val = phy_read(phydev, MII_VSC85XX_INT_MASK);
331 		reg_val |= MII_VSC85XX_INT_MASK_WOL;
332 		rc = phy_write(phydev, MII_VSC85XX_INT_MASK, reg_val);
333 		if (rc)
334 			goto out_unlock;
335 	} else {
336 		/* Disable the WOL interrupt */
337 		reg_val = phy_read(phydev, MII_VSC85XX_INT_MASK);
338 		reg_val &= (~MII_VSC85XX_INT_MASK_WOL);
339 		rc = phy_write(phydev, MII_VSC85XX_INT_MASK, reg_val);
340 		if (rc)
341 			goto out_unlock;
342 	}
343 	/* Clear WOL iterrupt status */
344 	reg_val = phy_read(phydev, MII_VSC85XX_INT_STATUS);
345 
346 out_unlock:
347 	mutex_unlock(&phydev->lock);
348 
349 	return rc;
350 }
351 
352 static void vsc85xx_wol_get(struct phy_device *phydev,
353 			    struct ethtool_wolinfo *wol)
354 {
355 	int rc;
356 	u16 reg_val;
357 	u8  i;
358 	u16 pwd[3] = {0, 0, 0};
359 	struct ethtool_wolinfo *wol_conf = wol;
360 
361 	mutex_lock(&phydev->lock);
362 	rc = phy_select_page(phydev, MSCC_PHY_PAGE_EXTENDED_2);
363 	if (rc < 0)
364 		goto out_unlock;
365 
366 	reg_val = __phy_read(phydev, MSCC_PHY_WOL_MAC_CONTROL);
367 	if (reg_val & SECURE_ON_ENABLE)
368 		wol_conf->wolopts |= WAKE_MAGICSECURE;
369 	if (wol_conf->wolopts & WAKE_MAGICSECURE) {
370 		pwd[0] = __phy_read(phydev, MSCC_PHY_WOL_LOWER_PASSWD);
371 		pwd[1] = __phy_read(phydev, MSCC_PHY_WOL_MID_PASSWD);
372 		pwd[2] = __phy_read(phydev, MSCC_PHY_WOL_UPPER_PASSWD);
373 		for (i = 0; i < ARRAY_SIZE(pwd); i++) {
374 			wol_conf->sopass[5 - i * 2] = pwd[i] & 0x00ff;
375 			wol_conf->sopass[5 - (i * 2 + 1)] = (pwd[i] & 0xff00)
376 							    >> 8;
377 		}
378 	}
379 
380 out_unlock:
381 	phy_restore_page(phydev, rc, rc > 0 ? 0 : rc);
382 	mutex_unlock(&phydev->lock);
383 }
384 
385 #ifdef CONFIG_OF_MDIO
386 static int vsc85xx_edge_rate_magic_get(struct phy_device *phydev)
387 {
388 	u32 vdd, sd;
389 	int i, j;
390 	struct device *dev = &phydev->mdio.dev;
391 	struct device_node *of_node = dev->of_node;
392 	u8 sd_array_size = ARRAY_SIZE(edge_table[0].slowdown);
393 
394 	if (!of_node)
395 		return -ENODEV;
396 
397 	if (of_property_read_u32(of_node, "vsc8531,vddmac", &vdd))
398 		vdd = MSCC_VDDMAC_3300;
399 
400 	if (of_property_read_u32(of_node, "vsc8531,edge-slowdown", &sd))
401 		sd = 0;
402 
403 	for (i = 0; i < ARRAY_SIZE(edge_table); i++)
404 		if (edge_table[i].vddmac == vdd)
405 			for (j = 0; j < sd_array_size; j++)
406 				if (edge_table[i].slowdown[j] == sd)
407 					return (sd_array_size - j - 1);
408 
409 	return -EINVAL;
410 }
411 
412 static int vsc85xx_dt_led_mode_get(struct phy_device *phydev,
413 				   char *led,
414 				   u32 default_mode)
415 {
416 	struct vsc8531_private *priv = phydev->priv;
417 	struct device *dev = &phydev->mdio.dev;
418 	struct device_node *of_node = dev->of_node;
419 	u32 led_mode;
420 	int err;
421 
422 	if (!of_node)
423 		return -ENODEV;
424 
425 	led_mode = default_mode;
426 	err = of_property_read_u32(of_node, led, &led_mode);
427 	if (!err && !(BIT(led_mode) & priv->supp_led_modes)) {
428 		phydev_err(phydev, "DT %s invalid\n", led);
429 		return -EINVAL;
430 	}
431 
432 	return led_mode;
433 }
434 
435 #else
436 static int vsc85xx_edge_rate_magic_get(struct phy_device *phydev)
437 {
438 	return 0;
439 }
440 
441 static int vsc85xx_dt_led_mode_get(struct phy_device *phydev,
442 				   char *led,
443 				   u8 default_mode)
444 {
445 	return default_mode;
446 }
447 #endif /* CONFIG_OF_MDIO */
448 
449 static int vsc85xx_dt_led_modes_get(struct phy_device *phydev,
450 				    u32 *default_mode)
451 {
452 	struct vsc8531_private *priv = phydev->priv;
453 	char led_dt_prop[28];
454 	int i, ret;
455 
456 	for (i = 0; i < priv->nleds; i++) {
457 		ret = sprintf(led_dt_prop, "vsc8531,led-%d-mode", i);
458 		if (ret < 0)
459 			return ret;
460 
461 		ret = vsc85xx_dt_led_mode_get(phydev, led_dt_prop,
462 					      default_mode[i]);
463 		if (ret < 0)
464 			return ret;
465 		priv->leds_mode[i] = ret;
466 	}
467 
468 	return 0;
469 }
470 
471 static int vsc85xx_edge_rate_cntl_set(struct phy_device *phydev, u8 edge_rate)
472 {
473 	int rc;
474 
475 	mutex_lock(&phydev->lock);
476 	rc = phy_modify_paged(phydev, MSCC_PHY_PAGE_EXTENDED_2,
477 			      MSCC_PHY_WOL_MAC_CONTROL, EDGE_RATE_CNTL_MASK,
478 			      edge_rate << EDGE_RATE_CNTL_POS);
479 	mutex_unlock(&phydev->lock);
480 
481 	return rc;
482 }
483 
484 static int vsc85xx_mac_if_set(struct phy_device *phydev,
485 			      phy_interface_t interface)
486 {
487 	int rc;
488 	u16 reg_val;
489 
490 	mutex_lock(&phydev->lock);
491 	reg_val = phy_read(phydev, MSCC_PHY_EXT_PHY_CNTL_1);
492 	reg_val &= ~(MAC_IF_SELECTION_MASK);
493 	switch (interface) {
494 	case PHY_INTERFACE_MODE_RGMII_TXID:
495 	case PHY_INTERFACE_MODE_RGMII_RXID:
496 	case PHY_INTERFACE_MODE_RGMII_ID:
497 	case PHY_INTERFACE_MODE_RGMII:
498 		reg_val |= (MAC_IF_SELECTION_RGMII << MAC_IF_SELECTION_POS);
499 		break;
500 	case PHY_INTERFACE_MODE_RMII:
501 		reg_val |= (MAC_IF_SELECTION_RMII << MAC_IF_SELECTION_POS);
502 		break;
503 	case PHY_INTERFACE_MODE_MII:
504 	case PHY_INTERFACE_MODE_GMII:
505 		reg_val |= (MAC_IF_SELECTION_GMII << MAC_IF_SELECTION_POS);
506 		break;
507 	default:
508 		rc = -EINVAL;
509 		goto out_unlock;
510 	}
511 	rc = phy_write(phydev, MSCC_PHY_EXT_PHY_CNTL_1, reg_val);
512 	if (rc)
513 		goto out_unlock;
514 
515 	rc = genphy_soft_reset(phydev);
516 
517 out_unlock:
518 	mutex_unlock(&phydev->lock);
519 
520 	return rc;
521 }
522 
523 /* Set the RGMII RX and TX clock skews individually, according to the PHY
524  * interface type, to:
525  *  * 0.2 ns (their default, and lowest, hardware value) if delays should
526  *    not be enabled
527  *  * 2.0 ns (which causes the data to be sampled at exactly half way between
528  *    clock transitions at 1000 Mbps) if delays should be enabled
529  */
530 static int vsc85xx_rgmii_set_skews(struct phy_device *phydev, u32 rgmii_cntl,
531 				   u16 rgmii_rx_delay_mask,
532 				   u16 rgmii_tx_delay_mask)
533 {
534 	u16 rgmii_rx_delay_pos = ffs(rgmii_rx_delay_mask) - 1;
535 	u16 rgmii_tx_delay_pos = ffs(rgmii_tx_delay_mask) - 1;
536 	u16 reg_val = 0;
537 	int rc;
538 
539 	mutex_lock(&phydev->lock);
540 
541 	if (phydev->interface == PHY_INTERFACE_MODE_RGMII_RXID ||
542 	    phydev->interface == PHY_INTERFACE_MODE_RGMII_ID)
543 		reg_val |= RGMII_CLK_DELAY_2_0_NS << rgmii_rx_delay_pos;
544 	if (phydev->interface == PHY_INTERFACE_MODE_RGMII_TXID ||
545 	    phydev->interface == PHY_INTERFACE_MODE_RGMII_ID)
546 		reg_val |= RGMII_CLK_DELAY_2_0_NS << rgmii_tx_delay_pos;
547 
548 	rc = phy_modify_paged(phydev, MSCC_PHY_PAGE_EXTENDED_2,
549 			      rgmii_cntl,
550 			      rgmii_rx_delay_mask | rgmii_tx_delay_mask,
551 			      reg_val);
552 
553 	mutex_unlock(&phydev->lock);
554 
555 	return rc;
556 }
557 
558 static int vsc85xx_default_config(struct phy_device *phydev)
559 {
560 	int rc;
561 
562 	phydev->mdix_ctrl = ETH_TP_MDI_AUTO;
563 
564 	if (phy_interface_mode_is_rgmii(phydev->interface)) {
565 		rc = vsc85xx_rgmii_set_skews(phydev, VSC8502_RGMII_CNTL,
566 					     VSC8502_RGMII_RX_DELAY_MASK,
567 					     VSC8502_RGMII_TX_DELAY_MASK);
568 		if (rc)
569 			return rc;
570 	}
571 
572 	return 0;
573 }
574 
575 static int vsc85xx_get_tunable(struct phy_device *phydev,
576 			       struct ethtool_tunable *tuna, void *data)
577 {
578 	switch (tuna->id) {
579 	case ETHTOOL_PHY_DOWNSHIFT:
580 		return vsc85xx_downshift_get(phydev, (u8 *)data);
581 	default:
582 		return -EINVAL;
583 	}
584 }
585 
586 static int vsc85xx_set_tunable(struct phy_device *phydev,
587 			       struct ethtool_tunable *tuna,
588 			       const void *data)
589 {
590 	switch (tuna->id) {
591 	case ETHTOOL_PHY_DOWNSHIFT:
592 		return vsc85xx_downshift_set(phydev, *(u8 *)data);
593 	default:
594 		return -EINVAL;
595 	}
596 }
597 
598 /* mdiobus lock should be locked when using this function */
599 static void vsc85xx_tr_write(struct phy_device *phydev, u16 addr, u32 val)
600 {
601 	__phy_write(phydev, MSCC_PHY_TR_MSB, val >> 16);
602 	__phy_write(phydev, MSCC_PHY_TR_LSB, val & GENMASK(15, 0));
603 	__phy_write(phydev, MSCC_PHY_TR_CNTL, TR_WRITE | TR_ADDR(addr));
604 }
605 
606 static int vsc8531_pre_init_seq_set(struct phy_device *phydev)
607 {
608 	int rc;
609 	static const struct reg_val init_seq[] = {
610 		{0x0f90, 0x00688980},
611 		{0x0696, 0x00000003},
612 		{0x07fa, 0x0050100f},
613 		{0x1686, 0x00000004},
614 	};
615 	unsigned int i;
616 	int oldpage;
617 
618 	rc = phy_modify_paged(phydev, MSCC_PHY_PAGE_STANDARD,
619 			      MSCC_PHY_EXT_CNTL_STATUS, SMI_BROADCAST_WR_EN,
620 			      SMI_BROADCAST_WR_EN);
621 	if (rc < 0)
622 		return rc;
623 	rc = phy_modify_paged(phydev, MSCC_PHY_PAGE_TEST,
624 			      MSCC_PHY_TEST_PAGE_24, 0, 0x0400);
625 	if (rc < 0)
626 		return rc;
627 	rc = phy_modify_paged(phydev, MSCC_PHY_PAGE_TEST,
628 			      MSCC_PHY_TEST_PAGE_5, 0x0a00, 0x0e00);
629 	if (rc < 0)
630 		return rc;
631 	rc = phy_modify_paged(phydev, MSCC_PHY_PAGE_TEST,
632 			      MSCC_PHY_TEST_PAGE_8, 0x8000, 0x8000);
633 	if (rc < 0)
634 		return rc;
635 
636 	mutex_lock(&phydev->lock);
637 	oldpage = phy_select_page(phydev, MSCC_PHY_PAGE_TR);
638 	if (oldpage < 0)
639 		goto out_unlock;
640 
641 	for (i = 0; i < ARRAY_SIZE(init_seq); i++)
642 		vsc85xx_tr_write(phydev, init_seq[i].reg, init_seq[i].val);
643 
644 out_unlock:
645 	oldpage = phy_restore_page(phydev, oldpage, oldpage);
646 	mutex_unlock(&phydev->lock);
647 
648 	return oldpage;
649 }
650 
651 static int vsc85xx_eee_init_seq_set(struct phy_device *phydev)
652 {
653 	static const struct reg_val init_eee[] = {
654 		{0x0f82, 0x0012b00a},
655 		{0x1686, 0x00000004},
656 		{0x168c, 0x00d2c46f},
657 		{0x17a2, 0x00000620},
658 		{0x16a0, 0x00eeffdd},
659 		{0x16a6, 0x00071448},
660 		{0x16a4, 0x0013132f},
661 		{0x16a8, 0x00000000},
662 		{0x0ffc, 0x00c0a028},
663 		{0x0fe8, 0x0091b06c},
664 		{0x0fea, 0x00041600},
665 		{0x0f80, 0x00000af4},
666 		{0x0fec, 0x00901809},
667 		{0x0fee, 0x0000a6a1},
668 		{0x0ffe, 0x00b01007},
669 		{0x16b0, 0x00eeff00},
670 		{0x16b2, 0x00007000},
671 		{0x16b4, 0x00000814},
672 	};
673 	unsigned int i;
674 	int oldpage;
675 
676 	mutex_lock(&phydev->lock);
677 	oldpage = phy_select_page(phydev, MSCC_PHY_PAGE_TR);
678 	if (oldpage < 0)
679 		goto out_unlock;
680 
681 	for (i = 0; i < ARRAY_SIZE(init_eee); i++)
682 		vsc85xx_tr_write(phydev, init_eee[i].reg, init_eee[i].val);
683 
684 out_unlock:
685 	oldpage = phy_restore_page(phydev, oldpage, oldpage);
686 	mutex_unlock(&phydev->lock);
687 
688 	return oldpage;
689 }
690 
691 /* phydev->bus->mdio_lock should be locked when using this function */
692 static int phy_base_write(struct phy_device *phydev, u32 regnum, u16 val)
693 {
694 	struct vsc8531_private *priv = phydev->priv;
695 
696 	if (unlikely(!mutex_is_locked(&phydev->mdio.bus->mdio_lock))) {
697 		dev_err(&phydev->mdio.dev, "MDIO bus lock not held!\n");
698 		dump_stack();
699 	}
700 
701 	return __mdiobus_write(phydev->mdio.bus, priv->base_addr, regnum, val);
702 }
703 
704 /* phydev->bus->mdio_lock should be locked when using this function */
705 static int phy_base_read(struct phy_device *phydev, u32 regnum)
706 {
707 	struct vsc8531_private *priv = phydev->priv;
708 
709 	if (unlikely(!mutex_is_locked(&phydev->mdio.bus->mdio_lock))) {
710 		dev_err(&phydev->mdio.dev, "MDIO bus lock not held!\n");
711 		dump_stack();
712 	}
713 
714 	return __mdiobus_read(phydev->mdio.bus, priv->base_addr, regnum);
715 }
716 
717 /* bus->mdio_lock should be locked when using this function */
718 static void vsc8584_csr_write(struct phy_device *phydev, u16 addr, u32 val)
719 {
720 	phy_base_write(phydev, MSCC_PHY_TR_MSB, val >> 16);
721 	phy_base_write(phydev, MSCC_PHY_TR_LSB, val & GENMASK(15, 0));
722 	phy_base_write(phydev, MSCC_PHY_TR_CNTL, TR_WRITE | TR_ADDR(addr));
723 }
724 
725 /* bus->mdio_lock should be locked when using this function */
726 static int vsc8584_cmd(struct phy_device *phydev, u16 val)
727 {
728 	unsigned long deadline;
729 	u16 reg_val;
730 
731 	phy_base_write(phydev, MSCC_EXT_PAGE_ACCESS,
732 		       MSCC_PHY_PAGE_EXTENDED_GPIO);
733 
734 	phy_base_write(phydev, MSCC_PHY_PROC_CMD, PROC_CMD_NCOMPLETED | val);
735 
736 	deadline = jiffies + msecs_to_jiffies(PROC_CMD_NCOMPLETED_TIMEOUT_MS);
737 	do {
738 		reg_val = phy_base_read(phydev, MSCC_PHY_PROC_CMD);
739 	} while (time_before(jiffies, deadline) &&
740 		 (reg_val & PROC_CMD_NCOMPLETED) &&
741 		 !(reg_val & PROC_CMD_FAILED));
742 
743 	phy_base_write(phydev, MSCC_EXT_PAGE_ACCESS, MSCC_PHY_PAGE_STANDARD);
744 
745 	if (reg_val & PROC_CMD_FAILED)
746 		return -EIO;
747 
748 	if (reg_val & PROC_CMD_NCOMPLETED)
749 		return -ETIMEDOUT;
750 
751 	return 0;
752 }
753 
754 /* bus->mdio_lock should be locked when using this function */
755 static int vsc8584_micro_deassert_reset(struct phy_device *phydev,
756 					bool patch_en)
757 {
758 	u32 enable, release;
759 
760 	phy_base_write(phydev, MSCC_EXT_PAGE_ACCESS,
761 		       MSCC_PHY_PAGE_EXTENDED_GPIO);
762 
763 	enable = RUN_FROM_INT_ROM | MICRO_CLK_EN | DW8051_CLK_EN;
764 	release = MICRO_NSOFT_RESET | RUN_FROM_INT_ROM | DW8051_CLK_EN |
765 		MICRO_CLK_EN;
766 
767 	if (patch_en) {
768 		enable |= MICRO_PATCH_EN;
769 		release |= MICRO_PATCH_EN;
770 
771 		/* Clear all patches */
772 		phy_base_write(phydev, MSCC_INT_MEM_CNTL, READ_RAM);
773 	}
774 
775 	/* Enable 8051 Micro clock; CLEAR/SET patch present; disable PRAM clock
776 	 * override and addr. auto-incr; operate at 125 MHz
777 	 */
778 	phy_base_write(phydev, MSCC_DW8051_CNTL_STATUS, enable);
779 	/* Release 8051 Micro SW reset */
780 	phy_base_write(phydev, MSCC_DW8051_CNTL_STATUS, release);
781 
782 	phy_base_write(phydev, MSCC_EXT_PAGE_ACCESS, MSCC_PHY_PAGE_STANDARD);
783 
784 	return 0;
785 }
786 
787 /* bus->mdio_lock should be locked when using this function */
788 static int vsc8584_micro_assert_reset(struct phy_device *phydev)
789 {
790 	int ret;
791 	u16 reg;
792 
793 	ret = vsc8584_cmd(phydev, PROC_CMD_NOP);
794 	if (ret)
795 		return ret;
796 
797 	phy_base_write(phydev, MSCC_EXT_PAGE_ACCESS,
798 		       MSCC_PHY_PAGE_EXTENDED_GPIO);
799 
800 	reg = phy_base_read(phydev, MSCC_INT_MEM_CNTL);
801 	reg &= ~EN_PATCH_RAM_TRAP_ADDR(4);
802 	phy_base_write(phydev, MSCC_INT_MEM_CNTL, reg);
803 
804 	phy_base_write(phydev, MSCC_TRAP_ROM_ADDR(4), 0x005b);
805 	phy_base_write(phydev, MSCC_PATCH_RAM_ADDR(4), 0x005b);
806 
807 	reg = phy_base_read(phydev, MSCC_INT_MEM_CNTL);
808 	reg |= EN_PATCH_RAM_TRAP_ADDR(4);
809 	phy_base_write(phydev, MSCC_INT_MEM_CNTL, reg);
810 
811 	phy_base_write(phydev, MSCC_PHY_PROC_CMD, PROC_CMD_NOP);
812 
813 	reg = phy_base_read(phydev, MSCC_DW8051_CNTL_STATUS);
814 	reg &= ~MICRO_NSOFT_RESET;
815 	phy_base_write(phydev, MSCC_DW8051_CNTL_STATUS, reg);
816 
817 	phy_base_write(phydev, MSCC_PHY_PROC_CMD, PROC_CMD_MCB_ACCESS_MAC_CONF |
818 		       PROC_CMD_SGMII_PORT(0) | PROC_CMD_NO_MAC_CONF |
819 		       PROC_CMD_READ);
820 
821 	reg = phy_base_read(phydev, MSCC_INT_MEM_CNTL);
822 	reg &= ~EN_PATCH_RAM_TRAP_ADDR(4);
823 	phy_base_write(phydev, MSCC_INT_MEM_CNTL, reg);
824 
825 	phy_base_write(phydev, MSCC_EXT_PAGE_ACCESS, MSCC_PHY_PAGE_STANDARD);
826 
827 	return 0;
828 }
829 
830 /* bus->mdio_lock should be locked when using this function */
831 static int vsc8584_get_fw_crc(struct phy_device *phydev, u16 start, u16 size,
832 			      u16 *crc)
833 {
834 	int ret;
835 
836 	phy_base_write(phydev, MSCC_EXT_PAGE_ACCESS, MSCC_PHY_PAGE_EXTENDED);
837 
838 	phy_base_write(phydev, MSCC_PHY_VERIPHY_CNTL_2, start);
839 	phy_base_write(phydev, MSCC_PHY_VERIPHY_CNTL_3, size);
840 
841 	/* Start Micro command */
842 	ret = vsc8584_cmd(phydev, PROC_CMD_CRC16);
843 	if (ret)
844 		goto out;
845 
846 	phy_base_write(phydev, MSCC_EXT_PAGE_ACCESS, MSCC_PHY_PAGE_EXTENDED);
847 
848 	*crc = phy_base_read(phydev, MSCC_PHY_VERIPHY_CNTL_2);
849 
850 out:
851 	phy_base_write(phydev, MSCC_EXT_PAGE_ACCESS, MSCC_PHY_PAGE_STANDARD);
852 
853 	return ret;
854 }
855 
856 /* bus->mdio_lock should be locked when using this function */
857 static int vsc8584_patch_fw(struct phy_device *phydev,
858 			    const struct firmware *fw)
859 {
860 	int i, ret;
861 
862 	ret = vsc8584_micro_assert_reset(phydev);
863 	if (ret) {
864 		dev_err(&phydev->mdio.dev,
865 			"%s: failed to assert reset of micro\n", __func__);
866 		return ret;
867 	}
868 
869 	phy_base_write(phydev, MSCC_EXT_PAGE_ACCESS,
870 		       MSCC_PHY_PAGE_EXTENDED_GPIO);
871 
872 	/* Hold 8051 Micro in SW Reset, Enable auto incr address and patch clock
873 	 * Disable the 8051 Micro clock
874 	 */
875 	phy_base_write(phydev, MSCC_DW8051_CNTL_STATUS, RUN_FROM_INT_ROM |
876 		       AUTOINC_ADDR | PATCH_RAM_CLK | MICRO_CLK_EN |
877 		       MICRO_CLK_DIVIDE(2));
878 	phy_base_write(phydev, MSCC_INT_MEM_CNTL, READ_PRAM | INT_MEM_WRITE_EN |
879 		       INT_MEM_DATA(2));
880 	phy_base_write(phydev, MSCC_INT_MEM_ADDR, 0x0000);
881 
882 	for (i = 0; i < fw->size; i++)
883 		phy_base_write(phydev, MSCC_INT_MEM_CNTL, READ_PRAM |
884 			       INT_MEM_WRITE_EN | fw->data[i]);
885 
886 	/* Clear internal memory access */
887 	phy_base_write(phydev, MSCC_INT_MEM_CNTL, READ_RAM);
888 
889 	phy_base_write(phydev, MSCC_EXT_PAGE_ACCESS, MSCC_PHY_PAGE_STANDARD);
890 
891 	return 0;
892 }
893 
894 /* bus->mdio_lock should be locked when using this function */
895 static bool vsc8574_is_serdes_init(struct phy_device *phydev)
896 {
897 	u16 reg;
898 	bool ret;
899 
900 	phy_base_write(phydev, MSCC_EXT_PAGE_ACCESS,
901 		       MSCC_PHY_PAGE_EXTENDED_GPIO);
902 
903 	reg = phy_base_read(phydev, MSCC_TRAP_ROM_ADDR(1));
904 	if (reg != 0x3eb7) {
905 		ret = false;
906 		goto out;
907 	}
908 
909 	reg = phy_base_read(phydev, MSCC_PATCH_RAM_ADDR(1));
910 	if (reg != 0x4012) {
911 		ret = false;
912 		goto out;
913 	}
914 
915 	reg = phy_base_read(phydev, MSCC_INT_MEM_CNTL);
916 	if (reg != EN_PATCH_RAM_TRAP_ADDR(1)) {
917 		ret = false;
918 		goto out;
919 	}
920 
921 	reg = phy_base_read(phydev, MSCC_DW8051_CNTL_STATUS);
922 	if ((MICRO_NSOFT_RESET | RUN_FROM_INT_ROM |  DW8051_CLK_EN |
923 	     MICRO_CLK_EN) != (reg & MSCC_DW8051_VLD_MASK)) {
924 		ret = false;
925 		goto out;
926 	}
927 
928 	ret = true;
929 out:
930 	phy_base_write(phydev, MSCC_EXT_PAGE_ACCESS, MSCC_PHY_PAGE_STANDARD);
931 
932 	return ret;
933 }
934 
935 /* bus->mdio_lock should be locked when using this function */
936 static int vsc8574_config_pre_init(struct phy_device *phydev)
937 {
938 	static const struct reg_val pre_init1[] = {
939 		{0x0fae, 0x000401bd},
940 		{0x0fac, 0x000f000f},
941 		{0x17a0, 0x00a0f147},
942 		{0x0fe4, 0x00052f54},
943 		{0x1792, 0x0027303d},
944 		{0x07fe, 0x00000704},
945 		{0x0fe0, 0x00060150},
946 		{0x0f82, 0x0012b00a},
947 		{0x0f80, 0x00000d74},
948 		{0x02e0, 0x00000012},
949 		{0x03a2, 0x00050208},
950 		{0x03b2, 0x00009186},
951 		{0x0fb0, 0x000e3700},
952 		{0x1688, 0x00049f81},
953 		{0x0fd2, 0x0000ffff},
954 		{0x168a, 0x00039fa2},
955 		{0x1690, 0x0020640b},
956 		{0x0258, 0x00002220},
957 		{0x025a, 0x00002a20},
958 		{0x025c, 0x00003060},
959 		{0x025e, 0x00003fa0},
960 		{0x03a6, 0x0000e0f0},
961 		{0x0f92, 0x00001489},
962 		{0x16a2, 0x00007000},
963 		{0x16a6, 0x00071448},
964 		{0x16a0, 0x00eeffdd},
965 		{0x0fe8, 0x0091b06c},
966 		{0x0fea, 0x00041600},
967 		{0x16b0, 0x00eeff00},
968 		{0x16b2, 0x00007000},
969 		{0x16b4, 0x00000814},
970 		{0x0f90, 0x00688980},
971 		{0x03a4, 0x0000d8f0},
972 		{0x0fc0, 0x00000400},
973 		{0x07fa, 0x0050100f},
974 		{0x0796, 0x00000003},
975 		{0x07f8, 0x00c3ff98},
976 		{0x0fa4, 0x0018292a},
977 		{0x168c, 0x00d2c46f},
978 		{0x17a2, 0x00000620},
979 		{0x16a4, 0x0013132f},
980 		{0x16a8, 0x00000000},
981 		{0x0ffc, 0x00c0a028},
982 		{0x0fec, 0x00901c09},
983 		{0x0fee, 0x0004a6a1},
984 		{0x0ffe, 0x00b01807},
985 	};
986 	static const struct reg_val pre_init2[] = {
987 		{0x0486, 0x0008a518},
988 		{0x0488, 0x006dc696},
989 		{0x048a, 0x00000912},
990 		{0x048e, 0x00000db6},
991 		{0x049c, 0x00596596},
992 		{0x049e, 0x00000514},
993 		{0x04a2, 0x00410280},
994 		{0x04a4, 0x00000000},
995 		{0x04a6, 0x00000000},
996 		{0x04a8, 0x00000000},
997 		{0x04aa, 0x00000000},
998 		{0x04ae, 0x007df7dd},
999 		{0x04b0, 0x006d95d4},
1000 		{0x04b2, 0x00492410},
1001 	};
1002 	struct device *dev = &phydev->mdio.dev;
1003 	const struct firmware *fw;
1004 	unsigned int i;
1005 	u16 crc, reg;
1006 	bool serdes_init;
1007 	int ret;
1008 
1009 	phy_base_write(phydev, MSCC_EXT_PAGE_ACCESS, MSCC_PHY_PAGE_STANDARD);
1010 
1011 	/* all writes below are broadcasted to all PHYs in the same package */
1012 	reg = phy_base_read(phydev, MSCC_PHY_EXT_CNTL_STATUS);
1013 	reg |= SMI_BROADCAST_WR_EN;
1014 	phy_base_write(phydev, MSCC_PHY_EXT_CNTL_STATUS, reg);
1015 
1016 	phy_base_write(phydev, MII_VSC85XX_INT_MASK, 0);
1017 
1018 	/* The below register writes are tweaking analog and electrical
1019 	 * configuration that were determined through characterization by PHY
1020 	 * engineers. These don't mean anything more than "these are the best
1021 	 * values".
1022 	 */
1023 	phy_base_write(phydev, MSCC_PHY_EXT_PHY_CNTL_2, 0x0040);
1024 
1025 	phy_base_write(phydev, MSCC_EXT_PAGE_ACCESS, MSCC_PHY_PAGE_TEST);
1026 
1027 	phy_base_write(phydev, MSCC_PHY_TEST_PAGE_20, 0x4320);
1028 	phy_base_write(phydev, MSCC_PHY_TEST_PAGE_24, 0x0c00);
1029 	phy_base_write(phydev, MSCC_PHY_TEST_PAGE_9, 0x18ca);
1030 	phy_base_write(phydev, MSCC_PHY_TEST_PAGE_5, 0x1b20);
1031 
1032 	reg = phy_base_read(phydev, MSCC_PHY_TEST_PAGE_8);
1033 	reg |= 0x8000;
1034 	phy_base_write(phydev, MSCC_PHY_TEST_PAGE_8, reg);
1035 
1036 	phy_base_write(phydev, MSCC_EXT_PAGE_ACCESS, MSCC_PHY_PAGE_TR);
1037 
1038 	for (i = 0; i < ARRAY_SIZE(pre_init1); i++)
1039 		vsc8584_csr_write(phydev, pre_init1[i].reg, pre_init1[i].val);
1040 
1041 	phy_base_write(phydev, MSCC_EXT_PAGE_ACCESS, MSCC_PHY_PAGE_EXTENDED_2);
1042 
1043 	phy_base_write(phydev, MSCC_PHY_CU_PMD_TX_CNTL, 0x028e);
1044 
1045 	phy_base_write(phydev, MSCC_EXT_PAGE_ACCESS, MSCC_PHY_PAGE_TR);
1046 
1047 	for (i = 0; i < ARRAY_SIZE(pre_init2); i++)
1048 		vsc8584_csr_write(phydev, pre_init2[i].reg, pre_init2[i].val);
1049 
1050 	phy_base_write(phydev, MSCC_EXT_PAGE_ACCESS, MSCC_PHY_PAGE_TEST);
1051 
1052 	reg = phy_base_read(phydev, MSCC_PHY_TEST_PAGE_8);
1053 	reg &= ~0x8000;
1054 	phy_base_write(phydev, MSCC_PHY_TEST_PAGE_8, reg);
1055 
1056 	phy_base_write(phydev, MSCC_EXT_PAGE_ACCESS, MSCC_PHY_PAGE_STANDARD);
1057 
1058 	/* end of write broadcasting */
1059 	reg = phy_base_read(phydev, MSCC_PHY_EXT_CNTL_STATUS);
1060 	reg &= ~SMI_BROADCAST_WR_EN;
1061 	phy_base_write(phydev, MSCC_PHY_EXT_CNTL_STATUS, reg);
1062 
1063 	ret = request_firmware(&fw, MSCC_VSC8574_REVB_INT8051_FW, dev);
1064 	if (ret) {
1065 		dev_err(dev, "failed to load firmware %s, ret: %d\n",
1066 			MSCC_VSC8574_REVB_INT8051_FW, ret);
1067 		return ret;
1068 	}
1069 
1070 	/* Add one byte to size for the one added by the patch_fw function */
1071 	ret = vsc8584_get_fw_crc(phydev,
1072 				 MSCC_VSC8574_REVB_INT8051_FW_START_ADDR,
1073 				 fw->size + 1, &crc);
1074 	if (ret)
1075 		goto out;
1076 
1077 	if (crc == MSCC_VSC8574_REVB_INT8051_FW_CRC) {
1078 		serdes_init = vsc8574_is_serdes_init(phydev);
1079 
1080 		if (!serdes_init) {
1081 			ret = vsc8584_micro_assert_reset(phydev);
1082 			if (ret) {
1083 				dev_err(dev,
1084 					"%s: failed to assert reset of micro\n",
1085 					__func__);
1086 				goto out;
1087 			}
1088 		}
1089 	} else {
1090 		dev_dbg(dev, "FW CRC is not the expected one, patching FW\n");
1091 
1092 		serdes_init = false;
1093 
1094 		if (vsc8584_patch_fw(phydev, fw))
1095 			dev_warn(dev,
1096 				 "failed to patch FW, expect non-optimal device\n");
1097 	}
1098 
1099 	if (!serdes_init) {
1100 		phy_base_write(phydev, MSCC_EXT_PAGE_ACCESS,
1101 			       MSCC_PHY_PAGE_EXTENDED_GPIO);
1102 
1103 		phy_base_write(phydev, MSCC_TRAP_ROM_ADDR(1), 0x3eb7);
1104 		phy_base_write(phydev, MSCC_PATCH_RAM_ADDR(1), 0x4012);
1105 		phy_base_write(phydev, MSCC_INT_MEM_CNTL,
1106 			       EN_PATCH_RAM_TRAP_ADDR(1));
1107 
1108 		vsc8584_micro_deassert_reset(phydev, false);
1109 
1110 		/* Add one byte to size for the one added by the patch_fw
1111 		 * function
1112 		 */
1113 		ret = vsc8584_get_fw_crc(phydev,
1114 					 MSCC_VSC8574_REVB_INT8051_FW_START_ADDR,
1115 					 fw->size + 1, &crc);
1116 		if (ret)
1117 			goto out;
1118 
1119 		if (crc != MSCC_VSC8574_REVB_INT8051_FW_CRC)
1120 			dev_warn(dev,
1121 				 "FW CRC after patching is not the expected one, expect non-optimal device\n");
1122 	}
1123 
1124 	phy_base_write(phydev, MSCC_EXT_PAGE_ACCESS,
1125 		       MSCC_PHY_PAGE_EXTENDED_GPIO);
1126 
1127 	ret = vsc8584_cmd(phydev, PROC_CMD_1588_DEFAULT_INIT |
1128 			  PROC_CMD_PHY_INIT);
1129 
1130 out:
1131 	phy_base_write(phydev, MSCC_EXT_PAGE_ACCESS, MSCC_PHY_PAGE_STANDARD);
1132 
1133 	release_firmware(fw);
1134 
1135 	return ret;
1136 }
1137 
1138 /* bus->mdio_lock should be locked when using this function */
1139 static int vsc8584_config_pre_init(struct phy_device *phydev)
1140 {
1141 	static const struct reg_val pre_init1[] = {
1142 		{0x07fa, 0x0050100f},
1143 		{0x1688, 0x00049f81},
1144 		{0x0f90, 0x00688980},
1145 		{0x03a4, 0x0000d8f0},
1146 		{0x0fc0, 0x00000400},
1147 		{0x0f82, 0x0012b002},
1148 		{0x1686, 0x00000004},
1149 		{0x168c, 0x00d2c46f},
1150 		{0x17a2, 0x00000620},
1151 		{0x16a0, 0x00eeffdd},
1152 		{0x16a6, 0x00071448},
1153 		{0x16a4, 0x0013132f},
1154 		{0x16a8, 0x00000000},
1155 		{0x0ffc, 0x00c0a028},
1156 		{0x0fe8, 0x0091b06c},
1157 		{0x0fea, 0x00041600},
1158 		{0x0f80, 0x00fffaff},
1159 		{0x0fec, 0x00901809},
1160 		{0x0ffe, 0x00b01007},
1161 		{0x16b0, 0x00eeff00},
1162 		{0x16b2, 0x00007000},
1163 		{0x16b4, 0x00000814},
1164 	};
1165 	static const struct reg_val pre_init2[] = {
1166 		{0x0486, 0x0008a518},
1167 		{0x0488, 0x006dc696},
1168 		{0x048a, 0x00000912},
1169 	};
1170 	const struct firmware *fw;
1171 	struct device *dev = &phydev->mdio.dev;
1172 	unsigned int i;
1173 	u16 crc, reg;
1174 	int ret;
1175 
1176 	phy_base_write(phydev, MSCC_EXT_PAGE_ACCESS, MSCC_PHY_PAGE_STANDARD);
1177 
1178 	/* all writes below are broadcasted to all PHYs in the same package */
1179 	reg = phy_base_read(phydev, MSCC_PHY_EXT_CNTL_STATUS);
1180 	reg |= SMI_BROADCAST_WR_EN;
1181 	phy_base_write(phydev, MSCC_PHY_EXT_CNTL_STATUS, reg);
1182 
1183 	phy_base_write(phydev, MII_VSC85XX_INT_MASK, 0);
1184 
1185 	reg = phy_base_read(phydev,  MSCC_PHY_BYPASS_CONTROL);
1186 	reg |= PARALLEL_DET_IGNORE_ADVERTISED;
1187 	phy_base_write(phydev, MSCC_PHY_BYPASS_CONTROL, reg);
1188 
1189 	/* The below register writes are tweaking analog and electrical
1190 	 * configuration that were determined through characterization by PHY
1191 	 * engineers. These don't mean anything more than "these are the best
1192 	 * values".
1193 	 */
1194 	phy_base_write(phydev, MSCC_EXT_PAGE_ACCESS, MSCC_PHY_PAGE_EXTENDED_3);
1195 
1196 	phy_base_write(phydev, MSCC_PHY_SERDES_TX_CRC_ERR_CNT, 0x2000);
1197 
1198 	phy_base_write(phydev, MSCC_EXT_PAGE_ACCESS, MSCC_PHY_PAGE_TEST);
1199 
1200 	phy_base_write(phydev, MSCC_PHY_TEST_PAGE_5, 0x1f20);
1201 
1202 	reg = phy_base_read(phydev, MSCC_PHY_TEST_PAGE_8);
1203 	reg |= 0x8000;
1204 	phy_base_write(phydev, MSCC_PHY_TEST_PAGE_8, reg);
1205 
1206 	phy_base_write(phydev, MSCC_EXT_PAGE_ACCESS, MSCC_PHY_PAGE_TR);
1207 
1208 	phy_base_write(phydev, MSCC_PHY_TR_CNTL, TR_WRITE | TR_ADDR(0x2fa4));
1209 
1210 	reg = phy_base_read(phydev, MSCC_PHY_TR_MSB);
1211 	reg &= ~0x007f;
1212 	reg |= 0x0019;
1213 	phy_base_write(phydev, MSCC_PHY_TR_MSB, reg);
1214 
1215 	phy_base_write(phydev, MSCC_PHY_TR_CNTL, TR_WRITE | TR_ADDR(0x0fa4));
1216 
1217 	for (i = 0; i < ARRAY_SIZE(pre_init1); i++)
1218 		vsc8584_csr_write(phydev, pre_init1[i].reg, pre_init1[i].val);
1219 
1220 	phy_base_write(phydev, MSCC_EXT_PAGE_ACCESS, MSCC_PHY_PAGE_EXTENDED_2);
1221 
1222 	phy_base_write(phydev, MSCC_PHY_CU_PMD_TX_CNTL, 0x028e);
1223 
1224 	phy_base_write(phydev, MSCC_EXT_PAGE_ACCESS, MSCC_PHY_PAGE_TR);
1225 
1226 	for (i = 0; i < ARRAY_SIZE(pre_init2); i++)
1227 		vsc8584_csr_write(phydev, pre_init2[i].reg, pre_init2[i].val);
1228 
1229 	phy_base_write(phydev, MSCC_EXT_PAGE_ACCESS, MSCC_PHY_PAGE_TEST);
1230 
1231 	reg = phy_base_read(phydev, MSCC_PHY_TEST_PAGE_8);
1232 	reg &= ~0x8000;
1233 	phy_base_write(phydev, MSCC_PHY_TEST_PAGE_8, reg);
1234 
1235 	phy_base_write(phydev, MSCC_EXT_PAGE_ACCESS, MSCC_PHY_PAGE_STANDARD);
1236 
1237 	/* end of write broadcasting */
1238 	reg = phy_base_read(phydev, MSCC_PHY_EXT_CNTL_STATUS);
1239 	reg &= ~SMI_BROADCAST_WR_EN;
1240 	phy_base_write(phydev, MSCC_PHY_EXT_CNTL_STATUS, reg);
1241 
1242 	ret = request_firmware(&fw, MSCC_VSC8584_REVB_INT8051_FW, dev);
1243 	if (ret) {
1244 		dev_err(dev, "failed to load firmware %s, ret: %d\n",
1245 			MSCC_VSC8584_REVB_INT8051_FW, ret);
1246 		return ret;
1247 	}
1248 
1249 	/* Add one byte to size for the one added by the patch_fw function */
1250 	ret = vsc8584_get_fw_crc(phydev,
1251 				 MSCC_VSC8584_REVB_INT8051_FW_START_ADDR,
1252 				 fw->size + 1, &crc);
1253 	if (ret)
1254 		goto out;
1255 
1256 	if (crc != MSCC_VSC8584_REVB_INT8051_FW_CRC) {
1257 		dev_dbg(dev, "FW CRC is not the expected one, patching FW\n");
1258 		if (vsc8584_patch_fw(phydev, fw))
1259 			dev_warn(dev,
1260 				 "failed to patch FW, expect non-optimal device\n");
1261 	}
1262 
1263 	vsc8584_micro_deassert_reset(phydev, false);
1264 
1265 	/* Add one byte to size for the one added by the patch_fw function */
1266 	ret = vsc8584_get_fw_crc(phydev,
1267 				 MSCC_VSC8584_REVB_INT8051_FW_START_ADDR,
1268 				 fw->size + 1, &crc);
1269 	if (ret)
1270 		goto out;
1271 
1272 	if (crc != MSCC_VSC8584_REVB_INT8051_FW_CRC)
1273 		dev_warn(dev,
1274 			 "FW CRC after patching is not the expected one, expect non-optimal device\n");
1275 
1276 	ret = vsc8584_micro_assert_reset(phydev);
1277 	if (ret)
1278 		goto out;
1279 
1280 	vsc8584_micro_deassert_reset(phydev, true);
1281 
1282 out:
1283 	phy_base_write(phydev, MSCC_EXT_PAGE_ACCESS, MSCC_PHY_PAGE_STANDARD);
1284 
1285 	release_firmware(fw);
1286 
1287 	return ret;
1288 }
1289 
1290 /* Check if one PHY has already done the init of the parts common to all PHYs
1291  * in the Quad PHY package.
1292  */
1293 static bool vsc8584_is_pkg_init(struct phy_device *phydev, bool reversed)
1294 {
1295 	struct mdio_device **map = phydev->mdio.bus->mdio_map;
1296 	struct vsc8531_private *vsc8531;
1297 	struct phy_device *phy;
1298 	int i, addr;
1299 
1300 	/* VSC8584 is a Quad PHY */
1301 	for (i = 0; i < 4; i++) {
1302 		vsc8531 = phydev->priv;
1303 
1304 		if (reversed)
1305 			addr = vsc8531->base_addr - i;
1306 		else
1307 			addr = vsc8531->base_addr + i;
1308 
1309 		if (!map[addr])
1310 			continue;
1311 
1312 		phy = container_of(map[addr], struct phy_device, mdio);
1313 
1314 		if ((phy->phy_id & phydev->drv->phy_id_mask) !=
1315 		    (phydev->drv->phy_id & phydev->drv->phy_id_mask))
1316 			continue;
1317 
1318 		vsc8531 = phy->priv;
1319 
1320 		if (vsc8531 && vsc8531->pkg_init)
1321 			return true;
1322 	}
1323 
1324 	return false;
1325 }
1326 
1327 static int vsc8584_config_init(struct phy_device *phydev)
1328 {
1329 	struct vsc8531_private *vsc8531 = phydev->priv;
1330 	u16 addr, val;
1331 	int ret, i;
1332 
1333 	phydev->mdix_ctrl = ETH_TP_MDI_AUTO;
1334 
1335 	mutex_lock(&phydev->mdio.bus->mdio_lock);
1336 
1337 	__mdiobus_write(phydev->mdio.bus, phydev->mdio.addr,
1338 			MSCC_EXT_PAGE_ACCESS, MSCC_PHY_PAGE_EXTENDED);
1339 	addr = __mdiobus_read(phydev->mdio.bus, phydev->mdio.addr,
1340 			      MSCC_PHY_EXT_PHY_CNTL_4);
1341 	addr >>= PHY_CNTL_4_ADDR_POS;
1342 
1343 	val = __mdiobus_read(phydev->mdio.bus, phydev->mdio.addr,
1344 			     MSCC_PHY_ACTIPHY_CNTL);
1345 	if (val & PHY_ADDR_REVERSED)
1346 		vsc8531->base_addr = phydev->mdio.addr + addr;
1347 	else
1348 		vsc8531->base_addr = phydev->mdio.addr - addr;
1349 
1350 	vsc8531->addr = addr;
1351 
1352 	/* Some parts of the init sequence are identical for every PHY in the
1353 	 * package. Some parts are modifying the GPIO register bank which is a
1354 	 * set of registers that are affecting all PHYs, a few resetting the
1355 	 * microprocessor common to all PHYs. The CRC check responsible of the
1356 	 * checking the firmware within the 8051 microprocessor can only be
1357 	 * accessed via the PHY whose internal address in the package is 0.
1358 	 * All PHYs' interrupts mask register has to be zeroed before enabling
1359 	 * any PHY's interrupt in this register.
1360 	 * For all these reasons, we need to do the init sequence once and only
1361 	 * once whatever is the first PHY in the package that is initialized and
1362 	 * do the correct init sequence for all PHYs that are package-critical
1363 	 * in this pre-init function.
1364 	 */
1365 	if (!vsc8584_is_pkg_init(phydev, val & PHY_ADDR_REVERSED ? 1 : 0)) {
1366 		/* The following switch statement assumes that the lowest
1367 		 * nibble of the phy_id_mask is always 0. This works because
1368 		 * the lowest nibble of the PHY_ID's below are also 0.
1369 		 */
1370 		WARN_ON(phydev->drv->phy_id_mask & 0xf);
1371 
1372 		switch (phydev->phy_id & phydev->drv->phy_id_mask) {
1373 		case PHY_ID_VSC8504:
1374 		case PHY_ID_VSC8552:
1375 		case PHY_ID_VSC8572:
1376 		case PHY_ID_VSC8574:
1377 			ret = vsc8574_config_pre_init(phydev);
1378 			break;
1379 		case PHY_ID_VSC856X:
1380 		case PHY_ID_VSC8575:
1381 		case PHY_ID_VSC8582:
1382 		case PHY_ID_VSC8584:
1383 			ret = vsc8584_config_pre_init(phydev);
1384 			break;
1385 		default:
1386 			ret = -EINVAL;
1387 			break;
1388 		}
1389 
1390 		if (ret)
1391 			goto err;
1392 	}
1393 
1394 	vsc8531->pkg_init = true;
1395 
1396 	phy_base_write(phydev, MSCC_EXT_PAGE_ACCESS,
1397 		       MSCC_PHY_PAGE_EXTENDED_GPIO);
1398 
1399 	val = phy_base_read(phydev, MSCC_PHY_MAC_CFG_FASTLINK);
1400 	val &= ~MAC_CFG_MASK;
1401 	if (phydev->interface == PHY_INTERFACE_MODE_QSGMII) {
1402 		val |= MAC_CFG_QSGMII;
1403 	} else if (phydev->interface == PHY_INTERFACE_MODE_SGMII) {
1404 		val |= MAC_CFG_SGMII;
1405 	} else if (phy_interface_is_rgmii(phydev)) {
1406 		val |= MAC_CFG_RGMII;
1407 	} else {
1408 		ret = -EINVAL;
1409 		goto err;
1410 	}
1411 
1412 	ret = phy_base_write(phydev, MSCC_PHY_MAC_CFG_FASTLINK, val);
1413 	if (ret)
1414 		goto err;
1415 
1416 	if (!phy_interface_is_rgmii(phydev)) {
1417 		val = PROC_CMD_MCB_ACCESS_MAC_CONF | PROC_CMD_RST_CONF_PORT |
1418 			PROC_CMD_READ_MOD_WRITE_PORT;
1419 		if (phydev->interface == PHY_INTERFACE_MODE_QSGMII)
1420 			val |= PROC_CMD_QSGMII_MAC;
1421 		else
1422 			val |= PROC_CMD_SGMII_MAC;
1423 
1424 		ret = vsc8584_cmd(phydev, val);
1425 		if (ret)
1426 			goto err;
1427 
1428 		usleep_range(10000, 20000);
1429 	}
1430 
1431 	/* Disable SerDes for 100Base-FX */
1432 	ret = vsc8584_cmd(phydev, PROC_CMD_FIBER_MEDIA_CONF |
1433 			  PROC_CMD_FIBER_PORT(addr) | PROC_CMD_FIBER_DISABLE |
1434 			  PROC_CMD_READ_MOD_WRITE_PORT |
1435 			  PROC_CMD_RST_CONF_PORT | PROC_CMD_FIBER_100BASE_FX);
1436 	if (ret)
1437 		goto err;
1438 
1439 	/* Disable SerDes for 1000Base-X */
1440 	ret = vsc8584_cmd(phydev, PROC_CMD_FIBER_MEDIA_CONF |
1441 			  PROC_CMD_FIBER_PORT(addr) | PROC_CMD_FIBER_DISABLE |
1442 			  PROC_CMD_READ_MOD_WRITE_PORT |
1443 			  PROC_CMD_RST_CONF_PORT | PROC_CMD_FIBER_1000BASE_X);
1444 	if (ret)
1445 		goto err;
1446 
1447 	mutex_unlock(&phydev->mdio.bus->mdio_lock);
1448 
1449 	ret = vsc8584_macsec_init(phydev);
1450 	if (ret)
1451 		return ret;
1452 
1453 	phy_write(phydev, MSCC_EXT_PAGE_ACCESS, MSCC_PHY_PAGE_STANDARD);
1454 
1455 	val = phy_read(phydev, MSCC_PHY_EXT_PHY_CNTL_1);
1456 	val &= ~(MEDIA_OP_MODE_MASK | VSC8584_MAC_IF_SELECTION_MASK);
1457 	val |= (MEDIA_OP_MODE_COPPER << MEDIA_OP_MODE_POS) |
1458 	       (VSC8584_MAC_IF_SELECTION_SGMII << VSC8584_MAC_IF_SELECTION_POS);
1459 	ret = phy_write(phydev, MSCC_PHY_EXT_PHY_CNTL_1, val);
1460 	if (ret)
1461 		return ret;
1462 
1463 	if (phy_interface_is_rgmii(phydev)) {
1464 		ret = vsc85xx_rgmii_set_skews(phydev, VSC8572_RGMII_CNTL,
1465 					      VSC8572_RGMII_RX_DELAY_MASK,
1466 					      VSC8572_RGMII_TX_DELAY_MASK);
1467 		if (ret)
1468 			return ret;
1469 	}
1470 
1471 	ret = genphy_soft_reset(phydev);
1472 	if (ret)
1473 		return ret;
1474 
1475 	for (i = 0; i < vsc8531->nleds; i++) {
1476 		ret = vsc85xx_led_cntl_set(phydev, i, vsc8531->leds_mode[i]);
1477 		if (ret)
1478 			return ret;
1479 	}
1480 
1481 	return 0;
1482 
1483 err:
1484 	mutex_unlock(&phydev->mdio.bus->mdio_lock);
1485 	return ret;
1486 }
1487 
1488 static irqreturn_t vsc8584_handle_interrupt(struct phy_device *phydev)
1489 {
1490 	int irq_status;
1491 
1492 	irq_status = phy_read(phydev, MII_VSC85XX_INT_STATUS);
1493 	if (irq_status < 0 || !(irq_status & MII_VSC85XX_INT_MASK_MASK))
1494 		return IRQ_NONE;
1495 
1496 	if (irq_status & MII_VSC85XX_INT_MASK_EXT)
1497 		vsc8584_handle_macsec_interrupt(phydev);
1498 
1499 	if (irq_status & MII_VSC85XX_INT_MASK_LINK_CHG)
1500 		phy_mac_interrupt(phydev);
1501 
1502 	return IRQ_HANDLED;
1503 }
1504 
1505 static int vsc85xx_config_init(struct phy_device *phydev)
1506 {
1507 	int rc, i, phy_id;
1508 	struct vsc8531_private *vsc8531 = phydev->priv;
1509 
1510 	rc = vsc85xx_default_config(phydev);
1511 	if (rc)
1512 		return rc;
1513 
1514 	rc = vsc85xx_mac_if_set(phydev, phydev->interface);
1515 	if (rc)
1516 		return rc;
1517 
1518 	rc = vsc85xx_edge_rate_cntl_set(phydev, vsc8531->rate_magic);
1519 	if (rc)
1520 		return rc;
1521 
1522 	phy_id = phydev->drv->phy_id & phydev->drv->phy_id_mask;
1523 	if (PHY_ID_VSC8531 == phy_id || PHY_ID_VSC8541 == phy_id ||
1524 	    PHY_ID_VSC8530 == phy_id || PHY_ID_VSC8540 == phy_id) {
1525 		rc = vsc8531_pre_init_seq_set(phydev);
1526 		if (rc)
1527 			return rc;
1528 	}
1529 
1530 	rc = vsc85xx_eee_init_seq_set(phydev);
1531 	if (rc)
1532 		return rc;
1533 
1534 	for (i = 0; i < vsc8531->nleds; i++) {
1535 		rc = vsc85xx_led_cntl_set(phydev, i, vsc8531->leds_mode[i]);
1536 		if (rc)
1537 			return rc;
1538 	}
1539 
1540 	return 0;
1541 }
1542 
1543 static int vsc8584_did_interrupt(struct phy_device *phydev)
1544 {
1545 	int rc = 0;
1546 
1547 	if (phydev->interrupts == PHY_INTERRUPT_ENABLED)
1548 		rc = phy_read(phydev, MII_VSC85XX_INT_STATUS);
1549 
1550 	return (rc < 0) ? 0 : rc & MII_VSC85XX_INT_MASK_MASK;
1551 }
1552 
1553 static int vsc8514_config_pre_init(struct phy_device *phydev)
1554 {
1555 	/* These are the settings to override the silicon default
1556 	 * values to handle hardware performance of PHY. They
1557 	 * are set at Power-On state and remain until PHY Reset.
1558 	 */
1559 	static const struct reg_val pre_init1[] = {
1560 		{0x0f90, 0x00688980},
1561 		{0x0786, 0x00000003},
1562 		{0x07fa, 0x0050100f},
1563 		{0x0f82, 0x0012b002},
1564 		{0x1686, 0x00000004},
1565 		{0x168c, 0x00d2c46f},
1566 		{0x17a2, 0x00000620},
1567 		{0x16a0, 0x00eeffdd},
1568 		{0x16a6, 0x00071448},
1569 		{0x16a4, 0x0013132f},
1570 		{0x16a8, 0x00000000},
1571 		{0x0ffc, 0x00c0a028},
1572 		{0x0fe8, 0x0091b06c},
1573 		{0x0fea, 0x00041600},
1574 		{0x0f80, 0x00fffaff},
1575 		{0x0fec, 0x00901809},
1576 		{0x0ffe, 0x00b01007},
1577 		{0x16b0, 0x00eeff00},
1578 		{0x16b2, 0x00007000},
1579 		{0x16b4, 0x00000814},
1580 	};
1581 	unsigned int i;
1582 	u16 reg;
1583 
1584 	phy_base_write(phydev, MSCC_EXT_PAGE_ACCESS, MSCC_PHY_PAGE_STANDARD);
1585 
1586 	/* all writes below are broadcasted to all PHYs in the same package */
1587 	reg = phy_base_read(phydev, MSCC_PHY_EXT_CNTL_STATUS);
1588 	reg |= SMI_BROADCAST_WR_EN;
1589 	phy_base_write(phydev, MSCC_PHY_EXT_CNTL_STATUS, reg);
1590 
1591 	phy_base_write(phydev, MSCC_EXT_PAGE_ACCESS, MSCC_PHY_PAGE_TEST);
1592 
1593 	reg = phy_base_read(phydev, MSCC_PHY_TEST_PAGE_8);
1594 	reg |= BIT(15);
1595 	phy_base_write(phydev, MSCC_PHY_TEST_PAGE_8, reg);
1596 
1597 	phy_base_write(phydev, MSCC_EXT_PAGE_ACCESS, MSCC_PHY_PAGE_TR);
1598 
1599 	for (i = 0; i < ARRAY_SIZE(pre_init1); i++)
1600 		vsc8584_csr_write(phydev, pre_init1[i].reg, pre_init1[i].val);
1601 
1602 	phy_base_write(phydev, MSCC_EXT_PAGE_ACCESS, MSCC_PHY_PAGE_TEST);
1603 
1604 	reg = phy_base_read(phydev, MSCC_PHY_TEST_PAGE_8);
1605 	reg &= ~BIT(15);
1606 	phy_base_write(phydev, MSCC_PHY_TEST_PAGE_8, reg);
1607 
1608 	phy_base_write(phydev, MSCC_EXT_PAGE_ACCESS, MSCC_PHY_PAGE_STANDARD);
1609 
1610 	reg = phy_base_read(phydev, MSCC_PHY_EXT_CNTL_STATUS);
1611 	reg &= ~SMI_BROADCAST_WR_EN;
1612 	phy_base_write(phydev, MSCC_PHY_EXT_CNTL_STATUS, reg);
1613 
1614 	return 0;
1615 }
1616 
1617 static u32 vsc85xx_csr_ctrl_phy_read(struct phy_device *phydev,
1618 				     u32 target, u32 reg)
1619 {
1620 	unsigned long deadline;
1621 	u32 val, val_l, val_h;
1622 
1623 	phy_base_write(phydev, MSCC_EXT_PAGE_ACCESS, MSCC_PHY_PAGE_CSR_CNTL);
1624 
1625 	/* CSR registers are grouped under different Target IDs.
1626 	 * 6-bit Target_ID is split between MSCC_EXT_PAGE_CSR_CNTL_20 and
1627 	 * MSCC_EXT_PAGE_CSR_CNTL_19 registers.
1628 	 * Target_ID[5:2] maps to bits[3:0] of MSCC_EXT_PAGE_CSR_CNTL_20
1629 	 * and Target_ID[1:0] maps to bits[13:12] of MSCC_EXT_PAGE_CSR_CNTL_19.
1630 	 */
1631 
1632 	/* Setup the Target ID */
1633 	phy_base_write(phydev, MSCC_EXT_PAGE_CSR_CNTL_20,
1634 		       MSCC_PHY_CSR_CNTL_20_TARGET(target >> 2));
1635 
1636 	/* Trigger CSR Action - Read into the CSR's */
1637 	phy_base_write(phydev, MSCC_EXT_PAGE_CSR_CNTL_19,
1638 		       MSCC_PHY_CSR_CNTL_19_CMD | MSCC_PHY_CSR_CNTL_19_READ |
1639 		       MSCC_PHY_CSR_CNTL_19_REG_ADDR(reg) |
1640 		       MSCC_PHY_CSR_CNTL_19_TARGET(target & 0x3));
1641 
1642 	/* Wait for register access*/
1643 	deadline = jiffies + msecs_to_jiffies(PROC_CMD_NCOMPLETED_TIMEOUT_MS);
1644 	do {
1645 		usleep_range(500, 1000);
1646 		val = phy_base_read(phydev, MSCC_EXT_PAGE_CSR_CNTL_19);
1647 	} while (time_before(jiffies, deadline) &&
1648 		!(val & MSCC_PHY_CSR_CNTL_19_CMD));
1649 
1650 	if (!(val & MSCC_PHY_CSR_CNTL_19_CMD))
1651 		return 0xffffffff;
1652 
1653 	/* Read the Least Significant Word (LSW) (17) */
1654 	val_l = phy_base_read(phydev, MSCC_EXT_PAGE_CSR_CNTL_17);
1655 
1656 	/* Read the Most Significant Word (MSW) (18) */
1657 	val_h = phy_base_read(phydev, MSCC_EXT_PAGE_CSR_CNTL_18);
1658 
1659 	phy_base_write(phydev, MSCC_EXT_PAGE_ACCESS,
1660 		       MSCC_PHY_PAGE_STANDARD);
1661 
1662 	return (val_h << 16) | val_l;
1663 }
1664 
1665 static int vsc85xx_csr_ctrl_phy_write(struct phy_device *phydev,
1666 				      u32 target, u32 reg, u32 val)
1667 {
1668 	unsigned long deadline;
1669 
1670 	phy_base_write(phydev, MSCC_EXT_PAGE_ACCESS, MSCC_PHY_PAGE_CSR_CNTL);
1671 
1672 	/* CSR registers are grouped under different Target IDs.
1673 	 * 6-bit Target_ID is split between MSCC_EXT_PAGE_CSR_CNTL_20 and
1674 	 * MSCC_EXT_PAGE_CSR_CNTL_19 registers.
1675 	 * Target_ID[5:2] maps to bits[3:0] of MSCC_EXT_PAGE_CSR_CNTL_20
1676 	 * and Target_ID[1:0] maps to bits[13:12] of MSCC_EXT_PAGE_CSR_CNTL_19.
1677 	 */
1678 
1679 	/* Setup the Target ID */
1680 	phy_base_write(phydev, MSCC_EXT_PAGE_CSR_CNTL_20,
1681 		       MSCC_PHY_CSR_CNTL_20_TARGET(target >> 2));
1682 
1683 	/* Write the Least Significant Word (LSW) (17) */
1684 	phy_base_write(phydev, MSCC_EXT_PAGE_CSR_CNTL_17, (u16)val);
1685 
1686 	/* Write the Most Significant Word (MSW) (18) */
1687 	phy_base_write(phydev, MSCC_EXT_PAGE_CSR_CNTL_18, (u16)(val >> 16));
1688 
1689 	/* Trigger CSR Action - Write into the CSR's */
1690 	phy_base_write(phydev, MSCC_EXT_PAGE_CSR_CNTL_19,
1691 		       MSCC_PHY_CSR_CNTL_19_CMD |
1692 		       MSCC_PHY_CSR_CNTL_19_REG_ADDR(reg) |
1693 		       MSCC_PHY_CSR_CNTL_19_TARGET(target & 0x3));
1694 
1695 	/* Wait for register access */
1696 	deadline = jiffies + msecs_to_jiffies(PROC_CMD_NCOMPLETED_TIMEOUT_MS);
1697 	do {
1698 		usleep_range(500, 1000);
1699 		val = phy_base_read(phydev, MSCC_EXT_PAGE_CSR_CNTL_19);
1700 	} while (time_before(jiffies, deadline) &&
1701 		 !(val & MSCC_PHY_CSR_CNTL_19_CMD));
1702 
1703 	if (!(val & MSCC_PHY_CSR_CNTL_19_CMD))
1704 		return -ETIMEDOUT;
1705 
1706 	phy_base_write(phydev, MSCC_EXT_PAGE_ACCESS,
1707 		       MSCC_PHY_PAGE_STANDARD);
1708 
1709 	return 0;
1710 }
1711 
1712 static int __phy_write_mcb_s6g(struct phy_device *phydev, u32 reg, u8 mcb,
1713 			       u32 op)
1714 {
1715 	unsigned long deadline;
1716 	u32 val;
1717 	int ret;
1718 
1719 	ret = vsc85xx_csr_ctrl_phy_write(phydev, PHY_MCB_TARGET, reg,
1720 					 op | (1 << mcb));
1721 	if (ret)
1722 		return -EINVAL;
1723 
1724 	deadline = jiffies + msecs_to_jiffies(PROC_CMD_NCOMPLETED_TIMEOUT_MS);
1725 	do {
1726 		usleep_range(500, 1000);
1727 		val = vsc85xx_csr_ctrl_phy_read(phydev, PHY_MCB_TARGET, reg);
1728 
1729 		if (val == 0xffffffff)
1730 			return -EIO;
1731 
1732 	} while (time_before(jiffies, deadline) && (val & op));
1733 
1734 	if (val & op)
1735 		return -ETIMEDOUT;
1736 
1737 	return 0;
1738 }
1739 
1740 /* Trigger a read to the spcified MCB */
1741 static int phy_update_mcb_s6g(struct phy_device *phydev, u32 reg, u8 mcb)
1742 {
1743 	return __phy_write_mcb_s6g(phydev, reg, mcb, PHY_MCB_S6G_READ);
1744 }
1745 
1746 /* Trigger a write to the spcified MCB */
1747 static int phy_commit_mcb_s6g(struct phy_device *phydev, u32 reg, u8 mcb)
1748 {
1749 	return __phy_write_mcb_s6g(phydev, reg, mcb, PHY_MCB_S6G_WRITE);
1750 }
1751 
1752 static int vsc8514_config_init(struct phy_device *phydev)
1753 {
1754 	struct vsc8531_private *vsc8531 = phydev->priv;
1755 	unsigned long deadline;
1756 	u16 val, addr;
1757 	int ret, i;
1758 	u32 reg;
1759 
1760 	phydev->mdix_ctrl = ETH_TP_MDI_AUTO;
1761 
1762 	mutex_lock(&phydev->mdio.bus->mdio_lock);
1763 
1764 	__phy_write(phydev, MSCC_EXT_PAGE_ACCESS, MSCC_PHY_PAGE_EXTENDED);
1765 
1766 	addr = __phy_read(phydev, MSCC_PHY_EXT_PHY_CNTL_4);
1767 	addr >>= PHY_CNTL_4_ADDR_POS;
1768 
1769 	val = __phy_read(phydev, MSCC_PHY_ACTIPHY_CNTL);
1770 
1771 	if (val & PHY_ADDR_REVERSED)
1772 		vsc8531->base_addr = phydev->mdio.addr + addr;
1773 	else
1774 		vsc8531->base_addr = phydev->mdio.addr - addr;
1775 
1776 	vsc8531->addr = addr;
1777 
1778 	/* Some parts of the init sequence are identical for every PHY in the
1779 	 * package. Some parts are modifying the GPIO register bank which is a
1780 	 * set of registers that are affecting all PHYs, a few resetting the
1781 	 * microprocessor common to all PHYs.
1782 	 * All PHYs' interrupts mask register has to be zeroed before enabling
1783 	 * any PHY's interrupt in this register.
1784 	 * For all these reasons, we need to do the init sequence once and only
1785 	 * once whatever is the first PHY in the package that is initialized and
1786 	 * do the correct init sequence for all PHYs that are package-critical
1787 	 * in this pre-init function.
1788 	 */
1789 	if (!vsc8584_is_pkg_init(phydev, val & PHY_ADDR_REVERSED ? 1 : 0))
1790 		vsc8514_config_pre_init(phydev);
1791 
1792 	vsc8531->pkg_init = true;
1793 
1794 	phy_base_write(phydev, MSCC_EXT_PAGE_ACCESS,
1795 		       MSCC_PHY_PAGE_EXTENDED_GPIO);
1796 
1797 	val = phy_base_read(phydev, MSCC_PHY_MAC_CFG_FASTLINK);
1798 
1799 	val &= ~MAC_CFG_MASK;
1800 	val |= MAC_CFG_QSGMII;
1801 	ret = phy_base_write(phydev, MSCC_PHY_MAC_CFG_FASTLINK, val);
1802 
1803 	if (ret)
1804 		goto err;
1805 
1806 	ret = vsc8584_cmd(phydev,
1807 			  PROC_CMD_MCB_ACCESS_MAC_CONF |
1808 			  PROC_CMD_RST_CONF_PORT |
1809 			  PROC_CMD_READ_MOD_WRITE_PORT | PROC_CMD_QSGMII_MAC);
1810 	if (ret)
1811 		goto err;
1812 
1813 	/* 6g mcb */
1814 	phy_update_mcb_s6g(phydev, PHY_MCB_S6G_CFG, 0);
1815 	/* lcpll mcb */
1816 	phy_update_mcb_s6g(phydev, PHY_S6G_LCPLL_CFG, 0);
1817 	/* pll5gcfg0 */
1818 	ret = vsc85xx_csr_ctrl_phy_write(phydev, PHY_MCB_TARGET,
1819 					 PHY_S6G_PLL5G_CFG0, 0x7036f145);
1820 	if (ret)
1821 		goto err;
1822 
1823 	phy_commit_mcb_s6g(phydev, PHY_S6G_LCPLL_CFG, 0);
1824 	/* pllcfg */
1825 	ret = vsc85xx_csr_ctrl_phy_write(phydev, PHY_MCB_TARGET,
1826 					 PHY_S6G_PLL_CFG,
1827 					 (3 << PHY_S6G_PLL_ENA_OFFS_POS) |
1828 					 (120 << PHY_S6G_PLL_FSM_CTRL_DATA_POS)
1829 					 | (0 << PHY_S6G_PLL_FSM_ENA_POS));
1830 	if (ret)
1831 		goto err;
1832 
1833 	/* commoncfg */
1834 	ret = vsc85xx_csr_ctrl_phy_write(phydev, PHY_MCB_TARGET,
1835 					 PHY_S6G_COMMON_CFG,
1836 					 (0 << PHY_S6G_SYS_RST_POS) |
1837 					 (0 << PHY_S6G_ENA_LANE_POS) |
1838 					 (0 << PHY_S6G_ENA_LOOP_POS) |
1839 					 (0 << PHY_S6G_QRATE_POS) |
1840 					 (3 << PHY_S6G_IF_MODE_POS));
1841 	if (ret)
1842 		goto err;
1843 
1844 	/* misccfg */
1845 	ret = vsc85xx_csr_ctrl_phy_write(phydev, PHY_MCB_TARGET,
1846 					 PHY_S6G_MISC_CFG, 1);
1847 	if (ret)
1848 		goto err;
1849 
1850 	/* gpcfg */
1851 	ret = vsc85xx_csr_ctrl_phy_write(phydev, PHY_MCB_TARGET,
1852 					 PHY_S6G_GPC_CFG, 768);
1853 	if (ret)
1854 		goto err;
1855 
1856 	phy_commit_mcb_s6g(phydev, PHY_S6G_DFT_CFG2, 0);
1857 
1858 	deadline = jiffies + msecs_to_jiffies(PROC_CMD_NCOMPLETED_TIMEOUT_MS);
1859 	do {
1860 		usleep_range(500, 1000);
1861 		phy_update_mcb_s6g(phydev, PHY_MCB_S6G_CFG,
1862 				   0); /* read 6G MCB into CSRs */
1863 		reg = vsc85xx_csr_ctrl_phy_read(phydev, PHY_MCB_TARGET,
1864 						PHY_S6G_PLL_STATUS);
1865 		if (reg == 0xffffffff) {
1866 			mutex_unlock(&phydev->mdio.bus->mdio_lock);
1867 			return -EIO;
1868 		}
1869 
1870 	} while (time_before(jiffies, deadline) && (reg & BIT(12)));
1871 
1872 	if (reg & BIT(12)) {
1873 		mutex_unlock(&phydev->mdio.bus->mdio_lock);
1874 		return -ETIMEDOUT;
1875 	}
1876 
1877 	/* misccfg */
1878 	ret = vsc85xx_csr_ctrl_phy_write(phydev, PHY_MCB_TARGET,
1879 					 PHY_S6G_MISC_CFG, 0);
1880 	if (ret)
1881 		goto err;
1882 
1883 	phy_commit_mcb_s6g(phydev, PHY_MCB_S6G_CFG, 0);
1884 
1885 	deadline = jiffies + msecs_to_jiffies(PROC_CMD_NCOMPLETED_TIMEOUT_MS);
1886 	do {
1887 		usleep_range(500, 1000);
1888 		phy_update_mcb_s6g(phydev, PHY_MCB_S6G_CFG,
1889 				   0); /* read 6G MCB into CSRs */
1890 		reg = vsc85xx_csr_ctrl_phy_read(phydev, PHY_MCB_TARGET,
1891 						PHY_S6G_IB_STATUS0);
1892 		if (reg == 0xffffffff) {
1893 			mutex_unlock(&phydev->mdio.bus->mdio_lock);
1894 			return -EIO;
1895 		}
1896 
1897 	} while (time_before(jiffies, deadline) && !(reg & BIT(8)));
1898 
1899 	if (!(reg & BIT(8))) {
1900 		mutex_unlock(&phydev->mdio.bus->mdio_lock);
1901 		return -ETIMEDOUT;
1902 	}
1903 
1904 	mutex_unlock(&phydev->mdio.bus->mdio_lock);
1905 
1906 	ret = phy_write(phydev, MSCC_EXT_PAGE_ACCESS, MSCC_PHY_PAGE_STANDARD);
1907 
1908 	if (ret)
1909 		return ret;
1910 
1911 	ret = phy_modify(phydev, MSCC_PHY_EXT_PHY_CNTL_1, MEDIA_OP_MODE_MASK,
1912 			 MEDIA_OP_MODE_COPPER << MEDIA_OP_MODE_POS);
1913 
1914 	if (ret)
1915 		return ret;
1916 
1917 	ret = genphy_soft_reset(phydev);
1918 
1919 	if (ret)
1920 		return ret;
1921 
1922 	for (i = 0; i < vsc8531->nleds; i++) {
1923 		ret = vsc85xx_led_cntl_set(phydev, i, vsc8531->leds_mode[i]);
1924 		if (ret)
1925 			return ret;
1926 	}
1927 
1928 	return ret;
1929 
1930 err:
1931 	mutex_unlock(&phydev->mdio.bus->mdio_lock);
1932 	return ret;
1933 }
1934 
1935 static int vsc85xx_ack_interrupt(struct phy_device *phydev)
1936 {
1937 	int rc = 0;
1938 
1939 	if (phydev->interrupts == PHY_INTERRUPT_ENABLED)
1940 		rc = phy_read(phydev, MII_VSC85XX_INT_STATUS);
1941 
1942 	return (rc < 0) ? rc : 0;
1943 }
1944 
1945 static int vsc85xx_config_intr(struct phy_device *phydev)
1946 {
1947 	int rc;
1948 
1949 	if (phydev->interrupts == PHY_INTERRUPT_ENABLED) {
1950 		vsc8584_config_macsec_intr(phydev);
1951 
1952 		rc = phy_write(phydev, MII_VSC85XX_INT_MASK,
1953 			       MII_VSC85XX_INT_MASK_MASK);
1954 	} else {
1955 		rc = phy_write(phydev, MII_VSC85XX_INT_MASK, 0);
1956 		if (rc < 0)
1957 			return rc;
1958 		rc = phy_read(phydev, MII_VSC85XX_INT_STATUS);
1959 	}
1960 
1961 	return rc;
1962 }
1963 
1964 static int vsc85xx_config_aneg(struct phy_device *phydev)
1965 {
1966 	int rc;
1967 
1968 	rc = vsc85xx_mdix_set(phydev, phydev->mdix_ctrl);
1969 	if (rc < 0)
1970 		return rc;
1971 
1972 	return genphy_config_aneg(phydev);
1973 }
1974 
1975 static int vsc85xx_read_status(struct phy_device *phydev)
1976 {
1977 	int rc;
1978 
1979 	rc = vsc85xx_mdix_get(phydev, &phydev->mdix);
1980 	if (rc < 0)
1981 		return rc;
1982 
1983 	return genphy_read_status(phydev);
1984 }
1985 
1986 static int vsc8514_probe(struct phy_device *phydev)
1987 {
1988 	struct vsc8531_private *vsc8531;
1989 	u32 default_mode[4] = {VSC8531_LINK_1000_ACTIVITY,
1990 	   VSC8531_LINK_100_ACTIVITY, VSC8531_LINK_ACTIVITY,
1991 	   VSC8531_DUPLEX_COLLISION};
1992 
1993 	vsc8531 = devm_kzalloc(&phydev->mdio.dev, sizeof(*vsc8531), GFP_KERNEL);
1994 	if (!vsc8531)
1995 		return -ENOMEM;
1996 
1997 	phydev->priv = vsc8531;
1998 
1999 	vsc8531->nleds = 4;
2000 	vsc8531->supp_led_modes = VSC85XX_SUPP_LED_MODES;
2001 	vsc8531->hw_stats = vsc85xx_hw_stats;
2002 	vsc8531->nstats = ARRAY_SIZE(vsc85xx_hw_stats);
2003 	vsc8531->stats = devm_kcalloc(&phydev->mdio.dev, vsc8531->nstats,
2004 				      sizeof(u64), GFP_KERNEL);
2005 	if (!vsc8531->stats)
2006 		return -ENOMEM;
2007 
2008 	return vsc85xx_dt_led_modes_get(phydev, default_mode);
2009 }
2010 
2011 static int vsc8574_probe(struct phy_device *phydev)
2012 {
2013 	struct vsc8531_private *vsc8531;
2014 	u32 default_mode[4] = {VSC8531_LINK_1000_ACTIVITY,
2015 	   VSC8531_LINK_100_ACTIVITY, VSC8531_LINK_ACTIVITY,
2016 	   VSC8531_DUPLEX_COLLISION};
2017 
2018 	vsc8531 = devm_kzalloc(&phydev->mdio.dev, sizeof(*vsc8531), GFP_KERNEL);
2019 	if (!vsc8531)
2020 		return -ENOMEM;
2021 
2022 	phydev->priv = vsc8531;
2023 
2024 	vsc8531->nleds = 4;
2025 	vsc8531->supp_led_modes = VSC8584_SUPP_LED_MODES;
2026 	vsc8531->hw_stats = vsc8584_hw_stats;
2027 	vsc8531->nstats = ARRAY_SIZE(vsc8584_hw_stats);
2028 	vsc8531->stats = devm_kcalloc(&phydev->mdio.dev, vsc8531->nstats,
2029 				      sizeof(u64), GFP_KERNEL);
2030 	if (!vsc8531->stats)
2031 		return -ENOMEM;
2032 
2033 	return vsc85xx_dt_led_modes_get(phydev, default_mode);
2034 }
2035 
2036 static int vsc8584_probe(struct phy_device *phydev)
2037 {
2038 	struct vsc8531_private *vsc8531;
2039 	u32 default_mode[4] = {VSC8531_LINK_1000_ACTIVITY,
2040 	   VSC8531_LINK_100_ACTIVITY, VSC8531_LINK_ACTIVITY,
2041 	   VSC8531_DUPLEX_COLLISION};
2042 
2043 	if ((phydev->phy_id & MSCC_DEV_REV_MASK) != VSC8584_REVB) {
2044 		dev_err(&phydev->mdio.dev, "Only VSC8584 revB is supported.\n");
2045 		return -ENOTSUPP;
2046 	}
2047 
2048 	vsc8531 = devm_kzalloc(&phydev->mdio.dev, sizeof(*vsc8531), GFP_KERNEL);
2049 	if (!vsc8531)
2050 		return -ENOMEM;
2051 
2052 	phydev->priv = vsc8531;
2053 
2054 	vsc8531->nleds = 4;
2055 	vsc8531->supp_led_modes = VSC8584_SUPP_LED_MODES;
2056 	vsc8531->hw_stats = vsc8584_hw_stats;
2057 	vsc8531->nstats = ARRAY_SIZE(vsc8584_hw_stats);
2058 	vsc8531->stats = devm_kcalloc(&phydev->mdio.dev, vsc8531->nstats,
2059 				      sizeof(u64), GFP_KERNEL);
2060 	if (!vsc8531->stats)
2061 		return -ENOMEM;
2062 
2063 	return vsc85xx_dt_led_modes_get(phydev, default_mode);
2064 }
2065 
2066 static int vsc85xx_probe(struct phy_device *phydev)
2067 {
2068 	struct vsc8531_private *vsc8531;
2069 	int rate_magic;
2070 	u32 default_mode[2] = {VSC8531_LINK_1000_ACTIVITY,
2071 	   VSC8531_LINK_100_ACTIVITY};
2072 
2073 	rate_magic = vsc85xx_edge_rate_magic_get(phydev);
2074 	if (rate_magic < 0)
2075 		return rate_magic;
2076 
2077 	vsc8531 = devm_kzalloc(&phydev->mdio.dev, sizeof(*vsc8531), GFP_KERNEL);
2078 	if (!vsc8531)
2079 		return -ENOMEM;
2080 
2081 	phydev->priv = vsc8531;
2082 
2083 	vsc8531->rate_magic = rate_magic;
2084 	vsc8531->nleds = 2;
2085 	vsc8531->supp_led_modes = VSC85XX_SUPP_LED_MODES;
2086 	vsc8531->hw_stats = vsc85xx_hw_stats;
2087 	vsc8531->nstats = ARRAY_SIZE(vsc85xx_hw_stats);
2088 	vsc8531->stats = devm_kcalloc(&phydev->mdio.dev, vsc8531->nstats,
2089 				      sizeof(u64), GFP_KERNEL);
2090 	if (!vsc8531->stats)
2091 		return -ENOMEM;
2092 
2093 	return vsc85xx_dt_led_modes_get(phydev, default_mode);
2094 }
2095 
2096 /* Microsemi VSC85xx PHYs */
2097 static struct phy_driver vsc85xx_driver[] = {
2098 {
2099 	.phy_id		= PHY_ID_VSC8502,
2100 	.name		= "Microsemi GE VSC8502 SyncE",
2101 	.phy_id_mask	= 0xfffffff0,
2102 	/* PHY_BASIC_FEATURES */
2103 	.soft_reset	= &genphy_soft_reset,
2104 	.config_init	= &vsc85xx_config_init,
2105 	.config_aneg    = &vsc85xx_config_aneg,
2106 	.read_status	= &vsc85xx_read_status,
2107 	.ack_interrupt	= &vsc85xx_ack_interrupt,
2108 	.config_intr	= &vsc85xx_config_intr,
2109 	.suspend	= &genphy_suspend,
2110 	.resume		= &genphy_resume,
2111 	.probe		= &vsc85xx_probe,
2112 	.set_wol	= &vsc85xx_wol_set,
2113 	.get_wol	= &vsc85xx_wol_get,
2114 	.get_tunable	= &vsc85xx_get_tunable,
2115 	.set_tunable	= &vsc85xx_set_tunable,
2116 	.read_page	= &vsc85xx_phy_read_page,
2117 	.write_page	= &vsc85xx_phy_write_page,
2118 	.get_sset_count = &vsc85xx_get_sset_count,
2119 	.get_strings    = &vsc85xx_get_strings,
2120 	.get_stats      = &vsc85xx_get_stats,
2121 },
2122 {
2123 	.phy_id		= PHY_ID_VSC8504,
2124 	.name		= "Microsemi GE VSC8504 SyncE",
2125 	.phy_id_mask	= 0xfffffff0,
2126 	/* PHY_GBIT_FEATURES */
2127 	.soft_reset	= &genphy_soft_reset,
2128 	.config_init    = &vsc8584_config_init,
2129 	.config_aneg    = &vsc85xx_config_aneg,
2130 	.aneg_done	= &genphy_aneg_done,
2131 	.read_status	= &vsc85xx_read_status,
2132 	.ack_interrupt  = &vsc85xx_ack_interrupt,
2133 	.config_intr    = &vsc85xx_config_intr,
2134 	.did_interrupt  = &vsc8584_did_interrupt,
2135 	.suspend	= &genphy_suspend,
2136 	.resume		= &genphy_resume,
2137 	.probe		= &vsc8574_probe,
2138 	.set_wol	= &vsc85xx_wol_set,
2139 	.get_wol	= &vsc85xx_wol_get,
2140 	.get_tunable	= &vsc85xx_get_tunable,
2141 	.set_tunable	= &vsc85xx_set_tunable,
2142 	.read_page	= &vsc85xx_phy_read_page,
2143 	.write_page	= &vsc85xx_phy_write_page,
2144 	.get_sset_count = &vsc85xx_get_sset_count,
2145 	.get_strings    = &vsc85xx_get_strings,
2146 	.get_stats      = &vsc85xx_get_stats,
2147 },
2148 {
2149 	.phy_id		= PHY_ID_VSC8514,
2150 	.name		= "Microsemi GE VSC8514 SyncE",
2151 	.phy_id_mask	= 0xfffffff0,
2152 	.soft_reset	= &genphy_soft_reset,
2153 	.config_init    = &vsc8514_config_init,
2154 	.config_aneg    = &vsc85xx_config_aneg,
2155 	.read_status	= &vsc85xx_read_status,
2156 	.ack_interrupt  = &vsc85xx_ack_interrupt,
2157 	.config_intr    = &vsc85xx_config_intr,
2158 	.suspend	= &genphy_suspend,
2159 	.resume		= &genphy_resume,
2160 	.probe		= &vsc8514_probe,
2161 	.set_wol	= &vsc85xx_wol_set,
2162 	.get_wol	= &vsc85xx_wol_get,
2163 	.get_tunable	= &vsc85xx_get_tunable,
2164 	.set_tunable	= &vsc85xx_set_tunable,
2165 	.read_page      = &vsc85xx_phy_read_page,
2166 	.write_page     = &vsc85xx_phy_write_page,
2167 	.get_sset_count = &vsc85xx_get_sset_count,
2168 	.get_strings    = &vsc85xx_get_strings,
2169 	.get_stats      = &vsc85xx_get_stats,
2170 },
2171 {
2172 	.phy_id		= PHY_ID_VSC8530,
2173 	.name		= "Microsemi FE VSC8530",
2174 	.phy_id_mask	= 0xfffffff0,
2175 	/* PHY_BASIC_FEATURES */
2176 	.soft_reset	= &genphy_soft_reset,
2177 	.config_init	= &vsc85xx_config_init,
2178 	.config_aneg    = &vsc85xx_config_aneg,
2179 	.read_status	= &vsc85xx_read_status,
2180 	.ack_interrupt	= &vsc85xx_ack_interrupt,
2181 	.config_intr	= &vsc85xx_config_intr,
2182 	.suspend	= &genphy_suspend,
2183 	.resume		= &genphy_resume,
2184 	.probe		= &vsc85xx_probe,
2185 	.set_wol	= &vsc85xx_wol_set,
2186 	.get_wol	= &vsc85xx_wol_get,
2187 	.get_tunable	= &vsc85xx_get_tunable,
2188 	.set_tunable	= &vsc85xx_set_tunable,
2189 	.read_page	= &vsc85xx_phy_read_page,
2190 	.write_page	= &vsc85xx_phy_write_page,
2191 	.get_sset_count = &vsc85xx_get_sset_count,
2192 	.get_strings    = &vsc85xx_get_strings,
2193 	.get_stats      = &vsc85xx_get_stats,
2194 },
2195 {
2196 	.phy_id		= PHY_ID_VSC8531,
2197 	.name		= "Microsemi VSC8531",
2198 	.phy_id_mask    = 0xfffffff0,
2199 	/* PHY_GBIT_FEATURES */
2200 	.soft_reset	= &genphy_soft_reset,
2201 	.config_init    = &vsc85xx_config_init,
2202 	.config_aneg    = &vsc85xx_config_aneg,
2203 	.read_status	= &vsc85xx_read_status,
2204 	.ack_interrupt  = &vsc85xx_ack_interrupt,
2205 	.config_intr    = &vsc85xx_config_intr,
2206 	.suspend	= &genphy_suspend,
2207 	.resume		= &genphy_resume,
2208 	.probe		= &vsc85xx_probe,
2209 	.set_wol	= &vsc85xx_wol_set,
2210 	.get_wol	= &vsc85xx_wol_get,
2211 	.get_tunable	= &vsc85xx_get_tunable,
2212 	.set_tunable	= &vsc85xx_set_tunable,
2213 	.read_page	= &vsc85xx_phy_read_page,
2214 	.write_page	= &vsc85xx_phy_write_page,
2215 	.get_sset_count = &vsc85xx_get_sset_count,
2216 	.get_strings    = &vsc85xx_get_strings,
2217 	.get_stats      = &vsc85xx_get_stats,
2218 },
2219 {
2220 	.phy_id		= PHY_ID_VSC8540,
2221 	.name		= "Microsemi FE VSC8540 SyncE",
2222 	.phy_id_mask	= 0xfffffff0,
2223 	/* PHY_BASIC_FEATURES */
2224 	.soft_reset	= &genphy_soft_reset,
2225 	.config_init	= &vsc85xx_config_init,
2226 	.config_aneg	= &vsc85xx_config_aneg,
2227 	.read_status	= &vsc85xx_read_status,
2228 	.ack_interrupt	= &vsc85xx_ack_interrupt,
2229 	.config_intr	= &vsc85xx_config_intr,
2230 	.suspend	= &genphy_suspend,
2231 	.resume		= &genphy_resume,
2232 	.probe		= &vsc85xx_probe,
2233 	.set_wol	= &vsc85xx_wol_set,
2234 	.get_wol	= &vsc85xx_wol_get,
2235 	.get_tunable	= &vsc85xx_get_tunable,
2236 	.set_tunable	= &vsc85xx_set_tunable,
2237 	.read_page	= &vsc85xx_phy_read_page,
2238 	.write_page	= &vsc85xx_phy_write_page,
2239 	.get_sset_count = &vsc85xx_get_sset_count,
2240 	.get_strings    = &vsc85xx_get_strings,
2241 	.get_stats      = &vsc85xx_get_stats,
2242 },
2243 {
2244 	.phy_id		= PHY_ID_VSC8541,
2245 	.name		= "Microsemi VSC8541 SyncE",
2246 	.phy_id_mask    = 0xfffffff0,
2247 	/* PHY_GBIT_FEATURES */
2248 	.soft_reset	= &genphy_soft_reset,
2249 	.config_init    = &vsc85xx_config_init,
2250 	.config_aneg    = &vsc85xx_config_aneg,
2251 	.read_status	= &vsc85xx_read_status,
2252 	.ack_interrupt  = &vsc85xx_ack_interrupt,
2253 	.config_intr    = &vsc85xx_config_intr,
2254 	.suspend	= &genphy_suspend,
2255 	.resume		= &genphy_resume,
2256 	.probe		= &vsc85xx_probe,
2257 	.set_wol	= &vsc85xx_wol_set,
2258 	.get_wol	= &vsc85xx_wol_get,
2259 	.get_tunable	= &vsc85xx_get_tunable,
2260 	.set_tunable	= &vsc85xx_set_tunable,
2261 	.read_page	= &vsc85xx_phy_read_page,
2262 	.write_page	= &vsc85xx_phy_write_page,
2263 	.get_sset_count = &vsc85xx_get_sset_count,
2264 	.get_strings    = &vsc85xx_get_strings,
2265 	.get_stats      = &vsc85xx_get_stats,
2266 },
2267 {
2268 	.phy_id		= PHY_ID_VSC8552,
2269 	.name		= "Microsemi GE VSC8552 SyncE",
2270 	.phy_id_mask	= 0xfffffff0,
2271 	/* PHY_GBIT_FEATURES */
2272 	.soft_reset	= &genphy_soft_reset,
2273 	.config_init    = &vsc8584_config_init,
2274 	.config_aneg    = &vsc85xx_config_aneg,
2275 	.read_status	= &vsc85xx_read_status,
2276 	.ack_interrupt  = &vsc85xx_ack_interrupt,
2277 	.config_intr    = &vsc85xx_config_intr,
2278 	.did_interrupt  = &vsc8584_did_interrupt,
2279 	.suspend	= &genphy_suspend,
2280 	.resume		= &genphy_resume,
2281 	.probe		= &vsc8574_probe,
2282 	.set_wol	= &vsc85xx_wol_set,
2283 	.get_wol	= &vsc85xx_wol_get,
2284 	.get_tunable	= &vsc85xx_get_tunable,
2285 	.set_tunable	= &vsc85xx_set_tunable,
2286 	.read_page	= &vsc85xx_phy_read_page,
2287 	.write_page	= &vsc85xx_phy_write_page,
2288 	.get_sset_count = &vsc85xx_get_sset_count,
2289 	.get_strings    = &vsc85xx_get_strings,
2290 	.get_stats      = &vsc85xx_get_stats,
2291 },
2292 {
2293 	.phy_id		= PHY_ID_VSC856X,
2294 	.name		= "Microsemi GE VSC856X SyncE",
2295 	.phy_id_mask	= 0xfffffff0,
2296 	/* PHY_GBIT_FEATURES */
2297 	.soft_reset	= &genphy_soft_reset,
2298 	.config_init    = &vsc8584_config_init,
2299 	.config_aneg    = &vsc85xx_config_aneg,
2300 	.read_status	= &vsc85xx_read_status,
2301 	.ack_interrupt  = &vsc85xx_ack_interrupt,
2302 	.config_intr    = &vsc85xx_config_intr,
2303 	.did_interrupt  = &vsc8584_did_interrupt,
2304 	.suspend	= &genphy_suspend,
2305 	.resume		= &genphy_resume,
2306 	.probe		= &vsc8584_probe,
2307 	.get_tunable	= &vsc85xx_get_tunable,
2308 	.set_tunable	= &vsc85xx_set_tunable,
2309 	.read_page	= &vsc85xx_phy_read_page,
2310 	.write_page	= &vsc85xx_phy_write_page,
2311 	.get_sset_count = &vsc85xx_get_sset_count,
2312 	.get_strings    = &vsc85xx_get_strings,
2313 	.get_stats      = &vsc85xx_get_stats,
2314 },
2315 {
2316 	.phy_id		= PHY_ID_VSC8572,
2317 	.name		= "Microsemi GE VSC8572 SyncE",
2318 	.phy_id_mask	= 0xfffffff0,
2319 	/* PHY_GBIT_FEATURES */
2320 	.soft_reset	= &genphy_soft_reset,
2321 	.config_init    = &vsc8584_config_init,
2322 	.config_aneg    = &vsc85xx_config_aneg,
2323 	.aneg_done	= &genphy_aneg_done,
2324 	.read_status	= &vsc85xx_read_status,
2325 	.handle_interrupt = &vsc8584_handle_interrupt,
2326 	.ack_interrupt  = &vsc85xx_ack_interrupt,
2327 	.config_intr    = &vsc85xx_config_intr,
2328 	.did_interrupt  = &vsc8584_did_interrupt,
2329 	.suspend	= &genphy_suspend,
2330 	.resume		= &genphy_resume,
2331 	.probe		= &vsc8574_probe,
2332 	.set_wol	= &vsc85xx_wol_set,
2333 	.get_wol	= &vsc85xx_wol_get,
2334 	.get_tunable	= &vsc85xx_get_tunable,
2335 	.set_tunable	= &vsc85xx_set_tunable,
2336 	.read_page	= &vsc85xx_phy_read_page,
2337 	.write_page	= &vsc85xx_phy_write_page,
2338 	.get_sset_count = &vsc85xx_get_sset_count,
2339 	.get_strings    = &vsc85xx_get_strings,
2340 	.get_stats      = &vsc85xx_get_stats,
2341 },
2342 {
2343 	.phy_id		= PHY_ID_VSC8574,
2344 	.name		= "Microsemi GE VSC8574 SyncE",
2345 	.phy_id_mask	= 0xfffffff0,
2346 	/* PHY_GBIT_FEATURES */
2347 	.soft_reset	= &genphy_soft_reset,
2348 	.config_init    = &vsc8584_config_init,
2349 	.config_aneg    = &vsc85xx_config_aneg,
2350 	.aneg_done	= &genphy_aneg_done,
2351 	.read_status	= &vsc85xx_read_status,
2352 	.ack_interrupt  = &vsc85xx_ack_interrupt,
2353 	.config_intr    = &vsc85xx_config_intr,
2354 	.did_interrupt  = &vsc8584_did_interrupt,
2355 	.suspend	= &genphy_suspend,
2356 	.resume		= &genphy_resume,
2357 	.probe		= &vsc8574_probe,
2358 	.set_wol	= &vsc85xx_wol_set,
2359 	.get_wol	= &vsc85xx_wol_get,
2360 	.get_tunable	= &vsc85xx_get_tunable,
2361 	.set_tunable	= &vsc85xx_set_tunable,
2362 	.read_page	= &vsc85xx_phy_read_page,
2363 	.write_page	= &vsc85xx_phy_write_page,
2364 	.get_sset_count = &vsc85xx_get_sset_count,
2365 	.get_strings    = &vsc85xx_get_strings,
2366 	.get_stats      = &vsc85xx_get_stats,
2367 },
2368 {
2369 	.phy_id		= PHY_ID_VSC8575,
2370 	.name		= "Microsemi GE VSC8575 SyncE",
2371 	.phy_id_mask	= 0xfffffff0,
2372 	/* PHY_GBIT_FEATURES */
2373 	.soft_reset	= &genphy_soft_reset,
2374 	.config_init    = &vsc8584_config_init,
2375 	.config_aneg    = &vsc85xx_config_aneg,
2376 	.aneg_done	= &genphy_aneg_done,
2377 	.read_status	= &vsc85xx_read_status,
2378 	.handle_interrupt = &vsc8584_handle_interrupt,
2379 	.ack_interrupt  = &vsc85xx_ack_interrupt,
2380 	.config_intr    = &vsc85xx_config_intr,
2381 	.did_interrupt  = &vsc8584_did_interrupt,
2382 	.suspend	= &genphy_suspend,
2383 	.resume		= &genphy_resume,
2384 	.probe		= &vsc8584_probe,
2385 	.get_tunable	= &vsc85xx_get_tunable,
2386 	.set_tunable	= &vsc85xx_set_tunable,
2387 	.read_page	= &vsc85xx_phy_read_page,
2388 	.write_page	= &vsc85xx_phy_write_page,
2389 	.get_sset_count = &vsc85xx_get_sset_count,
2390 	.get_strings    = &vsc85xx_get_strings,
2391 	.get_stats      = &vsc85xx_get_stats,
2392 },
2393 {
2394 	.phy_id		= PHY_ID_VSC8582,
2395 	.name		= "Microsemi GE VSC8582 SyncE",
2396 	.phy_id_mask	= 0xfffffff0,
2397 	/* PHY_GBIT_FEATURES */
2398 	.soft_reset	= &genphy_soft_reset,
2399 	.config_init    = &vsc8584_config_init,
2400 	.config_aneg    = &vsc85xx_config_aneg,
2401 	.aneg_done	= &genphy_aneg_done,
2402 	.read_status	= &vsc85xx_read_status,
2403 	.handle_interrupt = &vsc8584_handle_interrupt,
2404 	.ack_interrupt  = &vsc85xx_ack_interrupt,
2405 	.config_intr    = &vsc85xx_config_intr,
2406 	.did_interrupt  = &vsc8584_did_interrupt,
2407 	.suspend	= &genphy_suspend,
2408 	.resume		= &genphy_resume,
2409 	.probe		= &vsc8584_probe,
2410 	.get_tunable	= &vsc85xx_get_tunable,
2411 	.set_tunable	= &vsc85xx_set_tunable,
2412 	.read_page	= &vsc85xx_phy_read_page,
2413 	.write_page	= &vsc85xx_phy_write_page,
2414 	.get_sset_count = &vsc85xx_get_sset_count,
2415 	.get_strings    = &vsc85xx_get_strings,
2416 	.get_stats      = &vsc85xx_get_stats,
2417 },
2418 {
2419 	.phy_id		= PHY_ID_VSC8584,
2420 	.name		= "Microsemi GE VSC8584 SyncE",
2421 	.phy_id_mask	= 0xfffffff0,
2422 	/* PHY_GBIT_FEATURES */
2423 	.soft_reset	= &genphy_soft_reset,
2424 	.config_init    = &vsc8584_config_init,
2425 	.config_aneg    = &vsc85xx_config_aneg,
2426 	.aneg_done	= &genphy_aneg_done,
2427 	.read_status	= &vsc85xx_read_status,
2428 	.handle_interrupt = &vsc8584_handle_interrupt,
2429 	.ack_interrupt  = &vsc85xx_ack_interrupt,
2430 	.config_intr    = &vsc85xx_config_intr,
2431 	.did_interrupt  = &vsc8584_did_interrupt,
2432 	.suspend	= &genphy_suspend,
2433 	.resume		= &genphy_resume,
2434 	.probe		= &vsc8584_probe,
2435 	.get_tunable	= &vsc85xx_get_tunable,
2436 	.set_tunable	= &vsc85xx_set_tunable,
2437 	.read_page	= &vsc85xx_phy_read_page,
2438 	.write_page	= &vsc85xx_phy_write_page,
2439 	.get_sset_count = &vsc85xx_get_sset_count,
2440 	.get_strings    = &vsc85xx_get_strings,
2441 	.get_stats      = &vsc85xx_get_stats,
2442 }
2443 
2444 };
2445 
2446 module_phy_driver(vsc85xx_driver);
2447 
2448 static struct mdio_device_id __maybe_unused vsc85xx_tbl[] = {
2449 	{ PHY_ID_VSC8504, 0xfffffff0, },
2450 	{ PHY_ID_VSC8514, 0xfffffff0, },
2451 	{ PHY_ID_VSC8530, 0xfffffff0, },
2452 	{ PHY_ID_VSC8531, 0xfffffff0, },
2453 	{ PHY_ID_VSC8540, 0xfffffff0, },
2454 	{ PHY_ID_VSC8541, 0xfffffff0, },
2455 	{ PHY_ID_VSC8552, 0xfffffff0, },
2456 	{ PHY_ID_VSC856X, 0xfffffff0, },
2457 	{ PHY_ID_VSC8572, 0xfffffff0, },
2458 	{ PHY_ID_VSC8574, 0xfffffff0, },
2459 	{ PHY_ID_VSC8575, 0xfffffff0, },
2460 	{ PHY_ID_VSC8582, 0xfffffff0, },
2461 	{ PHY_ID_VSC8584, 0xfffffff0, },
2462 	{ }
2463 };
2464 
2465 MODULE_DEVICE_TABLE(mdio, vsc85xx_tbl);
2466 
2467 MODULE_DESCRIPTION("Microsemi VSC85xx PHY driver");
2468 MODULE_AUTHOR("Nagaraju Lakkaraju");
2469 MODULE_LICENSE("Dual MIT/GPL");
2470