2009-02-28 03:43:04 +00:00
|
|
|
/*
|
|
|
|
* Line6 Linux USB driver - 0.8.0
|
|
|
|
*
|
|
|
|
* Copyright (C) 2004-2009 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
|
|
|
|
* published by the Free Software Foundation, version 2.
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "driver.h"
|
|
|
|
|
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>
|
|
|
|
|
2009-02-28 03:43:04 +00:00
|
|
|
#include <sound/core.h>
|
|
|
|
#include <sound/pcm.h>
|
|
|
|
#include <sound/pcm_params.h>
|
|
|
|
|
|
|
|
#include "audio.h"
|
|
|
|
#include "pcm.h"
|
|
|
|
#include "pod.h"
|
2009-02-28 04:45:03 +00:00
|
|
|
#include "playback.h"
|
2009-02-28 03:43:04 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
Software stereo volume control.
|
|
|
|
*/
|
2009-02-28 06:41:12 +00:00
|
|
|
static void change_volume(struct urb *urb_out, int volume[],
|
|
|
|
int bytes_per_frame)
|
2009-02-28 03:43:04 +00:00
|
|
|
{
|
|
|
|
int chn = 0;
|
|
|
|
|
2009-02-28 06:41:12 +00:00
|
|
|
if (volume[0] == 256 && volume[1] == 256)
|
2009-11-16 04:17:50 +00:00
|
|
|
return; /* maximum volume - no change */
|
2009-02-28 03:43:04 +00:00
|
|
|
|
2009-02-28 06:41:12 +00:00
|
|
|
if (bytes_per_frame == 4) {
|
2009-02-28 03:43:04 +00:00
|
|
|
short *p, *buf_end;
|
|
|
|
p = (short *)urb_out->transfer_buffer;
|
|
|
|
buf_end = p + urb_out->transfer_buffer_length / sizeof(*p);
|
|
|
|
|
2009-02-28 06:41:12 +00:00
|
|
|
for (; p < buf_end; ++p) {
|
2009-02-28 03:43:04 +00:00
|
|
|
*p = (*p * volume[chn & 1]) >> 8;
|
|
|
|
++chn;
|
|
|
|
}
|
2009-02-28 06:41:12 +00:00
|
|
|
} else if (bytes_per_frame == 6) {
|
2009-02-28 03:43:04 +00:00
|
|
|
unsigned char *p, *buf_end;
|
|
|
|
p = (unsigned char *)urb_out->transfer_buffer;
|
|
|
|
buf_end = p + urb_out->transfer_buffer_length;
|
|
|
|
|
2009-02-28 06:41:12 +00:00
|
|
|
for (; p < buf_end; p += 3) {
|
|
|
|
int val;
|
|
|
|
val = p[0] + (p[1] << 8) + ((signed char)p[2] << 16);
|
2009-02-28 03:43:04 +00:00
|
|
|
val = (val * volume[chn & 1]) >> 8;
|
|
|
|
p[0] = val;
|
|
|
|
p[1] = val >> 8;
|
|
|
|
p[2] = val >> 16;
|
|
|
|
++chn;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
Find a free URB, prepare audio data, and submit URB.
|
|
|
|
*/
|
|
|
|
static int submit_audio_out_urb(struct snd_pcm_substream *substream)
|
|
|
|
{
|
|
|
|
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;
|
2009-11-16 04:17:50 +00:00
|
|
|
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);
|
2009-02-28 03:43:04 +00:00
|
|
|
struct snd_pcm_runtime *runtime = substream->runtime;
|
|
|
|
struct urb *urb_out;
|
|
|
|
|
|
|
|
spin_lock_irqsave(&line6pcm->lock_audio_out, flags);
|
2009-11-16 04:17:50 +00:00
|
|
|
index =
|
|
|
|
find_first_zero_bit(&line6pcm->active_urb_out, LINE6_ISO_BUFFERS);
|
2009-02-28 03:43:04 +00:00
|
|
|
|
2009-02-28 06:41:12 +00:00
|
|
|
if (index < 0 || index >= LINE6_ISO_BUFFERS) {
|
2009-02-28 03:43:04 +00:00
|
|
|
spin_unlock_irqrestore(&line6pcm->lock_audio_out, flags);
|
|
|
|
dev_err(s2m(substream), "no free URB found\n");
|
|
|
|
return -EINVAL;
|
|
|
|
}
|
|
|
|
|
|
|
|
urb_out = line6pcm->urb_audio_out[index];
|
|
|
|
urb_size = 0;
|
|
|
|
|
2009-02-28 06:41:12 +00:00
|
|
|
for (i = 0; i < LINE6_ISO_PACKETS; ++i) {
|
2009-02-28 03:43:04 +00:00
|
|
|
/* compute frame size for given sampling rate */
|
|
|
|
int n, fs;
|
2009-11-16 04:17:50 +00:00
|
|
|
struct usb_iso_packet_descriptor *fout =
|
|
|
|
&urb_out->iso_frame_desc[i];
|
2009-02-28 03:43:04 +00:00
|
|
|
line6pcm->count_out += frame_increment;
|
|
|
|
n = line6pcm->count_out / frame_factor;
|
|
|
|
line6pcm->count_out -= n * frame_factor;
|
|
|
|
fs = n * bytes_per_frame;
|
|
|
|
fout->offset = urb_size;
|
|
|
|
fout->length = fs;
|
|
|
|
urb_size += fs;
|
|
|
|
}
|
|
|
|
|
|
|
|
urb_frames = urb_size / bytes_per_frame;
|
|
|
|
|
2009-02-28 06:41:12 +00:00
|
|
|
if (test_bit(BIT_PAUSE_PLAYBACK, &line6pcm->flags)) {
|
2009-02-28 03:43:04 +00:00
|
|
|
urb_out->transfer_buffer = line6pcm->wrap_out;
|
|
|
|
memset(line6pcm->wrap_out, 0, urb_size);
|
2009-02-28 06:41:12 +00:00
|
|
|
} else {
|
|
|
|
if (line6pcm->pos_out + urb_frames > runtime->buffer_size) {
|
2009-02-28 03:43:04 +00:00
|
|
|
/*
|
2009-11-16 04:17:50 +00:00
|
|
|
The transferred area goes over buffer boundary,
|
|
|
|
copy the data to the temp buffer.
|
|
|
|
*/
|
2009-02-28 03:43:04 +00:00
|
|
|
int len;
|
|
|
|
len = runtime->buffer_size - line6pcm->pos_out;
|
|
|
|
urb_out->transfer_buffer = line6pcm->wrap_out;
|
|
|
|
|
2009-02-28 06:41:12 +00:00
|
|
|
if (len > 0) {
|
2009-11-16 04:17:50 +00:00
|
|
|
memcpy(line6pcm->wrap_out,
|
|
|
|
runtime->dma_area +
|
|
|
|
line6pcm->pos_out * bytes_per_frame,
|
|
|
|
len * bytes_per_frame);
|
|
|
|
memcpy(line6pcm->wrap_out +
|
|
|
|
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);
|
|
|
|
}
|
2009-02-28 06:41:12 +00:00
|
|
|
} else {
|
2009-02-28 03:43:04 +00:00
|
|
|
/* set the buffer pointer */
|
2009-11-16 04:17:50 +00:00
|
|
|
urb_out->transfer_buffer =
|
|
|
|
runtime->dma_area +
|
|
|
|
line6pcm->pos_out * bytes_per_frame;
|
2009-02-28 03:43:04 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-11-16 04:17:51 +00:00
|
|
|
line6pcm->pos_out += urb_frames;
|
|
|
|
if (line6pcm->pos_out >= runtime->buffer_size)
|
2009-02-28 03:43:04 +00:00
|
|
|
line6pcm->pos_out -= runtime->buffer_size;
|
|
|
|
|
|
|
|
urb_out->transfer_buffer_length = urb_size;
|
|
|
|
urb_out->context = substream;
|
|
|
|
change_volume(urb_out, line6pcm->volume, bytes_per_frame);
|
|
|
|
|
|
|
|
#if DO_DUMP_PCM_SEND
|
2009-02-28 06:41:12 +00:00
|
|
|
for (i = 0; i < LINE6_ISO_PACKETS; ++i) {
|
2009-11-16 04:17:50 +00:00
|
|
|
struct usb_iso_packet_descriptor *fout =
|
|
|
|
&urb_out->iso_frame_desc[i];
|
|
|
|
line6_write_hexdump(line6pcm->line6, 'P',
|
|
|
|
urb_out->transfer_buffer + fout->offset,
|
|
|
|
fout->length);
|
2009-02-28 03:43:04 +00:00
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2009-02-28 06:41:12 +00:00
|
|
|
if (usb_submit_urb(urb_out, GFP_ATOMIC) == 0)
|
2009-02-28 03:43:04 +00:00
|
|
|
set_bit(index, &line6pcm->active_urb_out);
|
|
|
|
else
|
2009-11-16 04:17:50 +00:00
|
|
|
dev_err(s2m(substream), "URB out #%d submission failed\n",
|
|
|
|
index);
|
2009-02-28 03:43:04 +00:00
|
|
|
|
|
|
|
spin_unlock_irqrestore(&line6pcm->lock_audio_out, flags);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
Submit all currently available playback URBs.
|
|
|
|
*/
|
|
|
|
static int submit_audio_out_all_urbs(struct snd_pcm_substream *substream)
|
|
|
|
{
|
|
|
|
int ret, i;
|
|
|
|
|
2009-02-28 06:41:12 +00:00
|
|
|
for (i = 0; i < LINE6_ISO_BUFFERS; ++i) {
|
|
|
|
ret = submit_audio_out_urb(substream);
|
|
|
|
if (ret < 0)
|
2009-02-28 03:43:04 +00:00
|
|
|
return ret;
|
2009-02-28 06:41:12 +00:00
|
|
|
}
|
2009-02-28 03:43:04 +00:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
Unlink all currently active playback URBs.
|
|
|
|
*/
|
|
|
|
static void unlink_audio_out_urbs(struct snd_line6_pcm *line6pcm)
|
|
|
|
{
|
|
|
|
unsigned int i;
|
|
|
|
|
2009-02-28 06:41:12 +00:00
|
|
|
for (i = LINE6_ISO_BUFFERS; i--;) {
|
|
|
|
if (test_bit(i, &line6pcm->active_urb_out)) {
|
|
|
|
if (!test_and_set_bit(i, &line6pcm->unlink_urb_out)) {
|
2009-02-28 03:43:04 +00:00
|
|
|
struct urb *u = line6pcm->urb_audio_out[i];
|
|
|
|
usb_unlink_urb(u);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
2009-11-16 04:17:50 +00:00
|
|
|
Wait until unlinking of all currently active playback URBs has been finished.
|
2009-02-28 03:43:04 +00:00
|
|
|
*/
|
|
|
|
static void wait_clear_audio_out_urbs(struct snd_line6_pcm *line6pcm)
|
|
|
|
{
|
|
|
|
int timeout = HZ;
|
|
|
|
unsigned int i;
|
|
|
|
int alive;
|
|
|
|
|
|
|
|
do {
|
|
|
|
alive = 0;
|
|
|
|
for (i = LINE6_ISO_BUFFERS; i--;) {
|
|
|
|
if (test_bit(i, &line6pcm->active_urb_out))
|
|
|
|
alive++;
|
|
|
|
}
|
2009-02-28 06:41:12 +00:00
|
|
|
if (!alive)
|
2009-02-28 03:43:04 +00:00
|
|
|
break;
|
|
|
|
set_current_state(TASK_UNINTERRUPTIBLE);
|
|
|
|
schedule_timeout(1);
|
|
|
|
} 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)
|
|
|
|
{
|
|
|
|
unlink_audio_out_urbs(line6pcm);
|
|
|
|
wait_clear_audio_out_urbs(line6pcm);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
Callback for completed playback URB.
|
|
|
|
*/
|
2009-02-28 04:28:04 +00:00
|
|
|
static void audio_out_callback(struct urb *urb)
|
2009-02-28 03:43:04 +00:00
|
|
|
{
|
|
|
|
int i, index, length = 0, shutdown = 0;
|
|
|
|
unsigned long flags;
|
|
|
|
|
2009-11-16 04:17:50 +00:00
|
|
|
struct snd_pcm_substream *substream =
|
|
|
|
(struct snd_pcm_substream *)urb->context;
|
2009-02-28 03:43:04 +00:00
|
|
|
struct snd_line6_pcm *line6pcm = snd_pcm_substream_chip(substream);
|
|
|
|
struct snd_pcm_runtime *runtime = substream->runtime;
|
|
|
|
|
|
|
|
/* find index of URB */
|
2009-02-28 06:41:12 +00:00
|
|
|
for (index = LINE6_ISO_BUFFERS; index--;)
|
|
|
|
if (urb == line6pcm->urb_audio_out[index])
|
2009-02-28 03:43:04 +00:00
|
|
|
break;
|
|
|
|
|
2009-02-28 06:41:12 +00:00
|
|
|
if (index < 0)
|
2009-11-16 04:17:50 +00:00
|
|
|
return; /* URB has been unlinked asynchronously */
|
2009-02-28 03:43:04 +00:00
|
|
|
|
2009-02-28 06:41:12 +00:00
|
|
|
for (i = LINE6_ISO_PACKETS; i--;)
|
2009-02-28 03:43:04 +00:00
|
|
|
length += urb->iso_frame_desc[i].length;
|
|
|
|
|
|
|
|
spin_lock_irqsave(&line6pcm->lock_audio_out, flags);
|
2009-11-16 04:17:50 +00:00
|
|
|
line6pcm->pos_out_done +=
|
|
|
|
length / line6pcm->properties->bytes_per_frame;
|
2009-02-28 03:43:04 +00:00
|
|
|
|
2009-02-28 06:41:12 +00:00
|
|
|
if (line6pcm->pos_out_done >= runtime->buffer_size)
|
2009-02-28 03:43:04 +00:00
|
|
|
line6pcm->pos_out_done -= runtime->buffer_size;
|
|
|
|
|
|
|
|
clear_bit(index, &line6pcm->active_urb_out);
|
|
|
|
|
2009-02-28 06:41:12 +00:00
|
|
|
for (i = LINE6_ISO_PACKETS; i--;)
|
|
|
|
if (urb->iso_frame_desc[i].status == -ESHUTDOWN) {
|
2009-02-28 03:43:04 +00:00
|
|
|
shutdown = 1;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2009-02-28 06:41:12 +00:00
|
|
|
if (test_bit(index, &line6pcm->unlink_urb_out))
|
2009-02-28 03:43:04 +00:00
|
|
|
shutdown = 1;
|
|
|
|
|
|
|
|
spin_unlock_irqrestore(&line6pcm->lock_audio_out, flags);
|
|
|
|
|
2009-02-28 06:41:12 +00:00
|
|
|
if (!shutdown) {
|
2009-02-28 03:43:04 +00:00
|
|
|
submit_audio_out_urb(substream);
|
|
|
|
|
2009-11-16 04:17:51 +00:00
|
|
|
line6pcm->bytes_out += length;
|
|
|
|
if (line6pcm->bytes_out >= line6pcm->period_out) {
|
2009-02-28 03:43:04 +00:00
|
|
|
line6pcm->bytes_out -= line6pcm->period_out;
|
|
|
|
snd_pcm_period_elapsed(substream);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* open playback callback */
|
|
|
|
static int snd_line6_playback_open(struct snd_pcm_substream *substream)
|
|
|
|
{
|
|
|
|
int err;
|
|
|
|
struct snd_pcm_runtime *runtime = substream->runtime;
|
|
|
|
struct snd_line6_pcm *line6pcm = snd_pcm_substream_chip(substream);
|
|
|
|
|
2009-02-28 06:41:12 +00:00
|
|
|
err = snd_pcm_hw_constraint_ratdens(runtime, 0, SNDRV_PCM_HW_PARAM_RATE,
|
2009-11-16 04:17:50 +00:00
|
|
|
(&line6pcm->properties->
|
|
|
|
snd_line6_rates));
|
2009-02-28 06:41:12 +00:00
|
|
|
if (err < 0)
|
2009-02-28 03:43:04 +00:00
|
|
|
return err;
|
|
|
|
|
|
|
|
runtime->hw = line6pcm->properties->snd_line6_playback_hw;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* close playback callback */
|
|
|
|
static int snd_line6_playback_close(struct snd_pcm_substream *substream)
|
|
|
|
{
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* hw_params playback callback */
|
2009-11-16 04:17:50 +00:00
|
|
|
static int snd_line6_playback_hw_params(struct snd_pcm_substream *substream,
|
|
|
|
struct snd_pcm_hw_params *hw_params)
|
2009-02-28 03:43:04 +00:00
|
|
|
{
|
|
|
|
int ret;
|
|
|
|
struct snd_line6_pcm *line6pcm = snd_pcm_substream_chip(substream);
|
|
|
|
|
|
|
|
/* -- Florian Demski [FD] */
|
|
|
|
/* don't ask me why, but this fixes the bug on my machine */
|
2009-02-28 06:41:12 +00:00
|
|
|
if (line6pcm == NULL) {
|
|
|
|
if (substream->pcm == NULL)
|
2009-02-28 03:43:04 +00:00
|
|
|
return -ENOMEM;
|
2009-02-28 06:41:12 +00:00
|
|
|
if (substream->pcm->private_data == NULL)
|
2009-02-28 03:43:04 +00:00
|
|
|
return -ENOMEM;
|
|
|
|
substream->private_data = substream->pcm->private_data;
|
2009-02-28 06:41:12 +00:00
|
|
|
line6pcm = snd_pcm_substream_chip(substream);
|
2009-02-28 03:43:04 +00:00
|
|
|
}
|
|
|
|
/* -- [FD] end */
|
|
|
|
|
2009-02-28 06:41:12 +00:00
|
|
|
ret = snd_pcm_lib_malloc_pages(substream,
|
|
|
|
params_buffer_bytes(hw_params));
|
|
|
|
if (ret < 0)
|
2009-02-28 03:43:04 +00:00
|
|
|
return ret;
|
|
|
|
|
|
|
|
line6pcm->period_out = params_period_bytes(hw_params);
|
|
|
|
line6pcm->wrap_out = kmalloc(2 * LINE6_ISO_PACKET_SIZE_MAX, GFP_KERNEL);
|
|
|
|
|
2009-02-28 06:41:12 +00:00
|
|
|
if (!line6pcm->wrap_out) {
|
2009-02-28 03:43:04 +00:00
|
|
|
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);
|
|
|
|
|
2009-02-28 06:41:12 +00:00
|
|
|
kfree(line6pcm->wrap_out);
|
|
|
|
line6pcm->wrap_out = NULL;
|
2009-02-28 03:43:04 +00:00
|
|
|
|
|
|
|
return snd_pcm_lib_free_pages(substream);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* trigger playback callback */
|
|
|
|
int snd_line6_playback_trigger(struct snd_pcm_substream *substream, int cmd)
|
|
|
|
{
|
|
|
|
struct snd_line6_pcm *line6pcm = snd_pcm_substream_chip(substream);
|
|
|
|
int err;
|
|
|
|
line6pcm->count_out = 0;
|
|
|
|
|
2009-02-28 06:41:12 +00:00
|
|
|
switch (cmd) {
|
2009-02-28 03:43:04 +00:00
|
|
|
case SNDRV_PCM_TRIGGER_START:
|
2009-02-28 06:41:12 +00:00
|
|
|
if (!test_and_set_bit(BIT_RUNNING_PLAYBACK, &line6pcm->flags)) {
|
2009-02-28 03:43:04 +00:00
|
|
|
err = submit_audio_out_all_urbs(substream);
|
|
|
|
|
2009-02-28 06:41:12 +00:00
|
|
|
if (err < 0) {
|
2009-11-16 04:17:50 +00:00
|
|
|
clear_bit(BIT_RUNNING_PLAYBACK,
|
|
|
|
&line6pcm->flags);
|
2009-02-28 03:43:04 +00:00
|
|
|
return err;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
case SNDRV_PCM_TRIGGER_STOP:
|
2009-02-28 06:41:12 +00:00
|
|
|
if (test_and_clear_bit(BIT_RUNNING_PLAYBACK, &line6pcm->flags))
|
2009-02-28 03:43:04 +00:00
|
|
|
unlink_audio_out_urbs(line6pcm);
|
|
|
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
case SNDRV_PCM_TRIGGER_PAUSE_PUSH:
|
|
|
|
set_bit(BIT_PAUSE_PLAYBACK, &line6pcm->flags);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case SNDRV_PCM_TRIGGER_PAUSE_RELEASE:
|
|
|
|
clear_bit(BIT_PAUSE_PLAYBACK, &line6pcm->flags);
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
return -EINVAL;
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* playback pointer callback */
|
|
|
|
static snd_pcm_uframes_t
|
|
|
|
snd_line6_playback_pointer(struct snd_pcm_substream *substream)
|
|
|
|
{
|
|
|
|
struct snd_line6_pcm *line6pcm = snd_pcm_substream_chip(substream);
|
|
|
|
return line6pcm->pos_out_done;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* playback operators */
|
|
|
|
struct snd_pcm_ops snd_line6_playback_ops = {
|
2009-11-16 04:17:50 +00:00
|
|
|
.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,
|
2009-02-28 03:43:04 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
int create_audio_out_urbs(struct snd_line6_pcm *line6pcm)
|
|
|
|
{
|
|
|
|
int i;
|
|
|
|
|
|
|
|
/* create audio URBs and fill in constant values: */
|
2009-02-28 06:41:12 +00:00
|
|
|
for (i = 0; i < LINE6_ISO_BUFFERS; ++i) {
|
2009-02-28 03:43:04 +00:00
|
|
|
struct urb *urb;
|
|
|
|
|
|
|
|
/* URB for audio out: */
|
2009-11-16 04:17:50 +00:00
|
|
|
urb = line6pcm->urb_audio_out[i] =
|
|
|
|
usb_alloc_urb(LINE6_ISO_PACKETS, GFP_KERNEL);
|
2009-02-28 03:43:04 +00:00
|
|
|
|
2009-02-28 06:41:12 +00:00
|
|
|
if (urb == NULL) {
|
2009-02-28 03:43:04 +00:00
|
|
|
dev_err(line6pcm->line6->ifcdev, "Out of memory\n");
|
|
|
|
return -ENOMEM;
|
|
|
|
}
|
|
|
|
|
|
|
|
urb->dev = line6pcm->line6->usbdev;
|
2009-11-16 04:17:50 +00:00
|
|
|
urb->pipe =
|
|
|
|
usb_sndisocpipe(line6pcm->line6->usbdev,
|
|
|
|
line6pcm->
|
|
|
|
ep_audio_write & USB_ENDPOINT_NUMBER_MASK);
|
2009-02-28 03:43:04 +00:00
|
|
|
urb->transfer_flags = URB_ISO_ASAP;
|
|
|
|
urb->start_frame = -1;
|
|
|
|
urb->number_of_packets = LINE6_ISO_PACKETS;
|
|
|
|
urb->interval = LINE6_ISO_INTERVAL;
|
|
|
|
urb->error_count = 0;
|
|
|
|
urb->complete = audio_out_callback;
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|