Skip to content

Commit bbe1580

Browse files
author
bolv
committed
Revert "[device]: Fix a bug that psuutil cannot access gpio sysfs to get PSU status (sonic-net#1789)"
This reverts commit 310c3f9.
1 parent 8f74ddb commit bbe1580

File tree

1 file changed

+30
-19
lines changed
  • device/celestica/x86_64-cel_seastone-r0/plugins

1 file changed

+30
-19
lines changed

device/celestica/x86_64-cel_seastone-r0/plugins/psuutil.py

+30-19
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,7 @@
33
# Platform-specific PSU status interface for SONiC
44
#
55

6-
import os
7-
6+
import os.path
87

98
try:
109
from sonic_psu.psu_base import PsuBase
@@ -19,32 +18,42 @@ def __init__(self):
1918
PsuBase.__init__(self)
2019
# DX010 PSU pin mapping
2120
self.psu = [
22-
{'base': self.get_gpio_base()},
21+
{'base':216}, # Reserved
2322
{'abs':27, 'power':22},
2423
{'abs':28, 'power':25}
2524
]
2625

27-
def get_gpio_base(self):
28-
sys_gpio_dir = "/sys/class/gpio"
29-
for r in os.listdir(sys_gpio_dir):
30-
if "gpiochip" in r:
31-
return int(r[8:],10)
32-
return 216 #Reserve
26+
def init_psu_gpio(self, pinnum):
27+
# export pin, input as default
28+
gpio_base = self.psu[0]['base']
29+
export_file = "/sys/class/gpio/export"
30+
direction_file = '/sys/class/gpio/gpio' + str(gpio_base+pinnum) + '/direction'
31+
32+
try:
33+
with open(export_file, 'w') as fd:
34+
fd.write(str(gpio_base+pinnum))
35+
except Exception as error:
36+
logging.error("Unable to export gpio ", pinnum)
3337

3438

3539
# Get a psu status and presence
3640
def read_psu_statuses(self, pinnum):
3741
sys_gpio_dir = "/sys/class/gpio"
42+
retval = 'ERR'
3843
gpio_base = self.psu[0]['base']
3944

4045
gpio_dir = sys_gpio_dir + '/gpio' + str(gpio_base+pinnum)
4146
gpio_file = gpio_dir + "/value"
47+
48+
# init gpio
49+
if (not os.path.isdir(gpio_dir)):
50+
self.init_psu_gpio(pinnum)
4251

4352
try:
4453
with open(gpio_file, 'r') as fd:
4554
retval = fd.read()
46-
except IOError:
47-
raise IOError("Unable to open " + gpio_file + "file !")
55+
except Exception as error:
56+
logging.error("Unable to open ", gpio_file, "file !")
4857

4958
retval = retval.rstrip('\r\n')
5059
return retval
@@ -67,10 +76,11 @@ def get_psu_status(self, index):
6776
"""
6877
status = 0
6978
psu_status = self.read_psu_statuses(self.psu[index]['power'])
70-
psu_status = int(psu_status, 10)
71-
# Check for PSU status
72-
if (psu_status == 1):
73-
status = 1
79+
if (psu_status != 'ERR'):
80+
psu_status = int(psu_status, 10)
81+
# Check for PSU status
82+
if (psu_status == 1):
83+
status = 1
7484

7585
return status
7686

@@ -83,9 +93,10 @@ def get_psu_presence(self, index):
8393
"""
8494
status = 0
8595
psu_absence = self.read_psu_statuses(self.psu[index]['abs'])
86-
psu_absence = (int(psu_absence, 10))
87-
# Check for PSU presence
88-
if (psu_absence == 0):
89-
status = 1
96+
if (psu_absence != 'ERR'):
97+
psu_absence = (int(psu_absence, 10))
98+
# Check for PSU presence
99+
if (psu_absence == 0):
100+
status = 1
90101

91102
return status

0 commit comments

Comments
 (0)