ftp://ftp.kernel.org/pub/linux/kernel/v2.6/linux-2.6.6.tar.bz2
[linux-2.6.git] / sound / pcmcia / vx / vxp_mixer.c
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
23 #include <sound/driver.h>
24 #include <sound/core.h>
25 #include <sound/control.h>
26 #include "vxpocket.h"
27
28 #define chip_t vx_core_t
29
30 #define MIC_LEVEL_MIN   0
31 #define MIC_LEVEL_MAX   8
32
33 /*
34  * mic level control (for VXPocket)
35  */
36 static int vx_mic_level_info(snd_kcontrol_t *kcontrol, snd_ctl_elem_info_t *uinfo)
37 {
38         uinfo->type = SNDRV_CTL_ELEM_TYPE_INTEGER;
39         uinfo->count = 1;
40         uinfo->value.integer.min = 0;
41         uinfo->value.integer.max = MIC_LEVEL_MAX;
42         return 0;
43 }
44
45 static int vx_mic_level_get(snd_kcontrol_t *kcontrol, snd_ctl_elem_value_t *ucontrol)
46 {
47         vx_core_t *_chip = snd_kcontrol_chip(kcontrol);
48         struct snd_vxpocket *chip = (struct snd_vxpocket *)_chip;
49         ucontrol->value.integer.value[0] = chip->mic_level;
50         return 0;
51 }
52
53 static int vx_mic_level_put(snd_kcontrol_t *kcontrol, snd_ctl_elem_value_t *ucontrol)
54 {
55         vx_core_t *_chip = snd_kcontrol_chip(kcontrol);
56         struct snd_vxpocket *chip = (struct snd_vxpocket *)_chip;
57         down(&_chip->mixer_mutex);
58         if (chip->mic_level != ucontrol->value.integer.value[0]) {
59                 vx_set_mic_level(_chip, ucontrol->value.integer.value[0]);
60                 chip->mic_level = ucontrol->value.integer.value[0];
61                 up(&_chip->mixer_mutex);
62                 return 1;
63         }
64         up(&_chip->mixer_mutex);
65         return 0;
66 }
67
68 static snd_kcontrol_new_t vx_control_mic_level = {
69         .iface =        SNDRV_CTL_ELEM_IFACE_MIXER,
70         .name =         "Mic Capture Volume",
71         .info =         vx_mic_level_info,
72         .get =          vx_mic_level_get,
73         .put =          vx_mic_level_put,
74 };
75
76 /*
77  * mic boost level control (for VXP440)
78  */
79 static int vx_mic_boost_info(snd_kcontrol_t *kcontrol, snd_ctl_elem_info_t *uinfo)
80 {
81         uinfo->type = SNDRV_CTL_ELEM_TYPE_BOOLEAN;
82         uinfo->count = 1;
83         uinfo->value.integer.min = 0;
84         uinfo->value.integer.max = 1;
85         return 0;
86 }
87
88 static int vx_mic_boost_get(snd_kcontrol_t *kcontrol, snd_ctl_elem_value_t *ucontrol)
89 {
90         vx_core_t *_chip = snd_kcontrol_chip(kcontrol);
91         struct snd_vxpocket *chip = (struct snd_vxpocket *)_chip;
92         ucontrol->value.integer.value[0] = chip->mic_level;
93         return 0;
94 }
95
96 static int vx_mic_boost_put(snd_kcontrol_t *kcontrol, snd_ctl_elem_value_t *ucontrol)
97 {
98         vx_core_t *_chip = snd_kcontrol_chip(kcontrol);
99         struct snd_vxpocket *chip = (struct snd_vxpocket *)_chip;
100         down(&_chip->mixer_mutex);
101         if (chip->mic_level != ucontrol->value.integer.value[0]) {
102                 vx_set_mic_boost(_chip, ucontrol->value.integer.value[0]);
103                 chip->mic_level = ucontrol->value.integer.value[0];
104                 up(&_chip->mixer_mutex);
105                 return 1;
106         }
107         up(&_chip->mixer_mutex);
108         return 0;
109 }
110
111 static snd_kcontrol_new_t vx_control_mic_boost = {
112         .iface =        SNDRV_CTL_ELEM_IFACE_MIXER,
113         .name =         "Mic Boost",
114         .info =         vx_mic_boost_info,
115         .get =          vx_mic_boost_get,
116         .put =          vx_mic_boost_put,
117 };
118
119
120 int vxp_add_mic_controls(vx_core_t *_chip)
121 {
122         struct snd_vxpocket *chip = (struct snd_vxpocket *)_chip;
123         int err;
124
125         /* mute input levels */
126         chip->mic_level = 0;
127         switch (_chip->type) {
128         case VX_TYPE_VXPOCKET:
129                 vx_set_mic_level(_chip, 0);
130                 break;
131         case VX_TYPE_VXP440:
132                 vx_set_mic_boost(_chip, 0);
133                 break;
134         }
135
136         /* mic level */
137         switch (_chip->type) {
138         case VX_TYPE_VXPOCKET:
139                 if ((err = snd_ctl_add(_chip->card, snd_ctl_new1(&vx_control_mic_level, chip))) < 0)
140                         return err;
141                 break;
142         case VX_TYPE_VXP440:
143                 if ((err = snd_ctl_add(_chip->card, snd_ctl_new1(&vx_control_mic_boost, chip))) < 0)
144                         return err;
145                 break;
146         }
147
148         return 0;
149 }
150