realtek: tl-sg2xxx: read MAC address from nvmem-cells
authorAlexandru Gagniuc <mr.nuke.me@gmail.com>
Sat, 20 Aug 2022 23:22:40 +0000 (18:22 -0500)
committerSander Vanheule <sander@svanheule.net>
Tue, 13 Sep 2022 07:22:26 +0000 (09:22 +0200)
The TP-Link RTL83xx based switches have their MAC address programmed
in the "para" partition. While in theory, the format of this partition
is dynamic, in practice, the MAC address appears to be located at a
consistent address. Thus, use nvmem-cells to read this MAC address.

The main MAC is required for deriving the MAC address of the switch
ports. Instead of reading it via mtd_get_mac_binary(), alias the
ethernet0 node as the label-mac-device, and use get_mac_label().

Signed-off-by: Alexandru Gagniuc <mr.nuke.me@gmail.com>
target/linux/realtek/base-files/etc/board.d/02_network
target/linux/realtek/dts-5.10/rtl8380_tplink_sg2xxx.dtsi
target/linux/realtek/dts-5.10/rtl8393_tplink_sg2452p-v4.dts

index 6e0e0e7e03422be38130149246d485f9fef77180..aacbef77b4f77b8d501d81cc91bd135f1b41cc37 100644 (file)
@@ -41,7 +41,7 @@ hpe,1920-24g)
        ;;
 tplink,sg2008p-v1|\
 tplink,sg2452p-v4)
-       label_mac=$(mtd_get_mac_binary para 0xfdff4)
+       label_mac=$(get_mac_label)
        lan_mac="$label_mac"
        ;;
 *)
index 8aa82831ab751478ed98b959332080bcb8876424..20e96af2e73e546ef7b9f77bc5e01b85ed83fa47 100644 (file)
@@ -11,6 +11,7 @@
                led-failsafe = &led_power;
                led-running = &led_power;
                led-upgrade = &led_power;
+               label-mac-device = &ethernet0;
        };
 
        memory@0 {
                                reg = <0x1b00000 0x400000>;
                        };
                        partition@1f00000 {
+                               compatible = "nvmem-cells";
                                label = "para";
                                reg = <0x1f00000 0x100000>;
+                               #address-cells = <1>;
+                               #size-cells = <1>;
                                read-only;
+
+                               factory_macaddr: macaddr@fdff4 {
+                                       reg = <0xfdff4 0x6>;
+                               };
                        };
                };
        };
 };
 
 &ethernet0 {
+       nvmem-cells = <&factory_macaddr>;
+       nvmem-cell-names = "mac-address";
+
        mdio: mdio-bus {
                compatible = "realtek,rtl838x-mdio";
                #address-cells = <1>;
index 0649c9fb37b14cd264f5cac785fdebac237b47c5..b7300cfcbee8c5ae8f9484f2833c7b422c43df50 100644 (file)
@@ -20,6 +20,7 @@
                led-failsafe = &led_sys;
                led-running = &led_sys;
                led-upgrade = &led_sys;
+               label-mac-device = &ethernet0;
        };
 
        chosen {
                                reg = <0x1b00000 0x400000>;
                        };
                        partition@1f00000 {
+                               compatible = "nvmem-cells";
                                label = "para";
                                reg = <0x1f00000 0x100000>;
+                               #address-cells = <1>;
+                               #size-cells = <1>;
                                read-only;
+
+                               factory_macaddr: macaddr@fdff4 {
+                                       reg = <0xfdff4 0x6>;
+                               };
                        };
                };
        };
 };
 
 &ethernet0 {
+       nvmem-cells = <&factory_macaddr>;
+       nvmem-cell-names = "mac-address";
+
        mdio: mdio-bus {
                compatible = "realtek,rtl838x-mdio";
                #address-cells = <1>;