diff options
author | Markus Grabner <grabner@icg.tugraz.at> | 2010-08-12 01:35:30 +0200 |
---|---|---|
committer | Greg Kroah-Hartman <gregkh@suse.de> | 2010-08-31 15:28:15 -0700 |
commit | 1027f476f507ef7ed9919cd3e3d32310f3985da1 (patch) | |
tree | 5f0da58a5bc15338c71e848693a5ae259b97a207 /drivers/staging/line6/playback.c | |
parent | 4498dbcd2d85b67e9f46790bcfee5860d2dd1762 (diff) |
staging: line6: sync with upstream
Big upstream sync.
Signed-off-by: Markus Grabner <grabner@icg.tugraz.at>
Signed-off-by: Greg Kroah-Hartman <gregkh@suse.de>
Diffstat (limited to 'drivers/staging/line6/playback.c')
-rw-r--r-- | drivers/staging/line6/playback.c | 302 |
1 files changed, 206 insertions, 96 deletions
diff --git a/drivers/staging/line6/playback.c b/drivers/staging/line6/playback.c index fbcd6e150aa..0c8c0c8bcd9 100644 --- a/drivers/staging/line6/playback.c +++ b/drivers/staging/line6/playback.c @@ -1,7 +1,7 @@ /* - * Line6 Linux USB driver - 0.8.0 + * Line6 Linux USB driver - 0.9.0 * - * Copyright (C) 2004-2009 Markus Grabner (grabner@icg.tugraz.at) + * Copyright (C) 2004-2010 Markus Grabner (grabner@icg.tugraz.at) * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License as @@ -9,15 +9,13 @@ * */ -#include "driver.h" - -#include <linux/slab.h> - #include <sound/core.h> #include <sound/pcm.h> #include <sound/pcm_params.h> #include "audio.h" +#include "capture.h" +#include "driver.h" #include "pcm.h" #include "pod.h" #include "playback.h" @@ -59,22 +57,85 @@ static void change_volume(struct urb *urb_out, int volume[], } } +#ifdef CONFIG_LINE6_USB_IMPULSE_RESPONSE + +/* + Create signal for impulse response test. +*/ +static void create_impulse_test_signal(struct snd_line6_pcm *line6pcm, + struct urb *urb_out, int bytes_per_frame) +{ + int frames = urb_out->transfer_buffer_length / bytes_per_frame; + + if (bytes_per_frame == 4) { + /* TODO: add code for TonePort etc. */ + } else if (bytes_per_frame == 6) { + int i, j; + unsigned char *pi = line6pcm->prev_fbuf; + unsigned char *po = urb_out->transfer_buffer; + + for (i = 0; i < frames; ++i) { + for (j = 0; j < bytes_per_frame / 2; ++j) + po[j] = pi[j]; + + for (; j < bytes_per_frame; ++j) + po[j] = 0; + + pi += bytes_per_frame; + po += bytes_per_frame; + } + + if (--line6pcm->impulse_count <= 0) { + ((unsigned char *)(urb_out-> + transfer_buffer))[bytes_per_frame - + 1] = + line6pcm->impulse_volume; + line6pcm->impulse_count = line6pcm->impulse_period; + } + } +} + +#endif + +/* + Add signal to buffer for software monitoring. +*/ +static void add_monitor_signal(struct urb *urb_out, unsigned char *signal, + int volume, int bytes_per_frame) +{ + if (volume == 0) + return; /* zero volume - no change */ + + if (bytes_per_frame == 4) { + short *pi, *po, *buf_end; + pi = (short *)signal; + po = (short *)urb_out->transfer_buffer; + buf_end = po + urb_out->transfer_buffer_length / sizeof(*po); + + for (; po < buf_end; ++pi, ++po) + *po += (*pi * volume) >> 8; + } + + /* + We don't need to handle devices with 6 bytes per frame here + since they all support hardware monitoring. + */ +} + /* Find a free URB, prepare audio data, and submit URB. */ -static int submit_audio_out_urb(struct snd_pcm_substream *substream) +static int submit_audio_out_urb(struct snd_line6_pcm *line6pcm) { int index; unsigned long flags; int i, urb_size, urb_frames; - struct snd_line6_pcm *line6pcm = snd_pcm_substream_chip(substream); const int bytes_per_frame = line6pcm->properties->bytes_per_frame; const int frame_increment = line6pcm->properties->snd_line6_rates.rats[0].num_min; const int frame_factor = line6pcm->properties->snd_line6_rates.rats[0].den * (USB_INTERVALS_PER_SECOND / LINE6_ISO_INTERVAL); - struct snd_pcm_runtime *runtime = substream->runtime; struct urb *urb_out; spin_lock_irqsave(&line6pcm->lock_audio_out, flags); @@ -83,7 +144,7 @@ static int submit_audio_out_urb(struct snd_pcm_substream *substream) if (index < 0 || index >= LINE6_ISO_BUFFERS) { spin_unlock_irqrestore(&line6pcm->lock_audio_out, flags); - dev_err(s2m(substream), "no free URB found\n"); + dev_err(line6pcm->line6->ifcdev, "no free URB found\n"); return -EINVAL; } @@ -92,24 +153,49 @@ static int submit_audio_out_urb(struct snd_pcm_substream *substream) for (i = 0; i < LINE6_ISO_PACKETS; ++i) { /* compute frame size for given sampling rate */ - int n, fs; + int fsize = 0; struct usb_iso_packet_descriptor *fout = &urb_out->iso_frame_desc[i]; - line6pcm->count_out += frame_increment; - n = line6pcm->count_out / frame_factor; - line6pcm->count_out -= n * frame_factor; - fs = n * bytes_per_frame; + + if (line6pcm->flags & MASK_CAPTURE) { + fsize = line6pcm->prev_fsize; + } + + if (fsize == 0) { + int n; + line6pcm->count_out += frame_increment; + n = line6pcm->count_out / frame_factor; + line6pcm->count_out -= n * frame_factor; + fsize = n * bytes_per_frame; + } + fout->offset = urb_size; - fout->length = fs; - urb_size += fs; + fout->length = fsize; + urb_size += fsize; + } + + if (urb_size == 0) { + /* can't determine URB size */ + spin_unlock_irqrestore(&line6pcm->lock_audio_out, flags); + dev_err(line6pcm->line6->ifcdev, "driver bug: urb_size = 0\n"); /* this is somewhat paranoid */ + return -EINVAL; } urb_frames = urb_size / bytes_per_frame; + urb_out->transfer_buffer = + line6pcm->buffer_out + + line6pcm->max_packet_size * line6pcm->index_out; + urb_out->transfer_buffer_length = urb_size; + urb_out->context = line6pcm; + + if (++line6pcm->index_out == LINE6_ISO_BUFFERS) + line6pcm->index_out = 0; + + if (test_bit(BIT_PCM_ALSA_PLAYBACK, &line6pcm->flags) && + !test_bit(BIT_PAUSE_PLAYBACK, &line6pcm->flags)) { + struct snd_pcm_runtime *runtime = + get_substream(line6pcm, SNDRV_PCM_STREAM_PLAYBACK)->runtime; - if (test_bit(BIT_PAUSE_PLAYBACK, &line6pcm->flags)) { - urb_out->transfer_buffer = line6pcm->wrap_out; - memset(line6pcm->wrap_out, 0, urb_size); - } else { if (line6pcm->pos_out + urb_frames > runtime->buffer_size) { /* The transferred area goes over buffer boundary, @@ -117,38 +203,65 @@ static int submit_audio_out_urb(struct snd_pcm_substream *substream) */ int len; len = runtime->buffer_size - line6pcm->pos_out; - urb_out->transfer_buffer = line6pcm->wrap_out; if (len > 0) { - memcpy(line6pcm->wrap_out, + memcpy(urb_out->transfer_buffer, runtime->dma_area + line6pcm->pos_out * bytes_per_frame, len * bytes_per_frame); - memcpy(line6pcm->wrap_out + + memcpy(urb_out->transfer_buffer + len * bytes_per_frame, runtime->dma_area, (urb_frames - len) * bytes_per_frame); - } else { - /* this is somewhat paranoid */ - dev_err(s2m(substream), - "driver bug: len = %d\n", len); - } + } else + dev_err(line6pcm->line6->ifcdev, "driver bug: len = %d\n", len); /* this is somewhat paranoid */ } else { +#if LINE6_REUSE_DMA_AREA_FOR_PLAYBACK /* set the buffer pointer */ urb_out->transfer_buffer = runtime->dma_area + line6pcm->pos_out * bytes_per_frame; +#else + /* copy data */ + memcpy(urb_out->transfer_buffer, + runtime->dma_area + + line6pcm->pos_out * bytes_per_frame, + urb_out->transfer_buffer_length); +#endif } - } - line6pcm->pos_out += urb_frames; - if (line6pcm->pos_out >= runtime->buffer_size) - line6pcm->pos_out -= runtime->buffer_size; + if ((line6pcm->pos_out += urb_frames) >= runtime->buffer_size) + line6pcm->pos_out -= runtime->buffer_size; + } else { + memset(urb_out->transfer_buffer, 0, + urb_out->transfer_buffer_length); + } - urb_out->transfer_buffer_length = urb_size; - urb_out->context = substream; - change_volume(urb_out, line6pcm->volume, bytes_per_frame); + change_volume(urb_out, line6pcm->volume_playback, bytes_per_frame); -#if DO_DUMP_PCM_SEND + if (line6pcm->prev_fbuf != 0) { +#ifdef CONFIG_LINE6_USB_IMPULSE_RESPONSE + if (line6pcm->flags & MASK_PCM_IMPULSE) { + create_impulse_test_signal(line6pcm, urb_out, + bytes_per_frame); + if (line6pcm->flags & MASK_PCM_ALSA_CAPTURE) { + line6_capture_copy(line6pcm, urb_out->transfer_buffer, + urb_out->transfer_buffer_length); + } + } else { +#endif + if (! + (line6pcm->line6->properties-> + capabilities & LINE6_BIT_HWMON) + && (line6pcm->flags & MASK_PLAYBACK) + && (line6pcm->flags & MASK_CAPTURE)) + add_monitor_signal(urb_out, line6pcm->prev_fbuf, + line6pcm->volume_monitor, + bytes_per_frame); +#ifdef CONFIG_LINE6_USB_IMPULSE_RESPONSE + } +#endif + } +#ifdef CONFIG_LINE6_USB_DUMP_PCM for (i = 0; i < LINE6_ISO_PACKETS; ++i) { struct usb_iso_packet_descriptor *fout = &urb_out->iso_frame_desc[i]; @@ -161,8 +274,8 @@ static int submit_audio_out_urb(struct snd_pcm_substream *substream) if (usb_submit_urb(urb_out, GFP_ATOMIC) == 0) set_bit(index, &line6pcm->active_urb_out); else - dev_err(s2m(substream), "URB out #%d submission failed\n", - index); + dev_err(line6pcm->line6->ifcdev, + "URB out #%d submission failed\n", index); spin_unlock_irqrestore(&line6pcm->lock_audio_out, flags); return 0; @@ -171,12 +284,12 @@ static int submit_audio_out_urb(struct snd_pcm_substream *substream) /* Submit all currently available playback URBs. */ -static int submit_audio_out_all_urbs(struct snd_pcm_substream *substream) +int line6_submit_audio_out_all_urbs(struct snd_line6_pcm *line6pcm) { int ret, i; for (i = 0; i < LINE6_ISO_BUFFERS; ++i) { - ret = submit_audio_out_urb(substream); + ret = submit_audio_out_urb(line6pcm); if (ret < 0) return ret; } @@ -187,7 +300,7 @@ static int submit_audio_out_all_urbs(struct snd_pcm_substream *substream) /* Unlink all currently active playback URBs. */ -static void unlink_audio_out_urbs(struct snd_line6_pcm *line6pcm) +void line6_unlink_audio_out_urbs(struct snd_line6_pcm *line6pcm) { unsigned int i; @@ -202,7 +315,7 @@ static void unlink_audio_out_urbs(struct snd_line6_pcm *line6pcm) } /* - Wait until unlinking of all currently active playback URBs has been finished. + Wait until unlinking of all currently active playback URBs has been finished. */ static void wait_clear_audio_out_urbs(struct snd_line6_pcm *line6pcm) { @@ -223,17 +336,14 @@ static void wait_clear_audio_out_urbs(struct snd_line6_pcm *line6pcm) } while (--timeout > 0); if (alive) snd_printk(KERN_ERR "timeout: still %d active urbs..\n", alive); - - line6pcm->active_urb_out = 0; - line6pcm->unlink_urb_out = 0; } /* Unlink all currently active playback URBs, and wait for finishing. */ -void unlink_wait_clear_audio_out_urbs(struct snd_line6_pcm *line6pcm) +void line6_unlink_wait_clear_audio_out_urbs(struct snd_line6_pcm *line6pcm) { - unlink_audio_out_urbs(line6pcm); + line6_unlink_audio_out_urbs(line6pcm); wait_clear_audio_out_urbs(line6pcm); } @@ -245,10 +355,16 @@ static void audio_out_callback(struct urb *urb) int i, index, length = 0, shutdown = 0; unsigned long flags; + struct snd_line6_pcm *line6pcm = + (struct snd_line6_pcm *)urb->context; struct snd_pcm_substream *substream = - (struct snd_pcm_substream *)urb->context; - struct snd_line6_pcm *line6pcm = snd_pcm_substream_chip(substream); - struct snd_pcm_runtime *runtime = substream->runtime; + get_substream(line6pcm, SNDRV_PCM_STREAM_PLAYBACK); + +#if USE_CLEAR_BUFFER_WORKAROUND + memset(urb->transfer_buffer, 0, urb->transfer_buffer_length); +#endif + + line6pcm->last_frame_out = urb->start_frame; /* find index of URB */ for (index = LINE6_ISO_BUFFERS; index--;) @@ -262,11 +378,15 @@ static void audio_out_callback(struct urb *urb) length += urb->iso_frame_desc[i].length; spin_lock_irqsave(&line6pcm->lock_audio_out, flags); - line6pcm->pos_out_done += - length / line6pcm->properties->bytes_per_frame; - if (line6pcm->pos_out_done >= runtime->buffer_size) - line6pcm->pos_out_done -= runtime->buffer_size; + if (test_bit(BIT_PCM_ALSA_PLAYBACK, &line6pcm->flags)) { + struct snd_pcm_runtime *runtime = substream->runtime; + line6pcm->pos_out_done += + length / line6pcm->properties->bytes_per_frame; + + if (line6pcm->pos_out_done >= runtime->buffer_size) + line6pcm->pos_out_done -= runtime->buffer_size; + } clear_bit(index, &line6pcm->active_urb_out); @@ -276,18 +396,20 @@ static void audio_out_callback(struct urb *urb) break; } - if (test_bit(index, &line6pcm->unlink_urb_out)) + if (test_and_clear_bit(index, &line6pcm->unlink_urb_out)) shutdown = 1; spin_unlock_irqrestore(&line6pcm->lock_audio_out, flags); if (!shutdown) { - submit_audio_out_urb(substream); + submit_audio_out_urb(line6pcm); - line6pcm->bytes_out += length; - if (line6pcm->bytes_out >= line6pcm->period_out) { - line6pcm->bytes_out -= line6pcm->period_out; - snd_pcm_period_elapsed(substream); + if (test_bit(BIT_PCM_ALSA_PLAYBACK, &line6pcm->flags)) { + if ((line6pcm->bytes_out += + length) >= line6pcm->period_out) { + line6pcm->bytes_out %= line6pcm->period_out; + snd_pcm_period_elapsed(substream); + } } } } @@ -340,52 +462,40 @@ static int snd_line6_playback_hw_params(struct snd_pcm_substream *substream, return ret; line6pcm->period_out = params_period_bytes(hw_params); - line6pcm->wrap_out = kmalloc(2 * LINE6_ISO_PACKET_SIZE_MAX, GFP_KERNEL); - - if (!line6pcm->wrap_out) { - dev_err(s2m(substream), "cannot malloc wrap_out\n"); - return -ENOMEM; - } - return 0; } /* hw_free playback callback */ static int snd_line6_playback_hw_free(struct snd_pcm_substream *substream) { - struct snd_line6_pcm *line6pcm = snd_pcm_substream_chip(substream); - unlink_wait_clear_audio_out_urbs(line6pcm); - - kfree(line6pcm->wrap_out); - line6pcm->wrap_out = NULL; - return snd_pcm_lib_free_pages(substream); } /* trigger playback callback */ -int snd_line6_playback_trigger(struct snd_pcm_substream *substream, int cmd) +int snd_line6_playback_trigger(struct snd_line6_pcm *line6pcm, int cmd) { - struct snd_line6_pcm *line6pcm = snd_pcm_substream_chip(substream); int err; - line6pcm->count_out = 0; switch (cmd) { case SNDRV_PCM_TRIGGER_START: - if (!test_and_set_bit(BIT_RUNNING_PLAYBACK, &line6pcm->flags)) { - err = submit_audio_out_all_urbs(substream); +#ifdef CONFIG_PM + case SNDRV_PCM_TRIGGER_RESUME: +#endif + err = line6_pcm_start(line6pcm, MASK_PCM_ALSA_PLAYBACK); - if (err < 0) { - clear_bit(BIT_RUNNING_PLAYBACK, - &line6pcm->flags); - return err; - } - } + if (err < 0) + return err; break; case SNDRV_PCM_TRIGGER_STOP: - if (test_and_clear_bit(BIT_RUNNING_PLAYBACK, &line6pcm->flags)) - unlink_audio_out_urbs(line6pcm); +#ifdef CONFIG_PM + case SNDRV_PCM_TRIGGER_SUSPEND: +#endif + err = line6_pcm_stop(line6pcm, MASK_PCM_ALSA_PLAYBACK); + + if (err < 0) + return err; break; @@ -414,17 +524,17 @@ snd_line6_playback_pointer(struct snd_pcm_substream *substream) /* playback operators */ struct snd_pcm_ops snd_line6_playback_ops = { - .open = snd_line6_playback_open, - .close = snd_line6_playback_close, - .ioctl = snd_pcm_lib_ioctl, - .hw_params = snd_line6_playback_hw_params, - .hw_free = snd_line6_playback_hw_free, - .prepare = snd_line6_prepare, - .trigger = snd_line6_trigger, - .pointer = snd_line6_playback_pointer, + .open = snd_line6_playback_open, + .close = snd_line6_playback_close, + .ioctl = snd_pcm_lib_ioctl, + .hw_params = snd_line6_playback_hw_params, + .hw_free = snd_line6_playback_hw_free, + .prepare = snd_line6_prepare, + .trigger = snd_line6_trigger, + .pointer = snd_line6_playback_pointer, }; -int create_audio_out_urbs(struct snd_line6_pcm *line6pcm) +int line6_create_audio_out_urbs(struct snd_line6_pcm *line6pcm) { int i; |