mixer_quirks.c 28 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119
  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(struct usb_mixer_interface *mixer,
  60. unsigned int unitid,
  61. unsigned int control,
  62. unsigned int cmask,
  63. int val_type,
  64. const char *name,
  65. snd_kcontrol_tlv_rw_t *tlv_callback)
  66. {
  67. int err;
  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. cval->id = unitid;
  74. cval->mixer = mixer;
  75. cval->val_type = val_type;
  76. cval->channels = 1;
  77. cval->control = control;
  78. cval->cmask = cmask;
  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 = 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. err = snd_usb_mixer_add_control(mixer, kctl);
  104. if (err < 0)
  105. return err;
  106. return 0;
  107. }
  108. /*
  109. * Create a set of standard UAC controls from a table
  110. */
  111. static int snd_create_std_mono_table(struct usb_mixer_interface *mixer,
  112. struct std_mono_table *t)
  113. {
  114. int err;
  115. while (t->name != NULL) {
  116. err = snd_create_std_mono_ctl(mixer, t->unitid, t->control,
  117. t->cmask, t->val_type, t->name, t->tlv_callback);
  118. if (err < 0)
  119. return err;
  120. t++;
  121. }
  122. return 0;
  123. }
  124. /*
  125. * Sound Blaster remote control configuration
  126. *
  127. * format of remote control data:
  128. * Extigy: xx 00
  129. * Audigy 2 NX: 06 80 xx 00 00 00
  130. * Live! 24-bit: 06 80 xx yy 22 83
  131. */
  132. static const struct rc_config {
  133. u32 usb_id;
  134. u8 offset;
  135. u8 length;
  136. u8 packet_length;
  137. u8 min_packet_length; /* minimum accepted length of the URB result */
  138. u8 mute_mixer_id;
  139. u32 mute_code;
  140. } rc_configs[] = {
  141. { USB_ID(0x041e, 0x3000), 0, 1, 2, 1, 18, 0x0013 }, /* Extigy */
  142. { USB_ID(0x041e, 0x3020), 2, 1, 6, 6, 18, 0x0013 }, /* Audigy 2 NX */
  143. { USB_ID(0x041e, 0x3040), 2, 2, 6, 6, 2, 0x6e91 }, /* Live! 24-bit */
  144. { USB_ID(0x041e, 0x3042), 0, 1, 1, 1, 1, 0x000d }, /* Usb X-Fi S51 */
  145. { USB_ID(0x041e, 0x30df), 0, 1, 1, 1, 1, 0x000d }, /* Usb X-Fi S51 Pro */
  146. { USB_ID(0x041e, 0x3048), 2, 2, 6, 6, 2, 0x6e91 }, /* Toshiba SB0500 */
  147. };
  148. static void snd_usb_soundblaster_remote_complete(struct urb *urb)
  149. {
  150. struct usb_mixer_interface *mixer = urb->context;
  151. const struct rc_config *rc = mixer->rc_cfg;
  152. u32 code;
  153. if (urb->status < 0 || urb->actual_length < rc->min_packet_length)
  154. return;
  155. code = mixer->rc_buffer[rc->offset];
  156. if (rc->length == 2)
  157. code |= mixer->rc_buffer[rc->offset + 1] << 8;
  158. /* the Mute button actually changes the mixer control */
  159. if (code == rc->mute_code)
  160. snd_usb_mixer_notify_id(mixer, rc->mute_mixer_id);
  161. mixer->rc_code = code;
  162. wmb();
  163. wake_up(&mixer->rc_waitq);
  164. }
  165. static long snd_usb_sbrc_hwdep_read(struct snd_hwdep *hw, char __user *buf,
  166. long count, loff_t *offset)
  167. {
  168. struct usb_mixer_interface *mixer = hw->private_data;
  169. int err;
  170. u32 rc_code;
  171. if (count != 1 && count != 4)
  172. return -EINVAL;
  173. err = wait_event_interruptible(mixer->rc_waitq,
  174. (rc_code = xchg(&mixer->rc_code, 0)) != 0);
  175. if (err == 0) {
  176. if (count == 1)
  177. err = put_user(rc_code, buf);
  178. else
  179. err = put_user(rc_code, (u32 __user *)buf);
  180. }
  181. return err < 0 ? err : count;
  182. }
  183. static unsigned int snd_usb_sbrc_hwdep_poll(struct snd_hwdep *hw, struct file *file,
  184. poll_table *wait)
  185. {
  186. struct usb_mixer_interface *mixer = hw->private_data;
  187. poll_wait(file, &mixer->rc_waitq, wait);
  188. return mixer->rc_code ? POLLIN | POLLRDNORM : 0;
  189. }
  190. static int snd_usb_soundblaster_remote_init(struct usb_mixer_interface *mixer)
  191. {
  192. struct snd_hwdep *hwdep;
  193. int err, len, i;
  194. for (i = 0; i < ARRAY_SIZE(rc_configs); ++i)
  195. if (rc_configs[i].usb_id == mixer->chip->usb_id)
  196. break;
  197. if (i >= ARRAY_SIZE(rc_configs))
  198. return 0;
  199. mixer->rc_cfg = &rc_configs[i];
  200. len = mixer->rc_cfg->packet_length;
  201. init_waitqueue_head(&mixer->rc_waitq);
  202. err = snd_hwdep_new(mixer->chip->card, "SB remote control", 0, &hwdep);
  203. if (err < 0)
  204. return err;
  205. snprintf(hwdep->name, sizeof(hwdep->name),
  206. "%s remote control", mixer->chip->card->shortname);
  207. hwdep->iface = SNDRV_HWDEP_IFACE_SB_RC;
  208. hwdep->private_data = mixer;
  209. hwdep->ops.read = snd_usb_sbrc_hwdep_read;
  210. hwdep->ops.poll = snd_usb_sbrc_hwdep_poll;
  211. hwdep->exclusive = 1;
  212. mixer->rc_urb = usb_alloc_urb(0, GFP_KERNEL);
  213. if (!mixer->rc_urb)
  214. return -ENOMEM;
  215. mixer->rc_setup_packet = kmalloc(sizeof(*mixer->rc_setup_packet), GFP_KERNEL);
  216. if (!mixer->rc_setup_packet) {
  217. usb_free_urb(mixer->rc_urb);
  218. mixer->rc_urb = NULL;
  219. return -ENOMEM;
  220. }
  221. mixer->rc_setup_packet->bRequestType =
  222. USB_DIR_IN | USB_TYPE_CLASS | USB_RECIP_INTERFACE;
  223. mixer->rc_setup_packet->bRequest = UAC_GET_MEM;
  224. mixer->rc_setup_packet->wValue = cpu_to_le16(0);
  225. mixer->rc_setup_packet->wIndex = cpu_to_le16(0);
  226. mixer->rc_setup_packet->wLength = cpu_to_le16(len);
  227. usb_fill_control_urb(mixer->rc_urb, mixer->chip->dev,
  228. usb_rcvctrlpipe(mixer->chip->dev, 0),
  229. (u8*)mixer->rc_setup_packet, mixer->rc_buffer, len,
  230. snd_usb_soundblaster_remote_complete, mixer);
  231. return 0;
  232. }
  233. #define snd_audigy2nx_led_info snd_ctl_boolean_mono_info
  234. static int snd_audigy2nx_led_get(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
  235. {
  236. struct usb_mixer_interface *mixer = snd_kcontrol_chip(kcontrol);
  237. int index = kcontrol->private_value;
  238. ucontrol->value.integer.value[0] = mixer->audigy2nx_leds[index];
  239. return 0;
  240. }
  241. static int snd_audigy2nx_led_put(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
  242. {
  243. struct usb_mixer_interface *mixer = snd_kcontrol_chip(kcontrol);
  244. int index = kcontrol->private_value;
  245. int value = ucontrol->value.integer.value[0];
  246. int err, changed;
  247. if (value > 1)
  248. return -EINVAL;
  249. changed = value != mixer->audigy2nx_leds[index];
  250. if (mixer->chip->usb_id == USB_ID(0x041e, 0x3042))
  251. err = snd_usb_ctl_msg(mixer->chip->dev,
  252. usb_sndctrlpipe(mixer->chip->dev, 0), 0x24,
  253. USB_DIR_OUT | USB_TYPE_VENDOR | USB_RECIP_OTHER,
  254. !value, 0, NULL, 0);
  255. /* USB X-Fi S51 Pro */
  256. if (mixer->chip->usb_id == USB_ID(0x041e, 0x30df))
  257. err = snd_usb_ctl_msg(mixer->chip->dev,
  258. usb_sndctrlpipe(mixer->chip->dev, 0), 0x24,
  259. USB_DIR_OUT | USB_TYPE_VENDOR | USB_RECIP_OTHER,
  260. !value, 0, NULL, 0);
  261. else
  262. err = snd_usb_ctl_msg(mixer->chip->dev,
  263. usb_sndctrlpipe(mixer->chip->dev, 0), 0x24,
  264. USB_DIR_OUT | USB_TYPE_VENDOR | USB_RECIP_OTHER,
  265. value, index + 2, NULL, 0);
  266. if (err < 0)
  267. return err;
  268. mixer->audigy2nx_leds[index] = value;
  269. return changed;
  270. }
  271. static struct snd_kcontrol_new snd_audigy2nx_controls[] = {
  272. {
  273. .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
  274. .name = "CMSS LED Switch",
  275. .info = snd_audigy2nx_led_info,
  276. .get = snd_audigy2nx_led_get,
  277. .put = snd_audigy2nx_led_put,
  278. .private_value = 0,
  279. },
  280. {
  281. .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
  282. .name = "Power LED Switch",
  283. .info = snd_audigy2nx_led_info,
  284. .get = snd_audigy2nx_led_get,
  285. .put = snd_audigy2nx_led_put,
  286. .private_value = 1,
  287. },
  288. {
  289. .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
  290. .name = "Dolby Digital LED Switch",
  291. .info = snd_audigy2nx_led_info,
  292. .get = snd_audigy2nx_led_get,
  293. .put = snd_audigy2nx_led_put,
  294. .private_value = 2,
  295. },
  296. };
  297. static int snd_audigy2nx_controls_create(struct usb_mixer_interface *mixer)
  298. {
  299. int i, err;
  300. for (i = 0; i < ARRAY_SIZE(snd_audigy2nx_controls); ++i) {
  301. /* USB X-Fi S51 doesn't have a CMSS LED */
  302. if ((mixer->chip->usb_id == USB_ID(0x041e, 0x3042)) && i == 0)
  303. continue;
  304. /* USB X-Fi S51 Pro doesn't have one either */
  305. if ((mixer->chip->usb_id == USB_ID(0x041e, 0x30df)) && i == 0)
  306. continue;
  307. if (i > 1 && /* Live24ext has 2 LEDs only */
  308. (mixer->chip->usb_id == USB_ID(0x041e, 0x3040) ||
  309. mixer->chip->usb_id == USB_ID(0x041e, 0x3042) ||
  310. mixer->chip->usb_id == USB_ID(0x041e, 0x30df) ||
  311. mixer->chip->usb_id == USB_ID(0x041e, 0x3048)))
  312. break;
  313. err = snd_ctl_add(mixer->chip->card,
  314. snd_ctl_new1(&snd_audigy2nx_controls[i], mixer));
  315. if (err < 0)
  316. return err;
  317. }
  318. mixer->audigy2nx_leds[1] = 1; /* Power LED is on by default */
  319. return 0;
  320. }
  321. static void snd_audigy2nx_proc_read(struct snd_info_entry *entry,
  322. struct snd_info_buffer *buffer)
  323. {
  324. static const struct sb_jack {
  325. int unitid;
  326. const char *name;
  327. } jacks_audigy2nx[] = {
  328. {4, "dig in "},
  329. {7, "line in"},
  330. {19, "spk out"},
  331. {20, "hph out"},
  332. {-1, NULL}
  333. }, jacks_live24ext[] = {
  334. {4, "line in"}, /* &1=Line, &2=Mic*/
  335. {3, "hph out"}, /* headphones */
  336. {0, "RC "}, /* last command, 6 bytes see rc_config above */
  337. {-1, NULL}
  338. };
  339. const struct sb_jack *jacks;
  340. struct usb_mixer_interface *mixer = entry->private_data;
  341. int i, err;
  342. u8 buf[3];
  343. snd_iprintf(buffer, "%s jacks\n\n", mixer->chip->card->shortname);
  344. if (mixer->chip->usb_id == USB_ID(0x041e, 0x3020))
  345. jacks = jacks_audigy2nx;
  346. else if (mixer->chip->usb_id == USB_ID(0x041e, 0x3040) ||
  347. mixer->chip->usb_id == USB_ID(0x041e, 0x3048))
  348. jacks = jacks_live24ext;
  349. else
  350. return;
  351. for (i = 0; jacks[i].name; ++i) {
  352. snd_iprintf(buffer, "%s: ", jacks[i].name);
  353. err = snd_usb_ctl_msg(mixer->chip->dev,
  354. usb_rcvctrlpipe(mixer->chip->dev, 0),
  355. UAC_GET_MEM, USB_DIR_IN | USB_TYPE_CLASS |
  356. USB_RECIP_INTERFACE, 0,
  357. jacks[i].unitid << 8, buf, 3);
  358. if (err == 3 && (buf[0] == 3 || buf[0] == 6))
  359. snd_iprintf(buffer, "%02x %02x\n", buf[1], buf[2]);
  360. else
  361. snd_iprintf(buffer, "?\n");
  362. }
  363. }
  364. static int snd_xonar_u1_switch_get(struct snd_kcontrol *kcontrol,
  365. struct snd_ctl_elem_value *ucontrol)
  366. {
  367. struct usb_mixer_interface *mixer = snd_kcontrol_chip(kcontrol);
  368. ucontrol->value.integer.value[0] = !!(mixer->xonar_u1_status & 0x02);
  369. return 0;
  370. }
  371. static int snd_xonar_u1_switch_put(struct snd_kcontrol *kcontrol,
  372. struct snd_ctl_elem_value *ucontrol)
  373. {
  374. struct usb_mixer_interface *mixer = snd_kcontrol_chip(kcontrol);
  375. u8 old_status, new_status;
  376. int err, changed;
  377. old_status = mixer->xonar_u1_status;
  378. if (ucontrol->value.integer.value[0])
  379. new_status = old_status | 0x02;
  380. else
  381. new_status = old_status & ~0x02;
  382. changed = new_status != old_status;
  383. err = snd_usb_ctl_msg(mixer->chip->dev,
  384. usb_sndctrlpipe(mixer->chip->dev, 0), 0x08,
  385. USB_DIR_OUT | USB_TYPE_VENDOR | USB_RECIP_OTHER,
  386. 50, 0, &new_status, 1);
  387. if (err < 0)
  388. return err;
  389. mixer->xonar_u1_status = new_status;
  390. return changed;
  391. }
  392. static struct snd_kcontrol_new snd_xonar_u1_output_switch = {
  393. .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
  394. .name = "Digital Playback Switch",
  395. .info = snd_ctl_boolean_mono_info,
  396. .get = snd_xonar_u1_switch_get,
  397. .put = snd_xonar_u1_switch_put,
  398. };
  399. static int snd_xonar_u1_controls_create(struct usb_mixer_interface *mixer)
  400. {
  401. int err;
  402. err = snd_ctl_add(mixer->chip->card,
  403. snd_ctl_new1(&snd_xonar_u1_output_switch, mixer));
  404. if (err < 0)
  405. return err;
  406. mixer->xonar_u1_status = 0x05;
  407. return 0;
  408. }
  409. /* Native Instruments device quirks */
  410. #define _MAKE_NI_CONTROL(bRequest,wIndex) ((bRequest) << 16 | (wIndex))
  411. static int snd_nativeinstruments_control_get(struct snd_kcontrol *kcontrol,
  412. struct snd_ctl_elem_value *ucontrol)
  413. {
  414. struct usb_mixer_interface *mixer = snd_kcontrol_chip(kcontrol);
  415. struct usb_device *dev = mixer->chip->dev;
  416. u8 bRequest = (kcontrol->private_value >> 16) & 0xff;
  417. u16 wIndex = kcontrol->private_value & 0xffff;
  418. u8 tmp;
  419. int ret = usb_control_msg(dev, usb_rcvctrlpipe(dev, 0), bRequest,
  420. USB_TYPE_VENDOR | USB_RECIP_DEVICE | USB_DIR_IN,
  421. 0, cpu_to_le16(wIndex),
  422. &tmp, sizeof(tmp), 1000);
  423. if (ret < 0) {
  424. snd_printk(KERN_ERR
  425. "unable to issue vendor read request (ret = %d)", ret);
  426. return ret;
  427. }
  428. ucontrol->value.integer.value[0] = tmp;
  429. return 0;
  430. }
  431. static int snd_nativeinstruments_control_put(struct snd_kcontrol *kcontrol,
  432. struct snd_ctl_elem_value *ucontrol)
  433. {
  434. struct usb_mixer_interface *mixer = snd_kcontrol_chip(kcontrol);
  435. struct usb_device *dev = mixer->chip->dev;
  436. u8 bRequest = (kcontrol->private_value >> 16) & 0xff;
  437. u16 wIndex = kcontrol->private_value & 0xffff;
  438. u16 wValue = ucontrol->value.integer.value[0];
  439. int ret = usb_control_msg(dev, usb_sndctrlpipe(dev, 0), bRequest,
  440. USB_TYPE_VENDOR | USB_RECIP_DEVICE | USB_DIR_OUT,
  441. cpu_to_le16(wValue), cpu_to_le16(wIndex),
  442. NULL, 0, 1000);
  443. if (ret < 0) {
  444. snd_printk(KERN_ERR
  445. "unable to issue vendor write request (ret = %d)", ret);
  446. return ret;
  447. }
  448. return 0;
  449. }
  450. static struct snd_kcontrol_new snd_nativeinstruments_ta6_mixers[] = {
  451. {
  452. .name = "Direct Thru Channel A",
  453. .private_value = _MAKE_NI_CONTROL(0x01, 0x03),
  454. },
  455. {
  456. .name = "Direct Thru Channel B",
  457. .private_value = _MAKE_NI_CONTROL(0x01, 0x05),
  458. },
  459. {
  460. .name = "Phono Input Channel A",
  461. .private_value = _MAKE_NI_CONTROL(0x02, 0x03),
  462. },
  463. {
  464. .name = "Phono Input Channel B",
  465. .private_value = _MAKE_NI_CONTROL(0x02, 0x05),
  466. },
  467. };
  468. static struct snd_kcontrol_new snd_nativeinstruments_ta10_mixers[] = {
  469. {
  470. .name = "Direct Thru Channel A",
  471. .private_value = _MAKE_NI_CONTROL(0x01, 0x03),
  472. },
  473. {
  474. .name = "Direct Thru Channel B",
  475. .private_value = _MAKE_NI_CONTROL(0x01, 0x05),
  476. },
  477. {
  478. .name = "Direct Thru Channel C",
  479. .private_value = _MAKE_NI_CONTROL(0x01, 0x07),
  480. },
  481. {
  482. .name = "Direct Thru Channel D",
  483. .private_value = _MAKE_NI_CONTROL(0x01, 0x09),
  484. },
  485. {
  486. .name = "Phono Input Channel A",
  487. .private_value = _MAKE_NI_CONTROL(0x02, 0x03),
  488. },
  489. {
  490. .name = "Phono Input Channel B",
  491. .private_value = _MAKE_NI_CONTROL(0x02, 0x05),
  492. },
  493. {
  494. .name = "Phono Input Channel C",
  495. .private_value = _MAKE_NI_CONTROL(0x02, 0x07),
  496. },
  497. {
  498. .name = "Phono Input Channel D",
  499. .private_value = _MAKE_NI_CONTROL(0x02, 0x09),
  500. },
  501. };
  502. static int snd_nativeinstruments_create_mixer(struct usb_mixer_interface *mixer,
  503. const struct snd_kcontrol_new *kc,
  504. unsigned int count)
  505. {
  506. int i, err = 0;
  507. struct snd_kcontrol_new template = {
  508. .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
  509. .access = SNDRV_CTL_ELEM_ACCESS_READWRITE,
  510. .get = snd_nativeinstruments_control_get,
  511. .put = snd_nativeinstruments_control_put,
  512. .info = snd_ctl_boolean_mono_info,
  513. };
  514. for (i = 0; i < count; i++) {
  515. struct snd_kcontrol *c;
  516. template.name = kc[i].name;
  517. template.private_value = kc[i].private_value;
  518. c = snd_ctl_new1(&template, mixer);
  519. err = snd_ctl_add(mixer->chip->card, c);
  520. if (err < 0)
  521. break;
  522. }
  523. return err;
  524. }
  525. /* M-Audio FastTrack Ultra quirks */
  526. /* FTU Effect switch */
  527. struct snd_ftu_eff_switch_priv_val {
  528. struct usb_mixer_interface *mixer;
  529. int cached_value;
  530. int is_cached;
  531. };
  532. static int snd_ftu_eff_switch_info(struct snd_kcontrol *kcontrol,
  533. struct snd_ctl_elem_info *uinfo)
  534. {
  535. static const char *texts[8] = {"Room 1",
  536. "Room 2",
  537. "Room 3",
  538. "Hall 1",
  539. "Hall 2",
  540. "Plate",
  541. "Delay",
  542. "Echo"
  543. };
  544. uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED;
  545. uinfo->count = 1;
  546. uinfo->value.enumerated.items = 8;
  547. if (uinfo->value.enumerated.item > 7)
  548. uinfo->value.enumerated.item = 7;
  549. strcpy(uinfo->value.enumerated.name,
  550. texts[uinfo->value.enumerated.item]);
  551. return 0;
  552. }
  553. static int snd_ftu_eff_switch_get(struct snd_kcontrol *kctl,
  554. struct snd_ctl_elem_value *ucontrol)
  555. {
  556. struct snd_usb_audio *chip;
  557. struct usb_mixer_interface *mixer;
  558. struct snd_ftu_eff_switch_priv_val *pval;
  559. int err;
  560. unsigned char value[2];
  561. const int id = 6;
  562. const int validx = 1;
  563. const int val_len = 2;
  564. value[0] = 0x00;
  565. value[1] = 0x00;
  566. pval = (struct snd_ftu_eff_switch_priv_val *)
  567. kctl->private_value;
  568. if (pval->is_cached) {
  569. ucontrol->value.enumerated.item[0] = pval->cached_value;
  570. return 0;
  571. }
  572. mixer = (struct usb_mixer_interface *) pval->mixer;
  573. if (snd_BUG_ON(!mixer))
  574. return -EINVAL;
  575. chip = (struct snd_usb_audio *) mixer->chip;
  576. if (snd_BUG_ON(!chip))
  577. return -EINVAL;
  578. err = snd_usb_ctl_msg(chip->dev,
  579. usb_rcvctrlpipe(chip->dev, 0), UAC_GET_CUR,
  580. USB_RECIP_INTERFACE | USB_TYPE_CLASS | USB_DIR_IN,
  581. validx << 8, snd_usb_ctrl_intf(chip) | (id << 8),
  582. value, val_len);
  583. if (err < 0)
  584. return err;
  585. ucontrol->value.enumerated.item[0] = value[0];
  586. pval->cached_value = value[0];
  587. pval->is_cached = 1;
  588. return 0;
  589. }
  590. static int snd_ftu_eff_switch_put(struct snd_kcontrol *kctl,
  591. struct snd_ctl_elem_value *ucontrol)
  592. {
  593. struct snd_usb_audio *chip;
  594. struct snd_ftu_eff_switch_priv_val *pval;
  595. struct usb_mixer_interface *mixer;
  596. int changed, cur_val, err, new_val;
  597. unsigned char value[2];
  598. const int id = 6;
  599. const int validx = 1;
  600. const int val_len = 2;
  601. changed = 0;
  602. pval = (struct snd_ftu_eff_switch_priv_val *)
  603. kctl->private_value;
  604. cur_val = pval->cached_value;
  605. new_val = ucontrol->value.enumerated.item[0];
  606. mixer = (struct usb_mixer_interface *) pval->mixer;
  607. if (snd_BUG_ON(!mixer))
  608. return -EINVAL;
  609. chip = (struct snd_usb_audio *) mixer->chip;
  610. if (snd_BUG_ON(!chip))
  611. return -EINVAL;
  612. if (!pval->is_cached) {
  613. /* Read current value */
  614. err = snd_usb_ctl_msg(chip->dev,
  615. usb_rcvctrlpipe(chip->dev, 0), UAC_GET_CUR,
  616. USB_RECIP_INTERFACE | USB_TYPE_CLASS | USB_DIR_IN,
  617. validx << 8, snd_usb_ctrl_intf(chip) | (id << 8),
  618. value, val_len);
  619. if (err < 0)
  620. return err;
  621. cur_val = value[0];
  622. pval->cached_value = cur_val;
  623. pval->is_cached = 1;
  624. }
  625. /* update value if needed */
  626. if (cur_val != new_val) {
  627. value[0] = new_val;
  628. value[1] = 0;
  629. err = snd_usb_ctl_msg(chip->dev,
  630. usb_sndctrlpipe(chip->dev, 0), UAC_SET_CUR,
  631. USB_RECIP_INTERFACE | USB_TYPE_CLASS | USB_DIR_OUT,
  632. validx << 8, snd_usb_ctrl_intf(chip) | (id << 8),
  633. value, val_len);
  634. if (err < 0)
  635. return err;
  636. pval->cached_value = new_val;
  637. pval->is_cached = 1;
  638. changed = 1;
  639. }
  640. return changed;
  641. }
  642. static int snd_ftu_create_effect_switch(struct usb_mixer_interface *mixer)
  643. {
  644. static struct snd_kcontrol_new template = {
  645. .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
  646. .name = "Effect Program Switch",
  647. .index = 0,
  648. .access = SNDRV_CTL_ELEM_ACCESS_READWRITE,
  649. .info = snd_ftu_eff_switch_info,
  650. .get = snd_ftu_eff_switch_get,
  651. .put = snd_ftu_eff_switch_put
  652. };
  653. int err;
  654. struct snd_kcontrol *kctl;
  655. struct snd_ftu_eff_switch_priv_val *pval;
  656. pval = kzalloc(sizeof(*pval), GFP_KERNEL);
  657. if (!pval)
  658. return -ENOMEM;
  659. pval->cached_value = 0;
  660. pval->is_cached = 0;
  661. pval->mixer = mixer;
  662. template.private_value = (unsigned long) pval;
  663. kctl = snd_ctl_new1(&template, mixer->chip);
  664. if (!kctl) {
  665. kfree(pval);
  666. return -ENOMEM;
  667. }
  668. err = snd_ctl_add(mixer->chip->card, kctl);
  669. if (err < 0)
  670. return err;
  671. return 0;
  672. }
  673. /* Create volume controls for FTU devices*/
  674. static int snd_ftu_create_volume_ctls(struct usb_mixer_interface *mixer)
  675. {
  676. char name[64];
  677. unsigned int control, cmask;
  678. int in, out, err;
  679. const unsigned int id = 5;
  680. const int val_type = USB_MIXER_S16;
  681. for (out = 0; out < 8; out++) {
  682. control = out + 1;
  683. for (in = 0; in < 8; in++) {
  684. cmask = 1 << in;
  685. snprintf(name, sizeof(name),
  686. "AIn%d - Out%d Capture Volume",
  687. in + 1, out + 1);
  688. err = snd_create_std_mono_ctl(mixer, id, control,
  689. cmask, val_type, name,
  690. &snd_usb_mixer_vol_tlv);
  691. if (err < 0)
  692. return err;
  693. }
  694. for (in = 8; in < 16; in++) {
  695. cmask = 1 << in;
  696. snprintf(name, sizeof(name),
  697. "DIn%d - Out%d Playback Volume",
  698. in - 7, out + 1);
  699. err = snd_create_std_mono_ctl(mixer, id, control,
  700. cmask, val_type, name,
  701. &snd_usb_mixer_vol_tlv);
  702. if (err < 0)
  703. return err;
  704. }
  705. }
  706. return 0;
  707. }
  708. /* This control needs a volume quirk, see mixer.c */
  709. static int snd_ftu_create_effect_volume_ctl(struct usb_mixer_interface *mixer)
  710. {
  711. static const char name[] = "Effect Volume";
  712. const unsigned int id = 6;
  713. const int val_type = USB_MIXER_U8;
  714. const unsigned int control = 2;
  715. const unsigned int cmask = 0;
  716. return snd_create_std_mono_ctl(mixer, id, control, cmask, val_type,
  717. name, snd_usb_mixer_vol_tlv);
  718. }
  719. /* This control needs a volume quirk, see mixer.c */
  720. static int snd_ftu_create_effect_duration_ctl(struct usb_mixer_interface *mixer)
  721. {
  722. static const char name[] = "Effect Duration";
  723. const unsigned int id = 6;
  724. const int val_type = USB_MIXER_S16;
  725. const unsigned int control = 3;
  726. const unsigned int cmask = 0;
  727. return snd_create_std_mono_ctl(mixer, id, control, cmask, val_type,
  728. name, snd_usb_mixer_vol_tlv);
  729. }
  730. /* This control needs a volume quirk, see mixer.c */
  731. static int snd_ftu_create_effect_feedback_ctl(struct usb_mixer_interface *mixer)
  732. {
  733. static const char name[] = "Effect Feedback Volume";
  734. const unsigned int id = 6;
  735. const int val_type = USB_MIXER_U8;
  736. const unsigned int control = 4;
  737. const unsigned int cmask = 0;
  738. return snd_create_std_mono_ctl(mixer, id, control, cmask, val_type,
  739. name, NULL);
  740. }
  741. static int snd_ftu_create_effect_return_ctls(struct usb_mixer_interface *mixer)
  742. {
  743. unsigned int cmask;
  744. int err, ch;
  745. char name[48];
  746. const unsigned int id = 7;
  747. const int val_type = USB_MIXER_S16;
  748. const unsigned int control = 7;
  749. for (ch = 0; ch < 4; ++ch) {
  750. cmask = 1 << ch;
  751. snprintf(name, sizeof(name),
  752. "Effect Return %d Volume", ch + 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. return 0;
  760. }
  761. static int snd_ftu_create_effect_send_ctls(struct usb_mixer_interface *mixer)
  762. {
  763. unsigned int cmask;
  764. int err, ch;
  765. char name[48];
  766. const unsigned int id = 5;
  767. const int val_type = USB_MIXER_S16;
  768. const unsigned int control = 9;
  769. for (ch = 0; ch < 8; ++ch) {
  770. cmask = 1 << ch;
  771. snprintf(name, sizeof(name),
  772. "Effect Send AIn%d Volume", ch + 1);
  773. err = snd_create_std_mono_ctl(mixer, id, control, cmask,
  774. val_type, name,
  775. snd_usb_mixer_vol_tlv);
  776. if (err < 0)
  777. return err;
  778. }
  779. for (ch = 8; ch < 16; ++ch) {
  780. cmask = 1 << ch;
  781. snprintf(name, sizeof(name),
  782. "Effect Send DIn%d Volume", ch - 7);
  783. err = snd_create_std_mono_ctl(mixer, id, control, cmask,
  784. val_type, name,
  785. snd_usb_mixer_vol_tlv);
  786. if (err < 0)
  787. return err;
  788. }
  789. return 0;
  790. }
  791. static int snd_ftu_create_mixer(struct usb_mixer_interface *mixer)
  792. {
  793. int err;
  794. err = snd_ftu_create_volume_ctls(mixer);
  795. if (err < 0)
  796. return err;
  797. err = snd_ftu_create_effect_switch(mixer);
  798. if (err < 0)
  799. return err;
  800. err = snd_ftu_create_effect_volume_ctl(mixer);
  801. if (err < 0)
  802. return err;
  803. err = snd_ftu_create_effect_duration_ctl(mixer);
  804. if (err < 0)
  805. return err;
  806. err = snd_ftu_create_effect_feedback_ctl(mixer);
  807. if (err < 0)
  808. return err;
  809. err = snd_ftu_create_effect_return_ctls(mixer);
  810. if (err < 0)
  811. return err;
  812. err = snd_ftu_create_effect_send_ctls(mixer);
  813. if (err < 0)
  814. return err;
  815. return 0;
  816. }
  817. void snd_emuusb_set_samplerate(struct snd_usb_audio *chip,
  818. unsigned char samplerate_id)
  819. {
  820. struct usb_mixer_interface *mixer;
  821. struct usb_mixer_elem_info *cval;
  822. int unitid = 12; /* SamleRate ExtensionUnit ID */
  823. list_for_each_entry(mixer, &chip->mixer_list, list) {
  824. cval = mixer->id_elems[unitid];
  825. if (cval) {
  826. snd_usb_mixer_set_ctl_value(cval, UAC_SET_CUR,
  827. cval->control << 8,
  828. samplerate_id);
  829. snd_usb_mixer_notify_id(mixer, unitid);
  830. }
  831. break;
  832. }
  833. }
  834. /*
  835. * The mixer units for Ebox-44 are corrupt, and even where they
  836. * are valid they presents mono controls as L and R channels of
  837. * stereo. So we provide a good mixer here.
  838. */
  839. struct std_mono_table ebox44_table[] = {
  840. {
  841. .unitid = 4,
  842. .control = 1,
  843. .cmask = 0x0,
  844. .val_type = USB_MIXER_INV_BOOLEAN,
  845. .name = "Headphone Playback Switch"
  846. },
  847. {
  848. .unitid = 4,
  849. .control = 2,
  850. .cmask = 0x1,
  851. .val_type = USB_MIXER_S16,
  852. .name = "Headphone A Mix Playback Volume"
  853. },
  854. {
  855. .unitid = 4,
  856. .control = 2,
  857. .cmask = 0x2,
  858. .val_type = USB_MIXER_S16,
  859. .name = "Headphone B Mix Playback Volume"
  860. },
  861. {
  862. .unitid = 7,
  863. .control = 1,
  864. .cmask = 0x0,
  865. .val_type = USB_MIXER_INV_BOOLEAN,
  866. .name = "Output Playback Switch"
  867. },
  868. {
  869. .unitid = 7,
  870. .control = 2,
  871. .cmask = 0x1,
  872. .val_type = USB_MIXER_S16,
  873. .name = "Output A Playback Volume"
  874. },
  875. {
  876. .unitid = 7,
  877. .control = 2,
  878. .cmask = 0x2,
  879. .val_type = USB_MIXER_S16,
  880. .name = "Output B Playback Volume"
  881. },
  882. {
  883. .unitid = 10,
  884. .control = 1,
  885. .cmask = 0x0,
  886. .val_type = USB_MIXER_INV_BOOLEAN,
  887. .name = "Input Capture Switch"
  888. },
  889. {
  890. .unitid = 10,
  891. .control = 2,
  892. .cmask = 0x1,
  893. .val_type = USB_MIXER_S16,
  894. .name = "Input A Capture Volume"
  895. },
  896. {
  897. .unitid = 10,
  898. .control = 2,
  899. .cmask = 0x2,
  900. .val_type = USB_MIXER_S16,
  901. .name = "Input B Capture Volume"
  902. },
  903. {}
  904. };
  905. int snd_usb_mixer_apply_create_quirk(struct usb_mixer_interface *mixer)
  906. {
  907. int err = 0;
  908. struct snd_info_entry *entry;
  909. if ((err = snd_usb_soundblaster_remote_init(mixer)) < 0)
  910. return err;
  911. switch (mixer->chip->usb_id) {
  912. case USB_ID(0x041e, 0x3020):
  913. case USB_ID(0x041e, 0x3040):
  914. case USB_ID(0x041e, 0x3042):
  915. case USB_ID(0x041e, 0x30df):
  916. case USB_ID(0x041e, 0x3048):
  917. err = snd_audigy2nx_controls_create(mixer);
  918. if (err < 0)
  919. break;
  920. if (!snd_card_proc_new(mixer->chip->card, "audigy2nx", &entry))
  921. snd_info_set_text_ops(entry, mixer,
  922. snd_audigy2nx_proc_read);
  923. break;
  924. case USB_ID(0x0763, 0x2080): /* M-Audio Fast Track Ultra */
  925. case USB_ID(0x0763, 0x2081): /* M-Audio Fast Track Ultra 8R */
  926. err = snd_ftu_create_mixer(mixer);
  927. break;
  928. case USB_ID(0x0b05, 0x1739):
  929. case USB_ID(0x0b05, 0x1743):
  930. err = snd_xonar_u1_controls_create(mixer);
  931. break;
  932. case USB_ID(0x17cc, 0x1011): /* Traktor Audio 6 */
  933. err = snd_nativeinstruments_create_mixer(mixer,
  934. snd_nativeinstruments_ta6_mixers,
  935. ARRAY_SIZE(snd_nativeinstruments_ta6_mixers));
  936. break;
  937. case USB_ID(0x17cc, 0x1021): /* Traktor Audio 10 */
  938. err = snd_nativeinstruments_create_mixer(mixer,
  939. snd_nativeinstruments_ta10_mixers,
  940. ARRAY_SIZE(snd_nativeinstruments_ta10_mixers));
  941. break;
  942. case USB_ID(0x200c, 0x1018): /* Electrix Ebox-44 */
  943. /* detection is disabled in mixer_maps.c */
  944. err = snd_create_std_mono_table(mixer, ebox44_table);
  945. break;
  946. }
  947. return err;
  948. }
  949. void snd_usb_mixer_rc_memory_change(struct usb_mixer_interface *mixer,
  950. int unitid)
  951. {
  952. if (!mixer->rc_cfg)
  953. return;
  954. /* unit ids specific to Extigy/Audigy 2 NX: */
  955. switch (unitid) {
  956. case 0: /* remote control */
  957. mixer->rc_urb->dev = mixer->chip->dev;
  958. usb_submit_urb(mixer->rc_urb, GFP_ATOMIC);
  959. break;
  960. case 4: /* digital in jack */
  961. case 7: /* line in jacks */
  962. case 19: /* speaker out jacks */
  963. case 20: /* headphones out jack */
  964. break;
  965. /* live24ext: 4 = line-in jack */
  966. case 3: /* hp-out jack (may actuate Mute) */
  967. if (mixer->chip->usb_id == USB_ID(0x041e, 0x3040) ||
  968. mixer->chip->usb_id == USB_ID(0x041e, 0x3048))
  969. snd_usb_mixer_notify_id(mixer, mixer->rc_cfg->mute_mixer_id);
  970. break;
  971. default:
  972. snd_printd(KERN_DEBUG "memory change in unknown unit %d\n", unitid);
  973. break;
  974. }
  975. }