mixer_quirks.c 29 KB

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