#!/bin/bash

switch_addr=0x76
i2c -a 0 /dev/mst/dev-i2c-1 w $switch_addr 0x00 0x20 2> /dev/null
rc=$?
if [ $rc -ne 0 ]; then
    switch_addr=0x77
    i2c -a 0 /dev/mst/dev-i2c-1 w $switch_addr 0x00 0x20 2> /dev/null
fi

# Open switch 0x70 to point to the gpios
i2c -a 0 /dev/mst/dev-i2c-1 w 0x70 0x00 0x02 2> /dev/null

# light the slave LED
# configure 'disable the WD','slave LED','power off to other cput' as output
i2c -a 1 /dev/mst/dev-i2c-1 w 0x27 0x1c 0xb6  2> /dev/null
# set 'slave LED' to 1 and others to 0
i2c -a 1 /dev/mst/dev-i2c-1 w 0x27 0x0c 0xba  2> /dev/null

# Light the slave status LED
i2c -a 1 /dev/mst/dev-i2c-1 w 0x27 0x19 0x83  2> /dev/null
i2c -a 1 /dev/mst/dev-i2c-1 w 0x27 0x09 0x93  2> /dev/null


# Close the main i2c switch
i2c -a 0 /dev/mst/dev-i2c-1 w $switch_addr 0x00 0x00  2> /dev/null
rc=$?

exit $rc
