aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/net/ethernet/davicom
diff options
context:
space:
mode:
authorTomasz Figa <tomasz.figa@gmail.com>2013-05-20 05:16:58 -0400
committerDavid S. Miller <davem@davemloft.net>2013-05-20 17:03:51 -0400
commit0b8bf1baabe56f721d541953f083560d0660d78f (patch)
tree38953bf7cf973921fa2ab9c696450aba2476d170 /drivers/net/ethernet/davicom
parentaafc787e41fd8a4d3a4378b028d8d8f8d38d9bb6 (diff)
net: dm9000: Allow instantiation using device tree
This patch adds Device Tree support to dm9000 driver. Signed-off-by: Tomasz Figa <tomasz.figa@gmail.com> Reviewed-by: Sylwester Nawrocki <sylvester.nawrocki@gmail.com> Reviewed-by: Sascha Hauer <s.hauer@pengutronix.de> Signed-off-by: David S. Miller <davem@davemloft.net>
Diffstat (limited to 'drivers/net/ethernet/davicom')
-rw-r--r--drivers/net/ethernet/davicom/dm9000.c42
1 files changed, 42 insertions, 0 deletions
diff --git a/drivers/net/ethernet/davicom/dm9000.c b/drivers/net/ethernet/davicom/dm9000.c
index a2408c84bbdd..dd243a1b03e0 100644
--- a/drivers/net/ethernet/davicom/dm9000.c
+++ b/drivers/net/ethernet/davicom/dm9000.c
@@ -29,6 +29,8 @@
29#include <linux/spinlock.h> 29#include <linux/spinlock.h>
30#include <linux/crc32.h> 30#include <linux/crc32.h>
31#include <linux/mii.h> 31#include <linux/mii.h>
32#include <linux/of.h>
33#include <linux/of_net.h>
32#include <linux/ethtool.h> 34#include <linux/ethtool.h>
33#include <linux/dm9000.h> 35#include <linux/dm9000.h>
34#include <linux/delay.h> 36#include <linux/delay.h>
@@ -1351,6 +1353,31 @@ static const struct net_device_ops dm9000_netdev_ops = {
1351#endif 1353#endif
1352}; 1354};
1353 1355
1356static struct dm9000_plat_data *dm9000_parse_dt(struct device *dev)
1357{
1358 struct dm9000_plat_data *pdata;
1359 struct device_node *np = dev->of_node;
1360 const void *mac_addr;
1361
1362 if (!IS_ENABLED(CONFIG_OF) || !np)
1363 return NULL;
1364
1365 pdata = devm_kzalloc(dev, sizeof(*pdata), GFP_KERNEL);
1366 if (!pdata)
1367 return ERR_PTR(-ENOMEM);
1368
1369 if (of_find_property(np, "davicom,ext-phy", NULL))
1370 pdata->flags |= DM9000_PLATF_EXT_PHY;
1371 if (of_find_property(np, "davicom,no-eeprom", NULL))
1372 pdata->flags |= DM9000_PLATF_NO_EEPROM;
1373
1374 mac_addr = of_get_mac_address(np);
1375 if (mac_addr)
1376 memcpy(pdata->dev_addr, mac_addr, sizeof(pdata->dev_addr));
1377
1378 return pdata;
1379}
1380
1354/* 1381/*
1355 * Search DM9000 board, allocate space and register it 1382 * Search DM9000 board, allocate space and register it
1356 */ 1383 */
@@ -1366,6 +1393,12 @@ dm9000_probe(struct platform_device *pdev)
1366 int i; 1393 int i;
1367 u32 id_val; 1394 u32 id_val;
1368 1395
1396 if (!pdata) {
1397 pdata = dm9000_parse_dt(&pdev->dev);
1398 if (IS_ERR(pdata))
1399 return PTR_ERR(pdata);
1400 }
1401
1369 /* Init network device */ 1402 /* Init network device */
1370 ndev = alloc_etherdev(sizeof(struct board_info)); 1403 ndev = alloc_etherdev(sizeof(struct board_info));
1371 if (!ndev) 1404 if (!ndev)
@@ -1676,11 +1709,20 @@ dm9000_drv_remove(struct platform_device *pdev)
1676 return 0; 1709 return 0;
1677} 1710}
1678 1711
1712#ifdef CONFIG_OF
1713static const struct of_device_id dm9000_of_matches[] = {
1714 { .compatible = "davicom,dm9000", },
1715 { /* sentinel */ }
1716};
1717MODULE_DEVICE_TABLE(of, dm9000_of_matches);
1718#endif
1719
1679static struct platform_driver dm9000_driver = { 1720static struct platform_driver dm9000_driver = {
1680 .driver = { 1721 .driver = {
1681 .name = "dm9000", 1722 .name = "dm9000",
1682 .owner = THIS_MODULE, 1723 .owner = THIS_MODULE,
1683 .pm = &dm9000_drv_pm_ops, 1724 .pm = &dm9000_drv_pm_ops,
1725 .of_match_table = of_match_ptr(dm9000_of_matches),
1684 }, 1726 },
1685 .probe = dm9000_probe, 1727 .probe = dm9000_probe,
1686 .remove = dm9000_drv_remove, 1728 .remove = dm9000_drv_remove,