1 // SPDX-License-Identifier: GPL-2.0+
2 /* Copyright (C) 2021 Maxlinear Corporation
3 * Copyright (C) 2020 Intel Corporation
5 * Drivers for Maxlinear Ethernet GPY
9 #include <linux/module.h>
10 #include <linux/bitfield.h>
11 #include <linux/hwmon.h>
12 #include <linux/mutex.h>
13 #include <linux/phy.h>
14 #include <linux/polynomial.h>
15 #include <linux/property.h>
16 #include <linux/netdevice.h>
19 #define PHY_ID_GPYx15B_MASK 0xFFFFFFFC
20 #define PHY_ID_GPY21xB_MASK 0xFFFFFFF9
21 #define PHY_ID_GPY2xx 0x67C9DC00
22 #define PHY_ID_GPY115B 0x67C9DF00
23 #define PHY_ID_GPY115C 0x67C9DF10
24 #define PHY_ID_GPY211B 0x67C9DE08
25 #define PHY_ID_GPY211C 0x67C9DE10
26 #define PHY_ID_GPY212B 0x67C9DE09
27 #define PHY_ID_GPY212C 0x67C9DE20
28 #define PHY_ID_GPY215B 0x67C9DF04
29 #define PHY_ID_GPY215C 0x67C9DF20
30 #define PHY_ID_GPY241B 0x67C9DE40
31 #define PHY_ID_GPY241BM 0x67C9DE80
32 #define PHY_ID_GPY245B 0x67C9DEC0
35 #define PHY_CTL1_MDICD BIT(3)
36 #define PHY_CTL1_MDIAB BIT(2)
37 #define PHY_CTL1_AMDIX BIT(0)
38 #define PHY_MIISTAT 0x18 /* MII state */
39 #define PHY_IMASK 0x19 /* interrupt mask */
40 #define PHY_ISTAT 0x1A /* interrupt status */
41 #define PHY_FWV 0x1E /* firmware version */
43 #define PHY_MIISTAT_SPD_MASK GENMASK(2, 0)
44 #define PHY_MIISTAT_DPX BIT(3)
45 #define PHY_MIISTAT_LS BIT(10)
47 #define PHY_MIISTAT_SPD_10 0
48 #define PHY_MIISTAT_SPD_100 1
49 #define PHY_MIISTAT_SPD_1000 2
50 #define PHY_MIISTAT_SPD_2500 4
52 #define PHY_IMASK_WOL BIT(15) /* Wake-on-LAN */
53 #define PHY_IMASK_ANC BIT(10) /* Auto-Neg complete */
54 #define PHY_IMASK_ADSC BIT(5) /* Link auto-downspeed detect */
55 #define PHY_IMASK_DXMC BIT(2) /* Duplex mode change */
56 #define PHY_IMASK_LSPC BIT(1) /* Link speed change */
57 #define PHY_IMASK_LSTC BIT(0) /* Link state change */
58 #define PHY_IMASK_MASK (PHY_IMASK_LSTC | \
64 #define PHY_FWV_REL_MASK BIT(15)
65 #define PHY_FWV_MAJOR_MASK GENMASK(11, 8)
66 #define PHY_FWV_MINOR_MASK GENMASK(7, 0)
68 #define PHY_PMA_MGBT_POLARITY 0x82
69 #define PHY_MDI_MDI_X_MASK GENMASK(1, 0)
70 #define PHY_MDI_MDI_X_NORMAL 0x3
71 #define PHY_MDI_MDI_X_AB 0x2
72 #define PHY_MDI_MDI_X_CD 0x1
73 #define PHY_MDI_MDI_X_CROSS 0x0
76 #define VSPEC1_SGMII_CTRL 0x08
77 #define VSPEC1_SGMII_CTRL_ANEN BIT(12) /* Aneg enable */
78 #define VSPEC1_SGMII_CTRL_ANRS BIT(9) /* Restart Aneg */
79 #define VSPEC1_SGMII_ANEN_ANRS (VSPEC1_SGMII_CTRL_ANEN | \
80 VSPEC1_SGMII_CTRL_ANRS)
82 /* Temperature sensor */
83 #define VSPEC1_TEMP_STA 0x0E
84 #define VSPEC1_TEMP_STA_DATA GENMASK(9, 0)
87 #define VSPEC1_MBOX_DATA 0x5
88 #define VSPEC1_MBOX_ADDRLO 0x6
89 #define VSPEC1_MBOX_CMD 0x7
90 #define VSPEC1_MBOX_CMD_ADDRHI GENMASK(7, 0)
91 #define VSPEC1_MBOX_CMD_RD (0 << 8)
92 #define VSPEC1_MBOX_CMD_READY BIT(15)
95 #define VPSPEC2_WOL_CTL 0x0E06
96 #define VPSPEC2_WOL_AD01 0x0E08
97 #define VPSPEC2_WOL_AD23 0x0E09
98 #define VPSPEC2_WOL_AD45 0x0E0A
101 /* Internal registers, access via mbox */
102 #define REG_GPIO0_OUT 0xd3ce00
105 /* serialize mailbox acesses */
106 struct mutex mbox_lock;
112 /* It takes 3 seconds to fully switch out of loopback mode before
113 * it can safely re-enter loopback mode. Record the time when
114 * loopback is disabled. Check and wait if necessary before loopback
120 static const struct {
123 } ver_need_sgmii_reaneg[] = {
129 #if IS_ENABLED(CONFIG_HWMON)
130 /* The original translation formulae of the temperature (in degrees of Celsius)
133 * T = -2.5761e-11*(N^4) + 9.7332e-8*(N^3) + -1.9165e-4*(N^2) +
134 * 3.0762e-1*(N^1) + -5.2156e1
136 * where [-52.156, 137.961]C and N = [0, 1023].
138 * They must be accordingly altered to be suitable for the integer arithmetics.
139 * The technique is called 'factor redistribution', which just makes sure the
140 * multiplications and divisions are made so to have a result of the operations
141 * within the integer numbers limit. In addition we need to translate the
142 * formulae to accept millidegrees of Celsius. Here what it looks like after
145 * T = -25761e-12*(N^4) + 97332e-9*(N^3) + -191650e-6*(N^2) +
146 * 307620e-3*(N^1) + -52156
148 * where T = [-52156, 137961]mC and N = [0, 1023].
150 static const struct polynomial poly_N_to_temp = {
152 {4, -25761, 1000, 1},
154 {2, -191650, 1000, 1},
155 {1, 307620, 1000, 1},
160 static int gpy_hwmon_read(struct device *dev,
161 enum hwmon_sensor_types type,
162 u32 attr, int channel, long *value)
164 struct phy_device *phydev = dev_get_drvdata(dev);
167 ret = phy_read_mmd(phydev, MDIO_MMD_VEND1, VSPEC1_TEMP_STA);
173 *value = polynomial_calc(&poly_N_to_temp,
174 FIELD_GET(VSPEC1_TEMP_STA_DATA, ret));
179 static umode_t gpy_hwmon_is_visible(const void *data,
180 enum hwmon_sensor_types type,
181 u32 attr, int channel)
186 static const struct hwmon_channel_info * const gpy_hwmon_info[] = {
187 HWMON_CHANNEL_INFO(temp, HWMON_T_INPUT),
191 static const struct hwmon_ops gpy_hwmon_hwmon_ops = {
192 .is_visible = gpy_hwmon_is_visible,
193 .read = gpy_hwmon_read,
196 static const struct hwmon_chip_info gpy_hwmon_chip_info = {
197 .ops = &gpy_hwmon_hwmon_ops,
198 .info = gpy_hwmon_info,
201 static int gpy_hwmon_register(struct phy_device *phydev)
203 struct device *dev = &phydev->mdio.dev;
204 struct device *hwmon_dev;
207 hwmon_name = devm_hwmon_sanitize_name(dev, dev_name(dev));
208 if (IS_ERR(hwmon_name))
209 return PTR_ERR(hwmon_name);
211 hwmon_dev = devm_hwmon_device_register_with_info(dev, hwmon_name,
213 &gpy_hwmon_chip_info,
216 return PTR_ERR_OR_ZERO(hwmon_dev);
219 static int gpy_hwmon_register(struct phy_device *phydev)
225 static int gpy_ack_interrupt(struct phy_device *phydev)
229 /* Clear all pending interrupts */
230 ret = phy_read(phydev, PHY_ISTAT);
231 return ret < 0 ? ret : 0;
234 static int gpy_mbox_read(struct phy_device *phydev, u32 addr)
236 struct gpy_priv *priv = phydev->priv;
240 mutex_lock(&priv->mbox_lock);
242 ret = phy_write_mmd(phydev, MDIO_MMD_VEND1, VSPEC1_MBOX_ADDRLO,
247 cmd = VSPEC1_MBOX_CMD_RD;
248 cmd |= FIELD_PREP(VSPEC1_MBOX_CMD_ADDRHI, addr >> 16);
250 ret = phy_write_mmd(phydev, MDIO_MMD_VEND1, VSPEC1_MBOX_CMD, cmd);
254 /* The mbox read is used in the interrupt workaround. It was observed
255 * that a read might take up to 2.5ms. This is also the time for which
256 * the interrupt line is stuck low. To be on the safe side, poll the
257 * ready bit for 10ms.
259 ret = phy_read_mmd_poll_timeout(phydev, MDIO_MMD_VEND1,
260 VSPEC1_MBOX_CMD, val,
261 (val & VSPEC1_MBOX_CMD_READY),
266 ret = phy_read_mmd(phydev, MDIO_MMD_VEND1, VSPEC1_MBOX_DATA);
269 mutex_unlock(&priv->mbox_lock);
273 static int gpy_config_init(struct phy_device *phydev)
275 /* Nothing to configure. Configuration Requirement Placeholder */
279 static int gpy21x_config_init(struct phy_device *phydev)
281 __set_bit(PHY_INTERFACE_MODE_2500BASEX, phydev->possible_interfaces);
282 __set_bit(PHY_INTERFACE_MODE_SGMII, phydev->possible_interfaces);
284 return gpy_config_init(phydev);
287 static int gpy_probe(struct phy_device *phydev)
289 struct device *dev = &phydev->mdio.dev;
290 struct gpy_priv *priv;
294 if (!phydev->is_c45) {
295 ret = phy_get_c45_ids(phydev);
300 priv = devm_kzalloc(dev, sizeof(*priv), GFP_KERNEL);
304 mutex_init(&priv->mbox_lock);
306 if (!device_property_present(dev, "maxlinear,use-broken-interrupts"))
307 phydev->dev_flags |= PHY_F_NO_IRQ;
309 fw_version = phy_read(phydev, PHY_FWV);
312 priv->fw_major = FIELD_GET(PHY_FWV_MAJOR_MASK, fw_version);
313 priv->fw_minor = FIELD_GET(PHY_FWV_MINOR_MASK, fw_version);
315 ret = gpy_hwmon_register(phydev);
319 /* Show GPY PHY FW version in dmesg */
320 phydev_info(phydev, "Firmware Version: %d.%d (0x%04X%s)\n",
321 priv->fw_major, priv->fw_minor, fw_version,
322 fw_version & PHY_FWV_REL_MASK ? "" : " test version");
327 static bool gpy_sgmii_need_reaneg(struct phy_device *phydev)
329 struct gpy_priv *priv = phydev->priv;
332 for (i = 0; i < ARRAY_SIZE(ver_need_sgmii_reaneg); i++) {
333 if (priv->fw_major != ver_need_sgmii_reaneg[i].major)
335 if (priv->fw_minor < ver_need_sgmii_reaneg[i].minor)
343 static bool gpy_2500basex_chk(struct phy_device *phydev)
347 ret = phy_read(phydev, PHY_MIISTAT);
349 phydev_err(phydev, "Error: MDIO register access failed: %d\n",
354 if (!(ret & PHY_MIISTAT_LS) ||
355 FIELD_GET(PHY_MIISTAT_SPD_MASK, ret) != PHY_MIISTAT_SPD_2500)
358 phydev->speed = SPEED_2500;
359 phydev->interface = PHY_INTERFACE_MODE_2500BASEX;
360 phy_modify_mmd(phydev, MDIO_MMD_VEND1, VSPEC1_SGMII_CTRL,
361 VSPEC1_SGMII_CTRL_ANEN, 0);
365 static bool gpy_sgmii_aneg_en(struct phy_device *phydev)
369 ret = phy_read_mmd(phydev, MDIO_MMD_VEND1, VSPEC1_SGMII_CTRL);
371 phydev_err(phydev, "Error: MMD register access failed: %d\n",
376 return (ret & VSPEC1_SGMII_CTRL_ANEN) ? true : false;
379 static int gpy_config_mdix(struct phy_device *phydev, u8 ctrl)
385 case ETH_TP_MDI_AUTO:
386 val = PHY_CTL1_AMDIX;
389 val = (PHY_CTL1_MDIAB | PHY_CTL1_MDICD);
398 ret = phy_modify(phydev, PHY_CTL1, PHY_CTL1_AMDIX | PHY_CTL1_MDIAB |
399 PHY_CTL1_MDICD, val);
403 return genphy_c45_restart_aneg(phydev);
406 static int gpy_config_aneg(struct phy_device *phydev)
408 bool changed = false;
412 if (phydev->autoneg == AUTONEG_DISABLE) {
413 /* Configure half duplex with genphy_setup_forced,
414 * because genphy_c45_pma_setup_forced does not support.
416 return phydev->duplex != DUPLEX_FULL
417 ? genphy_setup_forced(phydev)
418 : genphy_c45_pma_setup_forced(phydev);
421 ret = gpy_config_mdix(phydev, phydev->mdix_ctrl);
425 ret = genphy_c45_an_config_aneg(phydev);
431 adv = linkmode_adv_to_mii_ctrl1000_t(phydev->advertising);
432 ret = phy_modify_changed(phydev, MII_CTRL1000,
433 ADVERTISE_1000FULL | ADVERTISE_1000HALF,
440 ret = genphy_c45_check_and_restart_aneg(phydev, changed);
444 if (phydev->interface == PHY_INTERFACE_MODE_USXGMII ||
445 phydev->interface == PHY_INTERFACE_MODE_INTERNAL)
448 /* No need to trigger re-ANEG if link speed is 2.5G or SGMII ANEG is
451 if (!gpy_sgmii_need_reaneg(phydev) || gpy_2500basex_chk(phydev) ||
452 !gpy_sgmii_aneg_en(phydev))
455 /* There is a design constraint in GPY2xx device where SGMII AN is
456 * only triggered when there is change of speed. If, PHY link
457 * partner`s speed is still same even after PHY TPI is down and up
458 * again, SGMII AN is not triggered and hence no new in-band message
459 * from GPY to MAC side SGMII.
460 * This could cause an issue during power up, when PHY is up prior to
461 * MAC. At this condition, once MAC side SGMII is up, MAC side SGMII
462 * wouldn`t receive new in-band message from GPY with correct link
463 * status, speed and duplex info.
465 * 1) If PHY is already up and TPI link status is still down (such as
466 * hard reboot), TPI link status is polled for 4 seconds before
467 * retriggerring SGMII AN.
468 * 2) If PHY is already up and TPI link status is also up (such as soft
469 * reboot), polling of TPI link status is not needed and SGMII AN is
470 * immediately retriggered.
471 * 3) Other conditions such as PHY is down, speed change etc, skip
472 * retriggering SGMII AN. Note: in case of speed change, GPY FW will
476 if (phydev->state != PHY_UP)
479 ret = phy_read_poll_timeout(phydev, MII_BMSR, ret, ret & BMSR_LSTATUS,
480 20000, 4000000, false);
481 if (ret == -ETIMEDOUT)
486 /* Trigger SGMII AN. */
487 return phy_modify_mmd(phydev, MDIO_MMD_VEND1, VSPEC1_SGMII_CTRL,
488 VSPEC1_SGMII_CTRL_ANRS, VSPEC1_SGMII_CTRL_ANRS);
491 static int gpy_update_mdix(struct phy_device *phydev)
495 ret = phy_read(phydev, PHY_CTL1);
499 if (ret & PHY_CTL1_AMDIX)
500 phydev->mdix_ctrl = ETH_TP_MDI_AUTO;
502 if (ret & PHY_CTL1_MDICD || ret & PHY_CTL1_MDIAB)
503 phydev->mdix_ctrl = ETH_TP_MDI_X;
505 phydev->mdix_ctrl = ETH_TP_MDI;
507 ret = phy_read_mmd(phydev, MDIO_MMD_PMAPMD, PHY_PMA_MGBT_POLARITY);
511 if ((ret & PHY_MDI_MDI_X_MASK) < PHY_MDI_MDI_X_NORMAL)
512 phydev->mdix = ETH_TP_MDI_X;
514 phydev->mdix = ETH_TP_MDI;
519 static int gpy_update_interface(struct phy_device *phydev)
523 /* Interface mode is fixed for USXGMII and integrated PHY */
524 if (phydev->interface == PHY_INTERFACE_MODE_USXGMII ||
525 phydev->interface == PHY_INTERFACE_MODE_INTERNAL)
528 /* Automatically switch SERDES interface between SGMII and 2500-BaseX
529 * according to speed. Disable ANEG in 2500-BaseX mode.
531 switch (phydev->speed) {
533 phydev->interface = PHY_INTERFACE_MODE_2500BASEX;
534 ret = phy_modify_mmd(phydev, MDIO_MMD_VEND1, VSPEC1_SGMII_CTRL,
535 VSPEC1_SGMII_CTRL_ANEN, 0);
538 "Error: Disable of SGMII ANEG failed: %d\n",
546 phydev->interface = PHY_INTERFACE_MODE_SGMII;
547 if (gpy_sgmii_aneg_en(phydev))
549 /* Enable and restart SGMII ANEG for 10/100/1000Mbps link speed
550 * if ANEG is disabled (in 2500-BaseX mode).
552 ret = phy_modify_mmd(phydev, MDIO_MMD_VEND1, VSPEC1_SGMII_CTRL,
553 VSPEC1_SGMII_ANEN_ANRS,
554 VSPEC1_SGMII_ANEN_ANRS);
557 "Error: Enable of SGMII ANEG failed: %d\n",
564 if (phydev->speed == SPEED_2500 || phydev->speed == SPEED_1000) {
565 ret = genphy_read_master_slave(phydev);
570 return gpy_update_mdix(phydev);
573 static int gpy_read_status(struct phy_device *phydev)
577 ret = genphy_update_link(phydev);
581 phydev->speed = SPEED_UNKNOWN;
582 phydev->duplex = DUPLEX_UNKNOWN;
584 phydev->asym_pause = 0;
586 if (phydev->autoneg == AUTONEG_ENABLE && phydev->autoneg_complete) {
587 ret = genphy_c45_read_lpa(phydev);
591 /* Read the link partner's 1G advertisement */
592 ret = phy_read(phydev, MII_STAT1000);
595 mii_stat1000_mod_linkmode_lpa_t(phydev->lp_advertising, ret);
596 } else if (phydev->autoneg == AUTONEG_DISABLE) {
597 linkmode_zero(phydev->lp_advertising);
600 ret = phy_read(phydev, PHY_MIISTAT);
604 phydev->link = (ret & PHY_MIISTAT_LS) ? 1 : 0;
605 phydev->duplex = (ret & PHY_MIISTAT_DPX) ? DUPLEX_FULL : DUPLEX_HALF;
606 switch (FIELD_GET(PHY_MIISTAT_SPD_MASK, ret)) {
607 case PHY_MIISTAT_SPD_10:
608 phydev->speed = SPEED_10;
610 case PHY_MIISTAT_SPD_100:
611 phydev->speed = SPEED_100;
613 case PHY_MIISTAT_SPD_1000:
614 phydev->speed = SPEED_1000;
616 case PHY_MIISTAT_SPD_2500:
617 phydev->speed = SPEED_2500;
622 ret = gpy_update_interface(phydev);
630 static int gpy_config_intr(struct phy_device *phydev)
632 struct gpy_priv *priv = phydev->priv;
636 ret = gpy_ack_interrupt(phydev);
640 if (phydev->interrupts == PHY_INTERRUPT_ENABLED)
641 mask = PHY_IMASK_MASK;
643 if (priv->wolopts & WAKE_MAGIC)
644 mask |= PHY_IMASK_WOL;
646 if (priv->wolopts & WAKE_PHY)
647 mask |= PHY_IMASK_LSTC;
649 return phy_write(phydev, PHY_IMASK, mask);
652 static irqreturn_t gpy_handle_interrupt(struct phy_device *phydev)
656 reg = phy_read(phydev, PHY_ISTAT);
662 if (!(reg & PHY_IMASK_MASK))
665 /* The PHY might leave the interrupt line asserted even after PHY_ISTAT
666 * is read. To avoid interrupt storms, delay the interrupt handling as
667 * long as the PHY drives the interrupt line. An internal bus read will
668 * stall as long as the interrupt line is asserted, thus just read a
669 * random register here.
670 * Because we cannot access the internal bus at all while the interrupt
671 * is driven by the PHY, there is no way to make the interrupt line
672 * unstuck (e.g. by changing the pinmux to GPIO input) during that time
673 * frame. Therefore, polling is the best we can do and won't do any more
675 * It was observed that this bug happens on link state and link speed
676 * changes independent of the firmware version.
678 if (reg & (PHY_IMASK_LSTC | PHY_IMASK_LSPC)) {
679 reg = gpy_mbox_read(phydev, REG_GPIO0_OUT);
686 phy_trigger_machine(phydev);
691 static int gpy_set_wol(struct phy_device *phydev,
692 struct ethtool_wolinfo *wol)
694 struct net_device *attach_dev = phydev->attached_dev;
695 struct gpy_priv *priv = phydev->priv;
698 if (wol->wolopts & WAKE_MAGIC) {
699 /* MAC address - Byte0:Byte1:Byte2:Byte3:Byte4:Byte5
700 * VPSPEC2_WOL_AD45 = Byte0:Byte1
701 * VPSPEC2_WOL_AD23 = Byte2:Byte3
702 * VPSPEC2_WOL_AD01 = Byte4:Byte5
704 ret = phy_set_bits_mmd(phydev, MDIO_MMD_VEND2,
706 ((attach_dev->dev_addr[0] << 8) |
707 attach_dev->dev_addr[1]));
711 ret = phy_set_bits_mmd(phydev, MDIO_MMD_VEND2,
713 ((attach_dev->dev_addr[2] << 8) |
714 attach_dev->dev_addr[3]));
718 ret = phy_set_bits_mmd(phydev, MDIO_MMD_VEND2,
720 ((attach_dev->dev_addr[4] << 8) |
721 attach_dev->dev_addr[5]));
725 /* Enable the WOL interrupt */
726 ret = phy_write(phydev, PHY_IMASK, PHY_IMASK_WOL);
730 /* Enable magic packet matching */
731 ret = phy_set_bits_mmd(phydev, MDIO_MMD_VEND2,
737 /* Clear the interrupt status register.
738 * Only WoL is enabled so clear all.
740 ret = phy_read(phydev, PHY_ISTAT);
744 priv->wolopts |= WAKE_MAGIC;
746 /* Disable magic packet matching */
747 ret = phy_clear_bits_mmd(phydev, MDIO_MMD_VEND2,
753 /* Disable the WOL interrupt */
754 ret = phy_clear_bits(phydev, PHY_IMASK, PHY_IMASK_WOL);
758 priv->wolopts &= ~WAKE_MAGIC;
761 if (wol->wolopts & WAKE_PHY) {
762 /* Enable the link state change interrupt */
763 ret = phy_set_bits(phydev, PHY_IMASK, PHY_IMASK_LSTC);
767 /* Clear the interrupt status register */
768 ret = phy_read(phydev, PHY_ISTAT);
772 if (ret & (PHY_IMASK_MASK & ~PHY_IMASK_LSTC))
773 phy_trigger_machine(phydev);
775 priv->wolopts |= WAKE_PHY;
779 priv->wolopts &= ~WAKE_PHY;
780 /* Disable the link state change interrupt */
781 return phy_clear_bits(phydev, PHY_IMASK, PHY_IMASK_LSTC);
784 static void gpy_get_wol(struct phy_device *phydev,
785 struct ethtool_wolinfo *wol)
787 struct gpy_priv *priv = phydev->priv;
789 wol->supported = WAKE_MAGIC | WAKE_PHY;
790 wol->wolopts = priv->wolopts;
793 static int gpy_loopback(struct phy_device *phydev, bool enable)
795 struct gpy_priv *priv = phydev->priv;
800 u64 now = get_jiffies_64();
802 /* wait until 3 seconds from last disable */
803 if (time_before64(now, priv->lb_dis_to))
804 msleep(jiffies64_to_msecs(priv->lb_dis_to - now));
809 ret = phy_modify(phydev, MII_BMCR, BMCR_LOOPBACK, set);
814 /* It takes some time for PHY device to switch into
819 priv->lb_dis_to = get_jiffies_64() + HZ * 3;
825 static int gpy115_loopback(struct phy_device *phydev, bool enable)
827 struct gpy_priv *priv = phydev->priv;
830 return gpy_loopback(phydev, enable);
832 if (priv->fw_minor > 0x76)
833 return gpy_loopback(phydev, 0);
835 return genphy_soft_reset(phydev);
838 static struct phy_driver gpy_drivers[] = {
840 PHY_ID_MATCH_MODEL(PHY_ID_GPY2xx),
841 .name = "Maxlinear Ethernet GPY2xx",
842 .get_features = genphy_c45_pma_read_abilities,
843 .config_init = gpy_config_init,
845 .suspend = genphy_suspend,
846 .resume = genphy_resume,
847 .config_aneg = gpy_config_aneg,
848 .aneg_done = genphy_c45_aneg_done,
849 .read_status = gpy_read_status,
850 .config_intr = gpy_config_intr,
851 .handle_interrupt = gpy_handle_interrupt,
852 .set_wol = gpy_set_wol,
853 .get_wol = gpy_get_wol,
854 .set_loopback = gpy_loopback,
857 .phy_id = PHY_ID_GPY115B,
858 .phy_id_mask = PHY_ID_GPYx15B_MASK,
859 .name = "Maxlinear Ethernet GPY115B",
860 .get_features = genphy_c45_pma_read_abilities,
861 .config_init = gpy_config_init,
863 .suspend = genphy_suspend,
864 .resume = genphy_resume,
865 .config_aneg = gpy_config_aneg,
866 .aneg_done = genphy_c45_aneg_done,
867 .read_status = gpy_read_status,
868 .config_intr = gpy_config_intr,
869 .handle_interrupt = gpy_handle_interrupt,
870 .set_wol = gpy_set_wol,
871 .get_wol = gpy_get_wol,
872 .set_loopback = gpy115_loopback,
875 PHY_ID_MATCH_MODEL(PHY_ID_GPY115C),
876 .name = "Maxlinear Ethernet GPY115C",
877 .get_features = genphy_c45_pma_read_abilities,
878 .config_init = gpy_config_init,
880 .suspend = genphy_suspend,
881 .resume = genphy_resume,
882 .config_aneg = gpy_config_aneg,
883 .aneg_done = genphy_c45_aneg_done,
884 .read_status = gpy_read_status,
885 .config_intr = gpy_config_intr,
886 .handle_interrupt = gpy_handle_interrupt,
887 .set_wol = gpy_set_wol,
888 .get_wol = gpy_get_wol,
889 .set_loopback = gpy115_loopback,
892 .phy_id = PHY_ID_GPY211B,
893 .phy_id_mask = PHY_ID_GPY21xB_MASK,
894 .name = "Maxlinear Ethernet GPY211B",
895 .get_features = genphy_c45_pma_read_abilities,
896 .config_init = gpy21x_config_init,
898 .suspend = genphy_suspend,
899 .resume = genphy_resume,
900 .config_aneg = gpy_config_aneg,
901 .aneg_done = genphy_c45_aneg_done,
902 .read_status = gpy_read_status,
903 .config_intr = gpy_config_intr,
904 .handle_interrupt = gpy_handle_interrupt,
905 .set_wol = gpy_set_wol,
906 .get_wol = gpy_get_wol,
907 .set_loopback = gpy_loopback,
910 PHY_ID_MATCH_MODEL(PHY_ID_GPY211C),
911 .name = "Maxlinear Ethernet GPY211C",
912 .get_features = genphy_c45_pma_read_abilities,
913 .config_init = gpy21x_config_init,
915 .suspend = genphy_suspend,
916 .resume = genphy_resume,
917 .config_aneg = gpy_config_aneg,
918 .aneg_done = genphy_c45_aneg_done,
919 .read_status = gpy_read_status,
920 .config_intr = gpy_config_intr,
921 .handle_interrupt = gpy_handle_interrupt,
922 .set_wol = gpy_set_wol,
923 .get_wol = gpy_get_wol,
924 .set_loopback = gpy_loopback,
927 .phy_id = PHY_ID_GPY212B,
928 .phy_id_mask = PHY_ID_GPY21xB_MASK,
929 .name = "Maxlinear Ethernet GPY212B",
930 .get_features = genphy_c45_pma_read_abilities,
931 .config_init = gpy21x_config_init,
933 .suspend = genphy_suspend,
934 .resume = genphy_resume,
935 .config_aneg = gpy_config_aneg,
936 .aneg_done = genphy_c45_aneg_done,
937 .read_status = gpy_read_status,
938 .config_intr = gpy_config_intr,
939 .handle_interrupt = gpy_handle_interrupt,
940 .set_wol = gpy_set_wol,
941 .get_wol = gpy_get_wol,
942 .set_loopback = gpy_loopback,
945 PHY_ID_MATCH_MODEL(PHY_ID_GPY212C),
946 .name = "Maxlinear Ethernet GPY212C",
947 .get_features = genphy_c45_pma_read_abilities,
948 .config_init = gpy21x_config_init,
950 .suspend = genphy_suspend,
951 .resume = genphy_resume,
952 .config_aneg = gpy_config_aneg,
953 .aneg_done = genphy_c45_aneg_done,
954 .read_status = gpy_read_status,
955 .config_intr = gpy_config_intr,
956 .handle_interrupt = gpy_handle_interrupt,
957 .set_wol = gpy_set_wol,
958 .get_wol = gpy_get_wol,
959 .set_loopback = gpy_loopback,
962 .phy_id = PHY_ID_GPY215B,
963 .phy_id_mask = PHY_ID_GPYx15B_MASK,
964 .name = "Maxlinear Ethernet GPY215B",
965 .get_features = genphy_c45_pma_read_abilities,
966 .config_init = gpy21x_config_init,
968 .suspend = genphy_suspend,
969 .resume = genphy_resume,
970 .config_aneg = gpy_config_aneg,
971 .aneg_done = genphy_c45_aneg_done,
972 .read_status = gpy_read_status,
973 .config_intr = gpy_config_intr,
974 .handle_interrupt = gpy_handle_interrupt,
975 .set_wol = gpy_set_wol,
976 .get_wol = gpy_get_wol,
977 .set_loopback = gpy_loopback,
980 PHY_ID_MATCH_MODEL(PHY_ID_GPY215C),
981 .name = "Maxlinear Ethernet GPY215C",
982 .get_features = genphy_c45_pma_read_abilities,
983 .config_init = gpy21x_config_init,
985 .suspend = genphy_suspend,
986 .resume = genphy_resume,
987 .config_aneg = gpy_config_aneg,
988 .aneg_done = genphy_c45_aneg_done,
989 .read_status = gpy_read_status,
990 .config_intr = gpy_config_intr,
991 .handle_interrupt = gpy_handle_interrupt,
992 .set_wol = gpy_set_wol,
993 .get_wol = gpy_get_wol,
994 .set_loopback = gpy_loopback,
997 PHY_ID_MATCH_MODEL(PHY_ID_GPY241B),
998 .name = "Maxlinear Ethernet GPY241B",
999 .get_features = genphy_c45_pma_read_abilities,
1000 .config_init = gpy_config_init,
1002 .suspend = genphy_suspend,
1003 .resume = genphy_resume,
1004 .config_aneg = gpy_config_aneg,
1005 .aneg_done = genphy_c45_aneg_done,
1006 .read_status = gpy_read_status,
1007 .config_intr = gpy_config_intr,
1008 .handle_interrupt = gpy_handle_interrupt,
1009 .set_wol = gpy_set_wol,
1010 .get_wol = gpy_get_wol,
1011 .set_loopback = gpy_loopback,
1014 PHY_ID_MATCH_MODEL(PHY_ID_GPY241BM),
1015 .name = "Maxlinear Ethernet GPY241BM",
1016 .get_features = genphy_c45_pma_read_abilities,
1017 .config_init = gpy_config_init,
1019 .suspend = genphy_suspend,
1020 .resume = genphy_resume,
1021 .config_aneg = gpy_config_aneg,
1022 .aneg_done = genphy_c45_aneg_done,
1023 .read_status = gpy_read_status,
1024 .config_intr = gpy_config_intr,
1025 .handle_interrupt = gpy_handle_interrupt,
1026 .set_wol = gpy_set_wol,
1027 .get_wol = gpy_get_wol,
1028 .set_loopback = gpy_loopback,
1031 PHY_ID_MATCH_MODEL(PHY_ID_GPY245B),
1032 .name = "Maxlinear Ethernet GPY245B",
1033 .get_features = genphy_c45_pma_read_abilities,
1034 .config_init = gpy_config_init,
1036 .suspend = genphy_suspend,
1037 .resume = genphy_resume,
1038 .config_aneg = gpy_config_aneg,
1039 .aneg_done = genphy_c45_aneg_done,
1040 .read_status = gpy_read_status,
1041 .config_intr = gpy_config_intr,
1042 .handle_interrupt = gpy_handle_interrupt,
1043 .set_wol = gpy_set_wol,
1044 .get_wol = gpy_get_wol,
1045 .set_loopback = gpy_loopback,
1048 module_phy_driver(gpy_drivers);
1050 static struct mdio_device_id __maybe_unused gpy_tbl[] = {
1051 {PHY_ID_MATCH_MODEL(PHY_ID_GPY2xx)},
1052 {PHY_ID_GPY115B, PHY_ID_GPYx15B_MASK},
1053 {PHY_ID_MATCH_MODEL(PHY_ID_GPY115C)},
1054 {PHY_ID_GPY211B, PHY_ID_GPY21xB_MASK},
1055 {PHY_ID_MATCH_MODEL(PHY_ID_GPY211C)},
1056 {PHY_ID_GPY212B, PHY_ID_GPY21xB_MASK},
1057 {PHY_ID_MATCH_MODEL(PHY_ID_GPY212C)},
1058 {PHY_ID_GPY215B, PHY_ID_GPYx15B_MASK},
1059 {PHY_ID_MATCH_MODEL(PHY_ID_GPY215C)},
1060 {PHY_ID_MATCH_MODEL(PHY_ID_GPY241B)},
1061 {PHY_ID_MATCH_MODEL(PHY_ID_GPY241BM)},
1062 {PHY_ID_MATCH_MODEL(PHY_ID_GPY245B)},
1065 MODULE_DEVICE_TABLE(mdio, gpy_tbl);
1067 MODULE_DESCRIPTION("Maxlinear Ethernet GPY Driver");
1068 MODULE_AUTHOR("Xu Liang");
1069 MODULE_LICENSE("GPL");