slitaz-tools view tinyutils/soundconf @ rev 190

Add tazdialog
author Pascal Bellard <pascal.bellard@slitaz.org>
date Wed May 14 13:52:28 2008 +0000 (2008-05-14)
parents d10ae2aa1330
children 0c915e47ea57
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/modprobe.conf"
276 # Check for dialog
277 if which tazdialog > /dev/null; then
278 DIALOG=tazdialog
279 elif which dialog > /dev/null; then
280 DIALOG=dialog
281 else
282 xecho "Error, dialog or whiptail not found."
283 exit 1
284 fi
286 #
287 # remove the previous configuration by alsaconf
288 #
289 remove_ac_block() {
290 awk '/^'"$ACB"'$/,/^'"$ACE"'$/ { next } { print }'
291 }
293 #
294 # set default mixer volumes
295 #
296 set_mixers() {
297 amixer -s -q <<EOF
298 set Master 75% unmute
299 set Master -12dB
300 set 'Master Mono' 75% unmute
301 set 'Master Mono' -12dB
302 set Front 75% unmute
303 set Front -12dB
304 set PCM 90% unmute
305 set PCM 0dB
306 mixer Synth 90% unmute
307 mixer Synth 0dB
308 mixer CD 90% unmute
309 mixer CD 0dB
310 # mute mic
311 set Mic 0% mute
312 # ESS 1969 chipset has 2 PCM channels
313 set PCM,1 90% unmute
314 set PCM,1 0dB
315 # Trident/YMFPCI/emu10k1
316 set Wave 100% unmute
317 set Music 100% unmute
318 set AC97 100% unmute
319 # CS4237B chipset:
320 set 'Master Digital' 75% unmute
321 # Envy24 chips with analog outs
322 set DAC 90% unmute
323 set DAC -12dB
324 set DAC,0 90% unmute
325 set DAC,0 -12dB
326 set DAC,1 90% unmute
327 set DAC,1 -12dB
328 # some notebooks use headphone instead of master
329 set Headphone 75% unmute
330 set Headphone -12dB
331 set Playback 100% unmute
332 # turn off digital switches
333 set "SB Live Analog/Digital Output Jack" off
334 set "Audigy Analog/Digital Output Jack" off
335 EOF
336 }
338 # FAREWELL
339 farewell() {
340 local msg=$(gettext "
342 OK, sound driver is configured.
344 ALSA CONFIGURATOR
346 will prepare the card for playing now.
348 Now I'll run alsasound init script, then I'll use
349 amixer to raise the default volumes.
350 You can change the volume later via a mixer
351 program such as alsamixer or gamix.
353 ")
354 $DIALOG --msgbox "$msg" 17 60 || acex 0
355 }
357 # Exit function
358 acex() {
359 cleanup
360 clear
361 exit $1
362 }
364 #
365 # alsasound init script
366 #
368 #rcalsasound=/etc/init.d/alsa
369 rcalsasound=rcalsasound
371 # MAIN
372 if [ -d $PROCFS/asound ]; then
373 $rcalsasound stop >/dev/null 2>&1
374 $rcalsasound unload >/dev/null 2>&1
375 /sbin/rmmod dmasound dmasound_awacs 2>/dev/null
376 fi
379 cleanup () {
380 killall -9 aplay arecord >/dev/null 2>&1
381 /sbin/modprobe -r isapnp >/dev/null 2>&1
382 /sbin/modprobe -r isa-pnp >/dev/null 2>&1
383 rm -f "$TMP" "$addcfg" "$FOUND" "$DUMP"
384 }
385 trap cleanup 0
387 TMP=`mktemp -q /tmp/alsaconf.XXXXXX`
388 if [ $? -ne 0 ]; then
389 xecho "Can't create temp file, exiting..."
390 exit 1
391 fi
392 addcfg=`mktemp -q /tmp/alsaconf.XXXXXX`
393 if [ $? -ne 0 ]; then
394 xecho "Can't create temp file, exiting..."
395 exit 1
396 fi
397 FOUND=`mktemp -q /tmp/alsaconf.XXXXXX`
398 if [ $? -ne 0 ]; then
399 xecho "Can't create temp file, exiting..."
400 exit 1
401 fi
402 DUMP=`mktemp -q /tmp/alsaconf.XXXXXX`
403 if [ $? -ne 0 ]; then
404 xecho "Can't create temp file, exiting..."
405 exit 1
406 fi
408 # convert ISA PnP id number to string 'ABC'
409 convert_isapnp_id () {
410 if [ -z "$1" ]; then
411 echo "XXXX"
412 return
413 fi
414 let a='('$1'>>2) & 0x3f'
415 let b='(('$1' & 0x03) << 3) | (('$1' >> 13) & 0x07)'
416 let c='('$1'>> 8) & 0x1f'
417 strs='@ABCDEFGHIJKLMNOPQRSTUVWXYZ'
418 echo $strs | awk "{ printf \"%s%s%s\n\", \
419 substr(\$0,$a+1,1),substr(\$0,$b+1,1),substr(\$0,$c+1,1) }"
420 }
422 # swap high & low bytes
423 swap_number () {
424 if [ -z "$1" ]; then
425 echo "0000"
426 return
427 fi
428 let v='(('$1'>>8)&0xff)|(('$1'&0xff)<<8)'
429 printf "%04x" $v
430 }
432 # build card database
433 # build_card_db filename
434 build_card_db () {
435 MODDIR=/lib/modules/`uname -r`
436 last_driver=""
437 echo -n > $1
439 # list pci cards
440 while read driver vendor device dummy; do
441 if expr $driver : 'snd-.*' >/dev/null ; then
442 if [ "$last_driver" != "$driver" ]; then
443 echo $driver.o
444 last_driver=$driver
445 fi
446 id1=`printf '0x%04x' $vendor`
447 id2=`printf '0x%04x' $device`
448 echo "PCI: $id1=$id2"
449 fi
450 done < $MODDIR/modules.pcimap >> $1
452 # list isapnp cards
453 while read driver cardvendor carddevice data vendor func; do
454 if expr $driver : 'snd-.*' >/dev/null ; then
455 if [ "$last_driver" != "$driver" ]; then
456 echo $driver.o
457 last_driver=$driver
458 fi
459 id1=`convert_isapnp_id $cardvendor`
460 dev1=`swap_number $carddevice`
461 id2=`convert_isapnp_id $vendor`
462 dev2=`swap_number $func`
463 echo "ISAPNP: $id1$dev1=$id2$dev2"
464 fi
465 done < $MODDIR/modules.isapnpmap >> $1
466 }
468 #
469 # probe this card
470 #
471 probe_this_card () {
472 echo -n '' > $FOUND
473 # list pci cards
474 grep snd-$1 /lib/modules/`uname -r`/modules.pcimap | \
475 while read driver vendor device dummy; do
476 if expr $driver : 'snd-.*' >/dev/null ; then
477 if [ "$last_driver" != "$driver" ]; then
478 echo $driver.o
479 last_driver=$driver
480 fi
481 id1=`printf '%04x' $vendor`
482 id2=`printf '%04x' $device`
483 echo "PCI: 0x$id1=0x$id2"
484 if $lspci -n 2>/dev/null | grep -q "$id1:$id2"; then
485 echo "$id1:$id2 $last_driver" >> $FOUND
486 fi
487 fi
488 done > /var/tmp/alsaconf.mycard
489 [ -s $FOUND ]
490 }
492 #
493 # probe cards
494 #
495 probe_cards () {
496 found="0"
497 test -r $PROCFS/isapnp || /sbin/modprobe isapnp >/dev/null 2>&1
498 test -r $PROCFS/isapnp || /sbin/modprobe isa-pnp >/dev/null 2>&1
499 if [ -r $PROCFS/isapnp ]; then
500 cat $PROCFS/isapnp >"$DUMP"
501 found="1"
502 elif [ -d $SYSFS/bus/pnp/devices ]; then
503 # use 2.6 kernel's sysfs output
504 # fake the isapnp dump
505 index=0
506 bindex=0
507 for d1 in $SYSFS/devices/pnp* ; do
508 for d2 in $d1/*:* ; do
509 if [ -r $d2/card_id ]; then
510 id=`cat $d2/card_id`
511 name=`cat $d2/name`
512 echo "Card $index '$id:$name' " >> "$DUMP"
513 index=$[$index+1]
514 found="1"
515 else if [ -r $d2/id ]; then
516 # FIXME: multiple id might be present (separated with new-line)
517 id=`head -n 1 $d2/id`
518 echo "BIOS $bindex '$id' " >> "$DUMP"
519 bindex=$[$bindex+1]
520 found="1"
521 fi
522 fi
523 done
524 done
525 fi
526 if [ "$found" = "0" ]; then
527 echo -n >"$DUMP"
528 fi
529 CARDID_DB=/var/tmp/alsaconf.cards
530 if [ ! -r $CARDID_DB ]; then
531 use_modinfo_db=1
532 fi
533 if [ $use_modinfo_db != 1 ]; then
534 if [ $CARDID_DB -ot /lib/modules/`uname -r`/modules.dep ]; then
535 use_modinfo_db=1
536 fi
537 fi
538 if [ $use_modinfo_db = 1 ]; then
539 xecho "Building card database.."
540 build_card_db $CARDID_DB
541 fi
542 if [ ! -r $CARDID_DB ]; then
543 xecho "No card database is found.."
544 exit 1
545 fi
546 ncards=`grep '^snd-.*\.o$' $CARDID_DB | wc -w`
548 msg=$(gettext "Searching sound cards")
549 awk '
550 BEGIN {
551 format="%-40s %s\n";
552 ncards='"$ncards"';
553 idx=0;
554 }
555 /^snd-.*\.o$/{
556 sub(/.o$/, "");
557 driver=$0;
558 perc=(idx * 100) / (ncards + 1);
559 print int(perc);
560 idx++;
561 }
562 /^[<literal space><literal tab>]*PCI: /{
563 gsub(/0x/, "");
564 gsub(/=/, ":");
565 x = sprintf ("'$lspci' -n 2>/dev/null| grep '"' 04..: '"' | grep %s", $2);
566 if (system (x) == 0)
567 printf "%s %s\n", $2, driver >>"'"$FOUND"'"
568 }
569 /^[<literal space><literal tab>]*ISAPNP: /{
570 id2 = substr($0, index($0, "=")+1);
571 gsub(/=.*/, "");
572 x = sprintf ("grep '\''^Card [0-9] .%s:'\'' '"$DUMP"'", $2);
573 if (system (x) == 0)
574 printf "%s %s\n", $2, driver >>"'"$FOUND"'"
575 else if (index($2, "ffff") > 0) {
576 x = sprintf ("grep '\''^BIOS [0-9]* .%s.'\'' '"$DUMP"'", id2);
577 if (system (x) == 0)
578 printf "%s %s\n", id2, driver >>"'"$FOUND"'"
579 }
580 }' < $CARDID_DB |\
581 $DIALOG --gauge "$msg" 15 70 5
583 #
584 # PowerMac
585 #
586 if grep -q MacRISC $PROCFS/cpuinfo; then
587 MODDIR=/lib/modules/`uname -r`
588 find $MODDIR -name 'snd-powermac*' -print | \
589 while read i; do
590 i=${i##*/}
591 i=${i%%.o}
592 i=${i%%.ko}
593 echo "PowerMac $i" >> $FOUND
594 done
595 fi
597 #
598 # Sparc
599 #
600 if grep -q Sparc $PROCFS/cpuinfo; then
601 test -r $PROCFS/openprom/name || /bin/mount -t openpromfs none $PROCFS/openprom >/dev/null 2>&1
602 # Check for an "audio" device
603 audio=
604 compat=
605 if test -r $PROCFS/openprom; then
606 audio=`find $PROCFS/openprom -follow -type d -name "audio*" -print`
607 fi
608 if test -n "$audio"; then
609 compat=`cat $audio/compatible`
610 compat=${compat#\'}
611 compat=${compat%\'}
612 compat=${compat#SUNW,}
613 fi
614 # Go through all cards we have
615 MODDIR=/lib/modules/`uname -r`
616 find $MODDIR -name 'snd-sun-*' -print | \
617 while read i; do
618 i=${i##*/}
619 i=${i%%.o}
620 i=${i%%.ko}
621 sdev=`echo ${i#snd-sun-} | tr "[a-z]" "[A-Z]"`
623 if test "$sdev" = "$compat"; then
624 echo "$sdev $i" >> $FOUND
625 elif test -r $PROCFS/openprom; then
626 find $PROCFS/openprom -follow -type d -name "SUNW,${sdev}*" \
627 -exec echo "$sdev $i" \; 2>/dev/null >> $FOUND
628 else
629 echo "$sdev $i" >> $FOUND
630 fi
631 done
632 fi
633 }
635 #
636 # look for a descriptive device name from the given device id
637 #
638 find_device_name () {
639 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
640 $lspci -d $1 2>/dev/null| sed -e 's/^.*:..\.. [^:]*: //g'
641 return
642 elif expr "$1" : '[A-Z@][A-Z@][A-Z@][0-9a-f][0-9a-f][0-9a-f][0-9a-f]' >/dev/null; then
643 cardname=`grep '^Card [0-9]\+ .'$1':' $DUMP | head -n 1 | sed -e 's/^Card [0-9]\+ '\''.*:\(.*\)'\'' .*$/\1/'`
644 echo $cardname
645 else
646 echo $1
647 fi
648 }
650 # get hwcfg file type from the given driver name
651 get_hwcfg_type () {
652 while read dev driver; do
653 if [ "$driver" = "$1" ]; then
654 case "$dev" in
655 *:*)
656 # FIXME: need to look around /sys/bus/pci/* (or use vpid-* ?)
657 devid=`$lspci -d "$dev" | head -n 1 | sed -e 's/ .*$//'`
658 case "$devid" in
659 *:*:*.*) ;;
660 *) devid="0000:$devid" ;;
661 esac
662 echo bus-pci-$devid
663 ;;
664 *)
665 echo $driver
666 ;;
667 esac
668 break
669 fi
670 done
671 }
673 # clean up all hwcfg-* files containing ALSA modules
674 # alsaconf sets up exclusively
675 cleanup_hwcfg () {
676 for i in /etc/sysconfig/hardware/hwcfg-*; do
677 grep -q "MODULE='snd-" $i && rm -f $i
678 done
679 }
681 #
682 # set up /etc/sysconfig/hardware/hwcfg-* stuff
683 #
684 setup_hwcfg () {
685 card=$1
686 cleanup_hwcfg
687 cfg=`echo "$devs_olist" | get_hwcfg_type $card`
688 echo "MODULE='$card'" > /etc/sysconfig/hardware/hwcfg-$cfg
689 echo "STARTMODE='auto'" >> /etc/sysconfig/hardware/hwcfg-$cfg
690 }
693 #
694 # Configure sound card and set mixer for SliTaz Live mode
695 #
696 ac_config_card () {
698 CARD_DRIVER=snd-$1
699 shift; CARD_OPTS="$*"
700 SOUND_CORE="snd"
702 # Keep card driver name in /var/lib to be used by boot scripts.
703 echo $CARD_DRIVER > /var/lib/sound-card-driver
705 modprobe $CARD_DRIVER >/dev/null 2>&1
707 # Sed /etc/rcS.conf to add driver in LOAD_MODULES
708 . /etc/rcS.conf
709 modules=`echo "$LOAD_MODULES" | sed s/$CARD_DRIVER//`
710 newmods="$modules $CARD_DRIVER"
711 sed -i s/"LOAD_MODULES=\"$LOAD_MODULES\""/"LOAD_MODULES=\"$newmods\""/ \
712 /etc/rcS.conf
714 # Set default mixer volumes
715 set_mixers
717 # Store
718 alsactl store
719 }
721 # check playback
722 # return 0 - OK, 1 - NG, 2 - not working (irq/dma problem)
723 ac_try_load () {
724 local p1=$1
725 shift
726 test -n "$LOGFILE" && echo "$p1 $*" >> "$LOGFILE"
727 /sbin/modprobe snd-$p1 $* >/dev/null 2>&1
728 if $lsmod | grep -q -E '^(snd-|snd_)'$p1' '; then
729 : ;
730 else
731 /sbin/modprobe -r snd-$p1 >/dev/null 2>&1
732 return 1
733 fi
735 # mute mixers
736 amixer set Master 0% mute >/dev/null 2>&1
737 amixer set PCM 0% mute >/dev/null 2>&1
739 # output 0.5 sec
740 head -c 4000 < /dev/zero | aplay -N -r8000 -fS16_LE -traw -c1 > /dev/null 2>&1 &
741 # remember pid
742 pp=$!
743 # sleep for 2 seconds (to be sure -- 1 sec would be enough)
744 sleep 2
745 # kill the child process if still exists.
746 kill -9 $pp > /dev/null 2>&1
747 st=$?
748 ac_cardname=`head -n 1 $PROCFS/asound/cards | sed -e 's/^[0-9].* - \(.*\)$/\1/'`
749 /sbin/modprobe -r snd-$p1 >/dev/null 2>&1
750 if [ $st = 0 ]; then
751 # irq problem?
752 test -n "$LOGFILE" && echo "no playback return" >> "$LOGFILE"
753 return 2
754 else
755 # seems ok!
756 test -n "$LOGFILE" && echo "playback OK" >> "$LOGFILE"
757 return 0
758 fi
759 }
761 # check capture
762 # return 0 - OK, 1 - NG, 2 - not working (irq/dma problem)
763 # ac_try_capture card duplex opts
764 ac_try_capture () {
765 local p1=$1
766 local p2=$2
767 shift 2
768 test -n "$LOGFILE" && echo "$p1 $p2 $*" >> "$LOGFILE"
769 /sbin/modprobe snd-$p1 $* >/dev/null 2>&1
770 if $lsmod | grep -q -E '^(snd-|snd_)'$p1' '; then
771 : ;
772 else
773 /sbin/modprobe -r snd-$p1 >/dev/null 2>&1
774 return 1
775 fi
777 # mute mixers
778 amixer set Master 0% mute >/dev/null 2>&1
779 amixer set PCM 0% mute >/dev/null 2>&1
781 play_pid=0
782 if [ $p2 = yes ]; then
783 # try duplex - start dummy playing
784 aplay -N -r8000 -fS16_LE -traw -c1 < /dev/zero > /dev/null 2>&1 &
785 play_pid=$!
786 fi
787 # record 1sec
788 arecord -N -d1 > /dev/null 2>&1 &
789 # remember pid
790 pp=$!
791 # sleep for 2 seconds
792 sleep 2
793 # kill the child process if still exists.
794 kill -9 $pp > /dev/null 2>&1
795 st=$?
796 # kill playback process if any
797 test $play_pid != 0 && kill -9 $play_pid
798 /sbin/modprobe -r snd-$p1 >/dev/null 2>&1
799 if [ $st = 0 ]; then
800 test -n "$LOGFILE" && echo "capture no return" >> "$LOGFILE"
801 return 2
802 else
803 test -n "$LOGFILE" && echo "capture OK" >> "$LOGFILE"
804 return 0
805 fi
806 }
808 get_dma_pair () {
809 case $1 in
810 0)
811 echo 1 3 5;;
812 1)
813 echo 0 3 5;;
814 3)
815 echo 1 0 5;;
816 5)
817 echo 3 1 0;;
818 esac
819 }
821 #
822 # check playback on specified irqs
823 #
824 # ac_try_irq card opts irqs...
825 # return 0 - OK, 1 - NG, 2 - not working (dma problem?)
826 #
827 ac_try_irq () {
828 local p2=$2
829 card=$1
830 opts="$2 ${mpfx}irq=$3"
831 ac_try_load $card $opts >/dev/null 2>&1
832 result=$?
833 case $result in
834 0)
835 ac_opts="$opts"
836 return 0
837 ;;
838 2)
839 shift 3
840 for irq in $*; do
841 opts="$p2 ${mpfx}irq=$irq"
842 ac_try_load $card $opts >/dev/null 2>&1
843 if [ $? = 0 ]; then
844 ac_opts="$opts"
845 return 0
846 fi
847 done
848 return 2
849 ;;
850 esac
851 return 1
852 }
854 #
855 # check playback/capture on dma1 & dma2 & specified irqs
856 #
857 # ac_try_dmas card opts irqs...
858 # return 0 - OK, 1 - NG
859 #
860 ac_try_dmas () {
861 local p1=$1
862 local p2=$2
863 shift 2
864 dma_list=`check_dma_avail 1 0 3 5`
865 for irq in $*; do
866 for dma1 in $dma_list; do
867 for dma2 in `get_dma_pair $dma1`; do
868 opts="$p2 ${mpfx}dma1=$dma1 ${mpfx}dma2=$dma2 ${mpfx}irq=$irq"
869 ac_try_load $p1 $opts >/dev/null 2>&1
870 result=$?
871 if [ $result = 1 ]; then
872 if [ $try_all_combination = 1 ]; then
873 continue
874 else
875 return 1
876 fi
877 elif [ $result = 0 ]; then
878 test -n "$LOGFILE" && echo "Now checking capture..." >> "$LOGFILE"
879 ac_opts="$opts"
880 ac_try_capture $p1 yes $opts >/dev/null 2>&1 && return 0
881 for d in yes no; do
882 for dma2 in $dma_list; do
883 if [ $dma1 != $dma2 ]; then
884 opts="$p2 ${mpfx}dma1=$dma1 ${mpfx}dma2=$dma2 ${mpfx}irq=$irq"
885 ac_opts="$opts"
886 ac_try_capture $p1 $d $opts >/dev/null 2>&1 && return 0
887 fi
888 done
889 done
890 return 0
891 fi
892 done
893 done
894 done
895 return 1
896 }
898 # check if the option $2 exists in card $1: set value $3
899 ac_check_option () {
900 if /sbin/modinfo -p snd-$1 | grep -q $2; then
901 echo "$2=$3"
902 fi
903 }
905 ac_try_card_sb8 () {
906 card=sb8
907 irq_list=`check_irq_avail 5 3 9 10 7`
908 for dma8 in `check_dma_avail 1 3`; do
909 opts="${mpfx}dma8=$dma8"
910 ac_try_irq $card "$opts" $irq_list && return 0
911 done
912 return 1
913 }
915 ac_try_card_sb16 () {
916 card=sb16
917 isapnp=`ac_check_option $card ${mpfx}isapnp 0`
918 opts="$isapnp"
919 irq_list=`check_irq_avail 5 9 10 7 3`
920 dma_list=`check_dma_avail 0 1 3`
921 dma16_list=`check_dma_avail 5 6 7`
922 # at first try auto-probing by driver itself
923 ac_try_load $card $opts >/dev/null 2>&1
924 result=$?
925 case $result in
926 0)
927 ac_opts="$opts"
928 ac_try_capture $card yes $opts >/dev/null 2>&1 && return 0
929 for d in yes no; do
930 for dma8 in $dma_list; do
931 for irq in $irq_list; do
932 opts="${mpfx}dma8=$dma8 ${mpfx}irq=$irq $isapnp"
933 ac_try_capture $card $d $opts >/dev/null 2>&1 && return 0
934 done
935 done
936 done
937 return 0
938 ;;
939 2)
940 for dma16 in $dma16_list; do
941 opts="${mpfx}dma16=$dma16 $isapnp"
942 if ac_try_irq $card "$opts" $irq_list ; then
943 ac_try_capture $card yes $ac_opts >/dev/null 2>&1 && return 0
944 ac_opts_saved="$ac_opts"
945 for d in yes no; do
946 for dma8 in $dma_list; do
947 ac_opts="$ac_opts_saved ${mpfx}dma8=$dma8"
948 ac_try_capture $card $d $ac_opts >/dev/null 2>&1 && return 0
949 done
950 done
951 # return anyway here..
952 return 0
953 fi
954 done
955 ;;
956 esac
957 return 1
958 }
960 ac_try_card_es1688 () {
961 card=es1688
962 opts=""
963 irq_list=`check_irq_avail 5 9 10 7`
964 for dma8 in `check_dma_avail 1 3 0`; do
965 opts="${mpfx}dma8=$dma8 ${mpfx}mpu_irq=-1"
966 ac_try_irq $card "$opts" $irq_list && return 0
967 done
968 return 1
969 }
971 ac_try_card_es18xx () {
972 card=es18xx
973 opts=`ac_check_option $card ${mpfx}isapnp 0`
974 ac_try_dmas $card "$opts" `check_irq_avail 5 9 10 7` && return 0
975 return 1
976 }
978 ac_try_card_cs4236 () {
979 card=cs4236
980 irq_list=`check_irq_avail 5 7 9 11 12 15`
981 isapnp=`ac_check_option $card ${mpfx}isapnp 0`
982 for cport in 0x538 0x210 0xf00; do
983 for port in 0x530 0x534; do
984 opts="${mpfx}port=$port ${mpfx}cport=$cport $isapnp"
985 ac_try_dmas $card "$opts" $irq_list && return 0
986 done
987 done
988 return 1
989 }
991 ac_try_card_cs4232 () {
992 card=cs4232
993 irq_list=`check_irq_avail 5 7 9 11 12 15`
994 isapnp=`ac_check_option $card ${mpfx}isapnp 0`
995 for cport in 0x538 0x210 0xf00; do
996 for port in 0x530 0x534; do
997 opts="${mpfx}port=$port ${mpfx}cport=$cport $isapnp"
998 ac_try_dmas $card "$opts" $irq_list && return 0
999 done
1000 done
1001 return 1
1004 ac_try_card_cs4231 () {
1005 card=cs4231
1006 irq_list=`check_irq_avail 5 7 9 11 12 15`
1007 for port in 0x530 0x534; do
1008 opts="${mpfx}port=$port"
1009 ac_try_dmas $card "$opts" $irq_list && return 0
1010 done
1011 return 1
1014 ac_try_card_opl3sa2 () {
1015 card=opl3sa2
1016 irq_list=`check_irq_avail 5 9 3 1 11 12 15 0`
1017 isapnp=`ac_check_option $card ${mpfx}isapnp 0`
1018 for port in 0x370 0x538 0xf86 0x100; do
1019 for wss_port in 0x530 0xe80 0xf40 0x604; do
1020 opts="${mpfx}fm_port=-1 ${mpfx}midi_port=-1 ${mpfx}port=$port ${mpfx}wss_port=$wss_port $isapnp"
1021 ac_try_dmas $card "$opts" $irq_list && return 0
1022 done
1023 done
1024 return 1
1027 ac_config_legacy () {
1028 title=$(gettext "WARNING")
1029 msg=$(gettext "
1030 Probing legacy ISA cards might make
1031 your system unstable.
1033 Do you want to proceed?
1035 ")
1036 $DIALOG --title "$title" --yesno "$msg" 10 50 || acex 0
1038 if [ x"$1" = x ]; then
1039 probe_list="$LEGACY_CARDS"
1040 else
1041 probe_list=$*
1042 fi
1043 menu_args=""
1045 for card in $probe_list; do
1046 cardname=`/sbin/modinfo -d snd-$card | sed -e 's/^\"\(.*\)\"$/\1/g'`
1047 if [ x"$cardname" != x ]; then
1048 menu_args="$menu_args \"$card\" \"$cardname\" on"
1049 fi
1050 done
1051 if [ "$menu_args" = "" ]; then
1052 msg=$(gettext "No legacy drivers are available
1053 for your machine")
1054 $DIALOG --msgbox "$msg" 5 50
1055 return 1
1056 fi
1057 title=$(gettext "Driver Selection")
1058 msg=$(gettext " Probing legacy ISA cards
1060 Please select the drivers to probe:")
1061 eval $DIALOG --title \"$title\" --checklist \"$msg\" 15 70 5 $menu_args 2> $FOUND || acex 0
1063 if [ $try_all_combination != 1 ]; then
1064 msg=$(gettext "
1065 Shall I try all possible DMA and IRQ combinations?
1066 With this option, some unconventional configuration
1067 might be found, but it will take much longer time.")
1068 if $DIALOG --yesno "$msg" 15 70
1069 then
1070 try_all_combination=1
1071 fi
1072 fi
1074 xecho "Probing legacy cards.. This may take a few minutes.."
1075 echo -n $(gettext "Probing: ")
1076 cards=`cat $FOUND | tr -d \"`
1077 for card in $cards; do
1078 echo -n " $card"
1079 ac_opts=""
1080 if eval ac_try_card_$card ; then
1081 xecho " : FOUND!!"
1082 ac_config_card $card $ac_opts
1083 return 0
1084 fi
1085 done
1086 echo
1087 title=$(gettext "Result")
1088 msg=$(gettext "No legacy cards found")
1089 $DIALOG --title "$title" --msgbox "$msg" 15 70 5
1090 return 1
1094 # main part continued..
1097 if test -n "$LOGFILE" ; then
1098 touch "$LOGFILE"
1099 echo -n "Starting alsaconf: " >> "$LOGFILE"
1100 date >> "$LOGFILE"
1101 fi
1103 if [ x"$legacy_probe_card" != x ]; then
1104 ac_opts=""
1105 if eval ac_try_card_$legacy_probe_card >/dev/null 2>&1; then
1106 echo "$ac_opts"
1107 echo "$ac_cardname"
1108 exit 0
1109 else
1110 echo "FAILED"
1111 exit 1
1112 fi
1113 fi
1116 if [ $do_legacy_only = 1 ]; then
1117 ac_config_legacy
1118 exit 0
1119 fi
1121 if [ -n "$snd_module" ]; then
1122 if probe_this_card $snd_module; then
1123 ac_config_card $snd_module
1124 exit 0
1125 fi
1126 fi
1127 probe_cards
1129 devs_found=""
1130 devs_olist=""
1132 if [ -s "$FOUND" ]; then
1133 while read dev card ; do
1134 MODDIR=/lib/modules/`uname -r`
1135 find $MODDIR -type f | grep -q -E $card'\.(o|ko)' || continue
1136 cardname=`find_device_name $dev | cut -c 1-64`
1137 if [ -z "$cardname" ]; then
1138 cardname="$card"
1139 fi
1140 card=${card##snd-}
1141 devs_found="$devs_found $card \"$cardname\""
1142 #devs_devs=("${devs_devs[@]}" "$card" "$dev")
1143 done <"$FOUND"
1144 devs_olist=`cat $FOUND`
1145 fi
1146 if [ "$devs_found" != "" ]; then
1148 # check for TP600E
1150 if [ "${devs_found%% *}" = "cs46xx" ]; then
1151 if $lspci -nv 2>/dev/null| grep -q "Subsystem: 1014:1010"; then
1152 msg=$(gettext "
1153 Looks like you having a Thinkpad 600E or 770 notebook.
1154 On this notebook, CS4236 driver should be used
1155 although CS46xx chip is detected.
1157 Shall I try to snd-cs4236 driver and probe
1158 the legacy ISA configuration?")
1159 if $DIALOG --yesno "$msg" 13 60
1160 then
1161 try_all_combination=1
1162 ac_config_legacy cs4236
1163 exit 0
1164 fi
1165 elif $lspci -nv 2>/dev/null| grep -q "Subsystem: 8086:8080"; then
1166 msg=$(gettext "
1167 Looks like you having a Dell Dimension machine.
1168 On this machine, CS4232 driver should be used
1169 although CS46xx chip is detected.
1171 Shall I try to snd-cs4232 driver and probe
1172 the legacy ISA configuration?")
1173 if $DIALOG --yesno "$msg" 13 60
1174 then
1175 try_all_combination=1
1176 ac_config_legacy cs4232
1177 exit 0
1178 fi
1179 fi
1180 fi
1182 devs_found="$devs_found legacy 'Probe legacy ISA (non-PnP) chips'"
1183 title=$(gettext "Soundcard Selection")
1184 msg=$(gettext "
1185 Following card(s) are found on your system.
1186 Please skip or choose a soundcard to configure :
1187 ")
1188 eval $DIALOG --title \"$title\" --menu \"$msg\" 15 70 5 $devs_found 2> $FOUND || acex 0
1189 card=`head -n 1 $FOUND`
1190 if [ "$card" = "legacy" ]; then
1191 ac_config_legacy
1192 else
1193 ac_config_card "$card"
1194 fi
1195 exit 0
1196 else
1197 msg=$(gettext "
1198 No supported PnP or PCI card found.
1200 Would you like to probe legacy ISA sound cards/chips?
1202 ")
1203 if $DIALOG --yesno "$msg" 15 70 ; then
1204 ac_config_legacy
1205 exit 0
1206 fi
1207 fi
1209 rm -f "$FOUND" "$DUMP"
1210 exit 0