[U-Boot] net: ravb: Initialize PHY in probe() once

Message ID 20180213162954.15329-1-marek.vasut+renesas@gmail.com
State New
Delegated to: Joe Hershberger
Headers show
Series
  • [U-Boot] net: ravb: Initialize PHY in probe() once
Related show

Commit Message

Marek Vasut Feb. 13, 2018, 4:29 p.m.
Reset and initialize the PHY once in the probe() function rather than
doing it over and over again is start() function. This requires us to
keep the clock enabled while the driver is in use. This significantly
reduces the time between transfers as the PHY doesn't have to restart
autonegotiation between transfers, which takes forever.

Signed-off-by: Marek Vasut <marek.vasut+renesas@gmail.com>
Cc: Geert Uytterhoeven <geert+renesas@glider.be>
Cc: Joe Hershberger <joe.hershberger@ni.com>
---
 drivers/net/ravb.c | 32 +++++++++++++++++++-------------
 1 file changed, 19 insertions(+), 13 deletions(-)

Comments

Joe Hershberger Feb. 13, 2018, 5:35 p.m. | #1
On Tue, Feb 13, 2018 at 10:29 AM, Marek Vasut <marek.vasut@gmail.com> wrote:
> Reset and initialize the PHY once in the probe() function rather than
> doing it over and over again is start() function. This requires us to
> keep the clock enabled while the driver is in use. This significantly
> reduces the time between transfers as the PHY doesn't have to restart
> autonegotiation between transfers, which takes forever.
>
> Signed-off-by: Marek Vasut <marek.vasut+renesas@gmail.com>
> Cc: Geert Uytterhoeven <geert+renesas@glider.be>
> Cc: Joe Hershberger <joe.hershberger@ni.com>

Acked-by: Joe Hershberger <joe.hershberger@ni.com>
Marek Vasut Feb. 13, 2018, 5:39 p.m. | #2
On 02/13/2018 06:35 PM, Joe Hershberger wrote:
> On Tue, Feb 13, 2018 at 10:29 AM, Marek Vasut <marek.vasut@gmail.com> wrote:
>> Reset and initialize the PHY once in the probe() function rather than
>> doing it over and over again is start() function. This requires us to
>> keep the clock enabled while the driver is in use. This significantly
>> reduces the time between transfers as the PHY doesn't have to restart
>> autonegotiation between transfers, which takes forever.
>>
>> Signed-off-by: Marek Vasut <marek.vasut+renesas@gmail.com>
>> Cc: Geert Uytterhoeven <geert+renesas@glider.be>
>> Cc: Joe Hershberger <joe.hershberger@ni.com>
> 
> Acked-by: Joe Hershberger <joe.hershberger@ni.com>

Thanks, I'll pick it via u-boot-sh if you don't mind.
Or do you want to take it ?
Joe Hershberger Feb. 13, 2018, 5:40 p.m. | #3
On Tue, Feb 13, 2018 at 11:39 AM, Marek Vasut <marek.vasut@gmail.com> wrote:
> On 02/13/2018 06:35 PM, Joe Hershberger wrote:
>> On Tue, Feb 13, 2018 at 10:29 AM, Marek Vasut <marek.vasut@gmail.com> wrote:
>>> Reset and initialize the PHY once in the probe() function rather than
>>> doing it over and over again is start() function. This requires us to
>>> keep the clock enabled while the driver is in use. This significantly
>>> reduces the time between transfers as the PHY doesn't have to restart
>>> autonegotiation between transfers, which takes forever.
>>>
>>> Signed-off-by: Marek Vasut <marek.vasut+renesas@gmail.com>
>>> Cc: Geert Uytterhoeven <geert+renesas@glider.be>
>>> Cc: Joe Hershberger <joe.hershberger@ni.com>
>>
>> Acked-by: Joe Hershberger <joe.hershberger@ni.com>
>
> Thanks, I'll pick it via u-boot-sh if you don't mind.
> Or do you want to take it ?

Feel free to take it, but update patchwork to delegate to you.

Cheers,
-Joe

>
> --
> Best regards,
> Marek Vasut

Patch

diff --git a/drivers/net/ravb.c b/drivers/net/ravb.c
index 093288b639..bd30cba940 100644
--- a/drivers/net/ravb.c
+++ b/drivers/net/ravb.c
@@ -399,7 +399,7 @@  static int ravb_dmac_init(struct udevice *dev)
 static int ravb_config(struct udevice *dev)
 {
 	struct ravb_priv *eth = dev_get_priv(dev);
-	struct phy_device *phy;
+	struct phy_device *phy = eth->phydev;
 	u32 mask = ECMR_CHG_DM | ECMR_RE | ECMR_TE;
 	int ret;
 
@@ -410,13 +410,6 @@  static int ravb_config(struct udevice *dev)
 	ravb_mac_init(eth);
 	ravb_write_hwaddr(dev);
 
-	/* Configure phy */
-	ret = ravb_phy_config(dev);
-	if (ret)
-		return ret;
-
-	phy = eth->phydev;
-
 	ret = phy_startup(phy);
 	if (ret)
 		return ret;
@@ -443,10 +436,6 @@  static int ravb_start(struct udevice *dev)
 	struct ravb_priv *eth = dev_get_priv(dev);
 	int ret;
 
-	ret = clk_enable(&eth->clk);
-	if (ret)
-		return ret;
-
 	ret = ravb_reset(dev);
 	if (ret)
 		goto err;
@@ -473,8 +462,8 @@  static void ravb_stop(struct udevice *dev)
 {
 	struct ravb_priv *eth = dev_get_priv(dev);
 
+	phy_shutdown(eth->phydev);
 	ravb_reset(dev);
-	clk_disable(&eth->clk);
 }
 
 static int ravb_probe(struct udevice *dev)
@@ -512,8 +501,23 @@  static int ravb_probe(struct udevice *dev)
 
 	eth->bus = miiphy_get_dev_by_name(dev->name);
 
+	/* Bring up PHY */
+	ret = clk_enable(&eth->clk);
+	if (ret)
+		goto err_mdio_register;
+
+	ret = ravb_reset(dev);
+	if (ret)
+		goto err_mdio_reset;
+
+	ret = ravb_phy_config(dev);
+	if (ret)
+		goto err_mdio_reset;
+
 	return 0;
 
+err_mdio_reset:
+	clk_disable(&eth->clk);
 err_mdio_register:
 	mdio_free(mdiodev);
 err_mdio_alloc:
@@ -525,6 +529,8 @@  static int ravb_remove(struct udevice *dev)
 {
 	struct ravb_priv *eth = dev_get_priv(dev);
 
+	clk_disable(&eth->clk);
+
 	free(eth->phydev);
 	mdio_unregister(eth->bus);
 	mdio_free(eth->bus);