mixer_quirks.c 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761
  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. /* Create a volume control for FTU devices*/
  513. static int snd_maudio_ftu_create_volume_ctls(struct usb_mixer_interface *mixer)
  514. {
  515. char name[64];
  516. unsigned int control, cmask;
  517. int in, out, err;
  518. const unsigned int id = 5;
  519. const int val_type = USB_MIXER_S16;
  520. for (out = 0; out < 8; out++) {
  521. control = out + 1;
  522. for (in = 0; in < 8; in++) {
  523. cmask = 1 << in;
  524. snprintf(name, sizeof(name),
  525. "AIn%d - Out%d Capture Volume",
  526. in + 1, out + 1);
  527. err = snd_create_std_mono_ctl(mixer, id, control,
  528. cmask, val_type, name,
  529. NULL);
  530. if (err < 0)
  531. return err;
  532. }
  533. for (in = 8; in < 16; in++) {
  534. cmask = 1 << in;
  535. snprintf(name, sizeof(name),
  536. "DIn%d - Out%d Playback Volume",
  537. in - 7, out + 1);
  538. err = snd_create_std_mono_ctl(mixer, id, control,
  539. cmask, val_type, name,
  540. NULL);
  541. if (err < 0)
  542. return err;
  543. }
  544. }
  545. return 0;
  546. }
  547. static int snd_maudio_ftu_create_mixer(struct usb_mixer_interface *mixer)
  548. {
  549. int err;
  550. err = snd_maudio_ftu_create_volume_ctls(mixer);
  551. if (err < 0)
  552. return err;
  553. return 0;
  554. }
  555. /*
  556. * Create mixer for Electrix Ebox-44
  557. *
  558. * The mixer units from this device are corrupt, and even where they
  559. * are valid they presents mono controls as L and R channels of
  560. * stereo. So we create a good mixer in code.
  561. */
  562. static int snd_ebox44_create_mixer(struct usb_mixer_interface *mixer)
  563. {
  564. snd_create_std_mono_ctl(mixer, 4, 1, 0x0, USB_MIXER_INV_BOOLEAN,
  565. "Headphone Playback Switch", NULL);
  566. snd_create_std_mono_ctl(mixer, 4, 2, 0x1, USB_MIXER_S16,
  567. "Headphone A Mix Playback Volume", NULL);
  568. snd_create_std_mono_ctl(mixer, 4, 2, 0x2, USB_MIXER_S16,
  569. "Headphone B Mix Playback Volume", NULL);
  570. snd_create_std_mono_ctl(mixer, 7, 1, 0x0, USB_MIXER_INV_BOOLEAN,
  571. "Output Playback Switch", NULL);
  572. snd_create_std_mono_ctl(mixer, 7, 2, 0x1, USB_MIXER_S16,
  573. "Output A Playback Volume", NULL);
  574. snd_create_std_mono_ctl(mixer, 7, 2, 0x2, USB_MIXER_S16,
  575. "Output B Playback Volume", NULL);
  576. snd_create_std_mono_ctl(mixer, 10, 1, 0x0, USB_MIXER_INV_BOOLEAN,
  577. "Input Capture Switch", NULL);
  578. snd_create_std_mono_ctl(mixer, 10, 2, 0x1, USB_MIXER_S16,
  579. "Input A Capture Volume", NULL);
  580. snd_create_std_mono_ctl(mixer, 10, 2, 0x2, USB_MIXER_S16,
  581. "Input B Capture Volume", NULL);
  582. return 0;
  583. }
  584. void snd_emuusb_set_samplerate(struct snd_usb_audio *chip,
  585. unsigned char samplerate_id)
  586. {
  587. struct usb_mixer_interface *mixer;
  588. struct usb_mixer_elem_info *cval;
  589. int unitid = 12; /* SamleRate ExtensionUnit ID */
  590. list_for_each_entry(mixer, &chip->mixer_list, list) {
  591. cval = mixer->id_elems[unitid];
  592. if (cval) {
  593. snd_usb_mixer_set_ctl_value(cval, UAC_SET_CUR,
  594. cval->control << 8,
  595. samplerate_id);
  596. snd_usb_mixer_notify_id(mixer, unitid);
  597. }
  598. break;
  599. }
  600. }
  601. int snd_usb_mixer_apply_create_quirk(struct usb_mixer_interface *mixer)
  602. {
  603. int err = 0;
  604. struct snd_info_entry *entry;
  605. if ((err = snd_usb_soundblaster_remote_init(mixer)) < 0)
  606. return err;
  607. switch (mixer->chip->usb_id) {
  608. case USB_ID(0x041e, 0x3020):
  609. case USB_ID(0x041e, 0x3040):
  610. case USB_ID(0x041e, 0x3042):
  611. case USB_ID(0x041e, 0x30df):
  612. case USB_ID(0x041e, 0x3048):
  613. err = snd_audigy2nx_controls_create(mixer);
  614. if (err < 0)
  615. break;
  616. if (!snd_card_proc_new(mixer->chip->card, "audigy2nx", &entry))
  617. snd_info_set_text_ops(entry, mixer,
  618. snd_audigy2nx_proc_read);
  619. break;
  620. case USB_ID(0x0763, 0x2080): /* M-Audio Fast Track Ultra */
  621. case USB_ID(0x0763, 0x2081): /* M-Audio Fast Track Ultra 8R */
  622. err = snd_maudio_ftu_create_mixer(mixer);
  623. break;
  624. case USB_ID(0x0b05, 0x1739):
  625. case USB_ID(0x0b05, 0x1743):
  626. err = snd_xonar_u1_controls_create(mixer);
  627. break;
  628. case USB_ID(0x17cc, 0x1011): /* Traktor Audio 6 */
  629. err = snd_nativeinstruments_create_mixer(mixer,
  630. snd_nativeinstruments_ta6_mixers,
  631. ARRAY_SIZE(snd_nativeinstruments_ta6_mixers));
  632. break;
  633. case USB_ID(0x17cc, 0x1021): /* Traktor Audio 10 */
  634. err = snd_nativeinstruments_create_mixer(mixer,
  635. snd_nativeinstruments_ta10_mixers,
  636. ARRAY_SIZE(snd_nativeinstruments_ta10_mixers));
  637. break;
  638. case USB_ID(0x200c, 0x1018): /* Electrix Ebox-44 */
  639. err = snd_ebox44_create_mixer(mixer);
  640. break;
  641. }
  642. return err;
  643. }
  644. void snd_usb_mixer_rc_memory_change(struct usb_mixer_interface *mixer,
  645. int unitid)
  646. {
  647. if (!mixer->rc_cfg)
  648. return;
  649. /* unit ids specific to Extigy/Audigy 2 NX: */
  650. switch (unitid) {
  651. case 0: /* remote control */
  652. mixer->rc_urb->dev = mixer->chip->dev;
  653. usb_submit_urb(mixer->rc_urb, GFP_ATOMIC);
  654. break;
  655. case 4: /* digital in jack */
  656. case 7: /* line in jacks */
  657. case 19: /* speaker out jacks */
  658. case 20: /* headphones out jack */
  659. break;
  660. /* live24ext: 4 = line-in jack */
  661. case 3: /* hp-out jack (may actuate Mute) */
  662. if (mixer->chip->usb_id == USB_ID(0x041e, 0x3040) ||
  663. mixer->chip->usb_id == USB_ID(0x041e, 0x3048))
  664. snd_usb_mixer_notify_id(mixer, mixer->rc_cfg->mute_mixer_id);
  665. break;
  666. default:
  667. snd_printd(KERN_DEBUG "memory change in unknown unit %d\n", unitid);
  668. break;
  669. }
  670. }