Skip to content

Commit

Permalink
fby3.5: cl: Modify PMIC pre-read function (#327)
Browse files Browse the repository at this point in the history
Summary:
- In function driver_init(), pre-read function for each sensor is called.
The pre-read function of the PMIC sensor sends IPMB message to ME, but  IPMB is not ready at this time.
It causes unexpected behavior.
- Modify PMIC initialization function and pre-read function to avoid sending IPMB message to ME before IPMI initialization.
- Fix PMIC smbus address as described in #323 .

Pull Request resolved: #327

Test Plan:
- Build code: PASS
- Sensor read: PASS
```
root@bmc-oob:~# sensor-util slot1 | grep PMIC
DIMMA PMIC_Pout              (0x1E) :    0.38 Watts | (ok)
DIMMC PMIC_Pout              (0x1F) :    0.52 Watts | (ok)
DIMMD PMIC_Pout              (0x36) :    0.75 Watts | (ok)
DIMME PMIC_Pout              (0x37) :    0.60 Watts | (ok)
DIMMG PMIC_Pout              (0x42) :    0.50 Watts | (ok)
DIMMH PMIC_Pout              (0x47) :    0.50 Watts | (ok)
```

Reviewed By: zhdaniel12

Differential Revision: D37079722

Pulled By: GoldenBug

fbshipit-source-id: b622fa1e8c7548bd1a760bcfdcb7a18cb099f11c
  • Loading branch information
Yi-Shum authored and facebook-github-bot committed Jun 15, 2022
1 parent 2c235cf commit 108bf01
Show file tree
Hide file tree
Showing 5 changed files with 45 additions and 25 deletions.
2 changes: 2 additions & 0 deletions common/dev/pmic.c
Original file line number Diff line number Diff line change
Expand Up @@ -130,5 +130,7 @@ uint8_t pmic_init(uint8_t sensor_num)
return SENSOR_INIT_UNSPECIFIED_ERROR;
}
sensor_config[sensor_config_index_map[sensor_num]].read = pmic_read;
pmic_init_arg *init_arg = sensor_config[sensor_config_index_map[sensor_num]].init_args;
init_arg->is_init = true;
return SENSOR_INIT_SUCCESS;
}
1 change: 1 addition & 0 deletions common/service/sensor/sensor.c
Original file line number Diff line number Diff line change
Expand Up @@ -369,6 +369,7 @@ static void drive_init(void)
p->num, p->pre_sensor_read_args) == false) {
printk("[%s] sensor %d pre sensor read failed!\n",
__func__, p->num);
continue;
}
}
ret = sensor_drive_tbl[j].init(p->num);
Expand Down
38 changes: 25 additions & 13 deletions meta-facebook/yv35-cl/src/platform/plat_hook.c
Original file line number Diff line number Diff line change
Expand Up @@ -28,11 +28,11 @@ mp5990_init_arg mp5990_init_args[] = {

pmic_init_arg pmic_init_args[] = {
[0] = { .is_init = false, .smbus_bus_identifier = 0x00, .smbus_addr = 0x90 },
[1] = { .is_init = false, .smbus_bus_identifier = 0x00, .smbus_addr = 0x9C },
[2] = { .is_init = false, .smbus_bus_identifier = 0x00, .smbus_addr = 0x98 },
[1] = { .is_init = false, .smbus_bus_identifier = 0x00, .smbus_addr = 0x98 },
[2] = { .is_init = false, .smbus_bus_identifier = 0x00, .smbus_addr = 0x9C },
[3] = { .is_init = false, .smbus_bus_identifier = 0x01, .smbus_addr = 0x90 },
[4] = { .is_init = false, .smbus_bus_identifier = 0x01, .smbus_addr = 0x9C },
[5] = { .is_init = false, .smbus_bus_identifier = 0x01, .smbus_addr = 0x98 }
[4] = { .is_init = false, .smbus_bus_identifier = 0x01, .smbus_addr = 0x98 },
[5] = { .is_init = false, .smbus_bus_identifier = 0x01, .smbus_addr = 0x9C }
};

// R_load is the value of resistance connected to EFUSE , and EFUSE would adjust the reading accuracy according to r_load
Expand All @@ -53,6 +53,12 @@ isl69259_pre_proc_arg isl69259_pre_read_args[] = {
[1] = { 0x1 },
};

pmic_pre_proc_arg pmic_pre_read_args[] = {
[0] = { .pre_read_init = false }, [1] = { .pre_read_init = false },
[2] = { .pre_read_init = false }, [3] = { .pre_read_init = false },
[4] = { .pre_read_init = false }, [5] = { .pre_read_init = false }
};

/**************************************************************************************************
* PRE-HOOK/POST-HOOK FUNC
**************************************************************************************************/
Expand Down Expand Up @@ -135,8 +141,14 @@ bool pre_pmic_read(uint8_t sensor_num, void *args)
{
ARG_UNUSED(args);

pmic_init_arg *pmic_arg = sensor_config[sensor_config_index_map[sensor_num]].init_args;
if (pmic_arg->is_init == false) {
pmic_init_arg *init_arg = sensor_config[sensor_config_index_map[sensor_num]].init_args;
if (init_arg->is_init == false) {
return true;
}

pmic_pre_proc_arg *pre_proc_arg =
sensor_config[sensor_config_index_map[sensor_num]].pre_sensor_read_args;
if (pre_proc_arg->pre_read_init == false) {
static bool is_ME_reset = false;
int ret = 0;
uint8_t seq_source = 0xFF, write_data = 0x0;
Expand All @@ -156,8 +168,8 @@ bool pre_pmic_read(uint8_t sensor_num, void *args)
// Enable PMIC ADC
write_data = PMIC_ENABLE_ADC_BIT;
compose_memory_write_read_msg =
compose_memory_write_read_req(pmic_arg->smbus_bus_identifier,
pmic_arg->smbus_addr, PMIC_ADC_ADDR_VAL,
compose_memory_write_read_req(init_arg->smbus_bus_identifier,
init_arg->smbus_addr, PMIC_ADC_ADDR_VAL,
&write_data, 0x1);
if (compose_memory_write_read_msg == NULL) {
goto COMPOSE_MSG_ERR;
Expand All @@ -174,8 +186,8 @@ bool pre_pmic_read(uint8_t sensor_num, void *args)
// Initialize PMIC to report total mode (could be total power, total current, etc.)
write_data = SET_DEV_REPORT_TOTAL;
compose_memory_write_read_msg =
compose_memory_write_read_req(pmic_arg->smbus_bus_identifier,
pmic_arg->smbus_addr,
compose_memory_write_read_req(init_arg->smbus_bus_identifier,
init_arg->smbus_addr,
PMIC_TOTAL_INDIV_ADDR_VAL, &write_data, 0x1);
if (compose_memory_write_read_msg == NULL) {
goto COMPOSE_MSG_ERR;
Expand All @@ -192,8 +204,8 @@ bool pre_pmic_read(uint8_t sensor_num, void *args)
// Initialize PMIC to report power mode
write_data = SET_DEV_REPORT_POWER;
compose_memory_write_read_msg =
compose_memory_write_read_req(pmic_arg->smbus_bus_identifier,
pmic_arg->smbus_addr, PMIC_PWR_CURR_ADDR_VAL,
compose_memory_write_read_req(init_arg->smbus_bus_identifier,
init_arg->smbus_addr, PMIC_PWR_CURR_ADDR_VAL,
&write_data, 0x1);
if (compose_memory_write_read_msg == NULL) {
goto COMPOSE_MSG_ERR;
Expand All @@ -207,7 +219,7 @@ bool pre_pmic_read(uint8_t sensor_num, void *args)
}
k_msleep(PMIC_COMMAND_DELAY_MSEC);

pmic_arg->is_init = true;
pre_proc_arg->pre_read_init = true;
return true;

PMIC_IPMB_TRANSFER_ERR:
Expand Down
5 changes: 5 additions & 0 deletions meta-facebook/yv35-cl/src/platform/plat_hook.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,10 @@ typedef struct _isl69259_pre_proc_arg {
uint8_t vr_page;
} isl69259_pre_proc_arg;

typedef struct _pmic_pre_proc_arg {
bool pre_read_init;
} pmic_pre_proc_arg;

/**************************************************************************************************
* INIT ARGS
**************************************************************************************************/
Expand All @@ -20,6 +24,7 @@ extern max16550a_init_arg max16550a_init_args[];
**************************************************************************************************/
extern struct tca9548 mux_conf_addr_0xe2[];
extern isl69259_pre_proc_arg isl69259_pre_read_args[];
extern pmic_pre_proc_arg pmic_pre_read_args[];

/**************************************************************************************************
* PRE-HOOK/POST-HOOK FUNC
Expand Down
24 changes: 12 additions & 12 deletions meta-facebook/yv35-cl/src/platform/plat_sensor_table.c
Original file line number Diff line number Diff line change
Expand Up @@ -174,23 +174,23 @@ sensor_cfg plat_sensor_config[] = {
me_access, 0, 0, SAMPLE_COUNT_DEFAULT, 0, SENSOR_INIT_STATUS, NULL, NULL, NULL, NULL,
NULL },
{ SENSOR_NUM_PWR_DIMMA_PMIC, sensor_dev_pmic, I2C_BUS3, PCH_ADDR, NONE, me_access, 0, 0,
SAMPLE_COUNT_DEFAULT, 0, SENSOR_INIT_STATUS, pre_pmic_read, NULL, NULL, NULL,
&pmic_init_args[0] },
SAMPLE_COUNT_DEFAULT, 0, SENSOR_INIT_STATUS, pre_pmic_read, &pmic_pre_read_args[0], NULL,
NULL, &pmic_init_args[0] },
{ SENSOR_NUM_PWR_DIMMC_PMIC, sensor_dev_pmic, I2C_BUS3, PCH_ADDR, NONE, me_access, 0, 0,
SAMPLE_COUNT_DEFAULT, 0, SENSOR_INIT_STATUS, pre_pmic_read, NULL, NULL, NULL,
&pmic_init_args[1] },
SAMPLE_COUNT_DEFAULT, 0, SENSOR_INIT_STATUS, pre_pmic_read, &pmic_pre_read_args[1], NULL,
NULL, &pmic_init_args[1] },
{ SENSOR_NUM_PWR_DIMMD_PMIC, sensor_dev_pmic, I2C_BUS3, PCH_ADDR, NONE, me_access, 0, 0,
SAMPLE_COUNT_DEFAULT, 0, SENSOR_INIT_STATUS, pre_pmic_read, NULL, NULL, NULL,
&pmic_init_args[2] },
SAMPLE_COUNT_DEFAULT, 0, SENSOR_INIT_STATUS, pre_pmic_read, &pmic_pre_read_args[2], NULL,
NULL, &pmic_init_args[2] },
{ SENSOR_NUM_PWR_DIMME_PMIC, sensor_dev_pmic, I2C_BUS3, PCH_ADDR, NONE, me_access, 0, 0,
SAMPLE_COUNT_DEFAULT, 0, SENSOR_INIT_STATUS, pre_pmic_read, NULL, NULL, NULL,
&pmic_init_args[3] },
SAMPLE_COUNT_DEFAULT, 0, SENSOR_INIT_STATUS, pre_pmic_read, &pmic_pre_read_args[3], NULL,
NULL, &pmic_init_args[3] },
{ SENSOR_NUM_PWR_DIMMG_PMIC, sensor_dev_pmic, I2C_BUS3, PCH_ADDR, NONE, me_access, 0, 0,
SAMPLE_COUNT_DEFAULT, 0, SENSOR_INIT_STATUS, pre_pmic_read, NULL, NULL, NULL,
&pmic_init_args[4] },
SAMPLE_COUNT_DEFAULT, 0, SENSOR_INIT_STATUS, pre_pmic_read, &pmic_pre_read_args[4], NULL,
NULL, &pmic_init_args[4] },
{ SENSOR_NUM_PWR_DIMMH_PMIC, sensor_dev_pmic, I2C_BUS3, PCH_ADDR, NONE, me_access, 0, 0,
SAMPLE_COUNT_DEFAULT, 0, SENSOR_INIT_STATUS, pre_pmic_read, NULL, NULL, NULL,
&pmic_init_args[5] },
SAMPLE_COUNT_DEFAULT, 0, SENSOR_INIT_STATUS, pre_pmic_read, &pmic_pre_read_args[5], NULL,
NULL, &pmic_init_args[5] },
};

sensor_cfg mp5990_sensor_config_table[] = {
Expand Down

0 comments on commit 108bf01

Please sign in to comment.