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

source code of linux/sound/pcmcia/vx/vxp_mixer.c