]> git.karo-electronics.de Git - karo-tx-linux.git/commitdiff
net: fec: Reset ethernet PHY whenever the enet_out clock is being enabled
authorLothar Waßmann <LW@KARO-electronics.de>
Wed, 20 Jan 2016 09:13:45 +0000 (10:13 +0100)
committerLothar Waßmann <LW@KARO-electronics.de>
Tue, 8 Mar 2016 09:24:34 +0000 (10:24 +0100)
If a PHY uses ENET_OUT as reference clock, it may need a RESET to get
functional after the clock had been disabled.

Failure to do this results in the link state constantly toggling
between up and down:
fec 02188000.ethernet eth0: Link is Up - 100Mbps/Full - flow control rx/tx
fec 02188000.ethernet eth0: Link is Down
fec 02188000.ethernet eth0: Link is Up - 100Mbps/Full - flow control rx/tx
fec 02188000.ethernet eth0: Link is Down
[...]

Signed-off-by: Lothar Waßmann <LW@KARO-electronics.de>
drivers/net/ethernet/freescale/fec.h
drivers/net/ethernet/freescale/fec_main.c

index 99d33e2d35e6c2c219fbd06f34546619a01a586d..c952d654e25265a4628a49fddf90e138f0e7200a 100644 (file)
@@ -519,6 +519,8 @@ struct fec_enet_private {
        int     pause_flag;
        int     wol_flag;
        u32     quirks;
+       int     phy_reset_gpio;
+       int     phy_reset_duration;
 
        struct  napi_struct napi;
        int     csum_flags;
index 408e64052fbde019faa81692aa8b7d6401d1e7d3..976940e303f6062a28e70816cac76e4d40549351 100644 (file)
@@ -66,6 +66,7 @@
 
 static void set_multicast_list(struct net_device *ndev);
 static void fec_enet_itr_coal_init(struct net_device *ndev);
+static void fec_reset_phy(struct platform_device *pdev);
 
 #define DRIVER_NAME    "fec"
 
@@ -1861,6 +1862,8 @@ static int fec_enet_clk_enable(struct net_device *ndev, bool enable)
                        ret = clk_prepare_enable(fep->clk_enet_out);
                        if (ret)
                                goto failed_clk_enet_out;
+
+                       fec_reset_phy(fep->pdev);
                }
                if (fep->clk_ptp) {
                        mutex_lock(&fep->ptp_clk_mutex);
@@ -3233,30 +3236,43 @@ static int fec_enet_init(struct net_device *ndev)
 #ifdef CONFIG_OF
 static void fec_reset_phy(struct platform_device *pdev)
 {
-       int err, phy_reset;
-       int msec = 1;
-       struct device_node *np = pdev->dev.of_node;
+       struct net_device *ndev = platform_get_drvdata(pdev);
+       struct fec_enet_private *fep = netdev_priv(ndev);
 
-       if (!np)
+       if (!gpio_is_valid(fep->phy_reset_gpio))
                return;
 
-       of_property_read_u32(np, "phy-reset-duration", &msec);
-       /* A sane reset duration should not be longer than 1s */
-       if (msec > 1000)
-               msec = 1;
+       gpio_set_value_cansleep(fep->phy_reset_gpio, 0);
+       msleep(fep->phy_reset_duration);
+       gpio_set_value_cansleep(fep->phy_reset_gpio, 1);
+}
+
+static int fec_get_reset_gpio(struct platform_device *pdev)
+{
+       int err, phy_reset;
+       int msec = 1;
+       struct device_node *np = pdev->dev.of_node;
+       struct net_device *ndev = platform_get_drvdata(pdev);
+       struct fec_enet_private *fep = netdev_priv(ndev);
 
        phy_reset = of_get_named_gpio(np, "phy-reset-gpios", 0);
        if (!gpio_is_valid(phy_reset))
-               return;
+               return phy_reset;
 
        err = devm_gpio_request_one(&pdev->dev, phy_reset,
                                    GPIOF_OUT_INIT_LOW, "phy-reset");
        if (err) {
                dev_err(&pdev->dev, "failed to get phy-reset-gpios: %d\n", err);
-               return;
+               return err;
        }
-       msleep(msec);
-       gpio_set_value_cansleep(phy_reset, 1);
+
+       of_property_read_u32(np, "phy-reset-duration", &msec);
+       /* A sane reset duration should not be longer than 1s */
+       if (msec > 1000)
+               msec = 1;
+       fep->phy_reset_duration = msec;
+
+       return phy_reset;
 }
 #else /* CONFIG_OF */
 static void fec_reset_phy(struct platform_device *pdev)
@@ -3266,6 +3282,11 @@ static void fec_reset_phy(struct platform_device *pdev)
         * by machine code.
         */
 }
+
+static inline int fec_get_reset_gpio(struct platform_device *pdev)
+{
+       return -EINVAL;
+}
 #endif /* CONFIG_OF */
 
 static void
@@ -3361,6 +3382,11 @@ fec_probe(struct platform_device *pdev)
 
        platform_set_drvdata(pdev, ndev);
 
+       ret = fec_get_reset_gpio(pdev);
+       if (ret == -EPROBE_DEFER)
+               goto gpio_defer;
+       fep->phy_reset_gpio = ret;
+
        if (of_get_property(np, "fsl,magic-packet", NULL))
                fep->wol_flag |= FEC_WOL_HAS_MAGIC_PACKET;
 
@@ -3515,6 +3541,7 @@ failed_clk_ipg:
 failed_clk:
 failed_phy:
        of_node_put(phy_node);
+gpio_defer:
 failed_ioremap:
        free_netdev(ndev);