Skip to content

Commit

Permalink
fby3.5: hd: support bom3 sensor
Browse files Browse the repository at this point in the history
Summary:
- Support VR sensor MP2856GUT
- Add the sensor config table of 3rd source sensor, replace sensor talbe to it if board revision is SYS_BOARD_EVT_BOM3.

Test Plan:
- Build Code: Pass

Known issue:
- Pout reading for MP2856GUT is larger than expected, still checking with FAE.

Log:
Third source boar
```
Summary:

Support VR sensor MP2856GUT
Add the sensor config table of 3rd source sensor, replace sensor talbe to it if board revision is SYS_BOARD_EVT_BOM3.
Dependency: #467

Test Plan:

Build Code: Pass
Known issue:

Pout reading for MP2856GUT is larger than expected, still checking with FAE.
Log:
Third source boar

root@bmc-oob:~# sensor-util slot1
...
HSC Temp                     (0xE) :   47.12 C     | (ok)
CPU0 VR Temp                 (0xF) :   49.00 C     | (ok)
SOC VR Temp                  (0x10) :   51.00 C     | (ok)
CPU1 VR Temp                 (0x11) :   34.00 C     | (ok)
PVDDIO VR Temp               (0x12) :   34.00 C     | (ok)
PVDD11 VR Temp               (0x13) :   31.00 C     | (ok)
P12V_STBY Vol                (0x14) :   12.00 Volts | (ok)
PVDD18_S5 Vol                (0x15) :    1.81 Volts | (ok)
P3V3_STBY Vol                (0x16) :    3.30 Volts | (ok)
PVDD11_S3 Vol                (0x17) :    1.10 Volts | (ok)
P3V_BAT Vol                  (0x18) :    3.08 Volts | (ok)
PVDD33_S5 Vol                (0x19) :    3.31 Volts | (ok)
P5V_STBY Vol                 (0x1A) :    4.99 Volts | (ok)
P12V_MEM_1 Vol               (0x1B) :   12.05 Volts | (ok)
P12V_MEM_0 Vol               (0x1C) :   12.03 Volts | (ok)
P1V2_STBY Vol                (0x1D) :    1.20 Volts | (ok)
P3V3_M2 Vol                  (0x1E) :    3.31 Volts | (ok)
P1V8_STBY Vol                (0x1F) :    1.81 Volts | (ok)
HSC Input Vol                (0x20) :   12.05 Volts | (ok)
CPU0 VR Vol                  (0x21) :    0.92 Volts | (ok)
SOC VR Vol                   (0x22) :    1.19 Volts | (ok)
CPU1 VR Vol                  (0x23) :    0.93 Volts | (ok)
PVDDIO VR Vol                (0x24) :    1.10 Volts | (ok)
PVDD11 VR Vol                (0x25) :    1.10 Volts | (ok)
HSC Output Cur               (0x26) :   12.75 Amps  | (ok)
CPU0 VR Cur                  (0x27) :   12.75 Amps  | (ok)
SOC VR Cur                   (0x28) :   59.75 Amps  | (ok)
CPU1 VR Cur                  (0x29) :   16.75 Amps  | (ok)
PVDDIO VR Cur                (0x2A) :   31.75 Amps  | (ok)
PVDD11 VR Cur                (0x2B) :    3.25 Amps  | (ok)
HSC Input Pwr                (0x2C) :  155.15 Watts | (ok)
CPU0 VR Pwr                  (0x2D) :   96.00 Watts | (ok)
SOC VR Pwr                   (0x2E) :  568.00 Watts | (ucr)
CPU1 VR Pwr                  (0x2F) :  120.00 Watts | (ok)
PVDDIO VR Pwr                (0x30) :  280.00 Watts | (ucr)
PVDD11 VR Pwr                (0x31) :   32.00 Watts | (ok)
...
```
  • Loading branch information
Yi-Shum committed Aug 8, 2022
1 parent 82aca21 commit 81d2c41
Show file tree
Hide file tree
Showing 6 changed files with 188 additions and 0 deletions.
77 changes: 77 additions & 0 deletions common/dev/mp2856gut.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
#include <stdio.h>
#include <string.h>
#include "sensor.h"
#include "hal_i2c.h"
#include "pmbus.h"
#include "util_pmbus.h"

