diff --git a/device/marvell/armhf-marvell_et6448m_52x-r0/plugins/psuutil.py b/device/marvell/armhf-marvell_et6448m_52x-r0/plugins/psuutil.py index 3f155c6f15f2..16965414e64b 100755 --- a/device/marvell/armhf-marvell_et6448m_52x-r0/plugins/psuutil.py +++ b/device/marvell/armhf-marvell_et6448m_52x-r0/plugins/psuutil.py @@ -1,7 +1,18 @@ #!/usr/bin/env python +import sys import os.path -import subprocess +if sys.version_info[0] < 3: + import commands as cmd +else: + import subprocess as cmd + +smbus_present = 1 +try: + import smbus +except ImportError as e: + smbus_present = 0 + try: from sonic_psu.psu_base import PsuBase except ImportError as e: @@ -21,34 +32,45 @@ def get_num_psus(self): def get_psu_status(self, index): if index is None: return False - - cmdstatus, psustatus = subprocess.getstatusoutput('i2cget -y 0 0x41 0xa') #need to verify the cpld register logic - psustatus = int(psustatus, 16) - if cmdstatus == 0: - if index == 1: - psustatus = psustatus&4 - if psustatus == 4 : - return True - if index == 2: - psustatus = psustatus&8 - if psustatus == 8 : - return True + if smbus_present == 0: + cmdstatus, psustatus = cmd.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) + if index == 1: + psustatus = psustatus&4 + if psustatus == 4 : + return True + if index == 2: + psustatus = psustatus&8 + if psustatus == 8 : + return True + return False def get_psu_presence(self, index): if index is None: return False - cmdstatus , psustatus = subprocess.getstatusoutput('i2cget -y 0 0x41 0xa') #need to verify the cpld register logic - psustatus = int(psustatus, 16) - if cmdstatus == 0: - if index == 1: - psustatus = psustatus&1 - if psustatus == 1 : - return True - if index == 2: - psustatus = psustatus&2 - if psustatus == 2 : - return True + if smbus_present == 0: + cmdstatus, psustatus = cmd.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) + + if index == 1: + psustatus = psustatus&1 + if psustatus == 1 : + return True + if index == 2: + psustatus = psustatus&2 + if psustatus == 2 : + return True return False diff --git a/device/marvell/armhf-marvell_et6448m_52x-r0/plugins/sfputil.py b/device/marvell/armhf-marvell_et6448m_52x-r0/plugins/sfputil.py index 19ef663f57e6..92a1604f311a 100755 --- a/device/marvell/armhf-marvell_et6448m_52x-r0/plugins/sfputil.py +++ b/device/marvell/armhf-marvell_et6448m_52x-r0/plugins/sfputil.py @@ -8,6 +8,12 @@ except ImportError, e: raise ImportError (str(e) + "- required module not found") +smbus_present = 1 + +try: + import smbus +except ImportError, e: + smbus_present = 0 class SfpUtil(SfpUtilBase): """Platform specific sfputil class""" @@ -37,14 +43,21 @@ def __init__(self): if not os.path.exists("/sys/bus/i2c/devices/0-0050") : os.system("echo optoe2 0x50 > /sys/bus/i2c/devices/i2c-0/new_device") - #os.system("echo optoe 0x50 > /sys/bus/i2c/devices/i2c-0/new_device") - #enable optic - os.system("i2cset -y -m 0x0f 0 0x41 0x5 0x00") eeprom_path = '/sys/bus/i2c/devices/0-0050/eeprom' for x in range(self.port_start, self.port_end + 1): port_eeprom_path = eeprom_path.format(self.port_to_i2c_mapping[x]) self.port_to_eeprom_mapping[x] = port_eeprom_path + # Enable optical SFP Tx + if smbus_present == 0 : + os.system("i2cset -y -m 0x0f 0 0x41 0x5 0x00") + else : + bus = smbus.SMBus(0) + DEVICE_ADDRESS = 0x41 + DEVICEREG = 0x5 + OPTIC_E = bus.read_byte_data(DEVICE_ADDRESS, DEVICEREG) + OPTIC_E = OPTIC_E & 0xf0 + bus.write_byte_data(DEVICE_ADDRESS, DEVICEREG, OPTIC_E) SfpUtilBase.__init__(self) def reset(self, port_num):