xref: /linux/drivers/net/phy/marvell10g.c (revision 62d01535474b612b3c5d864999b17cbf2cd8f2cc)
1a2443fd1SAndrew Lunn // SPDX-License-Identifier: GPL-2.0+
220b2af32SRussell King /*
320b2af32SRussell King  * Marvell 10G 88x3310 PHY driver
420b2af32SRussell King  *
520b2af32SRussell King  * Based upon the ID registers, this PHY appears to be a mixture of IPs
620b2af32SRussell King  * from two different companies.
720b2af32SRussell King  *
820b2af32SRussell King  * There appears to be several different data paths through the PHY which
920b2af32SRussell King  * are automatically managed by the PHY.  The following has been determined
1005ca1b32SRussell King  * via observation and experimentation for a setup using single-lane Serdes:
1120b2af32SRussell King  *
1220b2af32SRussell King  *       SGMII PHYXS -- BASE-T PCS -- 10G PMA -- AN -- Copper (for <= 1G)
1320b2af32SRussell King  *  10GBASE-KR PHYXS -- BASE-T PCS -- 10G PMA -- AN -- Copper (for 10G)
1420b2af32SRussell King  *  10GBASE-KR PHYXS -- BASE-R PCS -- Fiber
1520b2af32SRussell King  *
1605ca1b32SRussell King  * With XAUI, observation shows:
1705ca1b32SRussell King  *
1805ca1b32SRussell King  *        XAUI PHYXS -- <appropriate PCS as above>
1905ca1b32SRussell King  *
2005ca1b32SRussell King  * and no switching of the host interface mode occurs.
2105ca1b32SRussell King  *
2220b2af32SRussell King  * If both the fiber and copper ports are connected, the first to gain
2320b2af32SRussell King  * link takes priority and the other port is completely locked out.
2420b2af32SRussell King  */
250d3ad854SRussell King #include <linux/ctype.h>
260d3ad854SRussell King #include <linux/hwmon.h>
27952b6b3bSAntoine Tenart #include <linux/marvell_phy.h>
280d3ad854SRussell King #include <linux/phy.h>
2920b2af32SRussell King 
30c47455f9SMaxime Chevallier #define MV_PHY_ALASKA_NBT_QUIRK_MASK	0xfffffffe
31c47455f9SMaxime Chevallier #define MV_PHY_ALASKA_NBT_QUIRK_REV	(MARVELL_PHY_ID_88X3310 | 0xa)
32c47455f9SMaxime Chevallier 
3320b2af32SRussell King enum {
3420b2af32SRussell King 	MV_PCS_BASE_T		= 0x0000,
3520b2af32SRussell King 	MV_PCS_BASE_R		= 0x1000,
3620b2af32SRussell King 	MV_PCS_1000BASEX	= 0x2000,
3720b2af32SRussell King 
38ea4efe25SRussell King 	MV_PCS_PAIRSWAP		= 0x8182,
39ea4efe25SRussell King 	MV_PCS_PAIRSWAP_MASK	= 0x0003,
40ea4efe25SRussell King 	MV_PCS_PAIRSWAP_AB	= 0x0002,
41ea4efe25SRussell King 	MV_PCS_PAIRSWAP_NONE	= 0x0003,
42ea4efe25SRussell King 
4320b2af32SRussell King 	/* These registers appear at 0x800X and 0xa00X - the 0xa00X control
4420b2af32SRussell King 	 * registers appear to set themselves to the 0x800X when AN is
4520b2af32SRussell King 	 * restarted, but status registers appear readable from either.
4620b2af32SRussell King 	 */
4720b2af32SRussell King 	MV_AN_CTRL1000		= 0x8000, /* 1000base-T control register */
4820b2af32SRussell King 	MV_AN_STAT1000		= 0x8001, /* 1000base-T status register */
490d3ad854SRussell King 
500d3ad854SRussell King 	/* Vendor2 MMD registers */
510d3ad854SRussell King 	MV_V2_TEMP_CTRL		= 0xf08a,
520d3ad854SRussell King 	MV_V2_TEMP_CTRL_MASK	= 0xc000,
530d3ad854SRussell King 	MV_V2_TEMP_CTRL_SAMPLE	= 0x0000,
540d3ad854SRussell King 	MV_V2_TEMP_CTRL_DISABLE	= 0xc000,
550d3ad854SRussell King 	MV_V2_TEMP		= 0xf08c,
560d3ad854SRussell King 	MV_V2_TEMP_UNKNOWN	= 0x9600, /* unknown function */
570d3ad854SRussell King };
580d3ad854SRussell King 
590d3ad854SRussell King struct mv3310_priv {
600d3ad854SRussell King 	struct device *hwmon_dev;
610d3ad854SRussell King 	char *hwmon_name;
6220b2af32SRussell King };
6320b2af32SRussell King 
640d3ad854SRussell King #ifdef CONFIG_HWMON
650d3ad854SRussell King static umode_t mv3310_hwmon_is_visible(const void *data,
660d3ad854SRussell King 				       enum hwmon_sensor_types type,
670d3ad854SRussell King 				       u32 attr, int channel)
680d3ad854SRussell King {
690d3ad854SRussell King 	if (type == hwmon_chip && attr == hwmon_chip_update_interval)
700d3ad854SRussell King 		return 0444;
710d3ad854SRussell King 	if (type == hwmon_temp && attr == hwmon_temp_input)
720d3ad854SRussell King 		return 0444;
730d3ad854SRussell King 	return 0;
740d3ad854SRussell King }
750d3ad854SRussell King 
760d3ad854SRussell King static int mv3310_hwmon_read(struct device *dev, enum hwmon_sensor_types type,
770d3ad854SRussell King 			     u32 attr, int channel, long *value)
780d3ad854SRussell King {
790d3ad854SRussell King 	struct phy_device *phydev = dev_get_drvdata(dev);
800d3ad854SRussell King 	int temp;
810d3ad854SRussell King 
820d3ad854SRussell King 	if (type == hwmon_chip && attr == hwmon_chip_update_interval) {
830d3ad854SRussell King 		*value = MSEC_PER_SEC;
840d3ad854SRussell King 		return 0;
850d3ad854SRussell King 	}
860d3ad854SRussell King 
870d3ad854SRussell King 	if (type == hwmon_temp && attr == hwmon_temp_input) {
880d3ad854SRussell King 		temp = phy_read_mmd(phydev, MDIO_MMD_VEND2, MV_V2_TEMP);
890d3ad854SRussell King 		if (temp < 0)
900d3ad854SRussell King 			return temp;
910d3ad854SRussell King 
920d3ad854SRussell King 		*value = ((temp & 0xff) - 75) * 1000;
930d3ad854SRussell King 
940d3ad854SRussell King 		return 0;
950d3ad854SRussell King 	}
960d3ad854SRussell King 
970d3ad854SRussell King 	return -EOPNOTSUPP;
980d3ad854SRussell King }
990d3ad854SRussell King 
1000d3ad854SRussell King static const struct hwmon_ops mv3310_hwmon_ops = {
1010d3ad854SRussell King 	.is_visible = mv3310_hwmon_is_visible,
1020d3ad854SRussell King 	.read = mv3310_hwmon_read,
1030d3ad854SRussell King };
1040d3ad854SRussell King 
1050d3ad854SRussell King static u32 mv3310_hwmon_chip_config[] = {
1060d3ad854SRussell King 	HWMON_C_REGISTER_TZ | HWMON_C_UPDATE_INTERVAL,
1070d3ad854SRussell King 	0,
1080d3ad854SRussell King };
1090d3ad854SRussell King 
1100d3ad854SRussell King static const struct hwmon_channel_info mv3310_hwmon_chip = {
1110d3ad854SRussell King 	.type = hwmon_chip,
1120d3ad854SRussell King 	.config = mv3310_hwmon_chip_config,
1130d3ad854SRussell King };
1140d3ad854SRussell King 
1150d3ad854SRussell King static u32 mv3310_hwmon_temp_config[] = {
1160d3ad854SRussell King 	HWMON_T_INPUT,
1170d3ad854SRussell King 	0,
1180d3ad854SRussell King };
1190d3ad854SRussell King 
1200d3ad854SRussell King static const struct hwmon_channel_info mv3310_hwmon_temp = {
1210d3ad854SRussell King 	.type = hwmon_temp,
1220d3ad854SRussell King 	.config = mv3310_hwmon_temp_config,
1230d3ad854SRussell King };
1240d3ad854SRussell King 
1250d3ad854SRussell King static const struct hwmon_channel_info *mv3310_hwmon_info[] = {
1260d3ad854SRussell King 	&mv3310_hwmon_chip,
1270d3ad854SRussell King 	&mv3310_hwmon_temp,
1280d3ad854SRussell King 	NULL,
1290d3ad854SRussell King };
1300d3ad854SRussell King 
1310d3ad854SRussell King static const struct hwmon_chip_info mv3310_hwmon_chip_info = {
1320d3ad854SRussell King 	.ops = &mv3310_hwmon_ops,
1330d3ad854SRussell King 	.info = mv3310_hwmon_info,
1340d3ad854SRussell King };
1350d3ad854SRussell King 
1360d3ad854SRussell King static int mv3310_hwmon_config(struct phy_device *phydev, bool enable)
1370d3ad854SRussell King {
1380d3ad854SRussell King 	u16 val;
1390d3ad854SRussell King 	int ret;
1400d3ad854SRussell King 
1410d3ad854SRussell King 	ret = phy_write_mmd(phydev, MDIO_MMD_VEND2, MV_V2_TEMP,
1420d3ad854SRussell King 			    MV_V2_TEMP_UNKNOWN);
1430d3ad854SRussell King 	if (ret < 0)
1440d3ad854SRussell King 		return ret;
1450d3ad854SRussell King 
1460d3ad854SRussell King 	val = enable ? MV_V2_TEMP_CTRL_SAMPLE : MV_V2_TEMP_CTRL_DISABLE;
1470d3ad854SRussell King 
148b06d8e5aSHeiner Kallweit 	return phy_modify_mmd(phydev, MDIO_MMD_VEND2, MV_V2_TEMP_CTRL,
149b06d8e5aSHeiner Kallweit 			      MV_V2_TEMP_CTRL_MASK, val);
1500d3ad854SRussell King }
1510d3ad854SRussell King 
1520d3ad854SRussell King static void mv3310_hwmon_disable(void *data)
1530d3ad854SRussell King {
1540d3ad854SRussell King 	struct phy_device *phydev = data;
1550d3ad854SRussell King 
1560d3ad854SRussell King 	mv3310_hwmon_config(phydev, false);
1570d3ad854SRussell King }
1580d3ad854SRussell King 
1590d3ad854SRussell King static int mv3310_hwmon_probe(struct phy_device *phydev)
1600d3ad854SRussell King {
1610d3ad854SRussell King 	struct device *dev = &phydev->mdio.dev;
1620d3ad854SRussell King 	struct mv3310_priv *priv = dev_get_drvdata(&phydev->mdio.dev);
1630d3ad854SRussell King 	int i, j, ret;
1640d3ad854SRussell King 
1650d3ad854SRussell King 	priv->hwmon_name = devm_kstrdup(dev, dev_name(dev), GFP_KERNEL);
1660d3ad854SRussell King 	if (!priv->hwmon_name)
1670d3ad854SRussell King 		return -ENODEV;
1680d3ad854SRussell King 
1690d3ad854SRussell King 	for (i = j = 0; priv->hwmon_name[i]; i++) {
1700d3ad854SRussell King 		if (isalnum(priv->hwmon_name[i])) {
1710d3ad854SRussell King 			if (i != j)
1720d3ad854SRussell King 				priv->hwmon_name[j] = priv->hwmon_name[i];
1730d3ad854SRussell King 			j++;
1740d3ad854SRussell King 		}
1750d3ad854SRussell King 	}
1760d3ad854SRussell King 	priv->hwmon_name[j] = '\0';
1770d3ad854SRussell King 
1780d3ad854SRussell King 	ret = mv3310_hwmon_config(phydev, true);
1790d3ad854SRussell King 	if (ret)
1800d3ad854SRussell King 		return ret;
1810d3ad854SRussell King 
1820d3ad854SRussell King 	ret = devm_add_action_or_reset(dev, mv3310_hwmon_disable, phydev);
1830d3ad854SRussell King 	if (ret)
1840d3ad854SRussell King 		return ret;
1850d3ad854SRussell King 
1860d3ad854SRussell King 	priv->hwmon_dev = devm_hwmon_device_register_with_info(dev,
1870d3ad854SRussell King 				priv->hwmon_name, phydev,
1880d3ad854SRussell King 				&mv3310_hwmon_chip_info, NULL);
1890d3ad854SRussell King 
1900d3ad854SRussell King 	return PTR_ERR_OR_ZERO(priv->hwmon_dev);
1910d3ad854SRussell King }
1920d3ad854SRussell King #else
1930d3ad854SRussell King static inline int mv3310_hwmon_config(struct phy_device *phydev, bool enable)
1940d3ad854SRussell King {
1950d3ad854SRussell King 	return 0;
1960d3ad854SRussell King }
1970d3ad854SRussell King 
1980d3ad854SRussell King static int mv3310_hwmon_probe(struct phy_device *phydev)
1990d3ad854SRussell King {
2000d3ad854SRussell King 	return 0;
2010d3ad854SRussell King }
2020d3ad854SRussell King #endif
2030d3ad854SRussell King 
20420b2af32SRussell King static int mv3310_probe(struct phy_device *phydev)
20520b2af32SRussell King {
2060d3ad854SRussell King 	struct mv3310_priv *priv;
20720b2af32SRussell King 	u32 mmd_mask = MDIO_DEVS_PMAPMD | MDIO_DEVS_AN;
2080d3ad854SRussell King 	int ret;
20920b2af32SRussell King 
21020b2af32SRussell King 	if (!phydev->is_c45 ||
21120b2af32SRussell King 	    (phydev->c45_ids.devices_in_package & mmd_mask) != mmd_mask)
21220b2af32SRussell King 		return -ENODEV;
21320b2af32SRussell King 
2140d3ad854SRussell King 	priv = devm_kzalloc(&phydev->mdio.dev, sizeof(*priv), GFP_KERNEL);
2150d3ad854SRussell King 	if (!priv)
2160d3ad854SRussell King 		return -ENOMEM;
2170d3ad854SRussell King 
2180d3ad854SRussell King 	dev_set_drvdata(&phydev->mdio.dev, priv);
2190d3ad854SRussell King 
2200d3ad854SRussell King 	ret = mv3310_hwmon_probe(phydev);
2210d3ad854SRussell King 	if (ret)
2220d3ad854SRussell King 		return ret;
2230d3ad854SRussell King 
22420b2af32SRussell King 	return 0;
22520b2af32SRussell King }
22620b2af32SRussell King 
2270d3ad854SRussell King static int mv3310_suspend(struct phy_device *phydev)
2280d3ad854SRussell King {
2290d3ad854SRussell King 	return 0;
2300d3ad854SRussell King }
2310d3ad854SRussell King 
2320d3ad854SRussell King static int mv3310_resume(struct phy_device *phydev)
2330d3ad854SRussell King {
2340d3ad854SRussell King 	return mv3310_hwmon_config(phydev, true);
2350d3ad854SRussell King }
2360d3ad854SRussell King 
237c47455f9SMaxime Chevallier /* Some PHYs in the Alaska family such as the 88X3310 and the 88E2010
238c47455f9SMaxime Chevallier  * don't set bit 14 in PMA Extended Abilities (1.11), although they do
239c47455f9SMaxime Chevallier  * support 2.5GBASET and 5GBASET. For these models, we can still read their
240c47455f9SMaxime Chevallier  * 2.5G/5G extended abilities register (1.21). We detect these models based on
241c47455f9SMaxime Chevallier  * the PMA device identifier, with a mask matching models known to have this
242c47455f9SMaxime Chevallier  * issue
243c47455f9SMaxime Chevallier  */
244c47455f9SMaxime Chevallier static bool mv3310_has_pma_ngbaset_quirk(struct phy_device *phydev)
245c47455f9SMaxime Chevallier {
246c47455f9SMaxime Chevallier 	if (!(phydev->c45_ids.devices_in_package & MDIO_DEVS_PMAPMD))
247c47455f9SMaxime Chevallier 		return false;
248c47455f9SMaxime Chevallier 
249c47455f9SMaxime Chevallier 	/* Only some revisions of the 88X3310 family PMA seem to be impacted */
250c47455f9SMaxime Chevallier 	return (phydev->c45_ids.device_ids[MDIO_MMD_PMAPMD] &
251c47455f9SMaxime Chevallier 		MV_PHY_ALASKA_NBT_QUIRK_MASK) == MV_PHY_ALASKA_NBT_QUIRK_REV;
252c47455f9SMaxime Chevallier }
253c47455f9SMaxime Chevallier 
25420b2af32SRussell King static int mv3310_config_init(struct phy_device *phydev)
25520b2af32SRussell King {
25620b2af32SRussell King 	/* Check that the PHY interface type is compatible */
25720b2af32SRussell King 	if (phydev->interface != PHY_INTERFACE_MODE_SGMII &&
258e555e5b1SMaxime Chevallier 	    phydev->interface != PHY_INTERFACE_MODE_2500BASEX &&
25920b2af32SRussell King 	    phydev->interface != PHY_INTERFACE_MODE_XAUI &&
26020b2af32SRussell King 	    phydev->interface != PHY_INTERFACE_MODE_RXAUI &&
26120b2af32SRussell King 	    phydev->interface != PHY_INTERFACE_MODE_10GKR)
26220b2af32SRussell King 		return -ENODEV;
26320b2af32SRussell King 
26474145424SMaxime Chevallier 	return 0;
26574145424SMaxime Chevallier }
26674145424SMaxime Chevallier 
26774145424SMaxime Chevallier static int mv3310_get_features(struct phy_device *phydev)
26874145424SMaxime Chevallier {
26974145424SMaxime Chevallier 	int ret, val;
27074145424SMaxime Chevallier 
27120b2af32SRussell King 	if (phydev->c45_ids.devices_in_package & MDIO_DEVS_AN) {
27220b2af32SRussell King 		val = phy_read_mmd(phydev, MDIO_MMD_AN, MDIO_STAT1);
27320b2af32SRussell King 		if (val < 0)
27420b2af32SRussell King 			return val;
27520b2af32SRussell King 
27620b2af32SRussell King 		if (val & MDIO_AN_STAT1_ABLE)
2770feaccd5SMaxime Chevallier 			linkmode_set_bit(ETHTOOL_LINK_MODE_Autoneg_BIT,
2783c1bcc86SAndrew Lunn 					 phydev->supported);
279ac3f5533SMaxime Chevallier 	}
280ac3f5533SMaxime Chevallier 
281ac3f5533SMaxime Chevallier 	ret = genphy_c45_pma_read_abilities(phydev);
282ac3f5533SMaxime Chevallier 	if (ret)
283ac3f5533SMaxime Chevallier 		return ret;
28420b2af32SRussell King 
285c47455f9SMaxime Chevallier 	if (mv3310_has_pma_ngbaset_quirk(phydev)) {
286c47455f9SMaxime Chevallier 		val = phy_read_mmd(phydev, MDIO_MMD_PMAPMD,
287c47455f9SMaxime Chevallier 				   MDIO_PMA_NG_EXTABLE);
288c47455f9SMaxime Chevallier 		if (val < 0)
289c47455f9SMaxime Chevallier 			return val;
290c47455f9SMaxime Chevallier 
291c47455f9SMaxime Chevallier 		linkmode_mod_bit(ETHTOOL_LINK_MODE_2500baseT_Full_BIT,
292c47455f9SMaxime Chevallier 				 phydev->supported,
293c47455f9SMaxime Chevallier 				 val & MDIO_PMA_NG_EXTABLE_2_5GBT);
294c47455f9SMaxime Chevallier 
295c47455f9SMaxime Chevallier 		linkmode_mod_bit(ETHTOOL_LINK_MODE_5000baseT_Full_BIT,
296c47455f9SMaxime Chevallier 				 phydev->supported,
297c47455f9SMaxime Chevallier 				 val & MDIO_PMA_NG_EXTABLE_5GBT);
298c47455f9SMaxime Chevallier 	}
299c47455f9SMaxime Chevallier 
30020b2af32SRussell King 	return 0;
30120b2af32SRussell King }
30220b2af32SRussell King 
30320b2af32SRussell King static int mv3310_config_aneg(struct phy_device *phydev)
30420b2af32SRussell King {
30520b2af32SRussell King 	bool changed = false;
3063c1bcc86SAndrew Lunn 	u16 reg;
30720b2af32SRussell King 	int ret;
30820b2af32SRussell King 
309ea4efe25SRussell King 	/* We don't support manual MDI control */
310ea4efe25SRussell King 	phydev->mdix_ctrl = ETH_TP_MDI_AUTO;
311ea4efe25SRussell King 
31230de65c3SHeiner Kallweit 	if (phydev->autoneg == AUTONEG_DISABLE)
31330de65c3SHeiner Kallweit 		return genphy_c45_pma_setup_forced(phydev);
31420b2af32SRussell King 
3153de97f3cSAndrew Lunn 	ret = genphy_c45_an_config_aneg(phydev);
31620b2af32SRussell King 	if (ret < 0)
31720b2af32SRussell King 		return ret;
31820b2af32SRussell King 	if (ret > 0)
31920b2af32SRussell King 		changed = true;
32020b2af32SRussell King 
3213de97f3cSAndrew Lunn 	/* Clause 45 has no standardized support for 1000BaseT, therefore
3223de97f3cSAndrew Lunn 	 * use vendor registers for this mode.
3233de97f3cSAndrew Lunn 	 */
3243c1bcc86SAndrew Lunn 	reg = linkmode_adv_to_mii_ctrl1000_t(phydev->advertising);
325b06d8e5aSHeiner Kallweit 	ret = phy_modify_mmd_changed(phydev, MDIO_MMD_AN, MV_AN_CTRL1000,
3263c1bcc86SAndrew Lunn 			     ADVERTISE_1000FULL | ADVERTISE_1000HALF, reg);
32720b2af32SRussell King 	if (ret < 0)
32820b2af32SRussell King 		return ret;
32920b2af32SRussell King 	if (ret > 0)
33020b2af32SRussell King 		changed = true;
33120b2af32SRussell King 
3326b4cb6cbSHeiner Kallweit 	return genphy_c45_check_and_restart_aneg(phydev, changed);
33320b2af32SRussell King }
33420b2af32SRussell King 
33520b2af32SRussell King static int mv3310_aneg_done(struct phy_device *phydev)
33620b2af32SRussell King {
33720b2af32SRussell King 	int val;
33820b2af32SRussell King 
33920b2af32SRussell King 	val = phy_read_mmd(phydev, MDIO_MMD_PCS, MV_PCS_BASE_R + MDIO_STAT1);
34020b2af32SRussell King 	if (val < 0)
34120b2af32SRussell King 		return val;
34220b2af32SRussell King 
34320b2af32SRussell King 	if (val & MDIO_STAT1_LSTATUS)
34420b2af32SRussell King 		return 1;
34520b2af32SRussell King 
34620b2af32SRussell King 	return genphy_c45_aneg_done(phydev);
34720b2af32SRussell King }
34820b2af32SRussell King 
34936c4449aSRussell King static void mv3310_update_interface(struct phy_device *phydev)
35036c4449aSRussell King {
35136c4449aSRussell King 	if ((phydev->interface == PHY_INTERFACE_MODE_SGMII ||
352e555e5b1SMaxime Chevallier 	     phydev->interface == PHY_INTERFACE_MODE_2500BASEX ||
35336c4449aSRussell King 	     phydev->interface == PHY_INTERFACE_MODE_10GKR) && phydev->link) {
35436c4449aSRussell King 		/* The PHY automatically switches its serdes interface (and
355e555e5b1SMaxime Chevallier 		 * active PHYXS instance) between Cisco SGMII, 10GBase-KR and
356e555e5b1SMaxime Chevallier 		 * 2500BaseX modes according to the speed.  Florian suggests
357e555e5b1SMaxime Chevallier 		 * setting phydev->interface to communicate this to the MAC.
358e555e5b1SMaxime Chevallier 		 * Only do this if we are already in one of the above modes.
35936c4449aSRussell King 		 */
360e555e5b1SMaxime Chevallier 		switch (phydev->speed) {
361e555e5b1SMaxime Chevallier 		case SPEED_10000:
36236c4449aSRussell King 			phydev->interface = PHY_INTERFACE_MODE_10GKR;
363e555e5b1SMaxime Chevallier 			break;
364e555e5b1SMaxime Chevallier 		case SPEED_2500:
365e555e5b1SMaxime Chevallier 			phydev->interface = PHY_INTERFACE_MODE_2500BASEX;
366e555e5b1SMaxime Chevallier 			break;
367e555e5b1SMaxime Chevallier 		case SPEED_1000:
368e555e5b1SMaxime Chevallier 		case SPEED_100:
369e555e5b1SMaxime Chevallier 		case SPEED_10:
37036c4449aSRussell King 			phydev->interface = PHY_INTERFACE_MODE_SGMII;
371e555e5b1SMaxime Chevallier 			break;
372e555e5b1SMaxime Chevallier 		default:
373e555e5b1SMaxime Chevallier 			break;
374e555e5b1SMaxime Chevallier 		}
37536c4449aSRussell King 	}
37636c4449aSRussell King }
37736c4449aSRussell King 
37820b2af32SRussell King /* 10GBASE-ER,LR,LRM,SR do not support autonegotiation. */
37920b2af32SRussell King static int mv3310_read_10gbr_status(struct phy_device *phydev)
38020b2af32SRussell King {
38120b2af32SRussell King 	phydev->link = 1;
38220b2af32SRussell King 	phydev->speed = SPEED_10000;
38320b2af32SRussell King 	phydev->duplex = DUPLEX_FULL;
38420b2af32SRussell King 
38536c4449aSRussell King 	mv3310_update_interface(phydev);
38620b2af32SRussell King 
38720b2af32SRussell King 	return 0;
38820b2af32SRussell King }
38920b2af32SRussell King 
39020b2af32SRussell King static int mv3310_read_status(struct phy_device *phydev)
39120b2af32SRussell King {
39220b2af32SRussell King 	int val;
39320b2af32SRussell King 
39420b2af32SRussell King 	phydev->speed = SPEED_UNKNOWN;
39520b2af32SRussell King 	phydev->duplex = DUPLEX_UNKNOWN;
396c0ec3c27SAndrew Lunn 	linkmode_zero(phydev->lp_advertising);
39720b2af32SRussell King 	phydev->link = 0;
39820b2af32SRussell King 	phydev->pause = 0;
39920b2af32SRussell King 	phydev->asym_pause = 0;
400ea4efe25SRussell King 	phydev->mdix = 0;
40120b2af32SRussell King 
40220b2af32SRussell King 	val = phy_read_mmd(phydev, MDIO_MMD_PCS, MV_PCS_BASE_R + MDIO_STAT1);
40320b2af32SRussell King 	if (val < 0)
40420b2af32SRussell King 		return val;
40520b2af32SRussell King 
40620b2af32SRussell King 	if (val & MDIO_STAT1_LSTATUS)
40720b2af32SRussell King 		return mv3310_read_10gbr_status(phydev);
40820b2af32SRussell King 
409998a8a83SHeiner Kallweit 	val = genphy_c45_read_link(phydev);
41020b2af32SRussell King 	if (val < 0)
41120b2af32SRussell King 		return val;
41220b2af32SRussell King 
41320b2af32SRussell King 	val = phy_read_mmd(phydev, MDIO_MMD_AN, MDIO_STAT1);
41420b2af32SRussell King 	if (val < 0)
41520b2af32SRussell King 		return val;
41620b2af32SRussell King 
41720b2af32SRussell King 	if (val & MDIO_AN_STAT1_COMPLETE) {
41820b2af32SRussell King 		val = genphy_c45_read_lpa(phydev);
41920b2af32SRussell King 		if (val < 0)
42020b2af32SRussell King 			return val;
42120b2af32SRussell King 
422cc1122b0SColin Ian King 		/* Read the link partner's 1G advertisement */
42320b2af32SRussell King 		val = phy_read_mmd(phydev, MDIO_MMD_AN, MV_AN_STAT1000);
42420b2af32SRussell King 		if (val < 0)
42520b2af32SRussell King 			return val;
42620b2af32SRussell King 
42778a24df3SAndrew Lunn 		mii_stat1000_mod_linkmode_lpa_t(phydev->lp_advertising, val);
42820b2af32SRussell King 
4296798d03cSRussell King 		if (phydev->autoneg == AUTONEG_ENABLE)
4306798d03cSRussell King 			phy_resolve_aneg_linkmode(phydev);
43120b2af32SRussell King 	}
43220b2af32SRussell King 
43320b2af32SRussell King 	if (phydev->autoneg != AUTONEG_ENABLE) {
43420b2af32SRussell King 		val = genphy_c45_read_pma(phydev);
43520b2af32SRussell King 		if (val < 0)
43620b2af32SRussell King 			return val;
43720b2af32SRussell King 	}
43820b2af32SRussell King 
439ea4efe25SRussell King 	if (phydev->speed == SPEED_10000) {
440ea4efe25SRussell King 		val = genphy_c45_read_mdix(phydev);
441ea4efe25SRussell King 		if (val < 0)
442ea4efe25SRussell King 			return val;
443ea4efe25SRussell King 	} else {
444ea4efe25SRussell King 		val = phy_read_mmd(phydev, MDIO_MMD_PCS, MV_PCS_PAIRSWAP);
445ea4efe25SRussell King 		if (val < 0)
446ea4efe25SRussell King 			return val;
447ea4efe25SRussell King 
448ea4efe25SRussell King 		switch (val & MV_PCS_PAIRSWAP_MASK) {
449ea4efe25SRussell King 		case MV_PCS_PAIRSWAP_AB:
450ea4efe25SRussell King 			phydev->mdix = ETH_TP_MDI_X;
451ea4efe25SRussell King 			break;
452ea4efe25SRussell King 		case MV_PCS_PAIRSWAP_NONE:
453ea4efe25SRussell King 			phydev->mdix = ETH_TP_MDI;
454ea4efe25SRussell King 			break;
455ea4efe25SRussell King 		default:
456ea4efe25SRussell King 			phydev->mdix = ETH_TP_MDI_INVALID;
457ea4efe25SRussell King 			break;
458ea4efe25SRussell King 		}
459ea4efe25SRussell King 	}
460ea4efe25SRussell King 
46136c4449aSRussell King 	mv3310_update_interface(phydev);
46220b2af32SRussell King 
46320b2af32SRussell King 	return 0;
46420b2af32SRussell King }
46520b2af32SRussell King 
46620b2af32SRussell King static struct phy_driver mv3310_drivers[] = {
46720b2af32SRussell King 	{
468631ba906SMaxime Chevallier 		.phy_id		= MARVELL_PHY_ID_88X3310,
469952b6b3bSAntoine Tenart 		.phy_id_mask	= MARVELL_PHY_ID_MASK,
47020b2af32SRussell King 		.name		= "mv88x3310",
47174145424SMaxime Chevallier 		.get_features	= mv3310_get_features,
47256847704SFlorian Fainelli 		.soft_reset	= gen10g_no_soft_reset,
47320b2af32SRussell King 		.config_init	= mv3310_config_init,
4740d3ad854SRussell King 		.probe		= mv3310_probe,
4750d3ad854SRussell King 		.suspend	= mv3310_suspend,
4760d3ad854SRussell King 		.resume		= mv3310_resume,
47720b2af32SRussell King 		.config_aneg	= mv3310_config_aneg,
47820b2af32SRussell King 		.aneg_done	= mv3310_aneg_done,
47920b2af32SRussell King 		.read_status	= mv3310_read_status,
48020b2af32SRussell King 	},
481*62d01535SMaxime Chevallier 	{
482*62d01535SMaxime Chevallier 		.phy_id		= MARVELL_PHY_ID_88E2110,
483*62d01535SMaxime Chevallier 		.phy_id_mask	= MARVELL_PHY_ID_MASK,
484*62d01535SMaxime Chevallier 		.name		= "mv88x2110",
485*62d01535SMaxime Chevallier 		.features	= PHY_10GBIT_FEATURES,
486*62d01535SMaxime Chevallier 		.probe		= mv3310_probe,
487*62d01535SMaxime Chevallier 		.soft_reset	= gen10g_no_soft_reset,
488*62d01535SMaxime Chevallier 		.config_init	= mv3310_config_init,
489*62d01535SMaxime Chevallier 		.config_aneg	= mv3310_config_aneg,
490*62d01535SMaxime Chevallier 		.aneg_done	= mv3310_aneg_done,
491*62d01535SMaxime Chevallier 		.read_status	= mv3310_read_status,
492*62d01535SMaxime Chevallier 	},
49320b2af32SRussell King };
49420b2af32SRussell King 
49520b2af32SRussell King module_phy_driver(mv3310_drivers);
49620b2af32SRussell King 
49720b2af32SRussell King static struct mdio_device_id __maybe_unused mv3310_tbl[] = {
498631ba906SMaxime Chevallier 	{ MARVELL_PHY_ID_88X3310, MARVELL_PHY_ID_MASK },
499*62d01535SMaxime Chevallier 	{ MARVELL_PHY_ID_88E2110, MARVELL_PHY_ID_MASK },
50020b2af32SRussell King 	{ },
50120b2af32SRussell King };
50220b2af32SRussell King MODULE_DEVICE_TABLE(mdio, mv3310_tbl);
50320b2af32SRussell King MODULE_DESCRIPTION("Marvell Alaska X 10Gigabit Ethernet PHY driver (MV88X3310)");
50420b2af32SRussell King MODULE_LICENSE("GPL");
505