All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] net: ks8851: Support DT-provided MAC address
@ 2017-12-18 10:17 Lukas Wunner
  2017-12-19 18:52 ` David Miller
  0 siblings, 1 reply; 2+ messages in thread
From: Lukas Wunner @ 2017-12-18 10:17 UTC (permalink / raw)
  To: David S. Miller
  Cc: Ben Dooks, Tristram Ha, David J. Choi, Mathias Duckeck, netdev

Allow the boot loader to specify the MAC address in the device tree
to override the EEPROM, or in case no EEPROM is present.

Cc: Ben Dooks <ben@simtec.co.uk>
Cc: Tristram Ha <tristram.ha@micrel.com>
Cc: David J. Choi <david.choi@micrel.com>
Signed-off-by: Lukas Wunner <lukas@wunner.de>
---
We're using this small patch on the "Revolution Pi" family of
open source PLCs (https://revolution.kunbus.com/) and would
love to see it mainlined.  Thanks!

 drivers/net/ethernet/micrel/ks8851.c | 13 +++++++++++--
 1 file changed, 11 insertions(+), 2 deletions(-)

diff --git a/drivers/net/ethernet/micrel/ks8851.c b/drivers/net/ethernet/micrel/ks8851.c
index 2fe96f1f3fe5..bd6e9014bc74 100644
--- a/drivers/net/ethernet/micrel/ks8851.c
+++ b/drivers/net/ethernet/micrel/ks8851.c
@@ -28,6 +28,7 @@
 #include <linux/spi/spi.h>
 #include <linux/gpio.h>
 #include <linux/of_gpio.h>
+#include <linux/of_net.h>
 
 #include "ks8851.h"
 
@@ -407,15 +408,23 @@ static void ks8851_read_mac_addr(struct net_device *dev)
  * @ks: The device structure
  *
  * Get or create the initial mac address for the device and then set that
- * into the station address register. If there is an EEPROM present, then
+ * into the station address register. A mac address supplied in the device
+ * tree takes precedence. Otherwise, if there is an EEPROM present, then
  * we try that. If no valid mac address is found we use eth_random_addr()
  * to create a new one.
  */
 static void ks8851_init_mac(struct ks8851_net *ks)
 {
 	struct net_device *dev = ks->netdev;
+	const u8 *mac_addr;
+
+	mac_addr = of_get_mac_address(ks->spidev->dev.of_node);
+	if (mac_addr) {
+		memcpy(dev->dev_addr, mac_addr, ETH_ALEN);
+		ks8851_write_mac_addr(dev);
+		return;
+	}
 
-	/* first, try reading what we've got already */
 	if (ks->rc_ccr & CCR_EEPROM) {
 		ks8851_read_mac_addr(dev);
 		if (is_valid_ether_addr(dev->dev_addr))
-- 
2.15.1

^ permalink raw reply related	[flat|nested] 2+ messages in thread

* Re: [PATCH] net: ks8851: Support DT-provided MAC address
  2017-12-18 10:17 [PATCH] net: ks8851: Support DT-provided MAC address Lukas Wunner
@ 2017-12-19 18:52 ` David Miller
  0 siblings, 0 replies; 2+ messages in thread
From: David Miller @ 2017-12-19 18:52 UTC (permalink / raw)
  To: lukas; +Cc: ben, tristram.ha, david.choi, m.duckeck, netdev

From: Lukas Wunner <lukas@wunner.de>
Date: Mon, 18 Dec 2017 11:17:07 +0100

> Allow the boot loader to specify the MAC address in the device tree
> to override the EEPROM, or in case no EEPROM is present.
> 
> Cc: Ben Dooks <ben@simtec.co.uk>
> Cc: Tristram Ha <tristram.ha@micrel.com>
> Cc: David J. Choi <david.choi@micrel.com>
> Signed-off-by: Lukas Wunner <lukas@wunner.de>

Applied to net-next, thank you.

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2017-12-19 18:53 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2017-12-18 10:17 [PATCH] net: ks8851: Support DT-provided MAC address Lukas Wunner
2017-12-19 18:52 ` David Miller

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.