1 // SPDX-License-Identifier: GPL-2.0-or-later
3 * Driver for Digigram VXpocket soundcards
7 * Copyright (c) 2002 by Takashi Iwai <tiwai@suse.de>
10 #include <sound/core.h>
11 #include <sound/control.h>
12 #include <sound/tlv.h>
15 #define MIC_LEVEL_MIN 0
16 #define MIC_LEVEL_MAX 8
19 * mic level control (for VXPocket)
21 static int vx_mic_level_info(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_info *uinfo)
23 uinfo->type = SNDRV_CTL_ELEM_TYPE_INTEGER;
25 uinfo->value.integer.min = 0;
26 uinfo->value.integer.max = MIC_LEVEL_MAX;
30 static int vx_mic_level_get(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
32 struct vx_core *_chip = snd_kcontrol_chip(kcontrol);
33 struct snd_vxpocket *chip = to_vxpocket(_chip);
34 ucontrol->value.integer.value[0] = chip->mic_level;
38 static int vx_mic_level_put(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
40 struct vx_core *_chip = snd_kcontrol_chip(kcontrol);
41 struct snd_vxpocket *chip = to_vxpocket(_chip);
42 unsigned int val = ucontrol->value.integer.value[0];
44 if (val > MIC_LEVEL_MAX)
46 mutex_lock(&_chip->mixer_mutex);
47 if (chip->mic_level != ucontrol->value.integer.value[0]) {
48 vx_set_mic_level(_chip, ucontrol->value.integer.value[0]);
49 chip->mic_level = ucontrol->value.integer.value[0];
50 mutex_unlock(&_chip->mixer_mutex);
53 mutex_unlock(&_chip->mixer_mutex);
57 static const DECLARE_TLV_DB_SCALE(db_scale_mic, -21, 3, 0);
59 static const struct snd_kcontrol_new vx_control_mic_level = {
60 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
61 .access = (SNDRV_CTL_ELEM_ACCESS_READWRITE |
62 SNDRV_CTL_ELEM_ACCESS_TLV_READ),
63 .name = "Mic Capture Volume",
64 .info = vx_mic_level_info,
65 .get = vx_mic_level_get,
66 .put = vx_mic_level_put,
67 .tlv = { .p = db_scale_mic },
71 * mic boost level control (for VXP440)
73 #define vx_mic_boost_info snd_ctl_boolean_mono_info
75 static int vx_mic_boost_get(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
77 struct vx_core *_chip = snd_kcontrol_chip(kcontrol);
78 struct snd_vxpocket *chip = to_vxpocket(_chip);
79 ucontrol->value.integer.value[0] = chip->mic_level;
83 static int vx_mic_boost_put(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
85 struct vx_core *_chip = snd_kcontrol_chip(kcontrol);
86 struct snd_vxpocket *chip = to_vxpocket(_chip);
87 int val = !!ucontrol->value.integer.value[0];
88 mutex_lock(&_chip->mixer_mutex);
89 if (chip->mic_level != val) {
90 vx_set_mic_boost(_chip, val);
91 chip->mic_level = val;
92 mutex_unlock(&_chip->mixer_mutex);
95 mutex_unlock(&_chip->mixer_mutex);
99 static const struct snd_kcontrol_new vx_control_mic_boost = {
100 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
102 .info = vx_mic_boost_info,
103 .get = vx_mic_boost_get,
104 .put = vx_mic_boost_put,
108 int vxp_add_mic_controls(struct vx_core *_chip)
110 struct snd_vxpocket *chip = to_vxpocket(_chip);
113 /* mute input levels */
115 switch (_chip->type) {
116 case VX_TYPE_VXPOCKET:
117 vx_set_mic_level(_chip, 0);
120 vx_set_mic_boost(_chip, 0);
125 switch (_chip->type) {
126 case VX_TYPE_VXPOCKET:
127 err = snd_ctl_add(_chip->card, snd_ctl_new1(&vx_control_mic_level, chip));
132 err = snd_ctl_add(_chip->card, snd_ctl_new1(&vx_control_mic_boost, chip));