blob: 1eff158b8687327b6e4584bd829def4122abf5da [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>
Takashi Iwaid0ae4842006-08-29 18:15:15 +020026#include <sound/tlv.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070027#include "vxpocket.h"
28
29#define MIC_LEVEL_MIN 0
30#define MIC_LEVEL_MAX 8
31
32/*
33 * mic level control (for VXPocket)
34 */
Takashi Iwaiaf263672005-11-17 14:46:59 +010035static int vx_mic_level_info(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_info *uinfo)
Linus Torvalds1da177e2005-04-16 15:20:36 -070036{
37 uinfo->type = SNDRV_CTL_ELEM_TYPE_INTEGER;
38 uinfo->count = 1;
39 uinfo->value.integer.min = 0;
40 uinfo->value.integer.max = MIC_LEVEL_MAX;
41 return 0;
42}
43
Takashi Iwaiaf263672005-11-17 14:46:59 +010044static int vx_mic_level_get(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
Linus Torvalds1da177e2005-04-16 15:20:36 -070045{
Takashi Iwaiaf263672005-11-17 14:46:59 +010046 struct vx_core *_chip = snd_kcontrol_chip(kcontrol);
Linus Torvalds1da177e2005-04-16 15:20:36 -070047 struct snd_vxpocket *chip = (struct snd_vxpocket *)_chip;
48 ucontrol->value.integer.value[0] = chip->mic_level;
49 return 0;
50}
51
Takashi Iwaiaf263672005-11-17 14:46:59 +010052static int vx_mic_level_put(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
Linus Torvalds1da177e2005-04-16 15:20:36 -070053{
Takashi Iwaiaf263672005-11-17 14:46:59 +010054 struct vx_core *_chip = snd_kcontrol_chip(kcontrol);
Linus Torvalds1da177e2005-04-16 15:20:36 -070055 struct snd_vxpocket *chip = (struct snd_vxpocket *)_chip;
Ingo Molnar12aa7572006-01-16 16:36:05 +010056 mutex_lock(&_chip->mixer_mutex);
Linus Torvalds1da177e2005-04-16 15:20:36 -070057 if (chip->mic_level != ucontrol->value.integer.value[0]) {
58 vx_set_mic_level(_chip, ucontrol->value.integer.value[0]);
59 chip->mic_level = ucontrol->value.integer.value[0];
Ingo Molnar12aa7572006-01-16 16:36:05 +010060 mutex_unlock(&_chip->mixer_mutex);
Linus Torvalds1da177e2005-04-16 15:20:36 -070061 return 1;
62 }
Ingo Molnar12aa7572006-01-16 16:36:05 +010063 mutex_unlock(&_chip->mixer_mutex);
Linus Torvalds1da177e2005-04-16 15:20:36 -070064 return 0;
65}
66
Takashi Iwai0cb29ea2007-01-29 15:33:49 +010067static const DECLARE_TLV_DB_SCALE(db_scale_mic, -21, 3, 0);
Takashi Iwaid0ae4842006-08-29 18:15:15 +020068
Takashi Iwaiaf263672005-11-17 14:46:59 +010069static struct snd_kcontrol_new vx_control_mic_level = {
Linus Torvalds1da177e2005-04-16 15:20:36 -070070 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
Takashi Iwaid0ae4842006-08-29 18:15:15 +020071 .access = (SNDRV_CTL_ELEM_ACCESS_READWRITE |
72 SNDRV_CTL_ELEM_ACCESS_TLV_READ),
Linus Torvalds1da177e2005-04-16 15:20:36 -070073 .name = "Mic Capture Volume",
74 .info = vx_mic_level_info,
75 .get = vx_mic_level_get,
76 .put = vx_mic_level_put,
Takashi Iwaid0ae4842006-08-29 18:15:15 +020077 .tlv = { .p = db_scale_mic },
Linus Torvalds1da177e2005-04-16 15:20:36 -070078};
79
80/*
81 * mic boost level control (for VXP440)
82 */
Takashi Iwaia5ce8892007-07-23 15:42:26 +020083#define vx_mic_boost_info snd_ctl_boolean_mono_info
Linus Torvalds1da177e2005-04-16 15:20:36 -070084
Takashi Iwaiaf263672005-11-17 14:46:59 +010085static int vx_mic_boost_get(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
Linus Torvalds1da177e2005-04-16 15:20:36 -070086{
Takashi Iwaiaf263672005-11-17 14:46:59 +010087 struct vx_core *_chip = snd_kcontrol_chip(kcontrol);
Linus Torvalds1da177e2005-04-16 15:20:36 -070088 struct snd_vxpocket *chip = (struct snd_vxpocket *)_chip;
89 ucontrol->value.integer.value[0] = chip->mic_level;
90 return 0;
91}
92
Takashi Iwaiaf263672005-11-17 14:46:59 +010093static int vx_mic_boost_put(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
Linus Torvalds1da177e2005-04-16 15:20:36 -070094{
Takashi Iwaiaf263672005-11-17 14:46:59 +010095 struct vx_core *_chip = snd_kcontrol_chip(kcontrol);
Linus Torvalds1da177e2005-04-16 15:20:36 -070096 struct snd_vxpocket *chip = (struct snd_vxpocket *)_chip;
Ingo Molnar12aa7572006-01-16 16:36:05 +010097 mutex_lock(&_chip->mixer_mutex);
Linus Torvalds1da177e2005-04-16 15:20:36 -070098 if (chip->mic_level != ucontrol->value.integer.value[0]) {
99 vx_set_mic_boost(_chip, ucontrol->value.integer.value[0]);
100 chip->mic_level = ucontrol->value.integer.value[0];
Ingo Molnar12aa7572006-01-16 16:36:05 +0100101 mutex_unlock(&_chip->mixer_mutex);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700102 return 1;
103 }
Ingo Molnar12aa7572006-01-16 16:36:05 +0100104 mutex_unlock(&_chip->mixer_mutex);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700105 return 0;
106}
107
Takashi Iwaiaf263672005-11-17 14:46:59 +0100108static struct snd_kcontrol_new vx_control_mic_boost = {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700109 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
110 .name = "Mic Boost",
111 .info = vx_mic_boost_info,
112 .get = vx_mic_boost_get,
113 .put = vx_mic_boost_put,
114};
115
116
Takashi Iwaiaf263672005-11-17 14:46:59 +0100117int vxp_add_mic_controls(struct vx_core *_chip)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700118{
119 struct snd_vxpocket *chip = (struct snd_vxpocket *)_chip;
120 int err;
121
122 /* mute input levels */
123 chip->mic_level = 0;
124 switch (_chip->type) {
125 case VX_TYPE_VXPOCKET:
126 vx_set_mic_level(_chip, 0);
127 break;
128 case VX_TYPE_VXP440:
129 vx_set_mic_boost(_chip, 0);
130 break;
131 }
132
133 /* mic level */
134 switch (_chip->type) {
135 case VX_TYPE_VXPOCKET:
136 if ((err = snd_ctl_add(_chip->card, snd_ctl_new1(&vx_control_mic_level, chip))) < 0)
137 return err;
138 break;
139 case VX_TYPE_VXP440:
140 if ((err = snd_ctl_add(_chip->card, snd_ctl_new1(&vx_control_mic_boost, chip))) < 0)
141 return err;
142 break;
143 }
144
145 return 0;
146}
147