diff --git a/machine.h b/machine.h index 22d046f..d653d66 100644 --- a/machine.h +++ b/machine.h @@ -38,4 +38,10 @@ typedef struct machine { int8_t reset_pin; }; +typedef struct machine_runtime +{ + uint8_t isRTL8373 : 1; + uint8_t isN : 1; +}; + #endif diff --git a/rtl837x_regs.h b/rtl837x_regs.h index 9f38fa7..a69b194 100644 --- a/rtl837x_regs.h +++ b/rtl837x_regs.h @@ -1,6 +1,7 @@ #ifndef _RTL837X_REGS_H_ #define _RTL837X_REGS_H_ +#define RTL837X_REG_CHIP_ID 0x0004 #define RTL837X_REG_CHIP_INFO 0x000c #define RTL837X_REG_RESET 0x0024 #define RESET_SOC_BIT 0 diff --git a/rtlplayground.c b/rtlplayground.c index 041282f..77718e9 100644 --- a/rtlplayground.c +++ b/rtlplayground.c @@ -24,6 +24,7 @@ extern __code const struct machine machine; extern __xdata uint16_t crc_value; __xdata uint8_t crc_testbytes[10]; +__xdata struct machine_runtime machine_detected; void crc16(__xdata uint8_t *v) __naked; // Upload Firmware to 1M @@ -683,7 +684,7 @@ void sds_config_mac(uint8_t sds, uint8_t mode) case 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); else sfr_data[2] &= 0x03; @@ -1098,7 +1099,7 @@ void idle(void) print_byte(linkbits_last[2]); print_byte(linkbits_last[3]); print_string(">\n"); 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_last = linkbits_last[2] >> 4; 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); // 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); } else { 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); delay(50); - if (!machine.isRTL8373) { + if (!machine_detected.isRTL8373) { // Change I2C addresses for SMI of the non-existent PHYs // r6450:000020e6 R6450-000000e6 reg_read_m(RTL837X_REG_SMI_PORT6_9_ADDR); @@ -1810,17 +1811,27 @@ void bootloader(void) // We have not detected any link linkbits_last[0] = linkbits_last[1] = linkbits_last[2] = linkbits_last[3] = linkbits_last_p89 = 0; - print_string("Detecting CPU: "); - reg_read_m(0x4); - if (sfr_data[1] == 0x73) { // Register was 0x83730000 - print_string("RTL8373\n"); - if (!machine.isRTL8373) - print_string("INCORRECT MACHINE!"); - rtl8224_enable(); // Power on the RTL8224 + machine_detected.isRTL8373 = 0; + machine_detected.isN = 0; + print_string("Detecting CPU: RTL837"); + reg_read_m(RTL837X_REG_CHIP_ID); + if (sfr_data[1] == 0x73) { // Register was 0x8373xx00 + machine_detected.isRTL8373 = 1; + write_char('3'); } else { - print_string("RTL8372\n"); - if (machine.isRTL8373) - print_string("INCORRECT MACHINE!"); + write_char('2'); + } + // 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 @@ -1840,7 +1851,7 @@ void bootloader(void) REG_SET(RTL837X_PIN_MUX_2, 0x0); // Disable pins for ACL init_smi(); rtl8373_revision(); - if (machine.isRTL8373) + if (machine_detected.isRTL8373) rtl8373_init(); else rtl8372_init();