Commit | Line | Data |
---|---|---|
7b1eda22 DM |
1 | /* |
2 | * USB Audio Driver for ALSA | |
3 | * | |
4 | * Quirks and vendor-specific extensions for mixer interfaces | |
5 | * | |
6 | * Copyright (c) 2002 by Takashi Iwai <tiwai@suse.de> | |
7 | * | |
8 | * Many codes borrowed from audio.c by | |
9 | * Alan Cox (alan@lxorguk.ukuu.org.uk) | |
10 | * Thomas Sailer (sailer@ife.ee.ethz.ch) | |
11 | * | |
066624c6 PR |
12 | * Audio Advantage Micro II support added by: |
13 | * Przemek Rudy (prudy1@o2.pl) | |
7b1eda22 DM |
14 | * |
15 | * This program is free software; you can redistribute it and/or modify | |
16 | * it under the terms of the GNU General Public License as published by | |
17 | * the Free Software Foundation; either version 2 of the License, or | |
18 | * (at your option) any later version. | |
19 | * | |
20 | * This program is distributed in the hope that it will be useful, | |
21 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
22 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
23 | * GNU General Public License for more details. | |
24 | * | |
25 | * You should have received a copy of the GNU General Public License | |
26 | * along with this program; if not, write to the Free Software | |
27 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA | |
28 | */ | |
29 | ||
30 | #include <linux/init.h> | |
36db0456 | 31 | #include <linux/slab.h> |
7b1eda22 DM |
32 | #include <linux/usb.h> |
33 | #include <linux/usb/audio.h> | |
34 | ||
066624c6 | 35 | #include <sound/asoundef.h> |
7b1eda22 DM |
36 | #include <sound/core.h> |
37 | #include <sound/control.h> | |
38 | #include <sound/hwdep.h> | |
39 | #include <sound/info.h> | |
40 | ||
41 | #include "usbaudio.h" | |
f0b5e634 | 42 | #include "mixer.h" |
7b1eda22 DM |
43 | #include "mixer_quirks.h" |
44 | #include "helper.h" | |
45 | ||
d5a0bf6c DM |
46 | extern struct snd_kcontrol_new *snd_usb_feature_unit_ctl; |
47 | ||
b71dad18 MH |
48 | struct std_mono_table { |
49 | unsigned int unitid, control, cmask; | |
50 | int val_type; | |
51 | const char *name; | |
52 | snd_kcontrol_tlv_rw_t *tlv_callback; | |
53 | }; | |
54 | ||
8a4d1d39 FH |
55 | /* private_free callback */ |
56 | static void usb_mixer_elem_free(struct snd_kcontrol *kctl) | |
57 | { | |
58 | kfree(kctl->private_data); | |
59 | kctl->private_data = NULL; | |
60 | } | |
61 | ||
62 | /* This function allows for the creation of standard UAC controls. | |
63 | * See the quirks for M-Audio FTUs or Ebox-44. | |
64 | * If you don't want to set a TLV callback pass NULL. | |
65 | * | |
66 | * Since there doesn't seem to be a devices that needs a multichannel | |
67 | * version, we keep it mono for simplicity. | |
68 | */ | |
9f814105 | 69 | static int snd_create_std_mono_ctl_offset(struct usb_mixer_interface *mixer, |
8a4d1d39 FH |
70 | unsigned int unitid, |
71 | unsigned int control, | |
72 | unsigned int cmask, | |
73 | int val_type, | |
9f814105 | 74 | unsigned int idx_off, |
8a4d1d39 FH |
75 | const char *name, |
76 | snd_kcontrol_tlv_rw_t *tlv_callback) | |
77 | { | |
78 | int err; | |
79 | struct usb_mixer_elem_info *cval; | |
80 | struct snd_kcontrol *kctl; | |
81 | ||
82 | cval = kzalloc(sizeof(*cval), GFP_KERNEL); | |
83 | if (!cval) | |
84 | return -ENOMEM; | |
85 | ||
86 | cval->id = unitid; | |
87 | cval->mixer = mixer; | |
88 | cval->val_type = val_type; | |
89 | cval->channels = 1; | |
90 | cval->control = control; | |
91 | cval->cmask = cmask; | |
9f814105 | 92 | cval->idx_off = idx_off; |
8a4d1d39 | 93 | |
7df4a691 MH |
94 | /* get_min_max() is called only for integer volumes later, |
95 | * so provide a short-cut for booleans */ | |
8a4d1d39 FH |
96 | cval->min = 0; |
97 | cval->max = 1; | |
98 | cval->res = 0; | |
99 | cval->dBmin = 0; | |
100 | cval->dBmax = 0; | |
101 | ||
102 | /* Create control */ | |
103 | kctl = snd_ctl_new1(snd_usb_feature_unit_ctl, cval); | |
104 | if (!kctl) { | |
105 | kfree(cval); | |
106 | return -ENOMEM; | |
107 | } | |
108 | ||
109 | /* Set name */ | |
110 | snprintf(kctl->id.name, sizeof(kctl->id.name), name); | |
111 | kctl->private_free = usb_mixer_elem_free; | |
112 | ||
113 | /* set TLV */ | |
114 | if (tlv_callback) { | |
115 | kctl->tlv.c = tlv_callback; | |
116 | kctl->vd[0].access |= | |
117 | SNDRV_CTL_ELEM_ACCESS_TLV_READ | | |
118 | SNDRV_CTL_ELEM_ACCESS_TLV_CALLBACK; | |
119 | } | |
120 | /* Add control to mixer */ | |
121 | err = snd_usb_mixer_add_control(mixer, kctl); | |
122 | if (err < 0) | |
123 | return err; | |
124 | ||
125 | return 0; | |
126 | } | |
127 | ||
9f814105 EZ |
128 | static int snd_create_std_mono_ctl(struct usb_mixer_interface *mixer, |
129 | unsigned int unitid, | |
130 | unsigned int control, | |
131 | unsigned int cmask, | |
132 | int val_type, | |
133 | const char *name, | |
134 | snd_kcontrol_tlv_rw_t *tlv_callback) | |
135 | { | |
136 | return snd_create_std_mono_ctl_offset(mixer, unitid, control, cmask, | |
137 | val_type, 0 /* Offset */, name, tlv_callback); | |
138 | } | |
139 | ||
b71dad18 MH |
140 | /* |
141 | * Create a set of standard UAC controls from a table | |
142 | */ | |
143 | static int snd_create_std_mono_table(struct usb_mixer_interface *mixer, | |
144 | struct std_mono_table *t) | |
145 | { | |
146 | int err; | |
147 | ||
148 | while (t->name != NULL) { | |
149 | err = snd_create_std_mono_ctl(mixer, t->unitid, t->control, | |
150 | t->cmask, t->val_type, t->name, t->tlv_callback); | |
151 | if (err < 0) | |
152 | return err; | |
153 | t++; | |
154 | } | |
155 | ||
156 | return 0; | |
157 | } | |
158 | ||
7b1eda22 DM |
159 | /* |
160 | * Sound Blaster remote control configuration | |
161 | * | |
162 | * format of remote control data: | |
163 | * Extigy: xx 00 | |
164 | * Audigy 2 NX: 06 80 xx 00 00 00 | |
165 | * Live! 24-bit: 06 80 xx yy 22 83 | |
166 | */ | |
167 | static const struct rc_config { | |
168 | u32 usb_id; | |
169 | u8 offset; | |
170 | u8 length; | |
171 | u8 packet_length; | |
172 | u8 min_packet_length; /* minimum accepted length of the URB result */ | |
173 | u8 mute_mixer_id; | |
174 | u32 mute_code; | |
175 | } rc_configs[] = { | |
176 | { USB_ID(0x041e, 0x3000), 0, 1, 2, 1, 18, 0x0013 }, /* Extigy */ | |
177 | { USB_ID(0x041e, 0x3020), 2, 1, 6, 6, 18, 0x0013 }, /* Audigy 2 NX */ | |
178 | { USB_ID(0x041e, 0x3040), 2, 2, 6, 6, 2, 0x6e91 }, /* Live! 24-bit */ | |
ca8dc34e | 179 | { USB_ID(0x041e, 0x3042), 0, 1, 1, 1, 1, 0x000d }, /* Usb X-Fi S51 */ |
7cdd8d73 | 180 | { USB_ID(0x041e, 0x30df), 0, 1, 1, 1, 1, 0x000d }, /* Usb X-Fi S51 Pro */ |
7b1eda22 DM |
181 | { USB_ID(0x041e, 0x3048), 2, 2, 6, 6, 2, 0x6e91 }, /* Toshiba SB0500 */ |
182 | }; | |
183 | ||
184 | static void snd_usb_soundblaster_remote_complete(struct urb *urb) | |
185 | { | |
186 | struct usb_mixer_interface *mixer = urb->context; | |
187 | const struct rc_config *rc = mixer->rc_cfg; | |
188 | u32 code; | |
189 | ||
190 | if (urb->status < 0 || urb->actual_length < rc->min_packet_length) | |
191 | return; | |
192 | ||
193 | code = mixer->rc_buffer[rc->offset]; | |
194 | if (rc->length == 2) | |
195 | code |= mixer->rc_buffer[rc->offset + 1] << 8; | |
196 | ||
197 | /* the Mute button actually changes the mixer control */ | |
198 | if (code == rc->mute_code) | |
199 | snd_usb_mixer_notify_id(mixer, rc->mute_mixer_id); | |
200 | mixer->rc_code = code; | |
201 | wmb(); | |
202 | wake_up(&mixer->rc_waitq); | |
203 | } | |
204 | ||
205 | static long snd_usb_sbrc_hwdep_read(struct snd_hwdep *hw, char __user *buf, | |
206 | long count, loff_t *offset) | |
207 | { | |
208 | struct usb_mixer_interface *mixer = hw->private_data; | |
209 | int err; | |
210 | u32 rc_code; | |
211 | ||
212 | if (count != 1 && count != 4) | |
213 | return -EINVAL; | |
214 | err = wait_event_interruptible(mixer->rc_waitq, | |
215 | (rc_code = xchg(&mixer->rc_code, 0)) != 0); | |
216 | if (err == 0) { | |
217 | if (count == 1) | |
218 | err = put_user(rc_code, buf); | |
219 | else | |
220 | err = put_user(rc_code, (u32 __user *)buf); | |
221 | } | |
222 | return err < 0 ? err : count; | |
223 | } | |
224 | ||
225 | static unsigned int snd_usb_sbrc_hwdep_poll(struct snd_hwdep *hw, struct file *file, | |
226 | poll_table *wait) | |
227 | { | |
228 | struct usb_mixer_interface *mixer = hw->private_data; | |
229 | ||
230 | poll_wait(file, &mixer->rc_waitq, wait); | |
231 | return mixer->rc_code ? POLLIN | POLLRDNORM : 0; | |
232 | } | |
233 | ||
234 | static int snd_usb_soundblaster_remote_init(struct usb_mixer_interface *mixer) | |
235 | { | |
236 | struct snd_hwdep *hwdep; | |
237 | int err, len, i; | |
238 | ||
239 | for (i = 0; i < ARRAY_SIZE(rc_configs); ++i) | |
240 | if (rc_configs[i].usb_id == mixer->chip->usb_id) | |
241 | break; | |
242 | if (i >= ARRAY_SIZE(rc_configs)) | |
243 | return 0; | |
244 | mixer->rc_cfg = &rc_configs[i]; | |
245 | ||
246 | len = mixer->rc_cfg->packet_length; | |
247 | ||
248 | init_waitqueue_head(&mixer->rc_waitq); | |
249 | err = snd_hwdep_new(mixer->chip->card, "SB remote control", 0, &hwdep); | |
250 | if (err < 0) | |
251 | return err; | |
252 | snprintf(hwdep->name, sizeof(hwdep->name), | |
253 | "%s remote control", mixer->chip->card->shortname); | |
254 | hwdep->iface = SNDRV_HWDEP_IFACE_SB_RC; | |
255 | hwdep->private_data = mixer; | |
256 | hwdep->ops.read = snd_usb_sbrc_hwdep_read; | |
257 | hwdep->ops.poll = snd_usb_sbrc_hwdep_poll; | |
258 | hwdep->exclusive = 1; | |
259 | ||
260 | mixer->rc_urb = usb_alloc_urb(0, GFP_KERNEL); | |
261 | if (!mixer->rc_urb) | |
262 | return -ENOMEM; | |
263 | mixer->rc_setup_packet = kmalloc(sizeof(*mixer->rc_setup_packet), GFP_KERNEL); | |
264 | if (!mixer->rc_setup_packet) { | |
265 | usb_free_urb(mixer->rc_urb); | |
266 | mixer->rc_urb = NULL; | |
267 | return -ENOMEM; | |
268 | } | |
269 | mixer->rc_setup_packet->bRequestType = | |
270 | USB_DIR_IN | USB_TYPE_CLASS | USB_RECIP_INTERFACE; | |
271 | mixer->rc_setup_packet->bRequest = UAC_GET_MEM; | |
272 | mixer->rc_setup_packet->wValue = cpu_to_le16(0); | |
273 | mixer->rc_setup_packet->wIndex = cpu_to_le16(0); | |
274 | mixer->rc_setup_packet->wLength = cpu_to_le16(len); | |
275 | usb_fill_control_urb(mixer->rc_urb, mixer->chip->dev, | |
276 | usb_rcvctrlpipe(mixer->chip->dev, 0), | |
277 | (u8*)mixer->rc_setup_packet, mixer->rc_buffer, len, | |
278 | snd_usb_soundblaster_remote_complete, mixer); | |
279 | return 0; | |
280 | } | |
281 | ||
282 | #define snd_audigy2nx_led_info snd_ctl_boolean_mono_info | |
283 | ||
284 | static int snd_audigy2nx_led_get(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol) | |
285 | { | |
286 | struct usb_mixer_interface *mixer = snd_kcontrol_chip(kcontrol); | |
287 | int index = kcontrol->private_value; | |
288 | ||
289 | ucontrol->value.integer.value[0] = mixer->audigy2nx_leds[index]; | |
290 | return 0; | |
291 | } | |
292 | ||
293 | static int snd_audigy2nx_led_put(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol) | |
294 | { | |
295 | struct usb_mixer_interface *mixer = snd_kcontrol_chip(kcontrol); | |
296 | int index = kcontrol->private_value; | |
297 | int value = ucontrol->value.integer.value[0]; | |
298 | int err, changed; | |
299 | ||
300 | if (value > 1) | |
301 | return -EINVAL; | |
302 | changed = value != mixer->audigy2nx_leds[index]; | |
888ea7d5 TI |
303 | down_read(&mixer->chip->shutdown_rwsem); |
304 | if (mixer->chip->shutdown) { | |
305 | err = -ENODEV; | |
306 | goto out; | |
307 | } | |
ca8dc34e MJ |
308 | if (mixer->chip->usb_id == USB_ID(0x041e, 0x3042)) |
309 | err = snd_usb_ctl_msg(mixer->chip->dev, | |
310 | usb_sndctrlpipe(mixer->chip->dev, 0), 0x24, | |
311 | USB_DIR_OUT | USB_TYPE_VENDOR | USB_RECIP_OTHER, | |
17d900c4 | 312 | !value, 0, NULL, 0); |
7cdd8d73 MB |
313 | /* USB X-Fi S51 Pro */ |
314 | if (mixer->chip->usb_id == USB_ID(0x041e, 0x30df)) | |
315 | err = snd_usb_ctl_msg(mixer->chip->dev, | |
316 | usb_sndctrlpipe(mixer->chip->dev, 0), 0x24, | |
317 | USB_DIR_OUT | USB_TYPE_VENDOR | USB_RECIP_OTHER, | |
17d900c4 | 318 | !value, 0, NULL, 0); |
ca8dc34e MJ |
319 | else |
320 | err = snd_usb_ctl_msg(mixer->chip->dev, | |
7b1eda22 DM |
321 | usb_sndctrlpipe(mixer->chip->dev, 0), 0x24, |
322 | USB_DIR_OUT | USB_TYPE_VENDOR | USB_RECIP_OTHER, | |
17d900c4 | 323 | value, index + 2, NULL, 0); |
888ea7d5 TI |
324 | out: |
325 | up_read(&mixer->chip->shutdown_rwsem); | |
7b1eda22 DM |
326 | if (err < 0) |
327 | return err; | |
328 | mixer->audigy2nx_leds[index] = value; | |
329 | return changed; | |
330 | } | |
331 | ||
332 | static struct snd_kcontrol_new snd_audigy2nx_controls[] = { | |
333 | { | |
334 | .iface = SNDRV_CTL_ELEM_IFACE_MIXER, | |
335 | .name = "CMSS LED Switch", | |
336 | .info = snd_audigy2nx_led_info, | |
337 | .get = snd_audigy2nx_led_get, | |
338 | .put = snd_audigy2nx_led_put, | |
339 | .private_value = 0, | |
340 | }, | |
341 | { | |
342 | .iface = SNDRV_CTL_ELEM_IFACE_MIXER, | |
343 | .name = "Power LED Switch", | |
344 | .info = snd_audigy2nx_led_info, | |
345 | .get = snd_audigy2nx_led_get, | |
346 | .put = snd_audigy2nx_led_put, | |
347 | .private_value = 1, | |
348 | }, | |
349 | { | |
350 | .iface = SNDRV_CTL_ELEM_IFACE_MIXER, | |
351 | .name = "Dolby Digital LED Switch", | |
352 | .info = snd_audigy2nx_led_info, | |
353 | .get = snd_audigy2nx_led_get, | |
354 | .put = snd_audigy2nx_led_put, | |
355 | .private_value = 2, | |
356 | }, | |
357 | }; | |
358 | ||
359 | static int snd_audigy2nx_controls_create(struct usb_mixer_interface *mixer) | |
360 | { | |
361 | int i, err; | |
362 | ||
363 | for (i = 0; i < ARRAY_SIZE(snd_audigy2nx_controls); ++i) { | |
ca8dc34e MJ |
364 | /* USB X-Fi S51 doesn't have a CMSS LED */ |
365 | if ((mixer->chip->usb_id == USB_ID(0x041e, 0x3042)) && i == 0) | |
366 | continue; | |
7cdd8d73 MB |
367 | /* USB X-Fi S51 Pro doesn't have one either */ |
368 | if ((mixer->chip->usb_id == USB_ID(0x041e, 0x30df)) && i == 0) | |
369 | continue; | |
7b1eda22 DM |
370 | if (i > 1 && /* Live24ext has 2 LEDs only */ |
371 | (mixer->chip->usb_id == USB_ID(0x041e, 0x3040) || | |
ca8dc34e | 372 | mixer->chip->usb_id == USB_ID(0x041e, 0x3042) || |
7cdd8d73 | 373 | mixer->chip->usb_id == USB_ID(0x041e, 0x30df) || |
7b1eda22 DM |
374 | mixer->chip->usb_id == USB_ID(0x041e, 0x3048))) |
375 | break; | |
376 | err = snd_ctl_add(mixer->chip->card, | |
377 | snd_ctl_new1(&snd_audigy2nx_controls[i], mixer)); | |
378 | if (err < 0) | |
379 | return err; | |
380 | } | |
381 | mixer->audigy2nx_leds[1] = 1; /* Power LED is on by default */ | |
382 | return 0; | |
383 | } | |
384 | ||
385 | static void snd_audigy2nx_proc_read(struct snd_info_entry *entry, | |
386 | struct snd_info_buffer *buffer) | |
387 | { | |
388 | static const struct sb_jack { | |
389 | int unitid; | |
390 | const char *name; | |
391 | } jacks_audigy2nx[] = { | |
392 | {4, "dig in "}, | |
393 | {7, "line in"}, | |
394 | {19, "spk out"}, | |
395 | {20, "hph out"}, | |
396 | {-1, NULL} | |
397 | }, jacks_live24ext[] = { | |
398 | {4, "line in"}, /* &1=Line, &2=Mic*/ | |
399 | {3, "hph out"}, /* headphones */ | |
400 | {0, "RC "}, /* last command, 6 bytes see rc_config above */ | |
401 | {-1, NULL} | |
402 | }; | |
403 | const struct sb_jack *jacks; | |
404 | struct usb_mixer_interface *mixer = entry->private_data; | |
405 | int i, err; | |
406 | u8 buf[3]; | |
407 | ||
408 | snd_iprintf(buffer, "%s jacks\n\n", mixer->chip->card->shortname); | |
409 | if (mixer->chip->usb_id == USB_ID(0x041e, 0x3020)) | |
410 | jacks = jacks_audigy2nx; | |
411 | else if (mixer->chip->usb_id == USB_ID(0x041e, 0x3040) || | |
412 | mixer->chip->usb_id == USB_ID(0x041e, 0x3048)) | |
413 | jacks = jacks_live24ext; | |
414 | else | |
415 | return; | |
416 | ||
417 | for (i = 0; jacks[i].name; ++i) { | |
418 | snd_iprintf(buffer, "%s: ", jacks[i].name); | |
888ea7d5 TI |
419 | down_read(&mixer->chip->shutdown_rwsem); |
420 | if (mixer->chip->shutdown) | |
421 | err = 0; | |
422 | else | |
423 | err = snd_usb_ctl_msg(mixer->chip->dev, | |
7b1eda22 DM |
424 | usb_rcvctrlpipe(mixer->chip->dev, 0), |
425 | UAC_GET_MEM, USB_DIR_IN | USB_TYPE_CLASS | | |
426 | USB_RECIP_INTERFACE, 0, | |
17d900c4 | 427 | jacks[i].unitid << 8, buf, 3); |
888ea7d5 | 428 | up_read(&mixer->chip->shutdown_rwsem); |
7b1eda22 DM |
429 | if (err == 3 && (buf[0] == 3 || buf[0] == 6)) |
430 | snd_iprintf(buffer, "%02x %02x\n", buf[1], buf[2]); | |
431 | else | |
432 | snd_iprintf(buffer, "?\n"); | |
433 | } | |
434 | } | |
435 | ||
44832a71 VK |
436 | /* EMU0204 */ |
437 | static int snd_emu0204_ch_switch_info(struct snd_kcontrol *kcontrol, | |
438 | struct snd_ctl_elem_info *uinfo) | |
439 | { | |
7bbd03e0 | 440 | static const char * const texts[2] = {"1/2", "3/4"}; |
44832a71 | 441 | |
7bbd03e0 | 442 | return snd_ctl_enum_info(uinfo, 1, ARRAY_SIZE(texts), texts); |
44832a71 VK |
443 | } |
444 | ||
445 | static int snd_emu0204_ch_switch_get(struct snd_kcontrol *kcontrol, | |
446 | struct snd_ctl_elem_value *ucontrol) | |
447 | { | |
448 | ucontrol->value.enumerated.item[0] = kcontrol->private_value; | |
449 | return 0; | |
450 | } | |
451 | ||
452 | static int snd_emu0204_ch_switch_put(struct snd_kcontrol *kcontrol, | |
453 | struct snd_ctl_elem_value *ucontrol) | |
454 | { | |
455 | struct usb_mixer_interface *mixer = snd_kcontrol_chip(kcontrol); | |
456 | unsigned int value = ucontrol->value.enumerated.item[0]; | |
457 | int err, changed; | |
458 | unsigned char buf[2]; | |
459 | ||
460 | if (value > 1) | |
461 | return -EINVAL; | |
462 | ||
463 | buf[0] = 0x01; | |
464 | buf[1] = value ? 0x02 : 0x01; | |
465 | ||
466 | changed = value != kcontrol->private_value; | |
467 | down_read(&mixer->chip->shutdown_rwsem); | |
468 | if (mixer->chip->shutdown) { | |
469 | err = -ENODEV; | |
470 | goto out; | |
471 | } | |
472 | err = snd_usb_ctl_msg(mixer->chip->dev, | |
473 | usb_sndctrlpipe(mixer->chip->dev, 0), UAC_SET_CUR, | |
474 | USB_RECIP_INTERFACE | USB_TYPE_CLASS | USB_DIR_OUT, | |
475 | 0x0400, 0x0e00, buf, 2); | |
476 | out: | |
477 | up_read(&mixer->chip->shutdown_rwsem); | |
478 | if (err < 0) | |
479 | return err; | |
480 | kcontrol->private_value = value; | |
481 | return changed; | |
482 | } | |
483 | ||
484 | ||
485 | static struct snd_kcontrol_new snd_emu0204_controls[] = { | |
486 | { | |
487 | .iface = SNDRV_CTL_ELEM_IFACE_MIXER, | |
488 | .name = "Front Jack Channels", | |
489 | .info = snd_emu0204_ch_switch_info, | |
490 | .get = snd_emu0204_ch_switch_get, | |
491 | .put = snd_emu0204_ch_switch_put, | |
492 | .private_value = 0, | |
493 | }, | |
494 | }; | |
495 | ||
496 | static int snd_emu0204_controls_create(struct usb_mixer_interface *mixer) | |
497 | { | |
498 | int i, err; | |
499 | ||
500 | for (i = 0; i < ARRAY_SIZE(snd_emu0204_controls); ++i) { | |
501 | err = snd_ctl_add(mixer->chip->card, | |
502 | snd_ctl_new1(&snd_emu0204_controls[i], mixer)); | |
503 | if (err < 0) | |
504 | return err; | |
505 | } | |
506 | ||
507 | return 0; | |
508 | } | |
1d31affb DW |
509 | /* ASUS Xonar U1 / U3 controls */ |
510 | ||
7b1eda22 DM |
511 | static int snd_xonar_u1_switch_get(struct snd_kcontrol *kcontrol, |
512 | struct snd_ctl_elem_value *ucontrol) | |
513 | { | |
514 | struct usb_mixer_interface *mixer = snd_kcontrol_chip(kcontrol); | |
515 | ||
516 | ucontrol->value.integer.value[0] = !!(mixer->xonar_u1_status & 0x02); | |
517 | return 0; | |
518 | } | |
519 | ||
520 | static int snd_xonar_u1_switch_put(struct snd_kcontrol *kcontrol, | |
521 | struct snd_ctl_elem_value *ucontrol) | |
522 | { | |
523 | struct usb_mixer_interface *mixer = snd_kcontrol_chip(kcontrol); | |
524 | u8 old_status, new_status; | |
525 | int err, changed; | |
526 | ||
527 | old_status = mixer->xonar_u1_status; | |
528 | if (ucontrol->value.integer.value[0]) | |
529 | new_status = old_status | 0x02; | |
530 | else | |
531 | new_status = old_status & ~0x02; | |
532 | changed = new_status != old_status; | |
888ea7d5 TI |
533 | down_read(&mixer->chip->shutdown_rwsem); |
534 | if (mixer->chip->shutdown) | |
535 | err = -ENODEV; | |
536 | else | |
537 | err = snd_usb_ctl_msg(mixer->chip->dev, | |
7b1eda22 DM |
538 | usb_sndctrlpipe(mixer->chip->dev, 0), 0x08, |
539 | USB_DIR_OUT | USB_TYPE_VENDOR | USB_RECIP_OTHER, | |
17d900c4 | 540 | 50, 0, &new_status, 1); |
888ea7d5 | 541 | up_read(&mixer->chip->shutdown_rwsem); |
7b1eda22 DM |
542 | if (err < 0) |
543 | return err; | |
544 | mixer->xonar_u1_status = new_status; | |
545 | return changed; | |
546 | } | |
547 | ||
548 | static struct snd_kcontrol_new snd_xonar_u1_output_switch = { | |
549 | .iface = SNDRV_CTL_ELEM_IFACE_MIXER, | |
550 | .name = "Digital Playback Switch", | |
551 | .info = snd_ctl_boolean_mono_info, | |
552 | .get = snd_xonar_u1_switch_get, | |
553 | .put = snd_xonar_u1_switch_put, | |
554 | }; | |
555 | ||
556 | static int snd_xonar_u1_controls_create(struct usb_mixer_interface *mixer) | |
557 | { | |
558 | int err; | |
559 | ||
560 | err = snd_ctl_add(mixer->chip->card, | |
561 | snd_ctl_new1(&snd_xonar_u1_output_switch, mixer)); | |
562 | if (err < 0) | |
563 | return err; | |
564 | mixer->xonar_u1_status = 0x05; | |
565 | return 0; | |
566 | } | |
567 | ||
d497a82f DZ |
568 | /* Digidesign Mbox 1 clock source switch (internal/spdif) */ |
569 | ||
570 | static int snd_mbox1_switch_get(struct snd_kcontrol *kctl, | |
571 | struct snd_ctl_elem_value *ucontrol) | |
572 | { | |
573 | ucontrol->value.enumerated.item[0] = kctl->private_value; | |
574 | return 0; | |
575 | } | |
576 | ||
577 | static int snd_mbox1_switch_put(struct snd_kcontrol *kctl, | |
578 | struct snd_ctl_elem_value *ucontrol) | |
579 | { | |
580 | struct snd_usb_audio *chip; | |
581 | struct usb_mixer_interface *mixer; | |
582 | int err; | |
583 | bool cur_val, new_val; | |
584 | unsigned char buff[3]; | |
585 | ||
586 | cur_val = kctl->private_value; | |
587 | new_val = ucontrol->value.enumerated.item[0]; | |
588 | ||
589 | mixer = snd_kcontrol_chip(kctl); | |
590 | if (snd_BUG_ON(!mixer)) | |
591 | return -EINVAL; | |
592 | ||
593 | chip = mixer->chip; | |
594 | if (snd_BUG_ON(!chip)) | |
595 | return -EINVAL; | |
596 | ||
597 | if (cur_val == new_val) | |
598 | return 0; | |
599 | ||
600 | down_read(&chip->shutdown_rwsem); | |
601 | if (chip->shutdown) { | |
602 | err = -ENODEV; | |
603 | goto err; | |
604 | } | |
605 | ||
606 | /* Prepare for magic command to toggle clock source */ | |
607 | err = snd_usb_ctl_msg(chip->dev, | |
608 | usb_rcvctrlpipe(chip->dev, 0), 0x81, | |
609 | USB_DIR_IN | | |
610 | USB_TYPE_CLASS | | |
611 | USB_RECIP_INTERFACE, 0x00, 0x500, buff, 1); | |
612 | if (err < 0) | |
613 | goto err; | |
614 | err = snd_usb_ctl_msg(chip->dev, | |
615 | usb_rcvctrlpipe(chip->dev, 0), 0x81, | |
616 | USB_DIR_IN | | |
617 | USB_TYPE_CLASS | | |
618 | USB_RECIP_ENDPOINT, 0x100, 0x81, buff, 3); | |
619 | if (err < 0) | |
620 | goto err; | |
621 | ||
622 | /* 2 possibilities: Internal -> send sample rate | |
623 | * S/PDIF sync -> send zeroes | |
624 | * NB: Sample rate locked to 48kHz on purpose to | |
625 | * prevent user from resetting the sample rate | |
626 | * while S/PDIF sync is enabled and confusing | |
627 | * this configuration. | |
628 | */ | |
629 | if (new_val == 0) { | |
630 | buff[0] = 0x80; | |
631 | buff[1] = 0xbb; | |
632 | buff[2] = 0x00; | |
633 | } else { | |
634 | buff[0] = buff[1] = buff[2] = 0x00; | |
635 | } | |
636 | ||
637 | /* Send the magic command to toggle the clock source */ | |
638 | err = snd_usb_ctl_msg(chip->dev, | |
639 | usb_sndctrlpipe(chip->dev, 0), 0x1, | |
640 | USB_TYPE_CLASS | | |
641 | USB_RECIP_ENDPOINT, 0x100, 0x81, buff, 3); | |
642 | if (err < 0) | |
643 | goto err; | |
644 | err = snd_usb_ctl_msg(chip->dev, | |
645 | usb_rcvctrlpipe(chip->dev, 0), 0x81, | |
646 | USB_DIR_IN | | |
647 | USB_TYPE_CLASS | | |
648 | USB_RECIP_ENDPOINT, 0x100, 0x81, buff, 3); | |
649 | if (err < 0) | |
650 | goto err; | |
651 | err = snd_usb_ctl_msg(chip->dev, | |
652 | usb_rcvctrlpipe(chip->dev, 0), 0x81, | |
653 | USB_DIR_IN | | |
654 | USB_TYPE_CLASS | | |
655 | USB_RECIP_ENDPOINT, 0x100, 0x2, buff, 3); | |
656 | if (err < 0) | |
657 | goto err; | |
658 | kctl->private_value = new_val; | |
659 | ||
660 | err: | |
661 | up_read(&chip->shutdown_rwsem); | |
662 | return err < 0 ? err : 1; | |
663 | } | |
664 | ||
665 | static int snd_mbox1_switch_info(struct snd_kcontrol *kcontrol, | |
666 | struct snd_ctl_elem_info *uinfo) | |
667 | { | |
668 | static const char *const texts[2] = { | |
669 | "Internal", | |
670 | "S/PDIF" | |
671 | }; | |
672 | ||
673 | return snd_ctl_enum_info(uinfo, 1, ARRAY_SIZE(texts), texts); | |
674 | } | |
675 | ||
676 | static struct snd_kcontrol_new snd_mbox1_switch = { | |
677 | .iface = SNDRV_CTL_ELEM_IFACE_MIXER, | |
678 | .name = "Clock Source", | |
679 | .index = 0, | |
680 | .access = SNDRV_CTL_ELEM_ACCESS_READWRITE, | |
681 | .info = snd_mbox1_switch_info, | |
682 | .get = snd_mbox1_switch_get, | |
683 | .put = snd_mbox1_switch_put, | |
684 | .private_value = 0 | |
685 | }; | |
686 | ||
687 | static int snd_mbox1_create_sync_switch(struct usb_mixer_interface *mixer) | |
688 | { | |
689 | return snd_ctl_add(mixer->chip->card, | |
690 | snd_ctl_new1(&snd_mbox1_switch, mixer)); | |
691 | } | |
692 | ||
54a8c500 DM |
693 | /* Native Instruments device quirks */ |
694 | ||
695 | #define _MAKE_NI_CONTROL(bRequest,wIndex) ((bRequest) << 16 | (wIndex)) | |
696 | ||
697 | static int snd_nativeinstruments_control_get(struct snd_kcontrol *kcontrol, | |
698 | struct snd_ctl_elem_value *ucontrol) | |
699 | { | |
700 | struct usb_mixer_interface *mixer = snd_kcontrol_chip(kcontrol); | |
701 | struct usb_device *dev = mixer->chip->dev; | |
702 | u8 bRequest = (kcontrol->private_value >> 16) & 0xff; | |
703 | u16 wIndex = kcontrol->private_value & 0xffff; | |
704 | u8 tmp; | |
888ea7d5 | 705 | int ret; |
54a8c500 | 706 | |
888ea7d5 TI |
707 | down_read(&mixer->chip->shutdown_rwsem); |
708 | if (mixer->chip->shutdown) | |
709 | ret = -ENODEV; | |
710 | else | |
711 | ret = usb_control_msg(dev, usb_rcvctrlpipe(dev, 0), bRequest, | |
54a8c500 | 712 | USB_TYPE_VENDOR | USB_RECIP_DEVICE | USB_DIR_IN, |
889d6684 | 713 | 0, wIndex, |
54a8c500 | 714 | &tmp, sizeof(tmp), 1000); |
888ea7d5 | 715 | up_read(&mixer->chip->shutdown_rwsem); |
54a8c500 DM |
716 | |
717 | if (ret < 0) { | |
0ba41d91 TI |
718 | dev_err(&dev->dev, |
719 | "unable to issue vendor read request (ret = %d)", ret); | |
54a8c500 DM |
720 | return ret; |
721 | } | |
722 | ||
723 | ucontrol->value.integer.value[0] = tmp; | |
724 | ||
725 | return 0; | |
726 | } | |
727 | ||
728 | static int snd_nativeinstruments_control_put(struct snd_kcontrol *kcontrol, | |
729 | struct snd_ctl_elem_value *ucontrol) | |
730 | { | |
731 | struct usb_mixer_interface *mixer = snd_kcontrol_chip(kcontrol); | |
732 | struct usb_device *dev = mixer->chip->dev; | |
733 | u8 bRequest = (kcontrol->private_value >> 16) & 0xff; | |
734 | u16 wIndex = kcontrol->private_value & 0xffff; | |
735 | u16 wValue = ucontrol->value.integer.value[0]; | |
888ea7d5 | 736 | int ret; |
54a8c500 | 737 | |
888ea7d5 TI |
738 | down_read(&mixer->chip->shutdown_rwsem); |
739 | if (mixer->chip->shutdown) | |
740 | ret = -ENODEV; | |
741 | else | |
742 | ret = usb_control_msg(dev, usb_sndctrlpipe(dev, 0), bRequest, | |
54a8c500 | 743 | USB_TYPE_VENDOR | USB_RECIP_DEVICE | USB_DIR_OUT, |
889d6684 | 744 | wValue, wIndex, |
54a8c500 | 745 | NULL, 0, 1000); |
888ea7d5 | 746 | up_read(&mixer->chip->shutdown_rwsem); |
54a8c500 DM |
747 | |
748 | if (ret < 0) { | |
0ba41d91 TI |
749 | dev_err(&dev->dev, |
750 | "unable to issue vendor write request (ret = %d)", ret); | |
54a8c500 DM |
751 | return ret; |
752 | } | |
753 | ||
754 | return 0; | |
755 | } | |
756 | ||
757 | static struct snd_kcontrol_new snd_nativeinstruments_ta6_mixers[] = { | |
758 | { | |
759 | .name = "Direct Thru Channel A", | |
760 | .private_value = _MAKE_NI_CONTROL(0x01, 0x03), | |
761 | }, | |
762 | { | |
763 | .name = "Direct Thru Channel B", | |
764 | .private_value = _MAKE_NI_CONTROL(0x01, 0x05), | |
765 | }, | |
766 | { | |
767 | .name = "Phono Input Channel A", | |
768 | .private_value = _MAKE_NI_CONTROL(0x02, 0x03), | |
769 | }, | |
770 | { | |
771 | .name = "Phono Input Channel B", | |
772 | .private_value = _MAKE_NI_CONTROL(0x02, 0x05), | |
773 | }, | |
774 | }; | |
775 | ||
776 | static struct snd_kcontrol_new snd_nativeinstruments_ta10_mixers[] = { | |
777 | { | |
778 | .name = "Direct Thru Channel A", | |
779 | .private_value = _MAKE_NI_CONTROL(0x01, 0x03), | |
780 | }, | |
781 | { | |
782 | .name = "Direct Thru Channel B", | |
783 | .private_value = _MAKE_NI_CONTROL(0x01, 0x05), | |
784 | }, | |
785 | { | |
786 | .name = "Direct Thru Channel C", | |
787 | .private_value = _MAKE_NI_CONTROL(0x01, 0x07), | |
788 | }, | |
789 | { | |
790 | .name = "Direct Thru Channel D", | |
791 | .private_value = _MAKE_NI_CONTROL(0x01, 0x09), | |
792 | }, | |
793 | { | |
794 | .name = "Phono Input Channel A", | |
795 | .private_value = _MAKE_NI_CONTROL(0x02, 0x03), | |
796 | }, | |
797 | { | |
798 | .name = "Phono Input Channel B", | |
799 | .private_value = _MAKE_NI_CONTROL(0x02, 0x05), | |
800 | }, | |
801 | { | |
802 | .name = "Phono Input Channel C", | |
803 | .private_value = _MAKE_NI_CONTROL(0x02, 0x07), | |
804 | }, | |
805 | { | |
806 | .name = "Phono Input Channel D", | |
807 | .private_value = _MAKE_NI_CONTROL(0x02, 0x09), | |
808 | }, | |
809 | }; | |
810 | ||
811 | static int snd_nativeinstruments_create_mixer(struct usb_mixer_interface *mixer, | |
812 | const struct snd_kcontrol_new *kc, | |
813 | unsigned int count) | |
814 | { | |
815 | int i, err = 0; | |
816 | struct snd_kcontrol_new template = { | |
817 | .iface = SNDRV_CTL_ELEM_IFACE_MIXER, | |
818 | .access = SNDRV_CTL_ELEM_ACCESS_READWRITE, | |
819 | .get = snd_nativeinstruments_control_get, | |
820 | .put = snd_nativeinstruments_control_put, | |
821 | .info = snd_ctl_boolean_mono_info, | |
822 | }; | |
823 | ||
824 | for (i = 0; i < count; i++) { | |
825 | struct snd_kcontrol *c; | |
826 | ||
827 | template.name = kc[i].name; | |
828 | template.private_value = kc[i].private_value; | |
829 | ||
830 | c = snd_ctl_new1(&template, mixer); | |
831 | err = snd_ctl_add(mixer->chip->card, c); | |
832 | ||
833 | if (err < 0) | |
834 | break; | |
835 | } | |
836 | ||
837 | return err; | |
838 | } | |
839 | ||
d5a0bf6c | 840 | /* M-Audio FastTrack Ultra quirks */ |
e9a25e04 | 841 | /* FTU Effect switch (also used by C400/C600) */ |
d34bf148 FH |
842 | struct snd_ftu_eff_switch_priv_val { |
843 | struct usb_mixer_interface *mixer; | |
844 | int cached_value; | |
845 | int is_cached; | |
d847ce0e EZ |
846 | int bUnitID; |
847 | int validx; | |
d34bf148 FH |
848 | }; |
849 | ||
850 | static int snd_ftu_eff_switch_info(struct snd_kcontrol *kcontrol, | |
851 | struct snd_ctl_elem_info *uinfo) | |
852 | { | |
7bbd03e0 TI |
853 | static const char *const texts[8] = { |
854 | "Room 1", "Room 2", "Room 3", "Hall 1", | |
855 | "Hall 2", "Plate", "Delay", "Echo" | |
d34bf148 FH |
856 | }; |
857 | ||
7bbd03e0 | 858 | return snd_ctl_enum_info(uinfo, 1, ARRAY_SIZE(texts), texts); |
d34bf148 FH |
859 | } |
860 | ||
861 | static int snd_ftu_eff_switch_get(struct snd_kcontrol *kctl, | |
862 | struct snd_ctl_elem_value *ucontrol) | |
863 | { | |
864 | struct snd_usb_audio *chip; | |
865 | struct usb_mixer_interface *mixer; | |
866 | struct snd_ftu_eff_switch_priv_val *pval; | |
867 | int err; | |
868 | unsigned char value[2]; | |
d847ce0e | 869 | int id, validx; |
d34bf148 | 870 | |
d34bf148 FH |
871 | const int val_len = 2; |
872 | ||
873 | value[0] = 0x00; | |
874 | value[1] = 0x00; | |
875 | ||
876 | pval = (struct snd_ftu_eff_switch_priv_val *) | |
877 | kctl->private_value; | |
878 | ||
879 | if (pval->is_cached) { | |
880 | ucontrol->value.enumerated.item[0] = pval->cached_value; | |
881 | return 0; | |
882 | } | |
883 | ||
884 | mixer = (struct usb_mixer_interface *) pval->mixer; | |
885 | if (snd_BUG_ON(!mixer)) | |
886 | return -EINVAL; | |
887 | ||
888 | chip = (struct snd_usb_audio *) mixer->chip; | |
889 | if (snd_BUG_ON(!chip)) | |
890 | return -EINVAL; | |
891 | ||
d847ce0e EZ |
892 | id = pval->bUnitID; |
893 | validx = pval->validx; | |
d34bf148 | 894 | |
888ea7d5 TI |
895 | down_read(&mixer->chip->shutdown_rwsem); |
896 | if (mixer->chip->shutdown) | |
897 | err = -ENODEV; | |
898 | else | |
899 | err = snd_usb_ctl_msg(chip->dev, | |
d34bf148 FH |
900 | usb_rcvctrlpipe(chip->dev, 0), UAC_GET_CUR, |
901 | USB_RECIP_INTERFACE | USB_TYPE_CLASS | USB_DIR_IN, | |
902 | validx << 8, snd_usb_ctrl_intf(chip) | (id << 8), | |
903 | value, val_len); | |
888ea7d5 | 904 | up_read(&mixer->chip->shutdown_rwsem); |
d34bf148 FH |
905 | if (err < 0) |
906 | return err; | |
907 | ||
908 | ucontrol->value.enumerated.item[0] = value[0]; | |
909 | pval->cached_value = value[0]; | |
910 | pval->is_cached = 1; | |
911 | ||
912 | return 0; | |
913 | } | |
914 | ||
915 | static int snd_ftu_eff_switch_put(struct snd_kcontrol *kctl, | |
916 | struct snd_ctl_elem_value *ucontrol) | |
917 | { | |
918 | struct snd_usb_audio *chip; | |
919 | struct snd_ftu_eff_switch_priv_val *pval; | |
920 | ||
921 | struct usb_mixer_interface *mixer; | |
922 | int changed, cur_val, err, new_val; | |
923 | unsigned char value[2]; | |
d847ce0e | 924 | int id, validx; |
d34bf148 | 925 | |
d34bf148 FH |
926 | const int val_len = 2; |
927 | ||
928 | changed = 0; | |
929 | ||
930 | pval = (struct snd_ftu_eff_switch_priv_val *) | |
931 | kctl->private_value; | |
932 | cur_val = pval->cached_value; | |
933 | new_val = ucontrol->value.enumerated.item[0]; | |
934 | ||
935 | mixer = (struct usb_mixer_interface *) pval->mixer; | |
936 | if (snd_BUG_ON(!mixer)) | |
937 | return -EINVAL; | |
938 | ||
939 | chip = (struct snd_usb_audio *) mixer->chip; | |
940 | if (snd_BUG_ON(!chip)) | |
941 | return -EINVAL; | |
942 | ||
d847ce0e EZ |
943 | id = pval->bUnitID; |
944 | validx = pval->validx; | |
945 | ||
d34bf148 FH |
946 | if (!pval->is_cached) { |
947 | /* Read current value */ | |
888ea7d5 TI |
948 | down_read(&mixer->chip->shutdown_rwsem); |
949 | if (mixer->chip->shutdown) | |
950 | err = -ENODEV; | |
951 | else | |
952 | err = snd_usb_ctl_msg(chip->dev, | |
d34bf148 FH |
953 | usb_rcvctrlpipe(chip->dev, 0), UAC_GET_CUR, |
954 | USB_RECIP_INTERFACE | USB_TYPE_CLASS | USB_DIR_IN, | |
955 | validx << 8, snd_usb_ctrl_intf(chip) | (id << 8), | |
956 | value, val_len); | |
888ea7d5 | 957 | up_read(&mixer->chip->shutdown_rwsem); |
d34bf148 FH |
958 | if (err < 0) |
959 | return err; | |
960 | ||
961 | cur_val = value[0]; | |
962 | pval->cached_value = cur_val; | |
963 | pval->is_cached = 1; | |
964 | } | |
965 | /* update value if needed */ | |
966 | if (cur_val != new_val) { | |
967 | value[0] = new_val; | |
968 | value[1] = 0; | |
888ea7d5 TI |
969 | down_read(&mixer->chip->shutdown_rwsem); |
970 | if (mixer->chip->shutdown) | |
971 | err = -ENODEV; | |
972 | else | |
973 | err = snd_usb_ctl_msg(chip->dev, | |
d34bf148 FH |
974 | usb_sndctrlpipe(chip->dev, 0), UAC_SET_CUR, |
975 | USB_RECIP_INTERFACE | USB_TYPE_CLASS | USB_DIR_OUT, | |
976 | validx << 8, snd_usb_ctrl_intf(chip) | (id << 8), | |
977 | value, val_len); | |
888ea7d5 | 978 | up_read(&mixer->chip->shutdown_rwsem); |
d34bf148 FH |
979 | if (err < 0) |
980 | return err; | |
981 | ||
982 | pval->cached_value = new_val; | |
983 | pval->is_cached = 1; | |
984 | changed = 1; | |
985 | } | |
986 | ||
987 | return changed; | |
988 | } | |
989 | ||
d847ce0e EZ |
990 | static int snd_ftu_create_effect_switch(struct usb_mixer_interface *mixer, |
991 | int validx, int bUnitID) | |
d34bf148 FH |
992 | { |
993 | static struct snd_kcontrol_new template = { | |
994 | .iface = SNDRV_CTL_ELEM_IFACE_MIXER, | |
995 | .name = "Effect Program Switch", | |
996 | .index = 0, | |
997 | .access = SNDRV_CTL_ELEM_ACCESS_READWRITE, | |
998 | .info = snd_ftu_eff_switch_info, | |
999 | .get = snd_ftu_eff_switch_get, | |
1000 | .put = snd_ftu_eff_switch_put | |
1001 | }; | |
1002 | ||
1003 | int err; | |
1004 | struct snd_kcontrol *kctl; | |
1005 | struct snd_ftu_eff_switch_priv_val *pval; | |
1006 | ||
1007 | pval = kzalloc(sizeof(*pval), GFP_KERNEL); | |
1008 | if (!pval) | |
1009 | return -ENOMEM; | |
1010 | ||
1011 | pval->cached_value = 0; | |
1012 | pval->is_cached = 0; | |
1013 | pval->mixer = mixer; | |
d847ce0e EZ |
1014 | pval->bUnitID = bUnitID; |
1015 | pval->validx = validx; | |
d34bf148 FH |
1016 | |
1017 | template.private_value = (unsigned long) pval; | |
1018 | kctl = snd_ctl_new1(&template, mixer->chip); | |
1019 | if (!kctl) { | |
1020 | kfree(pval); | |
1021 | return -ENOMEM; | |
1022 | } | |
1023 | ||
1024 | err = snd_ctl_add(mixer->chip->card, kctl); | |
1025 | if (err < 0) | |
1026 | return err; | |
1027 | ||
1028 | return 0; | |
1029 | } | |
d5a0bf6c | 1030 | |
cfe8f97c FH |
1031 | /* Create volume controls for FTU devices*/ |
1032 | static int snd_ftu_create_volume_ctls(struct usb_mixer_interface *mixer) | |
d5a0bf6c DM |
1033 | { |
1034 | char name[64]; | |
8a4d1d39 | 1035 | unsigned int control, cmask; |
d5a0bf6c DM |
1036 | int in, out, err; |
1037 | ||
8a4d1d39 FH |
1038 | const unsigned int id = 5; |
1039 | const int val_type = USB_MIXER_S16; | |
1040 | ||
d5a0bf6c | 1041 | for (out = 0; out < 8; out++) { |
8a4d1d39 | 1042 | control = out + 1; |
d5a0bf6c | 1043 | for (in = 0; in < 8; in++) { |
8a4d1d39 | 1044 | cmask = 1 << in; |
d5a0bf6c | 1045 | snprintf(name, sizeof(name), |
8a4d1d39 FH |
1046 | "AIn%d - Out%d Capture Volume", |
1047 | in + 1, out + 1); | |
1048 | err = snd_create_std_mono_ctl(mixer, id, control, | |
1049 | cmask, val_type, name, | |
25ee7ef8 | 1050 | &snd_usb_mixer_vol_tlv); |
d5a0bf6c DM |
1051 | if (err < 0) |
1052 | return err; | |
1053 | } | |
d5a0bf6c | 1054 | for (in = 8; in < 16; in++) { |
8a4d1d39 | 1055 | cmask = 1 << in; |
d5a0bf6c | 1056 | snprintf(name, sizeof(name), |
8a4d1d39 FH |
1057 | "DIn%d - Out%d Playback Volume", |
1058 | in - 7, out + 1); | |
1059 | err = snd_create_std_mono_ctl(mixer, id, control, | |
1060 | cmask, val_type, name, | |
25ee7ef8 | 1061 | &snd_usb_mixer_vol_tlv); |
d5a0bf6c DM |
1062 | if (err < 0) |
1063 | return err; | |
1064 | } | |
1065 | } | |
1066 | ||
1067 | return 0; | |
1068 | } | |
1069 | ||
d34bf148 FH |
1070 | /* This control needs a volume quirk, see mixer.c */ |
1071 | static int snd_ftu_create_effect_volume_ctl(struct usb_mixer_interface *mixer) | |
1072 | { | |
1073 | static const char name[] = "Effect Volume"; | |
1074 | const unsigned int id = 6; | |
1075 | const int val_type = USB_MIXER_U8; | |
1076 | const unsigned int control = 2; | |
1077 | const unsigned int cmask = 0; | |
1078 | ||
1079 | return snd_create_std_mono_ctl(mixer, id, control, cmask, val_type, | |
1080 | name, snd_usb_mixer_vol_tlv); | |
1081 | } | |
1082 | ||
1083 | /* This control needs a volume quirk, see mixer.c */ | |
1084 | static int snd_ftu_create_effect_duration_ctl(struct usb_mixer_interface *mixer) | |
1085 | { | |
1086 | static const char name[] = "Effect Duration"; | |
1087 | const unsigned int id = 6; | |
1088 | const int val_type = USB_MIXER_S16; | |
1089 | const unsigned int control = 3; | |
1090 | const unsigned int cmask = 0; | |
1091 | ||
1092 | return snd_create_std_mono_ctl(mixer, id, control, cmask, val_type, | |
1093 | name, snd_usb_mixer_vol_tlv); | |
1094 | } | |
1095 | ||
1096 | /* This control needs a volume quirk, see mixer.c */ | |
1097 | static int snd_ftu_create_effect_feedback_ctl(struct usb_mixer_interface *mixer) | |
1098 | { | |
1099 | static const char name[] = "Effect Feedback Volume"; | |
1100 | const unsigned int id = 6; | |
1101 | const int val_type = USB_MIXER_U8; | |
1102 | const unsigned int control = 4; | |
1103 | const unsigned int cmask = 0; | |
1104 | ||
1105 | return snd_create_std_mono_ctl(mixer, id, control, cmask, val_type, | |
1106 | name, NULL); | |
1107 | } | |
1108 | ||
1109 | static int snd_ftu_create_effect_return_ctls(struct usb_mixer_interface *mixer) | |
1110 | { | |
1111 | unsigned int cmask; | |
1112 | int err, ch; | |
1113 | char name[48]; | |
1114 | ||
1115 | const unsigned int id = 7; | |
1116 | const int val_type = USB_MIXER_S16; | |
1117 | const unsigned int control = 7; | |
1118 | ||
1119 | for (ch = 0; ch < 4; ++ch) { | |
1120 | cmask = 1 << ch; | |
1121 | snprintf(name, sizeof(name), | |
1122 | "Effect Return %d Volume", ch + 1); | |
1123 | err = snd_create_std_mono_ctl(mixer, id, control, | |
1124 | cmask, val_type, name, | |
1125 | snd_usb_mixer_vol_tlv); | |
1126 | if (err < 0) | |
1127 | return err; | |
1128 | } | |
1129 | ||
1130 | return 0; | |
1131 | } | |
1132 | ||
1133 | static int snd_ftu_create_effect_send_ctls(struct usb_mixer_interface *mixer) | |
1134 | { | |
1135 | unsigned int cmask; | |
1136 | int err, ch; | |
1137 | char name[48]; | |
1138 | ||
1139 | const unsigned int id = 5; | |
1140 | const int val_type = USB_MIXER_S16; | |
1141 | const unsigned int control = 9; | |
1142 | ||
1143 | for (ch = 0; ch < 8; ++ch) { | |
1144 | cmask = 1 << ch; | |
1145 | snprintf(name, sizeof(name), | |
1146 | "Effect Send AIn%d Volume", ch + 1); | |
1147 | err = snd_create_std_mono_ctl(mixer, id, control, cmask, | |
1148 | val_type, name, | |
1149 | snd_usb_mixer_vol_tlv); | |
1150 | if (err < 0) | |
1151 | return err; | |
1152 | } | |
1153 | for (ch = 8; ch < 16; ++ch) { | |
1154 | cmask = 1 << ch; | |
1155 | snprintf(name, sizeof(name), | |
1156 | "Effect Send DIn%d Volume", ch - 7); | |
1157 | err = snd_create_std_mono_ctl(mixer, id, control, cmask, | |
1158 | val_type, name, | |
1159 | snd_usb_mixer_vol_tlv); | |
1160 | if (err < 0) | |
1161 | return err; | |
1162 | } | |
1163 | return 0; | |
1164 | } | |
1165 | ||
cfe8f97c | 1166 | static int snd_ftu_create_mixer(struct usb_mixer_interface *mixer) |
7536c301 | 1167 | { |
8a4d1d39 | 1168 | int err; |
7536c301 | 1169 | |
cfe8f97c | 1170 | err = snd_ftu_create_volume_ctls(mixer); |
8a4d1d39 FH |
1171 | if (err < 0) |
1172 | return err; | |
7536c301 | 1173 | |
d847ce0e | 1174 | err = snd_ftu_create_effect_switch(mixer, 1, 6); |
d34bf148 FH |
1175 | if (err < 0) |
1176 | return err; | |
d847ce0e | 1177 | |
d34bf148 FH |
1178 | err = snd_ftu_create_effect_volume_ctl(mixer); |
1179 | if (err < 0) | |
1180 | return err; | |
1181 | ||
1182 | err = snd_ftu_create_effect_duration_ctl(mixer); | |
1183 | if (err < 0) | |
1184 | return err; | |
1185 | ||
1186 | err = snd_ftu_create_effect_feedback_ctl(mixer); | |
1187 | if (err < 0) | |
1188 | return err; | |
1189 | ||
1190 | err = snd_ftu_create_effect_return_ctls(mixer); | |
1191 | if (err < 0) | |
1192 | return err; | |
1193 | ||
1194 | err = snd_ftu_create_effect_send_ctls(mixer); | |
1195 | if (err < 0) | |
1196 | return err; | |
1197 | ||
8a4d1d39 | 1198 | return 0; |
7536c301 MH |
1199 | } |
1200 | ||
7b1eda22 DM |
1201 | void snd_emuusb_set_samplerate(struct snd_usb_audio *chip, |
1202 | unsigned char samplerate_id) | |
1203 | { | |
1204 | struct usb_mixer_interface *mixer; | |
1205 | struct usb_mixer_elem_info *cval; | |
1206 | int unitid = 12; /* SamleRate ExtensionUnit ID */ | |
1207 | ||
1208 | list_for_each_entry(mixer, &chip->mixer_list, list) { | |
1209 | cval = mixer->id_elems[unitid]; | |
1210 | if (cval) { | |
1211 | snd_usb_mixer_set_ctl_value(cval, UAC_SET_CUR, | |
1212 | cval->control << 8, | |
1213 | samplerate_id); | |
1214 | snd_usb_mixer_notify_id(mixer, unitid); | |
1215 | } | |
1216 | break; | |
1217 | } | |
1218 | } | |
1219 | ||
e9a25e04 MG |
1220 | /* M-Audio Fast Track C400/C600 */ |
1221 | /* C400/C600 volume controls, this control needs a volume quirk, see mixer.c */ | |
09d8e3a7 EZ |
1222 | static int snd_c400_create_vol_ctls(struct usb_mixer_interface *mixer) |
1223 | { | |
1224 | char name[64]; | |
1225 | unsigned int cmask, offset; | |
1226 | int out, chan, err; | |
e9a25e04 MG |
1227 | int num_outs = 0; |
1228 | int num_ins = 0; | |
09d8e3a7 EZ |
1229 | |
1230 | const unsigned int id = 0x40; | |
1231 | const int val_type = USB_MIXER_S16; | |
1232 | const int control = 1; | |
1233 | ||
e9a25e04 MG |
1234 | switch (mixer->chip->usb_id) { |
1235 | case USB_ID(0x0763, 0x2030): | |
1236 | num_outs = 6; | |
1237 | num_ins = 4; | |
1238 | break; | |
1239 | case USB_ID(0x0763, 0x2031): | |
1240 | num_outs = 8; | |
1241 | num_ins = 6; | |
1242 | break; | |
1243 | } | |
1244 | ||
1245 | for (chan = 0; chan < num_outs + num_ins; chan++) { | |
1246 | for (out = 0; out < num_outs; out++) { | |
1247 | if (chan < num_outs) { | |
09d8e3a7 EZ |
1248 | snprintf(name, sizeof(name), |
1249 | "PCM%d-Out%d Playback Volume", | |
1250 | chan + 1, out + 1); | |
1251 | } else { | |
1252 | snprintf(name, sizeof(name), | |
1253 | "In%d-Out%d Playback Volume", | |
e9a25e04 | 1254 | chan - num_outs + 1, out + 1); |
09d8e3a7 EZ |
1255 | } |
1256 | ||
1257 | cmask = (out == 0) ? 0 : 1 << (out - 1); | |
e9a25e04 | 1258 | offset = chan * num_outs; |
09d8e3a7 EZ |
1259 | err = snd_create_std_mono_ctl_offset(mixer, id, control, |
1260 | cmask, val_type, offset, name, | |
1261 | &snd_usb_mixer_vol_tlv); | |
1262 | if (err < 0) | |
1263 | return err; | |
1264 | } | |
1265 | } | |
1266 | ||
1267 | return 0; | |
1268 | } | |
1269 | ||
1270 | /* This control needs a volume quirk, see mixer.c */ | |
1271 | static int snd_c400_create_effect_volume_ctl(struct usb_mixer_interface *mixer) | |
1272 | { | |
1273 | static const char name[] = "Effect Volume"; | |
1274 | const unsigned int id = 0x43; | |
1275 | const int val_type = USB_MIXER_U8; | |
1276 | const unsigned int control = 3; | |
1277 | const unsigned int cmask = 0; | |
1278 | ||
1279 | return snd_create_std_mono_ctl(mixer, id, control, cmask, val_type, | |
1280 | name, snd_usb_mixer_vol_tlv); | |
1281 | } | |
1282 | ||
1283 | /* This control needs a volume quirk, see mixer.c */ | |
1284 | static int snd_c400_create_effect_duration_ctl(struct usb_mixer_interface *mixer) | |
1285 | { | |
1286 | static const char name[] = "Effect Duration"; | |
1287 | const unsigned int id = 0x43; | |
1288 | const int val_type = USB_MIXER_S16; | |
1289 | const unsigned int control = 4; | |
1290 | const unsigned int cmask = 0; | |
1291 | ||
1292 | return snd_create_std_mono_ctl(mixer, id, control, cmask, val_type, | |
1293 | name, snd_usb_mixer_vol_tlv); | |
1294 | } | |
1295 | ||
1296 | /* This control needs a volume quirk, see mixer.c */ | |
1297 | static int snd_c400_create_effect_feedback_ctl(struct usb_mixer_interface *mixer) | |
1298 | { | |
1299 | static const char name[] = "Effect Feedback Volume"; | |
1300 | const unsigned int id = 0x43; | |
1301 | const int val_type = USB_MIXER_U8; | |
1302 | const unsigned int control = 5; | |
1303 | const unsigned int cmask = 0; | |
1304 | ||
1305 | return snd_create_std_mono_ctl(mixer, id, control, cmask, val_type, | |
1306 | name, NULL); | |
1307 | } | |
1308 | ||
1309 | static int snd_c400_create_effect_vol_ctls(struct usb_mixer_interface *mixer) | |
1310 | { | |
1311 | char name[64]; | |
1312 | unsigned int cmask; | |
1313 | int chan, err; | |
e9a25e04 MG |
1314 | int num_outs = 0; |
1315 | int num_ins = 0; | |
09d8e3a7 EZ |
1316 | |
1317 | const unsigned int id = 0x42; | |
1318 | const int val_type = USB_MIXER_S16; | |
1319 | const int control = 1; | |
1320 | ||
e9a25e04 MG |
1321 | switch (mixer->chip->usb_id) { |
1322 | case USB_ID(0x0763, 0x2030): | |
1323 | num_outs = 6; | |
1324 | num_ins = 4; | |
1325 | break; | |
1326 | case USB_ID(0x0763, 0x2031): | |
1327 | num_outs = 8; | |
1328 | num_ins = 6; | |
1329 | break; | |
1330 | } | |
1331 | ||
1332 | for (chan = 0; chan < num_outs + num_ins; chan++) { | |
1333 | if (chan < num_outs) { | |
09d8e3a7 EZ |
1334 | snprintf(name, sizeof(name), |
1335 | "Effect Send DOut%d", | |
1336 | chan + 1); | |
1337 | } else { | |
1338 | snprintf(name, sizeof(name), | |
1339 | "Effect Send AIn%d", | |
e9a25e04 | 1340 | chan - num_outs + 1); |
09d8e3a7 EZ |
1341 | } |
1342 | ||
1343 | cmask = (chan == 0) ? 0 : 1 << (chan - 1); | |
1344 | err = snd_create_std_mono_ctl(mixer, id, control, | |
1345 | cmask, val_type, name, | |
1346 | &snd_usb_mixer_vol_tlv); | |
1347 | if (err < 0) | |
1348 | return err; | |
1349 | } | |
1350 | ||
1351 | return 0; | |
1352 | } | |
1353 | ||
1354 | static int snd_c400_create_effect_ret_vol_ctls(struct usb_mixer_interface *mixer) | |
1355 | { | |
1356 | char name[64]; | |
1357 | unsigned int cmask; | |
1358 | int chan, err; | |
e9a25e04 MG |
1359 | int num_outs = 0; |
1360 | int offset = 0; | |
09d8e3a7 EZ |
1361 | |
1362 | const unsigned int id = 0x40; | |
1363 | const int val_type = USB_MIXER_S16; | |
1364 | const int control = 1; | |
09d8e3a7 | 1365 | |
e9a25e04 MG |
1366 | switch (mixer->chip->usb_id) { |
1367 | case USB_ID(0x0763, 0x2030): | |
1368 | num_outs = 6; | |
1369 | offset = 0x3c; | |
1370 | /* { 0x3c, 0x43, 0x3e, 0x45, 0x40, 0x47 } */ | |
1371 | break; | |
1372 | case USB_ID(0x0763, 0x2031): | |
1373 | num_outs = 8; | |
1374 | offset = 0x70; | |
1375 | /* { 0x70, 0x79, 0x72, 0x7b, 0x74, 0x7d, 0x76, 0x7f } */ | |
1376 | break; | |
1377 | } | |
1378 | ||
1379 | for (chan = 0; chan < num_outs; chan++) { | |
09d8e3a7 EZ |
1380 | snprintf(name, sizeof(name), |
1381 | "Effect Return %d", | |
1382 | chan + 1); | |
1383 | ||
e9a25e04 MG |
1384 | cmask = (chan == 0) ? 0 : |
1385 | 1 << (chan + (chan % 2) * num_outs - 1); | |
09d8e3a7 EZ |
1386 | err = snd_create_std_mono_ctl_offset(mixer, id, control, |
1387 | cmask, val_type, offset, name, | |
1388 | &snd_usb_mixer_vol_tlv); | |
1389 | if (err < 0) | |
1390 | return err; | |
1391 | } | |
1392 | ||
1393 | return 0; | |
1394 | } | |
1395 | ||
1396 | static int snd_c400_create_mixer(struct usb_mixer_interface *mixer) | |
1397 | { | |
1398 | int err; | |
1399 | ||
1400 | err = snd_c400_create_vol_ctls(mixer); | |
1401 | if (err < 0) | |
1402 | return err; | |
1403 | ||
1404 | err = snd_c400_create_effect_vol_ctls(mixer); | |
1405 | if (err < 0) | |
1406 | return err; | |
1407 | ||
1408 | err = snd_c400_create_effect_ret_vol_ctls(mixer); | |
1409 | if (err < 0) | |
1410 | return err; | |
1411 | ||
1412 | err = snd_ftu_create_effect_switch(mixer, 2, 0x43); | |
1413 | if (err < 0) | |
1414 | return err; | |
1415 | ||
1416 | err = snd_c400_create_effect_volume_ctl(mixer); | |
1417 | if (err < 0) | |
1418 | return err; | |
1419 | ||
1420 | err = snd_c400_create_effect_duration_ctl(mixer); | |
1421 | if (err < 0) | |
1422 | return err; | |
1423 | ||
1424 | err = snd_c400_create_effect_feedback_ctl(mixer); | |
1425 | if (err < 0) | |
1426 | return err; | |
1427 | ||
1428 | return 0; | |
1429 | } | |
1430 | ||
b71dad18 MH |
1431 | /* |
1432 | * The mixer units for Ebox-44 are corrupt, and even where they | |
1433 | * are valid they presents mono controls as L and R channels of | |
1434 | * stereo. So we provide a good mixer here. | |
1435 | */ | |
e8e7da23 | 1436 | static struct std_mono_table ebox44_table[] = { |
989b0138 MH |
1437 | { |
1438 | .unitid = 4, | |
1439 | .control = 1, | |
1440 | .cmask = 0x0, | |
1441 | .val_type = USB_MIXER_INV_BOOLEAN, | |
1442 | .name = "Headphone Playback Switch" | |
1443 | }, | |
1444 | { | |
1445 | .unitid = 4, | |
1446 | .control = 2, | |
1447 | .cmask = 0x1, | |
1448 | .val_type = USB_MIXER_S16, | |
1449 | .name = "Headphone A Mix Playback Volume" | |
1450 | }, | |
1451 | { | |
1452 | .unitid = 4, | |
1453 | .control = 2, | |
1454 | .cmask = 0x2, | |
1455 | .val_type = USB_MIXER_S16, | |
1456 | .name = "Headphone B Mix Playback Volume" | |
1457 | }, | |
b71dad18 | 1458 | |
989b0138 MH |
1459 | { |
1460 | .unitid = 7, | |
1461 | .control = 1, | |
1462 | .cmask = 0x0, | |
1463 | .val_type = USB_MIXER_INV_BOOLEAN, | |
1464 | .name = "Output Playback Switch" | |
1465 | }, | |
1466 | { | |
1467 | .unitid = 7, | |
1468 | .control = 2, | |
1469 | .cmask = 0x1, | |
1470 | .val_type = USB_MIXER_S16, | |
1471 | .name = "Output A Playback Volume" | |
1472 | }, | |
1473 | { | |
1474 | .unitid = 7, | |
1475 | .control = 2, | |
1476 | .cmask = 0x2, | |
1477 | .val_type = USB_MIXER_S16, | |
1478 | .name = "Output B Playback Volume" | |
1479 | }, | |
b71dad18 | 1480 | |
989b0138 MH |
1481 | { |
1482 | .unitid = 10, | |
1483 | .control = 1, | |
1484 | .cmask = 0x0, | |
1485 | .val_type = USB_MIXER_INV_BOOLEAN, | |
1486 | .name = "Input Capture Switch" | |
1487 | }, | |
1488 | { | |
1489 | .unitid = 10, | |
1490 | .control = 2, | |
1491 | .cmask = 0x1, | |
1492 | .val_type = USB_MIXER_S16, | |
1493 | .name = "Input A Capture Volume" | |
1494 | }, | |
1495 | { | |
1496 | .unitid = 10, | |
1497 | .control = 2, | |
1498 | .cmask = 0x2, | |
1499 | .val_type = USB_MIXER_S16, | |
1500 | .name = "Input B Capture Volume" | |
1501 | }, | |
b71dad18 | 1502 | |
989b0138 | 1503 | {} |
b71dad18 MH |
1504 | }; |
1505 | ||
066624c6 PR |
1506 | /* Audio Advantage Micro II findings: |
1507 | * | |
1508 | * Mapping spdif AES bits to vendor register.bit: | |
1509 | * AES0: [0 0 0 0 2.3 2.2 2.1 2.0] - default 0x00 | |
1510 | * AES1: [3.3 3.2.3.1.3.0 2.7 2.6 2.5 2.4] - default: 0x01 | |
1511 | * AES2: [0 0 0 0 0 0 0 0] | |
1512 | * AES3: [0 0 0 0 0 0 x 0] - 'x' bit is set basing on standard usb request | |
1513 | * (UAC_EP_CS_ATTR_SAMPLE_RATE) for Audio Devices | |
1514 | * | |
1515 | * power on values: | |
1516 | * r2: 0x10 | |
1517 | * r3: 0x20 (b7 is zeroed just before playback (except IEC61937) and set | |
1518 | * just after it to 0xa0, presumably it disables/mutes some analog | |
1519 | * parts when there is no audio.) | |
1520 | * r9: 0x28 | |
1521 | * | |
1522 | * Optical transmitter on/off: | |
1523 | * vendor register.bit: 9.1 | |
1524 | * 0 - on (0x28 register value) | |
1525 | * 1 - off (0x2a register value) | |
1526 | * | |
1527 | */ | |
1528 | static int snd_microii_spdif_info(struct snd_kcontrol *kcontrol, | |
1529 | struct snd_ctl_elem_info *uinfo) | |
1530 | { | |
1531 | uinfo->type = SNDRV_CTL_ELEM_TYPE_IEC958; | |
1532 | uinfo->count = 1; | |
1533 | return 0; | |
1534 | } | |
1535 | ||
1536 | static int snd_microii_spdif_default_get(struct snd_kcontrol *kcontrol, | |
1537 | struct snd_ctl_elem_value *ucontrol) | |
1538 | { | |
1539 | struct usb_mixer_interface *mixer = snd_kcontrol_chip(kcontrol); | |
1540 | int err; | |
1541 | struct usb_interface *iface; | |
1542 | struct usb_host_interface *alts; | |
1543 | unsigned int ep; | |
1544 | unsigned char data[3]; | |
1545 | int rate; | |
1546 | ||
1547 | ucontrol->value.iec958.status[0] = kcontrol->private_value & 0xff; | |
1548 | ucontrol->value.iec958.status[1] = (kcontrol->private_value >> 8) & 0xff; | |
1549 | ucontrol->value.iec958.status[2] = 0x00; | |
1550 | ||
1551 | /* use known values for that card: interface#1 altsetting#1 */ | |
1552 | iface = usb_ifnum_to_if(mixer->chip->dev, 1); | |
1553 | alts = &iface->altsetting[1]; | |
1554 | ep = get_endpoint(alts, 0)->bEndpointAddress; | |
1555 | ||
1556 | err = snd_usb_ctl_msg(mixer->chip->dev, | |
1557 | usb_rcvctrlpipe(mixer->chip->dev, 0), | |
1558 | UAC_GET_CUR, | |
1559 | USB_TYPE_CLASS | USB_RECIP_ENDPOINT | USB_DIR_IN, | |
1560 | UAC_EP_CS_ATTR_SAMPLE_RATE << 8, | |
1561 | ep, | |
1562 | data, | |
1563 | sizeof(data)); | |
1564 | if (err < 0) | |
1565 | goto end; | |
1566 | ||
1567 | rate = data[0] | (data[1] << 8) | (data[2] << 16); | |
1568 | ucontrol->value.iec958.status[3] = (rate == 48000) ? | |
1569 | IEC958_AES3_CON_FS_48000 : IEC958_AES3_CON_FS_44100; | |
1570 | ||
1571 | err = 0; | |
1572 | end: | |
1573 | return err; | |
1574 | } | |
1575 | ||
1576 | static int snd_microii_spdif_default_put(struct snd_kcontrol *kcontrol, | |
1577 | struct snd_ctl_elem_value *ucontrol) | |
1578 | { | |
1579 | struct usb_mixer_interface *mixer = snd_kcontrol_chip(kcontrol); | |
1580 | int err; | |
1581 | u8 reg; | |
1582 | unsigned long priv_backup = kcontrol->private_value; | |
1583 | ||
1584 | reg = ((ucontrol->value.iec958.status[1] & 0x0f) << 4) | | |
1585 | (ucontrol->value.iec958.status[0] & 0x0f); | |
1586 | err = snd_usb_ctl_msg(mixer->chip->dev, | |
1587 | usb_sndctrlpipe(mixer->chip->dev, 0), | |
1588 | UAC_SET_CUR, | |
1589 | USB_DIR_OUT | USB_TYPE_VENDOR | USB_RECIP_OTHER, | |
1590 | reg, | |
1591 | 2, | |
1592 | NULL, | |
1593 | 0); | |
1594 | if (err < 0) | |
1595 | goto end; | |
1596 | ||
1597 | kcontrol->private_value &= 0xfffff0f0; | |
1598 | kcontrol->private_value |= (ucontrol->value.iec958.status[1] & 0x0f) << 8; | |
1599 | kcontrol->private_value |= (ucontrol->value.iec958.status[0] & 0x0f); | |
1600 | ||
1601 | reg = (ucontrol->value.iec958.status[0] & IEC958_AES0_NONAUDIO) ? | |
1602 | 0xa0 : 0x20; | |
1603 | reg |= (ucontrol->value.iec958.status[1] >> 4) & 0x0f; | |
1604 | err = snd_usb_ctl_msg(mixer->chip->dev, | |
1605 | usb_sndctrlpipe(mixer->chip->dev, 0), | |
1606 | UAC_SET_CUR, | |
1607 | USB_DIR_OUT | USB_TYPE_VENDOR | USB_RECIP_OTHER, | |
1608 | reg, | |
1609 | 3, | |
1610 | NULL, | |
1611 | 0); | |
1612 | if (err < 0) | |
1613 | goto end; | |
1614 | ||
1615 | kcontrol->private_value &= 0xffff0fff; | |
1616 | kcontrol->private_value |= (ucontrol->value.iec958.status[1] & 0xf0) << 8; | |
1617 | ||
1618 | /* The frequency bits in AES3 cannot be set via register access. */ | |
1619 | ||
1620 | /* Silently ignore any bits from the request that cannot be set. */ | |
1621 | ||
1622 | err = (priv_backup != kcontrol->private_value); | |
1623 | end: | |
1624 | return err; | |
1625 | } | |
1626 | ||
1627 | static int snd_microii_spdif_mask_get(struct snd_kcontrol *kcontrol, | |
1628 | struct snd_ctl_elem_value *ucontrol) | |
1629 | { | |
1630 | ucontrol->value.iec958.status[0] = 0x0f; | |
1631 | ucontrol->value.iec958.status[1] = 0xff; | |
1632 | ucontrol->value.iec958.status[2] = 0x00; | |
1633 | ucontrol->value.iec958.status[3] = 0x00; | |
1634 | ||
1635 | return 0; | |
1636 | } | |
1637 | ||
1638 | static int snd_microii_spdif_switch_get(struct snd_kcontrol *kcontrol, | |
1639 | struct snd_ctl_elem_value *ucontrol) | |
1640 | { | |
1641 | ucontrol->value.integer.value[0] = !(kcontrol->private_value & 0x02); | |
1642 | ||
1643 | return 0; | |
1644 | } | |
1645 | ||
1646 | static int snd_microii_spdif_switch_put(struct snd_kcontrol *kcontrol, | |
1647 | struct snd_ctl_elem_value *ucontrol) | |
1648 | { | |
1649 | struct usb_mixer_interface *mixer = snd_kcontrol_chip(kcontrol); | |
1650 | int err; | |
1651 | u8 reg = ucontrol->value.integer.value[0] ? 0x28 : 0x2a; | |
1652 | ||
1653 | err = snd_usb_ctl_msg(mixer->chip->dev, | |
1654 | usb_sndctrlpipe(mixer->chip->dev, 0), | |
1655 | UAC_SET_CUR, | |
1656 | USB_DIR_OUT | USB_TYPE_VENDOR | USB_RECIP_OTHER, | |
1657 | reg, | |
1658 | 9, | |
1659 | NULL, | |
1660 | 0); | |
1661 | ||
1662 | if (!err) { | |
1663 | err = (reg != (kcontrol->private_value & 0x0ff)); | |
1664 | if (err) | |
1665 | kcontrol->private_value = reg; | |
1666 | } | |
1667 | ||
1668 | return err; | |
1669 | } | |
1670 | ||
1671 | static struct snd_kcontrol_new snd_microii_mixer_spdif[] = { | |
1672 | { | |
1673 | .iface = SNDRV_CTL_ELEM_IFACE_PCM, | |
1674 | .name = SNDRV_CTL_NAME_IEC958("", PLAYBACK, DEFAULT), | |
1675 | .info = snd_microii_spdif_info, | |
1676 | .get = snd_microii_spdif_default_get, | |
1677 | .put = snd_microii_spdif_default_put, | |
1678 | .private_value = 0x00000100UL,/* reset value */ | |
1679 | }, | |
1680 | { | |
1681 | .access = SNDRV_CTL_ELEM_ACCESS_READ, | |
1682 | .iface = SNDRV_CTL_ELEM_IFACE_PCM, | |
1683 | .name = SNDRV_CTL_NAME_IEC958("", PLAYBACK, MASK), | |
1684 | .info = snd_microii_spdif_info, | |
1685 | .get = snd_microii_spdif_mask_get, | |
1686 | }, | |
1687 | { | |
1688 | .iface = SNDRV_CTL_ELEM_IFACE_MIXER, | |
1689 | .name = SNDRV_CTL_NAME_IEC958("", PLAYBACK, SWITCH), | |
1690 | .info = snd_ctl_boolean_mono_info, | |
1691 | .get = snd_microii_spdif_switch_get, | |
1692 | .put = snd_microii_spdif_switch_put, | |
1693 | .private_value = 0x00000028UL,/* reset value */ | |
1694 | } | |
1695 | }; | |
1696 | ||
1697 | static int snd_microii_controls_create(struct usb_mixer_interface *mixer) | |
1698 | { | |
1699 | int err, i; | |
1700 | ||
1701 | for (i = 0; i < ARRAY_SIZE(snd_microii_mixer_spdif); ++i) { | |
1702 | err = snd_ctl_add(mixer->chip->card, | |
1703 | snd_ctl_new1(&snd_microii_mixer_spdif[i], mixer)); | |
1704 | if (err < 0) | |
1705 | return err; | |
1706 | } | |
1707 | ||
18e4753f | 1708 | return 0; |
066624c6 PR |
1709 | } |
1710 | ||
7b1eda22 DM |
1711 | int snd_usb_mixer_apply_create_quirk(struct usb_mixer_interface *mixer) |
1712 | { | |
3347b26c | 1713 | int err = 0; |
7b1eda22 DM |
1714 | struct snd_info_entry *entry; |
1715 | ||
1716 | if ((err = snd_usb_soundblaster_remote_init(mixer)) < 0) | |
1717 | return err; | |
1718 | ||
3347b26c DM |
1719 | switch (mixer->chip->usb_id) { |
1720 | case USB_ID(0x041e, 0x3020): | |
1721 | case USB_ID(0x041e, 0x3040): | |
1722 | case USB_ID(0x041e, 0x3042): | |
7cdd8d73 | 1723 | case USB_ID(0x041e, 0x30df): |
3347b26c DM |
1724 | case USB_ID(0x041e, 0x3048): |
1725 | err = snd_audigy2nx_controls_create(mixer); | |
1726 | if (err < 0) | |
1727 | break; | |
7b1eda22 DM |
1728 | if (!snd_card_proc_new(mixer->chip->card, "audigy2nx", &entry)) |
1729 | snd_info_set_text_ops(entry, mixer, | |
1730 | snd_audigy2nx_proc_read); | |
3347b26c | 1731 | break; |
7b1eda22 | 1732 | |
44832a71 VK |
1733 | /* EMU0204 */ |
1734 | case USB_ID(0x041e, 0x3f19): | |
1735 | err = snd_emu0204_controls_create(mixer); | |
1736 | if (err < 0) | |
1737 | break; | |
1738 | break; | |
1739 | ||
09d8e3a7 | 1740 | case USB_ID(0x0763, 0x2030): /* M-Audio Fast Track C400 */ |
e9a25e04 | 1741 | case USB_ID(0x0763, 0x2031): /* M-Audio Fast Track C400 */ |
09d8e3a7 EZ |
1742 | err = snd_c400_create_mixer(mixer); |
1743 | break; | |
1744 | ||
d5a0bf6c DM |
1745 | case USB_ID(0x0763, 0x2080): /* M-Audio Fast Track Ultra */ |
1746 | case USB_ID(0x0763, 0x2081): /* M-Audio Fast Track Ultra 8R */ | |
cfe8f97c | 1747 | err = snd_ftu_create_mixer(mixer); |
d5a0bf6c DM |
1748 | break; |
1749 | ||
1d31affb DW |
1750 | case USB_ID(0x0b05, 0x1739): /* ASUS Xonar U1 */ |
1751 | case USB_ID(0x0b05, 0x1743): /* ASUS Xonar U1 (2) */ | |
1752 | case USB_ID(0x0b05, 0x17a0): /* ASUS Xonar U3 */ | |
7b1eda22 | 1753 | err = snd_xonar_u1_controls_create(mixer); |
3347b26c | 1754 | break; |
7b1eda22 | 1755 | |
066624c6 PR |
1756 | case USB_ID(0x0d8c, 0x0103): /* Audio Advantage Micro II */ |
1757 | err = snd_microii_controls_create(mixer); | |
1758 | break; | |
1759 | ||
d497a82f DZ |
1760 | case USB_ID(0x0dba, 0x1000): /* Digidesign Mbox 1 */ |
1761 | err = snd_mbox1_create_sync_switch(mixer); | |
1762 | break; | |
1763 | ||
3347b26c | 1764 | case USB_ID(0x17cc, 0x1011): /* Traktor Audio 6 */ |
54a8c500 DM |
1765 | err = snd_nativeinstruments_create_mixer(mixer, |
1766 | snd_nativeinstruments_ta6_mixers, | |
1767 | ARRAY_SIZE(snd_nativeinstruments_ta6_mixers)); | |
3347b26c | 1768 | break; |
54a8c500 | 1769 | |
3347b26c | 1770 | case USB_ID(0x17cc, 0x1021): /* Traktor Audio 10 */ |
54a8c500 DM |
1771 | err = snd_nativeinstruments_create_mixer(mixer, |
1772 | snd_nativeinstruments_ta10_mixers, | |
1773 | ARRAY_SIZE(snd_nativeinstruments_ta10_mixers)); | |
3347b26c | 1774 | break; |
7536c301 MH |
1775 | |
1776 | case USB_ID(0x200c, 0x1018): /* Electrix Ebox-44 */ | |
b71dad18 MH |
1777 | /* detection is disabled in mixer_maps.c */ |
1778 | err = snd_create_std_mono_table(mixer, ebox44_table); | |
7536c301 | 1779 | break; |
54a8c500 DM |
1780 | } |
1781 | ||
3347b26c | 1782 | return err; |
7b1eda22 DM |
1783 | } |
1784 | ||
1785 | void snd_usb_mixer_rc_memory_change(struct usb_mixer_interface *mixer, | |
1786 | int unitid) | |
1787 | { | |
1788 | if (!mixer->rc_cfg) | |
1789 | return; | |
1790 | /* unit ids specific to Extigy/Audigy 2 NX: */ | |
1791 | switch (unitid) { | |
1792 | case 0: /* remote control */ | |
1793 | mixer->rc_urb->dev = mixer->chip->dev; | |
1794 | usb_submit_urb(mixer->rc_urb, GFP_ATOMIC); | |
1795 | break; | |
1796 | case 4: /* digital in jack */ | |
1797 | case 7: /* line in jacks */ | |
1798 | case 19: /* speaker out jacks */ | |
1799 | case 20: /* headphones out jack */ | |
1800 | break; | |
1801 | /* live24ext: 4 = line-in jack */ | |
1802 | case 3: /* hp-out jack (may actuate Mute) */ | |
1803 | if (mixer->chip->usb_id == USB_ID(0x041e, 0x3040) || | |
1804 | mixer->chip->usb_id == USB_ID(0x041e, 0x3048)) | |
1805 | snd_usb_mixer_notify_id(mixer, mixer->rc_cfg->mute_mixer_id); | |
1806 | break; | |
1807 | default: | |
0ba41d91 | 1808 | usb_audio_dbg(mixer->chip, "memory change in unknown unit %d\n", unitid); |
7b1eda22 DM |
1809 | break; |
1810 | } | |
1811 | } | |
1812 |