mail archive of the barebox mailing list
 help / color / mirror / Atom feed
* [PATCH 0/5] fec_imx & miidev: support for 10 MBit connections
@ 2012-01-24 13:53 Wolfram Sang
  2012-01-24 13:53 ` [PATCH 1/5] net: fec_imx: small cleanups Wolfram Sang
                   ` (4 more replies)
  0 siblings, 5 replies; 8+ messages in thread
From: Wolfram Sang @ 2012-01-24 13:53 UTC (permalink / raw)
  To: barebox

This series enables an MX28 to support 10 Mbit connections. It couldn't do
before, because a special bit has to be set, but the phy needs to be queried
first:

1/5, 2/5: minor cleanups
3/5: activate additional FEC features
4/5: refactor phy code to let drivers get the status
5/5: set 10MBit mode when phy reported such a connection

All tested on a custom MX28 board, very similar to MX28EVK.

Regards,

   Wolfram

Wolfram Sang (5):
  net: fec_imx: small cleanups
  net: fec_imx: refactor R_CNTRL setup
  net: fec_imx: enable payload length check and pause frames
  net: miidev: factor out miidev_get_status()
  net: fec_imx: configure FEC for 10Mbit when necessary

 drivers/net/fec_imx.c |   44 ++++++++++++++++----------------
 drivers/net/fec_imx.h |   14 ----------
 drivers/net/miidev.c  |   65 +++++++++++++++++++++++++++++++-----------------
 include/miidev.h      |    5 ++++
 4 files changed, 69 insertions(+), 59 deletions(-)

-- 
1.7.8.3


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

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

* [PATCH 1/5] net: fec_imx: small cleanups
  2012-01-24 13:53 [PATCH 0/5] fec_imx & miidev: support for 10 MBit connections Wolfram Sang
@ 2012-01-24 13:53 ` Wolfram Sang
  2012-01-24 13:53 ` [PATCH 2/5] net: fec_imx: refactor R_CNTRL setup Wolfram Sang
                   ` (3 subsequent siblings)
  4 siblings, 0 replies; 8+ messages in thread
From: Wolfram Sang @ 2012-01-24 13:53 UTC (permalink / raw)
  To: barebox

remove double include, remove unused (and double in case of RCNTRL)
defines, sort the includes at least somewhat.

Signed-off-by: Wolfram Sang <w.sang@pengutronix.de>
---
 drivers/net/fec_imx.c |    8 ++++----
 drivers/net/fec_imx.h |   14 --------------
 2 files changed, 4 insertions(+), 18 deletions(-)

diff --git a/drivers/net/fec_imx.c b/drivers/net/fec_imx.c
index ae63fdc..1101dad 100644
--- a/drivers/net/fec_imx.c
+++ b/drivers/net/fec_imx.c
@@ -22,21 +22,21 @@
 #include <malloc.h>
 #include <net.h>
 #include <init.h>
-#include <miidev.h>
 #include <driver.h>
 #include <miidev.h>
 #include <fec.h>
+#include <io.h>
+#include <clock.h>
+#include <xfuncs.h>
 
 #include <asm/mmu.h>
-#include <io.h>
+
 #include <mach/generic.h>
 #include <mach/imx-regs.h>
-#include <clock.h>
 #include <mach/clock.h>
 #ifndef CONFIG_ARCH_MXS
 # include <mach/iim.h>
 #endif
-#include <xfuncs.h>
 
 #include "fec_imx.h"
 
diff --git a/drivers/net/fec_imx.h b/drivers/net/fec_imx.h
index 19f4709..b75b4d6 100644
--- a/drivers/net/fec_imx.h
+++ b/drivers/net/fec_imx.h
@@ -94,20 +94,6 @@
 #define FEC_IMASK_COL_RETRY_LIM         0x00100000
 #define FEC_IMASK_XFIFO_UN              0x00080000
 
-#define FEC_RCNTRL_MAX_FL_SHIFT         16
-#define FEC_RCNTRL_LOOP                 0x01
-#define FEC_RCNTRL_DRT                  0x02
-#define FEC_RCNTRL_MII_MODE             0x04
-#define FEC_RCNTRL_PROM                 0x08
-#define FEC_RCNTRL_BC_REJ               0x10
-#define FEC_RCNTRL_FCE                  0x20
-
-#define FEC_TCNTRL_GTS                  0x00000001
-#define FEC_TCNTRL_HBC                  0x00000002
-#define FEC_TCNTRL_FDEN                 0x00000004
-#define FEC_TCNTRL_TFC_PAUSE            0x00000008
-#define FEC_TCNTRL_RFC_PAUSE            0x00000010
-
 #define FEC_ECNTRL_RESET                0x00000001	/**< reset the FEC */
 #define FEC_ECNTRL_ETHER_EN             0x00000002	/**< enable the FEC */
 
-- 
1.7.8.3


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

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

* [PATCH 2/5] net: fec_imx: refactor R_CNTRL setup
  2012-01-24 13:53 [PATCH 0/5] fec_imx & miidev: support for 10 MBit connections Wolfram Sang
  2012-01-24 13:53 ` [PATCH 1/5] net: fec_imx: small cleanups Wolfram Sang
