Commit | Line | Data |
---|---|---|
1a59d1b8 | 1 | // SPDX-License-Identifier: GPL-2.0-or-later |
7b1eda22 DM |
2 | /* |
3 | * USB Audio Driver for ALSA | |
4 | * | |
5 | * Quirks and vendor-specific extensions for mixer interfaces | |
6 | * | |
7 | * Copyright (c) 2002 by Takashi Iwai <tiwai@suse.de> | |
8 | * | |
9 | * Many codes borrowed from audio.c by | |
10 | * Alan Cox (alan@lxorguk.ukuu.org.uk) | |
11 | * Thomas Sailer (sailer@ife.ee.ethz.ch) | |
12 | * | |
066624c6 PR |
13 | * Audio Advantage Micro II support added by: |
14 | * Przemek Rudy (prudy1@o2.pl) | |
7b1eda22 DM |
15 | */ |
16 | ||
388fdb8f | 17 | #include <linux/hid.h> |
7b1eda22 | 18 | #include <linux/init.h> |
d39f1d68 | 19 | #include <linux/math64.h> |
36db0456 | 20 | #include <linux/slab.h> |
7b1eda22 DM |
21 | #include <linux/usb.h> |
22 | #include <linux/usb/audio.h> | |
23 | ||
066624c6 | 24 | #include <sound/asoundef.h> |
7b1eda22 DM |
25 | #include <sound/core.h> |
26 | #include <sound/control.h> | |
4b8ea38f | 27 | #include <sound/hda_verbs.h> |
7b1eda22 DM |
28 | #include <sound/hwdep.h> |
29 | #include <sound/info.h> | |
42e3121d | 30 | #include <sound/tlv.h> |
7b1eda22 DM |
31 | |
32 | #include "usbaudio.h" | |
f0b5e634 | 33 | #include "mixer.h" |
7b1eda22 | 34 | #include "mixer_quirks.h" |
76b188c4 | 35 | #include "mixer_scarlett.h" |
9e4d5c1b | 36 | #include "mixer_scarlett_gen2.h" |
d2bb390a | 37 | #include "mixer_us16x08.h" |
8dc5efe3 | 38 | #include "mixer_s1810c.h" |
7b1eda22 DM |
39 | #include "helper.h" |
40 | ||
b71dad18 MH |
41 | struct std_mono_table { |
42 | unsigned int unitid, control, cmask; | |
43 | int val_type; | |
44 | const char *name; | |
45 | snd_kcontrol_tlv_rw_t *tlv_callback; | |
46 | }; | |
47 | ||
8a4d1d39 FH |
48 | /* This function allows for the creation of standard UAC controls. |
49 | * See the quirks for M-Audio FTUs or Ebox-44. | |
50 | * If you don't want to set a TLV callback pass NULL. | |
51 | * | |
52 | * Since there doesn't seem to be a devices that needs a multichannel | |
53 | * version, we keep it mono for simplicity. | |
54 | */ | |
9f814105 | 55 | static int snd_create_std_mono_ctl_offset(struct usb_mixer_interface *mixer, |
8a4d1d39 FH |
56 | unsigned int unitid, |
57 | unsigned int control, | |
58 | unsigned int cmask, | |
59 | int val_type, | |
9f814105 | 60 | unsigned int idx_off, |
8a4d1d39 FH |
61 | const char *name, |
62 | snd_kcontrol_tlv_rw_t *tlv_callback) | |
63 | { | |
8a4d1d39 FH |
64 | struct usb_mixer_elem_info *cval; |
65 | struct snd_kcontrol *kctl; | |
66 | ||
67 | cval = kzalloc(sizeof(*cval), GFP_KERNEL); | |
68 | if (!cval) | |
69 | return -ENOMEM; | |
70 | ||
3360b84b | 71 | snd_usb_mixer_elem_init_std(&cval->head, mixer, unitid); |
8a4d1d39 FH |
72 | cval->val_type = val_type; |
73 | cval->channels = 1; | |
74 | cval->control = control; | |
75 | cval->cmask = cmask; | |
9f814105 | 76 | cval->idx_off = idx_off; |
8a4d1d39 | 77 | |
7df4a691 MH |
78 | /* get_min_max() is called only for integer volumes later, |
79 | * so provide a short-cut for booleans */ | |
8a4d1d39 FH |
80 | cval->min = 0; |
81 | cval->max = 1; | |
82 | cval->res = 0; | |
83 | cval->dBmin = 0; | |
84 | cval->dBmax = 0; | |
85 | ||
86 | /* Create control */ | |
87 | kctl = snd_ctl_new1(snd_usb_feature_unit_ctl, cval); | |
88 | if (!kctl) { | |
89 | kfree(cval); | |
90 | return -ENOMEM; | |
91 | } | |
92 | ||
93 | /* Set name */ | |
94 | snprintf(kctl->id.name, sizeof(kctl->id.name), name); | |
eef90451 | 95 | kctl->private_free = snd_usb_mixer_elem_free; |
8a4d1d39 FH |
96 | |
97 | /* set TLV */ | |
98 | if (tlv_callback) { | |
99 | kctl->tlv.c = tlv_callback; | |
100 | kctl->vd[0].access |= | |
101 | SNDRV_CTL_ELEM_ACCESS_TLV_READ | | |
102 | SNDRV_CTL_ELEM_ACCESS_TLV_CALLBACK; | |
103 | } | |
104 | /* Add control to mixer */ | |
3360b84b | 105 | return snd_usb_mixer_add_control(&cval->head, kctl); |
8a4d1d39 FH |
106 | } |
107 | ||
9f814105 EZ |
108 | static int snd_create_std_mono_ctl(struct usb_mixer_interface *mixer, |
109 | unsigned int unitid, | |
110 | unsigned int control, | |
111 | unsigned int cmask, | |
112 | int val_type, | |
113 | const char *name, | |
114 | snd_kcontrol_tlv_rw_t *tlv_callback) | |
115 | { | |
116 | return snd_create_std_mono_ctl_offset(mixer, unitid, control, cmask, | |
117 | val_type, 0 /* Offset */, name, tlv_callback); | |
118 | } | |
119 | ||
b71dad18 MH |
120 | /* |
121 | * Create a set of standard UAC controls from a table | |
122 | */ | |
123 | static int snd_create_std_mono_table(struct usb_mixer_interface *mixer, | |
a01df925 | 124 | const struct std_mono_table *t) |
b71dad18 MH |
125 | { |
126 | int err; | |
127 | ||
128 | while (t->name != NULL) { | |
129 | err = snd_create_std_mono_ctl(mixer, t->unitid, t->control, | |
130 | t->cmask, t->val_type, t->name, t->tlv_callback); | |
131 | if (err < 0) | |
132 | return err; | |
133 | t++; | |
134 | } | |
135 | ||
136 | return 0; | |
137 | } | |
138 | ||
9cf3689b TI |
139 | static int add_single_ctl_with_resume(struct usb_mixer_interface *mixer, |
140 | int id, | |
141 | usb_mixer_elem_resume_func_t resume, | |
142 | const struct snd_kcontrol_new *knew, | |
143 | struct usb_mixer_elem_list **listp) | |
144 | { | |
145 | struct usb_mixer_elem_list *list; | |
146 | struct snd_kcontrol *kctl; | |
147 | ||
148 | list = kzalloc(sizeof(*list), GFP_KERNEL); | |
149 | if (!list) | |
150 | return -ENOMEM; | |
151 | if (listp) | |
152 | *listp = list; | |
153 | list->mixer = mixer; | |
154 | list->id = id; | |
7b9cf903 | 155 | list->resume = resume; |
9cf3689b TI |
156 | kctl = snd_ctl_new1(knew, list); |
157 | if (!kctl) { | |
158 | kfree(list); | |
159 | return -ENOMEM; | |
160 | } | |
161 | kctl->private_free = snd_usb_mixer_elem_free; | |
220345e9 TI |
162 | /* don't use snd_usb_mixer_add_control() here, this is a special list element */ |
163 | return snd_usb_mixer_add_list(list, kctl, false); | |
9cf3689b TI |
164 | } |
165 | ||
7b1eda22 DM |
166 | /* |
167 | * Sound Blaster remote control configuration | |
168 | * | |
169 | * format of remote control data: | |
170 | * Extigy: xx 00 | |
171 | * Audigy 2 NX: 06 80 xx 00 00 00 | |
172 | * Live! 24-bit: 06 80 xx yy 22 83 | |
173 | */ | |
174 | static const struct rc_config { | |
175 | u32 usb_id; | |
176 | u8 offset; | |
177 | u8 length; | |
178 | u8 packet_length; | |
179 | u8 min_packet_length; /* minimum accepted length of the URB result */ | |
180 | u8 mute_mixer_id; | |
181 | u32 mute_code; | |
182 | } rc_configs[] = { | |
183 | { USB_ID(0x041e, 0x3000), 0, 1, 2, 1, 18, 0x0013 }, /* Extigy */ | |
184 | { USB_ID(0x041e, 0x3020), 2, 1, 6, 6, 18, 0x0013 }, /* Audigy 2 NX */ | |
185 | { USB_ID(0x041e, 0x3040), 2, 2, 6, 6, 2, 0x6e91 }, /* Live! 24-bit */ | |
ca8dc34e | 186 | { USB_ID(0x041e, 0x3042), 0, 1, 1, 1, 1, 0x000d }, /* Usb X-Fi S51 */ |
7cdd8d73 | 187 | { USB_ID(0x041e, 0x30df), 0, 1, 1, 1, 1, 0x000d }, /* Usb X-Fi S51 Pro */ |
3dc8523f | 188 | { USB_ID(0x041e, 0x3237), 0, 1, 1, 1, 1, 0x000d }, /* Usb X-Fi S51 Pro */ |
fec90088 | 189 | { USB_ID(0x041e, 0x3263), 0, 1, 1, 1, 1, 0x000d }, /* Usb X-Fi S51 Pro */ |
7b1eda22 DM |
190 | { USB_ID(0x041e, 0x3048), 2, 2, 6, 6, 2, 0x6e91 }, /* Toshiba SB0500 */ |
191 | }; | |
192 | ||
193 | static void snd_usb_soundblaster_remote_complete(struct urb *urb) | |
194 | { | |
195 | struct usb_mixer_interface *mixer = urb->context; | |
196 | const struct rc_config *rc = mixer->rc_cfg; | |
197 | u32 code; | |
198 | ||
199 | if (urb->status < 0 || urb->actual_length < rc->min_packet_length) | |
200 | return; | |
201 | ||
202 | code = mixer->rc_buffer[rc->offset]; | |
203 | if (rc->length == 2) | |
204 | code |= mixer->rc_buffer[rc->offset + 1] << 8; | |
205 | ||
206 | /* the Mute button actually changes the mixer control */ | |
207 | if (code == rc->mute_code) | |
208 | snd_usb_mixer_notify_id(mixer, rc->mute_mixer_id); | |
209 | mixer->rc_code = code; | |
210 | wmb(); | |
211 | wake_up(&mixer->rc_waitq); | |
212 | } | |
213 | ||
214 | static long snd_usb_sbrc_hwdep_read(struct snd_hwdep *hw, char __user *buf, | |
215 | long count, loff_t *offset) | |
216 | { | |
217 | struct usb_mixer_interface *mixer = hw->private_data; | |
218 | int err; | |
219 | u32 rc_code; | |
220 | ||
221 | if (count != 1 && count != 4) | |
222 | return -EINVAL; | |
223 | err = wait_event_interruptible(mixer->rc_waitq, | |
224 | (rc_code = xchg(&mixer->rc_code, 0)) != 0); | |
225 | if (err == 0) { | |
226 | if (count == 1) | |
227 | err = put_user(rc_code, buf); | |
228 | else | |
229 | err = put_user(rc_code, (u32 __user *)buf); | |
230 | } | |
231 | return err < 0 ? err : count; | |
232 | } | |
233 | ||
680ef72a | 234 | static __poll_t snd_usb_sbrc_hwdep_poll(struct snd_hwdep *hw, struct file *file, |
7b1eda22 DM |
235 | poll_table *wait) |
236 | { | |
237 | struct usb_mixer_interface *mixer = hw->private_data; | |
238 | ||
239 | poll_wait(file, &mixer->rc_waitq, wait); | |
a9a08845 | 240 | return mixer->rc_code ? EPOLLIN | EPOLLRDNORM : 0; |
7b1eda22 DM |
241 | } |
242 | ||
243 | static int snd_usb_soundblaster_remote_init(struct usb_mixer_interface *mixer) | |
244 | { | |
245 | struct snd_hwdep *hwdep; | |
246 | int err, len, i; | |
247 | ||
248 | for (i = 0; i < ARRAY_SIZE(rc_configs); ++i) | |
249 | if (rc_configs[i].usb_id == mixer->chip->usb_id) | |
250 | break; | |
251 | if (i >= ARRAY_SIZE(rc_configs)) | |
252 | return 0; | |
253 | mixer->rc_cfg = &rc_configs[i]; | |
254 | ||
255 | len = mixer->rc_cfg->packet_length; | |
256 | ||
257 | init_waitqueue_head(&mixer->rc_waitq); | |
258 | err = snd_hwdep_new(mixer->chip->card, "SB remote control", 0, &hwdep); | |
259 | if (err < 0) | |
260 | return err; | |
261 | snprintf(hwdep->name, sizeof(hwdep->name), | |
262 | "%s remote control", mixer->chip->card->shortname); | |
263 | hwdep->iface = SNDRV_HWDEP_IFACE_SB_RC; | |
264 | hwdep->private_data = mixer; | |
265 | hwdep->ops.read = snd_usb_sbrc_hwdep_read; | |
266 | hwdep->ops.poll = snd_usb_sbrc_hwdep_poll; | |
267 | hwdep->exclusive = 1; | |
268 | ||
269 | mixer->rc_urb = usb_alloc_urb(0, GFP_KERNEL); | |
270 | if (!mixer->rc_urb) | |
271 | return -ENOMEM; | |
272 | mixer->rc_setup_packet = kmalloc(sizeof(*mixer->rc_setup_packet), GFP_KERNEL); | |
273 | if (!mixer->rc_setup_packet) { | |
274 | usb_free_urb(mixer->rc_urb); | |
275 | mixer->rc_urb = NULL; | |
276 | return -ENOMEM; | |
277 | } | |
278 | mixer->rc_setup_packet->bRequestType = | |
279 | USB_DIR_IN | USB_TYPE_CLASS | USB_RECIP_INTERFACE; | |
280 | mixer->rc_setup_packet->bRequest = UAC_GET_MEM; | |
281 | mixer->rc_setup_packet->wValue = cpu_to_le16(0); | |
282 | mixer->rc_setup_packet->wIndex = cpu_to_le16(0); | |
283 | mixer->rc_setup_packet->wLength = cpu_to_le16(len); | |
284 | usb_fill_control_urb(mixer->rc_urb, mixer->chip->dev, | |
285 | usb_rcvctrlpipe(mixer->chip->dev, 0), | |
286 | (u8*)mixer->rc_setup_packet, mixer->rc_buffer, len, | |
287 | snd_usb_soundblaster_remote_complete, mixer); | |
288 | return 0; | |
289 | } | |
290 | ||
291 | #define snd_audigy2nx_led_info snd_ctl_boolean_mono_info | |
292 | ||
293 | static int snd_audigy2nx_led_get(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol) | |
294 | { | |
9cf3689b | 295 | ucontrol->value.integer.value[0] = kcontrol->private_value >> 8; |
7b1eda22 DM |
296 | return 0; |
297 | } | |
298 | ||
9cf3689b TI |
299 | static int snd_audigy2nx_led_update(struct usb_mixer_interface *mixer, |
300 | int value, int index) | |
7b1eda22 | 301 | { |
9cf3689b TI |
302 | struct snd_usb_audio *chip = mixer->chip; |
303 | int err; | |
7b1eda22 | 304 | |
47ab1545 TI |
305 | err = snd_usb_lock_shutdown(chip); |
306 | if (err < 0) | |
307 | return err; | |
308 | ||
9cf3689b TI |
309 | if (chip->usb_id == USB_ID(0x041e, 0x3042)) |
310 | err = snd_usb_ctl_msg(chip->dev, | |
311 | usb_sndctrlpipe(chip->dev, 0), 0x24, | |
ca8dc34e | 312 | USB_DIR_OUT | USB_TYPE_VENDOR | USB_RECIP_OTHER, |
17d900c4 | 313 | !value, 0, NULL, 0); |
7cdd8d73 | 314 | /* USB X-Fi S51 Pro */ |
9cf3689b TI |
315 | if (chip->usb_id == USB_ID(0x041e, 0x30df)) |
316 | err = snd_usb_ctl_msg(chip->dev, | |
317 | usb_sndctrlpipe(chip->dev, 0), 0x24, | |
7cdd8d73 | 318 | USB_DIR_OUT | USB_TYPE_VENDOR | USB_RECIP_OTHER, |
17d900c4 | 319 | !value, 0, NULL, 0); |
ca8dc34e | 320 | else |
9cf3689b TI |
321 | err = snd_usb_ctl_msg(chip->dev, |
322 | usb_sndctrlpipe(chip->dev, 0), 0x24, | |
7b1eda22 | 323 | USB_DIR_OUT | USB_TYPE_VENDOR | USB_RECIP_OTHER, |
17d900c4 | 324 | value, index + 2, NULL, 0); |
47ab1545 | 325 | snd_usb_unlock_shutdown(chip); |
9cf3689b | 326 | return err; |
7b1eda22 DM |
327 | } |
328 | ||
9cf3689b TI |
329 | static int snd_audigy2nx_led_put(struct snd_kcontrol *kcontrol, |
330 | struct snd_ctl_elem_value *ucontrol) | |
331 | { | |
332 | struct usb_mixer_elem_list *list = snd_kcontrol_chip(kcontrol); | |
333 | struct usb_mixer_interface *mixer = list->mixer; | |
334 | int index = kcontrol->private_value & 0xff; | |
e87359ef | 335 | unsigned int value = ucontrol->value.integer.value[0]; |
9cf3689b TI |
336 | int old_value = kcontrol->private_value >> 8; |
337 | int err; | |
338 | ||
339 | if (value > 1) | |
340 | return -EINVAL; | |
341 | if (value == old_value) | |
342 | return 0; | |
343 | kcontrol->private_value = (value << 8) | index; | |
344 | err = snd_audigy2nx_led_update(mixer, value, index); | |
345 | return err < 0 ? err : 1; | |
346 | } | |
347 | ||
348 | static int snd_audigy2nx_led_resume(struct usb_mixer_elem_list *list) | |
349 | { | |
350 | int priv_value = list->kctl->private_value; | |
351 | ||
352 | return snd_audigy2nx_led_update(list->mixer, priv_value >> 8, | |
353 | priv_value & 0xff); | |
354 | } | |
355 | ||
356 | /* name and private_value are set dynamically */ | |
905e46ac | 357 | static const struct snd_kcontrol_new snd_audigy2nx_control = { |
9cf3689b TI |
358 | .iface = SNDRV_CTL_ELEM_IFACE_MIXER, |
359 | .info = snd_audigy2nx_led_info, | |
360 | .get = snd_audigy2nx_led_get, | |
361 | .put = snd_audigy2nx_led_put, | |
362 | }; | |
363 | ||
364 | static const char * const snd_audigy2nx_led_names[] = { | |
365 | "CMSS LED Switch", | |
366 | "Power LED Switch", | |
367 | "Dolby Digital LED Switch", | |
7b1eda22 DM |
368 | }; |
369 | ||
370 | static int snd_audigy2nx_controls_create(struct usb_mixer_interface *mixer) | |
371 | { | |
372 | int i, err; | |
373 | ||
9cf3689b TI |
374 | for (i = 0; i < ARRAY_SIZE(snd_audigy2nx_led_names); ++i) { |
375 | struct snd_kcontrol_new knew; | |
376 | ||
ca8dc34e MJ |
377 | /* USB X-Fi S51 doesn't have a CMSS LED */ |
378 | if ((mixer->chip->usb_id == USB_ID(0x041e, 0x3042)) && i == 0) | |
379 | continue; | |
7cdd8d73 MB |
380 | /* USB X-Fi S51 Pro doesn't have one either */ |
381 | if ((mixer->chip->usb_id == USB_ID(0x041e, 0x30df)) && i == 0) | |
382 | continue; | |
7b1eda22 DM |
383 | if (i > 1 && /* Live24ext has 2 LEDs only */ |
384 | (mixer->chip->usb_id == USB_ID(0x041e, 0x3040) || | |
ca8dc34e | 385 | mixer->chip->usb_id == USB_ID(0x041e, 0x3042) || |
7cdd8d73 | 386 | mixer->chip->usb_id == USB_ID(0x041e, 0x30df) || |
7b1eda22 DM |
387 | mixer->chip->usb_id == USB_ID(0x041e, 0x3048))) |
388 | break; | |
9cf3689b TI |
389 | |
390 | knew = snd_audigy2nx_control; | |
391 | knew.name = snd_audigy2nx_led_names[i]; | |
392 | knew.private_value = (1 << 8) | i; /* LED on as default */ | |
393 | err = add_single_ctl_with_resume(mixer, 0, | |
394 | snd_audigy2nx_led_resume, | |
395 | &knew, NULL); | |
7b1eda22 DM |
396 | if (err < 0) |
397 | return err; | |
398 | } | |
7b1eda22 DM |
399 | return 0; |
400 | } | |
401 | ||
402 | static void snd_audigy2nx_proc_read(struct snd_info_entry *entry, | |
403 | struct snd_info_buffer *buffer) | |
404 | { | |
405 | static const struct sb_jack { | |
406 | int unitid; | |
407 | const char *name; | |
408 | } jacks_audigy2nx[] = { | |
409 | {4, "dig in "}, | |
410 | {7, "line in"}, | |
411 | {19, "spk out"}, | |
412 | {20, "hph out"}, | |
413 | {-1, NULL} | |
414 | }, jacks_live24ext[] = { | |
415 | {4, "line in"}, /* &1=Line, &2=Mic*/ | |
416 | {3, "hph out"}, /* headphones */ | |
417 | {0, "RC "}, /* last command, 6 bytes see rc_config above */ | |
418 | {-1, NULL} | |
419 | }; | |
420 | const struct sb_jack *jacks; | |
421 | struct usb_mixer_interface *mixer = entry->private_data; | |
422 | int i, err; | |
423 | u8 buf[3]; | |
424 | ||
425 | snd_iprintf(buffer, "%s jacks\n\n", mixer->chip->card->shortname); | |
426 | if (mixer->chip->usb_id == USB_ID(0x041e, 0x3020)) | |
427 | jacks = jacks_audigy2nx; | |
428 | else if (mixer->chip->usb_id == USB_ID(0x041e, 0x3040) || | |
429 | mixer->chip->usb_id == USB_ID(0x041e, 0x3048)) | |
430 | jacks = jacks_live24ext; | |
431 | else | |
432 | return; | |
433 | ||
434 | for (i = 0; jacks[i].name; ++i) { | |
435 | snd_iprintf(buffer, "%s: ", jacks[i].name); | |
47ab1545 TI |
436 | err = snd_usb_lock_shutdown(mixer->chip); |
437 | if (err < 0) | |
438 | return; | |
439 | err = snd_usb_ctl_msg(mixer->chip->dev, | |
7b1eda22 DM |
440 | usb_rcvctrlpipe(mixer->chip->dev, 0), |
441 | UAC_GET_MEM, USB_DIR_IN | USB_TYPE_CLASS | | |
442 | USB_RECIP_INTERFACE, 0, | |
17d900c4 | 443 | jacks[i].unitid << 8, buf, 3); |
47ab1545 | 444 | snd_usb_unlock_shutdown(mixer->chip); |
7b1eda22 DM |
445 | if (err == 3 && (buf[0] == 3 || buf[0] == 6)) |
446 | snd_iprintf(buffer, "%02x %02x\n", buf[1], buf[2]); | |
447 | else | |
448 | snd_iprintf(buffer, "?\n"); | |
449 | } | |
450 | } | |
451 | ||
44832a71 VK |
452 | /* EMU0204 */ |
453 | static int snd_emu0204_ch_switch_info(struct snd_kcontrol *kcontrol, | |
454 | struct snd_ctl_elem_info *uinfo) | |
455 | { | |
7bbd03e0 | 456 | static const char * const texts[2] = {"1/2", "3/4"}; |
44832a71 | 457 | |
7bbd03e0 | 458 | return snd_ctl_enum_info(uinfo, 1, ARRAY_SIZE(texts), texts); |
44832a71 VK |
459 | } |
460 | ||
461 | static int snd_emu0204_ch_switch_get(struct snd_kcontrol *kcontrol, | |
462 | struct snd_ctl_elem_value *ucontrol) | |
463 | { | |
464 | ucontrol->value.enumerated.item[0] = kcontrol->private_value; | |
465 | return 0; | |
466 | } | |
467 | ||
5f503ee9 TI |
468 | static int snd_emu0204_ch_switch_update(struct usb_mixer_interface *mixer, |
469 | int value) | |
44832a71 | 470 | { |
5f503ee9 TI |
471 | struct snd_usb_audio *chip = mixer->chip; |
472 | int err; | |
44832a71 VK |
473 | unsigned char buf[2]; |
474 | ||
47ab1545 TI |
475 | err = snd_usb_lock_shutdown(chip); |
476 | if (err < 0) | |
477 | return err; | |
5f503ee9 TI |
478 | |
479 | buf[0] = 0x01; | |
480 | buf[1] = value ? 0x02 : 0x01; | |
481 | err = snd_usb_ctl_msg(chip->dev, | |
482 | usb_sndctrlpipe(chip->dev, 0), UAC_SET_CUR, | |
44832a71 VK |
483 | USB_RECIP_INTERFACE | USB_TYPE_CLASS | USB_DIR_OUT, |
484 | 0x0400, 0x0e00, buf, 2); | |
47ab1545 | 485 | snd_usb_unlock_shutdown(chip); |
5f503ee9 TI |
486 | return err; |
487 | } | |
488 | ||
489 | static int snd_emu0204_ch_switch_put(struct snd_kcontrol *kcontrol, | |
490 | struct snd_ctl_elem_value *ucontrol) | |
491 | { | |
492 | struct usb_mixer_elem_list *list = snd_kcontrol_chip(kcontrol); | |
493 | struct usb_mixer_interface *mixer = list->mixer; | |
494 | unsigned int value = ucontrol->value.enumerated.item[0]; | |
495 | int err; | |
496 | ||
497 | if (value > 1) | |
498 | return -EINVAL; | |
499 | ||
500 | if (value == kcontrol->private_value) | |
501 | return 0; | |
502 | ||
44832a71 | 503 | kcontrol->private_value = value; |
5f503ee9 TI |
504 | err = snd_emu0204_ch_switch_update(mixer, value); |
505 | return err < 0 ? err : 1; | |
44832a71 VK |
506 | } |
507 | ||
5f503ee9 TI |
508 | static int snd_emu0204_ch_switch_resume(struct usb_mixer_elem_list *list) |
509 | { | |
510 | return snd_emu0204_ch_switch_update(list->mixer, | |
511 | list->kctl->private_value); | |
512 | } | |
44832a71 | 513 | |
195727e8 | 514 | static const struct snd_kcontrol_new snd_emu0204_control = { |
5f503ee9 TI |
515 | .iface = SNDRV_CTL_ELEM_IFACE_MIXER, |
516 | .name = "Front Jack Channels", | |
517 | .info = snd_emu0204_ch_switch_info, | |
518 | .get = snd_emu0204_ch_switch_get, | |
519 | .put = snd_emu0204_ch_switch_put, | |
520 | .private_value = 0, | |
44832a71 VK |
521 | }; |
522 | ||
523 | static int snd_emu0204_controls_create(struct usb_mixer_interface *mixer) | |
524 | { | |
5f503ee9 TI |
525 | return add_single_ctl_with_resume(mixer, 0, |
526 | snd_emu0204_ch_switch_resume, | |
527 | &snd_emu0204_control, NULL); | |
44832a71 | 528 | } |
5f503ee9 | 529 | |
1d31affb DW |
530 | /* ASUS Xonar U1 / U3 controls */ |
531 | ||
7b1eda22 DM |
532 | static int snd_xonar_u1_switch_get(struct snd_kcontrol *kcontrol, |
533 | struct snd_ctl_elem_value *ucontrol) | |
534 | { | |
2bfb14c3 | 535 | ucontrol->value.integer.value[0] = !!(kcontrol->private_value & 0x02); |
7b1eda22 DM |
536 | return 0; |
537 | } | |
538 | ||
2bfb14c3 TI |
539 | static int snd_xonar_u1_switch_update(struct usb_mixer_interface *mixer, |
540 | unsigned char status) | |
541 | { | |
542 | struct snd_usb_audio *chip = mixer->chip; | |
543 | int err; | |
544 | ||
47ab1545 TI |
545 | err = snd_usb_lock_shutdown(chip); |
546 | if (err < 0) | |
547 | return err; | |
548 | err = snd_usb_ctl_msg(chip->dev, | |
2bfb14c3 TI |
549 | usb_sndctrlpipe(chip->dev, 0), 0x08, |
550 | USB_DIR_OUT | USB_TYPE_VENDOR | USB_RECIP_OTHER, | |
551 | 50, 0, &status, 1); | |
47ab1545 | 552 | snd_usb_unlock_shutdown(chip); |
2bfb14c3 TI |
553 | return err; |
554 | } | |
555 | ||
7b1eda22 DM |
556 | static int snd_xonar_u1_switch_put(struct snd_kcontrol *kcontrol, |
557 | struct snd_ctl_elem_value *ucontrol) | |
558 | { | |
2bfb14c3 | 559 | struct usb_mixer_elem_list *list = snd_kcontrol_chip(kcontrol); |
7b1eda22 | 560 | u8 old_status, new_status; |
2bfb14c3 | 561 | int err; |
7b1eda22 | 562 | |
2bfb14c3 | 563 | old_status = kcontrol->private_value; |
7b1eda22 DM |
564 | if (ucontrol->value.integer.value[0]) |
565 | new_status = old_status | 0x02; | |
566 | else | |
567 | new_status = old_status & ~0x02; | |
2bfb14c3 TI |
568 | if (new_status == old_status) |
569 | return 0; | |
570 | ||
571 | kcontrol->private_value = new_status; | |
572 | err = snd_xonar_u1_switch_update(list->mixer, new_status); | |
573 | return err < 0 ? err : 1; | |
574 | } | |
575 | ||
576 | static int snd_xonar_u1_switch_resume(struct usb_mixer_elem_list *list) | |
577 | { | |
578 | return snd_xonar_u1_switch_update(list->mixer, | |
579 | list->kctl->private_value); | |
7b1eda22 DM |
580 | } |
581 | ||
195727e8 | 582 | static const struct snd_kcontrol_new snd_xonar_u1_output_switch = { |
7b1eda22 DM |
583 | .iface = SNDRV_CTL_ELEM_IFACE_MIXER, |
584 | .name = "Digital Playback Switch", | |
585 | .info = snd_ctl_boolean_mono_info, | |
586 | .get = snd_xonar_u1_switch_get, | |
587 | .put = snd_xonar_u1_switch_put, | |
2bfb14c3 | 588 | .private_value = 0x05, |
7b1eda22 DM |
589 | }; |
590 | ||
591 | static int snd_xonar_u1_controls_create(struct usb_mixer_interface *mixer) | |
592 | { | |
2bfb14c3 TI |
593 | return add_single_ctl_with_resume(mixer, 0, |
594 | snd_xonar_u1_switch_resume, | |
595 | &snd_xonar_u1_output_switch, NULL); | |
7b1eda22 DM |
596 | } |
597 | ||
7ac2246f DZ |
598 | /* Digidesign Mbox 1 helper functions */ |
599 | ||
600 | static int snd_mbox1_is_spdif_synced(struct snd_usb_audio *chip) | |
601 | { | |
602 | unsigned char buff[3]; | |
603 | int err; | |
604 | int is_spdif_synced; | |
605 | ||
606 | /* Read clock source */ | |
607 | err = snd_usb_ctl_msg(chip->dev, | |
608 | usb_rcvctrlpipe(chip->dev, 0), 0x81, | |
609 | USB_DIR_IN | | |
610 | USB_TYPE_CLASS | | |
611 | USB_RECIP_ENDPOINT, 0x100, 0x81, buff, 3); | |
612 | if (err < 0) | |
613 | return err; | |
614 | ||
615 | /* spdif sync: buff is all zeroes */ | |
616 | is_spdif_synced = !(buff[0] | buff[1] | buff[2]); | |
617 | return is_spdif_synced; | |
618 | } | |
619 | ||
620 | static int snd_mbox1_set_clk_source(struct snd_usb_audio *chip, int rate_or_zero) | |
621 | { | |
622 | /* 2 possibilities: Internal -> expects sample rate | |
623 | * S/PDIF sync -> expects rate = 0 | |
624 | */ | |
625 | unsigned char buff[3]; | |
626 | ||
627 | buff[0] = (rate_or_zero >> 0) & 0xff; | |
628 | buff[1] = (rate_or_zero >> 8) & 0xff; | |
629 | buff[2] = (rate_or_zero >> 16) & 0xff; | |
630 | ||
631 | /* Set clock source */ | |
632 | return snd_usb_ctl_msg(chip->dev, | |
633 | usb_sndctrlpipe(chip->dev, 0), 0x1, | |
634 | USB_TYPE_CLASS | | |
635 | USB_RECIP_ENDPOINT, 0x100, 0x81, buff, 3); | |
636 | } | |
637 | ||
638 | static int snd_mbox1_is_spdif_input(struct snd_usb_audio *chip) | |
639 | { | |
640 | /* Hardware gives 2 possibilities: ANALOG Source -> 0x01 | |
641 | * S/PDIF Source -> 0x02 | |
642 | */ | |
643 | int err; | |
644 | unsigned char source[1]; | |
645 | ||
646 | /* Read input source */ | |
647 | err = snd_usb_ctl_msg(chip->dev, | |
648 | usb_rcvctrlpipe(chip->dev, 0), 0x81, | |
649 | USB_DIR_IN | | |
650 | USB_TYPE_CLASS | | |
651 | USB_RECIP_INTERFACE, 0x00, 0x500, source, 1); | |
652 | if (err < 0) | |
653 | return err; | |
654 | ||
655 | return (source[0] == 2); | |
656 | } | |
657 | ||
658 | static int snd_mbox1_set_input_source(struct snd_usb_audio *chip, int is_spdif) | |
659 | { | |
660 | /* NB: Setting the input source to S/PDIF resets the clock source to S/PDIF | |
661 | * Hardware expects 2 possibilities: ANALOG Source -> 0x01 | |
662 | * S/PDIF Source -> 0x02 | |
663 | */ | |
664 | unsigned char buff[1]; | |
665 | ||
666 | buff[0] = (is_spdif & 1) + 1; | |
667 | ||
668 | /* Set input source */ | |
669 | return snd_usb_ctl_msg(chip->dev, | |
670 | usb_sndctrlpipe(chip->dev, 0), 0x1, | |
671 | USB_TYPE_CLASS | | |
672 | USB_RECIP_INTERFACE, 0x00, 0x500, buff, 1); | |
673 | } | |
674 | ||
d497a82f DZ |
675 | /* Digidesign Mbox 1 clock source switch (internal/spdif) */ |
676 | ||
7ac2246f DZ |
677 | static int snd_mbox1_clk_switch_get(struct snd_kcontrol *kctl, |
678 | struct snd_ctl_elem_value *ucontrol) | |
d497a82f | 679 | { |
7ac2246f DZ |
680 | struct usb_mixer_elem_list *list = snd_kcontrol_chip(kctl); |
681 | struct snd_usb_audio *chip = list->mixer->chip; | |
682 | int err; | |
683 | ||
684 | err = snd_usb_lock_shutdown(chip); | |
685 | if (err < 0) | |
686 | goto err; | |
687 | ||
688 | err = snd_mbox1_is_spdif_synced(chip); | |
689 | if (err < 0) | |
690 | goto err; | |
691 | ||
692 | kctl->private_value = err; | |
693 | err = 0; | |
d497a82f | 694 | ucontrol->value.enumerated.item[0] = kctl->private_value; |
7ac2246f DZ |
695 | err: |
696 | snd_usb_unlock_shutdown(chip); | |
697 | return err; | |
d497a82f DZ |
698 | } |
699 | ||
7ac2246f | 700 | static int snd_mbox1_clk_switch_update(struct usb_mixer_interface *mixer, int is_spdif_sync) |
d497a82f | 701 | { |
25a9a4f9 | 702 | struct snd_usb_audio *chip = mixer->chip; |
d497a82f | 703 | int err; |
d497a82f | 704 | |
47ab1545 TI |
705 | err = snd_usb_lock_shutdown(chip); |
706 | if (err < 0) | |
707 | return err; | |
d497a82f | 708 | |
7ac2246f | 709 | err = snd_mbox1_is_spdif_input(chip); |
d497a82f DZ |
710 | if (err < 0) |
711 | goto err; | |
7ac2246f DZ |
712 | |
713 | err = snd_mbox1_is_spdif_synced(chip); | |
d497a82f DZ |
714 | if (err < 0) |
715 | goto err; | |
716 | ||
7ac2246f DZ |
717 | /* FIXME: hardcoded sample rate */ |
718 | err = snd_mbox1_set_clk_source(chip, is_spdif_sync ? 0 : 48000); | |
719 | if (err < 0) | |
720 | goto err; | |
d497a82f | 721 | |
7ac2246f DZ |
722 | err = snd_mbox1_is_spdif_synced(chip); |
723 | err: | |
724 | snd_usb_unlock_shutdown(chip); | |
725 | return err; | |
726 | } | |
727 | ||
728 | static int snd_mbox1_clk_switch_put(struct snd_kcontrol *kctl, | |
729 | struct snd_ctl_elem_value *ucontrol) | |
730 | { | |
731 | struct usb_mixer_elem_list *list = snd_kcontrol_chip(kctl); | |
732 | struct usb_mixer_interface *mixer = list->mixer; | |
733 | int err; | |
734 | bool cur_val, new_val; | |
735 | ||
736 | cur_val = kctl->private_value; | |
737 | new_val = ucontrol->value.enumerated.item[0]; | |
738 | if (cur_val == new_val) | |
739 | return 0; | |
740 | ||
741 | kctl->private_value = new_val; | |
742 | err = snd_mbox1_clk_switch_update(mixer, new_val); | |
743 | return err < 0 ? err : 1; | |
744 | } | |
745 | ||
746 | static int snd_mbox1_clk_switch_info(struct snd_kcontrol *kcontrol, | |
747 | struct snd_ctl_elem_info *uinfo) | |
748 | { | |
749 | static const char *const texts[2] = { | |
750 | "Internal", | |
751 | "S/PDIF" | |
752 | }; | |
753 | ||
754 | return snd_ctl_enum_info(uinfo, 1, ARRAY_SIZE(texts), texts); | |
755 | } | |
756 | ||
757 | static int snd_mbox1_clk_switch_resume(struct usb_mixer_elem_list *list) | |
758 | { | |
759 | return snd_mbox1_clk_switch_update(list->mixer, list->kctl->private_value); | |
760 | } | |
761 | ||
762 | /* Digidesign Mbox 1 input source switch (analog/spdif) */ | |
763 | ||
764 | static int snd_mbox1_src_switch_get(struct snd_kcontrol *kctl, | |
765 | struct snd_ctl_elem_value *ucontrol) | |
766 | { | |
767 | ucontrol->value.enumerated.item[0] = kctl->private_value; | |
768 | return 0; | |
769 | } | |
770 | ||
771 | static int snd_mbox1_src_switch_update(struct usb_mixer_interface *mixer, int is_spdif_input) | |
772 | { | |
773 | struct snd_usb_audio *chip = mixer->chip; | |
774 | int err; | |
775 | ||
776 | err = snd_usb_lock_shutdown(chip); | |
777 | if (err < 0) | |
778 | return err; | |
779 | ||
780 | err = snd_mbox1_is_spdif_input(chip); | |
d497a82f DZ |
781 | if (err < 0) |
782 | goto err; | |
7ac2246f DZ |
783 | |
784 | err = snd_mbox1_set_input_source(chip, is_spdif_input); | |
d497a82f DZ |
785 | if (err < 0) |
786 | goto err; | |
7ac2246f DZ |
787 | |
788 | err = snd_mbox1_is_spdif_input(chip); | |
d497a82f DZ |
789 | if (err < 0) |
790 | goto err; | |
d497a82f | 791 | |
7ac2246f | 792 | err = snd_mbox1_is_spdif_synced(chip); |
d497a82f | 793 | err: |
47ab1545 | 794 | snd_usb_unlock_shutdown(chip); |
25a9a4f9 TI |
795 | return err; |
796 | } | |
797 | ||
7ac2246f DZ |
798 | static int snd_mbox1_src_switch_put(struct snd_kcontrol *kctl, |
799 | struct snd_ctl_elem_value *ucontrol) | |
25a9a4f9 TI |
800 | { |
801 | struct usb_mixer_elem_list *list = snd_kcontrol_chip(kctl); | |
802 | struct usb_mixer_interface *mixer = list->mixer; | |
803 | int err; | |
804 | bool cur_val, new_val; | |
805 | ||
806 | cur_val = kctl->private_value; | |
807 | new_val = ucontrol->value.enumerated.item[0]; | |
808 | if (cur_val == new_val) | |
809 | return 0; | |
810 | ||
811 | kctl->private_value = new_val; | |
7ac2246f | 812 | err = snd_mbox1_src_switch_update(mixer, new_val); |
d497a82f DZ |
813 | return err < 0 ? err : 1; |
814 | } | |
815 | ||
7ac2246f DZ |
816 | static int snd_mbox1_src_switch_info(struct snd_kcontrol *kcontrol, |
817 | struct snd_ctl_elem_info *uinfo) | |
d497a82f DZ |
818 | { |
819 | static const char *const texts[2] = { | |
7ac2246f | 820 | "Analog", |
d497a82f DZ |
821 | "S/PDIF" |
822 | }; | |
823 | ||
824 | return snd_ctl_enum_info(uinfo, 1, ARRAY_SIZE(texts), texts); | |
825 | } | |
826 | ||
7ac2246f | 827 | static int snd_mbox1_src_switch_resume(struct usb_mixer_elem_list *list) |
25a9a4f9 | 828 | { |
7ac2246f | 829 | return snd_mbox1_src_switch_update(list->mixer, list->kctl->private_value); |
25a9a4f9 TI |
830 | } |
831 | ||
7ac2246f | 832 | static const struct snd_kcontrol_new snd_mbox1_clk_switch = { |
d497a82f DZ |
833 | .iface = SNDRV_CTL_ELEM_IFACE_MIXER, |
834 | .name = "Clock Source", | |
835 | .index = 0, | |
836 | .access = SNDRV_CTL_ELEM_ACCESS_READWRITE, | |
7ac2246f DZ |
837 | .info = snd_mbox1_clk_switch_info, |
838 | .get = snd_mbox1_clk_switch_get, | |
839 | .put = snd_mbox1_clk_switch_put, | |
840 | .private_value = 0 | |
841 | }; | |
842 | ||
843 | static const struct snd_kcontrol_new snd_mbox1_src_switch = { | |
844 | .iface = SNDRV_CTL_ELEM_IFACE_MIXER, | |
845 | .name = "Input Source", | |
846 | .index = 1, | |
847 | .access = SNDRV_CTL_ELEM_ACCESS_READWRITE, | |
848 | .info = snd_mbox1_src_switch_info, | |
849 | .get = snd_mbox1_src_switch_get, | |
850 | .put = snd_mbox1_src_switch_put, | |
d497a82f DZ |
851 | .private_value = 0 |
852 | }; | |
853 | ||
7ac2246f | 854 | static int snd_mbox1_controls_create(struct usb_mixer_interface *mixer) |
d497a82f | 855 | { |
7ac2246f DZ |
856 | int err; |
857 | err = add_single_ctl_with_resume(mixer, 0, | |
858 | snd_mbox1_clk_switch_resume, | |
859 | &snd_mbox1_clk_switch, NULL); | |
860 | if (err < 0) | |
861 | return err; | |
862 | ||
863 | return add_single_ctl_with_resume(mixer, 1, | |
864 | snd_mbox1_src_switch_resume, | |
865 | &snd_mbox1_src_switch, NULL); | |
d497a82f DZ |
866 | } |
867 | ||
54a8c500 DM |
868 | /* Native Instruments device quirks */ |
869 | ||
870 | #define _MAKE_NI_CONTROL(bRequest,wIndex) ((bRequest) << 16 | (wIndex)) | |
871 | ||
da6d2769 TI |
872 | static int snd_ni_control_init_val(struct usb_mixer_interface *mixer, |
873 | struct snd_kcontrol *kctl) | |
54a8c500 | 874 | { |
54a8c500 | 875 | struct usb_device *dev = mixer->chip->dev; |
da6d2769 TI |
876 | unsigned int pval = kctl->private_value; |
877 | u8 value; | |
878 | int err; | |
54a8c500 | 879 | |
da6d2769 TI |
880 | err = snd_usb_ctl_msg(dev, usb_rcvctrlpipe(dev, 0), |
881 | (pval >> 16) & 0xff, | |
882 | USB_TYPE_VENDOR | USB_RECIP_DEVICE | USB_DIR_IN, | |
883 | 0, pval & 0xffff, &value, 1); | |
884 | if (err < 0) { | |
0ba41d91 | 885 | dev_err(&dev->dev, |
da6d2769 TI |
886 | "unable to issue vendor read request (ret = %d)", err); |
887 | return err; | |
54a8c500 DM |
888 | } |
889 | ||
2acf5a3e | 890 | kctl->private_value |= ((unsigned int)value << 24); |
da6d2769 TI |
891 | return 0; |
892 | } | |
54a8c500 | 893 | |
da6d2769 TI |
894 | static int snd_nativeinstruments_control_get(struct snd_kcontrol *kcontrol, |
895 | struct snd_ctl_elem_value *ucontrol) | |
896 | { | |
897 | ucontrol->value.integer.value[0] = kcontrol->private_value >> 24; | |
54a8c500 DM |
898 | return 0; |
899 | } | |
900 | ||
da6d2769 TI |
901 | static int snd_ni_update_cur_val(struct usb_mixer_elem_list *list) |
902 | { | |
903 | struct snd_usb_audio *chip = list->mixer->chip; | |
904 | unsigned int pval = list->kctl->private_value; | |
905 | int err; | |
906 | ||
47ab1545 TI |
907 | err = snd_usb_lock_shutdown(chip); |
908 | if (err < 0) | |
909 | return err; | |
910 | err = usb_control_msg(chip->dev, usb_sndctrlpipe(chip->dev, 0), | |
911 | (pval >> 16) & 0xff, | |
912 | USB_TYPE_VENDOR | USB_RECIP_DEVICE | USB_DIR_OUT, | |
913 | pval >> 24, pval & 0xffff, NULL, 0, 1000); | |
914 | snd_usb_unlock_shutdown(chip); | |
da6d2769 TI |
915 | return err; |
916 | } | |
917 | ||
54a8c500 DM |
918 | static int snd_nativeinstruments_control_put(struct snd_kcontrol *kcontrol, |
919 | struct snd_ctl_elem_value *ucontrol) | |
920 | { | |
da6d2769 TI |
921 | struct usb_mixer_elem_list *list = snd_kcontrol_chip(kcontrol); |
922 | u8 oldval = (kcontrol->private_value >> 24) & 0xff; | |
923 | u8 newval = ucontrol->value.integer.value[0]; | |
924 | int err; | |
54a8c500 | 925 | |
da6d2769 TI |
926 | if (oldval == newval) |
927 | return 0; | |
54a8c500 | 928 | |
da6d2769 | 929 | kcontrol->private_value &= ~(0xff << 24); |
c4a359a0 | 930 | kcontrol->private_value |= (unsigned int)newval << 24; |
da6d2769 TI |
931 | err = snd_ni_update_cur_val(list); |
932 | return err < 0 ? err : 1; | |
54a8c500 DM |
933 | } |
934 | ||
195727e8 | 935 | static const struct snd_kcontrol_new snd_nativeinstruments_ta6_mixers[] = { |
54a8c500 DM |
936 | { |
937 | .name = "Direct Thru Channel A", | |
938 | .private_value = _MAKE_NI_CONTROL(0x01, 0x03), | |
939 | }, | |
940 | { | |
941 | .name = "Direct Thru Channel B", | |
942 | .private_value = _MAKE_NI_CONTROL(0x01, 0x05), | |
943 | }, | |
944 | { | |
945 | .name = "Phono Input Channel A", | |
946 | .private_value = _MAKE_NI_CONTROL(0x02, 0x03), | |
947 | }, | |
948 | { | |
949 | .name = "Phono Input Channel B", | |
950 | .private_value = _MAKE_NI_CONTROL(0x02, 0x05), | |
951 | }, | |
952 | }; | |
953 | ||
195727e8 | 954 | static const struct snd_kcontrol_new snd_nativeinstruments_ta10_mixers[] = { |
54a8c500 DM |
955 | { |
956 | .name = "Direct Thru Channel A", | |
957 | .private_value = _MAKE_NI_CONTROL(0x01, 0x03), | |
958 | }, | |
959 | { | |
960 | .name = "Direct Thru Channel B", | |
961 | .private_value = _MAKE_NI_CONTROL(0x01, 0x05), | |
962 | }, | |
963 | { | |
964 | .name = "Direct Thru Channel C", | |
965 | .private_value = _MAKE_NI_CONTROL(0x01, 0x07), | |
966 | }, | |
967 | { | |
968 | .name = "Direct Thru Channel D", | |
969 | .private_value = _MAKE_NI_CONTROL(0x01, 0x09), | |
970 | }, | |
971 | { | |
972 | .name = "Phono Input Channel A", | |
973 | .private_value = _MAKE_NI_CONTROL(0x02, 0x03), | |
974 | }, | |
975 | { | |
976 | .name = "Phono Input Channel B", | |
977 | .private_value = _MAKE_NI_CONTROL(0x02, 0x05), | |
978 | }, | |
979 | { | |
980 | .name = "Phono Input Channel C", | |
981 | .private_value = _MAKE_NI_CONTROL(0x02, 0x07), | |
982 | }, | |
983 | { | |
984 | .name = "Phono Input Channel D", | |
985 | .private_value = _MAKE_NI_CONTROL(0x02, 0x09), | |
986 | }, | |
987 | }; | |
988 | ||
989 | static int snd_nativeinstruments_create_mixer(struct usb_mixer_interface *mixer, | |
990 | const struct snd_kcontrol_new *kc, | |
991 | unsigned int count) | |
992 | { | |
993 | int i, err = 0; | |
994 | struct snd_kcontrol_new template = { | |
995 | .iface = SNDRV_CTL_ELEM_IFACE_MIXER, | |
996 | .access = SNDRV_CTL_ELEM_ACCESS_READWRITE, | |
997 | .get = snd_nativeinstruments_control_get, | |
998 | .put = snd_nativeinstruments_control_put, | |
999 | .info = snd_ctl_boolean_mono_info, | |
1000 | }; | |
1001 | ||
1002 | for (i = 0; i < count; i++) { | |
da6d2769 | 1003 | struct usb_mixer_elem_list *list; |
54a8c500 DM |
1004 | |
1005 | template.name = kc[i].name; | |
1006 | template.private_value = kc[i].private_value; | |
1007 | ||
da6d2769 TI |
1008 | err = add_single_ctl_with_resume(mixer, 0, |
1009 | snd_ni_update_cur_val, | |
1010 | &template, &list); | |
54a8c500 DM |
1011 | if (err < 0) |
1012 | break; | |
da6d2769 | 1013 | snd_ni_control_init_val(mixer, list->kctl); |
54a8c500 DM |
1014 | } |
1015 | ||
1016 | return err; | |
1017 | } | |
1018 | ||
d5a0bf6c | 1019 | /* M-Audio FastTrack Ultra quirks */ |
e9a25e04 | 1020 | /* FTU Effect switch (also used by C400/C600) */ |
d34bf148 FH |
1021 | static int snd_ftu_eff_switch_info(struct snd_kcontrol *kcontrol, |
1022 | struct snd_ctl_elem_info *uinfo) | |
1023 | { | |
7bbd03e0 TI |
1024 | static const char *const texts[8] = { |
1025 | "Room 1", "Room 2", "Room 3", "Hall 1", | |
1026 | "Hall 2", "Plate", "Delay", "Echo" | |
d34bf148 FH |
1027 | }; |
1028 | ||
7bbd03e0 | 1029 | return snd_ctl_enum_info(uinfo, 1, ARRAY_SIZE(texts), texts); |
d34bf148 FH |
1030 | } |
1031 | ||
0b4e9cfc TI |
1032 | static int snd_ftu_eff_switch_init(struct usb_mixer_interface *mixer, |
1033 | struct snd_kcontrol *kctl) | |
d34bf148 | 1034 | { |
0b4e9cfc TI |
1035 | struct usb_device *dev = mixer->chip->dev; |
1036 | unsigned int pval = kctl->private_value; | |
d34bf148 FH |
1037 | int err; |
1038 | unsigned char value[2]; | |
d34bf148 FH |
1039 | |
1040 | value[0] = 0x00; | |
1041 | value[1] = 0x00; | |
1042 | ||
0b4e9cfc TI |
1043 | err = snd_usb_ctl_msg(dev, usb_rcvctrlpipe(dev, 0), UAC_GET_CUR, |
1044 | USB_RECIP_INTERFACE | USB_TYPE_CLASS | USB_DIR_IN, | |
1045 | pval & 0xff00, | |
1046 | snd_usb_ctrl_intf(mixer->chip) | ((pval & 0xff) << 8), | |
1047 | value, 2); | |
1048 | if (err < 0) | |
1049 | return err; | |
d34bf148 | 1050 | |
2acf5a3e | 1051 | kctl->private_value |= (unsigned int)value[0] << 24; |
0b4e9cfc TI |
1052 | return 0; |
1053 | } | |
d34bf148 | 1054 | |
0b4e9cfc TI |
1055 | static int snd_ftu_eff_switch_get(struct snd_kcontrol *kctl, |
1056 | struct snd_ctl_elem_value *ucontrol) | |
1057 | { | |
1058 | ucontrol->value.enumerated.item[0] = kctl->private_value >> 24; | |
1059 | return 0; | |
1060 | } | |
d34bf148 | 1061 | |
0b4e9cfc TI |
1062 | static int snd_ftu_eff_switch_update(struct usb_mixer_elem_list *list) |
1063 | { | |
1064 | struct snd_usb_audio *chip = list->mixer->chip; | |
1065 | unsigned int pval = list->kctl->private_value; | |
1066 | unsigned char value[2]; | |
1067 | int err; | |
d34bf148 | 1068 | |
0b4e9cfc TI |
1069 | value[0] = pval >> 24; |
1070 | value[1] = 0; | |
d34bf148 | 1071 | |
47ab1545 TI |
1072 | err = snd_usb_lock_shutdown(chip); |
1073 | if (err < 0) | |
1074 | return err; | |
1075 | err = snd_usb_ctl_msg(chip->dev, | |
1076 | usb_sndctrlpipe(chip->dev, 0), | |
1077 | UAC_SET_CUR, | |
1078 | USB_RECIP_INTERFACE | USB_TYPE_CLASS | USB_DIR_OUT, | |
1079 | pval & 0xff00, | |
1080 | snd_usb_ctrl_intf(chip) | ((pval & 0xff) << 8), | |
1081 | value, 2); | |
1082 | snd_usb_unlock_shutdown(chip); | |
0b4e9cfc | 1083 | return err; |
d34bf148 FH |
1084 | } |
1085 | ||
1086 | static int snd_ftu_eff_switch_put(struct snd_kcontrol *kctl, | |
1087 | struct snd_ctl_elem_value *ucontrol) | |
1088 | { | |
0b4e9cfc TI |
1089 | struct usb_mixer_elem_list *list = snd_kcontrol_chip(kctl); |
1090 | unsigned int pval = list->kctl->private_value; | |
1091 | int cur_val, err, new_val; | |
d34bf148 | 1092 | |
0b4e9cfc | 1093 | cur_val = pval >> 24; |
d34bf148 | 1094 | new_val = ucontrol->value.enumerated.item[0]; |
0b4e9cfc TI |
1095 | if (cur_val == new_val) |
1096 | return 0; | |
d34bf148 | 1097 | |
0b4e9cfc TI |
1098 | kctl->private_value &= ~(0xff << 24); |
1099 | kctl->private_value |= new_val << 24; | |
1100 | err = snd_ftu_eff_switch_update(list); | |
1101 | return err < 0 ? err : 1; | |
1a290581 TI |
1102 | } |
1103 | ||
d847ce0e EZ |
1104 | static int snd_ftu_create_effect_switch(struct usb_mixer_interface *mixer, |
1105 | int validx, int bUnitID) | |
d34bf148 FH |
1106 | { |
1107 | static struct snd_kcontrol_new template = { | |
1108 | .iface = SNDRV_CTL_ELEM_IFACE_MIXER, | |
1109 | .name = "Effect Program Switch", | |
1110 | .index = 0, | |
1111 | .access = SNDRV_CTL_ELEM_ACCESS_READWRITE, | |
1112 | .info = snd_ftu_eff_switch_info, | |
1113 | .get = snd_ftu_eff_switch_get, | |
1114 | .put = snd_ftu_eff_switch_put | |
1115 | }; | |
0b4e9cfc | 1116 | struct usb_mixer_elem_list *list; |
d34bf148 | 1117 | int err; |
d34bf148 | 1118 | |
0b4e9cfc TI |
1119 | err = add_single_ctl_with_resume(mixer, bUnitID, |
1120 | snd_ftu_eff_switch_update, | |
1121 | &template, &list); | |
d34bf148 FH |
1122 | if (err < 0) |
1123 | return err; | |
0b4e9cfc TI |
1124 | list->kctl->private_value = (validx << 8) | bUnitID; |
1125 | snd_ftu_eff_switch_init(mixer, list->kctl); | |
d34bf148 FH |
1126 | return 0; |
1127 | } | |
d5a0bf6c | 1128 | |
cfe8f97c FH |
1129 | /* Create volume controls for FTU devices*/ |
1130 | static int snd_ftu_create_volume_ctls(struct usb_mixer_interface *mixer) | |
d5a0bf6c DM |
1131 | { |
1132 | char name[64]; | |
8a4d1d39 | 1133 | unsigned int control, cmask; |
d5a0bf6c DM |
1134 | int in, out, err; |
1135 | ||
8a4d1d39 FH |
1136 | const unsigned int id = 5; |
1137 | const int val_type = USB_MIXER_S16; | |
1138 | ||
d5a0bf6c | 1139 | for (out = 0; out < 8; out++) { |
8a4d1d39 | 1140 | control = out + 1; |
d5a0bf6c | 1141 | for (in = 0; in < 8; in++) { |
8a4d1d39 | 1142 | cmask = 1 << in; |
d5a0bf6c | 1143 | snprintf(name, sizeof(name), |
8a4d1d39 FH |
1144 | "AIn%d - Out%d Capture Volume", |
1145 | in + 1, out + 1); | |
1146 | err = snd_create_std_mono_ctl(mixer, id, control, | |
1147 | cmask, val_type, name, | |
25ee7ef8 | 1148 | &snd_usb_mixer_vol_tlv); |
d5a0bf6c DM |
1149 | if (err < 0) |
1150 | return err; | |
1151 | } | |
d5a0bf6c | 1152 | for (in = 8; in < 16; in++) { |
8a4d1d39 | 1153 | cmask = 1 << in; |
d5a0bf6c | 1154 | snprintf(name, sizeof(name), |
8a4d1d39 FH |
1155 | "DIn%d - Out%d Playback Volume", |
1156 | in - 7, out + 1); | |
1157 | err = snd_create_std_mono_ctl(mixer, id, control, | |
1158 | cmask, val_type, name, | |
25ee7ef8 | 1159 | &snd_usb_mixer_vol_tlv); |
d5a0bf6c DM |
1160 | if (err < 0) |
1161 | return err; | |
1162 | } | |
1163 | } | |
1164 | ||
1165 | return 0; | |
1166 | } | |
1167 | ||
d34bf148 FH |
1168 | /* This control needs a volume quirk, see mixer.c */ |
1169 | static int snd_ftu_create_effect_volume_ctl(struct usb_mixer_interface *mixer) | |
1170 | { | |
1171 | static const char name[] = "Effect Volume"; | |
1172 | const unsigned int id = 6; | |
1173 | const int val_type = USB_MIXER_U8; | |
1174 | const unsigned int control = 2; | |
1175 | const unsigned int cmask = 0; | |
1176 | ||
1177 | return snd_create_std_mono_ctl(mixer, id, control, cmask, val_type, | |
1178 | name, snd_usb_mixer_vol_tlv); | |
1179 | } | |
1180 | ||
1181 | /* This control needs a volume quirk, see mixer.c */ | |
1182 | static int snd_ftu_create_effect_duration_ctl(struct usb_mixer_interface *mixer) | |
1183 | { | |
1184 | static const char name[] = "Effect Duration"; | |
1185 | const unsigned int id = 6; | |
1186 | const int val_type = USB_MIXER_S16; | |
1187 | const unsigned int control = 3; | |
1188 | const unsigned int cmask = 0; | |
1189 | ||
1190 | return snd_create_std_mono_ctl(mixer, id, control, cmask, val_type, | |
1191 | name, snd_usb_mixer_vol_tlv); | |
1192 | } | |
1193 | ||
1194 | /* This control needs a volume quirk, see mixer.c */ | |
1195 | static int snd_ftu_create_effect_feedback_ctl(struct usb_mixer_interface *mixer) | |
1196 | { | |
1197 | static const char name[] = "Effect Feedback Volume"; | |
1198 | const unsigned int id = 6; | |
1199 | const int val_type = USB_MIXER_U8; | |
1200 | const unsigned int control = 4; | |
1201 | const unsigned int cmask = 0; | |
1202 | ||
1203 | return snd_create_std_mono_ctl(mixer, id, control, cmask, val_type, | |
1204 | name, NULL); | |
1205 | } | |
1206 | ||
1207 | static int snd_ftu_create_effect_return_ctls(struct usb_mixer_interface *mixer) | |
1208 | { | |
1209 | unsigned int cmask; | |
1210 | int err, ch; | |
1211 | char name[48]; | |
1212 | ||
1213 | const unsigned int id = 7; | |
1214 | const int val_type = USB_MIXER_S16; | |
1215 | const unsigned int control = 7; | |
1216 | ||
1217 | for (ch = 0; ch < 4; ++ch) { | |
1218 | cmask = 1 << ch; | |
1219 | snprintf(name, sizeof(name), | |
1220 | "Effect Return %d Volume", ch + 1); | |
1221 | err = snd_create_std_mono_ctl(mixer, id, control, | |
1222 | cmask, val_type, name, | |
1223 | snd_usb_mixer_vol_tlv); | |
1224 | if (err < 0) | |
1225 | return err; | |
1226 | } | |
1227 | ||
1228 | return 0; | |
1229 | } | |
1230 | ||
1231 | static int snd_ftu_create_effect_send_ctls(struct usb_mixer_interface *mixer) | |
1232 | { | |
1233 | unsigned int cmask; | |
1234 | int err, ch; | |
1235 | char name[48]; | |
1236 | ||
1237 | const unsigned int id = 5; | |
1238 | const int val_type = USB_MIXER_S16; | |
1239 | const unsigned int control = 9; | |
1240 | ||
1241 | for (ch = 0; ch < 8; ++ch) { | |
1242 | cmask = 1 << ch; | |
1243 | snprintf(name, sizeof(name), | |
1244 | "Effect Send AIn%d Volume", ch + 1); | |
1245 | err = snd_create_std_mono_ctl(mixer, id, control, cmask, | |
1246 | val_type, name, | |
1247 | snd_usb_mixer_vol_tlv); | |
1248 | if (err < 0) | |
1249 | return err; | |
1250 | } | |
1251 | for (ch = 8; ch < 16; ++ch) { | |
1252 | cmask = 1 << ch; | |
1253 | snprintf(name, sizeof(name), | |
1254 | "Effect Send DIn%d Volume", ch - 7); | |
1255 | err = snd_create_std_mono_ctl(mixer, id, control, cmask, | |
1256 | val_type, name, | |
1257 | snd_usb_mixer_vol_tlv); | |
1258 | if (err < 0) | |
1259 | return err; | |
1260 | } | |
1261 | return 0; | |
1262 | } | |
1263 | ||
cfe8f97c | 1264 | static int snd_ftu_create_mixer(struct usb_mixer_interface *mixer) |
7536c301 | 1265 | { |
8a4d1d39 | 1266 | int err; |
7536c301 | 1267 | |
cfe8f97c | 1268 | err = snd_ftu_create_volume_ctls(mixer); |
8a4d1d39 FH |
1269 | if (err < 0) |
1270 | return err; | |
7536c301 | 1271 | |
d847ce0e | 1272 | err = snd_ftu_create_effect_switch(mixer, 1, 6); |
d34bf148 FH |
1273 | if (err < 0) |
1274 | return err; | |
d847ce0e | 1275 | |
d34bf148 FH |
1276 | err = snd_ftu_create_effect_volume_ctl(mixer); |
1277 | if (err < 0) | |
1278 | return err; | |
1279 | ||
1280 | err = snd_ftu_create_effect_duration_ctl(mixer); | |
1281 | if (err < 0) | |
1282 | return err; | |
1283 | ||
1284 | err = snd_ftu_create_effect_feedback_ctl(mixer); | |
1285 | if (err < 0) | |
1286 | return err; | |
1287 | ||
1288 | err = snd_ftu_create_effect_return_ctls(mixer); | |
1289 | if (err < 0) | |
1290 | return err; | |
1291 | ||
1292 | err = snd_ftu_create_effect_send_ctls(mixer); | |
1293 | if (err < 0) | |
1294 | return err; | |
1295 | ||
8a4d1d39 | 1296 | return 0; |
7536c301 MH |
1297 | } |
1298 | ||
7b1eda22 DM |
1299 | void snd_emuusb_set_samplerate(struct snd_usb_audio *chip, |
1300 | unsigned char samplerate_id) | |
1301 | { | |
1302 | struct usb_mixer_interface *mixer; | |
1303 | struct usb_mixer_elem_info *cval; | |
6de3c9e3 | 1304 | int unitid = 12; /* SampleRate ExtensionUnit ID */ |
7b1eda22 DM |
1305 | |
1306 | list_for_each_entry(mixer, &chip->mixer_list, list) { | |
6de3c9e3 TI |
1307 | if (mixer->id_elems[unitid]) { |
1308 | cval = mixer_elem_list_to_info(mixer->id_elems[unitid]); | |
7b1eda22 DM |
1309 | snd_usb_mixer_set_ctl_value(cval, UAC_SET_CUR, |
1310 | cval->control << 8, | |
1311 | samplerate_id); | |
1312 | snd_usb_mixer_notify_id(mixer, unitid); | |
6de3c9e3 | 1313 | break; |
7b1eda22 | 1314 | } |
7b1eda22 DM |
1315 | } |
1316 | } | |
1317 | ||
e9a25e04 MG |
1318 | /* M-Audio Fast Track C400/C600 */ |
1319 | /* C400/C600 volume controls, this control needs a volume quirk, see mixer.c */ | |
09d8e3a7 EZ |
1320 | static int snd_c400_create_vol_ctls(struct usb_mixer_interface *mixer) |
1321 | { | |
1322 | char name[64]; | |
1323 | unsigned int cmask, offset; | |
1324 | int out, chan, err; | |
e9a25e04 MG |
1325 | int num_outs = 0; |
1326 | int num_ins = 0; | |
09d8e3a7 EZ |
1327 | |
1328 | const unsigned int id = 0x40; | |
1329 | const int val_type = USB_MIXER_S16; | |
1330 | const int control = 1; | |
1331 | ||
e9a25e04 MG |
1332 | switch (mixer->chip->usb_id) { |
1333 | case USB_ID(0x0763, 0x2030): | |
1334 | num_outs = 6; | |
1335 | num_ins = 4; | |
1336 | break; | |
1337 | case USB_ID(0x0763, 0x2031): | |
1338 | num_outs = 8; | |
1339 | num_ins = 6; | |
1340 | break; | |
1341 | } | |
1342 | ||
1343 | for (chan = 0; chan < num_outs + num_ins; chan++) { | |
1344 | for (out = 0; out < num_outs; out++) { | |
1345 | if (chan < num_outs) { | |
09d8e3a7 EZ |
1346 | snprintf(name, sizeof(name), |
1347 | "PCM%d-Out%d Playback Volume", | |
1348 | chan + 1, out + 1); | |
1349 | } else { | |
1350 | snprintf(name, sizeof(name), | |
1351 | "In%d-Out%d Playback Volume", | |
e9a25e04 | 1352 | chan - num_outs + 1, out + 1); |
09d8e3a7 EZ |
1353 | } |
1354 | ||
1355 | cmask = (out == 0) ? 0 : 1 << (out - 1); | |
e9a25e04 | 1356 | offset = chan * num_outs; |
09d8e3a7 EZ |
1357 | err = snd_create_std_mono_ctl_offset(mixer, id, control, |
1358 | cmask, val_type, offset, name, | |
1359 | &snd_usb_mixer_vol_tlv); | |
1360 | if (err < 0) | |
1361 | return err; | |
1362 | } | |
1363 | } | |
1364 | ||
1365 | return 0; | |
1366 | } | |
1367 | ||
1368 | /* This control needs a volume quirk, see mixer.c */ | |
1369 | static int snd_c400_create_effect_volume_ctl(struct usb_mixer_interface *mixer) | |
1370 | { | |
1371 | static const char name[] = "Effect Volume"; | |
1372 | const unsigned int id = 0x43; | |
1373 | const int val_type = USB_MIXER_U8; | |
1374 | const unsigned int control = 3; | |
1375 | const unsigned int cmask = 0; | |
1376 | ||
1377 | return snd_create_std_mono_ctl(mixer, id, control, cmask, val_type, | |
1378 | name, snd_usb_mixer_vol_tlv); | |
1379 | } | |
1380 | ||
1381 | /* This control needs a volume quirk, see mixer.c */ | |
1382 | static int snd_c400_create_effect_duration_ctl(struct usb_mixer_interface *mixer) | |
1383 | { | |
1384 | static const char name[] = "Effect Duration"; | |
1385 | const unsigned int id = 0x43; | |
1386 | const int val_type = USB_MIXER_S16; | |
1387 | const unsigned int control = 4; | |
1388 | const unsigned int cmask = 0; | |
1389 | ||
1390 | return snd_create_std_mono_ctl(mixer, id, control, cmask, val_type, | |
1391 | name, snd_usb_mixer_vol_tlv); | |
1392 | } | |
1393 | ||
1394 | /* This control needs a volume quirk, see mixer.c */ | |
1395 | static int snd_c400_create_effect_feedback_ctl(struct usb_mixer_interface *mixer) | |
1396 | { | |
1397 | static const char name[] = "Effect Feedback Volume"; | |
1398 | const unsigned int id = 0x43; | |
1399 | const int val_type = USB_MIXER_U8; | |
1400 | const unsigned int control = 5; | |
1401 | const unsigned int cmask = 0; | |
1402 | ||
1403 | return snd_create_std_mono_ctl(mixer, id, control, cmask, val_type, | |
1404 | name, NULL); | |
1405 | } | |
1406 | ||
1407 | static int snd_c400_create_effect_vol_ctls(struct usb_mixer_interface *mixer) | |
1408 | { | |
1409 | char name[64]; | |
1410 | unsigned int cmask; | |
1411 | int chan, err; | |
e9a25e04 MG |
1412 | int num_outs = 0; |
1413 | int num_ins = 0; | |
09d8e3a7 EZ |
1414 | |
1415 | const unsigned int id = 0x42; | |
1416 | const int val_type = USB_MIXER_S16; | |
1417 | const int control = 1; | |
1418 | ||
e9a25e04 MG |
1419 | switch (mixer->chip->usb_id) { |
1420 | case USB_ID(0x0763, 0x2030): | |
1421 | num_outs = 6; | |
1422 | num_ins = 4; | |
1423 | break; | |
1424 | case USB_ID(0x0763, 0x2031): | |
1425 | num_outs = 8; | |
1426 | num_ins = 6; | |
1427 | break; | |
1428 | } | |
1429 | ||
1430 | for (chan = 0; chan < num_outs + num_ins; chan++) { | |
1431 | if (chan < num_outs) { | |
09d8e3a7 EZ |
1432 | snprintf(name, sizeof(name), |
1433 | "Effect Send DOut%d", | |
1434 | chan + 1); | |
1435 | } else { | |
1436 | snprintf(name, sizeof(name), | |
1437 | "Effect Send AIn%d", | |
e9a25e04 | 1438 | chan - num_outs + 1); |
09d8e3a7 EZ |
1439 | } |
1440 | ||
1441 | cmask = (chan == 0) ? 0 : 1 << (chan - 1); | |
1442 | err = snd_create_std_mono_ctl(mixer, id, control, | |
1443 | cmask, val_type, name, | |
1444 | &snd_usb_mixer_vol_tlv); | |
1445 | if (err < 0) | |
1446 | return err; | |
1447 | } | |
1448 | ||
1449 | return 0; | |
1450 | } | |
1451 | ||
1452 | static int snd_c400_create_effect_ret_vol_ctls(struct usb_mixer_interface *mixer) | |
1453 | { | |
1454 | char name[64]; | |
1455 | unsigned int cmask; | |
1456 | int chan, err; | |
e9a25e04 MG |
1457 | int num_outs = 0; |
1458 | int offset = 0; | |
09d8e3a7 EZ |
1459 | |
1460 | const unsigned int id = 0x40; | |
1461 | const int val_type = USB_MIXER_S16; | |
1462 | const int control = 1; | |
09d8e3a7 | 1463 | |
e9a25e04 MG |
1464 | switch (mixer->chip->usb_id) { |
1465 | case USB_ID(0x0763, 0x2030): | |
1466 | num_outs = 6; | |
1467 | offset = 0x3c; | |
1468 | /* { 0x3c, 0x43, 0x3e, 0x45, 0x40, 0x47 } */ | |
1469 | break; | |
1470 | case USB_ID(0x0763, 0x2031): | |
1471 | num_outs = 8; | |
1472 | offset = 0x70; | |
1473 | /* { 0x70, 0x79, 0x72, 0x7b, 0x74, 0x7d, 0x76, 0x7f } */ | |
1474 | break; | |
1475 | } | |
1476 | ||
1477 | for (chan = 0; chan < num_outs; chan++) { | |
09d8e3a7 EZ |
1478 | snprintf(name, sizeof(name), |
1479 | "Effect Return %d", | |
1480 | chan + 1); | |
1481 | ||
e9a25e04 MG |
1482 | cmask = (chan == 0) ? 0 : |
1483 | 1 << (chan + (chan % 2) * num_outs - 1); | |
09d8e3a7 EZ |
1484 | err = snd_create_std_mono_ctl_offset(mixer, id, control, |
1485 | cmask, val_type, offset, name, | |
1486 | &snd_usb_mixer_vol_tlv); | |
1487 | if (err < 0) | |
1488 | return err; | |
1489 | } | |
1490 | ||
1491 | return 0; | |
1492 | } | |
1493 | ||
1494 | static int snd_c400_create_mixer(struct usb_mixer_interface *mixer) | |
1495 | { | |
1496 | int err; | |
1497 | ||
1498 | err = snd_c400_create_vol_ctls(mixer); | |
1499 | if (err < 0) | |
1500 | return err; | |
1501 | ||
1502 | err = snd_c400_create_effect_vol_ctls(mixer); | |
1503 | if (err < 0) | |
1504 | return err; | |
1505 | ||
1506 | err = snd_c400_create_effect_ret_vol_ctls(mixer); | |
1507 | if (err < 0) | |
1508 | return err; | |
1509 | ||
1510 | err = snd_ftu_create_effect_switch(mixer, 2, 0x43); | |
1511 | if (err < 0) | |
1512 | return err; | |
1513 | ||
1514 | err = snd_c400_create_effect_volume_ctl(mixer); | |
1515 | if (err < 0) | |
1516 | return err; | |
1517 | ||
1518 | err = snd_c400_create_effect_duration_ctl(mixer); | |
1519 | if (err < 0) | |
1520 | return err; | |
1521 | ||
1522 | err = snd_c400_create_effect_feedback_ctl(mixer); | |
1523 | if (err < 0) | |
1524 | return err; | |
1525 | ||
1526 | return 0; | |
1527 | } | |
1528 | ||
b71dad18 MH |
1529 | /* |
1530 | * The mixer units for Ebox-44 are corrupt, and even where they | |
1531 | * are valid they presents mono controls as L and R channels of | |
1532 | * stereo. So we provide a good mixer here. | |
1533 | */ | |
a01df925 | 1534 | static const struct std_mono_table ebox44_table[] = { |
989b0138 MH |
1535 | { |
1536 | .unitid = 4, | |
1537 | .control = 1, | |
1538 | .cmask = 0x0, | |
1539 | .val_type = USB_MIXER_INV_BOOLEAN, | |
1540 | .name = "Headphone Playback Switch" | |
1541 | }, | |
1542 | { | |
1543 | .unitid = 4, | |
1544 | .control = 2, | |
1545 | .cmask = 0x1, | |
1546 | .val_type = USB_MIXER_S16, | |
1547 | .name = "Headphone A Mix Playback Volume" | |
1548 | }, | |
1549 | { | |
1550 | .unitid = 4, | |
1551 | .control = 2, | |
1552 | .cmask = 0x2, | |
1553 | .val_type = USB_MIXER_S16, | |
1554 | .name = "Headphone B Mix Playback Volume" | |
1555 | }, | |
b71dad18 | 1556 | |
989b0138 MH |
1557 | { |
1558 | .unitid = 7, | |
1559 | .control = 1, | |
1560 | .cmask = 0x0, | |
1561 | .val_type = USB_MIXER_INV_BOOLEAN, | |
1562 | .name = "Output Playback Switch" | |
1563 | }, | |
1564 | { | |
1565 | .unitid = 7, | |
1566 | .control = 2, | |
1567 | .cmask = 0x1, | |
1568 | .val_type = USB_MIXER_S16, | |
1569 | .name = "Output A Playback Volume" | |
1570 | }, | |
1571 | { | |
1572 | .unitid = 7, | |
1573 | .control = 2, | |
1574 | .cmask = 0x2, | |
1575 | .val_type = USB_MIXER_S16, | |
1576 | .name = "Output B Playback Volume" | |
1577 | }, | |
b71dad18 | 1578 | |
989b0138 MH |
1579 | { |
1580 | .unitid = 10, | |
1581 | .control = 1, | |
1582 | .cmask = 0x0, | |
1583 | .val_type = USB_MIXER_INV_BOOLEAN, | |
1584 | .name = "Input Capture Switch" | |
1585 | }, | |
1586 | { | |
1587 | .unitid = 10, | |
1588 | .control = 2, | |
1589 | .cmask = 0x1, | |
1590 | .val_type = USB_MIXER_S16, | |
1591 | .name = "Input A Capture Volume" | |
1592 | }, | |
1593 | { | |
1594 | .unitid = 10, | |
1595 | .control = 2, | |
1596 | .cmask = 0x2, | |
1597 | .val_type = USB_MIXER_S16, | |
1598 | .name = "Input B Capture Volume" | |
1599 | }, | |
b71dad18 | 1600 | |
989b0138 | 1601 | {} |
b71dad18 MH |
1602 | }; |
1603 | ||
066624c6 PR |
1604 | /* Audio Advantage Micro II findings: |
1605 | * | |
1606 | * Mapping spdif AES bits to vendor register.bit: | |
1607 | * AES0: [0 0 0 0 2.3 2.2 2.1 2.0] - default 0x00 | |
1608 | * AES1: [3.3 3.2.3.1.3.0 2.7 2.6 2.5 2.4] - default: 0x01 | |
1609 | * AES2: [0 0 0 0 0 0 0 0] | |
1610 | * AES3: [0 0 0 0 0 0 x 0] - 'x' bit is set basing on standard usb request | |
1611 | * (UAC_EP_CS_ATTR_SAMPLE_RATE) for Audio Devices | |
1612 | * | |
1613 | * power on values: | |
1614 | * r2: 0x10 | |
1615 | * r3: 0x20 (b7 is zeroed just before playback (except IEC61937) and set | |
1616 | * just after it to 0xa0, presumably it disables/mutes some analog | |
1617 | * parts when there is no audio.) | |
1618 | * r9: 0x28 | |
1619 | * | |
1620 | * Optical transmitter on/off: | |
1621 | * vendor register.bit: 9.1 | |
1622 | * 0 - on (0x28 register value) | |
1623 | * 1 - off (0x2a register value) | |
1624 | * | |
1625 | */ | |
1626 | static int snd_microii_spdif_info(struct snd_kcontrol *kcontrol, | |
1627 | struct snd_ctl_elem_info *uinfo) | |
1628 | { | |
1629 | uinfo->type = SNDRV_CTL_ELEM_TYPE_IEC958; | |
1630 | uinfo->count = 1; | |
1631 | return 0; | |
1632 | } | |
1633 | ||
1634 | static int snd_microii_spdif_default_get(struct snd_kcontrol *kcontrol, | |
1635 | struct snd_ctl_elem_value *ucontrol) | |
1636 | { | |
288673be TI |
1637 | struct usb_mixer_elem_list *list = snd_kcontrol_chip(kcontrol); |
1638 | struct snd_usb_audio *chip = list->mixer->chip; | |
066624c6 PR |
1639 | int err; |
1640 | struct usb_interface *iface; | |
1641 | struct usb_host_interface *alts; | |
1642 | unsigned int ep; | |
1643 | unsigned char data[3]; | |
1644 | int rate; | |
1645 | ||
47ab1545 TI |
1646 | err = snd_usb_lock_shutdown(chip); |
1647 | if (err < 0) | |
1648 | return err; | |
288673be | 1649 | |
066624c6 PR |
1650 | ucontrol->value.iec958.status[0] = kcontrol->private_value & 0xff; |
1651 | ucontrol->value.iec958.status[1] = (kcontrol->private_value >> 8) & 0xff; | |
1652 | ucontrol->value.iec958.status[2] = 0x00; | |
1653 | ||
1654 | /* use known values for that card: interface#1 altsetting#1 */ | |
288673be | 1655 | iface = usb_ifnum_to_if(chip->dev, 1); |
59e1947c XY |
1656 | if (!iface || iface->num_altsetting < 2) { |
1657 | err = -EINVAL; | |
1658 | goto end; | |
1659 | } | |
066624c6 | 1660 | alts = &iface->altsetting[1]; |
59e1947c XY |
1661 | if (get_iface_desc(alts)->bNumEndpoints < 1) { |
1662 | err = -EINVAL; | |
1663 | goto end; | |
1664 | } | |
066624c6 PR |
1665 | ep = get_endpoint(alts, 0)->bEndpointAddress; |
1666 | ||
288673be TI |
1667 | err = snd_usb_ctl_msg(chip->dev, |
1668 | usb_rcvctrlpipe(chip->dev, 0), | |
066624c6 PR |
1669 | UAC_GET_CUR, |
1670 | USB_TYPE_CLASS | USB_RECIP_ENDPOINT | USB_DIR_IN, | |
1671 | UAC_EP_CS_ATTR_SAMPLE_RATE << 8, | |
1672 | ep, | |
1673 | data, | |
1674 | sizeof(data)); | |
1675 | if (err < 0) | |
1676 | goto end; | |
1677 | ||
1678 | rate = data[0] | (data[1] << 8) | (data[2] << 16); | |
1679 | ucontrol->value.iec958.status[3] = (rate == 48000) ? | |
1680 | IEC958_AES3_CON_FS_48000 : IEC958_AES3_CON_FS_44100; | |
1681 | ||
1682 | err = 0; | |
288673be | 1683 | end: |
47ab1545 | 1684 | snd_usb_unlock_shutdown(chip); |
066624c6 PR |
1685 | return err; |
1686 | } | |
1687 | ||
288673be | 1688 | static int snd_microii_spdif_default_update(struct usb_mixer_elem_list *list) |
066624c6 | 1689 | { |
288673be TI |
1690 | struct snd_usb_audio *chip = list->mixer->chip; |
1691 | unsigned int pval = list->kctl->private_value; | |
066624c6 | 1692 | u8 reg; |
288673be TI |
1693 | int err; |
1694 | ||
47ab1545 TI |
1695 | err = snd_usb_lock_shutdown(chip); |
1696 | if (err < 0) | |
1697 | return err; | |
066624c6 | 1698 | |
288673be TI |
1699 | reg = ((pval >> 4) & 0xf0) | (pval & 0x0f); |
1700 | err = snd_usb_ctl_msg(chip->dev, | |
1701 | usb_sndctrlpipe(chip->dev, 0), | |
066624c6 PR |
1702 | UAC_SET_CUR, |
1703 | USB_DIR_OUT | USB_TYPE_VENDOR | USB_RECIP_OTHER, | |
1704 | reg, | |
1705 | 2, | |
1706 | NULL, | |
1707 | 0); | |
1708 | if (err < 0) | |
1709 | goto end; | |
1710 | ||
288673be TI |
1711 | reg = (pval & IEC958_AES0_NONAUDIO) ? 0xa0 : 0x20; |
1712 | reg |= (pval >> 12) & 0x0f; | |
1713 | err = snd_usb_ctl_msg(chip->dev, | |
1714 | usb_sndctrlpipe(chip->dev, 0), | |
066624c6 PR |
1715 | UAC_SET_CUR, |
1716 | USB_DIR_OUT | USB_TYPE_VENDOR | USB_RECIP_OTHER, | |
1717 | reg, | |
1718 | 3, | |
1719 | NULL, | |
1720 | 0); | |
1721 | if (err < 0) | |
1722 | goto end; | |
1723 | ||
288673be | 1724 | end: |
47ab1545 | 1725 | snd_usb_unlock_shutdown(chip); |
288673be TI |
1726 | return err; |
1727 | } | |
1728 | ||
1729 | static int snd_microii_spdif_default_put(struct snd_kcontrol *kcontrol, | |
1730 | struct snd_ctl_elem_value *ucontrol) | |
1731 | { | |
1732 | struct usb_mixer_elem_list *list = snd_kcontrol_chip(kcontrol); | |
1733 | unsigned int pval, pval_old; | |
1734 | int err; | |
1735 | ||
1736 | pval = pval_old = kcontrol->private_value; | |
1737 | pval &= 0xfffff0f0; | |
1738 | pval |= (ucontrol->value.iec958.status[1] & 0x0f) << 8; | |
1739 | pval |= (ucontrol->value.iec958.status[0] & 0x0f); | |
1740 | ||
1741 | pval &= 0xffff0fff; | |
1742 | pval |= (ucontrol->value.iec958.status[1] & 0xf0) << 8; | |
066624c6 PR |
1743 | |
1744 | /* The frequency bits in AES3 cannot be set via register access. */ | |
1745 | ||
1746 | /* Silently ignore any bits from the request that cannot be set. */ | |
1747 | ||
288673be TI |
1748 | if (pval == pval_old) |
1749 | return 0; | |
1750 | ||
1751 | kcontrol->private_value = pval; | |
1752 | err = snd_microii_spdif_default_update(list); | |
1753 | return err < 0 ? err : 1; | |
066624c6 PR |
1754 | } |
1755 | ||
1756 | static int snd_microii_spdif_mask_get(struct snd_kcontrol *kcontrol, | |
1757 | struct snd_ctl_elem_value *ucontrol) | |
1758 | { | |
1759 | ucontrol->value.iec958.status[0] = 0x0f; | |
1760 | ucontrol->value.iec958.status[1] = 0xff; | |
1761 | ucontrol->value.iec958.status[2] = 0x00; | |
1762 | ucontrol->value.iec958.status[3] = 0x00; | |
1763 | ||
1764 | return 0; | |
1765 | } | |
1766 | ||
1767 | static int snd_microii_spdif_switch_get(struct snd_kcontrol *kcontrol, | |
1768 | struct snd_ctl_elem_value *ucontrol) | |
1769 | { | |
1770 | ucontrol->value.integer.value[0] = !(kcontrol->private_value & 0x02); | |
1771 | ||
1772 | return 0; | |
1773 | } | |
1774 | ||
288673be | 1775 | static int snd_microii_spdif_switch_update(struct usb_mixer_elem_list *list) |
066624c6 | 1776 | { |
288673be TI |
1777 | struct snd_usb_audio *chip = list->mixer->chip; |
1778 | u8 reg = list->kctl->private_value; | |
066624c6 | 1779 | int err; |
066624c6 | 1780 | |
47ab1545 TI |
1781 | err = snd_usb_lock_shutdown(chip); |
1782 | if (err < 0) | |
1783 | return err; | |
288673be TI |
1784 | |
1785 | err = snd_usb_ctl_msg(chip->dev, | |
1786 | usb_sndctrlpipe(chip->dev, 0), | |
066624c6 PR |
1787 | UAC_SET_CUR, |
1788 | USB_DIR_OUT | USB_TYPE_VENDOR | USB_RECIP_OTHER, | |
1789 | reg, | |
1790 | 9, | |
1791 | NULL, | |
1792 | 0); | |
1793 | ||
47ab1545 | 1794 | snd_usb_unlock_shutdown(chip); |
066624c6 PR |
1795 | return err; |
1796 | } | |
1797 | ||
288673be TI |
1798 | static int snd_microii_spdif_switch_put(struct snd_kcontrol *kcontrol, |
1799 | struct snd_ctl_elem_value *ucontrol) | |
1800 | { | |
1801 | struct usb_mixer_elem_list *list = snd_kcontrol_chip(kcontrol); | |
1802 | u8 reg; | |
1803 | int err; | |
1804 | ||
1805 | reg = ucontrol->value.integer.value[0] ? 0x28 : 0x2a; | |
1806 | if (reg != list->kctl->private_value) | |
1807 | return 0; | |
1808 | ||
1809 | kcontrol->private_value = reg; | |
1810 | err = snd_microii_spdif_switch_update(list); | |
1811 | return err < 0 ? err : 1; | |
1812 | } | |
1813 | ||
195727e8 | 1814 | static const struct snd_kcontrol_new snd_microii_mixer_spdif[] = { |
066624c6 PR |
1815 | { |
1816 | .iface = SNDRV_CTL_ELEM_IFACE_PCM, | |
1817 | .name = SNDRV_CTL_NAME_IEC958("", PLAYBACK, DEFAULT), | |
1818 | .info = snd_microii_spdif_info, | |
1819 | .get = snd_microii_spdif_default_get, | |
1820 | .put = snd_microii_spdif_default_put, | |
1821 | .private_value = 0x00000100UL,/* reset value */ | |
1822 | }, | |
1823 | { | |
1824 | .access = SNDRV_CTL_ELEM_ACCESS_READ, | |
1825 | .iface = SNDRV_CTL_ELEM_IFACE_PCM, | |
1826 | .name = SNDRV_CTL_NAME_IEC958("", PLAYBACK, MASK), | |
1827 | .info = snd_microii_spdif_info, | |
1828 | .get = snd_microii_spdif_mask_get, | |
1829 | }, | |
1830 | { | |
1831 | .iface = SNDRV_CTL_ELEM_IFACE_MIXER, | |
1832 | .name = SNDRV_CTL_NAME_IEC958("", PLAYBACK, SWITCH), | |
1833 | .info = snd_ctl_boolean_mono_info, | |
1834 | .get = snd_microii_spdif_switch_get, | |
1835 | .put = snd_microii_spdif_switch_put, | |
1836 | .private_value = 0x00000028UL,/* reset value */ | |
1837 | } | |
1838 | }; | |
1839 | ||
1840 | static int snd_microii_controls_create(struct usb_mixer_interface *mixer) | |
1841 | { | |
1842 | int err, i; | |
ff40e0d4 | 1843 | static const usb_mixer_elem_resume_func_t resume_funcs[] = { |
288673be TI |
1844 | snd_microii_spdif_default_update, |
1845 | NULL, | |
1846 | snd_microii_spdif_switch_update | |
1847 | }; | |
066624c6 PR |
1848 | |
1849 | for (i = 0; i < ARRAY_SIZE(snd_microii_mixer_spdif); ++i) { | |
288673be TI |
1850 | err = add_single_ctl_with_resume(mixer, 0, |
1851 | resume_funcs[i], | |
1852 | &snd_microii_mixer_spdif[i], | |
1853 | NULL); | |
066624c6 PR |
1854 | if (err < 0) |
1855 | return err; | |
1856 | } | |
1857 | ||
18e4753f | 1858 | return 0; |
066624c6 PR |
1859 | } |
1860 | ||
388fdb8f IDS |
1861 | /* Creative Sound Blaster E1 */ |
1862 | ||
1863 | static int snd_soundblaster_e1_switch_get(struct snd_kcontrol *kcontrol, | |
1864 | struct snd_ctl_elem_value *ucontrol) | |
1865 | { | |
1866 | ucontrol->value.integer.value[0] = kcontrol->private_value; | |
1867 | return 0; | |
1868 | } | |
1869 | ||
1870 | static int snd_soundblaster_e1_switch_update(struct usb_mixer_interface *mixer, | |
1871 | unsigned char state) | |
1872 | { | |
1873 | struct snd_usb_audio *chip = mixer->chip; | |
1874 | int err; | |
1875 | unsigned char buff[2]; | |
1876 | ||
1877 | buff[0] = 0x02; | |
1878 | buff[1] = state ? 0x02 : 0x00; | |
1879 | ||
1880 | err = snd_usb_lock_shutdown(chip); | |
1881 | if (err < 0) | |
1882 | return err; | |
1883 | err = snd_usb_ctl_msg(chip->dev, | |
1884 | usb_sndctrlpipe(chip->dev, 0), HID_REQ_SET_REPORT, | |
1885 | USB_TYPE_CLASS | USB_RECIP_INTERFACE | USB_DIR_OUT, | |
1886 | 0x0202, 3, buff, 2); | |
1887 | snd_usb_unlock_shutdown(chip); | |
1888 | return err; | |
1889 | } | |
1890 | ||
1891 | static int snd_soundblaster_e1_switch_put(struct snd_kcontrol *kcontrol, | |
1892 | struct snd_ctl_elem_value *ucontrol) | |
1893 | { | |
1894 | struct usb_mixer_elem_list *list = snd_kcontrol_chip(kcontrol); | |
1895 | unsigned char value = !!ucontrol->value.integer.value[0]; | |
1896 | int err; | |
1897 | ||
1898 | if (kcontrol->private_value == value) | |
1899 | return 0; | |
1900 | kcontrol->private_value = value; | |
1901 | err = snd_soundblaster_e1_switch_update(list->mixer, value); | |
1902 | return err < 0 ? err : 1; | |
1903 | } | |
1904 | ||
1905 | static int snd_soundblaster_e1_switch_resume(struct usb_mixer_elem_list *list) | |
1906 | { | |
1907 | return snd_soundblaster_e1_switch_update(list->mixer, | |
1908 | list->kctl->private_value); | |
1909 | } | |
1910 | ||
1911 | static int snd_soundblaster_e1_switch_info(struct snd_kcontrol *kcontrol, | |
1912 | struct snd_ctl_elem_info *uinfo) | |
1913 | { | |
1914 | static const char *const texts[2] = { | |
1915 | "Mic", "Aux" | |
1916 | }; | |
1917 | ||
1918 | return snd_ctl_enum_info(uinfo, 1, ARRAY_SIZE(texts), texts); | |
1919 | } | |
1920 | ||
195727e8 | 1921 | static const struct snd_kcontrol_new snd_soundblaster_e1_input_switch = { |
388fdb8f IDS |
1922 | .iface = SNDRV_CTL_ELEM_IFACE_MIXER, |
1923 | .name = "Input Source", | |
1924 | .info = snd_soundblaster_e1_switch_info, | |
1925 | .get = snd_soundblaster_e1_switch_get, | |
1926 | .put = snd_soundblaster_e1_switch_put, | |
1927 | .private_value = 0, | |
1928 | }; | |
1929 | ||
1930 | static int snd_soundblaster_e1_switch_create(struct usb_mixer_interface *mixer) | |
1931 | { | |
1932 | return add_single_ctl_with_resume(mixer, 0, | |
1933 | snd_soundblaster_e1_switch_resume, | |
1934 | &snd_soundblaster_e1_input_switch, | |
1935 | NULL); | |
1936 | } | |
1937 | ||
4b8ea38f JS |
1938 | /* |
1939 | * Dell WD15 dock jack detection | |
1940 | * | |
1941 | * The WD15 contains an ALC4020 USB audio controller and ALC3263 audio codec | |
1942 | * from Realtek. It is a UAC 1 device, and UAC 1 does not support jack | |
1943 | * detection. Instead, jack detection works by sending HD Audio commands over | |
1944 | * vendor-type USB messages. | |
1945 | */ | |
1946 | ||
1947 | #define HDA_VERB_CMD(V, N, D) (((N) << 20) | ((V) << 8) | (D)) | |
1948 | ||
1949 | #define REALTEK_HDA_VALUE 0x0038 | |
1950 | ||
1951 | #define REALTEK_HDA_SET 62 | |
2e57a335 | 1952 | #define REALTEK_MANUAL_MODE 72 |
4b8ea38f JS |
1953 | #define REALTEK_HDA_GET_OUT 88 |
1954 | #define REALTEK_HDA_GET_IN 89 | |
1955 | ||
2e57a335 | 1956 | #define REALTEK_AUDIO_FUNCTION_GROUP 0x01 |
4b8ea38f JS |
1957 | #define REALTEK_LINE1 0x1a |
1958 | #define REALTEK_VENDOR_REGISTERS 0x20 | |
1959 | #define REALTEK_HP_OUT 0x21 | |
1960 | ||
1961 | #define REALTEK_CBJ_CTRL2 0x50 | |
1962 | ||
1963 | #define REALTEK_JACK_INTERRUPT_NODE 5 | |
1964 | ||
1965 | #define REALTEK_MIC_FLAG 0x100 | |
1966 | ||
1967 | static int realtek_hda_set(struct snd_usb_audio *chip, u32 cmd) | |
1968 | { | |
1969 | struct usb_device *dev = chip->dev; | |
61c606a4 | 1970 | __be32 buf = cpu_to_be32(cmd); |
4b8ea38f JS |
1971 | |
1972 | return snd_usb_ctl_msg(dev, usb_sndctrlpipe(dev, 0), REALTEK_HDA_SET, | |
1973 | USB_RECIP_DEVICE | USB_TYPE_VENDOR | USB_DIR_OUT, | |
1974 | REALTEK_HDA_VALUE, 0, &buf, sizeof(buf)); | |
1975 | } | |
1976 | ||
1977 | static int realtek_hda_get(struct snd_usb_audio *chip, u32 cmd, u32 *value) | |
1978 | { | |
1979 | struct usb_device *dev = chip->dev; | |
1980 | int err; | |
61c606a4 | 1981 | __be32 buf = cpu_to_be32(cmd); |
4b8ea38f JS |
1982 | |
1983 | err = snd_usb_ctl_msg(dev, usb_sndctrlpipe(dev, 0), REALTEK_HDA_GET_OUT, | |
1984 | USB_RECIP_DEVICE | USB_TYPE_VENDOR | USB_DIR_OUT, | |
1985 | REALTEK_HDA_VALUE, 0, &buf, sizeof(buf)); | |
1986 | if (err < 0) | |
1987 | return err; | |
1988 | err = snd_usb_ctl_msg(dev, usb_rcvctrlpipe(dev, 0), REALTEK_HDA_GET_IN, | |
1989 | USB_RECIP_DEVICE | USB_TYPE_VENDOR | USB_DIR_IN, | |
1990 | REALTEK_HDA_VALUE, 0, &buf, sizeof(buf)); | |
1991 | if (err < 0) | |
1992 | return err; | |
1993 | ||
1994 | *value = be32_to_cpu(buf); | |
1995 | return 0; | |
1996 | } | |
1997 | ||
1998 | static int realtek_ctl_connector_get(struct snd_kcontrol *kcontrol, | |
1999 | struct snd_ctl_elem_value *ucontrol) | |
2000 | { | |
2001 | struct usb_mixer_elem_info *cval = kcontrol->private_data; | |
2002 | struct snd_usb_audio *chip = cval->head.mixer->chip; | |
2003 | u32 pv = kcontrol->private_value; | |
2004 | u32 node_id = pv & 0xff; | |
2005 | u32 sense; | |
2006 | u32 cbj_ctrl2; | |
2007 | bool presence; | |
2008 | int err; | |
2009 | ||
2010 | err = snd_usb_lock_shutdown(chip); | |
2011 | if (err < 0) | |
2012 | return err; | |
2013 | err = realtek_hda_get(chip, | |
2014 | HDA_VERB_CMD(AC_VERB_GET_PIN_SENSE, node_id, 0), | |
2015 | &sense); | |
2016 | if (err < 0) | |
2017 | goto err; | |
2018 | if (pv & REALTEK_MIC_FLAG) { | |
2019 | err = realtek_hda_set(chip, | |
2020 | HDA_VERB_CMD(AC_VERB_SET_COEF_INDEX, | |
2021 | REALTEK_VENDOR_REGISTERS, | |
2022 | REALTEK_CBJ_CTRL2)); | |
2023 | if (err < 0) | |
2024 | goto err; | |
2025 | err = realtek_hda_get(chip, | |
2026 | HDA_VERB_CMD(AC_VERB_GET_PROC_COEF, | |
2027 | REALTEK_VENDOR_REGISTERS, 0), | |
2028 | &cbj_ctrl2); | |
2029 | if (err < 0) | |
2030 | goto err; | |
2031 | } | |
2032 | err: | |
2033 | snd_usb_unlock_shutdown(chip); | |
2034 | if (err < 0) | |
2035 | return err; | |
2036 | ||
2037 | presence = sense & AC_PINSENSE_PRESENCE; | |
2038 | if (pv & REALTEK_MIC_FLAG) | |
2039 | presence = presence && (cbj_ctrl2 & 0x0070) == 0x0070; | |
2040 | ucontrol->value.integer.value[0] = presence; | |
2041 | return 0; | |
2042 | } | |
2043 | ||
2044 | static const struct snd_kcontrol_new realtek_connector_ctl_ro = { | |
2045 | .iface = SNDRV_CTL_ELEM_IFACE_CARD, | |
2046 | .name = "", /* will be filled later manually */ | |
2047 | .access = SNDRV_CTL_ELEM_ACCESS_READ, | |
2048 | .info = snd_ctl_boolean_mono_info, | |
2049 | .get = realtek_ctl_connector_get, | |
2050 | }; | |
2051 | ||
2052 | static int realtek_resume_jack(struct usb_mixer_elem_list *list) | |
2053 | { | |
2054 | snd_ctl_notify(list->mixer->chip->card, SNDRV_CTL_EVENT_MASK_VALUE, | |
2055 | &list->kctl->id); | |
2056 | return 0; | |
2057 | } | |
2058 | ||
2059 | static int realtek_add_jack(struct usb_mixer_interface *mixer, | |
2060 | char *name, u32 val) | |
2061 | { | |
2062 | struct usb_mixer_elem_info *cval; | |
2063 | struct snd_kcontrol *kctl; | |
2064 | ||
2065 | cval = kzalloc(sizeof(*cval), GFP_KERNEL); | |
2066 | if (!cval) | |
2067 | return -ENOMEM; | |
2068 | snd_usb_mixer_elem_init_std(&cval->head, mixer, | |
2069 | REALTEK_JACK_INTERRUPT_NODE); | |
2070 | cval->head.resume = realtek_resume_jack; | |
2071 | cval->val_type = USB_MIXER_BOOLEAN; | |
2072 | cval->channels = 1; | |
2073 | cval->min = 0; | |
2074 | cval->max = 1; | |
2075 | kctl = snd_ctl_new1(&realtek_connector_ctl_ro, cval); | |
2076 | if (!kctl) { | |
2077 | kfree(cval); | |
2078 | return -ENOMEM; | |
2079 | } | |
2080 | kctl->private_value = val; | |
2081 | strscpy(kctl->id.name, name, sizeof(kctl->id.name)); | |
2082 | kctl->private_free = snd_usb_mixer_elem_free; | |
2083 | return snd_usb_mixer_add_control(&cval->head, kctl); | |
2084 | } | |
2085 | ||
2086 | static int dell_dock_mixer_create(struct usb_mixer_interface *mixer) | |
2087 | { | |
2088 | int err; | |
2e57a335 JS |
2089 | struct usb_device *dev = mixer->chip->dev; |
2090 | ||
2091 | /* Power down the audio codec to avoid loud pops in the next step. */ | |
2092 | realtek_hda_set(mixer->chip, | |
2093 | HDA_VERB_CMD(AC_VERB_SET_POWER_STATE, | |
2094 | REALTEK_AUDIO_FUNCTION_GROUP, | |
2095 | AC_PWRST_D3)); | |
2096 | ||
2097 | /* | |
2098 | * Turn off 'manual mode' in case it was enabled. This removes the need | |
2099 | * to power cycle the dock after it was attached to a Windows machine. | |
2100 | */ | |
2101 | snd_usb_ctl_msg(dev, usb_sndctrlpipe(dev, 0), REALTEK_MANUAL_MODE, | |
2102 | USB_RECIP_DEVICE | USB_TYPE_VENDOR | USB_DIR_OUT, | |
2103 | 0, 0, NULL, 0); | |
4b8ea38f JS |
2104 | |
2105 | err = realtek_add_jack(mixer, "Line Out Jack", REALTEK_LINE1); | |
2106 | if (err < 0) | |
2107 | return err; | |
2108 | err = realtek_add_jack(mixer, "Headphone Jack", REALTEK_HP_OUT); | |
2109 | if (err < 0) | |
2110 | return err; | |
2111 | err = realtek_add_jack(mixer, "Headset Mic Jack", | |
2112 | REALTEK_HP_OUT | REALTEK_MIC_FLAG); | |
2113 | if (err < 0) | |
2114 | return err; | |
2115 | return 0; | |
2116 | } | |
2117 | ||
964af639 TI |
2118 | static void dell_dock_init_vol(struct snd_usb_audio *chip, int ch, int id) |
2119 | { | |
2120 | u16 buf = 0; | |
2121 | ||
2122 | snd_usb_ctl_msg(chip->dev, usb_sndctrlpipe(chip->dev, 0), UAC_SET_CUR, | |
2123 | USB_RECIP_INTERFACE | USB_TYPE_CLASS | USB_DIR_OUT, | |
2e57a335 JS |
2124 | (UAC_FU_VOLUME << 8) | ch, |
2125 | snd_usb_ctrl_intf(chip) | (id << 8), | |
964af639 TI |
2126 | &buf, 2); |
2127 | } | |
2128 | ||
2129 | static int dell_dock_mixer_init(struct usb_mixer_interface *mixer) | |
2130 | { | |
2131 | /* fix to 0dB playback volumes */ | |
2132 | dell_dock_init_vol(mixer->chip, 1, 16); | |
2133 | dell_dock_init_vol(mixer->chip, 2, 16); | |
2134 | dell_dock_init_vol(mixer->chip, 1, 19); | |
2135 | dell_dock_init_vol(mixer->chip, 2, 19); | |
2136 | return 0; | |
2137 | } | |
2138 | ||
d39f1d68 JL |
2139 | /* RME Class Compliant device quirks */ |
2140 | ||
2141 | #define SND_RME_GET_STATUS1 23 | |
2142 | #define SND_RME_GET_CURRENT_FREQ 17 | |
2143 | #define SND_RME_CLK_SYSTEM_SHIFT 16 | |
2144 | #define SND_RME_CLK_SYSTEM_MASK 0x1f | |
2145 | #define SND_RME_CLK_AES_SHIFT 8 | |
2146 | #define SND_RME_CLK_SPDIF_SHIFT 12 | |
2147 | #define SND_RME_CLK_AES_SPDIF_MASK 0xf | |
2148 | #define SND_RME_CLK_SYNC_SHIFT 6 | |
2149 | #define SND_RME_CLK_SYNC_MASK 0x3 | |
2150 | #define SND_RME_CLK_FREQMUL_SHIFT 18 | |
2151 | #define SND_RME_CLK_FREQMUL_MASK 0x7 | |
2152 | #define SND_RME_CLK_SYSTEM(x) \ | |
2153 | ((x >> SND_RME_CLK_SYSTEM_SHIFT) & SND_RME_CLK_SYSTEM_MASK) | |
2154 | #define SND_RME_CLK_AES(x) \ | |
2155 | ((x >> SND_RME_CLK_AES_SHIFT) & SND_RME_CLK_AES_SPDIF_MASK) | |
2156 | #define SND_RME_CLK_SPDIF(x) \ | |
2157 | ((x >> SND_RME_CLK_SPDIF_SHIFT) & SND_RME_CLK_AES_SPDIF_MASK) | |
2158 | #define SND_RME_CLK_SYNC(x) \ | |
2159 | ((x >> SND_RME_CLK_SYNC_SHIFT) & SND_RME_CLK_SYNC_MASK) | |
2160 | #define SND_RME_CLK_FREQMUL(x) \ | |
2161 | ((x >> SND_RME_CLK_FREQMUL_SHIFT) & SND_RME_CLK_FREQMUL_MASK) | |
2162 | #define SND_RME_CLK_AES_LOCK 0x1 | |
2163 | #define SND_RME_CLK_AES_SYNC 0x4 | |
2164 | #define SND_RME_CLK_SPDIF_LOCK 0x2 | |
2165 | #define SND_RME_CLK_SPDIF_SYNC 0x8 | |
2166 | #define SND_RME_SPDIF_IF_SHIFT 4 | |
2167 | #define SND_RME_SPDIF_FORMAT_SHIFT 5 | |
2168 | #define SND_RME_BINARY_MASK 0x1 | |
2169 | #define SND_RME_SPDIF_IF(x) \ | |
2170 | ((x >> SND_RME_SPDIF_IF_SHIFT) & SND_RME_BINARY_MASK) | |
2171 | #define SND_RME_SPDIF_FORMAT(x) \ | |
2172 | ((x >> SND_RME_SPDIF_FORMAT_SHIFT) & SND_RME_BINARY_MASK) | |
2173 | ||
2174 | static const u32 snd_rme_rate_table[] = { | |
2175 | 32000, 44100, 48000, 50000, | |
2176 | 64000, 88200, 96000, 100000, | |
2177 | 128000, 176400, 192000, 200000, | |
2178 | 256000, 352800, 384000, 400000, | |
2179 | 512000, 705600, 768000, 800000 | |
2180 | }; | |
2181 | /* maximum number of items for AES and S/PDIF rates for above table */ | |
2182 | #define SND_RME_RATE_IDX_AES_SPDIF_NUM 12 | |
2183 | ||
2184 | enum snd_rme_domain { | |
2185 | SND_RME_DOMAIN_SYSTEM, | |
2186 | SND_RME_DOMAIN_AES, | |
2187 | SND_RME_DOMAIN_SPDIF | |
2188 | }; | |
2189 | ||
2190 | enum snd_rme_clock_status { | |
2191 | SND_RME_CLOCK_NOLOCK, | |
2192 | SND_RME_CLOCK_LOCK, | |
2193 | SND_RME_CLOCK_SYNC | |
2194 | }; | |
2195 | ||
2196 | static int snd_rme_read_value(struct snd_usb_audio *chip, | |
2197 | unsigned int item, | |
2198 | u32 *value) | |
2199 | { | |
2200 | struct usb_device *dev = chip->dev; | |
2201 | int err; | |
2202 | ||
2203 | err = snd_usb_ctl_msg(dev, usb_rcvctrlpipe(dev, 0), | |
2204 | item, | |
2205 | USB_DIR_IN | USB_TYPE_VENDOR | USB_RECIP_DEVICE, | |
2206 | 0, 0, | |
2207 | value, sizeof(*value)); | |
2208 | if (err < 0) | |
2209 | dev_err(&dev->dev, | |
2210 | "unable to issue vendor read request %d (ret = %d)", | |
2211 | item, err); | |
2212 | return err; | |
2213 | } | |
2214 | ||
2215 | static int snd_rme_get_status1(struct snd_kcontrol *kcontrol, | |
2216 | u32 *status1) | |
2217 | { | |
2218 | struct usb_mixer_elem_list *list = snd_kcontrol_chip(kcontrol); | |
2219 | struct snd_usb_audio *chip = list->mixer->chip; | |
2220 | int err; | |
2221 | ||
2222 | err = snd_usb_lock_shutdown(chip); | |
2223 | if (err < 0) | |
2224 | return err; | |
2225 | err = snd_rme_read_value(chip, SND_RME_GET_STATUS1, status1); | |
2226 | snd_usb_unlock_shutdown(chip); | |
2227 | return err; | |
2228 | } | |
2229 | ||
2230 | static int snd_rme_rate_get(struct snd_kcontrol *kcontrol, | |
2231 | struct snd_ctl_elem_value *ucontrol) | |
2232 | { | |
2233 | u32 status1; | |
2234 | u32 rate = 0; | |
2235 | int idx; | |
2236 | int err; | |
2237 | ||
2238 | err = snd_rme_get_status1(kcontrol, &status1); | |
2239 | if (err < 0) | |
2240 | return err; | |
2241 | switch (kcontrol->private_value) { | |
2242 | case SND_RME_DOMAIN_SYSTEM: | |
2243 | idx = SND_RME_CLK_SYSTEM(status1); | |
2244 | if (idx < ARRAY_SIZE(snd_rme_rate_table)) | |
2245 | rate = snd_rme_rate_table[idx]; | |
2246 | break; | |
2247 | case SND_RME_DOMAIN_AES: | |
2248 | idx = SND_RME_CLK_AES(status1); | |
2249 | if (idx < SND_RME_RATE_IDX_AES_SPDIF_NUM) | |
2250 | rate = snd_rme_rate_table[idx]; | |
2251 | break; | |
2252 | case SND_RME_DOMAIN_SPDIF: | |
2253 | idx = SND_RME_CLK_SPDIF(status1); | |
2254 | if (idx < SND_RME_RATE_IDX_AES_SPDIF_NUM) | |
2255 | rate = snd_rme_rate_table[idx]; | |
2256 | break; | |
2257 | default: | |
2258 | return -EINVAL; | |
2259 | } | |
2260 | ucontrol->value.integer.value[0] = rate; | |
2261 | return 0; | |
2262 | } | |
2263 | ||
2264 | static int snd_rme_sync_state_get(struct snd_kcontrol *kcontrol, | |
2265 | struct snd_ctl_elem_value *ucontrol) | |
2266 | { | |
2267 | u32 status1; | |
2268 | int idx = SND_RME_CLOCK_NOLOCK; | |
2269 | int err; | |
2270 | ||
2271 | err = snd_rme_get_status1(kcontrol, &status1); | |
2272 | if (err < 0) | |
2273 | return err; | |
2274 | switch (kcontrol->private_value) { | |
2275 | case SND_RME_DOMAIN_AES: /* AES */ | |
2276 | if (status1 & SND_RME_CLK_AES_SYNC) | |
2277 | idx = SND_RME_CLOCK_SYNC; | |
2278 | else if (status1 & SND_RME_CLK_AES_LOCK) | |
2279 | idx = SND_RME_CLOCK_LOCK; | |
2280 | break; | |
2281 | case SND_RME_DOMAIN_SPDIF: /* SPDIF */ | |
2282 | if (status1 & SND_RME_CLK_SPDIF_SYNC) | |
2283 | idx = SND_RME_CLOCK_SYNC; | |
2284 | else if (status1 & SND_RME_CLK_SPDIF_LOCK) | |
2285 | idx = SND_RME_CLOCK_LOCK; | |
2286 | break; | |
2287 | default: | |
2288 | return -EINVAL; | |
2289 | } | |
2290 | ucontrol->value.enumerated.item[0] = idx; | |
2291 | return 0; | |
2292 | } | |
2293 | ||
2294 | static int snd_rme_spdif_if_get(struct snd_kcontrol *kcontrol, | |
2295 | struct snd_ctl_elem_value *ucontrol) | |
2296 | { | |
2297 | u32 status1; | |
2298 | int err; | |
2299 | ||
2300 | err = snd_rme_get_status1(kcontrol, &status1); | |
2301 | if (err < 0) | |
2302 | return err; | |
2303 | ucontrol->value.enumerated.item[0] = SND_RME_SPDIF_IF(status1); | |
2304 | return 0; | |
2305 | } | |
2306 | ||
2307 | static int snd_rme_spdif_format_get(struct snd_kcontrol *kcontrol, | |
2308 | struct snd_ctl_elem_value *ucontrol) | |
2309 | { | |
2310 | u32 status1; | |
2311 | int err; | |
2312 | ||
2313 | err = snd_rme_get_status1(kcontrol, &status1); | |
2314 | if (err < 0) | |
2315 | return err; | |
2316 | ucontrol->value.enumerated.item[0] = SND_RME_SPDIF_FORMAT(status1); | |
2317 | return 0; | |
2318 | } | |
2319 | ||
2320 | static int snd_rme_sync_source_get(struct snd_kcontrol *kcontrol, | |
2321 | struct snd_ctl_elem_value *ucontrol) | |
2322 | { | |
2323 | u32 status1; | |
2324 | int err; | |
2325 | ||
2326 | err = snd_rme_get_status1(kcontrol, &status1); | |
2327 | if (err < 0) | |
2328 | return err; | |
2329 | ucontrol->value.enumerated.item[0] = SND_RME_CLK_SYNC(status1); | |
2330 | return 0; | |
2331 | } | |
2332 | ||
2333 | static int snd_rme_current_freq_get(struct snd_kcontrol *kcontrol, | |
2334 | struct snd_ctl_elem_value *ucontrol) | |
2335 | { | |
2336 | struct usb_mixer_elem_list *list = snd_kcontrol_chip(kcontrol); | |
2337 | struct snd_usb_audio *chip = list->mixer->chip; | |
2338 | u32 status1; | |
2339 | const u64 num = 104857600000000ULL; | |
2340 | u32 den; | |
2341 | unsigned int freq; | |
2342 | int err; | |
2343 | ||
2344 | err = snd_usb_lock_shutdown(chip); | |
2345 | if (err < 0) | |
2346 | return err; | |
2347 | err = snd_rme_read_value(chip, SND_RME_GET_STATUS1, &status1); | |
2348 | if (err < 0) | |
2349 | goto end; | |
2350 | err = snd_rme_read_value(chip, SND_RME_GET_CURRENT_FREQ, &den); | |
2351 | if (err < 0) | |
2352 | goto end; | |
2353 | freq = (den == 0) ? 0 : div64_u64(num, den); | |
2354 | freq <<= SND_RME_CLK_FREQMUL(status1); | |
2355 | ucontrol->value.integer.value[0] = freq; | |
2356 | ||
2357 | end: | |
2358 | snd_usb_unlock_shutdown(chip); | |
2359 | return err; | |
2360 | } | |
2361 | ||
2362 | static int snd_rme_rate_info(struct snd_kcontrol *kcontrol, | |
2363 | struct snd_ctl_elem_info *uinfo) | |
2364 | { | |
2365 | uinfo->type = SNDRV_CTL_ELEM_TYPE_INTEGER; | |
2366 | uinfo->count = 1; | |
2367 | switch (kcontrol->private_value) { | |
2368 | case SND_RME_DOMAIN_SYSTEM: | |
2369 | uinfo->value.integer.min = 32000; | |
2370 | uinfo->value.integer.max = 800000; | |
2371 | break; | |
2372 | case SND_RME_DOMAIN_AES: | |
2373 | case SND_RME_DOMAIN_SPDIF: | |
2374 | default: | |
2375 | uinfo->value.integer.min = 0; | |
2376 | uinfo->value.integer.max = 200000; | |
2377 | } | |
2378 | uinfo->value.integer.step = 0; | |
2379 | return 0; | |
2380 | } | |
2381 | ||
2382 | static int snd_rme_sync_state_info(struct snd_kcontrol *kcontrol, | |
2383 | struct snd_ctl_elem_info *uinfo) | |
2384 | { | |
2385 | static const char *const sync_states[] = { | |
2386 | "No Lock", "Lock", "Sync" | |
2387 | }; | |
2388 | ||
2389 | return snd_ctl_enum_info(uinfo, 1, | |
2390 | ARRAY_SIZE(sync_states), sync_states); | |
2391 | } | |
2392 | ||
2393 | static int snd_rme_spdif_if_info(struct snd_kcontrol *kcontrol, | |
2394 | struct snd_ctl_elem_info *uinfo) | |
2395 | { | |
2396 | static const char *const spdif_if[] = { | |
2397 | "Coaxial", "Optical" | |
2398 | }; | |
2399 | ||
2400 | return snd_ctl_enum_info(uinfo, 1, | |
2401 | ARRAY_SIZE(spdif_if), spdif_if); | |
2402 | } | |
2403 | ||
2404 | static int snd_rme_spdif_format_info(struct snd_kcontrol *kcontrol, | |
2405 | struct snd_ctl_elem_info *uinfo) | |
2406 | { | |
2407 | static const char *const optical_type[] = { | |
2408 | "Consumer", "Professional" | |
2409 | }; | |
2410 | ||
2411 | return snd_ctl_enum_info(uinfo, 1, | |
2412 | ARRAY_SIZE(optical_type), optical_type); | |
2413 | } | |
2414 | ||
2415 | static int snd_rme_sync_source_info(struct snd_kcontrol *kcontrol, | |
2416 | struct snd_ctl_elem_info *uinfo) | |
2417 | { | |
2418 | static const char *const sync_sources[] = { | |
2419 | "Internal", "AES", "SPDIF", "Internal" | |
2420 | }; | |
2421 | ||
2422 | return snd_ctl_enum_info(uinfo, 1, | |
2423 | ARRAY_SIZE(sync_sources), sync_sources); | |
2424 | } | |
2425 | ||
195727e8 | 2426 | static const struct snd_kcontrol_new snd_rme_controls[] = { |
d39f1d68 JL |
2427 | { |
2428 | .iface = SNDRV_CTL_ELEM_IFACE_MIXER, | |
2429 | .name = "AES Rate", | |
2430 | .access = SNDRV_CTL_ELEM_ACCESS_READ | SNDRV_CTL_ELEM_ACCESS_VOLATILE, | |
2431 | .info = snd_rme_rate_info, | |
2432 | .get = snd_rme_rate_get, | |
2433 | .private_value = SND_RME_DOMAIN_AES | |
2434 | }, | |
2435 | { | |
2436 | .iface = SNDRV_CTL_ELEM_IFACE_MIXER, | |
2437 | .name = "AES Sync", | |
2438 | .access = SNDRV_CTL_ELEM_ACCESS_READ | SNDRV_CTL_ELEM_ACCESS_VOLATILE, | |
2439 | .info = snd_rme_sync_state_info, | |
2440 | .get = snd_rme_sync_state_get, | |
2441 | .private_value = SND_RME_DOMAIN_AES | |
2442 | }, | |
2443 | { | |
2444 | .iface = SNDRV_CTL_ELEM_IFACE_MIXER, | |
2445 | .name = "SPDIF Rate", | |
2446 | .access = SNDRV_CTL_ELEM_ACCESS_READ | SNDRV_CTL_ELEM_ACCESS_VOLATILE, | |
2447 | .info = snd_rme_rate_info, | |
2448 | .get = snd_rme_rate_get, | |
2449 | .private_value = SND_RME_DOMAIN_SPDIF | |
2450 | }, | |
2451 | { | |
2452 | .iface = SNDRV_CTL_ELEM_IFACE_MIXER, | |
2453 | .name = "SPDIF Sync", | |
2454 | .access = SNDRV_CTL_ELEM_ACCESS_READ | SNDRV_CTL_ELEM_ACCESS_VOLATILE, | |
2455 | .info = snd_rme_sync_state_info, | |
2456 | .get = snd_rme_sync_state_get, | |
2457 | .private_value = SND_RME_DOMAIN_SPDIF | |
2458 | }, | |
2459 | { | |
2460 | .iface = SNDRV_CTL_ELEM_IFACE_MIXER, | |
2461 | .name = "SPDIF Interface", | |
2462 | .access = SNDRV_CTL_ELEM_ACCESS_READ | SNDRV_CTL_ELEM_ACCESS_VOLATILE, | |
2463 | .info = snd_rme_spdif_if_info, | |
2464 | .get = snd_rme_spdif_if_get, | |
2465 | }, | |
2466 | { | |
2467 | .iface = SNDRV_CTL_ELEM_IFACE_MIXER, | |
2468 | .name = "SPDIF Format", | |
2469 | .access = SNDRV_CTL_ELEM_ACCESS_READ | SNDRV_CTL_ELEM_ACCESS_VOLATILE, | |
2470 | .info = snd_rme_spdif_format_info, | |
2471 | .get = snd_rme_spdif_format_get, | |
2472 | }, | |
2473 | { | |
2474 | .iface = SNDRV_CTL_ELEM_IFACE_MIXER, | |
2475 | .name = "Sync Source", | |
2476 | .access = SNDRV_CTL_ELEM_ACCESS_READ | SNDRV_CTL_ELEM_ACCESS_VOLATILE, | |
2477 | .info = snd_rme_sync_source_info, | |
2478 | .get = snd_rme_sync_source_get | |
2479 | }, | |
2480 | { | |
2481 | .iface = SNDRV_CTL_ELEM_IFACE_MIXER, | |
2482 | .name = "System Rate", | |
2483 | .access = SNDRV_CTL_ELEM_ACCESS_READ | SNDRV_CTL_ELEM_ACCESS_VOLATILE, | |
2484 | .info = snd_rme_rate_info, | |
2485 | .get = snd_rme_rate_get, | |
2486 | .private_value = SND_RME_DOMAIN_SYSTEM | |
2487 | }, | |
2488 | { | |
2489 | .iface = SNDRV_CTL_ELEM_IFACE_MIXER, | |
2490 | .name = "Current Frequency", | |
2491 | .access = SNDRV_CTL_ELEM_ACCESS_READ | SNDRV_CTL_ELEM_ACCESS_VOLATILE, | |
2492 | .info = snd_rme_rate_info, | |
2493 | .get = snd_rme_current_freq_get | |
2494 | } | |
2495 | }; | |
2496 | ||
2497 | static int snd_rme_controls_create(struct usb_mixer_interface *mixer) | |
2498 | { | |
2499 | int err, i; | |
2500 | ||
2501 | for (i = 0; i < ARRAY_SIZE(snd_rme_controls); ++i) { | |
2502 | err = add_single_ctl_with_resume(mixer, 0, | |
2503 | NULL, | |
2504 | &snd_rme_controls[i], | |
2505 | NULL); | |
2506 | if (err < 0) | |
2507 | return err; | |
2508 | } | |
2509 | ||
2510 | return 0; | |
2511 | } | |
2512 | ||
3e8f3bd0 TE |
2513 | /* |
2514 | * RME Babyface Pro (FS) | |
2515 | * | |
2516 | * These devices exposes a couple of DSP functions via request to EP0. | |
2517 | * Switches are available via control registers, while routing is controlled | |
2518 | * by controlling the volume on each possible crossing point. | |
47b4f5f5 | 2519 | * Volume control is linear, from -inf (dec. 0) to +6dB (dec. 65536) with |
3e8f3bd0 TE |
2520 | * 0dB being at dec. 32768. |
2521 | */ | |
2522 | enum { | |
2523 | SND_BBFPRO_CTL_REG1 = 0, | |
2524 | SND_BBFPRO_CTL_REG2 | |
2525 | }; | |
2526 | ||
2527 | #define SND_BBFPRO_CTL_REG_MASK 1 | |
2528 | #define SND_BBFPRO_CTL_IDX_MASK 0xff | |
2529 | #define SND_BBFPRO_CTL_IDX_SHIFT 1 | |
2530 | #define SND_BBFPRO_CTL_VAL_MASK 1 | |
2531 | #define SND_BBFPRO_CTL_VAL_SHIFT 9 | |
2532 | #define SND_BBFPRO_CTL_REG1_CLK_MASTER 0 | |
2533 | #define SND_BBFPRO_CTL_REG1_CLK_OPTICAL 1 | |
2534 | #define SND_BBFPRO_CTL_REG1_SPDIF_PRO 7 | |
2535 | #define SND_BBFPRO_CTL_REG1_SPDIF_EMPH 8 | |
2536 | #define SND_BBFPRO_CTL_REG1_SPDIF_OPTICAL 10 | |
2537 | #define SND_BBFPRO_CTL_REG2_48V_AN1 0 | |
2538 | #define SND_BBFPRO_CTL_REG2_48V_AN2 1 | |
2539 | #define SND_BBFPRO_CTL_REG2_SENS_IN3 2 | |
2540 | #define SND_BBFPRO_CTL_REG2_SENS_IN4 3 | |
2541 | #define SND_BBFPRO_CTL_REG2_PAD_AN1 4 | |
2542 | #define SND_BBFPRO_CTL_REG2_PAD_AN2 5 | |
2543 | ||
2544 | #define SND_BBFPRO_MIXER_IDX_MASK 0x1ff | |
2545 | #define SND_BBFPRO_MIXER_VAL_MASK 0x3ffff | |
2546 | #define SND_BBFPRO_MIXER_VAL_SHIFT 9 | |
2547 | #define SND_BBFPRO_MIXER_VAL_MIN 0 // -inf | |
47b4f5f5 | 2548 | #define SND_BBFPRO_MIXER_VAL_MAX 65536 // +6dB |
3e8f3bd0 TE |
2549 | |
2550 | #define SND_BBFPRO_USBREQ_CTL_REG1 0x10 | |
2551 | #define SND_BBFPRO_USBREQ_CTL_REG2 0x17 | |
2552 | #define SND_BBFPRO_USBREQ_MIXER 0x12 | |
2553 | ||
2554 | static int snd_bbfpro_ctl_update(struct usb_mixer_interface *mixer, u8 reg, | |
2555 | u8 index, u8 value) | |
2556 | { | |
2557 | int err; | |
2558 | u16 usb_req, usb_idx, usb_val; | |
2559 | struct snd_usb_audio *chip = mixer->chip; | |
2560 | ||
2561 | err = snd_usb_lock_shutdown(chip); | |
2562 | if (err < 0) | |
2563 | return err; | |
2564 | ||
2565 | if (reg == SND_BBFPRO_CTL_REG1) { | |
2566 | usb_req = SND_BBFPRO_USBREQ_CTL_REG1; | |
2567 | if (index == SND_BBFPRO_CTL_REG1_CLK_OPTICAL) { | |
2568 | usb_idx = 3; | |
2569 | usb_val = value ? 3 : 0; | |
2570 | } else { | |
2571 | usb_idx = 1 << index; | |
2572 | usb_val = value ? usb_idx : 0; | |
2573 | } | |
2574 | } else { | |
2575 | usb_req = SND_BBFPRO_USBREQ_CTL_REG2; | |
2576 | usb_idx = 1 << index; | |
2577 | usb_val = value ? usb_idx : 0; | |
2578 | } | |
2579 | ||
2580 | err = snd_usb_ctl_msg(chip->dev, | |
2581 | usb_sndctrlpipe(chip->dev, 0), usb_req, | |
2582 | USB_DIR_OUT | USB_TYPE_VENDOR | USB_RECIP_DEVICE, | |
f99e24a6 | 2583 | usb_val, usb_idx, NULL, 0); |
3e8f3bd0 TE |
2584 | |
2585 | snd_usb_unlock_shutdown(chip); | |
2586 | return err; | |
2587 | } | |
2588 | ||
2589 | static int snd_bbfpro_ctl_get(struct snd_kcontrol *kcontrol, | |
2590 | struct snd_ctl_elem_value *ucontrol) | |
2591 | { | |
2592 | u8 reg, idx, val; | |
2593 | int pv; | |
2594 | ||
2595 | pv = kcontrol->private_value; | |
2596 | reg = pv & SND_BBFPRO_CTL_REG_MASK; | |
2597 | idx = (pv >> SND_BBFPRO_CTL_IDX_SHIFT) & SND_BBFPRO_CTL_IDX_MASK; | |
2598 | val = kcontrol->private_value >> SND_BBFPRO_CTL_VAL_SHIFT; | |
2599 | ||
2600 | if ((reg == SND_BBFPRO_CTL_REG1 && | |
2601 | idx == SND_BBFPRO_CTL_REG1_CLK_OPTICAL) || | |
2602 | (reg == SND_BBFPRO_CTL_REG2 && | |
2603 | (idx == SND_BBFPRO_CTL_REG2_SENS_IN3 || | |
2604 | idx == SND_BBFPRO_CTL_REG2_SENS_IN4))) { | |
2605 | ucontrol->value.enumerated.item[0] = val; | |
2606 | } else { | |
2607 | ucontrol->value.integer.value[0] = val; | |
2608 | } | |
2609 | return 0; | |
2610 | } | |
2611 | ||
2612 | static int snd_bbfpro_ctl_info(struct snd_kcontrol *kcontrol, | |
2613 | struct snd_ctl_elem_info *uinfo) | |
2614 | { | |
2615 | u8 reg, idx; | |
2616 | int pv; | |
2617 | ||
2618 | pv = kcontrol->private_value; | |
2619 | reg = pv & SND_BBFPRO_CTL_REG_MASK; | |
2620 | idx = (pv >> SND_BBFPRO_CTL_IDX_SHIFT) & SND_BBFPRO_CTL_IDX_MASK; | |
2621 | ||
2622 | if (reg == SND_BBFPRO_CTL_REG1 && | |
2623 | idx == SND_BBFPRO_CTL_REG1_CLK_OPTICAL) { | |
2624 | static const char * const texts[2] = { | |
2625 | "AutoSync", | |
2626 | "Internal" | |
2627 | }; | |
2628 | return snd_ctl_enum_info(uinfo, 1, 2, texts); | |
2629 | } else if (reg == SND_BBFPRO_CTL_REG2 && | |
2630 | (idx == SND_BBFPRO_CTL_REG2_SENS_IN3 || | |
2631 | idx == SND_BBFPRO_CTL_REG2_SENS_IN4)) { | |
2632 | static const char * const texts[2] = { | |
2633 | "-10dBV", | |
2634 | "+4dBu" | |
2635 | }; | |
2636 | return snd_ctl_enum_info(uinfo, 1, 2, texts); | |
2637 | } | |
2638 | ||
2639 | uinfo->count = 1; | |
2640 | uinfo->value.integer.min = 0; | |
2641 | uinfo->value.integer.max = 1; | |
2642 | uinfo->type = SNDRV_CTL_ELEM_TYPE_BOOLEAN; | |
2643 | return 0; | |
2644 | } | |
2645 | ||
2646 | static int snd_bbfpro_ctl_put(struct snd_kcontrol *kcontrol, | |
2647 | struct snd_ctl_elem_value *ucontrol) | |
2648 | { | |
2649 | int err; | |
2650 | u8 reg, idx; | |
2651 | int old_value, pv, val; | |
2652 | ||
2653 | struct usb_mixer_elem_list *list = snd_kcontrol_chip(kcontrol); | |
2654 | struct usb_mixer_interface *mixer = list->mixer; | |
2655 | ||
2656 | pv = kcontrol->private_value; | |
2657 | reg = pv & SND_BBFPRO_CTL_REG_MASK; | |
2658 | idx = (pv >> SND_BBFPRO_CTL_IDX_SHIFT) & SND_BBFPRO_CTL_IDX_MASK; | |
2659 | old_value = (pv >> SND_BBFPRO_CTL_VAL_SHIFT) & SND_BBFPRO_CTL_VAL_MASK; | |
2660 | ||
2661 | if ((reg == SND_BBFPRO_CTL_REG1 && | |
2662 | idx == SND_BBFPRO_CTL_REG1_CLK_OPTICAL) || | |
2663 | (reg == SND_BBFPRO_CTL_REG2 && | |
2664 | (idx == SND_BBFPRO_CTL_REG2_SENS_IN3 || | |
2665 | idx == SND_BBFPRO_CTL_REG2_SENS_IN4))) { | |
2666 | val = ucontrol->value.enumerated.item[0]; | |
2667 | } else { | |
2668 | val = ucontrol->value.integer.value[0]; | |
2669 | } | |
2670 | ||
2671 | if (val > 1) | |
2672 | return -EINVAL; | |
2673 | ||
2674 | if (val == old_value) | |
2675 | return 0; | |
2676 | ||
2677 | kcontrol->private_value = reg | |
2678 | | ((idx & SND_BBFPRO_CTL_IDX_MASK) << SND_BBFPRO_CTL_IDX_SHIFT) | |
2679 | | ((val & SND_BBFPRO_CTL_VAL_MASK) << SND_BBFPRO_CTL_VAL_SHIFT); | |
2680 | ||
2681 | err = snd_bbfpro_ctl_update(mixer, reg, idx, val); | |
2682 | return err < 0 ? err : 1; | |
2683 | } | |
2684 | ||
2685 | static int snd_bbfpro_ctl_resume(struct usb_mixer_elem_list *list) | |
2686 | { | |
2687 | u8 reg, idx; | |
2688 | int value, pv; | |
2689 | ||
2690 | pv = list->kctl->private_value; | |
2691 | reg = pv & SND_BBFPRO_CTL_REG_MASK; | |
2692 | idx = (pv >> SND_BBFPRO_CTL_IDX_SHIFT) & SND_BBFPRO_CTL_IDX_MASK; | |
2693 | value = (pv >> SND_BBFPRO_CTL_VAL_SHIFT) & SND_BBFPRO_CTL_VAL_MASK; | |
2694 | ||
2695 | return snd_bbfpro_ctl_update(list->mixer, reg, idx, value); | |
2696 | } | |
2697 | ||
2698 | static int snd_bbfpro_vol_update(struct usb_mixer_interface *mixer, u16 index, | |
2699 | u32 value) | |
2700 | { | |
2701 | struct snd_usb_audio *chip = mixer->chip; | |
2702 | int err; | |
2703 | u16 idx; | |
2704 | u16 usb_idx, usb_val; | |
2705 | u32 v; | |
2706 | ||
2707 | err = snd_usb_lock_shutdown(chip); | |
2708 | if (err < 0) | |
2709 | return err; | |
2710 | ||
2711 | idx = index & SND_BBFPRO_MIXER_IDX_MASK; | |
2712 | // 18 bit linear volume, split so 2 bits end up in index. | |
2713 | v = value & SND_BBFPRO_MIXER_VAL_MASK; | |
2714 | usb_idx = idx | (v & 0x3) << 14; | |
2715 | usb_val = (v >> 2) & 0xffff; | |
2716 | ||
2717 | err = snd_usb_ctl_msg(chip->dev, | |
2718 | usb_sndctrlpipe(chip->dev, 0), | |
2719 | SND_BBFPRO_USBREQ_MIXER, | |
2720 | USB_DIR_OUT | USB_TYPE_VENDOR | | |
2721 | USB_RECIP_DEVICE, | |
f99e24a6 | 2722 | usb_val, usb_idx, NULL, 0); |
3e8f3bd0 TE |
2723 | |
2724 | snd_usb_unlock_shutdown(chip); | |
2725 | return err; | |
2726 | } | |
2727 | ||
2728 | static int snd_bbfpro_vol_get(struct snd_kcontrol *kcontrol, | |
2729 | struct snd_ctl_elem_value *ucontrol) | |
2730 | { | |
2731 | ucontrol->value.integer.value[0] = | |
2732 | kcontrol->private_value >> SND_BBFPRO_MIXER_VAL_SHIFT; | |
2733 | return 0; | |
2734 | } | |
2735 | ||
2736 | static int snd_bbfpro_vol_info(struct snd_kcontrol *kcontrol, | |
2737 | struct snd_ctl_elem_info *uinfo) | |
2738 | { | |
2739 | uinfo->type = SNDRV_CTL_ELEM_TYPE_INTEGER; | |
2740 | uinfo->count = 1; | |
2741 | uinfo->value.integer.min = SND_BBFPRO_MIXER_VAL_MIN; | |
2742 | uinfo->value.integer.max = SND_BBFPRO_MIXER_VAL_MAX; | |
2743 | return 0; | |
2744 | } | |
2745 | ||
2746 | static int snd_bbfpro_vol_put(struct snd_kcontrol *kcontrol, | |
2747 | struct snd_ctl_elem_value *ucontrol) | |
2748 | { | |
2749 | int err; | |
2750 | u16 idx; | |
2751 | u32 new_val, old_value, uvalue; | |
2752 | struct usb_mixer_elem_list *list = snd_kcontrol_chip(kcontrol); | |
2753 | struct usb_mixer_interface *mixer = list->mixer; | |
2754 | ||
2755 | uvalue = ucontrol->value.integer.value[0]; | |
2756 | idx = kcontrol->private_value & SND_BBFPRO_MIXER_IDX_MASK; | |
2757 | old_value = kcontrol->private_value >> SND_BBFPRO_MIXER_VAL_SHIFT; | |
2758 | ||
2759 | if (uvalue > SND_BBFPRO_MIXER_VAL_MAX) | |
2760 | return -EINVAL; | |
2761 | ||
2762 | if (uvalue == old_value) | |
2763 | return 0; | |
2764 | ||
2765 | new_val = uvalue & SND_BBFPRO_MIXER_VAL_MASK; | |
2766 | ||
2767 | kcontrol->private_value = idx | |
2768 | | (new_val << SND_BBFPRO_MIXER_VAL_SHIFT); | |
2769 | ||
2770 | err = snd_bbfpro_vol_update(mixer, idx, new_val); | |
2771 | return err < 0 ? err : 1; | |
2772 | } | |
2773 | ||
2774 | static int snd_bbfpro_vol_resume(struct usb_mixer_elem_list *list) | |
2775 | { | |
2776 | int pv = list->kctl->private_value; | |
2777 | u16 idx = pv & SND_BBFPRO_MIXER_IDX_MASK; | |
2778 | u32 val = (pv >> SND_BBFPRO_MIXER_VAL_SHIFT) | |
2779 | & SND_BBFPRO_MIXER_VAL_MASK; | |
2780 | return snd_bbfpro_vol_update(list->mixer, idx, val); | |
2781 | } | |
2782 | ||
2783 | // Predfine elements | |
2784 | static const struct snd_kcontrol_new snd_bbfpro_ctl_control = { | |
2785 | .iface = SNDRV_CTL_ELEM_IFACE_MIXER, | |
2786 | .access = SNDRV_CTL_ELEM_ACCESS_READWRITE, | |
2787 | .index = 0, | |
2788 | .info = snd_bbfpro_ctl_info, | |
2789 | .get = snd_bbfpro_ctl_get, | |
2790 | .put = snd_bbfpro_ctl_put | |
2791 | }; | |
2792 | ||
2793 | static const struct snd_kcontrol_new snd_bbfpro_vol_control = { | |
2794 | .iface = SNDRV_CTL_ELEM_IFACE_MIXER, | |
2795 | .access = SNDRV_CTL_ELEM_ACCESS_READWRITE, | |
2796 | .index = 0, | |
2797 | .info = snd_bbfpro_vol_info, | |
2798 | .get = snd_bbfpro_vol_get, | |
2799 | .put = snd_bbfpro_vol_put | |
2800 | }; | |
2801 | ||
2802 | static int snd_bbfpro_ctl_add(struct usb_mixer_interface *mixer, u8 reg, | |
2803 | u8 index, char *name) | |
2804 | { | |
2805 | struct snd_kcontrol_new knew = snd_bbfpro_ctl_control; | |
2806 | ||
2807 | knew.name = name; | |
2808 | knew.private_value = (reg & SND_BBFPRO_CTL_REG_MASK) | |
2809 | | ((index & SND_BBFPRO_CTL_IDX_MASK) | |
2810 | << SND_BBFPRO_CTL_IDX_SHIFT); | |
2811 | ||
2812 | return add_single_ctl_with_resume(mixer, 0, snd_bbfpro_ctl_resume, | |
2813 | &knew, NULL); | |
2814 | } | |
2815 | ||
2816 | static int snd_bbfpro_vol_add(struct usb_mixer_interface *mixer, u16 index, | |
2817 | char *name) | |
2818 | { | |
2819 | struct snd_kcontrol_new knew = snd_bbfpro_vol_control; | |
2820 | ||
2821 | knew.name = name; | |
2822 | knew.private_value = index & SND_BBFPRO_MIXER_IDX_MASK; | |
2823 | ||
2824 | return add_single_ctl_with_resume(mixer, 0, snd_bbfpro_vol_resume, | |
2825 | &knew, NULL); | |
2826 | } | |
2827 | ||
2828 | static int snd_bbfpro_controls_create(struct usb_mixer_interface *mixer) | |
2829 | { | |
2830 | int err, i, o; | |
2831 | char name[48]; | |
2832 | ||
2833 | static const char * const input[] = { | |
2834 | "AN1", "AN2", "IN3", "IN4", "AS1", "AS2", "ADAT3", | |
2835 | "ADAT4", "ADAT5", "ADAT6", "ADAT7", "ADAT8"}; | |
2836 | ||
2837 | static const char * const output[] = { | |
2838 | "AN1", "AN2", "PH3", "PH4", "AS1", "AS2", "ADAT3", "ADAT4", | |
2839 | "ADAT5", "ADAT6", "ADAT7", "ADAT8"}; | |
2840 | ||
2841 | for (o = 0 ; o < 12 ; ++o) { | |
2842 | for (i = 0 ; i < 12 ; ++i) { | |
2843 | // Line routing | |
2844 | snprintf(name, sizeof(name), | |
2845 | "%s-%s-%s Playback Volume", | |
2846 | (i < 2 ? "Mic" : "Line"), | |
2847 | input[i], output[o]); | |
2848 | err = snd_bbfpro_vol_add(mixer, (26 * o + i), name); | |
2849 | if (err < 0) | |
2850 | return err; | |
2851 | ||
2852 | // PCM routing... yes, it is output remapping | |
2853 | snprintf(name, sizeof(name), | |
2854 | "PCM-%s-%s Playback Volume", | |
2855 | output[i], output[o]); | |
2856 | err = snd_bbfpro_vol_add(mixer, (26 * o + 12 + i), | |
2857 | name); | |
2858 | if (err < 0) | |
2859 | return err; | |
2860 | } | |
2861 | } | |
2862 | ||
2863 | // Control Reg 1 | |
2864 | err = snd_bbfpro_ctl_add(mixer, SND_BBFPRO_CTL_REG1, | |
2865 | SND_BBFPRO_CTL_REG1_CLK_OPTICAL, | |
2866 | "Sample Clock Source"); | |
2867 | if (err < 0) | |
2868 | return err; | |
2869 | ||
2870 | err = snd_bbfpro_ctl_add(mixer, SND_BBFPRO_CTL_REG1, | |
2871 | SND_BBFPRO_CTL_REG1_SPDIF_PRO, | |
2872 | "IEC958 Pro Mask"); | |
2873 | if (err < 0) | |
2874 | return err; | |
2875 | ||
2876 | err = snd_bbfpro_ctl_add(mixer, SND_BBFPRO_CTL_REG1, | |
2877 | SND_BBFPRO_CTL_REG1_SPDIF_EMPH, | |
2878 | "IEC958 Emphasis"); | |
2879 | if (err < 0) | |
2880 | return err; | |
2881 | ||
2882 | err = snd_bbfpro_ctl_add(mixer, SND_BBFPRO_CTL_REG1, | |
2883 | SND_BBFPRO_CTL_REG1_SPDIF_OPTICAL, | |
2884 | "IEC958 Switch"); | |
2885 | if (err < 0) | |
2886 | return err; | |
2887 | ||
2888 | // Control Reg 2 | |
2889 | err = snd_bbfpro_ctl_add(mixer, SND_BBFPRO_CTL_REG2, | |
2890 | SND_BBFPRO_CTL_REG2_48V_AN1, | |
2891 | "Mic-AN1 48V"); | |
2892 | if (err < 0) | |
2893 | return err; | |
2894 | ||
2895 | err = snd_bbfpro_ctl_add(mixer, SND_BBFPRO_CTL_REG2, | |
2896 | SND_BBFPRO_CTL_REG2_48V_AN2, | |
2897 | "Mic-AN2 48V"); | |
2898 | if (err < 0) | |
2899 | return err; | |
2900 | ||
2901 | err = snd_bbfpro_ctl_add(mixer, SND_BBFPRO_CTL_REG2, | |
2902 | SND_BBFPRO_CTL_REG2_SENS_IN3, | |
2903 | "Line-IN3 Sens."); | |
2904 | if (err < 0) | |
2905 | return err; | |
2906 | ||
2907 | err = snd_bbfpro_ctl_add(mixer, SND_BBFPRO_CTL_REG2, | |
2908 | SND_BBFPRO_CTL_REG2_SENS_IN4, | |
2909 | "Line-IN4 Sens."); | |
2910 | if (err < 0) | |
2911 | return err; | |
2912 | ||
2913 | err = snd_bbfpro_ctl_add(mixer, SND_BBFPRO_CTL_REG2, | |
2914 | SND_BBFPRO_CTL_REG2_PAD_AN1, | |
2915 | "Mic-AN1 PAD"); | |
2916 | if (err < 0) | |
2917 | return err; | |
2918 | ||
2919 | err = snd_bbfpro_ctl_add(mixer, SND_BBFPRO_CTL_REG2, | |
2920 | SND_BBFPRO_CTL_REG2_PAD_AN2, | |
2921 | "Mic-AN2 PAD"); | |
2922 | if (err < 0) | |
2923 | return err; | |
2924 | ||
2925 | return 0; | |
2926 | } | |
2927 | ||
cdc01a15 | 2928 | /* |
a07df82c | 2929 | * Pioneer DJ DJM Mixers |
cdc01a15 | 2930 | * |
a07df82c OM |
2931 | * These devices generally have options for soft-switching the playback and |
2932 | * capture sources in addition to the recording level. Although different | |
2933 | * devices have different configurations, there seems to be canonical values | |
2934 | * for specific capture/playback types: See the definitions of these below. | |
cdc01a15 | 2935 | * |
a07df82c OM |
2936 | * The wValue is masked with the stereo channel number. e.g. Setting Ch2 to |
2937 | * capture phono would be 0x0203. Capture, playback and capture level have | |
2938 | * different wIndexes. | |
cdc01a15 FK |
2939 | */ |
2940 | ||
a07df82c OM |
2941 | // Capture types |
2942 | #define SND_DJM_CAP_LINE 0x00 | |
2943 | #define SND_DJM_CAP_CDLINE 0x01 | |
fee03efc | 2944 | #define SND_DJM_CAP_DIGITAL 0x02 |
a07df82c OM |
2945 | #define SND_DJM_CAP_PHONO 0x03 |
2946 | #define SND_DJM_CAP_PFADER 0x06 | |
2947 | #define SND_DJM_CAP_XFADERA 0x07 | |
2948 | #define SND_DJM_CAP_XFADERB 0x08 | |
2949 | #define SND_DJM_CAP_MIC 0x09 | |
2950 | #define SND_DJM_CAP_AUX 0x0d | |
2951 | #define SND_DJM_CAP_RECOUT 0x0a | |
2952 | #define SND_DJM_CAP_NONE 0x0f | |
2953 | #define SND_DJM_CAP_CH1PFADER 0x11 | |
2954 | #define SND_DJM_CAP_CH2PFADER 0x12 | |
fee03efc FL |
2955 | #define SND_DJM_CAP_CH3PFADER 0x13 |
2956 | #define SND_DJM_CAP_CH4PFADER 0x14 | |
a07df82c OM |
2957 | |
2958 | // Playback types | |
2959 | #define SND_DJM_PB_CH1 0x00 | |
2960 | #define SND_DJM_PB_CH2 0x01 | |
2961 | #define SND_DJM_PB_AUX 0x04 | |
2962 | ||
2963 | #define SND_DJM_WINDEX_CAP 0x8002 | |
2964 | #define SND_DJM_WINDEX_CAPLVL 0x8003 | |
2965 | #define SND_DJM_WINDEX_PB 0x8016 | |
2966 | ||
2967 | // kcontrol->private_value layout | |
2968 | #define SND_DJM_VALUE_MASK 0x0000ffff | |
2969 | #define SND_DJM_GROUP_MASK 0x00ff0000 | |
2970 | #define SND_DJM_DEVICE_MASK 0xff000000 | |
2971 | #define SND_DJM_GROUP_SHIFT 16 | |
2972 | #define SND_DJM_DEVICE_SHIFT 24 | |
2973 | ||
2974 | // device table index | |
7687850b | 2975 | // used for the snd_djm_devices table, so please update accordingly |
a07df82c OM |
2976 | #define SND_DJM_250MK2_IDX 0x0 |
2977 | #define SND_DJM_750_IDX 0x1 | |
7687850b NM |
2978 | #define SND_DJM_850_IDX 0x2 |
2979 | #define SND_DJM_900NXS2_IDX 0x3 | |
6d277881 | 2980 | #define SND_DJM_750MK2_IDX 0x4 |
a07df82c OM |
2981 | |
2982 | ||
2983 | #define SND_DJM_CTL(_name, suffix, _default_value, _windex) { \ | |
2984 | .name = _name, \ | |
2985 | .options = snd_djm_opts_##suffix, \ | |
2986 | .noptions = ARRAY_SIZE(snd_djm_opts_##suffix), \ | |
2987 | .default_value = _default_value, \ | |
2988 | .wIndex = _windex } | |
2989 | ||
2990 | #define SND_DJM_DEVICE(suffix) { \ | |
2991 | .controls = snd_djm_ctls_##suffix, \ | |
2992 | .ncontrols = ARRAY_SIZE(snd_djm_ctls_##suffix) } | |
2993 | ||
2994 | ||
2995 | struct snd_djm_device { | |
cdc01a15 | 2996 | const char *name; |
a07df82c OM |
2997 | const struct snd_djm_ctl *controls; |
2998 | size_t ncontrols; | |
cdc01a15 FK |
2999 | }; |
3000 | ||
a07df82c OM |
3001 | struct snd_djm_ctl { |
3002 | const char *name; | |
3003 | const u16 *options; | |
3004 | size_t noptions; | |
3005 | u16 default_value; | |
3006 | u16 wIndex; | |
cdc01a15 FK |
3007 | }; |
3008 | ||
a07df82c OM |
3009 | static const char *snd_djm_get_label_caplevel(u16 wvalue) |
3010 | { | |
3011 | switch (wvalue) { | |
3012 | case 0x0000: return "-19dB"; | |
3013 | case 0x0100: return "-15dB"; | |
3014 | case 0x0200: return "-10dB"; | |
3015 | case 0x0300: return "-5dB"; | |
3016 | default: return NULL; | |
3017 | } | |
cdc01a15 FK |
3018 | }; |
3019 | ||
b8db8be8 | 3020 | static const char *snd_djm_get_label_cap_common(u16 wvalue) |
a07df82c OM |
3021 | { |
3022 | switch (wvalue & 0x00ff) { | |
3023 | case SND_DJM_CAP_LINE: return "Control Tone LINE"; | |
3024 | case SND_DJM_CAP_CDLINE: return "Control Tone CD/LINE"; | |
fee03efc | 3025 | case SND_DJM_CAP_DIGITAL: return "Control Tone DIGITAL"; |
a07df82c OM |
3026 | case SND_DJM_CAP_PHONO: return "Control Tone PHONO"; |
3027 | case SND_DJM_CAP_PFADER: return "Post Fader"; | |
3028 | case SND_DJM_CAP_XFADERA: return "Cross Fader A"; | |
3029 | case SND_DJM_CAP_XFADERB: return "Cross Fader B"; | |
3030 | case SND_DJM_CAP_MIC: return "Mic"; | |
3031 | case SND_DJM_CAP_RECOUT: return "Rec Out"; | |
3032 | case SND_DJM_CAP_AUX: return "Aux"; | |
3033 | case SND_DJM_CAP_NONE: return "None"; | |
3034 | case SND_DJM_CAP_CH1PFADER: return "Post Fader Ch1"; | |
3035 | case SND_DJM_CAP_CH2PFADER: return "Post Fader Ch2"; | |
fee03efc FL |
3036 | case SND_DJM_CAP_CH3PFADER: return "Post Fader Ch3"; |
3037 | case SND_DJM_CAP_CH4PFADER: return "Post Fader Ch4"; | |
a07df82c OM |
3038 | default: return NULL; |
3039 | } | |
cdc01a15 FK |
3040 | }; |
3041 | ||
b8db8be8 NM |
3042 | // The DJM-850 has different values for CD/LINE and LINE capture |
3043 | // control options than the other DJM declared in this file. | |
3044 | static const char *snd_djm_get_label_cap_850(u16 wvalue) | |
3045 | { | |
3046 | switch (wvalue & 0x00ff) { | |
3047 | case 0x00: return "Control Tone CD/LINE"; | |
3048 | case 0x01: return "Control Tone LINE"; | |
3049 | default: return snd_djm_get_label_cap_common(wvalue); | |
3050 | } | |
3051 | }; | |
3052 | ||
3053 | static const char *snd_djm_get_label_cap(u8 device_idx, u16 wvalue) | |
3054 | { | |
3055 | switch (device_idx) { | |
3056 | case SND_DJM_850_IDX: return snd_djm_get_label_cap_850(wvalue); | |
3057 | default: return snd_djm_get_label_cap_common(wvalue); | |
3058 | } | |
3059 | }; | |
3060 | ||
a07df82c OM |
3061 | static const char *snd_djm_get_label_pb(u16 wvalue) |
3062 | { | |
3063 | switch (wvalue & 0x00ff) { | |
3064 | case SND_DJM_PB_CH1: return "Ch1"; | |
3065 | case SND_DJM_PB_CH2: return "Ch2"; | |
3066 | case SND_DJM_PB_AUX: return "Aux"; | |
3067 | default: return NULL; | |
3068 | } | |
cdc01a15 FK |
3069 | }; |
3070 | ||
b8db8be8 | 3071 | static const char *snd_djm_get_label(u8 device_idx, u16 wvalue, u16 windex) |
a07df82c OM |
3072 | { |
3073 | switch (windex) { | |
3074 | case SND_DJM_WINDEX_CAPLVL: return snd_djm_get_label_caplevel(wvalue); | |
b8db8be8 | 3075 | case SND_DJM_WINDEX_CAP: return snd_djm_get_label_cap(device_idx, wvalue); |
a07df82c OM |
3076 | case SND_DJM_WINDEX_PB: return snd_djm_get_label_pb(wvalue); |
3077 | default: return NULL; | |
3078 | } | |
cdc01a15 FK |
3079 | }; |
3080 | ||
7687850b | 3081 | // common DJM capture level option values |
a07df82c OM |
3082 | static const u16 snd_djm_opts_cap_level[] = { |
3083 | 0x0000, 0x0100, 0x0200, 0x0300 }; | |
3084 | ||
7687850b NM |
3085 | |
3086 | // DJM-250MK2 | |
a07df82c OM |
3087 | static const u16 snd_djm_opts_250mk2_cap1[] = { |
3088 | 0x0103, 0x0100, 0x0106, 0x0107, 0x0108, 0x0109, 0x010d, 0x010a }; | |
3089 | ||
3090 | static const u16 snd_djm_opts_250mk2_cap2[] = { | |
3091 | 0x0203, 0x0200, 0x0206, 0x0207, 0x0208, 0x0209, 0x020d, 0x020a }; | |
3092 | ||
3093 | static const u16 snd_djm_opts_250mk2_cap3[] = { | |
3094 | 0x030a, 0x0311, 0x0312, 0x0307, 0x0308, 0x0309, 0x030d }; | |
3095 | ||
3096 | static const u16 snd_djm_opts_250mk2_pb1[] = { 0x0100, 0x0101, 0x0104 }; | |
3097 | static const u16 snd_djm_opts_250mk2_pb2[] = { 0x0200, 0x0201, 0x0204 }; | |
3098 | static const u16 snd_djm_opts_250mk2_pb3[] = { 0x0300, 0x0301, 0x0304 }; | |
3099 | ||
3100 | static const struct snd_djm_ctl snd_djm_ctls_250mk2[] = { | |
3101 | SND_DJM_CTL("Capture Level", cap_level, 0, SND_DJM_WINDEX_CAPLVL), | |
3102 | SND_DJM_CTL("Ch1 Input", 250mk2_cap1, 2, SND_DJM_WINDEX_CAP), | |
3103 | SND_DJM_CTL("Ch2 Input", 250mk2_cap2, 2, SND_DJM_WINDEX_CAP), | |
3104 | SND_DJM_CTL("Ch3 Input", 250mk2_cap3, 0, SND_DJM_WINDEX_CAP), | |
3105 | SND_DJM_CTL("Ch1 Output", 250mk2_pb1, 0, SND_DJM_WINDEX_PB), | |
3106 | SND_DJM_CTL("Ch2 Output", 250mk2_pb2, 1, SND_DJM_WINDEX_PB), | |
3107 | SND_DJM_CTL("Ch3 Output", 250mk2_pb3, 2, SND_DJM_WINDEX_PB) | |
cdc01a15 FK |
3108 | }; |
3109 | ||
a07df82c OM |
3110 | |
3111 | // DJM-750 | |
3112 | static const u16 snd_djm_opts_750_cap1[] = { | |
3113 | 0x0101, 0x0103, 0x0106, 0x0107, 0x0108, 0x0109, 0x010a, 0x010f }; | |
3114 | static const u16 snd_djm_opts_750_cap2[] = { | |
3115 | 0x0200, 0x0201, 0x0206, 0x0207, 0x0208, 0x0209, 0x020a, 0x020f }; | |
3116 | static const u16 snd_djm_opts_750_cap3[] = { | |
3117 | 0x0300, 0x0301, 0x0306, 0x0307, 0x0308, 0x0309, 0x030a, 0x030f }; | |
3118 | static const u16 snd_djm_opts_750_cap4[] = { | |
3119 | 0x0401, 0x0403, 0x0406, 0x0407, 0x0408, 0x0409, 0x040a, 0x040f }; | |
3120 | ||
3121 | static const struct snd_djm_ctl snd_djm_ctls_750[] = { | |
3122 | SND_DJM_CTL("Capture Level", cap_level, 0, SND_DJM_WINDEX_CAPLVL), | |
3123 | SND_DJM_CTL("Ch1 Input", 750_cap1, 2, SND_DJM_WINDEX_CAP), | |
3124 | SND_DJM_CTL("Ch2 Input", 750_cap2, 2, SND_DJM_WINDEX_CAP), | |
3125 | SND_DJM_CTL("Ch3 Input", 750_cap3, 0, SND_DJM_WINDEX_CAP), | |
3126 | SND_DJM_CTL("Ch4 Input", 750_cap4, 0, SND_DJM_WINDEX_CAP) | |
cdc01a15 FK |
3127 | }; |
3128 | ||
a07df82c | 3129 | |
7687850b NM |
3130 | // DJM-850 |
3131 | static const u16 snd_djm_opts_850_cap1[] = { | |
3132 | 0x0100, 0x0103, 0x0106, 0x0107, 0x0108, 0x0109, 0x010a, 0x010f }; | |
3133 | static const u16 snd_djm_opts_850_cap2[] = { | |
3134 | 0x0200, 0x0201, 0x0206, 0x0207, 0x0208, 0x0209, 0x020a, 0x020f }; | |
3135 | static const u16 snd_djm_opts_850_cap3[] = { | |
3136 | 0x0300, 0x0301, 0x0306, 0x0307, 0x0308, 0x0309, 0x030a, 0x030f }; | |
3137 | static const u16 snd_djm_opts_850_cap4[] = { | |
3138 | 0x0400, 0x0403, 0x0406, 0x0407, 0x0408, 0x0409, 0x040a, 0x040f }; | |
3139 | ||
3140 | static const struct snd_djm_ctl snd_djm_ctls_850[] = { | |
3141 | SND_DJM_CTL("Capture Level", cap_level, 0, SND_DJM_WINDEX_CAPLVL), | |
3142 | SND_DJM_CTL("Ch1 Input", 850_cap1, 1, SND_DJM_WINDEX_CAP), | |
3143 | SND_DJM_CTL("Ch2 Input", 850_cap2, 0, SND_DJM_WINDEX_CAP), | |
3144 | SND_DJM_CTL("Ch3 Input", 850_cap3, 0, SND_DJM_WINDEX_CAP), | |
3145 | SND_DJM_CTL("Ch4 Input", 850_cap4, 1, SND_DJM_WINDEX_CAP) | |
3146 | }; | |
3147 | ||
3148 | ||
fee03efc FL |
3149 | // DJM-900NXS2 |
3150 | static const u16 snd_djm_opts_900nxs2_cap1[] = { | |
3151 | 0x0100, 0x0102, 0x0103, 0x0106, 0x0107, 0x0108, 0x0109, 0x010a }; | |
3152 | static const u16 snd_djm_opts_900nxs2_cap2[] = { | |
3153 | 0x0200, 0x0202, 0x0203, 0x0206, 0x0207, 0x0208, 0x0209, 0x020a }; | |
3154 | static const u16 snd_djm_opts_900nxs2_cap3[] = { | |
3155 | 0x0300, 0x0302, 0x0303, 0x0306, 0x0307, 0x0308, 0x0309, 0x030a }; | |
3156 | static const u16 snd_djm_opts_900nxs2_cap4[] = { | |
3157 | 0x0400, 0x0402, 0x0403, 0x0406, 0x0407, 0x0408, 0x0409, 0x040a }; | |
3158 | static const u16 snd_djm_opts_900nxs2_cap5[] = { | |
3159 | 0x0507, 0x0508, 0x0509, 0x050a, 0x0511, 0x0512, 0x0513, 0x0514 }; | |
3160 | ||
3161 | static const struct snd_djm_ctl snd_djm_ctls_900nxs2[] = { | |
3162 | SND_DJM_CTL("Capture Level", cap_level, 0, SND_DJM_WINDEX_CAPLVL), | |
3163 | SND_DJM_CTL("Ch1 Input", 900nxs2_cap1, 2, SND_DJM_WINDEX_CAP), | |
3164 | SND_DJM_CTL("Ch2 Input", 900nxs2_cap2, 2, SND_DJM_WINDEX_CAP), | |
3165 | SND_DJM_CTL("Ch3 Input", 900nxs2_cap3, 2, SND_DJM_WINDEX_CAP), | |
3166 | SND_DJM_CTL("Ch4 Input", 900nxs2_cap4, 2, SND_DJM_WINDEX_CAP), | |
3167 | SND_DJM_CTL("Ch5 Input", 900nxs2_cap5, 3, SND_DJM_WINDEX_CAP) | |
3168 | }; | |
3169 | ||
6d277881 WO |
3170 | // DJM-750MK2 |
3171 | static const u16 snd_djm_opts_750mk2_cap1[] = { | |
3172 | 0x0100, 0x0102, 0x0103, 0x0106, 0x0107, 0x0108, 0x0109, 0x010a }; | |
3173 | static const u16 snd_djm_opts_750mk2_cap2[] = { | |
3174 | 0x0200, 0x0202, 0x0203, 0x0206, 0x0207, 0x0208, 0x0209, 0x020a }; | |
3175 | static const u16 snd_djm_opts_750mk2_cap3[] = { | |
3176 | 0x0300, 0x0302, 0x0303, 0x0306, 0x0307, 0x0308, 0x0309, 0x030a }; | |
3177 | static const u16 snd_djm_opts_750mk2_cap4[] = { | |
3178 | 0x0400, 0x0402, 0x0403, 0x0406, 0x0407, 0x0408, 0x0409, 0x040a }; | |
3179 | static const u16 snd_djm_opts_750mk2_cap5[] = { | |
3180 | 0x0507, 0x0508, 0x0509, 0x050a, 0x0511, 0x0512, 0x0513, 0x0514 }; | |
3181 | ||
3182 | static const u16 snd_djm_opts_750mk2_pb1[] = { 0x0100, 0x0101, 0x0104 }; | |
3183 | static const u16 snd_djm_opts_750mk2_pb2[] = { 0x0200, 0x0201, 0x0204 }; | |
3184 | static const u16 snd_djm_opts_750mk2_pb3[] = { 0x0300, 0x0301, 0x0304 }; | |
3185 | ||
3186 | ||
3187 | static const struct snd_djm_ctl snd_djm_ctls_750mk2[] = { | |
3188 | SND_DJM_CTL("Capture Level", cap_level, 0, SND_DJM_WINDEX_CAPLVL), | |
3189 | SND_DJM_CTL("Ch1 Input", 750mk2_cap1, 2, SND_DJM_WINDEX_CAP), | |
3190 | SND_DJM_CTL("Ch2 Input", 750mk2_cap2, 2, SND_DJM_WINDEX_CAP), | |
3191 | SND_DJM_CTL("Ch3 Input", 750mk2_cap3, 2, SND_DJM_WINDEX_CAP), | |
3192 | SND_DJM_CTL("Ch4 Input", 750mk2_cap4, 2, SND_DJM_WINDEX_CAP), | |
3193 | SND_DJM_CTL("Ch5 Input", 750mk2_cap5, 3, SND_DJM_WINDEX_CAP), | |
3194 | SND_DJM_CTL("Ch1 Output", 750mk2_pb1, 0, SND_DJM_WINDEX_PB), | |
3195 | SND_DJM_CTL("Ch2 Output", 750mk2_pb2, 1, SND_DJM_WINDEX_PB), | |
3196 | SND_DJM_CTL("Ch3 Output", 750mk2_pb3, 2, SND_DJM_WINDEX_PB) | |
3197 | }; | |
3198 | ||
fee03efc | 3199 | |
a07df82c | 3200 | static const struct snd_djm_device snd_djm_devices[] = { |
fb1af5be GN |
3201 | [SND_DJM_250MK2_IDX] = SND_DJM_DEVICE(250mk2), |
3202 | [SND_DJM_750_IDX] = SND_DJM_DEVICE(750), | |
3203 | [SND_DJM_850_IDX] = SND_DJM_DEVICE(850), | |
3204 | [SND_DJM_900NXS2_IDX] = SND_DJM_DEVICE(900nxs2), | |
3205 | [SND_DJM_750MK2_IDX] = SND_DJM_DEVICE(750mk2), | |
cdc01a15 FK |
3206 | }; |
3207 | ||
cdc01a15 | 3208 | |
a07df82c OM |
3209 | static int snd_djm_controls_info(struct snd_kcontrol *kctl, |
3210 | struct snd_ctl_elem_info *info) | |
cdc01a15 | 3211 | { |
a07df82c OM |
3212 | unsigned long private_value = kctl->private_value; |
3213 | u8 device_idx = (private_value & SND_DJM_DEVICE_MASK) >> SND_DJM_DEVICE_SHIFT; | |
3214 | u8 ctl_idx = (private_value & SND_DJM_GROUP_MASK) >> SND_DJM_GROUP_SHIFT; | |
3215 | const struct snd_djm_device *device = &snd_djm_devices[device_idx]; | |
cdc01a15 | 3216 | const char *name; |
a07df82c OM |
3217 | const struct snd_djm_ctl *ctl; |
3218 | size_t noptions; | |
3219 | ||
3220 | if (ctl_idx >= device->ncontrols) | |
3221 | return -EINVAL; | |
3222 | ||
3223 | ctl = &device->controls[ctl_idx]; | |
3224 | noptions = ctl->noptions; | |
3225 | if (info->value.enumerated.item >= noptions) | |
3226 | info->value.enumerated.item = noptions - 1; | |
cdc01a15 | 3227 | |
b8db8be8 NM |
3228 | name = snd_djm_get_label(device_idx, |
3229 | ctl->options[info->value.enumerated.item], | |
a07df82c OM |
3230 | ctl->wIndex); |
3231 | if (!name) | |
cdc01a15 FK |
3232 | return -EINVAL; |
3233 | ||
75b1a8f9 | 3234 | strscpy(info->value.enumerated.name, name, sizeof(info->value.enumerated.name)); |
cdc01a15 FK |
3235 | info->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED; |
3236 | info->count = 1; | |
a07df82c | 3237 | info->value.enumerated.items = noptions; |
cdc01a15 FK |
3238 | return 0; |
3239 | } | |
3240 | ||
a07df82c OM |
3241 | static int snd_djm_controls_update(struct usb_mixer_interface *mixer, |
3242 | u8 device_idx, u8 group, u16 value) | |
cdc01a15 FK |
3243 | { |
3244 | int err; | |
a07df82c | 3245 | const struct snd_djm_device *device = &snd_djm_devices[device_idx]; |
cdc01a15 | 3246 | |
a07df82c | 3247 | if ((group >= device->ncontrols) || value >= device->controls[group].noptions) |
cdc01a15 FK |
3248 | return -EINVAL; |
3249 | ||
3250 | err = snd_usb_lock_shutdown(mixer->chip); | |
3251 | if (err) | |
3252 | return err; | |
3253 | ||
3254 | err = snd_usb_ctl_msg( | |
3255 | mixer->chip->dev, usb_sndctrlpipe(mixer->chip->dev, 0), | |
3256 | USB_REQ_SET_FEATURE, | |
3257 | USB_DIR_OUT | USB_TYPE_VENDOR | USB_RECIP_DEVICE, | |
a07df82c OM |
3258 | device->controls[group].options[value], |
3259 | device->controls[group].wIndex, | |
cdc01a15 FK |
3260 | NULL, 0); |
3261 | ||
3262 | snd_usb_unlock_shutdown(mixer->chip); | |
3263 | return err; | |
3264 | } | |
3265 | ||
a07df82c OM |
3266 | static int snd_djm_controls_get(struct snd_kcontrol *kctl, |
3267 | struct snd_ctl_elem_value *elem) | |
cdc01a15 | 3268 | { |
a07df82c | 3269 | elem->value.enumerated.item[0] = kctl->private_value & SND_DJM_VALUE_MASK; |
cdc01a15 FK |
3270 | return 0; |
3271 | } | |
3272 | ||
a07df82c | 3273 | static int snd_djm_controls_put(struct snd_kcontrol *kctl, struct snd_ctl_elem_value *elem) |
cdc01a15 FK |
3274 | { |
3275 | struct usb_mixer_elem_list *list = snd_kcontrol_chip(kctl); | |
3276 | struct usb_mixer_interface *mixer = list->mixer; | |
3277 | unsigned long private_value = kctl->private_value; | |
a07df82c OM |
3278 | |
3279 | u8 device = (private_value & SND_DJM_DEVICE_MASK) >> SND_DJM_DEVICE_SHIFT; | |
3280 | u8 group = (private_value & SND_DJM_GROUP_MASK) >> SND_DJM_GROUP_SHIFT; | |
cdc01a15 FK |
3281 | u16 value = elem->value.enumerated.item[0]; |
3282 | ||
50b1affc | 3283 | kctl->private_value = (((unsigned long)device << SND_DJM_DEVICE_SHIFT) | |
a07df82c OM |
3284 | (group << SND_DJM_GROUP_SHIFT) | |
3285 | value); | |
cdc01a15 | 3286 | |
a07df82c | 3287 | return snd_djm_controls_update(mixer, device, group, value); |
cdc01a15 FK |
3288 | } |
3289 | ||
a07df82c | 3290 | static int snd_djm_controls_resume(struct usb_mixer_elem_list *list) |
cdc01a15 FK |
3291 | { |
3292 | unsigned long private_value = list->kctl->private_value; | |
a07df82c OM |
3293 | u8 device = (private_value & SND_DJM_DEVICE_MASK) >> SND_DJM_DEVICE_SHIFT; |
3294 | u8 group = (private_value & SND_DJM_GROUP_MASK) >> SND_DJM_GROUP_SHIFT; | |
3295 | u16 value = (private_value & SND_DJM_VALUE_MASK); | |
cdc01a15 | 3296 | |
a07df82c | 3297 | return snd_djm_controls_update(list->mixer, device, group, value); |
cdc01a15 FK |
3298 | } |
3299 | ||
a07df82c OM |
3300 | static int snd_djm_controls_create(struct usb_mixer_interface *mixer, |
3301 | const u8 device_idx) | |
cdc01a15 FK |
3302 | { |
3303 | int err, i; | |
a07df82c OM |
3304 | u16 value; |
3305 | ||
3306 | const struct snd_djm_device *device = &snd_djm_devices[device_idx]; | |
3307 | ||
cdc01a15 FK |
3308 | struct snd_kcontrol_new knew = { |
3309 | .iface = SNDRV_CTL_ELEM_IFACE_MIXER, | |
3310 | .access = SNDRV_CTL_ELEM_ACCESS_READWRITE, | |
3311 | .index = 0, | |
a07df82c OM |
3312 | .info = snd_djm_controls_info, |
3313 | .get = snd_djm_controls_get, | |
3314 | .put = snd_djm_controls_put | |
cdc01a15 FK |
3315 | }; |
3316 | ||
a07df82c OM |
3317 | for (i = 0; i < device->ncontrols; i++) { |
3318 | value = device->controls[i].default_value; | |
3319 | knew.name = device->controls[i].name; | |
3320 | knew.private_value = ( | |
50b1affc | 3321 | ((unsigned long)device_idx << SND_DJM_DEVICE_SHIFT) | |
a07df82c OM |
3322 | (i << SND_DJM_GROUP_SHIFT) | |
3323 | value); | |
3324 | err = snd_djm_controls_update(mixer, device_idx, i, value); | |
cdc01a15 FK |
3325 | if (err) |
3326 | return err; | |
a07df82c | 3327 | err = add_single_ctl_with_resume(mixer, 0, snd_djm_controls_resume, |
cdc01a15 FK |
3328 | &knew, NULL); |
3329 | if (err) | |
3330 | return err; | |
3331 | } | |
3332 | return 0; | |
3333 | } | |
3334 | ||
7b1eda22 DM |
3335 | int snd_usb_mixer_apply_create_quirk(struct usb_mixer_interface *mixer) |
3336 | { | |
3347b26c | 3337 | int err = 0; |
7b1eda22 | 3338 | |
f25ecf8f TI |
3339 | err = snd_usb_soundblaster_remote_init(mixer); |
3340 | if (err < 0) | |
7b1eda22 DM |
3341 | return err; |
3342 | ||
3347b26c | 3343 | switch (mixer->chip->usb_id) { |
d2bb390a DU |
3344 | /* Tascam US-16x08 */ |
3345 | case USB_ID(0x0644, 0x8047): | |
3346 | err = snd_us16x08_controls_create(mixer); | |
3347 | break; | |
3347b26c DM |
3348 | case USB_ID(0x041e, 0x3020): |
3349 | case USB_ID(0x041e, 0x3040): | |
3350 | case USB_ID(0x041e, 0x3042): | |
7cdd8d73 | 3351 | case USB_ID(0x041e, 0x30df): |
3347b26c DM |
3352 | case USB_ID(0x041e, 0x3048): |
3353 | err = snd_audigy2nx_controls_create(mixer); | |
3354 | if (err < 0) | |
3355 | break; | |
7449054a TI |
3356 | snd_card_ro_proc_new(mixer->chip->card, "audigy2nx", |
3357 | mixer, snd_audigy2nx_proc_read); | |
3347b26c | 3358 | break; |
7b1eda22 | 3359 | |
44832a71 VK |
3360 | /* EMU0204 */ |
3361 | case USB_ID(0x041e, 0x3f19): | |
3362 | err = snd_emu0204_controls_create(mixer); | |
44832a71 VK |
3363 | break; |
3364 | ||
09d8e3a7 | 3365 | case USB_ID(0x0763, 0x2030): /* M-Audio Fast Track C400 */ |
e9a25e04 | 3366 | case USB_ID(0x0763, 0x2031): /* M-Audio Fast Track C400 */ |
09d8e3a7 EZ |
3367 | err = snd_c400_create_mixer(mixer); |
3368 | break; | |
3369 | ||
d5a0bf6c DM |
3370 | case USB_ID(0x0763, 0x2080): /* M-Audio Fast Track Ultra */ |
3371 | case USB_ID(0x0763, 0x2081): /* M-Audio Fast Track Ultra 8R */ | |
cfe8f97c | 3372 | err = snd_ftu_create_mixer(mixer); |
d5a0bf6c DM |
3373 | break; |
3374 | ||
1d31affb DW |
3375 | case USB_ID(0x0b05, 0x1739): /* ASUS Xonar U1 */ |
3376 | case USB_ID(0x0b05, 0x1743): /* ASUS Xonar U1 (2) */ | |
3377 | case USB_ID(0x0b05, 0x17a0): /* ASUS Xonar U3 */ | |
7b1eda22 | 3378 | err = snd_xonar_u1_controls_create(mixer); |
3347b26c | 3379 | break; |
7b1eda22 | 3380 | |
066624c6 PR |
3381 | case USB_ID(0x0d8c, 0x0103): /* Audio Advantage Micro II */ |
3382 | err = snd_microii_controls_create(mixer); | |
3383 | break; | |
3384 | ||
d497a82f | 3385 | case USB_ID(0x0dba, 0x1000): /* Digidesign Mbox 1 */ |
7ac2246f | 3386 | err = snd_mbox1_controls_create(mixer); |
d497a82f DZ |
3387 | break; |
3388 | ||
3347b26c | 3389 | case USB_ID(0x17cc, 0x1011): /* Traktor Audio 6 */ |
54a8c500 DM |
3390 | err = snd_nativeinstruments_create_mixer(mixer, |
3391 | snd_nativeinstruments_ta6_mixers, | |
3392 | ARRAY_SIZE(snd_nativeinstruments_ta6_mixers)); | |
3347b26c | 3393 | break; |
54a8c500 | 3394 | |
3347b26c | 3395 | case USB_ID(0x17cc, 0x1021): /* Traktor Audio 10 */ |
54a8c500 DM |
3396 | err = snd_nativeinstruments_create_mixer(mixer, |
3397 | snd_nativeinstruments_ta10_mixers, | |
3398 | ARRAY_SIZE(snd_nativeinstruments_ta10_mixers)); | |
3347b26c | 3399 | break; |
7536c301 MH |
3400 | |
3401 | case USB_ID(0x200c, 0x1018): /* Electrix Ebox-44 */ | |
b71dad18 MH |
3402 | /* detection is disabled in mixer_maps.c */ |
3403 | err = snd_create_std_mono_table(mixer, ebox44_table); | |
7536c301 | 3404 | break; |
76b188c4 CA |
3405 | |
3406 | case USB_ID(0x1235, 0x8012): /* Focusrite Scarlett 6i6 */ | |
3407 | case USB_ID(0x1235, 0x8002): /* Focusrite Scarlett 8i6 */ | |
3408 | case USB_ID(0x1235, 0x8004): /* Focusrite Scarlett 18i6 */ | |
3409 | case USB_ID(0x1235, 0x8014): /* Focusrite Scarlett 18i8 */ | |
3410 | case USB_ID(0x1235, 0x800c): /* Focusrite Scarlett 18i20 */ | |
3411 | err = snd_scarlett_controls_create(mixer); | |
3412 | break; | |
388fdb8f | 3413 | |
9e4d5c1b GB |
3414 | case USB_ID(0x1235, 0x8203): /* Focusrite Scarlett 6i6 2nd Gen */ |
3415 | case USB_ID(0x1235, 0x8204): /* Focusrite Scarlett 18i8 2nd Gen */ | |
3416 | case USB_ID(0x1235, 0x8201): /* Focusrite Scarlett 18i20 2nd Gen */ | |
2fa96277 GB |
3417 | case USB_ID(0x1235, 0x8211): /* Focusrite Scarlett Solo 3rd Gen */ |
3418 | case USB_ID(0x1235, 0x8210): /* Focusrite Scarlett 2i2 3rd Gen */ | |
4be47798 GB |
3419 | case USB_ID(0x1235, 0x8212): /* Focusrite Scarlett 4i4 3rd Gen */ |
3420 | case USB_ID(0x1235, 0x8213): /* Focusrite Scarlett 8i6 3rd Gen */ | |
3421 | case USB_ID(0x1235, 0x8214): /* Focusrite Scarlett 18i8 3rd Gen */ | |
3422 | case USB_ID(0x1235, 0x8215): /* Focusrite Scarlett 18i20 3rd Gen */ | |
f71c70df | 3423 | case USB_ID(0x1235, 0x820c): /* Focusrite Clarett+ 8Pre */ |
265d1a90 | 3424 | err = snd_scarlett_gen2_init(mixer); |
9e4d5c1b GB |
3425 | break; |
3426 | ||
388fdb8f IDS |
3427 | case USB_ID(0x041e, 0x323b): /* Creative Sound Blaster E1 */ |
3428 | err = snd_soundblaster_e1_switch_create(mixer); | |
3429 | break; | |
964af639 | 3430 | case USB_ID(0x0bda, 0x4014): /* Dell WD15 dock */ |
4b8ea38f JS |
3431 | err = dell_dock_mixer_create(mixer); |
3432 | if (err < 0) | |
3433 | break; | |
964af639 TI |
3434 | err = dell_dock_mixer_init(mixer); |
3435 | break; | |
d39f1d68 JL |
3436 | |
3437 | case USB_ID(0x2a39, 0x3fd2): /* RME ADI-2 Pro */ | |
3438 | case USB_ID(0x2a39, 0x3fd3): /* RME ADI-2 DAC */ | |
3439 | case USB_ID(0x2a39, 0x3fd4): /* RME */ | |
3440 | err = snd_rme_controls_create(mixer); | |
3441 | break; | |
8dc5efe3 | 3442 | |
1e583aef | 3443 | case USB_ID(0x194f, 0x010c): /* Presonus Studio 1810c */ |
8dc5efe3 NK |
3444 | err = snd_sc1810_init_mixer(mixer); |
3445 | break; | |
3e8f3bd0 TE |
3446 | case USB_ID(0x2a39, 0x3fb0): /* RME Babyface Pro FS */ |
3447 | err = snd_bbfpro_controls_create(mixer); | |
3448 | break; | |
cdc01a15 | 3449 | case USB_ID(0x2b73, 0x0017): /* Pioneer DJ DJM-250MK2 */ |
a07df82c OM |
3450 | err = snd_djm_controls_create(mixer, SND_DJM_250MK2_IDX); |
3451 | break; | |
3452 | case USB_ID(0x08e4, 0x017f): /* Pioneer DJ DJM-750 */ | |
3453 | err = snd_djm_controls_create(mixer, SND_DJM_750_IDX); | |
cdc01a15 | 3454 | break; |
6d277881 WO |
3455 | case USB_ID(0x2b73, 0x001b): /* Pioneer DJ DJM-750MK2 */ |
3456 | err = snd_djm_controls_create(mixer, SND_DJM_750MK2_IDX); | |
3457 | break; | |
7687850b NM |
3458 | case USB_ID(0x08e4, 0x0163): /* Pioneer DJ DJM-850 */ |
3459 | err = snd_djm_controls_create(mixer, SND_DJM_850_IDX); | |
3460 | break; | |
fee03efc FL |
3461 | case USB_ID(0x2b73, 0x000a): /* Pioneer DJ DJM-900NXS2 */ |
3462 | err = snd_djm_controls_create(mixer, SND_DJM_900NXS2_IDX); | |
3463 | break; | |
54a8c500 DM |
3464 | } |
3465 | ||
3347b26c | 3466 | return err; |
7b1eda22 DM |
3467 | } |
3468 | ||
964af639 TI |
3469 | void snd_usb_mixer_resume_quirk(struct usb_mixer_interface *mixer) |
3470 | { | |
3471 | switch (mixer->chip->usb_id) { | |
3472 | case USB_ID(0x0bda, 0x4014): /* Dell WD15 dock */ | |
3473 | dell_dock_mixer_init(mixer); | |
3474 | break; | |
3475 | } | |
3476 | } | |
964af639 | 3477 | |
7b1eda22 DM |
3478 | void snd_usb_mixer_rc_memory_change(struct usb_mixer_interface *mixer, |
3479 | int unitid) | |
3480 | { | |
3481 | if (!mixer->rc_cfg) | |
3482 | return; | |
3483 | /* unit ids specific to Extigy/Audigy 2 NX: */ | |
3484 | switch (unitid) { | |
3485 | case 0: /* remote control */ | |
3486 | mixer->rc_urb->dev = mixer->chip->dev; | |
3487 | usb_submit_urb(mixer->rc_urb, GFP_ATOMIC); | |
3488 | break; | |
3489 | case 4: /* digital in jack */ | |
3490 | case 7: /* line in jacks */ | |
3491 | case 19: /* speaker out jacks */ | |
3492 | case 20: /* headphones out jack */ | |
3493 | break; | |
3494 | /* live24ext: 4 = line-in jack */ | |
3495 | case 3: /* hp-out jack (may actuate Mute) */ | |
3496 | if (mixer->chip->usb_id == USB_ID(0x041e, 0x3040) || | |
3497 | mixer->chip->usb_id == USB_ID(0x041e, 0x3048)) | |
3498 | snd_usb_mixer_notify_id(mixer, mixer->rc_cfg->mute_mixer_id); | |
3499 | break; | |
3500 | default: | |
0ba41d91 | 3501 | usb_audio_dbg(mixer->chip, "memory change in unknown unit %d\n", unitid); |
7b1eda22 DM |
3502 | break; |
3503 | } | |
3504 | } | |
3505 | ||
42e3121d | 3506 | static void snd_dragonfly_quirk_db_scale(struct usb_mixer_interface *mixer, |
eb1a74b7 | 3507 | struct usb_mixer_elem_info *cval, |
42e3121d AH |
3508 | struct snd_kcontrol *kctl) |
3509 | { | |
3510 | /* Approximation using 10 ranges based on output measurement on hw v1.2. | |
3511 | * This seems close to the cubic mapping e.g. alsamixer uses. */ | |
3512 | static const DECLARE_TLV_DB_RANGE(scale, | |
3513 | 0, 1, TLV_DB_MINMAX_ITEM(-5300, -4970), | |
3514 | 2, 5, TLV_DB_MINMAX_ITEM(-4710, -4160), | |
3515 | 6, 7, TLV_DB_MINMAX_ITEM(-3884, -3710), | |
3516 | 8, 14, TLV_DB_MINMAX_ITEM(-3443, -2560), | |
3517 | 15, 16, TLV_DB_MINMAX_ITEM(-2475, -2324), | |
3518 | 17, 19, TLV_DB_MINMAX_ITEM(-2228, -2031), | |
3519 | 20, 26, TLV_DB_MINMAX_ITEM(-1910, -1393), | |
3520 | 27, 31, TLV_DB_MINMAX_ITEM(-1322, -1032), | |
3521 | 32, 40, TLV_DB_MINMAX_ITEM(-968, -490), | |
3522 | 41, 50, TLV_DB_MINMAX_ITEM(-441, 0), | |
3523 | ); | |
3524 | ||
eb1a74b7 AH |
3525 | if (cval->min == 0 && cval->max == 50) { |
3526 | usb_audio_info(mixer->chip, "applying DragonFly dB scale quirk (0-50 variant)\n"); | |
3527 | kctl->tlv.p = scale; | |
3528 | kctl->vd[0].access |= SNDRV_CTL_ELEM_ACCESS_TLV_READ; | |
3529 | kctl->vd[0].access &= ~SNDRV_CTL_ELEM_ACCESS_TLV_CALLBACK; | |
3530 | ||
3531 | } else if (cval->min == 0 && cval->max <= 1000) { | |
3532 | /* Some other clearly broken DragonFly variant. | |
3533 | * At least a 0..53 variant (hw v1.0) exists. | |
3534 | */ | |
3535 | usb_audio_info(mixer->chip, "ignoring too narrow dB range on a DragonFly device"); | |
3536 | kctl->vd[0].access &= ~SNDRV_CTL_ELEM_ACCESS_TLV_CALLBACK; | |
3537 | } | |
42e3121d AH |
3538 | } |
3539 | ||
3540 | void snd_usb_mixer_fu_apply_quirk(struct usb_mixer_interface *mixer, | |
3541 | struct usb_mixer_elem_info *cval, int unitid, | |
3542 | struct snd_kcontrol *kctl) | |
3543 | { | |
3544 | switch (mixer->chip->usb_id) { | |
3545 | case USB_ID(0x21b4, 0x0081): /* AudioQuest DragonFly */ | |
eb1a74b7 AH |
3546 | if (unitid == 7 && cval->control == UAC_FU_VOLUME) |
3547 | snd_dragonfly_quirk_db_scale(mixer, cval, kctl); | |
42e3121d | 3548 | break; |
0f306cca LPC |
3549 | /* lowest playback value is muted on some devices */ |
3550 | case USB_ID(0x0d8c, 0x000c): /* C-Media */ | |
3551 | case USB_ID(0x0d8c, 0x0014): /* C-Media */ | |
3552 | case USB_ID(0x19f7, 0x0003): /* RODE NT-USB */ | |
0f174b35 TI |
3553 | if (strstr(kctl->id.name, "Playback")) |
3554 | cval->min_mute = 1; | |
3555 | break; | |
42e3121d AH |
3556 | } |
3557 | } | |
3558 |