aboutsummaryrefslogtreecommitdiffstats
path: root/sound/usb
diff options
context:
space:
mode:
Diffstat (limited to 'sound/usb')
-rw-r--r--sound/usb/6fire/Makefile3
-rw-r--r--sound/usb/6fire/chip.c232
-rw-r--r--sound/usb/6fire/chip.h32
-rw-r--r--sound/usb/6fire/comm.c176
-rw-r--r--sound/usb/6fire/comm.h44
-rw-r--r--sound/usb/6fire/common.h30
-rw-r--r--sound/usb/6fire/control.c380
-rw-r--r--sound/usb/6fire/control.h54
-rw-r--r--sound/usb/6fire/firmware.c419
-rw-r--r--sound/usb/6fire/firmware.h27
-rw-r--r--sound/usb/6fire/midi.c203
-rw-r--r--sound/usb/6fire/midi.h46
-rw-r--r--sound/usb/6fire/pcm.c667
-rw-r--r--sound/usb/6fire/pcm.h76
-rw-r--r--sound/usb/Kconfig17
-rw-r--r--sound/usb/Makefile2
-rw-r--r--sound/usb/caiaq/audio.c178
-rw-r--r--sound/usb/caiaq/control.c208
-rw-r--r--sound/usb/caiaq/device.c16
-rw-r--r--sound/usb/caiaq/device.h7
-rw-r--r--sound/usb/caiaq/input.c248
-rw-r--r--sound/usb/caiaq/midi.c2
-rw-r--r--sound/usb/card.c138
-rw-r--r--sound/usb/card.h2
-rw-r--r--sound/usb/clock.c11
-rw-r--r--sound/usb/debug.h2
-rw-r--r--sound/usb/endpoint.c2
-rw-r--r--sound/usb/format.c10
-rw-r--r--sound/usb/helper.c17
-rw-r--r--sound/usb/midi.c44
-rw-r--r--sound/usb/mixer.c127
-rw-r--r--sound/usb/mixer.h16
-rw-r--r--sound/usb/mixer_quirks.c268
-rw-r--r--sound/usb/pcm.c37
-rw-r--r--sound/usb/power.h17
-rw-r--r--sound/usb/proc.c7
-rw-r--r--sound/usb/quirks-table.h300
-rw-r--r--sound/usb/quirks.c85
-rw-r--r--sound/usb/urb.c172
-rw-r--r--sound/usb/usbaudio.h10
-rw-r--r--sound/usb/usx2y/us122l.c41
-rw-r--r--sound/usb/usx2y/usx2yhwdeppcm.c8
42 files changed, 4038 insertions, 343 deletions
diff --git a/sound/usb/6fire/Makefile b/sound/usb/6fire/Makefile
new file mode 100644
index 000000000000..dfce6ec53513
--- /dev/null
+++ b/sound/usb/6fire/Makefile
@@ -0,0 +1,3 @@
1snd-usb-6fire-objs += chip.o comm.o midi.o control.o firmware.o pcm.o
2obj-$(CONFIG_SND_USB_6FIRE) += snd-usb-6fire.o
3
diff --git a/sound/usb/6fire/chip.c b/sound/usb/6fire/chip.c
new file mode 100644
index 000000000000..c7dca7b0b9fe
--- /dev/null
+++ b/sound/usb/6fire/chip.c
@@ -0,0 +1,232 @@
1/*
2 * Linux driver for TerraTec DMX 6Fire USB
3 *
4 * Main routines and module definitions.
5 *
6 * Author: Torsten Schenk <torsten.schenk@zoho.com>
7 * Created: Jan 01, 2011
8 * Version: 0.3.0
9 * Copyright: (C) Torsten Schenk
10 *
11 * This program is free software; you can redistribute it and/or modify
12 * it under the terms of the GNU General Public License as published by
13 * the Free Software Foundation; either version 2 of the License, or
14 * (at your option) any later version.
15 */
16
17#include "chip.h"
18#include "firmware.h"
19#include "pcm.h"
20#include "control.h"
21#include "comm.h"
22#include "midi.h"
23
24#include <linux/moduleparam.h>
25#include <linux/interrupt.h>
26#include <linux/module.h>
27#include <linux/init.h>
28#include <linux/gfp.h>
29#include <sound/initval.h>
30
31MODULE_AUTHOR("Torsten Schenk <torsten.schenk@zoho.com>");
32MODULE_DESCRIPTION("TerraTec DMX 6Fire USB audio driver, version 0.3.0");
33MODULE_LICENSE("GPL v2");
34MODULE_SUPPORTED_DEVICE("{{TerraTec, DMX 6Fire USB}}");
35
36static int index[SNDRV_CARDS] = SNDRV_DEFAULT_IDX; /* Index 0-max */
37static char *id[SNDRV_CARDS] = SNDRV_DEFAULT_STR; /* Id for card */
38static int enable[SNDRV_CARDS] = SNDRV_DEFAULT_ENABLE_PNP; /* Enable card */
39static struct sfire_chip *chips[SNDRV_CARDS] = SNDRV_DEFAULT_PTR;
40static struct usb_device *devices[SNDRV_CARDS] = SNDRV_DEFAULT_PTR;
41
42module_param_array(index, int, NULL, 0444);
43MODULE_PARM_DESC(index, "Index value for the 6fire sound device");
44module_param_array(id, charp, NULL, 0444);
45MODULE_PARM_DESC(id, "ID string for the 6fire sound device.");
46module_param_array(enable, bool, NULL, 0444);
47MODULE_PARM_DESC(enable, "Enable the 6fire sound device.");
48
49static DEFINE_MUTEX(register_mutex);
50
51static void usb6fire_chip_abort(struct sfire_chip *chip)
52{
53 if (chip) {
54 if (chip->pcm)
55 usb6fire_pcm_abort(chip);
56 if (chip->midi)
57 usb6fire_midi_abort(chip);
58 if (chip->comm)
59 usb6fire_comm_abort(chip);
60 if (chip->control)
61 usb6fire_control_abort(chip);
62 if (chip->card) {
63 snd_card_disconnect(chip->card);
64 snd_card_free_when_closed(chip->card);
65 chip->card = NULL;
66 }
67 }
68}
69
70static void usb6fire_chip_destroy(struct sfire_chip *chip)
71{
72 if (chip) {
73 if (chip->pcm)
74 usb6fire_pcm_destroy(chip);
75 if (chip->midi)
76 usb6fire_midi_destroy(chip);
77 if (chip->comm)
78 usb6fire_comm_destroy(chip);
79 if (chip->control)
80 usb6fire_control_destroy(chip);
81 if (chip->card)
82 snd_card_free(chip->card);
83 }
84}
85
86static int __devinit usb6fire_chip_probe(struct usb_interface *intf,
87 const struct usb_device_id *usb_id)
88{
89 int ret;
90 int i;
91 struct sfire_chip *chip = NULL;
92 struct usb_device *device = interface_to_usbdev(intf);
93 int regidx = -1; /* index in module parameter array */
94 struct snd_card *card = NULL;
95
96 /* look if we already serve this card and return if so */
97 mutex_lock(&register_mutex);
98 for (i = 0; i < SNDRV_CARDS; i++) {
99 if (devices[i] == device) {
100 if (chips[i])
101 chips[i]->intf_count++;
102 usb_set_intfdata(intf, chips[i]);
103 mutex_unlock(&register_mutex);
104 return 0;
105 } else if (regidx < 0)
106 regidx = i;
107 }
108 if (regidx < 0) {
109 mutex_unlock(&register_mutex);
110 snd_printk(KERN_ERR PREFIX "too many cards registered.\n");
111 return -ENODEV;
112 }
113 devices[regidx] = device;
114 mutex_unlock(&register_mutex);
115
116 /* check, if firmware is present on device, upload it if not */
117 ret = usb6fire_fw_init(intf);
118 if (ret < 0)
119 return ret;
120 else if (ret == FW_NOT_READY) /* firmware update performed */
121 return 0;
122
123 /* if we are here, card can be registered in alsa. */
124 if (usb_set_interface(device, 0, 0) != 0) {
125 snd_printk(KERN_ERR PREFIX "can't set first interface.\n");
126 return -EIO;
127 }
128 ret = snd_card_create(index[regidx], id[regidx], THIS_MODULE,
129 sizeof(struct sfire_chip), &card);
130 if (ret < 0) {
131 snd_printk(KERN_ERR PREFIX "cannot create alsa card.\n");
132 return ret;
133 }
134 strcpy(card->driver, "6FireUSB");
135 strcpy(card->shortname, "TerraTec DMX6FireUSB");
136 sprintf(card->longname, "%s at %d:%d", card->shortname,
137 device->bus->busnum, device->devnum);
138 snd_card_set_dev(card, &intf->dev);
139
140 chip = card->private_data;
141 chips[regidx] = chip;
142 chip->dev = device;
143 chip->regidx = regidx;
144 chip->intf_count = 1;
145 chip->card = card;
146
147 ret = usb6fire_comm_init(chip);
148 if (ret < 0) {
149 usb6fire_chip_destroy(chip);
150 return ret;
151 }
152
153 ret = usb6fire_midi_init(chip);
154 if (ret < 0) {
155 usb6fire_chip_destroy(chip);
156 return ret;
157 }
158
159 ret = usb6fire_pcm_init(chip);
160 if (ret < 0) {
161 usb6fire_chip_destroy(chip);
162 return ret;
163 }
164
165 ret = usb6fire_control_init(chip);
166 if (ret < 0) {
167 usb6fire_chip_destroy(chip);
168 return ret;
169 }
170
171 ret = snd_card_register(card);
172 if (ret < 0) {
173 snd_printk(KERN_ERR PREFIX "cannot register card.");
174 usb6fire_chip_destroy(chip);
175 return ret;
176 }
177 usb_set_intfdata(intf, chip);
178 return 0;
179}
180
181static void usb6fire_chip_disconnect(struct usb_interface *intf)
182{
183 struct sfire_chip *chip;
184 struct snd_card *card;
185
186 chip = usb_get_intfdata(intf);
187 if (chip) { /* if !chip, fw upload has been performed */
188 card = chip->card;
189 chip->intf_count--;
190 if (!chip->intf_count) {
191 mutex_lock(&register_mutex);
192 devices[chip->regidx] = NULL;
193 chips[chip->regidx] = NULL;
194 mutex_unlock(&register_mutex);
195
196 chip->shutdown = true;
197 usb6fire_chip_abort(chip);
198 usb6fire_chip_destroy(chip);
199 }
200 }
201}
202
203static struct usb_device_id device_table[] = {
204 {
205 .match_flags = USB_DEVICE_ID_MATCH_DEVICE,
206 .idVendor = 0x0ccd,
207 .idProduct = 0x0080
208 },
209 {}
210};
211
212MODULE_DEVICE_TABLE(usb, device_table);
213
214static struct usb_driver driver = {
215 .name = "snd-usb-6fire",
216 .probe = usb6fire_chip_probe,
217 .disconnect = usb6fire_chip_disconnect,
218 .id_table = device_table,
219};
220
221static int __init usb6fire_chip_init(void)
222{
223 return usb_register(&driver);
224}
225
226static void __exit usb6fire_chip_cleanup(void)
227{
228 usb_deregister(&driver);
229}
230
231module_init(usb6fire_chip_init);
232module_exit(usb6fire_chip_cleanup);
diff --git a/sound/usb/6fire/chip.h b/sound/usb/6fire/chip.h
new file mode 100644
index 000000000000..d11e5cb520f0
--- /dev/null
+++ b/sound/usb/6fire/chip.h
@@ -0,0 +1,32 @@
1/*
2 * Linux driver for TerraTec DMX 6Fire USB
3 *
4 * Author: Torsten Schenk <torsten.schenk@zoho.com>
5 * Created: Jan 01, 2011
6 * Version: 0.3.0
7 * Copyright: (C) Torsten Schenk
8 *
9 * This program is free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License as published by
11 * the Free Software Foundation; either version 2 of the License, or
12 * (at your option) any later version.
13 */
14#ifndef USB6FIRE_CHIP_H
15#define USB6FIRE_CHIP_H
16
17#include "common.h"
18
19struct sfire_chip {
20 struct usb_device *dev;
21 struct snd_card *card;
22 int intf_count; /* number of registered interfaces */
23 int regidx; /* index in module parameter arrays */
24 bool shutdown;
25
26 struct midi_runtime *midi;
27 struct pcm_runtime *pcm;
28 struct control_runtime *control;
29 struct comm_runtime *comm;
30};
31#endif /* USB6FIRE_CHIP_H */
32
diff --git a/sound/usb/6fire/comm.c b/sound/usb/6fire/comm.c
new file mode 100644
index 000000000000..c994daa57af2
--- /dev/null
+++ b/sound/usb/6fire/comm.c
@@ -0,0 +1,176 @@
1/*
2 * Linux driver for TerraTec DMX 6Fire USB
3 *
4 * Device communications
5 *
6 * Author: Torsten Schenk <torsten.schenk@zoho.com>
7 * Created: Jan 01, 2011
8 * Version: 0.3.0
9 * Copyright: (C) Torsten Schenk
10 *
11 * This program is free software; you can redistribute it and/or modify
12 * it under the terms of the GNU General Public License as published by
13 * the Free Software Foundation; either version 2 of the License, or
14 * (at your option) any later version.
15 */
16
17#include "comm.h"
18#include "chip.h"
19#include "midi.h"
20
21enum {
22 COMM_EP = 1,
23 COMM_FPGA_EP = 2
24};
25
26static void usb6fire_comm_init_urb(struct comm_runtime *rt, struct urb *urb,
27 u8 *buffer, void *context, void(*handler)(struct urb *urb))
28{
29 usb_init_urb(urb);
30 urb->transfer_buffer = buffer;
31 urb->pipe = usb_sndintpipe(rt->chip->dev, COMM_EP);
32 urb->complete = handler;
33 urb->context = context;
34 urb->interval = 1;
35 urb->dev = rt->chip->dev;
36}
37
38static void usb6fire_comm_receiver_handler(struct urb *urb)
39{
40 struct comm_runtime *rt = urb->context;
41 struct midi_runtime *midi_rt = rt->chip->midi;
42
43 if (!urb->status) {
44 if (rt->receiver_buffer[0] == 0x10) /* midi in event */
45 if (midi_rt)
46 midi_rt->in_received(midi_rt,
47 rt->receiver_buffer + 2,
48 rt->receiver_buffer[1]);
49 }
50
51 if (!rt->chip->shutdown) {
52 urb->status = 0;
53 urb->actual_length = 0;
54 if (usb_submit_urb(urb, GFP_ATOMIC) < 0)
55 snd_printk(KERN_WARNING PREFIX
56 "comm data receiver aborted.\n");
57 }
58}
59
60static void usb6fire_comm_init_buffer(u8 *buffer, u8 id, u8 request,
61 u8 reg, u8 vl, u8 vh)
62{
63 buffer[0] = 0x01;
64 buffer[2] = request;
65 buffer[3] = id;
66 switch (request) {
67 case 0x02:
68 buffer[1] = 0x05; /* length (starting at buffer[2]) */
69 buffer[4] = reg;
70 buffer[5] = vl;
71 buffer[6] = vh;
72 break;
73
74 case 0x12:
75 buffer[1] = 0x0b; /* length (starting at buffer[2]) */
76 buffer[4] = 0x00;
77 buffer[5] = 0x18;
78 buffer[6] = 0x05;
79 buffer[7] = 0x00;
80 buffer[8] = 0x01;
81 buffer[9] = 0x00;
82 buffer[10] = 0x9e;
83 buffer[11] = reg;
84 buffer[12] = vl;
85 break;
86
87 case 0x20:
88 case 0x21:
89 case 0x22:
90 buffer[1] = 0x04;
91 buffer[4] = reg;
92 buffer[5] = vl;
93 break;
94 }
95}
96
97static int usb6fire_comm_send_buffer(u8 *buffer, struct usb_device *dev)
98{
99 int ret;
100 int actual_len;
101
102 ret = usb_interrupt_msg(dev, usb_sndintpipe(dev, COMM_EP),
103 buffer, buffer[1] + 2, &actual_len, HZ);
104 if (ret < 0)
105 return ret;
106 else if (actual_len != buffer[1] + 2)
107 return -EIO;
108 return 0;
109}
110
111static int usb6fire_comm_write8(struct comm_runtime *rt, u8 request,
112 u8 reg, u8 value)
113{
114 u8 buffer[13]; /* 13: maximum length of message */
115
116 usb6fire_comm_init_buffer(buffer, 0x00, request, reg, value, 0x00);
117 return usb6fire_comm_send_buffer(buffer, rt->chip->dev);
118}
119
120static int usb6fire_comm_write16(struct comm_runtime *rt, u8 request,
121 u8 reg, u8 vl, u8 vh)
122{
123 u8 buffer[13]; /* 13: maximum length of message */
124
125 usb6fire_comm_init_buffer(buffer, 0x00, request, reg, vl, vh);
126 return usb6fire_comm_send_buffer(buffer, rt->chip->dev);
127}
128
129int __devinit usb6fire_comm_init(struct sfire_chip *chip)
130{
131 struct comm_runtime *rt = kzalloc(sizeof(struct comm_runtime),
132 GFP_KERNEL);
133 struct urb *urb = &rt->receiver;
134 int ret;
135
136 if (!rt)
137 return -ENOMEM;
138
139 rt->serial = 1;
140 rt->chip = chip;
141 usb_init_urb(urb);
142 rt->init_urb = usb6fire_comm_init_urb;
143 rt->write8 = usb6fire_comm_write8;
144 rt->write16 = usb6fire_comm_write16;
145
146 /* submit an urb that receives communication data from device */
147 urb->transfer_buffer = rt->receiver_buffer;
148 urb->transfer_buffer_length = COMM_RECEIVER_BUFSIZE;
149 urb->pipe = usb_rcvintpipe(chip->dev, COMM_EP);
150 urb->dev = chip->dev;
151 urb->complete = usb6fire_comm_receiver_handler;
152 urb->context = rt;
153 urb->interval = 1;
154 ret = usb_submit_urb(urb, GFP_KERNEL);
155 if (ret < 0) {
156 kfree(rt);
157 snd_printk(KERN_ERR PREFIX "cannot create comm data receiver.");
158 return ret;
159 }
160 chip->comm = rt;
161 return 0;
162}
163
164void usb6fire_comm_abort(struct sfire_chip *chip)
165{
166 struct comm_runtime *rt = chip->comm;
167
168 if (rt)
169 usb_poison_urb(&rt->receiver);
170}
171
172void usb6fire_comm_destroy(struct sfire_chip *chip)
173{
174 kfree(chip->comm);
175 chip->comm = NULL;
176}
diff --git a/sound/usb/6fire/comm.h b/sound/usb/6fire/comm.h
new file mode 100644
index 000000000000..edc5dc84b888
--- /dev/null
+++ b/sound/usb/6fire/comm.h
@@ -0,0 +1,44 @@
1/*
2 * Linux driver for TerraTec DMX 6Fire USB
3 *
4 * Author: Torsten Schenk <torsten.schenk@zoho.com>
5 * Created: Jan 01, 2011
6 * Version: 0.3.0
7 * Copyright: (C) Torsten Schenk
8 *
9 * This program is free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License as published by
11 * the Free Software Foundation; either version 2 of the License, or
12 * (at your option) any later version.
13 */
14#ifndef USB6FIRE_COMM_H
15#define USB6FIRE_COMM_H
16
17#include "common.h"
18
19enum /* settings for comm */
20{
21 COMM_RECEIVER_BUFSIZE = 64,
22};
23
24struct comm_runtime {
25 struct sfire_chip *chip;
26
27 struct urb receiver;
28 u8 receiver_buffer[COMM_RECEIVER_BUFSIZE];
29
30 u8 serial; /* urb serial */
31
32 void (*init_urb)(struct comm_runtime *rt, struct urb *urb, u8 *buffer,
33 void *context, void(*handler)(struct urb *urb));
34 /* writes control data to the device */
35 int (*write8)(struct comm_runtime *rt, u8 request, u8 reg, u8 value);
36 int (*write16)(struct comm_runtime *rt, u8 request, u8 reg,
37 u8 vh, u8 vl);
38};
39
40int __devinit usb6fire_comm_init(struct sfire_chip *chip);
41void usb6fire_comm_abort(struct sfire_chip *chip);
42void usb6fire_comm_destroy(struct sfire_chip *chip);
43#endif /* USB6FIRE_COMM_H */
44
diff --git a/sound/usb/6fire/common.h b/sound/usb/6fire/common.h
new file mode 100644
index 000000000000..7dbeb4a37831
--- /dev/null
+++ b/sound/usb/6fire/common.h
@@ -0,0 +1,30 @@
1/*
2 * Linux driver for TerraTec DMX 6Fire USB
3 *
4 * Author: Torsten Schenk <torsten.schenk@zoho.com>
5 * Created: Jan 01, 2011
6 * Version: 0.3.0
7 * Copyright: (C) Torsten Schenk
8 *
9 * This program is free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License as published by
11 * the Free Software Foundation; either version 2 of the License, or
12 * (at your option) any later version.
13 */
14
15#ifndef USB6FIRE_COMMON_H
16#define USB6FIRE_COMMON_H
17
18#include <linux/slab.h>
19#include <linux/usb.h>
20#include <sound/core.h>
21
22#define PREFIX "6fire: "
23
24struct sfire_chip;
25struct midi_runtime;
26struct pcm_runtime;
27struct control_runtime;
28struct comm_runtime;
29#endif /* USB6FIRE_COMMON_H */
30
diff --git a/sound/usb/6fire/control.c b/sound/usb/6fire/control.c
new file mode 100644
index 000000000000..ac828eff1a63
--- /dev/null
+++ b/sound/usb/6fire/control.c
@@ -0,0 +1,380 @@
1/*
2 * Linux driver for TerraTec DMX 6Fire USB
3 *
4 * Mixer control
5 *
6 * Author: Torsten Schenk <torsten.schenk@zoho.com>
7 * Created: Jan 01, 2011
8 * Version: 0.3.0
9 * Copyright: (C) Torsten Schenk
10 *
11 * This program is free software; you can redistribute it and/or modify
12 * it under the terms of the GNU General Public License as published by
13 * the Free Software Foundation; either version 2 of the License, or
14 * (at your option) any later version.
15 */
16
17#include <linux/interrupt.h>
18#include <sound/control.h>
19
20#include "control.h"
21#include "comm.h"
22#include "chip.h"
23
24static char *opt_coax_texts[2] = { "Optical", "Coax" };
25static char *line_phono_texts[2] = { "Line", "Phono" };
26
27/*
28 * calculated with $value\[i\] = 128 \cdot sqrt[3]{\frac{i}{128}}$
29 * this is done because the linear values cause rapid degredation
30 * of volume in the uppermost region.
31 */
32static const u8 log_volume_table[128] = {
33 0x00, 0x19, 0x20, 0x24, 0x28, 0x2b, 0x2e, 0x30, 0x32, 0x34,
34 0x36, 0x38, 0x3a, 0x3b, 0x3d, 0x3e, 0x40, 0x41, 0x42, 0x43,
35 0x44, 0x46, 0x47, 0x48, 0x49, 0x4a, 0x4b, 0x4c, 0x4d, 0x4e,
36 0x4e, 0x4f, 0x50, 0x51, 0x52, 0x53, 0x53, 0x54, 0x55, 0x56,
37 0x56, 0x57, 0x58, 0x58, 0x59, 0x5a, 0x5b, 0x5b, 0x5c, 0x5c,
38 0x5d, 0x5e, 0x5e, 0x5f, 0x60, 0x60, 0x61, 0x61, 0x62, 0x62,
39 0x63, 0x63, 0x64, 0x65, 0x65, 0x66, 0x66, 0x67, 0x67, 0x68,
40 0x68, 0x69, 0x69, 0x6a, 0x6a, 0x6b, 0x6b, 0x6c, 0x6c, 0x6c,
41 0x6d, 0x6d, 0x6e, 0x6e, 0x6f, 0x6f, 0x70, 0x70, 0x70, 0x71,
42 0x71, 0x72, 0x72, 0x73, 0x73, 0x73, 0x74, 0x74, 0x75, 0x75,
43 0x75, 0x76, 0x76, 0x77, 0x77, 0x77, 0x78, 0x78, 0x78, 0x79,
44 0x79, 0x7a, 0x7a, 0x7a, 0x7b, 0x7b, 0x7b, 0x7c, 0x7c, 0x7c,
45 0x7d, 0x7d, 0x7d, 0x7e, 0x7e, 0x7e, 0x7f, 0x7f };
46
47/*
48 * data that needs to be sent to device. sets up card internal stuff.
49 * values dumped from windows driver and filtered by trial'n'error.
50 */
51static const struct {
52 u8 type;
53 u8 reg;
54 u8 value;
55}
56init_data[] = {
57 { 0x22, 0x00, 0x00 }, { 0x20, 0x00, 0x08 }, { 0x22, 0x01, 0x01 },
58 { 0x20, 0x01, 0x08 }, { 0x22, 0x02, 0x00 }, { 0x20, 0x02, 0x08 },
59 { 0x22, 0x03, 0x00 }, { 0x20, 0x03, 0x08 }, { 0x22, 0x04, 0x00 },
60 { 0x20, 0x04, 0x08 }, { 0x22, 0x05, 0x01 }, { 0x20, 0x05, 0x08 },
61 { 0x22, 0x04, 0x01 }, { 0x12, 0x04, 0x00 }, { 0x12, 0x05, 0x00 },
62 { 0x12, 0x0d, 0x78 }, { 0x12, 0x21, 0x82 }, { 0x12, 0x22, 0x80 },
63 { 0x12, 0x23, 0x00 }, { 0x12, 0x06, 0x02 }, { 0x12, 0x03, 0x00 },
64 { 0x12, 0x02, 0x00 }, { 0x22, 0x03, 0x01 },
65 { 0 } /* TERMINATING ENTRY */
66};
67
68static const int rates_altsetting[] = { 1, 1, 2, 2, 3, 3 };
69/* values to write to soundcard register for all samplerates */
70static const u16 rates_6fire_vl[] = {0x00, 0x01, 0x00, 0x01, 0x00, 0x01};
71static const u16 rates_6fire_vh[] = {0x11, 0x11, 0x10, 0x10, 0x00, 0x00};
72
73enum {
74 DIGITAL_THRU_ONLY_SAMPLERATE = 3
75};
76
77static void usb6fire_control_master_vol_update(struct control_runtime *rt)
78{
79 struct comm_runtime *comm_rt = rt->chip->comm;
80 if (comm_rt) {
81 /* set volume */
82 comm_rt->write8(comm_rt, 0x12, 0x0f, 0x7f -
83 log_volume_table[rt->master_vol]);
84 /* unmute */
85 comm_rt->write8(comm_rt, 0x12, 0x0e, 0x00);
86 }
87}
88
89static void usb6fire_control_line_phono_update(struct control_runtime *rt)
90{
91 struct comm_runtime *comm_rt = rt->chip->comm;
92 if (comm_rt) {
93 comm_rt->write8(comm_rt, 0x22, 0x02, rt->line_phono_switch);
94 comm_rt->write8(comm_rt, 0x21, 0x02, rt->line_phono_switch);
95 }
96}
97
98static void usb6fire_control_opt_coax_update(struct control_runtime *rt)
99{
100 struct comm_runtime *comm_rt = rt->chip->comm;
101 if (comm_rt) {
102 comm_rt->write8(comm_rt, 0x22, 0x00, rt->opt_coax_switch);
103 comm_rt->write8(comm_rt, 0x21, 0x00, rt->opt_coax_switch);
104 }
105}
106
107static int usb6fire_control_set_rate(struct control_runtime *rt, int rate)
108{
109 int ret;
110 struct usb_device *device = rt->chip->dev;
111 struct comm_runtime *comm_rt = rt->chip->comm;
112
113 if (rate < 0 || rate >= CONTROL_N_RATES)
114 return -EINVAL;
115
116 ret = usb_set_interface(device, 1, rates_altsetting[rate]);
117 if (ret < 0)
118 return ret;
119
120 /* set soundcard clock */
121 ret = comm_rt->write16(comm_rt, 0x02, 0x01, rates_6fire_vl[rate],
122 rates_6fire_vh[rate]);
123 if (ret < 0)
124 return ret;
125
126 return 0;
127}
128
129static int usb6fire_control_set_channels(
130 struct control_runtime *rt, int n_analog_out,
131 int n_analog_in, bool spdif_out, bool spdif_in)
132{
133 int ret;
134 struct comm_runtime *comm_rt = rt->chip->comm;
135
136 /* enable analog inputs and outputs
137 * (one bit per stereo-channel) */
138 ret = comm_rt->write16(comm_rt, 0x02, 0x02,
139 (1 << (n_analog_out / 2)) - 1,
140 (1 << (n_analog_in / 2)) - 1);
141 if (ret < 0)
142 return ret;
143
144 /* disable digital inputs and outputs */
145 /* TODO: use spdif_x to enable/disable digital channels */
146 ret = comm_rt->write16(comm_rt, 0x02, 0x03, 0x00, 0x00);
147 if (ret < 0)
148 return ret;
149
150 return 0;
151}
152
153static int usb6fire_control_streaming_update(struct control_runtime *rt)
154{
155 struct comm_runtime *comm_rt = rt->chip->comm;
156
157 if (comm_rt) {
158 if (!rt->usb_streaming && rt->digital_thru_switch)
159 usb6fire_control_set_rate(rt,
160 DIGITAL_THRU_ONLY_SAMPLERATE);
161 return comm_rt->write16(comm_rt, 0x02, 0x00, 0x00,
162 (rt->usb_streaming ? 0x01 : 0x00) |
163 (rt->digital_thru_switch ? 0x08 : 0x00));
164 }
165 return -EINVAL;
166}
167
168static int usb6fire_control_master_vol_info(struct snd_kcontrol *kcontrol,
169 struct snd_ctl_elem_info *uinfo)
170{
171 uinfo->type = SNDRV_CTL_ELEM_TYPE_INTEGER;
172 uinfo->count = 1;
173 uinfo->value.integer.min = 0;
174 uinfo->value.integer.max = 127;
175 return 0;
176}
177
178static int usb6fire_control_master_vol_put(struct snd_kcontrol *kcontrol,
179 struct snd_ctl_elem_value *ucontrol)
180{
181 struct control_runtime *rt = snd_kcontrol_chip(kcontrol);
182 int changed = 0;
183 if (rt->master_vol != ucontrol->value.integer.value[0]) {
184 rt->master_vol = ucontrol->value.integer.value[0];
185 usb6fire_control_master_vol_update(rt);
186 changed = 1;
187 }
188 return changed;
189}
190
191static int usb6fire_control_master_vol_get(struct snd_kcontrol *kcontrol,
192 struct snd_ctl_elem_value *ucontrol)
193{
194 struct control_runtime *rt = snd_kcontrol_chip(kcontrol);
195 ucontrol->value.integer.value[0] = rt->master_vol;
196 return 0;
197}
198
199static int usb6fire_control_line_phono_info(struct snd_kcontrol *kcontrol,
200 struct snd_ctl_elem_info *uinfo)
201{
202 uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED;
203 uinfo->count = 1;
204 uinfo->value.enumerated.items = 2;
205 if (uinfo->value.enumerated.item > 1)
206 uinfo->value.enumerated.item = 1;
207 strcpy(uinfo->value.enumerated.name,
208 line_phono_texts[uinfo->value.enumerated.item]);
209 return 0;
210}
211
212static int usb6fire_control_line_phono_put(struct snd_kcontrol *kcontrol,
213 struct snd_ctl_elem_value *ucontrol)
214{
215 struct control_runtime *rt = snd_kcontrol_chip(kcontrol);
216 int changed = 0;
217 if (rt->line_phono_switch != ucontrol->value.integer.value[0]) {
218 rt->line_phono_switch = ucontrol->value.integer.value[0];
219 usb6fire_control_line_phono_update(rt);
220 changed = 1;
221 }
222 return changed;
223}
224
225static int usb6fire_control_line_phono_get(struct snd_kcontrol *kcontrol,
226 struct snd_ctl_elem_value *ucontrol)
227{
228 struct control_runtime *rt = snd_kcontrol_chip(kcontrol);
229 ucontrol->value.integer.value[0] = rt->line_phono_switch;
230 return 0;
231}
232
233static int usb6fire_control_opt_coax_info(struct snd_kcontrol *kcontrol,
234 struct snd_ctl_elem_info *uinfo)
235{
236 uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED;
237 uinfo->count = 1;
238 uinfo->value.enumerated.items = 2;
239 if (uinfo->value.enumerated.item > 1)
240 uinfo->value.enumerated.item = 1;
241 strcpy(uinfo->value.enumerated.name,
242 opt_coax_texts[uinfo->value.enumerated.item]);
243 return 0;
244}
245
246static int usb6fire_control_opt_coax_put(struct snd_kcontrol *kcontrol,
247 struct snd_ctl_elem_value *ucontrol)
248{
249 struct control_runtime *rt = snd_kcontrol_chip(kcontrol);
250 int changed = 0;
251
252 if (rt->opt_coax_switch != ucontrol->value.enumerated.item[0]) {
253 rt->opt_coax_switch = ucontrol->value.enumerated.item[0];
254 usb6fire_control_opt_coax_update(rt);
255 changed = 1;
256 }
257 return changed;
258}
259
260static int usb6fire_control_opt_coax_get(struct snd_kcontrol *kcontrol,
261 struct snd_ctl_elem_value *ucontrol)
262{
263 struct control_runtime *rt = snd_kcontrol_chip(kcontrol);
264 ucontrol->value.enumerated.item[0] = rt->opt_coax_switch;
265 return 0;
266}
267
268static int usb6fire_control_digital_thru_put(struct snd_kcontrol *kcontrol,
269 struct snd_ctl_elem_value *ucontrol)
270{
271 struct control_runtime *rt = snd_kcontrol_chip(kcontrol);
272 int changed = 0;
273
274 if (rt->digital_thru_switch != ucontrol->value.integer.value[0]) {
275 rt->digital_thru_switch = ucontrol->value.integer.value[0];
276 usb6fire_control_streaming_update(rt);
277 changed = 1;
278 }
279 return changed;
280}
281
282static int usb6fire_control_digital_thru_get(struct snd_kcontrol *kcontrol,
283 struct snd_ctl_elem_value *ucontrol)
284{
285 struct control_runtime *rt = snd_kcontrol_chip(kcontrol);
286 ucontrol->value.integer.value[0] = rt->digital_thru_switch;
287 return 0;
288}
289
290static struct __devinitdata snd_kcontrol_new elements[] = {
291 {
292 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
293 .name = "Master Playback Volume",
294 .index = 0,
295 .access = SNDRV_CTL_ELEM_ACCESS_READWRITE,
296 .info = usb6fire_control_master_vol_info,
297 .get = usb6fire_control_master_vol_get,
298 .put = usb6fire_control_master_vol_put
299 },
300 {
301 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
302 .name = "Line/Phono Capture Route",
303 .index = 0,
304 .access = SNDRV_CTL_ELEM_ACCESS_READWRITE,
305 .info = usb6fire_control_line_phono_info,
306 .get = usb6fire_control_line_phono_get,
307 .put = usb6fire_control_line_phono_put
308 },
309 {
310 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
311 .name = "Opt/Coax Capture Route",
312 .index = 0,
313 .access = SNDRV_CTL_ELEM_ACCESS_READWRITE,
314 .info = usb6fire_control_opt_coax_info,
315 .get = usb6fire_control_opt_coax_get,
316 .put = usb6fire_control_opt_coax_put
317 },
318 {
319 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
320 .name = "Digital Thru Playback Route",
321 .index = 0,
322 .access = SNDRV_CTL_ELEM_ACCESS_READWRITE,
323 .info = snd_ctl_boolean_mono_info,
324 .get = usb6fire_control_digital_thru_get,
325 .put = usb6fire_control_digital_thru_put
326 },
327 {}
328};
329
330int __devinit usb6fire_control_init(struct sfire_chip *chip)
331{
332 int i;
333 int ret;
334 struct control_runtime *rt = kzalloc(sizeof(struct control_runtime),
335 GFP_KERNEL);
336 struct comm_runtime *comm_rt = chip->comm;
337
338 if (!rt)
339 return -ENOMEM;
340
341 rt->chip = chip;
342 rt->update_streaming = usb6fire_control_streaming_update;
343 rt->set_rate = usb6fire_control_set_rate;
344 rt->set_channels = usb6fire_control_set_channels;
345
346 i = 0;
347 while (init_data[i].type) {
348 comm_rt->write8(comm_rt, init_data[i].type, init_data[i].reg,
349 init_data[i].value);
350 i++;
351 }
352
353 usb6fire_control_opt_coax_update(rt);
354 usb6fire_control_line_phono_update(rt);
355 usb6fire_control_master_vol_update(rt);
356 usb6fire_control_streaming_update(rt);
357
358 i = 0;
359 while (elements[i].name) {
360 ret = snd_ctl_add(chip->card, snd_ctl_new1(&elements[i], rt));
361 if (ret < 0) {
362 kfree(rt);
363 snd_printk(KERN_ERR PREFIX "cannot add control.\n");
364 return ret;
365 }
366 i++;
367 }
368
369 chip->control = rt;
370 return 0;
371}
372
373void usb6fire_control_abort(struct sfire_chip *chip)
374{}
375
376void usb6fire_control_destroy(struct sfire_chip *chip)
377{
378 kfree(chip->control);
379 chip->control = NULL;
380}
diff --git a/sound/usb/6fire/control.h b/sound/usb/6fire/control.h
new file mode 100644
index 000000000000..8f5aeead2e3d
--- /dev/null
+++ b/sound/usb/6fire/control.h
@@ -0,0 +1,54 @@
1/*
2 * Linux driver for TerraTec DMX 6Fire USB
3 *
4 * Author: Torsten Schenk <torsten.schenk@zoho.com>
5 * Created: Jan 01, 2011
6 * Version: 0.3.0
7 * Copyright: (C) Torsten Schenk
8 *
9 * This program is free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License as published by
11 * the Free Software Foundation; either version 2 of the License, or
12 * (at your option) any later version.
13 */
14
15#ifndef USB6FIRE_CONTROL_H
16#define USB6FIRE_CONTROL_H
17
18#include "common.h"
19
20enum {
21 CONTROL_MAX_ELEMENTS = 32
22};
23
24enum {
25 CONTROL_RATE_44KHZ,
26 CONTROL_RATE_48KHZ,
27 CONTROL_RATE_88KHZ,
28 CONTROL_RATE_96KHZ,
29 CONTROL_RATE_176KHZ,
30 CONTROL_RATE_192KHZ,
31 CONTROL_N_RATES
32};
33
34struct control_runtime {
35 int (*update_streaming)(struct control_runtime *rt);
36 int (*set_rate)(struct control_runtime *rt, int rate);
37 int (*set_channels)(struct control_runtime *rt, int n_analog_out,
38 int n_analog_in, bool spdif_out, bool spdif_in);
39
40 struct sfire_chip *chip;
41
42 struct snd_kcontrol *element[CONTROL_MAX_ELEMENTS];
43 bool opt_coax_switch;
44 bool line_phono_switch;
45 bool digital_thru_switch;
46 bool usb_streaming;
47 u8 master_vol;
48};
49
50int __devinit usb6fire_control_init(struct sfire_chip *chip);
51void usb6fire_control_abort(struct sfire_chip *chip);
52void usb6fire_control_destroy(struct sfire_chip *chip);
53#endif /* USB6FIRE_CONTROL_H */
54
diff --git a/sound/usb/6fire/firmware.c b/sound/usb/6fire/firmware.c
new file mode 100644
index 000000000000..1e3ae3327dd3
--- /dev/null
+++ b/sound/usb/6fire/firmware.c
@@ -0,0 +1,419 @@
1/*
2 * Linux driver for TerraTec DMX 6Fire USB
3 *
4 * Firmware loader
5 *
6 * Author: Torsten Schenk <torsten.schenk@zoho.com>
7 * Created: Jan 01, 2011
8 * Version: 0.3.0
9 * Copyright: (C) Torsten Schenk
10 *
11 * This program is free software; you can redistribute it and/or modify
12 * it under the terms of the GNU General Public License as published by
13 * the Free Software Foundation; either version 2 of the License, or
14 * (at your option) any later version.
15 */
16
17#include <linux/firmware.h>
18#include <linux/bitrev.h>
19
20#include "firmware.h"
21#include "chip.h"
22
23MODULE_FIRMWARE("6fire/dmx6firel2.ihx");
24MODULE_FIRMWARE("6fire/dmx6fireap.ihx");
25MODULE_FIRMWARE("6fire/dmx6firecf.bin");
26
27enum {
28 FPGA_BUFSIZE = 512, FPGA_EP = 2
29};
30
31/*
32 * wMaxPacketSize of pcm endpoints.
33 * keep synced with rates_in_packet_size and rates_out_packet_size in pcm.c
34 * fpp: frames per isopacket
35 *
36 * CAUTION: keep sizeof <= buffer[] in usb6fire_fw_init
37 */
38static const u8 ep_w_max_packet_size[] = {
39 0xe4, 0x00, 0xe4, 0x00, /* alt 1: 228 EP2 and EP6 (7 fpp) */
40 0xa4, 0x01, 0xa4, 0x01, /* alt 2: 420 EP2 and EP6 (13 fpp)*/
41 0x94, 0x01, 0x5c, 0x02 /* alt 3: 404 EP2 and 604 EP6 (25 fpp) */
42};
43
44static const u8 known_fw_versions[][4] = {
45 { 0x03, 0x01, 0x0b, 0x00 }
46};
47
48struct ihex_record {
49 u16 address;
50 u8 len;
51 u8 data[256];
52 char error; /* true if an error occurred parsing this record */
53
54 u8 max_len; /* maximum record length in whole ihex */
55
56 /* private */
57 const char *txt_data;
58 unsigned int txt_length;
59 unsigned int txt_offset; /* current position in txt_data */
60};
61
62static u8 usb6fire_fw_ihex_nibble(const u8 n)
63{
64 if (n >= '0' && n <= '9')
65 return n - '0';
66 else if (n >= 'A' && n <= 'F')
67 return n - ('A' - 10);
68 else if (n >= 'a' && n <= 'f')
69 return n - ('a' - 10);
70 return 0;
71}
72
73static u8 usb6fire_fw_ihex_hex(const u8 *data, u8 *crc)
74{
75 u8 val = (usb6fire_fw_ihex_nibble(data[0]) << 4) |
76 usb6fire_fw_ihex_nibble(data[1]);
77 *crc += val;
78 return val;
79}
80
81/*
82 * returns true if record is available, false otherwise.
83 * iff an error occurred, false will be returned and record->error will be true.
84 */
85static bool usb6fire_fw_ihex_next_record(struct ihex_record *record)
86{
87 u8 crc = 0;
88 u8 type;
89 int i;
90
91 record->error = false;
92
93 /* find begin of record (marked by a colon) */
94 while (record->txt_offset < record->txt_length
95 && record->txt_data[record->txt_offset] != ':')
96 record->txt_offset++;
97 if (record->txt_offset == record->txt_length)
98 return false;
99
100 /* number of characters needed for len, addr and type entries */
101 record->txt_offset++;
102 if (record->txt_offset + 8 > record->txt_length) {
103 record->error = true;
104 return false;
105 }
106
107 record->len = usb6fire_fw_ihex_hex(record->txt_data +
108 record->txt_offset, &crc);
109 record->txt_offset += 2;
110 record->address = usb6fire_fw_ihex_hex(record->txt_data +
111 record->txt_offset, &crc) << 8;
112 record->txt_offset += 2;
113 record->address |= usb6fire_fw_ihex_hex(record->txt_data +
114 record->txt_offset, &crc);
115 record->txt_offset += 2;
116 type = usb6fire_fw_ihex_hex(record->txt_data +
117 record->txt_offset, &crc);
118 record->txt_offset += 2;
119
120 /* number of characters needed for data and crc entries */
121 if (record->txt_offset + 2 * (record->len + 1) > record->txt_length) {
122 record->error = true;
123 return false;
124 }
125 for (i = 0; i < record->len; i++) {
126 record->data[i] = usb6fire_fw_ihex_hex(record->txt_data
127 + record->txt_offset, &crc);
128 record->txt_offset += 2;
129 }
130 usb6fire_fw_ihex_hex(record->txt_data + record->txt_offset, &crc);
131 if (crc) {
132 record->error = true;
133 return false;
134 }
135
136 if (type == 1 || !record->len) /* eof */
137 return false;
138 else if (type == 0)
139 return true;
140 else {
141 record->error = true;
142 return false;
143 }
144}
145
146static int usb6fire_fw_ihex_init(const struct firmware *fw,
147 struct ihex_record *record)
148{
149 record->txt_data = fw->data;
150 record->txt_length = fw->size;
151 record->txt_offset = 0;
152 record->max_len = 0;
153 /* read all records, if loop ends, record->error indicates,
154 * whether ihex is valid. */
155 while (usb6fire_fw_ihex_next_record(record))
156 record->max_len = max(record->len, record->max_len);
157 if (record->error)
158 return -EINVAL;
159 record->txt_offset = 0;
160 return 0;
161}
162
163static int usb6fire_fw_ezusb_write(struct usb_device *device,
164 int type, int value, char *data, int len)
165{
166 int ret;
167
168 ret = usb_control_msg(device, usb_sndctrlpipe(device, 0), type,
169 USB_DIR_OUT | USB_TYPE_VENDOR | USB_RECIP_DEVICE,
170 value, 0, data, len, HZ);
171 if (ret < 0)
172 return ret;
173 else if (ret != len)
174 return -EIO;
175 return 0;
176}
177
178static int usb6fire_fw_ezusb_read(struct usb_device *device,
179 int type, int value, char *data, int len)
180{
181 int ret = usb_control_msg(device, usb_rcvctrlpipe(device, 0), type,
182 USB_DIR_IN | USB_TYPE_VENDOR | USB_RECIP_DEVICE, value,
183 0, data, len, HZ);
184 if (ret < 0)
185 return ret;
186 else if (ret != len)
187 return -EIO;
188 return 0;
189}
190
191static int usb6fire_fw_fpga_write(struct usb_device *device,
192 char *data, int len)
193{
194 int actual_len;
195 int ret;
196
197 ret = usb_bulk_msg(device, usb_sndbulkpipe(device, FPGA_EP), data, len,
198 &actual_len, HZ);
199 if (ret < 0)
200 return ret;
201 else if (actual_len != len)
202 return -EIO;
203 return 0;
204}
205
206static int usb6fire_fw_ezusb_upload(
207 struct usb_interface *intf, const char *fwname,
208 unsigned int postaddr, u8 *postdata, unsigned int postlen)
209{
210 int ret;
211 u8 data;
212 struct usb_device *device = interface_to_usbdev(intf);
213 const struct firmware *fw = 0;
214 struct ihex_record *rec = kmalloc(sizeof(struct ihex_record),
215 GFP_KERNEL);
216
217 if (!rec)
218 return -ENOMEM;
219
220 ret = request_firmware(&fw, fwname, &device->dev);
221 if (ret < 0) {
222 kfree(rec);
223 snd_printk(KERN_ERR PREFIX "error requesting ezusb "
224 "firmware %s.\n", fwname);
225 return ret;
226 }
227 ret = usb6fire_fw_ihex_init(fw, rec);
228 if (ret < 0) {
229 kfree(rec);
230 release_firmware(fw);
231 snd_printk(KERN_ERR PREFIX "error validating ezusb "
232 "firmware %s.\n", fwname);
233 return ret;
234 }
235 /* upload firmware image */
236 data = 0x01; /* stop ezusb cpu */
237 ret = usb6fire_fw_ezusb_write(device, 0xa0, 0xe600, &data, 1);
238 if (ret < 0) {
239 kfree(rec);
240 release_firmware(fw);
241 snd_printk(KERN_ERR PREFIX "unable to upload ezusb "
242 "firmware %s: begin message.\n", fwname);
243 return ret;
244 }
245
246 while (usb6fire_fw_ihex_next_record(rec)) { /* write firmware */
247 ret = usb6fire_fw_ezusb_write(device, 0xa0, rec->address,
248 rec->data, rec->len);
249 if (ret < 0) {
250 kfree(rec);
251 release_firmware(fw);
252 snd_printk(KERN_ERR PREFIX "unable to upload ezusb "
253 "firmware %s: data urb.\n", fwname);
254 return ret;
255 }
256 }
257
258 release_firmware(fw);
259 kfree(rec);
260 if (postdata) { /* write data after firmware has been uploaded */
261 ret = usb6fire_fw_ezusb_write(device, 0xa0, postaddr,
262 postdata, postlen);
263 if (ret < 0) {
264 snd_printk(KERN_ERR PREFIX "unable to upload ezusb "
265 "firmware %s: post urb.\n", fwname);
266 return ret;
267 }
268 }
269
270 data = 0x00; /* resume ezusb cpu */
271 ret = usb6fire_fw_ezusb_write(device, 0xa0, 0xe600, &data, 1);
272 if (ret < 0) {
273 snd_printk(KERN_ERR PREFIX "unable to upload ezusb "
274 "firmware %s: end message.\n", fwname);
275 return ret;
276 }
277 return 0;
278}
279
280static int usb6fire_fw_fpga_upload(
281 struct usb_interface *intf, const char *fwname)
282{
283 int ret;
284 int i;
285 struct usb_device *device = interface_to_usbdev(intf);
286 u8 *buffer = kmalloc(FPGA_BUFSIZE, GFP_KERNEL);
287 const char *c;
288 const char *end;
289 const struct firmware *fw;
290
291 if (!buffer)
292 return -ENOMEM;
293
294 ret = request_firmware(&fw, fwname, &device->dev);
295 if (ret < 0) {
296 snd_printk(KERN_ERR PREFIX "unable to get fpga firmware %s.\n",
297 fwname);
298 kfree(buffer);
299 return -EIO;
300 }
301
302 c = fw->data;
303 end = fw->data + fw->size;
304
305 ret = usb6fire_fw_ezusb_write(device, 8, 0, NULL, 0);
306 if (ret < 0) {
307 kfree(buffer);
308 release_firmware(fw);
309 snd_printk(KERN_ERR PREFIX "unable to upload fpga firmware: "
310 "begin urb.\n");
311 return ret;
312 }
313
314 while (c != end) {
315 for (i = 0; c != end && i < FPGA_BUFSIZE; i++, c++)
316 buffer[i] = byte_rev_table[(u8) *c];
317
318 ret = usb6fire_fw_fpga_write(device, buffer, i);
319 if (ret < 0) {
320 release_firmware(fw);
321 kfree(buffer);
322 snd_printk(KERN_ERR PREFIX "unable to upload fpga "
323 "firmware: fw urb.\n");
324 return ret;
325 }
326 }
327 release_firmware(fw);
328 kfree(buffer);
329
330 ret = usb6fire_fw_ezusb_write(device, 9, 0, NULL, 0);
331 if (ret < 0) {
332 snd_printk(KERN_ERR PREFIX "unable to upload fpga firmware: "
333 "end urb.\n");
334 return ret;
335 }
336 return 0;
337}
338
339/* check, if the firmware version the devices has currently loaded
340 * is known by this driver. 'version' needs to have 4 bytes version
341 * info data. */
342static int usb6fire_fw_check(u8 *version)
343{
344 int i;
345
346 for (i = 0; i < ARRAY_SIZE(known_fw_versions); i++)
347 if (!memcmp(version, known_fw_versions + i, 4))
348 return 0;
349
350 snd_printk(KERN_ERR PREFIX "invalid fimware version in device: "
351 "%02x %02x %02x %02x. "
352 "please reconnect to power. if this failure "
353 "still happens, check your firmware installation.",
354 version[0], version[1], version[2], version[3]);
355 return -EINVAL;
356}
357
358int usb6fire_fw_init(struct usb_interface *intf)
359{
360 int i;
361 int ret;
362 struct usb_device *device = interface_to_usbdev(intf);
363 /* buffer: 8 receiving bytes from device and
364 * sizeof(EP_W_MAX_PACKET_SIZE) bytes for non-const copy */
365 u8 buffer[12];
366
367 ret = usb6fire_fw_ezusb_read(device, 1, 0, buffer, 8);
368 if (ret < 0) {
369 snd_printk(KERN_ERR PREFIX "unable to receive device "
370 "firmware state.\n");
371 return ret;
372 }
373 if (buffer[0] != 0xeb || buffer[1] != 0xaa || buffer[2] != 0x55) {
374 snd_printk(KERN_ERR PREFIX "unknown device firmware state "
375 "received from device: ");
376 for (i = 0; i < 8; i++)
377 snd_printk("%02x ", buffer[i]);
378 snd_printk("\n");
379 return -EIO;
380 }
381 /* do we need fpga loader ezusb firmware? */
382 if (buffer[3] == 0x01) {
383 ret = usb6fire_fw_ezusb_upload(intf,
384 "6fire/dmx6firel2.ihx", 0, NULL, 0);
385 if (ret < 0)
386 return ret;
387 return FW_NOT_READY;
388 }
389 /* do we need fpga firmware and application ezusb firmware? */
390 else if (buffer[3] == 0x02) {
391 ret = usb6fire_fw_check(buffer + 4);
392 if (ret < 0)
393 return ret;
394 ret = usb6fire_fw_fpga_upload(intf, "6fire/dmx6firecf.bin");
395 if (ret < 0)
396 return ret;
397 memcpy(buffer, ep_w_max_packet_size,
398 sizeof(ep_w_max_packet_size));
399 ret = usb6fire_fw_ezusb_upload(intf, "6fire/dmx6fireap.ihx",
400 0x0003, buffer, sizeof(ep_w_max_packet_size));
401 if (ret < 0)
402 return ret;
403 return FW_NOT_READY;
404 }
405 /* all fw loaded? */
406 else if (buffer[3] == 0x03)
407 return usb6fire_fw_check(buffer + 4);
408 /* unknown data? */
409 else {
410 snd_printk(KERN_ERR PREFIX "unknown device firmware state "
411 "received from device: ");
412 for (i = 0; i < 8; i++)
413 snd_printk("%02x ", buffer[i]);
414 snd_printk("\n");
415 return -EIO;
416 }
417 return 0;
418}
419
diff --git a/sound/usb/6fire/firmware.h b/sound/usb/6fire/firmware.h
new file mode 100644
index 000000000000..008569895381
--- /dev/null
+++ b/sound/usb/6fire/firmware.h
@@ -0,0 +1,27 @@
1/*
2 * Linux driver for TerraTec DMX 6Fire USB
3 *
4 * Author: Torsten Schenk
5 * Created: Jan 01, 2011
6 * Copyright: (C) Torsten Schenk
7 *
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; either version 2 of the License, or
11 * (at your option) any later version.
12 */
13
14#ifndef USB6FIRE_FIRMWARE_H
15#define USB6FIRE_FIRMWARE_H
16
17#include "common.h"
18
19enum /* firmware state of device */
20{
21 FW_READY = 0,
22 FW_NOT_READY = 1
23};
24
25int __devinit usb6fire_fw_init(struct usb_interface *intf);
26#endif /* USB6FIRE_FIRMWARE_H */
27
diff --git a/sound/usb/6fire/midi.c b/sound/usb/6fire/midi.c
new file mode 100644
index 000000000000..13f4509dce2b
--- /dev/null
+++ b/sound/usb/6fire/midi.c
@@ -0,0 +1,203 @@
1/*
2 * Linux driver for TerraTec DMX 6Fire USB
3 *
4 * Rawmidi driver
5 *
6 * Author: Torsten Schenk <torsten.schenk@zoho.com>
7 * Created: Jan 01, 2011
8 * Version: 0.3.0
9 * Copyright: (C) Torsten Schenk
10 *
11 * This program is free software; you can redistribute it and/or modify
12 * it under the terms of the GNU General Public License as published by
13 * the Free Software Foundation; either version 2 of the License, or
14 * (at your option) any later version.
15 */
16
17#include <sound/rawmidi.h>
18
19#include "midi.h"
20#include "chip.h"
21#include "comm.h"
22
23static void usb6fire_midi_out_handler(struct urb *urb)
24{
25 struct midi_runtime *rt = urb->context;
26 int ret;
27 unsigned long flags;
28
29 spin_lock_irqsave(&rt->out_lock, flags);
30
31 if (rt->out) {
32 ret = snd_rawmidi_transmit(rt->out, rt->out_buffer + 4,
33 MIDI_BUFSIZE - 4);
34 if (ret > 0) { /* more data available, send next packet */
35 rt->out_buffer[1] = ret + 2;
36 rt->out_buffer[3] = rt->out_serial++;
37 urb->transfer_buffer_length = ret + 4;
38
39 ret = usb_submit_urb(urb, GFP_ATOMIC);
40 if (ret < 0)
41 snd_printk(KERN_ERR PREFIX "midi out urb "
42 "submit failed: %d\n", ret);
43 } else /* no more data to transmit */
44 rt->out = NULL;
45 }
46 spin_unlock_irqrestore(&rt->out_lock, flags);
47}
48
49static void usb6fire_midi_in_received(
50 struct midi_runtime *rt, u8 *data, int length)
51{
52 unsigned long flags;
53
54 spin_lock_irqsave(&rt->in_lock, flags);
55 if (rt->in)
56 snd_rawmidi_receive(rt->in, data, length);
57 spin_unlock_irqrestore(&rt->in_lock, flags);
58}
59
60static int usb6fire_midi_out_open(struct snd_rawmidi_substream *alsa_sub)
61{
62 return 0;
63}
64
65static int usb6fire_midi_out_close(struct snd_rawmidi_substream *alsa_sub)
66{
67 return 0;
68}
69
70static void usb6fire_midi_out_trigger(
71 struct snd_rawmidi_substream *alsa_sub, int up)
72{
73 struct midi_runtime *rt = alsa_sub->rmidi->private_data;
74 struct urb *urb = &rt->out_urb;
75 __s8 ret;
76 unsigned long flags;
77
78 spin_lock_irqsave(&rt->out_lock, flags);
79 if (up) { /* start transfer */
80 if (rt->out) { /* we are already transmitting so just return */
81 spin_unlock_irqrestore(&rt->out_lock, flags);
82 return;
83 }
84
85 ret = snd_rawmidi_transmit(alsa_sub, rt->out_buffer + 4,
86 MIDI_BUFSIZE - 4);
87 if (ret > 0) {
88 rt->out_buffer[1] = ret + 2;
89 rt->out_buffer[3] = rt->out_serial++;
90 urb->transfer_buffer_length = ret + 4;
91
92 ret = usb_submit_urb(urb, GFP_ATOMIC);
93 if (ret < 0)
94 snd_printk(KERN_ERR PREFIX "midi out urb "
95 "submit failed: %d\n", ret);
96 else
97 rt->out = alsa_sub;
98 }
99 } else if (rt->out == alsa_sub)
100 rt->out = NULL;
101 spin_unlock_irqrestore(&rt->out_lock, flags);
102}
103
104static void usb6fire_midi_out_drain(struct snd_rawmidi_substream *alsa_sub)
105{
106 struct midi_runtime *rt = alsa_sub->rmidi->private_data;
107 int retry = 0;
108
109 while (rt->out && retry++ < 100)
110 msleep(10);
111}
112
113static int usb6fire_midi_in_open(struct snd_rawmidi_substream *alsa_sub)
114{
115 return 0;
116}
117
118static int usb6fire_midi_in_close(struct snd_rawmidi_substream *alsa_sub)
119{
120 return 0;
121}
122
123static void usb6fire_midi_in_trigger(
124 struct snd_rawmidi_substream *alsa_sub, int up)
125{
126 struct midi_runtime *rt = alsa_sub->rmidi->private_data;
127 unsigned long flags;
128
129 spin_lock_irqsave(&rt->in_lock, flags);
130 if (up)
131 rt->in = alsa_sub;
132 else
133 rt->in = NULL;
134 spin_unlock_irqrestore(&rt->in_lock, flags);
135}
136
137static struct snd_rawmidi_ops out_ops = {
138 .open = usb6fire_midi_out_open,
139 .close = usb6fire_midi_out_close,
140 .trigger = usb6fire_midi_out_trigger,
141 .drain = usb6fire_midi_out_drain
142};
143
144static struct snd_rawmidi_ops in_ops = {
145 .open = usb6fire_midi_in_open,
146 .close = usb6fire_midi_in_close,
147 .trigger = usb6fire_midi_in_trigger
148};
149
150int __devinit usb6fire_midi_init(struct sfire_chip *chip)
151{
152 int ret;
153 struct midi_runtime *rt = kzalloc(sizeof(struct midi_runtime),
154 GFP_KERNEL);
155 struct comm_runtime *comm_rt = chip->comm;
156
157 if (!rt)
158 return -ENOMEM;
159
160 rt->chip = chip;
161 rt->in_received = usb6fire_midi_in_received;
162 rt->out_buffer[0] = 0x80; /* 'send midi' command */
163 rt->out_buffer[1] = 0x00; /* size of data */
164 rt->out_buffer[2] = 0x00; /* always 0 */
165 spin_lock_init(&rt->in_lock);
166 spin_lock_init(&rt->out_lock);
167
168 comm_rt->init_urb(comm_rt, &rt->out_urb, rt->out_buffer, rt,
169 usb6fire_midi_out_handler);
170
171 ret = snd_rawmidi_new(chip->card, "6FireUSB", 0, 1, 1, &rt->instance);
172 if (ret < 0) {
173 kfree(rt);
174 snd_printk(KERN_ERR PREFIX "unable to create midi.\n");
175 return ret;
176 }
177 rt->instance->private_data = rt;
178 strcpy(rt->instance->name, "DMX6FireUSB MIDI");
179 rt->instance->info_flags = SNDRV_RAWMIDI_INFO_OUTPUT |
180 SNDRV_RAWMIDI_INFO_INPUT |
181 SNDRV_RAWMIDI_INFO_DUPLEX;
182 snd_rawmidi_set_ops(rt->instance, SNDRV_RAWMIDI_STREAM_OUTPUT,
183 &out_ops);
184 snd_rawmidi_set_ops(rt->instance, SNDRV_RAWMIDI_STREAM_INPUT,
185 &in_ops);
186
187 chip->midi = rt;
188 return 0;
189}
190
191void usb6fire_midi_abort(struct sfire_chip *chip)
192{
193 struct midi_runtime *rt = chip->midi;
194
195 if (rt)
196 usb_poison_urb(&rt->out_urb);
197}
198
199void usb6fire_midi_destroy(struct sfire_chip *chip)
200{
201 kfree(chip->midi);
202 chip->midi = NULL;
203}
diff --git a/sound/usb/6fire/midi.h b/sound/usb/6fire/midi.h
new file mode 100644
index 000000000000..97a7bf669135
--- /dev/null
+++ b/sound/usb/6fire/midi.h
@@ -0,0 +1,46 @@
1/*
2 * Linux driver for TerraTec DMX 6Fire USB
3 *
4 * Author: Torsten Schenk <torsten.schenk@zoho.com>
5 * Created: Jan 01, 2011
6 * Version: 0.3.0
7 * Copyright: (C) Torsten Schenk
8 *
9 * This program is free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License as published by
11 * the Free Software Foundation; either version 2 of the License, or
12 * (at your option) any later version.
13 */
14
15#ifndef USB6FIRE_MIDI_H
16#define USB6FIRE_MIDI_H
17
18#include "common.h"
19
20enum {
21 MIDI_BUFSIZE = 64
22};
23
24struct midi_runtime {
25 struct sfire_chip *chip;
26 struct snd_rawmidi *instance;
27
28 struct snd_rawmidi_substream *in;
29 char in_active;
30
31 spinlock_t in_lock;
32 spinlock_t out_lock;
33 struct snd_rawmidi_substream *out;
34 struct urb out_urb;
35 u8 out_serial; /* serial number of out packet */
36 u8 out_buffer[MIDI_BUFSIZE];
37 int buffer_offset;
38
39 void (*in_received)(struct midi_runtime *rt, u8 *data, int length);
40};
41
42int __devinit usb6fire_midi_init(struct sfire_chip *chip);
43void usb6fire_midi_abort(struct sfire_chip *chip);
44void usb6fire_midi_destroy(struct sfire_chip *chip);
45#endif /* USB6FIRE_MIDI_H */
46
diff --git a/sound/usb/6fire/pcm.c b/sound/usb/6fire/pcm.c
new file mode 100644
index 000000000000..d144cdb2f159
--- /dev/null
+++ b/sound/usb/6fire/pcm.c
@@ -0,0 +1,667 @@
1/*
2 * Linux driver for TerraTec DMX 6Fire USB
3 *
4 * PCM driver
5 *
6 * Author: Torsten Schenk <torsten.schenk@zoho.com>
7 * Created: Jan 01, 2011
8 * Version: 0.3.0
9 * Copyright: (C) Torsten Schenk
10 *
11 * This program is free software; you can redistribute it and/or modify
12 * it under the terms of the GNU General Public License as published by
13 * the Free Software Foundation; either version 2 of the License, or
14 * (at your option) any later version.
15 */
16
17#include "pcm.h"
18#include "chip.h"
19#include "comm.h"
20#include "control.h"
21
22enum {
23 OUT_N_CHANNELS = 6, IN_N_CHANNELS = 4
24};
25
26/* keep next two synced with
27 * FW_EP_W_MAX_PACKET_SIZE[] and RATES_MAX_PACKET_SIZE
28 * and CONTROL_RATE_XXX in control.h */
29static const int rates_in_packet_size[] = { 228, 228, 420, 420, 404, 404 };
30static const int rates_out_packet_size[] = { 228, 228, 420, 420, 604, 604 };
31static const int rates[] = { 44100, 48000, 88200, 96000, 176400, 192000 };
32static const int rates_alsaid[] = {
33 SNDRV_PCM_RATE_44100, SNDRV_PCM_RATE_48000,
34 SNDRV_PCM_RATE_88200, SNDRV_PCM_RATE_96000,
35 SNDRV_PCM_RATE_176400, SNDRV_PCM_RATE_192000 };
36
37enum { /* settings for pcm */
38 OUT_EP = 6, IN_EP = 2, MAX_BUFSIZE = 128 * 1024
39};
40
41enum { /* pcm streaming states */
42 STREAM_DISABLED, /* no pcm streaming */
43 STREAM_STARTING, /* pcm streaming requested, waiting to become ready */
44 STREAM_RUNNING, /* pcm streaming running */
45 STREAM_STOPPING
46};
47
48static const struct snd_pcm_hardware pcm_hw = {
49 .info = SNDRV_PCM_INFO_MMAP |
50 SNDRV_PCM_INFO_INTERLEAVED |
51 SNDRV_PCM_INFO_BLOCK_TRANSFER |
52 SNDRV_PCM_INFO_MMAP_VALID |
53 SNDRV_PCM_INFO_BATCH,
54
55 .formats = SNDRV_PCM_FMTBIT_S24_LE | SNDRV_PCM_FMTBIT_S32_LE,
56
57 .rates = SNDRV_PCM_RATE_44100 |
58 SNDRV_PCM_RATE_48000 |
59 SNDRV_PCM_RATE_88200 |
60 SNDRV_PCM_RATE_96000 |
61 SNDRV_PCM_RATE_176400 |
62 SNDRV_PCM_RATE_192000,
63
64 .rate_min = 44100,
65 .rate_max = 192000,
66 .channels_min = 1,
67 .channels_max = 0, /* set in pcm_open, depending on capture/playback */
68 .buffer_bytes_max = MAX_BUFSIZE,
69 .period_bytes_min = PCM_N_PACKETS_PER_URB * (PCM_MAX_PACKET_SIZE - 4),
70 .period_bytes_max = MAX_BUFSIZE,
71 .periods_min = 2,
72 .periods_max = 1024
73};
74
75static int usb6fire_pcm_set_rate(struct pcm_runtime *rt)
76{
77 int ret;
78 struct control_runtime *ctrl_rt = rt->chip->control;
79
80 ctrl_rt->usb_streaming = false;
81 ret = ctrl_rt->update_streaming(ctrl_rt);
82 if (ret < 0) {
83 snd_printk(KERN_ERR PREFIX "error stopping streaming while "
84 "setting samplerate %d.\n", rates[rt->rate]);
85 return ret;
86 }
87
88 ret = ctrl_rt->set_rate(ctrl_rt, rt->rate);
89 if (ret < 0) {
90 snd_printk(KERN_ERR PREFIX "error setting samplerate %d.\n",
91 rates[rt->rate]);
92 return ret;
93 }
94
95 ret = ctrl_rt->set_channels(ctrl_rt, OUT_N_CHANNELS, IN_N_CHANNELS,
96 false, false);
97 if (ret < 0) {
98 snd_printk(KERN_ERR PREFIX "error initializing channels "
99 "while setting samplerate %d.\n",
100 rates[rt->rate]);
101 return ret;
102 }
103
104 ctrl_rt->usb_streaming = true;
105 ret = ctrl_rt->update_streaming(ctrl_rt);
106 if (ret < 0) {
107 snd_printk(KERN_ERR PREFIX "error starting streaming while "
108 "setting samplerate %d.\n", rates[rt->rate]);
109 return ret;
110 }
111
112 rt->in_n_analog = IN_N_CHANNELS;
113 rt->out_n_analog = OUT_N_CHANNELS;
114 rt->in_packet_size = rates_in_packet_size[rt->rate];
115 rt->out_packet_size = rates_out_packet_size[rt->rate];
116 return 0;
117}
118
119static struct pcm_substream *usb6fire_pcm_get_substream(
120 struct snd_pcm_substream *alsa_sub)
121{
122 struct pcm_runtime *rt = snd_pcm_substream_chip(alsa_sub);
123
124 if (alsa_sub->stream == SNDRV_PCM_STREAM_PLAYBACK)
125 return &rt->playback;
126 else if (alsa_sub->stream == SNDRV_PCM_STREAM_CAPTURE)
127 return &rt->capture;
128 snd_printk(KERN_ERR PREFIX "error getting pcm substream slot.\n");
129 return NULL;
130}
131
132/* call with stream_mutex locked */
133static void usb6fire_pcm_stream_stop(struct pcm_runtime *rt)
134{
135 int i;
136 struct control_runtime *ctrl_rt = rt->chip->control;
137
138 if (rt->stream_state != STREAM_DISABLED) {
139 for (i = 0; i < PCM_N_URBS; i++) {
140 usb_kill_urb(&rt->in_urbs[i].instance);
141 usb_kill_urb(&rt->out_urbs[i].instance);
142 }
143 ctrl_rt->usb_streaming = false;
144 ctrl_rt->update_streaming(ctrl_rt);
145 rt->stream_state = STREAM_DISABLED;
146 }
147}
148
149/* call with stream_mutex locked */
150static int usb6fire_pcm_stream_start(struct pcm_runtime *rt)
151{
152 int ret;
153 int i;
154 int k;
155 struct usb_iso_packet_descriptor *packet;
156
157 if (rt->stream_state == STREAM_DISABLED) {
158 /* submit our in urbs */
159 rt->stream_wait_cond = false;
160 rt->stream_state = STREAM_STARTING;
161 for (i = 0; i < PCM_N_URBS; i++) {
162 for (k = 0; k < PCM_N_PACKETS_PER_URB; k++) {
163 packet = &rt->in_urbs[i].packets[k];
164 packet->offset = k * rt->in_packet_size;
165 packet->length = rt->in_packet_size;
166 packet->actual_length = 0;
167 packet->status = 0;
168 }
169 ret = usb_submit_urb(&rt->in_urbs[i].instance,
170 GFP_ATOMIC);
171 if (ret) {
172 usb6fire_pcm_stream_stop(rt);
173 return ret;
174 }
175 }
176
177 /* wait for first out urb to return (sent in in urb handler) */
178 wait_event_timeout(rt->stream_wait_queue, rt->stream_wait_cond,
179 HZ);
180 if (rt->stream_wait_cond)
181 rt->stream_state = STREAM_RUNNING;
182 else {
183 usb6fire_pcm_stream_stop(rt);
184 return -EIO;
185 }
186 }
187 return 0;
188}
189
190/* call with substream locked */
191static void usb6fire_pcm_capture(struct pcm_substream *sub, struct pcm_urb *urb)
192{
193 int i;
194 int frame;
195 int frame_count;
196 unsigned int total_length = 0;
197 struct pcm_runtime *rt = snd_pcm_substream_chip(sub->instance);
198 struct snd_pcm_runtime *alsa_rt = sub->instance->runtime;
199 u32 *src = NULL;
200 u32 *dest = (u32 *) (alsa_rt->dma_area + sub->dma_off
201 * (alsa_rt->frame_bits >> 3));
202 u32 *dest_end = (u32 *) (alsa_rt->dma_area + alsa_rt->buffer_size
203 * (alsa_rt->frame_bits >> 3));
204 int bytes_per_frame = alsa_rt->channels << 2;
205
206 for (i = 0; i < PCM_N_PACKETS_PER_URB; i++) {
207 /* at least 4 header bytes for valid packet.
208 * after that: 32 bits per sample for analog channels */
209 if (urb->packets[i].actual_length > 4)
210 frame_count = (urb->packets[i].actual_length - 4)
211 / (rt->in_n_analog << 2);
212 else
213 frame_count = 0;
214
215 if (alsa_rt->format == SNDRV_PCM_FORMAT_S24_LE)
216 src = (u32 *) (urb->buffer + total_length);
217 else if (alsa_rt->format == SNDRV_PCM_FORMAT_S32_LE)
218 src = (u32 *) (urb->buffer - 1 + total_length);
219 else
220 return;
221 src++; /* skip leading 4 bytes of every packet */
222 total_length += urb->packets[i].length;
223 for (frame = 0; frame < frame_count; frame++) {
224 memcpy(dest, src, bytes_per_frame);
225 dest += alsa_rt->channels;
226 src += rt->in_n_analog;
227 sub->dma_off++;
228 sub->period_off++;
229 if (dest == dest_end) {
230 sub->dma_off = 0;
231 dest = (u32 *) alsa_rt->dma_area;
232 }
233 }
234 }
235}
236
237/* call with substream locked */
238static void usb6fire_pcm_playback(struct pcm_substream *sub,
239 struct pcm_urb *urb)
240{
241 int i;
242 int frame;
243 int frame_count;
244 struct pcm_runtime *rt = snd_pcm_substream_chip(sub->instance);
245 struct snd_pcm_runtime *alsa_rt = sub->instance->runtime;
246 u32 *src = (u32 *) (alsa_rt->dma_area + sub->dma_off
247 * (alsa_rt->frame_bits >> 3));
248 u32 *src_end = (u32 *) (alsa_rt->dma_area + alsa_rt->buffer_size
249 * (alsa_rt->frame_bits >> 3));
250 u32 *dest;
251 int bytes_per_frame = alsa_rt->channels << 2;
252
253 if (alsa_rt->format == SNDRV_PCM_FORMAT_S32_LE)
254 dest = (u32 *) (urb->buffer - 1);
255 else if (alsa_rt->format == SNDRV_PCM_FORMAT_S24_LE)
256 dest = (u32 *) (urb->buffer);
257 else {
258 snd_printk(KERN_ERR PREFIX "Unknown sample format.");
259 return;
260 }
261
262 for (i = 0; i < PCM_N_PACKETS_PER_URB; i++) {
263 /* at least 4 header bytes for valid packet.
264 * after that: 32 bits per sample for analog channels */
265 if (urb->packets[i].length > 4)
266 frame_count = (urb->packets[i].length - 4)
267 / (rt->out_n_analog << 2);
268 else
269 frame_count = 0;
270 dest++; /* skip leading 4 bytes of every frame */
271 for (frame = 0; frame < frame_count; frame++) {
272 memcpy(dest, src, bytes_per_frame);
273 src += alsa_rt->channels;
274 dest += rt->out_n_analog;
275 sub->dma_off++;
276 sub->period_off++;
277 if (src == src_end) {
278 src = (u32 *) alsa_rt->dma_area;
279 sub->dma_off = 0;
280 }
281 }
282 }
283}
284
285static void usb6fire_pcm_in_urb_handler(struct urb *usb_urb)
286{
287 struct pcm_urb *in_urb = usb_urb->context;
288 struct pcm_urb *out_urb = in_urb->peer;
289 struct pcm_runtime *rt = in_urb->chip->pcm;
290 struct pcm_substream *sub;
291 unsigned long flags;
292 int total_length = 0;
293 int frame_count;
294 int frame;
295 int channel;
296 int i;
297 u8 *dest;
298
299 if (usb_urb->status || rt->panic || rt->stream_state == STREAM_STOPPING)
300 return;
301 for (i = 0; i < PCM_N_PACKETS_PER_URB; i++)
302 if (in_urb->packets[i].status) {
303 rt->panic = true;
304 return;
305 }
306
307 if (rt->stream_state == STREAM_DISABLED) {
308 snd_printk(KERN_ERR PREFIX "internal error: "
309 "stream disabled in in-urb handler.\n");
310 return;
311 }
312
313 /* receive our capture data */
314 sub = &rt->capture;
315 spin_lock_irqsave(&sub->lock, flags);
316 if (sub->active) {
317 usb6fire_pcm_capture(sub, in_urb);
318 if (sub->period_off >= sub->instance->runtime->period_size) {
319 sub->period_off %= sub->instance->runtime->period_size;
320 spin_unlock_irqrestore(&sub->lock, flags);
321 snd_pcm_period_elapsed(sub->instance);
322 } else
323 spin_unlock_irqrestore(&sub->lock, flags);
324 } else
325 spin_unlock_irqrestore(&sub->lock, flags);
326
327 /* setup out urb structure */
328 for (i = 0; i < PCM_N_PACKETS_PER_URB; i++) {
329 out_urb->packets[i].offset = total_length;
330 out_urb->packets[i].length = (in_urb->packets[i].actual_length
331 - 4) / (rt->in_n_analog << 2)
332 * (rt->out_n_analog << 2) + 4;
333 out_urb->packets[i].status = 0;
334 total_length += out_urb->packets[i].length;
335 }
336 memset(out_urb->buffer, 0, total_length);
337
338 /* now send our playback data (if a free out urb was found) */
339 sub = &rt->playback;
340 spin_lock_irqsave(&sub->lock, flags);
341 if (sub->active) {
342 usb6fire_pcm_playback(sub, out_urb);
343 if (sub->period_off >= sub->instance->runtime->period_size) {
344 sub->period_off %= sub->instance->runtime->period_size;
345 spin_unlock_irqrestore(&sub->lock, flags);
346 snd_pcm_period_elapsed(sub->instance);
347 } else
348 spin_unlock_irqrestore(&sub->lock, flags);
349 } else
350 spin_unlock_irqrestore(&sub->lock, flags);
351
352 /* setup the 4th byte of each sample (0x40 for analog channels) */
353 dest = out_urb->buffer;
354 for (i = 0; i < PCM_N_PACKETS_PER_URB; i++)
355 if (out_urb->packets[i].length >= 4) {
356 frame_count = (out_urb->packets[i].length - 4)
357 / (rt->out_n_analog << 2);
358 *(dest++) = 0xaa;
359 *(dest++) = 0xaa;
360 *(dest++) = frame_count;
361 *(dest++) = 0x00;
362 for (frame = 0; frame < frame_count; frame++)
363 for (channel = 0;
364 channel < rt->out_n_analog;
365 channel++) {
366 dest += 3; /* skip sample data */
367 *(dest++) = 0x40;
368 }
369 }
370 usb_submit_urb(&out_urb->instance, GFP_ATOMIC);
371 usb_submit_urb(&in_urb->instance, GFP_ATOMIC);
372}
373
374static void usb6fire_pcm_out_urb_handler(struct urb *usb_urb)
375{
376 struct pcm_urb *urb = usb_urb->context;
377 struct pcm_runtime *rt = urb->chip->pcm;
378
379 if (rt->stream_state == STREAM_STARTING) {
380 rt->stream_wait_cond = true;
381 wake_up(&rt->stream_wait_queue);
382 }
383}
384
385static int usb6fire_pcm_open(struct snd_pcm_substream *alsa_sub)
386{
387 struct pcm_runtime *rt = snd_pcm_substream_chip(alsa_sub);
388 struct pcm_substream *sub = NULL;
389 struct snd_pcm_runtime *alsa_rt = alsa_sub->runtime;
390
391 if (rt->panic)
392 return -EPIPE;
393
394 mutex_lock(&rt->stream_mutex);
395 alsa_rt->hw = pcm_hw;
396
397 if (alsa_sub->stream == SNDRV_PCM_STREAM_PLAYBACK) {
398 if (rt->rate < ARRAY_SIZE(rates))
399 alsa_rt->hw.rates = rates_alsaid[rt->rate];
400 alsa_rt->hw.channels_max = OUT_N_CHANNELS;
401 sub = &rt->playback;
402 } else if (alsa_sub->stream == SNDRV_PCM_STREAM_CAPTURE) {
403 if (rt->rate < ARRAY_SIZE(rates))
404 alsa_rt->hw.rates = rates_alsaid[rt->rate];
405 alsa_rt->hw.channels_max = IN_N_CHANNELS;
406 sub = &rt->capture;
407 }
408
409 if (!sub) {
410 mutex_unlock(&rt->stream_mutex);
411 snd_printk(KERN_ERR PREFIX "invalid stream type.\n");
412 return -EINVAL;
413 }
414
415 sub->instance = alsa_sub;
416 sub->active = false;
417 mutex_unlock(&rt->stream_mutex);
418 return 0;
419}
420
421static int usb6fire_pcm_close(struct snd_pcm_substream *alsa_sub)
422{
423 struct pcm_runtime *rt = snd_pcm_substream_chip(alsa_sub);
424 struct pcm_substream *sub = usb6fire_pcm_get_substream(alsa_sub);
425 unsigned long flags;
426
427 if (rt->panic)
428 return 0;
429
430 mutex_lock(&rt->stream_mutex);
431 if (sub) {
432 /* deactivate substream */
433 spin_lock_irqsave(&sub->lock, flags);
434 sub->instance = NULL;
435 sub->active = false;
436 spin_unlock_irqrestore(&sub->lock, flags);
437
438 /* all substreams closed? if so, stop streaming */
439 if (!rt->playback.instance && !rt->capture.instance) {
440 usb6fire_pcm_stream_stop(rt);
441 rt->rate = ARRAY_SIZE(rates);
442 }
443 }
444 mutex_unlock(&rt->stream_mutex);
445 return 0;
446}
447
448static int usb6fire_pcm_hw_params(struct snd_pcm_substream *alsa_sub,
449 struct snd_pcm_hw_params *hw_params)
450{
451 return snd_pcm_lib_malloc_pages(alsa_sub,
452 params_buffer_bytes(hw_params));
453}
454
455static int usb6fire_pcm_hw_free(struct snd_pcm_substream *alsa_sub)
456{
457 return snd_pcm_lib_free_pages(alsa_sub);
458}
459
460static int usb6fire_pcm_prepare(struct snd_pcm_substream *alsa_sub)
461{
462 struct pcm_runtime *rt = snd_pcm_substream_chip(alsa_sub);
463 struct pcm_substream *sub = usb6fire_pcm_get_substream(alsa_sub);
464 struct snd_pcm_runtime *alsa_rt = alsa_sub->runtime;
465 int ret;
466
467 if (rt->panic)
468 return -EPIPE;
469 if (!sub)
470 return -ENODEV;
471
472 mutex_lock(&rt->stream_mutex);
473 sub->dma_off = 0;
474 sub->period_off = 0;
475
476 if (rt->stream_state == STREAM_DISABLED) {
477 for (rt->rate = 0; rt->rate < ARRAY_SIZE(rates); rt->rate++)
478 if (alsa_rt->rate == rates[rt->rate])
479 break;
480 if (rt->rate == ARRAY_SIZE(rates)) {
481 mutex_unlock(&rt->stream_mutex);
482 snd_printk("invalid rate %d in prepare.\n",
483 alsa_rt->rate);
484 return -EINVAL;
485 }
486
487 ret = usb6fire_pcm_set_rate(rt);
488 if (ret) {
489 mutex_unlock(&rt->stream_mutex);
490 return ret;
491 }
492 ret = usb6fire_pcm_stream_start(rt);
493 if (ret) {
494 mutex_unlock(&rt->stream_mutex);
495 snd_printk(KERN_ERR PREFIX
496 "could not start pcm stream.\n");
497 return ret;
498 }
499 }
500 mutex_unlock(&rt->stream_mutex);
501 return 0;
502}
503
504static int usb6fire_pcm_trigger(struct snd_pcm_substream *alsa_sub, int cmd)
505{
506 struct pcm_substream *sub = usb6fire_pcm_get_substream(alsa_sub);
507 struct pcm_runtime *rt = snd_pcm_substream_chip(alsa_sub);
508 unsigned long flags;
509
510 if (rt->panic)
511 return -EPIPE;
512 if (!sub)
513 return -ENODEV;
514
515 switch (cmd) {
516 case SNDRV_PCM_TRIGGER_START:
517 case SNDRV_PCM_TRIGGER_PAUSE_RELEASE:
518 spin_lock_irqsave(&sub->lock, flags);
519 sub->active = true;
520 spin_unlock_irqrestore(&sub->lock, flags);
521 return 0;
522
523 case SNDRV_PCM_TRIGGER_STOP:
524 case SNDRV_PCM_TRIGGER_PAUSE_PUSH:
525 spin_lock_irqsave(&sub->lock, flags);
526 sub->active = false;
527 spin_unlock_irqrestore(&sub->lock, flags);
528 return 0;
529
530 default:
531 return -EINVAL;
532 }
533}
534
535static snd_pcm_uframes_t usb6fire_pcm_pointer(
536 struct snd_pcm_substream *alsa_sub)
537{
538 struct pcm_substream *sub = usb6fire_pcm_get_substream(alsa_sub);
539 struct pcm_runtime *rt = snd_pcm_substream_chip(alsa_sub);
540 unsigned long flags;
541 snd_pcm_uframes_t ret;
542
543 if (rt->panic || !sub)
544 return SNDRV_PCM_STATE_XRUN;
545
546 spin_lock_irqsave(&sub->lock, flags);
547 ret = sub->dma_off;
548 spin_unlock_irqrestore(&sub->lock, flags);
549 return ret;
550}
551
552static struct snd_pcm_ops pcm_ops = {
553 .open = usb6fire_pcm_open,
554 .close = usb6fire_pcm_close,
555 .ioctl = snd_pcm_lib_ioctl,
556 .hw_params = usb6fire_pcm_hw_params,
557 .hw_free = usb6fire_pcm_hw_free,
558 .prepare = usb6fire_pcm_prepare,
559 .trigger = usb6fire_pcm_trigger,
560 .pointer = usb6fire_pcm_pointer,
561};
562
563static void __devinit usb6fire_pcm_init_urb(struct pcm_urb *urb,
564 struct sfire_chip *chip, bool in, int ep,
565 void (*handler)(struct urb *))
566{
567 urb->chip = chip;
568 usb_init_urb(&urb->instance);
569 urb->instance.transfer_buffer = urb->buffer;
570 urb->instance.transfer_buffer_length =
571 PCM_N_PACKETS_PER_URB * PCM_MAX_PACKET_SIZE;
572 urb->instance.dev = chip->dev;
573 urb->instance.pipe = in ? usb_rcvisocpipe(chip->dev, ep)
574 : usb_sndisocpipe(chip->dev, ep);
575 urb->instance.interval = 1;
576 urb->instance.transfer_flags = URB_ISO_ASAP;
577 urb->instance.complete = handler;
578 urb->instance.context = urb;
579 urb->instance.number_of_packets = PCM_N_PACKETS_PER_URB;
580}
581
582int __devinit usb6fire_pcm_init(struct sfire_chip *chip)
583{
584 int i;
585 int ret;
586 struct snd_pcm *pcm;
587 struct pcm_runtime *rt =
588 kzalloc(sizeof(struct pcm_runtime), GFP_KERNEL);
589
590 if (!rt)
591 return -ENOMEM;
592
593 rt->chip = chip;
594 rt->stream_state = STREAM_DISABLED;
595 rt->rate = ARRAY_SIZE(rates);
596 init_waitqueue_head(&rt->stream_wait_queue);
597 mutex_init(&rt->stream_mutex);
598
599 spin_lock_init(&rt->playback.lock);
600 spin_lock_init(&rt->capture.lock);
601
602 for (i = 0; i < PCM_N_URBS; i++) {
603 usb6fire_pcm_init_urb(&rt->in_urbs[i], chip, true, IN_EP,
604 usb6fire_pcm_in_urb_handler);
605 usb6fire_pcm_init_urb(&rt->out_urbs[i], chip, false, OUT_EP,
606 usb6fire_pcm_out_urb_handler);
607
608 rt->in_urbs[i].peer = &rt->out_urbs[i];
609 rt->out_urbs[i].peer = &rt->in_urbs[i];
610 }
611
612 ret = snd_pcm_new(chip->card, "DMX6FireUSB", 0, 1, 1, &pcm);
613 if (ret < 0) {
614 kfree(rt);
615 snd_printk(KERN_ERR PREFIX "cannot create pcm instance.\n");
616 return ret;
617 }
618
619 pcm->private_data = rt;
620 strcpy(pcm->name, "DMX 6Fire USB");
621 snd_pcm_set_ops(pcm, SNDRV_PCM_STREAM_PLAYBACK, &pcm_ops);
622 snd_pcm_set_ops(pcm, SNDRV_PCM_STREAM_CAPTURE, &pcm_ops);
623
624 ret = snd_pcm_lib_preallocate_pages_for_all(pcm,
625 SNDRV_DMA_TYPE_CONTINUOUS,
626 snd_dma_continuous_data(GFP_KERNEL),
627 MAX_BUFSIZE, MAX_BUFSIZE);
628 if (ret) {
629 kfree(rt);
630 snd_printk(KERN_ERR PREFIX
631 "error preallocating pcm buffers.\n");
632 return ret;
633 }
634 rt->instance = pcm;
635
636 chip->pcm = rt;
637 return 0;
638}
639
640void usb6fire_pcm_abort(struct sfire_chip *chip)
641{
642 struct pcm_runtime *rt = chip->pcm;
643 int i;
644
645 if (rt) {
646 rt->panic = true;
647
648 if (rt->playback.instance)
649 snd_pcm_stop(rt->playback.instance,
650 SNDRV_PCM_STATE_XRUN);
651 if (rt->capture.instance)
652 snd_pcm_stop(rt->capture.instance,
653 SNDRV_PCM_STATE_XRUN);
654
655 for (i = 0; i < PCM_N_URBS; i++) {
656 usb_poison_urb(&rt->in_urbs[i].instance);
657 usb_poison_urb(&rt->out_urbs[i].instance);
658 }
659
660 }
661}
662
663void usb6fire_pcm_destroy(struct sfire_chip *chip)
664{
665 kfree(chip->pcm);
666 chip->pcm = NULL;
667}
diff --git a/sound/usb/6fire/pcm.h b/sound/usb/6fire/pcm.h
new file mode 100644
index 000000000000..2bee81374002
--- /dev/null
+++ b/sound/usb/6fire/pcm.h
@@ -0,0 +1,76 @@
1/*
2 * Linux driver for TerraTec DMX 6Fire USB
3 *
4 * Author: Torsten Schenk <torsten.schenk@zoho.com>
5 * Created: Jan 01, 2011
6 * Version: 0.3.0
7 * Copyright: (C) Torsten Schenk
8 *
9 * This program is free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License as published by
11 * the Free Software Foundation; either version 2 of the License, or
12 * (at your option) any later version.
13 */
14
15#ifndef USB6FIRE_PCM_H
16#define USB6FIRE_PCM_H
17
18#include <sound/pcm.h>
19#include <linux/mutex.h>
20
21#include "common.h"
22
23enum /* settings for pcm */
24{
25 /* maximum of EP_W_MAX_PACKET_SIZE[] (see firmware.c) */
26 PCM_N_URBS = 16, PCM_N_PACKETS_PER_URB = 8, PCM_MAX_PACKET_SIZE = 604
27};
28
29struct pcm_urb {
30 struct sfire_chip *chip;
31
32 /* BEGIN DO NOT SEPARATE */
33 struct urb instance;
34 struct usb_iso_packet_descriptor packets[PCM_N_PACKETS_PER_URB];
35 /* END DO NOT SEPARATE */
36 u8 buffer[PCM_N_PACKETS_PER_URB * PCM_MAX_PACKET_SIZE];
37
38 struct pcm_urb *peer;
39};
40
41struct pcm_substream {
42 spinlock_t lock;
43 struct snd_pcm_substream *instance;
44
45 bool active;
46
47 snd_pcm_uframes_t dma_off; /* current position in alsa dma_area */
48 snd_pcm_uframes_t period_off; /* current position in current period */
49};
50
51struct pcm_runtime {
52 struct sfire_chip *chip;
53 struct snd_pcm *instance;
54
55 struct pcm_substream playback;
56 struct pcm_substream capture;
57 bool panic; /* if set driver won't do anymore pcm on device */
58
59 struct pcm_urb in_urbs[PCM_N_URBS];
60 struct pcm_urb out_urbs[PCM_N_URBS];
61 int in_packet_size;
62 int out_packet_size;
63 int in_n_analog; /* number of analog channels soundcard sends */
64 int out_n_analog; /* number of analog channels soundcard receives */
65
66 struct mutex stream_mutex;
67 u8 stream_state; /* one of STREAM_XXX (pcm.c) */
68 u8 rate; /* one of PCM_RATE_XXX */
69 wait_queue_head_t stream_wait_queue;
70 bool stream_wait_cond;
71};
72
73int __devinit usb6fire_pcm_init(struct sfire_chip *chip);
74void usb6fire_pcm_abort(struct sfire_chip *chip);
75void usb6fire_pcm_destroy(struct sfire_chip *chip);
76#endif /* USB6FIRE_PCM_H */
diff --git a/sound/usb/Kconfig b/sound/usb/Kconfig
index 44d6d2ec964f..8beb77563da2 100644
--- a/sound/usb/Kconfig
+++ b/sound/usb/Kconfig
@@ -62,9 +62,11 @@ config SND_USB_CAIAQ
62 * Native Instruments Audio 2 DJ 62 * Native Instruments Audio 2 DJ
63 * Native Instruments Audio 4 DJ 63 * Native Instruments Audio 4 DJ
64 * Native Instruments Audio 8 DJ 64 * Native Instruments Audio 8 DJ
65 * Native Instruments Traktor Audio 2
65 * Native Instruments Guitar Rig Session I/O 66 * Native Instruments Guitar Rig Session I/O
66 * Native Instruments Guitar Rig mobile 67 * Native Instruments Guitar Rig mobile
67 * Native Instruments Traktor Kontrol X1 68 * Native Instruments Traktor Kontrol X1
69 * Native Instruments Traktor Kontrol S4
68 70
69 To compile this driver as a module, choose M here: the module 71 To compile this driver as a module, choose M here: the module
70 will be called snd-usb-caiaq. 72 will be called snd-usb-caiaq.
@@ -82,6 +84,7 @@ config SND_USB_CAIAQ_INPUT
82 * Native Instruments Kore Controller 84 * Native Instruments Kore Controller
83 * Native Instruments Kore Controller 2 85 * Native Instruments Kore Controller 2
84 * Native Instruments Audio Kontrol 1 86 * Native Instruments Audio Kontrol 1
87 * Native Instruments Traktor Kontrol S4
85 88
86config SND_USB_US122L 89config SND_USB_US122L
87 tristate "Tascam US-122L USB driver" 90 tristate "Tascam US-122L USB driver"
@@ -95,5 +98,19 @@ config SND_USB_US122L
95 To compile this driver as a module, choose M here: the module 98 To compile this driver as a module, choose M here: the module
96 will be called snd-usb-us122l. 99 will be called snd-usb-us122l.
97 100
101config SND_USB_6FIRE
102 tristate "TerraTec DMX 6Fire USB"
103 select FW_LOADER
104 select BITREVERSE
105 select SND_RAWMIDI
106 select SND_PCM
107 help
108 Say Y here to include support for TerraTec 6fire DMX USB interface.
109
110 You will need firmware files in order to be able to use the device
111 after it has been coldstarted. An install script for the firmware
112 and further help can be found at
113 http://sixfireusb.sourceforge.net
114
98endif # SND_USB 115endif # SND_USB
99 116
diff --git a/sound/usb/Makefile b/sound/usb/Makefile
index 1e362bf8834f..cf9ed66445fa 100644
--- a/sound/usb/Makefile
+++ b/sound/usb/Makefile
@@ -23,4 +23,4 @@ obj-$(CONFIG_SND_USB_UA101) += snd-usbmidi-lib.o
23obj-$(CONFIG_SND_USB_USX2Y) += snd-usbmidi-lib.o 23obj-$(CONFIG_SND_USB_USX2Y) += snd-usbmidi-lib.o
24obj-$(CONFIG_SND_USB_US122L) += snd-usbmidi-lib.o 24obj-$(CONFIG_SND_USB_US122L) += snd-usbmidi-lib.o
25 25
26obj-$(CONFIG_SND) += misc/ usx2y/ caiaq/ 26obj-$(CONFIG_SND) += misc/ usx2y/ caiaq/ 6fire/
diff --git a/sound/usb/caiaq/audio.c b/sound/usb/caiaq/audio.c
index 4328cad6c3a2..d0d493ca28ae 100644
--- a/sound/usb/caiaq/audio.c
+++ b/sound/usb/caiaq/audio.c
@@ -111,7 +111,7 @@ static int stream_start(struct snd_usb_caiaqdev *dev)
111 memset(dev->sub_capture, 0, sizeof(dev->sub_capture)); 111 memset(dev->sub_capture, 0, sizeof(dev->sub_capture));
112 dev->input_panic = 0; 112 dev->input_panic = 0;
113 dev->output_panic = 0; 113 dev->output_panic = 0;
114 dev->first_packet = 1; 114 dev->first_packet = 4;
115 dev->streaming = 1; 115 dev->streaming = 1;
116 dev->warned = 0; 116 dev->warned = 0;
117 117
@@ -169,7 +169,7 @@ static int snd_usb_caiaq_substream_close(struct snd_pcm_substream *substream)
169} 169}
170 170
171static int snd_usb_caiaq_pcm_hw_params(struct snd_pcm_substream *sub, 171static int snd_usb_caiaq_pcm_hw_params(struct snd_pcm_substream *sub,
172 struct snd_pcm_hw_params *hw_params) 172 struct snd_pcm_hw_params *hw_params)
173{ 173{
174 debug("%s(%p)\n", __func__, sub); 174 debug("%s(%p)\n", __func__, sub);
175 return snd_pcm_lib_malloc_pages(sub, params_buffer_bytes(hw_params)); 175 return snd_pcm_lib_malloc_pages(sub, params_buffer_bytes(hw_params));
@@ -189,7 +189,7 @@ static int snd_usb_caiaq_pcm_hw_free(struct snd_pcm_substream *sub)
189#endif 189#endif
190 190
191static unsigned int rates[] = { 5512, 8000, 11025, 16000, 22050, 32000, 44100, 191static unsigned int rates[] = { 5512, 8000, 11025, 16000, 22050, 32000, 44100,
192 48000, 64000, 88200, 96000, 176400, 192000 }; 192 48000, 64000, 88200, 96000, 176400, 192000 };
193 193
194static int snd_usb_caiaq_pcm_prepare(struct snd_pcm_substream *substream) 194static int snd_usb_caiaq_pcm_prepare(struct snd_pcm_substream *substream)
195{ 195{
@@ -201,12 +201,39 @@ static int snd_usb_caiaq_pcm_prepare(struct snd_pcm_substream *substream)
201 debug("%s(%p)\n", __func__, substream); 201 debug("%s(%p)\n", __func__, substream);
202 202
203 if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK) { 203 if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK) {
204 dev->period_out_count[index] = BYTES_PER_SAMPLE + 1; 204 int out_pos;
205 dev->audio_out_buf_pos[index] = BYTES_PER_SAMPLE + 1; 205
206 switch (dev->spec.data_alignment) {
207 case 0:
208 case 2:
209 out_pos = BYTES_PER_SAMPLE + 1;
210 break;
211 case 3:
212 default:
213 out_pos = 0;
214 break;
215 }
216
217 dev->period_out_count[index] = out_pos;
218 dev->audio_out_buf_pos[index] = out_pos;
206 } else { 219 } else {
207 int in_pos = (dev->spec.data_alignment == 2) ? 0 : 2; 220 int in_pos;
208 dev->period_in_count[index] = BYTES_PER_SAMPLE + in_pos; 221
209 dev->audio_in_buf_pos[index] = BYTES_PER_SAMPLE + in_pos; 222 switch (dev->spec.data_alignment) {
223 case 0:
224 in_pos = BYTES_PER_SAMPLE + 2;
225 break;
226 case 2:
227 in_pos = BYTES_PER_SAMPLE;
228 break;
229 case 3:
230 default:
231 in_pos = 0;
232 break;
233 }
234
235 dev->period_in_count[index] = in_pos;
236 dev->audio_in_buf_pos[index] = in_pos;
210 } 237 }
211 238
212 if (dev->streaming) 239 if (dev->streaming)
@@ -221,7 +248,7 @@ static int snd_usb_caiaq_pcm_prepare(struct snd_pcm_substream *substream)
221 snd_pcm_limit_hw_rates(runtime); 248 snd_pcm_limit_hw_rates(runtime);
222 249
223 bytes_per_sample = BYTES_PER_SAMPLE; 250 bytes_per_sample = BYTES_PER_SAMPLE;
224 if (dev->spec.data_alignment == 2) 251 if (dev->spec.data_alignment >= 2)
225 bytes_per_sample++; 252 bytes_per_sample++;
226 253
227 bpp = ((runtime->rate / 8000) + CLOCK_DRIFT_TOLERANCE) 254 bpp = ((runtime->rate / 8000) + CLOCK_DRIFT_TOLERANCE)
@@ -253,6 +280,8 @@ static int snd_usb_caiaq_pcm_trigger(struct snd_pcm_substream *sub, int cmd)
253{ 280{
254 struct snd_usb_caiaqdev *dev = snd_pcm_substream_chip(sub); 281 struct snd_usb_caiaqdev *dev = snd_pcm_substream_chip(sub);
255 282
283 debug("%s(%p) cmd %d\n", __func__, sub, cmd);
284
256 switch (cmd) { 285 switch (cmd) {
257 case SNDRV_PCM_TRIGGER_START: 286 case SNDRV_PCM_TRIGGER_START:
258 case SNDRV_PCM_TRIGGER_PAUSE_RELEASE: 287 case SNDRV_PCM_TRIGGER_PAUSE_RELEASE:
@@ -402,6 +431,61 @@ static void read_in_urb_mode2(struct snd_usb_caiaqdev *dev,
402 } 431 }
403} 432}
404 433
434static void read_in_urb_mode3(struct snd_usb_caiaqdev *dev,
435 const struct urb *urb,
436 const struct usb_iso_packet_descriptor *iso)
437{
438 unsigned char *usb_buf = urb->transfer_buffer + iso->offset;
439 int stream, i;
440
441 /* paranoia check */
442 if (iso->actual_length % (BYTES_PER_SAMPLE_USB * CHANNELS_PER_STREAM))
443 return;
444
445 for (i = 0; i < iso->actual_length;) {
446 for (stream = 0; stream < dev->n_streams; stream++) {
447 struct snd_pcm_substream *sub = dev->sub_capture[stream];
448 char *audio_buf = NULL;
449 int c, n, sz = 0;
450
451 if (sub && !dev->input_panic) {
452 struct snd_pcm_runtime *rt = sub->runtime;
453 audio_buf = rt->dma_area;
454 sz = frames_to_bytes(rt, rt->buffer_size);
455 }
456
457 for (c = 0; c < CHANNELS_PER_STREAM; c++) {
458 /* 3 audio data bytes, followed by 1 check byte */
459 if (audio_buf) {
460 for (n = 0; n < BYTES_PER_SAMPLE; n++) {
461 audio_buf[dev->audio_in_buf_pos[stream]++] = usb_buf[i+n];
462
463 if (dev->audio_in_buf_pos[stream] == sz)
464 dev->audio_in_buf_pos[stream] = 0;
465 }
466
467 dev->period_in_count[stream] += BYTES_PER_SAMPLE;
468 }
469
470 i += BYTES_PER_SAMPLE;
471
472 if (usb_buf[i] != ((stream << 1) | c) &&
473 !dev->first_packet) {
474 if (!dev->input_panic)
475 printk(" EXPECTED: %02x got %02x, c %d, stream %d, i %d\n",
476 ((stream << 1) | c), usb_buf[i], c, stream, i);
477 dev->input_panic = 1;
478 }
479
480 i++;
481 }
482 }
483 }
484
485 if (dev->first_packet > 0)
486 dev->first_packet--;
487}
488
405static void read_in_urb(struct snd_usb_caiaqdev *dev, 489static void read_in_urb(struct snd_usb_caiaqdev *dev,
406 const struct urb *urb, 490 const struct urb *urb,
407 const struct usb_iso_packet_descriptor *iso) 491 const struct usb_iso_packet_descriptor *iso)
@@ -419,6 +503,9 @@ static void read_in_urb(struct snd_usb_caiaqdev *dev,
419 case 2: 503 case 2:
420 read_in_urb_mode2(dev, urb, iso); 504 read_in_urb_mode2(dev, urb, iso);
421 break; 505 break;
506 case 3:
507 read_in_urb_mode3(dev, urb, iso);
508 break;
422 } 509 }
423 510
424 if ((dev->input_panic || dev->output_panic) && !dev->warned) { 511 if ((dev->input_panic || dev->output_panic) && !dev->warned) {
@@ -429,9 +516,9 @@ static void read_in_urb(struct snd_usb_caiaqdev *dev,
429 } 516 }
430} 517}
431 518
432static void fill_out_urb(struct snd_usb_caiaqdev *dev, 519static void fill_out_urb_mode_0(struct snd_usb_caiaqdev *dev,
433 struct urb *urb, 520 struct urb *urb,
434 const struct usb_iso_packet_descriptor *iso) 521 const struct usb_iso_packet_descriptor *iso)
435{ 522{
436 unsigned char *usb_buf = urb->transfer_buffer + iso->offset; 523 unsigned char *usb_buf = urb->transfer_buffer + iso->offset;
437 struct snd_pcm_substream *sub; 524 struct snd_pcm_substream *sub;
@@ -457,9 +544,67 @@ static void fill_out_urb(struct snd_usb_caiaqdev *dev,
457 /* fill in the check bytes */ 544 /* fill in the check bytes */
458 if (dev->spec.data_alignment == 2 && 545 if (dev->spec.data_alignment == 2 &&
459 i % (dev->n_streams * BYTES_PER_SAMPLE_USB) == 546 i % (dev->n_streams * BYTES_PER_SAMPLE_USB) ==
460 (dev->n_streams * CHANNELS_PER_STREAM)) 547 (dev->n_streams * CHANNELS_PER_STREAM))
461 for (stream = 0; stream < dev->n_streams; stream++, i++) 548 for (stream = 0; stream < dev->n_streams; stream++, i++)
462 usb_buf[i] = MAKE_CHECKBYTE(dev, stream, i); 549 usb_buf[i] = MAKE_CHECKBYTE(dev, stream, i);
550 }
551}
552
553static void fill_out_urb_mode_3(struct snd_usb_caiaqdev *dev,
554 struct urb *urb,
555 const struct usb_iso_packet_descriptor *iso)
556{
557 unsigned char *usb_buf = urb->transfer_buffer + iso->offset;
558 int stream, i;
559
560 for (i = 0; i < iso->length;) {
561 for (stream = 0; stream < dev->n_streams; stream++) {
562 struct snd_pcm_substream *sub = dev->sub_playback[stream];
563 char *audio_buf = NULL;
564 int c, n, sz = 0;
565
566 if (sub) {
567 struct snd_pcm_runtime *rt = sub->runtime;
568 audio_buf = rt->dma_area;
569 sz = frames_to_bytes(rt, rt->buffer_size);
570 }
571
572 for (c = 0; c < CHANNELS_PER_STREAM; c++) {
573 for (n = 0; n < BYTES_PER_SAMPLE; n++) {
574 if (audio_buf) {
575 usb_buf[i+n] = audio_buf[dev->audio_out_buf_pos[stream]++];
576
577 if (dev->audio_out_buf_pos[stream] == sz)
578 dev->audio_out_buf_pos[stream] = 0;
579 } else {
580 usb_buf[i+n] = 0;
581 }
582 }
583
584 if (audio_buf)
585 dev->period_out_count[stream] += BYTES_PER_SAMPLE;
586
587 i += BYTES_PER_SAMPLE;
588
589 /* fill in the check byte pattern */
590 usb_buf[i++] = (stream << 1) | c;
591 }
592 }
593 }
594}
595
596static inline void fill_out_urb(struct snd_usb_caiaqdev *dev,
597 struct urb *urb,
598 const struct usb_iso_packet_descriptor *iso)
599{
600 switch (dev->spec.data_alignment) {
601 case 0:
602 case 2:
603 fill_out_urb_mode_0(dev, urb, iso);
604 break;
605 case 3:
606 fill_out_urb_mode_3(dev, urb, iso);
607 break;
463 } 608 }
464} 609}
465 610
@@ -640,7 +785,7 @@ int snd_usb_caiaq_audio_init(struct snd_usb_caiaqdev *dev)
640 } 785 }
641 786
642 dev->pcm->private_data = dev; 787 dev->pcm->private_data = dev;
643 strcpy(dev->pcm->name, dev->product_name); 788 strlcpy(dev->pcm->name, dev->product_name, sizeof(dev->pcm->name));
644 789
645 memset(dev->sub_playback, 0, sizeof(dev->sub_playback)); 790 memset(dev->sub_playback, 0, sizeof(dev->sub_playback));
646 memset(dev->sub_capture, 0, sizeof(dev->sub_capture)); 791 memset(dev->sub_capture, 0, sizeof(dev->sub_capture));
@@ -660,6 +805,7 @@ int snd_usb_caiaq_audio_init(struct snd_usb_caiaqdev *dev)
660 case USB_ID(USB_VID_NATIVEINSTRUMENTS, USB_PID_AUDIO2DJ): 805 case USB_ID(USB_VID_NATIVEINSTRUMENTS, USB_PID_AUDIO2DJ):
661 case USB_ID(USB_VID_NATIVEINSTRUMENTS, USB_PID_AUDIO4DJ): 806 case USB_ID(USB_VID_NATIVEINSTRUMENTS, USB_PID_AUDIO4DJ):
662 case USB_ID(USB_VID_NATIVEINSTRUMENTS, USB_PID_AUDIO8DJ): 807 case USB_ID(USB_VID_NATIVEINSTRUMENTS, USB_PID_AUDIO8DJ):
808 case USB_ID(USB_VID_NATIVEINSTRUMENTS, USB_PID_TRAKTORAUDIO2):
663 dev->samplerates |= SNDRV_PCM_RATE_88200; 809 dev->samplerates |= SNDRV_PCM_RATE_88200;
664 break; 810 break;
665 } 811 }
diff --git a/sound/usb/caiaq/control.c b/sound/usb/caiaq/control.c
index 91c804cd2782..00e5d0a469e1 100644
--- a/sound/usb/caiaq/control.c
+++ b/sound/usb/caiaq/control.c
@@ -55,6 +55,10 @@ static int control_info(struct snd_kcontrol *kcontrol,
55 case USB_ID(USB_VID_NATIVEINSTRUMENTS, USB_PID_TRAKTORKONTROLX1): 55 case USB_ID(USB_VID_NATIVEINSTRUMENTS, USB_PID_TRAKTORKONTROLX1):
56 maxval = 127; 56 maxval = 127;
57 break; 57 break;
58
59 case USB_ID(USB_VID_NATIVEINSTRUMENTS, USB_PID_TRAKTORKONTROLS4):
60 maxval = 31;
61 break;
58 } 62 }
59 63
60 if (is_intval) { 64 if (is_intval) {
@@ -93,6 +97,7 @@ static int control_put(struct snd_kcontrol *kcontrol,
93 struct snd_usb_audio *chip = snd_kcontrol_chip(kcontrol); 97 struct snd_usb_audio *chip = snd_kcontrol_chip(kcontrol);
94 struct snd_usb_caiaqdev *dev = caiaqdev(chip->card); 98 struct snd_usb_caiaqdev *dev = caiaqdev(chip->card);
95 int pos = kcontrol->private_value; 99 int pos = kcontrol->private_value;
100 int v = ucontrol->value.integer.value[0];
96 unsigned char cmd = EP1_CMD_WRITE_IO; 101 unsigned char cmd = EP1_CMD_WRITE_IO;
97 102
98 if (dev->chip.usb_id == 103 if (dev->chip.usb_id ==
@@ -100,12 +105,27 @@ static int control_put(struct snd_kcontrol *kcontrol,
100 cmd = EP1_CMD_DIMM_LEDS; 105 cmd = EP1_CMD_DIMM_LEDS;
101 106
102 if (pos & CNT_INTVAL) { 107 if (pos & CNT_INTVAL) {
103 dev->control_state[pos & ~CNT_INTVAL] 108 int i = pos & ~CNT_INTVAL;
104 = ucontrol->value.integer.value[0]; 109
105 snd_usb_caiaq_send_command(dev, cmd, 110 dev->control_state[i] = v;
106 dev->control_state, sizeof(dev->control_state)); 111
112 if (dev->chip.usb_id ==
113 USB_ID(USB_VID_NATIVEINSTRUMENTS, USB_PID_TRAKTORKONTROLS4)) {
114 int actual_len;
115
116 dev->ep8_out_buf[0] = i;
117 dev->ep8_out_buf[1] = v;
118
119 usb_bulk_msg(dev->chip.dev,
120 usb_sndbulkpipe(dev->chip.dev, 8),
121 dev->ep8_out_buf, sizeof(dev->ep8_out_buf),
122 &actual_len, 200);
123 } else {
124 snd_usb_caiaq_send_command(dev, cmd,
125 dev->control_state, sizeof(dev->control_state));
126 }
107 } else { 127 } else {
108 if (ucontrol->value.integer.value[0]) 128 if (v)
109 dev->control_state[pos / 8] |= 1 << (pos % 8); 129 dev->control_state[pos / 8] |= 1 << (pos % 8);
110 else 130 else
111 dev->control_state[pos / 8] &= ~(1 << (pos % 8)); 131 dev->control_state[pos / 8] &= ~(1 << (pos % 8));
@@ -296,6 +316,179 @@ static struct caiaq_controller kontrolx1_controller[] = {
296 { "LED Deck B: SYNC", 8 | CNT_INTVAL }, 316 { "LED Deck B: SYNC", 8 | CNT_INTVAL },
297}; 317};
298 318
319static struct caiaq_controller kontrols4_controller[] = {
320 { "LED: Master: Quant", 10 | CNT_INTVAL },
321 { "LED: Master: Headphone", 11 | CNT_INTVAL },
322 { "LED: Master: Master", 12 | CNT_INTVAL },
323 { "LED: Master: Snap", 14 | CNT_INTVAL },
324 { "LED: Master: Warning", 15 | CNT_INTVAL },
325 { "LED: Master: Master button", 112 | CNT_INTVAL },
326 { "LED: Master: Snap button", 113 | CNT_INTVAL },
327 { "LED: Master: Rec", 118 | CNT_INTVAL },
328 { "LED: Master: Size", 119 | CNT_INTVAL },
329 { "LED: Master: Quant button", 120 | CNT_INTVAL },
330 { "LED: Master: Browser button", 121 | CNT_INTVAL },
331 { "LED: Master: Play button", 126 | CNT_INTVAL },
332 { "LED: Master: Undo button", 127 | CNT_INTVAL },
333
334 { "LED: Channel A: >", 4 | CNT_INTVAL },
335 { "LED: Channel A: <", 5 | CNT_INTVAL },
336 { "LED: Channel A: Meter 1", 97 | CNT_INTVAL },
337 { "LED: Channel A: Meter 2", 98 | CNT_INTVAL },
338 { "LED: Channel A: Meter 3", 99 | CNT_INTVAL },
339 { "LED: Channel A: Meter 4", 100 | CNT_INTVAL },
340 { "LED: Channel A: Meter 5", 101 | CNT_INTVAL },
341 { "LED: Channel A: Meter 6", 102 | CNT_INTVAL },
342 { "LED: Channel A: Meter clip", 103 | CNT_INTVAL },
343 { "LED: Channel A: Active", 114 | CNT_INTVAL },
344 { "LED: Channel A: Cue", 116 | CNT_INTVAL },
345 { "LED: Channel A: FX1", 149 | CNT_INTVAL },
346 { "LED: Channel A: FX2", 148 | CNT_INTVAL },
347
348 { "LED: Channel B: >", 2 | CNT_INTVAL },
349 { "LED: Channel B: <", 3 | CNT_INTVAL },
350 { "LED: Channel B: Meter 1", 89 | CNT_INTVAL },
351 { "LED: Channel B: Meter 2", 90 | CNT_INTVAL },
352 { "LED: Channel B: Meter 3", 91 | CNT_INTVAL },
353 { "LED: Channel B: Meter 4", 92 | CNT_INTVAL },
354 { "LED: Channel B: Meter 5", 93 | CNT_INTVAL },
355 { "LED: Channel B: Meter 6", 94 | CNT_INTVAL },
356 { "LED: Channel B: Meter clip", 95 | CNT_INTVAL },
357 { "LED: Channel B: Active", 122 | CNT_INTVAL },
358 { "LED: Channel B: Cue", 125 | CNT_INTVAL },
359 { "LED: Channel B: FX1", 147 | CNT_INTVAL },
360 { "LED: Channel B: FX2", 146 | CNT_INTVAL },
361
362 { "LED: Channel C: >", 6 | CNT_INTVAL },
363 { "LED: Channel C: <", 7 | CNT_INTVAL },
364 { "LED: Channel C: Meter 1", 105 | CNT_INTVAL },
365 { "LED: Channel C: Meter 2", 106 | CNT_INTVAL },
366 { "LED: Channel C: Meter 3", 107 | CNT_INTVAL },
367 { "LED: Channel C: Meter 4", 108 | CNT_INTVAL },
368 { "LED: Channel C: Meter 5", 109 | CNT_INTVAL },
369 { "LED: Channel C: Meter 6", 110 | CNT_INTVAL },
370 { "LED: Channel C: Meter clip", 111 | CNT_INTVAL },
371 { "LED: Channel C: Active", 115 | CNT_INTVAL },
372 { "LED: Channel C: Cue", 117 | CNT_INTVAL },
373 { "LED: Channel C: FX1", 151 | CNT_INTVAL },
374 { "LED: Channel C: FX2", 150 | CNT_INTVAL },
375
376 { "LED: Channel D: >", 0 | CNT_INTVAL },
377 { "LED: Channel D: <", 1 | CNT_INTVAL },
378 { "LED: Channel D: Meter 1", 81 | CNT_INTVAL },
379 { "LED: Channel D: Meter 2", 82 | CNT_INTVAL },
380 { "LED: Channel D: Meter 3", 83 | CNT_INTVAL },
381 { "LED: Channel D: Meter 4", 84 | CNT_INTVAL },
382 { "LED: Channel D: Meter 5", 85 | CNT_INTVAL },
383 { "LED: Channel D: Meter 6", 86 | CNT_INTVAL },
384 { "LED: Channel D: Meter clip", 87 | CNT_INTVAL },
385 { "LED: Channel D: Active", 123 | CNT_INTVAL },
386 { "LED: Channel D: Cue", 124 | CNT_INTVAL },
387 { "LED: Channel D: FX1", 145 | CNT_INTVAL },
388 { "LED: Channel D: FX2", 144 | CNT_INTVAL },
389
390 { "LED: Deck A: 1 (blue)", 22 | CNT_INTVAL },
391 { "LED: Deck A: 1 (green)", 23 | CNT_INTVAL },
392 { "LED: Deck A: 2 (blue)", 20 | CNT_INTVAL },
393 { "LED: Deck A: 2 (green)", 21 | CNT_INTVAL },
394 { "LED: Deck A: 3 (blue)", 18 | CNT_INTVAL },
395 { "LED: Deck A: 3 (green)", 19 | CNT_INTVAL },
396 { "LED: Deck A: 4 (blue)", 16 | CNT_INTVAL },
397 { "LED: Deck A: 4 (green)", 17 | CNT_INTVAL },
398 { "LED: Deck A: Load", 44 | CNT_INTVAL },
399 { "LED: Deck A: Deck C button", 45 | CNT_INTVAL },
400 { "LED: Deck A: In", 47 | CNT_INTVAL },
401 { "LED: Deck A: Out", 46 | CNT_INTVAL },
402 { "LED: Deck A: Shift", 24 | CNT_INTVAL },
403 { "LED: Deck A: Sync", 27 | CNT_INTVAL },
404 { "LED: Deck A: Cue", 26 | CNT_INTVAL },
405 { "LED: Deck A: Play", 25 | CNT_INTVAL },
406 { "LED: Deck A: Tempo up", 33 | CNT_INTVAL },
407 { "LED: Deck A: Tempo down", 32 | CNT_INTVAL },
408 { "LED: Deck A: Master", 34 | CNT_INTVAL },
409 { "LED: Deck A: Keylock", 35 | CNT_INTVAL },
410 { "LED: Deck A: Deck A", 37 | CNT_INTVAL },
411 { "LED: Deck A: Deck C", 36 | CNT_INTVAL },
412 { "LED: Deck A: Samples", 38 | CNT_INTVAL },
413 { "LED: Deck A: On Air", 39 | CNT_INTVAL },
414 { "LED: Deck A: Sample 1", 31 | CNT_INTVAL },
415 { "LED: Deck A: Sample 2", 30 | CNT_INTVAL },
416 { "LED: Deck A: Sample 3", 29 | CNT_INTVAL },
417 { "LED: Deck A: Sample 4", 28 | CNT_INTVAL },
418 { "LED: Deck A: Digit 1 - A", 55 | CNT_INTVAL },
419 { "LED: Deck A: Digit 1 - B", 54 | CNT_INTVAL },
420 { "LED: Deck A: Digit 1 - C", 53 | CNT_INTVAL },
421 { "LED: Deck A: Digit 1 - D", 52 | CNT_INTVAL },
422 { "LED: Deck A: Digit 1 - E", 51 | CNT_INTVAL },
423 { "LED: Deck A: Digit 1 - F", 50 | CNT_INTVAL },
424 { "LED: Deck A: Digit 1 - G", 49 | CNT_INTVAL },
425 { "LED: Deck A: Digit 1 - dot", 48 | CNT_INTVAL },
426 { "LED: Deck A: Digit 2 - A", 63 | CNT_INTVAL },
427 { "LED: Deck A: Digit 2 - B", 62 | CNT_INTVAL },
428 { "LED: Deck A: Digit 2 - C", 61 | CNT_INTVAL },
429 { "LED: Deck A: Digit 2 - D", 60 | CNT_INTVAL },
430 { "LED: Deck A: Digit 2 - E", 59 | CNT_INTVAL },
431 { "LED: Deck A: Digit 2 - F", 58 | CNT_INTVAL },
432 { "LED: Deck A: Digit 2 - G", 57 | CNT_INTVAL },
433 { "LED: Deck A: Digit 2 - dot", 56 | CNT_INTVAL },
434
435 { "LED: Deck B: 1 (blue)", 78 | CNT_INTVAL },
436 { "LED: Deck B: 1 (green)", 79 | CNT_INTVAL },
437 { "LED: Deck B: 2 (blue)", 76 | CNT_INTVAL },
438 { "LED: Deck B: 2 (green)", 77 | CNT_INTVAL },
439 { "LED: Deck B: 3 (blue)", 74 | CNT_INTVAL },
440 { "LED: Deck B: 3 (green)", 75 | CNT_INTVAL },
441 { "LED: Deck B: 4 (blue)", 72 | CNT_INTVAL },
442 { "LED: Deck B: 4 (green)", 73 | CNT_INTVAL },
443 { "LED: Deck B: Load", 180 | CNT_INTVAL },
444 { "LED: Deck B: Deck D button", 181 | CNT_INTVAL },
445 { "LED: Deck B: In", 183 | CNT_INTVAL },
446 { "LED: Deck B: Out", 182 | CNT_INTVAL },
447 { "LED: Deck B: Shift", 64 | CNT_INTVAL },
448 { "LED: Deck B: Sync", 67 | CNT_INTVAL },
449 { "LED: Deck B: Cue", 66 | CNT_INTVAL },
450 { "LED: Deck B: Play", 65 | CNT_INTVAL },
451 { "LED: Deck B: Tempo up", 185 | CNT_INTVAL },
452 { "LED: Deck B: Tempo down", 184 | CNT_INTVAL },
453 { "LED: Deck B: Master", 186 | CNT_INTVAL },
454 { "LED: Deck B: Keylock", 187 | CNT_INTVAL },
455 { "LED: Deck B: Deck B", 189 | CNT_INTVAL },
456 { "LED: Deck B: Deck D", 188 | CNT_INTVAL },
457 { "LED: Deck B: Samples", 190 | CNT_INTVAL },
458 { "LED: Deck B: On Air", 191 | CNT_INTVAL },
459 { "LED: Deck B: Sample 1", 71 | CNT_INTVAL },
460 { "LED: Deck B: Sample 2", 70 | CNT_INTVAL },
461 { "LED: Deck B: Sample 3", 69 | CNT_INTVAL },
462 { "LED: Deck B: Sample 4", 68 | CNT_INTVAL },
463 { "LED: Deck B: Digit 1 - A", 175 | CNT_INTVAL },
464 { "LED: Deck B: Digit 1 - B", 174 | CNT_INTVAL },
465 { "LED: Deck B: Digit 1 - C", 173 | CNT_INTVAL },
466 { "LED: Deck B: Digit 1 - D", 172 | CNT_INTVAL },
467 { "LED: Deck B: Digit 1 - E", 171 | CNT_INTVAL },
468 { "LED: Deck B: Digit 1 - F", 170 | CNT_INTVAL },
469 { "LED: Deck B: Digit 1 - G", 169 | CNT_INTVAL },
470 { "LED: Deck B: Digit 1 - dot", 168 | CNT_INTVAL },
471 { "LED: Deck B: Digit 2 - A", 167 | CNT_INTVAL },
472 { "LED: Deck B: Digit 2 - B", 166 | CNT_INTVAL },
473 { "LED: Deck B: Digit 2 - C", 165 | CNT_INTVAL },
474 { "LED: Deck B: Digit 2 - D", 164 | CNT_INTVAL },
475 { "LED: Deck B: Digit 2 - E", 163 | CNT_INTVAL },
476 { "LED: Deck B: Digit 2 - F", 162 | CNT_INTVAL },
477 { "LED: Deck B: Digit 2 - G", 161 | CNT_INTVAL },
478 { "LED: Deck B: Digit 2 - dot", 160 | CNT_INTVAL },
479
480 { "LED: FX1: dry/wet", 153 | CNT_INTVAL },
481 { "LED: FX1: 1", 154 | CNT_INTVAL },
482 { "LED: FX1: 2", 155 | CNT_INTVAL },
483 { "LED: FX1: 3", 156 | CNT_INTVAL },
484 { "LED: FX1: Mode", 157 | CNT_INTVAL },
485 { "LED: FX2: dry/wet", 129 | CNT_INTVAL },
486 { "LED: FX2: 1", 130 | CNT_INTVAL },
487 { "LED: FX2: 2", 131 | CNT_INTVAL },
488 { "LED: FX2: 3", 132 | CNT_INTVAL },
489 { "LED: FX2: Mode", 133 | CNT_INTVAL },
490};
491
299static int __devinit add_controls(struct caiaq_controller *c, int num, 492static int __devinit add_controls(struct caiaq_controller *c, int num,
300 struct snd_usb_caiaqdev *dev) 493 struct snd_usb_caiaqdev *dev)
301{ 494{
@@ -354,6 +547,11 @@ int __devinit snd_usb_caiaq_control_init(struct snd_usb_caiaqdev *dev)
354 ret = add_controls(kontrolx1_controller, 547 ret = add_controls(kontrolx1_controller,
355 ARRAY_SIZE(kontrolx1_controller), dev); 548 ARRAY_SIZE(kontrolx1_controller), dev);
356 break; 549 break;
550
551 case USB_ID(USB_VID_NATIVEINSTRUMENTS, USB_PID_TRAKTORKONTROLS4):
552 ret = add_controls(kontrols4_controller,
553 ARRAY_SIZE(kontrols4_controller), dev);
554 break;
357 } 555 }
358 556
359 return ret; 557 return ret;
diff --git a/sound/usb/caiaq/device.c b/sound/usb/caiaq/device.c
index cdfb856bddd2..45bc4a2dc6f0 100644
--- a/sound/usb/caiaq/device.c
+++ b/sound/usb/caiaq/device.c
@@ -36,7 +36,7 @@
36#include "input.h" 36#include "input.h"
37 37
38MODULE_AUTHOR("Daniel Mack <daniel@caiaq.de>"); 38MODULE_AUTHOR("Daniel Mack <daniel@caiaq.de>");
39MODULE_DESCRIPTION("caiaq USB audio, version 1.3.21"); 39MODULE_DESCRIPTION("caiaq USB audio");
40MODULE_LICENSE("GPL"); 40MODULE_LICENSE("GPL");
41MODULE_SUPPORTED_DEVICE("{{Native Instruments, RigKontrol2}," 41MODULE_SUPPORTED_DEVICE("{{Native Instruments, RigKontrol2},"
42 "{Native Instruments, RigKontrol3}," 42 "{Native Instruments, RigKontrol3},"
@@ -46,9 +46,11 @@ MODULE_SUPPORTED_DEVICE("{{Native Instruments, RigKontrol2},"
46 "{Native Instruments, Audio 2 DJ}," 46 "{Native Instruments, Audio 2 DJ},"
47 "{Native Instruments, Audio 4 DJ}," 47 "{Native Instruments, Audio 4 DJ},"
48 "{Native Instruments, Audio 8 DJ}," 48 "{Native Instruments, Audio 8 DJ},"
49 "{Native Instruments, Traktor Audio 2},"
49 "{Native Instruments, Session I/O}," 50 "{Native Instruments, Session I/O},"
50 "{Native Instruments, GuitarRig mobile}" 51 "{Native Instruments, GuitarRig mobile}"
51 "{Native Instruments, Traktor Kontrol X1}"); 52 "{Native Instruments, Traktor Kontrol X1}"
53 "{Native Instruments, Traktor Kontrol S4}");
52 54
53static int index[SNDRV_CARDS] = SNDRV_DEFAULT_IDX; /* Index 0-max */ 55static int index[SNDRV_CARDS] = SNDRV_DEFAULT_IDX; /* Index 0-max */
54static char* id[SNDRV_CARDS] = SNDRV_DEFAULT_STR; /* Id for this card */ 56static char* id[SNDRV_CARDS] = SNDRV_DEFAULT_STR; /* Id for this card */
@@ -134,6 +136,16 @@ static struct usb_device_id snd_usb_id_table[] = {
134 .idVendor = USB_VID_NATIVEINSTRUMENTS, 136 .idVendor = USB_VID_NATIVEINSTRUMENTS,
135 .idProduct = USB_PID_TRAKTORKONTROLX1 137 .idProduct = USB_PID_TRAKTORKONTROLX1
136 }, 138 },
139 {
140 .match_flags = USB_DEVICE_ID_MATCH_DEVICE,
141 .idVendor = USB_VID_NATIVEINSTRUMENTS,
142 .idProduct = USB_PID_TRAKTORKONTROLS4
143 },
144 {
145 .match_flags = USB_DEVICE_ID_MATCH_DEVICE,
146 .idVendor = USB_VID_NATIVEINSTRUMENTS,
147 .idProduct = USB_PID_TRAKTORAUDIO2
148 },
137 { /* terminator */ } 149 { /* terminator */ }
138}; 150};
139 151
diff --git a/sound/usb/caiaq/device.h b/sound/usb/caiaq/device.h
index f1117ecc84fd..b2b310194ffa 100644
--- a/sound/usb/caiaq/device.h
+++ b/sound/usb/caiaq/device.h
@@ -16,6 +16,8 @@
16#define USB_PID_SESSIONIO 0x1915 16#define USB_PID_SESSIONIO 0x1915
17#define USB_PID_GUITARRIGMOBILE 0x0d8d 17#define USB_PID_GUITARRIGMOBILE 0x0d8d
18#define USB_PID_TRAKTORKONTROLX1 0x2305 18#define USB_PID_TRAKTORKONTROLX1 0x2305
19#define USB_PID_TRAKTORKONTROLS4 0xbaff
20#define USB_PID_TRAKTORAUDIO2 0x041d
19 21
20#define EP1_BUFSIZE 64 22#define EP1_BUFSIZE 64
21#define EP4_BUFSIZE 512 23#define EP4_BUFSIZE 512
@@ -99,13 +101,14 @@ struct snd_usb_caiaqdev {
99 struct snd_pcm_substream *sub_capture[MAX_STREAMS]; 101 struct snd_pcm_substream *sub_capture[MAX_STREAMS];
100 102
101 /* Controls */ 103 /* Controls */
102 unsigned char control_state[64]; 104 unsigned char control_state[256];
105 unsigned char ep8_out_buf[2];
103 106
104 /* Linux input */ 107 /* Linux input */
105#ifdef CONFIG_SND_USB_CAIAQ_INPUT 108#ifdef CONFIG_SND_USB_CAIAQ_INPUT
106 struct input_dev *input_dev; 109 struct input_dev *input_dev;
107 char phys[64]; /* physical device path */ 110 char phys[64]; /* physical device path */
108 unsigned short keycode[64]; 111 unsigned short keycode[128];
109 struct urb *ep4_in_urb; 112 struct urb *ep4_in_urb;
110 unsigned char ep4_in_buf[EP4_BUFSIZE]; 113 unsigned char ep4_in_buf[EP4_BUFSIZE];
111#endif 114#endif
diff --git a/sound/usb/caiaq/input.c b/sound/usb/caiaq/input.c
index dcb620796d9e..4432ef7a70a9 100644
--- a/sound/usb/caiaq/input.c
+++ b/sound/usb/caiaq/input.c
@@ -67,7 +67,12 @@ static unsigned short keycode_kore[] = {
67 KEY_BRL_DOT5 67 KEY_BRL_DOT5
68}; 68};
69 69
70#define KONTROLX1_INPUTS 40 70#define KONTROLX1_INPUTS (40)
71#define KONTROLS4_BUTTONS (12 * 8)
72#define KONTROLS4_AXIS (46)
73
74#define KONTROLS4_BUTTON(X) ((X) + BTN_MISC)
75#define KONTROLS4_ABS(X) ((X) + ABS_HAT0X)
71 76
72#define DEG90 (range / 2) 77#define DEG90 (range / 2)
73#define DEG180 (range) 78#define DEG180 (range)
@@ -139,6 +144,13 @@ static unsigned int decode_erp(unsigned char a, unsigned char b)
139#undef HIGH_PEAK 144#undef HIGH_PEAK
140#undef LOW_PEAK 145#undef LOW_PEAK
141 146
147static inline void snd_caiaq_input_report_abs(struct snd_usb_caiaqdev *dev,
148 int axis, const unsigned char *buf,
149 int offset)
150{
151 input_report_abs(dev->input_dev, axis,
152 (buf[offset * 2] << 8) | buf[offset * 2 + 1]);
153}
142 154
143static void snd_caiaq_input_read_analog(struct snd_usb_caiaqdev *dev, 155static void snd_caiaq_input_read_analog(struct snd_usb_caiaqdev *dev,
144 const unsigned char *buf, 156 const unsigned char *buf,
@@ -148,36 +160,30 @@ static void snd_caiaq_input_read_analog(struct snd_usb_caiaqdev *dev,
148 160
149 switch (dev->chip.usb_id) { 161 switch (dev->chip.usb_id) {
150 case USB_ID(USB_VID_NATIVEINSTRUMENTS, USB_PID_RIGKONTROL2): 162 case USB_ID(USB_VID_NATIVEINSTRUMENTS, USB_PID_RIGKONTROL2):
151 input_report_abs(input_dev, ABS_X, (buf[4] << 8) | buf[5]); 163 snd_caiaq_input_report_abs(dev, ABS_X, buf, 2);
152 input_report_abs(input_dev, ABS_Y, (buf[0] << 8) | buf[1]); 164 snd_caiaq_input_report_abs(dev, ABS_Y, buf, 0);
153 input_report_abs(input_dev, ABS_Z, (buf[2] << 8) | buf[3]); 165 snd_caiaq_input_report_abs(dev, ABS_Z, buf, 1);
154 input_sync(input_dev);
155 break; 166 break;
156 case USB_ID(USB_VID_NATIVEINSTRUMENTS, USB_PID_RIGKONTROL3): 167 case USB_ID(USB_VID_NATIVEINSTRUMENTS, USB_PID_RIGKONTROL3):
157 input_report_abs(input_dev, ABS_X, (buf[0] << 8) | buf[1]);
158 input_report_abs(input_dev, ABS_Y, (buf[2] << 8) | buf[3]);
159 input_report_abs(input_dev, ABS_Z, (buf[4] << 8) | buf[5]);
160 input_sync(input_dev);
161 break;
162 case USB_ID(USB_VID_NATIVEINSTRUMENTS, USB_PID_KORECONTROLLER): 168 case USB_ID(USB_VID_NATIVEINSTRUMENTS, USB_PID_KORECONTROLLER):
163 case USB_ID(USB_VID_NATIVEINSTRUMENTS, USB_PID_KORECONTROLLER2): 169 case USB_ID(USB_VID_NATIVEINSTRUMENTS, USB_PID_KORECONTROLLER2):
164 input_report_abs(input_dev, ABS_X, (buf[0] << 8) | buf[1]); 170 snd_caiaq_input_report_abs(dev, ABS_X, buf, 0);
165 input_report_abs(input_dev, ABS_Y, (buf[2] << 8) | buf[3]); 171 snd_caiaq_input_report_abs(dev, ABS_Y, buf, 1);
166 input_report_abs(input_dev, ABS_Z, (buf[4] << 8) | buf[5]); 172 snd_caiaq_input_report_abs(dev, ABS_Z, buf, 2);
167 input_sync(input_dev);
168 break; 173 break;
169 case USB_ID(USB_VID_NATIVEINSTRUMENTS, USB_PID_TRAKTORKONTROLX1): 174 case USB_ID(USB_VID_NATIVEINSTRUMENTS, USB_PID_TRAKTORKONTROLX1):
170 input_report_abs(input_dev, ABS_HAT0X, (buf[8] << 8) | buf[9]); 175 snd_caiaq_input_report_abs(dev, ABS_HAT0X, buf, 4);
171 input_report_abs(input_dev, ABS_HAT0Y, (buf[4] << 8) | buf[5]); 176 snd_caiaq_input_report_abs(dev, ABS_HAT0Y, buf, 2);
172 input_report_abs(input_dev, ABS_HAT1X, (buf[12] << 8) | buf[13]); 177 snd_caiaq_input_report_abs(dev, ABS_HAT1X, buf, 6);
173 input_report_abs(input_dev, ABS_HAT1Y, (buf[2] << 8) | buf[3]); 178 snd_caiaq_input_report_abs(dev, ABS_HAT1Y, buf, 1);
174 input_report_abs(input_dev, ABS_HAT2X, (buf[14] << 8) | buf[15]); 179 snd_caiaq_input_report_abs(dev, ABS_HAT2X, buf, 7);
175 input_report_abs(input_dev, ABS_HAT2Y, (buf[0] << 8) | buf[1]); 180 snd_caiaq_input_report_abs(dev, ABS_HAT2Y, buf, 0);
176 input_report_abs(input_dev, ABS_HAT3X, (buf[10] << 8) | buf[11]); 181 snd_caiaq_input_report_abs(dev, ABS_HAT3X, buf, 5);
177 input_report_abs(input_dev, ABS_HAT3Y, (buf[6] << 8) | buf[7]); 182 snd_caiaq_input_report_abs(dev, ABS_HAT3Y, buf, 3);
178 input_sync(input_dev);
179 break; 183 break;
180 } 184 }
185
186 input_sync(input_dev);
181} 187}
182 188
183static void snd_caiaq_input_read_erp(struct snd_usb_caiaqdev *dev, 189static void snd_caiaq_input_read_erp(struct snd_usb_caiaqdev *dev,
@@ -250,6 +256,150 @@ static void snd_caiaq_input_read_io(struct snd_usb_caiaqdev *dev,
250 input_sync(input_dev); 256 input_sync(input_dev);
251} 257}
252 258
259#define TKS4_MSGBLOCK_SIZE 16
260
261static void snd_usb_caiaq_tks4_dispatch(struct snd_usb_caiaqdev *dev,
262 const unsigned char *buf,
263 unsigned int len)
264{
265 while (len) {
266 unsigned int i, block_id = (buf[0] << 8) | buf[1];
267
268 switch (block_id) {
269 case 0:
270 /* buttons */
271 for (i = 0; i < KONTROLS4_BUTTONS; i++)
272 input_report_key(dev->input_dev, KONTROLS4_BUTTON(i),
273 (buf[4 + (i / 8)] >> (i % 8)) & 1);
274 break;
275
276 case 1:
277 /* left wheel */
278 input_report_abs(dev->input_dev, KONTROLS4_ABS(36), buf[9] | ((buf[8] & 0x3) << 8));
279 /* right wheel */
280 input_report_abs(dev->input_dev, KONTROLS4_ABS(37), buf[13] | ((buf[12] & 0x3) << 8));
281
282 /* rotary encoders */
283 input_report_abs(dev->input_dev, KONTROLS4_ABS(38), buf[3] & 0xf);
284 input_report_abs(dev->input_dev, KONTROLS4_ABS(39), buf[4] >> 4);
285 input_report_abs(dev->input_dev, KONTROLS4_ABS(40), buf[4] & 0xf);
286 input_report_abs(dev->input_dev, KONTROLS4_ABS(41), buf[5] >> 4);
287 input_report_abs(dev->input_dev, KONTROLS4_ABS(42), buf[5] & 0xf);
288 input_report_abs(dev->input_dev, KONTROLS4_ABS(43), buf[6] >> 4);
289 input_report_abs(dev->input_dev, KONTROLS4_ABS(44), buf[6] & 0xf);
290 input_report_abs(dev->input_dev, KONTROLS4_ABS(45), buf[7] >> 4);
291 input_report_abs(dev->input_dev, KONTROLS4_ABS(46), buf[7] & 0xf);
292
293 break;
294 case 2:
295 /* Volume Fader Channel D */
296 snd_caiaq_input_report_abs(dev, KONTROLS4_ABS(0), buf, 1);
297 /* Volume Fader Channel B */
298 snd_caiaq_input_report_abs(dev, KONTROLS4_ABS(1), buf, 2);
299 /* Volume Fader Channel A */
300 snd_caiaq_input_report_abs(dev, KONTROLS4_ABS(2), buf, 3);
301 /* Volume Fader Channel C */
302 snd_caiaq_input_report_abs(dev, KONTROLS4_ABS(3), buf, 4);
303 /* Loop Volume */
304 snd_caiaq_input_report_abs(dev, KONTROLS4_ABS(4), buf, 6);
305 /* Crossfader */
306 snd_caiaq_input_report_abs(dev, KONTROLS4_ABS(7), buf, 7);
307
308 break;
309
310 case 3:
311 /* Tempo Fader R */
312 snd_caiaq_input_report_abs(dev, KONTROLS4_ABS(6), buf, 3);
313 /* Tempo Fader L */
314 snd_caiaq_input_report_abs(dev, KONTROLS4_ABS(5), buf, 4);
315 /* Mic Volume */
316 snd_caiaq_input_report_abs(dev, KONTROLS4_ABS(8), buf, 6);
317 /* Cue Mix */
318 snd_caiaq_input_report_abs(dev, KONTROLS4_ABS(9), buf, 7);
319
320 break;
321
322 case 4:
323 /* Wheel distance sensor L */
324 snd_caiaq_input_report_abs(dev, KONTROLS4_ABS(10), buf, 1);
325 /* Wheel distance sensor R */
326 snd_caiaq_input_report_abs(dev, KONTROLS4_ABS(11), buf, 2);
327 /* Channel D EQ - Filter */
328 snd_caiaq_input_report_abs(dev, KONTROLS4_ABS(12), buf, 3);
329 /* Channel D EQ - Low */
330 snd_caiaq_input_report_abs(dev, KONTROLS4_ABS(13), buf, 4);
331 /* Channel D EQ - Mid */
332 snd_caiaq_input_report_abs(dev, KONTROLS4_ABS(14), buf, 5);
333 /* Channel D EQ - Hi */
334 snd_caiaq_input_report_abs(dev, KONTROLS4_ABS(15), buf, 6);
335 /* FX2 - dry/wet */
336 snd_caiaq_input_report_abs(dev, KONTROLS4_ABS(16), buf, 7);
337
338 break;
339
340 case 5:
341 /* FX2 - 1 */
342 snd_caiaq_input_report_abs(dev, KONTROLS4_ABS(17), buf, 1);
343 /* FX2 - 2 */
344 snd_caiaq_input_report_abs(dev, KONTROLS4_ABS(18), buf, 2);
345 /* FX2 - 3 */
346 snd_caiaq_input_report_abs(dev, KONTROLS4_ABS(19), buf, 3);
347 /* Channel B EQ - Filter */
348 snd_caiaq_input_report_abs(dev, KONTROLS4_ABS(20), buf, 4);
349 /* Channel B EQ - Low */
350 snd_caiaq_input_report_abs(dev, KONTROLS4_ABS(21), buf, 5);
351 /* Channel B EQ - Mid */
352 snd_caiaq_input_report_abs(dev, KONTROLS4_ABS(22), buf, 6);
353 /* Channel B EQ - Hi */
354 snd_caiaq_input_report_abs(dev, KONTROLS4_ABS(23), buf, 7);
355
356 break;
357
358 case 6:
359 /* Channel A EQ - Filter */
360 snd_caiaq_input_report_abs(dev, KONTROLS4_ABS(24), buf, 1);
361 /* Channel A EQ - Low */
362 snd_caiaq_input_report_abs(dev, KONTROLS4_ABS(25), buf, 2);
363 /* Channel A EQ - Mid */
364 snd_caiaq_input_report_abs(dev, KONTROLS4_ABS(26), buf, 3);
365 /* Channel A EQ - Hi */
366 snd_caiaq_input_report_abs(dev, KONTROLS4_ABS(27), buf, 4);
367 /* Channel C EQ - Filter */
368 snd_caiaq_input_report_abs(dev, KONTROLS4_ABS(28), buf, 5);
369 /* Channel C EQ - Low */
370 snd_caiaq_input_report_abs(dev, KONTROLS4_ABS(29), buf, 6);
371 /* Channel C EQ - Mid */
372 snd_caiaq_input_report_abs(dev, KONTROLS4_ABS(30), buf, 7);
373
374 break;
375
376 case 7:
377 /* Channel C EQ - Hi */
378 snd_caiaq_input_report_abs(dev, KONTROLS4_ABS(31), buf, 1);
379 /* FX1 - wet/dry */
380 snd_caiaq_input_report_abs(dev, KONTROLS4_ABS(32), buf, 2);
381 /* FX1 - 1 */
382 snd_caiaq_input_report_abs(dev, KONTROLS4_ABS(33), buf, 3);
383 /* FX1 - 2 */
384 snd_caiaq_input_report_abs(dev, KONTROLS4_ABS(34), buf, 4);
385 /* FX1 - 3 */
386 snd_caiaq_input_report_abs(dev, KONTROLS4_ABS(35), buf, 5);
387
388 break;
389
390 default:
391 debug("%s(): bogus block (id %d)\n",
392 __func__, block_id);
393 return;
394 }
395
396 len -= TKS4_MSGBLOCK_SIZE;
397 buf += TKS4_MSGBLOCK_SIZE;
398 }
399
400 input_sync(dev->input_dev);
401}
402
253static void snd_usb_caiaq_ep4_reply_dispatch(struct urb *urb) 403static void snd_usb_caiaq_ep4_reply_dispatch(struct urb *urb)
254{ 404{
255 struct snd_usb_caiaqdev *dev = urb->context; 405 struct snd_usb_caiaqdev *dev = urb->context;
@@ -259,11 +409,11 @@ static void snd_usb_caiaq_ep4_reply_dispatch(struct urb *urb)
259 if (urb->status || !dev || urb != dev->ep4_in_urb) 409 if (urb->status || !dev || urb != dev->ep4_in_urb)
260 return; 410 return;
261 411
262 if (urb->actual_length < 24)
263 goto requeue;
264
265 switch (dev->chip.usb_id) { 412 switch (dev->chip.usb_id) {
266 case USB_ID(USB_VID_NATIVEINSTRUMENTS, USB_PID_TRAKTORKONTROLX1): 413 case USB_ID(USB_VID_NATIVEINSTRUMENTS, USB_PID_TRAKTORKONTROLX1):
414 if (urb->actual_length < 24)
415 goto requeue;
416
267 if (buf[0] & 0x3) 417 if (buf[0] & 0x3)
268 snd_caiaq_input_read_io(dev, buf + 1, 7); 418 snd_caiaq_input_read_io(dev, buf + 1, 7);
269 419
@@ -271,6 +421,10 @@ static void snd_usb_caiaq_ep4_reply_dispatch(struct urb *urb)
271 snd_caiaq_input_read_analog(dev, buf + 8, 16); 421 snd_caiaq_input_read_analog(dev, buf + 8, 16);
272 422
273 break; 423 break;
424
425 case USB_ID(USB_VID_NATIVEINSTRUMENTS, USB_PID_TRAKTORKONTROLS4):
426 snd_usb_caiaq_tks4_dispatch(dev, buf, urb->actual_length);
427 break;
274 } 428 }
275 429
276requeue: 430requeue:
@@ -289,6 +443,7 @@ static int snd_usb_caiaq_input_open(struct input_dev *idev)
289 443
290 switch (dev->chip.usb_id) { 444 switch (dev->chip.usb_id) {
291 case USB_ID(USB_VID_NATIVEINSTRUMENTS, USB_PID_TRAKTORKONTROLX1): 445 case USB_ID(USB_VID_NATIVEINSTRUMENTS, USB_PID_TRAKTORKONTROLX1):
446 case USB_ID(USB_VID_NATIVEINSTRUMENTS, USB_PID_TRAKTORKONTROLS4):
292 if (usb_submit_urb(dev->ep4_in_urb, GFP_KERNEL) != 0) 447 if (usb_submit_urb(dev->ep4_in_urb, GFP_KERNEL) != 0)
293 return -EIO; 448 return -EIO;
294 break; 449 break;
@@ -306,6 +461,7 @@ static void snd_usb_caiaq_input_close(struct input_dev *idev)
306 461
307 switch (dev->chip.usb_id) { 462 switch (dev->chip.usb_id) {
308 case USB_ID(USB_VID_NATIVEINSTRUMENTS, USB_PID_TRAKTORKONTROLX1): 463 case USB_ID(USB_VID_NATIVEINSTRUMENTS, USB_PID_TRAKTORKONTROLX1):
464 case USB_ID(USB_VID_NATIVEINSTRUMENTS, USB_PID_TRAKTORKONTROLS4):
309 usb_kill_urb(dev->ep4_in_urb); 465 usb_kill_urb(dev->ep4_in_urb);
310 break; 466 break;
311 } 467 }
@@ -456,6 +612,46 @@ int snd_usb_caiaq_input_init(struct snd_usb_caiaqdev *dev)
456 snd_usb_caiaq_set_auto_msg(dev, 1, 10, 5); 612 snd_usb_caiaq_set_auto_msg(dev, 1, 10, 5);
457 613
458 break; 614 break;
615
616 case USB_ID(USB_VID_NATIVEINSTRUMENTS, USB_PID_TRAKTORKONTROLS4):
617 input->evbit[0] = BIT_MASK(EV_KEY) | BIT_MASK(EV_ABS);
618 BUILD_BUG_ON(sizeof(dev->keycode) < KONTROLS4_BUTTONS);
619 for (i = 0; i < KONTROLS4_BUTTONS; i++)
620 dev->keycode[i] = KONTROLS4_BUTTON(i);
621 input->keycodemax = KONTROLS4_BUTTONS;
622
623 for (i = 0; i < KONTROLS4_AXIS; i++) {
624 int axis = KONTROLS4_ABS(i);
625 input->absbit[BIT_WORD(axis)] |= BIT_MASK(axis);
626 }
627
628 /* 36 analog potentiometers and faders */
629 for (i = 0; i < 36; i++)
630 input_set_abs_params(input, KONTROLS4_ABS(i), 0, 0xfff, 0, 10);
631
632 /* 2 encoder wheels */
633 input_set_abs_params(input, KONTROLS4_ABS(36), 0, 0x3ff, 0, 1);
634 input_set_abs_params(input, KONTROLS4_ABS(37), 0, 0x3ff, 0, 1);
635
636 /* 9 rotary encoders */
637 for (i = 0; i < 9; i++)
638 input_set_abs_params(input, KONTROLS4_ABS(38+i), 0, 0xf, 0, 1);
639
640 dev->ep4_in_urb = usb_alloc_urb(0, GFP_KERNEL);
641 if (!dev->ep4_in_urb) {
642 ret = -ENOMEM;
643 goto exit_free_idev;
644 }
645
646 usb_fill_bulk_urb(dev->ep4_in_urb, usb_dev,
647 usb_rcvbulkpipe(usb_dev, 0x4),
648 dev->ep4_in_buf, EP4_BUFSIZE,
649 snd_usb_caiaq_ep4_reply_dispatch, dev);
650
651 snd_usb_caiaq_set_auto_msg(dev, 1, 10, 5);
652
653 break;
654
459 default: 655 default:
460 /* no input methods supported on this device */ 656 /* no input methods supported on this device */
461 goto exit_free_idev; 657 goto exit_free_idev;
diff --git a/sound/usb/caiaq/midi.c b/sound/usb/caiaq/midi.c
index 2f218c77fff2..a1a47088fd0c 100644
--- a/sound/usb/caiaq/midi.c
+++ b/sound/usb/caiaq/midi.c
@@ -136,7 +136,7 @@ int snd_usb_caiaq_midi_init(struct snd_usb_caiaqdev *device)
136 if (ret < 0) 136 if (ret < 0)
137 return ret; 137 return ret;
138 138
139 strcpy(rmidi->name, device->product_name); 139 strlcpy(rmidi->name, device->product_name, sizeof(rmidi->name));
140 140
141 rmidi->info_flags = SNDRV_RAWMIDI_INFO_DUPLEX; 141 rmidi->info_flags = SNDRV_RAWMIDI_INFO_DUPLEX;
142 rmidi->private_data = device; 142 rmidi->private_data = device;
diff --git a/sound/usb/card.c b/sound/usb/card.c
index 4eabafa5b037..220c6167dd86 100644
--- a/sound/usb/card.c
+++ b/sound/usb/card.c
@@ -41,12 +41,14 @@
41#include <linux/list.h> 41#include <linux/list.h>
42#include <linux/slab.h> 42#include <linux/slab.h>
43#include <linux/string.h> 43#include <linux/string.h>
44#include <linux/ctype.h>
44#include <linux/usb.h> 45#include <linux/usb.h>
45#include <linux/moduleparam.h> 46#include <linux/moduleparam.h>
46#include <linux/mutex.h> 47#include <linux/mutex.h>
47#include <linux/usb/audio.h> 48#include <linux/usb/audio.h>
48#include <linux/usb/audio-v2.h> 49#include <linux/usb/audio-v2.h>
49 50
51#include <sound/control.h>
50#include <sound/core.h> 52#include <sound/core.h>
51#include <sound/info.h> 53#include <sound/info.h>
52#include <sound/pcm.h> 54#include <sound/pcm.h>
@@ -65,6 +67,7 @@
65#include "pcm.h" 67#include "pcm.h"
66#include "urb.h" 68#include "urb.h"
67#include "format.h" 69#include "format.h"
70#include "power.h"
68 71
69MODULE_AUTHOR("Takashi Iwai <tiwai@suse.de>"); 72MODULE_AUTHOR("Takashi Iwai <tiwai@suse.de>");
70MODULE_DESCRIPTION("USB Audio"); 73MODULE_DESCRIPTION("USB Audio");
@@ -282,6 +285,15 @@ static int snd_usb_audio_dev_free(struct snd_device *device)
282 return snd_usb_audio_free(chip); 285 return snd_usb_audio_free(chip);
283} 286}
284 287
288static void remove_trailing_spaces(char *str)
289{
290 char *p;
291
292 if (!*str)
293 return;
294 for (p = str + strlen(str) - 1; p >= str && isspace(*p); p--)
295 *p = 0;
296}
285 297
286/* 298/*
287 * create a chip instance and set its names. 299 * create a chip instance and set its names.
@@ -300,9 +312,13 @@ static int snd_usb_audio_create(struct usb_device *dev, int idx,
300 312
301 *rchip = NULL; 313 *rchip = NULL;
302 314
303 if (snd_usb_get_speed(dev) != USB_SPEED_LOW && 315 switch (snd_usb_get_speed(dev)) {
304 snd_usb_get_speed(dev) != USB_SPEED_FULL && 316 case USB_SPEED_LOW:
305 snd_usb_get_speed(dev) != USB_SPEED_HIGH) { 317 case USB_SPEED_FULL:
318 case USB_SPEED_HIGH:
319 case USB_SPEED_SUPER:
320 break;
321 default:
306 snd_printk(KERN_ERR "unknown device speed %d\n", snd_usb_get_speed(dev)); 322 snd_printk(KERN_ERR "unknown device speed %d\n", snd_usb_get_speed(dev));
307 return -ENXIO; 323 return -ENXIO;
308 } 324 }
@@ -319,12 +335,14 @@ static int snd_usb_audio_create(struct usb_device *dev, int idx,
319 return -ENOMEM; 335 return -ENOMEM;
320 } 336 }
321 337
338 mutex_init(&chip->shutdown_mutex);
322 chip->index = idx; 339 chip->index = idx;
323 chip->dev = dev; 340 chip->dev = dev;
324 chip->card = card; 341 chip->card = card;
325 chip->setup = device_setup[idx]; 342 chip->setup = device_setup[idx];
326 chip->nrpacks = nrpacks; 343 chip->nrpacks = nrpacks;
327 chip->async_unlink = async_unlink; 344 chip->async_unlink = async_unlink;
345 chip->probing = 1;
328 346
329 chip->usb_id = USB_ID(le16_to_cpu(dev->descriptor.idVendor), 347 chip->usb_id = USB_ID(le16_to_cpu(dev->descriptor.idVendor),
330 le16_to_cpu(dev->descriptor.idProduct)); 348 le16_to_cpu(dev->descriptor.idProduct));
@@ -344,7 +362,7 @@ static int snd_usb_audio_create(struct usb_device *dev, int idx,
344 snd_component_add(card, component); 362 snd_component_add(card, component);
345 363
346 /* retrieve the device string as shortname */ 364 /* retrieve the device string as shortname */
347 if (quirk && quirk->product_name) { 365 if (quirk && quirk->product_name && *quirk->product_name) {
348 strlcpy(card->shortname, quirk->product_name, sizeof(card->shortname)); 366 strlcpy(card->shortname, quirk->product_name, sizeof(card->shortname));
349 } else { 367 } else {
350 if (!dev->descriptor.iProduct || 368 if (!dev->descriptor.iProduct ||
@@ -356,9 +374,10 @@ static int snd_usb_audio_create(struct usb_device *dev, int idx,
356 USB_ID_PRODUCT(chip->usb_id)); 374 USB_ID_PRODUCT(chip->usb_id));
357 } 375 }
358 } 376 }
377 remove_trailing_spaces(card->shortname);
359 378
360 /* retrieve the vendor and device strings as longname */ 379 /* retrieve the vendor and device strings as longname */
361 if (quirk && quirk->vendor_name) { 380 if (quirk && quirk->vendor_name && *quirk->vendor_name) {
362 len = strlcpy(card->longname, quirk->vendor_name, sizeof(card->longname)); 381 len = strlcpy(card->longname, quirk->vendor_name, sizeof(card->longname));
363 } else { 382 } else {
364 if (dev->descriptor.iManufacturer) 383 if (dev->descriptor.iManufacturer)
@@ -368,8 +387,11 @@ static int snd_usb_audio_create(struct usb_device *dev, int idx,
368 len = 0; 387 len = 0;
369 /* we don't really care if there isn't any vendor string */ 388 /* we don't really care if there isn't any vendor string */
370 } 389 }
371 if (len > 0) 390 if (len > 0) {
372 strlcat(card->longname, " ", sizeof(card->longname)); 391 remove_trailing_spaces(card->longname);
392 if (*card->longname)
393 strlcat(card->longname, " ", sizeof(card->longname));
394 }
373 395
374 strlcat(card->longname, card->shortname, sizeof(card->longname)); 396 strlcat(card->longname, card->shortname, sizeof(card->longname));
375 397
@@ -378,11 +400,22 @@ static int snd_usb_audio_create(struct usb_device *dev, int idx,
378 if (len < sizeof(card->longname)) 400 if (len < sizeof(card->longname))
379 usb_make_path(dev, card->longname + len, sizeof(card->longname) - len); 401 usb_make_path(dev, card->longname + len, sizeof(card->longname) - len);
380 402
381 strlcat(card->longname, 403 switch (snd_usb_get_speed(dev)) {
382 snd_usb_get_speed(dev) == USB_SPEED_LOW ? ", low speed" : 404 case USB_SPEED_LOW:
383 snd_usb_get_speed(dev) == USB_SPEED_FULL ? ", full speed" : 405 strlcat(card->longname, ", low speed", sizeof(card->longname));
384 ", high speed", 406 break;
385 sizeof(card->longname)); 407 case USB_SPEED_FULL:
408 strlcat(card->longname, ", full speed", sizeof(card->longname));
409 break;
410 case USB_SPEED_HIGH:
411 strlcat(card->longname, ", high speed", sizeof(card->longname));
412 break;
413 case USB_SPEED_SUPER:
414 strlcat(card->longname, ", super speed", sizeof(card->longname));
415 break;
416 default:
417 break;
418 }
386 419
387 snd_usb_audio_create_proc(chip); 420 snd_usb_audio_create_proc(chip);
388 421
@@ -435,6 +468,7 @@ static void *snd_usb_audio_probe(struct usb_device *dev,
435 goto __error; 468 goto __error;
436 } 469 }
437 chip = usb_chip[i]; 470 chip = usb_chip[i];
471 chip->probing = 1;
438 break; 472 break;
439 } 473 }
440 } 474 }
@@ -450,6 +484,7 @@ static void *snd_usb_audio_probe(struct usb_device *dev,
450 goto __error; 484 goto __error;
451 } 485 }
452 snd_card_set_dev(chip->card, &intf->dev); 486 snd_card_set_dev(chip->card, &intf->dev);
487 chip->pm_intf = intf;
453 break; 488 break;
454 } 489 }
455 if (!chip) { 490 if (!chip) {
@@ -458,14 +493,6 @@ static void *snd_usb_audio_probe(struct usb_device *dev,
458 } 493 }
459 } 494 }
460 495
461 chip->txfr_quirk = 0;
462 err = 1; /* continue */
463 if (quirk && quirk->ifnum != QUIRK_NO_INTERFACE) {
464 /* need some special handlings */
465 if ((err = snd_usb_create_quirk(chip, intf, &usb_audio_driver, quirk)) < 0)
466 goto __error;
467 }
468
469 /* 496 /*
470 * For devices with more than one control interface, we assume the 497 * For devices with more than one control interface, we assume the
471 * first contains the audio controls. We might need a more specific 498 * first contains the audio controls. We might need a more specific
@@ -474,6 +501,14 @@ static void *snd_usb_audio_probe(struct usb_device *dev,
474 if (!chip->ctrl_intf) 501 if (!chip->ctrl_intf)
475 chip->ctrl_intf = alts; 502 chip->ctrl_intf = alts;
476 503
504 chip->txfr_quirk = 0;
505 err = 1; /* continue */
506 if (quirk && quirk->ifnum != QUIRK_NO_INTERFACE) {
507 /* need some special handlings */
508 if ((err = snd_usb_create_quirk(chip, intf, &usb_audio_driver, quirk)) < 0)
509 goto __error;
510 }
511
477 if (err > 0) { 512 if (err > 0) {
478 /* create normal USB audio interfaces */ 513 /* create normal USB audio interfaces */
479 if (snd_usb_create_streams(chip, ifnum) < 0 || 514 if (snd_usb_create_streams(chip, ifnum) < 0 ||
@@ -489,6 +524,7 @@ static void *snd_usb_audio_probe(struct usb_device *dev,
489 524
490 usb_chip[chip->index] = chip; 525 usb_chip[chip->index] = chip;
491 chip->num_interfaces++; 526 chip->num_interfaces++;
527 chip->probing = 0;
492 mutex_unlock(&register_mutex); 528 mutex_unlock(&register_mutex);
493 return chip; 529 return chip;
494 530
@@ -516,6 +552,7 @@ static void snd_usb_audio_disconnect(struct usb_device *dev, void *ptr)
516 chip = ptr; 552 chip = ptr;
517 card = chip->card; 553 card = chip->card;
518 mutex_lock(&register_mutex); 554 mutex_lock(&register_mutex);
555 mutex_lock(&chip->shutdown_mutex);
519 chip->shutdown = 1; 556 chip->shutdown = 1;
520 chip->num_interfaces--; 557 chip->num_interfaces--;
521 if (chip->num_interfaces <= 0) { 558 if (chip->num_interfaces <= 0) {
@@ -533,9 +570,11 @@ static void snd_usb_audio_disconnect(struct usb_device *dev, void *ptr)
533 snd_usb_mixer_disconnect(p); 570 snd_usb_mixer_disconnect(p);
534 } 571 }
535 usb_chip[chip->index] = NULL; 572 usb_chip[chip->index] = NULL;
573 mutex_unlock(&chip->shutdown_mutex);
536 mutex_unlock(&register_mutex); 574 mutex_unlock(&register_mutex);
537 snd_card_free_when_closed(card); 575 snd_card_free_when_closed(card);
538 } else { 576 } else {
577 mutex_unlock(&chip->shutdown_mutex);
539 mutex_unlock(&register_mutex); 578 mutex_unlock(&register_mutex);
540 } 579 }
541} 580}
@@ -562,29 +601,61 @@ static void usb_audio_disconnect(struct usb_interface *intf)
562} 601}
563 602
564#ifdef CONFIG_PM 603#ifdef CONFIG_PM
604
605int snd_usb_autoresume(struct snd_usb_audio *chip)
606{
607 int err = -ENODEV;
608
609 if (!chip->shutdown && !chip->probing)
610 err = usb_autopm_get_interface(chip->pm_intf);
611
612 return err;
613}
614
615void snd_usb_autosuspend(struct snd_usb_audio *chip)
616{
617 if (!chip->shutdown && !chip->probing)
618 usb_autopm_put_interface(chip->pm_intf);
619}
620
565static int usb_audio_suspend(struct usb_interface *intf, pm_message_t message) 621static int usb_audio_suspend(struct usb_interface *intf, pm_message_t message)
566{ 622{
567 struct snd_usb_audio *chip = usb_get_intfdata(intf); 623 struct snd_usb_audio *chip = usb_get_intfdata(intf);
568 struct list_head *p; 624 struct list_head *p;
569 struct snd_usb_stream *as; 625 struct snd_usb_stream *as;
626 struct usb_mixer_interface *mixer;
570 627
571 if (chip == (void *)-1L) 628 if (chip == (void *)-1L)
572 return 0; 629 return 0;
573 630
574 snd_power_change_state(chip->card, SNDRV_CTL_POWER_D3hot); 631 if (!(message.event & PM_EVENT_AUTO)) {
575 if (!chip->num_suspended_intf++) { 632 snd_power_change_state(chip->card, SNDRV_CTL_POWER_D3hot);
576 list_for_each(p, &chip->pcm_list) { 633 if (!chip->num_suspended_intf++) {
577 as = list_entry(p, struct snd_usb_stream, list); 634 list_for_each(p, &chip->pcm_list) {
578 snd_pcm_suspend_all(as->pcm); 635 as = list_entry(p, struct snd_usb_stream, list);
579 } 636 snd_pcm_suspend_all(as->pcm);
637 }
638 }
639 } else {
640 /*
641 * otherwise we keep the rest of the system in the dark
642 * to keep this transparent
643 */
644 if (!chip->num_suspended_intf++)
645 chip->autosuspended = 1;
580 } 646 }
581 647
648 list_for_each_entry(mixer, &chip->mixer_list, list)
649 snd_usb_mixer_inactivate(mixer);
650
582 return 0; 651 return 0;
583} 652}
584 653
585static int usb_audio_resume(struct usb_interface *intf) 654static int usb_audio_resume(struct usb_interface *intf)
586{ 655{
587 struct snd_usb_audio *chip = usb_get_intfdata(intf); 656 struct snd_usb_audio *chip = usb_get_intfdata(intf);
657 struct usb_mixer_interface *mixer;
658 int err = 0;
588 659
589 if (chip == (void *)-1L) 660 if (chip == (void *)-1L)
590 return 0; 661 return 0;
@@ -592,12 +663,20 @@ static int usb_audio_resume(struct usb_interface *intf)
592 return 0; 663 return 0;
593 /* 664 /*
594 * ALSA leaves material resumption to user space 665 * ALSA leaves material resumption to user space
595 * we just notify 666 * we just notify and restart the mixers
596 */ 667 */
668 list_for_each_entry(mixer, &chip->mixer_list, list) {
669 err = snd_usb_mixer_activate(mixer);
670 if (err < 0)
671 goto err_out;
672 }
597 673
598 snd_power_change_state(chip->card, SNDRV_CTL_POWER_D0); 674 if (!chip->autosuspended)
675 snd_power_change_state(chip->card, SNDRV_CTL_POWER_D0);
676 chip->autosuspended = 0;
599 677
600 return 0; 678err_out:
679 return err;
601} 680}
602#else 681#else
603#define usb_audio_suspend NULL 682#define usb_audio_suspend NULL
@@ -625,6 +704,7 @@ static struct usb_driver usb_audio_driver = {
625 .suspend = usb_audio_suspend, 704 .suspend = usb_audio_suspend,
626 .resume = usb_audio_resume, 705 .resume = usb_audio_resume,
627 .id_table = usb_audio_ids, 706 .id_table = usb_audio_ids,
707 .supports_autosuspend = 1,
628}; 708};
629 709
630static int __init snd_usb_audio_init(void) 710static int __init snd_usb_audio_init(void)
diff --git a/sound/usb/card.h b/sound/usb/card.h
index 1febf2f23754..ae4251d5abf7 100644
--- a/sound/usb/card.h
+++ b/sound/usb/card.h
@@ -62,12 +62,14 @@ struct snd_usb_substream {
62 unsigned int syncinterval; /* P for adaptive mode, 0 otherwise */ 62 unsigned int syncinterval; /* P for adaptive mode, 0 otherwise */
63 unsigned int freqn; /* nominal sampling rate in fs/fps in Q16.16 format */ 63 unsigned int freqn; /* nominal sampling rate in fs/fps in Q16.16 format */
64 unsigned int freqm; /* momentary sampling rate in fs/fps in Q16.16 format */ 64 unsigned int freqm; /* momentary sampling rate in fs/fps in Q16.16 format */
65 int freqshift; /* how much to shift the feedback value to get Q16.16 */
65 unsigned int freqmax; /* maximum sampling rate, used for buffer management */ 66 unsigned int freqmax; /* maximum sampling rate, used for buffer management */
66 unsigned int phase; /* phase accumulator */ 67 unsigned int phase; /* phase accumulator */
67 unsigned int maxpacksize; /* max packet size in bytes */ 68 unsigned int maxpacksize; /* max packet size in bytes */
68 unsigned int maxframesize; /* max packet size in frames */ 69 unsigned int maxframesize; /* max packet size in frames */
69 unsigned int curpacksize; /* current packet size in bytes (for capture) */ 70 unsigned int curpacksize; /* current packet size in bytes (for capture) */
70 unsigned int curframesize; /* current packet size in frames (for capture) */ 71 unsigned int curframesize; /* current packet size in frames (for capture) */
72 unsigned int syncmaxsize; /* sync endpoint packet size */
71 unsigned int fill_max: 1; /* fill max packet size always */ 73 unsigned int fill_max: 1; /* fill max packet size always */
72 unsigned int txfr_quirk:1; /* allow sub-frame alignment */ 74 unsigned int txfr_quirk:1; /* allow sub-frame alignment */
73 unsigned int fmt_type; /* USB audio format type (1-3) */ 75 unsigned int fmt_type; /* USB audio format type (1-3) */
diff --git a/sound/usb/clock.c b/sound/usb/clock.c
index 7754a1034545..075195e8661a 100644
--- a/sound/usb/clock.c
+++ b/sound/usb/clock.c
@@ -104,6 +104,15 @@ static bool uac_clock_source_is_valid(struct snd_usb_audio *chip, int source_id)
104 int err; 104 int err;
105 unsigned char data; 105 unsigned char data;
106 struct usb_device *dev = chip->dev; 106 struct usb_device *dev = chip->dev;
107 struct uac_clock_source_descriptor *cs_desc =
108 snd_usb_find_clock_source(chip->ctrl_intf, source_id);
109
110 if (!cs_desc)
111 return 0;
112
113 /* If a clock source can't tell us whether it's valid, we assume it is */
114 if (!uac2_control_is_readable(cs_desc->bmControls, UAC2_CS_CONTROL_CLOCK_VALID))
115 return 1;
107 116
108 err = snd_usb_ctl_msg(dev, usb_rcvctrlpipe(dev, 0), UAC2_CS_CUR, 117 err = snd_usb_ctl_msg(dev, usb_rcvctrlpipe(dev, 0), UAC2_CS_CUR,
109 USB_TYPE_CLASS | USB_RECIP_INTERFACE | USB_DIR_IN, 118 USB_TYPE_CLASS | USB_RECIP_INTERFACE | USB_DIR_IN,
@@ -114,7 +123,7 @@ static bool uac_clock_source_is_valid(struct snd_usb_audio *chip, int source_id)
114 if (err < 0) { 123 if (err < 0) {
115 snd_printk(KERN_WARNING "%s(): cannot get clock validity for id %d\n", 124 snd_printk(KERN_WARNING "%s(): cannot get clock validity for id %d\n",
116 __func__, source_id); 125 __func__, source_id);
117 return err; 126 return 0;
118 } 127 }
119 128
120 return !!data; 129 return !!data;
diff --git a/sound/usb/debug.h b/sound/usb/debug.h
index 343ec2d9ee66..58030176f008 100644
--- a/sound/usb/debug.h
+++ b/sound/usb/debug.h
@@ -8,7 +8,7 @@
8#ifdef HW_CONST_DEBUG 8#ifdef HW_CONST_DEBUG
9#define hwc_debug(fmt, args...) printk(KERN_DEBUG fmt, ##args) 9#define hwc_debug(fmt, args...) printk(KERN_DEBUG fmt, ##args)
10#else 10#else
11#define hwc_debug(fmt, args...) /**/ 11#define hwc_debug(fmt, args...) do { } while(0)
12#endif 12#endif
13 13
14#endif /* __USBAUDIO_DEBUG_H */ 14#endif /* __USBAUDIO_DEBUG_H */
diff --git a/sound/usb/endpoint.c b/sound/usb/endpoint.c
index ef0a07e34844..b0ef9f501896 100644
--- a/sound/usb/endpoint.c
+++ b/sound/usb/endpoint.c
@@ -405,8 +405,6 @@ int snd_usb_parse_audio_endpoints(struct snd_usb_audio *chip, int iface_no)
405 break; 405 break;
406 case USB_ID(0x041e, 0x3020): /* Creative SB Audigy 2 NX */ 406 case USB_ID(0x041e, 0x3020): /* Creative SB Audigy 2 NX */
407 case USB_ID(0x0763, 0x2003): /* M-Audio Audiophile USB */ 407 case USB_ID(0x0763, 0x2003): /* M-Audio Audiophile USB */
408 case USB_ID(0x0763, 0x2080): /* M-Audio Fast Track Ultra 8 */
409 case USB_ID(0x0763, 0x2081): /* M-Audio Fast Track Ultra 8R */
410 /* doesn't set the sample rate attribute, but supports it */ 408 /* doesn't set the sample rate attribute, but supports it */
411 fp->attributes |= UAC_EP_CS_ATTR_SAMPLE_RATE; 409 fp->attributes |= UAC_EP_CS_ATTR_SAMPLE_RATE;
412 break; 410 break;
diff --git a/sound/usb/format.c b/sound/usb/format.c
index 69148212aa70..8d042dce0d16 100644
--- a/sound/usb/format.c
+++ b/sound/usb/format.c
@@ -30,6 +30,7 @@
30#include "helper.h" 30#include "helper.h"
31#include "debug.h" 31#include "debug.h"
32#include "clock.h" 32#include "clock.h"
33#include "format.h"
33 34
34/* 35/*
35 * parse the audio format type I descriptor 36 * parse the audio format type I descriptor
@@ -76,7 +77,10 @@ static u64 parse_audio_format_i_type(struct snd_usb_audio *chip,
76 format = 1 << UAC_FORMAT_TYPE_I_PCM; 77 format = 1 << UAC_FORMAT_TYPE_I_PCM;
77 } 78 }
78 if (format & (1 << UAC_FORMAT_TYPE_I_PCM)) { 79 if (format & (1 << UAC_FORMAT_TYPE_I_PCM)) {
79 if (sample_width > sample_bytes * 8) { 80 if (chip->usb_id == USB_ID(0x0582, 0x0016) /* Edirol SD-90 */ &&
81 sample_width == 24 && sample_bytes == 2)
82 sample_bytes = 3;
83 else if (sample_width > sample_bytes * 8) {
80 snd_printk(KERN_INFO "%d:%u:%d : sample bitwidth %d in over sample bytes %d\n", 84 snd_printk(KERN_INFO "%d:%u:%d : sample bitwidth %d in over sample bytes %d\n",
81 chip->dev->devnum, fp->iface, fp->altsetting, 85 chip->dev->devnum, fp->iface, fp->altsetting,
82 sample_width, sample_bytes); 86 sample_width, sample_bytes);
@@ -173,9 +177,11 @@ static int parse_audio_format_rates_v1(struct snd_usb_audio *chip, struct audiof
173 if (!rate) 177 if (!rate)
174 continue; 178 continue;
175 /* C-Media CM6501 mislabels its 96 kHz altsetting */ 179 /* C-Media CM6501 mislabels its 96 kHz altsetting */
180 /* Terratec Aureon 7.1 USB C-Media 6206, too */
176 if (rate == 48000 && nr_rates == 1 && 181 if (rate == 48000 && nr_rates == 1 &&
177 (chip->usb_id == USB_ID(0x0d8c, 0x0201) || 182 (chip->usb_id == USB_ID(0x0d8c, 0x0201) ||
178 chip->usb_id == USB_ID(0x0d8c, 0x0102)) && 183 chip->usb_id == USB_ID(0x0d8c, 0x0102) ||
184 chip->usb_id == USB_ID(0x0ccd, 0x00b1)) &&
179 fp->altsetting == 5 && fp->maxpacksize == 392) 185 fp->altsetting == 5 && fp->maxpacksize == 392)
180 rate = 96000; 186 rate = 96000;
181 /* Creative VF0470 Live Cam reports 16 kHz instead of 8kHz */ 187 /* Creative VF0470 Live Cam reports 16 kHz instead of 8kHz */
diff --git a/sound/usb/helper.c b/sound/usb/helper.c
index d48d6f8f6ac9..f280c1903c25 100644
--- a/sound/usb/helper.c
+++ b/sound/usb/helper.c
@@ -103,11 +103,16 @@ int snd_usb_ctl_msg(struct usb_device *dev, unsigned int pipe, __u8 request,
103unsigned char snd_usb_parse_datainterval(struct snd_usb_audio *chip, 103unsigned char snd_usb_parse_datainterval(struct snd_usb_audio *chip,
104 struct usb_host_interface *alts) 104 struct usb_host_interface *alts)
105{ 105{
106 if (snd_usb_get_speed(chip->dev) == USB_SPEED_HIGH && 106 switch (snd_usb_get_speed(chip->dev)) {
107 get_endpoint(alts, 0)->bInterval >= 1 && 107 case USB_SPEED_HIGH:
108 get_endpoint(alts, 0)->bInterval <= 4) 108 case USB_SPEED_SUPER:
109 return get_endpoint(alts, 0)->bInterval - 1; 109 if (get_endpoint(alts, 0)->bInterval >= 1 &&
110 else 110 get_endpoint(alts, 0)->bInterval <= 4)
111 return 0; 111 return get_endpoint(alts, 0)->bInterval - 1;
112 break;
113 default:
114 break;
115 }
116 return 0;
112} 117}
113 118
diff --git a/sound/usb/midi.c b/sound/usb/midi.c
index b9c2bc65f51a..f9289102886a 100644
--- a/sound/usb/midi.c
+++ b/sound/usb/midi.c
@@ -54,6 +54,7 @@
54#include <sound/asequencer.h> 54#include <sound/asequencer.h>
55#include "usbaudio.h" 55#include "usbaudio.h"
56#include "midi.h" 56#include "midi.h"
57#include "power.h"
57#include "helper.h" 58#include "helper.h"
58 59
59/* 60/*
@@ -784,7 +785,7 @@ static struct usb_protocol_ops snd_usbmidi_novation_ops = {
784}; 785};
785 786
786/* 787/*
787 * "raw" protocol: used by the MOTU FastLane. 788 * "raw" protocol: just move raw MIDI bytes from/to the endpoint
788 */ 789 */
789 790
790static void snd_usbmidi_raw_input(struct snd_usb_midi_in_endpoint* ep, 791static void snd_usbmidi_raw_input(struct snd_usb_midi_in_endpoint* ep,
@@ -834,7 +835,14 @@ static void snd_usbmidi_us122l_output(struct snd_usb_midi_out_endpoint *ep,
834 835
835 if (!ep->ports[0].active) 836 if (!ep->ports[0].active)
836 return; 837 return;
837 count = snd_usb_get_speed(ep->umidi->dev) == USB_SPEED_HIGH ? 1 : 2; 838 switch (snd_usb_get_speed(ep->umidi->dev)) {
839 case USB_SPEED_HIGH:
840 case USB_SPEED_SUPER:
841 count = 1;
842 break;
843 default:
844 count = 2;
845 }
838 count = snd_rawmidi_transmit(ep->ports[0].substream, 846 count = snd_rawmidi_transmit(ep->ports[0].substream,
839 urb->transfer_buffer, 847 urb->transfer_buffer,
840 count); 848 count);
@@ -843,8 +851,8 @@ static void snd_usbmidi_us122l_output(struct snd_usb_midi_out_endpoint *ep,
843 return; 851 return;
844 } 852 }
845 853
846 memset(urb->transfer_buffer + count, 0xFD, 9 - count); 854 memset(urb->transfer_buffer + count, 0xFD, ep->max_transfer - count);
847 urb->transfer_buffer_length = count; 855 urb->transfer_buffer_length = ep->max_transfer;
848} 856}
849 857
850static struct usb_protocol_ops snd_usbmidi_122l_ops = { 858static struct usb_protocol_ops snd_usbmidi_122l_ops = {
@@ -1037,6 +1045,7 @@ static int snd_usbmidi_output_open(struct snd_rawmidi_substream *substream)
1037 struct snd_usb_midi* umidi = substream->rmidi->private_data; 1045 struct snd_usb_midi* umidi = substream->rmidi->private_data;
1038 struct usbmidi_out_port* port = NULL; 1046 struct usbmidi_out_port* port = NULL;
1039 int i, j; 1047 int i, j;
1048 int err;
1040 1049
1041 for (i = 0; i < MIDI_MAX_ENDPOINTS; ++i) 1050 for (i = 0; i < MIDI_MAX_ENDPOINTS; ++i)
1042 if (umidi->endpoints[i].out) 1051 if (umidi->endpoints[i].out)
@@ -1049,6 +1058,9 @@ static int snd_usbmidi_output_open(struct snd_rawmidi_substream *substream)
1049 snd_BUG(); 1058 snd_BUG();
1050 return -ENXIO; 1059 return -ENXIO;
1051 } 1060 }
1061 err = usb_autopm_get_interface(umidi->iface);
1062 if (err < 0)
1063 return -EIO;
1052 substream->runtime->private_data = port; 1064 substream->runtime->private_data = port;
1053 port->state = STATE_UNKNOWN; 1065 port->state = STATE_UNKNOWN;
1054 substream_open(substream, 1); 1066 substream_open(substream, 1);
@@ -1057,7 +1069,10 @@ static int snd_usbmidi_output_open(struct snd_rawmidi_substream *substream)
1057 1069
1058static int snd_usbmidi_output_close(struct snd_rawmidi_substream *substream) 1070static int snd_usbmidi_output_close(struct snd_rawmidi_substream *substream)
1059{ 1071{
1072 struct snd_usb_midi* umidi = substream->rmidi->private_data;
1073
1060 substream_open(substream, 0); 1074 substream_open(substream, 0);
1075 usb_autopm_put_interface(umidi->iface);
1061 return 0; 1076 return 0;
1062} 1077}
1063 1078
@@ -1286,8 +1301,16 @@ static int snd_usbmidi_out_endpoint_create(struct snd_usb_midi* umidi,
1286 case USB_ID(0x15ca, 0x0101): /* Textech USB Midi Cable */ 1301 case USB_ID(0x15ca, 0x0101): /* Textech USB Midi Cable */
1287 case USB_ID(0x15ca, 0x1806): /* Textech USB Midi Cable */ 1302 case USB_ID(0x15ca, 0x1806): /* Textech USB Midi Cable */
1288 case USB_ID(0x1a86, 0x752d): /* QinHeng CH345 "USB2.0-MIDI" */ 1303 case USB_ID(0x1a86, 0x752d): /* QinHeng CH345 "USB2.0-MIDI" */
1304 case USB_ID(0xfc08, 0x0101): /* Unknown vendor Cable */
1289 ep->max_transfer = 4; 1305 ep->max_transfer = 4;
1290 break; 1306 break;
1307 /*
1308 * Some devices only work with 9 bytes packet size:
1309 */
1310 case USB_ID(0x0644, 0x800E): /* Tascam US-122L */
1311 case USB_ID(0x0644, 0x800F): /* Tascam US-144 */
1312 ep->max_transfer = 9;
1313 break;
1291 } 1314 }
1292 for (i = 0; i < OUTPUT_URBS; ++i) { 1315 for (i = 0; i < OUTPUT_URBS; ++i) {
1293 buffer = usb_alloc_coherent(umidi->dev, 1316 buffer = usb_alloc_coherent(umidi->dev,
@@ -1722,13 +1745,7 @@ static int roland_load_info(struct snd_kcontrol *kcontrol,
1722{ 1745{
1723 static const char *const names[] = { "High Load", "Light Load" }; 1746 static const char *const names[] = { "High Load", "Light Load" };
1724 1747
1725 info->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED; 1748 return snd_ctl_enum_info(info, 1, 2, names);
1726 info->count = 1;
1727 info->value.enumerated.items = 2;
1728 if (info->value.enumerated.item > 1)
1729 info->value.enumerated.item = 1;
1730 strcpy(info->value.enumerated.name, names[info->value.enumerated.item]);
1731 return 0;
1732} 1749}
1733 1750
1734static int roland_load_get(struct snd_kcontrol *kcontrol, 1751static int roland_load_get(struct snd_kcontrol *kcontrol,
@@ -2115,7 +2132,7 @@ int snd_usbmidi_create(struct snd_card *card,
2115 umidi->usb_protocol_ops = &snd_usbmidi_novation_ops; 2132 umidi->usb_protocol_ops = &snd_usbmidi_novation_ops;
2116 err = snd_usbmidi_detect_per_port_endpoints(umidi, endpoints); 2133 err = snd_usbmidi_detect_per_port_endpoints(umidi, endpoints);
2117 break; 2134 break;
2118 case QUIRK_MIDI_FASTLANE: 2135 case QUIRK_MIDI_RAW_BYTES:
2119 umidi->usb_protocol_ops = &snd_usbmidi_raw_ops; 2136 umidi->usb_protocol_ops = &snd_usbmidi_raw_ops;
2120 /* 2137 /*
2121 * Interface 1 contains isochronous endpoints, but with the same 2138 * Interface 1 contains isochronous endpoints, but with the same
@@ -2126,7 +2143,8 @@ int snd_usbmidi_create(struct snd_card *card,
2126 * interface 0, so we have to make sure that the USB core looks 2143 * interface 0, so we have to make sure that the USB core looks
2127 * again at interface 0 by calling usb_set_interface() on it. 2144 * again at interface 0 by calling usb_set_interface() on it.
2128 */ 2145 */
2129 usb_set_interface(umidi->dev, 0, 0); 2146 if (umidi->usb_id == USB_ID(0x07fd, 0x0001)) /* MOTU Fastlane */
2147 usb_set_interface(umidi->dev, 0, 0);
2130 err = snd_usbmidi_detect_per_port_endpoints(umidi, endpoints); 2148 err = snd_usbmidi_detect_per_port_endpoints(umidi, endpoints);
2131 break; 2149 break;
2132 case QUIRK_MIDI_EMAGIC: 2150 case QUIRK_MIDI_EMAGIC:
diff --git a/sound/usb/mixer.c b/sound/usb/mixer.c
index 3ed3901369ce..c22fa76e363a 100644
--- a/sound/usb/mixer.c
+++ b/sound/usb/mixer.c
@@ -61,6 +61,7 @@
61#include "mixer.h" 61#include "mixer.h"
62#include "helper.h" 62#include "helper.h"
63#include "mixer_quirks.h" 63#include "mixer_quirks.h"
64#include "power.h"
64 65
65#define MAX_ID_ELEMS 256 66#define MAX_ID_ELEMS 256
66 67
@@ -85,17 +86,7 @@ struct mixer_build {
85 const struct usbmix_selector_map *selector_map; 86 const struct usbmix_selector_map *selector_map;
86}; 87};
87 88
88enum { 89/*E-mu 0202/0404/0204 eXtension Unit(XU) control*/
89 USB_MIXER_BOOLEAN,
90 USB_MIXER_INV_BOOLEAN,
91 USB_MIXER_S8,
92 USB_MIXER_U8,
93 USB_MIXER_S16,
94 USB_MIXER_U16,
95};
96
97
98/*E-mu 0202(0404) eXtension Unit(XU) control*/
99enum { 90enum {
100 USB_XU_CLOCK_RATE = 0xe301, 91 USB_XU_CLOCK_RATE = 0xe301,
101 USB_XU_CLOCK_SOURCE = 0xe302, 92 USB_XU_CLOCK_SOURCE = 0xe302,
@@ -295,16 +286,22 @@ static int get_ctl_value_v1(struct usb_mixer_elem_info *cval, int request, int v
295 unsigned char buf[2]; 286 unsigned char buf[2];
296 int val_len = cval->val_type >= USB_MIXER_S16 ? 2 : 1; 287 int val_len = cval->val_type >= USB_MIXER_S16 ? 2 : 1;
297 int timeout = 10; 288 int timeout = 10;
289 int err;
298 290
291 err = snd_usb_autoresume(cval->mixer->chip);
292 if (err < 0)
293 return -EIO;
299 while (timeout-- > 0) { 294 while (timeout-- > 0) {
300 if (snd_usb_ctl_msg(chip->dev, usb_rcvctrlpipe(chip->dev, 0), request, 295 if (snd_usb_ctl_msg(chip->dev, usb_rcvctrlpipe(chip->dev, 0), request,
301 USB_RECIP_INTERFACE | USB_TYPE_CLASS | USB_DIR_IN, 296 USB_RECIP_INTERFACE | USB_TYPE_CLASS | USB_DIR_IN,
302 validx, snd_usb_ctrl_intf(chip) | (cval->id << 8), 297 validx, snd_usb_ctrl_intf(chip) | (cval->id << 8),
303 buf, val_len, 100) >= val_len) { 298 buf, val_len, 100) >= val_len) {
304 *value_ret = convert_signed_value(cval, snd_usb_combine_bytes(buf, val_len)); 299 *value_ret = convert_signed_value(cval, snd_usb_combine_bytes(buf, val_len));
300 snd_usb_autosuspend(cval->mixer->chip);
305 return 0; 301 return 0;
306 } 302 }
307 } 303 }
304 snd_usb_autosuspend(cval->mixer->chip);
308 snd_printdd(KERN_ERR "cannot get ctl value: req = %#x, wValue = %#x, wIndex = %#x, type = %d\n", 305 snd_printdd(KERN_ERR "cannot get ctl value: req = %#x, wValue = %#x, wIndex = %#x, type = %d\n",
309 request, validx, snd_usb_ctrl_intf(chip) | (cval->id << 8), cval->val_type); 306 request, validx, snd_usb_ctrl_intf(chip) | (cval->id << 8), cval->val_type);
310 return -EINVAL; 307 return -EINVAL;
@@ -328,12 +325,18 @@ static int get_ctl_value_v2(struct usb_mixer_elem_info *cval, int request, int v
328 325
329 memset(buf, 0, sizeof(buf)); 326 memset(buf, 0, sizeof(buf));
330 327
328 ret = snd_usb_autoresume(chip) ? -EIO : 0;
329 if (ret)
330 goto error;
331
331 ret = snd_usb_ctl_msg(chip->dev, usb_rcvctrlpipe(chip->dev, 0), bRequest, 332 ret = snd_usb_ctl_msg(chip->dev, usb_rcvctrlpipe(chip->dev, 0), bRequest,
332 USB_RECIP_INTERFACE | USB_TYPE_CLASS | USB_DIR_IN, 333 USB_RECIP_INTERFACE | USB_TYPE_CLASS | USB_DIR_IN,
333 validx, snd_usb_ctrl_intf(chip) | (cval->id << 8), 334 validx, snd_usb_ctrl_intf(chip) | (cval->id << 8),
334 buf, size, 1000); 335 buf, size, 1000);
336 snd_usb_autosuspend(chip);
335 337
336 if (ret < 0) { 338 if (ret < 0) {
339error:
337 snd_printk(KERN_ERR "cannot get ctl value: req = %#x, wValue = %#x, wIndex = %#x, type = %d\n", 340 snd_printk(KERN_ERR "cannot get ctl value: req = %#x, wValue = %#x, wIndex = %#x, type = %d\n",
338 request, validx, snd_usb_ctrl_intf(chip) | (cval->id << 8), cval->val_type); 341 request, validx, snd_usb_ctrl_intf(chip) | (cval->id << 8), cval->val_type);
339 return ret; 342 return ret;
@@ -413,7 +416,7 @@ int snd_usb_mixer_set_ctl_value(struct usb_mixer_elem_info *cval,
413{ 416{
414 struct snd_usb_audio *chip = cval->mixer->chip; 417 struct snd_usb_audio *chip = cval->mixer->chip;
415 unsigned char buf[2]; 418 unsigned char buf[2];
416 int val_len, timeout = 10; 419 int val_len, err, timeout = 10;
417 420
418 if (cval->mixer->protocol == UAC_VERSION_1) { 421 if (cval->mixer->protocol == UAC_VERSION_1) {
419 val_len = cval->val_type >= USB_MIXER_S16 ? 2 : 1; 422 val_len = cval->val_type >= USB_MIXER_S16 ? 2 : 1;
@@ -433,13 +436,19 @@ int snd_usb_mixer_set_ctl_value(struct usb_mixer_elem_info *cval,
433 value_set = convert_bytes_value(cval, value_set); 436 value_set = convert_bytes_value(cval, value_set);
434 buf[0] = value_set & 0xff; 437 buf[0] = value_set & 0xff;
435 buf[1] = (value_set >> 8) & 0xff; 438 buf[1] = (value_set >> 8) & 0xff;
439 err = snd_usb_autoresume(chip);
440 if (err < 0)
441 return -EIO;
436 while (timeout-- > 0) 442 while (timeout-- > 0)
437 if (snd_usb_ctl_msg(chip->dev, 443 if (snd_usb_ctl_msg(chip->dev,
438 usb_sndctrlpipe(chip->dev, 0), request, 444 usb_sndctrlpipe(chip->dev, 0), request,
439 USB_RECIP_INTERFACE | USB_TYPE_CLASS | USB_DIR_OUT, 445 USB_RECIP_INTERFACE | USB_TYPE_CLASS | USB_DIR_OUT,
440 validx, snd_usb_ctrl_intf(chip) | (cval->id << 8), 446 validx, snd_usb_ctrl_intf(chip) | (cval->id << 8),
441 buf, val_len, 100) >= 0) 447 buf, val_len, 100) >= 0) {
448 snd_usb_autosuspend(chip);
442 return 0; 449 return 0;
450 }
451 snd_usb_autosuspend(chip);
443 snd_printdd(KERN_ERR "cannot set ctl value: req = %#x, wValue = %#x, wIndex = %#x, type = %d, data = %#x/%#x\n", 452 snd_printdd(KERN_ERR "cannot set ctl value: req = %#x, wValue = %#x, wIndex = %#x, type = %d, data = %#x/%#x\n",
444 request, validx, snd_usb_ctrl_intf(chip) | (cval->id << 8), cval->val_type, buf[0], buf[1]); 453 request, validx, snd_usb_ctrl_intf(chip) | (cval->id << 8), cval->val_type, buf[0], buf[1]);
445 return -EINVAL; 454 return -EINVAL;
@@ -516,20 +525,21 @@ static int check_matrix_bitmap(unsigned char *bmap, int ich, int och, int num_ou
516 * if failed, give up and free the control instance. 525 * if failed, give up and free the control instance.
517 */ 526 */
518 527
519static int add_control_to_empty(struct mixer_build *state, struct snd_kcontrol *kctl) 528int snd_usb_mixer_add_control(struct usb_mixer_interface *mixer,
529 struct snd_kcontrol *kctl)
520{ 530{
521 struct usb_mixer_elem_info *cval = kctl->private_data; 531 struct usb_mixer_elem_info *cval = kctl->private_data;
522 int err; 532 int err;
523 533
524 while (snd_ctl_find_id(state->chip->card, &kctl->id)) 534 while (snd_ctl_find_id(mixer->chip->card, &kctl->id))
525 kctl->id.index++; 535 kctl->id.index++;
526 if ((err = snd_ctl_add(state->chip->card, kctl)) < 0) { 536 if ((err = snd_ctl_add(mixer->chip->card, kctl)) < 0) {
527 snd_printd(KERN_ERR "cannot add control (err = %d)\n", err); 537 snd_printd(KERN_ERR "cannot add control (err = %d)\n", err);
528 return err; 538 return err;
529 } 539 }
530 cval->elem_id = &kctl->id; 540 cval->elem_id = &kctl->id;
531 cval->next_id_elem = state->mixer->id_elems[cval->id]; 541 cval->next_id_elem = mixer->id_elems[cval->id];
532 state->mixer->id_elems[cval->id] = cval; 542 mixer->id_elems[cval->id] = cval;
533 return 0; 543 return 0;
534} 544}
535 545
@@ -759,8 +769,6 @@ static void usb_mixer_elem_free(struct snd_kcontrol *kctl)
759 */ 769 */
760static int get_min_max(struct usb_mixer_elem_info *cval, int default_min) 770static int get_min_max(struct usb_mixer_elem_info *cval, int default_min)
761{ 771{
762 struct snd_usb_audio *chip = cval->mixer->chip;
763
764 /* for failsafe */ 772 /* for failsafe */
765 cval->min = default_min; 773 cval->min = default_min;
766 cval->max = cval->min + 1; 774 cval->max = cval->min + 1;
@@ -783,7 +791,7 @@ static int get_min_max(struct usb_mixer_elem_info *cval, int default_min)
783 if (get_ctl_value(cval, UAC_GET_MAX, (cval->control << 8) | minchn, &cval->max) < 0 || 791 if (get_ctl_value(cval, UAC_GET_MAX, (cval->control << 8) | minchn, &cval->max) < 0 ||
784 get_ctl_value(cval, UAC_GET_MIN, (cval->control << 8) | minchn, &cval->min) < 0) { 792 get_ctl_value(cval, UAC_GET_MIN, (cval->control << 8) | minchn, &cval->min) < 0) {
785 snd_printd(KERN_ERR "%d:%d: cannot get min/max values for control %d (id %d)\n", 793 snd_printd(KERN_ERR "%d:%d: cannot get min/max values for control %d (id %d)\n",
786 cval->id, snd_usb_ctrl_intf(chip), cval->control, cval->id); 794 cval->id, snd_usb_ctrl_intf(cval->mixer->chip), cval->control, cval->id);
787 return -EINVAL; 795 return -EINVAL;
788 } 796 }
789 if (get_ctl_value(cval, UAC_GET_RES, (cval->control << 8) | minchn, &cval->res) < 0) { 797 if (get_ctl_value(cval, UAC_GET_RES, (cval->control << 8) | minchn, &cval->res) < 0) {
@@ -967,6 +975,9 @@ static struct snd_kcontrol_new usb_feature_unit_ctl_ro = {
967 .put = NULL, 975 .put = NULL,
968}; 976};
969 977
978/* This symbol is exported in order to allow the mixer quirks to
979 * hook up to the standard feature unit control mechanism */
980struct snd_kcontrol_new *snd_usb_feature_unit_ctl = &usb_feature_unit_ctl;
970 981
971/* 982/*
972 * build a feature control 983 * build a feature control
@@ -989,6 +1000,7 @@ static void build_feature_ctl(struct mixer_build *state, void *raw_desc,
989 struct snd_kcontrol *kctl; 1000 struct snd_kcontrol *kctl;
990 struct usb_mixer_elem_info *cval; 1001 struct usb_mixer_elem_info *cval;
991 const struct usbmix_name_map *map; 1002 const struct usbmix_name_map *map;
1003 unsigned int range;
992 1004
993 control++; /* change from zero-based to 1-based value */ 1005 control++; /* change from zero-based to 1-based value */
994 1006
@@ -1079,11 +1091,13 @@ static void build_feature_ctl(struct mixer_build *state, void *raw_desc,
1079 append_ctl_name(kctl, control == UAC_FU_MUTE ? 1091 append_ctl_name(kctl, control == UAC_FU_MUTE ?
1080 " Switch" : " Volume"); 1092 " Switch" : " Volume");
1081 if (control == UAC_FU_VOLUME) { 1093 if (control == UAC_FU_VOLUME) {
1082 kctl->tlv.c = mixer_vol_tlv;
1083 kctl->vd[0].access |=
1084 SNDRV_CTL_ELEM_ACCESS_TLV_READ |
1085 SNDRV_CTL_ELEM_ACCESS_TLV_CALLBACK;
1086 check_mapped_dB(map, cval); 1094 check_mapped_dB(map, cval);
1095 if (cval->dBmin < cval->dBmax) {
1096 kctl->tlv.c = mixer_vol_tlv;
1097 kctl->vd[0].access |=
1098 SNDRV_CTL_ELEM_ACCESS_TLV_READ |
1099 SNDRV_CTL_ELEM_ACCESS_TLV_CALLBACK;
1100 }
1087 } 1101 }
1088 break; 1102 break;
1089 1103
@@ -1123,6 +1137,7 @@ static void build_feature_ctl(struct mixer_build *state, void *raw_desc,
1123 } 1137 }
1124 break; 1138 break;
1125 1139
1140 case USB_ID(0x046d, 0x0808):
1126 case USB_ID(0x046d, 0x0809): 1141 case USB_ID(0x046d, 0x0809):
1127 case USB_ID(0x046d, 0x0991): 1142 case USB_ID(0x046d, 0x0991):
1128 /* Most audio usb devices lie about volume resolution. 1143 /* Most audio usb devices lie about volume resolution.
@@ -1138,9 +1153,24 @@ static void build_feature_ctl(struct mixer_build *state, void *raw_desc,
1138 1153
1139 } 1154 }
1140 1155
1156 range = (cval->max - cval->min) / cval->res;
1157 /* Are there devices with volume range more than 255? I use a bit more
1158 * to be sure. 384 is a resolution magic number found on Logitech
1159 * devices. It will definitively catch all buggy Logitech devices.
1160 */
1161 if (range > 384) {
1162 snd_printk(KERN_WARNING "usb_audio: Warning! Unlikely big "
1163 "volume range (=%u), cval->res is probably wrong.",
1164 range);
1165 snd_printk(KERN_WARNING "usb_audio: [%d] FU [%s] ch = %d, "
1166 "val = %d/%d/%d", cval->id,
1167 kctl->id.name, cval->channels,
1168 cval->min, cval->max, cval->res);
1169 }
1170
1141 snd_printdd(KERN_INFO "[%d] FU [%s] ch = %d, val = %d/%d/%d\n", 1171 snd_printdd(KERN_INFO "[%d] FU [%s] ch = %d, val = %d/%d/%d\n",
1142 cval->id, kctl->id.name, cval->channels, cval->min, cval->max, cval->res); 1172 cval->id, kctl->id.name, cval->channels, cval->min, cval->max, cval->res);
1143 add_control_to_empty(state, kctl); 1173 snd_usb_mixer_add_control(state->mixer, kctl);
1144} 1174}
1145 1175
1146 1176
@@ -1148,7 +1178,7 @@ static void build_feature_ctl(struct mixer_build *state, void *raw_desc,
1148/* 1178/*
1149 * parse a feature unit 1179 * parse a feature unit
1150 * 1180 *
1151 * most of controlls are defined here. 1181 * most of controls are defined here.
1152 */ 1182 */
1153static int parse_audio_feature_unit(struct mixer_build *state, int unitid, void *_ftr) 1183static int parse_audio_feature_unit(struct mixer_build *state, int unitid, void *_ftr)
1154{ 1184{
@@ -1304,7 +1334,7 @@ static void build_mixer_unit_ctl(struct mixer_build *state,
1304 1334
1305 snd_printdd(KERN_INFO "[%d] MU [%s] ch = %d, val = %d/%d\n", 1335 snd_printdd(KERN_INFO "[%d] MU [%s] ch = %d, val = %d/%d\n",
1306 cval->id, kctl->id.name, cval->channels, cval->min, cval->max); 1336 cval->id, kctl->id.name, cval->channels, cval->min, cval->max);
1307 add_control_to_empty(state, kctl); 1337 snd_usb_mixer_add_control(state->mixer, kctl);
1308} 1338}
1309 1339
1310 1340
@@ -1568,7 +1598,7 @@ static int build_audio_procunit(struct mixer_build *state, int unitid, void *raw
1568 cval->initialized = 1; 1598 cval->initialized = 1;
1569 } else { 1599 } else {
1570 if (type == USB_XU_CLOCK_RATE) { 1600 if (type == USB_XU_CLOCK_RATE) {
1571 /* E-Mu USB 0404/0202/TrackerPre 1601 /* E-Mu USB 0404/0202/TrackerPre/0204
1572 * samplerate control quirk 1602 * samplerate control quirk
1573 */ 1603 */
1574 cval->min = 0; 1604 cval->min = 0;
@@ -1605,7 +1635,7 @@ static int build_audio_procunit(struct mixer_build *state, int unitid, void *raw
1605 1635
1606 snd_printdd(KERN_INFO "[%d] PU [%s] ch = %d, val = %d/%d\n", 1636 snd_printdd(KERN_INFO "[%d] PU [%s] ch = %d, val = %d/%d\n",
1607 cval->id, kctl->id.name, cval->channels, cval->min, cval->max); 1637 cval->id, kctl->id.name, cval->channels, cval->min, cval->max);
1608 if ((err = add_control_to_empty(state, kctl)) < 0) 1638 if ((err = snd_usb_mixer_add_control(state->mixer, kctl)) < 0)
1609 return err; 1639 return err;
1610 } 1640 }
1611 return 0; 1641 return 0;
@@ -1635,17 +1665,11 @@ static int parse_audio_extension_unit(struct mixer_build *state, int unitid, voi
1635static int mixer_ctl_selector_info(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_info *uinfo) 1665static int mixer_ctl_selector_info(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_info *uinfo)
1636{ 1666{
1637 struct usb_mixer_elem_info *cval = kcontrol->private_data; 1667 struct usb_mixer_elem_info *cval = kcontrol->private_data;
1638 char **itemlist = (char **)kcontrol->private_value; 1668 const char **itemlist = (const char **)kcontrol->private_value;
1639 1669
1640 if (snd_BUG_ON(!itemlist)) 1670 if (snd_BUG_ON(!itemlist))
1641 return -EINVAL; 1671 return -EINVAL;
1642 uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED; 1672 return snd_ctl_enum_info(uinfo, 1, cval->max, itemlist);
1643 uinfo->count = 1;
1644 uinfo->value.enumerated.items = cval->max;
1645 if ((int)uinfo->value.enumerated.item >= cval->max)
1646 uinfo->value.enumerated.item = cval->max - 1;
1647 strcpy(uinfo->value.enumerated.name, itemlist[uinfo->value.enumerated.item]);
1648 return 0;
1649} 1673}
1650 1674
1651/* get callback for selector unit */ 1675/* get callback for selector unit */
@@ -1828,7 +1852,7 @@ static int parse_audio_selector_unit(struct mixer_build *state, int unitid, void
1828 1852
1829 snd_printdd(KERN_INFO "[%d] SU [%s] items = %d\n", 1853 snd_printdd(KERN_INFO "[%d] SU [%s] items = %d\n",
1830 cval->id, kctl->id.name, desc->bNrInPins); 1854 cval->id, kctl->id.name, desc->bNrInPins);
1831 if ((err = add_control_to_empty(state, kctl)) < 0) 1855 if ((err = snd_usb_mixer_add_control(state->mixer, kctl)) < 0)
1832 return err; 1856 return err;
1833 1857
1834 return 0; 1858 return 0;
@@ -2066,8 +2090,9 @@ static void snd_usb_mixer_interrupt(struct urb *urb)
2066{ 2090{
2067 struct usb_mixer_interface *mixer = urb->context; 2091 struct usb_mixer_interface *mixer = urb->context;
2068 int len = urb->actual_length; 2092 int len = urb->actual_length;
2093 int ustatus = urb->status;
2069 2094
2070 if (urb->status != 0) 2095 if (ustatus != 0)
2071 goto requeue; 2096 goto requeue;
2072 2097
2073 if (mixer->protocol == UAC_VERSION_1) { 2098 if (mixer->protocol == UAC_VERSION_1) {
@@ -2108,12 +2133,32 @@ static void snd_usb_mixer_interrupt(struct urb *urb)
2108 } 2133 }
2109 2134
2110requeue: 2135requeue:
2111 if (urb->status != -ENOENT && urb->status != -ECONNRESET) { 2136 if (ustatus != -ENOENT && ustatus != -ECONNRESET && ustatus != -ESHUTDOWN) {
2112 urb->dev = mixer->chip->dev; 2137 urb->dev = mixer->chip->dev;
2113 usb_submit_urb(urb, GFP_ATOMIC); 2138 usb_submit_urb(urb, GFP_ATOMIC);
2114 } 2139 }
2115} 2140}
2116 2141
2142/* stop any bus activity of a mixer */
2143void snd_usb_mixer_inactivate(struct usb_mixer_interface *mixer)
2144{
2145 usb_kill_urb(mixer->urb);
2146 usb_kill_urb(mixer->rc_urb);
2147}
2148
2149int snd_usb_mixer_activate(struct usb_mixer_interface *mixer)
2150{
2151 int err;
2152
2153 if (mixer->urb) {
2154 err = usb_submit_urb(mixer->urb, GFP_NOIO);
2155 if (err < 0)
2156 return err;
2157 }
2158
2159 return 0;
2160}
2161
2117/* create the handler for the optional status interrupt endpoint */ 2162/* create the handler for the optional status interrupt endpoint */
2118static int snd_usb_mixer_status_create(struct usb_mixer_interface *mixer) 2163static int snd_usb_mixer_status_create(struct usb_mixer_interface *mixer)
2119{ 2164{
diff --git a/sound/usb/mixer.h b/sound/usb/mixer.h
index 26c636c5c93a..ae1a14dcfe82 100644
--- a/sound/usb/mixer.h
+++ b/sound/usb/mixer.h
@@ -24,7 +24,16 @@ struct usb_mixer_interface {
24 u8 xonar_u1_status; 24 u8 xonar_u1_status;
25}; 25};
26 26
27#define MAX_CHANNELS 10 /* max logical channels */ 27#define MAX_CHANNELS 16 /* max logical channels */
28
29enum {
30 USB_MIXER_BOOLEAN,
31 USB_MIXER_INV_BOOLEAN,
32 USB_MIXER_S8,
33 USB_MIXER_U8,
34 USB_MIXER_S16,
35 USB_MIXER_U16,
36};
28 37
29struct usb_mixer_elem_info { 38struct usb_mixer_elem_info {
30 struct usb_mixer_interface *mixer; 39 struct usb_mixer_interface *mixer;
@@ -52,5 +61,10 @@ void snd_usb_mixer_notify_id(struct usb_mixer_interface *mixer, int unitid);
52 61
53int snd_usb_mixer_set_ctl_value(struct usb_mixer_elem_info *cval, 62int snd_usb_mixer_set_ctl_value(struct usb_mixer_elem_info *cval,
54 int request, int validx, int value_set); 63 int request, int validx, int value_set);
64void snd_usb_mixer_inactivate(struct usb_mixer_interface *mixer);
65int snd_usb_mixer_activate(struct usb_mixer_interface *mixer);
66
67int snd_usb_mixer_add_control(struct usb_mixer_interface *mixer,
68 struct snd_kcontrol *kctl);
55 69
56#endif /* __USBMIXER_H */ 70#endif /* __USBMIXER_H */
diff --git a/sound/usb/mixer_quirks.c b/sound/usb/mixer_quirks.c
index e7df1e5e3f2e..3d0f4873112b 100644
--- a/sound/usb/mixer_quirks.c
+++ b/sound/usb/mixer_quirks.c
@@ -40,6 +40,8 @@
40#include "mixer_quirks.h" 40#include "mixer_quirks.h"
41#include "helper.h" 41#include "helper.h"
42 42
43extern struct snd_kcontrol_new *snd_usb_feature_unit_ctl;
44
43/* 45/*
44 * Sound Blaster remote control configuration 46 * Sound Blaster remote control configuration
45 * 47 *
@@ -60,6 +62,8 @@ static const struct rc_config {
60 { USB_ID(0x041e, 0x3000), 0, 1, 2, 1, 18, 0x0013 }, /* Extigy */ 62 { USB_ID(0x041e, 0x3000), 0, 1, 2, 1, 18, 0x0013 }, /* Extigy */
61 { USB_ID(0x041e, 0x3020), 2, 1, 6, 6, 18, 0x0013 }, /* Audigy 2 NX */ 63 { USB_ID(0x041e, 0x3020), 2, 1, 6, 6, 18, 0x0013 }, /* Audigy 2 NX */
62 { USB_ID(0x041e, 0x3040), 2, 2, 6, 6, 2, 0x6e91 }, /* Live! 24-bit */ 64 { USB_ID(0x041e, 0x3040), 2, 2, 6, 6, 2, 0x6e91 }, /* Live! 24-bit */
65 { USB_ID(0x041e, 0x3042), 0, 1, 1, 1, 1, 0x000d }, /* Usb X-Fi S51 */
66 { USB_ID(0x041e, 0x30df), 0, 1, 1, 1, 1, 0x000d }, /* Usb X-Fi S51 Pro */
63 { USB_ID(0x041e, 0x3048), 2, 2, 6, 6, 2, 0x6e91 }, /* Toshiba SB0500 */ 67 { USB_ID(0x041e, 0x3048), 2, 2, 6, 6, 2, 0x6e91 }, /* Toshiba SB0500 */
64}; 68};
65 69
@@ -182,7 +186,19 @@ static int snd_audigy2nx_led_put(struct snd_kcontrol *kcontrol, struct snd_ctl_e
182 if (value > 1) 186 if (value > 1)
183 return -EINVAL; 187 return -EINVAL;
184 changed = value != mixer->audigy2nx_leds[index]; 188 changed = value != mixer->audigy2nx_leds[index];
185 err = snd_usb_ctl_msg(mixer->chip->dev, 189 if (mixer->chip->usb_id == USB_ID(0x041e, 0x3042))
190 err = snd_usb_ctl_msg(mixer->chip->dev,
191 usb_sndctrlpipe(mixer->chip->dev, 0), 0x24,
192 USB_DIR_OUT | USB_TYPE_VENDOR | USB_RECIP_OTHER,
193 !value, 0, NULL, 0, 100);
194 /* USB X-Fi S51 Pro */
195 if (mixer->chip->usb_id == USB_ID(0x041e, 0x30df))
196 err = snd_usb_ctl_msg(mixer->chip->dev,
197 usb_sndctrlpipe(mixer->chip->dev, 0), 0x24,
198 USB_DIR_OUT | USB_TYPE_VENDOR | USB_RECIP_OTHER,
199 !value, 0, NULL, 0, 100);
200 else
201 err = snd_usb_ctl_msg(mixer->chip->dev,
186 usb_sndctrlpipe(mixer->chip->dev, 0), 0x24, 202 usb_sndctrlpipe(mixer->chip->dev, 0), 0x24,
187 USB_DIR_OUT | USB_TYPE_VENDOR | USB_RECIP_OTHER, 203 USB_DIR_OUT | USB_TYPE_VENDOR | USB_RECIP_OTHER,
188 value, index + 2, NULL, 0, 100); 204 value, index + 2, NULL, 0, 100);
@@ -224,8 +240,16 @@ static int snd_audigy2nx_controls_create(struct usb_mixer_interface *mixer)
224 int i, err; 240 int i, err;
225 241
226 for (i = 0; i < ARRAY_SIZE(snd_audigy2nx_controls); ++i) { 242 for (i = 0; i < ARRAY_SIZE(snd_audigy2nx_controls); ++i) {
243 /* USB X-Fi S51 doesn't have a CMSS LED */
244 if ((mixer->chip->usb_id == USB_ID(0x041e, 0x3042)) && i == 0)
245 continue;
246 /* USB X-Fi S51 Pro doesn't have one either */
247 if ((mixer->chip->usb_id == USB_ID(0x041e, 0x30df)) && i == 0)
248 continue;
227 if (i > 1 && /* Live24ext has 2 LEDs only */ 249 if (i > 1 && /* Live24ext has 2 LEDs only */
228 (mixer->chip->usb_id == USB_ID(0x041e, 0x3040) || 250 (mixer->chip->usb_id == USB_ID(0x041e, 0x3040) ||
251 mixer->chip->usb_id == USB_ID(0x041e, 0x3042) ||
252 mixer->chip->usb_id == USB_ID(0x041e, 0x30df) ||
229 mixer->chip->usb_id == USB_ID(0x041e, 0x3048))) 253 mixer->chip->usb_id == USB_ID(0x041e, 0x3048)))
230 break; 254 break;
231 err = snd_ctl_add(mixer->chip->card, 255 err = snd_ctl_add(mixer->chip->card,
@@ -335,6 +359,204 @@ static int snd_xonar_u1_controls_create(struct usb_mixer_interface *mixer)
335 return 0; 359 return 0;
336} 360}
337 361
362/* Native Instruments device quirks */
363
364#define _MAKE_NI_CONTROL(bRequest,wIndex) ((bRequest) << 16 | (wIndex))
365
366static int snd_nativeinstruments_control_get(struct snd_kcontrol *kcontrol,
367 struct snd_ctl_elem_value *ucontrol)
368{
369 struct usb_mixer_interface *mixer = snd_kcontrol_chip(kcontrol);
370 struct usb_device *dev = mixer->chip->dev;
371 u8 bRequest = (kcontrol->private_value >> 16) & 0xff;
372 u16 wIndex = kcontrol->private_value & 0xffff;
373 u8 tmp;
374
375 int ret = usb_control_msg(dev, usb_rcvctrlpipe(dev, 0), bRequest,
376 USB_TYPE_VENDOR | USB_RECIP_DEVICE | USB_DIR_IN,
377 0, cpu_to_le16(wIndex),
378 &tmp, sizeof(tmp), 1000);
379
380 if (ret < 0) {
381 snd_printk(KERN_ERR
382 "unable to issue vendor read request (ret = %d)", ret);
383 return ret;
384 }
385
386 ucontrol->value.integer.value[0] = tmp;
387
388 return 0;
389}
390
391static int snd_nativeinstruments_control_put(struct snd_kcontrol *kcontrol,
392 struct snd_ctl_elem_value *ucontrol)
393{
394 struct usb_mixer_interface *mixer = snd_kcontrol_chip(kcontrol);
395 struct usb_device *dev = mixer->chip->dev;
396 u8 bRequest = (kcontrol->private_value >> 16) & 0xff;
397 u16 wIndex = kcontrol->private_value & 0xffff;
398 u16 wValue = ucontrol->value.integer.value[0];
399
400 int ret = usb_control_msg(dev, usb_sndctrlpipe(dev, 0), bRequest,
401 USB_TYPE_VENDOR | USB_RECIP_DEVICE | USB_DIR_OUT,
402 cpu_to_le16(wValue), cpu_to_le16(wIndex),
403 NULL, 0, 1000);
404
405 if (ret < 0) {
406 snd_printk(KERN_ERR
407 "unable to issue vendor write request (ret = %d)", ret);
408 return ret;
409 }
410
411 return 0;
412}
413
414static struct snd_kcontrol_new snd_nativeinstruments_ta6_mixers[] = {
415 {
416 .name = "Direct Thru Channel A",
417 .private_value = _MAKE_NI_CONTROL(0x01, 0x03),
418 },
419 {
420 .name = "Direct Thru Channel B",
421 .private_value = _MAKE_NI_CONTROL(0x01, 0x05),
422 },
423 {
424 .name = "Phono Input Channel A",
425 .private_value = _MAKE_NI_CONTROL(0x02, 0x03),
426 },
427 {
428 .name = "Phono Input Channel B",
429 .private_value = _MAKE_NI_CONTROL(0x02, 0x05),
430 },
431};
432
433static struct snd_kcontrol_new snd_nativeinstruments_ta10_mixers[] = {
434 {
435 .name = "Direct Thru Channel A",
436 .private_value = _MAKE_NI_CONTROL(0x01, 0x03),
437 },
438 {
439 .name = "Direct Thru Channel B",
440 .private_value = _MAKE_NI_CONTROL(0x01, 0x05),
441 },
442 {
443 .name = "Direct Thru Channel C",
444 .private_value = _MAKE_NI_CONTROL(0x01, 0x07),
445 },
446 {
447 .name = "Direct Thru Channel D",
448 .private_value = _MAKE_NI_CONTROL(0x01, 0x09),
449 },
450 {
451 .name = "Phono Input Channel A",
452 .private_value = _MAKE_NI_CONTROL(0x02, 0x03),
453 },
454 {
455 .name = "Phono Input Channel B",
456 .private_value = _MAKE_NI_CONTROL(0x02, 0x05),
457 },
458 {
459 .name = "Phono Input Channel C",
460 .private_value = _MAKE_NI_CONTROL(0x02, 0x07),
461 },
462 {
463 .name = "Phono Input Channel D",
464 .private_value = _MAKE_NI_CONTROL(0x02, 0x09),
465 },
466};
467
468static int snd_nativeinstruments_create_mixer(struct usb_mixer_interface *mixer,
469 const struct snd_kcontrol_new *kc,
470 unsigned int count)
471{
472 int i, err = 0;
473 struct snd_kcontrol_new template = {
474 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
475 .access = SNDRV_CTL_ELEM_ACCESS_READWRITE,
476 .get = snd_nativeinstruments_control_get,
477 .put = snd_nativeinstruments_control_put,
478 .info = snd_ctl_boolean_mono_info,
479 };
480
481 for (i = 0; i < count; i++) {
482 struct snd_kcontrol *c;
483
484 template.name = kc[i].name;
485 template.private_value = kc[i].private_value;
486
487 c = snd_ctl_new1(&template, mixer);
488 err = snd_ctl_add(mixer->chip->card, c);
489
490 if (err < 0)
491 break;
492 }
493
494 return err;
495}
496
497/* M-Audio FastTrack Ultra quirks */
498
499/* private_free callback */
500static void usb_mixer_elem_free(struct snd_kcontrol *kctl)
501{
502 kfree(kctl->private_data);
503 kctl->private_data = NULL;
504}
505
506static int snd_maudio_ftu_create_ctl(struct usb_mixer_interface *mixer,
507 int in, int out, const char *name)
508{
509 struct usb_mixer_elem_info *cval;
510 struct snd_kcontrol *kctl;
511
512 cval = kzalloc(sizeof(*cval), GFP_KERNEL);
513 if (!cval)
514 return -ENOMEM;
515
516 cval->id = 5;
517 cval->mixer = mixer;
518 cval->val_type = USB_MIXER_S16;
519 cval->channels = 1;
520 cval->control = out + 1;
521 cval->cmask = 1 << in;
522
523 kctl = snd_ctl_new1(snd_usb_feature_unit_ctl, cval);
524 if (!kctl) {
525 kfree(cval);
526 return -ENOMEM;
527 }
528
529 snprintf(kctl->id.name, sizeof(kctl->id.name), name);
530 kctl->private_free = usb_mixer_elem_free;
531 return snd_usb_mixer_add_control(mixer, kctl);
532}
533
534static int snd_maudio_ftu_create_mixer(struct usb_mixer_interface *mixer)
535{
536 char name[64];
537 int in, out, err;
538
539 for (out = 0; out < 8; out++) {
540 for (in = 0; in < 8; in++) {
541 snprintf(name, sizeof(name),
542 "AIn%d - Out%d Capture Volume", in + 1, out + 1);
543 err = snd_maudio_ftu_create_ctl(mixer, in, out, name);
544 if (err < 0)
545 return err;
546 }
547
548 for (in = 8; in < 16; in++) {
549 snprintf(name, sizeof(name),
550 "DIn%d - Out%d Playback Volume", in - 7, out + 1);
551 err = snd_maudio_ftu_create_ctl(mixer, in, out, name);
552 if (err < 0)
553 return err;
554 }
555 }
556
557 return 0;
558}
559
338void snd_emuusb_set_samplerate(struct snd_usb_audio *chip, 560void snd_emuusb_set_samplerate(struct snd_usb_audio *chip,
339 unsigned char samplerate_id) 561 unsigned char samplerate_id)
340{ 562{
@@ -356,30 +578,50 @@ void snd_emuusb_set_samplerate(struct snd_usb_audio *chip,
356 578
357int snd_usb_mixer_apply_create_quirk(struct usb_mixer_interface *mixer) 579int snd_usb_mixer_apply_create_quirk(struct usb_mixer_interface *mixer)
358{ 580{
359 int err; 581 int err = 0;
360 struct snd_info_entry *entry; 582 struct snd_info_entry *entry;
361 583
362 if ((err = snd_usb_soundblaster_remote_init(mixer)) < 0) 584 if ((err = snd_usb_soundblaster_remote_init(mixer)) < 0)
363 return err; 585 return err;
364 586
365 if (mixer->chip->usb_id == USB_ID(0x041e, 0x3020) || 587 switch (mixer->chip->usb_id) {
366 mixer->chip->usb_id == USB_ID(0x041e, 0x3040) || 588 case USB_ID(0x041e, 0x3020):
367 mixer->chip->usb_id == USB_ID(0x041e, 0x3048)) { 589 case USB_ID(0x041e, 0x3040):
368 if ((err = snd_audigy2nx_controls_create(mixer)) < 0) 590 case USB_ID(0x041e, 0x3042):
369 return err; 591 case USB_ID(0x041e, 0x30df):
592 case USB_ID(0x041e, 0x3048):
593 err = snd_audigy2nx_controls_create(mixer);
594 if (err < 0)
595 break;
370 if (!snd_card_proc_new(mixer->chip->card, "audigy2nx", &entry)) 596 if (!snd_card_proc_new(mixer->chip->card, "audigy2nx", &entry))
371 snd_info_set_text_ops(entry, mixer, 597 snd_info_set_text_ops(entry, mixer,
372 snd_audigy2nx_proc_read); 598 snd_audigy2nx_proc_read);
373 } 599 break;
374 600
375 if (mixer->chip->usb_id == USB_ID(0x0b05, 0x1739) || 601 case USB_ID(0x0763, 0x2080): /* M-Audio Fast Track Ultra */
376 mixer->chip->usb_id == USB_ID(0x0b05, 0x1743)) { 602 case USB_ID(0x0763, 0x2081): /* M-Audio Fast Track Ultra 8R */
603 err = snd_maudio_ftu_create_mixer(mixer);
604 break;
605
606 case USB_ID(0x0b05, 0x1739):
607 case USB_ID(0x0b05, 0x1743):
377 err = snd_xonar_u1_controls_create(mixer); 608 err = snd_xonar_u1_controls_create(mixer);
378 if (err < 0) 609 break;
379 return err; 610
611 case USB_ID(0x17cc, 0x1011): /* Traktor Audio 6 */
612 err = snd_nativeinstruments_create_mixer(mixer,
613 snd_nativeinstruments_ta6_mixers,
614 ARRAY_SIZE(snd_nativeinstruments_ta6_mixers));
615 break;
616
617 case USB_ID(0x17cc, 0x1021): /* Traktor Audio 10 */
618 err = snd_nativeinstruments_create_mixer(mixer,
619 snd_nativeinstruments_ta10_mixers,
620 ARRAY_SIZE(snd_nativeinstruments_ta10_mixers));
621 break;
380 } 622 }
381 623
382 return 0; 624 return err;
383} 625}
384 626
385void snd_usb_mixer_rc_memory_change(struct usb_mixer_interface *mixer, 627void snd_usb_mixer_rc_memory_change(struct usb_mixer_interface *mixer,
diff --git a/sound/usb/pcm.c b/sound/usb/pcm.c
index 3b5135c93062..b8dcbf407bbb 100644
--- a/sound/usb/pcm.c
+++ b/sound/usb/pcm.c
@@ -32,6 +32,7 @@
32#include "helper.h" 32#include "helper.h"
33#include "pcm.h" 33#include "pcm.h"
34#include "clock.h" 34#include "clock.h"
35#include "power.h"
35 36
36/* 37/*
37 * return the current pcm pointer. just based on the hwptr_done value. 38 * return the current pcm pointer. just based on the hwptr_done value.
@@ -237,6 +238,7 @@ static int set_format(struct snd_usb_substream *subs, struct audioformat *fmt)
237 subs->datainterval = fmt->datainterval; 238 subs->datainterval = fmt->datainterval;
238 subs->syncpipe = subs->syncinterval = 0; 239 subs->syncpipe = subs->syncinterval = 0;
239 subs->maxpacksize = fmt->maxpacksize; 240 subs->maxpacksize = fmt->maxpacksize;
241 subs->syncmaxsize = 0;
240 subs->fill_max = 0; 242 subs->fill_max = 0;
241 243
242 /* we need a sync pipe in async OUT or adaptive IN mode */ 244 /* we need a sync pipe in async OUT or adaptive IN mode */
@@ -283,6 +285,7 @@ static int set_format(struct snd_usb_substream *subs, struct audioformat *fmt)
283 subs->syncinterval = get_endpoint(alts, 1)->bInterval - 1; 285 subs->syncinterval = get_endpoint(alts, 1)->bInterval - 1;
284 else 286 else
285 subs->syncinterval = 3; 287 subs->syncinterval = 3;
288 subs->syncmaxsize = le16_to_cpu(get_endpoint(alts, 1)->wMaxPacketSize);
286 } 289 }
287 290
288 /* always fill max packet size */ 291 /* always fill max packet size */
@@ -359,6 +362,7 @@ static int snd_usb_hw_params(struct snd_pcm_substream *substream,
359 } 362 }
360 363
361 if (changed) { 364 if (changed) {
365 mutex_lock(&subs->stream->chip->shutdown_mutex);
362 /* format changed */ 366 /* format changed */
363 snd_usb_release_substream_urbs(subs, 0); 367 snd_usb_release_substream_urbs(subs, 0);
364 /* influenced: period_bytes, channels, rate, format, */ 368 /* influenced: period_bytes, channels, rate, format, */
@@ -366,6 +370,7 @@ static int snd_usb_hw_params(struct snd_pcm_substream *substream,
366 params_rate(hw_params), 370 params_rate(hw_params),
367 snd_pcm_format_physical_width(params_format(hw_params)) * 371 snd_pcm_format_physical_width(params_format(hw_params)) *
368 params_channels(hw_params)); 372 params_channels(hw_params));
373 mutex_unlock(&subs->stream->chip->shutdown_mutex);
369 } 374 }
370 375
371 return ret; 376 return ret;
@@ -383,8 +388,9 @@ static int snd_usb_hw_free(struct snd_pcm_substream *substream)
383 subs->cur_audiofmt = NULL; 388 subs->cur_audiofmt = NULL;
384 subs->cur_rate = 0; 389 subs->cur_rate = 0;
385 subs->period_bytes = 0; 390 subs->period_bytes = 0;
386 if (!subs->stream->chip->shutdown) 391 mutex_lock(&subs->stream->chip->shutdown_mutex);
387 snd_usb_release_substream_urbs(subs, 0); 392 snd_usb_release_substream_urbs(subs, 0);
393 mutex_unlock(&subs->stream->chip->shutdown_mutex);
388 return snd_pcm_lib_free_vmalloc_buffer(substream); 394 return snd_pcm_lib_free_vmalloc_buffer(substream);
389} 395}
390 396
@@ -466,7 +472,7 @@ static int hw_check_valid_format(struct snd_usb_substream *subs,
466 return 0; 472 return 0;
467 } 473 }
468 /* check whether the period time is >= the data packet interval */ 474 /* check whether the period time is >= the data packet interval */
469 if (snd_usb_get_speed(subs->dev) == USB_SPEED_HIGH) { 475 if (snd_usb_get_speed(subs->dev) != USB_SPEED_FULL) {
470 ptime = 125 * (1 << fp->datainterval); 476 ptime = 125 * (1 << fp->datainterval);
471 if (ptime > pt->max || (ptime == pt->max && pt->openmax)) { 477 if (ptime > pt->max || (ptime == pt->max && pt->openmax)) {
472 hwc_debug(" > check: ptime %u > max %u\n", ptime, pt->max); 478 hwc_debug(" > check: ptime %u > max %u\n", ptime, pt->max);
@@ -674,8 +680,10 @@ static int snd_usb_pcm_check_knot(struct snd_pcm_runtime *runtime,
674 if (!needs_knot) 680 if (!needs_knot)
675 return 0; 681 return 0;
676 682
677 subs->rate_list.count = count;
678 subs->rate_list.list = kmalloc(sizeof(int) * count, GFP_KERNEL); 683 subs->rate_list.list = kmalloc(sizeof(int) * count, GFP_KERNEL);
684 if (!subs->rate_list.list)
685 return -ENOMEM;
686 subs->rate_list.count = count;
679 subs->rate_list.mask = 0; 687 subs->rate_list.mask = 0;
680 count = 0; 688 count = 0;
681 list_for_each_entry(fp, &subs->fmt_list, list) { 689 list_for_each_entry(fp, &subs->fmt_list, list) {
@@ -732,9 +740,12 @@ static int setup_hw_info(struct snd_pcm_runtime *runtime, struct snd_usb_substre
732 pt = 125 * (1 << fp->datainterval); 740 pt = 125 * (1 << fp->datainterval);
733 ptmin = min(ptmin, pt); 741 ptmin = min(ptmin, pt);
734 } 742 }
743 err = snd_usb_autoresume(subs->stream->chip);
744 if (err < 0)
745 return err;
735 746
736 param_period_time_if_needed = SNDRV_PCM_HW_PARAM_PERIOD_TIME; 747 param_period_time_if_needed = SNDRV_PCM_HW_PARAM_PERIOD_TIME;
737 if (snd_usb_get_speed(subs->dev) != USB_SPEED_HIGH) 748 if (snd_usb_get_speed(subs->dev) == USB_SPEED_FULL)
738 /* full speed devices have fixed data packet interval */ 749 /* full speed devices have fixed data packet interval */
739 ptmin = 1000; 750 ptmin = 1000;
740 if (ptmin == 1000) 751 if (ptmin == 1000)
@@ -749,21 +760,21 @@ static int setup_hw_info(struct snd_pcm_runtime *runtime, struct snd_usb_substre
749 SNDRV_PCM_HW_PARAM_CHANNELS, 760 SNDRV_PCM_HW_PARAM_CHANNELS,
750 param_period_time_if_needed, 761 param_period_time_if_needed,
751 -1)) < 0) 762 -1)) < 0)
752 return err; 763 goto rep_err;
753 if ((err = snd_pcm_hw_rule_add(runtime, 0, SNDRV_PCM_HW_PARAM_CHANNELS, 764 if ((err = snd_pcm_hw_rule_add(runtime, 0, SNDRV_PCM_HW_PARAM_CHANNELS,
754 hw_rule_channels, subs, 765 hw_rule_channels, subs,
755 SNDRV_PCM_HW_PARAM_FORMAT, 766 SNDRV_PCM_HW_PARAM_FORMAT,
756 SNDRV_PCM_HW_PARAM_RATE, 767 SNDRV_PCM_HW_PARAM_RATE,
757 param_period_time_if_needed, 768 param_period_time_if_needed,
758 -1)) < 0) 769 -1)) < 0)
759 return err; 770 goto rep_err;
760 if ((err = snd_pcm_hw_rule_add(runtime, 0, SNDRV_PCM_HW_PARAM_FORMAT, 771 if ((err = snd_pcm_hw_rule_add(runtime, 0, SNDRV_PCM_HW_PARAM_FORMAT,
761 hw_rule_format, subs, 772 hw_rule_format, subs,
762 SNDRV_PCM_HW_PARAM_RATE, 773 SNDRV_PCM_HW_PARAM_RATE,
763 SNDRV_PCM_HW_PARAM_CHANNELS, 774 SNDRV_PCM_HW_PARAM_CHANNELS,
764 param_period_time_if_needed, 775 param_period_time_if_needed,
765 -1)) < 0) 776 -1)) < 0)
766 return err; 777 goto rep_err;
767 if (param_period_time_if_needed >= 0) { 778 if (param_period_time_if_needed >= 0) {
768 err = snd_pcm_hw_rule_add(runtime, 0, 779 err = snd_pcm_hw_rule_add(runtime, 0,
769 SNDRV_PCM_HW_PARAM_PERIOD_TIME, 780 SNDRV_PCM_HW_PARAM_PERIOD_TIME,
@@ -773,11 +784,15 @@ static int setup_hw_info(struct snd_pcm_runtime *runtime, struct snd_usb_substre
773 SNDRV_PCM_HW_PARAM_RATE, 784 SNDRV_PCM_HW_PARAM_RATE,
774 -1); 785 -1);
775 if (err < 0) 786 if (err < 0)
776 return err; 787 goto rep_err;
777 } 788 }
778 if ((err = snd_usb_pcm_check_knot(runtime, subs)) < 0) 789 if ((err = snd_usb_pcm_check_knot(runtime, subs)) < 0)
779 return err; 790 goto rep_err;
780 return 0; 791 return 0;
792
793rep_err:
794 snd_usb_autosuspend(subs->stream->chip);
795 return err;
781} 796}
782 797
783static int snd_usb_pcm_open(struct snd_pcm_substream *substream, int direction) 798static int snd_usb_pcm_open(struct snd_pcm_substream *substream, int direction)
@@ -791,6 +806,7 @@ static int snd_usb_pcm_open(struct snd_pcm_substream *substream, int direction)
791 runtime->hw = snd_usb_hardware; 806 runtime->hw = snd_usb_hardware;
792 runtime->private_data = subs; 807 runtime->private_data = subs;
793 subs->pcm_substream = substream; 808 subs->pcm_substream = substream;
809 /* runtime PM is also done there */
794 return setup_hw_info(runtime, subs); 810 return setup_hw_info(runtime, subs);
795} 811}
796 812
@@ -804,6 +820,7 @@ static int snd_usb_pcm_close(struct snd_pcm_substream *substream, int direction)
804 subs->interface = -1; 820 subs->interface = -1;
805 } 821 }
806 subs->pcm_substream = NULL; 822 subs->pcm_substream = NULL;
823 snd_usb_autosuspend(subs->stream->chip);
807 return 0; 824 return 0;
808} 825}
809 826
diff --git a/sound/usb/power.h b/sound/usb/power.h
new file mode 100644
index 000000000000..48ee51dcb71e
--- /dev/null
+++ b/sound/usb/power.h
@@ -0,0 +1,17 @@
1#ifndef __USBAUDIO_POWER_H
2#define __USBAUDIO_POWER_H
3
4#ifdef CONFIG_PM
5int snd_usb_autoresume(struct snd_usb_audio *chip);
6void snd_usb_autosuspend(struct snd_usb_audio *chip);
7#else
8static inline int snd_usb_autoresume(struct snd_usb_audio *chip)
9{
10 return 0;
11}
12static inline void snd_usb_autosuspend(struct snd_usb_audio *chip)
13{
14}
15#endif
16
17#endif /* __USBAUDIO_POWER_H */
diff --git a/sound/usb/proc.c b/sound/usb/proc.c
index f5e3f356b95f..961c9a250686 100644
--- a/sound/usb/proc.c
+++ b/sound/usb/proc.c
@@ -107,7 +107,7 @@ static void proc_dump_substream_formats(struct snd_usb_substream *subs, struct s
107 } 107 }
108 snd_iprintf(buffer, "\n"); 108 snd_iprintf(buffer, "\n");
109 } 109 }
110 if (snd_usb_get_speed(subs->dev) == USB_SPEED_HIGH) 110 if (snd_usb_get_speed(subs->dev) != USB_SPEED_FULL)
111 snd_iprintf(buffer, " Data packet interval: %d us\n", 111 snd_iprintf(buffer, " Data packet interval: %d us\n",
112 125 * (1 << fp->datainterval)); 112 125 * (1 << fp->datainterval));
113 // snd_iprintf(buffer, " Max Packet Size = %d\n", fp->maxpacksize); 113 // snd_iprintf(buffer, " Max Packet Size = %d\n", fp->maxpacksize);
@@ -132,6 +132,11 @@ static void proc_dump_substream_status(struct snd_usb_substream *subs, struct sn
132 ? get_full_speed_hz(subs->freqm) 132 ? get_full_speed_hz(subs->freqm)
133 : get_high_speed_hz(subs->freqm), 133 : get_high_speed_hz(subs->freqm),
134 subs->freqm >> 16, subs->freqm & 0xffff); 134 subs->freqm >> 16, subs->freqm & 0xffff);
135 if (subs->freqshift != INT_MIN)
136 snd_iprintf(buffer, " Feedback Format = %d.%d\n",
137 (subs->syncmaxsize > 3 ? 32 : 24)
138 - (16 - subs->freqshift),
139 16 - subs->freqshift);
135 } else { 140 } else {
136 snd_iprintf(buffer, " Status: Stop\n"); 141 snd_iprintf(buffer, " Status: Stop\n");
137 } 142 }
diff --git a/sound/usb/quirks-table.h b/sound/usb/quirks-table.h
index 2e8003f98fca..0b2ae8e1c02d 100644
--- a/sound/usb/quirks-table.h
+++ b/sound/usb/quirks-table.h
@@ -79,6 +79,13 @@
79 .idProduct = 0x3f0a, 79 .idProduct = 0x3f0a,
80 .bInterfaceClass = USB_CLASS_AUDIO, 80 .bInterfaceClass = USB_CLASS_AUDIO,
81}, 81},
82{
83 /* E-Mu 0204 USB */
84 .match_flags = USB_DEVICE_ID_MATCH_DEVICE,
85 .idVendor = 0x041e,
86 .idProduct = 0x3f19,
87 .bInterfaceClass = USB_CLASS_AUDIO,
88},
82 89
83/* 90/*
84 * Logitech QuickCam: bDeviceClass is vendor-specific, so generic interface 91 * Logitech QuickCam: bDeviceClass is vendor-specific, so generic interface
@@ -240,9 +247,21 @@ YAMAHA_DEVICE(0x104f, NULL),
240YAMAHA_DEVICE(0x1050, NULL), 247YAMAHA_DEVICE(0x1050, NULL),
241YAMAHA_DEVICE(0x1051, NULL), 248YAMAHA_DEVICE(0x1051, NULL),
242YAMAHA_DEVICE(0x1052, NULL), 249YAMAHA_DEVICE(0x1052, NULL),
250YAMAHA_INTERFACE(0x1053, 0, NULL),
251YAMAHA_INTERFACE(0x1054, 0, NULL),
252YAMAHA_DEVICE(0x1055, NULL),
253YAMAHA_DEVICE(0x1056, NULL),
254YAMAHA_DEVICE(0x1057, NULL),
255YAMAHA_DEVICE(0x1058, NULL),
256YAMAHA_DEVICE(0x1059, NULL),
257YAMAHA_DEVICE(0x105a, NULL),
258YAMAHA_DEVICE(0x105b, NULL),
259YAMAHA_DEVICE(0x105c, NULL),
260YAMAHA_DEVICE(0x105d, NULL),
243YAMAHA_DEVICE(0x2000, "DGP-7"), 261YAMAHA_DEVICE(0x2000, "DGP-7"),
244YAMAHA_DEVICE(0x2001, "DGP-5"), 262YAMAHA_DEVICE(0x2001, "DGP-5"),
245YAMAHA_DEVICE(0x2002, NULL), 263YAMAHA_DEVICE(0x2002, NULL),
264YAMAHA_DEVICE(0x2003, NULL),
246YAMAHA_DEVICE(0x5000, "CS1D"), 265YAMAHA_DEVICE(0x5000, "CS1D"),
247YAMAHA_DEVICE(0x5001, "DSP1D"), 266YAMAHA_DEVICE(0x5001, "DSP1D"),
248YAMAHA_DEVICE(0x5002, "DME32"), 267YAMAHA_DEVICE(0x5002, "DME32"),
@@ -693,11 +712,11 @@ YAMAHA_DEVICE(0x7010, "UB99"),
693 .data = (const struct snd_usb_audio_quirk[]) { 712 .data = (const struct snd_usb_audio_quirk[]) {
694 { 713 {
695 .ifnum = 0, 714 .ifnum = 0,
696 .type = QUIRK_IGNORE_INTERFACE 715 .type = QUIRK_AUDIO_STANDARD_INTERFACE
697 }, 716 },
698 { 717 {
699 .ifnum = 1, 718 .ifnum = 1,
700 .type = QUIRK_IGNORE_INTERFACE 719 .type = QUIRK_AUDIO_STANDARD_INTERFACE
701 }, 720 },
702 { 721 {
703 .ifnum = 2, 722 .ifnum = 2,
@@ -1136,11 +1155,34 @@ YAMAHA_DEVICE(0x7010, "UB99"),
1136 } 1155 }
1137}, 1156},
1138{ 1157{
1158 /* has ID 0x0066 when not in "Advanced Driver" mode */
1159 USB_DEVICE(0x0582, 0x0064),
1160 .driver_info = (unsigned long) & (const struct snd_usb_audio_quirk) {
1161 /* .vendor_name = "EDIROL", */
1162 /* .product_name = "PCR-1", */
1163 .ifnum = QUIRK_ANY_INTERFACE,
1164 .type = QUIRK_COMPOSITE,
1165 .data = (const struct snd_usb_audio_quirk[]) {
1166 {
1167 .ifnum = 1,
1168 .type = QUIRK_AUDIO_STANDARD_INTERFACE
1169 },
1170 {
1171 .ifnum = 2,
1172 .type = QUIRK_AUDIO_STANDARD_INTERFACE
1173 },
1174 {
1175 .ifnum = -1
1176 }
1177 }
1178 }
1179},
1180{
1139 /* has ID 0x0067 when not in "Advanced Driver" mode */ 1181 /* has ID 0x0067 when not in "Advanced Driver" mode */
1140 USB_DEVICE(0x0582, 0x0065), 1182 USB_DEVICE(0x0582, 0x0065),
1141 .driver_info = (unsigned long) & (const struct snd_usb_audio_quirk) { 1183 .driver_info = (unsigned long) & (const struct snd_usb_audio_quirk) {
1142 .vendor_name = "EDIROL", 1184 /* .vendor_name = "EDIROL", */
1143 .product_name = "PCR-1", 1185 /* .product_name = "PCR-1", */
1144 .ifnum = 0, 1186 .ifnum = 0,
1145 .type = QUIRK_MIDI_FIXED_ENDPOINT, 1187 .type = QUIRK_MIDI_FIXED_ENDPOINT,
1146 .data = & (const struct snd_usb_midi_endpoint_info) { 1188 .data = & (const struct snd_usb_midi_endpoint_info) {
@@ -1525,6 +1567,116 @@ YAMAHA_DEVICE(0x7010, "UB99"),
1525 } 1567 }
1526 } 1568 }
1527}, 1569},
1570{
1571 USB_DEVICE_VENDOR_SPEC(0x0582, 0x0104),
1572 .driver_info = (unsigned long) & (const struct snd_usb_audio_quirk) {
1573 /* .vendor_name = "Roland", */
1574 /* .product_name = "UM-1G", */
1575 .ifnum = 0,
1576 .type = QUIRK_MIDI_FIXED_ENDPOINT,
1577 .data = & (const struct snd_usb_midi_endpoint_info) {
1578 .out_cables = 0x0001,
1579 .in_cables = 0x0001
1580 }
1581 }
1582},
1583{
1584 /* Boss JS-8 Jam Station */
1585 USB_DEVICE(0x0582, 0x0109),
1586 .driver_info = (unsigned long) & (const struct snd_usb_audio_quirk) {
1587 /* .vendor_name = "BOSS", */
1588 /* .product_name = "JS-8", */
1589 .ifnum = QUIRK_ANY_INTERFACE,
1590 .type = QUIRK_COMPOSITE,
1591 .data = (const struct snd_usb_audio_quirk[]) {
1592 {
1593 .ifnum = 0,
1594 .type = QUIRK_AUDIO_STANDARD_INTERFACE
1595 },
1596 {
1597 .ifnum = 1,
1598 .type = QUIRK_AUDIO_STANDARD_INTERFACE
1599 },
1600 {
1601 .ifnum = 2,
1602 .type = QUIRK_MIDI_STANDARD_INTERFACE
1603 },
1604 {
1605 .ifnum = -1
1606 }
1607 }
1608 }
1609},
1610{
1611 /* has ID 0x0110 when not in Advanced Driver mode */
1612 USB_DEVICE_VENDOR_SPEC(0x0582, 0x010f),
1613 .driver_info = (unsigned long) & (const struct snd_usb_audio_quirk) {
1614 /* .vendor_name = "Roland", */
1615 /* .product_name = "A-PRO", */
1616 .ifnum = 1,
1617 .type = QUIRK_MIDI_FIXED_ENDPOINT,
1618 .data = & (const struct snd_usb_midi_endpoint_info) {
1619 .out_cables = 0x0003,
1620 .in_cables = 0x0007
1621 }
1622 }
1623},
1624{
1625 USB_DEVICE(0x0582, 0x0113),
1626 .driver_info = (unsigned long) & (const struct snd_usb_audio_quirk) {
1627 /* .vendor_name = "BOSS", */
1628 /* .product_name = "ME-25", */
1629 .ifnum = QUIRK_ANY_INTERFACE,
1630 .type = QUIRK_COMPOSITE,
1631 .data = (const struct snd_usb_audio_quirk[]) {
1632 {
1633 .ifnum = 0,
1634 .type = QUIRK_AUDIO_STANDARD_INTERFACE
1635 },
1636 {
1637 .ifnum = 1,
1638 .type = QUIRK_AUDIO_STANDARD_INTERFACE
1639 },
1640 {
1641 .ifnum = 2,
1642 .type = QUIRK_MIDI_FIXED_ENDPOINT,
1643 .data = & (const struct snd_usb_midi_endpoint_info) {
1644 .out_cables = 0x0001,
1645 .in_cables = 0x0001
1646 }
1647 },
1648 {
1649 .ifnum = -1
1650 }
1651 }
1652 }
1653},
1654{
1655 USB_DEVICE(0x0582, 0x0127),
1656 .driver_info = (unsigned long) & (const struct snd_usb_audio_quirk) {
1657 /* .vendor_name = "Roland", */
1658 /* .product_name = "GR-55", */
1659 .ifnum = QUIRK_ANY_INTERFACE,
1660 .type = QUIRK_COMPOSITE,
1661 .data = (const struct snd_usb_audio_quirk[]) {
1662 {
1663 .ifnum = 0,
1664 .type = QUIRK_AUDIO_STANDARD_INTERFACE
1665 },
1666 {
1667 .ifnum = 1,
1668 .type = QUIRK_AUDIO_STANDARD_INTERFACE
1669 },
1670 {
1671 .ifnum = 2,
1672 .type = QUIRK_MIDI_STANDARD_INTERFACE
1673 },
1674 {
1675 .ifnum = -1
1676 }
1677 }
1678 }
1679},
1528 1680
1529/* Guillemot devices */ 1681/* Guillemot devices */
1530{ 1682{
@@ -1827,24 +1979,64 @@ YAMAHA_DEVICE(0x7010, "UB99"),
1827 } 1979 }
1828}, 1980},
1829{ 1981{
1830 USB_DEVICE(0x0763, 0x2080), 1982 USB_DEVICE_VENDOR_SPEC(0x0763, 0x2080),
1831 .driver_info = (unsigned long) & (const struct snd_usb_audio_quirk) { 1983 .driver_info = (unsigned long) & (const struct snd_usb_audio_quirk) {
1832 /* .vendor_name = "M-Audio", */ 1984 /* .vendor_name = "M-Audio", */
1833 /* .product_name = "Fast Track Ultra 8", */ 1985 /* .product_name = "Fast Track Ultra", */
1834 .ifnum = QUIRK_ANY_INTERFACE, 1986 .ifnum = QUIRK_ANY_INTERFACE,
1835 .type = QUIRK_COMPOSITE, 1987 .type = QUIRK_COMPOSITE,
1836 .data = & (const struct snd_usb_audio_quirk[]) { 1988 .data = & (const struct snd_usb_audio_quirk[]) {
1837 { 1989 {
1838 .ifnum = 0, 1990 .ifnum = 0,
1839 .type = QUIRK_IGNORE_INTERFACE 1991 .type = QUIRK_AUDIO_STANDARD_MIXER,
1840 }, 1992 },
1841 { 1993 {
1842 .ifnum = 1, 1994 .ifnum = 1,
1843 .type = QUIRK_AUDIO_STANDARD_INTERFACE 1995 .type = QUIRK_AUDIO_FIXED_ENDPOINT,
1996 .data = & (const struct audioformat) {
1997 .formats = SNDRV_PCM_FMTBIT_S24_3LE,
1998 .channels = 8,
1999 .iface = 1,
2000 .altsetting = 1,
2001 .altset_idx = 1,
2002 .attributes = UAC_EP_CS_ATTR_SAMPLE_RATE,
2003 .endpoint = 0x01,
2004 .ep_attr = 0x09,
2005 .rates = SNDRV_PCM_RATE_44100 |
2006 SNDRV_PCM_RATE_48000 |
2007 SNDRV_PCM_RATE_88200 |
2008 SNDRV_PCM_RATE_96000,
2009 .rate_min = 44100,
2010 .rate_max = 96000,
2011 .nr_rates = 4,
2012 .rate_table = (unsigned int[]) {
2013 44100, 48000, 88200, 96000
2014 }
2015 }
1844 }, 2016 },
1845 { 2017 {
1846 .ifnum = 2, 2018 .ifnum = 2,
1847 .type = QUIRK_AUDIO_STANDARD_INTERFACE 2019 .type = QUIRK_AUDIO_FIXED_ENDPOINT,
2020 .data = & (const struct audioformat) {
2021 .formats = SNDRV_PCM_FMTBIT_S24_3LE,
2022 .channels = 8,
2023 .iface = 2,
2024 .altsetting = 1,
2025 .altset_idx = 1,
2026 .attributes = UAC_EP_CS_ATTR_SAMPLE_RATE,
2027 .endpoint = 0x81,
2028 .ep_attr = 0x05,
2029 .rates = SNDRV_PCM_RATE_44100 |
2030 SNDRV_PCM_RATE_48000 |
2031 SNDRV_PCM_RATE_88200 |
2032 SNDRV_PCM_RATE_96000,
2033 .rate_min = 44100,
2034 .rate_max = 96000,
2035 .nr_rates = 4,
2036 .rate_table = (unsigned int[]) {
2037 44100, 48000, 88200, 96000
2038 }
2039 }
1848 }, 2040 },
1849 /* interface 3 (MIDI) is standard compliant */ 2041 /* interface 3 (MIDI) is standard compliant */
1850 { 2042 {
@@ -1854,7 +2046,7 @@ YAMAHA_DEVICE(0x7010, "UB99"),
1854 } 2046 }
1855}, 2047},
1856{ 2048{
1857 USB_DEVICE(0x0763, 0x2081), 2049 USB_DEVICE_VENDOR_SPEC(0x0763, 0x2081),
1858 .driver_info = (unsigned long) & (const struct snd_usb_audio_quirk) { 2050 .driver_info = (unsigned long) & (const struct snd_usb_audio_quirk) {
1859 /* .vendor_name = "M-Audio", */ 2051 /* .vendor_name = "M-Audio", */
1860 /* .product_name = "Fast Track Ultra 8R", */ 2052 /* .product_name = "Fast Track Ultra 8R", */
@@ -1863,15 +2055,55 @@ YAMAHA_DEVICE(0x7010, "UB99"),
1863 .data = & (const struct snd_usb_audio_quirk[]) { 2055 .data = & (const struct snd_usb_audio_quirk[]) {
1864 { 2056 {
1865 .ifnum = 0, 2057 .ifnum = 0,
1866 .type = QUIRK_IGNORE_INTERFACE 2058 .type = QUIRK_AUDIO_STANDARD_MIXER,
1867 }, 2059 },
1868 { 2060 {
1869 .ifnum = 1, 2061 .ifnum = 1,
1870 .type = QUIRK_AUDIO_STANDARD_INTERFACE 2062 .type = QUIRK_AUDIO_FIXED_ENDPOINT,
2063 .data = & (const struct audioformat) {
2064 .formats = SNDRV_PCM_FMTBIT_S24_3LE,
2065 .channels = 8,
2066 .iface = 1,
2067 .altsetting = 1,
2068 .altset_idx = 1,
2069 .attributes = UAC_EP_CS_ATTR_SAMPLE_RATE,
2070 .endpoint = 0x01,
2071 .ep_attr = 0x09,
2072 .rates = SNDRV_PCM_RATE_44100 |
2073 SNDRV_PCM_RATE_48000 |
2074 SNDRV_PCM_RATE_88200 |
2075 SNDRV_PCM_RATE_96000,
2076 .rate_min = 44100,
2077 .rate_max = 96000,
2078 .nr_rates = 4,
2079 .rate_table = (unsigned int[]) {
2080 44100, 48000, 88200, 96000
2081 }
2082 }
1871 }, 2083 },
1872 { 2084 {
1873 .ifnum = 2, 2085 .ifnum = 2,
1874 .type = QUIRK_AUDIO_STANDARD_INTERFACE 2086 .type = QUIRK_AUDIO_FIXED_ENDPOINT,
2087 .data = & (const struct audioformat) {
2088 .formats = SNDRV_PCM_FMTBIT_S24_3LE,
2089 .channels = 8,
2090 .iface = 2,
2091 .altsetting = 1,
2092 .altset_idx = 1,
2093 .attributes = UAC_EP_CS_ATTR_SAMPLE_RATE,
2094 .endpoint = 0x81,
2095 .ep_attr = 0x05,
2096 .rates = SNDRV_PCM_RATE_44100 |
2097 SNDRV_PCM_RATE_48000 |
2098 SNDRV_PCM_RATE_88200 |
2099 SNDRV_PCM_RATE_96000,
2100 .rate_min = 44100,
2101 .rate_max = 96000,
2102 .nr_rates = 4,
2103 .rate_table = (unsigned int[]) {
2104 44100, 48000, 88200, 96000
2105 }
2106 }
1875 }, 2107 },
1876 /* interface 3 (MIDI) is standard compliant */ 2108 /* interface 3 (MIDI) is standard compliant */
1877 { 2109 {
@@ -1919,7 +2151,7 @@ YAMAHA_DEVICE(0x7010, "UB99"),
1919 .data = & (const struct snd_usb_audio_quirk[]) { 2151 .data = & (const struct snd_usb_audio_quirk[]) {
1920 { 2152 {
1921 .ifnum = 0, 2153 .ifnum = 0,
1922 .type = QUIRK_MIDI_FASTLANE 2154 .type = QUIRK_MIDI_RAW_BYTES
1923 }, 2155 },
1924 { 2156 {
1925 .ifnum = 1, 2157 .ifnum = 1,
@@ -1973,6 +2205,17 @@ YAMAHA_DEVICE(0x7010, "UB99"),
1973 } 2205 }
1974}, 2206},
1975 2207
2208/* KORG devices */
2209{
2210 USB_DEVICE_VENDOR_SPEC(0x0944, 0x0200),
2211 .driver_info = (unsigned long) & (const struct snd_usb_audio_quirk) {
2212 .vendor_name = "KORG, Inc.",
2213 /* .product_name = "PANDORA PX5D", */
2214 .ifnum = 3,
2215 .type = QUIRK_MIDI_STANDARD_INTERFACE,
2216 }
2217},
2218
1976/* AKAI devices */ 2219/* AKAI devices */
1977{ 2220{
1978 USB_DEVICE(0x09e8, 0x0062), 2221 USB_DEVICE(0x09e8, 0x0062),
@@ -2068,6 +2311,15 @@ YAMAHA_DEVICE(0x7010, "UB99"),
2068 } 2311 }
2069}, 2312},
2070{ 2313{
2314 USB_DEVICE(0x1235, 0x000e),
2315 .driver_info = (unsigned long) & (const struct snd_usb_audio_quirk) {
2316 /* .vendor_name = "Novation", */
2317 /* .product_name = "Launchpad", */
2318 .ifnum = 0,
2319 .type = QUIRK_MIDI_RAW_BYTES
2320 }
2321},
2322{
2071 USB_DEVICE_VENDOR_SPEC(0x1235, 0x4661), 2323 USB_DEVICE_VENDOR_SPEC(0x1235, 0x4661),
2072 .driver_info = (unsigned long) & (const struct snd_usb_audio_quirk) { 2324 .driver_info = (unsigned long) & (const struct snd_usb_audio_quirk) {
2073 .vendor_name = "Novation", 2325 .vendor_name = "Novation",
@@ -2115,6 +2367,26 @@ YAMAHA_DEVICE(0x7010, "UB99"),
2115 } 2367 }
2116}, 2368},
2117 2369
2370/* Native Instruments MK2 series */
2371{
2372 /* Komplete Audio 6 */
2373 .match_flags = USB_DEVICE_ID_MATCH_DEVICE,
2374 .idVendor = 0x17cc,
2375 .idProduct = 0x1000,
2376},
2377{
2378 /* Traktor Audio 6 */
2379 .match_flags = USB_DEVICE_ID_MATCH_DEVICE,
2380 .idVendor = 0x17cc,
2381 .idProduct = 0x1010,
2382},
2383{
2384 /* Traktor Audio 10 */
2385 .match_flags = USB_DEVICE_ID_MATCH_DEVICE,
2386 .idVendor = 0x17cc,
2387 .idProduct = 0x1020,
2388},
2389
2118/* Miditech devices */ 2390/* Miditech devices */
2119{ 2391{
2120 USB_DEVICE(0x4752, 0x0011), 2392 USB_DEVICE(0x4752, 0x0011),
diff --git a/sound/usb/quirks.c b/sound/usb/quirks.c
index 9a9da09586a5..090e1930dfdc 100644
--- a/sound/usb/quirks.c
+++ b/sound/usb/quirks.c
@@ -19,6 +19,7 @@
19#include <linux/usb.h> 19#include <linux/usb.h>
20#include <linux/usb/audio.h> 20#include <linux/usb/audio.h>
21 21
22#include <sound/control.h>
22#include <sound/core.h> 23#include <sound/core.h>
23#include <sound/info.h> 24#include <sound/info.h>
24#include <sound/pcm.h> 25#include <sound/pcm.h>
@@ -263,10 +264,24 @@ static int create_uaxx_quirk(struct snd_usb_audio *chip,
263} 264}
264 265
265/* 266/*
267 * Create a standard mixer for the specified interface.
268 */
269static int create_standard_mixer_quirk(struct snd_usb_audio *chip,
270 struct usb_interface *iface,
271 struct usb_driver *driver,
272 const struct snd_usb_audio_quirk *quirk)
273{
274 if (quirk->ifnum < 0)
275 return 0;
276
277 return snd_usb_create_mixer(chip, quirk->ifnum, 0);
278}
279
280/*
266 * audio-interface quirks 281 * audio-interface quirks
267 * 282 *
268 * returns zero if no standard audio/MIDI parsing is needed. 283 * returns zero if no standard audio/MIDI parsing is needed.
269 * returns a postive value if standard audio/midi interfaces are parsed 284 * returns a positive value if standard audio/midi interfaces are parsed
270 * after this. 285 * after this.
271 * returns a negative value at error. 286 * returns a negative value at error.
272 */ 287 */
@@ -287,14 +302,15 @@ int snd_usb_create_quirk(struct snd_usb_audio *chip,
287 [QUIRK_MIDI_YAMAHA] = create_any_midi_quirk, 302 [QUIRK_MIDI_YAMAHA] = create_any_midi_quirk,
288 [QUIRK_MIDI_MIDIMAN] = create_any_midi_quirk, 303 [QUIRK_MIDI_MIDIMAN] = create_any_midi_quirk,
289 [QUIRK_MIDI_NOVATION] = create_any_midi_quirk, 304 [QUIRK_MIDI_NOVATION] = create_any_midi_quirk,
290 [QUIRK_MIDI_FASTLANE] = create_any_midi_quirk, 305 [QUIRK_MIDI_RAW_BYTES] = create_any_midi_quirk,
291 [QUIRK_MIDI_EMAGIC] = create_any_midi_quirk, 306 [QUIRK_MIDI_EMAGIC] = create_any_midi_quirk,
292 [QUIRK_MIDI_CME] = create_any_midi_quirk, 307 [QUIRK_MIDI_CME] = create_any_midi_quirk,
293 [QUIRK_MIDI_AKAI] = create_any_midi_quirk, 308 [QUIRK_MIDI_AKAI] = create_any_midi_quirk,
294 [QUIRK_AUDIO_STANDARD_INTERFACE] = create_standard_audio_quirk, 309 [QUIRK_AUDIO_STANDARD_INTERFACE] = create_standard_audio_quirk,
295 [QUIRK_AUDIO_FIXED_ENDPOINT] = create_fixed_stream_quirk, 310 [QUIRK_AUDIO_FIXED_ENDPOINT] = create_fixed_stream_quirk,
296 [QUIRK_AUDIO_EDIROL_UAXX] = create_uaxx_quirk, 311 [QUIRK_AUDIO_EDIROL_UAXX] = create_uaxx_quirk,
297 [QUIRK_AUDIO_ALIGN_TRANSFER] = create_align_transfer_quirk 312 [QUIRK_AUDIO_ALIGN_TRANSFER] = create_align_transfer_quirk,
313 [QUIRK_AUDIO_STANDARD_MIXER] = create_standard_mixer_quirk,
298 }; 314 };
299 315
300 if (quirk->type < QUIRK_TYPE_COUNT) { 316 if (quirk->type < QUIRK_TYPE_COUNT) {
@@ -387,7 +403,7 @@ static int snd_usb_cm106_boot_quirk(struct usb_device *dev)
387static int snd_usb_cm6206_boot_quirk(struct usb_device *dev) 403static int snd_usb_cm6206_boot_quirk(struct usb_device *dev)
388{ 404{
389 int err, reg; 405 int err, reg;
390 int val[] = {0x200c, 0x3000, 0xf800, 0x143f, 0x0000, 0x3000}; 406 int val[] = {0x2004, 0x3000, 0xf800, 0x143f, 0x0000, 0x3000};
391 407
392 for (reg = 0; reg < ARRAY_SIZE(val); reg++) { 408 for (reg = 0; reg < ARRAY_SIZE(val); reg++) {
393 err = snd_usb_cm106_write_int_reg(dev, reg, val[reg]); 409 err = snd_usb_cm106_write_int_reg(dev, reg, val[reg]);
@@ -425,6 +441,34 @@ static int snd_usb_accessmusic_boot_quirk(struct usb_device *dev)
425} 441}
426 442
427/* 443/*
444 * Some sound cards from Native Instruments are in fact compliant to the USB
445 * audio standard of version 2 and other approved USB standards, even though
446 * they come up as vendor-specific device when first connected.
447 *
448 * However, they can be told to come up with a new set of descriptors
449 * upon their next enumeration, and the interfaces announced by the new
450 * descriptors will then be handled by the kernel's class drivers. As the
451 * product ID will also change, no further checks are required.
452 */
453
454static int snd_usb_nativeinstruments_boot_quirk(struct usb_device *dev)
455{
456 int ret = usb_control_msg(dev, usb_sndctrlpipe(dev, 0),
457 0xaf, USB_TYPE_VENDOR | USB_RECIP_DEVICE,
458 cpu_to_le16(1), 0, NULL, 0, 1000);
459
460 if (ret < 0)
461 return ret;
462
463 usb_reset_device(dev);
464
465 /* return -EAGAIN, so the creation of an audio interface for this
466 * temporary device is aborted. The device will reconnect with a
467 * new product ID */
468 return -EAGAIN;
469}
470
471/*
428 * Setup quirks 472 * Setup quirks
429 */ 473 */
430#define AUDIOPHILE_SET 0x01 /* if set, parse device_setup */ 474#define AUDIOPHILE_SET 0x01 /* if set, parse device_setup */
@@ -489,27 +533,35 @@ int snd_usb_apply_boot_quirk(struct usb_device *dev,
489 u32 id = USB_ID(le16_to_cpu(dev->descriptor.idVendor), 533 u32 id = USB_ID(le16_to_cpu(dev->descriptor.idVendor),
490 le16_to_cpu(dev->descriptor.idProduct)); 534 le16_to_cpu(dev->descriptor.idProduct));
491 535
492 /* SB Extigy needs special boot-up sequence */ 536 switch (id) {
493 /* if more models come, this will go to the quirk list. */ 537 case USB_ID(0x041e, 0x3000):
494 if (id == USB_ID(0x041e, 0x3000)) 538 /* SB Extigy needs special boot-up sequence */
539 /* if more models come, this will go to the quirk list. */
495 return snd_usb_extigy_boot_quirk(dev, intf); 540 return snd_usb_extigy_boot_quirk(dev, intf);
496 541
497 /* SB Audigy 2 NX needs its own boot-up magic, too */ 542 case USB_ID(0x041e, 0x3020):
498 if (id == USB_ID(0x041e, 0x3020)) 543 /* SB Audigy 2 NX needs its own boot-up magic, too */
499 return snd_usb_audigy2nx_boot_quirk(dev); 544 return snd_usb_audigy2nx_boot_quirk(dev);
500 545
501 /* C-Media CM106 / Turtle Beach Audio Advantage Roadie */ 546 case USB_ID(0x10f5, 0x0200):
502 if (id == USB_ID(0x10f5, 0x0200)) 547 /* C-Media CM106 / Turtle Beach Audio Advantage Roadie */
503 return snd_usb_cm106_boot_quirk(dev); 548 return snd_usb_cm106_boot_quirk(dev);
504 549
505 /* C-Media CM6206 / CM106-Like Sound Device */ 550 case USB_ID(0x0d8c, 0x0102):
506 if (id == USB_ID(0x0d8c, 0x0102)) 551 /* C-Media CM6206 / CM106-Like Sound Device */
552 case USB_ID(0x0ccd, 0x00b1): /* Terratec Aureon 7.1 USB */
507 return snd_usb_cm6206_boot_quirk(dev); 553 return snd_usb_cm6206_boot_quirk(dev);
508 554
509 /* Access Music VirusTI Desktop */ 555 case USB_ID(0x133e, 0x0815):
510 if (id == USB_ID(0x133e, 0x0815)) 556 /* Access Music VirusTI Desktop */
511 return snd_usb_accessmusic_boot_quirk(dev); 557 return snd_usb_accessmusic_boot_quirk(dev);
512 558
559 case USB_ID(0x17cc, 0x1000): /* Komplete Audio 6 */
560 case USB_ID(0x17cc, 0x1010): /* Traktor Audio 6 */
561 case USB_ID(0x17cc, 0x1020): /* Traktor Audio 10 */
562 return snd_usb_nativeinstruments_boot_quirk(dev);
563 }
564
513 return 0; 565 return 0;
514} 566}
515 567
@@ -532,7 +584,7 @@ int snd_usb_is_big_endian_format(struct snd_usb_audio *chip, struct audioformat
532} 584}
533 585
534/* 586/*
535 * For E-Mu 0404USB/0202USB/TrackerPre sample rate should be set for device, 587 * For E-Mu 0404USB/0202USB/TrackerPre/0204 sample rate should be set for device,
536 * not for interface. 588 * not for interface.
537 */ 589 */
538 590
@@ -589,6 +641,7 @@ void snd_usb_set_format_quirk(struct snd_usb_substream *subs,
589 case USB_ID(0x041e, 0x3f02): /* E-Mu 0202 USB */ 641 case USB_ID(0x041e, 0x3f02): /* E-Mu 0202 USB */
590 case USB_ID(0x041e, 0x3f04): /* E-Mu 0404 USB */ 642 case USB_ID(0x041e, 0x3f04): /* E-Mu 0404 USB */
591 case USB_ID(0x041e, 0x3f0a): /* E-Mu Tracker Pre */ 643 case USB_ID(0x041e, 0x3f0a): /* E-Mu Tracker Pre */
644 case USB_ID(0x041e, 0x3f19): /* E-Mu 0204 USB */
592 set_format_emu_quirk(subs, fmt); 645 set_format_emu_quirk(subs, fmt);
593 break; 646 break;
594 } 647 }
diff --git a/sound/usb/urb.c b/sound/usb/urb.c
index de607d4411ac..e184349aee83 100644
--- a/sound/usb/urb.c
+++ b/sound/usb/urb.c
@@ -225,6 +225,7 @@ int snd_usb_init_substream_urbs(struct snd_usb_substream *subs,
225 else 225 else
226 subs->freqn = get_usb_high_speed_rate(rate); 226 subs->freqn = get_usb_high_speed_rate(rate);
227 subs->freqm = subs->freqn; 227 subs->freqm = subs->freqn;
228 subs->freqshift = INT_MIN;
228 /* calculate max. frequency */ 229 /* calculate max. frequency */
229 if (subs->maxpacksize) { 230 if (subs->maxpacksize) {
230 /* whatever fits into a max. size packet */ 231 /* whatever fits into a max. size packet */
@@ -244,7 +245,7 @@ int snd_usb_init_substream_urbs(struct snd_usb_substream *subs,
244 else 245 else
245 subs->curpacksize = maxsize; 246 subs->curpacksize = maxsize;
246 247
247 if (snd_usb_get_speed(subs->dev) == USB_SPEED_HIGH) 248 if (snd_usb_get_speed(subs->dev) != USB_SPEED_FULL)
248 packs_per_ms = 8 >> subs->datainterval; 249 packs_per_ms = 8 >> subs->datainterval;
249 else 250 else
250 packs_per_ms = 1; 251 packs_per_ms = 1;
@@ -513,11 +514,10 @@ static int retire_paused_capture_urb(struct snd_usb_substream *subs,
513 514
514 515
515/* 516/*
516 * prepare urb for full speed playback sync pipe 517 * prepare urb for playback sync pipe
517 * 518 *
518 * set up the offset and length to receive the current frequency. 519 * set up the offset and length to receive the current frequency.
519 */ 520 */
520
521static int prepare_playback_sync_urb(struct snd_usb_substream *subs, 521static int prepare_playback_sync_urb(struct snd_usb_substream *subs,
522 struct snd_pcm_runtime *runtime, 522 struct snd_pcm_runtime *runtime,
523 struct urb *urb) 523 struct urb *urb)
@@ -525,103 +525,78 @@ static int prepare_playback_sync_urb(struct snd_usb_substream *subs,
525 struct snd_urb_ctx *ctx = urb->context; 525 struct snd_urb_ctx *ctx = urb->context;
526 526
527 urb->dev = ctx->subs->dev; /* we need to set this at each time */ 527 urb->dev = ctx->subs->dev; /* we need to set this at each time */
528 urb->iso_frame_desc[0].length = 3; 528 urb->iso_frame_desc[0].length = min(4u, ctx->subs->syncmaxsize);
529 urb->iso_frame_desc[0].offset = 0; 529 urb->iso_frame_desc[0].offset = 0;
530 return 0; 530 return 0;
531} 531}
532 532
533/* 533/*
534 * prepare urb for high speed playback sync pipe 534 * process after playback sync complete
535 * 535 *
536 * set up the offset and length to receive the current frequency. 536 * Full speed devices report feedback values in 10.14 format as samples per
537 */ 537 * frame, high speed devices in 16.16 format as samples per microframe.
538 538 * Because the Audio Class 1 spec was written before USB 2.0, many high speed
539static int prepare_playback_sync_urb_hs(struct snd_usb_substream *subs, 539 * devices use a wrong interpretation, some others use an entirely different
540 struct snd_pcm_runtime *runtime, 540 * format. Therefore, we cannot predict what format any particular device uses
541 struct urb *urb) 541 * and must detect it automatically.
542{
543 struct snd_urb_ctx *ctx = urb->context;
544
545 urb->dev = ctx->subs->dev; /* we need to set this at each time */
546 urb->iso_frame_desc[0].length = 4;
547 urb->iso_frame_desc[0].offset = 0;
548 return 0;
549}
550
551/*
552 * process after full speed playback sync complete
553 *
554 * retrieve the current 10.14 frequency from pipe, and set it.
555 * the value is referred in prepare_playback_urb().
556 */ 542 */
557static int retire_playback_sync_urb(struct snd_usb_substream *subs, 543static int retire_playback_sync_urb(struct snd_usb_substream *subs,
558 struct snd_pcm_runtime *runtime, 544 struct snd_pcm_runtime *runtime,
559 struct urb *urb) 545 struct urb *urb)
560{ 546{
561 unsigned int f; 547 unsigned int f;
548 int shift;
562 unsigned long flags; 549 unsigned long flags;
563 550
564 if (urb->iso_frame_desc[0].status == 0 && 551 if (urb->iso_frame_desc[0].status != 0 ||
565 urb->iso_frame_desc[0].actual_length == 3) { 552 urb->iso_frame_desc[0].actual_length < 3)
566 f = combine_triple((u8*)urb->transfer_buffer) << 2; 553 return 0;
567 if (f >= subs->freqn - subs->freqn / 8 && f <= subs->freqmax) {
568 spin_lock_irqsave(&subs->lock, flags);
569 subs->freqm = f;
570 spin_unlock_irqrestore(&subs->lock, flags);
571 }
572 }
573
574 return 0;
575}
576 554
577/* 555 f = le32_to_cpup(urb->transfer_buffer);
578 * process after high speed playback sync complete 556 if (urb->iso_frame_desc[0].actual_length == 3)
579 * 557 f &= 0x00ffffff;
580 * retrieve the current 12.13 frequency from pipe, and set it. 558 else
581 * the value is referred in prepare_playback_urb(). 559 f &= 0x0fffffff;
582 */ 560 if (f == 0)
583static int retire_playback_sync_urb_hs(struct snd_usb_substream *subs, 561 return 0;
584 struct snd_pcm_runtime *runtime,
585 struct urb *urb)
586{
587 unsigned int f;
588 unsigned long flags;
589 562
590 if (urb->iso_frame_desc[0].status == 0 && 563 if (unlikely(subs->freqshift == INT_MIN)) {
591 urb->iso_frame_desc[0].actual_length == 4) { 564 /*
592 f = combine_quad((u8*)urb->transfer_buffer) & 0x0fffffff; 565 * The first time we see a feedback value, determine its format
593 if (f >= subs->freqn - subs->freqn / 8 && f <= subs->freqmax) { 566 * by shifting it left or right until it matches the nominal
594 spin_lock_irqsave(&subs->lock, flags); 567 * frequency value. This assumes that the feedback does not
595 subs->freqm = f; 568 * differ from the nominal value more than +50% or -25%.
596 spin_unlock_irqrestore(&subs->lock, flags); 569 */
570 shift = 0;
571 while (f < subs->freqn - subs->freqn / 4) {
572 f <<= 1;
573 shift++;
574 }
575 while (f > subs->freqn + subs->freqn / 2) {
576 f >>= 1;
577 shift--;
597 } 578 }
579 subs->freqshift = shift;
598 } 580 }
581 else if (subs->freqshift >= 0)
582 f <<= subs->freqshift;
583 else
584 f >>= -subs->freqshift;
599 585
600 return 0; 586 if (likely(f >= subs->freqn - subs->freqn / 8 && f <= subs->freqmax)) {
601} 587 /*
602 588 * If the frequency looks valid, set it.
603/* 589 * This value is referred to in prepare_playback_urb().
604 * process after E-Mu 0202/0404/Tracker Pre high speed playback sync complete 590 */
605 * 591 spin_lock_irqsave(&subs->lock, flags);
606 * These devices return the number of samples per packet instead of the number 592 subs->freqm = f;
607 * of samples per microframe. 593 spin_unlock_irqrestore(&subs->lock, flags);
608 */ 594 } else {
609static int retire_playback_sync_urb_hs_emu(struct snd_usb_substream *subs, 595 /*
610 struct snd_pcm_runtime *runtime, 596 * Out of range; maybe the shift value is wrong.
611 struct urb *urb) 597 * Reset it so that we autodetect again the next time.
612{ 598 */
613 unsigned int f; 599 subs->freqshift = INT_MIN;
614 unsigned long flags;
615
616 if (urb->iso_frame_desc[0].status == 0 &&
617 urb->iso_frame_desc[0].actual_length == 4) {
618 f = combine_quad((u8*)urb->transfer_buffer) & 0x0fffffff;
619 f >>= subs->datainterval;
620 if (f >= subs->freqn - subs->freqn / 8 && f <= subs->freqmax) {
621 spin_lock_irqsave(&subs->lock, flags);
622 subs->freqm = f;
623 spin_unlock_irqrestore(&subs->lock, flags);
624 }
625 } 600 }
626 601
627 return 0; 602 return 0;
@@ -878,21 +853,6 @@ static struct snd_urb_ops audio_urb_ops[2] = {
878 }, 853 },
879}; 854};
880 855
881static struct snd_urb_ops audio_urb_ops_high_speed[2] = {
882 {
883 .prepare = prepare_nodata_playback_urb,
884 .retire = retire_playback_urb,
885 .prepare_sync = prepare_playback_sync_urb_hs,
886 .retire_sync = retire_playback_sync_urb_hs,
887 },
888 {
889 .prepare = prepare_capture_urb,
890 .retire = retire_capture_urb,
891 .prepare_sync = prepare_capture_sync_urb_hs,
892 .retire_sync = retire_capture_sync_urb,
893 },
894};
895
896/* 856/*
897 * initialize the substream instance. 857 * initialize the substream instance.
898 */ 858 */
@@ -909,23 +869,9 @@ void snd_usb_init_substream(struct snd_usb_stream *as,
909 subs->direction = stream; 869 subs->direction = stream;
910 subs->dev = as->chip->dev; 870 subs->dev = as->chip->dev;
911 subs->txfr_quirk = as->chip->txfr_quirk; 871 subs->txfr_quirk = as->chip->txfr_quirk;
912 if (snd_usb_get_speed(subs->dev) == USB_SPEED_FULL) { 872 subs->ops = audio_urb_ops[stream];
913 subs->ops = audio_urb_ops[stream]; 873 if (snd_usb_get_speed(subs->dev) >= USB_SPEED_HIGH)
914 } else { 874 subs->ops.prepare_sync = prepare_capture_sync_urb_hs;
915 subs->ops = audio_urb_ops_high_speed[stream];
916 switch (as->chip->usb_id) {
917 case USB_ID(0x041e, 0x3f02): /* E-Mu 0202 USB */
918 case USB_ID(0x041e, 0x3f04): /* E-Mu 0404 USB */
919 case USB_ID(0x041e, 0x3f0a): /* E-Mu Tracker Pre */
920 subs->ops.retire_sync = retire_playback_sync_urb_hs_emu;
921 break;
922 case USB_ID(0x0763, 0x2080): /* M-Audio Fast Track Ultra 8 */
923 case USB_ID(0x0763, 0x2081): /* M-Audio Fast Track Ultra 8R */
924 subs->ops.prepare_sync = prepare_playback_sync_urb;
925 subs->ops.retire_sync = retire_playback_sync_urb;
926 break;
927 }
928 }
929 875
930 snd_usb_set_pcm_ops(as->pcm, stream); 876 snd_usb_set_pcm_ops(as->pcm, stream);
931 877
diff --git a/sound/usb/usbaudio.h b/sound/usb/usbaudio.h
index 24d3319cc34d..1e79986b5777 100644
--- a/sound/usb/usbaudio.h
+++ b/sound/usb/usbaudio.h
@@ -34,9 +34,14 @@ struct snd_usb_audio {
34 int index; 34 int index;
35 struct usb_device *dev; 35 struct usb_device *dev;
36 struct snd_card *card; 36 struct snd_card *card;
37 struct usb_interface *pm_intf;
37 u32 usb_id; 38 u32 usb_id;
38 int shutdown; 39 struct mutex shutdown_mutex;
40 unsigned int shutdown:1;
41 unsigned int probing:1;
42 unsigned int autosuspended:1;
39 unsigned int txfr_quirk:1; /* Subframe boundaries on transfers */ 43 unsigned int txfr_quirk:1; /* Subframe boundaries on transfers */
44
40 int num_interfaces; 45 int num_interfaces;
41 int num_suspended_intf; 46 int num_suspended_intf;
42 47
@@ -70,7 +75,7 @@ enum quirk_type {
70 QUIRK_MIDI_YAMAHA, 75 QUIRK_MIDI_YAMAHA,
71 QUIRK_MIDI_MIDIMAN, 76 QUIRK_MIDI_MIDIMAN,
72 QUIRK_MIDI_NOVATION, 77 QUIRK_MIDI_NOVATION,
73 QUIRK_MIDI_FASTLANE, 78 QUIRK_MIDI_RAW_BYTES,
74 QUIRK_MIDI_EMAGIC, 79 QUIRK_MIDI_EMAGIC,
75 QUIRK_MIDI_CME, 80 QUIRK_MIDI_CME,
76 QUIRK_MIDI_AKAI, 81 QUIRK_MIDI_AKAI,
@@ -79,6 +84,7 @@ enum quirk_type {
79 QUIRK_AUDIO_FIXED_ENDPOINT, 84 QUIRK_AUDIO_FIXED_ENDPOINT,
80 QUIRK_AUDIO_EDIROL_UAXX, 85 QUIRK_AUDIO_EDIROL_UAXX,
81 QUIRK_AUDIO_ALIGN_TRANSFER, 86 QUIRK_AUDIO_ALIGN_TRANSFER,
87 QUIRK_AUDIO_STANDARD_MIXER,
82 88
83 QUIRK_TYPE_COUNT 89 QUIRK_TYPE_COUNT
84}; 90};
diff --git a/sound/usb/usx2y/us122l.c b/sound/usb/usx2y/us122l.c
index 6ef68e42138e..084e6fc8d5bf 100644
--- a/sound/usb/usx2y/us122l.c
+++ b/sound/usb/usx2y/us122l.c
@@ -273,29 +273,26 @@ static unsigned int usb_stream_hwdep_poll(struct snd_hwdep *hw,
273 struct file *file, poll_table *wait) 273 struct file *file, poll_table *wait)
274{ 274{
275 struct us122l *us122l = hw->private_data; 275 struct us122l *us122l = hw->private_data;
276 struct usb_stream *s = us122l->sk.s;
277 unsigned *polled; 276 unsigned *polled;
278 unsigned int mask; 277 unsigned int mask;
279 278
280 poll_wait(file, &us122l->sk.sleep, wait); 279 poll_wait(file, &us122l->sk.sleep, wait);
281 280
282 switch (s->state) { 281 mask = POLLIN | POLLOUT | POLLWRNORM | POLLERR;
283 case usb_stream_ready: 282 if (mutex_trylock(&us122l->mutex)) {
284 if (us122l->first == file) 283 struct usb_stream *s = us122l->sk.s;
285 polled = &s->periods_polled; 284 if (s && s->state == usb_stream_ready) {
286 else 285 if (us122l->first == file)
287 polled = &us122l->second_periods_polled; 286 polled = &s->periods_polled;
288 if (*polled != s->periods_done) { 287 else
289 *polled = s->periods_done; 288 polled = &us122l->second_periods_polled;
290 mask = POLLIN | POLLOUT | POLLWRNORM; 289 if (*polled != s->periods_done) {
291 break; 290 *polled = s->periods_done;
291 mask = POLLIN | POLLOUT | POLLWRNORM;
292 } else
293 mask = 0;
292 } 294 }
293 /* Fall through */ 295 mutex_unlock(&us122l->mutex);
294 mask = 0;
295 break;
296 default:
297 mask = POLLIN | POLLOUT | POLLWRNORM | POLLERR;
298 break;
299 } 296 }
300 return mask; 297 return mask;
301} 298}
@@ -381,6 +378,7 @@ static int usb_stream_hwdep_ioctl(struct snd_hwdep *hw, struct file *file,
381{ 378{
382 struct usb_stream_config *cfg; 379 struct usb_stream_config *cfg;
383 struct us122l *us122l = hw->private_data; 380 struct us122l *us122l = hw->private_data;
381 struct usb_stream *s;
384 unsigned min_period_frames; 382 unsigned min_period_frames;
385 int err = 0; 383 int err = 0;
386 bool high_speed; 384 bool high_speed;
@@ -426,18 +424,18 @@ static int usb_stream_hwdep_ioctl(struct snd_hwdep *hw, struct file *file,
426 snd_power_wait(hw->card, SNDRV_CTL_POWER_D0); 424 snd_power_wait(hw->card, SNDRV_CTL_POWER_D0);
427 425
428 mutex_lock(&us122l->mutex); 426 mutex_lock(&us122l->mutex);
427 s = us122l->sk.s;
429 if (!us122l->master) 428 if (!us122l->master)
430 us122l->master = file; 429 us122l->master = file;
431 else if (us122l->master != file) { 430 else if (us122l->master != file) {
432 if (memcmp(cfg, &us122l->sk.s->cfg, sizeof(*cfg))) { 431 if (!s || memcmp(cfg, &s->cfg, sizeof(*cfg))) {
433 err = -EIO; 432 err = -EIO;
434 goto unlock; 433 goto unlock;
435 } 434 }
436 us122l->slave = file; 435 us122l->slave = file;
437 } 436 }
438 if (!us122l->sk.s || 437 if (!s || memcmp(cfg, &s->cfg, sizeof(*cfg)) ||
439 memcmp(cfg, &us122l->sk.s->cfg, sizeof(*cfg)) || 438 s->state == usb_stream_xrun) {
440 us122l->sk.s->state == usb_stream_xrun) {
441 us122l_stop(us122l); 439 us122l_stop(us122l);
442 if (!us122l_start(us122l, cfg->sample_rate, cfg->period_frames)) 440 if (!us122l_start(us122l, cfg->sample_rate, cfg->period_frames))
443 err = -EIO; 441 err = -EIO;
@@ -448,6 +446,7 @@ unlock:
448 mutex_unlock(&us122l->mutex); 446 mutex_unlock(&us122l->mutex);
449free: 447free:
450 kfree(cfg); 448 kfree(cfg);
449 wake_up_all(&us122l->sk.sleep);
451 return err; 450 return err;
452} 451}
453 452
diff --git a/sound/usb/usx2y/usx2yhwdeppcm.c b/sound/usb/usx2y/usx2yhwdeppcm.c
index 2a528e56afd5..a51340f6f2db 100644
--- a/sound/usb/usx2y/usx2yhwdeppcm.c
+++ b/sound/usb/usx2y/usx2yhwdeppcm.c
@@ -20,7 +20,7 @@
20 at standard samplerates, 20 at standard samplerates,
21 what led to this part of the usx2y module: 21 what led to this part of the usx2y module:
22 It provides the alsa kernel half of the usx2y-alsa-jack driver pair. 22 It provides the alsa kernel half of the usx2y-alsa-jack driver pair.
23 The pair uses a hardware dependant alsa-device for mmaped pcm transport. 23 The pair uses a hardware dependent alsa-device for mmaped pcm transport.
24 Advantage achieved: 24 Advantage achieved:
25 The usb_hc moves pcm data from/into memory via DMA. 25 The usb_hc moves pcm data from/into memory via DMA.
26 That memory is mmaped by jack's usx2y driver. 26 That memory is mmaped by jack's usx2y driver.
@@ -36,9 +36,9 @@
36 plain usx2y alsa mode is able to achieve 64frames, 4periods, but only at the 36 plain usx2y alsa mode is able to achieve 64frames, 4periods, but only at the
37 cost of easier triggered i.e. aeolus xruns (128 or 256frames, 37 cost of easier triggered i.e. aeolus xruns (128 or 256frames,
38 2periods works but is useless cause of crackling). 38 2periods works but is useless cause of crackling).
39 39
40 This is a first "proof of concept" implementation. 40 This is a first "proof of concept" implementation.
41 Later, funcionalities should migrate to more apropriate places: 41 Later, functionalities should migrate to more appropriate places:
42 Userland: 42 Userland:
43 - The jackd could mmap its float-pcm buffers directly from alsa-lib. 43 - The jackd could mmap its float-pcm buffers directly from alsa-lib.
44 - alsa-lib could provide power of 2 period sized shaping combined with int/float 44 - alsa-lib could provide power of 2 period sized shaping combined with int/float
@@ -54,7 +54,7 @@
54#include <linux/gfp.h> 54#include <linux/gfp.h>
55#include "usbusx2yaudio.c" 55#include "usbusx2yaudio.c"
56 56
57#if defined(USX2Y_NRPACKS_VARIABLE) || (!defined(USX2Y_NRPACKS_VARIABLE) && USX2Y_NRPACKS == 1) 57#if defined(USX2Y_NRPACKS_VARIABLE) || USX2Y_NRPACKS == 1
58 58
59#include <sound/hwdep.h> 59#include <sound/hwdep.h>
60 60