From: Oleksij Rempel <o.rempel@pengutronix.de>
To: barebox@lists.infradead.org
Cc: Oleksij Rempel <o.rempel@pengutronix.de>
Subject: [PATCH v1 1/2] net: sja1105: split adjust_link into reusable functions
Date: Wed, 29 May 2024 11:41:23 +0200 [thread overview]
Message-ID: <20240529094124.513880-1-o.rempel@pengutronix.de> (raw)
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@pengutronix.de>
---
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
next reply other threads:[~2024-05-29 9:42 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-05-29 9:41 Oleksij Rempel [this message]
2024-05-29 9:41 ` [PATCH v1 2/2] net: sja1105: add function to configure CPU port Oleksij Rempel
2024-05-30 13:25 ` [PATCH v1 1/2] net: sja1105: split adjust_link into reusable functions Sascha Hauer
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20240529094124.513880-1-o.rempel@pengutronix.de \
--to=o.rempel@pengutronix.de \
--cc=barebox@lists.infradead.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox