2019-08-02 13:00:18 -05:00
|
|
|
import sys
|
2019-07-30 11:03:36 -05:00
|
|
|
import os.path
|
2019-08-02 13:00:18 -05:00
|
|
|
if sys.version_info[0] < 3:
|
2020-11-25 12:28:36 -06:00
|
|
|
import commands
|
2019-08-02 13:00:18 -05:00
|
|
|
else:
|
2020-11-25 12:28:36 -06:00
|
|
|
import subprocess as commands
|
2019-08-02 13:00:18 -05:00
|
|
|
|
|
|
|
smbus_present = 1
|
|
|
|
try:
|
2020-11-25 12:28:36 -06:00
|
|
|
import smbus
|
2019-08-02 13:00:18 -05:00
|
|
|
except ImportError as e:
|
2020-11-25 12:28:36 -06:00
|
|
|
smbus_present = 0
|
2019-08-02 13:00:18 -05:00
|
|
|
|
2019-07-30 11:03:36 -05:00
|
|
|
try:
|
|
|
|
from sonic_psu.psu_base import PsuBase
|
|
|
|
except ImportError as e:
|
2020-11-25 12:28:36 -06:00
|
|
|
raise ImportError(str(e) + "- required module not found")
|
|
|
|
|
2019-07-30 11:03:36 -05:00
|
|
|
|
|
|
|
class PsuUtil(PsuBase):
|
|
|
|
"""Platform-specific PSUutil class"""
|
|
|
|
|
|
|
|
def __init__(self):
|
2020-11-25 12:28:36 -06:00
|
|
|
PsuBase.__init__(self)
|
|
|
|
MAX_PSUS = 2
|
2019-07-30 11:03:36 -05:00
|
|
|
|
|
|
|
def get_num_psus(self):
|
|
|
|
MAX_PSUS = 2
|
|
|
|
return MAX_PSUS
|
|
|
|
|
|
|
|
def get_psu_status(self, index):
|
|
|
|
if index is None:
|
2020-11-25 12:28:36 -06:00
|
|
|
return False
|
|
|
|
if smbus_present == 0:
|
|
|
|
cmdstatus, psustatus = commands.getstatusoutput(
|
|
|
|
'i2cget -y 0 0x41 0xa') # need to verify the cpld register logic
|
|
|
|
psustatus = int(psustatus, 16)
|
|
|
|
else:
|
|
|
|
bus = smbus.SMBus(0)
|
|
|
|
DEVICE_ADDRESS = 0x41
|
|
|
|
DEVICE_REG = 0xa
|
|
|
|
psustatus = bus.read_byte_data(DEVICE_ADDRESS, DEVICE_REG)
|
2019-08-02 13:00:18 -05:00
|
|
|
if index == 1:
|
2020-11-25 12:28:36 -06:00
|
|
|
psustatus = psustatus & 4
|
|
|
|
if psustatus == 4:
|
|
|
|
return True
|
2019-08-02 13:00:18 -05:00
|
|
|
if index == 2:
|
2020-11-25 12:28:36 -06:00
|
|
|
psustatus = psustatus & 8
|
|
|
|
if psustatus == 8:
|
|
|
|
return True
|
|
|
|
|
2019-07-30 11:03:36 -05:00
|
|
|
return False
|
|
|
|
|
|
|
|
def get_psu_presence(self, index):
|
|
|
|
if index is None:
|
|
|
|
return False
|
|
|
|
|
2020-11-25 12:28:36 -06:00
|
|
|
if smbus_present == 0:
|
|
|
|
cmdstatus, psustatus = commands.getstatusoutput(
|
|
|
|
'i2cget -y 0 0x41 0xa') # need to verify the cpld register logic
|
|
|
|
psustatus = int(psustatus, 16)
|
|
|
|
else:
|
|
|
|
bus = smbus.SMBus(0)
|
|
|
|
DEVICE_ADDRESS = 0x41
|
|
|
|
DEVICE_REG = 0xa
|
|
|
|
psustatus = bus.read_byte_data(DEVICE_ADDRESS, DEVICE_REG)
|
2019-08-02 13:00:18 -05:00
|
|
|
|
|
|
|
if index == 1:
|
2020-11-25 12:28:36 -06:00
|
|
|
psustatus = psustatus & 1
|
|
|
|
if psustatus == 1:
|
|
|
|
return True
|
2019-08-02 13:00:18 -05:00
|
|
|
if index == 2:
|
2020-11-25 12:28:36 -06:00
|
|
|
psustatus = psustatus & 2
|
|
|
|
if psustatus == 2:
|
2019-08-02 13:00:18 -05:00
|
|
|
return True
|
2019-07-30 11:03:36 -05:00
|
|
|
return False
|