]> git.ipfire.org Git - thirdparty/openwrt.git/commitdiff
realtek: extend SoC information 19653/head
authorJan Hoffmann <jan@3e8.eu>
Sat, 2 Aug 2025 18:31:39 +0000 (20:31 +0200)
committerRobert Marko <robimarko@gmail.com>
Wed, 6 Aug 2025 11:41:51 +0000 (13:41 +0200)
Add SoC revision, CPU part number, and a flag for engineering samples to
the rtl83xx_soc_info structure.

Also extend the system type string to include this information.

Signed-off-by: Jan Hoffmann <jan@3e8.eu>
Link: https://github.com/openwrt/openwrt/pull/19653
Signed-off-by: Robert Marko <robimarko@gmail.com>
target/linux/realtek/files-6.12/arch/mips/include/asm/mach-rtl838x/mach-rtl83xx.h
target/linux/realtek/files-6.12/arch/mips/rtl838x/prom.c

index e611b7aebc9f657d8898f9ccb03b96415375db23..263f246275f41f15e701f20d4304420560ea97ac 100644 (file)
@@ -7,6 +7,8 @@
 #define _MACH_RTL838X_H_
 
 #include <asm/types.h>
+#include <linux/types.h>
+
 /*
  * Register access macros
  */
@@ -393,6 +395,9 @@ struct rtl83xx_soc_info {
        unsigned char *name;
        unsigned int id;
        unsigned int family;
+       unsigned int revision;
+       unsigned int cpu;
+       bool testchip;
        unsigned char *compatible;
        volatile void *sw_base;
        volatile void *icu_base;
index 32e7a064fef651961f6b94001b16df93e6c4d271..fe2d86883d5ea4abd38fbec473eba7790896b794 100644 (file)
@@ -21,7 +21,7 @@ struct rtl83xx_soc_info soc_info;
 const void *fdt;
 
 static char soc_name[16];
-static char rtl83xx_system_type[32];
+static char rtl83xx_system_type[48];
 
 #ifdef CONFIG_MIPS_MT_SMP
 
@@ -102,6 +102,62 @@ const char *get_system_type(void)
        return rtl83xx_system_type;
 }
 
+static void __init rtl838x_read_details(uint32_t model)
+{
+       uint32_t chip_info, ext_version, tmp;
+
+       sw_w32(0x3, RTL838X_INT_RW_CTRL);
+       sw_w32(0xa << 28, RTL838X_CHIP_INFO);
+
+       chip_info = sw_r32(RTL838X_CHIP_INFO);
+       soc_info.cpu = chip_info & 0xffff;
+
+       ext_version = sw_r32(RTL838X_EXT_VERSION);
+       tmp = ext_version & 0x1f;
+
+       if (tmp == 2) {
+               soc_info.revision = 1;
+       } else {
+               tmp = (chip_info >> 16) & 0x1f;
+               if (soc_info.cpu == 0x0477) {
+                       soc_info.revision = tmp;
+                       soc_info.testchip = true;
+               } else {
+                       soc_info.revision = tmp - 1;
+               }
+       }
+}
+
+static void __init rtl839x_read_details(uint32_t model)
+{
+       uint32_t chip_info;
+
+       sw_w32(0xa << 28, RTL839X_CHIP_INFO);
+
+       chip_info = sw_r32(RTL839X_CHIP_INFO);
+       soc_info.cpu = chip_info & 0xffff;
+
+       soc_info.revision = (model >> 1) & 0x1f;
+
+       if (!(model & 0x3e))
+               soc_info.testchip = true;
+}
+
+static void __init rtl93xx_read_details(uint32_t model)
+{
+       uint32_t chip_info;
+
+       sw_w32(0xa << 16, RTL93XX_CHIP_INFO);
+
+       chip_info = sw_r32(RTL93XX_CHIP_INFO);
+       soc_info.cpu = chip_info & 0xffff;
+
+       soc_info.revision = model & 0xf;
+
+       if (model & 0x30)
+               soc_info.testchip = true;
+}
+
 static uint32_t __init read_model(void)
 {
        uint32_t model, id;
@@ -111,6 +167,7 @@ static uint32_t __init read_model(void)
        if ((id >= 0x8380 && id <= 0x8382) || id == 0x8330 || id == 0x8332) {
                soc_info.id = id;
                soc_info.family = RTL8380_FAMILY_ID;
+               rtl838x_read_details(model);
                return model;
        }
 
@@ -119,6 +176,7 @@ static uint32_t __init read_model(void)
        if ((id >= 0x8391 && id <= 0x8396) || (id >= 0x8351 && id <= 0x8353)) {
                soc_info.id = id;
                soc_info.family = RTL8390_FAMILY_ID;
+               rtl839x_read_details(model);
                return model;
        }
 
@@ -127,10 +185,12 @@ static uint32_t __init read_model(void)
        if (id >= 0x9301 && id <= 0x9303) {
                soc_info.id = id;
                soc_info.family = RTL9300_FAMILY_ID;
+               rtl93xx_read_details(model);
                return model;
        } else if (id >= 0x9311 && id <= 0x9313) {
                soc_info.id = id;
                soc_info.family = RTL9310_FAMILY_ID;
+               rtl93xx_read_details(model);
                return model;
        }
 
@@ -153,8 +213,18 @@ static void __init parse_model(uint32_t model)
 }
 
 static void __init rtl83xx_set_system_type(void) {
+       char revision = '?';
+       char *es = "";
+
+       if (soc_info.revision >= 0 && soc_info.revision < 26)
+               revision = 'A' + soc_info.revision;
+
+       if (soc_info.testchip)
+               es = " ES";
+
        snprintf(rtl83xx_system_type, sizeof(rtl83xx_system_type),
-                "Realtek %s", soc_info.name);
+                "Realtek %s%s rev %c (%04X)",
+                soc_info.name, es, revision, soc_info.cpu);
 }
 
 void __init prom_init(void)