From 66944a1d0fc3534c49d7693001baf50371646ebb Mon Sep 17 00:00:00 2001 From: Eric Chen Date: Tue, 28 Nov 2023 16:35:02 +0800 Subject: [PATCH] fby4: sd: support ina233 sensors Summary: Description: - Add following sensors: - MB_INA233_x8_RTM_CURR_A - MB_INA233_x16_RTM_CURR_A - MB_INA233_x8_RTM_PWR_W - MB_INA233_x8_RTM_PWR_W Motivation: - support sentinel dome ina233 sensor for retimer Test Plan: - Get corresponding sensor reading Test Log: root@bmc:/usr/libexec/phosphor-state-manager# busctl introspect xyz.openbmc_project.PLDM /xyz/openbmc_project/sensors/current/MB_INA233_x16_RTM_CURR_A_70_134 ... .Value property d 0.2569 emits-change writable ... root@bmc:/usr/libexec/phosphor-state-manager# busctl introspect xyz.openbmc_project.PLDM /xyz/openbmc_project/sensors/current/MB_INA233_x8_RTM_CURR_A_69_134 ... .Value property d 0.186 emits-change writable ... root@bmc:/usr/libexec/phosphor-state-manager# busctl introspect xyz.openbmc_project.PLDM /xyz/openbmc_project/sensors/power/MB_INA233_x16_RTM_PWR_W_99_134 ... .Value property d 3.075 emits-change writable ... root@bmc:/usr/libexec/phosphor-state-manager# busctl introspect xyz.openbmc_project.PLDM /xyz/openbmc_project/sensors/power/MB_INA233_x8_RTM_PWR_W_98_134 ... .Value property d 2.25 emits-change writable ... --- meta-facebook/yv4-sd/src/platform/plat_hook.c | 19 + meta-facebook/yv4-sd/src/platform/plat_hook.h | 1 + .../yv4-sd/src/platform/plat_pldm_sensor.c | 359 ++++++++++++++++++ .../yv4-sd/src/platform/plat_pldm_sensor.h | 3 + 4 files changed, 382 insertions(+) diff --git a/meta-facebook/yv4-sd/src/platform/plat_hook.c b/meta-facebook/yv4-sd/src/platform/plat_hook.c index 99964102eb..5c7b190654 100644 --- a/meta-facebook/yv4-sd/src/platform/plat_hook.c +++ b/meta-facebook/yv4-sd/src/platform/plat_hook.c @@ -50,6 +50,25 @@ vr_pre_proc_arg vr_pre_read_args[] = { [1] = { 0x1 }, }; +ina233_init_arg ina233_init_args[] = { + [0] = { + .is_init = false, + .current_lsb = 0.001, + .r_shunt = 0.002, + .mfr_config_init = false, + .is_need_mfr_device_config_init = false, + .is_need_set_alert_threshold = false, + }, + [1] = { + .is_init = false, + .current_lsb = 0.001, + .r_shunt = 0.002, + .mfr_config_init = false, + .is_need_mfr_device_config_init = false, + .is_need_set_alert_threshold = false, + }, +}; + bool pre_vr_read(sensor_cfg *cfg, void *args) { CHECK_NULL_ARG_WITH_RETURN(cfg, false); diff --git a/meta-facebook/yv4-sd/src/platform/plat_hook.h b/meta-facebook/yv4-sd/src/platform/plat_hook.h index 641cb1cfab..bf6ff489ff 100644 --- a/meta-facebook/yv4-sd/src/platform/plat_hook.h +++ b/meta-facebook/yv4-sd/src/platform/plat_hook.h @@ -26,6 +26,7 @@ typedef struct _vr_pre_proc_arg { extern adc_asd_init_arg ast_adc_init_args[]; extern apml_mailbox_init_arg apml_mailbox_init_args[]; extern vr_pre_proc_arg vr_pre_read_args[]; +extern ina233_init_arg ina233_init_args[]; bool pre_vr_read(sensor_cfg *cfg, void *args); bool post_amd_tsi_read(sensor_cfg *cfg, void *args, int *const reading); diff --git a/meta-facebook/yv4-sd/src/platform/plat_pldm_sensor.c b/meta-facebook/yv4-sd/src/platform/plat_pldm_sensor.c index 55c7fbc3e1..3a7b856628 100644 --- a/meta-facebook/yv4-sd/src/platform/plat_pldm_sensor.c +++ b/meta-facebook/yv4-sd/src/platform/plat_pldm_sensor.c @@ -34,6 +34,7 @@ static struct pldm_sensor_thread pal_pldm_sensor_thread[MAX_SENSOR_THREAD_ID] = { VR_SENSOR_THREAD_ID, "VR_PLDM_SENSOR_THREAD" }, { MB_TEMP_SENSOR_THREAD_ID, "MB_TEMP_SENSOR_THREAD" }, { CPU_SENSOR_THREAD_ID, "CPU_TEMP_SENSOR_THREAD" }, + { INA233_SENSOR_THREAD_ID, "INA233_PLDM_SENSOR_THREAD" }, }; pldm_sensor_info plat_pldm_sensor_adc_table[] = { @@ -2237,6 +2238,286 @@ pldm_sensor_info plat_pldm_sensor_cpu_table[] = { }, }; +pldm_sensor_info plat_pldm_sensor_ina233_table[] = { + { + { + // MB_INA233_x8_RTM_CURR_A + /*** PDR common header***/ + { + 0x00000000, //uint32_t record_handle + 0x01, //uint8_t PDR_header_version + 0x02, //uint8_t PDR_type + 0x0000, //uint16_t record_change_number + 0x0000, //uint16_t data_length + }, + + /***numeric sensor format***/ + 0x0000, //uint16_t PLDM_terminus_handle; + 0x0045, //uint16_t sensor_id; + 0x0000, //uint16_t entity_type; //Need to check + 0x0001, //uint16_t entity_instance_number; + 0x0000, //uint16_t container_id; + PDR_SENSOR_USEINIT_PDR, //uint8_t sensor_init; + 0x01, //uint8_t sensor_auxiliary_names_pdr; + 0x06, //uint8_t base_unit; + -4, //int8_t unit_modifier; + 0x00, //uint8_t rate_unit; + 0x00, //uint8_t base_oem_unit_handle; + 0x00, //uint8_t aux_unit; + 0x00, //int8_t aux_unit_modifier; + 0x00, //uint8_t auxrate_unit; + 0x00, //uint8_t rel; + 0x00, //uint8_t aux_oem_unit_handle; + 0x00, //uint8_t is_linear; + 0x04, //uint8_t sensor_data_size; + 1, //int32_t resolution; + 0, //int32_t offset; + + 0x0000, //uint16_t accuracy; + 0x00, //uint8_t plus_tolerance; + 0x00, //uint8_t minus_tolerance; + 0x00000000, //uint32_t hysteresis; + 0xFF, //uint8_t supported_thresholds; + 0x00, //uint8_t threshold_and_hysteresis_volatility; + 0, //real32_t state_transition_interval; + + UPDATE_INTERVAL_1S, //int32_t update_interval; + 0x00000000, //uint32_t max_readable; + 0x00000000, //uint32_t min_readable; + 0x04, //uint8_t range_field_format; + 0xFF, //uint8_t range_field_support; + 0x00000000, //uint32_t nominal_value; + 0x00000000, //uint32_t normal_max; + 0x00000000, //uint32_t normal_min; + 0x00000000, //uint32_t warning_high; + 0x00000000, //uint32_t warning_low; + 0x00000000, //uint32_t critical_high; + 0x00000000, //uint32_t critical_low; + 0x00000000, //uint32_t fatal_high; + 0x00000000, //uint32_t fatal_low; + + }, + .update_time = 0, + { + .type = sensor_dev_ina233, + .port = I2C_BUS6, + .target_addr = ADDR_X8_INA233, + .offset = PMBUS_READ_IOUT, + .access_checker = stby_access, + .sample_count = SAMPLE_COUNT_DEFAULT, + .cache = 0, + .cache_status = PLDM_SENSOR_INITIALIZING, + .init_args = &ina233_init_args[0], + }, + }, + { + { + // MB_INA233_x16_RTM_CURR_A + /*** PDR common header***/ + { + 0x00000000, //uint32_t record_handle + 0x01, //uint8_t PDR_header_version + 0x02, //uint8_t PDR_type + 0x0000, //uint16_t record_change_number + 0x0000, //uint16_t data_length + }, + + /***numeric sensor format***/ + 0x0000, //uint16_t PLDM_terminus_handle; + 0x0046, //uint16_t sensor_id; + 0x0000, //uint16_t entity_type; //Need to check + 0x0002, //uint16_t entity_instance_number; + 0x0000, //uint16_t container_id; + PDR_SENSOR_USEINIT_PDR, //uint8_t sensor_init; + 0x01, //uint8_t sensor_auxiliary_names_pdr; + 0x06, //uint8_t base_unit; + -4, //int8_t unit_modifier; + 0x00, //uint8_t rate_unit; + 0x00, //uint8_t base_oem_unit_handle; + 0x00, //uint8_t aux_unit; + 0x00, //int8_t aux_unit_modifier; + 0x00, //uint8_t auxrate_unit; + 0x00, //uint8_t rel; + 0x00, //uint8_t aux_oem_unit_handle; + 0x00, //uint8_t is_linear; + 0x04, //uint8_t sensor_data_size; + 1, //int32_t resolution; + 0, //int32_t offset; + 0x0000, //uint16_t accuracy; + 0x00, //uint8_t plus_tolerance; + 0x00, //uint8_t minus_tolerance; + 0x00000000, //uint32_t hysteresis; + 0xFF, //uint8_t supported_thresholds; + 0x00, //uint8_t threshold_and_hysteresis_volatility; + 0, //real32_t state_transition_interval; + UPDATE_INTERVAL_1S, //int32_t update_interval; + 0x00000000, //uint32_t max_readable; + 0x00000000, //uint32_t min_readable; + 0x04, //uint8_t range_field_format; + 0xFF, //uint8_t range_field_support; + 0x00000000, //uint32_t nominal_value; + 0x00000000, //uint32_t normal_max; + 0x00000000, //uint32_t normal_min; + 0x00000000, //uint32_t warning_high; + 0x00000000, //uint32_t warning_low; + 0x00000000, //uint32_t critical_high; + 0x00000000, //uint32_t critical_low; + 0x00000000, //uint32_t fatal_high; + 0x00000000, //uint32_t fatal_low; + + }, + .update_time = 0, + { + .type = sensor_dev_ina233, + .port = I2C_BUS6, + .target_addr = ADDR_X16_INA233, + .offset = PMBUS_READ_IOUT, + .access_checker = stby_access, + .sample_count = SAMPLE_COUNT_DEFAULT, + .cache = 0, + .cache_status = PLDM_SENSOR_INITIALIZING, + .init_args = &ina233_init_args[1], + }, + }, + { + { + // MB_INA233_x8_RTM_PWR_W + /*** PDR common header***/ + { + 0x00000000, //uint32_t record_handle + 0x01, //uint8_t PDR_header_version + 0x02, //uint8_t PDR_type + 0x0000, //uint16_t record_change_number + 0x0000, //uint16_t data_length + }, + + /***numeric sensor format***/ + 0x0000, //uint16_t PLDM_terminus_handle; + 0x0062, //uint16_t sensor_id; + 0x0000, //uint16_t entity_type; //Need to check + 0x0003, //uint16_t entity_instance_number; + 0x0000, //uint16_t container_id; + PDR_SENSOR_USEINIT_PDR, //uint8_t sensor_init; + 0x01, //uint8_t sensor_auxiliary_names_pdr; + 0x07, //uint8_t base_unit; + -4, //int8_t unit_modifier; + 0x00, //uint8_t rate_unit; + 0x00, //uint8_t base_oem_unit_handle; + 0x00, //uint8_t aux_unit; + 0x00, //int8_t aux_unit_modifier; + 0x00, //uint8_t auxrate_unit; + 0x00, //uint8_t rel; + 0x00, //uint8_t aux_oem_unit_handle; + 0x00, //uint8_t is_linear; + 0x04, //uint8_t sensor_data_size; + 1, //int32_t resolution; + 0, //int32_t offset; + 0x0000, //uint16_t accuracy; + 0x00, //uint8_t plus_tolerance; + 0x00, //uint8_t minus_tolerance; + 0x00000000, //uint32_t hysteresis; + 0xFF, //uint8_t supported_thresholds; + 0x00, //uint8_t threshold_and_hysteresis_volatility; + 0, //real32_t state_transition_interval; + UPDATE_INTERVAL_1S, //int32_t update_interval; + 0x00000000, //uint32_t max_readable; + 0x00000000, //uint32_t min_readable; + 0x04, //uint8_t range_field_format; + 0xFF, //uint8_t range_field_support; + 0x00000000, //uint32_t nominal_value; + 0x00000000, //uint32_t normal_max; + 0x00000000, //uint32_t normal_min; + 0x00000000, //uint32_t warning_high; + 0x00000000, //uint32_t warning_low; + 0x00000000, //uint32_t critical_high; + 0x00000000, //uint32_t critical_low; + 0x00000000, //uint32_t fatal_high; + 0x00000000, //uint32_t fatal_low; + + }, + .update_time = 0, + { + .type = sensor_dev_ina233, + .port = I2C_BUS6, + .target_addr = ADDR_X8_INA233, + .offset = PMBUS_READ_POUT, + .access_checker = stby_access, + .sample_count = SAMPLE_COUNT_DEFAULT, + .cache = 0, + .cache_status = PLDM_SENSOR_INITIALIZING, + .init_args = &ina233_init_args[0], + }, + }, + { + { + // MB_INA233_x16_RTM_PWR_W + /*** PDR common header***/ + { + 0x00000000, //uint32_t record_handle + 0x01, //uint8_t PDR_header_version + 0x02, //uint8_t PDR_type + 0x0000, //uint16_t record_change_number + 0x0000, //uint16_t data_length + }, + + /***numeric sensor format***/ + 0x0000, //uint16_t PLDM_terminus_handle; + 0x0063, //uint16_t sensor_id; + 0x0000, //uint16_t entity_type; //Need to check + 0x0004, //uint16_t entity_instance_number; + 0x0000, //uint16_t container_id; + PDR_SENSOR_USEINIT_PDR, //uint8_t sensor_init; + 0x01, //uint8_t sensor_auxiliary_names_pdr; + 0x07, //uint8_t base_unit; + -4, //int8_t unit_modifier; + 0x00, //uint8_t rate_unit; + 0x00, //uint8_t base_oem_unit_handle; + 0x00, //uint8_t aux_unit; + 0x00, //int8_t aux_unit_modifier; + 0x00, //uint8_t auxrate_unit; + 0x00, //uint8_t rel; + 0x00, //uint8_t aux_oem_unit_handle; + 0x00, //uint8_t is_linear; + 0x04, //uint8_t sensor_data_size; + 1, //int32_t resolution; + 0, //int32_t offset; + 0x0000, //uint16_t accuracy; + 0x00, //uint8_t plus_tolerance; + 0x00, //uint8_t minus_tolerance; + 0x00000000, //uint32_t hysteresis; + 0xFF, //uint8_t supported_thresholds; + 0x00, //uint8_t threshold_and_hysteresis_volatility; + 0, //real32_t state_transition_interval; + UPDATE_INTERVAL_1S, //int32_t update_interval; + 0x00000000, //uint32_t max_readable; + 0x00000000, //uint32_t min_readable; + 0x04, //uint8_t range_field_format; + 0xFF, //uint8_t range_field_support; + 0x00000000, //uint32_t nominal_value; + 0x00000000, //uint32_t normal_max; + 0x00000000, //uint32_t normal_min; + 0x00000000, //uint32_t warning_high; + 0x00000000, //uint32_t warning_low; + 0x00000000, //uint32_t critical_high; + 0x00000000, //uint32_t critical_low; + 0x00000000, //uint32_t fatal_high; + 0x00000000, //uint32_t fatal_low; + }, + .update_time = 0, + { + .type = sensor_dev_ina233, + .port = I2C_BUS6, + .target_addr = ADDR_X16_INA233, + .offset = PMBUS_READ_POUT, + .access_checker = stby_access, + .sample_count = SAMPLE_COUNT_DEFAULT, + .cache = 0, + .cache_status = PLDM_SENSOR_INITIALIZING, + .init_args = &ina233_init_args[1], + }, + }, +}; + PDR_sensor_auxiliary_names plat_pdr_sensor_aux_names_table[] = { { // MB_INLET_TEMP_C @@ -2918,6 +3199,40 @@ PDR_sensor_auxiliary_names plat_pdr_sensor_aux_names_table[] = { .nameLanguageTag = "en", .sensorName = u"MB_VR_PVDD11_CURR_A", }, + { + // MB_INA233_x8_RTM_CURR_A + /*** PDR common header***/ + { + .record_handle = 0x00000000, + .PDR_header_version = 0x01, + .PDR_type = PLDM_SENSOR_AUXILIARY_NAMES_PDR, + .record_change_number = 0x0000, + .data_length = 0x0000, + }, + .terminus_handle = 0x0000, + .sensor_id = 0x0045, + .sensor_count = 0x1, + .nameStringCount = 0x1, + .nameLanguageTag = "en", + .sensorName = u"MB_INA233_x8_RTM_CURR_A", + }, + { + // MB_INA233_x16_RTM_CURR_A + /*** PDR common header***/ + { + .record_handle = 0x00000000, + .PDR_header_version = 0x01, + .PDR_type = PLDM_SENSOR_AUXILIARY_NAMES_PDR, + .record_change_number = 0x0000, + .data_length = 0x0000, + }, + .terminus_handle = 0x0000, + .sensor_id = 0x0046, + .sensor_count = 0x1, + .nameStringCount = 0x1, + .nameLanguageTag = "en", + .sensorName = u"MB_INA233_x16_RTM_CURR_A", + }, { // MB_VR_CPU0_PWR_W /*** PDR common header***/ @@ -3224,6 +3539,40 @@ PDR_sensor_auxiliary_names plat_pdr_sensor_aux_names_table[] = { .nameLanguageTag = "en", .sensorName = u"MB_DIMM_L_PWR_W", }, + { + // MB_INA233_x8_RTM_PWR_W + /*** PDR common header***/ + { + .record_handle = 0x00000000, + .PDR_header_version = 0x01, + .PDR_type = PLDM_SENSOR_AUXILIARY_NAMES_PDR, + .record_change_number = 0x0000, + .data_length = 0x0000, + }, + .terminus_handle = 0x0000, + .sensor_id = 0x0062, + .sensor_count = 0x1, + .nameStringCount = 0x1, + .nameLanguageTag = "en", + .sensorName = u"MB_INA233_x8_RTM_PWR_W", + }, + { + // MB_INA233_x16_RTM_PWR_W + /*** PDR common header***/ + { + .record_handle = 0x00000000, + .PDR_header_version = 0x01, + .PDR_type = PLDM_SENSOR_AUXILIARY_NAMES_PDR, + .record_change_number = 0x0000, + .data_length = 0x0000, + }, + .terminus_handle = 0x0000, + .sensor_id = 0x0063, + .sensor_count = 0x1, + .nameStringCount = 0x1, + .nameLanguageTag = "en", + .sensorName = u"MB_INA233_x16_RTM_PWR_W", + } }; uint32_t plat_get_pdr_size(uint8_t pdr_type) @@ -3262,6 +3611,8 @@ pldm_sensor_info *plat_pldm_sensor_load(int thread_id) return plat_pldm_sensor_mb_temp_table; case CPU_SENSOR_THREAD_ID: return plat_pldm_sensor_cpu_table; + case INA233_SENSOR_THREAD_ID: + return plat_pldm_sensor_ina233_table; default: LOG_ERR("Unknow pldm sensor thread id %d", thread_id); return NULL; @@ -3285,6 +3636,9 @@ int plat_pldm_sensor_get_sensor_count(int thread_id) case CPU_SENSOR_THREAD_ID: count = ARRAY_SIZE(plat_pldm_sensor_cpu_table); break; + case INA233_SENSOR_THREAD_ID: + count = ARRAY_SIZE(plat_pldm_sensor_ina233_table); + break; default: count = -1; LOG_ERR("Unknow pldm sensor thread id %d", thread_id); @@ -3318,6 +3672,11 @@ void plat_pldm_sensor_get_pdr_numeric_sensor(int thread_id, int sensor_num, &plat_pldm_sensor_cpu_table[sensor_num].pdr_numeric_sensor, sizeof(PDR_numeric_sensor)); break; + case INA233_SENSOR_THREAD_ID: + memcpy(numeric_sensor_table, + &plat_pldm_sensor_ina233_table[sensor_num].pdr_numeric_sensor, + sizeof(PDR_numeric_sensor)); + break; default: LOG_ERR("Unknow pldm sensor thread id %d", thread_id); break; diff --git a/meta-facebook/yv4-sd/src/platform/plat_pldm_sensor.h b/meta-facebook/yv4-sd/src/platform/plat_pldm_sensor.h index b5e10e2651..fe295e4b15 100644 --- a/meta-facebook/yv4-sd/src/platform/plat_pldm_sensor.h +++ b/meta-facebook/yv4-sd/src/platform/plat_pldm_sensor.h @@ -27,6 +27,8 @@ #define ADDR_VR_CPU1 (0XC6 >> 1) #define ADDR_VR_PVDDIO (0XC6 >> 1) #define ADDR_VR_PVDD11 (0XE4 >> 1) +#define ADDR_X8_INA233 (0x8A >> 1) +#define ADDR_X16_INA233 (0x82 >> 1) #define OFFSET_TMP75_TEMP 0x00 #define OFFSET_NVME_TEMP 0x00 @@ -39,6 +41,7 @@ enum SENSOR_THREAD_LIST { VR_SENSOR_THREAD_ID, MB_TEMP_SENSOR_THREAD_ID, CPU_SENSOR_THREAD_ID, + INA233_SENSOR_THREAD_ID, MAX_SENSOR_THREAD_ID, };