linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: "H. Nikolaus Schaller" <hns@goldelico.com>
To: "Paul Cercueil" <paul@crapouillou.net>,
	"Paul Boddie" <paul@boddie.org.uk>,
	"Alex Smith" <alex.smith@imgtec.com>,
	"Rob Herring" <robh+dt@kernel.org>,
	"Mark Rutland" <mark.rutland@arm.com>,
	"Ralf Baechle" <ralf@linux-mips.org>,
	"Paul Burton" <paulburton@kernel.org>,
	"James Hogan" <jhogan@kernel.org>,
	"David Airlie" <airlied@linux.ie>,
	"Daniel Vetter" <daniel@ffwll.ch>,
	"David S. Miller" <davem@davemloft.net>,
	"Linus Walleij" <linus.walleij@linaro.org>,
	"H. Nikolaus Schaller" <hns@goldelico.com>,
	"Andi Kleen" <ak@linux.intel.com>,
	"Krzysztof Kozlowski" <krzk@kernel.org>,
	"Geert Uytterhoeven" <geert+renesas@glider.be>,
	"Miquel Raynal" <miquel.raynal@bootlin.com>,
	"Petr Štetiar" <ynezz@true.cz>,
	"Richard Fontana" <rfontana@redhat.com>,
	"Allison Randal" <allison@lohutok.net>,
	"Stephen Boyd" <swboyd@chromium.org>
Cc: devicetree@vger.kernel.org, linux-mips@vger.kernel.org,
	linux-kernel@vger.kernel.org, dri-devel@lists.freedesktop.org,
	linux-i2c@vger.kernel.org, netdev@vger.kernel.org,
	linux-gpio@vger.kernel.org, letux-kernel@openphoenux.org,
	kernel@pyra-handheld.com
Subject: [PATCH 03/14] net: davicom: dm9000: allow to pass MAC address through mac_addr module parameter
Date: Tue, 11 Feb 2020 22:41:20 +0100	[thread overview]
Message-ID: <4e11dd4183da55012198824ca7b8933b1eb57e4a.1581457290.git.hns@goldelico.com> (raw)
In-Reply-To: <cover.1581457290.git.hns@goldelico.com>

This is needed to give the MIPS Ingenic CI20 board a stable MAC address
which can be optionally provided by vendor U-Boot.

For get_mac_addr() we use an adapted copy of from ksz884x.c which
has very similar functionality.

Signed-off-by: H. Nikolaus Schaller <hns@goldelico.com>
---
 drivers/net/ethernet/davicom/dm9000.c | 42 +++++++++++++++++++++++++++
 1 file changed, 42 insertions(+)

diff --git a/drivers/net/ethernet/davicom/dm9000.c b/drivers/net/ethernet/davicom/dm9000.c
index 1ea3372775e6..7402030b0352 100644
--- a/drivers/net/ethernet/davicom/dm9000.c
+++ b/drivers/net/ethernet/davicom/dm9000.c
@@ -1409,6 +1409,43 @@ static struct dm9000_plat_data *dm9000_parse_dt(struct device *dev)
 	return pdata;
 }
 
+static char *mac_addr = ":";
+module_param(mac_addr, charp, 0);
+MODULE_PARM_DESC(mac_addr, "MAC address");
+
+static void get_mac_addr(struct net_device *ndev, char *macaddr)
+{
+	int i = 0;
+	int j = 0;
+	int got_num = 0;
+	int num = 0;
+
+	while (j < ETH_ALEN) {
+		if (macaddr[i]) {
+			int digit;
+
+			got_num = 1;
+			digit = hex_to_bin(macaddr[i]);
+			if (digit >= 0)
+				num = num * 16 + digit;
+			else if (':' == macaddr[i])
+				got_num = 2;
+			else
+				break;
+		} else if (got_num) {
+			got_num = 2;
+		} else {
+			break;
+		}
+		if (got_num == 2) {
+			ndev->dev_addr[j++] = (u8)num;
+			num = 0;
+			got_num = 0;
+		}
+		i++;
+	}
+}
+
 /*
  * Search DM9000 board, allocate space and register it
  */
@@ -1679,6 +1716,11 @@ dm9000_probe(struct platform_device *pdev)
 			ndev->dev_addr[i] = ior(db, i+DM9000_PAR);
 	}
 
