mirror of
https://github.com/Telecominfraproject/OpenNetworkLinux.git
synced 2025-12-25 17:27:01 +00:00
Merge pull request #332 from jostar-yang/as5812_0306
Add feature support to read PSU serial number on as5812-54x
This commit is contained in:
7
packages/platforms/accton/x86-64/x86-64-accton-as5812-54x/modules/builds/x86-64-accton-as5812-54x-fan.c
Normal file → Executable file
7
packages/platforms/accton/x86-64/x86-64-accton-as5812-54x/modules/builds/x86-64-accton-as5812-54x-fan.c
Normal file → Executable file
@@ -393,12 +393,7 @@ static struct platform_driver accton_as5812_54x_fan_driver = {
|
||||
static int __init accton_as5812_54x_fan_init(void)
|
||||
{
|
||||
int ret;
|
||||
|
||||
extern int platform_accton_as5812_54x(void);
|
||||
if(!platform_accton_as5812_54x()) {
|
||||
return -ENODEV;
|
||||
}
|
||||
|
||||
|
||||
ret = platform_driver_register(&accton_as5812_54x_fan_driver);
|
||||
if (ret < 0) {
|
||||
goto exit;
|
||||
|
||||
6
packages/platforms/accton/x86-64/x86-64-accton-as5812-54x/modules/builds/x86-64-accton-as5812-54x-leds.c
Normal file → Executable file
6
packages/platforms/accton/x86-64/x86-64-accton-as5812-54x/modules/builds/x86-64-accton-as5812-54x-leds.c
Normal file → Executable file
@@ -551,11 +551,7 @@ static struct platform_driver accton_as5812_54x_led_driver = {
|
||||
static int __init accton_as5812_54x_led_init(void)
|
||||
{
|
||||
int ret;
|
||||
|
||||
extern int platform_accton_as5812_54x(void);
|
||||
if(!platform_accton_as5812_54x()) {
|
||||
return -ENODEV;
|
||||
}
|
||||
|
||||
ret = platform_driver_register(&accton_as5812_54x_led_driver);
|
||||
if (ret < 0) {
|
||||
goto exit;
|
||||
|
||||
91
packages/platforms/accton/x86-64/x86-64-accton-as5812-54x/modules/builds/x86-64-accton-as5812-54x-psu.c
Normal file → Executable file
91
packages/platforms/accton/x86-64/x86-64-accton-as5812-54x/modules/builds/x86-64-accton-as5812-54x-psu.c
Normal file → Executable file
@@ -42,9 +42,10 @@
|
||||
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 ssize_t show_serial_number(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);
|
||||
static int as5812_54x_psu_model_name_get(struct device *dev , int get_serial);
|
||||
|
||||
/* Addresses scanned
|
||||
*/
|
||||
@@ -60,6 +61,7 @@ struct as5812_54x_psu_data {
|
||||
u8 index; /* PSU index */
|
||||
u8 status; /* Status(present/power_good) register read from CPLD */
|
||||
char model_name[14]; /* Model name, read from eeprom */
|
||||
char serial[16]; /* Model name, read from eeprom */
|
||||
};
|
||||
|
||||
static struct as5812_54x_psu_data *as5812_54x_psu_update_device(struct device *dev);
|
||||
@@ -68,7 +70,8 @@ enum as5812_54x_psu_sysfs_attributes {
|
||||
PSU_INDEX,
|
||||
PSU_PRESENT,
|
||||
PSU_MODEL_NAME,
|
||||
PSU_POWER_GOOD
|
||||
PSU_POWER_GOOD,
|
||||
PSU_SERIAL_NUMBER
|
||||
};
|
||||
|
||||
/* sysfs attributes for hwmon
|
||||
@@ -76,12 +79,14 @@ enum as5812_54x_psu_sysfs_attributes {
|
||||
static SENSOR_DEVICE_ATTR(psu_index, S_IRUGO, show_index, NULL, PSU_INDEX);
|
||||
static SENSOR_DEVICE_ATTR(psu_present, S_IRUGO, show_status, NULL, PSU_PRESENT);
|
||||
static SENSOR_DEVICE_ATTR(psu_model_name, S_IRUGO, show_model_name,NULL, PSU_MODEL_NAME);
|
||||
static SENSOR_DEVICE_ATTR(psu_serial, S_IRUGO, show_serial_number, NULL, PSU_SERIAL_NUMBER);
|
||||
static SENSOR_DEVICE_ATTR(psu_power_good, S_IRUGO, show_status, NULL, PSU_POWER_GOOD);
|
||||
|
||||
static struct attribute *as5812_54x_psu_attributes[] = {
|
||||
&sensor_dev_attr_psu_index.dev_attr.attr,
|
||||
&sensor_dev_attr_psu_present.dev_attr.attr,
|
||||
&sensor_dev_attr_psu_model_name.dev_attr.attr,
|
||||
&sensor_dev_attr_psu_serial.dev_attr.attr,
|
||||
&sensor_dev_attr_psu_power_good.dev_attr.attr,
|
||||
NULL
|
||||
};
|
||||
@@ -116,6 +121,25 @@ static ssize_t show_status(struct device *dev, struct device_attribute *da,
|
||||
return sprintf(buf, "%d\n", status);
|
||||
}
|
||||
|
||||
static ssize_t show_serial_number(struct device *dev, struct device_attribute *da,
|
||||
char *buf)
|
||||
{
|
||||
struct as5812_54x_psu_data *data = as5812_54x_psu_update_device(dev);
|
||||
|
||||
if (!data->valid) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
if (!IS_PRESENT(data->index, data->status)) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
if (as5812_54x_psu_model_name_get(dev, 1) < 0) {
|
||||
return -ENXIO;
|
||||
}
|
||||
return sprintf(buf, "%s\n", data->serial);
|
||||
}
|
||||
|
||||
static ssize_t show_model_name(struct device *dev, struct device_attribute *da,
|
||||
char *buf)
|
||||
{
|
||||
@@ -129,7 +153,7 @@ static ssize_t show_model_name(struct device *dev, struct device_attribute *da,
|
||||
return 0;
|
||||
}
|
||||
|
||||
if (as5812_54x_psu_model_name_get(dev) < 0) {
|
||||
if (as5812_54x_psu_model_name_get(dev, 0) < 0) {
|
||||
return -ENXIO;
|
||||
}
|
||||
|
||||
@@ -254,6 +278,59 @@ enum psu_type {
|
||||
PSU_UM400D01_01G /* DC48V - B2F */
|
||||
};
|
||||
|
||||
struct serial_number_info {
|
||||
enum psu_type type;
|
||||
u8 offset;
|
||||
u8 length;
|
||||
};
|
||||
|
||||
struct serial_number_info serials[] = {
|
||||
{PSU_YM_2401_JCR, 0x20, 11},
|
||||
{PSU_YM_2401_JDR, 0x20, 11},
|
||||
{PSU_CPR_4011_4M11, 0x47, 15},
|
||||
{PSU_CPR_4011_4M21, 0x47, 15},
|
||||
{PSU_CPR_6011_2M11, 0x46, 15},
|
||||
{PSU_CPR_6011_2M21, 0x46, 15},
|
||||
{PSU_UM400D_01G, 0x50, 9},
|
||||
{PSU_UM400D01_01G, 0x50, 12},
|
||||
};
|
||||
|
||||
static int as5812_54x_psu_serial_number_get(struct device *dev, enum psu_type type)
|
||||
{
|
||||
struct i2c_client *client = to_i2c_client(dev);
|
||||
struct as5812_54x_psu_data *data = i2c_get_clientdata(client);
|
||||
int i, status;
|
||||
|
||||
switch (type) {
|
||||
case PSU_CPR_4011_4M11:
|
||||
case PSU_CPR_4011_4M21:
|
||||
case PSU_CPR_6011_2M11:
|
||||
case PSU_CPR_6011_2M21:
|
||||
{
|
||||
if(type >= sizeof(serials)/sizeof(struct serial_number_info))
|
||||
return -EINVAL;
|
||||
status = as5812_54x_psu_read_block(client, serials[type].offset,
|
||||
data->serial, serials[type].length);
|
||||
if (status < 0) {
|
||||
data->serial[0] = '\0';
|
||||
dev_dbg(&client->dev, "unable to read serial number from (0x%x) offset(0x%x)\n",
|
||||
client->addr, serials[type].offset);
|
||||
return status;
|
||||
}
|
||||
else {
|
||||
data->serial[serials[type].length] = '\0';
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
return -ENODATA;
|
||||
}
|
||||
|
||||
|
||||
struct model_name_info {
|
||||
enum psu_type type;
|
||||
u8 offset;
|
||||
@@ -272,7 +349,7 @@ struct model_name_info models[] = {
|
||||
{PSU_UM400D01_01G, 0x50, 12, "um400d01-01G"},
|
||||
};
|
||||
|
||||
static int as5812_54x_psu_model_name_get(struct device *dev)
|
||||
static int as5812_54x_psu_model_name_get(struct device *dev , int get_serial)
|
||||
{
|
||||
struct i2c_client *client = to_i2c_client(dev);
|
||||
struct as5812_54x_psu_data *data = i2c_get_clientdata(client);
|
||||
@@ -303,7 +380,7 @@ static int as5812_54x_psu_model_name_get(struct device *dev)
|
||||
/* 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;
|
||||
return get_serial ? as5812_54x_psu_serial_number_get(dev, i) : 0;
|
||||
}
|
||||
else {
|
||||
data->model_name[0] = '\0';
|
||||
@@ -351,10 +428,6 @@ exit:
|
||||
|
||||
static int __init as5812_54x_psu_init(void)
|
||||
{
|
||||
extern int platform_accton_as5812_54x(void);
|
||||
if(!platform_accton_as5812_54x()) {
|
||||
return -ENODEV;
|
||||
}
|
||||
return i2c_add_driver(&as5812_54x_psu_driver);
|
||||
}
|
||||
|
||||
|
||||
28
packages/platforms/accton/x86-64/x86-64-accton-as5812-54x/onlp/builds/src/module/src/platform_lib.c
Normal file → Executable file
28
packages/platforms/accton/x86-64/x86-64-accton-as5812-54x/onlp/builds/src/module/src/platform_lib.c
Normal file → Executable file
@@ -23,6 +23,8 @@
|
||||
*
|
||||
*
|
||||
***********************************************************/
|
||||
#include <onlp/onlp.h>
|
||||
#include <onlplib/file.h>
|
||||
#include <errno.h>
|
||||
#include <string.h>
|
||||
#include <stdio.h>
|
||||
@@ -249,3 +251,29 @@ int psu_ym2401_pmbus_info_set(int id, char *node, int value)
|
||||
return ONLP_STATUS_OK;
|
||||
}
|
||||
|
||||
#define PSU_SERIAL_NUMBER_LEN 18
|
||||
|
||||
int psu_serial_number_get(int id, int is_ac, char *serial, int serial_len)
|
||||
{
|
||||
int size = 0;
|
||||
int ret = ONLP_STATUS_OK;
|
||||
char *prefix = NULL;
|
||||
|
||||
if (serial == NULL || serial_len < PSU_SERIAL_NUMBER_LEN) {
|
||||
return ONLP_STATUS_E_PARAM;
|
||||
}
|
||||
|
||||
memset((void *)serial, 0x0, serial_len);
|
||||
if(is_ac)
|
||||
prefix = (id == PSU1_ID) ? PSU1_AC_EEPROM_PREFIX : PSU2_AC_EEPROM_PREFIX;
|
||||
else
|
||||
prefix = (id == PSU1_ID) ? PSU1_DC_EEPROM_PREFIX : PSU2_DC_EEPROM_PREFIX;
|
||||
ret = onlp_file_read((uint8_t*)serial, PSU_SERIAL_NUMBER_LEN, &size, "%s%s", prefix, "psu_serial");
|
||||
if (ret != ONLP_STATUS_OK || size != PSU_SERIAL_NUMBER_LEN) {
|
||||
return ONLP_STATUS_E_INTERNAL;
|
||||
|
||||
}
|
||||
|
||||
serial[PSU_SERIAL_NUMBER_LEN] = '\0';
|
||||
return ONLP_STATUS_OK;
|
||||
}
|
||||
1
packages/platforms/accton/x86-64/x86-64-accton-as5812-54x/onlp/builds/src/module/src/platform_lib.h
Normal file → Executable file
1
packages/platforms/accton/x86-64/x86-64-accton-as5812-54x/onlp/builds/src/module/src/platform_lib.h
Normal file → Executable file
@@ -71,6 +71,7 @@ typedef enum psu_type {
|
||||
} psu_type_t;
|
||||
|
||||
psu_type_t get_psu_type(int id, char* modelname, int modelname_len);
|
||||
int psu_serial_number_get(int id, int is_ac, char *serial, int serial_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);
|
||||
|
||||
|
||||
3
packages/platforms/accton/x86-64/x86-64-accton-as5812-54x/onlp/builds/src/module/src/psui.c
Normal file → Executable file
3
packages/platforms/accton/x86-64/x86-64-accton-as5812-54x/onlp/builds/src/module/src/psui.c
Normal file → Executable file
@@ -225,6 +225,7 @@ onlp_psui_info_get(onlp_oid_t id, onlp_psu_info_t* info)
|
||||
int val = 0;
|
||||
int ret = ONLP_STATUS_OK;
|
||||
int index = ONLP_OID_ID_GET(id);
|
||||
int is_ac=1;
|
||||
psu_type_t psu_type;
|
||||
|
||||
VALIDATE(id);
|
||||
@@ -270,12 +271,14 @@ onlp_psui_info_get(onlp_oid_t id, onlp_psu_info_t* info)
|
||||
break;
|
||||
case PSU_TYPE_DC_48V_F2B:
|
||||
case PSU_TYPE_DC_48V_B2F:
|
||||
is_ac=0;
|
||||
ret = psu_um400d_info_get(info);
|
||||
break;
|
||||
default:
|
||||
ret = ONLP_STATUS_E_UNSUPPORTED;
|
||||
break;
|
||||
}
|
||||
psu_serial_number_get(index, is_ac, info->serial, sizeof(info->serial));
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user