Skip to content

Commit 0b8bf1b

Browse files
tom3qdavem330
authored andcommitted
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>
1 parent aafc787 commit 0b8bf1b

File tree

3 files changed

+69
-0
lines changed

3 files changed

+69
-0
lines changed
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
Davicom DM9000 Fast Ethernet controller
2+
3+
Required properties:
4+
- compatible = "davicom,dm9000";
5+
- reg : physical addresses and sizes of registers, must contain 2 entries:
6+
first entry : address register,
7+
second entry : data register.
8+
- interrupt-parent : interrupt controller to which the device is connected
9+
- interrupts : interrupt specifier specific to interrupt controller
10+
11+
Optional properties:
12+
- local-mac-address : A bytestring of 6 bytes specifying Ethernet MAC address
13+
to use (from firmware or bootloader)
14+
- davicom,no-eeprom : Configuration EEPROM is not available
15+
- davicom,ext-phy : Use external PHY
16+
17+
Example:
18+
19+
ethernet@18000000 {
20+
compatible = "davicom,dm9000";
21+
reg = <0x18000000 0x2 0x18000004 0x2>;
22+
interrupt-parent = <&gpn>;
23+
interrupts = <7 4>;
24+
local-mac-address = [00 00 de ad be ef];
25+
davicom,no-eeprom;
26+
};

Documentation/devicetree/bindings/vendor-prefixes.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ chrp Common Hardware Reference Platform
1818
cirrus Cirrus Logic, Inc.
1919
cortina Cortina Systems, Inc.
2020
dallas Maxim Integrated Products (formerly Dallas Semiconductor)
21+
davicom DAVICOM Semiconductor, Inc.
2122
denx Denx Software Engineering
2223
emmicro EM Microelectronic
2324
epson Seiko Epson Corp.

drivers/net/ethernet/davicom/dm9000.c

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,8 @@
2929
#include <linux/spinlock.h>
3030
#include <linux/crc32.h>
3131
#include <linux/mii.h>
32+
#include <linux/of.h>
33+
#include <linux/of_net.h>
3234
#include <linux/ethtool.h>
3335
#include <linux/dm9000.h>
3436
#include <linux/delay.h>
@@ -1351,6 +1353,31 @@ static const struct net_device_ops dm9000_netdev_ops = {
13511353
#endif
13521354
};
13531355

1356+
static 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+
13541381
/*
13551382
* Search DM9000 board, allocate space and register it
13561383
*/
@@ -1366,6 +1393,12 @@ dm9000_probe(struct platform_device *pdev)
13661393
int i;
13671394
u32 id_val;
13681395

1396+
if (!pdata) {
1397+
pdata = dm9000_parse_dt(&pdev->dev);
1398+
if (IS_ERR(pdata))
1399+
return PTR_ERR(pdata);
1400+
}
1401+
13691402
/* Init network device */
13701403
ndev = alloc_etherdev(sizeof(struct board_info));
13711404
if (!ndev)
@@ -1676,11 +1709,20 @@ dm9000_drv_remove(struct platform_device *pdev)
16761709
return 0;
16771710
}
16781711

1712+
#ifdef CONFIG_OF
1713+
static const struct of_device_id dm9000_of_matches[] = {
1714+
{ .compatible = "davicom,dm9000", },
1715+
{ /* sentinel */ }
1716+
};
1717+
MODULE_DEVICE_TABLE(of, dm9000_of_matches);
1718+
#endif
1719+
16791720
static struct platform_driver dm9000_driver = {
16801721
.driver = {
16811722
.name = "dm9000",
16821723
.owner = THIS_MODULE,
16831724
.pm = &dm9000_drv_pm_ops,
1725+
.of_match_table = of_match_ptr(dm9000_of_matches),
16841726
},
16851727
.probe = dm9000_probe,
16861728
.remove = dm9000_drv_remove,

0 commit comments

Comments
 (0)