ctmixer.c 28 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157
  1. /**
  2. * Copyright (C) 2008, Creative Technology Ltd. All Rights Reserved.
  3. *
  4. * This source file is released under GPL v2 license (no other versions).
  5. * See the COPYING file included in the main directory of this source
  6. * distribution for the license terms and conditions.
  7. *
  8. * @File ctmixer.c
  9. *
  10. * @Brief
  11. * This file contains the implementation of alsa mixer device functions.
  12. *
  13. * @Author Liu Chun
  14. * @Date May 28 2008
  15. *
  16. */
  17. #include "ctmixer.h"
  18. #include "ctamixer.h"
  19. #include <linux/slab.h>
  20. #include <sound/core.h>
  21. #include <sound/control.h>
  22. #include <sound/asoundef.h>
  23. #include <sound/pcm.h>
  24. #include <sound/tlv.h>
  25. enum CT_SUM_CTL {
  26. SUM_IN_F,
  27. SUM_IN_R,
  28. SUM_IN_C,
  29. SUM_IN_S,
  30. SUM_IN_F_C,
  31. NUM_CT_SUMS
  32. };
  33. enum CT_AMIXER_CTL {
  34. /* volume control mixers */
  35. AMIXER_MASTER_F,
  36. AMIXER_MASTER_R,
  37. AMIXER_MASTER_C,
  38. AMIXER_MASTER_S,
  39. AMIXER_PCM_F,
  40. AMIXER_PCM_R,
  41. AMIXER_PCM_C,
  42. AMIXER_PCM_S,
  43. AMIXER_SPDIFI,
  44. AMIXER_LINEIN,
  45. AMIXER_MIC,
  46. AMIXER_SPDIFO,
  47. AMIXER_WAVE_F,
  48. AMIXER_WAVE_R,
  49. AMIXER_WAVE_C,
  50. AMIXER_WAVE_S,
  51. AMIXER_MASTER_F_C,
  52. AMIXER_PCM_F_C,
  53. AMIXER_SPDIFI_C,
  54. AMIXER_LINEIN_C,
  55. AMIXER_MIC_C,
  56. /* this should always be the last one */
  57. NUM_CT_AMIXERS
  58. };
  59. enum CTALSA_MIXER_CTL {
  60. /* volume control mixers */
  61. MIXER_MASTER_P,
  62. MIXER_PCM_P,
  63. MIXER_LINEIN_P,
  64. MIXER_MIC_P,
  65. MIXER_SPDIFI_P,
  66. MIXER_SPDIFO_P,
  67. MIXER_WAVEF_P,
  68. MIXER_WAVER_P,
  69. MIXER_WAVEC_P,
  70. MIXER_WAVES_P,
  71. MIXER_MASTER_C,
  72. MIXER_PCM_C,
  73. MIXER_LINEIN_C,
  74. MIXER_MIC_C,
  75. MIXER_SPDIFI_C,
  76. /* switch control mixers */
  77. MIXER_PCM_C_S,
  78. MIXER_LINEIN_C_S,
  79. MIXER_MIC_C_S,
  80. MIXER_SPDIFI_C_S,
  81. MIXER_LINEIN_P_S,
  82. MIXER_SPDIFO_P_S,
  83. MIXER_SPDIFI_P_S,
  84. MIXER_WAVEF_P_S,
  85. MIXER_WAVER_P_S,
  86. MIXER_WAVEC_P_S,
  87. MIXER_WAVES_P_S,
  88. MIXER_DIGITAL_IO_S,
  89. MIXER_IEC958_MASK,
  90. MIXER_IEC958_DEFAULT,
  91. MIXER_IEC958_STREAM,
  92. /* this should always be the last one */
  93. NUM_CTALSA_MIXERS
  94. };
  95. #define VOL_MIXER_START MIXER_MASTER_P
  96. #define VOL_MIXER_END MIXER_SPDIFI_C
  97. #define VOL_MIXER_NUM (VOL_MIXER_END - VOL_MIXER_START + 1)
  98. #define SWH_MIXER_START MIXER_PCM_C_S
  99. #define SWH_MIXER_END MIXER_DIGITAL_IO_S
  100. #define SWH_CAPTURE_START MIXER_PCM_C_S
  101. #define SWH_CAPTURE_END MIXER_SPDIFI_C_S
  102. #define CHN_NUM 2
  103. struct ct_kcontrol_init {
  104. unsigned char ctl;
  105. char *name;
  106. };
  107. static struct ct_kcontrol_init
  108. ct_kcontrol_init_table[NUM_CTALSA_MIXERS] = {
  109. [MIXER_MASTER_P] = {
  110. .ctl = 1,
  111. .name = "Master Playback Volume",
  112. },
  113. [MIXER_MASTER_C] = {
  114. .ctl = 1,
  115. .name = "Master Capture Volume",
  116. },
  117. [MIXER_PCM_P] = {
  118. .ctl = 1,
  119. .name = "PCM Playback Volume",
  120. },
  121. [MIXER_PCM_C] = {
  122. .ctl = 1,
  123. .name = "PCM Capture Volume",
  124. },
  125. [MIXER_LINEIN_P] = {
  126. .ctl = 1,
  127. .name = "Line-in Playback Volume",
  128. },
  129. [MIXER_LINEIN_C] = {
  130. .ctl = 1,
  131. .name = "Line-in Capture Volume",
  132. },
  133. [MIXER_MIC_P] = {
  134. .ctl = 1,
  135. .name = "Mic Playback Volume",
  136. },
  137. [MIXER_MIC_C] = {
  138. .ctl = 1,
  139. .name = "Mic Capture Volume",
  140. },
  141. [MIXER_SPDIFI_P] = {
  142. .ctl = 1,
  143. .name = "S/PDIF-in Playback Volume",
  144. },
  145. [MIXER_SPDIFI_C] = {
  146. .ctl = 1,
  147. .name = "S/PDIF-in Capture Volume",
  148. },
  149. [MIXER_SPDIFO_P] = {
  150. .ctl = 1,
  151. .name = "S/PDIF-out Playback Volume",
  152. },
  153. [MIXER_WAVEF_P] = {
  154. .ctl = 1,
  155. .name = "Front Playback Volume",
  156. },
  157. [MIXER_WAVES_P] = {
  158. .ctl = 1,
  159. .name = "Side Playback Volume",
  160. },
  161. [MIXER_WAVEC_P] = {
  162. .ctl = 1,
  163. .name = "Center/LFE Playback Volume",
  164. },
  165. [MIXER_WAVER_P] = {
  166. .ctl = 1,
  167. .name = "Surround Playback Volume",
  168. },
  169. [MIXER_PCM_C_S] = {
  170. .ctl = 1,
  171. .name = "PCM Capture Switch",
  172. },
  173. [MIXER_LINEIN_C_S] = {
  174. .ctl = 1,
  175. .name = "Line-in Capture Switch",
  176. },
  177. [MIXER_MIC_C_S] = {
  178. .ctl = 1,
  179. .name = "Mic Capture Switch",
  180. },
  181. [MIXER_SPDIFI_C_S] = {
  182. .ctl = 1,
  183. .name = "S/PDIF-in Capture Switch",
  184. },
  185. [MIXER_LINEIN_P_S] = {
  186. .ctl = 1,
  187. .name = "Line-in Playback Switch",
  188. },
  189. [MIXER_SPDIFO_P_S] = {
  190. .ctl = 1,
  191. .name = "S/PDIF-out Playback Switch",
  192. },
  193. [MIXER_SPDIFI_P_S] = {
  194. .ctl = 1,
  195. .name = "S/PDIF-in Playback Switch",
  196. },
  197. [MIXER_WAVEF_P_S] = {
  198. .ctl = 1,
  199. .name = "Front Playback Switch",
  200. },
  201. [MIXER_WAVES_P_S] = {
  202. .ctl = 1,
  203. .name = "Side Playback Switch",
  204. },
  205. [MIXER_WAVEC_P_S] = {
  206. .ctl = 1,
  207. .name = "Center/LFE Playback Switch",
  208. },
  209. [MIXER_WAVER_P_S] = {
  210. .ctl = 1,
  211. .name = "Surround Playback Switch",
  212. },
  213. [MIXER_DIGITAL_IO_S] = {
  214. .ctl = 0,
  215. .name = "Digit-IO Playback Switch",
  216. },
  217. };
  218. static void
  219. ct_mixer_recording_select(struct ct_mixer *mixer, enum CT_AMIXER_CTL type);
  220. static void
  221. ct_mixer_recording_unselect(struct ct_mixer *mixer, enum CT_AMIXER_CTL type);
  222. static struct snd_kcontrol *kctls[2] = {NULL};
  223. static enum CT_AMIXER_CTL get_amixer_index(enum CTALSA_MIXER_CTL alsa_index)
  224. {
  225. switch (alsa_index) {
  226. case MIXER_MASTER_P: return AMIXER_MASTER_F;
  227. case MIXER_MASTER_C: return AMIXER_MASTER_F_C;
  228. case MIXER_PCM_P: return AMIXER_PCM_F;
  229. case MIXER_PCM_C:
  230. case MIXER_PCM_C_S: return AMIXER_PCM_F_C;
  231. case MIXER_LINEIN_P: return AMIXER_LINEIN;
  232. case MIXER_LINEIN_C:
  233. case MIXER_LINEIN_C_S: return AMIXER_LINEIN_C;
  234. case MIXER_MIC_P: return AMIXER_MIC;
  235. case MIXER_MIC_C:
  236. case MIXER_MIC_C_S: return AMIXER_MIC_C;
  237. case MIXER_SPDIFI_P: return AMIXER_SPDIFI;
  238. case MIXER_SPDIFI_C:
  239. case MIXER_SPDIFI_C_S: return AMIXER_SPDIFI_C;
  240. case MIXER_SPDIFO_P: return AMIXER_SPDIFO;
  241. case MIXER_WAVEF_P: return AMIXER_WAVE_F;
  242. case MIXER_WAVES_P: return AMIXER_WAVE_S;
  243. case MIXER_WAVEC_P: return AMIXER_WAVE_C;
  244. case MIXER_WAVER_P: return AMIXER_WAVE_R;
  245. default: return NUM_CT_AMIXERS;
  246. }
  247. }
  248. static enum CT_AMIXER_CTL get_recording_amixer(enum CT_AMIXER_CTL index)
  249. {
  250. switch (index) {
  251. case AMIXER_MASTER_F: return AMIXER_MASTER_F_C;
  252. case AMIXER_PCM_F: return AMIXER_PCM_F_C;
  253. case AMIXER_SPDIFI: return AMIXER_SPDIFI_C;
  254. case AMIXER_LINEIN: return AMIXER_LINEIN_C;
  255. case AMIXER_MIC: return AMIXER_MIC_C;
  256. default: return NUM_CT_AMIXERS;
  257. }
  258. }
  259. static unsigned char
  260. get_switch_state(struct ct_mixer *mixer, enum CTALSA_MIXER_CTL type)
  261. {
  262. return (mixer->switch_state & (0x1 << (type - SWH_MIXER_START)))
  263. ? 1 : 0;
  264. }
  265. static void
  266. set_switch_state(struct ct_mixer *mixer,
  267. enum CTALSA_MIXER_CTL type, unsigned char state)
  268. {
  269. if (state)
  270. mixer->switch_state |= (0x1 << (type - SWH_MIXER_START));
  271. else
  272. mixer->switch_state &= ~(0x1 << (type - SWH_MIXER_START));
  273. }
  274. #if 0 /* not used */
  275. /* Map integer value ranging from 0 to 65535 to 14-bit float value ranging
  276. * from 2^-6 to (1+1023/1024) */
  277. static unsigned int uint16_to_float14(unsigned int x)
  278. {
  279. unsigned int i;
  280. if (x < 17)
  281. return 0;
  282. x *= 2031;
  283. x /= 65535;
  284. x += 16;
  285. /* i <= 6 */
  286. for (i = 0; !(x & 0x400); i++)
  287. x <<= 1;
  288. x = (((7 - i) & 0x7) << 10) | (x & 0x3ff);
  289. return x;
  290. }
  291. static unsigned int float14_to_uint16(unsigned int x)
  292. {
  293. unsigned int e;
  294. if (!x)
  295. return x;
  296. e = (x >> 10) & 0x7;
  297. x &= 0x3ff;
  298. x += 1024;
  299. x >>= (7 - e);
  300. x -= 16;
  301. x *= 65535;
  302. x /= 2031;
  303. return x;
  304. }
  305. #endif /* not used */
  306. #define VOL_SCALE 0x1c
  307. #define VOL_MAX 0x100
  308. static const DECLARE_TLV_DB_SCALE(ct_vol_db_scale, -6400, 25, 1);
  309. static int ct_alsa_mix_volume_info(struct snd_kcontrol *kcontrol,
  310. struct snd_ctl_elem_info *uinfo)
  311. {
  312. uinfo->type = SNDRV_CTL_ELEM_TYPE_INTEGER;
  313. uinfo->count = 2;
  314. uinfo->value.integer.min = 0;
  315. uinfo->value.integer.max = VOL_MAX;
  316. return 0;
  317. }
  318. static int ct_alsa_mix_volume_get(struct snd_kcontrol *kcontrol,
  319. struct snd_ctl_elem_value *ucontrol)
  320. {
  321. struct ct_atc *atc = snd_kcontrol_chip(kcontrol);
  322. enum CT_AMIXER_CTL type = get_amixer_index(kcontrol->private_value);
  323. struct amixer *amixer;
  324. int i, val;
  325. for (i = 0; i < 2; i++) {
  326. amixer = ((struct ct_mixer *)atc->mixer)->
  327. amixers[type*CHN_NUM+i];
  328. val = amixer->ops->get_scale(amixer) / VOL_SCALE;
  329. if (val < 0)
  330. val = 0;
  331. else if (val > VOL_MAX)
  332. val = VOL_MAX;
  333. ucontrol->value.integer.value[i] = val;
  334. }
  335. return 0;
  336. }
  337. static int ct_alsa_mix_volume_put(struct snd_kcontrol *kcontrol,
  338. struct snd_ctl_elem_value *ucontrol)
  339. {
  340. struct ct_atc *atc = snd_kcontrol_chip(kcontrol);
  341. struct ct_mixer *mixer = atc->mixer;
  342. enum CT_AMIXER_CTL type = get_amixer_index(kcontrol->private_value);
  343. struct amixer *amixer;
  344. int i, j, val, oval, change = 0;
  345. for (i = 0; i < 2; i++) {
  346. val = ucontrol->value.integer.value[i];
  347. if (val < 0)
  348. val = 0;
  349. else if (val > VOL_MAX)
  350. val = VOL_MAX;
  351. val *= VOL_SCALE;
  352. amixer = mixer->amixers[type*CHN_NUM+i];
  353. oval = amixer->ops->get_scale(amixer);
  354. if (val != oval) {
  355. amixer->ops->set_scale(amixer, val);
  356. amixer->ops->commit_write(amixer);
  357. change = 1;
  358. /* Synchronize Master/PCM playback AMIXERs. */
  359. if (AMIXER_MASTER_F == type || AMIXER_PCM_F == type) {
  360. for (j = 1; j < 4; j++) {
  361. amixer = mixer->
  362. amixers[(type+j)*CHN_NUM+i];
  363. amixer->ops->set_scale(amixer, val);
  364. amixer->ops->commit_write(amixer);
  365. }
  366. }
  367. }
  368. }
  369. return change;
  370. }
  371. static struct snd_kcontrol_new vol_ctl = {
  372. .access = SNDRV_CTL_ELEM_ACCESS_READWRITE |
  373. SNDRV_CTL_ELEM_ACCESS_TLV_READ,
  374. .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
  375. .info = ct_alsa_mix_volume_info,
  376. .get = ct_alsa_mix_volume_get,
  377. .put = ct_alsa_mix_volume_put,
  378. .tlv = { .p = ct_vol_db_scale },
  379. };
  380. static void
  381. do_line_mic_switch(struct ct_atc *atc, enum CTALSA_MIXER_CTL type)
  382. {
  383. if (MIXER_LINEIN_C_S == type) {
  384. atc->select_line_in(atc);
  385. set_switch_state(atc->mixer, MIXER_MIC_C_S, 0);
  386. snd_ctl_notify(atc->card, SNDRV_CTL_EVENT_MASK_VALUE,
  387. &kctls[1]->id);
  388. } else if (MIXER_MIC_C_S == type) {
  389. atc->select_mic_in(atc);
  390. set_switch_state(atc->mixer, MIXER_LINEIN_C_S, 0);
  391. snd_ctl_notify(atc->card, SNDRV_CTL_EVENT_MASK_VALUE,
  392. &kctls[0]->id);
  393. }
  394. }
  395. static void
  396. do_digit_io_switch(struct ct_atc *atc, int state)
  397. {
  398. struct ct_mixer *mixer = atc->mixer;
  399. if (state) {
  400. atc->select_digit_io(atc);
  401. atc->spdif_out_unmute(atc,
  402. get_switch_state(mixer, MIXER_SPDIFO_P_S));
  403. atc->spdif_in_unmute(atc, 1);
  404. atc->line_in_unmute(atc, 0);
  405. return;
  406. }
  407. if (get_switch_state(mixer, MIXER_LINEIN_C_S))
  408. atc->select_line_in(atc);
  409. else if (get_switch_state(mixer, MIXER_MIC_C_S))
  410. atc->select_mic_in(atc);
  411. atc->spdif_out_unmute(atc, 0);
  412. atc->spdif_in_unmute(atc, 0);
  413. atc->line_in_unmute(atc, 1);
  414. return;
  415. }
  416. static void do_switch(struct ct_atc *atc, enum CTALSA_MIXER_CTL type, int state)
  417. {
  418. struct ct_mixer *mixer = atc->mixer;
  419. /* Do changes in mixer. */
  420. if ((SWH_CAPTURE_START <= type) && (SWH_CAPTURE_END >= type)) {
  421. if (state) {
  422. ct_mixer_recording_select(mixer,
  423. get_amixer_index(type));
  424. } else {
  425. ct_mixer_recording_unselect(mixer,
  426. get_amixer_index(type));
  427. }
  428. }
  429. /* Do changes out of mixer. */
  430. if (state && (MIXER_LINEIN_C_S == type || MIXER_MIC_C_S == type))
  431. do_line_mic_switch(atc, type);
  432. else if (MIXER_WAVEF_P_S == type)
  433. atc->line_front_unmute(atc, state);
  434. else if (MIXER_WAVES_P_S == type)
  435. atc->line_surround_unmute(atc, state);
  436. else if (MIXER_WAVEC_P_S == type)
  437. atc->line_clfe_unmute(atc, state);
  438. else if (MIXER_WAVER_P_S == type)
  439. atc->line_rear_unmute(atc, state);
  440. else if (MIXER_LINEIN_P_S == type)
  441. atc->line_in_unmute(atc, state);
  442. else if (MIXER_SPDIFO_P_S == type)
  443. atc->spdif_out_unmute(atc, state);
  444. else if (MIXER_SPDIFI_P_S == type)
  445. atc->spdif_in_unmute(atc, state);
  446. else if (MIXER_DIGITAL_IO_S == type)
  447. do_digit_io_switch(atc, state);
  448. return;
  449. }
  450. static int ct_alsa_mix_switch_info(struct snd_kcontrol *kcontrol,
  451. struct snd_ctl_elem_info *uinfo)
  452. {
  453. uinfo->type = SNDRV_CTL_ELEM_TYPE_BOOLEAN;
  454. uinfo->count = 1;
  455. uinfo->value.integer.min = 0;
  456. uinfo->value.integer.max = 1;
  457. uinfo->value.integer.step = 1;
  458. return 0;
  459. }
  460. static int ct_alsa_mix_switch_get(struct snd_kcontrol *kcontrol,
  461. struct snd_ctl_elem_value *ucontrol)
  462. {
  463. struct ct_mixer *mixer =
  464. ((struct ct_atc *)snd_kcontrol_chip(kcontrol))->mixer;
  465. enum CTALSA_MIXER_CTL type = kcontrol->private_value;
  466. ucontrol->value.integer.value[0] = get_switch_state(mixer, type);
  467. return 0;
  468. }
  469. static int ct_alsa_mix_switch_put(struct snd_kcontrol *kcontrol,
  470. struct snd_ctl_elem_value *ucontrol)
  471. {
  472. struct ct_atc *atc = snd_kcontrol_chip(kcontrol);
  473. struct ct_mixer *mixer = atc->mixer;
  474. enum CTALSA_MIXER_CTL type = kcontrol->private_value;
  475. int state;
  476. state = ucontrol->value.integer.value[0];
  477. if (get_switch_state(mixer, type) == state)
  478. return 0;
  479. set_switch_state(mixer, type, state);
  480. do_switch(atc, type, state);
  481. return 1;
  482. }
  483. static struct snd_kcontrol_new swh_ctl = {
  484. .access = SNDRV_CTL_ELEM_ACCESS_READWRITE,
  485. .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
  486. .info = ct_alsa_mix_switch_info,
  487. .get = ct_alsa_mix_switch_get,
  488. .put = ct_alsa_mix_switch_put
  489. };
  490. static int ct_spdif_info(struct snd_kcontrol *kcontrol,
  491. struct snd_ctl_elem_info *uinfo)
  492. {
  493. uinfo->type = SNDRV_CTL_ELEM_TYPE_IEC958;
  494. uinfo->count = 1;
  495. return 0;
  496. }
  497. static int ct_spdif_get_mask(struct snd_kcontrol *kcontrol,
  498. struct snd_ctl_elem_value *ucontrol)
  499. {
  500. ucontrol->value.iec958.status[0] = 0xff;
  501. ucontrol->value.iec958.status[1] = 0xff;
  502. ucontrol->value.iec958.status[2] = 0xff;
  503. ucontrol->value.iec958.status[3] = 0xff;
  504. return 0;
  505. }
  506. static int ct_spdif_default_get(struct snd_kcontrol *kcontrol,
  507. struct snd_ctl_elem_value *ucontrol)
  508. {
  509. unsigned int status = SNDRV_PCM_DEFAULT_CON_SPDIF;
  510. ucontrol->value.iec958.status[0] = (status >> 0) & 0xff;
  511. ucontrol->value.iec958.status[1] = (status >> 8) & 0xff;
  512. ucontrol->value.iec958.status[2] = (status >> 16) & 0xff;
  513. ucontrol->value.iec958.status[3] = (status >> 24) & 0xff;
  514. return 0;
  515. }
  516. static int ct_spdif_get(struct snd_kcontrol *kcontrol,
  517. struct snd_ctl_elem_value *ucontrol)
  518. {
  519. struct ct_atc *atc = snd_kcontrol_chip(kcontrol);
  520. unsigned int status;
  521. atc->spdif_out_get_status(atc, &status);
  522. ucontrol->value.iec958.status[0] = (status >> 0) & 0xff;
  523. ucontrol->value.iec958.status[1] = (status >> 8) & 0xff;
  524. ucontrol->value.iec958.status[2] = (status >> 16) & 0xff;
  525. ucontrol->value.iec958.status[3] = (status >> 24) & 0xff;
  526. return 0;
  527. }
  528. static int ct_spdif_put(struct snd_kcontrol *kcontrol,
  529. struct snd_ctl_elem_value *ucontrol)
  530. {
  531. struct ct_atc *atc = snd_kcontrol_chip(kcontrol);
  532. int change;
  533. unsigned int status, old_status;
  534. status = (ucontrol->value.iec958.status[0] << 0) |
  535. (ucontrol->value.iec958.status[1] << 8) |
  536. (ucontrol->value.iec958.status[2] << 16) |
  537. (ucontrol->value.iec958.status[3] << 24);
  538. atc->spdif_out_get_status(atc, &old_status);
  539. change = (old_status != status);
  540. if (change)
  541. atc->spdif_out_set_status(atc, status);
  542. return change;
  543. }
  544. static struct snd_kcontrol_new iec958_mask_ctl = {
  545. .access = SNDRV_CTL_ELEM_ACCESS_READ,
  546. .iface = SNDRV_CTL_ELEM_IFACE_PCM,
  547. .name = SNDRV_CTL_NAME_IEC958("", PLAYBACK, MASK),
  548. .count = 1,
  549. .info = ct_spdif_info,
  550. .get = ct_spdif_get_mask,
  551. .private_value = MIXER_IEC958_MASK
  552. };
  553. static struct snd_kcontrol_new iec958_default_ctl = {
  554. .iface = SNDRV_CTL_ELEM_IFACE_PCM,
  555. .name = SNDRV_CTL_NAME_IEC958("", PLAYBACK, DEFAULT),
  556. .count = 1,
  557. .info = ct_spdif_info,
  558. .get = ct_spdif_default_get,
  559. .put = ct_spdif_put,
  560. .private_value = MIXER_IEC958_DEFAULT
  561. };
  562. static struct snd_kcontrol_new iec958_ctl = {
  563. .access = SNDRV_CTL_ELEM_ACCESS_READWRITE,
  564. .iface = SNDRV_CTL_ELEM_IFACE_PCM,
  565. .name = SNDRV_CTL_NAME_IEC958("", PLAYBACK, PCM_STREAM),
  566. .count = 1,
  567. .info = ct_spdif_info,
  568. .get = ct_spdif_get,
  569. .put = ct_spdif_put,
  570. .private_value = MIXER_IEC958_STREAM
  571. };
  572. #define NUM_IEC958_CTL 3
  573. static int
  574. ct_mixer_kcontrol_new(struct ct_mixer *mixer, struct snd_kcontrol_new *new)
  575. {
  576. struct snd_kcontrol *kctl;
  577. int err;
  578. kctl = snd_ctl_new1(new, mixer->atc);
  579. if (!kctl)
  580. return -ENOMEM;
  581. if (SNDRV_CTL_ELEM_IFACE_PCM == kctl->id.iface)
  582. kctl->id.device = IEC958;
  583. err = snd_ctl_add(mixer->atc->card, kctl);
  584. if (err)
  585. return err;
  586. switch (new->private_value) {
  587. case MIXER_LINEIN_C_S:
  588. kctls[0] = kctl; break;
  589. case MIXER_MIC_C_S:
  590. kctls[1] = kctl; break;
  591. default:
  592. break;
  593. }
  594. return 0;
  595. }
  596. static int ct_mixer_kcontrols_create(struct ct_mixer *mixer)
  597. {
  598. enum CTALSA_MIXER_CTL type;
  599. struct ct_atc *atc = mixer->atc;
  600. int err;
  601. /* Create snd kcontrol instances on demand */
  602. for (type = VOL_MIXER_START; type <= VOL_MIXER_END; type++) {
  603. if (ct_kcontrol_init_table[type].ctl) {
  604. vol_ctl.name = ct_kcontrol_init_table[type].name;
  605. vol_ctl.private_value = (unsigned long)type;
  606. err = ct_mixer_kcontrol_new(mixer, &vol_ctl);
  607. if (err)
  608. return err;
  609. }
  610. }
  611. ct_kcontrol_init_table[MIXER_DIGITAL_IO_S].ctl =
  612. atc->have_digit_io_switch(atc);
  613. for (type = SWH_MIXER_START; type <= SWH_MIXER_END; type++) {
  614. if (ct_kcontrol_init_table[type].ctl) {
  615. swh_ctl.name = ct_kcontrol_init_table[type].name;
  616. swh_ctl.private_value = (unsigned long)type;
  617. err = ct_mixer_kcontrol_new(mixer, &swh_ctl);
  618. if (err)
  619. return err;
  620. }
  621. }
  622. err = ct_mixer_kcontrol_new(mixer, &iec958_mask_ctl);
  623. if (err)
  624. return err;
  625. err = ct_mixer_kcontrol_new(mixer, &iec958_default_ctl);
  626. if (err)
  627. return err;
  628. err = ct_mixer_kcontrol_new(mixer, &iec958_ctl);
  629. if (err)
  630. return err;
  631. atc->line_front_unmute(atc, 1);
  632. set_switch_state(mixer, MIXER_WAVEF_P_S, 1);
  633. atc->line_surround_unmute(atc, 0);
  634. set_switch_state(mixer, MIXER_WAVES_P_S, 0);
  635. atc->line_clfe_unmute(atc, 0);
  636. set_switch_state(mixer, MIXER_WAVEC_P_S, 0);
  637. atc->line_rear_unmute(atc, 0);
  638. set_switch_state(mixer, MIXER_WAVER_P_S, 0);
  639. atc->spdif_out_unmute(atc, 0);
  640. set_switch_state(mixer, MIXER_SPDIFO_P_S, 0);
  641. atc->line_in_unmute(atc, 0);
  642. set_switch_state(mixer, MIXER_LINEIN_P_S, 0);
  643. atc->spdif_in_unmute(atc, 0);
  644. set_switch_state(mixer, MIXER_SPDIFI_P_S, 0);
  645. set_switch_state(mixer, MIXER_PCM_C_S, 1);
  646. set_switch_state(mixer, MIXER_LINEIN_C_S, 1);
  647. set_switch_state(mixer, MIXER_SPDIFI_C_S, 1);
  648. return 0;
  649. }
  650. static void
  651. ct_mixer_recording_select(struct ct_mixer *mixer, enum CT_AMIXER_CTL type)
  652. {
  653. struct amixer *amix_d;
  654. struct sum *sum_c;
  655. int i;
  656. for (i = 0; i < 2; i++) {
  657. amix_d = mixer->amixers[type*CHN_NUM+i];
  658. sum_c = mixer->sums[SUM_IN_F_C*CHN_NUM+i];
  659. amix_d->ops->set_sum(amix_d, sum_c);
  660. amix_d->ops->commit_write(amix_d);
  661. }
  662. }
  663. static void
  664. ct_mixer_recording_unselect(struct ct_mixer *mixer, enum CT_AMIXER_CTL type)
  665. {
  666. struct amixer *amix_d;
  667. int i;
  668. for (i = 0; i < 2; i++) {
  669. amix_d = mixer->amixers[type*CHN_NUM+i];
  670. amix_d->ops->set_sum(amix_d, NULL);
  671. amix_d->ops->commit_write(amix_d);
  672. }
  673. }
  674. static int ct_mixer_get_resources(struct ct_mixer *mixer)
  675. {
  676. struct sum_mgr *sum_mgr;
  677. struct sum *sum;
  678. struct sum_desc sum_desc = {0};
  679. struct amixer_mgr *amixer_mgr;
  680. struct amixer *amixer;
  681. struct amixer_desc am_desc = {0};
  682. int err;
  683. int i;
  684. /* Allocate sum resources for mixer obj */
  685. sum_mgr = (struct sum_mgr *)mixer->atc->rsc_mgrs[SUM];
  686. sum_desc.msr = mixer->atc->msr;
  687. for (i = 0; i < (NUM_CT_SUMS * CHN_NUM); i++) {
  688. err = sum_mgr->get_sum(sum_mgr, &sum_desc, &sum);
  689. if (err) {
  690. printk(KERN_ERR "ctxfi:Failed to get sum resources for "
  691. "front output!\n");
  692. break;
  693. }
  694. mixer->sums[i] = sum;
  695. }
  696. if (err)
  697. goto error1;
  698. /* Allocate amixer resources for mixer obj */
  699. amixer_mgr = (struct amixer_mgr *)mixer->atc->rsc_mgrs[AMIXER];
  700. am_desc.msr = mixer->atc->msr;
  701. for (i = 0; i < (NUM_CT_AMIXERS * CHN_NUM); i++) {
  702. err = amixer_mgr->get_amixer(amixer_mgr, &am_desc, &amixer);
  703. if (err) {
  704. printk(KERN_ERR "ctxfi:Failed to get amixer resources "
  705. "for mixer obj!\n");
  706. break;
  707. }
  708. mixer->amixers[i] = amixer;
  709. }
  710. if (err)
  711. goto error2;
  712. return 0;
  713. error2:
  714. for (i = 0; i < (NUM_CT_AMIXERS * CHN_NUM); i++) {
  715. if (NULL != mixer->amixers[i]) {
  716. amixer = mixer->amixers[i];
  717. amixer_mgr->put_amixer(amixer_mgr, amixer);
  718. mixer->amixers[i] = NULL;
  719. }
  720. }
  721. error1:
  722. for (i = 0; i < (NUM_CT_SUMS * CHN_NUM); i++) {
  723. if (NULL != mixer->sums[i]) {
  724. sum_mgr->put_sum(sum_mgr, (struct sum *)mixer->sums[i]);
  725. mixer->sums[i] = NULL;
  726. }
  727. }
  728. return err;
  729. }
  730. static int ct_mixer_get_mem(struct ct_mixer **rmixer)
  731. {
  732. struct ct_mixer *mixer;
  733. int err;
  734. *rmixer = NULL;
  735. /* Allocate mem for mixer obj */
  736. mixer = kzalloc(sizeof(*mixer), GFP_KERNEL);
  737. if (!mixer)
  738. return -ENOMEM;
  739. mixer->amixers = kzalloc(sizeof(void *)*(NUM_CT_AMIXERS*CHN_NUM),
  740. GFP_KERNEL);
  741. if (!mixer->amixers) {
  742. err = -ENOMEM;
  743. goto error1;
  744. }
  745. mixer->sums = kzalloc(sizeof(void *)*(NUM_CT_SUMS*CHN_NUM), GFP_KERNEL);
  746. if (!mixer->sums) {
  747. err = -ENOMEM;
  748. goto error2;
  749. }
  750. *rmixer = mixer;
  751. return 0;
  752. error2:
  753. kfree(mixer->amixers);
  754. error1:
  755. kfree(mixer);
  756. return err;
  757. }
  758. static int ct_mixer_topology_build(struct ct_mixer *mixer)
  759. {
  760. struct sum *sum;
  761. struct amixer *amix_d, *amix_s;
  762. enum CT_AMIXER_CTL i, j;
  763. /* Build topology from destination to source */
  764. /* Set up Master mixer */
  765. for (i = AMIXER_MASTER_F, j = SUM_IN_F;
  766. i <= AMIXER_MASTER_S; i++, j++) {
  767. amix_d = mixer->amixers[i*CHN_NUM];
  768. sum = mixer->sums[j*CHN_NUM];
  769. amix_d->ops->setup(amix_d, &sum->rsc, INIT_VOL, NULL);
  770. amix_d = mixer->amixers[i*CHN_NUM+1];
  771. sum = mixer->sums[j*CHN_NUM+1];
  772. amix_d->ops->setup(amix_d, &sum->rsc, INIT_VOL, NULL);
  773. }
  774. /* Set up Wave-out mixer */
  775. for (i = AMIXER_WAVE_F, j = AMIXER_MASTER_F;
  776. i <= AMIXER_WAVE_S; i++, j++) {
  777. amix_d = mixer->amixers[i*CHN_NUM];
  778. amix_s = mixer->amixers[j*CHN_NUM];
  779. amix_d->ops->setup(amix_d, &amix_s->rsc, INIT_VOL, NULL);
  780. amix_d = mixer->amixers[i*CHN_NUM+1];
  781. amix_s = mixer->amixers[j*CHN_NUM+1];
  782. amix_d->ops->setup(amix_d, &amix_s->rsc, INIT_VOL, NULL);
  783. }
  784. /* Set up S/PDIF-out mixer */
  785. amix_d = mixer->amixers[AMIXER_SPDIFO*CHN_NUM];
  786. amix_s = mixer->amixers[AMIXER_MASTER_F*CHN_NUM];
  787. amix_d->ops->setup(amix_d, &amix_s->rsc, INIT_VOL, NULL);
  788. amix_d = mixer->amixers[AMIXER_SPDIFO*CHN_NUM+1];
  789. amix_s = mixer->amixers[AMIXER_MASTER_F*CHN_NUM+1];
  790. amix_d->ops->setup(amix_d, &amix_s->rsc, INIT_VOL, NULL);
  791. /* Set up PCM-in mixer */
  792. for (i = AMIXER_PCM_F, j = SUM_IN_F; i <= AMIXER_PCM_S; i++, j++) {
  793. amix_d = mixer->amixers[i*CHN_NUM];
  794. sum = mixer->sums[j*CHN_NUM];
  795. amix_d->ops->setup(amix_d, NULL, INIT_VOL, sum);
  796. amix_d = mixer->amixers[i*CHN_NUM+1];
  797. sum = mixer->sums[j*CHN_NUM+1];
  798. amix_d->ops->setup(amix_d, NULL, INIT_VOL, sum);
  799. }
  800. /* Set up Line-in mixer */
  801. amix_d = mixer->amixers[AMIXER_LINEIN*CHN_NUM];
  802. sum = mixer->sums[SUM_IN_F*CHN_NUM];
  803. amix_d->ops->setup(amix_d, NULL, INIT_VOL, sum);
  804. amix_d = mixer->amixers[AMIXER_LINEIN*CHN_NUM+1];
  805. sum = mixer->sums[SUM_IN_F*CHN_NUM+1];
  806. amix_d->ops->setup(amix_d, NULL, INIT_VOL, sum);
  807. /* Set up Mic-in mixer */
  808. amix_d = mixer->amixers[AMIXER_MIC*CHN_NUM];
  809. sum = mixer->sums[SUM_IN_F*CHN_NUM];
  810. amix_d->ops->setup(amix_d, NULL, INIT_VOL, sum);
  811. amix_d = mixer->amixers[AMIXER_MIC*CHN_NUM+1];
  812. sum = mixer->sums[SUM_IN_F*CHN_NUM+1];
  813. amix_d->ops->setup(amix_d, NULL, INIT_VOL, sum);
  814. /* Set up S/PDIF-in mixer */
  815. amix_d = mixer->amixers[AMIXER_SPDIFI*CHN_NUM];
  816. sum = mixer->sums[SUM_IN_F*CHN_NUM];
  817. amix_d->ops->setup(amix_d, NULL, INIT_VOL, sum);
  818. amix_d = mixer->amixers[AMIXER_SPDIFI*CHN_NUM+1];
  819. sum = mixer->sums[SUM_IN_F*CHN_NUM+1];
  820. amix_d->ops->setup(amix_d, NULL, INIT_VOL, sum);
  821. /* Set up Master recording mixer */
  822. amix_d = mixer->amixers[AMIXER_MASTER_F_C*CHN_NUM];
  823. sum = mixer->sums[SUM_IN_F_C*CHN_NUM];
  824. amix_d->ops->setup(amix_d, &sum->rsc, INIT_VOL, NULL);
  825. amix_d = mixer->amixers[AMIXER_MASTER_F_C*CHN_NUM+1];
  826. sum = mixer->sums[SUM_IN_F_C*CHN_NUM+1];
  827. amix_d->ops->setup(amix_d, &sum->rsc, INIT_VOL, NULL);
  828. /* Set up PCM-in recording mixer */
  829. amix_d = mixer->amixers[AMIXER_PCM_F_C*CHN_NUM];
  830. sum = mixer->sums[SUM_IN_F_C*CHN_NUM];
  831. amix_d->ops->setup(amix_d, NULL, INIT_VOL, sum);
  832. amix_d = mixer->amixers[AMIXER_PCM_F_C*CHN_NUM+1];
  833. sum = mixer->sums[SUM_IN_F_C*CHN_NUM+1];
  834. amix_d->ops->setup(amix_d, NULL, INIT_VOL, sum);
  835. /* Set up Line-in recording mixer */
  836. amix_d = mixer->amixers[AMIXER_LINEIN_C*CHN_NUM];
  837. sum = mixer->sums[SUM_IN_F_C*CHN_NUM];
  838. amix_d->ops->setup(amix_d, NULL, INIT_VOL, sum);
  839. amix_d = mixer->amixers[AMIXER_LINEIN_C*CHN_NUM+1];
  840. sum = mixer->sums[SUM_IN_F_C*CHN_NUM+1];
  841. amix_d->ops->setup(amix_d, NULL, INIT_VOL, sum);
  842. /* Set up Mic-in recording mixer */
  843. amix_d = mixer->amixers[AMIXER_MIC_C*CHN_NUM];
  844. sum = mixer->sums[SUM_IN_F_C*CHN_NUM];
  845. amix_d->ops->setup(amix_d, NULL, INIT_VOL, sum);
  846. amix_d = mixer->amixers[AMIXER_MIC_C*CHN_NUM+1];
  847. sum = mixer->sums[SUM_IN_F_C*CHN_NUM+1];
  848. amix_d->ops->setup(amix_d, NULL, INIT_VOL, sum);
  849. /* Set up S/PDIF-in recording mixer */
  850. amix_d = mixer->amixers[AMIXER_SPDIFI_C*CHN_NUM];
  851. sum = mixer->sums[SUM_IN_F_C*CHN_NUM];
  852. amix_d->ops->setup(amix_d, NULL, INIT_VOL, sum);
  853. amix_d = mixer->amixers[AMIXER_SPDIFI_C*CHN_NUM+1];
  854. sum = mixer->sums[SUM_IN_F_C*CHN_NUM+1];
  855. amix_d->ops->setup(amix_d, NULL, INIT_VOL, sum);
  856. return 0;
  857. }
  858. static int mixer_set_input_port(struct amixer *amixer, struct rsc *rsc)
  859. {
  860. amixer->ops->set_input(amixer, rsc);
  861. amixer->ops->commit_write(amixer);
  862. return 0;
  863. }
  864. static enum CT_AMIXER_CTL port_to_amixer(enum MIXER_PORT_T type)
  865. {
  866. switch (type) {
  867. case MIX_WAVE_FRONT: return AMIXER_WAVE_F;
  868. case MIX_WAVE_SURROUND: return AMIXER_WAVE_S;
  869. case MIX_WAVE_CENTLFE: return AMIXER_WAVE_C;
  870. case MIX_WAVE_REAR: return AMIXER_WAVE_R;
  871. case MIX_PCMO_FRONT: return AMIXER_MASTER_F_C;
  872. case MIX_SPDIF_OUT: return AMIXER_SPDIFO;
  873. case MIX_LINE_IN: return AMIXER_LINEIN;
  874. case MIX_MIC_IN: return AMIXER_MIC;
  875. case MIX_SPDIF_IN: return AMIXER_SPDIFI;
  876. case MIX_PCMI_FRONT: return AMIXER_PCM_F;
  877. case MIX_PCMI_SURROUND: return AMIXER_PCM_S;
  878. case MIX_PCMI_CENTLFE: return AMIXER_PCM_C;
  879. case MIX_PCMI_REAR: return AMIXER_PCM_R;
  880. default: return 0;
  881. }
  882. }
  883. static int mixer_get_output_ports(struct ct_mixer *mixer,
  884. enum MIXER_PORT_T type,
  885. struct rsc **rleft, struct rsc **rright)
  886. {
  887. enum CT_AMIXER_CTL amix = port_to_amixer(type);
  888. if (NULL != rleft)
  889. *rleft = &((struct amixer *)mixer->amixers[amix*CHN_NUM])->rsc;
  890. if (NULL != rright)
  891. *rright =
  892. &((struct amixer *)mixer->amixers[amix*CHN_NUM+1])->rsc;
  893. return 0;
  894. }
  895. static int mixer_set_input_left(struct ct_mixer *mixer,
  896. enum MIXER_PORT_T type, struct rsc *rsc)
  897. {
  898. enum CT_AMIXER_CTL amix = port_to_amixer(type);
  899. mixer_set_input_port(mixer->amixers[amix*CHN_NUM], rsc);
  900. amix = get_recording_amixer(amix);
  901. if (amix < NUM_CT_AMIXERS)
  902. mixer_set_input_port(mixer->amixers[amix*CHN_NUM], rsc);
  903. return 0;
  904. }
  905. static int
  906. mixer_set_input_right(struct ct_mixer *mixer,
  907. enum MIXER_PORT_T type, struct rsc *rsc)
  908. {
  909. enum CT_AMIXER_CTL amix = port_to_amixer(type);
  910. mixer_set_input_port(mixer->amixers[amix*CHN_NUM+1], rsc);
  911. amix = get_recording_amixer(amix);
  912. if (amix < NUM_CT_AMIXERS)
  913. mixer_set_input_port(mixer->amixers[amix*CHN_NUM+1], rsc);
  914. return 0;
  915. }
  916. #ifdef CONFIG_PM
  917. static int mixer_resume(struct ct_mixer *mixer)
  918. {
  919. int i, state;
  920. struct amixer *amixer;
  921. /* resume topology and volume gain. */
  922. for (i = 0; i < NUM_CT_AMIXERS*CHN_NUM; i++) {
  923. amixer = mixer->amixers[i];
  924. amixer->ops->commit_write(amixer);
  925. }
  926. /* resume switch state. */
  927. for (i = SWH_MIXER_START; i <= SWH_MIXER_END; i++) {
  928. state = get_switch_state(mixer, i);
  929. do_switch(mixer->atc, i, state);
  930. }
  931. return 0;
  932. }
  933. #endif
  934. int ct_mixer_destroy(struct ct_mixer *mixer)
  935. {
  936. struct sum_mgr *sum_mgr = (struct sum_mgr *)mixer->atc->rsc_mgrs[SUM];
  937. struct amixer_mgr *amixer_mgr =
  938. (struct amixer_mgr *)mixer->atc->rsc_mgrs[AMIXER];
  939. struct amixer *amixer;
  940. int i = 0;
  941. /* Release amixer resources */
  942. for (i = 0; i < (NUM_CT_AMIXERS * CHN_NUM); i++) {
  943. if (NULL != mixer->amixers[i]) {
  944. amixer = mixer->amixers[i];
  945. amixer_mgr->put_amixer(amixer_mgr, amixer);
  946. }
  947. }
  948. /* Release sum resources */
  949. for (i = 0; i < (NUM_CT_SUMS * CHN_NUM); i++) {
  950. if (NULL != mixer->sums[i])
  951. sum_mgr->put_sum(sum_mgr, (struct sum *)mixer->sums[i]);
  952. }
  953. /* Release mem assigned to mixer object */
  954. kfree(mixer->sums);
  955. kfree(mixer->amixers);
  956. kfree(mixer);
  957. return 0;
  958. }
  959. int ct_mixer_create(struct ct_atc *atc, struct ct_mixer **rmixer)
  960. {
  961. struct ct_mixer *mixer;
  962. int err;
  963. *rmixer = NULL;
  964. /* Allocate mem for mixer obj */
  965. err = ct_mixer_get_mem(&mixer);
  966. if (err)
  967. return err;
  968. mixer->switch_state = 0;
  969. mixer->atc = atc;
  970. /* Set operations */
  971. mixer->get_output_ports = mixer_get_output_ports;
  972. mixer->set_input_left = mixer_set_input_left;
  973. mixer->set_input_right = mixer_set_input_right;
  974. #ifdef CONFIG_PM
  975. mixer->resume = mixer_resume;
  976. #endif
  977. /* Allocate chip resources for mixer obj */
  978. err = ct_mixer_get_resources(mixer);
  979. if (err)
  980. goto error;
  981. /* Build internal mixer topology */
  982. ct_mixer_topology_build(mixer);
  983. *rmixer = mixer;
  984. return 0;
  985. error:
  986. ct_mixer_destroy(mixer);
  987. return err;
  988. }
  989. int ct_alsa_mix_create(struct ct_atc *atc,
  990. enum CTALSADEVS device,
  991. const char *device_name)
  992. {
  993. int err;
  994. /* Create snd kcontrol instances on demand */
  995. /* vol_ctl.device = swh_ctl.device = device; */ /* better w/ device 0 */
  996. err = ct_mixer_kcontrols_create((struct ct_mixer *)atc->mixer);
  997. if (err)
  998. return err;
  999. strcpy(atc->card->mixername, device_name);
  1000. return 0;
  1001. }