blob: 9906119e0954cf0f5185512ee031853e8d67938b [file] [log] [blame]
Clement Guedezf6cdab52007-01-08 10:48:41 +01001/*
2 * ALSA driver for ICEnsemble VT1724 (Envy24HT)
Alexander Beregalovf14d8e92008-09-07 01:54:27 +04003 *
Clement Guedezf6cdab52007-01-08 10:48:41 +01004 * 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 Beregalovf14d8e92008-09-07 01:54:27 +04009 *
Clement Guedezf6cdab52007-01-08 10:48:41 +010010 * 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 Beregalovf14d8e92008-09-07 01:54:27 +040023 *
24 */
Clement Guedezf6cdab52007-01-08 10:48:41 +010025
26
27
Clement Guedezf6cdab52007-01-08 10:48:41 +010028#include <linux/delay.h>
29#include <linux/interrupt.h>
30#include <linux/init.h>
Clement Guedezf6cdab52007-01-08 10:48:41 +010031#include <sound/core.h>
Clément Guedez16ddbe72015-03-18 02:26:29 +010032#include <sound/tlv.h>
Clément Guedez1aa9a4e2015-03-18 02:26:31 +010033#include <linux/slab.h>
Clement Guedezf6cdab52007-01-08 10:48:41 +010034
35#include "ice1712.h"
36#include "envy24ht.h"
37#include "wtm.h"
38#include "stac946x.h"
39
Clément Guedez1aa9a4e2015-03-18 02:26:31 +010040struct wtm_spec {
41 /* rate change needs atomic mute/unmute of all dacs*/
42 struct mutex mute_mutex;
43};
44
Clement Guedezf6cdab52007-01-08 10:48:41 +010045
46/*
Alexander Beregalovf14d8e92008-09-07 01:54:27 +040047 * 2*ADC 6*DAC no1 ringbuffer r/w on i2c bus
Clement Guedezf6cdab52007-01-08 10:48:41 +010048 */
Alexander Beregalovf14d8e92008-09-07 01:54:27 +040049static inline void stac9460_put(struct snd_ice1712 *ice, int reg,
Clement Guedezf6cdab52007-01-08 10:48:41 +010050 unsigned char val)
51{
52 snd_vt1724_write_i2c(ice, STAC9460_I2C_ADDR, reg, val);
53}
54
55static 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 */
63static 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
69static 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 Guedez1aa9a4e2015-03-18 02:26:31 +010078static 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 Iwaia5ce8892007-07-23 15:42:26 +0200125#define stac9460_dac_mute_info snd_ctl_boolean_mono_info
Clement Guedezf6cdab52007-01-08 10:48:41 +0100126
127static int stac9460_dac_mute_get(struct snd_kcontrol *kcontrol,
Alexander Beregalovf14d8e92008-09-07 01:54:27 +0400128 struct snd_ctl_elem_value *ucontrol)
Clement Guedezf6cdab52007-01-08 10:48:41 +0100129{
130 struct snd_ice1712 *ice = snd_kcontrol_chip(kcontrol);
Clément Guedez1aa9a4e2015-03-18 02:26:31 +0100131 struct wtm_spec *spec = ice->spec;
Clement Guedezf6cdab52007-01-08 10:48:41 +0100132 unsigned char val;
133 int idx, id;
134
Clément Guedez1aa9a4e2015-03-18 02:26:31 +0100135 mutex_lock(&spec->mute_mutex);
136
Clement Guedezf6cdab52007-01-08 10:48:41 +0100137 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 Beregalovf14d8e92008-09-07 01:54:27 +0400146 else
147 val = stac9460_2_get(ice, idx - 6);
Clement Guedezf6cdab52007-01-08 10:48:41 +0100148 ucontrol->value.integer.value[0] = (~val >> 7) & 0x1;
Clément Guedez1aa9a4e2015-03-18 02:26:31 +0100149
150 mutex_unlock(&spec->mute_mutex);
Clement Guedezf6cdab52007-01-08 10:48:41 +0100151 return 0;
152}
153
154static int stac9460_dac_mute_put(struct snd_kcontrol *kcontrol,
Alexander Beregalovf14d8e92008-09-07 01:54:27 +0400155 struct snd_ctl_elem_value *ucontrol)
Clement Guedezf6cdab52007-01-08 10:48:41 +0100156{
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 Beregalovf14d8e92008-09-07 01:54:27 +0400165 new = (~ucontrol->value.integer.value[0] << 7 & 0x80) |
166 (old & ~0x80);
Clement Guedezf6cdab52007-01-08 10:48:41 +0100167 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 Beregalovf14d8e92008-09-07 01:54:27 +0400177 else
Clement Guedezf6cdab52007-01-08 10:48:41 +0100178 old = stac9460_2_get(ice, idx - 6);
Alexander Beregalovf14d8e92008-09-07 01:54:27 +0400179 new = (~ucontrol->value.integer.value[0] << 7 & 0x80) |
Clement Guedezf6cdab52007-01-08 10:48:41 +0100180 (old & ~0x80);
181 change = (new != old);
182 if (change) {
183 if (id < 6)
Alexander Beregalovf14d8e92008-09-07 01:54:27 +0400184 stac9460_put(ice, idx, new);
Clement Guedezf6cdab52007-01-08 10:48:41 +0100185 else
Alexander Beregalovf14d8e92008-09-07 01:54:27 +0400186 stac9460_2_put(ice, idx - 6, new);
Clement Guedezf6cdab52007-01-08 10:48:41 +0100187 }
188 }
189 return change;
190}
191
192/*
193 * DAC volume attenuation mixer control
194 */
195static int stac9460_dac_vol_info(struct snd_kcontrol *kcontrol,
Alexander Beregalovf14d8e92008-09-07 01:54:27 +0400196 struct snd_ctl_elem_info *uinfo)
Clement Guedezf6cdab52007-01-08 10:48:41 +0100197{
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
205static int stac9460_dac_vol_get(struct snd_kcontrol *kcontrol,
Alexander Beregalovf14d8e92008-09-07 01:54:27 +0400206 struct snd_ctl_elem_value *ucontrol)
Clement Guedezf6cdab52007-01-08 10:48:41 +0100207{
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 Beregalovf14d8e92008-09-07 01:54:27 +0400221 else
Clement Guedezf6cdab52007-01-08 10:48:41 +0100222 vol = stac9460_2_get(ice, idx - 6) & 0x7f;
223 ucontrol->value.integer.value[0] = 0x7f - vol;
224 return 0;
225}
226
227static int stac9460_dac_vol_put(struct snd_kcontrol *kcontrol,
Alexander Beregalovf14d8e92008-09-07 01:54:27 +0400228 struct snd_ctl_elem_value *ucontrol)
Clement Guedezf6cdab52007-01-08 10:48:41 +0100229{
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 Iwai9cd17cd2007-11-15 15:56:07 +0100237 nvol = ucontrol->value.integer.value[0] & 0x7f;
Clement Guedezf6cdab52007-01-08 10:48:41 +0100238 tmp = stac9460_get(ice, idx);
239 ovol = 0x7f - (tmp & 0x7f);
240 change = (ovol != nvol);
241 if (change) {
Alexander Beregalovf14d8e92008-09-07 01:54:27 +0400242 stac9460_put(ice, idx, (0x7f - nvol) | (tmp & 0x80));
243 stac9460_2_put(ice, idx, (0x7f - nvol) | (tmp & 0x80));
Clement Guedezf6cdab52007-01-08 10:48:41 +0100244 }
245 } else {
246 id = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id);
247 idx = id + STAC946X_LF_VOLUME;
Takashi Iwai9cd17cd2007-11-15 15:56:07 +0100248 nvol = ucontrol->value.integer.value[0] & 0x7f;
Clement Guedezf6cdab52007-01-08 10:48:41 +0100249 if (id < 6)
250 tmp = stac9460_get(ice, idx);
Alexander Beregalovf14d8e92008-09-07 01:54:27 +0400251 else
Clement Guedezf6cdab52007-01-08 10:48:41 +0100252 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 Beregalovf14d8e92008-09-07 01:54:27 +0400258 (tmp & 0x80));
259 else
Clement Guedezf6cdab52007-01-08 10:48:41 +0100260 stac9460_2_put(ice, idx-6, (0x7f - nvol) |
Alexander Beregalovf14d8e92008-09-07 01:54:27 +0400261 (tmp & 0x80));
Clement Guedezf6cdab52007-01-08 10:48:41 +0100262 }
263 }
264 return change;
265}
266
267/*
268 * ADC mute control
269 */
Takashi Iwaia5ce8892007-07-23 15:42:26 +0200270#define stac9460_adc_mute_info snd_ctl_boolean_stereo_info
Clement Guedezf6cdab52007-01-08 10:48:41 +0100271
272static int stac9460_adc_mute_get(struct snd_kcontrol *kcontrol,
Alexander Beregalovf14d8e92008-09-07 01:54:27 +0400273 struct snd_ctl_elem_value *ucontrol)
Clement Guedezf6cdab52007-01-08 10:48:41 +0100274{
275 struct snd_ice1712 *ice = snd_kcontrol_chip(kcontrol);
276 unsigned char val;
277 int i, id;
Alexander Beregalovf14d8e92008-09-07 01:54:27 +0400278
Clement Guedezf6cdab52007-01-08 10:48:41 +0100279 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
294static int stac9460_adc_mute_put(struct snd_kcontrol *kcontrol,
Alexander Beregalovf14d8e92008-09-07 01:54:27 +0400295 struct snd_ctl_elem_value *ucontrol)
Clement Guedezf6cdab52007-01-08 10:48:41 +0100296{
297 struct snd_ice1712 *ice = snd_kcontrol_chip(kcontrol);
298 unsigned char new, old;
299 int i, reg, id;
300 int change;
Alexander Beregalovf14d8e92008-09-07 01:54:27 +0400301
Clement Guedezf6cdab52007-01-08 10:48:41 +0100302 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 Beregalovf14d8e92008-09-07 01:54:27 +0400308 (old&~0x80);
Clement Guedezf6cdab52007-01-08 10:48:41 +0100309 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 Beregalovf14d8e92008-09-07 01:54:27 +0400318 (old&~0x80);
Clement Guedezf6cdab52007-01-08 10:48:41 +0100319 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 */
330static int stac9460_adc_vol_info(struct snd_kcontrol *kcontrol,
Alexander Beregalovf14d8e92008-09-07 01:54:27 +0400331 struct snd_ctl_elem_info *uinfo)
Clement Guedezf6cdab52007-01-08 10:48:41 +0100332{
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
340static int stac9460_adc_vol_get(struct snd_kcontrol *kcontrol,
Alexander Beregalovf14d8e92008-09-07 01:54:27 +0400341 struct snd_ctl_elem_value *ucontrol)
Clement Guedezf6cdab52007-01-08 10:48:41 +0100342{
343 struct snd_ice1712 *ice = snd_kcontrol_chip(kcontrol);
344 int i, reg, id;
345 unsigned char vol;
Alexander Beregalovf14d8e92008-09-07 01:54:27 +0400346
Clement Guedezf6cdab52007-01-08 10:48:41 +0100347 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
364static int stac9460_adc_vol_put(struct snd_kcontrol *kcontrol,
Alexander Beregalovf14d8e92008-09-07 01:54:27 +0400365 struct snd_ctl_elem_value *ucontrol)
Clement Guedezf6cdab52007-01-08 10:48:41 +0100366{
367 struct snd_ice1712 *ice = snd_kcontrol_chip(kcontrol);
368 int i, reg, id;
369 unsigned char ovol, nvol;
370 int change;
Alexander Beregalovf14d8e92008-09-07 01:54:27 +0400371
Clement Guedezf6cdab52007-01-08 10:48:41 +0100372 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 Iwai9cd17cd2007-11-15 15:56:07 +0100376 nvol = ucontrol->value.integer.value[i] & 0x0f;
Clement Guedezf6cdab52007-01-08 10:48:41 +0100377 ovol = 0x0f - stac9460_get(ice, reg);
378 change = ((ovol & 0x0f) != nvol);
379 if (change)
380 stac9460_put(ice, reg, (0x0f - nvol) |
Alexander Beregalovf14d8e92008-09-07 01:54:27 +0400381 (ovol & ~0x0f));
Clement Guedezf6cdab52007-01-08 10:48:41 +0100382 }
383 } else {
384 for (i = 0; i < 2; ++i) {
385 reg = STAC946X_MIC_L_VOLUME + i;
Takashi Iwai9cd17cd2007-11-15 15:56:07 +0100386 nvol = ucontrol->value.integer.value[i] & 0x0f;
Clement Guedezf6cdab52007-01-08 10:48:41 +0100387 ovol = 0x0f - stac9460_2_get(ice, reg);
388 change = ((ovol & 0x0f) != nvol);
389 if (change)
390 stac9460_2_put(ice, reg, (0x0f - nvol) |
Alexander Beregalovf14d8e92008-09-07 01:54:27 +0400391 (ovol & ~0x0f));
Clement Guedezf6cdab52007-01-08 10:48:41 +0100392 }
393 }
394 return change;
395}
396
397/*
398 * MIC / LINE switch fonction
399 */
Clément Guedezae8a9a12015-03-18 02:26:30 +0100400static 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 Guedezf6cdab52007-01-08 10:48:41 +0100404
Clément Guedezae8a9a12015-03-18 02:26:30 +0100405 return snd_ctl_enum_info(uinfo, 1, 2, texts);
406}
407
Clement Guedezf6cdab52007-01-08 10:48:41 +0100408
409static int stac9460_mic_sw_get(struct snd_kcontrol *kcontrol,
Alexander Beregalovf14d8e92008-09-07 01:54:27 +0400410 struct snd_ctl_elem_value *ucontrol)
Clement Guedezf6cdab52007-01-08 10:48:41 +0100411{
412 struct snd_ice1712 *ice = snd_kcontrol_chip(kcontrol);
413 unsigned char val;
414 int id;
Alexander Beregalovf14d8e92008-09-07 01:54:27 +0400415
Clement Guedezf6cdab52007-01-08 10:48:41 +0100416 id = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id);
417 if (id == 0)
Alexander Beregalovf14d8e92008-09-07 01:54:27 +0400418 val = stac9460_get(ice, STAC946X_GENERAL_PURPOSE);
Clement Guedezf6cdab52007-01-08 10:48:41 +0100419 else
Alexander Beregalovf14d8e92008-09-07 01:54:27 +0400420 val = stac9460_2_get(ice, STAC946X_GENERAL_PURPOSE);
Clément Guedezae8a9a12015-03-18 02:26:30 +0100421 ucontrol->value.enumerated.item[0] = (val >> 7) & 0x1;
Clement Guedezf6cdab52007-01-08 10:48:41 +0100422 return 0;
423}
424
425static int stac9460_mic_sw_put(struct snd_kcontrol *kcontrol,
Alexander Beregalovf14d8e92008-09-07 01:54:27 +0400426 struct snd_ctl_elem_value *ucontrol)
Clement Guedezf6cdab52007-01-08 10:48:41 +0100427{
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 Beregalovf14d8e92008-09-07 01:54:27 +0400434 old = stac9460_get(ice, STAC946X_GENERAL_PURPOSE);
Clement Guedezf6cdab52007-01-08 10:48:41 +0100435 else
Alexander Beregalovf14d8e92008-09-07 01:54:27 +0400436 old = stac9460_2_get(ice, STAC946X_GENERAL_PURPOSE);
Clément Guedezae8a9a12015-03-18 02:26:30 +0100437 new = (ucontrol->value.enumerated.item[0] << 7 & 0x80) | (old & ~0x80);
Clement Guedezf6cdab52007-01-08 10:48:41 +0100438 change = (new != old);
439 if (change) {
440 if (id == 0)
Alexander Beregalovf14d8e92008-09-07 01:54:27 +0400441 stac9460_put(ice, STAC946X_GENERAL_PURPOSE, new);
Clement Guedezf6cdab52007-01-08 10:48:41 +0100442 else
Alexander Beregalovf14d8e92008-09-07 01:54:27 +0400443 stac9460_2_put(ice, STAC946X_GENERAL_PURPOSE, new);
Clement Guedezf6cdab52007-01-08 10:48:41 +0100444 }
445 return change;
446}
447
Clément Guedez16ddbe72015-03-18 02:26:29 +0100448
Clément Guedez1aa9a4e2015-03-18 02:26:31 +0100449/*
450 * Handler for setting correct codec rate - called when rate change is detected
451 */
452static 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 Guedez16ddbe72015-03-18 02:26:29 +0100487/*Limits value in dB for fader*/
488static const DECLARE_TLV_DB_SCALE(db_scale_dac, -19125, 75, 0);
489static const DECLARE_TLV_DB_SCALE(db_scale_adc, 0, 150, 0);
490
Clement Guedezf6cdab52007-01-08 10:48:41 +0100491/*
492 * Control tabs
493 */
Bill Pembertone23e7a12012-12-06 12:35:10 -0500494static struct snd_kcontrol_new stac9640_controls[] = {
Clement Guedezf6cdab52007-01-08 10:48:41 +0100495 {
496 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
Clément Guedez16ddbe72015-03-18 02:26:29 +0100497 .access = (SNDRV_CTL_ELEM_ACCESS_READWRITE |
498 SNDRV_CTL_ELEM_ACCESS_TLV_READ),
Clement Guedezf6cdab52007-01-08 10:48:41 +0100499 .name = "Master Playback Switch",
500 .info = stac9460_dac_mute_info,
501 .get = stac9460_dac_mute_get,
502 .put = stac9460_dac_mute_put,
Clément Guedez16ddbe72015-03-18 02:26:29 +0100503 .private_value = 1,
504 .tlv = { .p = db_scale_dac }
Clement Guedezf6cdab52007-01-08 10:48:41 +0100505 },
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 Guedezae8a9a12015-03-18 02:26:30 +0100516 .name = "MIC/Line Input Enum",
Clement Guedezf6cdab52007-01-08 10:48:41 +0100517 .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 Guedez16ddbe72015-03-18 02:26:29 +0100533 .access = (SNDRV_CTL_ELEM_ACCESS_READWRITE |
534 SNDRV_CTL_ELEM_ACCESS_TLV_READ),
535
Clement Guedezf6cdab52007-01-08 10:48:41 +0100536 .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 Guedez16ddbe72015-03-18 02:26:29 +0100541 .tlv = { .p = db_scale_dac }
Clement Guedezf6cdab52007-01-08 10:48:41 +0100542 },
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 Guedez16ddbe72015-03-18 02:26:29 +0100553 .access = (SNDRV_CTL_ELEM_ACCESS_READWRITE |
554 SNDRV_CTL_ELEM_ACCESS_TLV_READ),
555
Clement Guedezf6cdab52007-01-08 10:48:41 +0100556 .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 Guedez16ddbe72015-03-18 02:26:29 +0100561 .tlv = { .p = db_scale_adc }
Alexander Beregalovf14d8e92008-09-07 01:54:27 +0400562 }
Clement Guedezf6cdab52007-01-08 10:48:41 +0100563};
564
565
566
567/*INIT*/
Bill Pembertone23e7a12012-12-06 12:35:10 -0500568static int wtm_add_controls(struct snd_ice1712 *ice)
Clement Guedezf6cdab52007-01-08 10:48:41 +0100569{
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 Pembertone23e7a12012-12-06 12:35:10 -0500582static int wtm_init(struct snd_ice1712 *ice)
Clement Guedezf6cdab52007-01-08 10:48:41 +0100583{
Clément Guedezb56df152015-03-18 02:26:26 +0100584 static unsigned short stac_inits_wtm[] = {
Clement Guedezf6cdab52007-01-08 10:48:41 +0100585 STAC946X_RESET, 0,
Clément Guedez1aa9a4e2015-03-18 02:26:31 +0100586 STAC946X_MASTER_CLOCKING, 0x11,
Clement Guedezf6cdab52007-01-08 10:48:41 +0100587 (unsigned short)-1
588 };
589 unsigned short *p;
Clément Guedez1aa9a4e2015-03-18 02:26:31 +0100590 struct wtm_spec *spec;
Alexander Beregalovf14d8e92008-09-07 01:54:27 +0400591
Clement Guedezf6cdab52007-01-08 10:48:41 +0100592 /*WTM 192M*/
593 ice->num_total_dacs = 8;
594 ice->num_total_adcs = 4;
595 ice->force_rdma1 = 1;
596
Clément Guedez1aa9a4e2015-03-18 02:26:31 +0100597 /*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 Guedezf6cdab52007-01-08 10:48:41 +0100605 /*initialize codec*/
Clément Guedezb56df152015-03-18 02:26:26 +0100606 p = stac_inits_wtm;
Clement Guedezf6cdab52007-01-08 10:48:41 +0100607 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 Guedez1aa9a4e2015-03-18 02:26:31 +0100611 ice->gpio.set_pro_rate = stac9460_set_rate_val;
Clement Guedezf6cdab52007-01-08 10:48:41 +0100612 return 0;
613}
614
615
Bill Pembertone23e7a12012-12-06 12:35:10 -0500616static unsigned char wtm_eeprom[] = {
Clément Guedezf8a8b3a2015-03-18 02:26:28 +0100617 [ICE_EEP2_SYSCONF] = 0x67, /*SYSCONF: clock 192KHz, mpu401,
618 4ADC, 8DAC */
Clément Guedez71277442015-03-18 02:26:27 +0100619 [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 Guedezf6cdab52007-01-08 10:48:41 +0100631};
632
633
634/*entry point*/
Bill Pembertone23e7a12012-12-06 12:35:10 -0500635struct snd_ice1712_card_info snd_vt1724_wtm_cards[] = {
Clement Guedezf6cdab52007-01-08 10:48:41 +0100636 {
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};