Skip to contentSkip to conversation

riscv: dts: spacemit: enable onboard eeprom for OrangePi

PATCH Applied Chukun Pan 3 participants 7 messages Sep 1 – Sep 15

Subsystems (3)
lore
Share & tools
lore

Chukun Pan

author
#0 lore raw

PATCH 1/1 riscv: dts: spacemit: enable onboard eeprom for OrangePi

Enable the i2c2 bus and add the connected GT24C02B EEPROM.

[   6.766] TlvInfo Header:
[   6.766]    Id String:    TlvInfo
[   6.769]    Version:      1
[   6.772]    Total Length: 38
[   6.775] TLV Name             Code Len Value
[   6.779] -------------------- ---- --- -----
[   6.783] Base MAC Address     0x24   6 .....
[   6.788] MAC Addresses        0x2A   2 2
[   6.792] Product Name         0x21  15 x1_orangepi-r2s
[   6.797] Unknown              0x41   1  0x01
[   6.801] CRC-32               0xFE   4 0xE5A74B18
[   6.806] Checksum is valid.

---
This patch depends on the following to avoid conflicts:
https://lore.kernel.org/lkml/[email protected]/

---
 .../boot/dts/spacemit/k1-orangepi-r2s.dts     | 30 ++++++++++++++++++
 .../boot/dts/spacemit/k1-orangepi-rv2.dts     | 31 +++++++++++++++++++
 2 files changed, 61 insertions(+)