#define MFR_VR_CONFIG2_VOUT_MODE_BIT BIT(11)
#define MFR_VR_CONFIG2 0x5E

uint8_t mp2856gut_read(uint8_t sensor_num, int *reading)
{
if (reading == NULL || (sensor_num > SENSOR_NUM_MAX)) {
return SENSOR_UNSPECIFIED_ERROR;
}

uint8_t retry = 5;
sensor_val *sval = (sensor_val *)reading;
I2C_MSG msg;
memset(sval, 0, sizeof(sensor_val));
sensor_cfg *cfg = &sensor_config[sensor_config_index_map[sensor_num]];

msg.bus = cfg->port;
msg.target_addr = cfg->target_addr;
msg.tx_len = 1;
msg.rx_len = 2;
msg.data[0] = cfg->offset;

if (i2c_master_read(&msg, retry)) {
return SENSOR_FAIL_TO_ACCESS;
}

float val;
if (cfg->offset == PMBUS_READ_VOUT) {
val = (msg.data[1] << 8) | msg.data[0];

msg.bus = cfg->port;
msg.target_addr = cfg->target_addr;
msg.tx_len = 1;
msg.rx_len = 2;
msg.data[0] = MFR_VR_CONFIG2;

if (i2c_master_read(&msg, retry)) {
return SENSOR_FAIL_TO_ACCESS;
}

uint16_t mfg_vr_config2_data = (msg.data[1] << 8) | msg.data[0];
bool vout_mode = mfg_vr_config2_data && MFR_VR_CONFIG2_VOUT_MODE_BIT;

if (vout_mode) {
val *= 0.00390625;
} else {
val *= 0.005;
}
} else if (cfg->offset == PMBUS_READ_IOUT || cfg->offset == PMBUS_READ_POUT) {
uint16_t read_value = (msg.data[1] << 8) | msg.data[0];
val = slinear11_to_float(read_value);
} else if (cfg->offset == PMBUS_READ_TEMPERATURE_1) {
val = msg.data[0];
} else {
return SENSOR_FAIL_TO_ACCESS;
}
sval->integer = val;
sval->fraction = (val - sval->integer) * 1000;

return SENSOR_READ_SUCCESS;
}

uint8_t mp2856gut_init(uint8_t sensor_num)
{
if (sensor_num > SENSOR_NUM_MAX) {
return SENSOR_INIT_UNSPECIFIED_ERROR;
}

sensor_config[sensor_config_index_map[sensor_num]].read = mp2856gut_read;
return SENSOR_INIT_SUCCESS;
}
2 changes: 2 additions & 0 deletions common/service/sensor/sensor.c
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@ SENSOR_DRIVE_INIT_DECLARE(apml_mailbox);
#endif
SENSOR_DRIVE_INIT_DECLARE(xdpe19283b);
SENSOR_DRIVE_INIT_DECLARE(g788p81u);
SENSOR_DRIVE_INIT_DECLARE(mp2856gut);