@ 2012-01-24 13:53 ` Wolfram Sang
  2012-01-24 13:53 ` [PATCH 3/5] net: fec_imx: enable payload length check and pause frames Wolfram Sang
                   ` (2 subsequent siblings)
  4 siblings, 0 replies; 8+ messages in thread
From: Wolfram Sang @ 2012-01-24 13:53 UTC (permalink / raw)
  To: barebox

Introduce a variable which gets updated when needed and only written
once. Will make further additions easier.

Signed-off-by: Wolfram Sang <w.sang@pengutronix.de>
---
 drivers/net/fec_imx.c |   23 +++++++----------------
 1 files changed, 7 insertions(+), 16 deletions(-)

diff --git a/drivers/net/fec_imx.c b/drivers/net/fec_imx.c
index 1101dad..15c7a4a 100644
--- a/drivers/net/fec_imx.c
+++ b/drivers/net/fec_imx.c
@@ -274,6 +274,7 @@ static int fec_set_hwaddr(struct eth_device *dev, unsigned char *mac)
 static int fec_init(struct eth_device *dev)
 {
 	struct fec_priv *fec = (struct fec_priv *)dev->priv;
+	u32 rcntl;
 
 	/*
 	 * Clear FEC-Lite interrupt event register(IEVENT)
@@ -288,17 +289,9 @@ static int fec_init(struct eth_device *dev)
 	/*
 	 * Set FEC-Lite receive control register(R_CNTRL):
 	 */
-	if (fec->xcv_type == SEVENWIRE) {
-		/*
-		 * Frame length=1518; 7-wire mode
-		 */
-		writel(FEC_R_CNTRL_MAX_FL(1518), fec->regs + FEC_R_CNTRL);
-	} else {
-		/*
-		 * Frame length=1518; MII mode;
-		 */
-		writel(FEC_R_CNTRL_MAX_FL(1518) | FEC_R_CNTRL_MII_MODE,
-			fec->regs + FEC_R_CNTRL);
+	rcntl = FEC_R_CNTRL_MAX_FL(1518);
+	if (fec->xcv_type != SEVENWIRE) {
+		rcntl |= FEC_R_CNTRL_MII_MODE;
 		/*
 		 * Set MII_SPEED = (1/(mii_speed * 2)) * System Clock
 		 * and do not drop the Preamble.
@@ -309,13 +302,10 @@ static int fec_init(struct eth_device *dev)
 
 	if (fec->xcv_type == RMII) {
 		if (cpu_is_mx28()) {
-			/* just another way to enable RMII */
-			uint32_t reg = readl(fec->regs + FEC_R_CNTRL);
-			writel(reg | FEC_R_CNTRL_RMII_MODE
+			rcntl |= FEC_R_CNTRL_RMII_MODE;
 				/* the linux driver add these bits, why not we? */
 				/* | FEC_R_CNTRL_FCE | */
-				/* FEC_R_CNTRL_NO_LGTH_CHECK */,
-				fec->regs + FEC_R_CNTRL);
+				/* FEC_R_CNTRL_NO_LGTH_CHECK */
 		} else {
 			/* disable the gasket and wait */
 			writel(0, fec->regs + FEC_MIIGSK_ENR);
@@ -329,6 +319,7 @@ static int fec_init(struct eth_device *dev)
 			writel(FEC_MIIGSK_ENR_EN, fec->regs + FEC_MIIGSK_ENR);
 		}
 	}
+	writel(rcntl, fec->regs + FEC_R_CNTRL);
 
 	/*
 	 * Set Opcode/Pause Duration Register
-- 
1.7.8.3


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

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

* [PATCH 3/5] net: fec_imx: enable payload length check and pause frames
  2012-01-24 13:53 [PATCH 0/5] fec_imx & miidev: support for 10 MBit connections Wolfram Sang
  2012-01-24 13:53 ` [PATCH 1/5] net: fec_imx: small cleanups Wolfram Sang
  2012-01-24 13:53 ` [PATCH 2/5] net: fec_imx: refactor R_CNTRL setup Wolfram Sang
@ 2012-01-24 13:53 ` Wolfram Sang
  2012-01-24 13:53 ` [PATCH 4/5] net: miidev: factor out miidev_get_status() Wolfram Sang
  2012-01-24 13:53 ` [PATCH 5/5] net: fec_imx: configure FEC for 10Mbit when necessary Wolfram Sang
  4 siblings, 0 replies; 8+ messages in thread
