From 80975cd4fc9182921d1a31c8d14ad0ec6a9a5591 Mon Sep 17 00:00:00 2001 From: brandonchuang Date: Fri, 16 Jun 2017 14:03:57 +0800 Subject: [PATCH] [as5812-54x] Support DC power and YM2401J AC power --- .../builds/x86-64-accton-as5812-54x-psu.c | 146 ++++++++++++++---- .../onlp/builds/src/module/src/fani.c | 71 ++++++--- .../onlp/builds/src/module/src/platform_lib.c | 124 ++++++++++++--- .../onlp/builds/src/module/src/platform_lib.h | 46 ++++-- .../onlp/builds/src/module/src/psui.c | 51 +++++- .../onlp/builds/src/module/src/thermali.c | 14 +- .../x86_64_accton_as5812_54x_r0/__init__.py | 9 +- 7 files changed, 362 insertions(+), 99 deletions(-) diff --git a/packages/platforms/accton/x86-64/x86-64-accton-as5812-54x/modules/builds/x86-64-accton-as5812-54x-psu.c b/packages/platforms/accton/x86-64/x86-64-accton-as5812-54x/modules/builds/x86-64-accton-as5812-54x-psu.c index 0d299807..d4c44779 100644 --- a/packages/platforms/accton/x86-64/x86-64-accton-as5812-54x/modules/builds/x86-64-accton-as5812-54x-psu.c +++ b/packages/platforms/accton/x86-64/x86-64-accton-as5812-54x/modules/builds/x86-64-accton-as5812-54x-psu.c @@ -32,15 +32,23 @@ #include #include + +#define PSU_STATUS_I2C_ADDR 0x60 +#define PSU_STATUS_I2C_REG_OFFSET 0x2 + +#define IS_POWER_GOOD(id, value) (!!(value & BIT(id*4 + 1))) +#define IS_PRESENT(id, value) (!(value & BIT(id*4))) + static ssize_t show_index(struct device *dev, struct device_attribute *da, char *buf); static ssize_t show_status(struct device *dev, struct device_attribute *da, char *buf); static ssize_t show_model_name(struct device *dev, struct device_attribute *da, char *buf); static int as5812_54x_psu_read_block(struct i2c_client *client, u8 command, u8 *data,int data_len); extern int as5812_54x_i2c_cpld_read(unsigned short cpld_addr, u8 reg); +static int as5812_54x_psu_model_name_get(struct device *dev); /* Addresses scanned */ -static const unsigned short normal_i2c[] = { 0x38, 0x3b, 0x50, 0x53, I2C_CLIENT_END }; +static const unsigned short normal_i2c[] = { I2C_CLIENT_END }; /* Each client has this additional data */ @@ -94,11 +102,15 @@ static ssize_t show_status(struct device *dev, struct device_attribute *da, struct as5812_54x_psu_data *data = as5812_54x_psu_update_device(dev); u8 status = 0; + if (!data->valid) { + return sprintf(buf, "0\n"); + } + if (attr->index == PSU_PRESENT) { - status = !(data->status >> ((data->index - 1) * 4) & 0x1); + status = IS_PRESENT(data->index, data->status); } else { /* PSU_POWER_GOOD */ - status = data->status >> ((data->index - 1) * 4 + 1) & 0x1; + status = IS_POWER_GOOD(data->index, data->status); } return sprintf(buf, "%d\n", status); @@ -109,7 +121,19 @@ static ssize_t show_model_name(struct device *dev, struct device_attribute *da, { struct as5812_54x_psu_data *data = as5812_54x_psu_update_device(dev); - return sprintf(buf, "%s", data->model_name); + if (!data->valid) { + return 0; + } + + if (!IS_PRESENT(data->index, data->status)) { + return 0; + } + + if (as5812_54x_psu_model_name_get(dev) < 0) { + return -ENXIO; + } + + return sprintf(buf, "%s\n", data->model_name); } static const struct attribute_group as5812_54x_psu_group = { @@ -135,6 +159,7 @@ static int as5812_54x_psu_probe(struct i2c_client *client, i2c_set_clientdata(client, data); data->valid = 0; + data->index = dev_id->driver_data; mutex_init(&data->update_lock); dev_info(&client->dev, "chip found\n"); @@ -151,14 +176,6 @@ static int as5812_54x_psu_probe(struct i2c_client *client, goto exit_remove; } - /* Update PSU index */ - if (client->addr == 0x38 || client->addr == 0x50) { - data->index = 1; - } - else if (client->addr == 0x3b || client->addr == 0x53) { - data->index = 2; - } - dev_info(&client->dev, "%s: psu '%s'\n", dev_name(data->hwmon_dev), client->name); @@ -184,8 +201,15 @@ static int as5812_54x_psu_remove(struct i2c_client *client) return 0; } +enum psu_index +{ + as5812_54x_psu1, + as5812_54x_psu2 +}; + static const struct i2c_device_id as5812_54x_psu_id[] = { - { "as5812_54x_psu", 0 }, + { "as5812_54x_psu1", as5812_54x_psu1 }, + { "as5812_54x_psu2", as5812_54x_psu2 }, {} }; MODULE_DEVICE_TABLE(i2c, as5812_54x_psu_id); @@ -219,6 +243,76 @@ abort: return result; } +enum psu_type { + PSU_YM_2401_JCR, /* AC110V - F2B */ + PSU_YM_2401_JDR, /* AC110V - B2F */ + PSU_CPR_4011_4M11, /* AC110V - F2B */ + PSU_CPR_4011_4M21, /* AC110V - B2F */ + PSU_CPR_6011_2M11, /* AC110V - F2B */ + PSU_CPR_6011_2M21, /* AC110V - B2F */ + PSU_UM400D_01G, /* DC48V - F2B */ + PSU_UM400D01_01G /* DC48V - B2F */ +}; + +struct model_name_info { + enum psu_type type; + u8 offset; + u8 length; + char* model_name; +}; + +struct model_name_info models[] = { +{PSU_YM_2401_JCR, 0x20, 11, "YM-2401JCR"}, +{PSU_YM_2401_JDR, 0x20, 11, "YM-2401JDR"}, +{PSU_CPR_4011_4M11, 0x26, 13, "CPR-4011-4M11"}, +{PSU_CPR_4011_4M21, 0x26, 13, "CPR-4011-4M21"}, +{PSU_CPR_6011_2M11, 0x26, 13, "CPR-6011-2M11"}, +{PSU_CPR_6011_2M21, 0x26, 13, "CPR-6011-2M21"}, +{PSU_UM400D_01G, 0x50, 9, "um400d01G"}, +{PSU_UM400D01_01G, 0x50, 12, "um400d01-01G"}, +}; + +static int as5812_54x_psu_model_name_get(struct device *dev) +{ + struct i2c_client *client = to_i2c_client(dev); + struct as5812_54x_psu_data *data = i2c_get_clientdata(client); + int i, status; + + for (i = 0; i < ARRAY_SIZE(models); i++) { + memset(data->model_name, 0, sizeof(data->model_name)); + + status = as5812_54x_psu_read_block(client, models[i].offset, + data->model_name, models[i].length); + if (status < 0) { + data->model_name[0] = '\0'; + dev_dbg(&client->dev, "unable to read model name from (0x%x) offset(0x%x)\n", + client->addr, models[i].offset); + return status; + } + else { + data->model_name[models[i].length] = '\0'; + } + + if (i == PSU_YM_2401_JCR || i == PSU_YM_2401_JDR) { + /* Skip the meaningless data byte 8*/ + data->model_name[8] = data->model_name[9]; + data->model_name[9] = data->model_name[10]; + data->model_name[10] = '\0'; + } + + /* Determine if the model name is known, if not, read next index + */ + if (strncmp(data->model_name, models[i].model_name, models[i].length) == 0) { + return 0; + } + else { + data->model_name[0] = '\0'; + } + } + + return -ENODATA; +} + static struct as5812_54x_psu_data *as5812_54x_psu_update_device(struct device *dev) { struct i2c_client *client = to_i2c_client(dev); @@ -231,32 +325,15 @@ static struct as5812_54x_psu_data *as5812_54x_psu_update_device(struct device *d int status = -1; dev_dbg(&client->dev, "Starting as5812_54x update\n"); + data->valid = 0; - /* Read model name */ - if (client->addr == 0x38 || client->addr == 0x3b) { - /* AC power */ - status = as5812_54x_psu_read_block(client, 0x26, data->model_name, - ARRAY_SIZE(data->model_name)-1); - } - else { - /* DC power */ - status = as5812_54x_psu_read_block(client, 0x50, data->model_name, - ARRAY_SIZE(data->model_name)-1); - } - - if (status < 0) { - data->model_name[0] = '\0'; - dev_dbg(&client->dev, "unable to read model name from (0x%x)\n", client->addr); - } - else { - data->model_name[ARRAY_SIZE(data->model_name)-1] = '\0'; - } /* Read psu status */ - status = as5812_54x_i2c_cpld_read(0x60, 0x2); + status = as5812_54x_i2c_cpld_read(PSU_STATUS_I2C_ADDR, PSU_STATUS_I2C_REG_OFFSET); if (status < 0) { - dev_dbg(&client->dev, "cpld reg 0x60 err %d\n", status); + dev_dbg(&client->dev, "cpld reg (0x%x) err %d\n", PSU_STATUS_I2C_ADDR, status); + goto exit; } else { data->status = status; @@ -266,6 +343,7 @@ static struct as5812_54x_psu_data *as5812_54x_psu_update_device(struct device *d data->valid = 1; } +exit: mutex_unlock(&data->update_lock); return data; diff --git a/packages/platforms/accton/x86-64/x86-64-accton-as5812-54x/onlp/builds/src/module/src/fani.c b/packages/platforms/accton/x86-64/x86-64-accton-as5812-54x/onlp/builds/src/module/src/fani.c index fa1e588e..4e76e24c 100644 --- a/packages/platforms/accton/x86-64/x86-64-accton-as5812-54x/onlp/builds/src/module/src/fani.c +++ b/packages/platforms/accton/x86-64/x86-64-accton-as5812-54x/onlp/builds/src/module/src/fani.c @@ -24,7 +24,8 @@ * ***********************************************************/ #include -#include +#include +#include #include #include "platform_lib.h" @@ -135,11 +136,11 @@ onlp_fan_info_t linfo[] = { /* PSU relative marco */ -#define SET_PSU_TYPE_CPR_4011_F2B_FAN(info) \ +#define SET_PSU_TYPE_AC_F2B_FAN(info) \ info->status |= (ONLP_FAN_STATUS_PRESENT | ONLP_FAN_STATUS_F2B); \ info->caps |= ONLP_FAN_CAPS_SET_PERCENTAGE | ONLP_FAN_CAPS_GET_RPM | ONLP_FAN_CAPS_GET_PERCENTAGE -#define SET_PSU_TYPE_CPR_4011_B2F_FAN(info) \ +#define SET_PSU_TYPE_AC_B2F_FAN(info) \ info->status |= (ONLP_FAN_STATUS_PRESENT | ONLP_FAN_STATUS_B2F); \ info->caps |= ONLP_FAN_CAPS_SET_PERCENTAGE | ONLP_FAN_CAPS_GET_RPM | ONLP_FAN_CAPS_GET_PERCENTAGE @@ -199,10 +200,26 @@ _onlp_fani_info_get_fan(int local_id, onlp_fan_info_t* info) return ONLP_STATUS_OK; } +static int +_onlp_fani_info_get_fan_on_psu_ym2401(int pid, onlp_fan_info_t* info) +{ + int val = 0; + + /* get fan status + */ + if (psu_ym2401_pmbus_info_get(pid, "psu_fan1_speed_rpm", &val) == ONLP_STATUS_OK) { + info->status |= (val > 0) ? 0 : ONLP_FAN_STATUS_FAILED; + info->rpm = val; + info->percentage = (info->rpm * 100) / 21600; + } + + return ONLP_STATUS_OK; +} + static int _onlp_fani_info_get_fan_on_psu(int local_id, onlp_fan_info_t* info) { - int psu_id, is_ac=0; + int psu_id; int fd, len, nbytes = 10; char r_data[10] = {0}; char fullpath[50] = {0}; @@ -211,24 +228,19 @@ _onlp_fani_info_get_fan_on_psu(int local_id, onlp_fan_info_t* info) /* get fan other cap status according to psu type */ psu_id = (local_id-FAN_1_ON_PSU1) + 1; - - if (LOCAL_DEBUG) - printf("[Debug][%s][%d][psu_id: %d]\n", __FUNCTION__, __LINE__, psu_id); + DEBUG_PRINT("[psu_id: %d]", psu_id); psu_type = get_psu_type(psu_id, NULL, 0); /* psu_id = 1 , present PSU1. pus_id =2 , present PSU2 */ - - if (LOCAL_DEBUG) - printf("[Debug][%s][%d][psu_type: %d]\n", __FUNCTION__, __LINE__, psu_type); - + DEBUG_PRINT("[psu_type: %d]", psu_type); switch (psu_type) { - case PSU_TYPE_AC_F2B: - SET_PSU_TYPE_CPR_4011_F2B_FAN(info); - is_ac = 1; + case PSU_TYPE_AC_COMPUWARE_F2B: + case PSU_TYPE_AC_3YPOWER_F2B: + SET_PSU_TYPE_AC_F2B_FAN(info); break; - case PSU_TYPE_AC_B2F: - SET_PSU_TYPE_CPR_4011_B2F_FAN(info); - is_ac = 1; + case PSU_TYPE_AC_COMPUWARE_B2F: + case PSU_TYPE_AC_3YPOWER_B2F: + SET_PSU_TYPE_AC_B2F_FAN(info); break; case PSU_TYPE_DC_48V_F2B: SET_PSU_TYPE_UM400D_F2B_FAN(info); @@ -243,7 +255,8 @@ _onlp_fani_info_get_fan_on_psu(int local_id, onlp_fan_info_t* info) break; } - if (1 == is_ac) + if (psu_type == PSU_TYPE_AC_COMPUWARE_F2B || + psu_type == PSU_TYPE_AC_COMPUWARE_B2F ) { /* get fan fault status */ @@ -259,8 +272,12 @@ _onlp_fani_info_get_fan_on_psu(int local_id, onlp_fan_info_t* info) info->rpm = atoi(r_data); /* get speed percentage from rpm */ - info->percentage = (info->rpm * 100)/19328; - + info->percentage = (info->rpm * 100)/19328; + } + else if (psu_type == PSU_TYPE_AC_3YPOWER_F2B || + psu_type == PSU_TYPE_AC_3YPOWER_B2F ) + { + return _onlp_fani_info_get_fan_on_psu_ym2401(psu_id, info); } return ONLP_STATUS_OK; @@ -351,8 +368,22 @@ onlp_fani_percentage_set(onlp_oid_t id, int p) { case FAN_1_ON_PSU1: case FAN_1_ON_PSU2: + { + int psu_id; + psu_type_t psu_type; + + psu_id = local_id - FAN_1_ON_PSU1 + 1; + psu_type = get_psu_type(psu_id, NULL, 0); + + if (psu_type == PSU_TYPE_AC_3YPOWER_F2B || + psu_type == PSU_TYPE_AC_3YPOWER_B2F ) { + return psu_ym2401_pmbus_info_set(psu_id, "psu_fan1_duty_cycle_percentage", p); + } + sprintf(fullpath, "%s%s", PREFIX_PATH_ON_PSU, last_path[local_id].ctrl_speed); break; + } + default: sprintf(fullpath, "%s%s", PREFIX_PATH_ON_MAIN_BOARD, last_path[local_id].ctrl_speed); break; diff --git a/packages/platforms/accton/x86-64/x86-64-accton-as5812-54x/onlp/builds/src/module/src/platform_lib.c b/packages/platforms/accton/x86-64/x86-64-accton-as5812-54x/onlp/builds/src/module/src/platform_lib.c index 7c28f95b..75526b5f 100644 --- a/packages/platforms/accton/x86-64/x86-64-accton-as5812-54x/onlp/builds/src/module/src/platform_lib.c +++ b/packages/platforms/accton/x86-64/x86-64-accton-as5812-54x/onlp/builds/src/module/src/platform_lib.c @@ -23,12 +23,13 @@ * * ***********************************************************/ -#include #include #include #include #include #include +#include +#include #include #include "platform_lib.h" @@ -121,6 +122,7 @@ int deviceNodeReadString(char *filename, char *buffer, int buf_size, int data_le } #define I2C_PSU_MODEL_NAME_LEN 13 +#define STRLEN(x) (sizeof(x) - 1) psu_type_t get_psu_type(int id, char* modelname, int modelname_len) { @@ -128,38 +130,73 @@ psu_type_t get_psu_type(int id, char* modelname, int modelname_len) char model_name[I2C_PSU_MODEL_NAME_LEN + 1] = {0}; /* Check AC model name */ - node = (id == PSU1_ID) ? PSU1_AC_HWMON_NODE(psu_model_name) : PSU2_AC_HWMON_NODE(psu_model_name); + node = (id == PSU1_ID) ? PSU1_AC_EEPROM_NODE(psu_model_name) : PSU2_AC_EEPROM_NODE(psu_model_name); if (deviceNodeReadString(node, model_name, sizeof(model_name), 0) == 0) { - if (strncmp(model_name, "CPR-4011-4M11", strlen("CPR-4011-4M11")) == 0) { - if (modelname) { - strncpy(modelname, model_name, modelname_len-1); - } - return PSU_TYPE_AC_F2B; + if (strncmp(model_name, "CPR-4011-4M11", STRLEN("CPR-4011-4M11")) == 0) { + if (modelname) { + strncpy(modelname, model_name, sizeof(model_name)); + } + return PSU_TYPE_AC_COMPUWARE_F2B; } - else if (strncmp(model_name, "CPR-4011-4M21", strlen("CPR-4011-4M21")) == 0) { - if (modelname) { - strncpy(modelname, model_name, modelname_len-1); - } - return PSU_TYPE_AC_B2F; + else if (strncmp(model_name, "CPR-4011-4M21", STRLEN("CPR-4011-4M21")) == 0) { + if (modelname) { + strncpy(modelname, model_name, sizeof(model_name)); + } + return PSU_TYPE_AC_COMPUWARE_B2F; + } + else if (strncmp(model_name, "CPR-6011-2M11", STRLEN("CPR-6011-2M11")) == 0) { + if (modelname) { + strncpy(modelname, model_name, sizeof(model_name)); + } + return PSU_TYPE_AC_COMPUWARE_F2B; + } + else if (strncmp(model_name, "CPR-6011-2M21", STRLEN("CPR-6011-2M21")) == 0) { + if (modelname) { + strncpy(modelname, model_name, sizeof(model_name)); + } + return PSU_TYPE_AC_COMPUWARE_B2F; + } + } + + /* Check 3Y-Power AC model name */ + memset(model_name, 0, sizeof(model_name)); + node = (id == PSU1_ID) ? PSU1_AC_3YPOWER_EEPROM_NODE(psu_model_name) : PSU2_AC_3YPOWER_EEPROM_NODE(psu_model_name); + + if (deviceNodeReadString(node, model_name, sizeof(model_name), 0) == 0) { + if (strncmp(model_name, "YM-2401JCR", STRLEN("YM-2401JCR")) == 0) { + if (modelname) { + model_name[STRLEN("YM-2401JCR")] = 0; + strncpy(modelname, model_name, 11); + } + return PSU_TYPE_AC_3YPOWER_F2B; + } + else if (strncmp(model_name, "YM-2401JDR", STRLEN("YM-2401JDR")) == 0) { + if (modelname) { + model_name[STRLEN("YM-2401JDR")] = 0; + strncpy(modelname, model_name, 11); + } + return PSU_TYPE_AC_3YPOWER_B2F; } } /* Check DC model name */ memset(model_name, 0, sizeof(model_name)); - node = (id == PSU1_ID) ? PSU1_DC_HWMON_NODE(psu_model_name) : PSU2_DC_HWMON_NODE(psu_model_name); + node = (id == PSU1_ID) ? PSU1_DC_EEPROM_NODE(psu_model_name) : PSU2_DC_EEPROM_NODE(psu_model_name); if (deviceNodeReadString(node, model_name, sizeof(model_name), 0) == 0) { - if (strncmp(model_name, "um400d01G", strlen("um400d01G")) == 0) { - if (modelname) { - strncpy(modelname, model_name, modelname_len-1); - } + if (strncmp(model_name, "um400d01G", STRLEN("um400d01G")) == 0) { + if (modelname) { + model_name[STRLEN("um400d01G")] = 0; + strncpy(modelname, model_name, 10); + } return PSU_TYPE_DC_48V_B2F; } - else if (strncmp(model_name, "um400d01-01G", strlen("um400d01-01G")) == 0) { - if (modelname) { - strncpy(modelname, model_name, modelname_len-1); - } + else if (strncmp(model_name, "um400d01-01G", STRLEN("um400d01-01G")) == 0) { + if (modelname) { + model_name[STRLEN("um400d01-01G")] = 0; + strncpy(modelname, model_name, 13); + } return PSU_TYPE_DC_48V_F2B; } } @@ -167,3 +204,48 @@ psu_type_t get_psu_type(int id, char* modelname, int modelname_len) return PSU_TYPE_UNKNOWN; } +int psu_ym2401_pmbus_info_get(int id, char *node, int *value) +{ + int ret = 0; + char path[64] = {0}; + + *value = 0; + + if (PSU1_ID == id) { + sprintf(path, "%s%s", PSU1_AC_3YPOWER_PMBUS_PREFIX, node); + } + else { + sprintf(path, "%s%s", PSU2_AC_3YPOWER_PMBUS_PREFIX, node); + } + + if (onlp_file_read_int(value, path) < 0) { + AIM_LOG_ERROR("Unable to read status from file(%s)\r\n", path); + return ONLP_STATUS_E_INTERNAL; + } + + return ret; +} + +int psu_ym2401_pmbus_info_set(int id, char *node, int value) +{ + char path[64] = {0}; + + switch (id) { + case PSU1_ID: + sprintf(path, "%s%s", PSU1_AC_3YPOWER_PMBUS_PREFIX, node); + break; + case PSU2_ID: + sprintf(path, "%s%s", PSU2_AC_3YPOWER_PMBUS_PREFIX, node); + break; + default: + return ONLP_STATUS_E_UNSUPPORTED; + }; + + if (deviceNodeWriteInt(path, value, 0) < 0) { + AIM_LOG_ERROR("Unable to write data to file (%s)\r\n", path); + return ONLP_STATUS_E_INTERNAL; + } + + return ONLP_STATUS_OK; +} + diff --git a/packages/platforms/accton/x86-64/x86-64-accton-as5812-54x/onlp/builds/src/module/src/platform_lib.h b/packages/platforms/accton/x86-64/x86-64-accton-as5812-54x/onlp/builds/src/module/src/platform_lib.h index 1c8d033c..f49973e6 100644 --- a/packages/platforms/accton/x86-64/x86-64-accton-as5812-54x/onlp/builds/src/module/src/platform_lib.h +++ b/packages/platforms/accton/x86-64/x86-64-accton-as5812-54x/onlp/builds/src/module/src/platform_lib.h @@ -35,21 +35,24 @@ #define CHASSIS_THERMAL_COUNT 4 #define CHASSIS_LED_COUNT 10 -#define PSU1_AC_PMBUS_PREFIX "/sys/bus/i2c/devices/57-003c/" -#define PSU2_AC_PMBUS_PREFIX "/sys/bus/i2c/devices/58-003f/" +#define PSU1_AC_PMBUS_PREFIX "/sys/bus/i2c/devices/57-003c/" /* Compuware psu */ +#define PSU2_AC_PMBUS_PREFIX "/sys/bus/i2c/devices/58-003f/" /* Compuware psu */ +#define PSU1_AC_3YPOWER_PMBUS_PREFIX "/sys/bus/i2c/devices/57-0058/" /* 3YPower psu */ +#define PSU2_AC_3YPOWER_PMBUS_PREFIX "/sys/bus/i2c/devices/58-005b/" /* 3YPower psu */ -#define PSU1_AC_HWMON_PREFIX "/sys/bus/i2c/devices/57-0038/" -#define PSU1_DC_HWMON_PREFIX "/sys/bus/i2c/devices/57-0050/" -#define PSU2_AC_HWMON_PREFIX "/sys/bus/i2c/devices/58-003b/" -#define PSU2_DC_HWMON_PREFIX "/sys/bus/i2c/devices/58-0053/" +#define PSU1_AC_EEPROM_PREFIX "/sys/bus/i2c/devices/57-0038/" +#define PSU1_DC_EEPROM_PREFIX "/sys/bus/i2c/devices/57-0050/" +#define PSU2_AC_EEPROM_PREFIX "/sys/bus/i2c/devices/58-003b/" +#define PSU2_DC_EEPROM_PREFIX "/sys/bus/i2c/devices/58-0053/" +#define PSU1_AC_3YPOWER_EEPROM_PREFIX "/sys/bus/i2c/devices/57-0050/" +#define PSU2_AC_3YPOWER_EEPROM_PREFIX "/sys/bus/i2c/devices/58-0053/" -#define PSU1_AC_HWMON_NODE(node) PSU1_AC_HWMON_PREFIX#node -#define PSU1_DC_HWMON_NODE(node) PSU1_DC_HWMON_PREFIX#node -#define PSU2_AC_HWMON_NODE(node) PSU2_AC_HWMON_PREFIX#node -#define PSU2_DC_HWMON_NODE(node) PSU2_DC_HWMON_PREFIX#node - -//#define SFP_HWMON_PREFIX "/sys/bus/i2c/devices/3-0050/" -//#define SFP_HWMON_NODE(node) SFP_HWMON_PREFIX#node +#define PSU1_AC_EEPROM_NODE(node) PSU1_AC_EEPROM_PREFIX#node +#define PSU1_DC_EEPROM_NODE(node) PSU1_DC_EEPROM_PREFIX#node +#define PSU2_AC_EEPROM_NODE(node) PSU2_AC_EEPROM_PREFIX#node +#define PSU2_DC_EEPROM_NODE(node) PSU2_DC_EEPROM_PREFIX#node +#define PSU1_AC_3YPOWER_EEPROM_NODE(node) PSU1_AC_3YPOWER_EEPROM_PREFIX#node +#define PSU2_AC_3YPOWER_EEPROM_NODE(node) PSU2_AC_3YPOWER_EEPROM_PREFIX#node #define IDPROM_PATH "/sys/devices/pci0000:00/0000:00:13.0/i2c-1/1-0057/eeprom" @@ -59,12 +62,25 @@ int deviceNodeReadString(char *filename, char *buffer, int buf_size, int data_le typedef enum psu_type { PSU_TYPE_UNKNOWN, - PSU_TYPE_AC_F2B, - PSU_TYPE_AC_B2F, + PSU_TYPE_AC_COMPUWARE_F2B, + PSU_TYPE_AC_COMPUWARE_B2F, + PSU_TYPE_AC_3YPOWER_F2B, + PSU_TYPE_AC_3YPOWER_B2F, PSU_TYPE_DC_48V_F2B, PSU_TYPE_DC_48V_B2F } psu_type_t; psu_type_t get_psu_type(int id, char* modelname, int modelname_len); +int psu_ym2401_pmbus_info_get(int id, char *node, int *value); +int psu_ym2401_pmbus_info_set(int id, char *node, int value); + +#define DEBUG_MODE 0 + +#if (DEBUG_MODE == 1) + #define DEBUG_PRINT(fmt, args...) \ + printf("%s:%s[%d]: " fmt "\r\n", __FILE__, __FUNCTION__, __LINE__, ##args) +#else + #define DEBUG_PRINT(fmt, args...) +#endif #endif /* __PLATFORM_LIB_H__ */ diff --git a/packages/platforms/accton/x86-64/x86-64-accton-as5812-54x/onlp/builds/src/module/src/psui.c b/packages/platforms/accton/x86-64/x86-64-accton-as5812-54x/onlp/builds/src/module/src/psui.c index 0d59bd1a..7a14c060 100644 --- a/packages/platforms/accton/x86-64/x86-64-accton-as5812-54x/onlp/builds/src/module/src/psui.c +++ b/packages/platforms/accton/x86-64/x86-64-accton-as5812-54x/onlp/builds/src/module/src/psui.c @@ -24,7 +24,6 @@ * ***********************************************************/ #include -#include #include #include #include "platform_lib.h" @@ -52,10 +51,10 @@ psu_status_info_get(int id, int is_ac, char *node, int *value) *value = 0; if (PSU1_ID == id) { - sprintf(node_path, "%s%s", is_ac ? PSU1_AC_HWMON_PREFIX : PSU1_DC_HWMON_PREFIX, node); + sprintf(node_path, "%s%s", is_ac ? PSU1_AC_EEPROM_PREFIX : PSU1_DC_EEPROM_PREFIX, node); } else if (PSU2_ID == id) { - sprintf(node_path, "%s%s", is_ac ? PSU2_AC_HWMON_PREFIX : PSU2_DC_HWMON_PREFIX, node); + sprintf(node_path, "%s%s", is_ac ? PSU2_AC_EEPROM_PREFIX : PSU2_DC_EEPROM_PREFIX, node); } ret = deviceNodeReadString(node_path, buf, sizeof(buf), 0); @@ -169,6 +168,43 @@ psu_um400d_info_get(onlp_psu_info_t* info) return ONLP_STATUS_OK; } +static int +psu_ym2401_info_get(onlp_psu_info_t* info) +{ + int val = 0; + int index = ONLP_OID_ID_GET(info->hdr.id); + + /* Set capability + */ + info->caps = ONLP_PSU_CAPS_AC; + + if (info->status & ONLP_PSU_STATUS_FAILED) { + return ONLP_STATUS_OK; + } + + /* Set the associated oid_table */ + info->hdr.coids[0] = ONLP_FAN_ID_CREATE(index + CHASSIS_FAN_COUNT); + info->hdr.coids[1] = ONLP_THERMAL_ID_CREATE(index + CHASSIS_THERMAL_COUNT); + + /* Read voltage, current and power */ + if (psu_ym2401_pmbus_info_get(index, "psu_v_out", &val) == 0) { + info->mvout = val; + info->caps |= ONLP_PSU_CAPS_VOUT; + } + + if (psu_ym2401_pmbus_info_get(index, "psu_i_out", &val) == 0) { + info->miout = val; + info->caps |= ONLP_PSU_CAPS_IOUT; + } + + if (psu_ym2401_pmbus_info_get(index, "psu_p_out", &val) == 0) { + info->mpout = val; + info->caps |= ONLP_PSU_CAPS_POUT; + } + + return ONLP_STATUS_OK; +} + /* * Get all information about the given PSU oid. */ @@ -215,6 +251,7 @@ onlp_psui_info_get(onlp_oid_t id, onlp_psu_info_t* info) if (val != PSU_STATUS_POWER_GOOD) { info->status |= ONLP_PSU_STATUS_FAILED; + return 0; } @@ -223,10 +260,14 @@ onlp_psui_info_get(onlp_oid_t id, onlp_psu_info_t* info) psu_type = get_psu_type(index, info->model, sizeof(info->model)); switch (psu_type) { - case PSU_TYPE_AC_F2B: - case PSU_TYPE_AC_B2F: + case PSU_TYPE_AC_COMPUWARE_F2B: + case PSU_TYPE_AC_COMPUWARE_B2F: ret = psu_cpr_4011_info_get(info); break; + case PSU_TYPE_AC_3YPOWER_F2B: + case PSU_TYPE_AC_3YPOWER_B2F: + ret = psu_ym2401_info_get(info); + break; case PSU_TYPE_DC_48V_F2B: case PSU_TYPE_DC_48V_B2F: ret = psu_um400d_info_get(info); diff --git a/packages/platforms/accton/x86-64/x86-64-accton-as5812-54x/onlp/builds/src/module/src/thermali.c b/packages/platforms/accton/x86-64/x86-64-accton-as5812-54x/onlp/builds/src/module/src/thermali.c index 6ab6f5a5..c4b2e2e5 100644 --- a/packages/platforms/accton/x86-64/x86-64-accton-as5812-54x/onlp/builds/src/module/src/thermali.c +++ b/packages/platforms/accton/x86-64/x86-64-accton-as5812-54x/onlp/builds/src/module/src/thermali.c @@ -24,10 +24,9 @@ * ***********************************************************/ #include -#include #include #include -#include +#include "platform_lib.h" #define VALIDATE(_id) \ @@ -123,6 +122,9 @@ int onlp_thermali_info_get(onlp_oid_t id, onlp_thermal_info_t* info) { int local_id; + int psu_id; + psu_type_t psu_type; + VALIDATE(id); local_id = ONLP_OID_ID_GET(id); @@ -135,5 +137,13 @@ onlp_thermali_info_get(onlp_oid_t id, onlp_thermal_info_t* info) return rv; } + psu_id = local_id - THERMAL_1_ON_PSU1 + 1; + psu_type = get_psu_type(psu_id, NULL, 0); + + if (psu_type == PSU_TYPE_AC_3YPOWER_F2B || psu_type == PSU_TYPE_AC_3YPOWER_B2F ) { + int rv = psu_ym2401_pmbus_info_get(psu_id, "psu_temp1_input", &info->mcelsius); + return rv; + } + return onlp_file_read_int(&info->mcelsius, devfiles[local_id]); } diff --git a/packages/platforms/accton/x86-64/x86-64-accton-as5812-54x/platform-config/r0/src/python/x86_64_accton_as5812_54x_r0/__init__.py b/packages/platforms/accton/x86-64/x86-64-accton-as5812-54x/platform-config/r0/src/python/x86_64_accton_as5812_54x_r0/__init__.py index b71c2674..5eee6748 100644 --- a/packages/platforms/accton/x86-64/x86-64-accton-as5812-54x/platform-config/r0/src/python/x86_64_accton_as5812_54x_r0/__init__.py +++ b/packages/platforms/accton/x86-64/x86-64-accton-as5812-54x/platform-config/r0/src/python/x86_64_accton_as5812_54x_r0/__init__.py @@ -10,6 +10,7 @@ class OnlPlatform_x86_64_accton_as5812_54x_r0(OnlPlatformAccton, def baseconfig(self): self.insmod('cpr_4011_4mxx') + self.insmod("ym2651y") for m in [ 'cpld', 'fan', 'psu', 'leds', 'sfp' ]: self.insmod("x86-64-accton-as5812-54x-%s.ko" % m) @@ -43,12 +44,16 @@ class OnlPlatform_x86_64_accton_as5812_54x_r0(OnlPlatformAccton, ('pca9548', 0x70, 1), # initiate PSU-1 AC Power - ('as5812_54x_psu', 0x38, 57), + ('as5812_54x_psu1', 0x38, 57), ('cpr_4011_4mxx', 0x3c, 57), + ('as5812_54x_psu1', 0x50, 57), + ('ym2401', 0x58, 57), # initiate PSU-2 AC Power - ('as5812_54x_psu', 0x3b, 58), + ('as5812_54x_psu2', 0x3b, 58), ('cpr_4011_4mxx', 0x3f, 58), + ('as5812_54x_psu2', 0x53, 58), + ('ym2401', 0x5b, 58), # initiate lm75 ('lm75', 0x48, 61),