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;
42 unsigned int id = dev->chip.usb_id;
47 if (((id == USB_ID(USB_VID_NATIVEINSTRUMENTS, USB_PID_AUDIO8DJ)) ||
48 (id == USB_ID(USB_VID_NATIVEINSTRUMENTS, USB_PID_AUDIO4DJ)))
50 /* current input mode of A8DJ and A4DJ */
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 static struct caiaq_controller a4dj_controller[] = {
252 { "Current input mode", 0 | CNT_INTVAL }
255 static int __devinit add_controls(struct caiaq_controller *c, int num,
256 struct snd_usb_caiaqdev *dev)
259 struct snd_kcontrol *kc;
261 for (i = 0; i < num; i++, c++) {
262 kcontrol_template.name = c->name;
263 kcontrol_template.private_value = c->index;
264 kc = snd_ctl_new1(&kcontrol_template, dev);
265 ret = snd_ctl_add(dev->chip.card, kc);
273 int __devinit snd_usb_caiaq_control_init(struct snd_usb_caiaqdev *dev)
277 switch (dev->chip.usb_id) {
278 case USB_ID(USB_VID_NATIVEINSTRUMENTS, USB_PID_AK1):
279 ret = add_controls(ak1_controller,
280 ARRAY_SIZE(ak1_controller), dev);
283 case USB_ID(USB_VID_NATIVEINSTRUMENTS, USB_PID_RIGKONTROL2):
284 ret = add_controls(rk2_controller,
285 ARRAY_SIZE(rk2_controller), dev);
288 case USB_ID(USB_VID_NATIVEINSTRUMENTS, USB_PID_RIGKONTROL3):
289 ret = add_controls(rk3_controller,
290 ARRAY_SIZE(rk3_controller), dev);
293 case USB_ID(USB_VID_NATIVEINSTRUMENTS, USB_PID_KORECONTROLLER):
294 case USB_ID(USB_VID_NATIVEINSTRUMENTS, USB_PID_KORECONTROLLER2):
295 ret = add_controls(kore_controller,
296 ARRAY_SIZE(kore_controller), dev);
299 case USB_ID(USB_VID_NATIVEINSTRUMENTS, USB_PID_AUDIO8DJ):
300 ret = add_controls(a8dj_controller,
301 ARRAY_SIZE(a8dj_controller), dev);
303 case USB_ID(USB_VID_NATIVEINSTRUMENTS, USB_PID_AUDIO4DJ):
304 ret = add_controls(a4dj_controller,
305 ARRAY_SIZE(a4dj_controller), dev);