mixer_us16x08.c 37 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414
  1. // SPDX-License-Identifier: GPL-2.0-or-later
  2. /*
  3. * Tascam US-16x08 ALSA driver
  4. *
  5. * Copyright (c) 2016 by Detlef Urban ([email protected])
  6. */
  7. #include <linux/slab.h>
  8. #include <linux/usb.h>
  9. #include <linux/usb/audio-v2.h>
  10. #include <sound/core.h>
  11. #include <sound/control.h>
  12. #include "usbaudio.h"
  13. #include "mixer.h"
  14. #include "helper.h"
  15. #include "mixer_us16x08.h"
  16. /* USB control message templates */
  17. static const char route_msg[] = {
  18. 0x61,
  19. 0x02,
  20. 0x03, /* input from master (0x02) or input from computer bus (0x03) */
  21. 0x62,
  22. 0x02,
  23. 0x01, /* input index (0x01/0x02 eq. left/right) or bus (0x01-0x08) */
  24. 0x41,
  25. 0x01,
  26. 0x61,
  27. 0x02,
  28. 0x01,
  29. 0x62,
  30. 0x02,
  31. 0x01, /* output index (0x01-0x08) */
  32. 0x42,
  33. 0x01,
  34. 0x43,
  35. 0x01,
  36. 0x00,
  37. 0x00
  38. };
  39. static const char mix_init_msg1[] = {
  40. 0x71, 0x01, 0x00, 0x00
  41. };
  42. static const char mix_init_msg2[] = {
  43. 0x62, 0x02, 0x00, 0x61, 0x02, 0x04, 0xb1, 0x01, 0x00, 0x00
  44. };
  45. static const char mix_msg_in[] = {
  46. /* default message head, equal to all mixers */
  47. 0x61, 0x02, 0x04, 0x62, 0x02, 0x01,
  48. 0x81, /* 0x06: Controller ID */
  49. 0x02, /* 0x07: */
  50. 0x00, /* 0x08: Value of common mixer */
  51. 0x00,
  52. 0x00
  53. };
  54. static const char mix_msg_out[] = {
  55. /* default message head, equal to all mixers */
  56. 0x61, 0x02, 0x02, 0x62, 0x02, 0x01,
  57. 0x81, /* 0x06: Controller ID */
  58. 0x02, /* 0x07: */
  59. 0x00, /* 0x08: Value of common mixer */
  60. 0x00,
  61. 0x00
  62. };
  63. static const char bypass_msg_out[] = {
  64. 0x45,
  65. 0x02,
  66. 0x01, /* on/off flag */
  67. 0x00,
  68. 0x00
  69. };
  70. static const char bus_msg_out[] = {
  71. 0x44,
  72. 0x02,
  73. 0x01, /* on/off flag */
  74. 0x00,
  75. 0x00
  76. };
  77. static const char comp_msg[] = {
  78. /* default message head, equal to all mixers */
  79. 0x61, 0x02, 0x04, 0x62, 0x02, 0x01,
  80. 0x91,
  81. 0x02,
  82. 0xf0, /* 0x08: Threshold db (8) (e0 ... 00) (+-0dB -- -32dB) x-32 */
  83. 0x92,
  84. 0x02,
  85. 0x0a, /* 0x0b: Ratio (0a,0b,0d,0f,11,14,19,1e,23,28,32,3c,50,a0,ff) */
  86. 0x93,
  87. 0x02,
  88. 0x02, /* 0x0e: Attack (0x02 ... 0xc0) (2ms ... 200ms) */
  89. 0x94,
  90. 0x02,
  91. 0x01, /* 0x11: Release (0x01 ... 0x64) (10ms ... 1000ms) x*10 */
  92. 0x95,
  93. 0x02,
  94. 0x03, /* 0x14: gain (0 ... 20) (0dB .. 20dB) */
  95. 0x96,
  96. 0x02,
  97. 0x01,
  98. 0x97,
  99. 0x02,
  100. 0x01, /* 0x1a: main Comp switch (0 ... 1) (off ... on)) */
  101. 0x00,
  102. 0x00
  103. };
  104. static const char eqs_msq[] = {
  105. /* default message head, equal to all mixers */
  106. 0x61, 0x02, 0x04, 0x62, 0x02, 0x01,
  107. 0x51, /* 0x06: Controller ID */
  108. 0x02,
  109. 0x04, /* 0x08: EQ set num (0x01..0x04) (LOW, LOWMID, HIGHMID, HIGH)) */
  110. 0x52,
  111. 0x02,
  112. 0x0c, /* 0x0b: value dB (0 ... 12) (-12db .. +12db) x-6 */
  113. 0x53,
  114. 0x02,
  115. 0x0f, /* 0x0e: value freq (32-47) (1.7kHz..18kHz) */
  116. 0x54,
  117. 0x02,
  118. 0x02, /* 0x11: band width (0-6) (Q16-Q0.25) 2^x/4 (EQ xxMID only) */
  119. 0x55,
  120. 0x02,
  121. 0x01, /* 0x14: main EQ switch (0 ... 1) (off ... on)) */
  122. 0x00,
  123. 0x00
  124. };
  125. /* compressor ratio map */
  126. static const char ratio_map[] = {
  127. 0x0a, 0x0b, 0x0d, 0x0f, 0x11, 0x14, 0x19, 0x1e,
  128. 0x23, 0x28, 0x32, 0x3c, 0x50, 0xa0, 0xff
  129. };
  130. /* route enumeration names */
  131. static const char *const route_names[] = {
  132. "Master Left", "Master Right", "Output 1", "Output 2", "Output 3",
  133. "Output 4", "Output 5", "Output 6", "Output 7", "Output 8",
  134. };
  135. static int snd_us16x08_recv_urb(struct snd_usb_audio *chip,
  136. unsigned char *buf, int size)
  137. {
  138. mutex_lock(&chip->mutex);
  139. snd_usb_ctl_msg(chip->dev,
  140. usb_rcvctrlpipe(chip->dev, 0),
  141. SND_US16X08_URB_METER_REQUEST,
  142. SND_US16X08_URB_METER_REQUESTTYPE, 0, 0, buf, size);
  143. mutex_unlock(&chip->mutex);
  144. return 0;
  145. }
  146. /* wrapper function to send prepared URB buffer to usb device. Return an error
  147. * code if something went wrong
  148. */
  149. static int snd_us16x08_send_urb(struct snd_usb_audio *chip, char *buf, int size)
  150. {
  151. return snd_usb_ctl_msg(chip->dev, usb_sndctrlpipe(chip->dev, 0),
  152. SND_US16X08_URB_REQUEST, SND_US16X08_URB_REQUESTTYPE,
  153. 0, 0, buf, size);
  154. }
  155. static int snd_us16x08_route_info(struct snd_kcontrol *kcontrol,
  156. struct snd_ctl_elem_info *uinfo)
  157. {
  158. return snd_ctl_enum_info(uinfo, 1, 10, route_names);
  159. }
  160. static int snd_us16x08_route_get(struct snd_kcontrol *kcontrol,
  161. struct snd_ctl_elem_value *ucontrol)
  162. {
  163. struct usb_mixer_elem_info *elem = kcontrol->private_data;
  164. int index = ucontrol->id.index;
  165. /* route has no bias */
  166. ucontrol->value.enumerated.item[0] = elem->cache_val[index];
  167. return 0;
  168. }
  169. static int snd_us16x08_route_put(struct snd_kcontrol *kcontrol,
  170. struct snd_ctl_elem_value *ucontrol)
  171. {
  172. struct usb_mixer_elem_info *elem = kcontrol->private_data;
  173. struct snd_usb_audio *chip = elem->head.mixer->chip;
  174. int index = ucontrol->id.index;
  175. char buf[sizeof(route_msg)];
  176. int val, val_org, err;
  177. /* get the new value (no bias for routes) */
  178. val = ucontrol->value.enumerated.item[0];
  179. /* sanity check */
  180. if (val < 0 || val > 9)
  181. return -EINVAL;
  182. /* prepare the message buffer from template */
  183. memcpy(buf, route_msg, sizeof(route_msg));
  184. if (val < 2) {
  185. /* input comes from a master channel */
  186. val_org = val;
  187. buf[2] = 0x02;
  188. } else {
  189. /* input comes from a computer channel */
  190. buf[2] = 0x03;
  191. val_org = val - 2;
  192. }
  193. /* place new route selection in URB message */
  194. buf[5] = (unsigned char) (val_org & 0x0f) + 1;
  195. /* place route selector in URB message */
  196. buf[13] = index + 1;
  197. err = snd_us16x08_send_urb(chip, buf, sizeof(route_msg));
  198. if (err > 0) {
  199. elem->cached |= 1 << index;
  200. elem->cache_val[index] = val;
  201. } else {
  202. usb_audio_dbg(chip, "Failed to set routing, err:%d\n", err);
  203. }
  204. return err > 0 ? 1 : 0;
  205. }
  206. static int snd_us16x08_master_info(struct snd_kcontrol *kcontrol,
  207. struct snd_ctl_elem_info *uinfo)
  208. {
  209. uinfo->count = 1;
  210. uinfo->type = SNDRV_CTL_ELEM_TYPE_INTEGER;
  211. uinfo->value.integer.max = SND_US16X08_KCMAX(kcontrol);
  212. uinfo->value.integer.min = SND_US16X08_KCMIN(kcontrol);
  213. uinfo->value.integer.step = SND_US16X08_KCSTEP(kcontrol);
  214. return 0;
  215. }
  216. static int snd_us16x08_master_get(struct snd_kcontrol *kcontrol,
  217. struct snd_ctl_elem_value *ucontrol)
  218. {
  219. struct usb_mixer_elem_info *elem = kcontrol->private_data;
  220. int index = ucontrol->id.index;
  221. ucontrol->value.integer.value[0] = elem->cache_val[index];
  222. return 0;
  223. }
  224. static int snd_us16x08_master_put(struct snd_kcontrol *kcontrol,
  225. struct snd_ctl_elem_value *ucontrol)
  226. {
  227. struct usb_mixer_elem_info *elem = kcontrol->private_data;
  228. struct snd_usb_audio *chip = elem->head.mixer->chip;
  229. char buf[sizeof(mix_msg_out)];
  230. int val, err;
  231. int index = ucontrol->id.index;
  232. /* new control value incl. bias*/
  233. val = ucontrol->value.integer.value[0];
  234. /* sanity check */
  235. if (val < SND_US16X08_KCMIN(kcontrol)
  236. || val > SND_US16X08_KCMAX(kcontrol))
  237. return -EINVAL;
  238. /* prepare the message buffer from template */
  239. memcpy(buf, mix_msg_out, sizeof(mix_msg_out));
  240. buf[8] = val - SND_US16X08_KCBIAS(kcontrol);
  241. buf[6] = elem->head.id;
  242. /* place channel selector in URB message */
  243. buf[5] = index + 1;
  244. err = snd_us16x08_send_urb(chip, buf, sizeof(mix_msg_out));
  245. if (err > 0) {
  246. elem->cached |= 1 << index;
  247. elem->cache_val[index] = val;
  248. } else {
  249. usb_audio_dbg(chip, "Failed to set master, err:%d\n", err);
  250. }
  251. return err > 0 ? 1 : 0;
  252. }
  253. static int snd_us16x08_bus_put(struct snd_kcontrol *kcontrol,
  254. struct snd_ctl_elem_value *ucontrol)
  255. {
  256. struct usb_mixer_elem_info *elem = kcontrol->private_data;
  257. struct snd_usb_audio *chip = elem->head.mixer->chip;
  258. char buf[sizeof(mix_msg_out)];
  259. int val, err = 0;
  260. val = ucontrol->value.integer.value[0];
  261. /* prepare the message buffer from template */
  262. switch (elem->head.id) {
  263. case SND_US16X08_ID_BYPASS:
  264. memcpy(buf, bypass_msg_out, sizeof(bypass_msg_out));
  265. buf[2] = val;
  266. err = snd_us16x08_send_urb(chip, buf, sizeof(bypass_msg_out));
  267. break;
  268. case SND_US16X08_ID_BUSS_OUT:
  269. memcpy(buf, bus_msg_out, sizeof(bus_msg_out));
  270. buf[2] = val;
  271. err = snd_us16x08_send_urb(chip, buf, sizeof(bus_msg_out));
  272. break;
  273. case SND_US16X08_ID_MUTE:
  274. memcpy(buf, mix_msg_out, sizeof(mix_msg_out));
  275. buf[8] = val;
  276. buf[6] = elem->head.id;
  277. buf[5] = 1;
  278. err = snd_us16x08_send_urb(chip, buf, sizeof(mix_msg_out));
  279. break;
  280. }
  281. if (err > 0) {
  282. elem->cached |= 1;
  283. elem->cache_val[0] = val;
  284. } else {
  285. usb_audio_dbg(chip, "Failed to set bus parameter, err:%d\n", err);
  286. }
  287. return err > 0 ? 1 : 0;
  288. }
  289. static int snd_us16x08_bus_get(struct snd_kcontrol *kcontrol,
  290. struct snd_ctl_elem_value *ucontrol)
  291. {
  292. struct usb_mixer_elem_info *elem = kcontrol->private_data;
  293. switch (elem->head.id) {
  294. case SND_US16X08_ID_BUSS_OUT:
  295. ucontrol->value.integer.value[0] = elem->cache_val[0];
  296. break;
  297. case SND_US16X08_ID_BYPASS:
  298. ucontrol->value.integer.value[0] = elem->cache_val[0];
  299. break;
  300. case SND_US16X08_ID_MUTE:
  301. ucontrol->value.integer.value[0] = elem->cache_val[0];
  302. break;
  303. }
  304. return 0;
  305. }
  306. /* gets a current mixer value from common store */
  307. static int snd_us16x08_channel_get(struct snd_kcontrol *kcontrol,
  308. struct snd_ctl_elem_value *ucontrol)
  309. {
  310. struct usb_mixer_elem_info *elem = kcontrol->private_data;
  311. int index = ucontrol->id.index;
  312. ucontrol->value.integer.value[0] = elem->cache_val[index];
  313. return 0;
  314. }
  315. static int snd_us16x08_channel_put(struct snd_kcontrol *kcontrol,
  316. struct snd_ctl_elem_value *ucontrol)
  317. {
  318. struct usb_mixer_elem_info *elem = kcontrol->private_data;
  319. struct snd_usb_audio *chip = elem->head.mixer->chip;
  320. char buf[sizeof(mix_msg_in)];
  321. int val, err;
  322. int index = ucontrol->id.index;
  323. val = ucontrol->value.integer.value[0];
  324. /* sanity check */
  325. if (val < SND_US16X08_KCMIN(kcontrol)
  326. || val > SND_US16X08_KCMAX(kcontrol))
  327. return -EINVAL;
  328. /* prepare URB message from template */
  329. memcpy(buf, mix_msg_in, sizeof(mix_msg_in));
  330. /* add the bias to the new value */
  331. buf[8] = val - SND_US16X08_KCBIAS(kcontrol);
  332. buf[6] = elem->head.id;
  333. buf[5] = index + 1;
  334. err = snd_us16x08_send_urb(chip, buf, sizeof(mix_msg_in));
  335. if (err > 0) {
  336. elem->cached |= 1 << index;
  337. elem->cache_val[index] = val;
  338. } else {
  339. usb_audio_dbg(chip, "Failed to set channel, err:%d\n", err);
  340. }
  341. return err > 0 ? 1 : 0;
  342. }
  343. static int snd_us16x08_mix_info(struct snd_kcontrol *kcontrol,
  344. struct snd_ctl_elem_info *uinfo)
  345. {
  346. uinfo->count = 1;
  347. uinfo->type = SNDRV_CTL_ELEM_TYPE_INTEGER;
  348. uinfo->value.integer.max = SND_US16X08_KCMAX(kcontrol);
  349. uinfo->value.integer.min = SND_US16X08_KCMIN(kcontrol);
  350. uinfo->value.integer.step = SND_US16X08_KCSTEP(kcontrol);
  351. return 0;
  352. }
  353. static int snd_us16x08_comp_get(struct snd_kcontrol *kcontrol,
  354. struct snd_ctl_elem_value *ucontrol)
  355. {
  356. struct usb_mixer_elem_info *elem = kcontrol->private_data;
  357. struct snd_us16x08_comp_store *store = elem->private_data;
  358. int index = ucontrol->id.index;
  359. int val_idx = COMP_STORE_IDX(elem->head.id);
  360. ucontrol->value.integer.value[0] = store->val[val_idx][index];
  361. return 0;
  362. }
  363. static int snd_us16x08_comp_put(struct snd_kcontrol *kcontrol,
  364. struct snd_ctl_elem_value *ucontrol)
  365. {
  366. struct usb_mixer_elem_info *elem = kcontrol->private_data;
  367. struct snd_usb_audio *chip = elem->head.mixer->chip;
  368. struct snd_us16x08_comp_store *store = elem->private_data;
  369. int index = ucontrol->id.index;
  370. char buf[sizeof(comp_msg)];
  371. int val_idx, val;
  372. int err;
  373. val = ucontrol->value.integer.value[0];
  374. /* sanity check */
  375. if (val < SND_US16X08_KCMIN(kcontrol)
  376. || val > SND_US16X08_KCMAX(kcontrol))
  377. return -EINVAL;
  378. /* new control value incl. bias*/
  379. val_idx = elem->head.id - SND_US16X08_ID_COMP_BASE;
  380. store->val[val_idx][index] = ucontrol->value.integer.value[0];
  381. /* prepare compressor URB message from template */
  382. memcpy(buf, comp_msg, sizeof(comp_msg));
  383. /* place comp values in message buffer watch bias! */
  384. buf[8] = store->val[
  385. COMP_STORE_IDX(SND_US16X08_ID_COMP_THRESHOLD)][index]
  386. - SND_US16X08_COMP_THRESHOLD_BIAS;
  387. buf[11] = ratio_map[store->val[
  388. COMP_STORE_IDX(SND_US16X08_ID_COMP_RATIO)][index]];
  389. buf[14] = store->val[COMP_STORE_IDX(SND_US16X08_ID_COMP_ATTACK)][index]
  390. + SND_US16X08_COMP_ATTACK_BIAS;
  391. buf[17] = store->val[COMP_STORE_IDX(SND_US16X08_ID_COMP_RELEASE)][index]
  392. + SND_US16X08_COMP_RELEASE_BIAS;
  393. buf[20] = store->val[COMP_STORE_IDX(SND_US16X08_ID_COMP_GAIN)][index];
  394. buf[26] = store->val[COMP_STORE_IDX(SND_US16X08_ID_COMP_SWITCH)][index];
  395. /* place channel selector in message buffer */
  396. buf[5] = index + 1;
  397. err = snd_us16x08_send_urb(chip, buf, sizeof(comp_msg));
  398. if (err > 0) {
  399. elem->cached |= 1 << index;
  400. elem->cache_val[index] = val;
  401. } else {
  402. usb_audio_dbg(chip, "Failed to set compressor, err:%d\n", err);
  403. }
  404. return 1;
  405. }
  406. static int snd_us16x08_eqswitch_get(struct snd_kcontrol *kcontrol,
  407. struct snd_ctl_elem_value *ucontrol)
  408. {
  409. int val;
  410. struct usb_mixer_elem_info *elem = kcontrol->private_data;
  411. struct snd_us16x08_eq_store *store = elem->private_data;
  412. int index = ucontrol->id.index;
  413. /* get low switch from cache is enough, cause all bands are together */
  414. val = store->val[EQ_STORE_BAND_IDX(elem->head.id)]
  415. [EQ_STORE_PARAM_IDX(elem->head.id)][index];
  416. ucontrol->value.integer.value[0] = val;
  417. return 0;
  418. }
  419. static int snd_us16x08_eqswitch_put(struct snd_kcontrol *kcontrol,
  420. struct snd_ctl_elem_value *ucontrol)
  421. {
  422. struct usb_mixer_elem_info *elem = kcontrol->private_data;
  423. struct snd_usb_audio *chip = elem->head.mixer->chip;
  424. struct snd_us16x08_eq_store *store = elem->private_data;
  425. int index = ucontrol->id.index;
  426. char buf[sizeof(eqs_msq)];
  427. int val, err = 0;
  428. int b_idx;
  429. /* new control value incl. bias*/
  430. val = ucontrol->value.integer.value[0] + SND_US16X08_KCBIAS(kcontrol);
  431. /* prepare URB message from EQ template */
  432. memcpy(buf, eqs_msq, sizeof(eqs_msq));
  433. /* place channel index in URB message */
  434. buf[5] = index + 1;
  435. for (b_idx = 0; b_idx < SND_US16X08_ID_EQ_BAND_COUNT; b_idx++) {
  436. /* all four EQ bands have to be enabled/disabled in once */
  437. buf[20] = val;
  438. buf[17] = store->val[b_idx][2][index];
  439. buf[14] = store->val[b_idx][1][index];
  440. buf[11] = store->val[b_idx][0][index];
  441. buf[8] = b_idx + 1;
  442. err = snd_us16x08_send_urb(chip, buf, sizeof(eqs_msq));
  443. if (err < 0)
  444. break;
  445. store->val[b_idx][3][index] = val;
  446. msleep(15);
  447. }
  448. if (err > 0) {
  449. elem->cached |= 1 << index;
  450. elem->cache_val[index] = val;
  451. } else {
  452. usb_audio_dbg(chip, "Failed to set eq switch, err:%d\n", err);
  453. }
  454. return 1;
  455. }
  456. static int snd_us16x08_eq_get(struct snd_kcontrol *kcontrol,
  457. struct snd_ctl_elem_value *ucontrol)
  458. {
  459. int val;
  460. struct usb_mixer_elem_info *elem = kcontrol->private_data;
  461. struct snd_us16x08_eq_store *store = elem->private_data;
  462. int index = ucontrol->id.index;
  463. int b_idx = EQ_STORE_BAND_IDX(elem->head.id) - 1;
  464. int p_idx = EQ_STORE_PARAM_IDX(elem->head.id);
  465. val = store->val[b_idx][p_idx][index];
  466. ucontrol->value.integer.value[0] = val;
  467. return 0;
  468. }
  469. static int snd_us16x08_eq_put(struct snd_kcontrol *kcontrol,
  470. struct snd_ctl_elem_value *ucontrol)
  471. {
  472. struct usb_mixer_elem_info *elem = kcontrol->private_data;
  473. struct snd_usb_audio *chip = elem->head.mixer->chip;
  474. struct snd_us16x08_eq_store *store = elem->private_data;
  475. int index = ucontrol->id.index;
  476. char buf[sizeof(eqs_msq)];
  477. int val, err;
  478. int b_idx = EQ_STORE_BAND_IDX(elem->head.id) - 1;
  479. int p_idx = EQ_STORE_PARAM_IDX(elem->head.id);
  480. val = ucontrol->value.integer.value[0];
  481. /* sanity check */
  482. if (val < SND_US16X08_KCMIN(kcontrol)
  483. || val > SND_US16X08_KCMAX(kcontrol))
  484. return -EINVAL;
  485. /* copy URB buffer from EQ template */
  486. memcpy(buf, eqs_msq, sizeof(eqs_msq));
  487. store->val[b_idx][p_idx][index] = val;
  488. buf[20] = store->val[b_idx][3][index];
  489. buf[17] = store->val[b_idx][2][index];
  490. buf[14] = store->val[b_idx][1][index];
  491. buf[11] = store->val[b_idx][0][index];
  492. /* place channel index in URB buffer */
  493. buf[5] = index + 1;
  494. /* place EQ band in URB buffer */
  495. buf[8] = b_idx + 1;
  496. err = snd_us16x08_send_urb(chip, buf, sizeof(eqs_msq));
  497. if (err > 0) {
  498. /* store new value in EQ band cache */
  499. elem->cached |= 1 << index;
  500. elem->cache_val[index] = val;
  501. } else {
  502. usb_audio_dbg(chip, "Failed to set eq param, err:%d\n", err);
  503. }
  504. return 1;
  505. }
  506. static int snd_us16x08_meter_info(struct snd_kcontrol *kcontrol,
  507. struct snd_ctl_elem_info *uinfo)
  508. {
  509. uinfo->count = 34;
  510. uinfo->type = SNDRV_CTL_ELEM_TYPE_INTEGER;
  511. uinfo->value.integer.max = 0x7FFF;
  512. uinfo->value.integer.min = 0;
  513. return 0;
  514. }
  515. /* calculate compressor index for reduction level request */
  516. static int snd_get_meter_comp_index(struct snd_us16x08_meter_store *store)
  517. {
  518. int ret;
  519. /* any channel active */
  520. if (store->comp_active_index) {
  521. /* check for stereo link */
  522. if (store->comp_active_index & 0x20) {
  523. /* reset comp_index to left channel*/
  524. if (store->comp_index -
  525. store->comp_active_index > 1)
  526. store->comp_index =
  527. store->comp_active_index;
  528. ret = store->comp_index++ & 0x1F;
  529. } else {
  530. /* no stereo link */
  531. ret = store->comp_active_index;
  532. }
  533. } else {
  534. /* skip channels with no compressor active */
  535. while (store->comp_index <= SND_US16X08_MAX_CHANNELS
  536. && !store->comp_store->val[
  537. COMP_STORE_IDX(SND_US16X08_ID_COMP_SWITCH)]
  538. [store->comp_index - 1]) {
  539. store->comp_index++;
  540. }
  541. ret = store->comp_index++;
  542. if (store->comp_index > SND_US16X08_MAX_CHANNELS)
  543. store->comp_index = 1;
  544. }
  545. return ret;
  546. }
  547. /* retrieve the meter level values from URB message */
  548. static void get_meter_levels_from_urb(int s,
  549. struct snd_us16x08_meter_store *store,
  550. u8 *meter_urb)
  551. {
  552. int val = MUC2(meter_urb, s) + (MUC3(meter_urb, s) << 8);
  553. if (MUA0(meter_urb, s) == 0x61 && MUA1(meter_urb, s) == 0x02 &&
  554. MUA2(meter_urb, s) == 0x04 && MUB0(meter_urb, s) == 0x62) {
  555. if (MUC0(meter_urb, s) == 0x72)
  556. store->meter_level[MUB2(meter_urb, s) - 1] = val;
  557. if (MUC0(meter_urb, s) == 0xb2)
  558. store->comp_level[MUB2(meter_urb, s) - 1] = val;
  559. }
  560. if (MUA0(meter_urb, s) == 0x61 && MUA1(meter_urb, s) == 0x02 &&
  561. MUA2(meter_urb, s) == 0x02 && MUB0(meter_urb, s) == 0x62)
  562. store->master_level[MUB2(meter_urb, s) - 1] = val;
  563. }
  564. /* Function to retrieve current meter values from the device.
  565. *
  566. * The device needs to be polled for meter values with an initial
  567. * requests. It will return with a sequence of different meter value
  568. * packages. The first request (case 0:) initiate this meter response sequence.
  569. * After the third response, an additional request can be placed,
  570. * to retrieve compressor reduction level value for given channel. This round
  571. * trip channel selector will skip all inactive compressors.
  572. * A mixer can interrupt this round-trip by selecting one ore two (stereo-link)
  573. * specific channels.
  574. */
  575. static int snd_us16x08_meter_get(struct snd_kcontrol *kcontrol,
  576. struct snd_ctl_elem_value *ucontrol)
  577. {
  578. int i, set;
  579. struct usb_mixer_elem_info *elem = kcontrol->private_data;
  580. struct snd_usb_audio *chip = elem->head.mixer->chip;
  581. struct snd_us16x08_meter_store *store = elem->private_data;
  582. u8 meter_urb[64];
  583. switch (kcontrol->private_value) {
  584. case 0: {
  585. char tmp[sizeof(mix_init_msg1)];
  586. memcpy(tmp, mix_init_msg1, sizeof(mix_init_msg1));
  587. snd_us16x08_send_urb(chip, tmp, 4);
  588. snd_us16x08_recv_urb(chip, meter_urb,
  589. sizeof(meter_urb));
  590. kcontrol->private_value++;
  591. break;
  592. }
  593. case 1:
  594. snd_us16x08_recv_urb(chip, meter_urb,
  595. sizeof(meter_urb));
  596. kcontrol->private_value++;
  597. break;
  598. case 2:
  599. snd_us16x08_recv_urb(chip, meter_urb,
  600. sizeof(meter_urb));
  601. kcontrol->private_value++;
  602. break;
  603. case 3: {
  604. char tmp[sizeof(mix_init_msg2)];
  605. memcpy(tmp, mix_init_msg2, sizeof(mix_init_msg2));
  606. tmp[2] = snd_get_meter_comp_index(store);
  607. snd_us16x08_send_urb(chip, tmp, 10);
  608. snd_us16x08_recv_urb(chip, meter_urb,
  609. sizeof(meter_urb));
  610. kcontrol->private_value = 0;
  611. break;
  612. }
  613. }
  614. for (set = 0; set < 6; set++)
  615. get_meter_levels_from_urb(set, store, meter_urb);
  616. for (i = 0; i < SND_US16X08_MAX_CHANNELS; i++) {
  617. ucontrol->value.integer.value[i] =
  618. store ? store->meter_level[i] : 0;
  619. }
  620. ucontrol->value.integer.value[i++] = store ? store->master_level[0] : 0;
  621. ucontrol->value.integer.value[i++] = store ? store->master_level[1] : 0;
  622. for (i = 2; i < SND_US16X08_MAX_CHANNELS + 2; i++)
  623. ucontrol->value.integer.value[i + SND_US16X08_MAX_CHANNELS] =
  624. store ? store->comp_level[i - 2] : 0;
  625. return 1;
  626. }
  627. static int snd_us16x08_meter_put(struct snd_kcontrol *kcontrol,
  628. struct snd_ctl_elem_value *ucontrol)
  629. {
  630. struct usb_mixer_elem_info *elem = kcontrol->private_data;
  631. struct snd_us16x08_meter_store *store = elem->private_data;
  632. int val;
  633. val = ucontrol->value.integer.value[0];
  634. /* sanity check */
  635. if (val < 0 || val >= SND_US16X08_MAX_CHANNELS)
  636. return -EINVAL;
  637. store->comp_active_index = val;
  638. store->comp_index = val;
  639. return 1;
  640. }
  641. static const struct snd_kcontrol_new snd_us16x08_ch_boolean_ctl = {
  642. .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
  643. .access = SNDRV_CTL_ELEM_ACCESS_READWRITE,
  644. .count = 16,
  645. .info = snd_us16x08_switch_info,
  646. .get = snd_us16x08_channel_get,
  647. .put = snd_us16x08_channel_put,
  648. .private_value = SND_US16X08_KCSET(SND_US16X08_NO_BIAS, 1, 0, 1)
  649. };
  650. static const struct snd_kcontrol_new snd_us16x08_ch_int_ctl = {
  651. .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
  652. .access = SNDRV_CTL_ELEM_ACCESS_READWRITE,
  653. .count = 16,
  654. .info = snd_us16x08_mix_info,
  655. .get = snd_us16x08_channel_get,
  656. .put = snd_us16x08_channel_put,
  657. .private_value = SND_US16X08_KCSET(SND_US16X08_FADER_BIAS, 1, 0, 133)
  658. };
  659. static const struct snd_kcontrol_new snd_us16x08_pan_int_ctl = {
  660. .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
  661. .access = SNDRV_CTL_ELEM_ACCESS_READWRITE,
  662. .count = 16,
  663. .info = snd_us16x08_mix_info,
  664. .get = snd_us16x08_channel_get,
  665. .put = snd_us16x08_channel_put,
  666. .private_value = SND_US16X08_KCSET(SND_US16X08_FADER_BIAS, 1, 0, 255)
  667. };
  668. static const struct snd_kcontrol_new snd_us16x08_master_ctl = {
  669. .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
  670. .access = SNDRV_CTL_ELEM_ACCESS_READWRITE,
  671. .count = 1,
  672. .info = snd_us16x08_master_info,
  673. .get = snd_us16x08_master_get,
  674. .put = snd_us16x08_master_put,
  675. .private_value = SND_US16X08_KCSET(SND_US16X08_FADER_BIAS, 1, 0, 133)
  676. };
  677. static const struct snd_kcontrol_new snd_us16x08_route_ctl = {
  678. .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
  679. .access = SNDRV_CTL_ELEM_ACCESS_READWRITE,
  680. .count = 8,
  681. .info = snd_us16x08_route_info,
  682. .get = snd_us16x08_route_get,
  683. .put = snd_us16x08_route_put,
  684. .private_value = SND_US16X08_KCSET(SND_US16X08_NO_BIAS, 1, 0, 9)
  685. };
  686. static const struct snd_kcontrol_new snd_us16x08_bus_ctl = {
  687. .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
  688. .access = SNDRV_CTL_ELEM_ACCESS_READWRITE,
  689. .count = 1,
  690. .info = snd_us16x08_switch_info,
  691. .get = snd_us16x08_bus_get,
  692. .put = snd_us16x08_bus_put,
  693. .private_value = SND_US16X08_KCSET(SND_US16X08_NO_BIAS, 1, 0, 1)
  694. };
  695. static const struct snd_kcontrol_new snd_us16x08_compswitch_ctl = {
  696. .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
  697. .access = SNDRV_CTL_ELEM_ACCESS_READWRITE,
  698. .count = 16,
  699. .info = snd_us16x08_switch_info,
  700. .get = snd_us16x08_comp_get,
  701. .put = snd_us16x08_comp_put,
  702. .private_value = SND_US16X08_KCSET(SND_US16X08_NO_BIAS, 1, 0, 1)
  703. };
  704. static const struct snd_kcontrol_new snd_us16x08_comp_threshold_ctl = {
  705. .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
  706. .access = SNDRV_CTL_ELEM_ACCESS_READWRITE,
  707. .count = 16,
  708. .info = snd_us16x08_mix_info,
  709. .get = snd_us16x08_comp_get,
  710. .put = snd_us16x08_comp_put,
  711. .private_value = SND_US16X08_KCSET(SND_US16X08_COMP_THRESHOLD_BIAS, 1,
  712. 0, 0x20)
  713. };
  714. static const struct snd_kcontrol_new snd_us16x08_comp_ratio_ctl = {
  715. .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
  716. .access = SNDRV_CTL_ELEM_ACCESS_READWRITE,
  717. .count = 16,
  718. .info = snd_us16x08_mix_info,
  719. .get = snd_us16x08_comp_get,
  720. .put = snd_us16x08_comp_put,
  721. .private_value = SND_US16X08_KCSET(SND_US16X08_NO_BIAS, 1, 0,
  722. sizeof(ratio_map) - 1), /*max*/
  723. };
  724. static const struct snd_kcontrol_new snd_us16x08_comp_gain_ctl = {
  725. .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
  726. .access = SNDRV_CTL_ELEM_ACCESS_READWRITE,
  727. .count = 16,
  728. .info = snd_us16x08_mix_info,
  729. .get = snd_us16x08_comp_get,
  730. .put = snd_us16x08_comp_put,
  731. .private_value = SND_US16X08_KCSET(SND_US16X08_NO_BIAS, 1, 0, 0x14)
  732. };
  733. static const struct snd_kcontrol_new snd_us16x08_comp_attack_ctl = {
  734. .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
  735. .access = SNDRV_CTL_ELEM_ACCESS_READWRITE,
  736. .count = 16,
  737. .info = snd_us16x08_mix_info,
  738. .get = snd_us16x08_comp_get,
  739. .put = snd_us16x08_comp_put,
  740. .private_value =
  741. SND_US16X08_KCSET(SND_US16X08_COMP_ATTACK_BIAS, 1, 0, 0xc6),
  742. };
  743. static const struct snd_kcontrol_new snd_us16x08_comp_release_ctl = {
  744. .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
  745. .access = SNDRV_CTL_ELEM_ACCESS_READWRITE,
  746. .count = 16,
  747. .info = snd_us16x08_mix_info,
  748. .get = snd_us16x08_comp_get,
  749. .put = snd_us16x08_comp_put,
  750. .private_value =
  751. SND_US16X08_KCSET(SND_US16X08_COMP_RELEASE_BIAS, 1, 0, 0x63),
  752. };
  753. static const struct snd_kcontrol_new snd_us16x08_eq_gain_ctl = {
  754. .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
  755. .access = SNDRV_CTL_ELEM_ACCESS_READWRITE,
  756. .count = 16,
  757. .info = snd_us16x08_mix_info,
  758. .get = snd_us16x08_eq_get,
  759. .put = snd_us16x08_eq_put,
  760. .private_value = SND_US16X08_KCSET(SND_US16X08_NO_BIAS, 1, 0, 24),
  761. };
  762. static const struct snd_kcontrol_new snd_us16x08_eq_low_freq_ctl = {
  763. .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
  764. .access = SNDRV_CTL_ELEM_ACCESS_READWRITE,
  765. .count = 16,
  766. .info = snd_us16x08_mix_info,
  767. .get = snd_us16x08_eq_get,
  768. .put = snd_us16x08_eq_put,
  769. .private_value = SND_US16X08_KCSET(SND_US16X08_NO_BIAS, 1, 0, 0x1F),
  770. };
  771. static const struct snd_kcontrol_new snd_us16x08_eq_mid_freq_ctl = {
  772. .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
  773. .access = SNDRV_CTL_ELEM_ACCESS_READWRITE,
  774. .count = 16,
  775. .info = snd_us16x08_mix_info,
  776. .get = snd_us16x08_eq_get,
  777. .put = snd_us16x08_eq_put,
  778. .private_value = SND_US16X08_KCSET(SND_US16X08_NO_BIAS, 1, 0, 0x3F)
  779. };
  780. static const struct snd_kcontrol_new snd_us16x08_eq_mid_width_ctl = {
  781. .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
  782. .access = SNDRV_CTL_ELEM_ACCESS_READWRITE,
  783. .count = 16,
  784. .info = snd_us16x08_mix_info,
  785. .get = snd_us16x08_eq_get,
  786. .put = snd_us16x08_eq_put,
  787. .private_value = SND_US16X08_KCSET(SND_US16X08_NO_BIAS, 1, 0, 0x06)
  788. };
  789. static const struct snd_kcontrol_new snd_us16x08_eq_high_freq_ctl = {
  790. .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
  791. .access = SNDRV_CTL_ELEM_ACCESS_READWRITE,
  792. .count = 16,
  793. .info = snd_us16x08_mix_info,
  794. .get = snd_us16x08_eq_get,
  795. .put = snd_us16x08_eq_put,
  796. .private_value =
  797. SND_US16X08_KCSET(SND_US16X08_EQ_HIGHFREQ_BIAS, 1, 0, 0x1F)
  798. };
  799. static const struct snd_kcontrol_new snd_us16x08_eq_switch_ctl = {
  800. .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
  801. .access = SNDRV_CTL_ELEM_ACCESS_READWRITE,
  802. .count = 16,
  803. .info = snd_us16x08_switch_info,
  804. .get = snd_us16x08_eqswitch_get,
  805. .put = snd_us16x08_eqswitch_put,
  806. .private_value = SND_US16X08_KCSET(SND_US16X08_NO_BIAS, 1, 0, 1)
  807. };
  808. static const struct snd_kcontrol_new snd_us16x08_meter_ctl = {
  809. .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
  810. .access = SNDRV_CTL_ELEM_ACCESS_READWRITE,
  811. .count = 1,
  812. .info = snd_us16x08_meter_info,
  813. .get = snd_us16x08_meter_get,
  814. .put = snd_us16x08_meter_put
  815. };
  816. /* control store preparation */
  817. /* setup compressor store and assign default value */
  818. static struct snd_us16x08_comp_store *snd_us16x08_create_comp_store(void)
  819. {
  820. int i;
  821. struct snd_us16x08_comp_store *tmp;
  822. tmp = kmalloc(sizeof(*tmp), GFP_KERNEL);
  823. if (!tmp)
  824. return NULL;
  825. for (i = 0; i < SND_US16X08_MAX_CHANNELS; i++) {
  826. tmp->val[COMP_STORE_IDX(SND_US16X08_ID_COMP_THRESHOLD)][i]
  827. = 0x20;
  828. tmp->val[COMP_STORE_IDX(SND_US16X08_ID_COMP_RATIO)][i] = 0x00;
  829. tmp->val[COMP_STORE_IDX(SND_US16X08_ID_COMP_GAIN)][i] = 0x00;
  830. tmp->val[COMP_STORE_IDX(SND_US16X08_ID_COMP_SWITCH)][i] = 0x00;
  831. tmp->val[COMP_STORE_IDX(SND_US16X08_ID_COMP_ATTACK)][i] = 0x00;
  832. tmp->val[COMP_STORE_IDX(SND_US16X08_ID_COMP_RELEASE)][i] = 0x00;
  833. }
  834. return tmp;
  835. }
  836. /* setup EQ store and assign default values */
  837. static struct snd_us16x08_eq_store *snd_us16x08_create_eq_store(void)
  838. {
  839. int i, b_idx;
  840. struct snd_us16x08_eq_store *tmp;
  841. tmp = kmalloc(sizeof(*tmp), GFP_KERNEL);
  842. if (!tmp)
  843. return NULL;
  844. for (i = 0; i < SND_US16X08_MAX_CHANNELS; i++) {
  845. for (b_idx = 0; b_idx < SND_US16X08_ID_EQ_BAND_COUNT; b_idx++) {
  846. tmp->val[b_idx][0][i] = 0x0c;
  847. tmp->val[b_idx][3][i] = 0x00;
  848. switch (b_idx) {
  849. case 0: /* EQ Low */
  850. tmp->val[b_idx][1][i] = 0x05;
  851. tmp->val[b_idx][2][i] = 0xff;
  852. break;
  853. case 1: /* EQ Mid low */
  854. tmp->val[b_idx][1][i] = 0x0e;
  855. tmp->val[b_idx][2][i] = 0x02;
  856. break;
  857. case 2: /* EQ Mid High */
  858. tmp->val[b_idx][1][i] = 0x1b;
  859. tmp->val[b_idx][2][i] = 0x02;
  860. break;
  861. case 3: /* EQ High */
  862. tmp->val[b_idx][1][i] = 0x2f
  863. - SND_US16X08_EQ_HIGHFREQ_BIAS;
  864. tmp->val[b_idx][2][i] = 0xff;
  865. break;
  866. }
  867. }
  868. }
  869. return tmp;
  870. }
  871. static struct snd_us16x08_meter_store *snd_us16x08_create_meter_store(void)
  872. {
  873. struct snd_us16x08_meter_store *tmp;
  874. tmp = kzalloc(sizeof(*tmp), GFP_KERNEL);
  875. if (!tmp)
  876. return NULL;
  877. tmp->comp_index = 1;
  878. tmp->comp_active_index = 0;
  879. return tmp;
  880. }
  881. /* release elem->private_free as well; called only once for each *_store */
  882. static void elem_private_free(struct snd_kcontrol *kctl)
  883. {
  884. struct usb_mixer_elem_info *elem = kctl->private_data;
  885. if (elem)
  886. kfree(elem->private_data);
  887. kfree(elem);
  888. kctl->private_data = NULL;
  889. }
  890. static int add_new_ctl(struct usb_mixer_interface *mixer,
  891. const struct snd_kcontrol_new *ncontrol,
  892. int index, int val_type, int channels,
  893. const char *name, void *opt,
  894. bool do_private_free,
  895. struct usb_mixer_elem_info **elem_ret)
  896. {
  897. struct snd_kcontrol *kctl;
  898. struct usb_mixer_elem_info *elem;
  899. int err;
  900. usb_audio_dbg(mixer->chip, "us16x08 add mixer %s\n", name);
  901. elem = kzalloc(sizeof(*elem), GFP_KERNEL);
  902. if (!elem)
  903. return -ENOMEM;
  904. elem->head.mixer = mixer;
  905. elem->head.resume = NULL;
  906. elem->control = 0;
  907. elem->idx_off = 0;
  908. elem->head.id = index;
  909. elem->val_type = val_type;
  910. elem->channels = channels;
  911. elem->private_data = opt;
  912. kctl = snd_ctl_new1(ncontrol, elem);
  913. if (!kctl) {
  914. kfree(elem);
  915. return -ENOMEM;
  916. }
  917. if (do_private_free)
  918. kctl->private_free = elem_private_free;
  919. else
  920. kctl->private_free = snd_usb_mixer_elem_free;
  921. strscpy(kctl->id.name, name, sizeof(kctl->id.name));
  922. err = snd_usb_mixer_add_control(&elem->head, kctl);
  923. if (err < 0)
  924. return err;
  925. if (elem_ret)
  926. *elem_ret = elem;
  927. return 0;
  928. }
  929. /* table of EQ controls */
  930. static const struct snd_us16x08_control_params eq_controls[] = {
  931. { /* EQ switch */
  932. .kcontrol_new = &snd_us16x08_eq_switch_ctl,
  933. .control_id = SND_US16X08_ID_EQENABLE,
  934. .type = USB_MIXER_BOOLEAN,
  935. .num_channels = 16,
  936. .name = "EQ Switch",
  937. },
  938. { /* EQ low gain */
  939. .kcontrol_new = &snd_us16x08_eq_gain_ctl,
  940. .control_id = SND_US16X08_ID_EQLOWLEVEL,
  941. .type = USB_MIXER_U8,
  942. .num_channels = 16,
  943. .name = "EQ Low Volume",
  944. },
  945. { /* EQ low freq */
  946. .kcontrol_new = &snd_us16x08_eq_low_freq_ctl,
  947. .control_id = SND_US16X08_ID_EQLOWFREQ,
  948. .type = USB_MIXER_U8,
  949. .num_channels = 16,
  950. .name = "EQ Low Frequency",
  951. },
  952. { /* EQ mid low gain */
  953. .kcontrol_new = &snd_us16x08_eq_gain_ctl,
  954. .control_id = SND_US16X08_ID_EQLOWMIDLEVEL,
  955. .type = USB_MIXER_U8,
  956. .num_channels = 16,
  957. .name = "EQ MidLow Volume",
  958. },
  959. { /* EQ mid low freq */
  960. .kcontrol_new = &snd_us16x08_eq_mid_freq_ctl,
  961. .control_id = SND_US16X08_ID_EQLOWMIDFREQ,
  962. .type = USB_MIXER_U8,
  963. .num_channels = 16,
  964. .name = "EQ MidLow Frequency",
  965. },
  966. { /* EQ mid low Q */
  967. .kcontrol_new = &snd_us16x08_eq_mid_width_ctl,
  968. .control_id = SND_US16X08_ID_EQLOWMIDWIDTH,
  969. .type = USB_MIXER_U8,
  970. .num_channels = 16,
  971. .name = "EQ MidLow Q",
  972. },
  973. { /* EQ mid high gain */
  974. .kcontrol_new = &snd_us16x08_eq_gain_ctl,
  975. .control_id = SND_US16X08_ID_EQHIGHMIDLEVEL,
  976. .type = USB_MIXER_U8,
  977. .num_channels = 16,
  978. .name = "EQ MidHigh Volume",
  979. },
  980. { /* EQ mid high freq */
  981. .kcontrol_new = &snd_us16x08_eq_mid_freq_ctl,
  982. .control_id = SND_US16X08_ID_EQHIGHMIDFREQ,
  983. .type = USB_MIXER_U8,
  984. .num_channels = 16,
  985. .name = "EQ MidHigh Frequency",
  986. },
  987. { /* EQ mid high Q */
  988. .kcontrol_new = &snd_us16x08_eq_mid_width_ctl,
  989. .control_id = SND_US16X08_ID_EQHIGHMIDWIDTH,
  990. .type = USB_MIXER_U8,
  991. .num_channels = 16,
  992. .name = "EQ MidHigh Q",
  993. },
  994. { /* EQ high gain */
  995. .kcontrol_new = &snd_us16x08_eq_gain_ctl,
  996. .control_id = SND_US16X08_ID_EQHIGHLEVEL,
  997. .type = USB_MIXER_U8,
  998. .num_channels = 16,
  999. .name = "EQ High Volume",
  1000. },
  1001. { /* EQ low freq */
  1002. .kcontrol_new = &snd_us16x08_eq_high_freq_ctl,
  1003. .control_id = SND_US16X08_ID_EQHIGHFREQ,
  1004. .type = USB_MIXER_U8,
  1005. .num_channels = 16,
  1006. .name = "EQ High Frequency",
  1007. },
  1008. };
  1009. /* table of compressor controls */
  1010. static const struct snd_us16x08_control_params comp_controls[] = {
  1011. { /* Comp enable */
  1012. .kcontrol_new = &snd_us16x08_compswitch_ctl,
  1013. .control_id = SND_US16X08_ID_COMP_SWITCH,
  1014. .type = USB_MIXER_BOOLEAN,
  1015. .num_channels = 16,
  1016. .name = "Compressor Switch",
  1017. },
  1018. { /* Comp threshold */
  1019. .kcontrol_new = &snd_us16x08_comp_threshold_ctl,
  1020. .control_id = SND_US16X08_ID_COMP_THRESHOLD,
  1021. .type = USB_MIXER_U8,
  1022. .num_channels = 16,
  1023. .name = "Compressor Threshold Volume",
  1024. },
  1025. { /* Comp ratio */
  1026. .kcontrol_new = &snd_us16x08_comp_ratio_ctl,
  1027. .control_id = SND_US16X08_ID_COMP_RATIO,
  1028. .type = USB_MIXER_U8,
  1029. .num_channels = 16,
  1030. .name = "Compressor Ratio",
  1031. },
  1032. { /* Comp attack */
  1033. .kcontrol_new = &snd_us16x08_comp_attack_ctl,
  1034. .control_id = SND_US16X08_ID_COMP_ATTACK,
  1035. .type = USB_MIXER_U8,
  1036. .num_channels = 16,
  1037. .name = "Compressor Attack",
  1038. },
  1039. { /* Comp release */
  1040. .kcontrol_new = &snd_us16x08_comp_release_ctl,
  1041. .control_id = SND_US16X08_ID_COMP_RELEASE,
  1042. .type = USB_MIXER_U8,
  1043. .num_channels = 16,
  1044. .name = "Compressor Release",
  1045. },
  1046. { /* Comp gain */
  1047. .kcontrol_new = &snd_us16x08_comp_gain_ctl,
  1048. .control_id = SND_US16X08_ID_COMP_GAIN,
  1049. .type = USB_MIXER_U8,
  1050. .num_channels = 16,
  1051. .name = "Compressor Volume",
  1052. },
  1053. };
  1054. /* table of channel controls */
  1055. static const struct snd_us16x08_control_params channel_controls[] = {
  1056. { /* Phase */
  1057. .kcontrol_new = &snd_us16x08_ch_boolean_ctl,
  1058. .control_id = SND_US16X08_ID_PHASE,
  1059. .type = USB_MIXER_BOOLEAN,
  1060. .num_channels = 16,
  1061. .name = "Phase Switch",
  1062. .default_val = 0
  1063. },
  1064. { /* Fader */
  1065. .kcontrol_new = &snd_us16x08_ch_int_ctl,
  1066. .control_id = SND_US16X08_ID_FADER,
  1067. .type = USB_MIXER_U8,
  1068. .num_channels = 16,
  1069. .name = "Line Volume",
  1070. .default_val = 127
  1071. },
  1072. { /* Mute */
  1073. .kcontrol_new = &snd_us16x08_ch_boolean_ctl,
  1074. .control_id = SND_US16X08_ID_MUTE,
  1075. .type = USB_MIXER_BOOLEAN,
  1076. .num_channels = 16,
  1077. .name = "Mute Switch",
  1078. .default_val = 0
  1079. },
  1080. { /* Pan */
  1081. .kcontrol_new = &snd_us16x08_pan_int_ctl,
  1082. .control_id = SND_US16X08_ID_PAN,
  1083. .type = USB_MIXER_U16,
  1084. .num_channels = 16,
  1085. .name = "Pan Left-Right Volume",
  1086. .default_val = 127
  1087. },
  1088. };
  1089. /* table of master controls */
  1090. static const struct snd_us16x08_control_params master_controls[] = {
  1091. { /* Master */
  1092. .kcontrol_new = &snd_us16x08_master_ctl,
  1093. .control_id = SND_US16X08_ID_FADER,
  1094. .type = USB_MIXER_U8,
  1095. .num_channels = 16,
  1096. .name = "Master Volume",
  1097. .default_val = 127
  1098. },
  1099. { /* Bypass */
  1100. .kcontrol_new = &snd_us16x08_bus_ctl,
  1101. .control_id = SND_US16X08_ID_BYPASS,
  1102. .type = USB_MIXER_BOOLEAN,
  1103. .num_channels = 16,
  1104. .name = "DSP Bypass Switch",
  1105. .default_val = 0
  1106. },
  1107. { /* Buss out */
  1108. .kcontrol_new = &snd_us16x08_bus_ctl,
  1109. .control_id = SND_US16X08_ID_BUSS_OUT,
  1110. .type = USB_MIXER_BOOLEAN,
  1111. .num_channels = 16,
  1112. .name = "Buss Out Switch",
  1113. .default_val = 0
  1114. },
  1115. { /* Master mute */
  1116. .kcontrol_new = &snd_us16x08_bus_ctl,
  1117. .control_id = SND_US16X08_ID_MUTE,
  1118. .type = USB_MIXER_BOOLEAN,
  1119. .num_channels = 16,
  1120. .name = "Master Mute Switch",
  1121. .default_val = 0
  1122. },
  1123. };
  1124. int snd_us16x08_controls_create(struct usb_mixer_interface *mixer)
  1125. {
  1126. int i, j;
  1127. int err;
  1128. struct usb_mixer_elem_info *elem;
  1129. struct snd_us16x08_comp_store *comp_store;
  1130. struct snd_us16x08_meter_store *meter_store;
  1131. struct snd_us16x08_eq_store *eq_store;
  1132. /* just check for non-MIDI interface */
  1133. if (mixer->hostif->desc.bInterfaceNumber == 3) {
  1134. /* add routing control */
  1135. err = add_new_ctl(mixer, &snd_us16x08_route_ctl,
  1136. SND_US16X08_ID_ROUTE, USB_MIXER_U8, 8, "Line Out Route",
  1137. NULL, false, &elem);
  1138. if (err < 0) {
  1139. usb_audio_dbg(mixer->chip,
  1140. "Failed to create route control, err:%d\n",
  1141. err);
  1142. return err;
  1143. }
  1144. for (i = 0; i < 8; i++)
  1145. elem->cache_val[i] = i < 2 ? i : i + 2;
  1146. elem->cached = 0xff;
  1147. /* create compressor mixer elements */
  1148. comp_store = snd_us16x08_create_comp_store();
  1149. if (!comp_store)
  1150. return -ENOMEM;
  1151. /* add master controls */
  1152. for (i = 0; i < ARRAY_SIZE(master_controls); i++) {
  1153. err = add_new_ctl(mixer,
  1154. master_controls[i].kcontrol_new,
  1155. master_controls[i].control_id,
  1156. master_controls[i].type,
  1157. master_controls[i].num_channels,
  1158. master_controls[i].name,
  1159. comp_store,
  1160. i == 0, /* release comp_store only once */
  1161. &elem);
  1162. if (err < 0)
  1163. return err;
  1164. elem->cache_val[0] = master_controls[i].default_val;
  1165. elem->cached = 1;
  1166. }
  1167. /* add channel controls */
  1168. for (i = 0; i < ARRAY_SIZE(channel_controls); i++) {
  1169. err = add_new_ctl(mixer,
  1170. channel_controls[i].kcontrol_new,
  1171. channel_controls[i].control_id,
  1172. channel_controls[i].type,
  1173. channel_controls[i].num_channels,
  1174. channel_controls[i].name,
  1175. comp_store,
  1176. false, &elem);
  1177. if (err < 0)
  1178. return err;
  1179. for (j = 0; j < SND_US16X08_MAX_CHANNELS; j++) {
  1180. elem->cache_val[j] =
  1181. channel_controls[i].default_val;
  1182. }
  1183. elem->cached = 0xffff;
  1184. }
  1185. /* create eq store */
  1186. eq_store = snd_us16x08_create_eq_store();
  1187. if (!eq_store)
  1188. return -ENOMEM;
  1189. /* add EQ controls */
  1190. for (i = 0; i < ARRAY_SIZE(eq_controls); i++) {
  1191. err = add_new_ctl(mixer,
  1192. eq_controls[i].kcontrol_new,
  1193. eq_controls[i].control_id,
  1194. eq_controls[i].type,
  1195. eq_controls[i].num_channels,
  1196. eq_controls[i].name,
  1197. eq_store,
  1198. i == 0, /* release eq_store only once */
  1199. NULL);
  1200. if (err < 0)
  1201. return err;
  1202. }
  1203. /* add compressor controls */
  1204. for (i = 0; i < ARRAY_SIZE(comp_controls); i++) {
  1205. err = add_new_ctl(mixer,
  1206. comp_controls[i].kcontrol_new,
  1207. comp_controls[i].control_id,
  1208. comp_controls[i].type,
  1209. comp_controls[i].num_channels,
  1210. comp_controls[i].name,
  1211. comp_store,
  1212. false, NULL);
  1213. if (err < 0)
  1214. return err;
  1215. }
  1216. /* create meters store */
  1217. meter_store = snd_us16x08_create_meter_store();
  1218. if (!meter_store)
  1219. return -ENOMEM;
  1220. /* meter function 'get' must access to compressor store
  1221. * so place a reference here
  1222. */
  1223. meter_store->comp_store = comp_store;
  1224. err = add_new_ctl(mixer, &snd_us16x08_meter_ctl,
  1225. SND_US16X08_ID_METER, USB_MIXER_U16, 0, "Level Meter",
  1226. meter_store, true, NULL);
  1227. if (err < 0)
  1228. return err;
  1229. }
  1230. return 0;
  1231. }