1 // SPDX-License-Identifier: GPL-2.0
3 * Marvell 88Q2XXX automotive 100BASE-T1/1000BASE-T1 PHY driver
5 #include <linux/ethtool_netlink.h>
6 #include <linux/marvell_phy.h>
9 #define MDIO_MMD_AN_MV_STAT 32769
10 #define MDIO_MMD_AN_MV_STAT_ANEG 0x0100
11 #define MDIO_MMD_AN_MV_STAT_LOCAL_RX 0x1000
12 #define MDIO_MMD_AN_MV_STAT_REMOTE_RX 0x2000
13 #define MDIO_MMD_AN_MV_STAT_LOCAL_MASTER 0x4000
14 #define MDIO_MMD_AN_MV_STAT_MS_CONF_FAULT 0x8000
16 #define MDIO_MMD_PCS_MV_100BT1_STAT1 33032
17 #define MDIO_MMD_PCS_MV_100BT1_STAT1_IDLE_ERROR 0x00FF
18 #define MDIO_MMD_PCS_MV_100BT1_STAT1_JABBER 0x0100
19 #define MDIO_MMD_PCS_MV_100BT1_STAT1_LINK 0x0200
20 #define MDIO_MMD_PCS_MV_100BT1_STAT1_LOCAL_RX 0x1000
21 #define MDIO_MMD_PCS_MV_100BT1_STAT1_REMOTE_RX 0x2000
22 #define MDIO_MMD_PCS_MV_100BT1_STAT1_LOCAL_MASTER 0x4000
24 #define MDIO_MMD_PCS_MV_100BT1_STAT2 33033
25 #define MDIO_MMD_PCS_MV_100BT1_STAT2_JABBER 0x0001
26 #define MDIO_MMD_PCS_MV_100BT1_STAT2_POL 0x0002
27 #define MDIO_MMD_PCS_MV_100BT1_STAT2_LINK 0x0004
28 #define MDIO_MMD_PCS_MV_100BT1_STAT2_ANGE 0x0008
30 static int mv88q2xxx_soft_reset(struct phy_device *phydev)
35 ret = phy_write_mmd(phydev, MDIO_MMD_PCS,
36 MDIO_PCS_1000BT1_CTRL, MDIO_PCS_1000BT1_CTRL_RESET);
40 return phy_read_mmd_poll_timeout(phydev, MDIO_MMD_PCS,
41 MDIO_PCS_1000BT1_CTRL, val,
42 !(val & MDIO_PCS_1000BT1_CTRL_RESET),
46 static int mv88q2xxx_read_link_gbit(struct phy_device *phydev)
51 /* Read vendor specific Auto-Negotiation status register to get local
52 * and remote receiver status according to software initialization
55 ret = phy_read_mmd(phydev, MDIO_MMD_AN, MDIO_MMD_AN_MV_STAT);
58 } else if ((ret & MDIO_MMD_AN_MV_STAT_LOCAL_RX) &&
59 (ret & MDIO_MMD_AN_MV_STAT_REMOTE_RX)) {
60 /* The link state is latched low so that momentary link
61 * drops can be detected. Do not double-read the status
62 * in polling mode to detect such short link drops except
63 * the link was already down.
65 if (!phy_polling_mode(phydev) || !phydev->link) {
66 ret = phy_read_mmd(phydev, MDIO_MMD_PCS, MDIO_PCS_1000BT1_STAT);
69 else if (ret & MDIO_PCS_1000BT1_STAT_LINK)
74 ret = phy_read_mmd(phydev, MDIO_MMD_PCS, MDIO_PCS_1000BT1_STAT);
77 else if (ret & MDIO_PCS_1000BT1_STAT_LINK)
87 static int mv88q2xxx_read_link_100m(struct phy_device *phydev)
91 /* The link state is latched low so that momentary link
92 * drops can be detected. Do not double-read the status
93 * in polling mode to detect such short link drops except
94 * the link was already down. In case we are not polling,
95 * we always read the realtime status.
97 if (!phy_polling_mode(phydev) || !phydev->link) {
98 ret = phy_read_mmd(phydev, MDIO_MMD_PCS, MDIO_MMD_PCS_MV_100BT1_STAT1);
101 else if (ret & MDIO_MMD_PCS_MV_100BT1_STAT1_LINK)
105 ret = phy_read_mmd(phydev, MDIO_MMD_PCS, MDIO_MMD_PCS_MV_100BT1_STAT1);
110 /* Check if we have link and if the remote and local receiver are ok */
111 if ((ret & MDIO_MMD_PCS_MV_100BT1_STAT1_LINK) &&
112 (ret & MDIO_MMD_PCS_MV_100BT1_STAT1_LOCAL_RX) &&
113 (ret & MDIO_MMD_PCS_MV_100BT1_STAT1_REMOTE_RX))
116 phydev->link = false;
121 static int mv88q2xxx_read_link(struct phy_device *phydev)
125 /* The 88Q2XXX PHYs do not have the PMA/PMD status register available,
126 * therefore we need to read the link status from the vendor specific
127 * registers depending on the speed.
129 if (phydev->speed == SPEED_1000)
130 ret = mv88q2xxx_read_link_gbit(phydev);
132 ret = mv88q2xxx_read_link_100m(phydev);
137 static int mv88q2xxx_read_status(struct phy_device *phydev)
141 ret = mv88q2xxx_read_link(phydev);
145 return genphy_c45_read_pma(phydev);
148 static int mv88q2xxx_get_features(struct phy_device *phydev)
152 ret = genphy_c45_pma_read_abilities(phydev);
156 /* We need to read the baset1 extended abilities manually because the
157 * PHY does not signalize it has the extended abilities register
160 ret = genphy_c45_pma_baset1_read_abilities(phydev);
164 /* The PHY signalizes it supports autonegotiation. Unfortunately, so
165 * far it was not possible to get a link even when following the init
166 * sequence provided by Marvell. Disable it for now until a proper
167 * workaround is found or a new PHY revision is released.
169 linkmode_clear_bit(ETHTOOL_LINK_MODE_Autoneg_BIT, phydev->supported);
174 static int mv88q2xxx_config_aneg(struct phy_device *phydev)
178 ret = genphy_c45_config_aneg(phydev);
182 return mv88q2xxx_soft_reset(phydev);
185 static int mv88q2xxx_config_init(struct phy_device *phydev)
189 /* The 88Q2XXX PHYs do have the extended ability register available, but
190 * register MDIO_PMA_EXTABLE where they should signalize it does not
191 * work according to specification. Therefore, we force it here.
193 phydev->pma_extable = MDIO_PMA_EXTABLE_BT1;
195 /* Read the current PHY configuration */
196 ret = genphy_c45_read_pma(phydev);
200 return mv88q2xxx_config_aneg(phydev);
203 static int mv88q2xxxx_get_sqi(struct phy_device *phydev)
207 if (phydev->speed == SPEED_100) {
208 /* Read the SQI from the vendor specific receiver status
211 ret = phy_read_mmd(phydev, MDIO_MMD_PCS, 0x8230);
217 /* Read from vendor specific registers, they are not documented
218 * but can be found in the Software Initialization Guide. Only
219 * revisions >= A0 are supported.
221 ret = phy_modify_mmd(phydev, MDIO_MMD_PCS, 0xFC5D, 0x00FF, 0x00AC);
225 ret = phy_read_mmd(phydev, MDIO_MMD_PCS, 0xfc88);
233 static int mv88q2xxxx_get_sqi_max(struct phy_device *phydev)
238 static struct phy_driver mv88q2xxx_driver[] = {
240 .phy_id = MARVELL_PHY_ID_88Q2110,
241 .phy_id_mask = MARVELL_PHY_ID_MASK,
243 .get_features = mv88q2xxx_get_features,
244 .config_aneg = mv88q2xxx_config_aneg,
245 .config_init = mv88q2xxx_config_init,
246 .read_status = mv88q2xxx_read_status,
247 .soft_reset = mv88q2xxx_soft_reset,
248 .set_loopback = genphy_c45_loopback,
249 .get_sqi = mv88q2xxxx_get_sqi,
250 .get_sqi_max = mv88q2xxxx_get_sqi_max,
254 module_phy_driver(mv88q2xxx_driver);
256 static struct mdio_device_id __maybe_unused mv88q2xxx_tbl[] = {
257 { MARVELL_PHY_ID_88Q2110, MARVELL_PHY_ID_MASK },
260 MODULE_DEVICE_TABLE(mdio, mv88q2xxx_tbl);
262 MODULE_DESCRIPTION("Marvell 88Q2XXX 100/1000BASE-T1 Automotive Ethernet PHY driver");
263 MODULE_LICENSE("GPL");