Merge branch 'devel' of git.alsa-project.org:alsa-kernel into topic/misc
authorTakashi Iwai <tiwai@suse.de>
Wed, 13 Jan 2010 07:32:53 +0000 (08:32 +0100)
committerTakashi Iwai <tiwai@suse.de>
Wed, 13 Jan 2010 07:32:53 +0000 (08:32 +0100)
33 files changed:
Documentation/sound/alsa/ALSA-Configuration.txt
include/sound/cs46xx_dsp_spos.h
include/sound/pcm.h
include/sound/sb.h
sound/core/pcm_lib.c
sound/core/pcm_memory.c
sound/core/pcm_native.c
sound/drivers/vx/vx_pcm.c
sound/isa/Kconfig
sound/isa/Makefile
sound/isa/als100.c
sound/isa/dt019x.c [deleted file]
sound/isa/opti9xx/opti92x-ad1848.c
sound/isa/sb/Makefile
sound/isa/sb/jazz16.c [new file with mode: 0644]
sound/isa/sb/sb8_main.c
sound/isa/sb/sb_common.c
sound/isa/sb/sb_mixer.c
sound/isa/wss/wss_lib.c
sound/mips/sgio2audio.c
sound/oss/soundcard.c
sound/pci/cs46xx/cs46xx_lib.c
sound/pci/cs46xx/dsp_spos.c
sound/pci/cs46xx/dsp_spos.h
sound/pci/cs46xx/dsp_spos_scb_lib.c
sound/pcmcia/pdaudiocf/pdaudiocf_pcm.c
sound/usb/Kconfig
sound/usb/Makefile
sound/usb/ua101.c [new file with mode: 0644]
sound/usb/usbaudio.c
sound/usb/usbaudio.h
sound/usb/usbmixer.c
sound/usb/usbquirks.h

index 8923597..c540637 100644 (file)
@@ -1123,6 +1123,21 @@ Prior to version 0.9.0rc4 options had a 'snd_' prefix. This was removed.
 
     This module supports multiple cards, autoprobe and ISA PnP.
 
+  Module snd-jazz16
+  -------------------
+
+    Module for Media Vision Jazz16 chipset. The chipset consists of 3 chips:
+    MVD1216 + MVA416 + MVA514.
+
+    port       - port # for SB DSP chip (0x210,0x220,0x230,0x240,0x250,0x260)
+    irq                - IRQ # for SB DSP chip (3,5,7,9,10,15)
+    dma8       - DMA # for SB DSP chip (1,3)
+    dma16      - DMA # for SB DSP chip (5,7)
+    mpu_port   - MPU-401 port # (0x300,0x310,0x320,0x330)
+    mpu_irq    - MPU-401 irq # (2,3,5,7)
+
+    This module supports multiple cards.
+
   Module snd-korg1212
   -------------------
 
@@ -1791,6 +1806,13 @@ Prior to version 0.9.0rc4 options had a 'snd_' prefix. This was removed.
 
     The power-management is supported.
 
+  Module snd-ua101
+  ----------------
+
+    Module for the Edirol UA-101 audio/MIDI interface.
+
+    This module supports multiple devices, autoprobe and hotplugging.
+
   Module snd-usb-audio
   --------------------
 
