1#!/bin/bash 2# ######################################################### 3# Script to run on witherspoon BMC to unbind/bind the ir35221 4# driver's devices 5 6status=0 7max_retries=3 8driver_path="/sys/bus/i2c/drivers/ir35221/" 9platform_path="/sys/devices/platform/ahb/1e780000.apb/1e780000.apb:bus@1e78a000/" 10 11unbind_driver () { 12 echo "$1" > $driver_path/unbind 13} 14 15bind_driver () { 16 device=$1 17 tries=0 18 19 until [ $tries -ge $max_retries ]; do 20 tries=$((tries+1)) 21 ret=0 22 # shellcheck disable=SC2320 23 echo "$device" > $driver_path/bind || ret=$? 24 if [ $ret -ne 0 ]; then 25 echo "VRM $1 bind failed. Try $tries" 26 sleep 1 27 else 28 tries=$((max_retries+1)) 29 fi 30 done 31 32 #Script will return a nonzero value if any binds fail. 33 if [ "$ret" -ne 0 ]; then 34 status=$ret 35 fi 36} 37 38if [ "$1" = "unbind" ] 39then 40 if [ -e $driver_path/4-0070 ] 41 then 42 unbind_driver "4-0070" 43 fi 44 45 if [ -e $driver_path/4-0071 ] 46 then 47 unbind_driver "4-0071" 48 fi 49 50 if [ -e $driver_path/5-0070 ] 51 then 52 unbind_driver "5-0070" 53 fi 54 55 if [ -e $driver_path/5-0071 ] 56 then 57 unbind_driver "5-0071" 58 fi 59elif [ "$1" = "bind" ] 60then 61 if [ -e $platform_path/1e78a140.i2c/i2c-4/4-0070 ] 62 then 63 bind_driver "4-0070" 64 fi 65 66 if [ -e $platform_path/1e78a140.i2c/i2c-4/4-0071 ] 67 then 68 bind_driver "4-0071" 69 fi 70 71 if [ -e $platform_path/1e78a180.i2c/i2c-5/5-0070 ] 72 then 73 bind_driver "5-0070" 74 fi 75 76 if [ -e $platform_path/1e78a180.i2c/i2c-5/5-0071 ] 77 then 78 bind_driver "5-0071" 79 fi 80fi 81 82exit "$status" 83