aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDavid S. Miller <davem@davemloft.net>2017-01-03 09:33:00 -0500
committerDavid S. Miller <davem@davemloft.net>2017-01-03 09:33:00 -0500
commita2962b08f414555db46146f207ba9184dc28437f (patch)
treee73506edb228b80ff7f17a678077ebc38d55e235
parent4e5da369df64628358e25ffedcf80ac43af3793d (diff)
parenta8de4d719dfc12bc22192d7daef7c7ae6cfb8b80 (diff)
Merge branch 'dwmac-oxnas-leaks'
Johan Hovold says: ==================== net: stmmac: dwmac-oxnas: fix leaks and simplify pm These patches fixes of-node and fixed-phydev leaks in the recently added dwmac-oxnas driver, and ultimately switches over to using the generic pm implementation as the required callbacks are now in place. Note that this series has only been compile tested. ==================== Signed-off-by: David S. Miller <davem@davemloft.net>
-rw-r--r--drivers/net/ethernet/stmicro/stmmac/dwmac-oxnas.c89
1 files changed, 33 insertions, 56 deletions
diff --git a/drivers/net/ethernet/stmicro/stmmac/dwmac-oxnas.c b/drivers/net/ethernet/stmicro/stmmac/dwmac-oxnas.c
index c35597586121..3dc7d279f805 100644
--- a/drivers/net/ethernet/stmicro/stmmac/dwmac-oxnas.c
+++ b/drivers/net/ethernet/stmicro/stmmac/dwmac-oxnas.c
@@ -60,8 +60,9 @@ struct oxnas_dwmac {
60 struct regmap *regmap; 60 struct regmap *regmap;
61}; 61};
62 62
63static int oxnas_dwmac_init(struct oxnas_dwmac *dwmac) 63static int oxnas_dwmac_init(struct platform_device *pdev, void *priv)
64{ 64{
65 struct oxnas_dwmac *dwmac = priv;
65 unsigned int value; 66 unsigned int value;
66 int ret; 67 int ret;
67 68
@@ -105,20 +106,20 @@ static int oxnas_dwmac_init(struct oxnas_dwmac *dwmac)
105 return 0; 106 return 0;
106} 107}
107 108
109static void oxnas_dwmac_exit(struct platform_device *pdev, void *priv)
110{
111 struct oxnas_dwmac *dwmac = priv;
112
113 clk_disable_unprepare(dwmac->clk);
114}
115
108static int oxnas_dwmac_probe(struct platform_device *pdev) 116static int oxnas_dwmac_probe(struct platform_device *pdev)
109{ 117{
110 struct plat_stmmacenet_data *plat_dat; 118 struct plat_stmmacenet_data *plat_dat;
111 struct stmmac_resources stmmac_res; 119 struct stmmac_resources stmmac_res;
112 struct device_node *sysctrl;
113 struct oxnas_dwmac *dwmac; 120 struct oxnas_dwmac *dwmac;
114 int ret; 121 int ret;
115 122
116 sysctrl = of_parse_phandle(pdev->dev.of_node, "oxsemi,sys-ctrl", 0);
117 if (!sysctrl) {
118 dev_err(&pdev->dev, "failed to get sys-ctrl node\n");
119 return -EINVAL;
120 }
121
122 ret = stmmac_get_platform_resources(pdev, &stmmac_res); 123 ret = stmmac_get_platform_resources(pdev, &stmmac_res);
123 if (ret) 124 if (ret)
124 return ret; 125 return ret;
@@ -128,72 +129,48 @@ static int oxnas_dwmac_probe(struct platform_device *pdev)
128 return PTR_ERR(plat_dat); 129 return PTR_ERR(plat_dat);
129 130
130 dwmac = devm_kzalloc(&pdev->dev, sizeof(*dwmac), GFP_KERNEL); 131 dwmac = devm_kzalloc(&pdev->dev, sizeof(*dwmac), GFP_KERNEL);
131 if (!dwmac) 132 if (!dwmac) {
132 return -ENOMEM; 133 ret = -ENOMEM;
134 goto err_remove_config_dt;
135 }
133 136
134 dwmac->dev = &pdev->dev; 137 dwmac->dev = &pdev->dev;
135 plat_dat->bsp_priv = dwmac; 138 plat_dat->bsp_priv = dwmac;
139 plat_dat->init = oxnas_dwmac_init;
140 plat_dat->exit = oxnas_dwmac_exit;
136 141
137 dwmac->regmap = syscon_node_to_regmap(sysctrl); 142 dwmac->regmap = syscon_regmap_lookup_by_phandle(pdev->dev.of_node,
143 "oxsemi,sys-ctrl");
138 if (IS_ERR(dwmac->regmap)) { 144 if (IS_ERR(dwmac->regmap)) {
139 dev_err(&pdev->dev, "failed to have sysctrl regmap\n"); 145 dev_err(&pdev->dev, "failed to have sysctrl regmap\n");
140 return PTR_ERR(dwmac->regmap); 146 ret = PTR_ERR(dwmac->regmap);
147 goto err_remove_config_dt;
141 } 148 }
142 149
143 dwmac->clk = devm_clk_get(&pdev->dev, "gmac"); 150 dwmac->clk = devm_clk_get(&pdev->dev, "gmac");
144 if (IS_ERR(dwmac->clk)) 151 if (IS_ERR(dwmac->clk)) {
145 return PTR_ERR(dwmac->clk); 152 ret = PTR_ERR(dwmac->clk);
153 goto err_remove_config_dt;
154 }
146 155
147 ret = oxnas_dwmac_init(dwmac); 156 ret = oxnas_dwmac_init(pdev, plat_dat->bsp_priv);
148 if (ret) 157 if (ret)
149 return ret; 158 goto err_remove_config_dt;
150 159
151 ret = stmmac_dvr_probe(&pdev->dev, plat_dat, &stmmac_res); 160 ret = stmmac_dvr_probe(&pdev->dev, plat_dat, &stmmac_res);
152 if (ret) 161 if (ret)
153 clk_disable_unprepare(dwmac->clk); 162 goto err_dwmac_exit;
154 163
155 return ret;
156}
157 164
158static int oxnas_dwmac_remove(struct platform_device *pdev) 165 return 0;
159{
160 struct oxnas_dwmac *dwmac = get_stmmac_bsp_priv(&pdev->dev);
161 int ret = stmmac_dvr_remove(&pdev->dev);
162
163 clk_disable_unprepare(dwmac->clk);
164
165 return ret;
166}
167
168#ifdef CONFIG_PM_SLEEP
169static int oxnas_dwmac_suspend(struct device *dev)
170{
171 struct oxnas_dwmac *dwmac = get_stmmac_bsp_priv(dev);
172 int ret;
173
174 ret = stmmac_suspend(dev);
175 clk_disable_unprepare(dwmac->clk);
176
177 return ret;
178}
179
180static int oxnas_dwmac_resume(struct device *dev)
181{
182 struct oxnas_dwmac *dwmac = get_stmmac_bsp_priv(dev);
183 int ret;
184
185 ret = oxnas_dwmac_init(dwmac);
186 if (ret)
187 return ret;
188 166
189 ret = stmmac_resume(dev); 167err_dwmac_exit:
168 oxnas_dwmac_exit(pdev, plat_dat->bsp_priv);
169err_remove_config_dt:
170 stmmac_remove_config_dt(pdev, plat_dat);
190 171
191 return ret; 172 return ret;
192} 173}
193#endif /* CONFIG_PM_SLEEP */
194
195static SIMPLE_DEV_PM_OPS(oxnas_dwmac_pm_ops,
196 oxnas_dwmac_suspend, oxnas_dwmac_resume);
197 174
198static const struct of_device_id oxnas_dwmac_match[] = { 175static const struct of_device_id oxnas_dwmac_match[] = {
199 { .compatible = "oxsemi,ox820-dwmac" }, 176 { .compatible = "oxsemi,ox820-dwmac" },
@@ -203,10 +180,10 @@ MODULE_DEVICE_TABLE(of, oxnas_dwmac_match);
203 180
204static struct platform_driver oxnas_dwmac_driver = { 181static struct platform_driver oxnas_dwmac_driver = {
205 .probe = oxnas_dwmac_probe, 182 .probe = oxnas_dwmac_probe,
206 .remove = oxnas_dwmac_remove, 183 .remove = stmmac_pltfr_remove,
207 .driver = { 184 .driver = {
208 .name = "oxnas-dwmac", 185 .name = "oxnas-dwmac",
209 .pm = &oxnas_dwmac_pm_ops, 186 .pm = &stmmac_pltfr_pm_ops,
210 .of_match_table = oxnas_dwmac_match, 187 .of_match_table = oxnas_dwmac_match,
211 }, 188 },
212}; 189};