mail archive of the barebox mailing list
 help / color / mirror / Atom feed
From: Wolfram Sang <w.sang@pengutronix.de>
To: barebox@lists.infradead.org
Subject: [PATCH 4/5] net: miidev: factor out miidev_get_status()
Date: Tue, 24 Jan 2012 14:53:50 +0100	[thread overview]
Message-ID: <1327413231-17495-5-git-send-email-w.sang@pengutronix.de> (raw)
In-Reply-To: <1327413231-17495-1-git-send-email-w.sang@pengutronix.de>

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

  parent reply	other threads:[~2012-01-24 13:54 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
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 ` Wolfram Sang [this message]
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

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=1327413231-17495-5-git-send-email-w.sang@pengutronix.de \
    --to=w.sang@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