mail archive of the barebox mailing list
 help / color / mirror / Atom feed
From: Michael Tretter <m.tretter@pengutronix.de>
To: barebox@lists.infradead.org
Cc: Michael Tretter <m.tretter@pengutronix.de>
Subject: [PATCH 2/3] net: macb: adjust clk_tx rate for link speed changes
Date: Thu, 15 Oct 2020 15:20:47 +0200	[thread overview]
Message-ID: <20201015132048.420995-2-m.tretter@pengutronix.de> (raw)
In-Reply-To: <20201015132048.420995-1-m.tretter@pengutronix.de>

Changes of the link speed might require an adjustment of the clk_tx.

Read the clk_tx from the device tree and change the rate if the link
speed changes.

If the clk_tx rate is already correct, changing the clock is not
required and, thus, not being able to get the clock rate is not fatal.

Signed-off-by: Michael Tretter <m.tretter@pengutronix.de>
---
 drivers/net/macb.c | 35 +++++++++++++++++++++++++++++++++++
 1 file changed, 35 insertions(+)

diff --git a/drivers/net/macb.c b/drivers/net/macb.c
index 09b58ffd017f..fa530cfe8e4c 100644
--- a/drivers/net/macb.c
+++ b/drivers/net/macb.c
@@ -258,9 +258,38 @@ static int macb_recv(struct eth_device *edev)
 	return 0;
 }
 
+static int macb_set_tx_clk(struct macb_device *macb, int speed)
+{
+	int rate;
+	int rate_rounded;
+
+	if (!macb->txclk) {
+		dev_dbg(macb->dev, "txclk not available\n");
+		return 0;
+	}
+
+	switch (speed) {
+	case SPEED_100:
+		rate = 25000000;
+		break;
+	case SPEED_1000:
+		rate = 125000000;
+		break;
+	default:
+		return -EINVAL;
+	}
+
+	rate_rounded = clk_round_rate(macb->txclk, rate);
+	if (rate_rounded <= 0)
+		return -EINVAL;
+
+	return clk_set_rate(macb->txclk, rate_rounded);
+}
+
 static void macb_adjust_link(struct eth_device *edev)
 {
 	struct macb_device *macb = edev->priv;
+	int err;
 	u32 reg;
 
 	reg = macb_readl(macb, NCFGR);
@@ -276,6 +305,10 @@ static void macb_adjust_link(struct eth_device *edev)
 		reg |= GEM_BIT(GBE);
 
 	macb_or_gem_writel(macb, NCFGR, reg);
+
+	err = macb_set_tx_clk(macb, edev->phydev->speed);
+	if (err)
+		dev_warn(macb->dev, "cannot set txclk\n");
 }
 
 static int macb_open(struct eth_device *edev)
@@ -724,6 +757,8 @@ static int macb_probe(struct device_d *dev)
 	macb->txclk = clk_get(dev, "tx_clk");
 	if (!IS_ERR(macb->txclk))
 		clk_enable(macb->txclk);
+	else
+		macb->txclk = NULL;
 
 	macb->rxclk = clk_get(dev, "rx_clk");
 	if (!IS_ERR(macb->rxclk))
-- 
2.20.1


_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox

  reply	other threads:[~2020-10-15 13:20 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-10-15 13:20 [PATCH 1/3] net: macb: reduce DEBUG output to make it more useful Michael Tretter
2020-10-15 13:20 ` Michael Tretter [this message]
2020-10-15 13:20 ` [PATCH 3/3] net: macb: fix compiler warning for 64 bit systems Michael Tretter
2020-10-15 13:29   ` Ahmad Fatoum
2020-10-15 14:04     ` Michael Tretter
2020-10-15 14:13       ` Ahmad Fatoum
2020-10-19  8:10   ` Sascha Hauer
2020-10-19  8:02 ` [PATCH 1/3] net: macb: reduce DEBUG output to make it more useful 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=20201015132048.420995-2-m.tretter@pengutronix.de \
    --to=m.tretter@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