aboutsummaryrefslogtreecommitdiffstats
path: root/sound/usb
diff options
context:
space:
mode:
Diffstat (limited to 'sound/usb')
-rw-r--r--sound/usb/caiaq/audio.c1
-rw-r--r--sound/usb/card.h2
-rw-r--r--sound/usb/endpoint.c13
-rw-r--r--sound/usb/format.c4
-rw-r--r--sound/usb/line6/Kconfig5
-rw-r--r--sound/usb/line6/capture.c50
-rw-r--r--sound/usb/line6/driver.c269
-rw-r--r--sound/usb/line6/driver.h59
-rw-r--r--sound/usb/line6/midi.c2
-rw-r--r--sound/usb/line6/pcm.c83
-rw-r--r--sound/usb/line6/pcm.h20
-rw-r--r--sound/usb/line6/playback.c37
-rw-r--r--sound/usb/line6/pod.c12
-rw-r--r--sound/usb/line6/podhd.c300
-rw-r--r--sound/usb/line6/toneport.c6
-rw-r--r--sound/usb/line6/variax.c6
-rw-r--r--sound/usb/mixer_quirks.c22
-rw-r--r--sound/usb/quirks.c6
18 files changed, 733 insertions, 164 deletions
diff --git a/sound/usb/caiaq/audio.c b/sound/usb/caiaq/audio.c
index 327f8642ca80..8f66ba730d69 100644
--- a/sound/usb/caiaq/audio.c
+++ b/sound/usb/caiaq/audio.c
@@ -739,7 +739,6 @@ static struct urb **alloc_urbs(struct snd_usb_caiaqdev *cdev, int dir, int *ret)
for (i = 0; i < N_URBS; i++) {
urbs[i] = usb_alloc_urb(FRAMES_PER_URB, GFP_KERNEL);
if (!urbs[i]) {
- dev_err(dev, "unable to usb_alloc_urb(), OOM!?\n");
*ret = -ENOMEM;
return urbs;
}
diff --git a/sound/usb/card.h b/sound/usb/card.h
index 71778ca4b26a..111b0f009afa 100644
--- a/sound/usb/card.h
+++ b/sound/usb/card.h
@@ -92,7 +92,7 @@ struct snd_usb_endpoint {
unsigned int curframesize; /* current packet size in frames (for capture) */
unsigned int syncmaxsize; /* sync endpoint packet size */
unsigned int fill_max:1; /* fill max packet size always */
- unsigned int udh01_fb_quirk:1; /* corrupted feedback data */
+ unsigned int tenor_fb_quirk:1; /* corrupted feedback data */
unsigned int datainterval; /* log_2 of data packet interval */
unsigned int syncinterval; /* P for adaptive mode, 0 otherwise */
unsigned char silence_value;
diff --git a/sound/usb/endpoint.c b/sound/usb/endpoint.c
index c07a7eda42a2..c470251cea4b 100644
--- a/sound/usb/endpoint.c
+++ b/sound/usb/endpoint.c
@@ -502,10 +502,6 @@ struct snd_usb_endpoint *snd_usb_add_endpoint(struct snd_usb_audio *chip,
ep->syncinterval = 3;
ep->syncmaxsize = le16_to_cpu(get_endpoint(alts, 1)->wMaxPacketSize);
-
- if (chip->usb_id == USB_ID(0x0644, 0x8038) /* TEAC UD-H01 */ &&
- ep->syncmaxsize == 4)
- ep->udh01_fb_quirk = 1;
}
list_add_tail(&ep->list, &chip->ep_list);
@@ -1171,15 +1167,16 @@ void snd_usb_handle_sync_urb(struct snd_usb_endpoint *ep,
if (f == 0)
return;
- if (unlikely(sender->udh01_fb_quirk)) {
+ if (unlikely(sender->tenor_fb_quirk)) {
/*
- * The TEAC UD-H01 firmware sometimes changes the feedback value
+ * Devices based on Tenor 8802 chipsets (TEAC UD-H01
+ * and others) sometimes change the feedback value
* by +/- 0x1.0000.
*/
if (f < ep->freqn - 0x8000)
- f += 0x10000;
+ f += 0xf000;
else if (f > ep->freqn + 0x8000)
- f -= 0x10000;
+ f -= 0xf000;
} else if (unlikely(ep->freqshift == INT_MIN)) {
/*
* The first time we see a feedback value, determine its format
diff --git a/sound/usb/format.c b/sound/usb/format.c
index 789d19ec035d..2c44386e5569 100644
--- a/sound/usb/format.c
+++ b/sound/usb/format.c
@@ -176,10 +176,8 @@ static int parse_audio_format_rates_v1(struct snd_usb_audio *chip, struct audiof
int r, idx;
fp->rate_table = kmalloc(sizeof(int) * nr_rates, GFP_KERNEL);
- if (fp->rate_table == NULL) {
- usb_audio_err(chip, "cannot malloc\n");
+ if (fp->rate_table == NULL)
return -ENOMEM;
- }
fp->nr_rates = 0;
fp->rate_min = fp->rate_max = 0;
diff --git a/sound/usb/line6/Kconfig b/sound/usb/line6/Kconfig
index f4585d378ef3..39b400392d71 100644
--- a/sound/usb/line6/Kconfig
+++ b/sound/usb/line6/Kconfig
@@ -2,6 +2,7 @@ config SND_USB_LINE6
tristate
select SND_RAWMIDI
select SND_PCM
+ select SND_HWDEP
config SND_USB_POD
tristate "Line 6 POD USB support"
@@ -21,10 +22,10 @@ config SND_USB_POD
re-amping)
config SND_USB_PODHD
- tristate "Line 6 POD HD300/400/500 USB support"
+ tristate "Line 6 POD X3/HD300/400/500 USB support"
select SND_USB_LINE6
help
- This is a driver for POD HD300, 400 and 500 devices.
+ This is a driver for POD X3, HD300, 400 and 500 devices.
config SND_USB_TONEPORT
tristate "TonePort GX, UX1 and UX2 USB support"
diff --git a/sound/usb/line6/capture.c b/sound/usb/line6/capture.c
index f518fbbe88de..7c812565f90d 100644
--- a/sound/usb/line6/capture.c
+++ b/sound/usb/line6/capture.c
@@ -29,10 +29,10 @@ static int submit_audio_in_urb(struct snd_line6_pcm *line6pcm)
int ret;
struct urb *urb_in;
- index =
- find_first_zero_bit(&line6pcm->in.active_urbs, LINE6_ISO_BUFFERS);
+ index = find_first_zero_bit(&line6pcm->in.active_urbs,
+ line6pcm->line6->iso_buffers);
- if (index < 0 || index >= LINE6_ISO_BUFFERS) {
+ if (index < 0 || index >= line6pcm->line6->iso_buffers) {
dev_err(line6pcm->line6->ifcdev, "no free URB found\n");
return -EINVAL;
}
@@ -44,13 +44,13 @@ static int submit_audio_in_urb(struct snd_line6_pcm *line6pcm)
struct usb_iso_packet_descriptor *fin =
&urb_in->iso_frame_desc[i];
fin->offset = urb_size;
- fin->length = line6pcm->max_packet_size;
- urb_size += line6pcm->max_packet_size;
+ fin->length = line6pcm->max_packet_size_in;
+ urb_size += line6pcm->max_packet_size_in;
}
urb_in->transfer_buffer =
line6pcm->in.buffer +
- index * LINE6_ISO_PACKETS * line6pcm->max_packet_size;
+ index * LINE6_ISO_PACKETS * line6pcm->max_packet_size_in;
urb_in->transfer_buffer_length = urb_size;
urb_in->context = line6pcm;
@@ -73,7 +73,7 @@ int line6_submit_audio_in_all_urbs(struct snd_line6_pcm *line6pcm)
{
int ret = 0, i;
- for (i = 0; i < LINE6_ISO_BUFFERS; ++i) {
+ for (i = 0; i < line6pcm->line6->iso_buffers; ++i) {
ret = submit_audio_in_urb(line6pcm);
if (ret < 0)
break;
@@ -90,7 +90,9 @@ void line6_capture_copy(struct snd_line6_pcm *line6pcm, char *fbuf, int fsize)
struct snd_pcm_substream *substream =
get_substream(line6pcm, SNDRV_PCM_STREAM_CAPTURE);
struct snd_pcm_runtime *runtime = substream->runtime;
- const int bytes_per_frame = line6pcm->properties->bytes_per_frame;
+ const int bytes_per_frame =
+ line6pcm->properties->bytes_per_channel *
+ line6pcm->properties->capture_hw.channels_max;
int frames = fsize / bytes_per_frame;
if (runtime == NULL)
@@ -154,7 +156,7 @@ static void audio_in_callback(struct urb *urb)
line6pcm->in.last_frame = urb->start_frame;
/* find index of URB */
- for (index = 0; index < LINE6_ISO_BUFFERS; ++index)
+ for (index = 0; index < line6pcm->line6->iso_buffers; ++index)
if (urb == line6pcm->in.urbs[index])
break;
@@ -173,17 +175,27 @@ static void audio_in_callback(struct urb *urb)
fbuf = urb->transfer_buffer + fin->offset;
fsize = fin->actual_length;
- if (fsize > line6pcm->max_packet_size) {
+ if (fsize > line6pcm->max_packet_size_in) {
dev_err(line6pcm->line6->ifcdev,
"driver and/or device bug: packet too large (%d > %d)\n",
- fsize, line6pcm->max_packet_size);
+ fsize, line6pcm->max_packet_size_in);
}
length += fsize;
- /* the following assumes LINE6_ISO_PACKETS == 1: */
+ BUILD_BUG_ON_MSG(LINE6_ISO_PACKETS != 1,
+ "The following code assumes LINE6_ISO_PACKETS == 1");
+ /* TODO:
+ * Also, if iso_buffers != 2, the prev frame is almost random at
+ * playback side.
+ * This needs to be redesigned. It should be "stable", but we may
+ * experience sync problems on such high-speed configs.
+ */
+
line6pcm->prev_fbuf = fbuf;
- line6pcm->prev_fsize = fsize;
+ line6pcm->prev_fsize = fsize /
+ (line6pcm->properties->bytes_per_channel *
+ line6pcm->properties->capture_hw.channels_max);
if (!test_bit(LINE6_STREAM_IMPULSE, &line6pcm->in.running) &&
test_bit(LINE6_STREAM_PCM, &line6pcm->in.running) &&
@@ -220,6 +232,8 @@ static int snd_line6_capture_open(struct snd_pcm_substream *substream)
if (err < 0)
return err;
+ line6_pcm_acquire(line6pcm, LINE6_STREAM_CAPTURE_HELPER, false);
+
runtime->hw = line6pcm->properties->capture_hw;
return 0;
}
@@ -227,6 +241,9 @@ static int snd_line6_capture_open(struct snd_pcm_substream *substream)
/* close capture callback */
static int snd_line6_capture_close(struct snd_pcm_substream *substream)
{
+ struct snd_line6_pcm *line6pcm = snd_pcm_substream_chip(substream);
+
+ line6_pcm_release(line6pcm, LINE6_STREAM_CAPTURE_HELPER);
return 0;
}
@@ -247,8 +264,13 @@ int line6_create_audio_in_urbs(struct snd_line6_pcm *line6pcm)
struct usb_line6 *line6 = line6pcm->line6;
int i;
+ line6pcm->in.urbs = kzalloc(
+ sizeof(struct urb *) * line6->iso_buffers, GFP_KERNEL);
+ if (line6pcm->in.urbs == NULL)
+ return -ENOMEM;
+
/* create audio URBs and fill in constant values: */
- for (i = 0; i < LINE6_ISO_BUFFERS; ++i) {
+ for (i = 0; i < line6->iso_buffers; ++i) {
struct urb *urb;
/* URB for audio in: */
diff --git a/sound/usb/line6/driver.c b/sound/usb/line6/driver.c
index 81b7da8e56d3..14e587e70655 100644
--- a/sound/usb/line6/driver.c
+++ b/sound/usb/line6/driver.c
@@ -17,6 +17,7 @@
#include <sound/core.h>
#include <sound/initval.h>
+#include <sound/hwdep.h>
#include "capture.h"
#include "driver.h"
@@ -29,7 +30,7 @@
/*
This is Line 6's MIDI manufacturer ID.
*/
-const unsigned char line6_midi_id[] = {
+const unsigned char line6_midi_id[3] = {
0x00, 0x01, 0x0c
};
EXPORT_SYMBOL_GPL(line6_midi_id);
@@ -66,10 +67,17 @@ static int line6_start_listen(struct usb_line6 *line6)
{
int err;
- usb_fill_int_urb(line6->urb_listen, line6->usbdev,
- usb_rcvintpipe(line6->usbdev, line6->properties->ep_ctrl_r),
- line6->buffer_listen, LINE6_BUFSIZE_LISTEN,
- line6_data_received, line6, line6->interval);
+ if (line6->properties->capabilities & LINE6_CAP_CONTROL_MIDI) {
+ usb_fill_int_urb(line6->urb_listen, line6->usbdev,
+ usb_rcvintpipe(line6->usbdev, line6->properties->ep_ctrl_r),
+ line6->buffer_listen, LINE6_BUFSIZE_LISTEN,
+ line6_data_received, line6, line6->interval);
+ } else {
+ usb_fill_bulk_urb(line6->urb_listen, line6->usbdev,
+ usb_rcvbulkpipe(line6->usbdev, line6->properties->ep_ctrl_r),
+ line6->buffer_listen, LINE6_BUFSIZE_LISTEN,
+ line6_data_received, line6);
+ }
line6->urb_listen->actual_length = 0;
err = usb_submit_urb(line6->urb_listen, GFP_ATOMIC);
return err;
@@ -90,6 +98,7 @@ static int line6_send_raw_message(struct usb_line6 *line6, const char *buffer,
int size)
{
int i, done = 0;
+ const struct line6_properties *properties = line6->properties;
for (i = 0; i < size; i += line6->max_packet_size) {
int partial;
@@ -97,15 +106,21 @@ static int line6_send_raw_message(struct usb_line6 *line6, const char *buffer,
int frag_size = min(line6->max_packet_size, size - i);
int retval;
- retval = usb_interrupt_msg(line6->usbdev,
- usb_sndintpipe(line6->usbdev,
- line6->properties->ep_ctrl_w),
- (char *)frag_buf, frag_size,
- &partial, LINE6_TIMEOUT * HZ);
+ if (properties->capabilities & LINE6_CAP_CONTROL_MIDI) {
+ retval = usb_interrupt_msg(line6->usbdev,
+ usb_sndintpipe(line6->usbdev, properties->ep_ctrl_w),
+ (char *)frag_buf, frag_size,
+ &partial, LINE6_TIMEOUT * HZ);
+ } else {
+ retval = usb_bulk_msg(line6->usbdev,
+ usb_sndbulkpipe(line6->usbdev, properties->ep_ctrl_w),
+ (char *)frag_buf, frag_size,
+ &partial, LINE6_TIMEOUT * HZ);
+ }
if (retval) {
dev_err(line6->ifcdev,
- "usb_interrupt_msg failed (%d)\n", retval);
+ "usb_bulk_msg failed (%d)\n", retval);
break;
}
@@ -140,10 +155,17 @@ static int line6_send_raw_message_async_part(struct message *msg,
int done = msg->done;
int bytes = min(msg->size - done, line6->max_packet_size);
- usb_fill_int_urb(urb, line6->usbdev,
- usb_sndintpipe(line6->usbdev, line6->properties->ep_ctrl_w),
- (char *)msg->buffer + done, bytes,
- line6_async_request_sent, msg, line6->interval);
+ if (line6->properties->capabilities & LINE6_CAP_CONTROL_MIDI) {
+ usb_fill_int_urb(urb, line6->usbdev,
+ usb_sndintpipe(line6->usbdev, line6->properties->ep_ctrl_w),
+ (char *)msg->buffer + done, bytes,
+ line6_async_request_sent, msg, line6->interval);
+ } else {
+ usb_fill_bulk_urb(urb, line6->usbdev,
+ usb_sndbulkpipe(line6->usbdev, line6->properties->ep_ctrl_w),
+ (char *)msg->buffer + done, bytes,
+ line6_async_request_sent, msg);
+ }
msg->done += bytes;
retval = usb_submit_urb(urb, GFP_ATOMIC);
@@ -269,28 +291,36 @@ static void line6_data_received(struct urb *urb)
if (urb->status == -ESHUTDOWN)
return;
- done =
- line6_midibuf_write(mb, urb->transfer_buffer, urb->actual_length);
+ if (line6->properties->capabilities & LINE6_CAP_CONTROL_MIDI) {
+ done =
+ line6_midibuf_write(mb, urb->transfer_buffer, urb->actual_length);
- if (done < urb->actual_length) {
- line6_midibuf_ignore(mb, done);
- dev_dbg(line6->ifcdev, "%d %d buffer overflow - message skipped\n",
- done, urb->actual_length);
- }
+ if (done < urb->actual_length) {
+ line6_midibuf_ignore(mb, done);
+ dev_dbg(line6->ifcdev, "%d %d buffer overflow - message skipped\n",
+ done, urb->actual_length);
+ }
- for (;;) {
- done =
- line6_midibuf_read(mb, line6->buffer_message,
- LINE6_MESSAGE_MAXLEN);
+ for (;;) {
+ done =
+ line6_midibuf_read(mb, line6->buffer_message,
+ LINE6_MIDI_MESSAGE_MAXLEN);
- if (done == 0)
- break;
+ if (done == 0)
+ break;
- line6->message_length = done;
- line6_midi_receive(line6, line6->buffer_message, done);
+ line6->message_length = done;
+ line6_midi_receive(line6, line6->buffer_message, done);
+ if (line6->process_message)
+ line6->process_message(line6);
+ }
+ } else {
+ line6->buffer_message = urb->transfer_buffer;
+ line6->message_length = urb->actual_length;
if (line6->process_message)
line6->process_message(line6);
+ line6->buffer_message = NULL;
}
line6_start_listen(line6);
@@ -447,12 +477,16 @@ static void line6_destruct(struct snd_card *card)
struct usb_line6 *line6 = card->private_data;
struct usb_device *usbdev = line6->usbdev;
- /* free buffer memory first: */
+ /* Free buffer memory first. We cannot depend on the existence of private
+ * data from the (podhd) module, it may be gone already during this call
+ */
kfree(line6->buffer_message);
+
kfree(line6->buffer_listen);
/* then free URBs: */
usb_free_urb(line6->urb_listen);
+ line6->urb_listen = NULL;
/* decrement reference counters: */
usb_put_dev(usbdev);
@@ -462,13 +496,29 @@ static void line6_destruct(struct snd_card *card)
static void line6_get_interval(struct usb_line6 *line6)
{
struct usb_device *usbdev = line6->usbdev;
+ const struct line6_properties *properties = line6->properties;
+ int pipe;
struct usb_host_endpoint *ep;
- unsigned pipe = usb_rcvintpipe(usbdev, line6->properties->ep_ctrl_r);
- unsigned epnum = usb_pipeendpoint(pipe);
- ep = usbdev->ep_in[epnum];
+ if (properties->capabilities & LINE6_CAP_CONTROL_MIDI) {
+ pipe =
+ usb_rcvintpipe(line6->usbdev, line6->properties->ep_ctrl_r);
+ } else {
+ pipe =
+ usb_rcvbulkpipe(line6->usbdev, line6->properties->ep_ctrl_r);
+ }
+ ep = usbdev->ep_in[usb_pipeendpoint(pipe)];
+
if (ep) {
line6->interval = ep->desc.bInterval;
+ if (usbdev->speed == USB_SPEED_LOW) {
+ line6->intervals_per_second = USB_LOW_INTERVALS_PER_SECOND;
+ line6->iso_buffers = USB_LOW_ISO_BUFFERS;
+ } else {
+ line6->intervals_per_second = USB_HIGH_INTERVALS_PER_SECOND;
+ line6->iso_buffers = USB_HIGH_ISO_BUFFERS;
+ }
+
line6->max_packet_size = le16_to_cpu(ep->desc.wMaxPacketSize);
} else {
dev_err(line6->ifcdev,
@@ -478,6 +528,138 @@ static void line6_get_interval(struct usb_line6 *line6)
}
}
+
+/* Enable buffering of incoming messages, flush the buffer */
+static int line6_hwdep_open(struct snd_hwdep *hw, struct file *file)
+{
+ struct usb_line6 *line6 = hw->private_data;
+
+ /* NOTE: hwdep layer provides atomicity here */
+
+ line6->messages.active = 1;
+
+ return 0;
+}
+
+/* Stop buffering */
+static int line6_hwdep_release(struct snd_hwdep *hw, struct file *file)
+{
+ struct usb_line6 *line6 = hw->private_data;
+
+ line6->messages.active = 0;
+
+ return 0;
+}
+
+/* Read from circular buffer, return to user */
+static long
+line6_hwdep_read(struct snd_hwdep *hwdep, char __user *buf, long count,
+ loff_t *offset)
+{
+ struct usb_line6 *line6 = hwdep->private_data;
+ long rv = 0;
+ unsigned int out_count;
+
+ if (mutex_lock_interruptible(&line6->messages.read_lock))
+ return -ERESTARTSYS;
+
+ while (kfifo_len(&line6->messages.fifo) == 0) {
+ mutex_unlock(&line6->messages.read_lock);
+
+ rv = wait_event_interruptible(
+ line6->messages.wait_queue,
+ kfifo_len(&line6->messages.fifo) != 0);
+ if (rv < 0)
+ return rv;
+
+ if (mutex_lock_interruptible(&line6->messages.read_lock))
+ return -ERESTARTSYS;
+ }
+
+ if (kfifo_peek_len(&line6->messages.fifo) > count) {
+ /* Buffer too small; allow re-read of the current item... */
+ rv = -EINVAL;
+ } else {
+ rv = kfifo_to_user(&line6->messages.fifo, buf, count, &out_count);
+ if (rv == 0)
+ rv = out_count;
+ }
+
+ mutex_unlock(&line6->messages.read_lock);
+ return rv;
+}
+
+/* Write directly (no buffering) to device by user*/
+static long
+line6_hwdep_write(struct snd_hwdep *hwdep, const char __user *data, long count,
+ loff_t *offset)
+{
+ struct usb_line6 *line6 = hwdep->private_data;
+ int rv;
+ char *data_copy;
+
+ if (count > line6->max_packet_size * LINE6_RAW_MESSAGES_MAXCOUNT) {
+ /* This is an arbitrary limit - still better than nothing... */
+ return -EINVAL;
+ }
+
+ data_copy = memdup_user(data, count);
+ if (IS_ERR(ERR_PTR))
+ return -ENOMEM;
+
+ rv = line6_send_raw_message(line6, data_copy, count);
+
+ kfree(data_copy);
+ return rv;
+}
+
+static const struct snd_hwdep_ops hwdep_ops = {
+ .open = line6_hwdep_open,
+ .release = line6_hwdep_release,
+ .read = line6_hwdep_read,
+ .write = line6_hwdep_write,
+};
+
+/* Insert into circular buffer */
+static void line6_hwdep_push_message(struct usb_line6 *line6)
+{
+ if (!line6->messages.active)
+ return;
+
+ if (kfifo_avail(&line6->messages.fifo) >= line6->message_length) {
+ /* No race condition here, there's only one writer */
+ kfifo_in(&line6->messages.fifo,
+ line6->buffer_message, line6->message_length);
+ } /* else TODO: signal overflow */
+
+ wake_up_interruptible(&line6->messages.wait_queue);
+}
+
+static int line6_hwdep_init(struct usb_line6 *line6)
+{
+ int err;
+ struct snd_hwdep *hwdep;
+
+ /* TODO: usb_driver_claim_interface(); */
+ line6->process_message = line6_hwdep_push_message;
+ line6->messages.active = 0;
+ init_waitqueue_head(&line6->messages.wait_queue);
+ mutex_init(&line6->messages.read_lock);
+ INIT_KFIFO(line6->messages.fifo);
+
+ err = snd_hwdep_new(line6->card, "config", 0, &hwdep);
+ if (err < 0)
+ goto end;
+ strcpy(hwdep->name, "config");
+ hwdep->iface = SNDRV_HWDEP_IFACE_LINE6;
+ hwdep->ops = hwdep_ops;
+ hwdep->private_data = line6;
+ hwdep->exclusive = true;
+
+end:
+ return err;
+}
+
static int line6_init_cap_control(struct usb_line6 *line6)
{
int ret;
@@ -487,14 +669,20 @@ static int line6_init_cap_control(struct usb_line6 *line6)
if (!line6->buffer_listen)
return -ENOMEM;
- line6->buffer_message = kmalloc(LINE6_MESSAGE_MAXLEN, GFP_KERNEL);
- if (!line6->buffer_message)
- return -ENOMEM;
-
line6->urb_listen = usb_alloc_urb(0, GFP_KERNEL);
if (!line6->urb_listen)
return -ENOMEM;
+ if (line6->properties->capabilities & LINE6_CAP_CONTROL_MIDI) {
+ line6->buffer_message = kmalloc(LINE6_MIDI_MESSAGE_MAXLEN, GFP_KERNEL);
+ if (!line6->buffer_message)
+ return -ENOMEM;
+ } else {
+ ret = line6_hwdep_init(line6);
+ if (ret < 0)
+ return ret;
+ }
+
ret = line6_start_listen(line6);
if (ret < 0) {
dev_err(line6->ifcdev, "cannot start listening: %d\n", ret);
@@ -558,6 +746,7 @@ int line6_probe(struct usb_interface *interface,
/* query interface number */
interface_number = interface->cur_altsetting->desc.bInterfaceNumber;
+ /* TODO reserves the bus bandwidth even without actual transfer */
ret = usb_set_interface(usbdev, interface_number,
properties->altsetting);
if (ret < 0) {
@@ -565,9 +754,8 @@ int line6_probe(struct usb_interface *interface,
goto error;
}
- line6_get_interval(line6);
-
if (properties->capabilities & LINE6_CAP_CONTROL) {
+ line6_get_interval(line6);
ret = line6_init_cap_control(line6);
if (ret < 0)
goto error;
@@ -670,3 +858,4 @@ EXPORT_SYMBOL_GPL(line6_resume);
MODULE_AUTHOR(DRIVER_AUTHOR);
MODULE_DESCRIPTION(DRIVER_DESC);
MODULE_LICENSE("GPL");
+
diff --git a/sound/usb/line6/driver.h b/sound/usb/line6/driver.h
index 7da643e79e3b..7e3a3aada222 100644
--- a/sound/usb/line6/driver.h
+++ b/sound/usb/line6/driver.h
@@ -12,21 +12,37 @@
#ifndef DRIVER_H
#define DRIVER_H
-#include <linux/spinlock.h>
#include <linux/usb.h>
+#include <linux/mutex.h>
+#include <linux/kfifo.h>
#include <sound/core.h>
#include "midi.h"
-#define USB_INTERVALS_PER_SECOND 1000
+/* USB 1.1 speed configuration */
+#define USB_LOW_INTERVALS_PER_SECOND 1000
+#define USB_LOW_ISO_BUFFERS 2
+
+/* USB 2.0+ speed configuration */
+#define USB_HIGH_INTERVALS_PER_SECOND 8000
+#define USB_HIGH_ISO_BUFFERS 16
/* Fallback USB interval and max packet size values */
#define LINE6_FALLBACK_INTERVAL 10
#define LINE6_FALLBACK_MAXPACKETSIZE 16
#define LINE6_TIMEOUT 1
-#define LINE6_BUFSIZE_LISTEN 32
-#define LINE6_MESSAGE_MAXLEN 256
+#define LINE6_BUFSIZE_LISTEN 64
+#define LINE6_MIDI_MESSAGE_MAXLEN 256
+
+#define LINE6_RAW_MESSAGES_MAXCOUNT_ORDER 7
+/* 4k packets are common, BUFSIZE * MAXCOUNT should be bigger... */
+#define LINE6_RAW_MESSAGES_MAXCOUNT (1 << LINE6_RAW_MESSAGES_MAXCOUNT_ORDER)
+
+
+#if LINE6_BUFSIZE_LISTEN > 65535
+#error "Use dynamic fifo instead"
+#endif
/*
Line 6 MIDI control commands
@@ -94,8 +110,12 @@ enum {
LINE6_CAP_CONTROL = 1 << 0,
/* device supports PCM input/output via USB */
LINE6_CAP_PCM = 1 << 1,
- /* device support hardware monitoring */
+ /* device supports hardware monitoring */
LINE6_CAP_HWMON = 1 << 2,
+ /* device requires output data when input is read */
+ LINE6_CAP_IN_NEEDS_OUT = 1 << 3,
+ /* device uses raw MIDI via USB (data endpoints) */
+ LINE6_CAP_CONTROL_MIDI = 1 << 4,
};
/*
@@ -109,10 +129,15 @@ struct usb_line6 {
/* Properties */
const struct line6_properties *properties;
- /* Interval (ms) */
+ /* Interval for data USB packets */
int interval;
+ /* ...for isochronous transfers framing */
+ int intervals_per_second;
+
+ /* Number of isochronous URBs used for frame transfers */
+ int iso_buffers;
- /* Maximum size of USB packet */
+ /* Maximum size of data USB packet */
int max_packet_size;
/* Device representing the USB interface */
@@ -129,18 +154,30 @@ struct usb_line6 {
/* Line 6 MIDI device data structure */
struct snd_line6_midi *line6midi;
- /* URB for listening to PODxt Pro control endpoint */
+ /* URB for listening to POD data endpoint */
struct urb *urb_listen;
- /* Buffer for listening to PODxt Pro control endpoint */
+ /* Buffer for incoming data from POD data endpoint */
unsigned char *buffer_listen;
- /* Buffer for message to be processed */
+ /* Buffer for message to be processed, generated from MIDI layer */
unsigned char *buffer_message;
- /* Length of message to be processed */
+ /* Length of message to be processed, generated from MIDI layer */
int message_length;
+ /* Circular buffer for non-MIDI control messages */
+ struct {
+ struct mutex read_lock;
+ wait_queue_head_t wait_queue;
+ unsigned int active:1;
+ STRUCT_KFIFO_REC_2(LINE6_BUFSIZE_LISTEN * LINE6_RAW_MESSAGES_MAXCOUNT)
+ fifo;
+ } messages;
+
+ /* If MIDI is supported, buffer_message contains the pre-processed data;
+ * otherwise the data is only in urb_listen (buffer_incoming).
+ */
void (*process_message)(struct usb_line6 *);
void (*disconnect)(struct usb_line6 *line6);
};
diff --git a/sound/usb/line6/midi.c b/sound/usb/line6/midi.c
index cebea9b7f769..d0fb2f205bd9 100644
--- a/sound/usb/line6/midi.c
+++ b/sound/usb/line6/midi.c
@@ -258,7 +258,7 @@ int line6_init_midi(struct usb_line6 *line6)
struct snd_rawmidi *rmidi;
struct snd_line6_midi *line6midi;
- if (!(line6->properties->capabilities & LINE6_CAP_CONTROL)) {
+ if (!(line6->properties->capabilities & LINE6_CAP_CONTROL_MIDI)) {
/* skip MIDI initialization and report success */
return 0;
}
diff --git a/sound/usb/line6/pcm.c b/sound/usb/line6/pcm.c
index 41aa3355e920..fab53f58d447 100644
--- a/sound/usb/line6/pcm.c
+++ b/sound/usb/line6/pcm.c
@@ -52,7 +52,7 @@ static int snd_line6_impulse_volume_put(struct snd_kcontrol *kcontrol,
line6pcm->impulse_volume = value;
if (value > 0) {
- err = line6_pcm_acquire(line6pcm, LINE6_STREAM_IMPULSE);
+ err = line6_pcm_acquire(line6pcm, LINE6_STREAM_IMPULSE, true);
if (err < 0) {
line6pcm->impulse_volume = 0;
return err;
@@ -104,7 +104,7 @@ static void line6_unlink_audio_urbs(struct snd_line6_pcm *line6pcm,
{
int i;
- for (i = 0; i < LINE6_ISO_BUFFERS; i++) {
+ for (i = 0; i < line6pcm->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]);
@@ -124,7 +124,7 @@ static void line6_wait_clear_audio_urbs(struct snd_line6_pcm *line6pcm,
do {
alive = 0;
- for (i = 0; i < LINE6_ISO_BUFFERS; i++) {
+ for (i = 0; i < line6pcm->line6->iso_buffers; i++) {
if (test_bit(i, &pcms->active_urbs))
alive++;
}
@@ -146,15 +146,20 @@ get_stream(struct snd_line6_pcm *line6pcm, int direction)
}
/* allocate a buffer if not opened yet;
- * call this in line6pcm.state_change mutex
+ * call this in line6pcm.state_mutex
*/
static int line6_buffer_acquire(struct snd_line6_pcm *line6pcm,
- struct line6_pcm_stream *pstr, int type)
+ struct line6_pcm_stream *pstr, int direction, int type)
{
+ const int pkt_size =
+ (direction == SNDRV_PCM_STREAM_PLAYBACK) ?
+ line6pcm->max_packet_size_out :
+ line6pcm->max_packet_size_in;
+
/* 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);
+ pstr->buffer = kmalloc(line6pcm->line6->iso_buffers *
+ LINE6_ISO_PACKETS * pkt_size, GFP_KERNEL);
if (!pstr->buffer)
return -ENOMEM;
}
@@ -162,12 +167,11 @@ static int line6_buffer_acquire(struct snd_line6_pcm *line6pcm,
}
/* free a buffer if all streams are closed;
- * call this in line6pcm.state_change mutex
+ * call this in line6pcm.state_mutex
*/
static void line6_buffer_release(struct snd_line6_pcm *line6pcm,
struct line6_pcm_stream *pstr, int type)
{
-
clear_bit(type, &pstr->opened);
if (!pstr->opened) {
line6_wait_clear_audio_urbs(line6pcm, pstr);
@@ -194,6 +198,7 @@ static int line6_stream_start(struct snd_line6_pcm *line6pcm, int direction,
else
ret = line6_submit_audio_in_all_urbs(line6pcm);
}
+
if (ret < 0)
clear_bit(type, &pstr->running);
spin_unlock_irqrestore(&pstr->lock, flags);
@@ -237,6 +242,14 @@ int snd_line6_trigger(struct snd_pcm_substream *substream, int cmd)
switch (cmd) {
case SNDRV_PCM_TRIGGER_START:
case SNDRV_PCM_TRIGGER_RESUME:
+ if (s->stream == SNDRV_PCM_STREAM_CAPTURE &&
+ (line6pcm->line6->properties->capabilities &
+ LINE6_CAP_IN_NEEDS_OUT)) {
+ err = line6_stream_start(line6pcm, SNDRV_PCM_STREAM_PLAYBACK,
+ LINE6_STREAM_CAPTURE_HELPER);
+ if (err < 0)
+ return err;
+ }
err = line6_stream_start(line6pcm, s->stream,
LINE6_STREAM_PCM);
if (err < 0)
@@ -245,6 +258,12 @@ int snd_line6_trigger(struct snd_pcm_substream *substream, int cmd)
case SNDRV_PCM_TRIGGER_STOP:
case SNDRV_PCM_TRIGGER_SUSPEND:
+ if (s->stream == SNDRV_PCM_STREAM_CAPTURE &&
+ (line6pcm->line6->properties->capabilities &
+ LINE6_CAP_IN_NEEDS_OUT)) {
+ line6_stream_stop(line6pcm, SNDRV_PCM_STREAM_PLAYBACK,
+ LINE6_STREAM_CAPTURE_HELPER);
+ }
line6_stream_stop(line6pcm, s->stream,
LINE6_STREAM_PCM);
break;
@@ -278,27 +297,30 @@ snd_pcm_uframes_t snd_line6_pointer(struct snd_pcm_substream *substream)
return pstr->pos_done;
}
-/* Acquire and start duplex streams:
+/* Acquire and optionally start duplex streams:
* type is either LINE6_STREAM_IMPULSE or LINE6_STREAM_MONITOR
*/
-int line6_pcm_acquire(struct snd_line6_pcm *line6pcm, int type)
+int line6_pcm_acquire(struct snd_line6_pcm *line6pcm, int type, bool start)
{
struct line6_pcm_stream *pstr;
int ret = 0, dir;
+ /* TODO: We should assert SNDRV_PCM_STREAM_PLAYBACK/CAPTURE == 0/1 */
mutex_lock(&line6pcm->state_mutex);
for (dir = 0; dir < 2; dir++) {
pstr = get_stream(line6pcm, dir);
- ret = line6_buffer_acquire(line6pcm, pstr, type);
+ ret = line6_buffer_acquire(line6pcm, pstr, dir, type);
if (ret < 0)
goto error;
if (!pstr->running)
line6_wait_clear_audio_urbs(line6pcm, pstr);
}
- for (dir = 0; dir < 2; dir++) {
- ret = line6_stream_start(line6pcm, dir, type);
- if (ret < 0)
- goto error;
+ if (start) {
+ for (dir = 0; dir < 2; dir++) {
+ ret = line6_stream_start(line6pcm, dir, type);
+ if (ret < 0)
+ goto error;
+ }
}
error:
mutex_unlock(&line6pcm->state_mutex);
@@ -334,7 +356,8 @@ int snd_line6_hw_params(struct snd_pcm_substream *substream,
struct line6_pcm_stream *pstr = get_stream(line6pcm, substream->stream);
mutex_lock(&line6pcm->state_mutex);
- ret = line6_buffer_acquire(line6pcm, pstr, LINE6_STREAM_PCM);
+ ret = line6_buffer_acquire(line6pcm, pstr, substream->stream,
+ LINE6_STREAM_PCM);
if (ret < 0)
goto error;
@@ -434,24 +457,30 @@ static struct snd_kcontrol_new line6_controls[] = {
/*
Cleanup the PCM device.
*/
-static void cleanup_urbs(struct line6_pcm_stream *pcms)
+static void cleanup_urbs(struct line6_pcm_stream *pcms, int iso_buffers)
{
int i;
- for (i = 0; i < LINE6_ISO_BUFFERS; i++) {
+ /* Most likely impossible in current code... */
+ if (pcms->urbs == NULL)
+ return;
+
+ for (i = 0; i < iso_buffers; i++) {
if (pcms->urbs[i]) {
usb_kill_urb(pcms->urbs[i]);
usb_free_urb(pcms->urbs[i]);
}
}
+ kfree(pcms->urbs);
+ pcms->urbs = NULL;
}
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);
+ cleanup_urbs(&line6pcm->out, line6pcm->line6->iso_buffers);
+ cleanup_urbs(&line6pcm->in, line6pcm->line6->iso_buffers);
kfree(line6pcm);
}
@@ -523,12 +552,12 @@ int line6_init_pcm(struct usb_line6 *line6,
line6pcm->volume_monitor = 255;
line6pcm->line6 = line6;
- /* 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));
+ line6pcm->max_packet_size_in =
+ usb_maxpacket(line6->usbdev,
+ usb_rcvisocpipe(line6->usbdev, ep_read), 0);
+ line6pcm->max_packet_size_out =
+ usb_maxpacket(line6->usbdev,
+ usb_sndisocpipe(line6->usbdev, ep_write), 1);
spin_lock_init(&line6pcm->out.lock);
spin_lock_init(&line6pcm->in.lock);
diff --git a/sound/usb/line6/pcm.h b/sound/usb/line6/pcm.h
index 508410adbd51..bb0c9cbf2a78 100644
--- a/sound/usb/line6/pcm.h
+++ b/sound/usb/line6/pcm.h
@@ -20,9 +20,6 @@
#include "driver.h"
-/* number of URBs */
-#define LINE6_ISO_BUFFERS 2
-
/*
number of USB frames per URB
The Line 6 Windows driver always transmits two frames per packet, but
@@ -31,7 +28,9 @@
*/
#define LINE6_ISO_PACKETS 1
-/* in a "full speed" device (such as the PODxt Pro) this means 1ms */
+/* in a "full speed" device (such as the PODxt Pro) this means 1ms,
+ * for "high speed" it's 1/8ms
+ */
#define LINE6_ISO_INTERVAL 1
#define LINE6_IMPULSE_DEFAULT_PERIOD 100
@@ -74,6 +73,7 @@ enum {
LINE6_STREAM_PCM,
LINE6_STREAM_MONITOR,
LINE6_STREAM_IMPULSE,
+ LINE6_STREAM_CAPTURE_HELPER,
};
/* misc bit flags for PCM operation */
@@ -85,12 +85,12 @@ enum {
struct line6_pcm_properties {
struct snd_pcm_hardware playback_hw, capture_hw;
struct snd_pcm_hw_constraint_ratdens rates;
- int bytes_per_frame;
+ int bytes_per_channel;
};
struct line6_pcm_stream {
/* allocated URBs */
- struct urb *urbs[LINE6_ISO_BUFFERS];
+ struct urb **urbs;
/* Temporary buffer;
* Since the packet size is not known in advance, this buffer is
@@ -157,11 +157,12 @@ struct snd_line6_pcm {
/* Previously captured frame (for software monitoring) */
unsigned char *prev_fbuf;
- /* Size of previously captured frame (for software monitoring) */
+ /* Size of previously captured frame (for software monitoring/sync) */
int prev_fsize;
/* Maximum size of USB packet */
- int max_packet_size;
+ int max_packet_size_in;
+ int max_packet_size_out;
/* PCM playback volume (left and right) */
int volume_playback[2];
@@ -191,7 +192,8 @@ extern int snd_line6_hw_params(struct snd_pcm_substream *substream,
extern int snd_line6_hw_free(struct snd_pcm_substream *substream);
extern snd_pcm_uframes_t snd_line6_pointer(struct snd_pcm_substream *substream);
extern void line6_pcm_disconnect(struct snd_line6_pcm *line6pcm);
-extern int line6_pcm_acquire(struct snd_line6_pcm *line6pcm, int type);
+extern int line6_pcm_acquire(struct snd_line6_pcm *line6pcm, int type,
+ bool start);
extern void line6_pcm_release(struct snd_line6_pcm *line6pcm, int type);
#endif
diff --git a/sound/usb/line6/playback.c b/sound/usb/line6/playback.c
index 97ed593f6010..812d18191e01 100644
--- a/sound/usb/line6/playback.c
+++ b/sound/usb/line6/playback.c
@@ -146,18 +146,20 @@ static int submit_audio_out_urb(struct snd_line6_pcm *line6pcm)
int index;
int i, urb_size, urb_frames;
int ret;
- const int bytes_per_frame = line6pcm->properties->bytes_per_frame;
+ const int bytes_per_frame =
+ line6pcm->properties->bytes_per_channel *
+ line6pcm->properties->playback_hw.channels_max;
const int frame_increment =
line6pcm->properties->rates.rats[0].num_min;
const int frame_factor =
line6pcm->properties->rates.rats[0].den *
- (USB_INTERVALS_PER_SECOND / LINE6_ISO_INTERVAL);
+ (line6pcm->line6->intervals_per_second / LINE6_ISO_INTERVAL);
struct urb *urb_out;
- index =
- find_first_zero_bit(&line6pcm->out.active_urbs, LINE6_ISO_BUFFERS);
+ index = find_first_zero_bit(&line6pcm->out.active_urbs,
+ line6pcm->line6->iso_buffers);
- if (index < 0 || index >= LINE6_ISO_BUFFERS) {
+ if (index < 0 || index >= line6pcm->line6->iso_buffers) {
dev_err(line6pcm->line6->ifcdev, "no free URB found\n");
return -EINVAL;
}
@@ -165,6 +167,7 @@ static int submit_audio_out_urb(struct snd_line6_pcm *line6pcm)
urb_out = line6pcm->out.urbs[index];
urb_size = 0;
+ /* TODO: this may not work for LINE6_ISO_PACKETS != 1 */
for (i = 0; i < LINE6_ISO_PACKETS; ++i) {
/* compute frame size for given sampling rate */
int fsize = 0;
@@ -178,9 +181,11 @@ static int submit_audio_out_urb(struct snd_line6_pcm *line6pcm)
line6pcm->out.count += frame_increment;
n = line6pcm->out.count / frame_factor;
line6pcm->out.count -= n * frame_factor;
- fsize = n * bytes_per_frame;
+ fsize = n;
}
+ fsize *= bytes_per_frame;
+
fout->offset = urb_size;
fout->length = fsize;
urb_size += fsize;
@@ -195,7 +200,7 @@ static int submit_audio_out_urb(struct snd_line6_pcm *line6pcm)
urb_frames = urb_size / bytes_per_frame;
urb_out->transfer_buffer =
line6pcm->out.buffer +
- index * LINE6_ISO_PACKETS * line6pcm->max_packet_size;
+ index * LINE6_ISO_PACKETS * line6pcm->max_packet_size_out;
urb_out->transfer_buffer_length = urb_size;
urb_out->context = line6pcm;
@@ -286,7 +291,7 @@ int line6_submit_audio_out_all_urbs(struct snd_line6_pcm *line6pcm)
{
int ret = 0, i;
- for (i = 0; i < LINE6_ISO_BUFFERS; ++i) {
+ for (i = 0; i < line6pcm->line6->iso_buffers; ++i) {
ret = submit_audio_out_urb(line6pcm);
if (ret < 0)
break;
@@ -305,6 +310,9 @@ static void audio_out_callback(struct urb *urb)
struct snd_line6_pcm *line6pcm = (struct snd_line6_pcm *)urb->context;
struct snd_pcm_substream *substream =
get_substream(line6pcm, SNDRV_PCM_STREAM_PLAYBACK);
+ const int bytes_per_frame =
+ line6pcm->properties->bytes_per_channel *
+ line6pcm->properties->playback_hw.channels_max;
#if USE_CLEAR_BUFFER_WORKAROUND
memset(urb->transfer_buffer, 0, urb->transfer_buffer_length);
@@ -313,11 +321,11 @@ static void audio_out_callback(struct urb *urb)
line6pcm->out.last_frame = urb->start_frame;
/* find index of URB */
- for (index = 0; index < LINE6_ISO_BUFFERS; index++)
+ for (index = 0; index < line6pcm->line6->iso_buffers; index++)
if (urb == line6pcm->out.urbs[index])
break;
- if (index >= LINE6_ISO_BUFFERS)
+ if (index >= line6pcm->line6->iso_buffers)
return; /* URB has been unlinked asynchronously */
for (i = 0; i < LINE6_ISO_PACKETS; i++)
@@ -329,7 +337,7 @@ static void audio_out_callback(struct urb *urb)
struct snd_pcm_runtime *runtime = substream->runtime;
line6pcm->out.pos_done +=
- length / line6pcm->properties->bytes_per_frame;
+ length / bytes_per_frame;
if (line6pcm->out.pos_done >= runtime->buffer_size)
line6pcm->out.pos_done -= runtime->buffer_size;
@@ -401,8 +409,13 @@ int line6_create_audio_out_urbs(struct snd_line6_pcm *line6pcm)
struct usb_line6 *line6 = line6pcm->line6;
int i;
+ line6pcm->out.urbs = kzalloc(
+ sizeof(struct urb *) * line6->iso_buffers, GFP_KERNEL);
+ if (line6pcm->out.urbs == NULL)
+ return -ENOMEM;
+
/* create audio URBs and fill in constant values: */
- for (i = 0; i < LINE6_ISO_BUFFERS; ++i) {
+ for (i = 0; i < line6->iso_buffers; ++i) {
struct urb *urb;
/* URB for audio out: */
diff --git a/sound/usb/line6/pod.c b/sound/usb/line6/pod.c
index 45dd34874f43..17aa616e61f5 100644
--- a/sound/usb/line6/pod.c
+++ b/sound/usb/line6/pod.c
@@ -83,7 +83,6 @@ struct usb_line6_pod {
};
#define POD_SYSEX_CODE 3
-#define POD_BYTES_PER_FRAME 6 /* 24bit audio (stereo) */
/* *INDENT-OFF* */
@@ -167,7 +166,7 @@ static struct line6_pcm_properties pod_pcm_properties = {
.rates = {
.nrats = 1,
.rats = &pod_ratden},
- .bytes_per_frame = POD_BYTES_PER_FRAME
+ .bytes_per_channel = 3 /* SNDRV_PCM_FMTBIT_S24_3LE */
};
static const char pod_version_header[] = {
@@ -476,6 +475,7 @@ static const struct line6_properties pod_properties_table[] = {
.id = "BassPODxt",
.name = "BassPODxt",
.capabilities = LINE6_CAP_CONTROL
+ | LINE6_CAP_CONTROL_MIDI
| LINE6_CAP_PCM
| LINE6_CAP_HWMON,
.altsetting = 5,
@@ -488,6 +488,7 @@ static const struct line6_properties pod_properties_table[] = {
.id = "BassPODxtLive",
.name = "BassPODxt Live",
.capabilities = LINE6_CAP_CONTROL
+ | LINE6_CAP_CONTROL_MIDI
| LINE6_CAP_PCM
| LINE6_CAP_HWMON,
.altsetting = 1,
@@ -500,6 +501,7 @@ static const struct line6_properties pod_properties_table[] = {
.id = "BassPODxtPro",
.name = "BassPODxt Pro",
.capabilities = LINE6_CAP_CONTROL
+ | LINE6_CAP_CONTROL_MIDI
| LINE6_CAP_PCM
| LINE6_CAP_HWMON,
.altsetting = 5,
@@ -511,7 +513,8 @@ static const struct line6_properties pod_properties_table[] = {
[LINE6_POCKETPOD] = {
.id = "PocketPOD",
.name = "Pocket POD",
- .capabilities = LINE6_CAP_CONTROL,
+ .capabilities = LINE6_CAP_CONTROL
+ | LINE6_CAP_CONTROL_MIDI,
.altsetting = 0,
.ep_ctrl_r = 0x82,
.ep_ctrl_w = 0x02,
@@ -521,6 +524,7 @@ static const struct line6_properties pod_properties_table[] = {
.id = "PODxt",
.name = "PODxt",
.capabilities = LINE6_CAP_CONTROL
+ | LINE6_CAP_CONTROL_MIDI
| LINE6_CAP_PCM
| LINE6_CAP_HWMON,
.altsetting = 5,
@@ -533,6 +537,7 @@ static const struct line6_properties pod_properties_table[] = {
.id = "PODxtLive",
.name = "PODxt Live",
.capabilities = LINE6_CAP_CONTROL
+ | LINE6_CAP_CONTROL_MIDI
| LINE6_CAP_PCM
| LINE6_CAP_HWMON,
.altsetting = 1,
@@ -545,6 +550,7 @@ static const struct line6_properties pod_properties_table[] = {
.id = "PODxtPro",
.name = "PODxt Pro",
.capabilities = LINE6_CAP_CONTROL
+ | LINE6_CAP_CONTROL_MIDI
| LINE6_CAP_PCM
| LINE6_CAP_HWMON,
.altsetting = 5,
diff --git a/sound/usb/line6/podhd.c b/sound/usb/line6/podhd.c
index 63dcaef41ac3..9352a44ae6e4 100644
--- a/sound/usb/line6/podhd.c
+++ b/sound/usb/line6/podhd.c
@@ -2,6 +2,7 @@
* Line 6 Pod HD
*
* Copyright (C) 2011 Stefan Hajnoczi <stefanha@gmail.com>
+ * Copyright (C) 2015 Andrej Krutak <dev@andree.sk>
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License as
@@ -18,14 +19,46 @@
#include "driver.h"
#include "pcm.h"
+#define PODHD_STARTUP_DELAY 500
+
+/*
+ * Stages of POD startup procedure
+ */
+enum {
+ PODHD_STARTUP_INIT = 1,
+ PODHD_STARTUP_SCHEDULE_WORKQUEUE,
+ PODHD_STARTUP_SETUP,
+ PODHD_STARTUP_LAST = PODHD_STARTUP_SETUP - 1
+};
+
enum {
LINE6_PODHD300,
LINE6_PODHD400,
LINE6_PODHD500_0,
LINE6_PODHD500_1,
+ LINE6_PODX3,
+ LINE6_PODX3LIVE
};
-#define PODHD_BYTES_PER_FRAME 6 /* 24bit audio (stereo) */
+struct usb_line6_podhd {
+ /* Generic Line 6 USB data */
+ struct usb_line6 line6;
+
+ /* Timer for device initialization */
+ struct timer_list startup_timer;
+
+ /* Work handler for device initialization */
+ struct work_struct startup_work;
+
+ /* Current progress in startup procedure */
+ int startup_progress;
+
+ /* Serial number of device */
+ u32 serial_number;
+
+ /* Firmware version */
+ int firmware_version;
+};
static struct snd_ratden podhd_ratden = {
.num_min = 48000,
@@ -73,29 +106,233 @@ static struct line6_pcm_properties podhd_pcm_properties = {
.rates = {
.nrats = 1,
.rats = &podhd_ratden},
- .bytes_per_frame = PODHD_BYTES_PER_FRAME
+ .bytes_per_channel = 3 /* SNDRV_PCM_FMTBIT_S24_3LE */
+};
+
+static struct line6_pcm_properties podx3_pcm_properties = {
+ .playback_hw = {
+ .info = (SNDRV_PCM_INFO_MMAP |
+ SNDRV_PCM_INFO_INTERLEAVED |
+ SNDRV_PCM_INFO_BLOCK_TRANSFER |
+ SNDRV_PCM_INFO_MMAP_VALID |
+ SNDRV_PCM_INFO_PAUSE |
+ SNDRV_PCM_INFO_SYNC_START),
+ .formats = SNDRV_PCM_FMTBIT_S24_3LE,
+ .rates = SNDRV_PCM_RATE_48000,
+ .rate_min = 48000,
+ .rate_max = 48000,
+ .channels_min = 2,
+ .channels_max = 2,
+ .buffer_bytes_max = 60000,
+ .period_bytes_min = 64,
+ .period_bytes_max = 8192,
+ .periods_min = 1,
+ .periods_max = 1024},
+ .capture_hw = {
+ .info = (SNDRV_PCM_INFO_MMAP |
+ SNDRV_PCM_INFO_INTERLEAVED |
+ SNDRV_PCM_INFO_BLOCK_TRANSFER |
+ SNDRV_PCM_INFO_MMAP_VALID |
+ SNDRV_PCM_INFO_SYNC_START),
+ .formats = SNDRV_PCM_FMTBIT_S24_3LE,
+ .rates = SNDRV_PCM_RATE_48000,
+ .rate_min = 48000,
+ .rate_max = 48000,
+ /* 1+2: Main signal (out), 3+4: Tone 1,
+ * 5+6: Tone 2, 7+8: raw
+ */
+ .channels_min = 8,
+ .channels_max = 8,
+ .buffer_bytes_max = 60000,
+ .period_bytes_min = 64,
+ .period_bytes_max = 8192,
+ .periods_min = 1,
+ .periods_max = 1024},
+ .rates = {
+ .nrats = 1,
+ .rats = &podhd_ratden},
+ .bytes_per_channel = 3 /* SNDRV_PCM_FMTBIT_S24_3LE */
+};
+
+static void podhd_startup_start_workqueue(unsigned long data);
+static void podhd_startup_workqueue(struct work_struct *work);
+static int podhd_startup_finalize(struct usb_line6_podhd *pod);
+
+static ssize_t serial_number_show(struct device *dev,
+ struct device_attribute *attr, char *buf)
+{
+ struct snd_card *card = dev_to_snd_card(dev);
+ struct usb_line6_podhd *pod = card->private_data;
+
+ return sprintf(buf, "%u\n", pod->serial_number);
+}
+
+static ssize_t firmware_version_show(struct device *dev,
+ struct device_attribute *attr, char *buf)
+{
+ struct snd_card *card = dev_to_snd_card(dev);
+ struct usb_line6_podhd *pod = card->private_data;
+
+ return sprintf(buf, "%06x\n", pod->firmware_version);
+}
+
+static DEVICE_ATTR_RO(firmware_version);
+static DEVICE_ATTR_RO(serial_number);
+
+static struct attribute *podhd_dev_attrs[] = {
+ &dev_attr_firmware_version.attr,
+ &dev_attr_serial_number.attr,
+ NULL
+};
+
+static const struct attribute_group podhd_dev_attr_group = {
+ .name = "podhd",
+ .attrs = podhd_dev_attrs,
};
/*
+ * POD X3 startup procedure.
+ *
+ * May be compatible with other POD HD's, since it's also similar to the
+ * previous POD setup. In any case, it doesn't seem to be required for the
+ * audio nor bulk interfaces to work.
+ */
+
+static void podhd_startup(struct usb_line6_podhd *pod)
+{
+ CHECK_STARTUP_PROGRESS(pod->startup_progress, PODHD_STARTUP_INIT);
+
+ /* delay startup procedure: */
+ line6_start_timer(&pod->startup_timer, PODHD_STARTUP_DELAY,
+ podhd_startup_start_workqueue, (unsigned long)pod);
+}
+
+static void podhd_startup_start_workqueue(unsigned long data)
+{
+ struct usb_line6_podhd *pod = (struct usb_line6_podhd *)data;
+
+ CHECK_STARTUP_PROGRESS(pod->startup_progress,
+ PODHD_STARTUP_SCHEDULE_WORKQUEUE);
+
+ /* schedule work for global work queue: */
+ schedule_work(&pod->startup_work);
+}
+
+static int podhd_dev_start(struct usb_line6_podhd *pod)
+{
+ int ret;
+ u8 init_bytes[8];
+ int i;
+ struct usb_device *usbdev = pod->line6.usbdev;
+
+ ret = usb_control_msg(usbdev, usb_sndctrlpipe(usbdev, 0),
+ 0x67, USB_TYPE_VENDOR | USB_RECIP_DEVICE | USB_DIR_OUT,
+ 0x11, 0,
+ NULL, 0, LINE6_TIMEOUT * HZ);
+ if (ret < 0) {
+ dev_err(pod->line6.ifcdev, "read request failed (error %d)\n", ret);
+ return ret;
+ }
+
+ /* NOTE: looks like some kind of ping message */
+ ret = usb_control_msg(usbdev, usb_rcvctrlpipe(usbdev, 0), 0x67,
+ USB_TYPE_VENDOR | USB_RECIP_DEVICE | USB_DIR_IN,
+ 0x11, 0x0,
+ &init_bytes, 3, LINE6_TIMEOUT * HZ);
+ if (ret < 0) {
+ dev_err(pod->line6.ifcdev,
+ "receive length failed (error %d)\n", ret);
+ return ret;
+ }
+
+ pod->firmware_version =
+ (init_bytes[0] << 16) | (init_bytes[1] << 8) | (init_bytes[2] << 0);
+
+ for (i = 0; i <= 16; i++) {
+ ret = line6_read_data(&pod->line6, 0xf000 + 0x08 * i, init_bytes, 8);
+ if (ret < 0)
+ return ret;
+ }
+
+ ret = usb_control_msg(usbdev, usb_sndctrlpipe(usbdev, 0),
+ USB_REQ_SET_FEATURE,
+ USB_TYPE_STANDARD | USB_RECIP_DEVICE | USB_DIR_OUT,
+ 1, 0,
+ NULL, 0, LINE6_TIMEOUT * HZ);
+ if (ret < 0)
+ return ret;
+
+ return 0;
+}
+
+static void podhd_startup_workqueue(struct work_struct *work)
+{
+ struct usb_line6_podhd *pod =
+ container_of(work, struct usb_line6_podhd, startup_work);
+
+ CHECK_STARTUP_PROGRESS(pod->startup_progress, PODHD_STARTUP_SETUP);
+
+ podhd_dev_start(pod);
+ line6_read_serial_number(&pod->line6, &pod->serial_number);
+
+ podhd_startup_finalize(pod);
+}
+
+static int podhd_startup_finalize(struct usb_line6_podhd *pod)
+{
+ struct usb_line6 *line6 = &pod->line6;
+
+ /* ALSA audio interface: */
+ return snd_card_register(line6->card);
+}
+
+static void podhd_disconnect(struct usb_line6 *line6)
+{
+ struct usb_line6_podhd *pod = (struct usb_line6_podhd *)line6;
+
+ if (pod->line6.properties->capabilities & LINE6_CAP_CONTROL) {
+ del_timer_sync(&pod->startup_timer);
+ cancel_work_sync(&pod->startup_work);
+ }
+}
+
+/*
Try to init POD HD device.
*/
static int podhd_init(struct usb_line6 *line6,
const struct usb_device_id *id)
{
int err;
+ struct usb_line6_podhd *pod = (struct usb_line6_podhd *) line6;
- /* initialize MIDI subsystem: */
- err = line6_init_midi(line6);
- if (err < 0)
- return err;
+ line6->disconnect = podhd_disconnect;
- /* initialize PCM subsystem: */
- err = line6_init_pcm(line6, &podhd_pcm_properties);
- if (err < 0)
- return err;
+ if (pod->line6.properties->capabilities & LINE6_CAP_CONTROL) {
+ /* create sysfs entries: */
+ err = snd_card_add_dev_attr(line6->card, &podhd_dev_attr_group);
+ if (err < 0)
+ return err;
+ }
- /* register USB audio system: */
- return snd_card_register(line6->card);
+ if (pod->line6.properties->capabilities & LINE6_CAP_PCM) {
+ /* initialize PCM subsystem: */
+ err = line6_init_pcm(line6,
+ (id->driver_info == LINE6_PODX3) ? &podx3_pcm_properties :
+ &podhd_pcm_properties);
+ if (err < 0)
+ return err;
+ }
+
+ if (!(pod->line6.properties->capabilities & LINE6_CAP_CONTROL)) {
+ /* register USB audio system directly */
+ return podhd_startup_finalize(pod);
+ }
+
+ /* init device and delay registering */
+ init_timer(&pod->startup_timer);
+ INIT_WORK(&pod->startup_work, podhd_startup_workqueue);
+ podhd_startup(pod);
+ return 0;
}
#define LINE6_DEVICE(prod) USB_DEVICE(0x0e41, prod)
@@ -103,10 +340,13 @@ static int podhd_init(struct usb_line6 *line6,
/* table of devices that work with this driver */
static const struct usb_device_id podhd_id_table[] = {
+ /* TODO: no need to alloc data interfaces when only audio is used */
{ LINE6_DEVICE(0x5057), .driver_info = LINE6_PODHD300 },
{ LINE6_DEVICE(0x5058), .driver_info = LINE6_PODHD400 },
{ LINE6_IF_NUM(0x414D, 0), .driver_info = LINE6_PODHD500_0 },
{ LINE6_IF_NUM(0x414D, 1), .driver_info = LINE6_PODHD500_1 },
+ { LINE6_IF_NUM(0x414A, 0), .driver_info = LINE6_PODX3 },
+ { LINE6_IF_NUM(0x414B, 0), .driver_info = LINE6_PODX3LIVE },
{}
};
@@ -116,8 +356,7 @@ static const struct line6_properties podhd_properties_table[] = {
[LINE6_PODHD300] = {
.id = "PODHD300",
.name = "POD HD300",
- .capabilities = LINE6_CAP_CONTROL
- | LINE6_CAP_PCM
+ .capabilities = LINE6_CAP_PCM
| LINE6_CAP_HWMON,
.altsetting = 5,
.ep_ctrl_r = 0x84,
@@ -128,8 +367,7 @@ static const struct line6_properties podhd_properties_table[] = {
[LINE6_PODHD400] = {
.id = "PODHD400",
.name = "POD HD400",
- .capabilities = LINE6_CAP_CONTROL
- | LINE6_CAP_PCM
+ .capabilities = LINE6_CAP_PCM
| LINE6_CAP_HWMON,
.altsetting = 5,
.ep_ctrl_r = 0x84,
@@ -140,8 +378,7 @@ static const struct line6_properties podhd_properties_table[] = {
[LINE6_PODHD500_0] = {
.id = "PODHD500",
.name = "POD HD500",
- .capabilities = LINE6_CAP_CONTROL
- | LINE6_CAP_PCM
+ .capabilities = LINE6_CAP_PCM
| LINE6_CAP_HWMON,
.altsetting = 1,
.ep_ctrl_r = 0x81,
@@ -152,8 +389,7 @@ static const struct line6_properties podhd_properties_table[] = {
[LINE6_PODHD500_1] = {
.id = "PODHD500",
.name = "POD HD500",
- .capabilities = LINE6_CAP_CONTROL
- | LINE6_CAP_PCM
+ .capabilities = LINE6_CAP_PCM
| LINE6_CAP_HWMON,
.altsetting = 1,
.ep_ctrl_r = 0x81,
@@ -161,6 +397,28 @@ static const struct line6_properties podhd_properties_table[] = {
.ep_audio_r = 0x86,
.ep_audio_w = 0x02,
},
+ [LINE6_PODX3] = {
+ .id = "PODX3",
+ .name = "POD X3",
+ .capabilities = LINE6_CAP_CONTROL
+ | LINE6_CAP_PCM | LINE6_CAP_HWMON | LINE6_CAP_IN_NEEDS_OUT,
+ .altsetting = 1,
+ .ep_ctrl_r = 0x81,
+ .ep_ctrl_w = 0x01,
+ .ep_audio_r = 0x86,
+ .ep_audio_w = 0x02,
+ },
+ [LINE6_PODX3LIVE] = {
+ .id = "PODX3LIVE",
+ .name = "POD X3 LIVE",
+ .capabilities = LINE6_CAP_CONTROL
+ | LINE6_CAP_PCM | LINE6_CAP_HWMON | LINE6_CAP_IN_NEEDS_OUT,
+ .altsetting = 1,
+ .ep_ctrl_r = 0x81,
+ .ep_ctrl_w = 0x01,
+ .ep_audio_r = 0x86,
+ .ep_audio_w = 0x02,
+ },
};
/*
@@ -171,7 +429,7 @@ static int podhd_probe(struct usb_interface *interface,
{
return line6_probe(interface, id, "Line6-PODHD",
&podhd_properties_table[id->driver_info],
- podhd_init, sizeof(struct usb_line6));
+ podhd_init, sizeof(struct usb_line6_podhd));
}
static struct usb_driver podhd_driver = {
diff --git a/sound/usb/line6/toneport.c b/sound/usb/line6/toneport.c
index 6d4c50c9b17d..8e22f430d700 100644
--- a/sound/usb/line6/toneport.c
+++ b/sound/usb/line6/toneport.c
@@ -114,7 +114,7 @@ static struct line6_pcm_properties toneport_pcm_properties = {
.rates = {
.nrats = 1,
.rats = &toneport_ratden},
- .bytes_per_frame = 4
+ .bytes_per_channel = 2
};
static const struct {
@@ -177,7 +177,7 @@ static int snd_toneport_monitor_put(struct snd_kcontrol *kcontrol,
line6pcm->volume_monitor = ucontrol->value.integer.value[0];
if (line6pcm->volume_monitor > 0) {
- err = line6_pcm_acquire(line6pcm, LINE6_STREAM_MONITOR);
+ err = line6_pcm_acquire(line6pcm, LINE6_STREAM_MONITOR, true);
if (err < 0) {
line6pcm->volume_monitor = 0;
line6_pcm_release(line6pcm, LINE6_STREAM_MONITOR);
@@ -246,7 +246,7 @@ static void toneport_start_pcm(unsigned long arg)
struct usb_line6_toneport *toneport = (struct usb_line6_toneport *)arg;
struct usb_line6 *line6 = &toneport->line6;
- line6_pcm_acquire(line6->line6pcm, LINE6_STREAM_MONITOR);
+ line6_pcm_acquire(line6->line6pcm, LINE6_STREAM_MONITOR, true);
}
/* control definition */
diff --git a/sound/usb/line6/variax.c b/sound/usb/line6/variax.c
index ddc23ddf0750..0c4512d0382e 100644
--- a/sound/usb/line6/variax.c
+++ b/sound/usb/line6/variax.c
@@ -259,7 +259,8 @@ static const struct line6_properties variax_properties_table[] = {
[LINE6_PODXTLIVE_VARIAX] = {
.id = "PODxtLive",
.name = "PODxt Live",
- .capabilities = LINE6_CAP_CONTROL,
+ .capabilities = LINE6_CAP_CONTROL
+ | LINE6_CAP_CONTROL_MIDI,
.altsetting = 1,
.ep_ctrl_r = 0x86,
.ep_ctrl_w = 0x05,
@@ -269,7 +270,8 @@ static const struct line6_properties variax_properties_table[] = {
[LINE6_VARIAX] = {
.id = "Variax",
.name = "Variax Workbench",
- .capabilities = LINE6_CAP_CONTROL,
+ .capabilities = LINE6_CAP_CONTROL
+ | LINE6_CAP_CONTROL_MIDI,
.altsetting = 1,
.ep_ctrl_r = 0x82,
.ep_ctrl_w = 0x01,
diff --git a/sound/usb/mixer_quirks.c b/sound/usb/mixer_quirks.c
index f6c3bf79af9a..04991b009132 100644
--- a/sound/usb/mixer_quirks.c
+++ b/sound/usb/mixer_quirks.c
@@ -1831,6 +1831,7 @@ void snd_usb_mixer_rc_memory_change(struct usb_mixer_interface *mixer,
}
static void snd_dragonfly_quirk_db_scale(struct usb_mixer_interface *mixer,
+ struct usb_mixer_elem_info *cval,
struct snd_kcontrol *kctl)
{
/* Approximation using 10 ranges based on output measurement on hw v1.2.
@@ -1848,10 +1849,19 @@ static void snd_dragonfly_quirk_db_scale(struct usb_mixer_interface *mixer,
41, 50, TLV_DB_MINMAX_ITEM(-441, 0),
);
- usb_audio_info(mixer->chip, "applying DragonFly dB scale quirk\n");
- kctl->tlv.p = scale;
- kctl->vd[0].access |= SNDRV_CTL_ELEM_ACCESS_TLV_READ;
- kctl->vd[0].access &= ~SNDRV_CTL_ELEM_ACCESS_TLV_CALLBACK;
+ if (cval->min == 0 && cval->max == 50) {
+ usb_audio_info(mixer->chip, "applying DragonFly dB scale quirk (0-50 variant)\n");
+ kctl->tlv.p = scale;
+ kctl->vd[0].access |= SNDRV_CTL_ELEM_ACCESS_TLV_READ;
+ kctl->vd[0].access &= ~SNDRV_CTL_ELEM_ACCESS_TLV_CALLBACK;
+
+ } else if (cval->min == 0 && cval->max <= 1000) {
+ /* Some other clearly broken DragonFly variant.
+ * At least a 0..53 variant (hw v1.0) exists.
+ */
+ usb_audio_info(mixer->chip, "ignoring too narrow dB range on a DragonFly device");
+ kctl->vd[0].access &= ~SNDRV_CTL_ELEM_ACCESS_TLV_CALLBACK;
+ }
}
void snd_usb_mixer_fu_apply_quirk(struct usb_mixer_interface *mixer,
@@ -1860,8 +1870,8 @@ void snd_usb_mixer_fu_apply_quirk(struct usb_mixer_interface *mixer,
{
switch (mixer->chip->usb_id) {
case USB_ID(0x21b4, 0x0081): /* AudioQuest DragonFly */
- if (unitid == 7 && cval->min == 0 && cval->max == 50)
- snd_dragonfly_quirk_db_scale(mixer, kctl);
+ if (unitid == 7 && cval->control == UAC_FU_VOLUME)
+ snd_dragonfly_quirk_db_scale(mixer, cval, kctl);
break;
}
}
diff --git a/sound/usb/quirks.c b/sound/usb/quirks.c
index 152292e5ee2b..2782155ae3ce 100644
--- a/sound/usb/quirks.c
+++ b/sound/usb/quirks.c
@@ -1217,6 +1217,12 @@ void snd_usb_endpoint_start_quirk(struct snd_usb_endpoint *ep)
ep->chip->usb_id == USB_ID(0x0763, 0x2031)) &&
ep->type == SND_USB_ENDPOINT_TYPE_DATA)
ep->skip_packets = 16;
+
+ /* Work around devices that report unreasonable feedback data */
+ if ((ep->chip->usb_id == USB_ID(0x0644, 0x8038) || /* TEAC UD-H01 */
+ ep->chip->usb_id == USB_ID(0x1852, 0x5034)) && /* T+A Dac8 */
+ ep->syncmaxsize == 4)
+ ep->tenor_fb_quirk = 1;
}
void snd_usb_set_interface_quirk(struct usb_device *dev)