mirror of
https://github.com/Telecominfraproject/OpenNetworkLinux.git
synced 2025-12-26 01:37:04 +00:00
Merge pull request #142 from brandonchuang/master
[as5710] Support DC12V power supply(PSU-12V-650)
This commit is contained in:
@@ -121,26 +121,28 @@ int deviceNodeReadString(char *filename, char *buffer, int buf_size, int data_le
|
||||
}
|
||||
|
||||
#define I2C_PSU_MODEL_NAME_LEN 13
|
||||
#define I2C_PSU_FAN_DIR_LEN 3
|
||||
|
||||
psu_type_t get_psu_type(int id, char* modelname, int modelname_len)
|
||||
{
|
||||
char *node = NULL;
|
||||
char model_name[I2C_PSU_MODEL_NAME_LEN + 1] = {0};
|
||||
char fan_dir[I2C_PSU_FAN_DIR_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);
|
||||
|
||||
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);
|
||||
}
|
||||
if (modelname) {
|
||||
strncpy(modelname, model_name, 13);
|
||||
}
|
||||
return PSU_TYPE_AC_F2B;
|
||||
}
|
||||
else if (strncmp(model_name, "CPR-4011-4M21", strlen("CPR-4011-4M21")) == 0) {
|
||||
if (modelname) {
|
||||
strncpy(modelname, model_name, modelname_len-1);
|
||||
}
|
||||
if (modelname) {
|
||||
strncpy(modelname, model_name, 13);
|
||||
}
|
||||
return PSU_TYPE_AC_B2F;
|
||||
}
|
||||
}
|
||||
@@ -151,17 +153,40 @@ psu_type_t get_psu_type(int id, char* modelname, int modelname_len)
|
||||
|
||||
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 (modelname) {
|
||||
strncpy(modelname, model_name, 9);
|
||||
}
|
||||
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);
|
||||
}
|
||||
if (modelname) {
|
||||
strncpy(modelname, model_name, 12);
|
||||
}
|
||||
return PSU_TYPE_DC_48V_F2B;
|
||||
}
|
||||
|
||||
if (strncmp(model_name, "PSU-12V-650", 11) == 0) {
|
||||
if (modelname) {
|
||||
strncpy(modelname, model_name, 11);
|
||||
}
|
||||
|
||||
node = (id == PSU1_ID) ? PSU1_DC_HWMON_NODE(psu_fan_dir) : PSU2_DC_HWMON_NODE(psu_fan_dir);
|
||||
if (deviceNodeReadString(node, fan_dir, sizeof(fan_dir), 0) != 0) {
|
||||
return PSU_TYPE_UNKNOWN;
|
||||
}
|
||||
|
||||
if (strncmp(fan_dir, "F2B", 3) == 0) {
|
||||
return PSU_TYPE_DC_12V_F2B;
|
||||
}
|
||||
|
||||
if (strncmp(fan_dir, "B2F", 3) == 0) {
|
||||
return PSU_TYPE_DC_12V_B2F;
|
||||
}
|
||||
|
||||
if (strncmp(fan_dir, "NON", 3) == 0) {
|
||||
return PSU_TYPE_DC_12V_FANLESS;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return PSU_TYPE_UNKNOWN;
|
||||
|
||||
@@ -63,7 +63,10 @@ typedef enum psu_type {
|
||||
PSU_TYPE_AC_F2B,
|
||||
PSU_TYPE_AC_B2F,
|
||||
PSU_TYPE_DC_48V_F2B,
|
||||
PSU_TYPE_DC_48V_B2F
|
||||
PSU_TYPE_DC_48V_B2F,
|
||||
PSU_TYPE_DC_12V_F2B,
|
||||
PSU_TYPE_DC_12V_B2F,
|
||||
PSU_TYPE_DC_12V_FANLESS
|
||||
} psu_type_t;
|
||||
|
||||
psu_type_t get_psu_type(int id, char* modelname, int modelname_len);
|
||||
|
||||
@@ -169,6 +169,56 @@ psu_um400d_info_get(onlp_psu_info_t* info)
|
||||
return ONLP_STATUS_OK;
|
||||
}
|
||||
|
||||
#include <onlplib/i2c.h>
|
||||
#define DC12V_650_REG_TO_CURRENT(low, high) (((low << 4 | high >> 4) * 20 * 1000) / 754)
|
||||
#define DC12V_650_REG_TO_VOLTAGE(low, high) ((low << 4 | high >> 4) * 25)
|
||||
|
||||
static int
|
||||
psu_dc12v_650_info_get(onlp_psu_info_t* info)
|
||||
{
|
||||
int pid = ONLP_OID_ID_GET(info->hdr.id);
|
||||
int bus = (PSU1_ID == pid) ? 5 : 6;
|
||||
int iout_low, iout_high;
|
||||
int vout_low, vout_high;
|
||||
|
||||
/* Set capability
|
||||
*/
|
||||
info->caps = ONLP_PSU_CAPS_DC12;
|
||||
|
||||
if (info->status & ONLP_PSU_STATUS_FAILED) {
|
||||
return ONLP_STATUS_OK;
|
||||
}
|
||||
|
||||
/* Get current
|
||||
*/
|
||||
iout_low = onlp_i2c_readb(bus, 0x6f, 0x0, ONLP_I2C_F_FORCE);
|
||||
iout_high = onlp_i2c_readb(bus, 0x6f, 0x1, ONLP_I2C_F_FORCE);
|
||||
|
||||
if ((iout_low >= 0) && (iout_high >= 0)) {
|
||||
info->miout = DC12V_650_REG_TO_CURRENT(iout_low, iout_high);
|
||||
info->caps |= ONLP_PSU_CAPS_IOUT;
|
||||
}
|
||||
|
||||
/* Get voltage
|
||||
*/
|
||||
vout_low = onlp_i2c_readb(bus, 0x6f, 0x2, ONLP_I2C_F_FORCE);
|
||||
vout_high = onlp_i2c_readb(bus, 0x6f, 0x3, ONLP_I2C_F_FORCE);
|
||||
|
||||
if ((vout_low >= 0) && (vout_high >= 0)) {
|
||||
info->mvout = DC12V_650_REG_TO_VOLTAGE(vout_low, vout_high);
|
||||
info->caps |= ONLP_PSU_CAPS_VOUT;
|
||||
}
|
||||
|
||||
/* Get power based on current and voltage
|
||||
*/
|
||||
if ((info->caps & ONLP_PSU_CAPS_IOUT) && (info->caps & ONLP_PSU_CAPS_VOUT)) {
|
||||
info->mpout = (info->miout * info->mvout) / 1000;
|
||||
info->caps |= ONLP_PSU_CAPS_POUT;
|
||||
}
|
||||
|
||||
return ONLP_STATUS_OK;
|
||||
}
|
||||
|
||||
/*
|
||||
* Get all information about the given PSU oid.
|
||||
*/
|
||||
@@ -231,6 +281,11 @@ onlp_psui_info_get(onlp_oid_t id, onlp_psu_info_t* info)
|
||||
case PSU_TYPE_DC_48V_B2F:
|
||||
ret = psu_um400d_info_get(info);
|
||||
break;
|
||||
case PSU_TYPE_DC_12V_F2B:
|
||||
case PSU_TYPE_DC_12V_B2F:
|
||||
case PSU_TYPE_DC_12V_FANLESS:
|
||||
ret = psu_dc12v_650_info_get(info);
|
||||
break;
|
||||
default:
|
||||
ret = ONLP_STATUS_E_UNSUPPORTED;
|
||||
break;
|
||||
|
||||
Reference in New Issue
Block a user