+	if (!is_valid_ether_addr(ndev->dev_addr)) {
+		mac_src = "param";
+		get_mac_addr(ndev, mac_addr);
+	}
+
 	if (!is_valid_ether_addr(ndev->dev_addr)) {
 		inv_mac_addr = true;
 		eth_hw_addr_random(ndev);
-- 
2.23.0


  parent reply	other threads:[~2020-02-11 21:42 UTC|newest]

Thread overview: 24+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-02-11 21:41 [PATCH 00/14] MIPS: Fixes and improvements for CI20 board (JZ4780) H. Nikolaus Schaller
2020-02-11 21:41 ` [PATCH 01/14] i2c: jz4780: suppress txabrt reports for i2cdetect H. Nikolaus Schaller
2020-02-12  9:46   ` i2c: jz4780: silence log flood on txabrt Wolfram Sang
2020-02-12 14:46     ` H. Nikolaus Schaller
2020-02-12 14:53       ` Wolfram Sang
2020-02-12 14:59         ` H. Nikolaus Schaller
2020-02-13  9:10     ` Wolfram Sang
2020-02-11 21:41 ` [PATCH 02/14] drm: ingenic-drm: add MODULE_DEVICE_TABLE H. Nikolaus Schaller
2020-02-11 21:41 ` H. Nikolaus Schaller [this message]
2020-02-11 22:25   ` [PATCH 03/14] net: davicom: dm9000: allow to pass MAC address through mac_addr module parameter Andrew Lunn
2020-02-12  8:07     ` Geert Uytterhoeven
2020-02-12  8:13       ` H. Nikolaus Schaller
2020-02-11 21:41 ` [PATCH 04/14] MIPS: DTS: jz4780: fix #includes for irq.h and gpio.h H. Nikolaus Schaller
2020-02-11 21:41 ` [PATCH 05/14] MIPS: CI20: defconfig: configure for supporting modules H. Nikolaus Schaller
2020-02-11 21:41 ` [PATCH 06/14] MIPS: CI20: defconfig: compile leds-gpio driver into the kernel and configure for LED triggers H. Nikolaus Schaller
2020-02-11 21:41 ` [PATCH 07/14] MIPS: DTS: CI20: fix PMU definitions for ACT8600 H. Nikolaus Schaller
2020-02-11 21:48   ` [Letux-kernel] " Andreas Kemnade
2020-02-11 21:41 ` [PATCH 08/14] MIPS: CI20: defconfig: configure CONFIG_REGULATOR_ACT8865 for PMU H. Nikolaus Schaller
2020-02-11 21:41 ` [PATCH 09/14] MIPS: DTS: CI20: give eth0_power a defined voltage H. Nikolaus Schaller
2020-02-11 21:41 ` [PATCH 10/14] MIPS: DTS: CI20: add DT node for IR sensor H. Nikolaus Schaller
2020-02-11 21:41 ` [PATCH 11/14] MIPS: CI20: defconfig: compile gpio-ir driver H. Nikolaus Schaller
2020-02-11 21:41 ` [PATCH 12/14] MIPS: DTS: CI20: add DT node for SW1 as Enter button H. Nikolaus Schaller
2020-02-11 21:41 ` [PATCH 13/14] MIPS: CI20: defconfig: configure for CONFIG_KEYBOARD_GPIO=m H. Nikolaus Schaller
2020-02-11 21:41 ` [PATCH 14/14] MIPS: DTS: CI20: fix interrupt for pcf8563 RTC H. Nikolaus Schaller

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=4e11dd4183da55012198824ca7b8933b1eb57e4a.1581457290.git.hns@goldelico.com \
    --to=hns@goldelico.com \
    --cc=airlied@linux.ie \
    --cc=ak@linux.intel.com \
    --cc=alex.smith@imgtec.com \
    --cc=allison@lohutok.net \
    --cc=daniel@ffwll.ch \
    --cc=davem@davemloft.net \
    --cc=devicetree@vger.kernel.org \
    --cc=dri-devel@lists.freedesktop.org \
    --cc=geert+renesas@glider.be \
    --cc=jhogan@kernel.org \
    --cc=kernel@pyra-handheld.com \
    --cc=krzk@kernel.org \
    --cc=letux-kernel@openphoenux.org \
    --cc=linus.walleij@linaro.org \
    --cc=linux-gpio@vger.kernel.org \
    --cc=linux-i2c@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-mips@vger.kernel.org \
    --cc=mark.rutland@arm.com \
    --cc=miquel.raynal@bootlin.com \
    --cc=netdev@vger.kernel.org \
    --cc=paul@boddie.org.uk \
    --cc=paul@crapouillou.net \
    --cc=paulburton@kernel.org \
    --cc=ralf@linux-mips.org \
    --cc=rfontana@redhat.com \
    --cc=robh+dt@kernel.org \
    --cc=swboyd@chromium.org \
    --cc=ynezz@true.cz \
    --subject='Re: [PATCH 03/14] net: davicom: dm9000: allow to pass MAC address through mac_addr module parameter' \
    /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

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).