From 2eb350d14faa7d00011efe299f0904fbb4dc9a47 Mon Sep 17 00:00:00 2001 From: Gustavo de Souza dos Reis Date: Tue, 17 Oct 2023 13:10:28 -0300 Subject: [PATCH] Separate the I2C chip_id map for AFC devices and RTM devices 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. --- modules/i2c.c | 36 ++++++++++++++++++++++----- port/board/afc-common/board_fru.c | 5 +++- port/board/afc-v3/i2c_mapping.c | 5 ---- port/board/afc-v3/i2c_mapping.h | 6 +---- port/board/rtm-8sfp/CMakeLists.txt | 7 ++++++ port/board/rtm-8sfp/rtm_i2c_mapping.c | 11 ++++++++ port/board/rtm-8sfp/rtm_i2c_mapping.h | 17 +++++++++++++ port/board/rtm-8sfp/rtm_user.c | 1 + port/board/rtm-8sfp/sdr_list.c | 2 +- port/board/rtm-lamp/CMakeLists.txt | 8 ++++++ port/board/rtm-lamp/rtm_i2c_mapping.c | 15 +++++++++++ port/board/rtm-lamp/rtm_i2c_mapping.h | 21 ++++++++++++++++ port/board/rtm-lamp/rtm_user.c | 1 + port/board/rtm-lamp/sdr_list.c | 2 +- 14 files changed, 118 insertions(+), 19 deletions(-) create mode 100644 port/board/rtm-8sfp/rtm_i2c_mapping.c create mode 100644 port/board/rtm-8sfp/rtm_i2c_mapping.h create mode 100644 port/board/rtm-lamp/rtm_i2c_mapping.c create mode 100644 port/board/rtm-lamp/rtm_i2c_mapping.h diff --git a/modules/i2c.c b/modules/i2c.c index aa3ab7e7f..2831403ee 100644 --- a/modules/i2c.c +++ b/modules/i2c.c @@ -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++ ) { @@ -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 ); diff --git a/port/board/afc-common/board_fru.c b/port/board/afc-common/board_fru.c index d0281aaf9..d10c93e65 100644 --- a/port/board/afc-common/board_fru.c +++ b/port/board/afc-common/board_fru.c @@ -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 = { @@ -40,6 +42,7 @@ fru_data_t fru[FRU_COUNT] = { .runtime = false }, #ifdef MODULE_RTM + [FRU_RTM] = { .cfg = { .eeprom_id = CHIP_ID_RTM_EEPROM, diff --git a/port/board/afc-v3/i2c_mapping.c b/port/board/afc-v3/i2c_mapping.c index e979a3cdf..d31f5f506 100644 --- a/port/board/afc-v3/i2c_mapping.c +++ b/port/board/afc-v3/i2c_mapping.c @@ -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 ) diff --git a/port/board/afc-v3/i2c_mapping.h b/port/board/afc-v3/i2c_mapping.h index aaf5cb474..6613343a6 100644 --- a/port/board/afc-v3/i2c_mapping.h +++ b/port/board/afc-v3/i2c_mapping.h @@ -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]; diff --git a/port/board/rtm-8sfp/CMakeLists.txt b/port/board/rtm-8sfp/CMakeLists.txt index 224b6917b..2504a6c5d 100644 --- a/port/board/rtm-8sfp/CMakeLists.txt +++ b/port/board/rtm-8sfp/CMakeLists.txt @@ -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) diff --git a/port/board/rtm-8sfp/rtm_i2c_mapping.c b/port/board/rtm-8sfp/rtm_i2c_mapping.c new file mode 100644 index 000000000..1c617534e --- /dev/null +++ b/port/board/rtm-8sfp/rtm_i2c_mapping.c @@ -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 }, +}; diff --git a/port/board/rtm-8sfp/rtm_i2c_mapping.h b/port/board/rtm-8sfp/rtm_i2c_mapping.h new file mode 100644 index 000000000..e2de49b62 --- /dev/null +++ b/port/board/rtm-8sfp/rtm_i2c_mapping.h @@ -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 diff --git a/port/board/rtm-8sfp/rtm_user.c b/port/board/rtm-8sfp/rtm_user.c index 9042a8be9..c1849335f 100644 --- a/port/board/rtm-8sfp/rtm_user.c +++ b/port/board/rtm-8sfp/rtm_user.c @@ -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" diff --git a/port/board/rtm-8sfp/sdr_list.c b/port/board/rtm-8sfp/sdr_list.c index 94aad3c6a..c60e15a36 100644 --- a/port/board/rtm-8sfp/sdr_list.c +++ b/port/board/rtm-8sfp/sdr_list.c @@ -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 diff --git a/port/board/rtm-lamp/CMakeLists.txt b/port/board/rtm-lamp/CMakeLists.txt index 6b46c70bb..e4a1a0d75 100644 --- a/port/board/rtm-lamp/CMakeLists.txt +++ b/port/board/rtm-lamp/CMakeLists.txt @@ -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) diff --git a/port/board/rtm-lamp/rtm_i2c_mapping.c b/port/board/rtm-lamp/rtm_i2c_mapping.c new file mode 100644 index 000000000..d2e8a9371 --- /dev/null +++ b/port/board/rtm-lamp/rtm_i2c_mapping.c @@ -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 }, +}; diff --git a/port/board/rtm-lamp/rtm_i2c_mapping.h b/port/board/rtm-lamp/rtm_i2c_mapping.h new file mode 100644 index 000000000..fb0171852 --- /dev/null +++ b/port/board/rtm-lamp/rtm_i2c_mapping.h @@ -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 diff --git a/port/board/rtm-lamp/rtm_user.c b/port/board/rtm-lamp/rtm_user.c index 7bcab98a8..6d2d8ab08 100644 --- a/port/board/rtm-lamp/rtm_user.c +++ b/port/board/rtm-lamp/rtm_user.c @@ -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" diff --git a/port/board/rtm-lamp/sdr_list.c b/port/board/rtm-lamp/sdr_list.c index db7d705a5..8f1e63f16 100644 --- a/port/board/rtm-lamp/sdr_list.c +++ b/port/board/rtm-lamp/sdr_list.c @@ -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