summaryrefslogtreecommitdiff
path: root/net
diff options
context:
space:
mode:
authorTom Rini <[email protected]>2022-06-09 15:20:11 -0400
committerTom Rini <[email protected]>2022-06-09 15:20:11 -0400
commite5028bb227c578ca89273f0b1e0d289ec1987d2f (patch)
treea9b8552bc82bd10d9b0638113c2ed65b87a892d7 /net
parentc0e63bf46848d573b3ef86d5796f8f993c316ed6 (diff)
parent3f51ba926bc138f54dab8d0fa0c363a3b1e71794 (diff)
Merge branch '2022-06-09-add-support-for-nvmem-api' into next
To quote the author: This adds support for the nvmem-cells properties cropping up in manyb device trees. This is an easy way to load configuration, version information, or calibration data from a non-volatile memory source. For more information, refer to patch 6 ("misc: Add support for nvmem cells"). For the moment I have only added some integration tests using the ethernet addresses. This hits the main code paths (looking up nvmem cells) but doesn't test writing. I can add a few stand-alone tests if desired.
Diffstat (limited to 'net')
-rw-r--r--net/dsa-uclass.c6
-rw-r--r--net/eth-uclass.c13
2 files changed, 13 insertions, 6 deletions
diff --git a/net/dsa-uclass.c b/net/dsa-uclass.c
index 9ff55a02fb2..3bf4351c847 100644
--- a/net/dsa-uclass.c
+++ b/net/dsa-uclass.c
@@ -477,8 +477,10 @@ static int dsa_pre_probe(struct udevice *dev)
return -ENODEV;
}
- uclass_find_device_by_ofnode(UCLASS_ETH, pdata->master_node,
- &priv->master_dev);
+ err = uclass_get_device_by_ofnode(UCLASS_ETH, pdata->master_node,
+ &priv->master_dev);
+ if (err)
+ return err;
/* Simulate a probing event for the CPU port */
if (ops->port_probe) {
diff --git a/net/eth-uclass.c b/net/eth-uclass.c
index bcefc54ded8..0f6b45b002c 100644
--- a/net/eth-uclass.c
+++ b/net/eth-uclass.c
@@ -14,6 +14,7 @@
#include <env.h>
#include <log.h>
#include <net.h>
+#include <nvmem.h>
#include <asm/global_data.h>
#include <dm/device-internal.h>
#include <dm/uclass-internal.h>
@@ -507,17 +508,21 @@ static bool eth_dev_get_mac_address(struct udevice *dev, u8 mac[ARP_HLEN])
{
#if CONFIG_IS_ENABLED(OF_CONTROL)
const uint8_t *p;
+ struct nvmem_cell mac_cell;
p = dev_read_u8_array_ptr(dev, "mac-address", ARP_HLEN);
if (!p)
p = dev_read_u8_array_ptr(dev, "local-mac-address", ARP_HLEN);
- if (!p)
- return false;
+ if (p) {
+ memcpy(mac, p, ARP_HLEN);
+ return true;
+ }
- memcpy(mac, p, ARP_HLEN);
+ if (nvmem_cell_get_by_name(dev, "mac-address", &mac_cell))
+ return false;
- return true;
+ return !nvmem_cell_read(&mac_cell, mac, ARP_HLEN);
#else
return false;
#endif