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 <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>
30 #include "caiaq-device.h"
31 #include "caiaq-control.h"
33 #define CNT_INTVAL 0x10000
35 static int control_info(struct snd_kcontrol *kcontrol,
36 struct snd_ctl_elem_info *uinfo)
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;
46 if (dev->chip.usb_id ==
47 USB_ID(USB_VID_NATIVEINSTRUMENTS, USB_PID_AUDIO8DJ)
49 /* current input mode of A8DJ */
50 uinfo->type = SNDRV_CTL_ELEM_TYPE_INTEGER;
51 uinfo->value.integer.min = 0;
52 uinfo->value.integer.max = 2;
57 uinfo->type = SNDRV_CTL_ELEM_TYPE_INTEGER;
58 uinfo->value.integer.min = 0;
59 uinfo->value.integer.max = 64;
61 uinfo->type = SNDRV_CTL_ELEM_TYPE_BOOLEAN;
62 uinfo->value.integer.min = 0;
63 uinfo->value.integer.max = 1;
69 static int control_get(struct snd_kcontrol *kcontrol,
70 struct snd_ctl_elem_value *ucontrol)
72 struct snd_usb_audio *chip = snd_kcontrol_chip(kcontrol);
73 struct snd_usb_caiaqdev *dev = caiaqdev(chip->card);
74 int pos = kcontrol->private_value;
77 ucontrol->value.integer.value[0]
78 = dev->control_state[pos & ~CNT_INTVAL];
80 ucontrol->value.integer.value[0]
81 = !!(dev->control_state[pos / 8] & (1 << pos % 8));
86 static int control_put(struct snd_kcontrol *kcontrol,
87 struct snd_ctl_elem_value *ucontrol)
89 struct snd_usb_audio *chip = snd_kcontrol_chip(kcontrol);
90 struct snd_usb_caiaqdev *dev = caiaqdev(chip->card);
91 int pos = kcontrol->private_value;
93 if (pos & CNT_INTVAL) {
94 dev->control_state[pos & ~CNT_INTVAL]
95 = ucontrol->value.integer.value[0];
96 snd_usb_caiaq_send_command(dev, EP1_CMD_DIMM_LEDS,
97 dev->control_state, sizeof(dev->control_state));
99 if (ucontrol->value.integer.value[0])
100 dev->control_state[pos / 8] |= 1 << (pos % 8);
102 dev->control_state[pos / 8] &= ~(1 << (pos % 8));
104 snd_usb_caiaq_send_command(dev, EP1_CMD_WRITE_IO,
105 dev->control_state, sizeof(dev->control_state));
111 static struct snd_kcontrol_new kcontrol_template __devinitdata = {
112 .iface = SNDRV_CTL_ELEM_IFACE_HWDEP,
113 .access = SNDRV_CTL_ELEM_ACCESS_READWRITE,
115 .info = control_info,
118 /* name and private_value filled later */
121 struct caiaq_controller {
126 static struct caiaq_controller ak1_controller[] = {
133 static struct caiaq_controller rk2_controller[] = {
141 { "LED 7seg_1b", 8 },
142 { "LED 7seg_1c", 9 },
143 { "LED 7seg_2a", 10 },
144 { "LED 7seg_2b", 11 },
145 { "LED 7seg_2c", 12 },
146 { "LED 7seg_2d", 13 },
147 { "LED 7seg_2e", 14 },
148 { "LED 7seg_2f", 15 },
149 { "LED 7seg_2g", 16 },
150 { "LED 7seg_3a", 17 },
151 { "LED 7seg_3b", 18 },
152 { "LED 7seg_3c", 19 },
153 { "LED 7seg_3d", 20 },
154 { "LED 7seg_3e", 21 },
155 { "LED 7seg_3f", 22 },
156 { "LED 7seg_3g", 23 }
159 static struct caiaq_controller rk3_controller[] = {
160 { "LED 7seg_1a", 0 + 0 },
161 { "LED 7seg_1b", 0 + 1 },
162 { "LED 7seg_1c", 0 + 2 },
163 { "LED 7seg_1d", 0 + 3 },
164 { "LED 7seg_1e", 0 + 4 },
165 { "LED 7seg_1f", 0 + 5 },
166 { "LED 7seg_1g", 0 + 6 },
167 { "LED 7seg_1p", 0 + 7 },
169 { "LED 7seg_2a", 8 + 0 },
170 { "LED 7seg_2b", 8 + 1 },
171 { "LED 7seg_2c", 8 + 2 },
172 { "LED 7seg_2d", 8 + 3 },
173 { "LED 7seg_2e", 8 + 4 },
174 { "LED 7seg_2f", 8 + 5 },
175 { "LED 7seg_2g", 8 + 6 },
176 { "LED 7seg_2p", 8 + 7 },
178 { "LED 7seg_3a", 16 + 0 },
179 { "LED 7seg_3b", 16 + 1 },
180 { "LED 7seg_3c", 16 + 2 },
181 { "LED 7seg_3d", 16 + 3 },
182 { "LED 7seg_3e", 16 + 4 },
183 { "LED 7seg_3f", 16 + 5 },
184 { "LED 7seg_3g", 16 + 6 },
185 { "LED 7seg_3p", 16 + 7 },
187 { "LED 7seg_4a", 24 + 0 },
188 { "LED 7seg_4b", 24 + 1 },
189 { "LED 7seg_4c", 24 + 2 },
190 { "LED 7seg_4d", 24 + 3 },
191 { "LED 7seg_4e", 24 + 4 },
192 { "LED 7seg_4f", 24 + 5 },
193 { "LED 7seg_4g", 24 + 6 },
194 { "LED 7seg_4p", 24 + 7 },
204 { "LED pedal", 32 + 8 }
207 static struct caiaq_controller kore_controller[] = {
208 { "LED F1", 8 | CNT_INTVAL },
209 { "LED F2", 12 | CNT_INTVAL },
210 { "LED F3", 0 | CNT_INTVAL },
211 { "LED F4", 4 | CNT_INTVAL },
212 { "LED F5", 11 | CNT_INTVAL },
213 { "LED F6", 15 | CNT_INTVAL },
214 { "LED F7", 3 | CNT_INTVAL },
215 { "LED F8", 7 | CNT_INTVAL },
216 { "LED touch1", 10 | CNT_INTVAL },
217 { "LED touch2", 14 | CNT_INTVAL },
218 { "LED touch3", 2 | CNT_INTVAL },
219 { "LED touch4", 6 | CNT_INTVAL },
220 { "LED touch5", 9 | CNT_INTVAL },
221 { "LED touch6", 13 | CNT_INTVAL },
222 { "LED touch7", 1 | CNT_INTVAL },
223 { "LED touch8", 5 | CNT_INTVAL },
224 { "LED left", 18 | CNT_INTVAL },
225 { "LED right", 22 | CNT_INTVAL },
226 { "LED up", 16 | CNT_INTVAL },
227 { "LED down", 20 | CNT_INTVAL },
228 { "LED stop", 23 | CNT_INTVAL },
229 { "LED play", 21 | CNT_INTVAL },
230 { "LED record", 19 | CNT_INTVAL },
231 { "LED listen", 17 | CNT_INTVAL },
232 { "LED lcd", 30 | CNT_INTVAL },
233 { "LED menu", 28 | CNT_INTVAL },
234 { "LED sound", 31 | CNT_INTVAL },
235 { "LED esc", 29 | CNT_INTVAL },
236 { "LED view", 27 | CNT_INTVAL },
237 { "LED enter", 24 | CNT_INTVAL },
238 { "LED control", 26 | CNT_INTVAL }
241 static struct caiaq_controller a8dj_controller[] = {
242 { "Current input mode", 0 | CNT_INTVAL },
243 { "GND lift for TC Vinyl mode", 24 + 0 },
244 { "GND lift for TC CD/Line mode", 24 + 1 },
245 { "GND lift for phono mode", 24 + 2 },
246 { "GND lift for TC Vinyl mode", 24 + 3 },
247 { "Software lock", 40 }
250 static int __devinit add_controls(struct caiaq_controller *c, int num,
251 struct snd_usb_caiaqdev *dev)
254 struct snd_kcontrol *kc;
256 for (i = 0; i < num; i++, c++) {
257 kcontrol_template.name = c->name;
258 kcontrol_template.private_value = c->index;
259 kc = snd_ctl_new1(&kcontrol_template, dev);
260 ret = snd_ctl_add(dev->chip.card, kc);
268 int __devinit snd_usb_caiaq_control_init(struct snd_usb_caiaqdev *dev)
272 switch (dev->chip.usb_id) {
273 case USB_ID(USB_VID_NATIVEINSTRUMENTS, USB_PID_AK1):
274 ret = add_controls(ak1_controller,
275 ARRAY_SIZE(ak1_controller), dev);
278 case USB_ID(USB_VID_NATIVEINSTRUMENTS, USB_PID_RIGKONTROL2):
279 ret = add_controls(rk2_controller,
280 ARRAY_SIZE(rk2_controller), dev);
283 case USB_ID(USB_VID_NATIVEINSTRUMENTS, USB_PID_RIGKONTROL3):
284 ret = add_controls(rk3_controller,
285 ARRAY_SIZE(rk3_controller), dev);
288 case USB_ID(USB_VID_NATIVEINSTRUMENTS, USB_PID_KORECONTROLLER):
289 case USB_ID(USB_VID_NATIVEINSTRUMENTS, USB_PID_KORECONTROLLER2):
290 ret = add_controls(kore_controller,
291 ARRAY_SIZE(kore_controller), dev);
294 case USB_ID(USB_VID_NATIVEINSTRUMENTS, USB_PID_AUDIO8DJ):
295 ret = add_controls(a8dj_controller,
296 ARRAY_SIZE(a8dj_controller), dev);