- 2.6.17 port work build breaks, but the patch set is relativly stable
[linux-flexiantxendom0-3.2.10.git] / sound / usb / usbaudio.c
index 51a8626..4e614ac 100644 (file)
@@ -70,6 +70,7 @@ static int vid[SNDRV_CARDS] = { [0 ... (SNDRV_CARDS-1)] = -1 }; /* Vendor ID for
 static int pid[SNDRV_CARDS] = { [0 ... (SNDRV_CARDS-1)] = -1 }; /* Product ID for this card */
 static int nrpacks = 4;                /* max. number of packets per urb */
 static int async_unlink = 1;
+static int device_setup[SNDRV_CARDS]; /* device parameter for this card*/
 
 module_param_array(index, int, NULL, 0444);
 MODULE_PARM_DESC(index, "Index value for the USB audio adapter.");
@@ -85,6 +86,8 @@ module_param(nrpacks, int, 0644);
 MODULE_PARM_DESC(nrpacks, "Max. number of packets per URB.");
 module_param(async_unlink, bool, 0444);
 MODULE_PARM_DESC(async_unlink, "Use async unlink mode.");
+module_param_array(device_setup, int, NULL, 0444);
+MODULE_PARM_DESC(device_setup, "Specific device setup (if needed).");
 
 
 /*
@@ -720,10 +723,9 @@ static int snd_pcm_alloc_vmalloc_buffer(struct snd_pcm_substream *subs, size_t s
 static int snd_pcm_free_vmalloc_buffer(struct snd_pcm_substream *subs)
 {
        struct snd_pcm_runtime *runtime = subs->runtime;
-       if (runtime->dma_area) {
-               vfree(runtime->dma_area);
-               runtime->dma_area = NULL;
-       }
+
+       vfree(runtime->dma_area);
+       runtime->dma_area = NULL;
        return 0;
 }
 
@@ -774,6 +776,35 @@ static int deactivate_urbs(struct snd_usb_substream *subs, int force, int can_sl
 }
 
 
+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";
+#ifndef CONFIG_USB_EHCI_SPLIT_ISO
+       case -ENOSYS:
+               return "enable CONFIG_USB_EHCI_SPLIT_ISO to play through a hub";
+#endif
+       case -EINVAL:
+       case -EAGAIN:
+       case -EFBIG:
+       case -EMSGSIZE:
+               return "internal error";
+       default:
+               return "unknown error";
+       }
+}
+
 /*
  * set up and start data/sync urbs
  */
