On an Orange Pi Zero 2W with an AC300 fused at 0x6, the 100BASE-TX link to an ASIX AX88179 repeatedly drops when the vendor driver programs 0x9. The link stays up with the factory code. Mainline copied the vendor driver's +3 offset and four-bit mask for both packages. The TX trim field uses four-bit two's complement, so adding 3 to factory codes 5, 6 and 7 and keeping the low four bits selects -8, -7 and -6. In sweeps of all 16 settings, these gave the three weakest outputs: 28-33% below the AC200 test board's own factory level and 35-43% below the AC300 board's. None of 1,705 H616 SID readings contained a negative factory trim. The 1,694 AC300 readings covered codes 0 to 7; 865 were 5 through 7. The 11 AC200 readings covered codes 0 to 3. Use the factory trim without an offset on AC300. Keep the AC200 offset: on the same single-ended scope setup, the 100BASE-TX outer idle-level span was 118.80 mV on AC200 (fuse 1, programmed 4), 3.2% above the 115.15 mV measured on AC300 at its factory code of 6. Without the offset, the AC200 span was 109.59 mV, 4.8% below the AC300 span. Decode the factory trim as signed and check it before accepting the adjusted value. If either is outside 0 through +7, warn at probe and program +7. This also catches an AC200 fuse of 0xd: it encodes -3 even though adding the offset gives zero. None of the 1,705 H616 SID readings would trigger the warning. Fixes: 6cc2fbceb49b ("net: phy: add X-Powers AC200/AC300 EPHY driver") Reported-by: Viktor Lazarev Signed-off-by: James Hilliard --- drivers/net/phy/xpowers/ac200.c | 24 ++++++++++-------------- drivers/net/phy/xpowers/ac300.c | 13 +++++-------- drivers/net/phy/xpowers/acx00.c | 28 ++++++++++++++++++++++------ drivers/net/phy/xpowers/acx00.h | 6 ++++-- 4 files changed, 41 insertions(+), 30 deletions(-) diff --git a/drivers/net/phy/xpowers/ac200.c b/drivers/net/phy/xpowers/ac200.c index 3718878e3994..9b724a2a4f17 100644 --- a/drivers/net/phy/xpowers/ac200.c +++ b/drivers/net/phy/xpowers/ac200.c @@ -209,15 +209,14 @@ static int ac200_ephy_ctl_power_on(struct acx00_ephy_control *control, struct acx00_ephy_control * ac200_ephy_ctl_create(struct phy_device *phydev, struct device_node *package_node, - bool has_calibration, u8 calibration) + bool has_configuration, unsigned int fuse) { struct device *dev = &phydev->mdio.dev; - unsigned int internal_calibration; struct device_node *ac200_node; struct ac200_ephy_ctl *priv; struct i2c_client *client; unsigned long clk_rate; - u8 bps_effuse_code; + s8 bps_effuse_code; struct clk *clk; int ret; @@ -259,21 +258,12 @@ ac200_ephy_ctl_create(struct phy_device *phydev, goto out_put_client; } - if (!has_calibration) { - ret = regmap_read(priv->regmap, AC200_EFUSE_EPHY_REG, - &internal_calibration); + if (!has_configuration) { + ret = regmap_read(priv->regmap, AC200_EFUSE_EPHY_REG, &fuse); if (ret) goto out_error; - calibration = internal_calibration; } - /* The vendor driver supplies no transfer function beyond this offset. */ - bps_effuse_code = (calibration + AC200_EPHY_BPS_EFFUSE_OFFSET) & - FIELD_MAX(AC200_EPHY_BPS_EFFUSE_MASK); - priv->ephy_ctl = - FIELD_PREP(AC200_EPHY_BPS_EFFUSE_MASK, bps_effuse_code); - /* EPHY_MODE and BIST_CLK_EN stay clear for normal operation. */ - clk = clk_get(&client->dev, NULL); if (IS_ERR(clk)) { ret = PTR_ERR(clk); @@ -297,6 +287,12 @@ ac200_ephy_ctl_create(struct phy_device *phydev, goto out_put_client; } + bps_effuse_code = acx00_ephy_tx_trim(phydev, fuse, + AC200_EPHY_BPS_EFFUSE_OFFSET); + priv->ephy_ctl |= FIELD_PREP(AC200_EPHY_BPS_EFFUSE_MASK, + bps_effuse_code); + /* EPHY_MODE and BIST_CLK_EN stay clear for normal operation. */ + priv->control.power_on = ac200_ephy_ctl_power_on; priv->control.power_off = ac200_ephy_ctl_power_off; priv->control.set_interface = ac200_ephy_ctl_set_interface; diff --git a/drivers/net/phy/xpowers/ac300.c b/drivers/net/phy/xpowers/ac300.c index 37e40c16cece..68534e6f4d19 100644 --- a/drivers/net/phy/xpowers/ac300.c +++ b/drivers/net/phy/xpowers/ac300.c @@ -15,7 +15,6 @@ #include "../phylib.h" #include "acx00.h" -#define AC300_EPHY_BGS_EFFUSE_OFFSET 3 #define AC300_EPHY_CLK_RATE_24_MHZ 24000000 #define AC300_EPHY_CLK_RATE_25_MHZ 25000000 #define AC300_EPHY_CLK_RATE_27_MHZ 27000000 @@ -317,12 +316,12 @@ static void ac300_ephy_clk_put(void *data) struct acx00_ephy_control * ac300_ephy_ctl_create(struct phy_device *phydev, - struct device_node *package_node, u8 calibration) + struct device_node *package_node, unsigned int fuse) { struct device *dev = &phydev->mdio.dev; struct ac300_ephy_ctl *priv; unsigned long clk_rate; - u8 bgs_effuse_code; + s8 bgs_effuse_code; int ret; priv = devm_kzalloc_obj(dev, *priv); @@ -370,11 +369,9 @@ ac300_ephy_ctl_create(struct phy_device *phydev, } priv->sys_control |= AC300_SYS_CONTROL_ENABLE_BITS; - /* The vendor driver supplies no transfer function beyond this offset. */ - bgs_effuse_code = (calibration + AC300_EPHY_BGS_EFFUSE_OFFSET) & - FIELD_MAX(AC300_EPHY_BGS_EFFUSE_MASK); - priv->ephy_config = - FIELD_PREP(AC300_EPHY_BGS_EFFUSE_MASK, bgs_effuse_code); + bgs_effuse_code = acx00_ephy_tx_trim(phydev, fuse, 0); + priv->ephy_config = FIELD_PREP(AC300_EPHY_BGS_EFFUSE_MASK, + bgs_effuse_code); /* EPHY_MODE and BIST_CLK_EN stay clear for normal operation. */ priv->control.power_on = ac300_ephy_ctl_power_on; diff --git a/drivers/net/phy/xpowers/acx00.c b/drivers/net/phy/xpowers/acx00.c index cee6c7ff0278..5fbf38471013 100644 --- a/drivers/net/phy/xpowers/acx00.c +++ b/drivers/net/phy/xpowers/acx00.c @@ -24,6 +24,8 @@ #define ACX00_EPHY_CONFIG_VARIANT_AC300 BIT(8) #define ACX00_EPHY_CONFIG_CALIBRATION_LOW BIT(9) +#define ACX00_EPHY_TX_TRIM_MAX 7 + #define ACX00_PAGE_SELECT_REG 0x1f #define ACX00_PAGE_SELECT_MASK GENMASK(12, 8) #define ACX00_PAGE_0 0 @@ -93,6 +95,24 @@ struct acx00_ephy_priv { bool xmii_rx_clock_inverted; }; +s8 acx00_ephy_tx_trim(struct phy_device *phydev, unsigned int fuse, u8 offset) +{ + s8 factory = FIELD_GET_SIGNED(ACX00_EPHY_CONFIG_CALIBRATION_MASK, fuse); + + /* + * The four-bit two's complement trim wraps from maximum TX amplitude + * at +7 to minimum at -8. The offset can also hide a negative fuse + * value, so check the factory trim as well as the sum. + */ + if (factory >= 0 && factory + offset <= ACX00_EPHY_TX_TRIM_MAX) + return factory + offset; + + phydev_warn(phydev, "TX trim fuse %#lx (%d), adjusted %d; using +%d\n", + fuse & ACX00_EPHY_CONFIG_CALIBRATION_MASK, factory, + factory + offset, ACX00_EPHY_TX_TRIM_MAX); + return ACX00_EPHY_TX_TRIM_MAX; +} + static int acx00_ephy_read_page(struct phy_device *phydev) { int ret; @@ -200,7 +220,6 @@ static int acx00_ephy_init_package(struct phy_device *phydev, bool selectable; bool fixed_ac300; bool has_configuration; - u8 calibration; u32 base_addr; u16 configuration = 0; int ret; @@ -269,9 +288,6 @@ static int acx00_ephy_init_package(struct phy_device *phydev, } } - calibration = FIELD_GET(ACX00_EPHY_CONFIG_CALIBRATION_MASK, - configuration); - priv->use_low_calibration_tuning = priv->is_ac300 && !!(configuration & ACX00_EPHY_CONFIG_CALIBRATION_LOW); @@ -282,12 +298,12 @@ static int acx00_ephy_init_package(struct phy_device *phydev, if (priv->is_ac300) priv->control = ac300_ephy_ctl_create(phydev, package_node, - calibration); + configuration); else priv->control = ac200_ephy_ctl_create(phydev, package_node, has_configuration, - calibration); + configuration); ret = PTR_ERR_OR_ZERO(priv->control); out_put_node: diff --git a/drivers/net/phy/xpowers/acx00.h b/drivers/net/phy/xpowers/acx00.h index 7df6084c7a77..321949b2be3e 100644 --- a/drivers/net/phy/xpowers/acx00.h +++ b/drivers/net/phy/xpowers/acx00.h @@ -17,12 +17,14 @@ struct acx00_ephy_control { phy_interface_t interface); }; +s8 acx00_ephy_tx_trim(struct phy_device *phydev, unsigned int fuse, u8 offset); + struct acx00_ephy_control * ac200_ephy_ctl_create(struct phy_device *phydev, struct device_node *package_node, - bool has_calibration, u8 calibration); + bool has_configuration, unsigned int fuse); struct acx00_ephy_control * ac300_ephy_ctl_create(struct phy_device *phydev, - struct device_node *package_node, u8 calibration); + struct device_node *package_node, unsigned int fuse); #endif --- base-commit: af61bd1c3715acf0e7f60d77fb06d5f126abdb76 base-tree: git://git.kernel.org/pub/scm/linux/kernel/git/netdev/net.git main change-id: 20261205-submit-acx00-ephy-tx-trim-v1-10033217e045 Best regards, -- James Hilliard