slitaz-tools view tinyutils/soundconf @ rev 17

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