aboutsummaryrefslogtreecommitdiffstats
path: root/sound/usb
diff options
context:
space:
mode:
Diffstat (limited to 'sound/usb')
-rw-r--r--sound/usb/caiaq/control.c92
-rw-r--r--sound/usb/caiaq/device.c25
-rw-r--r--sound/usb/caiaq/device.h5
-rw-r--r--sound/usb/card.c9
-rw-r--r--sound/usb/card.h12
-rw-r--r--sound/usb/endpoint.c139
-rw-r--r--sound/usb/endpoint.h4
-rw-r--r--sound/usb/helper.c1
-rw-r--r--sound/usb/mixer.c4
-rw-r--r--sound/usb/pcm.c40
-rw-r--r--sound/usb/usbaudio.h1
11 files changed, 228 insertions, 104 deletions
diff --git a/sound/usb/caiaq/control.c b/sound/usb/caiaq/control.c
index ae6b50f9ed56..f65fc0987cfb 100644
--- a/sound/usb/caiaq/control.c
+++ b/sound/usb/caiaq/control.c
@@ -28,6 +28,7 @@
28#include "control.h" 28#include "control.h"
29 29
30#define CNT_INTVAL 0x10000 30#define CNT_INTVAL 0x10000
31#define MASCHINE_BANK_SIZE 32
31 32
32static int control_info(struct snd_kcontrol *kcontrol, 33static int control_info(struct snd_kcontrol *kcontrol,
33 struct snd_ctl_elem_info *uinfo) 34 struct snd_ctl_elem_info *uinfo)
@@ -105,6 +106,10 @@ static int control_put(struct snd_kcontrol *kcontrol,
105 USB_ID(USB_VID_NATIVEINSTRUMENTS, USB_PID_TRAKTORKONTROLX1)) 106 USB_ID(USB_VID_NATIVEINSTRUMENTS, USB_PID_TRAKTORKONTROLX1))
106 cmd = EP1_CMD_DIMM_LEDS; 107 cmd = EP1_CMD_DIMM_LEDS;
107 108
109 if (cdev->chip.usb_id ==
110 USB_ID(USB_VID_NATIVEINSTRUMENTS, USB_PID_MASCHINECONTROLLER))
111 cmd = EP1_CMD_DIMM_LEDS;
112
108 if (pos & CNT_INTVAL) { 113 if (pos & CNT_INTVAL) {
109 int i = pos & ~CNT_INTVAL; 114 int i = pos & ~CNT_INTVAL;
110 115
@@ -121,6 +126,20 @@ static int control_put(struct snd_kcontrol *kcontrol,
121 usb_sndbulkpipe(cdev->chip.dev, 8), 126 usb_sndbulkpipe(cdev->chip.dev, 8),
122 cdev->ep8_out_buf, sizeof(cdev->ep8_out_buf), 127 cdev->ep8_out_buf, sizeof(cdev->ep8_out_buf),
123 &actual_len, 200); 128 &actual_len, 200);
129 } else if (cdev->chip.usb_id ==
130 USB_ID(USB_VID_NATIVEINSTRUMENTS, USB_PID_MASCHINECONTROLLER)) {
131
132 int bank = 0;
133 int offset = 0;
134
135 if (i >= MASCHINE_BANK_SIZE) {
136 bank = 0x1e;
137 offset = MASCHINE_BANK_SIZE;
138 }
139
140 snd_usb_caiaq_send_command_bank(cdev, cmd, bank,
141 cdev->control_state + offset,
142 MASCHINE_BANK_SIZE);
124 } else { 143 } else {
125 snd_usb_caiaq_send_command(cdev, cmd, 144 snd_usb_caiaq_send_command(cdev, cmd,
126 cdev->control_state, sizeof(cdev->control_state)); 145 cdev->control_state, sizeof(cdev->control_state));
@@ -490,6 +509,74 @@ static struct caiaq_controller kontrols4_controller[] = {
490 { "LED: FX2: Mode", 133 | CNT_INTVAL }, 509 { "LED: FX2: Mode", 133 | CNT_INTVAL },
491}; 510};
492 511
512static struct caiaq_controller maschine_controller[] = {
513 { "LED: Pad 1", 3 | CNT_INTVAL },
514 { "LED: Pad 2", 2 | CNT_INTVAL },
515 { "LED: Pad 3", 1 | CNT_INTVAL },
516 { "LED: Pad 4", 0 | CNT_INTVAL },
517 { "LED: Pad 5", 7 | CNT_INTVAL },
518 { "LED: Pad 6", 6 | CNT_INTVAL },
519 { "LED: Pad 7", 5 | CNT_INTVAL },
520 { "LED: Pad 8", 4 | CNT_INTVAL },
521 { "LED: Pad 9", 11 | CNT_INTVAL },
522 { "LED: Pad 10", 10 | CNT_INTVAL },
523 { "LED: Pad 11", 9 | CNT_INTVAL },
524 { "LED: Pad 12", 8 | CNT_INTVAL },
525 { "LED: Pad 13", 15 | CNT_INTVAL },
526 { "LED: Pad 14", 14 | CNT_INTVAL },
527 { "LED: Pad 15", 13 | CNT_INTVAL },
528 { "LED: Pad 16", 12 | CNT_INTVAL },
529
530 { "LED: Mute", 16 | CNT_INTVAL },
531 { "LED: Solo", 17 | CNT_INTVAL },
532 { "LED: Select", 18 | CNT_INTVAL },
533 { "LED: Duplicate", 19 | CNT_INTVAL },
534 { "LED: Navigate", 20 | CNT_INTVAL },
535 { "LED: Pad Mode", 21 | CNT_INTVAL },
536 { "LED: Pattern", 22 | CNT_INTVAL },
537 { "LED: Scene", 23 | CNT_INTVAL },
538
539 { "LED: Shift", 24 | CNT_INTVAL },
540 { "LED: Erase", 25 | CNT_INTVAL },
541 { "LED: Grid", 26 | CNT_INTVAL },
542 { "LED: Right Bottom", 27 | CNT_INTVAL },
543 { "LED: Rec", 28 | CNT_INTVAL },
544 { "LED: Play", 29 | CNT_INTVAL },
545 { "LED: Left Bottom", 32 | CNT_INTVAL },
546 { "LED: Restart", 33 | CNT_INTVAL },
547
548 { "LED: Group A", 41 | CNT_INTVAL },
549 { "LED: Group B", 40 | CNT_INTVAL },
550 { "LED: Group C", 37 | CNT_INTVAL },
551 { "LED: Group D", 36 | CNT_INTVAL },
552 { "LED: Group E", 39 | CNT_INTVAL },
553 { "LED: Group F", 38 | CNT_INTVAL },
554 { "LED: Group G", 35 | CNT_INTVAL },
555 { "LED: Group H", 34 | CNT_INTVAL },
556
557 { "LED: Auto Write", 42 | CNT_INTVAL },
558 { "LED: Snap", 43 | CNT_INTVAL },
559 { "LED: Right Top", 44 | CNT_INTVAL },
560 { "LED: Left Top", 45 | CNT_INTVAL },
561 { "LED: Sampling", 46 | CNT_INTVAL },
562 { "LED: Browse", 47 | CNT_INTVAL },
563 { "LED: Step", 48 | CNT_INTVAL },
564 { "LED: Control", 49 | CNT_INTVAL },
565
566 { "LED: Top Button 1", 57 | CNT_INTVAL },
567 { "LED: Top Button 2", 56 | CNT_INTVAL },
568 { "LED: Top Button 3", 55 | CNT_INTVAL },
569 { "LED: Top Button 4", 54 | CNT_INTVAL },
570 { "LED: Top Button 5", 53 | CNT_INTVAL },
571 { "LED: Top Button 6", 52 | CNT_INTVAL },
572 { "LED: Top Button 7", 51 | CNT_INTVAL },
573 { "LED: Top Button 8", 50 | CNT_INTVAL },
574
575 { "LED: Note Repeat", 58 | CNT_INTVAL },
576
577 { "Backlight Display", 59 | CNT_INTVAL }
578};
579
493static int add_controls(struct caiaq_controller *c, int num, 580static int add_controls(struct caiaq_controller *c, int num,
494 struct snd_usb_caiaqdev *cdev) 581 struct snd_usb_caiaqdev *cdev)
495{ 582{
@@ -553,6 +640,11 @@ int snd_usb_caiaq_control_init(struct snd_usb_caiaqdev *cdev)
553 ret = add_controls(kontrols4_controller, 640 ret = add_controls(kontrols4_controller,
554 ARRAY_SIZE(kontrols4_controller), cdev); 641 ARRAY_SIZE(kontrols4_controller), cdev);
555 break; 642 break;
643
644 case USB_ID(USB_VID_NATIVEINSTRUMENTS, USB_PID_MASCHINECONTROLLER):
645 ret = add_controls(maschine_controller,
646 ARRAY_SIZE(maschine_controller), cdev);
647 break;
556 } 648 }
557 649
558 return ret; 650 return ret;
diff --git a/sound/usb/caiaq/device.c b/sound/usb/caiaq/device.c
index 1a61dd12fe38..bc55f708a696 100644
--- a/sound/usb/caiaq/device.c
+++ b/sound/usb/caiaq/device.c
@@ -235,6 +235,31 @@ int snd_usb_caiaq_send_command(struct snd_usb_caiaqdev *cdev,
235 cdev->ep1_out_buf, len+1, &actual_len, 200); 235 cdev->ep1_out_buf, len+1, &actual_len, 200);
236} 236}
237 237
238int snd_usb_caiaq_send_command_bank(struct snd_usb_caiaqdev *cdev,
239 unsigned char command,
240 unsigned char bank,
241 const unsigned char *buffer,
242 int len)
243{
244 int actual_len;
245 struct usb_device *usb_dev = cdev->chip.dev;
246
247 if (!usb_dev)
248 return -EIO;
249
250 if (len > EP1_BUFSIZE - 2)
251 len = EP1_BUFSIZE - 2;
252
253 if (buffer && len > 0)
254 memcpy(cdev->ep1_out_buf+2, buffer, len);
255
256 cdev->ep1_out_buf[0] = command;
257 cdev->ep1_out_buf[1] = bank;
258
259 return usb_bulk_msg(usb_dev, usb_sndbulkpipe(usb_dev, 1),
260 cdev->ep1_out_buf, len+2, &actual_len, 200);
261}
262
238int snd_usb_caiaq_set_audio_params (struct snd_usb_caiaqdev *cdev, 263int snd_usb_caiaq_set_audio_params (struct snd_usb_caiaqdev *cdev,
239 int rate, int depth, int bpp) 264 int rate, int depth, int bpp)
240{ 265{
diff --git a/sound/usb/caiaq/device.h b/sound/usb/caiaq/device.h
index ad102fac6942..ab0f7520a99b 100644
--- a/sound/usb/caiaq/device.h
+++ b/sound/usb/caiaq/device.h
@@ -128,5 +128,10 @@ int snd_usb_caiaq_send_command(struct snd_usb_caiaqdev *cdev,
128 unsigned char command, 128 unsigned char command,
129 const unsigned char *buffer, 129 const unsigned char *buffer,
130 int len); 130 int len);
131int snd_usb_caiaq_send_command_bank(struct snd_usb_caiaqdev *cdev,
132 unsigned char command,
133 unsigned char bank,
134 const unsigned char *buffer,
135 int len);
131 136
132#endif /* CAIAQ_DEVICE_H */ 137#endif /* CAIAQ_DEVICE_H */
diff --git a/sound/usb/card.c b/sound/usb/card.c
index 64952e2d3ed1..9d9de8d53469 100644
--- a/sound/usb/card.c
+++ b/sound/usb/card.c
@@ -79,7 +79,6 @@ static bool enable[SNDRV_CARDS] = SNDRV_DEFAULT_ENABLE_PNP;/* Enable this card *
79/* Vendor/product IDs for this card */ 79/* Vendor/product IDs for this card */
80static int vid[SNDRV_CARDS] = { [0 ... (SNDRV_CARDS-1)] = -1 }; 80static int vid[SNDRV_CARDS] = { [0 ... (SNDRV_CARDS-1)] = -1 };
81static int pid[SNDRV_CARDS] = { [0 ... (SNDRV_CARDS-1)] = -1 }; 81static int pid[SNDRV_CARDS] = { [0 ... (SNDRV_CARDS-1)] = -1 };
82static int nrpacks = 8; /* max. number of packets per urb */
83static int device_setup[SNDRV_CARDS]; /* device parameter for this card */ 82static int device_setup[SNDRV_CARDS]; /* device parameter for this card */
84static bool ignore_ctl_error; 83static bool ignore_ctl_error;
85static bool autoclock = true; 84static bool autoclock = true;
@@ -94,8 +93,6 @@ module_param_array(vid, int, NULL, 0444);
94MODULE_PARM_DESC(vid, "Vendor ID for the USB audio device."); 93MODULE_PARM_DESC(vid, "Vendor ID for the USB audio device.");
95module_param_array(pid, int, NULL, 0444); 94module_param_array(pid, int, NULL, 0444);
96MODULE_PARM_DESC(pid, "Product ID for the USB audio device."); 95MODULE_PARM_DESC(pid, "Product ID for the USB audio device.");
97module_param(nrpacks, int, 0644);
98MODULE_PARM_DESC(nrpacks, "Max. number of packets per URB.");
99module_param_array(device_setup, int, NULL, 0444); 96module_param_array(device_setup, int, NULL, 0444);
100MODULE_PARM_DESC(device_setup, "Specific device setup (if needed)."); 97MODULE_PARM_DESC(device_setup, "Specific device setup (if needed).");
101module_param(ignore_ctl_error, bool, 0444); 98module_param(ignore_ctl_error, bool, 0444);
@@ -349,6 +346,7 @@ static int snd_usb_audio_create(struct usb_device *dev, int idx,
349 case USB_SPEED_LOW: 346 case USB_SPEED_LOW:
350 case USB_SPEED_FULL: 347 case USB_SPEED_FULL:
351 case USB_SPEED_HIGH: 348 case USB_SPEED_HIGH:
349 case USB_SPEED_WIRELESS:
352 case USB_SPEED_SUPER: 350 case USB_SPEED_SUPER:
353 break; 351 break;
354 default: 352 default:
@@ -374,7 +372,6 @@ static int snd_usb_audio_create(struct usb_device *dev, int idx,
374 chip->dev = dev; 372 chip->dev = dev;
375 chip->card = card; 373 chip->card = card;
376 chip->setup = device_setup[idx]; 374 chip->setup = device_setup[idx];
377 chip->nrpacks = nrpacks;
378 chip->autoclock = autoclock; 375 chip->autoclock = autoclock;
379 chip->probing = 1; 376 chip->probing = 1;
380 377
@@ -756,10 +753,6 @@ static struct usb_driver usb_audio_driver = {
756 753
757static int __init snd_usb_audio_init(void) 754static int __init snd_usb_audio_init(void)
758{ 755{
759 if (nrpacks < 1 || nrpacks > MAX_PACKS) {
760 printk(KERN_WARNING "invalid nrpacks value.\n");
761 return -EINVAL;
762 }
763 return usb_register(&usb_audio_driver); 756 return usb_register(&usb_audio_driver);
764} 757}
765 758
diff --git a/sound/usb/card.h b/sound/usb/card.h
index 5ecacaa90b53..9867ab866857 100644
--- a/sound/usb/card.h
+++ b/sound/usb/card.h
@@ -2,11 +2,11 @@
2#define __USBAUDIO_CARD_H 2#define __USBAUDIO_CARD_H
3 3
4#define MAX_NR_RATES 1024 4#define MAX_NR_RATES 1024
5#define MAX_PACKS 20 5#define MAX_PACKS 6 /* per URB */
6#define MAX_PACKS_HS (MAX_PACKS * 8) /* in high speed mode */ 6#define MAX_PACKS_HS (MAX_PACKS * 8) /* in high speed mode */
7#define MAX_URBS 8 7#define MAX_URBS 12
8#define SYNC_URBS 4 /* always four urbs for sync */ 8#define SYNC_URBS 4 /* always four urbs for sync */
9#define MAX_QUEUE 24 /* try not to exceed this queue length, in ms */ 9#define MAX_QUEUE 18 /* try not to exceed this queue length, in ms */
10 10
11struct audioformat { 11struct audioformat {
12 struct list_head list; 12 struct list_head list;
@@ -87,6 +87,7 @@ struct snd_usb_endpoint {
87 unsigned int phase; /* phase accumulator */ 87 unsigned int phase; /* phase accumulator */
88 unsigned int maxpacksize; /* max packet size in bytes */ 88 unsigned int maxpacksize; /* max packet size in bytes */
89 unsigned int maxframesize; /* max packet size in frames */ 89 unsigned int maxframesize; /* max packet size in frames */
90 unsigned int max_urb_frames; /* max URB size in frames */
90 unsigned int curpacksize; /* current packet size in bytes (for capture) */ 91 unsigned int curpacksize; /* current packet size in bytes (for capture) */
91 unsigned int curframesize; /* current packet size in frames (for capture) */ 92 unsigned int curframesize; /* current packet size in frames (for capture) */
92 unsigned int syncmaxsize; /* sync endpoint packet size */ 93 unsigned int syncmaxsize; /* sync endpoint packet size */
@@ -95,7 +96,7 @@ struct snd_usb_endpoint {
95 unsigned int syncinterval; /* P for adaptive mode, 0 otherwise */ 96 unsigned int syncinterval; /* P for adaptive mode, 0 otherwise */
96 unsigned char silence_value; 97 unsigned char silence_value;
97 unsigned int stride; 98 unsigned int stride;
98 int iface, alt_idx; 99 int iface, altsetting;
99 int skip_packets; /* quirks for devices to ignore the first n packets 100 int skip_packets; /* quirks for devices to ignore the first n packets
100 in a stream */ 101 in a stream */
101 102
@@ -116,6 +117,8 @@ struct snd_usb_substream {
116 unsigned int channels_max; /* max channels in the all audiofmts */ 117 unsigned int channels_max; /* max channels in the all audiofmts */
117 unsigned int cur_rate; /* current rate (for hw_params callback) */ 118 unsigned int cur_rate; /* current rate (for hw_params callback) */
118 unsigned int period_bytes; /* current period bytes (for hw_params callback) */ 119 unsigned int period_bytes; /* current period bytes (for hw_params callback) */
120 unsigned int period_frames; /* current frames per period */
121 unsigned int buffer_periods; /* current periods per buffer */
119 unsigned int altset_idx; /* USB data format: index of alternate setting */ 122 unsigned int altset_idx; /* USB data format: index of alternate setting */
120 unsigned int txfr_quirk:1; /* allow sub-frame alignment */ 123 unsigned int txfr_quirk:1; /* allow sub-frame alignment */
121 unsigned int fmt_type; /* USB audio format type (1-3) */ 124 unsigned int fmt_type; /* USB audio format type (1-3) */
@@ -125,6 +128,7 @@ struct snd_usb_substream {
125 128
126 unsigned int hwptr_done; /* processed byte position in the buffer */ 129 unsigned int hwptr_done; /* processed byte position in the buffer */
127 unsigned int transfer_done; /* processed frames since last period update */ 130 unsigned int transfer_done; /* processed frames since last period update */
131 unsigned int frame_limit; /* limits number of packets in URB */
128 132
129 /* data and sync endpoints for this stream */ 133 /* data and sync endpoints for this stream */
130 unsigned int ep_num; /* the endpoint number */ 134 unsigned int ep_num; /* the endpoint number */
diff --git a/sound/usb/endpoint.c b/sound/usb/endpoint.c
index 93e970f2b3c0..b9ba0fcc45df 100644
--- a/sound/usb/endpoint.c
+++ b/sound/usb/endpoint.c
@@ -33,7 +33,6 @@
33#include "pcm.h" 33#include "pcm.h"
34#include "quirks.h" 34#include "quirks.h"
35 35
36#define EP_FLAG_ACTIVATED 0
37#define EP_FLAG_RUNNING 1 36#define EP_FLAG_RUNNING 1
38#define EP_FLAG_STOPPING 2 37#define EP_FLAG_STOPPING 2
39 38
@@ -426,9 +425,9 @@ struct snd_usb_endpoint *snd_usb_add_endpoint(struct snd_usb_audio *chip,
426 list_for_each_entry(ep, &chip->ep_list, list) { 425 list_for_each_entry(ep, &chip->ep_list, list) {
427 if (ep->ep_num == ep_num && 426 if (ep->ep_num == ep_num &&
428 ep->iface == alts->desc.bInterfaceNumber && 427 ep->iface == alts->desc.bInterfaceNumber &&
429 ep->alt_idx == alts->desc.bAlternateSetting) { 428 ep->altsetting == alts->desc.bAlternateSetting) {
430 snd_printdd(KERN_DEBUG "Re-using EP %x in iface %d,%d @%p\n", 429 snd_printdd(KERN_DEBUG "Re-using EP %x in iface %d,%d @%p\n",
431 ep_num, ep->iface, ep->alt_idx, ep); 430 ep_num, ep->iface, ep->altsetting, ep);
432 goto __exit_unlock; 431 goto __exit_unlock;
433 } 432 }
434 } 433 }
@@ -447,7 +446,7 @@ struct snd_usb_endpoint *snd_usb_add_endpoint(struct snd_usb_audio *chip,
447 ep->type = type; 446 ep->type = type;
448 ep->ep_num = ep_num; 447 ep->ep_num = ep_num;
449 ep->iface = alts->desc.bInterfaceNumber; 448 ep->iface = alts->desc.bInterfaceNumber;
450 ep->alt_idx = alts->desc.bAlternateSetting; 449 ep->altsetting = alts->desc.bAlternateSetting;
451 INIT_LIST_HEAD(&ep->ready_playback_urbs); 450 INIT_LIST_HEAD(&ep->ready_playback_urbs);
452 ep_num &= USB_ENDPOINT_NUMBER_MASK; 451 ep_num &= USB_ENDPOINT_NUMBER_MASK;
453 452
@@ -574,11 +573,14 @@ static int data_ep_set_params(struct snd_usb_endpoint *ep,
574 snd_pcm_format_t pcm_format, 573 snd_pcm_format_t pcm_format,
575 unsigned int channels, 574 unsigned int channels,
576 unsigned int period_bytes, 575 unsigned int period_bytes,
576 unsigned int frames_per_period,
577 unsigned int periods_per_buffer,
577 struct audioformat *fmt, 578 struct audioformat *fmt,
578 struct snd_usb_endpoint *sync_ep) 579 struct snd_usb_endpoint *sync_ep)
579{ 580{
580 unsigned int maxsize, i, urb_packs, total_packs, packs_per_ms; 581 unsigned int maxsize, minsize, packs_per_ms, max_packs_per_urb;
581 int is_playback = usb_pipeout(ep->pipe); 582 unsigned int max_packs_per_period, urbs_per_period, urb_packs;
583 unsigned int max_urbs, i;
582 int frame_bits = snd_pcm_format_physical_width(pcm_format) * channels; 584 int frame_bits = snd_pcm_format_physical_width(pcm_format) * channels;
583 585
584 if (pcm_format == SNDRV_PCM_FORMAT_DSD_U16_LE && fmt->dsd_dop) { 586 if (pcm_format == SNDRV_PCM_FORMAT_DSD_U16_LE && fmt->dsd_dop) {
@@ -611,58 +613,67 @@ static int data_ep_set_params(struct snd_usb_endpoint *ep,
611 else 613 else
612 ep->curpacksize = maxsize; 614 ep->curpacksize = maxsize;
613 615
614 if (snd_usb_get_speed(ep->chip->dev) != USB_SPEED_FULL) 616 if (snd_usb_get_speed(ep->chip->dev) != USB_SPEED_FULL) {
615 packs_per_ms = 8 >> ep->datainterval; 617 packs_per_ms = 8 >> ep->datainterval;
616 else 618 max_packs_per_urb = MAX_PACKS_HS;
617 packs_per_ms = 1;
618
619 if (is_playback && !snd_usb_endpoint_implicit_feedback_sink(ep)) {
620 urb_packs = max(ep->chip->nrpacks, 1);
621 urb_packs = min(urb_packs, (unsigned int) MAX_PACKS);
622 } else { 619 } else {
623 urb_packs = 1; 620 packs_per_ms = 1;
621 max_packs_per_urb = MAX_PACKS;
624 } 622 }
623 if (sync_ep && !snd_usb_endpoint_implicit_feedback_sink(ep))
624 max_packs_per_urb = min(max_packs_per_urb,
625 1U << sync_ep->syncinterval);
626 max_packs_per_urb = max(1u, max_packs_per_urb >> ep->datainterval);
625 627
626 urb_packs *= packs_per_ms; 628 /*
629 * Capture endpoints need to use small URBs because there's no way
630 * to tell in advance where the next period will end, and we don't
631 * want the next URB to complete much after the period ends.
632 *
633 * Playback endpoints with implicit sync much use the same parameters
634 * as their corresponding capture endpoint.
635 */
636 if (usb_pipein(ep->pipe) ||
637 snd_usb_endpoint_implicit_feedback_sink(ep)) {
627 638
628 if (sync_ep && !snd_usb_endpoint_implicit_feedback_sink(ep)) 639 /* make capture URBs <= 1 ms and smaller than a period */
629 urb_packs = min(urb_packs, 1U << sync_ep->syncinterval); 640 urb_packs = min(max_packs_per_urb, packs_per_ms);
641 while (urb_packs > 1 && urb_packs * maxsize >= period_bytes)
642 urb_packs >>= 1;
643 ep->nurbs = MAX_URBS;
630 644
631 /* decide how many packets to be used */ 645 /*
632 if (is_playback && !snd_usb_endpoint_implicit_feedback_sink(ep)) { 646 * Playback endpoints without implicit sync are adjusted so that
633 unsigned int minsize, maxpacks; 647 * a period fits as evenly as possible in the smallest number of
648 * URBs. The total number of URBs is adjusted to the size of the
649 * ALSA buffer, subject to the MAX_URBS and MAX_QUEUE limits.
650 */
651 } else {
634 /* determine how small a packet can be */ 652 /* determine how small a packet can be */
635 minsize = (ep->freqn >> (16 - ep->datainterval)) 653 minsize = (ep->freqn >> (16 - ep->datainterval)) *
636 * (frame_bits >> 3); 654 (frame_bits >> 3);
637 /* with sync from device, assume it can be 12% lower */ 655 /* with sync from device, assume it can be 12% lower */
638 if (sync_ep) 656 if (sync_ep)
639 minsize -= minsize >> 3; 657 minsize -= minsize >> 3;
640 minsize = max(minsize, 1u); 658 minsize = max(minsize, 1u);
641 total_packs = (period_bytes + minsize - 1) / minsize;
642 /* we need at least two URBs for queueing */
643 if (total_packs < 2) {
644 total_packs = 2;
645 } else {
646 /* and we don't want too long a queue either */
647 maxpacks = max(MAX_QUEUE * packs_per_ms, urb_packs * 2);
648 total_packs = min(total_packs, maxpacks);
649 }
650 } else {
651 while (urb_packs > 1 && urb_packs * maxsize >= period_bytes)
652 urb_packs >>= 1;
653 total_packs = MAX_URBS * urb_packs;
654 }
655 659
656 ep->nurbs = (total_packs + urb_packs - 1) / urb_packs; 660 /* how many packets will contain an entire ALSA period? */
657 if (ep->nurbs > MAX_URBS) { 661 max_packs_per_period = DIV_ROUND_UP(period_bytes, minsize);
658 /* too much... */ 662
659 ep->nurbs = MAX_URBS; 663 /* how many URBs will contain a period? */
660 total_packs = MAX_URBS * urb_packs; 664 urbs_per_period = DIV_ROUND_UP(max_packs_per_period,
661 } else if (ep->nurbs < 2) { 665 max_packs_per_urb);
662 /* too little - we need at least two packets 666 /* how many packets are needed in each URB? */
663 * to ensure contiguous playback/capture 667 urb_packs = DIV_ROUND_UP(max_packs_per_period, urbs_per_period);
664 */ 668
665 ep->nurbs = 2; 669 /* limit the number of frames in a single URB */
670 ep->max_urb_frames = DIV_ROUND_UP(frames_per_period,
671 urbs_per_period);
672
673 /* try to use enough URBs to contain an entire ALSA buffer */
674 max_urbs = min((unsigned) MAX_URBS,
675 MAX_QUEUE * packs_per_ms / urb_packs);
676 ep->nurbs = min(max_urbs, urbs_per_period * periods_per_buffer);
666 } 677 }
667 678
668 /* allocate and initialize data urbs */ 679 /* allocate and initialize data urbs */
@@ -670,8 +681,7 @@ static int data_ep_set_params(struct snd_usb_endpoint *ep,
670 struct snd_urb_ctx *u = &ep->urb[i]; 681 struct snd_urb_ctx *u = &ep->urb[i];
671 u->index = i; 682 u->index = i;
672 u->ep = ep; 683 u->ep = ep;
673 u->packets = (i + 1) * total_packs / ep->nurbs 684 u->packets = urb_packs;
674 - i * total_packs / ep->nurbs;
675 u->buffer_size = maxsize * u->packets; 685 u->buffer_size = maxsize * u->packets;
676 686
677 if (fmt->fmt_type == UAC_FORMAT_TYPE_II) 687 if (fmt->fmt_type == UAC_FORMAT_TYPE_II)
@@ -703,8 +713,7 @@ out_of_memory:
703/* 713/*
704 * configure a sync endpoint 714 * configure a sync endpoint
705 */ 715 */
706static int sync_ep_set_params(struct snd_usb_endpoint *ep, 716static int sync_ep_set_params(struct snd_usb_endpoint *ep)
707 struct audioformat *fmt)
708{ 717{
709 int i; 718 int i;
710 719
@@ -748,6 +757,8 @@ out_of_memory:
748 * @pcm_format: the audio fomat. 757 * @pcm_format: the audio fomat.
749 * @channels: the number of audio channels. 758 * @channels: the number of audio channels.
750 * @period_bytes: the number of bytes in one alsa period. 759 * @period_bytes: the number of bytes in one alsa period.
760 * @period_frames: the number of frames in one alsa period.
761 * @buffer_periods: the number of periods in one alsa buffer.
751 * @rate: the frame rate. 762 * @rate: the frame rate.
752 * @fmt: the USB audio format information 763 * @fmt: the USB audio format information
753 * @sync_ep: the sync endpoint to use, if any 764 * @sync_ep: the sync endpoint to use, if any
@@ -760,6 +771,8 @@ int snd_usb_endpoint_set_params(struct snd_usb_endpoint *ep,
760 snd_pcm_format_t pcm_format, 771 snd_pcm_format_t pcm_format,
761 unsigned int channels, 772 unsigned int channels,
762 unsigned int period_bytes, 773 unsigned int period_bytes,
774 unsigned int period_frames,
775 unsigned int buffer_periods,
763 unsigned int rate, 776 unsigned int rate,
764 struct audioformat *fmt, 777 struct audioformat *fmt,
765 struct snd_usb_endpoint *sync_ep) 778 struct snd_usb_endpoint *sync_ep)
@@ -793,10 +806,11 @@ int snd_usb_endpoint_set_params(struct snd_usb_endpoint *ep,
793 switch (ep->type) { 806 switch (ep->type) {
794 case SND_USB_ENDPOINT_TYPE_DATA: 807 case SND_USB_ENDPOINT_TYPE_DATA:
795 err = data_ep_set_params(ep, pcm_format, channels, 808 err = data_ep_set_params(ep, pcm_format, channels,
796 period_bytes, fmt, sync_ep); 809 period_bytes, period_frames,
810 buffer_periods, fmt, sync_ep);
797 break; 811 break;
798 case SND_USB_ENDPOINT_TYPE_SYNC: 812 case SND_USB_ENDPOINT_TYPE_SYNC:
799 err = sync_ep_set_params(ep, fmt); 813 err = sync_ep_set_params(ep);
800 break; 814 break;
801 default: 815 default:
802 err = -EINVAL; 816 err = -EINVAL;
@@ -931,28 +945,21 @@ void snd_usb_endpoint_stop(struct snd_usb_endpoint *ep)
931 * 945 *
932 * @ep: the endpoint to deactivate 946 * @ep: the endpoint to deactivate
933 * 947 *
934 * If the endpoint is not currently in use, this functions will select the 948 * If the endpoint is not currently in use, this functions will
935 * alternate interface setting 0 for the interface of this endpoint. 949 * deactivate its associated URBs.
936 * 950 *
937 * In case of any active users, this functions does nothing. 951 * In case of any active users, this functions does nothing.
938 *
939 * Returns an error if usb_set_interface() failed, 0 in all other
940 * cases.
941 */ 952 */
942int snd_usb_endpoint_deactivate(struct snd_usb_endpoint *ep) 953void snd_usb_endpoint_deactivate(struct snd_usb_endpoint *ep)
943{ 954{
944 if (!ep) 955 if (!ep)
945 return -EINVAL; 956 return;
946
947 deactivate_urbs(ep, true);
948 wait_clear_urbs(ep);
949 957
950 if (ep->use_count != 0) 958 if (ep->use_count != 0)
951 return 0; 959 return;
952
953 clear_bit(EP_FLAG_ACTIVATED, &ep->flags);
954 960
955 return 0; 961 deactivate_urbs(ep, true);
962 wait_clear_urbs(ep);
956} 963}
957 964
958/** 965/**
diff --git a/sound/usb/endpoint.h b/sound/usb/endpoint.h
index 2287adf5ca59..1c7e8ee48abc 100644
--- a/sound/usb/endpoint.h
+++ b/sound/usb/endpoint.h
@@ -12,6 +12,8 @@ int snd_usb_endpoint_set_params(struct snd_usb_endpoint *ep,
12 snd_pcm_format_t pcm_format, 12 snd_pcm_format_t pcm_format,
13 unsigned int channels, 13 unsigned int channels,
14 unsigned int period_bytes, 14 unsigned int period_bytes,
15 unsigned int period_frames,
16 unsigned int buffer_periods,
15 unsigned int rate, 17 unsigned int rate,
16 struct audioformat *fmt, 18 struct audioformat *fmt,
17 struct snd_usb_endpoint *sync_ep); 19 struct snd_usb_endpoint *sync_ep);
@@ -20,7 +22,7 @@ int snd_usb_endpoint_start(struct snd_usb_endpoint *ep, bool can_sleep);
20void snd_usb_endpoint_stop(struct snd_usb_endpoint *ep); 22void snd_usb_endpoint_stop(struct snd_usb_endpoint *ep);
21void snd_usb_endpoint_sync_pending_stop(struct snd_usb_endpoint *ep); 23void snd_usb_endpoint_sync_pending_stop(struct snd_usb_endpoint *ep);
22int snd_usb_endpoint_activate(struct snd_usb_endpoint *ep); 24int snd_usb_endpoint_activate(struct snd_usb_endpoint *ep);
23int snd_usb_endpoint_deactivate(struct snd_usb_endpoint *ep); 25void snd_usb_endpoint_deactivate(struct snd_usb_endpoint *ep);
24void snd_usb_endpoint_free(struct list_head *head); 26void snd_usb_endpoint_free(struct list_head *head);
25 27
26int snd_usb_endpoint_implicit_feedback_sink(struct snd_usb_endpoint *ep); 28int snd_usb_endpoint_implicit_feedback_sink(struct snd_usb_endpoint *ep);
diff --git a/sound/usb/helper.c b/sound/usb/helper.c
index 620902463c6e..51ed1ac825fd 100644
--- a/sound/usb/helper.c
+++ b/sound/usb/helper.c
@@ -118,6 +118,7 @@ unsigned char snd_usb_parse_datainterval(struct snd_usb_audio *chip,
118{ 118{
119 switch (snd_usb_get_speed(chip->dev)) { 119 switch (snd_usb_get_speed(chip->dev)) {
120 case USB_SPEED_HIGH: 120 case USB_SPEED_HIGH:
121 case USB_SPEED_WIRELESS:
121 case USB_SPEED_SUPER: 122 case USB_SPEED_SUPER:
122 if (get_endpoint(alts, 0)->bInterval >= 1 && 123 if (get_endpoint(alts, 0)->bInterval >= 1 &&
123 get_endpoint(alts, 0)->bInterval <= 4) 124 get_endpoint(alts, 0)->bInterval <= 4)
diff --git a/sound/usb/mixer.c b/sound/usb/mixer.c
index 95558ef4a7a0..44b0ba4feab3 100644
--- a/sound/usb/mixer.c
+++ b/sound/usb/mixer.c
@@ -1151,14 +1151,14 @@ static void check_no_speaker_on_headset(struct snd_kcontrol *kctl,
1151 const char *names_to_check[] = { 1151 const char *names_to_check[] = {
1152 "Headset", "headset", "Headphone", "headphone", NULL}; 1152 "Headset", "headset", "Headphone", "headphone", NULL};
1153 const char **s; 1153 const char **s;
1154 bool found = 0; 1154 bool found = false;
1155 1155
1156 if (strcmp("Speaker", kctl->id.name)) 1156 if (strcmp("Speaker", kctl->id.name))
1157 return; 1157 return;
1158 1158
1159 for (s = names_to_check; *s; s++) 1159 for (s = names_to_check; *s; s++)
1160 if (strstr(card->shortname, *s)) { 1160 if (strstr(card->shortname, *s)) {
1161 found = 1; 1161 found = true;
1162 break; 1162 break;
1163 } 1163 }
1164 1164
diff --git a/sound/usb/pcm.c b/sound/usb/pcm.c
index b375d58871e7..ca3256d6fde3 100644
--- a/sound/usb/pcm.c
+++ b/sound/usb/pcm.c
@@ -241,16 +241,17 @@ static int start_endpoints(struct snd_usb_substream *subs, bool can_sleep)
241 struct snd_usb_endpoint *ep = subs->sync_endpoint; 241 struct snd_usb_endpoint *ep = subs->sync_endpoint;
242 242
243 if (subs->data_endpoint->iface != subs->sync_endpoint->iface || 243 if (subs->data_endpoint->iface != subs->sync_endpoint->iface ||
244 subs->data_endpoint->alt_idx != subs->sync_endpoint->alt_idx) { 244 subs->data_endpoint->altsetting != subs->sync_endpoint->altsetting) {
245 err = usb_set_interface(subs->dev, 245 err = usb_set_interface(subs->dev,
246 subs->sync_endpoint->iface, 246 subs->sync_endpoint->iface,
247 subs->sync_endpoint->alt_idx); 247 subs->sync_endpoint->altsetting);
248 if (err < 0) { 248 if (err < 0) {
249 clear_bit(SUBSTREAM_FLAG_SYNC_EP_STARTED, &subs->flags);
249 snd_printk(KERN_ERR 250 snd_printk(KERN_ERR
250 "%d:%d:%d: cannot set interface (%d)\n", 251 "%d:%d:%d: cannot set interface (%d)\n",
251 subs->dev->devnum, 252 subs->dev->devnum,
252 subs->sync_endpoint->iface, 253 subs->sync_endpoint->iface,
253 subs->sync_endpoint->alt_idx, err); 254 subs->sync_endpoint->altsetting, err);
254 return -EIO; 255 return -EIO;
255 } 256 }
256 } 257 }
@@ -282,22 +283,6 @@ static void stop_endpoints(struct snd_usb_substream *subs, bool wait)
282 } 283 }
283} 284}
284 285
285static int deactivate_endpoints(struct snd_usb_substream *subs)
286{
287 int reta, retb;
288
289 reta = snd_usb_endpoint_deactivate(subs->sync_endpoint);
290 retb = snd_usb_endpoint_deactivate(subs->data_endpoint);
291
292 if (reta < 0)
293 return reta;
294
295 if (retb < 0)
296 return retb;
297
298 return 0;
299}
300
301static int search_roland_implicit_fb(struct usb_device *dev, int ifnum, 286static int search_roland_implicit_fb(struct usb_device *dev, int ifnum,
302 unsigned int altsetting, 287 unsigned int altsetting,
303 struct usb_host_interface **alts, 288 struct usb_host_interface **alts,
@@ -595,6 +580,7 @@ static int configure_sync_endpoint(struct snd_usb_substream *subs)
595 subs->pcm_format, 580 subs->pcm_format,
596 subs->channels, 581 subs->channels,
597 subs->period_bytes, 582 subs->period_bytes,
583 0, 0,
598 subs->cur_rate, 584 subs->cur_rate,
599 subs->cur_audiofmt, 585 subs->cur_audiofmt,
600 NULL); 586 NULL);
@@ -631,6 +617,7 @@ static int configure_sync_endpoint(struct snd_usb_substream *subs)
631 subs->pcm_format, 617 subs->pcm_format,
632 sync_fp->channels, 618 sync_fp->channels,
633 sync_period_bytes, 619 sync_period_bytes,
620 0, 0,
634 subs->cur_rate, 621 subs->cur_rate,
635 sync_fp, 622 sync_fp,
636 NULL); 623 NULL);
@@ -653,6 +640,8 @@ static int configure_endpoint(struct snd_usb_substream *subs)
653 subs->pcm_format, 640 subs->pcm_format,
654 subs->channels, 641 subs->channels,
655 subs->period_bytes, 642 subs->period_bytes,
643 subs->period_frames,
644 subs->buffer_periods,
656 subs->cur_rate, 645 subs->cur_rate,
657 subs->cur_audiofmt, 646 subs->cur_audiofmt,
658 subs->sync_endpoint); 647 subs->sync_endpoint);
@@ -689,6 +678,8 @@ static int snd_usb_hw_params(struct snd_pcm_substream *substream,
689 678
690 subs->pcm_format = params_format(hw_params); 679 subs->pcm_format = params_format(hw_params);
691 subs->period_bytes = params_period_bytes(hw_params); 680 subs->period_bytes = params_period_bytes(hw_params);
681 subs->period_frames = params_period_size(hw_params);
682 subs->buffer_periods = params_periods(hw_params);
692 subs->channels = params_channels(hw_params); 683 subs->channels = params_channels(hw_params);
693 subs->cur_rate = params_rate(hw_params); 684 subs->cur_rate = params_rate(hw_params);
694 685
@@ -730,7 +721,8 @@ static int snd_usb_hw_free(struct snd_pcm_substream *substream)
730 down_read(&subs->stream->chip->shutdown_rwsem); 721 down_read(&subs->stream->chip->shutdown_rwsem);
731 if (!subs->stream->chip->shutdown) { 722 if (!subs->stream->chip->shutdown) {
732 stop_endpoints(subs, true); 723 stop_endpoints(subs, true);
733 deactivate_endpoints(subs); 724 snd_usb_endpoint_deactivate(subs->sync_endpoint);
725 snd_usb_endpoint_deactivate(subs->data_endpoint);
734 } 726 }
735 up_read(&subs->stream->chip->shutdown_rwsem); 727 up_read(&subs->stream->chip->shutdown_rwsem);
736 return snd_pcm_lib_free_vmalloc_buffer(substream); 728 return snd_pcm_lib_free_vmalloc_buffer(substream);
@@ -1363,6 +1355,7 @@ static void prepare_playback_urb(struct snd_usb_substream *subs,
1363 frames = 0; 1355 frames = 0;
1364 urb->number_of_packets = 0; 1356 urb->number_of_packets = 0;
1365 spin_lock_irqsave(&subs->lock, flags); 1357 spin_lock_irqsave(&subs->lock, flags);
1358 subs->frame_limit += ep->max_urb_frames;
1366 for (i = 0; i < ctx->packets; i++) { 1359 for (i = 0; i < ctx->packets; i++) {
1367 if (ctx->packet_size[i]) 1360 if (ctx->packet_size[i])
1368 counts = ctx->packet_size[i]; 1361 counts = ctx->packet_size[i];
@@ -1377,6 +1370,7 @@ static void prepare_playback_urb(struct snd_usb_substream *subs,
1377 subs->transfer_done += counts; 1370 subs->transfer_done += counts;
1378 if (subs->transfer_done >= runtime->period_size) { 1371 if (subs->transfer_done >= runtime->period_size) {
1379 subs->transfer_done -= runtime->period_size; 1372 subs->transfer_done -= runtime->period_size;
1373 subs->frame_limit = 0;
1380 period_elapsed = 1; 1374 period_elapsed = 1;
1381 if (subs->fmt_type == UAC_FORMAT_TYPE_II) { 1375 if (subs->fmt_type == UAC_FORMAT_TYPE_II) {
1382 if (subs->transfer_done > 0) { 1376 if (subs->transfer_done > 0) {
@@ -1399,8 +1393,10 @@ static void prepare_playback_urb(struct snd_usb_substream *subs,
1399 break; 1393 break;
1400 } 1394 }
1401 } 1395 }
1402 if (period_elapsed && 1396 /* finish at the period boundary or after enough frames */
1403 !snd_usb_endpoint_implicit_feedback_sink(subs->data_endpoint)) /* finish at the period boundary */ 1397 if ((period_elapsed ||
1398 subs->transfer_done >= subs->frame_limit) &&
1399 !snd_usb_endpoint_implicit_feedback_sink(ep))
1404 break; 1400 break;
1405 } 1401 }
1406 bytes = frames * ep->stride; 1402 bytes = frames * ep->stride;
diff --git a/sound/usb/usbaudio.h b/sound/usb/usbaudio.h
index caabe9b3af49..5d2fe0530745 100644
--- a/sound/usb/usbaudio.h
+++ b/sound/usb/usbaudio.h
@@ -55,7 +55,6 @@ struct snd_usb_audio {
55 struct list_head mixer_list; /* list of mixer interfaces */ 55 struct list_head mixer_list; /* list of mixer interfaces */
56 56
57 int setup; /* from the 'device_setup' module param */ 57 int setup; /* from the 'device_setup' module param */
58 int nrpacks; /* from the 'nrpacks' module param */
59 bool autoclock; /* from the 'autoclock' module param */ 58 bool autoclock; /* from the 'autoclock' module param */
60 59
61 struct usb_host_interface *ctrl_intf; /* the audio control interface */ 60 struct usb_host_interface *ctrl_intf; /* the audio control interface */