From: Wolfram Sang @ 2012-01-24 13:53 UTC (permalink / raw)
  To: barebox

Q: "the linux driver add these bits, why not we?"
A: Because nobody activated the bits?

Signed-off-by: Wolfram Sang <w.sang@pengutronix.de>
---
 drivers/net/fec_imx.c |    6 ++----
 1 files changed, 2 insertions(+), 4 deletions(-)

diff --git a/drivers/net/fec_imx.c b/drivers/net/fec_imx.c
index 15c7a4a..45af78f 100644
--- a/drivers/net/fec_imx.c
+++ b/drivers/net/fec_imx.c
@@ -302,10 +302,8 @@ static int fec_init(struct eth_device *dev)
 
 	if (fec->xcv_type == RMII) {
 		if (cpu_is_mx28()) {
-			rcntl |= FEC_R_CNTRL_RMII_MODE;
-				/* the linux driver add these bits, why not we? */
-				/* | FEC_R_CNTRL_FCE | */
-				/* FEC_R_CNTRL_NO_LGTH_CHECK */
+			rcntl |= FEC_R_CNTRL_RMII_MODE | FEC_R_CNTRL_FCE |
+				FEC_R_CNTRL_NO_LGTH_CHECK;
 		} else {
 			/* disable the gasket and wait */
 			writel(0, fec->regs + FEC_MIIGSK_ENR);
-- 
1.7.8.3


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

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

* [PATCH 4/5] net: miidev: factor out miidev_get_status()
  2012-01-24 13:53 [PATCH 0/5] fec_imx & miidev: support for 10 MBit connections Wolfram Sang
                   ` (2 preceding siblings ...)
  2012-01-24 13:53 ` [PATCH 3/5] net: fec_imx: enable payload length check and pause frames Wolfram Sang
@ 2012-01-24 13:53 ` Wolfram Sang
  2012-01-24 13:53 ` [PATCH 5/5] net: fec_imx: configure FEC for 10Mbit when necessary Wolfram Sang
  4 siblings, 0 replies; 8+ messages in thread
From: Wolfram Sang @ 2012-01-24 13:53 UTC (permalink / raw)
  To: barebox

Currently, we can only print the phy_status. Factor out the routine to
get the status, so we can query it from fec drivers and configure
accordingly. Needed because mx28 needs a special bit set for 10Mbit.

Signed-off-by: Wolfram Sang <w.sang@pengutronix.de>
---
 drivers/net/miidev.c |   65 ++++++++++++++++++++++++++++++++-----------------
 include/miidev.h     |    5 ++++
 2 files changed, 47 insertions(+), 23 deletions(-)

diff --git a/drivers/net/miidev.c b/drivers/net/miidev.c
index 501a4f8..d721aac 100644
--- a/drivers/net/miidev.c
+++ b/drivers/net/miidev.c
@@ -100,44 +100,63 @@ int miidev_wait_aneg(struct mii_device *mdev)
 	return 0;
 }
 
+int miidev_get_status(struct mii_device *mdev)
+{
+	int ret, status;
+
+	ret = mii_read(mdev, mdev->address, MII_BMSR);
+	if (ret < 0)
+		goto err_out;
+
+	status = ret & BMSR_LSTATUS ? MIIDEV_STATUS_IS_UP : 0;
+
+	ret = mii_read(mdev, mdev->address, MII_BMCR);
+	if (ret < 0)
+		goto err_out;
+
+	if (ret & BMCR_ANENABLE) {
+		ret = mii_read(mdev, mdev->address, MII_LPA);
+		if (ret < 0)
+			goto err_out;
+
+		status |= ret & LPA_DUPLEX ? MIIDEV_STATUS_IS_FULL_DUPLEX : 0;
+		status |= ret & LPA_100 ? MIIDEV_STATUS_IS_100MBIT :
+				MIIDEV_STATUS_IS_10MBIT;
+	} else {
+		status |= ret & BMCR_FULLDPLX ? MIIDEV_STATUS_IS_FULL_DUPLEX : 0;
+		status |= ret & BMCR_SPEED100 ? MIIDEV_STATUS_IS_100MBIT :
+			MIIDEV_STATUS_IS_10MBIT;
+	}
+
+	return status;
+err_out:
+	printf("%s: failed to read (%d)\n", mdev->cdev.name, ret);
+	return ret;
+}
+
 int miidev_print_status(struct mii_device *mdev)
 {
-	int bmsr, bmcr, lpa;
 	char *duplex;
-	int speed;
+	int speed, status;
 
 	if (mdev->flags & MIIDEV_FORCE_LINK) {
 		printf("Forcing link present...\n");
 		return 0;
 	}
 
-	bmsr = mii_read(mdev, mdev->address, MII_BMSR);
-	if (bmsr < 0)
-		goto err_out;
-	bmcr = mii_read(mdev, mdev->address, MII_BMCR);
-	if (bmcr < 0)
-		goto err_out;
-	lpa = mii_read(mdev, mdev->address, MII_LPA);
-	if (lpa < 0)
-		goto err_out;
+	status = miidev_get_status(mdev);
+	if (status < 0)
+		return status;
 
-	printf("%s: Link is %s", mdev->cdev.name,
-			bmsr & BMSR_LSTATUS ? "up" : "down");
+	duplex = status & MIIDEV_STATUS_IS_FULL_DUPLEX ? "Full" : "Half";
+	speed = status & MIIDEV_STATUS_IS_100MBIT ? 100 : 10;
 
-	if (bmcr & BMCR_ANENABLE) {
-		duplex = lpa & LPA_DUPLEX ? "Full" : "Half";
-		speed = lpa & LPA_100 ? 100 : 10;
-	} else {
-		duplex = bmcr & BMCR_FULLDPLX ? "Full" : "Half";
-		speed = bmcr & BMCR_SPEED100 ? 100 : 10;
-	}
 
+	printf("%s: Link is %s", mdev->cdev.name,
+			status & MIIDEV_STATUS_IS_UP ? "up" : "down");
 	printf(" - %d/%s\n", speed, duplex);
 
 	return 0;
-err_out:
-	printf("%s: failed to read\n", mdev->cdev.name);
-	return -1;
 }
 
 static ssize_t miidev_read(struct cdev *cdev, void *_buf, size_t count, ulong offset, ulong flags)
diff --git a/include/miidev.h b/include/miidev.h
index 21727ef..8cd4c45 100644
--- a/include/miidev.h
+++ b/include/miidev.h
@@ -49,6 +49,11 @@ int mii_register(struct mii_device *dev);
 void mii_unregister(struct mii_device *mdev);
 int miidev_restart_aneg(struct mii_device *mdev);
 int miidev_wait_aneg(struct mii_device *mdev);
+int miidev_get_status(struct mii_device *mdev);
+#define MIIDEV_STATUS_IS_UP		(1 << 0)
+#define MIIDEV_STATUS_IS_FULL_DUPLEX	(1 << 1)
+#define MIIDEV_STATUS_IS_10MBIT		(1 << 2)
+#define MIIDEV_STATUS_IS_100MBIT	(1 << 3)
 int miidev_print_status(struct mii_device *mdev);
 
 static int inline mii_write(struct mii_device *dev, int addr, int reg, int value)
-- 
1.7.8.3


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

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

* [PATCH 5/5] net: fec_imx: configure FEC for 10Mbit when necessary
  2012-01-24 13:53 [PATCH 0/5] fec_imx & miidev: support for 10 MBit connections Wolfram Sang
                   ` (3 preceding siblings ...)
  2012-01-24 13:53 ` [PATCH 4/5] net: miidev: factor out miidev_get_status() Wolfram Sang
@ 2012-01-24 13:53 ` Wolfram Sang
  2012-01-24 15:38   ` Eric Bénard
  4 siblings, 1 reply; 8+ messages in thread
From: Wolfram Sang @ 2012-01-24 13:53 UTC (permalink / raw)
  To: barebox

Signed-off-by: Wolfram Sang <w.sang@pengutronix.de>
---
 drivers/net/fec_imx.c |   11 +++++++++++
 1 files changed, 11 insertions(+), 0 deletions(-)

diff --git a/drivers/net/fec_imx.c b/drivers/net/fec_imx.c
index 45af78f..653b488 100644
--- a/drivers/net/fec_imx.c
+++ b/drivers/net/fec_imx.c
@@ -373,6 +373,17 @@ static int fec_open(struct eth_device *edev)
 		ret = miidev_wait_aneg(&fec->miidev);
 		if (ret)
 			return ret;
+
+		ret = miidev_get_status(&fec->miidev);
+		if (ret < 0)
+			return ret;
+
+		if (ret & MIIDEV_STATUS_IS_10MBIT) {
+			u32 rcntl = readl(fec->regs + FEC_R_CNTRL);
+			rcntl |= FEC_R_CNTRL_RMII_10T;
+			writel(rcntl, fec->regs + FEC_R_CNTRL);
+		}
+
 		miidev_print_status(&fec->miidev);
 	}
 
