diff mbox series

[12/14] test: Load mac address with i2c eeprom

Message ID 20220207234212.685316-13-sean.anderson@seco.com
State Changes Requested
Delegated to: Simon Glass
Headers show
Series Add support for NVMEM API | expand

Commit Message

Sean Anderson Feb. 7, 2022, 11:42 p.m. UTC
This uses an i2c eeprom to load a mac address using the nvmem interface.

Signed-off-by: Sean Anderson <sean.anderson@seco.com>
---

 arch/sandbox/dts/test.dts      | 9 ++++++++-
 drivers/misc/i2c_eeprom_emul.c | 4 ++++
 2 files changed, 12 insertions(+), 1 deletion(-)

Comments

Simon Glass Feb. 26, 2022, 6:37 p.m. UTC | #1
On Mon, 7 Feb 2022 at 16:42, Sean Anderson <sean.anderson@seco.com> wrote:
>
> This uses an i2c eeprom to load a mac address using the nvmem interface.
>
> Signed-off-by: Sean Anderson <sean.anderson@seco.com>
> ---
>
>  arch/sandbox/dts/test.dts      | 9 ++++++++-
>  drivers/misc/i2c_eeprom_emul.c | 4 ++++
>  2 files changed, 12 insertions(+), 1 deletion(-)
>

Reviewed-by: Simon Glass <sjg@chromium.org>
diff mbox series

Patch

diff --git a/arch/sandbox/dts/test.dts b/arch/sandbox/dts/test.dts
index e111a1f050..031fe2bf6d 100644
--- a/arch/sandbox/dts/test.dts
+++ b/arch/sandbox/dts/test.dts
@@ -517,7 +517,8 @@ 
 	eth_3: sbe5 {
 		compatible = "sandbox,eth";
 		reg = <0x10005000 0x1000>;
-		mac-address = [ 02 00 11 22 33 45 ];
+		nvmem-cells = <&eth3_addr>;
+		nvmem-cell-names = "mac-address";
 	};
 
 	eth@10004000 {
@@ -683,6 +684,8 @@ 
 		pinctrl-0 = <&pinmux_i2c0_pins>;
 
 		eeprom@2c {
+			#address-cells = <1>;
+			#size-cells = <1>;
 			reg = <0x2c>;
 			compatible = "i2c-eeprom";
 			sandbox,emul = <&emul_eeprom>;
@@ -694,6 +697,10 @@ 
 					reg = <10 2>;
 				};
 			};
+
+			eth3_addr: mac-address@24 {
+				reg = <24 6>;
+			};
 		};
 
 		rtc_0: rtc@43 {
diff --git a/drivers/misc/i2c_eeprom_emul.c b/drivers/misc/i2c_eeprom_emul.c
index 85b127c406..6f32087ede 100644
--- a/drivers/misc/i2c_eeprom_emul.c
+++ b/drivers/misc/i2c_eeprom_emul.c
@@ -171,11 +171,15 @@  static int sandbox_i2c_eeprom_probe(struct udevice *dev)
 {
 	struct sandbox_i2c_flash_plat_data *plat = dev_get_plat(dev);
 	struct sandbox_i2c_flash *priv = dev_get_priv(dev);
+	/* For eth3 */
+	const u8 mac[] = { 0x02, 0x00, 0x11, 0x22, 0x33, 0x45 };
 
 	priv->data = calloc(1, plat->size);
 	if (!priv->data)
 		return -ENOMEM;
 
+	memcpy(&priv->data[24], mac, sizeof(mac));
+
 	return 0;
 }