blob: 8a5833317b0a080346e7e417f062911e302dac92 [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/*
2 * Copyright (c) 2004 James Courtier-Dutton <James@superbug.demon.co.uk>
3 * Driver CA0106 chips. e.g. Sound Blaster Audigy LS and Live 24bit
James Courtier-Duttoned144f32005-05-27 23:28:27 +02004 * Version: 0.0.17
Linus Torvalds1da177e2005-04-16 15:20:36 -07005 *
6 * FEATURES currently supported:
7 * See ca0106_main.c for features.
8 *
9 * Changelog:
10 * Support interrupts per period.
11 * Removed noise from Center/LFE channel when in Analog mode.
12 * Rename and remove mixer controls.
13 * 0.0.6
14 * Use separate card based DMA buffer for periods table list.
15 * 0.0.7
16 * Change remove and rename ctrls into lists.
17 * 0.0.8
18 * Try to fix capture sources.
19 * 0.0.9
20 * Fix AC3 output.
21 * Enable S32_LE format support.
22 * 0.0.10
23 * Enable playback 48000 and 96000 rates. (Rates other that these do not work, even with "plug:front".)
24 * 0.0.11
25 * Add Model name recognition.
26 * 0.0.12
27 * Correct interrupt timing. interrupt at end of period, instead of in the middle of a playback period.
28 * Remove redundent "voice" handling.
29 * 0.0.13
30 * Single trigger call for multi channels.
31 * 0.0.14
32 * Set limits based on what the sound card hardware can do.
33 * playback periods_min=2, periods_max=8
34 * capture hw constraints require period_size = n * 64 bytes.
35 * playback hw constraints require period_size = n * 64 bytes.
36 * 0.0.15
37 * Separated ca0106.c into separate functional .c files.
38 * 0.0.16
39 * Modified Copyright message.
James Courtier-Duttoned144f32005-05-27 23:28:27 +020040 * 0.0.17
41 * Implement Mic and Line in Capture.
Linus Torvalds1da177e2005-04-16 15:20:36 -070042 *
43 * This code was initally based on code from ALSA's emu10k1x.c which is:
44 * Copyright (c) by Francisco Moraes <fmoraes@nc.rr.com>
45 *
46 * This program is free software; you can redistribute it and/or modify
47 * it under the terms of the GNU General Public License as published by
48 * the Free Software Foundation; either version 2 of the License, or
49 * (at your option) any later version.
50 *
51 * This program is distributed in the hope that it will be useful,
52 * but WITHOUT ANY WARRANTY; without even the implied warranty of
53 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
54 * GNU General Public License for more details.
55 *
56 * You should have received a copy of the GNU General Public License
57 * along with this program; if not, write to the Free Software
58 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
59 *
60 */
61#include <sound/driver.h>
62#include <linux/delay.h>
63#include <linux/init.h>
64#include <linux/interrupt.h>
65#include <linux/pci.h>
66#include <linux/slab.h>
67#include <linux/moduleparam.h>
68#include <sound/core.h>
69#include <sound/initval.h>
70#include <sound/pcm.h>
71#include <sound/ac97_codec.h>
72#include <sound/info.h>
73
74#include "ca0106.h"
75
Takashi Iwaie4a3d142005-11-17 14:55:40 +010076static int snd_ca0106_shared_spdif_info(struct snd_kcontrol *kcontrol,
77 struct snd_ctl_elem_info *uinfo)
Linus Torvalds1da177e2005-04-16 15:20:36 -070078{
79 uinfo->type = SNDRV_CTL_ELEM_TYPE_BOOLEAN;
80 uinfo->count = 1;
81 uinfo->value.integer.min = 0;
82 uinfo->value.integer.max = 1;
83 return 0;
84}
85
Takashi Iwaie4a3d142005-11-17 14:55:40 +010086static int snd_ca0106_shared_spdif_get(struct snd_kcontrol *kcontrol,
87 struct snd_ctl_elem_value *ucontrol)
Linus Torvalds1da177e2005-04-16 15:20:36 -070088{
Takashi Iwaie4a3d142005-11-17 14:55:40 +010089 struct snd_ca0106 *emu = snd_kcontrol_chip(kcontrol);
Linus Torvalds1da177e2005-04-16 15:20:36 -070090
91 ucontrol->value.enumerated.item[0] = emu->spdif_enable;
92 return 0;
93}
94
Takashi Iwaie4a3d142005-11-17 14:55:40 +010095static int snd_ca0106_shared_spdif_put(struct snd_kcontrol *kcontrol,
96 struct snd_ctl_elem_value *ucontrol)
Linus Torvalds1da177e2005-04-16 15:20:36 -070097{
Takashi Iwaie4a3d142005-11-17 14:55:40 +010098 struct snd_ca0106 *emu = snd_kcontrol_chip(kcontrol);
Linus Torvalds1da177e2005-04-16 15:20:36 -070099 unsigned int val;
100 int change = 0;
101 u32 mask;
102
103 val = ucontrol->value.enumerated.item[0] ;
104 change = (emu->spdif_enable != val);
105 if (change) {
106 emu->spdif_enable = val;
107 if (val == 1) {
108 /* Digital */
109 snd_ca0106_ptr_write(emu, SPDIF_SELECT1, 0, 0xf);
110 snd_ca0106_ptr_write(emu, SPDIF_SELECT2, 0, 0x0b000000);
111 snd_ca0106_ptr_write(emu, CAPTURE_CONTROL, 0,
112 snd_ca0106_ptr_read(emu, CAPTURE_CONTROL, 0) & ~0x1000);
113 mask = inl(emu->port + GPIO) & ~0x101;
114 outl(mask, emu->port + GPIO);
115
116 } else {
117 /* Analog */
118 snd_ca0106_ptr_write(emu, SPDIF_SELECT1, 0, 0xf);
James Courtier-Dutton1f829412005-05-21 16:23:37 +0200119 snd_ca0106_ptr_write(emu, SPDIF_SELECT2, 0, 0x000f0000);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700120 snd_ca0106_ptr_write(emu, CAPTURE_CONTROL, 0,
121 snd_ca0106_ptr_read(emu, CAPTURE_CONTROL, 0) | 0x1000);
122 mask = inl(emu->port + GPIO) | 0x101;
123 outl(mask, emu->port + GPIO);
124 }
125 }
126 return change;
127}
128
Takashi Iwaie4a3d142005-11-17 14:55:40 +0100129static int snd_ca0106_capture_source_info(struct snd_kcontrol *kcontrol,
130 struct snd_ctl_elem_info *uinfo)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700131{
Takashi Iwai95a98262005-11-17 10:40:18 +0100132 static char *texts[6] = {
James Courtier-Dutton39596dc2005-12-16 21:59:59 +0100133 "IEC958 out", "i2s mixer out", "IEC958 in", "i2s in", "AC97 in", "SRC out"
Takashi Iwai95a98262005-11-17 10:40:18 +0100134 };
Linus Torvalds1da177e2005-04-16 15:20:36 -0700135
136 uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED;
137 uinfo->count = 1;
138 uinfo->value.enumerated.items = 6;
139 if (uinfo->value.enumerated.item > 5)
140 uinfo->value.enumerated.item = 5;
141 strcpy(uinfo->value.enumerated.name, texts[uinfo->value.enumerated.item]);
142 return 0;
143}
144
Takashi Iwaie4a3d142005-11-17 14:55:40 +0100145static int snd_ca0106_capture_source_get(struct snd_kcontrol *kcontrol,
146 struct snd_ctl_elem_value *ucontrol)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700147{
Takashi Iwaie4a3d142005-11-17 14:55:40 +0100148 struct snd_ca0106 *emu = snd_kcontrol_chip(kcontrol);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700149
150 ucontrol->value.enumerated.item[0] = emu->capture_source;
151 return 0;
152}
153
Takashi Iwaie4a3d142005-11-17 14:55:40 +0100154static int snd_ca0106_capture_source_put(struct snd_kcontrol *kcontrol,
155 struct snd_ctl_elem_value *ucontrol)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700156{
Takashi Iwaie4a3d142005-11-17 14:55:40 +0100157 struct snd_ca0106 *emu = snd_kcontrol_chip(kcontrol);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700158 unsigned int val;
159 int change = 0;
160 u32 mask;
161 u32 source;
162
163 val = ucontrol->value.enumerated.item[0] ;
164 change = (emu->capture_source != val);
165 if (change) {
166 emu->capture_source = val;
167 source = (val << 28) | (val << 24) | (val << 20) | (val << 16);
168 mask = snd_ca0106_ptr_read(emu, CAPTURE_SOURCE, 0) & 0xffff;
169 snd_ca0106_ptr_write(emu, CAPTURE_SOURCE, 0, source | mask);
170 }
171 return change;
172}
173
James Courtier-Dutton6129daa2006-04-09 13:01:34 +0100174static int snd_ca0106_i2c_capture_source_info(struct snd_kcontrol *kcontrol,
175 struct snd_ctl_elem_info *uinfo)
176{
177 static char *texts[6] = {
178 "Phone", "Mic", "Line in", "Aux"
179 };
180
181 uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED;
182 uinfo->count = 1;
183 uinfo->value.enumerated.items = 4;
184 if (uinfo->value.enumerated.item > 3)
185 uinfo->value.enumerated.item = 3;
186 strcpy(uinfo->value.enumerated.name, texts[uinfo->value.enumerated.item]);
187 return 0;
188}
189
190static int snd_ca0106_i2c_capture_source_get(struct snd_kcontrol *kcontrol,
191 struct snd_ctl_elem_value *ucontrol)
192{
193 struct snd_ca0106 *emu = snd_kcontrol_chip(kcontrol);
194
195 ucontrol->value.enumerated.item[0] = emu->i2c_capture_source;
196 return 0;
197}
198
199static int snd_ca0106_i2c_capture_source_put(struct snd_kcontrol *kcontrol,
200 struct snd_ctl_elem_value *ucontrol)
201{
202 struct snd_ca0106 *emu = snd_kcontrol_chip(kcontrol);
203 unsigned int source_id;
204 unsigned int ngain, ogain;
205 int change = 0;
206 u32 source;
207 /* If the capture source has changed,
208 * update the capture volume from the cached value
209 * for the particular source.
210 */
211 source_id = ucontrol->value.enumerated.item[0] ;
212 change = (emu->i2c_capture_source != source_id);
213 if (change) {
214 snd_ca0106_i2c_write(emu, ADC_MUX, 0); /* Mute input */
215 ngain = emu->i2c_capture_volume[source_id][0]; /* Left */
216 ogain = emu->i2c_capture_volume[emu->i2c_capture_source][0]; /* Left */
217 if (ngain != ogain)
218 snd_ca0106_i2c_write(emu, ADC_ATTEN_ADCL, ((ngain) & 0xff));
219 ngain = emu->i2c_capture_volume[source_id][1]; /* Left */
220 ogain = emu->i2c_capture_volume[emu->i2c_capture_source][1]; /* Left */
221 if (ngain != ogain)
222 snd_ca0106_i2c_write(emu, ADC_ATTEN_ADCR, ((ngain) & 0xff));
223 source = 1 << source_id;
224 snd_ca0106_i2c_write(emu, ADC_MUX, source); /* Set source */
225 emu->i2c_capture_source = source_id;
226 }
227 return change;
228}
229
Takashi Iwaie4a3d142005-11-17 14:55:40 +0100230static int snd_ca0106_capture_mic_line_in_info(struct snd_kcontrol *kcontrol,
231 struct snd_ctl_elem_info *uinfo)
James Courtier-Duttoned144f32005-05-27 23:28:27 +0200232{
233 static char *texts[2] = { "Line in", "Mic in" };
234
235 uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED;
236 uinfo->count = 1;
237 uinfo->value.enumerated.items = 2;
238 if (uinfo->value.enumerated.item > 1)
239 uinfo->value.enumerated.item = 1;
240 strcpy(uinfo->value.enumerated.name, texts[uinfo->value.enumerated.item]);
241 return 0;
242}
243
Takashi Iwaie4a3d142005-11-17 14:55:40 +0100244static int snd_ca0106_capture_mic_line_in_get(struct snd_kcontrol *kcontrol,
245 struct snd_ctl_elem_value *ucontrol)
James Courtier-Duttoned144f32005-05-27 23:28:27 +0200246{
Takashi Iwaie4a3d142005-11-17 14:55:40 +0100247 struct snd_ca0106 *emu = snd_kcontrol_chip(kcontrol);
James Courtier-Duttoned144f32005-05-27 23:28:27 +0200248
249 ucontrol->value.enumerated.item[0] = emu->capture_mic_line_in;
250 return 0;
251}
252
Takashi Iwaie4a3d142005-11-17 14:55:40 +0100253static int snd_ca0106_capture_mic_line_in_put(struct snd_kcontrol *kcontrol,
254 struct snd_ctl_elem_value *ucontrol)
James Courtier-Duttoned144f32005-05-27 23:28:27 +0200255{
Takashi Iwaie4a3d142005-11-17 14:55:40 +0100256 struct snd_ca0106 *emu = snd_kcontrol_chip(kcontrol);
James Courtier-Duttoned144f32005-05-27 23:28:27 +0200257 unsigned int val;
258 int change = 0;
259 u32 tmp;
260
261 val = ucontrol->value.enumerated.item[0] ;
262 change = (emu->capture_mic_line_in != val);
263 if (change) {
264 emu->capture_mic_line_in = val;
265 if (val) {
James Courtier-Dutton6129daa2006-04-09 13:01:34 +0100266 //snd_ca0106_i2c_write(emu, ADC_MUX, 0); /* Mute input */
James Courtier-Duttoned144f32005-05-27 23:28:27 +0200267 tmp = inl(emu->port+GPIO) & ~0x400;
268 tmp = tmp | 0x400;
269 outl(tmp, emu->port+GPIO);
James Courtier-Dutton6129daa2006-04-09 13:01:34 +0100270 //snd_ca0106_i2c_write(emu, ADC_MUX, ADC_MUX_MIC);
James Courtier-Duttoned144f32005-05-27 23:28:27 +0200271 } else {
James Courtier-Dutton6129daa2006-04-09 13:01:34 +0100272 //snd_ca0106_i2c_write(emu, ADC_MUX, 0); /* Mute input */
James Courtier-Duttoned144f32005-05-27 23:28:27 +0200273 tmp = inl(emu->port+GPIO) & ~0x400;
274 outl(tmp, emu->port+GPIO);
James Courtier-Dutton6129daa2006-04-09 13:01:34 +0100275 //snd_ca0106_i2c_write(emu, ADC_MUX, ADC_MUX_LINEIN);
James Courtier-Duttoned144f32005-05-27 23:28:27 +0200276 }
277 }
278 return change;
279}
280
Takashi Iwaie4a3d142005-11-17 14:55:40 +0100281static struct snd_kcontrol_new snd_ca0106_capture_mic_line_in __devinitdata =
James Courtier-Duttoned144f32005-05-27 23:28:27 +0200282{
283 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
James Courtier-Dutton6129daa2006-04-09 13:01:34 +0100284 .name = "Shared Mic/Line in Capture Switch",
James Courtier-Duttoned144f32005-05-27 23:28:27 +0200285 .info = snd_ca0106_capture_mic_line_in_info,
286 .get = snd_ca0106_capture_mic_line_in_get,
287 .put = snd_ca0106_capture_mic_line_in_put
288};
289
Takashi Iwaie4a3d142005-11-17 14:55:40 +0100290static int snd_ca0106_spdif_info(struct snd_kcontrol *kcontrol,
291 struct snd_ctl_elem_info *uinfo)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700292{
293 uinfo->type = SNDRV_CTL_ELEM_TYPE_IEC958;
294 uinfo->count = 1;
295 return 0;
296}
297
Takashi Iwaie4a3d142005-11-17 14:55:40 +0100298static int snd_ca0106_spdif_get(struct snd_kcontrol *kcontrol,
299 struct snd_ctl_elem_value *ucontrol)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700300{
Takashi Iwaie4a3d142005-11-17 14:55:40 +0100301 struct snd_ca0106 *emu = snd_kcontrol_chip(kcontrol);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700302 unsigned int idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id);
303
304 ucontrol->value.iec958.status[0] = (emu->spdif_bits[idx] >> 0) & 0xff;
305 ucontrol->value.iec958.status[1] = (emu->spdif_bits[idx] >> 8) & 0xff;
306 ucontrol->value.iec958.status[2] = (emu->spdif_bits[idx] >> 16) & 0xff;
307 ucontrol->value.iec958.status[3] = (emu->spdif_bits[idx] >> 24) & 0xff;
308 return 0;
309}
310
Takashi Iwaie4a3d142005-11-17 14:55:40 +0100311static int snd_ca0106_spdif_get_mask(struct snd_kcontrol *kcontrol,
312 struct snd_ctl_elem_value *ucontrol)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700313{
314 ucontrol->value.iec958.status[0] = 0xff;
315 ucontrol->value.iec958.status[1] = 0xff;
316 ucontrol->value.iec958.status[2] = 0xff;
317 ucontrol->value.iec958.status[3] = 0xff;
318 return 0;
319}
320
Takashi Iwaie4a3d142005-11-17 14:55:40 +0100321static int snd_ca0106_spdif_put(struct snd_kcontrol *kcontrol,
322 struct snd_ctl_elem_value *ucontrol)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700323{
Takashi Iwaie4a3d142005-11-17 14:55:40 +0100324 struct snd_ca0106 *emu = snd_kcontrol_chip(kcontrol);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700325 unsigned int idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id);
326 int change;
327 unsigned int val;
328
329 val = (ucontrol->value.iec958.status[0] << 0) |
330 (ucontrol->value.iec958.status[1] << 8) |
331 (ucontrol->value.iec958.status[2] << 16) |
332 (ucontrol->value.iec958.status[3] << 24);
333 change = val != emu->spdif_bits[idx];
334 if (change) {
335 snd_ca0106_ptr_write(emu, SPCS0 + idx, 0, val);
336 emu->spdif_bits[idx] = val;
337 }
338 return change;
339}
340
Takashi Iwaie4a3d142005-11-17 14:55:40 +0100341static int snd_ca0106_volume_info(struct snd_kcontrol *kcontrol,
342 struct snd_ctl_elem_info *uinfo)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700343{
344 uinfo->type = SNDRV_CTL_ELEM_TYPE_INTEGER;
345 uinfo->count = 2;
346 uinfo->value.integer.min = 0;
347 uinfo->value.integer.max = 255;
348 return 0;
349}
350
Takashi Iwaie4a3d142005-11-17 14:55:40 +0100351static int snd_ca0106_volume_get(struct snd_kcontrol *kcontrol,
352 struct snd_ctl_elem_value *ucontrol)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700353{
Takashi Iwaie4a3d142005-11-17 14:55:40 +0100354 struct snd_ca0106 *emu = snd_kcontrol_chip(kcontrol);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700355 unsigned int value;
Takashi Iwai95a98262005-11-17 10:40:18 +0100356 int channel_id, reg;
357
358 channel_id = (kcontrol->private_value >> 8) & 0xff;
359 reg = kcontrol->private_value & 0xff;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700360
361 value = snd_ca0106_ptr_read(emu, reg, channel_id);
362 ucontrol->value.integer.value[0] = 0xff - ((value >> 24) & 0xff); /* Left */
363 ucontrol->value.integer.value[1] = 0xff - ((value >> 16) & 0xff); /* Right */
364 return 0;
365}
366
Takashi Iwaie4a3d142005-11-17 14:55:40 +0100367static int snd_ca0106_volume_put(struct snd_kcontrol *kcontrol,
368 struct snd_ctl_elem_value *ucontrol)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700369{
Takashi Iwaie4a3d142005-11-17 14:55:40 +0100370 struct snd_ca0106 *emu = snd_kcontrol_chip(kcontrol);
Takashi Iwai95a98262005-11-17 10:40:18 +0100371 unsigned int oval, nval;
372 int channel_id, reg;
373
374 channel_id = (kcontrol->private_value >> 8) & 0xff;
375 reg = kcontrol->private_value & 0xff;
376
377 oval = snd_ca0106_ptr_read(emu, reg, channel_id);
378 nval = ((0xff - ucontrol->value.integer.value[0]) << 24) |
379 ((0xff - ucontrol->value.integer.value[1]) << 16);
380 nval |= ((0xff - ucontrol->value.integer.value[0]) << 8) |
381 ((0xff - ucontrol->value.integer.value[1]) );
382 if (oval == nval)
383 return 0;
384 snd_ca0106_ptr_write(emu, reg, channel_id, nval);
385 return 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700386}
387
James Courtier-Dutton6129daa2006-04-09 13:01:34 +0100388static int snd_ca0106_i2c_volume_info(struct snd_kcontrol *kcontrol,
389 struct snd_ctl_elem_info *uinfo)
390{
391 uinfo->type = SNDRV_CTL_ELEM_TYPE_INTEGER;
392 uinfo->count = 2;
393 uinfo->value.integer.min = 0;
394 uinfo->value.integer.max = 255;
395 return 0;
396}
397
398static int snd_ca0106_i2c_volume_get(struct snd_kcontrol *kcontrol,
399 struct snd_ctl_elem_value *ucontrol)
400{
401 struct snd_ca0106 *emu = snd_kcontrol_chip(kcontrol);
402 int source_id;
403
404 source_id = kcontrol->private_value;
405
406 ucontrol->value.integer.value[0] = emu->i2c_capture_volume[source_id][0];
407 ucontrol->value.integer.value[1] = emu->i2c_capture_volume[source_id][1];
408 return 0;
409}
410
411static int snd_ca0106_i2c_volume_put(struct snd_kcontrol *kcontrol,
412 struct snd_ctl_elem_value *ucontrol)
413{
414 struct snd_ca0106 *emu = snd_kcontrol_chip(kcontrol);
415 unsigned int ogain;
416 unsigned int ngain;
417 int source_id;
418 int change = 0;
419
420 source_id = kcontrol->private_value;
421 ogain = emu->i2c_capture_volume[source_id][0]; /* Left */
422 ngain = ucontrol->value.integer.value[0];
423 if (ngain > 0xff)
424 return 0;
425 if (ogain != ngain) {
426 if (emu->i2c_capture_source == source_id)
427 snd_ca0106_i2c_write(emu, ADC_ATTEN_ADCL, ((ngain) & 0xff) );
428 emu->i2c_capture_volume[source_id][0] = ucontrol->value.integer.value[0];
429 change = 1;
430 }
431 ogain = emu->i2c_capture_volume[source_id][1]; /* Right */
432 ngain = ucontrol->value.integer.value[1];
433 if (ngain > 0xff)
434 return 0;
435 if (ogain != ngain) {
436 if (emu->i2c_capture_source == source_id)
437 snd_ca0106_i2c_write(emu, ADC_ATTEN_ADCR, ((ngain) & 0xff));
438 emu->i2c_capture_volume[source_id][1] = ucontrol->value.integer.value[1];
439 change = 1;
440 }
441
442 return change;
443}
444
Takashi Iwai95a98262005-11-17 10:40:18 +0100445#define CA_VOLUME(xname,chid,reg) \
446{ \
447 .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = xname, \
James Courtier-Dutton6129daa2006-04-09 13:01:34 +0100448 .info = snd_ca0106_volume_info, \
449 .get = snd_ca0106_volume_get, \
450 .put = snd_ca0106_volume_put, \
Takashi Iwai95a98262005-11-17 10:40:18 +0100451 .private_value = ((chid) << 8) | (reg) \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700452}
453
James Courtier-Dutton6129daa2006-04-09 13:01:34 +0100454#define I2C_VOLUME(xname,chid) \
455{ \
456 .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = xname, \
457 .info = snd_ca0106_i2c_volume_info, \
458 .get = snd_ca0106_i2c_volume_get, \
459 .put = snd_ca0106_i2c_volume_put, \
460 .private_value = chid \
461}
462
Takashi Iwai95a98262005-11-17 10:40:18 +0100463
Takashi Iwaie4a3d142005-11-17 14:55:40 +0100464static struct snd_kcontrol_new snd_ca0106_volume_ctls[] __devinitdata = {
Takashi Iwai95a98262005-11-17 10:40:18 +0100465 CA_VOLUME("Analog Front Playback Volume",
466 CONTROL_FRONT_CHANNEL, PLAYBACK_VOLUME2),
467 CA_VOLUME("Analog Rear Playback Volume",
468 CONTROL_REAR_CHANNEL, PLAYBACK_VOLUME2),
469 CA_VOLUME("Analog Center/LFE Playback Volume",
470 CONTROL_CENTER_LFE_CHANNEL, PLAYBACK_VOLUME2),
471 CA_VOLUME("Analog Side Playback Volume",
472 CONTROL_UNKNOWN_CHANNEL, PLAYBACK_VOLUME2),
473
James Courtier-Dutton39596dc2005-12-16 21:59:59 +0100474 CA_VOLUME("IEC958 Front Playback Volume",
Takashi Iwai95a98262005-11-17 10:40:18 +0100475 CONTROL_FRONT_CHANNEL, PLAYBACK_VOLUME1),
James Courtier-Dutton39596dc2005-12-16 21:59:59 +0100476 CA_VOLUME("IEC958 Rear Playback Volume",
Takashi Iwai95a98262005-11-17 10:40:18 +0100477 CONTROL_REAR_CHANNEL, PLAYBACK_VOLUME1),
James Courtier-Dutton39596dc2005-12-16 21:59:59 +0100478 CA_VOLUME("IEC958 Center/LFE Playback Volume",
Takashi Iwai95a98262005-11-17 10:40:18 +0100479 CONTROL_CENTER_LFE_CHANNEL, PLAYBACK_VOLUME1),
James Courtier-Dutton39596dc2005-12-16 21:59:59 +0100480 CA_VOLUME("IEC958 Unknown Playback Volume",
Takashi Iwai95a98262005-11-17 10:40:18 +0100481 CONTROL_UNKNOWN_CHANNEL, PLAYBACK_VOLUME1),
482
483 CA_VOLUME("CAPTURE feedback Playback Volume",
484 1, CAPTURE_CONTROL),
485
James Courtier-Dutton6129daa2006-04-09 13:01:34 +0100486 I2C_VOLUME("Phone Capture Volume", 0),
487 I2C_VOLUME("Mic Capture Volume", 1),
488 I2C_VOLUME("Line in Capture Volume", 2),
489 I2C_VOLUME("Aux Capture Volume", 3),
490
Takashi Iwai95a98262005-11-17 10:40:18 +0100491 {
492 .access = SNDRV_CTL_ELEM_ACCESS_READ,
493 .iface = SNDRV_CTL_ELEM_IFACE_PCM,
494 .name = SNDRV_CTL_NAME_IEC958("",PLAYBACK,MASK),
495 .count = 4,
496 .info = snd_ca0106_spdif_info,
497 .get = snd_ca0106_spdif_get_mask
498 },
499 {
500 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
James Courtier-Dutton39596dc2005-12-16 21:59:59 +0100501 .name = "IEC958 Playback Switch",
Takashi Iwai95a98262005-11-17 10:40:18 +0100502 .info = snd_ca0106_shared_spdif_info,
503 .get = snd_ca0106_shared_spdif_get,
504 .put = snd_ca0106_shared_spdif_put
505 },
506 {
507 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
James Courtier-Dutton6129daa2006-04-09 13:01:34 +0100508 .name = "Digital Capture Source",
Takashi Iwai95a98262005-11-17 10:40:18 +0100509 .info = snd_ca0106_capture_source_info,
510 .get = snd_ca0106_capture_source_get,
511 .put = snd_ca0106_capture_source_put
512 },
513 {
James Courtier-Dutton6129daa2006-04-09 13:01:34 +0100514 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
515 .name = "Capture Source",
516 .info = snd_ca0106_i2c_capture_source_info,
517 .get = snd_ca0106_i2c_capture_source_get,
518 .put = snd_ca0106_i2c_capture_source_put
519 },
520 {
Takashi Iwai95a98262005-11-17 10:40:18 +0100521 .iface = SNDRV_CTL_ELEM_IFACE_PCM,
522 .name = SNDRV_CTL_NAME_IEC958("",PLAYBACK,DEFAULT),
523 .count = 4,
524 .info = snd_ca0106_spdif_info,
525 .get = snd_ca0106_spdif_get,
526 .put = snd_ca0106_spdif_put
527 },
Linus Torvalds1da177e2005-04-16 15:20:36 -0700528};
529
Takashi Iwaie4a3d142005-11-17 14:55:40 +0100530static int __devinit remove_ctl(struct snd_card *card, const char *name)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700531{
Takashi Iwaie4a3d142005-11-17 14:55:40 +0100532 struct snd_ctl_elem_id id;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700533 memset(&id, 0, sizeof(id));
534 strcpy(id.name, name);
535 id.iface = SNDRV_CTL_ELEM_IFACE_MIXER;
536 return snd_ctl_remove_id(card, &id);
537}
538
Takashi Iwaie4a3d142005-11-17 14:55:40 +0100539static struct snd_kcontrol __devinit *ctl_find(struct snd_card *card, const char *name)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700540{
Takashi Iwaie4a3d142005-11-17 14:55:40 +0100541 struct snd_ctl_elem_id sid;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700542 memset(&sid, 0, sizeof(sid));
543 /* FIXME: strcpy is bad. */
544 strcpy(sid.name, name);
545 sid.iface = SNDRV_CTL_ELEM_IFACE_MIXER;
546 return snd_ctl_find_id(card, &sid);
547}
548
Takashi Iwaie4a3d142005-11-17 14:55:40 +0100549static int __devinit rename_ctl(struct snd_card *card, const char *src, const char *dst)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700550{
Takashi Iwaie4a3d142005-11-17 14:55:40 +0100551 struct snd_kcontrol *kctl = ctl_find(card, src);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700552 if (kctl) {
553 strcpy(kctl->id.name, dst);
554 return 0;
555 }
556 return -ENOENT;
557}
558
Takashi Iwaie4a3d142005-11-17 14:55:40 +0100559int __devinit snd_ca0106_mixer(struct snd_ca0106 *emu)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700560{
Takashi Iwai95a98262005-11-17 10:40:18 +0100561 int i, err;
Takashi Iwaie4a3d142005-11-17 14:55:40 +0100562 struct snd_card *card = emu->card;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700563 char **c;
564 static char *ca0106_remove_ctls[] = {
565 "Master Mono Playback Switch",
566 "Master Mono Playback Volume",
567 "3D Control - Switch",
568 "3D Control Sigmatel - Depth",
569 "PCM Playback Switch",
570 "PCM Playback Volume",
571 "CD Playback Switch",
572 "CD Playback Volume",
573 "Phone Playback Switch",
574 "Phone Playback Volume",
575 "Video Playback Switch",
576 "Video Playback Volume",
577 "PC Speaker Playback Switch",
578 "PC Speaker Playback Volume",
579 "Mono Output Select",
580 "Capture Source",
581 "Capture Switch",
582 "Capture Volume",
583 "External Amplifier",
584 "Sigmatel 4-Speaker Stereo Playback Switch",
585 "Sigmatel Surround Phase Inversion Playback ",
586 NULL
587 };
588 static char *ca0106_rename_ctls[] = {
589 "Master Playback Switch", "Capture Switch",
590 "Master Playback Volume", "Capture Volume",
591 "Line Playback Switch", "AC97 Line Capture Switch",
592 "Line Playback Volume", "AC97 Line Capture Volume",
593 "Aux Playback Switch", "AC97 Aux Capture Switch",
594 "Aux Playback Volume", "AC97 Aux Capture Volume",
595 "Mic Playback Switch", "AC97 Mic Capture Switch",
596 "Mic Playback Volume", "AC97 Mic Capture Volume",
597 "Mic Select", "AC97 Mic Select",
598 "Mic Boost (+20dB)", "AC97 Mic Boost (+20dB)",
599 NULL
600 };
601#if 1
Takashi Iwai95a98262005-11-17 10:40:18 +0100602 for (c = ca0106_remove_ctls; *c; c++)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700603 remove_ctl(card, *c);
Takashi Iwai95a98262005-11-17 10:40:18 +0100604 for (c = ca0106_rename_ctls; *c; c += 2)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700605 rename_ctl(card, c[0], c[1]);
606#endif
607
Takashi Iwai95a98262005-11-17 10:40:18 +0100608 for (i = 0; i < ARRAY_SIZE(snd_ca0106_volume_ctls); i++) {
609 err = snd_ctl_add(card, snd_ctl_new1(&snd_ca0106_volume_ctls[i], emu));
610 if (err < 0)
James Courtier-Duttoned144f32005-05-27 23:28:27 +0200611 return err;
612 }
Takashi Iwai95a98262005-11-17 10:40:18 +0100613 if (emu->details->i2c_adc == 1) {
614 err = snd_ctl_add(card, snd_ctl_new1(&snd_ca0106_capture_mic_line_in, emu));
615 if (err < 0)
616 return err;
617 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700618 return 0;
619}
620