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