net: stmmac: Enable stmmac main clock when probing hardware
authorChen-Yu Tsai <wens@csie.org>
Fri, 17 Jan 2014 13:24:40 +0000 (21:24 +0800)
committerDavid S. Miller <davem@davemloft.net>
Mon, 20 Jan 2014 04:02:02 +0000 (20:02 -0800)
The stmmac driver does not enable the main clock during the probe phase.
If the clock was not enabled by the boot loader or was disabled by the
kernel, hardware features and the MDIO bus would not be probed properly.

Signed-off-by: Chen-Yu Tsai <wens@csie.org>
Signed-off-by: David S. Miller <davem@davemloft.net>
drivers/net/ethernet/stmicro/stmmac/stmmac_main.c

index cddcf76f11f9f514f4c4289cec6fa98b315c078c..0d2c4cb0996b3155a59586fe4fa855cdfc70fa3a 100644 (file)
@@ -1680,8 +1680,6 @@ static int stmmac_open(struct net_device *dev)
        struct stmmac_priv *priv = netdev_priv(dev);
        int ret;
 
-       clk_prepare_enable(priv->stmmac_clk);
-
        stmmac_check_ether_addr(priv);
 
        if (priv->pcs != STMMAC_PCS_RGMII && priv->pcs != STMMAC_PCS_TBI &&
@@ -1819,7 +1817,6 @@ static int stmmac_release(struct net_device *dev)
 #ifdef CONFIG_STMMAC_DEBUG_FS
        stmmac_exit_fs();
 #endif
-       clk_disable_unprepare(priv->stmmac_clk);
 
        stmmac_release_ptp(priv);
 
@@ -2727,10 +2724,18 @@ struct stmmac_priv *stmmac_dvr_probe(struct device *device,
        if ((phyaddr >= 0) && (phyaddr <= 31))
                priv->plat->phy_addr = phyaddr;
 
+       priv->stmmac_clk = devm_clk_get(priv->device, STMMAC_RESOURCE_NAME);
+       if (IS_ERR(priv->stmmac_clk)) {
+               dev_warn(priv->device, "%s: warning: cannot get CSR clock\n",
+                        __func__);
+               goto error_clk_get;
+       }
+       clk_prepare_enable(priv->stmmac_clk);
+
        /* Init MAC and get the capabilities */
        ret = stmmac_hw_init(priv);
        if (ret)
-               goto error_free_netdev;
+               goto error_hw_init;
 
        ndev->netdev_ops = &stmmac_netdev_ops;
 
@@ -2768,12 +2773,6 @@ struct stmmac_priv *stmmac_dvr_probe(struct device *device,
                goto error_netdev_register;
        }
 
-       priv->stmmac_clk = clk_get(priv->device, STMMAC_RESOURCE_NAME);
-       if (IS_ERR(priv->stmmac_clk)) {
-               pr_warn("%s: warning: cannot get CSR clock\n", __func__);
-               goto error_clk_get;
-       }
-
        /* If a specific clk_csr value is passed from the platform
         * this means that the CSR Clock Range selection cannot be
         * changed at run-time and it is fixed. Viceversa the driver'll try to
@@ -2801,12 +2800,12 @@ struct stmmac_priv *stmmac_dvr_probe(struct device *device,
        return priv;
 
 error_mdio_register:
-       clk_put(priv->stmmac_clk);
-error_clk_get:
        unregister_netdev(ndev);
 error_netdev_register:
        netif_napi_del(&priv->napi);
-error_free_netdev:
+error_hw_init:
+       clk_disable_unprepare(priv->stmmac_clk);
+error_clk_get:
        free_netdev(ndev);
 
        return NULL;
@@ -2833,6 +2832,7 @@ int stmmac_dvr_remove(struct net_device *ndev)
                stmmac_mdio_unregister(ndev);
        netif_carrier_off(ndev);
        unregister_netdev(ndev);
+       clk_disable_unprepare(priv->stmmac_clk);
        free_netdev(ndev);
 
        return 0;