X-Git-Url: http://pilppa.org/gitweb/?a=blobdiff_plain;f=sound%2Fusb%2Fusbaudio.c;h=7bd5852fcc0d1aa1cd0056c083929f2f69197369;hb=9b19ccc9096e498f1603dfefbcc3eafa6f1e4f9b;hp=d2e066dc5d81690d4d122bea687aaf7f030fa660;hpb=e4f8e656d8c152c08cd44d0e3c21f009fab09952;p=linux-2.6-omap-h63xx.git diff --git a/sound/usb/usbaudio.c b/sound/usb/usbaudio.c index d2e066dc5d8..7bd5852fcc0 100644 --- a/sound/usb/usbaudio.c +++ b/sound/usb/usbaudio.c @@ -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) */ @@ -253,7 +254,7 @@ static int prepare_capture_sync_urb(struct snd_usb_substream *subs, struct urb *urb) { unsigned char *cp = urb->transfer_buffer; - struct snd_urb_ctx *ctx = (struct snd_urb_ctx *)urb->context; + struct snd_urb_ctx *ctx = urb->context; urb->dev = ctx->subs->dev; /* we need to set this at each time */ urb->iso_frame_desc[0].length = 3; @@ -275,7 +276,7 @@ static int prepare_capture_sync_urb_hs(struct snd_usb_substream *subs, struct urb *urb) { unsigned char *cp = urb->transfer_buffer; - struct snd_urb_ctx *ctx = (struct snd_urb_ctx *)urb->context; + struct snd_urb_ctx *ctx = urb->context; urb->dev = ctx->subs->dev; /* we need to set this at each time */ urb->iso_frame_desc[0].length = 4; @@ -313,7 +314,7 @@ static int prepare_capture_urb(struct snd_usb_substream *subs, struct urb *urb) { int i, offs; - struct snd_urb_ctx *ctx = (struct snd_urb_ctx *)urb->context; + struct snd_urb_ctx *ctx = urb->context; offs = 0; urb->dev = ctx->subs->dev; /* we need to set this at each time */ @@ -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; } @@ -412,7 +403,7 @@ static int prepare_playback_sync_urb(struct snd_usb_substream *subs, struct snd_pcm_runtime *runtime, struct urb *urb) { - struct snd_urb_ctx *ctx = (struct snd_urb_ctx *)urb->context; + struct snd_urb_ctx *ctx = urb->context; urb->dev = ctx->subs->dev; /* we need to set this at each time */ urb->iso_frame_desc[0].length = 3; @@ -430,7 +421,7 @@ static int prepare_playback_sync_urb_hs(struct snd_usb_substream *subs, struct snd_pcm_runtime *runtime, struct urb *urb) { - struct snd_urb_ctx *ctx = (struct snd_urb_ctx *)urb->context; + struct snd_urb_ctx *ctx = urb->context; urb->dev = ctx->subs->dev; /* we need to set this at each time */ urb->iso_frame_desc[0].length = 4; @@ -547,7 +538,7 @@ static int prepare_playback_urb(struct snd_usb_substream *subs, unsigned int counts; unsigned long flags; int period_elapsed = 0; - struct snd_urb_ctx *ctx = (struct snd_urb_ctx *)urb->context; + struct snd_urb_ctx *ctx = urb->context; stride = runtime->frame_bits >> 3; @@ -665,7 +656,7 @@ static struct snd_urb_ops audio_urb_ops_high_speed[2] = { */ static void snd_complete_urb(struct urb *urb) { - struct snd_urb_ctx *ctx = (struct snd_urb_ctx *)urb->context; + struct snd_urb_ctx *ctx = urb->context; struct snd_usb_substream *subs = ctx->subs; struct snd_pcm_substream *substream = ctx->subs->pcm_substream; int err = 0; @@ -688,7 +679,7 @@ static void snd_complete_urb(struct urb *urb) */ static void snd_complete_sync_urb(struct urb *urb) { - struct snd_urb_ctx *ctx = (struct snd_urb_ctx *)urb->context; + struct snd_urb_ctx *ctx = urb->context; struct snd_usb_substream *subs = ctx->subs; struct snd_pcm_substream *substream = ctx->subs->pcm_substream; int err = 0; @@ -1429,7 +1420,7 @@ static int set_format(struct snd_usb_substream *subs, struct audioformat *fmt) static int snd_usb_hw_params(struct snd_pcm_substream *substream, struct snd_pcm_hw_params *hw_params) { - struct snd_usb_substream *subs = (struct snd_usb_substream *)substream->runtime->private_data; + struct snd_usb_substream *subs = substream->runtime->private_data; struct audioformat *fmt; unsigned int channels, rate, format; int ret, changed; @@ -1485,7 +1476,7 @@ static int snd_usb_hw_params(struct snd_pcm_substream *substream, */ static int snd_usb_hw_free(struct snd_pcm_substream *substream) { - struct snd_usb_substream *subs = (struct snd_usb_substream *)substream->runtime->private_data; + struct snd_usb_substream *subs = substream->runtime->private_data; subs->cur_audiofmt = NULL; subs->cur_rate = 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); } @@ -2350,7 +2350,9 @@ static int is_big_endian_format(struct snd_usb_audio *chip, struct audioformat * return 1; break; case USB_ID(0x0763, 0x2003): /* M-Audio Audiophile USB */ - return 1; + if (device_setup[chip->index] == 0x00 || + fp->altsetting==1 || fp->altsetting==2 || fp->altsetting==3) + return 1; } return 0; } @@ -2463,6 +2465,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 +2488,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 +2504,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 { @@ -2524,7 +2532,18 @@ static int parse_audio_format_i(struct snd_usb_audio *chip, struct audioformat * * but we give normal PCM format to get the existing * apps working... */ - pcm_format = SNDRV_PCM_FORMAT_S16_LE; + switch (chip->usb_id) { + + case USB_ID(0x0763, 0x2003): /* M-Audio Audiophile USB */ + if (device_setup[chip->index] == 0x00 && + fp->altsetting == 6) + pcm_format = SNDRV_PCM_FORMAT_S16_BE; + else + pcm_format = SNDRV_PCM_FORMAT_S16_LE; + break; + default: + pcm_format = SNDRV_PCM_FORMAT_S16_LE; + } } else { pcm_format = parse_audio_format_i_type(chip, fp, format, fmt); if (pcm_format < 0) @@ -3064,6 +3083,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); @@ -3193,6 +3264,11 @@ static int snd_usb_cm106_boot_quirk(struct usb_device *dev) static int audiophile_skip_setting_quirk(struct snd_usb_audio *chip, int iface, int altno) { + /* Reset ALL ifaces to 0 altsetting. + * Call it for every possible altsetting of every interface. + */ + usb_set_interface(chip->dev, iface, 0); + if (device_setup[chip->index] & AUDIOPHILE_SET) { if ((device_setup[chip->index] & AUDIOPHILE_SET_DTS) && altno != 6) @@ -3245,6 +3321,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) {