aboutsummaryrefslogtreecommitdiffstats
path: root/sound/usb
diff options
context:
space:
mode:
authorAndrea Bastoni <bastoni@cs.unc.edu>2010-05-30 19:16:45 -0400
committerAndrea Bastoni <bastoni@cs.unc.edu>2010-05-30 19:16:45 -0400
commitada47b5fe13d89735805b566185f4885f5a3f750 (patch)
tree644b88f8a71896307d71438e9b3af49126ffb22b /sound/usb
parent43e98717ad40a4ae64545b5ba047c7b86aa44f4f (diff)
parent3280f21d43ee541f97f8cda5792150d2dbec20d5 (diff)
Merge branch 'wip-2.6.34' into old-private-masterarchived-private-master
Diffstat (limited to 'sound/usb')
-rw-r--r--sound/usb/Kconfig12
-rw-r--r--sound/usb/Makefile2
-rw-r--r--sound/usb/caiaq/audio.c1
-rw-r--r--sound/usb/caiaq/device.c1
-rw-r--r--sound/usb/caiaq/midi.c1
-rw-r--r--sound/usb/caiaq/midi.h2
-rw-r--r--sound/usb/ua101.c1387
-rw-r--r--sound/usb/usbaudio.c928
-rw-r--r--sound/usb/usbaudio.h116
-rw-r--r--sound/usb/usbmidi.c262
-rw-r--r--sound/usb/usbmixer.c371
-rw-r--r--sound/usb/usbmixer_maps.c46
-rw-r--r--sound/usb/usbquirks.h286
-rw-r--r--sound/usb/usx2y/us122l.c158
-rw-r--r--sound/usb/usx2y/us122l.h6
-rw-r--r--sound/usb/usx2y/usX2Yhwdep.c9
-rw-r--r--sound/usb/usx2y/usb_stream.c1
-rw-r--r--sound/usb/usx2y/usbusx2y.c29
-rw-r--r--sound/usb/usx2y/usbusx2y.h6
-rw-r--r--sound/usb/usx2y/usbusx2yaudio.c35
-rw-r--r--sound/usb/usx2y/usx2yhwdeppcm.c9
21 files changed, 2903 insertions, 765 deletions
diff --git a/sound/usb/Kconfig b/sound/usb/Kconfig
index 73525c048e7f..c570ae3e6d55 100644
--- a/sound/usb/Kconfig
+++ b/sound/usb/Kconfig
@@ -21,6 +21,18 @@ config SND_USB_AUDIO
21 To compile this driver as a module, choose M here: the module 21 To compile this driver as a module, choose M here: the module
22 will be called snd-usb-audio. 22 will be called snd-usb-audio.
23 23
24config SND_USB_UA101
25 tristate "Edirol UA-101/UA-1000 driver (EXPERIMENTAL)"
26 depends on EXPERIMENTAL
27 select SND_PCM
28 select SND_RAWMIDI
29 help
30 Say Y here to include support for the Edirol UA-101 and UA-1000
31 audio/MIDI interfaces.
32
33 To compile this driver as a module, choose M here: the module
34 will be called snd-ua101.
35
24config SND_USB_USX2Y 36config SND_USB_USX2Y
25 tristate "Tascam US-122, US-224 and US-428 USB driver" 37 tristate "Tascam US-122, US-224 and US-428 USB driver"
26 depends on X86 || PPC || ALPHA 38 depends on X86 || PPC || ALPHA
diff --git a/sound/usb/Makefile b/sound/usb/Makefile
index abb288bfe35d..5bf64aef9558 100644
--- a/sound/usb/Makefile
+++ b/sound/usb/Makefile
@@ -4,9 +4,11 @@
4 4
5snd-usb-audio-objs := usbaudio.o usbmixer.o 5snd-usb-audio-objs := usbaudio.o usbmixer.o
6snd-usb-lib-objs := usbmidi.o 6snd-usb-lib-objs := usbmidi.o
7snd-ua101-objs := ua101.o
7 8
8# Toplevel Module Dependency 9# Toplevel Module Dependency
9obj-$(CONFIG_SND_USB_AUDIO) += snd-usb-audio.o snd-usb-lib.o 10obj-$(CONFIG_SND_USB_AUDIO) += snd-usb-audio.o snd-usb-lib.o
11obj-$(CONFIG_SND_USB_UA101) += snd-ua101.o snd-usb-lib.o
10obj-$(CONFIG_SND_USB_USX2Y) += snd-usb-lib.o 12obj-$(CONFIG_SND_USB_USX2Y) += snd-usb-lib.o
11obj-$(CONFIG_SND_USB_US122L) += snd-usb-lib.o 13obj-$(CONFIG_SND_USB_US122L) += snd-usb-lib.o
12 14
diff --git a/sound/usb/caiaq/audio.c b/sound/usb/caiaq/audio.c
index 86b2c3b92df5..4328cad6c3a2 100644
--- a/sound/usb/caiaq/audio.c
+++ b/sound/usb/caiaq/audio.c
@@ -17,6 +17,7 @@
17*/ 17*/
18 18
19#include <linux/spinlock.h> 19#include <linux/spinlock.h>
20#include <linux/slab.h>
20#include <linux/init.h> 21#include <linux/init.h>
21#include <linux/usb.h> 22#include <linux/usb.h>
22#include <sound/core.h> 23#include <sound/core.h>
diff --git a/sound/usb/caiaq/device.c b/sound/usb/caiaq/device.c
index a3f02dd97440..afc5aeb68005 100644
--- a/sound/usb/caiaq/device.c
+++ b/sound/usb/caiaq/device.c
@@ -23,6 +23,7 @@
23#include <linux/interrupt.h> 23#include <linux/interrupt.h>
24#include <linux/module.h> 24#include <linux/module.h>
25#include <linux/init.h> 25#include <linux/init.h>
26#include <linux/gfp.h>
26#include <linux/usb.h> 27#include <linux/usb.h>
27#include <sound/initval.h> 28#include <sound/initval.h>
28#include <sound/core.h> 29#include <sound/core.h>
diff --git a/sound/usb/caiaq/midi.c b/sound/usb/caiaq/midi.c
index 538e8c00d31a..2f218c77fff2 100644
--- a/sound/usb/caiaq/midi.c
+++ b/sound/usb/caiaq/midi.c
@@ -17,6 +17,7 @@
17*/ 17*/
18 18
19#include <linux/usb.h> 19#include <linux/usb.h>
20#include <linux/gfp.h>
20#include <sound/rawmidi.h> 21#include <sound/rawmidi.h>
21#include <sound/core.h> 22#include <sound/core.h>
22#include <sound/pcm.h> 23#include <sound/pcm.h>
diff --git a/sound/usb/caiaq/midi.h b/sound/usb/caiaq/midi.h
index 9d16db027fc3..380f984babc9 100644
--- a/sound/usb/caiaq/midi.h
+++ b/sound/usb/caiaq/midi.h
@@ -3,6 +3,6 @@
3 3
4int snd_usb_caiaq_midi_init(struct snd_usb_caiaqdev *dev); 4int snd_usb_caiaq_midi_init(struct snd_usb_caiaqdev *dev);
5void snd_usb_caiaq_midi_handle_input(struct snd_usb_caiaqdev *dev, int port, const char *buf, int len); 5void snd_usb_caiaq_midi_handle_input(struct snd_usb_caiaqdev *dev, int port, const char *buf, int len);
6void snd_usb_caiaq_midi_output_done(struct urb* urb); 6void snd_usb_caiaq_midi_output_done(struct urb *urb);
7 7
8#endif /* CAIAQ_MIDI_H */ 8#endif /* CAIAQ_MIDI_H */
diff --git a/sound/usb/ua101.c b/sound/usb/ua101.c
new file mode 100644
index 000000000000..3d458d3b9962
--- /dev/null
+++ b/sound/usb/ua101.c
@@ -0,0 +1,1387 @@
1/*
2 * Edirol UA-101/UA-1000 driver
3 * Copyright (c) Clemens Ladisch <clemens@ladisch.de>
4 *
5 * This driver is free software: you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License, version 2.
7 *
8 * This driver is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU General Public License for more details.
12 *
13 * You should have received a copy of the GNU General Public License
14 * along with this driver. If not, see <http://www.gnu.org/licenses/>.
15 */
16
17#include <linux/init.h>
18#include <linux/module.h>
19#include <linux/slab.h>
20#include <linux/usb.h>
21#include <linux/usb/audio.h>
22#include <sound/core.h>
23#include <sound/initval.h>
24#include <sound/pcm.h>
25#include <sound/pcm_params.h>
26#include "usbaudio.h"
27
28MODULE_DESCRIPTION("Edirol UA-101/1000 driver");
29MODULE_AUTHOR("Clemens Ladisch <clemens@ladisch.de>");
30MODULE_LICENSE("GPL v2");
31MODULE_SUPPORTED_DEVICE("{{Edirol,UA-101},{Edirol,UA-1000}}");
32
33/*
34 * Should not be lower than the minimum scheduling delay of the host
35 * controller. Some Intel controllers need more than one frame; as long as
36 * that driver doesn't tell us about this, use 1.5 frames just to be sure.
37 */
38#define MIN_QUEUE_LENGTH 12
39/* Somewhat random. */
40#define MAX_QUEUE_LENGTH 30
41/*
42 * This magic value optimizes memory usage efficiency for the UA-101's packet
43 * sizes at all sample rates, taking into account the stupid cache pool sizes
44 * that usb_buffer_alloc() uses.
45 */
46#define DEFAULT_QUEUE_LENGTH 21
47
48#define MAX_PACKET_SIZE 672 /* hardware specific */
49#define MAX_MEMORY_BUFFERS DIV_ROUND_UP(MAX_QUEUE_LENGTH, \
50 PAGE_SIZE / MAX_PACKET_SIZE)
51
52static int index[SNDRV_CARDS] = SNDRV_DEFAULT_IDX;
53static char *id[SNDRV_CARDS] = SNDRV_DEFAULT_STR;
54static int enable[SNDRV_CARDS] = SNDRV_DEFAULT_ENABLE_PNP;
55static unsigned int queue_length = 21;
56
57module_param_array(index, int, NULL, 0444);
58MODULE_PARM_DESC(index, "card index");
59module_param_array(id, charp, NULL, 0444);
60MODULE_PARM_DESC(id, "ID string");
61module_param_array(enable, bool, NULL, 0444);
62MODULE_PARM_DESC(enable, "enable card");
63module_param(queue_length, uint, 0644);
64MODULE_PARM_DESC(queue_length, "USB queue length in microframes, "
65 __stringify(MIN_QUEUE_LENGTH)"-"__stringify(MAX_QUEUE_LENGTH));
66
67enum {
68 INTF_PLAYBACK,
69 INTF_CAPTURE,
70 INTF_MIDI,
71
72 INTF_COUNT
73};
74
75/* bits in struct ua101::states */
76enum {
77 USB_CAPTURE_RUNNING,
78 USB_PLAYBACK_RUNNING,
79 ALSA_CAPTURE_OPEN,
80 ALSA_PLAYBACK_OPEN,
81 ALSA_CAPTURE_RUNNING,
82 ALSA_PLAYBACK_RUNNING,
83 CAPTURE_URB_COMPLETED,
84 PLAYBACK_URB_COMPLETED,
85 DISCONNECTED,
86};
87
88struct ua101 {
89 struct usb_device *dev;
90 struct snd_card *card;
91 struct usb_interface *intf[INTF_COUNT];
92 int card_index;
93 struct snd_pcm *pcm;
94 struct list_head midi_list;
95 u64 format_bit;
96 unsigned int rate;
97 unsigned int packets_per_second;
98 spinlock_t lock;
99 struct mutex mutex;
100 unsigned long states;
101
102 /* FIFO to synchronize playback rate to capture rate */
103 unsigned int rate_feedback_start;
104 unsigned int rate_feedback_count;
105 u8 rate_feedback[MAX_QUEUE_LENGTH];
106
107 struct list_head ready_playback_urbs;
108 struct tasklet_struct playback_tasklet;
109 wait_queue_head_t alsa_capture_wait;
110 wait_queue_head_t rate_feedback_wait;
111 wait_queue_head_t alsa_playback_wait;
112 struct ua101_stream {
113 struct snd_pcm_substream *substream;
114 unsigned int usb_pipe;
115 unsigned int channels;
116 unsigned int frame_bytes;
117 unsigned int max_packet_bytes;
118 unsigned int period_pos;
119 unsigned int buffer_pos;
120 unsigned int queue_length;
121 struct ua101_urb {
122 struct urb urb;
123 struct usb_iso_packet_descriptor iso_frame_desc[1];
124 struct list_head ready_list;
125 } *urbs[MAX_QUEUE_LENGTH];
126 struct {
127 unsigned int size;
128 void *addr;
129 dma_addr_t dma;
130 } buffers[MAX_MEMORY_BUFFERS];
131 } capture, playback;
132};
133
134static DEFINE_MUTEX(devices_mutex);
135static unsigned int devices_used;
136static struct usb_driver ua101_driver;
137
138static void abort_alsa_playback(struct ua101 *ua);
139static void abort_alsa_capture(struct ua101 *ua);
140
141static const char *usb_error_string(int err)
142{
143 switch (err) {
144 case -ENODEV:
145 return "no device";
146 case -ENOENT:
147 return "endpoint not enabled";
148 case -EPIPE:
149 return "endpoint stalled";
150 case -ENOSPC:
151 return "not enough bandwidth";
152 case -ESHUTDOWN:
153 return "device disabled";
154 case -EHOSTUNREACH:
155 return "device suspended";
156 case -EINVAL:
157 case -EAGAIN:
158 case -EFBIG:
159 case -EMSGSIZE:
160 return "internal error";
161 default:
162 return "unknown error";
163 }
164}
165
166static void abort_usb_capture(struct ua101 *ua)
167{
168 if (test_and_clear_bit(USB_CAPTURE_RUNNING, &ua->states)) {
169 wake_up(&ua->alsa_capture_wait);
170 wake_up(&ua->rate_feedback_wait);
171 }
172}
173
174static void abort_usb_playback(struct ua101 *ua)
175{
176 if (test_and_clear_bit(USB_PLAYBACK_RUNNING, &ua->states))
177 wake_up(&ua->alsa_playback_wait);
178}
179
180static void playback_urb_complete(struct urb *usb_urb)
181{
182 struct ua101_urb *urb = (struct ua101_urb *)usb_urb;
183 struct ua101 *ua = urb->urb.context;
184 unsigned long flags;
185
186 if (unlikely(urb->urb.status == -ENOENT || /* unlinked */
187 urb->urb.status == -ENODEV || /* device removed */
188 urb->urb.status == -ECONNRESET || /* unlinked */
189 urb->urb.status == -ESHUTDOWN)) { /* device disabled */
190 abort_usb_playback(ua);
191 abort_alsa_playback(ua);
192 return;
193 }
194
195 if (test_bit(USB_PLAYBACK_RUNNING, &ua->states)) {
196 /* append URB to FIFO */
197 spin_lock_irqsave(&ua->lock, flags);
198 list_add_tail(&urb->ready_list, &ua->ready_playback_urbs);
199 if (ua->rate_feedback_count > 0)
200 tasklet_schedule(&ua->playback_tasklet);
201 ua->playback.substream->runtime->delay -=
202 urb->urb.iso_frame_desc[0].length /
203 ua->playback.frame_bytes;
204 spin_unlock_irqrestore(&ua->lock, flags);
205 }
206}
207
208static void first_playback_urb_complete(struct urb *urb)
209{
210 struct ua101 *ua = urb->context;
211
212 urb->complete = playback_urb_complete;
213 playback_urb_complete(urb);
214
215 set_bit(PLAYBACK_URB_COMPLETED, &ua->states);
216 wake_up(&ua->alsa_playback_wait);
217}
218
219/* copy data from the ALSA ring buffer into the URB buffer */
220static bool copy_playback_data(struct ua101_stream *stream, struct urb *urb,
221 unsigned int frames)
222{
223 struct snd_pcm_runtime *runtime;
224 unsigned int frame_bytes, frames1;
225 const u8 *source;
226
227 runtime = stream->substream->runtime;
228 frame_bytes = stream->frame_bytes;
229 source = runtime->dma_area + stream->buffer_pos * frame_bytes;
230 if (stream->buffer_pos + frames <= runtime->buffer_size) {
231 memcpy(urb->transfer_buffer, source, frames * frame_bytes);
232 } else {
233 /* wrap around at end of ring buffer */
234 frames1 = runtime->buffer_size - stream->buffer_pos;
235 memcpy(urb->transfer_buffer, source, frames1 * frame_bytes);
236 memcpy(urb->transfer_buffer + frames1 * frame_bytes,
237 runtime->dma_area, (frames - frames1) * frame_bytes);
238 }
239
240 stream->buffer_pos += frames;
241 if (stream->buffer_pos >= runtime->buffer_size)
242 stream->buffer_pos -= runtime->buffer_size;
243 stream->period_pos += frames;
244 if (stream->period_pos >= runtime->period_size) {
245 stream->period_pos -= runtime->period_size;
246 return true;
247 }
248 return false;
249}
250
251static inline void add_with_wraparound(struct ua101 *ua,
252 unsigned int *value, unsigned int add)
253{
254 *value += add;
255 if (*value >= ua->playback.queue_length)
256 *value -= ua->playback.queue_length;
257}
258
259static void playback_tasklet(unsigned long data)
260{
261 struct ua101 *ua = (void *)data;
262 unsigned long flags;
263 unsigned int frames;
264 struct ua101_urb *urb;
265 bool do_period_elapsed = false;
266 int err;
267
268 if (unlikely(!test_bit(USB_PLAYBACK_RUNNING, &ua->states)))
269 return;
270
271 /*
272 * Synchronizing the playback rate to the capture rate is done by using
273 * the same sequence of packet sizes for both streams.
274 * Submitting a playback URB therefore requires both a ready URB and
275 * the size of the corresponding capture packet, i.e., both playback
276 * and capture URBs must have been completed. Since the USB core does
277 * not guarantee that playback and capture complete callbacks are
278 * called alternately, we use two FIFOs for packet sizes and read URBs;
279 * submitting playback URBs is possible as long as both FIFOs are
280 * nonempty.
281 */
282 spin_lock_irqsave(&ua->lock, flags);
283 while (ua->rate_feedback_count > 0 &&
284 !list_empty(&ua->ready_playback_urbs)) {
285 /* take packet size out of FIFO */
286 frames = ua->rate_feedback[ua->rate_feedback_start];
287 add_with_wraparound(ua, &ua->rate_feedback_start, 1);
288 ua->rate_feedback_count--;
289
290 /* take URB out of FIFO */
291 urb = list_first_entry(&ua->ready_playback_urbs,
292 struct ua101_urb, ready_list);
293 list_del(&urb->ready_list);
294
295 /* fill packet with data or silence */
296 urb->urb.iso_frame_desc[0].length =
297 frames * ua->playback.frame_bytes;
298 if (test_bit(ALSA_PLAYBACK_RUNNING, &ua->states))
299 do_period_elapsed |= copy_playback_data(&ua->playback,
300 &urb->urb,
301 frames);
302 else
303 memset(urb->urb.transfer_buffer, 0,
304 urb->urb.iso_frame_desc[0].length);
305
306 /* and off you go ... */
307 err = usb_submit_urb(&urb->urb, GFP_ATOMIC);
308 if (unlikely(err < 0)) {
309 spin_unlock_irqrestore(&ua->lock, flags);
310 abort_usb_playback(ua);
311 abort_alsa_playback(ua);
312 dev_err(&ua->dev->dev, "USB request error %d: %s\n",
313 err, usb_error_string(err));
314 return;
315 }
316 ua->playback.substream->runtime->delay += frames;
317 }
318 spin_unlock_irqrestore(&ua->lock, flags);
319 if (do_period_elapsed)
320 snd_pcm_period_elapsed(ua->playback.substream);
321}
322
323/* copy data from the URB buffer into the ALSA ring buffer */
324static bool copy_capture_data(struct ua101_stream *stream, struct urb *urb,
325 unsigned int frames)
326{
327 struct snd_pcm_runtime *runtime;
328 unsigned int frame_bytes, frames1;
329 u8 *dest;
330
331 runtime = stream->substream->runtime;
332 frame_bytes = stream->frame_bytes;
333 dest = runtime->dma_area + stream->buffer_pos * frame_bytes;
334 if (stream->buffer_pos + frames <= runtime->buffer_size) {
335 memcpy(dest, urb->transfer_buffer, frames * frame_bytes);
336 } else {
337 /* wrap around at end of ring buffer */
338 frames1 = runtime->buffer_size - stream->buffer_pos;
339 memcpy(dest, urb->transfer_buffer, frames1 * frame_bytes);
340 memcpy(runtime->dma_area,
341 urb->transfer_buffer + frames1 * frame_bytes,
342 (frames - frames1) * frame_bytes);
343 }
344
345 stream->buffer_pos += frames;
346 if (stream->buffer_pos >= runtime->buffer_size)
347 stream->buffer_pos -= runtime->buffer_size;
348 stream->period_pos += frames;
349 if (stream->period_pos >= runtime->period_size) {
350 stream->period_pos -= runtime->period_size;
351 return true;
352 }
353 return false;
354}
355
356static void capture_urb_complete(struct urb *urb)
357{
358 struct ua101 *ua = urb->context;
359 struct ua101_stream *stream = &ua->capture;
360 unsigned long flags;
361 unsigned int frames, write_ptr;
362 bool do_period_elapsed;
363 int err;
364
365 if (unlikely(urb->status == -ENOENT || /* unlinked */
366 urb->status == -ENODEV || /* device removed */
367 urb->status == -ECONNRESET || /* unlinked */
368 urb->status == -ESHUTDOWN)) /* device disabled */
369 goto stream_stopped;
370
371 if (urb->status >= 0 && urb->iso_frame_desc[0].status >= 0)
372 frames = urb->iso_frame_desc[0].actual_length /
373 stream->frame_bytes;
374 else
375 frames = 0;
376
377 spin_lock_irqsave(&ua->lock, flags);
378
379 if (frames > 0 && test_bit(ALSA_CAPTURE_RUNNING, &ua->states))
380 do_period_elapsed = copy_capture_data(stream, urb, frames);
381 else
382 do_period_elapsed = false;
383
384 if (test_bit(USB_CAPTURE_RUNNING, &ua->states)) {
385 err = usb_submit_urb(urb, GFP_ATOMIC);
386 if (unlikely(err < 0)) {
387 spin_unlock_irqrestore(&ua->lock, flags);
388 dev_err(&ua->dev->dev, "USB request error %d: %s\n",
389 err, usb_error_string(err));
390 goto stream_stopped;
391 }
392
393 /* append packet size to FIFO */
394 write_ptr = ua->rate_feedback_start;
395 add_with_wraparound(ua, &write_ptr, ua->rate_feedback_count);
396 ua->rate_feedback[write_ptr] = frames;
397 if (ua->rate_feedback_count < ua->playback.queue_length) {
398 ua->rate_feedback_count++;
399 if (ua->rate_feedback_count ==
400 ua->playback.queue_length)
401 wake_up(&ua->rate_feedback_wait);
402 } else {
403 /*
404 * Ring buffer overflow; this happens when the playback
405 * stream is not running. Throw away the oldest entry,
406 * so that the playback stream, when it starts, sees
407 * the most recent packet sizes.
408 */
409 add_with_wraparound(ua, &ua->rate_feedback_start, 1);
410 }
411 if (test_bit(USB_PLAYBACK_RUNNING, &ua->states) &&
412 !list_empty(&ua->ready_playback_urbs))
413 tasklet_schedule(&ua->playback_tasklet);
414 }
415
416 spin_unlock_irqrestore(&ua->lock, flags);
417
418 if (do_period_elapsed)
419 snd_pcm_period_elapsed(stream->substream);
420
421 return;
422
423stream_stopped:
424 abort_usb_playback(ua);
425 abort_usb_capture(ua);
426 abort_alsa_playback(ua);
427 abort_alsa_capture(ua);
428}
429
430static void first_capture_urb_complete(struct urb *urb)
431{
432 struct ua101 *ua = urb->context;
433
434 urb->complete = capture_urb_complete;
435 capture_urb_complete(urb);
436
437 set_bit(CAPTURE_URB_COMPLETED, &ua->states);
438 wake_up(&ua->alsa_capture_wait);
439}
440
441static int submit_stream_urbs(struct ua101 *ua, struct ua101_stream *stream)
442{
443 unsigned int i;
444
445 for (i = 0; i < stream->queue_length; ++i) {
446 int err = usb_submit_urb(&stream->urbs[i]->urb, GFP_KERNEL);
447 if (err < 0) {
448 dev_err(&ua->dev->dev, "USB request error %d: %s\n",
449 err, usb_error_string(err));
450 return err;
451 }
452 }
453 return 0;
454}
455
456static void kill_stream_urbs(struct ua101_stream *stream)
457{
458 unsigned int i;
459
460 for (i = 0; i < stream->queue_length; ++i)
461 usb_kill_urb(&stream->urbs[i]->urb);
462}
463
464static int enable_iso_interface(struct ua101 *ua, unsigned int intf_index)
465{
466 struct usb_host_interface *alts;
467
468 alts = ua->intf[intf_index]->cur_altsetting;
469 if (alts->desc.bAlternateSetting != 1) {
470 int err = usb_set_interface(ua->dev,
471 alts->desc.bInterfaceNumber, 1);
472 if (err < 0) {
473 dev_err(&ua->dev->dev,
474 "cannot initialize interface; error %d: %s\n",
475 err, usb_error_string(err));
476 return err;
477 }
478 }
479 return 0;
480}
481
482static void disable_iso_interface(struct ua101 *ua, unsigned int intf_index)
483{
484 struct usb_host_interface *alts;
485
486 alts = ua->intf[intf_index]->cur_altsetting;
487 if (alts->desc.bAlternateSetting != 0) {
488 int err = usb_set_interface(ua->dev,
489 alts->desc.bInterfaceNumber, 0);
490 if (err < 0 && !test_bit(DISCONNECTED, &ua->states))
491 dev_warn(&ua->dev->dev,
492 "interface reset failed; error %d: %s\n",
493 err, usb_error_string(err));
494 }
495}
496
497static void stop_usb_capture(struct ua101 *ua)
498{
499 clear_bit(USB_CAPTURE_RUNNING, &ua->states);
500
501 kill_stream_urbs(&ua->capture);
502
503 disable_iso_interface(ua, INTF_CAPTURE);
504}
505
506static int start_usb_capture(struct ua101 *ua)
507{
508 int err;
509
510 if (test_bit(DISCONNECTED, &ua->states))
511 return -ENODEV;
512
513 if (test_bit(USB_CAPTURE_RUNNING, &ua->states))
514 return 0;
515
516 kill_stream_urbs(&ua->capture);
517
518 err = enable_iso_interface(ua, INTF_CAPTURE);
519 if (err < 0)
520 return err;
521
522 clear_bit(CAPTURE_URB_COMPLETED, &ua->states);
523 ua->capture.urbs[0]->urb.complete = first_capture_urb_complete;
524 ua->rate_feedback_start = 0;
525 ua->rate_feedback_count = 0;
526
527 set_bit(USB_CAPTURE_RUNNING, &ua->states);
528 err = submit_stream_urbs(ua, &ua->capture);
529 if (err < 0)
530 stop_usb_capture(ua);
531 return err;
532}
533
534static void stop_usb_playback(struct ua101 *ua)
535{
536 clear_bit(USB_PLAYBACK_RUNNING, &ua->states);
537
538 kill_stream_urbs(&ua->playback);
539
540 tasklet_kill(&ua->playback_tasklet);
541
542 disable_iso_interface(ua, INTF_PLAYBACK);
543}
544
545static int start_usb_playback(struct ua101 *ua)
546{
547 unsigned int i, frames;
548 struct urb *urb;
549 int err = 0;
550
551 if (test_bit(DISCONNECTED, &ua->states))
552 return -ENODEV;
553
554 if (test_bit(USB_PLAYBACK_RUNNING, &ua->states))
555 return 0;
556
557 kill_stream_urbs(&ua->playback);
558 tasklet_kill(&ua->playback_tasklet);
559
560 err = enable_iso_interface(ua, INTF_PLAYBACK);
561 if (err < 0)
562 return err;
563
564 clear_bit(PLAYBACK_URB_COMPLETED, &ua->states);
565 ua->playback.urbs[0]->urb.complete =
566 first_playback_urb_complete;
567 spin_lock_irq(&ua->lock);
568 INIT_LIST_HEAD(&ua->ready_playback_urbs);
569 spin_unlock_irq(&ua->lock);
570
571 /*
572 * We submit the initial URBs all at once, so we have to wait for the
573 * packet size FIFO to be full.
574 */
575 wait_event(ua->rate_feedback_wait,
576 ua->rate_feedback_count >= ua->playback.queue_length ||
577 !test_bit(USB_CAPTURE_RUNNING, &ua->states) ||
578 test_bit(DISCONNECTED, &ua->states));
579 if (test_bit(DISCONNECTED, &ua->states)) {
580 stop_usb_playback(ua);
581 return -ENODEV;
582 }
583 if (!test_bit(USB_CAPTURE_RUNNING, &ua->states)) {
584 stop_usb_playback(ua);
585 return -EIO;
586 }
587
588 for (i = 0; i < ua->playback.queue_length; ++i) {
589 /* all initial URBs contain silence */
590 spin_lock_irq(&ua->lock);
591 frames = ua->rate_feedback[ua->rate_feedback_start];
592 add_with_wraparound(ua, &ua->rate_feedback_start, 1);
593 ua->rate_feedback_count--;
594 spin_unlock_irq(&ua->lock);
595 urb = &ua->playback.urbs[i]->urb;
596 urb->iso_frame_desc[0].length =
597 frames * ua->playback.frame_bytes;
598 memset(urb->transfer_buffer, 0,
599 urb->iso_frame_desc[0].length);
600 }
601
602 set_bit(USB_PLAYBACK_RUNNING, &ua->states);
603 err = submit_stream_urbs(ua, &ua->playback);
604 if (err < 0)
605 stop_usb_playback(ua);
606 return err;
607}
608
609static void abort_alsa_capture(struct ua101 *ua)
610{
611 if (test_bit(ALSA_CAPTURE_RUNNING, &ua->states))
612 snd_pcm_stop(ua->capture.substream, SNDRV_PCM_STATE_XRUN);
613}
614
615static void abort_alsa_playback(struct ua101 *ua)
616{
617 if (test_bit(ALSA_PLAYBACK_RUNNING, &ua->states))
618 snd_pcm_stop(ua->playback.substream, SNDRV_PCM_STATE_XRUN);
619}
620
621static int set_stream_hw(struct ua101 *ua, struct snd_pcm_substream *substream,
622 unsigned int channels)
623{
624 int err;
625
626 substream->runtime->hw.info =
627 SNDRV_PCM_INFO_MMAP |
628 SNDRV_PCM_INFO_MMAP_VALID |
629 SNDRV_PCM_INFO_BATCH |
630 SNDRV_PCM_INFO_INTERLEAVED |
631 SNDRV_PCM_INFO_BLOCK_TRANSFER |
632 SNDRV_PCM_INFO_FIFO_IN_FRAMES;
633 substream->runtime->hw.formats = ua->format_bit;
634 substream->runtime->hw.rates = snd_pcm_rate_to_rate_bit(ua->rate);
635 substream->runtime->hw.rate_min = ua->rate;
636 substream->runtime->hw.rate_max = ua->rate;
637 substream->runtime->hw.channels_min = channels;
638 substream->runtime->hw.channels_max = channels;
639 substream->runtime->hw.buffer_bytes_max = 45000 * 1024;
640 substream->runtime->hw.period_bytes_min = 1;
641 substream->runtime->hw.period_bytes_max = UINT_MAX;
642 substream->runtime->hw.periods_min = 2;
643 substream->runtime->hw.periods_max = UINT_MAX;
644 err = snd_pcm_hw_constraint_minmax(substream->runtime,
645 SNDRV_PCM_HW_PARAM_PERIOD_TIME,
646 1500000 / ua->packets_per_second,
647 8192000);
648 if (err < 0)
649 return err;
650 err = snd_pcm_hw_constraint_msbits(substream->runtime, 0, 32, 24);
651 return err;
652}
653
654static int capture_pcm_open(struct snd_pcm_substream *substream)
655{
656 struct ua101 *ua = substream->private_data;
657 int err;
658
659 ua->capture.substream = substream;
660 err = set_stream_hw(ua, substream, ua->capture.channels);
661 if (err < 0)
662 return err;
663 substream->runtime->hw.fifo_size =
664 DIV_ROUND_CLOSEST(ua->rate, ua->packets_per_second);
665 substream->runtime->delay = substream->runtime->hw.fifo_size;
666
667 mutex_lock(&ua->mutex);
668 err = start_usb_capture(ua);
669 if (err >= 0)
670 set_bit(ALSA_CAPTURE_OPEN, &ua->states);
671 mutex_unlock(&ua->mutex);
672 return err;
673}
674
675static int playback_pcm_open(struct snd_pcm_substream *substream)
676{
677 struct ua101 *ua = substream->private_data;
678 int err;
679
680 ua->playback.substream = substream;
681 err = set_stream_hw(ua, substream, ua->playback.channels);
682 if (err < 0)
683 return err;
684 substream->runtime->hw.fifo_size =
685 DIV_ROUND_CLOSEST(ua->rate * ua->playback.queue_length,
686 ua->packets_per_second);
687
688 mutex_lock(&ua->mutex);
689 err = start_usb_capture(ua);
690 if (err < 0)
691 goto error;
692 err = start_usb_playback(ua);
693 if (err < 0) {
694 if (!test_bit(ALSA_CAPTURE_OPEN, &ua->states))
695 stop_usb_capture(ua);
696 goto error;
697 }
698 set_bit(ALSA_PLAYBACK_OPEN, &ua->states);
699error:
700 mutex_unlock(&ua->mutex);
701 return err;
702}
703
704static int capture_pcm_close(struct snd_pcm_substream *substream)
705{
706 struct ua101 *ua = substream->private_data;
707
708 mutex_lock(&ua->mutex);
709 clear_bit(ALSA_CAPTURE_OPEN, &ua->states);
710 if (!test_bit(ALSA_PLAYBACK_OPEN, &ua->states))
711 stop_usb_capture(ua);
712 mutex_unlock(&ua->mutex);
713 return 0;
714}
715
716static int playback_pcm_close(struct snd_pcm_substream *substream)
717{
718 struct ua101 *ua = substream->private_data;
719
720 mutex_lock(&ua->mutex);
721 stop_usb_playback(ua);
722 clear_bit(ALSA_PLAYBACK_OPEN, &ua->states);
723 if (!test_bit(ALSA_CAPTURE_OPEN, &ua->states))
724 stop_usb_capture(ua);
725 mutex_unlock(&ua->mutex);
726 return 0;
727}
728
729static int capture_pcm_hw_params(struct snd_pcm_substream *substream,
730 struct snd_pcm_hw_params *hw_params)
731{
732 struct ua101 *ua = substream->private_data;
733 int err;
734
735 mutex_lock(&ua->mutex);
736 err = start_usb_capture(ua);
737 mutex_unlock(&ua->mutex);
738 if (err < 0)
739 return err;
740
741 return snd_pcm_lib_alloc_vmalloc_buffer(substream,
742 params_buffer_bytes(hw_params));
743}
744
745static int playback_pcm_hw_params(struct snd_pcm_substream *substream,
746 struct snd_pcm_hw_params *hw_params)
747{
748 struct ua101 *ua = substream->private_data;
749 int err;
750
751 mutex_lock(&ua->mutex);
752 err = start_usb_capture(ua);
753 if (err >= 0)
754 err = start_usb_playback(ua);
755 mutex_unlock(&ua->mutex);
756 if (err < 0)
757 return err;
758
759 return snd_pcm_lib_alloc_vmalloc_buffer(substream,
760 params_buffer_bytes(hw_params));
761}
762
763static int ua101_pcm_hw_free(struct snd_pcm_substream *substream)
764{
765 return snd_pcm_lib_free_vmalloc_buffer(substream);
766}
767
768static int capture_pcm_prepare(struct snd_pcm_substream *substream)
769{
770 struct ua101 *ua = substream->private_data;
771 int err;
772
773 mutex_lock(&ua->mutex);
774 err = start_usb_capture(ua);
775 mutex_unlock(&ua->mutex);
776 if (err < 0)
777 return err;
778
779 /*
780 * The EHCI driver schedules the first packet of an iso stream at 10 ms
781 * in the future, i.e., no data is actually captured for that long.
782 * Take the wait here so that the stream is known to be actually
783 * running when the start trigger has been called.
784 */
785 wait_event(ua->alsa_capture_wait,
786 test_bit(CAPTURE_URB_COMPLETED, &ua->states) ||
787 !test_bit(USB_CAPTURE_RUNNING, &ua->states));
788 if (test_bit(DISCONNECTED, &ua->states))
789 return -ENODEV;
790 if (!test_bit(USB_CAPTURE_RUNNING, &ua->states))
791 return -EIO;
792
793 ua->capture.period_pos = 0;
794 ua->capture.buffer_pos = 0;
795 return 0;
796}
797
798static int playback_pcm_prepare(struct snd_pcm_substream *substream)
799{
800 struct ua101 *ua = substream->private_data;
801 int err;
802
803 mutex_lock(&ua->mutex);
804 err = start_usb_capture(ua);
805 if (err >= 0)
806 err = start_usb_playback(ua);
807 mutex_unlock(&ua->mutex);
808 if (err < 0)
809 return err;
810
811 /* see the comment in capture_pcm_prepare() */
812 wait_event(ua->alsa_playback_wait,
813 test_bit(PLAYBACK_URB_COMPLETED, &ua->states) ||
814 !test_bit(USB_PLAYBACK_RUNNING, &ua->states));
815 if (test_bit(DISCONNECTED, &ua->states))
816 return -ENODEV;
817 if (!test_bit(USB_PLAYBACK_RUNNING, &ua->states))
818 return -EIO;
819
820 substream->runtime->delay = 0;
821 ua->playback.period_pos = 0;
822 ua->playback.buffer_pos = 0;
823 return 0;
824}
825
826static int capture_pcm_trigger(struct snd_pcm_substream *substream, int cmd)
827{
828 struct ua101 *ua = substream->private_data;
829
830 switch (cmd) {
831 case SNDRV_PCM_TRIGGER_START:
832 if (!test_bit(USB_CAPTURE_RUNNING, &ua->states))
833 return -EIO;
834 set_bit(ALSA_CAPTURE_RUNNING, &ua->states);
835 return 0;
836 case SNDRV_PCM_TRIGGER_STOP:
837 clear_bit(ALSA_CAPTURE_RUNNING, &ua->states);
838 return 0;
839 default:
840 return -EINVAL;
841 }
842}
843
844static int playback_pcm_trigger(struct snd_pcm_substream *substream, int cmd)
845{
846 struct ua101 *ua = substream->private_data;
847
848 switch (cmd) {
849 case SNDRV_PCM_TRIGGER_START:
850 if (!test_bit(USB_PLAYBACK_RUNNING, &ua->states))
851 return -EIO;
852 set_bit(ALSA_PLAYBACK_RUNNING, &ua->states);
853 return 0;
854 case SNDRV_PCM_TRIGGER_STOP:
855 clear_bit(ALSA_PLAYBACK_RUNNING, &ua->states);
856 return 0;
857 default:
858 return -EINVAL;
859 }
860}
861
862static inline snd_pcm_uframes_t ua101_pcm_pointer(struct ua101 *ua,
863 struct ua101_stream *stream)
864{
865 unsigned long flags;
866 unsigned int pos;
867
868 spin_lock_irqsave(&ua->lock, flags);
869 pos = stream->buffer_pos;
870 spin_unlock_irqrestore(&ua->lock, flags);
871 return pos;
872}
873
874static snd_pcm_uframes_t capture_pcm_pointer(struct snd_pcm_substream *subs)
875{
876 struct ua101 *ua = subs->private_data;
877
878 return ua101_pcm_pointer(ua, &ua->capture);
879}
880
881static snd_pcm_uframes_t playback_pcm_pointer(struct snd_pcm_substream *subs)
882{
883 struct ua101 *ua = subs->private_data;
884
885 return ua101_pcm_pointer(ua, &ua->playback);
886}
887
888static struct snd_pcm_ops capture_pcm_ops = {
889 .open = capture_pcm_open,
890 .close = capture_pcm_close,
891 .ioctl = snd_pcm_lib_ioctl,
892 .hw_params = capture_pcm_hw_params,
893 .hw_free = ua101_pcm_hw_free,
894 .prepare = capture_pcm_prepare,
895 .trigger = capture_pcm_trigger,
896 .pointer = capture_pcm_pointer,
897 .page = snd_pcm_lib_get_vmalloc_page,
898 .mmap = snd_pcm_lib_mmap_vmalloc,
899};
900
901static struct snd_pcm_ops playback_pcm_ops = {
902 .open = playback_pcm_open,
903 .close = playback_pcm_close,
904 .ioctl = snd_pcm_lib_ioctl,
905 .hw_params = playback_pcm_hw_params,
906 .hw_free = ua101_pcm_hw_free,
907 .prepare = playback_pcm_prepare,
908 .trigger = playback_pcm_trigger,
909 .pointer = playback_pcm_pointer,
910 .page = snd_pcm_lib_get_vmalloc_page,
911 .mmap = snd_pcm_lib_mmap_vmalloc,
912};
913
914static const struct uac_format_type_i_discrete_descriptor *
915find_format_descriptor(struct usb_interface *interface)
916{
917 struct usb_host_interface *alt;
918 u8 *extra;
919 int extralen;
920
921 if (interface->num_altsetting != 2) {
922 dev_err(&interface->dev, "invalid num_altsetting\n");
923 return NULL;
924 }
925
926 alt = &interface->altsetting[0];
927 if (alt->desc.bNumEndpoints != 0) {
928 dev_err(&interface->dev, "invalid bNumEndpoints\n");
929 return NULL;
930 }
931
932 alt = &interface->altsetting[1];
933 if (alt->desc.bNumEndpoints != 1) {
934 dev_err(&interface->dev, "invalid bNumEndpoints\n");
935 return NULL;
936 }
937
938 extra = alt->extra;
939 extralen = alt->extralen;
940 while (extralen >= sizeof(struct usb_descriptor_header)) {
941 struct uac_format_type_i_discrete_descriptor *desc;
942
943 desc = (struct uac_format_type_i_discrete_descriptor *)extra;
944 if (desc->bLength > extralen) {
945 dev_err(&interface->dev, "descriptor overflow\n");
946 return NULL;
947 }
948 if (desc->bLength == UAC_FORMAT_TYPE_I_DISCRETE_DESC_SIZE(1) &&
949 desc->bDescriptorType == USB_DT_CS_INTERFACE &&
950 desc->bDescriptorSubtype == UAC_FORMAT_TYPE) {
951 if (desc->bFormatType != UAC_FORMAT_TYPE_I_PCM ||
952 desc->bSamFreqType != 1) {
953 dev_err(&interface->dev,
954 "invalid format type\n");
955 return NULL;
956 }
957 return desc;
958 }
959 extralen -= desc->bLength;
960 extra += desc->bLength;
961 }
962 dev_err(&interface->dev, "sample format descriptor not found\n");
963 return NULL;
964}
965
966static int detect_usb_format(struct ua101 *ua)
967{
968 const struct uac_format_type_i_discrete_descriptor *fmt_capture;
969 const struct uac_format_type_i_discrete_descriptor *fmt_playback;
970 const struct usb_endpoint_descriptor *epd;
971 unsigned int rate2;
972
973 fmt_capture = find_format_descriptor(ua->intf[INTF_CAPTURE]);
974 fmt_playback = find_format_descriptor(ua->intf[INTF_PLAYBACK]);
975 if (!fmt_capture || !fmt_playback)
976 return -ENXIO;
977
978 switch (fmt_capture->bSubframeSize) {
979 case 3:
980 ua->format_bit = SNDRV_PCM_FMTBIT_S24_3LE;
981 break;
982 case 4:
983 ua->format_bit = SNDRV_PCM_FMTBIT_S32_LE;
984 break;
985 default:
986 dev_err(&ua->dev->dev, "sample width is not 24 or 32 bits\n");
987 return -ENXIO;
988 }
989 if (fmt_capture->bSubframeSize != fmt_playback->bSubframeSize) {
990 dev_err(&ua->dev->dev,
991 "playback/capture sample widths do not match\n");
992 return -ENXIO;
993 }
994
995 if (fmt_capture->bBitResolution != 24 ||
996 fmt_playback->bBitResolution != 24) {
997 dev_err(&ua->dev->dev, "sample width is not 24 bits\n");
998 return -ENXIO;
999 }
1000
1001 ua->rate = combine_triple(fmt_capture->tSamFreq[0]);
1002 rate2 = combine_triple(fmt_playback->tSamFreq[0]);
1003 if (ua->rate != rate2) {
1004 dev_err(&ua->dev->dev,
1005 "playback/capture rates do not match: %u/%u\n",
1006 rate2, ua->rate);
1007 return -ENXIO;
1008 }
1009
1010 switch (ua->dev->speed) {
1011 case USB_SPEED_FULL:
1012 ua->packets_per_second = 1000;
1013 break;
1014 case USB_SPEED_HIGH:
1015 ua->packets_per_second = 8000;
1016 break;
1017 default:
1018 dev_err(&ua->dev->dev, "unknown device speed\n");
1019 return -ENXIO;
1020 }
1021
1022 ua->capture.channels = fmt_capture->bNrChannels;
1023 ua->playback.channels = fmt_playback->bNrChannels;
1024 ua->capture.frame_bytes =
1025 fmt_capture->bSubframeSize * ua->capture.channels;
1026 ua->playback.frame_bytes =
1027 fmt_playback->bSubframeSize * ua->playback.channels;
1028
1029 epd = &ua->intf[INTF_CAPTURE]->altsetting[1].endpoint[0].desc;
1030 if (!usb_endpoint_is_isoc_in(epd)) {
1031 dev_err(&ua->dev->dev, "invalid capture endpoint\n");
1032 return -ENXIO;
1033 }
1034 ua->capture.usb_pipe = usb_rcvisocpipe(ua->dev, usb_endpoint_num(epd));
1035 ua->capture.max_packet_bytes = le16_to_cpu(epd->wMaxPacketSize);
1036
1037 epd = &ua->intf[INTF_PLAYBACK]->altsetting[1].endpoint[0].desc;
1038 if (!usb_endpoint_is_isoc_out(epd)) {
1039 dev_err(&ua->dev->dev, "invalid playback endpoint\n");
1040 return -ENXIO;
1041 }
1042 ua->playback.usb_pipe = usb_sndisocpipe(ua->dev, usb_endpoint_num(epd));
1043 ua->playback.max_packet_bytes = le16_to_cpu(epd->wMaxPacketSize);
1044 return 0;
1045}
1046
1047static int alloc_stream_buffers(struct ua101 *ua, struct ua101_stream *stream)
1048{
1049 unsigned int remaining_packets, packets, packets_per_page, i;
1050 size_t size;
1051
1052 stream->queue_length = queue_length;
1053 stream->queue_length = max(stream->queue_length,
1054 (unsigned int)MIN_QUEUE_LENGTH);
1055 stream->queue_length = min(stream->queue_length,
1056 (unsigned int)MAX_QUEUE_LENGTH);
1057
1058 /*
1059 * The cache pool sizes used by usb_buffer_alloc() (128, 512, 2048) are
1060 * quite bad when used with the packet sizes of this device (e.g. 280,
1061 * 520, 624). Therefore, we allocate and subdivide entire pages, using
1062 * a smaller buffer only for the last chunk.
1063 */
1064 remaining_packets = stream->queue_length;
1065 packets_per_page = PAGE_SIZE / stream->max_packet_bytes;
1066 for (i = 0; i < ARRAY_SIZE(stream->buffers); ++i) {
1067 packets = min(remaining_packets, packets_per_page);
1068 size = packets * stream->max_packet_bytes;
1069 stream->buffers[i].addr =
1070 usb_buffer_alloc(ua->dev, size, GFP_KERNEL,
1071 &stream->buffers[i].dma);
1072 if (!stream->buffers[i].addr)
1073 return -ENOMEM;
1074 stream->buffers[i].size = size;
1075 remaining_packets -= packets;
1076 if (!remaining_packets)
1077 break;
1078 }
1079 if (remaining_packets) {
1080 dev_err(&ua->dev->dev, "too many packets\n");
1081 return -ENXIO;
1082 }
1083 return 0;
1084}
1085
1086static void free_stream_buffers(struct ua101 *ua, struct ua101_stream *stream)
1087{
1088 unsigned int i;
1089
1090 for (i = 0; i < ARRAY_SIZE(stream->buffers); ++i)
1091 usb_buffer_free(ua->dev,
1092 stream->buffers[i].size,
1093 stream->buffers[i].addr,
1094 stream->buffers[i].dma);
1095}
1096
1097static int alloc_stream_urbs(struct ua101 *ua, struct ua101_stream *stream,
1098 void (*urb_complete)(struct urb *))
1099{
1100 unsigned max_packet_size = stream->max_packet_bytes;
1101 struct ua101_urb *urb;
1102 unsigned int b, u = 0;
1103
1104 for (b = 0; b < ARRAY_SIZE(stream->buffers); ++b) {
1105 unsigned int size = stream->buffers[b].size;
1106 u8 *addr = stream->buffers[b].addr;
1107 dma_addr_t dma = stream->buffers[b].dma;
1108
1109 while (size >= max_packet_size) {
1110 if (u >= stream->queue_length)
1111 goto bufsize_error;
1112 urb = kmalloc(sizeof(*urb), GFP_KERNEL);
1113 if (!urb)
1114 return -ENOMEM;
1115 usb_init_urb(&urb->urb);
1116 urb->urb.dev = ua->dev;
1117 urb->urb.pipe = stream->usb_pipe;
1118 urb->urb.transfer_flags = URB_ISO_ASAP |
1119 URB_NO_TRANSFER_DMA_MAP;
1120 urb->urb.transfer_buffer = addr;
1121 urb->urb.transfer_dma = dma;
1122 urb->urb.transfer_buffer_length = max_packet_size;
1123 urb->urb.number_of_packets = 1;
1124 urb->urb.interval = 1;
1125 urb->urb.context = ua;
1126 urb->urb.complete = urb_complete;
1127 urb->urb.iso_frame_desc[0].offset = 0;
1128 urb->urb.iso_frame_desc[0].length = max_packet_size;
1129 stream->urbs[u++] = urb;
1130 size -= max_packet_size;
1131 addr += max_packet_size;
1132 dma += max_packet_size;
1133 }
1134 }
1135 if (u == stream->queue_length)
1136 return 0;
1137bufsize_error:
1138 dev_err(&ua->dev->dev, "internal buffer size error\n");
1139 return -ENXIO;
1140}
1141
1142static void free_stream_urbs(struct ua101_stream *stream)
1143{
1144 unsigned int i;
1145
1146 for (i = 0; i < stream->queue_length; ++i)
1147 kfree(stream->urbs[i]);
1148}
1149
1150static void free_usb_related_resources(struct ua101 *ua,
1151 struct usb_interface *interface)
1152{
1153 unsigned int i;
1154
1155 free_stream_urbs(&ua->capture);
1156 free_stream_urbs(&ua->playback);
1157 free_stream_buffers(ua, &ua->capture);
1158 free_stream_buffers(ua, &ua->playback);
1159
1160 for (i = 0; i < ARRAY_SIZE(ua->intf); ++i)
1161 if (ua->intf[i]) {
1162 usb_set_intfdata(ua->intf[i], NULL);
1163 if (ua->intf[i] != interface)
1164 usb_driver_release_interface(&ua101_driver,
1165 ua->intf[i]);
1166 }
1167}
1168
1169static void ua101_card_free(struct snd_card *card)
1170{
1171 struct ua101 *ua = card->private_data;
1172
1173 mutex_destroy(&ua->mutex);
1174}
1175
1176static int ua101_probe(struct usb_interface *interface,
1177 const struct usb_device_id *usb_id)
1178{
1179 static const struct snd_usb_midi_endpoint_info midi_ep = {
1180 .out_cables = 0x0001,
1181 .in_cables = 0x0001
1182 };
1183 static const struct snd_usb_audio_quirk midi_quirk = {
1184 .type = QUIRK_MIDI_FIXED_ENDPOINT,
1185 .data = &midi_ep
1186 };
1187 static const int intf_numbers[2][3] = {
1188 { /* UA-101 */
1189 [INTF_PLAYBACK] = 0,
1190 [INTF_CAPTURE] = 1,
1191 [INTF_MIDI] = 2,
1192 },
1193 { /* UA-1000 */
1194 [INTF_CAPTURE] = 1,
1195 [INTF_PLAYBACK] = 2,
1196 [INTF_MIDI] = 3,
1197 },
1198 };
1199 struct snd_card *card;
1200 struct ua101 *ua;
1201 unsigned int card_index, i;
1202 int is_ua1000;
1203 const char *name;
1204 char usb_path[32];
1205 int err;
1206
1207 is_ua1000 = usb_id->idProduct == 0x0044;
1208
1209 if (interface->altsetting->desc.bInterfaceNumber !=
1210 intf_numbers[is_ua1000][0])
1211 return -ENODEV;
1212
1213 mutex_lock(&devices_mutex);
1214
1215 for (card_index = 0; card_index < SNDRV_CARDS; ++card_index)
1216 if (enable[card_index] && !(devices_used & (1 << card_index)))
1217 break;
1218 if (card_index >= SNDRV_CARDS) {
1219 mutex_unlock(&devices_mutex);
1220 return -ENOENT;
1221 }
1222 err = snd_card_create(index[card_index], id[card_index], THIS_MODULE,
1223 sizeof(*ua), &card);
1224 if (err < 0) {
1225 mutex_unlock(&devices_mutex);
1226 return err;
1227 }
1228 card->private_free = ua101_card_free;
1229 ua = card->private_data;
1230 ua->dev = interface_to_usbdev(interface);
1231 ua->card = card;
1232 ua->card_index = card_index;
1233 INIT_LIST_HEAD(&ua->midi_list);
1234 spin_lock_init(&ua->lock);
1235 mutex_init(&ua->mutex);
1236 INIT_LIST_HEAD(&ua->ready_playback_urbs);
1237 tasklet_init(&ua->playback_tasklet,
1238 playback_tasklet, (unsigned long)ua);
1239 init_waitqueue_head(&ua->alsa_capture_wait);
1240 init_waitqueue_head(&ua->rate_feedback_wait);
1241 init_waitqueue_head(&ua->alsa_playback_wait);
1242
1243 ua->intf[0] = interface;
1244 for (i = 1; i < ARRAY_SIZE(ua->intf); ++i) {
1245 ua->intf[i] = usb_ifnum_to_if(ua->dev,
1246 intf_numbers[is_ua1000][i]);
1247 if (!ua->intf[i]) {
1248 dev_err(&ua->dev->dev, "interface %u not found\n",
1249 intf_numbers[is_ua1000][i]);
1250 err = -ENXIO;
1251 goto probe_error;
1252 }
1253 err = usb_driver_claim_interface(&ua101_driver,
1254 ua->intf[i], ua);
1255 if (err < 0) {
1256 ua->intf[i] = NULL;
1257 err = -EBUSY;
1258 goto probe_error;
1259 }
1260 }
1261
1262 snd_card_set_dev(card, &interface->dev);
1263
1264 err = detect_usb_format(ua);
1265 if (err < 0)
1266 goto probe_error;
1267
1268 name = usb_id->idProduct == 0x0044 ? "UA-1000" : "UA-101";
1269 strcpy(card->driver, "UA-101");
1270 strcpy(card->shortname, name);
1271 usb_make_path(ua->dev, usb_path, sizeof(usb_path));
1272 snprintf(ua->card->longname, sizeof(ua->card->longname),
1273 "EDIROL %s (serial %s), %u Hz at %s, %s speed", name,
1274 ua->dev->serial ? ua->dev->serial : "?", ua->rate, usb_path,
1275 ua->dev->speed == USB_SPEED_HIGH ? "high" : "full");
1276
1277 err = alloc_stream_buffers(ua, &ua->capture);
1278 if (err < 0)
1279 goto probe_error;
1280 err = alloc_stream_buffers(ua, &ua->playback);
1281 if (err < 0)
1282 goto probe_error;
1283
1284 err = alloc_stream_urbs(ua, &ua->capture, capture_urb_complete);
1285 if (err < 0)
1286 goto probe_error;
1287 err = alloc_stream_urbs(ua, &ua->playback, playback_urb_complete);
1288 if (err < 0)
1289 goto probe_error;
1290
1291 err = snd_pcm_new(card, name, 0, 1, 1, &ua->pcm);
1292 if (err < 0)
1293 goto probe_error;
1294 ua->pcm->private_data = ua;
1295 strcpy(ua->pcm->name, name);
1296 snd_pcm_set_ops(ua->pcm, SNDRV_PCM_STREAM_PLAYBACK, &playback_pcm_ops);
1297 snd_pcm_set_ops(ua->pcm, SNDRV_PCM_STREAM_CAPTURE, &capture_pcm_ops);
1298
1299 err = snd_usbmidi_create(card, ua->intf[INTF_MIDI],
1300 &ua->midi_list, &midi_quirk);
1301 if (err < 0)
1302 goto probe_error;
1303
1304 err = snd_card_register(card);
1305 if (err < 0)
1306 goto probe_error;
1307
1308 usb_set_intfdata(interface, ua);
1309 devices_used |= 1 << card_index;
1310
1311 mutex_unlock(&devices_mutex);
1312 return 0;
1313
1314probe_error:
1315 free_usb_related_resources(ua, interface);
1316 snd_card_free(card);
1317 mutex_unlock(&devices_mutex);
1318 return err;
1319}
1320
1321static void ua101_disconnect(struct usb_interface *interface)
1322{
1323 struct ua101 *ua = usb_get_intfdata(interface);
1324 struct list_head *midi;
1325
1326 if (!ua)
1327 return;
1328
1329 mutex_lock(&devices_mutex);
1330
1331 set_bit(DISCONNECTED, &ua->states);
1332 wake_up(&ua->rate_feedback_wait);
1333
1334 /* make sure that userspace cannot create new requests */
1335 snd_card_disconnect(ua->card);
1336
1337 /* make sure that there are no pending USB requests */
1338 __list_for_each(midi, &ua->midi_list)
1339 snd_usbmidi_disconnect(midi);
1340 abort_alsa_playback(ua);
1341 abort_alsa_capture(ua);
1342 mutex_lock(&ua->mutex);
1343 stop_usb_playback(ua);
1344 stop_usb_capture(ua);
1345 mutex_unlock(&ua->mutex);
1346
1347 free_usb_related_resources(ua, interface);
1348
1349 devices_used &= ~(1 << ua->card_index);
1350
1351 snd_card_free_when_closed(ua->card);
1352
1353 mutex_unlock(&devices_mutex);
1354}
1355
1356static struct usb_device_id ua101_ids[] = {
1357 { USB_DEVICE(0x0582, 0x0044) }, /* UA-1000 high speed */
1358 { USB_DEVICE(0x0582, 0x007d) }, /* UA-101 high speed */
1359 { USB_DEVICE(0x0582, 0x008d) }, /* UA-101 full speed */
1360 { }
1361};
1362MODULE_DEVICE_TABLE(usb, ua101_ids);
1363
1364static struct usb_driver ua101_driver = {
1365 .name = "snd-ua101",
1366 .id_table = ua101_ids,
1367 .probe = ua101_probe,
1368 .disconnect = ua101_disconnect,
1369#if 0
1370 .suspend = ua101_suspend,
1371 .resume = ua101_resume,
1372#endif
1373};
1374
1375static int __init alsa_card_ua101_init(void)
1376{
1377 return usb_register(&ua101_driver);
1378}
1379
1380static void __exit alsa_card_ua101_exit(void)
1381{
1382 usb_deregister(&ua101_driver);
1383 mutex_destroy(&devices_mutex);
1384}
1385
1386module_init(alsa_card_ua101_init);
1387module_exit(alsa_card_ua101_exit);
diff --git a/sound/usb/usbaudio.c b/sound/usb/usbaudio.c
index 8db0374e10d5..11b0826b8fe6 100644
--- a/sound/usb/usbaudio.c
+++ b/sound/usb/usbaudio.c
@@ -44,9 +44,11 @@
44#include <linux/slab.h> 44#include <linux/slab.h>
45#include <linux/string.h> 45#include <linux/string.h>
46#include <linux/usb.h> 46#include <linux/usb.h>
47#include <linux/vmalloc.h>
48#include <linux/moduleparam.h> 47#include <linux/moduleparam.h>
49#include <linux/mutex.h> 48#include <linux/mutex.h>
49#include <linux/usb/audio.h>
50#include <linux/usb/ch9.h>
51
50#include <sound/core.h> 52#include <sound/core.h>
51#include <sound/info.h> 53#include <sound/info.h>
52#include <sound/pcm.h> 54#include <sound/pcm.h>
@@ -170,11 +172,12 @@ struct snd_usb_substream {
170 unsigned int curpacksize; /* current packet size in bytes (for capture) */ 172 unsigned int curpacksize; /* current packet size in bytes (for capture) */
171 unsigned int curframesize; /* current packet size in frames (for capture) */ 173 unsigned int curframesize; /* current packet size in frames (for capture) */
172 unsigned int fill_max: 1; /* fill max packet size always */ 174 unsigned int fill_max: 1; /* fill max packet size always */
175 unsigned int txfr_quirk:1; /* allow sub-frame alignment */
173 unsigned int fmt_type; /* USB audio format type (1-3) */ 176 unsigned int fmt_type; /* USB audio format type (1-3) */
174 177
175 unsigned int running: 1; /* running status */ 178 unsigned int running: 1; /* running status */
176 179
177 unsigned int hwptr_done; /* processed frame position in the buffer */ 180 unsigned int hwptr_done; /* processed byte position in the buffer */
178 unsigned int transfer_done; /* processed frames since last period update */ 181 unsigned int transfer_done; /* processed frames since last period update */
179 unsigned long active_mask; /* bitmask of active urbs */ 182 unsigned long active_mask; /* bitmask of active urbs */
180 unsigned long unlink_mask; /* bitmask of unlinked urbs */ 183 unsigned long unlink_mask; /* bitmask of unlinked urbs */
@@ -343,7 +346,7 @@ static int retire_capture_urb(struct snd_usb_substream *subs,
343 unsigned long flags; 346 unsigned long flags;
344 unsigned char *cp; 347 unsigned char *cp;
345 int i; 348 int i;
346 unsigned int stride, len, oldptr; 349 unsigned int stride, frames, bytes, oldptr;
347 int period_elapsed = 0; 350 int period_elapsed = 0;
348 351
349 stride = runtime->frame_bits >> 3; 352 stride = runtime->frame_bits >> 3;
@@ -354,29 +357,39 @@ static int retire_capture_urb(struct snd_usb_substream *subs,
354 snd_printd(KERN_ERR "frame %d active: %d\n", i, urb->iso_frame_desc[i].status); 357 snd_printd(KERN_ERR "frame %d active: %d\n", i, urb->iso_frame_desc[i].status);
355 // continue; 358 // continue;
356 } 359 }
357 len = urb->iso_frame_desc[i].actual_length / stride; 360 bytes = urb->iso_frame_desc[i].actual_length;
358 if (! len) 361 frames = bytes / stride;
359 continue; 362 if (!subs->txfr_quirk)
363 bytes = frames * stride;
364 if (bytes % (runtime->sample_bits >> 3) != 0) {
365#ifdef CONFIG_SND_DEBUG_VERBOSE
366 int oldbytes = bytes;
367#endif
368 bytes = frames * stride;
369 snd_printdd(KERN_ERR "Corrected urb data len. %d->%d\n",
370 oldbytes, bytes);
371 }
360 /* update the current pointer */ 372 /* update the current pointer */
361 spin_lock_irqsave(&subs->lock, flags); 373 spin_lock_irqsave(&subs->lock, flags);
362 oldptr = subs->hwptr_done; 374 oldptr = subs->hwptr_done;
363 subs->hwptr_done += len; 375 subs->hwptr_done += bytes;
364 if (subs->hwptr_done >= runtime->buffer_size) 376 if (subs->hwptr_done >= runtime->buffer_size * stride)
365 subs->hwptr_done -= runtime->buffer_size; 377 subs->hwptr_done -= runtime->buffer_size * stride;
366 subs->transfer_done += len; 378 frames = (bytes + (oldptr % stride)) / stride;
379 subs->transfer_done += frames;
367 if (subs->transfer_done >= runtime->period_size) { 380 if (subs->transfer_done >= runtime->period_size) {
368 subs->transfer_done -= runtime->period_size; 381 subs->transfer_done -= runtime->period_size;
369 period_elapsed = 1; 382 period_elapsed = 1;
370 } 383 }
371 spin_unlock_irqrestore(&subs->lock, flags); 384 spin_unlock_irqrestore(&subs->lock, flags);
372 /* copy a data chunk */ 385 /* copy a data chunk */
373 if (oldptr + len > runtime->buffer_size) { 386 if (oldptr + bytes > runtime->buffer_size * stride) {
374 unsigned int cnt = runtime->buffer_size - oldptr; 387 unsigned int bytes1 =
375 unsigned int blen = cnt * stride; 388 runtime->buffer_size * stride - oldptr;
376 memcpy(runtime->dma_area + oldptr * stride, cp, blen); 389 memcpy(runtime->dma_area + oldptr, cp, bytes1);
377 memcpy(runtime->dma_area, cp + blen, len * stride - blen); 390 memcpy(runtime->dma_area, cp + bytes1, bytes - bytes1);
378 } else { 391 } else {
379 memcpy(runtime->dma_area + oldptr * stride, cp, len * stride); 392 memcpy(runtime->dma_area + oldptr, cp, bytes);
380 } 393 }
381 } 394 }
382 if (period_elapsed) 395 if (period_elapsed)
@@ -563,34 +576,34 @@ static int prepare_playback_urb(struct snd_usb_substream *subs,
563 struct snd_pcm_runtime *runtime, 576 struct snd_pcm_runtime *runtime,
564 struct urb *urb) 577 struct urb *urb)
565{ 578{
566 int i, stride, offs; 579 int i, stride;
567 unsigned int counts; 580 unsigned int counts, frames, bytes;
568 unsigned long flags; 581 unsigned long flags;
569 int period_elapsed = 0; 582 int period_elapsed = 0;
570 struct snd_urb_ctx *ctx = urb->context; 583 struct snd_urb_ctx *ctx = urb->context;
571 584
572 stride = runtime->frame_bits >> 3; 585 stride = runtime->frame_bits >> 3;
573 586
574 offs = 0; 587 frames = 0;
575 urb->dev = ctx->subs->dev; /* we need to set this at each time */ 588 urb->dev = ctx->subs->dev; /* we need to set this at each time */
576 urb->number_of_packets = 0; 589 urb->number_of_packets = 0;
577 spin_lock_irqsave(&subs->lock, flags); 590 spin_lock_irqsave(&subs->lock, flags);
578 for (i = 0; i < ctx->packets; i++) { 591 for (i = 0; i < ctx->packets; i++) {
579 counts = snd_usb_audio_next_packet_size(subs); 592 counts = snd_usb_audio_next_packet_size(subs);
580 /* set up descriptor */ 593 /* set up descriptor */
581 urb->iso_frame_desc[i].offset = offs * stride; 594 urb->iso_frame_desc[i].offset = frames * stride;
582 urb->iso_frame_desc[i].length = counts * stride; 595 urb->iso_frame_desc[i].length = counts * stride;
583 offs += counts; 596 frames += counts;
584 urb->number_of_packets++; 597 urb->number_of_packets++;
585 subs->transfer_done += counts; 598 subs->transfer_done += counts;
586 if (subs->transfer_done >= runtime->period_size) { 599 if (subs->transfer_done >= runtime->period_size) {
587 subs->transfer_done -= runtime->period_size; 600 subs->transfer_done -= runtime->period_size;
588 period_elapsed = 1; 601 period_elapsed = 1;
589 if (subs->fmt_type == USB_FORMAT_TYPE_II) { 602 if (subs->fmt_type == UAC_FORMAT_TYPE_II) {
590 if (subs->transfer_done > 0) { 603 if (subs->transfer_done > 0) {
591 /* FIXME: fill-max mode is not 604 /* FIXME: fill-max mode is not
592 * supported yet */ 605 * supported yet */
593 offs -= subs->transfer_done; 606 frames -= subs->transfer_done;
594 counts -= subs->transfer_done; 607 counts -= subs->transfer_done;
595 urb->iso_frame_desc[i].length = 608 urb->iso_frame_desc[i].length =
596 counts * stride; 609 counts * stride;
@@ -600,7 +613,7 @@ static int prepare_playback_urb(struct snd_usb_substream *subs,
600 if (i < ctx->packets) { 613 if (i < ctx->packets) {
601 /* add a transfer delimiter */ 614 /* add a transfer delimiter */
602 urb->iso_frame_desc[i].offset = 615 urb->iso_frame_desc[i].offset =
603 offs * stride; 616 frames * stride;
604 urb->iso_frame_desc[i].length = 0; 617 urb->iso_frame_desc[i].length = 0;
605 urb->number_of_packets++; 618 urb->number_of_packets++;
606 } 619 }
@@ -610,26 +623,25 @@ static int prepare_playback_urb(struct snd_usb_substream *subs,
610 if (period_elapsed) /* finish at the period boundary */ 623 if (period_elapsed) /* finish at the period boundary */
611 break; 624 break;
612 } 625 }
613 if (subs->hwptr_done + offs > runtime->buffer_size) { 626 bytes = frames * stride;
627 if (subs->hwptr_done + bytes > runtime->buffer_size * stride) {
614 /* err, the transferred area goes over buffer boundary. */ 628 /* err, the transferred area goes over buffer boundary. */
615 unsigned int len = runtime->buffer_size - subs->hwptr_done; 629 unsigned int bytes1 =
630 runtime->buffer_size * stride - subs->hwptr_done;
616 memcpy(urb->transfer_buffer, 631 memcpy(urb->transfer_buffer,
617 runtime->dma_area + subs->hwptr_done * stride, 632 runtime->dma_area + subs->hwptr_done, bytes1);
618 len * stride); 633 memcpy(urb->transfer_buffer + bytes1,
619 memcpy(urb->transfer_buffer + len * stride, 634 runtime->dma_area, bytes - bytes1);
620 runtime->dma_area,
621 (offs - len) * stride);
622 } else { 635 } else {
623 memcpy(urb->transfer_buffer, 636 memcpy(urb->transfer_buffer,
624 runtime->dma_area + subs->hwptr_done * stride, 637 runtime->dma_area + subs->hwptr_done, bytes);
625 offs * stride);
626 } 638 }
627 subs->hwptr_done += offs; 639 subs->hwptr_done += bytes;
628 if (subs->hwptr_done >= runtime->buffer_size) 640 if (subs->hwptr_done >= runtime->buffer_size * stride)
629 subs->hwptr_done -= runtime->buffer_size; 641 subs->hwptr_done -= runtime->buffer_size * stride;
630 runtime->delay += offs; 642 runtime->delay += frames;
631 spin_unlock_irqrestore(&subs->lock, flags); 643 spin_unlock_irqrestore(&subs->lock, flags);
632 urb->transfer_buffer_length = offs * stride; 644 urb->transfer_buffer_length = bytes;
633 if (period_elapsed) 645 if (period_elapsed)
634 snd_pcm_period_elapsed(subs->pcm_substream); 646 snd_pcm_period_elapsed(subs->pcm_substream);
635 return 0; 647 return 0;
@@ -735,41 +747,6 @@ static void snd_complete_sync_urb(struct urb *urb)
735} 747}
736 748
737 749
738/* get the physical page pointer at the given offset */
739static struct page *snd_pcm_get_vmalloc_page(struct snd_pcm_substream *subs,
740 unsigned long offset)
741{
742 void *pageptr = subs->runtime->dma_area + offset;
743 return vmalloc_to_page(pageptr);
744}
745
746/* allocate virtual buffer; may be called more than once */
747static int snd_pcm_alloc_vmalloc_buffer(struct snd_pcm_substream *subs, size_t size)
748{
749 struct snd_pcm_runtime *runtime = subs->runtime;
750 if (runtime->dma_area) {
751 if (runtime->dma_bytes >= size)
752 return 0; /* already large enough */
753 vfree(runtime->dma_area);
754 }
755 runtime->dma_area = vmalloc(size);
756 if (!runtime->dma_area)
757 return -ENOMEM;
758 runtime->dma_bytes = size;
759 return 0;
760}
761
762/* free virtual buffer; may be called more than once */
763static int snd_pcm_free_vmalloc_buffer(struct snd_pcm_substream *subs)
764{
765 struct snd_pcm_runtime *runtime = subs->runtime;
766
767 vfree(runtime->dma_area);
768 runtime->dma_area = NULL;
769 return 0;
770}
771
772
773/* 750/*
774 * unlink active urbs. 751 * unlink active urbs.
775 */ 752 */
@@ -937,18 +914,18 @@ static int wait_clear_urbs(struct snd_usb_substream *subs)
937 914
938 915
939/* 916/*
940 * return the current pcm pointer. just return the hwptr_done value. 917 * return the current pcm pointer. just based on the hwptr_done value.
941 */ 918 */
942static snd_pcm_uframes_t snd_usb_pcm_pointer(struct snd_pcm_substream *substream) 919static snd_pcm_uframes_t snd_usb_pcm_pointer(struct snd_pcm_substream *substream)
943{ 920{
944 struct snd_usb_substream *subs; 921 struct snd_usb_substream *subs;
945 snd_pcm_uframes_t hwptr_done; 922 unsigned int hwptr_done;
946 923
947 subs = (struct snd_usb_substream *)substream->runtime->private_data; 924 subs = (struct snd_usb_substream *)substream->runtime->private_data;
948 spin_lock(&subs->lock); 925 spin_lock(&subs->lock);
949 hwptr_done = subs->hwptr_done; 926 hwptr_done = subs->hwptr_done;
950 spin_unlock(&subs->lock); 927 spin_unlock(&subs->lock);
951 return hwptr_done; 928 return hwptr_done / (substream->runtime->frame_bits >> 3);
952} 929}
953 930
954 931
@@ -1130,7 +1107,7 @@ static int init_substream_urbs(struct snd_usb_substream *subs, unsigned int peri
1130 u->packets = (i + 1) * total_packs / subs->nurbs 1107 u->packets = (i + 1) * total_packs / subs->nurbs
1131 - i * total_packs / subs->nurbs; 1108 - i * total_packs / subs->nurbs;
1132 u->buffer_size = maxsize * u->packets; 1109 u->buffer_size = maxsize * u->packets;
1133 if (subs->fmt_type == USB_FORMAT_TYPE_II) 1110 if (subs->fmt_type == UAC_FORMAT_TYPE_II)
1134 u->packets++; /* for transfer delimiter */ 1111 u->packets++; /* for transfer delimiter */
1135 u->urb = usb_alloc_urb(u->packets, GFP_KERNEL); 1112 u->urb = usb_alloc_urb(u->packets, GFP_KERNEL);
1136 if (!u->urb) 1113 if (!u->urb)
@@ -1206,7 +1183,7 @@ static struct audioformat *find_format(struct snd_usb_substream *subs, unsigned
1206 if (i >= fp->nr_rates) 1183 if (i >= fp->nr_rates)
1207 continue; 1184 continue;
1208 } 1185 }
1209 attr = fp->ep_attr & EP_ATTR_MASK; 1186 attr = fp->ep_attr & USB_ENDPOINT_SYNCTYPE;
1210 if (! found) { 1187 if (! found) {
1211 found = fp; 1188 found = fp;
1212 cur_attr = attr; 1189 cur_attr = attr;
@@ -1218,14 +1195,14 @@ static struct audioformat *find_format(struct snd_usb_substream *subs, unsigned
1218 * M-audio audiophile USB. 1195 * M-audio audiophile USB.
1219 */ 1196 */
1220 if (attr != cur_attr) { 1197 if (attr != cur_attr) {
1221 if ((attr == EP_ATTR_ASYNC && 1198 if ((attr == USB_ENDPOINT_SYNC_ASYNC &&
1222 subs->direction == SNDRV_PCM_STREAM_PLAYBACK) || 1199 subs->direction == SNDRV_PCM_STREAM_PLAYBACK) ||
1223 (attr == EP_ATTR_ADAPTIVE && 1200 (attr == USB_ENDPOINT_SYNC_ADAPTIVE &&
1224 subs->direction == SNDRV_PCM_STREAM_CAPTURE)) 1201 subs->direction == SNDRV_PCM_STREAM_CAPTURE))
1225 continue; 1202 continue;
1226 if ((cur_attr == EP_ATTR_ASYNC && 1203 if ((cur_attr == USB_ENDPOINT_SYNC_ASYNC &&
1227 subs->direction == SNDRV_PCM_STREAM_PLAYBACK) || 1204 subs->direction == SNDRV_PCM_STREAM_PLAYBACK) ||
1228 (cur_attr == EP_ATTR_ADAPTIVE && 1205 (cur_attr == USB_ENDPOINT_SYNC_ADAPTIVE &&
1229 subs->direction == SNDRV_PCM_STREAM_CAPTURE)) { 1206 subs->direction == SNDRV_PCM_STREAM_CAPTURE)) {
1230 found = fp; 1207 found = fp;
1231 cur_attr = attr; 1208 cur_attr = attr;
@@ -1255,11 +1232,11 @@ static int init_usb_pitch(struct usb_device *dev, int iface,
1255 1232
1256 ep = get_endpoint(alts, 0)->bEndpointAddress; 1233 ep = get_endpoint(alts, 0)->bEndpointAddress;
1257 /* if endpoint has pitch control, enable it */ 1234 /* if endpoint has pitch control, enable it */
1258 if (fmt->attributes & EP_CS_ATTR_PITCH_CONTROL) { 1235 if (fmt->attributes & UAC_EP_CS_ATTR_PITCH_CONTROL) {
1259 data[0] = 1; 1236 data[0] = 1;
1260 if ((err = snd_usb_ctl_msg(dev, usb_sndctrlpipe(dev, 0), SET_CUR, 1237 if ((err = snd_usb_ctl_msg(dev, usb_sndctrlpipe(dev, 0), UAC_SET_CUR,
1261 USB_TYPE_CLASS|USB_RECIP_ENDPOINT|USB_DIR_OUT, 1238 USB_TYPE_CLASS|USB_RECIP_ENDPOINT|USB_DIR_OUT,
1262 PITCH_CONTROL << 8, ep, data, 1, 1000)) < 0) { 1239 UAC_EP_CS_ATTR_PITCH_CONTROL << 8, ep, data, 1, 1000)) < 0) {
1263 snd_printk(KERN_ERR "%d:%d:%d: cannot set enable PITCH\n", 1240 snd_printk(KERN_ERR "%d:%d:%d: cannot set enable PITCH\n",
1264 dev->devnum, iface, ep); 1241 dev->devnum, iface, ep);
1265 return err; 1242 return err;
@@ -1278,21 +1255,21 @@ static int init_usb_sample_rate(struct usb_device *dev, int iface,
1278 1255
1279 ep = get_endpoint(alts, 0)->bEndpointAddress; 1256 ep = get_endpoint(alts, 0)->bEndpointAddress;
1280 /* if endpoint has sampling rate control, set it */ 1257 /* if endpoint has sampling rate control, set it */
1281 if (fmt->attributes & EP_CS_ATTR_SAMPLE_RATE) { 1258 if (fmt->attributes & UAC_EP_CS_ATTR_SAMPLE_RATE) {
1282 int crate; 1259 int crate;
1283 data[0] = rate; 1260 data[0] = rate;
1284 data[1] = rate >> 8; 1261 data[1] = rate >> 8;
1285 data[2] = rate >> 16; 1262 data[2] = rate >> 16;
1286 if ((err = snd_usb_ctl_msg(dev, usb_sndctrlpipe(dev, 0), SET_CUR, 1263 if ((err = snd_usb_ctl_msg(dev, usb_sndctrlpipe(dev, 0), UAC_SET_CUR,
1287 USB_TYPE_CLASS|USB_RECIP_ENDPOINT|USB_DIR_OUT, 1264 USB_TYPE_CLASS|USB_RECIP_ENDPOINT|USB_DIR_OUT,
1288 SAMPLING_FREQ_CONTROL << 8, ep, data, 3, 1000)) < 0) { 1265 UAC_EP_CS_ATTR_SAMPLE_RATE << 8, ep, data, 3, 1000)) < 0) {
1289 snd_printk(KERN_ERR "%d:%d:%d: cannot set freq %d to ep %#x\n", 1266 snd_printk(KERN_ERR "%d:%d:%d: cannot set freq %d to ep %#x\n",
1290 dev->devnum, iface, fmt->altsetting, rate, ep); 1267 dev->devnum, iface, fmt->altsetting, rate, ep);
1291 return err; 1268 return err;
1292 } 1269 }
1293 if ((err = snd_usb_ctl_msg(dev, usb_rcvctrlpipe(dev, 0), GET_CUR, 1270 if ((err = snd_usb_ctl_msg(dev, usb_rcvctrlpipe(dev, 0), UAC_GET_CUR,
1294 USB_TYPE_CLASS|USB_RECIP_ENDPOINT|USB_DIR_IN, 1271 USB_TYPE_CLASS|USB_RECIP_ENDPOINT|USB_DIR_IN,
1295 SAMPLING_FREQ_CONTROL << 8, ep, data, 3, 1000)) < 0) { 1272 UAC_EP_CS_ATTR_SAMPLE_RATE << 8, ep, data, 3, 1000)) < 0) {
1296 snd_printk(KERN_WARNING "%d:%d:%d: cannot get freq at ep %#x\n", 1273 snd_printk(KERN_WARNING "%d:%d:%d: cannot get freq at ep %#x\n",
1297 dev->devnum, iface, fmt->altsetting, ep); 1274 dev->devnum, iface, fmt->altsetting, ep);
1298 return 0; /* some devices don't support reading */ 1275 return 0; /* some devices don't support reading */
@@ -1307,6 +1284,47 @@ static int init_usb_sample_rate(struct usb_device *dev, int iface,
1307} 1284}
1308 1285
1309/* 1286/*
1287 * For E-Mu 0404USB/0202USB/TrackerPre sample rate should be set for device,
1288 * not for interface.
1289 */
1290static void set_format_emu_quirk(struct snd_usb_substream *subs,
1291 struct audioformat *fmt)
1292{
1293 unsigned char emu_samplerate_id = 0;
1294
1295 /* When capture is active
1296 * sample rate shouldn't be changed
1297 * by playback substream
1298 */
1299 if (subs->direction == SNDRV_PCM_STREAM_PLAYBACK) {
1300 if (subs->stream->substream[SNDRV_PCM_STREAM_CAPTURE].interface != -1)
1301 return;
1302 }
1303
1304 switch (fmt->rate_min) {
1305 case 48000:
1306 emu_samplerate_id = EMU_QUIRK_SR_48000HZ;
1307 break;
1308 case 88200:
1309 emu_samplerate_id = EMU_QUIRK_SR_88200HZ;
1310 break;
1311 case 96000:
1312 emu_samplerate_id = EMU_QUIRK_SR_96000HZ;
1313 break;
1314 case 176400:
1315 emu_samplerate_id = EMU_QUIRK_SR_176400HZ;
1316 break;
1317 case 192000:
1318 emu_samplerate_id = EMU_QUIRK_SR_192000HZ;
1319 break;
1320 default:
1321 emu_samplerate_id = EMU_QUIRK_SR_44100HZ;
1322 break;
1323 }
1324 snd_emuusb_set_samplerate(subs->stream->chip, emu_samplerate_id);
1325}
1326
1327/*
1310 * find a matching format and set up the interface 1328 * find a matching format and set up the interface
1311 */ 1329 */
1312static int set_format(struct snd_usb_substream *subs, struct audioformat *fmt) 1330static int set_format(struct snd_usb_substream *subs, struct audioformat *fmt)
@@ -1369,9 +1387,9 @@ static int set_format(struct snd_usb_substream *subs, struct audioformat *fmt)
1369 * descriptors which fool us. if it has only one EP, 1387 * descriptors which fool us. if it has only one EP,
1370 * assume it as adaptive-out or sync-in. 1388 * assume it as adaptive-out or sync-in.
1371 */ 1389 */
1372 attr = fmt->ep_attr & EP_ATTR_MASK; 1390 attr = fmt->ep_attr & USB_ENDPOINT_SYNCTYPE;
1373 if (((is_playback && attr == EP_ATTR_ASYNC) || 1391 if (((is_playback && attr == USB_ENDPOINT_SYNC_ASYNC) ||
1374 (! is_playback && attr == EP_ATTR_ADAPTIVE)) && 1392 (! is_playback && attr == USB_ENDPOINT_SYNC_ADAPTIVE)) &&
1375 altsd->bNumEndpoints >= 2) { 1393 altsd->bNumEndpoints >= 2) {
1376 /* check sync-pipe endpoint */ 1394 /* check sync-pipe endpoint */
1377 /* ... and check descriptor size before accessing bSynchAddress 1395 /* ... and check descriptor size before accessing bSynchAddress
@@ -1411,7 +1429,7 @@ static int set_format(struct snd_usb_substream *subs, struct audioformat *fmt)
1411 } 1429 }
1412 1430
1413 /* always fill max packet size */ 1431 /* always fill max packet size */
1414 if (fmt->attributes & EP_CS_ATTR_FILL_MAX) 1432 if (fmt->attributes & UAC_EP_CS_ATTR_FILL_MAX)
1415 subs->fill_max = 1; 1433 subs->fill_max = 1;
1416 1434
1417 if ((err = init_usb_pitch(dev, subs->interface, alts, fmt)) < 0) 1435 if ((err = init_usb_pitch(dev, subs->interface, alts, fmt)) < 0)
@@ -1419,6 +1437,14 @@ static int set_format(struct snd_usb_substream *subs, struct audioformat *fmt)
1419 1437
1420 subs->cur_audiofmt = fmt; 1438 subs->cur_audiofmt = fmt;
1421 1439
1440 switch (subs->stream->chip->usb_id) {
1441 case USB_ID(0x041e, 0x3f02): /* E-Mu 0202 USB */
1442 case USB_ID(0x041e, 0x3f04): /* E-Mu 0404 USB */
1443 case USB_ID(0x041e, 0x3f0a): /* E-Mu Tracker Pre */
1444 set_format_emu_quirk(subs, fmt);
1445 break;
1446 }
1447
1422#if 0 1448#if 0
1423 printk(KERN_DEBUG 1449 printk(KERN_DEBUG
1424 "setting done: format = %d, rate = %d..%d, channels = %d\n", 1450 "setting done: format = %d, rate = %d..%d, channels = %d\n",
@@ -1449,8 +1475,8 @@ static int snd_usb_hw_params(struct snd_pcm_substream *substream,
1449 unsigned int channels, rate, format; 1475 unsigned int channels, rate, format;
1450 int ret, changed; 1476 int ret, changed;
1451 1477
1452 ret = snd_pcm_alloc_vmalloc_buffer(substream, 1478 ret = snd_pcm_lib_alloc_vmalloc_buffer(substream,
1453 params_buffer_bytes(hw_params)); 1479 params_buffer_bytes(hw_params));
1454 if (ret < 0) 1480 if (ret < 0)
1455 return ret; 1481 return ret;
1456 1482
@@ -1507,7 +1533,7 @@ static int snd_usb_hw_free(struct snd_pcm_substream *substream)
1507 subs->period_bytes = 0; 1533 subs->period_bytes = 0;
1508 if (!subs->stream->chip->shutdown) 1534 if (!subs->stream->chip->shutdown)
1509 release_substream_urbs(subs, 0); 1535 release_substream_urbs(subs, 0);
1510 return snd_pcm_free_vmalloc_buffer(substream); 1536 return snd_pcm_lib_free_vmalloc_buffer(substream);
1511} 1537}
1512 1538
1513/* 1539/*
@@ -1861,7 +1887,7 @@ static int setup_hw_info(struct snd_pcm_runtime *runtime, struct snd_usb_substre
1861 runtime->hw.channels_min = fp->channels; 1887 runtime->hw.channels_min = fp->channels;
1862 if (runtime->hw.channels_max < fp->channels) 1888 if (runtime->hw.channels_max < fp->channels)
1863 runtime->hw.channels_max = fp->channels; 1889 runtime->hw.channels_max = fp->channels;
1864 if (fp->fmt_type == USB_FORMAT_TYPE_II && fp->frame_size > 0) { 1890 if (fp->fmt_type == UAC_FORMAT_TYPE_II && fp->frame_size > 0) {
1865 /* FIXME: there might be more than one audio formats... */ 1891 /* FIXME: there might be more than one audio formats... */
1866 runtime->hw.period_bytes_min = runtime->hw.period_bytes_max = 1892 runtime->hw.period_bytes_min = runtime->hw.period_bytes_max =
1867 fp->frame_size; 1893 fp->frame_size;
@@ -1936,7 +1962,7 @@ static int snd_usb_pcm_close(struct snd_pcm_substream *substream, int direction)
1936 struct snd_usb_stream *as = snd_pcm_substream_chip(substream); 1962 struct snd_usb_stream *as = snd_pcm_substream_chip(substream);
1937 struct snd_usb_substream *subs = &as->substream[direction]; 1963 struct snd_usb_substream *subs = &as->substream[direction];
1938 1964
1939 if (subs->interface >= 0) { 1965 if (!as->chip->shutdown && subs->interface >= 0) {
1940 usb_set_interface(subs->dev, subs->interface, 0); 1966 usb_set_interface(subs->dev, subs->interface, 0);
1941 subs->interface = -1; 1967 subs->interface = -1;
1942 } 1968 }
@@ -1973,7 +1999,8 @@ static struct snd_pcm_ops snd_usb_playback_ops = {
1973 .prepare = snd_usb_pcm_prepare, 1999 .prepare = snd_usb_pcm_prepare,
1974 .trigger = snd_usb_pcm_playback_trigger, 2000 .trigger = snd_usb_pcm_playback_trigger,
1975 .pointer = snd_usb_pcm_pointer, 2001 .pointer = snd_usb_pcm_pointer,
1976 .page = snd_pcm_get_vmalloc_page, 2002 .page = snd_pcm_lib_get_vmalloc_page,
2003 .mmap = snd_pcm_lib_mmap_vmalloc,
1977}; 2004};
1978 2005
1979static struct snd_pcm_ops snd_usb_capture_ops = { 2006static struct snd_pcm_ops snd_usb_capture_ops = {
@@ -1985,7 +2012,8 @@ static struct snd_pcm_ops snd_usb_capture_ops = {
1985 .prepare = snd_usb_pcm_prepare, 2012 .prepare = snd_usb_pcm_prepare,
1986 .trigger = snd_usb_pcm_capture_trigger, 2013 .trigger = snd_usb_pcm_capture_trigger,
1987 .pointer = snd_usb_pcm_pointer, 2014 .pointer = snd_usb_pcm_pointer,
1988 .page = snd_pcm_get_vmalloc_page, 2015 .page = snd_pcm_lib_get_vmalloc_page,
2016 .mmap = snd_pcm_lib_mmap_vmalloc,
1989}; 2017};
1990 2018
1991 2019
@@ -2093,7 +2121,7 @@ static struct usb_device_id usb_audio_ids [] = {
2093#include "usbquirks.h" 2121#include "usbquirks.h"
2094 { .match_flags = (USB_DEVICE_ID_MATCH_INT_CLASS | USB_DEVICE_ID_MATCH_INT_SUBCLASS), 2122 { .match_flags = (USB_DEVICE_ID_MATCH_INT_CLASS | USB_DEVICE_ID_MATCH_INT_SUBCLASS),
2095 .bInterfaceClass = USB_CLASS_AUDIO, 2123 .bInterfaceClass = USB_CLASS_AUDIO,
2096 .bInterfaceSubClass = USB_SUBCLASS_AUDIO_CONTROL }, 2124 .bInterfaceSubClass = USB_SUBCLASS_AUDIOCONTROL },
2097 { } /* Terminating entry */ 2125 { } /* Terminating entry */
2098}; 2126};
2099 2127
@@ -2132,7 +2160,7 @@ static void proc_dump_substream_formats(struct snd_usb_substream *subs, struct s
2132 snd_iprintf(buffer, " Endpoint: %d %s (%s)\n", 2160 snd_iprintf(buffer, " Endpoint: %d %s (%s)\n",
2133 fp->endpoint & USB_ENDPOINT_NUMBER_MASK, 2161 fp->endpoint & USB_ENDPOINT_NUMBER_MASK,
2134 fp->endpoint & USB_DIR_IN ? "IN" : "OUT", 2162 fp->endpoint & USB_DIR_IN ? "IN" : "OUT",
2135 sync_types[(fp->ep_attr & EP_ATTR_MASK) >> 2]); 2163 sync_types[(fp->ep_attr & USB_ENDPOINT_SYNCTYPE) >> 2]);
2136 if (fp->rates & SNDRV_PCM_RATE_CONTINUOUS) { 2164 if (fp->rates & SNDRV_PCM_RATE_CONTINUOUS) {
2137 snd_iprintf(buffer, " Rates: %d - %d (continuous)\n", 2165 snd_iprintf(buffer, " Rates: %d - %d (continuous)\n",
2138 fp->rate_min, fp->rate_max); 2166 fp->rate_min, fp->rate_max);
@@ -2227,6 +2255,7 @@ static void init_substream(struct snd_usb_stream *as, int stream, struct audiofo
2227 subs->stream = as; 2255 subs->stream = as;
2228 subs->direction = stream; 2256 subs->direction = stream;
2229 subs->dev = as->chip->dev; 2257 subs->dev = as->chip->dev;
2258 subs->txfr_quirk = as->chip->txfr_quirk;
2230 if (snd_usb_get_speed(subs->dev) == USB_SPEED_FULL) { 2259 if (snd_usb_get_speed(subs->dev) == USB_SPEED_FULL) {
2231 subs->ops = audio_urb_ops[stream]; 2260 subs->ops = audio_urb_ops[stream];
2232 } else { 2261 } else {
@@ -2394,29 +2423,67 @@ static int is_big_endian_format(struct snd_usb_audio *chip, struct audioformat *
2394 * @format: the format tag (wFormatTag) 2423 * @format: the format tag (wFormatTag)
2395 * @fmt: the format type descriptor 2424 * @fmt: the format type descriptor
2396 */ 2425 */
2397static int parse_audio_format_i_type(struct snd_usb_audio *chip, struct audioformat *fp, 2426static int parse_audio_format_i_type(struct snd_usb_audio *chip,
2398 int format, unsigned char *fmt) 2427 struct audioformat *fp,
2428 int format, void *_fmt,
2429 int protocol)
2399{ 2430{
2400 int pcm_format; 2431 int pcm_format, i;
2401 int sample_width, sample_bytes; 2432 int sample_width, sample_bytes;
2402 2433
2434 switch (protocol) {
2435 case UAC_VERSION_1: {
2436 struct uac_format_type_i_discrete_descriptor *fmt = _fmt;
2437 sample_width = fmt->bBitResolution;
2438 sample_bytes = fmt->bSubframeSize;
2439 break;
2440 }
2441
2442 case UAC_VERSION_2: {
2443 struct uac_format_type_i_ext_descriptor *fmt = _fmt;
2444 sample_width = fmt->bBitResolution;
2445 sample_bytes = fmt->bSubslotSize;
2446
2447 /*
2448 * FIXME
2449 * USB audio class v2 devices specify a bitmap of possible
2450 * audio formats rather than one fix value. For now, we just
2451 * pick one of them and report that as the only possible
2452 * value for this setting.
2453 * The bit allocation map is in fact compatible to the
2454 * wFormatTag of the v1 AS streaming descriptors, which is why
2455 * we can simply map the matrix.
2456 */
2457
2458 for (i = 0; i < 5; i++)
2459 if (format & (1UL << i)) {
2460 format = i + 1;
2461 break;
2462 }
2463
2464 break;
2465 }
2466
2467 default:
2468 return -EINVAL;
2469 }
2470
2403 /* FIXME: correct endianess and sign? */ 2471 /* FIXME: correct endianess and sign? */
2404 pcm_format = -1; 2472 pcm_format = -1;
2405 sample_width = fmt[6]; 2473
2406 sample_bytes = fmt[5];
2407 switch (format) { 2474 switch (format) {
2408 case 0: /* some devices don't define this correctly... */ 2475 case UAC_FORMAT_TYPE_I_UNDEFINED: /* some devices don't define this correctly... */
2409 snd_printdd(KERN_INFO "%d:%u:%d : format type 0 is detected, processed as PCM\n", 2476 snd_printdd(KERN_INFO "%d:%u:%d : format type 0 is detected, processed as PCM\n",
2410 chip->dev->devnum, fp->iface, fp->altsetting); 2477 chip->dev->devnum, fp->iface, fp->altsetting);
2411 /* fall-through */ 2478 /* fall-through */
2412 case USB_AUDIO_FORMAT_PCM: 2479 case UAC_FORMAT_TYPE_I_PCM:
2413 if (sample_width > sample_bytes * 8) { 2480 if (sample_width > sample_bytes * 8) {
2414 snd_printk(KERN_INFO "%d:%u:%d : sample bitwidth %d in over sample bytes %d\n", 2481 snd_printk(KERN_INFO "%d:%u:%d : sample bitwidth %d in over sample bytes %d\n",
2415 chip->dev->devnum, fp->iface, fp->altsetting, 2482 chip->dev->devnum, fp->iface, fp->altsetting,
2416 sample_width, sample_bytes); 2483 sample_width, sample_bytes);
2417 } 2484 }
2418 /* check the format byte size */ 2485 /* check the format byte size */
2419 switch (fmt[5]) { 2486 switch (sample_bytes) {
2420 case 1: 2487 case 1:
2421 pcm_format = SNDRV_PCM_FORMAT_S8; 2488 pcm_format = SNDRV_PCM_FORMAT_S8;
2422 break; 2489 break;
@@ -2437,12 +2504,12 @@ static int parse_audio_format_i_type(struct snd_usb_audio *chip, struct audiofor
2437 break; 2504 break;
2438 default: 2505 default:
2439 snd_printk(KERN_INFO "%d:%u:%d : unsupported sample bitwidth %d in %d bytes\n", 2506 snd_printk(KERN_INFO "%d:%u:%d : unsupported sample bitwidth %d in %d bytes\n",
2440 chip->dev->devnum, fp->iface, 2507 chip->dev->devnum, fp->iface, fp->altsetting,
2441 fp->altsetting, sample_width, sample_bytes); 2508 sample_width, sample_bytes);
2442 break; 2509 break;
2443 } 2510 }
2444 break; 2511 break;
2445 case USB_AUDIO_FORMAT_PCM8: 2512 case UAC_FORMAT_TYPE_I_PCM8:
2446 pcm_format = SNDRV_PCM_FORMAT_U8; 2513 pcm_format = SNDRV_PCM_FORMAT_U8;
2447 2514
2448 /* Dallas DS4201 workaround: it advertises U8 format, but really 2515 /* Dallas DS4201 workaround: it advertises U8 format, but really
@@ -2450,13 +2517,13 @@ static int parse_audio_format_i_type(struct snd_usb_audio *chip, struct audiofor
2450 if (chip->usb_id == USB_ID(0x04fa, 0x4201)) 2517 if (chip->usb_id == USB_ID(0x04fa, 0x4201))
2451 pcm_format = SNDRV_PCM_FORMAT_S8; 2518 pcm_format = SNDRV_PCM_FORMAT_S8;
2452 break; 2519 break;
2453 case USB_AUDIO_FORMAT_IEEE_FLOAT: 2520 case UAC_FORMAT_TYPE_I_IEEE_FLOAT:
2454 pcm_format = SNDRV_PCM_FORMAT_FLOAT_LE; 2521 pcm_format = SNDRV_PCM_FORMAT_FLOAT_LE;
2455 break; 2522 break;
2456 case USB_AUDIO_FORMAT_ALAW: 2523 case UAC_FORMAT_TYPE_I_ALAW:
2457 pcm_format = SNDRV_PCM_FORMAT_A_LAW; 2524 pcm_format = SNDRV_PCM_FORMAT_A_LAW;
2458 break; 2525 break;
2459 case USB_AUDIO_FORMAT_MU_LAW: 2526 case UAC_FORMAT_TYPE_I_MULAW:
2460 pcm_format = SNDRV_PCM_FORMAT_MU_LAW; 2527 pcm_format = SNDRV_PCM_FORMAT_MU_LAW;
2461 break; 2528 break;
2462 default: 2529 default:
@@ -2470,7 +2537,7 @@ static int parse_audio_format_i_type(struct snd_usb_audio *chip, struct audiofor
2470 2537
2471/* 2538/*
2472 * parse the format descriptor and stores the possible sample rates 2539 * parse the format descriptor and stores the possible sample rates
2473 * on the audioformat table. 2540 * on the audioformat table (audio class v1).
2474 * 2541 *
2475 * @dev: usb device 2542 * @dev: usb device
2476 * @fp: audioformat record 2543 * @fp: audioformat record
@@ -2478,13 +2545,13 @@ static int parse_audio_format_i_type(struct snd_usb_audio *chip, struct audiofor
2478 * @offset: the start offset of descriptor pointing the rate type 2545 * @offset: the start offset of descriptor pointing the rate type
2479 * (7 for type I and II, 8 for type II) 2546 * (7 for type I and II, 8 for type II)
2480 */ 2547 */
2481static int parse_audio_format_rates(struct snd_usb_audio *chip, struct audioformat *fp, 2548static int parse_audio_format_rates_v1(struct snd_usb_audio *chip, struct audioformat *fp,
2482 unsigned char *fmt, int offset) 2549 unsigned char *fmt, int offset)
2483{ 2550{
2484 int nr_rates = fmt[offset]; 2551 int nr_rates = fmt[offset];
2485 2552
2486 if (fmt[0] < offset + 1 + 3 * (nr_rates ? nr_rates : 2)) { 2553 if (fmt[0] < offset + 1 + 3 * (nr_rates ? nr_rates : 2)) {
2487 snd_printk(KERN_ERR "%d:%u:%d : invalid FORMAT_TYPE desc\n", 2554 snd_printk(KERN_ERR "%d:%u:%d : invalid UAC_FORMAT_TYPE desc\n",
2488 chip->dev->devnum, fp->iface, fp->altsetting); 2555 chip->dev->devnum, fp->iface, fp->altsetting);
2489 return -1; 2556 return -1;
2490 } 2557 }
@@ -2513,6 +2580,9 @@ static int parse_audio_format_rates(struct snd_usb_audio *chip, struct audioform
2513 chip->usb_id == USB_ID(0x0d8c, 0x0102)) && 2580 chip->usb_id == USB_ID(0x0d8c, 0x0102)) &&
2514 fp->altsetting == 5 && fp->maxpacksize == 392) 2581 fp->altsetting == 5 && fp->maxpacksize == 392)
2515 rate = 96000; 2582 rate = 96000;
2583 /* Creative VF0470 Live Cam reports 16 kHz instead of 8kHz */
2584 if (rate == 16000 && chip->usb_id == USB_ID(0x041e, 0x4068))
2585 rate = 8000;
2516 fp->rate_table[fp->nr_rates] = rate; 2586 fp->rate_table[fp->nr_rates] = rate;
2517 if (!fp->rate_min || rate < fp->rate_min) 2587 if (!fp->rate_min || rate < fp->rate_min)
2518 fp->rate_min = rate; 2588 fp->rate_min = rate;
@@ -2535,14 +2605,87 @@ static int parse_audio_format_rates(struct snd_usb_audio *chip, struct audioform
2535} 2605}
2536 2606
2537/* 2607/*
2608 * parse the format descriptor and stores the possible sample rates
2609 * on the audioformat table (audio class v2).
2610 */
2611static int parse_audio_format_rates_v2(struct snd_usb_audio *chip,
2612 struct audioformat *fp,
2613 struct usb_host_interface *iface)
2614{
2615 struct usb_device *dev = chip->dev;
2616 unsigned char tmp[2], *data;
2617 int i, nr_rates, data_size, ret = 0;
2618
2619 /* get the number of sample rates first by only fetching 2 bytes */
2620 ret = snd_usb_ctl_msg(dev, usb_rcvctrlpipe(dev, 0), UAC2_CS_RANGE,
2621 USB_TYPE_CLASS | USB_RECIP_INTERFACE | USB_DIR_IN,
2622 0x0100, chip->clock_id << 8, tmp, sizeof(tmp), 1000);
2623
2624 if (ret < 0) {
2625 snd_printk(KERN_ERR "unable to retrieve number of sample rates\n");
2626 goto err;
2627 }
2628
2629 nr_rates = (tmp[1] << 8) | tmp[0];
2630 data_size = 2 + 12 * nr_rates;
2631 data = kzalloc(data_size, GFP_KERNEL);
2632 if (!data) {
2633 ret = -ENOMEM;
2634 goto err;
2635 }
2636
2637 /* now get the full information */
2638 ret = snd_usb_ctl_msg(dev, usb_rcvctrlpipe(dev, 0), UAC2_CS_RANGE,
2639 USB_TYPE_CLASS | USB_RECIP_INTERFACE | USB_DIR_IN,
2640 0x0100, chip->clock_id << 8, data, data_size, 1000);
2641
2642 if (ret < 0) {
2643 snd_printk(KERN_ERR "unable to retrieve sample rate range\n");
2644 ret = -EINVAL;
2645 goto err_free;
2646 }
2647
2648 fp->rate_table = kmalloc(sizeof(int) * nr_rates, GFP_KERNEL);
2649 if (!fp->rate_table) {
2650 ret = -ENOMEM;
2651 goto err_free;
2652 }
2653
2654 fp->nr_rates = 0;
2655 fp->rate_min = fp->rate_max = 0;
2656
2657 for (i = 0; i < nr_rates; i++) {
2658 int rate = combine_quad(&data[2 + 12 * i]);
2659
2660 fp->rate_table[fp->nr_rates] = rate;
2661 if (!fp->rate_min || rate < fp->rate_min)
2662 fp->rate_min = rate;
2663 if (!fp->rate_max || rate > fp->rate_max)
2664 fp->rate_max = rate;
2665 fp->rates |= snd_pcm_rate_to_rate_bit(rate);
2666 fp->nr_rates++;
2667 }
2668
2669err_free:
2670 kfree(data);
2671err:
2672 return ret;
2673}
2674
2675/*
2538 * parse the format type I and III descriptors 2676 * parse the format type I and III descriptors
2539 */ 2677 */
2540static int parse_audio_format_i(struct snd_usb_audio *chip, struct audioformat *fp, 2678static int parse_audio_format_i(struct snd_usb_audio *chip,
2541 int format, unsigned char *fmt) 2679 struct audioformat *fp,
2680 int format, void *_fmt,
2681 struct usb_host_interface *iface)
2542{ 2682{
2543 int pcm_format; 2683 struct usb_interface_descriptor *altsd = get_iface_desc(iface);
2684 struct uac_format_type_i_discrete_descriptor *fmt = _fmt;
2685 int protocol = altsd->bInterfaceProtocol;
2686 int pcm_format, ret;
2544 2687
2545 if (fmt[3] == USB_FORMAT_TYPE_III) { 2688 if (fmt->bFormatType == UAC_FORMAT_TYPE_III) {
2546 /* FIXME: the format type is really IECxxx 2689 /* FIXME: the format type is really IECxxx
2547 * but we give normal PCM format to get the existing 2690 * but we give normal PCM format to get the existing
2548 * apps working... 2691 * apps working...
@@ -2560,34 +2703,57 @@ static int parse_audio_format_i(struct snd_usb_audio *chip, struct audioformat *
2560 pcm_format = SNDRV_PCM_FORMAT_S16_LE; 2703 pcm_format = SNDRV_PCM_FORMAT_S16_LE;
2561 } 2704 }
2562 } else { 2705 } else {
2563 pcm_format = parse_audio_format_i_type(chip, fp, format, fmt); 2706 pcm_format = parse_audio_format_i_type(chip, fp, format, fmt, protocol);
2564 if (pcm_format < 0) 2707 if (pcm_format < 0)
2565 return -1; 2708 return -1;
2566 } 2709 }
2710
2567 fp->format = pcm_format; 2711 fp->format = pcm_format;
2568 fp->channels = fmt[4]; 2712
2713 /* gather possible sample rates */
2714 /* audio class v1 reports possible sample rates as part of the
2715 * proprietary class specific descriptor.
2716 * audio class v2 uses class specific EP0 range requests for that.
2717 */
2718 switch (protocol) {
2719 case UAC_VERSION_1:
2720 fp->channels = fmt->bNrChannels;
2721 ret = parse_audio_format_rates_v1(chip, fp, _fmt, 7);
2722 break;
2723 case UAC_VERSION_2:
2724 /* fp->channels is already set in this case */
2725 ret = parse_audio_format_rates_v2(chip, fp, iface);
2726 break;
2727 }
2728
2569 if (fp->channels < 1) { 2729 if (fp->channels < 1) {
2570 snd_printk(KERN_ERR "%d:%u:%d : invalid channels %d\n", 2730 snd_printk(KERN_ERR "%d:%u:%d : invalid channels %d\n",
2571 chip->dev->devnum, fp->iface, fp->altsetting, fp->channels); 2731 chip->dev->devnum, fp->iface, fp->altsetting, fp->channels);
2572 return -1; 2732 return -1;
2573 } 2733 }
2574 return parse_audio_format_rates(chip, fp, fmt, 7); 2734
2735 return ret;
2575} 2736}
2576 2737
2577/* 2738/*
2578 * prase the format type II descriptor 2739 * parse the format type II descriptor
2579 */ 2740 */
2580static int parse_audio_format_ii(struct snd_usb_audio *chip, struct audioformat *fp, 2741static int parse_audio_format_ii(struct snd_usb_audio *chip,
2581 int format, unsigned char *fmt) 2742 struct audioformat *fp,
2743 int format, void *_fmt,
2744 struct usb_host_interface *iface)
2582{ 2745{
2583 int brate, framesize; 2746 int brate, framesize, ret;
2747 struct usb_interface_descriptor *altsd = get_iface_desc(iface);
2748 int protocol = altsd->bInterfaceProtocol;
2749
2584 switch (format) { 2750 switch (format) {
2585 case USB_AUDIO_FORMAT_AC3: 2751 case UAC_FORMAT_TYPE_II_AC3:
2586 /* FIXME: there is no AC3 format defined yet */ 2752 /* FIXME: there is no AC3 format defined yet */
2587 // fp->format = SNDRV_PCM_FORMAT_AC3; 2753 // fp->format = SNDRV_PCM_FORMAT_AC3;
2588 fp->format = SNDRV_PCM_FORMAT_U8; /* temporarily hack to receive byte streams */ 2754 fp->format = SNDRV_PCM_FORMAT_U8; /* temporarily hack to receive byte streams */
2589 break; 2755 break;
2590 case USB_AUDIO_FORMAT_MPEG: 2756 case UAC_FORMAT_TYPE_II_MPEG:
2591 fp->format = SNDRV_PCM_FORMAT_MPEG; 2757 fp->format = SNDRV_PCM_FORMAT_MPEG;
2592 break; 2758 break;
2593 default: 2759 default:
@@ -2596,26 +2762,46 @@ static int parse_audio_format_ii(struct snd_usb_audio *chip, struct audioformat
2596 fp->format = SNDRV_PCM_FORMAT_MPEG; 2762 fp->format = SNDRV_PCM_FORMAT_MPEG;
2597 break; 2763 break;
2598 } 2764 }
2765
2599 fp->channels = 1; 2766 fp->channels = 1;
2600 brate = combine_word(&fmt[4]); /* fmt[4,5] : wMaxBitRate (in kbps) */ 2767
2601 framesize = combine_word(&fmt[6]); /* fmt[6,7]: wSamplesPerFrame */ 2768 switch (protocol) {
2602 snd_printd(KERN_INFO "found format II with max.bitrate = %d, frame size=%d\n", brate, framesize); 2769 case UAC_VERSION_1: {
2603 fp->frame_size = framesize; 2770 struct uac_format_type_ii_discrete_descriptor *fmt = _fmt;
2604 return parse_audio_format_rates(chip, fp, fmt, 8); /* fmt[8..] sample rates */ 2771 brate = le16_to_cpu(fmt->wMaxBitRate);
2772 framesize = le16_to_cpu(fmt->wSamplesPerFrame);
2773 snd_printd(KERN_INFO "found format II with max.bitrate = %d, frame size=%d\n", brate, framesize);
2774 fp->frame_size = framesize;
2775 ret = parse_audio_format_rates_v1(chip, fp, _fmt, 8); /* fmt[8..] sample rates */
2776 break;
2777 }
2778 case UAC_VERSION_2: {
2779 struct uac_format_type_ii_ext_descriptor *fmt = _fmt;
2780 brate = le16_to_cpu(fmt->wMaxBitRate);
2781 framesize = le16_to_cpu(fmt->wSamplesPerFrame);
2782 snd_printd(KERN_INFO "found format II with max.bitrate = %d, frame size=%d\n", brate, framesize);
2783 fp->frame_size = framesize;
2784 ret = parse_audio_format_rates_v2(chip, fp, iface);
2785 break;
2786 }
2787 }
2788
2789 return ret;
2605} 2790}
2606 2791
2607static int parse_audio_format(struct snd_usb_audio *chip, struct audioformat *fp, 2792static int parse_audio_format(struct snd_usb_audio *chip, struct audioformat *fp,
2608 int format, unsigned char *fmt, int stream) 2793 int format, unsigned char *fmt, int stream,
2794 struct usb_host_interface *iface)
2609{ 2795{
2610 int err; 2796 int err;
2611 2797
2612 switch (fmt[3]) { 2798 switch (fmt[3]) {
2613 case USB_FORMAT_TYPE_I: 2799 case UAC_FORMAT_TYPE_I:
2614 case USB_FORMAT_TYPE_III: 2800 case UAC_FORMAT_TYPE_III:
2615 err = parse_audio_format_i(chip, fp, format, fmt); 2801 err = parse_audio_format_i(chip, fp, format, fmt, iface);
2616 break; 2802 break;
2617 case USB_FORMAT_TYPE_II: 2803 case UAC_FORMAT_TYPE_II:
2618 err = parse_audio_format_ii(chip, fp, format, fmt); 2804 err = parse_audio_format_ii(chip, fp, format, fmt, iface);
2619 break; 2805 break;
2620 default: 2806 default:
2621 snd_printd(KERN_INFO "%d:%u:%d : format type %d is not supported yet\n", 2807 snd_printd(KERN_INFO "%d:%u:%d : format type %d is not supported yet\n",
@@ -2633,7 +2819,7 @@ static int parse_audio_format(struct snd_usb_audio *chip, struct audioformat *fp
2633 if (chip->usb_id == USB_ID(0x041e, 0x3000) || 2819 if (chip->usb_id == USB_ID(0x041e, 0x3000) ||
2634 chip->usb_id == USB_ID(0x041e, 0x3020) || 2820 chip->usb_id == USB_ID(0x041e, 0x3020) ||
2635 chip->usb_id == USB_ID(0x041e, 0x3061)) { 2821 chip->usb_id == USB_ID(0x041e, 0x3061)) {
2636 if (fmt[3] == USB_FORMAT_TYPE_I && 2822 if (fmt[3] == UAC_FORMAT_TYPE_I &&
2637 fp->rates != SNDRV_PCM_RATE_48000 && 2823 fp->rates != SNDRV_PCM_RATE_48000 &&
2638 fp->rates != SNDRV_PCM_RATE_96000) 2824 fp->rates != SNDRV_PCM_RATE_96000)
2639 return -1; 2825 return -1;
@@ -2662,10 +2848,10 @@ static int parse_audio_endpoints(struct snd_usb_audio *chip, int iface_no)
2662 struct usb_host_interface *alts; 2848 struct usb_host_interface *alts;
2663 struct usb_interface_descriptor *altsd; 2849 struct usb_interface_descriptor *altsd;
2664 int i, altno, err, stream; 2850 int i, altno, err, stream;
2665 int format; 2851 int format = 0, num_channels = 0;
2666 struct audioformat *fp = NULL; 2852 struct audioformat *fp = NULL;
2667 unsigned char *fmt, *csep; 2853 unsigned char *fmt, *csep;
2668 int num; 2854 int num, protocol;
2669 2855
2670 dev = chip->dev; 2856 dev = chip->dev;
2671 2857
@@ -2684,10 +2870,11 @@ static int parse_audio_endpoints(struct snd_usb_audio *chip, int iface_no)
2684 for (i = 0; i < num; i++) { 2870 for (i = 0; i < num; i++) {
2685 alts = &iface->altsetting[i]; 2871 alts = &iface->altsetting[i];
2686 altsd = get_iface_desc(alts); 2872 altsd = get_iface_desc(alts);
2873 protocol = altsd->bInterfaceProtocol;
2687 /* skip invalid one */ 2874 /* skip invalid one */
2688 if ((altsd->bInterfaceClass != USB_CLASS_AUDIO && 2875 if ((altsd->bInterfaceClass != USB_CLASS_AUDIO &&
2689 altsd->bInterfaceClass != USB_CLASS_VENDOR_SPEC) || 2876 altsd->bInterfaceClass != USB_CLASS_VENDOR_SPEC) ||
2690 (altsd->bInterfaceSubClass != USB_SUBCLASS_AUDIO_STREAMING && 2877 (altsd->bInterfaceSubClass != USB_SUBCLASS_AUDIOSTREAMING &&
2691 altsd->bInterfaceSubClass != USB_SUBCLASS_VENDOR_SPEC) || 2878 altsd->bInterfaceSubClass != USB_SUBCLASS_VENDOR_SPEC) ||
2692 altsd->bNumEndpoints < 1 || 2879 altsd->bNumEndpoints < 1 ||
2693 le16_to_cpu(get_endpoint(alts, 0)->wMaxPacketSize) == 0) 2880 le16_to_cpu(get_endpoint(alts, 0)->wMaxPacketSize) == 0)
@@ -2708,30 +2895,65 @@ static int parse_audio_endpoints(struct snd_usb_audio *chip, int iface_no)
2708 continue; 2895 continue;
2709 2896
2710 /* get audio formats */ 2897 /* get audio formats */
2711 fmt = snd_usb_find_csint_desc(alts->extra, alts->extralen, NULL, AS_GENERAL); 2898 switch (protocol) {
2712 if (!fmt) { 2899 case UAC_VERSION_1: {
2713 snd_printk(KERN_ERR "%d:%u:%d : AS_GENERAL descriptor not found\n", 2900 struct uac_as_header_descriptor_v1 *as =
2714 dev->devnum, iface_no, altno); 2901 snd_usb_find_csint_desc(alts->extra, alts->extralen, NULL, UAC_AS_GENERAL);
2715 continue; 2902
2903 if (!as) {
2904 snd_printk(KERN_ERR "%d:%u:%d : UAC_AS_GENERAL descriptor not found\n",
2905 dev->devnum, iface_no, altno);
2906 continue;
2907 }
2908
2909 if (as->bLength < sizeof(*as)) {
2910 snd_printk(KERN_ERR "%d:%u:%d : invalid UAC_AS_GENERAL desc\n",
2911 dev->devnum, iface_no, altno);
2912 continue;
2913 }
2914
2915 format = le16_to_cpu(as->wFormatTag); /* remember the format value */
2916 break;
2716 } 2917 }
2717 2918
2718 if (fmt[0] < 7) { 2919 case UAC_VERSION_2: {
2719 snd_printk(KERN_ERR "%d:%u:%d : invalid AS_GENERAL desc\n", 2920 struct uac_as_header_descriptor_v2 *as =
2720 dev->devnum, iface_no, altno); 2921 snd_usb_find_csint_desc(alts->extra, alts->extralen, NULL, UAC_AS_GENERAL);
2721 continue; 2922
2923 if (!as) {
2924 snd_printk(KERN_ERR "%d:%u:%d : UAC_AS_GENERAL descriptor not found\n",
2925 dev->devnum, iface_no, altno);
2926 continue;
2927 }
2928
2929 if (as->bLength < sizeof(*as)) {
2930 snd_printk(KERN_ERR "%d:%u:%d : invalid UAC_AS_GENERAL desc\n",
2931 dev->devnum, iface_no, altno);
2932 continue;
2933 }
2934
2935 num_channels = as->bNrChannels;
2936 format = le32_to_cpu(as->bmFormats);
2937
2938 break;
2722 } 2939 }
2723 2940
2724 format = (fmt[6] << 8) | fmt[5]; /* remember the format value */ 2941 default:
2942 snd_printk(KERN_ERR "%d:%u:%d : unknown interface protocol %04x\n",
2943 dev->devnum, iface_no, altno, protocol);
2944 continue;
2945 }
2725 2946
2726 /* get format type */ 2947 /* get format type */
2727 fmt = snd_usb_find_csint_desc(alts->extra, alts->extralen, NULL, FORMAT_TYPE); 2948 fmt = snd_usb_find_csint_desc(alts->extra, alts->extralen, NULL, UAC_FORMAT_TYPE);
2728 if (!fmt) { 2949 if (!fmt) {
2729 snd_printk(KERN_ERR "%d:%u:%d : no FORMAT_TYPE desc\n", 2950 snd_printk(KERN_ERR "%d:%u:%d : no UAC_FORMAT_TYPE desc\n",
2730 dev->devnum, iface_no, altno); 2951 dev->devnum, iface_no, altno);
2731 continue; 2952 continue;
2732 } 2953 }
2733 if (fmt[0] < 8) { 2954 if (((protocol == UAC_VERSION_1) && (fmt[0] < 8)) ||
2734 snd_printk(KERN_ERR "%d:%u:%d : invalid FORMAT_TYPE desc\n", 2955 ((protocol == UAC_VERSION_2) && (fmt[0] != 6))) {
2956 snd_printk(KERN_ERR "%d:%u:%d : invalid UAC_FORMAT_TYPE desc\n",
2735 dev->devnum, iface_no, altno); 2957 dev->devnum, iface_no, altno);
2736 continue; 2958 continue;
2737 } 2959 }
@@ -2744,6 +2966,7 @@ static int parse_audio_endpoints(struct snd_usb_audio *chip, int iface_no)
2744 if (fmt[4] == 1 && fmt[5] == 2 && altno == 2 && num == 3 && 2966 if (fmt[4] == 1 && fmt[5] == 2 && altno == 2 && num == 3 &&
2745 fp && fp->altsetting == 1 && fp->channels == 1 && 2967 fp && fp->altsetting == 1 && fp->channels == 1 &&
2746 fp->format == SNDRV_PCM_FORMAT_S16_LE && 2968 fp->format == SNDRV_PCM_FORMAT_S16_LE &&
2969 protocol == UAC_VERSION_1 &&
2747 le16_to_cpu(get_endpoint(alts, 0)->wMaxPacketSize) == 2970 le16_to_cpu(get_endpoint(alts, 0)->wMaxPacketSize) ==
2748 fp->maxpacksize * 2) 2971 fp->maxpacksize * 2)
2749 continue; 2972 continue;
@@ -2752,7 +2975,7 @@ static int parse_audio_endpoints(struct snd_usb_audio *chip, int iface_no)
2752 /* Creamware Noah has this descriptor after the 2nd endpoint */ 2975 /* Creamware Noah has this descriptor after the 2nd endpoint */
2753 if (!csep && altsd->bNumEndpoints >= 2) 2976 if (!csep && altsd->bNumEndpoints >= 2)
2754 csep = snd_usb_find_desc(alts->endpoint[1].extra, alts->endpoint[1].extralen, NULL, USB_DT_CS_ENDPOINT); 2977 csep = snd_usb_find_desc(alts->endpoint[1].extra, alts->endpoint[1].extralen, NULL, USB_DT_CS_ENDPOINT);
2755 if (!csep || csep[0] < 7 || csep[2] != EP_GENERAL) { 2978 if (!csep || csep[0] < 7 || csep[2] != UAC_EP_GENERAL) {
2756 snd_printk(KERN_WARNING "%d:%u:%d : no or invalid" 2979 snd_printk(KERN_WARNING "%d:%u:%d : no or invalid"
2757 " class specific endpoint descriptor\n", 2980 " class specific endpoint descriptor\n",
2758 dev->devnum, iface_no, altno); 2981 dev->devnum, iface_no, altno);
@@ -2772,6 +2995,8 @@ static int parse_audio_endpoints(struct snd_usb_audio *chip, int iface_no)
2772 fp->ep_attr = get_endpoint(alts, 0)->bmAttributes; 2995 fp->ep_attr = get_endpoint(alts, 0)->bmAttributes;
2773 fp->datainterval = parse_datainterval(chip, alts); 2996 fp->datainterval = parse_datainterval(chip, alts);
2774 fp->maxpacksize = le16_to_cpu(get_endpoint(alts, 0)->wMaxPacketSize); 2997 fp->maxpacksize = le16_to_cpu(get_endpoint(alts, 0)->wMaxPacketSize);
2998 /* num_channels is only set for v2 interfaces */
2999 fp->channels = num_channels;
2775 if (snd_usb_get_speed(dev) == USB_SPEED_HIGH) 3000 if (snd_usb_get_speed(dev) == USB_SPEED_HIGH)
2776 fp->maxpacksize = (((fp->maxpacksize >> 11) & 3) + 1) 3001 fp->maxpacksize = (((fp->maxpacksize >> 11) & 3) + 1)
2777 * (fp->maxpacksize & 0x7ff); 3002 * (fp->maxpacksize & 0x7ff);
@@ -2784,12 +3009,12 @@ static int parse_audio_endpoints(struct snd_usb_audio *chip, int iface_no)
2784 /* Optoplay sets the sample rate attribute although 3009 /* Optoplay sets the sample rate attribute although
2785 * it seems not supporting it in fact. 3010 * it seems not supporting it in fact.
2786 */ 3011 */
2787 fp->attributes &= ~EP_CS_ATTR_SAMPLE_RATE; 3012 fp->attributes &= ~UAC_EP_CS_ATTR_SAMPLE_RATE;
2788 break; 3013 break;
2789 case USB_ID(0x041e, 0x3020): /* Creative SB Audigy 2 NX */ 3014 case USB_ID(0x041e, 0x3020): /* Creative SB Audigy 2 NX */
2790 case USB_ID(0x0763, 0x2003): /* M-Audio Audiophile USB */ 3015 case USB_ID(0x0763, 0x2003): /* M-Audio Audiophile USB */
2791 /* doesn't set the sample rate attribute, but supports it */ 3016 /* doesn't set the sample rate attribute, but supports it */
2792 fp->attributes |= EP_CS_ATTR_SAMPLE_RATE; 3017 fp->attributes |= UAC_EP_CS_ATTR_SAMPLE_RATE;
2793 break; 3018 break;
2794 case USB_ID(0x047f, 0x0ca1): /* plantronics headset */ 3019 case USB_ID(0x047f, 0x0ca1): /* plantronics headset */
2795 case USB_ID(0x077d, 0x07af): /* Griffin iMic (note that there is 3020 case USB_ID(0x077d, 0x07af): /* Griffin iMic (note that there is
@@ -2798,16 +3023,16 @@ static int parse_audio_endpoints(struct snd_usb_audio *chip, int iface_no)
2798 * plantronics headset and Griffin iMic have set adaptive-in 3023 * plantronics headset and Griffin iMic have set adaptive-in
2799 * although it's really not... 3024 * although it's really not...
2800 */ 3025 */
2801 fp->ep_attr &= ~EP_ATTR_MASK; 3026 fp->ep_attr &= ~USB_ENDPOINT_SYNCTYPE;
2802 if (stream == SNDRV_PCM_STREAM_PLAYBACK) 3027 if (stream == SNDRV_PCM_STREAM_PLAYBACK)
2803 fp->ep_attr |= EP_ATTR_ADAPTIVE; 3028 fp->ep_attr |= USB_ENDPOINT_SYNC_ADAPTIVE;
2804 else 3029 else
2805 fp->ep_attr |= EP_ATTR_SYNC; 3030 fp->ep_attr |= USB_ENDPOINT_SYNC_SYNC;
2806 break; 3031 break;
2807 } 3032 }
2808 3033
2809 /* ok, let's parse further... */ 3034 /* ok, let's parse further... */
2810 if (parse_audio_format(chip, fp, format, fmt, stream) < 0) { 3035 if (parse_audio_format(chip, fp, format, fmt, stream, alts) < 0) {
2811 kfree(fp->rate_table); 3036 kfree(fp->rate_table);
2812 kfree(fp); 3037 kfree(fp);
2813 continue; 3038 continue;
@@ -2849,6 +3074,65 @@ static void snd_usb_stream_disconnect(struct list_head *head)
2849 } 3074 }
2850} 3075}
2851 3076
3077static int snd_usb_create_stream(struct snd_usb_audio *chip, int ctrlif, int interface)
3078{
3079 struct usb_device *dev = chip->dev;
3080 struct usb_host_interface *alts;
3081 struct usb_interface_descriptor *altsd;
3082 struct usb_interface *iface = usb_ifnum_to_if(dev, interface);
3083
3084 if (!iface) {
3085 snd_printk(KERN_ERR "%d:%u:%d : does not exist\n",
3086 dev->devnum, ctrlif, interface);
3087 return -EINVAL;
3088 }
3089
3090 if (usb_interface_claimed(iface)) {
3091 snd_printdd(KERN_INFO "%d:%d:%d: skipping, already claimed\n",
3092 dev->devnum, ctrlif, interface);
3093 return -EINVAL;
3094 }
3095
3096 alts = &iface->altsetting[0];
3097 altsd = get_iface_desc(alts);
3098 if ((altsd->bInterfaceClass == USB_CLASS_AUDIO ||
3099 altsd->bInterfaceClass == USB_CLASS_VENDOR_SPEC) &&
3100 altsd->bInterfaceSubClass == USB_SUBCLASS_MIDISTREAMING) {
3101 int err = snd_usbmidi_create(chip->card, iface,
3102 &chip->midi_list, NULL);
3103 if (err < 0) {
3104 snd_printk(KERN_ERR "%d:%u:%d: cannot create sequencer device\n",
3105 dev->devnum, ctrlif, interface);
3106 return -EINVAL;
3107 }
3108 usb_driver_claim_interface(&usb_audio_driver, iface, (void *)-1L);
3109
3110 return 0;
3111 }
3112
3113 if ((altsd->bInterfaceClass != USB_CLASS_AUDIO &&
3114 altsd->bInterfaceClass != USB_CLASS_VENDOR_SPEC) ||
3115 altsd->bInterfaceSubClass != USB_SUBCLASS_AUDIOSTREAMING) {
3116 snd_printdd(KERN_ERR "%d:%u:%d: skipping non-supported interface %d\n",
3117 dev->devnum, ctrlif, interface, altsd->bInterfaceClass);
3118 /* skip non-supported classes */
3119 return -EINVAL;
3120 }
3121
3122 if (snd_usb_get_speed(dev) == USB_SPEED_LOW) {
3123 snd_printk(KERN_ERR "low speed audio streaming not supported\n");
3124 return -EINVAL;
3125 }
3126
3127 if (! parse_audio_endpoints(chip, interface)) {
3128 usb_set_interface(dev, interface, 0); /* reset the current interface */
3129 usb_driver_claim_interface(&usb_audio_driver, iface, (void *)-1L);
3130 return -EINVAL;
3131 }
3132
3133 return 0;
3134}
3135
2852/* 3136/*
2853 * parse audio control descriptor and create pcm/midi streams 3137 * parse audio control descriptor and create pcm/midi streams
2854 */ 3138 */
@@ -2856,65 +3140,81 @@ static int snd_usb_create_streams(struct snd_usb_audio *chip, int ctrlif)
2856{ 3140{
2857 struct usb_device *dev = chip->dev; 3141 struct usb_device *dev = chip->dev;
2858 struct usb_host_interface *host_iface; 3142 struct usb_host_interface *host_iface;
2859 struct usb_interface *iface; 3143 struct usb_interface_descriptor *altsd;
2860 unsigned char *p1; 3144 void *control_header;
2861 int i, j; 3145 int i, protocol;
2862 3146
2863 /* find audiocontrol interface */ 3147 /* find audiocontrol interface */
2864 host_iface = &usb_ifnum_to_if(dev, ctrlif)->altsetting[0]; 3148 host_iface = &usb_ifnum_to_if(dev, ctrlif)->altsetting[0];
2865 if (!(p1 = snd_usb_find_csint_desc(host_iface->extra, host_iface->extralen, NULL, HEADER))) { 3149 control_header = snd_usb_find_csint_desc(host_iface->extra,
2866 snd_printk(KERN_ERR "cannot find HEADER\n"); 3150 host_iface->extralen,
2867 return -EINVAL; 3151 NULL, UAC_HEADER);
2868 } 3152 altsd = get_iface_desc(host_iface);
2869 if (! p1[7] || p1[0] < 8 + p1[7]) { 3153 protocol = altsd->bInterfaceProtocol;
2870 snd_printk(KERN_ERR "invalid HEADER\n"); 3154
3155 if (!control_header) {
3156 snd_printk(KERN_ERR "cannot find UAC_HEADER\n");
2871 return -EINVAL; 3157 return -EINVAL;
2872 } 3158 }
2873 3159
2874 /* 3160 switch (protocol) {
2875 * parse all USB audio streaming interfaces 3161 case UAC_VERSION_1: {
2876 */ 3162 struct uac_ac_header_descriptor_v1 *h1 = control_header;
2877 for (i = 0; i < p1[7]; i++) { 3163
2878 struct usb_host_interface *alts; 3164 if (!h1->bInCollection) {
2879 struct usb_interface_descriptor *altsd; 3165 snd_printk(KERN_INFO "skipping empty audio interface (v1)\n");
2880 j = p1[8 + i]; 3166 return -EINVAL;
2881 iface = usb_ifnum_to_if(dev, j);
2882 if (!iface) {
2883 snd_printk(KERN_ERR "%d:%u:%d : does not exist\n",
2884 dev->devnum, ctrlif, j);
2885 continue;
2886 }
2887 if (usb_interface_claimed(iface)) {
2888 snd_printdd(KERN_INFO "%d:%d:%d: skipping, already claimed\n", dev->devnum, ctrlif, j);
2889 continue;
2890 } 3167 }
2891 alts = &iface->altsetting[0]; 3168
2892 altsd = get_iface_desc(alts); 3169 if (h1->bLength < sizeof(*h1) + h1->bInCollection) {
2893 if ((altsd->bInterfaceClass == USB_CLASS_AUDIO || 3170 snd_printk(KERN_ERR "invalid UAC_HEADER (v1)\n");
2894 altsd->bInterfaceClass == USB_CLASS_VENDOR_SPEC) && 3171 return -EINVAL;
2895 altsd->bInterfaceSubClass == USB_SUBCLASS_MIDI_STREAMING) {
2896 if (snd_usb_create_midi_interface(chip, iface, NULL) < 0) {
2897 snd_printk(KERN_ERR "%d:%u:%d: cannot create sequencer device\n", dev->devnum, ctrlif, j);
2898 continue;
2899 }
2900 usb_driver_claim_interface(&usb_audio_driver, iface, (void *)-1L);
2901 continue;
2902 } 3172 }
2903 if ((altsd->bInterfaceClass != USB_CLASS_AUDIO && 3173
2904 altsd->bInterfaceClass != USB_CLASS_VENDOR_SPEC) || 3174 for (i = 0; i < h1->bInCollection; i++)
2905 altsd->bInterfaceSubClass != USB_SUBCLASS_AUDIO_STREAMING) { 3175 snd_usb_create_stream(chip, ctrlif, h1->baInterfaceNr[i]);
2906 snd_printdd(KERN_ERR "%d:%u:%d: skipping non-supported interface %d\n", dev->devnum, ctrlif, j, altsd->bInterfaceClass); 3176
2907 /* skip non-supported classes */ 3177 break;
2908 continue; 3178 }
3179
3180 case UAC_VERSION_2: {
3181 struct uac_clock_source_descriptor *cs;
3182 struct usb_interface_assoc_descriptor *assoc =
3183 usb_ifnum_to_if(dev, ctrlif)->intf_assoc;
3184
3185 if (!assoc) {
3186 snd_printk(KERN_ERR "Audio class v2 interfaces need an interface association\n");
3187 return -EINVAL;
2909 } 3188 }
2910 if (snd_usb_get_speed(dev) == USB_SPEED_LOW) { 3189
2911 snd_printk(KERN_ERR "low speed audio streaming not supported\n"); 3190 /* FIXME: for now, we expect there is at least one clock source
2912 continue; 3191 * descriptor and we always take the first one.
3192 * We should properly support devices with multiple clock sources,
3193 * clock selectors and sample rate conversion units. */
3194
3195 cs = snd_usb_find_csint_desc(host_iface->extra, host_iface->extralen,
3196 NULL, UAC_CLOCK_SOURCE);
3197
3198 if (!cs) {
3199 snd_printk(KERN_ERR "CLOCK_SOURCE descriptor not found\n");
3200 return -EINVAL;
2913 } 3201 }
2914 if (! parse_audio_endpoints(chip, j)) { 3202
2915 usb_set_interface(dev, j, 0); /* reset the current interface */ 3203 chip->clock_id = cs->bClockID;
2916 usb_driver_claim_interface(&usb_audio_driver, iface, (void *)-1L); 3204
3205 for (i = 0; i < assoc->bInterfaceCount; i++) {
3206 int intf = assoc->bFirstInterface + i;
3207
3208 if (intf != ctrlif)
3209 snd_usb_create_stream(chip, ctrlif, intf);
2917 } 3210 }
3211
3212 break;
3213 }
3214
3215 default:
3216 snd_printk(KERN_ERR "unknown protocol version 0x%02x\n", protocol);
3217 return -EINVAL;
2918 } 3218 }
2919 3219
2920 return 0; 3220 return 0;
@@ -3005,7 +3305,7 @@ static int create_uaxx_quirk(struct snd_usb_audio *chip,
3005 static const struct audioformat ua_format = { 3305 static const struct audioformat ua_format = {
3006 .format = SNDRV_PCM_FORMAT_S24_3LE, 3306 .format = SNDRV_PCM_FORMAT_S24_3LE,
3007 .channels = 2, 3307 .channels = 2,
3008 .fmt_type = USB_FORMAT_TYPE_I, 3308 .fmt_type = UAC_FORMAT_TYPE_I,
3009 .altsetting = 1, 3309 .altsetting = 1,
3010 .altset_idx = 1, 3310 .altset_idx = 1,
3011 .rates = SNDRV_PCM_RATE_CONTINUOUS, 3311 .rates = SNDRV_PCM_RATE_CONTINUOUS,
@@ -3038,12 +3338,11 @@ static int create_uaxx_quirk(struct snd_usb_audio *chip,
3038 .type = QUIRK_MIDI_FIXED_ENDPOINT, 3338 .type = QUIRK_MIDI_FIXED_ENDPOINT,
3039 .data = &uaxx_ep 3339 .data = &uaxx_ep
3040 }; 3340 };
3041 if (chip->usb_id == USB_ID(0x0582, 0x002b)) 3341 const struct snd_usb_audio_quirk *quirk =
3042 return snd_usb_create_midi_interface(chip, iface, 3342 chip->usb_id == USB_ID(0x0582, 0x002b)
3043 &ua700_quirk); 3343 ? &ua700_quirk : &uaxx_quirk;
3044 else 3344 return snd_usbmidi_create(chip->card, iface,
3045 return snd_usb_create_midi_interface(chip, iface, 3345 &chip->midi_list, quirk);
3046 &uaxx_quirk);
3047 } 3346 }
3048 3347
3049 if (altsd->bNumEndpoints != 1) 3348 if (altsd->bNumEndpoints != 1)
@@ -3089,111 +3388,6 @@ static int create_uaxx_quirk(struct snd_usb_audio *chip,
3089 return 0; 3388 return 0;
3090} 3389}
3091 3390
3092/*
3093 * Create a stream for an Edirol UA-1000 interface.
3094 */
3095static int create_ua1000_quirk(struct snd_usb_audio *chip,
3096 struct usb_interface *iface,
3097 const struct snd_usb_audio_quirk *quirk)
3098{
3099 static const struct audioformat ua1000_format = {
3100 .format = SNDRV_PCM_FORMAT_S32_LE,
3101 .fmt_type = USB_FORMAT_TYPE_I,
3102 .altsetting = 1,
3103 .altset_idx = 1,
3104 .attributes = 0,
3105 .rates = SNDRV_PCM_RATE_CONTINUOUS,
3106 };
3107 struct usb_host_interface *alts;
3108 struct usb_interface_descriptor *altsd;
3109 struct audioformat *fp;
3110 int stream, err;
3111
3112 if (iface->num_altsetting != 2)
3113 return -ENXIO;
3114 alts = &iface->altsetting[1];
3115 altsd = get_iface_desc(alts);
3116 if (alts->extralen != 11 || alts->extra[1] != USB_DT_CS_INTERFACE ||
3117 altsd->bNumEndpoints != 1)
3118 return -ENXIO;
3119
3120 fp = kmemdup(&ua1000_format, sizeof(*fp), GFP_KERNEL);
3121 if (!fp)
3122 return -ENOMEM;
3123
3124 fp->channels = alts->extra[4];
3125 fp->iface = altsd->bInterfaceNumber;
3126 fp->endpoint = get_endpoint(alts, 0)->bEndpointAddress;
3127 fp->ep_attr = get_endpoint(alts, 0)->bmAttributes;
3128 fp->datainterval = parse_datainterval(chip, alts);
3129 fp->maxpacksize = le16_to_cpu(get_endpoint(alts, 0)->wMaxPacketSize);
3130 fp->rate_max = fp->rate_min = combine_triple(&alts->extra[8]);
3131
3132 stream = (fp->endpoint & USB_DIR_IN)
3133 ? SNDRV_PCM_STREAM_CAPTURE : SNDRV_PCM_STREAM_PLAYBACK;
3134 err = add_audio_endpoint(chip, stream, fp);
3135 if (err < 0) {
3136 kfree(fp);
3137 return err;
3138 }
3139 /* FIXME: playback must be synchronized to capture */
3140 usb_set_interface(chip->dev, fp->iface, 0);
3141 return 0;
3142}
3143
3144/*
3145 * Create a stream for an Edirol UA-101 interface.
3146 * Copy, paste and modify from Edirol UA-1000
3147 */
3148static int create_ua101_quirk(struct snd_usb_audio *chip,
3149 struct usb_interface *iface,
3150 const struct snd_usb_audio_quirk *quirk)
3151{
3152 static const struct audioformat ua101_format = {
3153 .format = SNDRV_PCM_FORMAT_S32_LE,
3154 .fmt_type = USB_FORMAT_TYPE_I,
3155 .altsetting = 1,
3156 .altset_idx = 1,
3157 .attributes = 0,
3158 .rates = SNDRV_PCM_RATE_CONTINUOUS,
3159 };
3160 struct usb_host_interface *alts;
3161 struct usb_interface_descriptor *altsd;
3162 struct audioformat *fp;
3163 int stream, err;
3164
3165 if (iface->num_altsetting != 2)
3166 return -ENXIO;
3167 alts = &iface->altsetting[1];
3168 altsd = get_iface_desc(alts);
3169 if (alts->extralen != 18 || alts->extra[1] != USB_DT_CS_INTERFACE ||
3170 altsd->bNumEndpoints != 1)
3171 return -ENXIO;
3172
3173 fp = kmemdup(&ua101_format, sizeof(*fp), GFP_KERNEL);
3174 if (!fp)
3175 return -ENOMEM;
3176
3177 fp->channels = alts->extra[11];
3178 fp->iface = altsd->bInterfaceNumber;
3179 fp->endpoint = get_endpoint(alts, 0)->bEndpointAddress;
3180 fp->ep_attr = get_endpoint(alts, 0)->bmAttributes;
3181 fp->datainterval = parse_datainterval(chip, alts);
3182 fp->maxpacksize = le16_to_cpu(get_endpoint(alts, 0)->wMaxPacketSize);
3183 fp->rate_max = fp->rate_min = combine_triple(&alts->extra[15]);
3184
3185 stream = (fp->endpoint & USB_DIR_IN)
3186 ? SNDRV_PCM_STREAM_CAPTURE : SNDRV_PCM_STREAM_PLAYBACK;
3187 err = add_audio_endpoint(chip, stream, fp);
3188 if (err < 0) {
3189 kfree(fp);
3190 return err;
3191 }
3192 /* FIXME: playback must be synchronized to capture */
3193 usb_set_interface(chip->dev, fp->iface, 0);
3194 return 0;
3195}
3196
3197static int snd_usb_create_quirk(struct snd_usb_audio *chip, 3391static int snd_usb_create_quirk(struct snd_usb_audio *chip,
3198 struct usb_interface *iface, 3392 struct usb_interface *iface,
3199 const struct snd_usb_audio_quirk *quirk); 3393 const struct snd_usb_audio_quirk *quirk);
@@ -3231,6 +3425,18 @@ static int ignore_interface_quirk(struct snd_usb_audio *chip,
3231 return 0; 3425 return 0;
3232} 3426}
3233 3427
3428/*
3429 * Allow alignment on audio sub-slot (channel samples) rather than
3430 * on audio slots (audio frames)
3431 */
3432static int create_align_transfer_quirk(struct snd_usb_audio *chip,
3433 struct usb_interface *iface,
3434 const struct snd_usb_audio_quirk *quirk)
3435{
3436 chip->txfr_quirk = 1;
3437 return 1; /* Continue with creating streams and mixer */
3438}
3439
3234 3440
3235/* 3441/*
3236 * boot quirks 3442 * boot quirks
@@ -3326,6 +3532,32 @@ static int snd_usb_cm6206_boot_quirk(struct usb_device *dev)
3326} 3532}
3327 3533
3328/* 3534/*
3535 * This call will put the synth in "USB send" mode, i.e it will send MIDI
3536 * messages through USB (this is disabled at startup). The synth will
3537 * acknowledge by sending a sysex on endpoint 0x85 and by displaying a USB
3538 * sign on its LCD. Values here are chosen based on sniffing USB traffic
3539 * under Windows.
3540 */
3541static int snd_usb_accessmusic_boot_quirk(struct usb_device *dev)
3542{
3543 int err, actual_length;
3544
3545 /* "midi send" enable */
3546 static const u8 seq[] = { 0x4e, 0x73, 0x52, 0x01 };
3547
3548 void *buf = kmemdup(seq, ARRAY_SIZE(seq), GFP_KERNEL);
3549 if (!buf)
3550 return -ENOMEM;
3551 err = usb_interrupt_msg(dev, usb_sndintpipe(dev, 0x05), buf,
3552 ARRAY_SIZE(seq), &actual_length, 1000);
3553 kfree(buf);
3554 if (err < 0)
3555 return err;
3556
3557 return 0;
3558}
3559
3560/*
3329 * Setup quirks 3561 * Setup quirks
3330 */ 3562 */
3331#define AUDIOPHILE_SET 0x01 /* if set, parse device_setup */ 3563#define AUDIOPHILE_SET 0x01 /* if set, parse device_setup */
@@ -3370,6 +3602,13 @@ static int audiophile_skip_setting_quirk(struct snd_usb_audio *chip,
3370 return 0; /* keep this altsetting */ 3602 return 0; /* keep this altsetting */
3371} 3603}
3372 3604
3605static int create_any_midi_quirk(struct snd_usb_audio *chip,
3606 struct usb_interface *intf,
3607 const struct snd_usb_audio_quirk *quirk)
3608{
3609 return snd_usbmidi_create(chip->card, intf, &chip->midi_list, quirk);
3610}
3611
3373/* 3612/*
3374 * audio-interface quirks 3613 * audio-interface quirks
3375 * 3614 *
@@ -3387,19 +3626,18 @@ static int snd_usb_create_quirk(struct snd_usb_audio *chip,
3387 static const quirk_func_t quirk_funcs[] = { 3626 static const quirk_func_t quirk_funcs[] = {
3388 [QUIRK_IGNORE_INTERFACE] = ignore_interface_quirk, 3627 [QUIRK_IGNORE_INTERFACE] = ignore_interface_quirk,
3389 [QUIRK_COMPOSITE] = create_composite_quirk, 3628 [QUIRK_COMPOSITE] = create_composite_quirk,
3390 [QUIRK_MIDI_STANDARD_INTERFACE] = snd_usb_create_midi_interface, 3629 [QUIRK_MIDI_STANDARD_INTERFACE] = create_any_midi_quirk,
3391 [QUIRK_MIDI_FIXED_ENDPOINT] = snd_usb_create_midi_interface, 3630 [QUIRK_MIDI_FIXED_ENDPOINT] = create_any_midi_quirk,
3392 [QUIRK_MIDI_YAMAHA] = snd_usb_create_midi_interface, 3631 [QUIRK_MIDI_YAMAHA] = create_any_midi_quirk,
3393 [QUIRK_MIDI_MIDIMAN] = snd_usb_create_midi_interface, 3632 [QUIRK_MIDI_MIDIMAN] = create_any_midi_quirk,
3394 [QUIRK_MIDI_NOVATION] = snd_usb_create_midi_interface, 3633 [QUIRK_MIDI_NOVATION] = create_any_midi_quirk,
3395 [QUIRK_MIDI_FASTLANE] = snd_usb_create_midi_interface, 3634 [QUIRK_MIDI_FASTLANE] = create_any_midi_quirk,
3396 [QUIRK_MIDI_EMAGIC] = snd_usb_create_midi_interface, 3635 [QUIRK_MIDI_EMAGIC] = create_any_midi_quirk,
3397 [QUIRK_MIDI_CME] = snd_usb_create_midi_interface, 3636 [QUIRK_MIDI_CME] = create_any_midi_quirk,
3398 [QUIRK_AUDIO_STANDARD_INTERFACE] = create_standard_audio_quirk, 3637 [QUIRK_AUDIO_STANDARD_INTERFACE] = create_standard_audio_quirk,
3399 [QUIRK_AUDIO_FIXED_ENDPOINT] = create_fixed_stream_quirk, 3638 [QUIRK_AUDIO_FIXED_ENDPOINT] = create_fixed_stream_quirk,
3400 [QUIRK_AUDIO_EDIROL_UA1000] = create_ua1000_quirk, 3639 [QUIRK_AUDIO_EDIROL_UAXX] = create_uaxx_quirk,
3401 [QUIRK_AUDIO_EDIROL_UA101] = create_ua101_quirk, 3640 [QUIRK_AUDIO_ALIGN_TRANSFER] = create_align_transfer_quirk
3402 [QUIRK_AUDIO_EDIROL_UAXX] = create_uaxx_quirk
3403 }; 3641 };
3404 3642
3405 if (quirk->type < QUIRK_TYPE_COUNT) { 3643 if (quirk->type < QUIRK_TYPE_COUNT) {
@@ -3588,7 +3826,6 @@ static void *snd_usb_audio_probe(struct usb_device *dev,
3588 ifnum = get_iface_desc(alts)->bInterfaceNumber; 3826 ifnum = get_iface_desc(alts)->bInterfaceNumber;
3589 id = USB_ID(le16_to_cpu(dev->descriptor.idVendor), 3827 id = USB_ID(le16_to_cpu(dev->descriptor.idVendor),
3590 le16_to_cpu(dev->descriptor.idProduct)); 3828 le16_to_cpu(dev->descriptor.idProduct));
3591
3592 if (quirk && quirk->ifnum >= 0 && ifnum != quirk->ifnum) 3829 if (quirk && quirk->ifnum >= 0 && ifnum != quirk->ifnum)
3593 goto __err_val; 3830 goto __err_val;
3594 3831
@@ -3616,6 +3853,12 @@ static void *snd_usb_audio_probe(struct usb_device *dev,
3616 goto __err_val; 3853 goto __err_val;
3617 } 3854 }
3618 3855
3856 /* Access Music VirusTI Desktop */
3857 if (id == USB_ID(0x133e, 0x0815)) {
3858 if (snd_usb_accessmusic_boot_quirk(dev) < 0)
3859 goto __err_val;
3860 }
3861
3619 /* 3862 /*
3620 * found a config. now register to ALSA 3863 * found a config. now register to ALSA
3621 */ 3864 */
@@ -3653,6 +3896,7 @@ static void *snd_usb_audio_probe(struct usb_device *dev,
3653 } 3896 }
3654 } 3897 }
3655 3898
3899 chip->txfr_quirk = 0;
3656 err = 1; /* continue */ 3900 err = 1; /* continue */
3657 if (quirk && quirk->ifnum != QUIRK_NO_INTERFACE) { 3901 if (quirk && quirk->ifnum != QUIRK_NO_INTERFACE) {
3658 /* need some special handlings */ 3902 /* need some special handlings */
diff --git a/sound/usb/usbaudio.h b/sound/usb/usbaudio.h
index e9a3a9dca15c..42c299cbf63a 100644
--- a/sound/usb/usbaudio.h
+++ b/sound/usb/usbaudio.h
@@ -21,93 +21,6 @@
21 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 21 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
22 */ 22 */
23 23
24
25/*
26 */
27
28#define USB_SUBCLASS_AUDIO_CONTROL 0x01
29#define USB_SUBCLASS_AUDIO_STREAMING 0x02
30#define USB_SUBCLASS_MIDI_STREAMING 0x03
31#define USB_SUBCLASS_VENDOR_SPEC 0xff
32
33#define HEADER 0x01
34#define INPUT_TERMINAL 0x02
35#define OUTPUT_TERMINAL 0x03
36#define MIXER_UNIT 0x04
37#define SELECTOR_UNIT 0x05
38#define FEATURE_UNIT 0x06
39#define PROCESSING_UNIT 0x07
40#define EXTENSION_UNIT 0x08
41
42#define AS_GENERAL 0x01
43#define FORMAT_TYPE 0x02
44#define FORMAT_SPECIFIC 0x03
45
46#define EP_GENERAL 0x01
47
48#define MS_GENERAL 0x01
49#define MIDI_IN_JACK 0x02
50#define MIDI_OUT_JACK 0x03
51
52/* endpoint attributes */
53#define EP_ATTR_MASK 0x0c
54#define EP_ATTR_ASYNC 0x04
55#define EP_ATTR_ADAPTIVE 0x08
56#define EP_ATTR_SYNC 0x0c
57
58/* cs endpoint attributes */
59#define EP_CS_ATTR_SAMPLE_RATE 0x01
60#define EP_CS_ATTR_PITCH_CONTROL 0x02
61#define EP_CS_ATTR_FILL_MAX 0x80
62
63/* Audio Class specific Request Codes */
64
65#define SET_CUR 0x01
66#define GET_CUR 0x81
67#define SET_MIN 0x02
68#define GET_MIN 0x82
69#define SET_MAX 0x03
70#define GET_MAX 0x83
71#define SET_RES 0x04
72#define GET_RES 0x84
73#define SET_MEM 0x05
74#define GET_MEM 0x85
75#define GET_STAT 0xff
76
77/* Terminal Control Selectors */
78
79#define COPY_PROTECT_CONTROL 0x01
80
81/* Endpoint Control Selectors */
82
83#define SAMPLING_FREQ_CONTROL 0x01
84#define PITCH_CONTROL 0x02
85
86/* Format Types */
87#define USB_FORMAT_TYPE_I 0x01
88#define USB_FORMAT_TYPE_II 0x02
89#define USB_FORMAT_TYPE_III 0x03
90
91/* type I */
92#define USB_AUDIO_FORMAT_PCM 0x01
93#define USB_AUDIO_FORMAT_PCM8 0x02
94#define USB_AUDIO_FORMAT_IEEE_FLOAT 0x03
95#define USB_AUDIO_FORMAT_ALAW 0x04
96#define USB_AUDIO_FORMAT_MU_LAW 0x05
97
98/* type II */
99#define USB_AUDIO_FORMAT_MPEG 0x1001
100#define USB_AUDIO_FORMAT_AC3 0x1002
101
102/* type III */
103#define USB_AUDIO_FORMAT_IEC1937_AC3 0x2001
104#define USB_AUDIO_FORMAT_IEC1937_MPEG1_LAYER1 0x2002
105#define USB_AUDIO_FORMAT_IEC1937_MPEG2_NOEXT 0x2003
106#define USB_AUDIO_FORMAT_IEC1937_MPEG2_EXT 0x2004
107#define USB_AUDIO_FORMAT_IEC1937_MPEG2_LAYER1_LS 0x2005
108#define USB_AUDIO_FORMAT_IEC1937_MPEG2_LAYER23_LS 0x2006
109
110
111/* maximum number of endpoints per interface */ 24/* maximum number of endpoints per interface */
112#define MIDI_MAX_ENDPOINTS 2 25#define MIDI_MAX_ENDPOINTS 2
113 26
@@ -125,14 +38,17 @@ struct snd_usb_audio {
125 struct snd_card *card; 38 struct snd_card *card;
126 u32 usb_id; 39 u32 usb_id;
127 int shutdown; 40 int shutdown;
41 unsigned int txfr_quirk:1; /* Subframe boundaries on transfers */
128 int num_interfaces; 42 int num_interfaces;
129 int num_suspended_intf; 43 int num_suspended_intf;
130 44
45 /* for audio class v2 */
46 int clock_id;
47
131 struct list_head pcm_list; /* list of pcm streams */ 48 struct list_head pcm_list; /* list of pcm streams */
132 int pcm_devs; 49 int pcm_devs;
133 50
134 struct list_head midi_list; /* list of midi interfaces */ 51 struct list_head midi_list; /* list of midi interfaces */
135 int next_midi_device;
136 52
137 struct list_head mixer_list; /* list of mixer interfaces */ 53 struct list_head mixer_list; /* list of mixer interfaces */
138}; 54};
@@ -159,9 +75,8 @@ enum quirk_type {
159 QUIRK_MIDI_US122L, 75 QUIRK_MIDI_US122L,
160 QUIRK_AUDIO_STANDARD_INTERFACE, 76 QUIRK_AUDIO_STANDARD_INTERFACE,
161 QUIRK_AUDIO_FIXED_ENDPOINT, 77 QUIRK_AUDIO_FIXED_ENDPOINT,
162 QUIRK_AUDIO_EDIROL_UA1000,
163 QUIRK_AUDIO_EDIROL_UA101,
164 QUIRK_AUDIO_EDIROL_UAXX, 78 QUIRK_AUDIO_EDIROL_UAXX,
79 QUIRK_AUDIO_ALIGN_TRANSFER,
165 80
166 QUIRK_TYPE_COUNT 81 QUIRK_TYPE_COUNT
167}; 82};
@@ -196,7 +111,7 @@ struct snd_usb_midi_endpoint_info {
196 111
197/* for QUIRK_AUDIO/MIDI_STANDARD_INTERFACE, data is NULL */ 112/* for QUIRK_AUDIO/MIDI_STANDARD_INTERFACE, data is NULL */
198 113
199/* for QUIRK_AUDIO_EDIROL_UA700_UA25/UA1000, data is NULL */ 114/* for QUIRK_AUDIO_EDIROL_UAXX, data is NULL */
200 115
201/* for QUIRK_IGNORE_INTERFACE, data is NULL */ 116/* for QUIRK_IGNORE_INTERFACE, data is NULL */
202 117
@@ -210,6 +125,16 @@ struct snd_usb_midi_endpoint_info {
210/* 125/*
211 */ 126 */
212 127
128/*E-mu USB samplerate control quirk*/
129enum {
130 EMU_QUIRK_SR_44100HZ = 0,
131 EMU_QUIRK_SR_48000HZ,
132 EMU_QUIRK_SR_88200HZ,
133 EMU_QUIRK_SR_96000HZ,
134 EMU_QUIRK_SR_176400HZ,
135 EMU_QUIRK_SR_192000HZ
136};
137
213#define combine_word(s) ((*(s)) | ((unsigned int)(s)[1] << 8)) 138#define combine_word(s) ((*(s)) | ((unsigned int)(s)[1] << 8))
214#define combine_triple(s) (combine_word(s) | ((unsigned int)(s)[2] << 16)) 139#define combine_triple(s) (combine_word(s) | ((unsigned int)(s)[2] << 16))
215#define combine_quad(s) (combine_triple(s) | ((unsigned int)(s)[3] << 24)) 140#define combine_quad(s) (combine_triple(s) | ((unsigned int)(s)[3] << 24))
@@ -227,12 +152,17 @@ int snd_usb_create_mixer(struct snd_usb_audio *chip, int ctrlif,
227 int ignore_error); 152 int ignore_error);
228void snd_usb_mixer_disconnect(struct list_head *p); 153void snd_usb_mixer_disconnect(struct list_head *p);
229 154
230int snd_usb_create_midi_interface(struct snd_usb_audio *chip, struct usb_interface *iface, 155int snd_usbmidi_create(struct snd_card *card,
231 const struct snd_usb_audio_quirk *quirk); 156 struct usb_interface *iface,
157 struct list_head *midi_list,
158 const struct snd_usb_audio_quirk *quirk);
232void snd_usbmidi_input_stop(struct list_head* p); 159void snd_usbmidi_input_stop(struct list_head* p);
233void snd_usbmidi_input_start(struct list_head* p); 160void snd_usbmidi_input_start(struct list_head* p);
234void snd_usbmidi_disconnect(struct list_head *p); 161void snd_usbmidi_disconnect(struct list_head *p);
235 162
163void snd_emuusb_set_samplerate(struct snd_usb_audio *chip,
164 unsigned char samplerate_id);
165
236/* 166/*
237 * retrieve usb_interface descriptor from the host interface 167 * retrieve usb_interface descriptor from the host interface
238 * (conditional for compatibility with the older API) 168 * (conditional for compatibility with the older API)
diff --git a/sound/usb/usbmidi.c b/sound/usb/usbmidi.c
index 0eff19ceb7e1..9e28b20cb2ce 100644
--- a/sound/usb/usbmidi.c
+++ b/sound/usb/usbmidi.c
@@ -1,7 +1,7 @@
1/* 1/*
2 * usbmidi.c - ALSA USB MIDI driver 2 * usbmidi.c - ALSA USB MIDI driver
3 * 3 *
4 * Copyright (c) 2002-2007 Clemens Ladisch 4 * Copyright (c) 2002-2009 Clemens Ladisch
5 * All rights reserved. 5 * All rights reserved.
6 * 6 *
7 * Based on the OSS usb-midi driver by NAGANO Daisuke, 7 * Based on the OSS usb-midi driver by NAGANO Daisuke,
@@ -46,7 +46,10 @@
46#include <linux/timer.h> 46#include <linux/timer.h>
47#include <linux/usb.h> 47#include <linux/usb.h>
48#include <linux/wait.h> 48#include <linux/wait.h>
49#include <linux/usb/audio.h>
50
49#include <sound/core.h> 51#include <sound/core.h>
52#include <sound/control.h>
50#include <sound/rawmidi.h> 53#include <sound/rawmidi.h>
51#include <sound/asequencer.h> 54#include <sound/asequencer.h>
52#include "usbaudio.h" 55#include "usbaudio.h"
@@ -101,7 +104,8 @@ struct usb_protocol_ops {
101}; 104};
102 105
103struct snd_usb_midi { 106struct snd_usb_midi {
104 struct snd_usb_audio *chip; 107 struct usb_device *dev;
108 struct snd_card *card;
105 struct usb_interface *iface; 109 struct usb_interface *iface;
106 const struct snd_usb_audio_quirk *quirk; 110 const struct snd_usb_audio_quirk *quirk;
107 struct snd_rawmidi *rmidi; 111 struct snd_rawmidi *rmidi;
@@ -109,13 +113,19 @@ struct snd_usb_midi {
109 struct list_head list; 113 struct list_head list;
110 struct timer_list error_timer; 114 struct timer_list error_timer;
111 spinlock_t disc_lock; 115 spinlock_t disc_lock;
116 struct mutex mutex;
117 u32 usb_id;
118 int next_midi_device;
112 119
113 struct snd_usb_midi_endpoint { 120 struct snd_usb_midi_endpoint {
114 struct snd_usb_midi_out_endpoint *out; 121 struct snd_usb_midi_out_endpoint *out;
115 struct snd_usb_midi_in_endpoint *in; 122 struct snd_usb_midi_in_endpoint *in;
116 } endpoints[MIDI_MAX_ENDPOINTS]; 123 } endpoints[MIDI_MAX_ENDPOINTS];
117 unsigned long input_triggered; 124 unsigned long input_triggered;
125 unsigned int opened;
118 unsigned char disconnected; 126 unsigned char disconnected;
127
128 struct snd_kcontrol *roland_load_ctl;
119}; 129};
120 130
121struct snd_usb_midi_out_endpoint { 131struct snd_usb_midi_out_endpoint {
@@ -255,7 +265,7 @@ static void snd_usbmidi_in_urb_complete(struct urb* urb)
255 } 265 }
256 } 266 }
257 267
258 urb->dev = ep->umidi->chip->dev; 268 urb->dev = ep->umidi->dev;
259 snd_usbmidi_submit_urb(urb, GFP_ATOMIC); 269 snd_usbmidi_submit_urb(urb, GFP_ATOMIC);
260} 270}
261 271
@@ -296,7 +306,7 @@ static void snd_usbmidi_do_output(struct snd_usb_midi_out_endpoint* ep)
296 unsigned long flags; 306 unsigned long flags;
297 307
298 spin_lock_irqsave(&ep->buffer_lock, flags); 308 spin_lock_irqsave(&ep->buffer_lock, flags);
299 if (ep->umidi->chip->shutdown) { 309 if (ep->umidi->disconnected) {
300 spin_unlock_irqrestore(&ep->buffer_lock, flags); 310 spin_unlock_irqrestore(&ep->buffer_lock, flags);
301 return; 311 return;
302 } 312 }
@@ -312,7 +322,7 @@ static void snd_usbmidi_do_output(struct snd_usb_midi_out_endpoint* ep)
312 322
313 dump_urb("sending", urb->transfer_buffer, 323 dump_urb("sending", urb->transfer_buffer,
314 urb->transfer_buffer_length); 324 urb->transfer_buffer_length);
315 urb->dev = ep->umidi->chip->dev; 325 urb->dev = ep->umidi->dev;
316 if (snd_usbmidi_submit_urb(urb, GFP_ATOMIC) < 0) 326 if (snd_usbmidi_submit_urb(urb, GFP_ATOMIC) < 0)
317 break; 327 break;
318 ep->active_urbs |= 1 << urb_index; 328 ep->active_urbs |= 1 << urb_index;
@@ -349,7 +359,7 @@ static void snd_usbmidi_error_timer(unsigned long data)
349 if (in && in->error_resubmit) { 359 if (in && in->error_resubmit) {
350 in->error_resubmit = 0; 360 in->error_resubmit = 0;
351 for (j = 0; j < INPUT_URBS; ++j) { 361 for (j = 0; j < INPUT_URBS; ++j) {
352 in->urbs[j]->dev = umidi->chip->dev; 362 in->urbs[j]->dev = umidi->dev;
353 snd_usbmidi_submit_urb(in->urbs[j], GFP_ATOMIC); 363 snd_usbmidi_submit_urb(in->urbs[j], GFP_ATOMIC);
354 } 364 }
355 } 365 }
@@ -369,7 +379,7 @@ static int send_bulk_static_data(struct snd_usb_midi_out_endpoint* ep,
369 return -ENOMEM; 379 return -ENOMEM;
370 dump_urb("sending", buf, len); 380 dump_urb("sending", buf, len);
371 if (ep->urbs[0].urb) 381 if (ep->urbs[0].urb)
372 err = usb_bulk_msg(ep->umidi->chip->dev, ep->urbs[0].urb->pipe, 382 err = usb_bulk_msg(ep->umidi->dev, ep->urbs[0].urb->pipe,
373 buf, len, NULL, 250); 383 buf, len, NULL, 250);
374 kfree(buf); 384 kfree(buf);
375 return err; 385 return err;
@@ -724,8 +734,7 @@ static void snd_usbmidi_us122l_output(struct snd_usb_midi_out_endpoint *ep,
724 734
725 if (!ep->ports[0].active) 735 if (!ep->ports[0].active)
726 return; 736 return;
727 count = snd_usb_get_speed(ep->umidi->chip->dev) == USB_SPEED_HIGH 737 count = snd_usb_get_speed(ep->umidi->dev) == USB_SPEED_HIGH ? 1 : 2;
728 ? 1 : 2;
729 count = snd_rawmidi_transmit(ep->ports[0].substream, 738 count = snd_rawmidi_transmit(ep->ports[0].substream,
730 urb->transfer_buffer, 739 urb->transfer_buffer,
731 count); 740 count);
@@ -879,6 +888,50 @@ static struct usb_protocol_ops snd_usbmidi_emagic_ops = {
879}; 888};
880 889
881 890
891static void update_roland_altsetting(struct snd_usb_midi* umidi)
892{
893 struct usb_interface *intf;
894 struct usb_host_interface *hostif;
895 struct usb_interface_descriptor *intfd;
896 int is_light_load;
897
898 intf = umidi->iface;
899 is_light_load = intf->cur_altsetting != intf->altsetting;
900 if (umidi->roland_load_ctl->private_value == is_light_load)
901 return;
902 hostif = &intf->altsetting[umidi->roland_load_ctl->private_value];
903 intfd = get_iface_desc(hostif);
904 snd_usbmidi_input_stop(&umidi->list);
905 usb_set_interface(umidi->dev, intfd->bInterfaceNumber,
906 intfd->bAlternateSetting);
907 snd_usbmidi_input_start(&umidi->list);
908}
909
910static void substream_open(struct snd_rawmidi_substream *substream, int open)
911{
912 struct snd_usb_midi* umidi = substream->rmidi->private_data;
913 struct snd_kcontrol *ctl;
914
915 mutex_lock(&umidi->mutex);
916 if (open) {
917 if (umidi->opened++ == 0 && umidi->roland_load_ctl) {
918 ctl = umidi->roland_load_ctl;
919 ctl->vd[0].access |= SNDRV_CTL_ELEM_ACCESS_INACTIVE;
920 snd_ctl_notify(umidi->card,
921 SNDRV_CTL_EVENT_MASK_INFO, &ctl->id);
922 update_roland_altsetting(umidi);
923 }
924 } else {
925 if (--umidi->opened == 0 && umidi->roland_load_ctl) {
926 ctl = umidi->roland_load_ctl;
927 ctl->vd[0].access &= ~SNDRV_CTL_ELEM_ACCESS_INACTIVE;
928 snd_ctl_notify(umidi->card,
929 SNDRV_CTL_EVENT_MASK_INFO, &ctl->id);
930 }
931 }
932 mutex_unlock(&umidi->mutex);
933}
934
882static int snd_usbmidi_output_open(struct snd_rawmidi_substream *substream) 935static int snd_usbmidi_output_open(struct snd_rawmidi_substream *substream)
883{ 936{
884 struct snd_usb_midi* umidi = substream->rmidi->private_data; 937 struct snd_usb_midi* umidi = substream->rmidi->private_data;
@@ -898,11 +951,13 @@ static int snd_usbmidi_output_open(struct snd_rawmidi_substream *substream)
898 } 951 }
899 substream->runtime->private_data = port; 952 substream->runtime->private_data = port;
900 port->state = STATE_UNKNOWN; 953 port->state = STATE_UNKNOWN;
954 substream_open(substream, 1);
901 return 0; 955 return 0;
902} 956}
903 957
904static int snd_usbmidi_output_close(struct snd_rawmidi_substream *substream) 958static int snd_usbmidi_output_close(struct snd_rawmidi_substream *substream)
905{ 959{
960 substream_open(substream, 0);
906 return 0; 961 return 0;
907} 962}
908 963
@@ -912,7 +967,7 @@ static void snd_usbmidi_output_trigger(struct snd_rawmidi_substream *substream,
912 967
913 port->active = up; 968 port->active = up;
914 if (up) { 969 if (up) {
915 if (port->ep->umidi->chip->shutdown) { 970 if (port->ep->umidi->disconnected) {
916 /* gobble up remaining bytes to prevent wait in 971 /* gobble up remaining bytes to prevent wait in
917 * snd_rawmidi_drain_output */ 972 * snd_rawmidi_drain_output */
918 while (!snd_rawmidi_transmit_empty(substream)) 973 while (!snd_rawmidi_transmit_empty(substream))
@@ -931,6 +986,8 @@ static void snd_usbmidi_output_drain(struct snd_rawmidi_substream *substream)
931 DEFINE_WAIT(wait); 986 DEFINE_WAIT(wait);
932 long timeout = msecs_to_jiffies(50); 987 long timeout = msecs_to_jiffies(50);
933 988
989 if (ep->umidi->disconnected)
990 return;
934 /* 991 /*
935 * The substream buffer is empty, but some data might still be in the 992 * The substream buffer is empty, but some data might still be in the
936 * currently active URBs, so we have to wait for those to complete. 993 * currently active URBs, so we have to wait for those to complete.
@@ -954,11 +1011,13 @@ static void snd_usbmidi_output_drain(struct snd_rawmidi_substream *substream)
954 1011
955static int snd_usbmidi_input_open(struct snd_rawmidi_substream *substream) 1012static int snd_usbmidi_input_open(struct snd_rawmidi_substream *substream)
956{ 1013{
1014 substream_open(substream, 1);
957 return 0; 1015 return 0;
958} 1016}
959 1017
960static int snd_usbmidi_input_close(struct snd_rawmidi_substream *substream) 1018static int snd_usbmidi_input_close(struct snd_rawmidi_substream *substream)
961{ 1019{
1020 substream_open(substream, 0);
962 return 0; 1021 return 0;
963} 1022}
964 1023
@@ -988,7 +1047,7 @@ static struct snd_rawmidi_ops snd_usbmidi_input_ops = {
988static void free_urb_and_buffer(struct snd_usb_midi *umidi, struct urb *urb, 1047static void free_urb_and_buffer(struct snd_usb_midi *umidi, struct urb *urb,
989 unsigned int buffer_length) 1048 unsigned int buffer_length)
990{ 1049{
991 usb_buffer_free(umidi->chip->dev, buffer_length, 1050 usb_buffer_free(umidi->dev, buffer_length,
992 urb->transfer_buffer, urb->transfer_dma); 1051 urb->transfer_buffer, urb->transfer_dma);
993 usb_free_urb(urb); 1052 usb_free_urb(urb);
994} 1053}
@@ -1035,24 +1094,24 @@ static int snd_usbmidi_in_endpoint_create(struct snd_usb_midi* umidi,
1035 } 1094 }
1036 } 1095 }
1037 if (ep_info->in_interval) 1096 if (ep_info->in_interval)
1038 pipe = usb_rcvintpipe(umidi->chip->dev, ep_info->in_ep); 1097 pipe = usb_rcvintpipe(umidi->dev, ep_info->in_ep);
1039 else 1098 else
1040 pipe = usb_rcvbulkpipe(umidi->chip->dev, ep_info->in_ep); 1099 pipe = usb_rcvbulkpipe(umidi->dev, ep_info->in_ep);
1041 length = usb_maxpacket(umidi->chip->dev, pipe, 0); 1100 length = usb_maxpacket(umidi->dev, pipe, 0);
1042 for (i = 0; i < INPUT_URBS; ++i) { 1101 for (i = 0; i < INPUT_URBS; ++i) {
1043 buffer = usb_buffer_alloc(umidi->chip->dev, length, GFP_KERNEL, 1102 buffer = usb_buffer_alloc(umidi->dev, length, GFP_KERNEL,
1044 &ep->urbs[i]->transfer_dma); 1103 &ep->urbs[i]->transfer_dma);
1045 if (!buffer) { 1104 if (!buffer) {
1046 snd_usbmidi_in_endpoint_delete(ep); 1105 snd_usbmidi_in_endpoint_delete(ep);
1047 return -ENOMEM; 1106 return -ENOMEM;
1048 } 1107 }
1049 if (ep_info->in_interval) 1108 if (ep_info->in_interval)
1050 usb_fill_int_urb(ep->urbs[i], umidi->chip->dev, 1109 usb_fill_int_urb(ep->urbs[i], umidi->dev,
1051 pipe, buffer, length, 1110 pipe, buffer, length,
1052 snd_usbmidi_in_urb_complete, 1111 snd_usbmidi_in_urb_complete,
1053 ep, ep_info->in_interval); 1112 ep, ep_info->in_interval);
1054 else 1113 else
1055 usb_fill_bulk_urb(ep->urbs[i], umidi->chip->dev, 1114 usb_fill_bulk_urb(ep->urbs[i], umidi->dev,
1056 pipe, buffer, length, 1115 pipe, buffer, length,
1057 snd_usbmidi_in_urb_complete, ep); 1116 snd_usbmidi_in_urb_complete, ep);
1058 ep->urbs[i]->transfer_flags = URB_NO_TRANSFER_DMA_MAP; 1117 ep->urbs[i]->transfer_flags = URB_NO_TRANSFER_DMA_MAP;
@@ -1062,27 +1121,25 @@ static int snd_usbmidi_in_endpoint_create(struct snd_usb_midi* umidi,
1062 return 0; 1121 return 0;
1063} 1122}
1064 1123
1065static unsigned int snd_usbmidi_count_bits(unsigned int x)
1066{
1067 unsigned int bits;
1068
1069 for (bits = 0; x; ++bits)
1070 x &= x - 1;
1071 return bits;
1072}
1073
1074/* 1124/*
1075 * Frees an output endpoint. 1125 * Frees an output endpoint.
1076 * May be called when ep hasn't been initialized completely. 1126 * May be called when ep hasn't been initialized completely.
1077 */ 1127 */
1078static void snd_usbmidi_out_endpoint_delete(struct snd_usb_midi_out_endpoint* ep) 1128static void snd_usbmidi_out_endpoint_clear(struct snd_usb_midi_out_endpoint *ep)
1079{ 1129{
1080 unsigned int i; 1130 unsigned int i;
1081 1131
1082 for (i = 0; i < OUTPUT_URBS; ++i) 1132 for (i = 0; i < OUTPUT_URBS; ++i)
1083 if (ep->urbs[i].urb) 1133 if (ep->urbs[i].urb) {
1084 free_urb_and_buffer(ep->umidi, ep->urbs[i].urb, 1134 free_urb_and_buffer(ep->umidi, ep->urbs[i].urb,
1085 ep->max_transfer); 1135 ep->max_transfer);
1136 ep->urbs[i].urb = NULL;
1137 }
1138}
1139
1140static void snd_usbmidi_out_endpoint_delete(struct snd_usb_midi_out_endpoint *ep)
1141{
1142 snd_usbmidi_out_endpoint_clear(ep);
1086 kfree(ep); 1143 kfree(ep);
1087} 1144}
1088 1145
@@ -1113,15 +1170,27 @@ static int snd_usbmidi_out_endpoint_create(struct snd_usb_midi* umidi,
1113 ep->urbs[i].ep = ep; 1170 ep->urbs[i].ep = ep;
1114 } 1171 }
1115 if (ep_info->out_interval) 1172 if (ep_info->out_interval)
1116 pipe = usb_sndintpipe(umidi->chip->dev, ep_info->out_ep); 1173 pipe = usb_sndintpipe(umidi->dev, ep_info->out_ep);
1117 else 1174 else
1118 pipe = usb_sndbulkpipe(umidi->chip->dev, ep_info->out_ep); 1175 pipe = usb_sndbulkpipe(umidi->dev, ep_info->out_ep);
1119 if (umidi->chip->usb_id == USB_ID(0x0a92, 0x1020)) /* ESI M4U */ 1176 switch (umidi->usb_id) {
1177 default:
1178 ep->max_transfer = usb_maxpacket(umidi->dev, pipe, 1);
1179 break;
1180 /*
1181 * Various chips declare a packet size larger than 4 bytes, but
1182 * do not actually work with larger packets:
1183 */
1184 case USB_ID(0x0a92, 0x1020): /* ESI M4U */
1185 case USB_ID(0x1430, 0x474b): /* RedOctane GH MIDI INTERFACE */
1186 case USB_ID(0x15ca, 0x0101): /* Textech USB Midi Cable */
1187 case USB_ID(0x15ca, 0x1806): /* Textech USB Midi Cable */
1188 case USB_ID(0x1a86, 0x752d): /* QinHeng CH345 "USB2.0-MIDI" */
1120 ep->max_transfer = 4; 1189 ep->max_transfer = 4;
1121 else 1190 break;
1122 ep->max_transfer = usb_maxpacket(umidi->chip->dev, pipe, 1); 1191 }
1123 for (i = 0; i < OUTPUT_URBS; ++i) { 1192 for (i = 0; i < OUTPUT_URBS; ++i) {
1124 buffer = usb_buffer_alloc(umidi->chip->dev, 1193 buffer = usb_buffer_alloc(umidi->dev,
1125 ep->max_transfer, GFP_KERNEL, 1194 ep->max_transfer, GFP_KERNEL,
1126 &ep->urbs[i].urb->transfer_dma); 1195 &ep->urbs[i].urb->transfer_dma);
1127 if (!buffer) { 1196 if (!buffer) {
@@ -1129,12 +1198,12 @@ static int snd_usbmidi_out_endpoint_create(struct snd_usb_midi* umidi,
1129 return -ENOMEM; 1198 return -ENOMEM;
1130 } 1199 }
1131 if (ep_info->out_interval) 1200 if (ep_info->out_interval)
1132 usb_fill_int_urb(ep->urbs[i].urb, umidi->chip->dev, 1201 usb_fill_int_urb(ep->urbs[i].urb, umidi->dev,
1133 pipe, buffer, ep->max_transfer, 1202 pipe, buffer, ep->max_transfer,
1134 snd_usbmidi_out_urb_complete, 1203 snd_usbmidi_out_urb_complete,
1135 &ep->urbs[i], ep_info->out_interval); 1204 &ep->urbs[i], ep_info->out_interval);
1136 else 1205 else
1137 usb_fill_bulk_urb(ep->urbs[i].urb, umidi->chip->dev, 1206 usb_fill_bulk_urb(ep->urbs[i].urb, umidi->dev,
1138 pipe, buffer, ep->max_transfer, 1207 pipe, buffer, ep->max_transfer,
1139 snd_usbmidi_out_urb_complete, 1208 snd_usbmidi_out_urb_complete,
1140 &ep->urbs[i]); 1209 &ep->urbs[i]);
@@ -1172,6 +1241,7 @@ static void snd_usbmidi_free(struct snd_usb_midi* umidi)
1172 if (ep->in) 1241 if (ep->in)
1173 snd_usbmidi_in_endpoint_delete(ep->in); 1242 snd_usbmidi_in_endpoint_delete(ep->in);
1174 } 1243 }
1244 mutex_destroy(&umidi->mutex);
1175 kfree(umidi); 1245 kfree(umidi);
1176} 1246}
1177 1247
@@ -1201,15 +1271,18 @@ void snd_usbmidi_disconnect(struct list_head* p)
1201 usb_kill_urb(ep->out->urbs[j].urb); 1271 usb_kill_urb(ep->out->urbs[j].urb);
1202 if (umidi->usb_protocol_ops->finish_out_endpoint) 1272 if (umidi->usb_protocol_ops->finish_out_endpoint)
1203 umidi->usb_protocol_ops->finish_out_endpoint(ep->out); 1273 umidi->usb_protocol_ops->finish_out_endpoint(ep->out);
1274 ep->out->active_urbs = 0;
1275 if (ep->out->drain_urbs) {
1276 ep->out->drain_urbs = 0;
1277 wake_up(&ep->out->drain_wait);
1278 }
1204 } 1279 }
1205 if (ep->in) 1280 if (ep->in)
1206 for (j = 0; j < INPUT_URBS; ++j) 1281 for (j = 0; j < INPUT_URBS; ++j)
1207 usb_kill_urb(ep->in->urbs[j]); 1282 usb_kill_urb(ep->in->urbs[j]);
1208 /* free endpoints here; later call can result in Oops */ 1283 /* free endpoints here; later call can result in Oops */
1209 if (ep->out) { 1284 if (ep->out)
1210 snd_usbmidi_out_endpoint_delete(ep->out); 1285 snd_usbmidi_out_endpoint_clear(ep->out);
1211 ep->out = NULL;
1212 }
1213 if (ep->in) { 1286 if (ep->in) {
1214 snd_usbmidi_in_endpoint_delete(ep->in); 1287 snd_usbmidi_in_endpoint_delete(ep->in);
1215 ep->in = NULL; 1288 ep->in = NULL;
@@ -1360,6 +1433,12 @@ static struct port_info {
1360 EXTERNAL_PORT(0x086a, 0x0001, 8, "%s Broadcast"), 1433 EXTERNAL_PORT(0x086a, 0x0001, 8, "%s Broadcast"),
1361 EXTERNAL_PORT(0x086a, 0x0002, 8, "%s Broadcast"), 1434 EXTERNAL_PORT(0x086a, 0x0002, 8, "%s Broadcast"),
1362 EXTERNAL_PORT(0x086a, 0x0003, 4, "%s Broadcast"), 1435 EXTERNAL_PORT(0x086a, 0x0003, 4, "%s Broadcast"),
1436 /* Access Music Virus TI */
1437 EXTERNAL_PORT(0x133e, 0x0815, 0, "%s MIDI"),
1438 PORT_INFO(0x133e, 0x0815, 1, "%s Synth", 0,
1439 SNDRV_SEQ_PORT_TYPE_MIDI_GENERIC |
1440 SNDRV_SEQ_PORT_TYPE_HARDWARE |
1441 SNDRV_SEQ_PORT_TYPE_SYNTHESIZER),
1363}; 1442};
1364 1443
1365static struct port_info *find_port_info(struct snd_usb_midi* umidi, int number) 1444static struct port_info *find_port_info(struct snd_usb_midi* umidi, int number)
@@ -1367,7 +1446,7 @@ static struct port_info *find_port_info(struct snd_usb_midi* umidi, int number)
1367 int i; 1446 int i;
1368 1447
1369 for (i = 0; i < ARRAY_SIZE(snd_usbmidi_port_info); ++i) { 1448 for (i = 0; i < ARRAY_SIZE(snd_usbmidi_port_info); ++i) {
1370 if (snd_usbmidi_port_info[i].id == umidi->chip->usb_id && 1449 if (snd_usbmidi_port_info[i].id == umidi->usb_id &&
1371 snd_usbmidi_port_info[i].port == number) 1450 snd_usbmidi_port_info[i].port == number)
1372 return &snd_usbmidi_port_info[i]; 1451 return &snd_usbmidi_port_info[i];
1373 } 1452 }
@@ -1405,7 +1484,7 @@ static void snd_usbmidi_init_substream(struct snd_usb_midi* umidi,
1405 port_info = find_port_info(umidi, number); 1484 port_info = find_port_info(umidi, number);
1406 name_format = port_info ? port_info->name : "%s MIDI %d"; 1485 name_format = port_info ? port_info->name : "%s MIDI %d";
1407 snprintf(substream->name, sizeof(substream->name), 1486 snprintf(substream->name, sizeof(substream->name),
1408 name_format, umidi->chip->card->shortname, number + 1); 1487 name_format, umidi->card->shortname, number + 1);
1409 1488
1410 *rsubstream = substream; 1489 *rsubstream = substream;
1411} 1490}
@@ -1475,7 +1554,7 @@ static int snd_usbmidi_get_ms_info(struct snd_usb_midi* umidi,
1475 if (hostif->extralen >= 7 && 1554 if (hostif->extralen >= 7 &&
1476 ms_header->bLength >= 7 && 1555 ms_header->bLength >= 7 &&
1477 ms_header->bDescriptorType == USB_DT_CS_INTERFACE && 1556 ms_header->bDescriptorType == USB_DT_CS_INTERFACE &&
1478 ms_header->bDescriptorSubtype == HEADER) 1557 ms_header->bDescriptorSubtype == UAC_HEADER)
1479 snd_printdd(KERN_INFO "MIDIStreaming version %02x.%02x\n", 1558 snd_printdd(KERN_INFO "MIDIStreaming version %02x.%02x\n",
1480 ms_header->bcdMSC[1], ms_header->bcdMSC[0]); 1559 ms_header->bcdMSC[1], ms_header->bcdMSC[0]);
1481 else 1560 else
@@ -1491,7 +1570,7 @@ static int snd_usbmidi_get_ms_info(struct snd_usb_midi* umidi,
1491 if (hostep->extralen < 4 || 1570 if (hostep->extralen < 4 ||
1492 ms_ep->bLength < 4 || 1571 ms_ep->bLength < 4 ||
1493 ms_ep->bDescriptorType != USB_DT_CS_ENDPOINT || 1572 ms_ep->bDescriptorType != USB_DT_CS_ENDPOINT ||
1494 ms_ep->bDescriptorSubtype != MS_GENERAL) 1573 ms_ep->bDescriptorSubtype != UAC_MS_GENERAL)
1495 continue; 1574 continue;
1496 if (usb_endpoint_dir_out(ep)) { 1575 if (usb_endpoint_dir_out(ep)) {
1497 if (endpoints[epidx].out_ep) { 1576 if (endpoints[epidx].out_ep) {
@@ -1503,7 +1582,7 @@ static int snd_usbmidi_get_ms_info(struct snd_usb_midi* umidi,
1503 endpoints[epidx].out_ep = usb_endpoint_num(ep); 1582 endpoints[epidx].out_ep = usb_endpoint_num(ep);
1504 if (usb_endpoint_xfer_int(ep)) 1583 if (usb_endpoint_xfer_int(ep))
1505 endpoints[epidx].out_interval = ep->bInterval; 1584 endpoints[epidx].out_interval = ep->bInterval;
1506 else if (snd_usb_get_speed(umidi->chip->dev) == USB_SPEED_LOW) 1585 else if (snd_usb_get_speed(umidi->dev) == USB_SPEED_LOW)
1507 /* 1586 /*
1508 * Low speed bulk transfers don't exist, so 1587 * Low speed bulk transfers don't exist, so
1509 * force interrupt transfers for devices like 1588 * force interrupt transfers for devices like
@@ -1523,7 +1602,7 @@ static int snd_usbmidi_get_ms_info(struct snd_usb_midi* umidi,
1523 endpoints[epidx].in_ep = usb_endpoint_num(ep); 1602 endpoints[epidx].in_ep = usb_endpoint_num(ep);
1524 if (usb_endpoint_xfer_int(ep)) 1603 if (usb_endpoint_xfer_int(ep))
1525 endpoints[epidx].in_interval = ep->bInterval; 1604 endpoints[epidx].in_interval = ep->bInterval;
1526 else if (snd_usb_get_speed(umidi->chip->dev) == USB_SPEED_LOW) 1605 else if (snd_usb_get_speed(umidi->dev) == USB_SPEED_LOW)
1527 endpoints[epidx].in_interval = 1; 1606 endpoints[epidx].in_interval = 1;
1528 endpoints[epidx].in_cables = (1 << ms_ep->bNumEmbMIDIJack) - 1; 1607 endpoints[epidx].in_cables = (1 << ms_ep->bNumEmbMIDIJack) - 1;
1529 snd_printdd(KERN_INFO "EP %02X: %d jack(s)\n", 1608 snd_printdd(KERN_INFO "EP %02X: %d jack(s)\n",
@@ -1533,6 +1612,52 @@ static int snd_usbmidi_get_ms_info(struct snd_usb_midi* umidi,
1533 return 0; 1612 return 0;
1534} 1613}
1535 1614
1615static int roland_load_info(struct snd_kcontrol *kcontrol,
1616 struct snd_ctl_elem_info *info)
1617{
1618 static const char *const names[] = { "High Load", "Light Load" };
1619
1620 info->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED;
1621 info->count = 1;
1622 info->value.enumerated.items = 2;
1623 if (info->value.enumerated.item > 1)
1624 info->value.enumerated.item = 1;
1625 strcpy(info->value.enumerated.name, names[info->value.enumerated.item]);
1626 return 0;
1627}
1628
1629static int roland_load_get(struct snd_kcontrol *kcontrol,
1630 struct snd_ctl_elem_value *value)
1631{
1632 value->value.enumerated.item[0] = kcontrol->private_value;
1633 return 0;
1634}
1635
1636static int roland_load_put(struct snd_kcontrol *kcontrol,
1637 struct snd_ctl_elem_value *value)
1638{
1639 struct snd_usb_midi* umidi = kcontrol->private_data;
1640 int changed;
1641
1642 if (value->value.enumerated.item[0] > 1)
1643 return -EINVAL;
1644 mutex_lock(&umidi->mutex);
1645 changed = value->value.enumerated.item[0] != kcontrol->private_value;
1646 if (changed)
1647 kcontrol->private_value = value->value.enumerated.item[0];
1648 mutex_unlock(&umidi->mutex);
1649 return changed;
1650}
1651
1652static struct snd_kcontrol_new roland_load_ctl = {
1653 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
1654 .name = "MIDI Input Mode",
1655 .info = roland_load_info,
1656 .get = roland_load_get,
1657 .put = roland_load_put,
1658 .private_value = 1,
1659};
1660
1536/* 1661/*
1537 * On Roland devices, use the second alternate setting to be able to use 1662 * On Roland devices, use the second alternate setting to be able to use
1538 * the interrupt input endpoint. 1663 * the interrupt input endpoint.
@@ -1556,8 +1681,12 @@ static void snd_usbmidi_switch_roland_altsetting(struct snd_usb_midi* umidi)
1556 1681
1557 snd_printdd(KERN_INFO "switching to altsetting %d with int ep\n", 1682 snd_printdd(KERN_INFO "switching to altsetting %d with int ep\n",
1558 intfd->bAlternateSetting); 1683 intfd->bAlternateSetting);
1559 usb_set_interface(umidi->chip->dev, intfd->bInterfaceNumber, 1684 usb_set_interface(umidi->dev, intfd->bInterfaceNumber,
1560 intfd->bAlternateSetting); 1685 intfd->bAlternateSetting);
1686
1687 umidi->roland_load_ctl = snd_ctl_new1(&roland_load_ctl, umidi);
1688 if (snd_ctl_add(umidi->card, umidi->roland_load_ctl) < 0)
1689 umidi->roland_load_ctl = NULL;
1561} 1690}
1562 1691
1563/* 1692/*
@@ -1573,7 +1702,7 @@ static int snd_usbmidi_detect_endpoints(struct snd_usb_midi* umidi,
1573 struct usb_endpoint_descriptor* epd; 1702 struct usb_endpoint_descriptor* epd;
1574 int i, out_eps = 0, in_eps = 0; 1703 int i, out_eps = 0, in_eps = 0;
1575 1704
1576 if (USB_ID_VENDOR(umidi->chip->usb_id) == 0x0582) 1705 if (USB_ID_VENDOR(umidi->usb_id) == 0x0582)
1577 snd_usbmidi_switch_roland_altsetting(umidi); 1706 snd_usbmidi_switch_roland_altsetting(umidi);
1578 1707
1579 if (endpoint[0].out_ep || endpoint[0].in_ep) 1708 if (endpoint[0].out_ep || endpoint[0].in_ep)
@@ -1653,9 +1782,9 @@ static int snd_usbmidi_detect_yamaha(struct snd_usb_midi* umidi,
1653 cs_desc < hostif->extra + hostif->extralen && cs_desc[0] >= 2; 1782 cs_desc < hostif->extra + hostif->extralen && cs_desc[0] >= 2;
1654 cs_desc += cs_desc[0]) { 1783 cs_desc += cs_desc[0]) {
1655 if (cs_desc[1] == USB_DT_CS_INTERFACE) { 1784 if (cs_desc[1] == USB_DT_CS_INTERFACE) {
1656 if (cs_desc[2] == MIDI_IN_JACK) 1785 if (cs_desc[2] == UAC_MIDI_IN_JACK)
1657 endpoint->in_cables = (endpoint->in_cables << 1) | 1; 1786 endpoint->in_cables = (endpoint->in_cables << 1) | 1;
1658 else if (cs_desc[2] == MIDI_OUT_JACK) 1787 else if (cs_desc[2] == UAC_MIDI_OUT_JACK)
1659 endpoint->out_cables = (endpoint->out_cables << 1) | 1; 1788 endpoint->out_cables = (endpoint->out_cables << 1) | 1;
1660 } 1789 }
1661 } 1790 }
@@ -1760,12 +1889,12 @@ static int snd_usbmidi_create_rawmidi(struct snd_usb_midi* umidi,
1760 struct snd_rawmidi *rmidi; 1889 struct snd_rawmidi *rmidi;
1761 int err; 1890 int err;
1762 1891
1763 err = snd_rawmidi_new(umidi->chip->card, "USB MIDI", 1892 err = snd_rawmidi_new(umidi->card, "USB MIDI",
1764 umidi->chip->next_midi_device++, 1893 umidi->next_midi_device++,
1765 out_ports, in_ports, &rmidi); 1894 out_ports, in_ports, &rmidi);
1766 if (err < 0) 1895 if (err < 0)
1767 return err; 1896 return err;
1768 strcpy(rmidi->name, umidi->chip->card->shortname); 1897 strcpy(rmidi->name, umidi->card->shortname);
1769 rmidi->info_flags = SNDRV_RAWMIDI_INFO_OUTPUT | 1898 rmidi->info_flags = SNDRV_RAWMIDI_INFO_OUTPUT |
1770 SNDRV_RAWMIDI_INFO_INPUT | 1899 SNDRV_RAWMIDI_INFO_INPUT |
1771 SNDRV_RAWMIDI_INFO_DUPLEX; 1900 SNDRV_RAWMIDI_INFO_DUPLEX;
@@ -1804,7 +1933,7 @@ static void snd_usbmidi_input_start_ep(struct snd_usb_midi_in_endpoint* ep)
1804 return; 1933 return;
1805 for (i = 0; i < INPUT_URBS; ++i) { 1934 for (i = 0; i < INPUT_URBS; ++i) {
1806 struct urb* urb = ep->urbs[i]; 1935 struct urb* urb = ep->urbs[i];
1807 urb->dev = ep->umidi->chip->dev; 1936 urb->dev = ep->umidi->dev;
1808 snd_usbmidi_submit_urb(urb, GFP_KERNEL); 1937 snd_usbmidi_submit_urb(urb, GFP_KERNEL);
1809 } 1938 }
1810} 1939}
@@ -1825,9 +1954,10 @@ void snd_usbmidi_input_start(struct list_head* p)
1825/* 1954/*
1826 * Creates and registers everything needed for a MIDI streaming interface. 1955 * Creates and registers everything needed for a MIDI streaming interface.
1827 */ 1956 */
1828int snd_usb_create_midi_interface(struct snd_usb_audio* chip, 1957int snd_usbmidi_create(struct snd_card *card,
1829 struct usb_interface* iface, 1958 struct usb_interface* iface,
1830 const struct snd_usb_audio_quirk* quirk) 1959 struct list_head *midi_list,
1960 const struct snd_usb_audio_quirk* quirk)
1831{ 1961{
1832 struct snd_usb_midi* umidi; 1962 struct snd_usb_midi* umidi;
1833 struct snd_usb_midi_endpoint_info endpoints[MIDI_MAX_ENDPOINTS]; 1963 struct snd_usb_midi_endpoint_info endpoints[MIDI_MAX_ENDPOINTS];
@@ -1837,12 +1967,16 @@ int snd_usb_create_midi_interface(struct snd_usb_audio* chip,
1837 umidi = kzalloc(sizeof(*umidi), GFP_KERNEL); 1967 umidi = kzalloc(sizeof(*umidi), GFP_KERNEL);
1838 if (!umidi) 1968 if (!umidi)
1839 return -ENOMEM; 1969 return -ENOMEM;
1840 umidi->chip = chip; 1970 umidi->dev = interface_to_usbdev(iface);
1971 umidi->card = card;
1841 umidi->iface = iface; 1972 umidi->iface = iface;
1842 umidi->quirk = quirk; 1973 umidi->quirk = quirk;
1843 umidi->usb_protocol_ops = &snd_usbmidi_standard_ops; 1974 umidi->usb_protocol_ops = &snd_usbmidi_standard_ops;
1844 init_timer(&umidi->error_timer); 1975 init_timer(&umidi->error_timer);
1845 spin_lock_init(&umidi->disc_lock); 1976 spin_lock_init(&umidi->disc_lock);
1977 mutex_init(&umidi->mutex);
1978 umidi->usb_id = USB_ID(le16_to_cpu(umidi->dev->descriptor.idVendor),
1979 le16_to_cpu(umidi->dev->descriptor.idProduct));
1846 umidi->error_timer.function = snd_usbmidi_error_timer; 1980 umidi->error_timer.function = snd_usbmidi_error_timer;
1847 umidi->error_timer.data = (unsigned long)umidi; 1981 umidi->error_timer.data = (unsigned long)umidi;
1848 1982
@@ -1851,7 +1985,7 @@ int snd_usb_create_midi_interface(struct snd_usb_audio* chip,
1851 switch (quirk ? quirk->type : QUIRK_MIDI_STANDARD_INTERFACE) { 1985 switch (quirk ? quirk->type : QUIRK_MIDI_STANDARD_INTERFACE) {
1852 case QUIRK_MIDI_STANDARD_INTERFACE: 1986 case QUIRK_MIDI_STANDARD_INTERFACE:
1853 err = snd_usbmidi_get_ms_info(umidi, endpoints); 1987 err = snd_usbmidi_get_ms_info(umidi, endpoints);
1854 if (chip->usb_id == USB_ID(0x0763, 0x0150)) /* M-Audio Uno */ 1988 if (umidi->usb_id == USB_ID(0x0763, 0x0150)) /* M-Audio Uno */
1855 umidi->usb_protocol_ops = 1989 umidi->usb_protocol_ops =
1856 &snd_usbmidi_maudio_broken_running_status_ops; 1990 &snd_usbmidi_maudio_broken_running_status_ops;
1857 break; 1991 break;
@@ -1887,7 +2021,7 @@ int snd_usb_create_midi_interface(struct snd_usb_audio* chip,
1887 * interface 0, so we have to make sure that the USB core looks 2021 * interface 0, so we have to make sure that the USB core looks
1888 * again at interface 0 by calling usb_set_interface() on it. 2022 * again at interface 0 by calling usb_set_interface() on it.
1889 */ 2023 */
1890 usb_set_interface(umidi->chip->dev, 0, 0); 2024 usb_set_interface(umidi->dev, 0, 0);
1891 err = snd_usbmidi_detect_per_port_endpoints(umidi, endpoints); 2025 err = snd_usbmidi_detect_per_port_endpoints(umidi, endpoints);
1892 break; 2026 break;
1893 case QUIRK_MIDI_EMAGIC: 2027 case QUIRK_MIDI_EMAGIC:
@@ -1914,8 +2048,8 @@ int snd_usb_create_midi_interface(struct snd_usb_audio* chip,
1914 out_ports = 0; 2048 out_ports = 0;
1915 in_ports = 0; 2049 in_ports = 0;
1916 for (i = 0; i < MIDI_MAX_ENDPOINTS; ++i) { 2050 for (i = 0; i < MIDI_MAX_ENDPOINTS; ++i) {
1917 out_ports += snd_usbmidi_count_bits(endpoints[i].out_cables); 2051 out_ports += hweight16(endpoints[i].out_cables);
1918 in_ports += snd_usbmidi_count_bits(endpoints[i].in_cables); 2052 in_ports += hweight16(endpoints[i].in_cables);
1919 } 2053 }
1920 err = snd_usbmidi_create_rawmidi(umidi, out_ports, in_ports); 2054 err = snd_usbmidi_create_rawmidi(umidi, out_ports, in_ports);
1921 if (err < 0) { 2055 if (err < 0) {
@@ -1933,14 +2067,14 @@ int snd_usb_create_midi_interface(struct snd_usb_audio* chip,
1933 return err; 2067 return err;
1934 } 2068 }
1935 2069
1936 list_add(&umidi->list, &umidi->chip->midi_list); 2070 list_add_tail(&umidi->list, midi_list);
1937 2071
1938 for (i = 0; i < MIDI_MAX_ENDPOINTS; ++i) 2072 for (i = 0; i < MIDI_MAX_ENDPOINTS; ++i)
1939 snd_usbmidi_input_start_ep(umidi->endpoints[i].in); 2073 snd_usbmidi_input_start_ep(umidi->endpoints[i].in);
1940 return 0; 2074 return 0;
1941} 2075}
1942 2076
1943EXPORT_SYMBOL(snd_usb_create_midi_interface); 2077EXPORT_SYMBOL(snd_usbmidi_create);
1944EXPORT_SYMBOL(snd_usbmidi_input_stop); 2078EXPORT_SYMBOL(snd_usbmidi_input_stop);
1945EXPORT_SYMBOL(snd_usbmidi_input_start); 2079EXPORT_SYMBOL(snd_usbmidi_input_start);
1946EXPORT_SYMBOL(snd_usbmidi_disconnect); 2080EXPORT_SYMBOL(snd_usbmidi_disconnect);
diff --git a/sound/usb/usbmixer.c b/sound/usb/usbmixer.c
index c998220b99c6..8e8f871b74ca 100644
--- a/sound/usb/usbmixer.c
+++ b/sound/usb/usbmixer.c
@@ -32,6 +32,8 @@
32#include <linux/slab.h> 32#include <linux/slab.h>
33#include <linux/string.h> 33#include <linux/string.h>
34#include <linux/usb.h> 34#include <linux/usb.h>
35#include <linux/usb/audio.h>
36
35#include <sound/core.h> 37#include <sound/core.h>
36#include <sound/control.h> 38#include <sound/control.h>
37#include <sound/hwdep.h> 39#include <sound/hwdep.h>
@@ -69,13 +71,16 @@ static const struct rc_config {
69 { USB_ID(0x041e, 0x3048), 2, 2, 6, 6, 2, 0x6e91 }, /* Toshiba SB0500 */ 71 { USB_ID(0x041e, 0x3048), 2, 2, 6, 6, 2, 0x6e91 }, /* Toshiba SB0500 */
70}; 72};
71 73
74#define MAX_ID_ELEMS 256
75
72struct usb_mixer_interface { 76struct usb_mixer_interface {
73 struct snd_usb_audio *chip; 77 struct snd_usb_audio *chip;
74 unsigned int ctrlif; 78 unsigned int ctrlif;
75 struct list_head list; 79 struct list_head list;
76 unsigned int ignore_ctl_error; 80 unsigned int ignore_ctl_error;
77 struct urb *urb; 81 struct urb *urb;
78 struct usb_mixer_elem_info **id_elems; /* array[256], indexed by unit id */ 82 /* array[MAX_ID_ELEMS], indexed by unit id */
83 struct usb_mixer_elem_info **id_elems;
79 84
80 /* Sound Blaster remote control stuff */ 85 /* Sound Blaster remote control stuff */
81 const struct rc_config *rc_cfg; 86 const struct rc_config *rc_cfg;
@@ -105,7 +110,7 @@ struct mixer_build {
105 struct usb_mixer_interface *mixer; 110 struct usb_mixer_interface *mixer;
106 unsigned char *buffer; 111 unsigned char *buffer;
107 unsigned int buflen; 112 unsigned int buflen;
108 DECLARE_BITMAP(unitbitmap, 256); 113 DECLARE_BITMAP(unitbitmap, MAX_ID_ELEMS);
109 struct usb_audio_term oterm; 114 struct usb_audio_term oterm;
110 const struct usbmix_name_map *map; 115 const struct usbmix_name_map *map;
111 const struct usbmix_selector_map *selector_map; 116 const struct usbmix_selector_map *selector_map;
@@ -123,6 +128,7 @@ struct usb_mixer_elem_info {
123 int channels; 128 int channels;
124 int val_type; 129 int val_type;
125 int min, max, res; 130 int min, max, res;
131 int dBmin, dBmax;
126 int cached; 132 int cached;
127 int cache_val[MAX_CHANNELS]; 133 int cache_val[MAX_CHANNELS];
128 u8 initialized; 134 u8 initialized;
@@ -186,6 +192,21 @@ enum {
186 USB_PROC_DCR_RELEASE = 6, 192 USB_PROC_DCR_RELEASE = 6,
187}; 193};
188 194
195/*E-mu 0202(0404) eXtension Unit(XU) control*/
196enum {
197 USB_XU_CLOCK_RATE = 0xe301,
198 USB_XU_CLOCK_SOURCE = 0xe302,
199 USB_XU_DIGITAL_IO_STATUS = 0xe303,
200 USB_XU_DEVICE_OPTIONS = 0xe304,
201 USB_XU_DIRECT_MONITORING = 0xe305,
202 USB_XU_METERING = 0xe306
203};
204enum {
205 USB_XU_CLOCK_SOURCE_SELECTOR = 0x02, /* clock source*/
206 USB_XU_CLOCK_RATE_SELECTOR = 0x03, /* clock rate */
207 USB_XU_DIGITAL_FORMAT_SELECTOR = 0x01, /* the spdif format */
208 USB_XU_SOFT_LIMIT_SELECTOR = 0x03 /* soft limiter */
209};
189 210
190/* 211/*
191 * manual mapping of mixer names 212 * manual mapping of mixer names
@@ -194,42 +215,50 @@ enum {
194 */ 215 */
195#include "usbmixer_maps.c" 216#include "usbmixer_maps.c"
196 217
197/* get the mapped name if the unit matches */ 218static const struct usbmix_name_map *
198static int check_mapped_name(struct mixer_build *state, int unitid, int control, char *buf, int buflen) 219find_map(struct mixer_build *state, int unitid, int control)
199{ 220{
200 const struct usbmix_name_map *p; 221 const struct usbmix_name_map *p = state->map;
201 222
202 if (! state->map) 223 if (!p)
203 return 0; 224 return NULL;
204 225
205 for (p = state->map; p->id; p++) { 226 for (p = state->map; p->id; p++) {
206 if (p->id == unitid && p->name && 227 if (p->id == unitid &&
207 (! control || ! p->control || control == p->control)) { 228 (!control || !p->control || control == p->control))
208 buflen--; 229 return p;
209 return strlcpy(buf, p->name, buflen);
210 }
211 } 230 }
212 return 0; 231 return NULL;
213} 232}
214 233
215/* check whether the control should be ignored */ 234/* get the mapped name if the unit matches */
216static int check_ignored_ctl(struct mixer_build *state, int unitid, int control) 235static int
236check_mapped_name(const struct usbmix_name_map *p, char *buf, int buflen)
217{ 237{
218 const struct usbmix_name_map *p; 238 if (!p || !p->name)
239 return 0;
240
241 buflen--;
242 return strlcpy(buf, p->name, buflen);
243}
219 244
220 if (! state->map) 245/* check whether the control should be ignored */
246static inline int
247check_ignored_ctl(const struct usbmix_name_map *p)
248{
249 if (!p || p->name || p->dB)
221 return 0; 250 return 0;
222 for (p = state->map; p->id; p++) { 251 return 1;
223 if (p->id == unitid && ! p->name && 252}
224 (! control || ! p->control || control == p->control)) { 253
225 /* 254/* dB mapping */
226 printk(KERN_DEBUG "ignored control %d:%d\n", 255static inline void check_mapped_dB(const struct usbmix_name_map *p,
227 unitid, control); 256 struct usb_mixer_elem_info *cval)
228 */ 257{
229 return 1; 258 if (p && p->dB) {
230 } 259 cval->dBmin = p->dB->min;
260 cval->dBmax = p->dB->max;
231 } 261 }
232 return 0;
233} 262}
234 263
235/* get the mapped selector source name */ 264/* get the mapped selector source name */
@@ -257,7 +286,7 @@ static void *find_audio_control_unit(struct mixer_build *state, unsigned char un
257 p = NULL; 286 p = NULL;
258 while ((p = snd_usb_find_desc(state->buffer, state->buflen, p, 287 while ((p = snd_usb_find_desc(state->buffer, state->buflen, p,
259 USB_DT_CS_INTERFACE)) != NULL) { 288 USB_DT_CS_INTERFACE)) != NULL) {
260 if (p[0] >= 4 && p[2] >= INPUT_TERMINAL && p[2] <= EXTENSION_UNIT && p[3] == unit) 289 if (p[0] >= 4 && p[2] >= UAC_INPUT_TERMINAL && p[2] <= UAC_EXTENSION_UNIT_V1 && p[3] == unit)
261 return p; 290 return p;
262 } 291 }
263 return NULL; 292 return NULL;
@@ -378,14 +407,14 @@ static int get_ctl_value(struct usb_mixer_elem_info *cval, int request, int vali
378 407
379static int get_cur_ctl_value(struct usb_mixer_elem_info *cval, int validx, int *value) 408static int get_cur_ctl_value(struct usb_mixer_elem_info *cval, int validx, int *value)
380{ 409{
381 return get_ctl_value(cval, GET_CUR, validx, value); 410 return get_ctl_value(cval, UAC_GET_CUR, validx, value);
382} 411}
383 412
384/* channel = 0: master, 1 = first channel */ 413/* channel = 0: master, 1 = first channel */
385static inline int get_cur_mix_raw(struct usb_mixer_elem_info *cval, 414static inline int get_cur_mix_raw(struct usb_mixer_elem_info *cval,
386 int channel, int *value) 415 int channel, int *value)
387{ 416{
388 return get_ctl_value(cval, GET_CUR, (cval->control << 8) | channel, value); 417 return get_ctl_value(cval, UAC_GET_CUR, (cval->control << 8) | channel, value);
389} 418}
390 419
391static int get_cur_mix_value(struct usb_mixer_elem_info *cval, 420static int get_cur_mix_value(struct usb_mixer_elem_info *cval,
@@ -439,14 +468,14 @@ static int set_ctl_value(struct usb_mixer_elem_info *cval, int request, int vali
439 468
440static int set_cur_ctl_value(struct usb_mixer_elem_info *cval, int validx, int value) 469static int set_cur_ctl_value(struct usb_mixer_elem_info *cval, int validx, int value)
441{ 470{
442 return set_ctl_value(cval, SET_CUR, validx, value); 471 return set_ctl_value(cval, UAC_SET_CUR, validx, value);
443} 472}
444 473
445static int set_cur_mix_value(struct usb_mixer_elem_info *cval, int channel, 474static int set_cur_mix_value(struct usb_mixer_elem_info *cval, int channel,
446 int index, int value) 475 int index, int value)
447{ 476{
448 int err; 477 int err;
449 err = set_ctl_value(cval, SET_CUR, (cval->control << 8) | channel, 478 err = set_ctl_value(cval, UAC_SET_CUR, (cval->control << 8) | channel,
450 value); 479 value);
451 if (err < 0) 480 if (err < 0)
452 return err; 481 return err;
@@ -466,20 +495,8 @@ static int mixer_vol_tlv(struct snd_kcontrol *kcontrol, int op_flag,
466 495
467 if (size < sizeof(scale)) 496 if (size < sizeof(scale))
468 return -ENOMEM; 497 return -ENOMEM;
469 /* USB descriptions contain the dB scale in 1/256 dB unit 498 scale[2] = cval->dBmin;
470 * while ALSA TLV contains in 1/100 dB unit 499 scale[3] = cval->dBmax;
471 */
472 scale[2] = (convert_signed_value(cval, cval->min) * 100) / 256;
473 scale[3] = (convert_signed_value(cval, cval->max) * 100) / 256;
474 if (scale[3] <= scale[2]) {
475 /* something is wrong; assume it's either from/to 0dB */
476 if (scale[2] < 0)
477 scale[3] = 0;
478 else if (scale[2] > 0)
479 scale[2] = 0;
480 else /* totally crap, return an error */
481 return -EINVAL;
482 }
483 if (copy_to_user(_tlv, scale, sizeof(scale))) 500 if (copy_to_user(_tlv, scale, sizeof(scale)))
484 return -EFAULT; 501 return -EFAULT;
485 return 0; 502 return 0;
@@ -588,13 +605,13 @@ static int get_term_name(struct mixer_build *state, struct usb_audio_term *iterm
588 if (term_only) 605 if (term_only)
589 return 0; 606 return 0;
590 switch (iterm->type >> 16) { 607 switch (iterm->type >> 16) {
591 case SELECTOR_UNIT: 608 case UAC_SELECTOR_UNIT:
592 strcpy(name, "Selector"); return 8; 609 strcpy(name, "Selector"); return 8;
593 case PROCESSING_UNIT: 610 case UAC_PROCESSING_UNIT_V1:
594 strcpy(name, "Process Unit"); return 12; 611 strcpy(name, "Process Unit"); return 12;
595 case EXTENSION_UNIT: 612 case UAC_EXTENSION_UNIT_V1:
596 strcpy(name, "Ext Unit"); return 8; 613 strcpy(name, "Ext Unit"); return 8;
597 case MIXER_UNIT: 614 case UAC_MIXER_UNIT:
598 strcpy(name, "Mixer"); return 5; 615 strcpy(name, "Mixer"); return 5;
599 default: 616 default:
600 return sprintf(name, "Unit %d", iterm->id); 617 return sprintf(name, "Unit %d", iterm->id);
@@ -633,22 +650,22 @@ static int check_input_term(struct mixer_build *state, int id, struct usb_audio_
633 while ((p1 = find_audio_control_unit(state, id)) != NULL) { 650 while ((p1 = find_audio_control_unit(state, id)) != NULL) {
634 term->id = id; 651 term->id = id;
635 switch (p1[2]) { 652 switch (p1[2]) {
636 case INPUT_TERMINAL: 653 case UAC_INPUT_TERMINAL:
637 term->type = combine_word(p1 + 4); 654 term->type = combine_word(p1 + 4);
638 term->channels = p1[7]; 655 term->channels = p1[7];
639 term->chconfig = combine_word(p1 + 8); 656 term->chconfig = combine_word(p1 + 8);
640 term->name = p1[11]; 657 term->name = p1[11];
641 return 0; 658 return 0;
642 case FEATURE_UNIT: 659 case UAC_FEATURE_UNIT:
643 id = p1[4]; 660 id = p1[4];
644 break; /* continue to parse */ 661 break; /* continue to parse */
645 case MIXER_UNIT: 662 case UAC_MIXER_UNIT:
646 term->type = p1[2] << 16; /* virtual type */ 663 term->type = p1[2] << 16; /* virtual type */
647 term->channels = p1[5 + p1[4]]; 664 term->channels = p1[5 + p1[4]];
648 term->chconfig = combine_word(p1 + 6 + p1[4]); 665 term->chconfig = combine_word(p1 + 6 + p1[4]);
649 term->name = p1[p1[0] - 1]; 666 term->name = p1[p1[0] - 1];
650 return 0; 667 return 0;
651 case SELECTOR_UNIT: 668 case UAC_SELECTOR_UNIT:
652 /* call recursively to retrieve the channel info */ 669 /* call recursively to retrieve the channel info */
653 if (check_input_term(state, p1[5], term) < 0) 670 if (check_input_term(state, p1[5], term) < 0)
654 return -ENODEV; 671 return -ENODEV;
@@ -656,8 +673,8 @@ static int check_input_term(struct mixer_build *state, int id, struct usb_audio_
656 term->id = id; 673 term->id = id;
657 term->name = p1[9 + p1[0] - 1]; 674 term->name = p1[9 + p1[0] - 1];
658 return 0; 675 return 0;
659 case PROCESSING_UNIT: 676 case UAC_PROCESSING_UNIT_V1:
660 case EXTENSION_UNIT: 677 case UAC_EXTENSION_UNIT_V1:
661 if (p1[6] == 1) { 678 if (p1[6] == 1) {
662 id = p1[7]; 679 id = p1[7];
663 break; /* continue to parse */ 680 break; /* continue to parse */
@@ -720,6 +737,7 @@ static int get_min_max(struct usb_mixer_elem_info *cval, int default_min)
720 cval->min = default_min; 737 cval->min = default_min;
721 cval->max = cval->min + 1; 738 cval->max = cval->min + 1;
722 cval->res = 1; 739 cval->res = 1;
740 cval->dBmin = cval->dBmax = 0;
723 741
724 if (cval->val_type == USB_MIXER_BOOLEAN || 742 if (cval->val_type == USB_MIXER_BOOLEAN ||
725 cval->val_type == USB_MIXER_INV_BOOLEAN) { 743 cval->val_type == USB_MIXER_INV_BOOLEAN) {
@@ -734,23 +752,23 @@ static int get_min_max(struct usb_mixer_elem_info *cval, int default_min)
734 break; 752 break;
735 } 753 }
736 } 754 }
737 if (get_ctl_value(cval, GET_MAX, (cval->control << 8) | minchn, &cval->max) < 0 || 755 if (get_ctl_value(cval, UAC_GET_MAX, (cval->control << 8) | minchn, &cval->max) < 0 ||
738 get_ctl_value(cval, GET_MIN, (cval->control << 8) | minchn, &cval->min) < 0) { 756 get_ctl_value(cval, UAC_GET_MIN, (cval->control << 8) | minchn, &cval->min) < 0) {
739 snd_printd(KERN_ERR "%d:%d: cannot get min/max values for control %d (id %d)\n", 757 snd_printd(KERN_ERR "%d:%d: cannot get min/max values for control %d (id %d)\n",
740 cval->id, cval->mixer->ctrlif, cval->control, cval->id); 758 cval->id, cval->mixer->ctrlif, cval->control, cval->id);
741 return -EINVAL; 759 return -EINVAL;
742 } 760 }
743 if (get_ctl_value(cval, GET_RES, (cval->control << 8) | minchn, &cval->res) < 0) { 761 if (get_ctl_value(cval, UAC_GET_RES, (cval->control << 8) | minchn, &cval->res) < 0) {
744 cval->res = 1; 762 cval->res = 1;
745 } else { 763 } else {
746 int last_valid_res = cval->res; 764 int last_valid_res = cval->res;
747 765
748 while (cval->res > 1) { 766 while (cval->res > 1) {
749 if (set_ctl_value(cval, SET_RES, (cval->control << 8) | minchn, cval->res / 2) < 0) 767 if (set_ctl_value(cval, UAC_SET_RES, (cval->control << 8) | minchn, cval->res / 2) < 0)
750 break; 768 break;
751 cval->res /= 2; 769 cval->res /= 2;
752 } 770 }
753 if (get_ctl_value(cval, GET_RES, (cval->control << 8) | minchn, &cval->res) < 0) 771 if (get_ctl_value(cval, UAC_GET_RES, (cval->control << 8) | minchn, &cval->res) < 0)
754 cval->res = last_valid_res; 772 cval->res = last_valid_res;
755 } 773 }
756 if (cval->res == 0) 774 if (cval->res == 0)
@@ -787,6 +805,24 @@ static int get_min_max(struct usb_mixer_elem_info *cval, int default_min)
787 805
788 cval->initialized = 1; 806 cval->initialized = 1;
789 } 807 }
808
809 /* USB descriptions contain the dB scale in 1/256 dB unit
810 * while ALSA TLV contains in 1/100 dB unit
811 */
812 cval->dBmin = (convert_signed_value(cval, cval->min) * 100) / 256;
813 cval->dBmax = (convert_signed_value(cval, cval->max) * 100) / 256;
814 if (cval->dBmin > cval->dBmax) {
815 /* something is wrong; assume it's either from/to 0dB */
816 if (cval->dBmin < 0)
817 cval->dBmax = 0;
818 else if (cval->dBmin > 0)
819 cval->dBmin = 0;
820 if (cval->dBmin > cval->dBmax) {
821 /* totally crap, return an error */
822 return -EINVAL;
823 }
824 }
825
790 return 0; 826 return 0;
791} 827}
792 828
@@ -912,6 +948,7 @@ static void build_feature_ctl(struct mixer_build *state, unsigned char *desc,
912 int nameid = desc[desc[0] - 1]; 948 int nameid = desc[desc[0] - 1];
913 struct snd_kcontrol *kctl; 949 struct snd_kcontrol *kctl;
914 struct usb_mixer_elem_info *cval; 950 struct usb_mixer_elem_info *cval;
951 const struct usbmix_name_map *map;
915 952
916 control++; /* change from zero-based to 1-based value */ 953 control++; /* change from zero-based to 1-based value */
917 954
@@ -920,7 +957,8 @@ static void build_feature_ctl(struct mixer_build *state, unsigned char *desc,
920 return; 957 return;
921 } 958 }
922 959
923 if (check_ignored_ctl(state, unitid, control)) 960 map = find_map(state, unitid, control);
961 if (check_ignored_ctl(map))
924 return; 962 return;
925 963
926 cval = kzalloc(sizeof(*cval), GFP_KERNEL); 964 cval = kzalloc(sizeof(*cval), GFP_KERNEL);
@@ -954,10 +992,11 @@ static void build_feature_ctl(struct mixer_build *state, unsigned char *desc,
954 } 992 }
955 kctl->private_free = usb_mixer_elem_free; 993 kctl->private_free = usb_mixer_elem_free;
956 994
957 len = check_mapped_name(state, unitid, control, kctl->id.name, sizeof(kctl->id.name)); 995 len = check_mapped_name(map, kctl->id.name, sizeof(kctl->id.name));
958 mapped_name = len != 0; 996 mapped_name = len != 0;
959 if (! len && nameid) 997 if (! len && nameid)
960 len = snd_usb_copy_string_desc(state, nameid, kctl->id.name, sizeof(kctl->id.name)); 998 len = snd_usb_copy_string_desc(state, nameid,
999 kctl->id.name, sizeof(kctl->id.name));
961 1000
962 switch (control) { 1001 switch (control) {
963 case USB_FEATURE_MUTE: 1002 case USB_FEATURE_MUTE:
@@ -995,6 +1034,7 @@ static void build_feature_ctl(struct mixer_build *state, unsigned char *desc,
995 kctl->vd[0].access |= 1034 kctl->vd[0].access |=
996 SNDRV_CTL_ELEM_ACCESS_TLV_READ | 1035 SNDRV_CTL_ELEM_ACCESS_TLV_READ |
997 SNDRV_CTL_ELEM_ACCESS_TLV_CALLBACK; 1036 SNDRV_CTL_ELEM_ACCESS_TLV_CALLBACK;
1037 check_mapped_dB(map, cval);
998 } 1038 }
999 break; 1039 break;
1000 1040
@@ -1048,29 +1088,30 @@ static void build_feature_ctl(struct mixer_build *state, unsigned char *desc,
1048 * 1088 *
1049 * most of controlls are defined here. 1089 * most of controlls are defined here.
1050 */ 1090 */
1051static int parse_audio_feature_unit(struct mixer_build *state, int unitid, unsigned char *ftr) 1091static int parse_audio_feature_unit(struct mixer_build *state, int unitid, void *_ftr)
1052{ 1092{
1053 int channels, i, j; 1093 int channels, i, j;
1054 struct usb_audio_term iterm; 1094 struct usb_audio_term iterm;
1055 unsigned int master_bits, first_ch_bits; 1095 unsigned int master_bits, first_ch_bits;
1056 int err, csize; 1096 int err, csize;
1097 struct uac_feature_unit_descriptor *ftr = _ftr;
1057 1098
1058 if (ftr[0] < 7 || ! (csize = ftr[5]) || ftr[0] < 7 + csize) { 1099 if (ftr->bLength < 7 || ! (csize = ftr->bControlSize) || ftr->bLength < 7 + csize) {
1059 snd_printk(KERN_ERR "usbaudio: unit %u: invalid FEATURE_UNIT descriptor\n", unitid); 1100 snd_printk(KERN_ERR "usbaudio: unit %u: invalid UAC_FEATURE_UNIT descriptor\n", unitid);
1060 return -EINVAL; 1101 return -EINVAL;
1061 } 1102 }
1062 1103
1063 /* parse the source unit */ 1104 /* parse the source unit */
1064 if ((err = parse_audio_unit(state, ftr[4])) < 0) 1105 if ((err = parse_audio_unit(state, ftr->bSourceID)) < 0)
1065 return err; 1106 return err;
1066 1107
1067 /* determine the input source type and name */ 1108 /* determine the input source type and name */
1068 if (check_input_term(state, ftr[4], &iterm) < 0) 1109 if (check_input_term(state, ftr->bSourceID, &iterm) < 0)
1069 return -EINVAL; 1110 return -EINVAL;
1070 1111
1071 channels = (ftr[0] - 7) / csize - 1; 1112 channels = (ftr->bLength - 7) / csize - 1;
1072 1113
1073 master_bits = snd_usb_combine_bytes(ftr + 6, csize); 1114 master_bits = snd_usb_combine_bytes(ftr->controls, csize);
1074 /* master configuration quirks */ 1115 /* master configuration quirks */
1075 switch (state->chip->usb_id) { 1116 switch (state->chip->usb_id) {
1076 case USB_ID(0x08bb, 0x2702): 1117 case USB_ID(0x08bb, 0x2702):
@@ -1081,21 +1122,21 @@ static int parse_audio_feature_unit(struct mixer_build *state, int unitid, unsig
1081 break; 1122 break;
1082 } 1123 }
1083 if (channels > 0) 1124 if (channels > 0)
1084 first_ch_bits = snd_usb_combine_bytes(ftr + 6 + csize, csize); 1125 first_ch_bits = snd_usb_combine_bytes(ftr->controls + csize, csize);
1085 else 1126 else
1086 first_ch_bits = 0; 1127 first_ch_bits = 0;
1087 /* check all control types */ 1128 /* check all control types */
1088 for (i = 0; i < 10; i++) { 1129 for (i = 0; i < 10; i++) {
1089 unsigned int ch_bits = 0; 1130 unsigned int ch_bits = 0;
1090 for (j = 0; j < channels; j++) { 1131 for (j = 0; j < channels; j++) {
1091 unsigned int mask = snd_usb_combine_bytes(ftr + 6 + csize * (j+1), csize); 1132 unsigned int mask = snd_usb_combine_bytes(ftr->controls + csize * (j+1), csize);
1092 if (mask & (1 << i)) 1133 if (mask & (1 << i))
1093 ch_bits |= (1 << j); 1134 ch_bits |= (1 << j);
1094 } 1135 }
1095 if (ch_bits & 1) /* the first channel must be set (for ease of programming) */ 1136 if (ch_bits & 1) /* the first channel must be set (for ease of programming) */
1096 build_feature_ctl(state, ftr, ch_bits, i, &iterm, unitid); 1137 build_feature_ctl(state, _ftr, ch_bits, i, &iterm, unitid);
1097 if (master_bits & (1 << i)) 1138 if (master_bits & (1 << i))
1098 build_feature_ctl(state, ftr, 0, i, &iterm, unitid); 1139 build_feature_ctl(state, _ftr, 0, i, &iterm, unitid);
1099 } 1140 }
1100 1141
1101 return 0; 1142 return 0;
@@ -1122,8 +1163,10 @@ static void build_mixer_unit_ctl(struct mixer_build *state, unsigned char *desc,
1122 unsigned int num_outs = desc[5 + input_pins]; 1163 unsigned int num_outs = desc[5 + input_pins];
1123 unsigned int i, len; 1164 unsigned int i, len;
1124 struct snd_kcontrol *kctl; 1165 struct snd_kcontrol *kctl;
1166 const struct usbmix_name_map *map;
1125 1167
1126 if (check_ignored_ctl(state, unitid, 0)) 1168 map = find_map(state, unitid, 0);
1169 if (check_ignored_ctl(map))
1127 return; 1170 return;
1128 1171
1129 cval = kzalloc(sizeof(*cval), GFP_KERNEL); 1172 cval = kzalloc(sizeof(*cval), GFP_KERNEL);
@@ -1152,7 +1195,7 @@ static void build_mixer_unit_ctl(struct mixer_build *state, unsigned char *desc,
1152 } 1195 }
1153 kctl->private_free = usb_mixer_elem_free; 1196 kctl->private_free = usb_mixer_elem_free;
1154 1197
1155 len = check_mapped_name(state, unitid, 0, kctl->id.name, sizeof(kctl->id.name)); 1198 len = check_mapped_name(map, kctl->id.name, sizeof(kctl->id.name));
1156 if (! len) 1199 if (! len)
1157 len = get_term_name(state, iterm, kctl->id.name, sizeof(kctl->id.name), 0); 1200 len = get_term_name(state, iterm, kctl->id.name, sizeof(kctl->id.name), 0);
1158 if (! len) 1201 if (! len)
@@ -1330,7 +1373,32 @@ static struct procunit_info procunits[] = {
1330 { USB_PROC_DCR, "DCR", dcr_proc_info }, 1373 { USB_PROC_DCR, "DCR", dcr_proc_info },
1331 { 0 }, 1374 { 0 },
1332}; 1375};
1333 1376/*
1377 * predefined data for extension units
1378 */
1379static struct procunit_value_info clock_rate_xu_info[] = {
1380 { USB_XU_CLOCK_RATE_SELECTOR, "Selector", USB_MIXER_U8, 0 },
1381 { 0 }
1382};
1383static struct procunit_value_info clock_source_xu_info[] = {
1384 { USB_XU_CLOCK_SOURCE_SELECTOR, "External", USB_MIXER_BOOLEAN },
1385 { 0 }
1386};
1387static struct procunit_value_info spdif_format_xu_info[] = {
1388 { USB_XU_DIGITAL_FORMAT_SELECTOR, "SPDIF/AC3", USB_MIXER_BOOLEAN },
1389 { 0 }
1390};
1391static struct procunit_value_info soft_limit_xu_info[] = {
1392 { USB_XU_SOFT_LIMIT_SELECTOR, " ", USB_MIXER_BOOLEAN },
1393 { 0 }
1394};
1395static struct procunit_info extunits[] = {
1396 { USB_XU_CLOCK_RATE, "Clock rate", clock_rate_xu_info },
1397 { USB_XU_CLOCK_SOURCE, "DigitalIn CLK source", clock_source_xu_info },
1398 { USB_XU_DIGITAL_IO_STATUS, "DigitalOut format:", spdif_format_xu_info },
1399 { USB_XU_DEVICE_OPTIONS, "AnalogueIn Soft Limit", soft_limit_xu_info },
1400 { 0 }
1401};
1334/* 1402/*
1335 * build a processing/extension unit 1403 * build a processing/extension unit
1336 */ 1404 */
@@ -1342,6 +1410,7 @@ static int build_audio_procunit(struct mixer_build *state, int unitid, unsigned
1342 int i, err, nameid, type, len; 1410 int i, err, nameid, type, len;
1343 struct procunit_info *info; 1411 struct procunit_info *info;
1344 struct procunit_value_info *valinfo; 1412 struct procunit_value_info *valinfo;
1413 const struct usbmix_name_map *map;
1345 static struct procunit_value_info default_value_info[] = { 1414 static struct procunit_value_info default_value_info[] = {
1346 { 0x01, "Switch", USB_MIXER_BOOLEAN }, 1415 { 0x01, "Switch", USB_MIXER_BOOLEAN },
1347 { 0 } 1416 { 0 }
@@ -1371,7 +1440,8 @@ static int build_audio_procunit(struct mixer_build *state, int unitid, unsigned
1371 /* FIXME: bitmap might be longer than 8bit */ 1440 /* FIXME: bitmap might be longer than 8bit */
1372 if (! (dsc[12 + num_ins] & (1 << (valinfo->control - 1)))) 1441 if (! (dsc[12 + num_ins] & (1 << (valinfo->control - 1))))
1373 continue; 1442 continue;
1374 if (check_ignored_ctl(state, unitid, valinfo->control)) 1443 map = find_map(state, unitid, valinfo->control);
1444 if (check_ignored_ctl(map))
1375 continue; 1445 continue;
1376 cval = kzalloc(sizeof(*cval), GFP_KERNEL); 1446 cval = kzalloc(sizeof(*cval), GFP_KERNEL);
1377 if (! cval) { 1447 if (! cval) {
@@ -1391,8 +1461,18 @@ static int build_audio_procunit(struct mixer_build *state, int unitid, unsigned
1391 cval->max = dsc[15]; 1461 cval->max = dsc[15];
1392 cval->res = 1; 1462 cval->res = 1;
1393 cval->initialized = 1; 1463 cval->initialized = 1;
1394 } else 1464 } else {
1395 get_min_max(cval, valinfo->min_value); 1465 if (type == USB_XU_CLOCK_RATE) {
1466 /* E-Mu USB 0404/0202/TrackerPre
1467 * samplerate control quirk
1468 */
1469 cval->min = 0;
1470 cval->max = 5;
1471 cval->res = 1;
1472 cval->initialized = 1;
1473 } else
1474 get_min_max(cval, valinfo->min_value);
1475 }
1396 1476
1397 kctl = snd_ctl_new1(&mixer_procunit_ctl, cval); 1477 kctl = snd_ctl_new1(&mixer_procunit_ctl, cval);
1398 if (! kctl) { 1478 if (! kctl) {
@@ -1402,8 +1482,9 @@ static int build_audio_procunit(struct mixer_build *state, int unitid, unsigned
1402 } 1482 }
1403 kctl->private_free = usb_mixer_elem_free; 1483 kctl->private_free = usb_mixer_elem_free;
1404 1484
1405 if (check_mapped_name(state, unitid, cval->control, kctl->id.name, sizeof(kctl->id.name))) 1485 if (check_mapped_name(map, kctl->id.name,
1406 ; 1486 sizeof(kctl->id.name)))
1487 /* nothing */ ;
1407 else if (info->name) 1488 else if (info->name)
1408 strlcpy(kctl->id.name, info->name, sizeof(kctl->id.name)); 1489 strlcpy(kctl->id.name, info->name, sizeof(kctl->id.name));
1409 else { 1490 else {
@@ -1433,7 +1514,7 @@ static int parse_audio_processing_unit(struct mixer_build *state, int unitid, un
1433 1514
1434static int parse_audio_extension_unit(struct mixer_build *state, int unitid, unsigned char *desc) 1515static int parse_audio_extension_unit(struct mixer_build *state, int unitid, unsigned char *desc)
1435{ 1516{
1436 return build_audio_procunit(state, unitid, desc, NULL, "Extension Unit"); 1517 return build_audio_procunit(state, unitid, desc, extunits, "Extension Unit");
1437} 1518}
1438 1519
1439 1520
@@ -1542,6 +1623,7 @@ static int parse_audio_selector_unit(struct mixer_build *state, int unitid, unsi
1542 int err; 1623 int err;
1543 struct usb_mixer_elem_info *cval; 1624 struct usb_mixer_elem_info *cval;
1544 struct snd_kcontrol *kctl; 1625 struct snd_kcontrol *kctl;
1626 const struct usbmix_name_map *map;
1545 char **namelist; 1627 char **namelist;
1546 1628
1547 if (! num_ins || desc[0] < 5 + num_ins) { 1629 if (! num_ins || desc[0] < 5 + num_ins) {
@@ -1557,7 +1639,8 @@ static int parse_audio_selector_unit(struct mixer_build *state, int unitid, unsi
1557 if (num_ins == 1) /* only one ? nonsense! */ 1639 if (num_ins == 1) /* only one ? nonsense! */
1558 return 0; 1640 return 0;
1559 1641
1560 if (check_ignored_ctl(state, unitid, 0)) 1642 map = find_map(state, unitid, 0);
1643 if (check_ignored_ctl(map))
1561 return 0; 1644 return 0;
1562 1645
1563 cval = kzalloc(sizeof(*cval), GFP_KERNEL); 1646 cval = kzalloc(sizeof(*cval), GFP_KERNEL);
@@ -1612,7 +1695,7 @@ static int parse_audio_selector_unit(struct mixer_build *state, int unitid, unsi
1612 kctl->private_free = usb_mixer_selector_elem_free; 1695 kctl->private_free = usb_mixer_selector_elem_free;
1613 1696
1614 nameid = desc[desc[0] - 1]; 1697 nameid = desc[desc[0] - 1];
1615 len = check_mapped_name(state, unitid, 0, kctl->id.name, sizeof(kctl->id.name)); 1698 len = check_mapped_name(map, kctl->id.name, sizeof(kctl->id.name));
1616 if (len) 1699 if (len)
1617 ; 1700 ;
1618 else if (nameid) 1701 else if (nameid)
@@ -1656,17 +1739,17 @@ static int parse_audio_unit(struct mixer_build *state, int unitid)
1656 } 1739 }
1657 1740
1658 switch (p1[2]) { 1741 switch (p1[2]) {
1659 case INPUT_TERMINAL: 1742 case UAC_INPUT_TERMINAL:
1660 return 0; /* NOP */ 1743 return 0; /* NOP */
1661 case MIXER_UNIT: 1744 case UAC_MIXER_UNIT:
1662 return parse_audio_mixer_unit(state, unitid, p1); 1745 return parse_audio_mixer_unit(state, unitid, p1);
1663 case SELECTOR_UNIT: 1746 case UAC_SELECTOR_UNIT:
1664 return parse_audio_selector_unit(state, unitid, p1); 1747 return parse_audio_selector_unit(state, unitid, p1);
1665 case FEATURE_UNIT: 1748 case UAC_FEATURE_UNIT:
1666 return parse_audio_feature_unit(state, unitid, p1); 1749 return parse_audio_feature_unit(state, unitid, p1);
1667 case PROCESSING_UNIT: 1750 case UAC_PROCESSING_UNIT_V1:
1668 return parse_audio_processing_unit(state, unitid, p1); 1751 return parse_audio_processing_unit(state, unitid, p1);
1669 case EXTENSION_UNIT: 1752 case UAC_EXTENSION_UNIT_V1:
1670 return parse_audio_extension_unit(state, unitid, p1); 1753 return parse_audio_extension_unit(state, unitid, p1);
1671 default: 1754 default:
1672 snd_printk(KERN_ERR "usbaudio: unit %u: unexpected type 0x%02x\n", unitid, p1[2]); 1755 snd_printk(KERN_ERR "usbaudio: unit %u: unexpected type 0x%02x\n", unitid, p1[2]);
@@ -1696,11 +1779,11 @@ static int snd_usb_mixer_dev_free(struct snd_device *device)
1696/* 1779/*
1697 * create mixer controls 1780 * create mixer controls
1698 * 1781 *
1699 * walk through all OUTPUT_TERMINAL descriptors to search for mixers 1782 * walk through all UAC_OUTPUT_TERMINAL descriptors to search for mixers
1700 */ 1783 */
1701static int snd_usb_mixer_controls(struct usb_mixer_interface *mixer) 1784static int snd_usb_mixer_controls(struct usb_mixer_interface *mixer)
1702{ 1785{
1703 unsigned char *desc; 1786 struct uac_output_terminal_descriptor_v1 *desc;
1704 struct mixer_build state; 1787 struct mixer_build state;
1705 int err; 1788 int err;
1706 const struct usbmix_ctl_map *map; 1789 const struct usbmix_ctl_map *map;
@@ -1724,14 +1807,14 @@ static int snd_usb_mixer_controls(struct usb_mixer_interface *mixer)
1724 } 1807 }
1725 1808
1726 desc = NULL; 1809 desc = NULL;
1727 while ((desc = snd_usb_find_csint_desc(hostif->extra, hostif->extralen, desc, OUTPUT_TERMINAL)) != NULL) { 1810 while ((desc = snd_usb_find_csint_desc(hostif->extra, hostif->extralen, desc, UAC_OUTPUT_TERMINAL)) != NULL) {
1728 if (desc[0] < 9) 1811 if (desc->bLength < 9)
1729 continue; /* invalid descriptor? */ 1812 continue; /* invalid descriptor? */
1730 set_bit(desc[3], state.unitbitmap); /* mark terminal ID as visited */ 1813 set_bit(desc->bTerminalID, state.unitbitmap); /* mark terminal ID as visited */
1731 state.oterm.id = desc[3]; 1814 state.oterm.id = desc->bTerminalID;
1732 state.oterm.type = combine_word(&desc[4]); 1815 state.oterm.type = le16_to_cpu(desc->wTerminalType);
1733 state.oterm.name = desc[8]; 1816 state.oterm.name = desc->iTerminal;
1734 err = parse_audio_unit(&state, desc[7]); 1817 err = parse_audio_unit(&state, desc->bSourceID);
1735 if (err < 0) 1818 if (err < 0)
1736 return err; 1819 return err;
1737 } 1820 }
@@ -1748,6 +1831,46 @@ static void snd_usb_mixer_notify_id(struct usb_mixer_interface *mixer,
1748 info->elem_id); 1831 info->elem_id);
1749} 1832}
1750 1833
1834static void snd_usb_mixer_dump_cval(struct snd_info_buffer *buffer,
1835 int unitid,
1836 struct usb_mixer_elem_info *cval)
1837{
1838 static char *val_types[] = {"BOOLEAN", "INV_BOOLEAN",
1839 "S8", "U8", "S16", "U16"};
1840 snd_iprintf(buffer, " Unit: %i\n", unitid);
1841 if (cval->elem_id)
1842 snd_iprintf(buffer, " Control: name=\"%s\", index=%i\n",
1843 cval->elem_id->name, cval->elem_id->index);
1844 snd_iprintf(buffer, " Info: id=%i, control=%i, cmask=0x%x, "
1845 "channels=%i, type=\"%s\"\n", cval->id,
1846 cval->control, cval->cmask, cval->channels,
1847 val_types[cval->val_type]);
1848 snd_iprintf(buffer, " Volume: min=%i, max=%i, dBmin=%i, dBmax=%i\n",
1849 cval->min, cval->max, cval->dBmin, cval->dBmax);
1850}
1851
1852static void snd_usb_mixer_proc_read(struct snd_info_entry *entry,
1853 struct snd_info_buffer *buffer)
1854{
1855 struct snd_usb_audio *chip = entry->private_data;
1856 struct usb_mixer_interface *mixer;
1857 struct usb_mixer_elem_info *cval;
1858 int unitid;
1859
1860 list_for_each_entry(mixer, &chip->mixer_list, list) {
1861 snd_iprintf(buffer,
1862 "USB Mixer: usb_id=0x%08x, ctrlif=%i, ctlerr=%i\n",
1863 chip->usb_id, mixer->ctrlif,
1864 mixer->ignore_ctl_error);
1865 snd_iprintf(buffer, "Card: %s\n", chip->card->longname);
1866 for (unitid = 0; unitid < MAX_ID_ELEMS; unitid++) {
1867 for (cval = mixer->id_elems[unitid]; cval;
1868 cval = cval->next_id_elem)
1869 snd_usb_mixer_dump_cval(buffer, unitid, cval);
1870 }
1871 }
1872}
1873
1751static void snd_usb_mixer_memory_change(struct usb_mixer_interface *mixer, 1874static void snd_usb_mixer_memory_change(struct usb_mixer_interface *mixer,
1752 int unitid) 1875 int unitid)
1753{ 1876{
@@ -1924,7 +2047,7 @@ static int snd_usb_soundblaster_remote_init(struct usb_mixer_interface *mixer)
1924 } 2047 }
1925 mixer->rc_setup_packet->bRequestType = 2048 mixer->rc_setup_packet->bRequestType =
1926 USB_DIR_IN | USB_TYPE_CLASS | USB_RECIP_INTERFACE; 2049 USB_DIR_IN | USB_TYPE_CLASS | USB_RECIP_INTERFACE;
1927 mixer->rc_setup_packet->bRequest = GET_MEM; 2050 mixer->rc_setup_packet->bRequest = UAC_GET_MEM;
1928 mixer->rc_setup_packet->wValue = cpu_to_le16(0); 2051 mixer->rc_setup_packet->wValue = cpu_to_le16(0);
1929 mixer->rc_setup_packet->wIndex = cpu_to_le16(0); 2052 mixer->rc_setup_packet->wIndex = cpu_to_le16(0);
1930 mixer->rc_setup_packet->wLength = cpu_to_le16(len); 2053 mixer->rc_setup_packet->wLength = cpu_to_le16(len);
@@ -2047,7 +2170,7 @@ static void snd_audigy2nx_proc_read(struct snd_info_entry *entry,
2047 snd_iprintf(buffer, "%s: ", jacks[i].name); 2170 snd_iprintf(buffer, "%s: ", jacks[i].name);
2048 err = snd_usb_ctl_msg(mixer->chip->dev, 2171 err = snd_usb_ctl_msg(mixer->chip->dev,
2049 usb_rcvctrlpipe(mixer->chip->dev, 0), 2172 usb_rcvctrlpipe(mixer->chip->dev, 0),
2050 GET_MEM, USB_DIR_IN | USB_TYPE_CLASS | 2173 UAC_GET_MEM, USB_DIR_IN | USB_TYPE_CLASS |
2051 USB_RECIP_INTERFACE, 0, 2174 USB_RECIP_INTERFACE, 0,
2052 jacks[i].unitid << 8, buf, 3, 100); 2175 jacks[i].unitid << 8, buf, 3, 100);
2053 if (err == 3 && (buf[0] == 3 || buf[0] == 6)) 2176 if (err == 3 && (buf[0] == 3 || buf[0] == 6))
@@ -2109,6 +2232,24 @@ static int snd_xonar_u1_controls_create(struct usb_mixer_interface *mixer)
2109 return 0; 2232 return 0;
2110} 2233}
2111 2234
2235void snd_emuusb_set_samplerate(struct snd_usb_audio *chip,
2236 unsigned char samplerate_id)
2237{
2238 struct usb_mixer_interface *mixer;
2239 struct usb_mixer_elem_info *cval;
2240 int unitid = 12; /* SamleRate ExtensionUnit ID */
2241
2242 list_for_each_entry(mixer, &chip->mixer_list, list) {
2243 cval = mixer->id_elems[unitid];
2244 if (cval) {
2245 set_cur_ctl_value(cval, cval->control << 8,
2246 samplerate_id);
2247 snd_usb_mixer_notify_id(mixer, unitid);
2248 }
2249 break;
2250 }
2251}
2252
2112int snd_usb_create_mixer(struct snd_usb_audio *chip, int ctrlif, 2253int snd_usb_create_mixer(struct snd_usb_audio *chip, int ctrlif,
2113 int ignore_error) 2254 int ignore_error)
2114{ 2255{
@@ -2116,7 +2257,9 @@ int snd_usb_create_mixer(struct snd_usb_audio *chip, int ctrlif,
2116 .dev_free = snd_usb_mixer_dev_free 2257 .dev_free = snd_usb_mixer_dev_free
2117 }; 2258 };
2118 struct usb_mixer_interface *mixer; 2259 struct usb_mixer_interface *mixer;
2119 int err; 2260 struct snd_info_entry *entry;
2261 struct usb_host_interface *host_iface;
2262 int err, protocol;
2120 2263
2121 strcpy(chip->card->mixername, "USB Mixer"); 2264 strcpy(chip->card->mixername, "USB Mixer");
2122 2265
@@ -2126,12 +2269,23 @@ int snd_usb_create_mixer(struct snd_usb_audio *chip, int ctrlif,
2126 mixer->chip = chip; 2269 mixer->chip = chip;
2127 mixer->ctrlif = ctrlif; 2270 mixer->ctrlif = ctrlif;
2128 mixer->ignore_ctl_error = ignore_error; 2271 mixer->ignore_ctl_error = ignore_error;
2129 mixer->id_elems = kcalloc(256, sizeof(*mixer->id_elems), GFP_KERNEL); 2272 mixer->id_elems = kcalloc(MAX_ID_ELEMS, sizeof(*mixer->id_elems),
2273 GFP_KERNEL);
2130 if (!mixer->id_elems) { 2274 if (!mixer->id_elems) {
2131 kfree(mixer); 2275 kfree(mixer);
2132 return -ENOMEM; 2276 return -ENOMEM;
2133 } 2277 }
2134 2278
2279 host_iface = &usb_ifnum_to_if(chip->dev, ctrlif)->altsetting[0];
2280 protocol = host_iface->desc.bInterfaceProtocol;
2281
2282 /* FIXME! */
2283 if (protocol != UAC_VERSION_1) {
2284 snd_printk(KERN_WARNING "mixer interface protocol 0x%02x not yet supported\n",
2285 protocol);
2286 return 0;
2287 }
2288
2135 if ((err = snd_usb_mixer_controls(mixer)) < 0 || 2289 if ((err = snd_usb_mixer_controls(mixer)) < 0 ||
2136 (err = snd_usb_mixer_status_create(mixer)) < 0) 2290 (err = snd_usb_mixer_status_create(mixer)) < 0)
2137 goto _error; 2291 goto _error;
@@ -2142,8 +2296,6 @@ int snd_usb_create_mixer(struct snd_usb_audio *chip, int ctrlif,
2142 if (mixer->chip->usb_id == USB_ID(0x041e, 0x3020) || 2296 if (mixer->chip->usb_id == USB_ID(0x041e, 0x3020) ||
2143 mixer->chip->usb_id == USB_ID(0x041e, 0x3040) || 2297 mixer->chip->usb_id == USB_ID(0x041e, 0x3040) ||
2144 mixer->chip->usb_id == USB_ID(0x041e, 0x3048)) { 2298 mixer->chip->usb_id == USB_ID(0x041e, 0x3048)) {
2145 struct snd_info_entry *entry;
2146
2147 if ((err = snd_audigy2nx_controls_create(mixer)) < 0) 2299 if ((err = snd_audigy2nx_controls_create(mixer)) < 0)
2148 goto _error; 2300 goto _error;
2149 if (!snd_card_proc_new(chip->card, "audigy2nx", &entry)) 2301 if (!snd_card_proc_new(chip->card, "audigy2nx", &entry))
@@ -2161,6 +2313,11 @@ int snd_usb_create_mixer(struct snd_usb_audio *chip, int ctrlif,
2161 err = snd_device_new(chip->card, SNDRV_DEV_LOWLEVEL, mixer, &dev_ops); 2313 err = snd_device_new(chip->card, SNDRV_DEV_LOWLEVEL, mixer, &dev_ops);
2162 if (err < 0) 2314 if (err < 0)
2163 goto _error; 2315 goto _error;
2316
2317 if (list_empty(&chip->mixer_list) &&
2318 !snd_card_proc_new(chip->card, "usbmixer", &entry))
2319 snd_info_set_text_ops(entry, chip, snd_usb_mixer_proc_read);
2320
2164 list_add(&mixer->list, &chip->mixer_list); 2321 list_add(&mixer->list, &chip->mixer_list);
2165 return 0; 2322 return 0;
2166 2323
diff --git a/sound/usb/usbmixer_maps.c b/sound/usb/usbmixer_maps.c
index 3e5d66cf1f5a..79e903a60862 100644
--- a/sound/usb/usbmixer_maps.c
+++ b/sound/usb/usbmixer_maps.c
@@ -19,11 +19,16 @@
19 * 19 *
20 */ 20 */
21 21
22struct usbmix_dB_map {
23 u32 min;
24 u32 max;
25};
22 26
23struct usbmix_name_map { 27struct usbmix_name_map {
24 int id; 28 int id;
25 const char *name; 29 const char *name;
26 int control; 30 int control;
31 struct usbmix_dB_map *dB;
27}; 32};
28 33
29struct usbmix_selector_map { 34struct usbmix_selector_map {
@@ -72,7 +77,7 @@ static struct usbmix_name_map extigy_map[] = {
72 { 8, "Line Playback" }, /* FU */ 77 { 8, "Line Playback" }, /* FU */
73 /* 9: IT mic */ 78 /* 9: IT mic */
74 { 10, "Mic Playback" }, /* FU */ 79 { 10, "Mic Playback" }, /* FU */
75 { 11, "Capture Input Source" }, /* SU */ 80 { 11, "Capture Source" }, /* SU */
76 { 12, "Capture" }, /* FU */ 81 { 12, "Capture" }, /* FU */
77 /* 13: OT pcm capture */ 82 /* 13: OT pcm capture */
78 /* 14: MU (w/o controls) */ 83 /* 14: MU (w/o controls) */
@@ -102,6 +107,9 @@ static struct usbmix_name_map extigy_map[] = {
102 * e.g. no Master and fake PCM volume 107 * e.g. no Master and fake PCM volume
103 * Pavel Mihaylov <bin@bash.info> 108 * Pavel Mihaylov <bin@bash.info>
104 */ 109 */
110static struct usbmix_dB_map mp3plus_dB_1 = {-4781, 0}; /* just guess */
111static struct usbmix_dB_map mp3plus_dB_2 = {-1781, 618}; /* just guess */
112
105static struct usbmix_name_map mp3plus_map[] = { 113static struct usbmix_name_map mp3plus_map[] = {
106 /* 1: IT pcm */ 114 /* 1: IT pcm */
107 /* 2: IT mic */ 115 /* 2: IT mic */
@@ -110,16 +118,19 @@ static struct usbmix_name_map mp3plus_map[] = {
110 /* 5: OT digital out */ 118 /* 5: OT digital out */
111 /* 6: OT speaker */ 119 /* 6: OT speaker */
112 /* 7: OT pcm capture */ 120 /* 7: OT pcm capture */
113 { 8, "Capture Input Source" }, /* FU, default PCM Capture Source */ 121 { 8, "Capture Source" }, /* FU, default PCM Capture Source */
114 /* (Mic, Input 1 = Line input, Input 2 = Optical input) */ 122 /* (Mic, Input 1 = Line input, Input 2 = Optical input) */
115 { 9, "Master Playback" }, /* FU, default Speaker 1 */ 123 { 9, "Master Playback" }, /* FU, default Speaker 1 */
116 /* { 10, "Mic Capture", 1 }, */ /* FU, Mic Capture */ 124 /* { 10, "Mic Capture", 1 }, */ /* FU, Mic Capture */
117 /* { 10, "Mic Capture", 2 }, */ /* FU, Mic Capture */ 125 { 10, /* "Mic Capture", */ NULL, 2, .dB = &mp3plus_dB_2 },
126 /* FU, Mic Capture */
118 { 10, "Mic Boost", 7 }, /* FU, default Auto Gain Input */ 127 { 10, "Mic Boost", 7 }, /* FU, default Auto Gain Input */
119 { 11, "Line Capture" }, /* FU, default PCM Capture */ 128 { 11, "Line Capture", .dB = &mp3plus_dB_2 },
129 /* FU, default PCM Capture */
120 { 12, "Digital In Playback" }, /* FU, default PCM 1 */ 130 { 12, "Digital In Playback" }, /* FU, default PCM 1 */
121 /* { 13, "Mic Playback" }, */ /* FU, default Mic Playback */ 131 { 13, /* "Mic Playback", */ .dB = &mp3plus_dB_1 },
122 { 14, "Line Playback" }, /* FU, default Speaker */ 132 /* FU, default Mic Playback */
133 { 14, "Line Playback", .dB = &mp3plus_dB_1 }, /* FU, default Speaker */
123 /* 15: MU */ 134 /* 15: MU */
124 { 0 } /* terminator */ 135 { 0 } /* terminator */
125}; 136};
@@ -277,6 +288,22 @@ static struct usbmix_name_map scratch_live_map[] = {
277 { 0 } /* terminator */ 288 { 0 } /* terminator */
278}; 289};
279 290
291/* "Gamesurround Muse Pocket LT" looks same like "Sound Blaster MP3+"
292 * most importand difference is SU[8], it should be set to "Capture Source"
293 * to make alsamixer and PA working properly.
294 * FIXME: or mp3plus_map should use "Capture Source" too,
295 * so this maps can be merget
296 */
297static struct usbmix_name_map hercules_usb51_map[] = {
298 { 8, "Capture Source" }, /* SU, default "PCM Capture Source" */
299 { 9, "Master Playback" }, /* FU, default "Speaker Playback" */
300 { 10, "Mic Boost", 7 }, /* FU, default "Auto Gain Input" */
301 { 11, "Line Capture" }, /* FU, default "PCM Capture" */
302 { 13, "Mic Bypass Playback" }, /* FU, default "Mic Playback" */
303 { 14, "Line Bypass Playback" }, /* FU, default "Line Playback" */
304 { 0 } /* terminator */
305};
306
280/* 307/*
281 * Control map entries 308 * Control map entries
282 */ 309 */
@@ -316,6 +343,13 @@ static struct usbmix_ctl_map usbmix_ctl_maps[] = {
316 .ignore_ctl_error = 1, 343 .ignore_ctl_error = 1,
317 }, 344 },
318 { 345 {
346 /* Hercules Gamesurround Muse Pocket LT
347 * (USB 5.1 Channel Audio Adapter)
348 */
349 .id = USB_ID(0x06f8, 0xc000),
350 .map = hercules_usb51_map,
351 },
352 {
319 .id = USB_ID(0x08bb, 0x2702), 353 .id = USB_ID(0x08bb, 0x2702),
320 .map = linex_map, 354 .map = linex_map,
321 .ignore_ctl_error = 1, 355 .ignore_ctl_error = 1,
diff --git a/sound/usb/usbquirks.h b/sound/usb/usbquirks.h
index f6f201eb24ce..2b426c1fd0e8 100644
--- a/sound/usb/usbquirks.h
+++ b/sound/usb/usbquirks.h
@@ -91,7 +91,7 @@
91 .idVendor = 0x046d, 91 .idVendor = 0x046d,
92 .idProduct = 0x0850, 92 .idProduct = 0x0850,
93 .bInterfaceClass = USB_CLASS_AUDIO, 93 .bInterfaceClass = USB_CLASS_AUDIO,
94 .bInterfaceSubClass = USB_SUBCLASS_AUDIO_CONTROL 94 .bInterfaceSubClass = USB_SUBCLASS_AUDIOCONTROL
95}, 95},
96{ 96{
97 .match_flags = USB_DEVICE_ID_MATCH_DEVICE | 97 .match_flags = USB_DEVICE_ID_MATCH_DEVICE |
@@ -100,7 +100,7 @@
100 .idVendor = 0x046d, 100 .idVendor = 0x046d,
101 .idProduct = 0x08ae, 101 .idProduct = 0x08ae,
102 .bInterfaceClass = USB_CLASS_AUDIO, 102 .bInterfaceClass = USB_CLASS_AUDIO,
103 .bInterfaceSubClass = USB_SUBCLASS_AUDIO_CONTROL 103 .bInterfaceSubClass = USB_SUBCLASS_AUDIOCONTROL
104}, 104},
105{ 105{
106 .match_flags = USB_DEVICE_ID_MATCH_DEVICE | 106 .match_flags = USB_DEVICE_ID_MATCH_DEVICE |
@@ -109,7 +109,7 @@
109 .idVendor = 0x046d, 109 .idVendor = 0x046d,
110 .idProduct = 0x08c6, 110 .idProduct = 0x08c6,
111 .bInterfaceClass = USB_CLASS_AUDIO, 111 .bInterfaceClass = USB_CLASS_AUDIO,
112 .bInterfaceSubClass = USB_SUBCLASS_AUDIO_CONTROL 112 .bInterfaceSubClass = USB_SUBCLASS_AUDIOCONTROL
113}, 113},
114{ 114{
115 .match_flags = USB_DEVICE_ID_MATCH_DEVICE | 115 .match_flags = USB_DEVICE_ID_MATCH_DEVICE |
@@ -118,7 +118,7 @@
118 .idVendor = 0x046d, 118 .idVendor = 0x046d,
119 .idProduct = 0x08f0, 119 .idProduct = 0x08f0,
120 .bInterfaceClass = USB_CLASS_AUDIO, 120 .bInterfaceClass = USB_CLASS_AUDIO,
121 .bInterfaceSubClass = USB_SUBCLASS_AUDIO_CONTROL 121 .bInterfaceSubClass = USB_SUBCLASS_AUDIOCONTROL
122}, 122},
123{ 123{
124 .match_flags = USB_DEVICE_ID_MATCH_DEVICE | 124 .match_flags = USB_DEVICE_ID_MATCH_DEVICE |
@@ -127,7 +127,7 @@
127 .idVendor = 0x046d, 127 .idVendor = 0x046d,
128 .idProduct = 0x08f5, 128 .idProduct = 0x08f5,
129 .bInterfaceClass = USB_CLASS_AUDIO, 129 .bInterfaceClass = USB_CLASS_AUDIO,
130 .bInterfaceSubClass = USB_SUBCLASS_AUDIO_CONTROL 130 .bInterfaceSubClass = USB_SUBCLASS_AUDIOCONTROL
131}, 131},
132{ 132{
133 .match_flags = USB_DEVICE_ID_MATCH_DEVICE | 133 .match_flags = USB_DEVICE_ID_MATCH_DEVICE |
@@ -136,7 +136,7 @@
136 .idVendor = 0x046d, 136 .idVendor = 0x046d,
137 .idProduct = 0x08f6, 137 .idProduct = 0x08f6,
138 .bInterfaceClass = USB_CLASS_AUDIO, 138 .bInterfaceClass = USB_CLASS_AUDIO,
139 .bInterfaceSubClass = USB_SUBCLASS_AUDIO_CONTROL 139 .bInterfaceSubClass = USB_SUBCLASS_AUDIOCONTROL
140}, 140},
141{ 141{
142 USB_DEVICE(0x046d, 0x0990), 142 USB_DEVICE(0x046d, 0x0990),
@@ -301,7 +301,7 @@ YAMAHA_DEVICE(0x7010, "UB99"),
301 .iface = 1, 301 .iface = 1,
302 .altsetting = 1, 302 .altsetting = 1,
303 .altset_idx = 1, 303 .altset_idx = 1,
304 .attributes = EP_CS_ATTR_FILL_MAX, 304 .attributes = UAC_EP_CS_ATTR_FILL_MAX,
305 .endpoint = 0x81, 305 .endpoint = 0x81,
306 .ep_attr = 0x05, 306 .ep_attr = 0x05,
307 .rates = SNDRV_PCM_RATE_CONTINUOUS, 307 .rates = SNDRV_PCM_RATE_CONTINUOUS,
@@ -1016,36 +1016,6 @@ YAMAHA_DEVICE(0x7010, "UB99"),
1016 } 1016 }
1017}, 1017},
1018{ 1018{
1019 USB_DEVICE(0x0582, 0x0044),
1020 .driver_info = (unsigned long) & (const struct snd_usb_audio_quirk) {
1021 .vendor_name = "Roland",
1022 .product_name = "UA-1000",
1023 .ifnum = QUIRK_ANY_INTERFACE,
1024 .type = QUIRK_COMPOSITE,
1025 .data = (const struct snd_usb_audio_quirk[]) {
1026 {
1027 .ifnum = 1,
1028 .type = QUIRK_AUDIO_EDIROL_UA1000
1029 },
1030 {
1031 .ifnum = 2,
1032 .type = QUIRK_AUDIO_EDIROL_UA1000
1033 },
1034 {
1035 .ifnum = 3,
1036 .type = QUIRK_MIDI_FIXED_ENDPOINT,
1037 .data = & (const struct snd_usb_midi_endpoint_info) {
1038 .out_cables = 0x0003,
1039 .in_cables = 0x0003
1040 }
1041 },
1042 {
1043 .ifnum = -1
1044 }
1045 }
1046 }
1047},
1048{
1049 /* has ID 0x0049 when not in "Advanced Driver" mode */ 1019 /* has ID 0x0049 when not in "Advanced Driver" mode */
1050 USB_DEVICE(0x0582, 0x0047), 1020 USB_DEVICE(0x0582, 0x0047),
1051 .driver_info = (unsigned long) & (const struct snd_usb_audio_quirk) { 1021 .driver_info = (unsigned long) & (const struct snd_usb_audio_quirk) {
@@ -1266,37 +1236,6 @@ YAMAHA_DEVICE(0x7010, "UB99"),
1266 } 1236 }
1267 } 1237 }
1268}, 1238},
1269/* Roland UA-101 in High-Speed Mode only */
1270{
1271 USB_DEVICE(0x0582, 0x007d),
1272 .driver_info = (unsigned long) & (const struct snd_usb_audio_quirk) {
1273 .vendor_name = "Roland",
1274 .product_name = "UA-101",
1275 .ifnum = QUIRK_ANY_INTERFACE,
1276 .type = QUIRK_COMPOSITE,
1277 .data = (const struct snd_usb_audio_quirk[]) {
1278 {
1279 .ifnum = 0,
1280 .type = QUIRK_AUDIO_EDIROL_UA101
1281 },
1282 {
1283 .ifnum = 1,
1284 .type = QUIRK_AUDIO_EDIROL_UA101
1285 },
1286 {
1287 .ifnum = 2,
1288 .type = QUIRK_MIDI_FIXED_ENDPOINT,
1289 .data = & (const struct snd_usb_midi_endpoint_info) {
1290 .out_cables = 0x0001,
1291 .in_cables = 0x0001
1292 }
1293 },
1294 {
1295 .ifnum = -1
1296 }
1297 }
1298 }
1299},
1300{ 1239{
1301 /* has ID 0x0081 when not in "Advanced Driver" mode */ 1240 /* has ID 0x0081 when not in "Advanced Driver" mode */
1302 USB_DEVICE(0x0582, 0x0080), 1241 USB_DEVICE(0x0582, 0x0080),
@@ -1563,6 +1502,29 @@ YAMAHA_DEVICE(0x7010, "UB99"),
1563 } 1502 }
1564 } 1503 }
1565}, 1504},
1505{
1506 /* has ID 0x00ea when not in Advanced Driver mode */
1507 USB_DEVICE_VENDOR_SPEC(0x0582, 0x00e9),
1508 .driver_info = (unsigned long) & (const struct snd_usb_audio_quirk) {
1509 /* .vendor_name = "Roland", */
1510 /* .product_name = "UA-1G", */
1511 .ifnum = QUIRK_ANY_INTERFACE,
1512 .type = QUIRK_COMPOSITE,
1513 .data = (const struct snd_usb_audio_quirk[]) {
1514 {
1515 .ifnum = 0,
1516 .type = QUIRK_AUDIO_STANDARD_INTERFACE
1517 },
1518 {
1519 .ifnum = 1,
1520 .type = QUIRK_AUDIO_STANDARD_INTERFACE
1521 },
1522 {
1523 .ifnum = -1
1524 }
1525 }
1526 }
1527},
1566 1528
1567/* Guillemot devices */ 1529/* Guillemot devices */
1568{ 1530{
@@ -2050,6 +2012,33 @@ YAMAHA_DEVICE(0x7010, "UB99"),
2050 } 2012 }
2051}, 2013},
2052 2014
2015/* Access Music devices */
2016{
2017 /* VirusTI Desktop */
2018 USB_DEVICE_VENDOR_SPEC(0x133e, 0x0815),
2019 .driver_info = (unsigned long) &(const struct snd_usb_audio_quirk) {
2020 .ifnum = QUIRK_ANY_INTERFACE,
2021 .type = QUIRK_COMPOSITE,
2022 .data = &(const struct snd_usb_audio_quirk[]) {
2023 {
2024 .ifnum = 3,
2025 .type = QUIRK_MIDI_FIXED_ENDPOINT,
2026 .data = &(const struct snd_usb_midi_endpoint_info) {
2027 .out_cables = 0x0003,
2028 .in_cables = 0x0003
2029 }
2030 },
2031 {
2032 .ifnum = 4,
2033 .type = QUIRK_IGNORE_INTERFACE
2034 },
2035 {
2036 .ifnum = -1
2037 }
2038 }
2039 }
2040},
2041
2053/* */ 2042/* */
2054{ 2043{
2055 /* aka. Serato Scratch Live DJ Box */ 2044 /* aka. Serato Scratch Live DJ Box */
@@ -2082,6 +2071,165 @@ YAMAHA_DEVICE(0x7010, "UB99"),
2082 } 2071 }
2083}, 2072},
2084 2073
2074/* Hauppauge HVR-950Q and HVR-850 */
2075{
2076 USB_DEVICE_VENDOR_SPEC(0x2040, 0x7200),
2077 .match_flags = USB_DEVICE_ID_MATCH_DEVICE |
2078 USB_DEVICE_ID_MATCH_INT_CLASS |
2079 USB_DEVICE_ID_MATCH_INT_SUBCLASS,
2080 .bInterfaceClass = USB_CLASS_AUDIO,
2081 .bInterfaceSubClass = USB_SUBCLASS_AUDIOCONTROL,
2082 .driver_info = (unsigned long) &(const struct snd_usb_audio_quirk) {
2083 .vendor_name = "Hauppauge",
2084 .product_name = "HVR-950Q",
2085 .ifnum = QUIRK_ANY_INTERFACE,
2086 .type = QUIRK_AUDIO_ALIGN_TRANSFER,
2087 }
2088},
2089{
2090 USB_DEVICE_VENDOR_SPEC(0x2040, 0x7201),
2091 .match_flags = USB_DEVICE_ID_MATCH_DEVICE |
2092 USB_DEVICE_ID_MATCH_INT_CLASS |
2093 USB_DEVICE_ID_MATCH_INT_SUBCLASS,
2094 .bInterfaceClass = USB_CLASS_AUDIO,
2095 .bInterfaceSubClass = USB_SUBCLASS_AUDIOCONTROL,
2096 .driver_info = (unsigned long) &(const struct snd_usb_audio_quirk) {
2097 .vendor_name = "Hauppauge",
2098 .product_name = "HVR-950Q",
2099 .ifnum = QUIRK_ANY_INTERFACE,
2100 .type = QUIRK_AUDIO_ALIGN_TRANSFER,
2101 }
2102},
2103{
2104 USB_DEVICE_VENDOR_SPEC(0x2040, 0x7202),
2105 .match_flags = USB_DEVICE_ID_MATCH_DEVICE |
2106 USB_DEVICE_ID_MATCH_INT_CLASS |
2107 USB_DEVICE_ID_MATCH_INT_SUBCLASS,
2108 .bInterfaceClass = USB_CLASS_AUDIO,
2109 .bInterfaceSubClass = USB_SUBCLASS_AUDIOCONTROL,
2110 .driver_info = (unsigned long) &(const struct snd_usb_audio_quirk) {
2111 .vendor_name = "Hauppauge",
2112 .product_name = "HVR-950Q",
2113 .ifnum = QUIRK_ANY_INTERFACE,
2114 .type = QUIRK_AUDIO_ALIGN_TRANSFER,
2115 }
2116},
2117{
2118 USB_DEVICE_VENDOR_SPEC(0x2040, 0x7203),
2119 .match_flags = USB_DEVICE_ID_MATCH_DEVICE |
2120 USB_DEVICE_ID_MATCH_INT_CLASS |
2121 USB_DEVICE_ID_MATCH_INT_SUBCLASS,
2122 .bInterfaceClass = USB_CLASS_AUDIO,
2123 .bInterfaceSubClass = USB_SUBCLASS_AUDIOCONTROL,
2124 .driver_info = (unsigned long) &(const struct snd_usb_audio_quirk) {
2125 .vendor_name = "Hauppauge",
2126 .product_name = "HVR-950Q",
2127 .ifnum = QUIRK_ANY_INTERFACE,
2128 .type = QUIRK_AUDIO_ALIGN_TRANSFER,
2129 }
2130},
2131{
2132 USB_DEVICE_VENDOR_SPEC(0x2040, 0x7204),
2133 .match_flags = USB_DEVICE_ID_MATCH_DEVICE |
2134 USB_DEVICE_ID_MATCH_INT_CLASS |
2135 USB_DEVICE_ID_MATCH_INT_SUBCLASS,
2136 .bInterfaceClass = USB_CLASS_AUDIO,
2137 .bInterfaceSubClass = USB_SUBCLASS_AUDIOCONTROL,
2138 .driver_info = (unsigned long) &(const struct snd_usb_audio_quirk) {
2139 .vendor_name = "Hauppauge",
2140 .product_name = "HVR-950Q",
2141 .ifnum = QUIRK_ANY_INTERFACE,
2142 .type = QUIRK_AUDIO_ALIGN_TRANSFER,
2143 }
2144},
2145{
2146 USB_DEVICE_VENDOR_SPEC(0x2040, 0x7205),
2147 .match_flags = USB_DEVICE_ID_MATCH_DEVICE |
2148 USB_DEVICE_ID_MATCH_INT_CLASS |
2149 USB_DEVICE_ID_MATCH_INT_SUBCLASS,
2150 .bInterfaceClass = USB_CLASS_AUDIO,
2151 .bInterfaceSubClass = USB_SUBCLASS_AUDIOCONTROL,
2152 .driver_info = (unsigned long) &(const struct snd_usb_audio_quirk) {
2153 .vendor_name = "Hauppauge",
2154 .product_name = "HVR-950Q",
2155 .ifnum = QUIRK_ANY_INTERFACE,
2156 .type = QUIRK_AUDIO_ALIGN_TRANSFER,
2157 }
2158},
2159{
2160 USB_DEVICE_VENDOR_SPEC(0x2040, 0x7250),
2161 .match_flags = USB_DEVICE_ID_MATCH_DEVICE |
2162 USB_DEVICE_ID_MATCH_INT_CLASS |
2163 USB_DEVICE_ID_MATCH_INT_SUBCLASS,
2164 .bInterfaceClass = USB_CLASS_AUDIO,
2165 .bInterfaceSubClass = USB_SUBCLASS_AUDIOCONTROL,
2166 .driver_info = (unsigned long) &(const struct snd_usb_audio_quirk) {
2167 .vendor_name = "Hauppauge",
2168 .product_name = "HVR-950Q",
2169 .ifnum = QUIRK_ANY_INTERFACE,
2170 .type = QUIRK_AUDIO_ALIGN_TRANSFER,
2171 }
2172},
2173{
2174 USB_DEVICE_VENDOR_SPEC(0x2040, 0x7230),
2175 .match_flags = USB_DEVICE_ID_MATCH_DEVICE |
2176 USB_DEVICE_ID_MATCH_INT_CLASS |
2177 USB_DEVICE_ID_MATCH_INT_SUBCLASS,
2178 .bInterfaceClass = USB_CLASS_AUDIO,
2179 .bInterfaceSubClass = USB_SUBCLASS_AUDIOCONTROL,
2180 .driver_info = (unsigned long) &(const struct snd_usb_audio_quirk) {
2181 .vendor_name = "Hauppauge",
2182 .product_name = "HVR-850",
2183 .ifnum = QUIRK_ANY_INTERFACE,
2184 .type = QUIRK_AUDIO_ALIGN_TRANSFER,
2185 }
2186},
2187
2188/* Digidesign Mbox */
2189{
2190 /* Thanks to Clemens Ladisch <clemens@ladisch.de> */
2191 USB_DEVICE(0x0dba, 0x1000),
2192 .driver_info = (unsigned long) &(const struct snd_usb_audio_quirk) {
2193 .vendor_name = "Digidesign",
2194 .product_name = "MBox",
2195 .ifnum = QUIRK_ANY_INTERFACE,
2196 .type = QUIRK_COMPOSITE,
2197 .data = (const struct snd_usb_audio_quirk[]){
2198 {
2199 .ifnum = 0,
2200 .type = QUIRK_IGNORE_INTERFACE,
2201 },
2202 {
2203 .ifnum = 1,
2204 .type = QUIRK_AUDIO_FIXED_ENDPOINT,
2205 .data = &(const struct audioformat) {
2206 .format = SNDRV_PCM_FORMAT_S24_3BE,
2207 .channels = 2,
2208 .iface = 1,
2209 .altsetting = 1,
2210 .altset_idx = 1,
2211 .attributes = UAC_EP_CS_ATTR_SAMPLE_RATE,
2212 .endpoint = 0x02,
2213 .ep_attr = 0x01,
2214 .maxpacksize = 0x130,
2215 .rates = SNDRV_PCM_RATE_44100 |
2216 SNDRV_PCM_RATE_48000,
2217 .rate_min = 44100,
2218 .rate_max = 48000,
2219 .nr_rates = 2,
2220 .rate_table = (unsigned int[]) {
2221 44100, 48000
2222 }
2223 }
2224 },
2225 {
2226 .ifnum = -1
2227 }
2228 }
2229
2230 }
2231},
2232
2085{ 2233{
2086 /* 2234 /*
2087 * Some USB MIDI devices don't have an audio control interface, 2235 * Some USB MIDI devices don't have an audio control interface,
@@ -2090,7 +2238,7 @@ YAMAHA_DEVICE(0x7010, "UB99"),
2090 .match_flags = USB_DEVICE_ID_MATCH_INT_CLASS | 2238 .match_flags = USB_DEVICE_ID_MATCH_INT_CLASS |
2091 USB_DEVICE_ID_MATCH_INT_SUBCLASS, 2239 USB_DEVICE_ID_MATCH_INT_SUBCLASS,
2092 .bInterfaceClass = USB_CLASS_AUDIO, 2240 .bInterfaceClass = USB_CLASS_AUDIO,
2093 .bInterfaceSubClass = USB_SUBCLASS_MIDI_STREAMING, 2241 .bInterfaceSubClass = USB_SUBCLASS_MIDISTREAMING,
2094 .driver_info = (unsigned long) & (const struct snd_usb_audio_quirk) { 2242 .driver_info = (unsigned long) & (const struct snd_usb_audio_quirk) {
2095 .ifnum = QUIRK_ANY_INTERFACE, 2243 .ifnum = QUIRK_ANY_INTERFACE,
2096 .type = QUIRK_MIDI_STANDARD_INTERFACE 2244 .type = QUIRK_MIDI_STANDARD_INTERFACE
diff --git a/sound/usb/usx2y/us122l.c b/sound/usb/usx2y/us122l.c
index 99f33766cd51..9ca9a13a78da 100644
--- a/sound/usb/usx2y/us122l.c
+++ b/sound/usb/usx2y/us122l.c
@@ -16,6 +16,9 @@
16 * Inc., 675 Mass Ave, Cambridge, MA 02139, USA. 16 * Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
17 */ 17 */
18 18
19#include <linux/slab.h>
20#include <linux/usb.h>
21#include <linux/usb/audio.h>
19#include <sound/core.h> 22#include <sound/core.h>
20#include <sound/hwdep.h> 23#include <sound/hwdep.h>
21#include <sound/pcm.h> 24#include <sound/pcm.h>
@@ -59,11 +62,33 @@ static int us122l_create_usbmidi(struct snd_card *card)
59 .type = QUIRK_MIDI_US122L, 62 .type = QUIRK_MIDI_US122L,
60 .data = &quirk_data 63 .data = &quirk_data
61 }; 64 };
62 struct usb_device *dev = US122L(card)->chip.dev; 65 struct usb_device *dev = US122L(card)->dev;
63 struct usb_interface *iface = usb_ifnum_to_if(dev, 1); 66 struct usb_interface *iface = usb_ifnum_to_if(dev, 1);
64 67
65 return snd_usb_create_midi_interface(&US122L(card)->chip, 68 return snd_usbmidi_create(card, iface,
66 iface, &quirk); 69 &US122L(card)->midi_list, &quirk);
70}
71
72static int us144_create_usbmidi(struct snd_card *card)
73{
74 static struct snd_usb_midi_endpoint_info quirk_data = {
75 .out_ep = 4,
76 .in_ep = 3,
77 .out_cables = 0x001,
78 .in_cables = 0x001
79 };
80 static struct snd_usb_audio_quirk quirk = {
81 .vendor_name = "US144",
82 .product_name = NAME_ALLCAPS,
83 .ifnum = 0,
84 .type = QUIRK_MIDI_US122L,
85 .data = &quirk_data
86 };
87 struct usb_device *dev = US122L(card)->dev;
88 struct usb_interface *iface = usb_ifnum_to_if(dev, 0);
89
90 return snd_usbmidi_create(card, iface,
91 &US122L(card)->midi_list, &quirk);
67} 92}
68 93
69/* 94/*
@@ -171,7 +196,13 @@ static int usb_stream_hwdep_open(struct snd_hwdep *hw, struct file *file)
171 196
172 if (!us122l->first) 197 if (!us122l->first)
173 us122l->first = file; 198 us122l->first = file;
174 iface = usb_ifnum_to_if(us122l->chip.dev, 1); 199
200 if (us122l->dev->descriptor.idProduct == USB_ID_US144 ||
201 us122l->dev->descriptor.idProduct == USB_ID_US144MKII) {
202 iface = usb_ifnum_to_if(us122l->dev, 0);
203 usb_autopm_get_interface(iface);
204 }
205 iface = usb_ifnum_to_if(us122l->dev, 1);
175 usb_autopm_get_interface(iface); 206 usb_autopm_get_interface(iface);
176 return 0; 207 return 0;
177} 208}
@@ -179,8 +210,15 @@ static int usb_stream_hwdep_open(struct snd_hwdep *hw, struct file *file)
179static int usb_stream_hwdep_release(struct snd_hwdep *hw, struct file *file) 210static int usb_stream_hwdep_release(struct snd_hwdep *hw, struct file *file)
180{ 211{
181 struct us122l *us122l = hw->private_data; 212 struct us122l *us122l = hw->private_data;
182 struct usb_interface *iface = usb_ifnum_to_if(us122l->chip.dev, 1); 213 struct usb_interface *iface;
183 snd_printdd(KERN_DEBUG "%p %p\n", hw, file); 214 snd_printdd(KERN_DEBUG "%p %p\n", hw, file);
215
216 if (us122l->dev->descriptor.idProduct == USB_ID_US144 ||
217 us122l->dev->descriptor.idProduct == USB_ID_US144MKII) {
218 iface = usb_ifnum_to_if(us122l->dev, 0);
219 usb_autopm_put_interface(iface);
220 }
221 iface = usb_ifnum_to_if(us122l->dev, 1);
184 usb_autopm_put_interface(iface); 222 usb_autopm_put_interface(iface);
185 if (us122l->first == file) 223 if (us122l->first == file)
186 us122l->first = NULL; 224 us122l->first = NULL;
@@ -264,7 +302,7 @@ static unsigned int usb_stream_hwdep_poll(struct snd_hwdep *hw,
264static void us122l_stop(struct us122l *us122l) 302static void us122l_stop(struct us122l *us122l)
265{ 303{
266 struct list_head *p; 304 struct list_head *p;
267 list_for_each(p, &us122l->chip.midi_list) 305 list_for_each(p, &us122l->midi_list)
268 snd_usbmidi_input_stop(p); 306 snd_usbmidi_input_stop(p);
269 307
270 usb_stream_stop(&us122l->sk); 308 usb_stream_stop(&us122l->sk);
@@ -280,9 +318,9 @@ static int us122l_set_sample_rate(struct usb_device *dev, int rate)
280 data[0] = rate; 318 data[0] = rate;
281 data[1] = rate >> 8; 319 data[1] = rate >> 8;
282 data[2] = rate >> 16; 320 data[2] = rate >> 16;
283 err = us122l_ctl_msg(dev, usb_sndctrlpipe(dev, 0), SET_CUR, 321 err = us122l_ctl_msg(dev, usb_sndctrlpipe(dev, 0), UAC_SET_CUR,
284 USB_TYPE_CLASS|USB_RECIP_ENDPOINT|USB_DIR_OUT, 322 USB_TYPE_CLASS|USB_RECIP_ENDPOINT|USB_DIR_OUT,
285 SAMPLING_FREQ_CONTROL << 8, ep, data, 3, 1000); 323 UAC_EP_CS_ATTR_SAMPLE_RATE << 8, ep, data, 3, 1000);
286 if (err < 0) 324 if (err < 0)
287 snd_printk(KERN_ERR "%d: cannot set freq %d to ep 0x%x\n", 325 snd_printk(KERN_ERR "%d: cannot set freq %d to ep 0x%x\n",
288 dev->devnum, rate, ep); 326 dev->devnum, rate, ep);
@@ -297,7 +335,7 @@ static bool us122l_start(struct us122l *us122l,
297 unsigned use_packsize = 0; 335 unsigned use_packsize = 0;
298 bool success = false; 336 bool success = false;
299 337
300 if (us122l->chip.dev->speed == USB_SPEED_HIGH) { 338 if (us122l->dev->speed == USB_SPEED_HIGH) {
301 /* The us-122l's descriptor defaults to iso max_packsize 78, 339 /* The us-122l's descriptor defaults to iso max_packsize 78,
302 which isn't needed for samplerates <= 48000. 340 which isn't needed for samplerates <= 48000.
303 Lets save some memory: 341 Lets save some memory:
@@ -314,11 +352,11 @@ static bool us122l_start(struct us122l *us122l,
314 break; 352 break;
315 } 353 }
316 } 354 }
317 if (!usb_stream_new(&us122l->sk, us122l->chip.dev, 1, 2, 355 if (!usb_stream_new(&us122l->sk, us122l->dev, 1, 2,
318 rate, use_packsize, period_frames, 6)) 356 rate, use_packsize, period_frames, 6))
319 goto out; 357 goto out;
320 358
321 err = us122l_set_sample_rate(us122l->chip.dev, rate); 359 err = us122l_set_sample_rate(us122l->dev, rate);
322 if (err < 0) { 360 if (err < 0) {
323 us122l_stop(us122l); 361 us122l_stop(us122l);
324 snd_printk(KERN_ERR "us122l_set_sample_rate error \n"); 362 snd_printk(KERN_ERR "us122l_set_sample_rate error \n");
@@ -330,7 +368,7 @@ static bool us122l_start(struct us122l *us122l,
330 snd_printk(KERN_ERR "us122l_start error %i \n", err); 368 snd_printk(KERN_ERR "us122l_start error %i \n", err);
331 goto out; 369 goto out;
332 } 370 }
333 list_for_each(p, &us122l->chip.midi_list) 371 list_for_each(p, &us122l->midi_list)
334 snd_usbmidi_input_start(p); 372 snd_usbmidi_input_start(p);
335 success = true; 373 success = true;
336out: 374out:
@@ -357,7 +395,7 @@ static int usb_stream_hwdep_ioctl(struct snd_hwdep *hw, struct file *file,
357 err = -ENXIO; 395 err = -ENXIO;
358 goto free; 396 goto free;
359 } 397 }
360 high_speed = us122l->chip.dev->speed == USB_SPEED_HIGH; 398 high_speed = us122l->dev->speed == USB_SPEED_HIGH;
361 if ((cfg->sample_rate != 44100 && cfg->sample_rate != 48000 && 399 if ((cfg->sample_rate != 44100 && cfg->sample_rate != 48000 &&
362 (!high_speed || 400 (!high_speed ||
363 (cfg->sample_rate != 88200 && cfg->sample_rate != 96000))) || 401 (cfg->sample_rate != 88200 && cfg->sample_rate != 96000))) ||
@@ -417,7 +455,7 @@ static int usb_stream_hwdep_new(struct snd_card *card)
417{ 455{
418 int err; 456 int err;
419 struct snd_hwdep *hw; 457 struct snd_hwdep *hw;
420 struct usb_device *dev = US122L(card)->chip.dev; 458 struct usb_device *dev = US122L(card)->dev;
421 459
422 err = snd_hwdep_new(card, SND_USB_STREAM_ID, 0, &hw); 460 err = snd_hwdep_new(card, SND_USB_STREAM_ID, 0, &hw);
423 if (err < 0) 461 if (err < 0)
@@ -443,19 +481,31 @@ static bool us122l_create_card(struct snd_card *card)
443 int err; 481 int err;
444 struct us122l *us122l = US122L(card); 482 struct us122l *us122l = US122L(card);
445 483
446 err = usb_set_interface(us122l->chip.dev, 1, 1); 484 if (us122l->dev->descriptor.idProduct == USB_ID_US144 ||
485 us122l->dev->descriptor.idProduct == USB_ID_US144MKII) {
486 err = usb_set_interface(us122l->dev, 0, 1);
487 if (err) {
488 snd_printk(KERN_ERR "usb_set_interface error \n");
489 return false;
490 }
491 }
492 err = usb_set_interface(us122l->dev, 1, 1);
447 if (err) { 493 if (err) {
448 snd_printk(KERN_ERR "usb_set_interface error \n"); 494 snd_printk(KERN_ERR "usb_set_interface error \n");
449 return false; 495 return false;
450 } 496 }
451 497
452 pt_info_set(us122l->chip.dev, 0x11); 498 pt_info_set(us122l->dev, 0x11);
453 pt_info_set(us122l->chip.dev, 0x10); 499 pt_info_set(us122l->dev, 0x10);
454 500
455 if (!us122l_start(us122l, 44100, 256)) 501 if (!us122l_start(us122l, 44100, 256))
456 return false; 502 return false;
457 503
458 err = us122l_create_usbmidi(card); 504 if (us122l->dev->descriptor.idProduct == USB_ID_US144 ||
505 us122l->dev->descriptor.idProduct == USB_ID_US144MKII)
506 err = us144_create_usbmidi(card);
507 else
508 err = us122l_create_usbmidi(card);
459 if (err < 0) { 509 if (err < 0) {
460 snd_printk(KERN_ERR "us122l_create_usbmidi error %i \n", err); 510 snd_printk(KERN_ERR "us122l_create_usbmidi error %i \n", err);
461 us122l_stop(us122l); 511 us122l_stop(us122l);
@@ -465,7 +515,7 @@ static bool us122l_create_card(struct snd_card *card)
465 if (err < 0) { 515 if (err < 0) {
466/* release the midi resources */ 516/* release the midi resources */
467 struct list_head *p; 517 struct list_head *p;
468 list_for_each(p, &us122l->chip.midi_list) 518 list_for_each(p, &us122l->midi_list)
469 snd_usbmidi_disconnect(p); 519 snd_usbmidi_disconnect(p);
470 520
471 us122l_stop(us122l); 521 us122l_stop(us122l);
@@ -477,7 +527,7 @@ static bool us122l_create_card(struct snd_card *card)
477static void snd_us122l_free(struct snd_card *card) 527static void snd_us122l_free(struct snd_card *card)
478{ 528{
479 struct us122l *us122l = US122L(card); 529 struct us122l *us122l = US122L(card);
480 int index = us122l->chip.index; 530 int index = us122l->card_index;
481 if (index >= 0 && index < SNDRV_CARDS) 531 if (index >= 0 && index < SNDRV_CARDS)
482 snd_us122l_card_used[index] = 0; 532 snd_us122l_card_used[index] = 0;
483} 533}
@@ -497,13 +547,12 @@ static int usx2y_create_card(struct usb_device *device, struct snd_card **cardp)
497 sizeof(struct us122l), &card); 547 sizeof(struct us122l), &card);
498 if (err < 0) 548 if (err < 0)
499 return err; 549 return err;
500 snd_us122l_card_used[US122L(card)->chip.index = dev] = 1; 550 snd_us122l_card_used[US122L(card)->card_index = dev] = 1;
501 card->private_free = snd_us122l_free; 551 card->private_free = snd_us122l_free;
502 US122L(card)->chip.dev = device; 552 US122L(card)->dev = device;
503 US122L(card)->chip.card = card;
504 mutex_init(&US122L(card)->mutex); 553 mutex_init(&US122L(card)->mutex);
505 init_waitqueue_head(&US122L(card)->sk.sleep); 554 init_waitqueue_head(&US122L(card)->sk.sleep);
506 INIT_LIST_HEAD(&US122L(card)->chip.midi_list); 555 INIT_LIST_HEAD(&US122L(card)->midi_list);
507 strcpy(card->driver, "USB "NAME_ALLCAPS""); 556 strcpy(card->driver, "USB "NAME_ALLCAPS"");
508 sprintf(card->shortname, "TASCAM "NAME_ALLCAPS""); 557 sprintf(card->shortname, "TASCAM "NAME_ALLCAPS"");
509 sprintf(card->longname, "%s (%x:%x if %d at %03d/%03d)", 558 sprintf(card->longname, "%s (%x:%x if %d at %03d/%03d)",
@@ -511,8 +560,8 @@ static int usx2y_create_card(struct usb_device *device, struct snd_card **cardp)
511 le16_to_cpu(device->descriptor.idVendor), 560 le16_to_cpu(device->descriptor.idVendor),
512 le16_to_cpu(device->descriptor.idProduct), 561 le16_to_cpu(device->descriptor.idProduct),
513 0, 562 0,
514 US122L(card)->chip.dev->bus->busnum, 563 US122L(card)->dev->bus->busnum,
515 US122L(card)->chip.dev->devnum 564 US122L(card)->dev->devnum
516 ); 565 );
517 *cardp = card; 566 *cardp = card;
518 return 0; 567 return 0;
@@ -542,6 +591,7 @@ static int us122l_usb_probe(struct usb_interface *intf,
542 return err; 591 return err;
543 } 592 }
544 593
594 usb_get_intf(usb_ifnum_to_if(device, 0));
545 usb_get_dev(device); 595 usb_get_dev(device);
546 *cardp = card; 596 *cardp = card;
547 return 0; 597 return 0;
@@ -550,9 +600,17 @@ static int us122l_usb_probe(struct usb_interface *intf,
550static int snd_us122l_probe(struct usb_interface *intf, 600static int snd_us122l_probe(struct usb_interface *intf,
551 const struct usb_device_id *id) 601 const struct usb_device_id *id)
552{ 602{
603 struct usb_device *device = interface_to_usbdev(intf);
553 struct snd_card *card; 604 struct snd_card *card;
554 int err; 605 int err;
555 606
607 if ((device->descriptor.idProduct == USB_ID_US144 ||
608 device->descriptor.idProduct == USB_ID_US144MKII)
609 && device->speed == USB_SPEED_HIGH) {
610 snd_printk(KERN_ERR "disable ehci-hcd to run US-144 \n");
611 return -ENODEV;
612 }
613
556 snd_printdd(KERN_DEBUG"%p:%i\n", 614 snd_printdd(KERN_DEBUG"%p:%i\n",
557 intf, intf->cur_altsetting->desc.bInterfaceNumber); 615 intf, intf->cur_altsetting->desc.bInterfaceNumber);
558 if (intf->cur_altsetting->desc.bInterfaceNumber != 1) 616 if (intf->cur_altsetting->desc.bInterfaceNumber != 1)
@@ -584,15 +642,15 @@ static void snd_us122l_disconnect(struct usb_interface *intf)
584 mutex_lock(&us122l->mutex); 642 mutex_lock(&us122l->mutex);
585 us122l_stop(us122l); 643 us122l_stop(us122l);
586 mutex_unlock(&us122l->mutex); 644 mutex_unlock(&us122l->mutex);
587 us122l->chip.shutdown = 1;
588 645
589/* release the midi resources */ 646/* release the midi resources */
590 list_for_each(p, &us122l->chip.midi_list) { 647 list_for_each(p, &us122l->midi_list) {
591 snd_usbmidi_disconnect(p); 648 snd_usbmidi_disconnect(p);
592 } 649 }
593 650
594 usb_put_intf(intf); 651 usb_put_intf(usb_ifnum_to_if(us122l->dev, 0));
595 usb_put_dev(us122l->chip.dev); 652 usb_put_intf(usb_ifnum_to_if(us122l->dev, 1));
653 usb_put_dev(us122l->dev);
596 654
597 while (atomic_read(&us122l->mmap_count)) 655 while (atomic_read(&us122l->mmap_count))
598 msleep(500); 656 msleep(500);
@@ -615,7 +673,7 @@ static int snd_us122l_suspend(struct usb_interface *intf, pm_message_t message)
615 if (!us122l) 673 if (!us122l)
616 return 0; 674 return 0;
617 675
618 list_for_each(p, &us122l->chip.midi_list) 676 list_for_each(p, &us122l->midi_list)
619 snd_usbmidi_input_stop(p); 677 snd_usbmidi_input_stop(p);
620 678
621 mutex_lock(&us122l->mutex); 679 mutex_lock(&us122l->mutex);
@@ -642,16 +700,24 @@ static int snd_us122l_resume(struct usb_interface *intf)
642 700
643 mutex_lock(&us122l->mutex); 701 mutex_lock(&us122l->mutex);
644 /* needed, doesn't restart without: */ 702 /* needed, doesn't restart without: */
645 err = usb_set_interface(us122l->chip.dev, 1, 1); 703 if (us122l->dev->descriptor.idProduct == USB_ID_US144 ||
704 us122l->dev->descriptor.idProduct == USB_ID_US144MKII) {
705 err = usb_set_interface(us122l->dev, 0, 1);
706 if (err) {
707 snd_printk(KERN_ERR "usb_set_interface error \n");
708 goto unlock;
709 }
710 }
711 err = usb_set_interface(us122l->dev, 1, 1);
646 if (err) { 712 if (err) {
647 snd_printk(KERN_ERR "usb_set_interface error \n"); 713 snd_printk(KERN_ERR "usb_set_interface error \n");
648 goto unlock; 714 goto unlock;
649 } 715 }
650 716
651 pt_info_set(us122l->chip.dev, 0x11); 717 pt_info_set(us122l->dev, 0x11);
652 pt_info_set(us122l->chip.dev, 0x10); 718 pt_info_set(us122l->dev, 0x10);
653 719
654 err = us122l_set_sample_rate(us122l->chip.dev, 720 err = us122l_set_sample_rate(us122l->dev,
655 us122l->sk.s->cfg.sample_rate); 721 us122l->sk.s->cfg.sample_rate);
656 if (err < 0) { 722 if (err < 0) {
657 snd_printk(KERN_ERR "us122l_set_sample_rate error \n"); 723 snd_printk(KERN_ERR "us122l_set_sample_rate error \n");
@@ -661,7 +727,7 @@ static int snd_us122l_resume(struct usb_interface *intf)
661 if (err) 727 if (err)
662 goto unlock; 728 goto unlock;
663 729
664 list_for_each(p, &us122l->chip.midi_list) 730 list_for_each(p, &us122l->midi_list)
665 snd_usbmidi_input_start(p); 731 snd_usbmidi_input_start(p);
666unlock: 732unlock:
667 mutex_unlock(&us122l->mutex); 733 mutex_unlock(&us122l->mutex);
@@ -675,11 +741,21 @@ static struct usb_device_id snd_us122l_usb_id_table[] = {
675 .idVendor = 0x0644, 741 .idVendor = 0x0644,
676 .idProduct = USB_ID_US122L 742 .idProduct = USB_ID_US122L
677 }, 743 },
678/* { */ /* US-144 maybe works when @USB1.1. Untested. */ 744 { /* US-144 only works at USB1.1! Disable module ehci-hcd. */
679/* .match_flags = USB_DEVICE_ID_MATCH_DEVICE, */ 745 .match_flags = USB_DEVICE_ID_MATCH_DEVICE,
680/* .idVendor = 0x0644, */ 746 .idVendor = 0x0644,
681/* .idProduct = USB_ID_US144 */ 747 .idProduct = USB_ID_US144
682/* }, */ 748 },
749 {
750 .match_flags = USB_DEVICE_ID_MATCH_DEVICE,
751 .idVendor = 0x0644,
752 .idProduct = USB_ID_US122MKII
753 },
754 {
755 .match_flags = USB_DEVICE_ID_MATCH_DEVICE,
756 .idVendor = 0x0644,
757 .idProduct = USB_ID_US144MKII
758 },
683 { /* terminator */ } 759 { /* terminator */ }
684}; 760};
685 761
diff --git a/sound/usb/usx2y/us122l.h b/sound/usb/usx2y/us122l.h
index 3d10c4b2a0f5..f263b3f96c86 100644
--- a/sound/usb/usx2y/us122l.h
+++ b/sound/usb/usx2y/us122l.h
@@ -3,7 +3,8 @@
3 3
4 4
5struct us122l { 5struct us122l {
6 struct snd_usb_audio chip; 6 struct usb_device *dev;
7 int card_index;
7 int stride; 8 int stride;
8 struct usb_stream_kernel sk; 9 struct usb_stream_kernel sk;
9 10
@@ -12,6 +13,7 @@ struct us122l {
12 unsigned second_periods_polled; 13 unsigned second_periods_polled;
13 struct file *master; 14 struct file *master;
14 struct file *slave; 15 struct file *slave;
16 struct list_head midi_list;
15 17
16 atomic_t mmap_count; 18 atomic_t mmap_count;
17}; 19};
@@ -23,5 +25,7 @@ struct us122l {
23 25
24#define USB_ID_US122L 0x800E 26#define USB_ID_US122L 0x800E
25#define USB_ID_US144 0x800F 27#define USB_ID_US144 0x800F
28#define USB_ID_US122MKII 0x8021
29#define USB_ID_US144MKII 0x8020
26 30
27#endif 31#endif
diff --git a/sound/usb/usx2y/usX2Yhwdep.c b/sound/usb/usx2y/usX2Yhwdep.c
index 52e04b2f35d3..04aafb43a13c 100644
--- a/sound/usb/usx2y/usX2Yhwdep.c
+++ b/sound/usb/usx2y/usX2Yhwdep.c
@@ -21,6 +21,7 @@
21 */ 21 */
22 22
23#include <linux/interrupt.h> 23#include <linux/interrupt.h>
24#include <linux/slab.h>
24#include <linux/usb.h> 25#include <linux/usb.h>
25#include <sound/core.h> 26#include <sound/core.h>
26#include <sound/memalloc.h> 27#include <sound/memalloc.h>
@@ -114,7 +115,7 @@ static int snd_usX2Y_hwdep_dsp_status(struct snd_hwdep *hw,
114 struct usX2Ydev *us428 = hw->private_data; 115 struct usX2Ydev *us428 = hw->private_data;
115 int id = -1; 116 int id = -1;
116 117
117 switch (le16_to_cpu(us428->chip.dev->descriptor.idProduct)) { 118 switch (le16_to_cpu(us428->dev->descriptor.idProduct)) {
118 case USB_ID_US122: 119 case USB_ID_US122:
119 id = USX2Y_TYPE_122; 120 id = USX2Y_TYPE_122;
120 break; 121 break;
@@ -164,14 +165,14 @@ static int usX2Y_create_usbmidi(struct snd_card *card)
164 .type = QUIRK_MIDI_FIXED_ENDPOINT, 165 .type = QUIRK_MIDI_FIXED_ENDPOINT,
165 .data = &quirk_data_2 166 .data = &quirk_data_2
166 }; 167 };
167 struct usb_device *dev = usX2Y(card)->chip.dev; 168 struct usb_device *dev = usX2Y(card)->dev;
168 struct usb_interface *iface = usb_ifnum_to_if(dev, 0); 169 struct usb_interface *iface = usb_ifnum_to_if(dev, 0);
169 struct snd_usb_audio_quirk *quirk = 170 struct snd_usb_audio_quirk *quirk =
170 le16_to_cpu(dev->descriptor.idProduct) == USB_ID_US428 ? 171 le16_to_cpu(dev->descriptor.idProduct) == USB_ID_US428 ?
171 &quirk_2 : &quirk_1; 172 &quirk_2 : &quirk_1;
172 173
173 snd_printdd("usX2Y_create_usbmidi \n"); 174 snd_printdd("usX2Y_create_usbmidi \n");
174 return snd_usb_create_midi_interface(&usX2Y(card)->chip, iface, quirk); 175 return snd_usbmidi_create(card, iface, &usX2Y(card)->midi_list, quirk);
175} 176}
176 177
177static int usX2Y_create_alsa_devices(struct snd_card *card) 178static int usX2Y_create_alsa_devices(struct snd_card *card)
@@ -202,7 +203,7 @@ static int snd_usX2Y_hwdep_dsp_load(struct snd_hwdep *hw,
202 snd_printdd( "dsp_load %s\n", dsp->name); 203 snd_printdd( "dsp_load %s\n", dsp->name);
203 204
204 if (access_ok(VERIFY_READ, dsp->image, dsp->length)) { 205 if (access_ok(VERIFY_READ, dsp->image, dsp->length)) {
205 struct usb_device* dev = priv->chip.dev; 206 struct usb_device* dev = priv->dev;
206 char *buf; 207 char *buf;
207 208
208 buf = memdup_user(dsp->image, dsp->length); 209 buf = memdup_user(dsp->image, dsp->length);
diff --git a/sound/usb/usx2y/usb_stream.c b/sound/usb/usx2y/usb_stream.c
index 12ae0340adc0..c400ade3ff08 100644
--- a/sound/usb/usx2y/usb_stream.c
+++ b/sound/usb/usx2y/usb_stream.c
@@ -17,6 +17,7 @@
17 */ 17 */
18 18
19#include <linux/usb.h> 19#include <linux/usb.h>
20#include <linux/gfp.h>
20 21
21#include "usb_stream.h" 22#include "usb_stream.h"
22 23
diff --git a/sound/usb/usx2y/usbusx2y.c b/sound/usb/usx2y/usbusx2y.c
index cb4bb8373ca2..cbd37f2c76d0 100644
--- a/sound/usb/usx2y/usbusx2y.c
+++ b/sound/usb/usx2y/usbusx2y.c
@@ -133,6 +133,7 @@
133#include <linux/init.h> 133#include <linux/init.h>
134#include <linux/module.h> 134#include <linux/module.h>
135#include <linux/moduleparam.h> 135#include <linux/moduleparam.h>
136#include <linux/slab.h>
136#include <linux/interrupt.h> 137#include <linux/interrupt.h>
137#include <linux/usb.h> 138#include <linux/usb.h>
138#include <sound/core.h> 139#include <sound/core.h>
@@ -239,8 +240,8 @@ static void i_usX2Y_In04Int(struct urb *urb)
239 for (j = 0; j < URBS_AsyncSeq && !err; ++j) 240 for (j = 0; j < URBS_AsyncSeq && !err; ++j)
240 if (0 == usX2Y->AS04.urb[j]->status) { 241 if (0 == usX2Y->AS04.urb[j]->status) {
241 struct us428_p4out *p4out = us428ctls->p4out + send; // FIXME if more than 1 p4out is new, 1 gets lost. 242 struct us428_p4out *p4out = us428ctls->p4out + send; // FIXME if more than 1 p4out is new, 1 gets lost.
242 usb_fill_bulk_urb(usX2Y->AS04.urb[j], usX2Y->chip.dev, 243 usb_fill_bulk_urb(usX2Y->AS04.urb[j], usX2Y->dev,
243 usb_sndbulkpipe(usX2Y->chip.dev, 0x04), &p4out->val.vol, 244 usb_sndbulkpipe(usX2Y->dev, 0x04), &p4out->val.vol,
244 p4out->type == eLT_Light ? sizeof(struct us428_lights) : 5, 245 p4out->type == eLT_Light ? sizeof(struct us428_lights) : 5,
245 i_usX2Y_Out04Int, usX2Y); 246 i_usX2Y_Out04Int, usX2Y);
246 err = usb_submit_urb(usX2Y->AS04.urb[j], GFP_ATOMIC); 247 err = usb_submit_urb(usX2Y->AS04.urb[j], GFP_ATOMIC);
@@ -253,7 +254,7 @@ static void i_usX2Y_In04Int(struct urb *urb)
253 if (err) 254 if (err)
254 snd_printk(KERN_ERR "In04Int() usb_submit_urb err=%i\n", err); 255 snd_printk(KERN_ERR "In04Int() usb_submit_urb err=%i\n", err);
255 256
256 urb->dev = usX2Y->chip.dev; 257 urb->dev = usX2Y->dev;
257 usb_submit_urb(urb, GFP_ATOMIC); 258 usb_submit_urb(urb, GFP_ATOMIC);
258} 259}
259 260
@@ -273,8 +274,8 @@ int usX2Y_AsyncSeq04_init(struct usX2Ydev *usX2Y)
273 err = -ENOMEM; 274 err = -ENOMEM;
274 break; 275 break;
275 } 276 }
276 usb_fill_bulk_urb( usX2Y->AS04.urb[i], usX2Y->chip.dev, 277 usb_fill_bulk_urb( usX2Y->AS04.urb[i], usX2Y->dev,
277 usb_sndbulkpipe(usX2Y->chip.dev, 0x04), 278 usb_sndbulkpipe(usX2Y->dev, 0x04),
278 usX2Y->AS04.buffer + URB_DataLen_AsyncSeq*i, 0, 279 usX2Y->AS04.buffer + URB_DataLen_AsyncSeq*i, 0,
279 i_usX2Y_Out04Int, usX2Y 280 i_usX2Y_Out04Int, usX2Y
280 ); 281 );
@@ -293,7 +294,7 @@ int usX2Y_In04_init(struct usX2Ydev *usX2Y)
293 } 294 }
294 295
295 init_waitqueue_head(&usX2Y->In04WaitQueue); 296 init_waitqueue_head(&usX2Y->In04WaitQueue);
296 usb_fill_int_urb(usX2Y->In04urb, usX2Y->chip.dev, usb_rcvintpipe(usX2Y->chip.dev, 0x4), 297 usb_fill_int_urb(usX2Y->In04urb, usX2Y->dev, usb_rcvintpipe(usX2Y->dev, 0x4),
297 usX2Y->In04Buf, 21, 298 usX2Y->In04Buf, 21,
298 i_usX2Y_In04Int, usX2Y, 299 i_usX2Y_In04Int, usX2Y,
299 10); 300 10);
@@ -348,13 +349,12 @@ static int usX2Y_create_card(struct usb_device *device, struct snd_card **cardp)
348 sizeof(struct usX2Ydev), &card); 349 sizeof(struct usX2Ydev), &card);
349 if (err < 0) 350 if (err < 0)
350 return err; 351 return err;
351 snd_usX2Y_card_used[usX2Y(card)->chip.index = dev] = 1; 352 snd_usX2Y_card_used[usX2Y(card)->card_index = dev] = 1;
352 card->private_free = snd_usX2Y_card_private_free; 353 card->private_free = snd_usX2Y_card_private_free;
353 usX2Y(card)->chip.dev = device; 354 usX2Y(card)->dev = device;
354 usX2Y(card)->chip.card = card;
355 init_waitqueue_head(&usX2Y(card)->prepare_wait_queue); 355 init_waitqueue_head(&usX2Y(card)->prepare_wait_queue);
356 mutex_init(&usX2Y(card)->prepare_mutex); 356 mutex_init(&usX2Y(card)->prepare_mutex);
357 INIT_LIST_HEAD(&usX2Y(card)->chip.midi_list); 357 INIT_LIST_HEAD(&usX2Y(card)->midi_list);
358 strcpy(card->driver, "USB "NAME_ALLCAPS""); 358 strcpy(card->driver, "USB "NAME_ALLCAPS"");
359 sprintf(card->shortname, "TASCAM "NAME_ALLCAPS""); 359 sprintf(card->shortname, "TASCAM "NAME_ALLCAPS"");
360 sprintf(card->longname, "%s (%x:%x if %d at %03d/%03d)", 360 sprintf(card->longname, "%s (%x:%x if %d at %03d/%03d)",
@@ -362,7 +362,7 @@ static int usX2Y_create_card(struct usb_device *device, struct snd_card **cardp)
362 le16_to_cpu(device->descriptor.idVendor), 362 le16_to_cpu(device->descriptor.idVendor),
363 le16_to_cpu(device->descriptor.idProduct), 363 le16_to_cpu(device->descriptor.idProduct),
364 0,//us428(card)->usbmidi.ifnum, 364 0,//us428(card)->usbmidi.ifnum,
365 usX2Y(card)->chip.dev->bus->busnum, usX2Y(card)->chip.dev->devnum 365 usX2Y(card)->dev->bus->busnum, usX2Y(card)->dev->devnum
366 ); 366 );
367 *cardp = card; 367 *cardp = card;
368 return 0; 368 return 0;
@@ -432,8 +432,8 @@ static void snd_usX2Y_card_private_free(struct snd_card *card)
432 usb_free_urb(usX2Y(card)->In04urb); 432 usb_free_urb(usX2Y(card)->In04urb);
433 if (usX2Y(card)->us428ctls_sharedmem) 433 if (usX2Y(card)->us428ctls_sharedmem)
434 snd_free_pages(usX2Y(card)->us428ctls_sharedmem, sizeof(*usX2Y(card)->us428ctls_sharedmem)); 434 snd_free_pages(usX2Y(card)->us428ctls_sharedmem, sizeof(*usX2Y(card)->us428ctls_sharedmem));
435 if (usX2Y(card)->chip.index >= 0 && usX2Y(card)->chip.index < SNDRV_CARDS) 435 if (usX2Y(card)->card_index >= 0 && usX2Y(card)->card_index < SNDRV_CARDS)
436 snd_usX2Y_card_used[usX2Y(card)->chip.index] = 0; 436 snd_usX2Y_card_used[usX2Y(card)->card_index] = 0;
437} 437}
438 438
439/* 439/*
@@ -445,13 +445,12 @@ static void usX2Y_usb_disconnect(struct usb_device *device, void* ptr)
445 struct snd_card *card = ptr; 445 struct snd_card *card = ptr;
446 struct usX2Ydev *usX2Y = usX2Y(card); 446 struct usX2Ydev *usX2Y = usX2Y(card);
447 struct list_head *p; 447 struct list_head *p;
448 usX2Y->chip.shutdown = 1;
449 usX2Y->chip_status = USX2Y_STAT_CHIP_HUP; 448 usX2Y->chip_status = USX2Y_STAT_CHIP_HUP;
450 usX2Y_unlinkSeq(&usX2Y->AS04); 449 usX2Y_unlinkSeq(&usX2Y->AS04);
451 usb_kill_urb(usX2Y->In04urb); 450 usb_kill_urb(usX2Y->In04urb);
452 snd_card_disconnect(card); 451 snd_card_disconnect(card);
453 /* release the midi resources */ 452 /* release the midi resources */
454 list_for_each(p, &usX2Y->chip.midi_list) { 453 list_for_each(p, &usX2Y->midi_list) {
455 snd_usbmidi_disconnect(p); 454 snd_usbmidi_disconnect(p);
456 } 455 }
457 if (usX2Y->us428ctls_sharedmem) 456 if (usX2Y->us428ctls_sharedmem)
diff --git a/sound/usb/usx2y/usbusx2y.h b/sound/usb/usx2y/usbusx2y.h
index 456b5fdbc339..1d174cea352b 100644
--- a/sound/usb/usx2y/usbusx2y.h
+++ b/sound/usb/usx2y/usbusx2y.h
@@ -22,7 +22,8 @@ struct snd_usX2Y_urbSeq {
22#include "usx2yhwdeppcm.h" 22#include "usx2yhwdeppcm.h"
23 23
24struct usX2Ydev { 24struct usX2Ydev {
25 struct snd_usb_audio chip; 25 struct usb_device *dev;
26 int card_index;
26 int stride; 27 int stride;
27 struct urb *In04urb; 28 struct urb *In04urb;
28 void *In04Buf; 29 void *In04Buf;
@@ -42,6 +43,9 @@ struct usX2Ydev {
42 struct snd_usX2Y_substream *subs[4]; 43 struct snd_usX2Y_substream *subs[4];
43 struct snd_usX2Y_substream * volatile prepare_subs; 44 struct snd_usX2Y_substream * volatile prepare_subs;
44 wait_queue_head_t prepare_wait_queue; 45 wait_queue_head_t prepare_wait_queue;
46 struct list_head midi_list;
47 struct list_head pcm_list;
48 int pcm_devs;
45}; 49};
46 50
47 51
diff --git a/sound/usb/usx2y/usbusx2yaudio.c b/sound/usb/usx2y/usbusx2yaudio.c
index 9efd27f6b52f..5d37d1ccf813 100644
--- a/sound/usb/usx2y/usbusx2yaudio.c
+++ b/sound/usb/usx2y/usbusx2yaudio.c
@@ -32,6 +32,7 @@
32 32
33 33
34#include <linux/interrupt.h> 34#include <linux/interrupt.h>
35#include <linux/slab.h>
35#include <linux/usb.h> 36#include <linux/usb.h>
36#include <sound/core.h> 37#include <sound/core.h>
37#include <sound/info.h> 38#include <sound/info.h>
@@ -199,7 +200,7 @@ static int usX2Y_urb_submit(struct snd_usX2Y_substream *subs, struct urb *urb, i
199 return -ENODEV; 200 return -ENODEV;
200 urb->start_frame = (frame + NRURBS * nr_of_packs()); // let hcd do rollover sanity checks 201 urb->start_frame = (frame + NRURBS * nr_of_packs()); // let hcd do rollover sanity checks
201 urb->hcpriv = NULL; 202 urb->hcpriv = NULL;
202 urb->dev = subs->usX2Y->chip.dev; /* we need to set this at each time */ 203 urb->dev = subs->usX2Y->dev; /* we need to set this at each time */
203 if ((err = usb_submit_urb(urb, GFP_ATOMIC)) < 0) { 204 if ((err = usb_submit_urb(urb, GFP_ATOMIC)) < 0) {
204 snd_printk(KERN_ERR "usb_submit_urb() returned %i\n", err); 205 snd_printk(KERN_ERR "usb_submit_urb() returned %i\n", err);
205 return err; 206 return err;
@@ -300,7 +301,7 @@ static void usX2Y_error_sequence(struct usX2Ydev *usX2Y,
300"Sequence Error!(hcd_frame=%i ep=%i%s;wait=%i,frame=%i).\n" 301"Sequence Error!(hcd_frame=%i ep=%i%s;wait=%i,frame=%i).\n"
301"Most propably some urb of usb-frame %i is still missing.\n" 302"Most propably some urb of usb-frame %i is still missing.\n"
302"Cause could be too long delays in usb-hcd interrupt handling.\n", 303"Cause could be too long delays in usb-hcd interrupt handling.\n",
303 usb_get_current_frame_number(usX2Y->chip.dev), 304 usb_get_current_frame_number(usX2Y->dev),
304 subs->endpoint, usb_pipein(urb->pipe) ? "in" : "out", 305 subs->endpoint, usb_pipein(urb->pipe) ? "in" : "out",
305 usX2Y->wait_iso_frame, urb->start_frame, usX2Y->wait_iso_frame); 306 usX2Y->wait_iso_frame, urb->start_frame, usX2Y->wait_iso_frame);
306 usX2Y_clients_stop(usX2Y); 307 usX2Y_clients_stop(usX2Y);
@@ -313,7 +314,7 @@ static void i_usX2Y_urb_complete(struct urb *urb)
313 314
314 if (unlikely(atomic_read(&subs->state) < state_PREPARED)) { 315 if (unlikely(atomic_read(&subs->state) < state_PREPARED)) {
315 snd_printdd("hcd_frame=%i ep=%i%s status=%i start_frame=%i\n", 316 snd_printdd("hcd_frame=%i ep=%i%s status=%i start_frame=%i\n",
316 usb_get_current_frame_number(usX2Y->chip.dev), 317 usb_get_current_frame_number(usX2Y->dev),
317 subs->endpoint, usb_pipein(urb->pipe) ? "in" : "out", 318 subs->endpoint, usb_pipein(urb->pipe) ? "in" : "out",
318 urb->status, urb->start_frame); 319 urb->status, urb->start_frame);
319 return; 320 return;
@@ -424,7 +425,7 @@ static int usX2Y_urbs_allocate(struct snd_usX2Y_substream *subs)
424 int i; 425 int i;
425 unsigned int pipe; 426 unsigned int pipe;
426 int is_playback = subs == subs->usX2Y->subs[SNDRV_PCM_STREAM_PLAYBACK]; 427 int is_playback = subs == subs->usX2Y->subs[SNDRV_PCM_STREAM_PLAYBACK];
427 struct usb_device *dev = subs->usX2Y->chip.dev; 428 struct usb_device *dev = subs->usX2Y->dev;
428 429
429 pipe = is_playback ? usb_sndisocpipe(dev, subs->endpoint) : 430 pipe = is_playback ? usb_sndisocpipe(dev, subs->endpoint) :
430 usb_rcvisocpipe(dev, subs->endpoint); 431 usb_rcvisocpipe(dev, subs->endpoint);
@@ -500,7 +501,7 @@ static int usX2Y_urbs_start(struct snd_usX2Y_substream *subs)
500 unsigned long pack; 501 unsigned long pack;
501 if (0 == i) 502 if (0 == i)
502 atomic_set(&subs->state, state_STARTING3); 503 atomic_set(&subs->state, state_STARTING3);
503 urb->dev = usX2Y->chip.dev; 504 urb->dev = usX2Y->dev;
504 urb->transfer_flags = URB_ISO_ASAP; 505 urb->transfer_flags = URB_ISO_ASAP;
505 for (pack = 0; pack < nr_of_packs(); pack++) { 506 for (pack = 0; pack < nr_of_packs(); pack++) {
506 urb->iso_frame_desc[pack].offset = subs->maxpacksize * pack; 507 urb->iso_frame_desc[pack].offset = subs->maxpacksize * pack;
@@ -692,7 +693,7 @@ static int usX2Y_rate_set(struct usX2Ydev *usX2Y, int rate)
692 } 693 }
693 ((char*)(usbdata + i))[0] = ra[i].c1; 694 ((char*)(usbdata + i))[0] = ra[i].c1;
694 ((char*)(usbdata + i))[1] = ra[i].c2; 695 ((char*)(usbdata + i))[1] = ra[i].c2;
695 usb_fill_bulk_urb(us->urb[i], usX2Y->chip.dev, usb_sndbulkpipe(usX2Y->chip.dev, 4), 696 usb_fill_bulk_urb(us->urb[i], usX2Y->dev, usb_sndbulkpipe(usX2Y->dev, 4),
696 usbdata + i, 2, i_usX2Y_04Int, usX2Y); 697 usbdata + i, 2, i_usX2Y_04Int, usX2Y);
697#ifdef OLD_USB 698#ifdef OLD_USB
698 us->urb[i]->transfer_flags = USB_QUEUE_BULK; 699 us->urb[i]->transfer_flags = USB_QUEUE_BULK;
@@ -740,17 +741,17 @@ static int usX2Y_format_set(struct usX2Ydev *usX2Y, snd_pcm_format_t format)
740 alternate = 1; 741 alternate = 1;
741 usX2Y->stride = 4; 742 usX2Y->stride = 4;
742 } 743 }
743 list_for_each(p, &usX2Y->chip.midi_list) { 744 list_for_each(p, &usX2Y->midi_list) {
744 snd_usbmidi_input_stop(p); 745 snd_usbmidi_input_stop(p);
745 } 746 }
746 usb_kill_urb(usX2Y->In04urb); 747 usb_kill_urb(usX2Y->In04urb);
747 if ((err = usb_set_interface(usX2Y->chip.dev, 0, alternate))) { 748 if ((err = usb_set_interface(usX2Y->dev, 0, alternate))) {
748 snd_printk(KERN_ERR "usb_set_interface error \n"); 749 snd_printk(KERN_ERR "usb_set_interface error \n");
749 return err; 750 return err;
750 } 751 }
751 usX2Y->In04urb->dev = usX2Y->chip.dev; 752 usX2Y->In04urb->dev = usX2Y->dev;
752 err = usb_submit_urb(usX2Y->In04urb, GFP_KERNEL); 753 err = usb_submit_urb(usX2Y->In04urb, GFP_KERNEL);
753 list_for_each(p, &usX2Y->chip.midi_list) { 754 list_for_each(p, &usX2Y->midi_list) {
754 snd_usbmidi_input_start(p); 755 snd_usbmidi_input_start(p);
755 } 756 }
756 usX2Y->format = format; 757 usX2Y->format = format;
@@ -955,7 +956,7 @@ static int usX2Y_audio_stream_new(struct snd_card *card, int playback_endpoint,
955 struct snd_pcm *pcm; 956 struct snd_pcm *pcm;
956 int err, i; 957 int err, i;
957 struct snd_usX2Y_substream **usX2Y_substream = 958 struct snd_usX2Y_substream **usX2Y_substream =
958 usX2Y(card)->subs + 2 * usX2Y(card)->chip.pcm_devs; 959 usX2Y(card)->subs + 2 * usX2Y(card)->pcm_devs;
959 960
960 for (i = playback_endpoint ? SNDRV_PCM_STREAM_PLAYBACK : SNDRV_PCM_STREAM_CAPTURE; 961 for (i = playback_endpoint ? SNDRV_PCM_STREAM_PLAYBACK : SNDRV_PCM_STREAM_CAPTURE;
961 i <= SNDRV_PCM_STREAM_CAPTURE; ++i) { 962 i <= SNDRV_PCM_STREAM_CAPTURE; ++i) {
@@ -971,7 +972,7 @@ static int usX2Y_audio_stream_new(struct snd_card *card, int playback_endpoint,
971 usX2Y_substream[SNDRV_PCM_STREAM_PLAYBACK]->endpoint = playback_endpoint; 972 usX2Y_substream[SNDRV_PCM_STREAM_PLAYBACK]->endpoint = playback_endpoint;
972 usX2Y_substream[SNDRV_PCM_STREAM_CAPTURE]->endpoint = capture_endpoint; 973 usX2Y_substream[SNDRV_PCM_STREAM_CAPTURE]->endpoint = capture_endpoint;
973 974
974 err = snd_pcm_new(card, NAME_ALLCAPS" Audio", usX2Y(card)->chip.pcm_devs, 975 err = snd_pcm_new(card, NAME_ALLCAPS" Audio", usX2Y(card)->pcm_devs,
975 playback_endpoint ? 1 : 0, 1, 976 playback_endpoint ? 1 : 0, 1,
976 &pcm); 977 &pcm);
977 if (err < 0) { 978 if (err < 0) {
@@ -987,7 +988,7 @@ static int usX2Y_audio_stream_new(struct snd_card *card, int playback_endpoint,
987 pcm->private_free = snd_usX2Y_pcm_private_free; 988 pcm->private_free = snd_usX2Y_pcm_private_free;
988 pcm->info_flags = 0; 989 pcm->info_flags = 0;
989 990
990 sprintf(pcm->name, NAME_ALLCAPS" Audio #%d", usX2Y(card)->chip.pcm_devs); 991 sprintf(pcm->name, NAME_ALLCAPS" Audio #%d", usX2Y(card)->pcm_devs);
991 992
992 if ((playback_endpoint && 993 if ((playback_endpoint &&
993 0 > (err = snd_pcm_lib_preallocate_pages(pcm->streams[SNDRV_PCM_STREAM_PLAYBACK].substream, 994 0 > (err = snd_pcm_lib_preallocate_pages(pcm->streams[SNDRV_PCM_STREAM_PLAYBACK].substream,
@@ -1001,7 +1002,7 @@ static int usX2Y_audio_stream_new(struct snd_card *card, int playback_endpoint,
1001 snd_usX2Y_pcm_private_free(pcm); 1002 snd_usX2Y_pcm_private_free(pcm);
1002 return err; 1003 return err;
1003 } 1004 }
1004 usX2Y(card)->chip.pcm_devs++; 1005 usX2Y(card)->pcm_devs++;
1005 1006
1006 return 0; 1007 return 0;
1007} 1008}
@@ -1013,14 +1014,14 @@ int usX2Y_audio_create(struct snd_card *card)
1013{ 1014{
1014 int err = 0; 1015 int err = 0;
1015 1016
1016 INIT_LIST_HEAD(&usX2Y(card)->chip.pcm_list); 1017 INIT_LIST_HEAD(&usX2Y(card)->pcm_list);
1017 1018
1018 if (0 > (err = usX2Y_audio_stream_new(card, 0xA, 0x8))) 1019 if (0 > (err = usX2Y_audio_stream_new(card, 0xA, 0x8)))
1019 return err; 1020 return err;
1020 if (le16_to_cpu(usX2Y(card)->chip.dev->descriptor.idProduct) == USB_ID_US428) 1021 if (le16_to_cpu(usX2Y(card)->dev->descriptor.idProduct) == USB_ID_US428)
1021 if (0 > (err = usX2Y_audio_stream_new(card, 0, 0xA))) 1022 if (0 > (err = usX2Y_audio_stream_new(card, 0, 0xA)))
1022 return err; 1023 return err;
1023 if (le16_to_cpu(usX2Y(card)->chip.dev->descriptor.idProduct) != USB_ID_US122) 1024 if (le16_to_cpu(usX2Y(card)->dev->descriptor.idProduct) != USB_ID_US122)
1024 err = usX2Y_rate_set(usX2Y(card), 44100); // Lets us428 recognize output-volume settings, disturbs us122. 1025 err = usX2Y_rate_set(usX2Y(card), 44100); // Lets us428 recognize output-volume settings, disturbs us122.
1025 return err; 1026 return err;
1026} 1027}
diff --git a/sound/usb/usx2y/usx2yhwdeppcm.c b/sound/usb/usx2y/usx2yhwdeppcm.c
index 4b2304c2e02d..2a528e56afd5 100644
--- a/sound/usb/usx2y/usx2yhwdeppcm.c
+++ b/sound/usb/usx2y/usx2yhwdeppcm.c
@@ -51,6 +51,7 @@
51*/ 51*/
52 52
53#include <linux/delay.h> 53#include <linux/delay.h>
54#include <linux/gfp.h>
54#include "usbusx2yaudio.c" 55#include "usbusx2yaudio.c"
55 56
56#if defined(USX2Y_NRPACKS_VARIABLE) || (!defined(USX2Y_NRPACKS_VARIABLE) && USX2Y_NRPACKS == 1) 57#if defined(USX2Y_NRPACKS_VARIABLE) || (!defined(USX2Y_NRPACKS_VARIABLE) && USX2Y_NRPACKS == 1)
@@ -234,7 +235,7 @@ static void i_usX2Y_usbpcm_urb_complete(struct urb *urb)
234 235
235 if (unlikely(atomic_read(&subs->state) < state_PREPARED)) { 236 if (unlikely(atomic_read(&subs->state) < state_PREPARED)) {
236 snd_printdd("hcd_frame=%i ep=%i%s status=%i start_frame=%i\n", 237 snd_printdd("hcd_frame=%i ep=%i%s status=%i start_frame=%i\n",
237 usb_get_current_frame_number(usX2Y->chip.dev), 238 usb_get_current_frame_number(usX2Y->dev),
238 subs->endpoint, usb_pipein(urb->pipe) ? "in" : "out", 239 subs->endpoint, usb_pipein(urb->pipe) ? "in" : "out",
239 urb->status, urb->start_frame); 240 urb->status, urb->start_frame);
240 return; 241 return;
@@ -318,7 +319,7 @@ static int usX2Y_usbpcm_urbs_allocate(struct snd_usX2Y_substream *subs)
318 int i; 319 int i;
319 unsigned int pipe; 320 unsigned int pipe;
320 int is_playback = subs == subs->usX2Y->subs[SNDRV_PCM_STREAM_PLAYBACK]; 321 int is_playback = subs == subs->usX2Y->subs[SNDRV_PCM_STREAM_PLAYBACK];
321 struct usb_device *dev = subs->usX2Y->chip.dev; 322 struct usb_device *dev = subs->usX2Y->dev;
322 323
323 pipe = is_playback ? usb_sndisocpipe(dev, subs->endpoint) : 324 pipe = is_playback ? usb_sndisocpipe(dev, subs->endpoint) :
324 usb_rcvisocpipe(dev, subs->endpoint); 325 usb_rcvisocpipe(dev, subs->endpoint);
@@ -441,7 +442,7 @@ static int usX2Y_usbpcm_urbs_start(struct snd_usX2Y_substream *subs)
441 unsigned long pack; 442 unsigned long pack;
442 if (0 == u) 443 if (0 == u)
443 atomic_set(&subs->state, state_STARTING3); 444 atomic_set(&subs->state, state_STARTING3);
444 urb->dev = usX2Y->chip.dev; 445 urb->dev = usX2Y->dev;
445 urb->transfer_flags = URB_ISO_ASAP; 446 urb->transfer_flags = URB_ISO_ASAP;
446 for (pack = 0; pack < nr_of_packs(); pack++) { 447 for (pack = 0; pack < nr_of_packs(); pack++) {
447 urb->iso_frame_desc[pack].offset = subs->maxpacksize * (pack + u * nr_of_packs()); 448 urb->iso_frame_desc[pack].offset = subs->maxpacksize * (pack + u * nr_of_packs());
@@ -741,7 +742,7 @@ int usX2Y_hwdep_pcm_new(struct snd_card *card)
741 int err; 742 int err;
742 struct snd_hwdep *hw; 743 struct snd_hwdep *hw;
743 struct snd_pcm *pcm; 744 struct snd_pcm *pcm;
744 struct usb_device *dev = usX2Y(card)->chip.dev; 745 struct usb_device *dev = usX2Y(card)->dev;
745 if (1 != nr_of_packs()) 746 if (1 != nr_of_packs())
746 return 0; 747 return 0;
747 748