1 // SPDX-License-Identifier: GPL-2.0
2 // Broadcom BCM84881 NBASE-T PHY driver, as found on a SFP+ module.
3 // Copyright (C) 2019 Russell King, Deep Blue Solutions Ltd.
5 // Like the Marvell 88x3310, the Broadcom 84881 changes its host-side
6 // interface according to the operating speed between 10GBASE-R,
7 // 2500BASE-X and SGMII (but unlike the 88x3310, without the control
10 // This driver only supports those aspects of the PHY that I'm able to
11 // observe and test with the SFP+ module, which is an incomplete subset
12 // of what this PHY is able to support. For example, I only assume it
13 // supports a single lane Serdes connection, but it may be that the PHY
14 // is able to support more than that.
15 #include <linux/delay.h>
16 #include <linux/module.h>
17 #include <linux/phy.h>
23 static int bcm84881_wait_init(struct phy_device
*phydev
)
25 unsigned int tries
= 20;
29 val
= phy_read_mmd(phydev
, MDIO_MMD_PMAPMD
, MDIO_CTRL1
);
34 if (!(val
& MDIO_CTRL1_RESET
)) {
46 phydev_err(phydev
, "%s failed: %d\n", __func__
, ret
);
51 static int bcm84881_config_init(struct phy_device
*phydev
)
53 switch (phydev
->interface
) {
54 case PHY_INTERFACE_MODE_SGMII
:
55 case PHY_INTERFACE_MODE_2500BASEX
:
56 case PHY_INTERFACE_MODE_10GBASER
:
64 static int bcm84881_probe(struct phy_device
*phydev
)
66 /* This driver requires PMAPMD and AN blocks */
67 const u32 mmd_mask
= MDIO_DEVS_PMAPMD
| MDIO_DEVS_AN
;
69 if (!phydev
->is_c45
||
70 (phydev
->c45_ids
.devices_in_package
& mmd_mask
) != mmd_mask
)
76 static int bcm84881_get_features(struct phy_device
*phydev
)
80 ret
= genphy_c45_pma_read_abilities(phydev
);
84 /* Although the PHY sets bit 1.11.8, it does not support 10M modes */
85 linkmode_clear_bit(ETHTOOL_LINK_MODE_10baseT_Half_BIT
,
87 linkmode_clear_bit(ETHTOOL_LINK_MODE_10baseT_Full_BIT
,
93 static int bcm84881_config_aneg(struct phy_device
*phydev
)
99 /* Wait for the PHY to finish initialising, otherwise our
100 * advertisement may be overwritten.
102 ret
= bcm84881_wait_init(phydev
);
106 /* We don't support manual MDI control */
107 phydev
->mdix_ctrl
= ETH_TP_MDI_AUTO
;
109 /* disabled autoneg doesn't seem to work with this PHY */
110 if (phydev
->autoneg
== AUTONEG_DISABLE
)
113 ret
= genphy_c45_an_config_aneg(phydev
);
119 adv
= linkmode_adv_to_mii_ctrl1000_t(phydev
->advertising
);
120 ret
= phy_modify_mmd_changed(phydev
, MDIO_MMD_AN
,
121 MDIO_AN_C22
+ MII_CTRL1000
,
122 ADVERTISE_1000FULL
| ADVERTISE_1000HALF
,
129 return genphy_c45_check_and_restart_aneg(phydev
, changed
);
132 static int bcm84881_aneg_done(struct phy_device
*phydev
)
136 val
= phy_read_mmd(phydev
, MDIO_MMD_AN
, MDIO_STAT1
);
140 bmsr
= phy_read_mmd(phydev
, MDIO_MMD_AN
, MDIO_AN_C22
+ MII_BMSR
);
144 return !!(val
& MDIO_AN_STAT1_COMPLETE
) &&
145 !!(bmsr
& BMSR_ANEGCOMPLETE
);
148 static int bcm84881_read_status(struct phy_device
*phydev
)
153 val
= phy_read_mmd(phydev
, MDIO_MMD_AN
, MDIO_CTRL1
);
157 if (val
& MDIO_AN_CTRL1_RESTART
) {
162 val
= phy_read_mmd(phydev
, MDIO_MMD_AN
, MDIO_STAT1
);
166 bmsr
= phy_read_mmd(phydev
, MDIO_MMD_AN
, MDIO_AN_C22
+ MII_BMSR
);
170 phydev
->autoneg_complete
= !!(val
& MDIO_AN_STAT1_COMPLETE
) &&
171 !!(bmsr
& BMSR_ANEGCOMPLETE
);
172 phydev
->link
= !!(val
& MDIO_STAT1_LSTATUS
) &&
173 !!(bmsr
& BMSR_LSTATUS
);
174 if (phydev
->autoneg
== AUTONEG_ENABLE
&& !phydev
->autoneg_complete
)
175 phydev
->link
= false;
180 linkmode_zero(phydev
->lp_advertising
);
181 phydev
->speed
= SPEED_UNKNOWN
;
182 phydev
->duplex
= DUPLEX_UNKNOWN
;
184 phydev
->asym_pause
= 0;
187 if (phydev
->autoneg_complete
) {
188 val
= genphy_c45_read_lpa(phydev
);
192 val
= phy_read_mmd(phydev
, MDIO_MMD_AN
,
193 MDIO_AN_C22
+ MII_STAT1000
);
197 mii_stat1000_mod_linkmode_lpa_t(phydev
->lp_advertising
, val
);
199 if (phydev
->autoneg
== AUTONEG_ENABLE
)
200 phy_resolve_aneg_linkmode(phydev
);
203 if (phydev
->autoneg
== AUTONEG_DISABLE
) {
204 /* disabled autoneg doesn't seem to work, so force the link
211 /* Set the host link mode - we set the phy interface mode and
212 * the speed according to this register so that downshift works.
213 * We leave the duplex setting as per the resolution from the
216 val
= phy_read_mmd(phydev
, MDIO_MMD_VEND1
, 0x4011);
217 mode
= (val
& 0x1e) >> 1;
218 if (mode
== 1 || mode
== 2)
219 phydev
->interface
= PHY_INTERFACE_MODE_SGMII
;
221 phydev
->interface
= PHY_INTERFACE_MODE_10GBASER
;
223 phydev
->interface
= PHY_INTERFACE_MODE_2500BASEX
;
226 phydev
->speed
= SPEED_100
;
229 phydev
->speed
= SPEED_1000
;
232 phydev
->speed
= SPEED_10000
;
235 phydev
->speed
= SPEED_2500
;
238 phydev
->speed
= SPEED_5000
;
242 return genphy_c45_read_mdix(phydev
);
245 static struct phy_driver bcm84881_drivers
[] = {
247 .phy_id
= 0xae025150,
248 .phy_id_mask
= 0xfffffff0,
249 .name
= "Broadcom BCM84881",
250 .config_init
= bcm84881_config_init
,
251 .probe
= bcm84881_probe
,
252 .get_features
= bcm84881_get_features
,
253 .config_aneg
= bcm84881_config_aneg
,
254 .aneg_done
= bcm84881_aneg_done
,
255 .read_status
= bcm84881_read_status
,
259 module_phy_driver(bcm84881_drivers
);
261 /* FIXME: module auto-loading for Clause 45 PHYs seems non-functional */
262 static struct mdio_device_id __maybe_unused bcm84881_tbl
[] = {
263 { 0xae025150, 0xfffffff0 },
266 MODULE_AUTHOR("Russell King");
267 MODULE_DESCRIPTION("Broadcom BCM84881 PHY driver");
268 MODULE_DEVICE_TABLE(mdio
, bcm84881_tbl
);
269 MODULE_LICENSE("GPL");