mixer_quirks.c 52 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008
  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. 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. const 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 __poll_t 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 ? EPOLLIN | EPOLLRDNORM : 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; /* SampleRate ExtensionUnit ID */
  1025. list_for_each_entry(mixer, &chip->mixer_list, list) {
  1026. if (mixer->id_elems[unitid]) {
  1027. cval = mixer_elem_list_to_info(mixer->id_elems[unitid]);
  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. break;
  1033. }
  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 const 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. const 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. /* Creative Sound Blaster E1 */
  1508. static int snd_soundblaster_e1_switch_get(struct snd_kcontrol *kcontrol,
  1509. struct snd_ctl_elem_value *ucontrol)
  1510. {
  1511. ucontrol->value.integer.value[0] = kcontrol->private_value;
  1512. return 0;
  1513. }
  1514. static int snd_soundblaster_e1_switch_update(struct usb_mixer_interface *mixer,
  1515. unsigned char state)
  1516. {
  1517. struct snd_usb_audio *chip = mixer->chip;
  1518. int err;
  1519. unsigned char buff[2];
  1520. buff[0] = 0x02;
  1521. buff[1] = state ? 0x02 : 0x00;
  1522. err = snd_usb_lock_shutdown(chip);
  1523. if (err < 0)
  1524. return err;
  1525. err = snd_usb_ctl_msg(chip->dev,
  1526. usb_sndctrlpipe(chip->dev, 0), HID_REQ_SET_REPORT,
  1527. USB_TYPE_CLASS | USB_RECIP_INTERFACE | USB_DIR_OUT,
  1528. 0x0202, 3, buff, 2);
  1529. snd_usb_unlock_shutdown(chip);
  1530. return err;
  1531. }
  1532. static int snd_soundblaster_e1_switch_put(struct snd_kcontrol *kcontrol,
  1533. struct snd_ctl_elem_value *ucontrol)
  1534. {
  1535. struct usb_mixer_elem_list *list = snd_kcontrol_chip(kcontrol);
  1536. unsigned char value = !!ucontrol->value.integer.value[0];
  1537. int err;
  1538. if (kcontrol->private_value == value)
  1539. return 0;
  1540. kcontrol->private_value = value;
  1541. err = snd_soundblaster_e1_switch_update(list->mixer, value);
  1542. return err < 0 ? err : 1;
  1543. }
  1544. static int snd_soundblaster_e1_switch_resume(struct usb_mixer_elem_list *list)
  1545. {
  1546. return snd_soundblaster_e1_switch_update(list->mixer,
  1547. list->kctl->private_value);
  1548. }
  1549. static int snd_soundblaster_e1_switch_info(struct snd_kcontrol *kcontrol,
  1550. struct snd_ctl_elem_info *uinfo)
  1551. {
  1552. static const char *const texts[2] = {
  1553. "Mic", "Aux"
  1554. };
  1555. return snd_ctl_enum_info(uinfo, 1, ARRAY_SIZE(texts), texts);
  1556. }
  1557. static struct snd_kcontrol_new snd_soundblaster_e1_input_switch = {
  1558. .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
  1559. .name = "Input Source",
  1560. .info = snd_soundblaster_e1_switch_info,
  1561. .get = snd_soundblaster_e1_switch_get,
  1562. .put = snd_soundblaster_e1_switch_put,
  1563. .private_value = 0,
  1564. };
  1565. static int snd_soundblaster_e1_switch_create(struct usb_mixer_interface *mixer)
  1566. {
  1567. return add_single_ctl_with_resume(mixer, 0,
  1568. snd_soundblaster_e1_switch_resume,
  1569. &snd_soundblaster_e1_input_switch,
  1570. NULL);
  1571. }
  1572. static void dell_dock_init_vol(struct snd_usb_audio *chip, int ch, int id)
  1573. {
  1574. u16 buf = 0;
  1575. snd_usb_ctl_msg(chip->dev, usb_sndctrlpipe(chip->dev, 0), UAC_SET_CUR,
  1576. USB_RECIP_INTERFACE | USB_TYPE_CLASS | USB_DIR_OUT,
  1577. ch, snd_usb_ctrl_intf(chip) | (id << 8),
  1578. &buf, 2);
  1579. }
  1580. static int dell_dock_mixer_init(struct usb_mixer_interface *mixer)
  1581. {
  1582. /* fix to 0dB playback volumes */
  1583. dell_dock_init_vol(mixer->chip, 1, 16);
  1584. dell_dock_init_vol(mixer->chip, 2, 16);
  1585. dell_dock_init_vol(mixer->chip, 1, 19);
  1586. dell_dock_init_vol(mixer->chip, 2, 19);
  1587. return 0;
  1588. }
  1589. int snd_usb_mixer_apply_create_quirk(struct usb_mixer_interface *mixer)
  1590. {
  1591. int err = 0;
  1592. struct snd_info_entry *entry;
  1593. err = snd_usb_soundblaster_remote_init(mixer);
  1594. if (err < 0)
  1595. return err;
  1596. switch (mixer->chip->usb_id) {
  1597. /* Tascam US-16x08 */
  1598. case USB_ID(0x0644, 0x8047):
  1599. err = snd_us16x08_controls_create(mixer);
  1600. break;
  1601. case USB_ID(0x041e, 0x3020):
  1602. case USB_ID(0x041e, 0x3040):
  1603. case USB_ID(0x041e, 0x3042):
  1604. case USB_ID(0x041e, 0x30df):
  1605. case USB_ID(0x041e, 0x3048):
  1606. err = snd_audigy2nx_controls_create(mixer);
  1607. if (err < 0)
  1608. break;
  1609. if (!snd_card_proc_new(mixer->chip->card, "audigy2nx", &entry))
  1610. snd_info_set_text_ops(entry, mixer,
  1611. snd_audigy2nx_proc_read);
  1612. break;
  1613. /* EMU0204 */
  1614. case USB_ID(0x041e, 0x3f19):
  1615. err = snd_emu0204_controls_create(mixer);
  1616. break;
  1617. case USB_ID(0x0763, 0x2030): /* M-Audio Fast Track C400 */
  1618. case USB_ID(0x0763, 0x2031): /* M-Audio Fast Track C400 */
  1619. err = snd_c400_create_mixer(mixer);
  1620. break;
  1621. case USB_ID(0x0763, 0x2080): /* M-Audio Fast Track Ultra */
  1622. case USB_ID(0x0763, 0x2081): /* M-Audio Fast Track Ultra 8R */
  1623. err = snd_ftu_create_mixer(mixer);
  1624. break;
  1625. case USB_ID(0x0b05, 0x1739): /* ASUS Xonar U1 */
  1626. case USB_ID(0x0b05, 0x1743): /* ASUS Xonar U1 (2) */
  1627. case USB_ID(0x0b05, 0x17a0): /* ASUS Xonar U3 */
  1628. err = snd_xonar_u1_controls_create(mixer);
  1629. break;
  1630. case USB_ID(0x0d8c, 0x0103): /* Audio Advantage Micro II */
  1631. err = snd_microii_controls_create(mixer);
  1632. break;
  1633. case USB_ID(0x0dba, 0x1000): /* Digidesign Mbox 1 */
  1634. err = snd_mbox1_create_sync_switch(mixer);
  1635. break;
  1636. case USB_ID(0x17cc, 0x1011): /* Traktor Audio 6 */
  1637. err = snd_nativeinstruments_create_mixer(mixer,
  1638. snd_nativeinstruments_ta6_mixers,
  1639. ARRAY_SIZE(snd_nativeinstruments_ta6_mixers));
  1640. break;
  1641. case USB_ID(0x17cc, 0x1021): /* Traktor Audio 10 */
  1642. err = snd_nativeinstruments_create_mixer(mixer,
  1643. snd_nativeinstruments_ta10_mixers,
  1644. ARRAY_SIZE(snd_nativeinstruments_ta10_mixers));
  1645. break;
  1646. case USB_ID(0x200c, 0x1018): /* Electrix Ebox-44 */
  1647. /* detection is disabled in mixer_maps.c */
  1648. err = snd_create_std_mono_table(mixer, ebox44_table);
  1649. break;
  1650. case USB_ID(0x1235, 0x8012): /* Focusrite Scarlett 6i6 */
  1651. case USB_ID(0x1235, 0x8002): /* Focusrite Scarlett 8i6 */
  1652. case USB_ID(0x1235, 0x8004): /* Focusrite Scarlett 18i6 */
  1653. case USB_ID(0x1235, 0x8014): /* Focusrite Scarlett 18i8 */
  1654. case USB_ID(0x1235, 0x800c): /* Focusrite Scarlett 18i20 */
  1655. err = snd_scarlett_controls_create(mixer);
  1656. break;
  1657. case USB_ID(0x041e, 0x323b): /* Creative Sound Blaster E1 */
  1658. err = snd_soundblaster_e1_switch_create(mixer);
  1659. break;
  1660. case USB_ID(0x0bda, 0x4014): /* Dell WD15 dock */
  1661. err = dell_dock_mixer_init(mixer);
  1662. break;
  1663. }
  1664. return err;
  1665. }
  1666. #ifdef CONFIG_PM
  1667. void snd_usb_mixer_resume_quirk(struct usb_mixer_interface *mixer)
  1668. {
  1669. switch (mixer->chip->usb_id) {
  1670. case USB_ID(0x0bda, 0x4014): /* Dell WD15 dock */
  1671. dell_dock_mixer_init(mixer);
  1672. break;
  1673. }
  1674. }
  1675. #endif
  1676. void snd_usb_mixer_rc_memory_change(struct usb_mixer_interface *mixer,
  1677. int unitid)
  1678. {
  1679. if (!mixer->rc_cfg)
  1680. return;
  1681. /* unit ids specific to Extigy/Audigy 2 NX: */
  1682. switch (unitid) {
  1683. case 0: /* remote control */
  1684. mixer->rc_urb->dev = mixer->chip->dev;
  1685. usb_submit_urb(mixer->rc_urb, GFP_ATOMIC);
  1686. break;
  1687. case 4: /* digital in jack */
  1688. case 7: /* line in jacks */
  1689. case 19: /* speaker out jacks */
  1690. case 20: /* headphones out jack */
  1691. break;
  1692. /* live24ext: 4 = line-in jack */
  1693. case 3: /* hp-out jack (may actuate Mute) */
  1694. if (mixer->chip->usb_id == USB_ID(0x041e, 0x3040) ||
  1695. mixer->chip->usb_id == USB_ID(0x041e, 0x3048))
  1696. snd_usb_mixer_notify_id(mixer, mixer->rc_cfg->mute_mixer_id);
  1697. break;
  1698. default:
  1699. usb_audio_dbg(mixer->chip, "memory change in unknown unit %d\n", unitid);
  1700. break;
  1701. }
  1702. }
  1703. static void snd_dragonfly_quirk_db_scale(struct usb_mixer_interface *mixer,
  1704. struct usb_mixer_elem_info *cval,
  1705. struct snd_kcontrol *kctl)
  1706. {
  1707. /* Approximation using 10 ranges based on output measurement on hw v1.2.
  1708. * This seems close to the cubic mapping e.g. alsamixer uses. */
  1709. static const DECLARE_TLV_DB_RANGE(scale,
  1710. 0, 1, TLV_DB_MINMAX_ITEM(-5300, -4970),
  1711. 2, 5, TLV_DB_MINMAX_ITEM(-4710, -4160),
  1712. 6, 7, TLV_DB_MINMAX_ITEM(-3884, -3710),
  1713. 8, 14, TLV_DB_MINMAX_ITEM(-3443, -2560),
  1714. 15, 16, TLV_DB_MINMAX_ITEM(-2475, -2324),
  1715. 17, 19, TLV_DB_MINMAX_ITEM(-2228, -2031),
  1716. 20, 26, TLV_DB_MINMAX_ITEM(-1910, -1393),
  1717. 27, 31, TLV_DB_MINMAX_ITEM(-1322, -1032),
  1718. 32, 40, TLV_DB_MINMAX_ITEM(-968, -490),
  1719. 41, 50, TLV_DB_MINMAX_ITEM(-441, 0),
  1720. );
  1721. if (cval->min == 0 && cval->max == 50) {
  1722. usb_audio_info(mixer->chip, "applying DragonFly dB scale quirk (0-50 variant)\n");
  1723. kctl->tlv.p = scale;
  1724. kctl->vd[0].access |= SNDRV_CTL_ELEM_ACCESS_TLV_READ;
  1725. kctl->vd[0].access &= ~SNDRV_CTL_ELEM_ACCESS_TLV_CALLBACK;
  1726. } else if (cval->min == 0 && cval->max <= 1000) {
  1727. /* Some other clearly broken DragonFly variant.
  1728. * At least a 0..53 variant (hw v1.0) exists.
  1729. */
  1730. usb_audio_info(mixer->chip, "ignoring too narrow dB range on a DragonFly device");
  1731. kctl->vd[0].access &= ~SNDRV_CTL_ELEM_ACCESS_TLV_CALLBACK;
  1732. }
  1733. }
  1734. void snd_usb_mixer_fu_apply_quirk(struct usb_mixer_interface *mixer,
  1735. struct usb_mixer_elem_info *cval, int unitid,
  1736. struct snd_kcontrol *kctl)
  1737. {
  1738. switch (mixer->chip->usb_id) {
  1739. case USB_ID(0x21b4, 0x0081): /* AudioQuest DragonFly */
  1740. if (unitid == 7 && cval->control == UAC_FU_VOLUME)
  1741. snd_dragonfly_quirk_db_scale(mixer, cval, kctl);
  1742. break;
  1743. /* lowest playback value is muted on C-Media devices */
  1744. case USB_ID(0x0d8c, 0x000c):
  1745. case USB_ID(0x0d8c, 0x0014):
  1746. if (strstr(kctl->id.name, "Playback"))
  1747. cval->min_mute = 1;
  1748. break;
  1749. }
  1750. }