-- 
1.7.8.3


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

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

* Re: [PATCH 5/5] net: fec_imx: configure FEC for 10Mbit when necessary
  2012-01-24 13:53 ` [PATCH 5/5] net: fec_imx: configure FEC for 10Mbit when necessary Wolfram Sang
@ 2012-01-24 15:38   ` Eric Bénard
  2012-01-24 15:40     ` Wolfram Sang
  0 siblings, 1 reply; 8+ messages in thread
From: Eric Bénard @ 2012-01-24 15:38 UTC (permalink / raw)
  To: Wolfram Sang; +Cc: barebox

Hi Wolfram,

Le Tue, 24 Jan 2012 14:53:51 +0100,
Wolfram Sang <w.sang@pengutronix.de> a écrit :

> Signed-off-by: Wolfram Sang <w.sang@pengutronix.de>
> ---
>  drivers/net/fec_imx.c |   11 +++++++++++
>  1 files changed, 11 insertions(+), 0 deletions(-)
> 
> diff --git a/drivers/net/fec_imx.c b/drivers/net/fec_imx.c
> index 45af78f..653b488 100644
> --- a/drivers/net/fec_imx.c
> +++ b/drivers/net/fec_imx.c
> @@ -373,6 +373,17 @@ static int fec_open(struct eth_device *edev)
>  		ret = miidev_wait_aneg(&fec->miidev);
>  		if (ret)
>  			return ret;
> +
> +		ret = miidev_get_status(&fec->miidev);
> +		if (ret < 0)
> +			return ret;
> +
> +		if (ret & MIIDEV_STATUS_IS_10MBIT) {
> +			u32 rcntl = readl(fec->regs + FEC_R_CNTRL);
> +			rcntl |= FEC_R_CNTRL_RMII_10T;
> +			writel(rcntl, fec->regs + FEC_R_CNTRL);
> +		}
> +
>  		miidev_print_status(&fec->miidev);
>  	}
>  

I didn't check the code where this patch is inserted but if the fec is
similar to the MX25 one, you need to set this bit only when wired in
RMII so maybe you need a test for the way the PHY is wired.

Here is what is in the kernel for the i.MX25 :
http://git.kernel.org/?p=linux/kernel/git/torvalds/linux-2.6.git;a=commitdiff;h=8d82f219c2d476811cd3157a39c7b5c1f045ebc3;hp=25cecd7e355bf90b8fea039bd06947bb3234e77d

Eric

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

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

* Re: [PATCH 5/5] net: fec_imx: configure FEC for 10Mbit when necessary
  2012-01-24 15:38   ` Eric Bénard
