]> pilppa.org Git - linux-2.6-omap-h63xx.git/blobdiff - sound/usb/usbaudio.c
Merge branch 'for-linus' of git://oss.sgi.com:8090/xfs/xfs-2.6
[linux-2.6-omap-h63xx.git] / sound / usb / usbaudio.c
index de680d095e94dc949fd2663ab326fce4dc515dbd..8ebc1adb5ed9818ddb9c6d8cfef453ca418110cd 100644 (file)
@@ -186,6 +186,7 @@ struct snd_usb_substream {
        u64 formats;                    /* format bitmasks (all or'ed) */
        unsigned int num_formats;               /* number of supported audio formats (list) */
        struct list_head fmt_list;      /* format list */
+       struct snd_pcm_hw_constraint_list rate_list;    /* limited rates */
        spinlock_t lock;
 
        struct snd_urb_ops ops;         /* callbacks (must be filled at init) */
@@ -324,16 +325,6 @@ static int prepare_capture_urb(struct snd_usb_substream *subs,
        }
        urb->transfer_buffer_length = offs;
        urb->number_of_packets = ctx->packets;
-#if 0 // for check
-       if (! urb->bandwidth) {
-               int bustime;
-               bustime = usb_check_bandwidth(urb->dev, urb);
-               if (bustime < 0)
-                       return bustime;
-               printk("urb %d: bandwidth = %d (packets = %d)\n", ctx->index, bustime, urb->number_of_packets);
-               usb_claim_bandwidth(urb->dev, urb, bustime, 1);
-       }
-#endif // for check
        return 0;
 }
 
@@ -1818,28 +1809,33 @@ static int check_hw_params_convention(struct snd_usb_substream *subs)
 static int snd_usb_pcm_check_knot(struct snd_pcm_runtime *runtime,
                                  struct snd_usb_substream *subs)
 {
-       struct list_head *p;
-       struct snd_pcm_hw_constraint_list constraints_rates;
+       struct audioformat *fp;
+       int count = 0, needs_knot = 0;
        int err;
 
-       list_for_each(p, &subs->fmt_list) {
-               struct audioformat *fp;
-               fp = list_entry(p, struct audioformat, list);
-
-               if (!fp->needs_knot)
-                       continue;
-
-               constraints_rates.count = fp->nr_rates;
-               constraints_rates.list = fp->rate_table;
-               constraints_rates.mask = 0;
-
-               err = snd_pcm_hw_constraint_list(runtime, 0,
-                       SNDRV_PCM_HW_PARAM_RATE,
-                       &constraints_rates);
-
-               if (err < 0)
-                       return err;
+       list_for_each_entry(fp, &subs->fmt_list, list) {
+               if (fp->rates & SNDRV_PCM_RATE_CONTINUOUS)
+                       return 0;
+               count += fp->nr_rates;
+               if (fp->needs_knot)
+                       needs_knot = 1;
        }
+       if (!needs_knot)
+               return 0;
+
+       subs->rate_list.count = count;
+       subs->rate_list.list = kmalloc(sizeof(int) * count, GFP_KERNEL);
+       subs->rate_list.mask = 0;
+       count = 0;
+       list_for_each_entry(fp, &subs->fmt_list, list) {
+               int i;
+               for (i = 0; i < fp->nr_rates; i++)
+                       subs->rate_list.list[count++] = fp->rate_table[i];
+       }
+       err = snd_pcm_hw_constraint_list(runtime, 0, SNDRV_PCM_HW_PARAM_RATE,
+                                        &subs->rate_list);
+       if (err < 0)
+               return err;
 
        return 0;
 }
@@ -1882,6 +1878,9 @@ static int setup_hw_info(struct snd_pcm_runtime *runtime, struct snd_usb_substre
        }
 
        /* set the period time minimum 1ms */
+       /* FIXME: high-speed mode allows 125us minimum period, but many parts
+        * in the current code assume the 1ms period.
+        */
        snd_pcm_hw_constraint_minmax(runtime, SNDRV_PCM_HW_PARAM_PERIOD_TIME,
                                     1000 * MIN_PACKS_URB,
                                     /*(nrpacks * MAX_URBS) * 1000*/ UINT_MAX);
@@ -2238,6 +2237,7 @@ static void free_substream(struct snd_usb_substream *subs)
                kfree(fp->rate_table);
                kfree(fp);
        }
+       kfree(subs->rate_list.list);
 }
 
 
@@ -2463,6 +2463,7 @@ static int parse_audio_format_rates(struct snd_usb_audio *chip, struct audioform
                 * build the rate table and bitmap flags
                 */
                int r, idx, c;
+               unsigned int nonzero_rates = 0;
                /* this table corresponds to the SNDRV_PCM_RATE_XXX bit */
                static unsigned int conv_rates[] = {
                        5512, 8000, 11025, 16000, 22050, 32000, 44100, 48000,
@@ -2485,6 +2486,7 @@ static int parse_audio_format_rates(struct snd_usb_audio *chip, struct audioform
                            fp->altsetting == 5 && fp->maxpacksize == 392)
                                rate = 96000;
                        fp->rate_table[r] = rate;
+                       nonzero_rates |= rate;
                        if (rate < fp->rate_min)
                                fp->rate_min = rate;
                        else if (rate > fp->rate_max)
@@ -2500,6 +2502,10 @@ static int parse_audio_format_rates(struct snd_usb_audio *chip, struct audioform
                        if (!found)
                                fp->needs_knot = 1;
                }
+               if (!nonzero_rates) {
+                       hwc_debug("All rates were zero. Skipping format!\n");
+                       return -1;
+               }
                if (fp->needs_knot)
                        fp->rates |= SNDRV_PCM_RATE_KNOT;
        } else {
@@ -3064,6 +3070,58 @@ 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->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);
@@ -3245,6 +3303,7 @@ static int snd_usb_create_quirk(struct snd_usb_audio *chip,
                [QUIRK_AUDIO_FIXED_ENDPOINT] = create_fixed_stream_quirk,
                [QUIRK_AUDIO_EDIROL_UA700_UA25] = create_ua700_ua25_quirk,
                [QUIRK_AUDIO_EDIROL_UA1000] = create_ua1000_quirk,
+               [QUIRK_AUDIO_EDIROL_UA101] = create_ua101_quirk,
        };
 
        if (quirk->type < QUIRK_TYPE_COUNT) {