aboutsummaryrefslogtreecommitdiffstats
path: root/sound/usb/caiaq/caiaq-control.c
diff options
context:
space:
mode:
authorDaniel Mack <daniel@caiaq.de>2007-11-22 05:40:04 -0500
committerJaroslav Kysela <perex@perex.cz>2008-01-31 11:29:28 -0500
commit8e3cd08ed8e590952aa9a656758cb24d4ba898f8 (patch)
tree162fa11dcaff39a1f5e2fff6f7f03670321a558d /sound/usb/caiaq/caiaq-control.c
parente5f73e2ae813aa216b480728548e5ffbebcc170a (diff)
[ALSA] caiaq - add control API and more input features
- added support for all input controllers on Native Instrument's 'Kore controller'. - added ALSA controls to switch LEDs on 'RigKontrol 2', 'RigKontrol3', 'Audio Kontrol 1' and 'Kore controller'. - added ALSA controls to switch input mode, software lock and ground lift features on 'Audio 8 DJ'. Signed-off-by: Daniel Mack <daniel@caiaq.de> Signed-off-by: Takashi Iwai <tiwai@suse.de> Signed-off-by: Jaroslav Kysela <perex@perex.cz>
Diffstat (limited to 'sound/usb/caiaq/caiaq-control.c')
-rw-r--r--sound/usb/caiaq/caiaq-control.c315
1 files changed, 315 insertions, 0 deletions
diff --git a/sound/usb/caiaq/caiaq-control.c b/sound/usb/caiaq/caiaq-control.c
new file mode 100644
index 000000000000..14e8e32de925
--- /dev/null
+++ b/sound/usb/caiaq/caiaq-control.c
@@ -0,0 +1,315 @@
1/*
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
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>
30
31#include "caiaq-device.h"
32#include "caiaq-control.h"
33
34#define CNT_INTVAL 0x10000
35
36static int control_info(struct snd_kcontrol *kcontrol,
37 struct snd_ctl_elem_info *uinfo)
38{
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;
43
44 uinfo->count = 1;
45 pos &= ~CNT_INTVAL;
46
47 if (dev->chip.usb_id ==
48 USB_ID(USB_VID_NATIVEINSTRUMENTS, USB_PID_AUDIO8DJ)
49 && (pos == 0)) {
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;
54 return 0;
55 }
56
57 if (is_intval) {
58 uinfo->type = SNDRV_CTL_ELEM_TYPE_INTEGER;
59 uinfo->value.integer.min = 0;
60 uinfo->value.integer.max = 64;
61 } else {
62 uinfo->type = SNDRV_CTL_ELEM_TYPE_BOOLEAN;
63 uinfo->value.integer.min = 0;
64 uinfo->value.integer.max = 1;
65 }
66
67 return 0;
68}
69
70static int control_get(struct snd_kcontrol *kcontrol,
71 struct snd_ctl_elem_value *ucontrol)
72{
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;
76
77 if (pos & CNT_INTVAL)
78 ucontrol->value.integer.value[0]
79 = dev->control_state[pos & ~CNT_INTVAL];
80 else
81 ucontrol->value.integer.value[0]
82 = !!(dev->control_state[pos / 8] & (1 << pos % 8));
83
84 return 0;
85}
86
87static int control_put(struct snd_kcontrol *kcontrol,
88 struct snd_ctl_elem_value *ucontrol)
89{
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;
93
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));
99 } else {
100 if (ucontrol->value.integer.value[0])
101 dev->control_state[pos / 8] |= 1 << (pos % 8);
102 else
103 dev->control_state[pos / 8] &= ~(1 << (pos % 8));
104
105 snd_usb_caiaq_send_command(dev, EP1_CMD_WRITE_IO,
106 dev->control_state, sizeof(dev->control_state));
107 }
108
109 return 1;
110}
111
112static struct snd_kcontrol_new kcontrol_template __devinitdata = {
113 .iface = SNDRV_CTL_ELEM_IFACE_HWDEP,
114 .access = SNDRV_CTL_ELEM_ACCESS_READWRITE,
115 .index = 0,
116 .info = control_info,
117 .get = control_get,
118 .put = control_put,
119 /* name and private_value filled later */
120};
121
122struct caiaq_controller {
123 char *name;
124 int index;
125};
126
127static struct caiaq_controller ak1_controller[] = {
128 { "LED left", 2 },
129 { "LED middle", 1 },
130 { "LED right", 0 },
131 { "LED ring", 3 }
132};
133
134static struct caiaq_controller rk2_controller[] = {
135 { "LED 1", 5 },
136 { "LED 2", 4 },
137 { "LED 3", 3 },
138 { "LED 4", 2 },
139 { "LED 5", 1 },
140 { "LED 6", 0 },
141 { "LED pedal", 6 },
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 }
158};
159
160static 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 },
169
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 },
178
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 },
187
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 },
196
197 { "LED 1", 32 + 0 },
198 { "LED 2", 32 + 1 },
199 { "LED 3", 32 + 2 },
200 { "LED 4", 32 + 3 },
201 { "LED 5", 32 + 4 },
202 { "LED 6", 32 + 5 },
203 { "LED 7", 32 + 6 },
204 { "LED 8", 32 + 7 },
205 { "LED pedal", 32 + 8 }
206};
207
208static 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 }
240};
241
242static 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 }
249};
250
251int __devinit snd_usb_caiaq_control_init(struct snd_usb_caiaqdev *dev)
252{
253 int i;
254 struct snd_kcontrol *kc;
255
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);
264 }
265
266 break;
267
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);
275 }
276
277 break;
278
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);
286 }
287
288 break;
289
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);
297 }
298
299 break;
300
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);
308 }
309
310 break;
311 }
312
313 return 0;
314}
315