Skip to contentSkip to conversation

net: fec_mxc: fix mii_speed configuration for MX6's

PATCH New Philippe De Muyter 3 participants 6 messages Feb 19, 2014 – Feb 20, 2014

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 net: fec_mxc: fix mii_speed configuration for MX6's

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.

---
 drivers/net/fec_mxc.c |   20 +++++++++++++++++---
 1 files changed, 17 insertions(+), 3 deletions(-)
drivers/net/fec_mxc.c +17 -3
index 3b2b995..3ab0ecd 100644
@@ -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,
Signature · 1 line
1.7.5.3
#1 lore raw

PATCH 1/1 net: fec_mxc: fix mii_speed configuration for MX6's

Quoted 27 lines · Philippe De Muyter

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.

---
 drivers/net/fec_mxc.c |   20 +++++++++++++++++---
 1 files changed, 17 insertions(+), 3 deletions(-)
drivers/net/fec_mxc.c +3 -0
index 3b2b995..3ab0ecd 100644
@@ -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.

drivers/net/fec_mxc.c static int fec_mdio_read(struct ethernet_regs *eth, uint8_t phyAddr, · line 139

Quoted 10 lines
drivers/net/fec_mxc.c +6 -3
+	 * 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

Why not fix it in arch/arm/cpu/armv7/mx6/clock.c ?

u32 imx_get_fecclk(void)
{
- return decode_pll(PLL_ENET, MXC_HCLK);
+ mxc_get_clock(MXC_IPG_CLK);
}

Quoted 12 lines
drivers/net/fec_mxc.c +8 -0
+#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,
#2 lore raw

PATCH 1/1 net: fec_mxc: fix mii_speed configuration for MX6's

Quoted 46 lines · Troy Kisky
Quoted 27 lines · Philippe De Muyter

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.

---
 drivers/net/fec_mxc.c |   20 +++++++++++++++++---
 1 files changed, 17 insertions(+), 3 deletions(-)
drivers/net/fec_mxc.c +3 -0
index 3b2b995..3ab0ecd 100644
@@ -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.

drivers/net/fec_mxc.c static int fec_mdio_read(struct ethernet_regs *eth, uint8_t phyAddr, · line 139

Quoted 10 lines
drivers/net/fec_mxc.c +6 -3
+	 * 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

Why not fix it in arch/arm/cpu/armv7/mx6/clock.c ?

u32 imx_get_fecclk(void)
{

(quoted diff) +1 -1
-	return decode_pll(PLL_ENET, MXC_HCLK);
+	mxc_get_clock(MXC_IPG_CLK);
Quoted 1 line

}

Yeah. I had not thought about it. Thanks. Actually, one could also call directly get_ipg_clk().

Quoted 13 lines
Quoted 13 lines
drivers/net/fec_mxc.c +8 -0
+#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,
Signature · 1 line
Philippe De Muyter +32 2 6101532 Macq SA rue de l'Aeronef 2 B-1140 Bruxelles
#3 lore raw

PATCH v2 1/1 net: fec_mxc: fix mii_speed configuration for MX6's

In reply to Troy Kisky

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 the fec linux driver.

---
Change since v1:
- call get_ipg_clk() directly in mx6's imx_get_fecclk()

 arch/arm/cpu/armv7/mx6/clock.c |    2 +-
 drivers/net/fec_mxc.c          |   16 +++++++++++++---
 2 files changed, 14 insertions(+), 4 deletions(-)
arch/arm/cpu/armv7/mx6/clock.c +1 -1
index 5617a41..83bb3b7 100644
@@ -409,7 +409,7 @@ u32 imx_get_uartclk(void)
 
 u32 imx_get_fecclk(void)
 {
-	return decode_pll(PLL_ENET, MXC_HCLK);
+	return get_ipg_clk();
 }
 
 int enable_sata_clock(void)
drivers/net/fec_mxc.c +13 -3
index 3b2b995..02fd1a6 100644
@@ -124,13 +124,23 @@ 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));
+	sysclock = imx_get_fecclk();
+#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,
Signature · 1 line
1.7.5.3
#4 lore raw

PATCH 1/1 net: fec_mxc: fix mii_speed configuration for MX6's

In reply to Philippe De Muyter

Hello Phillip,

Am 19.02.2014 15:27, wrote Philippe De Muyter:

Quoted 7 lines

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.

this should be fixed with

ARM: imx6: fix wrong fec clk
NET: fec_mxc: fix MDIO clock prescaler calculation

and was pulled yesterday to

u-boot-arm/master

Quoted 42 lines
---
 drivers/net/fec_mxc.c |   20 +++++++++++++++++---
 1 files changed, 17 insertions(+), 3 deletions(-)
drivers/net/fec_mxc.c +17 -3
index 3b2b995..3ab0ecd 100644
@@ -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,
#5 lore raw

PATCH 1/1 net: fec_mxc: fix mii_speed configuration for MX6's

Hi Markus,

Quoted 11 lines · Markus Niebel

Hello Phillip,

Am 19.02.2014 15:27, wrote Philippe De Muyter:

Quoted 7 lines

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.

Quoted 8 lines

this should be fixed with

ARM: imx6: fix wrong fec clk
NET: fec_mxc: fix MDIO clock prescaler calculation

and was pulled yesterday to

u-boot-arm/master

I am working with plain u-boot (git://git.denx.de/u-boot.git), and of course those patches were not yet there yesterday :)

Thanks

Philippe

Quoted 43 lines
Quoted 43 lines
---
 drivers/net/fec_mxc.c |   20 +++++++++++++++++---
 1 files changed, 17 insertions(+), 3 deletions(-)
drivers/net/fec_mxc.c +17 -3
index 3b2b995..3ab0ecd 100644
@@ -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,
Signature · 1 line
Philippe De Muyter +32 2 6101532 Macq SA rue de l'Aeronef 2 B-1140 Bruxelles