Detect SOC type and use detected SOC type to init the hardware.

Detect the SOC type and variant. RTL8372 vs RTL8373 and also is it as
non-N/N variant of the SOC.
Even if the machine profile is wrong the hardware will be initilised on
the detected type.
This commit is contained in:
René van Dorst
2026-01-25 16:55:43 +01:00
parent 17b428a603
commit aa750d8ff1
3 changed files with 33 additions and 15 deletions
+6
View File
@@ -38,4 +38,10 @@ typedef struct machine {
int8_t reset_pin; int8_t reset_pin;
}; };
typedef struct machine_runtime
{
uint8_t isRTL8373 : 1;
uint8_t isN : 1;
};
#endif #endif
+1
View File
@@ -1,6 +1,7 @@
#ifndef _RTL837X_REGS_H_ #ifndef _RTL837X_REGS_H_
#define _RTL837X_REGS_H_ #define _RTL837X_REGS_H_
#define RTL837X_REG_CHIP_ID 0x0004
#define RTL837X_REG_CHIP_INFO 0x000c #define RTL837X_REG_CHIP_INFO 0x000c
#define RTL837X_REG_RESET 0x0024 #define RTL837X_REG_RESET 0x0024
#define RESET_SOC_BIT 0 #define RESET_SOC_BIT 0
+26 -15
View File
@@ -24,6 +24,7 @@ extern __code const struct machine machine;
extern __xdata uint16_t crc_value; extern __xdata uint16_t crc_value;
__xdata uint8_t crc_testbytes[10]; __xdata uint8_t crc_testbytes[10];
__xdata struct machine_runtime machine_detected;
void crc16(__xdata uint8_t *v) __naked; void crc16(__xdata uint8_t *v) __naked;
// Upload Firmware to 1M // Upload Firmware to 1M
@@ -683,7 +684,7 @@ void sds_config_mac(uint8_t sds, uint8_t mode)
case 2: case 2:
sfr_mask_data(1, 0xfc, 0x02 << 2); sfr_mask_data(1, 0xfc, 0x02 << 2);
} }
if (machine.isRTL8373) // Set 3rd SERDES Mode to 0x2 for RTL8224 if (machine_detected.isRTL8373) // Set 3rd SERDES Mode to 0x2 for RTL8224
sfr_mask_data(1, 0xfc, 0x02 << 2); sfr_mask_data(1, 0xfc, 0x02 << 2);
else else
sfr_data[2] &= 0x03; sfr_data[2] &= 0x03;
@@ -1098,7 +1099,7 @@ void idle(void)
print_byte(linkbits_last[2]); print_byte(linkbits_last[3]); print_byte(linkbits_last[2]); print_byte(linkbits_last[3]);
print_string(">\n"); print_string(">\n");
linkbits_last_p89 = linkbits_p89; linkbits_last_p89 = linkbits_p89;
if (!machine.isRTL8373 && machine.n_sfp != 2) { if (!machine_detected.isRTL8373 && machine.n_sfp != 2) {
uint8_t p5 = sfr_data[2] >> 4; uint8_t p5 = sfr_data[2] >> 4;
uint8_t p5_last = linkbits_last[2] >> 4; uint8_t p5_last = linkbits_last[2] >> 4;
cpy_4(linkbits_last, sfr_data); cpy_4(linkbits_last, sfr_data);
@@ -1678,7 +1679,7 @@ void init_smi(void)
REG_SET(RTL837X_REG_SMI_MAC_TYPE, machine.n_sfp == 2 ? 0x00005515 : 0x00005555); REG_SET(RTL837X_REG_SMI_MAC_TYPE, machine.n_sfp == 2 ? 0x00005515 : 0x00005555);
// Configure polling of all PHYs by the MAC to detect link-state changes // Configure polling of all PHYs by the MAC to detect link-state changes
if (machine.isRTL8373) { if (machine_detected.isRTL8373) {
REG_SET(RTL837X_REG_SMI_PORT_POLLING, 0xff); REG_SET(RTL837X_REG_SMI_PORT_POLLING, 0xff);
} else { } else {
REG_SET(RTL837X_REG_SMI_PORT_POLLING, machine.n_sfp == 2 ? 0xf0 : 0x1f8); REG_SET(RTL837X_REG_SMI_PORT_POLLING, machine.n_sfp == 2 ? 0xf0 : 0x1f8);
@@ -1689,7 +1690,7 @@ void init_smi(void)
reg_write_m(RTL837X_REG_SMI_CTRL); reg_write_m(RTL837X_REG_SMI_CTRL);
delay(50); delay(50);
if (!machine.isRTL8373) { if (!machine_detected.isRTL8373) {
// Change I2C addresses for SMI of the non-existent PHYs // Change I2C addresses for SMI of the non-existent PHYs
// r6450:000020e6 R6450-000000e6 // r6450:000020e6 R6450-000000e6
reg_read_m(RTL837X_REG_SMI_PORT6_9_ADDR); reg_read_m(RTL837X_REG_SMI_PORT6_9_ADDR);
@@ -1810,17 +1811,27 @@ void bootloader(void)
// We have not detected any link // We have not detected any link
linkbits_last[0] = linkbits_last[1] = linkbits_last[2] = linkbits_last[3] = linkbits_last_p89 = 0; linkbits_last[0] = linkbits_last[1] = linkbits_last[2] = linkbits_last[3] = linkbits_last_p89 = 0;
print_string("Detecting CPU: "); machine_detected.isRTL8373 = 0;
reg_read_m(0x4); machine_detected.isN = 0;
if (sfr_data[1] == 0x73) { // Register was 0x83730000 print_string("Detecting CPU: RTL837");
print_string("RTL8373\n"); reg_read_m(RTL837X_REG_CHIP_ID);
if (!machine.isRTL8373) if (sfr_data[1] == 0x73) { // Register was 0x8373xx00
print_string("INCORRECT MACHINE!"); machine_detected.isRTL8373 = 1;
rtl8224_enable(); // Power on the RTL8224 write_char('3');
} else { } else {
print_string("RTL8372\n"); write_char('2');
if (machine.isRTL8373) }
print_string("INCORRECT MACHINE!"); // Detect non-N/N chip, 0xxxxx70xx
if (sfr_data[2] == 0x70) {
machine_detected.isN = 1;
write_char('N');
}
write_char('\n');
if (machine.isRTL8373 != machine_detected.isRTL8373) {
print_string("INCORRECT MACHINE!");
}
if (machine_detected.isRTL8373) {
rtl8224_enable(); // Power on the RTL8224
} }
// Print SW version // Print SW version
@@ -1840,7 +1851,7 @@ void bootloader(void)
REG_SET(RTL837X_PIN_MUX_2, 0x0); // Disable pins for ACL REG_SET(RTL837X_PIN_MUX_2, 0x0); // Disable pins for ACL
init_smi(); init_smi();
rtl8373_revision(); rtl8373_revision();
if (machine.isRTL8373) if (machine_detected.isRTL8373)
rtl8373_init(); rtl8373_init();
else else
rtl8372_init(); rtl8372_init();