Skip to content
68 changes: 68 additions & 0 deletions common/dev/nct7718w.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
#include <stdio.h>
#include <string.h>
#include "sensor.h"
#include "hal_i2c.h"

uint8_t nct7718w_read(uint8_t sensor_num, int *reading)
{
if (!reading || (sensor_num > SENSOR_NUM_MAX)) {
return SENSOR_UNSPECIFIED_ERROR;
}

uint8_t retry = 5;
I2C_MSG msg = { 0 };

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 = 1;
msg.data[0] = cfg->offset;

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

float read_out = 0;

switch (cfg->offset) {
case NCT7718W_LOCAL_TEMP_OFFSET:
read_out = (int8_t)msg.data[0];
break;
case NCT7718W_REMOTE_TEMP_MSB_OFFSET:
read_out = (int8_t)msg.data[0];

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

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

read_out += 0.125 * (msg.data[0] >> 5);
break;

default:
break;
}

sensor_val *sval = (sensor_val *)reading;
memset(sval, 0, sizeof(sensor_val));
sval->integer = (int)read_out;
sval->fraction = (int)(read_out * 1000) % 1000;

return SENSOR_READ_SUCCESS;
}

uint8_t nct7718w_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 = nct7718w_read;
return SENSOR_INIT_SUCCESS;
}
72 changes: 72 additions & 0 deletions common/dev/raa229621.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
#include <stdio.h>
#include <string.h>
#include "sensor.h"
#include "hal_i2c.h"
#include "pmbus.h"

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

sensor_cfg *cfg = &sensor_config[sensor_config_index_map[sensor_num]];
uint8_t retry = 5;
uint8_t offset = cfg->offset;

I2C_MSG msg;

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

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

sensor_val *sval = (sensor_val *)reading;
memset(sval, 0, sizeof(sensor_val));
int val = 0;
val = (msg.data[1] << 8) | msg.data[0];

switch (offset) {
case PMBUS_READ_VOUT:
/* 1 mV/LSB, unsigned integer */
sval->integer = val / 1000;
sval->fraction = val % 1000;
break;
case PMBUS_READ_IOUT:
/* 0.1 A/LSB, 2's complement */
sval->integer = (int16_t)val / 10;
sval->fraction = ((int16_t)val - (sval->integer * 10)) * 100;
break;
case PMBUS_READ_TEMPERATURE_1:
/* 1 Degree C/LSB, 2's complement */
sval->integer = val;
sval->fraction = 0;
break;
case PMBUS_READ_POUT:
/* 1 Watt/LSB, 2's complement */
sval->integer = val;
sval->fraction = 0;
break;
default:
printf("[%s] not support offset: 0x%x\n", __func__, offset);
return SENSOR_FAIL_TO_ACCESS;
break;
}

return SENSOR_READ_SUCCESS;
}

uint8_t raa229621_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 = raa229621_read;
return SENSOR_INIT_SUCCESS;
}
24 changes: 11 additions & 13 deletions common/dev/xdpe12284c.c
Original file line number Diff line number Diff line change
Expand Up @@ -5,22 +5,20 @@
#include "pmbus.h"
#include "util_pmbus.h"

