sunxi: driver refresh for 3.13
[openwrt.git] / target / linux / sunxi / patches-3.13 / 151-7-stmmac-fixup-7.patch
1 From 33a23e223749c45ff8099ff9baa235301a3ad07f Mon Sep 17 00:00:00 2001
2 From: Srinivas Kandagatla <srinivas.kandagatla@st.com>
3 Date: Thu, 16 Jan 2014 10:52:44 +0000
4 Subject: [PATCH] net: stmmac: use suspend functions for hibernation
5
6 In hibernation freeze case the driver just releases the resources like
7 dma buffers, irqs, unregisters the drivers and during restore it does
8 register, request the resources. This is not really necessary, as part
9 of power management all the data structures are intact, all the
10 previously allocated resources can be used after coming out of low
11 power.
12
13 This patch uses the suspend and resume callbacks for freeze and
14 restore which initializes the hardware correctly without unregistering
15 or releasing the resources, this should also help in reducing the time
16 to restore.
17
18 Also this patch fixes a bug in stmmac_pltfr_restore and
19 stmmac_pltfr_freeze where it tries to get hold of platform data via
20 dev_get_platdata call, which would return NULL in device tree cases and
21 the next if statement would crash as there is no NULL check.
22
23 Signed-off-by: Srinivas Kandagatla <srinivas.kandagatla@st.com>
24 Acked-by: Giuseppe Cavallaro <peppe.cavallaro@st.com>
25 Signed-off-by: David S. Miller <davem@davemloft.net>
26 ---
27  drivers/net/ethernet/stmicro/stmmac/stmmac.h       |  2 -
28  drivers/net/ethernet/stmicro/stmmac/stmmac_main.c  | 16 --------
29  .../net/ethernet/stmicro/stmmac/stmmac_platform.c  | 44 ++++++----------------
30  3 files changed, 12 insertions(+), 50 deletions(-)
31
32 diff --git a/drivers/net/ethernet/stmicro/stmmac/stmmac.h b/drivers/net/ethernet/stmicro/stmmac/stmmac.h
33 index 5a568015..027f1dd 100644
34 --- a/drivers/net/ethernet/stmicro/stmmac/stmmac.h
35 +++ b/drivers/net/ethernet/stmicro/stmmac/stmmac.h
36 @@ -117,8 +117,6 @@ struct stmmac_priv {
37  extern const struct stmmac_hwtimestamp stmmac_ptp;
38  int stmmac_ptp_register(struct stmmac_priv *priv);
39  void stmmac_ptp_unregister(struct stmmac_priv *priv);
40 -int stmmac_freeze(struct net_device *ndev);
41 -int stmmac_restore(struct net_device *ndev);
42  int stmmac_resume(struct net_device *ndev);
43  int stmmac_suspend(struct net_device *ndev);
44  int stmmac_dvr_remove(struct net_device *ndev);
45 diff --git a/drivers/net/ethernet/stmicro/stmmac/stmmac_main.c b/drivers/net/ethernet/stmicro/stmmac/stmmac_main.c
46 index 742a83f..c1298a0 100644
47 --- a/drivers/net/ethernet/stmicro/stmmac/stmmac_main.c
48 +++ b/drivers/net/ethernet/stmicro/stmmac/stmmac_main.c
49 @@ -2912,22 +2912,6 @@ int stmmac_resume(struct net_device *ndev)
50  
51         return 0;
52  }
53 -
54 -int stmmac_freeze(struct net_device *ndev)
55 -{
56 -       if (!ndev || !netif_running(ndev))
57 -               return 0;
58 -
59 -       return stmmac_release(ndev);
60 -}
61 -
62 -int stmmac_restore(struct net_device *ndev)
63 -{
64 -       if (!ndev || !netif_running(ndev))
65 -               return 0;
66 -
67 -       return stmmac_open(ndev);
68 -}
69  #endif /* CONFIG_PM */
70  
71  /* Driver can be configured w/ and w/ both PCI and Platf drivers
72 diff --git a/drivers/net/ethernet/stmicro/stmmac/stmmac_platform.c b/drivers/net/ethernet/stmicro/stmmac/stmmac_platform.c
73 index 9377ee6..6d0bf22 100644
74 --- a/drivers/net/ethernet/stmicro/stmmac/stmmac_platform.c
75 +++ b/drivers/net/ethernet/stmicro/stmmac/stmmac_platform.c
76 @@ -211,55 +211,35 @@ static int stmmac_pltfr_remove(struct platform_device *pdev)
77  #ifdef CONFIG_PM
78  static int stmmac_pltfr_suspend(struct device *dev)
79  {
80 -       struct net_device *ndev = dev_get_drvdata(dev);
81 -
82 -       return stmmac_suspend(ndev);
83 -}
84 -
85 -static int stmmac_pltfr_resume(struct device *dev)
86 -{
87 -       struct net_device *ndev = dev_get_drvdata(dev);
88 -
89 -       return stmmac_resume(ndev);
90 -}
91 -
92 -static int stmmac_pltfr_freeze(struct device *dev)
93 -{
94         int ret;
95 -       struct plat_stmmacenet_data *plat_dat = dev_get_platdata(dev);
96         struct net_device *ndev = dev_get_drvdata(dev);
97 +       struct stmmac_priv *priv = netdev_priv(ndev);
98         struct platform_device *pdev = to_platform_device(dev);
99  
100 -       ret = stmmac_freeze(ndev);
101 -       if (plat_dat->exit)
102 -               plat_dat->exit(pdev);
103 +       ret = stmmac_suspend(ndev);
104 +       if (priv->plat->exit)
105 +               priv->plat->exit(pdev);
106  
107         return ret;
108  }
109  
110 -static int stmmac_pltfr_restore(struct device *dev)
111 +static int stmmac_pltfr_resume(struct device *dev)
112  {
113 -       struct plat_stmmacenet_data *plat_dat = dev_get_platdata(dev);
114         struct net_device *ndev = dev_get_drvdata(dev);
115 +       struct stmmac_priv *priv = netdev_priv(ndev);
116         struct platform_device *pdev = to_platform_device(dev);
117  
118 -       if (plat_dat->init)
119 -               plat_dat->init(pdev);
120 +       if (priv->plat->init)
121 +               priv->plat->init(pdev);
122  
123 -       return stmmac_restore(ndev);
124 +       return stmmac_resume(ndev);
125  }
126  
127 -static const struct dev_pm_ops stmmac_pltfr_pm_ops = {
128 -       .suspend = stmmac_pltfr_suspend,
129 -       .resume = stmmac_pltfr_resume,
130 -       .freeze = stmmac_pltfr_freeze,
131 -       .thaw = stmmac_pltfr_restore,
132 -       .restore = stmmac_pltfr_restore,
133 -};
134 -#else
135 -static const struct dev_pm_ops stmmac_pltfr_pm_ops;
136  #endif /* CONFIG_PM */
137  
138 +static SIMPLE_DEV_PM_OPS(stmmac_pltfr_pm_ops,
139 +                       stmmac_pltfr_suspend, stmmac_pltfr_resume);
140 +
141  static const struct of_device_id stmmac_dt_ids[] = {
142         { .compatible = "st,spear600-gmac"},
143         { .compatible = "snps,dwmac-3.610"},
144 -- 
145 1.8.5.5
146