From 59894e68cbd51991d08947e39082ef9b67d31596 Mon Sep 17 00:00:00 2001 From: logicog Date: Tue, 3 Feb 2026 19:21:08 +0100 Subject: [PATCH] Add LED-pad mapping --- machine.c | 22 +++++++++++++++ machine.h | 4 +++ rtl837x_leds.c | 72 +++++++++++++++++++++++++++++++++++++++++++++++++- rtl837x_regs.h | 7 +++++ 4 files changed, 104 insertions(+), 1 deletion(-) diff --git a/machine.c b/machine.c index 0e93a68..08f16dc 100644 --- a/machine.c +++ b/machine.c @@ -1,6 +1,7 @@ #include "machine.h" #include "rtl837x_pins.h" #include "rtl837x_leds.h" +#include "rtl837x_regs.h" #ifdef MACHINE_KP_9000_6XHML_X2 __code const struct machine machine = { @@ -35,7 +36,13 @@ __code const struct machine machine = { LEDS_1G | LEDS_LINK, 0 }, }, + .led_mux_custom = 1, + .led_mux = {0x3f, 0x3f, 0x3f, 0x3f, 0x3f, 0x3f, 0x3f, 0x3f, 0x0f, 0x0c, 0x0d, 0x0e, 0x10, 0x11, 0x12, 0x14, + 0x15, 0x16, 0x18, 0x19, 0x1a, 0x1c, 0x1d, 0x1e, 0x20, 0x21, 0x22, 0x23 }, }; + +void machine_custom_init(void) { } + #elif defined MACHINE_KP_9000_6XH_X __code const struct machine machine = { .machine_name = "keepLink KP-9000-6XH-X", @@ -64,6 +71,9 @@ __code const struct machine machine = { 0 }, }, }; + +void machine_custom_init(void) { } + #elif defined MACHINE_KP_9000_9XH_X_EU __code const struct machine machine = { .machine_name = "keepLink KP-9000-6XH-X-EU", @@ -89,6 +99,8 @@ __code const struct machine machine = { }, }; +void machine_custom_init(void) { } + #elif defined MACHINE_SWGT024_V2_0 __code const struct machine machine = { .machine_name = "SWGT024 V2.0", @@ -126,6 +138,8 @@ __code const struct machine machine = { }, }; +void machine_custom_init(void) { } + #elif defined MACHINE_HG0402XG_V1_1 __code const struct machine machine = { .machine_name = "HG0402XG V1.1", @@ -164,6 +178,8 @@ __code const struct machine machine = { }, }; +void machine_custom_init(void) { } + #elif defined DEFAULT_8C_1SFP __code const struct machine machine = { .machine_name = "8+1 SFP Port Switch", @@ -188,6 +204,9 @@ __code const struct machine machine = { LEDS_2G5 | LEDS_LINK | LEDS_ACT }, }, }; + +void machine_custom_init(void) { } + #elif defined MACHINE_TRENDNET_TEG_S562 __code const struct machine machine = { .machine_name = "Trendnet TEG-S562", @@ -210,4 +229,7 @@ __code const struct machine machine = { .sfp_port[1].i2c = { .sda = GPIO49_I2C_SDA1, .scl = GPIO48_I2C_SCL1 }, .reset_pin = GPIO_NA, }; + +void machine_custom_init(void) { } + #endif diff --git a/machine.h b/machine.h index 2532797..cba1ac8 100644 --- a/machine.h +++ b/machine.h @@ -59,6 +59,8 @@ typedef struct machine { struct high_leds high_leds; uint8_t port_led_set[9]; uint32_t led_sets[4][4]; + uint8_t led_mux_custom; + uint8_t led_mux[28]; }; typedef struct machine_runtime @@ -67,4 +69,6 @@ typedef struct machine_runtime uint8_t isN : 1; }; +void machine_custom_init(void); + #endif diff --git a/rtl837x_leds.c b/rtl837x_leds.c index c641af9..4c68f82 100644 --- a/rtl837x_leds.c +++ b/rtl837x_leds.c @@ -38,7 +38,42 @@ void leds_dump(void) __banked print_string("RTL837X_REG_LED3_0_SET1: "); print_reg(RTL837X_REG_LED3_0_SET1); write_char('\n'); print_string("RTL837X_REG_LED3_0_SET3: "); print_reg(RTL837X_REG_LED3_0_SET3); write_char('\n'); print_string("RTL837X_LED_PORT_SET_SEL: "); print_reg(RTL837X_LED_PORT_SET_SEL); write_char('\n'); - print_string("LED Configuration:\n"); + print_string("RTL837X_REG_LED_GLB_MUX_1: "); print_reg(RTL837X_REG_LED_GLB_MUX_1); write_char('\n'); + print_string("RTL837X_REG_LED_GLB_MUX_2: "); print_reg(RTL837X_REG_LED_GLB_MUX_2); write_char('\n'); + print_string("RTL837X_REG_LED_GLB_MUX_3: "); print_reg(RTL837X_REG_LED_GLB_MUX_3); write_char('\n'); + print_string("RTL837X_REG_LED_GLB_MUX_4: "); print_reg(RTL837X_REG_LED_GLB_MUX_4); write_char('\n'); + print_string("RTL837X_REG_LED_GLB_MUX_5: "); print_reg(RTL837X_REG_LED_GLB_MUX_5); write_char('\n'); + print_string("RTL837X_REG_LED_GLB_MUX_6: "); print_reg(RTL837X_REG_LED_GLB_MUX_6); write_char('\n'); + print_string("RTL837X_REG_LED_GLB_ACTIVE: "); print_reg(RTL837X_REG_LED_GLB_ACTIVE); write_char('\n'); + print_string("LED pad Configuration:\n"); + for (uint8_t i = 0; i < 28; i++) { + print_byte(i); + write_char(' '); + } + write_char('\n'); + for (uint8_t i = 0; i < 28; i++) { + switch (i % 5) { + case 0: // 0 + reg_read_m(RTL837X_REG_LED_GLB_MUX_1 + (i / 5) * 4); + print_byte(sfr_data[3] & 0x3f); + break; + case 1: // 6 + print_byte(((sfr_data[3] >> 6) | (sfr_data[2] << 2)) & 0x3f); + break; + case 2: // 12 + print_byte(((sfr_data[1] << 4) | (sfr_data[2] >> 4)) & 0x3f); + break; + case 3: // 18 + print_byte((sfr_data[1] >> 2) & 0x3f); + break; + case 4: // 24 + print_byte(sfr_data[0] & 0x3f); + break; + } + write_char(' '); + } + write_char('\n'); + print_string("LED-set Configuration:\n"); print_string("LED-ID\t\t0\t\t1\t\t2\t\t3\n"); for (__xdata uint8_t set = 0; set < 4; set++) { print_string("SET "); write_char('0' + set); write_char(':'); @@ -181,6 +216,38 @@ void leds_setup(void) __banked reg_bit_clear(RTL837X_REG_LED_GLB_IO_EN, 29); + // Configure the LED-mux + if (machine.led_mux_custom) { + print_string("Configuring custom LED-muxes: "); + for (uint8_t i = 0; i < 28; i++) { + switch (i % 5) { + case 0: // 0 + sfr_data[3] = machine.led_mux[i]; + break; + case 1: // 6 + sfr_data[3] |= machine.led_mux[i] << 6; + sfr_data[2] = machine.led_mux[i] >> 2; + break; + case 2: // 12 + sfr_data[2] |= machine.led_mux[i] << 4; + sfr_data[1] = machine.led_mux[i] >> 4; + break; + case 3: // 18 + sfr_data[1] |= machine.led_mux[i] << 2; + break; + case 4: // 24 + sfr_data[0] = machine.led_mux[i]; + print_sfr_data(); write_char(' '); + reg_write_m(RTL837X_REG_LED_GLB_MUX_1 + (i / 5) * 4); + break; + } + write_char(' '); + } + sfr_data[0] = 0; sfr_data[1] &= 0xf; + print_sfr_data(); write_char('\n'); + reg_write_m(RTL837X_REG_LED_GLB_MUX_6); + } + // Configure the LED-set of a port sfr_data[3] = sfr_data[2] = sfr_data[1] = sfr_data[0] = 0; for (uint8_t i = machine.min_port; i <= machine.max_port; i++) @@ -188,6 +255,9 @@ void leds_setup(void) __banked reg_write_m(RTL837X_LED_PORT_SET_SEL); // Configure the LED-sets + sfr_data[3] = sfr_data[2] = sfr_data[1] = sfr_data[0] = 0; + reg_write_m(RTL837X_REG_LED3_0_SET1); + reg_write_m(RTL837X_REG_LED3_0_SET3); __code uint8_t * __xdata lptr = &machine.led_sets[0][0]; for (__xdata uint8_t set = 0; set < 4; set++) { sfr_data[0] = *(lptr + 5); diff --git a/rtl837x_regs.h b/rtl837x_regs.h index 6232a42..32e7a98 100644 --- a/rtl837x_regs.h +++ b/rtl837x_regs.h @@ -22,6 +22,13 @@ // BIT 17 set: LED solid on // Bytes 0/1 hold the LED mode, e.g. serial, RTL8231? // Blink rate is defined by setAsicRegBits(0x6520,0xe00000,rate); +#define RTL837X_REG_LED_GLB_MUX_1 0x65E0 +#define RTL837X_REG_LED_GLB_MUX_2 0x65E4 +#define RTL837X_REG_LED_GLB_MUX_3 0x65E8 +#define RTL837X_REG_LED_GLB_MUX_4 0x65EC +#define RTL837X_REG_LED_GLB_MUX_5 0x65F0 +#define RTL837X_REG_LED_GLB_MUX_6 0x65F4 +#define RTL837X_REG_LED_GLB_ACTIVE 0x65D8 #define RTL837X_REG_LED_GLB_IO_EN 0x65DC #define RTL837X_REG_LED3_0_SET3 0x6524 #define RTL837X_REG_LED3_0_SET1 0x6528