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>,
	netdev@vger.kernel.org, linux-kernel@vger.kernel.org
Subject: [PATCH v2 net-next 7/9] net: korina: Add support for device tree
Date: Wed, 14 Apr 2021 17:29:43 +0200	[thread overview]
Message-ID: <20210414152946.12517-8-tsbogend@alpha.franken.de> (raw)
In-Reply-To: <20210414152946.12517-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 | 29 ++++++++++++++++++++++++++---
 1 file changed, 26 insertions(+), 3 deletions(-)

diff --git a/drivers/net/ethernet/korina.c b/drivers/net/ethernet/korina.c
index 69c8baa87a6e..c4590b2c65aa 100644
--- a/drivers/net/ethernet/korina.c
+++ b/drivers/net/ethernet/korina.c
@@ -42,6 +42,8 @@
 #include <linux/interrupt.h>
 #include <linux/ioport.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>
@@ -1056,7 +1058,7 @@ static const struct net_device_ops korina_netdev_ops = {
 
 static int korina_probe(struct platform_device *pdev)
 {
-	u8 *mac_addr = dev_get_platdata(&pdev->dev);
+	const u8 *mac_addr = dev_get_platdata(&pdev->dev);
 	struct korina_private *lp;
 	struct net_device *dev;
 	void __iomem *p;
@@ -1069,7 +1071,15 @@ 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 {
+		mac_addr = of_get_mac_address(pdev->dev.of_node);
+		if (!IS_ERR(mac_addr))
+			ether_addr_copy(dev->dev_addr, mac_addr);
+		else
+			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");
@@ -1149,8 +1159,21 @@ static int korina_remove(struct platform_device *pdev)
 	return 0;
 }
 
+#ifdef CONFIG_OF
+static const struct of_device_id korina_match[] = {
+	{
+		.compatible = "korina",
+	},
+	{ }
+};
+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-14 15:30 UTC|newest]

Thread overview: 13+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-04-14 15:29 [PATCH v2 net-next 0/9] net: Korina improvements Thomas Bogendoerfer
2021-04-14 15:29 ` [PATCH v2 net-next 1/9] net: korina: Fix MDIO functions Thomas Bogendoerfer
2021-04-14 15:29 ` [PATCH v2 net-next 2/9] net: korina: Use devres functions Thomas Bogendoerfer
2021-04-14 15:29 ` [PATCH v2 net-next 3/9] net: korina: Remove not needed cache flushes Thomas Bogendoerfer
2021-04-14 15:29 ` [PATCH v2 net-next 4/9] net: korina: Remove nested helpers Thomas Bogendoerfer
2021-04-14 15:29 ` [PATCH v2 net-next 5/9] net: korina: Use DMA API Thomas Bogendoerfer
2021-04-14 15:29 ` [PATCH v2 net-next 6/9] net: korina: Only pass mac address via platform data Thomas Bogendoerfer
2021-04-14 15:29 ` Thomas Bogendoerfer [this message]
2021-04-14 18:33   ` [PATCH v2 net-next 7/9] net: korina: Add support for device tree Florian Fainelli
2021-04-14 15:29 ` [PATCH v2 net-next 8/9] net: korina: Get mdio input clock via common clock framework Thomas Bogendoerfer
2021-04-14 15:29 ` [PATCH v2 net-next 9/9] net: korina: Make driver COMPILE_TESTable Thomas Bogendoerfer
2021-04-15  2:48   ` kernel test robot
2021-04-14 21:10 ` [PATCH v2 net-next 0/9] net: Korina improvements David Miller

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=20210414152946.12517-8-tsbogend@alpha.franken.de \
    --to=tsbogend@alpha.franken.de \
    --cc=davem@davemloft.net \
    --cc=kuba@kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=netdev@vger.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).