ChangeSet 1.2217.4.2, 2005/03/25 20:57:47-08:00, [EMAIL PROTECTED]

        merge mainline with 2.6.11.6 and 2.6.11.5



 Makefile                     |   53 +++--
 drivers/net/amd8111e.c       |    7 
 drivers/net/tun.c            |    4 
 drivers/net/via-rhine.c      |    4 
 fs/binfmt_elf.c              |   48 +++--
 kernel/signal.c              |   37 +++-
 net/bluetooth/af_bluetooth.c |    2 
 net/ipv4/fib_hash.c          |   23 ++
 net/netrom/nr_in.c           |    2 
 net/xfrm/xfrm_state.c        |   30 +++
 sound/pci/ac97/ac97_codec.c  |  381 ++++++++++++++++++++++---------------------
 11 files changed, 357 insertions(+), 234 deletions(-)


diff -Nru a/Makefile b/Makefile
--- a/Makefile  2005-03-26 11:30:49 -08:00
+++ b/Makefile  2005-03-26 11:30:49 -08:00
@@ -1,7 +1,7 @@
 VERSION = 2
 PATCHLEVEL = 6
 SUBLEVEL = 11
-EXTRAVERSION = .6
+EXTRAVERSION =
 NAME=Woozy Numbat
 
 # *DOCUMENTATION*
@@ -18,7 +18,7 @@
 #
 # Most importantly: sub-Makefiles should only ever modify files in
 # their own directory. If in some directory we have a dependency on
-# a file in another dir (which doesn't happen often, but it's of
+# a file in another dir (which doesn't happen often, but it's often
 # unavoidable when linking the built-in.o targets which finally
 # turn into vmlinux), we will call a sub make in that other dir, and
 # after that we are sure that everything which is in that other dir
@@ -67,7 +67,7 @@
 
 
 # kbuild supports saving output files in a separate directory.
-# To locate output files in a separate directory two syntax'es are supported.
+# To locate output files in a separate directory two syntaxes are supported.
 # In both cases the working directory must be the root of the kernel src.
 # 1) O=
 # Use "make O=dir/to/store/output/files/"
@@ -78,7 +78,8 @@
 # export KBUILD_OUTPUT=dir/to/store/output/files/
 # make
 #
-# The O= assigment takes precedence over the KBUILD_OUTPUT environment 
variable.
+# The O= assignment takes precedence over the KBUILD_OUTPUT environment
+# variable.
 
 
 # KBUILD_SRC is set on invocation of make in OBJ directory
@@ -539,16 +540,14 @@
 # Default kernel image to build when no specific target is given.
 # KBUILD_IMAGE may be overruled on the commandline or
 # set in the environment
-# Also any assingments in arch/$(ARCH)/Makefiel take precedence over
+# Also any assignments in arch/$(ARCH)/Makefile take precedence over
 # this default value
 export KBUILD_IMAGE ?= vmlinux
 
 #
 # INSTALL_PATH specifies where to place the updated kernel and system map
-# images.  Uncomment if you want to place them anywhere other than root.
-#
-
-#export        INSTALL_PATH=/boot
+# images. Default is /boot, but you can set it to other values
+export INSTALL_PATH ?= /boot
 
 #
 # INSTALL_MOD_PATH specifies a prefix to MODLIB for module directory
@@ -898,7 +897,7 @@
 endif
 .PHONY: _modinst_post
 _modinst_post: _modinst_
-       if [ -r System.map ]; then $(DEPMOD) -ae -F System.map $(depmod_opts) 
$(KERNELRELEASE); fi
+       if [ -r System.map -a -x $(DEPMOD) ]; then $(DEPMOD) -ae -F System.map 
$(depmod_opts) $(KERNELRELEASE); fi
 
 else # CONFIG_MODULES
 
@@ -1096,9 +1095,17 @@
 crmodverdir:
        $(Q)mkdir -p $(MODVERDIR)
 
