Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[as7816-64x] Support different PSU sequence for any CPLD version #3882

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 21 additions & 2 deletions device/accton/x86_64-accton_as7816_64x-r0/plugins/psuutil.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,25 @@ def __init__(self):
2: "9-0050",
}

def get_psu_mapping(self, index):
if index is None:
return False

for id in self.psu_mapping:
psu_name = str()
node = self.psu_path + self.psu_mapping[id] + "/name"

try:
with open(node, 'r') as psu_name_fd:
psu_name = psu_name_fd.read()
except IOError:
return False

if psu_name.find("as7816_64x_psu" + str(index)) != -1:
return self.psu_mapping[id]

return str()

def get_num_psus(self):
return len(self.psu_mapping)

Expand All @@ -37,7 +56,7 @@ def get_psu_status(self, index):
return False

status = 0
node = self.psu_path + self.psu_mapping[index]+self.psu_oper_status
node = self.psu_path + self.get_psu_mapping(index) + self.psu_oper_status
try:
with open(node, 'r') as power_status:
status = int(power_status.read())
Expand All @@ -51,7 +70,7 @@ def get_psu_presence(self, index):
return False

status = 0
node = self.psu_path + self.psu_mapping[index] + self.psu_presence
node = self.psu_path + self.get_psu_mapping(index) + self.psu_presence
try:
with open(node, 'r') as presence_status:
status = int(presence_status.read())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@
#define IS_POWER_GOOD(id, value) (!!(value & BIT(2+id)))
#define IS_PRESENT(id, value) (!(value & BIT(id)))

static ssize_t show_id(struct device *dev, struct device_attribute *da, char *buf);
static ssize_t show_status(struct device *dev, struct device_attribute *da, char *buf);
static struct as7816_64x_psu_data *as7816_64x_psu_update_device(struct device *dev);
extern int accton_i2c_cpld_read (u8 cpld_addr, u8 reg);
Expand All @@ -61,17 +62,20 @@ struct as7816_64x_psu_data {

enum as7816_64x_psu_sysfs_attributes {
PSU_PRESENT,
PSU_POWER_GOOD
PSU_POWER_GOOD,
CPLD_ID
};

/* sysfs attributes for hwmon
*/
static SENSOR_DEVICE_ATTR(psu_present, S_IRUGO, show_status, NULL, PSU_PRESENT);
static SENSOR_DEVICE_ATTR(psu_power_good, S_IRUGO, show_status, NULL, PSU_POWER_GOOD);
static SENSOR_DEVICE_ATTR(cpld_id, S_IRUGO, show_id, NULL, CPLD_ID);

static struct attribute *as7816_64x_psu_attributes[] = {
&sensor_dev_attr_psu_present.dev_attr.attr,
&sensor_dev_attr_psu_power_good.dev_attr.attr,
&sensor_dev_attr_cpld_id.dev_attr.attr,
NULL
};

Expand Down Expand Up @@ -100,6 +104,36 @@ static const struct attribute_group as7816_64x_psu_group = {
.attrs = as7816_64x_psu_attributes,
};

static ssize_t show_id(struct device *dev, struct device_attribute *da, char *buf)
{
int i = 0;
u8 cpld_id[3] = {0};
struct i2c_client *client = to_i2c_client(dev);
struct as7816_64x_psu_data *data = i2c_get_clientdata(client);
int status = 0;

mutex_lock(&data->update_lock);
for (i = 0; i < ARRAY_SIZE(cpld_id)-1; i++) {
status = accton_i2c_cpld_read(PSU_STATUS_I2C_ADDR, 0xfd+i);
if (unlikely(status < 0)) {
goto exit;
}

cpld_id[i] = status;
}
mutex_unlock(&data->update_lock);

if (cpld_id[0] == 0xff && cpld_id[1] == 0xff) {
return sprintf(buf, "NULL\n");
}

return sprintf(buf, "%s\n", cpld_id);

exit:
mutex_unlock(&data->update_lock);
return status;
}

static int as7816_64x_psu_probe(struct i2c_client *client,
const struct i2c_device_id *dev_id)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,38 @@ def ir3570_check():
return -1
return ret

def psu_index_check():
version = 0
CPLD1_VERSION="/sys/bus/i2c/devices/19-0060/version"
try:
with open(CPLD1_VERSION, 'r') as cpld_version:
version = int(cpld_version.read())
except IOError:
return False

cpld_id = "NULL"
CPLD1_ID="/sys/bus/i2c/devices/10-0053/cpld_id"
if os.path.exists(CPLD1_ID):
try:
with open(CPLD1_ID, 'r') as cpld_id_fd:
cpld_id = cpld_id_fd.read()
except IOError:
return False

at_found = 0
if cpld_id.find("AT") != -1:
at_found = 1
elif (version == 5) and (cpld_id.find("NULL") != -1):
at_found = 1

if (at_found):
log_os_system('echo 0x53 > /sys/bus/i2c/devices/i2c-10/delete_device', 1)
log_os_system('echo 0x50 > /sys/bus/i2c/devices/i2c-9/delete_device', 1)
log_os_system('echo as7816_64x_psu1 0x50 > /sys/bus/i2c/devices/i2c-9/new_device', 1)
log_os_system('echo as7816_64x_psu2 0x53 > /sys/bus/i2c/devices/i2c-10/new_device', 1)

return True

def show_eeprom_help():
cmd = sys.argv[0].split("/")[-1]+ " " + args[0]
print " use \""+ cmd + " 1-64 \" to dump sfp# eeprom"
Expand Down Expand Up @@ -283,6 +315,8 @@ def device_install():
if FORCE == 0:
return status

psu_index_check()

for i in range(0,len(sfp_map)):
path = "/sys/bus/i2c/devices/i2c-"+str(sfp_map[i])+"/new_device"
status, output =log_os_system("echo optoe1 0x50 > " + path, 1)
Expand Down