2 * Edirol UA-101/UA-1000 driver
3 * Copyright (c) Clemens Ladisch <clemens@ladisch.de>
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.
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.
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/>.
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>
28 MODULE_DESCRIPTION("Edirol UA-101/1000 driver");
29 MODULE_AUTHOR("Clemens Ladisch <clemens@ladisch.de>");
30 MODULE_LICENSE("GPL v2");
31 MODULE_SUPPORTED_DEVICE("{{Edirol,UA-101},{Edirol,UA-1000}}");
33 /* I use my UA-1A for testing because I don't have a UA-101 ... */
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.
41 #define MIN_QUEUE_LENGTH 12
42 /* Somewhat random. */
43 #define MAX_QUEUE_LENGTH 30
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.
49 #define DEFAULT_QUEUE_LENGTH 21
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)
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;
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
));
78 /* bits in struct ua101::states */
85 ALSA_PLAYBACK_RUNNING
,
86 CAPTURE_URB_COMPLETED
,
87 PLAYBACK_URB_COMPLETED
,
92 struct usb_device
*dev
;
93 struct snd_card
*card
;
94 struct usb_interface
*intf
[INTF_COUNT
];
97 struct list_head midi_list
;
100 unsigned int packets_per_second
;
103 unsigned long states
;
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
];
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
;
126 struct usb_iso_packet_descriptor iso_frame_desc
[1];
127 struct list_head ready_list
;
128 } *urbs
[MAX_QUEUE_LENGTH
];
133 } buffers
[MAX_MEMORY_BUFFERS
];
136 unsigned int fps
[10];
137 unsigned int frame_counter
;
140 static DEFINE_MUTEX(devices_mutex
);
141 static unsigned int devices_used
;
142 static struct usb_driver ua101_driver
;
144 static void abort_alsa_playback(struct ua101
*ua
);
145 static void abort_alsa_capture(struct ua101
*ua
);
147 static const char *usb_error_string(int err
)
153 return "endpoint not enabled";
155 return "endpoint stalled";
157 return "not enough bandwidth";
159 return "device disabled";
161 return "device suspended";
166 return "internal error";
168 return "unknown error";
172 static void abort_usb_capture(struct ua101
*ua
)
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
);
180 static void abort_usb_playback(struct ua101
*ua
)
182 if (test_and_clear_bit(USB_PLAYBACK_RUNNING
, &ua
->states
))
183 wake_up(&ua
->alsa_playback_wait
);
186 static void playback_urb_complete(struct urb
*usb_urb
)
188 struct ua101_urb
*urb
= (struct ua101_urb
*)usb_urb
;
189 struct ua101
*ua
= urb
->urb
.context
;
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
);
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
);
214 static void first_playback_urb_complete(struct urb
*urb
)
216 struct ua101
*ua
= urb
->context
;
218 urb
->complete
= playback_urb_complete
;
219 playback_urb_complete(urb
);
221 set_bit(PLAYBACK_URB_COMPLETED
, &ua
->states
);
222 wake_up(&ua
->alsa_playback_wait
);
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
,
229 struct snd_pcm_runtime
*runtime
;
230 unsigned int frame_bytes
, frames1
;
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
);
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
);
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
;
257 static inline void add_with_wraparound(struct ua101
*ua
,
258 unsigned int *value
, unsigned int add
)
261 if (*value
>= ua
->playback
.queue_length
)
262 *value
-= ua
->playback
.queue_length
;
265 static void playback_tasklet(unsigned long data
)
267 struct ua101
*ua
= (void *)data
;
270 struct ua101_urb
*urb
;
271 bool do_period_elapsed
= false;
274 if (unlikely(!test_bit(USB_PLAYBACK_RUNNING
, &ua
->states
)))
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
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
--;
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
);
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
,
309 memset(urb
->urb
.transfer_buffer
, 0,
310 urb
->urb
.iso_frame_desc
[0].length
);
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
));
322 ua
->playback
.substream
->runtime
->delay
+= frames
;
324 spin_unlock_irqrestore(&ua
->lock
, flags
);
325 if (do_period_elapsed
)
326 snd_pcm_period_elapsed(ua
->playback
.substream
);
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
,
333 struct snd_pcm_runtime
*runtime
;
334 unsigned int frame_bytes
, frames1
;
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
);
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
);
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
;
362 static void capture_urb_complete(struct urb
*urb
)
364 struct ua101
*ua
= urb
->context
;
365 struct ua101_stream
*stream
= &ua
->capture
;
367 unsigned int frames
, write_ptr
;
368 bool do_period_elapsed
;
371 if (unlikely(urb
->status
== -ENOENT
|| /* unlinked */
372 urb
->status
== -ENODEV
|| /* device removed */
373 urb
->status
== -ECONNRESET
|| /* unlinked */
374 urb
->status
== -ESHUTDOWN
)) /* device disabled */
377 if (urb
->status
>= 0 && urb
->iso_frame_desc
[0].status
>= 0)
378 frames
= urb
->iso_frame_desc
[0].actual_length
/
383 spin_lock_irqsave(&ua
->lock
, flags
);
385 if (frames
> 0 && test_bit(ALSA_CAPTURE_RUNNING
, &ua
->states
))
386 do_period_elapsed
= copy_capture_data(stream
, urb
, frames
);
388 do_period_elapsed
= false;
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
));
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
);
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.
415 add_with_wraparound(ua
, &ua
->rate_feedback_start
, 1);
417 if (test_bit(USB_PLAYBACK_RUNNING
, &ua
->states
) &&
418 !list_empty(&ua
->ready_playback_urbs
))
419 tasklet_schedule(&ua
->playback_tasklet
);
422 spin_unlock_irqrestore(&ua
->lock
, flags
);
424 if (do_period_elapsed
)
425 snd_pcm_period_elapsed(stream
->substream
);
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;
440 abort_usb_playback(ua
);
441 abort_usb_capture(ua
);
442 abort_alsa_playback(ua
);
443 abort_alsa_capture(ua
);
446 static void first_capture_urb_complete(struct urb
*urb
)
448 struct ua101
*ua
= urb
->context
;
450 urb
->complete
= capture_urb_complete
;
451 capture_urb_complete(urb
);
453 set_bit(CAPTURE_URB_COMPLETED
, &ua
->states
);
454 wake_up(&ua
->alsa_capture_wait
);
457 static int submit_stream_urbs(struct ua101
*ua
, struct ua101_stream
*stream
)
461 for (i
= 0; i
< stream
->queue_length
; ++i
) {
462 int err
= usb_submit_urb(&stream
->urbs
[i
]->urb
, GFP_KERNEL
);
464 dev_err(&ua
->dev
->dev
, "USB request error %d: %s\n",
465 err
, usb_error_string(err
));
472 static void kill_stream_urbs(struct ua101_stream
*stream
)
476 for (i
= 0; i
< stream
->queue_length
; ++i
)
477 usb_kill_urb(&stream
->urbs
[i
]->urb
);
480 static int enable_iso_interface(struct ua101
*ua
, unsigned int intf_index
)
482 struct usb_host_interface
*alts
;
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);
489 dev_err(&ua
->dev
->dev
,
490 "cannot initialize interface; error %d: %s\n",
491 err
, usb_error_string(err
));
498 static void disable_iso_interface(struct ua101
*ua
, unsigned int intf_index
)
500 struct usb_host_interface
*alts
;
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
));
513 static void stop_usb_capture(struct ua101
*ua
)
515 clear_bit(USB_CAPTURE_RUNNING
, &ua
->states
);
517 kill_stream_urbs(&ua
->capture
);
519 disable_iso_interface(ua
, INTF_CAPTURE
);
522 static int start_usb_capture(struct ua101
*ua
)
526 if (test_bit(DISCONNECTED
, &ua
->states
))
529 if (test_bit(USB_CAPTURE_RUNNING
, &ua
->states
))
532 kill_stream_urbs(&ua
->capture
);
534 err
= enable_iso_interface(ua
, INTF_CAPTURE
);
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;
543 set_bit(USB_CAPTURE_RUNNING
, &ua
->states
);
544 err
= submit_stream_urbs(ua
, &ua
->capture
);
546 stop_usb_capture(ua
);
550 static void stop_usb_playback(struct ua101
*ua
)
552 clear_bit(USB_PLAYBACK_RUNNING
, &ua
->states
);
554 kill_stream_urbs(&ua
->playback
);
556 tasklet_kill(&ua
->playback_tasklet
);
558 disable_iso_interface(ua
, INTF_PLAYBACK
);
561 static int start_usb_playback(struct ua101
*ua
)
563 unsigned int i
, frames
;
567 if (test_bit(DISCONNECTED
, &ua
->states
))
570 if (test_bit(USB_PLAYBACK_RUNNING
, &ua
->states
))
573 kill_stream_urbs(&ua
->playback
);
574 tasklet_kill(&ua
->playback_tasklet
);
576 err
= enable_iso_interface(ua
, INTF_PLAYBACK
);
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
);
588 * We submit the initial URBs all at once, so we have to wait for the
589 * packet size FIFO to be full.
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
);
599 if (!test_bit(USB_CAPTURE_RUNNING
, &ua
->states
)) {
600 stop_usb_playback(ua
);
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
);
618 set_bit(USB_PLAYBACK_RUNNING
, &ua
->states
);
619 err
= submit_stream_urbs(ua
, &ua
->playback
);
621 stop_usb_playback(ua
);
625 static void abort_alsa_capture(struct ua101
*ua
)
627 if (test_bit(ALSA_CAPTURE_RUNNING
, &ua
->states
))
628 snd_pcm_stop(ua
->capture
.substream
, SNDRV_PCM_STATE_XRUN
);
631 static void abort_alsa_playback(struct ua101
*ua
)
633 if (test_bit(ALSA_PLAYBACK_RUNNING
, &ua
->states
))
634 snd_pcm_stop(ua
->playback
.substream
, SNDRV_PCM_STATE_XRUN
);
637 static int set_stream_hw(struct ua101
*ua
, struct snd_pcm_substream
*substream
,
638 unsigned int channels
)
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
,
666 err
= snd_pcm_hw_constraint_msbits(substream
->runtime
, 0, 32, 24);
670 static int capture_pcm_open(struct snd_pcm_substream
*substream
)
672 struct ua101
*ua
= substream
->private_data
;
675 ua
->capture
.substream
= substream
;
676 err
= set_stream_hw(ua
, substream
, ua
->capture
.channels
);
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
;
683 mutex_lock(&ua
->mutex
);
684 err
= start_usb_capture(ua
);
686 set_bit(ALSA_CAPTURE_OPEN
, &ua
->states
);
687 mutex_unlock(&ua
->mutex
);
691 static int playback_pcm_open(struct snd_pcm_substream
*substream
)
693 struct ua101
*ua
= substream
->private_data
;
696 ua
->playback
.substream
= substream
;
697 err
= set_stream_hw(ua
, substream
, ua
->playback
.channels
);
700 substream
->runtime
->hw
.fifo_size
=
701 DIV_ROUND_CLOSEST(ua
->rate
* ua
->playback
.queue_length
,
702 ua
->packets_per_second
);
704 mutex_lock(&ua
->mutex
);
705 err
= start_usb_capture(ua
);
708 err
= start_usb_playback(ua
);
710 if (!test_bit(ALSA_CAPTURE_OPEN
, &ua
->states
))
711 stop_usb_capture(ua
);
714 set_bit(ALSA_PLAYBACK_OPEN
, &ua
->states
);
716 mutex_unlock(&ua
->mutex
);
720 static int capture_pcm_close(struct snd_pcm_substream
*substream
)
722 struct ua101
*ua
= substream
->private_data
;
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
);
732 static int playback_pcm_close(struct snd_pcm_substream
*substream
)
734 struct ua101
*ua
= substream
->private_data
;
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
);
745 static int capture_pcm_hw_params(struct snd_pcm_substream
*substream
,
746 struct snd_pcm_hw_params
*hw_params
)
748 struct ua101
*ua
= substream
->private_data
;
751 mutex_lock(&ua
->mutex
);
752 err
= start_usb_capture(ua
);
753 mutex_unlock(&ua
->mutex
);
757 return snd_pcm_lib_alloc_vmalloc_buffer(substream
,
758 params_buffer_bytes(hw_params
));
761 static int playback_pcm_hw_params(struct snd_pcm_substream
*substream
,
762 struct snd_pcm_hw_params
*hw_params
)
764 struct ua101
*ua
= substream
->private_data
;
767 mutex_lock(&ua
->mutex
);
768 err
= start_usb_capture(ua
);
770 err
= start_usb_playback(ua
);
771 mutex_unlock(&ua
->mutex
);
775 return snd_pcm_lib_alloc_vmalloc_buffer(substream
,
776 params_buffer_bytes(hw_params
));
779 static int ua101_pcm_hw_free(struct snd_pcm_substream
*substream
)
781 return snd_pcm_lib_free_vmalloc_buffer(substream
);
784 static int capture_pcm_prepare(struct snd_pcm_substream
*substream
)
786 struct ua101
*ua
= substream
->private_data
;
789 mutex_lock(&ua
->mutex
);
790 err
= start_usb_capture(ua
);
791 mutex_unlock(&ua
->mutex
);
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.
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
))
806 if (!test_bit(USB_CAPTURE_RUNNING
, &ua
->states
))
809 ua
->capture
.period_pos
= 0;
810 ua
->capture
.buffer_pos
= 0;
814 static int playback_pcm_prepare(struct snd_pcm_substream
*substream
)
816 struct ua101
*ua
= substream
->private_data
;
819 mutex_lock(&ua
->mutex
);
820 err
= start_usb_capture(ua
);
822 err
= start_usb_playback(ua
);
823 mutex_unlock(&ua
->mutex
);
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
))
833 if (!test_bit(USB_PLAYBACK_RUNNING
, &ua
->states
))
836 substream
->runtime
->delay
= 0;
837 ua
->playback
.period_pos
= 0;
838 ua
->playback
.buffer_pos
= 0;
842 static int capture_pcm_trigger(struct snd_pcm_substream
*substream
, int cmd
)
844 struct ua101
*ua
= substream
->private_data
;
847 case SNDRV_PCM_TRIGGER_START
:
848 if (!test_bit(USB_CAPTURE_RUNNING
, &ua
->states
))
850 set_bit(ALSA_CAPTURE_RUNNING
, &ua
->states
);
852 case SNDRV_PCM_TRIGGER_STOP
:
853 clear_bit(ALSA_CAPTURE_RUNNING
, &ua
->states
);
860 static int playback_pcm_trigger(struct snd_pcm_substream
*substream
, int cmd
)
862 struct ua101
*ua
= substream
->private_data
;
865 case SNDRV_PCM_TRIGGER_START
:
866 if (!test_bit(USB_PLAYBACK_RUNNING
, &ua
->states
))
868 set_bit(ALSA_PLAYBACK_RUNNING
, &ua
->states
);
870 case SNDRV_PCM_TRIGGER_STOP
:
871 clear_bit(ALSA_PLAYBACK_RUNNING
, &ua
->states
);
878 static inline snd_pcm_uframes_t
ua101_pcm_pointer(struct ua101
*ua
,
879 struct ua101_stream
*stream
)
884 spin_lock_irqsave(&ua
->lock
, flags
);
885 pos
= stream
->buffer_pos
;
886 spin_unlock_irqrestore(&ua
->lock
, flags
);
890 static snd_pcm_uframes_t
capture_pcm_pointer(struct snd_pcm_substream
*subs
)
892 struct ua101
*ua
= subs
->private_data
;
894 return ua101_pcm_pointer(ua
, &ua
->capture
);
897 static snd_pcm_uframes_t
playback_pcm_pointer(struct snd_pcm_substream
*subs
)
899 struct ua101
*ua
= subs
->private_data
;
901 return ua101_pcm_pointer(ua
, &ua
->playback
);
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
,
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
,
930 static const struct uac_format_type_i_discrete_descriptor
*
931 find_format_descriptor(struct usb_interface
*interface
)
933 struct usb_host_interface
*alt
;
937 if (interface
->num_altsetting
!= 2) {
938 dev_err(&interface
->dev
, "invalid num_altsetting\n");
942 alt
= &interface
->altsetting
[0];
943 if (alt
->desc
.bNumEndpoints
!= 0) {
944 dev_err(&interface
->dev
, "invalid bNumEndpoints\n");
948 alt
= &interface
->altsetting
[1];
949 if (alt
->desc
.bNumEndpoints
!= 1) {
950 dev_err(&interface
->dev
, "invalid bNumEndpoints\n");
955 extralen
= alt
->extralen
;
956 while (extralen
>= sizeof(struct usb_descriptor_header
)) {
957 struct uac_format_type_i_discrete_descriptor
*desc
;
959 desc
= (struct uac_format_type_i_discrete_descriptor
*)extra
;
960 if (desc
->bLength
> extralen
) {
961 dev_err(&interface
->dev
, "descriptor overflow\n");
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");
975 extralen
-= desc
->bLength
;
976 extra
+= desc
->bLength
;
978 dev_err(&interface
->dev
, "sample format descriptor not found\n");
982 static int detect_usb_format(struct ua101
*ua
)
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
;
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
)
994 switch (fmt_capture
->bSubframeSize
) {
996 ua
->format_bit
= SNDRV_PCM_FMTBIT_S24_3LE
;
999 ua
->format_bit
= SNDRV_PCM_FMTBIT_S32_LE
;
1002 dev_err(&ua
->dev
->dev
, "sample width is not 24 or 32 bits\n");
1005 if (fmt_capture
->bSubframeSize
!= fmt_playback
->bSubframeSize
) {
1006 dev_err(&ua
->dev
->dev
,
1007 "playback/capture sample widths do not match\n");
1011 if (fmt_capture
->bBitResolution
!= 24 ||
1012 fmt_playback
->bBitResolution
!= 24) {
1013 dev_err(&ua
->dev
->dev
, "sample width is not 24 bits\n");
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",
1026 switch (ua
->dev
->speed
) {
1027 case USB_SPEED_FULL
:
1028 ua
->packets_per_second
= 1000;
1030 case USB_SPEED_HIGH
:
1031 ua
->packets_per_second
= 8000;
1034 dev_err(&ua
->dev
->dev
, "unknown device speed\n");
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
;
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");
1050 ua
->capture
.usb_pipe
= usb_rcvisocpipe(ua
->dev
, usb_endpoint_num(epd
));
1051 ua
->capture
.max_packet_bytes
= le16_to_cpu(epd
->wMaxPacketSize
);
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");
1058 ua
->playback
.usb_pipe
= usb_sndisocpipe(ua
->dev
, usb_endpoint_num(epd
));
1059 ua
->playback
.max_packet_bytes
= le16_to_cpu(epd
->wMaxPacketSize
);
1063 static int alloc_stream_buffers(struct ua101
*ua
, struct ua101_stream
*stream
)
1065 unsigned int remaining_packets
, packets
, packets_per_page
, i
;
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
);
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.
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
)
1090 stream
->buffers
[i
].size
= size
;
1091 remaining_packets
-= packets
;
1092 if (!remaining_packets
)
1095 if (remaining_packets
) {
1096 dev_err(&ua
->dev
->dev
, "too many packets\n");
1102 static void free_stream_buffers(struct ua101
*ua
, struct ua101_stream
*stream
)
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
);
1113 static int alloc_stream_urbs(struct ua101
*ua
, struct ua101_stream
*stream
,
1114 void (*urb_complete
)(struct urb
*))
1116 unsigned max_packet_size
= stream
->max_packet_bytes
;
1117 struct ua101_urb
*urb
;
1118 unsigned int b
, u
= 0;
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
;
1125 while (size
>= max_packet_size
) {
1126 if (u
>= stream
->queue_length
)
1128 urb
= kmalloc(sizeof(*urb
), GFP_KERNEL
);
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
;
1151 if (u
== stream
->queue_length
)
1154 dev_err(&ua
->dev
->dev
, "internal buffer size error\n");
1158 static void free_stream_urbs(struct ua101_stream
*stream
)
1162 for (i
= 0; i
< stream
->queue_length
; ++i
)
1163 kfree(stream
->urbs
[i
]);
1166 static void free_usb_related_resources(struct ua101
*ua
,
1167 struct usb_interface
*interface
)
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
);
1176 for (i
= 0; i
< ARRAY_SIZE(ua
->intf
); ++i
)
1178 usb_set_intfdata(ua
->intf
[i
], NULL
);
1179 if (ua
->intf
[i
] != interface
)
1180 usb_driver_release_interface(&ua101_driver
,
1185 static void ua101_card_free(struct snd_card
*card
)
1187 struct ua101
*ua
= card
->private_data
;
1189 mutex_destroy(&ua
->mutex
);
1192 static int ua101_probe(struct usb_interface
*interface
,
1193 const struct usb_device_id
*usb_id
)
1195 static const struct snd_usb_midi_endpoint_info midi_ep
= {
1196 .out_cables
= 0x0001,
1199 static const struct snd_usb_audio_quirk midi_quirk
= {
1200 .type
= QUIRK_MIDI_FIXED_ENDPOINT
,
1203 static const int intf_numbers
[2][3] = {
1205 [INTF_PLAYBACK
] = 0,
1211 [INTF_PLAYBACK
] = 2,
1215 struct snd_card
*card
;
1217 unsigned int card_index
, i
;
1223 is_ua1000
= usb_id
->idProduct
== 0x0044;
1225 if (interface
->altsetting
->desc
.bInterfaceNumber
!=
1226 intf_numbers
[is_ua1000
][0])
1229 mutex_lock(&devices_mutex
);
1231 for (card_index
= 0; card_index
< SNDRV_CARDS
; ++card_index
)
1232 if (enable
[card_index
] && !(devices_used
& (1 << card_index
)))
1234 if (card_index
>= SNDRV_CARDS
) {
1235 mutex_unlock(&devices_mutex
);
1238 err
= snd_card_create(index
[card_index
], id
[card_index
], THIS_MODULE
,
1239 sizeof(*ua
), &card
);
1241 mutex_unlock(&devices_mutex
);
1244 card
->private_free
= ua101_card_free
;
1245 ua
= card
->private_data
;
1246 ua
->dev
= interface_to_usbdev(interface
);
1248 ua
->card_index
= card_index
;
1249 INIT_LIST_HEAD(&ua
->midi_list
);
1250 spin_lock_init(&ua
->lock
);
1251 mutex_init(&ua
->mutex
);
1252 INIT_LIST_HEAD(&ua
->ready_playback_urbs
);
1253 tasklet_init(&ua
->playback_tasklet
,
1254 playback_tasklet
, (unsigned long)ua
);
1255 init_waitqueue_head(&ua
->alsa_capture_wait
);
1256 init_waitqueue_head(&ua
->rate_feedback_wait
);
1257 init_waitqueue_head(&ua
->alsa_playback_wait
);
1260 if (ua
->dev
->descriptor
.idProduct
== cpu_to_le16(0x0018)) {
1261 ua
->intf
[2] = interface
;
1262 ua
->intf
[0] = usb_ifnum_to_if(ua
->dev
, 1);
1263 ua
->intf
[1] = usb_ifnum_to_if(ua
->dev
, 2);
1264 usb_driver_claim_interface(&ua101_driver
, ua
->intf
[0], ua
);
1265 usb_driver_claim_interface(&ua101_driver
, ua
->intf
[1], ua
);
1268 ua
->intf
[0] = interface
;
1269 for (i
= 1; i
< ARRAY_SIZE(ua
->intf
); ++i
) {
1270 ua
->intf
[i
] = usb_ifnum_to_if(ua
->dev
,
1271 intf_numbers
[is_ua1000
][i
]);
1273 dev_err(&ua
->dev
->dev
, "interface %u not found\n",
1274 intf_numbers
[is_ua1000
][i
]);
1278 err
= usb_driver_claim_interface(&ua101_driver
,
1290 snd_card_set_dev(card
, &interface
->dev
);
1293 if (ua
->dev
->descriptor
.idProduct
== cpu_to_le16(0x0018)) {
1294 ua
->format_bit
= SNDRV_PCM_FMTBIT_S16_LE
;
1296 ua
->packets_per_second
= 1000;
1297 ua
->capture
.channels
= 2;
1298 ua
->playback
.channels
= 2;
1299 ua
->capture
.frame_bytes
= 4;
1300 ua
->playback
.frame_bytes
= 4;
1301 ua
->capture
.usb_pipe
= usb_rcvisocpipe(ua
->dev
, 2);
1302 ua
->playback
.usb_pipe
= usb_sndisocpipe(ua
->dev
, 1);
1303 ua
->capture
.max_packet_bytes
= 192;
1304 ua
->playback
.max_packet_bytes
= 192;
1307 err
= detect_usb_format(ua
);
1314 name
= usb_id
->idProduct
== 0x0044 ? "UA-1000" : "UA-101";
1315 strcpy(card
->driver
, "UA-101");
1316 strcpy(card
->shortname
, name
);
1317 usb_make_path(ua
->dev
, usb_path
, sizeof(usb_path
));
1318 snprintf(ua
->card
->longname
, sizeof(ua
->card
->longname
),
1319 "EDIROL %s (serial %s), %u Hz at %s, %s speed", name
,
1320 ua
->dev
->serial
? ua
->dev
->serial
: "?", ua
->rate
, usb_path
,
1321 ua
->dev
->speed
== USB_SPEED_HIGH
? "high" : "full");
1323 err
= alloc_stream_buffers(ua
, &ua
->capture
);
1326 err
= alloc_stream_buffers(ua
, &ua
->playback
);
1330 err
= alloc_stream_urbs(ua
, &ua
->capture
, capture_urb_complete
);
1333 err
= alloc_stream_urbs(ua
, &ua
->playback
, playback_urb_complete
);
1337 err
= snd_pcm_new(card
, name
, 0, 1, 1, &ua
->pcm
);
1340 ua
->pcm
->private_data
= ua
;
1341 strcpy(ua
->pcm
->name
, name
);
1342 snd_pcm_set_ops(ua
->pcm
, SNDRV_PCM_STREAM_PLAYBACK
, &playback_pcm_ops
);
1343 snd_pcm_set_ops(ua
->pcm
, SNDRV_PCM_STREAM_CAPTURE
, &capture_pcm_ops
);
1346 if (ua
->dev
->descriptor
.idProduct
!= cpu_to_le16(0x0018)) {
1348 err
= snd_usbmidi_create(card
, ua
->intf
[INTF_MIDI
],
1349 &ua
->midi_list
, &midi_quirk
);
1356 err
= snd_card_register(card
);
1360 usb_set_intfdata(interface
, ua
);
1361 devices_used
|= 1 << card_index
;
1363 mutex_unlock(&devices_mutex
);
1367 free_usb_related_resources(ua
, interface
);
1368 snd_card_free(card
);
1369 mutex_unlock(&devices_mutex
);
1373 static void ua101_disconnect(struct usb_interface
*interface
)
1375 struct ua101
*ua
= usb_get_intfdata(interface
);
1376 struct list_head
*midi
;
1381 mutex_lock(&devices_mutex
);
1383 set_bit(DISCONNECTED
, &ua
->states
);
1384 wake_up(&ua
->rate_feedback_wait
);
1386 /* make sure that userspace cannot create new requests */
1387 snd_card_disconnect(ua
->card
);
1389 /* make sure that there are no pending USB requests */
1390 __list_for_each(midi
, &ua
->midi_list
)
1391 snd_usbmidi_disconnect(midi
);
1392 abort_alsa_playback(ua
);
1393 abort_alsa_capture(ua
);
1394 mutex_lock(&ua
->mutex
);
1395 stop_usb_playback(ua
);
1396 stop_usb_capture(ua
);
1397 mutex_unlock(&ua
->mutex
);
1399 free_usb_related_resources(ua
, interface
);
1401 devices_used
&= ~(1 << ua
->card_index
);
1403 snd_card_free_when_closed(ua
->card
);
1405 mutex_unlock(&devices_mutex
);
1408 static struct usb_device_id ua101_ids
[] = {
1410 { USB_DEVICE(0x0582, 0x0018) },
1412 { USB_DEVICE(0x0582, 0x0044) }, /* UA-1000 high speed */
1413 { USB_DEVICE(0x0582, 0x007d) }, /* UA-101 high speed */
1414 { USB_DEVICE(0x0582, 0x008d) }, /* UA-101 full speed */
1417 MODULE_DEVICE_TABLE(usb
, ua101_ids
);
1419 static struct usb_driver ua101_driver
= {
1420 .name
= "snd-ua101",
1421 .id_table
= ua101_ids
,
1422 .probe
= ua101_probe
,
1423 .disconnect
= ua101_disconnect
,
1425 .suspend
= ua101_suspend
,
1426 .resume
= ua101_resume
,
1430 static int __init
alsa_card_ua101_init(void)
1432 return usb_register(&ua101_driver
);
1435 static void __exit
alsa_card_ua101_exit(void)
1437 usb_deregister(&ua101_driver
);
1438 mutex_destroy(&devices_mutex
);
1441 module_init(alsa_card_ua101_init
);
1442 module_exit(alsa_card_ua101_exit
);