mixer_quirks.c 43 KB

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