enum {
VR12 = 1,
VR13,
IMVP9,
enum { VR12 = 1,
VR13,
IMVP9,
};

enum {
VID_IDENTIFIER = 1,
enum { VID_IDENTIFIER = 1,
};

/* Reference: Infineon spec section 8.24: VID table
* PMBUS spec section 8.2: VOUT mode
*/
static float vid_to_float(int val, uint8_t vout_mode) {
static float vid_to_float(int val, uint8_t vout_mode)
{
uint8_t mode = 0;
uint8_t parameter = 0;

//VID 0 is always 0 V
if (val == 0) {
Expand All @@ -36,15 +34,15 @@ static float vid_to_float(int val, uint8_t vout_mode) {

switch (vout_mode & 0x1f) {
case VR12:
if(val > 0) {
if (val > 0) {
return ((val - 1) * 5 + 250);
}
case VR13:
if(val > 0) {
if (val > 0) {
return ((val - 1) * 10 + 500);
}
case IMVP9:
if(val > 0) {
if (val > 0) {
return ((val - 1) * 10 + 200);
}
default:
Expand Down Expand Up @@ -81,7 +79,7 @@ uint8_t xdpe12284c_read(uint8_t sensor_num, int *reading)

val = (msg.data[1] << 8) | msg.data[0];

switch (offset) {
switch (offset) {
case PMBUS_READ_IOUT:
case PMBUS_READ_POUT:
case PMBUS_READ_TEMPERATURE_1:
Expand All @@ -100,7 +98,7 @@ uint8_t xdpe12284c_read(uint8_t sensor_num, int *reading)
msg.tx_len = 1;
msg.rx_len = 1;
msg.data[0] = PMBUS_VOUT_MODE;

if (i2c_master_read(&msg, retry)) {
return SENSOR_FAIL_TO_ACCESS;
}
Expand Down
4 changes: 4 additions & 0 deletions common/service/sensor/sensor.c
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,8 @@ SENSOR_DRIVE_INIT_DECLARE(isl69254iraz_t);
SENSOR_DRIVE_INIT_DECLARE(max16550a);
SENSOR_DRIVE_INIT_DECLARE(ina230);
SENSOR_DRIVE_INIT_DECLARE(xdpe12284c);
SENSOR_DRIVE_INIT_DECLARE(raa229621);
SENSOR_DRIVE_INIT_DECLARE(nct7718w);

struct sensor_drive_api {
enum SENSOR_DEV dev;
Expand All @@ -87,6 +89,8 @@ struct sensor_drive_api {
SENSOR_DRIVE_TYPE_INIT_MAP(max16550a),
SENSOR_DRIVE_TYPE_INIT_MAP(ina230),
SENSOR_DRIVE_TYPE_INIT_MAP(xdpe12284c),
SENSOR_DRIVE_TYPE_INIT_MAP(raa229621),
SENSOR_DRIVE_TYPE_INIT_MAP(nct7718w),
};

static void init_sensor_num(void)
Expand Down
34 changes: 20 additions & 14 deletions common/service/sensor/sensor.h
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,12 @@ enum ADM1278_OFFSET {
ADM1278_EIN_EXT_OFFSET = 0xDC,
};

enum NCT7718W_OFFSET {
NCT7718W_LOCAL_TEMP_OFFSET = 0x00,
NCT7718W_REMOTE_TEMP_MSB_OFFSET = 0x01,
NCT7718W_REMOTE_TEMP_LSB_OFFSET = 0x10,
};

enum INA230_OFFSET {
INA230_CFG_OFFSET = 0x00,
INA230_VSH_VOL_OFFSET = 0x01,
Expand Down Expand Up @@ -72,6 +78,8 @@ enum SENSOR_DEV {
sensor_dev_max16550a = 0x12,
sensor_dev_ina230 = 0x13,
sensor_dev_xdpe12284c = 0x14,
sensor_dev_raa229621 = 0x15,
sensor_dev_nct7718w = 0x16,
sensor_dev_max
};

Expand Down Expand Up @@ -110,20 +118,18 @@ static inline float convert_MBR_to_reading(uint8_t sensor_num, uint8_t val)
return (val - round_add(sensor_num, val)) * SDR_M(sensor_num) / SDR_Rexp(sensor_num);
}

enum {
SENSOR_READ_SUCCESS,
SENSOR_READ_ACUR_SUCCESS,
SENSOR_NOT_FOUND,
SENSOR_NOT_ACCESSIBLE,
SENSOR_FAIL_TO_ACCESS,
SENSOR_INIT_STATUS,
SENSOR_UNSPECIFIED_ERROR,
SENSOR_POLLING_DISABLE,
SENSOR_PRE_READ_ERROR,
SENSOR_POST_READ_ERROR,
SENSOR_READ_API_UNREGISTER,
SENSOR_READ_4BYTE_ACUR_SUCCESS
};
enum { SENSOR_READ_SUCCESS,
SENSOR_READ_ACUR_SUCCESS,
SENSOR_NOT_FOUND,
SENSOR_NOT_ACCESSIBLE,
SENSOR_FAIL_TO_ACCESS,
SENSOR_INIT_STATUS,
SENSOR_UNSPECIFIED_ERROR,
SENSOR_POLLING_DISABLE,
SENSOR_PRE_READ_ERROR,
SENSOR_POST_READ_ERROR,
SENSOR_READ_API_UNREGISTER,
SENSOR_READ_4BYTE_ACUR_SUCCESS };

enum { SENSOR_INIT_SUCCESS, SENSOR_INIT_UNSPECIFIED_ERROR };

Expand Down
17 changes: 9 additions & 8 deletions common/shell/shell_platform.h
Original file line number Diff line number Diff line change
Expand Up @@ -62,14 +62,15 @@ enum GPIO_ACCESS { GPIO_READ, GPIO_WRITE };
const char *const sensor_type_name[] = {
sensor_name_to_num(tmp75) sensor_name_to_num(adc) sensor_name_to_num(
peci) sensor_name_to_num(isl69259) sensor_name_to_num(hsc) sensor_name_to_num(nvme)
sensor_name_to_num(pch) sensor_name_to_num(mp5990) sensor_name_to_num(isl28022)
sensor_name_to_num(pex89000) sensor_name_to_num(tps53689)
sensor_name_to_num(xdpe15284) sensor_name_to_num(ltc4282)
sensor_name_to_num(fan) sensor_name_to_num(tmp431)
sensor_name_to_num(pmic) sensor_name_to_num(ina233)
sensor_name_to_num(isl69254)
sensor_name_to_num(max16550a)
sensor_name_to_num(ina230)
sensor_name_to_num(pch) sensor_name_to_num(mp5990) sensor_name_to_num(
isl28022) sensor_name_to_num(pex89000) sensor_name_to_num(tps53689)
sensor_name_to_num(xdpe15284) sensor_name_to_num(
ltc4282) sensor_name_to_num(fan) sensor_name_to_num(tmp431)
sensor_name_to_num(pmic) sensor_name_to_num(ina233)
sensor_name_to_num(isl69254) sensor_name_to_num(max16550a)
sensor_name_to_num(ina230)
sensor_name_to_num(raa229621)
sensor_name_to_num(nct7718w)
};

const char *const sensor_status_name[] = {
Expand Down
19 changes: 19 additions & 0 deletions meta-facebook/yv35-hd/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
# SPDX-License-Identifier: Apache-2.0

cmake_minimum_required(VERSION 3.13.1)

find_package(Zephyr REQUIRED HINTS $ENV{ZEPHYR_BASE})
project(yv35-hd)

set(common_path ../../common)
FILE(GLOB app_sources src/ipmi/*.c src/platform/*.c src/lib/*.c)
FILE(GLOB common_sources ${common_path}/service/*.c ${common_path}/service/*/*.c ${common_path}/hal/*.c ${common_path}/dev/*.c ${common_path}/lib/*.c ${common_path}/shell/*.c)

target_sources(app PRIVATE ${app_sources})
target_sources(app PRIVATE ${common_sources})
target_include_directories(app PRIVATE ${ZEPHYR_BASE}/include/portability)
target_include_directories(app PRIVATE ${common_path} ${common_path}/service/ipmi/include ${common_path}/service/host ${common_path}/service/sensor ${common_path}/service/usb ${common_path}/service/ipmb ${common_path}/service/mctp ${common_path}/service/pldm ${common_path}/hal ${common_path}/dev/include ${common_path}/lib ${common_path}/shell)
target_include_directories(app PRIVATE src/ipmi/include src/lib src/platform)

# Fail build if there are any warnings
target_compile_options(app PRIVATE -Werror)
12 changes: 12 additions & 0 deletions meta-facebook/yv35-hd/boards/ast1030_evb.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
CONFIG_GPIO_ASPEED=y
CONFIG_SPI_ASPEED=y
CONFIG_I2C_ASPEED=y
CONFIG_ADC_ASPEED=y
CONFIG_JTAG_ASPEED=y
CONFIG_ESPI_ASPEED=y
CONFIG_USB_ASPEED=y
CONFIG_WDT_ASPEED=y

CONFIG_ADC_ASPEED_ACQUISITION_THREAD_STACK_SIZE=512
CONFIG_SYSTEM_WORKQUEUE_STACK_SIZE=2048
CONFIG_IDLE_STACK_SIZE=512
Loading