X-Git-Url: http://pilppa.org/gitweb/?a=blobdiff_plain;f=sound%2Fusb%2Fusbaudio.c;h=8fd37596e3a171a1a3ecded3c63c23a9ea1354e5;hb=8fec560d9beb3957bf45ac93b1c0c616abd77a07;hp=19bdcc74c96c9aa376742135c0c65de753dc62e7;hpb=51e6ed23fc95c3e710d8a98717924ccb2571aa66;p=linux-2.6-omap-h63xx.git diff --git a/sound/usb/usbaudio.c b/sound/usb/usbaudio.c index 19bdcc74c96..8fd37596e3a 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 */ @@ -391,6 +392,16 @@ static int retire_capture_urb(struct snd_usb_substream *subs, return 0; } +/* + * Process after capture complete when paused. Nothing to do. + */ +static int retire_paused_capture_urb(struct snd_usb_substream *subs, + struct snd_pcm_runtime *runtime, + struct urb *urb) +{ + return 0; +} + /* * prepare urb for full speed playback sync pipe @@ -402,7 +413,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; @@ -420,7 +431,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; @@ -493,13 +504,13 @@ static int snd_usb_audio_next_packet_size(struct snd_usb_substream *subs) } /* - * Prepare urb for streaming before playback starts. + * Prepare urb for streaming before playback starts or when paused. * - * We don't yet have data, so we send a frame of silence. + * We don't have any data, so we send a frame of silence. */ -static int prepare_startup_playback_urb(struct snd_usb_substream *subs, - struct snd_pcm_runtime *runtime, - struct urb *urb) +static int prepare_nodata_playback_urb(struct snd_usb_substream *subs, + struct snd_pcm_runtime *runtime, + struct urb *urb) { unsigned int i, offs, counts; struct snd_urb_ctx *ctx = urb->context; @@ -537,7 +548,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; @@ -622,7 +633,7 @@ static int retire_playback_urb(struct snd_usb_substream *subs, */ static struct snd_urb_ops audio_urb_ops[2] = { { - .prepare = prepare_startup_playback_urb, + .prepare = prepare_nodata_playback_urb, .retire = retire_playback_urb, .prepare_sync = prepare_playback_sync_urb, .retire_sync = retire_playback_sync_urb, @@ -637,7 +648,7 @@ static struct snd_urb_ops audio_urb_ops[2] = { static struct snd_urb_ops audio_urb_ops_high_speed[2] = { { - .prepare = prepare_startup_playback_urb, + .prepare = prepare_nodata_playback_urb, .retire = retire_playback_urb, .prepare_sync = prepare_playback_sync_urb_hs, .retire_sync = retire_playback_sync_urb_hs, @@ -655,7 +666,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; @@ -678,7 +689,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; @@ -925,10 +936,14 @@ static int snd_usb_pcm_playback_trigger(struct snd_pcm_substream *substream, switch (cmd) { case SNDRV_PCM_TRIGGER_START: + case SNDRV_PCM_TRIGGER_PAUSE_RELEASE: subs->ops.prepare = prepare_playback_urb; return 0; case SNDRV_PCM_TRIGGER_STOP: return deactivate_urbs(subs, 0, 0); + case SNDRV_PCM_TRIGGER_PAUSE_PUSH: + subs->ops.prepare = prepare_nodata_playback_urb; + return 0; default: return -EINVAL; } @@ -944,9 +959,16 @@ static int snd_usb_pcm_capture_trigger(struct snd_pcm_substream *substream, switch (cmd) { case SNDRV_PCM_TRIGGER_START: + subs->ops.retire = retire_capture_urb; return start_urbs(subs, substream->runtime); case SNDRV_PCM_TRIGGER_STOP: return deactivate_urbs(subs, 0, 0); + case SNDRV_PCM_TRIGGER_PAUSE_PUSH: + subs->ops.retire = retire_paused_capture_urb; + return 0; + case SNDRV_PCM_TRIGGER_PAUSE_RELEASE: + subs->ops.retire = retire_capture_urb; + return 0; default: return -EINVAL; } @@ -1408,7 +1430,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; @@ -1464,7 +1486,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; @@ -1505,33 +1527,20 @@ static int snd_usb_pcm_prepare(struct snd_pcm_substream *substream) /* for playback, submit the URBs now; otherwise, the first hwptr_done * updates for all URBs would happen at the same time when starting */ if (subs->direction == SNDRV_PCM_STREAM_PLAYBACK) { - subs->ops.prepare = prepare_startup_playback_urb; + subs->ops.prepare = prepare_nodata_playback_urb; return start_urbs(subs, runtime); } else return 0; } -static struct snd_pcm_hardware snd_usb_playback = +static struct snd_pcm_hardware snd_usb_hardware = { .info = SNDRV_PCM_INFO_MMAP | SNDRV_PCM_INFO_MMAP_VALID | SNDRV_PCM_INFO_BATCH | SNDRV_PCM_INFO_INTERLEAVED | - SNDRV_PCM_INFO_BLOCK_TRANSFER, - .buffer_bytes_max = 1024 * 1024, - .period_bytes_min = 64, - .period_bytes_max = 512 * 1024, - .periods_min = 2, - .periods_max = 1024, -}; - -static struct snd_pcm_hardware snd_usb_capture = -{ - .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_BLOCK_TRANSFER | + SNDRV_PCM_INFO_PAUSE, .buffer_bytes_max = 1024 * 1024, .period_bytes_min = 64, .period_bytes_max = 512 * 1024, @@ -1810,28 +1819,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; } @@ -1904,8 +1918,7 @@ static int setup_hw_info(struct snd_pcm_runtime *runtime, struct snd_usb_substre return 0; } -static int snd_usb_pcm_open(struct snd_pcm_substream *substream, int direction, - struct snd_pcm_hardware *hw) +static int snd_usb_pcm_open(struct snd_pcm_substream *substream, int direction) { struct snd_usb_stream *as = snd_pcm_substream_chip(substream); struct snd_pcm_runtime *runtime = substream->runtime; @@ -1913,7 +1926,7 @@ static int snd_usb_pcm_open(struct snd_pcm_substream *substream, int direction, subs->interface = -1; subs->format = 0; - runtime->hw = *hw; + runtime->hw = snd_usb_hardware; runtime->private_data = subs; subs->pcm_substream = substream; return setup_hw_info(runtime, subs); @@ -1934,7 +1947,7 @@ static int snd_usb_pcm_close(struct snd_pcm_substream *substream, int direction) static int snd_usb_playback_open(struct snd_pcm_substream *substream) { - return snd_usb_pcm_open(substream, SNDRV_PCM_STREAM_PLAYBACK, &snd_usb_playback); + return snd_usb_pcm_open(substream, SNDRV_PCM_STREAM_PLAYBACK); } static int snd_usb_playback_close(struct snd_pcm_substream *substream) @@ -1944,7 +1957,7 @@ static int snd_usb_playback_close(struct snd_pcm_substream *substream) static int snd_usb_capture_open(struct snd_pcm_substream *substream) { - return snd_usb_pcm_open(substream, SNDRV_PCM_STREAM_CAPTURE, &snd_usb_capture); + return snd_usb_pcm_open(substream, SNDRV_PCM_STREAM_CAPTURE); } static int snd_usb_capture_close(struct snd_pcm_substream *substream) @@ -2231,6 +2244,7 @@ static void free_substream(struct snd_usb_substream *subs) kfree(fp->rate_table); kfree(fp); } + kfree(subs->rate_list.list); } @@ -2456,6 +2470,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, @@ -2478,6 +2493,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) @@ -2493,6 +2509,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 {