slitaz-tools view tinyutils/soundconf @ rev 110

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