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> |
Clement Guedez | f6cdab5 | 2007-01-08 10:48:41 +0100 | [diff] [blame] | 33 | |
| 34 | #include "ice1712.h" |
| 35 | #include "envy24ht.h" |
| 36 | #include "wtm.h" |
| 37 | #include "stac946x.h" |
| 38 | |
| 39 | |
| 40 | /* |
Alexander Beregalov | f14d8e9 | 2008-09-07 01:54:27 +0400 | [diff] [blame] | 41 | * 2*ADC 6*DAC no1 ringbuffer r/w on i2c bus |
Clement Guedez | f6cdab5 | 2007-01-08 10:48:41 +0100 | [diff] [blame] | 42 | */ |
Alexander Beregalov | f14d8e9 | 2008-09-07 01:54:27 +0400 | [diff] [blame] | 43 | static inline void stac9460_put(struct snd_ice1712 *ice, int reg, |
Clement Guedez | f6cdab5 | 2007-01-08 10:48:41 +0100 | [diff] [blame] | 44 | unsigned char val) |
| 45 | { |
| 46 | snd_vt1724_write_i2c(ice, STAC9460_I2C_ADDR, reg, val); |
| 47 | } |
| 48 | |
| 49 | static inline unsigned char stac9460_get(struct snd_ice1712 *ice, int reg) |
| 50 | { |
| 51 | return snd_vt1724_read_i2c(ice, STAC9460_I2C_ADDR, reg); |
| 52 | } |
| 53 | |
| 54 | /* |
| 55 | * 2*ADC 2*DAC no2 ringbuffer r/w on i2c bus |
| 56 | */ |
| 57 | static inline void stac9460_2_put(struct snd_ice1712 *ice, int reg, |
| 58 | unsigned char val) |
| 59 | { |
| 60 | snd_vt1724_write_i2c(ice, STAC9460_2_I2C_ADDR, reg, val); |
| 61 | } |
| 62 | |
| 63 | static inline unsigned char stac9460_2_get(struct snd_ice1712 *ice, int reg) |
| 64 | { |
| 65 | return snd_vt1724_read_i2c(ice, STAC9460_2_I2C_ADDR, reg); |
| 66 | } |
| 67 | |
| 68 | |
| 69 | /* |
| 70 | * DAC mute control |
| 71 | */ |
Takashi Iwai | a5ce889 | 2007-07-23 15:42:26 +0200 | [diff] [blame] | 72 | #define stac9460_dac_mute_info snd_ctl_boolean_mono_info |
Clement Guedez | f6cdab5 | 2007-01-08 10:48:41 +0100 | [diff] [blame] | 73 | |
| 74 | static int stac9460_dac_mute_get(struct snd_kcontrol *kcontrol, |
Alexander Beregalov | f14d8e9 | 2008-09-07 01:54:27 +0400 | [diff] [blame] | 75 | struct snd_ctl_elem_value *ucontrol) |
Clement Guedez | f6cdab5 | 2007-01-08 10:48:41 +0100 | [diff] [blame] | 76 | { |
| 77 | struct snd_ice1712 *ice = snd_kcontrol_chip(kcontrol); |
| 78 | unsigned char val; |
| 79 | int idx, id; |
| 80 | |
| 81 | if (kcontrol->private_value) { |
| 82 | idx = STAC946X_MASTER_VOLUME; |
| 83 | id = 0; |
| 84 | } else { |
| 85 | id = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id); |
| 86 | idx = id + STAC946X_LF_VOLUME; |
| 87 | } |
| 88 | if (id < 6) |
| 89 | val = stac9460_get(ice, idx); |
Alexander Beregalov | f14d8e9 | 2008-09-07 01:54:27 +0400 | [diff] [blame] | 90 | else |
| 91 | val = stac9460_2_get(ice, idx - 6); |
Clement Guedez | f6cdab5 | 2007-01-08 10:48:41 +0100 | [diff] [blame] | 92 | ucontrol->value.integer.value[0] = (~val >> 7) & 0x1; |
| 93 | return 0; |
| 94 | } |
| 95 | |
| 96 | static int stac9460_dac_mute_put(struct snd_kcontrol *kcontrol, |
Alexander Beregalov | f14d8e9 | 2008-09-07 01:54:27 +0400 | [diff] [blame] | 97 | struct snd_ctl_elem_value *ucontrol) |
Clement Guedez | f6cdab5 | 2007-01-08 10:48:41 +0100 | [diff] [blame] | 98 | { |
| 99 | struct snd_ice1712 *ice = snd_kcontrol_chip(kcontrol); |
| 100 | unsigned char new, old; |
| 101 | int id, idx; |
| 102 | int change; |
| 103 | |
| 104 | if (kcontrol->private_value) { |
| 105 | idx = STAC946X_MASTER_VOLUME; |
| 106 | old = stac9460_get(ice, idx); |
Alexander Beregalov | f14d8e9 | 2008-09-07 01:54:27 +0400 | [diff] [blame] | 107 | new = (~ucontrol->value.integer.value[0] << 7 & 0x80) | |
| 108 | (old & ~0x80); |
Clement Guedez | f6cdab5 | 2007-01-08 10:48:41 +0100 | [diff] [blame] | 109 | change = (new != old); |
| 110 | if (change) { |
| 111 | stac9460_put(ice, idx, new); |
| 112 | stac9460_2_put(ice, idx, new); |
| 113 | } |
| 114 | } else { |
| 115 | id = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id); |
| 116 | idx = id + STAC946X_LF_VOLUME; |
| 117 | if (id < 6) |
| 118 | old = stac9460_get(ice, idx); |
Alexander Beregalov | f14d8e9 | 2008-09-07 01:54:27 +0400 | [diff] [blame] | 119 | else |
Clement Guedez | f6cdab5 | 2007-01-08 10:48:41 +0100 | [diff] [blame] | 120 | old = stac9460_2_get(ice, idx - 6); |
Alexander Beregalov | f14d8e9 | 2008-09-07 01:54:27 +0400 | [diff] [blame] | 121 | new = (~ucontrol->value.integer.value[0] << 7 & 0x80) | |
Clement Guedez | f6cdab5 | 2007-01-08 10:48:41 +0100 | [diff] [blame] | 122 | (old & ~0x80); |
| 123 | change = (new != old); |
| 124 | if (change) { |
| 125 | if (id < 6) |
Alexander Beregalov | f14d8e9 | 2008-09-07 01:54:27 +0400 | [diff] [blame] | 126 | stac9460_put(ice, idx, new); |
Clement Guedez | f6cdab5 | 2007-01-08 10:48:41 +0100 | [diff] [blame] | 127 | else |
Alexander Beregalov | f14d8e9 | 2008-09-07 01:54:27 +0400 | [diff] [blame] | 128 | stac9460_2_put(ice, idx - 6, new); |
Clement Guedez | f6cdab5 | 2007-01-08 10:48:41 +0100 | [diff] [blame] | 129 | } |
| 130 | } |
| 131 | return change; |
| 132 | } |
| 133 | |
| 134 | /* |
| 135 | * DAC volume attenuation mixer control |
| 136 | */ |
| 137 | static int stac9460_dac_vol_info(struct snd_kcontrol *kcontrol, |
Alexander Beregalov | f14d8e9 | 2008-09-07 01:54:27 +0400 | [diff] [blame] | 138 | struct snd_ctl_elem_info *uinfo) |
Clement Guedez | f6cdab5 | 2007-01-08 10:48:41 +0100 | [diff] [blame] | 139 | { |
| 140 | uinfo->type = SNDRV_CTL_ELEM_TYPE_INTEGER; |
| 141 | uinfo->count = 1; |
| 142 | uinfo->value.integer.min = 0; /* mute */ |
| 143 | uinfo->value.integer.max = 0x7f; /* 0dB */ |
| 144 | return 0; |
| 145 | } |
| 146 | |
| 147 | static int stac9460_dac_vol_get(struct snd_kcontrol *kcontrol, |
Alexander Beregalov | f14d8e9 | 2008-09-07 01:54:27 +0400 | [diff] [blame] | 148 | struct snd_ctl_elem_value *ucontrol) |
Clement Guedez | f6cdab5 | 2007-01-08 10:48:41 +0100 | [diff] [blame] | 149 | { |
| 150 | struct snd_ice1712 *ice = snd_kcontrol_chip(kcontrol); |
| 151 | int idx, id; |
| 152 | unsigned char vol; |
| 153 | |
| 154 | if (kcontrol->private_value) { |
| 155 | idx = STAC946X_MASTER_VOLUME; |
| 156 | id = 0; |
| 157 | } else { |
| 158 | id = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id); |
| 159 | idx = id + STAC946X_LF_VOLUME; |
| 160 | } |
| 161 | if (id < 6) |
| 162 | vol = stac9460_get(ice, idx) & 0x7f; |
Alexander Beregalov | f14d8e9 | 2008-09-07 01:54:27 +0400 | [diff] [blame] | 163 | else |
Clement Guedez | f6cdab5 | 2007-01-08 10:48:41 +0100 | [diff] [blame] | 164 | vol = stac9460_2_get(ice, idx - 6) & 0x7f; |
| 165 | ucontrol->value.integer.value[0] = 0x7f - vol; |
| 166 | return 0; |
| 167 | } |
| 168 | |
| 169 | static int stac9460_dac_vol_put(struct snd_kcontrol *kcontrol, |
Alexander Beregalov | f14d8e9 | 2008-09-07 01:54:27 +0400 | [diff] [blame] | 170 | struct snd_ctl_elem_value *ucontrol) |
Clement Guedez | f6cdab5 | 2007-01-08 10:48:41 +0100 | [diff] [blame] | 171 | { |
| 172 | struct snd_ice1712 *ice = snd_kcontrol_chip(kcontrol); |
| 173 | int idx, id; |
| 174 | unsigned char tmp, ovol, nvol; |
| 175 | int change; |
| 176 | |
| 177 | if (kcontrol->private_value) { |
| 178 | idx = STAC946X_MASTER_VOLUME; |
Takashi Iwai | 9cd17cd | 2007-11-15 15:56:07 +0100 | [diff] [blame] | 179 | nvol = ucontrol->value.integer.value[0] & 0x7f; |
Clement Guedez | f6cdab5 | 2007-01-08 10:48:41 +0100 | [diff] [blame] | 180 | tmp = stac9460_get(ice, idx); |
| 181 | ovol = 0x7f - (tmp & 0x7f); |
| 182 | change = (ovol != nvol); |
| 183 | if (change) { |
Alexander Beregalov | f14d8e9 | 2008-09-07 01:54:27 +0400 | [diff] [blame] | 184 | stac9460_put(ice, idx, (0x7f - nvol) | (tmp & 0x80)); |
| 185 | stac9460_2_put(ice, idx, (0x7f - nvol) | (tmp & 0x80)); |
Clement Guedez | f6cdab5 | 2007-01-08 10:48:41 +0100 | [diff] [blame] | 186 | } |
| 187 | } else { |
| 188 | id = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id); |
| 189 | idx = id + STAC946X_LF_VOLUME; |
Takashi Iwai | 9cd17cd | 2007-11-15 15:56:07 +0100 | [diff] [blame] | 190 | nvol = ucontrol->value.integer.value[0] & 0x7f; |
Clement Guedez | f6cdab5 | 2007-01-08 10:48:41 +0100 | [diff] [blame] | 191 | if (id < 6) |
| 192 | tmp = stac9460_get(ice, idx); |
Alexander Beregalov | f14d8e9 | 2008-09-07 01:54:27 +0400 | [diff] [blame] | 193 | else |
Clement Guedez | f6cdab5 | 2007-01-08 10:48:41 +0100 | [diff] [blame] | 194 | tmp = stac9460_2_get(ice, idx - 6); |
| 195 | ovol = 0x7f - (tmp & 0x7f); |
| 196 | change = (ovol != nvol); |
| 197 | if (change) { |
| 198 | if (id < 6) |
| 199 | stac9460_put(ice, idx, (0x7f - nvol) | |
Alexander Beregalov | f14d8e9 | 2008-09-07 01:54:27 +0400 | [diff] [blame] | 200 | (tmp & 0x80)); |
| 201 | else |
Clement Guedez | f6cdab5 | 2007-01-08 10:48:41 +0100 | [diff] [blame] | 202 | stac9460_2_put(ice, idx-6, (0x7f - nvol) | |
Alexander Beregalov | f14d8e9 | 2008-09-07 01:54:27 +0400 | [diff] [blame] | 203 | (tmp & 0x80)); |
Clement Guedez | f6cdab5 | 2007-01-08 10:48:41 +0100 | [diff] [blame] | 204 | } |
| 205 | } |
| 206 | return change; |
| 207 | } |
| 208 | |
| 209 | /* |
| 210 | * ADC mute control |
| 211 | */ |
Takashi Iwai | a5ce889 | 2007-07-23 15:42:26 +0200 | [diff] [blame] | 212 | #define stac9460_adc_mute_info snd_ctl_boolean_stereo_info |
Clement Guedez | f6cdab5 | 2007-01-08 10:48:41 +0100 | [diff] [blame] | 213 | |
| 214 | static int stac9460_adc_mute_get(struct snd_kcontrol *kcontrol, |
Alexander Beregalov | f14d8e9 | 2008-09-07 01:54:27 +0400 | [diff] [blame] | 215 | struct snd_ctl_elem_value *ucontrol) |
Clement Guedez | f6cdab5 | 2007-01-08 10:48:41 +0100 | [diff] [blame] | 216 | { |
| 217 | struct snd_ice1712 *ice = snd_kcontrol_chip(kcontrol); |
| 218 | unsigned char val; |
| 219 | int i, id; |
Alexander Beregalov | f14d8e9 | 2008-09-07 01:54:27 +0400 | [diff] [blame] | 220 | |
Clement Guedez | f6cdab5 | 2007-01-08 10:48:41 +0100 | [diff] [blame] | 221 | id = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id); |
| 222 | if (id == 0) { |
| 223 | for (i = 0; i < 2; ++i) { |
| 224 | val = stac9460_get(ice, STAC946X_MIC_L_VOLUME + i); |
| 225 | ucontrol->value.integer.value[i] = ~val>>7 & 0x1; |
| 226 | } |
| 227 | } else { |
| 228 | for (i = 0; i < 2; ++i) { |
| 229 | val = stac9460_2_get(ice, STAC946X_MIC_L_VOLUME + i); |
| 230 | ucontrol->value.integer.value[i] = ~val>>7 & 0x1; |
| 231 | } |
| 232 | } |
| 233 | return 0; |
| 234 | } |
| 235 | |
| 236 | static int stac9460_adc_mute_put(struct snd_kcontrol *kcontrol, |
Alexander Beregalov | f14d8e9 | 2008-09-07 01:54:27 +0400 | [diff] [blame] | 237 | struct snd_ctl_elem_value *ucontrol) |
Clement Guedez | f6cdab5 | 2007-01-08 10:48:41 +0100 | [diff] [blame] | 238 | { |
| 239 | struct snd_ice1712 *ice = snd_kcontrol_chip(kcontrol); |
| 240 | unsigned char new, old; |
| 241 | int i, reg, id; |
| 242 | int change; |
Alexander Beregalov | f14d8e9 | 2008-09-07 01:54:27 +0400 | [diff] [blame] | 243 | |
Clement Guedez | f6cdab5 | 2007-01-08 10:48:41 +0100 | [diff] [blame] | 244 | id = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id); |
| 245 | if (id == 0) { |
| 246 | for (i = 0; i < 2; ++i) { |
| 247 | reg = STAC946X_MIC_L_VOLUME + i; |
| 248 | old = stac9460_get(ice, reg); |
| 249 | new = (~ucontrol->value.integer.value[i]<<7&0x80) | |
Alexander Beregalov | f14d8e9 | 2008-09-07 01:54:27 +0400 | [diff] [blame] | 250 | (old&~0x80); |
Clement Guedez | f6cdab5 | 2007-01-08 10:48:41 +0100 | [diff] [blame] | 251 | change = (new != old); |
| 252 | if (change) |
| 253 | stac9460_put(ice, reg, new); |
| 254 | } |
| 255 | } else { |
| 256 | for (i = 0; i < 2; ++i) { |
| 257 | reg = STAC946X_MIC_L_VOLUME + i; |
| 258 | old = stac9460_2_get(ice, reg); |
| 259 | new = (~ucontrol->value.integer.value[i]<<7&0x80) | |
Alexander Beregalov | f14d8e9 | 2008-09-07 01:54:27 +0400 | [diff] [blame] | 260 | (old&~0x80); |
Clement Guedez | f6cdab5 | 2007-01-08 10:48:41 +0100 | [diff] [blame] | 261 | change = (new != old); |
| 262 | if (change) |
| 263 | stac9460_2_put(ice, reg, new); |
| 264 | } |
| 265 | } |
| 266 | return change; |
| 267 | } |
| 268 | |
| 269 | /* |
| 270 | *ADC gain mixer control |
| 271 | */ |
| 272 | static int stac9460_adc_vol_info(struct snd_kcontrol *kcontrol, |
Alexander Beregalov | f14d8e9 | 2008-09-07 01:54:27 +0400 | [diff] [blame] | 273 | struct snd_ctl_elem_info *uinfo) |
Clement Guedez | f6cdab5 | 2007-01-08 10:48:41 +0100 | [diff] [blame] | 274 | { |
| 275 | uinfo->type = SNDRV_CTL_ELEM_TYPE_INTEGER; |
| 276 | uinfo->count = 2; |
| 277 | uinfo->value.integer.min = 0; /* 0dB */ |
| 278 | uinfo->value.integer.max = 0x0f; /* 22.5dB */ |
| 279 | return 0; |
| 280 | } |
| 281 | |
| 282 | static int stac9460_adc_vol_get(struct snd_kcontrol *kcontrol, |
Alexander Beregalov | f14d8e9 | 2008-09-07 01:54:27 +0400 | [diff] [blame] | 283 | struct snd_ctl_elem_value *ucontrol) |
Clement Guedez | f6cdab5 | 2007-01-08 10:48:41 +0100 | [diff] [blame] | 284 | { |
| 285 | struct snd_ice1712 *ice = snd_kcontrol_chip(kcontrol); |
| 286 | int i, reg, id; |
| 287 | unsigned char vol; |
Alexander Beregalov | f14d8e9 | 2008-09-07 01:54:27 +0400 | [diff] [blame] | 288 | |
Clement Guedez | f6cdab5 | 2007-01-08 10:48:41 +0100 | [diff] [blame] | 289 | id = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id); |
| 290 | if (id == 0) { |
| 291 | for (i = 0; i < 2; ++i) { |
| 292 | reg = STAC946X_MIC_L_VOLUME + i; |
| 293 | vol = stac9460_get(ice, reg) & 0x0f; |
| 294 | ucontrol->value.integer.value[i] = 0x0f - vol; |
| 295 | } |
| 296 | } else { |
| 297 | for (i = 0; i < 2; ++i) { |
| 298 | reg = STAC946X_MIC_L_VOLUME + i; |
| 299 | vol = stac9460_2_get(ice, reg) & 0x0f; |
| 300 | ucontrol->value.integer.value[i] = 0x0f - vol; |
| 301 | } |
| 302 | } |
| 303 | return 0; |
| 304 | } |
| 305 | |
| 306 | static int stac9460_adc_vol_put(struct snd_kcontrol *kcontrol, |
Alexander Beregalov | f14d8e9 | 2008-09-07 01:54:27 +0400 | [diff] [blame] | 307 | struct snd_ctl_elem_value *ucontrol) |
Clement Guedez | f6cdab5 | 2007-01-08 10:48:41 +0100 | [diff] [blame] | 308 | { |
| 309 | struct snd_ice1712 *ice = snd_kcontrol_chip(kcontrol); |
| 310 | int i, reg, id; |
| 311 | unsigned char ovol, nvol; |
| 312 | int change; |
Alexander Beregalov | f14d8e9 | 2008-09-07 01:54:27 +0400 | [diff] [blame] | 313 | |
Clement Guedez | f6cdab5 | 2007-01-08 10:48:41 +0100 | [diff] [blame] | 314 | id = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id); |
| 315 | if (id == 0) { |
| 316 | for (i = 0; i < 2; ++i) { |
| 317 | reg = STAC946X_MIC_L_VOLUME + i; |
Takashi Iwai | 9cd17cd | 2007-11-15 15:56:07 +0100 | [diff] [blame] | 318 | nvol = ucontrol->value.integer.value[i] & 0x0f; |
Clement Guedez | f6cdab5 | 2007-01-08 10:48:41 +0100 | [diff] [blame] | 319 | ovol = 0x0f - stac9460_get(ice, reg); |
| 320 | change = ((ovol & 0x0f) != nvol); |
| 321 | if (change) |
| 322 | stac9460_put(ice, reg, (0x0f - nvol) | |
Alexander Beregalov | f14d8e9 | 2008-09-07 01:54:27 +0400 | [diff] [blame] | 323 | (ovol & ~0x0f)); |
Clement Guedez | f6cdab5 | 2007-01-08 10:48:41 +0100 | [diff] [blame] | 324 | } |
| 325 | } else { |
| 326 | for (i = 0; i < 2; ++i) { |
| 327 | reg = STAC946X_MIC_L_VOLUME + i; |
Takashi Iwai | 9cd17cd | 2007-11-15 15:56:07 +0100 | [diff] [blame] | 328 | nvol = ucontrol->value.integer.value[i] & 0x0f; |
Clement Guedez | f6cdab5 | 2007-01-08 10:48:41 +0100 | [diff] [blame] | 329 | ovol = 0x0f - stac9460_2_get(ice, reg); |
| 330 | change = ((ovol & 0x0f) != nvol); |
| 331 | if (change) |
| 332 | stac9460_2_put(ice, reg, (0x0f - nvol) | |
Alexander Beregalov | f14d8e9 | 2008-09-07 01:54:27 +0400 | [diff] [blame] | 333 | (ovol & ~0x0f)); |
Clement Guedez | f6cdab5 | 2007-01-08 10:48:41 +0100 | [diff] [blame] | 334 | } |
| 335 | } |
| 336 | return change; |
| 337 | } |
| 338 | |
| 339 | /* |
| 340 | * MIC / LINE switch fonction |
| 341 | */ |
Clément Guedez | ae8a9a1 | 2015-03-18 02:26:30 +0100 | [diff] [blame^] | 342 | static int stac9460_mic_sw_info(struct snd_kcontrol *kcontrol, |
| 343 | struct snd_ctl_elem_info *uinfo) |
| 344 | { |
| 345 | static const char * const texts[2] = { "Line In", "Mic" }; |
Clement Guedez | f6cdab5 | 2007-01-08 10:48:41 +0100 | [diff] [blame] | 346 | |
Clément Guedez | ae8a9a1 | 2015-03-18 02:26:30 +0100 | [diff] [blame^] | 347 | return snd_ctl_enum_info(uinfo, 1, 2, texts); |
| 348 | } |
| 349 | |
Clement Guedez | f6cdab5 | 2007-01-08 10:48:41 +0100 | [diff] [blame] | 350 | |
| 351 | static int stac9460_mic_sw_get(struct snd_kcontrol *kcontrol, |
Alexander Beregalov | f14d8e9 | 2008-09-07 01:54:27 +0400 | [diff] [blame] | 352 | struct snd_ctl_elem_value *ucontrol) |
Clement Guedez | f6cdab5 | 2007-01-08 10:48:41 +0100 | [diff] [blame] | 353 | { |
| 354 | struct snd_ice1712 *ice = snd_kcontrol_chip(kcontrol); |
| 355 | unsigned char val; |
| 356 | int id; |
Alexander Beregalov | f14d8e9 | 2008-09-07 01:54:27 +0400 | [diff] [blame] | 357 | |
Clement Guedez | f6cdab5 | 2007-01-08 10:48:41 +0100 | [diff] [blame] | 358 | id = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id); |
| 359 | if (id == 0) |
Alexander Beregalov | f14d8e9 | 2008-09-07 01:54:27 +0400 | [diff] [blame] | 360 | val = stac9460_get(ice, STAC946X_GENERAL_PURPOSE); |
Clement Guedez | f6cdab5 | 2007-01-08 10:48:41 +0100 | [diff] [blame] | 361 | else |
Alexander Beregalov | f14d8e9 | 2008-09-07 01:54:27 +0400 | [diff] [blame] | 362 | val = stac9460_2_get(ice, STAC946X_GENERAL_PURPOSE); |
Clément Guedez | ae8a9a1 | 2015-03-18 02:26:30 +0100 | [diff] [blame^] | 363 | ucontrol->value.enumerated.item[0] = (val >> 7) & 0x1; |
Clement Guedez | f6cdab5 | 2007-01-08 10:48:41 +0100 | [diff] [blame] | 364 | return 0; |
| 365 | } |
| 366 | |
| 367 | static int stac9460_mic_sw_put(struct snd_kcontrol *kcontrol, |
Alexander Beregalov | f14d8e9 | 2008-09-07 01:54:27 +0400 | [diff] [blame] | 368 | struct snd_ctl_elem_value *ucontrol) |
Clement Guedez | f6cdab5 | 2007-01-08 10:48:41 +0100 | [diff] [blame] | 369 | { |
| 370 | struct snd_ice1712 *ice = snd_kcontrol_chip(kcontrol); |
| 371 | unsigned char new, old; |
| 372 | int change, id; |
| 373 | |
| 374 | id = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id); |
| 375 | if (id == 0) |
Alexander Beregalov | f14d8e9 | 2008-09-07 01:54:27 +0400 | [diff] [blame] | 376 | old = stac9460_get(ice, STAC946X_GENERAL_PURPOSE); |
Clement Guedez | f6cdab5 | 2007-01-08 10:48:41 +0100 | [diff] [blame] | 377 | else |
Alexander Beregalov | f14d8e9 | 2008-09-07 01:54:27 +0400 | [diff] [blame] | 378 | old = stac9460_2_get(ice, STAC946X_GENERAL_PURPOSE); |
Clément Guedez | ae8a9a1 | 2015-03-18 02:26:30 +0100 | [diff] [blame^] | 379 | new = (ucontrol->value.enumerated.item[0] << 7 & 0x80) | (old & ~0x80); |
Clement Guedez | f6cdab5 | 2007-01-08 10:48:41 +0100 | [diff] [blame] | 380 | change = (new != old); |
| 381 | if (change) { |
| 382 | if (id == 0) |
Alexander Beregalov | f14d8e9 | 2008-09-07 01:54:27 +0400 | [diff] [blame] | 383 | stac9460_put(ice, STAC946X_GENERAL_PURPOSE, new); |
Clement Guedez | f6cdab5 | 2007-01-08 10:48:41 +0100 | [diff] [blame] | 384 | else |
Alexander Beregalov | f14d8e9 | 2008-09-07 01:54:27 +0400 | [diff] [blame] | 385 | stac9460_2_put(ice, STAC946X_GENERAL_PURPOSE, new); |
Clement Guedez | f6cdab5 | 2007-01-08 10:48:41 +0100 | [diff] [blame] | 386 | } |
| 387 | return change; |
| 388 | } |
| 389 | |
Clément Guedez | 16ddbe7 | 2015-03-18 02:26:29 +0100 | [diff] [blame] | 390 | |
| 391 | /*Limits value in dB for fader*/ |
| 392 | static const DECLARE_TLV_DB_SCALE(db_scale_dac, -19125, 75, 0); |
| 393 | static const DECLARE_TLV_DB_SCALE(db_scale_adc, 0, 150, 0); |
| 394 | |
Clement Guedez | f6cdab5 | 2007-01-08 10:48:41 +0100 | [diff] [blame] | 395 | /* |
| 396 | * Control tabs |
| 397 | */ |
Bill Pemberton | e23e7a1 | 2012-12-06 12:35:10 -0500 | [diff] [blame] | 398 | static struct snd_kcontrol_new stac9640_controls[] = { |
Clement Guedez | f6cdab5 | 2007-01-08 10:48:41 +0100 | [diff] [blame] | 399 | { |
| 400 | .iface = SNDRV_CTL_ELEM_IFACE_MIXER, |
Clément Guedez | 16ddbe7 | 2015-03-18 02:26:29 +0100 | [diff] [blame] | 401 | .access = (SNDRV_CTL_ELEM_ACCESS_READWRITE | |
| 402 | SNDRV_CTL_ELEM_ACCESS_TLV_READ), |
Clement Guedez | f6cdab5 | 2007-01-08 10:48:41 +0100 | [diff] [blame] | 403 | .name = "Master Playback Switch", |
| 404 | .info = stac9460_dac_mute_info, |
| 405 | .get = stac9460_dac_mute_get, |
| 406 | .put = stac9460_dac_mute_put, |
Clément Guedez | 16ddbe7 | 2015-03-18 02:26:29 +0100 | [diff] [blame] | 407 | .private_value = 1, |
| 408 | .tlv = { .p = db_scale_dac } |
Clement Guedez | f6cdab5 | 2007-01-08 10:48:41 +0100 | [diff] [blame] | 409 | }, |
| 410 | { |
| 411 | .iface = SNDRV_CTL_ELEM_IFACE_MIXER, |
| 412 | .name = "Master Playback Volume", |
| 413 | .info = stac9460_dac_vol_info, |
| 414 | .get = stac9460_dac_vol_get, |
| 415 | .put = stac9460_dac_vol_put, |
| 416 | .private_value = 1, |
| 417 | }, |
| 418 | { |
| 419 | .iface = SNDRV_CTL_ELEM_IFACE_MIXER, |
Clément Guedez | ae8a9a1 | 2015-03-18 02:26:30 +0100 | [diff] [blame^] | 420 | .name = "MIC/Line Input Enum", |
Clement Guedez | f6cdab5 | 2007-01-08 10:48:41 +0100 | [diff] [blame] | 421 | .count = 2, |
| 422 | .info = stac9460_mic_sw_info, |
| 423 | .get = stac9460_mic_sw_get, |
| 424 | .put = stac9460_mic_sw_put, |
| 425 | |
| 426 | }, |
| 427 | { |
| 428 | .iface = SNDRV_CTL_ELEM_IFACE_MIXER, |
| 429 | .name = "DAC Switch", |
| 430 | .count = 8, |
| 431 | .info = stac9460_dac_mute_info, |
| 432 | .get = stac9460_dac_mute_get, |
| 433 | .put = stac9460_dac_mute_put, |
| 434 | }, |
| 435 | { |
| 436 | .iface = SNDRV_CTL_ELEM_IFACE_MIXER, |
Clément Guedez | 16ddbe7 | 2015-03-18 02:26:29 +0100 | [diff] [blame] | 437 | .access = (SNDRV_CTL_ELEM_ACCESS_READWRITE | |
| 438 | SNDRV_CTL_ELEM_ACCESS_TLV_READ), |
| 439 | |
Clement Guedez | f6cdab5 | 2007-01-08 10:48:41 +0100 | [diff] [blame] | 440 | .name = "DAC Volume", |
| 441 | .count = 8, |
| 442 | .info = stac9460_dac_vol_info, |
| 443 | .get = stac9460_dac_vol_get, |
| 444 | .put = stac9460_dac_vol_put, |
Clément Guedez | 16ddbe7 | 2015-03-18 02:26:29 +0100 | [diff] [blame] | 445 | .tlv = { .p = db_scale_dac } |
Clement Guedez | f6cdab5 | 2007-01-08 10:48:41 +0100 | [diff] [blame] | 446 | }, |
| 447 | { |
| 448 | .iface = SNDRV_CTL_ELEM_IFACE_MIXER, |
| 449 | .name = "ADC Switch", |
| 450 | .count = 2, |
| 451 | .info = stac9460_adc_mute_info, |
| 452 | .get = stac9460_adc_mute_get, |
| 453 | .put = stac9460_adc_mute_put, |
| 454 | }, |
| 455 | { |
| 456 | .iface = SNDRV_CTL_ELEM_IFACE_MIXER, |
Clément Guedez | 16ddbe7 | 2015-03-18 02:26:29 +0100 | [diff] [blame] | 457 | .access = (SNDRV_CTL_ELEM_ACCESS_READWRITE | |
| 458 | SNDRV_CTL_ELEM_ACCESS_TLV_READ), |
| 459 | |
Clement Guedez | f6cdab5 | 2007-01-08 10:48:41 +0100 | [diff] [blame] | 460 | .name = "ADC Volume", |
| 461 | .count = 2, |
| 462 | .info = stac9460_adc_vol_info, |
| 463 | .get = stac9460_adc_vol_get, |
| 464 | .put = stac9460_adc_vol_put, |
Clément Guedez | 16ddbe7 | 2015-03-18 02:26:29 +0100 | [diff] [blame] | 465 | .tlv = { .p = db_scale_adc } |
Alexander Beregalov | f14d8e9 | 2008-09-07 01:54:27 +0400 | [diff] [blame] | 466 | } |
Clement Guedez | f6cdab5 | 2007-01-08 10:48:41 +0100 | [diff] [blame] | 467 | }; |
| 468 | |
| 469 | |
| 470 | |
| 471 | /*INIT*/ |
Bill Pemberton | e23e7a1 | 2012-12-06 12:35:10 -0500 | [diff] [blame] | 472 | static int wtm_add_controls(struct snd_ice1712 *ice) |
Clement Guedez | f6cdab5 | 2007-01-08 10:48:41 +0100 | [diff] [blame] | 473 | { |
| 474 | unsigned int i; |
| 475 | int err; |
| 476 | |
| 477 | for (i = 0; i < ARRAY_SIZE(stac9640_controls); i++) { |
| 478 | err = snd_ctl_add(ice->card, |
| 479 | snd_ctl_new1(&stac9640_controls[i], ice)); |
| 480 | if (err < 0) |
| 481 | return err; |
| 482 | } |
| 483 | return 0; |
| 484 | } |
| 485 | |
Bill Pemberton | e23e7a1 | 2012-12-06 12:35:10 -0500 | [diff] [blame] | 486 | static int wtm_init(struct snd_ice1712 *ice) |
Clement Guedez | f6cdab5 | 2007-01-08 10:48:41 +0100 | [diff] [blame] | 487 | { |
Clément Guedez | b56df15 | 2015-03-18 02:26:26 +0100 | [diff] [blame] | 488 | static unsigned short stac_inits_wtm[] = { |
Clement Guedez | f6cdab5 | 2007-01-08 10:48:41 +0100 | [diff] [blame] | 489 | STAC946X_RESET, 0, |
| 490 | (unsigned short)-1 |
| 491 | }; |
| 492 | unsigned short *p; |
Alexander Beregalov | f14d8e9 | 2008-09-07 01:54:27 +0400 | [diff] [blame] | 493 | |
Clement Guedez | f6cdab5 | 2007-01-08 10:48:41 +0100 | [diff] [blame] | 494 | /*WTM 192M*/ |
| 495 | ice->num_total_dacs = 8; |
| 496 | ice->num_total_adcs = 4; |
| 497 | ice->force_rdma1 = 1; |
| 498 | |
| 499 | /*initialize codec*/ |
Clément Guedez | b56df15 | 2015-03-18 02:26:26 +0100 | [diff] [blame] | 500 | p = stac_inits_wtm; |
Clement Guedez | f6cdab5 | 2007-01-08 10:48:41 +0100 | [diff] [blame] | 501 | for (; *p != (unsigned short)-1; p += 2) { |
| 502 | stac9460_put(ice, p[0], p[1]); |
| 503 | stac9460_2_put(ice, p[0], p[1]); |
| 504 | } |
| 505 | return 0; |
| 506 | } |
| 507 | |
| 508 | |
Bill Pemberton | e23e7a1 | 2012-12-06 12:35:10 -0500 | [diff] [blame] | 509 | static unsigned char wtm_eeprom[] = { |
Clément Guedez | f8a8b3a | 2015-03-18 02:26:28 +0100 | [diff] [blame] | 510 | [ICE_EEP2_SYSCONF] = 0x67, /*SYSCONF: clock 192KHz, mpu401, |
| 511 | 4ADC, 8DAC */ |
Clément Guedez | 7127744 | 2015-03-18 02:26:27 +0100 | [diff] [blame] | 512 | [ICE_EEP2_ACLINK] = 0x80, /* ACLINK : I2S */ |
| 513 | [ICE_EEP2_I2S] = 0xf8, /* I2S: vol; 96k, 24bit, 192k */ |
| 514 | [ICE_EEP2_SPDIF] = 0xc1, /*SPDIF: out-en, spidf ext out*/ |
| 515 | [ICE_EEP2_GPIO_DIR] = 0x9f, |
| 516 | [ICE_EEP2_GPIO_DIR1] = 0xff, |
| 517 | [ICE_EEP2_GPIO_DIR2] = 0x7f, |
| 518 | [ICE_EEP2_GPIO_MASK] = 0x9f, |
| 519 | [ICE_EEP2_GPIO_MASK1] = 0xff, |
| 520 | [ICE_EEP2_GPIO_MASK2] = 0x7f, |
| 521 | [ICE_EEP2_GPIO_STATE] = 0x16, |
| 522 | [ICE_EEP2_GPIO_STATE1] = 0x80, |
| 523 | [ICE_EEP2_GPIO_STATE2] = 0x00, |
Clement Guedez | f6cdab5 | 2007-01-08 10:48:41 +0100 | [diff] [blame] | 524 | }; |
| 525 | |
| 526 | |
| 527 | /*entry point*/ |
Bill Pemberton | e23e7a1 | 2012-12-06 12:35:10 -0500 | [diff] [blame] | 528 | struct snd_ice1712_card_info snd_vt1724_wtm_cards[] = { |
Clement Guedez | f6cdab5 | 2007-01-08 10:48:41 +0100 | [diff] [blame] | 529 | { |
| 530 | .subvendor = VT1724_SUBDEVICE_WTM, |
| 531 | .name = "ESI Waveterminal 192M", |
| 532 | .model = "WT192M", |
| 533 | .chip_init = wtm_init, |
| 534 | .build_controls = wtm_add_controls, |
| 535 | .eeprom_size = sizeof(wtm_eeprom), |
| 536 | .eeprom_data = wtm_eeprom, |
| 537 | }, |
| 538 | {} /*terminator*/ |
| 539 | }; |