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> 268d8963c3SRussell King #include <linux/delay.h> 270d3ad854SRussell King #include <linux/hwmon.h> 28952b6b3bSAntoine Tenart #include <linux/marvell_phy.h> 290d3ad854SRussell King #include <linux/phy.h> 3036023da1SRussell King #include <linux/sfp.h> 3120b2af32SRussell King 32c47455f9SMaxime Chevallier #define MV_PHY_ALASKA_NBT_QUIRK_MASK 0xfffffffe 33c47455f9SMaxime Chevallier #define MV_PHY_ALASKA_NBT_QUIRK_REV (MARVELL_PHY_ID_88X3310 | 0xa) 34c47455f9SMaxime Chevallier 3520b2af32SRussell King enum { 36dd649b4fSRussell King MV_PMA_FW_VER0 = 0xc011, 37dd649b4fSRussell King MV_PMA_FW_VER1 = 0xc012, 389ab0fbd0SMarek Behún MV_PMA_21X0_PORT_CTRL = 0xc04a, 399ab0fbd0SMarek Behún MV_PMA_21X0_PORT_CTRL_SWRST = BIT(15), 409ab0fbd0SMarek Behún MV_PMA_21X0_PORT_CTRL_MACTYPE_MASK = 0x7, 419ab0fbd0SMarek Behún MV_PMA_21X0_PORT_CTRL_MACTYPE_USXGMII = 0x0, 429ab0fbd0SMarek Behún MV_PMA_2180_PORT_CTRL_MACTYPE_DXGMII = 0x1, 439ab0fbd0SMarek Behún MV_PMA_2180_PORT_CTRL_MACTYPE_QXGMII = 0x2, 449ab0fbd0SMarek Behún MV_PMA_21X0_PORT_CTRL_MACTYPE_5GBASER = 0x4, 459ab0fbd0SMarek Behún MV_PMA_21X0_PORT_CTRL_MACTYPE_5GBASER_NO_SGMII_AN = 0x5, 469ab0fbd0SMarek Behún MV_PMA_21X0_PORT_CTRL_MACTYPE_10GBASER_RATE_MATCH = 0x6, 473d3ced2eSRussell King MV_PMA_BOOT = 0xc050, 483d3ced2eSRussell King MV_PMA_BOOT_FATAL = BIT(0), 493d3ced2eSRussell King 5020b2af32SRussell King MV_PCS_BASE_T = 0x0000, 5120b2af32SRussell King MV_PCS_BASE_R = 0x1000, 5220b2af32SRussell King MV_PCS_1000BASEX = 0x2000, 5320b2af32SRussell King 548d8963c3SRussell King MV_PCS_CSCR1 = 0x8000, 55a585c03eSRussell King MV_PCS_CSCR1_ED_MASK = 0x0300, 56a585c03eSRussell King MV_PCS_CSCR1_ED_OFF = 0x0000, 57a585c03eSRussell King MV_PCS_CSCR1_ED_RX = 0x0200, 58a585c03eSRussell King MV_PCS_CSCR1_ED_NLP = 0x0300, 598d8963c3SRussell King MV_PCS_CSCR1_MDIX_MASK = 0x0060, 608d8963c3SRussell King MV_PCS_CSCR1_MDIX_MDI = 0x0000, 618d8963c3SRussell King MV_PCS_CSCR1_MDIX_MDIX = 0x0020, 628d8963c3SRussell King MV_PCS_CSCR1_MDIX_AUTO = 0x0060, 638d8963c3SRussell King 64c84786faSRussell King MV_PCS_CSSR1 = 0x8008, 65c84786faSRussell King MV_PCS_CSSR1_SPD1_MASK = 0xc000, 66c84786faSRussell King MV_PCS_CSSR1_SPD1_SPD2 = 0xc000, 67c84786faSRussell King MV_PCS_CSSR1_SPD1_1000 = 0x8000, 68c84786faSRussell King MV_PCS_CSSR1_SPD1_100 = 0x4000, 69c84786faSRussell King MV_PCS_CSSR1_SPD1_10 = 0x0000, 70c84786faSRussell King MV_PCS_CSSR1_DUPLEX_FULL= BIT(13), 71c84786faSRussell King MV_PCS_CSSR1_RESOLVED = BIT(11), 72c84786faSRussell King MV_PCS_CSSR1_MDIX = BIT(6), 73c84786faSRussell King MV_PCS_CSSR1_SPD2_MASK = 0x000c, 74c84786faSRussell King MV_PCS_CSSR1_SPD2_5000 = 0x0008, 75c84786faSRussell King MV_PCS_CSSR1_SPD2_2500 = 0x0004, 76c84786faSRussell King MV_PCS_CSSR1_SPD2_10000 = 0x0000, 77ea4efe25SRussell King 78c3e302edSBaruch Siach /* Temperature read register (88E2110 only) */ 79c3e302edSBaruch Siach MV_PCS_TEMP = 0x8042, 80c3e302edSBaruch Siach 8120b2af32SRussell King /* These registers appear at 0x800X and 0xa00X - the 0xa00X control 8220b2af32SRussell King * registers appear to set themselves to the 0x800X when AN is 8320b2af32SRussell King * restarted, but status registers appear readable from either. 8420b2af32SRussell King */ 8520b2af32SRussell King MV_AN_CTRL1000 = 0x8000, /* 1000base-T control register */ 8620b2af32SRussell King MV_AN_STAT1000 = 0x8001, /* 1000base-T status register */ 870d3ad854SRussell King 880d3ad854SRussell King /* Vendor2 MMD registers */ 89af3e28cbSAntoine Tenart MV_V2_PORT_CTRL = 0xf001, 908f48c2acSRussell King MV_V2_PORT_CTRL_PWRDOWN = BIT(11), 919893f316SMarek Behún MV_V2_33X0_PORT_CTRL_SWRST = BIT(15), 929893f316SMarek Behún MV_V2_33X0_PORT_CTRL_MACTYPE_MASK = 0x7, 93f8ee45fcSMarek Behún MV_V2_33X0_PORT_CTRL_MACTYPE_RXAUI = 0x0, 94f8ee45fcSMarek Behún MV_V2_3310_PORT_CTRL_MACTYPE_XAUI_RATE_MATCH = 0x1, 95f8ee45fcSMarek Behún MV_V2_3340_PORT_CTRL_MACTYPE_RXAUI_NO_SGMII_AN = 0x1, 96f8ee45fcSMarek Behún MV_V2_33X0_PORT_CTRL_MACTYPE_RXAUI_RATE_MATCH = 0x2, 97f8ee45fcSMarek Behún MV_V2_3310_PORT_CTRL_MACTYPE_XAUI = 0x3, 98f8ee45fcSMarek Behún MV_V2_33X0_PORT_CTRL_MACTYPE_10GBASER = 0x4, 99f8ee45fcSMarek Behún MV_V2_33X0_PORT_CTRL_MACTYPE_10GBASER_NO_SGMII_AN = 0x5, 100f8ee45fcSMarek Behún MV_V2_33X0_PORT_CTRL_MACTYPE_10GBASER_RATE_MATCH = 0x6, 101f8ee45fcSMarek Behún MV_V2_33X0_PORT_CTRL_MACTYPE_USXGMII = 0x7, 102c3e302edSBaruch Siach /* Temperature control/read registers (88X3310 only) */ 1030d3ad854SRussell King MV_V2_TEMP_CTRL = 0xf08a, 1040d3ad854SRussell King MV_V2_TEMP_CTRL_MASK = 0xc000, 1050d3ad854SRussell King MV_V2_TEMP_CTRL_SAMPLE = 0x0000, 1060d3ad854SRussell King MV_V2_TEMP_CTRL_DISABLE = 0xc000, 1070d3ad854SRussell King MV_V2_TEMP = 0xf08c, 1080d3ad854SRussell King MV_V2_TEMP_UNKNOWN = 0x9600, /* unknown function */ 1090d3ad854SRussell King }; 1100d3ad854SRussell King 11197bbe3bdSMarek Behún struct mv3310_chip { 112261a74c6SMarek Behún void (*init_supported_interfaces)(unsigned long *mask); 11397bbe3bdSMarek Behún int (*get_mactype)(struct phy_device *phydev); 11497bbe3bdSMarek Behún int (*init_interface)(struct phy_device *phydev, int mactype); 115884d9a67SMarek Behún 116884d9a67SMarek Behún #ifdef CONFIG_HWMON 117884d9a67SMarek Behún int (*hwmon_read_temp_reg)(struct phy_device *phydev); 118884d9a67SMarek Behún #endif 11997bbe3bdSMarek Behún }; 12097bbe3bdSMarek Behún 1210d3ad854SRussell King struct mv3310_priv { 122261a74c6SMarek Behún DECLARE_BITMAP(supported_interfaces, PHY_INTERFACE_MODE_MAX); 123261a74c6SMarek Behún 124dd649b4fSRussell King u32 firmware_ver; 125e1170333SBaruch Siach bool rate_match; 12697bbe3bdSMarek Behún phy_interface_t const_interface; 127dd649b4fSRussell King 1280d3ad854SRussell King struct device *hwmon_dev; 1290d3ad854SRussell King char *hwmon_name; 13020b2af32SRussell King }; 13120b2af32SRussell King 13297bbe3bdSMarek Behún static const struct mv3310_chip *to_mv3310_chip(struct phy_device *phydev) 13397bbe3bdSMarek Behún { 13497bbe3bdSMarek Behún return phydev->drv->driver_data; 13597bbe3bdSMarek Behún } 13697bbe3bdSMarek Behún 1370d3ad854SRussell King #ifdef CONFIG_HWMON 1380d3ad854SRussell King static umode_t mv3310_hwmon_is_visible(const void *data, 1390d3ad854SRussell King enum hwmon_sensor_types type, 1400d3ad854SRussell King u32 attr, int channel) 1410d3ad854SRussell King { 1420d3ad854SRussell King if (type == hwmon_chip && attr == hwmon_chip_update_interval) 1430d3ad854SRussell King return 0444; 1440d3ad854SRussell King if (type == hwmon_temp && attr == hwmon_temp_input) 1450d3ad854SRussell King return 0444; 1460d3ad854SRussell King return 0; 1470d3ad854SRussell King } 1480d3ad854SRussell King 149c3e302edSBaruch Siach static int mv3310_hwmon_read_temp_reg(struct phy_device *phydev) 150c3e302edSBaruch Siach { 151c3e302edSBaruch Siach return phy_read_mmd(phydev, MDIO_MMD_VEND2, MV_V2_TEMP); 152c3e302edSBaruch Siach } 153c3e302edSBaruch Siach 154c3e302edSBaruch Siach static int mv2110_hwmon_read_temp_reg(struct phy_device *phydev) 155c3e302edSBaruch Siach { 156c3e302edSBaruch Siach return phy_read_mmd(phydev, MDIO_MMD_PCS, MV_PCS_TEMP); 157c3e302edSBaruch Siach } 158c3e302edSBaruch Siach 1590d3ad854SRussell King static int mv3310_hwmon_read(struct device *dev, enum hwmon_sensor_types type, 1600d3ad854SRussell King u32 attr, int channel, long *value) 1610d3ad854SRussell King { 1620d3ad854SRussell King struct phy_device *phydev = dev_get_drvdata(dev); 163884d9a67SMarek Behún const struct mv3310_chip *chip = to_mv3310_chip(phydev); 1640d3ad854SRussell King int temp; 1650d3ad854SRussell King 1660d3ad854SRussell King if (type == hwmon_chip && attr == hwmon_chip_update_interval) { 1670d3ad854SRussell King *value = MSEC_PER_SEC; 1680d3ad854SRussell King return 0; 1690d3ad854SRussell King } 1700d3ad854SRussell King 1710d3ad854SRussell King if (type == hwmon_temp && attr == hwmon_temp_input) { 172884d9a67SMarek Behún temp = chip->hwmon_read_temp_reg(phydev); 1730d3ad854SRussell King if (temp < 0) 1740d3ad854SRussell King return temp; 1750d3ad854SRussell King 1760d3ad854SRussell King *value = ((temp & 0xff) - 75) * 1000; 1770d3ad854SRussell King 1780d3ad854SRussell King return 0; 1790d3ad854SRussell King } 1800d3ad854SRussell King 1810d3ad854SRussell King return -EOPNOTSUPP; 1820d3ad854SRussell King } 1830d3ad854SRussell King 1840d3ad854SRussell King static const struct hwmon_ops mv3310_hwmon_ops = { 1850d3ad854SRussell King .is_visible = mv3310_hwmon_is_visible, 1860d3ad854SRussell King .read = mv3310_hwmon_read, 1870d3ad854SRussell King }; 1880d3ad854SRussell King 1890d3ad854SRussell King static u32 mv3310_hwmon_chip_config[] = { 1900d3ad854SRussell King HWMON_C_REGISTER_TZ | HWMON_C_UPDATE_INTERVAL, 1910d3ad854SRussell King 0, 1920d3ad854SRussell King }; 1930d3ad854SRussell King 1940d3ad854SRussell King static const struct hwmon_channel_info mv3310_hwmon_chip = { 1950d3ad854SRussell King .type = hwmon_chip, 1960d3ad854SRussell King .config = mv3310_hwmon_chip_config, 1970d3ad854SRussell King }; 1980d3ad854SRussell King 1990d3ad854SRussell King static u32 mv3310_hwmon_temp_config[] = { 2000d3ad854SRussell King HWMON_T_INPUT, 2010d3ad854SRussell King 0, 2020d3ad854SRussell King }; 2030d3ad854SRussell King 2040d3ad854SRussell King static const struct hwmon_channel_info mv3310_hwmon_temp = { 2050d3ad854SRussell King .type = hwmon_temp, 2060d3ad854SRussell King .config = mv3310_hwmon_temp_config, 2070d3ad854SRussell King }; 2080d3ad854SRussell King 2090d3ad854SRussell King static const struct hwmon_channel_info *mv3310_hwmon_info[] = { 2100d3ad854SRussell King &mv3310_hwmon_chip, 2110d3ad854SRussell King &mv3310_hwmon_temp, 2120d3ad854SRussell King NULL, 2130d3ad854SRussell King }; 2140d3ad854SRussell King 2150d3ad854SRussell King static const struct hwmon_chip_info mv3310_hwmon_chip_info = { 2160d3ad854SRussell King .ops = &mv3310_hwmon_ops, 2170d3ad854SRussell King .info = mv3310_hwmon_info, 2180d3ad854SRussell King }; 2190d3ad854SRussell King 2200d3ad854SRussell King static int mv3310_hwmon_config(struct phy_device *phydev, bool enable) 2210d3ad854SRussell King { 2220d3ad854SRussell King u16 val; 2230d3ad854SRussell King int ret; 2240d3ad854SRussell King 225c3e302edSBaruch Siach if (phydev->drv->phy_id != MARVELL_PHY_ID_88X3310) 226c3e302edSBaruch Siach return 0; 227c3e302edSBaruch Siach 2280d3ad854SRussell King ret = phy_write_mmd(phydev, MDIO_MMD_VEND2, MV_V2_TEMP, 2290d3ad854SRussell King MV_V2_TEMP_UNKNOWN); 2300d3ad854SRussell King if (ret < 0) 2310d3ad854SRussell King return ret; 2320d3ad854SRussell King 2330d3ad854SRussell King val = enable ? MV_V2_TEMP_CTRL_SAMPLE : MV_V2_TEMP_CTRL_DISABLE; 2340d3ad854SRussell King 235b06d8e5aSHeiner Kallweit return phy_modify_mmd(phydev, MDIO_MMD_VEND2, MV_V2_TEMP_CTRL, 236b06d8e5aSHeiner Kallweit MV_V2_TEMP_CTRL_MASK, val); 2370d3ad854SRussell King } 2380d3ad854SRussell King 2390d3ad854SRussell King static int mv3310_hwmon_probe(struct phy_device *phydev) 2400d3ad854SRussell King { 2410d3ad854SRussell King struct device *dev = &phydev->mdio.dev; 2420d3ad854SRussell King struct mv3310_priv *priv = dev_get_drvdata(&phydev->mdio.dev); 2430d3ad854SRussell King int i, j, ret; 2440d3ad854SRussell King 2450d3ad854SRussell King priv->hwmon_name = devm_kstrdup(dev, dev_name(dev), GFP_KERNEL); 2460d3ad854SRussell King if (!priv->hwmon_name) 2470d3ad854SRussell King return -ENODEV; 2480d3ad854SRussell King 2490d3ad854SRussell King for (i = j = 0; priv->hwmon_name[i]; i++) { 2500d3ad854SRussell King if (isalnum(priv->hwmon_name[i])) { 2510d3ad854SRussell King if (i != j) 2520d3ad854SRussell King priv->hwmon_name[j] = priv->hwmon_name[i]; 2530d3ad854SRussell King j++; 2540d3ad854SRussell King } 2550d3ad854SRussell King } 2560d3ad854SRussell King priv->hwmon_name[j] = '\0'; 2570d3ad854SRussell King 2580d3ad854SRussell King ret = mv3310_hwmon_config(phydev, true); 2590d3ad854SRussell King if (ret) 2600d3ad854SRussell King return ret; 2610d3ad854SRussell King 2620d3ad854SRussell King priv->hwmon_dev = devm_hwmon_device_register_with_info(dev, 2630d3ad854SRussell King priv->hwmon_name, phydev, 2640d3ad854SRussell King &mv3310_hwmon_chip_info, NULL); 2650d3ad854SRussell King 2660d3ad854SRussell King return PTR_ERR_OR_ZERO(priv->hwmon_dev); 2670d3ad854SRussell King } 2680d3ad854SRussell King #else 2690d3ad854SRussell King static inline int mv3310_hwmon_config(struct phy_device *phydev, bool enable) 2700d3ad854SRussell King { 2710d3ad854SRussell King return 0; 2720d3ad854SRussell King } 2730d3ad854SRussell King 2740d3ad854SRussell King static int mv3310_hwmon_probe(struct phy_device *phydev) 2750d3ad854SRussell King { 2760d3ad854SRussell King return 0; 2770d3ad854SRussell King } 2780d3ad854SRussell King #endif 2790d3ad854SRussell King 280c9cc1c81SRussell King static int mv3310_power_down(struct phy_device *phydev) 281c9cc1c81SRussell King { 282c9cc1c81SRussell King return phy_set_bits_mmd(phydev, MDIO_MMD_VEND2, MV_V2_PORT_CTRL, 283c9cc1c81SRussell King MV_V2_PORT_CTRL_PWRDOWN); 284c9cc1c81SRussell King } 285c9cc1c81SRussell King 286c9cc1c81SRussell King static int mv3310_power_up(struct phy_device *phydev) 287c9cc1c81SRussell King { 2888f48c2acSRussell King struct mv3310_priv *priv = dev_get_drvdata(&phydev->mdio.dev); 2898f48c2acSRussell King int ret; 2908f48c2acSRussell King 2918f48c2acSRussell King ret = phy_clear_bits_mmd(phydev, MDIO_MMD_VEND2, MV_V2_PORT_CTRL, 292c9cc1c81SRussell King MV_V2_PORT_CTRL_PWRDOWN); 2938f48c2acSRussell King 294829e7573SBaruch Siach if (phydev->drv->phy_id != MARVELL_PHY_ID_88X3310 || 295829e7573SBaruch Siach priv->firmware_ver < 0x00030000) 2968f48c2acSRussell King return ret; 2978f48c2acSRussell King 2988f48c2acSRussell King return phy_set_bits_mmd(phydev, MDIO_MMD_VEND2, MV_V2_PORT_CTRL, 2999893f316SMarek Behún MV_V2_33X0_PORT_CTRL_SWRST); 300c9cc1c81SRussell King } 301c9cc1c81SRussell King 3028d8963c3SRussell King static int mv3310_reset(struct phy_device *phydev, u32 unit) 3038d8963c3SRussell King { 3048964a217SDejin Zheng int val, err; 3058d8963c3SRussell King 3068d8963c3SRussell King err = phy_modify_mmd(phydev, MDIO_MMD_PCS, unit + MDIO_CTRL1, 3078d8963c3SRussell King MDIO_CTRL1_RESET, MDIO_CTRL1_RESET); 3088d8963c3SRussell King if (err < 0) 3098d8963c3SRussell King return err; 3108d8963c3SRussell King 3118964a217SDejin Zheng return phy_read_mmd_poll_timeout(phydev, MDIO_MMD_PCS, 3128964a217SDejin Zheng unit + MDIO_CTRL1, val, 3138964a217SDejin Zheng !(val & MDIO_CTRL1_RESET), 3148964a217SDejin Zheng 5000, 100000, true); 3158d8963c3SRussell King } 3168d8963c3SRussell King 317a585c03eSRussell King static int mv3310_get_edpd(struct phy_device *phydev, u16 *edpd) 318a585c03eSRussell King { 319a585c03eSRussell King int val; 320a585c03eSRussell King 321a585c03eSRussell King val = phy_read_mmd(phydev, MDIO_MMD_PCS, MV_PCS_CSCR1); 322a585c03eSRussell King if (val < 0) 323a585c03eSRussell King return val; 324a585c03eSRussell King 325a585c03eSRussell King switch (val & MV_PCS_CSCR1_ED_MASK) { 326a585c03eSRussell King case MV_PCS_CSCR1_ED_NLP: 327a585c03eSRussell King *edpd = 1000; 328a585c03eSRussell King break; 329a585c03eSRussell King case MV_PCS_CSCR1_ED_RX: 330a585c03eSRussell King *edpd = ETHTOOL_PHY_EDPD_NO_TX; 331a585c03eSRussell King break; 332a585c03eSRussell King default: 333a585c03eSRussell King *edpd = ETHTOOL_PHY_EDPD_DISABLE; 334a585c03eSRussell King break; 335a585c03eSRussell King } 336a585c03eSRussell King return 0; 337a585c03eSRussell King } 338a585c03eSRussell King 339a585c03eSRussell King static int mv3310_set_edpd(struct phy_device *phydev, u16 edpd) 340a585c03eSRussell King { 341a585c03eSRussell King u16 val; 342a585c03eSRussell King int err; 343a585c03eSRussell King 344a585c03eSRussell King switch (edpd) { 345a585c03eSRussell King case 1000: 346a585c03eSRussell King case ETHTOOL_PHY_EDPD_DFLT_TX_MSECS: 347a585c03eSRussell King val = MV_PCS_CSCR1_ED_NLP; 348a585c03eSRussell King break; 349a585c03eSRussell King 350a585c03eSRussell King case ETHTOOL_PHY_EDPD_NO_TX: 351a585c03eSRussell King val = MV_PCS_CSCR1_ED_RX; 352a585c03eSRussell King break; 353a585c03eSRussell King 354a585c03eSRussell King case ETHTOOL_PHY_EDPD_DISABLE: 355a585c03eSRussell King val = MV_PCS_CSCR1_ED_OFF; 356a585c03eSRussell King break; 357a585c03eSRussell King 358a585c03eSRussell King default: 359a585c03eSRussell King return -EINVAL; 360a585c03eSRussell King } 361a585c03eSRussell King 362a585c03eSRussell King err = phy_modify_mmd_changed(phydev, MDIO_MMD_PCS, MV_PCS_CSCR1, 363a585c03eSRussell King MV_PCS_CSCR1_ED_MASK, val); 364a585c03eSRussell King if (err > 0) 365a585c03eSRussell King err = mv3310_reset(phydev, MV_PCS_BASE_T); 366a585c03eSRussell King 367a585c03eSRussell King return err; 368a585c03eSRussell King } 369a585c03eSRussell King 37036023da1SRussell King static int mv3310_sfp_insert(void *upstream, const struct sfp_eeprom_id *id) 37136023da1SRussell King { 37236023da1SRussell King struct phy_device *phydev = upstream; 37336023da1SRussell King __ETHTOOL_DECLARE_LINK_MODE_MASK(support) = { 0, }; 37436023da1SRussell King phy_interface_t iface; 37536023da1SRussell King 37636023da1SRussell King sfp_parse_support(phydev->sfp_bus, id, support); 377a4516c70SRussell King iface = sfp_select_interface(phydev->sfp_bus, support); 37836023da1SRussell King 379e0f909bcSRussell King if (iface != PHY_INTERFACE_MODE_10GBASER) { 38036023da1SRussell King dev_err(&phydev->mdio.dev, "incompatible SFP module inserted\n"); 38136023da1SRussell King return -EINVAL; 38236023da1SRussell King } 38336023da1SRussell King return 0; 38436023da1SRussell King } 38536023da1SRussell King 38636023da1SRussell King static const struct sfp_upstream_ops mv3310_sfp_ops = { 38736023da1SRussell King .attach = phy_sfp_attach, 38836023da1SRussell King .detach = phy_sfp_detach, 38936023da1SRussell King .module_insert = mv3310_sfp_insert, 39036023da1SRussell King }; 39136023da1SRussell King 39220b2af32SRussell King static int mv3310_probe(struct phy_device *phydev) 39320b2af32SRussell King { 394261a74c6SMarek Behún const struct mv3310_chip *chip = to_mv3310_chip(phydev); 3950d3ad854SRussell King struct mv3310_priv *priv; 39620b2af32SRussell King u32 mmd_mask = MDIO_DEVS_PMAPMD | MDIO_DEVS_AN; 3970d3ad854SRussell King int ret; 39820b2af32SRussell King 39920b2af32SRussell King if (!phydev->is_c45 || 40020b2af32SRussell King (phydev->c45_ids.devices_in_package & mmd_mask) != mmd_mask) 40120b2af32SRussell King return -ENODEV; 40220b2af32SRussell King 4033d3ced2eSRussell King ret = phy_read_mmd(phydev, MDIO_MMD_PMAPMD, MV_PMA_BOOT); 4043d3ced2eSRussell King if (ret < 0) 4053d3ced2eSRussell King return ret; 4063d3ced2eSRussell King 4073d3ced2eSRussell King if (ret & MV_PMA_BOOT_FATAL) { 4083d3ced2eSRussell King dev_warn(&phydev->mdio.dev, 4093d3ced2eSRussell King "PHY failed to boot firmware, status=%04x\n", ret); 4103d3ced2eSRussell King return -ENODEV; 4113d3ced2eSRussell King } 4123d3ced2eSRussell King 4130d3ad854SRussell King priv = devm_kzalloc(&phydev->mdio.dev, sizeof(*priv), GFP_KERNEL); 4140d3ad854SRussell King if (!priv) 4150d3ad854SRussell King return -ENOMEM; 4160d3ad854SRussell King 4170d3ad854SRussell King dev_set_drvdata(&phydev->mdio.dev, priv); 4180d3ad854SRussell King 419dd649b4fSRussell King ret = phy_read_mmd(phydev, MDIO_MMD_PMAPMD, MV_PMA_FW_VER0); 420dd649b4fSRussell King if (ret < 0) 421dd649b4fSRussell King return ret; 422dd649b4fSRussell King 423dd649b4fSRussell King priv->firmware_ver = ret << 16; 424dd649b4fSRussell King 425dd649b4fSRussell King ret = phy_read_mmd(phydev, MDIO_MMD_PMAPMD, MV_PMA_FW_VER1); 426dd649b4fSRussell King if (ret < 0) 427dd649b4fSRussell King return ret; 428dd649b4fSRussell King 429dd649b4fSRussell King priv->firmware_ver |= ret; 430dd649b4fSRussell King 431dd649b4fSRussell King phydev_info(phydev, "Firmware version %u.%u.%u.%u\n", 432dd649b4fSRussell King priv->firmware_ver >> 24, (priv->firmware_ver >> 16) & 255, 433dd649b4fSRussell King (priv->firmware_ver >> 8) & 255, priv->firmware_ver & 255); 434dd649b4fSRussell King 435c9cc1c81SRussell King /* Powering down the port when not in use saves about 600mW */ 436c9cc1c81SRussell King ret = mv3310_power_down(phydev); 437c9cc1c81SRussell King if (ret) 438c9cc1c81SRussell King return ret; 439c9cc1c81SRussell King 4400d3ad854SRussell King ret = mv3310_hwmon_probe(phydev); 4410d3ad854SRussell King if (ret) 4420d3ad854SRussell King return ret; 4430d3ad854SRussell King 444261a74c6SMarek Behún chip->init_supported_interfaces(priv->supported_interfaces); 445261a74c6SMarek Behún 44636023da1SRussell King return phy_sfp_probe(phydev, &mv3310_sfp_ops); 44720b2af32SRussell King } 44820b2af32SRussell King 4491b8ef142SMarek Behún static void mv3310_remove(struct phy_device *phydev) 4501b8ef142SMarek Behún { 4511b8ef142SMarek Behún mv3310_hwmon_config(phydev, false); 4521b8ef142SMarek Behún } 4531b8ef142SMarek Behún 4540d3ad854SRussell King static int mv3310_suspend(struct phy_device *phydev) 4550d3ad854SRussell King { 456c9cc1c81SRussell King return mv3310_power_down(phydev); 4570d3ad854SRussell King } 4580d3ad854SRussell King 4590d3ad854SRussell King static int mv3310_resume(struct phy_device *phydev) 4600d3ad854SRussell King { 461af3e28cbSAntoine Tenart int ret; 462af3e28cbSAntoine Tenart 463c9cc1c81SRussell King ret = mv3310_power_up(phydev); 464af3e28cbSAntoine Tenart if (ret) 465af3e28cbSAntoine Tenart return ret; 466af3e28cbSAntoine Tenart 4670d3ad854SRussell King return mv3310_hwmon_config(phydev, true); 4680d3ad854SRussell King } 4690d3ad854SRussell King 470c47455f9SMaxime Chevallier /* Some PHYs in the Alaska family such as the 88X3310 and the 88E2010 471c47455f9SMaxime Chevallier * don't set bit 14 in PMA Extended Abilities (1.11), although they do 472c47455f9SMaxime Chevallier * support 2.5GBASET and 5GBASET. For these models, we can still read their 473c47455f9SMaxime Chevallier * 2.5G/5G extended abilities register (1.21). We detect these models based on 474c47455f9SMaxime Chevallier * the PMA device identifier, with a mask matching models known to have this 475c47455f9SMaxime Chevallier * issue 476c47455f9SMaxime Chevallier */ 477c47455f9SMaxime Chevallier static bool mv3310_has_pma_ngbaset_quirk(struct phy_device *phydev) 478c47455f9SMaxime Chevallier { 479c47455f9SMaxime Chevallier if (!(phydev->c45_ids.devices_in_package & MDIO_DEVS_PMAPMD)) 480c47455f9SMaxime Chevallier return false; 481c47455f9SMaxime Chevallier 482c47455f9SMaxime Chevallier /* Only some revisions of the 88X3310 family PMA seem to be impacted */ 483c47455f9SMaxime Chevallier return (phydev->c45_ids.device_ids[MDIO_MMD_PMAPMD] & 484c47455f9SMaxime Chevallier MV_PHY_ALASKA_NBT_QUIRK_MASK) == MV_PHY_ALASKA_NBT_QUIRK_REV; 485c47455f9SMaxime Chevallier } 486c47455f9SMaxime Chevallier 48797bbe3bdSMarek Behún static int mv2110_get_mactype(struct phy_device *phydev) 48897bbe3bdSMarek Behún { 48997bbe3bdSMarek Behún int mactype; 49097bbe3bdSMarek Behún 49197bbe3bdSMarek Behún mactype = phy_read_mmd(phydev, MDIO_MMD_PMAPMD, MV_PMA_21X0_PORT_CTRL); 49297bbe3bdSMarek Behún if (mactype < 0) 49397bbe3bdSMarek Behún return mactype; 49497bbe3bdSMarek Behún 49597bbe3bdSMarek Behún return mactype & MV_PMA_21X0_PORT_CTRL_MACTYPE_MASK; 49697bbe3bdSMarek Behún } 49797bbe3bdSMarek Behún 49897bbe3bdSMarek Behún static int mv3310_get_mactype(struct phy_device *phydev) 49997bbe3bdSMarek Behún { 50097bbe3bdSMarek Behún int mactype; 50197bbe3bdSMarek Behún 50297bbe3bdSMarek Behún mactype = phy_read_mmd(phydev, MDIO_MMD_VEND2, MV_V2_PORT_CTRL); 50397bbe3bdSMarek Behún if (mactype < 0) 50497bbe3bdSMarek Behún return mactype; 50597bbe3bdSMarek Behún 50697bbe3bdSMarek Behún return mactype & MV_V2_33X0_PORT_CTRL_MACTYPE_MASK; 50797bbe3bdSMarek Behún } 50897bbe3bdSMarek Behún 50997bbe3bdSMarek Behún static int mv2110_init_interface(struct phy_device *phydev, int mactype) 51020b2af32SRussell King { 511e1170333SBaruch Siach struct mv3310_priv *priv = dev_get_drvdata(&phydev->mdio.dev); 51297bbe3bdSMarek Behún 51397bbe3bdSMarek Behún priv->rate_match = false; 51497bbe3bdSMarek Behún 515*ccbf2891SMarek Behún if (mactype == MV_PMA_21X0_PORT_CTRL_MACTYPE_10GBASER_RATE_MATCH) 51697bbe3bdSMarek Behún priv->rate_match = true; 517*ccbf2891SMarek Behún 518*ccbf2891SMarek Behún if (mactype == MV_PMA_21X0_PORT_CTRL_MACTYPE_USXGMII) 519*ccbf2891SMarek Behún priv->const_interface = PHY_INTERFACE_MODE_USXGMII; 520*ccbf2891SMarek Behún else if (mactype == MV_PMA_21X0_PORT_CTRL_MACTYPE_10GBASER_RATE_MATCH) 52197bbe3bdSMarek Behún priv->const_interface = PHY_INTERFACE_MODE_10GBASER; 522*ccbf2891SMarek Behún else if (mactype == MV_PMA_21X0_PORT_CTRL_MACTYPE_5GBASER || 523*ccbf2891SMarek Behún mactype == MV_PMA_21X0_PORT_CTRL_MACTYPE_5GBASER_NO_SGMII_AN) 524*ccbf2891SMarek Behún priv->const_interface = PHY_INTERFACE_MODE_NA; 525*ccbf2891SMarek Behún else 526*ccbf2891SMarek Behún return -EINVAL; 52797bbe3bdSMarek Behún 52897bbe3bdSMarek Behún return 0; 52997bbe3bdSMarek Behún } 53097bbe3bdSMarek Behún 53197bbe3bdSMarek Behún static int mv3310_init_interface(struct phy_device *phydev, int mactype) 53297bbe3bdSMarek Behún { 53397bbe3bdSMarek Behún struct mv3310_priv *priv = dev_get_drvdata(&phydev->mdio.dev); 53497bbe3bdSMarek Behún 53597bbe3bdSMarek Behún priv->rate_match = false; 53697bbe3bdSMarek Behún 53797bbe3bdSMarek Behún if (mactype == MV_V2_33X0_PORT_CTRL_MACTYPE_10GBASER_RATE_MATCH || 53897bbe3bdSMarek Behún mactype == MV_V2_33X0_PORT_CTRL_MACTYPE_RXAUI_RATE_MATCH || 53997bbe3bdSMarek Behún mactype == MV_V2_3310_PORT_CTRL_MACTYPE_XAUI_RATE_MATCH) 54097bbe3bdSMarek Behún priv->rate_match = true; 54197bbe3bdSMarek Behún 542*ccbf2891SMarek Behún if (mactype == MV_V2_33X0_PORT_CTRL_MACTYPE_USXGMII) 543*ccbf2891SMarek Behún priv->const_interface = PHY_INTERFACE_MODE_USXGMII; 544*ccbf2891SMarek Behún else if (mactype == MV_V2_33X0_PORT_CTRL_MACTYPE_10GBASER_RATE_MATCH || 545*ccbf2891SMarek Behún mactype == MV_V2_33X0_PORT_CTRL_MACTYPE_10GBASER_NO_SGMII_AN || 546*ccbf2891SMarek Behún mactype == MV_V2_33X0_PORT_CTRL_MACTYPE_10GBASER) 54797bbe3bdSMarek Behún priv->const_interface = PHY_INTERFACE_MODE_10GBASER; 548*ccbf2891SMarek Behún else if (mactype == MV_V2_33X0_PORT_CTRL_MACTYPE_RXAUI_RATE_MATCH || 549*ccbf2891SMarek Behún mactype == MV_V2_33X0_PORT_CTRL_MACTYPE_RXAUI) 55097bbe3bdSMarek Behún priv->const_interface = PHY_INTERFACE_MODE_RXAUI; 551*ccbf2891SMarek Behún else if (mactype == MV_V2_3310_PORT_CTRL_MACTYPE_XAUI_RATE_MATCH || 552*ccbf2891SMarek Behún mactype == MV_V2_3310_PORT_CTRL_MACTYPE_XAUI) 55397bbe3bdSMarek Behún priv->const_interface = PHY_INTERFACE_MODE_XAUI; 554*ccbf2891SMarek Behún else 555*ccbf2891SMarek Behún return -EINVAL; 55697bbe3bdSMarek Behún 55797bbe3bdSMarek Behún return 0; 55897bbe3bdSMarek Behún } 55997bbe3bdSMarek Behún 56097bbe3bdSMarek Behún static int mv3310_config_init(struct phy_device *phydev) 56197bbe3bdSMarek Behún { 562261a74c6SMarek Behún struct mv3310_priv *priv = dev_get_drvdata(&phydev->mdio.dev); 56397bbe3bdSMarek Behún const struct mv3310_chip *chip = to_mv3310_chip(phydev); 56497bbe3bdSMarek Behún int err, mactype; 565c9cc1c81SRussell King 56620b2af32SRussell King /* Check that the PHY interface type is compatible */ 567261a74c6SMarek Behún if (!test_bit(phydev->interface, priv->supported_interfaces)) 56820b2af32SRussell King return -ENODEV; 56920b2af32SRussell King 5708d8963c3SRussell King phydev->mdix_ctrl = ETH_TP_MDI_AUTO; 5718d8963c3SRussell King 572c9cc1c81SRussell King /* Power up so reset works */ 573c9cc1c81SRussell King err = mv3310_power_up(phydev); 574c9cc1c81SRussell King if (err) 575c9cc1c81SRussell King return err; 576c9cc1c81SRussell King 57797bbe3bdSMarek Behún mactype = chip->get_mactype(phydev); 57897bbe3bdSMarek Behún if (mactype < 0) 57997bbe3bdSMarek Behún return mactype; 58097bbe3bdSMarek Behún 58197bbe3bdSMarek Behún err = chip->init_interface(phydev, mactype); 582*ccbf2891SMarek Behún if (err) { 583*ccbf2891SMarek Behún phydev_err(phydev, "MACTYPE configuration invalid\n"); 58497bbe3bdSMarek Behún return err; 585*ccbf2891SMarek Behún } 586e1170333SBaruch Siach 587a585c03eSRussell King /* Enable EDPD mode - saving 600mW */ 588a585c03eSRussell King return mv3310_set_edpd(phydev, ETHTOOL_PHY_EDPD_DFLT_TX_MSECS); 58974145424SMaxime Chevallier } 59074145424SMaxime Chevallier 59174145424SMaxime Chevallier static int mv3310_get_features(struct phy_device *phydev) 59274145424SMaxime Chevallier { 59374145424SMaxime Chevallier int ret, val; 59474145424SMaxime Chevallier 595ac3f5533SMaxime Chevallier ret = genphy_c45_pma_read_abilities(phydev); 596ac3f5533SMaxime Chevallier if (ret) 597ac3f5533SMaxime Chevallier return ret; 59820b2af32SRussell King 599c47455f9SMaxime Chevallier if (mv3310_has_pma_ngbaset_quirk(phydev)) { 600c47455f9SMaxime Chevallier val = phy_read_mmd(phydev, MDIO_MMD_PMAPMD, 601c47455f9SMaxime Chevallier MDIO_PMA_NG_EXTABLE); 602c47455f9SMaxime Chevallier if (val < 0) 603c47455f9SMaxime Chevallier return val; 604c47455f9SMaxime Chevallier 605c47455f9SMaxime Chevallier linkmode_mod_bit(ETHTOOL_LINK_MODE_2500baseT_Full_BIT, 606c47455f9SMaxime Chevallier phydev->supported, 607c47455f9SMaxime Chevallier val & MDIO_PMA_NG_EXTABLE_2_5GBT); 608c47455f9SMaxime Chevallier 609c47455f9SMaxime Chevallier linkmode_mod_bit(ETHTOOL_LINK_MODE_5000baseT_Full_BIT, 610c47455f9SMaxime Chevallier phydev->supported, 611c47455f9SMaxime Chevallier val & MDIO_PMA_NG_EXTABLE_5GBT); 612c47455f9SMaxime Chevallier } 613c47455f9SMaxime Chevallier 61420b2af32SRussell King return 0; 61520b2af32SRussell King } 61620b2af32SRussell King 6178d8963c3SRussell King static int mv3310_config_mdix(struct phy_device *phydev) 6188d8963c3SRussell King { 6198d8963c3SRussell King u16 val; 6208d8963c3SRussell King int err; 6218d8963c3SRussell King 6228d8963c3SRussell King switch (phydev->mdix_ctrl) { 6238d8963c3SRussell King case ETH_TP_MDI_AUTO: 6248d8963c3SRussell King val = MV_PCS_CSCR1_MDIX_AUTO; 6258d8963c3SRussell King break; 6268d8963c3SRussell King case ETH_TP_MDI_X: 6278d8963c3SRussell King val = MV_PCS_CSCR1_MDIX_MDIX; 6288d8963c3SRussell King break; 6298d8963c3SRussell King case ETH_TP_MDI: 6308d8963c3SRussell King val = MV_PCS_CSCR1_MDIX_MDI; 6318d8963c3SRussell King break; 6328d8963c3SRussell King default: 6338d8963c3SRussell King return -EINVAL; 6348d8963c3SRussell King } 6358d8963c3SRussell King 6368d8963c3SRussell King err = phy_modify_mmd_changed(phydev, MDIO_MMD_PCS, MV_PCS_CSCR1, 6378d8963c3SRussell King MV_PCS_CSCR1_MDIX_MASK, val); 6388d8963c3SRussell King if (err > 0) 6398d8963c3SRussell King err = mv3310_reset(phydev, MV_PCS_BASE_T); 6408d8963c3SRussell King 6418d8963c3SRussell King return err; 6428d8963c3SRussell King } 6438d8963c3SRussell King 64420b2af32SRussell King static int mv3310_config_aneg(struct phy_device *phydev) 64520b2af32SRussell King { 64620b2af32SRussell King bool changed = false; 6473c1bcc86SAndrew Lunn u16 reg; 64820b2af32SRussell King int ret; 64920b2af32SRussell King 6508d8963c3SRussell King ret = mv3310_config_mdix(phydev); 6518d8963c3SRussell King if (ret < 0) 6528d8963c3SRussell King return ret; 653ea4efe25SRussell King 65430de65c3SHeiner Kallweit if (phydev->autoneg == AUTONEG_DISABLE) 65530de65c3SHeiner Kallweit return genphy_c45_pma_setup_forced(phydev); 65620b2af32SRussell King 6573de97f3cSAndrew Lunn ret = genphy_c45_an_config_aneg(phydev); 65820b2af32SRussell King if (ret < 0) 65920b2af32SRussell King return ret; 66020b2af32SRussell King if (ret > 0) 66120b2af32SRussell King changed = true; 66220b2af32SRussell King 6633de97f3cSAndrew Lunn /* Clause 45 has no standardized support for 1000BaseT, therefore 6643de97f3cSAndrew Lunn * use vendor registers for this mode. 6653de97f3cSAndrew Lunn */ 6663c1bcc86SAndrew Lunn reg = linkmode_adv_to_mii_ctrl1000_t(phydev->advertising); 667b06d8e5aSHeiner Kallweit ret = phy_modify_mmd_changed(phydev, MDIO_MMD_AN, MV_AN_CTRL1000, 6683c1bcc86SAndrew Lunn ADVERTISE_1000FULL | ADVERTISE_1000HALF, reg); 66920b2af32SRussell King if (ret < 0) 67020b2af32SRussell King return ret; 67120b2af32SRussell King if (ret > 0) 67220b2af32SRussell King changed = true; 67320b2af32SRussell King 6746b4cb6cbSHeiner Kallweit return genphy_c45_check_and_restart_aneg(phydev, changed); 67520b2af32SRussell King } 67620b2af32SRussell King 67720b2af32SRussell King static int mv3310_aneg_done(struct phy_device *phydev) 67820b2af32SRussell King { 67920b2af32SRussell King int val; 68020b2af32SRussell King 68120b2af32SRussell King val = phy_read_mmd(phydev, MDIO_MMD_PCS, MV_PCS_BASE_R + MDIO_STAT1); 68220b2af32SRussell King if (val < 0) 68320b2af32SRussell King return val; 68420b2af32SRussell King 68520b2af32SRussell King if (val & MDIO_STAT1_LSTATUS) 68620b2af32SRussell King return 1; 68720b2af32SRussell King 68820b2af32SRussell King return genphy_c45_aneg_done(phydev); 68920b2af32SRussell King } 69020b2af32SRussell King 69136c4449aSRussell King static void mv3310_update_interface(struct phy_device *phydev) 69236c4449aSRussell King { 693e1170333SBaruch Siach struct mv3310_priv *priv = dev_get_drvdata(&phydev->mdio.dev); 694e1170333SBaruch Siach 695*ccbf2891SMarek Behún if (!phydev->link) 696*ccbf2891SMarek Behún return; 697*ccbf2891SMarek Behún 69897bbe3bdSMarek Behún /* In all of the "* with Rate Matching" modes the PHY interface is fixed 69997bbe3bdSMarek Behún * at 10Gb. The PHY adapts the rate to actual wire speed with help of 700e1170333SBaruch Siach * internal 16KB buffer. 701*ccbf2891SMarek Behún * 702*ccbf2891SMarek Behún * In USXGMII mode the PHY interface mode is also fixed. 703e1170333SBaruch Siach */ 704*ccbf2891SMarek Behún if (priv->rate_match || 705*ccbf2891SMarek Behún priv->const_interface == PHY_INTERFACE_MODE_USXGMII) { 70697bbe3bdSMarek Behún phydev->interface = priv->const_interface; 707e1170333SBaruch Siach return; 708e1170333SBaruch Siach } 709e1170333SBaruch Siach 710*ccbf2891SMarek Behún /* The PHY automatically switches its serdes interface (and active PHYXS 711*ccbf2891SMarek Behún * instance) between Cisco SGMII, 2500BaseX, 5GBase-R and 10GBase-R / 712*ccbf2891SMarek Behún * xaui / rxaui modes according to the speed. 713*ccbf2891SMarek Behún * Florian suggests setting phydev->interface to communicate this to the 714*ccbf2891SMarek Behún * MAC. Only do this if we are already in one of the above modes. 71536c4449aSRussell King */ 716e555e5b1SMaxime Chevallier switch (phydev->speed) { 717e555e5b1SMaxime Chevallier case SPEED_10000: 718*ccbf2891SMarek Behún phydev->interface = priv->const_interface; 719e555e5b1SMaxime Chevallier break; 7200d375542SMarek Behún case SPEED_5000: 7210d375542SMarek Behún phydev->interface = PHY_INTERFACE_MODE_5GBASER; 7220d375542SMarek Behún break; 723e555e5b1SMaxime Chevallier case SPEED_2500: 724e555e5b1SMaxime Chevallier phydev->interface = PHY_INTERFACE_MODE_2500BASEX; 725e555e5b1SMaxime Chevallier break; 726e555e5b1SMaxime Chevallier case SPEED_1000: 727e555e5b1SMaxime Chevallier case SPEED_100: 728e555e5b1SMaxime Chevallier case SPEED_10: 72936c4449aSRussell King phydev->interface = PHY_INTERFACE_MODE_SGMII; 730e555e5b1SMaxime Chevallier break; 731e555e5b1SMaxime Chevallier default: 732e555e5b1SMaxime Chevallier break; 733e555e5b1SMaxime Chevallier } 73436c4449aSRussell King } 73536c4449aSRussell King 73620b2af32SRussell King /* 10GBASE-ER,LR,LRM,SR do not support autonegotiation. */ 737c84786faSRussell King static int mv3310_read_status_10gbaser(struct phy_device *phydev) 73820b2af32SRussell King { 73920b2af32SRussell King phydev->link = 1; 74020b2af32SRussell King phydev->speed = SPEED_10000; 74120b2af32SRussell King phydev->duplex = DUPLEX_FULL; 7424217a64eSMichael Walle phydev->port = PORT_FIBRE; 74320b2af32SRussell King 74420b2af32SRussell King return 0; 74520b2af32SRussell King } 74620b2af32SRussell King 747c84786faSRussell King static int mv3310_read_status_copper(struct phy_device *phydev) 74820b2af32SRussell King { 749c84786faSRussell King int cssr1, speed, val; 75020b2af32SRussell King 751998a8a83SHeiner Kallweit val = genphy_c45_read_link(phydev); 75220b2af32SRussell King if (val < 0) 75320b2af32SRussell King return val; 75420b2af32SRussell King 75520b2af32SRussell King val = phy_read_mmd(phydev, MDIO_MMD_AN, MDIO_STAT1); 75620b2af32SRussell King if (val < 0) 75720b2af32SRussell King return val; 75820b2af32SRussell King 759c84786faSRussell King cssr1 = phy_read_mmd(phydev, MDIO_MMD_PCS, MV_PCS_CSSR1); 760c84786faSRussell King if (cssr1 < 0) 761c84786faSRussell King return val; 762c84786faSRussell King 763c84786faSRussell King /* If the link settings are not resolved, mark the link down */ 764c84786faSRussell King if (!(cssr1 & MV_PCS_CSSR1_RESOLVED)) { 765c84786faSRussell King phydev->link = 0; 766c84786faSRussell King return 0; 767c84786faSRussell King } 768c84786faSRussell King 769c84786faSRussell King /* Read the copper link settings */ 770c84786faSRussell King speed = cssr1 & MV_PCS_CSSR1_SPD1_MASK; 771c84786faSRussell King if (speed == MV_PCS_CSSR1_SPD1_SPD2) 772c84786faSRussell King speed |= cssr1 & MV_PCS_CSSR1_SPD2_MASK; 773c84786faSRussell King 774c84786faSRussell King switch (speed) { 775c84786faSRussell King case MV_PCS_CSSR1_SPD1_SPD2 | MV_PCS_CSSR1_SPD2_10000: 776c84786faSRussell King phydev->speed = SPEED_10000; 777c84786faSRussell King break; 778c84786faSRussell King 779c84786faSRussell King case MV_PCS_CSSR1_SPD1_SPD2 | MV_PCS_CSSR1_SPD2_5000: 780c84786faSRussell King phydev->speed = SPEED_5000; 781c84786faSRussell King break; 782c84786faSRussell King 783c84786faSRussell King case MV_PCS_CSSR1_SPD1_SPD2 | MV_PCS_CSSR1_SPD2_2500: 784c84786faSRussell King phydev->speed = SPEED_2500; 785c84786faSRussell King break; 786c84786faSRussell King 787c84786faSRussell King case MV_PCS_CSSR1_SPD1_1000: 788c84786faSRussell King phydev->speed = SPEED_1000; 789c84786faSRussell King break; 790c84786faSRussell King 791c84786faSRussell King case MV_PCS_CSSR1_SPD1_100: 792c84786faSRussell King phydev->speed = SPEED_100; 793c84786faSRussell King break; 794c84786faSRussell King 795c84786faSRussell King case MV_PCS_CSSR1_SPD1_10: 796c84786faSRussell King phydev->speed = SPEED_10; 797c84786faSRussell King break; 798c84786faSRussell King } 799c84786faSRussell King 800c84786faSRussell King phydev->duplex = cssr1 & MV_PCS_CSSR1_DUPLEX_FULL ? 801c84786faSRussell King DUPLEX_FULL : DUPLEX_HALF; 8024217a64eSMichael Walle phydev->port = PORT_TP; 803c84786faSRussell King phydev->mdix = cssr1 & MV_PCS_CSSR1_MDIX ? 804c84786faSRussell King ETH_TP_MDI_X : ETH_TP_MDI; 805c84786faSRussell King 80620b2af32SRussell King if (val & MDIO_AN_STAT1_COMPLETE) { 80720b2af32SRussell King val = genphy_c45_read_lpa(phydev); 80820b2af32SRussell King if (val < 0) 80920b2af32SRussell King return val; 81020b2af32SRussell King 811cc1122b0SColin Ian King /* Read the link partner's 1G advertisement */ 81220b2af32SRussell King val = phy_read_mmd(phydev, MDIO_MMD_AN, MV_AN_STAT1000); 81320b2af32SRussell King if (val < 0) 81420b2af32SRussell King return val; 81520b2af32SRussell King 81678a24df3SAndrew Lunn mii_stat1000_mod_linkmode_lpa_t(phydev->lp_advertising, val); 81720b2af32SRussell King 818c84786faSRussell King /* Update the pause status */ 819c84786faSRussell King phy_resolve_aneg_pause(phydev); 82020b2af32SRussell King } 82120b2af32SRussell King 822c84786faSRussell King return 0; 82320b2af32SRussell King } 82420b2af32SRussell King 825c84786faSRussell King static int mv3310_read_status(struct phy_device *phydev) 826c84786faSRussell King { 827c84786faSRussell King int err, val; 828ea4efe25SRussell King 829c84786faSRussell King phydev->speed = SPEED_UNKNOWN; 830c84786faSRussell King phydev->duplex = DUPLEX_UNKNOWN; 831c84786faSRussell King linkmode_zero(phydev->lp_advertising); 832c84786faSRussell King phydev->link = 0; 833c84786faSRussell King phydev->pause = 0; 834c84786faSRussell King phydev->asym_pause = 0; 835ea4efe25SRussell King phydev->mdix = ETH_TP_MDI_INVALID; 836ea4efe25SRussell King 837c84786faSRussell King val = phy_read_mmd(phydev, MDIO_MMD_PCS, MV_PCS_BASE_R + MDIO_STAT1); 838c84786faSRussell King if (val < 0) 839c84786faSRussell King return val; 840c84786faSRussell King 841c84786faSRussell King if (val & MDIO_STAT1_LSTATUS) 842c84786faSRussell King err = mv3310_read_status_10gbaser(phydev); 843c84786faSRussell King else 844c84786faSRussell King err = mv3310_read_status_copper(phydev); 845c84786faSRussell King if (err < 0) 846c84786faSRussell King return err; 847c84786faSRussell King 848c84786faSRussell King if (phydev->link) 84936c4449aSRussell King mv3310_update_interface(phydev); 85020b2af32SRussell King 85120b2af32SRussell King return 0; 85220b2af32SRussell King } 85320b2af32SRussell King 854a585c03eSRussell King static int mv3310_get_tunable(struct phy_device *phydev, 855a585c03eSRussell King struct ethtool_tunable *tuna, void *data) 856a585c03eSRussell King { 857a585c03eSRussell King switch (tuna->id) { 858a585c03eSRussell King case ETHTOOL_PHY_EDPD: 859a585c03eSRussell King return mv3310_get_edpd(phydev, data); 860a585c03eSRussell King default: 861a585c03eSRussell King return -EOPNOTSUPP; 862a585c03eSRussell King } 863a585c03eSRussell King } 864a585c03eSRussell King 865a585c03eSRussell King static int mv3310_set_tunable(struct phy_device *phydev, 866a585c03eSRussell King struct ethtool_tunable *tuna, const void *data) 867a585c03eSRussell King { 868a585c03eSRussell King switch (tuna->id) { 869a585c03eSRussell King case ETHTOOL_PHY_EDPD: 870a585c03eSRussell King return mv3310_set_edpd(phydev, *(u16 *)data); 871a585c03eSRussell King default: 872a585c03eSRussell King return -EOPNOTSUPP; 873a585c03eSRussell King } 874a585c03eSRussell King } 875a585c03eSRussell King 876261a74c6SMarek Behún static void mv3310_init_supported_interfaces(unsigned long *mask) 877261a74c6SMarek Behún { 878261a74c6SMarek Behún __set_bit(PHY_INTERFACE_MODE_SGMII, mask); 879261a74c6SMarek Behún __set_bit(PHY_INTERFACE_MODE_2500BASEX, mask); 880261a74c6SMarek Behún __set_bit(PHY_INTERFACE_MODE_5GBASER, mask); 881261a74c6SMarek Behún __set_bit(PHY_INTERFACE_MODE_XAUI, mask); 882261a74c6SMarek Behún __set_bit(PHY_INTERFACE_MODE_RXAUI, mask); 883261a74c6SMarek Behún __set_bit(PHY_INTERFACE_MODE_10GBASER, mask); 884261a74c6SMarek Behún __set_bit(PHY_INTERFACE_MODE_USXGMII, mask); 885261a74c6SMarek Behún } 886261a74c6SMarek Behún 887261a74c6SMarek Behún static void mv2110_init_supported_interfaces(unsigned long *mask) 888261a74c6SMarek Behún { 889261a74c6SMarek Behún __set_bit(PHY_INTERFACE_MODE_SGMII, mask); 890261a74c6SMarek Behún __set_bit(PHY_INTERFACE_MODE_2500BASEX, mask); 891261a74c6SMarek Behún __set_bit(PHY_INTERFACE_MODE_5GBASER, mask); 892261a74c6SMarek Behún __set_bit(PHY_INTERFACE_MODE_10GBASER, mask); 893261a74c6SMarek Behún __set_bit(PHY_INTERFACE_MODE_USXGMII, mask); 894261a74c6SMarek Behún } 895261a74c6SMarek Behún 89697bbe3bdSMarek Behún static const struct mv3310_chip mv3310_type = { 897261a74c6SMarek Behún .init_supported_interfaces = mv3310_init_supported_interfaces, 89897bbe3bdSMarek Behún .get_mactype = mv3310_get_mactype, 89997bbe3bdSMarek Behún .init_interface = mv3310_init_interface, 900884d9a67SMarek Behún 901884d9a67SMarek Behún #ifdef CONFIG_HWMON 902884d9a67SMarek Behún .hwmon_read_temp_reg = mv3310_hwmon_read_temp_reg, 903884d9a67SMarek Behún #endif 90497bbe3bdSMarek Behún }; 90597bbe3bdSMarek Behún 90697bbe3bdSMarek Behún static const struct mv3310_chip mv2110_type = { 907261a74c6SMarek Behún .init_supported_interfaces = mv2110_init_supported_interfaces, 90897bbe3bdSMarek Behún .get_mactype = mv2110_get_mactype, 90997bbe3bdSMarek Behún .init_interface = mv2110_init_interface, 910884d9a67SMarek Behún 911884d9a67SMarek Behún #ifdef CONFIG_HWMON 912884d9a67SMarek Behún .hwmon_read_temp_reg = mv2110_hwmon_read_temp_reg, 913884d9a67SMarek Behún #endif 91497bbe3bdSMarek Behún }; 91597bbe3bdSMarek Behún 91620b2af32SRussell King static struct phy_driver mv3310_drivers[] = { 91720b2af32SRussell King { 918631ba906SMaxime Chevallier .phy_id = MARVELL_PHY_ID_88X3310, 919952b6b3bSAntoine Tenart .phy_id_mask = MARVELL_PHY_ID_MASK, 92020b2af32SRussell King .name = "mv88x3310", 92197bbe3bdSMarek Behún .driver_data = &mv3310_type, 92274145424SMaxime Chevallier .get_features = mv3310_get_features, 92320b2af32SRussell King .config_init = mv3310_config_init, 9240d3ad854SRussell King .probe = mv3310_probe, 9250d3ad854SRussell King .suspend = mv3310_suspend, 9260d3ad854SRussell King .resume = mv3310_resume, 92720b2af32SRussell King .config_aneg = mv3310_config_aneg, 92820b2af32SRussell King .aneg_done = mv3310_aneg_done, 92920b2af32SRussell King .read_status = mv3310_read_status, 930a585c03eSRussell King .get_tunable = mv3310_get_tunable, 931a585c03eSRussell King .set_tunable = mv3310_set_tunable, 9321b8ef142SMarek Behún .remove = mv3310_remove, 933d137c70dSWong Vee Khee .set_loopback = genphy_c45_loopback, 93420b2af32SRussell King }, 93562d01535SMaxime Chevallier { 93662d01535SMaxime Chevallier .phy_id = MARVELL_PHY_ID_88E2110, 93762d01535SMaxime Chevallier .phy_id_mask = MARVELL_PHY_ID_MASK, 93862d01535SMaxime Chevallier .name = "mv88x2110", 93997bbe3bdSMarek Behún .driver_data = &mv2110_type, 94062d01535SMaxime Chevallier .probe = mv3310_probe, 941e02c4a9dSAntoine Tenart .suspend = mv3310_suspend, 942e02c4a9dSAntoine Tenart .resume = mv3310_resume, 94362d01535SMaxime Chevallier .config_init = mv3310_config_init, 94462d01535SMaxime Chevallier .config_aneg = mv3310_config_aneg, 94562d01535SMaxime Chevallier .aneg_done = mv3310_aneg_done, 94662d01535SMaxime Chevallier .read_status = mv3310_read_status, 947a585c03eSRussell King .get_tunable = mv3310_get_tunable, 948a585c03eSRussell King .set_tunable = mv3310_set_tunable, 9491b8ef142SMarek Behún .remove = mv3310_remove, 950d137c70dSWong Vee Khee .set_loopback = genphy_c45_loopback, 95162d01535SMaxime Chevallier }, 95220b2af32SRussell King }; 95320b2af32SRussell King 95420b2af32SRussell King module_phy_driver(mv3310_drivers); 95520b2af32SRussell King 95620b2af32SRussell King static struct mdio_device_id __maybe_unused mv3310_tbl[] = { 957631ba906SMaxime Chevallier { MARVELL_PHY_ID_88X3310, MARVELL_PHY_ID_MASK }, 95862d01535SMaxime Chevallier { MARVELL_PHY_ID_88E2110, MARVELL_PHY_ID_MASK }, 95920b2af32SRussell King { }, 96020b2af32SRussell King }; 96120b2af32SRussell King MODULE_DEVICE_TABLE(mdio, mv3310_tbl); 96220b2af32SRussell King MODULE_DESCRIPTION("Marvell Alaska X 10Gigabit Ethernet PHY driver (MV88X3310)"); 96320b2af32SRussell King MODULE_LICENSE("GPL"); 964