slitaz-tools view tinyutils/soundconf @ rev 183

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