slitaz-tools view tinyutils/soundconf @ rev 37

Rewrite tazx and add more screen size and colors choice
author Christophe Lincoln <pankso@slitaz.org>
date Mon Jan 14 13:25:50 2008 +0100 (2008-01-14)
parents 3495ca7075dc
children eeb6350d8c97
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" 6 40 0
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 echo "Loading drivers : $CARD_DRIVER"
676 modprobe $CARD_DRIVER
677 sleep 1
679 # Sed /etc/rcS.conf to add driver in LOAD_MODULES
680 . /etc/rcS.conf
681 modules=`echo "$LOAD_MODULES" | sed s/$CARD_DRIVER//`
682 newmods="$modules $CARD_DRIVER"
683 sed -i s/"LOAD_MODULES=\"$LOAD_MODULES\""/"LOAD_MODULES=\"$newmods\""/ \
684 /etc/rcS.conf
686 # Set default mixer volumes
687 echo -n "Setting default mixers volumes..."
688 set_mixers
689 status
691 # Store
692 alsactl store
694 echo -e "
695 * Now ALSA is ready to use.
696 * For adjustment of volumes, use your favorite mixer.
697 * Have a lot of fun!\n"
698 }
700 # check playback
701 # return 0 - OK, 1 - NG, 2 - not working (irq/dma problem)
702 ac_try_load () {
703 local p1=$1
704 shift
705 test -n "$LOGFILE" && echo "$p1 $*" >> "$LOGFILE"
706 /sbin/modprobe snd-$p1 $* >/dev/null 2>&1
707 if $lsmod | grep -q -E '^(snd-|snd_)'$p1' '; then
708 : ;
709 else
710 /sbin/modprobe -r snd-$p1 >/dev/null 2>&1
711 return 1
712 fi
714 # mute mixers
715 amixer set Master 0% mute >/dev/null 2>&1
716 amixer set PCM 0% mute >/dev/null 2>&1
718 # output 0.5 sec
719 head -c 4000 < /dev/zero | aplay -N -r8000 -fS16_LE -traw -c1 > /dev/null 2>&1 &
720 # remember pid
721 pp=$!
722 # sleep for 2 seconds (to be sure -- 1 sec would be enough)
723 sleep 2
724 # kill the child process if still exists.
725 kill -9 $pp > /dev/null 2>&1
726 st=$?
727 ac_cardname=`head -n 1 $PROCFS/asound/cards | sed -e 's/^[0-9].* - \(.*\)$/\1/'`
728 /sbin/modprobe -r snd-$p1 >/dev/null 2>&1
729 if [ $st = 0 ]; then
730 # irq problem?
731 test -n "$LOGFILE" && echo "no playback return" >> "$LOGFILE"
732 return 2
733 else
734 # seems ok!
735 test -n "$LOGFILE" && echo "playback OK" >> "$LOGFILE"
736 return 0
737 fi
738 }
740 # check capture
741 # return 0 - OK, 1 - NG, 2 - not working (irq/dma problem)
742 # ac_try_capture card duplex opts
743 ac_try_capture () {
744 local p1=$1
745 local p2=$2
746 shift 2
747 test -n "$LOGFILE" && echo "$p1 $p2 $*" >> "$LOGFILE"
748 /sbin/modprobe snd-$p1 $* >/dev/null 2>&1
749 if $lsmod | grep -q -E '^(snd-|snd_)'$p1' '; then
750 : ;
751 else
752 /sbin/modprobe -r snd-$p1 >/dev/null 2>&1
753 return 1
754 fi
756 # mute mixers
757 amixer set Master 0% mute >/dev/null 2>&1
758 amixer set PCM 0% mute >/dev/null 2>&1
760 play_pid=0
761 if [ $p2 = yes ]; then
762 # try duplex - start dummy playing
763 aplay -N -r8000 -fS16_LE -traw -c1 < /dev/zero > /dev/null 2>&1 &
764 play_pid=$!
765 fi
766 # record 1sec
767 arecord -N -d1 > /dev/null 2>&1 &
768 # remember pid
769 pp=$!
770 # sleep for 2 seconds
771 sleep 2
772 # kill the child process if still exists.
773 kill -9 $pp > /dev/null 2>&1
774 st=$?
775 # kill playback process if any
776 test $play_pid != 0 && kill -9 $play_pid
777 /sbin/modprobe -r snd-$p1 >/dev/null 2>&1
778 if [ $st = 0 ]; then
779 test -n "$LOGFILE" && echo "capture no return" >> "$LOGFILE"
780 return 2
781 else
782 test -n "$LOGFILE" && echo "capture OK" >> "$LOGFILE"
783 return 0
784 fi
785 }
787 get_dma_pair () {
788 case $1 in
789 0)
790 echo 1 3 5;;
791 1)
792 echo 0 3 5;;
793 3)
794 echo 1 0 5;;
795 5)
796 echo 3 1 0;;
797 esac
798 }
800 #
801 # check playback on specified irqs
802 #
803 # ac_try_irq card opts irqs...
804 # return 0 - OK, 1 - NG, 2 - not working (dma problem?)
805 #
806 ac_try_irq () {
807 local p2=$2
808 card=$1
809 opts="$2 ${mpfx}irq=$3"
810 ac_try_load $card $opts >/dev/null 2>&1
811 result=$?
812 case $result in
813 0)
814 ac_opts="$opts"
815 return 0
816 ;;
817 2)
818 shift 3
819 for irq in $*; do
820 opts="$p2 ${mpfx}irq=$irq"
821 ac_try_load $card $opts >/dev/null 2>&1
822 if [ $? = 0 ]; then
823 ac_opts="$opts"
824 return 0
825 fi
826 done
827 return 2
828 ;;
829 esac
830 return 1
831 }
833 #
834 # check playback/capture on dma1 & dma2 & specified irqs
835 #
836 # ac_try_dmas card opts irqs...
837 # return 0 - OK, 1 - NG
838 #
839 ac_try_dmas () {
840 local p1=$1
841 local p2=$2
842 shift 2
843 dma_list=`check_dma_avail 1 0 3 5`
844 for irq in $*; do
845 for dma1 in $dma_list; do
846 for dma2 in `get_dma_pair $dma1`; do
847 opts="$p2 ${mpfx}dma1=$dma1 ${mpfx}dma2=$dma2 ${mpfx}irq=$irq"
848 ac_try_load $p1 $opts >/dev/null 2>&1
849 result=$?
850 if [ $result = 1 ]; then
851 if [ $try_all_combination = 1 ]; then
852 continue
853 else
854 return 1
855 fi
856 elif [ $result = 0 ]; then
857 test -n "$LOGFILE" && echo "Now checking capture..." >> "$LOGFILE"
858 ac_opts="$opts"
859 ac_try_capture $p1 yes $opts >/dev/null 2>&1 && return 0
860 for d in yes no; do
861 for dma2 in $dma_list; do
862 if [ $dma1 != $dma2 ]; then
863 opts="$p2 ${mpfx}dma1=$dma1 ${mpfx}dma2=$dma2 ${mpfx}irq=$irq"
864 ac_opts="$opts"
865 ac_try_capture $p1 $d $opts >/dev/null 2>&1 && return 0
866 fi
867 done
868 done
869 return 0
870 fi
871 done
872 done
873 done
874 return 1
875 }
877 # check if the option $2 exists in card $1: set value $3
878 ac_check_option () {
879 if /sbin/modinfo -p snd-$1 | grep -q $2; then
880 echo "$2=$3"
881 fi
882 }
884 ac_try_card_sb8 () {
885 card=sb8
886 irq_list=`check_irq_avail 5 3 9 10 7`
887 for dma8 in `check_dma_avail 1 3`; do
888 opts="${mpfx}dma8=$dma8"
889 ac_try_irq $card "$opts" $irq_list && return 0
890 done
891 return 1
892 }
894 ac_try_card_sb16 () {
895 card=sb16
896 isapnp=`ac_check_option $card ${mpfx}isapnp 0`
897 opts="$isapnp"
898 irq_list=`check_irq_avail 5 9 10 7 3`
899 dma_list=`check_dma_avail 0 1 3`
900 dma16_list=`check_dma_avail 5 6 7`
901 # at first try auto-probing by driver itself
902 ac_try_load $card $opts >/dev/null 2>&1
903 result=$?
904 case $result in
905 0)
906 ac_opts="$opts"
907 ac_try_capture $card yes $opts >/dev/null 2>&1 && return 0
908 for d in yes no; do
909 for dma8 in $dma_list; do
910 for irq in $irq_list; do
911 opts="${mpfx}dma8=$dma8 ${mpfx}irq=$irq $isapnp"
912 ac_try_capture $card $d $opts >/dev/null 2>&1 && return 0
913 done
914 done
915 done
916 return 0
917 ;;
918 2)
919 for dma16 in $dma16_list; do
920 opts="${mpfx}dma16=$dma16 $isapnp"
921 if ac_try_irq $card "$opts" $irq_list ; then
922 ac_try_capture $card yes $ac_opts >/dev/null 2>&1 && return 0
923 ac_opts_saved="$ac_opts"
924 for d in yes no; do
925 for dma8 in $dma_list; do
926 ac_opts="$ac_opts_saved ${mpfx}dma8=$dma8"
927 ac_try_capture $card $d $ac_opts >/dev/null 2>&1 && return 0
928 done
929 done
930 # return anyway here..
931 return 0
932 fi
933 done
934 ;;
935 esac
936 return 1
937 }
939 ac_try_card_es1688 () {
940 card=es1688
941 opts=""
942 irq_list=`check_irq_avail 5 9 10 7`
943 for dma8 in `check_dma_avail 1 3 0`; do
944 opts="${mpfx}dma8=$dma8 ${mpfx}mpu_irq=-1"
945 ac_try_irq $card "$opts" $irq_list && return 0
946 done
947 return 1
948 }
950 ac_try_card_es18xx () {
951 card=es18xx
952 opts=`ac_check_option $card ${mpfx}isapnp 0`
953 ac_try_dmas $card "$opts" `check_irq_avail 5 9 10 7` && return 0
954 return 1
955 }
957 ac_try_card_cs4236 () {
958 card=cs4236
959 irq_list=`check_irq_avail 5 7 9 11 12 15`
960 isapnp=`ac_check_option $card ${mpfx}isapnp 0`
961 for cport in 0x538 0x210 0xf00; do
962 for port in 0x530 0x534; do
963 opts="${mpfx}port=$port ${mpfx}cport=$cport $isapnp"
964 ac_try_dmas $card "$opts" $irq_list && return 0
965 done
966 done
967 return 1
968 }
970 ac_try_card_cs4232 () {
971 card=cs4232
972 irq_list=`check_irq_avail 5 7 9 11 12 15`
973 isapnp=`ac_check_option $card ${mpfx}isapnp 0`
974 for cport in 0x538 0x210 0xf00; do
975 for port in 0x530 0x534; do
976 opts="${mpfx}port=$port ${mpfx}cport=$cport $isapnp"
977 ac_try_dmas $card "$opts" $irq_list && return 0
978 done
979 done
980 return 1
981 }
983 ac_try_card_cs4231 () {
984 card=cs4231
985 irq_list=`check_irq_avail 5 7 9 11 12 15`
986 for port in 0x530 0x534; do
987 opts="${mpfx}port=$port"
988 ac_try_dmas $card "$opts" $irq_list && return 0
989 done
990 return 1
991 }
993 ac_try_card_opl3sa2 () {
994 card=opl3sa2
995 irq_list=`check_irq_avail 5 9 3 1 11 12 15 0`
996 isapnp=`ac_check_option $card ${mpfx}isapnp 0`
997 for port in 0x370 0x538 0xf86 0x100; do
998 for wss_port in 0x530 0xe80 0xf40 0x604; do
999 opts="${mpfx}fm_port=-1 ${mpfx}midi_port=-1 ${mpfx}port=$port ${mpfx}wss_port=$wss_port $isapnp"
1000 ac_try_dmas $card "$opts" $irq_list && return 0
1001 done
1002 done
1003 return 1
1006 ac_config_legacy () {
1007 title=$(gettext "WARNING")
1008 msg=$(gettext "
1009 Probing legacy ISA cards might make
1010 your system unstable.
1012 Do you want to proceed?
1014 ")
1015 $DIALOG --title "$title" --yesno "$msg" 10 50 || acex 0
1017 if [ x"$1" = x ]; then
1018 probe_list="$LEGACY_CARDS"
1019 else
1020 probe_list=$*
1021 fi
1022 menu_args=""
1024 for card in $probe_list; do
1025 cardname=`/sbin/modinfo -d snd-$card | sed -e 's/^\"\(.*\)\"$/\1/g'`
1026 if [ x"$cardname" != x ]; then
1027 menu_args="$menu_args \"$card\" \"$cardname\" on"
1028 fi
1029 done
1030 if [ "$menu_args" = "" ]; then
1031 msg=$(gettext "No legacy drivers are available
1032 for your machine")
1033 $DIALOG --msgbox "$msg" 5 50
1034 return 1
1035 fi
1036 title=$(gettext "Driver Selection")
1037 msg=$(gettext " Probing legacy ISA cards
1039 Please select the drivers to probe:")
1040 eval $DIALOG --title \"$title\" --checklist \"$msg\" 17 64 8 $menu_args 2> $FOUND || acex 0
1042 if [ $try_all_combination != 1 ]; then
1043 msg=$(gettext "
1044 Shall I try all possible DMA and IRQ combinations?
1045 With this option, some unconventional configuration
1046 might be found, but it will take much longer time.")
1047 if $DIALOG --yesno "$msg" 10 60
1048 then
1049 try_all_combination=1
1050 fi
1051 fi
1053 xecho "Probing legacy cards.. This may take a few minutes.."
1054 echo -n $(gettext "Probing: ")
1055 cards=`cat $FOUND | tr -d \"`
1056 for card in $cards; do
1057 echo -n " $card"
1058 ac_opts=""
1059 if eval ac_try_card_$card ; then
1060 xecho " : FOUND!!"
1061 ac_config_card $card $ac_opts
1062 return 0
1063 fi
1064 done
1065 echo
1066 title=$(gettext "Result")
1067 msg=$(gettext "No legacy cards found")
1068 $DIALOG --title "$title" --msgbox "$msg" 5 50
1069 return 1
1073 # main part continued..
1076 if test -n "$LOGFILE" ; then
1077 touch "$LOGFILE"
1078 echo -n "Starting alsaconf: " >> "$LOGFILE"
1079 date >> "$LOGFILE"
1080 fi
1082 if [ x"$legacy_probe_card" != x ]; then
1083 ac_opts=""
1084 if eval ac_try_card_$legacy_probe_card >/dev/null 2>&1; then
1085 echo "$ac_opts"
1086 echo "$ac_cardname"
1087 exit 0
1088 else
1089 echo "FAILED"
1090 exit 1
1091 fi
1092 fi
1095 if [ $do_legacy_only = 1 ]; then
1096 ac_config_legacy
1097 exit 0
1098 fi
1100 probe_cards
1102 devs_found=""
1103 devs_olist=""
1105 if [ -s "$FOUND" ]; then
1106 while read dev card ; do
1107 MODDIR=/lib/modules/`uname -r`
1108 find $MODDIR -type f | grep -q -E $card'\.(o|ko)' || continue
1109 cardname=`find_device_name $dev | cut -c 1-64`
1110 if [ -z "$cardname" ]; then
1111 cardname="$card"
1112 fi
1113 card=${card##snd-}
1114 devs_found="$devs_found $card \"$cardname\""
1115 #devs_devs=("${devs_devs[@]}" "$card" "$dev")
1116 done <"$FOUND"
1117 devs_olist=`cat $FOUND`
1118 fi
1119 if [ "$devs_found" != "" ]; then
1121 # check for TP600E
1123 if [ "${devs_found%% *}" = "cs46xx" ]; then
1124 if $lspci -nv 2>/dev/null| grep -q "Subsystem: 1014:1010"; then
1125 msg=$(gettext "
1126 Looks like you having a Thinkpad 600E or 770 notebook.
1127 On this notebook, CS4236 driver should be used
1128 although CS46xx chip is detected.
1130 Shall I try to snd-cs4236 driver and probe
1131 the legacy ISA configuration?")
1132 if $DIALOG --yesno "$msg" 13 60
1133 then
1134 try_all_combination=1
1135 ac_config_legacy cs4236
1136 exit 0
1137 fi
1138 elif $lspci -nv 2>/dev/null| grep -q "Subsystem: 8086:8080"; then
1139 msg=$(gettext "
1140 Looks like you having a Dell Dimension machine.
1141 On this machine, CS4232 driver should be used
1142 although CS46xx chip is detected.
1144 Shall I try to snd-cs4232 driver and probe
1145 the legacy ISA configuration?")
1146 if $DIALOG --yesno "$msg" 13 60
1147 then
1148 try_all_combination=1
1149 ac_config_legacy cs4232
1150 exit 0
1151 fi
1152 fi
1153 fi
1155 devs_found="$devs_found legacy 'Probe legacy ISA (non-PnP) chips'"
1156 title=$(gettext "Soundcard Selection")
1157 msg=$(gettext "
1158 Following card(s) are found on your system.
1159 Please skip or choose a soundcard to configure :
1160 ")
1161 eval $DIALOG --title \"$title\" --menu \"$msg\" 17 76 8 $devs_found 2> $FOUND || acex 0
1162 card=`head -n 1 $FOUND`
1163 if [ "$card" = "legacy" ]; then
1164 ac_config_legacy
1165 else
1166 ac_config_card "$card"
1167 fi
1168 exit 0
1169 else
1170 msg=$(gettext "
1171 No supported PnP or PCI card found.
1173 Would you like to probe legacy ISA sound cards/chips?
1175 ")
1176 if $DIALOG --yesno "$msg" 9 60 ; then
1177 ac_config_legacy
1178 exit 0
1179 fi
1180 fi
1182 rm -f "$FOUND" "$DUMP"
1183 exit 0