summaryrefslogtreecommitdiff
path: root/board/dhelectronics/common/dh_common.c
diff options
context:
space:
mode:
authorTom Rini <trini@konsulko.com>2022-08-12 21:39:15 -0400
committerTom Rini <trini@konsulko.com>2022-08-12 21:41:07 -0400
commit8f9eee8275cf475f6d9435e85aa2d04b61b3cd75 (patch)
tree1e09bcb44c8e3bc72f3a8315616ec49057e3e49d /board/dhelectronics/common/dh_common.c
parent6fc212779c990ff27a430e370bfb8fac01ddde7f (diff)
parentecf1d2741d95f5f84e31dc1d0bef149d8ff1f0a3 (diff)
Merge branch '2022-08-12-assorted-updates'
- Clean up some code with the DH electronics boards, remove a few boards that have had their removal ack'd, update Azure CI hosts for macOS and Ubuntu, and migrate a few more symbols to Kconfig.
Diffstat (limited to 'board/dhelectronics/common/dh_common.c')
-rw-r--r--board/dhelectronics/common/dh_common.c65
1 files changed, 65 insertions, 0 deletions
diff --git a/board/dhelectronics/common/dh_common.c b/board/dhelectronics/common/dh_common.c
new file mode 100644
index 00000000000..67e3d59b1f3
--- /dev/null
+++ b/board/dhelectronics/common/dh_common.c
@@ -0,0 +1,65 @@
+// SPDX-License-Identifier: GPL-2.0+
+/*
+ * Copyright 2022 Marek Vasut <marex@denx.de>
+ * Copyright 2022 DENX Software Engineering GmbH, Philip Oberfichtner <pro@denx.de>
+ */
+
+#include <common.h>
+#include <dm.h>
+#include <i2c_eeprom.h>
+#include <net.h>
+
+#include "dh_common.h"
+
+bool dh_mac_is_in_env(const char *env)
+{
+ unsigned char enetaddr[6];
+
+ return eth_env_get_enetaddr(env, enetaddr);
+}
+
+int dh_get_mac_from_eeprom(unsigned char *enetaddr, const char *alias)
+{
+ struct udevice *dev;
+ int ret;
+ ofnode node;
+
+ node = ofnode_path(alias);
+ if (!ofnode_valid(node)) {
+ printf("%s: ofnode for %s not found!", __func__, alias);
+ return -ENOENT;
+ }
+
+ ret = uclass_get_device_by_ofnode(UCLASS_I2C_EEPROM, node, &dev);
+ if (ret) {
+ printf("%s: Cannot find EEPROM! ret = %d\n", __func__, ret);
+ return ret;
+ }
+
+ ret = i2c_eeprom_read(dev, 0xfa, enetaddr, 0x6);
+ if (ret) {
+ printf("%s: Error reading EEPROM! ret = %d\n", __func__, ret);
+ return ret;
+ }
+
+ if (!is_valid_ethaddr(enetaddr)) {
+ printf("%s: Address read from EEPROM is invalid!\n", __func__);
+ return -EINVAL;
+ }
+
+ return 0;
+}
+
+__weak int dh_setup_mac_address(void)
+{
+ unsigned char enetaddr[6];
+
+ if (dh_mac_is_in_env("ethaddr"))
+ return 0;
+
+ if (!dh_get_mac_from_eeprom(enetaddr, "eeprom0"))
+ return eth_env_set_enetaddr("ethaddr", enetaddr);
+
+ printf("%s: Unable to set mac address!\n", __func__);
+ return -ENXIO;
+}