@@ -806,16 +837,22 @@ static int start_urbs(struct snd_usb_substream *subs, struct snd_pcm_runtime *ru
        subs->unlink_mask = 0;
        subs->running = 1;
        for (i = 0; i < subs->nurbs; i++) {
-               if ((err = usb_submit_urb(subs->dataurb[i].urb, GFP_ATOMIC)) < 0) {
-                       snd_printk(KERN_ERR "cannot submit datapipe for urb %d, err = %d\n", i, err);
+               err = usb_submit_urb(subs->dataurb[i].urb, GFP_ATOMIC);
+               if (err < 0) {
+                       snd_printk(KERN_ERR "cannot submit datapipe "
+                                  "for urb %d, error %d: %s\n",
+                                  i, err, usb_error_string(err));
                        goto __error;
                }
                set_bit(i, &subs->active_mask);
        }
        if (subs->syncpipe) {
                for (i = 0; i < SYNC_URBS; i++) {
-                       if ((err = usb_submit_urb(subs->syncurb[i].urb, GFP_ATOMIC)) < 0) {
-                               snd_printk(KERN_ERR "cannot submit syncpipe for urb %d, err = %d\n", i, err);
+                       err = usb_submit_urb(subs->syncurb[i].urb, GFP_ATOMIC);
+                       if (err < 0) {
+                               snd_printk(KERN_ERR "cannot submit syncpipe "
+                                          "for urb %d, error %d: %s\n",
+                                          i, err, usb_error_string(err));
                                goto __error;
                        }
                        set_bit(i + 16, &subs->active_mask);
@@ -2513,6 +2550,8 @@ static int parse_audio_format(struct snd_usb_audio *chip, struct audioformat *fp
        return 0;
 }
 
+static int audiophile_skip_setting_quirk(struct snd_usb_audio *chip,
+                                        int iface, int altno);
 static int parse_audio_endpoints(struct snd_usb_audio *chip, int iface_no)
 {
        struct usb_device *dev;
@@ -2547,6 +2586,12 @@ static int parse_audio_endpoints(struct snd_usb_audio *chip, int iface_no)
                stream = (get_endpoint(alts, 0)->bEndpointAddress & USB_DIR_IN) ?
                        SNDRV_PCM_STREAM_CAPTURE : SNDRV_PCM_STREAM_PLAYBACK;
                altno = altsd->bAlternateSetting;
+       
+               /* audiophile usb: skip altsets incompatible with device_setup
+                */
+               if (chip->usb_id == USB_ID(0x0763, 0x2003) && 
+                   audiophile_skip_setting_quirk(chip, iface_no, altno))
+                       continue;
 
                /* get audio formats */
                fmt = snd_usb_find_csint_desc(alts->extra, alts->extralen, NULL, AS_GENERAL);
@@ -2641,7 +2686,7 @@ static int parse_audio_endpoints(struct snd_usb_audio *chip, int iface_no)
                        continue;
                }
 
-               snd_printdd(KERN_INFO "%d:%u:%d: add audio endpoint 0x%x\n", dev->devnum, iface_no, i, fp->endpoint);
+               snd_printdd(KERN_INFO "%d:%u:%d: add audio endpoint 0x%x\n", dev->devnum, iface_no, altno, fp->endpoint);
                err = add_audio_endpoint(chip, stream, fp);
                if (err < 0) {
                        kfree(fp->rate_table);
@@ -3049,6 +3094,45 @@ static int snd_usb_audigy2nx_boot_quirk(struct usb_device *dev)
        return 0;
 }
 
+/*
+ * Setup quirks
+ */
+#define AUDIOPHILE_SET                 0x01 /* if set, parse device_setup */
+#define AUDIOPHILE_SET_DTS              0x02 /* if set, enable DTS Digital Output */
+#define AUDIOPHILE_SET_96K              0x04 /* 48-96KHz rate if set, 8-48KHz otherwise */
+#define AUDIOPHILE_SET_24B             0x08 /* 24bits sample if set, 16bits otherwise */
+#define AUDIOPHILE_SET_DI              0x10 /* if set, enable Digital Input */
+#define AUDIOPHILE_SET_MASK            0x1F /* bit mask for setup value */
+#define AUDIOPHILE_SET_24B_48K_DI      0x19 /* value for 24bits+48KHz+Digital Input */
+#define AUDIOPHILE_SET_24B_48K_NOTDI   0x09 /* value for 24bits+48KHz+No Digital Input */
+#define AUDIOPHILE_SET_16B_48K_DI      0x11 /* value for 16bits+48KHz+Digital Input */
+#define AUDIOPHILE_SET_16B_48K_NOTDI   0x01 /* value for 16bits+48KHz+No Digital Input */
+
+static int audiophile_skip_setting_quirk(struct snd_usb_audio *chip,
+                                        int iface, int altno)
+{
+       if (device_setup[chip->index] & AUDIOPHILE_SET) {
+               if ((device_setup[chip->index] & AUDIOPHILE_SET_DTS)
+                   && altno != 6)
+                       return 1; /* skip this altsetting */
+               if ((device_setup[chip->index] & AUDIOPHILE_SET_96K)
+                   && altno != 1)
+                       return 1; /* skip this altsetting */
+               if ((device_setup[chip->index] & AUDIOPHILE_SET_MASK) ==
+                   AUDIOPHILE_SET_24B_48K_DI && altno != 2)
+                       return 1; /* skip this altsetting */
+               if ((device_setup[chip->index] & AUDIOPHILE_SET_MASK) ==
+                   AUDIOPHILE_SET_24B_48K_NOTDI && altno != 3)
+                       return 1; /* skip this altsetting */
+               if ((device_setup[chip->index] & AUDIOPHILE_SET_MASK) ==
+                   AUDIOPHILE_SET_16B_48K_DI && altno != 4)
+                       return 1; /* skip this altsetting */
+               if ((device_setup[chip->index] & AUDIOPHILE_SET_MASK) ==
+                   AUDIOPHILE_SET_16B_48K_NOTDI && altno != 5)
+                       return 1; /* skip this altsetting */
+       }       
+       return 0; /* keep this altsetting */
+}
 
 /*
  * audio-interface quirks
@@ -3074,7 +3158,7 @@ static int snd_usb_create_quirk(struct snd_usb_audio *chip,
                [QUIRK_MIDI_NOVATION] = snd_usb_create_midi_interface,
                [QUIRK_MIDI_RAW] = snd_usb_create_midi_interface,
                [QUIRK_MIDI_EMAGIC] = snd_usb_create_midi_interface,
-               [QUIRK_MIDI_MIDITECH] = snd_usb_create_midi_interface,
+               [QUIRK_MIDI_CME] = snd_usb_create_midi_interface,
                [QUIRK_AUDIO_STANDARD_INTERFACE] = create_standard_audio_quirk,
                [QUIRK_AUDIO_FIXED_ENDPOINT] = create_fixed_stream_quirk,
                [QUIRK_AUDIO_EDIROL_UA700_UA25] = create_ua700_ua25_quirk,