From 6af072eb2c5e382672d750115ffc02f330a5c9d6 Mon Sep 17 00:00:00 2001 From: logicog Date: Sun, 1 Feb 2026 11:42:43 +0100 Subject: [PATCH] Add LED configuration in machine profile --- machine.c | 66 +++++++++++++++++++++++++++++++++++++++++++++++++++++++ machine.h | 15 +++++++++++++ 2 files changed, 81 insertions(+) diff --git a/machine.c b/machine.c index aaa5303..0e93a68 100644 --- a/machine.c +++ b/machine.c @@ -1,5 +1,6 @@ #include "machine.h" #include "rtl837x_pins.h" +#include "rtl837x_leds.h" #ifdef MACHINE_KP_9000_6XHML_X2 __code const struct machine machine = { @@ -22,6 +23,18 @@ __code const struct machine machine = { .sfp_port[1].sds = 1, .sfp_port[1].i2c = { .sda = GPIO39_I2C_SDA4, .scl = GPIO40_I2C_SCL3_MDC1 }, .reset_pin = GPIO46_I2C_SCL0, + .high_leds = { .mux = LED_27 | LED_29, .enable = LED_28 | LED_29 }, + .port_led_set = { 0, 0, 0, 0, 0, 0, 0, 0, 0}, + /* Conditions for LED on: + * dual led orange: ledset_0 & ledset_2 + * dual led green: ledset_2 & !ledset_0 + * single right led green: ledset_0 & !ledset_1 + */ + .led_sets = { { LEDS_2G5 | LEDS_1G | LEDS_100M | LEDS_10M | LEDS_LINK | LEDS_ACT | LEDS_10G, + LEDS_2G5 | LEDS_LINK | LEDS_10G, + LEDS_1G | LEDS_LINK, + 0 }, + }, }; #elif defined MACHINE_KP_9000_6XH_X __code const struct machine machine = { @@ -37,8 +50,19 @@ __code const struct machine machine = { .sfp_port[0].pin_los = GPIO37, .sfp_port[0].pin_tx_disable = GPIO_NA, .sfp_port[0].sds = 1, + .sfp_port[0].i2c_bus = { .sda = 4, .scl = 3 }, .sfp_port[0].i2c = { .sda = GPIO39_I2C_SDA4, .scl = GPIO40_I2C_SCL3_MDC1 }, .reset_pin = GPIO_NA, + /* Conditions for LED on: + * dual led orange: ledset_0 & ledset_2 + * dual led green: ledset_2 & !ledset_0 + * single right led green: ledset_0 & !ledset_1 + */ + .led_sets = { { LEDS_2G5 | LEDS_1G | LEDS_100M | LEDS_10M | LEDS_LINK | LEDS_ACT | LEDS_10G, + LEDS_2G5 | LEDS_LINK | LEDS_10G, + LEDS_1G | LEDS_LINK, + 0 }, + }, }; #elif defined MACHINE_KP_9000_9XH_X_EU __code const struct machine machine = { @@ -56,6 +80,13 @@ __code const struct machine machine = { .sfp_port[0].sds = 1, .sfp_port[0].i2c = { .sda = GPIO39_I2C_SDA4, .scl = GPIO40_I2C_SCL3_MDC1 }, .reset_pin = GPIO_NA, + .high_leds = { .mux = LED_27 | LED_29, .enable = LED_28 | LED_29 }, + .port_led_set = { 0, 0, 0, 0, 0, 0, 0, 0, 0}, + .led_sets = { { LEDS_2G5 | LEDS_TWO_PAIR_1G | LEDS_1G | LEDS_500M | LEDS_100M | LEDS_10M | LEDS_LINK | LEDS_ACT | LEDS_10G | LEDS_TWO_PAIR_5G | LEDS_5G | LEDS_TWO_PAIR_2G5, + LEDS_2G5 | LEDS_LINK, + LEDS_1G | LEDS_LINK, + LEDS_2G5 | LEDS_LINK | LEDS_ACT }, + }, }; #elif defined MACHINE_SWGT024_V2_0 @@ -81,6 +112,18 @@ __code const struct machine machine = { .sfp_port[1].sds = 0, .sfp_port[1].i2c = { .sda = GPIO41_I2C_SDA3_MDIO1, .scl = GPIO40_I2C_SCL3_MDC1 }, /* GPIO 40 */ .reset_pin = GPIO36_PWM_OUT, + .high_leds = { .mux = LED_27 | LED_29, .enable = LED_28 | LED_29 }, + .port_led_set = { 0, 0, 0, 0, 0, 0, 0, 0, 0}, + /* Conditions for LED on: + * dual led orange: ledset_0 & ledset_2 + * dual led green: ledset_2 & !ledset_0 + * single right led green: ledset_0 & !ledset_1 + */ + .led_sets = { { LEDS_2G5 | LEDS_1G | LEDS_100M | LEDS_10M | LEDS_LINK | LEDS_ACT | LEDS_10G, + LEDS_2G5 | LEDS_LINK | LEDS_10G, + LEDS_1G | LEDS_LINK, + 0 }, + }, }; #elif defined MACHINE_HG0402XG_V1_1 @@ -103,6 +146,22 @@ __code const struct machine machine = { .sfp_port[1].pin_tx_disable = 0xFF, .sfp_port[1].sds = 0, .sfp_port[1].i2c_bus = { .sda = GPIO39_I2C_SDA4, .scl = GPIO40_I2C_SCL3_MDC1 }, + .reset_pin = GPIO_NA, + .high_leds = { .mux = LED_27 , .enable = LED_27 | LED_29 }, + .port_led_set = { 0, 0, 0, 1, 0, 0, 0, 0, 1}, + /* The Ethernet ports have 1 amber LED (left) and 1 green LED (right) + * The SFP ports have also 1 amber LED and 1 green LED + * Ethernet ports use LED-set 0, SFP ports use LED-set 1 + */ + .led_sets = { { LEDS_10M | LEDS_LINK | LEDS_ACT, + LEDS_1G | LEDS_100M | LEDS_10M | LEDS_2G5 | LEDS_LINK | LEDS_ACT, + LEDS_2G5 | LEDS_LINK | LEDS_ACT, + 0 }, + { LEDS_100M | LEDS_10M | LEDS_LINK, + LEDS_2G5 | LEDS_1G | LEDS_100M | LEDS_10M | LEDS_10M | LEDS_LINK | LEDS_ACT | LEDS_10G, + LEDS_10G | LEDS_LINK, + 0 }, + }, }; #elif defined DEFAULT_8C_1SFP @@ -121,6 +180,13 @@ __code const struct machine machine = { .sfp_port[0].sds = 1, .sfp_port[0].i2c = { .sda = GPIO39_I2C_SDA4, .scl = GPIO40_I2C_SCL3_MDC1 }, .reset_pin = GPIO_NA, + .high_leds = { .mux = LED_27 | LED_29, .enable = LED_28 | LED_29 }, + .port_led_set = { 0, 0, 0, 0, 0, 0, 0, 0, 0}, + .led_sets = { { LEDS_2G5 | LEDS_TWO_PAIR_1G | LEDS_1G | LEDS_500M | LEDS_100M | LEDS_10M | LEDS_LINK | LEDS_ACT | LEDS_10G | LEDS_TWO_PAIR_5G | LEDS_5G | LEDS_TWO_PAIR_2G5, + LEDS_2G5 | LEDS_LINK, + LEDS_1G | LEDS_LINK, + LEDS_2G5 | LEDS_LINK | LEDS_ACT }, + }, }; #elif defined MACHINE_TRENDNET_TEG_S562 __code const struct machine machine = { diff --git a/machine.h b/machine.h index 5bb02ce..2532797 100644 --- a/machine.h +++ b/machine.h @@ -23,6 +23,18 @@ typedef struct { uint8_t scl; } i2c_bus_t; + +#define LED_27 1 +#define LED_28 2 +#define LED_29 4 + +struct high_leds { + // Defines MUX and LED enabling for pins 27-29 + uint8_t mux : 3; + uint8_t enable : 3; + uint8_t reserved : 2; +}; + struct sfp_port { uint8_t pin_detect; // gpio number 0-63, 0xFF = don't have it? @@ -44,6 +56,9 @@ typedef struct machine { // sfp_port[0] is the first SFP-port from the left on the device, sfp_port[1] the next if present struct sfp_port sfp_port[2]; int8_t reset_pin; + struct high_leds high_leds; + uint8_t port_led_set[9]; + uint32_t led_sets[4][4]; }; typedef struct machine_runtime