aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/net/phy/mdio-gpio.c
diff options
context:
space:
mode:
authorSrinivas Kandagatla <srinivas.kandagatla@st.com>2012-08-23 21:59:17 -0400
committerDavid S. Miller <davem@davemloft.net>2012-08-30 12:37:52 -0400
commite92bdf4bf199f582dae8249a21e991db4bf66480 (patch)
tree6619f8122ee1204d67ae3148d673647cc7010483 /drivers/net/phy/mdio-gpio.c
parentf9dc9ac51610a35629c8211b6b8c9b0c65cf0e1d (diff)
of/mdio-gpio: Simplify the way device tree support is implemented.
This patch cleans up the way device tree support is added in mdio-gpio driver. I found lot of code duplication which is not necessary. Also strangely a new platform driver was also introduced for device tree support. All this forced me to do this cleanup patch. After this patch, the driver probe checks the of_node pointer to get the data from device tree. Signed-off-by: Srinivas Kandagatla <srinivas.kandagatla@st.com> Signed-off-by: David S. Miller <davem@davemloft.net>
Diffstat (limited to 'drivers/net/phy/mdio-gpio.c')
-rw-r--r--drivers/net/phy/mdio-gpio.c132
1 files changed, 40 insertions, 92 deletions
diff --git a/drivers/net/phy/mdio-gpio.c b/drivers/net/phy/mdio-gpio.c
index 7189adf54bd1..899274f2f9b1 100644
--- a/drivers/net/phy/mdio-gpio.c
+++ b/drivers/net/phy/mdio-gpio.c
@@ -28,17 +28,38 @@
28#include <linux/gpio.h> 28#include <linux/gpio.h>
29#include <linux/mdio-gpio.h> 29#include <linux/mdio-gpio.h>
30 30
31#ifdef CONFIG_OF_GPIO
32#include <linux/of_gpio.h> 31#include <linux/of_gpio.h>
33#include <linux/of_mdio.h> 32#include <linux/of_mdio.h>
34#include <linux/of_platform.h>
35#endif
36 33
37struct mdio_gpio_info { 34struct mdio_gpio_info {
38 struct mdiobb_ctrl ctrl; 35 struct mdiobb_ctrl ctrl;
39 int mdc, mdio; 36 int mdc, mdio;
40}; 37};
41 38
39static void *mdio_gpio_of_get_data(struct platform_device *pdev)
40{
41 struct device_node *np = pdev->dev.of_node;
42 struct mdio_gpio_platform_data *pdata;
43 int ret;
44
45 pdata = devm_kzalloc(&pdev->dev, sizeof(*pdata), GFP_KERNEL);
46 if (!pdata)
47 return NULL;
48
49 ret = of_get_gpio(np, 0);
50 if (ret < 0)
51 return NULL;
52
53 pdata->mdc = ret;
54
55 ret = of_get_gpio(np, 1);
56 if (ret < 0)
57 return NULL;
58 pdata->mdio = ret;
59
60 return pdata;
61}
62
42static void mdio_dir(struct mdiobb_ctrl *ctrl, int dir) 63static void mdio_dir(struct mdiobb_ctrl *ctrl, int dir)
43{ 64{
44 struct mdio_gpio_info *bitbang = 65 struct mdio_gpio_info *bitbang =
@@ -162,10 +183,15 @@ static void __devexit mdio_gpio_bus_destroy(struct device *dev)
162 183
163static int __devinit mdio_gpio_probe(struct platform_device *pdev) 184static int __devinit mdio_gpio_probe(struct platform_device *pdev)
164{ 185{
165 struct mdio_gpio_platform_data *pdata = pdev->dev.platform_data; 186 struct mdio_gpio_platform_data *pdata;
166 struct mii_bus *new_bus; 187 struct mii_bus *new_bus;
167 int ret; 188 int ret;
168 189
190 if (pdev->dev.of_node)
191 pdata = mdio_gpio_of_get_data(pdev);
192 else
193 pdata = pdev->dev.platform_data;
194
169 if (!pdata) 195 if (!pdata)
170 return -ENODEV; 196 return -ENODEV;
171 197
@@ -173,7 +199,11 @@ static int __devinit mdio_gpio_probe(struct platform_device *pdev)
173 if (!new_bus) 199 if (!new_bus)
174 return -ENODEV; 200 return -ENODEV;
175 201
176 ret = mdiobus_register(new_bus); 202 if (pdev->dev.of_node)
203 ret = of_mdiobus_register(new_bus, pdev->dev.of_node);
204 else
205 ret = mdiobus_register(new_bus);
206
177 if (ret) 207 if (ret)
178 mdio_gpio_bus_deinit(&pdev->dev); 208 mdio_gpio_bus_deinit(&pdev->dev);
179 209
@@ -187,112 +217,30 @@ static int __devexit mdio_gpio_remove(struct platform_device *pdev)
187 return 0; 217 return 0;
188} 218}
189 219
190#ifdef CONFIG_OF_GPIO 220static struct of_device_id mdio_gpio_of_match[] = {
191 221 { .compatible = "virtual,mdio-gpio", },
192static int __devinit mdio_ofgpio_probe(struct platform_device *ofdev) 222 { /* sentinel */ }
193{
194 struct mdio_gpio_platform_data *pdata;
195 struct mii_bus *new_bus;
196 int ret;
197
198 pdata = kzalloc(sizeof(*pdata), GFP_KERNEL);
199 if (!pdata)
200 return -ENOMEM;
201
202 ret = of_get_gpio(ofdev->dev.of_node, 0);
203 if (ret < 0)
204 goto out_free;
205 pdata->mdc = ret;
206
207 ret = of_get_gpio(ofdev->dev.of_node, 1);
208 if (ret < 0)
209 goto out_free;
210 pdata->mdio = ret;
211
212 new_bus = mdio_gpio_bus_init(&ofdev->dev, pdata, pdata->mdc);
213 if (!new_bus)
214 goto out_free;
215
216 ret = of_mdiobus_register(new_bus, ofdev->dev.of_node);
217 if (ret)
218 mdio_gpio_bus_deinit(&ofdev->dev);
219
220 return ret;
221
222out_free:
223 kfree(pdata);
224 return -ENODEV;
225}
226
227static int __devexit mdio_ofgpio_remove(struct platform_device *ofdev)
228{
229 mdio_gpio_bus_destroy(&ofdev->dev);
230 kfree(ofdev->dev.platform_data);
231
232 return 0;
233}
234
235static struct of_device_id mdio_ofgpio_match[] = {
236 {
237 .compatible = "virtual,mdio-gpio",
238 },
239 {},
240};
241MODULE_DEVICE_TABLE(of, mdio_ofgpio_match);
242
243static struct platform_driver mdio_ofgpio_driver = {
244 .driver = {
245 .name = "mdio-ofgpio",
246 .owner = THIS_MODULE,
247 .of_match_table = mdio_ofgpio_match,
248 },
249 .probe = mdio_ofgpio_probe,
250 .remove = __devexit_p(mdio_ofgpio_remove),
251}; 223};
252 224
253static inline int __init mdio_ofgpio_init(void)
254{
255 return platform_driver_register(&mdio_ofgpio_driver);
256}
257
258static inline void mdio_ofgpio_exit(void)
259{
260 platform_driver_unregister(&mdio_ofgpio_driver);
261}
262#else
263static inline int __init mdio_ofgpio_init(void) { return 0; }
264static inline void mdio_ofgpio_exit(void) { }
265#endif /* CONFIG_OF_GPIO */
266
267static struct platform_driver mdio_gpio_driver = { 225static struct platform_driver mdio_gpio_driver = {
268 .probe = mdio_gpio_probe, 226 .probe = mdio_gpio_probe,
269 .remove = __devexit_p(mdio_gpio_remove), 227 .remove = __devexit_p(mdio_gpio_remove),
270 .driver = { 228 .driver = {
271 .name = "mdio-gpio", 229 .name = "mdio-gpio",
272 .owner = THIS_MODULE, 230 .owner = THIS_MODULE,
231 .of_match_table = mdio_gpio_of_match,
273 }, 232 },
274}; 233};
275 234
276static int __init mdio_gpio_init(void) 235static int __init mdio_gpio_init(void)
277{ 236{
278 int ret; 237 return platform_driver_register(&mdio_gpio_driver);
279
280 ret = mdio_ofgpio_init();
281 if (ret)
282 return ret;
283
284 ret = platform_driver_register(&mdio_gpio_driver);
285 if (ret)
286 mdio_ofgpio_exit();
287
288 return ret;
289} 238}
290module_init(mdio_gpio_init); 239module_init(mdio_gpio_init);
291 240
292static void __exit mdio_gpio_exit(void) 241static void __exit mdio_gpio_exit(void)
293{ 242{
294 platform_driver_unregister(&mdio_gpio_driver); 243 platform_driver_unregister(&mdio_gpio_driver);
295 mdio_ofgpio_exit();
296} 244}
297module_exit(mdio_gpio_exit); 245module_exit(mdio_gpio_exit);
298 246