blob: 27ca3b9dcd2acc843323d402fbea07d39c057199 [file] [log] [blame]
Ben_Paib24a3e52019-07-15 16:19:02 +08001#!/bin/bash
2# #########################################################
3# Script to run on mihawk BMC to unbind/bind the ir35221
4# driver's devices
5
6status=0
7max_retries=3
8driver_path="/sys/bus/i2c/drivers/ir35221/"
9platform_path="/sys/devices/platform/ahb/ahb:apb/ahb:apb:bus@1e78a000/"
10
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
37if [ "$1" = "unbind" ]
38then
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
58elif [ "$1" = "bind" ]
59then
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
79fi
80
81exit $status