diff options
author | Mugunthan V N <mugunthanvnm@ti.com> | 2012-08-06 01:05:57 -0400 |
---|---|---|
committer | David S. Miller <davem@davemloft.net> | 2012-08-07 19:24:55 -0400 |
commit | ec03e6a89e5168c92581a769681207c29ad2030f (patch) | |
tree | f2a3a44726091809c12151209c9ab7c30e1304fb /drivers/net/ethernet/ti/davinci_mdio.c | |
parent | aae06bf5f90403554f8d4ff83810a8281aef7f03 (diff) |
drivers: net: ethernet: davince_mdio: device tree implementation
device tree implementation for davinci mdio driver
Signed-off-by: Mugunthan V N <mugunthanvnm@ti.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
Diffstat (limited to 'drivers/net/ethernet/ti/davinci_mdio.c')
-rw-r--r-- | drivers/net/ethernet/ti/davinci_mdio.c | 41 |
1 files changed, 37 insertions, 4 deletions
diff --git a/drivers/net/ethernet/ti/davinci_mdio.c b/drivers/net/ethernet/ti/davinci_mdio.c index cd7ee204e94..573f3be5f42 100644 --- a/drivers/net/ethernet/ti/davinci_mdio.c +++ b/drivers/net/ethernet/ti/davinci_mdio.c | |||
@@ -36,6 +36,8 @@ | |||
36 | #include <linux/io.h> | 36 | #include <linux/io.h> |
37 | #include <linux/pm_runtime.h> | 37 | #include <linux/pm_runtime.h> |
38 | #include <linux/davinci_emac.h> | 38 | #include <linux/davinci_emac.h> |
39 | #include <linux/of.h> | ||
40 | #include <linux/of_device.h> | ||
39 | 41 | ||
40 | /* | 42 | /* |
41 | * This timeout definition is a worst-case ultra defensive measure against | 43 | * This timeout definition is a worst-case ultra defensive measure against |
@@ -289,6 +291,25 @@ static int davinci_mdio_write(struct mii_bus *bus, int phy_id, | |||
289 | return 0; | 291 | return 0; |
290 | } | 292 | } |
291 | 293 | ||
294 | static int davinci_mdio_probe_dt(struct mdio_platform_data *data, | ||
295 | struct platform_device *pdev) | ||
296 | { | ||
297 | struct device_node *node = pdev->dev.of_node; | ||
298 | u32 prop; | ||
299 | |||
300 | if (!node) | ||
301 | return -EINVAL; | ||
302 | |||
303 | if (of_property_read_u32(node, "bus_freq", &prop)) { | ||
304 | pr_err("Missing bus_freq property in the DT.\n"); | ||
305 | return -EINVAL; | ||
306 | } | ||
307 | data->bus_freq = prop; | ||
308 | |||
309 | return 0; | ||
310 | } | ||
311 | |||
312 | |||
292 | static int __devinit davinci_mdio_probe(struct platform_device *pdev) | 313 | static int __devinit davinci_mdio_probe(struct platform_device *pdev) |
293 | { | 314 | { |
294 | struct mdio_platform_data *pdata = pdev->dev.platform_data; | 315 | struct mdio_platform_data *pdata = pdev->dev.platform_data; |
@@ -304,8 +325,6 @@ static int __devinit davinci_mdio_probe(struct platform_device *pdev) | |||
304 | return -ENOMEM; | 325 | return -ENOMEM; |
305 | } | 326 | } |
306 | 327 | ||
307 | data->pdata = pdata ? (*pdata) : default_pdata; | ||
308 | |||
309 | data->bus = mdiobus_alloc(); | 328 | data->bus = mdiobus_alloc(); |
310 | if (!data->bus) { | 329 | if (!data->bus) { |
311 | dev_err(dev, "failed to alloc mii bus\n"); | 330 | dev_err(dev, "failed to alloc mii bus\n"); |
@@ -313,14 +332,22 @@ static int __devinit davinci_mdio_probe(struct platform_device *pdev) | |||
313 | goto bail_out; | 332 | goto bail_out; |
314 | } | 333 | } |
315 | 334 | ||
335 | if (dev->of_node) { | ||
336 | if (davinci_mdio_probe_dt(&data->pdata, pdev)) | ||
337 | data->pdata = default_pdata; | ||
338 | snprintf(data->bus->id, MII_BUS_ID_SIZE, "%s", pdev->name); | ||
339 | } else { | ||
340 | data->pdata = pdata ? (*pdata) : default_pdata; | ||
341 | snprintf(data->bus->id, MII_BUS_ID_SIZE, "%s-%x", | ||
342 | pdev->name, pdev->id); | ||
343 | } | ||
344 | |||
316 | data->bus->name = dev_name(dev); | 345 | data->bus->name = dev_name(dev); |
317 | data->bus->read = davinci_mdio_read, | 346 | data->bus->read = davinci_mdio_read, |
318 | data->bus->write = davinci_mdio_write, | 347 | data->bus->write = davinci_mdio_write, |
319 | data->bus->reset = davinci_mdio_reset, | 348 | data->bus->reset = davinci_mdio_reset, |
320 | data->bus->parent = dev; | 349 | data->bus->parent = dev; |
321 | data->bus->priv = data; | 350 | data->bus->priv = data; |
322 | snprintf(data->bus->id, MII_BUS_ID_SIZE, "%s-%x", | ||
323 | pdev->name, pdev->id); | ||
324 | 351 | ||
325 | pm_runtime_enable(&pdev->dev); | 352 | pm_runtime_enable(&pdev->dev); |
326 | pm_runtime_get_sync(&pdev->dev); | 353 | pm_runtime_get_sync(&pdev->dev); |
@@ -454,11 +481,17 @@ static const struct dev_pm_ops davinci_mdio_pm_ops = { | |||
454 | .resume = davinci_mdio_resume, | 481 | .resume = davinci_mdio_resume, |
455 | }; | 482 | }; |
456 | 483 | ||
484 | static const struct of_device_id davinci_mdio_of_mtable[] = { | ||
485 | { .compatible = "ti,davinci_mdio", }, | ||
486 | { /* sentinel */ }, | ||
487 | }; | ||
488 | |||
457 | static struct platform_driver davinci_mdio_driver = { | 489 | static struct platform_driver davinci_mdio_driver = { |
458 | .driver = { | 490 | .driver = { |
459 | .name = "davinci_mdio", | 491 | .name = "davinci_mdio", |
460 | .owner = THIS_MODULE, | 492 | .owner = THIS_MODULE, |
461 | .pm = &davinci_mdio_pm_ops, | 493 | .pm = &davinci_mdio_pm_ops, |
494 | .of_match_table = of_match_ptr(davinci_mdio_of_mtable), | ||
462 | }, | 495 | }, |
463 | .probe = davinci_mdio_probe, | 496 | .probe = davinci_mdio_probe, |
464 | .remove = __devexit_p(davinci_mdio_remove), | 497 | .remove = __devexit_p(davinci_mdio_remove), |