Markus Bollinger | e12229b | 2005-12-06 13:55:26 +0100 | [diff] [blame] | 1 | #define __NO_VERSION__ |
| 2 | /* |
| 3 | * Driver for Digigram pcxhr compatible soundcards |
| 4 | * |
| 5 | * mixer callbacks |
| 6 | * |
| 7 | * Copyright (c) 2004 by Digigram <alsa@digigram.com> |
| 8 | * |
| 9 | * This program is free software; you can redistribute it and/or modify |
| 10 | * it under the terms of the GNU General Public License as published by |
| 11 | * the Free Software Foundation; either version 2 of the License, or |
| 12 | * (at your option) any later version. |
| 13 | * |
| 14 | * This program is distributed in the hope that it will be useful, |
| 15 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 16 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 17 | * GNU General Public License for more details. |
| 18 | * |
| 19 | * You should have received a copy of the GNU General Public License |
| 20 | * along with this program; if not, write to the Free Software |
| 21 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
| 22 | */ |
| 23 | |
Markus Bollinger | e12229b | 2005-12-06 13:55:26 +0100 | [diff] [blame] | 24 | #include <linux/time.h> |
| 25 | #include <linux/interrupt.h> |
| 26 | #include <linux/init.h> |
Ingo Molnar | 62932df | 2006-01-16 16:34:20 +0100 | [diff] [blame] | 27 | #include <linux/mutex.h> |
Markus Bollinger | e12229b | 2005-12-06 13:55:26 +0100 | [diff] [blame] | 28 | #include <sound/core.h> |
| 29 | #include "pcxhr.h" |
| 30 | #include "pcxhr_hwdep.h" |
| 31 | #include "pcxhr_core.h" |
| 32 | #include <sound/control.h> |
Takashi Iwai | c6ff77f | 2006-08-23 19:53:02 +0200 | [diff] [blame] | 33 | #include <sound/tlv.h> |
Markus Bollinger | e12229b | 2005-12-06 13:55:26 +0100 | [diff] [blame] | 34 | #include <sound/asoundef.h> |
| 35 | #include "pcxhr_mixer.h" |
Markus Bollinger | c0193f3 | 2008-11-25 12:37:52 +0100 | [diff] [blame] | 36 | #include "pcxhr_mix22.h" |
Markus Bollinger | e12229b | 2005-12-06 13:55:26 +0100 | [diff] [blame] | 37 | |
Markus Bollinger | c0193f3 | 2008-11-25 12:37:52 +0100 | [diff] [blame] | 38 | #define PCXHR_LINE_CAPTURE_LEVEL_MIN 0 /* -112.0 dB */ |
| 39 | #define PCXHR_LINE_CAPTURE_LEVEL_MAX 255 /* +15.5 dB */ |
| 40 | #define PCXHR_LINE_CAPTURE_ZERO_LEVEL 224 /* 0.0 dB ( 0 dBu -> 0 dBFS ) */ |
Markus Bollinger | e12229b | 2005-12-06 13:55:26 +0100 | [diff] [blame] | 41 | |
Markus Bollinger | c0193f3 | 2008-11-25 12:37:52 +0100 | [diff] [blame] | 42 | #define PCXHR_LINE_PLAYBACK_LEVEL_MIN 0 /* -104.0 dB */ |
| 43 | #define PCXHR_LINE_PLAYBACK_LEVEL_MAX 128 /* +24.0 dB */ |
| 44 | #define PCXHR_LINE_PLAYBACK_ZERO_LEVEL 104 /* 0.0 dB ( 0 dBFS -> 0 dBu ) */ |
Markus Bollinger | e12229b | 2005-12-06 13:55:26 +0100 | [diff] [blame] | 45 | |
Markus Bollinger | c0193f3 | 2008-11-25 12:37:52 +0100 | [diff] [blame] | 46 | static const DECLARE_TLV_DB_SCALE(db_scale_analog_capture, -11200, 50, 1550); |
Takashi Iwai | e6382cf | 2007-10-10 10:06:46 +0200 | [diff] [blame] | 47 | static const DECLARE_TLV_DB_SCALE(db_scale_analog_playback, -10400, 100, 2400); |
Takashi Iwai | c6ff77f | 2006-08-23 19:53:02 +0200 | [diff] [blame] | 48 | |
Markus Bollinger | c0193f3 | 2008-11-25 12:37:52 +0100 | [diff] [blame] | 49 | static const DECLARE_TLV_DB_SCALE(db_scale_a_hr222_capture, -11150, 50, 1600); |
| 50 | static const DECLARE_TLV_DB_SCALE(db_scale_a_hr222_playback, -2550, 50, 2400); |
| 51 | |
| 52 | static int pcxhr_update_analog_audio_level(struct snd_pcxhr *chip, |
| 53 | int is_capture, int channel) |
Markus Bollinger | e12229b | 2005-12-06 13:55:26 +0100 | [diff] [blame] | 54 | { |
| 55 | int err, vol; |
| 56 | struct pcxhr_rmh rmh; |
| 57 | |
| 58 | pcxhr_init_rmh(&rmh, CMD_ACCESS_IO_WRITE); |
| 59 | if (is_capture) { |
| 60 | rmh.cmd[0] |= IO_NUM_REG_IN_ANA_LEVEL; |
| 61 | rmh.cmd[2] = chip->analog_capture_volume[channel]; |
| 62 | } else { |
| 63 | rmh.cmd[0] |= IO_NUM_REG_OUT_ANA_LEVEL; |
| 64 | if (chip->analog_playback_active[channel]) |
| 65 | vol = chip->analog_playback_volume[channel]; |
| 66 | else |
Markus Bollinger | c0193f3 | 2008-11-25 12:37:52 +0100 | [diff] [blame] | 67 | vol = PCXHR_LINE_PLAYBACK_LEVEL_MIN; |
| 68 | /* playback analog levels are inversed */ |
| 69 | rmh.cmd[2] = PCXHR_LINE_PLAYBACK_LEVEL_MAX - vol; |
Markus Bollinger | e12229b | 2005-12-06 13:55:26 +0100 | [diff] [blame] | 70 | } |
| 71 | rmh.cmd[1] = 1 << ((2 * chip->chip_idx) + channel); /* audio mask */ |
| 72 | rmh.cmd_len = 3; |
| 73 | err = pcxhr_send_msg(chip->mgr, &rmh); |
| 74 | if (err < 0) { |
Takashi Iwai | b59bb8e | 2014-02-26 11:47:55 +0100 | [diff] [blame^] | 75 | dev_dbg(chip->card->dev, |
| 76 | "error update_analog_audio_level card(%d)" |
Markus Bollinger | c0193f3 | 2008-11-25 12:37:52 +0100 | [diff] [blame] | 77 | " is_capture(%d) err(%x)\n", |
| 78 | chip->chip_idx, is_capture, err); |
Markus Bollinger | e12229b | 2005-12-06 13:55:26 +0100 | [diff] [blame] | 79 | return -EINVAL; |
| 80 | } |
| 81 | return 0; |
| 82 | } |
| 83 | |
| 84 | /* |
| 85 | * analog level control |
| 86 | */ |
| 87 | static int pcxhr_analog_vol_info(struct snd_kcontrol *kcontrol, |
| 88 | struct snd_ctl_elem_info *uinfo) |
| 89 | { |
Markus Bollinger | c0193f3 | 2008-11-25 12:37:52 +0100 | [diff] [blame] | 90 | struct snd_pcxhr *chip = snd_kcontrol_chip(kcontrol); |
| 91 | |
Markus Bollinger | e12229b | 2005-12-06 13:55:26 +0100 | [diff] [blame] | 92 | uinfo->type = SNDRV_CTL_ELEM_TYPE_INTEGER; |
| 93 | uinfo->count = 2; |
| 94 | if (kcontrol->private_value == 0) { /* playback */ |
Markus Bollinger | c0193f3 | 2008-11-25 12:37:52 +0100 | [diff] [blame] | 95 | if (chip->mgr->is_hr_stereo) { |
| 96 | uinfo->value.integer.min = |
| 97 | HR222_LINE_PLAYBACK_LEVEL_MIN; /* -25 dB */ |
| 98 | uinfo->value.integer.max = |
| 99 | HR222_LINE_PLAYBACK_LEVEL_MAX; /* +24 dB */ |
| 100 | } else { |
| 101 | uinfo->value.integer.min = |
| 102 | PCXHR_LINE_PLAYBACK_LEVEL_MIN; /*-104 dB */ |
| 103 | uinfo->value.integer.max = |
| 104 | PCXHR_LINE_PLAYBACK_LEVEL_MAX; /* +24 dB */ |
| 105 | } |
Markus Bollinger | e12229b | 2005-12-06 13:55:26 +0100 | [diff] [blame] | 106 | } else { /* capture */ |
Markus Bollinger | c0193f3 | 2008-11-25 12:37:52 +0100 | [diff] [blame] | 107 | if (chip->mgr->is_hr_stereo) { |
| 108 | uinfo->value.integer.min = |
| 109 | HR222_LINE_CAPTURE_LEVEL_MIN; /*-112 dB */ |
| 110 | uinfo->value.integer.max = |
| 111 | HR222_LINE_CAPTURE_LEVEL_MAX; /* +15.5 dB */ |
| 112 | } else { |
| 113 | uinfo->value.integer.min = |
| 114 | PCXHR_LINE_CAPTURE_LEVEL_MIN; /*-112 dB */ |
| 115 | uinfo->value.integer.max = |
| 116 | PCXHR_LINE_CAPTURE_LEVEL_MAX; /* +15.5 dB */ |
| 117 | } |
Markus Bollinger | e12229b | 2005-12-06 13:55:26 +0100 | [diff] [blame] | 118 | } |
| 119 | return 0; |
| 120 | } |
| 121 | |
| 122 | static int pcxhr_analog_vol_get(struct snd_kcontrol *kcontrol, |
| 123 | struct snd_ctl_elem_value *ucontrol) |
| 124 | { |
| 125 | struct snd_pcxhr *chip = snd_kcontrol_chip(kcontrol); |
Ingo Molnar | 62932df | 2006-01-16 16:34:20 +0100 | [diff] [blame] | 126 | mutex_lock(&chip->mgr->mixer_mutex); |
Markus Bollinger | e12229b | 2005-12-06 13:55:26 +0100 | [diff] [blame] | 127 | if (kcontrol->private_value == 0) { /* playback */ |
Markus Bollinger | c0193f3 | 2008-11-25 12:37:52 +0100 | [diff] [blame] | 128 | ucontrol->value.integer.value[0] = chip->analog_playback_volume[0]; |
| 129 | ucontrol->value.integer.value[1] = chip->analog_playback_volume[1]; |
Markus Bollinger | e12229b | 2005-12-06 13:55:26 +0100 | [diff] [blame] | 130 | } else { /* capture */ |
Markus Bollinger | c0193f3 | 2008-11-25 12:37:52 +0100 | [diff] [blame] | 131 | ucontrol->value.integer.value[0] = chip->analog_capture_volume[0]; |
| 132 | ucontrol->value.integer.value[1] = chip->analog_capture_volume[1]; |
Markus Bollinger | e12229b | 2005-12-06 13:55:26 +0100 | [diff] [blame] | 133 | } |
Ingo Molnar | 62932df | 2006-01-16 16:34:20 +0100 | [diff] [blame] | 134 | mutex_unlock(&chip->mgr->mixer_mutex); |
Markus Bollinger | e12229b | 2005-12-06 13:55:26 +0100 | [diff] [blame] | 135 | return 0; |
| 136 | } |
| 137 | |
| 138 | static int pcxhr_analog_vol_put(struct snd_kcontrol *kcontrol, |
| 139 | struct snd_ctl_elem_value *ucontrol) |
| 140 | { |
| 141 | struct snd_pcxhr *chip = snd_kcontrol_chip(kcontrol); |
| 142 | int changed = 0; |
| 143 | int is_capture, i; |
| 144 | |
Ingo Molnar | 62932df | 2006-01-16 16:34:20 +0100 | [diff] [blame] | 145 | mutex_lock(&chip->mgr->mixer_mutex); |
Markus Bollinger | e12229b | 2005-12-06 13:55:26 +0100 | [diff] [blame] | 146 | is_capture = (kcontrol->private_value != 0); |
| 147 | for (i = 0; i < 2; i++) { |
| 148 | int new_volume = ucontrol->value.integer.value[i]; |
Takashi Iwai | 4e98d6a | 2007-11-15 15:58:13 +0100 | [diff] [blame] | 149 | int *stored_volume = is_capture ? |
| 150 | &chip->analog_capture_volume[i] : |
Markus Bollinger | e12229b | 2005-12-06 13:55:26 +0100 | [diff] [blame] | 151 | &chip->analog_playback_volume[i]; |
Takashi Iwai | 4e98d6a | 2007-11-15 15:58:13 +0100 | [diff] [blame] | 152 | if (is_capture) { |
Markus Bollinger | c0193f3 | 2008-11-25 12:37:52 +0100 | [diff] [blame] | 153 | if (chip->mgr->is_hr_stereo) { |
| 154 | if (new_volume < HR222_LINE_CAPTURE_LEVEL_MIN || |
| 155 | new_volume > HR222_LINE_CAPTURE_LEVEL_MAX) |
| 156 | continue; |
| 157 | } else { |
| 158 | if (new_volume < PCXHR_LINE_CAPTURE_LEVEL_MIN || |
| 159 | new_volume > PCXHR_LINE_CAPTURE_LEVEL_MAX) |
| 160 | continue; |
| 161 | } |
Takashi Iwai | 4e98d6a | 2007-11-15 15:58:13 +0100 | [diff] [blame] | 162 | } else { |
Markus Bollinger | c0193f3 | 2008-11-25 12:37:52 +0100 | [diff] [blame] | 163 | if (chip->mgr->is_hr_stereo) { |
| 164 | if (new_volume < HR222_LINE_PLAYBACK_LEVEL_MIN || |
| 165 | new_volume > HR222_LINE_PLAYBACK_LEVEL_MAX) |
| 166 | continue; |
| 167 | } else { |
| 168 | if (new_volume < PCXHR_LINE_PLAYBACK_LEVEL_MIN || |
| 169 | new_volume > PCXHR_LINE_PLAYBACK_LEVEL_MAX) |
| 170 | continue; |
| 171 | } |
Takashi Iwai | 4e98d6a | 2007-11-15 15:58:13 +0100 | [diff] [blame] | 172 | } |
Markus Bollinger | e12229b | 2005-12-06 13:55:26 +0100 | [diff] [blame] | 173 | if (*stored_volume != new_volume) { |
| 174 | *stored_volume = new_volume; |
| 175 | changed = 1; |
Markus Bollinger | c0193f3 | 2008-11-25 12:37:52 +0100 | [diff] [blame] | 176 | if (chip->mgr->is_hr_stereo) |
| 177 | hr222_update_analog_audio_level(chip, |
| 178 | is_capture, i); |
| 179 | else |
| 180 | pcxhr_update_analog_audio_level(chip, |
| 181 | is_capture, i); |
Markus Bollinger | e12229b | 2005-12-06 13:55:26 +0100 | [diff] [blame] | 182 | } |
| 183 | } |
Ingo Molnar | 62932df | 2006-01-16 16:34:20 +0100 | [diff] [blame] | 184 | mutex_unlock(&chip->mgr->mixer_mutex); |
Markus Bollinger | e12229b | 2005-12-06 13:55:26 +0100 | [diff] [blame] | 185 | return changed; |
| 186 | } |
| 187 | |
| 188 | static struct snd_kcontrol_new pcxhr_control_analog_level = { |
| 189 | .iface = SNDRV_CTL_ELEM_IFACE_MIXER, |
Takashi Iwai | c6ff77f | 2006-08-23 19:53:02 +0200 | [diff] [blame] | 190 | .access = (SNDRV_CTL_ELEM_ACCESS_READWRITE | |
| 191 | SNDRV_CTL_ELEM_ACCESS_TLV_READ), |
Markus Bollinger | e12229b | 2005-12-06 13:55:26 +0100 | [diff] [blame] | 192 | /* name will be filled later */ |
| 193 | .info = pcxhr_analog_vol_info, |
| 194 | .get = pcxhr_analog_vol_get, |
| 195 | .put = pcxhr_analog_vol_put, |
Takashi Iwai | c6ff77f | 2006-08-23 19:53:02 +0200 | [diff] [blame] | 196 | /* tlv will be filled later */ |
Markus Bollinger | e12229b | 2005-12-06 13:55:26 +0100 | [diff] [blame] | 197 | }; |
| 198 | |
| 199 | /* shared */ |
Markus Bollinger | c0193f3 | 2008-11-25 12:37:52 +0100 | [diff] [blame] | 200 | |
Takashi Iwai | a5ce889 | 2007-07-23 15:42:26 +0200 | [diff] [blame] | 201 | #define pcxhr_sw_info snd_ctl_boolean_stereo_info |
Markus Bollinger | e12229b | 2005-12-06 13:55:26 +0100 | [diff] [blame] | 202 | |
| 203 | static int pcxhr_audio_sw_get(struct snd_kcontrol *kcontrol, |
| 204 | struct snd_ctl_elem_value *ucontrol) |
| 205 | { |
| 206 | struct snd_pcxhr *chip = snd_kcontrol_chip(kcontrol); |
| 207 | |
Ingo Molnar | 62932df | 2006-01-16 16:34:20 +0100 | [diff] [blame] | 208 | mutex_lock(&chip->mgr->mixer_mutex); |
Markus Bollinger | e12229b | 2005-12-06 13:55:26 +0100 | [diff] [blame] | 209 | ucontrol->value.integer.value[0] = chip->analog_playback_active[0]; |
| 210 | ucontrol->value.integer.value[1] = chip->analog_playback_active[1]; |
Ingo Molnar | 62932df | 2006-01-16 16:34:20 +0100 | [diff] [blame] | 211 | mutex_unlock(&chip->mgr->mixer_mutex); |
Markus Bollinger | e12229b | 2005-12-06 13:55:26 +0100 | [diff] [blame] | 212 | return 0; |
| 213 | } |
| 214 | |
| 215 | static int pcxhr_audio_sw_put(struct snd_kcontrol *kcontrol, |
| 216 | struct snd_ctl_elem_value *ucontrol) |
| 217 | { |
| 218 | struct snd_pcxhr *chip = snd_kcontrol_chip(kcontrol); |
| 219 | int i, changed = 0; |
Ingo Molnar | 62932df | 2006-01-16 16:34:20 +0100 | [diff] [blame] | 220 | mutex_lock(&chip->mgr->mixer_mutex); |
Markus Bollinger | e12229b | 2005-12-06 13:55:26 +0100 | [diff] [blame] | 221 | for(i = 0; i < 2; i++) { |
Takashi Iwai | 4e98d6a | 2007-11-15 15:58:13 +0100 | [diff] [blame] | 222 | if (chip->analog_playback_active[i] != |
| 223 | ucontrol->value.integer.value[i]) { |
| 224 | chip->analog_playback_active[i] = |
| 225 | !!ucontrol->value.integer.value[i]; |
Markus Bollinger | e12229b | 2005-12-06 13:55:26 +0100 | [diff] [blame] | 226 | changed = 1; |
Takashi Iwai | 4e98d6a | 2007-11-15 15:58:13 +0100 | [diff] [blame] | 227 | /* update playback levels */ |
Markus Bollinger | c0193f3 | 2008-11-25 12:37:52 +0100 | [diff] [blame] | 228 | if (chip->mgr->is_hr_stereo) |
| 229 | hr222_update_analog_audio_level(chip, 0, i); |
| 230 | else |
| 231 | pcxhr_update_analog_audio_level(chip, 0, i); |
Markus Bollinger | e12229b | 2005-12-06 13:55:26 +0100 | [diff] [blame] | 232 | } |
| 233 | } |
Ingo Molnar | 62932df | 2006-01-16 16:34:20 +0100 | [diff] [blame] | 234 | mutex_unlock(&chip->mgr->mixer_mutex); |
Markus Bollinger | e12229b | 2005-12-06 13:55:26 +0100 | [diff] [blame] | 235 | return changed; |
| 236 | } |
| 237 | |
| 238 | static struct snd_kcontrol_new pcxhr_control_output_switch = { |
| 239 | .iface = SNDRV_CTL_ELEM_IFACE_MIXER, |
| 240 | .name = "Master Playback Switch", |
| 241 | .info = pcxhr_sw_info, /* shared */ |
| 242 | .get = pcxhr_audio_sw_get, |
| 243 | .put = pcxhr_audio_sw_put |
| 244 | }; |
| 245 | |
| 246 | |
| 247 | #define PCXHR_DIGITAL_LEVEL_MIN 0x000 /* -110 dB */ |
| 248 | #define PCXHR_DIGITAL_LEVEL_MAX 0x1ff /* +18 dB */ |
| 249 | #define PCXHR_DIGITAL_ZERO_LEVEL 0x1b7 /* 0 dB */ |
| 250 | |
Takashi Iwai | e6382cf | 2007-10-10 10:06:46 +0200 | [diff] [blame] | 251 | static const DECLARE_TLV_DB_SCALE(db_scale_digital, -10975, 25, 1800); |
Markus Bollinger | e12229b | 2005-12-06 13:55:26 +0100 | [diff] [blame] | 252 | |
| 253 | #define MORE_THAN_ONE_STREAM_LEVEL 0x000001 |
| 254 | #define VALID_STREAM_PAN_LEVEL_MASK 0x800000 |
| 255 | #define VALID_STREAM_LEVEL_MASK 0x400000 |
| 256 | #define VALID_STREAM_LEVEL_1_MASK 0x200000 |
| 257 | #define VALID_STREAM_LEVEL_2_MASK 0x100000 |
| 258 | |
| 259 | static int pcxhr_update_playback_stream_level(struct snd_pcxhr* chip, int idx) |
| 260 | { |
| 261 | int err; |
| 262 | struct pcxhr_rmh rmh; |
| 263 | struct pcxhr_pipe *pipe = &chip->playback_pipe; |
| 264 | int left, right; |
| 265 | |
| 266 | if (chip->digital_playback_active[idx][0]) |
| 267 | left = chip->digital_playback_volume[idx][0]; |
| 268 | else |
| 269 | left = PCXHR_DIGITAL_LEVEL_MIN; |
| 270 | if (chip->digital_playback_active[idx][1]) |
| 271 | right = chip->digital_playback_volume[idx][1]; |
| 272 | else |
| 273 | right = PCXHR_DIGITAL_LEVEL_MIN; |
| 274 | |
| 275 | pcxhr_init_rmh(&rmh, CMD_STREAM_OUT_LEVEL_ADJUST); |
| 276 | /* add pipe and stream mask */ |
| 277 | pcxhr_set_pipe_cmd_params(&rmh, 0, pipe->first_audio, 0, 1<<idx); |
| 278 | /* volume left->left / right->right panoramic level */ |
| 279 | rmh.cmd[0] |= MORE_THAN_ONE_STREAM_LEVEL; |
| 280 | rmh.cmd[2] = VALID_STREAM_PAN_LEVEL_MASK | VALID_STREAM_LEVEL_1_MASK; |
| 281 | rmh.cmd[2] |= (left << 10); |
| 282 | rmh.cmd[3] = VALID_STREAM_PAN_LEVEL_MASK | VALID_STREAM_LEVEL_2_MASK; |
| 283 | rmh.cmd[3] |= right; |
| 284 | rmh.cmd_len = 4; |
| 285 | |
| 286 | err = pcxhr_send_msg(chip->mgr, &rmh); |
| 287 | if (err < 0) { |
Takashi Iwai | b59bb8e | 2014-02-26 11:47:55 +0100 | [diff] [blame^] | 288 | dev_dbg(chip->card->dev, "error update_playback_stream_level " |
Markus Bollinger | e12229b | 2005-12-06 13:55:26 +0100 | [diff] [blame] | 289 | "card(%d) err(%x)\n", chip->chip_idx, err); |
| 290 | return -EINVAL; |
| 291 | } |
| 292 | return 0; |
| 293 | } |
| 294 | |
| 295 | #define AUDIO_IO_HAS_MUTE_LEVEL 0x400000 |
| 296 | #define AUDIO_IO_HAS_MUTE_MONITOR_1 0x200000 |
| 297 | #define VALID_AUDIO_IO_DIGITAL_LEVEL 0x000001 |
| 298 | #define VALID_AUDIO_IO_MONITOR_LEVEL 0x000002 |
| 299 | #define VALID_AUDIO_IO_MUTE_LEVEL 0x000004 |
| 300 | #define VALID_AUDIO_IO_MUTE_MONITOR_1 0x000008 |
| 301 | |
Markus Bollinger | c0193f3 | 2008-11-25 12:37:52 +0100 | [diff] [blame] | 302 | static int pcxhr_update_audio_pipe_level(struct snd_pcxhr *chip, |
| 303 | int capture, int channel) |
Markus Bollinger | e12229b | 2005-12-06 13:55:26 +0100 | [diff] [blame] | 304 | { |
| 305 | int err; |
| 306 | struct pcxhr_rmh rmh; |
| 307 | struct pcxhr_pipe *pipe; |
| 308 | |
| 309 | if (capture) |
| 310 | pipe = &chip->capture_pipe[0]; |
| 311 | else |
| 312 | pipe = &chip->playback_pipe; |
| 313 | |
| 314 | pcxhr_init_rmh(&rmh, CMD_AUDIO_LEVEL_ADJUST); |
| 315 | /* add channel mask */ |
Markus Bollinger | c0193f3 | 2008-11-25 12:37:52 +0100 | [diff] [blame] | 316 | pcxhr_set_pipe_cmd_params(&rmh, capture, 0, 0, |
| 317 | 1 << (channel + pipe->first_audio)); |
| 318 | /* TODO : if mask (3 << pipe->first_audio) is used, left and right |
| 319 | * channel will be programmed to the same params */ |
Markus Bollinger | e12229b | 2005-12-06 13:55:26 +0100 | [diff] [blame] | 320 | if (capture) { |
| 321 | rmh.cmd[0] |= VALID_AUDIO_IO_DIGITAL_LEVEL; |
Markus Bollinger | c0193f3 | 2008-11-25 12:37:52 +0100 | [diff] [blame] | 322 | /* VALID_AUDIO_IO_MUTE_LEVEL not yet handled |
| 323 | * (capture pipe level) */ |
Markus Bollinger | e12229b | 2005-12-06 13:55:26 +0100 | [diff] [blame] | 324 | rmh.cmd[2] = chip->digital_capture_volume[channel]; |
| 325 | } else { |
Markus Bollinger | c0193f3 | 2008-11-25 12:37:52 +0100 | [diff] [blame] | 326 | rmh.cmd[0] |= VALID_AUDIO_IO_MONITOR_LEVEL | |
| 327 | VALID_AUDIO_IO_MUTE_MONITOR_1; |
| 328 | /* VALID_AUDIO_IO_DIGITAL_LEVEL and VALID_AUDIO_IO_MUTE_LEVEL |
| 329 | * not yet handled (playback pipe level) |
Markus Bollinger | e12229b | 2005-12-06 13:55:26 +0100 | [diff] [blame] | 330 | */ |
| 331 | rmh.cmd[2] = chip->monitoring_volume[channel] << 10; |
| 332 | if (chip->monitoring_active[channel] == 0) |
| 333 | rmh.cmd[2] |= AUDIO_IO_HAS_MUTE_MONITOR_1; |
| 334 | } |
| 335 | rmh.cmd_len = 3; |
| 336 | |
| 337 | err = pcxhr_send_msg(chip->mgr, &rmh); |
Markus Bollinger | c0193f3 | 2008-11-25 12:37:52 +0100 | [diff] [blame] | 338 | if (err < 0) { |
Takashi Iwai | b59bb8e | 2014-02-26 11:47:55 +0100 | [diff] [blame^] | 339 | dev_dbg(chip->card->dev, |
| 340 | "error update_audio_level(%d) err=%x\n", |
Markus Bollinger | e12229b | 2005-12-06 13:55:26 +0100 | [diff] [blame] | 341 | chip->chip_idx, err); |
| 342 | return -EINVAL; |
| 343 | } |
| 344 | return 0; |
| 345 | } |
| 346 | |
| 347 | |
| 348 | /* shared */ |
| 349 | static int pcxhr_digital_vol_info(struct snd_kcontrol *kcontrol, |
| 350 | struct snd_ctl_elem_info *uinfo) |
| 351 | { |
| 352 | uinfo->type = SNDRV_CTL_ELEM_TYPE_INTEGER; |
| 353 | uinfo->count = 2; |
| 354 | uinfo->value.integer.min = PCXHR_DIGITAL_LEVEL_MIN; /* -109.5 dB */ |
| 355 | uinfo->value.integer.max = PCXHR_DIGITAL_LEVEL_MAX; /* 18.0 dB */ |
| 356 | return 0; |
| 357 | } |
| 358 | |
| 359 | |
| 360 | static int pcxhr_pcm_vol_get(struct snd_kcontrol *kcontrol, |
| 361 | struct snd_ctl_elem_value *ucontrol) |
| 362 | { |
| 363 | struct snd_pcxhr *chip = snd_kcontrol_chip(kcontrol); |
Markus Bollinger | c0193f3 | 2008-11-25 12:37:52 +0100 | [diff] [blame] | 364 | int idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id); /* index */ |
Markus Bollinger | e12229b | 2005-12-06 13:55:26 +0100 | [diff] [blame] | 365 | int *stored_volume; |
| 366 | int is_capture = kcontrol->private_value; |
| 367 | |
Ingo Molnar | 62932df | 2006-01-16 16:34:20 +0100 | [diff] [blame] | 368 | mutex_lock(&chip->mgr->mixer_mutex); |
Markus Bollinger | c0193f3 | 2008-11-25 12:37:52 +0100 | [diff] [blame] | 369 | if (is_capture) /* digital capture */ |
| 370 | stored_volume = chip->digital_capture_volume; |
| 371 | else /* digital playback */ |
| 372 | stored_volume = chip->digital_playback_volume[idx]; |
Markus Bollinger | e12229b | 2005-12-06 13:55:26 +0100 | [diff] [blame] | 373 | ucontrol->value.integer.value[0] = stored_volume[0]; |
| 374 | ucontrol->value.integer.value[1] = stored_volume[1]; |
Ingo Molnar | 62932df | 2006-01-16 16:34:20 +0100 | [diff] [blame] | 375 | mutex_unlock(&chip->mgr->mixer_mutex); |
Markus Bollinger | e12229b | 2005-12-06 13:55:26 +0100 | [diff] [blame] | 376 | return 0; |
| 377 | } |
| 378 | |
| 379 | static int pcxhr_pcm_vol_put(struct snd_kcontrol *kcontrol, |
| 380 | struct snd_ctl_elem_value *ucontrol) |
| 381 | { |
| 382 | struct snd_pcxhr *chip = snd_kcontrol_chip(kcontrol); |
Markus Bollinger | c0193f3 | 2008-11-25 12:37:52 +0100 | [diff] [blame] | 383 | int idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id); /* index */ |
Markus Bollinger | e12229b | 2005-12-06 13:55:26 +0100 | [diff] [blame] | 384 | int changed = 0; |
| 385 | int is_capture = kcontrol->private_value; |
| 386 | int *stored_volume; |
| 387 | int i; |
| 388 | |
Ingo Molnar | 62932df | 2006-01-16 16:34:20 +0100 | [diff] [blame] | 389 | mutex_lock(&chip->mgr->mixer_mutex); |
Takashi Iwai | 4e98d6a | 2007-11-15 15:58:13 +0100 | [diff] [blame] | 390 | if (is_capture) /* digital capture */ |
| 391 | stored_volume = chip->digital_capture_volume; |
| 392 | else /* digital playback */ |
| 393 | stored_volume = chip->digital_playback_volume[idx]; |
Markus Bollinger | e12229b | 2005-12-06 13:55:26 +0100 | [diff] [blame] | 394 | for (i = 0; i < 2; i++) { |
Takashi Iwai | 4e98d6a | 2007-11-15 15:58:13 +0100 | [diff] [blame] | 395 | int vol = ucontrol->value.integer.value[i]; |
| 396 | if (vol < PCXHR_DIGITAL_LEVEL_MIN || |
| 397 | vol > PCXHR_DIGITAL_LEVEL_MAX) |
| 398 | continue; |
| 399 | if (stored_volume[i] != vol) { |
| 400 | stored_volume[i] = vol; |
Markus Bollinger | e12229b | 2005-12-06 13:55:26 +0100 | [diff] [blame] | 401 | changed = 1; |
| 402 | if (is_capture) /* update capture volume */ |
| 403 | pcxhr_update_audio_pipe_level(chip, 1, i); |
| 404 | } |
| 405 | } |
Takashi Iwai | 4e98d6a | 2007-11-15 15:58:13 +0100 | [diff] [blame] | 406 | if (!is_capture && changed) /* update playback volume */ |
| 407 | pcxhr_update_playback_stream_level(chip, idx); |
Ingo Molnar | 62932df | 2006-01-16 16:34:20 +0100 | [diff] [blame] | 408 | mutex_unlock(&chip->mgr->mixer_mutex); |
Markus Bollinger | e12229b | 2005-12-06 13:55:26 +0100 | [diff] [blame] | 409 | return changed; |
| 410 | } |
| 411 | |
| 412 | static struct snd_kcontrol_new snd_pcxhr_pcm_vol = |
| 413 | { |
| 414 | .iface = SNDRV_CTL_ELEM_IFACE_MIXER, |
Takashi Iwai | c6ff77f | 2006-08-23 19:53:02 +0200 | [diff] [blame] | 415 | .access = (SNDRV_CTL_ELEM_ACCESS_READWRITE | |
| 416 | SNDRV_CTL_ELEM_ACCESS_TLV_READ), |
Markus Bollinger | e12229b | 2005-12-06 13:55:26 +0100 | [diff] [blame] | 417 | /* name will be filled later */ |
| 418 | /* count will be filled later */ |
| 419 | .info = pcxhr_digital_vol_info, /* shared */ |
| 420 | .get = pcxhr_pcm_vol_get, |
| 421 | .put = pcxhr_pcm_vol_put, |
Takashi Iwai | c6ff77f | 2006-08-23 19:53:02 +0200 | [diff] [blame] | 422 | .tlv = { .p = db_scale_digital }, |
Markus Bollinger | e12229b | 2005-12-06 13:55:26 +0100 | [diff] [blame] | 423 | }; |
| 424 | |
| 425 | |
| 426 | static int pcxhr_pcm_sw_get(struct snd_kcontrol *kcontrol, |
| 427 | struct snd_ctl_elem_value *ucontrol) |
| 428 | { |
| 429 | struct snd_pcxhr *chip = snd_kcontrol_chip(kcontrol); |
| 430 | int idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id); /* index */ |
| 431 | |
Ingo Molnar | 62932df | 2006-01-16 16:34:20 +0100 | [diff] [blame] | 432 | mutex_lock(&chip->mgr->mixer_mutex); |
Markus Bollinger | e12229b | 2005-12-06 13:55:26 +0100 | [diff] [blame] | 433 | ucontrol->value.integer.value[0] = chip->digital_playback_active[idx][0]; |
| 434 | ucontrol->value.integer.value[1] = chip->digital_playback_active[idx][1]; |
Ingo Molnar | 62932df | 2006-01-16 16:34:20 +0100 | [diff] [blame] | 435 | mutex_unlock(&chip->mgr->mixer_mutex); |
Markus Bollinger | e12229b | 2005-12-06 13:55:26 +0100 | [diff] [blame] | 436 | return 0; |
| 437 | } |
| 438 | |
Markus Bollinger | c0193f3 | 2008-11-25 12:37:52 +0100 | [diff] [blame] | 439 | static int pcxhr_pcm_sw_put(struct snd_kcontrol *kcontrol, |
| 440 | struct snd_ctl_elem_value *ucontrol) |
Markus Bollinger | e12229b | 2005-12-06 13:55:26 +0100 | [diff] [blame] | 441 | { |
| 442 | struct snd_pcxhr *chip = snd_kcontrol_chip(kcontrol); |
| 443 | int changed = 0; |
| 444 | int idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id); /* index */ |
| 445 | int i, j; |
| 446 | |
Ingo Molnar | 62932df | 2006-01-16 16:34:20 +0100 | [diff] [blame] | 447 | mutex_lock(&chip->mgr->mixer_mutex); |
Markus Bollinger | e12229b | 2005-12-06 13:55:26 +0100 | [diff] [blame] | 448 | j = idx; |
| 449 | for (i = 0; i < 2; i++) { |
Takashi Iwai | 4e98d6a | 2007-11-15 15:58:13 +0100 | [diff] [blame] | 450 | if (chip->digital_playback_active[j][i] != |
| 451 | ucontrol->value.integer.value[i]) { |
| 452 | chip->digital_playback_active[j][i] = |
| 453 | !!ucontrol->value.integer.value[i]; |
Markus Bollinger | e12229b | 2005-12-06 13:55:26 +0100 | [diff] [blame] | 454 | changed = 1; |
| 455 | } |
| 456 | } |
| 457 | if (changed) |
| 458 | pcxhr_update_playback_stream_level(chip, idx); |
Ingo Molnar | 62932df | 2006-01-16 16:34:20 +0100 | [diff] [blame] | 459 | mutex_unlock(&chip->mgr->mixer_mutex); |
Markus Bollinger | e12229b | 2005-12-06 13:55:26 +0100 | [diff] [blame] | 460 | return changed; |
| 461 | } |
| 462 | |
| 463 | static struct snd_kcontrol_new pcxhr_control_pcm_switch = { |
| 464 | .iface = SNDRV_CTL_ELEM_IFACE_MIXER, |
| 465 | .name = "PCM Playback Switch", |
| 466 | .count = PCXHR_PLAYBACK_STREAMS, |
| 467 | .info = pcxhr_sw_info, /* shared */ |
| 468 | .get = pcxhr_pcm_sw_get, |
| 469 | .put = pcxhr_pcm_sw_put |
| 470 | }; |
| 471 | |
| 472 | |
| 473 | /* |
| 474 | * monitoring level control |
| 475 | */ |
| 476 | |
| 477 | static int pcxhr_monitor_vol_get(struct snd_kcontrol *kcontrol, |
| 478 | struct snd_ctl_elem_value *ucontrol) |
| 479 | { |
| 480 | struct snd_pcxhr *chip = snd_kcontrol_chip(kcontrol); |
Ingo Molnar | 62932df | 2006-01-16 16:34:20 +0100 | [diff] [blame] | 481 | mutex_lock(&chip->mgr->mixer_mutex); |
Markus Bollinger | e12229b | 2005-12-06 13:55:26 +0100 | [diff] [blame] | 482 | ucontrol->value.integer.value[0] = chip->monitoring_volume[0]; |
| 483 | ucontrol->value.integer.value[1] = chip->monitoring_volume[1]; |
Ingo Molnar | 62932df | 2006-01-16 16:34:20 +0100 | [diff] [blame] | 484 | mutex_unlock(&chip->mgr->mixer_mutex); |
Markus Bollinger | e12229b | 2005-12-06 13:55:26 +0100 | [diff] [blame] | 485 | return 0; |
| 486 | } |
| 487 | |
| 488 | static int pcxhr_monitor_vol_put(struct snd_kcontrol *kcontrol, |
| 489 | struct snd_ctl_elem_value *ucontrol) |
| 490 | { |
| 491 | struct snd_pcxhr *chip = snd_kcontrol_chip(kcontrol); |
| 492 | int changed = 0; |
| 493 | int i; |
| 494 | |
Ingo Molnar | 62932df | 2006-01-16 16:34:20 +0100 | [diff] [blame] | 495 | mutex_lock(&chip->mgr->mixer_mutex); |
Markus Bollinger | e12229b | 2005-12-06 13:55:26 +0100 | [diff] [blame] | 496 | for (i = 0; i < 2; i++) { |
Takashi Iwai | 4e98d6a | 2007-11-15 15:58:13 +0100 | [diff] [blame] | 497 | if (chip->monitoring_volume[i] != |
| 498 | ucontrol->value.integer.value[i]) { |
| 499 | chip->monitoring_volume[i] = |
Markus Bollinger | c0193f3 | 2008-11-25 12:37:52 +0100 | [diff] [blame] | 500 | ucontrol->value.integer.value[i]; |
| 501 | if (chip->monitoring_active[i]) |
Markus Bollinger | e12229b | 2005-12-06 13:55:26 +0100 | [diff] [blame] | 502 | /* update monitoring volume and mute */ |
Takashi Iwai | 4e98d6a | 2007-11-15 15:58:13 +0100 | [diff] [blame] | 503 | /* do only when monitoring is unmuted */ |
Markus Bollinger | e12229b | 2005-12-06 13:55:26 +0100 | [diff] [blame] | 504 | pcxhr_update_audio_pipe_level(chip, 0, i); |
| 505 | changed = 1; |
| 506 | } |
| 507 | } |
Ingo Molnar | 62932df | 2006-01-16 16:34:20 +0100 | [diff] [blame] | 508 | mutex_unlock(&chip->mgr->mixer_mutex); |
Markus Bollinger | e12229b | 2005-12-06 13:55:26 +0100 | [diff] [blame] | 509 | return changed; |
| 510 | } |
| 511 | |
| 512 | static struct snd_kcontrol_new pcxhr_control_monitor_vol = { |
| 513 | .iface = SNDRV_CTL_ELEM_IFACE_MIXER, |
Takashi Iwai | c6ff77f | 2006-08-23 19:53:02 +0200 | [diff] [blame] | 514 | .access = (SNDRV_CTL_ELEM_ACCESS_READWRITE | |
| 515 | SNDRV_CTL_ELEM_ACCESS_TLV_READ), |
Markus Bollinger | c0193f3 | 2008-11-25 12:37:52 +0100 | [diff] [blame] | 516 | .name = "Monitoring Playback Volume", |
Markus Bollinger | e12229b | 2005-12-06 13:55:26 +0100 | [diff] [blame] | 517 | .info = pcxhr_digital_vol_info, /* shared */ |
| 518 | .get = pcxhr_monitor_vol_get, |
| 519 | .put = pcxhr_monitor_vol_put, |
Takashi Iwai | c6ff77f | 2006-08-23 19:53:02 +0200 | [diff] [blame] | 520 | .tlv = { .p = db_scale_digital }, |
Markus Bollinger | e12229b | 2005-12-06 13:55:26 +0100 | [diff] [blame] | 521 | }; |
| 522 | |
| 523 | /* |
| 524 | * monitoring switch control |
| 525 | */ |
| 526 | |
| 527 | static int pcxhr_monitor_sw_get(struct snd_kcontrol *kcontrol, |
| 528 | struct snd_ctl_elem_value *ucontrol) |
| 529 | { |
| 530 | struct snd_pcxhr *chip = snd_kcontrol_chip(kcontrol); |
Ingo Molnar | 62932df | 2006-01-16 16:34:20 +0100 | [diff] [blame] | 531 | mutex_lock(&chip->mgr->mixer_mutex); |
Markus Bollinger | e12229b | 2005-12-06 13:55:26 +0100 | [diff] [blame] | 532 | ucontrol->value.integer.value[0] = chip->monitoring_active[0]; |
| 533 | ucontrol->value.integer.value[1] = chip->monitoring_active[1]; |
Ingo Molnar | 62932df | 2006-01-16 16:34:20 +0100 | [diff] [blame] | 534 | mutex_unlock(&chip->mgr->mixer_mutex); |
Markus Bollinger | e12229b | 2005-12-06 13:55:26 +0100 | [diff] [blame] | 535 | return 0; |
| 536 | } |
| 537 | |
| 538 | static int pcxhr_monitor_sw_put(struct snd_kcontrol *kcontrol, |
| 539 | struct snd_ctl_elem_value *ucontrol) |
| 540 | { |
| 541 | struct snd_pcxhr *chip = snd_kcontrol_chip(kcontrol); |
| 542 | int changed = 0; |
| 543 | int i; |
| 544 | |
Ingo Molnar | 62932df | 2006-01-16 16:34:20 +0100 | [diff] [blame] | 545 | mutex_lock(&chip->mgr->mixer_mutex); |
Markus Bollinger | e12229b | 2005-12-06 13:55:26 +0100 | [diff] [blame] | 546 | for (i = 0; i < 2; i++) { |
Takashi Iwai | 4e98d6a | 2007-11-15 15:58:13 +0100 | [diff] [blame] | 547 | if (chip->monitoring_active[i] != |
| 548 | ucontrol->value.integer.value[i]) { |
| 549 | chip->monitoring_active[i] = |
| 550 | !!ucontrol->value.integer.value[i]; |
Markus Bollinger | e12229b | 2005-12-06 13:55:26 +0100 | [diff] [blame] | 551 | changed |= (1<<i); /* mask 0x01 and 0x02 */ |
| 552 | } |
| 553 | } |
Takashi Iwai | 4e98d6a | 2007-11-15 15:58:13 +0100 | [diff] [blame] | 554 | if (changed & 0x01) |
Markus Bollinger | e12229b | 2005-12-06 13:55:26 +0100 | [diff] [blame] | 555 | /* update left monitoring volume and mute */ |
| 556 | pcxhr_update_audio_pipe_level(chip, 0, 0); |
Takashi Iwai | 4e98d6a | 2007-11-15 15:58:13 +0100 | [diff] [blame] | 557 | if (changed & 0x02) |
Markus Bollinger | e12229b | 2005-12-06 13:55:26 +0100 | [diff] [blame] | 558 | /* update right monitoring volume and mute */ |
| 559 | pcxhr_update_audio_pipe_level(chip, 0, 1); |
| 560 | |
Ingo Molnar | 62932df | 2006-01-16 16:34:20 +0100 | [diff] [blame] | 561 | mutex_unlock(&chip->mgr->mixer_mutex); |
Markus Bollinger | e12229b | 2005-12-06 13:55:26 +0100 | [diff] [blame] | 562 | return (changed != 0); |
| 563 | } |
| 564 | |
| 565 | static struct snd_kcontrol_new pcxhr_control_monitor_sw = { |
| 566 | .iface = SNDRV_CTL_ELEM_IFACE_MIXER, |
Markus Bollinger | c0193f3 | 2008-11-25 12:37:52 +0100 | [diff] [blame] | 567 | .name = "Monitoring Playback Switch", |
Markus Bollinger | e12229b | 2005-12-06 13:55:26 +0100 | [diff] [blame] | 568 | .info = pcxhr_sw_info, /* shared */ |
| 569 | .get = pcxhr_monitor_sw_get, |
| 570 | .put = pcxhr_monitor_sw_put |
| 571 | }; |
| 572 | |
| 573 | |
| 574 | |
| 575 | /* |
| 576 | * audio source select |
| 577 | */ |
| 578 | #define PCXHR_SOURCE_AUDIO01_UER 0x000100 |
| 579 | #define PCXHR_SOURCE_AUDIO01_SYNC 0x000200 |
| 580 | #define PCXHR_SOURCE_AUDIO23_UER 0x000400 |
| 581 | #define PCXHR_SOURCE_AUDIO45_UER 0x001000 |
| 582 | #define PCXHR_SOURCE_AUDIO67_UER 0x040000 |
| 583 | |
| 584 | static int pcxhr_set_audio_source(struct snd_pcxhr* chip) |
| 585 | { |
| 586 | struct pcxhr_rmh rmh; |
| 587 | unsigned int mask, reg; |
| 588 | unsigned int codec; |
Markus Bollinger | c0193f3 | 2008-11-25 12:37:52 +0100 | [diff] [blame] | 589 | int err, changed; |
Markus Bollinger | e12229b | 2005-12-06 13:55:26 +0100 | [diff] [blame] | 590 | |
| 591 | switch (chip->chip_idx) { |
| 592 | case 0 : mask = PCXHR_SOURCE_AUDIO01_UER; codec = CS8420_01_CS; break; |
| 593 | case 1 : mask = PCXHR_SOURCE_AUDIO23_UER; codec = CS8420_23_CS; break; |
| 594 | case 2 : mask = PCXHR_SOURCE_AUDIO45_UER; codec = CS8420_45_CS; break; |
| 595 | case 3 : mask = PCXHR_SOURCE_AUDIO67_UER; codec = CS8420_67_CS; break; |
| 596 | default: return -EINVAL; |
| 597 | } |
Markus Bollinger | e12229b | 2005-12-06 13:55:26 +0100 | [diff] [blame] | 598 | if (chip->audio_capture_source != 0) { |
| 599 | reg = mask; /* audio source from digital plug */ |
Markus Bollinger | c0193f3 | 2008-11-25 12:37:52 +0100 | [diff] [blame] | 600 | } else { |
| 601 | reg = 0; /* audio source from analog plug */ |
Markus Bollinger | e12229b | 2005-12-06 13:55:26 +0100 | [diff] [blame] | 602 | } |
| 603 | /* set the input source */ |
| 604 | pcxhr_write_io_num_reg_cont(chip->mgr, mask, reg, &changed); |
| 605 | /* resync them (otherwise channel inversion possible) */ |
| 606 | if (changed) { |
| 607 | pcxhr_init_rmh(&rmh, CMD_RESYNC_AUDIO_INPUTS); |
| 608 | rmh.cmd[0] |= (1 << chip->chip_idx); |
| 609 | err = pcxhr_send_msg(chip->mgr, &rmh); |
| 610 | if (err) |
| 611 | return err; |
| 612 | } |
Markus Bollinger | c0193f3 | 2008-11-25 12:37:52 +0100 | [diff] [blame] | 613 | if (chip->mgr->board_aes_in_192k) { |
| 614 | int i; |
| 615 | unsigned int src_config = 0xC0; |
| 616 | /* update all src configs with one call */ |
| 617 | for (i = 0; (i < 4) && (i < chip->mgr->capture_chips); i++) { |
| 618 | if (chip->mgr->chip[i]->audio_capture_source == 2) |
| 619 | src_config |= (1 << (3 - i)); |
| 620 | } |
| 621 | /* set codec SRC on off */ |
| 622 | pcxhr_init_rmh(&rmh, CMD_ACCESS_IO_WRITE); |
| 623 | rmh.cmd_len = 2; |
| 624 | rmh.cmd[0] |= IO_NUM_REG_CONFIG_SRC; |
| 625 | rmh.cmd[1] = src_config; |
| 626 | err = pcxhr_send_msg(chip->mgr, &rmh); |
| 627 | } else { |
| 628 | int use_src = 0; |
| 629 | if (chip->audio_capture_source == 2) |
| 630 | use_src = 1; |
| 631 | /* set codec SRC on off */ |
| 632 | pcxhr_init_rmh(&rmh, CMD_ACCESS_IO_WRITE); |
| 633 | rmh.cmd_len = 3; |
| 634 | rmh.cmd[0] |= IO_NUM_UER_CHIP_REG; |
| 635 | rmh.cmd[1] = codec; |
| 636 | rmh.cmd[2] = ((CS8420_DATA_FLOW_CTL & CHIP_SIG_AND_MAP_SPI) | |
| 637 | (use_src ? 0x41 : 0x54)); |
| 638 | err = pcxhr_send_msg(chip->mgr, &rmh); |
| 639 | if (err) |
| 640 | return err; |
| 641 | rmh.cmd[2] = ((CS8420_CLOCK_SRC_CTL & CHIP_SIG_AND_MAP_SPI) | |
| 642 | (use_src ? 0x41 : 0x49)); |
| 643 | err = pcxhr_send_msg(chip->mgr, &rmh); |
| 644 | } |
Markus Bollinger | e12229b | 2005-12-06 13:55:26 +0100 | [diff] [blame] | 645 | return err; |
| 646 | } |
| 647 | |
| 648 | static int pcxhr_audio_src_info(struct snd_kcontrol *kcontrol, |
| 649 | struct snd_ctl_elem_info *uinfo) |
| 650 | { |
Markus Bollinger | c0193f3 | 2008-11-25 12:37:52 +0100 | [diff] [blame] | 651 | static const char *texts[5] = { |
| 652 | "Line", "Digital", "Digi+SRC", "Mic", "Line+Mic" |
| 653 | }; |
| 654 | int i; |
| 655 | struct snd_pcxhr *chip = snd_kcontrol_chip(kcontrol); |
Markus Bollinger | e12229b | 2005-12-06 13:55:26 +0100 | [diff] [blame] | 656 | |
Markus Bollinger | c0193f3 | 2008-11-25 12:37:52 +0100 | [diff] [blame] | 657 | i = 2; /* no SRC, no Mic available */ |
| 658 | if (chip->mgr->board_has_aes1) { |
| 659 | i = 3; /* SRC available */ |
| 660 | if (chip->mgr->board_has_mic) |
| 661 | i = 5; /* Mic and MicroMix available */ |
| 662 | } |
Markus Bollinger | e12229b | 2005-12-06 13:55:26 +0100 | [diff] [blame] | 663 | uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED; |
| 664 | uinfo->count = 1; |
Markus Bollinger | c0193f3 | 2008-11-25 12:37:52 +0100 | [diff] [blame] | 665 | uinfo->value.enumerated.items = i; |
| 666 | if (uinfo->value.enumerated.item > (i-1)) |
| 667 | uinfo->value.enumerated.item = i-1; |
Markus Bollinger | e12229b | 2005-12-06 13:55:26 +0100 | [diff] [blame] | 668 | strcpy(uinfo->value.enumerated.name, |
| 669 | texts[uinfo->value.enumerated.item]); |
| 670 | return 0; |
| 671 | } |
| 672 | |
| 673 | static int pcxhr_audio_src_get(struct snd_kcontrol *kcontrol, |
| 674 | struct snd_ctl_elem_value *ucontrol) |
| 675 | { |
| 676 | struct snd_pcxhr *chip = snd_kcontrol_chip(kcontrol); |
| 677 | ucontrol->value.enumerated.item[0] = chip->audio_capture_source; |
| 678 | return 0; |
| 679 | } |
| 680 | |
| 681 | static int pcxhr_audio_src_put(struct snd_kcontrol *kcontrol, |
| 682 | struct snd_ctl_elem_value *ucontrol) |
| 683 | { |
| 684 | struct snd_pcxhr *chip = snd_kcontrol_chip(kcontrol); |
| 685 | int ret = 0; |
Markus Bollinger | c0193f3 | 2008-11-25 12:37:52 +0100 | [diff] [blame] | 686 | int i = 2; /* no SRC, no Mic available */ |
| 687 | if (chip->mgr->board_has_aes1) { |
| 688 | i = 3; /* SRC available */ |
| 689 | if (chip->mgr->board_has_mic) |
| 690 | i = 5; /* Mic and MicroMix available */ |
| 691 | } |
| 692 | if (ucontrol->value.enumerated.item[0] >= i) |
Takashi Iwai | 4e98d6a | 2007-11-15 15:58:13 +0100 | [diff] [blame] | 693 | return -EINVAL; |
Ingo Molnar | 62932df | 2006-01-16 16:34:20 +0100 | [diff] [blame] | 694 | mutex_lock(&chip->mgr->mixer_mutex); |
Markus Bollinger | e12229b | 2005-12-06 13:55:26 +0100 | [diff] [blame] | 695 | if (chip->audio_capture_source != ucontrol->value.enumerated.item[0]) { |
| 696 | chip->audio_capture_source = ucontrol->value.enumerated.item[0]; |
Markus Bollinger | c0193f3 | 2008-11-25 12:37:52 +0100 | [diff] [blame] | 697 | if (chip->mgr->is_hr_stereo) |
| 698 | hr222_set_audio_source(chip); |
| 699 | else |
| 700 | pcxhr_set_audio_source(chip); |
Markus Bollinger | e12229b | 2005-12-06 13:55:26 +0100 | [diff] [blame] | 701 | ret = 1; |
| 702 | } |
Ingo Molnar | 62932df | 2006-01-16 16:34:20 +0100 | [diff] [blame] | 703 | mutex_unlock(&chip->mgr->mixer_mutex); |
Markus Bollinger | e12229b | 2005-12-06 13:55:26 +0100 | [diff] [blame] | 704 | return ret; |
| 705 | } |
| 706 | |
| 707 | static struct snd_kcontrol_new pcxhr_control_audio_src = { |
| 708 | .iface = SNDRV_CTL_ELEM_IFACE_MIXER, |
| 709 | .name = "Capture Source", |
| 710 | .info = pcxhr_audio_src_info, |
| 711 | .get = pcxhr_audio_src_get, |
| 712 | .put = pcxhr_audio_src_put, |
| 713 | }; |
| 714 | |
| 715 | |
| 716 | /* |
| 717 | * clock type selection |
| 718 | * enum pcxhr_clock_type { |
Markus Bollinger | c0193f3 | 2008-11-25 12:37:52 +0100 | [diff] [blame] | 719 | * PCXHR_CLOCK_TYPE_INTERNAL = 0, |
| 720 | * PCXHR_CLOCK_TYPE_WORD_CLOCK, |
| 721 | * PCXHR_CLOCK_TYPE_AES_SYNC, |
| 722 | * PCXHR_CLOCK_TYPE_AES_1, |
| 723 | * PCXHR_CLOCK_TYPE_AES_2, |
| 724 | * PCXHR_CLOCK_TYPE_AES_3, |
| 725 | * PCXHR_CLOCK_TYPE_AES_4, |
| 726 | * PCXHR_CLOCK_TYPE_MAX = PCXHR_CLOCK_TYPE_AES_4, |
| 727 | * HR22_CLOCK_TYPE_INTERNAL = PCXHR_CLOCK_TYPE_INTERNAL, |
| 728 | * HR22_CLOCK_TYPE_AES_SYNC, |
| 729 | * HR22_CLOCK_TYPE_AES_1, |
| 730 | * HR22_CLOCK_TYPE_MAX = HR22_CLOCK_TYPE_AES_1, |
| 731 | * }; |
Markus Bollinger | e12229b | 2005-12-06 13:55:26 +0100 | [diff] [blame] | 732 | */ |
| 733 | |
| 734 | static int pcxhr_clock_type_info(struct snd_kcontrol *kcontrol, |
| 735 | struct snd_ctl_elem_info *uinfo) |
| 736 | { |
Markus Bollinger | c0193f3 | 2008-11-25 12:37:52 +0100 | [diff] [blame] | 737 | static const char *textsPCXHR[7] = { |
| 738 | "Internal", "WordClock", "AES Sync", |
| 739 | "AES 1", "AES 2", "AES 3", "AES 4" |
Markus Bollinger | e12229b | 2005-12-06 13:55:26 +0100 | [diff] [blame] | 740 | }; |
Markus Bollinger | c0193f3 | 2008-11-25 12:37:52 +0100 | [diff] [blame] | 741 | static const char *textsHR22[3] = { |
| 742 | "Internal", "AES Sync", "AES 1" |
| 743 | }; |
| 744 | const char **texts; |
Markus Bollinger | e12229b | 2005-12-06 13:55:26 +0100 | [diff] [blame] | 745 | struct pcxhr_mgr *mgr = snd_kcontrol_chip(kcontrol); |
Markus Bollinger | c0193f3 | 2008-11-25 12:37:52 +0100 | [diff] [blame] | 746 | int clock_items = 2; /* at least Internal and AES Sync clock */ |
| 747 | if (mgr->board_has_aes1) { |
| 748 | clock_items += mgr->capture_chips; /* add AES x */ |
| 749 | if (!mgr->is_hr_stereo) |
| 750 | clock_items += 1; /* add word clock */ |
| 751 | } |
| 752 | if (mgr->is_hr_stereo) { |
| 753 | texts = textsHR22; |
| 754 | snd_BUG_ON(clock_items > (HR22_CLOCK_TYPE_MAX+1)); |
| 755 | } else { |
| 756 | texts = textsPCXHR; |
| 757 | snd_BUG_ON(clock_items > (PCXHR_CLOCK_TYPE_MAX+1)); |
| 758 | } |
Markus Bollinger | e12229b | 2005-12-06 13:55:26 +0100 | [diff] [blame] | 759 | uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED; |
| 760 | uinfo->count = 1; |
| 761 | uinfo->value.enumerated.items = clock_items; |
| 762 | if (uinfo->value.enumerated.item >= clock_items) |
| 763 | uinfo->value.enumerated.item = clock_items-1; |
| 764 | strcpy(uinfo->value.enumerated.name, |
| 765 | texts[uinfo->value.enumerated.item]); |
| 766 | return 0; |
| 767 | } |
| 768 | |
| 769 | static int pcxhr_clock_type_get(struct snd_kcontrol *kcontrol, |
| 770 | struct snd_ctl_elem_value *ucontrol) |
| 771 | { |
| 772 | struct pcxhr_mgr *mgr = snd_kcontrol_chip(kcontrol); |
| 773 | ucontrol->value.enumerated.item[0] = mgr->use_clock_type; |
| 774 | return 0; |
| 775 | } |
| 776 | |
| 777 | static int pcxhr_clock_type_put(struct snd_kcontrol *kcontrol, |
| 778 | struct snd_ctl_elem_value *ucontrol) |
| 779 | { |
| 780 | struct pcxhr_mgr *mgr = snd_kcontrol_chip(kcontrol); |
| 781 | int rate, ret = 0; |
Markus Bollinger | c0193f3 | 2008-11-25 12:37:52 +0100 | [diff] [blame] | 782 | unsigned int clock_items = 2; /* at least Internal and AES Sync clock */ |
| 783 | if (mgr->board_has_aes1) { |
| 784 | clock_items += mgr->capture_chips; /* add AES x */ |
| 785 | if (!mgr->is_hr_stereo) |
| 786 | clock_items += 1; /* add word clock */ |
| 787 | } |
Takashi Iwai | 4e98d6a | 2007-11-15 15:58:13 +0100 | [diff] [blame] | 788 | if (ucontrol->value.enumerated.item[0] >= clock_items) |
| 789 | return -EINVAL; |
Ingo Molnar | 62932df | 2006-01-16 16:34:20 +0100 | [diff] [blame] | 790 | mutex_lock(&mgr->mixer_mutex); |
Markus Bollinger | e12229b | 2005-12-06 13:55:26 +0100 | [diff] [blame] | 791 | if (mgr->use_clock_type != ucontrol->value.enumerated.item[0]) { |
Ingo Molnar | 62932df | 2006-01-16 16:34:20 +0100 | [diff] [blame] | 792 | mutex_lock(&mgr->setup_mutex); |
Markus Bollinger | e12229b | 2005-12-06 13:55:26 +0100 | [diff] [blame] | 793 | mgr->use_clock_type = ucontrol->value.enumerated.item[0]; |
Markus Bollinger | 55aef45 | 2009-01-23 14:45:41 +0100 | [diff] [blame] | 794 | rate = 0; |
| 795 | if (mgr->use_clock_type != PCXHR_CLOCK_TYPE_INTERNAL) { |
Markus Bollinger | c0193f3 | 2008-11-25 12:37:52 +0100 | [diff] [blame] | 796 | pcxhr_get_external_clock(mgr, mgr->use_clock_type, |
| 797 | &rate); |
Markus Bollinger | 55aef45 | 2009-01-23 14:45:41 +0100 | [diff] [blame] | 798 | } else { |
Markus Bollinger | e12229b | 2005-12-06 13:55:26 +0100 | [diff] [blame] | 799 | rate = mgr->sample_rate; |
Markus Bollinger | 55aef45 | 2009-01-23 14:45:41 +0100 | [diff] [blame] | 800 | if (!rate) |
| 801 | rate = 48000; |
| 802 | } |
Markus Bollinger | e12229b | 2005-12-06 13:55:26 +0100 | [diff] [blame] | 803 | if (rate) { |
| 804 | pcxhr_set_clock(mgr, rate); |
| 805 | if (mgr->sample_rate) |
| 806 | mgr->sample_rate = rate; |
| 807 | } |
Ingo Molnar | 62932df | 2006-01-16 16:34:20 +0100 | [diff] [blame] | 808 | mutex_unlock(&mgr->setup_mutex); |
Markus Bollinger | c0193f3 | 2008-11-25 12:37:52 +0100 | [diff] [blame] | 809 | ret = 1; /* return 1 even if the set was not done. ok ? */ |
Markus Bollinger | e12229b | 2005-12-06 13:55:26 +0100 | [diff] [blame] | 810 | } |
Ingo Molnar | 62932df | 2006-01-16 16:34:20 +0100 | [diff] [blame] | 811 | mutex_unlock(&mgr->mixer_mutex); |
Markus Bollinger | e12229b | 2005-12-06 13:55:26 +0100 | [diff] [blame] | 812 | return ret; |
| 813 | } |
| 814 | |
| 815 | static struct snd_kcontrol_new pcxhr_control_clock_type = { |
| 816 | .iface = SNDRV_CTL_ELEM_IFACE_MIXER, |
| 817 | .name = "Clock Mode", |
| 818 | .info = pcxhr_clock_type_info, |
| 819 | .get = pcxhr_clock_type_get, |
| 820 | .put = pcxhr_clock_type_put, |
| 821 | }; |
| 822 | |
| 823 | /* |
| 824 | * clock rate control |
| 825 | * specific control that scans the sample rates on the external plugs |
| 826 | */ |
| 827 | static int pcxhr_clock_rate_info(struct snd_kcontrol *kcontrol, |
| 828 | struct snd_ctl_elem_info *uinfo) |
| 829 | { |
| 830 | struct pcxhr_mgr *mgr = snd_kcontrol_chip(kcontrol); |
| 831 | uinfo->type = SNDRV_CTL_ELEM_TYPE_INTEGER; |
| 832 | uinfo->count = 3 + mgr->capture_chips; |
| 833 | uinfo->value.integer.min = 0; /* clock not present */ |
| 834 | uinfo->value.integer.max = 192000; /* max sample rate 192 kHz */ |
| 835 | return 0; |
| 836 | } |
| 837 | |
| 838 | static int pcxhr_clock_rate_get(struct snd_kcontrol *kcontrol, |
| 839 | struct snd_ctl_elem_value *ucontrol) |
| 840 | { |
| 841 | struct pcxhr_mgr *mgr = snd_kcontrol_chip(kcontrol); |
| 842 | int i, err, rate; |
| 843 | |
Ingo Molnar | 62932df | 2006-01-16 16:34:20 +0100 | [diff] [blame] | 844 | mutex_lock(&mgr->mixer_mutex); |
Markus Bollinger | e12229b | 2005-12-06 13:55:26 +0100 | [diff] [blame] | 845 | for(i = 0; i < 3 + mgr->capture_chips; i++) { |
| 846 | if (i == PCXHR_CLOCK_TYPE_INTERNAL) |
| 847 | rate = mgr->sample_rate_real; |
| 848 | else { |
| 849 | err = pcxhr_get_external_clock(mgr, i, &rate); |
| 850 | if (err) |
| 851 | break; |
| 852 | } |
| 853 | ucontrol->value.integer.value[i] = rate; |
| 854 | } |
Ingo Molnar | 62932df | 2006-01-16 16:34:20 +0100 | [diff] [blame] | 855 | mutex_unlock(&mgr->mixer_mutex); |
Markus Bollinger | e12229b | 2005-12-06 13:55:26 +0100 | [diff] [blame] | 856 | return 0; |
| 857 | } |
| 858 | |
| 859 | static struct snd_kcontrol_new pcxhr_control_clock_rate = { |
| 860 | .access = SNDRV_CTL_ELEM_ACCESS_READ, |
| 861 | .iface = SNDRV_CTL_ELEM_IFACE_CARD, |
| 862 | .name = "Clock Rates", |
| 863 | .info = pcxhr_clock_rate_info, |
| 864 | .get = pcxhr_clock_rate_get, |
| 865 | }; |
| 866 | |
| 867 | /* |
| 868 | * IEC958 status bits |
| 869 | */ |
Markus Bollinger | c0193f3 | 2008-11-25 12:37:52 +0100 | [diff] [blame] | 870 | static int pcxhr_iec958_info(struct snd_kcontrol *kcontrol, |
| 871 | struct snd_ctl_elem_info *uinfo) |
Markus Bollinger | e12229b | 2005-12-06 13:55:26 +0100 | [diff] [blame] | 872 | { |
| 873 | uinfo->type = SNDRV_CTL_ELEM_TYPE_IEC958; |
| 874 | uinfo->count = 1; |
| 875 | return 0; |
| 876 | } |
| 877 | |
Markus Bollinger | c0193f3 | 2008-11-25 12:37:52 +0100 | [diff] [blame] | 878 | static int pcxhr_iec958_capture_byte(struct snd_pcxhr *chip, |
| 879 | int aes_idx, unsigned char *aes_bits) |
Markus Bollinger | e12229b | 2005-12-06 13:55:26 +0100 | [diff] [blame] | 880 | { |
| 881 | int i, err; |
| 882 | unsigned char temp; |
| 883 | struct pcxhr_rmh rmh; |
| 884 | |
| 885 | pcxhr_init_rmh(&rmh, CMD_ACCESS_IO_READ); |
| 886 | rmh.cmd[0] |= IO_NUM_UER_CHIP_REG; |
| 887 | switch (chip->chip_idx) { |
Markus Bollinger | c0193f3 | 2008-11-25 12:37:52 +0100 | [diff] [blame] | 888 | /* instead of CS8420_01_CS use CS8416_01_CS for AES SYNC plug */ |
| 889 | case 0: rmh.cmd[1] = CS8420_01_CS; break; |
Markus Bollinger | e12229b | 2005-12-06 13:55:26 +0100 | [diff] [blame] | 890 | case 1: rmh.cmd[1] = CS8420_23_CS; break; |
| 891 | case 2: rmh.cmd[1] = CS8420_45_CS; break; |
| 892 | case 3: rmh.cmd[1] = CS8420_67_CS; break; |
| 893 | default: return -EINVAL; |
| 894 | } |
Markus Bollinger | c0193f3 | 2008-11-25 12:37:52 +0100 | [diff] [blame] | 895 | if (chip->mgr->board_aes_in_192k) { |
| 896 | switch (aes_idx) { |
| 897 | case 0: rmh.cmd[2] = CS8416_CSB0; break; |
| 898 | case 1: rmh.cmd[2] = CS8416_CSB1; break; |
| 899 | case 2: rmh.cmd[2] = CS8416_CSB2; break; |
| 900 | case 3: rmh.cmd[2] = CS8416_CSB3; break; |
| 901 | case 4: rmh.cmd[2] = CS8416_CSB4; break; |
| 902 | default: return -EINVAL; |
| 903 | } |
| 904 | } else { |
| 905 | switch (aes_idx) { |
| 906 | /* instead of CS8420_CSB0 use CS8416_CSBx for AES SYNC plug */ |
| 907 | case 0: rmh.cmd[2] = CS8420_CSB0; break; |
| 908 | case 1: rmh.cmd[2] = CS8420_CSB1; break; |
| 909 | case 2: rmh.cmd[2] = CS8420_CSB2; break; |
| 910 | case 3: rmh.cmd[2] = CS8420_CSB3; break; |
| 911 | case 4: rmh.cmd[2] = CS8420_CSB4; break; |
| 912 | default: return -EINVAL; |
| 913 | } |
Markus Bollinger | e12229b | 2005-12-06 13:55:26 +0100 | [diff] [blame] | 914 | } |
Markus Bollinger | c0193f3 | 2008-11-25 12:37:52 +0100 | [diff] [blame] | 915 | /* size and code the chip id for the fpga */ |
| 916 | rmh.cmd[1] &= 0x0fffff; |
| 917 | /* chip signature + map for spi read */ |
| 918 | rmh.cmd[2] &= CHIP_SIG_AND_MAP_SPI; |
Markus Bollinger | e12229b | 2005-12-06 13:55:26 +0100 | [diff] [blame] | 919 | rmh.cmd_len = 3; |
| 920 | err = pcxhr_send_msg(chip->mgr, &rmh); |
| 921 | if (err) |
| 922 | return err; |
Markus Bollinger | c0193f3 | 2008-11-25 12:37:52 +0100 | [diff] [blame] | 923 | |
| 924 | if (chip->mgr->board_aes_in_192k) { |
| 925 | temp = (unsigned char)rmh.stat[1]; |
| 926 | } else { |
| 927 | temp = 0; |
| 928 | /* reversed bit order (not with CS8416_01_CS) */ |
| 929 | for (i = 0; i < 8; i++) { |
| 930 | temp <<= 1; |
| 931 | if (rmh.stat[1] & (1 << i)) |
| 932 | temp |= 1; |
| 933 | } |
Markus Bollinger | e12229b | 2005-12-06 13:55:26 +0100 | [diff] [blame] | 934 | } |
Takashi Iwai | b59bb8e | 2014-02-26 11:47:55 +0100 | [diff] [blame^] | 935 | dev_dbg(chip->card->dev, "read iec958 AES %d byte %d = 0x%x\n", |
Markus Bollinger | c0193f3 | 2008-11-25 12:37:52 +0100 | [diff] [blame] | 936 | chip->chip_idx, aes_idx, temp); |
Markus Bollinger | e12229b | 2005-12-06 13:55:26 +0100 | [diff] [blame] | 937 | *aes_bits = temp; |
| 938 | return 0; |
| 939 | } |
| 940 | |
Markus Bollinger | c0193f3 | 2008-11-25 12:37:52 +0100 | [diff] [blame] | 941 | static int pcxhr_iec958_get(struct snd_kcontrol *kcontrol, |
| 942 | struct snd_ctl_elem_value *ucontrol) |
Markus Bollinger | e12229b | 2005-12-06 13:55:26 +0100 | [diff] [blame] | 943 | { |
| 944 | struct snd_pcxhr *chip = snd_kcontrol_chip(kcontrol); |
| 945 | unsigned char aes_bits; |
| 946 | int i, err; |
| 947 | |
Ingo Molnar | 62932df | 2006-01-16 16:34:20 +0100 | [diff] [blame] | 948 | mutex_lock(&chip->mgr->mixer_mutex); |
Markus Bollinger | e12229b | 2005-12-06 13:55:26 +0100 | [diff] [blame] | 949 | for(i = 0; i < 5; i++) { |
| 950 | if (kcontrol->private_value == 0) /* playback */ |
| 951 | aes_bits = chip->aes_bits[i]; |
| 952 | else { /* capture */ |
Markus Bollinger | c0193f3 | 2008-11-25 12:37:52 +0100 | [diff] [blame] | 953 | if (chip->mgr->is_hr_stereo) |
| 954 | err = hr222_iec958_capture_byte(chip, i, |
| 955 | &aes_bits); |
| 956 | else |
| 957 | err = pcxhr_iec958_capture_byte(chip, i, |
| 958 | &aes_bits); |
Markus Bollinger | e12229b | 2005-12-06 13:55:26 +0100 | [diff] [blame] | 959 | if (err) |
| 960 | break; |
| 961 | } |
| 962 | ucontrol->value.iec958.status[i] = aes_bits; |
| 963 | } |
Ingo Molnar | 62932df | 2006-01-16 16:34:20 +0100 | [diff] [blame] | 964 | mutex_unlock(&chip->mgr->mixer_mutex); |
Markus Bollinger | e12229b | 2005-12-06 13:55:26 +0100 | [diff] [blame] | 965 | return 0; |
| 966 | } |
| 967 | |
| 968 | static int pcxhr_iec958_mask_get(struct snd_kcontrol *kcontrol, |
| 969 | struct snd_ctl_elem_value *ucontrol) |
| 970 | { |
| 971 | int i; |
| 972 | for (i = 0; i < 5; i++) |
| 973 | ucontrol->value.iec958.status[i] = 0xff; |
| 974 | return 0; |
| 975 | } |
| 976 | |
Markus Bollinger | c0193f3 | 2008-11-25 12:37:52 +0100 | [diff] [blame] | 977 | static int pcxhr_iec958_update_byte(struct snd_pcxhr *chip, |
| 978 | int aes_idx, unsigned char aes_bits) |
Markus Bollinger | e12229b | 2005-12-06 13:55:26 +0100 | [diff] [blame] | 979 | { |
| 980 | int i, err, cmd; |
| 981 | unsigned char new_bits = aes_bits; |
| 982 | unsigned char old_bits = chip->aes_bits[aes_idx]; |
| 983 | struct pcxhr_rmh rmh; |
| 984 | |
| 985 | for (i = 0; i < 8; i++) { |
| 986 | if ((old_bits & 0x01) != (new_bits & 0x01)) { |
Markus Bollinger | c0193f3 | 2008-11-25 12:37:52 +0100 | [diff] [blame] | 987 | cmd = chip->chip_idx & 0x03; /* chip index 0..3 */ |
| 988 | if (chip->chip_idx > 3) |
Markus Bollinger | e12229b | 2005-12-06 13:55:26 +0100 | [diff] [blame] | 989 | /* new bit used if chip_idx>3 (PCX1222HR) */ |
| 990 | cmd |= 1 << 22; |
Markus Bollinger | c0193f3 | 2008-11-25 12:37:52 +0100 | [diff] [blame] | 991 | cmd |= ((aes_idx << 3) + i) << 2; /* add bit offset */ |
| 992 | cmd |= (new_bits & 0x01) << 23; /* add bit value */ |
Markus Bollinger | e12229b | 2005-12-06 13:55:26 +0100 | [diff] [blame] | 993 | pcxhr_init_rmh(&rmh, CMD_ACCESS_IO_WRITE); |
| 994 | rmh.cmd[0] |= IO_NUM_REG_CUER; |
| 995 | rmh.cmd[1] = cmd; |
| 996 | rmh.cmd_len = 2; |
Takashi Iwai | b59bb8e | 2014-02-26 11:47:55 +0100 | [diff] [blame^] | 997 | dev_dbg(chip->card->dev, |
| 998 | "write iec958 AES %d byte %d bit %d (cmd %x)\n", |
Markus Bollinger | e12229b | 2005-12-06 13:55:26 +0100 | [diff] [blame] | 999 | chip->chip_idx, aes_idx, i, cmd); |
| 1000 | err = pcxhr_send_msg(chip->mgr, &rmh); |
| 1001 | if (err) |
| 1002 | return err; |
| 1003 | } |
| 1004 | old_bits >>= 1; |
| 1005 | new_bits >>= 1; |
| 1006 | } |
| 1007 | chip->aes_bits[aes_idx] = aes_bits; |
| 1008 | return 0; |
| 1009 | } |
| 1010 | |
| 1011 | static int pcxhr_iec958_put(struct snd_kcontrol *kcontrol, |
| 1012 | struct snd_ctl_elem_value *ucontrol) |
| 1013 | { |
| 1014 | struct snd_pcxhr *chip = snd_kcontrol_chip(kcontrol); |
| 1015 | int i, changed = 0; |
| 1016 | |
| 1017 | /* playback */ |
Ingo Molnar | 62932df | 2006-01-16 16:34:20 +0100 | [diff] [blame] | 1018 | mutex_lock(&chip->mgr->mixer_mutex); |
Markus Bollinger | e12229b | 2005-12-06 13:55:26 +0100 | [diff] [blame] | 1019 | for (i = 0; i < 5; i++) { |
| 1020 | if (ucontrol->value.iec958.status[i] != chip->aes_bits[i]) { |
Markus Bollinger | c0193f3 | 2008-11-25 12:37:52 +0100 | [diff] [blame] | 1021 | if (chip->mgr->is_hr_stereo) |
| 1022 | hr222_iec958_update_byte(chip, i, |
| 1023 | ucontrol->value.iec958.status[i]); |
| 1024 | else |
| 1025 | pcxhr_iec958_update_byte(chip, i, |
| 1026 | ucontrol->value.iec958.status[i]); |
Markus Bollinger | e12229b | 2005-12-06 13:55:26 +0100 | [diff] [blame] | 1027 | changed = 1; |
| 1028 | } |
| 1029 | } |
Ingo Molnar | 62932df | 2006-01-16 16:34:20 +0100 | [diff] [blame] | 1030 | mutex_unlock(&chip->mgr->mixer_mutex); |
Markus Bollinger | e12229b | 2005-12-06 13:55:26 +0100 | [diff] [blame] | 1031 | return changed; |
| 1032 | } |
| 1033 | |
| 1034 | static struct snd_kcontrol_new pcxhr_control_playback_iec958_mask = { |
| 1035 | .access = SNDRV_CTL_ELEM_ACCESS_READ, |
| 1036 | .iface = SNDRV_CTL_ELEM_IFACE_PCM, |
| 1037 | .name = SNDRV_CTL_NAME_IEC958("",PLAYBACK,MASK), |
| 1038 | .info = pcxhr_iec958_info, |
| 1039 | .get = pcxhr_iec958_mask_get |
| 1040 | }; |
| 1041 | static struct snd_kcontrol_new pcxhr_control_playback_iec958 = { |
| 1042 | .iface = SNDRV_CTL_ELEM_IFACE_PCM, |
| 1043 | .name = SNDRV_CTL_NAME_IEC958("",PLAYBACK,DEFAULT), |
| 1044 | .info = pcxhr_iec958_info, |
| 1045 | .get = pcxhr_iec958_get, |
| 1046 | .put = pcxhr_iec958_put, |
| 1047 | .private_value = 0 /* playback */ |
| 1048 | }; |
| 1049 | |
| 1050 | static struct snd_kcontrol_new pcxhr_control_capture_iec958_mask = { |
| 1051 | .access = SNDRV_CTL_ELEM_ACCESS_READ, |
| 1052 | .iface = SNDRV_CTL_ELEM_IFACE_PCM, |
| 1053 | .name = SNDRV_CTL_NAME_IEC958("",CAPTURE,MASK), |
| 1054 | .info = pcxhr_iec958_info, |
| 1055 | .get = pcxhr_iec958_mask_get |
| 1056 | }; |
| 1057 | static struct snd_kcontrol_new pcxhr_control_capture_iec958 = { |
| 1058 | .access = SNDRV_CTL_ELEM_ACCESS_READ, |
| 1059 | .iface = SNDRV_CTL_ELEM_IFACE_PCM, |
| 1060 | .name = SNDRV_CTL_NAME_IEC958("",CAPTURE,DEFAULT), |
| 1061 | .info = pcxhr_iec958_info, |
| 1062 | .get = pcxhr_iec958_get, |
| 1063 | .private_value = 1 /* capture */ |
| 1064 | }; |
| 1065 | |
| 1066 | static void pcxhr_init_audio_levels(struct snd_pcxhr *chip) |
| 1067 | { |
| 1068 | int i; |
| 1069 | |
| 1070 | for (i = 0; i < 2; i++) { |
| 1071 | if (chip->nb_streams_play) { |
| 1072 | int j; |
| 1073 | /* at boot time the digital volumes are unmuted 0dB */ |
| 1074 | for (j = 0; j < PCXHR_PLAYBACK_STREAMS; j++) { |
| 1075 | chip->digital_playback_active[j][i] = 1; |
Markus Bollinger | c0193f3 | 2008-11-25 12:37:52 +0100 | [diff] [blame] | 1076 | chip->digital_playback_volume[j][i] = |
| 1077 | PCXHR_DIGITAL_ZERO_LEVEL; |
Markus Bollinger | e12229b | 2005-12-06 13:55:26 +0100 | [diff] [blame] | 1078 | } |
Markus Bollinger | c0193f3 | 2008-11-25 12:37:52 +0100 | [diff] [blame] | 1079 | /* after boot, only two bits are set on the uer |
| 1080 | * interface |
| 1081 | */ |
| 1082 | chip->aes_bits[0] = (IEC958_AES0_PROFESSIONAL | |
| 1083 | IEC958_AES0_PRO_FS_48000); |
Markus Bollinger | e12229b | 2005-12-06 13:55:26 +0100 | [diff] [blame] | 1084 | #ifdef CONFIG_SND_DEBUG |
Markus Bollinger | c0193f3 | 2008-11-25 12:37:52 +0100 | [diff] [blame] | 1085 | /* analog volumes for playback |
| 1086 | * (is LEVEL_MIN after boot) |
| 1087 | */ |
Markus Bollinger | e12229b | 2005-12-06 13:55:26 +0100 | [diff] [blame] | 1088 | chip->analog_playback_active[i] = 1; |
Markus Bollinger | c0193f3 | 2008-11-25 12:37:52 +0100 | [diff] [blame] | 1089 | if (chip->mgr->is_hr_stereo) |
| 1090 | chip->analog_playback_volume[i] = |
| 1091 | HR222_LINE_PLAYBACK_ZERO_LEVEL; |
| 1092 | else { |
| 1093 | chip->analog_playback_volume[i] = |
| 1094 | PCXHR_LINE_PLAYBACK_ZERO_LEVEL; |
| 1095 | pcxhr_update_analog_audio_level(chip, 0, i); |
| 1096 | } |
Markus Bollinger | e12229b | 2005-12-06 13:55:26 +0100 | [diff] [blame] | 1097 | #endif |
Markus Bollinger | c0193f3 | 2008-11-25 12:37:52 +0100 | [diff] [blame] | 1098 | /* stereo cards need to be initialised after boot */ |
| 1099 | if (chip->mgr->is_hr_stereo) |
| 1100 | hr222_update_analog_audio_level(chip, 0, i); |
Markus Bollinger | e12229b | 2005-12-06 13:55:26 +0100 | [diff] [blame] | 1101 | } |
| 1102 | if (chip->nb_streams_capt) { |
| 1103 | /* at boot time the digital volumes are unmuted 0dB */ |
Markus Bollinger | c0193f3 | 2008-11-25 12:37:52 +0100 | [diff] [blame] | 1104 | chip->digital_capture_volume[i] = |
| 1105 | PCXHR_DIGITAL_ZERO_LEVEL; |
| 1106 | chip->analog_capture_active = 1; |
Markus Bollinger | e12229b | 2005-12-06 13:55:26 +0100 | [diff] [blame] | 1107 | #ifdef CONFIG_SND_DEBUG |
Markus Bollinger | c0193f3 | 2008-11-25 12:37:52 +0100 | [diff] [blame] | 1108 | /* analog volumes for playback |
| 1109 | * (is LEVEL_MIN after boot) |
| 1110 | */ |
| 1111 | if (chip->mgr->is_hr_stereo) |
| 1112 | chip->analog_capture_volume[i] = |
| 1113 | HR222_LINE_CAPTURE_ZERO_LEVEL; |
| 1114 | else { |
| 1115 | chip->analog_capture_volume[i] = |
| 1116 | PCXHR_LINE_CAPTURE_ZERO_LEVEL; |
| 1117 | pcxhr_update_analog_audio_level(chip, 1, i); |
| 1118 | } |
Markus Bollinger | e12229b | 2005-12-06 13:55:26 +0100 | [diff] [blame] | 1119 | #endif |
Markus Bollinger | c0193f3 | 2008-11-25 12:37:52 +0100 | [diff] [blame] | 1120 | /* stereo cards need to be initialised after boot */ |
| 1121 | if (chip->mgr->is_hr_stereo) |
| 1122 | hr222_update_analog_audio_level(chip, 1, i); |
Markus Bollinger | e12229b | 2005-12-06 13:55:26 +0100 | [diff] [blame] | 1123 | } |
| 1124 | } |
| 1125 | |
| 1126 | return; |
| 1127 | } |
| 1128 | |
| 1129 | |
| 1130 | int pcxhr_create_mixer(struct pcxhr_mgr *mgr) |
| 1131 | { |
| 1132 | struct snd_pcxhr *chip; |
| 1133 | int err, i; |
| 1134 | |
Ingo Molnar | 62932df | 2006-01-16 16:34:20 +0100 | [diff] [blame] | 1135 | mutex_init(&mgr->mixer_mutex); /* can be in another place */ |
Markus Bollinger | e12229b | 2005-12-06 13:55:26 +0100 | [diff] [blame] | 1136 | |
| 1137 | for (i = 0; i < mgr->num_cards; i++) { |
| 1138 | struct snd_kcontrol_new temp; |
| 1139 | chip = mgr->chip[i]; |
| 1140 | |
| 1141 | if (chip->nb_streams_play) { |
| 1142 | /* analog output level control */ |
| 1143 | temp = pcxhr_control_analog_level; |
| 1144 | temp.name = "Master Playback Volume"; |
| 1145 | temp.private_value = 0; /* playback */ |
Markus Bollinger | c0193f3 | 2008-11-25 12:37:52 +0100 | [diff] [blame] | 1146 | if (mgr->is_hr_stereo) |
| 1147 | temp.tlv.p = db_scale_a_hr222_playback; |
| 1148 | else |
| 1149 | temp.tlv.p = db_scale_analog_playback; |
| 1150 | err = snd_ctl_add(chip->card, |
| 1151 | snd_ctl_new1(&temp, chip)); |
| 1152 | if (err < 0) |
Markus Bollinger | e12229b | 2005-12-06 13:55:26 +0100 | [diff] [blame] | 1153 | return err; |
Markus Bollinger | c0193f3 | 2008-11-25 12:37:52 +0100 | [diff] [blame] | 1154 | |
Markus Bollinger | e12229b | 2005-12-06 13:55:26 +0100 | [diff] [blame] | 1155 | /* output mute controls */ |
Markus Bollinger | c0193f3 | 2008-11-25 12:37:52 +0100 | [diff] [blame] | 1156 | err = snd_ctl_add(chip->card, |
| 1157 | snd_ctl_new1(&pcxhr_control_output_switch, |
| 1158 | chip)); |
| 1159 | if (err < 0) |
Markus Bollinger | e12229b | 2005-12-06 13:55:26 +0100 | [diff] [blame] | 1160 | return err; |
Markus Bollinger | c0193f3 | 2008-11-25 12:37:52 +0100 | [diff] [blame] | 1161 | |
Markus Bollinger | e12229b | 2005-12-06 13:55:26 +0100 | [diff] [blame] | 1162 | temp = snd_pcxhr_pcm_vol; |
| 1163 | temp.name = "PCM Playback Volume"; |
| 1164 | temp.count = PCXHR_PLAYBACK_STREAMS; |
| 1165 | temp.private_value = 0; /* playback */ |
Markus Bollinger | c0193f3 | 2008-11-25 12:37:52 +0100 | [diff] [blame] | 1166 | err = snd_ctl_add(chip->card, |
| 1167 | snd_ctl_new1(&temp, chip)); |
| 1168 | if (err < 0) |
Markus Bollinger | e12229b | 2005-12-06 13:55:26 +0100 | [diff] [blame] | 1169 | return err; |
| 1170 | |
Markus Bollinger | c0193f3 | 2008-11-25 12:37:52 +0100 | [diff] [blame] | 1171 | err = snd_ctl_add(chip->card, |
| 1172 | snd_ctl_new1(&pcxhr_control_pcm_switch, chip)); |
| 1173 | if (err < 0) |
Markus Bollinger | e12229b | 2005-12-06 13:55:26 +0100 | [diff] [blame] | 1174 | return err; |
| 1175 | |
| 1176 | /* IEC958 controls */ |
Markus Bollinger | c0193f3 | 2008-11-25 12:37:52 +0100 | [diff] [blame] | 1177 | err = snd_ctl_add(chip->card, |
| 1178 | snd_ctl_new1(&pcxhr_control_playback_iec958_mask, |
| 1179 | chip)); |
| 1180 | if (err < 0) |
Markus Bollinger | e12229b | 2005-12-06 13:55:26 +0100 | [diff] [blame] | 1181 | return err; |
Markus Bollinger | c0193f3 | 2008-11-25 12:37:52 +0100 | [diff] [blame] | 1182 | |
| 1183 | err = snd_ctl_add(chip->card, |
| 1184 | snd_ctl_new1(&pcxhr_control_playback_iec958, |
| 1185 | chip)); |
| 1186 | if (err < 0) |
Markus Bollinger | e12229b | 2005-12-06 13:55:26 +0100 | [diff] [blame] | 1187 | return err; |
| 1188 | } |
| 1189 | if (chip->nb_streams_capt) { |
Markus Bollinger | c0193f3 | 2008-11-25 12:37:52 +0100 | [diff] [blame] | 1190 | /* analog input level control */ |
Markus Bollinger | e12229b | 2005-12-06 13:55:26 +0100 | [diff] [blame] | 1191 | temp = pcxhr_control_analog_level; |
Markus Bollinger | c0193f3 | 2008-11-25 12:37:52 +0100 | [diff] [blame] | 1192 | temp.name = "Line Capture Volume"; |
Markus Bollinger | e12229b | 2005-12-06 13:55:26 +0100 | [diff] [blame] | 1193 | temp.private_value = 1; /* capture */ |
Markus Bollinger | c0193f3 | 2008-11-25 12:37:52 +0100 | [diff] [blame] | 1194 | if (mgr->is_hr_stereo) |
| 1195 | temp.tlv.p = db_scale_a_hr222_capture; |
| 1196 | else |
| 1197 | temp.tlv.p = db_scale_analog_capture; |
| 1198 | |
| 1199 | err = snd_ctl_add(chip->card, |
| 1200 | snd_ctl_new1(&temp, chip)); |
| 1201 | if (err < 0) |
Markus Bollinger | e12229b | 2005-12-06 13:55:26 +0100 | [diff] [blame] | 1202 | return err; |
| 1203 | |
| 1204 | temp = snd_pcxhr_pcm_vol; |
| 1205 | temp.name = "PCM Capture Volume"; |
| 1206 | temp.count = 1; |
| 1207 | temp.private_value = 1; /* capture */ |
Markus Bollinger | c0193f3 | 2008-11-25 12:37:52 +0100 | [diff] [blame] | 1208 | |
| 1209 | err = snd_ctl_add(chip->card, |
| 1210 | snd_ctl_new1(&temp, chip)); |
| 1211 | if (err < 0) |
Markus Bollinger | e12229b | 2005-12-06 13:55:26 +0100 | [diff] [blame] | 1212 | return err; |
Markus Bollinger | c0193f3 | 2008-11-25 12:37:52 +0100 | [diff] [blame] | 1213 | |
Markus Bollinger | e12229b | 2005-12-06 13:55:26 +0100 | [diff] [blame] | 1214 | /* Audio source */ |
Markus Bollinger | c0193f3 | 2008-11-25 12:37:52 +0100 | [diff] [blame] | 1215 | err = snd_ctl_add(chip->card, |
| 1216 | snd_ctl_new1(&pcxhr_control_audio_src, chip)); |
| 1217 | if (err < 0) |
Markus Bollinger | e12229b | 2005-12-06 13:55:26 +0100 | [diff] [blame] | 1218 | return err; |
Markus Bollinger | c0193f3 | 2008-11-25 12:37:52 +0100 | [diff] [blame] | 1219 | |
Markus Bollinger | e12229b | 2005-12-06 13:55:26 +0100 | [diff] [blame] | 1220 | /* IEC958 controls */ |
Markus Bollinger | c0193f3 | 2008-11-25 12:37:52 +0100 | [diff] [blame] | 1221 | err = snd_ctl_add(chip->card, |
| 1222 | snd_ctl_new1(&pcxhr_control_capture_iec958_mask, |
| 1223 | chip)); |
| 1224 | if (err < 0) |
Markus Bollinger | e12229b | 2005-12-06 13:55:26 +0100 | [diff] [blame] | 1225 | return err; |
Markus Bollinger | c0193f3 | 2008-11-25 12:37:52 +0100 | [diff] [blame] | 1226 | |
| 1227 | err = snd_ctl_add(chip->card, |
| 1228 | snd_ctl_new1(&pcxhr_control_capture_iec958, |
| 1229 | chip)); |
| 1230 | if (err < 0) |
Markus Bollinger | e12229b | 2005-12-06 13:55:26 +0100 | [diff] [blame] | 1231 | return err; |
Markus Bollinger | c0193f3 | 2008-11-25 12:37:52 +0100 | [diff] [blame] | 1232 | |
| 1233 | if (mgr->is_hr_stereo) { |
| 1234 | err = hr222_add_mic_controls(chip); |
| 1235 | if (err < 0) |
| 1236 | return err; |
| 1237 | } |
Markus Bollinger | e12229b | 2005-12-06 13:55:26 +0100 | [diff] [blame] | 1238 | } |
| 1239 | /* monitoring only if playback and capture device available */ |
| 1240 | if (chip->nb_streams_capt > 0 && chip->nb_streams_play > 0) { |
| 1241 | /* monitoring */ |
Markus Bollinger | c0193f3 | 2008-11-25 12:37:52 +0100 | [diff] [blame] | 1242 | err = snd_ctl_add(chip->card, |
| 1243 | snd_ctl_new1(&pcxhr_control_monitor_vol, chip)); |
| 1244 | if (err < 0) |
Markus Bollinger | e12229b | 2005-12-06 13:55:26 +0100 | [diff] [blame] | 1245 | return err; |
Markus Bollinger | c0193f3 | 2008-11-25 12:37:52 +0100 | [diff] [blame] | 1246 | |
| 1247 | err = snd_ctl_add(chip->card, |
| 1248 | snd_ctl_new1(&pcxhr_control_monitor_sw, chip)); |
| 1249 | if (err < 0) |
Markus Bollinger | e12229b | 2005-12-06 13:55:26 +0100 | [diff] [blame] | 1250 | return err; |
| 1251 | } |
| 1252 | |
| 1253 | if (i == 0) { |
| 1254 | /* clock mode only one control per pcxhr */ |
Markus Bollinger | c0193f3 | 2008-11-25 12:37:52 +0100 | [diff] [blame] | 1255 | err = snd_ctl_add(chip->card, |
| 1256 | snd_ctl_new1(&pcxhr_control_clock_type, mgr)); |
| 1257 | if (err < 0) |
Markus Bollinger | e12229b | 2005-12-06 13:55:26 +0100 | [diff] [blame] | 1258 | return err; |
Markus Bollinger | c0193f3 | 2008-11-25 12:37:52 +0100 | [diff] [blame] | 1259 | /* non standard control used to scan |
| 1260 | * the external clock presence/frequencies |
| 1261 | */ |
| 1262 | err = snd_ctl_add(chip->card, |
| 1263 | snd_ctl_new1(&pcxhr_control_clock_rate, mgr)); |
| 1264 | if (err < 0) |
Markus Bollinger | e12229b | 2005-12-06 13:55:26 +0100 | [diff] [blame] | 1265 | return err; |
| 1266 | } |
| 1267 | |
| 1268 | /* init values for the mixer data */ |
| 1269 | pcxhr_init_audio_levels(chip); |
| 1270 | } |
| 1271 | |
| 1272 | return 0; |
| 1273 | } |