mixer_quirks.c 35 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404
  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. *
  13. * This program is free software; you can redistribute it and/or modify
  14. * it under the terms of the GNU General Public License as published by
  15. * the Free Software Foundation; either version 2 of the License, or
  16. * (at your option) any later version.
  17. *
  18. * This program is distributed in the hope that it will be useful,
  19. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  20. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  21. * GNU General Public License for more details.
  22. *
  23. * You should have received a copy of the GNU General Public License
  24. * along with this program; if not, write to the Free Software
  25. * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  26. */
  27. #include <linux/init.h>
  28. #include <linux/slab.h>
  29. #include <linux/usb.h>
  30. #include <linux/usb/audio.h>
  31. #include <sound/core.h>
  32. #include <sound/control.h>
  33. #include <sound/hwdep.h>
  34. #include <sound/info.h>
  35. #include "usbaudio.h"
  36. #include "mixer.h"
  37. #include "mixer_quirks.h"
  38. #include "helper.h"
  39. extern struct snd_kcontrol_new *snd_usb_feature_unit_ctl;
  40. struct std_mono_table {
  41. unsigned int unitid, control, cmask;
  42. int val_type;
  43. const char *name;
  44. snd_kcontrol_tlv_rw_t *tlv_callback;
  45. };
  46. /* private_free callback */
  47. static void usb_mixer_elem_free(struct snd_kcontrol *kctl)
  48. {
  49. kfree(kctl->private_data);
  50. kctl->private_data = NULL;
  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. int err;
  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. cval->id = unitid;
  75. cval->mixer = mixer;
  76. cval->val_type = val_type;
  77. cval->channels = 1;
  78. cval->control = control;
  79. cval->cmask = cmask;
  80. cval->idx_off = idx_off;
  81. /* get_min_max() is called only for integer volumes later,
  82. * so provide a short-cut for booleans */
  83. cval->min = 0;
  84. cval->max = 1;
  85. cval->res = 0;
  86. cval->dBmin = 0;
  87. cval->dBmax = 0;
  88. /* Create control */
  89. kctl = snd_ctl_new1(snd_usb_feature_unit_ctl, cval);
  90. if (!kctl) {
  91. kfree(cval);
  92. return -ENOMEM;
  93. }
  94. /* Set name */
  95. snprintf(kctl->id.name, sizeof(kctl->id.name), name);
  96. kctl->private_free = usb_mixer_elem_free;
  97. /* set TLV */
  98. if (tlv_callback) {
  99. kctl->tlv.c = tlv_callback;
  100. kctl->vd[0].access |=
  101. SNDRV_CTL_ELEM_ACCESS_TLV_READ |
  102. SNDRV_CTL_ELEM_ACCESS_TLV_CALLBACK;
  103. }
  104. /* Add control to mixer */
  105. err = snd_usb_mixer_add_control(mixer, kctl);
  106. if (err < 0)
  107. return err;
  108. return 0;
  109. }
  110. static int snd_create_std_mono_ctl(struct usb_mixer_interface *mixer,
  111. unsigned int unitid,
  112. unsigned int control,
  113. unsigned int cmask,
  114. int val_type,
  115. const char *name,
  116. snd_kcontrol_tlv_rw_t *tlv_callback)
  117. {
  118. return snd_create_std_mono_ctl_offset(mixer, unitid, control, cmask,
  119. val_type, 0 /* Offset */, name, tlv_callback);
  120. }
  121. /*
  122. * Create a set of standard UAC controls from a table
  123. */
  124. static int snd_create_std_mono_table(struct usb_mixer_interface *mixer,
  125. struct std_mono_table *t)
  126. {
  127. int err;
  128. while (t->name != NULL) {
  129. err = snd_create_std_mono_ctl(mixer, t->unitid, t->control,
  130. t->cmask, t->val_type, t->name, t->tlv_callback);
  131. if (err < 0)
  132. return err;
  133. t++;
  134. }
  135. return 0;
  136. }
  137. /*
  138. * Sound Blaster remote control configuration
  139. *
  140. * format of remote control data:
  141. * Extigy: xx 00
  142. * Audigy 2 NX: 06 80 xx 00 00 00
  143. * Live! 24-bit: 06 80 xx yy 22 83
  144. */
  145. static const struct rc_config {
  146. u32 usb_id;
  147. u8 offset;
  148. u8 length;
  149. u8 packet_length;
  150. u8 min_packet_length; /* minimum accepted length of the URB result */
  151. u8 mute_mixer_id;
  152. u32 mute_code;
  153. } rc_configs[] = {
  154. { USB_ID(0x041e, 0x3000), 0, 1, 2, 1, 18, 0x0013 }, /* Extigy */
  155. { USB_ID(0x041e, 0x3020), 2, 1, 6, 6, 18, 0x0013 }, /* Audigy 2 NX */
  156. { USB_ID(0x041e, 0x3040), 2, 2, 6, 6, 2, 0x6e91 }, /* Live! 24-bit */
  157. { USB_ID(0x041e, 0x3042), 0, 1, 1, 1, 1, 0x000d }, /* Usb X-Fi S51 */
  158. { USB_ID(0x041e, 0x30df), 0, 1, 1, 1, 1, 0x000d }, /* Usb X-Fi S51 Pro */
  159. { USB_ID(0x041e, 0x3048), 2, 2, 6, 6, 2, 0x6e91 }, /* Toshiba SB0500 */
  160. };
  161. static void snd_usb_soundblaster_remote_complete(struct urb *urb)
  162. {
  163. struct usb_mixer_interface *mixer = urb->context;
  164. const struct rc_config *rc = mixer->rc_cfg;
  165. u32 code;
  166. if (urb->status < 0 || urb->actual_length < rc->min_packet_length)
  167. return;
  168. code = mixer->rc_buffer[rc->offset];
  169. if (rc->length == 2)
  170. code |= mixer->rc_buffer[rc->offset + 1] << 8;
  171. /* the Mute button actually changes the mixer control */
  172. if (code == rc->mute_code)
  173. snd_usb_mixer_notify_id(mixer, rc->mute_mixer_id);
  174. mixer->rc_code = code;
  175. wmb();
  176. wake_up(&mixer->rc_waitq);
  177. }
  178. static long snd_usb_sbrc_hwdep_read(struct snd_hwdep *hw, char __user *buf,
  179. long count, loff_t *offset)
  180. {
  181. struct usb_mixer_interface *mixer = hw->private_data;
  182. int err;
  183. u32 rc_code;
  184. if (count != 1 && count != 4)
  185. return -EINVAL;
  186. err = wait_event_interruptible(mixer->rc_waitq,
  187. (rc_code = xchg(&mixer->rc_code, 0)) != 0);
  188. if (err == 0) {
  189. if (count == 1)
  190. err = put_user(rc_code, buf);
  191. else
  192. err = put_user(rc_code, (u32 __user *)buf);
  193. }
  194. return err < 0 ? err : count;
  195. }
  196. static unsigned int snd_usb_sbrc_hwdep_poll(struct snd_hwdep *hw, struct file *file,
  197. poll_table *wait)
  198. {
  199. struct usb_mixer_interface *mixer = hw->private_data;
  200. poll_wait(file, &mixer->rc_waitq, wait);
  201. return mixer->rc_code ? POLLIN | POLLRDNORM : 0;
  202. }
  203. static int snd_usb_soundblaster_remote_init(struct usb_mixer_interface *mixer)
  204. {
  205. struct snd_hwdep *hwdep;
  206. int err, len, i;
  207. for (i = 0; i < ARRAY_SIZE(rc_configs); ++i)
  208. if (rc_configs[i].usb_id == mixer->chip->usb_id)
  209. break;
  210. if (i >= ARRAY_SIZE(rc_configs))
  211. return 0;
  212. mixer->rc_cfg = &rc_configs[i];
  213. len = mixer->rc_cfg->packet_length;
  214. init_waitqueue_head(&mixer->rc_waitq);
  215. err = snd_hwdep_new(mixer->chip->card, "SB remote control", 0, &hwdep);
  216. if (err < 0)
  217. return err;
  218. snprintf(hwdep->name, sizeof(hwdep->name),
  219. "%s remote control", mixer->chip->card->shortname);
  220. hwdep->iface = SNDRV_HWDEP_IFACE_SB_RC;
  221. hwdep->private_data = mixer;
  222. hwdep->ops.read = snd_usb_sbrc_hwdep_read;
  223. hwdep->ops.poll = snd_usb_sbrc_hwdep_poll;
  224. hwdep->exclusive = 1;
  225. mixer->rc_urb = usb_alloc_urb(0, GFP_KERNEL);
  226. if (!mixer->rc_urb)
  227. return -ENOMEM;
  228. mixer->rc_setup_packet = kmalloc(sizeof(*mixer->rc_setup_packet), GFP_KERNEL);
  229. if (!mixer->rc_setup_packet) {
  230. usb_free_urb(mixer->rc_urb);
  231. mixer->rc_urb = NULL;
  232. return -ENOMEM;
  233. }
  234. mixer->rc_setup_packet->bRequestType =
  235. USB_DIR_IN | USB_TYPE_CLASS | USB_RECIP_INTERFACE;
  236. mixer->rc_setup_packet->bRequest = UAC_GET_MEM;
  237. mixer->rc_setup_packet->wValue = cpu_to_le16(0);
  238. mixer->rc_setup_packet->wIndex = cpu_to_le16(0);
  239. mixer->rc_setup_packet->wLength = cpu_to_le16(len);
  240. usb_fill_control_urb(mixer->rc_urb, mixer->chip->dev,
  241. usb_rcvctrlpipe(mixer->chip->dev, 0),
  242. (u8*)mixer->rc_setup_packet, mixer->rc_buffer, len,
  243. snd_usb_soundblaster_remote_complete, mixer);
  244. return 0;
  245. }
  246. #define snd_audigy2nx_led_info snd_ctl_boolean_mono_info
  247. static int snd_audigy2nx_led_get(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
  248. {
  249. struct usb_mixer_interface *mixer = snd_kcontrol_chip(kcontrol);
  250. int index = kcontrol->private_value;
  251. ucontrol->value.integer.value[0] = mixer->audigy2nx_leds[index];
  252. return 0;
  253. }
  254. static int snd_audigy2nx_led_put(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
  255. {
  256. struct usb_mixer_interface *mixer = snd_kcontrol_chip(kcontrol);
  257. int index = kcontrol->private_value;
  258. int value = ucontrol->value.integer.value[0];
  259. int err, changed;
  260. if (value > 1)
  261. return -EINVAL;
  262. changed = value != mixer->audigy2nx_leds[index];
  263. down_read(&mixer->chip->shutdown_rwsem);
  264. if (mixer->chip->shutdown) {
  265. err = -ENODEV;
  266. goto out;
  267. }
  268. if (mixer->chip->usb_id == USB_ID(0x041e, 0x3042))
  269. err = snd_usb_ctl_msg(mixer->chip->dev,
  270. usb_sndctrlpipe(mixer->chip->dev, 0), 0x24,
  271. USB_DIR_OUT | USB_TYPE_VENDOR | USB_RECIP_OTHER,
  272. !value, 0, NULL, 0);
  273. /* USB X-Fi S51 Pro */
  274. if (mixer->chip->usb_id == USB_ID(0x041e, 0x30df))
  275. err = snd_usb_ctl_msg(mixer->chip->dev,
  276. usb_sndctrlpipe(mixer->chip->dev, 0), 0x24,
  277. USB_DIR_OUT | USB_TYPE_VENDOR | USB_RECIP_OTHER,
  278. !value, 0, NULL, 0);
  279. else
  280. err = snd_usb_ctl_msg(mixer->chip->dev,
  281. usb_sndctrlpipe(mixer->chip->dev, 0), 0x24,
  282. USB_DIR_OUT | USB_TYPE_VENDOR | USB_RECIP_OTHER,
  283. value, index + 2, NULL, 0);
  284. out:
  285. up_read(&mixer->chip->shutdown_rwsem);
  286. if (err < 0)
  287. return err;
  288. mixer->audigy2nx_leds[index] = value;
  289. return changed;
  290. }
  291. static struct snd_kcontrol_new snd_audigy2nx_controls[] = {
  292. {
  293. .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
  294. .name = "CMSS LED Switch",
  295. .info = snd_audigy2nx_led_info,
  296. .get = snd_audigy2nx_led_get,
  297. .put = snd_audigy2nx_led_put,
  298. .private_value = 0,
  299. },
  300. {
  301. .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
  302. .name = "Power LED Switch",
  303. .info = snd_audigy2nx_led_info,
  304. .get = snd_audigy2nx_led_get,
  305. .put = snd_audigy2nx_led_put,
  306. .private_value = 1,
  307. },
  308. {
  309. .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
  310. .name = "Dolby Digital LED Switch",
  311. .info = snd_audigy2nx_led_info,
  312. .get = snd_audigy2nx_led_get,
  313. .put = snd_audigy2nx_led_put,
  314. .private_value = 2,
  315. },
  316. };
  317. static int snd_audigy2nx_controls_create(struct usb_mixer_interface *mixer)
  318. {
  319. int i, err;
  320. for (i = 0; i < ARRAY_SIZE(snd_audigy2nx_controls); ++i) {
  321. /* USB X-Fi S51 doesn't have a CMSS LED */
  322. if ((mixer->chip->usb_id == USB_ID(0x041e, 0x3042)) && i == 0)
  323. continue;
  324. /* USB X-Fi S51 Pro doesn't have one either */
  325. if ((mixer->chip->usb_id == USB_ID(0x041e, 0x30df)) && i == 0)
  326. continue;
  327. if (i > 1 && /* Live24ext has 2 LEDs only */
  328. (mixer->chip->usb_id == USB_ID(0x041e, 0x3040) ||
  329. mixer->chip->usb_id == USB_ID(0x041e, 0x3042) ||
  330. mixer->chip->usb_id == USB_ID(0x041e, 0x30df) ||
  331. mixer->chip->usb_id == USB_ID(0x041e, 0x3048)))
  332. break;
  333. err = snd_ctl_add(mixer->chip->card,
  334. snd_ctl_new1(&snd_audigy2nx_controls[i], mixer));
  335. if (err < 0)
  336. return err;
  337. }
  338. mixer->audigy2nx_leds[1] = 1; /* Power LED is on by default */
  339. return 0;
  340. }
  341. static void snd_audigy2nx_proc_read(struct snd_info_entry *entry,
  342. struct snd_info_buffer *buffer)
  343. {
  344. static const struct sb_jack {
  345. int unitid;
  346. const char *name;
  347. } jacks_audigy2nx[] = {
  348. {4, "dig in "},
  349. {7, "line in"},
  350. {19, "spk out"},
  351. {20, "hph out"},
  352. {-1, NULL}
  353. }, jacks_live24ext[] = {
  354. {4, "line in"}, /* &1=Line, &2=Mic*/
  355. {3, "hph out"}, /* headphones */
  356. {0, "RC "}, /* last command, 6 bytes see rc_config above */
  357. {-1, NULL}
  358. };
  359. const struct sb_jack *jacks;
  360. struct usb_mixer_interface *mixer = entry->private_data;
  361. int i, err;
  362. u8 buf[3];
  363. snd_iprintf(buffer, "%s jacks\n\n", mixer->chip->card->shortname);
  364. if (mixer->chip->usb_id == USB_ID(0x041e, 0x3020))
  365. jacks = jacks_audigy2nx;
  366. else if (mixer->chip->usb_id == USB_ID(0x041e, 0x3040) ||
  367. mixer->chip->usb_id == USB_ID(0x041e, 0x3048))
  368. jacks = jacks_live24ext;
  369. else
  370. return;
  371. for (i = 0; jacks[i].name; ++i) {
  372. snd_iprintf(buffer, "%s: ", jacks[i].name);
  373. down_read(&mixer->chip->shutdown_rwsem);
  374. if (mixer->chip->shutdown)
  375. err = 0;
  376. else
  377. err = snd_usb_ctl_msg(mixer->chip->dev,
  378. usb_rcvctrlpipe(mixer->chip->dev, 0),
  379. UAC_GET_MEM, USB_DIR_IN | USB_TYPE_CLASS |
  380. USB_RECIP_INTERFACE, 0,
  381. jacks[i].unitid << 8, buf, 3);
  382. up_read(&mixer->chip->shutdown_rwsem);
  383. if (err == 3 && (buf[0] == 3 || buf[0] == 6))
  384. snd_iprintf(buffer, "%02x %02x\n", buf[1], buf[2]);
  385. else
  386. snd_iprintf(buffer, "?\n");
  387. }
  388. }
  389. /* ASUS Xonar U1 / U3 controls */
  390. static int snd_xonar_u1_switch_get(struct snd_kcontrol *kcontrol,
  391. struct snd_ctl_elem_value *ucontrol)
  392. {
  393. struct usb_mixer_interface *mixer = snd_kcontrol_chip(kcontrol);
  394. ucontrol->value.integer.value[0] = !!(mixer->xonar_u1_status & 0x02);
  395. return 0;
  396. }
  397. static int snd_xonar_u1_switch_put(struct snd_kcontrol *kcontrol,
  398. struct snd_ctl_elem_value *ucontrol)
  399. {
  400. struct usb_mixer_interface *mixer = snd_kcontrol_chip(kcontrol);
  401. u8 old_status, new_status;
  402. int err, changed;
  403. old_status = mixer->xonar_u1_status;
  404. if (ucontrol->value.integer.value[0])
  405. new_status = old_status | 0x02;
  406. else
  407. new_status = old_status & ~0x02;
  408. changed = new_status != old_status;
  409. down_read(&mixer->chip->shutdown_rwsem);
  410. if (mixer->chip->shutdown)
  411. err = -ENODEV;
  412. else
  413. err = snd_usb_ctl_msg(mixer->chip->dev,
  414. usb_sndctrlpipe(mixer->chip->dev, 0), 0x08,
  415. USB_DIR_OUT | USB_TYPE_VENDOR | USB_RECIP_OTHER,
  416. 50, 0, &new_status, 1);
  417. up_read(&mixer->chip->shutdown_rwsem);
  418. if (err < 0)
  419. return err;
  420. mixer->xonar_u1_status = new_status;
  421. return changed;
  422. }
  423. static struct snd_kcontrol_new snd_xonar_u1_output_switch = {
  424. .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
  425. .name = "Digital Playback Switch",
  426. .info = snd_ctl_boolean_mono_info,
  427. .get = snd_xonar_u1_switch_get,
  428. .put = snd_xonar_u1_switch_put,
  429. };
  430. static int snd_xonar_u1_controls_create(struct usb_mixer_interface *mixer)
  431. {
  432. int err;
  433. err = snd_ctl_add(mixer->chip->card,
  434. snd_ctl_new1(&snd_xonar_u1_output_switch, mixer));
  435. if (err < 0)
  436. return err;
  437. mixer->xonar_u1_status = 0x05;
  438. return 0;
  439. }
  440. /* Native Instruments device quirks */
  441. #define _MAKE_NI_CONTROL(bRequest,wIndex) ((bRequest) << 16 | (wIndex))
  442. static int snd_nativeinstruments_control_get(struct snd_kcontrol *kcontrol,
  443. struct snd_ctl_elem_value *ucontrol)
  444. {
  445. struct usb_mixer_interface *mixer = snd_kcontrol_chip(kcontrol);
  446. struct usb_device *dev = mixer->chip->dev;
  447. u8 bRequest = (kcontrol->private_value >> 16) & 0xff;
  448. u16 wIndex = kcontrol->private_value & 0xffff;
  449. u8 tmp;
  450. int ret;
  451. down_read(&mixer->chip->shutdown_rwsem);
  452. if (mixer->chip->shutdown)
  453. ret = -ENODEV;
  454. else
  455. ret = usb_control_msg(dev, usb_rcvctrlpipe(dev, 0), bRequest,
  456. USB_TYPE_VENDOR | USB_RECIP_DEVICE | USB_DIR_IN,
  457. 0, cpu_to_le16(wIndex),
  458. &tmp, sizeof(tmp), 1000);
  459. up_read(&mixer->chip->shutdown_rwsem);
  460. if (ret < 0) {
  461. snd_printk(KERN_ERR
  462. "unable to issue vendor read request (ret = %d)", ret);
  463. return ret;
  464. }
  465. ucontrol->value.integer.value[0] = tmp;
  466. return 0;
  467. }
  468. static int snd_nativeinstruments_control_put(struct snd_kcontrol *kcontrol,
  469. struct snd_ctl_elem_value *ucontrol)
  470. {
  471. struct usb_mixer_interface *mixer = snd_kcontrol_chip(kcontrol);
  472. struct usb_device *dev = mixer->chip->dev;
  473. u8 bRequest = (kcontrol->private_value >> 16) & 0xff;
  474. u16 wIndex = kcontrol->private_value & 0xffff;
  475. u16 wValue = ucontrol->value.integer.value[0];
  476. int ret;
  477. down_read(&mixer->chip->shutdown_rwsem);
  478. if (mixer->chip->shutdown)
  479. ret = -ENODEV;
  480. else
  481. ret = usb_control_msg(dev, usb_sndctrlpipe(dev, 0), bRequest,
  482. USB_TYPE_VENDOR | USB_RECIP_DEVICE | USB_DIR_OUT,
  483. cpu_to_le16(wValue), cpu_to_le16(wIndex),
  484. NULL, 0, 1000);
  485. up_read(&mixer->chip->shutdown_rwsem);
  486. if (ret < 0) {
  487. snd_printk(KERN_ERR
  488. "unable to issue vendor write request (ret = %d)", ret);
  489. return ret;
  490. }
  491. return 0;
  492. }
  493. static struct snd_kcontrol_new snd_nativeinstruments_ta6_mixers[] = {
  494. {
  495. .name = "Direct Thru Channel A",
  496. .private_value = _MAKE_NI_CONTROL(0x01, 0x03),
  497. },
  498. {
  499. .name = "Direct Thru Channel B",
  500. .private_value = _MAKE_NI_CONTROL(0x01, 0x05),
  501. },
  502. {
  503. .name = "Phono Input Channel A",
  504. .private_value = _MAKE_NI_CONTROL(0x02, 0x03),
  505. },
  506. {
  507. .name = "Phono Input Channel B",
  508. .private_value = _MAKE_NI_CONTROL(0x02, 0x05),
  509. },
  510. };
  511. static struct snd_kcontrol_new snd_nativeinstruments_ta10_mixers[] = {
  512. {
  513. .name = "Direct Thru Channel A",
  514. .private_value = _MAKE_NI_CONTROL(0x01, 0x03),
  515. },
  516. {
  517. .name = "Direct Thru Channel B",
  518. .private_value = _MAKE_NI_CONTROL(0x01, 0x05),
  519. },
  520. {
  521. .name = "Direct Thru Channel C",
  522. .private_value = _MAKE_NI_CONTROL(0x01, 0x07),
  523. },
  524. {
  525. .name = "Direct Thru Channel D",
  526. .private_value = _MAKE_NI_CONTROL(0x01, 0x09),
  527. },
  528. {
  529. .name = "Phono Input Channel A",
  530. .private_value = _MAKE_NI_CONTROL(0x02, 0x03),
  531. },
  532. {
  533. .name = "Phono Input Channel B",
  534. .private_value = _MAKE_NI_CONTROL(0x02, 0x05),
  535. },
  536. {
  537. .name = "Phono Input Channel C",
  538. .private_value = _MAKE_NI_CONTROL(0x02, 0x07),
  539. },
  540. {
  541. .name = "Phono Input Channel D",
  542. .private_value = _MAKE_NI_CONTROL(0x02, 0x09),
  543. },
  544. };
  545. static int snd_nativeinstruments_create_mixer(struct usb_mixer_interface *mixer,
  546. const struct snd_kcontrol_new *kc,
  547. unsigned int count)
  548. {
  549. int i, err = 0;
  550. struct snd_kcontrol_new template = {
  551. .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
  552. .access = SNDRV_CTL_ELEM_ACCESS_READWRITE,
  553. .get = snd_nativeinstruments_control_get,
  554. .put = snd_nativeinstruments_control_put,
  555. .info = snd_ctl_boolean_mono_info,
  556. };
  557. for (i = 0; i < count; i++) {
  558. struct snd_kcontrol *c;
  559. template.name = kc[i].name;
  560. template.private_value = kc[i].private_value;
  561. c = snd_ctl_new1(&template, mixer);
  562. err = snd_ctl_add(mixer->chip->card, c);
  563. if (err < 0)
  564. break;
  565. }
  566. return err;
  567. }
  568. /* M-Audio FastTrack Ultra quirks */
  569. /* FTU Effect switch (also used by C400/C600) */
  570. struct snd_ftu_eff_switch_priv_val {
  571. struct usb_mixer_interface *mixer;
  572. int cached_value;
  573. int is_cached;
  574. int bUnitID;
  575. int validx;
  576. };
  577. static int snd_ftu_eff_switch_info(struct snd_kcontrol *kcontrol,
  578. struct snd_ctl_elem_info *uinfo)
  579. {
  580. static const char *texts[8] = {"Room 1",
  581. "Room 2",
  582. "Room 3",
  583. "Hall 1",
  584. "Hall 2",
  585. "Plate",
  586. "Delay",
  587. "Echo"
  588. };
  589. uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED;
  590. uinfo->count = 1;
  591. uinfo->value.enumerated.items = 8;
  592. if (uinfo->value.enumerated.item > 7)
  593. uinfo->value.enumerated.item = 7;
  594. strcpy(uinfo->value.enumerated.name,
  595. texts[uinfo->value.enumerated.item]);
  596. return 0;
  597. }
  598. static int snd_ftu_eff_switch_get(struct snd_kcontrol *kctl,
  599. struct snd_ctl_elem_value *ucontrol)
  600. {
  601. struct snd_usb_audio *chip;
  602. struct usb_mixer_interface *mixer;
  603. struct snd_ftu_eff_switch_priv_val *pval;
  604. int err;
  605. unsigned char value[2];
  606. int id, validx;
  607. const int val_len = 2;
  608. value[0] = 0x00;
  609. value[1] = 0x00;
  610. pval = (struct snd_ftu_eff_switch_priv_val *)
  611. kctl->private_value;
  612. if (pval->is_cached) {
  613. ucontrol->value.enumerated.item[0] = pval->cached_value;
  614. return 0;
  615. }
  616. mixer = (struct usb_mixer_interface *) pval->mixer;
  617. if (snd_BUG_ON(!mixer))
  618. return -EINVAL;
  619. chip = (struct snd_usb_audio *) mixer->chip;
  620. if (snd_BUG_ON(!chip))
  621. return -EINVAL;
  622. id = pval->bUnitID;
  623. validx = pval->validx;
  624. down_read(&mixer->chip->shutdown_rwsem);
  625. if (mixer->chip->shutdown)
  626. err = -ENODEV;
  627. else
  628. err = snd_usb_ctl_msg(chip->dev,
  629. usb_rcvctrlpipe(chip->dev, 0), UAC_GET_CUR,
  630. USB_RECIP_INTERFACE | USB_TYPE_CLASS | USB_DIR_IN,
  631. validx << 8, snd_usb_ctrl_intf(chip) | (id << 8),
  632. value, val_len);
  633. up_read(&mixer->chip->shutdown_rwsem);
  634. if (err < 0)
  635. return err;
  636. ucontrol->value.enumerated.item[0] = value[0];
  637. pval->cached_value = value[0];
  638. pval->is_cached = 1;
  639. return 0;
  640. }
  641. static int snd_ftu_eff_switch_put(struct snd_kcontrol *kctl,
  642. struct snd_ctl_elem_value *ucontrol)
  643. {
  644. struct snd_usb_audio *chip;
  645. struct snd_ftu_eff_switch_priv_val *pval;
  646. struct usb_mixer_interface *mixer;
  647. int changed, cur_val, err, new_val;
  648. unsigned char value[2];
  649. int id, validx;
  650. const int val_len = 2;
  651. changed = 0;
  652. pval = (struct snd_ftu_eff_switch_priv_val *)
  653. kctl->private_value;
  654. cur_val = pval->cached_value;
  655. new_val = ucontrol->value.enumerated.item[0];
  656. mixer = (struct usb_mixer_interface *) pval->mixer;
  657. if (snd_BUG_ON(!mixer))
  658. return -EINVAL;
  659. chip = (struct snd_usb_audio *) mixer->chip;
  660. if (snd_BUG_ON(!chip))
  661. return -EINVAL;
  662. id = pval->bUnitID;
  663. validx = pval->validx;
  664. if (!pval->is_cached) {
  665. /* Read current value */
  666. down_read(&mixer->chip->shutdown_rwsem);
  667. if (mixer->chip->shutdown)
  668. err = -ENODEV;
  669. else
  670. err = snd_usb_ctl_msg(chip->dev,
  671. usb_rcvctrlpipe(chip->dev, 0), UAC_GET_CUR,
  672. USB_RECIP_INTERFACE | USB_TYPE_CLASS | USB_DIR_IN,
  673. validx << 8, snd_usb_ctrl_intf(chip) | (id << 8),
  674. value, val_len);
  675. up_read(&mixer->chip->shutdown_rwsem);
  676. if (err < 0)
  677. return err;
  678. cur_val = value[0];
  679. pval->cached_value = cur_val;
  680. pval->is_cached = 1;
  681. }
  682. /* update value if needed */
  683. if (cur_val != new_val) {
  684. value[0] = new_val;
  685. value[1] = 0;
  686. down_read(&mixer->chip->shutdown_rwsem);
  687. if (mixer->chip->shutdown)
  688. err = -ENODEV;
  689. else
  690. err = snd_usb_ctl_msg(chip->dev,
  691. usb_sndctrlpipe(chip->dev, 0), UAC_SET_CUR,
  692. USB_RECIP_INTERFACE | USB_TYPE_CLASS | USB_DIR_OUT,
  693. validx << 8, snd_usb_ctrl_intf(chip) | (id << 8),
  694. value, val_len);
  695. up_read(&mixer->chip->shutdown_rwsem);
  696. if (err < 0)
  697. return err;
  698. pval->cached_value = new_val;
  699. pval->is_cached = 1;
  700. changed = 1;
  701. }
  702. return changed;
  703. }
  704. static int snd_ftu_create_effect_switch(struct usb_mixer_interface *mixer,
  705. int validx, int bUnitID)
  706. {
  707. static struct snd_kcontrol_new template = {
  708. .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
  709. .name = "Effect Program Switch",
  710. .index = 0,
  711. .access = SNDRV_CTL_ELEM_ACCESS_READWRITE,
  712. .info = snd_ftu_eff_switch_info,
  713. .get = snd_ftu_eff_switch_get,
  714. .put = snd_ftu_eff_switch_put
  715. };
  716. int err;
  717. struct snd_kcontrol *kctl;
  718. struct snd_ftu_eff_switch_priv_val *pval;
  719. pval = kzalloc(sizeof(*pval), GFP_KERNEL);
  720. if (!pval)
  721. return -ENOMEM;
  722. pval->cached_value = 0;
  723. pval->is_cached = 0;
  724. pval->mixer = mixer;
  725. pval->bUnitID = bUnitID;
  726. pval->validx = validx;
  727. template.private_value = (unsigned long) pval;
  728. kctl = snd_ctl_new1(&template, mixer->chip);
  729. if (!kctl) {
  730. kfree(pval);
  731. return -ENOMEM;
  732. }
  733. err = snd_ctl_add(mixer->chip->card, kctl);
  734. if (err < 0)
  735. return err;
  736. return 0;
  737. }
  738. /* Create volume controls for FTU devices*/
  739. static int snd_ftu_create_volume_ctls(struct usb_mixer_interface *mixer)
  740. {
  741. char name[64];
  742. unsigned int control, cmask;
  743. int in, out, err;
  744. const unsigned int id = 5;
  745. const int val_type = USB_MIXER_S16;
  746. for (out = 0; out < 8; out++) {
  747. control = out + 1;
  748. for (in = 0; in < 8; in++) {
  749. cmask = 1 << in;
  750. snprintf(name, sizeof(name),
  751. "AIn%d - Out%d Capture Volume",
  752. in + 1, out + 1);
  753. err = snd_create_std_mono_ctl(mixer, id, control,
  754. cmask, val_type, name,
  755. &snd_usb_mixer_vol_tlv);
  756. if (err < 0)
  757. return err;
  758. }
  759. for (in = 8; in < 16; in++) {
  760. cmask = 1 << in;
  761. snprintf(name, sizeof(name),
  762. "DIn%d - Out%d Playback Volume",
  763. in - 7, out + 1);
  764. err = snd_create_std_mono_ctl(mixer, id, control,
  765. cmask, val_type, name,
  766. &snd_usb_mixer_vol_tlv);
  767. if (err < 0)
  768. return err;
  769. }
  770. }
  771. return 0;
  772. }
  773. /* This control needs a volume quirk, see mixer.c */
  774. static int snd_ftu_create_effect_volume_ctl(struct usb_mixer_interface *mixer)
  775. {
  776. static const char name[] = "Effect Volume";
  777. const unsigned int id = 6;
  778. const int val_type = USB_MIXER_U8;
  779. const unsigned int control = 2;
  780. const unsigned int cmask = 0;
  781. return snd_create_std_mono_ctl(mixer, id, control, cmask, val_type,
  782. name, snd_usb_mixer_vol_tlv);
  783. }
  784. /* This control needs a volume quirk, see mixer.c */
  785. static int snd_ftu_create_effect_duration_ctl(struct usb_mixer_interface *mixer)
  786. {
  787. static const char name[] = "Effect Duration";
  788. const unsigned int id = 6;
  789. const int val_type = USB_MIXER_S16;
  790. const unsigned int control = 3;
  791. const unsigned int cmask = 0;
  792. return snd_create_std_mono_ctl(mixer, id, control, cmask, val_type,
  793. name, snd_usb_mixer_vol_tlv);
  794. }
  795. /* This control needs a volume quirk, see mixer.c */
  796. static int snd_ftu_create_effect_feedback_ctl(struct usb_mixer_interface *mixer)
  797. {
  798. static const char name[] = "Effect Feedback Volume";
  799. const unsigned int id = 6;
  800. const int val_type = USB_MIXER_U8;
  801. const unsigned int control = 4;
  802. const unsigned int cmask = 0;
  803. return snd_create_std_mono_ctl(mixer, id, control, cmask, val_type,
  804. name, NULL);
  805. }
  806. static int snd_ftu_create_effect_return_ctls(struct usb_mixer_interface *mixer)
  807. {
  808. unsigned int cmask;
  809. int err, ch;
  810. char name[48];
  811. const unsigned int id = 7;
  812. const int val_type = USB_MIXER_S16;
  813. const unsigned int control = 7;
  814. for (ch = 0; ch < 4; ++ch) {
  815. cmask = 1 << ch;
  816. snprintf(name, sizeof(name),
  817. "Effect Return %d Volume", ch + 1);
  818. err = snd_create_std_mono_ctl(mixer, id, control,
  819. cmask, val_type, name,
  820. snd_usb_mixer_vol_tlv);
  821. if (err < 0)
  822. return err;
  823. }
  824. return 0;
  825. }
  826. static int snd_ftu_create_effect_send_ctls(struct usb_mixer_interface *mixer)
  827. {
  828. unsigned int cmask;
  829. int err, ch;
  830. char name[48];
  831. const unsigned int id = 5;
  832. const int val_type = USB_MIXER_S16;
  833. const unsigned int control = 9;
  834. for (ch = 0; ch < 8; ++ch) {
  835. cmask = 1 << ch;
  836. snprintf(name, sizeof(name),
  837. "Effect Send AIn%d Volume", ch + 1);
  838. err = snd_create_std_mono_ctl(mixer, id, control, cmask,
  839. val_type, name,
  840. snd_usb_mixer_vol_tlv);
  841. if (err < 0)
  842. return err;
  843. }
  844. for (ch = 8; ch < 16; ++ch) {
  845. cmask = 1 << ch;
  846. snprintf(name, sizeof(name),
  847. "Effect Send DIn%d Volume", ch - 7);
  848. err = snd_create_std_mono_ctl(mixer, id, control, cmask,
  849. val_type, name,
  850. snd_usb_mixer_vol_tlv);
  851. if (err < 0)
  852. return err;
  853. }
  854. return 0;
  855. }
  856. static int snd_ftu_create_mixer(struct usb_mixer_interface *mixer)
  857. {
  858. int err;
  859. err = snd_ftu_create_volume_ctls(mixer);
  860. if (err < 0)
  861. return err;
  862. err = snd_ftu_create_effect_switch(mixer, 1, 6);
  863. if (err < 0)
  864. return err;
  865. err = snd_ftu_create_effect_volume_ctl(mixer);
  866. if (err < 0)
  867. return err;
  868. err = snd_ftu_create_effect_duration_ctl(mixer);
  869. if (err < 0)
  870. return err;
  871. err = snd_ftu_create_effect_feedback_ctl(mixer);
  872. if (err < 0)
  873. return err;
  874. err = snd_ftu_create_effect_return_ctls(mixer);
  875. if (err < 0)
  876. return err;
  877. err = snd_ftu_create_effect_send_ctls(mixer);
  878. if (err < 0)
  879. return err;
  880. return 0;
  881. }
  882. void snd_emuusb_set_samplerate(struct snd_usb_audio *chip,
  883. unsigned char samplerate_id)
  884. {
  885. struct usb_mixer_interface *mixer;
  886. struct usb_mixer_elem_info *cval;
  887. int unitid = 12; /* SamleRate ExtensionUnit ID */
  888. list_for_each_entry(mixer, &chip->mixer_list, list) {
  889. cval = mixer->id_elems[unitid];
  890. if (cval) {
  891. snd_usb_mixer_set_ctl_value(cval, UAC_SET_CUR,
  892. cval->control << 8,
  893. samplerate_id);
  894. snd_usb_mixer_notify_id(mixer, unitid);
  895. }
  896. break;
  897. }
  898. }
  899. /* M-Audio Fast Track C400/C600 */
  900. /* C400/C600 volume controls, this control needs a volume quirk, see mixer.c */
  901. static int snd_c400_create_vol_ctls(struct usb_mixer_interface *mixer)
  902. {
  903. char name[64];
  904. unsigned int cmask, offset;
  905. int out, chan, err;
  906. int num_outs = 0;
  907. int num_ins = 0;
  908. const unsigned int id = 0x40;
  909. const int val_type = USB_MIXER_S16;
  910. const int control = 1;
  911. switch (mixer->chip->usb_id) {
  912. case USB_ID(0x0763, 0x2030):
  913. num_outs = 6;
  914. num_ins = 4;
  915. break;
  916. case USB_ID(0x0763, 0x2031):
  917. num_outs = 8;
  918. num_ins = 6;
  919. break;
  920. }
  921. for (chan = 0; chan < num_outs + num_ins; chan++) {
  922. for (out = 0; out < num_outs; out++) {
  923. if (chan < num_outs) {
  924. snprintf(name, sizeof(name),
  925. "PCM%d-Out%d Playback Volume",
  926. chan + 1, out + 1);
  927. } else {
  928. snprintf(name, sizeof(name),
  929. "In%d-Out%d Playback Volume",
  930. chan - num_outs + 1, out + 1);
  931. }
  932. cmask = (out == 0) ? 0 : 1 << (out - 1);
  933. offset = chan * num_outs;
  934. err = snd_create_std_mono_ctl_offset(mixer, id, control,
  935. cmask, val_type, offset, name,
  936. &snd_usb_mixer_vol_tlv);
  937. if (err < 0)
  938. return err;
  939. }
  940. }
  941. return 0;
  942. }
  943. /* This control needs a volume quirk, see mixer.c */
  944. static int snd_c400_create_effect_volume_ctl(struct usb_mixer_interface *mixer)
  945. {
  946. static const char name[] = "Effect Volume";
  947. const unsigned int id = 0x43;
  948. const int val_type = USB_MIXER_U8;
  949. const unsigned int control = 3;
  950. const unsigned int cmask = 0;
  951. return snd_create_std_mono_ctl(mixer, id, control, cmask, val_type,
  952. name, snd_usb_mixer_vol_tlv);
  953. }
  954. /* This control needs a volume quirk, see mixer.c */
  955. static int snd_c400_create_effect_duration_ctl(struct usb_mixer_interface *mixer)
  956. {
  957. static const char name[] = "Effect Duration";
  958. const unsigned int id = 0x43;
  959. const int val_type = USB_MIXER_S16;
  960. const unsigned int control = 4;
  961. const unsigned int cmask = 0;
  962. return snd_create_std_mono_ctl(mixer, id, control, cmask, val_type,
  963. name, snd_usb_mixer_vol_tlv);
  964. }
  965. /* This control needs a volume quirk, see mixer.c */
  966. static int snd_c400_create_effect_feedback_ctl(struct usb_mixer_interface *mixer)
  967. {
  968. static const char name[] = "Effect Feedback Volume";
  969. const unsigned int id = 0x43;
  970. const int val_type = USB_MIXER_U8;
  971. const unsigned int control = 5;
  972. const unsigned int cmask = 0;
  973. return snd_create_std_mono_ctl(mixer, id, control, cmask, val_type,
  974. name, NULL);
  975. }
  976. static int snd_c400_create_effect_vol_ctls(struct usb_mixer_interface *mixer)
  977. {
  978. char name[64];
  979. unsigned int cmask;
  980. int chan, err;
  981. int num_outs = 0;
  982. int num_ins = 0;
  983. const unsigned int id = 0x42;
  984. const int val_type = USB_MIXER_S16;
  985. const int control = 1;
  986. switch (mixer->chip->usb_id) {
  987. case USB_ID(0x0763, 0x2030):
  988. num_outs = 6;
  989. num_ins = 4;
  990. break;
  991. case USB_ID(0x0763, 0x2031):
  992. num_outs = 8;
  993. num_ins = 6;
  994. break;
  995. }
  996. for (chan = 0; chan < num_outs + num_ins; chan++) {
  997. if (chan < num_outs) {
  998. snprintf(name, sizeof(name),
  999. "Effect Send DOut%d",
  1000. chan + 1);
  1001. } else {
  1002. snprintf(name, sizeof(name),
  1003. "Effect Send AIn%d",
  1004. chan - num_outs + 1);
  1005. }
  1006. cmask = (chan == 0) ? 0 : 1 << (chan - 1);
  1007. err = snd_create_std_mono_ctl(mixer, id, control,
  1008. cmask, val_type, name,
  1009. &snd_usb_mixer_vol_tlv);
  1010. if (err < 0)
  1011. return err;
  1012. }
  1013. return 0;
  1014. }
  1015. static int snd_c400_create_effect_ret_vol_ctls(struct usb_mixer_interface *mixer)
  1016. {
  1017. char name[64];
  1018. unsigned int cmask;
  1019. int chan, err;
  1020. int num_outs = 0;
  1021. int offset = 0;
  1022. const unsigned int id = 0x40;
  1023. const int val_type = USB_MIXER_S16;
  1024. const int control = 1;
  1025. switch (mixer->chip->usb_id) {
  1026. case USB_ID(0x0763, 0x2030):
  1027. num_outs = 6;
  1028. offset = 0x3c;
  1029. /* { 0x3c, 0x43, 0x3e, 0x45, 0x40, 0x47 } */
  1030. break;
  1031. case USB_ID(0x0763, 0x2031):
  1032. num_outs = 8;
  1033. offset = 0x70;
  1034. /* { 0x70, 0x79, 0x72, 0x7b, 0x74, 0x7d, 0x76, 0x7f } */
  1035. break;
  1036. }
  1037. for (chan = 0; chan < num_outs; chan++) {
  1038. snprintf(name, sizeof(name),
  1039. "Effect Return %d",
  1040. chan + 1);
  1041. cmask = (chan == 0) ? 0 :
  1042. 1 << (chan + (chan % 2) * num_outs - 1);
  1043. err = snd_create_std_mono_ctl_offset(mixer, id, control,
  1044. cmask, val_type, offset, name,
  1045. &snd_usb_mixer_vol_tlv);
  1046. if (err < 0)
  1047. return err;
  1048. }
  1049. return 0;
  1050. }
  1051. static int snd_c400_create_mixer(struct usb_mixer_interface *mixer)
  1052. {
  1053. int err;
  1054. err = snd_c400_create_vol_ctls(mixer);
  1055. if (err < 0)
  1056. return err;
  1057. err = snd_c400_create_effect_vol_ctls(mixer);
  1058. if (err < 0)
  1059. return err;
  1060. err = snd_c400_create_effect_ret_vol_ctls(mixer);
  1061. if (err < 0)
  1062. return err;
  1063. err = snd_ftu_create_effect_switch(mixer, 2, 0x43);
  1064. if (err < 0)
  1065. return err;
  1066. err = snd_c400_create_effect_volume_ctl(mixer);
  1067. if (err < 0)
  1068. return err;
  1069. err = snd_c400_create_effect_duration_ctl(mixer);
  1070. if (err < 0)
  1071. return err;
  1072. err = snd_c400_create_effect_feedback_ctl(mixer);
  1073. if (err < 0)
  1074. return err;
  1075. return 0;
  1076. }
  1077. /*
  1078. * The mixer units for Ebox-44 are corrupt, and even where they
  1079. * are valid they presents mono controls as L and R channels of
  1080. * stereo. So we provide a good mixer here.
  1081. */
  1082. static struct std_mono_table ebox44_table[] = {
  1083. {
  1084. .unitid = 4,
  1085. .control = 1,
  1086. .cmask = 0x0,
  1087. .val_type = USB_MIXER_INV_BOOLEAN,
  1088. .name = "Headphone Playback Switch"
  1089. },
  1090. {
  1091. .unitid = 4,
  1092. .control = 2,
  1093. .cmask = 0x1,
  1094. .val_type = USB_MIXER_S16,
  1095. .name = "Headphone A Mix Playback Volume"
  1096. },
  1097. {
  1098. .unitid = 4,
  1099. .control = 2,
  1100. .cmask = 0x2,
  1101. .val_type = USB_MIXER_S16,
  1102. .name = "Headphone B Mix Playback Volume"
  1103. },
  1104. {
  1105. .unitid = 7,
  1106. .control = 1,
  1107. .cmask = 0x0,
  1108. .val_type = USB_MIXER_INV_BOOLEAN,
  1109. .name = "Output Playback Switch"
  1110. },
  1111. {
  1112. .unitid = 7,
  1113. .control = 2,
  1114. .cmask = 0x1,
  1115. .val_type = USB_MIXER_S16,
  1116. .name = "Output A Playback Volume"
  1117. },
  1118. {
  1119. .unitid = 7,
  1120. .control = 2,
  1121. .cmask = 0x2,
  1122. .val_type = USB_MIXER_S16,
  1123. .name = "Output B Playback Volume"
  1124. },
  1125. {
  1126. .unitid = 10,
  1127. .control = 1,
  1128. .cmask = 0x0,
  1129. .val_type = USB_MIXER_INV_BOOLEAN,
  1130. .name = "Input Capture Switch"
  1131. },
  1132. {
  1133. .unitid = 10,
  1134. .control = 2,
  1135. .cmask = 0x1,
  1136. .val_type = USB_MIXER_S16,
  1137. .name = "Input A Capture Volume"
  1138. },
  1139. {
  1140. .unitid = 10,
  1141. .control = 2,
  1142. .cmask = 0x2,
  1143. .val_type = USB_MIXER_S16,
  1144. .name = "Input B Capture Volume"
  1145. },
  1146. {}
  1147. };
  1148. int snd_usb_mixer_apply_create_quirk(struct usb_mixer_interface *mixer)
  1149. {
  1150. int err = 0;
  1151. struct snd_info_entry *entry;
  1152. if ((err = snd_usb_soundblaster_remote_init(mixer)) < 0)
  1153. return err;
  1154. switch (mixer->chip->usb_id) {
  1155. case USB_ID(0x041e, 0x3020):
  1156. case USB_ID(0x041e, 0x3040):
  1157. case USB_ID(0x041e, 0x3042):
  1158. case USB_ID(0x041e, 0x30df):
  1159. case USB_ID(0x041e, 0x3048):
  1160. err = snd_audigy2nx_controls_create(mixer);
  1161. if (err < 0)
  1162. break;
  1163. if (!snd_card_proc_new(mixer->chip->card, "audigy2nx", &entry))
  1164. snd_info_set_text_ops(entry, mixer,
  1165. snd_audigy2nx_proc_read);
  1166. break;
  1167. case USB_ID(0x0763, 0x2030): /* M-Audio Fast Track C400 */
  1168. case USB_ID(0x0763, 0x2031): /* M-Audio Fast Track C400 */
  1169. err = snd_c400_create_mixer(mixer);
  1170. break;
  1171. case USB_ID(0x0763, 0x2080): /* M-Audio Fast Track Ultra */
  1172. case USB_ID(0x0763, 0x2081): /* M-Audio Fast Track Ultra 8R */
  1173. err = snd_ftu_create_mixer(mixer);
  1174. break;
  1175. case USB_ID(0x0b05, 0x1739): /* ASUS Xonar U1 */
  1176. case USB_ID(0x0b05, 0x1743): /* ASUS Xonar U1 (2) */
  1177. case USB_ID(0x0b05, 0x17a0): /* ASUS Xonar U3 */
  1178. err = snd_xonar_u1_controls_create(mixer);
  1179. break;
  1180. case USB_ID(0x17cc, 0x1011): /* Traktor Audio 6 */
  1181. err = snd_nativeinstruments_create_mixer(mixer,
  1182. snd_nativeinstruments_ta6_mixers,
  1183. ARRAY_SIZE(snd_nativeinstruments_ta6_mixers));
  1184. break;
  1185. case USB_ID(0x17cc, 0x1021): /* Traktor Audio 10 */
  1186. err = snd_nativeinstruments_create_mixer(mixer,
  1187. snd_nativeinstruments_ta10_mixers,
  1188. ARRAY_SIZE(snd_nativeinstruments_ta10_mixers));
  1189. break;
  1190. case USB_ID(0x200c, 0x1018): /* Electrix Ebox-44 */
  1191. /* detection is disabled in mixer_maps.c */
  1192. err = snd_create_std_mono_table(mixer, ebox44_table);
  1193. break;
  1194. }
  1195. return err;
  1196. }
  1197. void snd_usb_mixer_rc_memory_change(struct usb_mixer_interface *mixer,
  1198. int unitid)
  1199. {
  1200. if (!mixer->rc_cfg)
  1201. return;
  1202. /* unit ids specific to Extigy/Audigy 2 NX: */
  1203. switch (unitid) {
  1204. case 0: /* remote control */
  1205. mixer->rc_urb->dev = mixer->chip->dev;
  1206. usb_submit_urb(mixer->rc_urb, GFP_ATOMIC);
  1207. break;
  1208. case 4: /* digital in jack */
  1209. case 7: /* line in jacks */
  1210. case 19: /* speaker out jacks */
  1211. case 20: /* headphones out jack */
  1212. break;
  1213. /* live24ext: 4 = line-in jack */
  1214. case 3: /* hp-out jack (may actuate Mute) */
  1215. if (mixer->chip->usb_id == USB_ID(0x041e, 0x3040) ||
  1216. mixer->chip->usb_id == USB_ID(0x041e, 0x3048))
  1217. snd_usb_mixer_notify_id(mixer, mixer->rc_cfg->mute_mixer_id);
  1218. break;
  1219. default:
  1220. snd_printd(KERN_DEBUG "memory change in unknown unit %d\n", unitid);
  1221. break;
  1222. }
  1223. }