Commit 6b02a17e authored by Markus Grabner's avatar Markus Grabner Committed by Greg Kroah-Hartman

staging: line6: fixed ALSA/PCM interaction

The PCM subsystem in the Line6 driver is mainly used for PCM playback and
capture by ALSA, but also has other tasks, most notably providing a
low-latency software monitor for devices which don't support hardware
monitoring (e.g., the TonePort series). This patch makes ALSA "play nicely"
with the other components, i.e., prevents it from resetting the isochronous
USB transfer while other PCM tasks (software monitoring) are running.
Signed-off-by: default avatarMarkus Grabner <grabner@icg.tugraz.at>
Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@suse.de>
parent 665f3f50
...@@ -193,6 +193,31 @@ void line6_capture_check_period(struct snd_line6_pcm *line6pcm, int length) ...@@ -193,6 +193,31 @@ void line6_capture_check_period(struct snd_line6_pcm *line6pcm, int length)
} }
} }
int line6_alloc_capture_buffer(struct snd_line6_pcm *line6pcm)
{
/* We may be invoked multiple times in a row so allocate once only */
if (line6pcm->buffer_in)
return 0;
line6pcm->buffer_in =
kmalloc(LINE6_ISO_BUFFERS * LINE6_ISO_PACKETS *
line6pcm->max_packet_size, GFP_KERNEL);
if (!line6pcm->buffer_in) {
dev_err(line6pcm->line6->ifcdev,
"cannot malloc capture buffer\n");
return -ENOMEM;
}
return 0;
}
void line6_free_capture_buffer(struct snd_line6_pcm *line6pcm)
{
kfree(line6pcm->buffer_in);
line6pcm->buffer_in = NULL;
}
/* /*
* Callback for completed capture URB. * Callback for completed capture URB.
*/ */
...@@ -316,16 +341,11 @@ static int snd_line6_capture_hw_params(struct snd_pcm_substream *substream, ...@@ -316,16 +341,11 @@ static int snd_line6_capture_hw_params(struct snd_pcm_substream *substream,
} }
/* -- [FD] end */ /* -- [FD] end */
/* We may be invoked multiple times in a row so allocate once only */ if ((line6pcm->flags & MASK_CAPTURE) == 0) {
if (!line6pcm->buffer_in) ret = line6_alloc_capture_buffer(line6pcm);
line6pcm->buffer_in =
kmalloc(LINE6_ISO_BUFFERS * LINE6_ISO_PACKETS *
line6pcm->max_packet_size, GFP_KERNEL);
if (!line6pcm->buffer_in) { if (ret < 0)
dev_err(line6pcm->line6->ifcdev, return ret;
"cannot malloc capture buffer\n");
return -ENOMEM;
} }
ret = snd_pcm_lib_malloc_pages(substream, ret = snd_pcm_lib_malloc_pages(substream,
...@@ -342,9 +362,11 @@ static int snd_line6_capture_hw_free(struct snd_pcm_substream *substream) ...@@ -342,9 +362,11 @@ static int snd_line6_capture_hw_free(struct snd_pcm_substream *substream)
{ {
struct snd_line6_pcm *line6pcm = snd_pcm_substream_chip(substream); struct snd_line6_pcm *line6pcm = snd_pcm_substream_chip(substream);
line6_unlink_wait_clear_audio_in_urbs(line6pcm); if ((line6pcm->flags & MASK_CAPTURE) == 0) {
kfree(line6pcm->buffer_in); line6_unlink_wait_clear_audio_in_urbs(line6pcm);
line6pcm->buffer_in = NULL; line6_free_capture_buffer(line6pcm);
}
return snd_pcm_lib_free_pages(substream); return snd_pcm_lib_free_pages(substream);
} }
......
...@@ -19,11 +19,13 @@ ...@@ -19,11 +19,13 @@
extern struct snd_pcm_ops snd_line6_capture_ops; extern struct snd_pcm_ops snd_line6_capture_ops;
extern int line6_alloc_capture_buffer(struct snd_line6_pcm *line6pcm);
extern void line6_capture_copy(struct snd_line6_pcm *line6pcm, char *fbuf, extern void line6_capture_copy(struct snd_line6_pcm *line6pcm, char *fbuf,
int fsize); int fsize);
extern void line6_capture_check_period(struct snd_line6_pcm *line6pcm, extern void line6_capture_check_period(struct snd_line6_pcm *line6pcm,
int length); int length);
extern int line6_create_audio_in_urbs(struct snd_line6_pcm *line6pcm); extern int line6_create_audio_in_urbs(struct snd_line6_pcm *line6pcm);
extern void line6_free_capture_buffer(struct snd_line6_pcm *line6pcm);
extern int line6_submit_audio_in_all_urbs(struct snd_line6_pcm *line6pcm); extern int line6_submit_audio_in_all_urbs(struct snd_line6_pcm *line6pcm);
extern void line6_unlink_audio_in_urbs(struct snd_line6_pcm *line6pcm); extern void line6_unlink_audio_in_urbs(struct snd_line6_pcm *line6pcm);
extern void line6_unlink_wait_clear_audio_in_urbs(struct snd_line6_pcm extern void line6_unlink_wait_clear_audio_in_urbs(struct snd_line6_pcm
......
...@@ -86,17 +86,22 @@ static DEVICE_ATTR(impulse_period, S_IWUSR | S_IRUGO, pcm_get_impulse_period, ...@@ -86,17 +86,22 @@ static DEVICE_ATTR(impulse_period, S_IWUSR | S_IRUGO, pcm_get_impulse_period,
#endif #endif
static bool test_flags(unsigned long flags0, unsigned long flags1,
unsigned long mask)
{
return ((flags0 & mask) == 0) && ((flags1 & mask) != 0);
}
int line6_pcm_start(struct snd_line6_pcm *line6pcm, int channels) int line6_pcm_start(struct snd_line6_pcm *line6pcm, int channels)
{ {
unsigned long flags_old = unsigned long flags_old =
__sync_fetch_and_or(&line6pcm->flags, channels); __sync_fetch_and_or(&line6pcm->flags, channels);
unsigned long flags_new = flags_old | channels; unsigned long flags_new = flags_old | channels;
int err = 0; int err = 0;
line6pcm->prev_fbuf = NULL; line6pcm->prev_fbuf = NULL;
if (((flags_old & MASK_CAPTURE) == 0) && if (test_flags(flags_old, flags_new, MASK_CAPTURE)) {
((flags_new & MASK_CAPTURE) != 0)) {
/* /*
Waiting for completion of active URBs in the stop handler is Waiting for completion of active URBs in the stop handler is
a bug, we therefore report an error if capturing is restarted a bug, we therefore report an error if capturing is restarted
...@@ -105,34 +110,47 @@ int line6_pcm_start(struct snd_line6_pcm *line6pcm, int channels) ...@@ -105,34 +110,47 @@ int line6_pcm_start(struct snd_line6_pcm *line6pcm, int channels)
if (line6pcm->active_urb_in | line6pcm->unlink_urb_in) if (line6pcm->active_urb_in | line6pcm->unlink_urb_in)
return -EBUSY; return -EBUSY;
if (!(flags_new & MASK_PCM_ALSA_CAPTURE)) {
err = line6_alloc_capture_buffer(line6pcm);
if (err < 0)
goto pcm_start_error;
}
line6pcm->count_in = 0; line6pcm->count_in = 0;
line6pcm->prev_fsize = 0; line6pcm->prev_fsize = 0;
err = line6_submit_audio_in_all_urbs(line6pcm); err = line6_submit_audio_in_all_urbs(line6pcm);
if (err < 0) { if (err < 0)
__sync_fetch_and_and(&line6pcm->flags, ~channels); goto pcm_start_error;
return err;
}
} }
if (((flags_old & MASK_PLAYBACK) == 0) && if (test_flags(flags_old, flags_new, MASK_PLAYBACK)) {
((flags_new & MASK_PLAYBACK) != 0)) {
/* /*
See comment above regarding PCM restart. See comment above regarding PCM restart.
*/ */
if (line6pcm->active_urb_out | line6pcm->unlink_urb_out) if (line6pcm->active_urb_out | line6pcm->unlink_urb_out)
return -EBUSY; return -EBUSY;
if (!(flags_new & MASK_PCM_ALSA_PLAYBACK)) {
err = line6_alloc_playback_buffer(line6pcm);
if (err < 0)
goto pcm_start_error;
}
line6pcm->count_out = 0; line6pcm->count_out = 0;
err = line6_submit_audio_out_all_urbs(line6pcm); err = line6_submit_audio_out_all_urbs(line6pcm);
if (err < 0) { if (err < 0)
__sync_fetch_and_and(&line6pcm->flags, ~channels); goto pcm_start_error;
return err;
}
} }
return 0; return 0;
pcm_start_error:
__sync_fetch_and_and(&line6pcm->flags, ~channels);
return err;
} }
int line6_pcm_stop(struct snd_line6_pcm *line6pcm, int channels) int line6_pcm_stop(struct snd_line6_pcm *line6pcm, int channels)
...@@ -141,14 +159,18 @@ int line6_pcm_stop(struct snd_line6_pcm *line6pcm, int channels) ...@@ -141,14 +159,18 @@ int line6_pcm_stop(struct snd_line6_pcm *line6pcm, int channels)
__sync_fetch_and_and(&line6pcm->flags, ~channels); __sync_fetch_and_and(&line6pcm->flags, ~channels);
unsigned long flags_new = flags_old & ~channels; unsigned long flags_new = flags_old & ~channels;
if (((flags_old & MASK_CAPTURE) != 0) && if (test_flags(flags_new, flags_old, MASK_CAPTURE)) {
((flags_new & MASK_CAPTURE) == 0)) {
line6_unlink_audio_in_urbs(line6pcm); line6_unlink_audio_in_urbs(line6pcm);
if (!(flags_old & MASK_PCM_ALSA_CAPTURE))
line6_free_capture_buffer(line6pcm);
} }
if (((flags_old & MASK_PLAYBACK) != 0) && if (test_flags(flags_new, flags_old, MASK_PLAYBACK)) {
((flags_new & MASK_PLAYBACK) == 0)) {
line6_unlink_audio_out_urbs(line6pcm); line6_unlink_audio_out_urbs(line6pcm);
if (!(flags_old & MASK_PCM_ALSA_PLAYBACK))
line6_free_playback_buffer(line6pcm);
} }
return 0; return 0;
...@@ -476,18 +498,21 @@ int snd_line6_prepare(struct snd_pcm_substream *substream) ...@@ -476,18 +498,21 @@ int snd_line6_prepare(struct snd_pcm_substream *substream)
switch (substream->stream) { switch (substream->stream) {
case SNDRV_PCM_STREAM_PLAYBACK: case SNDRV_PCM_STREAM_PLAYBACK:
line6_unlink_wait_clear_audio_out_urbs(line6pcm); if ((line6pcm->flags & MASK_PLAYBACK) == 0)
line6_unlink_wait_clear_audio_out_urbs(line6pcm);
break; break;
case SNDRV_PCM_STREAM_CAPTURE: case SNDRV_PCM_STREAM_CAPTURE:
line6_unlink_wait_clear_audio_in_urbs(line6pcm); if ((line6pcm->flags & MASK_CAPTURE) == 0)
line6_unlink_wait_clear_audio_in_urbs(line6pcm);
break; break;
default: default:
MISSING_CASE; MISSING_CASE;
} }
if (!test_and_set_bit(BIT_PREPARED, &line6pcm->flags)) { if (!test_and_set_bit(BIT_PREPARED, &line6pcm->flags)) {
line6pcm->count_out = 0; line6pcm->count_out = 0;
line6pcm->pos_out = 0; line6pcm->pos_out = 0;
......
...@@ -351,6 +351,31 @@ void line6_unlink_wait_clear_audio_out_urbs(struct snd_line6_pcm *line6pcm) ...@@ -351,6 +351,31 @@ void line6_unlink_wait_clear_audio_out_urbs(struct snd_line6_pcm *line6pcm)
wait_clear_audio_out_urbs(line6pcm); wait_clear_audio_out_urbs(line6pcm);
} }
int line6_alloc_playback_buffer(struct snd_line6_pcm *line6pcm)
{
/* We may be invoked multiple times in a row so allocate once only */
if (line6pcm->buffer_out)
return 0;
line6pcm->buffer_out =
kmalloc(LINE6_ISO_BUFFERS * LINE6_ISO_PACKETS *
line6pcm->max_packet_size, GFP_KERNEL);
if (!line6pcm->buffer_out) {
dev_err(line6pcm->line6->ifcdev,
"cannot malloc playback buffer\n");
return -ENOMEM;
}
return 0;
}
void line6_free_playback_buffer(struct snd_line6_pcm *line6pcm)
{
kfree(line6pcm->buffer_out);
line6pcm->buffer_out = NULL;
}
/* /*
Callback for completed playback URB. Callback for completed playback URB.
*/ */
...@@ -459,16 +484,11 @@ static int snd_line6_playback_hw_params(struct snd_pcm_substream *substream, ...@@ -459,16 +484,11 @@ static int snd_line6_playback_hw_params(struct snd_pcm_substream *substream,
} }
/* -- [FD] end */ /* -- [FD] end */
/* We may be invoked multiple times in a row so allocate once only */ if ((line6pcm->flags & MASK_PLAYBACK) == 0) {
if (!line6pcm->buffer_out) ret = line6_alloc_playback_buffer(line6pcm);
line6pcm->buffer_out =
kmalloc(LINE6_ISO_BUFFERS * LINE6_ISO_PACKETS *
line6pcm->max_packet_size, GFP_KERNEL);
if (!line6pcm->buffer_out) { if (ret < 0)
dev_err(line6pcm->line6->ifcdev, return ret;
"cannot malloc playback buffer\n");
return -ENOMEM;
} }
ret = snd_pcm_lib_malloc_pages(substream, ret = snd_pcm_lib_malloc_pages(substream,
...@@ -485,9 +505,11 @@ static int snd_line6_playback_hw_free(struct snd_pcm_substream *substream) ...@@ -485,9 +505,11 @@ static int snd_line6_playback_hw_free(struct snd_pcm_substream *substream)
{ {
struct snd_line6_pcm *line6pcm = snd_pcm_substream_chip(substream); struct snd_line6_pcm *line6pcm = snd_pcm_substream_chip(substream);
line6_unlink_wait_clear_audio_out_urbs(line6pcm); if ((line6pcm->flags & MASK_PLAYBACK) == 0) {
kfree(line6pcm->buffer_out); line6_unlink_wait_clear_audio_out_urbs(line6pcm);
line6pcm->buffer_out = NULL; line6_free_playback_buffer(line6pcm);
}
return snd_pcm_lib_free_pages(substream); return snd_pcm_lib_free_pages(substream);
} }
......
...@@ -29,7 +29,9 @@ ...@@ -29,7 +29,9 @@
extern struct snd_pcm_ops snd_line6_playback_ops; extern struct snd_pcm_ops snd_line6_playback_ops;
extern int line6_alloc_playback_buffer(struct snd_line6_pcm *line6pcm);
extern int line6_create_audio_out_urbs(struct snd_line6_pcm *line6pcm); extern int line6_create_audio_out_urbs(struct snd_line6_pcm *line6pcm);
extern void line6_free_playback_buffer(struct snd_line6_pcm *line6pcm);
extern int line6_submit_audio_out_all_urbs(struct snd_line6_pcm *line6pcm); extern int line6_submit_audio_out_all_urbs(struct snd_line6_pcm *line6pcm);
extern void line6_unlink_audio_out_urbs(struct snd_line6_pcm *line6pcm); extern void line6_unlink_audio_out_urbs(struct snd_line6_pcm *line6pcm);
extern void line6_unlink_wait_clear_audio_out_urbs(struct snd_line6_pcm extern void line6_unlink_wait_clear_audio_out_urbs(struct snd_line6_pcm
......
#ifndef DRIVER_REVISION #ifndef DRIVER_REVISION
/* current subversion revision */ /* current subversion revision */
#define DRIVER_REVISION " (revision 690)" #define DRIVER_REVISION " (904)"
#endif #endif
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment