2009-02-28 03:43:04 +00:00
|
|
|
/*
|
2015-01-20 08:20:50 +00:00
|
|
|
* Line 6 Linux USB driver
|
2009-02-28 03:43:04 +00:00
|
|
|
*
|
2010-08-11 23:35:30 +00:00
|
|
|
* Copyright (C) 2004-2010 Markus Grabner (grabner@icg.tugraz.at)
|
2009-02-28 03:43:04 +00:00
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU General Public License as
|
|
|
|
* published by the Free Software Foundation, version 2.
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
include cleanup: Update gfp.h and slab.h includes to prepare for breaking implicit slab.h inclusion from percpu.h
percpu.h is included by sched.h and module.h and thus ends up being
included when building most .c files. percpu.h includes slab.h which
in turn includes gfp.h making everything defined by the two files
universally available and complicating inclusion dependencies.
percpu.h -> slab.h dependency is about to be removed. Prepare for
this change by updating users of gfp and slab facilities include those
headers directly instead of assuming availability. As this conversion
needs to touch large number of source files, the following script is
used as the basis of conversion.
http://userweb.kernel.org/~tj/misc/slabh-sweep.py
The script does the followings.
* Scan files for gfp and slab usages and update includes such that
only the necessary includes are there. ie. if only gfp is used,
gfp.h, if slab is used, slab.h.
* When the script inserts a new include, it looks at the include
blocks and try to put the new include such that its order conforms
to its surrounding. It's put in the include block which contains
core kernel includes, in the same order that the rest are ordered -
alphabetical, Christmas tree, rev-Xmas-tree or at the end if there
doesn't seem to be any matching order.
* If the script can't find a place to put a new include (mostly
because the file doesn't have fitting include block), it prints out
an error message indicating which .h file needs to be added to the
file.
The conversion was done in the following steps.
1. The initial automatic conversion of all .c files updated slightly
over 4000 files, deleting around 700 includes and adding ~480 gfp.h
and ~3000 slab.h inclusions. The script emitted errors for ~400
files.
2. Each error was manually checked. Some didn't need the inclusion,
some needed manual addition while adding it to implementation .h or
embedding .c file was more appropriate for others. This step added
inclusions to around 150 files.
3. The script was run again and the output was compared to the edits
from #2 to make sure no file was left behind.
4. Several build tests were done and a couple of problems were fixed.
e.g. lib/decompress_*.c used malloc/free() wrappers around slab
APIs requiring slab.h to be added manually.
5. The script was run on all .h files but without automatically
editing them as sprinkling gfp.h and slab.h inclusions around .h
files could easily lead to inclusion dependency hell. Most gfp.h
inclusion directives were ignored as stuff from gfp.h was usually
wildly available and often used in preprocessor macros. Each
slab.h inclusion directive was examined and added manually as
necessary.
6. percpu.h was updated not to include slab.h.
7. Build test were done on the following configurations and failures
were fixed. CONFIG_GCOV_KERNEL was turned off for all tests (as my
distributed build env didn't work with gcov compiles) and a few
more options had to be turned off depending on archs to make things
build (like ipr on powerpc/64 which failed due to missing writeq).
* x86 and x86_64 UP and SMP allmodconfig and a custom test config.
* powerpc and powerpc64 SMP allmodconfig
* sparc and sparc64 SMP allmodconfig
* ia64 SMP allmodconfig
* s390 SMP allmodconfig
* alpha SMP allmodconfig
* um on x86_64 SMP allmodconfig
8. percpu.h modifications were reverted so that it could be applied as
a separate patch and serve as bisection point.
Given the fact that I had only a couple of failures from tests on step
6, I'm fairly confident about the coverage of this conversion patch.
If there is a breakage, it's likely to be something in one of the arch
headers which should be easily discoverable easily on most builds of
the specific arch.
Signed-off-by: Tejun Heo <tj@kernel.org>
Guess-its-ok-by: Christoph Lameter <cl@linux-foundation.org>
Cc: Ingo Molnar <mingo@redhat.com>
Cc: Lee Schermerhorn <Lee.Schermerhorn@hp.com>
2010-03-24 08:04:11 +00:00
|
|
|
#include <linux/slab.h>
|
2015-01-15 07:22:31 +00:00
|
|
|
#include <linux/export.h>
|
2009-02-28 03:43:04 +00:00
|
|
|
#include <sound/core.h>
|
|
|
|
#include <sound/control.h>
|
|
|
|
#include <sound/pcm.h>
|
|
|
|
#include <sound/pcm_params.h>
|
|
|
|
|
|
|
|
#include "capture.h"
|
2010-08-11 23:35:30 +00:00
|
|
|
#include "driver.h"
|
2009-02-28 03:43:04 +00:00
|
|
|
#include "playback.h"
|
|
|
|
|
2015-01-19 13:28:25 +00:00
|
|
|
/* impulse response volume controls */
|
|
|
|
static int snd_line6_impulse_volume_info(struct snd_kcontrol *kcontrol,
|
|
|
|
struct snd_ctl_elem_info *uinfo)
|
2010-08-11 23:35:30 +00:00
|
|
|
{
|
2015-01-19 13:28:25 +00:00
|
|
|
uinfo->type = SNDRV_CTL_ELEM_TYPE_INTEGER;
|
|
|
|
uinfo->count = 1;
|
|
|
|
uinfo->value.integer.min = 0;
|
|
|
|
uinfo->value.integer.max = 255;
|
|
|
|
return 0;
|
2010-08-11 23:35:30 +00:00
|
|
|
}
|
|
|
|
|
2015-01-19 13:28:25 +00:00
|
|
|
static int snd_line6_impulse_volume_get(struct snd_kcontrol *kcontrol,
|
|
|
|
struct snd_ctl_elem_value *ucontrol)
|
2010-08-11 23:35:30 +00:00
|
|
|
{
|
2015-01-19 13:28:25 +00:00
|
|
|
struct snd_line6_pcm *line6pcm = snd_kcontrol_chip(kcontrol);
|
|
|
|
|
|
|
|
ucontrol->value.integer.value[0] = line6pcm->impulse_volume;
|
|
|
|
return 0;
|
2010-08-11 23:35:30 +00:00
|
|
|
}
|
|
|
|
|
2015-01-19 13:28:25 +00:00
|
|
|
static int snd_line6_impulse_volume_put(struct snd_kcontrol *kcontrol,
|
|
|
|
struct snd_ctl_elem_value *ucontrol)
|
2010-08-11 23:35:30 +00:00
|
|
|
{
|
2015-01-19 13:28:25 +00:00
|
|
|
struct snd_line6_pcm *line6pcm = snd_kcontrol_chip(kcontrol);
|
|
|
|
int value = ucontrol->value.integer.value[0];
|
2015-01-27 15:42:14 +00:00
|
|
|
int err;
|
2012-08-06 12:08:50 +00:00
|
|
|
|
2015-01-19 13:28:25 +00:00
|
|
|
if (line6pcm->impulse_volume == value)
|
|
|
|
return 0;
|
2012-08-06 12:08:50 +00:00
|
|
|
|
2010-08-11 23:35:30 +00:00
|
|
|
line6pcm->impulse_volume = value;
|
2015-01-27 15:42:14 +00:00
|
|
|
if (value > 0) {
|
|
|
|
err = line6_pcm_acquire(line6pcm, LINE6_STREAM_IMPULSE);
|
|
|
|
if (err < 0) {
|
|
|
|
line6pcm->impulse_volume = 0;
|
|
|
|
line6_pcm_release(line6pcm, LINE6_STREAM_IMPULSE);
|
|
|
|
return err;
|
|
|
|
}
|
|
|
|
} else {
|
2015-01-27 14:24:09 +00:00
|
|
|
line6_pcm_release(line6pcm, LINE6_STREAM_IMPULSE);
|
2015-01-27 15:42:14 +00:00
|
|
|
}
|
2015-01-19 13:28:25 +00:00
|
|
|
return 1;
|
|
|
|
}
|
2010-08-11 23:35:30 +00:00
|
|
|
|
2015-01-19 13:28:25 +00:00
|
|
|
/* impulse response period controls */
|
|
|
|
static int snd_line6_impulse_period_info(struct snd_kcontrol *kcontrol,
|
|
|
|
struct snd_ctl_elem_info *uinfo)
|
|
|
|
{
|
|
|
|
uinfo->type = SNDRV_CTL_ELEM_TYPE_INTEGER;
|
|
|
|
uinfo->count = 1;
|
|
|
|
uinfo->value.integer.min = 0;
|
|
|
|
uinfo->value.integer.max = 2000;
|
|
|
|
return 0;
|
2010-08-11 23:35:30 +00:00
|
|
|
}
|
|
|
|
|
2015-01-19 13:28:25 +00:00
|
|
|
static int snd_line6_impulse_period_get(struct snd_kcontrol *kcontrol,
|
|
|
|
struct snd_ctl_elem_value *ucontrol)
|
2010-08-11 23:35:30 +00:00
|
|
|
{
|
2015-01-19 13:28:25 +00:00
|
|
|
struct snd_line6_pcm *line6pcm = snd_kcontrol_chip(kcontrol);
|
|
|
|
|
|
|
|
ucontrol->value.integer.value[0] = line6pcm->impulse_period;
|
|
|
|
return 0;
|
2010-08-11 23:35:30 +00:00
|
|
|
}
|
|
|
|
|
2015-01-19 13:28:25 +00:00
|
|
|
static int snd_line6_impulse_period_put(struct snd_kcontrol *kcontrol,
|
|
|
|
struct snd_ctl_elem_value *ucontrol)
|
2010-08-11 23:35:30 +00:00
|
|
|
{
|
2015-01-19 13:28:25 +00:00
|
|
|
struct snd_line6_pcm *line6pcm = snd_kcontrol_chip(kcontrol);
|
|
|
|
int value = ucontrol->value.integer.value[0];
|
2012-11-30 10:57:32 +00:00
|
|
|
|
2015-01-19 13:28:25 +00:00
|
|
|
if (line6pcm->impulse_period == value)
|
|
|
|
return 0;
|
2012-11-30 10:57:32 +00:00
|
|
|
|
2015-01-19 13:28:25 +00:00
|
|
|
line6pcm->impulse_period = value;
|
|
|
|
return 1;
|
2010-08-11 23:35:30 +00:00
|
|
|
}
|
|
|
|
|
2015-01-23 15:18:42 +00:00
|
|
|
/*
|
|
|
|
Unlink all currently active URBs.
|
|
|
|
*/
|
|
|
|
static void line6_unlink_audio_urbs(struct snd_line6_pcm *line6pcm,
|
|
|
|
struct line6_pcm_stream *pcms)
|
|
|
|
{
|
|
|
|
int i;
|
|
|
|
|
|
|
|
for (i = 0; i < LINE6_ISO_BUFFERS; i++) {
|
|
|
|
if (test_bit(i, &pcms->active_urbs)) {
|
|
|
|
if (!test_and_set_bit(i, &pcms->unlink_urbs))
|
|
|
|
usb_unlink_urb(pcms->urbs[i]);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
Wait until unlinking of all currently active URBs has been finished.
|
|
|
|
*/
|
|
|
|
static void line6_wait_clear_audio_urbs(struct snd_line6_pcm *line6pcm,
|
|
|
|
struct line6_pcm_stream *pcms)
|
|
|
|
{
|
|
|
|
int timeout = HZ;
|
|
|
|
int i;
|
|
|
|
int alive;
|
|
|
|
|
|
|
|
do {
|
|
|
|
alive = 0;
|
|
|
|
for (i = 0; i < LINE6_ISO_BUFFERS; i++) {
|
|
|
|
if (test_bit(i, &pcms->active_urbs))
|
|
|
|
alive++;
|
|
|
|
}
|
|
|
|
if (!alive)
|
|
|
|
break;
|
|
|
|
set_current_state(TASK_UNINTERRUPTIBLE);
|
|
|
|
schedule_timeout(1);
|
|
|
|
} while (--timeout > 0);
|
|
|
|
if (alive)
|
2015-01-23 15:20:50 +00:00
|
|
|
dev_err(line6pcm->line6->ifcdev,
|
|
|
|
"timeout: still %d active urbs..\n", alive);
|
2015-01-23 15:18:42 +00:00
|
|
|
}
|
|
|
|
|
2015-01-27 14:24:09 +00:00
|
|
|
static inline struct line6_pcm_stream *
|
|
|
|
get_stream(struct snd_line6_pcm *line6pcm, int direction)
|
2015-01-23 15:25:03 +00:00
|
|
|
{
|
2015-01-27 14:24:09 +00:00
|
|
|
return (direction == SNDRV_PCM_STREAM_PLAYBACK) ?
|
|
|
|
&line6pcm->out : &line6pcm->in;
|
2015-01-23 15:25:03 +00:00
|
|
|
}
|
|
|
|
|
2015-01-27 14:24:09 +00:00
|
|
|
/* allocate a buffer if not opened yet;
|
|
|
|
* call this in line6pcm.state_change mutex
|
|
|
|
*/
|
|
|
|
static int line6_buffer_acquire(struct snd_line6_pcm *line6pcm,
|
|
|
|
struct line6_pcm_stream *pstr, int type)
|
2015-01-23 15:25:03 +00:00
|
|
|
{
|
2015-01-27 14:24:09 +00:00
|
|
|
/* Invoked multiple times in a row so allocate once only */
|
|
|
|
if (!test_and_set_bit(type, &pstr->opened) && !pstr->buffer) {
|
|
|
|
pstr->buffer = kmalloc(LINE6_ISO_BUFFERS * LINE6_ISO_PACKETS *
|
|
|
|
line6pcm->max_packet_size, GFP_KERNEL);
|
|
|
|
if (!pstr->buffer)
|
|
|
|
return -ENOMEM;
|
|
|
|
}
|
|
|
|
return 0;
|
2015-01-23 15:25:03 +00:00
|
|
|
}
|
|
|
|
|
2015-01-27 14:24:09 +00:00
|
|
|
/* free a buffer if all streams are closed;
|
|
|
|
* call this in line6pcm.state_change mutex
|
|
|
|
*/
|
|
|
|
static void line6_buffer_release(struct snd_line6_pcm *line6pcm,
|
|
|
|
struct line6_pcm_stream *pstr, int type)
|
2011-12-10 01:12:32 +00:00
|
|
|
{
|
2015-01-27 14:24:09 +00:00
|
|
|
|
|
|
|
clear_bit(type, &pstr->opened);
|
|
|
|
if (!pstr->opened) {
|
|
|
|
line6_wait_clear_audio_urbs(line6pcm, pstr);
|
|
|
|
kfree(pstr->buffer);
|
|
|
|
pstr->buffer = NULL;
|
|
|
|
}
|
2011-12-10 01:12:32 +00:00
|
|
|
}
|
|
|
|
|
2015-01-27 14:24:09 +00:00
|
|
|
/* start a PCM stream */
|
|
|
|
static int line6_stream_start(struct snd_line6_pcm *line6pcm, int direction,
|
|
|
|
int type)
|
2010-08-11 23:35:30 +00:00
|
|
|
{
|
2015-01-27 14:24:09 +00:00
|
|
|
unsigned long flags;
|
|
|
|
struct line6_pcm_stream *pstr = get_stream(line6pcm, direction);
|
|
|
|
int ret = 0;
|
|
|
|
|
|
|
|
spin_lock_irqsave(&pstr->lock, flags);
|
2015-07-14 13:19:37 +00:00
|
|
|
if (!test_and_set_bit(type, &pstr->running) &&
|
|
|
|
!(pstr->active_urbs || pstr->unlink_urbs)) {
|
2015-01-27 14:24:09 +00:00
|
|
|
pstr->count = 0;
|
|
|
|
/* Submit all currently available URBs */
|
|
|
|
if (direction == SNDRV_PCM_STREAM_PLAYBACK)
|
|
|
|
ret = line6_submit_audio_out_all_urbs(line6pcm);
|
|
|
|
else
|
|
|
|
ret = line6_submit_audio_in_all_urbs(line6pcm);
|
2012-01-19 23:09:09 +00:00
|
|
|
}
|
2015-01-27 14:24:09 +00:00
|
|
|
if (ret < 0)
|
|
|
|
clear_bit(type, &pstr->running);
|
|
|
|
spin_unlock_irqrestore(&pstr->lock, flags);
|
|
|
|
return ret;
|
|
|
|
}
|
2012-01-19 23:09:09 +00:00
|
|
|
|
2015-01-27 14:24:09 +00:00
|
|
|
/* stop a PCM stream; this doesn't sync with the unlinked URBs */
|
|
|
|
static void line6_stream_stop(struct snd_line6_pcm *line6pcm, int direction,
|
|
|
|
int type)
|
|
|
|
{
|
|
|
|
unsigned long flags;
|
|
|
|
struct line6_pcm_stream *pstr = get_stream(line6pcm, direction);
|
|
|
|
|
|
|
|
spin_lock_irqsave(&pstr->lock, flags);
|
|
|
|
clear_bit(type, &pstr->running);
|
|
|
|
if (!pstr->running) {
|
|
|
|
line6_unlink_audio_urbs(line6pcm, pstr);
|
|
|
|
if (direction == SNDRV_PCM_STREAM_CAPTURE) {
|
|
|
|
line6pcm->prev_fbuf = NULL;
|
|
|
|
line6pcm->prev_fsize = 0;
|
2011-12-10 01:12:32 +00:00
|
|
|
}
|
2015-01-27 14:24:09 +00:00
|
|
|
}
|
|
|
|
spin_unlock_irqrestore(&pstr->lock, flags);
|
|
|
|
}
|
2011-12-10 01:12:32 +00:00
|
|
|
|
2015-01-27 14:24:09 +00:00
|
|
|
/* common PCM trigger callback */
|
|
|
|
int snd_line6_trigger(struct snd_pcm_substream *substream, int cmd)
|
|
|
|
{
|
|
|
|
struct snd_line6_pcm *line6pcm = snd_pcm_substream_chip(substream);
|
|
|
|
struct snd_pcm_substream *s;
|
|
|
|
int err;
|
2010-08-22 23:08:25 +00:00
|
|
|
|
2015-01-27 14:24:09 +00:00
|
|
|
clear_bit(LINE6_FLAG_PREPARED, &line6pcm->flags);
|
2012-01-19 23:09:09 +00:00
|
|
|
|
2015-01-27 14:24:09 +00:00
|
|
|
snd_pcm_group_for_each_entry(s, substream) {
|
|
|
|
if (s->pcm->card != substream->pcm->card)
|
|
|
|
continue;
|
2010-08-22 23:08:25 +00:00
|
|
|
|
2015-01-27 14:24:09 +00:00
|
|
|
switch (cmd) {
|
|
|
|
case SNDRV_PCM_TRIGGER_START:
|
|
|
|
case SNDRV_PCM_TRIGGER_RESUME:
|
|
|
|
err = line6_stream_start(line6pcm, s->stream,
|
|
|
|
LINE6_STREAM_PCM);
|
|
|
|
if (err < 0)
|
|
|
|
return err;
|
|
|
|
break;
|
2011-12-10 01:12:32 +00:00
|
|
|
|
2015-01-27 14:24:09 +00:00
|
|
|
case SNDRV_PCM_TRIGGER_STOP:
|
|
|
|
case SNDRV_PCM_TRIGGER_SUSPEND:
|
|
|
|
line6_stream_stop(line6pcm, s->stream,
|
|
|
|
LINE6_STREAM_PCM);
|
|
|
|
break;
|
2011-12-10 01:12:32 +00:00
|
|
|
|
2015-01-27 14:24:09 +00:00
|
|
|
case SNDRV_PCM_TRIGGER_PAUSE_PUSH:
|
|
|
|
if (s->stream != SNDRV_PCM_STREAM_PLAYBACK)
|
|
|
|
return -EINVAL;
|
|
|
|
set_bit(LINE6_FLAG_PAUSE_PLAYBACK, &line6pcm->flags);
|
|
|
|
break;
|
2010-08-22 23:08:25 +00:00
|
|
|
|
2015-01-27 14:24:09 +00:00
|
|
|
case SNDRV_PCM_TRIGGER_PAUSE_RELEASE:
|
|
|
|
if (s->stream != SNDRV_PCM_STREAM_PLAYBACK)
|
|
|
|
return -EINVAL;
|
|
|
|
clear_bit(LINE6_FLAG_PAUSE_PLAYBACK, &line6pcm->flags);
|
|
|
|
break;
|
2012-01-19 23:09:09 +00:00
|
|
|
|
2015-01-27 14:24:09 +00:00
|
|
|
default:
|
|
|
|
return -EINVAL;
|
|
|
|
}
|
2010-08-11 23:35:30 +00:00
|
|
|
}
|
2010-08-22 23:08:25 +00:00
|
|
|
|
2010-08-11 23:35:30 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2015-01-27 14:41:27 +00:00
|
|
|
/* common PCM pointer callback */
|
|
|
|
snd_pcm_uframes_t snd_line6_pointer(struct snd_pcm_substream *substream)
|
|
|
|
{
|
|
|
|
struct snd_line6_pcm *line6pcm = snd_pcm_substream_chip(substream);
|
|
|
|
struct line6_pcm_stream *pstr = get_stream(line6pcm, substream->stream);
|
|
|
|
|
|
|
|
return pstr->pos_done;
|
|
|
|
}
|
|
|
|
|
2015-01-27 14:24:09 +00:00
|
|
|
/* Acquire and start duplex streams:
|
|
|
|
* type is either LINE6_STREAM_IMPULSE or LINE6_STREAM_MONITOR
|
|
|
|
*/
|
|
|
|
int line6_pcm_acquire(struct snd_line6_pcm *line6pcm, int type)
|
2010-08-11 23:35:30 +00:00
|
|
|
{
|
2015-01-27 14:24:09 +00:00
|
|
|
struct line6_pcm_stream *pstr;
|
|
|
|
int ret = 0, dir;
|
|
|
|
|
|
|
|
mutex_lock(&line6pcm->state_mutex);
|
|
|
|
for (dir = 0; dir < 2; dir++) {
|
|
|
|
pstr = get_stream(line6pcm, dir);
|
|
|
|
ret = line6_buffer_acquire(line6pcm, pstr, type);
|
|
|
|
if (ret < 0)
|
|
|
|
goto error;
|
|
|
|
if (!pstr->running)
|
|
|
|
line6_wait_clear_audio_urbs(line6pcm, pstr);
|
2015-01-27 15:17:26 +00:00
|
|
|
}
|
2015-01-27 14:24:09 +00:00
|
|
|
for (dir = 0; dir < 2; dir++) {
|
|
|
|
ret = line6_stream_start(line6pcm, dir, type);
|
|
|
|
if (ret < 0)
|
|
|
|
goto error;
|
2010-08-11 23:35:30 +00:00
|
|
|
}
|
2015-01-27 14:24:09 +00:00
|
|
|
error:
|
|
|
|
mutex_unlock(&line6pcm->state_mutex);
|
|
|
|
if (ret < 0)
|
|
|
|
line6_pcm_release(line6pcm, type);
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
EXPORT_SYMBOL_GPL(line6_pcm_acquire);
|
2010-08-11 23:35:30 +00:00
|
|
|
|
2015-01-27 14:24:09 +00:00
|
|
|
/* Stop and release duplex streams */
|
|
|
|
void line6_pcm_release(struct snd_line6_pcm *line6pcm, int type)
|
|
|
|
{
|
|
|
|
struct line6_pcm_stream *pstr;
|
|
|
|
int dir;
|
|
|
|
|
|
|
|
mutex_lock(&line6pcm->state_mutex);
|
|
|
|
for (dir = 0; dir < 2; dir++)
|
|
|
|
line6_stream_stop(line6pcm, dir, type);
|
|
|
|
for (dir = 0; dir < 2; dir++) {
|
|
|
|
pstr = get_stream(line6pcm, dir);
|
|
|
|
line6_buffer_release(line6pcm, pstr, type);
|
2010-08-11 23:35:30 +00:00
|
|
|
}
|
2015-01-27 14:24:09 +00:00
|
|
|
mutex_unlock(&line6pcm->state_mutex);
|
2010-08-11 23:35:30 +00:00
|
|
|
}
|
2015-01-15 07:22:31 +00:00
|
|
|
EXPORT_SYMBOL_GPL(line6_pcm_release);
|
2010-08-11 23:35:30 +00:00
|
|
|
|
2015-01-27 14:24:09 +00:00
|
|
|
/* common PCM hw_params callback */
|
|
|
|
int snd_line6_hw_params(struct snd_pcm_substream *substream,
|
|
|
|
struct snd_pcm_hw_params *hw_params)
|
2009-02-28 03:43:04 +00:00
|
|
|
{
|
2015-01-27 14:24:09 +00:00
|
|
|
int ret;
|
2009-02-28 03:43:04 +00:00
|
|
|
struct snd_line6_pcm *line6pcm = snd_pcm_substream_chip(substream);
|
2015-01-27 14:24:09 +00:00
|
|
|
struct line6_pcm_stream *pstr = get_stream(line6pcm, substream->stream);
|
|
|
|
|
|
|
|
mutex_lock(&line6pcm->state_mutex);
|
|
|
|
ret = line6_buffer_acquire(line6pcm, pstr, LINE6_STREAM_PCM);
|
|
|
|
if (ret < 0)
|
|
|
|
goto error;
|
|
|
|
|
|
|
|
ret = snd_pcm_lib_malloc_pages(substream,
|
|
|
|
params_buffer_bytes(hw_params));
|
|
|
|
if (ret < 0) {
|
|
|
|
line6_buffer_release(line6pcm, pstr, LINE6_STREAM_PCM);
|
|
|
|
goto error;
|
|
|
|
}
|
2009-02-28 03:43:04 +00:00
|
|
|
|
2015-01-27 14:24:09 +00:00
|
|
|
pstr->period = params_period_bytes(hw_params);
|
|
|
|
error:
|
|
|
|
mutex_unlock(&line6pcm->state_mutex);
|
|
|
|
return ret;
|
|
|
|
}
|
2009-02-28 03:43:04 +00:00
|
|
|
|
2015-01-27 14:24:09 +00:00
|
|
|
/* common PCM hw_free callback */
|
|
|
|
int snd_line6_hw_free(struct snd_pcm_substream *substream)
|
|
|
|
{
|
|
|
|
struct snd_line6_pcm *line6pcm = snd_pcm_substream_chip(substream);
|
|
|
|
struct line6_pcm_stream *pstr = get_stream(line6pcm, substream->stream);
|
2009-02-28 03:43:04 +00:00
|
|
|
|
2015-01-27 14:24:09 +00:00
|
|
|
mutex_lock(&line6pcm->state_mutex);
|
|
|
|
line6_buffer_release(line6pcm, pstr, LINE6_STREAM_PCM);
|
|
|
|
mutex_unlock(&line6pcm->state_mutex);
|
|
|
|
return snd_pcm_lib_free_pages(substream);
|
2009-02-28 03:43:04 +00:00
|
|
|
}
|
|
|
|
|
2015-01-27 14:24:09 +00:00
|
|
|
|
2009-02-28 03:43:04 +00:00
|
|
|
/* control info callback */
|
2010-08-11 23:35:30 +00:00
|
|
|
static int snd_line6_control_playback_info(struct snd_kcontrol *kcontrol,
|
|
|
|
struct snd_ctl_elem_info *uinfo)
|
2009-02-28 06:43:30 +00:00
|
|
|
{
|
2009-02-28 03:43:04 +00:00
|
|
|
uinfo->type = SNDRV_CTL_ELEM_TYPE_INTEGER;
|
|
|
|
uinfo->count = 2;
|
|
|
|
uinfo->value.integer.min = 0;
|
|
|
|
uinfo->value.integer.max = 256;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* control get callback */
|
2010-08-11 23:35:30 +00:00
|
|
|
static int snd_line6_control_playback_get(struct snd_kcontrol *kcontrol,
|
|
|
|
struct snd_ctl_elem_value *ucontrol)
|
2009-02-28 06:43:30 +00:00
|
|
|
{
|
2009-02-28 03:43:04 +00:00
|
|
|
int i;
|
|
|
|
struct snd_line6_pcm *line6pcm = snd_kcontrol_chip(kcontrol);
|
|
|
|
|
2015-01-23 14:08:40 +00:00
|
|
|
for (i = 0; i < 2; i++)
|
2010-08-11 23:35:30 +00:00
|
|
|
ucontrol->value.integer.value[i] = line6pcm->volume_playback[i];
|
2009-02-28 03:43:04 +00:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* control put callback */
|
2010-08-11 23:35:30 +00:00
|
|
|
static int snd_line6_control_playback_put(struct snd_kcontrol *kcontrol,
|
|
|
|
struct snd_ctl_elem_value *ucontrol)
|
2009-02-28 06:43:30 +00:00
|
|
|
{
|
2009-02-28 03:43:04 +00:00
|
|
|
int i, changed = 0;
|
|
|
|
struct snd_line6_pcm *line6pcm = snd_kcontrol_chip(kcontrol);
|
|
|
|
|
2015-01-23 14:08:40 +00:00
|
|
|
for (i = 0; i < 2; i++)
|
2010-08-22 23:08:25 +00:00
|
|
|
if (line6pcm->volume_playback[i] !=
|
|
|
|
ucontrol->value.integer.value[i]) {
|
|
|
|
line6pcm->volume_playback[i] =
|
|
|
|
ucontrol->value.integer.value[i];
|
2009-02-28 03:43:04 +00:00
|
|
|
changed = 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
return changed;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* control definition */
|
2015-01-19 13:28:25 +00:00
|
|
|
static struct snd_kcontrol_new line6_controls[] = {
|
|
|
|
{
|
|
|
|
.iface = SNDRV_CTL_ELEM_IFACE_MIXER,
|
|
|
|
.name = "PCM Playback Volume",
|
|
|
|
.info = snd_line6_control_playback_info,
|
|
|
|
.get = snd_line6_control_playback_get,
|
|
|
|
.put = snd_line6_control_playback_put
|
|
|
|
},
|
|
|
|
{
|
|
|
|
.iface = SNDRV_CTL_ELEM_IFACE_MIXER,
|
|
|
|
.name = "Impulse Response Volume",
|
|
|
|
.info = snd_line6_impulse_volume_info,
|
|
|
|
.get = snd_line6_impulse_volume_get,
|
|
|
|
.put = snd_line6_impulse_volume_put
|
|
|
|
},
|
|
|
|
{
|
|
|
|
.iface = SNDRV_CTL_ELEM_IFACE_MIXER,
|
|
|
|
.name = "Impulse Response Period",
|
|
|
|
.info = snd_line6_impulse_period_info,
|
|
|
|
.get = snd_line6_impulse_period_get,
|
|
|
|
.put = snd_line6_impulse_period_put
|
|
|
|
},
|
2009-02-28 03:43:04 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
/*
|
|
|
|
Cleanup the PCM device.
|
|
|
|
*/
|
2015-01-23 15:18:42 +00:00
|
|
|
static void cleanup_urbs(struct line6_pcm_stream *pcms)
|
2009-02-28 03:43:04 +00:00
|
|
|
{
|
|
|
|
int i;
|
|
|
|
|
2015-01-23 14:08:40 +00:00
|
|
|
for (i = 0; i < LINE6_ISO_BUFFERS; i++) {
|
2015-01-23 15:18:42 +00:00
|
|
|
if (pcms->urbs[i]) {
|
|
|
|
usb_kill_urb(pcms->urbs[i]);
|
|
|
|
usb_free_urb(pcms->urbs[i]);
|
2009-02-28 03:43:04 +00:00
|
|
|
}
|
|
|
|
}
|
2015-01-23 15:18:42 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void line6_cleanup_pcm(struct snd_pcm *pcm)
|
|
|
|
{
|
|
|
|
struct snd_line6_pcm *line6pcm = snd_pcm_chip(pcm);
|
|
|
|
|
|
|
|
cleanup_urbs(&line6pcm->out);
|
|
|
|
cleanup_urbs(&line6pcm->in);
|
2015-01-19 13:41:57 +00:00
|
|
|
kfree(line6pcm);
|
2009-02-28 03:43:04 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* create a PCM device */
|
2015-01-19 13:41:57 +00:00
|
|
|
static int snd_line6_new_pcm(struct usb_line6 *line6, struct snd_pcm **pcm_ret)
|
2009-02-28 03:43:04 +00:00
|
|
|
{
|
|
|
|
struct snd_pcm *pcm;
|
|
|
|
int err;
|
|
|
|
|
2015-01-19 13:41:57 +00:00
|
|
|
err = snd_pcm_new(line6->card, (char *)line6->properties->name,
|
|
|
|
0, 1, 1, pcm_ret);
|
2009-02-28 06:43:30 +00:00
|
|
|
if (err < 0)
|
2009-02-28 03:43:04 +00:00
|
|
|
return err;
|
2015-01-19 13:41:57 +00:00
|
|
|
pcm = *pcm_ret;
|
|
|
|
strcpy(pcm->name, line6->properties->name);
|
2009-02-28 03:43:04 +00:00
|
|
|
|
|
|
|
/* set operators */
|
2009-11-16 04:17:57 +00:00
|
|
|
snd_pcm_set_ops(pcm, SNDRV_PCM_STREAM_PLAYBACK,
|
|
|
|
&snd_line6_playback_ops);
|
2010-08-22 23:08:25 +00:00
|
|
|
snd_pcm_set_ops(pcm, SNDRV_PCM_STREAM_CAPTURE, &snd_line6_capture_ops);
|
2009-02-28 03:43:04 +00:00
|
|
|
|
|
|
|
/* pre-allocation of buffers */
|
2009-02-28 06:43:30 +00:00
|
|
|
snd_pcm_lib_preallocate_pages_for_all(pcm, SNDRV_DMA_TYPE_CONTINUOUS,
|
2010-08-22 23:08:25 +00:00
|
|
|
snd_dma_continuous_data
|
|
|
|
(GFP_KERNEL), 64 * 1024,
|
|
|
|
128 * 1024);
|
2009-02-28 03:43:04 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2010-08-11 23:35:30 +00:00
|
|
|
/*
|
2015-01-19 15:15:54 +00:00
|
|
|
Sync with PCM stream stops.
|
2010-08-11 23:35:30 +00:00
|
|
|
*/
|
|
|
|
void line6_pcm_disconnect(struct snd_line6_pcm *line6pcm)
|
|
|
|
{
|
2015-01-23 15:18:42 +00:00
|
|
|
line6_unlink_audio_urbs(line6pcm, &line6pcm->out);
|
|
|
|
line6_unlink_audio_urbs(line6pcm, &line6pcm->in);
|
|
|
|
line6_wait_clear_audio_urbs(line6pcm, &line6pcm->out);
|
|
|
|
line6_wait_clear_audio_urbs(line6pcm, &line6pcm->in);
|
2010-08-11 23:35:30 +00:00
|
|
|
}
|
|
|
|
|
2009-02-28 03:43:04 +00:00
|
|
|
/*
|
|
|
|
Create and register the PCM device and mixer entries.
|
|
|
|
Create URBs for playback and capture.
|
|
|
|
*/
|
2009-02-28 06:43:30 +00:00
|
|
|
int line6_init_pcm(struct usb_line6 *line6,
|
|
|
|
struct line6_pcm_properties *properties)
|
2009-02-28 03:43:04 +00:00
|
|
|
{
|
2015-01-19 13:28:25 +00:00
|
|
|
int i, err;
|
2015-01-12 20:42:55 +00:00
|
|
|
unsigned ep_read = line6->properties->ep_audio_r;
|
|
|
|
unsigned ep_write = line6->properties->ep_audio_w;
|
2015-01-19 13:41:57 +00:00
|
|
|
struct snd_pcm *pcm;
|
2009-02-28 03:43:04 +00:00
|
|
|
struct snd_line6_pcm *line6pcm;
|
|
|
|
|
2015-01-12 20:42:45 +00:00
|
|
|
if (!(line6->properties->capabilities & LINE6_CAP_PCM))
|
2010-08-22 23:08:25 +00:00
|
|
|
return 0; /* skip PCM initialization and report success */
|
2009-02-28 03:43:04 +00:00
|
|
|
|
2015-01-19 13:41:57 +00:00
|
|
|
err = snd_line6_new_pcm(line6, &pcm);
|
|
|
|
if (err < 0)
|
|
|
|
return err;
|
2009-02-28 03:43:04 +00:00
|
|
|
|
2015-01-19 13:41:57 +00:00
|
|
|
line6pcm = kzalloc(sizeof(*line6pcm), GFP_KERNEL);
|
|
|
|
if (!line6pcm)
|
2009-02-28 03:43:04 +00:00
|
|
|
return -ENOMEM;
|
|
|
|
|
2015-01-27 14:24:09 +00:00
|
|
|
mutex_init(&line6pcm->state_mutex);
|
2015-01-19 13:41:57 +00:00
|
|
|
line6pcm->pcm = pcm;
|
|
|
|
line6pcm->properties = properties;
|
2010-08-11 23:35:30 +00:00
|
|
|
line6pcm->volume_playback[0] = line6pcm->volume_playback[1] = 255;
|
|
|
|
line6pcm->volume_monitor = 255;
|
2009-02-28 03:43:04 +00:00
|
|
|
line6pcm->line6 = line6;
|
2011-11-23 08:20:44 +00:00
|
|
|
|
|
|
|
/* Read and write buffers are sized identically, so choose minimum */
|
|
|
|
line6pcm->max_packet_size = min(
|
|
|
|
usb_maxpacket(line6->usbdev,
|
|
|
|
usb_rcvisocpipe(line6->usbdev, ep_read), 0),
|
|
|
|
usb_maxpacket(line6->usbdev,
|
|
|
|
usb_sndisocpipe(line6->usbdev, ep_write), 1));
|
|
|
|
|
2015-01-23 15:10:57 +00:00
|
|
|
spin_lock_init(&line6pcm->out.lock);
|
|
|
|
spin_lock_init(&line6pcm->in.lock);
|
2015-01-19 13:28:25 +00:00
|
|
|
line6pcm->impulse_period = LINE6_IMPULSE_DEFAULT_PERIOD;
|
2009-02-28 03:43:04 +00:00
|
|
|
|
2015-01-19 13:41:57 +00:00
|
|
|
line6->line6pcm = line6pcm;
|
|
|
|
|
|
|
|
pcm->private_data = line6pcm;
|
|
|
|
pcm->private_free = line6_cleanup_pcm;
|
|
|
|
|
2010-08-11 23:35:30 +00:00
|
|
|
err = line6_create_audio_out_urbs(line6pcm);
|
2009-02-28 06:43:30 +00:00
|
|
|
if (err < 0)
|
2009-02-28 03:43:04 +00:00
|
|
|
return err;
|
|
|
|
|
2010-08-11 23:35:30 +00:00
|
|
|
err = line6_create_audio_in_urbs(line6pcm);
|
2009-02-28 06:43:30 +00:00
|
|
|
if (err < 0)
|
2009-02-28 03:43:04 +00:00
|
|
|
return err;
|
|
|
|
|
|
|
|
/* mixer: */
|
2015-01-19 13:28:25 +00:00
|
|
|
for (i = 0; i < ARRAY_SIZE(line6_controls); i++) {
|
|
|
|
err = snd_ctl_add(line6->card,
|
|
|
|
snd_ctl_new1(&line6_controls[i], line6pcm));
|
|
|
|
if (err < 0)
|
|
|
|
return err;
|
|
|
|
}
|
2010-08-11 23:35:30 +00:00
|
|
|
|
2009-02-28 03:43:04 +00:00
|
|
|
return 0;
|
|
|
|
}
|
2015-01-15 07:22:31 +00:00
|
|
|
EXPORT_SYMBOL_GPL(line6_init_pcm);
|
2009-02-28 03:43:04 +00:00
|
|
|
|
|
|
|
/* prepare pcm callback */
|
|
|
|
int snd_line6_prepare(struct snd_pcm_substream *substream)
|
|
|
|
{
|
|
|
|
struct snd_line6_pcm *line6pcm = snd_pcm_substream_chip(substream);
|
2015-01-27 14:24:09 +00:00
|
|
|
struct line6_pcm_stream *pstr = get_stream(line6pcm, substream->stream);
|
2009-02-28 03:43:04 +00:00
|
|
|
|
2015-01-27 14:24:09 +00:00
|
|
|
mutex_lock(&line6pcm->state_mutex);
|
|
|
|
if (!pstr->running)
|
|
|
|
line6_wait_clear_audio_urbs(line6pcm, pstr);
|
2011-12-10 01:12:31 +00:00
|
|
|
|
2015-01-27 14:24:09 +00:00
|
|
|
if (!test_and_set_bit(LINE6_FLAG_PREPARED, &line6pcm->flags)) {
|
2015-01-23 15:10:57 +00:00
|
|
|
line6pcm->out.count = 0;
|
|
|
|
line6pcm->out.pos = 0;
|
|
|
|
line6pcm->out.pos_done = 0;
|
|
|
|
line6pcm->out.bytes = 0;
|
|
|
|
line6pcm->in.count = 0;
|
|
|
|
line6pcm->in.pos_done = 0;
|
|
|
|
line6pcm->in.bytes = 0;
|
2009-02-28 03:43:04 +00:00
|
|
|
}
|
|
|
|
|
2015-01-27 14:24:09 +00:00
|
|
|
mutex_unlock(&line6pcm->state_mutex);
|
2009-02-28 03:43:04 +00:00
|
|
|
return 0;
|
|
|
|
}
|