control.c 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621
  1. /*
  2. * Linux driver for TerraTec DMX 6Fire USB
  3. *
  4. * Mixer control
  5. *
  6. * Author: Torsten Schenk <torsten.schenk@zoho.com>
  7. * Created: Jan 01, 2011
  8. * Copyright: (C) Torsten Schenk
  9. *
  10. * Thanks to:
  11. * - Holger Ruckdeschel: he found out how to control individual channel
  12. * volumes and introduced mute switch
  13. *
  14. * This program is free software; you can redistribute it and/or modify
  15. * it under the terms of the GNU General Public License as published by
  16. * the Free Software Foundation; either version 2 of the License, or
  17. * (at your option) any later version.
  18. */
  19. #include <linux/interrupt.h>
  20. #include <sound/control.h>
  21. #include <sound/tlv.h>
  22. #include "control.h"
  23. #include "comm.h"
  24. #include "chip.h"
  25. static const char * const opt_coax_texts[2] = { "Optical", "Coax" };
  26. static const char * const line_phono_texts[2] = { "Line", "Phono" };
  27. /*
  28. * data that needs to be sent to device. sets up card internal stuff.
  29. * values dumped from windows driver and filtered by trial'n'error.
  30. */
  31. static const struct {
  32. u8 type;
  33. u8 reg;
  34. u8 value;
  35. }
  36. init_data[] = {
  37. { 0x22, 0x00, 0x00 }, { 0x20, 0x00, 0x08 }, { 0x22, 0x01, 0x01 },
  38. { 0x20, 0x01, 0x08 }, { 0x22, 0x02, 0x00 }, { 0x20, 0x02, 0x08 },
  39. { 0x22, 0x03, 0x00 }, { 0x20, 0x03, 0x08 }, { 0x22, 0x04, 0x00 },
  40. { 0x20, 0x04, 0x08 }, { 0x22, 0x05, 0x01 }, { 0x20, 0x05, 0x08 },
  41. { 0x22, 0x04, 0x01 }, { 0x12, 0x04, 0x00 }, { 0x12, 0x05, 0x00 },
  42. { 0x12, 0x0d, 0x38 }, { 0x12, 0x21, 0x82 }, { 0x12, 0x22, 0x80 },
  43. { 0x12, 0x23, 0x00 }, { 0x12, 0x06, 0x02 }, { 0x12, 0x03, 0x00 },
  44. { 0x12, 0x02, 0x00 }, { 0x22, 0x03, 0x01 },
  45. { 0 } /* TERMINATING ENTRY */
  46. };
  47. static const int rates_altsetting[] = { 1, 1, 2, 2, 3, 3 };
  48. /* values to write to soundcard register for all samplerates */
  49. static const u16 rates_6fire_vl[] = {0x00, 0x01, 0x00, 0x01, 0x00, 0x01};
  50. static const u16 rates_6fire_vh[] = {0x11, 0x11, 0x10, 0x10, 0x00, 0x00};
  51. static DECLARE_TLV_DB_MINMAX(tlv_output, -9000, 0);
  52. static DECLARE_TLV_DB_MINMAX(tlv_input, -1500, 1500);
  53. enum {
  54. DIGITAL_THRU_ONLY_SAMPLERATE = 3
  55. };
  56. static void usb6fire_control_output_vol_update(struct control_runtime *rt)
  57. {
  58. struct comm_runtime *comm_rt = rt->chip->comm;
  59. int i;
  60. if (comm_rt)
  61. for (i = 0; i < 6; i++)
  62. if (!(rt->ovol_updated & (1 << i))) {
  63. comm_rt->write8(comm_rt, 0x12, 0x0f + i,
  64. 180 - rt->output_vol[i]);
  65. rt->ovol_updated |= 1 << i;
  66. }
  67. }
  68. static void usb6fire_control_output_mute_update(struct control_runtime *rt)
  69. {
  70. struct comm_runtime *comm_rt = rt->chip->comm;
  71. if (comm_rt)
  72. comm_rt->write8(comm_rt, 0x12, 0x0e, ~rt->output_mute);
  73. }
  74. static void usb6fire_control_input_vol_update(struct control_runtime *rt)
  75. {
  76. struct comm_runtime *comm_rt = rt->chip->comm;
  77. int i;
  78. if (comm_rt)
  79. for (i = 0; i < 2; i++)
  80. if (!(rt->ivol_updated & (1 << i))) {
  81. comm_rt->write8(comm_rt, 0x12, 0x1c + i,
  82. rt->input_vol[i] & 0x3f);
  83. rt->ivol_updated |= 1 << i;
  84. }
  85. }
  86. static void usb6fire_control_line_phono_update(struct control_runtime *rt)
  87. {
  88. struct comm_runtime *comm_rt = rt->chip->comm;
  89. if (comm_rt) {
  90. comm_rt->write8(comm_rt, 0x22, 0x02, rt->line_phono_switch);
  91. comm_rt->write8(comm_rt, 0x21, 0x02, rt->line_phono_switch);
  92. }
  93. }
  94. static void usb6fire_control_opt_coax_update(struct control_runtime *rt)
  95. {
  96. struct comm_runtime *comm_rt = rt->chip->comm;
  97. if (comm_rt) {
  98. comm_rt->write8(comm_rt, 0x22, 0x00, rt->opt_coax_switch);
  99. comm_rt->write8(comm_rt, 0x21, 0x00, rt->opt_coax_switch);
  100. }
  101. }
  102. static int usb6fire_control_set_rate(struct control_runtime *rt, int rate)
  103. {
  104. int ret;
  105. struct usb_device *device = rt->chip->dev;
  106. struct comm_runtime *comm_rt = rt->chip->comm;
  107. if (rate < 0 || rate >= CONTROL_N_RATES)
  108. return -EINVAL;
  109. ret = usb_set_interface(device, 1, rates_altsetting[rate]);
  110. if (ret < 0)
  111. return ret;
  112. /* set soundcard clock */
  113. ret = comm_rt->write16(comm_rt, 0x02, 0x01, rates_6fire_vl[rate],
  114. rates_6fire_vh[rate]);
  115. if (ret < 0)
  116. return ret;
  117. return 0;
  118. }
  119. static int usb6fire_control_set_channels(
  120. struct control_runtime *rt, int n_analog_out,
  121. int n_analog_in, bool spdif_out, bool spdif_in)
  122. {
  123. int ret;
  124. struct comm_runtime *comm_rt = rt->chip->comm;
  125. /* enable analog inputs and outputs
  126. * (one bit per stereo-channel) */
  127. ret = comm_rt->write16(comm_rt, 0x02, 0x02,
  128. (1 << (n_analog_out / 2)) - 1,
  129. (1 << (n_analog_in / 2)) - 1);
  130. if (ret < 0)
  131. return ret;
  132. /* disable digital inputs and outputs */
  133. /* TODO: use spdif_x to enable/disable digital channels */
  134. ret = comm_rt->write16(comm_rt, 0x02, 0x03, 0x00, 0x00);
  135. if (ret < 0)
  136. return ret;
  137. return 0;
  138. }
  139. static int usb6fire_control_streaming_update(struct control_runtime *rt)
  140. {
  141. struct comm_runtime *comm_rt = rt->chip->comm;
  142. if (comm_rt) {
  143. if (!rt->usb_streaming && rt->digital_thru_switch)
  144. usb6fire_control_set_rate(rt,
  145. DIGITAL_THRU_ONLY_SAMPLERATE);
  146. return comm_rt->write16(comm_rt, 0x02, 0x00, 0x00,
  147. (rt->usb_streaming ? 0x01 : 0x00) |
  148. (rt->digital_thru_switch ? 0x08 : 0x00));
  149. }
  150. return -EINVAL;
  151. }
  152. static int usb6fire_control_output_vol_info(struct snd_kcontrol *kcontrol,
  153. struct snd_ctl_elem_info *uinfo)
  154. {
  155. uinfo->type = SNDRV_CTL_ELEM_TYPE_INTEGER;
  156. uinfo->count = 2;
  157. uinfo->value.integer.min = 0;
  158. uinfo->value.integer.max = 180;
  159. return 0;
  160. }
  161. static int usb6fire_control_output_vol_put(struct snd_kcontrol *kcontrol,
  162. struct snd_ctl_elem_value *ucontrol)
  163. {
  164. struct control_runtime *rt = snd_kcontrol_chip(kcontrol);
  165. unsigned int ch = kcontrol->private_value;
  166. int changed = 0;
  167. if (ch > 4) {
  168. dev_err(&rt->chip->dev->dev,
  169. "Invalid channel in volume control.");
  170. return -EINVAL;
  171. }
  172. if (rt->output_vol[ch] != ucontrol->value.integer.value[0]) {
  173. rt->output_vol[ch] = ucontrol->value.integer.value[0];
  174. rt->ovol_updated &= ~(1 << ch);
  175. changed = 1;
  176. }
  177. if (rt->output_vol[ch + 1] != ucontrol->value.integer.value[1]) {
  178. rt->output_vol[ch + 1] = ucontrol->value.integer.value[1];
  179. rt->ovol_updated &= ~(2 << ch);
  180. changed = 1;
  181. }
  182. if (changed)
  183. usb6fire_control_output_vol_update(rt);
  184. return changed;
  185. }
  186. static int usb6fire_control_output_vol_get(struct snd_kcontrol *kcontrol,
  187. struct snd_ctl_elem_value *ucontrol)
  188. {
  189. struct control_runtime *rt = snd_kcontrol_chip(kcontrol);
  190. unsigned int ch = kcontrol->private_value;
  191. if (ch > 4) {
  192. dev_err(&rt->chip->dev->dev,
  193. "Invalid channel in volume control.");
  194. return -EINVAL;
  195. }
  196. ucontrol->value.integer.value[0] = rt->output_vol[ch];
  197. ucontrol->value.integer.value[1] = rt->output_vol[ch + 1];
  198. return 0;
  199. }
  200. static int usb6fire_control_output_mute_put(struct snd_kcontrol *kcontrol,
  201. struct snd_ctl_elem_value *ucontrol)
  202. {
  203. struct control_runtime *rt = snd_kcontrol_chip(kcontrol);
  204. unsigned int ch = kcontrol->private_value;
  205. u8 old = rt->output_mute;
  206. u8 value = 0;
  207. if (ch > 4) {
  208. dev_err(&rt->chip->dev->dev,
  209. "Invalid channel in volume control.");
  210. return -EINVAL;
  211. }
  212. rt->output_mute &= ~(3 << ch);
  213. if (ucontrol->value.integer.value[0])
  214. value |= 1;
  215. if (ucontrol->value.integer.value[1])
  216. value |= 2;
  217. rt->output_mute |= value << ch;
  218. if (rt->output_mute != old)
  219. usb6fire_control_output_mute_update(rt);
  220. return rt->output_mute != old;
  221. }
  222. static int usb6fire_control_output_mute_get(struct snd_kcontrol *kcontrol,
  223. struct snd_ctl_elem_value *ucontrol)
  224. {
  225. struct control_runtime *rt = snd_kcontrol_chip(kcontrol);
  226. unsigned int ch = kcontrol->private_value;
  227. u8 value = rt->output_mute >> ch;
  228. if (ch > 4) {
  229. dev_err(&rt->chip->dev->dev,
  230. "Invalid channel in volume control.");
  231. return -EINVAL;
  232. }
  233. ucontrol->value.integer.value[0] = 1 & value;
  234. value >>= 1;
  235. ucontrol->value.integer.value[1] = 1 & value;
  236. return 0;
  237. }
  238. static int usb6fire_control_input_vol_info(struct snd_kcontrol *kcontrol,
  239. struct snd_ctl_elem_info *uinfo)
  240. {
  241. uinfo->type = SNDRV_CTL_ELEM_TYPE_INTEGER;
  242. uinfo->count = 2;
  243. uinfo->value.integer.min = 0;
  244. uinfo->value.integer.max = 30;
  245. return 0;
  246. }
  247. static int usb6fire_control_input_vol_put(struct snd_kcontrol *kcontrol,
  248. struct snd_ctl_elem_value *ucontrol)
  249. {
  250. struct control_runtime *rt = snd_kcontrol_chip(kcontrol);
  251. int changed = 0;
  252. if (rt->input_vol[0] != ucontrol->value.integer.value[0]) {
  253. rt->input_vol[0] = ucontrol->value.integer.value[0] - 15;
  254. rt->ivol_updated &= ~(1 << 0);
  255. changed = 1;
  256. }
  257. if (rt->input_vol[1] != ucontrol->value.integer.value[1]) {
  258. rt->input_vol[1] = ucontrol->value.integer.value[1] - 15;
  259. rt->ivol_updated &= ~(1 << 1);
  260. changed = 1;
  261. }
  262. if (changed)
  263. usb6fire_control_input_vol_update(rt);
  264. return changed;
  265. }
  266. static int usb6fire_control_input_vol_get(struct snd_kcontrol *kcontrol,
  267. struct snd_ctl_elem_value *ucontrol)
  268. {
  269. struct control_runtime *rt = snd_kcontrol_chip(kcontrol);
  270. ucontrol->value.integer.value[0] = rt->input_vol[0] + 15;
  271. ucontrol->value.integer.value[1] = rt->input_vol[1] + 15;
  272. return 0;
  273. }
  274. static int usb6fire_control_line_phono_info(struct snd_kcontrol *kcontrol,
  275. struct snd_ctl_elem_info *uinfo)
  276. {
  277. return snd_ctl_enum_info(uinfo, 1, 2, line_phono_texts);
  278. }
  279. static int usb6fire_control_line_phono_put(struct snd_kcontrol *kcontrol,
  280. struct snd_ctl_elem_value *ucontrol)
  281. {
  282. struct control_runtime *rt = snd_kcontrol_chip(kcontrol);
  283. int changed = 0;
  284. if (rt->line_phono_switch != ucontrol->value.integer.value[0]) {
  285. rt->line_phono_switch = ucontrol->value.integer.value[0];
  286. usb6fire_control_line_phono_update(rt);
  287. changed = 1;
  288. }
  289. return changed;
  290. }
  291. static int usb6fire_control_line_phono_get(struct snd_kcontrol *kcontrol,
  292. struct snd_ctl_elem_value *ucontrol)
  293. {
  294. struct control_runtime *rt = snd_kcontrol_chip(kcontrol);
  295. ucontrol->value.integer.value[0] = rt->line_phono_switch;
  296. return 0;
  297. }
  298. static int usb6fire_control_opt_coax_info(struct snd_kcontrol *kcontrol,
  299. struct snd_ctl_elem_info *uinfo)
  300. {
  301. return snd_ctl_enum_info(uinfo, 1, 2, opt_coax_texts);
  302. }
  303. static int usb6fire_control_opt_coax_put(struct snd_kcontrol *kcontrol,
  304. struct snd_ctl_elem_value *ucontrol)
  305. {
  306. struct control_runtime *rt = snd_kcontrol_chip(kcontrol);
  307. int changed = 0;
  308. if (rt->opt_coax_switch != ucontrol->value.enumerated.item[0]) {
  309. rt->opt_coax_switch = ucontrol->value.enumerated.item[0];
  310. usb6fire_control_opt_coax_update(rt);
  311. changed = 1;
  312. }
  313. return changed;
  314. }
  315. static int usb6fire_control_opt_coax_get(struct snd_kcontrol *kcontrol,
  316. struct snd_ctl_elem_value *ucontrol)
  317. {
  318. struct control_runtime *rt = snd_kcontrol_chip(kcontrol);
  319. ucontrol->value.enumerated.item[0] = rt->opt_coax_switch;
  320. return 0;
  321. }
  322. static int usb6fire_control_digital_thru_put(struct snd_kcontrol *kcontrol,
  323. struct snd_ctl_elem_value *ucontrol)
  324. {
  325. struct control_runtime *rt = snd_kcontrol_chip(kcontrol);
  326. int changed = 0;
  327. if (rt->digital_thru_switch != ucontrol->value.integer.value[0]) {
  328. rt->digital_thru_switch = ucontrol->value.integer.value[0];
  329. usb6fire_control_streaming_update(rt);
  330. changed = 1;
  331. }
  332. return changed;
  333. }
  334. static int usb6fire_control_digital_thru_get(struct snd_kcontrol *kcontrol,
  335. struct snd_ctl_elem_value *ucontrol)
  336. {
  337. struct control_runtime *rt = snd_kcontrol_chip(kcontrol);
  338. ucontrol->value.integer.value[0] = rt->digital_thru_switch;
  339. return 0;
  340. }
  341. static struct snd_kcontrol_new vol_elements[] = {
  342. {
  343. .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
  344. .name = "Analog Playback Volume",
  345. .index = 0,
  346. .private_value = 0,
  347. .access = SNDRV_CTL_ELEM_ACCESS_READWRITE |
  348. SNDRV_CTL_ELEM_ACCESS_TLV_READ,
  349. .info = usb6fire_control_output_vol_info,
  350. .get = usb6fire_control_output_vol_get,
  351. .put = usb6fire_control_output_vol_put,
  352. .tlv = { .p = tlv_output }
  353. },
  354. {
  355. .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
  356. .name = "Analog Playback Volume",
  357. .index = 1,
  358. .private_value = 2,
  359. .access = SNDRV_CTL_ELEM_ACCESS_READWRITE |
  360. SNDRV_CTL_ELEM_ACCESS_TLV_READ,
  361. .info = usb6fire_control_output_vol_info,
  362. .get = usb6fire_control_output_vol_get,
  363. .put = usb6fire_control_output_vol_put,
  364. .tlv = { .p = tlv_output }
  365. },
  366. {
  367. .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
  368. .name = "Analog Playback Volume",
  369. .index = 2,
  370. .private_value = 4,
  371. .access = SNDRV_CTL_ELEM_ACCESS_READWRITE |
  372. SNDRV_CTL_ELEM_ACCESS_TLV_READ,
  373. .info = usb6fire_control_output_vol_info,
  374. .get = usb6fire_control_output_vol_get,
  375. .put = usb6fire_control_output_vol_put,
  376. .tlv = { .p = tlv_output }
  377. },
  378. {}
  379. };
  380. static struct snd_kcontrol_new mute_elements[] = {
  381. {
  382. .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
  383. .name = "Analog Playback Switch",
  384. .index = 0,
  385. .private_value = 0,
  386. .access = SNDRV_CTL_ELEM_ACCESS_READWRITE,
  387. .info = snd_ctl_boolean_stereo_info,
  388. .get = usb6fire_control_output_mute_get,
  389. .put = usb6fire_control_output_mute_put,
  390. },
  391. {
  392. .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
  393. .name = "Analog Playback Switch",
  394. .index = 1,
  395. .private_value = 2,
  396. .access = SNDRV_CTL_ELEM_ACCESS_READWRITE,
  397. .info = snd_ctl_boolean_stereo_info,
  398. .get = usb6fire_control_output_mute_get,
  399. .put = usb6fire_control_output_mute_put,
  400. },
  401. {
  402. .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
  403. .name = "Analog Playback Switch",
  404. .index = 2,
  405. .private_value = 4,
  406. .access = SNDRV_CTL_ELEM_ACCESS_READWRITE,
  407. .info = snd_ctl_boolean_stereo_info,
  408. .get = usb6fire_control_output_mute_get,
  409. .put = usb6fire_control_output_mute_put,
  410. },
  411. {}
  412. };
  413. static struct snd_kcontrol_new elements[] = {
  414. {
  415. .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
  416. .name = "Line/Phono Capture Route",
  417. .index = 0,
  418. .access = SNDRV_CTL_ELEM_ACCESS_READWRITE,
  419. .info = usb6fire_control_line_phono_info,
  420. .get = usb6fire_control_line_phono_get,
  421. .put = usb6fire_control_line_phono_put
  422. },
  423. {
  424. .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
  425. .name = "Opt/Coax Capture Route",
  426. .index = 0,
  427. .access = SNDRV_CTL_ELEM_ACCESS_READWRITE,
  428. .info = usb6fire_control_opt_coax_info,
  429. .get = usb6fire_control_opt_coax_get,
  430. .put = usb6fire_control_opt_coax_put
  431. },
  432. {
  433. .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
  434. .name = "Digital Thru Playback Route",
  435. .index = 0,
  436. .access = SNDRV_CTL_ELEM_ACCESS_READWRITE,
  437. .info = snd_ctl_boolean_mono_info,
  438. .get = usb6fire_control_digital_thru_get,
  439. .put = usb6fire_control_digital_thru_put
  440. },
  441. {
  442. .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
  443. .name = "Analog Capture Volume",
  444. .index = 0,
  445. .access = SNDRV_CTL_ELEM_ACCESS_READWRITE |
  446. SNDRV_CTL_ELEM_ACCESS_TLV_READ,
  447. .info = usb6fire_control_input_vol_info,
  448. .get = usb6fire_control_input_vol_get,
  449. .put = usb6fire_control_input_vol_put,
  450. .tlv = { .p = tlv_input }
  451. },
  452. {}
  453. };
  454. static int usb6fire_control_add_virtual(
  455. struct control_runtime *rt,
  456. struct snd_card *card,
  457. char *name,
  458. struct snd_kcontrol_new *elems)
  459. {
  460. int ret;
  461. int i;
  462. struct snd_kcontrol *vmaster =
  463. snd_ctl_make_virtual_master(name, tlv_output);
  464. struct snd_kcontrol *control;
  465. if (!vmaster)
  466. return -ENOMEM;
  467. ret = snd_ctl_add(card, vmaster);
  468. if (ret < 0)
  469. return ret;
  470. i = 0;
  471. while (elems[i].name) {
  472. control = snd_ctl_new1(&elems[i], rt);
  473. if (!control)
  474. return -ENOMEM;
  475. ret = snd_ctl_add(card, control);
  476. if (ret < 0)
  477. return ret;
  478. ret = snd_ctl_add_slave(vmaster, control);
  479. if (ret < 0)
  480. return ret;
  481. i++;
  482. }
  483. return 0;
  484. }
  485. int usb6fire_control_init(struct sfire_chip *chip)
  486. {
  487. int i;
  488. int ret;
  489. struct control_runtime *rt = kzalloc(sizeof(struct control_runtime),
  490. GFP_KERNEL);
  491. struct comm_runtime *comm_rt = chip->comm;
  492. if (!rt)
  493. return -ENOMEM;
  494. rt->chip = chip;
  495. rt->update_streaming = usb6fire_control_streaming_update;
  496. rt->set_rate = usb6fire_control_set_rate;
  497. rt->set_channels = usb6fire_control_set_channels;
  498. i = 0;
  499. while (init_data[i].type) {
  500. comm_rt->write8(comm_rt, init_data[i].type, init_data[i].reg,
  501. init_data[i].value);
  502. i++;
  503. }
  504. usb6fire_control_opt_coax_update(rt);
  505. usb6fire_control_line_phono_update(rt);
  506. usb6fire_control_output_vol_update(rt);
  507. usb6fire_control_output_mute_update(rt);
  508. usb6fire_control_input_vol_update(rt);
  509. usb6fire_control_streaming_update(rt);
  510. ret = usb6fire_control_add_virtual(rt, chip->card,
  511. "Master Playback Volume", vol_elements);
  512. if (ret) {
  513. dev_err(&chip->dev->dev, "cannot add control.\n");
  514. kfree(rt);
  515. return ret;
  516. }
  517. ret = usb6fire_control_add_virtual(rt, chip->card,
  518. "Master Playback Switch", mute_elements);
  519. if (ret) {
  520. dev_err(&chip->dev->dev, "cannot add control.\n");
  521. kfree(rt);
  522. return ret;
  523. }
  524. i = 0;
  525. while (elements[i].name) {
  526. ret = snd_ctl_add(chip->card, snd_ctl_new1(&elements[i], rt));
  527. if (ret < 0) {
  528. kfree(rt);
  529. dev_err(&chip->dev->dev, "cannot add control.\n");
  530. return ret;
  531. }
  532. i++;
  533. }
  534. chip->control = rt;
  535. return 0;
  536. }
  537. void usb6fire_control_abort(struct sfire_chip *chip)
  538. {}
  539. void usb6fire_control_destroy(struct sfire_chip *chip)
  540. {
  541. kfree(chip->control);
  542. chip->control = NULL;
  543. }