[PATCH v1 1/2] net: sja1105: split adjust_link into reusable functions

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Refactor sja1105_adjust_link by moving RGMII delay and speed settings
into separate functions: sja1105_set_rgmii_delay() and
sja1105_set_speed().
This restructuring makes the code more modular and reusable, preparing
for the next patch where the CPU port configuration will be handled in
a separate function.

Signed-off-by: Oleksij Rempel <o.rempel@xxxxxxxxxxxxxx>
---
 drivers/net/sja1105.c | 89 ++++++++++++++++++++++++++-----------------
 1 file changed, 53 insertions(+), 36 deletions(-)

diff --git a/drivers/net/sja1105.c b/drivers/net/sja1105.c
index d88a5e2fcf..c759c40b36 100644
--- a/drivers/net/sja1105.c
+++ b/drivers/net/sja1105.c
@@ -2713,6 +2713,55 @@ static int sja1105_port_set_mode(struct dsa_port *dp, int port,
 	return 0;
 }
 
+static int sja1105_set_rgmii_delay(struct sja1105_private *priv, int port,
+				   phy_interface_t phy_mode)
+{
+	if (phy_mode == PHY_INTERFACE_MODE_RGMII_RXID ||
+	    phy_mode == PHY_INTERFACE_MODE_RGMII_ID)
+		priv->rgmii_rx_delay[port] = true;
+
+	if (phy_mode == PHY_INTERFACE_MODE_RGMII_TXID ||
+	    phy_mode == PHY_INTERFACE_MODE_RGMII_ID)
+		priv->rgmii_tx_delay[port] = true;
+
+	if ((priv->rgmii_rx_delay[port] ||
+	     priv->rgmii_tx_delay[port]) &&
+	     !priv->dcfg->setup_rgmii_delay) {
+		dev_err(priv->dev, "Chip does not support internal RGMII delays\n");
+		return -EINVAL;
+	}
+
+	return 0;
+}
+
+static void sja1105_set_speed(struct dsa_port *dp, int port, int speed)
+{
+	struct device *dev = dp->ds->dev;
+	struct sja1105_private *priv = dev_get_priv(dev);
+	struct sja1105_xmii_params_entry *mii;
+	struct sja1105_mac_config_entry *mac;
+
+	mii = priv->static_config.tables[BLK_IDX_XMII_PARAMS].entries;
+	mac = priv->static_config.tables[BLK_IDX_MAC_CONFIG].entries;
+
+	if (mii->xmii_mode[port] == XMII_MODE_SGMII) {
+		mac[port].speed =
+			priv->dcfg->port_speed[SJA1105_SPEED_1000MBPS];
+		priv->xpcs_cfg[port].speed = speed;
+	} else if (speed == SPEED_1000) {
+		mac[port].speed =
+			priv->dcfg->port_speed[SJA1105_SPEED_1000MBPS];
+	} else if (speed == SPEED_100) {
+		mac[port].speed =
+			priv->dcfg->port_speed[SJA1105_SPEED_100MBPS];
+	} else if (speed == SPEED_10) {
+		mac[port].speed =
+			priv->dcfg->port_speed[SJA1105_SPEED_10MBPS];
+	} else {
+		mac[port].speed = priv->dcfg->port_speed[SJA1105_SPEED_AUTO];
+	}
+}
+
 static int sja1105_port_pre_enable(struct dsa_port *dp, int port,
 				   phy_interface_t phy_mode)
 {
@@ -2734,13 +2783,10 @@ static void sja1105_adjust_link(struct eth_device *edev)
 	struct sja1105_private *priv = dev_get_priv(dev);
 	struct phy_device *phy = dp->edev.phydev;
 	phy_interface_t phy_mode = phy->interface;
-	struct sja1105_xmii_params_entry *mii;
-	struct sja1105_mac_config_entry *mac;
 	int port = dp->index;
 	int ret;
 
-	mii = priv->static_config.tables[BLK_IDX_XMII_PARAMS].entries;
-	mac = priv->static_config.tables[BLK_IDX_MAC_CONFIG].entries;
+	sja1105_set_speed(dp, port, phy->speed);
 
 	ret = sja1105_port_set_mode(dp, port, phy_mode);
 	if (ret)
@@ -2748,38 +2794,9 @@ static void sja1105_adjust_link(struct eth_device *edev)
 
 	/* Let the PHY handle the RGMII delays, if present. */
 	if (phy->phy_id == 0) {
-		if (phy_mode == PHY_INTERFACE_MODE_RGMII_RXID ||
-		    phy_mode == PHY_INTERFACE_MODE_RGMII_ID)
-			priv->rgmii_rx_delay[port] = true;
-
-		if (phy_mode == PHY_INTERFACE_MODE_RGMII_TXID ||
-		    phy_mode == PHY_INTERFACE_MODE_RGMII_ID)
-			priv->rgmii_tx_delay[port] = true;
-
-		if ((priv->rgmii_rx_delay[port] ||
-		     priv->rgmii_tx_delay[port]) &&
-		     !priv->dcfg->setup_rgmii_delay) {
-			dev_err(priv->dev, "Chip does not support internal RGMII delays\n");
-			return;
-		}
-	}
-
-	if (mii->xmii_mode[port] == XMII_MODE_SGMII) {
-		mac[port].speed =
-			priv->dcfg->port_speed[SJA1105_SPEED_1000MBPS];
-		priv->xpcs_cfg[port].speed = phy->speed;
-	} else if (phy->speed == SPEED_1000) {
-		mac[port].speed =
-			priv->dcfg->port_speed[SJA1105_SPEED_1000MBPS];
-	} else if (phy->speed == SPEED_100) {
-		mac[port].speed =
-			priv->dcfg->port_speed[SJA1105_SPEED_100MBPS];
-	} else if (phy->speed == SPEED_10) {
-		mac[port].speed =
-			priv->dcfg->port_speed[SJA1105_SPEED_10MBPS];
-	} else {
-		mac[port].speed = priv->dcfg->port_speed[SJA1105_SPEED_AUTO];
-		return;
+		ret = sja1105_set_rgmii_delay(priv, port, phy_mode);
+		if (ret)
+			goto error;
 	}
 
 	ret = sja1105_static_config_reload(priv);
-- 
2.39.2





[Index of Archives]     [Linux Embedded]     [Linux USB Devel]     [Linux Audio Users]     [Yosemite News]     [Linux Kernel]     [Linux SCSI]     [XFree86]

  Powered by Linux