control.c 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635
  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. 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. uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED;
  278. uinfo->count = 1;
  279. uinfo->value.enumerated.items = 2;
  280. if (uinfo->value.enumerated.item > 1)
  281. uinfo->value.enumerated.item = 1;
  282. strcpy(uinfo->value.enumerated.name,
  283. line_phono_texts[uinfo->value.enumerated.item]);
  284. return 0;
  285. }
  286. static int usb6fire_control_line_phono_put(struct snd_kcontrol *kcontrol,
  287. struct snd_ctl_elem_value *ucontrol)
  288. {
  289. struct control_runtime *rt = snd_kcontrol_chip(kcontrol);
  290. int changed = 0;
  291. if (rt->line_phono_switch != ucontrol->value.integer.value[0]) {
  292. rt->line_phono_switch = ucontrol->value.integer.value[0];
  293. usb6fire_control_line_phono_update(rt);
  294. changed = 1;
  295. }
  296. return changed;
  297. }
  298. static int usb6fire_control_line_phono_get(struct snd_kcontrol *kcontrol,
  299. struct snd_ctl_elem_value *ucontrol)
  300. {
  301. struct control_runtime *rt = snd_kcontrol_chip(kcontrol);
  302. ucontrol->value.integer.value[0] = rt->line_phono_switch;
  303. return 0;
  304. }
  305. static int usb6fire_control_opt_coax_info(struct snd_kcontrol *kcontrol,
  306. struct snd_ctl_elem_info *uinfo)
  307. {
  308. uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED;
  309. uinfo->count = 1;
  310. uinfo->value.enumerated.items = 2;
  311. if (uinfo->value.enumerated.item > 1)
  312. uinfo->value.enumerated.item = 1;
  313. strcpy(uinfo->value.enumerated.name,
  314. opt_coax_texts[uinfo->value.enumerated.item]);
  315. return 0;
  316. }
  317. static int usb6fire_control_opt_coax_put(struct snd_kcontrol *kcontrol,
  318. struct snd_ctl_elem_value *ucontrol)
  319. {
  320. struct control_runtime *rt = snd_kcontrol_chip(kcontrol);
  321. int changed = 0;
  322. if (rt->opt_coax_switch != ucontrol->value.enumerated.item[0]) {
  323. rt->opt_coax_switch = ucontrol->value.enumerated.item[0];
  324. usb6fire_control_opt_coax_update(rt);
  325. changed = 1;
  326. }
  327. return changed;
  328. }
  329. static int usb6fire_control_opt_coax_get(struct snd_kcontrol *kcontrol,
  330. struct snd_ctl_elem_value *ucontrol)
  331. {
  332. struct control_runtime *rt = snd_kcontrol_chip(kcontrol);
  333. ucontrol->value.enumerated.item[0] = rt->opt_coax_switch;
  334. return 0;
  335. }
  336. static int usb6fire_control_digital_thru_put(struct snd_kcontrol *kcontrol,
  337. struct snd_ctl_elem_value *ucontrol)
  338. {
  339. struct control_runtime *rt = snd_kcontrol_chip(kcontrol);
  340. int changed = 0;
  341. if (rt->digital_thru_switch != ucontrol->value.integer.value[0]) {
  342. rt->digital_thru_switch = ucontrol->value.integer.value[0];
  343. usb6fire_control_streaming_update(rt);
  344. changed = 1;
  345. }
  346. return changed;
  347. }
  348. static int usb6fire_control_digital_thru_get(struct snd_kcontrol *kcontrol,
  349. struct snd_ctl_elem_value *ucontrol)
  350. {
  351. struct control_runtime *rt = snd_kcontrol_chip(kcontrol);
  352. ucontrol->value.integer.value[0] = rt->digital_thru_switch;
  353. return 0;
  354. }
  355. static struct snd_kcontrol_new vol_elements[] = {
  356. {
  357. .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
  358. .name = "Analog Playback Volume",
  359. .index = 0,
  360. .private_value = 0,
  361. .access = SNDRV_CTL_ELEM_ACCESS_READWRITE |
  362. SNDRV_CTL_ELEM_ACCESS_TLV_READ,
  363. .info = usb6fire_control_output_vol_info,
  364. .get = usb6fire_control_output_vol_get,
  365. .put = usb6fire_control_output_vol_put,
  366. .tlv = { .p = tlv_output }
  367. },
  368. {
  369. .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
  370. .name = "Analog Playback Volume",
  371. .index = 1,
  372. .private_value = 2,
  373. .access = SNDRV_CTL_ELEM_ACCESS_READWRITE |
  374. SNDRV_CTL_ELEM_ACCESS_TLV_READ,
  375. .info = usb6fire_control_output_vol_info,
  376. .get = usb6fire_control_output_vol_get,
  377. .put = usb6fire_control_output_vol_put,
  378. .tlv = { .p = tlv_output }
  379. },
  380. {
  381. .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
  382. .name = "Analog Playback Volume",
  383. .index = 2,
  384. .private_value = 4,
  385. .access = SNDRV_CTL_ELEM_ACCESS_READWRITE |
  386. SNDRV_CTL_ELEM_ACCESS_TLV_READ,
  387. .info = usb6fire_control_output_vol_info,
  388. .get = usb6fire_control_output_vol_get,
  389. .put = usb6fire_control_output_vol_put,
  390. .tlv = { .p = tlv_output }
  391. },
  392. {}
  393. };
  394. static struct snd_kcontrol_new mute_elements[] = {
  395. {
  396. .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
  397. .name = "Analog Playback Switch",
  398. .index = 0,
  399. .private_value = 0,
  400. .access = SNDRV_CTL_ELEM_ACCESS_READWRITE,
  401. .info = snd_ctl_boolean_stereo_info,
  402. .get = usb6fire_control_output_mute_get,
  403. .put = usb6fire_control_output_mute_put,
  404. },
  405. {
  406. .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
  407. .name = "Analog Playback Switch",
  408. .index = 1,
  409. .private_value = 2,
  410. .access = SNDRV_CTL_ELEM_ACCESS_READWRITE,
  411. .info = snd_ctl_boolean_stereo_info,
  412. .get = usb6fire_control_output_mute_get,
  413. .put = usb6fire_control_output_mute_put,
  414. },
  415. {
  416. .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
  417. .name = "Analog Playback Switch",
  418. .index = 2,
  419. .private_value = 4,
  420. .access = SNDRV_CTL_ELEM_ACCESS_READWRITE,
  421. .info = snd_ctl_boolean_stereo_info,
  422. .get = usb6fire_control_output_mute_get,
  423. .put = usb6fire_control_output_mute_put,
  424. },
  425. {}
  426. };
  427. static struct snd_kcontrol_new elements[] = {
  428. {
  429. .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
  430. .name = "Line/Phono Capture Route",
  431. .index = 0,
  432. .access = SNDRV_CTL_ELEM_ACCESS_READWRITE,
  433. .info = usb6fire_control_line_phono_info,
  434. .get = usb6fire_control_line_phono_get,
  435. .put = usb6fire_control_line_phono_put
  436. },
  437. {
  438. .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
  439. .name = "Opt/Coax Capture Route",
  440. .index = 0,
  441. .access = SNDRV_CTL_ELEM_ACCESS_READWRITE,
  442. .info = usb6fire_control_opt_coax_info,
  443. .get = usb6fire_control_opt_coax_get,
  444. .put = usb6fire_control_opt_coax_put
  445. },
  446. {
  447. .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
  448. .name = "Digital Thru Playback Route",
  449. .index = 0,
  450. .access = SNDRV_CTL_ELEM_ACCESS_READWRITE,
  451. .info = snd_ctl_boolean_mono_info,
  452. .get = usb6fire_control_digital_thru_get,
  453. .put = usb6fire_control_digital_thru_put
  454. },
  455. {
  456. .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
  457. .name = "Analog Capture Volume",
  458. .index = 0,
  459. .access = SNDRV_CTL_ELEM_ACCESS_READWRITE |
  460. SNDRV_CTL_ELEM_ACCESS_TLV_READ,
  461. .info = usb6fire_control_input_vol_info,
  462. .get = usb6fire_control_input_vol_get,
  463. .put = usb6fire_control_input_vol_put,
  464. .tlv = { .p = tlv_input }
  465. },
  466. {}
  467. };
  468. static int usb6fire_control_add_virtual(
  469. struct control_runtime *rt,
  470. struct snd_card *card,
  471. char *name,
  472. struct snd_kcontrol_new *elems)
  473. {
  474. int ret;
  475. int i;
  476. struct snd_kcontrol *vmaster =
  477. snd_ctl_make_virtual_master(name, tlv_output);
  478. struct snd_kcontrol *control;
  479. if (!vmaster)
  480. return -ENOMEM;
  481. ret = snd_ctl_add(card, vmaster);
  482. if (ret < 0)
  483. return ret;
  484. i = 0;
  485. while (elems[i].name) {
  486. control = snd_ctl_new1(&elems[i], rt);
  487. if (!control)
  488. return -ENOMEM;
  489. ret = snd_ctl_add(card, control);
  490. if (ret < 0)
  491. return ret;
  492. ret = snd_ctl_add_slave(vmaster, control);
  493. if (ret < 0)
  494. return ret;
  495. i++;
  496. }
  497. return 0;
  498. }
  499. int usb6fire_control_init(struct sfire_chip *chip)
  500. {
  501. int i;
  502. int ret;
  503. struct control_runtime *rt = kzalloc(sizeof(struct control_runtime),
  504. GFP_KERNEL);
  505. struct comm_runtime *comm_rt = chip->comm;
  506. if (!rt)
  507. return -ENOMEM;
  508. rt->chip = chip;
  509. rt->update_streaming = usb6fire_control_streaming_update;
  510. rt->set_rate = usb6fire_control_set_rate;
  511. rt->set_channels = usb6fire_control_set_channels;
  512. i = 0;
  513. while (init_data[i].type) {
  514. comm_rt->write8(comm_rt, init_data[i].type, init_data[i].reg,
  515. init_data[i].value);
  516. i++;
  517. }
  518. usb6fire_control_opt_coax_update(rt);
  519. usb6fire_control_line_phono_update(rt);
  520. usb6fire_control_output_vol_update(rt);
  521. usb6fire_control_output_mute_update(rt);
  522. usb6fire_control_input_vol_update(rt);
  523. usb6fire_control_streaming_update(rt);
  524. ret = usb6fire_control_add_virtual(rt, chip->card,
  525. "Master Playback Volume", vol_elements);
  526. if (ret) {
  527. dev_err(&chip->dev->dev, "cannot add control.\n");
  528. kfree(rt);
  529. return ret;
  530. }
  531. ret = usb6fire_control_add_virtual(rt, chip->card,
  532. "Master Playback Switch", mute_elements);
  533. if (ret) {
  534. dev_err(&chip->dev->dev, "cannot add control.\n");
  535. kfree(rt);
  536. return ret;
  537. }
  538. i = 0;
  539. while (elements[i].name) {
  540. ret = snd_ctl_add(chip->card, snd_ctl_new1(&elements[i], rt));
  541. if (ret < 0) {
  542. kfree(rt);
  543. dev_err(&chip->dev->dev, "cannot add control.\n");
  544. return ret;
  545. }
  546. i++;
  547. }
  548. chip->control = rt;
  549. return 0;
  550. }
  551. void usb6fire_control_abort(struct sfire_chip *chip)
  552. {}
  553. void usb6fire_control_destroy(struct sfire_chip *chip)
  554. {
  555. kfree(chip->control);
  556. chip->control = NULL;
  557. }