Home | History | Annotate | Download | only in alsaconf
      1 #!/bin/bash
      2 #
      3 #  ALSA Configurator
      4 #
      5 #  Copyright (c) 1999-2002  SuSE GmbH
      6 #                           Jan ONDREJ
      7 #
      8 #  written by Takashi Iwai <tiwai (at] suse.de>
      9 #             Bernd Kaindl <bk (at] suse.de>
     10 #             Jan ONDREJ (SAL) <ondrejj (at] salstar.sk>
     11 #
     12 #  based on the original version of Jan ONDREJ's alsaconf for ALSA 0.4.
     13 #
     14 #  This program is free software; you can redistribute it and/or modify
     15 #  it under the terms of the GNU General Public License as published by
     16 #  the Free Software Foundation; either version 2 of the License, or
     17 #  (at your option) any later version.
     18 #
     19 
     20 export TEXTDOMAIN=alsaconf
     21 
     22 prefix=@prefix@
     23 exec_prefix=@exec_prefix@
     24 bindir=@bindir@
     25 sbindir=@sbindir@
     26 version=@VERSION@
     27 USE_NLS=@USE_NLS@
     28 
     29 # Useful for debugging
     30 PROCFS="/proc"
     31 SYSFS="/sys"
     32 
     33 # i18n stuff
     34 if test "$USE_NLS" = "yes" && type -p gettext > /dev/null; then
     35   xecho() {
     36     gettext -s "$*"
     37   }
     38 else
     39   xecho() {
     40     echo "$*"
     41   }
     42   gettext() {
     43     echo -n "$*"
     44   }
     45 fi
     46 xmsg() {
     47   msg=$(gettext "$1")
     48   shift
     49   printf "$msg" $*
     50 }
     51 
     52 # Check for GNU/Linux distributions
     53 if [ -f /etc/SuSE-release ]; then
     54   distribution="suse"
     55   suse_version=$(grep 'VERSION = ' /etc/SuSE-release | sed -e s/'VERSION = '//)
     56 elif [ -f /etc/UnitedLinux-release ]; then
     57   distribution="suse"
     58 elif [ -f /etc/gentoo-release ]; then
     59   distribution="gentoo"
     60 elif [ -f /etc/debian_version ]; then
     61   distribution="debian"
     62 elif [ -f /etc/mandrake-release ]; then
     63   distribution="mandrake"
     64 elif test -f /etc/redhat-release && grep -q "Red Hat" /etc/redhat-release; then
     65   distribution="redhat"
     66 elif test -f /etc/fedora-release && grep -q "Fedora" /etc/fedora-release; then
     67   distribution="fedora"
     68 elif [ -f /etc/slackware-version -o -f /etc/slamd64-version ]; then
     69   distribution="slackware"
     70 else
     71   distribution="unknown"
     72 fi
     73 
     74 for prog in lspci lsmod; do
     75 	for path in /sbin /usr/sbin /bin /usr/bin;do
     76 		test -x $path/$prog && eval $prog=$path/$prog
     77 	done
     78 done
     79 unset prog path
     80 
     81 usage() {
     82     xecho "ALSA configurator"
     83     echo "  version $version"
     84     xecho "usage: alsaconf [options]
     85   -l|--legacy    check only legacy non-isapnp cards
     86   -m|--modinfo   read module descriptions instead of reading card db
     87   -s|--sound wav-file
     88                  use the specified wav file as a test sound
     89   -u|--uid uid   set the uid for the ALSA devices (default = 0) [obsoleted]
     90   -g|--gid gid   set the gid for the ALSA devices (default = 0) [obsoleted]
     91   -d|--devmode mode
     92                  set the permission for ALSA devices (default = 0666) [obs.]
     93   -r|--strict    set strict device mode (equiv. with -g 17 -d 0660) [obsoleted]
     94   -L|--log file  logging on the specified file (for debugging purpose only)
     95   -p|--probe card-name
     96                  probe a legacy non-isapnp card and print module options
     97   -P|--listprobe list the supported legacy card modules
     98   -c|--config file
     99                  specify the module config file
    100   -R|--resources list available DMA and IRQ resources with debug for legacy
    101   -h|--help      what you're reading"
    102 }
    103 
    104 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
    105 eval set -- "$OPTS"
    106 
    107 do_legacy_only=0
    108 use_modinfo_db=0
    109 alsa_uid=0
    110 alsa_gid=0
    111 alsa_mode=0666
    112 legacy_probe_card=""
    113 LOGFILE=""
    114 TESTSOUND="@TESTSOUND@"
    115 try_all_combination=0
    116 resources="false"
    117 
    118 # legacy support
    119 LEGACY_CARDS="opl3sa2 cs4236 cs4232 cs4231 es18xx es1688 sb16 sb8"
    120 
    121 while true ; do
    122     case "$1" in
    123     -l|--legacy)
    124 	do_legacy_only=1; shift ;;
    125     -m|--modinfo)
    126 	use_modinfo_db=1; shift ;;
    127     -s|--sound)
    128 	TESTSOUND=$2; shift 2;;
    129     -h|--help)
    130 	usage; exit 0 ;;
    131     -L|--log)
    132 	LOGFILE="$2"; shift 2;;
    133     -p|--probe)
    134 	legacy_probe_card="$2"; shift 2;;
    135     -P|--listprobe)
    136 	echo "$LEGACY_CARDS"; exit 0;;
    137     -u|--uid)
    138 	alsa_uid="$2"; shift 2;;
    139     -g|--gid)
    140 	alsa_gid="$2"; shift 2;;
    141     -d|--devmode)
    142 	alsa_mode="$2"; shift 2;;
    143     -r|--strict)
    144 	alsa_uid=0; alsa_gid=17; alsa_mode=0660; shift;;
    145     -c|--config)
    146 	cfgfile="$2"; shift 2;;
    147     -R|--resources)
    148         resources="true"; shift;;
    149     --) shift ; break ;;
    150     *) usage ; exit 1 ;;
    151     esac
    152 done
    153 
    154 #
    155 # probe legacy ISA cards
    156 #
    157 
    158 check_dma_avail () {
    159     list=""
    160     if [ -d $SYSFS/bus/pnp/devices ]; then
    161       for dma in $*; do
    162         ok="true"
    163         for i in $SYSFS/bus/pnp/devices/??:* ; do
    164           if grep -q "state = active" $i/resources ; then
    165             if grep -q '^dma '$dma'$' $i/resources; then
    166               ok="false"
    167             fi
    168           fi
    169         done
    170         if [ -r $PROCFS/dma ]; then
    171 	  if grep -q '^ *'$dma': ' $PROCFS/dma ; then
    172             ok="false"
    173           fi
    174 	fi
    175         if [ "$ok" = "true" ]; then
    176           list="$list $dma"
    177         fi
    178       done
    179     else
    180       if [ -r $PROCFS/dma ]; then
    181   	for dma in $*; do
    182 	    grep -q '^ *'$dma': ' $PROCFS/dma || list="$list $dma"
    183 	done
    184       fi
    185     fi
    186     if [ ! -z "$list" ]; then
    187       echo $list
    188     fi
    189 }
    190 
    191 check_irq_avail () {
    192     list=""
    193     if [ -d $SYSFS/bus/pnp/devices ]; then
    194       for irq in $*; do
    195         ok="true"
    196         for i in $SYSFS/bus/pnp/devices/??:* ; do
    197           if grep -q "state = active" $i/resources ; then
    198             if grep -q '^irq '$irq'$' $i/resources; then
    199               ok="false"
    200             fi
    201           fi
    202         done
    203         if [ -r $PROCFS/interrupts ]; then
    204 	  if grep -q '^ *'$irq': ' $PROCFS/interrupts ; then
    205             ok="false"
    206           fi
    207 	fi
    208         if [ "$ok" = "true" ]; then
    209           list="$list $irq"
    210         fi
    211       done
    212     else
    213       if [ -r $PROCFS/interrupts ]; then
    214 	for irq in $*; do
    215 	    grep -q '^ *'$irq': ' $PROCFS/interrupts || list="$list $irq"
    216 	done
    217       fi
    218     fi
    219     if [ ! -z "$list" ]; then
    220       echo $list
    221     fi
    222 }
    223 
    224 #
    225 #
    226 #
    227 
    228 if [ "$resources" = "true" ]; then
    229   if [ -d $SYSFS/bus/pnp/devices ]; then
    230     for i in $SYSFS/bus/pnp/devices/??:* ; do
    231       if [ "$resources" = "true" ]; then
    232         echo ">>>>> PnP file: $i/resources"
    233         cat $i/resources
    234       fi
    235     done
    236   fi
    237   if [ -r $PROCFS/dma ]; then
    238     echo ">>>>> Allocated dma channels:"
    239     cat $PROCFS/dma
    240   fi
    241   if [ -r $PROCFS/interrupts ]; then
    242     echo ">>>>> Allocated interrupt channels:"
    243     cat $PROCFS/interrupts
    244   fi
    245   echo -n "Valid DMA channels: "
    246   check_dma_avail 0 1 2 3 4 5 6 7
    247   echo -n "Valid IRQ channels: "
    248   check_irq_avail 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
    249   exit 0
    250 fi
    251 
    252 # Check for root privileges
    253 if [ `id -u` -ne 0 ]; then
    254   xecho "You must be root to use this script."
    255   exit 1
    256 fi
    257 
    258 #
    259 # check the snd_ prefix for ALSA module options
    260 # snd_ prefix is obsoleted since 0.9.0rc4.
    261 #
    262 if /sbin/modinfo -p snd | grep -q snd_ ; then
    263   mpfx="snd_"
    264 else
    265   mpfx=""
    266 fi
    267 
    268 alsa_device_opts=""
    269 if /sbin/modinfo -p snd | grep -q uid ; then
    270   if [ x"$alsa_uid" != x0 ]; then
    271     alsa_device_opts="$alsa_device_opts ${mpfx}device_uid=$alsa_uid"
    272   fi
    273   if [ x"$alsa_gid" != x0 ]; then
    274     alsa_device_opts="$alsa_device_opts ${mpfx}device_gid=$alsa_gid"
    275   fi
    276 fi
    277 if /sbin/modinfo -p snd | grep -q device_mode ; then
    278   if [ x"$alsa_mode" != x0 ]; then
    279     alsa_device_opts="$alsa_device_opts ${mpfx}device_mode=$alsa_mode"
    280   fi
    281 fi
    282 
    283 case `uname -r` in
    284 2.6.*)
    285   kernel="new"
    286   ;;
    287 *)
    288   kernel="old"
    289   ;;
    290 esac
    291 
    292 # cfgfile = base config file to remove/update the sound setting
    293 # cfgout = new config file to write the sound setting (if different from $cfgfile)
    294 if [ -n "$cfgfile" ]; then
    295   if [ ! -r "$cfgfile" ]; then
    296     xecho "ERROR: The config file doesn't exist: "
    297     echo $cfgfile
    298     exit 1
    299   fi
    300 else
    301 if [ "$distribution" = "gentoo" ]; then
    302   cfgfile="/etc/modules.d/alsa"
    303 elif [ "$kernel" = "new" ]; then
    304   if [ -d /etc/modprobe.d ]; then
    305     cfgout="/etc/modprobe.d/sound"
    306   fi
    307   cfgfile="/etc/modprobe.conf"
    308 elif [ "$distribution" = "debian" ]; then
    309   cfgfile="/etc/modutils/sound"
    310 elif [ -e /etc/modules.conf ]; then
    311   cfgfile="/etc/modules.conf"
    312 elif [ -e /etc/conf.modules ]; then
    313   cfgfile="/etc/conf.modules"
    314 else
    315   cfgfile="/etc/modules.conf"
    316   touch /etc/modules.conf
    317 fi
    318 fi
    319 
    320 # Check for dialog, whiptail, gdialog, awk, ... ?
    321 if type -p dialog > /dev/null; then
    322     DIALOG=dialog
    323 else
    324   if type -p whiptail > /dev/null; then
    325     whiptail_wrapper() {
    326       X1="$1"
    327       X2="$2"
    328       if [ $1 = --yesno ]; then
    329         X3=`expr $3 + 2`
    330       else
    331         X3=$3
    332       fi
    333       shift 3
    334       whiptail "$X1" "$X2" $X3 "$@"
    335     }
    336     DIALOG=whiptail_wrapper
    337   else
    338     xecho "Error, dialog or whiptail not found."
    339     exit 1
    340   fi
    341 fi
    342 if type -p awk > /dev/null; then :
    343 else
    344   xecho "Error, awk not found. Can't continue."
    345   exit 1
    346 fi
    347 
    348 #
    349 # remove entries by yast2 sound configurator
    350 #
    351 remove_y2_block() {
    352     awk '
    353     /^alias sound-slot-[0-9]/ { next }
    354     /^alias char-major-116 / { next }
    355     /^alias char-major-14 / { next }
    356     /^alias snd-card-[0-9] / { next }
    357     /^options snd / { next }
    358     /^options snd-/ { next }
    359     /^options off / { next }
    360     /^alias sound-service-[0-9]/ { next }
    361     /^# YaST2: sound / { next }
    362    { print }'
    363 }
    364 
    365 #
    366 # remove entries by sndconfig sound configurator
    367 #
    368 # found strings to search for in WriteConfModules, 
    369 # from sndconfig 0.68-4 (rawhide version)
    370 
    371 remove_sndconfig_block() {
    372     awk '
    373     /^alias sound-slot-0/ { modulename = $3 ; next }
    374     /^alias sound-slot-[0-9]/ { next }
    375     /^post-install sound-slot-[0-9] / { next }
    376     /^pre-remove sound-slot-[0-9] / { next }
    377     /^options sound / { next }
    378     /^alias synth0 opl3/ { next }
    379     /^options opl3 / { next }
    380     /^alias midi / { mididev = $3 ; next }
    381     /^options / { if ($2 == mididev) next }
    382     /^pre-install / { if ($2 == mididev) next }
    383     /^alias synth0 / { synth = $3 ; next }
    384     /^post-install / { if ($2 == synth) next }
    385     /^options sb / { next }
    386     /^post-install .+ \/bin\/modprobe "aci"/ { if ($2 == modulename) next }
    387     /^options adlib_card / { next }
    388     /^options .+ isapnp=1/ { if ($2 == modulename) next }
    389     /^options i810_audio / { next }
    390     /^options / {if ($2 == modulename) next }
    391    { print }'
    392 }
    393 
    394 #
    395 # remove the previous configuration by alsaconf
    396 #
    397 remove_ac_block() {
    398     awk '/^'"$ACB"'$/,/^'"$ACE"'$/ { next } { print }'
    399 }
    400 
    401 #
    402 # set default mixer volumes
    403 #
    404 set_mixers() {
    405     amixer -s -q <<EOF
    406 set Master 75% unmute
    407 set Master -12dB
    408 set 'Master Mono' 75% unmute
    409 set 'Master Mono' -12dB
    410 set Front 75% unmute
    411 set Front -12dB
    412 set PCM 90% unmute
    413 set PCM 0dB
    414 mixer Synth 90% unmute
    415 mixer Synth 0dB
    416 mixer CD 90% unmute
    417 mixer CD 0dB
    418 # mute mic
    419 set Mic 0% mute
    420 # ESS 1969 chipset has 2 PCM channels
    421 set PCM,1 90% unmute
    422 set PCM,1 0dB
    423 # Trident/YMFPCI/emu10k1
    424 set Wave 100% unmute
    425 set Music 100% unmute
    426 set AC97 100% unmute
    427 # CS4237B chipset:
    428 set 'Master Digital' 75% unmute
    429 # Envy24 chips with analog outs
    430 set DAC 90% unmute
    431 set DAC -12dB
    432 set DAC,0 90% unmute
    433 set DAC,0 -12dB
    434 set DAC,1 90% unmute
    435 set DAC,1 -12dB
    436 # some notebooks use headphone instead of master
    437 set Headphone 75% unmute
    438 set Headphone -12dB
    439 set Playback 100% unmute
    440 # turn off digital switches
    441 set "SB Live Analog/Digital Output Jack" off
    442 set "Audigy Analog/Digital Output Jack" off
    443 EOF
    444 }
    445 
    446 
    447 # INTRO
    448 intro() {
    449   local msg=$(xmsg "
    450                    ALSA  CONFIGURATOR
    451                    version %s
    452 
    453             This script is a configurator for
    454     Advanced Linux Sound Architecture (ALSA) driver.
    455 
    456 
    457   If ALSA is already running, you should close all sound
    458   apps now and stop the sound driver.
    459   alsaconf will try to do this, but it's not 100%% sure." $version)
    460   $DIALOG --msgbox "$msg" 20 63 || acex 0
    461 }
    462 
    463 # FAREWELL
    464 farewell() {
    465   local msg=$(gettext "
    466 
    467      OK, sound driver is configured.
    468 
    469                   ALSA  CONFIGURATOR
    470 
    471           will prepare the card for playing now.
    472 
    473      Now I'll run alsasound init script, then I'll use
    474      amixer to raise the default volumes.
    475      You can change the volume later via a mixer
    476      program such as alsamixer or gamix.
    477   
    478   ")
    479   $DIALOG --msgbox "$msg" 17 60 || acex 0
    480 }
    481 
    482 # Exit function
    483 acex() {
    484   cleanup
    485   clear
    486   exit $1
    487 }
    488 
    489 #
    490 # search for alsasound init script
    491 #
    492 
    493 if [ "$distribution" = "debian" ]; then
    494     rcalsasound=/etc/init.d/alsa
    495 elif [ -x /etc/rc.d/rc.alsa ]; then
    496     rcalsasound=/etc/rc.d/rc.alsa
    497 elif [ -x /etc/init.d/alsasound ]; then
    498     rcalsasound=/etc/init.d/alsasound
    499 elif [ -x /usr/sbin/rcalsasound ]; then
    500     rcalsasound=/usr/sbin/rcalsasound
    501 elif [ -x /sbin/rcalsasound ]; then
    502     rcalsasound=/sbin/rcalsasound
    503 elif [ -x /etc/rc.d/init.d/alsasound ]; then
    504     rcalsasound=/etc/rc.d/init.d/alsasound
    505 elif [ -x /etc/init.d/alsa ]; then
    506     rcalsasound=/etc/init.d/alsa
    507 else
    508     rcalsasound=rcalsasound
    509 fi
    510 
    511     
    512 # MAIN
    513 if [ -d $PROCFS/asound ]; then
    514   $rcalsasound stop >/dev/null 2>&1
    515   $rcalsasound unload >/dev/null 2>&1
    516   /sbin/rmmod dmasound dmasound_awacs 2>/dev/null
    517 fi
    518 
    519 
    520 cleanup () {
    521     killall -9 aplay arecord >/dev/null 2>&1
    522     /sbin/modprobe -r isapnp >/dev/null 2>&1
    523     /sbin/modprobe -r isa-pnp >/dev/null 2>&1
    524     rm -f "$TMP" "$addcfg" "$FOUND" "$DUMP"
    525 }
    526 trap cleanup 0 
    527 
    528 TMP=`mktemp -q /tmp/alsaconf.XXXXXX`
    529 if [ $? -ne 0 ]; then
    530 	xecho "Can't create temp file, exiting..."
    531         exit 1
    532 fi
    533 addcfg=`mktemp -q /tmp/alsaconf.XXXXXX`
    534 if [ $? -ne 0 ]; then
    535 	xecho "Can't create temp file, exiting..."
    536         exit 1
    537 fi
    538 FOUND=`mktemp -q /tmp/alsaconf.XXXXXX`
    539 if [ $? -ne 0 ]; then
    540 	xecho "Can't create temp file, exiting..."
    541         exit 1
    542 fi
    543 DUMP=`mktemp -q /tmp/alsaconf.XXXXXX`
    544 if [ $? -ne 0 ]; then
    545 	xecho "Can't create temp file, exiting..."
    546         exit 1
    547 fi
    548 
    549 # convert ISA PnP id number to string 'ABC'
    550 convert_isapnp_id () {
    551     if [ -z "$1" ]; then
    552 	echo "XXXX"
    553 	return
    554     fi
    555     let a='('$1'>>2) & 0x3f'
    556     let b='(('$1' & 0x03) << 3) | (('$1' >> 13) & 0x07)'
    557     let c='('$1'>> 8) & 0x1f'
    558     strs='@ABCDEFGHIJKLMNOPQRSTUVWXYZ'
    559     echo ${strs:$a:1}${strs:$b:1}${strs:$c:1}
    560 }
    561 
    562 # swap high & low bytes
    563 swap_number () {
    564     if [ -z "$1" ]; then
    565 	echo "0000"
    566 	return
    567     fi
    568     let v='(('$1'>>8)&0xff)|(('$1'&0xff)<<8)'
    569     printf "%04x" $v
    570 }
    571 
    572 # build card database
    573 # build_card_db filename
    574 build_card_db () {
    575     MODDIR=/lib/modules/`uname -r`
    576     last_driver=""
    577     echo -n > $1
    578 
    579     # list pci cards
    580     while read driver vendor device dummy; do
    581 	if expr $driver : 'snd-.*' >/dev/null ; then
    582 	    if [ "$last_driver" != "$driver" ]; then
    583 		echo $driver.o
    584 		last_driver=$driver
    585 	    fi
    586 	    id1=`printf '0x%04x' $vendor`
    587 	    id2=`printf '0x%04x' $device`
    588 	    echo "PCI: $id1=$id2"
    589 	fi
    590     done < $MODDIR/modules.pcimap >> $1
    591 
    592     # list isapnp cards
    593     while read driver cardvendor carddevice data vendor func; do
    594 	if expr $driver : 'snd-.*' >/dev/null ; then
    595 	    if [ "$last_driver" != "$driver" ]; then
    596 		echo $driver.o
    597 		last_driver=$driver
    598 	    fi
    599 	    id1=`convert_isapnp_id $cardvendor`
    600 	    dev1=`swap_number $carddevice`
    601 	    id2=`convert_isapnp_id $vendor`
    602 	    dev2=`swap_number $func`
    603 	    echo "ISAPNP: $id1$dev1=$id2$dev2"
    604 	fi
    605     done < $MODDIR/modules.isapnpmap >> $1
    606 }
    607 
    608 #
    609 # probe cards
    610 #
    611 probe_cards () {
    612     found="0"
    613     test -r $PROCFS/isapnp || /sbin/modprobe isapnp >/dev/null 2>&1
    614     test -r $PROCFS/isapnp || /sbin/modprobe isa-pnp >/dev/null 2>&1
    615     if [ -r $PROCFS/isapnp ]; then
    616 	cat $PROCFS/isapnp >"$DUMP"
    617 	found="1"
    618     elif [ -d $SYSFS/bus/pnp/devices ]; then
    619 	# use 2.6 kernel's sysfs output
    620 	# fake the isapnp dump
    621 	index=0
    622 	bindex=0
    623 	for d1 in $SYSFS/devices/pnp* ; do
    624 	  for d2 in $d1/*:* ; do
    625 	    if [ -r $d2/card_id ]; then
    626 	      id=`cat $d2/card_id`
    627 	      name=`cat $d2/name`
    628 	      echo "Card $index '$id:$name' " >> "$DUMP"
    629 	      index=$[$index+1]
    630 	      found="1"
    631 	    else if [ -r $d2/id ]; then
    632 	      # FIXME: multiple id might be present (separated with new-line)
    633 	      id=`head -n 1 $d2/id`
    634 	      echo "BIOS $bindex '$id' " >> "$DUMP"
    635 	      bindex=$[$bindex+1]
    636 	      found="1"
    637 	    fi
    638 	    fi
    639 	  done
    640 	done
    641     fi
    642     if [ "$found" = "0" ]; then
    643       echo -n >"$DUMP"
    644     fi 
    645     CARDID_DB=/var/tmp/alsaconf.cards
    646     if [ ! -r $CARDID_DB ]; then
    647         use_modinfo_db=1
    648     fi
    649     if [ $use_modinfo_db != 1 ]; then
    650 	if [ $CARDID_DB -ot /lib/modules/`uname -r`/modules.dep ]; then
    651 	    use_modinfo_db=1
    652 	fi
    653     fi
    654     if [ $use_modinfo_db = 1 ]; then
    655 	xecho "Building card database.."
    656 	build_card_db $CARDID_DB
    657     fi
    658     if [ ! -r $CARDID_DB ]; then
    659 	xecho "No card database is found.."
    660 	exit 1
    661     fi
    662     ncards=`grep '^snd-.*\.o$' $CARDID_DB | wc -w`
    663 
    664     msg=$(gettext "Searching sound cards")
    665     awk '
    666 BEGIN {
    667 	format="%-40s %s\n";
    668 	ncards='"$ncards"';
    669 	idx=0;
    670 }
    671 /^snd-.*\.o$/{
    672 	sub(/.o$/, "");
    673 	driver=$0;
    674 	perc=(idx * 100) / (ncards + 1);
    675 	print int(perc);
    676 	idx++;
    677 }
    678 /^[<literal space><literal tab>]*PCI: /{
    679 	gsub(/0x/, "");
    680 	gsub(/=/, ":");
    681 	x = sprintf ("'$lspci' -n 2>/dev/null| grep '"' 04..: '"' | grep %s", $2);
    682 	if (system (x) == 0)
    683 		printf "%s %s\n", $2, driver >>"'"$FOUND"'"
    684 }
    685 /^[<literal space><literal tab>]*ISAPNP: /{
    686 	id2 = substr($0, index($0, "=")+1);
    687 	gsub(/=.*/, "");
    688 	x = sprintf ("grep '\''^Card [0-9] .%s:'\'' '"$DUMP"'", $2);
    689 	if (system (x) == 0)
    690 		printf "%s %s\n", $2, driver >>"'"$FOUND"'"
    691 	else if (index($2, "ffff") > 0) {
    692 		x = sprintf ("grep '\''^BIOS [0-9]* .%s.'\'' '"$DUMP"'", id2);
    693 		if (system (x) == 0)
    694 			printf "%s %s\n", id2, driver >>"'"$FOUND"'"
    695 	}
    696 }' < $CARDID_DB |\
    697     $DIALOG --gauge "$msg" 6 40 0
    698 
    699     #
    700     # PowerMac
    701     #
    702     if grep -q MacRISC $PROCFS/cpuinfo; then
    703 	MODDIR=/lib/modules/`uname -r`
    704 	find $MODDIR -name 'snd-powermac*' -print | \
    705 	while read i; do
    706 	    i=${i##*/}
    707 	    i=${i%%.o}
    708 	    i=${i%%.ko}
    709 	    echo "PowerMac $i" >> $FOUND
    710 	done
    711     fi
    712 
    713     #
    714     # Sparc
    715     #
    716     if grep -q Sparc $PROCFS/cpuinfo; then
    717 	test -r $PROCFS/openprom/name || /bin/mount -t openpromfs none $PROCFS/openprom >/dev/null 2>&1
    718 	# Check for an "audio" device
    719 	audio=
    720 	compat=
    721 	if test -r $PROCFS/openprom; then
    722 	    audio=`find $PROCFS/openprom -follow -type d -name "audio*" -print`
    723 	fi
    724 	if test -n "$audio"; then
    725 	    compat=`cat $audio/compatible`
    726 	    compat=${compat#\'}
    727 	    compat=${compat%\'}
    728 	    compat=${compat#SUNW,}
    729 	fi
    730 	# Go through all cards we have
    731 	MODDIR=/lib/modules/`uname -r`
    732 	find $MODDIR -name 'snd-sun-*' -print | \
    733 	while read i; do
    734 	    i=${i##*/}
    735 	    i=${i%%.o}
    736 	    i=${i%%.ko}
    737 	    sdev=`echo ${i#snd-sun-} | tr "[a-z]" "[A-Z]"`
    738 
    739 	    if test "$sdev" = "$compat"; then
    740 		echo "$sdev $i" >> $FOUND
    741 	    elif test -r $PROCFS/openprom; then
    742 		find $PROCFS/openprom -follow -type d -name "SUNW,${sdev}*" \
    743 		    -exec echo "$sdev $i" \; 2>/dev/null >> $FOUND
    744 	    else
    745 		echo "$sdev $i" >> $FOUND
    746 	    fi
    747 	done
    748     fi
    749 }
    750 
    751 #
    752 # look for a descriptive device name from the given device id
    753 #
    754 find_device_name () {
    755     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
    756 	$lspci -d $1 2>/dev/null| sed -e 's/^.*:..\.. [^:]*: //g'
    757 	return
    758     elif expr "$1" : '[A-Z@][A-Z@][A-Z@][0-9a-f][0-9a-f][0-9a-f][0-9a-f]' >/dev/null; then
    759 	cardname=`grep '^Card [0-9]\+ .'$1':' $DUMP | head -n 1 | sed -e 's/^Card [0-9]\+ '\''.*:\(.*\)'\'' .*$/\1/'`
    760 	echo $cardname
    761     else
    762 	echo $1
    763     fi
    764 }
    765 
    766 # get hwcfg file type from the given driver name
    767 get_hwcfg_type () {
    768     while read dev driver; do
    769 	if [ "$driver" = "$1" ]; then
    770 	    case "$dev" in
    771 	    *:*)
    772 		# FIXME: need to look around /sys/bus/pci/* (or use vpid-* ?)
    773 		devid=`$lspci -d "$dev" | head -n 1 | sed -e 's/ .*$//'`
    774 		case "$devid" in
    775 		*:*:*.*) ;;
    776 		*) devid="0000:$devid" ;;
    777 		esac
    778 		echo bus-pci-$devid
    779 		;;
    780 	    *)
    781 		echo $driver
    782 		;;
    783 	    esac
    784 	    break
    785 	fi
    786     done
    787 }
    788 
    789 # clean up all hwcfg-* files containing ALSA modules
    790 # alsaconf sets up exclusively
    791 cleanup_hwcfg () {
    792     for i in /etc/sysconfig/hardware/hwcfg-*; do
    793 	grep -q "MODULE='snd-" $i && rm -f $i
    794     done
    795 }
    796 
    797 #
    798 # set up /etc/sysconfig/hardware/hwcfg-* stuff
    799 #
    800 setup_hwcfg () {
    801     card=$1
    802     cleanup_hwcfg
    803     cfg=`echo "$devs_olist" | get_hwcfg_type $card`
    804     echo "MODULE='$card'" > /etc/sysconfig/hardware/hwcfg-$cfg
    805     echo "STARTMODE='auto'" >> /etc/sysconfig/hardware/hwcfg-$cfg
    806 }
    807 
    808 
    809 #
    810 # configure and try test sound
    811 #
    812 ac_config_card () {
    813 
    814     CARD_DRIVER=snd-$1
    815     CARD_OPTS="${*:2}"
    816 
    817     if [ -n "$cfgout" ]; then
    818 	msg=$(xmsg "
    819 Configuring %s
    820 Do you want to modify %s (and %s if present)?" $CARD_DRIVER $cfgout $cfgfile)
    821         $DIALOG --yesno "$msg" 8 50 || acex 0
    822     else
    823 	msg=$(xmsg "
    824 Configuring %s
    825 Do you want to modify %s?" $CARD_DRIVER $cfgfile)
    826         $DIALOG --yesno "$msg" 8 50 || acex 0
    827     fi
    828     clear
    829 
    830     # Copy conf.modules and make changes.
    831     ACB="# --- BEGIN: Generated by ALSACONF, do not edit. ---"
    832     ACE="# --- END: Generated by ALSACONF, do not edit. ---"
    833 
    834     # Detect 2.2.X kernel
    835     KVER=`uname -r | tr ".-" "  "`
    836     KVER1=`echo $KVER | cut -d" " -f1`
    837     KVER2=`echo $KVER | cut -d" " -f2`
    838     if [ $KVER1 -ge 2 ] && [ $KVER2 -ge 2 ]; then
    839 	SOUND_CORE="soundcore"
    840     else
    841 	SOUND_CORE="snd"
    842     fi
    843 
    844     if [ -r $cfgfile ] ; then
    845         if [ "$distribution" = "redhat" -o "$distribution" = "fedora" ] ; then
    846             remove_ac_block < $cfgfile | remove_sndconfig_block | uniq > $TMP
    847         else
    848 	    remove_ac_block < $cfgfile | remove_y2_block | uniq > $TMP
    849         fi
    850     fi
    851 
    852     if [ -z "$have_alias" -a "$kernel" = "new" ]; then
    853 	if grep -q char-major-116 /lib/modules/`uname -r`/modules.alias; then
    854 	    have_alias="yes"
    855 	fi
    856     fi
    857     if [ -z "$have_alias" ]; then
    858 echo "alias char-major-116 snd
    859 alias char-major-14 $SOUND_CORE
    860 alias sound-service-0-0 snd-mixer-oss
    861 alias sound-service-0-1 snd-seq-oss
    862 alias sound-service-0-3 snd-pcm-oss
    863 alias sound-service-0-8 snd-seq-oss
    864 alias sound-service-0-12 snd-pcm-oss" >> $addcfg
    865     fi
    866     if [ -n "$alsa_device_opts" ]; then
    867 	echo "options snd $alsa_device_opts" >> $addcfg
    868     fi
    869 echo "alias snd-card-0 $CARD_DRIVER
    870 alias sound-slot-0 $CARD_DRIVER" >> $addcfg
    871     if [ -n "$CARD_OPTS" ]; then
    872 	echo "options $CARD_DRIVER $CARD_OPTS" >> $addcfg
    873     fi
    874 
    875     if [ -n "$cfgout" ]; then
    876 	[ ! -r "$cfgfile" ] || cmp -s "$TMP" "$cfgfile" || cat "$TMP" > "$cfgfile"
    877 	cmp -s "$addcfg" "$cfgout" || cat "$addcfg" > "$cfgout"
    878     else
    879 	echo "$ACB
    880 # --- ALSACONF version $version ---" >> $TMP
    881         cat "$addcfg" >> "$TMP"
    882 	echo "$ACE
    883 " >> $TMP
    884         cmp -s "$TMP" "$cfgfile" || cat "$TMP" > "$cfgfile"
    885     fi
    886 
    887     /sbin/depmod -a 2>/dev/null
    888 
    889     # remove yast2 entries (- only for suse distro)
    890     if [ -f /var/lib/YaST/unique.inf ]; then
    891 	awk '
    892 BEGIN { in_sound=0; }
    893 /^\[sound\]$/ { print; in_sound=1; next; }
    894 /^\[.+\]$/ { print; in_sound=0; next; }
    895 { if (in_sound == 0) { print; } }
    896 ' < /var/lib/YaST/unique.inf > $TMP
    897 	cp -f $TMP /var/lib/YaST/unique.inf
    898     fi
    899 
    900     # set up /etc/sysconfig/hardware/*
    901     if [ "$distribution" = "suse" ]; then
    902 	case "$suse_version" in
    903 	10.[012]*|10)
    904 	    setup_hwcfg $CARD_DRIVER
    905 	    ;;
    906 	esac
    907     fi
    908 
    909     farewell
    910     clear
    911     case "$distribution" in
    912     gentoo | debian)
    913 	xecho "Running update-modules..."
    914 	update-modules
    915 	;;
    916     esac
    917     if [ -x $rcalsasound ] ; then
    918       echo Loading driver...
    919       $rcalsasound restart
    920     fi
    921     echo Setting default volumes...
    922     if [ -x $bindir/set_default_volume ]; then
    923 	$bindir/set_default_volume -f
    924     else
    925 	set_mixers
    926     fi
    927     if [ -f $TESTSOUND ]; then
    928       msg=$(gettext "
    929        The mixer is set up now for for playing.
    930        Shall I try to play a sound sample now?
    931 
    932                            NOTE:
    933 If you have a big amplifier, lower your volumes or say no.
    934     Otherwise check that your speaker volume is open,
    935           and look if you can hear test sound.
    936 ")
    937       if $DIALOG --yesno "$msg" 13 65 
    938       then
    939           clear
    940 	  echo
    941 	  aplay -N $TESTSOUND
    942       fi
    943     fi
    944     if [ ! -r /etc/asound.state ]; then
    945 	xecho "Saving the mixer setup used for this in /etc/asound.state."
    946 	$sbindir/alsactl store
    947     fi
    948     clear
    949     xecho "
    950 ===============================================================================
    951 
    952  Now ALSA is ready to use.
    953  For adjustment of volumes, use your favorite mixer.
    954 
    955  Have a lot of fun!
    956 
    957 "
    958 }
    959 
    960 # check playback
    961 # return 0 - OK, 1 - NG, 2 - not working (irq/dma problem)
    962 ac_try_load () {
    963     test -n "$LOGFILE" && echo "$1 ${*:2}" >> "$LOGFILE"
    964     /sbin/modprobe snd-$1 ${*:2} >/dev/null 2>&1
    965     if $lsmod | grep -q -E '^(snd-|snd_)'$1' '; then
    966 	: ;
    967     else
    968 	/sbin/modprobe -r snd-$1 >/dev/null 2>&1
    969 	return 1
    970     fi
    971 
    972     # mute mixers
    973     amixer set Master 0% mute >/dev/null 2>&1
    974     amixer set PCM 0% mute >/dev/null 2>&1
    975     
    976     # output 0.5 sec
    977     head -c 4000 < /dev/zero | aplay -N -r8000 -fS16_LE -traw -c1 > /dev/null 2>&1 &
    978     # remember pid
    979     pp=$!
    980     # sleep for 2 seconds (to be sure -- 1 sec would be enough)
    981     sleep 2
    982     # kill the child process if still exists.
    983     kill -9 $pp > /dev/null 2>&1
    984     st=$?
    985     ac_cardname=`head -n 1 $PROCFS/asound/cards | sed -e 's/^[0-9].* - \(.*\)$/\1/'`
    986     /sbin/modprobe -r snd-$1 >/dev/null 2>&1
    987     if [ $st = 0 ]; then
    988 	# irq problem?
    989 	test -n "$LOGFILE" && echo "no playback return" >> "$LOGFILE"
    990 	return 2
    991     else
    992 	# seems ok!
    993 	test -n "$LOGFILE" && echo "playback OK" >> "$LOGFILE"
    994 	return 0
    995     fi
    996 }
    997 
    998 # check capture
    999 # return 0 - OK, 1 - NG, 2 - not working (irq/dma problem)
   1000 # ac_try_capture card duplex opts
   1001 ac_try_capture () {
   1002     test -n "$LOGFILE" && echo "$1 ${*:2}" >> "$LOGFILE"
   1003     /sbin/modprobe snd-$1 ${*:3} >/dev/null 2>&1
   1004     if $lsmod | grep -q -E '^(snd-|snd_)'$1' '; then
   1005 	: ;
   1006     else
   1007 	/sbin/modprobe -r snd-$1 >/dev/null 2>&1
   1008 	return 1
   1009     fi
   1010 
   1011     # mute mixers
   1012     amixer set Master 0% mute >/dev/null 2>&1
   1013     amixer set PCM 0% mute >/dev/null 2>&1
   1014 
   1015     play_pid=0
   1016     if [ $2 = yes ]; then
   1017 	# try duplex - start dummy playing
   1018 	aplay -N -r8000 -fS16_LE -traw -c1 < /dev/zero > /dev/null 2>&1 &
   1019 	play_pid=$!
   1020     fi
   1021     # record 1sec
   1022     arecord -N -d1 > /dev/null 2>&1 &
   1023     # remember pid
   1024     pp=$!
   1025     # sleep for 2 seconds
   1026     sleep 2
   1027     # kill the child process if still exists.
   1028     kill -9 $pp > /dev/null 2>&1
   1029     st=$?
   1030     # kill playback process if any
   1031     test $play_pid != 0 && kill -9 $play_pid
   1032     /sbin/modprobe -r snd-$1 >/dev/null 2>&1
   1033     if [ $st = 0 ]; then
   1034 	test -n "$LOGFILE" && echo "capture no return" >> "$LOGFILE"
   1035 	return 2
   1036     else
   1037 	test -n "$LOGFILE" && echo "capture OK" >> "$LOGFILE"
   1038 	return 0
   1039     fi
   1040 }
   1041 
   1042 get_dma_pair () {
   1043     case $1 in
   1044     0)
   1045 	echo 1 3 5;;
   1046     1)
   1047 	echo 0 3 5;;
   1048     3)
   1049 	echo 1 0 5;;
   1050     5)
   1051 	echo 3 1 0;;
   1052     esac
   1053 }
   1054 
   1055 #
   1056 # check playback on specified irqs
   1057 #
   1058 # ac_try_irq card opts irqs...
   1059 # return 0 - OK, 1 - NG, 2 - not working (dma problem?)
   1060 #
   1061 ac_try_irq () {
   1062     card=$1
   1063     opts="$2 ${mpfx}irq=$3"
   1064     ac_try_load $card $opts >/dev/null 2>&1
   1065     result=$?
   1066     case $result in
   1067     0)
   1068 	ac_opts="$opts"
   1069 	return 0
   1070 	;;
   1071     2)
   1072 	for irq in ${*:4}; do
   1073 	    opts="$2 ${mpfx}irq=$irq"
   1074 	    ac_try_load $card $opts >/dev/null 2>&1
   1075 	    if [ $? = 0 ]; then
   1076 		ac_opts="$opts"
   1077 		return 0
   1078 	    fi
   1079 	done
   1080 	return 2
   1081 	;;
   1082     esac
   1083     return 1
   1084 }
   1085 
   1086 #
   1087 # check playback/capture on dma1 & dma2 & specified irqs
   1088 #
   1089 # ac_try_dmas card opts irqs...
   1090 # return 0 - OK, 1 - NG
   1091 #
   1092 ac_try_dmas () {
   1093     dma_list=`check_dma_avail 1 0 3 5`
   1094     for irq in ${*:3}; do
   1095 	for dma1 in $dma_list; do
   1096 	    for dma2 in `get_dma_pair $dma1`; do
   1097 		opts="$2 ${mpfx}dma1=$dma1 ${mpfx}dma2=$dma2 ${mpfx}irq=$irq"
   1098 		ac_try_load $1 $opts >/dev/null 2>&1
   1099 		result=$?
   1100 		if [ $result = 1 ]; then
   1101 		    if [ $try_all_combination = 1 ]; then
   1102 			continue
   1103 		    else
   1104 			return 1
   1105 		    fi
   1106 		elif [ $result = 0 ]; then
   1107 		    test -n "$LOGFILE" && echo "Now checking capture..." >> "$LOGFILE"
   1108 		    ac_opts="$opts"
   1109 		    ac_try_capture $1 yes $opts >/dev/null 2>&1 && return 0
   1110 		    for d in yes no; do
   1111 			for dma2 in $dma_list; do
   1112 			    if [ $dma1 != $dma2 ]; then
   1113 				opts="$2 ${mpfx}dma1=$dma1 ${mpfx}dma2=$dma2 ${mpfx}irq=$irq"
   1114 				ac_opts="$opts"
   1115 				ac_try_capture $1 $d $opts >/dev/null 2>&1 && return 0
   1116 			    fi
   1117 			done
   1118 		    done
   1119 		    return 0
   1120 		fi
   1121 	    done
   1122 	done
   1123     done
   1124     return 1
   1125 }
   1126 
   1127 # check if the option $2 exists in card $1: set value $3
   1128 ac_check_option () {
   1129     if /sbin/modinfo -p snd-$1 | grep -q $2; then
   1130       echo "$2=$3"
   1131     fi
   1132 }
   1133 
   1134 ac_try_card_sb8 () {
   1135     card=sb8
   1136     irq_list=`check_irq_avail 5 3 9 10 7`
   1137     for dma8 in `check_dma_avail 1 3`; do
   1138 	opts="${mpfx}dma8=$dma8"
   1139 	ac_try_irq $card "$opts" $irq_list && return 0
   1140     done
   1141     return 1
   1142 }
   1143 
   1144 ac_try_card_sb16 () {
   1145     card=sb16
   1146     isapnp=`ac_check_option $card ${mpfx}isapnp 0`
   1147     opts="$isapnp"
   1148     irq_list=`check_irq_avail 5 9 10 7 3`
   1149     dma_list=`check_dma_avail 0 1 3`
   1150     dma16_list=`check_dma_avail 5 6 7`
   1151     # at first try auto-probing by driver itself
   1152     ac_try_load $card $opts >/dev/null 2>&1
   1153     result=$?
   1154     case $result in
   1155     0)
   1156 	ac_opts="$opts"
   1157 	ac_try_capture $card yes $opts >/dev/null 2>&1 && return 0
   1158 	for d in yes no; do
   1159 	    for dma8 in $dma_list; do
   1160 		for irq in $irq_list; do
   1161 		    opts="${mpfx}dma8=$dma8 ${mpfx}irq=$irq $isapnp"
   1162 		    ac_try_capture $card $d $opts >/dev/null 2>&1 && return 0
   1163 		done
   1164 	    done
   1165 	done
   1166 	return 0
   1167 	;;
   1168     2)
   1169 	for dma16 in $dma16_list; do
   1170 	    opts="${mpfx}dma16=$dma16 $isapnp"
   1171 	    if ac_try_irq $card "$opts" $irq_list ; then
   1172 		ac_try_capture $card yes $ac_opts >/dev/null 2>&1 && return 0
   1173 		ac_opts_saved="$ac_opts"
   1174 		for d in yes no; do
   1175 		    for dma8 in $dma_list; do
   1176 			ac_opts="$ac_opts_saved ${mpfx}dma8=$dma8"
   1177 			ac_try_capture $card $d $ac_opts >/dev/null 2>&1 && return 0
   1178 		    done
   1179 		done
   1180 		# return anyway here..
   1181 		return 0
   1182 	    fi
   1183 	done
   1184 	;;
   1185     esac
   1186     return 1
   1187 }
   1188 
   1189 ac_try_card_es1688 () {
   1190     card=es1688
   1191     opts=""
   1192     irq_list=`check_irq_avail 5 9 10 7`
   1193     for dma8 in `check_dma_avail 1 3 0`; do
   1194 	opts="${mpfx}dma8=$dma8 ${mpfx}mpu_irq=-1"
   1195 	ac_try_irq $card "$opts" $irq_list && return 0
   1196     done
   1197     return 1
   1198 }
   1199 
   1200 ac_try_card_es18xx () {
   1201     card=es18xx
   1202     opts=`ac_check_option $card ${mpfx}isapnp 0`
   1203     ac_try_dmas $card "$opts" `check_irq_avail 5 9 10 7` && return 0
   1204     return 1
   1205 }
   1206 
   1207 ac_try_card_cs4236 () {
   1208     card=cs4236
   1209     irq_list=`check_irq_avail 5 7 9 11 12 15`
   1210     isapnp=`ac_check_option $card ${mpfx}isapnp 0`
   1211     for cport in 0x538 0x210 0xf00; do
   1212 	for port in 0x530 0x534; do
   1213 	    opts="${mpfx}port=$port ${mpfx}cport=$cport $isapnp"
   1214 	    ac_try_dmas $card "$opts" $irq_list && return 0
   1215 	done
   1216     done
   1217     return 1
   1218 }
   1219 
   1220 ac_try_card_cs4232 () {
   1221     card=cs4232
   1222     irq_list=`check_irq_avail 5 7 9 11 12 15`
   1223     isapnp=`ac_check_option $card ${mpfx}isapnp 0`
   1224     for cport in 0x538 0x210 0xf00; do
   1225 	for port in 0x530 0x534; do
   1226 	    opts="${mpfx}port=$port ${mpfx}cport=$cport $isapnp"
   1227 	    ac_try_dmas $card "$opts" $irq_list && return 0
   1228 	done
   1229     done
   1230     return 1
   1231 }
   1232 
   1233 ac_try_card_cs4231 () {
   1234     card=cs4231
   1235     irq_list=`check_irq_avail 5 7 9 11 12 15`
   1236     for port in 0x530 0x534; do
   1237 	opts="${mpfx}port=$port"
   1238 	ac_try_dmas $card "$opts" $irq_list && return 0
   1239     done
   1240     return 1
   1241 }
   1242 
   1243 ac_try_card_opl3sa2 () {
   1244     card=opl3sa2
   1245     irq_list=`check_irq_avail 5 9 3 1 11 12 15 0`
   1246     isapnp=`ac_check_option $card ${mpfx}isapnp 0`
   1247     for port in 0x370 0x538 0xf86 0x100; do
   1248 	for wss_port in 0x530 0xe80 0xf40 0x604; do
   1249 	    opts="${mpfx}fm_port=-1 ${mpfx}midi_port=-1 ${mpfx}port=$port ${mpfx}wss_port=$wss_port $isapnp"
   1250 	    ac_try_dmas $card "$opts" $irq_list && return 0
   1251 	done
   1252     done
   1253     return 1
   1254 }
   1255 
   1256 ac_config_legacy () {
   1257    title=$(gettext "WARNING")
   1258    msg=$(gettext "
   1259    Probing legacy ISA cards might make
   1260    your system unstable.
   1261 
   1262         Do you want to proceed?
   1263 
   1264 ")
   1265     $DIALOG --title "$title" --yesno "$msg" 10 50 || acex 0
   1266 
   1267     if [ x"$1" = x ]; then
   1268 	probe_list="$LEGACY_CARDS"
   1269     else
   1270 	probe_list=$*
   1271     fi
   1272     menu_args=()
   1273 
   1274     for card in $probe_list; do
   1275 	cardname=`/sbin/modinfo -d snd-$card | sed -e 's/^\"\(.*\)\"$/\1/g'`
   1276 	if [ x"$cardname" != x ]; then
   1277 	    menu_args=("${menu_args[@]}" "$card" "$cardname" "on")
   1278 	fi
   1279     done
   1280     if [ x$menu_args = x ]; then
   1281 	msg=$(gettext "No legacy drivers are available
   1282    for your machine")
   1283 	$DIALOG --msgbox "$msg" 5 50
   1284 	return 1
   1285     fi
   1286     title=$(gettext "Driver Selection")
   1287     msg=$(gettext "           Probing legacy ISA cards
   1288 
   1289         Please select the drivers to probe:")
   1290     $DIALOG --title "$title" --checklist "$msg" \
   1291 	17 64 8 "${menu_args[@]}" 2> $FOUND || acex 0
   1292 
   1293     if [ $try_all_combination != 1 ]; then
   1294 	msg=$(gettext "
   1295  Shall I try all possible DMA and IRQ combinations?
   1296  With this option, some unconventional configuration
   1297  might be found, but it will take much longer time.")
   1298 	if $DIALOG --yesno "$msg" 10 60
   1299 	    then
   1300 	    try_all_combination=1
   1301 	fi
   1302     fi
   1303 
   1304     xecho "Probing legacy cards..   This may take a few minutes.."
   1305     echo -n $(gettext "Probing: ")
   1306     cards=`cat $FOUND | tr -d \"`
   1307     for card in $cards; do
   1308 	echo -n " $card"
   1309 	ac_opts=""
   1310 	if eval ac_try_card_$card ; then
   1311 	    xecho " : FOUND!!"
   1312 	    ac_config_card $card $ac_opts
   1313 	    return 0
   1314 	fi
   1315     done
   1316     echo
   1317     title=$(gettext "Result")
   1318     msg=$(gettext "No legacy cards found")
   1319     $DIALOG --title "$title" --msgbox "$msg" 5 50
   1320     return 1
   1321 }
   1322 
   1323 #
   1324 # main part continued..
   1325 #
   1326 
   1327 if test -n "$LOGFILE" ; then
   1328     touch "$LOGFILE"
   1329     echo -n "Starting alsaconf: " >> "$LOGFILE"
   1330     date >> "$LOGFILE"
   1331 fi
   1332 
   1333 if [ x"$legacy_probe_card" != x ]; then
   1334     ac_opts=""
   1335     if eval ac_try_card_$legacy_probe_card >/dev/null 2>&1; then
   1336 	echo "$ac_opts"
   1337 	echo "$ac_cardname"
   1338 	exit 0
   1339     else
   1340 	echo "FAILED"
   1341 	exit 1
   1342     fi
   1343 fi
   1344 
   1345 intro
   1346 
   1347 if [ $do_legacy_only = 1 ]; then
   1348     ac_config_legacy
   1349     exit 0
   1350 fi
   1351     
   1352 probe_cards
   1353 
   1354 devs_found=()
   1355 devs_olist=""
   1356 
   1357 if [ -s "$FOUND" ]; then
   1358     while read dev card ; do
   1359 	MODDIR=/lib/modules/`uname -r`
   1360 	find $MODDIR -type f | grep -q -E $card'\.(o|ko)' || continue
   1361 	cardname=`find_device_name $dev | cut -c 1-64`
   1362 	if [ -z "$cardname" ]; then
   1363 	    cardname="$card"
   1364 	fi
   1365 	card=${card##snd-}
   1366 	devs_found=("${devs_found[@]}" "$card" "$cardname")
   1367 	devs_devs=("${devs_devs[@]}" "$card" "$dev")
   1368     done <"$FOUND"
   1369     devs_olist=`cat $FOUND`
   1370 fi
   1371 if [ x$devs_found != x ]; then
   1372     #
   1373     # check for TP600E
   1374     #
   1375     if [ ${devs_found[0]} = cs46xx ]; then
   1376 	if $lspci -nv 2>/dev/null| grep -q "Subsystem: 1014:1010"; then
   1377 	    msg=$(gettext "
   1378  Looks like you having a Thinkpad 600E or 770 notebook.
   1379  On this notebook, CS4236 driver should be used
   1380  although CS46xx chip is detected.
   1381 
   1382  Shall I try to snd-cs4236 driver and probe
   1383  the legacy ISA configuration?")
   1384 	    if $DIALOG --yesno "$msg" 13 60
   1385 	    then
   1386 		try_all_combination=1
   1387 		ac_config_legacy cs4236
   1388 		exit 0
   1389 	    fi
   1390 	elif $lspci -nv 2>/dev/null| grep -q "Subsystem: 8086:8080"; then
   1391 	    msg=$(gettext "
   1392  Looks like you having a Dell Dimension machine.
   1393  On this machine, CS4232 driver should be used
   1394  although CS46xx chip is detected.
   1395 
   1396  Shall I try to snd-cs4232 driver and probe
   1397  the legacy ISA configuration?")
   1398 	    if $DIALOG --yesno "$msg" 13 60
   1399 	    then
   1400 		try_all_combination=1
   1401 		ac_config_legacy cs4232
   1402 		exit 0
   1403 	    fi
   1404         fi	
   1405     fi
   1406    
   1407     devs_found=("${devs_found[@]}" "legacy" "Probe legacy ISA (non-PnP) chips")
   1408     title=$(gettext "Soundcard Selection")
   1409     msg=$(gettext "
   1410          Following card(s) are found on your system.
   1411          Choose a soundcard to configure:
   1412 ")
   1413     $DIALOG --title "$title" --menu "$msg" 17 76 8 "${devs_found[@]}" --output-fd 3 3> $FOUND || acex 0
   1414     card=`head -n 1 $FOUND`
   1415     if [ "$card" = "legacy" ]; then
   1416 	ac_config_legacy
   1417     else
   1418 	ac_config_card "$card"
   1419     fi
   1420     exit 0
   1421 else
   1422     msg=$(gettext "
   1423         No supported PnP or PCI card found.
   1424 
   1425  Would you like to probe legacy ISA sound cards/chips?
   1426 
   1427 ")
   1428     if $DIALOG --yesno "$msg" 9 60 ; then
   1429 	ac_config_legacy
   1430 	exit 0
   1431     fi
   1432 fi
   1433 
   1434 rm -f "$FOUND" "$DUMP"
   1435 exit 0
   1436