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 */
254075a6a0SRussell King #include <linux/bitfield.h>
260d3ad854SRussell King #include <linux/ctype.h>
278d8963c3SRussell King #include <linux/delay.h>
280d3ad854SRussell King #include <linux/hwmon.h>
29952b6b3bSAntoine Tenart #include <linux/marvell_phy.h>
300d3ad854SRussell King #include <linux/phy.h>
3136023da1SRussell King #include <linux/sfp.h>
3208041a9aSVoon Weifeng #include <linux/netdevice.h>
3320b2af32SRussell King
34c47455f9SMaxime Chevallier #define MV_PHY_ALASKA_NBT_QUIRK_MASK 0xfffffffe
35c47455f9SMaxime Chevallier #define MV_PHY_ALASKA_NBT_QUIRK_REV (MARVELL_PHY_ID_88X3310 | 0xa)
36c47455f9SMaxime Chevallier
374075a6a0SRussell King #define MV_VERSION(a,b,c,d) ((a) << 24 | (b) << 16 | (c) << 8 | (d))
384075a6a0SRussell King
3920b2af32SRussell King enum {
40dd649b4fSRussell King MV_PMA_FW_VER0 = 0xc011,
41dd649b4fSRussell King MV_PMA_FW_VER1 = 0xc012,
429ab0fbd0SMarek Behún MV_PMA_21X0_PORT_CTRL = 0xc04a,
439ab0fbd0SMarek Behún MV_PMA_21X0_PORT_CTRL_SWRST = BIT(15),
449ab0fbd0SMarek Behún MV_PMA_21X0_PORT_CTRL_MACTYPE_MASK = 0x7,
459ab0fbd0SMarek Behún MV_PMA_21X0_PORT_CTRL_MACTYPE_USXGMII = 0x0,
469ab0fbd0SMarek Behún MV_PMA_2180_PORT_CTRL_MACTYPE_DXGMII = 0x1,
479ab0fbd0SMarek Behún MV_PMA_2180_PORT_CTRL_MACTYPE_QXGMII = 0x2,
489ab0fbd0SMarek Behún MV_PMA_21X0_PORT_CTRL_MACTYPE_5GBASER = 0x4,
499ab0fbd0SMarek Behún MV_PMA_21X0_PORT_CTRL_MACTYPE_5GBASER_NO_SGMII_AN = 0x5,
509ab0fbd0SMarek Behún MV_PMA_21X0_PORT_CTRL_MACTYPE_10GBASER_RATE_MATCH = 0x6,
513d3ced2eSRussell King MV_PMA_BOOT = 0xc050,
523d3ced2eSRussell King MV_PMA_BOOT_FATAL = BIT(0),
533d3ced2eSRussell King
5420b2af32SRussell King MV_PCS_BASE_T = 0x0000,
5520b2af32SRussell King MV_PCS_BASE_R = 0x1000,
5620b2af32SRussell King MV_PCS_1000BASEX = 0x2000,
5720b2af32SRussell King
588d8963c3SRussell King MV_PCS_CSCR1 = 0x8000,
59a585c03eSRussell King MV_PCS_CSCR1_ED_MASK = 0x0300,
60a585c03eSRussell King MV_PCS_CSCR1_ED_OFF = 0x0000,
61a585c03eSRussell King MV_PCS_CSCR1_ED_RX = 0x0200,
62a585c03eSRussell King MV_PCS_CSCR1_ED_NLP = 0x0300,
638d8963c3SRussell King MV_PCS_CSCR1_MDIX_MASK = 0x0060,
648d8963c3SRussell King MV_PCS_CSCR1_MDIX_MDI = 0x0000,
658d8963c3SRussell King MV_PCS_CSCR1_MDIX_MDIX = 0x0020,
668d8963c3SRussell King MV_PCS_CSCR1_MDIX_AUTO = 0x0060,
678d8963c3SRussell King
684075a6a0SRussell King MV_PCS_DSC1 = 0x8003,
694075a6a0SRussell King MV_PCS_DSC1_ENABLE = BIT(9),
704075a6a0SRussell King MV_PCS_DSC1_10GBT = 0x01c0,
714075a6a0SRussell King MV_PCS_DSC1_1GBR = 0x0038,
724075a6a0SRussell King MV_PCS_DSC1_100BTX = 0x0007,
734075a6a0SRussell King MV_PCS_DSC2 = 0x8004,
744075a6a0SRussell King MV_PCS_DSC2_2P5G = 0xf000,
754075a6a0SRussell King MV_PCS_DSC2_5G = 0x0f00,
764075a6a0SRussell King
77c84786faSRussell King MV_PCS_CSSR1 = 0x8008,
78c84786faSRussell King MV_PCS_CSSR1_SPD1_MASK = 0xc000,
79c84786faSRussell King MV_PCS_CSSR1_SPD1_SPD2 = 0xc000,
80c84786faSRussell King MV_PCS_CSSR1_SPD1_1000 = 0x8000,
81c84786faSRussell King MV_PCS_CSSR1_SPD1_100 = 0x4000,
82c84786faSRussell King MV_PCS_CSSR1_SPD1_10 = 0x0000,
83c84786faSRussell King MV_PCS_CSSR1_DUPLEX_FULL= BIT(13),
84c84786faSRussell King MV_PCS_CSSR1_RESOLVED = BIT(11),
85c84786faSRussell King MV_PCS_CSSR1_MDIX = BIT(6),
86c84786faSRussell King MV_PCS_CSSR1_SPD2_MASK = 0x000c,
87c84786faSRussell King MV_PCS_CSSR1_SPD2_5000 = 0x0008,
88c84786faSRussell King MV_PCS_CSSR1_SPD2_2500 = 0x0004,
89c84786faSRussell King MV_PCS_CSSR1_SPD2_10000 = 0x0000,
90ea4efe25SRussell King
91c3e302edSBaruch Siach /* Temperature read register (88E2110 only) */
92c3e302edSBaruch Siach MV_PCS_TEMP = 0x8042,
93c3e302edSBaruch Siach
94a5de4be0SMarek Behún /* Number of ports on the device */
95a5de4be0SMarek Behún MV_PCS_PORT_INFO = 0xd00d,
96a5de4be0SMarek Behún MV_PCS_PORT_INFO_NPORTS_MASK = 0x0380,
97a5de4be0SMarek Behún MV_PCS_PORT_INFO_NPORTS_SHIFT = 7,
98a5de4be0SMarek Behún
99d6d29292SRussell King /* SerDes reinitialization 88E21X0 */
100d6d29292SRussell King MV_AN_21X0_SERDES_CTRL2 = 0x800f,
101d6d29292SRussell King MV_AN_21X0_SERDES_CTRL2_AUTO_INIT_DIS = BIT(13),
102d6d29292SRussell King MV_AN_21X0_SERDES_CTRL2_RUN_INIT = BIT(15),
103d6d29292SRussell King
10420b2af32SRussell King /* These registers appear at 0x800X and 0xa00X - the 0xa00X control
10520b2af32SRussell King * registers appear to set themselves to the 0x800X when AN is
10620b2af32SRussell King * restarted, but status registers appear readable from either.
10720b2af32SRussell King */
10820b2af32SRussell King MV_AN_CTRL1000 = 0x8000, /* 1000base-T control register */
10920b2af32SRussell King MV_AN_STAT1000 = 0x8001, /* 1000base-T status register */
1100d3ad854SRussell King
1110d3ad854SRussell King /* Vendor2 MMD registers */
112af3e28cbSAntoine Tenart MV_V2_PORT_CTRL = 0xf001,
1138f48c2acSRussell King MV_V2_PORT_CTRL_PWRDOWN = BIT(11),
1149893f316SMarek Behún MV_V2_33X0_PORT_CTRL_SWRST = BIT(15),
1159893f316SMarek Behún MV_V2_33X0_PORT_CTRL_MACTYPE_MASK = 0x7,
116f8ee45fcSMarek Behún MV_V2_33X0_PORT_CTRL_MACTYPE_RXAUI = 0x0,
117f8ee45fcSMarek Behún MV_V2_3310_PORT_CTRL_MACTYPE_XAUI_RATE_MATCH = 0x1,
118f8ee45fcSMarek Behún MV_V2_3340_PORT_CTRL_MACTYPE_RXAUI_NO_SGMII_AN = 0x1,
119f8ee45fcSMarek Behún MV_V2_33X0_PORT_CTRL_MACTYPE_RXAUI_RATE_MATCH = 0x2,
120f8ee45fcSMarek Behún MV_V2_3310_PORT_CTRL_MACTYPE_XAUI = 0x3,
121f8ee45fcSMarek Behún MV_V2_33X0_PORT_CTRL_MACTYPE_10GBASER = 0x4,
122f8ee45fcSMarek Behún MV_V2_33X0_PORT_CTRL_MACTYPE_10GBASER_NO_SGMII_AN = 0x5,
123f8ee45fcSMarek Behún MV_V2_33X0_PORT_CTRL_MACTYPE_10GBASER_RATE_MATCH = 0x6,
124f8ee45fcSMarek Behún MV_V2_33X0_PORT_CTRL_MACTYPE_USXGMII = 0x7,
12508041a9aSVoon Weifeng MV_V2_PORT_INTR_STS = 0xf040,
12608041a9aSVoon Weifeng MV_V2_PORT_INTR_MASK = 0xf043,
12708041a9aSVoon Weifeng MV_V2_PORT_INTR_STS_WOL_EN = BIT(8),
12808041a9aSVoon Weifeng MV_V2_MAGIC_PKT_WORD0 = 0xf06b,
12908041a9aSVoon Weifeng MV_V2_MAGIC_PKT_WORD1 = 0xf06c,
13008041a9aSVoon Weifeng MV_V2_MAGIC_PKT_WORD2 = 0xf06d,
13108041a9aSVoon Weifeng /* Wake on LAN registers */
13208041a9aSVoon Weifeng MV_V2_WOL_CTRL = 0xf06e,
13308041a9aSVoon Weifeng MV_V2_WOL_CTRL_CLEAR_STS = BIT(15),
13408041a9aSVoon Weifeng MV_V2_WOL_CTRL_MAGIC_PKT_EN = BIT(0),
135c3e302edSBaruch Siach /* Temperature control/read registers (88X3310 only) */
1360d3ad854SRussell King MV_V2_TEMP_CTRL = 0xf08a,
1370d3ad854SRussell King MV_V2_TEMP_CTRL_MASK = 0xc000,
1380d3ad854SRussell King MV_V2_TEMP_CTRL_SAMPLE = 0x0000,
1390d3ad854SRussell King MV_V2_TEMP_CTRL_DISABLE = 0xc000,
1400d3ad854SRussell King MV_V2_TEMP = 0xf08c,
1410d3ad854SRussell King MV_V2_TEMP_UNKNOWN = 0x9600, /* unknown function */
1420d3ad854SRussell King };
1430d3ad854SRussell King
1442cb6d63bSRussell King (Oracle) struct mv3310_mactype {
1452cb6d63bSRussell King (Oracle) bool valid;
1462cb6d63bSRussell King (Oracle) bool fixed_interface;
1472cb6d63bSRussell King (Oracle) phy_interface_t interface_10g;
1482cb6d63bSRussell King (Oracle) };
1492cb6d63bSRussell King (Oracle)
15097bbe3bdSMarek Behún struct mv3310_chip {
1514075a6a0SRussell King bool (*has_downshift)(struct phy_device *phydev);
152261a74c6SMarek Behún void (*init_supported_interfaces)(unsigned long *mask);
15397bbe3bdSMarek Behún int (*get_mactype)(struct phy_device *phydev);
154d6d29292SRussell King int (*set_mactype)(struct phy_device *phydev, int mactype);
155d6d29292SRussell King int (*select_mactype)(unsigned long *interfaces);
1562cb6d63bSRussell King (Oracle)
1572cb6d63bSRussell King (Oracle) const struct mv3310_mactype *mactypes;
1582cb6d63bSRussell King (Oracle) size_t n_mactypes;
159884d9a67SMarek Behún
160884d9a67SMarek Behún #ifdef CONFIG_HWMON
161884d9a67SMarek Behún int (*hwmon_read_temp_reg)(struct phy_device *phydev);
162884d9a67SMarek Behún #endif
16397bbe3bdSMarek Behún };
16497bbe3bdSMarek Behún
1650d3ad854SRussell King struct mv3310_priv {
166261a74c6SMarek Behún DECLARE_BITMAP(supported_interfaces, PHY_INTERFACE_MODE_MAX);
1672cb6d63bSRussell King (Oracle) const struct mv3310_mactype *mactype;
168261a74c6SMarek Behún
169dd649b4fSRussell King u32 firmware_ver;
1704075a6a0SRussell King bool has_downshift;
171dd649b4fSRussell King
1720d3ad854SRussell King struct device *hwmon_dev;
1730d3ad854SRussell King char *hwmon_name;
17420b2af32SRussell King };
17520b2af32SRussell King
to_mv3310_chip(struct phy_device * phydev)17697bbe3bdSMarek Behún static const struct mv3310_chip *to_mv3310_chip(struct phy_device *phydev)
17797bbe3bdSMarek Behún {
17897bbe3bdSMarek Behún return phydev->drv->driver_data;
17997bbe3bdSMarek Behún }
18097bbe3bdSMarek Behún
1810d3ad854SRussell King #ifdef CONFIG_HWMON
mv3310_hwmon_is_visible(const void * data,enum hwmon_sensor_types type,u32 attr,int channel)1820d3ad854SRussell King static umode_t mv3310_hwmon_is_visible(const void *data,
1830d3ad854SRussell King enum hwmon_sensor_types type,
1840d3ad854SRussell King u32 attr, int channel)
1850d3ad854SRussell King {
1860d3ad854SRussell King if (type == hwmon_chip && attr == hwmon_chip_update_interval)
1870d3ad854SRussell King return 0444;
1880d3ad854SRussell King if (type == hwmon_temp && attr == hwmon_temp_input)
1890d3ad854SRussell King return 0444;
1900d3ad854SRussell King return 0;
1910d3ad854SRussell King }
1920d3ad854SRussell King
mv3310_hwmon_read_temp_reg(struct phy_device * phydev)193c3e302edSBaruch Siach static int mv3310_hwmon_read_temp_reg(struct phy_device *phydev)
194c3e302edSBaruch Siach {
195c3e302edSBaruch Siach return phy_read_mmd(phydev, MDIO_MMD_VEND2, MV_V2_TEMP);
196c3e302edSBaruch Siach }
197c3e302edSBaruch Siach
mv2110_hwmon_read_temp_reg(struct phy_device * phydev)198c3e302edSBaruch Siach static int mv2110_hwmon_read_temp_reg(struct phy_device *phydev)
199c3e302edSBaruch Siach {
200c3e302edSBaruch Siach return phy_read_mmd(phydev, MDIO_MMD_PCS, MV_PCS_TEMP);
201c3e302edSBaruch Siach }
202c3e302edSBaruch Siach
mv3310_hwmon_read(struct device * dev,enum hwmon_sensor_types type,u32 attr,int channel,long * value)2030d3ad854SRussell King static int mv3310_hwmon_read(struct device *dev, enum hwmon_sensor_types type,
2040d3ad854SRussell King u32 attr, int channel, long *value)
2050d3ad854SRussell King {
2060d3ad854SRussell King struct phy_device *phydev = dev_get_drvdata(dev);
207884d9a67SMarek Behún const struct mv3310_chip *chip = to_mv3310_chip(phydev);
2080d3ad854SRussell King int temp;
2090d3ad854SRussell King
2100d3ad854SRussell King if (type == hwmon_chip && attr == hwmon_chip_update_interval) {
2110d3ad854SRussell King *value = MSEC_PER_SEC;
2120d3ad854SRussell King return 0;
2130d3ad854SRussell King }
2140d3ad854SRussell King
2150d3ad854SRussell King if (type == hwmon_temp && attr == hwmon_temp_input) {
216884d9a67SMarek Behún temp = chip->hwmon_read_temp_reg(phydev);
2170d3ad854SRussell King if (temp < 0)
2180d3ad854SRussell King return temp;
2190d3ad854SRussell King
2200d3ad854SRussell King *value = ((temp & 0xff) - 75) * 1000;
2210d3ad854SRussell King
2220d3ad854SRussell King return 0;
2230d3ad854SRussell King }
2240d3ad854SRussell King
2250d3ad854SRussell King return -EOPNOTSUPP;
2260d3ad854SRussell King }
2270d3ad854SRussell King
2280d3ad854SRussell King static const struct hwmon_ops mv3310_hwmon_ops = {
2290d3ad854SRussell King .is_visible = mv3310_hwmon_is_visible,
2300d3ad854SRussell King .read = mv3310_hwmon_read,
2310d3ad854SRussell King };
2320d3ad854SRussell King
2330d3ad854SRussell King static u32 mv3310_hwmon_chip_config[] = {
2340d3ad854SRussell King HWMON_C_REGISTER_TZ | HWMON_C_UPDATE_INTERVAL,
2350d3ad854SRussell King 0,
2360d3ad854SRussell King };
2370d3ad854SRussell King
2380d3ad854SRussell King static const struct hwmon_channel_info mv3310_hwmon_chip = {
2390d3ad854SRussell King .type = hwmon_chip,
2400d3ad854SRussell King .config = mv3310_hwmon_chip_config,
2410d3ad854SRussell King };
2420d3ad854SRussell King
2430d3ad854SRussell King static u32 mv3310_hwmon_temp_config[] = {
2440d3ad854SRussell King HWMON_T_INPUT,
2450d3ad854SRussell King 0,
2460d3ad854SRussell King };
2470d3ad854SRussell King
2480d3ad854SRussell King static const struct hwmon_channel_info mv3310_hwmon_temp = {
2490d3ad854SRussell King .type = hwmon_temp,
2500d3ad854SRussell King .config = mv3310_hwmon_temp_config,
2510d3ad854SRussell King };
2520d3ad854SRussell King
253ff0805e2SKrzysztof Kozlowski static const struct hwmon_channel_info * const mv3310_hwmon_info[] = {
2540d3ad854SRussell King &mv3310_hwmon_chip,
2550d3ad854SRussell King &mv3310_hwmon_temp,
2560d3ad854SRussell King NULL,
2570d3ad854SRussell King };
2580d3ad854SRussell King
2590d3ad854SRussell King static const struct hwmon_chip_info mv3310_hwmon_chip_info = {
2600d3ad854SRussell King .ops = &mv3310_hwmon_ops,
2610d3ad854SRussell King .info = mv3310_hwmon_info,
2620d3ad854SRussell King };
2630d3ad854SRussell King
mv3310_hwmon_config(struct phy_device * phydev,bool enable)2640d3ad854SRussell King static int mv3310_hwmon_config(struct phy_device *phydev, bool enable)
2650d3ad854SRussell King {
2660d3ad854SRussell King u16 val;
2670d3ad854SRussell King int ret;
2680d3ad854SRussell King
269c3e302edSBaruch Siach if (phydev->drv->phy_id != MARVELL_PHY_ID_88X3310)
270c3e302edSBaruch Siach return 0;
271c3e302edSBaruch Siach
2720d3ad854SRussell King ret = phy_write_mmd(phydev, MDIO_MMD_VEND2, MV_V2_TEMP,
2730d3ad854SRussell King MV_V2_TEMP_UNKNOWN);
2740d3ad854SRussell King if (ret < 0)
2750d3ad854SRussell King return ret;
2760d3ad854SRussell King
2770d3ad854SRussell King val = enable ? MV_V2_TEMP_CTRL_SAMPLE : MV_V2_TEMP_CTRL_DISABLE;
2780d3ad854SRussell King
279b06d8e5aSHeiner Kallweit return phy_modify_mmd(phydev, MDIO_MMD_VEND2, MV_V2_TEMP_CTRL,
280b06d8e5aSHeiner Kallweit MV_V2_TEMP_CTRL_MASK, val);
2810d3ad854SRussell King }
2820d3ad854SRussell King
mv3310_hwmon_probe(struct phy_device * phydev)2830d3ad854SRussell King static int mv3310_hwmon_probe(struct phy_device *phydev)
2840d3ad854SRussell King {
2850d3ad854SRussell King struct device *dev = &phydev->mdio.dev;
2860d3ad854SRussell King struct mv3310_priv *priv = dev_get_drvdata(&phydev->mdio.dev);
2870d3ad854SRussell King int i, j, ret;
2880d3ad854SRussell King
2890d3ad854SRussell King priv->hwmon_name = devm_kstrdup(dev, dev_name(dev), GFP_KERNEL);
2900d3ad854SRussell King if (!priv->hwmon_name)
2910d3ad854SRussell King return -ENODEV;
2920d3ad854SRussell King
2930d3ad854SRussell King for (i = j = 0; priv->hwmon_name[i]; i++) {
2940d3ad854SRussell King if (isalnum(priv->hwmon_name[i])) {
2950d3ad854SRussell King if (i != j)
2960d3ad854SRussell King priv->hwmon_name[j] = priv->hwmon_name[i];
2970d3ad854SRussell King j++;
2980d3ad854SRussell King }
2990d3ad854SRussell King }
3000d3ad854SRussell King priv->hwmon_name[j] = '\0';
3010d3ad854SRussell King
3020d3ad854SRussell King ret = mv3310_hwmon_config(phydev, true);
3030d3ad854SRussell King if (ret)
3040d3ad854SRussell King return ret;
3050d3ad854SRussell King
3060d3ad854SRussell King priv->hwmon_dev = devm_hwmon_device_register_with_info(dev,
3070d3ad854SRussell King priv->hwmon_name, phydev,
3080d3ad854SRussell King &mv3310_hwmon_chip_info, NULL);
3090d3ad854SRussell King
3100d3ad854SRussell King return PTR_ERR_OR_ZERO(priv->hwmon_dev);
3110d3ad854SRussell King }
3120d3ad854SRussell King #else
mv3310_hwmon_config(struct phy_device * phydev,bool enable)3130d3ad854SRussell King static inline int mv3310_hwmon_config(struct phy_device *phydev, bool enable)
3140d3ad854SRussell King {
3150d3ad854SRussell King return 0;
3160d3ad854SRussell King }
3170d3ad854SRussell King
mv3310_hwmon_probe(struct phy_device * phydev)3180d3ad854SRussell King static int mv3310_hwmon_probe(struct phy_device *phydev)
3190d3ad854SRussell King {
3200d3ad854SRussell King return 0;
3210d3ad854SRussell King }
3220d3ad854SRussell King #endif
3230d3ad854SRussell King
mv3310_power_down(struct phy_device * phydev)324c9cc1c81SRussell King static int mv3310_power_down(struct phy_device *phydev)
325c9cc1c81SRussell King {
326c9cc1c81SRussell King return phy_set_bits_mmd(phydev, MDIO_MMD_VEND2, MV_V2_PORT_CTRL,
327c9cc1c81SRussell King MV_V2_PORT_CTRL_PWRDOWN);
328c9cc1c81SRussell King }
329c9cc1c81SRussell King
mv3310_power_up(struct phy_device * phydev)330c9cc1c81SRussell King static int mv3310_power_up(struct phy_device *phydev)
331c9cc1c81SRussell King {
3328f48c2acSRussell King struct mv3310_priv *priv = dev_get_drvdata(&phydev->mdio.dev);
3338f48c2acSRussell King int ret;
3348f48c2acSRussell King
3358f48c2acSRussell King ret = phy_clear_bits_mmd(phydev, MDIO_MMD_VEND2, MV_V2_PORT_CTRL,
336c9cc1c81SRussell King MV_V2_PORT_CTRL_PWRDOWN);
3378f48c2acSRussell King
338c7b75beaSJiawen Wu /* Sometimes, the power down bit doesn't clear immediately, and
339c7b75beaSJiawen Wu * a read of this register causes the bit not to clear. Delay
340c7b75beaSJiawen Wu * 100us to allow the PHY to come out of power down mode before
341c7b75beaSJiawen Wu * the next access.
342c7b75beaSJiawen Wu */
343c7b75beaSJiawen Wu udelay(100);
344c7b75beaSJiawen Wu
345829e7573SBaruch Siach if (phydev->drv->phy_id != MARVELL_PHY_ID_88X3310 ||
346829e7573SBaruch Siach priv->firmware_ver < 0x00030000)
3478f48c2acSRussell King return ret;
3488f48c2acSRussell King
3498f48c2acSRussell King return phy_set_bits_mmd(phydev, MDIO_MMD_VEND2, MV_V2_PORT_CTRL,
3509893f316SMarek Behún MV_V2_33X0_PORT_CTRL_SWRST);
351c9cc1c81SRussell King }
352c9cc1c81SRussell King
mv3310_reset(struct phy_device * phydev,u32 unit)3538d8963c3SRussell King static int mv3310_reset(struct phy_device *phydev, u32 unit)
3548d8963c3SRussell King {
3558964a217SDejin Zheng int val, err;
3568d8963c3SRussell King
3578d8963c3SRussell King err = phy_modify_mmd(phydev, MDIO_MMD_PCS, unit + MDIO_CTRL1,
3588d8963c3SRussell King MDIO_CTRL1_RESET, MDIO_CTRL1_RESET);
3598d8963c3SRussell King if (err < 0)
3608d8963c3SRussell King return err;
3618d8963c3SRussell King
3628964a217SDejin Zheng return phy_read_mmd_poll_timeout(phydev, MDIO_MMD_PCS,
3638964a217SDejin Zheng unit + MDIO_CTRL1, val,
3648964a217SDejin Zheng !(val & MDIO_CTRL1_RESET),
3658964a217SDejin Zheng 5000, 100000, true);
3668d8963c3SRussell King }
3678d8963c3SRussell King
mv3310_get_downshift(struct phy_device * phydev,u8 * ds)3684075a6a0SRussell King static int mv3310_get_downshift(struct phy_device *phydev, u8 *ds)
3694075a6a0SRussell King {
3704075a6a0SRussell King struct mv3310_priv *priv = dev_get_drvdata(&phydev->mdio.dev);
3714075a6a0SRussell King int val;
3724075a6a0SRussell King
3734075a6a0SRussell King if (!priv->has_downshift)
3744075a6a0SRussell King return -EOPNOTSUPP;
3754075a6a0SRussell King
3764075a6a0SRussell King val = phy_read_mmd(phydev, MDIO_MMD_PCS, MV_PCS_DSC1);
3774075a6a0SRussell King if (val < 0)
3784075a6a0SRussell King return val;
3794075a6a0SRussell King
3804075a6a0SRussell King if (val & MV_PCS_DSC1_ENABLE)
3814075a6a0SRussell King /* assume that all fields are the same */
3824075a6a0SRussell King *ds = 1 + FIELD_GET(MV_PCS_DSC1_10GBT, (u16)val);
3834075a6a0SRussell King else
3844075a6a0SRussell King *ds = DOWNSHIFT_DEV_DISABLE;
3854075a6a0SRussell King
3864075a6a0SRussell King return 0;
3874075a6a0SRussell King }
3884075a6a0SRussell King
mv3310_set_downshift(struct phy_device * phydev,u8 ds)3894075a6a0SRussell King static int mv3310_set_downshift(struct phy_device *phydev, u8 ds)
3904075a6a0SRussell King {
3914075a6a0SRussell King struct mv3310_priv *priv = dev_get_drvdata(&phydev->mdio.dev);
3924075a6a0SRussell King u16 val;
3934075a6a0SRussell King int err;
3944075a6a0SRussell King
3954075a6a0SRussell King if (!priv->has_downshift)
3964075a6a0SRussell King return -EOPNOTSUPP;
3974075a6a0SRussell King
3984075a6a0SRussell King if (ds == DOWNSHIFT_DEV_DISABLE)
3994075a6a0SRussell King return phy_clear_bits_mmd(phydev, MDIO_MMD_PCS, MV_PCS_DSC1,
4004075a6a0SRussell King MV_PCS_DSC1_ENABLE);
4014075a6a0SRussell King
4024075a6a0SRussell King /* DOWNSHIFT_DEV_DEFAULT_COUNT is confusing. It looks like it should
4034075a6a0SRussell King * set the default settings for the PHY. However, it is used for
4044075a6a0SRussell King * "ethtool --set-phy-tunable ethN downshift on". The intention is
4054075a6a0SRussell King * to enable downshift at a default number of retries. The default
4064075a6a0SRussell King * settings for 88x3310 are for two retries with downshift disabled.
4074075a6a0SRussell King * So let's use two retries with downshift enabled.
4084075a6a0SRussell King */
4094075a6a0SRussell King if (ds == DOWNSHIFT_DEV_DEFAULT_COUNT)
4104075a6a0SRussell King ds = 2;
4114075a6a0SRussell King
4124075a6a0SRussell King if (ds > 8)
4134075a6a0SRussell King return -E2BIG;
4144075a6a0SRussell King
4154075a6a0SRussell King ds -= 1;
4164075a6a0SRussell King val = FIELD_PREP(MV_PCS_DSC2_2P5G, ds);
4174075a6a0SRussell King val |= FIELD_PREP(MV_PCS_DSC2_5G, ds);
4184075a6a0SRussell King err = phy_modify_mmd(phydev, MDIO_MMD_PCS, MV_PCS_DSC2,
4194075a6a0SRussell King MV_PCS_DSC2_2P5G | MV_PCS_DSC2_5G, val);
4204075a6a0SRussell King if (err < 0)
4214075a6a0SRussell King return err;
4224075a6a0SRussell King
4234075a6a0SRussell King val = MV_PCS_DSC1_ENABLE;
4244075a6a0SRussell King val |= FIELD_PREP(MV_PCS_DSC1_10GBT, ds);
4254075a6a0SRussell King val |= FIELD_PREP(MV_PCS_DSC1_1GBR, ds);
4264075a6a0SRussell King val |= FIELD_PREP(MV_PCS_DSC1_100BTX, ds);
4274075a6a0SRussell King
4284075a6a0SRussell King return phy_modify_mmd(phydev, MDIO_MMD_PCS, MV_PCS_DSC1,
4294075a6a0SRussell King MV_PCS_DSC1_ENABLE | MV_PCS_DSC1_10GBT |
4304075a6a0SRussell King MV_PCS_DSC1_1GBR | MV_PCS_DSC1_100BTX, val);
4314075a6a0SRussell King }
4324075a6a0SRussell King
mv3310_get_edpd(struct phy_device * phydev,u16 * edpd)433a585c03eSRussell King static int mv3310_get_edpd(struct phy_device *phydev, u16 *edpd)
434a585c03eSRussell King {
435a585c03eSRussell King int val;
436a585c03eSRussell King
437a585c03eSRussell King val = phy_read_mmd(phydev, MDIO_MMD_PCS, MV_PCS_CSCR1);
438a585c03eSRussell King if (val < 0)
439a585c03eSRussell King return val;
440a585c03eSRussell King
441a585c03eSRussell King switch (val & MV_PCS_CSCR1_ED_MASK) {
442a585c03eSRussell King case MV_PCS_CSCR1_ED_NLP:
443a585c03eSRussell King *edpd = 1000;
444a585c03eSRussell King break;
445a585c03eSRussell King case MV_PCS_CSCR1_ED_RX:
446a585c03eSRussell King *edpd = ETHTOOL_PHY_EDPD_NO_TX;
447a585c03eSRussell King break;
448a585c03eSRussell King default:
449a585c03eSRussell King *edpd = ETHTOOL_PHY_EDPD_DISABLE;
450a585c03eSRussell King break;
451a585c03eSRussell King }
452a585c03eSRussell King return 0;
453a585c03eSRussell King }
454a585c03eSRussell King
mv3310_set_edpd(struct phy_device * phydev,u16 edpd)455a585c03eSRussell King static int mv3310_set_edpd(struct phy_device *phydev, u16 edpd)
456a585c03eSRussell King {
457a585c03eSRussell King u16 val;
458a585c03eSRussell King int err;
459a585c03eSRussell King
460a585c03eSRussell King switch (edpd) {
461a585c03eSRussell King case 1000:
462a585c03eSRussell King case ETHTOOL_PHY_EDPD_DFLT_TX_MSECS:
463a585c03eSRussell King val = MV_PCS_CSCR1_ED_NLP;
464a585c03eSRussell King break;
465a585c03eSRussell King
466a585c03eSRussell King case ETHTOOL_PHY_EDPD_NO_TX:
467a585c03eSRussell King val = MV_PCS_CSCR1_ED_RX;
468a585c03eSRussell King break;
469a585c03eSRussell King
470a585c03eSRussell King case ETHTOOL_PHY_EDPD_DISABLE:
471a585c03eSRussell King val = MV_PCS_CSCR1_ED_OFF;
472a585c03eSRussell King break;
473a585c03eSRussell King
474a585c03eSRussell King default:
475a585c03eSRussell King return -EINVAL;
476a585c03eSRussell King }
477a585c03eSRussell King
478a585c03eSRussell King err = phy_modify_mmd_changed(phydev, MDIO_MMD_PCS, MV_PCS_CSCR1,
479a585c03eSRussell King MV_PCS_CSCR1_ED_MASK, val);
480a585c03eSRussell King if (err > 0)
481a585c03eSRussell King err = mv3310_reset(phydev, MV_PCS_BASE_T);
482a585c03eSRussell King
483a585c03eSRussell King return err;
484a585c03eSRussell King }
485a585c03eSRussell King
mv3310_sfp_insert(void * upstream,const struct sfp_eeprom_id * id)48636023da1SRussell King static int mv3310_sfp_insert(void *upstream, const struct sfp_eeprom_id *id)
48736023da1SRussell King {
48836023da1SRussell King struct phy_device *phydev = upstream;
48936023da1SRussell King __ETHTOOL_DECLARE_LINK_MODE_MASK(support) = { 0, };
490fd580c98SRussell King DECLARE_PHY_INTERFACE_MASK(interfaces);
49136023da1SRussell King phy_interface_t iface;
49236023da1SRussell King
493fd580c98SRussell King sfp_parse_support(phydev->sfp_bus, id, support, interfaces);
494a4516c70SRussell King iface = sfp_select_interface(phydev->sfp_bus, support);
49536023da1SRussell King
496e0f909bcSRussell King if (iface != PHY_INTERFACE_MODE_10GBASER) {
49736023da1SRussell King dev_err(&phydev->mdio.dev, "incompatible SFP module inserted\n");
49836023da1SRussell King return -EINVAL;
49936023da1SRussell King }
50036023da1SRussell King return 0;
50136023da1SRussell King }
50236023da1SRussell King
50336023da1SRussell King static const struct sfp_upstream_ops mv3310_sfp_ops = {
50436023da1SRussell King .attach = phy_sfp_attach,
50536023da1SRussell King .detach = phy_sfp_detach,
506*b2db6f4aSMaxime Chevallier .connect_phy = phy_sfp_connect_phy,
507*b2db6f4aSMaxime Chevallier .disconnect_phy = phy_sfp_disconnect_phy,
50836023da1SRussell King .module_insert = mv3310_sfp_insert,
50936023da1SRussell King };
51036023da1SRussell King
mv3310_probe(struct phy_device * phydev)51120b2af32SRussell King static int mv3310_probe(struct phy_device *phydev)
51220b2af32SRussell King {
513261a74c6SMarek Behún const struct mv3310_chip *chip = to_mv3310_chip(phydev);
5140d3ad854SRussell King struct mv3310_priv *priv;
51520b2af32SRussell King u32 mmd_mask = MDIO_DEVS_PMAPMD | MDIO_DEVS_AN;
5160d3ad854SRussell King int ret;
51720b2af32SRussell King
51820b2af32SRussell King if (!phydev->is_c45 ||
51920b2af32SRussell King (phydev->c45_ids.devices_in_package & mmd_mask) != mmd_mask)
52020b2af32SRussell King return -ENODEV;
52120b2af32SRussell King
5223d3ced2eSRussell King ret = phy_read_mmd(phydev, MDIO_MMD_PMAPMD, MV_PMA_BOOT);
5233d3ced2eSRussell King if (ret < 0)
5243d3ced2eSRussell King return ret;
5253d3ced2eSRussell King
5263d3ced2eSRussell King if (ret & MV_PMA_BOOT_FATAL) {
5273d3ced2eSRussell King dev_warn(&phydev->mdio.dev,
5283d3ced2eSRussell King "PHY failed to boot firmware, status=%04x\n", ret);
5293d3ced2eSRussell King return -ENODEV;
5303d3ced2eSRussell King }
5313d3ced2eSRussell King
5320d3ad854SRussell King priv = devm_kzalloc(&phydev->mdio.dev, sizeof(*priv), GFP_KERNEL);
5330d3ad854SRussell King if (!priv)
5340d3ad854SRussell King return -ENOMEM;
5350d3ad854SRussell King
5360d3ad854SRussell King dev_set_drvdata(&phydev->mdio.dev, priv);
5370d3ad854SRussell King
538dd649b4fSRussell King ret = phy_read_mmd(phydev, MDIO_MMD_PMAPMD, MV_PMA_FW_VER0);
539dd649b4fSRussell King if (ret < 0)
540dd649b4fSRussell King return ret;
541dd649b4fSRussell King
542dd649b4fSRussell King priv->firmware_ver = ret << 16;
543dd649b4fSRussell King
544dd649b4fSRussell King ret = phy_read_mmd(phydev, MDIO_MMD_PMAPMD, MV_PMA_FW_VER1);
545dd649b4fSRussell King if (ret < 0)
546dd649b4fSRussell King return ret;
547dd649b4fSRussell King
548dd649b4fSRussell King priv->firmware_ver |= ret;
549dd649b4fSRussell King
550dd649b4fSRussell King phydev_info(phydev, "Firmware version %u.%u.%u.%u\n",
551dd649b4fSRussell King priv->firmware_ver >> 24, (priv->firmware_ver >> 16) & 255,
552dd649b4fSRussell King (priv->firmware_ver >> 8) & 255, priv->firmware_ver & 255);
553dd649b4fSRussell King
5544075a6a0SRussell King if (chip->has_downshift)
5554075a6a0SRussell King priv->has_downshift = chip->has_downshift(phydev);
5564075a6a0SRussell King
557c9cc1c81SRussell King /* Powering down the port when not in use saves about 600mW */
558c9cc1c81SRussell King ret = mv3310_power_down(phydev);
559c9cc1c81SRussell King if (ret)
560c9cc1c81SRussell King return ret;
561c9cc1c81SRussell King
5620d3ad854SRussell King ret = mv3310_hwmon_probe(phydev);
5630d3ad854SRussell King if (ret)
5640d3ad854SRussell King return ret;
5650d3ad854SRussell King
566261a74c6SMarek Behún chip->init_supported_interfaces(priv->supported_interfaces);
567261a74c6SMarek Behún
56836023da1SRussell King return phy_sfp_probe(phydev, &mv3310_sfp_ops);
56920b2af32SRussell King }
57020b2af32SRussell King
mv3310_remove(struct phy_device * phydev)5711b8ef142SMarek Behún static void mv3310_remove(struct phy_device *phydev)
5721b8ef142SMarek Behún {
5731b8ef142SMarek Behún mv3310_hwmon_config(phydev, false);
5741b8ef142SMarek Behún }
5751b8ef142SMarek Behún
mv3310_suspend(struct phy_device * phydev)5760d3ad854SRussell King static int mv3310_suspend(struct phy_device *phydev)
5770d3ad854SRussell King {
578c9cc1c81SRussell King return mv3310_power_down(phydev);
5790d3ad854SRussell King }
5800d3ad854SRussell King
mv3310_resume(struct phy_device * phydev)5810d3ad854SRussell King static int mv3310_resume(struct phy_device *phydev)
5820d3ad854SRussell King {
583af3e28cbSAntoine Tenart int ret;
584af3e28cbSAntoine Tenart
585c9cc1c81SRussell King ret = mv3310_power_up(phydev);
586af3e28cbSAntoine Tenart if (ret)
587af3e28cbSAntoine Tenart return ret;
588af3e28cbSAntoine Tenart
5890d3ad854SRussell King return mv3310_hwmon_config(phydev, true);
5900d3ad854SRussell King }
5910d3ad854SRussell King
592c47455f9SMaxime Chevallier /* Some PHYs in the Alaska family such as the 88X3310 and the 88E2010
593c47455f9SMaxime Chevallier * don't set bit 14 in PMA Extended Abilities (1.11), although they do
594c47455f9SMaxime Chevallier * support 2.5GBASET and 5GBASET. For these models, we can still read their
595c47455f9SMaxime Chevallier * 2.5G/5G extended abilities register (1.21). We detect these models based on
596c47455f9SMaxime Chevallier * the PMA device identifier, with a mask matching models known to have this
597c47455f9SMaxime Chevallier * issue
598c47455f9SMaxime Chevallier */
mv3310_has_pma_ngbaset_quirk(struct phy_device * phydev)599c47455f9SMaxime Chevallier static bool mv3310_has_pma_ngbaset_quirk(struct phy_device *phydev)
600c47455f9SMaxime Chevallier {
601c47455f9SMaxime Chevallier if (!(phydev->c45_ids.devices_in_package & MDIO_DEVS_PMAPMD))
602c47455f9SMaxime Chevallier return false;
603c47455f9SMaxime Chevallier
604c47455f9SMaxime Chevallier /* Only some revisions of the 88X3310 family PMA seem to be impacted */
605c47455f9SMaxime Chevallier return (phydev->c45_ids.device_ids[MDIO_MMD_PMAPMD] &
606c47455f9SMaxime Chevallier MV_PHY_ALASKA_NBT_QUIRK_MASK) == MV_PHY_ALASKA_NBT_QUIRK_REV;
607c47455f9SMaxime Chevallier }
608c47455f9SMaxime Chevallier
mv2110_get_mactype(struct phy_device * phydev)60997bbe3bdSMarek Behún static int mv2110_get_mactype(struct phy_device *phydev)
61097bbe3bdSMarek Behún {
61197bbe3bdSMarek Behún int mactype;
61297bbe3bdSMarek Behún
61397bbe3bdSMarek Behún mactype = phy_read_mmd(phydev, MDIO_MMD_PMAPMD, MV_PMA_21X0_PORT_CTRL);
61497bbe3bdSMarek Behún if (mactype < 0)
61597bbe3bdSMarek Behún return mactype;
61697bbe3bdSMarek Behún
61797bbe3bdSMarek Behún return mactype & MV_PMA_21X0_PORT_CTRL_MACTYPE_MASK;
61897bbe3bdSMarek Behún }
61997bbe3bdSMarek Behún
mv2110_set_mactype(struct phy_device * phydev,int mactype)620d6d29292SRussell King static int mv2110_set_mactype(struct phy_device *phydev, int mactype)
621d6d29292SRussell King {
622d6d29292SRussell King int err, val;
623d6d29292SRussell King
624d6d29292SRussell King mactype &= MV_PMA_21X0_PORT_CTRL_MACTYPE_MASK;
625d6d29292SRussell King err = phy_modify_mmd(phydev, MDIO_MMD_PMAPMD, MV_PMA_21X0_PORT_CTRL,
626d6d29292SRussell King MV_PMA_21X0_PORT_CTRL_SWRST |
627d6d29292SRussell King MV_PMA_21X0_PORT_CTRL_MACTYPE_MASK,
628d6d29292SRussell King MV_PMA_21X0_PORT_CTRL_SWRST | mactype);
629d6d29292SRussell King if (err)
630d6d29292SRussell King return err;
631d6d29292SRussell King
632d6d29292SRussell King err = phy_set_bits_mmd(phydev, MDIO_MMD_AN, MV_AN_21X0_SERDES_CTRL2,
633d6d29292SRussell King MV_AN_21X0_SERDES_CTRL2_AUTO_INIT_DIS |
634d6d29292SRussell King MV_AN_21X0_SERDES_CTRL2_RUN_INIT);
635d6d29292SRussell King if (err)
636d6d29292SRussell King return err;
637d6d29292SRussell King
638d6d29292SRussell King err = phy_read_mmd_poll_timeout(phydev, MDIO_MMD_AN,
639d6d29292SRussell King MV_AN_21X0_SERDES_CTRL2, val,
640d6d29292SRussell King !(val &
641d6d29292SRussell King MV_AN_21X0_SERDES_CTRL2_RUN_INIT),
642d6d29292SRussell King 5000, 100000, true);
643d6d29292SRussell King if (err)
644d6d29292SRussell King return err;
645d6d29292SRussell King
646d6d29292SRussell King return phy_clear_bits_mmd(phydev, MDIO_MMD_AN, MV_AN_21X0_SERDES_CTRL2,
647d6d29292SRussell King MV_AN_21X0_SERDES_CTRL2_AUTO_INIT_DIS);
648d6d29292SRussell King }
649d6d29292SRussell King
mv2110_select_mactype(unsigned long * interfaces)650d6d29292SRussell King static int mv2110_select_mactype(unsigned long *interfaces)
651d6d29292SRussell King {
652d6d29292SRussell King if (test_bit(PHY_INTERFACE_MODE_USXGMII, interfaces))
653d6d29292SRussell King return MV_PMA_21X0_PORT_CTRL_MACTYPE_USXGMII;
654d6d29292SRussell King else if (test_bit(PHY_INTERFACE_MODE_SGMII, interfaces) &&
655d6d29292SRussell King !test_bit(PHY_INTERFACE_MODE_10GBASER, interfaces))
656d6d29292SRussell King return MV_PMA_21X0_PORT_CTRL_MACTYPE_5GBASER;
657d6d29292SRussell King else if (test_bit(PHY_INTERFACE_MODE_10GBASER, interfaces))
658d6d29292SRussell King return MV_PMA_21X0_PORT_CTRL_MACTYPE_10GBASER_RATE_MATCH;
659d6d29292SRussell King else
660d6d29292SRussell King return -1;
661d6d29292SRussell King }
662d6d29292SRussell King
mv3310_get_mactype(struct phy_device * phydev)66397bbe3bdSMarek Behún static int mv3310_get_mactype(struct phy_device *phydev)
66497bbe3bdSMarek Behún {
66597bbe3bdSMarek Behún int mactype;
66697bbe3bdSMarek Behún
66797bbe3bdSMarek Behún mactype = phy_read_mmd(phydev, MDIO_MMD_VEND2, MV_V2_PORT_CTRL);
66897bbe3bdSMarek Behún if (mactype < 0)
66997bbe3bdSMarek Behún return mactype;
67097bbe3bdSMarek Behún
67197bbe3bdSMarek Behún return mactype & MV_V2_33X0_PORT_CTRL_MACTYPE_MASK;
67297bbe3bdSMarek Behún }
67397bbe3bdSMarek Behún
mv3310_set_mactype(struct phy_device * phydev,int mactype)674d6d29292SRussell King static int mv3310_set_mactype(struct phy_device *phydev, int mactype)
675d6d29292SRussell King {
676d6d29292SRussell King int ret;
677d6d29292SRussell King
678d6d29292SRussell King mactype &= MV_V2_33X0_PORT_CTRL_MACTYPE_MASK;
679d6d29292SRussell King ret = phy_modify_mmd_changed(phydev, MDIO_MMD_VEND2, MV_V2_PORT_CTRL,
680d6d29292SRussell King MV_V2_33X0_PORT_CTRL_MACTYPE_MASK,
681d6d29292SRussell King mactype);
682d6d29292SRussell King if (ret <= 0)
683d6d29292SRussell King return ret;
684d6d29292SRussell King
685d6d29292SRussell King return phy_set_bits_mmd(phydev, MDIO_MMD_VEND2, MV_V2_PORT_CTRL,
686d6d29292SRussell King MV_V2_33X0_PORT_CTRL_SWRST);
687d6d29292SRussell King }
688d6d29292SRussell King
mv3310_select_mactype(unsigned long * interfaces)689d6d29292SRussell King static int mv3310_select_mactype(unsigned long *interfaces)
690d6d29292SRussell King {
691d6d29292SRussell King if (test_bit(PHY_INTERFACE_MODE_USXGMII, interfaces))
692d6d29292SRussell King return MV_V2_33X0_PORT_CTRL_MACTYPE_USXGMII;
693d6d29292SRussell King else if (test_bit(PHY_INTERFACE_MODE_SGMII, interfaces) &&
694d6d29292SRussell King test_bit(PHY_INTERFACE_MODE_10GBASER, interfaces))
695d6d29292SRussell King return MV_V2_33X0_PORT_CTRL_MACTYPE_10GBASER;
696d6d29292SRussell King else if (test_bit(PHY_INTERFACE_MODE_SGMII, interfaces) &&
697d6d29292SRussell King test_bit(PHY_INTERFACE_MODE_RXAUI, interfaces))
698d6d29292SRussell King return MV_V2_33X0_PORT_CTRL_MACTYPE_RXAUI;
699d6d29292SRussell King else if (test_bit(PHY_INTERFACE_MODE_SGMII, interfaces) &&
700d6d29292SRussell King test_bit(PHY_INTERFACE_MODE_XAUI, interfaces))
701d6d29292SRussell King return MV_V2_3310_PORT_CTRL_MACTYPE_XAUI;
702d6d29292SRussell King else if (test_bit(PHY_INTERFACE_MODE_10GBASER, interfaces))
703d6d29292SRussell King return MV_V2_33X0_PORT_CTRL_MACTYPE_10GBASER_RATE_MATCH;
704d6d29292SRussell King else if (test_bit(PHY_INTERFACE_MODE_RXAUI, interfaces))
705d6d29292SRussell King return MV_V2_33X0_PORT_CTRL_MACTYPE_RXAUI_RATE_MATCH;
706d6d29292SRussell King else if (test_bit(PHY_INTERFACE_MODE_XAUI, interfaces))
707d6d29292SRussell King return MV_V2_3310_PORT_CTRL_MACTYPE_XAUI_RATE_MATCH;
708d6d29292SRussell King else if (test_bit(PHY_INTERFACE_MODE_SGMII, interfaces))
709d6d29292SRussell King return MV_V2_33X0_PORT_CTRL_MACTYPE_10GBASER;
710d6d29292SRussell King else
711d6d29292SRussell King return -1;
712d6d29292SRussell King }
713d6d29292SRussell King
7142cb6d63bSRussell King (Oracle) static const struct mv3310_mactype mv2110_mactypes[] = {
7152cb6d63bSRussell King (Oracle) [MV_PMA_21X0_PORT_CTRL_MACTYPE_USXGMII] = {
7162cb6d63bSRussell King (Oracle) .valid = true,
7172cb6d63bSRussell King (Oracle) .fixed_interface = true,
7182cb6d63bSRussell King (Oracle) .interface_10g = PHY_INTERFACE_MODE_USXGMII,
7192cb6d63bSRussell King (Oracle) },
7202cb6d63bSRussell King (Oracle) [MV_PMA_21X0_PORT_CTRL_MACTYPE_5GBASER] = {
7212cb6d63bSRussell King (Oracle) .valid = true,
7222cb6d63bSRussell King (Oracle) .interface_10g = PHY_INTERFACE_MODE_NA,
7232cb6d63bSRussell King (Oracle) },
7242cb6d63bSRussell King (Oracle) [MV_PMA_21X0_PORT_CTRL_MACTYPE_5GBASER_NO_SGMII_AN] = {
7252cb6d63bSRussell King (Oracle) .valid = true,
7262cb6d63bSRussell King (Oracle) .interface_10g = PHY_INTERFACE_MODE_NA,
7272cb6d63bSRussell King (Oracle) },
7282cb6d63bSRussell King (Oracle) [MV_PMA_21X0_PORT_CTRL_MACTYPE_10GBASER_RATE_MATCH] = {
7292cb6d63bSRussell King (Oracle) .valid = true,
7302cb6d63bSRussell King (Oracle) .fixed_interface = true,
7312cb6d63bSRussell King (Oracle) .interface_10g = PHY_INTERFACE_MODE_10GBASER,
7322cb6d63bSRussell King (Oracle) },
7332cb6d63bSRussell King (Oracle) };
73497bbe3bdSMarek Behún
7352cb6d63bSRussell King (Oracle) static const struct mv3310_mactype mv3310_mactypes[] = {
7362cb6d63bSRussell King (Oracle) [MV_V2_33X0_PORT_CTRL_MACTYPE_RXAUI] = {
7372cb6d63bSRussell King (Oracle) .valid = true,
7382cb6d63bSRussell King (Oracle) .interface_10g = PHY_INTERFACE_MODE_RXAUI,
7392cb6d63bSRussell King (Oracle) },
7402cb6d63bSRussell King (Oracle) [MV_V2_3310_PORT_CTRL_MACTYPE_XAUI_RATE_MATCH] = {
7412cb6d63bSRussell King (Oracle) .valid = true,
7422cb6d63bSRussell King (Oracle) .fixed_interface = true,
7432cb6d63bSRussell King (Oracle) .interface_10g = PHY_INTERFACE_MODE_XAUI,
7442cb6d63bSRussell King (Oracle) },
7452cb6d63bSRussell King (Oracle) [MV_V2_33X0_PORT_CTRL_MACTYPE_RXAUI_RATE_MATCH] = {
7462cb6d63bSRussell King (Oracle) .valid = true,
7472cb6d63bSRussell King (Oracle) .fixed_interface = true,
7482cb6d63bSRussell King (Oracle) .interface_10g = PHY_INTERFACE_MODE_RXAUI,
7492cb6d63bSRussell King (Oracle) },
7502cb6d63bSRussell King (Oracle) [MV_V2_3310_PORT_CTRL_MACTYPE_XAUI] = {
7512cb6d63bSRussell King (Oracle) .valid = true,
7522cb6d63bSRussell King (Oracle) .interface_10g = PHY_INTERFACE_MODE_XAUI,
7532cb6d63bSRussell King (Oracle) },
7542cb6d63bSRussell King (Oracle) [MV_V2_33X0_PORT_CTRL_MACTYPE_10GBASER] = {
7552cb6d63bSRussell King (Oracle) .valid = true,
7562cb6d63bSRussell King (Oracle) .interface_10g = PHY_INTERFACE_MODE_10GBASER,
7572cb6d63bSRussell King (Oracle) },
7582cb6d63bSRussell King (Oracle) [MV_V2_33X0_PORT_CTRL_MACTYPE_10GBASER_NO_SGMII_AN] = {
7592cb6d63bSRussell King (Oracle) .valid = true,
7602cb6d63bSRussell King (Oracle) .interface_10g = PHY_INTERFACE_MODE_10GBASER,
7612cb6d63bSRussell King (Oracle) },
7622cb6d63bSRussell King (Oracle) [MV_V2_33X0_PORT_CTRL_MACTYPE_10GBASER_RATE_MATCH] = {
7632cb6d63bSRussell King (Oracle) .valid = true,
7642cb6d63bSRussell King (Oracle) .fixed_interface = true,
7652cb6d63bSRussell King (Oracle) .interface_10g = PHY_INTERFACE_MODE_10GBASER,
7662cb6d63bSRussell King (Oracle) },
7672cb6d63bSRussell King (Oracle) [MV_V2_33X0_PORT_CTRL_MACTYPE_USXGMII] = {
7682cb6d63bSRussell King (Oracle) .valid = true,
7692cb6d63bSRussell King (Oracle) .fixed_interface = true,
7702cb6d63bSRussell King (Oracle) .interface_10g = PHY_INTERFACE_MODE_USXGMII,
7712cb6d63bSRussell King (Oracle) },
7722cb6d63bSRussell King (Oracle) };
77397bbe3bdSMarek Behún
7742cb6d63bSRussell King (Oracle) static const struct mv3310_mactype mv3340_mactypes[] = {
7752cb6d63bSRussell King (Oracle) [MV_V2_33X0_PORT_CTRL_MACTYPE_RXAUI] = {
7762cb6d63bSRussell King (Oracle) .valid = true,
7772cb6d63bSRussell King (Oracle) .interface_10g = PHY_INTERFACE_MODE_RXAUI,
7782cb6d63bSRussell King (Oracle) },
7792cb6d63bSRussell King (Oracle) [MV_V2_3340_PORT_CTRL_MACTYPE_RXAUI_NO_SGMII_AN] = {
7802cb6d63bSRussell King (Oracle) .valid = true,
7812cb6d63bSRussell King (Oracle) .interface_10g = PHY_INTERFACE_MODE_RXAUI,
7822cb6d63bSRussell King (Oracle) },
7832cb6d63bSRussell King (Oracle) [MV_V2_33X0_PORT_CTRL_MACTYPE_RXAUI_RATE_MATCH] = {
7842cb6d63bSRussell King (Oracle) .valid = true,
7852cb6d63bSRussell King (Oracle) .fixed_interface = true,
7862cb6d63bSRussell King (Oracle) .interface_10g = PHY_INTERFACE_MODE_RXAUI,
7872cb6d63bSRussell King (Oracle) },
7882cb6d63bSRussell King (Oracle) [MV_V2_33X0_PORT_CTRL_MACTYPE_10GBASER] = {
7892cb6d63bSRussell King (Oracle) .valid = true,
7902cb6d63bSRussell King (Oracle) .interface_10g = PHY_INTERFACE_MODE_10GBASER,
7912cb6d63bSRussell King (Oracle) },
7922cb6d63bSRussell King (Oracle) [MV_V2_33X0_PORT_CTRL_MACTYPE_10GBASER_NO_SGMII_AN] = {
7932cb6d63bSRussell King (Oracle) .valid = true,
7942cb6d63bSRussell King (Oracle) .interface_10g = PHY_INTERFACE_MODE_10GBASER,
7952cb6d63bSRussell King (Oracle) },
7962cb6d63bSRussell King (Oracle) [MV_V2_33X0_PORT_CTRL_MACTYPE_10GBASER_RATE_MATCH] = {
7972cb6d63bSRussell King (Oracle) .valid = true,
7982cb6d63bSRussell King (Oracle) .fixed_interface = true,
7992cb6d63bSRussell King (Oracle) .interface_10g = PHY_INTERFACE_MODE_10GBASER,
8002cb6d63bSRussell King (Oracle) },
8012cb6d63bSRussell King (Oracle) [MV_V2_33X0_PORT_CTRL_MACTYPE_USXGMII] = {
8022cb6d63bSRussell King (Oracle) .valid = true,
8032cb6d63bSRussell King (Oracle) .fixed_interface = true,
8042cb6d63bSRussell King (Oracle) .interface_10g = PHY_INTERFACE_MODE_USXGMII,
8052cb6d63bSRussell King (Oracle) },
8062cb6d63bSRussell King (Oracle) };
8079885d016SMarek Behún
mv3310_fill_possible_interfaces(struct phy_device * phydev)80882f2e76bSRussell King (Oracle) static void mv3310_fill_possible_interfaces(struct phy_device *phydev)
80982f2e76bSRussell King (Oracle) {
81082f2e76bSRussell King (Oracle) struct mv3310_priv *priv = dev_get_drvdata(&phydev->mdio.dev);
81182f2e76bSRussell King (Oracle) unsigned long *possible = phydev->possible_interfaces;
81282f2e76bSRussell King (Oracle) const struct mv3310_mactype *mactype = priv->mactype;
81382f2e76bSRussell King (Oracle)
81482f2e76bSRussell King (Oracle) if (mactype->interface_10g != PHY_INTERFACE_MODE_NA)
81582f2e76bSRussell King (Oracle) __set_bit(priv->mactype->interface_10g, possible);
81682f2e76bSRussell King (Oracle)
81782f2e76bSRussell King (Oracle) if (!mactype->fixed_interface) {
81882f2e76bSRussell King (Oracle) __set_bit(PHY_INTERFACE_MODE_5GBASER, possible);
81982f2e76bSRussell King (Oracle) __set_bit(PHY_INTERFACE_MODE_2500BASEX, possible);
82082f2e76bSRussell King (Oracle) __set_bit(PHY_INTERFACE_MODE_SGMII, possible);
82182f2e76bSRussell King (Oracle) }
82282f2e76bSRussell King (Oracle) }
82382f2e76bSRussell King (Oracle)
mv3310_config_init(struct phy_device * phydev)82497bbe3bdSMarek Behún static int mv3310_config_init(struct phy_device *phydev)
82597bbe3bdSMarek Behún {
826261a74c6SMarek Behún struct mv3310_priv *priv = dev_get_drvdata(&phydev->mdio.dev);
82797bbe3bdSMarek Behún const struct mv3310_chip *chip = to_mv3310_chip(phydev);
82897bbe3bdSMarek Behún int err, mactype;
829c9cc1c81SRussell King
83020b2af32SRussell King /* Check that the PHY interface type is compatible */
831261a74c6SMarek Behún if (!test_bit(phydev->interface, priv->supported_interfaces))
83220b2af32SRussell King return -ENODEV;
83320b2af32SRussell King
8348d8963c3SRussell King phydev->mdix_ctrl = ETH_TP_MDI_AUTO;
8358d8963c3SRussell King
836c9cc1c81SRussell King /* Power up so reset works */
837c9cc1c81SRussell King err = mv3310_power_up(phydev);
838c9cc1c81SRussell King if (err)
839c9cc1c81SRussell King return err;
840c9cc1c81SRussell King
841d6d29292SRussell King /* If host provided host supported interface modes, try to select the
842d6d29292SRussell King * best one
843d6d29292SRussell King */
844d6d29292SRussell King if (!phy_interface_empty(phydev->host_interfaces)) {
845d6d29292SRussell King mactype = chip->select_mactype(phydev->host_interfaces);
846d6d29292SRussell King if (mactype >= 0) {
847d6d29292SRussell King phydev_info(phydev, "Changing MACTYPE to %i\n",
848d6d29292SRussell King mactype);
849d6d29292SRussell King err = chip->set_mactype(phydev, mactype);
850d6d29292SRussell King if (err)
851d6d29292SRussell King return err;
852d6d29292SRussell King }
853d6d29292SRussell King }
854d6d29292SRussell King
85597bbe3bdSMarek Behún mactype = chip->get_mactype(phydev);
85697bbe3bdSMarek Behún if (mactype < 0)
85797bbe3bdSMarek Behún return mactype;
85897bbe3bdSMarek Behún
8592cb6d63bSRussell King (Oracle) if (mactype >= chip->n_mactypes || !chip->mactypes[mactype].valid) {
860ccbf2891SMarek Behún phydev_err(phydev, "MACTYPE configuration invalid\n");
8612cb6d63bSRussell King (Oracle) return -EINVAL;
862ccbf2891SMarek Behún }
863e1170333SBaruch Siach
8642cb6d63bSRussell King (Oracle) priv->mactype = &chip->mactypes[mactype];
8652cb6d63bSRussell King (Oracle)
86682f2e76bSRussell King (Oracle) mv3310_fill_possible_interfaces(phydev);
86782f2e76bSRussell King (Oracle)
868a585c03eSRussell King /* Enable EDPD mode - saving 600mW */
8694075a6a0SRussell King err = mv3310_set_edpd(phydev, ETHTOOL_PHY_EDPD_DFLT_TX_MSECS);
8704075a6a0SRussell King if (err)
8714075a6a0SRussell King return err;
8724075a6a0SRussell King
8734075a6a0SRussell King /* Allow downshift */
8744075a6a0SRussell King err = mv3310_set_downshift(phydev, DOWNSHIFT_DEV_DEFAULT_COUNT);
8754075a6a0SRussell King if (err && err != -EOPNOTSUPP)
8764075a6a0SRussell King return err;
8774075a6a0SRussell King
8784075a6a0SRussell King return 0;
87974145424SMaxime Chevallier }
88074145424SMaxime Chevallier
mv3310_get_features(struct phy_device * phydev)88174145424SMaxime Chevallier static int mv3310_get_features(struct phy_device *phydev)
88274145424SMaxime Chevallier {
88374145424SMaxime Chevallier int ret, val;
88474145424SMaxime Chevallier
885ac3f5533SMaxime Chevallier ret = genphy_c45_pma_read_abilities(phydev);
886ac3f5533SMaxime Chevallier if (ret)
887ac3f5533SMaxime Chevallier return ret;
88820b2af32SRussell King
889c47455f9SMaxime Chevallier if (mv3310_has_pma_ngbaset_quirk(phydev)) {
890c47455f9SMaxime Chevallier val = phy_read_mmd(phydev, MDIO_MMD_PMAPMD,
891c47455f9SMaxime Chevallier MDIO_PMA_NG_EXTABLE);
892c47455f9SMaxime Chevallier if (val < 0)
893c47455f9SMaxime Chevallier return val;
894c47455f9SMaxime Chevallier
895c47455f9SMaxime Chevallier linkmode_mod_bit(ETHTOOL_LINK_MODE_2500baseT_Full_BIT,
896c47455f9SMaxime Chevallier phydev->supported,
897c47455f9SMaxime Chevallier val & MDIO_PMA_NG_EXTABLE_2_5GBT);
898c47455f9SMaxime Chevallier
899c47455f9SMaxime Chevallier linkmode_mod_bit(ETHTOOL_LINK_MODE_5000baseT_Full_BIT,
900c47455f9SMaxime Chevallier phydev->supported,
901c47455f9SMaxime Chevallier val & MDIO_PMA_NG_EXTABLE_5GBT);
902c47455f9SMaxime Chevallier }
903c47455f9SMaxime Chevallier
90420b2af32SRussell King return 0;
90520b2af32SRussell King }
90620b2af32SRussell King
mv3310_config_mdix(struct phy_device * phydev)9078d8963c3SRussell King static int mv3310_config_mdix(struct phy_device *phydev)
9088d8963c3SRussell King {
9098d8963c3SRussell King u16 val;
9108d8963c3SRussell King int err;
9118d8963c3SRussell King
9128d8963c3SRussell King switch (phydev->mdix_ctrl) {
9138d8963c3SRussell King case ETH_TP_MDI_AUTO:
9148d8963c3SRussell King val = MV_PCS_CSCR1_MDIX_AUTO;
9158d8963c3SRussell King break;
9168d8963c3SRussell King case ETH_TP_MDI_X:
9178d8963c3SRussell King val = MV_PCS_CSCR1_MDIX_MDIX;
9188d8963c3SRussell King break;
9198d8963c3SRussell King case ETH_TP_MDI:
9208d8963c3SRussell King val = MV_PCS_CSCR1_MDIX_MDI;
9218d8963c3SRussell King break;
9228d8963c3SRussell King default:
9238d8963c3SRussell King return -EINVAL;
9248d8963c3SRussell King }
9258d8963c3SRussell King
9268d8963c3SRussell King err = phy_modify_mmd_changed(phydev, MDIO_MMD_PCS, MV_PCS_CSCR1,
9278d8963c3SRussell King MV_PCS_CSCR1_MDIX_MASK, val);
9288d8963c3SRussell King if (err > 0)
9298d8963c3SRussell King err = mv3310_reset(phydev, MV_PCS_BASE_T);
9308d8963c3SRussell King
9318d8963c3SRussell King return err;
9328d8963c3SRussell King }
9338d8963c3SRussell King
mv3310_config_aneg(struct phy_device * phydev)93420b2af32SRussell King static int mv3310_config_aneg(struct phy_device *phydev)
93520b2af32SRussell King {
93620b2af32SRussell King bool changed = false;
9373c1bcc86SAndrew Lunn u16 reg;
93820b2af32SRussell King int ret;
93920b2af32SRussell King
9408d8963c3SRussell King ret = mv3310_config_mdix(phydev);
9418d8963c3SRussell King if (ret < 0)
9428d8963c3SRussell King return ret;
943ea4efe25SRussell King
94430de65c3SHeiner Kallweit if (phydev->autoneg == AUTONEG_DISABLE)
94530de65c3SHeiner Kallweit return genphy_c45_pma_setup_forced(phydev);
94620b2af32SRussell King
9473de97f3cSAndrew Lunn ret = genphy_c45_an_config_aneg(phydev);
94820b2af32SRussell King if (ret < 0)
94920b2af32SRussell King return ret;
95020b2af32SRussell King if (ret > 0)
95120b2af32SRussell King changed = true;
95220b2af32SRussell King
9533de97f3cSAndrew Lunn /* Clause 45 has no standardized support for 1000BaseT, therefore
9543de97f3cSAndrew Lunn * use vendor registers for this mode.
9553de97f3cSAndrew Lunn */
9563c1bcc86SAndrew Lunn reg = linkmode_adv_to_mii_ctrl1000_t(phydev->advertising);
957b06d8e5aSHeiner Kallweit ret = phy_modify_mmd_changed(phydev, MDIO_MMD_AN, MV_AN_CTRL1000,
9583c1bcc86SAndrew Lunn ADVERTISE_1000FULL | ADVERTISE_1000HALF, reg);
95920b2af32SRussell King if (ret < 0)
96020b2af32SRussell King return ret;
96120b2af32SRussell King if (ret > 0)
96220b2af32SRussell King changed = true;
96320b2af32SRussell King
9646b4cb6cbSHeiner Kallweit return genphy_c45_check_and_restart_aneg(phydev, changed);
96520b2af32SRussell King }
96620b2af32SRussell King
mv3310_aneg_done(struct phy_device * phydev)96720b2af32SRussell King static int mv3310_aneg_done(struct phy_device *phydev)
96820b2af32SRussell King {
96920b2af32SRussell King int val;
97020b2af32SRussell King
97120b2af32SRussell King val = phy_read_mmd(phydev, MDIO_MMD_PCS, MV_PCS_BASE_R + MDIO_STAT1);
97220b2af32SRussell King if (val < 0)
97320b2af32SRussell King return val;
97420b2af32SRussell King
97520b2af32SRussell King if (val & MDIO_STAT1_LSTATUS)
97620b2af32SRussell King return 1;
97720b2af32SRussell King
97820b2af32SRussell King return genphy_c45_aneg_done(phydev);
97920b2af32SRussell King }
98020b2af32SRussell King
mv3310_update_interface(struct phy_device * phydev)98136c4449aSRussell King static void mv3310_update_interface(struct phy_device *phydev)
98236c4449aSRussell King {
983e1170333SBaruch Siach struct mv3310_priv *priv = dev_get_drvdata(&phydev->mdio.dev);
984e1170333SBaruch Siach
985ccbf2891SMarek Behún if (!phydev->link)
986ccbf2891SMarek Behún return;
987ccbf2891SMarek Behún
98897bbe3bdSMarek Behún /* In all of the "* with Rate Matching" modes the PHY interface is fixed
98997bbe3bdSMarek Behún * at 10Gb. The PHY adapts the rate to actual wire speed with help of
990e1170333SBaruch Siach * internal 16KB buffer.
991ccbf2891SMarek Behún *
992ccbf2891SMarek Behún * In USXGMII mode the PHY interface mode is also fixed.
993e1170333SBaruch Siach */
9942cb6d63bSRussell King (Oracle) if (priv->mactype->fixed_interface) {
9952cb6d63bSRussell King (Oracle) phydev->interface = priv->mactype->interface_10g;
996e1170333SBaruch Siach return;
997e1170333SBaruch Siach }
998e1170333SBaruch Siach
999ccbf2891SMarek Behún /* The PHY automatically switches its serdes interface (and active PHYXS
1000ccbf2891SMarek Behún * instance) between Cisco SGMII, 2500BaseX, 5GBase-R and 10GBase-R /
1001ccbf2891SMarek Behún * xaui / rxaui modes according to the speed.
1002ccbf2891SMarek Behún * Florian suggests setting phydev->interface to communicate this to the
1003ccbf2891SMarek Behún * MAC. Only do this if we are already in one of the above modes.
100436c4449aSRussell King */
1005e555e5b1SMaxime Chevallier switch (phydev->speed) {
1006e555e5b1SMaxime Chevallier case SPEED_10000:
10072cb6d63bSRussell King (Oracle) phydev->interface = priv->mactype->interface_10g;
1008e555e5b1SMaxime Chevallier break;
10090d375542SMarek Behún case SPEED_5000:
10100d375542SMarek Behún phydev->interface = PHY_INTERFACE_MODE_5GBASER;
10110d375542SMarek Behún break;
1012e555e5b1SMaxime Chevallier case SPEED_2500:
1013e555e5b1SMaxime Chevallier phydev->interface = PHY_INTERFACE_MODE_2500BASEX;
1014e555e5b1SMaxime Chevallier break;
1015e555e5b1SMaxime Chevallier case SPEED_1000:
1016e555e5b1SMaxime Chevallier case SPEED_100:
1017e555e5b1SMaxime Chevallier case SPEED_10:
101836c4449aSRussell King phydev->interface = PHY_INTERFACE_MODE_SGMII;
1019e555e5b1SMaxime Chevallier break;
1020e555e5b1SMaxime Chevallier default:
1021e555e5b1SMaxime Chevallier break;
1022e555e5b1SMaxime Chevallier }
102336c4449aSRussell King }
102436c4449aSRussell King
102520b2af32SRussell King /* 10GBASE-ER,LR,LRM,SR do not support autonegotiation. */
mv3310_read_status_10gbaser(struct phy_device * phydev)1026c84786faSRussell King static int mv3310_read_status_10gbaser(struct phy_device *phydev)
102720b2af32SRussell King {
102820b2af32SRussell King phydev->link = 1;
102920b2af32SRussell King phydev->speed = SPEED_10000;
103020b2af32SRussell King phydev->duplex = DUPLEX_FULL;
10314217a64eSMichael Walle phydev->port = PORT_FIBRE;
103220b2af32SRussell King
103320b2af32SRussell King return 0;
103420b2af32SRussell King }
103520b2af32SRussell King
mv3310_read_status_copper(struct phy_device * phydev)1036c84786faSRussell King static int mv3310_read_status_copper(struct phy_device *phydev)
103720b2af32SRussell King {
1038c84786faSRussell King int cssr1, speed, val;
103920b2af32SRussell King
1040998a8a83SHeiner Kallweit val = genphy_c45_read_link(phydev);
104120b2af32SRussell King if (val < 0)
104220b2af32SRussell King return val;
104320b2af32SRussell King
104420b2af32SRussell King val = phy_read_mmd(phydev, MDIO_MMD_AN, MDIO_STAT1);
104520b2af32SRussell King if (val < 0)
104620b2af32SRussell King return val;
104720b2af32SRussell King
1048c84786faSRussell King cssr1 = phy_read_mmd(phydev, MDIO_MMD_PCS, MV_PCS_CSSR1);
1049c84786faSRussell King if (cssr1 < 0)
10500ed9704bSBaruch Siach return cssr1;
1051c84786faSRussell King
1052c84786faSRussell King /* If the link settings are not resolved, mark the link down */
1053c84786faSRussell King if (!(cssr1 & MV_PCS_CSSR1_RESOLVED)) {
1054c84786faSRussell King phydev->link = 0;
1055c84786faSRussell King return 0;
1056c84786faSRussell King }
1057c84786faSRussell King
1058c84786faSRussell King /* Read the copper link settings */
1059c84786faSRussell King speed = cssr1 & MV_PCS_CSSR1_SPD1_MASK;
1060c84786faSRussell King if (speed == MV_PCS_CSSR1_SPD1_SPD2)
1061c84786faSRussell King speed |= cssr1 & MV_PCS_CSSR1_SPD2_MASK;
1062c84786faSRussell King
1063c84786faSRussell King switch (speed) {
1064c84786faSRussell King case MV_PCS_CSSR1_SPD1_SPD2 | MV_PCS_CSSR1_SPD2_10000:
1065c84786faSRussell King phydev->speed = SPEED_10000;
1066c84786faSRussell King break;
1067c84786faSRussell King
1068c84786faSRussell King case MV_PCS_CSSR1_SPD1_SPD2 | MV_PCS_CSSR1_SPD2_5000:
1069c84786faSRussell King phydev->speed = SPEED_5000;
1070c84786faSRussell King break;
1071c84786faSRussell King
1072c84786faSRussell King case MV_PCS_CSSR1_SPD1_SPD2 | MV_PCS_CSSR1_SPD2_2500:
1073c84786faSRussell King phydev->speed = SPEED_2500;
1074c84786faSRussell King break;
1075c84786faSRussell King
1076c84786faSRussell King case MV_PCS_CSSR1_SPD1_1000:
1077c84786faSRussell King phydev->speed = SPEED_1000;
1078c84786faSRussell King break;
1079c84786faSRussell King
1080c84786faSRussell King case MV_PCS_CSSR1_SPD1_100:
1081c84786faSRussell King phydev->speed = SPEED_100;
1082c84786faSRussell King break;
1083c84786faSRussell King
1084c84786faSRussell King case MV_PCS_CSSR1_SPD1_10:
1085c84786faSRussell King phydev->speed = SPEED_10;
1086c84786faSRussell King break;
1087c84786faSRussell King }
1088c84786faSRussell King
1089c84786faSRussell King phydev->duplex = cssr1 & MV_PCS_CSSR1_DUPLEX_FULL ?
1090c84786faSRussell King DUPLEX_FULL : DUPLEX_HALF;
10914217a64eSMichael Walle phydev->port = PORT_TP;
1092c84786faSRussell King phydev->mdix = cssr1 & MV_PCS_CSSR1_MDIX ?
1093c84786faSRussell King ETH_TP_MDI_X : ETH_TP_MDI;
1094c84786faSRussell King
109520b2af32SRussell King if (val & MDIO_AN_STAT1_COMPLETE) {
109620b2af32SRussell King val = genphy_c45_read_lpa(phydev);
109720b2af32SRussell King if (val < 0)
109820b2af32SRussell King return val;
109920b2af32SRussell King
1100cc1122b0SColin Ian King /* Read the link partner's 1G advertisement */
110120b2af32SRussell King val = phy_read_mmd(phydev, MDIO_MMD_AN, MV_AN_STAT1000);
110220b2af32SRussell King if (val < 0)
110320b2af32SRussell King return val;
110420b2af32SRussell King
110578a24df3SAndrew Lunn mii_stat1000_mod_linkmode_lpa_t(phydev->lp_advertising, val);
110620b2af32SRussell King
1107c84786faSRussell King /* Update the pause status */
1108c84786faSRussell King phy_resolve_aneg_pause(phydev);
110920b2af32SRussell King }
111020b2af32SRussell King
1111c84786faSRussell King return 0;
111220b2af32SRussell King }
111320b2af32SRussell King
mv3310_read_status(struct phy_device * phydev)1114c84786faSRussell King static int mv3310_read_status(struct phy_device *phydev)
1115c84786faSRussell King {
1116c84786faSRussell King int err, val;
1117ea4efe25SRussell King
1118c84786faSRussell King phydev->speed = SPEED_UNKNOWN;
1119c84786faSRussell King phydev->duplex = DUPLEX_UNKNOWN;
1120c84786faSRussell King linkmode_zero(phydev->lp_advertising);
1121c84786faSRussell King phydev->link = 0;
1122c84786faSRussell King phydev->pause = 0;
1123c84786faSRussell King phydev->asym_pause = 0;
1124ea4efe25SRussell King phydev->mdix = ETH_TP_MDI_INVALID;
1125ea4efe25SRussell King
1126c84786faSRussell King val = phy_read_mmd(phydev, MDIO_MMD_PCS, MV_PCS_BASE_R + MDIO_STAT1);
1127c84786faSRussell King if (val < 0)
1128c84786faSRussell King return val;
1129c84786faSRussell King
1130c84786faSRussell King if (val & MDIO_STAT1_LSTATUS)
1131c84786faSRussell King err = mv3310_read_status_10gbaser(phydev);
1132c84786faSRussell King else
1133c84786faSRussell King err = mv3310_read_status_copper(phydev);
1134c84786faSRussell King if (err < 0)
1135c84786faSRussell King return err;
1136c84786faSRussell King
1137c84786faSRussell King if (phydev->link)
113836c4449aSRussell King mv3310_update_interface(phydev);
113920b2af32SRussell King
114020b2af32SRussell King return 0;
114120b2af32SRussell King }
114220b2af32SRussell King
mv3310_get_tunable(struct phy_device * phydev,struct ethtool_tunable * tuna,void * data)1143a585c03eSRussell King static int mv3310_get_tunable(struct phy_device *phydev,
1144a585c03eSRussell King struct ethtool_tunable *tuna, void *data)
1145a585c03eSRussell King {
1146a585c03eSRussell King switch (tuna->id) {
11474075a6a0SRussell King case ETHTOOL_PHY_DOWNSHIFT:
11484075a6a0SRussell King return mv3310_get_downshift(phydev, data);
1149a585c03eSRussell King case ETHTOOL_PHY_EDPD:
1150a585c03eSRussell King return mv3310_get_edpd(phydev, data);
1151a585c03eSRussell King default:
1152a585c03eSRussell King return -EOPNOTSUPP;
1153a585c03eSRussell King }
1154a585c03eSRussell King }
1155a585c03eSRussell King
mv3310_set_tunable(struct phy_device * phydev,struct ethtool_tunable * tuna,const void * data)1156a585c03eSRussell King static int mv3310_set_tunable(struct phy_device *phydev,
1157a585c03eSRussell King struct ethtool_tunable *tuna, const void *data)
1158a585c03eSRussell King {
1159a585c03eSRussell King switch (tuna->id) {
11604075a6a0SRussell King case ETHTOOL_PHY_DOWNSHIFT:
11614075a6a0SRussell King return mv3310_set_downshift(phydev, *(u8 *)data);
1162a585c03eSRussell King case ETHTOOL_PHY_EDPD:
1163a585c03eSRussell King return mv3310_set_edpd(phydev, *(u16 *)data);
1164a585c03eSRussell King default:
1165a585c03eSRussell King return -EOPNOTSUPP;
1166a585c03eSRussell King }
1167a585c03eSRussell King }
1168a585c03eSRussell King
mv3310_has_downshift(struct phy_device * phydev)11694075a6a0SRussell King static bool mv3310_has_downshift(struct phy_device *phydev)
11704075a6a0SRussell King {
11714075a6a0SRussell King struct mv3310_priv *priv = dev_get_drvdata(&phydev->mdio.dev);
11724075a6a0SRussell King
11734075a6a0SRussell King /* Fails to downshift with firmware older than v0.3.5.0 */
11744075a6a0SRussell King return priv->firmware_ver >= MV_VERSION(0,3,5,0);
11754075a6a0SRussell King }
11764075a6a0SRussell King
mv3310_init_supported_interfaces(unsigned long * mask)1177261a74c6SMarek Behún static void mv3310_init_supported_interfaces(unsigned long *mask)
1178261a74c6SMarek Behún {
1179261a74c6SMarek Behún __set_bit(PHY_INTERFACE_MODE_SGMII, mask);
1180261a74c6SMarek Behún __set_bit(PHY_INTERFACE_MODE_2500BASEX, mask);
1181261a74c6SMarek Behún __set_bit(PHY_INTERFACE_MODE_5GBASER, mask);
1182261a74c6SMarek Behún __set_bit(PHY_INTERFACE_MODE_XAUI, mask);
1183261a74c6SMarek Behún __set_bit(PHY_INTERFACE_MODE_RXAUI, mask);
1184261a74c6SMarek Behún __set_bit(PHY_INTERFACE_MODE_10GBASER, mask);
1185261a74c6SMarek Behún __set_bit(PHY_INTERFACE_MODE_USXGMII, mask);
1186261a74c6SMarek Behún }
1187261a74c6SMarek Behún
mv3340_init_supported_interfaces(unsigned long * mask)11889885d016SMarek Behún static void mv3340_init_supported_interfaces(unsigned long *mask)
11899885d016SMarek Behún {
11909885d016SMarek Behún __set_bit(PHY_INTERFACE_MODE_SGMII, mask);
11919885d016SMarek Behún __set_bit(PHY_INTERFACE_MODE_2500BASEX, mask);
11929885d016SMarek Behún __set_bit(PHY_INTERFACE_MODE_5GBASER, mask);
11939885d016SMarek Behún __set_bit(PHY_INTERFACE_MODE_RXAUI, mask);
11949885d016SMarek Behún __set_bit(PHY_INTERFACE_MODE_10GBASER, mask);
11959885d016SMarek Behún __set_bit(PHY_INTERFACE_MODE_USXGMII, mask);
11969885d016SMarek Behún }
11979885d016SMarek Behún
mv2110_init_supported_interfaces(unsigned long * mask)1198261a74c6SMarek Behún static void mv2110_init_supported_interfaces(unsigned long *mask)
1199261a74c6SMarek Behún {
1200261a74c6SMarek Behún __set_bit(PHY_INTERFACE_MODE_SGMII, mask);
1201261a74c6SMarek Behún __set_bit(PHY_INTERFACE_MODE_2500BASEX, mask);
1202261a74c6SMarek Behún __set_bit(PHY_INTERFACE_MODE_5GBASER, mask);
1203261a74c6SMarek Behún __set_bit(PHY_INTERFACE_MODE_10GBASER, mask);
1204261a74c6SMarek Behún __set_bit(PHY_INTERFACE_MODE_USXGMII, mask);
1205261a74c6SMarek Behún }
1206261a74c6SMarek Behún
mv2111_init_supported_interfaces(unsigned long * mask)12070fca947cSMarek Behún static void mv2111_init_supported_interfaces(unsigned long *mask)
12080fca947cSMarek Behún {
12090fca947cSMarek Behún __set_bit(PHY_INTERFACE_MODE_SGMII, mask);
12100fca947cSMarek Behún __set_bit(PHY_INTERFACE_MODE_2500BASEX, mask);
12110fca947cSMarek Behún __set_bit(PHY_INTERFACE_MODE_10GBASER, mask);
12120fca947cSMarek Behún __set_bit(PHY_INTERFACE_MODE_USXGMII, mask);
12130fca947cSMarek Behún }
12140fca947cSMarek Behún
121597bbe3bdSMarek Behún static const struct mv3310_chip mv3310_type = {
12164075a6a0SRussell King .has_downshift = mv3310_has_downshift,
1217261a74c6SMarek Behún .init_supported_interfaces = mv3310_init_supported_interfaces,
121897bbe3bdSMarek Behún .get_mactype = mv3310_get_mactype,
1219d6d29292SRussell King .set_mactype = mv3310_set_mactype,
1220d6d29292SRussell King .select_mactype = mv3310_select_mactype,
12212cb6d63bSRussell King (Oracle)
12222cb6d63bSRussell King (Oracle) .mactypes = mv3310_mactypes,
12232cb6d63bSRussell King (Oracle) .n_mactypes = ARRAY_SIZE(mv3310_mactypes),
1224884d9a67SMarek Behún
1225884d9a67SMarek Behún #ifdef CONFIG_HWMON
1226884d9a67SMarek Behún .hwmon_read_temp_reg = mv3310_hwmon_read_temp_reg,
1227884d9a67SMarek Behún #endif
122897bbe3bdSMarek Behún };
122997bbe3bdSMarek Behún
12309885d016SMarek Behún static const struct mv3310_chip mv3340_type = {
12314075a6a0SRussell King .has_downshift = mv3310_has_downshift,
12329885d016SMarek Behún .init_supported_interfaces = mv3340_init_supported_interfaces,
12339885d016SMarek Behún .get_mactype = mv3310_get_mactype,
1234d6d29292SRussell King .set_mactype = mv3310_set_mactype,
1235d6d29292SRussell King .select_mactype = mv3310_select_mactype,
12362cb6d63bSRussell King (Oracle)
12372cb6d63bSRussell King (Oracle) .mactypes = mv3340_mactypes,
12382cb6d63bSRussell King (Oracle) .n_mactypes = ARRAY_SIZE(mv3340_mactypes),
12399885d016SMarek Behún
12409885d016SMarek Behún #ifdef CONFIG_HWMON
12419885d016SMarek Behún .hwmon_read_temp_reg = mv3310_hwmon_read_temp_reg,
12429885d016SMarek Behún #endif
12439885d016SMarek Behún };
12449885d016SMarek Behún
124597bbe3bdSMarek Behún static const struct mv3310_chip mv2110_type = {
1246261a74c6SMarek Behún .init_supported_interfaces = mv2110_init_supported_interfaces,
124797bbe3bdSMarek Behún .get_mactype = mv2110_get_mactype,
1248d6d29292SRussell King .set_mactype = mv2110_set_mactype,
1249d6d29292SRussell King .select_mactype = mv2110_select_mactype,
12502cb6d63bSRussell King (Oracle)
12512cb6d63bSRussell King (Oracle) .mactypes = mv2110_mactypes,
12522cb6d63bSRussell King (Oracle) .n_mactypes = ARRAY_SIZE(mv2110_mactypes),
1253884d9a67SMarek Behún
1254884d9a67SMarek Behún #ifdef CONFIG_HWMON
1255884d9a67SMarek Behún .hwmon_read_temp_reg = mv2110_hwmon_read_temp_reg,
1256884d9a67SMarek Behún #endif
125797bbe3bdSMarek Behún };
125897bbe3bdSMarek Behún
12590fca947cSMarek Behún static const struct mv3310_chip mv2111_type = {
12600fca947cSMarek Behún .init_supported_interfaces = mv2111_init_supported_interfaces,
12610fca947cSMarek Behún .get_mactype = mv2110_get_mactype,
1262d6d29292SRussell King .set_mactype = mv2110_set_mactype,
1263d6d29292SRussell King .select_mactype = mv2110_select_mactype,
12642cb6d63bSRussell King (Oracle)
12652cb6d63bSRussell King (Oracle) .mactypes = mv2110_mactypes,
12662cb6d63bSRussell King (Oracle) .n_mactypes = ARRAY_SIZE(mv2110_mactypes),
12670fca947cSMarek Behún
12680fca947cSMarek Behún #ifdef CONFIG_HWMON
12690fca947cSMarek Behún .hwmon_read_temp_reg = mv2110_hwmon_read_temp_reg,
12700fca947cSMarek Behún #endif
12710fca947cSMarek Behún };
12720fca947cSMarek Behún
mv3310_get_number_of_ports(struct phy_device * phydev)1273a5de4be0SMarek Behún static int mv3310_get_number_of_ports(struct phy_device *phydev)
1274a5de4be0SMarek Behún {
1275a5de4be0SMarek Behún int ret;
1276a5de4be0SMarek Behún
1277a5de4be0SMarek Behún ret = phy_read_mmd(phydev, MDIO_MMD_PCS, MV_PCS_PORT_INFO);
1278a5de4be0SMarek Behún if (ret < 0)
1279a5de4be0SMarek Behún return ret;
1280a5de4be0SMarek Behún
1281a5de4be0SMarek Behún ret &= MV_PCS_PORT_INFO_NPORTS_MASK;
1282a5de4be0SMarek Behún ret >>= MV_PCS_PORT_INFO_NPORTS_SHIFT;
1283a5de4be0SMarek Behún
1284a5de4be0SMarek Behún return ret + 1;
1285a5de4be0SMarek Behún }
1286a5de4be0SMarek Behún
mv3310_match_phy_device(struct phy_device * phydev)1287a5de4be0SMarek Behún static int mv3310_match_phy_device(struct phy_device *phydev)
1288a5de4be0SMarek Behún {
12890d55649dSVladimir Oltean if ((phydev->c45_ids.device_ids[MDIO_MMD_PMAPMD] &
12900d55649dSVladimir Oltean MARVELL_PHY_ID_MASK) != MARVELL_PHY_ID_88X3310)
12910d55649dSVladimir Oltean return 0;
12920d55649dSVladimir Oltean
1293a5de4be0SMarek Behún return mv3310_get_number_of_ports(phydev) == 1;
1294a5de4be0SMarek Behún }
1295a5de4be0SMarek Behún
mv3340_match_phy_device(struct phy_device * phydev)1296a5de4be0SMarek Behún static int mv3340_match_phy_device(struct phy_device *phydev)
1297a5de4be0SMarek Behún {
12980d55649dSVladimir Oltean if ((phydev->c45_ids.device_ids[MDIO_MMD_PMAPMD] &
12990d55649dSVladimir Oltean MARVELL_PHY_ID_MASK) != MARVELL_PHY_ID_88X3310)
13000d55649dSVladimir Oltean return 0;
13010d55649dSVladimir Oltean
1302a5de4be0SMarek Behún return mv3310_get_number_of_ports(phydev) == 4;
1303a5de4be0SMarek Behún }
1304a5de4be0SMarek Behún
mv211x_match_phy_device(struct phy_device * phydev,bool has_5g)13050fca947cSMarek Behún static int mv211x_match_phy_device(struct phy_device *phydev, bool has_5g)
13060fca947cSMarek Behún {
13070fca947cSMarek Behún int val;
13080fca947cSMarek Behún
13090fca947cSMarek Behún if ((phydev->c45_ids.device_ids[MDIO_MMD_PMAPMD] &
13100fca947cSMarek Behún MARVELL_PHY_ID_MASK) != MARVELL_PHY_ID_88E2110)
13110fca947cSMarek Behún return 0;
13120fca947cSMarek Behún
13130fca947cSMarek Behún val = phy_read_mmd(phydev, MDIO_MMD_PCS, MDIO_SPEED);
13140fca947cSMarek Behún if (val < 0)
13150fca947cSMarek Behún return val;
13160fca947cSMarek Behún
13170fca947cSMarek Behún return !!(val & MDIO_PCS_SPEED_5G) == has_5g;
13180fca947cSMarek Behún }
13190fca947cSMarek Behún
mv2110_match_phy_device(struct phy_device * phydev)13200fca947cSMarek Behún static int mv2110_match_phy_device(struct phy_device *phydev)
13210fca947cSMarek Behún {
13220fca947cSMarek Behún return mv211x_match_phy_device(phydev, true);
13230fca947cSMarek Behún }
13240fca947cSMarek Behún
mv2111_match_phy_device(struct phy_device * phydev)13250fca947cSMarek Behún static int mv2111_match_phy_device(struct phy_device *phydev)
13260fca947cSMarek Behún {
13270fca947cSMarek Behún return mv211x_match_phy_device(phydev, false);
13280fca947cSMarek Behún }
13290fca947cSMarek Behún
mv3110_get_wol(struct phy_device * phydev,struct ethtool_wolinfo * wol)133008041a9aSVoon Weifeng static void mv3110_get_wol(struct phy_device *phydev,
133108041a9aSVoon Weifeng struct ethtool_wolinfo *wol)
133208041a9aSVoon Weifeng {
133308041a9aSVoon Weifeng int ret;
133408041a9aSVoon Weifeng
133508041a9aSVoon Weifeng wol->supported = WAKE_MAGIC;
133608041a9aSVoon Weifeng wol->wolopts = 0;
133708041a9aSVoon Weifeng
133808041a9aSVoon Weifeng ret = phy_read_mmd(phydev, MDIO_MMD_VEND2, MV_V2_WOL_CTRL);
133908041a9aSVoon Weifeng if (ret < 0)
134008041a9aSVoon Weifeng return;
134108041a9aSVoon Weifeng
134208041a9aSVoon Weifeng if (ret & MV_V2_WOL_CTRL_MAGIC_PKT_EN)
134308041a9aSVoon Weifeng wol->wolopts |= WAKE_MAGIC;
134408041a9aSVoon Weifeng }
134508041a9aSVoon Weifeng
mv3110_set_wol(struct phy_device * phydev,struct ethtool_wolinfo * wol)134608041a9aSVoon Weifeng static int mv3110_set_wol(struct phy_device *phydev,
134708041a9aSVoon Weifeng struct ethtool_wolinfo *wol)
134808041a9aSVoon Weifeng {
134908041a9aSVoon Weifeng int ret;
135008041a9aSVoon Weifeng
135108041a9aSVoon Weifeng if (wol->wolopts & WAKE_MAGIC) {
135208041a9aSVoon Weifeng /* Enable the WOL interrupt */
135308041a9aSVoon Weifeng ret = phy_set_bits_mmd(phydev, MDIO_MMD_VEND2,
135408041a9aSVoon Weifeng MV_V2_PORT_INTR_MASK,
135508041a9aSVoon Weifeng MV_V2_PORT_INTR_STS_WOL_EN);
135608041a9aSVoon Weifeng if (ret < 0)
135708041a9aSVoon Weifeng return ret;
135808041a9aSVoon Weifeng
135908041a9aSVoon Weifeng /* Store the device address for the magic packet */
136008041a9aSVoon Weifeng ret = phy_write_mmd(phydev, MDIO_MMD_VEND2,
136108041a9aSVoon Weifeng MV_V2_MAGIC_PKT_WORD2,
136208041a9aSVoon Weifeng ((phydev->attached_dev->dev_addr[5] << 8) |
136308041a9aSVoon Weifeng phydev->attached_dev->dev_addr[4]));
136408041a9aSVoon Weifeng if (ret < 0)
136508041a9aSVoon Weifeng return ret;
136608041a9aSVoon Weifeng
136708041a9aSVoon Weifeng ret = phy_write_mmd(phydev, MDIO_MMD_VEND2,
136808041a9aSVoon Weifeng MV_V2_MAGIC_PKT_WORD1,
136908041a9aSVoon Weifeng ((phydev->attached_dev->dev_addr[3] << 8) |
137008041a9aSVoon Weifeng phydev->attached_dev->dev_addr[2]));
137108041a9aSVoon Weifeng if (ret < 0)
137208041a9aSVoon Weifeng return ret;
137308041a9aSVoon Weifeng
137408041a9aSVoon Weifeng ret = phy_write_mmd(phydev, MDIO_MMD_VEND2,
137508041a9aSVoon Weifeng MV_V2_MAGIC_PKT_WORD0,
137608041a9aSVoon Weifeng ((phydev->attached_dev->dev_addr[1] << 8) |
137708041a9aSVoon Weifeng phydev->attached_dev->dev_addr[0]));
137808041a9aSVoon Weifeng if (ret < 0)
137908041a9aSVoon Weifeng return ret;
138008041a9aSVoon Weifeng
138108041a9aSVoon Weifeng /* Clear WOL status and enable magic packet matching */
138208041a9aSVoon Weifeng ret = phy_set_bits_mmd(phydev, MDIO_MMD_VEND2,
138308041a9aSVoon Weifeng MV_V2_WOL_CTRL,
138408041a9aSVoon Weifeng MV_V2_WOL_CTRL_MAGIC_PKT_EN |
138508041a9aSVoon Weifeng MV_V2_WOL_CTRL_CLEAR_STS);
138608041a9aSVoon Weifeng if (ret < 0)
138708041a9aSVoon Weifeng return ret;
138808041a9aSVoon Weifeng } else {
138908041a9aSVoon Weifeng /* Disable magic packet matching & reset WOL status bit */
139008041a9aSVoon Weifeng ret = phy_modify_mmd(phydev, MDIO_MMD_VEND2,
139108041a9aSVoon Weifeng MV_V2_WOL_CTRL,
139208041a9aSVoon Weifeng MV_V2_WOL_CTRL_MAGIC_PKT_EN,
139308041a9aSVoon Weifeng MV_V2_WOL_CTRL_CLEAR_STS);
139408041a9aSVoon Weifeng if (ret < 0)
139508041a9aSVoon Weifeng return ret;
139608041a9aSVoon Weifeng }
139708041a9aSVoon Weifeng
139808041a9aSVoon Weifeng /* Reset the clear WOL status bit as it does not self-clear */
139908041a9aSVoon Weifeng return phy_clear_bits_mmd(phydev, MDIO_MMD_VEND2,
140008041a9aSVoon Weifeng MV_V2_WOL_CTRL,
140108041a9aSVoon Weifeng MV_V2_WOL_CTRL_CLEAR_STS);
140208041a9aSVoon Weifeng }
140308041a9aSVoon Weifeng
140420b2af32SRussell King static struct phy_driver mv3310_drivers[] = {
140520b2af32SRussell King {
1406631ba906SMaxime Chevallier .phy_id = MARVELL_PHY_ID_88X3310,
1407a5de4be0SMarek Behún .phy_id_mask = MARVELL_PHY_ID_MASK,
1408a5de4be0SMarek Behún .match_phy_device = mv3310_match_phy_device,
140920b2af32SRussell King .name = "mv88x3310",
141097bbe3bdSMarek Behún .driver_data = &mv3310_type,
141174145424SMaxime Chevallier .get_features = mv3310_get_features,
141220b2af32SRussell King .config_init = mv3310_config_init,
14130d3ad854SRussell King .probe = mv3310_probe,
14140d3ad854SRussell King .suspend = mv3310_suspend,
14150d3ad854SRussell King .resume = mv3310_resume,
141620b2af32SRussell King .config_aneg = mv3310_config_aneg,
141720b2af32SRussell King .aneg_done = mv3310_aneg_done,
141820b2af32SRussell King .read_status = mv3310_read_status,
1419a585c03eSRussell King .get_tunable = mv3310_get_tunable,
1420a585c03eSRussell King .set_tunable = mv3310_set_tunable,
14211b8ef142SMarek Behún .remove = mv3310_remove,
1422d137c70dSWong Vee Khee .set_loopback = genphy_c45_loopback,
142308041a9aSVoon Weifeng .get_wol = mv3110_get_wol,
142408041a9aSVoon Weifeng .set_wol = mv3110_set_wol,
142520b2af32SRussell King },
142662d01535SMaxime Chevallier {
1427a5de4be0SMarek Behún .phy_id = MARVELL_PHY_ID_88X3310,
1428a5de4be0SMarek Behún .phy_id_mask = MARVELL_PHY_ID_MASK,
1429a5de4be0SMarek Behún .match_phy_device = mv3340_match_phy_device,
14309885d016SMarek Behún .name = "mv88x3340",
14319885d016SMarek Behún .driver_data = &mv3340_type,
14329885d016SMarek Behún .get_features = mv3310_get_features,
14339885d016SMarek Behún .config_init = mv3310_config_init,
14349885d016SMarek Behún .probe = mv3310_probe,
14359885d016SMarek Behún .suspend = mv3310_suspend,
14369885d016SMarek Behún .resume = mv3310_resume,
14379885d016SMarek Behún .config_aneg = mv3310_config_aneg,
14389885d016SMarek Behún .aneg_done = mv3310_aneg_done,
14399885d016SMarek Behún .read_status = mv3310_read_status,
14409885d016SMarek Behún .get_tunable = mv3310_get_tunable,
14419885d016SMarek Behún .set_tunable = mv3310_set_tunable,
14429885d016SMarek Behún .remove = mv3310_remove,
14439885d016SMarek Behún .set_loopback = genphy_c45_loopback,
14449885d016SMarek Behún },
14459885d016SMarek Behún {
144662d01535SMaxime Chevallier .phy_id = MARVELL_PHY_ID_88E2110,
144762d01535SMaxime Chevallier .phy_id_mask = MARVELL_PHY_ID_MASK,
14480fca947cSMarek Behún .match_phy_device = mv2110_match_phy_device,
1449c89f27d4SMarek Behún .name = "mv88e2110",
145097bbe3bdSMarek Behún .driver_data = &mv2110_type,
145162d01535SMaxime Chevallier .probe = mv3310_probe,
1452e02c4a9dSAntoine Tenart .suspend = mv3310_suspend,
1453e02c4a9dSAntoine Tenart .resume = mv3310_resume,
145462d01535SMaxime Chevallier .config_init = mv3310_config_init,
145562d01535SMaxime Chevallier .config_aneg = mv3310_config_aneg,
145662d01535SMaxime Chevallier .aneg_done = mv3310_aneg_done,
145762d01535SMaxime Chevallier .read_status = mv3310_read_status,
1458a585c03eSRussell King .get_tunable = mv3310_get_tunable,
1459a585c03eSRussell King .set_tunable = mv3310_set_tunable,
14601b8ef142SMarek Behún .remove = mv3310_remove,
1461d137c70dSWong Vee Khee .set_loopback = genphy_c45_loopback,
146208041a9aSVoon Weifeng .get_wol = mv3110_get_wol,
146308041a9aSVoon Weifeng .set_wol = mv3110_set_wol,
146462d01535SMaxime Chevallier },
14650fca947cSMarek Behún {
14660fca947cSMarek Behún .phy_id = MARVELL_PHY_ID_88E2110,
14670fca947cSMarek Behún .phy_id_mask = MARVELL_PHY_ID_MASK,
14680fca947cSMarek Behún .match_phy_device = mv2111_match_phy_device,
14690fca947cSMarek Behún .name = "mv88e2111",
14700fca947cSMarek Behún .driver_data = &mv2111_type,
14710fca947cSMarek Behún .probe = mv3310_probe,
14720fca947cSMarek Behún .suspend = mv3310_suspend,
14730fca947cSMarek Behún .resume = mv3310_resume,
14740fca947cSMarek Behún .config_init = mv3310_config_init,
14750fca947cSMarek Behún .config_aneg = mv3310_config_aneg,
14760fca947cSMarek Behún .aneg_done = mv3310_aneg_done,
14770fca947cSMarek Behún .read_status = mv3310_read_status,
14780fca947cSMarek Behún .get_tunable = mv3310_get_tunable,
14790fca947cSMarek Behún .set_tunable = mv3310_set_tunable,
14800fca947cSMarek Behún .remove = mv3310_remove,
14810fca947cSMarek Behún .set_loopback = genphy_c45_loopback,
14820fca947cSMarek Behún },
148320b2af32SRussell King };
148420b2af32SRussell King
148520b2af32SRussell King module_phy_driver(mv3310_drivers);
148620b2af32SRussell King
148720b2af32SRussell King static struct mdio_device_id __maybe_unused mv3310_tbl[] = {
1488a5de4be0SMarek Behún { MARVELL_PHY_ID_88X3310, MARVELL_PHY_ID_MASK },
148962d01535SMaxime Chevallier { MARVELL_PHY_ID_88E2110, MARVELL_PHY_ID_MASK },
149020b2af32SRussell King { },
149120b2af32SRussell King };
149220b2af32SRussell King MODULE_DEVICE_TABLE(mdio, mv3310_tbl);
1493c7dce05eSMarek Behún MODULE_DESCRIPTION("Marvell Alaska X/M multi-gigabit Ethernet PHY driver");
149420b2af32SRussell King MODULE_LICENSE("GPL");
1495