diff options
Diffstat (limited to 'sound/usb')
-rw-r--r-- | sound/usb/Kconfig | 12 | ||||
-rw-r--r-- | sound/usb/Makefile | 2 | ||||
-rw-r--r-- | sound/usb/ua101.c | 1421 | ||||
-rw-r--r-- | sound/usb/usbaudio.c | 256 | ||||
-rw-r--r-- | sound/usb/usbaudio.h | 16 | ||||
-rw-r--r-- | sound/usb/usbmixer.c | 75 | ||||
-rw-r--r-- | sound/usb/usbquirks.h | 145 |
7 files changed, 1756 insertions, 171 deletions
diff --git a/sound/usb/Kconfig b/sound/usb/Kconfig index 73525c048e7f..8c2925814ce4 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 | ||
24 | config SND_USB_UA101 | ||
25 | tristate "Edirol UA-101 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 audio/MIDI | ||
31 | interface. | ||
32 | |||
33 | To compile this driver as a module, choose M here: the module | ||
34 | will be called snd-ua101. | ||
35 | |||
24 | config SND_USB_USX2Y | 36 | config 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 | ||
5 | snd-usb-audio-objs := usbaudio.o usbmixer.o | 5 | snd-usb-audio-objs := usbaudio.o usbmixer.o |
6 | snd-usb-lib-objs := usbmidi.o | 6 | snd-usb-lib-objs := usbmidi.o |
7 | snd-ua101-objs := ua101.o | ||
7 | 8 | ||
8 | # Toplevel Module Dependency | 9 | # Toplevel Module Dependency |
9 | obj-$(CONFIG_SND_USB_AUDIO) += snd-usb-audio.o snd-usb-lib.o | 10 | obj-$(CONFIG_SND_USB_AUDIO) += snd-usb-audio.o snd-usb-lib.o |
11 | obj-$(CONFIG_SND_USB_UA101) += snd-ua101.o snd-usb-lib.o | ||
10 | obj-$(CONFIG_SND_USB_USX2Y) += snd-usb-lib.o | 12 | obj-$(CONFIG_SND_USB_USX2Y) += snd-usb-lib.o |
11 | obj-$(CONFIG_SND_USB_US122L) += snd-usb-lib.o | 13 | obj-$(CONFIG_SND_USB_US122L) += snd-usb-lib.o |
12 | 14 | ||
diff --git a/sound/usb/ua101.c b/sound/usb/ua101.c new file mode 100644 index 000000000000..4f4ccdf70dd0 --- /dev/null +++ b/sound/usb/ua101.c | |||
@@ -0,0 +1,1421 @@ | |||
1 | /* | ||
2 | * Edirol UA-101 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 | |||
28 | MODULE_DESCRIPTION("Edirol UA-101 driver"); | ||
29 | MODULE_AUTHOR("Clemens Ladisch <clemens@ladisch.de>"); | ||
30 | MODULE_LICENSE("GPL v2"); | ||
31 | MODULE_SUPPORTED_DEVICE("{{Edirol,UA-101}}"); | ||
32 | |||
33 | /* I use my UA-1A for testing because I don't have a UA-101 ... */ | ||
34 | #define UA1A_HACK | ||
35 | |||
36 | /* | ||
37 | * Should not be lower than the minimum scheduling delay of the host | ||
38 | * controller. Some Intel controllers need more than one frame; as long as | ||
39 | * that driver doesn't tell us about this, use 1.5 frames just to be sure. | ||
40 | */ | ||
41 | #define MIN_QUEUE_LENGTH 12 | ||
42 | /* Somewhat random. */ | ||
43 | #define MAX_QUEUE_LENGTH 30 | ||
44 | /* | ||
45 | * This magic value optimizes memory usage efficiency for the UA-101's packet | ||
46 | * sizes at all sample rates, taking into account the stupid cache pool sizes | ||
47 | * that usb_buffer_alloc() uses. | ||
48 | */ | ||
49 | #define DEFAULT_QUEUE_LENGTH 21 | ||
50 | |||
51 | #define MAX_PACKET_SIZE 672 /* hardware specific */ | ||
52 | #define MAX_MEMORY_BUFFERS DIV_ROUND_UP(MAX_QUEUE_LENGTH, \ | ||
53 | PAGE_SIZE / MAX_PACKET_SIZE) | ||
54 | |||
55 | static int index[SNDRV_CARDS] = SNDRV_DEFAULT_IDX; | ||
56 | static char *id[SNDRV_CARDS] = SNDRV_DEFAULT_STR; | ||
57 | static int enable[SNDRV_CARDS] = SNDRV_DEFAULT_ENABLE_PNP; | ||
58 | static unsigned int queue_length = 21; | ||
59 | |||
60 | module_param_array(index, int, NULL, 0444); | ||
61 | MODULE_PARM_DESC(index, "card index"); | ||
62 | module_param_array(id, charp, NULL, 0444); | ||
63 | MODULE_PARM_DESC(id, "ID string"); | ||
64 | module_param_array(enable, bool, NULL, 0444); | ||
65 | MODULE_PARM_DESC(enable, "enable card"); | ||
66 | module_param(queue_length, uint, 0644); | ||
67 | MODULE_PARM_DESC(queue_length, "USB queue length in microframes, " | ||
68 | __stringify(MIN_QUEUE_LENGTH)"-"__stringify(MAX_QUEUE_LENGTH)); | ||
69 | |||
70 | enum { | ||
71 | INTF_PLAYBACK, | ||
72 | INTF_CAPTURE, | ||
73 | INTF_MIDI, | ||
74 | |||
75 | INTF_COUNT | ||
76 | }; | ||
77 | |||
78 | /* bits in struct ua101::states */ | ||
79 | enum { | ||
80 | USB_CAPTURE_RUNNING, | ||
81 | USB_PLAYBACK_RUNNING, | ||
82 | ALSA_CAPTURE_OPEN, | ||
83 | ALSA_PLAYBACK_OPEN, | ||
84 | ALSA_CAPTURE_RUNNING, | ||
85 | ALSA_PLAYBACK_RUNNING, | ||
86 | CAPTURE_URB_COMPLETED, | ||
87 | PLAYBACK_URB_COMPLETED, | ||
88 | DISCONNECTED, | ||
89 | }; | ||
90 | |||
91 | struct ua101 { | ||
92 | struct usb_device *dev; | ||
93 | struct snd_card *card; | ||
94 | struct usb_interface *intf[INTF_COUNT]; | ||
95 | int card_index; | ||
96 | struct snd_pcm *pcm; | ||
97 | struct list_head midi_list; | ||
98 | u64 format_bit; | ||
99 | unsigned int rate; | ||
100 | unsigned int packets_per_second; | ||
101 | spinlock_t lock; | ||
102 | struct mutex mutex; | ||
103 | unsigned long states; | ||
104 | |||
105 | /* FIFO to synchronize playback rate to capture rate */ | ||
106 | unsigned int rate_feedback_start; | ||
107 | unsigned int rate_feedback_count; | ||
108 | u8 rate_feedback[MAX_QUEUE_LENGTH]; | ||
109 | |||
110 | struct list_head ready_playback_urbs; | ||
111 | struct tasklet_struct playback_tasklet; | ||
112 | wait_queue_head_t alsa_capture_wait; | ||
113 | wait_queue_head_t rate_feedback_wait; | ||
114 | wait_queue_head_t alsa_playback_wait; | ||
115 | struct ua101_stream { | ||
116 | struct snd_pcm_substream *substream; | ||
117 | unsigned int usb_pipe; | ||
118 | unsigned int channels; | ||
119 | unsigned int frame_bytes; | ||
120 | unsigned int max_packet_bytes; | ||
121 | unsigned int period_pos; | ||
122 | unsigned int buffer_pos; | ||
123 | unsigned int queue_length; | ||
124 | struct ua101_urb { | ||
125 | struct urb urb; | ||
126 | struct usb_iso_packet_descriptor iso_frame_desc[1]; | ||
127 | struct list_head ready_list; | ||
128 | } *urbs[MAX_QUEUE_LENGTH]; | ||
129 | struct { | ||
130 | unsigned int size; | ||
131 | void *addr; | ||
132 | dma_addr_t dma; | ||
133 | } buffers[MAX_MEMORY_BUFFERS]; | ||
134 | } capture, playback; | ||
135 | |||
136 | unsigned int fps[10]; | ||
137 | unsigned int frame_counter; | ||
138 | }; | ||
139 | |||
140 | static DEFINE_MUTEX(devices_mutex); | ||
141 | static unsigned int devices_used; | ||
142 | static struct usb_driver ua101_driver; | ||
143 | |||
144 | static void abort_alsa_playback(struct ua101 *ua); | ||
145 | static void abort_alsa_capture(struct ua101 *ua); | ||
146 | |||
147 | static const char *usb_error_string(int err) | ||
148 | { | ||
149 | switch (err) { | ||
150 | case -ENODEV: | ||
151 | return "no device"; | ||
152 | case -ENOENT: | ||
153 | return "endpoint not enabled"; | ||
154 | case -EPIPE: | ||
155 | return "endpoint stalled"; | ||
156 | case -ENOSPC: | ||
157 | return "not enough bandwidth"; | ||
158 | case -ESHUTDOWN: | ||
159 | return "device disabled"; | ||
160 | case -EHOSTUNREACH: | ||
161 | return "device suspended"; | ||
162 | case -EINVAL: | ||
163 | case -EAGAIN: | ||
164 | case -EFBIG: | ||
165 | case -EMSGSIZE: | ||
166 | return "internal error"; | ||
167 | default: | ||
168 | return "unknown error"; | ||
169 | } | ||
170 | } | ||
171 | |||
172 | static void abort_usb_capture(struct ua101 *ua) | ||
173 | { | ||
174 | if (test_and_clear_bit(USB_CAPTURE_RUNNING, &ua->states)) { | ||
175 | wake_up(&ua->alsa_capture_wait); | ||
176 | wake_up(&ua->rate_feedback_wait); | ||
177 | } | ||
178 | } | ||
179 | |||
180 | static void abort_usb_playback(struct ua101 *ua) | ||
181 | { | ||
182 | if (test_and_clear_bit(USB_PLAYBACK_RUNNING, &ua->states)) | ||
183 | wake_up(&ua->alsa_playback_wait); | ||
184 | } | ||
185 | |||
186 | static void playback_urb_complete(struct urb *usb_urb) | ||
187 | { | ||
188 | struct ua101_urb *urb = (struct ua101_urb *)usb_urb; | ||
189 | struct ua101 *ua = urb->urb.context; | ||
190 | unsigned long flags; | ||
191 | |||
192 | if (unlikely(urb->urb.status == -ENOENT || /* unlinked */ | ||
193 | urb->urb.status == -ENODEV || /* device removed */ | ||
194 | urb->urb.status == -ECONNRESET || /* unlinked */ | ||
195 | urb->urb.status == -ESHUTDOWN)) { /* device disabled */ | ||
196 | abort_usb_playback(ua); | ||
197 | abort_alsa_playback(ua); | ||
198 | return; | ||
199 | } | ||
200 | |||
201 | if (test_bit(USB_PLAYBACK_RUNNING, &ua->states)) { | ||
202 | /* append URB to FIFO */ | ||
203 | spin_lock_irqsave(&ua->lock, flags); | ||
204 | list_add_tail(&urb->ready_list, &ua->ready_playback_urbs); | ||
205 | if (ua->rate_feedback_count > 0) | ||
206 | tasklet_schedule(&ua->playback_tasklet); | ||
207 | ua->playback.substream->runtime->delay -= | ||
208 | urb->urb.iso_frame_desc[0].length / | ||
209 | ua->playback.frame_bytes; | ||
210 | spin_unlock_irqrestore(&ua->lock, flags); | ||
211 | } | ||
212 | } | ||
213 | |||
214 | static void first_playback_urb_complete(struct urb *urb) | ||
215 | { | ||
216 | struct ua101 *ua = urb->context; | ||
217 | |||
218 | urb->complete = playback_urb_complete; | ||
219 | playback_urb_complete(urb); | ||
220 | |||
221 | set_bit(PLAYBACK_URB_COMPLETED, &ua->states); | ||
222 | wake_up(&ua->alsa_playback_wait); | ||
223 | } | ||
224 | |||
225 | /* copy data from the ALSA ring buffer into the URB buffer */ | ||
226 | static bool copy_playback_data(struct ua101_stream *stream, struct urb *urb, | ||
227 | unsigned int frames) | ||
228 | { | ||
229 | struct snd_pcm_runtime *runtime; | ||
230 | unsigned int frame_bytes, frames1; | ||
231 | const u8 *source; | ||
232 | |||
233 | runtime = stream->substream->runtime; | ||
234 | frame_bytes = stream->frame_bytes; | ||
235 | source = runtime->dma_area + stream->buffer_pos * frame_bytes; | ||
236 | if (stream->buffer_pos + frames <= runtime->buffer_size) { | ||
237 | memcpy(urb->transfer_buffer, source, frames * frame_bytes); | ||
238 | } else { | ||
239 | /* wrap around at end of ring buffer */ | ||
240 | frames1 = runtime->buffer_size - stream->buffer_pos; | ||
241 | memcpy(urb->transfer_buffer, source, frames1 * frame_bytes); | ||
242 | memcpy(urb->transfer_buffer + frames1 * frame_bytes, | ||
243 | runtime->dma_area, (frames - frames1) * frame_bytes); | ||
244 | } | ||
245 | |||
246 | stream->buffer_pos += frames; | ||
247 | if (stream->buffer_pos >= runtime->buffer_size) | ||
248 | stream->buffer_pos -= runtime->buffer_size; | ||
249 | stream->period_pos += frames; | ||
250 | if (stream->period_pos >= runtime->period_size) { | ||
251 | stream->period_pos -= runtime->period_size; | ||
252 | return true; | ||
253 | } | ||
254 | return false; | ||
255 | } | ||
256 | |||
257 | static inline void add_with_wraparound(struct ua101 *ua, | ||
258 | unsigned int *value, unsigned int add) | ||
259 | { | ||
260 | *value += add; | ||
261 | if (*value >= ua->playback.queue_length) | ||
262 | *value -= ua->playback.queue_length; | ||
263 | } | ||
264 | |||
265 | static void playback_tasklet(unsigned long data) | ||
266 | { | ||
267 | struct ua101 *ua = (void *)data; | ||
268 | unsigned long flags; | ||
269 | unsigned int frames; | ||
270 | struct ua101_urb *urb; | ||
271 | bool do_period_elapsed = false; | ||
272 | int err; | ||
273 | |||
274 | if (unlikely(!test_bit(USB_PLAYBACK_RUNNING, &ua->states))) | ||
275 | return; | ||
276 | |||
277 | /* | ||
278 | * Synchronizing the playback rate to the capture rate is done by using | ||
279 | * the same sequence of packet sizes for both streams. | ||
280 | * Submitting a playback URB therefore requires both a ready URB and | ||
281 | * the size of the corresponding capture packet, i.e., both playback | ||
282 | * and capture URBs must have been completed. Since the USB core does | ||
283 | * not guarantee that playback and capture complete callbacks are | ||
284 | * called alternately, we use two FIFOs for packet sizes and read URBs; | ||
285 | * submitting playback URBs is possible as long as both FIFOs are | ||
286 | * nonempty. | ||
287 | */ | ||
288 | spin_lock_irqsave(&ua->lock, flags); | ||
289 | while (ua->rate_feedback_count > 0 && | ||
290 | !list_empty(&ua->ready_playback_urbs)) { | ||
291 | /* take packet size out of FIFO */ | ||
292 | frames = ua->rate_feedback[ua->rate_feedback_start]; | ||
293 | add_with_wraparound(ua, &ua->rate_feedback_start, 1); | ||
294 | ua->rate_feedback_count--; | ||
295 | |||
296 | /* take URB out of FIFO */ | ||
297 | urb = list_first_entry(&ua->ready_playback_urbs, | ||
298 | struct ua101_urb, ready_list); | ||
299 | list_del(&urb->ready_list); | ||
300 | |||
301 | /* fill packet with data or silence */ | ||
302 | urb->urb.iso_frame_desc[0].length = | ||
303 | frames * ua->playback.frame_bytes; | ||
304 | if (test_bit(ALSA_PLAYBACK_RUNNING, &ua->states)) | ||
305 | do_period_elapsed |= copy_playback_data(&ua->playback, | ||
306 | &urb->urb, | ||
307 | frames); | ||
308 | else | ||
309 | memset(urb->urb.transfer_buffer, 0, | ||
310 | urb->urb.iso_frame_desc[0].length); | ||
311 | |||
312 | /* and off you go ... */ | ||
313 | err = usb_submit_urb(&urb->urb, GFP_ATOMIC); | ||
314 | if (unlikely(err < 0)) { | ||
315 | spin_unlock_irqrestore(&ua->lock, flags); | ||
316 | abort_usb_playback(ua); | ||
317 | abort_alsa_playback(ua); | ||
318 | dev_err(&ua->dev->dev, "USB request error %d: %s\n", | ||
319 | err, usb_error_string(err)); | ||
320 | return; | ||
321 | } | ||
322 | ua->playback.substream->runtime->delay += frames; | ||
323 | } | ||
324 | spin_unlock_irqrestore(&ua->lock, flags); | ||
325 | if (do_period_elapsed) | ||
326 | snd_pcm_period_elapsed(ua->playback.substream); | ||
327 | } | ||
328 | |||
329 | /* copy data from the URB buffer into the ALSA ring buffer */ | ||
330 | static bool copy_capture_data(struct ua101_stream *stream, struct urb *urb, | ||
331 | unsigned int frames) | ||
332 | { | ||
333 | struct snd_pcm_runtime *runtime; | ||
334 | unsigned int frame_bytes, frames1; | ||
335 | u8 *dest; | ||
336 | |||
337 | runtime = stream->substream->runtime; | ||
338 | frame_bytes = stream->frame_bytes; | ||
339 | dest = runtime->dma_area + stream->buffer_pos * frame_bytes; | ||
340 | if (stream->buffer_pos + frames <= runtime->buffer_size) { | ||
341 | memcpy(dest, urb->transfer_buffer, frames * frame_bytes); | ||
342 | } else { | ||
343 | /* wrap around at end of ring buffer */ | ||
344 | frames1 = runtime->buffer_size - stream->buffer_pos; | ||
345 | memcpy(dest, urb->transfer_buffer, frames1 * frame_bytes); | ||
346 | memcpy(runtime->dma_area, | ||
347 | urb->transfer_buffer + frames1 * frame_bytes, | ||
348 | (frames - frames1) * frame_bytes); | ||
349 | } | ||
350 | |||
351 | stream->buffer_pos += frames; | ||
352 | if (stream->buffer_pos >= runtime->buffer_size) | ||
353 | stream->buffer_pos -= runtime->buffer_size; | ||
354 | stream->period_pos += frames; | ||
355 | if (stream->period_pos >= runtime->period_size) { | ||
356 | stream->period_pos -= runtime->period_size; | ||
357 | return true; | ||
358 | } | ||
359 | return false; | ||
360 | } | ||
361 | |||
362 | static void capture_urb_complete(struct urb *urb) | ||
363 | { | ||
364 | struct ua101 *ua = urb->context; | ||
365 | struct ua101_stream *stream = &ua->capture; | ||
366 | unsigned long flags; | ||
367 | unsigned int frames, write_ptr; | ||
368 | bool do_period_elapsed; | ||
369 | int err; | ||
370 | |||
371 | if (unlikely(urb->status == -ENOENT || /* unlinked */ | ||
372 | urb->status == -ENODEV || /* device removed */ | ||
373 | urb->status == -ECONNRESET || /* unlinked */ | ||
374 | urb->status == -ESHUTDOWN)) /* device disabled */ | ||
375 | goto stream_stopped; | ||
376 | |||
377 | if (urb->status >= 0 && urb->iso_frame_desc[0].status >= 0) | ||
378 | frames = urb->iso_frame_desc[0].actual_length / | ||
379 | stream->frame_bytes; | ||
380 | else | ||
381 | frames = 0; | ||
382 | |||
383 | spin_lock_irqsave(&ua->lock, flags); | ||
384 | |||
385 | if (frames > 0 && test_bit(ALSA_CAPTURE_RUNNING, &ua->states)) | ||
386 | do_period_elapsed = copy_capture_data(stream, urb, frames); | ||
387 | else | ||
388 | do_period_elapsed = false; | ||
389 | |||
390 | if (test_bit(USB_CAPTURE_RUNNING, &ua->states)) { | ||
391 | err = usb_submit_urb(urb, GFP_ATOMIC); | ||
392 | if (unlikely(err < 0)) { | ||
393 | spin_unlock_irqrestore(&ua->lock, flags); | ||
394 | dev_err(&ua->dev->dev, "USB request error %d: %s\n", | ||
395 | err, usb_error_string(err)); | ||
396 | goto stream_stopped; | ||
397 | } | ||
398 | |||
399 | /* append packet size to FIFO */ | ||
400 | write_ptr = ua->rate_feedback_start; | ||
401 | add_with_wraparound(ua, &write_ptr, ua->rate_feedback_count); | ||
402 | ua->rate_feedback[write_ptr] = frames; | ||
403 | if (ua->rate_feedback_count < ua->playback.queue_length) { | ||
404 | ua->rate_feedback_count++; | ||
405 | if (ua->rate_feedback_count == | ||
406 | ua->playback.queue_length) | ||
407 | wake_up(&ua->rate_feedback_wait); | ||
408 | } else { | ||
409 | /* | ||
410 | * Ring buffer overflow; this happens when the playback | ||
411 | * stream is not running. Throw away the oldest entry, | ||
412 | * so that the playback stream, when it starts, sees | ||
413 | * the most recent packet sizes. | ||
414 | */ | ||
415 | add_with_wraparound(ua, &ua->rate_feedback_start, 1); | ||
416 | } | ||
417 | if (test_bit(USB_PLAYBACK_RUNNING, &ua->states) && | ||
418 | !list_empty(&ua->ready_playback_urbs)) | ||
419 | tasklet_schedule(&ua->playback_tasklet); | ||
420 | } | ||
421 | |||
422 | spin_unlock_irqrestore(&ua->lock, flags); | ||
423 | |||
424 | if (do_period_elapsed) | ||
425 | snd_pcm_period_elapsed(stream->substream); | ||
426 | |||
427 | /* for debugging: measure the sample rate relative to the USB clock */ | ||
428 | ua->fps[ua->frame_counter++ / ua->packets_per_second] += frames; | ||
429 | if (ua->frame_counter >= ARRAY_SIZE(ua->fps) * ua->packets_per_second) { | ||
430 | printk(KERN_DEBUG "capture rate:"); | ||
431 | for (frames = 0; frames < ARRAY_SIZE(ua->fps); ++frames) | ||
432 | printk(KERN_CONT " %u", ua->fps[frames]); | ||
433 | printk(KERN_CONT "\n"); | ||
434 | memset(ua->fps, 0, sizeof(ua->fps)); | ||
435 | ua->frame_counter = 0; | ||
436 | } | ||
437 | return; | ||
438 | |||
439 | stream_stopped: | ||
440 | abort_usb_playback(ua); | ||
441 | abort_usb_capture(ua); | ||
442 | abort_alsa_playback(ua); | ||
443 | abort_alsa_capture(ua); | ||
444 | } | ||
445 | |||
446 | static void first_capture_urb_complete(struct urb *urb) | ||
447 | { | ||
448 | struct ua101 *ua = urb->context; | ||
449 | |||
450 | urb->complete = capture_urb_complete; | ||
451 | capture_urb_complete(urb); | ||
452 | |||
453 | set_bit(CAPTURE_URB_COMPLETED, &ua->states); | ||
454 | wake_up(&ua->alsa_capture_wait); | ||
455 | } | ||
456 | |||
457 | static int submit_stream_urbs(struct ua101 *ua, struct ua101_stream *stream) | ||
458 | { | ||
459 | unsigned int i; | ||
460 | |||
461 | for (i = 0; i < stream->queue_length; ++i) { | ||
462 | int err = usb_submit_urb(&stream->urbs[i]->urb, GFP_KERNEL); | ||
463 | if (err < 0) { | ||
464 | dev_err(&ua->dev->dev, "USB request error %d: %s\n", | ||
465 | err, usb_error_string(err)); | ||
466 | return err; | ||
467 | } | ||
468 | } | ||
469 | return 0; | ||
470 | } | ||
471 | |||
472 | static void kill_stream_urbs(struct ua101_stream *stream) | ||
473 | { | ||
474 | unsigned int i; | ||
475 | |||
476 | for (i = 0; i < stream->queue_length; ++i) | ||
477 | usb_kill_urb(&stream->urbs[i]->urb); | ||
478 | } | ||
479 | |||
480 | static int enable_iso_interface(struct ua101 *ua, unsigned int intf_index) | ||
481 | { | ||
482 | struct usb_host_interface *alts; | ||
483 | |||
484 | alts = ua->intf[intf_index]->cur_altsetting; | ||
485 | if (alts->desc.bAlternateSetting != 1) { | ||
486 | int err = usb_set_interface(ua->dev, | ||
487 | alts->desc.bInterfaceNumber, 1); | ||
488 | if (err < 0) { | ||
489 | dev_err(&ua->dev->dev, | ||
490 | "cannot initialize interface; error %d: %s\n", | ||
491 | err, usb_error_string(err)); | ||
492 | return err; | ||
493 | } | ||
494 | } | ||
495 | return 0; | ||
496 | } | ||
497 | |||
498 | static void disable_iso_interface(struct ua101 *ua, unsigned int intf_index) | ||
499 | { | ||
500 | struct usb_host_interface *alts; | ||
501 | |||
502 | alts = ua->intf[intf_index]->cur_altsetting; | ||
503 | if (alts->desc.bAlternateSetting != 0) { | ||
504 | int err = usb_set_interface(ua->dev, | ||
505 | alts->desc.bInterfaceNumber, 0); | ||
506 | if (err < 0 && !test_bit(DISCONNECTED, &ua->states)) | ||
507 | dev_warn(&ua->dev->dev, | ||
508 | "interface reset failed; error %d: %s\n", | ||
509 | err, usb_error_string(err)); | ||
510 | } | ||
511 | } | ||
512 | |||
513 | static void stop_usb_capture(struct ua101 *ua) | ||
514 | { | ||
515 | clear_bit(USB_CAPTURE_RUNNING, &ua->states); | ||
516 | |||
517 | kill_stream_urbs(&ua->capture); | ||
518 | |||
519 | disable_iso_interface(ua, INTF_CAPTURE); | ||
520 | } | ||
521 | |||
522 | static int start_usb_capture(struct ua101 *ua) | ||
523 | { | ||
524 | int err; | ||
525 | |||
526 | if (test_bit(DISCONNECTED, &ua->states)) | ||
527 | return -ENODEV; | ||
528 | |||
529 | if (test_bit(USB_CAPTURE_RUNNING, &ua->states)) | ||
530 | return 0; | ||
531 | |||
532 | kill_stream_urbs(&ua->capture); | ||
533 | |||
534 | err = enable_iso_interface(ua, INTF_CAPTURE); | ||
535 | if (err < 0) | ||
536 | return err; | ||
537 | |||
538 | clear_bit(CAPTURE_URB_COMPLETED, &ua->states); | ||
539 | ua->capture.urbs[0]->urb.complete = first_capture_urb_complete; | ||
540 | ua->rate_feedback_start = 0; | ||
541 | ua->rate_feedback_count = 0; | ||
542 | |||
543 | set_bit(USB_CAPTURE_RUNNING, &ua->states); | ||
544 | err = submit_stream_urbs(ua, &ua->capture); | ||
545 | if (err < 0) | ||
546 | stop_usb_capture(ua); | ||
547 | return err; | ||
548 | } | ||
549 | |||
550 | static void stop_usb_playback(struct ua101 *ua) | ||
551 | { | ||
552 | clear_bit(USB_PLAYBACK_RUNNING, &ua->states); | ||
553 | |||
554 | kill_stream_urbs(&ua->playback); | ||
555 | |||
556 | tasklet_kill(&ua->playback_tasklet); | ||
557 | |||
558 | disable_iso_interface(ua, INTF_PLAYBACK); | ||
559 | } | ||
560 | |||
561 | static int start_usb_playback(struct ua101 *ua) | ||
562 | { | ||
563 | unsigned int i, frames; | ||
564 | struct urb *urb; | ||
565 | int err = 0; | ||
566 | |||
567 | if (test_bit(DISCONNECTED, &ua->states)) | ||
568 | return -ENODEV; | ||
569 | |||
570 | if (test_bit(USB_PLAYBACK_RUNNING, &ua->states)) | ||
571 | return 0; | ||
572 | |||
573 | kill_stream_urbs(&ua->playback); | ||
574 | tasklet_kill(&ua->playback_tasklet); | ||
575 | |||
576 | err = enable_iso_interface(ua, INTF_PLAYBACK); | ||
577 | if (err < 0) | ||
578 | return err; | ||
579 | |||
580 | clear_bit(PLAYBACK_URB_COMPLETED, &ua->states); | ||
581 | ua->playback.urbs[0]->urb.complete = | ||
582 | first_playback_urb_complete; | ||
583 | spin_lock_irq(&ua->lock); | ||
584 | INIT_LIST_HEAD(&ua->ready_playback_urbs); | ||
585 | spin_unlock_irq(&ua->lock); | ||
586 | |||
587 | /* | ||
588 | * We submit the initial URBs all at once, so we have to wait for the | ||
589 | * packet size FIFO to be full. | ||
590 | */ | ||
591 | wait_event(ua->rate_feedback_wait, | ||
592 | ua->rate_feedback_count >= ua->playback.queue_length || | ||
593 | !test_bit(USB_CAPTURE_RUNNING, &ua->states) || | ||
594 | test_bit(DISCONNECTED, &ua->states)); | ||
595 | if (test_bit(DISCONNECTED, &ua->states)) { | ||
596 | stop_usb_playback(ua); | ||
597 | return -ENODEV; | ||
598 | } | ||
599 | if (!test_bit(USB_CAPTURE_RUNNING, &ua->states)) { | ||
600 | stop_usb_playback(ua); | ||
601 | return -EIO; | ||
602 | } | ||
603 | |||
604 | for (i = 0; i < ua->playback.queue_length; ++i) { | ||
605 | /* all initial URBs contain silence */ | ||
606 | spin_lock_irq(&ua->lock); | ||
607 | frames = ua->rate_feedback[ua->rate_feedback_start]; | ||
608 | add_with_wraparound(ua, &ua->rate_feedback_start, 1); | ||
609 | ua->rate_feedback_count--; | ||
610 | spin_unlock_irq(&ua->lock); | ||
611 | urb = &ua->playback.urbs[i]->urb; | ||
612 | urb->iso_frame_desc[0].length = | ||
613 | frames * ua->playback.frame_bytes; | ||
614 | memset(urb->transfer_buffer, 0, | ||
615 | urb->iso_frame_desc[0].length); | ||
616 | } | ||
617 | |||
618 | set_bit(USB_PLAYBACK_RUNNING, &ua->states); | ||
619 | err = submit_stream_urbs(ua, &ua->playback); | ||
620 | if (err < 0) | ||
621 | stop_usb_playback(ua); | ||
622 | return err; | ||
623 | } | ||
624 | |||
625 | static void abort_alsa_capture(struct ua101 *ua) | ||
626 | { | ||
627 | if (test_bit(ALSA_CAPTURE_RUNNING, &ua->states)) | ||
628 | snd_pcm_stop(ua->capture.substream, SNDRV_PCM_STATE_XRUN); | ||
629 | } | ||
630 | |||
631 | static void abort_alsa_playback(struct ua101 *ua) | ||
632 | { | ||
633 | if (test_bit(ALSA_PLAYBACK_RUNNING, &ua->states)) | ||
634 | snd_pcm_stop(ua->playback.substream, SNDRV_PCM_STATE_XRUN); | ||
635 | } | ||
636 | |||
637 | static int set_stream_hw(struct ua101 *ua, struct snd_pcm_substream *substream, | ||
638 | unsigned int channels) | ||
639 | { | ||
640 | int err; | ||
641 | |||
642 | substream->runtime->hw.info = | ||
643 | SNDRV_PCM_INFO_MMAP | | ||
644 | SNDRV_PCM_INFO_MMAP_VALID | | ||
645 | SNDRV_PCM_INFO_BATCH | | ||
646 | SNDRV_PCM_INFO_INTERLEAVED | | ||
647 | SNDRV_PCM_INFO_BLOCK_TRANSFER | | ||
648 | SNDRV_PCM_INFO_FIFO_IN_FRAMES; | ||
649 | substream->runtime->hw.formats = ua->format_bit; | ||
650 | substream->runtime->hw.rates = snd_pcm_rate_to_rate_bit(ua->rate); | ||
651 | substream->runtime->hw.rate_min = ua->rate; | ||
652 | substream->runtime->hw.rate_max = ua->rate; | ||
653 | substream->runtime->hw.channels_min = channels; | ||
654 | substream->runtime->hw.channels_max = channels; | ||
655 | substream->runtime->hw.buffer_bytes_max = 45000 * 1024; | ||
656 | substream->runtime->hw.period_bytes_min = 1; | ||
657 | substream->runtime->hw.period_bytes_max = UINT_MAX; | ||
658 | substream->runtime->hw.periods_min = 2; | ||
659 | substream->runtime->hw.periods_max = UINT_MAX; | ||
660 | err = snd_pcm_hw_constraint_minmax(substream->runtime, | ||
661 | SNDRV_PCM_HW_PARAM_PERIOD_TIME, | ||
662 | 1500000 / ua->packets_per_second, | ||
663 | 8192000); | ||
664 | if (err < 0) | ||
665 | return err; | ||
666 | err = snd_pcm_hw_constraint_msbits(substream->runtime, 0, 32, 24); | ||
667 | return err; | ||
668 | } | ||
669 | |||
670 | static int capture_pcm_open(struct snd_pcm_substream *substream) | ||
671 | { | ||
672 | struct ua101 *ua = substream->private_data; | ||
673 | int err; | ||
674 | |||
675 | ua->capture.substream = substream; | ||
676 | err = set_stream_hw(ua, substream, ua->capture.channels); | ||
677 | if (err < 0) | ||
678 | return err; | ||
679 | substream->runtime->hw.fifo_size = | ||
680 | DIV_ROUND_CLOSEST(ua->rate, ua->packets_per_second); | ||
681 | substream->runtime->delay = substream->runtime->hw.fifo_size; | ||
682 | |||
683 | mutex_lock(&ua->mutex); | ||
684 | err = start_usb_capture(ua); | ||
685 | if (err >= 0) | ||
686 | set_bit(ALSA_CAPTURE_OPEN, &ua->states); | ||
687 | mutex_unlock(&ua->mutex); | ||
688 | return err; | ||
689 | } | ||
690 | |||
691 | static int playback_pcm_open(struct snd_pcm_substream *substream) | ||
692 | { | ||
693 | struct ua101 *ua = substream->private_data; | ||
694 | int err; | ||
695 | |||
696 | ua->playback.substream = substream; | ||
697 | err = set_stream_hw(ua, substream, ua->playback.channels); | ||
698 | if (err < 0) | ||
699 | return err; | ||
700 | substream->runtime->hw.fifo_size = | ||
701 | DIV_ROUND_CLOSEST(ua->rate * ua->playback.queue_length, | ||
702 | ua->packets_per_second); | ||
703 | |||
704 | mutex_lock(&ua->mutex); | ||
705 | err = start_usb_capture(ua); | ||
706 | if (err < 0) | ||
707 | goto error; | ||
708 | err = start_usb_playback(ua); | ||
709 | if (err < 0) { | ||
710 | if (!test_bit(ALSA_CAPTURE_OPEN, &ua->states)) | ||
711 | stop_usb_capture(ua); | ||
712 | goto error; | ||
713 | } | ||
714 | set_bit(ALSA_PLAYBACK_OPEN, &ua->states); | ||
715 | error: | ||
716 | mutex_unlock(&ua->mutex); | ||
717 | return err; | ||
718 | } | ||
719 | |||
720 | static int capture_pcm_close(struct snd_pcm_substream *substream) | ||
721 | { | ||
722 | struct ua101 *ua = substream->private_data; | ||
723 | |||
724 | mutex_lock(&ua->mutex); | ||
725 | clear_bit(ALSA_CAPTURE_OPEN, &ua->states); | ||
726 | if (!test_bit(ALSA_PLAYBACK_OPEN, &ua->states)) | ||
727 | stop_usb_capture(ua); | ||
728 | mutex_unlock(&ua->mutex); | ||
729 | return 0; | ||
730 | } | ||
731 | |||
732 | static int playback_pcm_close(struct snd_pcm_substream *substream) | ||
733 | { | ||
734 | struct ua101 *ua = substream->private_data; | ||
735 | |||
736 | mutex_lock(&ua->mutex); | ||
737 | stop_usb_playback(ua); | ||
738 | clear_bit(ALSA_PLAYBACK_OPEN, &ua->states); | ||
739 | if (!test_bit(ALSA_CAPTURE_OPEN, &ua->states)) | ||
740 | stop_usb_capture(ua); | ||
741 | mutex_unlock(&ua->mutex); | ||
742 | return 0; | ||
743 | } | ||
744 | |||
745 | static int capture_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 | mutex_unlock(&ua->mutex); | ||
754 | if (err < 0) | ||
755 | return err; | ||
756 | |||
757 | return snd_pcm_lib_alloc_vmalloc_buffer(substream, | ||
758 | params_buffer_bytes(hw_params)); | ||
759 | } | ||
760 | |||
761 | static int playback_pcm_hw_params(struct snd_pcm_substream *substream, | ||
762 | struct snd_pcm_hw_params *hw_params) | ||
763 | { | ||
764 | struct ua101 *ua = substream->private_data; | ||
765 | int err; | ||
766 | |||
767 | mutex_lock(&ua->mutex); | ||
768 | err = start_usb_capture(ua); | ||
769 | if (err >= 0) | ||
770 | err = start_usb_playback(ua); | ||
771 | mutex_unlock(&ua->mutex); | ||
772 | if (err < 0) | ||
773 | return err; | ||
774 | |||
775 | return snd_pcm_lib_alloc_vmalloc_buffer(substream, | ||
776 | params_buffer_bytes(hw_params)); | ||
777 | } | ||
778 | |||
779 | static int ua101_pcm_hw_free(struct snd_pcm_substream *substream) | ||
780 | { | ||
781 | return snd_pcm_lib_free_vmalloc_buffer(substream); | ||
782 | } | ||
783 | |||
784 | static int capture_pcm_prepare(struct snd_pcm_substream *substream) | ||
785 | { | ||
786 | struct ua101 *ua = substream->private_data; | ||
787 | int err; | ||
788 | |||
789 | mutex_lock(&ua->mutex); | ||
790 | err = start_usb_capture(ua); | ||
791 | mutex_unlock(&ua->mutex); | ||
792 | if (err < 0) | ||
793 | return err; | ||
794 | |||
795 | /* | ||
796 | * The EHCI driver schedules the first packet of an iso stream at 10 ms | ||
797 | * in the future, i.e., no data is actually captured for that long. | ||
798 | * Take the wait here so that the stream is known to be actually | ||
799 | * running when the start trigger has been called. | ||
800 | */ | ||
801 | wait_event(ua->alsa_capture_wait, | ||
802 | test_bit(CAPTURE_URB_COMPLETED, &ua->states) || | ||
803 | !test_bit(USB_CAPTURE_RUNNING, &ua->states)); | ||
804 | if (test_bit(DISCONNECTED, &ua->states)) | ||
805 | return -ENODEV; | ||
806 | if (!test_bit(USB_CAPTURE_RUNNING, &ua->states)) | ||
807 | return -EIO; | ||
808 | |||
809 | ua->capture.period_pos = 0; | ||
810 | ua->capture.buffer_pos = 0; | ||
811 | return 0; | ||
812 | } | ||
813 | |||
814 | static int playback_pcm_prepare(struct snd_pcm_substream *substream) | ||
815 | { | ||
816 | struct ua101 *ua = substream->private_data; | ||
817 | int err; | ||
818 | |||
819 | mutex_lock(&ua->mutex); | ||
820 | err = start_usb_capture(ua); | ||
821 | if (err >= 0) | ||
822 | err = start_usb_playback(ua); | ||
823 | mutex_unlock(&ua->mutex); | ||
824 | if (err < 0) | ||
825 | return err; | ||
826 | |||
827 | /* see the comment in capture_pcm_prepare() */ | ||
828 | wait_event(ua->alsa_playback_wait, | ||
829 | test_bit(PLAYBACK_URB_COMPLETED, &ua->states) || | ||
830 | !test_bit(USB_PLAYBACK_RUNNING, &ua->states)); | ||
831 | if (test_bit(DISCONNECTED, &ua->states)) | ||
832 | return -ENODEV; | ||
833 | if (!test_bit(USB_PLAYBACK_RUNNING, &ua->states)) | ||
834 | return -EIO; | ||
835 | |||
836 | substream->runtime->delay = 0; | ||
837 | ua->playback.period_pos = 0; | ||
838 | ua->playback.buffer_pos = 0; | ||
839 | return 0; | ||
840 | } | ||
841 | |||
842 | static int capture_pcm_trigger(struct snd_pcm_substream *substream, int cmd) | ||
843 | { | ||
844 | struct ua101 *ua = substream->private_data; | ||
845 | |||
846 | switch (cmd) { | ||
847 | case SNDRV_PCM_TRIGGER_START: | ||
848 | if (!test_bit(USB_CAPTURE_RUNNING, &ua->states)) | ||
849 | return -EIO; | ||
850 | set_bit(ALSA_CAPTURE_RUNNING, &ua->states); | ||
851 | return 0; | ||
852 | case SNDRV_PCM_TRIGGER_STOP: | ||
853 | clear_bit(ALSA_CAPTURE_RUNNING, &ua->states); | ||
854 | return 0; | ||
855 | default: | ||
856 | return -EINVAL; | ||
857 | } | ||
858 | } | ||
859 | |||
860 | static int playback_pcm_trigger(struct snd_pcm_substream *substream, int cmd) | ||
861 | { | ||
862 | struct ua101 *ua = substream->private_data; | ||
863 | |||
864 | switch (cmd) { | ||
865 | case SNDRV_PCM_TRIGGER_START: | ||
866 | if (!test_bit(USB_PLAYBACK_RUNNING, &ua->states)) | ||
867 | return -EIO; | ||
868 | set_bit(ALSA_PLAYBACK_RUNNING, &ua->states); | ||
869 | return 0; | ||
870 | case SNDRV_PCM_TRIGGER_STOP: | ||
871 | clear_bit(ALSA_PLAYBACK_RUNNING, &ua->states); | ||
872 | return 0; | ||
873 | default: | ||
874 | return -EINVAL; | ||
875 | } | ||
876 | } | ||
877 | |||
878 | static inline snd_pcm_uframes_t ua101_pcm_pointer(struct ua101 *ua, | ||
879 | struct ua101_stream *stream) | ||
880 | { | ||
881 | unsigned long flags; | ||
882 | unsigned int pos; | ||
883 | |||
884 | spin_lock_irqsave(&ua->lock, flags); | ||
885 | pos = stream->buffer_pos; | ||
886 | spin_unlock_irqrestore(&ua->lock, flags); | ||
887 | return pos; | ||
888 | } | ||
889 | |||
890 | static snd_pcm_uframes_t capture_pcm_pointer(struct snd_pcm_substream *subs) | ||
891 | { | ||
892 | struct ua101 *ua = subs->private_data; | ||
893 | |||
894 | return ua101_pcm_pointer(ua, &ua->capture); | ||
895 | } | ||
896 | |||
897 | static snd_pcm_uframes_t playback_pcm_pointer(struct snd_pcm_substream *subs) | ||
898 | { | ||
899 | struct ua101 *ua = subs->private_data; | ||
900 | |||
901 | return ua101_pcm_pointer(ua, &ua->playback); | ||
902 | } | ||
903 | |||
904 | static struct snd_pcm_ops capture_pcm_ops = { | ||
905 | .open = capture_pcm_open, | ||
906 | .close = capture_pcm_close, | ||
907 | .ioctl = snd_pcm_lib_ioctl, | ||
908 | .hw_params = capture_pcm_hw_params, | ||
909 | .hw_free = ua101_pcm_hw_free, | ||
910 | .prepare = capture_pcm_prepare, | ||
911 | .trigger = capture_pcm_trigger, | ||
912 | .pointer = capture_pcm_pointer, | ||
913 | .page = snd_pcm_lib_get_vmalloc_page, | ||
914 | .mmap = snd_pcm_lib_mmap_vmalloc, | ||
915 | }; | ||
916 | |||
917 | static struct snd_pcm_ops playback_pcm_ops = { | ||
918 | .open = playback_pcm_open, | ||
919 | .close = playback_pcm_close, | ||
920 | .ioctl = snd_pcm_lib_ioctl, | ||
921 | .hw_params = playback_pcm_hw_params, | ||
922 | .hw_free = ua101_pcm_hw_free, | ||
923 | .prepare = playback_pcm_prepare, | ||
924 | .trigger = playback_pcm_trigger, | ||
925 | .pointer = playback_pcm_pointer, | ||
926 | .page = snd_pcm_lib_get_vmalloc_page, | ||
927 | .mmap = snd_pcm_lib_mmap_vmalloc, | ||
928 | }; | ||
929 | |||
930 | static const struct uac_format_type_i_discrete_descriptor * | ||
931 | find_format_descriptor(struct usb_interface *interface) | ||
932 | { | ||
933 | struct usb_host_interface *alt; | ||
934 | u8 *extra; | ||
935 | int extralen; | ||
936 | |||
937 | if (interface->num_altsetting != 2) { | ||
938 | dev_err(&interface->dev, "invalid num_altsetting\n"); | ||
939 | return NULL; | ||
940 | } | ||
941 | |||
942 | alt = &interface->altsetting[0]; | ||
943 | if (alt->desc.bNumEndpoints != 0) { | ||
944 | dev_err(&interface->dev, "invalid bNumEndpoints\n"); | ||
945 | return NULL; | ||
946 | } | ||
947 | |||
948 | alt = &interface->altsetting[1]; | ||
949 | if (alt->desc.bNumEndpoints != 1) { | ||
950 | dev_err(&interface->dev, "invalid bNumEndpoints\n"); | ||
951 | return NULL; | ||
952 | } | ||
953 | |||
954 | extra = alt->extra; | ||
955 | extralen = alt->extralen; | ||
956 | while (extralen >= sizeof(struct usb_descriptor_header)) { | ||
957 | struct uac_format_type_i_discrete_descriptor *desc; | ||
958 | |||
959 | desc = (struct uac_format_type_i_discrete_descriptor *)extra; | ||
960 | if (desc->bLength > extralen) { | ||
961 | dev_err(&interface->dev, "descriptor overflow\n"); | ||
962 | return NULL; | ||
963 | } | ||
964 | if (desc->bLength == UAC_FORMAT_TYPE_I_DISCRETE_DESC_SIZE(1) && | ||
965 | desc->bDescriptorType == USB_DT_CS_INTERFACE && | ||
966 | desc->bDescriptorSubtype == UAC_FORMAT_TYPE) { | ||
967 | if (desc->bFormatType != UAC_FORMAT_TYPE_I_PCM || | ||
968 | desc->bSamFreqType != 1) { | ||
969 | dev_err(&interface->dev, | ||
970 | "invalid format type\n"); | ||
971 | return NULL; | ||
972 | } | ||
973 | return desc; | ||
974 | } | ||
975 | extralen -= desc->bLength; | ||
976 | extra += desc->bLength; | ||
977 | } | ||
978 | dev_err(&interface->dev, "sample format descriptor not found\n"); | ||
979 | return NULL; | ||
980 | } | ||
981 | |||
982 | static int detect_usb_format(struct ua101 *ua) | ||
983 | { | ||
984 | const struct uac_format_type_i_discrete_descriptor *fmt_capture; | ||
985 | const struct uac_format_type_i_discrete_descriptor *fmt_playback; | ||
986 | const struct usb_endpoint_descriptor *epd; | ||
987 | unsigned int rate2; | ||
988 | |||
989 | fmt_capture = find_format_descriptor(ua->intf[INTF_CAPTURE]); | ||
990 | fmt_playback = find_format_descriptor(ua->intf[INTF_PLAYBACK]); | ||
991 | if (!fmt_capture || !fmt_playback) | ||
992 | return -ENXIO; | ||
993 | |||
994 | switch (fmt_capture->bSubframeSize) { | ||
995 | case 3: | ||
996 | ua->format_bit = SNDRV_PCM_FMTBIT_S24_3LE; | ||
997 | break; | ||
998 | case 4: | ||
999 | ua->format_bit = SNDRV_PCM_FMTBIT_S32_LE; | ||
1000 | break; | ||
1001 | default: | ||
1002 | dev_err(&ua->dev->dev, "sample width is not 24 or 32 bits\n"); | ||
1003 | return -ENXIO; | ||
1004 | } | ||
1005 | if (fmt_capture->bSubframeSize != fmt_playback->bSubframeSize) { | ||
1006 | dev_err(&ua->dev->dev, | ||
1007 | "playback/capture sample widths do not match\n"); | ||
1008 | return -ENXIO; | ||
1009 | } | ||
1010 | |||
1011 | if (fmt_capture->bBitResolution != 24 || | ||
1012 | fmt_playback->bBitResolution != 24) { | ||
1013 | dev_err(&ua->dev->dev, "sample width is not 24 bits\n"); | ||
1014 | return -ENXIO; | ||
1015 | } | ||
1016 | |||
1017 | ua->rate = combine_triple(fmt_capture->tSamFreq[0]); | ||
1018 | rate2 = combine_triple(fmt_playback->tSamFreq[0]); | ||
1019 | if (ua->rate != rate2) { | ||
1020 | dev_err(&ua->dev->dev, | ||
1021 | "playback/capture rates do not match: %u/%u\n", | ||
1022 | rate2, ua->rate); | ||
1023 | return -ENXIO; | ||
1024 | } | ||
1025 | |||
1026 | switch (ua->dev->speed) { | ||
1027 | case USB_SPEED_FULL: | ||
1028 | ua->packets_per_second = 1000; | ||
1029 | break; | ||
1030 | case USB_SPEED_HIGH: | ||
1031 | ua->packets_per_second = 8000; | ||
1032 | break; | ||
1033 | default: | ||
1034 | dev_err(&ua->dev->dev, "unknown device speed\n"); | ||
1035 | return -ENXIO; | ||
1036 | } | ||
1037 | |||
1038 | ua->capture.channels = fmt_capture->bNrChannels; | ||
1039 | ua->playback.channels = fmt_playback->bNrChannels; | ||
1040 | ua->capture.frame_bytes = | ||
1041 | fmt_capture->bSubframeSize * ua->capture.channels; | ||
1042 | ua->playback.frame_bytes = | ||
1043 | fmt_playback->bSubframeSize * ua->playback.channels; | ||
1044 | |||
1045 | epd = &ua->intf[INTF_CAPTURE]->altsetting[1].endpoint[0].desc; | ||
1046 | if (!usb_endpoint_is_isoc_in(epd)) { | ||
1047 | dev_err(&ua->dev->dev, "invalid capture endpoint\n"); | ||
1048 | return -ENXIO; | ||
1049 | } | ||
1050 | ua->capture.usb_pipe = usb_rcvisocpipe(ua->dev, usb_endpoint_num(epd)); | ||
1051 | ua->capture.max_packet_bytes = le16_to_cpu(epd->wMaxPacketSize); | ||
1052 | |||
1053 | epd = &ua->intf[INTF_PLAYBACK]->altsetting[1].endpoint[0].desc; | ||
1054 | if (!usb_endpoint_is_isoc_out(epd)) { | ||
1055 | dev_err(&ua->dev->dev, "invalid playback endpoint\n"); | ||
1056 | return -ENXIO; | ||
1057 | } | ||
1058 | ua->playback.usb_pipe = usb_sndisocpipe(ua->dev, usb_endpoint_num(epd)); | ||
1059 | ua->playback.max_packet_bytes = le16_to_cpu(epd->wMaxPacketSize); | ||
1060 | return 0; | ||
1061 | } | ||
1062 | |||
1063 | static int alloc_stream_buffers(struct ua101 *ua, struct ua101_stream *stream) | ||
1064 | { | ||
1065 | unsigned int remaining_packets, packets, packets_per_page, i; | ||
1066 | size_t size; | ||
1067 | |||
1068 | stream->queue_length = queue_length; | ||
1069 | stream->queue_length = max(stream->queue_length, | ||
1070 | (unsigned int)MIN_QUEUE_LENGTH); | ||
1071 | stream->queue_length = min(stream->queue_length, | ||
1072 | (unsigned int)MAX_QUEUE_LENGTH); | ||
1073 | |||
1074 | /* | ||
1075 | * The cache pool sizes used by usb_buffer_alloc() (128, 512, 2048) are | ||
1076 | * quite bad when used with the packet sizes of this device (e.g. 280, | ||
1077 | * 520, 624). Therefore, we allocate and subdivide entire pages, using | ||
1078 | * a smaller buffer only for the last chunk. | ||
1079 | */ | ||
1080 | remaining_packets = stream->queue_length; | ||
1081 | packets_per_page = PAGE_SIZE / stream->max_packet_bytes; | ||
1082 | for (i = 0; i < ARRAY_SIZE(stream->buffers); ++i) { | ||
1083 | packets = min(remaining_packets, packets_per_page); | ||
1084 | size = packets * stream->max_packet_bytes; | ||
1085 | stream->buffers[i].addr = | ||
1086 | usb_buffer_alloc(ua->dev, size, GFP_KERNEL, | ||
1087 | &stream->buffers[i].dma); | ||
1088 | if (!stream->buffers[i].addr) | ||
1089 | return -ENOMEM; | ||
1090 | stream->buffers[i].size = size; | ||
1091 | remaining_packets -= packets; | ||
1092 | if (!remaining_packets) | ||
1093 | break; | ||
1094 | } | ||
1095 | if (remaining_packets) { | ||
1096 | dev_err(&ua->dev->dev, "too many packets\n"); | ||
1097 | return -ENXIO; | ||
1098 | } | ||
1099 | return 0; | ||
1100 | } | ||
1101 | |||
1102 | static void free_stream_buffers(struct ua101 *ua, struct ua101_stream *stream) | ||
1103 | { | ||
1104 | unsigned int i; | ||
1105 | |||
1106 | for (i = 0; i < ARRAY_SIZE(stream->buffers); ++i) | ||
1107 | usb_buffer_free(ua->dev, | ||
1108 | stream->buffers[i].size, | ||
1109 | stream->buffers[i].addr, | ||
1110 | stream->buffers[i].dma); | ||
1111 | } | ||
1112 | |||
1113 | static int alloc_stream_urbs(struct ua101 *ua, struct ua101_stream *stream, | ||
1114 | void (*urb_complete)(struct urb *)) | ||
1115 | { | ||
1116 | unsigned max_packet_size = stream->max_packet_bytes; | ||
1117 | struct ua101_urb *urb; | ||
1118 | unsigned int b, u = 0; | ||
1119 | |||
1120 | for (b = 0; b < ARRAY_SIZE(stream->buffers); ++b) { | ||
1121 | unsigned int size = stream->buffers[b].size; | ||
1122 | u8 *addr = stream->buffers[b].addr; | ||
1123 | dma_addr_t dma = stream->buffers[b].dma; | ||
1124 | |||
1125 | while (size >= max_packet_size) { | ||
1126 | if (u >= stream->queue_length) | ||
1127 | goto bufsize_error; | ||
1128 | urb = kmalloc(sizeof(*urb), GFP_KERNEL); | ||
1129 | if (!urb) | ||
1130 | return -ENOMEM; | ||
1131 | usb_init_urb(&urb->urb); | ||
1132 | urb->urb.dev = ua->dev; | ||
1133 | urb->urb.pipe = stream->usb_pipe; | ||
1134 | urb->urb.transfer_flags = URB_ISO_ASAP | | ||
1135 | URB_NO_TRANSFER_DMA_MAP; | ||
1136 | urb->urb.transfer_buffer = addr; | ||
1137 | urb->urb.transfer_dma = dma; | ||
1138 | urb->urb.transfer_buffer_length = max_packet_size; | ||
1139 | urb->urb.number_of_packets = 1; | ||
1140 | urb->urb.interval = 1; | ||
1141 | urb->urb.context = ua; | ||
1142 | urb->urb.complete = urb_complete; | ||
1143 | urb->urb.iso_frame_desc[0].offset = 0; | ||
1144 | urb->urb.iso_frame_desc[0].length = max_packet_size; | ||
1145 | stream->urbs[u++] = urb; | ||
1146 | size -= max_packet_size; | ||
1147 | addr += max_packet_size; | ||
1148 | dma += max_packet_size; | ||
1149 | } | ||
1150 | } | ||
1151 | if (u == stream->queue_length) | ||
1152 | return 0; | ||
1153 | bufsize_error: | ||
1154 | dev_err(&ua->dev->dev, "internal buffer size error\n"); | ||
1155 | return -ENXIO; | ||
1156 | } | ||
1157 | |||
1158 | static void free_stream_urbs(struct ua101_stream *stream) | ||
1159 | { | ||
1160 | unsigned int i; | ||
1161 | |||
1162 | for (i = 0; i < stream->queue_length; ++i) | ||
1163 | kfree(stream->urbs[i]); | ||
1164 | } | ||
1165 | |||
1166 | static void free_usb_related_resources(struct ua101 *ua, | ||
1167 | struct usb_interface *interface) | ||
1168 | { | ||
1169 | unsigned int i; | ||
1170 | |||
1171 | free_stream_urbs(&ua->capture); | ||
1172 | free_stream_urbs(&ua->playback); | ||
1173 | free_stream_buffers(ua, &ua->capture); | ||
1174 | free_stream_buffers(ua, &ua->playback); | ||
1175 | |||
1176 | for (i = 0; i < ARRAY_SIZE(ua->intf); ++i) | ||
1177 | if (ua->intf[i]) { | ||
1178 | usb_set_intfdata(ua->intf[i], NULL); | ||
1179 | if (ua->intf[i] != interface) | ||
1180 | usb_driver_release_interface(&ua101_driver, | ||
1181 | ua->intf[i]); | ||
1182 | } | ||
1183 | } | ||
1184 | |||
1185 | static void ua101_card_free(struct snd_card *card) | ||
1186 | { | ||
1187 | struct ua101 *ua = card->private_data; | ||
1188 | |||
1189 | mutex_destroy(&ua->mutex); | ||
1190 | } | ||
1191 | |||
1192 | static int ua101_probe(struct usb_interface *interface, | ||
1193 | const struct usb_device_id *usb_id) | ||
1194 | { | ||
1195 | static const struct snd_usb_midi_endpoint_info midi_ep = { | ||
1196 | .out_cables = 0x0001, | ||
1197 | .in_cables = 0x0001 | ||
1198 | }; | ||
1199 | static const struct snd_usb_audio_quirk midi_quirk = { | ||
1200 | .type = QUIRK_MIDI_FIXED_ENDPOINT, | ||
1201 | .data = &midi_ep | ||
1202 | }; | ||
1203 | struct snd_card *card; | ||
1204 | struct ua101 *ua; | ||
1205 | unsigned int card_index, i; | ||
1206 | char usb_path[32]; | ||
1207 | int err; | ||
1208 | |||
1209 | if (interface->altsetting->desc.bInterfaceNumber != 0) | ||
1210 | return -ENODEV; | ||
1211 | |||
1212 | mutex_lock(&devices_mutex); | ||
1213 | |||
1214 | for (card_index = 0; card_index < SNDRV_CARDS; ++card_index) | ||
1215 | if (enable[card_index] && !(devices_used & (1 << card_index))) | ||
1216 | break; | ||
1217 | if (card_index >= SNDRV_CARDS) { | ||
1218 | mutex_unlock(&devices_mutex); | ||
1219 | return -ENOENT; | ||
1220 | } | ||
1221 | err = snd_card_create(index[card_index], id[card_index], THIS_MODULE, | ||
1222 | sizeof(*ua), &card); | ||
1223 | if (err < 0) { | ||
1224 | mutex_unlock(&devices_mutex); | ||
1225 | return err; | ||
1226 | } | ||
1227 | card->private_free = ua101_card_free; | ||
1228 | ua = card->private_data; | ||
1229 | ua->dev = interface_to_usbdev(interface); | ||
1230 | ua->card = card; | ||
1231 | ua->card_index = card_index; | ||
1232 | INIT_LIST_HEAD(&ua->midi_list); | ||
1233 | spin_lock_init(&ua->lock); | ||
1234 | mutex_init(&ua->mutex); | ||
1235 | INIT_LIST_HEAD(&ua->ready_playback_urbs); | ||
1236 | tasklet_init(&ua->playback_tasklet, | ||
1237 | playback_tasklet, (unsigned long)ua); | ||
1238 | init_waitqueue_head(&ua->alsa_capture_wait); | ||
1239 | init_waitqueue_head(&ua->rate_feedback_wait); | ||
1240 | init_waitqueue_head(&ua->alsa_playback_wait); | ||
1241 | |||
1242 | #ifdef UA1A_HACK | ||
1243 | if (ua->dev->descriptor.idProduct == cpu_to_le16(0x0018)) { | ||
1244 | ua->intf[2] = interface; | ||
1245 | ua->intf[0] = usb_ifnum_to_if(ua->dev, 1); | ||
1246 | ua->intf[1] = usb_ifnum_to_if(ua->dev, 2); | ||
1247 | usb_driver_claim_interface(&ua101_driver, ua->intf[0], ua); | ||
1248 | usb_driver_claim_interface(&ua101_driver, ua->intf[1], ua); | ||
1249 | } else { | ||
1250 | #endif | ||
1251 | ua->intf[0] = interface; | ||
1252 | for (i = 1; i < ARRAY_SIZE(ua->intf); ++i) { | ||
1253 | ua->intf[i] = usb_ifnum_to_if(ua->dev, i); | ||
1254 | if (!ua->intf[i]) { | ||
1255 | dev_err(&ua->dev->dev, "interface %u not found\n", i); | ||
1256 | err = -ENXIO; | ||
1257 | goto probe_error; | ||
1258 | } | ||
1259 | err = usb_driver_claim_interface(&ua101_driver, | ||
1260 | ua->intf[i], ua); | ||
1261 | if (err < 0) { | ||
1262 | ua->intf[i] = NULL; | ||
1263 | err = -EBUSY; | ||
1264 | goto probe_error; | ||
1265 | } | ||
1266 | } | ||
1267 | #ifdef UA1A_HACK | ||
1268 | } | ||
1269 | #endif | ||
1270 | |||
1271 | snd_card_set_dev(card, &interface->dev); | ||
1272 | |||
1273 | #ifdef UA1A_HACK | ||
1274 | if (ua->dev->descriptor.idProduct == cpu_to_le16(0x0018)) { | ||
1275 | ua->format_bit = SNDRV_PCM_FMTBIT_S16_LE; | ||
1276 | ua->rate = 44100; | ||
1277 | ua->packets_per_second = 1000; | ||
1278 | ua->capture.channels = 2; | ||
1279 | ua->playback.channels = 2; | ||
1280 | ua->capture.frame_bytes = 4; | ||
1281 | ua->playback.frame_bytes = 4; | ||
1282 | ua->capture.usb_pipe = usb_rcvisocpipe(ua->dev, 2); | ||
1283 | ua->playback.usb_pipe = usb_sndisocpipe(ua->dev, 1); | ||
1284 | ua->capture.max_packet_bytes = 192; | ||
1285 | ua->playback.max_packet_bytes = 192; | ||
1286 | } else { | ||
1287 | #endif | ||
1288 | err = detect_usb_format(ua); | ||
1289 | if (err < 0) | ||
1290 | goto probe_error; | ||
1291 | #ifdef UA1A_HACK | ||
1292 | } | ||
1293 | #endif | ||
1294 | |||
1295 | strcpy(card->driver, "UA-101"); | ||
1296 | strcpy(card->shortname, "UA-101"); | ||
1297 | usb_make_path(ua->dev, usb_path, sizeof(usb_path)); | ||
1298 | snprintf(ua->card->longname, sizeof(ua->card->longname), | ||
1299 | "EDIROL UA-101 (serial %s), %u Hz at %s, %s speed", | ||
1300 | ua->dev->serial ? ua->dev->serial : "?", ua->rate, usb_path, | ||
1301 | ua->dev->speed == USB_SPEED_HIGH ? "high" : "full"); | ||
1302 | |||
1303 | err = alloc_stream_buffers(ua, &ua->capture); | ||
1304 | if (err < 0) | ||
1305 | goto probe_error; | ||
1306 | err = alloc_stream_buffers(ua, &ua->playback); | ||
1307 | if (err < 0) | ||
1308 | goto probe_error; | ||
1309 | |||
1310 | err = alloc_stream_urbs(ua, &ua->capture, capture_urb_complete); | ||
1311 | if (err < 0) | ||
1312 | goto probe_error; | ||
1313 | err = alloc_stream_urbs(ua, &ua->playback, playback_urb_complete); | ||
1314 | if (err < 0) | ||
1315 | goto probe_error; | ||
1316 | |||
1317 | err = snd_pcm_new(card, "UA-101", 0, 1, 1, &ua->pcm); | ||
1318 | if (err < 0) | ||
1319 | goto probe_error; | ||
1320 | ua->pcm->private_data = ua; | ||
1321 | strcpy(ua->pcm->name, "UA-101"); | ||
1322 | snd_pcm_set_ops(ua->pcm, SNDRV_PCM_STREAM_PLAYBACK, &playback_pcm_ops); | ||
1323 | snd_pcm_set_ops(ua->pcm, SNDRV_PCM_STREAM_CAPTURE, &capture_pcm_ops); | ||
1324 | |||
1325 | #ifdef UA1A_HACK | ||
1326 | if (ua->dev->descriptor.idProduct != cpu_to_le16(0x0018)) { | ||
1327 | #endif | ||
1328 | err = snd_usbmidi_create(card, ua->intf[INTF_MIDI], | ||
1329 | &ua->midi_list, &midi_quirk); | ||
1330 | if (err < 0) | ||
1331 | goto probe_error; | ||
1332 | #ifdef UA1A_HACK | ||
1333 | } | ||
1334 | #endif | ||
1335 | |||
1336 | err = snd_card_register(card); | ||
1337 | if (err < 0) | ||
1338 | goto probe_error; | ||
1339 | |||
1340 | usb_set_intfdata(interface, ua); | ||
1341 | devices_used |= 1 << card_index; | ||
1342 | |||
1343 | mutex_unlock(&devices_mutex); | ||
1344 | return 0; | ||
1345 | |||
1346 | probe_error: | ||
1347 | free_usb_related_resources(ua, interface); | ||
1348 | snd_card_free(card); | ||
1349 | mutex_unlock(&devices_mutex); | ||
1350 | return err; | ||
1351 | } | ||
1352 | |||
1353 | static void ua101_disconnect(struct usb_interface *interface) | ||
1354 | { | ||
1355 | struct ua101 *ua = usb_get_intfdata(interface); | ||
1356 | struct list_head *midi; | ||
1357 | |||
1358 | if (!ua) | ||
1359 | return; | ||
1360 | |||
1361 | mutex_lock(&devices_mutex); | ||
1362 | |||
1363 | set_bit(DISCONNECTED, &ua->states); | ||
1364 | wake_up(&ua->rate_feedback_wait); | ||
1365 | |||
1366 | /* make sure that userspace cannot create new requests */ | ||
1367 | snd_card_disconnect(ua->card); | ||
1368 | |||
1369 | /* make sure that there are no pending USB requests */ | ||
1370 | __list_for_each(midi, &ua->midi_list) | ||
1371 | snd_usbmidi_disconnect(midi); | ||
1372 | abort_alsa_playback(ua); | ||
1373 | abort_alsa_capture(ua); | ||
1374 | mutex_lock(&ua->mutex); | ||
1375 | stop_usb_playback(ua); | ||
1376 | stop_usb_capture(ua); | ||
1377 | mutex_unlock(&ua->mutex); | ||
1378 | |||
1379 | free_usb_related_resources(ua, interface); | ||
1380 | |||
1381 | devices_used &= ~(1 << ua->card_index); | ||
1382 | |||
1383 | snd_card_free_when_closed(ua->card); | ||
1384 | |||
1385 | mutex_unlock(&devices_mutex); | ||
1386 | } | ||
1387 | |||
1388 | static struct usb_device_id ua101_ids[] = { | ||
1389 | #ifdef UA1A_HACK | ||
1390 | { USB_DEVICE(0x0582, 0x0018) }, | ||
1391 | #endif | ||
1392 | { USB_DEVICE(0x0582, 0x007d) }, | ||
1393 | { USB_DEVICE(0x0582, 0x008d) }, | ||
1394 | { } | ||
1395 | }; | ||
1396 | MODULE_DEVICE_TABLE(usb, ua101_ids); | ||
1397 | |||
1398 | static struct usb_driver ua101_driver = { | ||
1399 | .name = "snd-ua101", | ||
1400 | .id_table = ua101_ids, | ||
1401 | .probe = ua101_probe, | ||
1402 | .disconnect = ua101_disconnect, | ||
1403 | #if 0 | ||
1404 | .suspend = ua101_suspend, | ||
1405 | .resume = ua101_resume, | ||
1406 | #endif | ||
1407 | }; | ||
1408 | |||
1409 | static int __init alsa_card_ua101_init(void) | ||
1410 | { | ||
1411 | return usb_register(&ua101_driver); | ||
1412 | } | ||
1413 | |||
1414 | static void __exit alsa_card_ua101_exit(void) | ||
1415 | { | ||
1416 | usb_deregister(&ua101_driver); | ||
1417 | mutex_destroy(&devices_mutex); | ||
1418 | } | ||
1419 | |||
1420 | module_init(alsa_card_ua101_init); | ||
1421 | module_exit(alsa_card_ua101_exit); | ||
diff --git a/sound/usb/usbaudio.c b/sound/usb/usbaudio.c index 4963defee18a..b8e0b8fda607 100644 --- a/sound/usb/usbaudio.c +++ b/sound/usb/usbaudio.c | |||
@@ -44,7 +44,6 @@ | |||
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> |
50 | #include <sound/core.h> | 49 | #include <sound/core.h> |
@@ -170,11 +169,12 @@ struct snd_usb_substream { | |||
170 | unsigned int curpacksize; /* current packet size in bytes (for capture) */ | 169 | unsigned int curpacksize; /* current packet size in bytes (for capture) */ |
171 | unsigned int curframesize; /* current packet size in frames (for capture) */ | 170 | unsigned int curframesize; /* current packet size in frames (for capture) */ |
172 | unsigned int fill_max: 1; /* fill max packet size always */ | 171 | unsigned int fill_max: 1; /* fill max packet size always */ |
172 | unsigned int txfr_quirk:1; /* allow sub-frame alignment */ | ||
173 | unsigned int fmt_type; /* USB audio format type (1-3) */ | 173 | unsigned int fmt_type; /* USB audio format type (1-3) */ |
174 | 174 | ||
175 | unsigned int running: 1; /* running status */ | 175 | unsigned int running: 1; /* running status */ |
176 | 176 | ||
177 | unsigned int hwptr_done; /* processed frame position in the buffer */ | 177 | unsigned int hwptr_done; /* processed byte position in the buffer */ |
178 | unsigned int transfer_done; /* processed frames since last period update */ | 178 | unsigned int transfer_done; /* processed frames since last period update */ |
179 | unsigned long active_mask; /* bitmask of active urbs */ | 179 | unsigned long active_mask; /* bitmask of active urbs */ |
180 | unsigned long unlink_mask; /* bitmask of unlinked urbs */ | 180 | unsigned long unlink_mask; /* bitmask of unlinked urbs */ |
@@ -343,7 +343,7 @@ static int retire_capture_urb(struct snd_usb_substream *subs, | |||
343 | unsigned long flags; | 343 | unsigned long flags; |
344 | unsigned char *cp; | 344 | unsigned char *cp; |
345 | int i; | 345 | int i; |
346 | unsigned int stride, len, oldptr; | 346 | unsigned int stride, frames, bytes, oldptr; |
347 | int period_elapsed = 0; | 347 | int period_elapsed = 0; |
348 | 348 | ||
349 | stride = runtime->frame_bits >> 3; | 349 | stride = runtime->frame_bits >> 3; |
@@ -354,29 +354,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); | 354 | snd_printd(KERN_ERR "frame %d active: %d\n", i, urb->iso_frame_desc[i].status); |
355 | // continue; | 355 | // continue; |
356 | } | 356 | } |
357 | len = urb->iso_frame_desc[i].actual_length / stride; | 357 | bytes = urb->iso_frame_desc[i].actual_length; |
358 | if (! len) | 358 | frames = bytes / stride; |
359 | continue; | 359 | if (!subs->txfr_quirk) |
360 | bytes = frames * stride; | ||
361 | if (bytes % (runtime->sample_bits >> 3) != 0) { | ||
362 | #ifdef CONFIG_SND_DEBUG_VERBOSE | ||
363 | int oldbytes = bytes; | ||
364 | #endif | ||
365 | bytes = frames * stride; | ||
366 | snd_printdd(KERN_ERR "Corrected urb data len. %d->%d\n", | ||
367 | oldbytes, bytes); | ||
368 | } | ||
360 | /* update the current pointer */ | 369 | /* update the current pointer */ |
361 | spin_lock_irqsave(&subs->lock, flags); | 370 | spin_lock_irqsave(&subs->lock, flags); |
362 | oldptr = subs->hwptr_done; | 371 | oldptr = subs->hwptr_done; |
363 | subs->hwptr_done += len; | 372 | subs->hwptr_done += bytes; |
364 | if (subs->hwptr_done >= runtime->buffer_size) | 373 | if (subs->hwptr_done >= runtime->buffer_size * stride) |
365 | subs->hwptr_done -= runtime->buffer_size; | 374 | subs->hwptr_done -= runtime->buffer_size * stride; |
366 | subs->transfer_done += len; | 375 | frames = (bytes + (oldptr % stride)) / stride; |
376 | subs->transfer_done += frames; | ||
367 | if (subs->transfer_done >= runtime->period_size) { | 377 | if (subs->transfer_done >= runtime->period_size) { |
368 | subs->transfer_done -= runtime->period_size; | 378 | subs->transfer_done -= runtime->period_size; |
369 | period_elapsed = 1; | 379 | period_elapsed = 1; |
370 | } | 380 | } |
371 | spin_unlock_irqrestore(&subs->lock, flags); | 381 | spin_unlock_irqrestore(&subs->lock, flags); |
372 | /* copy a data chunk */ | 382 | /* copy a data chunk */ |
373 | if (oldptr + len > runtime->buffer_size) { | 383 | if (oldptr + bytes > runtime->buffer_size * stride) { |
374 | unsigned int cnt = runtime->buffer_size - oldptr; | 384 | unsigned int bytes1 = |
375 | unsigned int blen = cnt * stride; | 385 | runtime->buffer_size * stride - oldptr; |
376 | memcpy(runtime->dma_area + oldptr * stride, cp, blen); | 386 | memcpy(runtime->dma_area + oldptr, cp, bytes1); |
377 | memcpy(runtime->dma_area, cp + blen, len * stride - blen); | 387 | memcpy(runtime->dma_area, cp + bytes1, bytes - bytes1); |
378 | } else { | 388 | } else { |
379 | memcpy(runtime->dma_area + oldptr * stride, cp, len * stride); | 389 | memcpy(runtime->dma_area + oldptr, cp, bytes); |
380 | } | 390 | } |
381 | } | 391 | } |
382 | if (period_elapsed) | 392 | if (period_elapsed) |
@@ -563,24 +573,24 @@ static int prepare_playback_urb(struct snd_usb_substream *subs, | |||
563 | struct snd_pcm_runtime *runtime, | 573 | struct snd_pcm_runtime *runtime, |
564 | struct urb *urb) | 574 | struct urb *urb) |
565 | { | 575 | { |
566 | int i, stride, offs; | 576 | int i, stride; |
567 | unsigned int counts; | 577 | unsigned int counts, frames, bytes; |
568 | unsigned long flags; | 578 | unsigned long flags; |
569 | int period_elapsed = 0; | 579 | int period_elapsed = 0; |
570 | struct snd_urb_ctx *ctx = urb->context; | 580 | struct snd_urb_ctx *ctx = urb->context; |
571 | 581 | ||
572 | stride = runtime->frame_bits >> 3; | 582 | stride = runtime->frame_bits >> 3; |
573 | 583 | ||
574 | offs = 0; | 584 | frames = 0; |
575 | urb->dev = ctx->subs->dev; /* we need to set this at each time */ | 585 | urb->dev = ctx->subs->dev; /* we need to set this at each time */ |
576 | urb->number_of_packets = 0; | 586 | urb->number_of_packets = 0; |
577 | spin_lock_irqsave(&subs->lock, flags); | 587 | spin_lock_irqsave(&subs->lock, flags); |
578 | for (i = 0; i < ctx->packets; i++) { | 588 | for (i = 0; i < ctx->packets; i++) { |
579 | counts = snd_usb_audio_next_packet_size(subs); | 589 | counts = snd_usb_audio_next_packet_size(subs); |
580 | /* set up descriptor */ | 590 | /* set up descriptor */ |
581 | urb->iso_frame_desc[i].offset = offs * stride; | 591 | urb->iso_frame_desc[i].offset = frames * stride; |
582 | urb->iso_frame_desc[i].length = counts * stride; | 592 | urb->iso_frame_desc[i].length = counts * stride; |
583 | offs += counts; | 593 | frames += counts; |
584 | urb->number_of_packets++; | 594 | urb->number_of_packets++; |
585 | subs->transfer_done += counts; | 595 | subs->transfer_done += counts; |
586 | if (subs->transfer_done >= runtime->period_size) { | 596 | if (subs->transfer_done >= runtime->period_size) { |
@@ -590,7 +600,7 @@ static int prepare_playback_urb(struct snd_usb_substream *subs, | |||
590 | if (subs->transfer_done > 0) { | 600 | if (subs->transfer_done > 0) { |
591 | /* FIXME: fill-max mode is not | 601 | /* FIXME: fill-max mode is not |
592 | * supported yet */ | 602 | * supported yet */ |
593 | offs -= subs->transfer_done; | 603 | frames -= subs->transfer_done; |
594 | counts -= subs->transfer_done; | 604 | counts -= subs->transfer_done; |
595 | urb->iso_frame_desc[i].length = | 605 | urb->iso_frame_desc[i].length = |
596 | counts * stride; | 606 | counts * stride; |
@@ -600,7 +610,7 @@ static int prepare_playback_urb(struct snd_usb_substream *subs, | |||
600 | if (i < ctx->packets) { | 610 | if (i < ctx->packets) { |
601 | /* add a transfer delimiter */ | 611 | /* add a transfer delimiter */ |
602 | urb->iso_frame_desc[i].offset = | 612 | urb->iso_frame_desc[i].offset = |
603 | offs * stride; | 613 | frames * stride; |
604 | urb->iso_frame_desc[i].length = 0; | 614 | urb->iso_frame_desc[i].length = 0; |
605 | urb->number_of_packets++; | 615 | urb->number_of_packets++; |
606 | } | 616 | } |
@@ -610,26 +620,25 @@ static int prepare_playback_urb(struct snd_usb_substream *subs, | |||
610 | if (period_elapsed) /* finish at the period boundary */ | 620 | if (period_elapsed) /* finish at the period boundary */ |
611 | break; | 621 | break; |
612 | } | 622 | } |
613 | if (subs->hwptr_done + offs > runtime->buffer_size) { | 623 | bytes = frames * stride; |
624 | if (subs->hwptr_done + bytes > runtime->buffer_size * stride) { | ||
614 | /* err, the transferred area goes over buffer boundary. */ | 625 | /* err, the transferred area goes over buffer boundary. */ |
615 | unsigned int len = runtime->buffer_size - subs->hwptr_done; | 626 | unsigned int bytes1 = |
627 | runtime->buffer_size * stride - subs->hwptr_done; | ||
616 | memcpy(urb->transfer_buffer, | 628 | memcpy(urb->transfer_buffer, |
617 | runtime->dma_area + subs->hwptr_done * stride, | 629 | runtime->dma_area + subs->hwptr_done, bytes1); |
618 | len * stride); | 630 | memcpy(urb->transfer_buffer + bytes1, |
619 | memcpy(urb->transfer_buffer + len * stride, | 631 | runtime->dma_area, bytes - bytes1); |
620 | runtime->dma_area, | ||
621 | (offs - len) * stride); | ||
622 | } else { | 632 | } else { |
623 | memcpy(urb->transfer_buffer, | 633 | memcpy(urb->transfer_buffer, |
624 | runtime->dma_area + subs->hwptr_done * stride, | 634 | runtime->dma_area + subs->hwptr_done, bytes); |
625 | offs * stride); | ||
626 | } | 635 | } |
627 | subs->hwptr_done += offs; | 636 | subs->hwptr_done += bytes; |
628 | if (subs->hwptr_done >= runtime->buffer_size) | 637 | if (subs->hwptr_done >= runtime->buffer_size * stride) |
629 | subs->hwptr_done -= runtime->buffer_size; | 638 | subs->hwptr_done -= runtime->buffer_size * stride; |
630 | runtime->delay += offs; | 639 | runtime->delay += frames; |
631 | spin_unlock_irqrestore(&subs->lock, flags); | 640 | spin_unlock_irqrestore(&subs->lock, flags); |
632 | urb->transfer_buffer_length = offs * stride; | 641 | urb->transfer_buffer_length = bytes; |
633 | if (period_elapsed) | 642 | if (period_elapsed) |
634 | snd_pcm_period_elapsed(subs->pcm_substream); | 643 | snd_pcm_period_elapsed(subs->pcm_substream); |
635 | return 0; | 644 | return 0; |
@@ -735,41 +744,6 @@ static void snd_complete_sync_urb(struct urb *urb) | |||
735 | } | 744 | } |
736 | 745 | ||
737 | 746 | ||
738 | /* get the physical page pointer at the given offset */ | ||
739 | static 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 */ | ||
747 | static 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_user(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 */ | ||
763 | static 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 | /* | 747 | /* |
774 | * unlink active urbs. | 748 | * unlink active urbs. |
775 | */ | 749 | */ |
@@ -937,18 +911,18 @@ static int wait_clear_urbs(struct snd_usb_substream *subs) | |||
937 | 911 | ||
938 | 912 | ||
939 | /* | 913 | /* |
940 | * return the current pcm pointer. just return the hwptr_done value. | 914 | * return the current pcm pointer. just based on the hwptr_done value. |
941 | */ | 915 | */ |
942 | static snd_pcm_uframes_t snd_usb_pcm_pointer(struct snd_pcm_substream *substream) | 916 | static snd_pcm_uframes_t snd_usb_pcm_pointer(struct snd_pcm_substream *substream) |
943 | { | 917 | { |
944 | struct snd_usb_substream *subs; | 918 | struct snd_usb_substream *subs; |
945 | snd_pcm_uframes_t hwptr_done; | 919 | unsigned int hwptr_done; |
946 | 920 | ||
947 | subs = (struct snd_usb_substream *)substream->runtime->private_data; | 921 | subs = (struct snd_usb_substream *)substream->runtime->private_data; |
948 | spin_lock(&subs->lock); | 922 | spin_lock(&subs->lock); |
949 | hwptr_done = subs->hwptr_done; | 923 | hwptr_done = subs->hwptr_done; |
950 | spin_unlock(&subs->lock); | 924 | spin_unlock(&subs->lock); |
951 | return hwptr_done; | 925 | return hwptr_done / (substream->runtime->frame_bits >> 3); |
952 | } | 926 | } |
953 | 927 | ||
954 | 928 | ||
@@ -1307,6 +1281,47 @@ static int init_usb_sample_rate(struct usb_device *dev, int iface, | |||
1307 | } | 1281 | } |
1308 | 1282 | ||
1309 | /* | 1283 | /* |
1284 | * For E-Mu 0404USB/0202USB/TrackerPre sample rate should be set for device, | ||
1285 | * not for interface. | ||
1286 | */ | ||
1287 | static void set_format_emu_quirk(struct snd_usb_substream *subs, | ||
1288 | struct audioformat *fmt) | ||
1289 | { | ||
1290 | unsigned char emu_samplerate_id = 0; | ||
1291 | |||
1292 | /* When capture is active | ||
1293 | * sample rate shouldn't be changed | ||
1294 | * by playback substream | ||
1295 | */ | ||
1296 | if (subs->direction == SNDRV_PCM_STREAM_PLAYBACK) { | ||
1297 | if (subs->stream->substream[SNDRV_PCM_STREAM_CAPTURE].interface != -1) | ||
1298 | return; | ||
1299 | } | ||
1300 | |||
1301 | switch (fmt->rate_min) { | ||
1302 | case 48000: | ||
1303 | emu_samplerate_id = EMU_QUIRK_SR_48000HZ; | ||
1304 | break; | ||
1305 | case 88200: | ||
1306 | emu_samplerate_id = EMU_QUIRK_SR_88200HZ; | ||
1307 | break; | ||
1308 | case 96000: | ||
1309 | emu_samplerate_id = EMU_QUIRK_SR_96000HZ; | ||
1310 | break; | ||
1311 | case 176400: | ||
1312 | emu_samplerate_id = EMU_QUIRK_SR_176400HZ; | ||
1313 | break; | ||
1314 | case 192000: | ||
1315 | emu_samplerate_id = EMU_QUIRK_SR_192000HZ; | ||
1316 | break; | ||
1317 | default: | ||
1318 | emu_samplerate_id = EMU_QUIRK_SR_44100HZ; | ||
1319 | break; | ||
1320 | } | ||
1321 | snd_emuusb_set_samplerate(subs->stream->chip, emu_samplerate_id); | ||
1322 | } | ||
1323 | |||
1324 | /* | ||
1310 | * find a matching format and set up the interface | 1325 | * find a matching format and set up the interface |
1311 | */ | 1326 | */ |
1312 | static int set_format(struct snd_usb_substream *subs, struct audioformat *fmt) | 1327 | static int set_format(struct snd_usb_substream *subs, struct audioformat *fmt) |
@@ -1419,6 +1434,14 @@ static int set_format(struct snd_usb_substream *subs, struct audioformat *fmt) | |||
1419 | 1434 | ||
1420 | subs->cur_audiofmt = fmt; | 1435 | subs->cur_audiofmt = fmt; |
1421 | 1436 | ||
1437 | switch (subs->stream->chip->usb_id) { | ||
1438 | case USB_ID(0x041e, 0x3f02): /* E-Mu 0202 USB */ | ||
1439 | case USB_ID(0x041e, 0x3f04): /* E-Mu 0404 USB */ | ||
1440 | case USB_ID(0x041e, 0x3f0a): /* E-Mu Tracker Pre */ | ||
1441 | set_format_emu_quirk(subs, fmt); | ||
1442 | break; | ||
1443 | } | ||
1444 | |||
1422 | #if 0 | 1445 | #if 0 |
1423 | printk(KERN_DEBUG | 1446 | printk(KERN_DEBUG |
1424 | "setting done: format = %d, rate = %d..%d, channels = %d\n", | 1447 | "setting done: format = %d, rate = %d..%d, channels = %d\n", |
@@ -1449,8 +1472,8 @@ static int snd_usb_hw_params(struct snd_pcm_substream *substream, | |||
1449 | unsigned int channels, rate, format; | 1472 | unsigned int channels, rate, format; |
1450 | int ret, changed; | 1473 | int ret, changed; |
1451 | 1474 | ||
1452 | ret = snd_pcm_alloc_vmalloc_buffer(substream, | 1475 | ret = snd_pcm_lib_alloc_vmalloc_buffer(substream, |
1453 | params_buffer_bytes(hw_params)); | 1476 | params_buffer_bytes(hw_params)); |
1454 | if (ret < 0) | 1477 | if (ret < 0) |
1455 | return ret; | 1478 | return ret; |
1456 | 1479 | ||
@@ -1507,7 +1530,7 @@ static int snd_usb_hw_free(struct snd_pcm_substream *substream) | |||
1507 | subs->period_bytes = 0; | 1530 | subs->period_bytes = 0; |
1508 | if (!subs->stream->chip->shutdown) | 1531 | if (!subs->stream->chip->shutdown) |
1509 | release_substream_urbs(subs, 0); | 1532 | release_substream_urbs(subs, 0); |
1510 | return snd_pcm_free_vmalloc_buffer(substream); | 1533 | return snd_pcm_lib_free_vmalloc_buffer(substream); |
1511 | } | 1534 | } |
1512 | 1535 | ||
1513 | /* | 1536 | /* |
@@ -1973,7 +1996,8 @@ static struct snd_pcm_ops snd_usb_playback_ops = { | |||
1973 | .prepare = snd_usb_pcm_prepare, | 1996 | .prepare = snd_usb_pcm_prepare, |
1974 | .trigger = snd_usb_pcm_playback_trigger, | 1997 | .trigger = snd_usb_pcm_playback_trigger, |
1975 | .pointer = snd_usb_pcm_pointer, | 1998 | .pointer = snd_usb_pcm_pointer, |
1976 | .page = snd_pcm_get_vmalloc_page, | 1999 | .page = snd_pcm_lib_get_vmalloc_page, |
2000 | .mmap = snd_pcm_lib_mmap_vmalloc, | ||
1977 | }; | 2001 | }; |
1978 | 2002 | ||
1979 | static struct snd_pcm_ops snd_usb_capture_ops = { | 2003 | static struct snd_pcm_ops snd_usb_capture_ops = { |
@@ -1985,7 +2009,8 @@ static struct snd_pcm_ops snd_usb_capture_ops = { | |||
1985 | .prepare = snd_usb_pcm_prepare, | 2009 | .prepare = snd_usb_pcm_prepare, |
1986 | .trigger = snd_usb_pcm_capture_trigger, | 2010 | .trigger = snd_usb_pcm_capture_trigger, |
1987 | .pointer = snd_usb_pcm_pointer, | 2011 | .pointer = snd_usb_pcm_pointer, |
1988 | .page = snd_pcm_get_vmalloc_page, | 2012 | .page = snd_pcm_lib_get_vmalloc_page, |
2013 | .mmap = snd_pcm_lib_mmap_vmalloc, | ||
1989 | }; | 2014 | }; |
1990 | 2015 | ||
1991 | 2016 | ||
@@ -2227,6 +2252,7 @@ static void init_substream(struct snd_usb_stream *as, int stream, struct audiofo | |||
2227 | subs->stream = as; | 2252 | subs->stream = as; |
2228 | subs->direction = stream; | 2253 | subs->direction = stream; |
2229 | subs->dev = as->chip->dev; | 2254 | subs->dev = as->chip->dev; |
2255 | subs->txfr_quirk = as->chip->txfr_quirk; | ||
2230 | if (snd_usb_get_speed(subs->dev) == USB_SPEED_FULL) { | 2256 | if (snd_usb_get_speed(subs->dev) == USB_SPEED_FULL) { |
2231 | subs->ops = audio_urb_ops[stream]; | 2257 | subs->ops = audio_urb_ops[stream]; |
2232 | } else { | 2258 | } else { |
@@ -3142,59 +3168,6 @@ static int create_ua1000_quirk(struct snd_usb_audio *chip, | |||
3142 | return 0; | 3168 | return 0; |
3143 | } | 3169 | } |
3144 | 3170 | ||
3145 | /* | ||
3146 | * Create a stream for an Edirol UA-101 interface. | ||
3147 | * Copy, paste and modify from Edirol UA-1000 | ||
3148 | */ | ||
3149 | static int create_ua101_quirk(struct snd_usb_audio *chip, | ||
3150 | struct usb_interface *iface, | ||
3151 | const struct snd_usb_audio_quirk *quirk) | ||
3152 | { | ||
3153 | static const struct audioformat ua101_format = { | ||
3154 | .format = SNDRV_PCM_FORMAT_S32_LE, | ||
3155 | .fmt_type = USB_FORMAT_TYPE_I, | ||
3156 | .altsetting = 1, | ||
3157 | .altset_idx = 1, | ||
3158 | .attributes = 0, | ||
3159 | .rates = SNDRV_PCM_RATE_CONTINUOUS, | ||
3160 | }; | ||
3161 | struct usb_host_interface *alts; | ||
3162 | struct usb_interface_descriptor *altsd; | ||
3163 | struct audioformat *fp; | ||
3164 | int stream, err; | ||
3165 | |||
3166 | if (iface->num_altsetting != 2) | ||
3167 | return -ENXIO; | ||
3168 | alts = &iface->altsetting[1]; | ||
3169 | altsd = get_iface_desc(alts); | ||
3170 | if (alts->extralen != 18 || alts->extra[1] != USB_DT_CS_INTERFACE || | ||
3171 | altsd->bNumEndpoints != 1) | ||
3172 | return -ENXIO; | ||
3173 | |||
3174 | fp = kmemdup(&ua101_format, sizeof(*fp), GFP_KERNEL); | ||
3175 | if (!fp) | ||
3176 | return -ENOMEM; | ||
3177 | |||
3178 | fp->channels = alts->extra[11]; | ||
3179 | fp->iface = altsd->bInterfaceNumber; | ||
3180 | fp->endpoint = get_endpoint(alts, 0)->bEndpointAddress; | ||
3181 | fp->ep_attr = get_endpoint(alts, 0)->bmAttributes; | ||
3182 | fp->datainterval = parse_datainterval(chip, alts); | ||
3183 | fp->maxpacksize = le16_to_cpu(get_endpoint(alts, 0)->wMaxPacketSize); | ||
3184 | fp->rate_max = fp->rate_min = combine_triple(&alts->extra[15]); | ||
3185 | |||
3186 | stream = (fp->endpoint & USB_DIR_IN) | ||
3187 | ? SNDRV_PCM_STREAM_CAPTURE : SNDRV_PCM_STREAM_PLAYBACK; | ||
3188 | err = add_audio_endpoint(chip, stream, fp); | ||
3189 | if (err < 0) { | ||
3190 | kfree(fp); | ||
3191 | return err; | ||
3192 | } | ||
3193 | /* FIXME: playback must be synchronized to capture */ | ||
3194 | usb_set_interface(chip->dev, fp->iface, 0); | ||
3195 | return 0; | ||
3196 | } | ||
3197 | |||
3198 | static int snd_usb_create_quirk(struct snd_usb_audio *chip, | 3171 | static int snd_usb_create_quirk(struct snd_usb_audio *chip, |
3199 | struct usb_interface *iface, | 3172 | struct usb_interface *iface, |
3200 | const struct snd_usb_audio_quirk *quirk); | 3173 | const struct snd_usb_audio_quirk *quirk); |
@@ -3232,6 +3205,18 @@ static int ignore_interface_quirk(struct snd_usb_audio *chip, | |||
3232 | return 0; | 3205 | return 0; |
3233 | } | 3206 | } |
3234 | 3207 | ||
3208 | /* | ||
3209 | * Allow alignment on audio sub-slot (channel samples) rather than | ||
3210 | * on audio slots (audio frames) | ||
3211 | */ | ||
3212 | static int create_align_transfer_quirk(struct snd_usb_audio *chip, | ||
3213 | struct usb_interface *iface, | ||
3214 | const struct snd_usb_audio_quirk *quirk) | ||
3215 | { | ||
3216 | chip->txfr_quirk = 1; | ||
3217 | return 1; /* Continue with creating streams and mixer */ | ||
3218 | } | ||
3219 | |||
3235 | 3220 | ||
3236 | /* | 3221 | /* |
3237 | * boot quirks | 3222 | * boot quirks |
@@ -3406,8 +3391,8 @@ static int snd_usb_create_quirk(struct snd_usb_audio *chip, | |||
3406 | [QUIRK_AUDIO_STANDARD_INTERFACE] = create_standard_audio_quirk, | 3391 | [QUIRK_AUDIO_STANDARD_INTERFACE] = create_standard_audio_quirk, |
3407 | [QUIRK_AUDIO_FIXED_ENDPOINT] = create_fixed_stream_quirk, | 3392 | [QUIRK_AUDIO_FIXED_ENDPOINT] = create_fixed_stream_quirk, |
3408 | [QUIRK_AUDIO_EDIROL_UA1000] = create_ua1000_quirk, | 3393 | [QUIRK_AUDIO_EDIROL_UA1000] = create_ua1000_quirk, |
3409 | [QUIRK_AUDIO_EDIROL_UA101] = create_ua101_quirk, | 3394 | [QUIRK_AUDIO_EDIROL_UAXX] = create_uaxx_quirk, |
3410 | [QUIRK_AUDIO_EDIROL_UAXX] = create_uaxx_quirk | 3395 | [QUIRK_AUDIO_ALIGN_TRANSFER] = create_align_transfer_quirk |
3411 | }; | 3396 | }; |
3412 | 3397 | ||
3413 | if (quirk->type < QUIRK_TYPE_COUNT) { | 3398 | if (quirk->type < QUIRK_TYPE_COUNT) { |
@@ -3661,6 +3646,7 @@ static void *snd_usb_audio_probe(struct usb_device *dev, | |||
3661 | } | 3646 | } |
3662 | } | 3647 | } |
3663 | 3648 | ||
3649 | chip->txfr_quirk = 0; | ||
3664 | err = 1; /* continue */ | 3650 | err = 1; /* continue */ |
3665 | if (quirk && quirk->ifnum != QUIRK_NO_INTERFACE) { | 3651 | if (quirk && quirk->ifnum != QUIRK_NO_INTERFACE) { |
3666 | /* need some special handlings */ | 3652 | /* need some special handlings */ |
diff --git a/sound/usb/usbaudio.h b/sound/usb/usbaudio.h index 40ba8115fb81..9d8cea48fc5f 100644 --- a/sound/usb/usbaudio.h +++ b/sound/usb/usbaudio.h | |||
@@ -125,6 +125,7 @@ struct snd_usb_audio { | |||
125 | struct snd_card *card; | 125 | struct snd_card *card; |
126 | u32 usb_id; | 126 | u32 usb_id; |
127 | int shutdown; | 127 | int shutdown; |
128 | unsigned int txfr_quirk:1; /* Subframe boundaries on transfers */ | ||
128 | int num_interfaces; | 129 | int num_interfaces; |
129 | int num_suspended_intf; | 130 | int num_suspended_intf; |
130 | 131 | ||
@@ -159,8 +160,8 @@ enum quirk_type { | |||
159 | QUIRK_AUDIO_STANDARD_INTERFACE, | 160 | QUIRK_AUDIO_STANDARD_INTERFACE, |
160 | QUIRK_AUDIO_FIXED_ENDPOINT, | 161 | QUIRK_AUDIO_FIXED_ENDPOINT, |
161 | QUIRK_AUDIO_EDIROL_UA1000, | 162 | QUIRK_AUDIO_EDIROL_UA1000, |
162 | QUIRK_AUDIO_EDIROL_UA101, | ||
163 | QUIRK_AUDIO_EDIROL_UAXX, | 163 | QUIRK_AUDIO_EDIROL_UAXX, |
164 | QUIRK_AUDIO_ALIGN_TRANSFER, | ||
164 | 165 | ||
165 | QUIRK_TYPE_COUNT | 166 | QUIRK_TYPE_COUNT |
166 | }; | 167 | }; |
@@ -209,6 +210,16 @@ struct snd_usb_midi_endpoint_info { | |||
209 | /* | 210 | /* |
210 | */ | 211 | */ |
211 | 212 | ||
213 | /*E-mu USB samplerate control quirk*/ | ||
214 | enum { | ||
215 | EMU_QUIRK_SR_44100HZ = 0, | ||
216 | EMU_QUIRK_SR_48000HZ, | ||
217 | EMU_QUIRK_SR_88200HZ, | ||
218 | EMU_QUIRK_SR_96000HZ, | ||
219 | EMU_QUIRK_SR_176400HZ, | ||
220 | EMU_QUIRK_SR_192000HZ | ||
221 | }; | ||
222 | |||
212 | #define combine_word(s) ((*(s)) | ((unsigned int)(s)[1] << 8)) | 223 | #define combine_word(s) ((*(s)) | ((unsigned int)(s)[1] << 8)) |
213 | #define combine_triple(s) (combine_word(s) | ((unsigned int)(s)[2] << 16)) | 224 | #define combine_triple(s) (combine_word(s) | ((unsigned int)(s)[2] << 16)) |
214 | #define combine_quad(s) (combine_triple(s) | ((unsigned int)(s)[3] << 24)) | 225 | #define combine_quad(s) (combine_triple(s) | ((unsigned int)(s)[3] << 24)) |
@@ -234,6 +245,9 @@ void snd_usbmidi_input_stop(struct list_head* p); | |||
234 | void snd_usbmidi_input_start(struct list_head* p); | 245 | void snd_usbmidi_input_start(struct list_head* p); |
235 | void snd_usbmidi_disconnect(struct list_head *p); | 246 | void snd_usbmidi_disconnect(struct list_head *p); |
236 | 247 | ||
248 | void snd_emuusb_set_samplerate(struct snd_usb_audio *chip, | ||
249 | unsigned char samplerate_id); | ||
250 | |||
237 | /* | 251 | /* |
238 | * retrieve usb_interface descriptor from the host interface | 252 | * retrieve usb_interface descriptor from the host interface |
239 | * (conditional for compatibility with the older API) | 253 | * (conditional for compatibility with the older API) |
diff --git a/sound/usb/usbmixer.c b/sound/usb/usbmixer.c index c72ad0c82581..dd0c1d7bf3ed 100644 --- a/sound/usb/usbmixer.c +++ b/sound/usb/usbmixer.c | |||
@@ -187,6 +187,21 @@ enum { | |||
187 | USB_PROC_DCR_RELEASE = 6, | 187 | USB_PROC_DCR_RELEASE = 6, |
188 | }; | 188 | }; |
189 | 189 | ||
190 | /*E-mu 0202(0404) eXtension Unit(XU) control*/ | ||
191 | enum { | ||
192 | USB_XU_CLOCK_RATE = 0xe301, | ||
193 | USB_XU_CLOCK_SOURCE = 0xe302, | ||
194 | USB_XU_DIGITAL_IO_STATUS = 0xe303, | ||
195 | USB_XU_DEVICE_OPTIONS = 0xe304, | ||
196 | USB_XU_DIRECT_MONITORING = 0xe305, | ||
197 | USB_XU_METERING = 0xe306 | ||
198 | }; | ||
199 | enum { | ||
200 | USB_XU_CLOCK_SOURCE_SELECTOR = 0x02, /* clock source*/ | ||
201 | USB_XU_CLOCK_RATE_SELECTOR = 0x03, /* clock rate */ | ||
202 | USB_XU_DIGITAL_FORMAT_SELECTOR = 0x01, /* the spdif format */ | ||
203 | USB_XU_SOFT_LIMIT_SELECTOR = 0x03 /* soft limiter */ | ||
204 | }; | ||
190 | 205 | ||
191 | /* | 206 | /* |
192 | * manual mapping of mixer names | 207 | * manual mapping of mixer names |
@@ -1352,7 +1367,32 @@ static struct procunit_info procunits[] = { | |||
1352 | { USB_PROC_DCR, "DCR", dcr_proc_info }, | 1367 | { USB_PROC_DCR, "DCR", dcr_proc_info }, |
1353 | { 0 }, | 1368 | { 0 }, |
1354 | }; | 1369 | }; |
1355 | 1370 | /* | |
1371 | * predefined data for extension units | ||
1372 | */ | ||
1373 | static struct procunit_value_info clock_rate_xu_info[] = { | ||
1374 | { USB_XU_CLOCK_RATE_SELECTOR, "Selector", USB_MIXER_U8, 0 }, | ||
1375 | { 0 } | ||
1376 | }; | ||
1377 | static struct procunit_value_info clock_source_xu_info[] = { | ||
1378 | { USB_XU_CLOCK_SOURCE_SELECTOR, "External", USB_MIXER_BOOLEAN }, | ||
1379 | { 0 } | ||
1380 | }; | ||
1381 | static struct procunit_value_info spdif_format_xu_info[] = { | ||
1382 | { USB_XU_DIGITAL_FORMAT_SELECTOR, "SPDIF/AC3", USB_MIXER_BOOLEAN }, | ||
1383 | { 0 } | ||
1384 | }; | ||
1385 | static struct procunit_value_info soft_limit_xu_info[] = { | ||
1386 | { USB_XU_SOFT_LIMIT_SELECTOR, " ", USB_MIXER_BOOLEAN }, | ||
1387 | { 0 } | ||
1388 | }; | ||
1389 | static struct procunit_info extunits[] = { | ||
1390 | { USB_XU_CLOCK_RATE, "Clock rate", clock_rate_xu_info }, | ||
1391 | { USB_XU_CLOCK_SOURCE, "DigitalIn CLK source", clock_source_xu_info }, | ||
1392 | { USB_XU_DIGITAL_IO_STATUS, "DigitalOut format:", spdif_format_xu_info }, | ||
1393 | { USB_XU_DEVICE_OPTIONS, "AnalogueIn Soft Limit", soft_limit_xu_info }, | ||
1394 | { 0 } | ||
1395 | }; | ||
1356 | /* | 1396 | /* |
1357 | * build a processing/extension unit | 1397 | * build a processing/extension unit |
1358 | */ | 1398 | */ |
@@ -1415,8 +1455,18 @@ static int build_audio_procunit(struct mixer_build *state, int unitid, unsigned | |||
1415 | cval->max = dsc[15]; | 1455 | cval->max = dsc[15]; |
1416 | cval->res = 1; | 1456 | cval->res = 1; |
1417 | cval->initialized = 1; | 1457 | cval->initialized = 1; |
1418 | } else | 1458 | } else { |
1419 | get_min_max(cval, valinfo->min_value); | 1459 | if (type == USB_XU_CLOCK_RATE) { |
1460 | /* E-Mu USB 0404/0202/TrackerPre | ||
1461 | * samplerate control quirk | ||
1462 | */ | ||
1463 | cval->min = 0; | ||
1464 | cval->max = 5; | ||
1465 | cval->res = 1; | ||
1466 | cval->initialized = 1; | ||
1467 | } else | ||
1468 | get_min_max(cval, valinfo->min_value); | ||
1469 | } | ||
1420 | 1470 | ||
1421 | kctl = snd_ctl_new1(&mixer_procunit_ctl, cval); | 1471 | kctl = snd_ctl_new1(&mixer_procunit_ctl, cval); |
1422 | if (! kctl) { | 1472 | if (! kctl) { |
@@ -1458,7 +1508,7 @@ static int parse_audio_processing_unit(struct mixer_build *state, int unitid, un | |||
1458 | 1508 | ||
1459 | static int parse_audio_extension_unit(struct mixer_build *state, int unitid, unsigned char *desc) | 1509 | static int parse_audio_extension_unit(struct mixer_build *state, int unitid, unsigned char *desc) |
1460 | { | 1510 | { |
1461 | return build_audio_procunit(state, unitid, desc, NULL, "Extension Unit"); | 1511 | return build_audio_procunit(state, unitid, desc, extunits, "Extension Unit"); |
1462 | } | 1512 | } |
1463 | 1513 | ||
1464 | 1514 | ||
@@ -2136,6 +2186,23 @@ static int snd_xonar_u1_controls_create(struct usb_mixer_interface *mixer) | |||
2136 | return 0; | 2186 | return 0; |
2137 | } | 2187 | } |
2138 | 2188 | ||
2189 | void snd_emuusb_set_samplerate(struct snd_usb_audio *chip, | ||
2190 | unsigned char samplerate_id) | ||
2191 | { | ||
2192 | struct usb_mixer_interface *mixer; | ||
2193 | struct usb_mixer_elem_info *cval; | ||
2194 | int unitid = 12; /* SamleRate ExtensionUnit ID */ | ||
2195 | |||
2196 | list_for_each_entry(mixer, &chip->mixer_list, list) { | ||
2197 | cval = mixer->id_elems[unitid]; | ||
2198 | if (cval) { | ||
2199 | set_cur_ctl_value(cval, cval->control << 8, samplerate_id); | ||
2200 | snd_usb_mixer_notify_id(mixer, unitid); | ||
2201 | } | ||
2202 | break; | ||
2203 | } | ||
2204 | } | ||
2205 | |||
2139 | int snd_usb_create_mixer(struct snd_usb_audio *chip, int ctrlif, | 2206 | int snd_usb_create_mixer(struct snd_usb_audio *chip, int ctrlif, |
2140 | int ignore_error) | 2207 | int ignore_error) |
2141 | { | 2208 | { |
diff --git a/sound/usb/usbquirks.h b/sound/usb/usbquirks.h index a892bda03df9..65bbd22f2e0c 100644 --- a/sound/usb/usbquirks.h +++ b/sound/usb/usbquirks.h | |||
@@ -1266,37 +1266,6 @@ YAMAHA_DEVICE(0x7010, "UB99"), | |||
1266 | } | 1266 | } |
1267 | } | 1267 | } |
1268 | }, | 1268 | }, |
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 | { | 1269 | { |
1301 | /* has ID 0x0081 when not in "Advanced Driver" mode */ | 1270 | /* has ID 0x0081 when not in "Advanced Driver" mode */ |
1302 | USB_DEVICE(0x0582, 0x0080), | 1271 | USB_DEVICE(0x0582, 0x0080), |
@@ -2105,6 +2074,120 @@ YAMAHA_DEVICE(0x7010, "UB99"), | |||
2105 | } | 2074 | } |
2106 | }, | 2075 | }, |
2107 | 2076 | ||
2077 | /* Hauppauge HVR-950Q and HVR-850 */ | ||
2078 | { | ||
2079 | USB_DEVICE_VENDOR_SPEC(0x2040, 0x7200), | ||
2080 | .match_flags = USB_DEVICE_ID_MATCH_DEVICE | | ||
2081 | USB_DEVICE_ID_MATCH_INT_CLASS | | ||
2082 | USB_DEVICE_ID_MATCH_INT_SUBCLASS, | ||
2083 | .bInterfaceClass = USB_CLASS_AUDIO, | ||
2084 | .bInterfaceSubClass = USB_SUBCLASS_AUDIO_CONTROL, | ||
2085 | .driver_info = (unsigned long) &(const struct snd_usb_audio_quirk) { | ||
2086 | .vendor_name = "Hauppauge", | ||
2087 | .product_name = "HVR-950Q", | ||
2088 | .ifnum = QUIRK_ANY_INTERFACE, | ||
2089 | .type = QUIRK_AUDIO_ALIGN_TRANSFER, | ||
2090 | } | ||
2091 | }, | ||
2092 | { | ||
2093 | USB_DEVICE_VENDOR_SPEC(0x2040, 0x7201), | ||
2094 | .match_flags = USB_DEVICE_ID_MATCH_DEVICE | | ||
2095 | USB_DEVICE_ID_MATCH_INT_CLASS | | ||
2096 | USB_DEVICE_ID_MATCH_INT_SUBCLASS, | ||
2097 | .bInterfaceClass = USB_CLASS_AUDIO, | ||
2098 | .bInterfaceSubClass = USB_SUBCLASS_AUDIO_CONTROL, | ||
2099 | .driver_info = (unsigned long) &(const struct snd_usb_audio_quirk) { | ||
2100 | .vendor_name = "Hauppauge", | ||
2101 | .product_name = "HVR-950Q", | ||
2102 | .ifnum = QUIRK_ANY_INTERFACE, | ||
2103 | .type = QUIRK_AUDIO_ALIGN_TRANSFER, | ||
2104 | } | ||
2105 | }, | ||
2106 | { | ||
2107 | USB_DEVICE_VENDOR_SPEC(0x2040, 0x7202), | ||
2108 | .match_flags = USB_DEVICE_ID_MATCH_DEVICE | | ||
2109 | USB_DEVICE_ID_MATCH_INT_CLASS | | ||
2110 | USB_DEVICE_ID_MATCH_INT_SUBCLASS, | ||
2111 | .bInterfaceClass = USB_CLASS_AUDIO, | ||
2112 | .bInterfaceSubClass = USB_SUBCLASS_AUDIO_CONTROL, | ||
2113 | .driver_info = (unsigned long) &(const struct snd_usb_audio_quirk) { | ||
2114 | .vendor_name = "Hauppauge", | ||
2115 | .product_name = "HVR-950Q", | ||
2116 | .ifnum = QUIRK_ANY_INTERFACE, | ||
2117 | .type = QUIRK_AUDIO_ALIGN_TRANSFER, | ||
2118 | } | ||
2119 | }, | ||
2120 | { | ||
2121 | USB_DEVICE_VENDOR_SPEC(0x2040, 0x7203), | ||
2122 | .match_flags = USB_DEVICE_ID_MATCH_DEVICE | | ||
2123 | USB_DEVICE_ID_MATCH_INT_CLASS | | ||
2124 | USB_DEVICE_ID_MATCH_INT_SUBCLASS, | ||
2125 | .bInterfaceClass = USB_CLASS_AUDIO, | ||
2126 | .bInterfaceSubClass = USB_SUBCLASS_AUDIO_CONTROL, | ||
2127 | .driver_info = (unsigned long) &(const struct snd_usb_audio_quirk) { | ||
2128 | .vendor_name = "Hauppauge", | ||
2129 | .product_name = "HVR-950Q", | ||
2130 | .ifnum = QUIRK_ANY_INTERFACE, | ||
2131 | .type = QUIRK_AUDIO_ALIGN_TRANSFER, | ||
2132 | } | ||
2133 | }, | ||
2134 | { | ||
2135 | USB_DEVICE_VENDOR_SPEC(0x2040, 0x7204), | ||
2136 | .match_flags = USB_DEVICE_ID_MATCH_DEVICE | | ||
2137 | USB_DEVICE_ID_MATCH_INT_CLASS | | ||
2138 | USB_DEVICE_ID_MATCH_INT_SUBCLASS, | ||
2139 | .bInterfaceClass = USB_CLASS_AUDIO, | ||
2140 | .bInterfaceSubClass = USB_SUBCLASS_AUDIO_CONTROL, | ||
2141 | .driver_info = (unsigned long) &(const struct snd_usb_audio_quirk) { | ||
2142 | .vendor_name = "Hauppauge", | ||
2143 | .product_name = "HVR-950Q", | ||
2144 | .ifnum = QUIRK_ANY_INTERFACE, | ||
2145 | .type = QUIRK_AUDIO_ALIGN_TRANSFER, | ||
2146 | } | ||
2147 | }, | ||
2148 | { | ||
2149 | USB_DEVICE_VENDOR_SPEC(0x2040, 0x7205), | ||
2150 | .match_flags = USB_DEVICE_ID_MATCH_DEVICE | | ||
2151 | USB_DEVICE_ID_MATCH_INT_CLASS | | ||
2152 | USB_DEVICE_ID_MATCH_INT_SUBCLASS, | ||
2153 | .bInterfaceClass = USB_CLASS_AUDIO, | ||
2154 | .bInterfaceSubClass = USB_SUBCLASS_AUDIO_CONTROL, | ||
2155 | .driver_info = (unsigned long) &(const struct snd_usb_audio_quirk) { | ||
2156 | .vendor_name = "Hauppauge", | ||
2157 | .product_name = "HVR-950Q", | ||
2158 | .ifnum = QUIRK_ANY_INTERFACE, | ||
2159 | .type = QUIRK_AUDIO_ALIGN_TRANSFER, | ||
2160 | } | ||
2161 | }, | ||
2162 | { | ||
2163 | USB_DEVICE_VENDOR_SPEC(0x2040, 0x7250), | ||
2164 | .match_flags = USB_DEVICE_ID_MATCH_DEVICE | | ||
2165 | USB_DEVICE_ID_MATCH_INT_CLASS | | ||
2166 | USB_DEVICE_ID_MATCH_INT_SUBCLASS, | ||
2167 | .bInterfaceClass = USB_CLASS_AUDIO, | ||
2168 | .bInterfaceSubClass = USB_SUBCLASS_AUDIO_CONTROL, | ||
2169 | .driver_info = (unsigned long) &(const struct snd_usb_audio_quirk) { | ||
2170 | .vendor_name = "Hauppauge", | ||
2171 | .product_name = "HVR-950Q", | ||
2172 | .ifnum = QUIRK_ANY_INTERFACE, | ||
2173 | .type = QUIRK_AUDIO_ALIGN_TRANSFER, | ||
2174 | } | ||
2175 | }, | ||
2176 | { | ||
2177 | USB_DEVICE_VENDOR_SPEC(0x2040, 0x7230), | ||
2178 | .match_flags = USB_DEVICE_ID_MATCH_DEVICE | | ||
2179 | USB_DEVICE_ID_MATCH_INT_CLASS | | ||
2180 | USB_DEVICE_ID_MATCH_INT_SUBCLASS, | ||
2181 | .bInterfaceClass = USB_CLASS_AUDIO, | ||
2182 | .bInterfaceSubClass = USB_SUBCLASS_AUDIO_CONTROL, | ||
2183 | .driver_info = (unsigned long) &(const struct snd_usb_audio_quirk) { | ||
2184 | .vendor_name = "Hauppauge", | ||
2185 | .product_name = "HVR-850", | ||
2186 | .ifnum = QUIRK_ANY_INTERFACE, | ||
2187 | .type = QUIRK_AUDIO_ALIGN_TRANSFER, | ||
2188 | } | ||
2189 | }, | ||
2190 | |||
2108 | { | 2191 | { |
2109 | /* | 2192 | /* |
2110 | * Some USB MIDI devices don't have an audio control interface, | 2193 | * Some USB MIDI devices don't have an audio control interface, |