mixer_quirks.c 49 KB

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