mail archive of the barebox mailing list
 help / color / mirror / Atom feed
From: Sascha Hauer <s.hauer@pengutronix.de>
To: Jean-Christophe PLAGNIOL-VILLARD <plagnioj@jcrosoft.com>
Cc: barebox@lists.infradead.org
Subject: Re: [PATCH 1/3] net: introduce phylib
Date: Sat, 15 Sep 2012 14:24:28 +0200	[thread overview]
Message-ID: <20120915122428.GV24458@pengutronix.de> (raw)
In-Reply-To: <1347609426-21286-1-git-send-email-plagnioj@jcrosoft.com>

On Fri, Sep 14, 2012 at 09:57:04AM +0200, Jean-Christophe PLAGNIOL-VILLARD wrote:
> 
> Adapt phylib from linux
> 
> switch all the driver to it
> 
> This will allow to have
>  - phy drivers
>  - to only connect the phy at then opening of the device
>  - if the phy is not ready fail on open
> 
> Same behaviour as in linux and will allow to share code and simplify porting.
> 
> Signed-off-by: Jean-Christophe PLAGNIOL-VILLARD <plagnioj@jcrosoft.com>
> ---

Had to squash the following in to fix compile breakage on i.MX6 boards.

Overall it seems there is enough room for cleanup still. We used to have
a struct mii_device which was a combination of a mii_bus and a
phy_device. Now we have a dedicated phy_device, but struct mii_device
still has a single phy and a single cdev. I think we should move the
struct cdev to struct phy_device and make the struct phy_device member
of struct mii_device a list of phy_devices. Anyway, this can be done
later.

For now I merged this series with the below changes.

Sascha


diff --git a/arch/arm/boards/freescale-mx6-arm2/board.c b/arch/arm/boards/freescale-mx6-arm2/board.c
index e4a9a49..7b08106 100644
--- a/arch/arm/boards/freescale-mx6-arm2/board.c
+++ b/arch/arm/boards/freescale-mx6-arm2/board.c
@@ -31,6 +31,7 @@
 #include <asm/mmu.h>
 #include <mach/generic.h>
 #include <sizes.h>
+#include <phy.h>
 #include <mach/imx6.h>
 #include <mach/devices-imx6.h>
 #include <mach/iomux-mx6.h>
