public inbox for u-boot@lists.denx.de
 help / color / mirror / Atom feed
* [U-Boot] [PATCH] net: fec_mxc: fix mii_speed configuration for MX6's
@ 2014-02-19 14:27 Philippe De Muyter
  2014-02-19 19:19 ` Troy Kisky
  2014-02-20  7:40 ` [U-Boot] [PATCH] " Markus Niebel
  0 siblings, 2 replies; 6+ messages in thread
From: Philippe De Muyter @ 2014-02-19 14:27 UTC (permalink / raw)
  To: u-boot

On MX6DL at least, measured mdc speed was wrong (3.3 Mhz instead of 2.5
Mhz), because of wrong assumptions about the reference clock and the
way the divider is used.

I have fixed that for all MX6's by using the IPG clock as the reference
clock, and applying the - 1 correction when we have a ENET MAC instead
of a FEC MAC, just like what is done in the fec linux driver.

Signed-off-by: Philippe De Muyter <phdm@macqel.be>
---
 drivers/net/fec_mxc.c |   20 +++++++++++++++++---
 1 files changed, 17 insertions(+), 3 deletions(-)

diff --git a/drivers/net/fec_mxc.c b/drivers/net/fec_mxc.c
index 3b2b995..3ab0ecd 100644
--- a/drivers/net/fec_mxc.c
+++ b/drivers/net/fec_mxc.c
@@ -124,13 +124,27 @@ static int fec_mdio_read(struct ethernet_regs *eth, uint8_t phyAddr,
 
 static void fec_mii_setspeed(struct ethernet_regs *eth)
 {
+	u32 sysclock;
+	u32 mii_speed;
+
 	/*
 	 * Set MII_SPEED = (1/(mii_speed * 2)) * System Clock
 	 * and do not drop the Preamble.
+	 * shift the result by 1, because MII_SPEED field is at bits 6..1.
 	 */
-	writel((((imx_get_fecclk() / 1000000) + 2) / 5) << 1,
-			&eth->mii_speed);
-	debug("%s: mii_speed %08x\n", __func__, readl(&eth->mii_speed));
+#if defined(CONFIG_MX6)
+	sysclock = mxc_get_clock(MXC_IPG_CLK);
+#else
+	sysclock = imx_get_fecclk();
+#endif
+#define MIIM_SPEED 2500000
+	mii_speed = DIV_ROUND_UP(sysclock, (MIIM_SPEED * 2));
+#ifdef FEC_QUIRK_ENET_MAC
+	mii_speed -= 1;
+#endif
+	writel(mii_speed << 1, &eth->mii_speed);
+	debug("%s: sysclock %u, mii_speed %08x\n", __func__, sysclock,
+						readl(&eth->mii_speed));
 }
 
 static int fec_mdio_write(struct ethernet_regs *eth, uint8_t phyAddr,
-- 
1.7.5.3

^ permalink raw reply related	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2014-02-20  8:44 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2014-02-19 14:27 [U-Boot] [PATCH] net: fec_mxc: fix mii_speed configuration for MX6's Philippe De Muyter
2014-02-19 19:19 ` Troy Kisky
2014-02-19 20:37   ` Philippe De Muyter
2014-02-19 20:58   ` [U-Boot] [PATCH v2] " Philippe De Muyter
2014-02-20  7:40 ` [U-Boot] [PATCH] " Markus Niebel
2014-02-20  8:44   ` Philippe De Muyter

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox