MLK-14470 net: fec: let shared mii bus always be active
authorFugang Duan <fugang.duan@nxp.com>
Wed, 3 May 2017 09:41:52 +0000 (17:41 +0800)
committerNitin Garg <nitin.garg@nxp.com>
Mon, 19 Mar 2018 20:22:07 +0000 (15:22 -0500)
Many boards installed with i.MX chip only use two pins for mii bus
in two NET MAC system to save two pins. Then one MAC need to share
the mii bus with the other one. Since two net interface operation
are parallel and separate, we should keep the shared mii bus always
be active. So it should keep MAC clocks on.

Signed-off-by: Fugang Duan <fugang.duan@nxp.com>
(cherry picked from commit: d0f18f7633ed)

drivers/net/ethernet/freescale/fec.h
drivers/net/ethernet/freescale/fec_main.c

index 158d80f..7ffcabc 100644 (file)
@@ -545,6 +545,7 @@ struct fec_enet_private {
        int     mii_timeout;
        int     mii_bus_share;
        bool    miibus_up_failed;
+       bool    mii_bus_active;
        uint    phy_speed;
        phy_interface_t phy_interface;
        struct device_node *phy_node;
index c1698cc..a5c53c3 100644 (file)
@@ -2914,9 +2914,12 @@ fec_enet_open(struct net_device *ndev)
                return ret;
 
        pinctrl_pm_select_default_state(&fep->pdev->dev);
-       ret = fec_enet_clk_enable(ndev, true);
-       if (ret)
-               goto clk_enable;
+       if (!(fep->mii_bus_share && fep->mii_bus_active)) {
+               fep->mii_bus_active = true;;
+               ret = fec_enet_clk_enable(ndev, true);
+               if (ret)
+                       goto clk_enable;
+       }
 
        /* I should reset the ring buffers here, but I don't yet know
         * a simple way to do that.
@@ -2964,10 +2967,11 @@ err_enet_alloc:
        if (!fep->mii_bus_share)
                fec_enet_clk_enable(ndev, false);
 clk_enable:
-       pm_runtime_mark_last_busy(&fep->pdev->dev);
-       pm_runtime_put_autosuspend(&fep->pdev->dev);
-       if (!fep->mii_bus_share)
+       if (!fep->mii_bus_share) {
+               pm_runtime_mark_last_busy(&fep->pdev->dev);
+               pm_runtime_put_autosuspend(&fep->pdev->dev);
                pinctrl_pm_select_sleep_state(&fep->pdev->dev);
+       }
        return ret;
 }
 
@@ -2992,7 +2996,10 @@ fec_enet_close(struct net_device *ndev)
 
        fec_enet_update_ethtool_stats(ndev);
 
-       fec_enet_clk_enable(ndev, false);
+       if (!fep->mii_bus_share) {
+               fec_enet_clk_enable(ndev, false);
+               fep->mii_bus_active = false;
+       }
        pm_qos_remove_request(&fep->pm_qos_req);
        pinctrl_pm_select_sleep_state(&fep->pdev->dev);
        pm_runtime_mark_last_busy(&fep->pdev->dev);