Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 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 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 23 | #include <sound/core.h> |
| 24 | #include <sound/control.h> |
Takashi Iwai | d0ae484 | 2006-08-29 18:15:15 +0200 | [diff] [blame] | 25 | #include <sound/tlv.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 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 Iwai | af26367 | 2005-11-17 14:46:59 +0100 | [diff] [blame] | 34 | static int vx_mic_level_info(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_info *uinfo) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 35 | { |
| 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 Iwai | af26367 | 2005-11-17 14:46:59 +0100 | [diff] [blame] | 43 | static int vx_mic_level_get(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 44 | { |
Takashi Iwai | af26367 | 2005-11-17 14:46:59 +0100 | [diff] [blame] | 45 | struct vx_core *_chip = snd_kcontrol_chip(kcontrol); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 46 | struct snd_vxpocket *chip = (struct snd_vxpocket *)_chip; |
| 47 | ucontrol->value.integer.value[0] = chip->mic_level; |
| 48 | return 0; |
| 49 | } |
| 50 | |
Takashi Iwai | af26367 | 2005-11-17 14:46:59 +0100 | [diff] [blame] | 51 | static int vx_mic_level_put(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 52 | { |
Takashi Iwai | af26367 | 2005-11-17 14:46:59 +0100 | [diff] [blame] | 53 | struct vx_core *_chip = snd_kcontrol_chip(kcontrol); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 54 | struct snd_vxpocket *chip = (struct snd_vxpocket *)_chip; |
Takashi Iwai | d05ab18 | 2007-11-15 16:13:32 +0100 | [diff] [blame] | 55 | unsigned int val = ucontrol->value.integer.value[0]; |
| 56 | |
| 57 | if (val > MIC_LEVEL_MAX) |
| 58 | return -EINVAL; |
Ingo Molnar | 12aa757 | 2006-01-16 16:36:05 +0100 | [diff] [blame] | 59 | mutex_lock(&_chip->mixer_mutex); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 60 | if (chip->mic_level != ucontrol->value.integer.value[0]) { |
| 61 | vx_set_mic_level(_chip, ucontrol->value.integer.value[0]); |
| 62 | chip->mic_level = ucontrol->value.integer.value[0]; |
Ingo Molnar | 12aa757 | 2006-01-16 16:36:05 +0100 | [diff] [blame] | 63 | mutex_unlock(&_chip->mixer_mutex); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 64 | return 1; |
| 65 | } |
Ingo Molnar | 12aa757 | 2006-01-16 16:36:05 +0100 | [diff] [blame] | 66 | mutex_unlock(&_chip->mixer_mutex); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 67 | return 0; |
| 68 | } |
| 69 | |
Takashi Iwai | 0cb29ea | 2007-01-29 15:33:49 +0100 | [diff] [blame] | 70 | static const DECLARE_TLV_DB_SCALE(db_scale_mic, -21, 3, 0); |
Takashi Iwai | d0ae484 | 2006-08-29 18:15:15 +0200 | [diff] [blame] | 71 | |
Takashi Iwai | af26367 | 2005-11-17 14:46:59 +0100 | [diff] [blame] | 72 | static struct snd_kcontrol_new vx_control_mic_level = { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 73 | .iface = SNDRV_CTL_ELEM_IFACE_MIXER, |
Takashi Iwai | d0ae484 | 2006-08-29 18:15:15 +0200 | [diff] [blame] | 74 | .access = (SNDRV_CTL_ELEM_ACCESS_READWRITE | |
| 75 | SNDRV_CTL_ELEM_ACCESS_TLV_READ), |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 76 | .name = "Mic Capture Volume", |
| 77 | .info = vx_mic_level_info, |
| 78 | .get = vx_mic_level_get, |
| 79 | .put = vx_mic_level_put, |
Takashi Iwai | d0ae484 | 2006-08-29 18:15:15 +0200 | [diff] [blame] | 80 | .tlv = { .p = db_scale_mic }, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 81 | }; |
| 82 | |
| 83 | /* |
| 84 | * mic boost level control (for VXP440) |
| 85 | */ |
Takashi Iwai | a5ce889 | 2007-07-23 15:42:26 +0200 | [diff] [blame] | 86 | #define vx_mic_boost_info snd_ctl_boolean_mono_info |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 87 | |
Takashi Iwai | af26367 | 2005-11-17 14:46:59 +0100 | [diff] [blame] | 88 | static int vx_mic_boost_get(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 89 | { |
Takashi Iwai | af26367 | 2005-11-17 14:46:59 +0100 | [diff] [blame] | 90 | struct vx_core *_chip = snd_kcontrol_chip(kcontrol); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 91 | struct snd_vxpocket *chip = (struct snd_vxpocket *)_chip; |
| 92 | ucontrol->value.integer.value[0] = chip->mic_level; |
| 93 | return 0; |
| 94 | } |
| 95 | |
Takashi Iwai | af26367 | 2005-11-17 14:46:59 +0100 | [diff] [blame] | 96 | static int vx_mic_boost_put(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 97 | { |
Takashi Iwai | af26367 | 2005-11-17 14:46:59 +0100 | [diff] [blame] | 98 | struct vx_core *_chip = snd_kcontrol_chip(kcontrol); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 99 | struct snd_vxpocket *chip = (struct snd_vxpocket *)_chip; |
Takashi Iwai | d05ab18 | 2007-11-15 16:13:32 +0100 | [diff] [blame] | 100 | int val = !!ucontrol->value.integer.value[0]; |
Ingo Molnar | 12aa757 | 2006-01-16 16:36:05 +0100 | [diff] [blame] | 101 | mutex_lock(&_chip->mixer_mutex); |
Takashi Iwai | d05ab18 | 2007-11-15 16:13:32 +0100 | [diff] [blame] | 102 | if (chip->mic_level != val) { |
| 103 | vx_set_mic_boost(_chip, val); |
| 104 | chip->mic_level = val; |
Ingo Molnar | 12aa757 | 2006-01-16 16:36:05 +0100 | [diff] [blame] | 105 | mutex_unlock(&_chip->mixer_mutex); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 106 | return 1; |
| 107 | } |
Ingo Molnar | 12aa757 | 2006-01-16 16:36:05 +0100 | [diff] [blame] | 108 | mutex_unlock(&_chip->mixer_mutex); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 109 | return 0; |
| 110 | } |
| 111 | |
Takashi Iwai | af26367 | 2005-11-17 14:46:59 +0100 | [diff] [blame] | 112 | static struct snd_kcontrol_new vx_control_mic_boost = { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 113 | .iface = SNDRV_CTL_ELEM_IFACE_MIXER, |
| 114 | .name = "Mic Boost", |
| 115 | .info = vx_mic_boost_info, |
| 116 | .get = vx_mic_boost_get, |
| 117 | .put = vx_mic_boost_put, |
| 118 | }; |
| 119 | |
| 120 | |
Takashi Iwai | af26367 | 2005-11-17 14:46:59 +0100 | [diff] [blame] | 121 | int vxp_add_mic_controls(struct vx_core *_chip) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 122 | { |
| 123 | struct snd_vxpocket *chip = (struct snd_vxpocket *)_chip; |
| 124 | int err; |
| 125 | |
| 126 | /* mute input levels */ |
| 127 | chip->mic_level = 0; |
| 128 | switch (_chip->type) { |
| 129 | case VX_TYPE_VXPOCKET: |
| 130 | vx_set_mic_level(_chip, 0); |
| 131 | break; |
| 132 | case VX_TYPE_VXP440: |
| 133 | vx_set_mic_boost(_chip, 0); |
| 134 | break; |
| 135 | } |
| 136 | |
| 137 | /* mic level */ |
| 138 | switch (_chip->type) { |
| 139 | case VX_TYPE_VXPOCKET: |
| 140 | if ((err = snd_ctl_add(_chip->card, snd_ctl_new1(&vx_control_mic_level, chip))) < 0) |
| 141 | return err; |
| 142 | break; |
| 143 | case VX_TYPE_VXP440: |
| 144 | if ((err = snd_ctl_add(_chip->card, snd_ctl_new1(&vx_control_mic_boost, chip))) < 0) |
| 145 | return err; |
| 146 | break; |
| 147 | } |
| 148 | |
| 149 | return 0; |
| 150 | } |
| 151 | |