mixer_quirks.c 49 KB

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