2 * Copyright (c) 2007 Daniel Mack
3 * friendly supported by NI.
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.
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.
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
20 #include <sound/driver.h>
21 #include <linux/init.h>
22 #include <linux/interrupt.h>
23 #include <linux/usb.h>
24 #include <sound/core.h>
25 #include <sound/initval.h>
26 #include <sound/pcm.h>
27 #include <sound/rawmidi.h>
28 #include <sound/control.h>
29 #include <linux/input.h>
31 #include "caiaq-device.h"
32 #include "caiaq-control.h"
34 #define CNT_INTVAL 0x10000
36 static int control_info(struct snd_kcontrol *kcontrol,
37 struct snd_ctl_elem_info *uinfo)
39 struct snd_usb_audio *chip = snd_kcontrol_chip(kcontrol);
40 struct snd_usb_caiaqdev *dev = caiaqdev(chip->card);
41 int pos = kcontrol->private_value;
42 int is_intval = pos & CNT_INTVAL;
47 if (dev->chip.usb_id ==
48 USB_ID(USB_VID_NATIVEINSTRUMENTS, USB_PID_AUDIO8DJ)
50 /* current input mode of A8DJ */
51 uinfo->type = SNDRV_CTL_ELEM_TYPE_INTEGER;
52 uinfo->value.integer.min = 0;
53 uinfo->value.integer.max = 2;
58 uinfo->type = SNDRV_CTL_ELEM_TYPE_INTEGER;
59 uinfo->value.integer.min = 0;
60 uinfo->value.integer.max = 64;
62 uinfo->type = SNDRV_CTL_ELEM_TYPE_BOOLEAN;
63 uinfo->value.integer.min = 0;
64 uinfo->value.integer.max = 1;
70 static int control_get(struct snd_kcontrol *kcontrol,
71 struct snd_ctl_elem_value *ucontrol)
73 struct snd_usb_audio *chip = snd_kcontrol_chip(kcontrol);
74 struct snd_usb_caiaqdev *dev = caiaqdev(chip->card);
75 int pos = kcontrol->private_value;
78 ucontrol->value.integer.value[0]
79 = dev->control_state[pos & ~CNT_INTVAL];
81 ucontrol->value.integer.value[0]
82 = !!(dev->control_state[pos / 8] & (1 << pos % 8));
87 static int control_put(struct snd_kcontrol *kcontrol,
88 struct snd_ctl_elem_value *ucontrol)
90 struct snd_usb_audio *chip = snd_kcontrol_chip(kcontrol);
91 struct snd_usb_caiaqdev *dev = caiaqdev(chip->card);
92 int pos = kcontrol->private_value;
94 if (pos & CNT_INTVAL) {
95 dev->control_state[pos & ~CNT_INTVAL]
96 = ucontrol->value.integer.value[0];
97 snd_usb_caiaq_send_command(dev, EP1_CMD_DIMM_LEDS,
98 dev->control_state, sizeof(dev->control_state));
100 if (ucontrol->value.integer.value[0])
101 dev->control_state[pos / 8] |= 1 << (pos % 8);
103 dev->control_state[pos / 8] &= ~(1 << (pos % 8));
105 snd_usb_caiaq_send_command(dev, EP1_CMD_WRITE_IO,
106 dev->control_state, sizeof(dev->control_state));
112 static struct snd_kcontrol_new kcontrol_template __devinitdata = {
113 .iface = SNDRV_CTL_ELEM_IFACE_HWDEP,
114 .access = SNDRV_CTL_ELEM_ACCESS_READWRITE,
116 .info = control_info,
119 /* name and private_value filled later */
122 struct caiaq_controller {
127 static struct caiaq_controller ak1_controller[] = {
134 static struct caiaq_controller rk2_controller[] = {
142 { "LED 7seg_1b", 8 },
143 { "LED 7seg_1c", 9 },
144 { "LED 7seg_2a", 10 },
145 { "LED 7seg_2b", 11 },
146 { "LED 7seg_2c", 12 },
147 { "LED 7seg_2d", 13 },
148 { "LED 7seg_2e", 14 },
149 { "LED 7seg_2f", 15 },
150 { "LED 7seg_2g", 16 },
151 { "LED 7seg_3a", 17 },
152 { "LED 7seg_3b", 18 },
153 { "LED 7seg_3c", 19 },
154 { "LED 7seg_3d", 20 },
155 { "LED 7seg_3e", 21 },
156 { "LED 7seg_3f", 22 },
157 { "LED 7seg_3g", 23 }
160 static struct caiaq_controller rk3_controller[] = {
161 { "LED 7seg_1a", 0 + 0 },
162 { "LED 7seg_1b", 0 + 1 },
163 { "LED 7seg_1c", 0 + 2 },
164 { "LED 7seg_1d", 0 + 3 },
165 { "LED 7seg_1e", 0 + 4 },
166 { "LED 7seg_1f", 0 + 5 },
167 { "LED 7seg_1g", 0 + 6 },
168 { "LED 7seg_1p", 0 + 7 },
170 { "LED 7seg_2a", 8 + 0 },
171 { "LED 7seg_2b", 8 + 1 },
172 { "LED 7seg_2c", 8 + 2 },
173 { "LED 7seg_2d", 8 + 3 },
174 { "LED 7seg_2e", 8 + 4 },
175 { "LED 7seg_2f", 8 + 5 },
176 { "LED 7seg_2g", 8 + 6 },
177 { "LED 7seg_2p", 8 + 7 },
179 { "LED 7seg_3a", 16 + 0 },
180 { "LED 7seg_3b", 16 + 1 },
181 { "LED 7seg_3c", 16 + 2 },
182 { "LED 7seg_3d", 16 + 3 },
183 { "LED 7seg_3e", 16 + 4 },
184 { "LED 7seg_3f", 16 + 5 },
185 { "LED 7seg_3g", 16 + 6 },
186 { "LED 7seg_3p", 16 + 7 },
188 { "LED 7seg_4a", 24 + 0 },
189 { "LED 7seg_4b", 24 + 1 },
190 { "LED 7seg_4c", 24 + 2 },
191 { "LED 7seg_4d", 24 + 3 },
192 { "LED 7seg_4e", 24 + 4 },
193 { "LED 7seg_4f", 24 + 5 },
194 { "LED 7seg_4g", 24 + 6 },
195 { "LED 7seg_4p", 24 + 7 },
205 { "LED pedal", 32 + 8 }
208 static struct caiaq_controller kore_controller[] = {
209 { "LED F1", 8 | CNT_INTVAL },
210 { "LED F2", 12 | CNT_INTVAL },
211 { "LED F3", 0 | CNT_INTVAL },
212 { "LED F4", 4 | CNT_INTVAL },
213 { "LED F5", 11 | CNT_INTVAL },
214 { "LED F6", 15 | CNT_INTVAL },
215 { "LED F7", 3 | CNT_INTVAL },
216 { "LED F8", 7 | CNT_INTVAL },
217 { "LED touch1", 10 | CNT_INTVAL },
218 { "LED touch2", 14 | CNT_INTVAL },
219 { "LED touch3", 2 | CNT_INTVAL },
220 { "LED touch4", 6 | CNT_INTVAL },
221 { "LED touch5", 9 | CNT_INTVAL },
222 { "LED touch6", 13 | CNT_INTVAL },
223 { "LED touch7", 1 | CNT_INTVAL },
224 { "LED touch8", 5 | CNT_INTVAL },
225 { "LED left", 18 | CNT_INTVAL },
226 { "LED right", 22 | CNT_INTVAL },
227 { "LED up", 16 | CNT_INTVAL },
228 { "LED down", 20 | CNT_INTVAL },
229 { "LED stop", 23 | CNT_INTVAL },
230 { "LED play", 21 | CNT_INTVAL },
231 { "LED record", 19 | CNT_INTVAL },
232 { "LED listen", 17 | CNT_INTVAL },
233 { "LED lcd", 30 | CNT_INTVAL },
234 { "LED menu", 28 | CNT_INTVAL },
235 { "LED sound", 31 | CNT_INTVAL },
236 { "LED esc", 29 | CNT_INTVAL },
237 { "LED view", 27 | CNT_INTVAL },
238 { "LED enter", 24 | CNT_INTVAL },
239 { "LED control", 26 | CNT_INTVAL }
242 static struct caiaq_controller a8dj_controller[] = {
243 { "Current input mode", 0 | CNT_INTVAL },
244 { "GND lift for TC Vinyl mode", 24 + 0 },
245 { "GND lift for TC CD/Line mode", 24 + 1 },
246 { "GND lift for phono mode", 24 + 2 },
247 { "GND lift for TC Vinyl mode", 24 + 3 },
248 { "Software lock", 40 }
251 int __devinit snd_usb_caiaq_control_init(struct snd_usb_caiaqdev *dev)
254 struct snd_kcontrol *kc;
256 switch (dev->chip.usb_id) {
257 case USB_ID(USB_VID_NATIVEINSTRUMENTS, USB_PID_AK1):
258 for (i = 0; i < ARRAY_SIZE(ak1_controller); i++) {
259 struct caiaq_controller *c = ak1_controller + i;
260 kcontrol_template.name = c->name;
261 kcontrol_template.private_value = c->index;
262 kc = snd_ctl_new1(&kcontrol_template, dev);
263 snd_ctl_add(dev->chip.card, kc);
268 case USB_ID(USB_VID_NATIVEINSTRUMENTS, USB_PID_RIGKONTROL2):
269 for (i = 0; i < ARRAY_SIZE(rk2_controller); i++) {
270 struct caiaq_controller *c = rk2_controller + i;
271 kcontrol_template.name = c->name;
272 kcontrol_template.private_value = c->index;
273 kc = snd_ctl_new1(&kcontrol_template, dev);
274 snd_ctl_add(dev->chip.card, kc);
279 case USB_ID(USB_VID_NATIVEINSTRUMENTS, USB_PID_RIGKONTROL3):
280 for (i = 0; i < ARRAY_SIZE(rk3_controller); i++) {
281 struct caiaq_controller *c = rk3_controller + i;
282 kcontrol_template.name = c->name;
283 kcontrol_template.private_value = c->index;
284 kc = snd_ctl_new1(&kcontrol_template, dev);
285 snd_ctl_add(dev->chip.card, kc);
290 case USB_ID(USB_VID_NATIVEINSTRUMENTS, USB_PID_KORECONTROLLER):
291 for (i = 0; i < ARRAY_SIZE(kore_controller); i++) {
292 struct caiaq_controller *c = kore_controller + i;
293 kcontrol_template.name = c->name;
294 kcontrol_template.private_value = c->index;
295 kc = snd_ctl_new1(&kcontrol_template, dev);
296 snd_ctl_add(dev->chip.card, kc);
301 case USB_ID(USB_VID_NATIVEINSTRUMENTS, USB_PID_AUDIO8DJ):
302 for (i = 0; i < ARRAY_SIZE(a8dj_controller); i++) {
303 struct caiaq_controller *c = a8dj_controller + i;
304 kcontrol_template.name = c->name;
305 kcontrol_template.private_value = c->index;
306 kc = snd_ctl_new1(&kcontrol_template, dev);
307 snd_ctl_add(dev->chip.card, kc);