linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Thomas Bogendoerfer <tsbogend@alpha.franken.de>
To: "David S. Miller" <davem@davemloft.net>,
	Jakub Kicinski <kuba@kernel.org>,
	Rob Herring <robh+dt@kernel.org>,
	netdev@vger.kernel.org, devicetree@vger.kernel.org,
	linux-kernel@vger.kernel.org, linux-mips@vger.kernel.org
Subject: [PATCH v4 net-next 07/10] net: korina: Add support for device tree
Date: Fri, 16 Apr 2021 10:47:08 +0200	[thread overview]
Message-ID: <20210416084712.62561-8-tsbogend@alpha.franken.de> (raw)
In-Reply-To: <20210416084712.62561-1-tsbogend@alpha.franken.de>

If there is no mac address passed via platform data try to get it via
device tree and fall back to a random mac address, if all fail.

Signed-off-by: Thomas Bogendoerfer <tsbogend@alpha.franken.de>
---
 drivers/net/ethernet/korina.c | 24 ++++++++++++++++++++++--
 1 file changed, 22 insertions(+), 2 deletions(-)

diff --git a/drivers/net/ethernet/korina.c b/drivers/net/ethernet/korina.c
index d6dbbdd43d7c..cd078a5c679b 100644
--- a/drivers/net/ethernet/korina.c
+++ b/drivers/net/ethernet/korina.c
@@ -43,6 +43,8 @@
 #include <linux/ioport.h>
 #include <linux/iopoll.h>
 #include <linux/in.h>
+#include <linux/of_device.h>
+#include <linux/of_net.h>
 #include <linux/slab.h>
 #include <linux/string.h>
 #include <linux/delay.h>
@@ -1068,7 +1070,12 @@ static int korina_probe(struct platform_device *pdev)
 	SET_NETDEV_DEV(dev, &pdev->dev);
 	lp = netdev_priv(dev);
 
-	memcpy(dev->dev_addr, mac_addr, ETH_ALEN);
+	if (mac_addr) {
+		ether_addr_copy(dev->dev_addr, mac_addr);
+	} else {
+		if (of_get_mac_address(pdev->dev.of_node, dev->dev_addr))
+			eth_hw_addr_random(dev);
+	}
 
 	lp->rx_irq = platform_get_irq_byname(pdev, "korina_rx");
 	lp->tx_irq = platform_get_irq_byname(pdev, "korina_tx");
@@ -1148,8 +1155,21 @@ static int korina_remove(struct platform_device *pdev)
 	return 0;
 }
 
+#ifdef CONFIG_OF
+static const struct of_device_id korina_match[] = {
+	{
+		.compatible = "idt,3243x-emac",
+	},
+	{ }
+};
+MODULE_DEVICE_TABLE(of, korina_match);
+#endif
+
 static struct platform_driver korina_driver = {
-	.driver.name = "korina",
+	.driver = {
+		.name = "korina",
+		.of_match_table = of_match_ptr(korina_match),
+	},
 	.probe = korina_probe,
 	.remove = korina_remove,
 };
-- 
2.29.2


  parent reply	other threads:[~2021-04-16  8:48 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-04-16  8:47 [PATCH v4 net-next 00/10] net: Korina improvements Thomas Bogendoerfer
2021-04-16  8:47 ` [PATCH v4 net-next 01/10] net: korina: Fix MDIO functions Thomas Bogendoerfer
2021-04-16  8:47 ` [PATCH v4 net-next 02/10] net: korina: Use devres functions Thomas Bogendoerfer
2021-04-16  8:47 ` [PATCH v4 net-next 03/10] net: korina: Remove not needed cache flushes Thomas Bogendoerfer
2021-04-16  8:47 ` [PATCH v4 net-next 04/10] net: korina: Remove nested helpers Thomas Bogendoerfer
2021-04-16  8:47 ` [PATCH v4 net-next 05/10] net: korina: Use DMA API Thomas Bogendoerfer
2021-04-16  8:47 ` [PATCH v4 net-next 06/10] net: korina: Only pass mac address via platform data Thomas Bogendoerfer
2021-04-16  8:47 ` Thomas Bogendoerfer [this message]
2021-04-16  9:21   ` [PATCH v4 net-next 07/10] net: korina: Add support for device tree Sergei Shtylyov
2021-04-16  8:47 ` [PATCH v4 net-next 08/10] net: korina: Get mdio input clock via common clock framework Thomas Bogendoerfer
2021-04-16  8:47 ` [PATCH v4 net-next 09/10] net: korina: Make driver COMPILE_TESTable Thomas Bogendoerfer

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20210416084712.62561-8-tsbogend@alpha.franken.de \
    --to=tsbogend@alpha.franken.de \
    --cc=davem@davemloft.net \
    --cc=devicetree@vger.kernel.org \
    --cc=kuba@kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-mips@vger.kernel.org \
    --cc=netdev@vger.kernel.org \
    --cc=robh+dt@kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).