Subject: Re: [PATCH net v3 1/2] net: phy: micrel: lan8842 errata

From: "Russell King (Oracle)" <[email-masked]>
Date: Thu, 30 Oct 2025 10:33:26 +0000

On Thu, Oct 30, 2025 at 08:49:40AM +0100, Horatiu Vultur wrote:
> +static int lan8842_erratas(struct phy_device *phydev)
> +{
> +	int ret;
> +
> +	/* Magjack center tapped ports */
> +	ret = lanphy_write_page_reg(phydev, LAN8814_PAGE_POWER_REGS,
> +				    LAN8814_POWER_MGMT_MODE_3_ANEG_MDI,
> +				    LAN8814_POWER_MGMT_VAL1);
> +	if (ret < 0)
> +		return ret;
> +
> +	ret = lanphy_write_page_reg(phydev, LAN8814_PAGE_POWER_REGS,
> +				    LAN8814_POWER_MGMT_MODE_4_ANEG_MDIX,
> +				    LAN8814_POWER_MGMT_VAL1);
> +	if (ret < 0)
> +		return ret;
> +
> +	ret = lanphy_write_page_reg(phydev, LAN8814_PAGE_POWER_REGS,
> +				    LAN8814_POWER_MGMT_MODE_5_10BT_MDI,
> +				    LAN8814_POWER_MGMT_VAL1);
> +	if (ret < 0)
> +		return ret;
> +
> +	ret = lanphy_write_page_reg(phydev, LAN8814_PAGE_POWER_REGS,
> +				    LAN8814_POWER_MGMT_MODE_6_10BT_MDIX,
> +				    LAN8814_POWER_MGMT_VAL1);
> +	if (ret < 0)
> +		return ret;
> +
> +	ret = lanphy_write_page_reg(phydev, LAN8814_PAGE_POWER_REGS,
> +				    LAN8814_POWER_MGMT_MODE_7_100BT_TRAIN,
> +				    LAN8814_POWER_MGMT_VAL2);
> +	if (ret < 0)
> +		return ret;
> +
> +	ret = lanphy_write_page_reg(phydev, LAN8814_PAGE_POWER_REGS,
> +				    LAN8814_POWER_MGMT_MODE_8_100BT_MDI,
> +				    LAN8814_POWER_MGMT_VAL3);
> +	if (ret < 0)
> +		return ret;
> +
> +	ret = lanphy_write_page_reg(phydev, LAN8814_PAGE_POWER_REGS,
> +				    LAN8814_POWER_MGMT_MODE_9_100BT_EEE_MDI_TX,
> +				    LAN8814_POWER_MGMT_VAL3);
> +	if (ret < 0)
> +		return ret;
> +
> +	ret = lanphy_write_page_reg(phydev, LAN8814_PAGE_POWER_REGS,
> +				    LAN8814_POWER_MGMT_MODE_10_100BT_EEE_MDI_RX,
> +				    LAN8814_POWER_MGMT_VAL4);
> +	if (ret < 0)
> +		return ret;
> +
> +	ret = lanphy_write_page_reg(phydev, LAN8814_PAGE_POWER_REGS,
> +				    LAN8814_POWER_MGMT_MODE_11_100BT_MDIX,
> +				    LAN8814_POWER_MGMT_VAL5);
> +	if (ret < 0)
> +		return ret;
> +
> +	ret = lanphy_write_page_reg(phydev, LAN8814_PAGE_POWER_REGS,
> +				    LAN8814_POWER_MGMT_MODE_12_100BT_EEE_MDIX_TX,
> +				    LAN8814_POWER_MGMT_VAL5);
> +	if (ret < 0)
> +		return ret;
> +
> +	ret = lanphy_write_page_reg(phydev, LAN8814_PAGE_POWER_REGS,
> +				    LAN8814_POWER_MGMT_MODE_13_100BT_EEE_MDIX_RX,
> +				    LAN8814_POWER_MGMT_VAL4);
> +	if (ret < 0)
> +		return ret;
> +
> +	return lanphy_write_page_reg(phydev, LAN8814_PAGE_POWER_REGS,
> +				     LAN8814_POWER_MGMT_MODE_14_100BTX_EEE_TX_RX,
> +				     LAN8814_POWER_MGMT_VAL4);

This is a lot of repetition.

Is it worth storing the errata register information in a struct, and
then using a loop to write these registers. Something like:

struct lanphy_reg_data {
	int page;
	u16 addr;
	u16 val;
;

static const struct lanphy_reg_data short_centre_tap_errata[] = {
	...
};

static int lanphy_write_reg_data(struct phy_device *phydev,
				 const struct lanphy_reg_data *data,
				 size_t num)
{
	int ret = 0;

	while (num--) {
		ret = lanphy_write_page_reg(phydev, data->page, data->addr,
					    data->val);
		if (ret)
			break;
	}

	return 0;
}

static int lan8842_erratas(struct phy_device *phydev)
{
	int ret;

	ret = lanphy_write_reg_data(phydev, short_centre_tap_errata,
				    ARRAY_SIZE(short_centre_tap_errata));
	if (ret)
		return ret;

	return lanphy_write_reg_data(phydev, blah_errata,
				     ARRAY_SIZE(blah_errata));
}

?

-- 
RMK's Patch system: https://www.armlinux.org.uk/developer/patches/
FTTP is here! 80Mbps down 10Mbps up. Decent connectivity at last!