From patchwork Mon Dec 18 10:17:07 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Lukas Wunner X-Patchwork-Id: 849970 X-Patchwork-Delegate: davem@davemloft.net Return-Path: X-Original-To: patchwork-incoming@ozlabs.org Delivered-To: patchwork-incoming@ozlabs.org Authentication-Results: ozlabs.org; spf=none (mailfrom) smtp.mailfrom=vger.kernel.org (client-ip=209.132.180.67; helo=vger.kernel.org; envelope-from=netdev-owner@vger.kernel.org; receiver=) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by ozlabs.org (Postfix) with ESMTP id 3z0cYN1T1Hz9s74 for ; Mon, 18 Dec 2017 21:22:48 +1100 (AEDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S932842AbdLRKWp (ORCPT ); Mon, 18 Dec 2017 05:22:45 -0500 Received: from mailout3.hostsharing.net ([176.9.242.54]:59669 "EHLO mailout3.hostsharing.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S932684AbdLRKWn (ORCPT ); Mon, 18 Dec 2017 05:22:43 -0500 X-Greylist: delayed 334 seconds by postgrey-1.27 at vger.kernel.org; Mon, 18 Dec 2017 05:22:43 EST Received: from h08.hostsharing.net (h08.hostsharing.net [83.223.95.28]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client CN "*.hostsharing.net", Issuer "COMODO RSA Domain Validation Secure Server CA" (not verified)) by mailout3.hostsharing.net (Postfix) with ESMTPS id BB84510310530; Mon, 18 Dec 2017 11:17:35 +0100 (CET) Received: from localhost (p4FC5FB1A.dip0.t-ipconnect.de [79.197.251.26]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by h08.hostsharing.net (Postfix) with ESMTPSA id EE06E60B31A5; Mon, 18 Dec 2017 11:17:07 +0100 (CET) X-Mailbox-Line: From 68ae82c3cac7b6e4123fa31140805f7fab93af06 Mon Sep 17 00:00:00 2001 Message-Id: <68ae82c3cac7b6e4123fa31140805f7fab93af06.1513591121.git.lukas@wunner.de> From: Lukas Wunner Date: Mon, 18 Dec 2017 11:17:07 +0100 Subject: [PATCH] net: ks8851: Support DT-provided MAC address To: "David S. Miller" Cc: Ben Dooks , Tristram Ha , "David J. Choi" , Mathias Duckeck , netdev@vger.kernel.org Sender: netdev-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org 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 Cc: Tristram Ha Cc: David J. Choi Signed-off-by: Lukas Wunner --- 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 #include #include +#include #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))