aboutsummaryrefslogtreecommitdiffstats
path: root/sound/usb/caiaq
diff options
context:
space:
mode:
Diffstat (limited to 'sound/usb/caiaq')
-rw-r--r--sound/usb/caiaq/audio.c1
-rw-r--r--sound/usb/caiaq/control.c99
-rw-r--r--sound/usb/caiaq/device.c17
-rw-r--r--sound/usb/caiaq/device.h24
-rw-r--r--sound/usb/caiaq/input.c163
-rw-r--r--sound/usb/caiaq/midi.c1
6 files changed, 239 insertions, 66 deletions
diff --git a/sound/usb/caiaq/audio.c b/sound/usb/caiaq/audio.c
index 86b2c3b92df5..4328cad6c3a2 100644
--- a/sound/usb/caiaq/audio.c
+++ b/sound/usb/caiaq/audio.c
@@ -17,6 +17,7 @@
17*/ 17*/
18 18
19#include <linux/spinlock.h> 19#include <linux/spinlock.h>
20#include <linux/slab.h>
20#include <linux/init.h> 21#include <linux/init.h>
21#include <linux/usb.h> 22#include <linux/usb.h>
22#include <sound/core.h> 23#include <sound/core.h>
diff --git a/sound/usb/caiaq/control.c b/sound/usb/caiaq/control.c
index 537102ba6b9d..91c804cd2782 100644
--- a/sound/usb/caiaq/control.c
+++ b/sound/usb/caiaq/control.c
@@ -35,33 +35,32 @@ static int control_info(struct snd_kcontrol *kcontrol,
35 struct snd_usb_caiaqdev *dev = caiaqdev(chip->card); 35 struct snd_usb_caiaqdev *dev = caiaqdev(chip->card);
36 int pos = kcontrol->private_value; 36 int pos = kcontrol->private_value;
37 int is_intval = pos & CNT_INTVAL; 37 int is_intval = pos & CNT_INTVAL;
38 unsigned int id = dev->chip.usb_id; 38 int maxval = 63;
39 39
40 uinfo->count = 1; 40 uinfo->count = 1;
41 pos &= ~CNT_INTVAL; 41 pos &= ~CNT_INTVAL;
42 42
43 if (id == USB_ID(USB_VID_NATIVEINSTRUMENTS, USB_PID_AUDIO8DJ) 43 switch (dev->chip.usb_id) {
44 && (pos == 0)) { 44 case USB_ID(USB_VID_NATIVEINSTRUMENTS, USB_PID_AUDIO8DJ):
45 /* current input mode of A8DJ */ 45 case USB_ID(USB_VID_NATIVEINSTRUMENTS, USB_PID_AUDIO4DJ):
46 uinfo->type = SNDRV_CTL_ELEM_TYPE_INTEGER; 46 if (pos == 0) {
47 uinfo->value.integer.min = 0; 47 /* current input mode of A8DJ and A4DJ */
48 uinfo->value.integer.max = 2; 48 uinfo->type = SNDRV_CTL_ELEM_TYPE_INTEGER;
49 return 0; 49 uinfo->value.integer.min = 0;
50 } 50 uinfo->value.integer.max = 2;
51 return 0;
52 }
53 break;
51 54
52 if (id == USB_ID(USB_VID_NATIVEINSTRUMENTS, USB_PID_AUDIO4DJ) 55 case USB_ID(USB_VID_NATIVEINSTRUMENTS, USB_PID_TRAKTORKONTROLX1):
53 && (pos == 0)) { 56 maxval = 127;
54 /* current input mode of A4DJ */ 57 break;
55 uinfo->type = SNDRV_CTL_ELEM_TYPE_INTEGER;
56 uinfo->value.integer.min = 0;
57 uinfo->value.integer.max = 1;
58 return 0;
59 } 58 }
60 59
61 if (is_intval) { 60 if (is_intval) {
62 uinfo->type = SNDRV_CTL_ELEM_TYPE_INTEGER; 61 uinfo->type = SNDRV_CTL_ELEM_TYPE_INTEGER;
63 uinfo->value.integer.min = 0; 62 uinfo->value.integer.min = 0;
64 uinfo->value.integer.max = 64; 63 uinfo->value.integer.max = maxval;
65 } else { 64 } else {
66 uinfo->type = SNDRV_CTL_ELEM_TYPE_BOOLEAN; 65 uinfo->type = SNDRV_CTL_ELEM_TYPE_BOOLEAN;
67 uinfo->value.integer.min = 0; 66 uinfo->value.integer.min = 0;
@@ -78,14 +77,6 @@ static int control_get(struct snd_kcontrol *kcontrol,
78 struct snd_usb_caiaqdev *dev = caiaqdev(chip->card); 77 struct snd_usb_caiaqdev *dev = caiaqdev(chip->card);
79 int pos = kcontrol->private_value; 78 int pos = kcontrol->private_value;
80 79
81 if (dev->chip.usb_id ==
82 USB_ID(USB_VID_NATIVEINSTRUMENTS, USB_PID_AUDIO4DJ)) {
83 /* A4DJ has only one control */
84 /* do not expose hardware input mode 0 */
85 ucontrol->value.integer.value[0] = dev->control_state[0] - 1;
86 return 0;
87 }
88
89 if (pos & CNT_INTVAL) 80 if (pos & CNT_INTVAL)
90 ucontrol->value.integer.value[0] 81 ucontrol->value.integer.value[0]
91 = dev->control_state[pos & ~CNT_INTVAL]; 82 = dev->control_state[pos & ~CNT_INTVAL];
@@ -102,21 +93,16 @@ static int control_put(struct snd_kcontrol *kcontrol,
102 struct snd_usb_audio *chip = snd_kcontrol_chip(kcontrol); 93 struct snd_usb_audio *chip = snd_kcontrol_chip(kcontrol);
103 struct snd_usb_caiaqdev *dev = caiaqdev(chip->card); 94 struct snd_usb_caiaqdev *dev = caiaqdev(chip->card);
104 int pos = kcontrol->private_value; 95 int pos = kcontrol->private_value;
96 unsigned char cmd = EP1_CMD_WRITE_IO;
105 97
106 if (dev->chip.usb_id == 98 if (dev->chip.usb_id ==
107 USB_ID(USB_VID_NATIVEINSTRUMENTS, USB_PID_AUDIO4DJ)) { 99 USB_ID(USB_VID_NATIVEINSTRUMENTS, USB_PID_TRAKTORKONTROLX1))
108 /* A4DJ has only one control */ 100 cmd = EP1_CMD_DIMM_LEDS;
109 /* do not expose hardware input mode 0 */
110 dev->control_state[0] = ucontrol->value.integer.value[0] + 1;
111 snd_usb_caiaq_send_command(dev, EP1_CMD_WRITE_IO,
112 dev->control_state, sizeof(dev->control_state));
113 return 1;
114 }
115 101
116 if (pos & CNT_INTVAL) { 102 if (pos & CNT_INTVAL) {
117 dev->control_state[pos & ~CNT_INTVAL] 103 dev->control_state[pos & ~CNT_INTVAL]
118 = ucontrol->value.integer.value[0]; 104 = ucontrol->value.integer.value[0];
119 snd_usb_caiaq_send_command(dev, EP1_CMD_WRITE_IO, 105 snd_usb_caiaq_send_command(dev, cmd,
120 dev->control_state, sizeof(dev->control_state)); 106 dev->control_state, sizeof(dev->control_state));
121 } else { 107 } else {
122 if (ucontrol->value.integer.value[0]) 108 if (ucontrol->value.integer.value[0])
@@ -124,7 +110,7 @@ static int control_put(struct snd_kcontrol *kcontrol,
124 else 110 else
125 dev->control_state[pos / 8] &= ~(1 << (pos % 8)); 111 dev->control_state[pos / 8] &= ~(1 << (pos % 8));
126 112
127 snd_usb_caiaq_send_command(dev, EP1_CMD_WRITE_IO, 113 snd_usb_caiaq_send_command(dev, cmd,
128 dev->control_state, sizeof(dev->control_state)); 114 dev->control_state, sizeof(dev->control_state));
129 } 115 }
130 116
@@ -273,6 +259,43 @@ static struct caiaq_controller a4dj_controller[] = {
273 { "Current input mode", 0 | CNT_INTVAL } 259 { "Current input mode", 0 | CNT_INTVAL }
274}; 260};
275 261
262static struct caiaq_controller kontrolx1_controller[] = {
263 { "LED FX A: ON", 7 | CNT_INTVAL },
264 { "LED FX A: 1", 6 | CNT_INTVAL },
265 { "LED FX A: 2", 5 | CNT_INTVAL },
266 { "LED FX A: 3", 4 | CNT_INTVAL },
267 { "LED FX B: ON", 3 | CNT_INTVAL },
268 { "LED FX B: 1", 2 | CNT_INTVAL },
269 { "LED FX B: 2", 1 | CNT_INTVAL },
270 { "LED FX B: 3", 0 | CNT_INTVAL },
271
272 { "LED Hotcue", 28 | CNT_INTVAL },
273 { "LED Shift (white)", 29 | CNT_INTVAL },
274 { "LED Shift (green)", 30 | CNT_INTVAL },
275
276 { "LED Deck A: FX1", 24 | CNT_INTVAL },
277 { "LED Deck A: FX2", 25 | CNT_INTVAL },
278 { "LED Deck A: IN", 17 | CNT_INTVAL },
279 { "LED Deck A: OUT", 16 | CNT_INTVAL },
280 { "LED Deck A: < BEAT", 19 | CNT_INTVAL },
281 { "LED Deck A: BEAT >", 18 | CNT_INTVAL },
282 { "LED Deck A: CUE/ABS", 21 | CNT_INTVAL },
283 { "LED Deck A: CUP/REL", 20 | CNT_INTVAL },
284 { "LED Deck A: PLAY", 23 | CNT_INTVAL },
285 { "LED Deck A: SYNC", 22 | CNT_INTVAL },
286
287 { "LED Deck B: FX1", 26 | CNT_INTVAL },
288 { "LED Deck B: FX2", 27 | CNT_INTVAL },
289 { "LED Deck B: IN", 15 | CNT_INTVAL },
290 { "LED Deck B: OUT", 14 | CNT_INTVAL },
291 { "LED Deck B: < BEAT", 13 | CNT_INTVAL },
292 { "LED Deck B: BEAT >", 12 | CNT_INTVAL },
293 { "LED Deck B: CUE/ABS", 11 | CNT_INTVAL },
294 { "LED Deck B: CUP/REL", 10 | CNT_INTVAL },
295 { "LED Deck B: PLAY", 9 | CNT_INTVAL },
296 { "LED Deck B: SYNC", 8 | CNT_INTVAL },
297};
298
276static int __devinit add_controls(struct caiaq_controller *c, int num, 299static int __devinit add_controls(struct caiaq_controller *c, int num,
277 struct snd_usb_caiaqdev *dev) 300 struct snd_usb_caiaqdev *dev)
278{ 301{
@@ -321,10 +344,16 @@ int __devinit snd_usb_caiaq_control_init(struct snd_usb_caiaqdev *dev)
321 ret = add_controls(a8dj_controller, 344 ret = add_controls(a8dj_controller,
322 ARRAY_SIZE(a8dj_controller), dev); 345 ARRAY_SIZE(a8dj_controller), dev);
323 break; 346 break;
347
324 case USB_ID(USB_VID_NATIVEINSTRUMENTS, USB_PID_AUDIO4DJ): 348 case USB_ID(USB_VID_NATIVEINSTRUMENTS, USB_PID_AUDIO4DJ):
325 ret = add_controls(a4dj_controller, 349 ret = add_controls(a4dj_controller,
326 ARRAY_SIZE(a4dj_controller), dev); 350 ARRAY_SIZE(a4dj_controller), dev);
327 break; 351 break;
352
353 case USB_ID(USB_VID_NATIVEINSTRUMENTS, USB_PID_TRAKTORKONTROLX1):
354 ret = add_controls(kontrolx1_controller,
355 ARRAY_SIZE(kontrolx1_controller), dev);
356 break;
328 } 357 }
329 358
330 return ret; 359 return ret;
diff --git a/sound/usb/caiaq/device.c b/sound/usb/caiaq/device.c
index a3f02dd97440..cdfb856bddd2 100644
--- a/sound/usb/caiaq/device.c
+++ b/sound/usb/caiaq/device.c
@@ -23,6 +23,7 @@
23#include <linux/interrupt.h> 23#include <linux/interrupt.h>
24#include <linux/module.h> 24#include <linux/module.h>
25#include <linux/init.h> 25#include <linux/init.h>
26#include <linux/gfp.h>
26#include <linux/usb.h> 27#include <linux/usb.h>
27#include <sound/initval.h> 28#include <sound/initval.h>
28#include <sound/core.h> 29#include <sound/core.h>
@@ -35,7 +36,7 @@
35#include "input.h" 36#include "input.h"
36 37
37MODULE_AUTHOR("Daniel Mack <daniel@caiaq.de>"); 38MODULE_AUTHOR("Daniel Mack <daniel@caiaq.de>");
38MODULE_DESCRIPTION("caiaq USB audio, version 1.3.20"); 39MODULE_DESCRIPTION("caiaq USB audio, version 1.3.21");
39MODULE_LICENSE("GPL"); 40MODULE_LICENSE("GPL");
40MODULE_SUPPORTED_DEVICE("{{Native Instruments, RigKontrol2}," 41MODULE_SUPPORTED_DEVICE("{{Native Instruments, RigKontrol2},"
41 "{Native Instruments, RigKontrol3}," 42 "{Native Instruments, RigKontrol3},"
@@ -46,7 +47,8 @@ MODULE_SUPPORTED_DEVICE("{{Native Instruments, RigKontrol2},"
46 "{Native Instruments, Audio 4 DJ}," 47 "{Native Instruments, Audio 4 DJ},"
47 "{Native Instruments, Audio 8 DJ}," 48 "{Native Instruments, Audio 8 DJ},"
48 "{Native Instruments, Session I/O}," 49 "{Native Instruments, Session I/O},"
49 "{Native Instruments, GuitarRig mobile}"); 50 "{Native Instruments, GuitarRig mobile}"
51 "{Native Instruments, Traktor Kontrol X1}");
50 52
51static int index[SNDRV_CARDS] = SNDRV_DEFAULT_IDX; /* Index 0-max */ 53static int index[SNDRV_CARDS] = SNDRV_DEFAULT_IDX; /* Index 0-max */
52static char* id[SNDRV_CARDS] = SNDRV_DEFAULT_STR; /* Id for this card */ 54static char* id[SNDRV_CARDS] = SNDRV_DEFAULT_STR; /* Id for this card */
@@ -127,6 +129,11 @@ static struct usb_device_id snd_usb_id_table[] = {
127 .idVendor = USB_VID_NATIVEINSTRUMENTS, 129 .idVendor = USB_VID_NATIVEINSTRUMENTS,
128 .idProduct = USB_PID_AUDIO2DJ 130 .idProduct = USB_PID_AUDIO2DJ
129 }, 131 },
132 {
133 .match_flags = USB_DEVICE_ID_MATCH_DEVICE,
134 .idVendor = USB_VID_NATIVEINSTRUMENTS,
135 .idProduct = USB_PID_TRAKTORKONTROLX1
136 },
130 { /* terminator */ } 137 { /* terminator */ }
131}; 138};
132 139
@@ -313,12 +320,6 @@ static void __devinit setup_card(struct snd_usb_caiaqdev *dev)
313 } 320 }
314 321
315 break; 322 break;
316 case USB_ID(USB_VID_NATIVEINSTRUMENTS, USB_PID_AUDIO4DJ):
317 /* Audio 4 DJ - default input mode to phono */
318 dev->control_state[0] = 2;
319 snd_usb_caiaq_send_command(dev, EP1_CMD_WRITE_IO,
320 dev->control_state, 1);
321 break;
322 } 323 }
323 324
324 if (dev->spec.num_analog_audio_out + 325 if (dev->spec.num_analog_audio_out +
diff --git a/sound/usb/caiaq/device.h b/sound/usb/caiaq/device.h
index 44e3edf88bef..f1117ecc84fd 100644
--- a/sound/usb/caiaq/device.h
+++ b/sound/usb/caiaq/device.h
@@ -5,18 +5,20 @@
5 5
6#define USB_VID_NATIVEINSTRUMENTS 0x17cc 6#define USB_VID_NATIVEINSTRUMENTS 0x17cc
7 7
8#define USB_PID_RIGKONTROL2 0x1969 8#define USB_PID_RIGKONTROL2 0x1969
9#define USB_PID_RIGKONTROL3 0x1940 9#define USB_PID_RIGKONTROL3 0x1940
10#define USB_PID_KORECONTROLLER 0x4711 10#define USB_PID_KORECONTROLLER 0x4711
11#define USB_PID_KORECONTROLLER2 0x4712 11#define USB_PID_KORECONTROLLER2 0x4712
12#define USB_PID_AK1 0x0815 12#define USB_PID_AK1 0x0815
13#define USB_PID_AUDIO2DJ 0x041c 13#define USB_PID_AUDIO2DJ 0x041c
14#define USB_PID_AUDIO4DJ 0x0839 14#define USB_PID_AUDIO4DJ 0x0839
15#define USB_PID_AUDIO8DJ 0x1978 15#define USB_PID_AUDIO8DJ 0x1978
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 19
19#define EP1_BUFSIZE 64 20#define EP1_BUFSIZE 64
21#define EP4_BUFSIZE 512
20#define CAIAQ_USB_STR_LEN 0xff 22#define CAIAQ_USB_STR_LEN 0xff
21#define MAX_STREAMS 32 23#define MAX_STREAMS 32
22 24
@@ -104,6 +106,8 @@ struct snd_usb_caiaqdev {
104 struct input_dev *input_dev; 106 struct input_dev *input_dev;
105 char phys[64]; /* physical device path */ 107 char phys[64]; /* physical device path */
106 unsigned short keycode[64]; 108 unsigned short keycode[64];
109 struct urb *ep4_in_urb;
110 unsigned char ep4_in_buf[EP4_BUFSIZE];
107#endif 111#endif
108 112
109 /* ALSA */ 113 /* ALSA */
diff --git a/sound/usb/caiaq/input.c b/sound/usb/caiaq/input.c
index a48d309bd94c..dcb620796d9e 100644
--- a/sound/usb/caiaq/input.c
+++ b/sound/usb/caiaq/input.c
@@ -16,9 +16,11 @@
16 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 16 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17*/ 17*/
18 18
19#include <linux/gfp.h>
19#include <linux/init.h> 20#include <linux/init.h>
20#include <linux/usb.h> 21#include <linux/usb.h>
21#include <linux/usb/input.h> 22#include <linux/usb/input.h>
23#include <sound/core.h>
22#include <sound/pcm.h> 24#include <sound/pcm.h>
23 25
24#include "device.h" 26#include "device.h"
@@ -65,6 +67,8 @@ static unsigned short keycode_kore[] = {
65 KEY_BRL_DOT5 67 KEY_BRL_DOT5
66}; 68};
67 69
70#define KONTROLX1_INPUTS 40
71
68#define DEG90 (range / 2) 72#define DEG90 (range / 2)
69#define DEG180 (range) 73#define DEG180 (range)
70#define DEG270 (DEG90 + DEG180) 74#define DEG270 (DEG90 + DEG180)
@@ -162,6 +166,17 @@ static void snd_caiaq_input_read_analog(struct snd_usb_caiaqdev *dev,
162 input_report_abs(input_dev, ABS_Z, (buf[4] << 8) | buf[5]); 166 input_report_abs(input_dev, ABS_Z, (buf[4] << 8) | buf[5]);
163 input_sync(input_dev); 167 input_sync(input_dev);
164 break; 168 break;
169 case USB_ID(USB_VID_NATIVEINSTRUMENTS, USB_PID_TRAKTORKONTROLX1):
170 input_report_abs(input_dev, ABS_HAT0X, (buf[8] << 8) | buf[9]);
171 input_report_abs(input_dev, ABS_HAT0Y, (buf[4] << 8) | buf[5]);
172 input_report_abs(input_dev, ABS_HAT1X, (buf[12] << 8) | buf[13]);
173 input_report_abs(input_dev, ABS_HAT1Y, (buf[2] << 8) | buf[3]);
174 input_report_abs(input_dev, ABS_HAT2X, (buf[14] << 8) | buf[15]);
175 input_report_abs(input_dev, ABS_HAT2Y, (buf[0] << 8) | buf[1]);
176 input_report_abs(input_dev, ABS_HAT3X, (buf[10] << 8) | buf[11]);
177 input_report_abs(input_dev, ABS_HAT3Y, (buf[6] << 8) | buf[7]);
178 input_sync(input_dev);
179 break;
165 } 180 }
166} 181}
167 182
@@ -201,7 +216,7 @@ static void snd_caiaq_input_read_erp(struct snd_usb_caiaqdev *dev,
201} 216}
202 217
203static void snd_caiaq_input_read_io(struct snd_usb_caiaqdev *dev, 218static void snd_caiaq_input_read_io(struct snd_usb_caiaqdev *dev,
204 char *buf, unsigned int len) 219 unsigned char *buf, unsigned int len)
205{ 220{
206 struct input_dev *input_dev = dev->input_dev; 221 struct input_dev *input_dev = dev->input_dev;
207 unsigned short *keycode = input_dev->keycode; 222 unsigned short *keycode = input_dev->keycode;
@@ -218,15 +233,84 @@ static void snd_caiaq_input_read_io(struct snd_usb_caiaqdev *dev,
218 input_report_key(input_dev, keycode[i], 233 input_report_key(input_dev, keycode[i],
219 buf[i / 8] & (1 << (i % 8))); 234 buf[i / 8] & (1 << (i % 8)));
220 235
221 if (dev->chip.usb_id == 236 switch (dev->chip.usb_id) {
222 USB_ID(USB_VID_NATIVEINSTRUMENTS, USB_PID_KORECONTROLLER) || 237 case USB_ID(USB_VID_NATIVEINSTRUMENTS, USB_PID_KORECONTROLLER):
223 dev->chip.usb_id == 238 case USB_ID(USB_VID_NATIVEINSTRUMENTS, USB_PID_KORECONTROLLER2):
224 USB_ID(USB_VID_NATIVEINSTRUMENTS, USB_PID_KORECONTROLLER2))
225 input_report_abs(dev->input_dev, ABS_MISC, 255 - buf[4]); 239 input_report_abs(dev->input_dev, ABS_MISC, 255 - buf[4]);
240 break;
241 case USB_ID(USB_VID_NATIVEINSTRUMENTS, USB_PID_TRAKTORKONTROLX1):
242 /* rotary encoders */
243 input_report_abs(dev->input_dev, ABS_X, buf[5] & 0xf);
244 input_report_abs(dev->input_dev, ABS_Y, buf[5] >> 4);
245 input_report_abs(dev->input_dev, ABS_Z, buf[6] & 0xf);
246 input_report_abs(dev->input_dev, ABS_MISC, buf[6] >> 4);
247 break;
248 }
226 249
227 input_sync(input_dev); 250 input_sync(input_dev);
228} 251}
229 252
253static void snd_usb_caiaq_ep4_reply_dispatch(struct urb *urb)
254{
255 struct snd_usb_caiaqdev *dev = urb->context;
256 unsigned char *buf = urb->transfer_buffer;
257 int ret;
258
259 if (urb->status || !dev || urb != dev->ep4_in_urb)
260 return;
261
262 if (urb->actual_length < 24)
263 goto requeue;
264
265 switch (dev->chip.usb_id) {
266 case USB_ID(USB_VID_NATIVEINSTRUMENTS, USB_PID_TRAKTORKONTROLX1):
267 if (buf[0] & 0x3)
268 snd_caiaq_input_read_io(dev, buf + 1, 7);
269
270 if (buf[0] & 0x4)
271 snd_caiaq_input_read_analog(dev, buf + 8, 16);
272
273 break;
274 }
275
276requeue:
277 dev->ep4_in_urb->actual_length = 0;
278 ret = usb_submit_urb(dev->ep4_in_urb, GFP_ATOMIC);
279 if (ret < 0)
280 log("unable to submit urb. OOM!?\n");
281}
282
283static int snd_usb_caiaq_input_open(struct input_dev *idev)
284{
285 struct snd_usb_caiaqdev *dev = input_get_drvdata(idev);
286
287 if (!dev)
288 return -EINVAL;
289
290 switch (dev->chip.usb_id) {
291 case USB_ID(USB_VID_NATIVEINSTRUMENTS, USB_PID_TRAKTORKONTROLX1):
292 if (usb_submit_urb(dev->ep4_in_urb, GFP_KERNEL) != 0)
293 return -EIO;
294 break;
295 }
296
297 return 0;
298}
299
300static void snd_usb_caiaq_input_close(struct input_dev *idev)
301{
302 struct snd_usb_caiaqdev *dev = input_get_drvdata(idev);
303
304 if (!dev)
305 return;
306
307 switch (dev->chip.usb_id) {
308 case USB_ID(USB_VID_NATIVEINSTRUMENTS, USB_PID_TRAKTORKONTROLX1):
309 usb_kill_urb(dev->ep4_in_urb);
310 break;
311 }
312}
313
230void snd_usb_caiaq_input_dispatch(struct snd_usb_caiaqdev *dev, 314void snd_usb_caiaq_input_dispatch(struct snd_usb_caiaqdev *dev,
231 char *buf, 315 char *buf,
232 unsigned int len) 316 unsigned int len)
@@ -251,7 +335,7 @@ int snd_usb_caiaq_input_init(struct snd_usb_caiaqdev *dev)
251{ 335{
252 struct usb_device *usb_dev = dev->chip.dev; 336 struct usb_device *usb_dev = dev->chip.dev;
253 struct input_dev *input; 337 struct input_dev *input;
254 int i, ret; 338 int i, ret = 0;
255 339
256 input = input_allocate_device(); 340 input = input_allocate_device();
257 if (!input) 341 if (!input)
@@ -265,7 +349,9 @@ int snd_usb_caiaq_input_init(struct snd_usb_caiaqdev *dev)
265 usb_to_input_id(usb_dev, &input->id); 349 usb_to_input_id(usb_dev, &input->id);
266 input->dev.parent = &usb_dev->dev; 350 input->dev.parent = &usb_dev->dev;
267 351
268 switch (dev->chip.usb_id) { 352 input_set_drvdata(input, dev);
353
354 switch (dev->chip.usb_id) {
269 case USB_ID(USB_VID_NATIVEINSTRUMENTS, USB_PID_RIGKONTROL2): 355 case USB_ID(USB_VID_NATIVEINSTRUMENTS, USB_PID_RIGKONTROL2):
270 input->evbit[0] = BIT_MASK(EV_KEY) | BIT_MASK(EV_ABS); 356 input->evbit[0] = BIT_MASK(EV_KEY) | BIT_MASK(EV_ABS);
271 input->absbit[0] = BIT_MASK(ABS_X) | BIT_MASK(ABS_Y) | 357 input->absbit[0] = BIT_MASK(ABS_X) | BIT_MASK(ABS_Y) |
@@ -326,25 +412,72 @@ int snd_usb_caiaq_input_init(struct snd_usb_caiaqdev *dev)
326 input_set_abs_params(input, ABS_MISC, 0, 255, 0, 1); 412 input_set_abs_params(input, ABS_MISC, 0, 255, 0, 1);
327 snd_usb_caiaq_set_auto_msg(dev, 1, 10, 5); 413 snd_usb_caiaq_set_auto_msg(dev, 1, 10, 5);
328 break; 414 break;
415 case USB_ID(USB_VID_NATIVEINSTRUMENTS, USB_PID_TRAKTORKONTROLX1):
416 input->evbit[0] = BIT_MASK(EV_KEY) | BIT_MASK(EV_ABS);
417 input->absbit[0] = BIT_MASK(ABS_HAT0X) | BIT_MASK(ABS_HAT0Y) |
418 BIT_MASK(ABS_HAT1X) | BIT_MASK(ABS_HAT1Y) |
419 BIT_MASK(ABS_HAT2X) | BIT_MASK(ABS_HAT2Y) |
420 BIT_MASK(ABS_HAT3X) | BIT_MASK(ABS_HAT3Y) |
421 BIT_MASK(ABS_X) | BIT_MASK(ABS_Y) |
422 BIT_MASK(ABS_Z);
423 input->absbit[BIT_WORD(ABS_MISC)] |= BIT_MASK(ABS_MISC);
424 BUILD_BUG_ON(sizeof(dev->keycode) < KONTROLX1_INPUTS);
425 for (i = 0; i < KONTROLX1_INPUTS; i++)
426 dev->keycode[i] = BTN_MISC + i;
427 input->keycodemax = KONTROLX1_INPUTS;
428
429 /* analog potentiometers */
430 input_set_abs_params(input, ABS_HAT0X, 0, 4096, 0, 10);
431 input_set_abs_params(input, ABS_HAT0Y, 0, 4096, 0, 10);
432 input_set_abs_params(input, ABS_HAT1X, 0, 4096, 0, 10);
433 input_set_abs_params(input, ABS_HAT1Y, 0, 4096, 0, 10);
434 input_set_abs_params(input, ABS_HAT2X, 0, 4096, 0, 10);
435 input_set_abs_params(input, ABS_HAT2Y, 0, 4096, 0, 10);
436 input_set_abs_params(input, ABS_HAT3X, 0, 4096, 0, 10);
437 input_set_abs_params(input, ABS_HAT3Y, 0, 4096, 0, 10);
438
439 /* rotary encoders */
440 input_set_abs_params(input, ABS_X, 0, 0xf, 0, 1);
441 input_set_abs_params(input, ABS_Y, 0, 0xf, 0, 1);
442 input_set_abs_params(input, ABS_Z, 0, 0xf, 0, 1);
443 input_set_abs_params(input, ABS_MISC, 0, 0xf, 0, 1);
444
445 dev->ep4_in_urb = usb_alloc_urb(0, GFP_KERNEL);
446 if (!dev->ep4_in_urb) {
447 ret = -ENOMEM;
448 goto exit_free_idev;
449 }
450
451 usb_fill_bulk_urb(dev->ep4_in_urb, usb_dev,
452 usb_rcvbulkpipe(usb_dev, 0x4),
453 dev->ep4_in_buf, EP4_BUFSIZE,
454 snd_usb_caiaq_ep4_reply_dispatch, dev);
455
456 snd_usb_caiaq_set_auto_msg(dev, 1, 10, 5);
457
458 break;
329 default: 459 default:
330 /* no input methods supported on this device */ 460 /* no input methods supported on this device */
331 input_free_device(input); 461 goto exit_free_idev;
332 return 0;
333 } 462 }
334 463
464 input->open = snd_usb_caiaq_input_open;
465 input->close = snd_usb_caiaq_input_close;
335 input->keycode = dev->keycode; 466 input->keycode = dev->keycode;
336 input->keycodesize = sizeof(unsigned short); 467 input->keycodesize = sizeof(unsigned short);
337 for (i = 0; i < input->keycodemax; i++) 468 for (i = 0; i < input->keycodemax; i++)
338 __set_bit(dev->keycode[i], input->keybit); 469 __set_bit(dev->keycode[i], input->keybit);
339 470
340 ret = input_register_device(input); 471 ret = input_register_device(input);
341 if (ret < 0) { 472 if (ret < 0)
342 input_free_device(input); 473 goto exit_free_idev;
343 return ret;
344 }
345 474
346 dev->input_dev = input; 475 dev->input_dev = input;
347 return 0; 476 return 0;
477
478exit_free_idev:
479 input_free_device(input);
480 return ret;
348} 481}
349 482
350void snd_usb_caiaq_input_free(struct snd_usb_caiaqdev *dev) 483void snd_usb_caiaq_input_free(struct snd_usb_caiaqdev *dev)
@@ -352,6 +485,10 @@ void snd_usb_caiaq_input_free(struct snd_usb_caiaqdev *dev)
352 if (!dev || !dev->input_dev) 485 if (!dev || !dev->input_dev)
353 return; 486 return;
354 487
488 usb_kill_urb(dev->ep4_in_urb);
489 usb_free_urb(dev->ep4_in_urb);
490 dev->ep4_in_urb = NULL;
491
355 input_unregister_device(dev->input_dev); 492 input_unregister_device(dev->input_dev);
356 dev->input_dev = NULL; 493 dev->input_dev = NULL;
357} 494}
diff --git a/sound/usb/caiaq/midi.c b/sound/usb/caiaq/midi.c
index 538e8c00d31a..2f218c77fff2 100644
--- a/sound/usb/caiaq/midi.c
+++ b/sound/usb/caiaq/midi.c
@@ -17,6 +17,7 @@
17*/ 17*/
18 18
19#include <linux/usb.h> 19#include <linux/usb.h>
20#include <linux/gfp.h>
20#include <sound/rawmidi.h> 21#include <sound/rawmidi.h>
21#include <sound/core.h> 22#include <sound/core.h>
22#include <sound/pcm.h> 23#include <sound/pcm.h>