Clement Guedez | f6cdab5 | 2007-01-08 10:48:41 +0100 | [diff] [blame] | 1 | /* |
| 2 | * ALSA driver for ICEnsemble VT1724 (Envy24HT) |
Alexander Beregalov | f14d8e9 | 2008-09-07 01:54:27 +0400 | [diff] [blame] | 3 | * |
Clement Guedez | f6cdab5 | 2007-01-08 10:48:41 +0100 | [diff] [blame] | 4 | * Lowlevel functions for Ego Sys Waveterminal 192M |
| 5 | * |
| 6 | * Copyright (c) 2006 Guedez Clement <klem.dev@gmail.com> |
| 7 | * Some functions are taken from the Prodigy192 driver |
| 8 | * source |
Alexander Beregalov | f14d8e9 | 2008-09-07 01:54:27 +0400 | [diff] [blame] | 9 | * |
Clement Guedez | f6cdab5 | 2007-01-08 10:48:41 +0100 | [diff] [blame] | 10 | * This program is free software; you can redistribute it and/or modify |
| 11 | * it under the terms of the GNU General Public License as published by |
| 12 | * the Free Software Foundation; either version 2 of the License, or |
| 13 | * (at your option) any later version. |
| 14 | * |
| 15 | * This program is distributed in the hope that it will be useful, |
| 16 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 17 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 18 | * GNU General Public License for more details. |
| 19 | * |
| 20 | * You should have received a copy of the GNU General Public License |
| 21 | * along with this program; if not, write to the Free Software |
| 22 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
Alexander Beregalov | f14d8e9 | 2008-09-07 01:54:27 +0400 | [diff] [blame] | 23 | * |
| 24 | */ |
Clement Guedez | f6cdab5 | 2007-01-08 10:48:41 +0100 | [diff] [blame] | 25 | |
| 26 | |
| 27 | |
Clement Guedez | f6cdab5 | 2007-01-08 10:48:41 +0100 | [diff] [blame] | 28 | #include <linux/delay.h> |
| 29 | #include <linux/interrupt.h> |
| 30 | #include <linux/init.h> |
Clement Guedez | f6cdab5 | 2007-01-08 10:48:41 +0100 | [diff] [blame] | 31 | #include <sound/core.h> |
Clément Guedez | 16ddbe7 | 2015-03-18 02:26:29 +0100 | [diff] [blame] | 32 | #include <sound/tlv.h> |
Clément Guedez | 1aa9a4e | 2015-03-18 02:26:31 +0100 | [diff] [blame] | 33 | #include <linux/slab.h> |
Clement Guedez | f6cdab5 | 2007-01-08 10:48:41 +0100 | [diff] [blame] | 34 | |
| 35 | #include "ice1712.h" |
| 36 | #include "envy24ht.h" |
| 37 | #include "wtm.h" |
| 38 | #include "stac946x.h" |
| 39 | |
Clément Guedez | 1aa9a4e | 2015-03-18 02:26:31 +0100 | [diff] [blame] | 40 | struct wtm_spec { |
| 41 | /* rate change needs atomic mute/unmute of all dacs*/ |
| 42 | struct mutex mute_mutex; |
| 43 | }; |
| 44 | |
Clement Guedez | f6cdab5 | 2007-01-08 10:48:41 +0100 | [diff] [blame] | 45 | |
| 46 | /* |
Alexander Beregalov | f14d8e9 | 2008-09-07 01:54:27 +0400 | [diff] [blame] | 47 | * 2*ADC 6*DAC no1 ringbuffer r/w on i2c bus |
Clement Guedez | f6cdab5 | 2007-01-08 10:48:41 +0100 | [diff] [blame] | 48 | */ |
Alexander Beregalov | f14d8e9 | 2008-09-07 01:54:27 +0400 | [diff] [blame] | 49 | static inline void stac9460_put(struct snd_ice1712 *ice, int reg, |
Clement Guedez | f6cdab5 | 2007-01-08 10:48:41 +0100 | [diff] [blame] | 50 | unsigned char val) |
| 51 | { |
| 52 | snd_vt1724_write_i2c(ice, STAC9460_I2C_ADDR, reg, val); |
| 53 | } |
| 54 | |
| 55 | static inline unsigned char stac9460_get(struct snd_ice1712 *ice, int reg) |
| 56 | { |
| 57 | return snd_vt1724_read_i2c(ice, STAC9460_I2C_ADDR, reg); |
| 58 | } |
| 59 | |
| 60 | /* |
| 61 | * 2*ADC 2*DAC no2 ringbuffer r/w on i2c bus |
| 62 | */ |
| 63 | static inline void stac9460_2_put(struct snd_ice1712 *ice, int reg, |
| 64 | unsigned char val) |
| 65 | { |
| 66 | snd_vt1724_write_i2c(ice, STAC9460_2_I2C_ADDR, reg, val); |
| 67 | } |
| 68 | |
| 69 | static inline unsigned char stac9460_2_get(struct snd_ice1712 *ice, int reg) |
| 70 | { |
| 71 | return snd_vt1724_read_i2c(ice, STAC9460_2_I2C_ADDR, reg); |
| 72 | } |
| 73 | |
| 74 | |
| 75 | /* |
| 76 | * DAC mute control |
| 77 | */ |
Clément Guedez | 1aa9a4e | 2015-03-18 02:26:31 +0100 | [diff] [blame] | 78 | static void stac9460_dac_mute_all(struct snd_ice1712 *ice, unsigned char mute, |
| 79 | unsigned short int *change_mask) |
| 80 | { |
| 81 | unsigned char new, old; |
| 82 | int id, idx, change; |
| 83 | |
| 84 | /*stac9460 1*/ |
| 85 | for (id = 0; id < 7; id++) { |
| 86 | if (*change_mask & (0x01 << id)) { |
| 87 | if (id == 0) |
| 88 | idx = STAC946X_MASTER_VOLUME; |
| 89 | else |
| 90 | idx = STAC946X_LF_VOLUME - 1 + id; |
| 91 | old = stac9460_get(ice, idx); |
| 92 | new = (~mute << 7 & 0x80) | (old & ~0x80); |
| 93 | change = (new != old); |
| 94 | if (change) { |
| 95 | stac9460_put(ice, idx, new); |
| 96 | *change_mask = *change_mask | (0x01 << id); |
| 97 | } else { |
| 98 | *change_mask = *change_mask & ~(0x01 << id); |
| 99 | } |
| 100 | } |
| 101 | } |
| 102 | |
| 103 | /*stac9460 2*/ |
| 104 | for (id = 0; id < 3; id++) { |
| 105 | if (*change_mask & (0x01 << (id + 7))) { |
| 106 | if (id == 0) |
| 107 | idx = STAC946X_MASTER_VOLUME; |
| 108 | else |
| 109 | idx = STAC946X_LF_VOLUME - 1 + id; |
| 110 | old = stac9460_2_get(ice, idx); |
| 111 | new = (~mute << 7 & 0x80) | (old & ~0x80); |
| 112 | change = (new != old); |
| 113 | if (change) { |
| 114 | stac9460_2_put(ice, idx, new); |
| 115 | *change_mask = *change_mask | (0x01 << id); |
| 116 | } else { |
| 117 | *change_mask = *change_mask & ~(0x01 << id); |
| 118 | } |
| 119 | } |
| 120 | } |
| 121 | } |
| 122 | |
| 123 | |
| 124 | |
Takashi Iwai | a5ce889 | 2007-07-23 15:42:26 +0200 | [diff] [blame] | 125 | #define stac9460_dac_mute_info snd_ctl_boolean_mono_info |
Clement Guedez | f6cdab5 | 2007-01-08 10:48:41 +0100 | [diff] [blame] | 126 | |
| 127 | static int stac9460_dac_mute_get(struct snd_kcontrol *kcontrol, |
Alexander Beregalov | f14d8e9 | 2008-09-07 01:54:27 +0400 | [diff] [blame] | 128 | struct snd_ctl_elem_value *ucontrol) |
Clement Guedez | f6cdab5 | 2007-01-08 10:48:41 +0100 | [diff] [blame] | 129 | { |
| 130 | struct snd_ice1712 *ice = snd_kcontrol_chip(kcontrol); |
Clément Guedez | 1aa9a4e | 2015-03-18 02:26:31 +0100 | [diff] [blame] | 131 | struct wtm_spec *spec = ice->spec; |
Clement Guedez | f6cdab5 | 2007-01-08 10:48:41 +0100 | [diff] [blame] | 132 | unsigned char val; |
| 133 | int idx, id; |
| 134 | |
Clément Guedez | 1aa9a4e | 2015-03-18 02:26:31 +0100 | [diff] [blame] | 135 | mutex_lock(&spec->mute_mutex); |
| 136 | |
Clement Guedez | f6cdab5 | 2007-01-08 10:48:41 +0100 | [diff] [blame] | 137 | if (kcontrol->private_value) { |
| 138 | idx = STAC946X_MASTER_VOLUME; |
| 139 | id = 0; |
| 140 | } else { |
| 141 | id = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id); |
| 142 | idx = id + STAC946X_LF_VOLUME; |
| 143 | } |
| 144 | if (id < 6) |
| 145 | val = stac9460_get(ice, idx); |
Alexander Beregalov | f14d8e9 | 2008-09-07 01:54:27 +0400 | [diff] [blame] | 146 | else |
| 147 | val = stac9460_2_get(ice, idx - 6); |
Clement Guedez | f6cdab5 | 2007-01-08 10:48:41 +0100 | [diff] [blame] | 148 | ucontrol->value.integer.value[0] = (~val >> 7) & 0x1; |
Clément Guedez | 1aa9a4e | 2015-03-18 02:26:31 +0100 | [diff] [blame] | 149 | |
| 150 | mutex_unlock(&spec->mute_mutex); |
Clement Guedez | f6cdab5 | 2007-01-08 10:48:41 +0100 | [diff] [blame] | 151 | return 0; |
| 152 | } |
| 153 | |
| 154 | static int stac9460_dac_mute_put(struct snd_kcontrol *kcontrol, |
Alexander Beregalov | f14d8e9 | 2008-09-07 01:54:27 +0400 | [diff] [blame] | 155 | struct snd_ctl_elem_value *ucontrol) |
Clement Guedez | f6cdab5 | 2007-01-08 10:48:41 +0100 | [diff] [blame] | 156 | { |
| 157 | struct snd_ice1712 *ice = snd_kcontrol_chip(kcontrol); |
| 158 | unsigned char new, old; |
| 159 | int id, idx; |
| 160 | int change; |
| 161 | |
| 162 | if (kcontrol->private_value) { |
| 163 | idx = STAC946X_MASTER_VOLUME; |
| 164 | old = stac9460_get(ice, idx); |
Alexander Beregalov | f14d8e9 | 2008-09-07 01:54:27 +0400 | [diff] [blame] | 165 | new = (~ucontrol->value.integer.value[0] << 7 & 0x80) | |
| 166 | (old & ~0x80); |
Clement Guedez | f6cdab5 | 2007-01-08 10:48:41 +0100 | [diff] [blame] | 167 | change = (new != old); |
| 168 | if (change) { |
| 169 | stac9460_put(ice, idx, new); |
| 170 | stac9460_2_put(ice, idx, new); |
| 171 | } |
| 172 | } else { |
| 173 | id = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id); |
| 174 | idx = id + STAC946X_LF_VOLUME; |
| 175 | if (id < 6) |
| 176 | old = stac9460_get(ice, idx); |
Alexander Beregalov | f14d8e9 | 2008-09-07 01:54:27 +0400 | [diff] [blame] | 177 | else |
Clement Guedez | f6cdab5 | 2007-01-08 10:48:41 +0100 | [diff] [blame] | 178 | old = stac9460_2_get(ice, idx - 6); |
Alexander Beregalov | f14d8e9 | 2008-09-07 01:54:27 +0400 | [diff] [blame] | 179 | new = (~ucontrol->value.integer.value[0] << 7 & 0x80) | |
Clement Guedez | f6cdab5 | 2007-01-08 10:48:41 +0100 | [diff] [blame] | 180 | (old & ~0x80); |
| 181 | change = (new != old); |
| 182 | if (change) { |
| 183 | if (id < 6) |
Alexander Beregalov | f14d8e9 | 2008-09-07 01:54:27 +0400 | [diff] [blame] | 184 | stac9460_put(ice, idx, new); |
Clement Guedez | f6cdab5 | 2007-01-08 10:48:41 +0100 | [diff] [blame] | 185 | else |
Alexander Beregalov | f14d8e9 | 2008-09-07 01:54:27 +0400 | [diff] [blame] | 186 | stac9460_2_put(ice, idx - 6, new); |
Clement Guedez | f6cdab5 | 2007-01-08 10:48:41 +0100 | [diff] [blame] | 187 | } |
| 188 | } |
| 189 | return change; |
| 190 | } |
| 191 | |
| 192 | /* |
| 193 | * DAC volume attenuation mixer control |
| 194 | */ |
| 195 | static int stac9460_dac_vol_info(struct snd_kcontrol *kcontrol, |
Alexander Beregalov | f14d8e9 | 2008-09-07 01:54:27 +0400 | [diff] [blame] | 196 | struct snd_ctl_elem_info *uinfo) |
Clement Guedez | f6cdab5 | 2007-01-08 10:48:41 +0100 | [diff] [blame] | 197 | { |
| 198 | uinfo->type = SNDRV_CTL_ELEM_TYPE_INTEGER; |
| 199 | uinfo->count = 1; |
| 200 | uinfo->value.integer.min = 0; /* mute */ |
| 201 | uinfo->value.integer.max = 0x7f; /* 0dB */ |
| 202 | return 0; |
| 203 | } |
| 204 | |
| 205 | static int stac9460_dac_vol_get(struct snd_kcontrol *kcontrol, |
Alexander Beregalov | f14d8e9 | 2008-09-07 01:54:27 +0400 | [diff] [blame] | 206 | struct snd_ctl_elem_value *ucontrol) |
Clement Guedez | f6cdab5 | 2007-01-08 10:48:41 +0100 | [diff] [blame] | 207 | { |
| 208 | struct snd_ice1712 *ice = snd_kcontrol_chip(kcontrol); |
| 209 | int idx, id; |
| 210 | unsigned char vol; |
| 211 | |
| 212 | if (kcontrol->private_value) { |
| 213 | idx = STAC946X_MASTER_VOLUME; |
| 214 | id = 0; |
| 215 | } else { |
| 216 | id = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id); |
| 217 | idx = id + STAC946X_LF_VOLUME; |
| 218 | } |
| 219 | if (id < 6) |
| 220 | vol = stac9460_get(ice, idx) & 0x7f; |
Alexander Beregalov | f14d8e9 | 2008-09-07 01:54:27 +0400 | [diff] [blame] | 221 | else |
Clement Guedez | f6cdab5 | 2007-01-08 10:48:41 +0100 | [diff] [blame] | 222 | vol = stac9460_2_get(ice, idx - 6) & 0x7f; |
| 223 | ucontrol->value.integer.value[0] = 0x7f - vol; |
| 224 | return 0; |
| 225 | } |
| 226 | |
| 227 | static int stac9460_dac_vol_put(struct snd_kcontrol *kcontrol, |
Alexander Beregalov | f14d8e9 | 2008-09-07 01:54:27 +0400 | [diff] [blame] | 228 | struct snd_ctl_elem_value *ucontrol) |
Clement Guedez | f6cdab5 | 2007-01-08 10:48:41 +0100 | [diff] [blame] | 229 | { |
| 230 | struct snd_ice1712 *ice = snd_kcontrol_chip(kcontrol); |
| 231 | int idx, id; |
| 232 | unsigned char tmp, ovol, nvol; |
| 233 | int change; |
| 234 | |
| 235 | if (kcontrol->private_value) { |
| 236 | idx = STAC946X_MASTER_VOLUME; |
Takashi Iwai | 9cd17cd | 2007-11-15 15:56:07 +0100 | [diff] [blame] | 237 | nvol = ucontrol->value.integer.value[0] & 0x7f; |
Clement Guedez | f6cdab5 | 2007-01-08 10:48:41 +0100 | [diff] [blame] | 238 | tmp = stac9460_get(ice, idx); |
| 239 | ovol = 0x7f - (tmp & 0x7f); |
| 240 | change = (ovol != nvol); |
| 241 | if (change) { |
Alexander Beregalov | f14d8e9 | 2008-09-07 01:54:27 +0400 | [diff] [blame] | 242 | stac9460_put(ice, idx, (0x7f - nvol) | (tmp & 0x80)); |
| 243 | stac9460_2_put(ice, idx, (0x7f - nvol) | (tmp & 0x80)); |
Clement Guedez | f6cdab5 | 2007-01-08 10:48:41 +0100 | [diff] [blame] | 244 | } |
| 245 | } else { |
| 246 | id = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id); |
| 247 | idx = id + STAC946X_LF_VOLUME; |
Takashi Iwai | 9cd17cd | 2007-11-15 15:56:07 +0100 | [diff] [blame] | 248 | nvol = ucontrol->value.integer.value[0] & 0x7f; |
Clement Guedez | f6cdab5 | 2007-01-08 10:48:41 +0100 | [diff] [blame] | 249 | if (id < 6) |
| 250 | tmp = stac9460_get(ice, idx); |
Alexander Beregalov | f14d8e9 | 2008-09-07 01:54:27 +0400 | [diff] [blame] | 251 | else |
Clement Guedez | f6cdab5 | 2007-01-08 10:48:41 +0100 | [diff] [blame] | 252 | tmp = stac9460_2_get(ice, idx - 6); |
| 253 | ovol = 0x7f - (tmp & 0x7f); |
| 254 | change = (ovol != nvol); |
| 255 | if (change) { |
| 256 | if (id < 6) |
| 257 | stac9460_put(ice, idx, (0x7f - nvol) | |
Alexander Beregalov | f14d8e9 | 2008-09-07 01:54:27 +0400 | [diff] [blame] | 258 | (tmp & 0x80)); |
| 259 | else |
Clement Guedez | f6cdab5 | 2007-01-08 10:48:41 +0100 | [diff] [blame] | 260 | stac9460_2_put(ice, idx-6, (0x7f - nvol) | |
Alexander Beregalov | f14d8e9 | 2008-09-07 01:54:27 +0400 | [diff] [blame] | 261 | (tmp & 0x80)); |
Clement Guedez | f6cdab5 | 2007-01-08 10:48:41 +0100 | [diff] [blame] | 262 | } |
| 263 | } |
| 264 | return change; |
| 265 | } |
| 266 | |
| 267 | /* |
| 268 | * ADC mute control |
| 269 | */ |
Takashi Iwai | a5ce889 | 2007-07-23 15:42:26 +0200 | [diff] [blame] | 270 | #define stac9460_adc_mute_info snd_ctl_boolean_stereo_info |
Clement Guedez | f6cdab5 | 2007-01-08 10:48:41 +0100 | [diff] [blame] | 271 | |
| 272 | static int stac9460_adc_mute_get(struct snd_kcontrol *kcontrol, |
Alexander Beregalov | f14d8e9 | 2008-09-07 01:54:27 +0400 | [diff] [blame] | 273 | struct snd_ctl_elem_value *ucontrol) |
Clement Guedez | f6cdab5 | 2007-01-08 10:48:41 +0100 | [diff] [blame] | 274 | { |
| 275 | struct snd_ice1712 *ice = snd_kcontrol_chip(kcontrol); |
| 276 | unsigned char val; |
| 277 | int i, id; |
Alexander Beregalov | f14d8e9 | 2008-09-07 01:54:27 +0400 | [diff] [blame] | 278 | |
Clement Guedez | f6cdab5 | 2007-01-08 10:48:41 +0100 | [diff] [blame] | 279 | id = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id); |
| 280 | if (id == 0) { |
| 281 | for (i = 0; i < 2; ++i) { |
| 282 | val = stac9460_get(ice, STAC946X_MIC_L_VOLUME + i); |
| 283 | ucontrol->value.integer.value[i] = ~val>>7 & 0x1; |
| 284 | } |
| 285 | } else { |
| 286 | for (i = 0; i < 2; ++i) { |
| 287 | val = stac9460_2_get(ice, STAC946X_MIC_L_VOLUME + i); |
| 288 | ucontrol->value.integer.value[i] = ~val>>7 & 0x1; |
| 289 | } |
| 290 | } |
| 291 | return 0; |
| 292 | } |
| 293 | |
| 294 | static int stac9460_adc_mute_put(struct snd_kcontrol *kcontrol, |
Alexander Beregalov | f14d8e9 | 2008-09-07 01:54:27 +0400 | [diff] [blame] | 295 | struct snd_ctl_elem_value *ucontrol) |
Clement Guedez | f6cdab5 | 2007-01-08 10:48:41 +0100 | [diff] [blame] | 296 | { |
| 297 | struct snd_ice1712 *ice = snd_kcontrol_chip(kcontrol); |
| 298 | unsigned char new, old; |
| 299 | int i, reg, id; |
| 300 | int change; |
Alexander Beregalov | f14d8e9 | 2008-09-07 01:54:27 +0400 | [diff] [blame] | 301 | |
Clement Guedez | f6cdab5 | 2007-01-08 10:48:41 +0100 | [diff] [blame] | 302 | id = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id); |
| 303 | if (id == 0) { |
| 304 | for (i = 0; i < 2; ++i) { |
| 305 | reg = STAC946X_MIC_L_VOLUME + i; |
| 306 | old = stac9460_get(ice, reg); |
| 307 | new = (~ucontrol->value.integer.value[i]<<7&0x80) | |
Alexander Beregalov | f14d8e9 | 2008-09-07 01:54:27 +0400 | [diff] [blame] | 308 | (old&~0x80); |
Clement Guedez | f6cdab5 | 2007-01-08 10:48:41 +0100 | [diff] [blame] | 309 | change = (new != old); |
| 310 | if (change) |
| 311 | stac9460_put(ice, reg, new); |
| 312 | } |
| 313 | } else { |
| 314 | for (i = 0; i < 2; ++i) { |
| 315 | reg = STAC946X_MIC_L_VOLUME + i; |
| 316 | old = stac9460_2_get(ice, reg); |
| 317 | new = (~ucontrol->value.integer.value[i]<<7&0x80) | |
Alexander Beregalov | f14d8e9 | 2008-09-07 01:54:27 +0400 | [diff] [blame] | 318 | (old&~0x80); |
Clement Guedez | f6cdab5 | 2007-01-08 10:48:41 +0100 | [diff] [blame] | 319 | change = (new != old); |
| 320 | if (change) |
| 321 | stac9460_2_put(ice, reg, new); |
| 322 | } |
| 323 | } |
| 324 | return change; |
| 325 | } |
| 326 | |
| 327 | /* |
| 328 | *ADC gain mixer control |
| 329 | */ |
| 330 | static int stac9460_adc_vol_info(struct snd_kcontrol *kcontrol, |
Alexander Beregalov | f14d8e9 | 2008-09-07 01:54:27 +0400 | [diff] [blame] | 331 | struct snd_ctl_elem_info *uinfo) |
Clement Guedez | f6cdab5 | 2007-01-08 10:48:41 +0100 | [diff] [blame] | 332 | { |
| 333 | uinfo->type = SNDRV_CTL_ELEM_TYPE_INTEGER; |
| 334 | uinfo->count = 2; |
| 335 | uinfo->value.integer.min = 0; /* 0dB */ |
| 336 | uinfo->value.integer.max = 0x0f; /* 22.5dB */ |
| 337 | return 0; |
| 338 | } |
| 339 | |
| 340 | static int stac9460_adc_vol_get(struct snd_kcontrol *kcontrol, |
Alexander Beregalov | f14d8e9 | 2008-09-07 01:54:27 +0400 | [diff] [blame] | 341 | struct snd_ctl_elem_value *ucontrol) |
Clement Guedez | f6cdab5 | 2007-01-08 10:48:41 +0100 | [diff] [blame] | 342 | { |
| 343 | struct snd_ice1712 *ice = snd_kcontrol_chip(kcontrol); |
| 344 | int i, reg, id; |
| 345 | unsigned char vol; |
Alexander Beregalov | f14d8e9 | 2008-09-07 01:54:27 +0400 | [diff] [blame] | 346 | |
Clement Guedez | f6cdab5 | 2007-01-08 10:48:41 +0100 | [diff] [blame] | 347 | id = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id); |
| 348 | if (id == 0) { |
| 349 | for (i = 0; i < 2; ++i) { |
| 350 | reg = STAC946X_MIC_L_VOLUME + i; |
| 351 | vol = stac9460_get(ice, reg) & 0x0f; |
| 352 | ucontrol->value.integer.value[i] = 0x0f - vol; |
| 353 | } |
| 354 | } else { |
| 355 | for (i = 0; i < 2; ++i) { |
| 356 | reg = STAC946X_MIC_L_VOLUME + i; |
| 357 | vol = stac9460_2_get(ice, reg) & 0x0f; |
| 358 | ucontrol->value.integer.value[i] = 0x0f - vol; |
| 359 | } |
| 360 | } |
| 361 | return 0; |
| 362 | } |
| 363 | |
| 364 | static int stac9460_adc_vol_put(struct snd_kcontrol *kcontrol, |
Alexander Beregalov | f14d8e9 | 2008-09-07 01:54:27 +0400 | [diff] [blame] | 365 | struct snd_ctl_elem_value *ucontrol) |
Clement Guedez | f6cdab5 | 2007-01-08 10:48:41 +0100 | [diff] [blame] | 366 | { |
| 367 | struct snd_ice1712 *ice = snd_kcontrol_chip(kcontrol); |
| 368 | int i, reg, id; |
| 369 | unsigned char ovol, nvol; |
| 370 | int change; |
Alexander Beregalov | f14d8e9 | 2008-09-07 01:54:27 +0400 | [diff] [blame] | 371 | |
Clement Guedez | f6cdab5 | 2007-01-08 10:48:41 +0100 | [diff] [blame] | 372 | id = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id); |
| 373 | if (id == 0) { |
| 374 | for (i = 0; i < 2; ++i) { |
| 375 | reg = STAC946X_MIC_L_VOLUME + i; |
Takashi Iwai | 9cd17cd | 2007-11-15 15:56:07 +0100 | [diff] [blame] | 376 | nvol = ucontrol->value.integer.value[i] & 0x0f; |
Clement Guedez | f6cdab5 | 2007-01-08 10:48:41 +0100 | [diff] [blame] | 377 | ovol = 0x0f - stac9460_get(ice, reg); |
| 378 | change = ((ovol & 0x0f) != nvol); |
| 379 | if (change) |
| 380 | stac9460_put(ice, reg, (0x0f - nvol) | |
Alexander Beregalov | f14d8e9 | 2008-09-07 01:54:27 +0400 | [diff] [blame] | 381 | (ovol & ~0x0f)); |
Clement Guedez | f6cdab5 | 2007-01-08 10:48:41 +0100 | [diff] [blame] | 382 | } |
| 383 | } else { |
| 384 | for (i = 0; i < 2; ++i) { |
| 385 | reg = STAC946X_MIC_L_VOLUME + i; |
Takashi Iwai | 9cd17cd | 2007-11-15 15:56:07 +0100 | [diff] [blame] | 386 | nvol = ucontrol->value.integer.value[i] & 0x0f; |
Clement Guedez | f6cdab5 | 2007-01-08 10:48:41 +0100 | [diff] [blame] | 387 | ovol = 0x0f - stac9460_2_get(ice, reg); |
| 388 | change = ((ovol & 0x0f) != nvol); |
| 389 | if (change) |
| 390 | stac9460_2_put(ice, reg, (0x0f - nvol) | |
Alexander Beregalov | f14d8e9 | 2008-09-07 01:54:27 +0400 | [diff] [blame] | 391 | (ovol & ~0x0f)); |
Clement Guedez | f6cdab5 | 2007-01-08 10:48:41 +0100 | [diff] [blame] | 392 | } |
| 393 | } |
| 394 | return change; |
| 395 | } |
| 396 | |
| 397 | /* |
| 398 | * MIC / LINE switch fonction |
| 399 | */ |
Clément Guedez | ae8a9a1 | 2015-03-18 02:26:30 +0100 | [diff] [blame] | 400 | static int stac9460_mic_sw_info(struct snd_kcontrol *kcontrol, |
| 401 | struct snd_ctl_elem_info *uinfo) |
| 402 | { |
| 403 | static const char * const texts[2] = { "Line In", "Mic" }; |
Clement Guedez | f6cdab5 | 2007-01-08 10:48:41 +0100 | [diff] [blame] | 404 | |
Clément Guedez | ae8a9a1 | 2015-03-18 02:26:30 +0100 | [diff] [blame] | 405 | return snd_ctl_enum_info(uinfo, 1, 2, texts); |
| 406 | } |
| 407 | |
Clement Guedez | f6cdab5 | 2007-01-08 10:48:41 +0100 | [diff] [blame] | 408 | |
| 409 | static int stac9460_mic_sw_get(struct snd_kcontrol *kcontrol, |
Alexander Beregalov | f14d8e9 | 2008-09-07 01:54:27 +0400 | [diff] [blame] | 410 | struct snd_ctl_elem_value *ucontrol) |
Clement Guedez | f6cdab5 | 2007-01-08 10:48:41 +0100 | [diff] [blame] | 411 | { |
| 412 | struct snd_ice1712 *ice = snd_kcontrol_chip(kcontrol); |
| 413 | unsigned char val; |
| 414 | int id; |
Alexander Beregalov | f14d8e9 | 2008-09-07 01:54:27 +0400 | [diff] [blame] | 415 | |
Clement Guedez | f6cdab5 | 2007-01-08 10:48:41 +0100 | [diff] [blame] | 416 | id = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id); |
| 417 | if (id == 0) |
Alexander Beregalov | f14d8e9 | 2008-09-07 01:54:27 +0400 | [diff] [blame] | 418 | val = stac9460_get(ice, STAC946X_GENERAL_PURPOSE); |
Clement Guedez | f6cdab5 | 2007-01-08 10:48:41 +0100 | [diff] [blame] | 419 | else |
Alexander Beregalov | f14d8e9 | 2008-09-07 01:54:27 +0400 | [diff] [blame] | 420 | val = stac9460_2_get(ice, STAC946X_GENERAL_PURPOSE); |
Clément Guedez | ae8a9a1 | 2015-03-18 02:26:30 +0100 | [diff] [blame] | 421 | ucontrol->value.enumerated.item[0] = (val >> 7) & 0x1; |
Clement Guedez | f6cdab5 | 2007-01-08 10:48:41 +0100 | [diff] [blame] | 422 | return 0; |
| 423 | } |
| 424 | |
| 425 | static int stac9460_mic_sw_put(struct snd_kcontrol *kcontrol, |
Alexander Beregalov | f14d8e9 | 2008-09-07 01:54:27 +0400 | [diff] [blame] | 426 | struct snd_ctl_elem_value *ucontrol) |
Clement Guedez | f6cdab5 | 2007-01-08 10:48:41 +0100 | [diff] [blame] | 427 | { |
| 428 | struct snd_ice1712 *ice = snd_kcontrol_chip(kcontrol); |
| 429 | unsigned char new, old; |
| 430 | int change, id; |
| 431 | |
| 432 | id = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id); |
| 433 | if (id == 0) |
Alexander Beregalov | f14d8e9 | 2008-09-07 01:54:27 +0400 | [diff] [blame] | 434 | old = stac9460_get(ice, STAC946X_GENERAL_PURPOSE); |
Clement Guedez | f6cdab5 | 2007-01-08 10:48:41 +0100 | [diff] [blame] | 435 | else |
Alexander Beregalov | f14d8e9 | 2008-09-07 01:54:27 +0400 | [diff] [blame] | 436 | old = stac9460_2_get(ice, STAC946X_GENERAL_PURPOSE); |
Clément Guedez | ae8a9a1 | 2015-03-18 02:26:30 +0100 | [diff] [blame] | 437 | new = (ucontrol->value.enumerated.item[0] << 7 & 0x80) | (old & ~0x80); |
Clement Guedez | f6cdab5 | 2007-01-08 10:48:41 +0100 | [diff] [blame] | 438 | change = (new != old); |
| 439 | if (change) { |
| 440 | if (id == 0) |
Alexander Beregalov | f14d8e9 | 2008-09-07 01:54:27 +0400 | [diff] [blame] | 441 | stac9460_put(ice, STAC946X_GENERAL_PURPOSE, new); |
Clement Guedez | f6cdab5 | 2007-01-08 10:48:41 +0100 | [diff] [blame] | 442 | else |
Alexander Beregalov | f14d8e9 | 2008-09-07 01:54:27 +0400 | [diff] [blame] | 443 | stac9460_2_put(ice, STAC946X_GENERAL_PURPOSE, new); |
Clement Guedez | f6cdab5 | 2007-01-08 10:48:41 +0100 | [diff] [blame] | 444 | } |
| 445 | return change; |
| 446 | } |
| 447 | |
Clément Guedez | 16ddbe7 | 2015-03-18 02:26:29 +0100 | [diff] [blame] | 448 | |
Clément Guedez | 1aa9a4e | 2015-03-18 02:26:31 +0100 | [diff] [blame] | 449 | /* |
| 450 | * Handler for setting correct codec rate - called when rate change is detected |
| 451 | */ |
| 452 | static void stac9460_set_rate_val(struct snd_ice1712 *ice, unsigned int rate) |
| 453 | { |
| 454 | unsigned char old, new; |
| 455 | unsigned short int changed; |
| 456 | struct wtm_spec *spec = ice->spec; |
| 457 | |
| 458 | if (rate == 0) /* no hint - S/PDIF input is master, simply return */ |
| 459 | return; |
| 460 | else if (rate <= 48000) |
| 461 | new = 0x08; /* 256x, base rate mode */ |
| 462 | else if (rate <= 96000) |
| 463 | new = 0x11; /* 256x, mid rate mode */ |
| 464 | else |
| 465 | new = 0x12; /* 128x, high rate mode */ |
| 466 | |
| 467 | old = stac9460_get(ice, STAC946X_MASTER_CLOCKING); |
| 468 | if (old == new) |
| 469 | return; |
| 470 | /* change detected, setting master clock, muting first */ |
| 471 | /* due to possible conflicts with mute controls - mutexing */ |
| 472 | mutex_lock(&spec->mute_mutex); |
| 473 | /* we have to remember current mute status for each DAC */ |
| 474 | changed = 0xFFFF; |
| 475 | stac9460_dac_mute_all(ice, 0, &changed); |
| 476 | /*printk(KERN_DEBUG "Rate change: %d, new MC: 0x%02x\n", rate, new);*/ |
| 477 | stac9460_put(ice, STAC946X_MASTER_CLOCKING, new); |
| 478 | stac9460_2_put(ice, STAC946X_MASTER_CLOCKING, new); |
| 479 | udelay(10); |
| 480 | /* unmuting - only originally unmuted dacs - |
| 481 | * i.e. those changed when muting */ |
| 482 | stac9460_dac_mute_all(ice, 1, &changed); |
| 483 | mutex_unlock(&spec->mute_mutex); |
| 484 | } |
| 485 | |
| 486 | |
Clément Guedez | 16ddbe7 | 2015-03-18 02:26:29 +0100 | [diff] [blame] | 487 | /*Limits value in dB for fader*/ |
| 488 | static const DECLARE_TLV_DB_SCALE(db_scale_dac, -19125, 75, 0); |
| 489 | static const DECLARE_TLV_DB_SCALE(db_scale_adc, 0, 150, 0); |
| 490 | |
Clement Guedez | f6cdab5 | 2007-01-08 10:48:41 +0100 | [diff] [blame] | 491 | /* |
| 492 | * Control tabs |
| 493 | */ |
Bill Pemberton | e23e7a1 | 2012-12-06 12:35:10 -0500 | [diff] [blame] | 494 | static struct snd_kcontrol_new stac9640_controls[] = { |
Clement Guedez | f6cdab5 | 2007-01-08 10:48:41 +0100 | [diff] [blame] | 495 | { |
| 496 | .iface = SNDRV_CTL_ELEM_IFACE_MIXER, |
Clément Guedez | 16ddbe7 | 2015-03-18 02:26:29 +0100 | [diff] [blame] | 497 | .access = (SNDRV_CTL_ELEM_ACCESS_READWRITE | |
| 498 | SNDRV_CTL_ELEM_ACCESS_TLV_READ), |
Clement Guedez | f6cdab5 | 2007-01-08 10:48:41 +0100 | [diff] [blame] | 499 | .name = "Master Playback Switch", |
| 500 | .info = stac9460_dac_mute_info, |
| 501 | .get = stac9460_dac_mute_get, |
| 502 | .put = stac9460_dac_mute_put, |
Clément Guedez | 16ddbe7 | 2015-03-18 02:26:29 +0100 | [diff] [blame] | 503 | .private_value = 1, |
| 504 | .tlv = { .p = db_scale_dac } |
Clement Guedez | f6cdab5 | 2007-01-08 10:48:41 +0100 | [diff] [blame] | 505 | }, |
| 506 | { |
| 507 | .iface = SNDRV_CTL_ELEM_IFACE_MIXER, |
| 508 | .name = "Master Playback Volume", |
| 509 | .info = stac9460_dac_vol_info, |
| 510 | .get = stac9460_dac_vol_get, |
| 511 | .put = stac9460_dac_vol_put, |
| 512 | .private_value = 1, |
| 513 | }, |
| 514 | { |
| 515 | .iface = SNDRV_CTL_ELEM_IFACE_MIXER, |
Clément Guedez | ae8a9a1 | 2015-03-18 02:26:30 +0100 | [diff] [blame] | 516 | .name = "MIC/Line Input Enum", |
Clement Guedez | f6cdab5 | 2007-01-08 10:48:41 +0100 | [diff] [blame] | 517 | .count = 2, |
| 518 | .info = stac9460_mic_sw_info, |
| 519 | .get = stac9460_mic_sw_get, |
| 520 | .put = stac9460_mic_sw_put, |
| 521 | |
| 522 | }, |
| 523 | { |
| 524 | .iface = SNDRV_CTL_ELEM_IFACE_MIXER, |
| 525 | .name = "DAC Switch", |
| 526 | .count = 8, |
| 527 | .info = stac9460_dac_mute_info, |
| 528 | .get = stac9460_dac_mute_get, |
| 529 | .put = stac9460_dac_mute_put, |
| 530 | }, |
| 531 | { |
| 532 | .iface = SNDRV_CTL_ELEM_IFACE_MIXER, |
Clément Guedez | 16ddbe7 | 2015-03-18 02:26:29 +0100 | [diff] [blame] | 533 | .access = (SNDRV_CTL_ELEM_ACCESS_READWRITE | |
| 534 | SNDRV_CTL_ELEM_ACCESS_TLV_READ), |
| 535 | |
Clement Guedez | f6cdab5 | 2007-01-08 10:48:41 +0100 | [diff] [blame] | 536 | .name = "DAC Volume", |
| 537 | .count = 8, |
| 538 | .info = stac9460_dac_vol_info, |
| 539 | .get = stac9460_dac_vol_get, |
| 540 | .put = stac9460_dac_vol_put, |
Clément Guedez | 16ddbe7 | 2015-03-18 02:26:29 +0100 | [diff] [blame] | 541 | .tlv = { .p = db_scale_dac } |
Clement Guedez | f6cdab5 | 2007-01-08 10:48:41 +0100 | [diff] [blame] | 542 | }, |
| 543 | { |
| 544 | .iface = SNDRV_CTL_ELEM_IFACE_MIXER, |
| 545 | .name = "ADC Switch", |
| 546 | .count = 2, |
| 547 | .info = stac9460_adc_mute_info, |
| 548 | .get = stac9460_adc_mute_get, |
| 549 | .put = stac9460_adc_mute_put, |
| 550 | }, |
| 551 | { |
| 552 | .iface = SNDRV_CTL_ELEM_IFACE_MIXER, |
Clément Guedez | 16ddbe7 | 2015-03-18 02:26:29 +0100 | [diff] [blame] | 553 | .access = (SNDRV_CTL_ELEM_ACCESS_READWRITE | |
| 554 | SNDRV_CTL_ELEM_ACCESS_TLV_READ), |
| 555 | |
Clement Guedez | f6cdab5 | 2007-01-08 10:48:41 +0100 | [diff] [blame] | 556 | .name = "ADC Volume", |
| 557 | .count = 2, |
| 558 | .info = stac9460_adc_vol_info, |
| 559 | .get = stac9460_adc_vol_get, |
| 560 | .put = stac9460_adc_vol_put, |
Clément Guedez | 16ddbe7 | 2015-03-18 02:26:29 +0100 | [diff] [blame] | 561 | .tlv = { .p = db_scale_adc } |
Alexander Beregalov | f14d8e9 | 2008-09-07 01:54:27 +0400 | [diff] [blame] | 562 | } |
Clement Guedez | f6cdab5 | 2007-01-08 10:48:41 +0100 | [diff] [blame] | 563 | }; |
| 564 | |
| 565 | |
| 566 | |
| 567 | /*INIT*/ |
Bill Pemberton | e23e7a1 | 2012-12-06 12:35:10 -0500 | [diff] [blame] | 568 | static int wtm_add_controls(struct snd_ice1712 *ice) |
Clement Guedez | f6cdab5 | 2007-01-08 10:48:41 +0100 | [diff] [blame] | 569 | { |
| 570 | unsigned int i; |
| 571 | int err; |
| 572 | |
| 573 | for (i = 0; i < ARRAY_SIZE(stac9640_controls); i++) { |
| 574 | err = snd_ctl_add(ice->card, |
| 575 | snd_ctl_new1(&stac9640_controls[i], ice)); |
| 576 | if (err < 0) |
| 577 | return err; |
| 578 | } |
| 579 | return 0; |
| 580 | } |
| 581 | |
Bill Pemberton | e23e7a1 | 2012-12-06 12:35:10 -0500 | [diff] [blame] | 582 | static int wtm_init(struct snd_ice1712 *ice) |
Clement Guedez | f6cdab5 | 2007-01-08 10:48:41 +0100 | [diff] [blame] | 583 | { |
Clément Guedez | b56df15 | 2015-03-18 02:26:26 +0100 | [diff] [blame] | 584 | static unsigned short stac_inits_wtm[] = { |
Clement Guedez | f6cdab5 | 2007-01-08 10:48:41 +0100 | [diff] [blame] | 585 | STAC946X_RESET, 0, |
Clément Guedez | 1aa9a4e | 2015-03-18 02:26:31 +0100 | [diff] [blame] | 586 | STAC946X_MASTER_CLOCKING, 0x11, |
Clement Guedez | f6cdab5 | 2007-01-08 10:48:41 +0100 | [diff] [blame] | 587 | (unsigned short)-1 |
| 588 | }; |
| 589 | unsigned short *p; |
Clément Guedez | 1aa9a4e | 2015-03-18 02:26:31 +0100 | [diff] [blame] | 590 | struct wtm_spec *spec; |
Alexander Beregalov | f14d8e9 | 2008-09-07 01:54:27 +0400 | [diff] [blame] | 591 | |
Clement Guedez | f6cdab5 | 2007-01-08 10:48:41 +0100 | [diff] [blame] | 592 | /*WTM 192M*/ |
| 593 | ice->num_total_dacs = 8; |
| 594 | ice->num_total_adcs = 4; |
| 595 | ice->force_rdma1 = 1; |
| 596 | |
Clément Guedez | 1aa9a4e | 2015-03-18 02:26:31 +0100 | [diff] [blame] | 597 | /*init mutex for dac mute conflict*/ |
| 598 | spec = kzalloc(sizeof(*spec), GFP_KERNEL); |
| 599 | if (!spec) |
| 600 | return -ENOMEM; |
| 601 | ice->spec = spec; |
| 602 | mutex_init(&spec->mute_mutex); |
| 603 | |
| 604 | |
Clement Guedez | f6cdab5 | 2007-01-08 10:48:41 +0100 | [diff] [blame] | 605 | /*initialize codec*/ |
Clément Guedez | b56df15 | 2015-03-18 02:26:26 +0100 | [diff] [blame] | 606 | p = stac_inits_wtm; |
Clement Guedez | f6cdab5 | 2007-01-08 10:48:41 +0100 | [diff] [blame] | 607 | for (; *p != (unsigned short)-1; p += 2) { |
| 608 | stac9460_put(ice, p[0], p[1]); |
| 609 | stac9460_2_put(ice, p[0], p[1]); |
| 610 | } |
Clément Guedez | 1aa9a4e | 2015-03-18 02:26:31 +0100 | [diff] [blame] | 611 | ice->gpio.set_pro_rate = stac9460_set_rate_val; |
Clement Guedez | f6cdab5 | 2007-01-08 10:48:41 +0100 | [diff] [blame] | 612 | return 0; |
| 613 | } |
| 614 | |
| 615 | |
Bill Pemberton | e23e7a1 | 2012-12-06 12:35:10 -0500 | [diff] [blame] | 616 | static unsigned char wtm_eeprom[] = { |
Clément Guedez | f8a8b3a | 2015-03-18 02:26:28 +0100 | [diff] [blame] | 617 | [ICE_EEP2_SYSCONF] = 0x67, /*SYSCONF: clock 192KHz, mpu401, |
| 618 | 4ADC, 8DAC */ |
Clément Guedez | 7127744 | 2015-03-18 02:26:27 +0100 | [diff] [blame] | 619 | [ICE_EEP2_ACLINK] = 0x80, /* ACLINK : I2S */ |
| 620 | [ICE_EEP2_I2S] = 0xf8, /* I2S: vol; 96k, 24bit, 192k */ |
| 621 | [ICE_EEP2_SPDIF] = 0xc1, /*SPDIF: out-en, spidf ext out*/ |
| 622 | [ICE_EEP2_GPIO_DIR] = 0x9f, |
| 623 | [ICE_EEP2_GPIO_DIR1] = 0xff, |
| 624 | [ICE_EEP2_GPIO_DIR2] = 0x7f, |
| 625 | [ICE_EEP2_GPIO_MASK] = 0x9f, |
| 626 | [ICE_EEP2_GPIO_MASK1] = 0xff, |
| 627 | [ICE_EEP2_GPIO_MASK2] = 0x7f, |
| 628 | [ICE_EEP2_GPIO_STATE] = 0x16, |
| 629 | [ICE_EEP2_GPIO_STATE1] = 0x80, |
| 630 | [ICE_EEP2_GPIO_STATE2] = 0x00, |
Clement Guedez | f6cdab5 | 2007-01-08 10:48:41 +0100 | [diff] [blame] | 631 | }; |
| 632 | |
| 633 | |
| 634 | /*entry point*/ |
Bill Pemberton | e23e7a1 | 2012-12-06 12:35:10 -0500 | [diff] [blame] | 635 | struct snd_ice1712_card_info snd_vt1724_wtm_cards[] = { |
Clement Guedez | f6cdab5 | 2007-01-08 10:48:41 +0100 | [diff] [blame] | 636 | { |
| 637 | .subvendor = VT1724_SUBDEVICE_WTM, |
| 638 | .name = "ESI Waveterminal 192M", |
| 639 | .model = "WT192M", |
| 640 | .chip_init = wtm_init, |
| 641 | .build_controls = wtm_add_controls, |
| 642 | .eeprom_size = sizeof(wtm_eeprom), |
| 643 | .eeprom_data = wtm_eeprom, |
| 644 | }, |
| 645 | {} /*terminator*/ |
| 646 | }; |