Skip to content

Commit d48235f

Browse files
authored
Merge pull request #37 from logicog/sfp_demagic
De-Magic I2C configuration for SFP-EEPROM reads
2 parents 0989b22 + 9c7572b commit d48235f

File tree

3 files changed

+18
-9
lines changed

3 files changed

+18
-9
lines changed

rtl837x_common.h

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,11 @@
55
#include <stdint.h>
66

77
// This has to be set to the number of SFP+ ports, i.e. 1 or 2
8-
#define NSFP 2
8+
#define NSFP 2
9+
// SCL and SDA pin numbers for SFP cage 0 and SFP cage 1
10+
#define SCL_PIN 3
11+
#define SDA_PIN_0 4
12+
#define SDA_PIN_1 3
913

1014
// Define Port-masks for 9-port devices and 6-port devices
1115
#define PMASK_9 0x1ff

rtl837x_regs.h

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -66,9 +66,13 @@
6666
/*
6767
* I2C controller
6868
*/
69-
#define RTL837X_REG_I2C_CTRL 0x0418
70-
#define RTL837X_REG_I2C_IN 0x0420
71-
#define RTL837X_REG_I2C_OUT 0x0424
69+
#define RTL837X_REG_I2C_MST_IF_CTRL 0x0414
70+
#define RTL837X_REG_I2C_CTRL 0x0418
71+
#define I2C_DEV_ADDR 3
72+
#define I2C_MEM_ADDR_WIDTH 20
73+
#define RTL837X_REG_I2C_CTRL2 0x041c
74+
#define RTL837X_REG_I2C_IN 0x0420
75+
#define RTL837X_REG_I2C_OUT 0x0424
7276

7377
/*
7478
* NIC Related registers

rtlplayground.c

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -725,11 +725,11 @@ uint8_t sfp_read_reg(uint8_t slot, uint8_t reg)
725725
{
726726
if (slot == 0) {
727727
reg_read_m(RTL837X_REG_I2C_CTRL);
728-
sfr_mask_data(1, 0xff, 0x72);
728+
sfr_mask_data(1, 0xfc, SCL_PIN << 5 | SDA_PIN_0 << 2);
729729
reg_write_m(RTL837X_REG_I2C_CTRL);
730730
} else {
731731
reg_read_m(RTL837X_REG_I2C_CTRL);
732-
sfr_mask_data(1, 0xff, 0x6e);
732+
sfr_mask_data(1, 0xfc, SCL_PIN << 5 | SDA_PIN_1 << 2);
733733
reg_write_m(RTL837X_REG_I2C_CTRL);
734734
}
735735

@@ -1650,9 +1650,10 @@ void setup_serial(void)
16501650

16511651
void setup_i2c(void)
16521652
{
1653-
REG_SET(0x0414, 0);
1654-
REG_SET(0x0418, 0x00100280);
1655-
REG_SET(0x041c, 0);
1653+
REG_SET(RTL837X_REG_I2C_MST_IF_CTRL, 0);
1654+
// Configure SFP EEPROM address (0x50) as I2C device address
1655+
REG_SET(RTL837X_REG_I2C_CTRL, 0x1L << I2C_MEM_ADDR_WIDTH | 0x50 << I2C_DEV_ADDR);
1656+
REG_SET(RTL837X_REG_I2C_CTRL2, 0);
16561657

16571658
// HW Control register, enable I2C?
16581659
reg_read_m(RTL837X_PIN_MUX_1);

0 commit comments

Comments
 (0)