blob: c35a61bdb858c22302c1439f3944b32d20da6ee0 [file] [log] [blame]
Christopher Bostic1fd06ed2017-06-07 16:12:27 -05001#!/bin/bash
2# #########################################################
3# Script to run on witherspoon BMC to unbind/bind the ir35221
4# driver's devices
5
Matt Spinler713d1c72018-05-25 12:29:33 -05006status=0
7max_retries=3
8driver_path="/sys/bus/i2c/drivers/ir35221/"
Matt Spinler94b63742019-03-22 10:17:16 -05009platform_path="/sys/devices/platform/ahb/ahb:apb/ahb:apb:bus@1e78a000/"
Matt Spinler713d1c72018-05-25 12:29:33 -050010
11unbind_driver () {
Patrick Williams9b871682023-04-14 15:08:08 -050012 echo "$1" > $driver_path/unbind
Matt Spinler713d1c72018-05-25 12:29:33 -050013}
14
15bind_driver () {
16 device=$1
17 tries=0
18
19 until [ $tries -ge $max_retries ]; do
20 tries=$((tries+1))
21 ret=0
Patrick Williams9b871682023-04-14 15:08:08 -050022 # shellcheck disable=SC2320
23 echo "$device" > $driver_path/bind || ret=$?
Matt Spinler713d1c72018-05-25 12:29:33 -050024 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.
Patrick Williams9b871682023-04-14 15:08:08 -050033 if [ "$ret" -ne 0 ]; then
Matt Spinler713d1c72018-05-25 12:29:33 -050034 status=$ret
35 fi
36}
37
Christopher Bostice6621902017-06-14 09:55:35 -050038if [ "$1" = "unbind" ]
39then
Matt Spinler713d1c72018-05-25 12:29:33 -050040 if [ -e $driver_path/4-0070 ]
Christopher Bostice6621902017-06-14 09:55:35 -050041 then
Matt Spinler713d1c72018-05-25 12:29:33 -050042 unbind_driver "4-0070"
Christopher Bostice6621902017-06-14 09:55:35 -050043 fi
44
Matt Spinler713d1c72018-05-25 12:29:33 -050045 if [ -e $driver_path/4-0071 ]
Christopher Bostice6621902017-06-14 09:55:35 -050046 then
Matt Spinler713d1c72018-05-25 12:29:33 -050047 unbind_driver "4-0071"
Christopher Bostice6621902017-06-14 09:55:35 -050048 fi
49
Matt Spinler713d1c72018-05-25 12:29:33 -050050 if [ -e $driver_path/5-0070 ]
Christopher Bostice6621902017-06-14 09:55:35 -050051 then
Matt Spinler713d1c72018-05-25 12:29:33 -050052 unbind_driver "5-0070"
Christopher Bostice6621902017-06-14 09:55:35 -050053 fi
54
Matt Spinler713d1c72018-05-25 12:29:33 -050055 if [ -e $driver_path/5-0071 ]
Christopher Bostice6621902017-06-14 09:55:35 -050056 then
Matt Spinler713d1c72018-05-25 12:29:33 -050057 unbind_driver "5-0071"
Christopher Bostice6621902017-06-14 09:55:35 -050058 fi
59elif [ "$1" = "bind" ]
60then
Matt Spinler713d1c72018-05-25 12:29:33 -050061 if [ -e $platform_path/1e78a140.i2c-bus/i2c-4/4-0070 ]
Christopher Bostice6621902017-06-14 09:55:35 -050062 then
Matt Spinler713d1c72018-05-25 12:29:33 -050063 bind_driver "4-0070"
Christopher Bostice6621902017-06-14 09:55:35 -050064 fi
65
Matt Spinler713d1c72018-05-25 12:29:33 -050066 if [ -e $platform_path/1e78a140.i2c-bus/i2c-4/4-0071 ]
Christopher Bostice6621902017-06-14 09:55:35 -050067 then
Matt Spinler713d1c72018-05-25 12:29:33 -050068 bind_driver "4-0071"
Christopher Bostice6621902017-06-14 09:55:35 -050069 fi
70
Matt Spinler713d1c72018-05-25 12:29:33 -050071 if [ -e $platform_path/1e78a180.i2c-bus/i2c-5/5-0070 ]
Christopher Bostice6621902017-06-14 09:55:35 -050072 then
Matt Spinler713d1c72018-05-25 12:29:33 -050073 bind_driver "5-0070"
Christopher Bostice6621902017-06-14 09:55:35 -050074 fi
75
Matt Spinler713d1c72018-05-25 12:29:33 -050076 if [ -e $platform_path/1e78a180.i2c-bus/i2c-5/5-0071 ]
Christopher Bostice6621902017-06-14 09:55:35 -050077 then
Matt Spinler713d1c72018-05-25 12:29:33 -050078 bind_driver "5-0071"
Christopher Bostice6621902017-06-14 09:55:35 -050079 fi
80fi
Matt Spinler713d1c72018-05-25 12:29:33 -050081
Patrick Williams9b871682023-04-14 15:08:08 -050082exit "$status"