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