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