+.PHONY: $(objtree)/Module.symvers
+$(objtree)/Module.symvers:
+       @test -e $(objtree)/Module.symvers || ( \
+       echo; \
+       echo "  WARNING: Symbol version dump $(objtree)/Module.symvers"; \
+       echo "           is missing; modules will have no dependencies and 
modversions."; \
+       echo )
+
 module-dirs := $(addprefix _module_,$(KBUILD_EXTMOD))
 .PHONY: $(module-dirs) modules
-$(module-dirs): crmodverdir
+$(module-dirs): crmodverdir $(objtree)/Module.symvers
        $(Q)$(MAKE) $(build)=$(patsubst _module_%,%,$@)
 
 modules: $(module-dirs)
@@ -1136,20 +1143,30 @@
 # Generate tags for editors
 # ---------------------------------------------------------------------------
 
+#We want __srctree to totally vanish out when KBUILD_OUTPUT is not set
+#(which is the most common case IMHO) to avoid unneeded clutter in the big 
tags file.
+#Adding $(srctree) adds about 20M on i386 to the size of the output file!
+
+ifeq ($(KBUILD_OUTPUT),)
+__srctree =
+else
+__srctree = $(srctree)/
+endif
+
 define all-sources
-       ( find $(srctree) $(RCS_FIND_IGNORE) \
+       ( find $(__srctree) $(RCS_FIND_IGNORE) \
               \( -name include -o -name arch \) -prune -o \
               -name '*.[chS]' -print; \
-         find $(srctree)/arch/$(ARCH) $(RCS_FIND_IGNORE) \
+         find $(__srctree)arch/$(ARCH) $(RCS_FIND_IGNORE) \
               -name '*.[chS]' -print; \
-         find $(srctree)/security/selinux/include $(RCS_FIND_IGNORE) \
+         find $(__srctree)security/selinux/include $(RCS_FIND_IGNORE) \
               -name '*.[chS]' -print; \
-         find $(srctree)/include $(RCS_FIND_IGNORE) \
+         find $(__srctree)include $(RCS_FIND_IGNORE) \
               \( -name config -o -name 'asm-*' \) -prune \
               -o -name '*.[chS]' -print; \
-         find $(srctree)/include/asm-$(ARCH) $(RCS_FIND_IGNORE) \
+         find $(__srctree)include/asm-$(ARCH) $(RCS_FIND_IGNORE) \
               -name '*.[chS]' -print; \
-         find $(srctree)/include/asm-generic $(RCS_FIND_IGNORE) \
+         find $(__srctree)include/asm-generic $(RCS_FIND_IGNORE) \
               -name '*.[chS]' -print )
 endef
 
@@ -1172,7 +1189,7 @@
 define cmd_tags
        rm -f $@; \
        CTAGSF=`ctags --version | grep -i exuberant >/dev/null && echo "-I 
__initdata,__exitdata,EXPORT_SYMBOL,EXPORT_SYMBOL_GPL"`; \
-       $(all-sources) | xargs ctags $$CTAGSF -a
+       $(all-sources) | xargs ctags $$CTAGSF -a --extra=+f
 endef
 
 TAGS: FORCE
diff -Nru a/drivers/net/amd8111e.c b/drivers/net/amd8111e.c
--- a/drivers/net/amd8111e.c    2005-03-26 11:30:49 -08:00
+++ b/drivers/net/amd8111e.c    2005-03-26 11:30:49 -08:00
@@ -105,6 +105,7 @@
 MODULE_AUTHOR("Advanced Micro Devices, Inc.");
 MODULE_DESCRIPTION ("AMD8111 based 10/100 Ethernet Controller. Driver Version 
3.0.3");
 MODULE_LICENSE("GPL");
+MODULE_DEVICE_TABLE(pci, amd8111e_pci_tbl);
 module_param_array(speed_duplex, int, NULL, 0);
 MODULE_PARM_DESC(speed_duplex, "Set device speed and duplex modes, 0: Auto 
Negotitate, 1: 10Mbps Half Duplex, 2: 10Mbps Full Duplex, 3: 100Mbps Half 
Duplex, 4: 100Mbps Full Duplex");
 module_param_array(coalesce, bool, NULL, 0);
@@ -1489,7 +1490,7 @@
 amd8111e crc generator implementation is different from the kernel
 ether_crc() function.
 */
-int amd8111e_ether_crc(int len, char* mac_addr)
+static int amd8111e_ether_crc(int len, char* mac_addr)
 {
        int i,byte;
        unsigned char octet;
@@ -1717,7 +1718,7 @@
 /* 
 This function changes the mtu of the device. It restarts the device  to 
initialize the descriptor with new receive buffers.
 */  
-int amd8111e_change_mtu(struct net_device *dev, int new_mtu)
+static int amd8111e_change_mtu(struct net_device *dev, int new_mtu)
 {
        struct amd8111e_priv *lp = netdev_priv(dev);
        int err;
@@ -1799,7 +1800,7 @@
        if(!err)
                netif_wake_queue(dev);
 }
-static int amd8111e_suspend(struct pci_dev *pci_dev, u32 state)
+static int amd8111e_suspend(struct pci_dev *pci_dev, pm_message_t state)
 {      
        struct net_device *dev = pci_get_drvdata(pci_dev);
        struct amd8111e_priv *lp = netdev_priv(dev);
diff -Nru a/drivers/net/tun.c b/drivers/net/tun.c
--- a/drivers/net/tun.c 2005-03-26 11:30:49 -08:00
+++ b/drivers/net/tun.c 2005-03-26 11:30:49 -08:00
@@ -843,7 +843,7 @@
        .set_rx_csum    = tun_set_rx_csum
 };
 
-int __init tun_init(void)
+static int __init tun_init(void)
 {
        int ret = 0;
 
@@ -856,7 +856,7 @@
        return ret;
 }
 
-void tun_cleanup(void)
+static void tun_cleanup(void)
 {
        struct tun_struct *tun, *nxt;
 
diff -Nru a/drivers/net/via-rhine.c b/drivers/net/via-rhine.c
--- a/drivers/net/via-rhine.c   2005-03-26 11:30:49 -08:00
+++ b/drivers/net/via-rhine.c   2005-03-26 11:30:49 -08:00
@@ -390,7 +390,7 @@
 
 #ifdef USE_MMIO
 /* Registers we check that mmio and reg are the same. */
-int mmio_verify_registers[] = {
+static const int mmio_verify_registers[] = {
        RxConfig, TxConfig, IntrEnable, ConfigA, ConfigB, ConfigC, ConfigD,
        0
 };
@@ -1942,7 +1942,7 @@
 }
 
 #ifdef CONFIG_PM
-static int rhine_suspend(struct pci_dev *pdev, u32 state)
+static int rhine_suspend(struct pci_dev *pdev, pm_message_t state)
 {
        struct net_device *dev = pci_get_drvdata(pdev);
        struct rhine_private *rp = netdev_priv(dev);
diff -Nru a/fs/binfmt_elf.c b/fs/binfmt_elf.c
--- a/fs/binfmt_elf.c   2005-03-26 11:30:49 -08:00
+++ b/fs/binfmt_elf.c   2005-03-26 11:30:49 -08:00
@@ -37,6 +37,7 @@
 #include <linux/pagemap.h>
 #include <linux/security.h>
 #include <linux/syscalls.h>
+#include <linux/random.h>
 
 #include <asm/uaccess.h>
 #include <asm/param.h>
@@ -165,21 +166,14 @@
        if (k_platform) {
                size_t len = strlen(k_platform) + 1;
 
-#ifdef CONFIG_X86_HT
                /*
                 * In some cases (e.g. Hyper-Threading), we want to avoid L1
                 * evictions by the processes running on the same package. One
                 * thing we can do is to shuffle the initial stack for them.
-                *
-                * The conditionals here are unneeded, but kept in to make the
-                * code behaviour the same as pre change unless we have
-                * hyperthreaded processors. This should be cleaned up
-                * before 2.6
                 */
         
-               if (smp_num_siblings > 1)
-                       STACK_ALLOC(p, ((current->pid % 64) << 7));
-#endif
+               p = arch_align_stack(p);
+
                u_platform = (elf_addr_t __user *)STACK_ALLOC(p, len);
                if (__copy_to_user(u_platform, k_platform, len))
                        return -EFAULT;
@@ -501,6 +495,19 @@
 #define INTERPRETER_ELF 2
 
 
+static unsigned long randomize_stack_top(unsigned long stack_top)
+{
+       unsigned int random_variable = 0;
+
+       if (current->flags & PF_RANDOMIZE)
+               random_variable = get_random_int() % (8*1024*1024);
+#ifdef CONFIG_STACK_GROWSUP
+       return PAGE_ALIGN(stack_top + random_variable);
+#else
+       return PAGE_ALIGN(stack_top - random_variable);
+#endif
+}
+
 static int load_elf_binary(struct linux_binprm * bprm, struct pt_regs * regs)
 {
        struct file *interpreter = NULL; /* to shut gcc up */
@@ -760,18 +767,29 @@
        if (elf_read_implies_exec(loc->elf_ex, executable_stack))
                current->personality |= READ_IMPLIES_EXEC;
 
+       if ( !(current->personality & ADDR_NO_RANDOMIZE) && randomize_va_space)
+               current->flags |= PF_RANDOMIZE;
        arch_pick_mmap_layout(current->mm);
 
        /* Do this so that we can load the interpreter, if need be.  We will
           change some of these later */
        current->mm->rss = 0;
        current->mm->free_area_cache = current->mm->mmap_base;
-       retval = setup_arg_pages(bprm, STACK_TOP, executable_stack);
+       retval = setup_arg_pages(bprm, randomize_stack_top(STACK_TOP),
+                                executable_stack);
        if (retval < 0) {
                send_sig(SIGKILL, current, 0);
                goto out_free_dentry;
        }
        
+#ifdef ARCH_HAS_SETUP_ADDITIONAL_PAGES
+       retval = arch_setup_additional_pages(bprm, executable_stack);
+       if (retval < 0) {
+               send_sig(SIGKILL, current, 0);
+               goto out_free_dentry;
+       }
+#endif /* ARCH_HAS_SETUP_ADDITIONAL_PAGES */
+
        current->mm->start_stack = bprm->p;
 
        /* Now we do a little grungy work by mmaping the ELF image into
@@ -1126,10 +1144,14 @@
  */
 static int maydump(struct vm_area_struct *vma)
 {
-       /* Do not dump I/O mapped devices, shared memory, or special mappings */
-       if (vma->vm_flags & (VM_IO | VM_SHARED | VM_RESERVED))
+       /* Do not dump I/O mapped devices or special mappings */
+       if (vma->vm_flags & (VM_IO | VM_RESERVED))
                return 0;
 
+       /* Dump shared memory only if mapped from an anonymous file.  */
+       if (vma->vm_flags & VM_SHARED)
+               return vma->vm_file->f_dentry->d_inode->i_nlink == 0;
+
        /* If it hasn't been written to, don't write it out */
        if (!vma->anon_vma)
                return 0;
@@ -1589,7 +1611,7 @@
                                        DUMP_SEEK (file->f_pos + PAGE_SIZE);
                                } else {
                                        void *kaddr;
-                                       flush_cache_page(vma, addr);
+                                       flush_cache_page(vma, addr, 
page_to_pfn(page));
                                        kaddr = kmap(page);
                                        if ((size += PAGE_SIZE) > limit ||
                                            !dump_write(file, kaddr,
diff -Nru a/kernel/signal.c b/kernel/signal.c
--- a/kernel/signal.c   2005-03-26 11:30:49 -08:00
+++ b/kernel/signal.c   2005-03-26 11:30:49 -08:00
@@ -22,13 +22,12 @@
 #include <linux/security.h>
 #include <linux/syscalls.h>
 #include <linux/ptrace.h>
+#include <linux/posix-timers.h>
 #include <asm/param.h>
 #include <asm/uaccess.h>
 #include <asm/unistd.h>
 #include <asm/siginfo.h>
 
-extern void k_getrusage(struct task_struct *, int, struct rusage *);
-
 /*
  * SLAB caches for signal bits.
  */
@@ -260,19 +259,23 @@
        return sig;
 }
 
-static struct sigqueue *__sigqueue_alloc(struct task_struct *t, int flags)
+static struct sigqueue *__sigqueue_alloc(struct task_struct *t, int flags,
+                                        int override_rlimit)
 {
        struct sigqueue *q = NULL;
 
-       if (atomic_read(&t->user->sigpending) <
+       atomic_inc(&t->user->sigpending);
+       if (override_rlimit ||
+           atomic_read(&t->user->sigpending) <=
                        t->signal->rlim[RLIMIT_SIGPENDING].rlim_cur)
                q = kmem_cache_alloc(sigqueue_cachep, flags);
-       if (q) {
+       if (unlikely(q == NULL)) {
+               atomic_dec(&t->user->sigpending);
+       } else {
                INIT_LIST_HEAD(&q->list);
                q->flags = 0;
                q->lock = NULL;
                q->user = get_uid(t->user);
-               atomic_inc(&q->user->sigpending);
        }
        return(q);
 }
@@ -347,7 +350,9 @@
        if (!atomic_read(&sig->count))
                BUG();
        spin_lock(&sighand->siglock);
+       posix_cpu_timers_exit(tsk);
        if (atomic_dec_and_test(&sig->count)) {
+               posix_cpu_timers_exit_group(tsk);
                if (tsk == sig->curr_target)
                        sig->curr_target = next_thread(tsk);
                tsk->signal = NULL;
@@ -381,6 +386,7 @@
                sig->maj_flt += tsk->maj_flt;
                sig->nvcsw += tsk->nvcsw;
                sig->nivcsw += tsk->nivcsw;
+               sig->sched_time += tsk->sched_time;
                spin_unlock(&sighand->siglock);
                sig = NULL;     /* Marker for below.  */
        }
@@ -402,6 +408,7 @@
                 * signals are constrained to threads inside the group.
                 */
                exit_itimers(sig);
+               exit_thread_group_keys(sig);
                kmem_cache_free(signal_cachep, sig);
        }
 }
@@ -564,7 +571,15 @@
        if ( signr &&
             ((info->si_code & __SI_MASK) == __SI_TIMER) &&
             info->si_sys_private){
+               /*
+                * Release the siglock to ensure proper locking order
+                * of timer locks outside of siglocks.  Note, we leave
+                * irqs disabled here, since the posix-timers code is
+                * about to disable them again anyway.
+                */
+               spin_unlock(&tsk->sighand->siglock);
                do_schedule_next_timer(info);
+               spin_lock(&tsk->sighand->siglock);
        }
        return signr;
 }
@@ -793,7 +808,9 @@
           make sure at least one signal gets delivered and don't
           pass on the info struct.  */
 
-       q = __sigqueue_alloc(t, GFP_ATOMIC);
+       q = __sigqueue_alloc(t, GFP_ATOMIC, (sig < SIGRTMIN &&
+                                            ((unsigned long) info < 2 ||
+                                             info->si_code >= 0)));
        if (q) {
                list_add_tail(&q->list, &signals->list);
                switch ((unsigned long) info) {
@@ -1036,7 +1053,7 @@
        return;
 }
 
-static int
+int
 __group_send_sig_info(int sig, struct siginfo *info, struct task_struct *p)
 {
        int ret = 0;
@@ -1316,7 +1333,7 @@
 {
        struct sigqueue *q;
 
-       if ((q = __sigqueue_alloc(current, GFP_KERNEL)))
+       if ((q = __sigqueue_alloc(current, GFP_KERNEL, 0)))
                q->flags |= SIGQUEUE_PREALLOC;
        return(q);
 }
@@ -2433,7 +2450,7 @@
                int ss_flags;
 
                error = -EFAULT;
-               if (verify_area(VERIFY_READ, uss, sizeof(*uss))
+               if (!access_ok(VERIFY_READ, uss, sizeof(*uss))
                    || __get_user(ss_sp, &uss->ss_sp)
                    || __get_user(ss_flags, &uss->ss_flags)
                    || __get_user(ss_size, &uss->ss_size))
diff -Nru a/net/bluetooth/af_bluetooth.c b/net/bluetooth/af_bluetooth.c
--- a/net/bluetooth/af_bluetooth.c      2005-03-26 11:30:49 -08:00
+++ b/net/bluetooth/af_bluetooth.c      2005-03-26 11:30:49 -08:00
@@ -130,7 +130,7 @@
        sock_init_data(sock, sk);
        INIT_LIST_HEAD(&bt_sk(sk)->accept_q);
 
-       sk->sk_zapped   = 0;
+       sock_reset_flag(sk, SOCK_ZAPPED);
        sk->sk_protocol = proto;
        sk->sk_state    = BT_OPEN;
 
diff -Nru a/net/ipv4/fib_hash.c b/net/ipv4/fib_hash.c
--- a/net/ipv4/fib_hash.c       2005-03-26 11:30:49 -08:00
+++ b/net/ipv4/fib_hash.c       2005-03-26 11:30:49 -08:00
@@ -93,6 +93,7 @@
 }
 
 static DEFINE_RWLOCK(fib_hash_lock);
+static unsigned int fib_hash_genid;
 
 #define FZ_MAX_DIVISOR ((PAGE_SIZE<<MAX_ORDER) / sizeof(struct hlist_head))
 
@@ -181,6 +182,7 @@
                fz->fz_hashmask = new_hashmask;
                fz->fz_divisor = new_divisor;
                fn_rebuild_zone(fz, old_ht, old_divisor);
+               fib_hash_genid++;
                write_unlock_bh(&fib_hash_lock);
 
                fz_hash_free(old_ht, old_divisor);
@@ -236,6 +238,7 @@
                table->fn_zones[i]->fz_next = fz;
        }
        table->fn_zones[z] = fz;
+       fib_hash_genid++;
        write_unlock_bh(&fib_hash_lock);
        return fz;
 }
@@ -451,6 +454,7 @@
                        fa->fa_scope = r->rtm_scope;
                        state = fa->fa_state;
                        fa->fa_state &= ~FA_S_ACCESSED;
+                       fib_hash_genid++;
                        write_unlock_bh(&fib_hash_lock);
 
                        fib_release_info(fi_drop);
@@ -515,6 +519,7 @@
                fib_insert_node(fz, new_f);
        list_add_tail(&new_fa->fa_list,
                 (fa ? &fa->fa_list : &f->fn_alias));
+       fib_hash_genid++;
        write_unlock_bh(&fib_hash_lock);
 
        if (new_f)
@@ -600,6 +605,7 @@
                        hlist_del(&f->fn_hash);
                        kill_fn = 1;
                }
+               fib_hash_genid++;
                write_unlock_bh(&fib_hash_lock);
 
                if (fa->fa_state & FA_S_ACCESSED)
@@ -637,6 +643,7 @@
                                        hlist_del(&f->fn_hash);
                                        kill_f = 1;
                                }
+                               fib_hash_genid++;
                                write_unlock_bh(&fib_hash_lock);
 
                                fn_free_alias(fa);
@@ -801,6 +808,9 @@
        struct hlist_head *hash_head;
        struct fib_node *fn;
        struct fib_alias *fa;
+       loff_t pos;
+       unsigned int genid;
+       int valid;
 };
 
 static struct fib_alias *fib_get_first(struct seq_file *seq)
@@ -812,6 +822,9 @@
        iter->hash_head = NULL;
        iter->fn        = NULL;
        iter->fa        = NULL;
+       iter->pos       = 0;
+       iter->genid     = fib_hash_genid;
+       iter->valid     = 1;
 
        for (iter->zone = table->fn_zone_list; iter->zone;
             iter->zone = iter->zone->fz_next) {
@@ -916,12 +929,20 @@
                }
        }
 out:
+       iter->pos++;
        return fa;
 }
 
 static struct fib_alias *fib_get_idx(struct seq_file *seq, loff_t pos)
 {
-       struct fib_alias *fa = fib_get_first(seq);
+       struct fib_iter_state *iter = seq->private;
+       struct fib_alias *fa;
+       
+       if (iter->valid && pos >= iter->pos && iter->genid == fib_hash_genid) {
+               fa   = iter->fa;
+               pos -= iter->pos;
+       } else
+               fa = fib_get_first(seq);
 
        if (fa)
                while (pos && (fa = fib_get_next(seq)))
diff -Nru a/net/netrom/nr_in.c b/net/netrom/nr_in.c
--- a/net/netrom/nr_in.c        2005-03-26 11:30:49 -08:00
+++ b/net/netrom/nr_in.c        2005-03-26 11:30:49 -08:00
@@ -261,7 +261,7 @@
        return queued;
 }
 
-/* Higher level upcall for a LAPB frame */
+/* Higher level upcall for a LAPB frame - called with sk locked */
 int nr_process_rx_frame(struct sock *sk, struct sk_buff *skb)
 {
        nr_cb *nr = nr_sk(sk);
diff -Nru a/net/xfrm/xfrm_state.c b/net/xfrm/xfrm_state.c
--- a/net/xfrm/xfrm_state.c     2005-03-26 11:30:49 -08:00
+++ b/net/xfrm/xfrm_state.c     2005-03-26 11:30:49 -08:00
@@ -966,6 +966,36 @@
 }
 EXPORT_SYMBOL(xfrm_state_delete_tunnel);
 
+int xfrm_state_mtu(struct xfrm_state *x, int mtu)
+{
+       int res = mtu;
+
+       res -= x->props.header_len;
+
+       for (;;) {
+               int m = res;
+
+               if (m < 68)
+                       return 68;
+
+               spin_lock_bh(&x->lock);
+               if (x->km.state == XFRM_STATE_VALID &&
+                   x->type && x->type->get_max_size)
+                       m = x->type->get_max_size(x, m);
+               else
+                       m += x->props.header_len;
+               spin_unlock_bh(&x->lock);
+
+               if (m <= mtu)
+                       break;
+               res -= (m - mtu);
+       }
+
+       return res;
+}
+
+EXPORT_SYMBOL(xfrm_state_mtu);
+ 
 void __init xfrm_state_init(void)
 {
        int i;
diff -Nru a/sound/pci/ac97/ac97_codec.c b/sound/pci/ac97/ac97_codec.c
--- a/sound/pci/ac97/ac97_codec.c       2005-03-26 11:30:49 -08:00
+++ b/sound/pci/ac97/ac97_codec.c       2005-03-26 11:30:49 -08:00
@@ -56,6 +56,7 @@
        const char *name;
        int (*patch)(ac97_t *ac97);
        int (*mpatch)(ac97_t *ac97);
+       unsigned int flags;
 } ac97_codec_id_t;
 
 static const ac97_codec_id_t snd_ac97_codec_id_vendors[] = {
@@ -103,6 +104,7 @@
 { 0x41445372, 0xffffffff, "AD1981A",           patch_ad1981a,  NULL },
 { 0x41445374, 0xffffffff, "AD1981B",           patch_ad1981b,  NULL },
 { 0x41445375, 0xffffffff, "AD1985",            patch_ad1985,   NULL },
+{ 0x41445378, 0xffffffff, "AD1986",            patch_ad1985,   NULL },
 { 0x414c4300, 0xffffff00, "ALC100/100P",       NULL,           NULL },
 { 0x414c4710, 0xfffffff0, "ALC200/200P",       NULL,           NULL },
 { 0x414c4721, 0xffffffff, "ALC650D",           NULL,   NULL }, /* already 
patched */
@@ -161,6 +163,7 @@
 { 0x574d4C05, 0xffffffff, "WM9705/WM9710",     patch_wolfson05, NULL},
 { 0x574d4C09, 0xffffffff, "WM9709",            NULL,           NULL},
 { 0x574d4C12, 0xffffffff, "WM9711/WM9712",     patch_wolfson11, NULL},
+{ 0x574d4c13, 0xffffffff, "WM9713/WM9714",     patch_wolfson13, NULL, 
AC97_DEFAULT_POWER_OFF},
 { 0x594d4800, 0xffffffff, "YMF743",            NULL,           NULL },
 { 0x594d4802, 0xffffffff, "YMF752",            NULL,           NULL },
 { 0x594d4803, 0xffffffff, "YMF753",            patch_yamaha_ymf753,    NULL },
@@ -438,111 +441,81 @@
 }
 
 /*
- *
+ * Controls
  */
 
-static int snd_ac97_info_mux(snd_kcontrol_t *kcontrol, snd_ctl_elem_info_t * 
uinfo)
+int snd_ac97_info_enum_double(snd_kcontrol_t *kcontrol, snd_ctl_elem_info_t * 
uinfo)
 {
-       static char *texts[8] = {
-               "Mic", "CD", "Video", "Aux", "Line",
-               "Mix", "Mix Mono", "Phone"
-       };
-
+       struct ac97_enum *e = (struct ac97_enum *)kcontrol->private_value;
+       
        uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED;
-       uinfo->count = 2;
-       uinfo->value.enumerated.items = 8;
-       if (uinfo->value.enumerated.item > 7)
-               uinfo->value.enumerated.item = 7;
-       strcpy(uinfo->value.enumerated.name, 
texts[uinfo->value.enumerated.item]);
-       return 0;
-}
-
-static int snd_ac97_get_mux(snd_kcontrol_t * kcontrol, snd_ctl_elem_value_t * 
ucontrol)
-{
-       ac97_t *ac97 = snd_kcontrol_chip(kcontrol);
-       unsigned short val;
+       uinfo->count = e->shift_l == e->shift_r ? 1 : 2;
+       uinfo->value.enumerated.items = e->mask;
        
-       val = snd_ac97_read_cache(ac97, AC97_REC_SEL);
-       ucontrol->value.enumerated.item[0] = (val >> 8) & 7;
-       ucontrol->value.enumerated.item[1] = (val >> 0) & 7;
+       if (uinfo->value.enumerated.item > e->mask - 1)
+               uinfo->value.enumerated.item = e->mask - 1;
+       strcpy(uinfo->value.enumerated.name, 
e->texts[uinfo->value.enumerated.item]);
        return 0;
 }
 
-static int snd_ac97_put_mux(snd_kcontrol_t * kcontrol, snd_ctl_elem_value_t * 
ucontrol)
+int snd_ac97_get_enum_double(snd_kcontrol_t * kcontrol, snd_ctl_elem_value_t * 
ucontrol)
 {
        ac97_t *ac97 = snd_kcontrol_chip(kcontrol);
+       struct ac97_enum *e = (struct ac97_enum *)kcontrol->private_value;
        unsigned short val;
        
-       if (ucontrol->value.enumerated.item[0] > 7 ||
-           ucontrol->value.enumerated.item[1] > 7)
-               return -EINVAL;
-       val = (ucontrol->value.enumerated.item[0] << 8) |
-             (ucontrol->value.enumerated.item[1] << 0);
-       return snd_ac97_update(ac97, AC97_REC_SEL, val);
-}
-
-#define AC97_ENUM_DOUBLE(xname, reg, shift, invert) \
-{ .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = xname, .info = 
snd_ac97_info_enum_double, \
-  .get = snd_ac97_get_enum_double, .put = snd_ac97_put_enum_double, \
-  .private_value = reg | (shift << 8) | (invert << 24) }
-
-static int snd_ac97_info_enum_double(snd_kcontrol_t *kcontrol, 
snd_ctl_elem_info_t * uinfo)
-{
-       static char *texts1[2] = { "pre 3D", "post 3D" };
-       static char *texts2[2] = { "Mix", "Mic" };
-       static char *texts3[2] = { "Mic1", "Mic2" };
-       char **texts = NULL;
-       int reg = kcontrol->private_value & 0xff;
-       int shift = (kcontrol->private_value >> 8) & 0xff;
+       val = snd_ac97_read_cache(ac97, e->reg);
+       ucontrol->value.enumerated.item[0] = (val >> e->shift_l) & (e->mask - 
1);
+       if (e->shift_l != e->shift_r)
+               ucontrol->value.enumerated.item[1] = (val >> e->shift_r) & 
(e->mask - 1);
 
-       switch (reg) {
-       case AC97_GENERAL_PURPOSE:
-               switch (shift) {
-               case 15: texts = texts1; break;
-               case 9: texts = texts2; break;
-               case 8: texts = texts3; break;
-               }
-       }
-       uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED;
-       uinfo->count = 1;
-       uinfo->value.enumerated.items = 2;
-       if (uinfo->value.enumerated.item > 1)
-               uinfo->value.enumerated.item = 1;
-       strcpy(uinfo->value.enumerated.name, 
texts[uinfo->value.enumerated.item]);
        return 0;
 }
 
-static int snd_ac97_get_enum_double(snd_kcontrol_t * kcontrol, 
snd_ctl_elem_value_t * ucontrol)
+int snd_ac97_put_enum_double(snd_kcontrol_t * kcontrol, snd_ctl_elem_value_t * 
ucontrol)
 {
        ac97_t *ac97 = snd_kcontrol_chip(kcontrol);
+       struct ac97_enum *e = (struct ac97_enum *)kcontrol->private_value;
        unsigned short val;
-       int reg = kcontrol->private_value & 0xff;
-       int shift = (kcontrol->private_value >> 8) & 0xff;
-       int invert = (kcontrol->private_value >> 24) & 0xff;
+       unsigned short mask;
        
-       val = (snd_ac97_read_cache(ac97, reg) >> shift) & 1;
-       if (invert)
-               val ^= 1;
-       ucontrol->value.enumerated.item[0] = val;
-       return 0;
+       if (ucontrol->value.enumerated.item[0] > e->mask - 1)
+               return -EINVAL;
+       val = ucontrol->value.enumerated.item[0] << e->shift_l;
+       mask = (e->mask - 1) << e->shift_l;
+       if (e->shift_l != e->shift_r) {
+               if (ucontrol->value.enumerated.item[1] > e->mask - 1)
+                       return -EINVAL;
+               val |= ucontrol->value.enumerated.item[1] << e->shift_r;
+               mask |= (e->mask - 1) << e->shift_r;
+       }
+       return snd_ac97_update_bits(ac97, e->reg, mask, val);
+}
+
+/* save/restore ac97 v2.3 paging */
+static int snd_ac97_page_save(ac97_t *ac97, int reg, snd_kcontrol_t *kcontrol)
+{
+       int page_save = -1;
+       if ((kcontrol->private_value & (1<<25)) &&
+           (ac97->ext_id & AC97_EI_REV_MASK) >= AC97_EI_REV_23 &&
+           (reg >= 0x60 && reg < 0x70)) {
+               unsigned short page = (kcontrol->private_value >> 26) & 0x0f;
+               down(&ac97->page_mutex); /* lock paging */
+               page_save = snd_ac97_read(ac97, AC97_INT_PAGING) & 
AC97_PAGE_MASK;
+               snd_ac97_update_bits(ac97, AC97_INT_PAGING, AC97_PAGE_MASK, 
page);
+       }
+       return page_save;
 }
 
-static int snd_ac97_put_enum_double(snd_kcontrol_t * kcontrol, 
snd_ctl_elem_value_t * ucontrol)
+static void snd_ac97_page_restore(ac97_t *ac97, int page_save)
 {
-       ac97_t *ac97 = snd_kcontrol_chip(kcontrol);
-       unsigned short val;
-       int reg = kcontrol->private_value & 0xff;
-       int shift = (kcontrol->private_value >> 8) & 0xff;
-       int invert = (kcontrol->private_value >> 24) & 0xff;
-       
-       if (ucontrol->value.enumerated.item[0] > 1)
-               return -EINVAL;
-       val = !!ucontrol->value.enumerated.item[0];
-       if (invert)
-               val = !val;
-       return snd_ac97_update_bits(ac97, reg, 1 << shift, val << shift);
+       if (page_save >= 0) {
+               snd_ac97_update_bits(ac97, AC97_INT_PAGING, AC97_PAGE_MASK, 
page_save);
+               up(&ac97->page_mutex); /* unlock paging */
+       }
 }
 
+/* volume and switch controls */
 int snd_ac97_info_volsw(snd_kcontrol_t *kcontrol, snd_ctl_elem_info_t * uinfo)
 {
        int mask = (kcontrol->private_value >> 16) & 0xff;
@@ -564,7 +537,9 @@
        int rshift = (kcontrol->private_value >> 12) & 0x0f;
        int mask = (kcontrol->private_value >> 16) & 0xff;
        int invert = (kcontrol->private_value >> 24) & 0x01;
-       
+       int page_save;
+
+       page_save = snd_ac97_page_save(ac97, reg, kcontrol);
        ucontrol->value.integer.value[0] = (snd_ac97_read_cache(ac97, reg) >> 
shift) & mask;
        if (shift != rshift)
                ucontrol->value.integer.value[1] = (snd_ac97_read_cache(ac97, 
reg) >> rshift) & mask;
@@ -573,6 +548,7 @@
                if (shift != rshift)
                        ucontrol->value.integer.value[1] = mask - 
ucontrol->value.integer.value[1];
        }
+       snd_ac97_page_restore(ac97, page_save);
        return 0;
 }
 
@@ -584,8 +560,10 @@
        int rshift = (kcontrol->private_value >> 12) & 0x0f;
        int mask = (kcontrol->private_value >> 16) & 0xff;
        int invert = (kcontrol->private_value >> 24) & 0x01;
+       int err, page_save;
        unsigned short val, val2, val_mask;
        
+       page_save = snd_ac97_page_save(ac97, reg, kcontrol);
        val = (ucontrol->value.integer.value[0] & mask);
        if (invert)
                val = mask - val;
@@ -598,48 +576,11 @@
                val_mask |= mask << rshift;
                val |= val2 << rshift;
        }
-       return snd_ac97_update_bits(ac97, reg, val_mask, val);
-}
-
-#define AC97_DOUBLE(xname, reg, shift_left, shift_right, mask, invert) \
-{ .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = (xname), .info = 
snd_ac97_info_volsw, \
-  .get = snd_ac97_get_volsw, .put = snd_ac97_put_volsw, \
-  .private_value = (reg) | ((shift_left) << 8) | ((shift_right) << 12) | 
((mask) << 16) | ((invert) << 24) }
-
-static int snd_ac97_getput_page(snd_kcontrol_t *kcontrol, snd_ctl_elem_value_t 
*ucontrol,
-                        int (*func)(snd_kcontrol_t *, snd_ctl_elem_value_t *))
-{
-       ac97_t *ac97 = snd_kcontrol_chip(kcontrol);
-       int reg = kcontrol->private_value & 0xff;
-       int err;
-
-       if ((ac97->ext_id & AC97_EI_REV_MASK) >= AC97_EI_REV_23 &&
-           (reg >= 0x60 && reg < 0x70)) {
-               unsigned short page_save;
-               unsigned short page = (kcontrol->private_value >> 25) & 0x0f;
-               down(&ac97->page_mutex); /* lock paging */
-               page_save = snd_ac97_read(ac97, AC97_INT_PAGING) & 
AC97_PAGE_MASK;
-               snd_ac97_update_bits(ac97, AC97_INT_PAGING, AC97_PAGE_MASK, 
page);
-               err = func(kcontrol, ucontrol);
-               snd_ac97_update_bits(ac97, AC97_INT_PAGING, AC97_PAGE_MASK, 
page_save);
-               up(&ac97->page_mutex); /* unlock paging */
-       } else
-               err = func(kcontrol, ucontrol);
+       err = snd_ac97_update_bits(ac97, reg, val_mask, val);
+       snd_ac97_page_restore(ac97, page_save);
        return err;
 }
 
-/* for rev2.3 paging */
-int snd_ac97_page_get_volsw(snd_kcontrol_t *kcontrol, snd_ctl_elem_value_t 
*ucontrol)
-{
-       return snd_ac97_getput_page(kcontrol, ucontrol, snd_ac97_get_volsw);
-}
-
-/* for rev2.3 paging */
-int snd_ac97_page_put_volsw(snd_kcontrol_t *kcontrol, snd_ctl_elem_value_t 
*ucontrol)
-{
-       return snd_ac97_getput_page(kcontrol, ucontrol, snd_ac97_put_volsw);
-}
-
 static const snd_kcontrol_new_t snd_ac97_controls_master_mono[2] = {
 AC97_SINGLE("Master Mono Playback Switch", AC97_MASTER_MONO, 15, 1, 1),
 AC97_SINGLE("Master Mono Playback Volume", AC97_MASTER_MONO, 0, 31, 1)
@@ -659,14 +600,21 @@
        AC97_SINGLE("Mic Boost (+20dB)", AC97_MIC, 6, 1, 0);
 
 
-static const snd_kcontrol_new_t snd_ac97_control_capture_src = {
-       .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
-       .name = "Capture Source",
-       .info = snd_ac97_info_mux,
-       .get = snd_ac97_get_mux,
-       .put = snd_ac97_put_mux,
+static const char* std_rec_sel[] = {"Mic", "CD", "Video", "Aux", "Line", 
"Mix", "Mix Mono", "Phone"};
+static const char* std_3d_path[] = {"pre 3D", "post 3D"};
+static const char* std_mix[] = {"Mix", "Mic"};
+static const char* std_mic[] = {"Mic1", "Mic2"};
+
+static const struct ac97_enum std_enum[] = {
+AC97_ENUM_DOUBLE(AC97_REC_SEL, 8, 0, 8, std_rec_sel),
+AC97_ENUM_SINGLE(AC97_GENERAL_PURPOSE, 15, 2, std_3d_path),
+AC97_ENUM_SINGLE(AC97_GENERAL_PURPOSE, 9, 2, std_mix),
+AC97_ENUM_SINGLE(AC97_GENERAL_PURPOSE, 8, 2, std_mic),
 };
 
+static const snd_kcontrol_new_t snd_ac97_control_capture_src = 
+AC97_ENUM("Capture Source", std_enum[0]); 
+
 static const snd_kcontrol_new_t snd_ac97_control_capture_vol =
 AC97_DOUBLE("Capture Volume", AC97_REC_GAIN, 8, 0, 15, 0);
 
@@ -686,12 +634,12 @@
 } ac97_general_index_t;
 
 static const snd_kcontrol_new_t snd_ac97_controls_general[7] = {
-AC97_ENUM_DOUBLE("PCM Out Path & Mute", AC97_GENERAL_PURPOSE, 15, 0),
+AC97_ENUM("PCM Out Path & Mute", std_enum[1]),
 AC97_SINGLE("Simulated Stereo Enhancement", AC97_GENERAL_PURPOSE, 14, 1, 0),
 AC97_SINGLE("3D Control - Switch", AC97_GENERAL_PURPOSE, 13, 1, 0),
 AC97_SINGLE("Loudness (bass boost)", AC97_GENERAL_PURPOSE, 12, 1, 0),
-AC97_ENUM_DOUBLE("Mono Output Select", AC97_GENERAL_PURPOSE, 9, 0),
-AC97_ENUM_DOUBLE("Mic Select", AC97_GENERAL_PURPOSE, 8, 0),
+AC97_ENUM("Mono Output Select", std_enum[2]),
+AC97_ENUM("Mic Select", std_enum[3]),
 AC97_SINGLE("ADC/DAC Loopback", AC97_GENERAL_PURPOSE, 7, 1, 0)
 };
 
@@ -1360,8 +1308,9 @@
        }
        
        /* build PC Speaker controls */
-       if ((ac97->flags & AC97_HAS_PC_BEEP) ||
-           snd_ac97_try_volume_mix(ac97, AC97_PC_BEEP)) {
+       if (!(ac97->flags & AC97_HAS_NO_PC_BEEP) && 
+               ((ac97->flags & AC97_HAS_PC_BEEP) ||
+           snd_ac97_try_volume_mix(ac97, AC97_PC_BEEP))) {
                for (idx = 0; idx < 2; idx++)
                        if ((err = snd_ctl_add(card, 
snd_ac97_cnew(&snd_ac97_controls_pc_beep[idx], ac97))) < 0)
                                return err;
@@ -1370,9 +1319,11 @@
        }
        
        /* build Phone controls */
-       if (snd_ac97_try_volume_mix(ac97, AC97_PHONE)) {
-               if ((err = snd_ac97_cmix_new(card, "Phone Playback", 
AC97_PHONE, ac97)) < 0)
-                       return err;
+       if (!(ac97->flags & AC97_HAS_NO_PHONE)) {
+               if (snd_ac97_try_volume_mix(ac97, AC97_PHONE)) {
+                       if ((err = snd_ac97_cmix_new(card, "Phone Playback", 
AC97_PHONE, ac97)) < 0)
+                               return err;
+               }
        }
        
        /* build MIC controls */
@@ -1390,15 +1341,19 @@
        }
        
        /* build CD controls */
-       if (snd_ac97_try_volume_mix(ac97, AC97_CD)) {
-               if ((err = snd_ac97_cmix_new(card, "CD Playback", AC97_CD, 
ac97)) < 0)
-                       return err;
+       if (!(ac97->flags & AC97_HAS_NO_CD)) {
+               if (snd_ac97_try_volume_mix(ac97, AC97_CD)) {
+                       if ((err = snd_ac97_cmix_new(card, "CD Playback", 
AC97_CD, ac97)) < 0)
+                               return err;
+               }
        }
        
        /* build Video controls */
-       if (snd_ac97_try_volume_mix(ac97, AC97_VIDEO)) {
-               if ((err = snd_ac97_cmix_new(card, "Video Playback", 
AC97_VIDEO, ac97)) < 0)
-                       return err;
+       if (!(ac97->flags & AC97_HAS_NO_VIDEO)) {
+               if (snd_ac97_try_volume_mix(ac97, AC97_VIDEO)) {
+                       if ((err = snd_ac97_cmix_new(card, "Video Playback", 
AC97_VIDEO, ac97)) < 0)
+                               return err;
+               }
        }
 
        /* build Aux controls */
@@ -1444,17 +1399,18 @@
        }
 
        /* build Capture controls */
-       if ((err = snd_ctl_add(card, 
snd_ac97_cnew(&snd_ac97_control_capture_src, ac97))) < 0)
-               return err;
-       if (snd_ac97_try_bit(ac97, AC97_REC_GAIN, 15)) {
-               if ((err = snd_ac97_cmute_new(card, "Capture Switch", 
AC97_REC_GAIN, ac97)) < 0)
+       if (!(ac97->flags & AC97_HAS_NO_REC_GAIN)) {
+               if ((err = snd_ctl_add(card, 
snd_ac97_cnew(&snd_ac97_control_capture_src, ac97))) < 0)
                        return err;
+               if (snd_ac97_try_bit(ac97, AC97_REC_GAIN, 15)) {
+                       if ((err = snd_ac97_cmute_new(card, "Capture Switch", 
AC97_REC_GAIN, ac97)) < 0)
+                               return err;
+               }
+               if ((err = snd_ctl_add(card, 
snd_ac97_cnew(&snd_ac97_control_capture_vol, ac97))) < 0)
+                       return err;
+               snd_ac97_write_cache(ac97, AC97_REC_SEL, 0x0000);
+               snd_ac97_write_cache(ac97, AC97_REC_GAIN, 0x0000);
        }
-       if ((err = snd_ctl_add(card, 
snd_ac97_cnew(&snd_ac97_control_capture_vol, ac97))) < 0)
-               return err;
-       snd_ac97_write_cache(ac97, AC97_REC_SEL, 0x0000);
-       snd_ac97_write_cache(ac97, AC97_REC_GAIN, 0x0000);
-
        /* build MIC Capture controls */
        if (snd_ac97_try_volume_mix(ac97, AC97_REC_GAIN_MIC)) {
                for (idx = 0; idx < 2; idx++)
@@ -1596,6 +1552,7 @@
 static void snd_ac97_determine_rates(ac97_t *ac97, int reg, int shadow_reg, 
unsigned int *r_result)
 {
        unsigned int result = 0;
+       unsigned short saved;
 
        if (ac97->bus->no_vra) {
                *r_result = SNDRV_PCM_RATE_48000;
@@ -1605,6 +1562,7 @@
                return;
        }
 
+       saved = snd_ac97_read(ac97, reg);
        if ((ac97->ext_id & AC97_EI_DRA) && reg == AC97_PCM_FRONT_DAC_RATE)
                snd_ac97_update_bits(ac97, AC97_EXTENDED_STATUS,
                                     AC97_EA_DRA, 0);
@@ -1643,6 +1601,10 @@
                snd_ac97_update_bits(ac97, AC97_EXTENDED_STATUS,
                                     AC97_EA_DRA, 0);
        }
+       /* restore the default value */
+       snd_ac97_write_cache(ac97, reg, saved);
+       if (shadow_reg)
+               snd_ac97_write_cache(ac97, shadow_reg, saved);
        *r_result = result;
 }
 
@@ -1666,6 +1628,18 @@
        return result;
 }
 
+/* look for the codec id table matching with the given id */
+static const ac97_codec_id_t *look_for_codec_id(const ac97_codec_id_t *table,
+                                               unsigned int id)
+{
+       const ac97_codec_id_t *pid;
+
+       for (pid = table; pid->id; pid++)
+               if (pid->id == (id & pid->mask))
+                       return pid;
+       return NULL;
+}
+
 void snd_ac97_get_name(ac97_t *ac97, unsigned int id, char *name, int modem)
 {
        const ac97_codec_id_t *pid;
@@ -1674,35 +1648,30 @@
                printable(id >> 24),
                printable(id >> 16),
                printable(id >> 8));
-       for (pid = snd_ac97_codec_id_vendors; pid->id; pid++)
-               if (pid->id == (id & pid->mask)) {
-                       strcpy(name, pid->name);
-                       if (ac97) {
-                               if (!modem && pid->patch)
-                                       pid->patch(ac97);
-                               else if (modem && pid->mpatch)
-                                       pid->mpatch(ac97);
-                       } 
-                       goto __vendor_ok;
-               }
-       return;
+       pid = look_for_codec_id(snd_ac97_codec_id_vendors, id);
+       if (! pid)
+               return;
 
-      __vendor_ok:
-       for (pid = snd_ac97_codec_ids; pid->id; pid++)
-               if (pid->id == (id & pid->mask)) {
-                       strcat(name, " ");
-                       strcat(name, pid->name);
-                       if (pid->mask != 0xffffffff)
-                               sprintf(name + strlen(name), " rev %d", id & 
~pid->mask);
-                       if (ac97) {
-                               if (!modem && pid->patch)
-                                       pid->patch(ac97);
-                               else if (modem && pid->mpatch)
-                                       pid->mpatch(ac97);
-                       }
-                       return;
+       strcpy(name, pid->name);
+       if (ac97 && pid->patch) {
+               if ((modem && (pid->flags & AC97_MODEM_PATCH)) ||
+                   (! modem && ! (pid->flags & AC97_MODEM_PATCH)))
+                       pid->patch(ac97);
+       } 
+
+       pid = look_for_codec_id(snd_ac97_codec_ids, id);
+       if (pid) {
+               strcat(name, " ");
+               strcat(name, pid->name);
+               if (pid->mask != 0xffffffff)
+                       sprintf(name + strlen(name), " rev %d", id & 
~pid->mask);
+               if (ac97 && pid->patch) {
+                       if ((modem && (pid->flags & AC97_MODEM_PATCH)) ||
+                           (! modem && ! (pid->flags & AC97_MODEM_PATCH)))
+                               pid->patch(ac97);
                }
-       sprintf(name + strlen(name), " id %x", id & 0xff);
+       } else
+               sprintf(name + strlen(name), " id %x", id & 0xff);
 }
 
 /**
@@ -1844,6 +1813,7 @@
        char name[64];
        unsigned long end_time;
        unsigned int reg;
+       const ac97_codec_id_t *pid;
        static snd_device_ops_t ops = {
                .dev_free =     snd_ac97_dev_free,
        };
@@ -1894,6 +1864,14 @@
                goto __access_ok;
        }
 
+       ac97->id = snd_ac97_read(ac97, AC97_VENDOR_ID1) << 16;
+       ac97->id |= snd_ac97_read(ac97, AC97_VENDOR_ID2);
+       if (ac97->id && ac97->id != (unsigned int)-1) {
+               pid = look_for_codec_id(snd_ac97_codec_ids, ac97->id);
+               if (pid && (pid->flags & AC97_DEFAULT_POWER_OFF))
+                       goto __access_ok;
+       }
+
        snd_ac97_write(ac97, AC97_RESET, 0);    /* reset to defaults */
        if (bus->ops->wait)
                bus->ops->wait(ac97);
@@ -1920,6 +1898,9 @@
                snd_ac97_free(ac97);
                return -EIO;
        }
+       pid = look_for_codec_id(snd_ac97_codec_ids, ac97->id);
+       if (pid)
+               ac97->flags |= pid->flags;
        
        /* test for AC'97 */
        if (!(ac97->scaps & AC97_SCAP_SKIP_AUDIO) && !(ac97->scaps & 
AC97_SCAP_AUDIO)) {
@@ -1958,10 +1939,12 @@
        if (ac97_is_audio(ac97)) {
                /* nothing should be in powerdown mode */
                snd_ac97_write_cache(ac97, AC97_POWERDOWN, 0);
-               snd_ac97_write_cache(ac97, AC97_RESET, 0);              /* 
reset to defaults */
-               udelay(100);
+               if (! (ac97->flags & AC97_DEFAULT_POWER_OFF)) {
+                       snd_ac97_write_cache(ac97, AC97_RESET, 0); /* reset to 
defaults */
+                       udelay(100);
+                       snd_ac97_write_cache(ac97, AC97_POWERDOWN, 0);
+               }
                /* nothing should be in powerdown mode */
-               snd_ac97_write_cache(ac97, AC97_POWERDOWN, 0);
                snd_ac97_write_cache(ac97, AC97_GENERAL_PURPOSE, 0);
                end_time = jiffies + (HZ / 10);
                do {
@@ -2228,9 +2211,11 @@
        }
 
        snd_ac97_write(ac97, AC97_POWERDOWN, 0);
-       snd_ac97_write(ac97, AC97_RESET, 0);
-       udelay(100);
-       snd_ac97_write(ac97, AC97_POWERDOWN, 0);
+       if (! (ac97->flags & AC97_DEFAULT_POWER_OFF)) {
+               snd_ac97_write(ac97, AC97_RESET, 0);
+               udelay(100);
+               snd_ac97_write(ac97, AC97_POWERDOWN, 0);
+       }
        snd_ac97_write(ac97, AC97_GENERAL_PURPOSE, 0);
 
        snd_ac97_write(ac97, AC97_POWERDOWN, ac97->regs[AC97_POWERDOWN]);
@@ -2334,6 +2319,35 @@
        return -ENOENT;
 }
 
+#if 1
+/* bind hp and master controls instead of using only hp control */
+static int bind_hp_volsw_put(snd_kcontrol_t *kcontrol, snd_ctl_elem_value_t 
*ucontrol)
+{
+       int err = snd_ac97_put_volsw(kcontrol, ucontrol);
+       if (err > 0) {
+               unsigned long priv_saved = kcontrol->private_value;
+               kcontrol->private_value = (kcontrol->private_value & ~0xff) | 
AC97_HEADPHONE;
+               snd_ac97_put_volsw(kcontrol, ucontrol);
+               kcontrol->private_value = priv_saved;
+       }
+       return err;
+}
+
+/* ac97 tune: bind Master and Headphone controls */
+static int tune_hp_only(ac97_t *ac97)
+{
+       snd_kcontrol_t *msw = ctl_find(ac97, "Master Playback Switch", NULL);
+       snd_kcontrol_t *mvol = ctl_find(ac97, "Master Playback Volume", NULL);
+       if (! msw || ! mvol)
+               return -ENOENT;
+       msw->put = bind_hp_volsw_put;
+       mvol->put = bind_hp_volsw_put;
+       snd_ac97_remove_ctl(ac97, "Headphone Playback", "Switch");
+       snd_ac97_remove_ctl(ac97, "Headphone Playback", "Volume");
+       return 0;
+}
+
+#else
 /* ac97 tune: use Headphone control as master */
 static int tune_hp_only(ac97_t *ac97)
 {
@@ -2344,6 +2358,7 @@
        snd_ac97_rename_vol_ctl(ac97, "Headphone Playback", "Master Playback");
        return 0;
 }
+#endif
 
 /* ac97 tune: swap Headphone and Master controls */
 static int tune_swap_hp(ac97_t *ac97)
@@ -2475,7 +2490,7 @@
        }
        /* for compatibility, accept the numbers, too */
        if (*typestr >= '0' && *typestr <= '9')
-               return apply_quirk(ac97, (int)simple_strtol(typestr, NULL, 10));
+               return apply_quirk(ac97, (int)simple_strtoul(typestr, NULL, 
10));
        return -EINVAL;
 }
 
-
To unsubscribe from this list: send the line "unsubscribe bk-commits-head" in
the body of a message to [EMAIL PROTECTED]
More majordomo info at  http://vger.kernel.org/majordomo-info.html

Reply via email to