arch/riscv/boot/dts/spacemit/k1-orangepi-r2s.dts +30 -0
index 2d1ba34cb00e..7125f2882ce8 100644
@@ -13,6 +13,7 @@ / {
 	compatible = "xunlong,orangepi-r2s", "spacemit,k1";
 
 	aliases {
+		i2c2 = &i2c2;
 		i2c8 = &i2c8;
 		serial0 = &uart0;
 		ethernet0 = &eth0;
@@ -112,6 +113,35 @@ rgmii1: phy@1 {
 	};
 };
 
+&i2c2 {
+	pinctrl-names = "default";
+	pinctrl-0 = <&i2c2_0_cfg>;
+	status = "okay";
+
+	eeprom@50 {
+		compatible = "atmel,24c02";
+		reg = <0x50>;
+		pagesize = <16>;
+		size = <256>;
+		read-only;
+		vcc-supply = <&buck3_1v8>;
+
+		nvmem-layout {
+			compatible = "onie,tlv-layout";
+
+			mac-address {
+				#nvmem-cell-cells = <1>;
+			};
+
+			num-macs {
+			};
+
+			product-name {
+			};
+		};
+	};
+};
+
 &i2c8 {
 	pinctrl-names = "default";
 	pinctrl-0 = <&i2c8_cfg>;
arch/riscv/boot/dts/spacemit/k1-orangepi-rv2.dts +31 -0
index f7547a4da71a..837616255464 100644
@@ -17,6 +17,8 @@ aliases {
 		serial0 = &uart0;
 		ethernet0 = &eth0;
 		ethernet1 = &eth1;
+		i2c2 = &i2c2;
+		i2c8 = &i2c8;
 		mmc0 = &emmc;
 		mmc1 = &sdhci0;
 	};
@@ -138,6 +140,35 @@ rgmii1: phy@1 {
 	};
 };
 
+&i2c2 {
+	pinctrl-names = "default";
+	pinctrl-0 = <&i2c2_0_cfg>;
+	status = "okay";
+
+	eeprom@50 {
+		compatible = "atmel,24c02";
+		reg = <0x50>;
+		pagesize = <16>;
+		size = <256>;
+		read-only;
+		vcc-supply = <&buck3_1v8>;
+
+		nvmem-layout {
+			compatible = "onie,tlv-layout";
+
+			mac-address {
+				#nvmem-cell-cells = <1>;
+			};
+
+			num-macs {
+			};
+
+			product-name {
+			};
+		};
+	};
+};
+
 &i2c8 {
 	pinctrl-names = "default";
 	pinctrl-0 = <&i2c8_cfg>;
Signature · 1 line
2.34.1
Tested-by on v1 1/1
#1 lore raw
Quoted 111 lines · Chukun Pan

Enable the i2c2 bus and add the connected GT24C02B EEPROM.

[   6.766] TlvInfo Header:
[   6.766]    Id String:    TlvInfo
[   6.769]    Version:      1
[   6.772]    Total Length: 38
[   6.775] TLV Name             Code Len Value
[   6.779] -------------------- ---- --- -----
[   6.783] Base MAC Address     0x24   6 .....
[   6.788] MAC Addresses        0x2A   2 2
[   6.792] Product Name         0x21  15 x1_orangepi-r2s
[   6.797] Unknown              0x41   1  0x01
[   6.801] CRC-32               0xFE   4 0xE5A74B18
[   6.806] Checksum is valid.

---
This patch depends on the following to avoid conflicts:
https://lore.kernel.org/lkml/[email protected]/

---
  .../boot/dts/spacemit/k1-orangepi-r2s.dts     | 30 ++++++++++++++++++
  .../boot/dts/spacemit/k1-orangepi-rv2.dts     | 31 +++++++++++++++++++
  2 files changed, 61 insertions(+)
arch/riscv/boot/dts/spacemit/k1-orangepi-r2s.dts +30 -0
index 2d1ba34cb00e..7125f2882ce8 100644
@@ -13,6 +13,7 @@ / {
  	compatible = "xunlong,orangepi-r2s", "spacemit,k1";
 
  	aliases {
+		i2c2 = &i2c2;
  		i2c8 = &i2c8;
  		serial0 = &uart0;
  		ethernet0 = &eth0;
@@ -112,6 +113,35 @@ rgmii1: phy@1 {
  	};
  };
 
+&i2c2 {
+	pinctrl-names = "default";
+	pinctrl-0 = <&i2c2_0_cfg>;
+	status = "okay";
+
+	eeprom@50 {
+		compatible = "atmel,24c02";
+		reg = <0x50>;
+		pagesize = <16>;
+		size = <256>;
+		read-only;
+		vcc-supply = <&buck3_1v8>;
+
+		nvmem-layout {
+			compatible = "onie,tlv-layout";
+
+			mac-address {
+				#nvmem-cell-cells = <1>;
+			};
+
+			num-macs {
+			};
+
+			product-name {
+			};
+		};
+	};
+};
+
  &i2c8 {
  	pinctrl-names = "default";
  	pinctrl-0 = <&i2c8_cfg>;
arch/riscv/boot/dts/spacemit/k1-orangepi-rv2.dts +24 -0
index f7547a4da71a..837616255464 100644
@@ -17,6 +17,8 @@ aliases {
  		serial0 = &uart0;
  		ethernet0 = &eth0;
  		ethernet1 = &eth1;
+		i2c2 = &i2c2;
+		i2c8 = &i2c8;
  		mmc0 = &emmc;
  		mmc1 = &sdhci0;
  	};
@@ -138,6 +140,35 @@ rgmii1: phy@1 {
  	};
  };
 
+&i2c2 {
+	pinctrl-names = "default";
+	pinctrl-0 = <&i2c2_0_cfg>;
+	status = "okay";
+
+	eeprom@50 {
+		compatible = "atmel,24c02";
+		reg = <0x50>;
+		pagesize = <16>;
+		size = <256>;
+		read-only;
+		vcc-supply = <&buck3_1v8>;
+
+		nvmem-layout {
+			compatible = "onie,tlv-layout";
+
+			mac-address {
+				#nvmem-cell-cells = <1>;
+			};
+
+			num-macs {
+			};

arch/riscv/boot/dts/spacemit/k1-orangepi-rv2.dts rgmii1: phy@1 { · line 174

Quoted 10 lines
arch/riscv/boot/dts/spacemit/k1-orangepi-rv2.dts +7 -0
+
+			product-name {
+			};
+		};
+	};
+};
+
  &i2c8 {
  	pinctrl-names = "default";
  	pinctrl-0 = <&i2c8_cfg>;

Hi Chukun,

I have tested this patch on an OrangePi RV2 with a kernel built from linux-next (next-20260904).

With the patch applied, the i2c2 bus comes up and a 24C02-compatible EEPROM (256 bytes) is probed at 2-0050. Reading the raw contents via

    hexdump -C /sys/bus/nvmem/devices/2-00500/nvmem

shows a valid ONIE TlvInfo table, and the nvmem cells (product-name, mac-address, num-macs, crc32) are properly exposed. The Product Name field reads "x1_orangepi-rv2", which matches this board.

I also tested the MAC address wiring below on top of this patch, with the nvmem-cells references added to eth0/eth1, eth0 picks up the base MAC address stored in the EEPROM and eth1 gets the base + 1; both addresses stay stable across reboots.

arch/riscv/boot/dts/spacemit/k1-orangepi-rv2.dts +0 -0
index 837616255464..44b81268c802 100644
@@ -93,6 +93,8 @@ &emmc {

};

&eth0 {
+ nvmem-cells = <&mac_address 0>;
+ nvmem-cell-names = "mac-address";
phy-handle = <&rgmii0>;
phy-mode = "rgmii-id";
pinctrl-names = "default";
@@ -117,6 +119,8 @@ rgmii0: phy@1 {
};

&eth1 {
+ nvmem-cells = <&mac_address 1>;
+ nvmem-cell-names = "mac-address";
phy-handle = <&rgmii1>;
phy-mode = "rgmii-id";
pinctrl-names = "default";

@@ -156,7 +160,7 @@ eeprom@50 {
	nvmem-layout {
	   compatible = "onie,tlv-layout";

- mac-address {

+         mac_address: mac-address {
		  #nvmem-cell-cells = <1>;
	   };

But I am not sure whether this wiring should be part of this patch. Without such wiring, the kernel falls back to random MAC addresses on this board.

Best regards,
Shuai

author
#2 lore raw

Hi,

Review

Quoted 2 lines
(quoted diff) +1 -1
-         mac-address {
+         mac_address: mac-address {

This requires removing the aliases for Ethernet.

Quoted 3 lines

But I am not sure whether this wiring should be part of this patch. Without such wiring, the kernel falls back to random MAC addresses on this board.

Currently, U-Boot patches the MAC address using the Ethernet alias from the Device Tree. The vendor U-Boot reads the MAC address from the eeprom. I think the mainline U-Boot will add this feature, so we don't need to add this one?

Thanks,
Chukun

maintainer
#3 lore raw

Hi Chukun,

Quoted 7 lines · Chukun Pan

Hi,

Review

Quoted 2 lines
(quoted diff) +1 -1
-         mac-address {
+         mac_address: mac-address {

This requires removing the aliases for Ethernet.

Quoted 9 lines
Quoted 3 lines

But I am not sure whether this wiring should be part of this patch. Without such wiring, the kernel falls back to random MAC addresses on this board.

Currently, U-Boot patches the MAC address using the Ethernet alias from the Device Tree. The vendor U-Boot reads the MAC address from the eeprom. I think the mainline U-Boot will add this feature, so we don't need to add this one?

I think it would take long time for us to get there - to have a mainline U-Boot which support parsing MAC address from eeprom. So, I have no objection to the idea of adding mac info into the dts..

Just let me know if you guys want to do in another separate patch, so I could take this patch first, or want to squash together and send an incremental
version? P.S checked k1-bananapi-cm6 board which already done as suggested..

Signature · 1 line
Yixun Lan (dlan)
author
#4 lore raw

Hi,

Quoted 3 lines

Just let me know if you guys want to do in another separate patch, so I could take this patch first, or want to squash together and send an incremental version? P.S checked k1-bananapi-cm6 board which already done as suggested..

I will send a separate patch for the MAC address.

Thanks,
Chukun

maintainer Reviewed-by on v1 1/1
#5 lore raw
In reply to Chukun Pan
Quoted 15 lines · Chukun Pan

Enable the i2c2 bus and add the connected GT24C02B EEPROM.

[   6.766] TlvInfo Header:
[   6.766]    Id String:    TlvInfo
[   6.769]    Version:      1
[   6.772]    Total Length: 38
[   6.775] TLV Name             Code Len Value
[   6.779] -------------------- ---- --- -----
[   6.783] Base MAC Address     0x24   6 .....
[   6.788] MAC Addresses        0x2A   2 2
[   6.792] Product Name         0x21  15 x1_orangepi-r2s
[   6.797] Unknown              0x41   1  0x01
[   6.801] CRC-32               0xFE   4 0xE5A74B18
[   6.806] Checksum is valid.
Quoted 9 lines

---
This patch depends on the following to avoid conflicts:
https://lore.kernel.org/lkml/[email protected]/

---
 .../boot/dts/spacemit/k1-orangepi-r2s.dts     | 30 ++++++++++++++++++
 .../boot/dts/spacemit/k1-orangepi-rv2.dts     | 31 +++++++++++++++++++
 2 files changed, 61 insertions(+)
Signature · 1 line
Yixun Lan (dlan)
maintainer Applied
#6 lore raw
In reply to Chukun Pan
Quoted 15 lines · Chukun Pan

Enable the i2c2 bus and add the connected GT24C02B EEPROM.

[   6.766] TlvInfo Header:
[   6.766]    Id String:    TlvInfo
[   6.769]    Version:      1
[   6.772]    Total Length: 38
[   6.775] TLV Name             Code Len Value
[   6.779] -------------------- ---- --- -----
[   6.783] Base MAC Address     0x24   6 .....
[   6.788] MAC Addresses        0x2A   2 2
[   6.792] Product Name         0x21  15 x1_orangepi-r2s
[   6.797] Unknown              0x41   1  0x01
[   6.801] CRC-32               0xFE   4 0xE5A74B18
[   6.806] Checksum is valid.
Quoted 1 line

[...]

Applied, thanks!

[1/1] riscv: dts: spacemit: enable onboard eeprom for OrangePi

      https://git.kernel.org/pub/scm/linux/kernel/git/spacemit/linux.git/commit/?id=ac436e6879f5bf25e971d80f96f9392b61ff54c6

Best regards,

Signature · 1 line
Yixun Lan <[email protected]>