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