Christopher Bostic | 1fd06ed | 2017-06-07 16:12:27 -0500 | [diff] [blame] | 1 | #!/bin/bash |
2 | # ######################################################### | ||||
3 | # Script to run on witherspoon BMC to unbind/bind the ir35221 | ||||
4 | # driver's devices | ||||
5 | |||||
Matt Spinler | 713d1c7 | 2018-05-25 12:29:33 -0500 | [diff] [blame] | 6 | status=0 |
7 | max_retries=3 | ||||
8 | driver_path="/sys/bus/i2c/drivers/ir35221/" | ||||
Matt Spinler | 94b6374 | 2019-03-22 10:17:16 -0500 | [diff] [blame] | 9 | platform_path="/sys/devices/platform/ahb/ahb:apb/ahb:apb:bus@1e78a000/" |
Matt Spinler | 713d1c7 | 2018-05-25 12:29:33 -0500 | [diff] [blame] | 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 | |||||
Christopher Bostic | e662190 | 2017-06-14 09:55:35 -0500 | [diff] [blame] | 37 | if [ "$1" = "unbind" ] |
38 | then | ||||
Matt Spinler | 713d1c7 | 2018-05-25 12:29:33 -0500 | [diff] [blame] | 39 | if [ -e $driver_path/4-0070 ] |
Christopher Bostic | e662190 | 2017-06-14 09:55:35 -0500 | [diff] [blame] | 40 | then |
Matt Spinler | 713d1c7 | 2018-05-25 12:29:33 -0500 | [diff] [blame] | 41 | unbind_driver "4-0070" |
Christopher Bostic | e662190 | 2017-06-14 09:55:35 -0500 | [diff] [blame] | 42 | fi |
43 | |||||
Matt Spinler | 713d1c7 | 2018-05-25 12:29:33 -0500 | [diff] [blame] | 44 | if [ -e $driver_path/4-0071 ] |
Christopher Bostic | e662190 | 2017-06-14 09:55:35 -0500 | [diff] [blame] | 45 | then |
Matt Spinler | 713d1c7 | 2018-05-25 12:29:33 -0500 | [diff] [blame] | 46 | unbind_driver "4-0071" |
Christopher Bostic | e662190 | 2017-06-14 09:55:35 -0500 | [diff] [blame] | 47 | fi |
48 | |||||
Matt Spinler | 713d1c7 | 2018-05-25 12:29:33 -0500 | [diff] [blame] | 49 | if [ -e $driver_path/5-0070 ] |
Christopher Bostic | e662190 | 2017-06-14 09:55:35 -0500 | [diff] [blame] | 50 | then |
Matt Spinler | 713d1c7 | 2018-05-25 12:29:33 -0500 | [diff] [blame] | 51 | unbind_driver "5-0070" |
Christopher Bostic | e662190 | 2017-06-14 09:55:35 -0500 | [diff] [blame] | 52 | fi |
53 | |||||
Matt Spinler | 713d1c7 | 2018-05-25 12:29:33 -0500 | [diff] [blame] | 54 | if [ -e $driver_path/5-0071 ] |
Christopher Bostic | e662190 | 2017-06-14 09:55:35 -0500 | [diff] [blame] | 55 | then |
Matt Spinler | 713d1c7 | 2018-05-25 12:29:33 -0500 | [diff] [blame] | 56 | unbind_driver "5-0071" |
Christopher Bostic | e662190 | 2017-06-14 09:55:35 -0500 | [diff] [blame] | 57 | fi |
58 | elif [ "$1" = "bind" ] | ||||
59 | then | ||||
Matt Spinler | 713d1c7 | 2018-05-25 12:29:33 -0500 | [diff] [blame] | 60 | if [ -e $platform_path/1e78a140.i2c-bus/i2c-4/4-0070 ] |
Christopher Bostic | e662190 | 2017-06-14 09:55:35 -0500 | [diff] [blame] | 61 | then |
Matt Spinler | 713d1c7 | 2018-05-25 12:29:33 -0500 | [diff] [blame] | 62 | bind_driver "4-0070" |
Christopher Bostic | e662190 | 2017-06-14 09:55:35 -0500 | [diff] [blame] | 63 | fi |
64 | |||||
Matt Spinler | 713d1c7 | 2018-05-25 12:29:33 -0500 | [diff] [blame] | 65 | if [ -e $platform_path/1e78a140.i2c-bus/i2c-4/4-0071 ] |
Christopher Bostic | e662190 | 2017-06-14 09:55:35 -0500 | [diff] [blame] | 66 | then |
Matt Spinler | 713d1c7 | 2018-05-25 12:29:33 -0500 | [diff] [blame] | 67 | bind_driver "4-0071" |
Christopher Bostic | e662190 | 2017-06-14 09:55:35 -0500 | [diff] [blame] | 68 | fi |
69 | |||||
Matt Spinler | 713d1c7 | 2018-05-25 12:29:33 -0500 | [diff] [blame] | 70 | if [ -e $platform_path/1e78a180.i2c-bus/i2c-5/5-0070 ] |
Christopher Bostic | e662190 | 2017-06-14 09:55:35 -0500 | [diff] [blame] | 71 | then |
Matt Spinler | 713d1c7 | 2018-05-25 12:29:33 -0500 | [diff] [blame] | 72 | bind_driver "5-0070" |
Christopher Bostic | e662190 | 2017-06-14 09:55:35 -0500 | [diff] [blame] | 73 | fi |
74 | |||||
Matt Spinler | 713d1c7 | 2018-05-25 12:29:33 -0500 | [diff] [blame] | 75 | if [ -e $platform_path/1e78a180.i2c-bus/i2c-5/5-0071 ] |
Christopher Bostic | e662190 | 2017-06-14 09:55:35 -0500 | [diff] [blame] | 76 | then |
Matt Spinler | 713d1c7 | 2018-05-25 12:29:33 -0500 | [diff] [blame] | 77 | bind_driver "5-0071" |
Christopher Bostic | e662190 | 2017-06-14 09:55:35 -0500 | [diff] [blame] | 78 | fi |
79 | fi | ||||
Matt Spinler | 713d1c7 | 2018-05-25 12:29:33 -0500 | [diff] [blame] | 80 | |
81 | exit $status |