mixer_quirks.c 49 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884
  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. }