@@ -112,7 +113,9 @@ static struct fec_platform_data fec_info = {
 static int mx6_rgmii_rework(void)
 {
 	struct mii_device *mdev;
+	struct phy_device *pdev;
 	u16 val;
+	int ret;
 
 	mdev = mii_open("phy0");
 	if (!mdev) {
@@ -120,26 +123,35 @@ static int mx6_rgmii_rework(void)
 		return -ENODEV;
 	}
 
+	pdev = mdev->phydev;
+	if (!pdev) {
+		printf("phy0 has no phydev\n");
+		ret = -ENODEV;
+		goto out;
+	}
+
 	/* To enable AR8031 ouput a 125MHz clk from CLK_25M */
-	mii_write(mdev, mdev->address, 0xd, 0x7);
-	mii_write(mdev, mdev->address, 0xe, 0x8016);
-	mii_write(mdev, mdev->address, 0xd, 0x4007);
+	phy_write(pdev, 0xd, 0x7);
+	phy_write(pdev, 0xe, 0x8016);
+	phy_write(pdev, 0xd, 0x4007);
 
-	val = mii_read(mdev, mdev->address, 0xe);
+	val = phy_read(pdev, 0xe);
 	val &= 0xffe3;
 	val |= 0x18;
-	mii_write(mdev, mdev->address, 0xe, val);
+	phy_write(pdev, 0xe, val);
 
 	/* introduce tx clock delay */
-	mii_write(mdev, mdev->address, 0x1d, 0x5);
+	phy_write(pdev, 0x1d, 0x5);
 
-	val = mii_read(mdev, mdev->address, 0x1e);
+	val = phy_read(pdev, 0x1e);
 	val |= 0x0100;
-	mii_write(mdev, mdev->address, 0x1e, val);
+	phy_write(pdev, 0x1e, val);
 
+	ret = 0;
+out:
 	mii_close(mdev);
 
-	return 0;
+	return ret;
 }
 
 static int arm2_devices_init(void)
diff --git a/arch/arm/boards/freescale-mx6-sabrelite/board.c b/arch/arm/boards/freescale-mx6-sabrelite/board.c
index 1ac401e..aded4ec 100644
--- a/arch/arm/boards/freescale-mx6-sabrelite/board.c
+++ b/arch/arm/boards/freescale-mx6-sabrelite/board.c
@@ -40,6 +40,7 @@
 #include <mach/gpio.h>
 #include <spi/spi.h>
 #include <mach/spi.h>
+#include <phy.h>
 
 #define SABRELITE_SD3_WP	IMX_GPIO_NR(7, 1)
 #define SABRELITE_SD3_CD	IMX_GPIO_NR(7, 0)
@@ -143,6 +144,8 @@ static struct fec_platform_data fec_info = {
 int mx6_rgmii_rework(void)
 {
 	struct mii_device *mdev;
+	struct phy_device *pdev;
+	int ret;
 
 	mdev = mii_open("phy0");
 	if (!mdev) {
@@ -150,21 +153,30 @@ int mx6_rgmii_rework(void)
 		return -ENODEV;
 	}
 
-	mii_write(mdev, mdev->address, 0x09, 0x0f00);
+	pdev = mdev->phydev;
+	if (!pdev) {
+		printf("phy0 has no phydev\n");
+		ret = -ENODEV;
+		goto out;
+	}
+
+	phy_write(pdev, 0x09, 0x0f00);
 
 	/* do same as linux kernel */
 	/* min rx data delay */
-	mii_write(mdev, mdev->address, 0x0b, 0x8105);
-	mii_write(mdev, mdev->address, 0x0c, 0x0000);
+	phy_write(pdev, 0x0b, 0x8105);
+	phy_write(pdev, 0x0c, 0x0000);
 
 	/* max rx/tx clock delay, min rx/tx control delay */
-	mii_write(mdev, mdev->address, 0x0b, 0x8104);
-	mii_write(mdev, mdev->address, 0x0c, 0xf0f0);
-	mii_write(mdev, mdev->address, 0x0b, 0x104);
+	phy_write(pdev, 0x0b, 0x8104);
+	phy_write(pdev, 0x0c, 0xf0f0);
+	phy_write(pdev, 0x0b, 0x104);
 
+	ret = 0;
+out:
 	mii_close(mdev);
 
-	return 0;
+	return ret;
 }
 
 static int sabrelite_ksz9021rn_setup(void)

-- 
Pengutronix e.K.                           |                             |
Industrial Linux Solutions                 | http://www.pengutronix.de/  |
Peiner Str. 6-8, 31137 Hildesheim, Germany | Phone: +49-5121-206917-0    |
Amtsgericht Hildesheim, HRA 2686           | Fax:   +49-5121-206917-5555 |

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

  parent reply	other threads:[~2012-09-15 12:25 UTC|newest]

Thread overview: 13+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2012-09-14  7:37 [PATCH 0/3 v3] net: check error and " Jean-Christophe PLAGNIOL-VILLARD
2012-09-14  7:57 ` [PATCH 1/3] net: " Jean-Christophe PLAGNIOL-VILLARD
2012-09-14  7:57   ` [PATCH 2/3] net: catch error on eth_send Jean-Christophe PLAGNIOL-VILLARD
2012-09-16  9:57     ` Jean-Christophe PLAGNIOL-VILLARD
2012-09-14  7:57   ` [PATCH 3/3] net: move the eth_dev status detection at driver level Jean-Christophe PLAGNIOL-VILLARD
2012-09-16  8:12     ` Sascha Hauer
2012-09-15 12:24   ` Sascha Hauer [this message]
2012-09-16  8:11   ` [PATCH 1/3] net: introduce phylib Sascha Hauer
2012-09-16  8:28     ` Jean-Christophe PLAGNIOL-VILLARD
2012-09-16  8:34       ` Sascha Hauer
2012-09-16  9:02         ` Jean-Christophe PLAGNIOL-VILLARD
2012-09-16  9:13           ` Sascha Hauer
2012-09-16  9:41             ` 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=20120915122428.GV24458@pengutronix.de \
    --to=s.hauer@pengutronix.de \
    --cc=barebox@lists.infradead.org \
    --cc=plagnioj@jcrosoft.com \
    /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