mixer_quirks.c 43 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706
  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. /* EMU0204 */
  393. static int snd_emu0204_ch_switch_info(struct snd_kcontrol *kcontrol,
  394. struct snd_ctl_elem_info *uinfo)
  395. {
  396. static const char *texts[2] = {"1/2",
  397. "3/4"
  398. };
  399. uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED;
  400. uinfo->count = 1;
  401. uinfo->value.enumerated.items = 2;
  402. if (uinfo->value.enumerated.item > 1)
  403. uinfo->value.enumerated.item = 1;
  404. strcpy(uinfo->value.enumerated.name,
  405. texts[uinfo->value.enumerated.item]);
  406. return 0;
  407. }
  408. static int snd_emu0204_ch_switch_get(struct snd_kcontrol *kcontrol,
  409. struct snd_ctl_elem_value *ucontrol)
  410. {
  411. ucontrol->value.enumerated.item[0] = kcontrol->private_value;
  412. return 0;
  413. }
  414. static int snd_emu0204_ch_switch_put(struct snd_kcontrol *kcontrol,
  415. struct snd_ctl_elem_value *ucontrol)
  416. {
  417. struct usb_mixer_interface *mixer = snd_kcontrol_chip(kcontrol);
  418. unsigned int value = ucontrol->value.enumerated.item[0];
  419. int err, changed;
  420. unsigned char buf[2];
  421. if (value > 1)
  422. return -EINVAL;
  423. buf[0] = 0x01;
  424. buf[1] = value ? 0x02 : 0x01;
  425. changed = value != kcontrol->private_value;
  426. down_read(&mixer->chip->shutdown_rwsem);
  427. if (mixer->chip->shutdown) {
  428. err = -ENODEV;
  429. goto out;
  430. }
  431. err = snd_usb_ctl_msg(mixer->chip->dev,
  432. usb_sndctrlpipe(mixer->chip->dev, 0), UAC_SET_CUR,
  433. USB_RECIP_INTERFACE | USB_TYPE_CLASS | USB_DIR_OUT,
  434. 0x0400, 0x0e00, buf, 2);
  435. out:
  436. up_read(&mixer->chip->shutdown_rwsem);
  437. if (err < 0)
  438. return err;
  439. kcontrol->private_value = value;
  440. return changed;
  441. }
  442. static struct snd_kcontrol_new snd_emu0204_controls[] = {
  443. {
  444. .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
  445. .name = "Front Jack Channels",
  446. .info = snd_emu0204_ch_switch_info,
  447. .get = snd_emu0204_ch_switch_get,
  448. .put = snd_emu0204_ch_switch_put,
  449. .private_value = 0,
  450. },
  451. };
  452. static int snd_emu0204_controls_create(struct usb_mixer_interface *mixer)
  453. {
  454. int i, err;
  455. for (i = 0; i < ARRAY_SIZE(snd_emu0204_controls); ++i) {
  456. err = snd_ctl_add(mixer->chip->card,
  457. snd_ctl_new1(&snd_emu0204_controls[i], mixer));
  458. if (err < 0)
  459. return err;
  460. }
  461. return 0;
  462. }
  463. /* ASUS Xonar U1 / U3 controls */
  464. static int snd_xonar_u1_switch_get(struct snd_kcontrol *kcontrol,
  465. struct snd_ctl_elem_value *ucontrol)
  466. {
  467. struct usb_mixer_interface *mixer = snd_kcontrol_chip(kcontrol);
  468. ucontrol->value.integer.value[0] = !!(mixer->xonar_u1_status & 0x02);
  469. return 0;
  470. }
  471. static int snd_xonar_u1_switch_put(struct snd_kcontrol *kcontrol,
  472. struct snd_ctl_elem_value *ucontrol)
  473. {
  474. struct usb_mixer_interface *mixer = snd_kcontrol_chip(kcontrol);
  475. u8 old_status, new_status;
  476. int err, changed;
  477. old_status = mixer->xonar_u1_status;
  478. if (ucontrol->value.integer.value[0])
  479. new_status = old_status | 0x02;
  480. else
  481. new_status = old_status & ~0x02;
  482. changed = new_status != old_status;
  483. down_read(&mixer->chip->shutdown_rwsem);
  484. if (mixer->chip->shutdown)
  485. err = -ENODEV;
  486. else
  487. err = snd_usb_ctl_msg(mixer->chip->dev,
  488. usb_sndctrlpipe(mixer->chip->dev, 0), 0x08,
  489. USB_DIR_OUT | USB_TYPE_VENDOR | USB_RECIP_OTHER,
  490. 50, 0, &new_status, 1);
  491. up_read(&mixer->chip->shutdown_rwsem);
  492. if (err < 0)
  493. return err;
  494. mixer->xonar_u1_status = new_status;
  495. return changed;
  496. }
  497. static struct snd_kcontrol_new snd_xonar_u1_output_switch = {
  498. .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
  499. .name = "Digital Playback Switch",
  500. .info = snd_ctl_boolean_mono_info,
  501. .get = snd_xonar_u1_switch_get,
  502. .put = snd_xonar_u1_switch_put,
  503. };
  504. static int snd_xonar_u1_controls_create(struct usb_mixer_interface *mixer)
  505. {
  506. int err;
  507. err = snd_ctl_add(mixer->chip->card,
  508. snd_ctl_new1(&snd_xonar_u1_output_switch, mixer));
  509. if (err < 0)
  510. return err;
  511. mixer->xonar_u1_status = 0x05;
  512. return 0;
  513. }
  514. /* Native Instruments device quirks */
  515. #define _MAKE_NI_CONTROL(bRequest,wIndex) ((bRequest) << 16 | (wIndex))
  516. static int snd_nativeinstruments_control_get(struct snd_kcontrol *kcontrol,
  517. struct snd_ctl_elem_value *ucontrol)
  518. {
  519. struct usb_mixer_interface *mixer = snd_kcontrol_chip(kcontrol);
  520. struct usb_device *dev = mixer->chip->dev;
  521. u8 bRequest = (kcontrol->private_value >> 16) & 0xff;
  522. u16 wIndex = kcontrol->private_value & 0xffff;
  523. u8 tmp;
  524. int ret;
  525. down_read(&mixer->chip->shutdown_rwsem);
  526. if (mixer->chip->shutdown)
  527. ret = -ENODEV;
  528. else
  529. ret = usb_control_msg(dev, usb_rcvctrlpipe(dev, 0), bRequest,
  530. USB_TYPE_VENDOR | USB_RECIP_DEVICE | USB_DIR_IN,
  531. 0, wIndex,
  532. &tmp, sizeof(tmp), 1000);
  533. up_read(&mixer->chip->shutdown_rwsem);
  534. if (ret < 0) {
  535. snd_printk(KERN_ERR
  536. "unable to issue vendor read request (ret = %d)", ret);
  537. return ret;
  538. }
  539. ucontrol->value.integer.value[0] = tmp;
  540. return 0;
  541. }
  542. static int snd_nativeinstruments_control_put(struct snd_kcontrol *kcontrol,
  543. struct snd_ctl_elem_value *ucontrol)
  544. {
  545. struct usb_mixer_interface *mixer = snd_kcontrol_chip(kcontrol);
  546. struct usb_device *dev = mixer->chip->dev;
  547. u8 bRequest = (kcontrol->private_value >> 16) & 0xff;
  548. u16 wIndex = kcontrol->private_value & 0xffff;
  549. u16 wValue = ucontrol->value.integer.value[0];
  550. int ret;
  551. down_read(&mixer->chip->shutdown_rwsem);
  552. if (mixer->chip->shutdown)
  553. ret = -ENODEV;
  554. else
  555. ret = usb_control_msg(dev, usb_sndctrlpipe(dev, 0), bRequest,
  556. USB_TYPE_VENDOR | USB_RECIP_DEVICE | USB_DIR_OUT,
  557. wValue, wIndex,
  558. NULL, 0, 1000);
  559. up_read(&mixer->chip->shutdown_rwsem);
  560. if (ret < 0) {
  561. snd_printk(KERN_ERR
  562. "unable to issue vendor write request (ret = %d)", ret);
  563. return ret;
  564. }
  565. return 0;
  566. }
  567. static struct snd_kcontrol_new snd_nativeinstruments_ta6_mixers[] = {
  568. {
  569. .name = "Direct Thru Channel A",
  570. .private_value = _MAKE_NI_CONTROL(0x01, 0x03),
  571. },
  572. {
  573. .name = "Direct Thru Channel B",
  574. .private_value = _MAKE_NI_CONTROL(0x01, 0x05),
  575. },
  576. {
  577. .name = "Phono Input Channel A",
  578. .private_value = _MAKE_NI_CONTROL(0x02, 0x03),
  579. },
  580. {
  581. .name = "Phono Input Channel B",
  582. .private_value = _MAKE_NI_CONTROL(0x02, 0x05),
  583. },
  584. };
  585. static struct snd_kcontrol_new snd_nativeinstruments_ta10_mixers[] = {
  586. {
  587. .name = "Direct Thru Channel A",
  588. .private_value = _MAKE_NI_CONTROL(0x01, 0x03),
  589. },
  590. {
  591. .name = "Direct Thru Channel B",
  592. .private_value = _MAKE_NI_CONTROL(0x01, 0x05),
  593. },
  594. {
  595. .name = "Direct Thru Channel C",
  596. .private_value = _MAKE_NI_CONTROL(0x01, 0x07),
  597. },
  598. {
  599. .name = "Direct Thru Channel D",
  600. .private_value = _MAKE_NI_CONTROL(0x01, 0x09),
  601. },
  602. {
  603. .name = "Phono Input Channel A",
  604. .private_value = _MAKE_NI_CONTROL(0x02, 0x03),
  605. },
  606. {
  607. .name = "Phono Input Channel B",
  608. .private_value = _MAKE_NI_CONTROL(0x02, 0x05),
  609. },
  610. {
  611. .name = "Phono Input Channel C",
  612. .private_value = _MAKE_NI_CONTROL(0x02, 0x07),
  613. },
  614. {
  615. .name = "Phono Input Channel D",
  616. .private_value = _MAKE_NI_CONTROL(0x02, 0x09),
  617. },
  618. };
  619. static int snd_nativeinstruments_create_mixer(struct usb_mixer_interface *mixer,
  620. const struct snd_kcontrol_new *kc,
  621. unsigned int count)
  622. {
  623. int i, err = 0;
  624. struct snd_kcontrol_new template = {
  625. .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
  626. .access = SNDRV_CTL_ELEM_ACCESS_READWRITE,
  627. .get = snd_nativeinstruments_control_get,
  628. .put = snd_nativeinstruments_control_put,
  629. .info = snd_ctl_boolean_mono_info,
  630. };
  631. for (i = 0; i < count; i++) {
  632. struct snd_kcontrol *c;
  633. template.name = kc[i].name;
  634. template.private_value = kc[i].private_value;
  635. c = snd_ctl_new1(&template, mixer);
  636. err = snd_ctl_add(mixer->chip->card, c);
  637. if (err < 0)
  638. break;
  639. }
  640. return err;
  641. }
  642. /* M-Audio FastTrack Ultra quirks */
  643. /* FTU Effect switch (also used by C400/C600) */
  644. struct snd_ftu_eff_switch_priv_val {
  645. struct usb_mixer_interface *mixer;
  646. int cached_value;
  647. int is_cached;
  648. int bUnitID;
  649. int validx;
  650. };
  651. static int snd_ftu_eff_switch_info(struct snd_kcontrol *kcontrol,
  652. struct snd_ctl_elem_info *uinfo)
  653. {
  654. static const char *texts[8] = {"Room 1",
  655. "Room 2",
  656. "Room 3",
  657. "Hall 1",
  658. "Hall 2",
  659. "Plate",
  660. "Delay",
  661. "Echo"
  662. };
  663. uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED;
  664. uinfo->count = 1;
  665. uinfo->value.enumerated.items = 8;
  666. if (uinfo->value.enumerated.item > 7)
  667. uinfo->value.enumerated.item = 7;
  668. strcpy(uinfo->value.enumerated.name,
  669. texts[uinfo->value.enumerated.item]);
  670. return 0;
  671. }
  672. static int snd_ftu_eff_switch_get(struct snd_kcontrol *kctl,
  673. struct snd_ctl_elem_value *ucontrol)
  674. {
  675. struct snd_usb_audio *chip;
  676. struct usb_mixer_interface *mixer;
  677. struct snd_ftu_eff_switch_priv_val *pval;
  678. int err;
  679. unsigned char value[2];
  680. int id, validx;
  681. const int val_len = 2;
  682. value[0] = 0x00;
  683. value[1] = 0x00;
  684. pval = (struct snd_ftu_eff_switch_priv_val *)
  685. kctl->private_value;
  686. if (pval->is_cached) {
  687. ucontrol->value.enumerated.item[0] = pval->cached_value;
  688. return 0;
  689. }
  690. mixer = (struct usb_mixer_interface *) pval->mixer;
  691. if (snd_BUG_ON(!mixer))
  692. return -EINVAL;
  693. chip = (struct snd_usb_audio *) mixer->chip;
  694. if (snd_BUG_ON(!chip))
  695. return -EINVAL;
  696. id = pval->bUnitID;
  697. validx = pval->validx;
  698. down_read(&mixer->chip->shutdown_rwsem);
  699. if (mixer->chip->shutdown)
  700. err = -ENODEV;
  701. else
  702. err = snd_usb_ctl_msg(chip->dev,
  703. usb_rcvctrlpipe(chip->dev, 0), UAC_GET_CUR,
  704. USB_RECIP_INTERFACE | USB_TYPE_CLASS | USB_DIR_IN,
  705. validx << 8, snd_usb_ctrl_intf(chip) | (id << 8),
  706. value, val_len);
  707. up_read(&mixer->chip->shutdown_rwsem);
  708. if (err < 0)
  709. return err;
  710. ucontrol->value.enumerated.item[0] = value[0];
  711. pval->cached_value = value[0];
  712. pval->is_cached = 1;
  713. return 0;
  714. }
  715. static int snd_ftu_eff_switch_put(struct snd_kcontrol *kctl,
  716. struct snd_ctl_elem_value *ucontrol)
  717. {
  718. struct snd_usb_audio *chip;
  719. struct snd_ftu_eff_switch_priv_val *pval;
  720. struct usb_mixer_interface *mixer;
  721. int changed, cur_val, err, new_val;
  722. unsigned char value[2];
  723. int id, validx;
  724. const int val_len = 2;
  725. changed = 0;
  726. pval = (struct snd_ftu_eff_switch_priv_val *)
  727. kctl->private_value;
  728. cur_val = pval->cached_value;
  729. new_val = ucontrol->value.enumerated.item[0];
  730. mixer = (struct usb_mixer_interface *) pval->mixer;
  731. if (snd_BUG_ON(!mixer))
  732. return -EINVAL;
  733. chip = (struct snd_usb_audio *) mixer->chip;
  734. if (snd_BUG_ON(!chip))
  735. return -EINVAL;
  736. id = pval->bUnitID;
  737. validx = pval->validx;
  738. if (!pval->is_cached) {
  739. /* Read current value */
  740. down_read(&mixer->chip->shutdown_rwsem);
  741. if (mixer->chip->shutdown)
  742. err = -ENODEV;
  743. else
  744. err = snd_usb_ctl_msg(chip->dev,
  745. usb_rcvctrlpipe(chip->dev, 0), UAC_GET_CUR,
  746. USB_RECIP_INTERFACE | USB_TYPE_CLASS | USB_DIR_IN,
  747. validx << 8, snd_usb_ctrl_intf(chip) | (id << 8),
  748. value, val_len);
  749. up_read(&mixer->chip->shutdown_rwsem);
  750. if (err < 0)
  751. return err;
  752. cur_val = value[0];
  753. pval->cached_value = cur_val;
  754. pval->is_cached = 1;
  755. }
  756. /* update value if needed */
  757. if (cur_val != new_val) {
  758. value[0] = new_val;
  759. value[1] = 0;
  760. down_read(&mixer->chip->shutdown_rwsem);
  761. if (mixer->chip->shutdown)
  762. err = -ENODEV;
  763. else
  764. err = snd_usb_ctl_msg(chip->dev,
  765. usb_sndctrlpipe(chip->dev, 0), UAC_SET_CUR,
  766. USB_RECIP_INTERFACE | USB_TYPE_CLASS | USB_DIR_OUT,
  767. validx << 8, snd_usb_ctrl_intf(chip) | (id << 8),
  768. value, val_len);
  769. up_read(&mixer->chip->shutdown_rwsem);
  770. if (err < 0)
  771. return err;
  772. pval->cached_value = new_val;
  773. pval->is_cached = 1;
  774. changed = 1;
  775. }
  776. return changed;
  777. }
  778. static int snd_ftu_create_effect_switch(struct usb_mixer_interface *mixer,
  779. int validx, int bUnitID)
  780. {
  781. static struct snd_kcontrol_new template = {
  782. .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
  783. .name = "Effect Program Switch",
  784. .index = 0,
  785. .access = SNDRV_CTL_ELEM_ACCESS_READWRITE,
  786. .info = snd_ftu_eff_switch_info,
  787. .get = snd_ftu_eff_switch_get,
  788. .put = snd_ftu_eff_switch_put
  789. };
  790. int err;
  791. struct snd_kcontrol *kctl;
  792. struct snd_ftu_eff_switch_priv_val *pval;
  793. pval = kzalloc(sizeof(*pval), GFP_KERNEL);
  794. if (!pval)
  795. return -ENOMEM;
  796. pval->cached_value = 0;
  797. pval->is_cached = 0;
  798. pval->mixer = mixer;
  799. pval->bUnitID = bUnitID;
  800. pval->validx = validx;
  801. template.private_value = (unsigned long) pval;
  802. kctl = snd_ctl_new1(&template, mixer->chip);
  803. if (!kctl) {
  804. kfree(pval);
  805. return -ENOMEM;
  806. }
  807. err = snd_ctl_add(mixer->chip->card, kctl);
  808. if (err < 0)
  809. return err;
  810. return 0;
  811. }
  812. /* Create volume controls for FTU devices*/
  813. static int snd_ftu_create_volume_ctls(struct usb_mixer_interface *mixer)
  814. {
  815. char name[64];
  816. unsigned int control, cmask;
  817. int in, out, err;
  818. const unsigned int id = 5;
  819. const int val_type = USB_MIXER_S16;
  820. for (out = 0; out < 8; out++) {
  821. control = out + 1;
  822. for (in = 0; in < 8; in++) {
  823. cmask = 1 << in;
  824. snprintf(name, sizeof(name),
  825. "AIn%d - Out%d Capture Volume",
  826. in + 1, out + 1);
  827. err = snd_create_std_mono_ctl(mixer, id, control,
  828. cmask, val_type, name,
  829. &snd_usb_mixer_vol_tlv);
  830. if (err < 0)
  831. return err;
  832. }
  833. for (in = 8; in < 16; in++) {
  834. cmask = 1 << in;
  835. snprintf(name, sizeof(name),
  836. "DIn%d - Out%d Playback Volume",
  837. in - 7, out + 1);
  838. err = snd_create_std_mono_ctl(mixer, id, control,
  839. cmask, val_type, name,
  840. &snd_usb_mixer_vol_tlv);
  841. if (err < 0)
  842. return err;
  843. }
  844. }
  845. return 0;
  846. }
  847. /* This control needs a volume quirk, see mixer.c */
  848. static int snd_ftu_create_effect_volume_ctl(struct usb_mixer_interface *mixer)
  849. {
  850. static const char name[] = "Effect Volume";
  851. const unsigned int id = 6;
  852. const int val_type = USB_MIXER_U8;
  853. const unsigned int control = 2;
  854. const unsigned int cmask = 0;
  855. return snd_create_std_mono_ctl(mixer, id, control, cmask, val_type,
  856. name, snd_usb_mixer_vol_tlv);
  857. }
  858. /* This control needs a volume quirk, see mixer.c */
  859. static int snd_ftu_create_effect_duration_ctl(struct usb_mixer_interface *mixer)
  860. {
  861. static const char name[] = "Effect Duration";
  862. const unsigned int id = 6;
  863. const int val_type = USB_MIXER_S16;
  864. const unsigned int control = 3;
  865. const unsigned int cmask = 0;
  866. return snd_create_std_mono_ctl(mixer, id, control, cmask, val_type,
  867. name, snd_usb_mixer_vol_tlv);
  868. }
  869. /* This control needs a volume quirk, see mixer.c */
  870. static int snd_ftu_create_effect_feedback_ctl(struct usb_mixer_interface *mixer)
  871. {
  872. static const char name[] = "Effect Feedback Volume";
  873. const unsigned int id = 6;
  874. const int val_type = USB_MIXER_U8;
  875. const unsigned int control = 4;
  876. const unsigned int cmask = 0;
  877. return snd_create_std_mono_ctl(mixer, id, control, cmask, val_type,
  878. name, NULL);
  879. }
  880. static int snd_ftu_create_effect_return_ctls(struct usb_mixer_interface *mixer)
  881. {
  882. unsigned int cmask;
  883. int err, ch;
  884. char name[48];
  885. const unsigned int id = 7;
  886. const int val_type = USB_MIXER_S16;
  887. const unsigned int control = 7;
  888. for (ch = 0; ch < 4; ++ch) {
  889. cmask = 1 << ch;
  890. snprintf(name, sizeof(name),
  891. "Effect Return %d Volume", ch + 1);
  892. err = snd_create_std_mono_ctl(mixer, id, control,
  893. cmask, val_type, name,
  894. snd_usb_mixer_vol_tlv);
  895. if (err < 0)
  896. return err;
  897. }
  898. return 0;
  899. }
  900. static int snd_ftu_create_effect_send_ctls(struct usb_mixer_interface *mixer)
  901. {
  902. unsigned int cmask;
  903. int err, ch;
  904. char name[48];
  905. const unsigned int id = 5;
  906. const int val_type = USB_MIXER_S16;
  907. const unsigned int control = 9;
  908. for (ch = 0; ch < 8; ++ch) {
  909. cmask = 1 << ch;
  910. snprintf(name, sizeof(name),
  911. "Effect Send AIn%d Volume", ch + 1);
  912. err = snd_create_std_mono_ctl(mixer, id, control, cmask,
  913. val_type, name,
  914. snd_usb_mixer_vol_tlv);
  915. if (err < 0)
  916. return err;
  917. }
  918. for (ch = 8; ch < 16; ++ch) {
  919. cmask = 1 << ch;
  920. snprintf(name, sizeof(name),
  921. "Effect Send DIn%d Volume", ch - 7);
  922. err = snd_create_std_mono_ctl(mixer, id, control, cmask,
  923. val_type, name,
  924. snd_usb_mixer_vol_tlv);
  925. if (err < 0)
  926. return err;
  927. }
  928. return 0;
  929. }
  930. static int snd_ftu_create_mixer(struct usb_mixer_interface *mixer)
  931. {
  932. int err;
  933. err = snd_ftu_create_volume_ctls(mixer);
  934. if (err < 0)
  935. return err;
  936. err = snd_ftu_create_effect_switch(mixer, 1, 6);
  937. if (err < 0)
  938. return err;
  939. err = snd_ftu_create_effect_volume_ctl(mixer);
  940. if (err < 0)
  941. return err;
  942. err = snd_ftu_create_effect_duration_ctl(mixer);
  943. if (err < 0)
  944. return err;
  945. err = snd_ftu_create_effect_feedback_ctl(mixer);
  946. if (err < 0)
  947. return err;
  948. err = snd_ftu_create_effect_return_ctls(mixer);
  949. if (err < 0)
  950. return err;
  951. err = snd_ftu_create_effect_send_ctls(mixer);
  952. if (err < 0)
  953. return err;
  954. return 0;
  955. }
  956. void snd_emuusb_set_samplerate(struct snd_usb_audio *chip,
  957. unsigned char samplerate_id)
  958. {
  959. struct usb_mixer_interface *mixer;
  960. struct usb_mixer_elem_info *cval;
  961. int unitid = 12; /* SamleRate ExtensionUnit ID */
  962. list_for_each_entry(mixer, &chip->mixer_list, list) {
  963. cval = mixer->id_elems[unitid];
  964. if (cval) {
  965. snd_usb_mixer_set_ctl_value(cval, UAC_SET_CUR,
  966. cval->control << 8,
  967. samplerate_id);
  968. snd_usb_mixer_notify_id(mixer, unitid);
  969. }
  970. break;
  971. }
  972. }
  973. /* M-Audio Fast Track C400/C600 */
  974. /* C400/C600 volume controls, this control needs a volume quirk, see mixer.c */
  975. static int snd_c400_create_vol_ctls(struct usb_mixer_interface *mixer)
  976. {
  977. char name[64];
  978. unsigned int cmask, offset;
  979. int out, chan, err;
  980. int num_outs = 0;
  981. int num_ins = 0;
  982. const unsigned int id = 0x40;
  983. const int val_type = USB_MIXER_S16;
  984. const int control = 1;
  985. switch (mixer->chip->usb_id) {
  986. case USB_ID(0x0763, 0x2030):
  987. num_outs = 6;
  988. num_ins = 4;
  989. break;
  990. case USB_ID(0x0763, 0x2031):
  991. num_outs = 8;
  992. num_ins = 6;
  993. break;
  994. }
  995. for (chan = 0; chan < num_outs + num_ins; chan++) {
  996. for (out = 0; out < num_outs; out++) {
  997. if (chan < num_outs) {
  998. snprintf(name, sizeof(name),
  999. "PCM%d-Out%d Playback Volume",
  1000. chan + 1, out + 1);
  1001. } else {
  1002. snprintf(name, sizeof(name),
  1003. "In%d-Out%d Playback Volume",
  1004. chan - num_outs + 1, out + 1);
  1005. }
  1006. cmask = (out == 0) ? 0 : 1 << (out - 1);
  1007. offset = chan * num_outs;
  1008. err = snd_create_std_mono_ctl_offset(mixer, id, control,
  1009. cmask, val_type, offset, name,
  1010. &snd_usb_mixer_vol_tlv);
  1011. if (err < 0)
  1012. return err;
  1013. }
  1014. }
  1015. return 0;
  1016. }
  1017. /* This control needs a volume quirk, see mixer.c */
  1018. static int snd_c400_create_effect_volume_ctl(struct usb_mixer_interface *mixer)
  1019. {
  1020. static const char name[] = "Effect Volume";
  1021. const unsigned int id = 0x43;
  1022. const int val_type = USB_MIXER_U8;
  1023. const unsigned int control = 3;
  1024. const unsigned int cmask = 0;
  1025. return snd_create_std_mono_ctl(mixer, id, control, cmask, val_type,
  1026. name, snd_usb_mixer_vol_tlv);
  1027. }
  1028. /* This control needs a volume quirk, see mixer.c */
  1029. static int snd_c400_create_effect_duration_ctl(struct usb_mixer_interface *mixer)
  1030. {
  1031. static const char name[] = "Effect Duration";
  1032. const unsigned int id = 0x43;
  1033. const int val_type = USB_MIXER_S16;
  1034. const unsigned int control = 4;
  1035. const unsigned int cmask = 0;
  1036. return snd_create_std_mono_ctl(mixer, id, control, cmask, val_type,
  1037. name, snd_usb_mixer_vol_tlv);
  1038. }
  1039. /* This control needs a volume quirk, see mixer.c */
  1040. static int snd_c400_create_effect_feedback_ctl(struct usb_mixer_interface *mixer)
  1041. {
  1042. static const char name[] = "Effect Feedback Volume";
  1043. const unsigned int id = 0x43;
  1044. const int val_type = USB_MIXER_U8;
  1045. const unsigned int control = 5;
  1046. const unsigned int cmask = 0;
  1047. return snd_create_std_mono_ctl(mixer, id, control, cmask, val_type,
  1048. name, NULL);
  1049. }
  1050. static int snd_c400_create_effect_vol_ctls(struct usb_mixer_interface *mixer)
  1051. {
  1052. char name[64];
  1053. unsigned int cmask;
  1054. int chan, err;
  1055. int num_outs = 0;
  1056. int num_ins = 0;
  1057. const unsigned int id = 0x42;
  1058. const int val_type = USB_MIXER_S16;
  1059. const int control = 1;
  1060. switch (mixer->chip->usb_id) {
  1061. case USB_ID(0x0763, 0x2030):
  1062. num_outs = 6;
  1063. num_ins = 4;
  1064. break;
  1065. case USB_ID(0x0763, 0x2031):
  1066. num_outs = 8;
  1067. num_ins = 6;
  1068. break;
  1069. }
  1070. for (chan = 0; chan < num_outs + num_ins; chan++) {
  1071. if (chan < num_outs) {
  1072. snprintf(name, sizeof(name),
  1073. "Effect Send DOut%d",
  1074. chan + 1);
  1075. } else {
  1076. snprintf(name, sizeof(name),
  1077. "Effect Send AIn%d",
  1078. chan - num_outs + 1);
  1079. }
  1080. cmask = (chan == 0) ? 0 : 1 << (chan - 1);
  1081. err = snd_create_std_mono_ctl(mixer, id, control,
  1082. cmask, val_type, name,
  1083. &snd_usb_mixer_vol_tlv);
  1084. if (err < 0)
  1085. return err;
  1086. }
  1087. return 0;
  1088. }
  1089. static int snd_c400_create_effect_ret_vol_ctls(struct usb_mixer_interface *mixer)
  1090. {
  1091. char name[64];
  1092. unsigned int cmask;
  1093. int chan, err;
  1094. int num_outs = 0;
  1095. int offset = 0;
  1096. const unsigned int id = 0x40;
  1097. const int val_type = USB_MIXER_S16;
  1098. const int control = 1;
  1099. switch (mixer->chip->usb_id) {
  1100. case USB_ID(0x0763, 0x2030):
  1101. num_outs = 6;
  1102. offset = 0x3c;
  1103. /* { 0x3c, 0x43, 0x3e, 0x45, 0x40, 0x47 } */
  1104. break;
  1105. case USB_ID(0x0763, 0x2031):
  1106. num_outs = 8;
  1107. offset = 0x70;
  1108. /* { 0x70, 0x79, 0x72, 0x7b, 0x74, 0x7d, 0x76, 0x7f } */
  1109. break;
  1110. }
  1111. for (chan = 0; chan < num_outs; chan++) {
  1112. snprintf(name, sizeof(name),
  1113. "Effect Return %d",
  1114. chan + 1);
  1115. cmask = (chan == 0) ? 0 :
  1116. 1 << (chan + (chan % 2) * num_outs - 1);
  1117. err = snd_create_std_mono_ctl_offset(mixer, id, control,
  1118. cmask, val_type, offset, name,
  1119. &snd_usb_mixer_vol_tlv);
  1120. if (err < 0)
  1121. return err;
  1122. }
  1123. return 0;
  1124. }
  1125. static int snd_c400_create_mixer(struct usb_mixer_interface *mixer)
  1126. {
  1127. int err;
  1128. err = snd_c400_create_vol_ctls(mixer);
  1129. if (err < 0)
  1130. return err;
  1131. err = snd_c400_create_effect_vol_ctls(mixer);
  1132. if (err < 0)
  1133. return err;
  1134. err = snd_c400_create_effect_ret_vol_ctls(mixer);
  1135. if (err < 0)
  1136. return err;
  1137. err = snd_ftu_create_effect_switch(mixer, 2, 0x43);
  1138. if (err < 0)
  1139. return err;
  1140. err = snd_c400_create_effect_volume_ctl(mixer);
  1141. if (err < 0)
  1142. return err;
  1143. err = snd_c400_create_effect_duration_ctl(mixer);
  1144. if (err < 0)
  1145. return err;
  1146. err = snd_c400_create_effect_feedback_ctl(mixer);
  1147. if (err < 0)
  1148. return err;
  1149. return 0;
  1150. }
  1151. /*
  1152. * The mixer units for Ebox-44 are corrupt, and even where they
  1153. * are valid they presents mono controls as L and R channels of
  1154. * stereo. So we provide a good mixer here.
  1155. */
  1156. static struct std_mono_table ebox44_table[] = {
  1157. {
  1158. .unitid = 4,
  1159. .control = 1,
  1160. .cmask = 0x0,
  1161. .val_type = USB_MIXER_INV_BOOLEAN,
  1162. .name = "Headphone Playback Switch"
  1163. },
  1164. {
  1165. .unitid = 4,
  1166. .control = 2,
  1167. .cmask = 0x1,
  1168. .val_type = USB_MIXER_S16,
  1169. .name = "Headphone A Mix Playback Volume"
  1170. },
  1171. {
  1172. .unitid = 4,
  1173. .control = 2,
  1174. .cmask = 0x2,
  1175. .val_type = USB_MIXER_S16,
  1176. .name = "Headphone B Mix Playback Volume"
  1177. },
  1178. {
  1179. .unitid = 7,
  1180. .control = 1,
  1181. .cmask = 0x0,
  1182. .val_type = USB_MIXER_INV_BOOLEAN,
  1183. .name = "Output Playback Switch"
  1184. },
  1185. {
  1186. .unitid = 7,
  1187. .control = 2,
  1188. .cmask = 0x1,
  1189. .val_type = USB_MIXER_S16,
  1190. .name = "Output A Playback Volume"
  1191. },
  1192. {
  1193. .unitid = 7,
  1194. .control = 2,
  1195. .cmask = 0x2,
  1196. .val_type = USB_MIXER_S16,
  1197. .name = "Output B Playback Volume"
  1198. },
  1199. {
  1200. .unitid = 10,
  1201. .control = 1,
  1202. .cmask = 0x0,
  1203. .val_type = USB_MIXER_INV_BOOLEAN,
  1204. .name = "Input Capture Switch"
  1205. },
  1206. {
  1207. .unitid = 10,
  1208. .control = 2,
  1209. .cmask = 0x1,
  1210. .val_type = USB_MIXER_S16,
  1211. .name = "Input A Capture Volume"
  1212. },
  1213. {
  1214. .unitid = 10,
  1215. .control = 2,
  1216. .cmask = 0x2,
  1217. .val_type = USB_MIXER_S16,
  1218. .name = "Input B Capture Volume"
  1219. },
  1220. {}
  1221. };
  1222. /* Audio Advantage Micro II findings:
  1223. *
  1224. * Mapping spdif AES bits to vendor register.bit:
  1225. * AES0: [0 0 0 0 2.3 2.2 2.1 2.0] - default 0x00
  1226. * AES1: [3.3 3.2.3.1.3.0 2.7 2.6 2.5 2.4] - default: 0x01
  1227. * AES2: [0 0 0 0 0 0 0 0]
  1228. * AES3: [0 0 0 0 0 0 x 0] - 'x' bit is set basing on standard usb request
  1229. * (UAC_EP_CS_ATTR_SAMPLE_RATE) for Audio Devices
  1230. *
  1231. * power on values:
  1232. * r2: 0x10
  1233. * r3: 0x20 (b7 is zeroed just before playback (except IEC61937) and set
  1234. * just after it to 0xa0, presumably it disables/mutes some analog
  1235. * parts when there is no audio.)
  1236. * r9: 0x28
  1237. *
  1238. * Optical transmitter on/off:
  1239. * vendor register.bit: 9.1
  1240. * 0 - on (0x28 register value)
  1241. * 1 - off (0x2a register value)
  1242. *
  1243. */
  1244. static int snd_microii_spdif_info(struct snd_kcontrol *kcontrol,
  1245. struct snd_ctl_elem_info *uinfo)
  1246. {
  1247. uinfo->type = SNDRV_CTL_ELEM_TYPE_IEC958;
  1248. uinfo->count = 1;
  1249. return 0;
  1250. }
  1251. static int snd_microii_spdif_default_get(struct snd_kcontrol *kcontrol,
  1252. struct snd_ctl_elem_value *ucontrol)
  1253. {
  1254. struct usb_mixer_interface *mixer = snd_kcontrol_chip(kcontrol);
  1255. int err;
  1256. struct usb_interface *iface;
  1257. struct usb_host_interface *alts;
  1258. unsigned int ep;
  1259. unsigned char data[3];
  1260. int rate;
  1261. ucontrol->value.iec958.status[0] = kcontrol->private_value & 0xff;
  1262. ucontrol->value.iec958.status[1] = (kcontrol->private_value >> 8) & 0xff;
  1263. ucontrol->value.iec958.status[2] = 0x00;
  1264. /* use known values for that card: interface#1 altsetting#1 */
  1265. iface = usb_ifnum_to_if(mixer->chip->dev, 1);
  1266. alts = &iface->altsetting[1];
  1267. ep = get_endpoint(alts, 0)->bEndpointAddress;
  1268. err = snd_usb_ctl_msg(mixer->chip->dev,
  1269. usb_rcvctrlpipe(mixer->chip->dev, 0),
  1270. UAC_GET_CUR,
  1271. USB_TYPE_CLASS | USB_RECIP_ENDPOINT | USB_DIR_IN,
  1272. UAC_EP_CS_ATTR_SAMPLE_RATE << 8,
  1273. ep,
  1274. data,
  1275. sizeof(data));
  1276. if (err < 0)
  1277. goto end;
  1278. rate = data[0] | (data[1] << 8) | (data[2] << 16);
  1279. ucontrol->value.iec958.status[3] = (rate == 48000) ?
  1280. IEC958_AES3_CON_FS_48000 : IEC958_AES3_CON_FS_44100;
  1281. err = 0;
  1282. end:
  1283. return err;
  1284. }
  1285. static int snd_microii_spdif_default_put(struct snd_kcontrol *kcontrol,
  1286. struct snd_ctl_elem_value *ucontrol)
  1287. {
  1288. struct usb_mixer_interface *mixer = snd_kcontrol_chip(kcontrol);
  1289. int err;
  1290. u8 reg;
  1291. unsigned long priv_backup = kcontrol->private_value;
  1292. reg = ((ucontrol->value.iec958.status[1] & 0x0f) << 4) |
  1293. (ucontrol->value.iec958.status[0] & 0x0f);
  1294. err = snd_usb_ctl_msg(mixer->chip->dev,
  1295. usb_sndctrlpipe(mixer->chip->dev, 0),
  1296. UAC_SET_CUR,
  1297. USB_DIR_OUT | USB_TYPE_VENDOR | USB_RECIP_OTHER,
  1298. reg,
  1299. 2,
  1300. NULL,
  1301. 0);
  1302. if (err < 0)
  1303. goto end;
  1304. kcontrol->private_value &= 0xfffff0f0;
  1305. kcontrol->private_value |= (ucontrol->value.iec958.status[1] & 0x0f) << 8;
  1306. kcontrol->private_value |= (ucontrol->value.iec958.status[0] & 0x0f);
  1307. reg = (ucontrol->value.iec958.status[0] & IEC958_AES0_NONAUDIO) ?
  1308. 0xa0 : 0x20;
  1309. reg |= (ucontrol->value.iec958.status[1] >> 4) & 0x0f;
  1310. err = snd_usb_ctl_msg(mixer->chip->dev,
  1311. usb_sndctrlpipe(mixer->chip->dev, 0),
  1312. UAC_SET_CUR,
  1313. USB_DIR_OUT | USB_TYPE_VENDOR | USB_RECIP_OTHER,
  1314. reg,
  1315. 3,
  1316. NULL,
  1317. 0);
  1318. if (err < 0)
  1319. goto end;
  1320. kcontrol->private_value &= 0xffff0fff;
  1321. kcontrol->private_value |= (ucontrol->value.iec958.status[1] & 0xf0) << 8;
  1322. /* The frequency bits in AES3 cannot be set via register access. */
  1323. /* Silently ignore any bits from the request that cannot be set. */
  1324. err = (priv_backup != kcontrol->private_value);
  1325. end:
  1326. return err;
  1327. }
  1328. static int snd_microii_spdif_mask_get(struct snd_kcontrol *kcontrol,
  1329. struct snd_ctl_elem_value *ucontrol)
  1330. {
  1331. ucontrol->value.iec958.status[0] = 0x0f;
  1332. ucontrol->value.iec958.status[1] = 0xff;
  1333. ucontrol->value.iec958.status[2] = 0x00;
  1334. ucontrol->value.iec958.status[3] = 0x00;
  1335. return 0;
  1336. }
  1337. static int snd_microii_spdif_switch_get(struct snd_kcontrol *kcontrol,
  1338. struct snd_ctl_elem_value *ucontrol)
  1339. {
  1340. ucontrol->value.integer.value[0] = !(kcontrol->private_value & 0x02);
  1341. return 0;
  1342. }
  1343. static int snd_microii_spdif_switch_put(struct snd_kcontrol *kcontrol,
  1344. struct snd_ctl_elem_value *ucontrol)
  1345. {
  1346. struct usb_mixer_interface *mixer = snd_kcontrol_chip(kcontrol);
  1347. int err;
  1348. u8 reg = ucontrol->value.integer.value[0] ? 0x28 : 0x2a;
  1349. err = snd_usb_ctl_msg(mixer->chip->dev,
  1350. usb_sndctrlpipe(mixer->chip->dev, 0),
  1351. UAC_SET_CUR,
  1352. USB_DIR_OUT | USB_TYPE_VENDOR | USB_RECIP_OTHER,
  1353. reg,
  1354. 9,
  1355. NULL,
  1356. 0);
  1357. if (!err) {
  1358. err = (reg != (kcontrol->private_value & 0x0ff));
  1359. if (err)
  1360. kcontrol->private_value = reg;
  1361. }
  1362. return err;
  1363. }
  1364. static struct snd_kcontrol_new snd_microii_mixer_spdif[] = {
  1365. {
  1366. .iface = SNDRV_CTL_ELEM_IFACE_PCM,
  1367. .name = SNDRV_CTL_NAME_IEC958("", PLAYBACK, DEFAULT),
  1368. .info = snd_microii_spdif_info,
  1369. .get = snd_microii_spdif_default_get,
  1370. .put = snd_microii_spdif_default_put,
  1371. .private_value = 0x00000100UL,/* reset value */
  1372. },
  1373. {
  1374. .access = SNDRV_CTL_ELEM_ACCESS_READ,
  1375. .iface = SNDRV_CTL_ELEM_IFACE_PCM,
  1376. .name = SNDRV_CTL_NAME_IEC958("", PLAYBACK, MASK),
  1377. .info = snd_microii_spdif_info,
  1378. .get = snd_microii_spdif_mask_get,
  1379. },
  1380. {
  1381. .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
  1382. .name = SNDRV_CTL_NAME_IEC958("", PLAYBACK, SWITCH),
  1383. .info = snd_ctl_boolean_mono_info,
  1384. .get = snd_microii_spdif_switch_get,
  1385. .put = snd_microii_spdif_switch_put,
  1386. .private_value = 0x00000028UL,/* reset value */
  1387. }
  1388. };
  1389. static int snd_microii_controls_create(struct usb_mixer_interface *mixer)
  1390. {
  1391. int err, i;
  1392. for (i = 0; i < ARRAY_SIZE(snd_microii_mixer_spdif); ++i) {
  1393. err = snd_ctl_add(mixer->chip->card,
  1394. snd_ctl_new1(&snd_microii_mixer_spdif[i], mixer));
  1395. if (err < 0)
  1396. return err;
  1397. }
  1398. return err;
  1399. }
  1400. int snd_usb_mixer_apply_create_quirk(struct usb_mixer_interface *mixer)
  1401. {
  1402. int err = 0;
  1403. struct snd_info_entry *entry;
  1404. if ((err = snd_usb_soundblaster_remote_init(mixer)) < 0)
  1405. return err;
  1406. switch (mixer->chip->usb_id) {
  1407. case USB_ID(0x041e, 0x3020):
  1408. case USB_ID(0x041e, 0x3040):
  1409. case USB_ID(0x041e, 0x3042):
  1410. case USB_ID(0x041e, 0x30df):
  1411. case USB_ID(0x041e, 0x3048):
  1412. err = snd_audigy2nx_controls_create(mixer);
  1413. if (err < 0)
  1414. break;
  1415. if (!snd_card_proc_new(mixer->chip->card, "audigy2nx", &entry))
  1416. snd_info_set_text_ops(entry, mixer,
  1417. snd_audigy2nx_proc_read);
  1418. break;
  1419. /* EMU0204 */
  1420. case USB_ID(0x041e, 0x3f19):
  1421. err = snd_emu0204_controls_create(mixer);
  1422. if (err < 0)
  1423. break;
  1424. break;
  1425. case USB_ID(0x0763, 0x2030): /* M-Audio Fast Track C400 */
  1426. case USB_ID(0x0763, 0x2031): /* M-Audio Fast Track C400 */
  1427. err = snd_c400_create_mixer(mixer);
  1428. break;
  1429. case USB_ID(0x0763, 0x2080): /* M-Audio Fast Track Ultra */
  1430. case USB_ID(0x0763, 0x2081): /* M-Audio Fast Track Ultra 8R */
  1431. err = snd_ftu_create_mixer(mixer);
  1432. break;
  1433. case USB_ID(0x0b05, 0x1739): /* ASUS Xonar U1 */
  1434. case USB_ID(0x0b05, 0x1743): /* ASUS Xonar U1 (2) */
  1435. case USB_ID(0x0b05, 0x17a0): /* ASUS Xonar U3 */
  1436. err = snd_xonar_u1_controls_create(mixer);
  1437. break;
  1438. case USB_ID(0x0d8c, 0x0103): /* Audio Advantage Micro II */
  1439. err = snd_microii_controls_create(mixer);
  1440. break;
  1441. case USB_ID(0x17cc, 0x1011): /* Traktor Audio 6 */
  1442. err = snd_nativeinstruments_create_mixer(mixer,
  1443. snd_nativeinstruments_ta6_mixers,
  1444. ARRAY_SIZE(snd_nativeinstruments_ta6_mixers));
  1445. break;
  1446. case USB_ID(0x17cc, 0x1021): /* Traktor Audio 10 */
  1447. err = snd_nativeinstruments_create_mixer(mixer,
  1448. snd_nativeinstruments_ta10_mixers,
  1449. ARRAY_SIZE(snd_nativeinstruments_ta10_mixers));
  1450. break;
  1451. case USB_ID(0x200c, 0x1018): /* Electrix Ebox-44 */
  1452. /* detection is disabled in mixer_maps.c */
  1453. err = snd_create_std_mono_table(mixer, ebox44_table);
  1454. break;
  1455. }
  1456. return err;
  1457. }
  1458. void snd_usb_mixer_rc_memory_change(struct usb_mixer_interface *mixer,
  1459. int unitid)
  1460. {
  1461. if (!mixer->rc_cfg)
  1462. return;
  1463. /* unit ids specific to Extigy/Audigy 2 NX: */
  1464. switch (unitid) {
  1465. case 0: /* remote control */
  1466. mixer->rc_urb->dev = mixer->chip->dev;
  1467. usb_submit_urb(mixer->rc_urb, GFP_ATOMIC);
  1468. break;
  1469. case 4: /* digital in jack */
  1470. case 7: /* line in jacks */
  1471. case 19: /* speaker out jacks */
  1472. case 20: /* headphones out jack */
  1473. break;
  1474. /* live24ext: 4 = line-in jack */
  1475. case 3: /* hp-out jack (may actuate Mute) */
  1476. if (mixer->chip->usb_id == USB_ID(0x041e, 0x3040) ||
  1477. mixer->chip->usb_id == USB_ID(0x041e, 0x3048))
  1478. snd_usb_mixer_notify_id(mixer, mixer->rc_cfg->mute_mixer_id);
  1479. break;
  1480. default:
  1481. snd_printd(KERN_DEBUG "memory change in unknown unit %d\n", unitid);
  1482. break;
  1483. }
  1484. }