MLK-14438-04 net: fec: add phy-reset-gpios PROBE_DEFER check
authorAndy Duan <fugang.duan@nxp.com>
Tue, 14 Mar 2017 06:09:29 +0000 (14:09 +0800)
committerNitin Garg <nitin.garg@nxp.com>
Mon, 19 Mar 2018 20:21:32 +0000 (15:21 -0500)
Add dts property "phy-reset-gpios" PROBE_DEFER check, and use
gpio_set_value_cansleep() due to the FEC PHY reset gpio may be on
an I2C expander.

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

drivers/net/ethernet/freescale/fec_main.c

index c15b5fd..5d6c1ad 100644 (file)
@@ -3332,7 +3332,7 @@ static int fec_enet_init(struct net_device *ndev)
 }
 
 #ifdef CONFIG_OF
-static void fec_reset_phy(struct platform_device *pdev)
+static int fec_reset_phy(struct platform_device *pdev)
 {
        int err, phy_reset;
        bool active_high = false;
@@ -3340,7 +3340,7 @@ static void fec_reset_phy(struct platform_device *pdev)
        struct device_node *np = pdev->dev.of_node;
 
        if (!np)
-               return;
+               return 0;
 
        err = of_property_read_u32(np, "phy-reset-duration", &msec);
        /* A sane reset duration should not be longer than 1s */
@@ -3348,8 +3348,10 @@ static void fec_reset_phy(struct platform_device *pdev)
                msec = 1;
 
        phy_reset = of_get_named_gpio(np, "phy-reset-gpios", 0);
-       if (!gpio_is_valid(phy_reset))
-               return;
+       if (phy_reset == -EPROBE_DEFER)
+               return phy_reset;
+       else if (!gpio_is_valid(phy_reset))
+               return 0;
 
        active_high = of_property_read_bool(np, "phy-reset-active-high");
 
@@ -3358,7 +3360,7 @@ static void fec_reset_phy(struct platform_device *pdev)
                        "phy-reset");
        if (err) {
                dev_err(&pdev->dev, "failed to get phy-reset-gpios: %d\n", err);
-               return;
+               return err;
        }
 
        if (msec > 20)
@@ -3367,14 +3369,17 @@ static void fec_reset_phy(struct platform_device *pdev)
                usleep_range(msec * 1000, msec * 1000 + 1000);
 
        gpio_set_value_cansleep(phy_reset, !active_high);
+
+       return 0;
 }
 #else /* CONFIG_OF */
-static void fec_reset_phy(struct platform_device *pdev)
+static int fec_reset_phy(struct platform_device *pdev)
 {
        /*
         * In case of platform probe, the reset has been done
         * by machine code.
         */
+       return 0;
 }
 #endif /* CONFIG_OF */
 
@@ -3600,7 +3605,9 @@ fec_probe(struct platform_device *pdev)
        pm_runtime_set_active(&pdev->dev);
        pm_runtime_enable(&pdev->dev);
 
-       fec_reset_phy(pdev);
+       ret = fec_reset_phy(pdev);
+       if (ret)
+               goto failed_reset;
 
        if (fep->bufdesc_ex)
                fec_ptp_init(pdev);
@@ -3669,6 +3676,9 @@ failed_init:
        fec_ptp_stop(pdev);
        if (fep->reg_phy)
                regulator_disable(fep->reg_phy);
+failed_reset:
+       pm_runtime_put(&pdev->dev);
+       pm_runtime_disable(&pdev->dev);
 failed_regulator:
        clk_disable_unprepare(fep->clk_ipg);
 failed_clk_ipg: