blob: e237f6c2018f0b545ba11ad60ca74e3d12194f71 [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/*
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
23#include <sound/driver.h>
24#include <sound/core.h>
25#include <sound/control.h>
26#include "vxpocket.h"
27
28#define MIC_LEVEL_MIN 0
29#define MIC_LEVEL_MAX 8
30
31/*
32 * mic level control (for VXPocket)
33 */
Takashi Iwaiaf263672005-11-17 14:46:59 +010034static int vx_mic_level_info(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_info *uinfo)
Linus Torvalds1da177e2005-04-16 15:20:36 -070035{
36 uinfo->type = SNDRV_CTL_ELEM_TYPE_INTEGER;
37 uinfo->count = 1;
38 uinfo->value.integer.min = 0;
39 uinfo->value.integer.max = MIC_LEVEL_MAX;
40 return 0;
41}
42
Takashi Iwaiaf263672005-11-17 14:46:59 +010043static int vx_mic_level_get(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
Linus Torvalds1da177e2005-04-16 15:20:36 -070044{
Takashi Iwaiaf263672005-11-17 14:46:59 +010045 struct vx_core *_chip = snd_kcontrol_chip(kcontrol);
Linus Torvalds1da177e2005-04-16 15:20:36 -070046 struct snd_vxpocket *chip = (struct snd_vxpocket *)_chip;
47 ucontrol->value.integer.value[0] = chip->mic_level;
48 return 0;
49}
50
Takashi Iwaiaf263672005-11-17 14:46:59 +010051static int vx_mic_level_put(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
Linus Torvalds1da177e2005-04-16 15:20:36 -070052{
Takashi Iwaiaf263672005-11-17 14:46:59 +010053 struct vx_core *_chip = snd_kcontrol_chip(kcontrol);
Linus Torvalds1da177e2005-04-16 15:20:36 -070054 struct snd_vxpocket *chip = (struct snd_vxpocket *)_chip;
Ingo Molnar12aa7572006-01-16 16:36:05 +010055 mutex_lock(&_chip->mixer_mutex);
Linus Torvalds1da177e2005-04-16 15:20:36 -070056 if (chip->mic_level != ucontrol->value.integer.value[0]) {
57 vx_set_mic_level(_chip, ucontrol->value.integer.value[0]);
58 chip->mic_level = ucontrol->value.integer.value[0];
Ingo Molnar12aa7572006-01-16 16:36:05 +010059 mutex_unlock(&_chip->mixer_mutex);
Linus Torvalds1da177e2005-04-16 15:20:36 -070060 return 1;
61 }
Ingo Molnar12aa7572006-01-16 16:36:05 +010062 mutex_unlock(&_chip->mixer_mutex);
Linus Torvalds1da177e2005-04-16 15:20:36 -070063 return 0;
64}
65
Takashi Iwaiaf263672005-11-17 14:46:59 +010066static struct snd_kcontrol_new vx_control_mic_level = {
Linus Torvalds1da177e2005-04-16 15:20:36 -070067 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
68 .name = "Mic Capture Volume",
69 .info = vx_mic_level_info,
70 .get = vx_mic_level_get,
71 .put = vx_mic_level_put,
72};
73
74/*
75 * mic boost level control (for VXP440)
76 */
Takashi Iwaiaf263672005-11-17 14:46:59 +010077static int vx_mic_boost_info(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_info *uinfo)
Linus Torvalds1da177e2005-04-16 15:20:36 -070078{
79 uinfo->type = SNDRV_CTL_ELEM_TYPE_BOOLEAN;
80 uinfo->count = 1;
81 uinfo->value.integer.min = 0;
82 uinfo->value.integer.max = 1;
83 return 0;
84}
85
Takashi Iwaiaf263672005-11-17 14:46:59 +010086static int vx_mic_boost_get(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
Linus Torvalds1da177e2005-04-16 15:20:36 -070087{
Takashi Iwaiaf263672005-11-17 14:46:59 +010088 struct vx_core *_chip = snd_kcontrol_chip(kcontrol);
Linus Torvalds1da177e2005-04-16 15:20:36 -070089 struct snd_vxpocket *chip = (struct snd_vxpocket *)_chip;
90 ucontrol->value.integer.value[0] = chip->mic_level;
91 return 0;
92}
93
Takashi Iwaiaf263672005-11-17 14:46:59 +010094static int vx_mic_boost_put(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
Linus Torvalds1da177e2005-04-16 15:20:36 -070095{
Takashi Iwaiaf263672005-11-17 14:46:59 +010096 struct vx_core *_chip = snd_kcontrol_chip(kcontrol);
Linus Torvalds1da177e2005-04-16 15:20:36 -070097 struct snd_vxpocket *chip = (struct snd_vxpocket *)_chip;
Ingo Molnar12aa7572006-01-16 16:36:05 +010098 mutex_lock(&_chip->mixer_mutex);
Linus Torvalds1da177e2005-04-16 15:20:36 -070099 if (chip->mic_level != ucontrol->value.integer.value[0]) {
100 vx_set_mic_boost(_chip, ucontrol->value.integer.value[0]);
101 chip->mic_level = ucontrol->value.integer.value[0];
Ingo Molnar12aa7572006-01-16 16:36:05 +0100102 mutex_unlock(&_chip->mixer_mutex);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700103 return 1;
104 }
Ingo Molnar12aa7572006-01-16 16:36:05 +0100105 mutex_unlock(&_chip->mixer_mutex);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700106 return 0;
107}
108
Takashi Iwaiaf263672005-11-17 14:46:59 +0100109static struct snd_kcontrol_new vx_control_mic_boost = {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700110 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
111 .name = "Mic Boost",
112 .info = vx_mic_boost_info,
113 .get = vx_mic_boost_get,
114 .put = vx_mic_boost_put,
115};
116
117
Takashi Iwaiaf263672005-11-17 14:46:59 +0100118int vxp_add_mic_controls(struct vx_core *_chip)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700119{
120 struct snd_vxpocket *chip = (struct snd_vxpocket *)_chip;
121 int err;
122
123 /* mute input levels */
124 chip->mic_level = 0;
125 switch (_chip->type) {
126 case VX_TYPE_VXPOCKET:
127 vx_set_mic_level(_chip, 0);
128 break;
129 case VX_TYPE_VXP440:
130 vx_set_mic_boost(_chip, 0);
131 break;
132 }
133
134 /* mic level */
135 switch (_chip->type) {
136 case VX_TYPE_VXPOCKET:
137 if ((err = snd_ctl_add(_chip->card, snd_ctl_new1(&vx_control_mic_level, chip))) < 0)
138 return err;
139 break;
140 case VX_TYPE_VXP440:
141 if ((err = snd_ctl_add(_chip->card, snd_ctl_new1(&vx_control_mic_boost, chip))) < 0)
142 return err;
143 break;
144 }
145
146 return 0;
147}
148