control.c 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632
  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 char *opt_coax_texts[2] = { "Optical", "Coax" };
  26. static char *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. snd_printk(KERN_ERR PREFIX "Invalid channel in volume control.");
  169. return -EINVAL;
  170. }
  171. if (rt->output_vol[ch] != ucontrol->value.integer.value[0]) {
  172. rt->output_vol[ch] = ucontrol->value.integer.value[0];
  173. rt->ovol_updated &= ~(1 << ch);
  174. changed = 1;
  175. }
  176. if (rt->output_vol[ch + 1] != ucontrol->value.integer.value[1]) {
  177. rt->output_vol[ch + 1] = ucontrol->value.integer.value[1];
  178. rt->ovol_updated &= ~(2 << ch);
  179. changed = 1;
  180. }
  181. if (changed)
  182. usb6fire_control_output_vol_update(rt);
  183. return changed;
  184. }
  185. static int usb6fire_control_output_vol_get(struct snd_kcontrol *kcontrol,
  186. struct snd_ctl_elem_value *ucontrol)
  187. {
  188. struct control_runtime *rt = snd_kcontrol_chip(kcontrol);
  189. unsigned int ch = kcontrol->private_value;
  190. if (ch > 4) {
  191. snd_printk(KERN_ERR PREFIX "Invalid channel in volume control.");
  192. return -EINVAL;
  193. }
  194. ucontrol->value.integer.value[0] = rt->output_vol[ch];
  195. ucontrol->value.integer.value[1] = rt->output_vol[ch + 1];
  196. return 0;
  197. }
  198. static int usb6fire_control_output_mute_put(struct snd_kcontrol *kcontrol,
  199. struct snd_ctl_elem_value *ucontrol)
  200. {
  201. struct control_runtime *rt = snd_kcontrol_chip(kcontrol);
  202. unsigned int ch = kcontrol->private_value;
  203. u8 old = rt->output_mute;
  204. u8 value = 0;
  205. if (ch > 4) {
  206. snd_printk(KERN_ERR PREFIX "Invalid channel in volume control.");
  207. return -EINVAL;
  208. }
  209. rt->output_mute &= ~(3 << ch);
  210. if (ucontrol->value.integer.value[0])
  211. value |= 1;
  212. if (ucontrol->value.integer.value[1])
  213. value |= 2;
  214. rt->output_mute |= value << ch;
  215. if (rt->output_mute != old)
  216. usb6fire_control_output_mute_update(rt);
  217. return rt->output_mute != old;
  218. }
  219. static int usb6fire_control_output_mute_get(struct snd_kcontrol *kcontrol,
  220. struct snd_ctl_elem_value *ucontrol)
  221. {
  222. struct control_runtime *rt = snd_kcontrol_chip(kcontrol);
  223. unsigned int ch = kcontrol->private_value;
  224. u8 value = rt->output_mute >> ch;
  225. if (ch > 4) {
  226. snd_printk(KERN_ERR PREFIX "Invalid channel in volume control.");
  227. return -EINVAL;
  228. }
  229. ucontrol->value.integer.value[0] = 1 & value;
  230. value >>= 1;
  231. ucontrol->value.integer.value[1] = 1 & value;
  232. return 0;
  233. }
  234. static int usb6fire_control_input_vol_info(struct snd_kcontrol *kcontrol,
  235. struct snd_ctl_elem_info *uinfo)
  236. {
  237. uinfo->type = SNDRV_CTL_ELEM_TYPE_INTEGER;
  238. uinfo->count = 2;
  239. uinfo->value.integer.min = 0;
  240. uinfo->value.integer.max = 30;
  241. return 0;
  242. }
  243. static int usb6fire_control_input_vol_put(struct snd_kcontrol *kcontrol,
  244. struct snd_ctl_elem_value *ucontrol)
  245. {
  246. struct control_runtime *rt = snd_kcontrol_chip(kcontrol);
  247. int changed = 0;
  248. if (rt->input_vol[0] != ucontrol->value.integer.value[0]) {
  249. rt->input_vol[0] = ucontrol->value.integer.value[0] - 15;
  250. rt->ivol_updated &= ~(1 << 0);
  251. changed = 1;
  252. }
  253. if (rt->input_vol[1] != ucontrol->value.integer.value[1]) {
  254. rt->input_vol[1] = ucontrol->value.integer.value[1] - 15;
  255. rt->ivol_updated &= ~(1 << 1);
  256. changed = 1;
  257. }
  258. if (changed)
  259. usb6fire_control_input_vol_update(rt);
  260. return changed;
  261. }
  262. static int usb6fire_control_input_vol_get(struct snd_kcontrol *kcontrol,
  263. struct snd_ctl_elem_value *ucontrol)
  264. {
  265. struct control_runtime *rt = snd_kcontrol_chip(kcontrol);
  266. ucontrol->value.integer.value[0] = rt->input_vol[0] + 15;
  267. ucontrol->value.integer.value[1] = rt->input_vol[1] + 15;
  268. return 0;
  269. }
  270. static int usb6fire_control_line_phono_info(struct snd_kcontrol *kcontrol,
  271. struct snd_ctl_elem_info *uinfo)
  272. {
  273. uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED;
  274. uinfo->count = 1;
  275. uinfo->value.enumerated.items = 2;
  276. if (uinfo->value.enumerated.item > 1)
  277. uinfo->value.enumerated.item = 1;
  278. strcpy(uinfo->value.enumerated.name,
  279. line_phono_texts[uinfo->value.enumerated.item]);
  280. return 0;
  281. }
  282. static int usb6fire_control_line_phono_put(struct snd_kcontrol *kcontrol,
  283. struct snd_ctl_elem_value *ucontrol)
  284. {
  285. struct control_runtime *rt = snd_kcontrol_chip(kcontrol);
  286. int changed = 0;
  287. if (rt->line_phono_switch != ucontrol->value.integer.value[0]) {
  288. rt->line_phono_switch = ucontrol->value.integer.value[0];
  289. usb6fire_control_line_phono_update(rt);
  290. changed = 1;
  291. }
  292. return changed;
  293. }
  294. static int usb6fire_control_line_phono_get(struct snd_kcontrol *kcontrol,
  295. struct snd_ctl_elem_value *ucontrol)
  296. {
  297. struct control_runtime *rt = snd_kcontrol_chip(kcontrol);
  298. ucontrol->value.integer.value[0] = rt->line_phono_switch;
  299. return 0;
  300. }
  301. static int usb6fire_control_opt_coax_info(struct snd_kcontrol *kcontrol,
  302. struct snd_ctl_elem_info *uinfo)
  303. {
  304. uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED;
  305. uinfo->count = 1;
  306. uinfo->value.enumerated.items = 2;
  307. if (uinfo->value.enumerated.item > 1)
  308. uinfo->value.enumerated.item = 1;
  309. strcpy(uinfo->value.enumerated.name,
  310. opt_coax_texts[uinfo->value.enumerated.item]);
  311. return 0;
  312. }
  313. static int usb6fire_control_opt_coax_put(struct snd_kcontrol *kcontrol,
  314. struct snd_ctl_elem_value *ucontrol)
  315. {
  316. struct control_runtime *rt = snd_kcontrol_chip(kcontrol);
  317. int changed = 0;
  318. if (rt->opt_coax_switch != ucontrol->value.enumerated.item[0]) {
  319. rt->opt_coax_switch = ucontrol->value.enumerated.item[0];
  320. usb6fire_control_opt_coax_update(rt);
  321. changed = 1;
  322. }
  323. return changed;
  324. }
  325. static int usb6fire_control_opt_coax_get(struct snd_kcontrol *kcontrol,
  326. struct snd_ctl_elem_value *ucontrol)
  327. {
  328. struct control_runtime *rt = snd_kcontrol_chip(kcontrol);
  329. ucontrol->value.enumerated.item[0] = rt->opt_coax_switch;
  330. return 0;
  331. }
  332. static int usb6fire_control_digital_thru_put(struct snd_kcontrol *kcontrol,
  333. struct snd_ctl_elem_value *ucontrol)
  334. {
  335. struct control_runtime *rt = snd_kcontrol_chip(kcontrol);
  336. int changed = 0;
  337. if (rt->digital_thru_switch != ucontrol->value.integer.value[0]) {
  338. rt->digital_thru_switch = ucontrol->value.integer.value[0];
  339. usb6fire_control_streaming_update(rt);
  340. changed = 1;
  341. }
  342. return changed;
  343. }
  344. static int usb6fire_control_digital_thru_get(struct snd_kcontrol *kcontrol,
  345. struct snd_ctl_elem_value *ucontrol)
  346. {
  347. struct control_runtime *rt = snd_kcontrol_chip(kcontrol);
  348. ucontrol->value.integer.value[0] = rt->digital_thru_switch;
  349. return 0;
  350. }
  351. static struct __devinitdata snd_kcontrol_new vol_elements[] = {
  352. {
  353. .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
  354. .name = "Analog Playback Volume",
  355. .index = 0,
  356. .private_value = 0,
  357. .access = SNDRV_CTL_ELEM_ACCESS_READWRITE |
  358. SNDRV_CTL_ELEM_ACCESS_TLV_READ,
  359. .info = usb6fire_control_output_vol_info,
  360. .get = usb6fire_control_output_vol_get,
  361. .put = usb6fire_control_output_vol_put,
  362. .tlv = { .p = tlv_output }
  363. },
  364. {
  365. .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
  366. .name = "Analog Playback Volume",
  367. .index = 1,
  368. .private_value = 2,
  369. .access = SNDRV_CTL_ELEM_ACCESS_READWRITE |
  370. SNDRV_CTL_ELEM_ACCESS_TLV_READ,
  371. .info = usb6fire_control_output_vol_info,
  372. .get = usb6fire_control_output_vol_get,
  373. .put = usb6fire_control_output_vol_put,
  374. .tlv = { .p = tlv_output }
  375. },
  376. {
  377. .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
  378. .name = "Analog Playback Volume",
  379. .index = 2,
  380. .private_value = 4,
  381. .access = SNDRV_CTL_ELEM_ACCESS_READWRITE |
  382. SNDRV_CTL_ELEM_ACCESS_TLV_READ,
  383. .info = usb6fire_control_output_vol_info,
  384. .get = usb6fire_control_output_vol_get,
  385. .put = usb6fire_control_output_vol_put,
  386. .tlv = { .p = tlv_output }
  387. },
  388. {}
  389. };
  390. static struct __devinitdata snd_kcontrol_new mute_elements[] = {
  391. {
  392. .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
  393. .name = "Analog Playback Switch",
  394. .index = 0,
  395. .private_value = 0,
  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 = 1,
  405. .private_value = 2,
  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. .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
  413. .name = "Analog Playback Switch",
  414. .index = 2,
  415. .private_value = 4,
  416. .access = SNDRV_CTL_ELEM_ACCESS_READWRITE,
  417. .info = snd_ctl_boolean_stereo_info,
  418. .get = usb6fire_control_output_mute_get,
  419. .put = usb6fire_control_output_mute_put,
  420. },
  421. {}
  422. };
  423. static struct __devinitdata snd_kcontrol_new elements[] = {
  424. {
  425. .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
  426. .name = "Line/Phono Capture Route",
  427. .index = 0,
  428. .access = SNDRV_CTL_ELEM_ACCESS_READWRITE,
  429. .info = usb6fire_control_line_phono_info,
  430. .get = usb6fire_control_line_phono_get,
  431. .put = usb6fire_control_line_phono_put
  432. },
  433. {
  434. .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
  435. .name = "Opt/Coax Capture Route",
  436. .index = 0,
  437. .access = SNDRV_CTL_ELEM_ACCESS_READWRITE,
  438. .info = usb6fire_control_opt_coax_info,
  439. .get = usb6fire_control_opt_coax_get,
  440. .put = usb6fire_control_opt_coax_put
  441. },
  442. {
  443. .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
  444. .name = "Digital Thru Playback Route",
  445. .index = 0,
  446. .access = SNDRV_CTL_ELEM_ACCESS_READWRITE,
  447. .info = snd_ctl_boolean_mono_info,
  448. .get = usb6fire_control_digital_thru_get,
  449. .put = usb6fire_control_digital_thru_put
  450. },
  451. {
  452. .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
  453. .name = "Analog Capture Volume",
  454. .index = 0,
  455. .access = SNDRV_CTL_ELEM_ACCESS_READWRITE |
  456. SNDRV_CTL_ELEM_ACCESS_TLV_READ,
  457. .info = usb6fire_control_input_vol_info,
  458. .get = usb6fire_control_input_vol_get,
  459. .put = usb6fire_control_input_vol_put,
  460. .tlv = { .p = tlv_input }
  461. },
  462. {}
  463. };
  464. static int usb6fire_control_add_virtual(
  465. struct control_runtime *rt,
  466. struct snd_card *card,
  467. char *name,
  468. struct snd_kcontrol_new *elems)
  469. {
  470. int ret;
  471. int i;
  472. struct snd_kcontrol *vmaster =
  473. snd_ctl_make_virtual_master(name, tlv_output);
  474. struct snd_kcontrol *control;
  475. if (!vmaster)
  476. return -ENOMEM;
  477. ret = snd_ctl_add(card, vmaster);
  478. if (ret < 0)
  479. return ret;
  480. i = 0;
  481. while (elems[i].name) {
  482. control = snd_ctl_new1(&elems[i], rt);
  483. if (!control)
  484. return -ENOMEM;
  485. ret = snd_ctl_add(card, control);
  486. if (ret < 0)
  487. return ret;
  488. ret = snd_ctl_add_slave(vmaster, control);
  489. if (ret < 0)
  490. return ret;
  491. i++;
  492. }
  493. return 0;
  494. }
  495. int __devinit usb6fire_control_init(struct sfire_chip *chip)
  496. {
  497. int i;
  498. int ret;
  499. struct control_runtime *rt = kzalloc(sizeof(struct control_runtime),
  500. GFP_KERNEL);
  501. struct comm_runtime *comm_rt = chip->comm;
  502. if (!rt)
  503. return -ENOMEM;
  504. rt->chip = chip;
  505. rt->update_streaming = usb6fire_control_streaming_update;
  506. rt->set_rate = usb6fire_control_set_rate;
  507. rt->set_channels = usb6fire_control_set_channels;
  508. i = 0;
  509. while (init_data[i].type) {
  510. comm_rt->write8(comm_rt, init_data[i].type, init_data[i].reg,
  511. init_data[i].value);
  512. i++;
  513. }
  514. usb6fire_control_opt_coax_update(rt);
  515. usb6fire_control_line_phono_update(rt);
  516. usb6fire_control_output_vol_update(rt);
  517. usb6fire_control_output_mute_update(rt);
  518. usb6fire_control_input_vol_update(rt);
  519. usb6fire_control_streaming_update(rt);
  520. ret = usb6fire_control_add_virtual(rt, chip->card,
  521. "Master Playback Volume", vol_elements);
  522. if (ret) {
  523. snd_printk(KERN_ERR PREFIX "cannot add control.\n");
  524. kfree(rt);
  525. return ret;
  526. }
  527. ret = usb6fire_control_add_virtual(rt, chip->card,
  528. "Master Playback Switch", mute_elements);
  529. if (ret) {
  530. snd_printk(KERN_ERR PREFIX "cannot add control.\n");
  531. kfree(rt);
  532. return ret;
  533. }
  534. i = 0;
  535. while (elements[i].name) {
  536. ret = snd_ctl_add(chip->card, snd_ctl_new1(&elements[i], rt));
  537. if (ret < 0) {
  538. kfree(rt);
  539. snd_printk(KERN_ERR PREFIX "cannot add control.\n");
  540. return ret;
  541. }
  542. i++;
  543. }
  544. chip->control = rt;
  545. return 0;
  546. }
  547. void usb6fire_control_abort(struct sfire_chip *chip)
  548. {}
  549. void usb6fire_control_destroy(struct sfire_chip *chip)
  550. {
  551. kfree(chip->control);
  552. chip->control = NULL;
  553. }