upgrade to fedora-2.6.12-1.1398.FC4 + vserver 2.0.rc7
[linux-2.6.git] / sound / usb / usbaudio.c
index 18efa78..aae6614 100644 (file)
@@ -1141,7 +1141,7 @@ static int init_usb_pitch(struct usb_device *dev, int iface,
                data[0] = 1;
                if ((err = snd_usb_ctl_msg(dev, usb_sndctrlpipe(dev, 0), SET_CUR,
                                           USB_TYPE_CLASS|USB_RECIP_ENDPOINT|USB_DIR_OUT,
-                                          PITCH_CONTROL << 8, ep, data, 1, HZ)) < 0) {
+                                          PITCH_CONTROL << 8, ep, data, 1, 1000)) < 0) {
                        snd_printk(KERN_ERR "%d:%d:%d: cannot set enable PITCH\n",
                                   dev->devnum, iface, ep);
                        return err;
@@ -1167,14 +1167,14 @@ static int init_usb_sample_rate(struct usb_device *dev, int iface,
                data[2] = rate >> 16;
                if ((err = snd_usb_ctl_msg(dev, usb_sndctrlpipe(dev, 0), SET_CUR,
                                           USB_TYPE_CLASS|USB_RECIP_ENDPOINT|USB_DIR_OUT,
-                                          SAMPLING_FREQ_CONTROL << 8, ep, data, 3, HZ)) < 0) {
+                                          SAMPLING_FREQ_CONTROL << 8, ep, data, 3, 1000)) < 0) {
                        snd_printk(KERN_ERR "%d:%d:%d: cannot set freq %d to ep 0x%x\n",
                                   dev->devnum, iface, fmt->altsetting, rate, ep);
                        return err;
                }
                if ((err = snd_usb_ctl_msg(dev, usb_rcvctrlpipe(dev, 0), GET_CUR,
                                           USB_TYPE_CLASS|USB_RECIP_ENDPOINT|USB_DIR_IN,
-                                          SAMPLING_FREQ_CONTROL << 8, ep, data, 3, HZ)) < 0) {
+                                          SAMPLING_FREQ_CONTROL << 8, ep, data, 3, 1000)) < 0) {
                        snd_printk(KERN_WARNING "%d:%d:%d: cannot get freq at ep 0x%x\n",
                                   dev->devnum, iface, fmt->altsetting, ep);
                        return 0; /* some devices don't support reading */
@@ -1606,62 +1606,65 @@ static int hw_rule_format(snd_pcm_hw_params_t *params,
        return changed;
 }
 
+#define MAX_MASK       64
+
 /*
  * check whether the registered audio formats need special hw-constraints
  */
 static int check_hw_params_convention(snd_usb_substream_t *subs)
 {
        int i;
-       u32 channels[64];
-       u32 rates[64];
+       u32 *channels;
+       u32 *rates;
        u32 cmaster, rmaster;
        u32 rate_min = 0, rate_max = 0;
        struct list_head *p;
+       int err = 1;
 
-       memset(channels, 0, sizeof(channels));
-       memset(rates, 0, sizeof(rates));
+       channels = kcalloc(MAX_MASK, sizeof(u32), GFP_KERNEL);
+       rates = kcalloc(MAX_MASK, sizeof(u32), GFP_KERNEL);
 
        list_for_each(p, &subs->fmt_list) {
                struct audioformat *f;
                f = list_entry(p, struct audioformat, list);
                /* unconventional channels? */
                if (f->channels > 32)
-                       return 1;
+                       goto __out;
                /* continuous rate min/max matches? */
                if (f->rates & SNDRV_PCM_RATE_CONTINUOUS) {
                        if (rate_min && f->rate_min != rate_min)
-                               return 1;
+                               goto __out;
                        if (rate_max && f->rate_max != rate_max)
-                               return 1;
+                               goto __out;
                        rate_min = f->rate_min;
                        rate_max = f->rate_max;
                }
                /* combination of continuous rates and fixed rates? */
                if (rates[f->format] & SNDRV_PCM_RATE_CONTINUOUS) {
                        if (f->rates != rates[f->format])
-                               return 1;
+                               goto __out;
                }
                if (f->rates & SNDRV_PCM_RATE_CONTINUOUS) {
                        if (rates[f->format] && rates[f->format] != f->rates)
-                               return 1;
+                               goto __out;
                }
                channels[f->format] |= (1 << f->channels);
                rates[f->format] |= f->rates;
        }
        /* check whether channels and rates match for all formats */
        cmaster = rmaster = 0;
-       for (i = 0; i < 64; i++) {
+       for (i = 0; i < MAX_MASK; i++) {
                if (cmaster != channels[i] && cmaster && channels[i])
-                       return 1;
+                       goto __out;
                if (rmaster != rates[i] && rmaster && rates[i])
-                       return 1;
+                       goto __out;
                if (channels[i])
                        cmaster = channels[i];
                if (rates[i])
                        rmaster = rates[i];
        }
        /* check whether channels match for all distinct rates */
-       memset(channels, 0, sizeof(channels));
+       memset(channels, 0, MAX_MASK * sizeof(u32));
        list_for_each(p, &subs->fmt_list) {
                struct audioformat *f;
                f = list_entry(p, struct audioformat, list);
@@ -1675,11 +1678,16 @@ static int check_hw_params_convention(snd_usb_substream_t *subs)
        cmaster = 0;
        for (i = 0; i < 32; i++) {
                if (cmaster != channels[i] && cmaster && channels[i])
-                       return 1;
+                       goto __out;
                if (channels[i])
                        cmaster = channels[i];
        }
-       return 0;
+       err = 0;
+
+ __out:
+       kfree(channels);
+       kfree(rates);
+       return err;
 }
 
 
@@ -2066,8 +2074,7 @@ static void free_substream(snd_usb_substream_t *subs)
                return; /* not initialized */
        list_for_each_safe(p, n, &subs->fmt_list) {
                struct audioformat *fp = list_entry(p, struct audioformat, list);
-               if (fp->rate_table)
-                       kfree(fp->rate_table);
+               kfree(fp->rate_table);
                kfree(fp);
        }
 }
@@ -2179,13 +2186,13 @@ static int add_audio_endpoint(snd_usb_audio_t *chip, int stream, struct audiofor
 static int is_big_endian_format(struct usb_device *dev, struct audioformat *fp)
 {
        /* M-Audio */
-       if (dev->descriptor.idVendor == 0x0763) {
+       if (le16_to_cpu(dev->descriptor.idVendor) == 0x0763) {
                /* Quattro: captured data only */
-               if (dev->descriptor.idProduct == 0x2001 &&
+               if (le16_to_cpu(dev->descriptor.idProduct) == 0x2001 &&
                    fp->endpoint & USB_DIR_IN)
                        return 1;
                /* Audiophile USB */
-               if (dev->descriptor.idProduct == 0x2003)
+               if (le16_to_cpu(dev->descriptor.idProduct) == 0x2003)
                        return 1;
        }
        return 0;
@@ -2249,7 +2256,8 @@ static int parse_audio_format_i_type(struct usb_device *dev, struct audioformat
                break;
        case USB_AUDIO_FORMAT_PCM8:
                /* Dallas DS4201 workaround */
-               if (dev->descriptor.idVendor == 0x04fa && dev->descriptor.idProduct == 0x4201)
+               if (le16_to_cpu(dev->descriptor.idVendor) == 0x04fa &&
+                   le16_to_cpu(dev->descriptor.idProduct) == 0x4201)
                        pcm_format = SNDRV_PCM_FORMAT_S8;
                else
                        pcm_format = SNDRV_PCM_FORMAT_U8;
@@ -2417,7 +2425,8 @@ static int parse_audio_format(struct usb_device *dev, struct audioformat *fp,
        /* extigy apparently supports sample rates other than 48k
         * but not in ordinary way.  so we enable only 48k atm.
         */
-       if (dev->descriptor.idVendor == 0x041e && dev->descriptor.idProduct == 0x3000) {
+       if (le16_to_cpu(dev->descriptor.idVendor) == 0x041e && 
+           le16_to_cpu(dev->descriptor.idProduct) == 0x3000) {
                if (fmt[3] == USB_FORMAT_TYPE_I &&
                    stream == SNDRV_PCM_STREAM_PLAYBACK &&
                    fp->rates != SNDRV_PCM_RATE_48000)
@@ -2451,7 +2460,7 @@ static int parse_audio_endpoints(snd_usb_audio_t *chip, int iface_no)
                    (altsd->bInterfaceSubClass != USB_SUBCLASS_AUDIO_STREAMING &&
                     altsd->bInterfaceSubClass != USB_SUBCLASS_VENDOR_SPEC) ||
                    altsd->bNumEndpoints < 1 ||
-                   get_endpoint(alts, 0)->wMaxPacketSize == 0)
+                   le16_to_cpu(get_endpoint(alts, 0)->wMaxPacketSize) == 0)
                        continue;
                /* must be isochronous */
                if ((get_endpoint(alts, 0)->bmAttributes & USB_ENDPOINT_XFERTYPE_MASK) !=
@@ -2514,14 +2523,14 @@ static int parse_audio_endpoints(snd_usb_audio_t *chip, int iface_no)
                fp->endpoint = get_endpoint(alts, 0)->bEndpointAddress;
                fp->ep_attr = get_endpoint(alts, 0)->bmAttributes;
                /* FIXME: decode wMaxPacketSize of high bandwith endpoints */
-               fp->maxpacksize = get_endpoint(alts, 0)->wMaxPacketSize;
+               fp->maxpacksize = le16_to_cpu(get_endpoint(alts, 0)->wMaxPacketSize);
                fp->attributes = csep[3];
 
                /* some quirks for attributes here */
 
                /* workaround for AudioTrak Optoplay */
-               if (dev->descriptor.idVendor == 0x0a92 &&
-                   dev->descriptor.idProduct == 0x0053) {
+               if (le16_to_cpu(dev->descriptor.idVendor) == 0x0a92 &&
+                   le16_to_cpu(dev->descriptor.idProduct) == 0x0053) {
                        /* Optoplay sets the sample rate attribute although
                         * it seems not supporting it in fact.
                         */
@@ -2529,8 +2538,8 @@ static int parse_audio_endpoints(snd_usb_audio_t *chip, int iface_no)
                }
 
                /* workaround for M-Audio Audiophile USB */
-               if (dev->descriptor.idVendor == 0x0763 &&
-                   dev->descriptor.idProduct == 0x2003) {
+               if (le16_to_cpu(dev->descriptor.idVendor) == 0x0763 &&
+                   le16_to_cpu(dev->descriptor.idProduct) == 0x2003) {
                        /* doesn't set the sample rate attribute, but supports it */
                        fp->attributes |= EP_CS_ATTR_SAMPLE_RATE;
                }
@@ -2539,11 +2548,11 @@ static int parse_audio_endpoints(snd_usb_audio_t *chip, int iface_no)
                 * plantronics headset and Griffin iMic have set adaptive-in
                 * although it's really not...
                 */
-               if ((dev->descriptor.idVendor == 0x047f &&
-                    dev->descriptor.idProduct == 0x0ca1) ||
+               if ((le16_to_cpu(dev->descriptor.idVendor) == 0x047f &&
+                    le16_to_cpu(dev->descriptor.idProduct) == 0x0ca1) ||
                    /* Griffin iMic (note that there is an older model 77d:223) */
-                   (dev->descriptor.idVendor == 0x077d &&
-                    dev->descriptor.idProduct == 0x07af)) {
+                   (le16_to_cpu(dev->descriptor.idVendor) == 0x077d &&
+                    le16_to_cpu(dev->descriptor.idProduct) == 0x07af)) {
                        fp->ep_attr &= ~EP_ATTR_MASK;
                        if (stream == SNDRV_PCM_STREAM_PLAYBACK)
                                fp->ep_attr |= EP_ATTR_ADAPTIVE;
@@ -2553,8 +2562,7 @@ static int parse_audio_endpoints(snd_usb_audio_t *chip, int iface_no)
 
                /* ok, let's parse further... */
                if (parse_audio_format(dev, fp, format, fmt, stream) < 0) {
-                       if (fp->rate_table)
-                               kfree(fp->rate_table);
+                       kfree(fp->rate_table);
                        kfree(fp);
                        continue;
                }
@@ -2562,8 +2570,7 @@ static int parse_audio_endpoints(snd_usb_audio_t *chip, int iface_no)
                snd_printdd(KERN_INFO "%d:%u:%d: add audio endpoint 0x%x\n", dev->devnum, iface_no, i, fp->endpoint);
                err = add_audio_endpoint(chip, stream, fp);
                if (err < 0) {
-                       if (fp->rate_table)
-                               kfree(fp->rate_table);
+                       kfree(fp->rate_table);
                        kfree(fp);
                        return err;
                }
@@ -2696,15 +2703,13 @@ static int create_fixed_stream_quirk(snd_usb_audio_t *chip,
        err = add_audio_endpoint(chip, stream, fp);
        if (err < 0) {
                kfree(fp);
-               if (rate_table)
-                       kfree(rate_table);
+               kfree(rate_table);
                return err;
        }
        if (fp->iface != get_iface_desc(&iface->altsetting[0])->bInterfaceNumber ||
            fp->altset_idx >= iface->num_altsetting) {
                kfree(fp);
-               if (rate_table)
-                       kfree(rate_table);
+               kfree(rate_table);
                return -EINVAL;
        }
        alts = &iface->altsetting[fp->altset_idx];
@@ -2791,7 +2796,7 @@ static int create_ua700_ua25_quirk(snd_usb_audio_t *chip,
                        .type = QUIRK_MIDI_FIXED_ENDPOINT,
                        .data = &ua25_ep
                };
-               if (chip->dev->descriptor.idProduct == 0x002b)
+               if (le16_to_cpu(chip->dev->descriptor.idProduct) == 0x002b)
                        return snd_usb_create_midi_interface(chip, iface,
                                                             &ua700_quirk);
                else
@@ -2810,7 +2815,7 @@ static int create_ua700_ua25_quirk(snd_usb_audio_t *chip,
        fp->iface = altsd->bInterfaceNumber;
        fp->endpoint = get_endpoint(alts, 0)->bEndpointAddress;
        fp->ep_attr = get_endpoint(alts, 0)->bmAttributes;
-       fp->maxpacksize = get_endpoint(alts, 0)->wMaxPacketSize;
+       fp->maxpacksize = le16_to_cpu(get_endpoint(alts, 0)->wMaxPacketSize);
 
        switch (fp->maxpacksize) {
        case 0x120:
@@ -2876,7 +2881,7 @@ static int create_ua1000_quirk(snd_usb_audio_t *chip, struct usb_interface *ifac
        fp->iface = altsd->bInterfaceNumber;
        fp->endpoint = get_endpoint(alts, 0)->bEndpointAddress;
        fp->ep_attr = get_endpoint(alts, 0)->bmAttributes;
-       fp->maxpacksize = get_endpoint(alts, 0)->wMaxPacketSize;
+       fp->maxpacksize = le16_to_cpu(get_endpoint(alts, 0)->wMaxPacketSize);
        fp->rate_max = fp->rate_min = combine_triple(&alts->extra[8]);
 
        stream = (fp->endpoint & USB_DIR_IN)
@@ -2934,12 +2939,12 @@ static int snd_usb_extigy_boot_quirk(struct usb_device *dev, struct usb_interfac
        struct usb_host_config *config = dev->actconfig;
        int err;
 
-       if (get_cfg_desc(config)->wTotalLength == EXTIGY_FIRMWARE_SIZE_OLD ||
-           get_cfg_desc(config)->wTotalLength == EXTIGY_FIRMWARE_SIZE_NEW) {
+       if (le16_to_cpu(get_cfg_desc(config)->wTotalLength) == EXTIGY_FIRMWARE_SIZE_OLD ||
+           le16_to_cpu(get_cfg_desc(config)->wTotalLength) == EXTIGY_FIRMWARE_SIZE_NEW) {
                snd_printdd("sending Extigy boot sequence...\n");
                /* Send message to force it to reconnect with full interface. */
                err = snd_usb_ctl_msg(dev, usb_sndctrlpipe(dev,0),
-                                     0x10, 0x43, 0x0001, 0x000a, NULL, 0, HZ);
+                                     0x10, 0x43, 0x0001, 0x000a, NULL, 0, 1000);
                if (err < 0) snd_printdd("error sending boot message: %d\n", err);
                err = usb_get_descriptor(dev, USB_DT_DEVICE, 0,
                                &dev->descriptor, sizeof(dev->descriptor));
@@ -2947,7 +2952,8 @@ static int snd_usb_extigy_boot_quirk(struct usb_device *dev, struct usb_interfac
                if (err < 0) snd_printdd("error usb_get_descriptor: %d\n", err);
                err = usb_reset_configuration(dev);
                if (err < 0) snd_printdd("error usb_reset_configuration: %d\n", err);
-               snd_printdd("extigy_boot: new boot length = %d\n", get_cfg_desc(config)->wTotalLength);
+               snd_printdd("extigy_boot: new boot length = %d\n",
+                           le16_to_cpu(get_cfg_desc(config)->wTotalLength));
                return -ENODEV; /* quit this anyway */
        }
        return 0;
@@ -2970,6 +2976,9 @@ static int snd_usb_create_quirk(snd_usb_audio_t *chip,
        case QUIRK_MIDI_FIXED_ENDPOINT:
        case QUIRK_MIDI_YAMAHA:
        case QUIRK_MIDI_MIDIMAN:
+       case QUIRK_MIDI_NOVATION:
+       case QUIRK_MIDI_MOTU:
+       case QUIRK_MIDI_EMAGIC:
                return snd_usb_create_midi_interface(chip, iface, quirk);
        case QUIRK_COMPOSITE:
                return create_composite_quirk(chip, iface, quirk);
@@ -2982,6 +2991,8 @@ static int snd_usb_create_quirk(snd_usb_audio_t *chip,
                return create_ua700_ua25_quirk(chip, iface);
        case QUIRK_AUDIO_EDIROL_UA1000:
                return create_ua1000_quirk(chip, iface);
+       case QUIRK_IGNORE_INTERFACE:
+               return 0;
        default:
                snd_printd(KERN_ERR "invalid quirk type %d\n", quirk->type);
                return -ENXIO;
@@ -3003,7 +3014,9 @@ static void proc_audio_usbid_read(snd_info_entry_t *entry, snd_info_buffer_t *bu
 {
        snd_usb_audio_t *chip = entry->private_data;
        if (! chip->shutdown)
-               snd_iprintf(buffer, "%04x:%04x\n", chip->dev->descriptor.idVendor, chip->dev->descriptor.idProduct);
+               snd_iprintf(buffer, "%04x:%04x\n", 
+                           le16_to_cpu(chip->dev->descriptor.idVendor),
+                           le16_to_cpu(chip->dev->descriptor.idProduct));
 }
 
 static void snd_usb_audio_create_proc(snd_usb_audio_t *chip)
@@ -3084,7 +3097,8 @@ static int snd_usb_audio_create(struct usb_device *dev, int idx,
 
        strcpy(card->driver, "USB-Audio");
        sprintf(component, "USB%04x:%04x",
-               dev->descriptor.idVendor, dev->descriptor.idProduct);
+               le16_to_cpu(dev->descriptor.idVendor),
+               le16_to_cpu(dev->descriptor.idProduct));
        snd_component_add(card, component);
 
        /* retrieve the device string as shortname */
@@ -3096,7 +3110,8 @@ static int snd_usb_audio_create(struct usb_device *dev, int idx,
                               card->shortname, sizeof(card->shortname)) <= 0) {
                        /* no name available from anywhere, so use ID */
                        sprintf(card->shortname, "USB Device %#04x:%#04x",
-                               dev->descriptor.idVendor, dev->descriptor.idProduct);
+                               le16_to_cpu(dev->descriptor.idVendor),
+                               le16_to_cpu(dev->descriptor.idProduct));
                }
        }
 
@@ -3163,7 +3178,8 @@ static void *snd_usb_audio_probe(struct usb_device *dev,
 
        /* SB Extigy needs special boot-up sequence */
        /* if more models come, this will go to the quirk list. */
-       if (dev->descriptor.idVendor == 0x041e && dev->descriptor.idProduct == 0x3000) {
+       if (le16_to_cpu(dev->descriptor.idVendor) == 0x041e && 
+           le16_to_cpu(dev->descriptor.idProduct) == 0x3000) {
                if (snd_usb_extigy_boot_quirk(dev, intf) < 0)
                        goto __err_val;
                config = dev->actconfig;
@@ -3197,8 +3213,8 @@ static void *snd_usb_audio_probe(struct usb_device *dev,
                }
                for (i = 0; i < SNDRV_CARDS; i++)
                        if (enable[i] && ! usb_chip[i] &&
-                           (vid[i] == -1 || vid[i] == dev->descriptor.idVendor) &&
-                           (pid[i] == -1 || pid[i] == dev->descriptor.idProduct)) {
+                           (vid[i] == -1 || vid[i] == le16_to_cpu(dev->descriptor.idVendor)) &&
+                           (pid[i] == -1 || pid[i] == le16_to_cpu(dev->descriptor.idProduct))) {
                                if (snd_usb_audio_create(dev, i, quirk, &chip) < 0) {
                                        goto __error;
                                }
@@ -3273,7 +3289,7 @@ static void snd_usb_audio_disconnect(struct usb_device *dev, void *ptr)
                }
                usb_chip[chip->index] = NULL;
                up(&register_mutex);
-               snd_card_free_in_thread(card);
+               snd_card_free(card);
        } else {
                up(&register_mutex);
        }