Skip site navigation (1)Skip section navigation (2)
Date:      Fri, 6 Oct 2023 17:06:02 GMT
From:      Emmanuel Vadot <manu@FreeBSD.org>
To:        src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-main@FreeBSD.org
Subject:   git: cf037a17c7c8 - main - dwc: rockchip: Properly calculate mii clock based on pclk_mac
Message-ID:  <202310061706.396H62a5060763@gitrepo.freebsd.org>

next in thread | raw e-mail | index | archive | help
The branch main has been updated by manu:

URL: https://cgit.FreeBSD.org/src/commit/?id=cf037a17c7c81e8a2e73c89eb90877f2625749d7

commit cf037a17c7c81e8a2e73c89eb90877f2625749d7
Author:     Emmanuel Vadot <manu@FreeBSD.org>
AuthorDate: 2023-10-06 15:44:00 +0000
Commit:     Emmanuel Vadot <manu@FreeBSD.org>
CommitDate: 2023-10-06 17:05:43 +0000

    dwc: rockchip: Properly calculate mii clock based on pclk_mac
---
 sys/dev/dwc/if_dwc_rk.c | 24 ++++++++++++++++++++++--
 1 file changed, 22 insertions(+), 2 deletions(-)

diff --git a/sys/dev/dwc/if_dwc_rk.c b/sys/dev/dwc/if_dwc_rk.c
index 43d4e4847c62..257d80bd1e59 100644
--- a/sys/dev/dwc/if_dwc_rk.c
+++ b/sys/dev/dwc/if_dwc_rk.c
@@ -581,9 +581,29 @@ if_dwc_rk_init(device_t dev)
 static int
 if_dwc_rk_mii_clk(device_t dev)
 {
+	struct if_dwc_rk_softc *sc;
+	uint64_t freq;
+	int rv;
 
-	/* Should be calculated from the clock */
-	return (GMAC_MII_CLK_150_250M_DIV102);
+	sc = device_get_softc(dev);
+	if ((rv = clk_get_freq(sc->pclk_mac, &freq)) != 0)
+		return (-rv);
+	freq = freq / 1000 / 1000;
+
+	if (freq >= 60 && freq <= 100)
+		return (GMAC_MII_CLK_60_100M_DIV42);
+	else if (freq >= 100 && freq <= 150)
+		return (GMAC_MII_CLK_100_150M_DIV62);
+	else if (freq >= 20 && freq <= 35)
+		return (GMAC_MII_CLK_25_35M_DIV16);
+	else if (freq >= 35 && freq <= 60)
+		return (GMAC_MII_CLK_35_60M_DIV26);
+	else if (freq >= 150 && freq <= 250)
+		return (GMAC_MII_CLK_150_250M_DIV102);
+	else if (freq >= 250 && freq <= 300)
+		return (GMAC_MII_CLK_250_300M_DIV124);
+
+	return (-ERANGE);
 }
 
 static int



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?202310061706.396H62a5060763>