mixer_quirks.c 52 KB

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