-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathverbit
executable file
·328 lines (244 loc) · 8.09 KB
/
verbit
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
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
#!/bin/bash
# verbit - Utility to parse a Linux Alsa Codec Dump and display the verbs used.
# Some basic verb modifications needed for AppleHDA are displayed as well.
#
# version 1.0 - This version assists with simple verb decoding and it is
# up to the user to choose which nodes and any final modifications
# to make.
#
# Many Thanks to THe KiNG
# Signal64
blacklist[0]="411111f0"
blacklist[1]="400000f0"
blacklist[2]="CD at Int ATAPI"
codecfile=$1
debug=./verbitdebug.txt
typeset -i i=0
typeset -i j=0
typeset -i verbcount=0
typeset -i nextassoc=0
brk="--------------------------------------------------------------------------------------------------------"
if [[ ! -f $codecfile ]];then
echo "ERROR: Could not find codec dump file: $codecfile"
exit
fi
# Simple check to see if this is a ALSA codec dump file
chk=`head -3 $codecfile | cut -f1 -d":" | tr "\n" " " | tr -d " "`
if [[ $chk != "CodecAddressVendorId" ]];then
echo "ERROR: This doesn't appear to be an alsa codec dump file"
head -3 $codecfile
exit
fi
####################################################################
# Start - Parse and display original codec info from file
echo " " > $debug
echo -e "\nVerbs from Linux Codec Dump File: $codecfile"
codecname=`head $codecfile | grep Codec: | cut -f2 -d":" | cut -f2- -d" "`
codecaddr=`head $codecfile | grep Address: | cut -f2 -d":"`
codechex=`head $codecfile | grep "Vendor Id:" | cut -f2 -d":"`
codecdec=`printf "%d" $codechex`
printf "\nCodec: %s Address: %s DevID: %s (%s)\n" "$codecname" $codecaddr $codecdec $codechex
echo -e "\n Jack Color Description Node PinDefault Original Verbs\n$brk"
#addr=`grep Address $codecfile | cut -f2 -d" "`
typeset -i nidnum=0
while read line;do
chknode=`echo $line | grep "Node 0x" | cut -f2 -d" "`
if [[ -n $chknode ]];then
hexnode=$chknode
vnode=`echo $hexnode | cut -f2 -d"x"`
fi
pin=`echo $line | grep "Pin Default" | cut -f2 -d"x" | cut -f1 -d":"`
if [[ -n $pin ]];then
desc=`echo $line | cut -f2 -d"]"`
jack=`grep -A8 "Node $hexnode" $codecfile | grep -A2 "$pin" | grep Color | cut -f2 -d"=" | cut -f1 -d","`
color=`grep -A8 "Node $hexnode" $codecfile | grep -A2 "$pin" | grep Color | cut -f3 -d"="`
# 71c Default Association/Sequence
verb1=$codecaddr$vnode"71c"`echo $pin | cut -c7,8`
# 71d Color/Misc
verb2=$codecaddr$vnode"71d"`echo $pin | cut -c5,6`
# 71e Default Device/Connection Type
verb3=$codecaddr$vnode"71e"`echo $pin | cut -c3,4`
# 71f Port Connectivity/Location
verb4=$codecaddr$vnode"71f"`echo $pin | cut -c1,2`
printf "%7s %7s %-27s %3d %-6s %-12s %s %s %s %s\n" $jack $color "$desc" $hexnode $hexnode "0x"$pin $verb1 $verb2 $verb3 $verb4
chkblklist="$jack $color $desc $hexnode 0x$pin"
blklisted=0;i=0
while [ $i -lt ${#blacklist[@]} ];do
chk=`echo $chkblklist | grep "${blacklist[i]}"`
if [[ $chk ]];then
blklisted=1
fi
i=i+1
done
if [[ $blklisted = 0 ]];then
vdesc[verbcount]="$desc"
vjack[verbcount]=$jack
vcolor[verbcount]=$color
vhex[verbcount]=$hexnode
vpin[verbcount]=$pin
verbc[verbcount]=$verb1
verbd[verbcount]=$verb2
verbe[verbcount]=$verb3
verbf[verbcount]=$verb4
verbcount=verbcount+1
else
blnodes=$blnodes$hexnode" "
fi
fi
done < $codecfile
echo -e "$brk\n"
# Show nodes that were blacklisted and removed
echo "Blacklist:" >> $debug
echo ${blacklist[*]} >> $debug
echo "Removed Nodes: $blnodes" >> $debug
# Correct Verbs
# Rules:
# Pin Defaults of 0x411111f0 or 0x400000f0 are removed
# Remove CD at INT ATAPI
# Taken Care of by blacklist array above, shouldn't be in current verb array
# 71c Sequence should always be 0
# 71c Association needs to be unique!
# 71d Set all Misc to 0 (Jack Detect Enabled) and determine which should be 1 later
# 71e - Not Processed in this version
# 71f Location should not use 02 for Front Panel, use 01 instead
#
# Step 1 - Correct 71c Associations
#
echo "Checking 71c Associations" >> $debug
echo -e "\nCurrent Associations" >> $debug
i=0
while [ $i -lt $verbcount ]
do
note=""
assoc[i]=`echo ${verbc[i]} | cut -c7`
if [[ ${assoc[i]} = 0 ]];then
assoc[i]=1
note=" note: Changed 0 to 1"
fi
# Debug
echo "${verbc[i]} = ${assoc[i]} $note" >> $debug
i=i+1
done
# Determine unused association values
i=1;j=0
while (( i < 15 ));do
# convert to single hex digit
ihex=`printf "%x\n" $i`
chk=`echo ${assoc[*]} | grep -w $ihex`
if [[ -z $chk ]];then
unused[j]=$ihex
j=j+1
fi
i=i+1
done
# Debug
echo -e "\n Used associations = "${assoc[*]} >> $debug
echo "Unused associations = "${unused[*]} >> $debug
echo -e "\nCorrecting duplicate associations\n" >> $debug
i=0;nextassoc=0
while [ $i -lt $verbcount ]
do
#build a assoc list without current node being checked
j=0;assoclist=""
while [ $j -lt $verbcount ]
do
if [[ $j != $i ]];then
assoclist=$assoclist${assoc[j]}" "
fi
j=j+1
done
echo "Checking if ${assoc[i]} already exists in: $assoclist" >> $debug
chkassoc=`echo $assoclist | grep -w ${assoc[i]}`
if [[ -n $chkassoc ]];then
#There is a duplicate
#Is this the first time we've seen this association?
echo " duplicate found - Is this the first time we've seen this association?" >> $debug
firstassoc=`echo $newassoclist | grep -w ${assoc[i]}`
if [[ -n $firstassoc ]];then
echo " no - replacing association with: ${unused[nextassoc]}" >> $debug
assoc[i]=${unused[nextassoc]}
nverbc[i]=`echo ${verbc[i]} | cut -c1-6`${assoc[i]}"0"
nextassoc=nextassoc+1
else
echo " yes - ignoring" >> $debug
nverbc[i]=`echo ${verbc[i]} | cut -c1-7`"0"
fi
else
echo " no duplicate found" >> $debug
nverbc[i]=`echo ${verbc[i]} | cut -c1-7`"0"
fi
newassoclist=$newassoclist${assoc[i]}" "
i=i+1
done
echo -e "\nNew 71c Associations" >> $debug
echo " Before After" >> $debug
echo "--------------------------------------------------" >> $debug
i=0
while [ $i -lt $verbcount ]
do
echo ${verbc[i]}" "${nverbc[i]}" "${verbd[i]}" "${verbe[i]}" "${verbf[i]} >> $debug
i=i+1
done
#
# Step 2 - Correcting 71d Misc
#
echo -e "\nReset 71d Misc to 0" >> $debug
i=0
while [ $i -lt $verbcount ]
do
nverbd[i]=`echo ${verbd[i]} | cut -c1-7`"0"
#verbd[i]=$verb$b
i=i+1
done
echo -e "New 71d Associations" >> $debug
echo " Before After" >> $debug
echo "--------------------------------------------------" >> $debug
i=0
while [ $i -lt $verbcount ]
do
echo ${verbd[i]}" "${nverbc[i]}" "${nverbd[i]}" "${verbe[i]}" "${verbf[i]} >> $debug
i=i+1
done
#
# Step 3 - Correct 71e
#
# Removed for now
#
# Step 4 - Correct 71f
#
echo -e "\nCorrect 71f 02 FP to 01" >> $debug
i=0
while [ $i -lt $verbcount ]
do
verb=`echo ${verbf[i]} | cut -c1-7`
misc=`echo ${verbf[i]} | cut -c8 | tr [a-z] [A-Z]`
if [[ $misc = "2" ]];then
misc="1"
fi
if [[ $misc != "1" ]];then
misc="0"
fi
nverbf[i]=$verb$misc
i=i+1
done
echo -e "New 71f Associations" >> $debug
echo " Before After" >> $debug
echo "--------------------------------------------------" >> $debug
i=0
while [ $i -lt $verbcount ]
do
echo ${verbd[i]}" "${nverbc[i]}" "${nverbd[i]}" "${verbe[i]}" "${nverbf[i]} >> $debug
i=i+1
done
echo " " >> $debug
#
# Step 5 - Show new verbs
#
echo -e "\n Jack Color Description Node PinDefault Modified Verbs\n$brk"
i=0
while [ $i -lt $verbcount ]
do
printf "%7s %7s %-27s %3d %-6s %-12s %s %s %s %s\n" ${vjack[i]} ${vcolor[i]} "${vdesc[i]}" ${vhex[i]} ${vhex[i]} "0x"${vpin[i]} ${nverbc[i]} ${nverbd[i]} ${verbe[i]} ${nverbf[i]}
i=i+1
done
echo -e "$brk\n"