vxp_mixer.c 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152
  1. /*
  2. * Driver for Digigram VXpocket soundcards
  3. *
  4. * VX-pocket mixer
  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/core.h>
  23. #include <sound/control.h>
  24. #include <sound/tlv.h>
  25. #include "vxpocket.h"
  26. #define MIC_LEVEL_MIN 0
  27. #define MIC_LEVEL_MAX 8
  28. /*
  29. * mic level control (for VXPocket)
  30. */
  31. static int vx_mic_level_info(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_info *uinfo)
  32. {
  33. uinfo->type = SNDRV_CTL_ELEM_TYPE_INTEGER;
  34. uinfo->count = 1;
  35. uinfo->value.integer.min = 0;
  36. uinfo->value.integer.max = MIC_LEVEL_MAX;
  37. return 0;
  38. }
  39. static int vx_mic_level_get(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
  40. {
  41. struct vx_core *_chip = snd_kcontrol_chip(kcontrol);
  42. struct snd_vxpocket *chip = (struct snd_vxpocket *)_chip;
  43. ucontrol->value.integer.value[0] = chip->mic_level;
  44. return 0;
  45. }
  46. static int vx_mic_level_put(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
  47. {
  48. struct vx_core *_chip = snd_kcontrol_chip(kcontrol);
  49. struct snd_vxpocket *chip = (struct snd_vxpocket *)_chip;
  50. unsigned int val = ucontrol->value.integer.value[0];
  51. if (val > MIC_LEVEL_MAX)
  52. return -EINVAL;
  53. mutex_lock(&_chip->mixer_mutex);
  54. if (chip->mic_level != ucontrol->value.integer.value[0]) {
  55. vx_set_mic_level(_chip, ucontrol->value.integer.value[0]);
  56. chip->mic_level = ucontrol->value.integer.value[0];
  57. mutex_unlock(&_chip->mixer_mutex);
  58. return 1;
  59. }
  60. mutex_unlock(&_chip->mixer_mutex);
  61. return 0;
  62. }
  63. static const DECLARE_TLV_DB_SCALE(db_scale_mic, -21, 3, 0);
  64. static struct snd_kcontrol_new vx_control_mic_level = {
  65. .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
  66. .access = (SNDRV_CTL_ELEM_ACCESS_READWRITE |
  67. SNDRV_CTL_ELEM_ACCESS_TLV_READ),
  68. .name = "Mic Capture Volume",
  69. .info = vx_mic_level_info,
  70. .get = vx_mic_level_get,
  71. .put = vx_mic_level_put,
  72. .tlv = { .p = db_scale_mic },
  73. };
  74. /*
  75. * mic boost level control (for VXP440)
  76. */
  77. #define vx_mic_boost_info snd_ctl_boolean_mono_info
  78. static int vx_mic_boost_get(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
  79. {
  80. struct vx_core *_chip = snd_kcontrol_chip(kcontrol);
  81. struct snd_vxpocket *chip = (struct snd_vxpocket *)_chip;
  82. ucontrol->value.integer.value[0] = chip->mic_level;
  83. return 0;
  84. }
  85. static int vx_mic_boost_put(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
  86. {
  87. struct vx_core *_chip = snd_kcontrol_chip(kcontrol);
  88. struct snd_vxpocket *chip = (struct snd_vxpocket *)_chip;
  89. int val = !!ucontrol->value.integer.value[0];
  90. mutex_lock(&_chip->mixer_mutex);
  91. if (chip->mic_level != val) {
  92. vx_set_mic_boost(_chip, val);
  93. chip->mic_level = val;
  94. mutex_unlock(&_chip->mixer_mutex);
  95. return 1;
  96. }
  97. mutex_unlock(&_chip->mixer_mutex);
  98. return 0;
  99. }
  100. static struct snd_kcontrol_new vx_control_mic_boost = {
  101. .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
  102. .name = "Mic Boost",
  103. .info = vx_mic_boost_info,
  104. .get = vx_mic_boost_get,
  105. .put = vx_mic_boost_put,
  106. };
  107. int vxp_add_mic_controls(struct vx_core *_chip)
  108. {
  109. struct snd_vxpocket *chip = (struct snd_vxpocket *)_chip;
  110. int err;
  111. /* mute input levels */
  112. chip->mic_level = 0;
  113. switch (_chip->type) {
  114. case VX_TYPE_VXPOCKET:
  115. vx_set_mic_level(_chip, 0);
  116. break;
  117. case VX_TYPE_VXP440:
  118. vx_set_mic_boost(_chip, 0);
  119. break;
  120. }
  121. /* mic level */
  122. switch (_chip->type) {
  123. case VX_TYPE_VXPOCKET:
  124. if ((err = snd_ctl_add(_chip->card, snd_ctl_new1(&vx_control_mic_level, chip))) < 0)
  125. return err;
  126. break;
  127. case VX_TYPE_VXP440:
  128. if ((err = snd_ctl_add(_chip->card, snd_ctl_new1(&vx_control_mic_boost, chip))) < 0)
  129. return err;
  130. break;
  131. }
  132. return 0;
  133. }