struct sensor_drive_api {
enum SENSOR_DEV dev;
Expand Down Expand Up @@ -108,6 +109,7 @@ struct sensor_drive_api {
#endif
SENSOR_DRIVE_TYPE_INIT_MAP(xdpe19283b),
SENSOR_DRIVE_TYPE_INIT_MAP(g788p81u),
SENSOR_DRIVE_TYPE_INIT_MAP(mp2856gut),
};

static void init_sensor_num(void)
Expand Down
1 change: 1 addition & 0 deletions common/service/sensor/sensor.h
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,7 @@ enum SENSOR_DEV {
sensor_dev_apml_mailbox = 0x19,
sensor_dev_xdpe19283b = 0x1A,
sensor_dev_g788p81u = 0x1B,
sensor_dev_mp2856gut = 0x1C,
sensor_dev_max
};

Expand Down
1 change: 1 addition & 0 deletions common/shell/shell_platform.h
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@ const char *const sensor_type_name[] = {
sensor_name_to_num(nct7718w) sensor_name_to_num(ltc4286)
sensor_name_to_num(amd_tsi) sensor_name_to_num(apml_mailbox)
sensor_name_to_num(xdpe19283b) sensor_name_to_num(g788p81u)
sensor_name_to_num(mp2856gut)
};

const char *const sensor_status_name[] = {
Expand Down
101 changes: 101 additions & 0 deletions meta-facebook/yv35-hd/src/platform/plat_sensor_table.c
Original file line number Diff line number Diff line change
Expand Up @@ -359,6 +359,101 @@ sensor_cfg EVT_BOM2_sensor_config_table[] = {
NULL, NULL },
};

sensor_cfg EVT_BOM3_sensor_config_table[] = {
/* HSC temperature sensor */
{ SENSOR_NUM_TEMP_HSC, sensor_dev_g788p81u, I2C_BUS5, TEMP_HSC_ADDR,
G788P81U_REMOTE_TEMP_OFFSET, stby_access, 0, 0, SAMPLE_COUNT_DEFAULT, POLL_TIME_DEFAULT,
ENABLE_SENSOR_POLLING, 0, SENSOR_INIT_STATUS, NULL, NULL, NULL, NULL, NULL },

/* VR voltage */
{ SENSOR_NUM_VOL_PVDDCR_CPU0_VR, sensor_dev_mp2856gut, I2C_BUS5, MP2856GUT_PVDDCR_CPU0_ADDR,
PMBUS_READ_VOUT, vr_access, 0, 0, SAMPLE_COUNT_DEFAULT, POLL_TIME_DEFAULT,
ENABLE_SENSOR_POLLING, 0, SENSOR_INIT_STATUS, pre_vr_read, &vr_pre_read_args[0], NULL,
NULL, NULL },
{ SENSOR_NUM_VOL_PVDDCR_SOC_VR, sensor_dev_mp2856gut, I2C_BUS5, MP2856GUT_PVDDCR_SOC_ADDR,
PMBUS_READ_VOUT, vr_access, 0, 0, SAMPLE_COUNT_DEFAULT, POLL_TIME_DEFAULT,
ENABLE_SENSOR_POLLING, 0, SENSOR_INIT_STATUS, pre_vr_read, &vr_pre_read_args[1], NULL,
NULL, NULL },
{ SENSOR_NUM_VOL_PVDDCR_CPU1_VR, sensor_dev_mp2856gut, I2C_BUS5, MP2856GUT_PVDDCR_CPU1_ADDR,
PMBUS_READ_VOUT, vr_access, 0, 0, SAMPLE_COUNT_DEFAULT, POLL_TIME_DEFAULT,
ENABLE_SENSOR_POLLING, 0, SENSOR_INIT_STATUS, pre_vr_read, &vr_pre_read_args[0], NULL,
NULL, NULL },
{ SENSOR_NUM_VOL_PVDDIO_VR, sensor_dev_mp2856gut, I2C_BUS5, MP2856GUT_PVDDIO_ADDR,
PMBUS_READ_VOUT, vr_access, 0, 0, SAMPLE_COUNT_DEFAULT, POLL_TIME_DEFAULT,
ENABLE_SENSOR_POLLING, 0, SENSOR_INIT_STATUS, pre_vr_read, &vr_pre_read_args[1], NULL,
NULL, NULL },
{ SENSOR_NUM_VOL_PVDD11_S3_VR, sensor_dev_mp2856gut, I2C_BUS5, MP2856GUT_PVDD11_S3_ADDR,
PMBUS_READ_VOUT, vr_access, 0, 0, SAMPLE_COUNT_DEFAULT, POLL_TIME_DEFAULT,
ENABLE_SENSOR_POLLING, 0, SENSOR_INIT_STATUS, pre_vr_read, &vr_pre_read_args[0], NULL,
NULL, NULL },

/* VR current */
{ SENSOR_NUM_CUR_PVDDCR_CPU0_VR, sensor_dev_mp2856gut, I2C_BUS5, MP2856GUT_PVDDCR_CPU0_ADDR,
PMBUS_READ_IOUT, vr_access, 0, 0, SAMPLE_COUNT_DEFAULT, POLL_TIME_DEFAULT,
ENABLE_SENSOR_POLLING, 0, SENSOR_INIT_STATUS, pre_vr_read, &vr_pre_read_args[0], NULL,
NULL, NULL },
{ SENSOR_NUM_CUR_PVDDCR_SOC_VR, sensor_dev_mp2856gut, I2C_BUS5, MP2856GUT_PVDDCR_SOC_ADDR,
PMBUS_READ_IOUT, vr_access, 0, 0, SAMPLE_COUNT_DEFAULT, POLL_TIME_DEFAULT,
ENABLE_SENSOR_POLLING, 0, SENSOR_INIT_STATUS, pre_vr_read, &vr_pre_read_args[1], NULL,
NULL, NULL },
{ SENSOR_NUM_CUR_PVDDCR_CPU1_VR, sensor_dev_mp2856gut, I2C_BUS5, MP2856GUT_PVDDCR_CPU1_ADDR,
PMBUS_READ_IOUT, vr_access, 0, 0, SAMPLE_COUNT_DEFAULT, POLL_TIME_DEFAULT,
ENABLE_SENSOR_POLLING, 0, SENSOR_INIT_STATUS, pre_vr_read, &vr_pre_read_args[0], NULL,
NULL, NULL },
{ SENSOR_NUM_CUR_PVDDIO_VR, sensor_dev_mp2856gut, I2C_BUS5, MP2856GUT_PVDDIO_ADDR,
PMBUS_READ_IOUT, vr_access, 0, 0, SAMPLE_COUNT_DEFAULT, POLL_TIME_DEFAULT,
ENABLE_SENSOR_POLLING, 0, SENSOR_INIT_STATUS, pre_vr_read, &vr_pre_read_args[1], NULL,
NULL, NULL },
{ SENSOR_NUM_CUR_PVDD11_S3_VR, sensor_dev_mp2856gut, I2C_BUS5, MP2856GUT_PVDD11_S3_ADDR,
PMBUS_READ_IOUT, vr_access, 0, 0, SAMPLE_COUNT_DEFAULT, POLL_TIME_DEFAULT,
ENABLE_SENSOR_POLLING, 0, SENSOR_INIT_STATUS, pre_vr_read, &vr_pre_read_args[0], NULL,
NULL, NULL },

/* VR temperature */
{ SENSOR_NUM_TEMP_PVDDCR_CPU0_VR, sensor_dev_mp2856gut, I2C_BUS5,
MP2856GUT_PVDDCR_CPU0_ADDR, PMBUS_READ_TEMPERATURE_1, vr_access, 0, 0,
SAMPLE_COUNT_DEFAULT, POLL_TIME_DEFAULT, ENABLE_SENSOR_POLLING, 0, SENSOR_INIT_STATUS,
pre_vr_read, &vr_pre_read_args[0], NULL, NULL, NULL },
{ SENSOR_NUM_TEMP_PVDDCR_SOC_VR, sensor_dev_mp2856gut, I2C_BUS5, MP2856GUT_PVDDCR_SOC_ADDR,
PMBUS_READ_TEMPERATURE_1, vr_access, 0, 0, SAMPLE_COUNT_DEFAULT, POLL_TIME_DEFAULT,
ENABLE_SENSOR_POLLING, 0, SENSOR_INIT_STATUS, pre_vr_read, &vr_pre_read_args[1], NULL,
NULL, NULL },
{ SENSOR_NUM_TEMP_PVDDCR_CPU1_VR, sensor_dev_mp2856gut, I2C_BUS5,
MP2856GUT_PVDDCR_CPU1_ADDR, PMBUS_READ_TEMPERATURE_1, vr_access, 0, 0,
SAMPLE_COUNT_DEFAULT, POLL_TIME_DEFAULT, ENABLE_SENSOR_POLLING, 0, SENSOR_INIT_STATUS,
pre_vr_read, &vr_pre_read_args[0], NULL, NULL, NULL },
{ SENSOR_NUM_TEMP_PVDDIO_VR, sensor_dev_mp2856gut, I2C_BUS5, MP2856GUT_PVDDIO_ADDR,
PMBUS_READ_TEMPERATURE_1, vr_access, 0, 0, SAMPLE_COUNT_DEFAULT, POLL_TIME_DEFAULT,
ENABLE_SENSOR_POLLING, 0, SENSOR_INIT_STATUS, pre_vr_read, &vr_pre_read_args[1], NULL,
NULL, NULL },
{ SENSOR_NUM_TEMP_PVDD11_S3_VR, sensor_dev_mp2856gut, I2C_BUS5, MP2856GUT_PVDD11_S3_ADDR,
PMBUS_READ_TEMPERATURE_1, vr_access, 0, 0, SAMPLE_COUNT_DEFAULT, POLL_TIME_DEFAULT,
ENABLE_SENSOR_POLLING, 0, SENSOR_INIT_STATUS, pre_vr_read, &vr_pre_read_args[0], NULL,
NULL, NULL },

/* VR power */
{ SENSOR_NUM_PWR_PVDDCR_CPU0_VR, sensor_dev_mp2856gut, I2C_BUS5, MP2856GUT_PVDDCR_CPU0_ADDR,
PMBUS_READ_POUT, vr_access, 0, 0, SAMPLE_COUNT_DEFAULT, POLL_TIME_DEFAULT,
ENABLE_SENSOR_POLLING, 0, SENSOR_INIT_STATUS, pre_vr_read, &vr_pre_read_args[0], NULL,
NULL, NULL },
{ SENSOR_NUM_PWR_PVDDCR_SOC_VR, sensor_dev_mp2856gut, I2C_BUS5, MP2856GUT_PVDDCR_SOC_ADDR,
PMBUS_READ_POUT, vr_access, 0, 0, SAMPLE_COUNT_DEFAULT, POLL_TIME_DEFAULT,
ENABLE_SENSOR_POLLING, 0, SENSOR_INIT_STATUS, pre_vr_read, &vr_pre_read_args[1], NULL,
NULL, NULL },
{ SENSOR_NUM_PWR_PVDDCR_CPU1_VR, sensor_dev_mp2856gut, I2C_BUS5, MP2856GUT_PVDDCR_CPU1_ADDR,
PMBUS_READ_POUT, vr_access, 0, 0, SAMPLE_COUNT_DEFAULT, POLL_TIME_DEFAULT,
ENABLE_SENSOR_POLLING, 0, SENSOR_INIT_STATUS, pre_vr_read, &vr_pre_read_args[0], NULL,
NULL, NULL },
{ SENSOR_NUM_PWR_PVDDIO_VR, sensor_dev_mp2856gut, I2C_BUS5, MP2856GUT_PVDDIO_ADDR,
PMBUS_READ_POUT, vr_access, 0, 0, SAMPLE_COUNT_DEFAULT, POLL_TIME_DEFAULT,
ENABLE_SENSOR_POLLING, 0, SENSOR_INIT_STATUS, pre_vr_read, &vr_pre_read_args[1], NULL,
NULL, NULL },
{ SENSOR_NUM_PWR_PVDD11_S3_VR, sensor_dev_mp2856gut, I2C_BUS5, MP2856GUT_PVDD11_S3_ADDR,
PMBUS_READ_POUT, vr_access, 0, 0, SAMPLE_COUNT_DEFAULT, POLL_TIME_DEFAULT,
ENABLE_SENSOR_POLLING, 0, SENSOR_INIT_STATUS, pre_vr_read, &vr_pre_read_args[0], NULL,
NULL, NULL },
};

void pal_extend_sensor_config()
{
uint8_t sensor_count = 0;
Expand Down Expand Up @@ -391,6 +486,12 @@ void pal_extend_sensor_config()
add_sensor_config(EVT_BOM2_sensor_config_table[index]);
}
break;
case SYS_BOARD_EVT_BOM3:
sensor_count = ARRAY_SIZE(EVT_BOM3_sensor_config_table);
for (int index = 0; index < sensor_count; index++) {
add_sensor_config(EVT_BOM3_sensor_config_table[index]);
}
break;
default:
break;
}
Expand Down
6 changes: 6 additions & 0 deletions meta-facebook/yv35-hd/src/platform/plat_sensor_table.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,12 @@
#define XDPE19283B_PVDDIO_ADDR 0x66
#define XDPE19283B_PVDD11_S3_ADDR 0x68

#define MP2856GUT_PVDDCR_CPU0_ADDR 0x4F
#define MP2856GUT_PVDDCR_SOC_ADDR 0x4F
#define MP2856GUT_PVDDCR_CPU1_ADDR 0x4E
#define MP2856GUT_PVDDIO_ADDR 0x4E
#define MP2856GUT_PVDD11_S3_ADDR 0x4B

#define ADM1278_ADDR (0x80 >> 1)
#define LTC4282_ADDR (0x82 >> 1)
#define TEMP_HSC_ADDR (0x98 >> 1)
Expand Down

0 comments on commit 81d2c41

Please sign in to comment.