blob: 85d77412d5c8a97422b17c1eb4e48ded1e103928 [file] [log] [blame]
Christopher Bosticdc8e2b62017-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 Spinler3e82c862018-05-25 12:29:33 -05006status=0
7max_retries=3
8driver_path="/sys/bus/i2c/drivers/ir35221/"
Matt Spinler03217662019-03-22 10:17:16 -05009platform_path="/sys/devices/platform/ahb/ahb:apb/ahb:apb:bus@1e78a000/"
Matt Spinler3e82c862018-05-25 12:29:33 -050010
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 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
Christopher Bosticaa546382017-06-14 09:55:35 -050037if [ "$1" = "unbind" ]
38then
Matt Spinler3e82c862018-05-25 12:29:33 -050039 if [ -e $driver_path/4-0070 ]
Christopher Bosticaa546382017-06-14 09:55:35 -050040 then
Matt Spinler3e82c862018-05-25 12:29:33 -050041 unbind_driver "4-0070"
Christopher Bosticaa546382017-06-14 09:55:35 -050042 fi
43
Matt Spinler3e82c862018-05-25 12:29:33 -050044 if [ -e $driver_path/4-0071 ]
Christopher Bosticaa546382017-06-14 09:55:35 -050045 then
Matt Spinler3e82c862018-05-25 12:29:33 -050046 unbind_driver "4-0071"
Christopher Bosticaa546382017-06-14 09:55:35 -050047 fi
48
Matt Spinler3e82c862018-05-25 12:29:33 -050049 if [ -e $driver_path/5-0070 ]
Christopher Bosticaa546382017-06-14 09:55:35 -050050 then
Matt Spinler3e82c862018-05-25 12:29:33 -050051 unbind_driver "5-0070"
Christopher Bosticaa546382017-06-14 09:55:35 -050052 fi
53
Matt Spinler3e82c862018-05-25 12:29:33 -050054 if [ -e $driver_path/5-0071 ]
Christopher Bosticaa546382017-06-14 09:55:35 -050055 then
Matt Spinler3e82c862018-05-25 12:29:33 -050056 unbind_driver "5-0071"
Christopher Bosticaa546382017-06-14 09:55:35 -050057 fi
58elif [ "$1" = "bind" ]
59then
Matt Spinler3e82c862018-05-25 12:29:33 -050060 if [ -e $platform_path/1e78a140.i2c-bus/i2c-4/4-0070 ]
Christopher Bosticaa546382017-06-14 09:55:35 -050061 then
Matt Spinler3e82c862018-05-25 12:29:33 -050062 bind_driver "4-0070"
Christopher Bosticaa546382017-06-14 09:55:35 -050063 fi
64
Matt Spinler3e82c862018-05-25 12:29:33 -050065 if [ -e $platform_path/1e78a140.i2c-bus/i2c-4/4-0071 ]
Christopher Bosticaa546382017-06-14 09:55:35 -050066 then
Matt Spinler3e82c862018-05-25 12:29:33 -050067 bind_driver "4-0071"
Christopher Bosticaa546382017-06-14 09:55:35 -050068 fi
69
Matt Spinler3e82c862018-05-25 12:29:33 -050070 if [ -e $platform_path/1e78a180.i2c-bus/i2c-5/5-0070 ]
Christopher Bosticaa546382017-06-14 09:55:35 -050071 then
Matt Spinler3e82c862018-05-25 12:29:33 -050072 bind_driver "5-0070"
Christopher Bosticaa546382017-06-14 09:55:35 -050073 fi
74
Matt Spinler3e82c862018-05-25 12:29:33 -050075 if [ -e $platform_path/1e78a180.i2c-bus/i2c-5/5-0071 ]
Christopher Bosticaa546382017-06-14 09:55:35 -050076 then
Matt Spinler3e82c862018-05-25 12:29:33 -050077 bind_driver "5-0071"
Christopher Bosticaa546382017-06-14 09:55:35 -050078 fi
79fi
Matt Spinler3e82c862018-05-25 12:29:33 -050080
81exit $status