mixer_quirks.c 28 KB

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