sunxi: driver refresh for 3.13
[openwrt.git] / target / linux / sunxi / patches-3.13 / 153-1-stmmac-enable-main-clock-when-probing.patch
1 From 62866e98737e77c87f9dec99edea76ab54360770 Mon Sep 17 00:00:00 2001
2 From: Chen-Yu Tsai <wens@csie.org>
3 Date: Fri, 17 Jan 2014 21:24:40 +0800
4 Subject: [PATCH] net: stmmac: Enable stmmac main clock when probing hardware
5
6 The stmmac driver does not enable the main clock during the probe phase.
7 If the clock was not enabled by the boot loader or was disabled by the
8 kernel, hardware features and the MDIO bus would not be probed properly.
9
10 Signed-off-by: Chen-Yu Tsai <wens@csie.org>
11 Signed-off-by: David S. Miller <davem@davemloft.net>
12 ---
13  drivers/net/ethernet/stmicro/stmmac/stmmac_main.c | 26 +++++++++++------------
14  1 file changed, 13 insertions(+), 13 deletions(-)
15
16 diff --git a/drivers/net/ethernet/stmicro/stmmac/stmmac_main.c b/drivers/net/ethernet/stmicro/stmmac/stmmac_main.c
17 index cddcf76..0d2c4cb 100644
18 --- a/drivers/net/ethernet/stmicro/stmmac/stmmac_main.c
19 +++ b/drivers/net/ethernet/stmicro/stmmac/stmmac_main.c
20 @@ -1680,8 +1680,6 @@ static int stmmac_open(struct net_device *dev)
21         struct stmmac_priv *priv = netdev_priv(dev);
22         int ret;
23  
24 -       clk_prepare_enable(priv->stmmac_clk);
25 -
26         stmmac_check_ether_addr(priv);
27  
28         if (priv->pcs != STMMAC_PCS_RGMII && priv->pcs != STMMAC_PCS_TBI &&
29 @@ -1819,7 +1817,6 @@ static int stmmac_release(struct net_device *dev)
30  #ifdef CONFIG_STMMAC_DEBUG_FS
31         stmmac_exit_fs();
32  #endif
33 -       clk_disable_unprepare(priv->stmmac_clk);
34  
35         stmmac_release_ptp(priv);
36  
37 @@ -2727,10 +2724,18 @@ struct stmmac_priv *stmmac_dvr_probe(struct device *device,
38         if ((phyaddr >= 0) && (phyaddr <= 31))
39                 priv->plat->phy_addr = phyaddr;
40  
41 +       priv->stmmac_clk = devm_clk_get(priv->device, STMMAC_RESOURCE_NAME);
42 +       if (IS_ERR(priv->stmmac_clk)) {
43 +               dev_warn(priv->device, "%s: warning: cannot get CSR clock\n",
44 +                        __func__);
45 +               goto error_clk_get;
46 +       }
47 +       clk_prepare_enable(priv->stmmac_clk);
48 +
49         /* Init MAC and get the capabilities */
50         ret = stmmac_hw_init(priv);
51         if (ret)
52 -               goto error_free_netdev;
53 +               goto error_hw_init;
54  
55         ndev->netdev_ops = &stmmac_netdev_ops;
56  
57 @@ -2768,12 +2773,6 @@ struct stmmac_priv *stmmac_dvr_probe(struct device *device,
58                 goto error_netdev_register;
59         }
60  
61 -       priv->stmmac_clk = clk_get(priv->device, STMMAC_RESOURCE_NAME);
62 -       if (IS_ERR(priv->stmmac_clk)) {
63 -               pr_warn("%s: warning: cannot get CSR clock\n", __func__);
64 -               goto error_clk_get;
65 -       }
66 -
67         /* If a specific clk_csr value is passed from the platform
68          * this means that the CSR Clock Range selection cannot be
69          * changed at run-time and it is fixed. Viceversa the driver'll try to
70 @@ -2801,12 +2800,12 @@ struct stmmac_priv *stmmac_dvr_probe(struct device *device,
71         return priv;
72  
73  error_mdio_register:
74 -       clk_put(priv->stmmac_clk);
75 -error_clk_get:
76         unregister_netdev(ndev);
77  error_netdev_register:
78         netif_napi_del(&priv->napi);
79 -error_free_netdev:
80 +error_hw_init:
81 +       clk_disable_unprepare(priv->stmmac_clk);
82 +error_clk_get:
83         free_netdev(ndev);
84  
85         return NULL;
86 @@ -2833,6 +2832,7 @@ int stmmac_dvr_remove(struct net_device *ndev)
87                 stmmac_mdio_unregister(ndev);
88         netif_carrier_off(ndev);
89         unregister_netdev(ndev);
90 +       clk_disable_unprepare(priv->stmmac_clk);
91         free_netdev(ndev);
92  
93         return 0;
94 -- 
95 1.8.5.5
96