Skip to content

Commit

Permalink
Separate the I2C chip_id map for AFC devices and RTM devices
Browse files Browse the repository at this point in the history
Create different i2c_chip_mapping_t arrays and reserve chip_id numbers
between 0 and 63 to AFC devices and between 64 and 127 to the RTM
devices.
  • Loading branch information
gustavosr8 authored and augustofg committed Oct 23, 2023
1 parent 7a91948 commit 2eb350d
Show file tree
Hide file tree
Showing 14 changed files with 118 additions and 19 deletions.
36 changes: 30 additions & 6 deletions modules/i2c.c
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,10 @@
#include "i2c.h"
#include "i2c_mapping.h"

#ifdef MODULE_RTM
#include "rtm_i2c_mapping.h"
#endif

void i2c_init( void )
{
for ( uint8_t i = 0; i < I2C_MUX_CNT; i++ ) {
Expand Down Expand Up @@ -85,13 +89,33 @@ bool i2c_take_by_busid( uint8_t bus_id, uint8_t *i2c_interface, TickType_t timeo

bool i2c_take_by_chipid( uint8_t chip_id, uint8_t *i2c_address, uint8_t *i2c_interface, uint32_t timeout )
{
if ( chip_id > I2C_CHIP_CNT ) {
return false;
}

uint8_t bus_id = i2c_chip_map[chip_id].bus_id;
if ( i2c_address != NULL ) {
*i2c_address = i2c_chip_map[chip_id].i2c_address;
uint8_t bus_id;

/*AFC devices*/
if (chip_id <= 63) {
if ( chip_id > I2C_CHIP_CNT ) {
return false;
}
bus_id = i2c_chip_map[chip_id].bus_id;
if ( i2c_address != NULL ) {
*i2c_address = i2c_chip_map[chip_id].i2c_address;
}

#ifdef MODULE_RTM
/*RTM devices*/
} else if ((64 <= chip_id) && (chip_id <= 127)) {
if ( chip_id > 64+I2C_CHIP_RTM_CNT ) {
return false;
}
bus_id = i2c_chip_rtm_map[chip_id-64].bus_id;
if ( i2c_address != NULL ) {
*i2c_address = i2c_chip_map[chip_id-64].i2c_address;
}
#endif

} else {
return false;
}

return i2c_take_by_busid( bus_id, i2c_interface, timeout );
Expand Down
5 changes: 4 additions & 1 deletion port/board/afc-common/board_fru.c
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,9 @@
#include "at24mac.h"
#include "eeprom_24xx64.h"
#include "i2c_mapping.h"

#ifdef MODULE_RTM
#include "rtm_i2c_mapping.h"
#endif
fru_data_t fru[FRU_COUNT] = {
[FRU_AMC] = {
.cfg = {
Expand All @@ -40,6 +42,7 @@ fru_data_t fru[FRU_COUNT] = {
.runtime = false
},
#ifdef MODULE_RTM

[FRU_RTM] = {
.cfg = {
.eeprom_id = CHIP_ID_RTM_EEPROM,
Expand Down
5 changes: 0 additions & 5 deletions port/board/afc-v3/i2c_mapping.c
Original file line number Diff line number Diff line change
Expand Up @@ -47,11 +47,6 @@ i2c_chip_mapping_t i2c_chip_map[I2C_CHIP_CNT] = {
[CHIP_ID_FMC2_EEPROM] = { I2C_BUS_FMC2_ID, 0x52 },
[CHIP_ID_FMC2_LM75_0] = { I2C_BUS_FMC2_ID, 0x48 },
[CHIP_ID_FMC2_LM75_1] = { I2C_BUS_FMC2_ID, 0x49 },

[CHIP_ID_RTM_PCA9554] = { I2C_BUS_RTM_ID, 0x20 },
[CHIP_ID_RTM_EEPROM] = { I2C_BUS_RTM_ID, 0x50 },
[CHIP_ID_RTM_LM75_0] = { I2C_BUS_RTM_ID, 0x48 },
[CHIP_ID_RTM_LM75_1] = { I2C_BUS_RTM_ID, 0x49 },
};

bool i2c_set_mux_bus( uint8_t bus_id, i2c_mux_state_t *i2c_mux, int8_t new_state )
Expand Down
6 changes: 1 addition & 5 deletions port/board/afc-v3/i2c_mapping.h
Original file line number Diff line number Diff line change
Expand Up @@ -55,15 +55,11 @@ enum {
CHIP_ID_FMC2_EEPROM,
CHIP_ID_FMC2_LM75_1,
CHIP_ID_FMC2_LM75_0,
CHIP_ID_RTM_PCA9554,
CHIP_ID_RTM_EEPROM,
CHIP_ID_RTM_LM75_0,
CHIP_ID_RTM_LM75_1
};

#define I2C_MUX_CNT 2
#define I2C_BUS_CNT 7
#define I2C_CHIP_CNT 28
#define I2C_CHIP_CNT 24

extern i2c_mux_state_t i2c_mux[I2C_MUX_CNT];
extern i2c_bus_mapping_t i2c_bus_map[I2C_BUS_CNT];
Expand Down
7 changes: 7 additions & 0 deletions port/board/rtm-8sfp/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,20 @@ set(RTM_8SFP_PATH ${CMAKE_CURRENT_SOURCE_DIR})
set( PROJ_SRCS ${PROJ_SRCS}
${RTM_8SFP_PATH}/rtm_user.c
${RTM_8SFP_PATH}/sdr_list.c
${RTM_8SFP_PATH}/rtm_i2c_mapping.c
)

#Include headers path
set(PROJ_HDRS ${PROJ_HDRS} ${RTM_8SFP_PATH})

if(${TARGET_BOARD_NAME} MATCHES "afc-v3")
list(APPEND PROJ_HDRS ${RTM_8SFP_PATH}/../afc-v3/i2c_mapping.h)
elseif(${TARGET_BOARD_NAME} MATCHES "afc-v4")
list(APPEND PROJ_HDRS ${RTM_8SFP_PATH}/../afc-v4/i2c_mapping.h)
endif()
#Set the variables in the main scope
set(TARGET_MODULES ${TARGET_MODULES} ${RTM_8SFP_MODULES} PARENT_SCOPE)

#Set the variables in the main scope
set(PROJ_SRCS ${PROJ_SRCS} PARENT_SCOPE)
set(PROJ_HDRS ${PROJ_HDRS} PARENT_SCOPE)
11 changes: 11 additions & 0 deletions port/board/rtm-8sfp/rtm_i2c_mapping.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
#include "i2c.h"
#include "rtm_i2c_mapping.h"
#include "i2c_mapping.h"
#include "port.h"

i2c_chip_mapping_t i2c_chip_rtm_map[I2C_CHIP_RTM_CNT] = {
[CHIP_ID_RTM_PCA9554 - 64] = { I2C_BUS_RTM_ID, 0x20 },
[CHIP_ID_RTM_EEPROM - 64] = { I2C_BUS_RTM_ID, 0x50 },
[CHIP_ID_RTM_LM75_0 - 64] = { I2C_BUS_RTM_ID, 0x48 },
[CHIP_ID_RTM_LM75_1 - 64] = { I2C_BUS_RTM_ID, 0x49 },
};
17 changes: 17 additions & 0 deletions port/board/rtm-8sfp/rtm_i2c_mapping.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
#ifndef RTM_I2C_MAPPING_H_
#define RTM_I2C_MAPPING_H_

#include "i2c.h"

enum {
CHIP_ID_RTM_PCA9554 = 64,
CHIP_ID_RTM_EEPROM,
CHIP_ID_RTM_LM75_0,
CHIP_ID_RTM_LM75_1
};

#define I2C_CHIP_RTM_CNT 4

extern i2c_chip_mapping_t i2c_chip_rtm_map[I2C_CHIP_RTM_CNT];

#endif
1 change: 1 addition & 0 deletions port/board/rtm-8sfp/rtm_user.c
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
#include "pin_mapping.h"
#include "hotswap.h"
#include "i2c_mapping.h"
#include "rtm_i2c_mapping.h"
#include "fru.h"
#include "utils.h"
#include "led.h"
Expand Down
2 changes: 1 addition & 1 deletion port/board/rtm-8sfp/sdr_list.c
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
#include "sdr.h"
#include "utils.h"
#include "sensors.h"
#include "i2c_mapping.h"
#include "rtm_i2c_mapping.h"

/* Rename file to sdr_list.c */
#ifdef MODULE_HOTSWAP
Expand Down
8 changes: 8 additions & 0 deletions port/board/rtm-lamp/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,21 @@ set(RTM_LAMP_PATH ${CMAKE_CURRENT_SOURCE_DIR})
set( PROJ_SRCS ${PROJ_SRCS}
${RTM_LAMP_PATH}/rtm_user.c
${RTM_LAMP_PATH}/sdr_list.c
${RTM_LAMP_PATH}/rtm_i2c_mapping.c
)

#Include headers path
set(PROJ_HDRS ${PROJ_HDRS} ${RTM_LAMP_PATH})

if(${TARGET_BOARD_NAME} MATCHES "afc-v3")
list(APPEND PROJ_HDRS ${RTM_8SFP_PATH}/../afc-v3/i2c_mapping.h)
elseif(${TARGET_BOARD_NAME} MATCHES "afc-v4")
list(APPEND PROJ_HDRS ${RTM_8SFP_PATH}/../afc-v4/i2c_mapping.h)
endif()

#Set the variables in the main scope
set(TARGET_MODULES ${TARGET_MODULES} ${RTM_LAMP_MODULES} PARENT_SCOPE)

#Set the variables in the main scope
set(PROJ_SRCS ${PROJ_SRCS} PARENT_SCOPE)
set(PROJ_HDRS ${PROJ_HDRS} PARENT_SCOPE)
15 changes: 15 additions & 0 deletions port/board/rtm-lamp/rtm_i2c_mapping.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
#include "i2c.h"
#include "rtm_i2c_mapping.h"
#include "i2c_mapping.h"
#include "port.h"

i2c_chip_mapping_t i2c_chip_rtm_map[I2C_CHIP_RTM_CNT] = {
[CHIP_ID_RTM_PCA9554_LEDS - 64] = { I2C_BUS_RTM_ID, 0x20 },
[CHIP_ID_RTM_PCA9554_PWR - 64] = { I2C_BUS_RTM_ID, 0x21 },
[CHIP_ID_RTM_EEPROM - 64] = { I2C_BUS_RTM_ID, 0x50 },
[CHIP_ID_RTM_LM75_0 - 64] = { I2C_BUS_RTM_ID, 0x48 },
[CHIP_ID_RTM_LM75_1 - 64] = { I2C_BUS_RTM_ID, 0x49 },
[CHIP_ID_RTM_LM75_2 - 64] = { I2C_BUS_RTM_ID, 0x4B },
[CHIP_ID_RTM_MAX11609 - 64] = { I2C_BUS_RTM_ID, 0x33 },
[CHIP_ID_RTM_CDCE906 - 64] = { I2C_BUS_RTM_ID, 0x69 },
};
21 changes: 21 additions & 0 deletions port/board/rtm-lamp/rtm_i2c_mapping.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
#ifndef RTM_I2C_MAPPING_H_
#define RTM_I2C_MAPPING_H_

#include "i2c.h"

enum {
CHIP_ID_RTM_PCA9554_LEDS = 64,
CHIP_ID_RTM_PCA9554_PWR,
CHIP_ID_RTM_EEPROM,
CHIP_ID_RTM_LM75_0,
CHIP_ID_RTM_LM75_1,
CHIP_ID_RTM_LM75_2,
CHIP_ID_RTM_MAX11609,
CHIP_ID_RTM_CDCE906,
};

#define I2C_CHIP_RTM_CNT 8

extern i2c_chip_mapping_t i2c_chip_rtm_map[I2C_CHIP_RTM_CNT];

#endif
1 change: 1 addition & 0 deletions port/board/rtm-lamp/rtm_user.c
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
#include "pin_mapping.h"
#include "hotswap.h"
#include "i2c_mapping.h"
#include "rtm_i2c_mapping.h"
#include "fru.h"
#include "utils.h"
#include "led.h"
Expand Down
2 changes: 1 addition & 1 deletion port/board/rtm-lamp/sdr_list.c
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
#include "sdr.h"
#include "utils.h"
#include "sensors.h"
#include "i2c_mapping.h"
#include "rtm_i2c_mapping.h"

/* Rename file to sdr_list.c */
#ifdef MODULE_HOTSWAP
Expand Down

0 comments on commit 2eb350d

Please sign in to comment.