vxp_mixer.c 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148
  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 "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(snd_kcontrol_t *kcontrol, snd_ctl_elem_info_t *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(snd_kcontrol_t *kcontrol, snd_ctl_elem_value_t *ucontrol)
  40. {
  41. vx_core_t *_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(snd_kcontrol_t *kcontrol, snd_ctl_elem_value_t *ucontrol)
  47. {
  48. vx_core_t *_chip = snd_kcontrol_chip(kcontrol);
  49. struct snd_vxpocket *chip = (struct snd_vxpocket *)_chip;
  50. down(&_chip->mixer_mutex);
  51. if (chip->mic_level != ucontrol->value.integer.value[0]) {
  52. vx_set_mic_level(_chip, ucontrol->value.integer.value[0]);
  53. chip->mic_level = ucontrol->value.integer.value[0];
  54. up(&_chip->mixer_mutex);
  55. return 1;
  56. }
  57. up(&_chip->mixer_mutex);
  58. return 0;
  59. }
  60. static snd_kcontrol_new_t vx_control_mic_level = {
  61. .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
  62. .name = "Mic Capture Volume",
  63. .info = vx_mic_level_info,
  64. .get = vx_mic_level_get,
  65. .put = vx_mic_level_put,
  66. };
  67. /*
  68. * mic boost level control (for VXP440)
  69. */
  70. static int vx_mic_boost_info(snd_kcontrol_t *kcontrol, snd_ctl_elem_info_t *uinfo)
  71. {
  72. uinfo->type = SNDRV_CTL_ELEM_TYPE_BOOLEAN;
  73. uinfo->count = 1;
  74. uinfo->value.integer.min = 0;
  75. uinfo->value.integer.max = 1;
  76. return 0;
  77. }
  78. static int vx_mic_boost_get(snd_kcontrol_t *kcontrol, snd_ctl_elem_value_t *ucontrol)
  79. {
  80. vx_core_t *_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(snd_kcontrol_t *kcontrol, snd_ctl_elem_value_t *ucontrol)
  86. {
  87. vx_core_t *_chip = snd_kcontrol_chip(kcontrol);
  88. struct snd_vxpocket *chip = (struct snd_vxpocket *)_chip;
  89. down(&_chip->mixer_mutex);
  90. if (chip->mic_level != ucontrol->value.integer.value[0]) {
  91. vx_set_mic_boost(_chip, ucontrol->value.integer.value[0]);
  92. chip->mic_level = ucontrol->value.integer.value[0];
  93. up(&_chip->mixer_mutex);
  94. return 1;
  95. }
  96. up(&_chip->mixer_mutex);
  97. return 0;
  98. }
  99. static snd_kcontrol_new_t vx_control_mic_boost = {
  100. .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
  101. .name = "Mic Boost",
  102. .info = vx_mic_boost_info,
  103. .get = vx_mic_boost_get,
  104. .put = vx_mic_boost_put,
  105. };
  106. int vxp_add_mic_controls(vx_core_t *_chip)
  107. {
  108. struct snd_vxpocket *chip = (struct snd_vxpocket *)_chip;
  109. int err;
  110. /* mute input levels */
  111. chip->mic_level = 0;
  112. switch (_chip->type) {
  113. case VX_TYPE_VXPOCKET:
  114. vx_set_mic_level(_chip, 0);
  115. break;
  116. case VX_TYPE_VXP440:
  117. vx_set_mic_boost(_chip, 0);
  118. break;
  119. }
  120. /* mic level */
  121. switch (_chip->type) {
  122. case VX_TYPE_VXPOCKET:
  123. if ((err = snd_ctl_add(_chip->card, snd_ctl_new1(&vx_control_mic_level, chip))) < 0)
  124. return err;
  125. break;
  126. case VX_TYPE_VXP440:
  127. if ((err = snd_ctl_add(_chip->card, snd_ctl_new1(&vx_control_mic_boost, chip))) < 0)
  128. return err;
  129. break;
  130. }
  131. return 0;
  132. }