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