mixer_quirks.c 41 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616
  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. * Audio Advantage Micro II support added by:
  13. * Przemek Rudy (prudy1@o2.pl)
  14. *
  15. * This program is free software; you can redistribute it and/or modify
  16. * it under the terms of the GNU General Public License as published by
  17. * the Free Software Foundation; either version 2 of the License, or
  18. * (at your option) any later version.
  19. *
  20. * This program is distributed in the hope that it will be useful,
  21. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  22. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  23. * GNU General Public License for more details.
  24. *
  25. * You should have received a copy of the GNU General Public License
  26. * along with this program; if not, write to the Free Software
  27. * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  28. */
  29. #include <linux/init.h>
  30. #include <linux/slab.h>
  31. #include <linux/usb.h>
  32. #include <linux/usb/audio.h>
  33. #include <sound/asoundef.h>
  34. #include <sound/core.h>
  35. #include <sound/control.h>
  36. #include <sound/hwdep.h>
  37. #include <sound/info.h>
  38. #include "usbaudio.h"
  39. #include "mixer.h"
  40. #include "mixer_quirks.h"
  41. #include "helper.h"
  42. extern struct snd_kcontrol_new *snd_usb_feature_unit_ctl;
  43. struct std_mono_table {
  44. unsigned int unitid, control, cmask;
  45. int val_type;
  46. const char *name;
  47. snd_kcontrol_tlv_rw_t *tlv_callback;
  48. };
  49. /* private_free callback */
  50. static void usb_mixer_elem_free(struct snd_kcontrol *kctl)
  51. {
  52. kfree(kctl->private_data);
  53. kctl->private_data = NULL;
  54. }
  55. /* This function allows for the creation of standard UAC controls.
  56. * See the quirks for M-Audio FTUs or Ebox-44.
  57. * If you don't want to set a TLV callback pass NULL.
  58. *
  59. * Since there doesn't seem to be a devices that needs a multichannel
  60. * version, we keep it mono for simplicity.
  61. */
  62. static int snd_create_std_mono_ctl_offset(struct usb_mixer_interface *mixer,
  63. unsigned int unitid,
  64. unsigned int control,
  65. unsigned int cmask,
  66. int val_type,
  67. unsigned int idx_off,
  68. const char *name,
  69. snd_kcontrol_tlv_rw_t *tlv_callback)
  70. {
  71. int err;
  72. struct usb_mixer_elem_info *cval;
  73. struct snd_kcontrol *kctl;
  74. cval = kzalloc(sizeof(*cval), GFP_KERNEL);
  75. if (!cval)
  76. return -ENOMEM;
  77. cval->id = unitid;
  78. cval->mixer = mixer;
  79. cval->val_type = val_type;
  80. cval->channels = 1;
  81. cval->control = control;
  82. cval->cmask = cmask;
  83. cval->idx_off = idx_off;
  84. /* get_min_max() is called only for integer volumes later,
  85. * so provide a short-cut for booleans */
  86. cval->min = 0;
  87. cval->max = 1;
  88. cval->res = 0;
  89. cval->dBmin = 0;
  90. cval->dBmax = 0;
  91. /* Create control */
  92. kctl = snd_ctl_new1(snd_usb_feature_unit_ctl, cval);
  93. if (!kctl) {
  94. kfree(cval);
  95. return -ENOMEM;
  96. }
  97. /* Set name */
  98. snprintf(kctl->id.name, sizeof(kctl->id.name), name);
  99. kctl->private_free = usb_mixer_elem_free;
  100. /* set TLV */
  101. if (tlv_callback) {
  102. kctl->tlv.c = tlv_callback;
  103. kctl->vd[0].access |=
  104. SNDRV_CTL_ELEM_ACCESS_TLV_READ |
  105. SNDRV_CTL_ELEM_ACCESS_TLV_CALLBACK;
  106. }
  107. /* Add control to mixer */
  108. err = snd_usb_mixer_add_control(mixer, kctl);
  109. if (err < 0)
  110. return err;
  111. return 0;
  112. }
  113. static int snd_create_std_mono_ctl(struct usb_mixer_interface *mixer,
  114. unsigned int unitid,
  115. unsigned int control,
  116. unsigned int cmask,
  117. int val_type,
  118. const char *name,
  119. snd_kcontrol_tlv_rw_t *tlv_callback)
  120. {
  121. return snd_create_std_mono_ctl_offset(mixer, unitid, control, cmask,
  122. val_type, 0 /* Offset */, name, tlv_callback);
  123. }
  124. /*
  125. * Create a set of standard UAC controls from a table
  126. */
  127. static int snd_create_std_mono_table(struct usb_mixer_interface *mixer,
  128. struct std_mono_table *t)
  129. {
  130. int err;
  131. while (t->name != NULL) {
  132. err = snd_create_std_mono_ctl(mixer, t->unitid, t->control,
  133. t->cmask, t->val_type, t->name, t->tlv_callback);
  134. if (err < 0)
  135. return err;
  136. t++;
  137. }
  138. return 0;
  139. }
  140. /*
  141. * Sound Blaster remote control configuration
  142. *
  143. * format of remote control data:
  144. * Extigy: xx 00
  145. * Audigy 2 NX: 06 80 xx 00 00 00
  146. * Live! 24-bit: 06 80 xx yy 22 83
  147. */
  148. static const struct rc_config {
  149. u32 usb_id;
  150. u8 offset;
  151. u8 length;
  152. u8 packet_length;
  153. u8 min_packet_length; /* minimum accepted length of the URB result */
  154. u8 mute_mixer_id;
  155. u32 mute_code;
  156. } rc_configs[] = {
  157. { USB_ID(0x041e, 0x3000), 0, 1, 2, 1, 18, 0x0013 }, /* Extigy */
  158. { USB_ID(0x041e, 0x3020), 2, 1, 6, 6, 18, 0x0013 }, /* Audigy 2 NX */
  159. { USB_ID(0x041e, 0x3040), 2, 2, 6, 6, 2, 0x6e91 }, /* Live! 24-bit */
  160. { USB_ID(0x041e, 0x3042), 0, 1, 1, 1, 1, 0x000d }, /* Usb X-Fi S51 */
  161. { USB_ID(0x041e, 0x30df), 0, 1, 1, 1, 1, 0x000d }, /* Usb X-Fi S51 Pro */
  162. { USB_ID(0x041e, 0x3048), 2, 2, 6, 6, 2, 0x6e91 }, /* Toshiba SB0500 */
  163. };
  164. static void snd_usb_soundblaster_remote_complete(struct urb *urb)
  165. {
  166. struct usb_mixer_interface *mixer = urb->context;
  167. const struct rc_config *rc = mixer->rc_cfg;
  168. u32 code;
  169. if (urb->status < 0 || urb->actual_length < rc->min_packet_length)
  170. return;
  171. code = mixer->rc_buffer[rc->offset];
  172. if (rc->length == 2)
  173. code |= mixer->rc_buffer[rc->offset + 1] << 8;
  174. /* the Mute button actually changes the mixer control */
  175. if (code == rc->mute_code)
  176. snd_usb_mixer_notify_id(mixer, rc->mute_mixer_id);
  177. mixer->rc_code = code;
  178. wmb();
  179. wake_up(&mixer->rc_waitq);
  180. }
  181. static long snd_usb_sbrc_hwdep_read(struct snd_hwdep *hw, char __user *buf,
  182. long count, loff_t *offset)
  183. {
  184. struct usb_mixer_interface *mixer = hw->private_data;
  185. int err;
  186. u32 rc_code;
  187. if (count != 1 && count != 4)
  188. return -EINVAL;
  189. err = wait_event_interruptible(mixer->rc_waitq,
  190. (rc_code = xchg(&mixer->rc_code, 0)) != 0);
  191. if (err == 0) {
  192. if (count == 1)
  193. err = put_user(rc_code, buf);
  194. else
  195. err = put_user(rc_code, (u32 __user *)buf);
  196. }
  197. return err < 0 ? err : count;
  198. }
  199. static unsigned int snd_usb_sbrc_hwdep_poll(struct snd_hwdep *hw, struct file *file,
  200. poll_table *wait)
  201. {
  202. struct usb_mixer_interface *mixer = hw->private_data;
  203. poll_wait(file, &mixer->rc_waitq, wait);
  204. return mixer->rc_code ? POLLIN | POLLRDNORM : 0;
  205. }
  206. static int snd_usb_soundblaster_remote_init(struct usb_mixer_interface *mixer)
  207. {
  208. struct snd_hwdep *hwdep;
  209. int err, len, i;
  210. for (i = 0; i < ARRAY_SIZE(rc_configs); ++i)
  211. if (rc_configs[i].usb_id == mixer->chip->usb_id)
  212. break;
  213. if (i >= ARRAY_SIZE(rc_configs))
  214. return 0;
  215. mixer->rc_cfg = &rc_configs[i];
  216. len = mixer->rc_cfg->packet_length;
  217. init_waitqueue_head(&mixer->rc_waitq);
  218. err = snd_hwdep_new(mixer->chip->card, "SB remote control", 0, &hwdep);
  219. if (err < 0)
  220. return err;
  221. snprintf(hwdep->name, sizeof(hwdep->name),
  222. "%s remote control", mixer->chip->card->shortname);
  223. hwdep->iface = SNDRV_HWDEP_IFACE_SB_RC;
  224. hwdep->private_data = mixer;
  225. hwdep->ops.read = snd_usb_sbrc_hwdep_read;
  226. hwdep->ops.poll = snd_usb_sbrc_hwdep_poll;
  227. hwdep->exclusive = 1;
  228. mixer->rc_urb = usb_alloc_urb(0, GFP_KERNEL);
  229. if (!mixer->rc_urb)
  230. return -ENOMEM;
  231. mixer->rc_setup_packet = kmalloc(sizeof(*mixer->rc_setup_packet), GFP_KERNEL);
  232. if (!mixer->rc_setup_packet) {
  233. usb_free_urb(mixer->rc_urb);
  234. mixer->rc_urb = NULL;
  235. return -ENOMEM;
  236. }
  237. mixer->rc_setup_packet->bRequestType =
  238. USB_DIR_IN | USB_TYPE_CLASS | USB_RECIP_INTERFACE;
  239. mixer->rc_setup_packet->bRequest = UAC_GET_MEM;
  240. mixer->rc_setup_packet->wValue = cpu_to_le16(0);
  241. mixer->rc_setup_packet->wIndex = cpu_to_le16(0);
  242. mixer->rc_setup_packet->wLength = cpu_to_le16(len);
  243. usb_fill_control_urb(mixer->rc_urb, mixer->chip->dev,
  244. usb_rcvctrlpipe(mixer->chip->dev, 0),
  245. (u8*)mixer->rc_setup_packet, mixer->rc_buffer, len,
  246. snd_usb_soundblaster_remote_complete, mixer);
  247. return 0;
  248. }
  249. #define snd_audigy2nx_led_info snd_ctl_boolean_mono_info
  250. static int snd_audigy2nx_led_get(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
  251. {
  252. struct usb_mixer_interface *mixer = snd_kcontrol_chip(kcontrol);
  253. int index = kcontrol->private_value;
  254. ucontrol->value.integer.value[0] = mixer->audigy2nx_leds[index];
  255. return 0;
  256. }
  257. static int snd_audigy2nx_led_put(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
  258. {
  259. struct usb_mixer_interface *mixer = snd_kcontrol_chip(kcontrol);
  260. int index = kcontrol->private_value;
  261. int value = ucontrol->value.integer.value[0];
  262. int err, changed;
  263. if (value > 1)
  264. return -EINVAL;
  265. changed = value != mixer->audigy2nx_leds[index];
  266. down_read(&mixer->chip->shutdown_rwsem);
  267. if (mixer->chip->shutdown) {
  268. err = -ENODEV;
  269. goto out;
  270. }
  271. if (mixer->chip->usb_id == USB_ID(0x041e, 0x3042))
  272. err = snd_usb_ctl_msg(mixer->chip->dev,
  273. usb_sndctrlpipe(mixer->chip->dev, 0), 0x24,
  274. USB_DIR_OUT | USB_TYPE_VENDOR | USB_RECIP_OTHER,
  275. !value, 0, NULL, 0);
  276. /* USB X-Fi S51 Pro */
  277. if (mixer->chip->usb_id == USB_ID(0x041e, 0x30df))
  278. err = snd_usb_ctl_msg(mixer->chip->dev,
  279. usb_sndctrlpipe(mixer->chip->dev, 0), 0x24,
  280. USB_DIR_OUT | USB_TYPE_VENDOR | USB_RECIP_OTHER,
  281. !value, 0, NULL, 0);
  282. else
  283. err = snd_usb_ctl_msg(mixer->chip->dev,
  284. usb_sndctrlpipe(mixer->chip->dev, 0), 0x24,
  285. USB_DIR_OUT | USB_TYPE_VENDOR | USB_RECIP_OTHER,
  286. value, index + 2, NULL, 0);
  287. out:
  288. up_read(&mixer->chip->shutdown_rwsem);
  289. if (err < 0)
  290. return err;
  291. mixer->audigy2nx_leds[index] = value;
  292. return changed;
  293. }
  294. static struct snd_kcontrol_new snd_audigy2nx_controls[] = {
  295. {
  296. .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
  297. .name = "CMSS LED Switch",
  298. .info = snd_audigy2nx_led_info,
  299. .get = snd_audigy2nx_led_get,
  300. .put = snd_audigy2nx_led_put,
  301. .private_value = 0,
  302. },
  303. {
  304. .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
  305. .name = "Power LED Switch",
  306. .info = snd_audigy2nx_led_info,
  307. .get = snd_audigy2nx_led_get,
  308. .put = snd_audigy2nx_led_put,
  309. .private_value = 1,
  310. },
  311. {
  312. .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
  313. .name = "Dolby Digital LED Switch",
  314. .info = snd_audigy2nx_led_info,
  315. .get = snd_audigy2nx_led_get,
  316. .put = snd_audigy2nx_led_put,
  317. .private_value = 2,
  318. },
  319. };
  320. static int snd_audigy2nx_controls_create(struct usb_mixer_interface *mixer)
  321. {
  322. int i, err;
  323. for (i = 0; i < ARRAY_SIZE(snd_audigy2nx_controls); ++i) {
  324. /* USB X-Fi S51 doesn't have a CMSS LED */
  325. if ((mixer->chip->usb_id == USB_ID(0x041e, 0x3042)) && i == 0)
  326. continue;
  327. /* USB X-Fi S51 Pro doesn't have one either */
  328. if ((mixer->chip->usb_id == USB_ID(0x041e, 0x30df)) && i == 0)
  329. continue;
  330. if (i > 1 && /* Live24ext has 2 LEDs only */
  331. (mixer->chip->usb_id == USB_ID(0x041e, 0x3040) ||
  332. mixer->chip->usb_id == USB_ID(0x041e, 0x3042) ||
  333. mixer->chip->usb_id == USB_ID(0x041e, 0x30df) ||
  334. mixer->chip->usb_id == USB_ID(0x041e, 0x3048)))
  335. break;
  336. err = snd_ctl_add(mixer->chip->card,
  337. snd_ctl_new1(&snd_audigy2nx_controls[i], mixer));
  338. if (err < 0)
  339. return err;
  340. }
  341. mixer->audigy2nx_leds[1] = 1; /* Power LED is on by default */
  342. return 0;
  343. }
  344. static void snd_audigy2nx_proc_read(struct snd_info_entry *entry,
  345. struct snd_info_buffer *buffer)
  346. {
  347. static const struct sb_jack {
  348. int unitid;
  349. const char *name;
  350. } jacks_audigy2nx[] = {
  351. {4, "dig in "},
  352. {7, "line in"},
  353. {19, "spk out"},
  354. {20, "hph out"},
  355. {-1, NULL}
  356. }, jacks_live24ext[] = {
  357. {4, "line in"}, /* &1=Line, &2=Mic*/
  358. {3, "hph out"}, /* headphones */
  359. {0, "RC "}, /* last command, 6 bytes see rc_config above */
  360. {-1, NULL}
  361. };
  362. const struct sb_jack *jacks;
  363. struct usb_mixer_interface *mixer = entry->private_data;
  364. int i, err;
  365. u8 buf[3];
  366. snd_iprintf(buffer, "%s jacks\n\n", mixer->chip->card->shortname);
  367. if (mixer->chip->usb_id == USB_ID(0x041e, 0x3020))
  368. jacks = jacks_audigy2nx;
  369. else if (mixer->chip->usb_id == USB_ID(0x041e, 0x3040) ||
  370. mixer->chip->usb_id == USB_ID(0x041e, 0x3048))
  371. jacks = jacks_live24ext;
  372. else
  373. return;
  374. for (i = 0; jacks[i].name; ++i) {
  375. snd_iprintf(buffer, "%s: ", jacks[i].name);
  376. down_read(&mixer->chip->shutdown_rwsem);
  377. if (mixer->chip->shutdown)
  378. err = 0;
  379. else
  380. err = snd_usb_ctl_msg(mixer->chip->dev,
  381. usb_rcvctrlpipe(mixer->chip->dev, 0),
  382. UAC_GET_MEM, USB_DIR_IN | USB_TYPE_CLASS |
  383. USB_RECIP_INTERFACE, 0,
  384. jacks[i].unitid << 8, buf, 3);
  385. up_read(&mixer->chip->shutdown_rwsem);
  386. if (err == 3 && (buf[0] == 3 || buf[0] == 6))
  387. snd_iprintf(buffer, "%02x %02x\n", buf[1], buf[2]);
  388. else
  389. snd_iprintf(buffer, "?\n");
  390. }
  391. }
  392. /* ASUS Xonar U1 / U3 controls */
  393. static int snd_xonar_u1_switch_get(struct snd_kcontrol *kcontrol,
  394. struct snd_ctl_elem_value *ucontrol)
  395. {
  396. struct usb_mixer_interface *mixer = snd_kcontrol_chip(kcontrol);
  397. ucontrol->value.integer.value[0] = !!(mixer->xonar_u1_status & 0x02);
  398. return 0;
  399. }
  400. static int snd_xonar_u1_switch_put(struct snd_kcontrol *kcontrol,
  401. struct snd_ctl_elem_value *ucontrol)
  402. {
  403. struct usb_mixer_interface *mixer = snd_kcontrol_chip(kcontrol);
  404. u8 old_status, new_status;
  405. int err, changed;
  406. old_status = mixer->xonar_u1_status;
  407. if (ucontrol->value.integer.value[0])
  408. new_status = old_status | 0x02;
  409. else
  410. new_status = old_status & ~0x02;
  411. changed = new_status != old_status;
  412. down_read(&mixer->chip->shutdown_rwsem);
  413. if (mixer->chip->shutdown)
  414. err = -ENODEV;
  415. else
  416. err = snd_usb_ctl_msg(mixer->chip->dev,
  417. usb_sndctrlpipe(mixer->chip->dev, 0), 0x08,
  418. USB_DIR_OUT | USB_TYPE_VENDOR | USB_RECIP_OTHER,
  419. 50, 0, &new_status, 1);
  420. up_read(&mixer->chip->shutdown_rwsem);
  421. if (err < 0)
  422. return err;
  423. mixer->xonar_u1_status = new_status;
  424. return changed;
  425. }
  426. static struct snd_kcontrol_new snd_xonar_u1_output_switch = {
  427. .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
  428. .name = "Digital Playback Switch",
  429. .info = snd_ctl_boolean_mono_info,
  430. .get = snd_xonar_u1_switch_get,
  431. .put = snd_xonar_u1_switch_put,
  432. };
  433. static int snd_xonar_u1_controls_create(struct usb_mixer_interface *mixer)
  434. {
  435. int err;
  436. err = snd_ctl_add(mixer->chip->card,
  437. snd_ctl_new1(&snd_xonar_u1_output_switch, mixer));
  438. if (err < 0)
  439. return err;
  440. mixer->xonar_u1_status = 0x05;
  441. return 0;
  442. }
  443. /* Native Instruments device quirks */
  444. #define _MAKE_NI_CONTROL(bRequest,wIndex) ((bRequest) << 16 | (wIndex))
  445. static int snd_nativeinstruments_control_get(struct snd_kcontrol *kcontrol,
  446. struct snd_ctl_elem_value *ucontrol)
  447. {
  448. struct usb_mixer_interface *mixer = snd_kcontrol_chip(kcontrol);
  449. struct usb_device *dev = mixer->chip->dev;
  450. u8 bRequest = (kcontrol->private_value >> 16) & 0xff;
  451. u16 wIndex = kcontrol->private_value & 0xffff;
  452. u8 tmp;
  453. int ret;
  454. down_read(&mixer->chip->shutdown_rwsem);
  455. if (mixer->chip->shutdown)
  456. ret = -ENODEV;
  457. else
  458. ret = usb_control_msg(dev, usb_rcvctrlpipe(dev, 0), bRequest,
  459. USB_TYPE_VENDOR | USB_RECIP_DEVICE | USB_DIR_IN,
  460. 0, wIndex,
  461. &tmp, sizeof(tmp), 1000);
  462. up_read(&mixer->chip->shutdown_rwsem);
  463. if (ret < 0) {
  464. snd_printk(KERN_ERR
  465. "unable to issue vendor read request (ret = %d)", ret);
  466. return ret;
  467. }
  468. ucontrol->value.integer.value[0] = tmp;
  469. return 0;
  470. }
  471. static int snd_nativeinstruments_control_put(struct snd_kcontrol *kcontrol,
  472. struct snd_ctl_elem_value *ucontrol)
  473. {
  474. struct usb_mixer_interface *mixer = snd_kcontrol_chip(kcontrol);
  475. struct usb_device *dev = mixer->chip->dev;
  476. u8 bRequest = (kcontrol->private_value >> 16) & 0xff;
  477. u16 wIndex = kcontrol->private_value & 0xffff;
  478. u16 wValue = ucontrol->value.integer.value[0];
  479. int ret;
  480. down_read(&mixer->chip->shutdown_rwsem);
  481. if (mixer->chip->shutdown)
  482. ret = -ENODEV;
  483. else
  484. ret = usb_control_msg(dev, usb_sndctrlpipe(dev, 0), bRequest,
  485. USB_TYPE_VENDOR | USB_RECIP_DEVICE | USB_DIR_OUT,
  486. wValue, wIndex,
  487. NULL, 0, 1000);
  488. up_read(&mixer->chip->shutdown_rwsem);
  489. if (ret < 0) {
  490. snd_printk(KERN_ERR
  491. "unable to issue vendor write request (ret = %d)", ret);
  492. return ret;
  493. }
  494. return 0;
  495. }
  496. static struct snd_kcontrol_new snd_nativeinstruments_ta6_mixers[] = {
  497. {
  498. .name = "Direct Thru Channel A",
  499. .private_value = _MAKE_NI_CONTROL(0x01, 0x03),
  500. },
  501. {
  502. .name = "Direct Thru Channel B",
  503. .private_value = _MAKE_NI_CONTROL(0x01, 0x05),
  504. },
  505. {
  506. .name = "Phono Input Channel A",
  507. .private_value = _MAKE_NI_CONTROL(0x02, 0x03),
  508. },
  509. {
  510. .name = "Phono Input Channel B",
  511. .private_value = _MAKE_NI_CONTROL(0x02, 0x05),
  512. },
  513. };
  514. static struct snd_kcontrol_new snd_nativeinstruments_ta10_mixers[] = {
  515. {
  516. .name = "Direct Thru Channel A",
  517. .private_value = _MAKE_NI_CONTROL(0x01, 0x03),
  518. },
  519. {
  520. .name = "Direct Thru Channel B",
  521. .private_value = _MAKE_NI_CONTROL(0x01, 0x05),
  522. },
  523. {
  524. .name = "Direct Thru Channel C",
  525. .private_value = _MAKE_NI_CONTROL(0x01, 0x07),
  526. },
  527. {
  528. .name = "Direct Thru Channel D",
  529. .private_value = _MAKE_NI_CONTROL(0x01, 0x09),
  530. },
  531. {
  532. .name = "Phono Input Channel A",
  533. .private_value = _MAKE_NI_CONTROL(0x02, 0x03),
  534. },
  535. {
  536. .name = "Phono Input Channel B",
  537. .private_value = _MAKE_NI_CONTROL(0x02, 0x05),
  538. },
  539. {
  540. .name = "Phono Input Channel C",
  541. .private_value = _MAKE_NI_CONTROL(0x02, 0x07),
  542. },
  543. {
  544. .name = "Phono Input Channel D",
  545. .private_value = _MAKE_NI_CONTROL(0x02, 0x09),
  546. },
  547. };
  548. static int snd_nativeinstruments_create_mixer(struct usb_mixer_interface *mixer,
  549. const struct snd_kcontrol_new *kc,
  550. unsigned int count)
  551. {
  552. int i, err = 0;
  553. struct snd_kcontrol_new template = {
  554. .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
  555. .access = SNDRV_CTL_ELEM_ACCESS_READWRITE,
  556. .get = snd_nativeinstruments_control_get,
  557. .put = snd_nativeinstruments_control_put,
  558. .info = snd_ctl_boolean_mono_info,
  559. };
  560. for (i = 0; i < count; i++) {
  561. struct snd_kcontrol *c;
  562. template.name = kc[i].name;
  563. template.private_value = kc[i].private_value;
  564. c = snd_ctl_new1(&template, mixer);
  565. err = snd_ctl_add(mixer->chip->card, c);
  566. if (err < 0)
  567. break;
  568. }
  569. return err;
  570. }
  571. /* M-Audio FastTrack Ultra quirks */
  572. /* FTU Effect switch (also used by C400/C600) */
  573. struct snd_ftu_eff_switch_priv_val {
  574. struct usb_mixer_interface *mixer;
  575. int cached_value;
  576. int is_cached;
  577. int bUnitID;
  578. int validx;
  579. };
  580. static int snd_ftu_eff_switch_info(struct snd_kcontrol *kcontrol,
  581. struct snd_ctl_elem_info *uinfo)
  582. {
  583. static const char *texts[8] = {"Room 1",
  584. "Room 2",
  585. "Room 3",
  586. "Hall 1",
  587. "Hall 2",
  588. "Plate",
  589. "Delay",
  590. "Echo"
  591. };
  592. uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED;
  593. uinfo->count = 1;
  594. uinfo->value.enumerated.items = 8;
  595. if (uinfo->value.enumerated.item > 7)
  596. uinfo->value.enumerated.item = 7;
  597. strcpy(uinfo->value.enumerated.name,
  598. texts[uinfo->value.enumerated.item]);
  599. return 0;
  600. }
  601. static int snd_ftu_eff_switch_get(struct snd_kcontrol *kctl,
  602. struct snd_ctl_elem_value *ucontrol)
  603. {
  604. struct snd_usb_audio *chip;
  605. struct usb_mixer_interface *mixer;
  606. struct snd_ftu_eff_switch_priv_val *pval;
  607. int err;
  608. unsigned char value[2];
  609. int id, validx;
  610. const int val_len = 2;
  611. value[0] = 0x00;
  612. value[1] = 0x00;
  613. pval = (struct snd_ftu_eff_switch_priv_val *)
  614. kctl->private_value;
  615. if (pval->is_cached) {
  616. ucontrol->value.enumerated.item[0] = pval->cached_value;
  617. return 0;
  618. }
  619. mixer = (struct usb_mixer_interface *) pval->mixer;
  620. if (snd_BUG_ON(!mixer))
  621. return -EINVAL;
  622. chip = (struct snd_usb_audio *) mixer->chip;
  623. if (snd_BUG_ON(!chip))
  624. return -EINVAL;
  625. id = pval->bUnitID;
  626. validx = pval->validx;
  627. down_read(&mixer->chip->shutdown_rwsem);
  628. if (mixer->chip->shutdown)
  629. err = -ENODEV;
  630. else
  631. err = snd_usb_ctl_msg(chip->dev,
  632. usb_rcvctrlpipe(chip->dev, 0), UAC_GET_CUR,
  633. USB_RECIP_INTERFACE | USB_TYPE_CLASS | USB_DIR_IN,
  634. validx << 8, snd_usb_ctrl_intf(chip) | (id << 8),
  635. value, val_len);
  636. up_read(&mixer->chip->shutdown_rwsem);
  637. if (err < 0)
  638. return err;
  639. ucontrol->value.enumerated.item[0] = value[0];
  640. pval->cached_value = value[0];
  641. pval->is_cached = 1;
  642. return 0;
  643. }
  644. static int snd_ftu_eff_switch_put(struct snd_kcontrol *kctl,
  645. struct snd_ctl_elem_value *ucontrol)
  646. {
  647. struct snd_usb_audio *chip;
  648. struct snd_ftu_eff_switch_priv_val *pval;
  649. struct usb_mixer_interface *mixer;
  650. int changed, cur_val, err, new_val;
  651. unsigned char value[2];
  652. int id, validx;
  653. const int val_len = 2;
  654. changed = 0;
  655. pval = (struct snd_ftu_eff_switch_priv_val *)
  656. kctl->private_value;
  657. cur_val = pval->cached_value;
  658. new_val = ucontrol->value.enumerated.item[0];
  659. mixer = (struct usb_mixer_interface *) pval->mixer;
  660. if (snd_BUG_ON(!mixer))
  661. return -EINVAL;
  662. chip = (struct snd_usb_audio *) mixer->chip;
  663. if (snd_BUG_ON(!chip))
  664. return -EINVAL;
  665. id = pval->bUnitID;
  666. validx = pval->validx;
  667. if (!pval->is_cached) {
  668. /* Read current value */
  669. down_read(&mixer->chip->shutdown_rwsem);
  670. if (mixer->chip->shutdown)
  671. err = -ENODEV;
  672. else
  673. err = snd_usb_ctl_msg(chip->dev,
  674. usb_rcvctrlpipe(chip->dev, 0), UAC_GET_CUR,
  675. USB_RECIP_INTERFACE | USB_TYPE_CLASS | USB_DIR_IN,
  676. validx << 8, snd_usb_ctrl_intf(chip) | (id << 8),
  677. value, val_len);
  678. up_read(&mixer->chip->shutdown_rwsem);
  679. if (err < 0)
  680. return err;
  681. cur_val = value[0];
  682. pval->cached_value = cur_val;
  683. pval->is_cached = 1;
  684. }
  685. /* update value if needed */
  686. if (cur_val != new_val) {
  687. value[0] = new_val;
  688. value[1] = 0;
  689. down_read(&mixer->chip->shutdown_rwsem);
  690. if (mixer->chip->shutdown)
  691. err = -ENODEV;
  692. else
  693. err = snd_usb_ctl_msg(chip->dev,
  694. usb_sndctrlpipe(chip->dev, 0), UAC_SET_CUR,
  695. USB_RECIP_INTERFACE | USB_TYPE_CLASS | USB_DIR_OUT,
  696. validx << 8, snd_usb_ctrl_intf(chip) | (id << 8),
  697. value, val_len);
  698. up_read(&mixer->chip->shutdown_rwsem);
  699. if (err < 0)
  700. return err;
  701. pval->cached_value = new_val;
  702. pval->is_cached = 1;
  703. changed = 1;
  704. }
  705. return changed;
  706. }
  707. static int snd_ftu_create_effect_switch(struct usb_mixer_interface *mixer,
  708. int validx, int bUnitID)
  709. {
  710. static struct snd_kcontrol_new template = {
  711. .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
  712. .name = "Effect Program Switch",
  713. .index = 0,
  714. .access = SNDRV_CTL_ELEM_ACCESS_READWRITE,
  715. .info = snd_ftu_eff_switch_info,
  716. .get = snd_ftu_eff_switch_get,
  717. .put = snd_ftu_eff_switch_put
  718. };
  719. int err;
  720. struct snd_kcontrol *kctl;
  721. struct snd_ftu_eff_switch_priv_val *pval;
  722. pval = kzalloc(sizeof(*pval), GFP_KERNEL);
  723. if (!pval)
  724. return -ENOMEM;
  725. pval->cached_value = 0;
  726. pval->is_cached = 0;
  727. pval->mixer = mixer;
  728. pval->bUnitID = bUnitID;
  729. pval->validx = validx;
  730. template.private_value = (unsigned long) pval;
  731. kctl = snd_ctl_new1(&template, mixer->chip);
  732. if (!kctl) {
  733. kfree(pval);
  734. return -ENOMEM;
  735. }
  736. err = snd_ctl_add(mixer->chip->card, kctl);
  737. if (err < 0)
  738. return err;
  739. return 0;
  740. }
  741. /* Create volume controls for FTU devices*/
  742. static int snd_ftu_create_volume_ctls(struct usb_mixer_interface *mixer)
  743. {
  744. char name[64];
  745. unsigned int control, cmask;
  746. int in, out, err;
  747. const unsigned int id = 5;
  748. const int val_type = USB_MIXER_S16;
  749. for (out = 0; out < 8; out++) {
  750. control = out + 1;
  751. for (in = 0; in < 8; in++) {
  752. cmask = 1 << in;
  753. snprintf(name, sizeof(name),
  754. "AIn%d - Out%d Capture Volume",
  755. in + 1, out + 1);
  756. err = snd_create_std_mono_ctl(mixer, id, control,
  757. cmask, val_type, name,
  758. &snd_usb_mixer_vol_tlv);
  759. if (err < 0)
  760. return err;
  761. }
  762. for (in = 8; in < 16; in++) {
  763. cmask = 1 << in;
  764. snprintf(name, sizeof(name),
  765. "DIn%d - Out%d Playback Volume",
  766. in - 7, out + 1);
  767. err = snd_create_std_mono_ctl(mixer, id, control,
  768. cmask, val_type, name,
  769. &snd_usb_mixer_vol_tlv);
  770. if (err < 0)
  771. return err;
  772. }
  773. }
  774. return 0;
  775. }
  776. /* This control needs a volume quirk, see mixer.c */
  777. static int snd_ftu_create_effect_volume_ctl(struct usb_mixer_interface *mixer)
  778. {
  779. static const char name[] = "Effect Volume";
  780. const unsigned int id = 6;
  781. const int val_type = USB_MIXER_U8;
  782. const unsigned int control = 2;
  783. const unsigned int cmask = 0;
  784. return snd_create_std_mono_ctl(mixer, id, control, cmask, val_type,
  785. name, snd_usb_mixer_vol_tlv);
  786. }
  787. /* This control needs a volume quirk, see mixer.c */
  788. static int snd_ftu_create_effect_duration_ctl(struct usb_mixer_interface *mixer)
  789. {
  790. static const char name[] = "Effect Duration";
  791. const unsigned int id = 6;
  792. const int val_type = USB_MIXER_S16;
  793. const unsigned int control = 3;
  794. const unsigned int cmask = 0;
  795. return snd_create_std_mono_ctl(mixer, id, control, cmask, val_type,
  796. name, snd_usb_mixer_vol_tlv);
  797. }
  798. /* This control needs a volume quirk, see mixer.c */
  799. static int snd_ftu_create_effect_feedback_ctl(struct usb_mixer_interface *mixer)
  800. {
  801. static const char name[] = "Effect Feedback Volume";
  802. const unsigned int id = 6;
  803. const int val_type = USB_MIXER_U8;
  804. const unsigned int control = 4;
  805. const unsigned int cmask = 0;
  806. return snd_create_std_mono_ctl(mixer, id, control, cmask, val_type,
  807. name, NULL);
  808. }
  809. static int snd_ftu_create_effect_return_ctls(struct usb_mixer_interface *mixer)
  810. {
  811. unsigned int cmask;
  812. int err, ch;
  813. char name[48];
  814. const unsigned int id = 7;
  815. const int val_type = USB_MIXER_S16;
  816. const unsigned int control = 7;
  817. for (ch = 0; ch < 4; ++ch) {
  818. cmask = 1 << ch;
  819. snprintf(name, sizeof(name),
  820. "Effect Return %d Volume", ch + 1);
  821. err = snd_create_std_mono_ctl(mixer, id, control,
  822. cmask, val_type, name,
  823. snd_usb_mixer_vol_tlv);
  824. if (err < 0)
  825. return err;
  826. }
  827. return 0;
  828. }
  829. static int snd_ftu_create_effect_send_ctls(struct usb_mixer_interface *mixer)
  830. {
  831. unsigned int cmask;
  832. int err, ch;
  833. char name[48];
  834. const unsigned int id = 5;
  835. const int val_type = USB_MIXER_S16;
  836. const unsigned int control = 9;
  837. for (ch = 0; ch < 8; ++ch) {
  838. cmask = 1 << ch;
  839. snprintf(name, sizeof(name),
  840. "Effect Send AIn%d Volume", ch + 1);
  841. err = snd_create_std_mono_ctl(mixer, id, control, cmask,
  842. val_type, name,
  843. snd_usb_mixer_vol_tlv);
  844. if (err < 0)
  845. return err;
  846. }
  847. for (ch = 8; ch < 16; ++ch) {
  848. cmask = 1 << ch;
  849. snprintf(name, sizeof(name),
  850. "Effect Send DIn%d Volume", ch - 7);
  851. err = snd_create_std_mono_ctl(mixer, id, control, cmask,
  852. val_type, name,
  853. snd_usb_mixer_vol_tlv);
  854. if (err < 0)
  855. return err;
  856. }
  857. return 0;
  858. }
  859. static int snd_ftu_create_mixer(struct usb_mixer_interface *mixer)
  860. {
  861. int err;
  862. err = snd_ftu_create_volume_ctls(mixer);
  863. if (err < 0)
  864. return err;
  865. err = snd_ftu_create_effect_switch(mixer, 1, 6);
  866. if (err < 0)
  867. return err;
  868. err = snd_ftu_create_effect_volume_ctl(mixer);
  869. if (err < 0)
  870. return err;
  871. err = snd_ftu_create_effect_duration_ctl(mixer);
  872. if (err < 0)
  873. return err;
  874. err = snd_ftu_create_effect_feedback_ctl(mixer);
  875. if (err < 0)
  876. return err;
  877. err = snd_ftu_create_effect_return_ctls(mixer);
  878. if (err < 0)
  879. return err;
  880. err = snd_ftu_create_effect_send_ctls(mixer);
  881. if (err < 0)
  882. return err;
  883. return 0;
  884. }
  885. void snd_emuusb_set_samplerate(struct snd_usb_audio *chip,
  886. unsigned char samplerate_id)
  887. {
  888. struct usb_mixer_interface *mixer;
  889. struct usb_mixer_elem_info *cval;
  890. int unitid = 12; /* SamleRate ExtensionUnit ID */
  891. list_for_each_entry(mixer, &chip->mixer_list, list) {
  892. cval = mixer->id_elems[unitid];
  893. if (cval) {
  894. snd_usb_mixer_set_ctl_value(cval, UAC_SET_CUR,
  895. cval->control << 8,
  896. samplerate_id);
  897. snd_usb_mixer_notify_id(mixer, unitid);
  898. }
  899. break;
  900. }
  901. }
  902. /* M-Audio Fast Track C400/C600 */
  903. /* C400/C600 volume controls, this control needs a volume quirk, see mixer.c */
  904. static int snd_c400_create_vol_ctls(struct usb_mixer_interface *mixer)
  905. {
  906. char name[64];
  907. unsigned int cmask, offset;
  908. int out, chan, err;
  909. int num_outs = 0;
  910. int num_ins = 0;
  911. const unsigned int id = 0x40;
  912. const int val_type = USB_MIXER_S16;
  913. const int control = 1;
  914. switch (mixer->chip->usb_id) {
  915. case USB_ID(0x0763, 0x2030):
  916. num_outs = 6;
  917. num_ins = 4;
  918. break;
  919. case USB_ID(0x0763, 0x2031):
  920. num_outs = 8;
  921. num_ins = 6;
  922. break;
  923. }
  924. for (chan = 0; chan < num_outs + num_ins; chan++) {
  925. for (out = 0; out < num_outs; out++) {
  926. if (chan < num_outs) {
  927. snprintf(name, sizeof(name),
  928. "PCM%d-Out%d Playback Volume",
  929. chan + 1, out + 1);
  930. } else {
  931. snprintf(name, sizeof(name),
  932. "In%d-Out%d Playback Volume",
  933. chan - num_outs + 1, out + 1);
  934. }
  935. cmask = (out == 0) ? 0 : 1 << (out - 1);
  936. offset = chan * num_outs;
  937. err = snd_create_std_mono_ctl_offset(mixer, id, control,
  938. cmask, val_type, offset, name,
  939. &snd_usb_mixer_vol_tlv);
  940. if (err < 0)
  941. return err;
  942. }
  943. }
  944. return 0;
  945. }
  946. /* This control needs a volume quirk, see mixer.c */
  947. static int snd_c400_create_effect_volume_ctl(struct usb_mixer_interface *mixer)
  948. {
  949. static const char name[] = "Effect Volume";
  950. const unsigned int id = 0x43;
  951. const int val_type = USB_MIXER_U8;
  952. const unsigned int control = 3;
  953. const unsigned int cmask = 0;
  954. return snd_create_std_mono_ctl(mixer, id, control, cmask, val_type,
  955. name, snd_usb_mixer_vol_tlv);
  956. }
  957. /* This control needs a volume quirk, see mixer.c */
  958. static int snd_c400_create_effect_duration_ctl(struct usb_mixer_interface *mixer)
  959. {
  960. static const char name[] = "Effect Duration";
  961. const unsigned int id = 0x43;
  962. const int val_type = USB_MIXER_S16;
  963. const unsigned int control = 4;
  964. const unsigned int cmask = 0;
  965. return snd_create_std_mono_ctl(mixer, id, control, cmask, val_type,
  966. name, snd_usb_mixer_vol_tlv);
  967. }
  968. /* This control needs a volume quirk, see mixer.c */
  969. static int snd_c400_create_effect_feedback_ctl(struct usb_mixer_interface *mixer)
  970. {
  971. static const char name[] = "Effect Feedback Volume";
  972. const unsigned int id = 0x43;
  973. const int val_type = USB_MIXER_U8;
  974. const unsigned int control = 5;
  975. const unsigned int cmask = 0;
  976. return snd_create_std_mono_ctl(mixer, id, control, cmask, val_type,
  977. name, NULL);
  978. }
  979. static int snd_c400_create_effect_vol_ctls(struct usb_mixer_interface *mixer)
  980. {
  981. char name[64];
  982. unsigned int cmask;
  983. int chan, err;
  984. int num_outs = 0;
  985. int num_ins = 0;
  986. const unsigned int id = 0x42;
  987. const int val_type = USB_MIXER_S16;
  988. const int control = 1;
  989. switch (mixer->chip->usb_id) {
  990. case USB_ID(0x0763, 0x2030):
  991. num_outs = 6;
  992. num_ins = 4;
  993. break;
  994. case USB_ID(0x0763, 0x2031):
  995. num_outs = 8;
  996. num_ins = 6;
  997. break;
  998. }
  999. for (chan = 0; chan < num_outs + num_ins; chan++) {
  1000. if (chan < num_outs) {
  1001. snprintf(name, sizeof(name),
  1002. "Effect Send DOut%d",
  1003. chan + 1);
  1004. } else {
  1005. snprintf(name, sizeof(name),
  1006. "Effect Send AIn%d",
  1007. chan - num_outs + 1);
  1008. }
  1009. cmask = (chan == 0) ? 0 : 1 << (chan - 1);
  1010. err = snd_create_std_mono_ctl(mixer, id, control,
  1011. cmask, val_type, name,
  1012. &snd_usb_mixer_vol_tlv);
  1013. if (err < 0)
  1014. return err;
  1015. }
  1016. return 0;
  1017. }
  1018. static int snd_c400_create_effect_ret_vol_ctls(struct usb_mixer_interface *mixer)
  1019. {
  1020. char name[64];
  1021. unsigned int cmask;
  1022. int chan, err;
  1023. int num_outs = 0;
  1024. int offset = 0;
  1025. const unsigned int id = 0x40;
  1026. const int val_type = USB_MIXER_S16;
  1027. const int control = 1;
  1028. switch (mixer->chip->usb_id) {
  1029. case USB_ID(0x0763, 0x2030):
  1030. num_outs = 6;
  1031. offset = 0x3c;
  1032. /* { 0x3c, 0x43, 0x3e, 0x45, 0x40, 0x47 } */
  1033. break;
  1034. case USB_ID(0x0763, 0x2031):
  1035. num_outs = 8;
  1036. offset = 0x70;
  1037. /* { 0x70, 0x79, 0x72, 0x7b, 0x74, 0x7d, 0x76, 0x7f } */
  1038. break;
  1039. }
  1040. for (chan = 0; chan < num_outs; chan++) {
  1041. snprintf(name, sizeof(name),
  1042. "Effect Return %d",
  1043. chan + 1);
  1044. cmask = (chan == 0) ? 0 :
  1045. 1 << (chan + (chan % 2) * num_outs - 1);
  1046. err = snd_create_std_mono_ctl_offset(mixer, id, control,
  1047. cmask, val_type, offset, name,
  1048. &snd_usb_mixer_vol_tlv);
  1049. if (err < 0)
  1050. return err;
  1051. }
  1052. return 0;
  1053. }
  1054. static int snd_c400_create_mixer(struct usb_mixer_interface *mixer)
  1055. {
  1056. int err;
  1057. err = snd_c400_create_vol_ctls(mixer);
  1058. if (err < 0)
  1059. return err;
  1060. err = snd_c400_create_effect_vol_ctls(mixer);
  1061. if (err < 0)
  1062. return err;
  1063. err = snd_c400_create_effect_ret_vol_ctls(mixer);
  1064. if (err < 0)
  1065. return err;
  1066. err = snd_ftu_create_effect_switch(mixer, 2, 0x43);
  1067. if (err < 0)
  1068. return err;
  1069. err = snd_c400_create_effect_volume_ctl(mixer);
  1070. if (err < 0)
  1071. return err;
  1072. err = snd_c400_create_effect_duration_ctl(mixer);
  1073. if (err < 0)
  1074. return err;
  1075. err = snd_c400_create_effect_feedback_ctl(mixer);
  1076. if (err < 0)
  1077. return err;
  1078. return 0;
  1079. }
  1080. /*
  1081. * The mixer units for Ebox-44 are corrupt, and even where they
  1082. * are valid they presents mono controls as L and R channels of
  1083. * stereo. So we provide a good mixer here.
  1084. */
  1085. static struct std_mono_table ebox44_table[] = {
  1086. {
  1087. .unitid = 4,
  1088. .control = 1,
  1089. .cmask = 0x0,
  1090. .val_type = USB_MIXER_INV_BOOLEAN,
  1091. .name = "Headphone Playback Switch"
  1092. },
  1093. {
  1094. .unitid = 4,
  1095. .control = 2,
  1096. .cmask = 0x1,
  1097. .val_type = USB_MIXER_S16,
  1098. .name = "Headphone A Mix Playback Volume"
  1099. },
  1100. {
  1101. .unitid = 4,
  1102. .control = 2,
  1103. .cmask = 0x2,
  1104. .val_type = USB_MIXER_S16,
  1105. .name = "Headphone B Mix Playback Volume"
  1106. },
  1107. {
  1108. .unitid = 7,
  1109. .control = 1,
  1110. .cmask = 0x0,
  1111. .val_type = USB_MIXER_INV_BOOLEAN,
  1112. .name = "Output Playback Switch"
  1113. },
  1114. {
  1115. .unitid = 7,
  1116. .control = 2,
  1117. .cmask = 0x1,
  1118. .val_type = USB_MIXER_S16,
  1119. .name = "Output A Playback Volume"
  1120. },
  1121. {
  1122. .unitid = 7,
  1123. .control = 2,
  1124. .cmask = 0x2,
  1125. .val_type = USB_MIXER_S16,
  1126. .name = "Output B Playback Volume"
  1127. },
  1128. {
  1129. .unitid = 10,
  1130. .control = 1,
  1131. .cmask = 0x0,
  1132. .val_type = USB_MIXER_INV_BOOLEAN,
  1133. .name = "Input Capture Switch"
  1134. },
  1135. {
  1136. .unitid = 10,
  1137. .control = 2,
  1138. .cmask = 0x1,
  1139. .val_type = USB_MIXER_S16,
  1140. .name = "Input A Capture Volume"
  1141. },
  1142. {
  1143. .unitid = 10,
  1144. .control = 2,
  1145. .cmask = 0x2,
  1146. .val_type = USB_MIXER_S16,
  1147. .name = "Input B Capture Volume"
  1148. },
  1149. {}
  1150. };
  1151. /* Audio Advantage Micro II findings:
  1152. *
  1153. * Mapping spdif AES bits to vendor register.bit:
  1154. * AES0: [0 0 0 0 2.3 2.2 2.1 2.0] - default 0x00
  1155. * AES1: [3.3 3.2.3.1.3.0 2.7 2.6 2.5 2.4] - default: 0x01
  1156. * AES2: [0 0 0 0 0 0 0 0]
  1157. * AES3: [0 0 0 0 0 0 x 0] - 'x' bit is set basing on standard usb request
  1158. * (UAC_EP_CS_ATTR_SAMPLE_RATE) for Audio Devices
  1159. *
  1160. * power on values:
  1161. * r2: 0x10
  1162. * r3: 0x20 (b7 is zeroed just before playback (except IEC61937) and set
  1163. * just after it to 0xa0, presumably it disables/mutes some analog
  1164. * parts when there is no audio.)
  1165. * r9: 0x28
  1166. *
  1167. * Optical transmitter on/off:
  1168. * vendor register.bit: 9.1
  1169. * 0 - on (0x28 register value)
  1170. * 1 - off (0x2a register value)
  1171. *
  1172. */
  1173. static int snd_microii_spdif_info(struct snd_kcontrol *kcontrol,
  1174. struct snd_ctl_elem_info *uinfo)
  1175. {
  1176. uinfo->type = SNDRV_CTL_ELEM_TYPE_IEC958;
  1177. uinfo->count = 1;
  1178. return 0;
  1179. }
  1180. static int snd_microii_spdif_default_get(struct snd_kcontrol *kcontrol,
  1181. struct snd_ctl_elem_value *ucontrol)
  1182. {
  1183. struct usb_mixer_interface *mixer = snd_kcontrol_chip(kcontrol);
  1184. int err;
  1185. struct usb_interface *iface;
  1186. struct usb_host_interface *alts;
  1187. unsigned int ep;
  1188. unsigned char data[3];
  1189. int rate;
  1190. ucontrol->value.iec958.status[0] = kcontrol->private_value & 0xff;
  1191. ucontrol->value.iec958.status[1] = (kcontrol->private_value >> 8) & 0xff;
  1192. ucontrol->value.iec958.status[2] = 0x00;
  1193. /* use known values for that card: interface#1 altsetting#1 */
  1194. iface = usb_ifnum_to_if(mixer->chip->dev, 1);
  1195. alts = &iface->altsetting[1];
  1196. ep = get_endpoint(alts, 0)->bEndpointAddress;
  1197. err = snd_usb_ctl_msg(mixer->chip->dev,
  1198. usb_rcvctrlpipe(mixer->chip->dev, 0),
  1199. UAC_GET_CUR,
  1200. USB_TYPE_CLASS | USB_RECIP_ENDPOINT | USB_DIR_IN,
  1201. UAC_EP_CS_ATTR_SAMPLE_RATE << 8,
  1202. ep,
  1203. data,
  1204. sizeof(data));
  1205. if (err < 0)
  1206. goto end;
  1207. rate = data[0] | (data[1] << 8) | (data[2] << 16);
  1208. ucontrol->value.iec958.status[3] = (rate == 48000) ?
  1209. IEC958_AES3_CON_FS_48000 : IEC958_AES3_CON_FS_44100;
  1210. err = 0;
  1211. end:
  1212. return err;
  1213. }
  1214. static int snd_microii_spdif_default_put(struct snd_kcontrol *kcontrol,
  1215. struct snd_ctl_elem_value *ucontrol)
  1216. {
  1217. struct usb_mixer_interface *mixer = snd_kcontrol_chip(kcontrol);
  1218. int err;
  1219. u8 reg;
  1220. unsigned long priv_backup = kcontrol->private_value;
  1221. reg = ((ucontrol->value.iec958.status[1] & 0x0f) << 4) |
  1222. (ucontrol->value.iec958.status[0] & 0x0f);
  1223. err = snd_usb_ctl_msg(mixer->chip->dev,
  1224. usb_sndctrlpipe(mixer->chip->dev, 0),
  1225. UAC_SET_CUR,
  1226. USB_DIR_OUT | USB_TYPE_VENDOR | USB_RECIP_OTHER,
  1227. reg,
  1228. 2,
  1229. NULL,
  1230. 0);
  1231. if (err < 0)
  1232. goto end;
  1233. kcontrol->private_value &= 0xfffff0f0;
  1234. kcontrol->private_value |= (ucontrol->value.iec958.status[1] & 0x0f) << 8;
  1235. kcontrol->private_value |= (ucontrol->value.iec958.status[0] & 0x0f);
  1236. reg = (ucontrol->value.iec958.status[0] & IEC958_AES0_NONAUDIO) ?
  1237. 0xa0 : 0x20;
  1238. reg |= (ucontrol->value.iec958.status[1] >> 4) & 0x0f;
  1239. err = snd_usb_ctl_msg(mixer->chip->dev,
  1240. usb_sndctrlpipe(mixer->chip->dev, 0),
  1241. UAC_SET_CUR,
  1242. USB_DIR_OUT | USB_TYPE_VENDOR | USB_RECIP_OTHER,
  1243. reg,
  1244. 3,
  1245. NULL,
  1246. 0);
  1247. if (err < 0)
  1248. goto end;
  1249. kcontrol->private_value &= 0xffff0fff;
  1250. kcontrol->private_value |= (ucontrol->value.iec958.status[1] & 0xf0) << 8;
  1251. /* The frequency bits in AES3 cannot be set via register access. */
  1252. /* Silently ignore any bits from the request that cannot be set. */
  1253. err = (priv_backup != kcontrol->private_value);
  1254. end:
  1255. return err;
  1256. }
  1257. static int snd_microii_spdif_mask_get(struct snd_kcontrol *kcontrol,
  1258. struct snd_ctl_elem_value *ucontrol)
  1259. {
  1260. ucontrol->value.iec958.status[0] = 0x0f;
  1261. ucontrol->value.iec958.status[1] = 0xff;
  1262. ucontrol->value.iec958.status[2] = 0x00;
  1263. ucontrol->value.iec958.status[3] = 0x00;
  1264. return 0;
  1265. }
  1266. static int snd_microii_spdif_switch_get(struct snd_kcontrol *kcontrol,
  1267. struct snd_ctl_elem_value *ucontrol)
  1268. {
  1269. ucontrol->value.integer.value[0] = !(kcontrol->private_value & 0x02);
  1270. return 0;
  1271. }
  1272. static int snd_microii_spdif_switch_put(struct snd_kcontrol *kcontrol,
  1273. struct snd_ctl_elem_value *ucontrol)
  1274. {
  1275. struct usb_mixer_interface *mixer = snd_kcontrol_chip(kcontrol);
  1276. int err;
  1277. u8 reg = ucontrol->value.integer.value[0] ? 0x28 : 0x2a;
  1278. err = snd_usb_ctl_msg(mixer->chip->dev,
  1279. usb_sndctrlpipe(mixer->chip->dev, 0),
  1280. UAC_SET_CUR,
  1281. USB_DIR_OUT | USB_TYPE_VENDOR | USB_RECIP_OTHER,
  1282. reg,
  1283. 9,
  1284. NULL,
  1285. 0);
  1286. if (!err) {
  1287. err = (reg != (kcontrol->private_value & 0x0ff));
  1288. if (err)
  1289. kcontrol->private_value = reg;
  1290. }
  1291. return err;
  1292. }
  1293. static struct snd_kcontrol_new snd_microii_mixer_spdif[] = {
  1294. {
  1295. .iface = SNDRV_CTL_ELEM_IFACE_PCM,
  1296. .name = SNDRV_CTL_NAME_IEC958("", PLAYBACK, DEFAULT),
  1297. .info = snd_microii_spdif_info,
  1298. .get = snd_microii_spdif_default_get,
  1299. .put = snd_microii_spdif_default_put,
  1300. .private_value = 0x00000100UL,/* reset value */
  1301. },
  1302. {
  1303. .access = SNDRV_CTL_ELEM_ACCESS_READ,
  1304. .iface = SNDRV_CTL_ELEM_IFACE_PCM,
  1305. .name = SNDRV_CTL_NAME_IEC958("", PLAYBACK, MASK),
  1306. .info = snd_microii_spdif_info,
  1307. .get = snd_microii_spdif_mask_get,
  1308. },
  1309. {
  1310. .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
  1311. .name = SNDRV_CTL_NAME_IEC958("", PLAYBACK, SWITCH),
  1312. .info = snd_ctl_boolean_mono_info,
  1313. .get = snd_microii_spdif_switch_get,
  1314. .put = snd_microii_spdif_switch_put,
  1315. .private_value = 0x00000028UL,/* reset value */
  1316. }
  1317. };
  1318. static int snd_microii_controls_create(struct usb_mixer_interface *mixer)
  1319. {
  1320. int err, i;
  1321. for (i = 0; i < ARRAY_SIZE(snd_microii_mixer_spdif); ++i) {
  1322. err = snd_ctl_add(mixer->chip->card,
  1323. snd_ctl_new1(&snd_microii_mixer_spdif[i], mixer));
  1324. if (err < 0)
  1325. return err;
  1326. }
  1327. return err;
  1328. }
  1329. int snd_usb_mixer_apply_create_quirk(struct usb_mixer_interface *mixer)
  1330. {
  1331. int err = 0;
  1332. struct snd_info_entry *entry;
  1333. if ((err = snd_usb_soundblaster_remote_init(mixer)) < 0)
  1334. return err;
  1335. switch (mixer->chip->usb_id) {
  1336. case USB_ID(0x041e, 0x3020):
  1337. case USB_ID(0x041e, 0x3040):
  1338. case USB_ID(0x041e, 0x3042):
  1339. case USB_ID(0x041e, 0x30df):
  1340. case USB_ID(0x041e, 0x3048):
  1341. err = snd_audigy2nx_controls_create(mixer);
  1342. if (err < 0)
  1343. break;
  1344. if (!snd_card_proc_new(mixer->chip->card, "audigy2nx", &entry))
  1345. snd_info_set_text_ops(entry, mixer,
  1346. snd_audigy2nx_proc_read);
  1347. break;
  1348. case USB_ID(0x0763, 0x2030): /* M-Audio Fast Track C400 */
  1349. case USB_ID(0x0763, 0x2031): /* M-Audio Fast Track C400 */
  1350. err = snd_c400_create_mixer(mixer);
  1351. break;
  1352. case USB_ID(0x0763, 0x2080): /* M-Audio Fast Track Ultra */
  1353. case USB_ID(0x0763, 0x2081): /* M-Audio Fast Track Ultra 8R */
  1354. err = snd_ftu_create_mixer(mixer);
  1355. break;
  1356. case USB_ID(0x0b05, 0x1739): /* ASUS Xonar U1 */
  1357. case USB_ID(0x0b05, 0x1743): /* ASUS Xonar U1 (2) */
  1358. case USB_ID(0x0b05, 0x17a0): /* ASUS Xonar U3 */
  1359. err = snd_xonar_u1_controls_create(mixer);
  1360. break;
  1361. case USB_ID(0x0d8c, 0x0103): /* Audio Advantage Micro II */
  1362. err = snd_microii_controls_create(mixer);
  1363. break;
  1364. case USB_ID(0x17cc, 0x1011): /* Traktor Audio 6 */
  1365. err = snd_nativeinstruments_create_mixer(mixer,
  1366. snd_nativeinstruments_ta6_mixers,
  1367. ARRAY_SIZE(snd_nativeinstruments_ta6_mixers));
  1368. break;
  1369. case USB_ID(0x17cc, 0x1021): /* Traktor Audio 10 */
  1370. err = snd_nativeinstruments_create_mixer(mixer,
  1371. snd_nativeinstruments_ta10_mixers,
  1372. ARRAY_SIZE(snd_nativeinstruments_ta10_mixers));
  1373. break;
  1374. case USB_ID(0x200c, 0x1018): /* Electrix Ebox-44 */
  1375. /* detection is disabled in mixer_maps.c */
  1376. err = snd_create_std_mono_table(mixer, ebox44_table);
  1377. break;
  1378. }
  1379. return err;
  1380. }
  1381. void snd_usb_mixer_rc_memory_change(struct usb_mixer_interface *mixer,
  1382. int unitid)
  1383. {
  1384. if (!mixer->rc_cfg)
  1385. return;
  1386. /* unit ids specific to Extigy/Audigy 2 NX: */
  1387. switch (unitid) {
  1388. case 0: /* remote control */
  1389. mixer->rc_urb->dev = mixer->chip->dev;
  1390. usb_submit_urb(mixer->rc_urb, GFP_ATOMIC);
  1391. break;
  1392. case 4: /* digital in jack */
  1393. case 7: /* line in jacks */
  1394. case 19: /* speaker out jacks */
  1395. case 20: /* headphones out jack */
  1396. break;
  1397. /* live24ext: 4 = line-in jack */
  1398. case 3: /* hp-out jack (may actuate Mute) */
  1399. if (mixer->chip->usb_id == USB_ID(0x041e, 0x3040) ||
  1400. mixer->chip->usb_id == USB_ID(0x041e, 0x3048))
  1401. snd_usb_mixer_notify_id(mixer, mixer->rc_cfg->mute_mixer_id);
  1402. break;
  1403. default:
  1404. snd_printd(KERN_DEBUG "memory change in unknown unit %d\n", unitid);
  1405. break;
  1406. }
  1407. }