diff options
author | Clemens Ladisch <clemens@ladisch.de> | 2007-12-23 13:50:57 -0500 |
---|---|---|
committer | Jaroslav Kysela <perex@perex.cz> | 2008-01-31 11:29:44 -0500 |
commit | d0ce9946c52e7bdf95afb09553775cf28b752254 (patch) | |
tree | 684edc99cfd1def12b87abb5431c6b8f0ea2f716 /sound/pci/oxygen/oxygen_mixer.c | |
parent | a9b3aa8a0a203b9b62e15c465ba7d4797a6a2c79 (diff) |
[ALSA] add CMI8788 driver
Add the snd-oxygen driver for the C-Media CMI8788 (Oxygen) chip, used on
the Asound A-8788, AuzenTech X-Meridian, Bgears b-Enspirer,
Club3D Theatron DTS, HT-Omega Claro, Razer Barracuda AC-1,
Sondigo Inferno, and TempoTec HIFIER sound cards.
Signed-off-by: Clemens Ladisch <clemens@ladisch.de>
Signed-off-by: Jaroslav Kysela <perex@perex.cz>
Diffstat (limited to 'sound/pci/oxygen/oxygen_mixer.c')
-rw-r--r-- | sound/pci/oxygen/oxygen_mixer.c | 623 |
1 files changed, 623 insertions, 0 deletions
diff --git a/sound/pci/oxygen/oxygen_mixer.c b/sound/pci/oxygen/oxygen_mixer.c new file mode 100644 index 000000000000..e252abac004e --- /dev/null +++ b/sound/pci/oxygen/oxygen_mixer.c | |||
@@ -0,0 +1,623 @@ | |||
1 | /* | ||
2 | * C-Media CMI8788 driver - mixer code | ||
3 | * | ||
4 | * Copyright (c) Clemens Ladisch <clemens@ladisch.de> | ||
5 | * | ||
6 | * | ||
7 | * This driver is free software; you can redistribute it and/or modify | ||
8 | * it under the terms of the GNU General Public License, version 2. | ||
9 | * | ||
10 | * This driver is distributed in the hope that it will be useful, | ||
11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
13 | * GNU General Public License for more details. | ||
14 | * | ||
15 | * You should have received a copy of the GNU General Public License | ||
16 | * along with this driver; if not, write to the Free Software | ||
17 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA | ||
18 | */ | ||
19 | |||
20 | #include <sound/driver.h> | ||
21 | #include <linux/mutex.h> | ||
22 | #include <sound/ac97_codec.h> | ||
23 | #include <sound/asoundef.h> | ||
24 | #include <sound/control.h> | ||
25 | #include <sound/tlv.h> | ||
26 | #include "oxygen.h" | ||
27 | |||
28 | static int dac_volume_info(struct snd_kcontrol *ctl, | ||
29 | struct snd_ctl_elem_info *info) | ||
30 | { | ||
31 | struct oxygen *chip = ctl->private_data; | ||
32 | |||
33 | info->type = SNDRV_CTL_ELEM_TYPE_INTEGER; | ||
34 | info->count = 8; | ||
35 | info->value.integer.min = chip->model->dac_minimum_volume; | ||
36 | info->value.integer.max = 0xff; | ||
37 | return 0; | ||
38 | } | ||
39 | |||
40 | static int dac_volume_get(struct snd_kcontrol *ctl, | ||
41 | struct snd_ctl_elem_value *value) | ||
42 | { | ||
43 | struct oxygen *chip = ctl->private_data; | ||
44 | unsigned int i; | ||
45 | |||
46 | mutex_lock(&chip->mutex); | ||
47 | for (i = 0; i < 8; ++i) | ||
48 | value->value.integer.value[i] = chip->dac_volume[i]; | ||
49 | mutex_unlock(&chip->mutex); | ||
50 | return 0; | ||
51 | } | ||
52 | |||
53 | static int dac_volume_put(struct snd_kcontrol *ctl, | ||
54 | struct snd_ctl_elem_value *value) | ||
55 | { | ||
56 | struct oxygen *chip = ctl->private_data; | ||
57 | unsigned int i; | ||
58 | int changed; | ||
59 | |||
60 | changed = 0; | ||
61 | mutex_lock(&chip->mutex); | ||
62 | for (i = 0; i < 8; ++i) | ||
63 | if (value->value.integer.value[i] != chip->dac_volume[i]) { | ||
64 | chip->dac_volume[i] = value->value.integer.value[i]; | ||
65 | changed = 1; | ||
66 | } | ||
67 | if (changed) | ||
68 | chip->model->update_dac_volume(chip); | ||
69 | mutex_unlock(&chip->mutex); | ||
70 | return changed; | ||
71 | } | ||
72 | |||
73 | static int dac_mute_get(struct snd_kcontrol *ctl, | ||
74 | struct snd_ctl_elem_value *value) | ||
75 | { | ||
76 | struct oxygen *chip = ctl->private_data; | ||
77 | |||
78 | mutex_lock(&chip->mutex); | ||
79 | value->value.integer.value[0] = !chip->dac_mute; | ||
80 | mutex_unlock(&chip->mutex); | ||
81 | return 0; | ||
82 | } | ||
83 | |||
84 | static int dac_mute_put(struct snd_kcontrol *ctl, | ||
85 | struct snd_ctl_elem_value *value) | ||
86 | { | ||
87 | struct oxygen *chip = ctl->private_data; | ||
88 | int changed; | ||
89 | |||
90 | mutex_lock(&chip->mutex); | ||
91 | changed = !value->value.integer.value[0] != chip->dac_mute; | ||
92 | if (changed) { | ||
93 | chip->dac_mute = !value->value.integer.value[0]; | ||
94 | chip->model->update_dac_mute(chip); | ||
95 | } | ||
96 | mutex_unlock(&chip->mutex); | ||
97 | return changed; | ||
98 | } | ||
99 | |||
100 | static int upmix_info(struct snd_kcontrol *ctl, struct snd_ctl_elem_info *info) | ||
101 | { | ||
102 | static const char *const names[3] = { | ||
103 | "Front", "Front+Rear", "Front+Rear+Side" | ||
104 | }; | ||
105 | info->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED; | ||
106 | info->count = 1; | ||
107 | info->value.enumerated.items = 3; | ||
108 | if (info->value.enumerated.item > 2) | ||
109 | info->value.enumerated.item = 2; | ||
110 | strcpy(info->value.enumerated.name, names[info->value.enumerated.item]); | ||
111 | return 0; | ||
112 | } | ||
113 | |||
114 | static int upmix_get(struct snd_kcontrol *ctl, struct snd_ctl_elem_value *value) | ||
115 | { | ||
116 | struct oxygen *chip = ctl->private_data; | ||
117 | |||
118 | mutex_lock(&chip->mutex); | ||
119 | value->value.enumerated.item[0] = chip->dac_routing; | ||
120 | mutex_unlock(&chip->mutex); | ||
121 | return 0; | ||
122 | } | ||
123 | |||
124 | void oxygen_update_dac_routing(struct oxygen *chip) | ||
125 | { | ||
126 | /* | ||
127 | * hardware channel order: front, side, center/lfe, rear | ||
128 | * ALSA channel order: front, rear, center/lfe, side | ||
129 | */ | ||
130 | static const unsigned int reg_values[3] = { | ||
131 | 0x6c00, 0x2c00, 0x2000 | ||
132 | }; | ||
133 | unsigned int reg_value; | ||
134 | |||
135 | if ((oxygen_read8(chip, OXYGEN_PLAY_CHANNELS) & | ||
136 | OXYGEN_PLAY_CHANNELS_MASK) == OXYGEN_PLAY_CHANNELS_2) | ||
137 | reg_value = reg_values[chip->dac_routing]; | ||
138 | else | ||
139 | reg_value = 0x6c00; | ||
140 | oxygen_write16_masked(chip, OXYGEN_PLAY_ROUTING, reg_value, 0xff00); | ||
141 | } | ||
142 | |||
143 | static int upmix_put(struct snd_kcontrol *ctl, struct snd_ctl_elem_value *value) | ||
144 | { | ||
145 | struct oxygen *chip = ctl->private_data; | ||
146 | int changed; | ||
147 | |||
148 | mutex_lock(&chip->mutex); | ||
149 | changed = value->value.enumerated.item[0] != chip->dac_routing; | ||
150 | if (changed) { | ||
151 | chip->dac_routing = min(value->value.enumerated.item[0], 2u); | ||
152 | spin_lock_irq(&chip->reg_lock); | ||
153 | oxygen_update_dac_routing(chip); | ||
154 | spin_unlock_irq(&chip->reg_lock); | ||
155 | } | ||
156 | mutex_unlock(&chip->mutex); | ||
157 | return changed; | ||
158 | } | ||
159 | |||
160 | static int spdif_switch_get(struct snd_kcontrol *ctl, | ||
161 | struct snd_ctl_elem_value *value) | ||
162 | { | ||
163 | struct oxygen *chip = ctl->private_data; | ||
164 | |||
165 | mutex_lock(&chip->mutex); | ||
166 | value->value.integer.value[0] = chip->spdif_playback_enable; | ||
167 | mutex_unlock(&chip->mutex); | ||
168 | return 0; | ||
169 | } | ||
170 | |||
171 | static unsigned int oxygen_spdif_rate(unsigned int oxygen_rate) | ||
172 | { | ||
173 | switch (oxygen_rate) { | ||
174 | case OXYGEN_RATE_32000: | ||
175 | return IEC958_AES3_CON_FS_32000 << OXYGEN_SPDIF_CS_RATE_SHIFT; | ||
176 | case OXYGEN_RATE_44100: | ||
177 | return IEC958_AES3_CON_FS_44100 << OXYGEN_SPDIF_CS_RATE_SHIFT; | ||
178 | default: /* OXYGEN_RATE_48000 */ | ||
179 | return IEC958_AES3_CON_FS_48000 << OXYGEN_SPDIF_CS_RATE_SHIFT; | ||
180 | case OXYGEN_RATE_64000: | ||
181 | return 0xb << OXYGEN_SPDIF_CS_RATE_SHIFT; | ||
182 | case OXYGEN_RATE_88200: | ||
183 | return 0x8 << OXYGEN_SPDIF_CS_RATE_SHIFT; | ||
184 | case OXYGEN_RATE_96000: | ||
185 | return 0xa << OXYGEN_SPDIF_CS_RATE_SHIFT; | ||
186 | case OXYGEN_RATE_176400: | ||
187 | return 0xc << OXYGEN_SPDIF_CS_RATE_SHIFT; | ||
188 | case OXYGEN_RATE_192000: | ||
189 | return 0xe << OXYGEN_SPDIF_CS_RATE_SHIFT; | ||
190 | } | ||
191 | } | ||
192 | |||
193 | void oxygen_update_spdif_source(struct oxygen *chip) | ||
194 | { | ||
195 | u32 old_control, new_control; | ||
196 | u16 old_routing, new_routing; | ||
197 | unsigned int oxygen_rate; | ||
198 | |||
199 | old_control = oxygen_read32(chip, OXYGEN_SPDIF_CONTROL); | ||
200 | old_routing = oxygen_read16(chip, OXYGEN_PLAY_ROUTING); | ||
201 | if (chip->pcm_active & (1 << PCM_SPDIF)) { | ||
202 | new_control = old_control | OXYGEN_SPDIF_OUT_ENABLE; | ||
203 | new_routing = (old_routing & ~0x00e0) | 0x0000; | ||
204 | oxygen_rate = (old_control >> OXYGEN_SPDIF_OUT_RATE_SHIFT) | ||
205 | & OXYGEN_I2S_RATE_MASK; | ||
206 | /* S/PDIF rate was already set by the caller */ | ||
207 | } else if ((chip->pcm_active & (1 << PCM_MULTICH)) && | ||
208 | chip->spdif_playback_enable) { | ||
209 | new_routing = (old_routing & ~0x00e0) | 0x0020; | ||
210 | oxygen_rate = oxygen_read16(chip, OXYGEN_I2S_MULTICH_FORMAT) | ||
211 | & OXYGEN_I2S_RATE_MASK; | ||
212 | new_control = (old_control & ~OXYGEN_SPDIF_OUT_RATE_MASK) | | ||
213 | (oxygen_rate << OXYGEN_SPDIF_OUT_RATE_SHIFT) | | ||
214 | OXYGEN_SPDIF_OUT_ENABLE; | ||
215 | } else { | ||
216 | new_control = old_control & ~OXYGEN_SPDIF_OUT_ENABLE; | ||
217 | new_routing = old_routing; | ||
218 | oxygen_rate = OXYGEN_RATE_44100; | ||
219 | } | ||
220 | if (old_routing != new_routing) { | ||
221 | oxygen_write32(chip, OXYGEN_SPDIF_CONTROL, | ||
222 | new_control & ~OXYGEN_SPDIF_OUT_ENABLE); | ||
223 | oxygen_write16(chip, OXYGEN_PLAY_ROUTING, new_routing); | ||
224 | } | ||
225 | if (new_control & OXYGEN_SPDIF_OUT_ENABLE) | ||
226 | oxygen_write32(chip, OXYGEN_SPDIF_OUTPUT_BITS, | ||
227 | oxygen_spdif_rate(oxygen_rate) | | ||
228 | ((chip->pcm_active & (1 << PCM_SPDIF)) ? | ||
229 | chip->spdif_pcm_bits : chip->spdif_bits)); | ||
230 | oxygen_write32(chip, OXYGEN_SPDIF_CONTROL, new_control); | ||
231 | } | ||
232 | |||
233 | static int spdif_switch_put(struct snd_kcontrol *ctl, | ||
234 | struct snd_ctl_elem_value *value) | ||
235 | { | ||
236 | struct oxygen *chip = ctl->private_data; | ||
237 | int changed; | ||
238 | |||
239 | mutex_lock(&chip->mutex); | ||
240 | changed = value->value.integer.value[0] != chip->spdif_playback_enable; | ||
241 | if (changed) { | ||
242 | chip->spdif_playback_enable = !!value->value.integer.value[0]; | ||
243 | spin_lock_irq(&chip->reg_lock); | ||
244 | oxygen_update_spdif_source(chip); | ||
245 | spin_unlock_irq(&chip->reg_lock); | ||
246 | } | ||
247 | mutex_unlock(&chip->mutex); | ||
248 | return changed; | ||
249 | } | ||
250 | |||
251 | static int spdif_info(struct snd_kcontrol *ctl, struct snd_ctl_elem_info *info) | ||
252 | { | ||
253 | info->type = SNDRV_CTL_ELEM_TYPE_IEC958; | ||
254 | info->count = 1; | ||
255 | return 0; | ||
256 | } | ||
257 | |||
258 | static void oxygen_to_iec958(u32 bits, struct snd_ctl_elem_value *value) | ||
259 | { | ||
260 | value->value.iec958.status[0] = | ||
261 | bits & (OXYGEN_SPDIF_NONAUDIO | OXYGEN_SPDIF_C | | ||
262 | OXYGEN_SPDIF_PREEMPHASIS); | ||
263 | value->value.iec958.status[1] = /* category and original */ | ||
264 | bits >> OXYGEN_SPDIF_CATEGORY_SHIFT; | ||
265 | } | ||
266 | |||
267 | static u32 iec958_to_oxygen(struct snd_ctl_elem_value *value) | ||
268 | { | ||
269 | u32 bits; | ||
270 | |||
271 | bits = value->value.iec958.status[0] & | ||
272 | (OXYGEN_SPDIF_NONAUDIO | OXYGEN_SPDIF_C | | ||
273 | OXYGEN_SPDIF_PREEMPHASIS); | ||
274 | bits |= value->value.iec958.status[1] << OXYGEN_SPDIF_CATEGORY_SHIFT; | ||
275 | if (bits & OXYGEN_SPDIF_NONAUDIO) | ||
276 | bits |= OXYGEN_SPDIF_V; | ||
277 | return bits; | ||
278 | } | ||
279 | |||
280 | static inline void write_spdif_bits(struct oxygen *chip, u32 bits) | ||
281 | { | ||
282 | oxygen_write32_masked(chip, OXYGEN_SPDIF_OUTPUT_BITS, bits, | ||
283 | OXYGEN_SPDIF_NONAUDIO | | ||
284 | OXYGEN_SPDIF_C | | ||
285 | OXYGEN_SPDIF_PREEMPHASIS | | ||
286 | OXYGEN_SPDIF_CATEGORY_MASK | | ||
287 | OXYGEN_SPDIF_ORIGINAL | | ||
288 | OXYGEN_SPDIF_V); | ||
289 | } | ||
290 | |||
291 | static int spdif_default_get(struct snd_kcontrol *ctl, | ||
292 | struct snd_ctl_elem_value *value) | ||
293 | { | ||
294 | struct oxygen *chip = ctl->private_data; | ||
295 | |||
296 | mutex_lock(&chip->mutex); | ||
297 | oxygen_to_iec958(chip->spdif_bits, value); | ||
298 | mutex_unlock(&chip->mutex); | ||
299 | return 0; | ||
300 | } | ||
301 | |||
302 | static int spdif_default_put(struct snd_kcontrol *ctl, | ||
303 | struct snd_ctl_elem_value *value) | ||
304 | { | ||
305 | struct oxygen *chip = ctl->private_data; | ||
306 | u32 new_bits; | ||
307 | int changed; | ||
308 | |||
309 | new_bits = iec958_to_oxygen(value); | ||
310 | mutex_lock(&chip->mutex); | ||
311 | changed = new_bits != chip->spdif_bits; | ||
312 | if (changed) { | ||
313 | chip->spdif_bits = new_bits; | ||
314 | if (!(chip->pcm_active & (1 << PCM_SPDIF))) | ||
315 | write_spdif_bits(chip, new_bits); | ||
316 | } | ||
317 | mutex_unlock(&chip->mutex); | ||
318 | return changed; | ||
319 | } | ||
320 | |||
321 | static int spdif_mask_get(struct snd_kcontrol *ctl, | ||
322 | struct snd_ctl_elem_value *value) | ||
323 | { | ||
324 | value->value.iec958.status[0] = IEC958_AES0_NONAUDIO | | ||
325 | IEC958_AES0_CON_NOT_COPYRIGHT | IEC958_AES0_CON_EMPHASIS; | ||
326 | value->value.iec958.status[1] = | ||
327 | IEC958_AES1_CON_CATEGORY | IEC958_AES1_CON_ORIGINAL; | ||
328 | return 0; | ||
329 | } | ||
330 | |||
331 | static int spdif_pcm_get(struct snd_kcontrol *ctl, | ||
332 | struct snd_ctl_elem_value *value) | ||
333 | { | ||
334 | struct oxygen *chip = ctl->private_data; | ||
335 | |||
336 | mutex_lock(&chip->mutex); | ||
337 | oxygen_to_iec958(chip->spdif_pcm_bits, value); | ||
338 | mutex_unlock(&chip->mutex); | ||
339 | return 0; | ||
340 | } | ||
341 | |||
342 | static int spdif_pcm_put(struct snd_kcontrol *ctl, | ||
343 | struct snd_ctl_elem_value *value) | ||
344 | { | ||
345 | struct oxygen *chip = ctl->private_data; | ||
346 | u32 new_bits; | ||
347 | int changed; | ||
348 | |||
349 | new_bits = iec958_to_oxygen(value); | ||
350 | mutex_lock(&chip->mutex); | ||
351 | changed = new_bits != chip->spdif_pcm_bits; | ||
352 | if (changed) { | ||
353 | chip->spdif_pcm_bits = new_bits; | ||
354 | if (chip->pcm_active & (1 << PCM_SPDIF)) | ||
355 | write_spdif_bits(chip, new_bits); | ||
356 | } | ||
357 | mutex_unlock(&chip->mutex); | ||
358 | return changed; | ||
359 | } | ||
360 | |||
361 | static int spdif_input_mask_get(struct snd_kcontrol *ctl, | ||
362 | struct snd_ctl_elem_value *value) | ||
363 | { | ||
364 | value->value.iec958.status[0] = 0xff; | ||
365 | value->value.iec958.status[1] = 0xff; | ||
366 | value->value.iec958.status[2] = 0xff; | ||
367 | value->value.iec958.status[3] = 0xff; | ||
368 | return 0; | ||
369 | } | ||
370 | |||
371 | static int spdif_input_default_get(struct snd_kcontrol *ctl, | ||
372 | struct snd_ctl_elem_value *value) | ||
373 | { | ||
374 | struct oxygen *chip = ctl->private_data; | ||
375 | u32 bits; | ||
376 | |||
377 | bits = oxygen_read32(chip, OXYGEN_SPDIF_INPUT_BITS); | ||
378 | value->value.iec958.status[0] = bits; | ||
379 | value->value.iec958.status[1] = bits >> 8; | ||
380 | value->value.iec958.status[2] = bits >> 16; | ||
381 | value->value.iec958.status[3] = bits >> 24; | ||
382 | return 0; | ||
383 | } | ||
384 | |||
385 | static int ac97_switch_get(struct snd_kcontrol *ctl, | ||
386 | struct snd_ctl_elem_value *value) | ||
387 | { | ||
388 | struct oxygen *chip = ctl->private_data; | ||
389 | unsigned int index = ctl->private_value & 0xff; | ||
390 | unsigned int bitnr = (ctl->private_value >> 8) & 0xff; | ||
391 | int invert = ctl->private_value & (1 << 16); | ||
392 | u16 reg; | ||
393 | |||
394 | mutex_lock(&chip->mutex); | ||
395 | reg = oxygen_read_ac97(chip, 0, index); | ||
396 | mutex_unlock(&chip->mutex); | ||
397 | if (!(reg & (1 << bitnr)) ^ !invert) | ||
398 | value->value.integer.value[0] = 1; | ||
399 | else | ||
400 | value->value.integer.value[0] = 0; | ||
401 | return 0; | ||
402 | } | ||
403 | |||
404 | static int ac97_switch_put(struct snd_kcontrol *ctl, | ||
405 | struct snd_ctl_elem_value *value) | ||
406 | { | ||
407 | struct oxygen *chip = ctl->private_data; | ||
408 | unsigned int index = ctl->private_value & 0xff; | ||
409 | unsigned int bitnr = (ctl->private_value >> 8) & 0xff; | ||
410 | int invert = ctl->private_value & (1 << 16); | ||
411 | u16 oldreg, newreg; | ||
412 | int change; | ||
413 | |||
414 | mutex_lock(&chip->mutex); | ||
415 | oldreg = oxygen_read_ac97(chip, 0, index); | ||
416 | newreg = oldreg; | ||
417 | if (!value->value.integer.value[0] ^ !invert) | ||
418 | newreg |= 1 << bitnr; | ||
419 | else | ||
420 | newreg &= ~(1 << bitnr); | ||
421 | change = newreg != oldreg; | ||
422 | if (change) { | ||
423 | oxygen_write_ac97(chip, 0, index, newreg); | ||
424 | if (index == AC97_LINE) | ||
425 | oxygen_write_ac97_masked(chip, 0, 0x72, | ||
426 | !!(newreg & 0x8000), 0x0001); | ||
427 | } | ||
428 | mutex_unlock(&chip->mutex); | ||
429 | return change; | ||
430 | } | ||
431 | |||
432 | static int ac97_volume_info(struct snd_kcontrol *ctl, | ||
433 | struct snd_ctl_elem_info *info) | ||
434 | { | ||
435 | info->type = SNDRV_CTL_ELEM_TYPE_INTEGER; | ||
436 | info->count = 2; | ||
437 | info->value.integer.min = 0; | ||
438 | info->value.integer.max = 0x1f; | ||
439 | return 0; | ||
440 | } | ||
441 | |||
442 | static int ac97_volume_get(struct snd_kcontrol *ctl, | ||
443 | struct snd_ctl_elem_value *value) | ||
444 | { | ||
445 | struct oxygen *chip = ctl->private_data; | ||
446 | unsigned int index = ctl->private_value; | ||
447 | u16 reg; | ||
448 | |||
449 | mutex_lock(&chip->mutex); | ||
450 | reg = oxygen_read_ac97(chip, 0, index); | ||
451 | mutex_unlock(&chip->mutex); | ||
452 | value->value.integer.value[0] = 31 - (reg & 0x1f); | ||
453 | value->value.integer.value[1] = 31 - ((reg >> 8) & 0x1f); | ||
454 | return 0; | ||
455 | } | ||
456 | |||
457 | static int ac97_volume_put(struct snd_kcontrol *ctl, | ||
458 | struct snd_ctl_elem_value *value) | ||
459 | { | ||
460 | struct oxygen *chip = ctl->private_data; | ||
461 | unsigned int index = ctl->private_value; | ||
462 | u16 oldreg, newreg; | ||
463 | int change; | ||
464 | |||
465 | mutex_lock(&chip->mutex); | ||
466 | oldreg = oxygen_read_ac97(chip, 0, index); | ||
467 | newreg = oldreg; | ||
468 | newreg = (newreg & ~0x1f) | | ||
469 | (31 - (value->value.integer.value[0] & 0x1f)); | ||
470 | newreg = (newreg & ~0x1f00) | | ||
471 | ((31 - (value->value.integer.value[0] & 0x1f)) << 8); | ||
472 | change = newreg != oldreg; | ||
473 | if (change) | ||
474 | oxygen_write_ac97(chip, 0, index, newreg); | ||
475 | mutex_unlock(&chip->mutex); | ||
476 | return change; | ||
477 | } | ||
478 | |||
479 | #define AC97_SWITCH(xname, index, bitnr, invert) { \ | ||
480 | .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \ | ||
481 | .name = xname, \ | ||
482 | .info = snd_ctl_boolean_mono_info, \ | ||
483 | .get = ac97_switch_get, \ | ||
484 | .put = ac97_switch_put, \ | ||
485 | .private_value = ((invert) << 16) | ((bitnr) << 8) | (index), \ | ||
486 | } | ||
487 | #define AC97_VOLUME(xname, index) { \ | ||
488 | .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \ | ||
489 | .name = xname, \ | ||
490 | .info = ac97_volume_info, \ | ||
491 | .get = ac97_volume_get, \ | ||
492 | .put = ac97_volume_put, \ | ||
493 | .tlv = { .p = ac97_db_scale, }, \ | ||
494 | .private_value = (index), \ | ||
495 | } | ||
496 | |||
497 | static DECLARE_TLV_DB_SCALE(ac97_db_scale, -3450, 150, 0); | ||
498 | |||
499 | static const struct snd_kcontrol_new controls[] = { | ||
500 | { | ||
501 | .iface = SNDRV_CTL_ELEM_IFACE_MIXER, | ||
502 | .name = "PCM Playback Volume", | ||
503 | .access = SNDRV_CTL_ELEM_ACCESS_READWRITE | | ||
504 | SNDRV_CTL_ELEM_ACCESS_TLV_READ, | ||
505 | .info = dac_volume_info, | ||
506 | .get = dac_volume_get, | ||
507 | .put = dac_volume_put, | ||
508 | .tlv = { | ||
509 | .p = NULL, /* set later */ | ||
510 | }, | ||
511 | }, | ||
512 | { | ||
513 | .iface = SNDRV_CTL_ELEM_IFACE_MIXER, | ||
514 | .name = "PCM Playback Switch", | ||
515 | .info = snd_ctl_boolean_mono_info, | ||
516 | .get = dac_mute_get, | ||
517 | .put = dac_mute_put, | ||
518 | }, | ||
519 | { | ||
520 | .iface = SNDRV_CTL_ELEM_IFACE_MIXER, | ||
521 | .name = "Stereo Upmixing", | ||
522 | .info = upmix_info, | ||
523 | .get = upmix_get, | ||
524 | .put = upmix_put, | ||
525 | }, | ||
526 | { | ||
527 | .iface = SNDRV_CTL_ELEM_IFACE_MIXER, | ||
528 | .name = SNDRV_CTL_NAME_IEC958("", PLAYBACK, SWITCH), | ||
529 | .info = snd_ctl_boolean_mono_info, | ||
530 | .get = spdif_switch_get, | ||
531 | .put = spdif_switch_put, | ||
532 | }, | ||
533 | { | ||
534 | .iface = SNDRV_CTL_ELEM_IFACE_PCM, | ||
535 | .device = 1, | ||
536 | .name = SNDRV_CTL_NAME_IEC958("", PLAYBACK, DEFAULT), | ||
537 | .info = spdif_info, | ||
538 | .get = spdif_default_get, | ||
539 | .put = spdif_default_put, | ||
540 | }, | ||
541 | { | ||
542 | .iface = SNDRV_CTL_ELEM_IFACE_PCM, | ||
543 | .device = 1, | ||
544 | .name = SNDRV_CTL_NAME_IEC958("", PLAYBACK, CON_MASK), | ||
545 | .access = SNDRV_CTL_ELEM_ACCESS_READ, | ||
546 | .info = spdif_info, | ||
547 | .get = spdif_mask_get, | ||
548 | }, | ||
549 | { | ||
550 | .iface = SNDRV_CTL_ELEM_IFACE_PCM, | ||
551 | .device = 1, | ||
552 | .name = SNDRV_CTL_NAME_IEC958("", PLAYBACK, PCM_STREAM), | ||
553 | .access = SNDRV_CTL_ELEM_ACCESS_READWRITE | | ||
554 | SNDRV_CTL_ELEM_ACCESS_INACTIVE, | ||
555 | .info = spdif_info, | ||
556 | .get = spdif_pcm_get, | ||
557 | .put = spdif_pcm_put, | ||
558 | }, | ||
559 | { | ||
560 | .iface = SNDRV_CTL_ELEM_IFACE_PCM, | ||
561 | .device = 1, | ||
562 | .name = SNDRV_CTL_NAME_IEC958("", CAPTURE, MASK), | ||
563 | .access = SNDRV_CTL_ELEM_ACCESS_READ, | ||
564 | .info = spdif_info, | ||
565 | .get = spdif_input_mask_get, | ||
566 | }, | ||
567 | { | ||
568 | .iface = SNDRV_CTL_ELEM_IFACE_PCM, | ||
569 | .device = 1, | ||
570 | .name = SNDRV_CTL_NAME_IEC958("", CAPTURE, DEFAULT), | ||
571 | .access = SNDRV_CTL_ELEM_ACCESS_READ, | ||
572 | .info = spdif_info, | ||
573 | .get = spdif_input_default_get, | ||
574 | }, | ||
575 | AC97_VOLUME("Mic Capture Volume", AC97_MIC), | ||
576 | AC97_SWITCH("Mic Capture Switch", AC97_MIC, 15, 1), | ||
577 | AC97_SWITCH("Mic Boost (+20dB)", AC97_MIC, 6, 0), | ||
578 | AC97_SWITCH("Line Capture Switch", AC97_LINE, 15, 1), | ||
579 | AC97_VOLUME("CD Capture Volume", AC97_CD), | ||
580 | AC97_SWITCH("CD Capture Switch", AC97_CD, 15, 1), | ||
581 | AC97_VOLUME("Aux Capture Volume", AC97_AUX), | ||
582 | AC97_SWITCH("Aux Capture Switch", AC97_AUX, 15, 1), | ||
583 | }; | ||
584 | |||
585 | static void oxygen_any_ctl_free(struct snd_kcontrol *ctl) | ||
586 | { | ||
587 | struct oxygen *chip = ctl->private_data; | ||
588 | |||
589 | /* I'm too lazy to write a function for each control :-) */ | ||
590 | chip->spdif_pcm_ctl = NULL; | ||
591 | chip->spdif_input_bits_ctl = NULL; | ||
592 | } | ||
593 | |||
594 | int oxygen_mixer_init(struct oxygen *chip) | ||
595 | { | ||
596 | unsigned int i; | ||
597 | struct snd_kcontrol *ctl; | ||
598 | int err; | ||
599 | |||
600 | for (i = 0; i < ARRAY_SIZE(controls); ++i) { | ||
601 | ctl = snd_ctl_new1(&controls[i], chip); | ||
602 | if (!ctl) | ||
603 | return -ENOMEM; | ||
604 | if (!strcmp(ctl->id.name, "PCM Playback Volume")) | ||
605 | ctl->tlv.p = chip->model->dac_tlv; | ||
606 | else if (chip->model->cd_in_from_video_in && | ||
607 | !strncmp(ctl->id.name, "CD Capture ", 11)) | ||
608 | ctl->private_value ^= AC97_CD ^ AC97_VIDEO; | ||
609 | err = snd_ctl_add(chip->card, ctl); | ||
610 | if (err < 0) | ||
611 | return err; | ||
612 | if (!strcmp(ctl->id.name, | ||
613 | SNDRV_CTL_NAME_IEC958("", PLAYBACK, PCM_STREAM))) { | ||
614 | chip->spdif_pcm_ctl = ctl; | ||
615 | ctl->private_free = oxygen_any_ctl_free; | ||
616 | } else if (!strcmp(ctl->id.name, | ||
617 | SNDRV_CTL_NAME_IEC958("", CAPTURE, DEFAULT))) { | ||
618 | chip->spdif_input_bits_ctl = ctl; | ||
619 | ctl->private_free = oxygen_any_ctl_free; | ||
620 | } | ||
621 | } | ||
622 | return chip->model->mixer_init ? chip->model->mixer_init(chip) : 0; | ||
623 | } | ||