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