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/usb.h>
22 #include <sound/control.h>
23 #include <sound/core.h>
24 #include <sound/pcm.h>
29 #define CNT_INTVAL 0x10000
31 static int control_info(struct snd_kcontrol
*kcontrol
,
32 struct snd_ctl_elem_info
*uinfo
)
34 struct snd_usb_audio
*chip
= snd_kcontrol_chip(kcontrol
);
35 struct snd_usb_caiaqdev
*dev
= caiaqdev(chip
->card
);
36 int pos
= kcontrol
->private_value
;
37 int is_intval
= pos
& CNT_INTVAL
;
38 unsigned int id
= dev
->chip
.usb_id
;
43 if (id
== USB_ID(USB_VID_NATIVEINSTRUMENTS
, USB_PID_AUDIO8DJ
)
45 /* current input mode of A8DJ */
46 uinfo
->type
= SNDRV_CTL_ELEM_TYPE_INTEGER
;
47 uinfo
->value
.integer
.min
= 0;
48 uinfo
->value
.integer
.max
= 2;
52 if (id
== USB_ID(USB_VID_NATIVEINSTRUMENTS
, USB_PID_AUDIO4DJ
)
54 /* current input mode of A4DJ */
55 uinfo
->type
= SNDRV_CTL_ELEM_TYPE_INTEGER
;
56 uinfo
->value
.integer
.min
= 0;
57 uinfo
->value
.integer
.max
= 1;
62 uinfo
->type
= SNDRV_CTL_ELEM_TYPE_INTEGER
;
63 uinfo
->value
.integer
.min
= 0;
64 uinfo
->value
.integer
.max
= 64;
66 uinfo
->type
= SNDRV_CTL_ELEM_TYPE_BOOLEAN
;
67 uinfo
->value
.integer
.min
= 0;
68 uinfo
->value
.integer
.max
= 1;
74 static int control_get(struct snd_kcontrol
*kcontrol
,
75 struct snd_ctl_elem_value
*ucontrol
)
77 struct snd_usb_audio
*chip
= snd_kcontrol_chip(kcontrol
);
78 struct snd_usb_caiaqdev
*dev
= caiaqdev(chip
->card
);
79 int pos
= kcontrol
->private_value
;
81 if (dev
->chip
.usb_id
==
82 USB_ID(USB_VID_NATIVEINSTRUMENTS
, USB_PID_AUDIO4DJ
)) {
83 /* A4DJ has only one control */
84 /* do not expose hardware input mode 0 */
85 ucontrol
->value
.integer
.value
[0] = dev
->control_state
[0] - 1;
90 ucontrol
->value
.integer
.value
[0]
91 = dev
->control_state
[pos
& ~CNT_INTVAL
];
93 ucontrol
->value
.integer
.value
[0]
94 = !!(dev
->control_state
[pos
/ 8] & (1 << pos
% 8));
99 static int control_put(struct snd_kcontrol
*kcontrol
,
100 struct snd_ctl_elem_value
*ucontrol
)
102 struct snd_usb_audio
*chip
= snd_kcontrol_chip(kcontrol
);
103 struct snd_usb_caiaqdev
*dev
= caiaqdev(chip
->card
);
104 int pos
= kcontrol
->private_value
;
106 if (dev
->chip
.usb_id
==
107 USB_ID(USB_VID_NATIVEINSTRUMENTS
, USB_PID_AUDIO4DJ
)) {
108 /* A4DJ has only one control */
109 /* do not expose hardware input mode 0 */
110 dev
->control_state
[0] = ucontrol
->value
.integer
.value
[0] + 1;
111 snd_usb_caiaq_send_command(dev
, EP1_CMD_WRITE_IO
,
112 dev
->control_state
, sizeof(dev
->control_state
));
116 if (pos
& CNT_INTVAL
) {
117 dev
->control_state
[pos
& ~CNT_INTVAL
]
118 = ucontrol
->value
.integer
.value
[0];
119 snd_usb_caiaq_send_command(dev
, EP1_CMD_WRITE_IO
,
120 dev
->control_state
, sizeof(dev
->control_state
));
122 if (ucontrol
->value
.integer
.value
[0])
123 dev
->control_state
[pos
/ 8] |= 1 << (pos
% 8);
125 dev
->control_state
[pos
/ 8] &= ~(1 << (pos
% 8));
127 snd_usb_caiaq_send_command(dev
, EP1_CMD_WRITE_IO
,
128 dev
->control_state
, sizeof(dev
->control_state
));
134 static struct snd_kcontrol_new kcontrol_template __devinitdata
= {
135 .iface
= SNDRV_CTL_ELEM_IFACE_HWDEP
,
136 .access
= SNDRV_CTL_ELEM_ACCESS_READWRITE
,
138 .info
= control_info
,
141 /* name and private_value filled later */
144 struct caiaq_controller
{
149 static struct caiaq_controller ak1_controller
[] = {
156 static struct caiaq_controller rk2_controller
[] = {
164 { "LED 7seg_1b", 8 },
165 { "LED 7seg_1c", 9 },
166 { "LED 7seg_2a", 10 },
167 { "LED 7seg_2b", 11 },
168 { "LED 7seg_2c", 12 },
169 { "LED 7seg_2d", 13 },
170 { "LED 7seg_2e", 14 },
171 { "LED 7seg_2f", 15 },
172 { "LED 7seg_2g", 16 },
173 { "LED 7seg_3a", 17 },
174 { "LED 7seg_3b", 18 },
175 { "LED 7seg_3c", 19 },
176 { "LED 7seg_3d", 20 },
177 { "LED 7seg_3e", 21 },
178 { "LED 7seg_3f", 22 },
179 { "LED 7seg_3g", 23 }
182 static struct caiaq_controller rk3_controller
[] = {
183 { "LED 7seg_1a", 0 + 0 },
184 { "LED 7seg_1b", 0 + 1 },
185 { "LED 7seg_1c", 0 + 2 },
186 { "LED 7seg_1d", 0 + 3 },
187 { "LED 7seg_1e", 0 + 4 },
188 { "LED 7seg_1f", 0 + 5 },
189 { "LED 7seg_1g", 0 + 6 },
190 { "LED 7seg_1p", 0 + 7 },
192 { "LED 7seg_2a", 8 + 0 },
193 { "LED 7seg_2b", 8 + 1 },
194 { "LED 7seg_2c", 8 + 2 },
195 { "LED 7seg_2d", 8 + 3 },
196 { "LED 7seg_2e", 8 + 4 },
197 { "LED 7seg_2f", 8 + 5 },
198 { "LED 7seg_2g", 8 + 6 },
199 { "LED 7seg_2p", 8 + 7 },
201 { "LED 7seg_3a", 16 + 0 },
202 { "LED 7seg_3b", 16 + 1 },
203 { "LED 7seg_3c", 16 + 2 },
204 { "LED 7seg_3d", 16 + 3 },
205 { "LED 7seg_3e", 16 + 4 },
206 { "LED 7seg_3f", 16 + 5 },
207 { "LED 7seg_3g", 16 + 6 },
208 { "LED 7seg_3p", 16 + 7 },
210 { "LED 7seg_4a", 24 + 0 },
211 { "LED 7seg_4b", 24 + 1 },
212 { "LED 7seg_4c", 24 + 2 },
213 { "LED 7seg_4d", 24 + 3 },
214 { "LED 7seg_4e", 24 + 4 },
215 { "LED 7seg_4f", 24 + 5 },
216 { "LED 7seg_4g", 24 + 6 },
217 { "LED 7seg_4p", 24 + 7 },
227 { "LED pedal", 32 + 8 }
230 static struct caiaq_controller kore_controller
[] = {
231 { "LED F1", 8 | CNT_INTVAL
},
232 { "LED F2", 12 | CNT_INTVAL
},
233 { "LED F3", 0 | CNT_INTVAL
},
234 { "LED F4", 4 | CNT_INTVAL
},
235 { "LED F5", 11 | CNT_INTVAL
},
236 { "LED F6", 15 | CNT_INTVAL
},
237 { "LED F7", 3 | CNT_INTVAL
},
238 { "LED F8", 7 | CNT_INTVAL
},
239 { "LED touch1", 10 | CNT_INTVAL
},
240 { "LED touch2", 14 | CNT_INTVAL
},
241 { "LED touch3", 2 | CNT_INTVAL
},
242 { "LED touch4", 6 | CNT_INTVAL
},
243 { "LED touch5", 9 | CNT_INTVAL
},
244 { "LED touch6", 13 | CNT_INTVAL
},
245 { "LED touch7", 1 | CNT_INTVAL
},
246 { "LED touch8", 5 | CNT_INTVAL
},
247 { "LED left", 18 | CNT_INTVAL
},
248 { "LED right", 22 | CNT_INTVAL
},
249 { "LED up", 16 | CNT_INTVAL
},
250 { "LED down", 20 | CNT_INTVAL
},
251 { "LED stop", 23 | CNT_INTVAL
},
252 { "LED play", 21 | CNT_INTVAL
},
253 { "LED record", 19 | CNT_INTVAL
},
254 { "LED listen", 17 | CNT_INTVAL
},
255 { "LED lcd", 30 | CNT_INTVAL
},
256 { "LED menu", 28 | CNT_INTVAL
},
257 { "LED sound", 31 | CNT_INTVAL
},
258 { "LED esc", 29 | CNT_INTVAL
},
259 { "LED view", 27 | CNT_INTVAL
},
260 { "LED enter", 24 | CNT_INTVAL
},
261 { "LED control", 26 | CNT_INTVAL
}
264 static struct caiaq_controller a8dj_controller
[] = {
265 { "Current input mode", 0 | CNT_INTVAL
},
266 { "GND lift for TC Vinyl mode", 24 + 0 },
267 { "GND lift for TC CD/Line mode", 24 + 1 },
268 { "GND lift for phono mode", 24 + 2 },
269 { "Software lock", 40 }
272 static struct caiaq_controller a4dj_controller
[] = {
273 { "Current input mode", 0 | CNT_INTVAL
}
276 static int __devinit
add_controls(struct caiaq_controller
*c
, int num
,
277 struct snd_usb_caiaqdev
*dev
)
280 struct snd_kcontrol
*kc
;
282 for (i
= 0; i
< num
; i
++, c
++) {
283 kcontrol_template
.name
= c
->name
;
284 kcontrol_template
.private_value
= c
->index
;
285 kc
= snd_ctl_new1(&kcontrol_template
, dev
);
286 ret
= snd_ctl_add(dev
->chip
.card
, kc
);
294 int __devinit
snd_usb_caiaq_control_init(struct snd_usb_caiaqdev
*dev
)
298 switch (dev
->chip
.usb_id
) {
299 case USB_ID(USB_VID_NATIVEINSTRUMENTS
, USB_PID_AK1
):
300 ret
= add_controls(ak1_controller
,
301 ARRAY_SIZE(ak1_controller
), dev
);
304 case USB_ID(USB_VID_NATIVEINSTRUMENTS
, USB_PID_RIGKONTROL2
):
305 ret
= add_controls(rk2_controller
,
306 ARRAY_SIZE(rk2_controller
), dev
);
309 case USB_ID(USB_VID_NATIVEINSTRUMENTS
, USB_PID_RIGKONTROL3
):
310 ret
= add_controls(rk3_controller
,
311 ARRAY_SIZE(rk3_controller
), dev
);
314 case USB_ID(USB_VID_NATIVEINSTRUMENTS
, USB_PID_KORECONTROLLER
):
315 case USB_ID(USB_VID_NATIVEINSTRUMENTS
, USB_PID_KORECONTROLLER2
):
316 ret
= add_controls(kore_controller
,
317 ARRAY_SIZE(kore_controller
), dev
);
320 case USB_ID(USB_VID_NATIVEINSTRUMENTS
, USB_PID_AUDIO8DJ
):
321 ret
= add_controls(a8dj_controller
,
322 ARRAY_SIZE(a8dj_controller
), dev
);
324 case USB_ID(USB_VID_NATIVEINSTRUMENTS
, USB_PID_AUDIO4DJ
):
325 ret
= add_controls(a4dj_controller
,
326 ARRAY_SIZE(a4dj_controller
), dev
);