1 // SPDX-License-Identifier: (GPL-2.0 OR MIT)
3 * Driver for Microsemi VSC85xx PHYs
5 * Author: Nagaraju Lakkaraju
6 * License: Dual MIT/GPL
7 * Copyright (c) 2016 Microsemi Corporation
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>
18 #include <linux/netdevice.h>
19 #include <dt-bindings/net/mscc-phy-vsc8531.h>
23 static const struct vsc85xx_hw_stat vsc85xx_hw_stats[] = {
25 .string = "phy_receive_errors",
26 .reg = MSCC_PHY_ERR_RX_CNT,
27 .page = MSCC_PHY_PAGE_STANDARD,
30 .string = "phy_false_carrier",
31 .reg = MSCC_PHY_ERR_FALSE_CARRIER_CNT,
32 .page = MSCC_PHY_PAGE_STANDARD,
35 .string = "phy_cu_media_link_disconnect",
36 .reg = MSCC_PHY_ERR_LINK_DISCONNECT_CNT,
37 .page = MSCC_PHY_PAGE_STANDARD,
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,
45 .string = "phy_cu_media_crc_error_count",
46 .reg = MSCC_PHY_EXT_PHY_CNTL_4,
47 .page = MSCC_PHY_PAGE_EXTENDED,
52 static const struct vsc85xx_hw_stat vsc8584_hw_stats[] = {
54 .string = "phy_receive_errors",
55 .reg = MSCC_PHY_ERR_RX_CNT,
56 .page = MSCC_PHY_PAGE_STANDARD,
59 .string = "phy_false_carrier",
60 .reg = MSCC_PHY_ERR_FALSE_CARRIER_CNT,
61 .page = MSCC_PHY_PAGE_STANDARD,
64 .string = "phy_cu_media_link_disconnect",
65 .reg = MSCC_PHY_ERR_LINK_DISCONNECT_CNT,
66 .page = MSCC_PHY_PAGE_STANDARD,
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,
74 .string = "phy_cu_media_crc_error_count",
75 .reg = MSCC_PHY_EXT_PHY_CNTL_4,
76 .page = MSCC_PHY_PAGE_EXTENDED,
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,
84 .string = "phy_serdes_tx_bad_crc_count",
85 .reg = MSCC_PHY_SERDES_TX_CRC_ERR_CNT,
86 .page = MSCC_PHY_PAGE_EXTENDED_3,
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,
94 .string = "phy_serdes_rx_bad_crc_count",
95 .reg = MSCC_PHY_SERDES_RX_CRC_ERR_CNT,
96 .page = MSCC_PHY_PAGE_EXTENDED_3,
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} },
110 static int vsc85xx_phy_read_page(struct phy_device *phydev)
112 return __phy_read(phydev, MSCC_EXT_PAGE_ACCESS);
115 static int vsc85xx_phy_write_page(struct phy_device *phydev, int page)
117 return __phy_write(phydev, MSCC_EXT_PAGE_ACCESS, page);
120 static int vsc85xx_get_sset_count(struct phy_device *phydev)
122 struct vsc8531_private *priv = phydev->priv;
130 static void vsc85xx_get_strings(struct phy_device *phydev, u8 *data)
132 struct vsc8531_private *priv = phydev->priv;
138 for (i = 0; i < priv->nstats; i++)
139 strlcpy(data + i * ETH_GSTRING_LEN, priv->hw_stats[i].string,
143 static u64 vsc85xx_get_stat(struct phy_device *phydev, int i)
145 struct vsc8531_private *priv = phydev->priv;
148 val = phy_read_paged(phydev, priv->hw_stats[i].page,
149 priv->hw_stats[i].reg);
153 val = val & priv->hw_stats[i].mask;
154 priv->stats[i] += val;
156 return priv->stats[i];
159 static void vsc85xx_get_stats(struct phy_device *phydev,
160 struct ethtool_stats *stats, u64 *data)
162 struct vsc8531_private *priv = phydev->priv;
168 for (i = 0; i < priv->nstats; i++)
169 data[i] = vsc85xx_get_stat(phydev, i);
172 static int vsc85xx_led_cntl_set(struct phy_device *phydev,
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);
189 static int vsc85xx_mdix_get(struct phy_device *phydev, u8 *mdix)
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;
202 static int vsc85xx_mdix_set(struct phy_device *phydev, u8 mdix)
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);
213 reg_val &= ~(DISABLE_PAIR_SWAP_CORR_MASK |
214 DISABLE_POLARITY_CORR_MASK |
215 DISABLE_HP_AUTO_MDIX_MASK);
217 rc = phy_write(phydev, MSCC_PHY_BYPASS_CONTROL, reg_val);
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;
228 rc = phy_modify_paged(phydev, MSCC_PHY_PAGE_EXTENDED,
229 MSCC_PHY_EXT_MODE_CNTL, FORCE_MDI_CROSSOVER_MASK,
234 return genphy_restart_aneg(phydev);
237 static int vsc85xx_downshift_get(struct phy_device *phydev, u8 *count)
241 reg_val = phy_read_paged(phydev, MSCC_PHY_PAGE_EXTENDED,
242 MSCC_PHY_ACTIPHY_CNTL);
246 reg_val &= DOWNSHIFT_CNTL_MASK;
247 if (!(reg_val & DOWNSHIFT_EN))
248 *count = DOWNSHIFT_DEV_DISABLE;
250 *count = ((reg_val & ~DOWNSHIFT_EN) >> DOWNSHIFT_CNTL_POS) + 2;
255 static int vsc85xx_downshift_set(struct phy_device *phydev, u8 count)
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");
264 /* Downshift count is either 2,3,4 or 5 */
265 count = (((count - 2) << DOWNSHIFT_CNTL_POS) | DOWNSHIFT_EN);
268 return phy_modify_paged(phydev, MSCC_PHY_PAGE_EXTENDED,
269 MSCC_PHY_ACTIPHY_CNTL, DOWNSHIFT_CNTL_MASK,
273 static int vsc85xx_wol_set(struct phy_device *phydev,
274 struct ethtool_wolinfo *wol)
279 u16 pwd[3] = {0, 0, 0};
280 struct ethtool_wolinfo *wol_conf = wol;
281 u8 *mac_addr = phydev->attached_dev->dev_addr;
283 mutex_lock(&phydev->lock);
284 rc = phy_select_page(phydev, MSCC_PHY_PAGE_EXTENDED_2);
286 rc = phy_restore_page(phydev, rc, rc);
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 |
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]);
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);
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]);
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);
317 reg_val = __phy_read(phydev, MSCC_PHY_WOL_MAC_CONTROL);
318 if (wol_conf->wolopts & WAKE_MAGICSECURE)
319 reg_val |= SECURE_ON_ENABLE;
321 reg_val &= ~SECURE_ON_ENABLE;
322 __phy_write(phydev, MSCC_PHY_WOL_MAC_CONTROL, reg_val);
324 rc = phy_restore_page(phydev, rc, rc > 0 ? 0 : rc);
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);
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);
343 /* Clear WOL iterrupt status */
344 reg_val = phy_read(phydev, MII_VSC85XX_INT_STATUS);
347 mutex_unlock(&phydev->lock);
352 static void vsc85xx_wol_get(struct phy_device *phydev,
353 struct ethtool_wolinfo *wol)
358 u16 pwd[3] = {0, 0, 0};
359 struct ethtool_wolinfo *wol_conf = wol;
361 mutex_lock(&phydev->lock);
362 rc = phy_select_page(phydev, MSCC_PHY_PAGE_EXTENDED_2);
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)
381 phy_restore_page(phydev, rc, rc > 0 ? 0 : rc);
382 mutex_unlock(&phydev->lock);
385 #ifdef CONFIG_OF_MDIO
386 static int vsc85xx_edge_rate_magic_get(struct phy_device *phydev)
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);
397 if (of_property_read_u32(of_node, "vsc8531,vddmac", &vdd))
398 vdd = MSCC_VDDMAC_3300;
400 if (of_property_read_u32(of_node, "vsc8531,edge-slowdown", &sd))
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);
412 static int vsc85xx_dt_led_mode_get(struct phy_device *phydev,
416 struct vsc8531_private *priv = phydev->priv;
417 struct device *dev = &phydev->mdio.dev;
418 struct device_node *of_node = dev->of_node;
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);
436 static int vsc85xx_edge_rate_magic_get(struct phy_device *phydev)
441 static int vsc85xx_dt_led_mode_get(struct phy_device *phydev,
447 #endif /* CONFIG_OF_MDIO */
449 static int vsc85xx_dt_led_modes_get(struct phy_device *phydev,
452 struct vsc8531_private *priv = phydev->priv;
453 char led_dt_prop[28];
456 for (i = 0; i < priv->nleds; i++) {
457 ret = sprintf(led_dt_prop, "vsc8531,led-%d-mode", i);
461 ret = vsc85xx_dt_led_mode_get(phydev, led_dt_prop,
465 priv->leds_mode[i] = ret;
471 static int vsc85xx_edge_rate_cntl_set(struct phy_device *phydev, u8 edge_rate)
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);
484 static int vsc85xx_mac_if_set(struct phy_device *phydev,
485 phy_interface_t interface)
490 mutex_lock(&phydev->lock);
491 reg_val = phy_read(phydev, MSCC_PHY_EXT_PHY_CNTL_1);
492 reg_val &= ~(MAC_IF_SELECTION_MASK);
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);
500 case PHY_INTERFACE_MODE_RMII:
501 reg_val |= (MAC_IF_SELECTION_RMII << MAC_IF_SELECTION_POS);
503 case PHY_INTERFACE_MODE_MII:
504 case PHY_INTERFACE_MODE_GMII:
505 reg_val |= (MAC_IF_SELECTION_GMII << MAC_IF_SELECTION_POS);
511 rc = phy_write(phydev, MSCC_PHY_EXT_PHY_CNTL_1, reg_val);
515 rc = genphy_soft_reset(phydev);
518 mutex_unlock(&phydev->lock);
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
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
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)
534 u16 rgmii_rx_delay_pos = ffs(rgmii_rx_delay_mask) - 1;
535 u16 rgmii_tx_delay_pos = ffs(rgmii_tx_delay_mask) - 1;
539 mutex_lock(&phydev->lock);
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;
548 rc = phy_modify_paged(phydev, MSCC_PHY_PAGE_EXTENDED_2,
550 rgmii_rx_delay_mask | rgmii_tx_delay_mask,
553 mutex_unlock(&phydev->lock);
558 static int vsc85xx_default_config(struct phy_device *phydev)
562 phydev->mdix_ctrl = ETH_TP_MDI_AUTO;
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);
575 static int vsc85xx_get_tunable(struct phy_device *phydev,
576 struct ethtool_tunable *tuna, void *data)
579 case ETHTOOL_PHY_DOWNSHIFT:
580 return vsc85xx_downshift_get(phydev, (u8 *)data);
586 static int vsc85xx_set_tunable(struct phy_device *phydev,
587 struct ethtool_tunable *tuna,
591 case ETHTOOL_PHY_DOWNSHIFT:
592 return vsc85xx_downshift_set(phydev, *(u8 *)data);
598 /* mdiobus lock should be locked when using this function */
599 static void vsc85xx_tr_write(struct phy_device *phydev, u16 addr, u32 val)
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));
606 static int vsc8531_pre_init_seq_set(struct phy_device *phydev)
609 static const struct reg_val init_seq[] = {
610 {0x0f90, 0x00688980},
611 {0x0696, 0x00000003},
612 {0x07fa, 0x0050100f},
613 {0x1686, 0x00000004},
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);
623 rc = phy_modify_paged(phydev, MSCC_PHY_PAGE_TEST,
624 MSCC_PHY_TEST_PAGE_24, 0, 0x0400);
627 rc = phy_modify_paged(phydev, MSCC_PHY_PAGE_TEST,
628 MSCC_PHY_TEST_PAGE_5, 0x0a00, 0x0e00);
631 rc = phy_modify_paged(phydev, MSCC_PHY_PAGE_TEST,
632 MSCC_PHY_TEST_PAGE_8, 0x8000, 0x8000);
636 mutex_lock(&phydev->lock);
637 oldpage = phy_select_page(phydev, MSCC_PHY_PAGE_TR);
641 for (i = 0; i < ARRAY_SIZE(init_seq); i++)
642 vsc85xx_tr_write(phydev, init_seq[i].reg, init_seq[i].val);
645 oldpage = phy_restore_page(phydev, oldpage, oldpage);
646 mutex_unlock(&phydev->lock);
651 static int vsc85xx_eee_init_seq_set(struct phy_device *phydev)
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},
676 mutex_lock(&phydev->lock);
677 oldpage = phy_select_page(phydev, MSCC_PHY_PAGE_TR);
681 for (i = 0; i < ARRAY_SIZE(init_eee); i++)
682 vsc85xx_tr_write(phydev, init_eee[i].reg, init_eee[i].val);
685 oldpage = phy_restore_page(phydev, oldpage, oldpage);
686 mutex_unlock(&phydev->lock);
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)
694 struct vsc8531_private *priv = phydev->priv;
696 if (unlikely(!mutex_is_locked(&phydev->mdio.bus->mdio_lock))) {
697 dev_err(&phydev->mdio.dev, "MDIO bus lock not held!\n");
701 return __mdiobus_write(phydev->mdio.bus, priv->base_addr, regnum, val);
704 /* phydev->bus->mdio_lock should be locked when using this function */
705 static int phy_base_read(struct phy_device *phydev, u32 regnum)
707 struct vsc8531_private *priv = phydev->priv;
709 if (unlikely(!mutex_is_locked(&phydev->mdio.bus->mdio_lock))) {
710 dev_err(&phydev->mdio.dev, "MDIO bus lock not held!\n");
714 return __mdiobus_read(phydev->mdio.bus, priv->base_addr, regnum);
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)
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));
725 /* bus->mdio_lock should be locked when using this function */
726 static int vsc8584_cmd(struct phy_device *phydev, u16 val)
728 unsigned long deadline;
731 phy_base_write(phydev, MSCC_EXT_PAGE_ACCESS,
732 MSCC_PHY_PAGE_EXTENDED_GPIO);
734 phy_base_write(phydev, MSCC_PHY_PROC_CMD, PROC_CMD_NCOMPLETED | val);
736 deadline = jiffies + msecs_to_jiffies(PROC_CMD_NCOMPLETED_TIMEOUT_MS);
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));
743 phy_base_write(phydev, MSCC_EXT_PAGE_ACCESS, MSCC_PHY_PAGE_STANDARD);
745 if (reg_val & PROC_CMD_FAILED)
748 if (reg_val & PROC_CMD_NCOMPLETED)
754 /* bus->mdio_lock should be locked when using this function */
755 static int vsc8584_micro_deassert_reset(struct phy_device *phydev,
760 phy_base_write(phydev, MSCC_EXT_PAGE_ACCESS,
761 MSCC_PHY_PAGE_EXTENDED_GPIO);
763 enable = RUN_FROM_INT_ROM | MICRO_CLK_EN | DW8051_CLK_EN;
764 release = MICRO_NSOFT_RESET | RUN_FROM_INT_ROM | DW8051_CLK_EN |
768 enable |= MICRO_PATCH_EN;
769 release |= MICRO_PATCH_EN;
771 /* Clear all patches */
772 phy_base_write(phydev, MSCC_INT_MEM_CNTL, READ_RAM);
775 /* Enable 8051 Micro clock; CLEAR/SET patch present; disable PRAM clock
776 * override and addr. auto-incr; operate at 125 MHz
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);
782 phy_base_write(phydev, MSCC_EXT_PAGE_ACCESS, MSCC_PHY_PAGE_STANDARD);
787 /* bus->mdio_lock should be locked when using this function */
788 static int vsc8584_micro_assert_reset(struct phy_device *phydev)
793 ret = vsc8584_cmd(phydev, PROC_CMD_NOP);
797 phy_base_write(phydev, MSCC_EXT_PAGE_ACCESS,
798 MSCC_PHY_PAGE_EXTENDED_GPIO);
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);
804 phy_base_write(phydev, MSCC_TRAP_ROM_ADDR(4), 0x005b);
805 phy_base_write(phydev, MSCC_PATCH_RAM_ADDR(4), 0x005b);
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);
811 phy_base_write(phydev, MSCC_PHY_PROC_CMD, PROC_CMD_NOP);
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);
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 |
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);
825 phy_base_write(phydev, MSCC_EXT_PAGE_ACCESS, MSCC_PHY_PAGE_STANDARD);
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,
836 phy_base_write(phydev, MSCC_EXT_PAGE_ACCESS, MSCC_PHY_PAGE_EXTENDED);
838 phy_base_write(phydev, MSCC_PHY_VERIPHY_CNTL_2, start);
839 phy_base_write(phydev, MSCC_PHY_VERIPHY_CNTL_3, size);
841 /* Start Micro command */
842 ret = vsc8584_cmd(phydev, PROC_CMD_CRC16);
846 phy_base_write(phydev, MSCC_EXT_PAGE_ACCESS, MSCC_PHY_PAGE_EXTENDED);
848 *crc = phy_base_read(phydev, MSCC_PHY_VERIPHY_CNTL_2);
851 phy_base_write(phydev, MSCC_EXT_PAGE_ACCESS, MSCC_PHY_PAGE_STANDARD);
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)
862 ret = vsc8584_micro_assert_reset(phydev);
864 dev_err(&phydev->mdio.dev,
865 "%s: failed to assert reset of micro\n", __func__);
869 phy_base_write(phydev, MSCC_EXT_PAGE_ACCESS,
870 MSCC_PHY_PAGE_EXTENDED_GPIO);
872 /* Hold 8051 Micro in SW Reset, Enable auto incr address and patch clock
873 * Disable the 8051 Micro clock
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 |
880 phy_base_write(phydev, MSCC_INT_MEM_ADDR, 0x0000);
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]);
886 /* Clear internal memory access */
887 phy_base_write(phydev, MSCC_INT_MEM_CNTL, READ_RAM);
889 phy_base_write(phydev, MSCC_EXT_PAGE_ACCESS, MSCC_PHY_PAGE_STANDARD);
894 /* bus->mdio_lock should be locked when using this function */
895 static bool vsc8574_is_serdes_init(struct phy_device *phydev)
900 phy_base_write(phydev, MSCC_EXT_PAGE_ACCESS,
901 MSCC_PHY_PAGE_EXTENDED_GPIO);
903 reg = phy_base_read(phydev, MSCC_TRAP_ROM_ADDR(1));
909 reg = phy_base_read(phydev, MSCC_PATCH_RAM_ADDR(1));
915 reg = phy_base_read(phydev, MSCC_INT_MEM_CNTL);
916 if (reg != EN_PATCH_RAM_TRAP_ADDR(1)) {
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)) {
930 phy_base_write(phydev, MSCC_EXT_PAGE_ACCESS, MSCC_PHY_PAGE_STANDARD);
935 /* bus->mdio_lock should be locked when using this function */
936 static int vsc8574_config_pre_init(struct phy_device *phydev)
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},
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},
1002 struct device *dev = &phydev->mdio.dev;
1003 const struct firmware *fw;
1009 phy_base_write(phydev, MSCC_EXT_PAGE_ACCESS, MSCC_PHY_PAGE_STANDARD);
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);
1016 phy_base_write(phydev, MII_VSC85XX_INT_MASK, 0);
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
1023 phy_base_write(phydev, MSCC_PHY_EXT_PHY_CNTL_2, 0x0040);
1025 phy_base_write(phydev, MSCC_EXT_PAGE_ACCESS, MSCC_PHY_PAGE_TEST);
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);
1032 reg = phy_base_read(phydev, MSCC_PHY_TEST_PAGE_8);
1034 phy_base_write(phydev, MSCC_PHY_TEST_PAGE_8, reg);
1036 phy_base_write(phydev, MSCC_EXT_PAGE_ACCESS, MSCC_PHY_PAGE_TR);
1038 for (i = 0; i < ARRAY_SIZE(pre_init1); i++)
1039 vsc8584_csr_write(phydev, pre_init1[i].reg, pre_init1[i].val);
1041 phy_base_write(phydev, MSCC_EXT_PAGE_ACCESS, MSCC_PHY_PAGE_EXTENDED_2);
1043 phy_base_write(phydev, MSCC_PHY_CU_PMD_TX_CNTL, 0x028e);
1045 phy_base_write(phydev, MSCC_EXT_PAGE_ACCESS, MSCC_PHY_PAGE_TR);
1047 for (i = 0; i < ARRAY_SIZE(pre_init2); i++)
1048 vsc8584_csr_write(phydev, pre_init2[i].reg, pre_init2[i].val);
1050 phy_base_write(phydev, MSCC_EXT_PAGE_ACCESS, MSCC_PHY_PAGE_TEST);
1052 reg = phy_base_read(phydev, MSCC_PHY_TEST_PAGE_8);
1054 phy_base_write(phydev, MSCC_PHY_TEST_PAGE_8, reg);
1056 phy_base_write(phydev, MSCC_EXT_PAGE_ACCESS, MSCC_PHY_PAGE_STANDARD);
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);
1063 ret = request_firmware(&fw, MSCC_VSC8574_REVB_INT8051_FW, dev);
1065 dev_err(dev, "failed to load firmware %s, ret: %d\n",
1066 MSCC_VSC8574_REVB_INT8051_FW, ret);
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);
1077 if (crc == MSCC_VSC8574_REVB_INT8051_FW_CRC) {
1078 serdes_init = vsc8574_is_serdes_init(phydev);
1081 ret = vsc8584_micro_assert_reset(phydev);
1084 "%s: failed to assert reset of micro\n",
1090 dev_dbg(dev, "FW CRC is not the expected one, patching FW\n");
1092 serdes_init = false;
1094 if (vsc8584_patch_fw(phydev, fw))
1096 "failed to patch FW, expect non-optimal device\n");
1100 phy_base_write(phydev, MSCC_EXT_PAGE_ACCESS,
1101 MSCC_PHY_PAGE_EXTENDED_GPIO);
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));
1108 vsc8584_micro_deassert_reset(phydev, false);
1110 /* Add one byte to size for the one added by the patch_fw
1113 ret = vsc8584_get_fw_crc(phydev,
1114 MSCC_VSC8574_REVB_INT8051_FW_START_ADDR,
1115 fw->size + 1, &crc);
1119 if (crc != MSCC_VSC8574_REVB_INT8051_FW_CRC)
1121 "FW CRC after patching is not the expected one, expect non-optimal device\n");
1124 phy_base_write(phydev, MSCC_EXT_PAGE_ACCESS,
1125 MSCC_PHY_PAGE_EXTENDED_GPIO);
1127 ret = vsc8584_cmd(phydev, PROC_CMD_1588_DEFAULT_INIT |
1131 phy_base_write(phydev, MSCC_EXT_PAGE_ACCESS, MSCC_PHY_PAGE_STANDARD);
1133 release_firmware(fw);
1138 /* bus->mdio_lock should be locked when using this function */
1139 static int vsc8584_config_pre_init(struct phy_device *phydev)
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},
1165 static const struct reg_val pre_init2[] = {
1166 {0x0486, 0x0008a518},
1167 {0x0488, 0x006dc696},
1168 {0x048a, 0x00000912},
1170 const struct firmware *fw;
1171 struct device *dev = &phydev->mdio.dev;
1176 phy_base_write(phydev, MSCC_EXT_PAGE_ACCESS, MSCC_PHY_PAGE_STANDARD);
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);
1183 phy_base_write(phydev, MII_VSC85XX_INT_MASK, 0);
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);
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
1194 phy_base_write(phydev, MSCC_EXT_PAGE_ACCESS, MSCC_PHY_PAGE_EXTENDED_3);
1196 phy_base_write(phydev, MSCC_PHY_SERDES_TX_CRC_ERR_CNT, 0x2000);
1198 phy_base_write(phydev, MSCC_EXT_PAGE_ACCESS, MSCC_PHY_PAGE_TEST);
1200 phy_base_write(phydev, MSCC_PHY_TEST_PAGE_5, 0x1f20);
1202 reg = phy_base_read(phydev, MSCC_PHY_TEST_PAGE_8);
1204 phy_base_write(phydev, MSCC_PHY_TEST_PAGE_8, reg);
1206 phy_base_write(phydev, MSCC_EXT_PAGE_ACCESS, MSCC_PHY_PAGE_TR);
1208 phy_base_write(phydev, MSCC_PHY_TR_CNTL, TR_WRITE | TR_ADDR(0x2fa4));
1210 reg = phy_base_read(phydev, MSCC_PHY_TR_MSB);
1213 phy_base_write(phydev, MSCC_PHY_TR_MSB, reg);
1215 phy_base_write(phydev, MSCC_PHY_TR_CNTL, TR_WRITE | TR_ADDR(0x0fa4));
1217 for (i = 0; i < ARRAY_SIZE(pre_init1); i++)
1218 vsc8584_csr_write(phydev, pre_init1[i].reg, pre_init1[i].val);
1220 phy_base_write(phydev, MSCC_EXT_PAGE_ACCESS, MSCC_PHY_PAGE_EXTENDED_2);
1222 phy_base_write(phydev, MSCC_PHY_CU_PMD_TX_CNTL, 0x028e);
1224 phy_base_write(phydev, MSCC_EXT_PAGE_ACCESS, MSCC_PHY_PAGE_TR);
1226 for (i = 0; i < ARRAY_SIZE(pre_init2); i++)
1227 vsc8584_csr_write(phydev, pre_init2[i].reg, pre_init2[i].val);
1229 phy_base_write(phydev, MSCC_EXT_PAGE_ACCESS, MSCC_PHY_PAGE_TEST);
1231 reg = phy_base_read(phydev, MSCC_PHY_TEST_PAGE_8);
1233 phy_base_write(phydev, MSCC_PHY_TEST_PAGE_8, reg);
1235 phy_base_write(phydev, MSCC_EXT_PAGE_ACCESS, MSCC_PHY_PAGE_STANDARD);
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);
1242 ret = request_firmware(&fw, MSCC_VSC8584_REVB_INT8051_FW, dev);
1244 dev_err(dev, "failed to load firmware %s, ret: %d\n",
1245 MSCC_VSC8584_REVB_INT8051_FW, ret);
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);
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))
1260 "failed to patch FW, expect non-optimal device\n");
1263 vsc8584_micro_deassert_reset(phydev, false);
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);
1272 if (crc != MSCC_VSC8584_REVB_INT8051_FW_CRC)
1274 "FW CRC after patching is not the expected one, expect non-optimal device\n");
1276 ret = vsc8584_micro_assert_reset(phydev);
1280 vsc8584_micro_deassert_reset(phydev, true);
1283 phy_base_write(phydev, MSCC_EXT_PAGE_ACCESS, MSCC_PHY_PAGE_STANDARD);
1285 release_firmware(fw);
1290 /* Check if one PHY has already done the init of the parts common to all PHYs
1291 * in the Quad PHY package.
1293 static bool vsc8584_is_pkg_init(struct phy_device *phydev, bool reversed)
1295 struct mdio_device **map = phydev->mdio.bus->mdio_map;
1296 struct vsc8531_private *vsc8531;
1297 struct phy_device *phy;
1300 /* VSC8584 is a Quad PHY */
1301 for (i = 0; i < 4; i++) {
1302 vsc8531 = phydev->priv;
1305 addr = vsc8531->base_addr - i;
1307 addr = vsc8531->base_addr + i;
1312 phy = container_of(map[addr], struct phy_device, mdio);
1314 if ((phy->phy_id & phydev->drv->phy_id_mask) !=
1315 (phydev->drv->phy_id & phydev->drv->phy_id_mask))
1318 vsc8531 = phy->priv;
1320 if (vsc8531 && vsc8531->pkg_init)
1327 static int vsc8584_config_init(struct phy_device *phydev)
1329 struct vsc8531_private *vsc8531 = phydev->priv;
1333 phydev->mdix_ctrl = ETH_TP_MDI_AUTO;
1335 mutex_lock(&phydev->mdio.bus->mdio_lock);
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;
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;
1348 vsc8531->base_addr = phydev->mdio.addr - addr;
1350 vsc8531->addr = addr;
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.
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.
1370 WARN_ON(phydev->drv->phy_id_mask & 0xf);
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);
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);
1394 vsc8531->pkg_init = true;
1396 phy_base_write(phydev, MSCC_EXT_PAGE_ACCESS,
1397 MSCC_PHY_PAGE_EXTENDED_GPIO);
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;
1412 ret = phy_base_write(phydev, MSCC_PHY_MAC_CFG_FASTLINK, val);
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;
1422 val |= PROC_CMD_SGMII_MAC;
1424 ret = vsc8584_cmd(phydev, val);
1428 usleep_range(10000, 20000);
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);
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);
1447 mutex_unlock(&phydev->mdio.bus->mdio_lock);
1449 ret = vsc8584_macsec_init(phydev);
1453 phy_write(phydev, MSCC_EXT_PAGE_ACCESS, MSCC_PHY_PAGE_STANDARD);
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);
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);
1471 ret = genphy_soft_reset(phydev);
1475 for (i = 0; i < vsc8531->nleds; i++) {
1476 ret = vsc85xx_led_cntl_set(phydev, i, vsc8531->leds_mode[i]);
1484 mutex_unlock(&phydev->mdio.bus->mdio_lock);
1488 static irqreturn_t vsc8584_handle_interrupt(struct phy_device *phydev)
1492 irq_status = phy_read(phydev, MII_VSC85XX_INT_STATUS);
1493 if (irq_status < 0 || !(irq_status & MII_VSC85XX_INT_MASK_MASK))
1496 if (irq_status & MII_VSC85XX_INT_MASK_EXT)
1497 vsc8584_handle_macsec_interrupt(phydev);
1499 if (irq_status & MII_VSC85XX_INT_MASK_LINK_CHG)
1500 phy_mac_interrupt(phydev);
1505 static int vsc85xx_config_init(struct phy_device *phydev)
1508 struct vsc8531_private *vsc8531 = phydev->priv;
1510 rc = vsc85xx_default_config(phydev);
1514 rc = vsc85xx_mac_if_set(phydev, phydev->interface);
1518 rc = vsc85xx_edge_rate_cntl_set(phydev, vsc8531->rate_magic);
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);
1530 rc = vsc85xx_eee_init_seq_set(phydev);
1534 for (i = 0; i < vsc8531->nleds; i++) {
1535 rc = vsc85xx_led_cntl_set(phydev, i, vsc8531->leds_mode[i]);
1543 static int vsc8584_did_interrupt(struct phy_device *phydev)
1547 if (phydev->interrupts == PHY_INTERRUPT_ENABLED)
1548 rc = phy_read(phydev, MII_VSC85XX_INT_STATUS);
1550 return (rc < 0) ? 0 : rc & MII_VSC85XX_INT_MASK_MASK;
1553 static int vsc8514_config_pre_init(struct phy_device *phydev)
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.
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},
1584 phy_base_write(phydev, MSCC_EXT_PAGE_ACCESS, MSCC_PHY_PAGE_STANDARD);
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);
1591 phy_base_write(phydev, MSCC_EXT_PAGE_ACCESS, MSCC_PHY_PAGE_TEST);
1593 reg = phy_base_read(phydev, MSCC_PHY_TEST_PAGE_8);
1595 phy_base_write(phydev, MSCC_PHY_TEST_PAGE_8, reg);
1597 phy_base_write(phydev, MSCC_EXT_PAGE_ACCESS, MSCC_PHY_PAGE_TR);
1599 for (i = 0; i < ARRAY_SIZE(pre_init1); i++)
1600 vsc8584_csr_write(phydev, pre_init1[i].reg, pre_init1[i].val);
1602 phy_base_write(phydev, MSCC_EXT_PAGE_ACCESS, MSCC_PHY_PAGE_TEST);
1604 reg = phy_base_read(phydev, MSCC_PHY_TEST_PAGE_8);
1606 phy_base_write(phydev, MSCC_PHY_TEST_PAGE_8, reg);
1608 phy_base_write(phydev, MSCC_EXT_PAGE_ACCESS, MSCC_PHY_PAGE_STANDARD);
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);
1617 static u32 vsc85xx_csr_ctrl_phy_read(struct phy_device *phydev,
1618 u32 target, u32 reg)
1620 unsigned long deadline;
1621 u32 val, val_l, val_h;
1623 phy_base_write(phydev, MSCC_EXT_PAGE_ACCESS, MSCC_PHY_PAGE_CSR_CNTL);
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.
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));
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));
1642 /* Wait for register access*/
1643 deadline = jiffies + msecs_to_jiffies(PROC_CMD_NCOMPLETED_TIMEOUT_MS);
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));
1650 if (!(val & MSCC_PHY_CSR_CNTL_19_CMD))
1653 /* Read the Least Significant Word (LSW) (17) */
1654 val_l = phy_base_read(phydev, MSCC_EXT_PAGE_CSR_CNTL_17);
1656 /* Read the Most Significant Word (MSW) (18) */
1657 val_h = phy_base_read(phydev, MSCC_EXT_PAGE_CSR_CNTL_18);
1659 phy_base_write(phydev, MSCC_EXT_PAGE_ACCESS,
1660 MSCC_PHY_PAGE_STANDARD);
1662 return (val_h << 16) | val_l;
1665 static int vsc85xx_csr_ctrl_phy_write(struct phy_device *phydev,
1666 u32 target, u32 reg, u32 val)
1668 unsigned long deadline;
1670 phy_base_write(phydev, MSCC_EXT_PAGE_ACCESS, MSCC_PHY_PAGE_CSR_CNTL);
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.
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));
1683 /* Write the Least Significant Word (LSW) (17) */
1684 phy_base_write(phydev, MSCC_EXT_PAGE_CSR_CNTL_17, (u16)val);
1686 /* Write the Most Significant Word (MSW) (18) */
1687 phy_base_write(phydev, MSCC_EXT_PAGE_CSR_CNTL_18, (u16)(val >> 16));
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));
1695 /* Wait for register access */
1696 deadline = jiffies + msecs_to_jiffies(PROC_CMD_NCOMPLETED_TIMEOUT_MS);
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));
1703 if (!(val & MSCC_PHY_CSR_CNTL_19_CMD))
1706 phy_base_write(phydev, MSCC_EXT_PAGE_ACCESS,
1707 MSCC_PHY_PAGE_STANDARD);
1712 static int __phy_write_mcb_s6g(struct phy_device *phydev, u32 reg, u8 mcb,
1715 unsigned long deadline;
1719 ret = vsc85xx_csr_ctrl_phy_write(phydev, PHY_MCB_TARGET, reg,
1724 deadline = jiffies + msecs_to_jiffies(PROC_CMD_NCOMPLETED_TIMEOUT_MS);
1726 usleep_range(500, 1000);
1727 val = vsc85xx_csr_ctrl_phy_read(phydev, PHY_MCB_TARGET, reg);
1729 if (val == 0xffffffff)
1732 } while (time_before(jiffies, deadline) && (val & op));
1740 /* Trigger a read to the spcified MCB */
1741 static int phy_update_mcb_s6g(struct phy_device *phydev, u32 reg, u8 mcb)
1743 return __phy_write_mcb_s6g(phydev, reg, mcb, PHY_MCB_S6G_READ);
1746 /* Trigger a write to the spcified MCB */
1747 static int phy_commit_mcb_s6g(struct phy_device *phydev, u32 reg, u8 mcb)
1749 return __phy_write_mcb_s6g(phydev, reg, mcb, PHY_MCB_S6G_WRITE);
1752 static int vsc8514_config_init(struct phy_device *phydev)
1754 struct vsc8531_private *vsc8531 = phydev->priv;
1755 unsigned long deadline;
1760 phydev->mdix_ctrl = ETH_TP_MDI_AUTO;
1762 mutex_lock(&phydev->mdio.bus->mdio_lock);
1764 __phy_write(phydev, MSCC_EXT_PAGE_ACCESS, MSCC_PHY_PAGE_EXTENDED);
1766 addr = __phy_read(phydev, MSCC_PHY_EXT_PHY_CNTL_4);
1767 addr >>= PHY_CNTL_4_ADDR_POS;
1769 val = __phy_read(phydev, MSCC_PHY_ACTIPHY_CNTL);
1771 if (val & PHY_ADDR_REVERSED)
1772 vsc8531->base_addr = phydev->mdio.addr + addr;
1774 vsc8531->base_addr = phydev->mdio.addr - addr;
1776 vsc8531->addr = addr;
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.
1789 if (!vsc8584_is_pkg_init(phydev, val & PHY_ADDR_REVERSED ? 1 : 0))
1790 vsc8514_config_pre_init(phydev);
1792 vsc8531->pkg_init = true;
1794 phy_base_write(phydev, MSCC_EXT_PAGE_ACCESS,
1795 MSCC_PHY_PAGE_EXTENDED_GPIO);
1797 val = phy_base_read(phydev, MSCC_PHY_MAC_CFG_FASTLINK);
1799 val &= ~MAC_CFG_MASK;
1800 val |= MAC_CFG_QSGMII;
1801 ret = phy_base_write(phydev, MSCC_PHY_MAC_CFG_FASTLINK, val);
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);
1814 phy_update_mcb_s6g(phydev, PHY_MCB_S6G_CFG, 0);
1816 phy_update_mcb_s6g(phydev, PHY_S6G_LCPLL_CFG, 0);
1818 ret = vsc85xx_csr_ctrl_phy_write(phydev, PHY_MCB_TARGET,
1819 PHY_S6G_PLL5G_CFG0, 0x7036f145);
1823 phy_commit_mcb_s6g(phydev, PHY_S6G_LCPLL_CFG, 0);
1825 ret = vsc85xx_csr_ctrl_phy_write(phydev, PHY_MCB_TARGET,
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));
1834 ret = vsc85xx_csr_ctrl_phy_write(phydev, PHY_MCB_TARGET,
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));
1845 ret = vsc85xx_csr_ctrl_phy_write(phydev, PHY_MCB_TARGET,
1846 PHY_S6G_MISC_CFG, 1);
1851 ret = vsc85xx_csr_ctrl_phy_write(phydev, PHY_MCB_TARGET,
1852 PHY_S6G_GPC_CFG, 768);
1856 phy_commit_mcb_s6g(phydev, PHY_S6G_DFT_CFG2, 0);
1858 deadline = jiffies + msecs_to_jiffies(PROC_CMD_NCOMPLETED_TIMEOUT_MS);
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);
1870 } while (time_before(jiffies, deadline) && (reg & BIT(12)));
1872 if (reg & BIT(12)) {
1873 mutex_unlock(&phydev->mdio.bus->mdio_lock);
1878 ret = vsc85xx_csr_ctrl_phy_write(phydev, PHY_MCB_TARGET,
1879 PHY_S6G_MISC_CFG, 0);
1883 phy_commit_mcb_s6g(phydev, PHY_MCB_S6G_CFG, 0);
1885 deadline = jiffies + msecs_to_jiffies(PROC_CMD_NCOMPLETED_TIMEOUT_MS);
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);
1897 } while (time_before(jiffies, deadline) && !(reg & BIT(8)));
1899 if (!(reg & BIT(8))) {
1900 mutex_unlock(&phydev->mdio.bus->mdio_lock);
1904 mutex_unlock(&phydev->mdio.bus->mdio_lock);
1906 ret = phy_write(phydev, MSCC_EXT_PAGE_ACCESS, MSCC_PHY_PAGE_STANDARD);
1911 ret = phy_modify(phydev, MSCC_PHY_EXT_PHY_CNTL_1, MEDIA_OP_MODE_MASK,
1912 MEDIA_OP_MODE_COPPER << MEDIA_OP_MODE_POS);
1917 ret = genphy_soft_reset(phydev);
1922 for (i = 0; i < vsc8531->nleds; i++) {
1923 ret = vsc85xx_led_cntl_set(phydev, i, vsc8531->leds_mode[i]);
1931 mutex_unlock(&phydev->mdio.bus->mdio_lock);
1935 static int vsc85xx_ack_interrupt(struct phy_device *phydev)
1939 if (phydev->interrupts == PHY_INTERRUPT_ENABLED)
1940 rc = phy_read(phydev, MII_VSC85XX_INT_STATUS);
1942 return (rc < 0) ? rc : 0;
1945 static int vsc85xx_config_intr(struct phy_device *phydev)
1949 if (phydev->interrupts == PHY_INTERRUPT_ENABLED) {
1950 vsc8584_config_macsec_intr(phydev);
1952 rc = phy_write(phydev, MII_VSC85XX_INT_MASK,
1953 MII_VSC85XX_INT_MASK_MASK);
1955 rc = phy_write(phydev, MII_VSC85XX_INT_MASK, 0);
1958 rc = phy_read(phydev, MII_VSC85XX_INT_STATUS);
1964 static int vsc85xx_config_aneg(struct phy_device *phydev)
1968 rc = vsc85xx_mdix_set(phydev, phydev->mdix_ctrl);
1972 return genphy_config_aneg(phydev);
1975 static int vsc85xx_read_status(struct phy_device *phydev)
1979 rc = vsc85xx_mdix_get(phydev, &phydev->mdix);
1983 return genphy_read_status(phydev);
1986 static int vsc8514_probe(struct phy_device *phydev)
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};
1993 vsc8531 = devm_kzalloc(&phydev->mdio.dev, sizeof(*vsc8531), GFP_KERNEL);
1997 phydev->priv = vsc8531;
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)
2008 return vsc85xx_dt_led_modes_get(phydev, default_mode);
2011 static int vsc8574_probe(struct phy_device *phydev)
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};
2018 vsc8531 = devm_kzalloc(&phydev->mdio.dev, sizeof(*vsc8531), GFP_KERNEL);
2022 phydev->priv = vsc8531;
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)
2033 return vsc85xx_dt_led_modes_get(phydev, default_mode);
2036 static int vsc8584_probe(struct phy_device *phydev)
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};
2043 if ((phydev->phy_id & MSCC_DEV_REV_MASK) != VSC8584_REVB) {
2044 dev_err(&phydev->mdio.dev, "Only VSC8584 revB is supported.\n");
2048 vsc8531 = devm_kzalloc(&phydev->mdio.dev, sizeof(*vsc8531), GFP_KERNEL);
2052 phydev->priv = vsc8531;
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)
2063 return vsc85xx_dt_led_modes_get(phydev, default_mode);
2066 static int vsc85xx_probe(struct phy_device *phydev)
2068 struct vsc8531_private *vsc8531;
2070 u32 default_mode[2] = {VSC8531_LINK_1000_ACTIVITY,
2071 VSC8531_LINK_100_ACTIVITY};
2073 rate_magic = vsc85xx_edge_rate_magic_get(phydev);
2077 vsc8531 = devm_kzalloc(&phydev->mdio.dev, sizeof(*vsc8531), GFP_KERNEL);
2081 phydev->priv = vsc8531;
2083 vsc8531->rate_magic = rate_magic;
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)
2093 return vsc85xx_dt_led_modes_get(phydev, default_mode);
2096 /* Microsemi VSC85xx PHYs */
2097 static struct phy_driver vsc85xx_driver[] = {
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,
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,
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,
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,
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,
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,
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,
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,
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,
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,
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,
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,
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,
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,
2446 module_phy_driver(vsc85xx_driver);
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, },
2465 MODULE_DEVICE_TABLE(mdio, vsc85xx_tbl);
2467 MODULE_DESCRIPTION("Microsemi VSC85xx PHY driver");
2468 MODULE_AUTHOR("Nagaraju Lakkaraju");
2469 MODULE_LICENSE("Dual MIT/GPL");