2020-11-25 12:28:36 -06:00
|
|
|
#!/usr/bin/python3
|
|
|
|
|
2019-06-07 10:59:54 -05:00
|
|
|
import sys
|
|
|
|
import os
|
|
|
|
import struct
|
2018-03-07 14:07:47 -06:00
|
|
|
|
2021-02-04 19:58:03 -06:00
|
|
|
PORT_RES = '/dev/port'
|
2019-06-07 10:59:54 -05:00
|
|
|
NVRAM_RES = '/dev/nvram'
|
2020-11-25 12:28:36 -06:00
|
|
|
COLD_RESET = 0xE # Cold Reset
|
|
|
|
WARM_RESET = 0x6 # Warm Reset
|
2021-02-04 19:58:03 -06:00
|
|
|
RESET_REG = 0xCF9
|
2019-02-16 13:50:15 -06:00
|
|
|
|
2019-06-07 10:59:54 -05:00
|
|
|
def io_reg_write(resource, offset, val):
|
|
|
|
fd = os.open(resource, os.O_RDWR)
|
|
|
|
if(fd < 0):
|
2020-11-25 12:28:36 -06:00
|
|
|
print('file open failed %s" % resource')
|
2019-06-07 10:59:54 -05:00
|
|
|
return
|
|
|
|
if(os.lseek(fd, offset, os.SEEK_SET) != offset):
|
2020-11-25 12:28:36 -06:00
|
|
|
print('lseek failed on %s' % resource)
|
2019-06-07 10:59:54 -05:00
|
|
|
return
|
|
|
|
ret = os.write(fd, struct.pack('B', val))
|
|
|
|
if(ret != 1):
|
2020-11-25 12:28:36 -06:00
|
|
|
print('write failed %d' % ret)
|
2019-06-07 10:59:54 -05:00
|
|
|
return
|
|
|
|
os.close(fd)
|
2019-02-16 13:50:15 -06:00
|
|
|
|
2019-06-07 10:59:54 -05:00
|
|
|
def power_reset(val):
|
|
|
|
with open('/sys/devices/platform/dell-s6000-cpld.0/power_reset', 'w') as p:
|
|
|
|
p.write(str(int(val)) + '\n')
|
|
|
|
p.flush()
|
|
|
|
|
2020-11-25 12:28:36 -06:00
|
|
|
def gpio_direction(pin, direction):
|
2019-06-07 10:59:54 -05:00
|
|
|
kernpath = '/sys/class/gpio/gpio'+str(pin)+'/direction'
|
|
|
|
with open(('kernpath'), 'w') as p:
|
|
|
|
p.write(str(direction) + '\n')
|
|
|
|
p.flush()
|
|
|
|
|
2020-11-25 12:28:36 -06:00
|
|
|
def gpio_set(pin, value):
|
2019-06-07 10:59:54 -05:00
|
|
|
kernpath = '/sys/class/gpio/gpio'+str(pin)+'/value'
|
|
|
|
with open(('kernpath'), 'w') as p:
|
|
|
|
p.write(str(int(value)) + '\n')
|
|
|
|
p.flush()
|
|
|
|
|
|
|
|
def gpio_export(value):
|
|
|
|
with open('/sys/class/gpio/export', 'w') as p:
|
|
|
|
p.write(str(int(value)) + '\n')
|
|
|
|
p.flush()
|
|
|
|
|
|
|
|
if __name__ == "__main__":
|
2021-02-04 19:58:03 -06:00
|
|
|
|
|
|
|
retry_count = 0
|
2019-06-07 10:59:54 -05:00
|
|
|
io_reg_write(NVRAM_RES, 0x49, COLD_RESET)
|
2021-02-04 19:58:03 -06:00
|
|
|
|
|
|
|
while retry_count < 3:
|
|
|
|
if not os.path.isdir("/sys/class/gpio/gpio10"):
|
|
|
|
gpio_export(10)
|
|
|
|
gpio_direction("10", "out")
|
|
|
|
# Toggle GPIO10 pin (to reset MUX)
|
|
|
|
gpio_set("10", 1)
|
|
|
|
gpio_set("10", 0)
|
|
|
|
power_reset(1)
|
|
|
|
retry_count += 1
|
|
|
|
io_reg_write(PORT_RES, RESET_REG, COLD_RESET)
|