mixer_quirks.c 28 KB

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