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 () { | ||||
Patrick Williams | 9b87168 | 2023-04-14 15:08:08 -0500 | [diff] [blame] | 12 | echo "$1" > $driver_path/unbind |
Matt Spinler | 713d1c7 | 2018-05-25 12:29:33 -0500 | [diff] [blame] | 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 | ||||
Patrick Williams | 9b87168 | 2023-04-14 15:08:08 -0500 | [diff] [blame] | 22 | # shellcheck disable=SC2320 |
23 | echo "$device" > $driver_path/bind || ret=$? | ||||
Matt Spinler | 713d1c7 | 2018-05-25 12:29:33 -0500 | [diff] [blame] | 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. | ||||
Patrick Williams | 9b87168 | 2023-04-14 15:08:08 -0500 | [diff] [blame] | 33 | if [ "$ret" -ne 0 ]; then |
Matt Spinler | 713d1c7 | 2018-05-25 12:29:33 -0500 | [diff] [blame] | 34 | status=$ret |
35 | fi | ||||
36 | } | ||||
37 | |||||
Christopher Bostic | e662190 | 2017-06-14 09:55:35 -0500 | [diff] [blame] | 38 | if [ "$1" = "unbind" ] |
39 | then | ||||
Matt Spinler | 713d1c7 | 2018-05-25 12:29:33 -0500 | [diff] [blame] | 40 | if [ -e $driver_path/4-0070 ] |
Christopher Bostic | e662190 | 2017-06-14 09:55:35 -0500 | [diff] [blame] | 41 | then |
Matt Spinler | 713d1c7 | 2018-05-25 12:29:33 -0500 | [diff] [blame] | 42 | unbind_driver "4-0070" |
Christopher Bostic | e662190 | 2017-06-14 09:55:35 -0500 | [diff] [blame] | 43 | fi |
44 | |||||
Matt Spinler | 713d1c7 | 2018-05-25 12:29:33 -0500 | [diff] [blame] | 45 | if [ -e $driver_path/4-0071 ] |
Christopher Bostic | e662190 | 2017-06-14 09:55:35 -0500 | [diff] [blame] | 46 | then |
Matt Spinler | 713d1c7 | 2018-05-25 12:29:33 -0500 | [diff] [blame] | 47 | unbind_driver "4-0071" |
Christopher Bostic | e662190 | 2017-06-14 09:55:35 -0500 | [diff] [blame] | 48 | fi |
49 | |||||
Matt Spinler | 713d1c7 | 2018-05-25 12:29:33 -0500 | [diff] [blame] | 50 | if [ -e $driver_path/5-0070 ] |
Christopher Bostic | e662190 | 2017-06-14 09:55:35 -0500 | [diff] [blame] | 51 | then |
Matt Spinler | 713d1c7 | 2018-05-25 12:29:33 -0500 | [diff] [blame] | 52 | unbind_driver "5-0070" |
Christopher Bostic | e662190 | 2017-06-14 09:55:35 -0500 | [diff] [blame] | 53 | fi |
54 | |||||
Matt Spinler | 713d1c7 | 2018-05-25 12:29:33 -0500 | [diff] [blame] | 55 | if [ -e $driver_path/5-0071 ] |
Christopher Bostic | e662190 | 2017-06-14 09:55:35 -0500 | [diff] [blame] | 56 | then |
Matt Spinler | 713d1c7 | 2018-05-25 12:29:33 -0500 | [diff] [blame] | 57 | unbind_driver "5-0071" |
Christopher Bostic | e662190 | 2017-06-14 09:55:35 -0500 | [diff] [blame] | 58 | fi |
59 | elif [ "$1" = "bind" ] | ||||
60 | then | ||||
Matt Spinler | 713d1c7 | 2018-05-25 12:29:33 -0500 | [diff] [blame] | 61 | if [ -e $platform_path/1e78a140.i2c-bus/i2c-4/4-0070 ] |
Christopher Bostic | e662190 | 2017-06-14 09:55:35 -0500 | [diff] [blame] | 62 | then |
Matt Spinler | 713d1c7 | 2018-05-25 12:29:33 -0500 | [diff] [blame] | 63 | bind_driver "4-0070" |
Christopher Bostic | e662190 | 2017-06-14 09:55:35 -0500 | [diff] [blame] | 64 | fi |
65 | |||||
Matt Spinler | 713d1c7 | 2018-05-25 12:29:33 -0500 | [diff] [blame] | 66 | if [ -e $platform_path/1e78a140.i2c-bus/i2c-4/4-0071 ] |
Christopher Bostic | e662190 | 2017-06-14 09:55:35 -0500 | [diff] [blame] | 67 | then |
Matt Spinler | 713d1c7 | 2018-05-25 12:29:33 -0500 | [diff] [blame] | 68 | bind_driver "4-0071" |
Christopher Bostic | e662190 | 2017-06-14 09:55:35 -0500 | [diff] [blame] | 69 | fi |
70 | |||||
Matt Spinler | 713d1c7 | 2018-05-25 12:29:33 -0500 | [diff] [blame] | 71 | if [ -e $platform_path/1e78a180.i2c-bus/i2c-5/5-0070 ] |
Christopher Bostic | e662190 | 2017-06-14 09:55:35 -0500 | [diff] [blame] | 72 | then |
Matt Spinler | 713d1c7 | 2018-05-25 12:29:33 -0500 | [diff] [blame] | 73 | bind_driver "5-0070" |
Christopher Bostic | e662190 | 2017-06-14 09:55:35 -0500 | [diff] [blame] | 74 | fi |
75 | |||||
Matt Spinler | 713d1c7 | 2018-05-25 12:29:33 -0500 | [diff] [blame] | 76 | if [ -e $platform_path/1e78a180.i2c-bus/i2c-5/5-0071 ] |
Christopher Bostic | e662190 | 2017-06-14 09:55:35 -0500 | [diff] [blame] | 77 | then |
Matt Spinler | 713d1c7 | 2018-05-25 12:29:33 -0500 | [diff] [blame] | 78 | bind_driver "5-0071" |
Christopher Bostic | e662190 | 2017-06-14 09:55:35 -0500 | [diff] [blame] | 79 | fi |
80 | fi | ||||
Matt Spinler | 713d1c7 | 2018-05-25 12:29:33 -0500 | [diff] [blame] | 81 | |
Patrick Williams | 9b87168 | 2023-04-14 15:08:08 -0500 | [diff] [blame] | 82 | exit "$status" |