]> git.karo-electronics.de Git - karo-tx-linux.git/commitdiff
ENGR00275469 net:fec: move devm_* and of_* apis to probe function
authorFugang Duan <B38611@freescale.com>
Fri, 16 Aug 2013 01:16:21 +0000 (09:16 +0800)
committerJason Liu <r64343@freescale.com>
Wed, 30 Oct 2013 01:54:42 +0000 (09:54 +0800)
fec_reset_phy() function is called in fec_enet_open(). And
fec_reset_phy() call of_get_named_gpio() and devm_gpio_request_one()
apis, which makes no sense since the two apis do something that
should only be done at .probe() time.

So move two functions into fec_probe() and only leave gpio_set_value()
and msleep() calls in fec_reset_phy(). And remove fec_free_reset_gpio()
function.

Signed-off-by: Fugang Duan <B38611@freescale.com>
Acked-by: Shawn Guo <shawn.guo@linaro.org>
drivers/net/ethernet/freescale/fec.h
drivers/net/ethernet/freescale/fec_main.c

index 888ff237338d9c772c6edf0c871dfc6fd9cffa9b..8072287d0e895ef8dbab505d013ca74a7347b0d3 100644 (file)
@@ -420,6 +420,7 @@ struct fec_enet_private {
        int     csum_flags;
 
        int     phy_reset_gpio;
+       int     reset_duration;
 
        struct ptp_clock *ptp_clock;
        struct ptp_clock_info ptp_caps;
index b0cad4e20cac543b75d2547f79b7faed904d0f1e..8cd644d8135e8173c41eb27800a50762e1d5f40c 100644 (file)
@@ -62,7 +62,6 @@
 
 static void set_multicast_list(struct net_device *ndev);
 static void fec_reset_phy(struct platform_device *pdev);
-static void fec_free_reset_gpio(struct platform_device *pdev);
 
 #if defined(CONFIG_ARM)
 #define FEC_ALIGNMENT  0xf
@@ -1813,7 +1812,6 @@ fec_enet_close(struct net_device *ndev)
        }
 
        fec_enet_free_buffers(ndev);
-       fec_free_reset_gpio(fep->pdev);
 
        return 0;
 }
@@ -2039,22 +2037,27 @@ static int fec_enet_init(struct net_device *ndev)
        return 0;
 }
 
-#ifdef CONFIG_OF
-static void fec_reset_phy(struct platform_device *pdev)
+static void fec_of_init(struct platform_device *pdev)
 {
-       int err;
-       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);
+       int err;
+
+       /*
+        * init phy-reset-gpio to one invalid GPIO for no phy
+        * gpio reset platform
+        */
+       fep->phy_reset_gpio = -1;
 
        if (!np)
                return;
 
-       of_property_read_u32(np, "phy-reset-duration", &msec);
+       of_property_read_u32(np, "phy-reset-duration",
+                                &fep->reset_duration);
        /* A sane reset duration should not be longer than 1s */
-       if (msec > 1000)
-               msec = 1;
+       if ((fep->reset_duration > 1000) || (fep->reset_duration == 0))
+               fep->reset_duration = 1;
 
        fep->phy_reset_gpio = of_get_named_gpio(np, "phy-reset-gpios", 0);
        if (!gpio_is_valid(fep->phy_reset_gpio))
@@ -2064,42 +2067,22 @@ static void fec_reset_phy(struct platform_device *pdev)
                                    GPIOF_OUT_INIT_LOW, "phy-reset");
        if (err) {
                dev_err(&pdev->dev, "failed to get phy-reset-gpios: %d\n", err);
-               return;
+               fep->phy_reset_gpio = -1;
        }
-       msleep(msec);
-       gpio_set_value(fep->phy_reset_gpio, 1);
 }
 
-static void fec_free_reset_gpio(struct platform_device *pdev)
+static void fec_reset_phy(struct platform_device *pdev)
 {
        struct net_device *ndev = platform_get_drvdata(pdev);
        struct fec_enet_private *fep = netdev_priv(ndev);
-       struct device_node *np = pdev->dev.of_node;
-       if (!np)
-               return;
-
-       fep->phy_reset_gpio = of_get_named_gpio(np, "phy-reset-gpios", 0);
-       if (!gpio_is_valid(fep->phy_reset_gpio))
-               return;
 
-       devm_gpio_free(&pdev->dev, fep->phy_reset_gpio);
-}
-#else /* CONFIG_OF */
-static void fec_reset_phy(struct platform_device *pdev)
-{
-       /*
-        * In case of platform probe, the reset has been done
-        * by machine code.
-        */
-}
-
-static void fec_free_reset_gpio(struct platform_device *pdev)
-{
-       /*
-        * make pair as api "fec_reset_phy()"
-        */
+       /* check GPIO valid to avoid kernel print warning when no gpio reset */
+       if (gpio_is_valid(fep->phy_reset_gpio)) {
+               gpio_set_value(fep->phy_reset_gpio, 0);
+               msleep(fep->reset_duration);
+               gpio_set_value(fep->phy_reset_gpio, 1);
+       }
 }
-#endif /* CONFIG_OF */
 
 static int
 fec_probe(struct platform_device *pdev)
@@ -2150,6 +2133,7 @@ fec_probe(struct platform_device *pdev)
 
        platform_set_drvdata(pdev, ndev);
 
+       fec_of_init(pdev);
        ret = of_get_phy_mode(pdev->dev.of_node);
        if (ret < 0) {
                pdata = pdev->dev.platform_data;