From 24cc827b73f23209414070fa636eff45d1522aab Mon Sep 17 00:00:00 2001 From: jostar-yang Date: Sun, 25 Jul 2021 07:45:07 +0800 Subject: [PATCH] [as4630-54pe] Modify to read correct psu SN and ID (#5389) Co-authored-by: Jostar Yang --- .../modules/x86-64-accton-as4630-54pe-psu.c | 35 +++++++++++++------ .../utils/accton_as9716_32d_monitor.py | 3 +- 2 files changed, 25 insertions(+), 13 deletions(-) diff --git a/platform/broadcom/sonic-platform-modules-accton/as4630-54pe/modules/x86-64-accton-as4630-54pe-psu.c b/platform/broadcom/sonic-platform-modules-accton/as4630-54pe/modules/x86-64-accton-as4630-54pe-psu.c index 798a5656410e..3d197210e35f 100755 --- a/platform/broadcom/sonic-platform-modules-accton/as4630-54pe/modules/x86-64-accton-as4630-54pe-psu.c +++ b/platform/broadcom/sonic-platform-modules-accton/as4630-54pe/modules/x86-64-accton-as4630-54pe-psu.c @@ -35,7 +35,7 @@ #include #define MAX_MODEL_NAME 20 -#define MAX_SERIAL_NUMBER 18 +#define MAX_SERIAL_NUMBER 19 static ssize_t show_status(struct device *dev, struct device_attribute *da, char *buf); static ssize_t show_string(struct device *dev, struct device_attribute *da, char *buf); @@ -90,8 +90,7 @@ static ssize_t show_status(struct device *dev, struct device_attribute *da, struct sensor_device_attribute *attr = to_sensor_dev_attr(da); struct as4630_54pe_psu_data *data = as4630_54pe_psu_update_device(dev); u8 status = 0; - - //printk("data->status=0x%x, attr->index=%d,data->index=%d \n", data->status, attr->index, data->index); + if (attr->index == PSU_PRESENT) { if(data->index==0) status = !( (data->status >> 5) & 0x1); @@ -267,7 +266,6 @@ static struct as4630_54pe_psu_data *as4630_54pe_psu_update_device(struct device /* Read psu status */ status = as4630_54pe_cpld_read(0x60, 0x22); - //printk("status=0x%x in %s\n", status, __FUNCTION__); if (status < 0) { dev_dbg(&client->dev, "cpld reg 0x60 err %d\n", status); } @@ -286,21 +284,36 @@ static struct as4630_54pe_psu_data *as4630_54pe_psu_update_device(struct device if (status < 0) { data->model_name[0] = '\0'; dev_dbg(&client->dev, "unable to read model name from (0x%x)\n", client->addr); - printk("unable to read model name from (0x%x)\n", client->addr); } - else { + else if(!strncmp(data->model_name, "YPEB1200", strlen("YPEB1200"))) + { + if (data->model_name[9]=='A' && data->model_name[10]=='M') + { + data->model_name[8]='A'; + data->model_name[9]='M'; + data->model_name[strlen("YPEB1200AM")]='\0'; + } + else + data->model_name[strlen("YPEB1200")]='\0'; + } + else + { data->model_name[ARRAY_SIZE(data->model_name)-1] = '\0'; - } - /* Read from offset 0x2e ~ 0x3d (16 bytes) */ + /* Read from offset 0x35 ~ 0x46 (18 bytes) */ status = as4630_54pe_psu_read_block(client, 0x35,data->serial_number, MAX_SERIAL_NUMBER); if (status < 0) { data->serial_number[0] = '\0'; - dev_dbg(&client->dev, "unable to read model name from (0x%x) offset(0x2e)\n", client->addr); - printk("unable to read model name from (0x%x) offset(0x2e)\n", client->addr); + dev_dbg(&client->dev, "unable to read model name from (0x%x) offset(0x35)\n", client->addr); + } + if (!strncmp(data->model_name, "YPEB1200AM", strlen("YPEB1200AM"))) /*for YPEB1200AM, SN length=18*/ + { + data->serial_number[MAX_SERIAL_NUMBER-1]='\0'; } - data->serial_number[MAX_SERIAL_NUMBER-1]='\0'; + else + data->serial_number[MAX_SERIAL_NUMBER-2]='\0'; + } data->last_updated = jiffies; diff --git a/platform/broadcom/sonic-platform-modules-accton/as9716-32d/utils/accton_as9716_32d_monitor.py b/platform/broadcom/sonic-platform-modules-accton/as9716-32d/utils/accton_as9716_32d_monitor.py index 49a99aa777a3..1cc35e577b8d 100755 --- a/platform/broadcom/sonic-platform-modules-accton/as9716-32d/utils/accton_as9716_32d_monitor.py +++ b/platform/broadcom/sonic-platform-modules-accton/as9716-32d/utils/accton_as9716_32d_monitor.py @@ -21,8 +21,7 @@ try: import commands - import getopt - import sys + import getopt, sys import logging import logging.config import logging.handlers