From 9c7572b28942b57018607a8bb340cb3193d7f6e4 Mon Sep 17 00:00:00 2001 From: logicog Date: Sun, 2 Nov 2025 09:49:13 +0100 Subject: [PATCH] De-Magic I2C configuration for SFP-EEPROM reads --- rtl837x_common.h | 6 +++++- rtl837x_regs.h | 10 +++++++--- rtlplayground.c | 11 ++++++----- 3 files changed, 18 insertions(+), 9 deletions(-) diff --git a/rtl837x_common.h b/rtl837x_common.h index c04fbb3..29f6536 100644 --- a/rtl837x_common.h +++ b/rtl837x_common.h @@ -5,7 +5,11 @@ #include // This has to be set to the number of SFP+ ports, i.e. 1 or 2 -#define NSFP 2 +#define NSFP 2 +// SCL and SDA pin numbers for SFP cage 0 and SFP cage 1 +#define SCL_PIN 3 +#define SDA_PIN_0 4 +#define SDA_PIN_1 3 // Define Port-masks for 9-port devices and 6-port devices #define PMASK_9 0x1ff diff --git a/rtl837x_regs.h b/rtl837x_regs.h index 4c47761..754b98c 100644 --- a/rtl837x_regs.h +++ b/rtl837x_regs.h @@ -66,9 +66,13 @@ /* * I2C controller */ -#define RTL837X_REG_I2C_CTRL 0x0418 -#define RTL837X_REG_I2C_IN 0x0420 -#define RTL837X_REG_I2C_OUT 0x0424 +#define RTL837X_REG_I2C_MST_IF_CTRL 0x0414 +#define RTL837X_REG_I2C_CTRL 0x0418 +#define I2C_DEV_ADDR 3 +#define I2C_MEM_ADDR_WIDTH 20 +#define RTL837X_REG_I2C_CTRL2 0x041c +#define RTL837X_REG_I2C_IN 0x0420 +#define RTL837X_REG_I2C_OUT 0x0424 /* * NIC Related registers diff --git a/rtlplayground.c b/rtlplayground.c index 7018fcb..960396b 100644 --- a/rtlplayground.c +++ b/rtlplayground.c @@ -725,11 +725,11 @@ uint8_t sfp_read_reg(uint8_t slot, uint8_t reg) { if (slot == 0) { reg_read_m(RTL837X_REG_I2C_CTRL); - sfr_mask_data(1, 0xff, 0x72); + sfr_mask_data(1, 0xfc, SCL_PIN << 5 | SDA_PIN_0 << 2); reg_write_m(RTL837X_REG_I2C_CTRL); } else { reg_read_m(RTL837X_REG_I2C_CTRL); - sfr_mask_data(1, 0xff, 0x6e); + sfr_mask_data(1, 0xfc, SCL_PIN << 5 | SDA_PIN_1 << 2); reg_write_m(RTL837X_REG_I2C_CTRL); } @@ -1650,9 +1650,10 @@ void setup_serial(void) void setup_i2c(void) { - REG_SET(0x0414, 0); - REG_SET(0x0418, 0x00100280); - REG_SET(0x041c, 0); + REG_SET(RTL837X_REG_I2C_MST_IF_CTRL, 0); + // Configure SFP EEPROM address (0x50) as I2C device address + REG_SET(RTL837X_REG_I2C_CTRL, 0x1L << I2C_MEM_ADDR_WIDTH | 0x50 << I2C_DEV_ADDR); + REG_SET(RTL837X_REG_I2C_CTRL2, 0); // HW Control register, enable I2C? reg_read_m(RTL837X_PIN_MUX_1);