vxp_mixer.c 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154
  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. mutex_lock(&_chip->mixer_mutex);
  52. if (chip->mic_level != ucontrol->value.integer.value[0]) {
  53. vx_set_mic_level(_chip, ucontrol->value.integer.value[0]);
  54. chip->mic_level = ucontrol->value.integer.value[0];
  55. mutex_unlock(&_chip->mixer_mutex);
  56. return 1;
  57. }
  58. mutex_unlock(&_chip->mixer_mutex);
  59. return 0;
  60. }
  61. static const DECLARE_TLV_DB_SCALE(db_scale_mic, -21, 3, 0);
  62. static struct snd_kcontrol_new vx_control_mic_level = {
  63. .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
  64. .access = (SNDRV_CTL_ELEM_ACCESS_READWRITE |
  65. SNDRV_CTL_ELEM_ACCESS_TLV_READ),
  66. .name = "Mic Capture Volume",
  67. .info = vx_mic_level_info,
  68. .get = vx_mic_level_get,
  69. .put = vx_mic_level_put,
  70. .tlv = { .p = db_scale_mic },
  71. };
  72. /*
  73. * mic boost level control (for VXP440)
  74. */
  75. static int vx_mic_boost_info(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_info *uinfo)
  76. {
  77. uinfo->type = SNDRV_CTL_ELEM_TYPE_BOOLEAN;
  78. uinfo->count = 1;
  79. uinfo->value.integer.min = 0;
  80. uinfo->value.integer.max = 1;
  81. return 0;
  82. }
  83. static int vx_mic_boost_get(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
  84. {
  85. struct vx_core *_chip = snd_kcontrol_chip(kcontrol);
  86. struct snd_vxpocket *chip = (struct snd_vxpocket *)_chip;
  87. ucontrol->value.integer.value[0] = chip->mic_level;
  88. return 0;
  89. }
  90. static int vx_mic_boost_put(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
  91. {
  92. struct vx_core *_chip = snd_kcontrol_chip(kcontrol);
  93. struct snd_vxpocket *chip = (struct snd_vxpocket *)_chip;
  94. mutex_lock(&_chip->mixer_mutex);
  95. if (chip->mic_level != ucontrol->value.integer.value[0]) {
  96. vx_set_mic_boost(_chip, ucontrol->value.integer.value[0]);
  97. chip->mic_level = ucontrol->value.integer.value[0];
  98. mutex_unlock(&_chip->mixer_mutex);
  99. return 1;
  100. }
  101. mutex_unlock(&_chip->mixer_mutex);
  102. return 0;
  103. }
  104. static struct snd_kcontrol_new vx_control_mic_boost = {
  105. .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
  106. .name = "Mic Boost",
  107. .info = vx_mic_boost_info,
  108. .get = vx_mic_boost_get,
  109. .put = vx_mic_boost_put,
  110. };
  111. int vxp_add_mic_controls(struct vx_core *_chip)
  112. {
  113. struct snd_vxpocket *chip = (struct snd_vxpocket *)_chip;
  114. int err;
  115. /* mute input levels */
  116. chip->mic_level = 0;
  117. switch (_chip->type) {
  118. case VX_TYPE_VXPOCKET:
  119. vx_set_mic_level(_chip, 0);
  120. break;
  121. case VX_TYPE_VXP440:
  122. vx_set_mic_boost(_chip, 0);
  123. break;
  124. }
  125. /* mic level */
  126. switch (_chip->type) {
  127. case VX_TYPE_VXPOCKET:
  128. if ((err = snd_ctl_add(_chip->card, snd_ctl_new1(&vx_control_mic_level, chip))) < 0)
  129. return err;
  130. break;
  131. case VX_TYPE_VXP440:
  132. if ((err = snd_ctl_add(_chip->card, snd_ctl_new1(&vx_control_mic_boost, chip))) < 0)
  133. return err;
  134. break;
  135. }
  136. return 0;
  137. }