Thomas Gleixner | 1a59d1b8 | 2019-05-27 08:55:05 +0200 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0-or-later |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2 | /* |
| 3 | * Driver for Digigram VXpocket soundcards |
| 4 | * |
| 5 | * VX-pocket mixer |
| 6 | * |
| 7 | * Copyright (c) 2002 by Takashi Iwai <tiwai@suse.de> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 8 | */ |
| 9 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 10 | #include <sound/core.h> |
| 11 | #include <sound/control.h> |
Takashi Iwai | d0ae484 | 2006-08-29 18:15:15 +0200 | [diff] [blame] | 12 | #include <sound/tlv.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 13 | #include "vxpocket.h" |
| 14 | |
| 15 | #define MIC_LEVEL_MIN 0 |
| 16 | #define MIC_LEVEL_MAX 8 |
| 17 | |
| 18 | /* |
| 19 | * mic level control (for VXPocket) |
| 20 | */ |
Takashi Iwai | af26367 | 2005-11-17 14:46:59 +0100 | [diff] [blame] | 21 | 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] | 22 | { |
| 23 | uinfo->type = SNDRV_CTL_ELEM_TYPE_INTEGER; |
| 24 | uinfo->count = 1; |
| 25 | uinfo->value.integer.min = 0; |
| 26 | uinfo->value.integer.max = MIC_LEVEL_MAX; |
| 27 | return 0; |
| 28 | } |
| 29 | |
Takashi Iwai | af26367 | 2005-11-17 14:46:59 +0100 | [diff] [blame] | 30 | 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] | 31 | { |
Takashi Iwai | af26367 | 2005-11-17 14:46:59 +0100 | [diff] [blame] | 32 | struct vx_core *_chip = snd_kcontrol_chip(kcontrol); |
Takashi Iwai | 2e0de6e | 2017-05-12 10:03:35 +0200 | [diff] [blame] | 33 | struct snd_vxpocket *chip = to_vxpocket(_chip); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 34 | ucontrol->value.integer.value[0] = chip->mic_level; |
| 35 | return 0; |
| 36 | } |
| 37 | |
Takashi Iwai | af26367 | 2005-11-17 14:46:59 +0100 | [diff] [blame] | 38 | 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] | 39 | { |
Takashi Iwai | af26367 | 2005-11-17 14:46:59 +0100 | [diff] [blame] | 40 | struct vx_core *_chip = snd_kcontrol_chip(kcontrol); |
Takashi Iwai | 2e0de6e | 2017-05-12 10:03:35 +0200 | [diff] [blame] | 41 | struct snd_vxpocket *chip = to_vxpocket(_chip); |
Takashi Iwai | d05ab18 | 2007-11-15 16:13:32 +0100 | [diff] [blame] | 42 | unsigned int val = ucontrol->value.integer.value[0]; |
| 43 | |
| 44 | if (val > MIC_LEVEL_MAX) |
| 45 | return -EINVAL; |
Ingo Molnar | 12aa757 | 2006-01-16 16:36:05 +0100 | [diff] [blame] | 46 | mutex_lock(&_chip->mixer_mutex); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 47 | if (chip->mic_level != ucontrol->value.integer.value[0]) { |
| 48 | vx_set_mic_level(_chip, ucontrol->value.integer.value[0]); |
| 49 | chip->mic_level = ucontrol->value.integer.value[0]; |
Ingo Molnar | 12aa757 | 2006-01-16 16:36:05 +0100 | [diff] [blame] | 50 | mutex_unlock(&_chip->mixer_mutex); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 51 | return 1; |
| 52 | } |
Ingo Molnar | 12aa757 | 2006-01-16 16:36:05 +0100 | [diff] [blame] | 53 | mutex_unlock(&_chip->mixer_mutex); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 54 | return 0; |
| 55 | } |
| 56 | |
Takashi Iwai | 0cb29ea | 2007-01-29 15:33:49 +0100 | [diff] [blame] | 57 | static const DECLARE_TLV_DB_SCALE(db_scale_mic, -21, 3, 0); |
Takashi Iwai | d0ae484 | 2006-08-29 18:15:15 +0200 | [diff] [blame] | 58 | |
Bhumika Goyal | 905e46a | 2017-05-27 20:16:15 +0530 | [diff] [blame] | 59 | static const struct snd_kcontrol_new vx_control_mic_level = { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 60 | .iface = SNDRV_CTL_ELEM_IFACE_MIXER, |
Takashi Iwai | d0ae484 | 2006-08-29 18:15:15 +0200 | [diff] [blame] | 61 | .access = (SNDRV_CTL_ELEM_ACCESS_READWRITE | |
| 62 | SNDRV_CTL_ELEM_ACCESS_TLV_READ), |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 63 | .name = "Mic Capture Volume", |
| 64 | .info = vx_mic_level_info, |
| 65 | .get = vx_mic_level_get, |
| 66 | .put = vx_mic_level_put, |
Takashi Iwai | d0ae484 | 2006-08-29 18:15:15 +0200 | [diff] [blame] | 67 | .tlv = { .p = db_scale_mic }, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 68 | }; |
| 69 | |
| 70 | /* |
| 71 | * mic boost level control (for VXP440) |
| 72 | */ |
Takashi Iwai | a5ce889 | 2007-07-23 15:42:26 +0200 | [diff] [blame] | 73 | #define vx_mic_boost_info snd_ctl_boolean_mono_info |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 74 | |
Takashi Iwai | af26367 | 2005-11-17 14:46:59 +0100 | [diff] [blame] | 75 | 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] | 76 | { |
Takashi Iwai | af26367 | 2005-11-17 14:46:59 +0100 | [diff] [blame] | 77 | struct vx_core *_chip = snd_kcontrol_chip(kcontrol); |
Takashi Iwai | 2e0de6e | 2017-05-12 10:03:35 +0200 | [diff] [blame] | 78 | struct snd_vxpocket *chip = to_vxpocket(_chip); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 79 | ucontrol->value.integer.value[0] = chip->mic_level; |
| 80 | return 0; |
| 81 | } |
| 82 | |
Takashi Iwai | af26367 | 2005-11-17 14:46:59 +0100 | [diff] [blame] | 83 | 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] | 84 | { |
Takashi Iwai | af26367 | 2005-11-17 14:46:59 +0100 | [diff] [blame] | 85 | struct vx_core *_chip = snd_kcontrol_chip(kcontrol); |
Takashi Iwai | 2e0de6e | 2017-05-12 10:03:35 +0200 | [diff] [blame] | 86 | struct snd_vxpocket *chip = to_vxpocket(_chip); |
Takashi Iwai | d05ab18 | 2007-11-15 16:13:32 +0100 | [diff] [blame] | 87 | int val = !!ucontrol->value.integer.value[0]; |
Ingo Molnar | 12aa757 | 2006-01-16 16:36:05 +0100 | [diff] [blame] | 88 | mutex_lock(&_chip->mixer_mutex); |
Takashi Iwai | d05ab18 | 2007-11-15 16:13:32 +0100 | [diff] [blame] | 89 | if (chip->mic_level != val) { |
| 90 | vx_set_mic_boost(_chip, val); |
| 91 | chip->mic_level = val; |
Ingo Molnar | 12aa757 | 2006-01-16 16:36:05 +0100 | [diff] [blame] | 92 | mutex_unlock(&_chip->mixer_mutex); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 93 | return 1; |
| 94 | } |
Ingo Molnar | 12aa757 | 2006-01-16 16:36:05 +0100 | [diff] [blame] | 95 | mutex_unlock(&_chip->mixer_mutex); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 96 | return 0; |
| 97 | } |
| 98 | |
Bhumika Goyal | 905e46a | 2017-05-27 20:16:15 +0530 | [diff] [blame] | 99 | static const struct snd_kcontrol_new vx_control_mic_boost = { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 100 | .iface = SNDRV_CTL_ELEM_IFACE_MIXER, |
| 101 | .name = "Mic Boost", |
| 102 | .info = vx_mic_boost_info, |
| 103 | .get = vx_mic_boost_get, |
| 104 | .put = vx_mic_boost_put, |
| 105 | }; |
| 106 | |
| 107 | |
Takashi Iwai | af26367 | 2005-11-17 14:46:59 +0100 | [diff] [blame] | 108 | int vxp_add_mic_controls(struct vx_core *_chip) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 109 | { |
Takashi Iwai | 2e0de6e | 2017-05-12 10:03:35 +0200 | [diff] [blame] | 110 | struct snd_vxpocket *chip = to_vxpocket(_chip); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 111 | int err; |
| 112 | |
| 113 | /* mute input levels */ |
| 114 | chip->mic_level = 0; |
| 115 | switch (_chip->type) { |
| 116 | case VX_TYPE_VXPOCKET: |
| 117 | vx_set_mic_level(_chip, 0); |
| 118 | break; |
| 119 | case VX_TYPE_VXP440: |
| 120 | vx_set_mic_boost(_chip, 0); |
| 121 | break; |
| 122 | } |
| 123 | |
| 124 | /* mic level */ |
| 125 | switch (_chip->type) { |
| 126 | case VX_TYPE_VXPOCKET: |
Takashi Iwai | 2073fa4 | 2021-06-08 16:05:31 +0200 | [diff] [blame] | 127 | err = snd_ctl_add(_chip->card, snd_ctl_new1(&vx_control_mic_level, chip)); |
| 128 | if (err < 0) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 129 | return err; |
| 130 | break; |
| 131 | case VX_TYPE_VXP440: |
Takashi Iwai | 2073fa4 | 2021-06-08 16:05:31 +0200 | [diff] [blame] | 132 | err = snd_ctl_add(_chip->card, snd_ctl_new1(&vx_control_mic_boost, chip)); |
| 133 | if (err < 0) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 134 | return err; |
| 135 | break; |
| 136 | } |
| 137 | |
| 138 | return 0; |
| 139 | } |
| 140 | |