slitaz-tools view tinyutils/soundconf @ rev 697

Added tag 4.7 for changeset 83491d0ac7b1
author Christophe Lincoln <pankso@slitaz.org>
date Thu Mar 01 15:56:00 2012 +0100 (2012-03-01)
parents 92aedc898747
children 5bb075010572
line source
1 #!/bin/ash
2 #
3 # ALSA Configurator - Modified for SliTaz GNU/Linux
4 # Last modif : 20071202
5 #
6 # Copyright (c) 1999-2002 SuSE GmbH
7 # Jan ONDREJ
8 #
9 # written by Takashi Iwai <tiwai@suse.de>
10 # Bernd Kaindl <bk@suse.de>
11 # Jan ONDREJ (SAL) <ondrejj@salstar.sk>
12 #
13 # based on the original version of Jan ONDREJ's alsaconf for ALSA 0.4.
14 #
15 # This program is free software; you can redistribute it and/or modify
16 # it under the terms of the GNU General Public License as published by
17 # the Free Software Foundation; either version 2 of the License, or
18 # (at your option) any later version.
19 #
20 . /etc/init.d/rc.functions
22 export TEXTDOMAIN=alsaconf
24 prefix=/usr
25 exec_prefix=${prefix}
26 bindir=${exec_prefix}/bin
27 sbindir=${exec_prefix}/sbin
28 version=1.0.15
29 USE_NLS=no
31 # Useful for debugging
32 PROCFS="/proc"
33 SYSFS="/sys"
35 # i18n stuff
36 xecho() {
37 echo "$*"
38 }
39 gettext() {
40 echo -n "$*"
41 }
43 xmsg() {
44 msg=$(gettext "$1")
45 shift
46 printf "$msg" $*
47 }
49 distribution="unknown"
51 for prog in lspci lsmod; do
52 for path in /sbin /usr/sbin /bin /usr/bin;do
53 test -x $path/$prog && eval $prog=$path/$prog
54 done
55 done
56 unset prog path
58 usage() {
59 xecho "ALSA configurator (modified for SliTaz GNU/Linux)"
60 echo " version $version"
61 xecho "usage: alsaconf [options]
62 -l|--legacy check only legacy non-isapnp cards
63 -m|--modinfo read module descriptions instead of reading card db
64 -s|--sound wav-file
65 use the specified wav file as a test sound
66 -u|--uid uid set the uid for the ALSA devices (default = 0) [obsoleted]
67 -g|--gid gid set the gid for the ALSA devices (default = 0) [obsoleted]
68 -d|--devmode mode
69 set the permission for ALSA devices (default = 0666) [obs.]
70 -r|--strict set strict device mode (equiv. with -g 17 -d 0660) [obsoleted]
71 -L|--log file logging on the specified file (for debugging purpose only)
72 -p|--probe card-name
73 probe a legacy non-isapnp card and print module options
74 -P|--listprobe list the supported legacy card modules
75 -c|--config file
76 specify the module config file
77 -R|--resources list available DMA and IRQ resources with debug for legacy
78 -M|--module load ALSA module device
79 -h|--help what you're reading"
80 }
82 OPTS=`getopt -o lmL:hp:Pu:g:d:rs:c:RM: --long legacy,modinfo,log:,help,probe:,listprobe,uid:,gid:,devmode:,strict,sound:,config:,resources,module: -n alsaconf -- "$@"` || exit 1
83 eval set -- "$OPTS"
85 do_legacy_only=0
86 use_modinfo_db=0
87 alsa_uid=0
88 alsa_gid=0
89 alsa_mode=0666
90 legacy_probe_card=""
91 LOGFILE=""
92 TESTSOUND="/usr/share/sounds/alsa/test.wav"
93 try_all_combination=0
94 resources="false"
95 snd_module=""
97 # legacy support
98 LEGACY_CARDS="opl3sa2 cs4236 cs4232 cs4231 es18xx es1688 sb16 sb8"
100 while true ; do
101 case "$1" in
102 -l|--legacy)
103 do_legacy_only=1; shift ;;
104 -m|--modinfo)
105 use_modinfo_db=1; shift ;;
106 -s|--sound)
107 TESTSOUND=$2; shift 2;;
108 -h|--help)
109 usage; exit 0 ;;
110 -L|--log)
111 LOGFILE="$2"; shift 2;;
112 -p|--probe)
113 legacy_probe_card="$2"; shift 2;;
114 -P|--listprobe)
115 echo "$LEGACY_CARDS"; exit 0;;
116 -u|--uid)
117 alsa_uid="$2"; shift 2;;
118 -g|--gid)
119 alsa_gid="$2"; shift 2;;
120 -d|--devmode)
121 alsa_mode="$2"; shift 2;;
122 -r|--strict)
123 alsa_uid=0; alsa_gid=17; alsa_mode=0660; shift;;
124 -c|--config)
125 cfgfile="$2"; shift 2;;
126 -R|--resources)
127 resources="true"; shift;;
128 -M|--module)
129 snd_module="$2"; shift 2;;
130 --) shift ; break ;;
131 *) usage ; exit 1 ;;
132 esac
133 done
135 #
136 # probe legacy ISA cards
137 #
139 check_dma_avail () {
140 list=""
141 if [ -d $SYSFS/bus/pnp/devices ]; then
142 for dma in $*; do
143 ok="true"
144 for i in $SYSFS/bus/pnp/devices/??:* ; do
145 if grep -q "state = active" $i/resources ; then
146 if grep -q '^dma '$dma'$' $i/resources; then
147 ok="false"
148 fi
149 fi
150 done
151 if [ -r $PROCFS/dma ]; then
152 if grep -q '^ *'$dma': ' $PROCFS/dma ; then
153 ok="false"
154 fi
155 fi
156 if [ "$ok" = "true" ]; then
157 list="$list $dma"
158 fi
159 done
160 else
161 if [ -r $PROCFS/dma ]; then
162 for dma in $*; do
163 grep -q '^ *'$dma': ' $PROCFS/dma || list="$list $dma"
164 done
165 fi
166 fi
167 if [ ! -z "$list" ]; then
168 echo $list
169 fi
170 }
172 check_irq_avail () {
173 list=""
174 if [ -d $SYSFS/bus/pnp/devices ]; then
175 for irq in $*; do
176 ok="true"
177 for i in $SYSFS/bus/pnp/devices/??:* ; do
178 if grep -q "state = active" $i/resources ; then
179 if grep -q '^irq '$irq'$' $i/resources; then
180 ok="false"
181 fi
182 fi
183 done
184 if [ -r $PROCFS/interrupts ]; then
185 if grep -q '^ *'$irq': ' $PROCFS/interrupts ; then
186 ok="false"
187 fi
188 fi
189 if [ "$ok" = "true" ]; then
190 list="$list $irq"
191 fi
192 done
193 else
194 if [ -r $PROCFS/interrupts ]; then
195 for irq in $*; do
196 grep -q '^ *'$irq': ' $PROCFS/interrupts || list="$list $irq"
197 done
198 fi
199 fi
200 if [ ! -z "$list" ]; then
201 echo $list
202 fi
203 }
205 #
206 #
207 #
209 if [ "$resources" = "true" ]; then
210 if [ -d $SYSFS/bus/pnp/devices ]; then
211 for i in $SYSFS/bus/pnp/devices/??:* ; do
212 if [ "$resources" = "true" ]; then
213 echo ">>>>> PnP file: $i/resources"
214 cat $i/resources
215 fi
216 done
217 fi
218 if [ -r $PROCFS/dma ]; then
219 echo ">>>>> Allocated dma channels:"
220 cat $PROCFS/dma
221 fi
222 if [ -r $PROCFS/interrupts ]; then
223 echo ">>>>> Allocated interrupt channels:"
224 cat $PROCFS/interrupts
225 fi
226 echo -n "Valid DMA channels: "
227 check_dma_avail 0 1 2 3 4 5 6 7
228 echo -n "Valid IRQ channels: "
229 check_irq_avail 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
230 exit 0
231 fi
233 # Check for root privileges
234 if [ `id -u` -ne 0 ]; then
235 xecho "You must be root to use this script."
236 exit 1
237 fi
239 #
240 # check the snd_ prefix for ALSA module options
241 # snd_ prefix is obsoleted since 0.9.0rc4.
242 #
243 if /sbin/modinfo -p snd | grep -q snd_ ; then
244 mpfx="snd_"
245 else
246 mpfx=""
247 fi
249 alsa_device_opts=""
250 if /sbin/modinfo -p snd | grep -q uid ; then
251 if [ x"$alsa_uid" != x0 ]; then
252 alsa_device_opts="$alsa_device_opts ${mpfx}device_uid=$alsa_uid"
253 fi
254 if [ x"$alsa_gid" != x0 ]; then
255 alsa_device_opts="$alsa_device_opts ${mpfx}device_gid=$alsa_gid"
256 fi
257 fi
258 if /sbin/modinfo -p snd | grep -q device_mode ; then
259 if [ x"$alsa_mode" != x0 ]; then
260 alsa_device_opts="$alsa_device_opts ${mpfx}device_mode=$alsa_mode"
261 fi
262 fi
264 case `uname -r` in
265 2.6.*)
266 kernel="new"
267 ;;
268 *)
269 kernel="old"
270 ;;
271 esac
273 # cfgfile = base config file to remove/update the sound setting
274 cfgfile="/etc/sound.conf"
276 DIALOG=dialog
278 #
279 # remove the previous configuration by alsaconf
280 #
281 remove_ac_block() {
282 awk '/^'"$ACB"'$/,/^'"$ACE"'$/ { next } { print }'
283 }
285 #
286 # set default mixer volumes with SliTaz setmixer script
287 #
288 set_mixers() {
289 setmixer
290 }
292 # FAREWELL
293 farewell() {
294 local msg=$(gettext "
296 OK, sound driver is configured.
298 ALSA CONFIGURATOR
300 will prepare the card for playing now.
302 Now I'll run alsasound init script, then I'll use
303 amixer to raise the default volumes.
304 You can change the volume later via a mixer
305 program such as alsamixer or gamix.
307 ")
308 $DIALOG --msgbox "$msg" 17 60 || acex 0
309 }
311 # Exit function
312 acex() {
313 cleanup
314 clear
315 exit $1
316 }
318 #
319 # alsasound init script
320 #
322 #rcalsasound=/etc/init.d/alsa
323 rcalsasound=rcalsasound
325 # MAIN
326 if [ -d $PROCFS/asound ]; then
327 $rcalsasound stop >/dev/null 2>&1
328 $rcalsasound unload >/dev/null 2>&1
329 /sbin/rmmod dmasound dmasound_awacs 2>/dev/null
330 fi
333 cleanup () {
334 killall -9 aplay arecord >/dev/null 2>&1
335 /sbin/modprobe -r isapnp >/dev/null 2>&1
336 /sbin/modprobe -r isa-pnp >/dev/null 2>&1
337 rm -f "$TMP" "$addcfg" "$FOUND" "$DUMP"
338 }
339 trap cleanup 0
341 TMP=`mktemp -q /tmp/alsaconf.XXXXXX`
342 if [ $? -ne 0 ]; then
343 xecho "Can't create temp file, exiting..."
344 exit 1
345 fi
346 addcfg=`mktemp -q /tmp/alsaconf.XXXXXX`
347 if [ $? -ne 0 ]; then
348 xecho "Can't create temp file, exiting..."
349 exit 1
350 fi
351 FOUND=`mktemp -q /tmp/alsaconf.XXXXXX`
352 if [ $? -ne 0 ]; then
353 xecho "Can't create temp file, exiting..."
354 exit 1
355 fi
356 DUMP=`mktemp -q /tmp/alsaconf.XXXXXX`
357 if [ $? -ne 0 ]; then
358 xecho "Can't create temp file, exiting..."
359 exit 1
360 fi
362 # convert ISA PnP id number to string 'ABC'
363 convert_isapnp_id () {
364 if [ -z "$1" ]; then
365 echo "XXXX"
366 return
367 fi
368 let a='('$1'>>2) & 0x3f'
369 let b='(('$1' & 0x03) << 3) | (('$1' >> 13) & 0x07)'
370 let c='('$1'>> 8) & 0x1f'
371 strs='@ABCDEFGHIJKLMNOPQRSTUVWXYZ'
372 echo $strs | awk "{ printf \"%s%s%s\n\", \
373 substr(\$0,$a+1,1),substr(\$0,$b+1,1),substr(\$0,$c+1,1) }"
374 }
376 # swap high & low bytes
377 swap_number () {
378 if [ -z "$1" ]; then
379 echo "0000"
380 return
381 fi
382 let v='(('$1'>>8)&0xff)|(('$1'&0xff)<<8)'
383 printf "%04x" $v
384 }
386 # build card database
387 # build_card_db filename
388 build_card_db () {
389 MODDIR=/lib/modules/`uname -r`
390 last_driver=""
391 echo -n > $1
393 # list pci cards
394 while read driver vendor device dummy; do
395 if expr $driver : 'snd-.*' >/dev/null ; then
396 if [ "$last_driver" != "$driver" ]; then
397 echo $driver.o
398 last_driver=$driver
399 fi
400 id1=`printf '0x%04x' $vendor`
401 id2=`printf '0x%04x' $device`
402 echo "PCI: $id1=$id2"
403 fi
404 done < $MODDIR/modules.pcimap >> $1
406 # list isapnp cards
407 while read driver cardvendor carddevice data vendor func; do
408 if expr $driver : 'snd-.*' >/dev/null ; then
409 if [ "$last_driver" != "$driver" ]; then
410 echo $driver.o
411 last_driver=$driver
412 fi
413 id1=`convert_isapnp_id $cardvendor`
414 dev1=`swap_number $carddevice`
415 id2=`convert_isapnp_id $vendor`
416 dev2=`swap_number $func`
417 echo "ISAPNP: $id1$dev1=$id2$dev2"
418 fi
419 done < $MODDIR/modules.isapnpmap >> $1
420 }
422 #
423 # probe this card
424 #
425 probe_this_card () {
426 echo -n '' > $FOUND
427 # list pci cards
428 grep snd-$1 /lib/modules/`uname -r`/modules.pcimap | \
429 while read driver vendor device dummy; do
430 if expr $driver : 'snd-.*' >/dev/null ; then
431 if [ "$last_driver" != "$driver" ]; then
432 echo $driver.o
433 last_driver=$driver
434 fi
435 id1=`printf '%04x' $vendor`
436 id2=`printf '%04x' $device`
437 echo "PCI: 0x$id1=0x$id2"
438 if $lspci -n 2>/dev/null | grep -q "$id1:$id2"; then
439 echo "$id1:$id2 $last_driver" >> $FOUND
440 fi
441 fi
442 done > /var/tmp/alsaconf.mycard
443 [ -s $FOUND ]
444 }
446 #
447 # probe cards
448 #
449 probe_cards () {
450 found="0"
451 test -r $PROCFS/isapnp || /sbin/modprobe isapnp >/dev/null 2>&1
452 test -r $PROCFS/isapnp || /sbin/modprobe isa-pnp >/dev/null 2>&1
453 if [ -r $PROCFS/isapnp ]; then
454 cat $PROCFS/isapnp >"$DUMP"
455 found="1"
456 elif [ -d $SYSFS/bus/pnp/devices ]; then
457 # use 2.6 kernel's sysfs output
458 # fake the isapnp dump
459 index=0
460 bindex=0
461 for d1 in $SYSFS/devices/pnp* ; do
462 for d2 in $d1/*:* ; do
463 if [ -r $d2/card_id ]; then
464 id=`cat $d2/card_id`
465 name=`cat $d2/name`
466 echo "Card $index '$id:$name' " >> "$DUMP"
467 index=$[$index+1]
468 found="1"
469 else if [ -r $d2/id ]; then
470 # FIXME: multiple id might be present (separated with new-line)
471 id=`head -n 1 $d2/id`
472 echo "BIOS $bindex '$id' " >> "$DUMP"
473 bindex=$[$bindex+1]
474 found="1"
475 fi
476 fi
477 done
478 done
479 fi
480 if [ "$found" = "0" ]; then
481 echo -n >"$DUMP"
482 fi
483 CARDID_DB=/var/tmp/alsaconf.cards
484 if [ ! -r $CARDID_DB ]; then
485 use_modinfo_db=1
486 fi
487 if [ $use_modinfo_db != 1 ]; then
488 if [ $CARDID_DB -ot /lib/modules/`uname -r`/modules.dep ]; then
489 use_modinfo_db=1
490 fi
491 fi
492 if [ $use_modinfo_db = 1 ]; then
493 xecho "Building card database.."
494 build_card_db $CARDID_DB
495 fi
496 if [ ! -r $CARDID_DB ]; then
497 xecho "No card database is found.."
498 exit 1
499 fi
500 ncards=`grep '^snd-.*\.o$' $CARDID_DB | wc -w`
502 msg=$(gettext "Searching sound cards")
503 awk '
504 BEGIN {
505 format="%-40s %s\n";
506 ncards='"$ncards"';
507 idx=0;
508 }
509 /^snd-.*\.o$/{
510 sub(/.o$/, "");
511 driver=$0;
512 perc=(idx * 100) / (ncards + 1);
513 print int(perc);
514 idx++;
515 }
516 /^[<literal space><literal tab>]*PCI: /{
517 gsub(/0x/, "");
518 gsub(/=/, ":");
519 x = sprintf ("'$lspci' -n 2>/dev/null| grep '"' 04..: '"' | grep %s", $2);
520 if (system (x) == 0)
521 printf "%s %s\n", $2, driver >>"'"$FOUND"'"
522 }
523 /^[<literal space><literal tab>]*ISAPNP: /{
524 id2 = substr($0, index($0, "=")+1);
525 gsub(/=.*/, "");
526 x = sprintf ("grep '\''^Card [0-9] .%s:'\'' '"$DUMP"'", $2);
527 if (system (x) == 0)
528 printf "%s %s\n", $2, driver >>"'"$FOUND"'"
529 else if (index($2, "ffff") > 0) {
530 x = sprintf ("grep '\''^BIOS [0-9]* .%s.'\'' '"$DUMP"'", id2);
531 if (system (x) == 0)
532 printf "%s %s\n", id2, driver >>"'"$FOUND"'"
533 }
534 }' < $CARDID_DB |\
535 $DIALOG --gauge "$msg" 15 70 5
537 #
538 # PowerMac
539 #
540 if grep -q MacRISC $PROCFS/cpuinfo; then
541 MODDIR=/lib/modules/`uname -r`
542 find $MODDIR -name 'snd-powermac*' -print | \
543 while read i; do
544 i=${i##*/}
545 i=${i%%.o}
546 i=${i%%.ko}
547 echo "PowerMac $i" >> $FOUND
548 done
549 fi
551 #
552 # Sparc
553 #
554 if grep -q Sparc $PROCFS/cpuinfo; then
555 test -r $PROCFS/openprom/name || /bin/mount -t openpromfs none $PROCFS/openprom >/dev/null 2>&1
556 # Check for an "audio" device
557 audio=
558 compat=
559 if test -r $PROCFS/openprom; then
560 audio=`find $PROCFS/openprom -follow -type d -name "audio*" -print`
561 fi
562 if test -n "$audio"; then
563 compat=`cat $audio/compatible`
564 compat=${compat#\'}
565 compat=${compat%\'}
566 compat=${compat#SUNW,}
567 fi
568 # Go through all cards we have
569 MODDIR=/lib/modules/`uname -r`
570 find $MODDIR -name 'snd-sun-*' -print | \
571 while read i; do
572 i=${i##*/}
573 i=${i%%.o}
574 i=${i%%.ko}
575 sdev=`echo ${i#snd-sun-} | tr "[a-z]" "[A-Z]"`
577 if test "$sdev" = "$compat"; then
578 echo "$sdev $i" >> $FOUND
579 elif test -r $PROCFS/openprom; then
580 find $PROCFS/openprom -follow -type d -name "SUNW,${sdev}*" \
581 -exec echo "$sdev $i" \; 2>/dev/null >> $FOUND
582 else
583 echo "$sdev $i" >> $FOUND
584 fi
585 done
586 fi
587 }
589 #
590 # look for a descriptive device name from the given device id
591 #
592 find_device_name () {
593 if expr "$1" : '[0-9a-f][0-9a-f][0-9a-f][0-9a-f]:[0-9a-f][0-9a-f][0-9a-f][0-9a-f]' >/dev/null; then
594 $lspci -d $1 2>/dev/null| sed -e 's/^.*:..\.. [^:]*: //g'
595 return
596 elif expr "$1" : '[A-Z@][A-Z@][A-Z@][0-9a-f][0-9a-f][0-9a-f][0-9a-f]' >/dev/null; then
597 cardname=`grep '^Card [0-9]\+ .'$1':' $DUMP | head -n 1 | sed -e 's/^Card [0-9]\+ '\''.*:\(.*\)'\'' .*$/\1/'`
598 echo $cardname
599 else
600 echo $1
601 fi
602 }
604 # get hwcfg file type from the given driver name
605 get_hwcfg_type () {
606 while read dev driver; do
607 if [ "$driver" = "$1" ]; then
608 case "$dev" in
609 *:*)
610 # FIXME: need to look around /sys/bus/pci/* (or use vpid-* ?)
611 devid=`$lspci -d "$dev" | head -n 1 | sed -e 's/ .*$//'`
612 case "$devid" in
613 *:*:*.*) ;;
614 *) devid="0000:$devid" ;;
615 esac
616 echo bus-pci-$devid
617 ;;
618 *)
619 echo $driver
620 ;;
621 esac
622 break
623 fi
624 done
625 }
627 # clean up all hwcfg-* files containing ALSA modules
628 # alsaconf sets up exclusively
629 cleanup_hwcfg () {
630 for i in /etc/sysconfig/hardware/hwcfg-*; do
631 grep -q "MODULE='snd-" $i && rm -f $i
632 done
633 }
635 #
636 # set up /etc/sysconfig/hardware/hwcfg-* stuff
637 #
638 setup_hwcfg () {
639 card=$1
640 cleanup_hwcfg
641 cfg=`echo "$devs_olist" | get_hwcfg_type $card`
642 echo "MODULE='$card'" > /etc/sysconfig/hardware/hwcfg-$cfg
643 echo "STARTMODE='auto'" >> /etc/sysconfig/hardware/hwcfg-$cfg
644 }
647 #
648 # Configure sound card and set mixer for SliTaz Live mode
649 #
650 ac_config_card () {
652 CARD_DRIVER=snd-$1
653 shift; CARD_OPTS="$*"
654 SOUND_CORE="snd"
656 # Keep card driver name in /var/lib to be used by boot scripts.
657 echo $CARD_DRIVER > /var/lib/sound-card-driver
659 modprobe $CARD_DRIVER >/dev/null 2>&1
661 # Sed /etc/rcS.conf to add driver in LOAD_MODULES
662 . /etc/rcS.conf
663 modules=`echo "$LOAD_MODULES" | sed s/$CARD_DRIVER//`
664 newmods="$modules $CARD_DRIVER"
665 sed -i s/"LOAD_MODULES=\"$LOAD_MODULES\""/"LOAD_MODULES=\"$newmods\""/ \
666 /etc/rcS.conf
668 # Set default mixer volumes
669 set_mixers
671 # Store
672 alsactl store
673 }
675 # check playback
676 # return 0 - OK, 1 - NG, 2 - not working (irq/dma problem)
677 ac_try_load () {
678 local p1=$1
679 shift
680 test -n "$LOGFILE" && echo "$p1 $*" >> "$LOGFILE"
681 /sbin/modprobe snd-$p1 $* >/dev/null 2>&1
682 if $lsmod | grep -q -E '^(snd-|snd_)'$p1' '; then
683 : ;
684 else
685 /sbin/modprobe -r snd-$p1 >/dev/null 2>&1
686 return 1
687 fi
689 # mute mixers
690 amixer set Master 0% mute >/dev/null 2>&1
691 amixer set PCM 0% mute >/dev/null 2>&1
693 # output 0.5 sec
694 head -c 4000 < /dev/zero | aplay -N -r8000 -fS16_LE -traw -c1 > /dev/null 2>&1 &
695 # remember pid
696 pp=$!
697 # sleep for 2 seconds (to be sure -- 1 sec would be enough)
698 sleep 2
699 # kill the child process if still exists.
700 kill -9 $pp > /dev/null 2>&1
701 st=$?
702 ac_cardname=`head -n 1 $PROCFS/asound/cards | sed -e 's/^[0-9].* - \(.*\)$/\1/'`
703 /sbin/modprobe -r snd-$p1 >/dev/null 2>&1
704 if [ $st = 0 ]; then
705 # irq problem?
706 test -n "$LOGFILE" && echo "no playback return" >> "$LOGFILE"
707 return 2
708 else
709 # seems ok!
710 test -n "$LOGFILE" && echo "playback OK" >> "$LOGFILE"
711 return 0
712 fi
713 }
715 # check capture
716 # return 0 - OK, 1 - NG, 2 - not working (irq/dma problem)
717 # ac_try_capture card duplex opts
718 ac_try_capture () {
719 local p1=$1
720 local p2=$2
721 shift 2
722 test -n "$LOGFILE" && echo "$p1 $p2 $*" >> "$LOGFILE"
723 /sbin/modprobe snd-$p1 $* >/dev/null 2>&1
724 if $lsmod | grep -q -E '^(snd-|snd_)'$p1' '; then
725 : ;
726 else
727 /sbin/modprobe -r snd-$p1 >/dev/null 2>&1
728 return 1
729 fi
731 # mute mixers
732 amixer set Master 0% mute >/dev/null 2>&1
733 amixer set PCM 0% mute >/dev/null 2>&1
735 play_pid=0
736 if [ $p2 = yes ]; then
737 # try duplex - start dummy playing
738 aplay -N -r8000 -fS16_LE -traw -c1 < /dev/zero > /dev/null 2>&1 &
739 play_pid=$!
740 fi
741 # record 1sec
742 arecord -N -d1 > /dev/null 2>&1 &
743 # remember pid
744 pp=$!
745 # sleep for 2 seconds
746 sleep 2
747 # kill the child process if still exists.
748 kill -9 $pp > /dev/null 2>&1
749 st=$?
750 # kill playback process if any
751 test $play_pid != 0 && kill -9 $play_pid
752 /sbin/modprobe -r snd-$p1 >/dev/null 2>&1
753 if [ $st = 0 ]; then
754 test -n "$LOGFILE" && echo "capture no return" >> "$LOGFILE"
755 return 2
756 else
757 test -n "$LOGFILE" && echo "capture OK" >> "$LOGFILE"
758 return 0
759 fi
760 }
762 get_dma_pair () {
763 case $1 in
764 0)
765 echo 1 3 5;;
766 1)
767 echo 0 3 5;;
768 3)
769 echo 1 0 5;;
770 5)
771 echo 3 1 0;;
772 esac
773 }
775 #
776 # check playback on specified irqs
777 #
778 # ac_try_irq card opts irqs...
779 # return 0 - OK, 1 - NG, 2 - not working (dma problem?)
780 #
781 ac_try_irq () {
782 local p2=$2
783 card=$1
784 opts="$2 ${mpfx}irq=$3"
785 ac_try_load $card $opts >/dev/null 2>&1
786 result=$?
787 case $result in
788 0)
789 ac_opts="$opts"
790 return 0
791 ;;
792 2)
793 shift 3
794 for irq in $*; do
795 opts="$p2 ${mpfx}irq=$irq"
796 ac_try_load $card $opts >/dev/null 2>&1
797 if [ $? = 0 ]; then
798 ac_opts="$opts"
799 return 0
800 fi
801 done
802 return 2
803 ;;
804 esac
805 return 1
806 }
808 #
809 # check playback/capture on dma1 & dma2 & specified irqs
810 #
811 # ac_try_dmas card opts irqs...
812 # return 0 - OK, 1 - NG
813 #
814 ac_try_dmas () {
815 local p1=$1
816 local p2=$2
817 shift 2
818 dma_list=`check_dma_avail 1 0 3 5`
819 for irq in $*; do
820 for dma1 in $dma_list; do
821 for dma2 in `get_dma_pair $dma1`; do
822 opts="$p2 ${mpfx}dma1=$dma1 ${mpfx}dma2=$dma2 ${mpfx}irq=$irq"
823 ac_try_load $p1 $opts >/dev/null 2>&1
824 result=$?
825 if [ $result = 1 ]; then
826 if [ $try_all_combination = 1 ]; then
827 continue
828 else
829 return 1
830 fi
831 elif [ $result = 0 ]; then
832 test -n "$LOGFILE" && echo "Now checking capture..." >> "$LOGFILE"
833 ac_opts="$opts"
834 ac_try_capture $p1 yes $opts >/dev/null 2>&1 && return 0
835 for d in yes no; do
836 for dma2 in $dma_list; do
837 if [ $dma1 != $dma2 ]; then
838 opts="$p2 ${mpfx}dma1=$dma1 ${mpfx}dma2=$dma2 ${mpfx}irq=$irq"
839 ac_opts="$opts"
840 ac_try_capture $p1 $d $opts >/dev/null 2>&1 && return 0
841 fi
842 done
843 done
844 return 0
845 fi
846 done
847 done
848 done
849 return 1
850 }
852 # check if the option $2 exists in card $1: set value $3
853 ac_check_option () {
854 if /sbin/modinfo -p snd-$1 | grep -q $2; then
855 echo "$2=$3"
856 fi
857 }
859 ac_try_card_sb8 () {
860 card=sb8
861 irq_list=`check_irq_avail 5 3 9 10 7`
862 for dma8 in `check_dma_avail 1 3`; do
863 opts="${mpfx}dma8=$dma8"
864 ac_try_irq $card "$opts" $irq_list && return 0
865 done
866 return 1
867 }
869 ac_try_card_sb16 () {
870 card=sb16
871 isapnp=`ac_check_option $card ${mpfx}isapnp 0`
872 opts="$isapnp"
873 irq_list=`check_irq_avail 5 9 10 7 3`
874 dma_list=`check_dma_avail 0 1 3`
875 dma16_list=`check_dma_avail 5 6 7`
876 # at first try auto-probing by driver itself
877 ac_try_load $card $opts >/dev/null 2>&1
878 result=$?
879 case $result in
880 0)
881 ac_opts="$opts"
882 ac_try_capture $card yes $opts >/dev/null 2>&1 && return 0
883 for d in yes no; do
884 for dma8 in $dma_list; do
885 for irq in $irq_list; do
886 opts="${mpfx}dma8=$dma8 ${mpfx}irq=$irq $isapnp"
887 ac_try_capture $card $d $opts >/dev/null 2>&1 && return 0
888 done
889 done
890 done
891 return 0
892 ;;
893 2)
894 for dma16 in $dma16_list; do
895 opts="${mpfx}dma16=$dma16 $isapnp"
896 if ac_try_irq $card "$opts" $irq_list ; then
897 ac_try_capture $card yes $ac_opts >/dev/null 2>&1 && return 0
898 ac_opts_saved="$ac_opts"
899 for d in yes no; do
900 for dma8 in $dma_list; do
901 ac_opts="$ac_opts_saved ${mpfx}dma8=$dma8"
902 ac_try_capture $card $d $ac_opts >/dev/null 2>&1 && return 0
903 done
904 done
905 # return anyway here..
906 return 0
907 fi
908 done
909 ;;
910 esac
911 return 1
912 }
914 ac_try_card_es1688 () {
915 card=es1688
916 opts=""
917 irq_list=`check_irq_avail 5 9 10 7`
918 for dma8 in `check_dma_avail 1 3 0`; do
919 opts="${mpfx}dma8=$dma8 ${mpfx}mpu_irq=-1"
920 ac_try_irq $card "$opts" $irq_list && return 0
921 done
922 return 1
923 }
925 ac_try_card_es18xx () {
926 card=es18xx
927 opts=`ac_check_option $card ${mpfx}isapnp 0`
928 ac_try_dmas $card "$opts" `check_irq_avail 5 9 10 7` && return 0
929 return 1
930 }
932 ac_try_card_cs4236 () {
933 card=cs4236
934 irq_list=`check_irq_avail 5 7 9 11 12 15`
935 isapnp=`ac_check_option $card ${mpfx}isapnp 0`
936 for cport in 0x538 0x210 0xf00; do
937 for port in 0x530 0x534; do
938 opts="${mpfx}port=$port ${mpfx}cport=$cport $isapnp"
939 ac_try_dmas $card "$opts" $irq_list && return 0
940 done
941 done
942 return 1
943 }
945 ac_try_card_cs4232 () {
946 card=cs4232
947 irq_list=`check_irq_avail 5 7 9 11 12 15`
948 isapnp=`ac_check_option $card ${mpfx}isapnp 0`
949 for cport in 0x538 0x210 0xf00; do
950 for port in 0x530 0x534; do
951 opts="${mpfx}port=$port ${mpfx}cport=$cport $isapnp"
952 ac_try_dmas $card "$opts" $irq_list && return 0
953 done
954 done
955 return 1
956 }
958 ac_try_card_cs4231 () {
959 card=cs4231
960 irq_list=`check_irq_avail 5 7 9 11 12 15`
961 for port in 0x530 0x534; do
962 opts="${mpfx}port=$port"
963 ac_try_dmas $card "$opts" $irq_list && return 0
964 done
965 return 1
966 }
968 ac_try_card_opl3sa2 () {
969 card=opl3sa2
970 irq_list=`check_irq_avail 5 9 3 1 11 12 15 0`
971 isapnp=`ac_check_option $card ${mpfx}isapnp 0`
972 for port in 0x370 0x538 0xf86 0x100; do
973 for wss_port in 0x530 0xe80 0xf40 0x604; do
974 opts="${mpfx}fm_port=-1 ${mpfx}midi_port=-1 ${mpfx}port=$port ${mpfx}wss_port=$wss_port $isapnp"
975 ac_try_dmas $card "$opts" $irq_list && return 0
976 done
977 done
978 return 1
979 }
981 ac_config_legacy () {
982 title=$(gettext "WARNING")
983 msg=$(gettext "
984 Probing legacy ISA cards might make
985 your system unstable.
987 Do you want to proceed?
989 ")
990 $DIALOG --title "$title" --yesno "$msg" 10 50 || acex 0
992 if [ x"$1" = x ]; then
993 probe_list="$LEGACY_CARDS"
994 else
995 probe_list=$*
996 fi
997 menu_args=""
999 for card in $probe_list; do
1000 cardname=`/sbin/modinfo -d snd-$card | sed -e 's/^\"\(.*\)\"$/\1/g'`
1001 if [ x"$cardname" != x ]; then
1002 menu_args="$menu_args \"$card\" \"$cardname\" on"
1003 fi
1004 done
1005 if [ "$menu_args" = "" ]; then
1006 msg=$(gettext "No legacy drivers are available
1007 for your machine")
1008 $DIALOG --msgbox "$msg" 5 50
1009 return 1
1010 fi
1011 title=$(gettext "Driver Selection")
1012 msg=$(gettext " Probing legacy ISA cards
1014 Please select the drivers to probe:")
1015 eval $DIALOG --title \"$title\" --checklist \"$msg\" 15 70 5 $menu_args 2> $FOUND || acex 0
1017 if [ $try_all_combination != 1 ]; then
1018 msg=$(gettext "
1019 Shall I try all possible DMA and IRQ combinations?
1020 With this option, some unconventional configuration
1021 might be found, but it will take much longer time.")
1022 if $DIALOG --yesno "$msg" 15 70
1023 then
1024 try_all_combination=1
1025 fi
1026 fi
1028 xecho "Probing legacy cards.. This may take a few minutes.."
1029 echo -n $(gettext "Probing: ")
1030 cards=`cat $FOUND | tr -d \"`
1031 for card in $cards; do
1032 echo -n " $card"
1033 ac_opts=""
1034 if eval ac_try_card_$card ; then
1035 xecho " : FOUND!!"
1036 ac_config_card $card $ac_opts
1037 return 0
1038 fi
1039 done
1040 echo
1041 title=$(gettext "Result")
1042 msg=$(gettext "No legacy cards found")
1043 $DIALOG --title "$title" --msgbox "$msg" 15 70 5
1044 return 1
1048 # main part continued..
1051 if test -n "$LOGFILE" ; then
1052 touch "$LOGFILE"
1053 echo -n "Starting alsaconf: " >> "$LOGFILE"
1054 date >> "$LOGFILE"
1055 fi
1057 if [ x"$legacy_probe_card" != x ]; then
1058 ac_opts=""
1059 if eval ac_try_card_$legacy_probe_card >/dev/null 2>&1; then
1060 echo "$ac_opts"
1061 echo "$ac_cardname"
1062 exit 0
1063 else
1064 echo "FAILED"
1065 exit 1
1066 fi
1067 fi
1070 if [ $do_legacy_only = 1 ]; then
1071 ac_config_legacy
1072 exit 0
1073 fi
1075 if [ -n "$snd_module" ]; then
1076 if probe_this_card $snd_module; then
1077 ac_config_card $snd_module
1078 exit 0
1079 fi
1080 fi
1081 probe_cards
1083 devs_found=""
1084 devs_olist=""
1086 if [ -s "$FOUND" ]; then
1087 while read dev card ; do
1088 MODDIR=/lib/modules/`uname -r`
1089 find $MODDIR -type f | grep -q -E $card'\.(o|ko)' || continue
1090 cardname=`find_device_name $dev | cut -c 1-64`
1091 if [ -z "$cardname" ]; then
1092 cardname="$card"
1093 fi
1094 card=${card##snd-}
1095 devs_found="$devs_found $card \"$cardname\""
1096 #devs_devs=("${devs_devs[@]}" "$card" "$dev")
1097 done <"$FOUND"
1098 devs_olist=`cat $FOUND`
1099 fi
1100 if [ "$devs_found" != "" ]; then
1102 # check for TP600E
1104 if [ "${devs_found%% *}" = "cs46xx" ]; then
1105 if $lspci -nv 2>/dev/null| grep -q "Subsystem: 1014:1010"; then
1106 msg=$(gettext "
1107 Looks like you having a Thinkpad 600E or 770 notebook.
1108 On this notebook, CS4236 driver should be used
1109 although CS46xx chip is detected.
1111 Shall I try to snd-cs4236 driver and probe
1112 the legacy ISA configuration?")
1113 if $DIALOG --yesno "$msg" 13 60
1114 then
1115 try_all_combination=1
1116 ac_config_legacy cs4236
1117 exit 0
1118 fi
1119 elif $lspci -nv 2>/dev/null| grep -q "Subsystem: 8086:8080"; then
1120 msg=$(gettext "
1121 Looks like you having a Dell Dimension machine.
1122 On this machine, CS4232 driver should be used
1123 although CS46xx chip is detected.
1125 Shall I try to snd-cs4232 driver and probe
1126 the legacy ISA configuration?")
1127 if $DIALOG --yesno "$msg" 13 60
1128 then
1129 try_all_combination=1
1130 ac_config_legacy cs4232
1131 exit 0
1132 fi
1133 fi
1134 fi
1136 devs_found="$devs_found legacy 'Probe legacy ISA (non-PnP) chips'"
1137 title=$(gettext "Soundcard Selection")
1138 msg=$(gettext "
1139 Following card(s) are found on your system.
1140 Please skip or choose a soundcard to configure :
1141 ")
1142 eval $DIALOG --title \"$title\" --menu \"$msg\" 15 70 5 $devs_found 2> $FOUND || acex 0
1143 card=`head -n 1 $FOUND`
1144 if [ "$card" = "legacy" ]; then
1145 ac_config_legacy
1146 else
1147 ac_config_card "$card"
1148 fi
1149 exit 0
1150 else
1151 msg=$(gettext "
1152 No supported PnP or PCI card found.
1154 Would you like to probe legacy ISA sound cards/chips?
1156 ")
1157 if $DIALOG --yesno "$msg" 15 70 ; then
1158 ac_config_legacy
1159 exit 0
1160 fi
1161 fi
1163 rm -f "$FOUND" "$DUMP"
1164 exit 0