public inbox for u-boot@lists.denx.de
 help / color / mirror / Atom feed
From: Wenyou Yang <wenyou.yang@microchip.com>
To: u-boot@lists.denx.de
Subject: [U-Boot] [PATCH v4 1/3] board: atmel: Create board/$(VENDOR)/common folder
Date: Fri, 1 Sep 2017 16:26:16 +0800	[thread overview]
Message-ID: <20170901082618.30622-2-wenyou.yang@microchip.com> (raw)
In-Reply-To: <20170901082618.30622-1-wenyou.yang@microchip.com>

Create board/$(VENDOR)/common folder to accommodate the common code
shared by other atmel boards, now put the code to set ethernet mac
address from eeprom, which uses the i2c eeprom driver.

Signed-off-by: Wenyou Yang <wenyou.yang@microchip.com>
---

Changes in v4:
 - Follow up the env function renaming.

Changes in v3: None
Changes in v2: None

 arch/arm/mach-at91/include/mach/at91_common.h |  2 ++
 board/atmel/common/Makefile                   | 11 ++++++++
 board/atmel/common/board.c                    | 12 +++++++++
 board/atmel/common/mac_eeprom.c               | 36 +++++++++++++++++++++++++++
 4 files changed, 61 insertions(+)
 create mode 100644 board/atmel/common/Makefile
 create mode 100644 board/atmel/common/board.c
 create mode 100644 board/atmel/common/mac_eeprom.c

diff --git a/arch/arm/mach-at91/include/mach/at91_common.h b/arch/arm/mach-at91/include/mach/at91_common.h
index 0742ffc56f..a95fe41610 100644
--- a/arch/arm/mach-at91/include/mach/at91_common.h
+++ b/arch/arm/mach-at91/include/mach/at91_common.h
@@ -36,4 +36,6 @@ void matrix_init(void);
 void redirect_int_from_saic_to_aic(void);
 void configure_2nd_sram_as_l2_cache(void);
 
+int at91_set_ethaddr(int offset);
+
 #endif /* AT91_COMMON_H */
diff --git a/board/atmel/common/Makefile b/board/atmel/common/Makefile
new file mode 100644
index 0000000000..6d9c6850b5
--- /dev/null
+++ b/board/atmel/common/Makefile
@@ -0,0 +1,11 @@
+#
+# Copyright (C) 2017 Microchip
+#		      Wenyou Yang <wenyou.yang@microchip.com>
+#
+# SPDX-License-Identifier:	GPL-2.0+
+#
+
+obj-y += board.o
+ifndef CONFIG_SPL_BUILD
+obj-$(CONFIG_I2C_EEPROM) += mac_eeprom.o
+endif
diff --git a/board/atmel/common/board.c b/board/atmel/common/board.c
new file mode 100644
index 0000000000..7e326d925b
--- /dev/null
+++ b/board/atmel/common/board.c
@@ -0,0 +1,12 @@
+/*
+ * Copyright (C) 2017 Microchip
+ *		      Wenyou Yang <wenyou.yang@microchip.com>
+ *
+ * SPDX-License-Identifier:	GPL-2.0+
+ */
+
+#include <common.h>
+
+void dummy(void)
+{
+}
diff --git a/board/atmel/common/mac_eeprom.c b/board/atmel/common/mac_eeprom.c
new file mode 100644
index 0000000000..60ddf00d45
--- /dev/null
+++ b/board/atmel/common/mac_eeprom.c
@@ -0,0 +1,36 @@
+/*
+ * Copyright (C) 2017 Microchip
+ *		      Wenyou Yang <wenyou.yang@microchip.com>
+ *
+ * SPDX-License-Identifier:	GPL-2.0+
+ */
+
+#include <common.h>
+#include <dm.h>
+#include <i2c_eeprom.h>
+#include <netdev.h>
+
+int at91_set_ethaddr(int offset)
+{
+	const int ETH_ADDR_LEN = 6;
+	unsigned char ethaddr[ETH_ADDR_LEN];
+	const char *ETHADDR_NAME = "ethaddr";
+	struct udevice *dev;
+	int ret;
+
+	if (env_get(ETHADDR_NAME))
+		return 0;
+
+	ret = uclass_first_device_err(UCLASS_I2C_EEPROM, &dev);
+	if (ret)
+		return ret;
+
+	ret = i2c_eeprom_read(dev, offset, ethaddr, 6);
+	if (ret)
+		return ret;
+
+	if (is_valid_ethaddr(ethaddr))
+		eth_env_set_enetaddr(ETHADDR_NAME, ethaddr);
+
+	return 0;
+}
-- 
2.13.0

  reply	other threads:[~2017-09-01  8:26 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-09-01  8:26 [U-Boot] [PATCH v4 0/3] board: atmel: Set the ethernet mac address from eeprom Wenyou Yang
2017-09-01  8:26 ` Wenyou Yang [this message]
2017-09-09  4:51   ` [U-Boot] [PATCH v4 1/3] board: atmel: Create board/$(VENDOR)/common folder Simon Glass
2017-09-12 13:31   ` [U-Boot] [U-Boot, v4, " Tom Rini
2017-09-01  8:26 ` [U-Boot] [PATCH v4 2/3] board: sama5d2_xplained: Replace code to set mac address Wenyou Yang
2017-09-09  4:51   ` Simon Glass
2017-09-12 13:31   ` [U-Boot] [U-Boot, v4, " Tom Rini
2017-09-01  8:26 ` [U-Boot] [PATCH v4 3/3] board: sama5d4_xplained: Set mac address from eeprom Wenyou Yang
2017-09-09  4:51   ` Simon Glass
2017-09-12 13:31   ` [U-Boot] [U-Boot, v4, " Tom Rini

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=20170901082618.30622-2-wenyou.yang@microchip.com \
    --to=wenyou.yang@microchip.com \
    --cc=u-boot@lists.denx.de \
    /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