@ 2012-01-24 15:40     ` Wolfram Sang
  0 siblings, 0 replies; 8+ messages in thread
From: Wolfram Sang @ 2012-01-24 15:40 UTC (permalink / raw)
  To: Eric Bénard; +Cc: barebox


[-- Attachment #1.1: Type: text/plain, Size: 579 bytes --]

Eric,

> I didn't check the code where this patch is inserted but if the fec is
> similar to the MX25 one, you need to set this bit only when wired in
> RMII so maybe you need a test for the way the PHY is wired.

I know this patch, it is different. The MX28 has no gasking, and only
MX28 has this special bit which needs to be set after the negotiation.
Kernel does it this way, too.

Regards,

   Wolfram

-- 
Pengutronix e.K.                           | Wolfram Sang                |
Industrial Linux Solutions                 | http://www.pengutronix.de/  |

[-- Attachment #1.2: Digital signature --]
[-- Type: application/pgp-signature, Size: 198 bytes --]

[-- Attachment #2: Type: text/plain, Size: 149 bytes --]

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

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

end of thread, other threads:[~2012-01-24 15:41 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2012-01-24 13:53 [PATCH 0/5] fec_imx & miidev: support for 10 MBit connections Wolfram Sang
2012-01-24 13:53 ` [PATCH 1/5] net: fec_imx: small cleanups Wolfram Sang
2012-01-24 13:53 ` [PATCH 2/5] net: fec_imx: refactor R_CNTRL setup Wolfram Sang
2012-01-24 13:53 ` [PATCH 3/5] net: fec_imx: enable payload length check and pause frames Wolfram Sang
2012-01-24 13:53 ` [PATCH 4/5] net: miidev: factor out miidev_get_status() Wolfram Sang
2012-01-24 13:53 ` [PATCH 5/5] net: fec_imx: configure FEC for 10Mbit when necessary Wolfram Sang
2012-01-24 15:38   ` Eric Bénard
2012-01-24 15:40     ` Wolfram Sang

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