Эх сурвалжийг харах

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>
Tomasz Figa 12 жил өмнө
parent
commit
0b8bf1baab

+ 26 - 0
Documentation/devicetree/bindings/net/davicom-dm9000.txt

@@ -0,0 +1,26 @@
+Davicom DM9000 Fast Ethernet controller
+
+Required properties:
+- compatible = "davicom,dm9000";
+- reg : physical addresses and sizes of registers, must contain 2 entries:
+    first entry : address register,
+    second entry : data register.
+- interrupt-parent : interrupt controller to which the device is connected
+- interrupts : interrupt specifier specific to interrupt controller
+
+Optional properties:
+- local-mac-address : A bytestring of 6 bytes specifying Ethernet MAC address
+    to use (from firmware or bootloader)
+- davicom,no-eeprom : Configuration EEPROM is not available
+- davicom,ext-phy : Use external PHY
+
+Example:
+
+	ethernet@18000000 {
+		compatible = "davicom,dm9000";
+		reg = <0x18000000 0x2 0x18000004 0x2>;
+		interrupt-parent = <&gpn>;
+		interrupts = <7 4>;
+		local-mac-address = [00 00 de ad be ef];
+		davicom,no-eeprom;
+	};

+ 1 - 0
Documentation/devicetree/bindings/vendor-prefixes.txt

@@ -18,6 +18,7 @@ chrp	Common Hardware Reference Platform
 cirrus	Cirrus Logic, Inc.
 cirrus	Cirrus Logic, Inc.
 cortina	Cortina Systems, Inc.
 cortina	Cortina Systems, Inc.
 dallas	Maxim Integrated Products (formerly Dallas Semiconductor)
 dallas	Maxim Integrated Products (formerly Dallas Semiconductor)
+davicom	DAVICOM Semiconductor, Inc.
 denx	Denx Software Engineering
 denx	Denx Software Engineering
 emmicro	EM Microelectronic
 emmicro	EM Microelectronic
 epson	Seiko Epson Corp.
 epson	Seiko Epson Corp.

+ 42 - 0
drivers/net/ethernet/davicom/dm9000.c

@@ -29,6 +29,8 @@
 #include <linux/spinlock.h>
 #include <linux/spinlock.h>
 #include <linux/crc32.h>
 #include <linux/crc32.h>
 #include <linux/mii.h>
 #include <linux/mii.h>
+#include <linux/of.h>
+#include <linux/of_net.h>
 #include <linux/ethtool.h>
 #include <linux/ethtool.h>
 #include <linux/dm9000.h>
 #include <linux/dm9000.h>
 #include <linux/delay.h>
 #include <linux/delay.h>
@@ -1351,6 +1353,31 @@ static const struct net_device_ops dm9000_netdev_ops = {
 #endif
 #endif
 };
 };
 
 
+static struct dm9000_plat_data *dm9000_parse_dt(struct device *dev)
+{
+	struct dm9000_plat_data *pdata;
+	struct device_node *np = dev->of_node;
+	const void *mac_addr;
+
+	if (!IS_ENABLED(CONFIG_OF) || !np)
+		return NULL;
+
+	pdata = devm_kzalloc(dev, sizeof(*pdata), GFP_KERNEL);
+	if (!pdata)
+		return ERR_PTR(-ENOMEM);
+
+	if (of_find_property(np, "davicom,ext-phy", NULL))
+		pdata->flags |= DM9000_PLATF_EXT_PHY;
+	if (of_find_property(np, "davicom,no-eeprom", NULL))
+		pdata->flags |= DM9000_PLATF_NO_EEPROM;
+
+	mac_addr = of_get_mac_address(np);
+	if (mac_addr)
+		memcpy(pdata->dev_addr, mac_addr, sizeof(pdata->dev_addr));
+
+	return pdata;
+}
+
 /*
 /*
  * Search DM9000 board, allocate space and register it
  * Search DM9000 board, allocate space and register it
  */
  */
@@ -1366,6 +1393,12 @@ dm9000_probe(struct platform_device *pdev)
 	int i;
 	int i;
 	u32 id_val;
 	u32 id_val;
 
 
+	if (!pdata) {
+		pdata = dm9000_parse_dt(&pdev->dev);
+		if (IS_ERR(pdata))
+			return PTR_ERR(pdata);
+	}
+
 	/* Init network device */
 	/* Init network device */
 	ndev = alloc_etherdev(sizeof(struct board_info));
 	ndev = alloc_etherdev(sizeof(struct board_info));
 	if (!ndev)
 	if (!ndev)
@@ -1676,11 +1709,20 @@ dm9000_drv_remove(struct platform_device *pdev)
 	return 0;
 	return 0;
 }
 }
 
 
+#ifdef CONFIG_OF
+static const struct of_device_id dm9000_of_matches[] = {
+	{ .compatible = "davicom,dm9000", },
+	{ /* sentinel */ }
+};
+MODULE_DEVICE_TABLE(of, dm9000_of_matches);
+#endif
+
 static struct platform_driver dm9000_driver = {
 static struct platform_driver dm9000_driver = {
 	.driver	= {
 	.driver	= {
 		.name    = "dm9000",
 		.name    = "dm9000",
 		.owner	 = THIS_MODULE,
 		.owner	 = THIS_MODULE,
 		.pm	 = &dm9000_drv_pm_ops,
 		.pm	 = &dm9000_drv_pm_ops,
+		.of_match_table = of_match_ptr(dm9000_of_matches),
 	},
 	},
 	.probe   = dm9000_probe,
 	.probe   = dm9000_probe,
 	.remove  = dm9000_drv_remove,
 	.remove  = dm9000_drv_remove,