blob: 45d45dfd3a394e9a97135fc5b852c9652ab715e3 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
|
#!/bin/bash
### BEGIN INIT INFO
# Provides: mts-io
# Default-Start: S
# Default-Stop:
# Short-Description: load the mts-io driver
# Description: mts-io driver initializes the Conduit hardware and
# provides user mode access through the driver to the
# Conduit features.
### END INIT INFO
((fail=0))
# To log debug, set LOGDBG to /usr/bin/LOGGER
if ((DEBUG)) ; then
LOGDBG=/usr/bin/logger
else
LOGDBG=":"
fi
${LOGDBG} -p daemon.info 'mts-io script'
sysdir=/sys/devices/platform/mts-io
gpiodir=/sys/class/gpio
USBRST=${sysdir}/usbhub-reset
RST[0]="${sysdir}/wifi-bt-reset"
RST[1]="${sysdir}/mtq-reset"
RST[2]="${sysdir}/ap1/reset"
RST[3]="${sysdir}/ap1/creset"
RST[4]="${sysdir}/ap2/reset"
RST[5]="${sysdir}/ap2/creset"
RST[6]="${sysdir}/gnss-reset"
RST[7]="${sysdir}/secure-reset"
RST[8]="${sysdir}/eth-reset"
RST[9]="${sysdir}/sm1-reset"
USLPTIME=60000 # 30 milliseconds from Redpine Signals Reset Spec
WAIT="/bin/busybox usleep ${USLPTIME}"
reset_path() {
pin=$1
${LOGDBG} -t "mts-io" -p daemon.info Reset $pin
if [[ -f ${pin} ]] ; then
if ! ( (echo 1 >${pin}) && (echo 0 >${pin}) && ${WAIT} && (echo 1 >${pin}) ) ; then
/usr/bin/logger -t "mts-io" -p daemon.error -s "Failed write to ${pin}"
return 1
fi
sleep 2
${LOGDBG} -t "mts-io" -p daemon.info Completeed reset $pin
else
${LOGDBG} -t "mts-io" -p daemon.info "${pin} does not exist"
fi
return 0
}
reset_array() {
fail=0
((i=${#RST[@]}-1))
while ((i>=0)) ; do
if [[ -f ${RST[$i]} ]] ; then
if ! ( (echo 1 >${RST[i]}) ) ; then
/usr/bin/logger -t "mts-io" -p daemon.error -s "Failed write to ${RST[$i]}"
fail=1
else
${LOGDBG} -t "mts-io" -p daemon.error -s "Wrote 1 to ${RST[$i]}"
fi
else
${LOGDBG} -t "mts-io" -p daemon.info "${RST[$i]} does not exist"
RST[$i]=""
fi
((i--))
done
((DBG)) && (cd $sysdir ; head gnss-reset eth-reset wifi-bt-reset usbhub-reset | logger -p daemon.info)
((i=${#RST[@]}-1))
while ((i>=0)) ; do
${LOGDBG} -s -p daemon.info "i value is $i RST is ${RST[$i]} count is ${#RST[$i]}"
if ((${#RST[$i]} > 0)) && [[ -f ${RST[$i]} ]] ; then
if ! ( (echo 0 >${RST[i]}) ) ; then
/usr/bin/logger -t "mts-io" -p daemon.error -s "Failed write to ${RST[$i]}"
fail=1
else
${LOGDBG} -t "mts-io" -p daemon.error -s "Wrote 0 to ${RST[$i]}"
:
fi
else
${LOGDBG} -t "mts-io" -p daemon.info "${RST[$i]} does not exist"
fi
((i--))
done
${WAIT}
((DBG)) && (cd $sysdir ; head gnss-reset eth-reset wifi-bt-reset usbhub-reset | logger -p daemon.info)
((i=${#RST[@]}-1))
while ((i>=0)) ; do
if ((${#RST[$i]} > 0)) && [[ -f ${RST[$i]} ]] ; then
if ! ( (echo 1 >${RST[$i]}) ) ; then
/usr/bin/logger -t "mts-io" -p daemon.error -s "Failed write to ${RST[$i]}"
fail=1
else
${LOGDBG} -t "mts-io" -p daemon.error -s "Wrote 1 to ${RST[$i]}"
fi
else
${LOGDBG} -t "mts-io" -p daemon.info "${RST[$i]} does not exist"
fi
((i--))
done
((DBG)) && (cd $sysdir ; head gnss-reset eth-reset wifi-bt-reset usbhub-reset | logger -p daemon.info)
return $fail
}
read_card_info() {
ap1_product_id=""
ap2_product_id=""
if [[ -d $sysdir/ap1 ]]; then
ap1_product_id=$(cat $sysdir/ap1/product-id)
fi
if [[ -d $sysdir/ap2 ]]; then
ap2_product_id=$(cat $sysdir/ap2/product-id)
fi
}
mfser_init() {
found_ap1=0
if [[ $ap1_product_id =~ ^MTAC-MFSER- ]]; then
/usr/bin/logger -t "mts-io" -p daemon.info -s "Linking /dev/mfser to /dev/ttyAP1"
ln -sf /dev/ttyAP1 /dev/mfser
found_ap1=1
fi
if [[ $ap2_product_id =~ ^MTAC-MFSER- ]]; then
if [[ $found_ap1 = 1 ]]; then
/usr/bin/logger -t "mts-io" -p daemon.info -s "Linking /dev/mfser-2 to /dev/ttyAP2"
ln -sf /dev/ttyAP2 /dev/mfser-2
else
/usr/bin/logger -t "mts-io" -p daemon.info -s "Linking /dev/mfser to /dev/ttyAP2"
ln -sf /dev/ttyAP2 /dev/mfser
fi
fi
}
case $1 in
start)
/usr/bin/logger -t "mts-io" -p daemon.info -s "Loading mts-io module"
if ! modprobe mts_io ; then
((fail++))
fi
/usr/bin/logger -t "mts-io" -p daemon.info -s "Resetting system modules"
read_card_info
if ! reset_path $USBRST ; then
((fail++))
fi
/bin/busybox usleep $USLPTIME
reset_array
mts-io-sysfs store radio-reset 0
mfser_init
if ! reset_path $RS9113RST ; then
((fail++))
fi
if ((fail == 0)) ; then
echo "OK"
else
echo "FAIL"
fi
exit $fail
;;
stop)
/usr/bin/logger -t "mts-io" -p daemon.info -s "Unloading mts-io module"
modprobe -r mts_io
RETVAL=$?
if ((RETVAL == 0)) ; then
echo "OK"
else
echo "FAIL"
fi
;;
restart)
$0 stop
sleep 1
$0 start
;;
reload)
/usr/bin/logger -t "mts-io" -p daemon.info -s "Resetting system modules"
if ! reset_path $USBRST ; then
((fail++))
fi
/bin/busybox usleep $USLPTIME
reset_array
mts-io-sysfs store radio-reset 0
mfser_init
if ((fail == 0)) ; then
echo "OK"
else
echo "FAIL"
fi
exit $fail
;;
status)
if [[ -d ${sysdir} ]] ; then
echo Driver is loaded
exit 0
else
echo Driver is not loaded
exit 3
fi
;;
*)
echo "Usage: $0 {start|stop|status|restart}"
exit 2
;;
esac
|