mail archive of the barebox mailing list
 help / color / mirror / Atom feed
From: Jean-Christophe PLAGNIOL-VILLARD <plagnioj@jcrosoft.com>
To: barebox@lists.infradead.org
Subject: [for master PATCH 1/2] miidev: add phy_addr detection support
Date: Tue, 14 Aug 2012 17:48:55 +0200	[thread overview]
Message-ID: <1344959336-18562-1-git-send-email-plagnioj@jcrosoft.com> (raw)

export via param the phy_addr and the phy_id detected

Signed-off-by: Jean-Christophe PLAGNIOL-VILLARD <plagnioj@jcrosoft.com>
---
Hi,

	this is need to fix the calao board support since the introduction of
	the gigabit phy detection support

Best Regards,
J.
 drivers/net/miidev.c |   76 ++++++++++++++++++++++++++++++++++++++++++++++----
 include/miidev.h     |    2 ++
 2 files changed, 72 insertions(+), 6 deletions(-)

diff --git a/drivers/net/miidev.c b/drivers/net/miidev.c
index b49944b..ab1811d 100644
--- a/drivers/net/miidev.c
+++ b/drivers/net/miidev.c
@@ -236,18 +236,82 @@ static struct file_operations miidev_ops = {
 	.lseek = dev_lseek_default,
 };
 
+static int get_phy_id(struct mii_device *mdev, int phy_addr,
+			  uint32_t *phy_id)
+{
+	int val;
+
+	val = mii_read(mdev, phy_addr, MII_PHYSID1);
+	if (val < 0)
+		return -EIO;
+	*phy_id = (val & 0xffff) << 16;
+	val = mii_read(mdev, phy_addr, MII_PHYSID2);
+	if (val < 0)
+		return -EIO;
+	*phy_id |= (val & 0xffff);
+
+	return 0;
+}
+
+static int phy_detect_one(struct mii_device *mdev, int phy_addr,
+			  uint32_t *phy_id)
+{
+	uint32_t _phy_id;
+	int ret;
+
+	ret = get_phy_id(mdev, phy_addr, &_phy_id);
+
+	if (ret)
+		return ret;
+
+	/* If the phy_id is mostly Fs, there is no device there */
+	if ((_phy_id & 0x1fffffff) == 0x1fffffff)
+		return -EIO;
+
+	*phy_id = _phy_id;
+
+	return 0;
+}
+
+static int phy_detect(struct mii_device *mdev)
+{
+	int phy_addr;
+
+	for (phy_addr = 0; phy_addr <= 0x1f; phy_addr++) {
+		if (!phy_detect_one(mdev, phy_addr, &mdev->phy_id))
+			return phy_addr;
+	}
+
+	return -EIO;
+}
+
 static int miidev_probe(struct device_d *dev)
 {
 	struct mii_device *mdev = dev->priv;
 	int val;
 	int caps = 0;
+	char str[11];
+
+	if (mdev->address < 0) {
+		int phy_addr;
+
+		phy_addr = phy_detect(mdev);
+
+		if (phy_addr < 0) {
+			dev_err(dev, "cannot detect PHY\n");
+			return -ENODEV;
+		}
+		mdev->address = phy_addr;
+	} else {
+		if (phy_detect_one(mdev, mdev->address, &mdev->phy_id) < 0)
+			goto err_out;
+	}
+
+	sprintf(str, "%u", mdev->address);
+	dev_add_param_fixed(dev, "phy_addr", str);
+	sprintf(str, "0x%08x", mdev->phy_id);
+	dev_add_param_fixed(dev, "phy_id", str);
 
-	val = mii_read(mdev, mdev->address, MII_PHYSID1);
-	if (val < 0 || val == 0xffff)
-		goto err_out;
-	val = mii_read(mdev, mdev->address, MII_PHYSID2);
-	if (val < 0 || val == 0xffff)
-		goto err_out;
 	val = mii_read(mdev, mdev->address, MII_BMSR);
 	if (val < 0)
 		goto err_out;
diff --git a/include/miidev.h b/include/miidev.h
index 4bbf94c..2f39234 100644
--- a/include/miidev.h
+++ b/include/miidev.h
@@ -38,6 +38,8 @@ struct mii_device {
 	struct device_d *parent;
 
 	int address;	/* The address the phy has on the bus */
+	uint32_t phy_id;	/* The phy id */
+
 	int	(*read) (struct mii_device *dev, int addr, int reg);
 	int	(*write) (struct mii_device *dev, int addr, int reg, int value);
 
-- 
1.7.10.4


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

             reply	other threads:[~2012-08-14 15:48 UTC|newest]

Thread overview: 14+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2012-08-14 15:48 Jean-Christophe PLAGNIOL-VILLARD [this message]
2012-08-14 15:48 ` [for master PATCH 2/2] calao: at91 qil/tny/usb auto detect the phy addr Jean-Christophe PLAGNIOL-VILLARD
2012-09-15 14:23   ` Jean-Christophe PLAGNIOL-VILLARD
2012-10-02 14:25     ` Jean-Christophe PLAGNIOL-VILLARD
2012-08-14 19:58 ` [for master PATCH 1/2] miidev: add phy_addr detection support Sascha Hauer
2012-08-15  4:32   ` Jean-Christophe PLAGNIOL-VILLARD
2012-08-29  7:09     ` Sascha Hauer
2012-09-10 15:19 ` Jean-Christophe PLAGNIOL-VILLARD
2012-09-11  7:53   ` Sascha Hauer
2012-09-11  8:57     ` Jean-Christophe PLAGNIOL-VILLARD
2012-09-11  9:14       ` Sascha Hauer
2012-09-11  9:25         ` Jean-Christophe PLAGNIOL-VILLARD
2012-10-02 13:23 ` Sascha Hauer
2012-10-02 14:25   ` Jean-Christophe PLAGNIOL-VILLARD

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=1344959336-18562-1-git-send-email-plagnioj@jcrosoft.com \
    --to=plagnioj@jcrosoft.com \
    --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