index 7c44667..49b03c9 100644 (file)
@@ -118,9 +118,11 @@ struct dsp_scb_descriptor {
 
        struct snd_info_entry *proc_info;
        int ref_count;
-       spinlock_t lock;
 
-       int deleted;
+       u16 volume[2];
+       unsigned int deleted :1;
+       unsigned int updated :1;
+       unsigned int volume_set :1;
 };
 
 struct dsp_task_descriptor {
index e26fb3c..1d4ca2a 100644 (file)
@@ -913,6 +913,44 @@ int snd_pcm_lib_preallocate_pages_for_all(struct snd_pcm *pcm,
 int snd_pcm_lib_malloc_pages(struct snd_pcm_substream *substream, size_t size);
 int snd_pcm_lib_free_pages(struct snd_pcm_substream *substream);
 
+int _snd_pcm_lib_alloc_vmalloc_buffer(struct snd_pcm_substream *substream,
+                                     size_t size, gfp_t gfp_flags);
+int snd_pcm_lib_free_vmalloc_buffer(struct snd_pcm_substream *substream);
+struct page *snd_pcm_lib_get_vmalloc_page(struct snd_pcm_substream *substream,
+                                         unsigned long offset);
+#if 0 /* for kernel-doc */
+/**
+ * snd_pcm_lib_alloc_vmalloc_buffer - allocate virtual DMA buffer
+ * @substream: the substream to allocate the buffer to
+ * @size: the requested buffer size, in bytes
+ *
+ * Allocates the PCM substream buffer using vmalloc(), i.e., the memory is
+ * contiguous in kernel virtual space, but not in physical memory.  Use this
+ * if the buffer is accessed by kernel code but not by device DMA.
+ *
+ * Returns 1 if the buffer was changed, 0 if not changed, or a negative error
+ * code.
+ */
+static int snd_pcm_lib_alloc_vmalloc_buffer
+                       (struct snd_pcm_substream *substream, size_t size);
+/**
+ * snd_pcm_lib_alloc_vmalloc_32_buffer - allocate 32-bit-addressable buffer
+ * @substream: the substream to allocate the buffer to
+ * @size: the requested buffer size, in bytes
+ *
+ * This function works like snd_pcm_lib_alloc_vmalloc_buffer(), but uses
+ * vmalloc_32(), i.e., the pages are allocated from 32-bit-addressable memory.
+ */
+static int snd_pcm_lib_alloc_vmalloc_32_buffer
+                       (struct snd_pcm_substream *substream, size_t size);
+#endif
+#define snd_pcm_lib_alloc_vmalloc_buffer(subs, size) \
+       _snd_pcm_lib_alloc_vmalloc_buffer \
+                       (subs, size, GFP_KERNEL | __GFP_HIGHMEM | __GFP_ZERO)
+#define snd_pcm_lib_alloc_vmalloc_32_buffer(subs, size) \
+       _snd_pcm_lib_alloc_vmalloc_buffer \
+                       (subs, size, GFP_KERNEL | GFP_DMA32 | __GFP_ZERO)
+
 #ifdef CONFIG_SND_DMA_SGBUF
 /*
  * SG-buffer handling
index 4e62ee1..9535354 100644 (file)
@@ -33,6 +33,7 @@ enum sb_hw_type {
        SB_HW_20,
        SB_HW_201,
        SB_HW_PRO,
+       SB_HW_JAZZ16,           /* Media Vision Jazz16 */
        SB_HW_16,
        SB_HW_16CSP,            /* SB16 with CSP chip */
        SB_HW_ALS100,           /* Avance Logic ALS100 chip */
index 5417f7d..7200195 100644 (file)
@@ -763,10 +763,13 @@ int snd_interval_ratnum(struct snd_interval *i,
                        unsigned int rats_count, struct snd_ratnum *rats,
                        unsigned int *nump, unsigned int *denp)
 {
-       unsigned int best_num, best_diff, best_den;
+       unsigned int best_num, best_den;
+       int best_diff;
        unsigned int k;
        struct snd_interval t;
        int err;
+       unsigned int result_num, result_den;
+       int result_diff;
 
        best_num = best_den = best_diff = 0;
        for (k = 0; k < rats_count; ++k) {
@@ -788,6 +791,8 @@ int snd_interval_ratnum(struct snd_interval *i,
                                den -= r;
                }
                diff = num - q * den;
+               if (diff < 0)
+                       diff = -diff;
                if (best_num == 0 ||
                    diff * best_den < best_diff * den) {
                        best_diff = diff;
@@ -802,6 +807,9 @@ int snd_interval_ratnum(struct snd_interval *i,
        t.min = div_down(best_num, best_den);
        t.openmin = !!(best_num % best_den);
        
+       result_num = best_num;
+       result_diff = best_diff;
+       result_den = best_den;
        best_num = best_den = best_diff = 0;
        for (k = 0; k < rats_count; ++k) {
                unsigned int num = rats[k].num;
@@ -824,6 +832,8 @@ int snd_interval_ratnum(struct snd_interval *i,
                                den += rats[k].den_step - r;
                }
                diff = q * den - num;
+               if (diff < 0)
+                       diff = -diff;
                if (best_num == 0 ||
                    diff * best_den < best_diff * den) {
                        best_diff = diff;
@@ -843,10 +853,14 @@ int snd_interval_ratnum(struct snd_interval *i,
                return err;
 
        if (snd_interval_single(i)) {
+               if (best_diff * result_den < result_diff * best_den) {
+                       result_num = best_num;
+                       result_den = best_den;
+               }
                if (nump)
-                       *nump = best_num;
+                       *nump = result_num;
                if (denp)
-                       *denp = best_den;
+                       *denp = result_den;
        }
        return err;
 }
index caa7796..d6d49d6 100644 (file)
@@ -23,6 +23,7 @@
 #include <linux/time.h>
 #include <linux/init.h>
 #include <linux/moduleparam.h>
+#include <linux/vmalloc.h>
 #include <sound/core.h>
 #include <sound/pcm.h>
 #include <sound/info.h>
@@ -434,3 +435,57 @@ int snd_pcm_lib_free_pages(struct snd_pcm_substream *substream)
 }
 
 EXPORT_SYMBOL(snd_pcm_lib_free_pages);
+
+int _snd_pcm_lib_alloc_vmalloc_buffer(struct snd_pcm_substream *substream,
+                                     size_t size, gfp_t gfp_flags)
+{
+       struct snd_pcm_runtime *runtime;
+
+       if (PCM_RUNTIME_CHECK(substream))
+               return -EINVAL;
+       runtime = substream->runtime;
+       if (runtime->dma_area) {
+               if (runtime->dma_bytes >= size)
+                       return 0; /* already large enough */
+               vfree(runtime->dma_area);
+       }
+       runtime->dma_area = __vmalloc(size, gfp_flags, PAGE_KERNEL);
+       if (!runtime->dma_area)
+               return -ENOMEM;
+       runtime->dma_bytes = size;
+       return 1;
+}
+EXPORT_SYMBOL(_snd_pcm_lib_alloc_vmalloc_buffer);
+
+/**
+ * snd_pcm_lib_free_vmalloc_buffer - free vmalloc buffer
+ * @substream: the substream with a buffer allocated by
+ *     snd_pcm_lib_alloc_vmalloc_buffer()
+ */
+int snd_pcm_lib_free_vmalloc_buffer(struct snd_pcm_substream *substream)
+{
+       struct snd_pcm_runtime *runtime;
+
+       if (PCM_RUNTIME_CHECK(substream))
+               return -EINVAL;
+       runtime = substream->runtime;
+       vfree(runtime->dma_area);
+       runtime->dma_area = NULL;
+       return 0;
+}
+EXPORT_SYMBOL(snd_pcm_lib_free_vmalloc_buffer);
+
+/**
+ * snd_pcm_lib_get_vmalloc_page - map vmalloc buffer offset to page struct
+ * @substream: the substream with a buffer allocated by
+ *     snd_pcm_lib_alloc_vmalloc_buffer()
+ * @offset: offset in the buffer
+ *
+ * This function is to be used as the page callback in the PCM ops.
+ */
+struct page *snd_pcm_lib_get_vmalloc_page(struct snd_pcm_substream *substream,
+                                         unsigned long offset)
+{
+       return vmalloc_to_page(substream->runtime->dma_area + offset);
+}
+EXPORT_SYMBOL(snd_pcm_lib_get_vmalloc_page);
index 27284f6..a870fe6 100644 (file)
@@ -1918,13 +1918,13 @@ int snd_pcm_hw_constraints_complete(struct snd_pcm_substream *substream)
 
        err = snd_pcm_hw_constraint_minmax(runtime, SNDRV_PCM_HW_PARAM_RATE,
                                           hw->rate_min, hw->rate_max);
-        if (err < 0)
-                return err;
+       if (err < 0)
+               return err;
 
        err = snd_pcm_hw_constraint_minmax(runtime, SNDRV_PCM_HW_PARAM_PERIOD_BYTES,
                                           hw->period_bytes_min, hw->period_bytes_max);
-        if (err < 0)
-                return err;
+       if (err < 0)
+               return err;
 
        err = snd_pcm_hw_constraint_minmax(runtime, SNDRV_PCM_HW_PARAM_PERIODS,
                                           hw->periods_min, hw->periods_max);
index 6644d00..c8385d2 100644 (file)
@@ -46,7 +46,6 @@
  */
 
 #include <linux/slab.h>
-#include <linux/vmalloc.h>
 #include <linux/delay.h>
 #include <sound/core.h>
 #include <sound/asoundef.h>
 
 
 /*
- * we use a vmalloc'ed (sg-)buffer
- */
-
-/* get the physical page pointer on the given offset */
-static struct page *snd_pcm_get_vmalloc_page(struct snd_pcm_substream *subs,
-                                            unsigned long offset)
-{
-       void *pageptr = subs->runtime->dma_area + offset;
-       return vmalloc_to_page(pageptr);
-}
-
-/*
- * allocate a buffer via vmalloc_32().
- * called from hw_params
- * NOTE: this may be called not only once per pcm open!
- */
-static int snd_pcm_alloc_vmalloc_buffer(struct snd_pcm_substream *subs, size_t size)
-{
-       struct snd_pcm_runtime *runtime = subs->runtime;
-       if (runtime->dma_area) {
-               /* already allocated */
-               if (runtime->dma_bytes >= size)
-                       return 0; /* already enough large */
-               vfree(runtime->dma_area);
-       }
-       runtime->dma_area = vmalloc_32(size);
-       if (! runtime->dma_area)
-               return -ENOMEM;
-       memset(runtime->dma_area, 0, size);
-       runtime->dma_bytes = size;
-       return 1; /* changed */
-}
-
-/*
- * free the buffer.
- * called from hw_free callback
- * NOTE: this may be called not only once per pcm open!
- */
-static int snd_pcm_free_vmalloc_buffer(struct snd_pcm_substream *subs)
-{
-       struct snd_pcm_runtime *runtime = subs->runtime;
-
-       vfree(runtime->dma_area);
-       runtime->dma_area = NULL;
-       return 0;
-}
-
-
-/*
  * read three pending pcm bytes via inb()
  */
 static void vx_pcm_read_per_bytes(struct vx_core *chip, struct snd_pcm_runtime *runtime,
@@ -865,7 +815,8 @@ static snd_pcm_uframes_t vx_pcm_playback_pointer(struct snd_pcm_substream *subs)
 static int vx_pcm_hw_params(struct snd_pcm_substream *subs,
                                     struct snd_pcm_hw_params *hw_params)
 {
-       return snd_pcm_alloc_vmalloc_buffer(subs, params_buffer_bytes(hw_params));
+       return snd_pcm_lib_alloc_vmalloc_32_buffer
+                                       (subs, params_buffer_bytes(hw_params));
 }
 
 /*
@@ -873,7 +824,7 @@ static int vx_pcm_hw_params(struct snd_pcm_substream *subs,
  */
 static int vx_pcm_hw_free(struct snd_pcm_substream *subs)
 {
-       return snd_pcm_free_vmalloc_buffer(subs);
+       return snd_pcm_lib_free_vmalloc_buffer(subs);
 }
 
 /*
@@ -953,7 +904,7 @@ static struct snd_pcm_ops vx_pcm_playback_ops = {
        .prepare =      vx_pcm_prepare,
        .trigger =      vx_pcm_trigger,
        .pointer =      vx_pcm_playback_pointer,
-       .page =         snd_pcm_get_vmalloc_page,
+       .page =         snd_pcm_lib_get_vmalloc_page,
 };
 
 
@@ -1173,7 +1124,7 @@ static struct snd_pcm_ops vx_pcm_capture_ops = {
        .prepare =      vx_pcm_prepare,
        .trigger =      vx_pcm_trigger,
        .pointer =      vx_pcm_capture_pointer,
-       .page =         snd_pcm_get_vmalloc_page,
+       .page =         snd_pcm_lib_get_vmalloc_page,
 };
 
 
index 02fe81c..755a0a5 100644 (file)
@@ -63,15 +63,16 @@ config SND_AD1848
          will be called snd-ad1848.
 
 config SND_ALS100
-       tristate "Avance Logic ALS100/ALS120"
+       tristate "Diamond Tech. DT-019x and Avance Logic ALSxxx"
        depends on PNP
        select ISAPNP
        select SND_OPL3_LIB
        select SND_MPU401_UART
        select SND_SB16_DSP
        help
-         Say Y here to include support for soundcards based on Avance
-         Logic ALS100, ALS110, ALS120 and ALS200 chips.
+         Say Y here to include support for soundcards based on the
+         Diamond Technologies DT-019X or Avance Logic chips: ALS007,
+         ALS100, ALS110, ALS120 and ALS200 chips.
 
          To compile this driver as a module, choose M here: the module
          will be called snd-als100.
@@ -127,20 +128,6 @@ config SND_CS4236
          To compile this driver as a module, choose M here: the module
          will be called snd-cs4236.
 
-config SND_DT019X
-       tristate "Diamond Technologies DT-019X, Avance Logic ALS-007"
-       depends on PNP
-       select ISAPNP
-       select SND_OPL3_LIB
-       select SND_MPU401_UART
-       select SND_SB16_DSP
-       help
-         Say Y here to include support for soundcards based on the
-         Diamond Technologies DT-019X or Avance Logic ALS-007 chips.
-
-         To compile this driver as a module, choose M here: the module
-         will be called snd-dt019x.
-
 config SND_ES968
        tristate "Generic ESS ES968 driver"
        depends on PNP
@@ -252,6 +239,22 @@ config SND_INTERWAVE_STB
          To compile this driver as a module, choose M here: the module
          will be called snd-interwave-stb.
 
+config SND_JAZZ16
+       tristate "Media Vision Jazz16 card and compatibles"
+       select SND_OPL3_LIB
+       select SND_MPU401_UART
+       select SND_SB8_DSP
+       help
+         Say Y here to include support for soundcards based on the
+         Media Vision Jazz16 chipset: digital chip MVD1216 (Jazz16),
+         codec MVA416 (CS4216) and mixer MVA514 (ICS2514).
+         Media Vision's Jazz16 cards were sold under names Pro Sonic 16,
+         Premium 3-D and Pro 3-D. There were also OEMs cards with the
+         Jazz16 chipset.
+
+         To compile this driver as a module, choose M here: the module
+         will be called snd-jazz16.
+
 config SND_OPL3SA2
        tristate "Yamaha OPL3-SA2/SA3"
        select SND_OPL3_LIB
index b906b9a..c73d30c 100644 (file)
@@ -7,7 +7,6 @@ snd-adlib-objs := adlib.o
 snd-als100-objs := als100.o
 snd-azt2320-objs := azt2320.o
 snd-cmi8330-objs := cmi8330.o
-snd-dt019x-objs := dt019x.o
 snd-es18xx-objs := es18xx.o
 snd-opl3sa2-objs := opl3sa2.o
 snd-sc6000-objs := sc6000.o
@@ -19,7 +18,6 @@ obj-$(CONFIG_SND_ADLIB) += snd-adlib.o
 obj-$(CONFIG_SND_ALS100) += snd-als100.o
 obj-$(CONFIG_SND_AZT2320) += snd-azt2320.o
 obj-$(CONFIG_SND_CMI8330) += snd-cmi8330.o
-obj-$(CONFIG_SND_DT019X) += snd-dt019x.o
 obj-$(CONFIG_SND_ES18XX) += snd-es18xx.o
 obj-$(CONFIG_SND_OPL3SA2) += snd-opl3sa2.o
 obj-$(CONFIG_SND_SC6000) += snd-sc6000.o
index 5fd52e4..20becc8 100644 (file)
@@ -2,9 +2,13 @@
 /*
     card-als100.c - driver for Avance Logic ALS100 based soundcards.
     Copyright (C) 1999-2000 by Massimo Piccioni <dafastidio@libero.it>
+    Copyright (C) 1999-2002 by Massimo Piccioni <dafastidio@libero.it>
 
     Thanks to Pierfrancesco 'qM2' Passerini.
 
+    Generalised for soundcards based on DT-0196 and ALS-007 chips
+    by Jonathan Woithe <jwoithe@physics.adelaide.edu.au>: June 2002.
+
     This program is free software; you can redistribute it and/or modify
     it under the terms of the GNU General Public License as published by
     the Free Software Foundation; either version 2 of the License, or
 
 #define PFX "als100: "
 
-MODULE_AUTHOR("Massimo Piccioni <dafastidio@libero.it>");
-MODULE_DESCRIPTION("Avance Logic ALS1X0");
-MODULE_LICENSE("GPL");
-MODULE_SUPPORTED_DEVICE("{{Avance Logic,ALS100 - PRO16PNP},"
+MODULE_DESCRIPTION("Avance Logic ALS007/ALS1X0");
+MODULE_SUPPORTED_DEVICE("{{Diamond Technologies DT-019X},"
+               "{Avance Logic ALS-007}}"
+               "{{Avance Logic,ALS100 - PRO16PNP},"
                "{Avance Logic,ALS110},"
                "{Avance Logic,ALS120},"
                "{Avance Logic,ALS200},"
@@ -45,9 +49,12 @@ MODULE_SUPPORTED_DEVICE("{{Avance Logic,ALS100 - PRO16PNP},"
                "{Avance Logic,ALS120},"
                "{RTL,RTL3000}}");
 
+MODULE_AUTHOR("Massimo Piccioni <dafastidio@libero.it>");
+MODULE_LICENSE("GPL");
+
 static int index[SNDRV_CARDS] = SNDRV_DEFAULT_IDX;     /* Index 0-MAX */
 static char *id[SNDRV_CARDS] = SNDRV_DEFAULT_STR;      /* ID for this card */
-static int enable[SNDRV_CARDS] = SNDRV_DEFAULT_ENABLE_ISAPNP; /* Enable this card */
+static int enable[SNDRV_CARDS] = SNDRV_DEFAULT_ENABLE; /* Enable this card */
 static long port[SNDRV_CARDS] = SNDRV_DEFAULT_PORT;    /* PnP setup */
 static long mpu_port[SNDRV_CARDS] = SNDRV_DEFAULT_PORT;        /* PnP setup */
 static long fm_port[SNDRV_CARDS] = SNDRV_DEFAULT_PORT; /* PnP setup */
@@ -57,14 +64,15 @@ static int dma8[SNDRV_CARDS] = SNDRV_DEFAULT_DMA;   /* PnP setup */
 static int dma16[SNDRV_CARDS] = SNDRV_DEFAULT_DMA;     /* PnP setup */
 
 module_param_array(index, int, NULL, 0444);
-MODULE_PARM_DESC(index, "Index value for als100 based soundcard.");
+MODULE_PARM_DESC(index, "Index value for Avance Logic based soundcard.");
 module_param_array(id, charp, NULL, 0444);
-MODULE_PARM_DESC(id, "ID string for als100 based soundcard.");
+MODULE_PARM_DESC(id, "ID string for Avance Logic based soundcard.");
 module_param_array(enable, bool, NULL, 0444);
-MODULE_PARM_DESC(enable, "Enable als100 based soundcard.");
+MODULE_PARM_DESC(enable, "Enable Avance Logic based soundcard.");
+
+MODULE_ALIAS("snd-dt019x");
 
 struct snd_card_als100 {
-       int dev_no;
        struct pnp_dev *dev;
        struct pnp_dev *devmpu;
        struct pnp_dev *devopl;
@@ -72,25 +80,43 @@ struct snd_card_als100 {
 };
 
 static struct pnp_card_device_id snd_als100_pnpids[] = {
+       /* DT197A30 */
+       { .id = "RWB1688",
+         .devs = { { "@@@0001" }, { "@X@0001" }, { "@H@0001" } },
+         .driver_data = SB_HW_DT019X },
+       /* DT0196 / ALS-007 */
+       { .id = "ALS0007",
+         .devs = { { "@@@0001" }, { "@X@0001" }, { "@H@0001" } },
+         .driver_data = SB_HW_DT019X },
        /* ALS100 - PRO16PNP */
-       { .id = "ALS0001", .devs = { { "@@@0001" }, { "@X@0001" }, { "@H@0001" } } },
+       { .id = "ALS0001",
+         .devs = { { "@@@0001" }, { "@X@0001" }, { "@H@0001" } },
+         .driver_data = SB_HW_ALS100 },
        /* ALS110 - MF1000 - Digimate 3D Sound */
-       { .id = "ALS0110", .devs = { { "@@@1001" }, { "@X@1001" }, { "@H@1001" } } },
+       { .id = "ALS0110",
+         .devs = { { "@@@1001" }, { "@X@1001" }, { "@H@1001" } },
+         .driver_data = SB_HW_ALS100 },
        /* ALS120 */
-       { .id = "ALS0120", .devs = { { "@@@2001" }, { "@X@2001" }, { "@H@2001" } } },
+       { .id = "ALS0120",
+         .devs = { { "@@@2001" }, { "@X@2001" }, { "@H@2001" } },
+         .driver_data = SB_HW_ALS100 },
        /* ALS200 */
-       { .id = "ALS0200", .devs = { { "@@@0020" }, { "@X@0020" }, { "@H@0001" } } },
+       { .id = "ALS0200",
+         .devs = { { "@@@0020" }, { "@X@0020" }, { "@H@0001" } },
+         .driver_data = SB_HW_ALS100 },
        /* ALS200 OEM */
-       { .id = "ALS0200", .devs = { { "@@@0020" }, { "@X@0020" }, { "@H@0020" } } },
+       { .id = "ALS0200",
+         .devs = { { "@@@0020" }, { "@X@0020" }, { "@H@0020" } },
+         .driver_data = SB_HW_ALS100 },
        /* RTL3000 */
-       { .id = "RTL3000", .devs = { { "@@@2001" }, { "@X@2001" }, { "@H@2001" } } },
-       { .id = "", } /* end */
+       { .id = "RTL3000",
+         .devs = { { "@@@2001" }, { "@X@2001" }, { "@H@2001" } },
+         .driver_data = SB_HW_ALS100 },
+       { .id = "" } /* end */
 };
 
 MODULE_DEVICE_TABLE(pnp_card, snd_als100_pnpids);
 
-#define DRIVER_NAME    "snd-card-als100"
-
 static int __devinit snd_card_als100_pnp(int dev, struct snd_card_als100 *acard,
                                         struct pnp_card_link *card,
                                         const struct pnp_card_device_id *id)
@@ -113,8 +139,12 @@ static int __devinit snd_card_als100_pnp(int dev, struct snd_card_als100 *acard,
                return err;
        }
        port[dev] = pnp_port_start(pdev, 0);
-       dma8[dev] = pnp_dma(pdev, 1);
-       dma16[dev] = pnp_dma(pdev, 0);
+       if (id->driver_data == SB_HW_DT019X)
+               dma8[dev] = pnp_dma(pdev, 0);
+       else {
+               dma8[dev] = pnp_dma(pdev, 1);
+               dma16[dev] = pnp_dma(pdev, 0);
+       }
        irq[dev] = pnp_irq(pdev, 0);
 
        pdev = acard->devmpu;
@@ -175,22 +205,33 @@ static int __devinit snd_card_als100_probe(int dev,
        }
        snd_card_set_dev(card, &pcard->card->dev);
 
-       if ((error = snd_sbdsp_create(card, port[dev],
-                                     irq[dev],
-                                     snd_sb16dsp_interrupt,
-                                     dma8[dev],
-                                     dma16[dev],
-                                     SB_HW_ALS100, &chip)) < 0) {
+       if (pid->driver_data == SB_HW_DT019X)
+               dma16[dev] = -1;
+
+       error = snd_sbdsp_create(card, port[dev], irq[dev],
+                                 snd_sb16dsp_interrupt,
+                                 dma8[dev], dma16[dev],
+                                 pid->driver_data,
+                                 &chip);
+       if (error < 0) {
                snd_card_free(card);
                return error;
        }
        acard->chip = chip;
 
-       strcpy(card->driver, "ALS100");
-       strcpy(card->shortname, "Avance Logic ALS100");
-       sprintf(card->longname, "%s, %s at 0x%lx, irq %d, dma %d&%d",
-               card->shortname, chip->name, chip->port,
-               irq[dev], dma8[dev], dma16[dev]);
+       if (pid->driver_data == SB_HW_DT019X) {
+               strcpy(card->driver, "DT-019X");
+               strcpy(card->shortname, "Diamond Tech. DT-019X");
+               sprintf(card->longname, "%s, %s at 0x%lx, irq %d, dma %d",
+                       card->shortname, chip->name, chip->port,
+                       irq[dev], dma8[dev]);
+       } else {
+               strcpy(card->driver, "ALS100");
+               strcpy(card->shortname, "Avance Logic ALS100");
+               sprintf(card->longname, "%s, %s at 0x%lx, irq %d, dma %d&%d",
+                       card->shortname, chip->name, chip->port,
+                       irq[dev], dma8[dev], dma16[dev]);
+       }
 
        if ((error = snd_sb16dsp_pcm(chip, 0, NULL)) < 0) {
                snd_card_free(card);
@@ -203,9 +244,19 @@ static int __devinit snd_card_als100_probe(int dev,
        }
 
        if (mpu_port[dev] > 0 && mpu_port[dev] != SNDRV_AUTO_PORT) {
-               if (snd_mpu401_uart_new(card, 0, MPU401_HW_ALS100,
+               int mpu_type = MPU401_HW_ALS100;
+
+               if (mpu_irq[dev] == SNDRV_AUTO_IRQ)
+                       mpu_irq[dev] = -1;
+
+               if (pid->driver_data == SB_HW_DT019X)
+                       mpu_type = MPU401_HW_MPU401;
+
+               if (snd_mpu401_uart_new(card, 0,
+                                       mpu_type,
                                        mpu_port[dev], 0, 
-                                       mpu_irq[dev], IRQF_DISABLED,
+                                       mpu_irq[dev],
+                                       mpu_irq[dev] >= 0 ? IRQF_DISABLED : 0,
                                        NULL) < 0)
                        snd_printk(KERN_ERR PFX "no MPU-401 device at 0x%lx\n", mpu_port[dev]);
        }
@@ -291,7 +342,7 @@ static int snd_als100_pnp_resume(struct pnp_card_link *pcard)
 
 static struct pnp_card_driver als100_pnpc_driver = {
        .flags          = PNP_DRIVER_RES_DISABLE,
-        .name           = "als100",
+       .name           = "als100",
         .id_table       = snd_als100_pnpids,
         .probe          = snd_als100_pnp_detect,
         .remove         = __devexit_p(snd_als100_pnp_remove),
@@ -312,7 +363,7 @@ static int __init alsa_card_als100_init(void)
        if (!als100_devices) {
                pnp_unregister_card_driver(&als100_pnpc_driver);
 #ifdef MODULE
-               snd_printk(KERN_ERR "no ALS100 based soundcards found\n");
+               snd_printk(KERN_ERR "no Avance Logic based soundcards found\n");
 #endif
                return -ENODEV;
        }
diff --git a/sound/isa/dt019x.c b/sound/isa/dt019x.c
deleted file mode 100644 (file)
index 80f5b1a..0000000
+++ /dev/null
@@ -1,321 +0,0 @@
-
-/*
-    dt019x.c - driver for Diamond Technologies DT-0197H based soundcards.
-    Copyright (C) 1999, 2002 by Massimo Piccioni <dafastidio@libero.it>
-
-    Generalised for soundcards based on DT-0196 and ALS-007 chips 
-    by Jonathan Woithe <jwoithe@physics.adelaide.edu.au>: June 2002.
-
-    This program is free software; you can redistribute it and/or modify
-    it under the terms of the GNU General Public License as published by
-    the Free Software Foundation; either version 2 of the License, or
-    (at your option) any later version.
-
-    This program is distributed in the hope that it will be useful,
-    but WITHOUT ANY WARRANTY; without even the implied warranty of
-    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
-    GNU General Public License for more details.
-
-    You should have received a copy of the GNU General Public License
-    along with this program; if not, write to the Free Software
-    Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
-*/
-
-#include <linux/init.h>
-#include <linux/wait.h>
-#include <linux/pnp.h>
-#include <linux/moduleparam.h>
-#include <sound/core.h>
-#include <sound/initval.h>
-#include <sound/mpu401.h>
-#include <sound/opl3.h>
-#include <sound/sb.h>
-
-#define PFX "dt019x: "
-
-MODULE_AUTHOR("Massimo Piccioni <dafastidio@libero.it>");
-MODULE_DESCRIPTION("Diamond Technologies DT-019X / Avance Logic ALS-007");
-MODULE_LICENSE("GPL");
-MODULE_SUPPORTED_DEVICE("{{Diamond Technologies DT-019X},"
-              "{Avance Logic ALS-007}}");
-
-static int index[SNDRV_CARDS] = SNDRV_DEFAULT_IDX;     /* Index 0-MAX */
-static char *id[SNDRV_CARDS] = SNDRV_DEFAULT_STR;      /* ID for this card */
-static int enable[SNDRV_CARDS] = SNDRV_DEFAULT_ENABLE; /* Enable this card */
-static long port[SNDRV_CARDS] = SNDRV_DEFAULT_PORT;    /* PnP setup */
-static long mpu_port[SNDRV_CARDS] = SNDRV_DEFAULT_PORT;        /* PnP setup */
-static long fm_port[SNDRV_CARDS] = SNDRV_DEFAULT_PORT; /* PnP setup */
-static int irq[SNDRV_CARDS] = SNDRV_DEFAULT_IRQ;       /* PnP setup */
-static int mpu_irq[SNDRV_CARDS] = SNDRV_DEFAULT_IRQ;   /* PnP setup */
-static int dma8[SNDRV_CARDS] = SNDRV_DEFAULT_DMA;      /* PnP setup */
-
-module_param_array(index, int, NULL, 0444);
-MODULE_PARM_DESC(index, "Index value for DT-019X based soundcard.");
-module_param_array(id, charp, NULL, 0444);
-MODULE_PARM_DESC(id, "ID string for DT-019X based soundcard.");
-module_param_array(enable, bool, NULL, 0444);
-MODULE_PARM_DESC(enable, "Enable DT-019X based soundcard.");
-
-struct snd_card_dt019x {
-       struct pnp_dev *dev;
-       struct pnp_dev *devmpu;
-       struct pnp_dev *devopl;
-       struct snd_sb *chip;
-};
-
-static struct pnp_card_device_id snd_dt019x_pnpids[] = {
-       /* DT197A30 */
-       { .id = "RWB1688", .devs = { { "@@@0001" }, { "@X@0001" }, { "@H@0001" }, } },
-       /* DT0196 / ALS-007 */
-       { .id = "ALS0007", .devs = { { "@@@0001" }, { "@X@0001" }, { "@H@0001" }, } },
-       { .id = "",  }
-};
-
-MODULE_DEVICE_TABLE(pnp_card, snd_dt019x_pnpids);
-
-
-#define DRIVER_NAME    "snd-card-dt019x"
-
-
-static int __devinit snd_card_dt019x_pnp(int dev, struct snd_card_dt019x *acard,
-                                        struct pnp_card_link *card,
-                                        const struct pnp_card_device_id *pid)
-{
-       struct pnp_dev *pdev;
-       int err;
-
-       acard->dev = pnp_request_card_device(card, pid->devs[0].id, NULL);
-       if (acard->dev == NULL)
-               return -ENODEV;
-
-       acard->devmpu = pnp_request_card_device(card, pid->devs[1].id, NULL);
-       acard->devopl = pnp_request_card_device(card, pid->devs[2].id, NULL);
-
-       pdev = acard->dev;
-
-       err = pnp_activate_dev(pdev);
-       if (err < 0) {
-               snd_printk(KERN_ERR PFX "DT-019X AUDIO pnp configure failure\n");
-               return err;
-       }
-
-       port[dev] = pnp_port_start(pdev, 0);
-       dma8[dev] = pnp_dma(pdev, 0);
-       irq[dev] = pnp_irq(pdev, 0);
-       snd_printdd("dt019x: found audio interface: port=0x%lx, irq=0x%x, dma=0x%x\n",
-                       port[dev],irq[dev],dma8[dev]);
-
-       pdev = acard->devmpu;
-       if (pdev != NULL) {
-               err = pnp_activate_dev(pdev);
-               if (err < 0) {
-                       pnp_release_card_device(pdev);
-                       snd_printk(KERN_ERR PFX "DT-019X MPU401 pnp configure failure, skipping\n");
-                       goto __mpu_error;
-               }
-               mpu_port[dev] = pnp_port_start(pdev, 0);
-               mpu_irq[dev] = pnp_irq(pdev, 0);
-               snd_printdd("dt019x: found MPU-401: port=0x%lx, irq=0x%x\n",
-                               mpu_port[dev],mpu_irq[dev]);
-       } else {
-       __mpu_error:
-               acard->devmpu = NULL;
-               mpu_port[dev] = -1;
-       }
-
-       pdev = acard->devopl;
-       if (pdev != NULL) {
-               err = pnp_activate_dev(pdev);
-               if (err < 0) {
-                       pnp_release_card_device(pdev);
-                       snd_printk(KERN_ERR PFX "DT-019X OPL3 pnp configure failure, skipping\n");
-                       goto __fm_error;
-               }
-               fm_port[dev] = pnp_port_start(pdev, 0);
-               snd_printdd("dt019x: found OPL3 synth: port=0x%lx\n",fm_port[dev]);
-       } else {
-       __fm_error:
-               acard->devopl = NULL;
-               fm_port[dev] = -1;
-       }
-
-       return 0;
-}
-
-static int __devinit snd_card_dt019x_probe(int dev, struct pnp_card_link *pcard, const struct pnp_card_device_id *pid)
-{
-       int error;
-       struct snd_sb *chip;
-       struct snd_card *card;
-       struct snd_card_dt019x *acard;
-       struct snd_opl3 *opl3;
-
-       error = snd_card_create(index[dev], id[dev], THIS_MODULE,
-                               sizeof(struct snd_card_dt019x), &card);
-       if (error < 0)
-               return error;
-       acard = card->private_data;
-
-       snd_card_set_dev(card, &pcard->card->dev);
-       if ((error = snd_card_dt019x_pnp(dev, acard, pcard, pid))) {
-               snd_card_free(card);
-               return error;
-       }
-
-       if ((error = snd_sbdsp_create(card, port[dev],
-                                     irq[dev],
-                                     snd_sb16dsp_interrupt,
-                                     dma8[dev],
-                                     -1,
-                                     SB_HW_DT019X,
-                                     &chip)) < 0) {
-               snd_card_free(card);
-               return error;
-       }
-       acard->chip = chip;
-
-       strcpy(card->driver, "DT-019X");
-       strcpy(card->shortname, "Diamond Tech. DT-019X");
-       sprintf(card->longname, "%s, %s at 0x%lx, irq %d, dma %d",
-               card->shortname, chip->name, chip->port,
-               irq[dev], dma8[dev]);
-
-       if ((error = snd_sb16dsp_pcm(chip, 0, NULL)) < 0) {
-               snd_card_free(card);
-               return error;
-       }
-       if ((error = snd_sbmixer_new(chip)) < 0) {
-               snd_card_free(card);
-               return error;
-       }
-
-       if (mpu_port[dev] > 0 && mpu_port[dev] != SNDRV_AUTO_PORT) {
-               if (mpu_irq[dev] == SNDRV_AUTO_IRQ)
-                       mpu_irq[dev] = -1;
-               if (snd_mpu401_uart_new(card, 0,
-/*                                     MPU401_HW_SB,*/
-                                       MPU401_HW_MPU401,
-                                       mpu_port[dev], 0,
-                                       mpu_irq[dev],
-                                       mpu_irq[dev] >= 0 ? IRQF_DISABLED : 0,
-                                       NULL) < 0)
-                       snd_printk(KERN_ERR PFX "no MPU-401 device at 0x%lx ?\n", mpu_port[dev]);
-       }
-
-       if (fm_port[dev] > 0 && fm_port[dev] != SNDRV_AUTO_PORT) {
-               if (snd_opl3_create(card,
-                                   fm_port[dev],
-                                   fm_port[dev] + 2,
-                                   OPL3_HW_AUTO, 0, &opl3) < 0) {
-                       snd_printk(KERN_ERR PFX "no OPL device at 0x%lx-0x%lx ?\n",
-                                  fm_port[dev], fm_port[dev] + 2);
-               } else {
-                       if ((error = snd_opl3_timer_new(opl3, 0, 1)) < 0) {
-                               snd_card_free(card);
-                               return error;
-                       }
-                       if ((error = snd_opl3_hwdep_new(opl3, 0, 1, NULL)) < 0) {
-                               snd_card_free(card);
-                               return error;
-                       }
-               }
-       }
-
-       if ((error = snd_card_register(card)) < 0) {
-               snd_card_free(card);
-               return error;
-       }
-       pnp_set_card_drvdata(pcard, card);
-       return 0;
-}
-
-static unsigned int __devinitdata dt019x_devices;
-
-static int __devinit snd_dt019x_pnp_probe(struct pnp_card_link *card,
-                                         const struct pnp_card_device_id *pid)
-{
-       static int dev;
-       int res;
-
-       for ( ; dev < SNDRV_CARDS; dev++) {
-               if (!enable[dev])
-                       continue;
-               res = snd_card_dt019x_probe(dev, card, pid);
-               if (res < 0)
-                       return res;
-               dev++;
-               dt019x_devices++;
-               return 0;
-       }
-       return -ENODEV;
-}
-
-static void __devexit snd_dt019x_pnp_remove(struct pnp_card_link * pcard)
-{
-       snd_card_free(pnp_get_card_drvdata(pcard));
-       pnp_set_card_drvdata(pcard, NULL);
-}
-
-#ifdef CONFIG_PM
-static int snd_dt019x_pnp_suspend(struct pnp_card_link *pcard, pm_message_t state)
-{
-       struct snd_card *card = pnp_get_card_drvdata(pcard);
-       struct snd_card_dt019x *acard = card->private_data;
-       struct snd_sb *chip = acard->chip;
-
-       snd_power_change_state(card, SNDRV_CTL_POWER_D3hot);
-       snd_pcm_suspend_all(chip->pcm);
-       snd_sbmixer_suspend(chip);
-       return 0;
-}
-
-static int snd_dt019x_pnp_resume(struct pnp_card_link *pcard)
-{
-       struct snd_card *card = pnp_get_card_drvdata(pcard);
-       struct snd_card_dt019x *acard = card->private_data;
-       struct snd_sb *chip = acard->chip;
-
-       snd_sbdsp_reset(chip);
-       snd_sbmixer_resume(chip);
-       snd_power_change_state(card, SNDRV_CTL_POWER_D0);
-       return 0;
-}
-#endif
-
-static struct pnp_card_driver dt019x_pnpc_driver = {
-       .flags          = PNP_DRIVER_RES_DISABLE,
-       .name           = "dt019x",
-       .id_table       = snd_dt019x_pnpids,
-       .probe          = snd_dt019x_pnp_probe,
-       .remove         = __devexit_p(snd_dt019x_pnp_remove),
-#ifdef CONFIG_PM
-       .suspend        = snd_dt019x_pnp_suspend,
-       .resume         = snd_dt019x_pnp_resume,
-#endif
-};
-
-static int __init alsa_card_dt019x_init(void)
-{
-       int err;
-
-       err = pnp_register_card_driver(&dt019x_pnpc_driver);
-       if (err)
-               return err;
-
-       if (!dt019x_devices) {
-               pnp_unregister_card_driver(&dt019x_pnpc_driver);
-#ifdef MODULE
-               snd_printk(KERN_ERR "no DT-019X / ALS-007 based soundcards found\n");
-#endif
-               return -ENODEV;
-       }
-       return 0;
-}
-
-static void __exit alsa_card_dt019x_exit(void)
-{
-       pnp_unregister_card_driver(&dt019x_pnpc_driver);
-}
-
-module_init(alsa_card_dt019x_init)
-module_exit(alsa_card_dt019x_exit)
index c8a8da0..a4af53b 100644 (file)
@@ -33,6 +33,7 @@
 #include <asm/io.h>
 #include <asm/dma.h>
 #include <sound/core.h>
+#include <sound/tlv.h>
 #include <sound/wss.h>
 #include <sound/mpu401.h>
 #include <sound/opl3.h>
@@ -546,6 +547,93 @@ __skip_mpu:
 
 #ifdef OPTi93X
 
+static const DECLARE_TLV_DB_SCALE(db_scale_5bit_3db_step, -9300, 300, 0);
+static const DECLARE_TLV_DB_SCALE(db_scale_5bit, -4650, 150, 0);
+static const DECLARE_TLV_DB_SCALE(db_scale_4bit_12db_max, -3300, 300, 0);
+
+static struct snd_kcontrol_new snd_opti93x_controls[] = {
+WSS_DOUBLE("Master Playback Switch", 0,
+               OPTi93X_OUT_LEFT, OPTi93X_OUT_RIGHT, 7, 7, 1, 1),
+WSS_DOUBLE_TLV("Master Playback Volume", 0,
+               OPTi93X_OUT_LEFT, OPTi93X_OUT_RIGHT, 1, 1, 31, 1,
+               db_scale_5bit_3db_step),
+WSS_DOUBLE_TLV("PCM Playback Volume", 0,
+               CS4231_LEFT_OUTPUT, CS4231_RIGHT_OUTPUT, 0, 0, 31, 1,
+               db_scale_5bit),
+WSS_DOUBLE_TLV("FM Playback Volume", 0,
+               CS4231_AUX2_LEFT_INPUT, CS4231_AUX2_RIGHT_INPUT, 1, 1, 15, 1,
+               db_scale_4bit_12db_max),
+WSS_DOUBLE("Line Playback Switch", 0,
+               CS4231_LEFT_LINE_IN, CS4231_RIGHT_LINE_IN, 7, 7, 1, 1),
+WSS_DOUBLE_TLV("Line Playback Volume", 0,
+               CS4231_LEFT_LINE_IN, CS4231_RIGHT_LINE_IN, 0, 0, 15, 1,
+               db_scale_4bit_12db_max),
+WSS_DOUBLE("Mic Playback Switch", 0,
+               OPTi93X_MIC_LEFT_INPUT, OPTi93X_MIC_RIGHT_INPUT, 7, 7, 1, 1),
+WSS_DOUBLE_TLV("Mic Playback Volume", 0,
+               OPTi93X_MIC_LEFT_INPUT, OPTi93X_MIC_RIGHT_INPUT, 1, 1, 15, 1,
+               db_scale_4bit_12db_max),
+WSS_DOUBLE_TLV("CD Playback Volume", 0,
+               CS4231_AUX1_LEFT_INPUT, CS4231_AUX1_RIGHT_INPUT, 1, 1, 15, 1,
+               db_scale_4bit_12db_max),
+WSS_DOUBLE("Aux Playback Switch", 0,
+               OPTi931_AUX_LEFT_INPUT, OPTi931_AUX_RIGHT_INPUT, 7, 7, 1, 1),
+WSS_DOUBLE_TLV("Aux Playback Volume", 0,
+               OPTi931_AUX_LEFT_INPUT, OPTi931_AUX_RIGHT_INPUT, 1, 1, 15, 1,
+               db_scale_4bit_12db_max),
+};
+
+static int __devinit snd_opti93x_mixer(struct snd_wss *chip)
+{
+       struct snd_card *card;
+       unsigned int idx;
+       struct snd_ctl_elem_id id1, id2;
+       int err;
+
+       if (snd_BUG_ON(!chip || !chip->pcm))
+               return -EINVAL;
+
+       card = chip->card;
+
+       strcpy(card->mixername, chip->pcm->name);
+
+       memset(&id1, 0, sizeof(id1));
+       memset(&id2, 0, sizeof(id2));
+       id1.iface = id2.iface = SNDRV_CTL_ELEM_IFACE_MIXER;
+       /* reassign AUX0 switch to CD */
+       strcpy(id1.name, "Aux Playback Switch");
+       strcpy(id2.name, "CD Playback Switch");
+       err = snd_ctl_rename_id(card, &id1, &id2);
+       if (err < 0) {
+               snd_printk(KERN_ERR "Cannot rename opti93x control\n");
+               return err;
+       }
+       /* reassign AUX1 switch to FM */
+       strcpy(id1.name, "Aux Playback Switch"); id1.index = 1;
+       strcpy(id2.name, "FM Playback Switch");
+       err = snd_ctl_rename_id(card, &id1, &id2);
+       if (err < 0) {
+               snd_printk(KERN_ERR "Cannot rename opti93x control\n");
+               return err;
+       }
+       /* remove AUX1 volume */
+       strcpy(id1.name, "Aux Playback Volume"); id1.index = 1;
+       snd_ctl_remove_id(card, &id1);
+
+       /* Replace WSS volume controls with OPTi93x volume controls */
+       id1.index = 0;
+       for (idx = 0; idx < ARRAY_SIZE(snd_opti93x_controls); idx++) {
+               strcpy(id1.name, snd_opti93x_controls[idx].name);
+               snd_ctl_remove_id(card, &id1);
+
+               err = snd_ctl_add(card,
+                               snd_ctl_new1(&snd_opti93x_controls[idx], chip));
+               if (err < 0)
+                       return err;
+       }
+       return 0;
+}
+
 static irqreturn_t snd_opti93x_interrupt(int irq, void *dev_id)
 {
        struct snd_opti9xx *chip = dev_id;
@@ -754,6 +842,11 @@ static int __devinit snd_opti9xx_probe(struct snd_card *card)
        error = snd_wss_mixer(codec);
        if (error < 0)
                return error;
+#ifdef OPTi93X
+       error = snd_opti93x_mixer(codec);
+       if (error < 0)
+               return error;
+#endif
 #ifdef CS4231
        error = snd_wss_timer(codec, 0, &timer);
        if (error < 0)
index faeffce..af36696 100644 (file)
@@ -12,6 +12,7 @@ snd-sb16-objs := sb16.o
 snd-sbawe-objs := sbawe.o emu8000.o
 snd-emu8000-synth-objs := emu8000_synth.o emu8000_callback.o emu8000_patch.o emu8000_pcm.o
 snd-es968-objs := es968.o
+snd-jazz16-objs := jazz16.o
 
 # Toplevel Module Dependency
 obj-$(CONFIG_SND_SB_COMMON) += snd-sb-common.o
@@ -21,6 +22,7 @@ obj-$(CONFIG_SND_SB8) += snd-sb8.o
 obj-$(CONFIG_SND_SB16) += snd-sb16.o
 obj-$(CONFIG_SND_SBAWE) += snd-sbawe.o
 obj-$(CONFIG_SND_ES968) += snd-es968.o
+obj-$(CONFIG_SND_JAZZ16) += snd-jazz16.o
 ifeq ($(CONFIG_SND_SB16_CSP),y)
   obj-$(CONFIG_SND_SB16) += snd-sb16-csp.o
   obj-$(CONFIG_SND_SBAWE) += snd-sb16-csp.o
diff --git a/sound/isa/sb/jazz16.c b/sound/isa/sb/jazz16.c
new file mode 100644 (file)
index 0000000..8d21a3f
--- /dev/null
@@ -0,0 +1,404 @@
+
+/*
+ * jazz16.c - driver for Media Vision Jazz16 based soundcards.
+ * Copyright (C) 2009 Krzysztof Helt <krzysztof.h1@wp.pl>
+ * Based on patches posted by Rask Ingemann Lambertsen and Rene Herman.
+ * Based on OSS Sound Blaster driver.
+ *
+ * This file is subject to the terms and conditions of the GNU General Public
+ * License.  See the file COPYING in the main directory of this archive for
+ * more details.
+ *
+ */
+
+#include <linux/init.h>
+#include <linux/module.h>
+#include <linux/io.h>
+#include <asm/dma.h>
+#include <linux/isa.h>
+#include <sound/core.h>
+#include <sound/mpu401.h>
+#include <sound/opl3.h>
+#include <sound/sb.h>
+#define SNDRV_LEGACY_FIND_FREE_IRQ
+#define SNDRV_LEGACY_FIND_FREE_DMA
+#include <sound/initval.h>
+
+#define PFX "jazz16: "
+
+MODULE_DESCRIPTION("Media Vision Jazz16");
+MODULE_SUPPORTED_DEVICE("{{Media Vision ??? },"
+               "{RTL,RTL3000}}");
+
+MODULE_AUTHOR("Krzysztof Helt <krzysztof.h1@wp.pl>");
+MODULE_LICENSE("GPL");
+
+static int index[SNDRV_CARDS] = SNDRV_DEFAULT_IDX;     /* Index 0-MAX */
+static char *id[SNDRV_CARDS] = SNDRV_DEFAULT_STR;      /* ID for this card */
+static int enable[SNDRV_CARDS] = SNDRV_DEFAULT_ENABLE; /* Enable this card */
+static unsigned long port[SNDRV_CARDS] = SNDRV_DEFAULT_PORT;
+static unsigned long mpu_port[SNDRV_CARDS] = SNDRV_DEFAULT_PORT;
+static int irq[SNDRV_CARDS] = SNDRV_DEFAULT_IRQ;
+static int mpu_irq[SNDRV_CARDS] = SNDRV_DEFAULT_IRQ;
+static int dma8[SNDRV_CARDS] = SNDRV_DEFAULT_DMA;
+static int dma16[SNDRV_CARDS] = SNDRV_DEFAULT_DMA;
+
+module_param_array(index, int, NULL, 0444);
+MODULE_PARM_DESC(index, "Index value for Media Vision Jazz16 based soundcard.");
+module_param_array(id, charp, NULL, 0444);
+MODULE_PARM_DESC(id, "ID string for Media Vision Jazz16 based soundcard.");
+module_param_array(enable, bool, NULL, 0444);
+MODULE_PARM_DESC(enable, "Enable Media Vision Jazz16 based soundcard.");
+module_param_array(port, long, NULL, 0444);
+MODULE_PARM_DESC(port, "Port # for jazz16 driver.");
+module_param_array(mpu_port, long, NULL, 0444);
+MODULE_PARM_DESC(mpu_port, "MPU-401 port # for jazz16 driver.");
+module_param_array(irq, int, NULL, 0444);
+MODULE_PARM_DESC(irq, "IRQ # for jazz16 driver.");
+module_param_array(mpu_irq, int, NULL, 0444);
+MODULE_PARM_DESC(mpu_irq, "MPU-401 IRQ # for jazz16 driver.");
+module_param_array(dma8, int, NULL, 0444);
+MODULE_PARM_DESC(dma8, "DMA8 # for jazz16 driver.");
+module_param_array(dma16, int, NULL, 0444);
+MODULE_PARM_DESC(dma16, "DMA16 # for jazz16 driver.");
+
+#define SB_JAZZ16_WAKEUP       0xaf
+#define SB_JAZZ16_SET_PORTS    0x50
+#define SB_DSP_GET_JAZZ_BRD_REV        0xfa
+#define SB_JAZZ16_SET_DMAINTR  0xfb
+#define SB_DSP_GET_JAZZ_MODEL  0xfe
+
+struct snd_card_jazz16 {
+       struct snd_sb *chip;
+};
+
+static irqreturn_t jazz16_interrupt(int irq, void *chip)
+{
+       return snd_sb8dsp_interrupt(chip);
+}
+
+static int __devinit jazz16_configure_ports(unsigned long port,
+                                           unsigned long mpu_port, int idx)
+{
+       unsigned char val;
+
+       if (!request_region(0x201, 1, "jazz16 config")) {
+               snd_printk(KERN_ERR "config port region is already in use.\n");
+               return -EBUSY;
+       }
+       outb(SB_JAZZ16_WAKEUP - idx, 0x201);
+       udelay(100);
+       outb(SB_JAZZ16_SET_PORTS + idx, 0x201);
+       udelay(100);
+       val = port & 0x70;
+       val |= (mpu_port & 0x30) >> 4;
+       outb(val, 0x201);
+
+       release_region(0x201, 1);
+       return 0;
+}
+
+static int __devinit jazz16_detect_board(unsigned long port,
+                                        unsigned long mpu_port)
+{
+       int err;
+       int val;
+       struct snd_sb chip;
+
+       if (!request_region(port, 0x10, "jazz16")) {
+               snd_printk(KERN_ERR "I/O port region is already in use.\n");
+               return -EBUSY;
+       }
+       /* just to call snd_sbdsp_command/reset/get_byte() */
+       chip.port = port;
+
+       err = snd_sbdsp_reset(&chip);
+       if (err < 0)
+               for (val = 0; val < 4; val++) {
+                       err = jazz16_configure_ports(port, mpu_port, val);
+                       if (err < 0)
+                               break;
+
+                       err = snd_sbdsp_reset(&chip);
+                       if (!err)
+                               break;
+               }
+       if (err < 0) {
+               err = -ENODEV;
+               goto err_unmap;
+       }
+       if (!snd_sbdsp_command(&chip, SB_DSP_GET_JAZZ_BRD_REV)) {
+               err = -EBUSY;
+               goto err_unmap;
+       }
+       val = snd_sbdsp_get_byte(&chip);
+       if (val >= 0x30)
+               snd_sbdsp_get_byte(&chip);
+
+       if ((val & 0xf0) != 0x10) {
+               err = -ENODEV;
+               goto err_unmap;
+       }
+       if (!snd_sbdsp_command(&chip, SB_DSP_GET_JAZZ_MODEL)) {
+               err = -EBUSY;
+               goto err_unmap;
+       }
+       snd_sbdsp_get_byte(&chip);
+       err = snd_sbdsp_get_byte(&chip);
+       snd_printd("Media Vision Jazz16 board detected: rev 0x%x, model 0x%x\n",
+                  val, err);
+
+       err = 0;
+
+err_unmap:
+       release_region(port, 0x10);
+       return err;
+}
+
+static int __devinit jazz16_configure_board(struct snd_sb *chip, int mpu_irq)
+{
+       static unsigned char jazz_irq_bits[] = { 0, 0, 2, 3, 0, 1, 0, 4,
+                                                0, 2, 5, 0, 0, 0, 0, 6 };
+       static unsigned char jazz_dma_bits[] = { 0, 1, 0, 2, 0, 3, 0, 4 };
+
+       if (jazz_dma_bits[chip->dma8] == 0 ||
+           jazz_dma_bits[chip->dma16] == 0 ||
+           jazz_irq_bits[chip->irq] == 0)
+               return -EINVAL;
+
+       if (!snd_sbdsp_command(chip, SB_JAZZ16_SET_DMAINTR))
+               return -EBUSY;
+
+       if (!snd_sbdsp_command(chip,
+                              jazz_dma_bits[chip->dma8] |
+                              (jazz_dma_bits[chip->dma16] << 4)))
+               return -EBUSY;
+
+       if (!snd_sbdsp_command(chip,
+                              jazz_irq_bits[chip->irq] |
+                              (jazz_irq_bits[mpu_irq] << 4)))
+               return -EBUSY;
+
+       return 0;
+}
+
+static int __devinit snd_jazz16_match(struct device *devptr, unsigned int dev)
+{
+       if (!enable[dev])
+               return 0;
+       if (port[dev] == SNDRV_AUTO_PORT) {
+               snd_printk(KERN_ERR "please specify port\n");
+               return 0;
+       } else if (port[dev] == 0x200 || (port[dev] & ~0x270)) {
+               snd_printk(KERN_ERR "incorrect port specified\n");
+               return 0;
+       }
+       if (dma8[dev] != SNDRV_AUTO_DMA &&
+           dma8[dev] != 1 && dma8[dev] != 3) {
+               snd_printk(KERN_ERR "dma8 must be 1 or 3\n");
+               return 0;
+       }
+       if (dma16[dev] != SNDRV_AUTO_DMA &&
+           dma16[dev] != 5 && dma16[dev] != 7) {
+               snd_printk(KERN_ERR "dma16 must be 5 or 7\n");
+               return 0;
+       }
+       if (mpu_port[dev] != SNDRV_AUTO_PORT &&
+           (mpu_port[dev] & ~0x030) != 0x300) {
+               snd_printk(KERN_ERR "incorrect mpu_port specified\n");
+               return 0;
+       }
+       if (mpu_irq[dev] != SNDRV_AUTO_DMA &&
+           mpu_irq[dev] != 2 && mpu_irq[dev] != 3 &&
+           mpu_irq[dev] != 5 && mpu_irq[dev] != 7) {
+               snd_printk(KERN_ERR "mpu_irq must be 2, 3, 5 or 7\n");
+               return 0;
+       }
+       return 1;
+}
+
+static int __devinit snd_jazz16_probe(struct device *devptr, unsigned int dev)
+{
+       struct snd_card *card;
+       struct snd_card_jazz16 *jazz16;
+       struct snd_sb *chip;
+       struct snd_opl3 *opl3;
+       static int possible_irqs[] = {2, 3, 5, 7, 9, 10, 15, -1};
+       static int possible_dmas8[] = {1, 3, -1};
+       static int possible_dmas16[] = {5, 7, -1};
+       int err, xirq, xdma8, xdma16, xmpu_port, xmpu_irq;
+
+       err = snd_card_create(index[dev], id[dev], THIS_MODULE,
+                             sizeof(struct snd_card_jazz16), &card);
+       if (err < 0)
+               return err;
+
+       jazz16 = card->private_data;
+
+       xirq = irq[dev];
+       if (xirq == SNDRV_AUTO_IRQ) {
+               xirq = snd_legacy_find_free_irq(possible_irqs);
+               if (xirq < 0) {
+                       snd_printk(KERN_ERR "unable to find a free IRQ\n");
+                       err = -EBUSY;
+                       goto err_free;
+               }
+       }
+       xdma8 = dma8[dev];
+       if (xdma8 == SNDRV_AUTO_DMA) {
+               xdma8 = snd_legacy_find_free_dma(possible_dmas8);
+               if (xdma8 < 0) {
+                       snd_printk(KERN_ERR "unable to find a free DMA8\n");
+                       err = -EBUSY;
+                       goto err_free;
+               }
+       }
+       xdma16 = dma16[dev];
+       if (xdma16 == SNDRV_AUTO_DMA) {
+               xdma16 = snd_legacy_find_free_dma(possible_dmas16);
+               if (xdma16 < 0) {
+                       snd_printk(KERN_ERR "unable to find a free DMA16\n");
+                       err = -EBUSY;
+                       goto err_free;
+               }
+       }
+
+       xmpu_port = mpu_port[dev];
+       if (xmpu_port == SNDRV_AUTO_PORT)
+               xmpu_port = 0;
+       err = jazz16_detect_board(port[dev], xmpu_port);
+       if (err < 0) {
+               printk(KERN_ERR "Media Vision Jazz16 board not detected\n");
+               goto err_free;
+       }
+       err = snd_sbdsp_create(card, port[dev], irq[dev],
+                              jazz16_interrupt,
+                              dma8[dev], dma16[dev],
+                              SB_HW_JAZZ16,
+                              &chip);
+       if (err < 0)
+               goto err_free;
+
+       xmpu_irq = mpu_irq[dev];
+       if (xmpu_irq == SNDRV_AUTO_IRQ || mpu_port[dev] == SNDRV_AUTO_PORT)
+               xmpu_irq = 0;
+       err = jazz16_configure_board(chip, xmpu_irq);
+       if (err < 0) {
+               printk(KERN_ERR "Media Vision Jazz16 configuration failed\n");
+               goto err_free;
+       }
+
+       jazz16->chip = chip;
+
+       strcpy(card->driver, "jazz16");
+       strcpy(card->shortname, "Media Vision Jazz16");
+       sprintf(card->longname,
+               "Media Vision Jazz16 at 0x%lx, irq %d, dma8 %d, dma16 %d",
+               port[dev], xirq, xdma8, xdma16);
+
+       err = snd_sb8dsp_pcm(chip, 0, NULL);
+       if (err < 0)
+               goto err_free;
+       err = snd_sbmixer_new(chip);
+       if (err < 0)
+               goto err_free;
+
+       err = snd_opl3_create(card, chip->port, chip->port + 2,
+                             OPL3_HW_AUTO, 1, &opl3);
+       if (err < 0)
+               snd_printk(KERN_WARNING "no OPL device at 0x%lx-0x%lx\n",
+                          chip->port, chip->port + 2);
+       else {
+               err = snd_opl3_hwdep_new(opl3, 0, 1, NULL);
+               if (err < 0)
+                       goto err_free;
+       }
+       if (mpu_port[dev] > 0 && mpu_port[dev] != SNDRV_AUTO_PORT) {
+               if (mpu_irq[dev] == SNDRV_AUTO_IRQ)
+                       mpu_irq[dev] = -1;
+
+               if (snd_mpu401_uart_new(card, 0,
+                                       MPU401_HW_MPU401,
+                                       mpu_port[dev], 0,
+                                       mpu_irq[dev],
+                                       mpu_irq[dev] >= 0 ? IRQF_DISABLED : 0,
+                                       NULL) < 0)
+                       snd_printk(KERN_ERR "no MPU-401 device at 0x%lx\n",
+                                       mpu_port[dev]);
+       }
+
+       snd_card_set_dev(card, devptr);
+
+       err = snd_card_register(card);
+       if (err < 0)
+               goto err_free;
+
+       dev_set_drvdata(devptr, card);
+       return 0;
+
+err_free:
+       snd_card_free(card);
+       return err;
+}
+
+static int __devexit snd_jazz16_remove(struct device *devptr, unsigned int dev)
+{
+       struct snd_card *card = dev_get_drvdata(devptr);
+
+       dev_set_drvdata(devptr, NULL);
+       snd_card_free(card);
+       return 0;
+}
+
+#ifdef CONFIG_PM
+static int snd_jazz16_suspend(struct device *pdev, unsigned int n,
+                              pm_message_t state)
+{
+       struct snd_card *card = dev_get_drvdata(pdev);
+       struct snd_card_jazz16 *acard = card->private_data;
+       struct snd_sb *chip = acard->chip;
+
+       snd_power_change_state(card, SNDRV_CTL_POWER_D3hot);
+       snd_pcm_suspend_all(chip->pcm);
+       snd_sbmixer_suspend(chip);
+       return 0;
+}
+
+static int snd_jazz16_resume(struct device *pdev, unsigned int n)
+{
+       struct snd_card *card = dev_get_drvdata(pdev);
+       struct snd_card_jazz16 *acard = card->private_data;
+       struct snd_sb *chip = acard->chip;
+
+       snd_sbdsp_reset(chip);
+       snd_sbmixer_resume(chip);
+       snd_power_change_state(card, SNDRV_CTL_POWER_D0);
+       return 0;
+}
+#endif
+
+static struct isa_driver snd_jazz16_driver = {
+       .match          = snd_jazz16_match,
+       .probe          = snd_jazz16_probe,
+       .remove         = __devexit_p(snd_jazz16_remove),
+#ifdef CONFIG_PM
+       .suspend        = snd_jazz16_suspend,
+       .resume         = snd_jazz16_resume,
+#endif
+       .driver         = {
+               .name   = "jazz16"
+       },
+};
+
+static int __init alsa_card_jazz16_init(void)
+{
+       return isa_register_driver(&snd_jazz16_driver, SNDRV_CARDS);
+}
+
+static void __exit alsa_card_jazz16_exit(void)
+{
+       isa_unregister_driver(&snd_jazz16_driver);
+}
+
+module_init(alsa_card_jazz16_init)
+module_exit(alsa_card_jazz16_exit)
index 658d557..7d84c9f 100644 (file)
@@ -106,9 +106,21 @@ static int snd_sb8_playback_prepare(struct snd_pcm_substream *substream)
        struct snd_sb *chip = snd_pcm_substream_chip(substream);
        struct snd_pcm_runtime *runtime = substream->runtime;
        unsigned int mixreg, rate, size, count;
+       unsigned char format;
+       unsigned char stereo = runtime->channels > 1;
+       int dma;
 
        rate = runtime->rate;
        switch (chip->hardware) {
+       case SB_HW_JAZZ16:
+               if (runtime->format == SNDRV_PCM_FORMAT_S16_LE) {
+                       if (chip->mode & SB_MODE_CAPTURE_16)
+                               return -EBUSY;
+                       else
+                               chip->mode |= SB_MODE_PLAYBACK_16;
+               }
+               chip->playback_format = SB_DSP_LO_OUTPUT_AUTO;
+               break;
        case SB_HW_PRO:
                if (runtime->channels > 1) {
                        if (snd_BUG_ON(rate != SB8_RATE(11025) &&
@@ -133,11 +145,21 @@ static int snd_sb8_playback_prepare(struct snd_pcm_substream *substream)
        default:
                return -EINVAL;
        }
+       if (chip->mode & SB_MODE_PLAYBACK_16) {
+               format = stereo ? SB_DSP_STEREO_16BIT : SB_DSP_MONO_16BIT;
+               dma = chip->dma16;
+       } else {
+               format = stereo ? SB_DSP_STEREO_8BIT : SB_DSP_MONO_8BIT;
+               chip->mode |= SB_MODE_PLAYBACK_8;
+               dma = chip->dma8;
+       }
        size = chip->p_dma_size = snd_pcm_lib_buffer_bytes(substream);
        count = chip->p_period_size = snd_pcm_lib_period_bytes(substream);
        spin_lock_irqsave(&chip->reg_lock, flags);
        snd_sbdsp_command(chip, SB_DSP_SPEAKER_ON);
-       if (runtime->channels > 1) {
+       if (chip->hardware == SB_HW_JAZZ16)
+               snd_sbdsp_command(chip, format);
+       else if (stereo) {
                /* set playback stereo mode */
                spin_lock(&chip->mixer_lock);
                mixreg = snd_sbmixer_read(chip, SB_DSP_STEREO_SW);
@@ -147,15 +169,14 @@ static int snd_sb8_playback_prepare(struct snd_pcm_substream *substream)
                /* Soundblaster hardware programming reference guide, 3-23 */
                snd_sbdsp_command(chip, SB_DSP_DMA8_EXIT);
                runtime->dma_area[0] = 0x80;
-               snd_dma_program(chip->dma8, runtime->dma_addr, 1, DMA_MODE_WRITE);
+               snd_dma_program(dma, runtime->dma_addr, 1, DMA_MODE_WRITE);
                /* force interrupt */
-               chip->mode = SB_MODE_HALT;
                snd_sbdsp_command(chip, SB_DSP_OUTPUT);
                snd_sbdsp_command(chip, 0);
                snd_sbdsp_command(chip, 0);
        }
        snd_sbdsp_command(chip, SB_DSP_SAMPLE_RATE);
-       if (runtime->channels > 1) {
+       if (stereo) {
                snd_sbdsp_command(chip, 256 - runtime->rate_den / 2);
                spin_lock(&chip->mixer_lock);
                /* save output filter status and turn it off */
@@ -168,13 +189,15 @@ static int snd_sb8_playback_prepare(struct snd_pcm_substream *substream)
                snd_sbdsp_command(chip, 256 - runtime->rate_den);
        }
        if (chip->playback_format != SB_DSP_OUTPUT) {
+               if (chip->mode & SB_MODE_PLAYBACK_16)
+                       count /= 2;
                count--;
                snd_sbdsp_command(chip, SB_DSP_BLOCK_SIZE);
                snd_sbdsp_command(chip, count & 0xff);
                snd_sbdsp_command(chip, count >> 8);
        }
        spin_unlock_irqrestore(&chip->reg_lock, flags);
-       snd_dma_program(chip->dma8, runtime->dma_addr,
+       snd_dma_program(dma, runtime->dma_addr,
                        size, DMA_MODE_WRITE | DMA_AUTOINIT);
        return 0;
 }
@@ -212,7 +235,6 @@ static int snd_sb8_playback_trigger(struct snd_pcm_substream *substream,
                snd_sbdsp_command(chip, SB_DSP_SPEAKER_OFF);
        }
        spin_unlock_irqrestore(&chip->reg_lock, flags);
-       chip->mode = (cmd == SNDRV_PCM_TRIGGER_START) ? SB_MODE_PLAYBACK_8 : SB_MODE_HALT;
        return 0;
 }
 
@@ -234,9 +256,21 @@ static int snd_sb8_capture_prepare(struct snd_pcm_substream *substream)
        struct snd_sb *chip = snd_pcm_substream_chip(substream);
        struct snd_pcm_runtime *runtime = substream->runtime;
        unsigned int mixreg, rate, size, count;
+       unsigned char format;
+       unsigned char stereo = runtime->channels > 1;
+       int dma;
 
        rate = runtime->rate;
        switch (chip->hardware) {
+       case SB_HW_JAZZ16:
+               if (runtime->format == SNDRV_PCM_FORMAT_S16_LE) {
+                       if (chip->mode & SB_MODE_PLAYBACK_16)
+                               return -EBUSY;
+                       else
+                               chip->mode |= SB_MODE_CAPTURE_16;
+               }
+               chip->capture_format = SB_DSP_LO_INPUT_AUTO;
+               break;
        case SB_HW_PRO:
                if (runtime->channels > 1) {
                        if (snd_BUG_ON(rate != SB8_RATE(11025) &&
@@ -262,14 +296,24 @@ static int snd_sb8_capture_prepare(struct snd_pcm_substream *substream)
        default:
                return -EINVAL;
        }
+       if (chip->mode & SB_MODE_CAPTURE_16) {
+               format = stereo ? SB_DSP_STEREO_16BIT : SB_DSP_MONO_16BIT;
+               dma = chip->dma16;
+       } else {
+               format = stereo ? SB_DSP_STEREO_8BIT : SB_DSP_MONO_8BIT;
+               chip->mode |= SB_MODE_CAPTURE_8;
+               dma = chip->dma8;
+       }
        size = chip->c_dma_size = snd_pcm_lib_buffer_bytes(substream);
        count = chip->c_period_size = snd_pcm_lib_period_bytes(substream);
        spin_lock_irqsave(&chip->reg_lock, flags);
        snd_sbdsp_command(chip, SB_DSP_SPEAKER_OFF);
-       if (runtime->channels > 1)
+       if (chip->hardware == SB_HW_JAZZ16)
+               snd_sbdsp_command(chip, format);
+       else if (stereo)
                snd_sbdsp_command(chip, SB_DSP_STEREO_8BIT);
        snd_sbdsp_command(chip, SB_DSP_SAMPLE_RATE);
-       if (runtime->channels > 1) {
+       if (stereo) {
                snd_sbdsp_command(chip, 256 - runtime->rate_den / 2);
                spin_lock(&chip->mixer_lock);
                /* save input filter status and turn it off */
@@ -282,13 +326,15 @@ static int snd_sb8_capture_prepare(struct snd_pcm_substream *substream)
                snd_sbdsp_command(chip, 256 - runtime->rate_den);
        }
        if (chip->capture_format != SB_DSP_INPUT) {
+               if (chip->mode & SB_MODE_PLAYBACK_16)
+                       count /= 2;
                count--;
                snd_sbdsp_command(chip, SB_DSP_BLOCK_SIZE);
                snd_sbdsp_command(chip, count & 0xff);
                snd_sbdsp_command(chip, count >> 8);
        }
        spin_unlock_irqrestore(&chip->reg_lock, flags);
-       snd_dma_program(chip->dma8, runtime->dma_addr,
+       snd_dma_program(dma, runtime->dma_addr,
                        size, DMA_MODE_READ | DMA_AUTOINIT);
        return 0;
 }
@@ -328,7 +374,6 @@ static int snd_sb8_capture_trigger(struct snd_pcm_substream *substream,
                snd_sbdsp_command(chip, SB_DSP_SPEAKER_OFF);
        }
        spin_unlock_irqrestore(&chip->reg_lock, flags);
-       chip->mode = (cmd == SNDRV_PCM_TRIGGER_START) ? SB_MODE_CAPTURE_8 : SB_MODE_HALT;
        return 0;
 }
 
@@ -339,13 +384,21 @@ irqreturn_t snd_sb8dsp_interrupt(struct snd_sb *chip)
 
        snd_sb_ack_8bit(chip);
        switch (chip->mode) {
-       case SB_MODE_PLAYBACK_8:        /* ok.. playback is active */
+       case SB_MODE_PLAYBACK_16:       /* ok.. playback is active */
+               if (chip->hardware != SB_HW_JAZZ16)
+                       break;
+               /* fallthru */
+       case SB_MODE_PLAYBACK_8:
                substream = chip->playback_substream;
                runtime = substream->runtime;
                if (chip->playback_format == SB_DSP_OUTPUT)
                        snd_sb8_playback_trigger(substream, SNDRV_PCM_TRIGGER_START);
                snd_pcm_period_elapsed(substream);
                break;
+       case SB_MODE_CAPTURE_16:
+               if (chip->hardware != SB_HW_JAZZ16)
+                       break;
+               /* fallthru */
        case SB_MODE_CAPTURE_8:
                substream = chip->capture_substream;
                runtime = substream->runtime;
@@ -361,10 +414,15 @@ static snd_pcm_uframes_t snd_sb8_playback_pointer(struct snd_pcm_substream *subs
 {
        struct snd_sb *chip = snd_pcm_substream_chip(substream);
        size_t ptr;
+       int dma;
 
-       if (chip->mode != SB_MODE_PLAYBACK_8)
+       if (chip->mode & SB_MODE_PLAYBACK_8)
+               dma = chip->dma8;
+       else if (chip->mode & SB_MODE_PLAYBACK_16)
+               dma = chip->dma16;
+       else
                return 0;
-       ptr = snd_dma_pointer(chip->dma8, chip->p_dma_size);
+       ptr = snd_dma_pointer(dma, chip->p_dma_size);
        return bytes_to_frames(substream->runtime, ptr);
 }
 
@@ -372,10 +430,15 @@ static snd_pcm_uframes_t snd_sb8_capture_pointer(struct snd_pcm_substream *subst
 {
        struct snd_sb *chip = snd_pcm_substream_chip(substream);
        size_t ptr;
+       int dma;
 
-       if (chip->mode != SB_MODE_CAPTURE_8)
+       if (chip->mode & SB_MODE_CAPTURE_8)
+               dma = chip->dma8;
+       else if (chip->mode & SB_MODE_CAPTURE_16)
+               dma = chip->dma16;
+       else
                return 0;
-       ptr = snd_dma_pointer(chip->dma8, chip->c_dma_size);
+       ptr = snd_dma_pointer(dma, chip->c_dma_size);
        return bytes_to_frames(substream->runtime, ptr);
 }
 
@@ -446,6 +509,14 @@ static int snd_sb8_open(struct snd_pcm_substream *substream)
                runtime->hw = snd_sb8_capture;
        }
        switch (chip->hardware) {
+       case SB_HW_JAZZ16:
+               if (chip->dma16 == 5 || chip->dma16 == 7)
+                       runtime->hw.formats |= SNDRV_PCM_FMTBIT_S16_LE;
+               runtime->hw.rates |= SNDRV_PCM_RATE_8000_48000;
+               runtime->hw.rate_min = 4000;
+               runtime->hw.rate_max = 50000;
+               runtime->hw.channels_max = 2;
+               break;
        case SB_HW_PRO:
                runtime->hw.rate_max = 44100;
                runtime->hw.channels_max = 2;
@@ -468,6 +539,14 @@ static int snd_sb8_open(struct snd_pcm_substream *substream)
        }
        snd_pcm_hw_constraint_ratnums(runtime, 0, SNDRV_PCM_HW_PARAM_RATE,
                                      &hw_constraints_clock);
+       if (chip->dma8 > 3 || chip->dma16 >= 0) {
+               snd_pcm_hw_constraint_step(runtime, 0,
+                                          SNDRV_PCM_HW_PARAM_BUFFER_BYTES, 2);
+               snd_pcm_hw_constraint_step(runtime, 0,
+                                          SNDRV_PCM_HW_PARAM_PERIOD_BYTES, 2);
+               runtime->hw.buffer_bytes_max = 128 * 1024 * 1024;
+               runtime->hw.period_bytes_max = 128 * 1024 * 1024;
+       }
        return 0;       
 }
 
@@ -480,6 +559,10 @@ static int snd_sb8_close(struct snd_pcm_substream *substream)
        chip->capture_substream = NULL;
        spin_lock_irqsave(&chip->open_lock, flags);
        chip->open &= ~SB_OPEN_PCM;
+       if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK)
+               chip->mode &= ~SB_MODE_PLAYBACK;
+       else
+               chip->mode &= ~SB_MODE_CAPTURE;
        spin_unlock_irqrestore(&chip->open_lock, flags);
        return 0;
 }
@@ -515,6 +598,7 @@ int snd_sb8dsp_pcm(struct snd_sb *chip, int device, struct snd_pcm ** rpcm)
        struct snd_card *card = chip->card;
        struct snd_pcm *pcm;
        int err;
+       size_t max_prealloc = 64 * 1024;
 
        if (rpcm)
                *rpcm = NULL;
@@ -527,9 +611,11 @@ int snd_sb8dsp_pcm(struct snd_sb *chip, int device, struct snd_pcm ** rpcm)
        snd_pcm_set_ops(pcm, SNDRV_PCM_STREAM_PLAYBACK, &snd_sb8_playback_ops);
        snd_pcm_set_ops(pcm, SNDRV_PCM_STREAM_CAPTURE, &snd_sb8_capture_ops);
 
+       if (chip->dma8 > 3 || chip->dma16 >= 0)
+               max_prealloc = 128 * 1024;
        snd_pcm_lib_preallocate_pages_for_all(pcm, SNDRV_DMA_TYPE_DEV,
                                              snd_dma_isa_data(),
-                                             64*1024, 64*1024);
+                                             64*1024, max_prealloc);
 
        if (rpcm)
                *rpcm = pcm;
index 27a6515..eae6c1c 100644 (file)
@@ -170,6 +170,9 @@ static int snd_sbdsp_probe(struct snd_sb * chip)
        case SB_HW_CS5530:
                str = "16 (CS5530)";
                break;
+       case SB_HW_JAZZ16:
+               str = "Pro (Jazz16)";
+               break;
        default:
                return -ENODEV;
        }
index 318ff0c..6496822 100644 (file)
@@ -528,20 +528,11 @@ int snd_sbmixer_add_ctl(struct snd_sb *chip, const char *name, int index, int ty
  * SB 2.0 specific mixer elements
  */
 
-static struct sbmix_elem snd_sb20_ctl_master_play_vol =
-       SB_SINGLE("Master Playback Volume", SB_DSP20_MASTER_DEV, 1, 7);
-static struct sbmix_elem snd_sb20_ctl_pcm_play_vol =
-       SB_SINGLE("PCM Playback Volume", SB_DSP20_PCM_DEV, 1, 3);
-static struct sbmix_elem snd_sb20_ctl_synth_play_vol =
-       SB_SINGLE("Synth Playback Volume", SB_DSP20_FM_DEV, 1, 7);
-static struct sbmix_elem snd_sb20_ctl_cd_play_vol =
-       SB_SINGLE("CD Playback Volume", SB_DSP20_CD_DEV, 1, 7);
-
-static struct sbmix_elem *snd_sb20_controls[] = {
-       &snd_sb20_ctl_master_play_vol,
-       &snd_sb20_ctl_pcm_play_vol,
-       &snd_sb20_ctl_synth_play_vol,
-       &snd_sb20_ctl_cd_play_vol
+static struct sbmix_elem snd_sb20_controls[] = {
+       SB_SINGLE("Master Playback Volume", SB_DSP20_MASTER_DEV, 1, 7),
+       SB_SINGLE("PCM Playback Volume", SB_DSP20_PCM_DEV, 1, 3),
+       SB_SINGLE("Synth Playback Volume", SB_DSP20_FM_DEV, 1, 7),
+       SB_SINGLE("CD Playback Volume", SB_DSP20_CD_DEV, 1, 7)
 };
 
 static unsigned char snd_sb20_init_values[][2] = {
@@ -552,41 +543,24 @@ static unsigned char snd_sb20_init_values[][2] = {
 /*
  * SB Pro specific mixer elements
  */
-static struct sbmix_elem snd_sbpro_ctl_master_play_vol =
-       SB_DOUBLE("Master Playback Volume", SB_DSP_MASTER_DEV, SB_DSP_MASTER_DEV, 5, 1, 7);
-static struct sbmix_elem snd_sbpro_ctl_pcm_play_vol =
-       SB_DOUBLE("PCM Playback Volume", SB_DSP_PCM_DEV, SB_DSP_PCM_DEV, 5, 1, 7);
-static struct sbmix_elem snd_sbpro_ctl_pcm_play_filter =
-       SB_SINGLE("PCM Playback Filter", SB_DSP_PLAYBACK_FILT, 5, 1);
-static struct sbmix_elem snd_sbpro_ctl_synth_play_vol =
-       SB_DOUBLE("Synth Playback Volume", SB_DSP_FM_DEV, SB_DSP_FM_DEV, 5, 1, 7);
-static struct sbmix_elem snd_sbpro_ctl_cd_play_vol =
-       SB_DOUBLE("CD Playback Volume", SB_DSP_CD_DEV, SB_DSP_CD_DEV, 5, 1, 7);
-static struct sbmix_elem snd_sbpro_ctl_line_play_vol =
-       SB_DOUBLE("Line Playback Volume", SB_DSP_LINE_DEV, SB_DSP_LINE_DEV, 5, 1, 7);
-static struct sbmix_elem snd_sbpro_ctl_mic_play_vol =
-       SB_SINGLE("Mic Playback Volume", SB_DSP_MIC_DEV, 1, 3);
-static struct sbmix_elem snd_sbpro_ctl_capture_source =
+static struct sbmix_elem snd_sbpro_controls[] = {
+       SB_DOUBLE("Master Playback Volume",
+                 SB_DSP_MASTER_DEV, SB_DSP_MASTER_DEV, 5, 1, 7),
+       SB_DOUBLE("PCM Playback Volume",
+                 SB_DSP_PCM_DEV, SB_DSP_PCM_DEV, 5, 1, 7),
+       SB_SINGLE("PCM Playback Filter", SB_DSP_PLAYBACK_FILT, 5, 1),
+       SB_DOUBLE("Synth Playback Volume",
+                 SB_DSP_FM_DEV, SB_DSP_FM_DEV, 5, 1, 7),
+       SB_DOUBLE("CD Playback Volume", SB_DSP_CD_DEV, SB_DSP_CD_DEV, 5, 1, 7),
+       SB_DOUBLE("Line Playback Volume",
+                 SB_DSP_LINE_DEV, SB_DSP_LINE_DEV, 5, 1, 7),
+       SB_SINGLE("Mic Playback Volume", SB_DSP_MIC_DEV, 1, 3),
        {
                .name = "Capture Source",
                .type = SB_MIX_CAPTURE_PRO
-       };
-static struct sbmix_elem snd_sbpro_ctl_capture_filter =
-       SB_SINGLE("Capture Filter", SB_DSP_CAPTURE_FILT, 5, 1);
-static struct sbmix_elem snd_sbpro_ctl_capture_low_filter =
-       SB_SINGLE("Capture Low-Pass Filter", SB_DSP_CAPTURE_FILT, 3, 1);
-
-static struct sbmix_elem *snd_sbpro_controls[] = {
-       &snd_sbpro_ctl_master_play_vol,
-       &snd_sbpro_ctl_pcm_play_vol,
-       &snd_sbpro_ctl_pcm_play_filter,
-       &snd_sbpro_ctl_synth_play_vol,
-       &snd_sbpro_ctl_cd_play_vol,
-       &snd_sbpro_ctl_line_play_vol,
-       &snd_sbpro_ctl_mic_play_vol,
-       &snd_sbpro_ctl_capture_source,
-       &snd_sbpro_ctl_capture_filter,
-       &snd_sbpro_ctl_capture_low_filter
+       },
+       SB_SINGLE("Capture Filter", SB_DSP_CAPTURE_FILT, 5, 1),
+       SB_SINGLE("Capture Low-Pass Filter", SB_DSP_CAPTURE_FILT, 3, 1)
 };
 
 static unsigned char snd_sbpro_init_values[][2] = {
@@ -598,68 +572,42 @@ static unsigned char snd_sbpro_init_values[][2] = {
 /*
  * SB16 specific mixer elements
  */
-static struct sbmix_elem snd_sb16_ctl_master_play_vol =
-       SB_DOUBLE("Master Playback Volume", SB_DSP4_MASTER_DEV, (SB_DSP4_MASTER_DEV + 1), 3, 3, 31);
-static struct sbmix_elem snd_sb16_ctl_3d_enhance_switch =
-       SB_SINGLE("3D Enhancement Switch", SB_DSP4_3DSE, 0, 1);
-static struct sbmix_elem snd_sb16_ctl_tone_bass =
-       SB_DOUBLE("Tone Control - Bass", SB_DSP4_BASS_DEV, (SB_DSP4_BASS_DEV + 1), 4, 4, 15);
-static struct sbmix_elem snd_sb16_ctl_tone_treble =
-       SB_DOUBLE("Tone Control - Treble", SB_DSP4_TREBLE_DEV, (SB_DSP4_TREBLE_DEV + 1), 4, 4, 15);
-static struct sbmix_elem snd_sb16_ctl_pcm_play_vol =
-       SB_DOUBLE("PCM Playback Volume", SB_DSP4_PCM_DEV, (SB_DSP4_PCM_DEV + 1), 3, 3, 31);
-static struct sbmix_elem snd_sb16_ctl_synth_capture_route =
-       SB16_INPUT_SW("Synth Capture Route", SB_DSP4_INPUT_LEFT, SB_DSP4_INPUT_RIGHT, 6, 5);
-static struct sbmix_elem snd_sb16_ctl_synth_play_vol =
-       SB_DOUBLE("Synth Playback Volume", SB_DSP4_SYNTH_DEV, (SB_DSP4_SYNTH_DEV + 1), 3, 3, 31);
-static struct sbmix_elem snd_sb16_ctl_cd_capture_route =
-       SB16_INPUT_SW("CD Capture Route", SB_DSP4_INPUT_LEFT, SB_DSP4_INPUT_RIGHT, 2, 1);
-static struct sbmix_elem snd_sb16_ctl_cd_play_switch =
-       SB_DOUBLE("CD Playback Switch", SB_DSP4_OUTPUT_SW, SB_DSP4_OUTPUT_SW, 2, 1, 1);
-static struct sbmix_elem snd_sb16_ctl_cd_play_vol =
-       SB_DOUBLE("CD Playback Volume", SB_DSP4_CD_DEV, (SB_DSP4_CD_DEV + 1), 3, 3, 31);
-static struct sbmix_elem snd_sb16_ctl_line_capture_route =
-       SB16_INPUT_SW("Line Capture Route", SB_DSP4_INPUT_LEFT, SB_DSP4_INPUT_RIGHT, 4, 3);
-static struct sbmix_elem snd_sb16_ctl_line_play_switch =
-       SB_DOUBLE("Line Playback Switch", SB_DSP4_OUTPUT_SW, SB_DSP4_OUTPUT_SW, 4, 3, 1);
-static struct sbmix_elem snd_sb16_ctl_line_play_vol =
-       SB_DOUBLE("Line Playback Volume", SB_DSP4_LINE_DEV, (SB_DSP4_LINE_DEV + 1), 3, 3, 31);
-static struct sbmix_elem snd_sb16_ctl_mic_capture_route =
-       SB16_INPUT_SW("Mic Capture Route", SB_DSP4_INPUT_LEFT, SB_DSP4_INPUT_RIGHT, 0, 0);
-static struct sbmix_elem snd_sb16_ctl_mic_play_switch =
-       SB_SINGLE("Mic Playback Switch", SB_DSP4_OUTPUT_SW, 0, 1);
-static struct sbmix_elem snd_sb16_ctl_mic_play_vol =
-       SB_SINGLE("Mic Playback Volume", SB_DSP4_MIC_DEV, 3, 31);
-static struct sbmix_elem snd_sb16_ctl_pc_speaker_vol =
-       SB_SINGLE("Beep Volume", SB_DSP4_SPEAKER_DEV, 6, 3);
-static struct sbmix_elem snd_sb16_ctl_capture_vol =
-       SB_DOUBLE("Capture Volume", SB_DSP4_IGAIN_DEV, (SB_DSP4_IGAIN_DEV + 1), 6, 6, 3);
-static struct sbmix_elem snd_sb16_ctl_play_vol =
-       SB_DOUBLE("Playback Volume", SB_DSP4_OGAIN_DEV, (SB_DSP4_OGAIN_DEV + 1), 6, 6, 3);
-static struct sbmix_elem snd_sb16_ctl_auto_mic_gain =
-       SB_SINGLE("Mic Auto Gain", SB_DSP4_MIC_AGC, 0, 1);
-
-static struct sbmix_elem *snd_sb16_controls[] = {
-       &snd_sb16_ctl_master_play_vol,
-       &snd_sb16_ctl_3d_enhance_switch,
-       &snd_sb16_ctl_tone_bass,
-       &snd_sb16_ctl_tone_treble,
-       &snd_sb16_ctl_pcm_play_vol,
-       &snd_sb16_ctl_synth_capture_route,
-       &snd_sb16_ctl_synth_play_vol,
-       &snd_sb16_ctl_cd_capture_route,
-       &snd_sb16_ctl_cd_play_switch,
-       &snd_sb16_ctl_cd_play_vol,
-       &snd_sb16_ctl_line_capture_route,
-       &snd_sb16_ctl_line_play_switch,
-       &snd_sb16_ctl_line_play_vol,
-       &snd_sb16_ctl_mic_capture_route,
-       &snd_sb16_ctl_mic_play_switch,
-       &snd_sb16_ctl_mic_play_vol,
-       &snd_sb16_ctl_pc_speaker_vol,
-       &snd_sb16_ctl_capture_vol,
-       &snd_sb16_ctl_play_vol,
-       &snd_sb16_ctl_auto_mic_gain
+static struct sbmix_elem snd_sb16_controls[] = {
+       SB_DOUBLE("Master Playback Volume",
+                 SB_DSP4_MASTER_DEV, (SB_DSP4_MASTER_DEV + 1), 3, 3, 31),
+       SB_DOUBLE("PCM Playback Volume",
+                 SB_DSP4_PCM_DEV, (SB_DSP4_PCM_DEV + 1), 3, 3, 31),
+       SB16_INPUT_SW("Synth Capture Route",
+                     SB_DSP4_INPUT_LEFT, SB_DSP4_INPUT_RIGHT, 6, 5),
+       SB_DOUBLE("Synth Playback Volume",
+                 SB_DSP4_SYNTH_DEV, (SB_DSP4_SYNTH_DEV + 1), 3, 3, 31),
+       SB16_INPUT_SW("CD Capture Route",
+                     SB_DSP4_INPUT_LEFT, SB_DSP4_INPUT_RIGHT, 2, 1),
+       SB_DOUBLE("CD Playback Switch",
+                 SB_DSP4_OUTPUT_SW, SB_DSP4_OUTPUT_SW, 2, 1, 1),
+       SB_DOUBLE("CD Playback Volume",
+                 SB_DSP4_CD_DEV, (SB_DSP4_CD_DEV + 1), 3, 3, 31),
+       SB16_INPUT_SW("Mic Capture Route",
+                     SB_DSP4_INPUT_LEFT, SB_DSP4_INPUT_RIGHT, 0, 0),
+       SB_SINGLE("Mic Playback Switch", SB_DSP4_OUTPUT_SW, 0, 1),
+       SB_SINGLE("Mic Playback Volume", SB_DSP4_MIC_DEV, 3, 31),
+       SB_SINGLE("Beep Volume", SB_DSP4_SPEAKER_DEV, 6, 3),
+       SB_DOUBLE("Capture Volume",
+                 SB_DSP4_IGAIN_DEV, (SB_DSP4_IGAIN_DEV + 1), 6, 6, 3),
+       SB_DOUBLE("Playback Volume",
+                 SB_DSP4_OGAIN_DEV, (SB_DSP4_OGAIN_DEV + 1), 6, 6, 3),
+       SB16_INPUT_SW("Line Capture Route",
+                     SB_DSP4_INPUT_LEFT, SB_DSP4_INPUT_RIGHT, 4, 3),
+       SB_DOUBLE("Line Playback Switch",
+                 SB_DSP4_OUTPUT_SW, SB_DSP4_OUTPUT_SW, 4, 3, 1),
+       SB_DOUBLE("Line Playback Volume",
+                 SB_DSP4_LINE_DEV, (SB_DSP4_LINE_DEV + 1), 3, 3, 31),
+       SB_SINGLE("Mic Auto Gain", SB_DSP4_MIC_AGC, 0, 1),
+       SB_SINGLE("3D Enhancement Switch", SB_DSP4_3DSE, 0, 1),
+       SB_DOUBLE("Tone Control - Bass",
+                 SB_DSP4_BASS_DEV, (SB_DSP4_BASS_DEV + 1), 4, 4, 15),
+       SB_DOUBLE("Tone Control - Treble",
+                 SB_DSP4_TREBLE_DEV, (SB_DSP4_TREBLE_DEV + 1), 4, 4, 15)
 };
 
 static unsigned char snd_sb16_init_values[][2] = {
@@ -678,46 +626,34 @@ static unsigned char snd_sb16_init_values[][2] = {
 /*
  * DT019x specific mixer elements
  */
-static struct sbmix_elem snd_dt019x_ctl_master_play_vol =
-       SB_DOUBLE("Master Playback Volume", SB_DT019X_MASTER_DEV, SB_DT019X_MASTER_DEV, 4,0, 15);
-static struct sbmix_elem snd_dt019x_ctl_pcm_play_vol =
-       SB_DOUBLE("PCM Playback Volume", SB_DT019X_PCM_DEV, SB_DT019X_PCM_DEV, 4,0, 15);
-static struct sbmix_elem snd_dt019x_ctl_synth_play_vol =
-       SB_DOUBLE("Synth Playback Volume", SB_DT019X_SYNTH_DEV, SB_DT019X_SYNTH_DEV, 4,0, 15);
-static struct sbmix_elem snd_dt019x_ctl_cd_play_vol =
-       SB_DOUBLE("CD Playback Volume", SB_DT019X_CD_DEV, SB_DT019X_CD_DEV, 4,0, 15);
-static struct sbmix_elem snd_dt019x_ctl_mic_play_vol =
-       SB_SINGLE("Mic Playback Volume", SB_DT019X_MIC_DEV, 4, 7);
-static struct sbmix_elem snd_dt019x_ctl_pc_speaker_vol =
-       SB_SINGLE("Beep Volume", SB_DT019X_SPKR_DEV, 0,  7);
-static struct sbmix_elem snd_dt019x_ctl_line_play_vol =
-       SB_DOUBLE("Line Playback Volume", SB_DT019X_LINE_DEV, SB_DT019X_LINE_DEV, 4,0, 15);
-static struct sbmix_elem snd_dt019x_ctl_pcm_play_switch =
-       SB_DOUBLE("PCM Playback Switch", SB_DT019X_OUTPUT_SW2, SB_DT019X_OUTPUT_SW2, 2,1, 1);
-static struct sbmix_elem snd_dt019x_ctl_synth_play_switch =
-       SB_DOUBLE("Synth Playback Switch", SB_DT019X_OUTPUT_SW2, SB_DT019X_OUTPUT_SW2, 4,3, 1);
-static struct sbmix_elem snd_dt019x_ctl_capture_source =
+static struct sbmix_elem snd_dt019x_controls[] = {
+       /* ALS4000 below has some parts which we might be lacking,
+        * e.g. snd_als4000_ctl_mono_playback_switch - check it! */
+       SB_DOUBLE("Master Playback Volume",
+                 SB_DT019X_MASTER_DEV, SB_DT019X_MASTER_DEV, 4, 0, 15),
+       SB_DOUBLE("PCM Playback Switch",
+                 SB_DT019X_OUTPUT_SW2, SB_DT019X_OUTPUT_SW2, 2, 1, 1),
+       SB_DOUBLE("PCM Playback Volume",
+                 SB_DT019X_PCM_DEV, SB_DT019X_PCM_DEV, 4, 0, 15),
+       SB_DOUBLE("Synth Playback Switch",
+                 SB_DT019X_OUTPUT_SW2, SB_DT019X_OUTPUT_SW2, 4, 3, 1),
+       SB_DOUBLE("Synth Playback Volume",
+                 SB_DT019X_SYNTH_DEV, SB_DT019X_SYNTH_DEV, 4, 0, 15),
+       SB_DOUBLE("CD Playback Switch",
+                 SB_DSP4_OUTPUT_SW, SB_DSP4_OUTPUT_SW, 2, 1, 1),
+       SB_DOUBLE("CD Playback Volume",
+                 SB_DT019X_CD_DEV, SB_DT019X_CD_DEV, 4, 0, 15),
+       SB_SINGLE("Mic Playback Switch", SB_DSP4_OUTPUT_SW, 0, 1),
+       SB_SINGLE("Mic Playback Volume", SB_DT019X_MIC_DEV, 4, 7),
+       SB_SINGLE("Beep Volume", SB_DT019X_SPKR_DEV, 0,  7),
+       SB_DOUBLE("Line Playback Switch",
+                 SB_DSP4_OUTPUT_SW, SB_DSP4_OUTPUT_SW, 4, 3, 1),
+       SB_DOUBLE("Line Playback Volume",
+                 SB_DT019X_LINE_DEV, SB_DT019X_LINE_DEV, 4, 0, 15),
        {
                .name = "Capture Source",
                .type = SB_MIX_CAPTURE_DT019X
-       };
-
-static struct sbmix_elem *snd_dt019x_controls[] = {
-       /* ALS4000 below has some parts which we might be lacking,
-        * e.g. snd_als4000_ctl_mono_playback_switch - check it! */
-       &snd_dt019x_ctl_master_play_vol,
-       &snd_dt019x_ctl_pcm_play_vol,
-       &snd_dt019x_ctl_synth_play_vol,
-       &snd_dt019x_ctl_cd_play_vol,
-       &snd_dt019x_ctl_mic_play_vol,
-       &snd_dt019x_ctl_pc_speaker_vol,
-       &snd_dt019x_ctl_line_play_vol,
-       &snd_sb16_ctl_mic_play_switch,
-       &snd_sb16_ctl_cd_play_switch,
-       &snd_sb16_ctl_line_play_switch,
-       &snd_dt019x_ctl_pcm_play_switch,
-       &snd_dt019x_ctl_synth_play_switch,
-       &snd_dt019x_ctl_capture_source
+       }
 };
 
 static unsigned char snd_dt019x_init_values[][2] = {
@@ -735,82 +671,37 @@ static unsigned char snd_dt019x_init_values[][2] = {
 /*
  * ALS4000 specific mixer elements
  */
-static struct sbmix_elem snd_als4000_ctl_master_mono_playback_switch =
-       SB_SINGLE("Master Mono Playback Switch", SB_ALS4000_MONO_IO_CTRL, 5, 1);
-static struct sbmix_elem snd_als4k_ctl_master_mono_capture_route = {
+static struct sbmix_elem snd_als4000_controls[] = {
+       SB_DOUBLE("PCM Playback Switch",
+                 SB_DT019X_OUTPUT_SW2, SB_DT019X_OUTPUT_SW2, 2, 1, 1),
+       SB_DOUBLE("Synth Playback Switch",
+                 SB_DT019X_OUTPUT_SW2, SB_DT019X_OUTPUT_SW2, 4, 3, 1),
+       SB_SINGLE("Mic Boost (+20dB)", SB_ALS4000_MIC_IN_GAIN, 0, 0x03),
+       SB_SINGLE("Master Mono Playback Switch", SB_ALS4000_MONO_IO_CTRL, 5, 1),
+       {
                .name = "Master Mono Capture Route",
                .type = SB_MIX_MONO_CAPTURE_ALS4K
-       };
-static struct sbmix_elem snd_als4000_ctl_mono_playback_switch =
-       SB_SINGLE("Mono Playback Switch", SB_DT019X_OUTPUT_SW2, 0, 1);
-static struct sbmix_elem snd_als4000_ctl_mic_20db_boost =
-       SB_SINGLE("Mic Boost (+20dB)", SB_ALS4000_MIC_IN_GAIN, 0, 0x03);
-static struct sbmix_elem snd_als4000_ctl_mixer_analog_loopback =
-       SB_SINGLE("Analog Loopback Switch", SB_ALS4000_MIC_IN_GAIN, 7, 0x01);
-static struct sbmix_elem snd_als4000_ctl_mixer_digital_loopback =
+       },
+       SB_SINGLE("Mono Playback Switch", SB_DT019X_OUTPUT_SW2, 0, 1),
+       SB_SINGLE("Analog Loopback Switch", SB_ALS4000_MIC_IN_GAIN, 7, 0x01),
+       SB_SINGLE("3D Control - Switch", SB_ALS4000_3D_SND_FX, 6, 0x01),
        SB_SINGLE("Digital Loopback Switch",
-                 SB_ALS4000_CR3_CONFIGURATION, 7, 0x01);
-/* FIXME: functionality of 3D controls might be swapped, I didn't find
- * a description of how to identify what is supposed to be what */
-static struct sbmix_elem snd_als4000_3d_control_switch =
-       SB_SINGLE("3D Control - Switch", SB_ALS4000_3D_SND_FX, 6, 0x01);
-static struct sbmix_elem snd_als4000_3d_control_ratio =
-       SB_SINGLE("3D Control - Level", SB_ALS4000_3D_SND_FX, 0, 0x07);
-static struct sbmix_elem snd_als4000_3d_control_freq =
+                 SB_ALS4000_CR3_CONFIGURATION, 7, 0x01),
+       /* FIXME: functionality of 3D controls might be swapped, I didn't find
+        * a description of how to identify what is supposed to be what */
+       SB_SINGLE("3D Control - Level", SB_ALS4000_3D_SND_FX, 0, 0x07),
        /* FIXME: maybe there's actually some standard 3D ctrl name for it?? */
-       SB_SINGLE("3D Control - Freq", SB_ALS4000_3D_SND_FX, 4, 0x03);
-static struct sbmix_elem snd_als4000_3d_control_delay =
+       SB_SINGLE("3D Control - Freq", SB_ALS4000_3D_SND_FX, 4, 0x03),
        /* FIXME: ALS4000a.pdf mentions BBD (Bucket Brigade Device) time delay,
         * but what ALSA 3D attribute is that actually? "Center", "Depth",
         * "Wide" or "Space" or even "Level"? Assuming "Wide" for now... */
-       SB_SINGLE("3D Control - Wide", SB_ALS4000_3D_TIME_DELAY, 0, 0x0f);
-static struct sbmix_elem snd_als4000_3d_control_poweroff_switch =
-       SB_SINGLE("3D PowerOff Switch", SB_ALS4000_3D_TIME_DELAY, 4, 0x01);
-static struct sbmix_elem snd_als4000_ctl_3db_freq_control_switch =
+       SB_SINGLE("3D Control - Wide", SB_ALS4000_3D_TIME_DELAY, 0, 0x0f),
+       SB_SINGLE("3D PowerOff Switch", SB_ALS4000_3D_TIME_DELAY, 4, 0x01),
        SB_SINGLE("Master Playback 8kHz / 20kHz LPF Switch",
-                 SB_ALS4000_FMDAC, 5, 0x01);
+                 SB_ALS4000_FMDAC, 5, 0x01),
 #ifdef NOT_AVAILABLE
-static struct sbmix_elem snd_als4000_ctl_fmdac =
-       SB_SINGLE("FMDAC Switch (Option ?)", SB_ALS4000_FMDAC, 0, 0x01);
-static struct sbmix_elem snd_als4000_ctl_qsound =
-       SB_SINGLE("QSound Mode", SB_ALS4000_QSOUND, 1, 0x1f);
-#endif
-
-static struct sbmix_elem *snd_als4000_controls[] = {
-                                               /* ALS4000a.PDF regs page */
-       &snd_sb16_ctl_master_play_vol,          /* MX30/31 12 */
-       &snd_dt019x_ctl_pcm_play_switch,        /* MX4C    16 */
-       &snd_sb16_ctl_pcm_play_vol,             /* MX32/33 12 */
-       &snd_sb16_ctl_synth_capture_route,      /* MX3D/3E 14 */
-       &snd_dt019x_ctl_synth_play_switch,      /* MX4C    16 */
-       &snd_sb16_ctl_synth_play_vol,           /* MX34/35 12/13 */
-       &snd_sb16_ctl_cd_capture_route,         /* MX3D/3E 14 */
-       &snd_sb16_ctl_cd_play_switch,           /* MX3C    14 */
-       &snd_sb16_ctl_cd_play_vol,              /* MX36/37 13 */
-       &snd_sb16_ctl_line_capture_route,       /* MX3D/3E 14 */
-       &snd_sb16_ctl_line_play_switch,         /* MX3C    14 */
-       &snd_sb16_ctl_line_play_vol,            /* MX38/39 13 */
-       &snd_sb16_ctl_mic_capture_route,        /* MX3D/3E 14 */
-       &snd_als4000_ctl_mic_20db_boost,        /* MX4D    16 */
-       &snd_sb16_ctl_mic_play_switch,          /* MX3C    14 */
-       &snd_sb16_ctl_mic_play_vol,             /* MX3A    13 */
-       &snd_sb16_ctl_pc_speaker_vol,           /* MX3B    14 */
-       &snd_sb16_ctl_capture_vol,              /* MX3F/40 15 */
-       &snd_sb16_ctl_play_vol,                 /* MX41/42 15 */
-       &snd_als4000_ctl_master_mono_playback_switch, /* MX4C 16 */
-       &snd_als4k_ctl_master_mono_capture_route, /* MX4B  16 */
-       &snd_als4000_ctl_mono_playback_switch,  /* MX4C    16 */
-       &snd_als4000_ctl_mixer_analog_loopback, /* MX4D    16 */
-       &snd_als4000_ctl_mixer_digital_loopback, /* CR3    21 */
-       &snd_als4000_3d_control_switch,          /* MX50   17 */
-       &snd_als4000_3d_control_ratio,           /* MX50   17 */
-       &snd_als4000_3d_control_freq,            /* MX50   17 */
-       &snd_als4000_3d_control_delay,           /* MX51   18 */
-       &snd_als4000_3d_control_poweroff_switch,        /* MX51    18 */
-       &snd_als4000_ctl_3db_freq_control_switch,       /* MX4F    17 */
-#ifdef NOT_AVAILABLE
-       &snd_als4000_ctl_fmdac,
-       &snd_als4000_ctl_qsound,
+       SB_SINGLE("FMDAC Switch (Option ?)", SB_ALS4000_FMDAC, 0, 0x01),
+       SB_SINGLE("QSound Mode", SB_ALS4000_QSOUND, 1, 0x1f),
 #endif
 };
 
@@ -829,11 +720,10 @@ static unsigned char snd_als4000_init_values[][2] = {
        { SB_ALS4000_MIC_IN_GAIN, 0 },
 };
 
-
 /*
  */
 static int snd_sbmixer_init(struct snd_sb *chip,
-                           struct sbmix_elem **controls,
+                           struct sbmix_elem *controls,
                            int controls_count,
                            unsigned char map[][2],
                            int map_count,
@@ -856,7 +746,8 @@ static int snd_sbmixer_init(struct snd_sb *chip,
        }
 
        for (idx = 0; idx < controls_count; idx++) {
-               if ((err = snd_sbmixer_add_ctl_elem(chip, controls[idx])) < 0)
+               err = snd_sbmixer_add_ctl_elem(chip, &controls[idx]);
+               if (err < 0)
                        return err;
        }
        snd_component_add(card, name);
@@ -888,6 +779,7 @@ int snd_sbmixer_new(struct snd_sb *chip)
                        return err;
                break;
        case SB_HW_PRO:
+       case SB_HW_JAZZ16:
                if ((err = snd_sbmixer_init(chip,
                                            snd_sbpro_controls,
                                            ARRAY_SIZE(snd_sbpro_controls),
@@ -908,6 +800,15 @@ int snd_sbmixer_new(struct snd_sb *chip)
                        return err;
                break;
        case SB_HW_ALS4000:
+               /* use only the first 16 controls from SB16 */
+               err = snd_sbmixer_init(chip,
+                                       snd_sb16_controls,
+                                       16,
+                                       snd_sb16_init_values,
+                                       ARRAY_SIZE(snd_sb16_init_values),
+                                       "ALS4000");
+               if (err < 0)
+                       return err;
                if ((err = snd_sbmixer_init(chip,
                                            snd_als4000_controls,
                                            ARRAY_SIZE(snd_als4000_controls),
@@ -1029,6 +930,7 @@ void snd_sbmixer_suspend(struct snd_sb *chip)
                save_mixer(chip, sb20_saved_regs, ARRAY_SIZE(sb20_saved_regs));
                break;
        case SB_HW_PRO:
+       case SB_HW_JAZZ16:
                save_mixer(chip, sbpro_saved_regs, ARRAY_SIZE(sbpro_saved_regs));
                break;
        case SB_HW_16:
@@ -1055,6 +957,7 @@ void snd_sbmixer_resume(struct snd_sb *chip)
                restore_mixer(chip, sb20_saved_regs, ARRAY_SIZE(sb20_saved_regs));
                break;
        case SB_HW_PRO:
+       case SB_HW_JAZZ16:
                restore_mixer(chip, sbpro_saved_regs, ARRAY_SIZE(sbpro_saved_regs));
                break;
        case SB_HW_16:
index 5b9d6c1..9191b32 100644 (file)
@@ -2014,6 +2014,7 @@ static int snd_wss_info_mux(struct snd_kcontrol *kcontrol,
        case WSS_HW_INTERWAVE:
                ptexts = gusmax_texts;
                break;
+       case WSS_HW_OPTI93X:
        case WSS_HW_OPL3SA2:
                ptexts = opl3sa_texts;
                break;
@@ -2246,54 +2247,12 @@ WSS_SINGLE("Beep Bypass Playback Switch", 0,
                CS4231_MONO_CTRL, 5, 1, 0),
 };
 
-static struct snd_kcontrol_new snd_opti93x_controls[] = {
-WSS_DOUBLE("Master Playback Switch", 0,
-               OPTi93X_OUT_LEFT, OPTi93X_OUT_RIGHT, 7, 7, 1, 1),
-WSS_DOUBLE_TLV("Master Playback Volume", 0,
-               OPTi93X_OUT_LEFT, OPTi93X_OUT_RIGHT, 1, 1, 31, 1,
-               db_scale_6bit),
-WSS_DOUBLE("PCM Playback Switch", 0,
-               CS4231_LEFT_OUTPUT, CS4231_RIGHT_OUTPUT, 7, 7, 1, 1),
-WSS_DOUBLE("PCM Playback Volume", 0,
-               CS4231_LEFT_OUTPUT, CS4231_RIGHT_OUTPUT, 0, 0, 31, 1),
-WSS_DOUBLE("FM Playback Switch", 0,
-               CS4231_AUX2_LEFT_INPUT, CS4231_AUX2_RIGHT_INPUT, 7, 7, 1, 1),
-WSS_DOUBLE("FM Playback Volume", 0,
-               CS4231_AUX2_LEFT_INPUT, CS4231_AUX2_RIGHT_INPUT, 1, 1, 15, 1),
-WSS_DOUBLE("Line Playback Switch", 0,
-               CS4231_LEFT_LINE_IN, CS4231_RIGHT_LINE_IN, 7, 7, 1, 1),
-WSS_DOUBLE("Line Playback Volume", 0,
-               CS4231_LEFT_LINE_IN, CS4231_RIGHT_LINE_IN, 0, 0, 15, 1),
-WSS_DOUBLE("Mic Playback Switch", 0,
-               OPTi93X_MIC_LEFT_INPUT, OPTi93X_MIC_RIGHT_INPUT, 7, 7, 1, 1),
-WSS_DOUBLE("Mic Playback Volume", 0,
-               OPTi93X_MIC_LEFT_INPUT, OPTi93X_MIC_RIGHT_INPUT, 1, 1, 15, 1),
-WSS_DOUBLE("Mic Boost", 0,
-               CS4231_LEFT_INPUT, CS4231_RIGHT_INPUT, 5, 5, 1, 0),
-WSS_DOUBLE("CD Playback Switch", 0,
-               CS4231_AUX1_LEFT_INPUT, CS4231_AUX1_RIGHT_INPUT, 7, 7, 1, 1),
-WSS_DOUBLE("CD Playback Volume", 0,
-               CS4231_AUX1_LEFT_INPUT, CS4231_AUX1_RIGHT_INPUT, 1, 1, 15, 1),
-WSS_DOUBLE("Aux Playback Switch", 0,
-               OPTi931_AUX_LEFT_INPUT, OPTi931_AUX_RIGHT_INPUT, 7, 7, 1, 1),
-WSS_DOUBLE("Aux Playback Volume", 0,
-               OPTi931_AUX_LEFT_INPUT, OPTi931_AUX_RIGHT_INPUT, 1, 1, 15, 1),
-WSS_DOUBLE("Capture Volume", 0,
-               CS4231_LEFT_INPUT, CS4231_RIGHT_INPUT, 0, 0, 15, 0),
-{
-       .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
-       .name = "Capture Source",
-       .info = snd_wss_info_mux,
-       .get = snd_wss_get_mux,
-       .put = snd_wss_put_mux,
-}
-};
-
 int snd_wss_mixer(struct snd_wss *chip)
 {
        struct snd_card *card;
        unsigned int idx;
        int err;
+       int count = ARRAY_SIZE(snd_wss_controls);
 
        if (snd_BUG_ON(!chip || !chip->pcm))
                return -EINVAL;
@@ -2302,28 +2261,19 @@ int snd_wss_mixer(struct snd_wss *chip)
 
        strcpy(card->mixername, chip->pcm->name);
 
-       if (chip->hardware == WSS_HW_OPTI93X)
-               for (idx = 0; idx < ARRAY_SIZE(snd_opti93x_controls); idx++) {
-                       err = snd_ctl_add(card,
-                                       snd_ctl_new1(&snd_opti93x_controls[idx],
-                                                    chip));
-                       if (err < 0)
-                               return err;
-               }
-       else {
-               int count = ARRAY_SIZE(snd_wss_controls);
-
-               /* Use only the first 11 entries on AD1848 */
-               if (chip->hardware & WSS_HW_AD1848_MASK)
-                       count = 11;
-
-               for (idx = 0; idx < count; idx++) {
-                       err = snd_ctl_add(card,
-                                       snd_ctl_new1(&snd_wss_controls[idx],
-                                                    chip));
-                       if (err < 0)
-                               return err;
-               }
+       /* Use only the first 11 entries on AD1848 */
+       if (chip->hardware & WSS_HW_AD1848_MASK)
+               count = 11;
+       /* There is no loopback on OPTI93X */
+       else if (chip->hardware == WSS_HW_OPTI93X)
+               count = 9;
+
+       for (idx = 0; idx < count; idx++) {
+               err = snd_ctl_add(card,
+                               snd_ctl_new1(&snd_wss_controls[idx],
+                                            chip));
+               if (err < 0)
+                       return err;
        }
        return 0;
 }
index f1d9d16..9b486be 100644 (file)
@@ -26,7 +26,6 @@
 #include <linux/delay.h>
 #include <linux/spinlock.h>
 #include <linux/gfp.h>
-#include <linux/vmalloc.h>
 #include <linux/interrupt.h>
 #include <linux/dma-mapping.h>
 #include <linux/platform_device.h>
@@ -603,25 +602,14 @@ static int snd_sgio2audio_pcm_close(struct snd_pcm_substream *substream)
 static int snd_sgio2audio_pcm_hw_params(struct snd_pcm_substream *substream,
                                        struct snd_pcm_hw_params *hw_params)
 {
-       struct snd_pcm_runtime *runtime = substream->runtime;
-       int size = params_buffer_bytes(hw_params);
-
-       /* alloc virtual 'dma' area */
-       if (runtime->dma_area)
-               vfree(runtime->dma_area);
-       runtime->dma_area = vmalloc_user(size);
-       if (runtime->dma_area == NULL)
-               return -ENOMEM;
-       runtime->dma_bytes = size;
-       return 0;
+       return snd_pcm_lib_alloc_vmalloc_buffer(substream,
+                                               params_buffer_bytes(hw_params));
 }
 
 /* hw_free callback */
 static int snd_sgio2audio_pcm_hw_free(struct snd_pcm_substream *substream)
 {
-       vfree(substream->runtime->dma_area);
-       substream->runtime->dma_area = NULL;
-       return 0;
+       return snd_pcm_lib_free_vmalloc_buffer(substream);
 }
 
 /* prepare callback */
@@ -692,13 +680,6 @@ snd_sgio2audio_pcm_pointer(struct snd_pcm_substream *substream)
                               chip->channel[chan->idx].pos);
 }
 
-/* get the physical page pointer on the given offset */
-static struct page *snd_sgio2audio_page(struct snd_pcm_substream *substream,
-                                       unsigned long offset)
-{
-       return vmalloc_to_page(substream->runtime->dma_area + offset);
-}
-
 /* operators */
 static struct snd_pcm_ops snd_sgio2audio_playback1_ops = {
        .open =        snd_sgio2audio_playback1_open,
@@ -709,7 +690,7 @@ static struct snd_pcm_ops snd_sgio2audio_playback1_ops = {
        .prepare =     snd_sgio2audio_pcm_prepare,
        .trigger =     snd_sgio2audio_pcm_trigger,
        .pointer =     snd_sgio2audio_pcm_pointer,
-       .page =        snd_sgio2audio_page,
+       .page =        snd_pcm_lib_get_vmalloc_page,
 };
 
 static struct snd_pcm_ops snd_sgio2audio_playback2_ops = {
@@ -721,7 +702,7 @@ static struct snd_pcm_ops snd_sgio2audio_playback2_ops = {
        .prepare =     snd_sgio2audio_pcm_prepare,
        .trigger =     snd_sgio2audio_pcm_trigger,
        .pointer =     snd_sgio2audio_pcm_pointer,
-       .page =        snd_sgio2audio_page,
+       .page =        snd_pcm_lib_get_vmalloc_page,
 };
 
 static struct snd_pcm_ops snd_sgio2audio_capture_ops = {
@@ -733,7 +714,7 @@ static struct snd_pcm_ops snd_sgio2audio_capture_ops = {
        .prepare =     snd_sgio2audio_pcm_prepare,
        .trigger =     snd_sgio2audio_pcm_trigger,
        .pointer =     snd_sgio2audio_pcm_pointer,
-       .page =        snd_sgio2audio_page,
+       .page =        snd_pcm_lib_get_vmalloc_page,
 };
 
 /*
index 61aaeda..6c3267b 100644 (file)
@@ -328,11 +328,11 @@ static int sound_mixer_ioctl(int mixdev, unsigned int cmd, void __user *arg)
        return mixer_devs[mixdev]->ioctl(mixdev, cmd, arg);
 }
 
-static int sound_ioctl(struct inode *inode, struct file *file,
-                      unsigned int cmd, unsigned long arg)
+static long sound_ioctl(struct file *file, unsigned int cmd, unsigned long arg)
 {
        int len = 0, dtype;
-       int dev = iminor(inode);
+       int dev = iminor(file->f_dentry->d_inode);
+       long ret = -EINVAL;
        void __user *p = (void __user *)arg;
 
        if (_SIOC_DIR(cmd) != _SIOC_NONE && _SIOC_DIR(cmd) != 0) {
@@ -353,6 +353,7 @@ static int sound_ioctl(struct inode *inode, struct file *file,
        if (cmd == OSS_GETVERSION)
                return __put_user(SOUND_VERSION, (int __user *)p);
        
+       lock_kernel();
        if (_IOC_TYPE(cmd) == 'M' && num_mixers > 0 &&   /* Mixer ioctl */
            (dev & 0x0f) != SND_DEV_CTL) {              
                dtype = dev & 0x0f;
@@ -360,24 +361,31 @@ static int sound_ioctl(struct inode *inode, struct file *file,
                case SND_DEV_DSP:
                case SND_DEV_DSP16:
                case SND_DEV_AUDIO:
-                       return sound_mixer_ioctl(audio_devs[dev >> 4]->mixer_dev,
+                       ret = sound_mixer_ioctl(audio_devs[dev >> 4]->mixer_dev,
                                                 cmd, p);
-                       
+                       break;                  
                default:
-                       return sound_mixer_ioctl(dev >> 4, cmd, p);
+                       ret = sound_mixer_ioctl(dev >> 4, cmd, p);
+                       break;
                }
+               unlock_kernel();
+               return ret;
        }
+
        switch (dev & 0x0f) {
        case SND_DEV_CTL:
                if (cmd == SOUND_MIXER_GETLEVELS)
-                       return get_mixer_levels(p);
-               if (cmd == SOUND_MIXER_SETLEVELS)
-                       return set_mixer_levels(p);
-               return sound_mixer_ioctl(dev >> 4, cmd, p);
+                       ret = get_mixer_levels(p);
+               else if (cmd == SOUND_MIXER_SETLEVELS)
+                       ret = set_mixer_levels(p);
+               else
+                       ret = sound_mixer_ioctl(dev >> 4, cmd, p);
+               break;
 
        case SND_DEV_SEQ:
        case SND_DEV_SEQ2:
-               return sequencer_ioctl(dev, file, cmd, p);
+               ret = sequencer_ioctl(dev, file, cmd, p);
+               break;
 
        case SND_DEV_DSP:
        case SND_DEV_DSP16:
@@ -390,7 +398,8 @@ static int sound_ioctl(struct inode *inode, struct file *file,
                break;
 
        }
-       return -EINVAL;
+       unlock_kernel();
+       return ret;
 }
 
 static unsigned int sound_poll(struct file *file, poll_table * wait)
@@ -490,7 +499,7 @@ const struct file_operations oss_sound_fops = {
        .read           = sound_read,
        .write          = sound_write,
        .poll           = sound_poll,
-       .ioctl          = sound_ioctl,
+       .unlocked_ioctl = sound_ioctl,
        .mmap           = sound_mmap,
        .open           = sound_open,
        .release        = sound_release,
index 1be96ea..e6b4a87 100644 (file)
@@ -3597,7 +3597,7 @@ static struct cs_card_type __devinitdata cards[] = {
 #ifdef CONFIG_PM
 static unsigned int saved_regs[] = {
        BA0_ACOSV,
-       BA0_ASER_FADDR,
+       /*BA0_ASER_FADDR,*/
        BA0_ASER_MASTER,
        BA1_PVOL,
        BA1_CVOL,
index f4f0c8f..3e5ca8f 100644 (file)
@@ -298,6 +298,9 @@ void  cs46xx_dsp_spos_destroy (struct snd_cs46xx * chip)
                if (ins->scbs[i].deleted) continue;
 
                cs46xx_dsp_proc_free_scb_desc ( (ins->scbs + i) );
+#ifdef CONFIG_PM
+               kfree(ins->scbs[i].data);
+#endif
        }
 
        kfree(ins->code.data);
@@ -974,13 +977,11 @@ static struct dsp_scb_descriptor * _map_scb (struct snd_cs46xx *chip, char * nam
 
        index = find_free_scb_index (ins);
 
+       memset(&ins->scbs[index], 0, sizeof(ins->scbs[index]));
        strcpy(ins->scbs[index].scb_name, name);
        ins->scbs[index].address = dest;
        ins->scbs[index].index = index;
-       ins->scbs[index].proc_info = NULL;
        ins->scbs[index].ref_count = 1;
-       ins->scbs[index].deleted = 0;
-       spin_lock_init(&ins->scbs[index].lock);
 
        desc = (ins->scbs + index);
        ins->scbs[index].scb_symbol = add_symbol (chip, name, dest, SYMBOL_PARAMETER);
@@ -1022,17 +1023,29 @@ _map_task_tree (struct snd_cs46xx *chip, char * name, u32 dest, u32 size)
        return desc;
 }
 
+#define SCB_BYTES      (0x10 * 4)
+
 struct dsp_scb_descriptor *
 cs46xx_dsp_create_scb (struct snd_cs46xx *chip, char * name, u32 * scb_data, u32 dest)
 {
        struct dsp_scb_descriptor * desc;
 
+#ifdef CONFIG_PM
+       /* copy the data for resume */
+       scb_data = kmemdup(scb_data, SCB_BYTES, GFP_KERNEL);
+       if (!scb_data)
+               return NULL;
+#endif
+
        desc = _map_scb (chip,name,dest);
        if (desc) {
                desc->data = scb_data;
                _dsp_create_scb(chip,scb_data,dest);
        } else {
                snd_printk(KERN_ERR "dsp_spos: failed to map SCB\n");
+#ifdef CONFIG_PM
+               kfree(scb_data);
+#endif
        }
 
        return desc;
@@ -1988,7 +2001,28 @@ int cs46xx_dsp_resume(struct snd_cs46xx * chip)
                        continue;
                _dsp_create_scb(chip, s->data, s->address);
        }
-
+       for (i = 0; i < ins->nscb; i++) {
+               struct dsp_scb_descriptor *s = &ins->scbs[i];
+               if (s->deleted)
+                       continue;
+               if (s->updated)
+                       cs46xx_dsp_spos_update_scb(chip, s);
+               if (s->volume_set)
+                       cs46xx_dsp_scb_set_volume(chip, s,
+                                                 s->volume[0], s->volume[1]);
+       }
+       if (ins->spdif_status_out & DSP_SPDIF_STATUS_HW_ENABLED) {
+               cs46xx_dsp_enable_spdif_hw(chip);
+               snd_cs46xx_poke(chip, (ins->ref_snoop_scb->address + 2) << 2,
+                               (OUTPUT_SNOOP_BUFFER + 0x10) << 0x10);
+               if (ins->spdif_status_out & DSP_SPDIF_STATUS_PLAYBACK_OPEN)
+                       cs46xx_poke_via_dsp(chip, SP_SPDOUT_CSUV,
+                                           ins->spdif_csuv_stream);
+       }
+       if (chip->dsp_spos_instance->spdif_status_in) {
+               cs46xx_poke_via_dsp(chip, SP_ASER_COUNTDOWN, 0x80000005);
+               cs46xx_poke_via_dsp(chip, SP_SPDIN_CONTROL, 0x800003ff);
+       }
        return 0;
 }
 #endif
index f9e169d..ca47a81 100644 (file)
@@ -212,6 +212,7 @@ static inline void cs46xx_dsp_spos_update_scb (struct snd_cs46xx * chip,
                        (scb->address + SCBsubListPtr) << 2,
                        (scb->sub_list_ptr->address << 0x10) |
                        (scb->next_scb_ptr->address));  
+       scb->updated = 1;
 }
 
 static inline void cs46xx_dsp_scb_set_volume (struct snd_cs46xx * chip,
@@ -222,6 +223,9 @@ static inline void cs46xx_dsp_scb_set_volume (struct snd_cs46xx * chip,
 
        snd_cs46xx_poke(chip, (scb->address + SCBVolumeCtrl) << 2, val);
        snd_cs46xx_poke(chip, (scb->address + SCBVolumeCtrl + 1) << 2, val);
+       scb->volume_set = 1;
+       scb->volume[0] = left;
+       scb->volume[1] = right;
 }
 #endif /* __DSP_SPOS_H__ */
 #endif /* CONFIG_SND_CS46XX_NEW_DSP  */
index dd7c41b..00b148a 100644 (file)
@@ -115,7 +115,6 @@ static void cs46xx_dsp_proc_scb_info_read (struct snd_info_entry *entry,
 static void _dsp_unlink_scb (struct snd_cs46xx *chip, struct dsp_scb_descriptor * scb)
 {
        struct dsp_spos_instance * ins = chip->dsp_spos_instance;
-       unsigned long flags;
 
        if ( scb->parent_scb_ptr ) {
                /* unlink parent SCB */
@@ -153,8 +152,6 @@ static void _dsp_unlink_scb (struct snd_cs46xx *chip, struct dsp_scb_descriptor
                        scb->next_scb_ptr = ins->the_null_scb;
                }
 
-               spin_lock_irqsave(&chip->reg_lock, flags);    
-
                /* update parent first entry in DSP RAM */
                cs46xx_dsp_spos_update_scb(chip,scb->parent_scb_ptr);
 
@@ -162,7 +159,6 @@ static void _dsp_unlink_scb (struct snd_cs46xx *chip, struct dsp_scb_descriptor
                cs46xx_dsp_spos_update_scb(chip,scb);
 
                scb->parent_scb_ptr = NULL;
-               spin_unlock_irqrestore(&chip->reg_lock, flags);
        }
 }
 
@@ -197,9 +193,9 @@ void cs46xx_dsp_remove_scb (struct snd_cs46xx *chip, struct dsp_scb_descriptor *
                goto _end;
 #endif
 
-       spin_lock_irqsave(&scb->lock, flags);
+       spin_lock_irqsave(&chip->reg_lock, flags);    
        _dsp_unlink_scb (chip,scb);
-       spin_unlock_irqrestore(&scb->lock, flags);
+       spin_unlock_irqrestore(&chip->reg_lock, flags);
 
        cs46xx_dsp_proc_free_scb_desc(scb);
        if (snd_BUG_ON(!scb->scb_symbol))
@@ -207,6 +203,10 @@ void cs46xx_dsp_remove_scb (struct snd_cs46xx *chip, struct dsp_scb_descriptor *
        remove_symbol (chip,scb->scb_symbol);
 
        ins->scbs[scb->index].deleted = 1;
+#ifdef CONFIG_PM
+       kfree(ins->scbs[scb->index].data);
+       ins->scbs[scb->index].data = NULL;
+#endif
 
        if (scb->index < ins->scb_highest_frag_index)
                ins->scb_highest_frag_index = scb->index;
@@ -1508,20 +1508,17 @@ int cs46xx_dsp_pcm_unlink (struct snd_cs46xx * chip,
                       chip->dsp_spos_instance->npcm_channels <= 0))
                return -EIO;
 
-       spin_lock(&pcm_channel->src_scb->lock);
-
+       spin_lock_irqsave(&chip->reg_lock, flags);
        if (pcm_channel->unlinked) {
-               spin_unlock(&pcm_channel->src_scb->lock);
+               spin_unlock_irqrestore(&chip->reg_lock, flags);
                return -EIO;
        }
 
-       spin_lock_irqsave(&chip->reg_lock, flags);
        pcm_channel->unlinked = 1;
-       spin_unlock_irqrestore(&chip->reg_lock, flags);
 
        _dsp_unlink_scb (chip,pcm_channel->pcm_reader_scb);
+       spin_unlock_irqrestore(&chip->reg_lock, flags);
 
-       spin_unlock(&pcm_channel->src_scb->lock);
        return 0;
 }
 
@@ -1533,10 +1530,10 @@ int cs46xx_dsp_pcm_link (struct snd_cs46xx * chip,
        struct dsp_scb_descriptor * src_scb = pcm_channel->src_scb;
        unsigned long flags;
 
-       spin_lock(&pcm_channel->src_scb->lock);
+       spin_lock_irqsave(&chip->reg_lock, flags);
 
        if (pcm_channel->unlinked == 0) {
-               spin_unlock(&pcm_channel->src_scb->lock);
+               spin_unlock_irqrestore(&chip->reg_lock, flags);
                return -EIO;
        }
 
@@ -1552,8 +1549,6 @@ int cs46xx_dsp_pcm_link (struct snd_cs46xx * chip,
        snd_BUG_ON(pcm_channel->pcm_reader_scb->parent_scb_ptr);
        pcm_channel->pcm_reader_scb->parent_scb_ptr = parent_scb;
 
-       spin_lock_irqsave(&chip->reg_lock, flags);
-
        /* update SCB entry in DSP RAM */
        cs46xx_dsp_spos_update_scb(chip,pcm_channel->pcm_reader_scb);
 
@@ -1562,8 +1557,6 @@ int cs46xx_dsp_pcm_link (struct snd_cs46xx * chip,
 
        pcm_channel->unlinked = 0;
        spin_unlock_irqrestore(&chip->reg_lock, flags);
-
-       spin_unlock(&pcm_channel->src_scb->lock);
        return 0;
 }
 
@@ -1596,13 +1589,17 @@ cs46xx_add_record_source (struct snd_cs46xx *chip, struct dsp_scb_descriptor * s
 
 int cs46xx_src_unlink(struct snd_cs46xx *chip, struct dsp_scb_descriptor * src)
 {
+       unsigned long flags;
+
        if (snd_BUG_ON(!src->parent_scb_ptr))
                return -EINVAL;
 
        /* mute SCB */
        cs46xx_dsp_scb_set_volume (chip,src,0,0);
 
+       spin_lock_irqsave(&chip->reg_lock, flags);
        _dsp_unlink_scb (chip,src);
+       spin_unlock_irqrestore(&chip->reg_lock, flags);
 
        return 0;
 }
index 5cfa608..0afa683 100644 (file)
@@ -21,7 +21,6 @@
  */
 
 #include <linux/slab.h>
-#include <linux/vmalloc.h>
 #include <linux/delay.h>
 #include <sound/core.h>
 #include <sound/asoundef.h>
 
 
 /*
- * we use a vmalloc'ed (sg-)buffer
- */
-
-/* get the physical page pointer on the given offset */
-static struct page *snd_pcm_get_vmalloc_page(struct snd_pcm_substream *subs, unsigned long offset)
-{
-       void *pageptr = subs->runtime->dma_area + offset;
-       return vmalloc_to_page(pageptr);
-}
-
-/*
- * hw_params callback
- * NOTE: this may be called not only once per pcm open!
- */
-static int snd_pcm_alloc_vmalloc_buffer(struct snd_pcm_substream *subs, size_t size)
-{
-       struct snd_pcm_runtime *runtime = subs->runtime;
-       if (runtime->dma_area) {
-               if (runtime->dma_bytes >= size)
-                       return 0; /* already enough large */
-               vfree(runtime->dma_area);
-       }
-       runtime->dma_area = vmalloc_32_user(size);
-       if (! runtime->dma_area)
-               return -ENOMEM;
-       runtime->dma_bytes = size;
-       return 0;
-}
-
-/*
- * hw_free callback
- * NOTE: this may be called not only once per pcm open!
- */
-static int snd_pcm_free_vmalloc_buffer(struct snd_pcm_substream *subs)
-{
-       struct snd_pcm_runtime *runtime = subs->runtime;
-
-       vfree(runtime->dma_area);
-       runtime->dma_area = NULL;
-       return 0;
-}
-
-/*
  * clear the SRAM contents
  */
 static int pdacf_pcm_clear_sram(struct snd_pdacf *chip)
@@ -147,7 +103,8 @@ static int pdacf_pcm_trigger(struct snd_pcm_substream *subs, int cmd)
 static int pdacf_pcm_hw_params(struct snd_pcm_substream *subs,
                                     struct snd_pcm_hw_params *hw_params)
 {
-       return snd_pcm_alloc_vmalloc_buffer(subs, params_buffer_bytes(hw_params));
+       return snd_pcm_lib_alloc_vmalloc_32_buffer
+                                       (subs, params_buffer_bytes(hw_params));
 }
 
 /*
@@ -155,7 +112,7 @@ static int pdacf_pcm_hw_params(struct snd_pcm_substream *subs,
  */
 static int pdacf_pcm_hw_free(struct snd_pcm_substream *subs)
 {
-       return snd_pcm_free_vmalloc_buffer(subs);
+       return snd_pcm_lib_free_vmalloc_buffer(subs);
 }
 
 /*
@@ -319,7 +276,7 @@ static struct snd_pcm_ops pdacf_pcm_capture_ops = {
        .prepare =      pdacf_pcm_prepare,
        .trigger =      pdacf_pcm_trigger,
        .pointer =      pdacf_pcm_capture_pointer,
-       .page =         snd_pcm_get_vmalloc_page,
+       .page =         snd_pcm_lib_get_vmalloc_page,
 };
 
 
index 73525c0..8c29258 100644 (file)
@@ -21,6 +21,18 @@ config SND_USB_AUDIO
          To compile this driver as a module, choose M here: the module
          will be called snd-usb-audio.
 
+config SND_USB_UA101
+       tristate "Edirol UA-101 driver (EXPERIMENTAL)"
+       depends on EXPERIMENTAL
+       select SND_PCM
+       select SND_RAWMIDI
+       help
+         Say Y here to include support for the Edirol UA-101 audio/MIDI
+         interface.
+
+         To compile this driver as a module, choose M here: the module
+         will be called snd-ua101.
+
 config SND_USB_USX2Y
        tristate "Tascam US-122, US-224 and US-428 USB driver"
        depends on X86 || PPC || ALPHA
index abb288b..5bf64ae 100644 (file)
@@ -4,9 +4,11 @@
 
 snd-usb-audio-objs := usbaudio.o usbmixer.o
 snd-usb-lib-objs := usbmidi.o
+snd-ua101-objs := ua101.o
 
 # Toplevel Module Dependency
 obj-$(CONFIG_SND_USB_AUDIO) += snd-usb-audio.o snd-usb-lib.o
+obj-$(CONFIG_SND_USB_UA101) += snd-ua101.o snd-usb-lib.o
 obj-$(CONFIG_SND_USB_USX2Y) += snd-usb-lib.o
 obj-$(CONFIG_SND_USB_US122L) += snd-usb-lib.o
 
diff --git a/sound/usb/ua101.c b/sound/usb/ua101.c
new file mode 100644 (file)
index 0000000..16dc7bd
--- /dev/null
@@ -0,0 +1,1419 @@
+/*
+ * Edirol UA-101 driver
+ * Copyright (c) Clemens Ladisch <clemens@ladisch.de>
+ *
+ * This driver is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License, version 2.
+ *
+ * This driver is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this driver.  If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#include <linux/init.h>
+#include <linux/module.h>
+#include <linux/slab.h>
+#include <linux/usb.h>
+#include <linux/usb/audio.h>
+#include <sound/core.h>
+#include <sound/initval.h>
+#include <sound/pcm.h>
+#include <sound/pcm_params.h>
+#include "usbaudio.h"
+
+MODULE_DESCRIPTION("Edirol UA-101 driver");
+MODULE_AUTHOR("Clemens Ladisch <clemens@ladisch.de>");
+MODULE_LICENSE("GPL v2");
+MODULE_SUPPORTED_DEVICE("{{Edirol,UA-101}}");
+
+/* I use my UA-1A for testing because I don't have a UA-101 ... */
+#define UA1A_HACK
+
+/*
+ * Should not be lower than the minimum scheduling delay of the host
+ * controller.  Some Intel controllers need more than one frame; as long as
+ * that driver doesn't tell us about this, use 1.5 frames just to be sure.
+ */
+#define MIN_QUEUE_LENGTH       12
+/* Somewhat random. */
+#define MAX_QUEUE_LENGTH       30
+/*
+ * This magic value optimizes memory usage efficiency for the UA-101's packet
+ * sizes at all sample rates, taking into account the stupid cache pool sizes
+ * that usb_buffer_alloc() uses.
+ */
+#define DEFAULT_QUEUE_LENGTH   21
+
+#define MAX_PACKET_SIZE                672 /* hardware specific */
+#define MAX_MEMORY_BUFFERS     DIV_ROUND_UP(MAX_QUEUE_LENGTH, \
+                                            PAGE_SIZE / MAX_PACKET_SIZE)
+
+static int index[SNDRV_CARDS] = SNDRV_DEFAULT_IDX;
+static char *id[SNDRV_CARDS] = SNDRV_DEFAULT_STR;
+static int enable[SNDRV_CARDS] = SNDRV_DEFAULT_ENABLE_PNP;
+static unsigned int queue_length = 21;
+
+module_param_array(index, int, NULL, 0444);
+MODULE_PARM_DESC(index, "card index");
+module_param_array(id, charp, NULL, 0444);
+MODULE_PARM_DESC(id, "ID string");
+module_param_array(enable, bool, NULL, 0444);
+MODULE_PARM_DESC(enable, "enable card");
+module_param(queue_length, uint, 0644);
+MODULE_PARM_DESC(queue_length, "USB queue length in microframes, "
+                __stringify(MIN_QUEUE_LENGTH)"-"__stringify(MAX_QUEUE_LENGTH));
+
+enum {
+       INTF_PLAYBACK,
+       INTF_CAPTURE,
+       INTF_MIDI,
+
+       INTF_COUNT
+};
+
+/* bits in struct ua101::states */
+enum {
+       USB_CAPTURE_RUNNING,
+       USB_PLAYBACK_RUNNING,
+       ALSA_CAPTURE_OPEN,
+       ALSA_PLAYBACK_OPEN,
+       ALSA_CAPTURE_RUNNING,
+       ALSA_PLAYBACK_RUNNING,
+       CAPTURE_URB_COMPLETED,
+       PLAYBACK_URB_COMPLETED,
+       DISCONNECTED,
+};
+
+struct ua101 {
+       struct usb_device *dev;
+       struct snd_card *card;
+       struct usb_interface *intf[INTF_COUNT];
+       int card_index;
+       struct snd_pcm *pcm;
+       struct list_head midi_list;
+       u64 format_bit;
+       unsigned int rate;
+       unsigned int packets_per_second;
+       spinlock_t lock;
+       struct mutex mutex;
+       unsigned long states;
+
+       /* FIFO to synchronize playback rate to capture rate */
+       unsigned int rate_feedback_start;
+       unsigned int rate_feedback_count;
+       u8 rate_feedback[MAX_QUEUE_LENGTH];
+
+       struct list_head ready_playback_urbs;
+       struct tasklet_struct playback_tasklet;
+       wait_queue_head_t alsa_capture_wait;
+       wait_queue_head_t rate_feedback_wait;
+       wait_queue_head_t alsa_playback_wait;
+       struct ua101_stream {
+               struct snd_pcm_substream *substream;
+               unsigned int usb_pipe;
+               unsigned int channels;
+               unsigned int frame_bytes;
+               unsigned int max_packet_bytes;
+               unsigned int period_pos;
+               unsigned int buffer_pos;
+               unsigned int queue_length;
+               struct ua101_urb {
+                       struct urb urb;
+                       struct usb_iso_packet_descriptor iso_frame_desc[1];
+                       struct list_head ready_list;
+               } *urbs[MAX_QUEUE_LENGTH];
+               struct {
+                       unsigned int size;
+                       void *addr;
+                       dma_addr_t dma;
+               } buffers[MAX_MEMORY_BUFFERS];
+       } capture, playback;
+
+       unsigned int fps[10];
+       unsigned int frame_counter;
+};
+
+static DEFINE_MUTEX(devices_mutex);
+static unsigned int devices_used;
+static struct usb_driver ua101_driver;
+
+static void abort_alsa_playback(struct ua101 *ua);
+static void abort_alsa_capture(struct ua101 *ua);
+
+static const char *usb_error_string(int err)
+{
+       switch (err) {
+       case -ENODEV:
+               return "no device";
+       case -ENOENT:
+               return "endpoint not enabled";
+       case -EPIPE:
+               return "endpoint stalled";
+       case -ENOSPC:
+               return "not enough bandwidth";
+       case -ESHUTDOWN:
+               return "device disabled";
+       case -EHOSTUNREACH:
+               return "device suspended";
+       case -EINVAL:
+       case -EAGAIN:
+       case -EFBIG:
+       case -EMSGSIZE:
+               return "internal error";
+       default:
+               return "unknown error";
+       }
+}
+
+static void abort_usb_capture(struct ua101 *ua)
+{
+       if (test_and_clear_bit(USB_CAPTURE_RUNNING, &ua->states)) {
+               wake_up(&ua->alsa_capture_wait);
+               wake_up(&ua->rate_feedback_wait);
+       }
+}
+
+static void abort_usb_playback(struct ua101 *ua)
+{
+       if (test_and_clear_bit(USB_PLAYBACK_RUNNING, &ua->states))
+               wake_up(&ua->alsa_playback_wait);
+}
+
+static void playback_urb_complete(struct urb *usb_urb)
+{
+       struct ua101_urb *urb = (struct ua101_urb *)usb_urb;
+       struct ua101 *ua = urb->urb.context;
+       unsigned long flags;
+
+       if (unlikely(urb->urb.status == -ENOENT ||      /* unlinked */
+                    urb->urb.status == -ENODEV ||      /* device removed */
+                    urb->urb.status == -ECONNRESET ||  /* unlinked */
+                    urb->urb.status == -ESHUTDOWN)) {  /* device disabled */
+               abort_usb_playback(ua);
+               abort_alsa_playback(ua);
+               return;
+       }
+
+       if (test_bit(USB_PLAYBACK_RUNNING, &ua->states)) {
+               /* append URB to FIFO */
+               spin_lock_irqsave(&ua->lock, flags);
+               list_add_tail(&urb->ready_list, &ua->ready_playback_urbs);
+               if (ua->rate_feedback_count > 0)
+                       tasklet_schedule(&ua->playback_tasklet);
+               ua->playback.substream->runtime->delay -=
+                               urb->urb.iso_frame_desc[0].length /
+                                               ua->playback.frame_bytes;
+               spin_unlock_irqrestore(&ua->lock, flags);
+       }
+}
+
+static void first_playback_urb_complete(struct urb *urb)
+{
+       struct ua101 *ua = urb->context;
+
+       urb->complete = playback_urb_complete;
+       playback_urb_complete(urb);
+
+       set_bit(PLAYBACK_URB_COMPLETED, &ua->states);
+       wake_up(&ua->alsa_playback_wait);
+}
+
+/* copy data from the ALSA ring buffer into the URB buffer */
+static bool copy_playback_data(struct ua101_stream *stream, struct urb *urb,
+                              unsigned int frames)
+{
+       struct snd_pcm_runtime *runtime;
+       unsigned int frame_bytes, frames1;
+       const u8 *source;
+
+       runtime = stream->substream->runtime;
+       frame_bytes = stream->frame_bytes;
+       source = runtime->dma_area + stream->buffer_pos * frame_bytes;
+       if (stream->buffer_pos + frames <= runtime->buffer_size) {
+               memcpy(urb->transfer_buffer, source, frames * frame_bytes);
+       } else {
+               /* wrap around at end of ring buffer */
+               frames1 = runtime->buffer_size - stream->buffer_pos;
+               memcpy(urb->transfer_buffer, source, frames1 * frame_bytes);
+               memcpy(urb->transfer_buffer + frames1 * frame_bytes,
+                      runtime->dma_area, (frames - frames1) * frame_bytes);
+       }
+
+       stream->buffer_pos += frames;
+       if (stream->buffer_pos >= runtime->buffer_size)
+               stream->buffer_pos -= runtime->buffer_size;
+       stream->period_pos += frames;
+       if (stream->period_pos >= runtime->period_size) {
+               stream->period_pos -= runtime->period_size;
+               return true;
+       }
+       return false;
+}
+
+static inline void add_with_wraparound(struct ua101 *ua,
+                                      unsigned int *value, unsigned int add)
+{
+       *value += add;
+       if (*value >= ua->playback.queue_length)
+               *value -= ua->playback.queue_length;
+}
+
+static void playback_tasklet(unsigned long data)
+{
+       struct ua101 *ua = (void *)data;
+       unsigned long flags;
+       unsigned int frames;
+       struct ua101_urb *urb;
+       bool do_period_elapsed = false;
+       int err;
+
+       if (unlikely(!test_bit(USB_PLAYBACK_RUNNING, &ua->states)))
+               return;
+
+       /*
+        * Synchronizing the playback rate to the capture rate is done by using
+        * the same sequence of packet sizes for both streams.
+        * Submitting a playback URB therefore requires both a ready URB and
+        * the size of the corresponding capture packet, i.e., both playback
+        * and capture URBs must have been completed.  Since the USB core does
+        * not guarantee that playback and capture complete callbacks are
+        * called alternately, we use two FIFOs for packet sizes and read URBs;
+        * submitting playback URBs is possible as long as both FIFOs are
+        * nonempty.
+        */
+       spin_lock_irqsave(&ua->lock, flags);
+       while (ua->rate_feedback_count > 0 &&
+              !list_empty(&ua->ready_playback_urbs)) {
+               /* take packet size out of FIFO */
+               frames = ua->rate_feedback[ua->rate_feedback_start];
+               add_with_wraparound(ua, &ua->rate_feedback_start, 1);
+               ua->rate_feedback_count--;
+
+               /* take URB out of FIFO */
+               urb = list_first_entry(&ua->ready_playback_urbs,
+                                      struct ua101_urb, ready_list);
+               list_del(&urb->ready_list);
+
+               /* fill packet with data or silence */
+               urb->urb.iso_frame_desc[0].length =
+                       frames * ua->playback.frame_bytes;
+               if (test_bit(ALSA_PLAYBACK_RUNNING, &ua->states))
+                       do_period_elapsed |= copy_playback_data(&ua->playback,
+                                                               &urb->urb,
+                                                               frames);
+               else
+                       memset(urb->urb.transfer_buffer, 0,
+                              urb->urb.iso_frame_desc[0].length);
+
+               /* and off you go ... */
+               err = usb_submit_urb(&urb->urb, GFP_ATOMIC);
+               if (unlikely(err < 0)) {
+                       spin_unlock_irqrestore(&ua->lock, flags);
+                       abort_usb_playback(ua);
+                       abort_alsa_playback(ua);
+                       dev_err(&ua->dev->dev, "USB request error %d: %s\n",
+                               err, usb_error_string(err));
+                       return;
+               }
+               ua->playback.substream->runtime->delay += frames;
+       }
+       spin_unlock_irqrestore(&ua->lock, flags);
+       if (do_period_elapsed)
+               snd_pcm_period_elapsed(ua->playback.substream);
+}
+
+/* copy data from the URB buffer into the ALSA ring buffer */
+static bool copy_capture_data(struct ua101_stream *stream, struct urb *urb,
+                             unsigned int frames)
+{
+       struct snd_pcm_runtime *runtime;
+       unsigned int frame_bytes, frames1;
+       u8 *dest;
+
+       runtime = stream->substream->runtime;
+       frame_bytes = stream->frame_bytes;
+       dest = runtime->dma_area + stream->buffer_pos * frame_bytes;
+       if (stream->buffer_pos + frames <= runtime->buffer_size) {
+               memcpy(dest, urb->transfer_buffer, frames * frame_bytes);
+       } else {
+               /* wrap around at end of ring buffer */
+               frames1 = runtime->buffer_size - stream->buffer_pos;
+               memcpy(dest, urb->transfer_buffer, frames1 * frame_bytes);
+               memcpy(runtime->dma_area,
+                      urb->transfer_buffer + frames1 * frame_bytes,
+                      (frames - frames1) * frame_bytes);
+       }
+
+       stream->buffer_pos += frames;
+       if (stream->buffer_pos >= runtime->buffer_size)
+               stream->buffer_pos -= runtime->buffer_size;
+       stream->period_pos += frames;
+       if (stream->period_pos >= runtime->period_size) {
+               stream->period_pos -= runtime->period_size;
+               return true;
+       }
+       return false;
+}
+
+static void capture_urb_complete(struct urb *urb)
+{
+       struct ua101 *ua = urb->context;
+       struct ua101_stream *stream = &ua->capture;
+       unsigned long flags;
+       unsigned int frames, write_ptr;
+       bool do_period_elapsed;
+       int err;
+
+       if (unlikely(urb->status == -ENOENT ||          /* unlinked */
+                    urb->status == -ENODEV ||          /* device removed */
+                    urb->status == -ECONNRESET ||      /* unlinked */
+                    urb->status == -ESHUTDOWN))        /* device disabled */
+               goto stream_stopped;
+
+       if (urb->status >= 0 && urb->iso_frame_desc[0].status >= 0)
+               frames = urb->iso_frame_desc[0].actual_length /
+                       stream->frame_bytes;
+       else
+               frames = 0;
+
+       spin_lock_irqsave(&ua->lock, flags);
+
+       if (frames > 0 && test_bit(ALSA_CAPTURE_RUNNING, &ua->states))
+               do_period_elapsed = copy_capture_data(stream, urb, frames);
+       else
+               do_period_elapsed = false;
+
+       if (test_bit(USB_CAPTURE_RUNNING, &ua->states)) {
+               err = usb_submit_urb(urb, GFP_ATOMIC);
+               if (unlikely(err < 0)) {
+                       spin_unlock_irqrestore(&ua->lock, flags);
+                       dev_err(&ua->dev->dev, "USB request error %d: %s\n",
+                               err, usb_error_string(err));
+                       goto stream_stopped;
+               }
+
+               /* append packet size to FIFO */
+               write_ptr = ua->rate_feedback_start;
+               add_with_wraparound(ua, &write_ptr, ua->rate_feedback_count);
+               ua->rate_feedback[write_ptr] = frames;
+               if (ua->rate_feedback_count < ua->playback.queue_length) {
+                       ua->rate_feedback_count++;
+                       if (ua->rate_feedback_count ==
+                                               ua->playback.queue_length)
+                               wake_up(&ua->rate_feedback_wait);
+               } else {
+                       /*
+                        * Ring buffer overflow; this happens when the playback
+                        * stream is not running.  Throw away the oldest entry,
+                        * so that the playback stream, when it starts, sees
+                        * the most recent packet sizes.
+                        */
+                       add_with_wraparound(ua, &ua->rate_feedback_start, 1);
+               }
+               if (test_bit(USB_PLAYBACK_RUNNING, &ua->states) &&
+                   !list_empty(&ua->ready_playback_urbs))
+                       tasklet_schedule(&ua->playback_tasklet);
+       }
+
+       spin_unlock_irqrestore(&ua->lock, flags);
+
+       if (do_period_elapsed)
+               snd_pcm_period_elapsed(stream->substream);
+
+       /* for debugging: measure the sample rate relative to the USB clock */
+       ua->fps[ua->frame_counter++ / ua->packets_per_second] += frames;
+       if (ua->frame_counter >= ARRAY_SIZE(ua->fps) * ua->packets_per_second) {
+               printk(KERN_DEBUG "capture rate:");
+               for (frames = 0; frames < ARRAY_SIZE(ua->fps); ++frames)
+                       printk(KERN_CONT " %u", ua->fps[frames]);
+               printk(KERN_CONT "\n");
+               memset(ua->fps, 0, sizeof(ua->fps));
+               ua->frame_counter = 0;
+       }
+       return;
+
+stream_stopped:
+       abort_usb_playback(ua);
+       abort_usb_capture(ua);
+       abort_alsa_playback(ua);
+       abort_alsa_capture(ua);
+}
+
+static void first_capture_urb_complete(struct urb *urb)
+{
+       struct ua101 *ua = urb->context;
+
+       urb->complete = capture_urb_complete;
+       capture_urb_complete(urb);
+
+       set_bit(CAPTURE_URB_COMPLETED, &ua->states);
+       wake_up(&ua->alsa_capture_wait);
+}
+
+static int submit_stream_urbs(struct ua101 *ua, struct ua101_stream *stream)
+{
+       unsigned int i;
+
+       for (i = 0; i < stream->queue_length; ++i) {
+               int err = usb_submit_urb(&stream->urbs[i]->urb, GFP_KERNEL);
+               if (err < 0) {
+                       dev_err(&ua->dev->dev, "USB request error %d: %s\n",
+                               err, usb_error_string(err));
+                       return err;
+               }
+       }
+       return 0;
+}
+
+static void kill_stream_urbs(struct ua101_stream *stream)
+{
+       unsigned int i;
+
+       for (i = 0; i < stream->queue_length; ++i)
+               usb_kill_urb(&stream->urbs[i]->urb);
+}
+
+static int enable_iso_interface(struct ua101 *ua, unsigned int intf_index)
+{
+       struct usb_host_interface *alts;
+
+       alts = ua->intf[intf_index]->cur_altsetting;
+       if (alts->desc.bAlternateSetting != 1) {
+               int err = usb_set_interface(ua->dev,
+                                           alts->desc.bInterfaceNumber, 1);
+               if (err < 0) {
+                       dev_err(&ua->dev->dev,
+                               "cannot initialize interface; error %d: %s\n",
+                               err, usb_error_string(err));
+                       return err;
+               }
+       }
+       return 0;
+}
+
+static void disable_iso_interface(struct ua101 *ua, unsigned int intf_index)
+{
+       struct usb_host_interface *alts;
+
+       alts = ua->intf[intf_index]->cur_altsetting;
+       if (alts->desc.bAlternateSetting != 0) {
+               int err = usb_set_interface(ua->dev,
+                                           alts->desc.bInterfaceNumber, 0);
+               if (err < 0 && !test_bit(DISCONNECTED, &ua->states))
+                       dev_warn(&ua->dev->dev,
+                                "interface reset failed; error %d: %s\n",
+                                err, usb_error_string(err));
+       }
+}
+
+static void stop_usb_capture(struct ua101 *ua)
+{
+       clear_bit(USB_CAPTURE_RUNNING, &ua->states);
+
+       kill_stream_urbs(&ua->capture);
+
+       disable_iso_interface(ua, INTF_CAPTURE);
+}
+
+static int start_usb_capture(struct ua101 *ua)
+{
+       int err;
+
+       if (test_bit(DISCONNECTED, &ua->states))
+               return -ENODEV;
+
+       if (test_bit(USB_CAPTURE_RUNNING, &ua->states))
+               return 0;
+
+       kill_stream_urbs(&ua->capture);
+
+       err = enable_iso_interface(ua, INTF_CAPTURE);
+       if (err < 0)
+               return err;
+
+       clear_bit(CAPTURE_URB_COMPLETED, &ua->states);
+       ua->capture.urbs[0]->urb.complete = first_capture_urb_complete;
+       ua->rate_feedback_start = 0;
+       ua->rate_feedback_count = 0;
+
+       set_bit(USB_CAPTURE_RUNNING, &ua->states);
+       err = submit_stream_urbs(ua, &ua->capture);
+       if (err < 0)
+               stop_usb_capture(ua);
+       return err;
+}
+
+static void stop_usb_playback(struct ua101 *ua)
+{
+       clear_bit(USB_PLAYBACK_RUNNING, &ua->states);
+
+       kill_stream_urbs(&ua->playback);
+
+       tasklet_kill(&ua->playback_tasklet);
+
+       disable_iso_interface(ua, INTF_PLAYBACK);
+}
+
+static int start_usb_playback(struct ua101 *ua)
+{
+       unsigned int i, frames;
+       struct urb *urb;
+       int err = 0;
+
+       if (test_bit(DISCONNECTED, &ua->states))
+               return -ENODEV;
+
+       if (test_bit(USB_PLAYBACK_RUNNING, &ua->states))
+               return 0;
+
+       kill_stream_urbs(&ua->playback);
+       tasklet_kill(&ua->playback_tasklet);
+
+       err = enable_iso_interface(ua, INTF_PLAYBACK);
+       if (err < 0)
+               return err;
+
+       clear_bit(PLAYBACK_URB_COMPLETED, &ua->states);
+       ua->playback.urbs[0]->urb.complete =
+               first_playback_urb_complete;
+       spin_lock_irq(&ua->lock);
+       INIT_LIST_HEAD(&ua->ready_playback_urbs);
+       spin_unlock_irq(&ua->lock);
+
+       /*
+        * We submit the initial URBs all at once, so we have to wait for the
+        * packet size FIFO to be full.
+        */
+       wait_event(ua->rate_feedback_wait,
+                  ua->rate_feedback_count >= ua->playback.queue_length ||
+                  !test_bit(USB_CAPTURE_RUNNING, &ua->states) ||
+                  test_bit(DISCONNECTED, &ua->states));
+       if (test_bit(DISCONNECTED, &ua->states)) {
+               stop_usb_playback(ua);
+               return -ENODEV;
+       }
+       if (!test_bit(USB_CAPTURE_RUNNING, &ua->states)) {
+               stop_usb_playback(ua);
+               return -EIO;
+       }
+
+       for (i = 0; i < ua->playback.queue_length; ++i) {
+               /* all initial URBs contain silence */
+               spin_lock_irq(&ua->lock);
+               frames = ua->rate_feedback[ua->rate_feedback_start];
+               add_with_wraparound(ua, &ua->rate_feedback_start, 1);
+               ua->rate_feedback_count--;
+               spin_unlock_irq(&ua->lock);
+               urb = &ua->playback.urbs[i]->urb;
+               urb->iso_frame_desc[0].length =
+                       frames * ua->playback.frame_bytes;
+               memset(urb->transfer_buffer, 0,
+                      urb->iso_frame_desc[0].length);
+       }
+
+       set_bit(USB_PLAYBACK_RUNNING, &ua->states);
+       err = submit_stream_urbs(ua, &ua->playback);
+       if (err < 0)
+               stop_usb_playback(ua);
+       return err;
+}
+
+static void abort_alsa_capture(struct ua101 *ua)
+{
+       if (test_bit(ALSA_CAPTURE_RUNNING, &ua->states))
+               snd_pcm_stop(ua->capture.substream, SNDRV_PCM_STATE_XRUN);
+}
+
+static void abort_alsa_playback(struct ua101 *ua)
+{
+       if (test_bit(ALSA_PLAYBACK_RUNNING, &ua->states))
+               snd_pcm_stop(ua->playback.substream, SNDRV_PCM_STATE_XRUN);
+}
+
+static int set_stream_hw(struct ua101 *ua, struct snd_pcm_substream *substream,
+                        unsigned int channels)
+{
+       int err;
+
+       substream->runtime->hw.info =
+               SNDRV_PCM_INFO_MMAP |
+               SNDRV_PCM_INFO_MMAP_VALID |
+               SNDRV_PCM_INFO_BATCH |
+               SNDRV_PCM_INFO_INTERLEAVED |
+               SNDRV_PCM_INFO_BLOCK_TRANSFER |
+               SNDRV_PCM_INFO_FIFO_IN_FRAMES;
+       substream->runtime->hw.formats = ua->format_bit;
+       substream->runtime->hw.rates = snd_pcm_rate_to_rate_bit(ua->rate);
+       substream->runtime->hw.rate_min = ua->rate;
+       substream->runtime->hw.rate_max = ua->rate;
+       substream->runtime->hw.channels_min = channels;
+       substream->runtime->hw.channels_max = channels;
+       substream->runtime->hw.buffer_bytes_max = 45000 * 1024;
+       substream->runtime->hw.period_bytes_min = 1;
+       substream->runtime->hw.period_bytes_max = UINT_MAX;
+       substream->runtime->hw.periods_min = 2;
+       substream->runtime->hw.periods_max = UINT_MAX;
+       err = snd_pcm_hw_constraint_minmax(substream->runtime,
+                                          SNDRV_PCM_HW_PARAM_PERIOD_TIME,
+                                          1500000 / ua->packets_per_second,
+                                          8192000);
+       if (err < 0)
+               return err;
+       err = snd_pcm_hw_constraint_msbits(substream->runtime, 0, 32, 24);
+       return err;
+}
+
+static int capture_pcm_open(struct snd_pcm_substream *substream)
+{
+       struct ua101 *ua = substream->private_data;
+       int err;
+
+       ua->capture.substream = substream;
+       err = set_stream_hw(ua, substream, ua->capture.channels);
+       if (err < 0)
+               return err;
+       substream->runtime->hw.fifo_size =
+               DIV_ROUND_CLOSEST(ua->rate, ua->packets_per_second);
+       substream->runtime->delay = substream->runtime->hw.fifo_size;
+
+       mutex_lock(&ua->mutex);
+       err = start_usb_capture(ua);
+       if (err >= 0)
+               set_bit(ALSA_CAPTURE_OPEN, &ua->states);
+       mutex_unlock(&ua->mutex);
+       return err;
+}
+
+static int playback_pcm_open(struct snd_pcm_substream *substream)
+{
+       struct ua101 *ua = substream->private_data;
+       int err;
+
+       ua->playback.substream = substream;
+       err = set_stream_hw(ua, substream, ua->playback.channels);
+       if (err < 0)
+               return err;
+       substream->runtime->hw.fifo_size =
+               DIV_ROUND_CLOSEST(ua->rate * ua->playback.queue_length,
+                                 ua->packets_per_second);
+
+       mutex_lock(&ua->mutex);
+       err = start_usb_capture(ua);
+       if (err < 0)
+               goto error;
+       err = start_usb_playback(ua);
+       if (err < 0) {
+               if (!test_bit(ALSA_CAPTURE_OPEN, &ua->states))
+                       stop_usb_capture(ua);
+               goto error;
+       }
+       set_bit(ALSA_PLAYBACK_OPEN, &ua->states);
+error:
+       mutex_unlock(&ua->mutex);
+       return err;
+}
+
+static int capture_pcm_close(struct snd_pcm_substream *substream)
+{
+       struct ua101 *ua = substream->private_data;
+
+       mutex_lock(&ua->mutex);
+       clear_bit(ALSA_CAPTURE_OPEN, &ua->states);
+       if (!test_bit(ALSA_PLAYBACK_OPEN, &ua->states))
+               stop_usb_capture(ua);
+       mutex_unlock(&ua->mutex);
+       return 0;
+}
+
+static int playback_pcm_close(struct snd_pcm_substream *substream)
+{
+       struct ua101 *ua = substream->private_data;
+
+       mutex_lock(&ua->mutex);
+       stop_usb_playback(ua);
+       clear_bit(ALSA_PLAYBACK_OPEN, &ua->states);
+       if (!test_bit(ALSA_CAPTURE_OPEN, &ua->states))
+               stop_usb_capture(ua);
+       mutex_unlock(&ua->mutex);
+       return 0;
+}
+
+static int capture_pcm_hw_params(struct snd_pcm_substream *substream,
+                                struct snd_pcm_hw_params *hw_params)
+{
+       struct ua101 *ua = substream->private_data;
+       int err;
+
+       mutex_lock(&ua->mutex);
+       err = start_usb_capture(ua);
+       mutex_unlock(&ua->mutex);
+       if (err < 0)
+               return err;
+
+       return snd_pcm_lib_alloc_vmalloc_buffer(substream,
+                                               params_buffer_bytes(hw_params));
+}
+
+static int playback_pcm_hw_params(struct snd_pcm_substream *substream,
+                                 struct snd_pcm_hw_params *hw_params)
+{
+       struct ua101 *ua = substream->private_data;
+       int err;
+
+       mutex_lock(&ua->mutex);
+       err = start_usb_capture(ua);
+       if (err >= 0)
+               err = start_usb_playback(ua);
+       mutex_unlock(&ua->mutex);
+       if (err < 0)
+               return err;
+
+       return snd_pcm_lib_alloc_vmalloc_buffer(substream,
+                                               params_buffer_bytes(hw_params));
+}
+
+static int ua101_pcm_hw_free(struct snd_pcm_substream *substream)
+{
+       return snd_pcm_lib_free_vmalloc_buffer(substream);
+}
+
+static int capture_pcm_prepare(struct snd_pcm_substream *substream)
+{
+       struct ua101 *ua = substream->private_data;
+       int err;
+
+       mutex_lock(&ua->mutex);
+       err = start_usb_capture(ua);
+       mutex_unlock(&ua->mutex);
+       if (err < 0)
+               return err;
+
+       /*
+        * The EHCI driver schedules the first packet of an iso stream at 10 ms
+        * in the future, i.e., no data is actually captured for that long.
+        * Take the wait here so that the stream is known to be actually
+        * running when the start trigger has been called.
+        */
+       wait_event(ua->alsa_capture_wait,
+                  test_bit(CAPTURE_URB_COMPLETED, &ua->states) ||
+                  !test_bit(USB_CAPTURE_RUNNING, &ua->states));
+       if (test_bit(DISCONNECTED, &ua->states))
+               return -ENODEV;
+       if (!test_bit(USB_CAPTURE_RUNNING, &ua->states))
+               return -EIO;
+
+       ua->capture.period_pos = 0;
+       ua->capture.buffer_pos = 0;
+       return 0;
+}
+
+static int playback_pcm_prepare(struct snd_pcm_substream *substream)
+{
+       struct ua101 *ua = substream->private_data;
+       int err;
+
+       mutex_lock(&ua->mutex);
+       err = start_usb_capture(ua);
+       if (err >= 0)
+               err = start_usb_playback(ua);
+       mutex_unlock(&ua->mutex);
+       if (err < 0)
+               return err;
+
+       /* see the comment in capture_pcm_prepare() */
+       wait_event(ua->alsa_playback_wait,
+                  test_bit(PLAYBACK_URB_COMPLETED, &ua->states) ||
+                  !test_bit(USB_PLAYBACK_RUNNING, &ua->states));
+       if (test_bit(DISCONNECTED, &ua->states))
+               return -ENODEV;
+       if (!test_bit(USB_PLAYBACK_RUNNING, &ua->states))
+               return -EIO;
+
+       substream->runtime->delay = 0;
+       ua->playback.period_pos = 0;
+       ua->playback.buffer_pos = 0;
+       return 0;
+}
+
+static int capture_pcm_trigger(struct snd_pcm_substream *substream, int cmd)
+{
+       struct ua101 *ua = substream->private_data;
+
+       switch (cmd) {
+       case SNDRV_PCM_TRIGGER_START:
+               if (!test_bit(USB_CAPTURE_RUNNING, &ua->states))
+                       return -EIO;
+               set_bit(ALSA_CAPTURE_RUNNING, &ua->states);
+               return 0;
+       case SNDRV_PCM_TRIGGER_STOP:
+               clear_bit(ALSA_CAPTURE_RUNNING, &ua->states);
+               return 0;
+       default:
+               return -EINVAL;
+       }
+}
+
+static int playback_pcm_trigger(struct snd_pcm_substream *substream, int cmd)
+{
+       struct ua101 *ua = substream->private_data;
+
+       switch (cmd) {
+       case SNDRV_PCM_TRIGGER_START:
+               if (!test_bit(USB_PLAYBACK_RUNNING, &ua->states))
+                       return -EIO;
+               set_bit(ALSA_PLAYBACK_RUNNING, &ua->states);
+               return 0;
+       case SNDRV_PCM_TRIGGER_STOP:
+               clear_bit(ALSA_PLAYBACK_RUNNING, &ua->states);
+               return 0;
+       default:
+               return -EINVAL;
+       }
+}
+
+static inline snd_pcm_uframes_t ua101_pcm_pointer(struct ua101 *ua,
+                                                 struct ua101_stream *stream)
+{
+       unsigned long flags;
+       unsigned int pos;
+
+       spin_lock_irqsave(&ua->lock, flags);
+       pos = stream->buffer_pos;
+       spin_unlock_irqrestore(&ua->lock, flags);
+       return pos;
+}
+
+static snd_pcm_uframes_t capture_pcm_pointer(struct snd_pcm_substream *subs)
+{
+       struct ua101 *ua = subs->private_data;
+
+       return ua101_pcm_pointer(ua, &ua->capture);
+}
+
+static snd_pcm_uframes_t playback_pcm_pointer(struct snd_pcm_substream *subs)
+{
+       struct ua101 *ua = subs->private_data;
+
+       return ua101_pcm_pointer(ua, &ua->playback);
+}
+
+static struct snd_pcm_ops capture_pcm_ops = {
+       .open = capture_pcm_open,
+       .close = capture_pcm_close,
+       .ioctl = snd_pcm_lib_ioctl,
+       .hw_params = capture_pcm_hw_params,
+       .hw_free = ua101_pcm_hw_free,
+       .prepare = capture_pcm_prepare,
+       .trigger = capture_pcm_trigger,
+       .pointer = capture_pcm_pointer,
+       .page = snd_pcm_lib_get_vmalloc_page,
+};
+
+static struct snd_pcm_ops playback_pcm_ops = {
+       .open = playback_pcm_open,
+       .close = playback_pcm_close,
+       .ioctl = snd_pcm_lib_ioctl,
+       .hw_params = playback_pcm_hw_params,
+       .hw_free = ua101_pcm_hw_free,
+       .prepare = playback_pcm_prepare,
+       .trigger = playback_pcm_trigger,
+       .pointer = playback_pcm_pointer,
+       .page = snd_pcm_lib_get_vmalloc_page,
+};
+
+static const struct uac_format_type_i_discrete_descriptor *
+find_format_descriptor(struct usb_interface *interface)
+{
+       struct usb_host_interface *alt;
+       u8 *extra;
+       int extralen;
+
+       if (interface->num_altsetting != 2) {
+               dev_err(&interface->dev, "invalid num_altsetting\n");
+               return NULL;
+       }
+
+       alt = &interface->altsetting[0];
+       if (alt->desc.bNumEndpoints != 0) {
+               dev_err(&interface->dev, "invalid bNumEndpoints\n");
+               return NULL;
+       }
+
+       alt = &interface->altsetting[1];
+       if (alt->desc.bNumEndpoints != 1) {
+               dev_err(&interface->dev, "invalid bNumEndpoints\n");
+               return NULL;
+       }
+
+       extra = alt->extra;
+       extralen = alt->extralen;
+       while (extralen >= sizeof(struct usb_descriptor_header)) {
+               struct uac_format_type_i_discrete_descriptor *desc;
+
+               desc = (struct uac_format_type_i_discrete_descriptor *)extra;
+               if (desc->bLength > extralen) {
+                       dev_err(&interface->dev, "descriptor overflow\n");
+                       return NULL;
+               }
+               if (desc->bLength == UAC_FORMAT_TYPE_I_DISCRETE_DESC_SIZE(1) &&
+                   desc->bDescriptorType == USB_DT_CS_INTERFACE &&
+                   desc->bDescriptorSubtype == UAC_FORMAT_TYPE) {
+                       if (desc->bFormatType != UAC_FORMAT_TYPE_I_PCM ||
+                           desc->bSamFreqType != 1) {
+                               dev_err(&interface->dev,
+                                       "invalid format type\n");
+                               return NULL;
+                       }
+                       return desc;
+               }
+               extralen -= desc->bLength;
+               extra += desc->bLength;
+       }
+       dev_err(&interface->dev, "sample format descriptor not found\n");
+       return NULL;
+}
+
+static int detect_usb_format(struct ua101 *ua)
+{
+       const struct uac_format_type_i_discrete_descriptor *fmt_capture;
+       const struct uac_format_type_i_discrete_descriptor *fmt_playback;
+       const struct usb_endpoint_descriptor *epd;
+       unsigned int rate2;
+
+       fmt_capture = find_format_descriptor(ua->intf[INTF_CAPTURE]);
+       fmt_playback = find_format_descriptor(ua->intf[INTF_PLAYBACK]);
+       if (!fmt_capture || !fmt_playback)
+               return -ENXIO;
+
+       switch (fmt_capture->bSubframeSize) {
+       case 3:
+               ua->format_bit = SNDRV_PCM_FMTBIT_S24_3LE;
+               break;
+       case 4:
+               ua->format_bit = SNDRV_PCM_FMTBIT_S32_LE;
+               break;
+       default:
+               dev_err(&ua->dev->dev, "sample width is not 24 or 32 bits\n");
+               return -ENXIO;
+       }
+       if (fmt_capture->bSubframeSize != fmt_playback->bSubframeSize) {
+               dev_err(&ua->dev->dev,
+                       "playback/capture sample widths do not match\n");
+               return -ENXIO;
+       }
+
+       if (fmt_capture->bBitResolution != 24 ||
+           fmt_playback->bBitResolution != 24) {
+               dev_err(&ua->dev->dev, "sample width is not 24 bits\n");
+               return -ENXIO;
+       }
+
+       ua->rate = combine_triple(fmt_capture->tSamFreq[0]);
+       rate2 = combine_triple(fmt_playback->tSamFreq[0]);
+       if (ua->rate != rate2) {
+               dev_err(&ua->dev->dev,
+                       "playback/capture rates do not match: %u/%u\n",
+                       rate2, ua->rate);
+               return -ENXIO;
+       }
+
+       switch (ua->dev->speed) {
+       case USB_SPEED_FULL:
+               ua->packets_per_second = 1000;
+               break;
+       case USB_SPEED_HIGH:
+               ua->packets_per_second = 8000;
+               break;
+       default:
+               dev_err(&ua->dev->dev, "unknown device speed\n");
+               return -ENXIO;
+       }
+
+       ua->capture.channels = fmt_capture->bNrChannels;
+       ua->playback.channels = fmt_playback->bNrChannels;
+       ua->capture.frame_bytes =
+               fmt_capture->bSubframeSize * ua->capture.channels;
+       ua->playback.frame_bytes =
+               fmt_playback->bSubframeSize * ua->playback.channels;
+
+       epd = &ua->intf[INTF_CAPTURE]->altsetting[1].endpoint[0].desc;
+       if (!usb_endpoint_is_isoc_in(epd)) {
+               dev_err(&ua->dev->dev, "invalid capture endpoint\n");
+               return -ENXIO;
+       }
+       ua->capture.usb_pipe = usb_rcvisocpipe(ua->dev, usb_endpoint_num(epd));
+       ua->capture.max_packet_bytes = le16_to_cpu(epd->wMaxPacketSize);
+
+       epd = &ua->intf[INTF_PLAYBACK]->altsetting[1].endpoint[0].desc;
+       if (!usb_endpoint_is_isoc_out(epd)) {
+               dev_err(&ua->dev->dev, "invalid playback endpoint\n");
+               return -ENXIO;
+       }
+       ua->playback.usb_pipe = usb_sndisocpipe(ua->dev, usb_endpoint_num(epd));
+       ua->playback.max_packet_bytes = le16_to_cpu(epd->wMaxPacketSize);
+       return 0;
+}
+
+static int alloc_stream_buffers(struct ua101 *ua, struct ua101_stream *stream)
+{
+       unsigned int remaining_packets, packets, packets_per_page, i;
+       size_t size;
+
+       stream->queue_length = queue_length;
+       stream->queue_length = max(stream->queue_length,
+                                  (unsigned int)MIN_QUEUE_LENGTH);
+       stream->queue_length = min(stream->queue_length,
+                                  (unsigned int)MAX_QUEUE_LENGTH);
+
+       /*
+        * The cache pool sizes used by usb_buffer_alloc() (128, 512, 2048) are
+        * quite bad when used with the packet sizes of this device (e.g. 280,
+        * 520, 624).  Therefore, we allocate and subdivide entire pages, using
+        * a smaller buffer only for the last chunk.
+        */
+       remaining_packets = stream->queue_length;
+       packets_per_page = PAGE_SIZE / stream->max_packet_bytes;
+       for (i = 0; i < ARRAY_SIZE(stream->buffers); ++i) {
+               packets = min(remaining_packets, packets_per_page);
+               size = packets * stream->max_packet_bytes;
+               stream->buffers[i].addr =
+                       usb_buffer_alloc(ua->dev, size, GFP_KERNEL,
+                                        &stream->buffers[i].dma);
+               if (!stream->buffers[i].addr)
+                       return -ENOMEM;
+               stream->buffers[i].size = size;
+               remaining_packets -= packets;
+               if (!remaining_packets)
+                       break;
+       }
+       if (remaining_packets) {
+               dev_err(&ua->dev->dev, "too many packets\n");
+               return -ENXIO;
+       }
+       return 0;
+}
+
+static void free_stream_buffers(struct ua101 *ua, struct ua101_stream *stream)
+{
+       unsigned int i;
+
+       for (i = 0; i < ARRAY_SIZE(stream->buffers); ++i)
+               usb_buffer_free(ua->dev,
+                               stream->buffers[i].size,
+                               stream->buffers[i].addr,
+                               stream->buffers[i].dma);
+}
+
+static int alloc_stream_urbs(struct ua101 *ua, struct ua101_stream *stream,
+                            void (*urb_complete)(struct urb *))
+{
+       unsigned max_packet_size = stream->max_packet_bytes;
+       struct ua101_urb *urb;
+       unsigned int b, u = 0;
+
+       for (b = 0; b < ARRAY_SIZE(stream->buffers); ++b) {
+               unsigned int size = stream->buffers[b].size;
+               u8 *addr = stream->buffers[b].addr;
+               dma_addr_t dma = stream->buffers[b].dma;
+
+               while (size >= max_packet_size) {
+                       if (u >= stream->queue_length)
+                               goto bufsize_error;
+                       urb = kmalloc(sizeof(*urb), GFP_KERNEL);
+                       if (!urb)
+                               return -ENOMEM;
+                       usb_init_urb(&urb->urb);
+                       urb->urb.dev = ua->dev;
+                       urb->urb.pipe = stream->usb_pipe;
+                       urb->urb.transfer_flags = URB_ISO_ASAP |
+                                       URB_NO_TRANSFER_DMA_MAP;
+                       urb->urb.transfer_buffer = addr;
+                       urb->urb.transfer_dma = dma;
+                       urb->urb.transfer_buffer_length = max_packet_size;
+                       urb->urb.number_of_packets = 1;
+                       urb->urb.interval = 1;
+                       urb->urb.context = ua;
+                       urb->urb.complete = urb_complete;
+                       urb->urb.iso_frame_desc[0].offset = 0;
+                       urb->urb.iso_frame_desc[0].length = max_packet_size;
+                       stream->urbs[u++] = urb;
+                       size -= max_packet_size;
+                       addr += max_packet_size;
+                       dma += max_packet_size;
+               }
+       }
+       if (u == stream->queue_length)
+               return 0;
+bufsize_error:
+       dev_err(&ua->dev->dev, "internal buffer size error\n");
+       return -ENXIO;
+}
+
+static void free_stream_urbs(struct ua101_stream *stream)
+{
+       unsigned int i;
+
+       for (i = 0; i < stream->queue_length; ++i)
+               kfree(stream->urbs[i]);
+}
+
+static void free_usb_related_resources(struct ua101 *ua,
+                                      struct usb_interface *interface)
+{
+       unsigned int i;
+
+       free_stream_urbs(&ua->capture);
+       free_stream_urbs(&ua->playback);
+       free_stream_buffers(ua, &ua->capture);
+       free_stream_buffers(ua, &ua->playback);
+
+       for (i = 0; i < ARRAY_SIZE(ua->intf); ++i)
+               if (ua->intf[i]) {
+                       usb_set_intfdata(ua->intf[i], NULL);
+                       if (ua->intf[i] != interface)
+                               usb_driver_release_interface(&ua101_driver,
+                                                            ua->intf[i]);
+               }
+}
+
+static void ua101_card_free(struct snd_card *card)
+{
+       struct ua101 *ua = card->private_data;
+
+       mutex_destroy(&ua->mutex);
+}
+
+static int ua101_probe(struct usb_interface *interface,
+                      const struct usb_device_id *usb_id)
+{
+       static const struct snd_usb_midi_endpoint_info midi_ep = {
+               .out_cables = 0x0001,
+               .in_cables = 0x0001
+       };
+       static const struct snd_usb_audio_quirk midi_quirk = {
+               .type = QUIRK_MIDI_FIXED_ENDPOINT,
+               .data = &midi_ep
+       };
+       struct snd_card *card;
+       struct ua101 *ua;
+       unsigned int card_index, i;
+       char usb_path[32];
+       int err;
+
+       if (interface->altsetting->desc.bInterfaceNumber != 0)
+               return -ENODEV;
+
+       mutex_lock(&devices_mutex);
+
+       for (card_index = 0; card_index < SNDRV_CARDS; ++card_index)
+               if (enable[card_index] && !(devices_used & (1 << card_index)))
+                       break;
+       if (card_index >= SNDRV_CARDS) {
+               mutex_unlock(&devices_mutex);
+               return -ENOENT;
+       }
+       err = snd_card_create(index[card_index], id[card_index], THIS_MODULE,
+                             sizeof(*ua), &card);
+       if (err < 0) {
+               mutex_unlock(&devices_mutex);
+               return err;
+       }
+       card->private_free = ua101_card_free;
+       ua = card->private_data;
+       ua->dev = interface_to_usbdev(interface);
+       ua->card = card;
+       ua->card_index = card_index;
+       INIT_LIST_HEAD(&ua->midi_list);
+       spin_lock_init(&ua->lock);
+       mutex_init(&ua->mutex);
+       INIT_LIST_HEAD(&ua->ready_playback_urbs);
+       tasklet_init(&ua->playback_tasklet,
+                    playback_tasklet, (unsigned long)ua);
+       init_waitqueue_head(&ua->alsa_capture_wait);
+       init_waitqueue_head(&ua->rate_feedback_wait);
+       init_waitqueue_head(&ua->alsa_playback_wait);
+
+#ifdef UA1A_HACK
+       if (ua->dev->descriptor.idProduct == cpu_to_le16(0x0018)) {
+               ua->intf[2] = interface;
+               ua->intf[0] = usb_ifnum_to_if(ua->dev, 1);
+               ua->intf[1] = usb_ifnum_to_if(ua->dev, 2);
+               usb_driver_claim_interface(&ua101_driver, ua->intf[0], ua);
+               usb_driver_claim_interface(&ua101_driver, ua->intf[1], ua);
+       } else {
+#endif
+       ua->intf[0] = interface;
+       for (i = 1; i < ARRAY_SIZE(ua->intf); ++i) {
+               ua->intf[i] = usb_ifnum_to_if(ua->dev, i);
+               if (!ua->intf[i]) {
+                       dev_err(&ua->dev->dev, "interface %u not found\n", i);
+                       err = -ENXIO;
+                       goto probe_error;
+               }
+               err = usb_driver_claim_interface(&ua101_driver,
+                                                ua->intf[i], ua);
+               if (err < 0) {
+                       ua->intf[i] = NULL;
+                       err = -EBUSY;
+                       goto probe_error;
+               }
+       }
+#ifdef UA1A_HACK
+       }
+#endif
+
+       snd_card_set_dev(card, &interface->dev);
+
+#ifdef UA1A_HACK
+       if (ua->dev->descriptor.idProduct == cpu_to_le16(0x0018)) {
+               ua->format_bit = SNDRV_PCM_FMTBIT_S16_LE;
+               ua->rate = 44100;
+               ua->packets_per_second = 1000;
+               ua->capture.channels = 2;
+               ua->playback.channels = 2;
+               ua->capture.frame_bytes = 4;
+               ua->playback.frame_bytes = 4;
+               ua->capture.usb_pipe = usb_rcvisocpipe(ua->dev, 2);
+               ua->playback.usb_pipe = usb_sndisocpipe(ua->dev, 1);
+               ua->capture.max_packet_bytes = 192;
+               ua->playback.max_packet_bytes = 192;
+       } else {
+#endif
+       err = detect_usb_format(ua);
+       if (err < 0)
+               goto probe_error;
+#ifdef UA1A_HACK
+       }
+#endif
+
+       strcpy(card->driver, "UA-101");
+       strcpy(card->shortname, "UA-101");
+       usb_make_path(ua->dev, usb_path, sizeof(usb_path));
+       snprintf(ua->card->longname, sizeof(ua->card->longname),
+                "EDIROL UA-101 (serial %s), %u Hz at %s, %s speed",
+                ua->dev->serial ? ua->dev->serial : "?", ua->rate, usb_path,
+                ua->dev->speed == USB_SPEED_HIGH ? "high" : "full");
+
+       err = alloc_stream_buffers(ua, &ua->capture);
+       if (err < 0)
+               goto probe_error;
+       err = alloc_stream_buffers(ua, &ua->playback);
+       if (err < 0)
+               goto probe_error;
+
+       err = alloc_stream_urbs(ua, &ua->capture, capture_urb_complete);
+       if (err < 0)
+               goto probe_error;
+       err = alloc_stream_urbs(ua, &ua->playback, playback_urb_complete);
+       if (err < 0)
+               goto probe_error;
+
+       err = snd_pcm_new(card, "UA-101", 0, 1, 1, &ua->pcm);
+       if (err < 0)
+               goto probe_error;
+       ua->pcm->private_data = ua;
+       strcpy(ua->pcm->name, "UA-101");
+       snd_pcm_set_ops(ua->pcm, SNDRV_PCM_STREAM_PLAYBACK, &playback_pcm_ops);
+       snd_pcm_set_ops(ua->pcm, SNDRV_PCM_STREAM_CAPTURE, &capture_pcm_ops);
+
+#ifdef UA1A_HACK
+       if (ua->dev->descriptor.idProduct != cpu_to_le16(0x0018)) {
+#endif
+       err = snd_usbmidi_create(card, ua->intf[INTF_MIDI],
+                                &ua->midi_list, &midi_quirk);
+       if (err < 0)
+               goto probe_error;
+#ifdef UA1A_HACK
+       }
+#endif
+
+       err = snd_card_register(card);
+       if (err < 0)
+               goto probe_error;
+
+       usb_set_intfdata(interface, ua);
+       devices_used |= 1 << card_index;
+
+       mutex_unlock(&devices_mutex);
+       return 0;
+
+probe_error:
+       free_usb_related_resources(ua, interface);
+       snd_card_free(card);
+       mutex_unlock(&devices_mutex);
+       return err;
+}
+
+static void ua101_disconnect(struct usb_interface *interface)
+{
+       struct ua101 *ua = usb_get_intfdata(interface);
+       struct list_head *midi;
+
+       if (!ua)
+               return;
+
+       mutex_lock(&devices_mutex);
+
+       set_bit(DISCONNECTED, &ua->states);
+       wake_up(&ua->rate_feedback_wait);
+
+       /* make sure that userspace cannot create new requests */
+       snd_card_disconnect(ua->card);
+
+       /* make sure that there are no pending USB requests */
+       __list_for_each(midi, &ua->midi_list)
+               snd_usbmidi_disconnect(midi);
+       abort_alsa_playback(ua);
+       abort_alsa_capture(ua);
+       mutex_lock(&ua->mutex);
+       stop_usb_playback(ua);
+       stop_usb_capture(ua);
+       mutex_unlock(&ua->mutex);
+
+       free_usb_related_resources(ua, interface);
+
+       devices_used &= ~(1 << ua->card_index);
+
+       snd_card_free_when_closed(ua->card);
+
+       mutex_unlock(&devices_mutex);
+}
+
+static struct usb_device_id ua101_ids[] = {
+#ifdef UA1A_HACK
+       { USB_DEVICE(0x0582, 0x0018) },
+#endif
+       { USB_DEVICE(0x0582, 0x007d) },
+       { USB_DEVICE(0x0582, 0x008d) },
+       { }
+};
+MODULE_DEVICE_TABLE(usb, ua101_ids);
+
+static struct usb_driver ua101_driver = {
+       .name = "snd-ua101",
+       .id_table = ua101_ids,
+       .probe = ua101_probe,
+       .disconnect = ua101_disconnect,
+#if 0
+       .suspend = ua101_suspend,
+       .resume = ua101_resume,
+#endif
+};
+
+static int __init alsa_card_ua101_init(void)
+{
+       return usb_register(&ua101_driver);
+}
+
+static void __exit alsa_card_ua101_exit(void)
+{
+       usb_deregister(&ua101_driver);
+       mutex_destroy(&devices_mutex);
+}
+
+module_init(alsa_card_ua101_init);
+module_exit(alsa_card_ua101_exit);
index 4963def..4ada98e 100644 (file)
@@ -44,7 +44,6 @@
 #include <linux/slab.h>
 #include <linux/string.h>
 #include <linux/usb.h>
-#include <linux/vmalloc.h>
 #include <linux/moduleparam.h>
 #include <linux/mutex.h>
 #include <sound/core.h>
@@ -170,11 +169,12 @@ struct snd_usb_substream {
        unsigned int curpacksize;       /* current packet size in bytes (for capture) */
        unsigned int curframesize;      /* current packet size in frames (for capture) */
        unsigned int fill_max: 1;       /* fill max packet size always */
+       unsigned int txfr_quirk:1;      /* allow sub-frame alignment */
        unsigned int fmt_type;          /* USB audio format type (1-3) */
 
        unsigned int running: 1;        /* running status */
 
-       unsigned int hwptr_done;                        /* processed frame position in the buffer */
+       unsigned int hwptr_done;        /* processed byte position in the buffer */
        unsigned int transfer_done;             /* processed frames since last period update */
        unsigned long active_mask;      /* bitmask of active urbs */
        unsigned long unlink_mask;      /* bitmask of unlinked urbs */
@@ -343,7 +343,7 @@ static int retire_capture_urb(struct snd_usb_substream *subs,
        unsigned long flags;
        unsigned char *cp;
        int i;
-       unsigned int stride, len, oldptr;
+       unsigned int stride, frames, bytes, oldptr;
        int period_elapsed = 0;
 
        stride = runtime->frame_bits >> 3;
@@ -354,29 +354,39 @@ static int retire_capture_urb(struct snd_usb_substream *subs,
                        snd_printd(KERN_ERR "frame %d active: %d\n", i, urb->iso_frame_desc[i].status);
                        // continue;
                }
-               len = urb->iso_frame_desc[i].actual_length / stride;
-               if (! len)
-                       continue;
+               bytes = urb->iso_frame_desc[i].actual_length;
+               frames = bytes / stride;
+               if (!subs->txfr_quirk)
+                       bytes = frames * stride;
+               if (bytes % (runtime->sample_bits >> 3) != 0) {
+#ifdef CONFIG_SND_DEBUG_VERBOSE
+                       int oldbytes = bytes;
+#endif
+                       bytes = frames * stride;
+                       snd_printdd(KERN_ERR "Corrected urb data len. %d->%d\n",
+                                                       oldbytes, bytes);
+               }
                /* update the current pointer */
                spin_lock_irqsave(&subs->lock, flags);
                oldptr = subs->hwptr_done;
-               subs->hwptr_done += len;
-               if (subs->hwptr_done >= runtime->buffer_size)
-                       subs->hwptr_done -= runtime->buffer_size;
-               subs->transfer_done += len;
+               subs->hwptr_done += bytes;
+               if (subs->hwptr_done >= runtime->buffer_size * stride)
+                       subs->hwptr_done -= runtime->buffer_size * stride;
+               frames = (bytes + (oldptr % stride)) / stride;
+               subs->transfer_done += frames;
                if (subs->transfer_done >= runtime->period_size) {
                        subs->transfer_done -= runtime->period_size;
                        period_elapsed = 1;
                }
                spin_unlock_irqrestore(&subs->lock, flags);
                /* copy a data chunk */
-               if (oldptr + len > runtime->buffer_size) {
-                       unsigned int cnt = runtime->buffer_size - oldptr;
-                       unsigned int blen = cnt * stride;
-                       memcpy(runtime->dma_area + oldptr * stride, cp, blen);
-                       memcpy(runtime->dma_area, cp + blen, len * stride - blen);
+               if (oldptr + bytes > runtime->buffer_size * stride) {
+                       unsigned int bytes1 =
+                                       runtime->buffer_size * stride - oldptr;
+                       memcpy(runtime->dma_area + oldptr, cp, bytes1);
+                       memcpy(runtime->dma_area, cp + bytes1, bytes - bytes1);
                } else {
-                       memcpy(runtime->dma_area + oldptr * stride, cp, len * stride);
+                       memcpy(runtime->dma_area + oldptr, cp, bytes);
                }
        }
        if (period_elapsed)
@@ -563,24 +573,24 @@ static int prepare_playback_urb(struct snd_usb_substream *subs,
                                struct snd_pcm_runtime *runtime,
                                struct urb *urb)
 {
-       int i, stride, offs;
-       unsigned int counts;
+       int i, stride;
+       unsigned int counts, frames, bytes;
        unsigned long flags;
        int period_elapsed = 0;
        struct snd_urb_ctx *ctx = urb->context;
 
        stride = runtime->frame_bits >> 3;
 
-       offs = 0;
+       frames = 0;
        urb->dev = ctx->subs->dev; /* we need to set this at each time */
        urb->number_of_packets = 0;
        spin_lock_irqsave(&subs->lock, flags);
        for (i = 0; i < ctx->packets; i++) {
                counts = snd_usb_audio_next_packet_size(subs);
                /* set up descriptor */
-               urb->iso_frame_desc[i].offset = offs * stride;
+               urb->iso_frame_desc[i].offset = frames * stride;
                urb->iso_frame_desc[i].length = counts * stride;
-               offs += counts;
+               frames += counts;
                urb->number_of_packets++;
                subs->transfer_done += counts;
                if (subs->transfer_done >= runtime->period_size) {
@@ -590,7 +600,7 @@ static int prepare_playback_urb(struct snd_usb_substream *subs,
                                if (subs->transfer_done > 0) {
                                        /* FIXME: fill-max mode is not
                                         * supported yet */
-                                       offs -= subs->transfer_done;
+                                       frames -= subs->transfer_done;
                                        counts -= subs->transfer_done;
                                        urb->iso_frame_desc[i].length =
                                                counts * stride;
@@ -600,7 +610,7 @@ static int prepare_playback_urb(struct snd_usb_substream *subs,
                                if (i < ctx->packets) {
                                        /* add a transfer delimiter */
                                        urb->iso_frame_desc[i].offset =
-                                               offs * stride;
+                                               frames * stride;
                                        urb->iso_frame_desc[i].length = 0;
                                        urb->number_of_packets++;
                                }
@@ -610,26 +620,25 @@ static int prepare_playback_urb(struct snd_usb_substream *subs,
                if (period_elapsed) /* finish at the period boundary */
                        break;
        }
-       if (subs->hwptr_done + offs > runtime->buffer_size) {
+       bytes = frames * stride;
+       if (subs->hwptr_done + bytes > runtime->buffer_size * stride) {
                /* err, the transferred area goes over buffer boundary. */
-               unsigned int len = runtime->buffer_size - subs->hwptr_done;
+               unsigned int bytes1 =
+                       runtime->buffer_size * stride - subs->hwptr_done;
                memcpy(urb->transfer_buffer,
-                      runtime->dma_area + subs->hwptr_done * stride,
-                      len * stride);
-               memcpy(urb->transfer_buffer + len * stride,
-                      runtime->dma_area,
-                      (offs - len) * stride);
+                      runtime->dma_area + subs->hwptr_done, bytes1);
+               memcpy(urb->transfer_buffer + bytes1,
+                      runtime->dma_area, bytes - bytes1);
        } else {
                memcpy(urb->transfer_buffer,
-                      runtime->dma_area + subs->hwptr_done * stride,
-                      offs * stride);
+                      runtime->dma_area + subs->hwptr_done, bytes);
        }
-       subs->hwptr_done += offs;
-       if (subs->hwptr_done >= runtime->buffer_size)
-               subs->hwptr_done -= runtime->buffer_size;
-       runtime->delay += offs;
+       subs->hwptr_done += bytes;
+       if (subs->hwptr_done >= runtime->buffer_size * stride)
+               subs->hwptr_done -= runtime->buffer_size * stride;
+       runtime->delay += frames;
        spin_unlock_irqrestore(&subs->lock, flags);
-       urb->transfer_buffer_length = offs * stride;
+       urb->transfer_buffer_length = bytes;
        if (period_elapsed)
                snd_pcm_period_elapsed(subs->pcm_substream);
        return 0;
@@ -735,41 +744,6 @@ static void snd_complete_sync_urb(struct urb *urb)
 }
 
 
-/* get the physical page pointer at the given offset */
-static struct page *snd_pcm_get_vmalloc_page(struct snd_pcm_substream *subs,
-                                            unsigned long offset)
-{
-       void *pageptr = subs->runtime->dma_area + offset;
-       return vmalloc_to_page(pageptr);
-}
-
-/* allocate virtual buffer; may be called more than once */
-static int snd_pcm_alloc_vmalloc_buffer(struct snd_pcm_substream *subs, size_t size)
-{
-       struct snd_pcm_runtime *runtime = subs->runtime;
-       if (runtime->dma_area) {
-               if (runtime->dma_bytes >= size)
-                       return 0; /* already large enough */
-               vfree(runtime->dma_area);
-       }
-       runtime->dma_area = vmalloc_user(size);
-       if (!runtime->dma_area)
-               return -ENOMEM;
-       runtime->dma_bytes = size;
-       return 0;
-}
-
-/* free virtual buffer; may be called more than once */
-static int snd_pcm_free_vmalloc_buffer(struct snd_pcm_substream *subs)
-{
-       struct snd_pcm_runtime *runtime = subs->runtime;
-
-       vfree(runtime->dma_area);
-       runtime->dma_area = NULL;
-       return 0;
-}
-
-
 /*
  * unlink active urbs.
  */
@@ -937,18 +911,18 @@ static int wait_clear_urbs(struct snd_usb_substream *subs)
 
 
 /*
- * return the current pcm pointer.  just return the hwptr_done value.
+ * return the current pcm pointer.  just based on the hwptr_done value.
  */
 static snd_pcm_uframes_t snd_usb_pcm_pointer(struct snd_pcm_substream *substream)
 {
        struct snd_usb_substream *subs;
-       snd_pcm_uframes_t hwptr_done;
+       unsigned int hwptr_done;
        
        subs = (struct snd_usb_substream *)substream->runtime->private_data;
        spin_lock(&subs->lock);
        hwptr_done = subs->hwptr_done;
        spin_unlock(&subs->lock);
-       return hwptr_done;
+       return hwptr_done / (substream->runtime->frame_bits >> 3);
 }
 
 
@@ -1307,6 +1281,47 @@ static int init_usb_sample_rate(struct usb_device *dev, int iface,
 }
 
 /*
+ * For E-Mu 0404USB/0202USB/TrackerPre sample rate should be set for device,
+ * not for interface.
+ */
+static void set_format_emu_quirk(struct snd_usb_substream *subs,
+                                struct audioformat *fmt)
+{
+       unsigned char emu_samplerate_id = 0;
+
+       /* When capture is active
+        * sample rate shouldn't be changed
+        * by playback substream
+        */
+       if (subs->direction == SNDRV_PCM_STREAM_PLAYBACK) {
+               if (subs->stream->substream[SNDRV_PCM_STREAM_CAPTURE].interface != -1)
+                       return;
+       }
+
+       switch (fmt->rate_min) {
+       case 48000:
+               emu_samplerate_id = EMU_QUIRK_SR_48000HZ;
+               break;
+       case 88200:
+               emu_samplerate_id = EMU_QUIRK_SR_88200HZ;
+               break;
+       case 96000:
+               emu_samplerate_id = EMU_QUIRK_SR_96000HZ;
+               break;
+       case 176400:
+               emu_samplerate_id = EMU_QUIRK_SR_176400HZ;
+               break;
+       case 192000:
+               emu_samplerate_id = EMU_QUIRK_SR_192000HZ;
+               break;
+       default:
+               emu_samplerate_id = EMU_QUIRK_SR_44100HZ;
+               break;
+       }
+       snd_emuusb_set_samplerate(subs->stream->chip, emu_samplerate_id);
+}
+
+/*
  * find a matching format and set up the interface
  */
 static int set_format(struct snd_usb_substream *subs, struct audioformat *fmt)
@@ -1419,6 +1434,14 @@ static int set_format(struct snd_usb_substream *subs, struct audioformat *fmt)
 
        subs->cur_audiofmt = fmt;
 
+       switch (subs->stream->chip->usb_id) {
+       case USB_ID(0x041e, 0x3f02): /* E-Mu 0202 USB */
+       case USB_ID(0x041e, 0x3f04): /* E-Mu 0404 USB */
+       case USB_ID(0x041e, 0x3f0a): /* E-Mu Tracker Pre */
+               set_format_emu_quirk(subs, fmt);
+               break;
+       }
+
 #if 0
        printk(KERN_DEBUG
               "setting done: format = %d, rate = %d..%d, channels = %d\n",
@@ -1449,8 +1472,8 @@ static int snd_usb_hw_params(struct snd_pcm_substream *substream,
        unsigned int channels, rate, format;
        int ret, changed;
 
-       ret = snd_pcm_alloc_vmalloc_buffer(substream,
-                                          params_buffer_bytes(hw_params));
+       ret = snd_pcm_lib_alloc_vmalloc_buffer(substream,
+                                              params_buffer_bytes(hw_params));
        if (ret < 0)
                return ret;
 
@@ -1507,7 +1530,7 @@ static int snd_usb_hw_free(struct snd_pcm_substream *substream)
        subs->period_bytes = 0;
        if (!subs->stream->chip->shutdown)
                release_substream_urbs(subs, 0);
-       return snd_pcm_free_vmalloc_buffer(substream);
+       return snd_pcm_lib_free_vmalloc_buffer(substream);
 }
 
 /*
@@ -1973,7 +1996,7 @@ static struct snd_pcm_ops snd_usb_playback_ops = {
        .prepare =      snd_usb_pcm_prepare,
        .trigger =      snd_usb_pcm_playback_trigger,
        .pointer =      snd_usb_pcm_pointer,
-       .page =         snd_pcm_get_vmalloc_page,
+       .page =         snd_pcm_lib_get_vmalloc_page,
 };
 
 static struct snd_pcm_ops snd_usb_capture_ops = {
@@ -1985,7 +2008,7 @@ static struct snd_pcm_ops snd_usb_capture_ops = {
        .prepare =      snd_usb_pcm_prepare,
        .trigger =      snd_usb_pcm_capture_trigger,
        .pointer =      snd_usb_pcm_pointer,
-       .page =         snd_pcm_get_vmalloc_page,
+       .page =         snd_pcm_lib_get_vmalloc_page,
 };
 
 
@@ -2227,6 +2250,7 @@ static void init_substream(struct snd_usb_stream *as, int stream, struct audiofo
        subs->stream = as;
        subs->direction = stream;
        subs->dev = as->chip->dev;
+       subs->txfr_quirk = as->chip->txfr_quirk;
        if (snd_usb_get_speed(subs->dev) == USB_SPEED_FULL) {
                subs->ops = audio_urb_ops[stream];
        } else {
@@ -3142,59 +3166,6 @@ static int create_ua1000_quirk(struct snd_usb_audio *chip,
        return 0;
 }
 
-/*
- * Create a stream for an Edirol UA-101 interface.
- * Copy, paste and modify from Edirol UA-1000
- */
-static int create_ua101_quirk(struct snd_usb_audio *chip,
-                              struct usb_interface *iface,
-                              const struct snd_usb_audio_quirk *quirk)
-{
-       static const struct audioformat ua101_format = {
-               .format = SNDRV_PCM_FORMAT_S32_LE,
-               .fmt_type = USB_FORMAT_TYPE_I,
-               .altsetting = 1,
-               .altset_idx = 1,
-               .attributes = 0,
-               .rates = SNDRV_PCM_RATE_CONTINUOUS,
-       };
-       struct usb_host_interface *alts;
-       struct usb_interface_descriptor *altsd;
-       struct audioformat *fp;
-       int stream, err;
-
-       if (iface->num_altsetting != 2)
-               return -ENXIO;
-       alts = &iface->altsetting[1];
-       altsd = get_iface_desc(alts);
-       if (alts->extralen != 18 || alts->extra[1] != USB_DT_CS_INTERFACE ||
-           altsd->bNumEndpoints != 1)
-               return -ENXIO;
-
-       fp = kmemdup(&ua101_format, sizeof(*fp), GFP_KERNEL);
-       if (!fp)
-               return -ENOMEM;
-
-       fp->channels = alts->extra[11];
-       fp->iface = altsd->bInterfaceNumber;
-       fp->endpoint = get_endpoint(alts, 0)->bEndpointAddress;
-       fp->ep_attr = get_endpoint(alts, 0)->bmAttributes;
-       fp->datainterval = parse_datainterval(chip, alts);
-       fp->maxpacksize = le16_to_cpu(get_endpoint(alts, 0)->wMaxPacketSize);
-       fp->rate_max = fp->rate_min = combine_triple(&alts->extra[15]);
-
-       stream = (fp->endpoint & USB_DIR_IN)
-               ? SNDRV_PCM_STREAM_CAPTURE : SNDRV_PCM_STREAM_PLAYBACK;
-       err = add_audio_endpoint(chip, stream, fp);
-       if (err < 0) {
-               kfree(fp);
-               return err;
-       }
-       /* FIXME: playback must be synchronized to capture */
-       usb_set_interface(chip->dev, fp->iface, 0);
-       return 0;
-}
-
 static int snd_usb_create_quirk(struct snd_usb_audio *chip,
                                struct usb_interface *iface,
                                const struct snd_usb_audio_quirk *quirk);
@@ -3232,6 +3203,18 @@ static int ignore_interface_quirk(struct snd_usb_audio *chip,
        return 0;
 }
 
+/*
+ * Allow alignment on audio sub-slot (channel samples) rather than
+ * on audio slots (audio frames)
+ */
+static int create_align_transfer_quirk(struct snd_usb_audio *chip,
+                                 struct usb_interface *iface,
+                                 const struct snd_usb_audio_quirk *quirk)
+{
+       chip->txfr_quirk = 1;
+       return 1;       /* Continue with creating streams and mixer */
+}
+
 
 /*
  * boot quirks
@@ -3406,8 +3389,8 @@ static int snd_usb_create_quirk(struct snd_usb_audio *chip,
                [QUIRK_AUDIO_STANDARD_INTERFACE] = create_standard_audio_quirk,
                [QUIRK_AUDIO_FIXED_ENDPOINT] = create_fixed_stream_quirk,
                [QUIRK_AUDIO_EDIROL_UA1000] = create_ua1000_quirk,
-               [QUIRK_AUDIO_EDIROL_UA101] = create_ua101_quirk,
-               [QUIRK_AUDIO_EDIROL_UAXX] = create_uaxx_quirk
+               [QUIRK_AUDIO_EDIROL_UAXX] = create_uaxx_quirk,
+               [QUIRK_AUDIO_ALIGN_TRANSFER] = create_align_transfer_quirk
        };
 
        if (quirk->type < QUIRK_TYPE_COUNT) {
@@ -3661,6 +3644,7 @@ static void *snd_usb_audio_probe(struct usb_device *dev,
                }
        }
 
+       chip->txfr_quirk = 0;
        err = 1; /* continue */
        if (quirk && quirk->ifnum != QUIRK_NO_INTERFACE) {
                /* need some special handlings */
index 40ba811..9d8cea4 100644 (file)
@@ -125,6 +125,7 @@ struct snd_usb_audio {
        struct snd_card *card;
        u32 usb_id;
        int shutdown;
+       unsigned int txfr_quirk:1; /* Subframe boundaries on transfers */
        int num_interfaces;
        int num_suspended_intf;
 
@@ -159,8 +160,8 @@ enum quirk_type {
        QUIRK_AUDIO_STANDARD_INTERFACE,
        QUIRK_AUDIO_FIXED_ENDPOINT,
        QUIRK_AUDIO_EDIROL_UA1000,
-       QUIRK_AUDIO_EDIROL_UA101,
        QUIRK_AUDIO_EDIROL_UAXX,
+       QUIRK_AUDIO_ALIGN_TRANSFER,
 
        QUIRK_TYPE_COUNT
 };
@@ -209,6 +210,16 @@ struct snd_usb_midi_endpoint_info {
 /*
  */
 
+/*E-mu USB samplerate control quirk*/
+enum {
+       EMU_QUIRK_SR_44100HZ = 0,
+       EMU_QUIRK_SR_48000HZ,
+       EMU_QUIRK_SR_88200HZ,
+       EMU_QUIRK_SR_96000HZ,
+       EMU_QUIRK_SR_176400HZ,
+       EMU_QUIRK_SR_192000HZ
+};
+
 #define combine_word(s)    ((*(s)) | ((unsigned int)(s)[1] << 8))
 #define combine_triple(s)  (combine_word(s) | ((unsigned int)(s)[2] << 16))
 #define combine_quad(s)    (combine_triple(s) | ((unsigned int)(s)[3] << 24))
@@ -234,6 +245,9 @@ void snd_usbmidi_input_stop(struct list_head* p);
 void snd_usbmidi_input_start(struct list_head* p);
 void snd_usbmidi_disconnect(struct list_head *p);
 
+void snd_emuusb_set_samplerate(struct snd_usb_audio *chip,
+                       unsigned char samplerate_id);
+
 /*
  * retrieve usb_interface descriptor from the host interface
  * (conditional for compatibility with the older API)
index c998220..f5596cf 100644 (file)
@@ -186,6 +186,21 @@ enum {
        USB_PROC_DCR_RELEASE = 6,
 };
 
+/*E-mu 0202(0404) eXtension Unit(XU) control*/
+enum {
+       USB_XU_CLOCK_RATE               = 0xe301,
+       USB_XU_CLOCK_SOURCE             = 0xe302,
+       USB_XU_DIGITAL_IO_STATUS        = 0xe303,
+       USB_XU_DEVICE_OPTIONS           = 0xe304,
+       USB_XU_DIRECT_MONITORING        = 0xe305,
+       USB_XU_METERING                 = 0xe306
+};
+enum {
+       USB_XU_CLOCK_SOURCE_SELECTOR = 0x02,    /* clock source*/
+       USB_XU_CLOCK_RATE_SELECTOR = 0x03,      /* clock rate */
+       USB_XU_DIGITAL_FORMAT_SELECTOR = 0x01,  /* the spdif format */
+       USB_XU_SOFT_LIMIT_SELECTOR = 0x03       /* soft limiter */
+};
 
 /*
  * manual mapping of mixer names
@@ -1330,7 +1345,32 @@ static struct procunit_info procunits[] = {
        { USB_PROC_DCR, "DCR", dcr_proc_info },
        { 0 },
 };
-
+/*
+ * predefined data for extension units
+ */
+static struct procunit_value_info clock_rate_xu_info[] = {
+       { USB_XU_CLOCK_RATE_SELECTOR, "Selector", USB_MIXER_U8, 0 },
+       { 0 }
+};
+static struct procunit_value_info clock_source_xu_info[] = {
+       { USB_XU_CLOCK_SOURCE_SELECTOR, "External", USB_MIXER_BOOLEAN },
+       { 0 }
+};
+static struct procunit_value_info spdif_format_xu_info[] = {
+       { USB_XU_DIGITAL_FORMAT_SELECTOR, "SPDIF/AC3", USB_MIXER_BOOLEAN },
+       { 0 }
+};
+static struct procunit_value_info soft_limit_xu_info[] = {
+       { USB_XU_SOFT_LIMIT_SELECTOR, " ", USB_MIXER_BOOLEAN },
+       { 0 }
+};
+static struct procunit_info extunits[] = {
+       { USB_XU_CLOCK_RATE, "Clock rate", clock_rate_xu_info },
+       { USB_XU_CLOCK_SOURCE, "DigitalIn CLK source", clock_source_xu_info },
+       { USB_XU_DIGITAL_IO_STATUS, "DigitalOut format:", spdif_format_xu_info },
+       { USB_XU_DEVICE_OPTIONS, "AnalogueIn Soft Limit", soft_limit_xu_info },
+       { 0 }
+};
 /*
  * build a processing/extension unit
  */
@@ -1391,8 +1431,18 @@ static int build_audio_procunit(struct mixer_build *state, int unitid, unsigned
                        cval->max = dsc[15];
                        cval->res = 1;
                        cval->initialized = 1;
-               } else
-                       get_min_max(cval, valinfo->min_value);
+               } else {
+                       if (type == USB_XU_CLOCK_RATE) {
+                               /* E-Mu USB 0404/0202/TrackerPre
+                                * samplerate control quirk
+                                */
+                               cval->min = 0;
+                               cval->max = 5;
+                               cval->res = 1;
+                               cval->initialized = 1;
+                       } else
+                               get_min_max(cval, valinfo->min_value);
+               }
 
                kctl = snd_ctl_new1(&mixer_procunit_ctl, cval);
                if (! kctl) {
@@ -1433,7 +1483,7 @@ static int parse_audio_processing_unit(struct mixer_build *state, int unitid, un
 
 static int parse_audio_extension_unit(struct mixer_build *state, int unitid, unsigned char *desc)
 {
-       return build_audio_procunit(state, unitid, desc, NULL, "Extension Unit");
+       return build_audio_procunit(state, unitid, desc, extunits, "Extension Unit");
 }
 
 
@@ -2109,6 +2159,23 @@ static int snd_xonar_u1_controls_create(struct usb_mixer_interface *mixer)
        return 0;
 }
 
+void snd_emuusb_set_samplerate(struct snd_usb_audio *chip,
+               unsigned char samplerate_id)
+{
+        struct usb_mixer_interface *mixer;
+        struct usb_mixer_elem_info *cval;
+        int unitid = 12; /* SamleRate ExtensionUnit ID */
+
+        list_for_each_entry(mixer, &chip->mixer_list, list) {
+                cval = mixer->id_elems[unitid];
+                if (cval) {
+                       set_cur_ctl_value(cval, cval->control << 8, samplerate_id);
+                       snd_usb_mixer_notify_id(mixer, unitid);
+                }
+                break;
+        }
+}
+
 int snd_usb_create_mixer(struct snd_usb_audio *chip, int ctrlif,
                         int ignore_error)
 {
index a892bda..65bbd22 100644 (file)
@@ -1266,37 +1266,6 @@ YAMAHA_DEVICE(0x7010, "UB99"),
                }
        }
 },
-/* Roland UA-101 in High-Speed Mode only */
-{
-       USB_DEVICE(0x0582, 0x007d),
-       .driver_info = (unsigned long) & (const struct snd_usb_audio_quirk) {
-               .vendor_name = "Roland",
-               .product_name = "UA-101",
-               .ifnum = QUIRK_ANY_INTERFACE,
-               .type = QUIRK_COMPOSITE,
-               .data = (const struct snd_usb_audio_quirk[]) {
-                       {
-                               .ifnum = 0,
-                               .type = QUIRK_AUDIO_EDIROL_UA101
-                       },
-                       {
-                               .ifnum = 1,
-                               .type = QUIRK_AUDIO_EDIROL_UA101
-                       },
-                       {
-                               .ifnum = 2,
-                               .type = QUIRK_MIDI_FIXED_ENDPOINT,
-                               .data = & (const struct snd_usb_midi_endpoint_info) {
-                                       .out_cables = 0x0001,
-                                       .in_cables  = 0x0001
-                               }
-                       },
-                       {
-                               .ifnum = -1
-                       }
-               }
-       }
-},
 {
        /* has ID 0x0081 when not in "Advanced Driver" mode */
        USB_DEVICE(0x0582, 0x0080),
@@ -2105,6 +2074,120 @@ YAMAHA_DEVICE(0x7010, "UB99"),
        }
 },
 
+/* Hauppauge HVR-950Q and HVR-850 */
+{
+       USB_DEVICE_VENDOR_SPEC(0x2040, 0x7200),
+       .match_flags = USB_DEVICE_ID_MATCH_DEVICE |
+                      USB_DEVICE_ID_MATCH_INT_CLASS |
+                      USB_DEVICE_ID_MATCH_INT_SUBCLASS,
+       .bInterfaceClass = USB_CLASS_AUDIO,
+       .bInterfaceSubClass = USB_SUBCLASS_AUDIO_CONTROL,
+       .driver_info = (unsigned long) &(const struct snd_usb_audio_quirk) {
+               .vendor_name = "Hauppauge",
+               .product_name = "HVR-950Q",
+               .ifnum = QUIRK_ANY_INTERFACE,
+               .type = QUIRK_AUDIO_ALIGN_TRANSFER,
+       }
+},
+{
+       USB_DEVICE_VENDOR_SPEC(0x2040, 0x7201),
+       .match_flags = USB_DEVICE_ID_MATCH_DEVICE |
+                      USB_DEVICE_ID_MATCH_INT_CLASS |
+                      USB_DEVICE_ID_MATCH_INT_SUBCLASS,
+       .bInterfaceClass = USB_CLASS_AUDIO,
+       .bInterfaceSubClass = USB_SUBCLASS_AUDIO_CONTROL,
+       .driver_info = (unsigned long) &(const struct snd_usb_audio_quirk) {
+               .vendor_name = "Hauppauge",
+               .product_name = "HVR-950Q",
+               .ifnum = QUIRK_ANY_INTERFACE,
+               .type = QUIRK_AUDIO_ALIGN_TRANSFER,
+       }
+},
+{
+       USB_DEVICE_VENDOR_SPEC(0x2040, 0x7202),
+       .match_flags = USB_DEVICE_ID_MATCH_DEVICE |
+                      USB_DEVICE_ID_MATCH_INT_CLASS |
+                      USB_DEVICE_ID_MATCH_INT_SUBCLASS,
+       .bInterfaceClass = USB_CLASS_AUDIO,
+       .bInterfaceSubClass = USB_SUBCLASS_AUDIO_CONTROL,
+       .driver_info = (unsigned long) &(const struct snd_usb_audio_quirk) {
+               .vendor_name = "Hauppauge",
+               .product_name = "HVR-950Q",
+               .ifnum = QUIRK_ANY_INTERFACE,
+               .type = QUIRK_AUDIO_ALIGN_TRANSFER,
+       }
+},
+{
+       USB_DEVICE_VENDOR_SPEC(0x2040, 0x7203),
+       .match_flags = USB_DEVICE_ID_MATCH_DEVICE |
+                      USB_DEVICE_ID_MATCH_INT_CLASS |
+                      USB_DEVICE_ID_MATCH_INT_SUBCLASS,
+       .bInterfaceClass = USB_CLASS_AUDIO,
+       .bInterfaceSubClass = USB_SUBCLASS_AUDIO_CONTROL,
+       .driver_info = (unsigned long) &(const struct snd_usb_audio_quirk) {
+               .vendor_name = "Hauppauge",
+               .product_name = "HVR-950Q",
+               .ifnum = QUIRK_ANY_INTERFACE,
+               .type = QUIRK_AUDIO_ALIGN_TRANSFER,
+       }
+},
+{
+       USB_DEVICE_VENDOR_SPEC(0x2040, 0x7204),
+       .match_flags = USB_DEVICE_ID_MATCH_DEVICE |
+                      USB_DEVICE_ID_MATCH_INT_CLASS |
+                      USB_DEVICE_ID_MATCH_INT_SUBCLASS,
+       .bInterfaceClass = USB_CLASS_AUDIO,
+       .bInterfaceSubClass = USB_SUBCLASS_AUDIO_CONTROL,
+       .driver_info = (unsigned long) &(const struct snd_usb_audio_quirk) {
+               .vendor_name = "Hauppauge",
+               .product_name = "HVR-950Q",
+               .ifnum = QUIRK_ANY_INTERFACE,
+               .type = QUIRK_AUDIO_ALIGN_TRANSFER,
+       }
+},
+{
+       USB_DEVICE_VENDOR_SPEC(0x2040, 0x7205),
+       .match_flags = USB_DEVICE_ID_MATCH_DEVICE |
+                      USB_DEVICE_ID_MATCH_INT_CLASS |
+                      USB_DEVICE_ID_MATCH_INT_SUBCLASS,
+       .bInterfaceClass = USB_CLASS_AUDIO,
+       .bInterfaceSubClass = USB_SUBCLASS_AUDIO_CONTROL,
+       .driver_info = (unsigned long) &(const struct snd_usb_audio_quirk) {
+               .vendor_name = "Hauppauge",
+               .product_name = "HVR-950Q",
+               .ifnum = QUIRK_ANY_INTERFACE,
+               .type = QUIRK_AUDIO_ALIGN_TRANSFER,
+       }
+},
+{
+       USB_DEVICE_VENDOR_SPEC(0x2040, 0x7250),
+       .match_flags = USB_DEVICE_ID_MATCH_DEVICE |
+                      USB_DEVICE_ID_MATCH_INT_CLASS |
+                      USB_DEVICE_ID_MATCH_INT_SUBCLASS,
+       .bInterfaceClass = USB_CLASS_AUDIO,
+       .bInterfaceSubClass = USB_SUBCLASS_AUDIO_CONTROL,
+       .driver_info = (unsigned long) &(const struct snd_usb_audio_quirk) {
+               .vendor_name = "Hauppauge",
+               .product_name = "HVR-950Q",
+               .ifnum = QUIRK_ANY_INTERFACE,
+               .type = QUIRK_AUDIO_ALIGN_TRANSFER,
+       }
+},
+{
+       USB_DEVICE_VENDOR_SPEC(0x2040, 0x7230),
+       .match_flags = USB_DEVICE_ID_MATCH_DEVICE |
+                      USB_DEVICE_ID_MATCH_INT_CLASS |
+                      USB_DEVICE_ID_MATCH_INT_SUBCLASS,
+       .bInterfaceClass = USB_CLASS_AUDIO,
+       .bInterfaceSubClass = USB_SUBCLASS_AUDIO_CONTROL,
+       .driver_info = (unsigned long) &(const struct snd_usb_audio_quirk) {
+               .vendor_name = "Hauppauge",
+               .product_name = "HVR-850",
+               .ifnum = QUIRK_ANY_INTERFACE,
+               .type = QUIRK_AUDIO_ALIGN_TRANSFER,
+       }
+},
+
 {
        /*
         * Some USB MIDI devices don't have an audio control interface,