realtek: rt-loader: fix RTL839x/RTL93xx version detection

There is a misunderstanding of the chip version detection in the
rt-loader. For all SoCs the data is gathered from the registers
MODEL_NAME_INFO and CHIP_INFO. Sadly the bits are shuffled around
with each hardware. Currently the loader gathers the wrong bits
for RTL839x and RTL93xx. Fix that.

While we are here write the if statements vice versa for better
readability and give some variables better names. Align the
ouput with that from the kernel.

Fixes: ccbff8b ("realtek: add rt-loader (runtime loader)"
Signed-off-by: Markus Stockhausen <markus.stockhausen@gmx.de>
Link: https://github.com/openwrt/openwrt/pull/21994
Signed-off-by: Robert Marko <robimarko@gmail.com>
This commit is contained in:
Markus Stockhausen 2026-02-11 22:08:17 +01:00 committed by Robert Marko
parent 8b9bd686e7
commit 086f1d3478
2 changed files with 19 additions and 20 deletions

View file

@ -65,42 +65,41 @@ unsigned int board_get_memory(void)
void board_get_system(char *buffer, int len)
{
unsigned int chip_id, model_id, model_version, chip_version;
unsigned int reg, val, act;
unsigned int reg, act, minfo, cinfo;
act = RTL93XX_CHIP_INFO_EN;
reg = RTL93XX_MODEL_NAME_INFO_REG;
val = ioread32(reg);
minfo = ioread32(reg);
if ((val & 0xffec0000) == 0x93000000)
if ((minfo & 0xffec0000) == 0x93000000)
goto found;
act = RTL83XX_CHIP_INFO_EN;
reg = RTL839X_MODEL_NAME_INFO_REG;
val = ioread32(reg);
if ((val & 0xfff80000) == 0x83900000)
minfo = ioread32(reg);
if ((minfo & 0xfff80000) == 0x83900000)
goto found;
iowrite32(0x3, RTL838X_INT_RW_CTRL_REG);
reg = RTL838X_MODEL_NAME_INFO_REG;
val = ioread32(reg);
minfo = ioread32(reg);
found:
model_id = val >> 16;
model_version = (val >> 11) & 0x1f;
iowrite32(act, reg + 4);
val = ioread32(reg + 4);
chip_id = val & 0xffff;
cinfo = ioread32(reg + 4);
if (model_id < 0x8390)
chip_version = (val >> 16) & 0x1f;
else if (model_id < 0x9300)
chip_version = ((val >> 16) & 0x1f) + 1;
model_id = minfo >> 16;
model_version = (minfo >> 11) & 0x1f;
chip_id = cinfo & 0xffff;
if (model_id >= 0x9300)
chip_version = minfo & 0xf;
else if (model_id >= 0x8390)
chip_version = (minfo >> 1) & 0x1f;
else
chip_version = ((val >> 28) & 0x0f) + 1;
chip_version = ((cinfo >> 16) & 0x1f) - 1;
snprintf(buffer, len, "RTL%04X%c (chip id %04x%c)",
model_id, model_version ? model_version + 64 : 0,
chip_id, chip_version ? chip_version + 64 : 0);
snprintf(buffer, len, "RTL%04X%c rev %c (%04x)", model_id,
model_version ? model_version + 64 : 0, chip_version + 65, chip_id);
}
/*

View file

@ -90,7 +90,7 @@ void welcome(void)
board_get_system(system, sizeof(system));
printf("\nrt-loader\n");
printf("Running on %s with %dMB\n", system, board_get_memory() >> 20);
printf("Running on %s SoC with %d MB\n", system, board_get_memory() >> 20);
}
void decompress_error(char *x)