blob: e92c2bbf4fe92742aa4f99a16d735d0996f7f8c9 [file] [log] [blame]
Daniel Mack8e3cd082007-11-22 11:40:04 +01001/*
2 * Copyright (c) 2007 Daniel Mack
3 * friendly supported by NI.
4 *
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software
17 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18 */
19
Daniel Mack8e3cd082007-11-22 11:40:04 +010020#include <linux/init.h>
21#include <linux/interrupt.h>
22#include <linux/usb.h>
23#include <sound/core.h>
24#include <sound/initval.h>
25#include <sound/pcm.h>
26#include <sound/rawmidi.h>
27#include <sound/control.h>
28#include <linux/input.h>
29
30#include "caiaq-device.h"
31#include "caiaq-control.h"
32
33#define CNT_INTVAL 0x10000
34
35static int control_info(struct snd_kcontrol *kcontrol,
36 struct snd_ctl_elem_info *uinfo)
37{
38 struct snd_usb_audio *chip = snd_kcontrol_chip(kcontrol);
39 struct snd_usb_caiaqdev *dev = caiaqdev(chip->card);
40 int pos = kcontrol->private_value;
41 int is_intval = pos & CNT_INTVAL;
Daniel Mack21655922009-01-16 11:03:19 +010042 unsigned int id = dev->chip.usb_id;
Daniel Mack8e3cd082007-11-22 11:40:04 +010043
44 uinfo->count = 1;
45 pos &= ~CNT_INTVAL;
46
Mark Hills9a9527e2009-02-04 22:34:32 +000047 if (id == USB_ID(USB_VID_NATIVEINSTRUMENTS, USB_PID_AUDIO8DJ)
Daniel Mack8e3cd082007-11-22 11:40:04 +010048 && (pos == 0)) {
Mark Hills9a9527e2009-02-04 22:34:32 +000049 /* current input mode of A8DJ */
Daniel Mack8e3cd082007-11-22 11:40:04 +010050 uinfo->type = SNDRV_CTL_ELEM_TYPE_INTEGER;
51 uinfo->value.integer.min = 0;
52 uinfo->value.integer.max = 2;
53 return 0;
54 }
55
Mark Hills9a9527e2009-02-04 22:34:32 +000056 if (id == USB_ID(USB_VID_NATIVEINSTRUMENTS, USB_PID_AUDIO4DJ)
57 && (pos == 0)) {
58 /* current input mode of A4DJ */
59 uinfo->type = SNDRV_CTL_ELEM_TYPE_INTEGER;
60 uinfo->value.integer.min = 0;
61 uinfo->value.integer.max = 1;
62 return 0;
63 }
64
Daniel Mack8e3cd082007-11-22 11:40:04 +010065 if (is_intval) {
66 uinfo->type = SNDRV_CTL_ELEM_TYPE_INTEGER;
67 uinfo->value.integer.min = 0;
68 uinfo->value.integer.max = 64;
69 } else {
70 uinfo->type = SNDRV_CTL_ELEM_TYPE_BOOLEAN;
71 uinfo->value.integer.min = 0;
72 uinfo->value.integer.max = 1;
73 }
74
75 return 0;
76}
77
78static int control_get(struct snd_kcontrol *kcontrol,
79 struct snd_ctl_elem_value *ucontrol)
80{
81 struct snd_usb_audio *chip = snd_kcontrol_chip(kcontrol);
82 struct snd_usb_caiaqdev *dev = caiaqdev(chip->card);
83 int pos = kcontrol->private_value;
84
Mark Hills9a9527e2009-02-04 22:34:32 +000085 if (dev->chip.usb_id ==
86 USB_ID(USB_VID_NATIVEINSTRUMENTS, USB_PID_AUDIO4DJ)) {
87 /* A4DJ has only one control */
88 /* do not expose hardware input mode 0 */
89 ucontrol->value.integer.value[0] = dev->control_state[0] - 1;
90 return 0;
91 }
92
Daniel Mack8e3cd082007-11-22 11:40:04 +010093 if (pos & CNT_INTVAL)
94 ucontrol->value.integer.value[0]
95 = dev->control_state[pos & ~CNT_INTVAL];
96 else
97 ucontrol->value.integer.value[0]
98 = !!(dev->control_state[pos / 8] & (1 << pos % 8));
99
100 return 0;
101}
102
103static int control_put(struct snd_kcontrol *kcontrol,
104 struct snd_ctl_elem_value *ucontrol)
105{
106 struct snd_usb_audio *chip = snd_kcontrol_chip(kcontrol);
107 struct snd_usb_caiaqdev *dev = caiaqdev(chip->card);
108 int pos = kcontrol->private_value;
109
Mark Hills9a9527e2009-02-04 22:34:32 +0000110 if (dev->chip.usb_id ==
111 USB_ID(USB_VID_NATIVEINSTRUMENTS, USB_PID_AUDIO4DJ)) {
112 /* A4DJ has only one control */
113 /* do not expose hardware input mode 0 */
114 dev->control_state[0] = ucontrol->value.integer.value[0] + 1;
115 snd_usb_caiaq_send_command(dev, EP1_CMD_WRITE_IO,
116 dev->control_state, sizeof(dev->control_state));
117 return 1;
118 }
119
Daniel Mack8e3cd082007-11-22 11:40:04 +0100120 if (pos & CNT_INTVAL) {
121 dev->control_state[pos & ~CNT_INTVAL]
122 = ucontrol->value.integer.value[0];
Mark Hills705350f2009-02-04 22:34:30 +0000123 snd_usb_caiaq_send_command(dev, EP1_CMD_WRITE_IO,
Daniel Mack8e3cd082007-11-22 11:40:04 +0100124 dev->control_state, sizeof(dev->control_state));
125 } else {
126 if (ucontrol->value.integer.value[0])
127 dev->control_state[pos / 8] |= 1 << (pos % 8);
128 else
129 dev->control_state[pos / 8] &= ~(1 << (pos % 8));
130
131 snd_usb_caiaq_send_command(dev, EP1_CMD_WRITE_IO,
132 dev->control_state, sizeof(dev->control_state));
133 }
134
135 return 1;
136}
137
138static struct snd_kcontrol_new kcontrol_template __devinitdata = {
139 .iface = SNDRV_CTL_ELEM_IFACE_HWDEP,
140 .access = SNDRV_CTL_ELEM_ACCESS_READWRITE,
141 .index = 0,
142 .info = control_info,
143 .get = control_get,
144 .put = control_put,
145 /* name and private_value filled later */
146};
147
148struct caiaq_controller {
149 char *name;
150 int index;
151};
152
153static struct caiaq_controller ak1_controller[] = {
154 { "LED left", 2 },
155 { "LED middle", 1 },
156 { "LED right", 0 },
157 { "LED ring", 3 }
158};
159
160static struct caiaq_controller rk2_controller[] = {
161 { "LED 1", 5 },
162 { "LED 2", 4 },
163 { "LED 3", 3 },
164 { "LED 4", 2 },
165 { "LED 5", 1 },
166 { "LED 6", 0 },
167 { "LED pedal", 6 },
168 { "LED 7seg_1b", 8 },
169 { "LED 7seg_1c", 9 },
170 { "LED 7seg_2a", 10 },
171 { "LED 7seg_2b", 11 },
172 { "LED 7seg_2c", 12 },
173 { "LED 7seg_2d", 13 },
174 { "LED 7seg_2e", 14 },
175 { "LED 7seg_2f", 15 },
176 { "LED 7seg_2g", 16 },
177 { "LED 7seg_3a", 17 },
178 { "LED 7seg_3b", 18 },
179 { "LED 7seg_3c", 19 },
180 { "LED 7seg_3d", 20 },
181 { "LED 7seg_3e", 21 },
182 { "LED 7seg_3f", 22 },
183 { "LED 7seg_3g", 23 }
184};
185
186static struct caiaq_controller rk3_controller[] = {
187 { "LED 7seg_1a", 0 + 0 },
188 { "LED 7seg_1b", 0 + 1 },
189 { "LED 7seg_1c", 0 + 2 },
190 { "LED 7seg_1d", 0 + 3 },
191 { "LED 7seg_1e", 0 + 4 },
192 { "LED 7seg_1f", 0 + 5 },
193 { "LED 7seg_1g", 0 + 6 },
194 { "LED 7seg_1p", 0 + 7 },
195
196 { "LED 7seg_2a", 8 + 0 },
197 { "LED 7seg_2b", 8 + 1 },
198 { "LED 7seg_2c", 8 + 2 },
199 { "LED 7seg_2d", 8 + 3 },
200 { "LED 7seg_2e", 8 + 4 },
201 { "LED 7seg_2f", 8 + 5 },
202 { "LED 7seg_2g", 8 + 6 },
203 { "LED 7seg_2p", 8 + 7 },
204
205 { "LED 7seg_3a", 16 + 0 },
206 { "LED 7seg_3b", 16 + 1 },
207 { "LED 7seg_3c", 16 + 2 },
208 { "LED 7seg_3d", 16 + 3 },
209 { "LED 7seg_3e", 16 + 4 },
210 { "LED 7seg_3f", 16 + 5 },
211 { "LED 7seg_3g", 16 + 6 },
212 { "LED 7seg_3p", 16 + 7 },
213
214 { "LED 7seg_4a", 24 + 0 },
215 { "LED 7seg_4b", 24 + 1 },
216 { "LED 7seg_4c", 24 + 2 },
217 { "LED 7seg_4d", 24 + 3 },
218 { "LED 7seg_4e", 24 + 4 },
219 { "LED 7seg_4f", 24 + 5 },
220 { "LED 7seg_4g", 24 + 6 },
221 { "LED 7seg_4p", 24 + 7 },
222
223 { "LED 1", 32 + 0 },
224 { "LED 2", 32 + 1 },
225 { "LED 3", 32 + 2 },
226 { "LED 4", 32 + 3 },
227 { "LED 5", 32 + 4 },
228 { "LED 6", 32 + 5 },
229 { "LED 7", 32 + 6 },
230 { "LED 8", 32 + 7 },
231 { "LED pedal", 32 + 8 }
232};
233
234static struct caiaq_controller kore_controller[] = {
235 { "LED F1", 8 | CNT_INTVAL },
236 { "LED F2", 12 | CNT_INTVAL },
237 { "LED F3", 0 | CNT_INTVAL },
238 { "LED F4", 4 | CNT_INTVAL },
239 { "LED F5", 11 | CNT_INTVAL },
240 { "LED F6", 15 | CNT_INTVAL },
241 { "LED F7", 3 | CNT_INTVAL },
242 { "LED F8", 7 | CNT_INTVAL },
243 { "LED touch1", 10 | CNT_INTVAL },
244 { "LED touch2", 14 | CNT_INTVAL },
245 { "LED touch3", 2 | CNT_INTVAL },
246 { "LED touch4", 6 | CNT_INTVAL },
247 { "LED touch5", 9 | CNT_INTVAL },
248 { "LED touch6", 13 | CNT_INTVAL },
249 { "LED touch7", 1 | CNT_INTVAL },
250 { "LED touch8", 5 | CNT_INTVAL },
251 { "LED left", 18 | CNT_INTVAL },
252 { "LED right", 22 | CNT_INTVAL },
253 { "LED up", 16 | CNT_INTVAL },
254 { "LED down", 20 | CNT_INTVAL },
255 { "LED stop", 23 | CNT_INTVAL },
256 { "LED play", 21 | CNT_INTVAL },
257 { "LED record", 19 | CNT_INTVAL },
258 { "LED listen", 17 | CNT_INTVAL },
259 { "LED lcd", 30 | CNT_INTVAL },
260 { "LED menu", 28 | CNT_INTVAL },
261 { "LED sound", 31 | CNT_INTVAL },
262 { "LED esc", 29 | CNT_INTVAL },
263 { "LED view", 27 | CNT_INTVAL },
264 { "LED enter", 24 | CNT_INTVAL },
265 { "LED control", 26 | CNT_INTVAL }
266};
267
268static struct caiaq_controller a8dj_controller[] = {
269 { "Current input mode", 0 | CNT_INTVAL },
270 { "GND lift for TC Vinyl mode", 24 + 0 },
271 { "GND lift for TC CD/Line mode", 24 + 1 },
272 { "GND lift for phono mode", 24 + 2 },
Daniel Mack8e3cd082007-11-22 11:40:04 +0100273 { "Software lock", 40 }
274};
275
Daniel Mack21655922009-01-16 11:03:19 +0100276static struct caiaq_controller a4dj_controller[] = {
277 { "Current input mode", 0 | CNT_INTVAL }
278};
279
Daniel Mack12666f02008-11-27 08:21:05 +0100280static int __devinit add_controls(struct caiaq_controller *c, int num,
281 struct snd_usb_caiaqdev *dev)
282{
283 int i, ret;
284 struct snd_kcontrol *kc;
285
286 for (i = 0; i < num; i++, c++) {
287 kcontrol_template.name = c->name;
288 kcontrol_template.private_value = c->index;
289 kc = snd_ctl_new1(&kcontrol_template, dev);
290 ret = snd_ctl_add(dev->chip.card, kc);
291 if (ret < 0)
292 return ret;
293 }
294
295 return 0;
296}
297
Daniel Mack8e3cd082007-11-22 11:40:04 +0100298int __devinit snd_usb_caiaq_control_init(struct snd_usb_caiaqdev *dev)
299{
Daniel Mack12666f02008-11-27 08:21:05 +0100300 int ret = 0;
Daniel Mack8e3cd082007-11-22 11:40:04 +0100301
302 switch (dev->chip.usb_id) {
303 case USB_ID(USB_VID_NATIVEINSTRUMENTS, USB_PID_AK1):
Daniel Mack12666f02008-11-27 08:21:05 +0100304 ret = add_controls(ak1_controller,
305 ARRAY_SIZE(ak1_controller), dev);
Daniel Mack8e3cd082007-11-22 11:40:04 +0100306 break;
307
308 case USB_ID(USB_VID_NATIVEINSTRUMENTS, USB_PID_RIGKONTROL2):
Daniel Mack12666f02008-11-27 08:21:05 +0100309 ret = add_controls(rk2_controller,
310 ARRAY_SIZE(rk2_controller), dev);
Daniel Mack8e3cd082007-11-22 11:40:04 +0100311 break;
312
313 case USB_ID(USB_VID_NATIVEINSTRUMENTS, USB_PID_RIGKONTROL3):
Daniel Mack12666f02008-11-27 08:21:05 +0100314 ret = add_controls(rk3_controller,
315 ARRAY_SIZE(rk3_controller), dev);
Daniel Mack8e3cd082007-11-22 11:40:04 +0100316 break;
317
318 case USB_ID(USB_VID_NATIVEINSTRUMENTS, USB_PID_KORECONTROLLER):
Daniel Mack7829d0e2007-11-26 09:00:56 +0100319 case USB_ID(USB_VID_NATIVEINSTRUMENTS, USB_PID_KORECONTROLLER2):
Daniel Mack12666f02008-11-27 08:21:05 +0100320 ret = add_controls(kore_controller,
321 ARRAY_SIZE(kore_controller), dev);
Daniel Mack8e3cd082007-11-22 11:40:04 +0100322 break;
323
324 case USB_ID(USB_VID_NATIVEINSTRUMENTS, USB_PID_AUDIO8DJ):
Daniel Mack12666f02008-11-27 08:21:05 +0100325 ret = add_controls(a8dj_controller,
326 ARRAY_SIZE(a8dj_controller), dev);
Daniel Mack8e3cd082007-11-22 11:40:04 +0100327 break;
Daniel Mack21655922009-01-16 11:03:19 +0100328 case USB_ID(USB_VID_NATIVEINSTRUMENTS, USB_PID_AUDIO4DJ):
329 ret = add_controls(a4dj_controller,
330 ARRAY_SIZE(a4dj_controller), dev);
331 break;
Daniel Mack8e3cd082007-11-22 11:40:04 +0100332 }
333
Daniel Mack12666f02008-11-27 08:21:05 +0100334 return ret;
Daniel Mack8e3cd082007-11-22 11:40:04 +0100335}
336