vx_mixer.c 27 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000
  1. /*
  2. * Driver for Digigram VX soundcards
  3. *
  4. * Common mixer part
  5. *
  6. * Copyright (c) 2002 by Takashi Iwai <tiwai@suse.de>
  7. *
  8. * This program is free software; you can redistribute it and/or modify
  9. * it under the terms of the GNU General Public License as published by
  10. * the Free Software Foundation; either version 2 of the License, or
  11. * (at your option) any later version.
  12. *
  13. * This program is distributed in the hope that it will be useful,
  14. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  16. * GNU General Public License for more details.
  17. *
  18. * You should have received a copy of the GNU General Public License
  19. * along with this program; if not, write to the Free Software
  20. * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  21. */
  22. #include <sound/driver.h>
  23. #include <sound/core.h>
  24. #include <sound/control.h>
  25. #include <sound/vx_core.h>
  26. #include "vx_cmd.h"
  27. /*
  28. * write a codec data (24bit)
  29. */
  30. static void vx_write_codec_reg(vx_core_t *chip, int codec, unsigned int data)
  31. {
  32. unsigned long flags;
  33. snd_assert(chip->ops->write_codec, return);
  34. if (chip->chip_status & VX_STAT_IS_STALE)
  35. return;
  36. spin_lock_irqsave(&chip->lock, flags);
  37. chip->ops->write_codec(chip, codec, data);
  38. spin_unlock_irqrestore(&chip->lock, flags);
  39. }
  40. /*
  41. * Data type used to access the Codec
  42. */
  43. typedef union {
  44. u32 l;
  45. #ifdef SNDRV_BIG_ENDIAN
  46. struct w {
  47. u16 h;
  48. u16 l;
  49. } w;
  50. struct b {
  51. u8 hh;
  52. u8 mh;
  53. u8 ml;
  54. u8 ll;
  55. } b;
  56. #else /* LITTLE_ENDIAN */
  57. struct w {
  58. u16 l;
  59. u16 h;
  60. } w;
  61. struct b {
  62. u8 ll;
  63. u8 ml;
  64. u8 mh;
  65. u8 hh;
  66. } b;
  67. #endif
  68. } vx_codec_data_t;
  69. #define SET_CDC_DATA_SEL(di,s) ((di).b.mh = (u8) (s))
  70. #define SET_CDC_DATA_REG(di,r) ((di).b.ml = (u8) (r))
  71. #define SET_CDC_DATA_VAL(di,d) ((di).b.ll = (u8) (d))
  72. #define SET_CDC_DATA_INIT(di) ((di).l = 0L, SET_CDC_DATA_SEL(di,XX_CODEC_SELECTOR))
  73. /*
  74. * set up codec register and write the value
  75. * @codec: the codec id, 0 or 1
  76. * @reg: register index
  77. * @val: data value
  78. */
  79. static void vx_set_codec_reg(vx_core_t *chip, int codec, int reg, int val)
  80. {
  81. vx_codec_data_t data;
  82. /* DAC control register */
  83. SET_CDC_DATA_INIT(data);
  84. SET_CDC_DATA_REG(data, reg);
  85. SET_CDC_DATA_VAL(data, val);
  86. vx_write_codec_reg(chip, codec, data.l);
  87. }
  88. /*
  89. * vx_set_analog_output_level - set the output attenuation level
  90. * @codec: the output codec, 0 or 1. (1 for VXP440 only)
  91. * @left: left output level, 0 = mute
  92. * @right: right output level
  93. */
  94. static void vx_set_analog_output_level(vx_core_t *chip, int codec, int left, int right)
  95. {
  96. left = chip->hw->output_level_max - left;
  97. right = chip->hw->output_level_max - right;
  98. if (chip->ops->akm_write) {
  99. chip->ops->akm_write(chip, XX_CODEC_LEVEL_LEFT_REGISTER, left);
  100. chip->ops->akm_write(chip, XX_CODEC_LEVEL_RIGHT_REGISTER, right);
  101. } else {
  102. /* convert to attenuation level: 0 = 0dB (max), 0xe3 = -113.5 dB (min) */
  103. vx_set_codec_reg(chip, codec, XX_CODEC_LEVEL_LEFT_REGISTER, left);
  104. vx_set_codec_reg(chip, codec, XX_CODEC_LEVEL_RIGHT_REGISTER, right);
  105. }
  106. }
  107. /*
  108. * vx_toggle_dac_mute - mute/unmute DAC
  109. * @mute: 0 = unmute, 1 = mute
  110. */
  111. #define DAC_ATTEN_MIN 0x08
  112. #define DAC_ATTEN_MAX 0x38
  113. void vx_toggle_dac_mute(vx_core_t *chip, int mute)
  114. {
  115. unsigned int i;
  116. for (i = 0; i < chip->hw->num_codecs; i++) {
  117. if (chip->ops->akm_write)
  118. chip->ops->akm_write(chip, XX_CODEC_DAC_CONTROL_REGISTER, mute); /* XXX */
  119. else
  120. vx_set_codec_reg(chip, i, XX_CODEC_DAC_CONTROL_REGISTER,
  121. mute ? DAC_ATTEN_MAX : DAC_ATTEN_MIN);
  122. }
  123. }
  124. /*
  125. * vx_reset_codec - reset and initialize the codecs
  126. */
  127. void vx_reset_codec(vx_core_t *chip, int cold_reset)
  128. {
  129. unsigned int i;
  130. int port = chip->type >= VX_TYPE_VXPOCKET ? 0x75 : 0x65;
  131. chip->ops->reset_codec(chip);
  132. /* AKM codecs should be initialized in reset_codec callback */
  133. if (! chip->ops->akm_write) {
  134. /* initialize old codecs */
  135. for (i = 0; i < chip->hw->num_codecs; i++) {
  136. /* DAC control register (change level when zero crossing + mute) */
  137. vx_set_codec_reg(chip, i, XX_CODEC_DAC_CONTROL_REGISTER, DAC_ATTEN_MAX);
  138. /* ADC control register */
  139. vx_set_codec_reg(chip, i, XX_CODEC_ADC_CONTROL_REGISTER, 0x00);
  140. /* Port mode register */
  141. vx_set_codec_reg(chip, i, XX_CODEC_PORT_MODE_REGISTER, port);
  142. /* Clock control register */
  143. vx_set_codec_reg(chip, i, XX_CODEC_CLOCK_CONTROL_REGISTER, 0x00);
  144. }
  145. }
  146. /* mute analog output */
  147. for (i = 0; i < chip->hw->num_codecs; i++) {
  148. chip->output_level[i][0] = 0;
  149. chip->output_level[i][1] = 0;
  150. vx_set_analog_output_level(chip, i, 0, 0);
  151. }
  152. }
  153. /*
  154. * change the audio input source
  155. * @src: the target source (VX_AUDIO_SRC_XXX)
  156. */
  157. static void vx_change_audio_source(vx_core_t *chip, int src)
  158. {
  159. unsigned long flags;
  160. if (chip->chip_status & VX_STAT_IS_STALE)
  161. return;
  162. spin_lock_irqsave(&chip->lock, flags);
  163. chip->ops->change_audio_source(chip, src);
  164. spin_unlock_irqrestore(&chip->lock, flags);
  165. }
  166. /*
  167. * change the audio source if necessary and possible
  168. * returns 1 if the source is actually changed.
  169. */
  170. int vx_sync_audio_source(vx_core_t *chip)
  171. {
  172. if (chip->audio_source_target == chip->audio_source ||
  173. chip->pcm_running)
  174. return 0;
  175. vx_change_audio_source(chip, chip->audio_source_target);
  176. chip->audio_source = chip->audio_source_target;
  177. return 1;
  178. }
  179. /*
  180. * audio level, mute, monitoring
  181. */
  182. struct vx_audio_level {
  183. unsigned int has_level: 1;
  184. unsigned int has_monitor_level: 1;
  185. unsigned int has_mute: 1;
  186. unsigned int has_monitor_mute: 1;
  187. unsigned int mute;
  188. unsigned int monitor_mute;
  189. short level;
  190. short monitor_level;
  191. };
  192. static int vx_adjust_audio_level(vx_core_t *chip, int audio, int capture,
  193. struct vx_audio_level *info)
  194. {
  195. struct vx_rmh rmh;
  196. if (chip->chip_status & VX_STAT_IS_STALE)
  197. return -EBUSY;
  198. vx_init_rmh(&rmh, CMD_AUDIO_LEVEL_ADJUST);
  199. if (capture)
  200. rmh.Cmd[0] |= COMMAND_RECORD_MASK;
  201. /* Add Audio IO mask */
  202. rmh.Cmd[1] = 1 << audio;
  203. rmh.Cmd[2] = 0;
  204. if (info->has_level) {
  205. rmh.Cmd[0] |= VALID_AUDIO_IO_DIGITAL_LEVEL;
  206. rmh.Cmd[2] |= info->level;
  207. }
  208. if (info->has_monitor_level) {
  209. rmh.Cmd[0] |= VALID_AUDIO_IO_MONITORING_LEVEL;
  210. rmh.Cmd[2] |= ((unsigned int)info->monitor_level << 10);
  211. }
  212. if (info->has_mute) {
  213. rmh.Cmd[0] |= VALID_AUDIO_IO_MUTE_LEVEL;
  214. if (info->mute)
  215. rmh.Cmd[2] |= AUDIO_IO_HAS_MUTE_LEVEL;
  216. }
  217. if (info->has_monitor_mute) {
  218. /* validate flag for M2 at least to unmute it */
  219. rmh.Cmd[0] |= VALID_AUDIO_IO_MUTE_MONITORING_1 | VALID_AUDIO_IO_MUTE_MONITORING_2;
  220. if (info->monitor_mute)
  221. rmh.Cmd[2] |= AUDIO_IO_HAS_MUTE_MONITORING_1;
  222. }
  223. return vx_send_msg(chip, &rmh);
  224. }
  225. #if 0 // not used
  226. static int vx_read_audio_level(vx_core_t *chip, int audio, int capture,
  227. struct vx_audio_level *info)
  228. {
  229. int err;
  230. struct vx_rmh rmh;
  231. memset(info, 0, sizeof(*info));
  232. vx_init_rmh(&rmh, CMD_GET_AUDIO_LEVELS);
  233. if (capture)
  234. rmh.Cmd[0] |= COMMAND_RECORD_MASK;
  235. /* Add Audio IO mask */
  236. rmh.Cmd[1] = 1 << audio;
  237. err = vx_send_msg(chip, &rmh);
  238. if (err < 0)
  239. return err;
  240. info.level = rmh.Stat[0] & MASK_DSP_WORD_LEVEL;
  241. info.monitor_level = (rmh.Stat[0] >> 10) & MASK_DSP_WORD_LEVEL;
  242. info.mute = (rmh.Stat[i] & AUDIO_IO_HAS_MUTE_LEVEL) ? 1 : 0;
  243. info.monitor_mute = (rmh.Stat[i] & AUDIO_IO_HAS_MUTE_MONITORING_1) ? 1 : 0;
  244. return 0;
  245. }
  246. #endif // not used
  247. /*
  248. * set the monitoring level and mute state of the given audio
  249. * no more static, because must be called from vx_pcm to demute monitoring
  250. */
  251. int vx_set_monitor_level(vx_core_t *chip, int audio, int level, int active)
  252. {
  253. struct vx_audio_level info;
  254. memset(&info, 0, sizeof(info));
  255. info.has_monitor_level = 1;
  256. info.monitor_level = level;
  257. info.has_monitor_mute = 1;
  258. info.monitor_mute = !active;
  259. chip->audio_monitor[audio] = level;
  260. chip->audio_monitor_active[audio] = active;
  261. return vx_adjust_audio_level(chip, audio, 0, &info); /* playback only */
  262. }
  263. /*
  264. * set the mute status of the given audio
  265. */
  266. static int vx_set_audio_switch(vx_core_t *chip, int audio, int active)
  267. {
  268. struct vx_audio_level info;
  269. memset(&info, 0, sizeof(info));
  270. info.has_mute = 1;
  271. info.mute = !active;
  272. chip->audio_active[audio] = active;
  273. return vx_adjust_audio_level(chip, audio, 0, &info); /* playback only */
  274. }
  275. /*
  276. * set the mute status of the given audio
  277. */
  278. static int vx_set_audio_gain(vx_core_t *chip, int audio, int capture, int level)
  279. {
  280. struct vx_audio_level info;
  281. memset(&info, 0, sizeof(info));
  282. info.has_level = 1;
  283. info.level = level;
  284. chip->audio_gain[capture][audio] = level;
  285. return vx_adjust_audio_level(chip, audio, capture, &info);
  286. }
  287. /*
  288. * reset all audio levels
  289. */
  290. static void vx_reset_audio_levels(vx_core_t *chip)
  291. {
  292. unsigned int i, c;
  293. struct vx_audio_level info;
  294. memset(chip->audio_gain, 0, sizeof(chip->audio_gain));
  295. memset(chip->audio_active, 0, sizeof(chip->audio_active));
  296. memset(chip->audio_monitor, 0, sizeof(chip->audio_monitor));
  297. memset(chip->audio_monitor_active, 0, sizeof(chip->audio_monitor_active));
  298. for (c = 0; c < 2; c++) {
  299. for (i = 0; i < chip->hw->num_ins * 2; i++) {
  300. memset(&info, 0, sizeof(info));
  301. if (c == 0) {
  302. info.has_monitor_level = 1;
  303. info.has_mute = 1;
  304. info.has_monitor_mute = 1;
  305. }
  306. info.has_level = 1;
  307. info.level = CVAL_0DB; /* default: 0dB */
  308. vx_adjust_audio_level(chip, i, c, &info);
  309. chip->audio_gain[c][i] = CVAL_0DB;
  310. chip->audio_monitor[i] = CVAL_0DB;
  311. }
  312. }
  313. }
  314. /*
  315. * VU, peak meter record
  316. */
  317. #define VU_METER_CHANNELS 2
  318. struct vx_vu_meter {
  319. int saturated;
  320. int vu_level;
  321. int peak_level;
  322. };
  323. /*
  324. * get the VU and peak meter values
  325. * @audio: the audio index
  326. * @capture: 0 = playback, 1 = capture operation
  327. * @info: the array of vx_vu_meter records (size = 2).
  328. */
  329. static int vx_get_audio_vu_meter(vx_core_t *chip, int audio, int capture, struct vx_vu_meter *info)
  330. {
  331. struct vx_rmh rmh;
  332. int i, err;
  333. if (chip->chip_status & VX_STAT_IS_STALE)
  334. return -EBUSY;
  335. vx_init_rmh(&rmh, CMD_AUDIO_VU_PIC_METER);
  336. rmh.LgStat += 2 * VU_METER_CHANNELS;
  337. if (capture)
  338. rmh.Cmd[0] |= COMMAND_RECORD_MASK;
  339. /* Add Audio IO mask */
  340. rmh.Cmd[1] = 0;
  341. for (i = 0; i < VU_METER_CHANNELS; i++)
  342. rmh.Cmd[1] |= 1 << (audio + i);
  343. err = vx_send_msg(chip, &rmh);
  344. if (err < 0)
  345. return err;
  346. /* Read response */
  347. for (i = 0; i < 2 * VU_METER_CHANNELS; i +=2) {
  348. info->saturated = (rmh.Stat[0] & (1 << (audio + i))) ? 1 : 0;
  349. info->vu_level = rmh.Stat[i + 1];
  350. info->peak_level = rmh.Stat[i + 2];
  351. info++;
  352. }
  353. return 0;
  354. }
  355. /*
  356. * control API entries
  357. */
  358. /*
  359. * output level control
  360. */
  361. static int vx_output_level_info(snd_kcontrol_t *kcontrol, snd_ctl_elem_info_t *uinfo)
  362. {
  363. vx_core_t *chip = snd_kcontrol_chip(kcontrol);
  364. uinfo->type = SNDRV_CTL_ELEM_TYPE_INTEGER;
  365. uinfo->count = 2;
  366. uinfo->value.integer.min = 0;
  367. uinfo->value.integer.max = chip->hw->output_level_max;
  368. return 0;
  369. }
  370. static int vx_output_level_get(snd_kcontrol_t *kcontrol, snd_ctl_elem_value_t *ucontrol)
  371. {
  372. vx_core_t *chip = snd_kcontrol_chip(kcontrol);
  373. int codec = kcontrol->id.index;
  374. down(&chip->mixer_mutex);
  375. ucontrol->value.integer.value[0] = chip->output_level[codec][0];
  376. ucontrol->value.integer.value[1] = chip->output_level[codec][1];
  377. up(&chip->mixer_mutex);
  378. return 0;
  379. }
  380. static int vx_output_level_put(snd_kcontrol_t *kcontrol, snd_ctl_elem_value_t *ucontrol)
  381. {
  382. vx_core_t *chip = snd_kcontrol_chip(kcontrol);
  383. int codec = kcontrol->id.index;
  384. down(&chip->mixer_mutex);
  385. if (ucontrol->value.integer.value[0] != chip->output_level[codec][0] ||
  386. ucontrol->value.integer.value[1] != chip->output_level[codec][1]) {
  387. vx_set_analog_output_level(chip, codec,
  388. ucontrol->value.integer.value[0],
  389. ucontrol->value.integer.value[1]);
  390. chip->output_level[codec][0] = ucontrol->value.integer.value[0];
  391. chip->output_level[codec][1] = ucontrol->value.integer.value[1];
  392. up(&chip->mixer_mutex);
  393. return 1;
  394. }
  395. up(&chip->mixer_mutex);
  396. return 0;
  397. }
  398. static snd_kcontrol_new_t vx_control_output_level = {
  399. .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
  400. .name = "Master Playback Volume",
  401. .info = vx_output_level_info,
  402. .get = vx_output_level_get,
  403. .put = vx_output_level_put,
  404. };
  405. /*
  406. * audio source select
  407. */
  408. static int vx_audio_src_info(snd_kcontrol_t *kcontrol, snd_ctl_elem_info_t *uinfo)
  409. {
  410. static char *texts_mic[3] = {
  411. "Digital", "Line", "Mic"
  412. };
  413. static char *texts_vx2[2] = {
  414. "Digital", "Analog"
  415. };
  416. vx_core_t *chip = snd_kcontrol_chip(kcontrol);
  417. uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED;
  418. uinfo->count = 1;
  419. if (chip->type >= VX_TYPE_VXPOCKET) {
  420. uinfo->value.enumerated.items = 3;
  421. if (uinfo->value.enumerated.item > 2)
  422. uinfo->value.enumerated.item = 2;
  423. strcpy(uinfo->value.enumerated.name,
  424. texts_mic[uinfo->value.enumerated.item]);
  425. } else {
  426. uinfo->value.enumerated.items = 2;
  427. if (uinfo->value.enumerated.item > 1)
  428. uinfo->value.enumerated.item = 1;
  429. strcpy(uinfo->value.enumerated.name,
  430. texts_vx2[uinfo->value.enumerated.item]);
  431. }
  432. return 0;
  433. }
  434. static int vx_audio_src_get(snd_kcontrol_t *kcontrol, snd_ctl_elem_value_t *ucontrol)
  435. {
  436. vx_core_t *chip = snd_kcontrol_chip(kcontrol);
  437. ucontrol->value.enumerated.item[0] = chip->audio_source_target;
  438. return 0;
  439. }
  440. static int vx_audio_src_put(snd_kcontrol_t *kcontrol, snd_ctl_elem_value_t *ucontrol)
  441. {
  442. vx_core_t *chip = snd_kcontrol_chip(kcontrol);
  443. down(&chip->mixer_mutex);
  444. if (chip->audio_source_target != ucontrol->value.enumerated.item[0]) {
  445. chip->audio_source_target = ucontrol->value.enumerated.item[0];
  446. vx_sync_audio_source(chip);
  447. up(&chip->mixer_mutex);
  448. return 1;
  449. }
  450. up(&chip->mixer_mutex);
  451. return 0;
  452. }
  453. static snd_kcontrol_new_t vx_control_audio_src = {
  454. .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
  455. .name = "Capture Source",
  456. .info = vx_audio_src_info,
  457. .get = vx_audio_src_get,
  458. .put = vx_audio_src_put,
  459. };
  460. /*
  461. * clock mode selection
  462. */
  463. static int vx_clock_mode_info(snd_kcontrol_t *kcontrol, snd_ctl_elem_info_t *uinfo)
  464. {
  465. static char *texts[3] = {
  466. "Auto", "Internal", "External"
  467. };
  468. uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED;
  469. uinfo->count = 1;
  470. uinfo->value.enumerated.items = 3;
  471. if (uinfo->value.enumerated.item > 2)
  472. uinfo->value.enumerated.item = 2;
  473. strcpy(uinfo->value.enumerated.name,
  474. texts[uinfo->value.enumerated.item]);
  475. return 0;
  476. }
  477. static int vx_clock_mode_get(snd_kcontrol_t *kcontrol, snd_ctl_elem_value_t *ucontrol)
  478. {
  479. vx_core_t *chip = snd_kcontrol_chip(kcontrol);
  480. ucontrol->value.enumerated.item[0] = chip->clock_mode;
  481. return 0;
  482. }
  483. static int vx_clock_mode_put(snd_kcontrol_t *kcontrol, snd_ctl_elem_value_t *ucontrol)
  484. {
  485. vx_core_t *chip = snd_kcontrol_chip(kcontrol);
  486. down(&chip->mixer_mutex);
  487. if (chip->clock_mode != ucontrol->value.enumerated.item[0]) {
  488. chip->clock_mode = ucontrol->value.enumerated.item[0];
  489. vx_set_clock(chip, chip->freq);
  490. up(&chip->mixer_mutex);
  491. return 1;
  492. }
  493. up(&chip->mixer_mutex);
  494. return 0;
  495. }
  496. static snd_kcontrol_new_t vx_control_clock_mode = {
  497. .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
  498. .name = "Clock Mode",
  499. .info = vx_clock_mode_info,
  500. .get = vx_clock_mode_get,
  501. .put = vx_clock_mode_put,
  502. };
  503. /*
  504. * Audio Gain
  505. */
  506. static int vx_audio_gain_info(snd_kcontrol_t *kcontrol, snd_ctl_elem_info_t *uinfo)
  507. {
  508. uinfo->type = SNDRV_CTL_ELEM_TYPE_INTEGER;
  509. uinfo->count = 2;
  510. uinfo->value.integer.min = 0;
  511. uinfo->value.integer.max = CVAL_MAX;
  512. return 0;
  513. }
  514. static int vx_audio_gain_get(snd_kcontrol_t *kcontrol, snd_ctl_elem_value_t *ucontrol)
  515. {
  516. vx_core_t *chip = snd_kcontrol_chip(kcontrol);
  517. int audio = kcontrol->private_value & 0xff;
  518. int capture = (kcontrol->private_value >> 8) & 1;
  519. down(&chip->mixer_mutex);
  520. ucontrol->value.integer.value[0] = chip->audio_gain[capture][audio];
  521. ucontrol->value.integer.value[1] = chip->audio_gain[capture][audio+1];
  522. up(&chip->mixer_mutex);
  523. return 0;
  524. }
  525. static int vx_audio_gain_put(snd_kcontrol_t *kcontrol, snd_ctl_elem_value_t *ucontrol)
  526. {
  527. vx_core_t *chip = snd_kcontrol_chip(kcontrol);
  528. int audio = kcontrol->private_value & 0xff;
  529. int capture = (kcontrol->private_value >> 8) & 1;
  530. down(&chip->mixer_mutex);
  531. if (ucontrol->value.integer.value[0] != chip->audio_gain[capture][audio] ||
  532. ucontrol->value.integer.value[1] != chip->audio_gain[capture][audio+1]) {
  533. vx_set_audio_gain(chip, audio, capture, ucontrol->value.integer.value[0]);
  534. vx_set_audio_gain(chip, audio+1, capture, ucontrol->value.integer.value[1]);
  535. up(&chip->mixer_mutex);
  536. return 1;
  537. }
  538. up(&chip->mixer_mutex);
  539. return 0;
  540. }
  541. static int vx_audio_monitor_get(snd_kcontrol_t *kcontrol, snd_ctl_elem_value_t *ucontrol)
  542. {
  543. vx_core_t *chip = snd_kcontrol_chip(kcontrol);
  544. int audio = kcontrol->private_value & 0xff;
  545. down(&chip->mixer_mutex);
  546. ucontrol->value.integer.value[0] = chip->audio_monitor[audio];
  547. ucontrol->value.integer.value[1] = chip->audio_monitor[audio+1];
  548. up(&chip->mixer_mutex);
  549. return 0;
  550. }
  551. static int vx_audio_monitor_put(snd_kcontrol_t *kcontrol, snd_ctl_elem_value_t *ucontrol)
  552. {
  553. vx_core_t *chip = snd_kcontrol_chip(kcontrol);
  554. int audio = kcontrol->private_value & 0xff;
  555. down(&chip->mixer_mutex);
  556. if (ucontrol->value.integer.value[0] != chip->audio_monitor[audio] ||
  557. ucontrol->value.integer.value[1] != chip->audio_monitor[audio+1]) {
  558. vx_set_monitor_level(chip, audio, ucontrol->value.integer.value[0],
  559. chip->audio_monitor_active[audio]);
  560. vx_set_monitor_level(chip, audio+1, ucontrol->value.integer.value[1],
  561. chip->audio_monitor_active[audio+1]);
  562. up(&chip->mixer_mutex);
  563. return 1;
  564. }
  565. up(&chip->mixer_mutex);
  566. return 0;
  567. }
  568. static int vx_audio_sw_info(snd_kcontrol_t *kcontrol, snd_ctl_elem_info_t *uinfo)
  569. {
  570. uinfo->type = SNDRV_CTL_ELEM_TYPE_BOOLEAN;
  571. uinfo->count = 2;
  572. uinfo->value.integer.min = 0;
  573. uinfo->value.integer.max = 1;
  574. return 0;
  575. }
  576. static int vx_audio_sw_get(snd_kcontrol_t *kcontrol, snd_ctl_elem_value_t *ucontrol)
  577. {
  578. vx_core_t *chip = snd_kcontrol_chip(kcontrol);
  579. int audio = kcontrol->private_value & 0xff;
  580. down(&chip->mixer_mutex);
  581. ucontrol->value.integer.value[0] = chip->audio_active[audio];
  582. ucontrol->value.integer.value[1] = chip->audio_active[audio+1];
  583. up(&chip->mixer_mutex);
  584. return 0;
  585. }
  586. static int vx_audio_sw_put(snd_kcontrol_t *kcontrol, snd_ctl_elem_value_t *ucontrol)
  587. {
  588. vx_core_t *chip = snd_kcontrol_chip(kcontrol);
  589. int audio = kcontrol->private_value & 0xff;
  590. down(&chip->mixer_mutex);
  591. if (ucontrol->value.integer.value[0] != chip->audio_active[audio] ||
  592. ucontrol->value.integer.value[1] != chip->audio_active[audio+1]) {
  593. vx_set_audio_switch(chip, audio, ucontrol->value.integer.value[0]);
  594. vx_set_audio_switch(chip, audio+1, ucontrol->value.integer.value[1]);
  595. up(&chip->mixer_mutex);
  596. return 1;
  597. }
  598. up(&chip->mixer_mutex);
  599. return 0;
  600. }
  601. static int vx_monitor_sw_get(snd_kcontrol_t *kcontrol, snd_ctl_elem_value_t *ucontrol)
  602. {
  603. vx_core_t *chip = snd_kcontrol_chip(kcontrol);
  604. int audio = kcontrol->private_value & 0xff;
  605. down(&chip->mixer_mutex);
  606. ucontrol->value.integer.value[0] = chip->audio_monitor_active[audio];
  607. ucontrol->value.integer.value[1] = chip->audio_monitor_active[audio+1];
  608. up(&chip->mixer_mutex);
  609. return 0;
  610. }
  611. static int vx_monitor_sw_put(snd_kcontrol_t *kcontrol, snd_ctl_elem_value_t *ucontrol)
  612. {
  613. vx_core_t *chip = snd_kcontrol_chip(kcontrol);
  614. int audio = kcontrol->private_value & 0xff;
  615. down(&chip->mixer_mutex);
  616. if (ucontrol->value.integer.value[0] != chip->audio_monitor_active[audio] ||
  617. ucontrol->value.integer.value[1] != chip->audio_monitor_active[audio+1]) {
  618. vx_set_monitor_level(chip, audio, chip->audio_monitor[audio],
  619. ucontrol->value.integer.value[0]);
  620. vx_set_monitor_level(chip, audio+1, chip->audio_monitor[audio+1],
  621. ucontrol->value.integer.value[1]);
  622. up(&chip->mixer_mutex);
  623. return 1;
  624. }
  625. up(&chip->mixer_mutex);
  626. return 0;
  627. }
  628. static snd_kcontrol_new_t vx_control_audio_gain = {
  629. .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
  630. /* name will be filled later */
  631. .info = vx_audio_gain_info,
  632. .get = vx_audio_gain_get,
  633. .put = vx_audio_gain_put
  634. };
  635. static snd_kcontrol_new_t vx_control_output_switch = {
  636. .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
  637. .name = "PCM Playback Switch",
  638. .info = vx_audio_sw_info,
  639. .get = vx_audio_sw_get,
  640. .put = vx_audio_sw_put
  641. };
  642. static snd_kcontrol_new_t vx_control_monitor_gain = {
  643. .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
  644. .name = "Monitoring Volume",
  645. .info = vx_audio_gain_info, /* shared */
  646. .get = vx_audio_monitor_get,
  647. .put = vx_audio_monitor_put
  648. };
  649. static snd_kcontrol_new_t vx_control_monitor_switch = {
  650. .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
  651. .name = "Monitoring Switch",
  652. .info = vx_audio_sw_info, /* shared */
  653. .get = vx_monitor_sw_get,
  654. .put = vx_monitor_sw_put
  655. };
  656. /*
  657. * IEC958 status bits
  658. */
  659. static int vx_iec958_info(snd_kcontrol_t *kcontrol, snd_ctl_elem_info_t *uinfo)
  660. {
  661. uinfo->type = SNDRV_CTL_ELEM_TYPE_IEC958;
  662. uinfo->count = 1;
  663. return 0;
  664. }
  665. static int vx_iec958_get(snd_kcontrol_t *kcontrol, snd_ctl_elem_value_t *ucontrol)
  666. {
  667. vx_core_t *chip = snd_kcontrol_chip(kcontrol);
  668. down(&chip->mixer_mutex);
  669. ucontrol->value.iec958.status[0] = (chip->uer_bits >> 0) & 0xff;
  670. ucontrol->value.iec958.status[1] = (chip->uer_bits >> 8) & 0xff;
  671. ucontrol->value.iec958.status[2] = (chip->uer_bits >> 16) & 0xff;
  672. ucontrol->value.iec958.status[3] = (chip->uer_bits >> 24) & 0xff;
  673. up(&chip->mixer_mutex);
  674. return 0;
  675. }
  676. static int vx_iec958_mask_get(snd_kcontrol_t * kcontrol, snd_ctl_elem_value_t *ucontrol)
  677. {
  678. ucontrol->value.iec958.status[0] = 0xff;
  679. ucontrol->value.iec958.status[1] = 0xff;
  680. ucontrol->value.iec958.status[2] = 0xff;
  681. ucontrol->value.iec958.status[3] = 0xff;
  682. return 0;
  683. }
  684. static int vx_iec958_put(snd_kcontrol_t *kcontrol, snd_ctl_elem_value_t *ucontrol)
  685. {
  686. vx_core_t *chip = snd_kcontrol_chip(kcontrol);
  687. unsigned int val;
  688. val = (ucontrol->value.iec958.status[0] << 0) |
  689. (ucontrol->value.iec958.status[1] << 8) |
  690. (ucontrol->value.iec958.status[2] << 16) |
  691. (ucontrol->value.iec958.status[3] << 24);
  692. down(&chip->mixer_mutex);
  693. if (chip->uer_bits != val) {
  694. chip->uer_bits = val;
  695. vx_set_iec958_status(chip, val);
  696. up(&chip->mixer_mutex);
  697. return 1;
  698. }
  699. up(&chip->mixer_mutex);
  700. return 0;
  701. }
  702. static snd_kcontrol_new_t vx_control_iec958_mask = {
  703. .access = SNDRV_CTL_ELEM_ACCESS_READ,
  704. .iface = SNDRV_CTL_ELEM_IFACE_PCM,
  705. .name = SNDRV_CTL_NAME_IEC958("",PLAYBACK,MASK),
  706. .info = vx_iec958_info, /* shared */
  707. .get = vx_iec958_mask_get,
  708. };
  709. static snd_kcontrol_new_t vx_control_iec958 = {
  710. .iface = SNDRV_CTL_ELEM_IFACE_PCM,
  711. .name = SNDRV_CTL_NAME_IEC958("",PLAYBACK,DEFAULT),
  712. .info = vx_iec958_info,
  713. .get = vx_iec958_get,
  714. .put = vx_iec958_put
  715. };
  716. /*
  717. * VU meter
  718. */
  719. #define METER_MAX 0xff
  720. #define METER_SHIFT 16
  721. static int vx_vu_meter_info(snd_kcontrol_t *kcontrol, snd_ctl_elem_info_t *uinfo)
  722. {
  723. uinfo->type = SNDRV_CTL_ELEM_TYPE_INTEGER;
  724. uinfo->count = 2;
  725. uinfo->value.integer.min = 0;
  726. uinfo->value.integer.max = METER_MAX;
  727. return 0;
  728. }
  729. static int vx_vu_meter_get(snd_kcontrol_t *kcontrol, snd_ctl_elem_value_t *ucontrol)
  730. {
  731. vx_core_t *chip = snd_kcontrol_chip(kcontrol);
  732. struct vx_vu_meter meter[2];
  733. int audio = kcontrol->private_value & 0xff;
  734. int capture = (kcontrol->private_value >> 8) & 1;
  735. vx_get_audio_vu_meter(chip, audio, capture, meter);
  736. ucontrol->value.integer.value[0] = meter[0].vu_level >> METER_SHIFT;
  737. ucontrol->value.integer.value[1] = meter[1].vu_level >> METER_SHIFT;
  738. return 0;
  739. }
  740. static int vx_peak_meter_get(snd_kcontrol_t *kcontrol, snd_ctl_elem_value_t *ucontrol)
  741. {
  742. vx_core_t *chip = snd_kcontrol_chip(kcontrol);
  743. struct vx_vu_meter meter[2];
  744. int audio = kcontrol->private_value & 0xff;
  745. int capture = (kcontrol->private_value >> 8) & 1;
  746. vx_get_audio_vu_meter(chip, audio, capture, meter);
  747. ucontrol->value.integer.value[0] = meter[0].peak_level >> METER_SHIFT;
  748. ucontrol->value.integer.value[1] = meter[1].peak_level >> METER_SHIFT;
  749. return 0;
  750. }
  751. static int vx_saturation_info(snd_kcontrol_t *kcontrol, snd_ctl_elem_info_t *uinfo)
  752. {
  753. uinfo->type = SNDRV_CTL_ELEM_TYPE_BOOLEAN;
  754. uinfo->count = 2;
  755. uinfo->value.integer.min = 0;
  756. uinfo->value.integer.max = 1;
  757. return 0;
  758. }
  759. static int vx_saturation_get(snd_kcontrol_t *kcontrol, snd_ctl_elem_value_t *ucontrol)
  760. {
  761. vx_core_t *chip = snd_kcontrol_chip(kcontrol);
  762. struct vx_vu_meter meter[2];
  763. int audio = kcontrol->private_value & 0xff;
  764. vx_get_audio_vu_meter(chip, audio, 1, meter); /* capture only */
  765. ucontrol->value.integer.value[0] = meter[0].saturated;
  766. ucontrol->value.integer.value[1] = meter[1].saturated;
  767. return 0;
  768. }
  769. static snd_kcontrol_new_t vx_control_vu_meter = {
  770. .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
  771. .access = SNDRV_CTL_ELEM_ACCESS_READ | SNDRV_CTL_ELEM_ACCESS_VOLATILE,
  772. /* name will be filled later */
  773. .info = vx_vu_meter_info,
  774. .get = vx_vu_meter_get,
  775. };
  776. static snd_kcontrol_new_t vx_control_peak_meter = {
  777. .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
  778. .access = SNDRV_CTL_ELEM_ACCESS_READ | SNDRV_CTL_ELEM_ACCESS_VOLATILE,
  779. /* name will be filled later */
  780. .info = vx_vu_meter_info, /* shared */
  781. .get = vx_peak_meter_get,
  782. };
  783. static snd_kcontrol_new_t vx_control_saturation = {
  784. .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
  785. .name = "Input Saturation",
  786. .access = SNDRV_CTL_ELEM_ACCESS_READ | SNDRV_CTL_ELEM_ACCESS_VOLATILE,
  787. .info = vx_saturation_info,
  788. .get = vx_saturation_get,
  789. };
  790. /*
  791. *
  792. */
  793. int snd_vx_mixer_new(vx_core_t *chip)
  794. {
  795. unsigned int i, c;
  796. int err;
  797. snd_kcontrol_new_t temp;
  798. snd_card_t *card = chip->card;
  799. char name[32];
  800. strcpy(card->mixername, card->driver);
  801. /* output level controls */
  802. for (i = 0; i < chip->hw->num_outs; i++) {
  803. temp = vx_control_output_level;
  804. temp.index = i;
  805. if ((err = snd_ctl_add(card, snd_ctl_new1(&temp, chip))) < 0)
  806. return err;
  807. }
  808. /* PCM volumes, switches, monitoring */
  809. for (i = 0; i < chip->hw->num_outs; i++) {
  810. int val = i * 2;
  811. temp = vx_control_audio_gain;
  812. temp.index = i;
  813. temp.name = "PCM Playback Volume";
  814. temp.private_value = val;
  815. if ((err = snd_ctl_add(card, snd_ctl_new1(&temp, chip))) < 0)
  816. return err;
  817. temp = vx_control_output_switch;
  818. temp.index = i;
  819. temp.private_value = val;
  820. if ((err = snd_ctl_add(card, snd_ctl_new1(&temp, chip))) < 0)
  821. return err;
  822. temp = vx_control_monitor_gain;
  823. temp.index = i;
  824. temp.private_value = val;
  825. if ((err = snd_ctl_add(card, snd_ctl_new1(&temp, chip))) < 0)
  826. return err;
  827. temp = vx_control_monitor_switch;
  828. temp.index = i;
  829. temp.private_value = val;
  830. if ((err = snd_ctl_add(card, snd_ctl_new1(&temp, chip))) < 0)
  831. return err;
  832. }
  833. for (i = 0; i < chip->hw->num_outs; i++) {
  834. temp = vx_control_audio_gain;
  835. temp.index = i;
  836. temp.name = "PCM Capture Volume";
  837. temp.private_value = (i * 2) | (1 << 8);
  838. if ((err = snd_ctl_add(card, snd_ctl_new1(&temp, chip))) < 0)
  839. return err;
  840. }
  841. /* Audio source */
  842. if ((err = snd_ctl_add(card, snd_ctl_new1(&vx_control_audio_src, chip))) < 0)
  843. return err;
  844. /* clock mode */
  845. if ((err = snd_ctl_add(card, snd_ctl_new1(&vx_control_clock_mode, chip))) < 0)
  846. return err;
  847. /* IEC958 controls */
  848. if ((err = snd_ctl_add(card, snd_ctl_new1(&vx_control_iec958_mask, chip))) < 0)
  849. return err;
  850. if ((err = snd_ctl_add(card, snd_ctl_new1(&vx_control_iec958, chip))) < 0)
  851. return err;
  852. /* VU, peak, saturation meters */
  853. for (c = 0; c < 2; c++) {
  854. static char *dir[2] = { "Output", "Input" };
  855. for (i = 0; i < chip->hw->num_ins; i++) {
  856. int val = (i * 2) | (c << 8);
  857. if (c == 1) {
  858. temp = vx_control_saturation;
  859. temp.index = i;
  860. temp.private_value = val;
  861. if ((err = snd_ctl_add(card, snd_ctl_new1(&temp, chip))) < 0)
  862. return err;
  863. }
  864. sprintf(name, "%s VU Meter", dir[c]);
  865. temp = vx_control_vu_meter;
  866. temp.index = i;
  867. temp.name = name;
  868. temp.private_value = val;
  869. if ((err = snd_ctl_add(card, snd_ctl_new1(&temp, chip))) < 0)
  870. return err;
  871. sprintf(name, "%s Peak Meter", dir[c]);
  872. temp = vx_control_peak_meter;
  873. temp.index = i;
  874. temp.name = name;
  875. temp.private_value = val;
  876. if ((err = snd_ctl_add(card, snd_ctl_new1(&temp, chip))) < 0)
  877. return err;
  878. }
  879. }
  880. vx_reset_audio_levels(chip);
  881. return 0;
  882. }