2 * Copyright (c) by Jaroslav Kysela <perex@suse.cz>
3 * Universal interface for Audio Codec '97
5 * For more details look to AC '97 component specification revision 2.2
6 * by Intel Corporation (http://developer.intel.com) and to datasheets
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.
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.
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
26 #include <sound/driver.h>
27 #include <linux/delay.h>
28 #include <linux/init.h>
29 #include <linux/slab.h>
30 #include <sound/core.h>
31 #include <sound/pcm.h>
32 #include <sound/control.h>
33 #include <sound/ac97_codec.h>
34 #include "ac97_patch.h"
36 #include "ac97_local.h"
39 * Chip specific initialization
42 static int patch_build_controls(ac97_t * ac97, const snd_kcontrol_new_t *controls, int count)
46 for (idx = 0; idx < count; idx++)
47 if ((err = snd_ctl_add(ac97->bus->card, snd_ac97_cnew(&controls[idx], ac97))) < 0)
52 /* set to the page, update bits and restore the page */
53 static int ac97_update_bits_page(ac97_t *ac97, unsigned short reg, unsigned short mask, unsigned short value, unsigned short page)
55 unsigned short page_save;
58 down(&ac97->page_mutex);
59 page_save = snd_ac97_read(ac97, AC97_INT_PAGING) & AC97_PAGE_MASK;
60 snd_ac97_update_bits(ac97, AC97_INT_PAGING, AC97_PAGE_MASK, page);
61 ret = snd_ac97_update_bits(ac97, reg, mask, value);
62 snd_ac97_update_bits(ac97, AC97_INT_PAGING, AC97_PAGE_MASK, page_save);
63 up(&ac97->page_mutex); /* unlock paging */
68 * shared line-in/mic controls
70 static int ac97_enum_text_info(snd_kcontrol_t *kcontrol, snd_ctl_elem_info_t *uinfo,
71 const char **texts, unsigned int nums)
73 uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED;
75 uinfo->value.enumerated.items = nums;
76 if (uinfo->value.enumerated.item > nums - 1)
77 uinfo->value.enumerated.item = nums - 1;
78 strcpy(uinfo->value.enumerated.name, texts[uinfo->value.enumerated.item]);
82 static int ac97_surround_jack_mode_info(snd_kcontrol_t *kcontrol, snd_ctl_elem_info_t *uinfo)
84 static const char *texts[] = { "Shared", "Independent" };
85 return ac97_enum_text_info(kcontrol, uinfo, texts, 2);
88 static int ac97_surround_jack_mode_get(snd_kcontrol_t *kcontrol, snd_ctl_elem_value_t *ucontrol)
90 ac97_t *ac97 = snd_kcontrol_chip(kcontrol);
92 ucontrol->value.enumerated.item[0] = ac97->indep_surround;
96 static int ac97_surround_jack_mode_put(snd_kcontrol_t *kcontrol, snd_ctl_elem_value_t *ucontrol)
98 ac97_t *ac97 = snd_kcontrol_chip(kcontrol);
99 unsigned char indep = !!ucontrol->value.enumerated.item[0];
101 if (indep != ac97->indep_surround) {
102 ac97->indep_surround = indep;
103 if (ac97->build_ops->update_jacks)
104 ac97->build_ops->update_jacks(ac97);
110 static int ac97_channel_mode_info(snd_kcontrol_t *kcontrol, snd_ctl_elem_info_t *uinfo)
112 static const char *texts[] = { "2ch", "4ch", "6ch" };
113 if (kcontrol->private_value)
114 return ac97_enum_text_info(kcontrol, uinfo, texts, 2); /* 4ch only */
115 return ac97_enum_text_info(kcontrol, uinfo, texts, 3);
118 static int ac97_channel_mode_get(snd_kcontrol_t *kcontrol, snd_ctl_elem_value_t *ucontrol)
120 ac97_t *ac97 = snd_kcontrol_chip(kcontrol);
122 ucontrol->value.enumerated.item[0] = ac97->channel_mode;
126 static int ac97_channel_mode_put(snd_kcontrol_t *kcontrol, snd_ctl_elem_value_t *ucontrol)
128 ac97_t *ac97 = snd_kcontrol_chip(kcontrol);
129 unsigned char mode = ucontrol->value.enumerated.item[0];
131 if (mode != ac97->channel_mode) {
132 ac97->channel_mode = mode;
133 if (ac97->build_ops->update_jacks)
134 ac97->build_ops->update_jacks(ac97);
140 #define AC97_SURROUND_JACK_MODE_CTL \
142 .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \
143 .name = "Surround Jack Mode", \
144 .info = ac97_surround_jack_mode_info, \
145 .get = ac97_surround_jack_mode_get, \
146 .put = ac97_surround_jack_mode_put, \
148 #define AC97_CHANNEL_MODE_CTL \
150 .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \
151 .name = "Channel Mode", \
152 .info = ac97_channel_mode_info, \
153 .get = ac97_channel_mode_get, \
154 .put = ac97_channel_mode_put, \
156 #define AC97_CHANNEL_MODE_4CH_CTL \
158 .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \
159 .name = "Channel Mode", \
160 .info = ac97_channel_mode_info, \
161 .get = ac97_channel_mode_get, \
162 .put = ac97_channel_mode_put, \
163 .private_value = 1, \
166 static inline int is_shared_linein(ac97_t *ac97)
168 return ! ac97->indep_surround && ac97->channel_mode >= 1;
171 static inline int is_shared_micin(ac97_t *ac97)
173 return ! ac97->indep_surround && ac97->channel_mode >= 2;
177 /* The following snd_ac97_ymf753_... items added by David Shust (dshust@shustring.com) */
179 /* It is possible to indicate to the Yamaha YMF753 the type of speakers being used. */
180 static int snd_ac97_ymf753_info_speaker(snd_kcontrol_t *kcontrol, snd_ctl_elem_info_t * uinfo)
182 static char *texts[3] = {
183 "Standard", "Small", "Smaller"
186 uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED;
188 uinfo->value.enumerated.items = 3;
189 if (uinfo->value.enumerated.item > 2)
190 uinfo->value.enumerated.item = 2;
191 strcpy(uinfo->value.enumerated.name, texts[uinfo->value.enumerated.item]);
195 static int snd_ac97_ymf753_get_speaker(snd_kcontrol_t * kcontrol, snd_ctl_elem_value_t * ucontrol)
197 ac97_t *ac97 = snd_kcontrol_chip(kcontrol);
200 val = ac97->regs[AC97_YMF753_3D_MODE_SEL];
201 val = (val >> 10) & 3;
202 if (val > 0) /* 0 = invalid */
204 ucontrol->value.enumerated.item[0] = val;
208 static int snd_ac97_ymf753_put_speaker(snd_kcontrol_t * kcontrol, snd_ctl_elem_value_t * ucontrol)
210 ac97_t *ac97 = snd_kcontrol_chip(kcontrol);
213 if (ucontrol->value.enumerated.item[0] > 2)
215 val = (ucontrol->value.enumerated.item[0] + 1) << 10;
216 return snd_ac97_update(ac97, AC97_YMF753_3D_MODE_SEL, val);
219 static const snd_kcontrol_new_t snd_ac97_ymf753_controls_speaker =
221 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
222 .name = "3D Control - Speaker",
223 .info = snd_ac97_ymf753_info_speaker,
224 .get = snd_ac97_ymf753_get_speaker,
225 .put = snd_ac97_ymf753_put_speaker,
228 /* It is possible to indicate to the Yamaha YMF753 the source to direct to the S/PDIF output. */
229 static int snd_ac97_ymf753_spdif_source_info(snd_kcontrol_t *kcontrol, snd_ctl_elem_info_t * uinfo)
231 static char *texts[2] = { "AC-Link", "A/D Converter" };
233 uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED;
235 uinfo->value.enumerated.items = 2;
236 if (uinfo->value.enumerated.item > 1)
237 uinfo->value.enumerated.item = 1;
238 strcpy(uinfo->value.enumerated.name, texts[uinfo->value.enumerated.item]);
242 static int snd_ac97_ymf753_spdif_source_get(snd_kcontrol_t * kcontrol, snd_ctl_elem_value_t * ucontrol)
244 ac97_t *ac97 = snd_kcontrol_chip(kcontrol);
247 val = ac97->regs[AC97_YMF753_DIT_CTRL2];
248 ucontrol->value.enumerated.item[0] = (val >> 1) & 1;
252 static int snd_ac97_ymf753_spdif_source_put(snd_kcontrol_t * kcontrol, snd_ctl_elem_value_t * ucontrol)
254 ac97_t *ac97 = snd_kcontrol_chip(kcontrol);
257 if (ucontrol->value.enumerated.item[0] > 1)
259 val = ucontrol->value.enumerated.item[0] << 1;
260 return snd_ac97_update_bits(ac97, AC97_YMF753_DIT_CTRL2, 0x0002, val);
263 /* The AC'97 spec states that the S/PDIF signal is to be output at pin 48.
264 The YMF753 will output the S/PDIF signal to pin 43, 47 (EAPD), or 48.
265 By default, no output pin is selected, and the S/PDIF signal is not output.
266 There is also a bit to mute S/PDIF output in a vendor-specific register. */
267 static int snd_ac97_ymf753_spdif_output_pin_info(snd_kcontrol_t *kcontrol, snd_ctl_elem_info_t * uinfo)
269 static char *texts[3] = { "Disabled", "Pin 43", "Pin 48" };
271 uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED;
273 uinfo->value.enumerated.items = 3;
274 if (uinfo->value.enumerated.item > 2)
275 uinfo->value.enumerated.item = 2;
276 strcpy(uinfo->value.enumerated.name, texts[uinfo->value.enumerated.item]);
280 static int snd_ac97_ymf753_spdif_output_pin_get(snd_kcontrol_t * kcontrol, snd_ctl_elem_value_t * ucontrol)
282 ac97_t *ac97 = snd_kcontrol_chip(kcontrol);
285 val = ac97->regs[AC97_YMF753_DIT_CTRL2];
286 ucontrol->value.enumerated.item[0] = (val & 0x0008) ? 2 : (val & 0x0020) ? 1 : 0;
290 static int snd_ac97_ymf753_spdif_output_pin_put(snd_kcontrol_t * kcontrol, snd_ctl_elem_value_t * ucontrol)
292 ac97_t *ac97 = snd_kcontrol_chip(kcontrol);
295 if (ucontrol->value.enumerated.item[0] > 2)
297 val = (ucontrol->value.enumerated.item[0] == 2) ? 0x0008 :
298 (ucontrol->value.enumerated.item[0] == 1) ? 0x0020 : 0;
299 return snd_ac97_update_bits(ac97, AC97_YMF753_DIT_CTRL2, 0x0028, val);
300 /* The following can be used to direct S/PDIF output to pin 47 (EAPD).
301 snd_ac97_write_cache(ac97, 0x62, snd_ac97_read(ac97, 0x62) | 0x0008); */
304 static const snd_kcontrol_new_t snd_ac97_ymf753_controls_spdif[3] = {
306 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
307 .name = SNDRV_CTL_NAME_IEC958("",PLAYBACK,NONE) "Source",
308 .info = snd_ac97_ymf753_spdif_source_info,
309 .get = snd_ac97_ymf753_spdif_source_get,
310 .put = snd_ac97_ymf753_spdif_source_put,
313 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
314 .name = SNDRV_CTL_NAME_IEC958("",PLAYBACK,NONE) "Output Pin",
315 .info = snd_ac97_ymf753_spdif_output_pin_info,
316 .get = snd_ac97_ymf753_spdif_output_pin_get,
317 .put = snd_ac97_ymf753_spdif_output_pin_put,
319 AC97_SINGLE(SNDRV_CTL_NAME_IEC958("",NONE,NONE) "Mute", AC97_YMF753_DIT_CTRL2, 2, 1, 1)
322 static int patch_yamaha_ymf753_3d(ac97_t * ac97)
324 snd_kcontrol_t *kctl;
327 if ((err = snd_ctl_add(ac97->bus->card, kctl = snd_ac97_cnew(&snd_ac97_controls_3d[0], ac97))) < 0)
329 strcpy(kctl->id.name, "3D Control - Wide");
330 kctl->private_value = AC97_SINGLE_VALUE(AC97_3D_CONTROL, 9, 7, 0);
331 snd_ac97_write_cache(ac97, AC97_3D_CONTROL, 0x0000);
332 if ((err = snd_ctl_add(ac97->bus->card, snd_ac97_cnew(&snd_ac97_ymf753_controls_speaker, ac97))) < 0)
334 snd_ac97_write_cache(ac97, AC97_YMF753_3D_MODE_SEL, 0x0c00);
338 static int patch_yamaha_ymf753_post_spdif(ac97_t * ac97)
342 if ((err = patch_build_controls(ac97, snd_ac97_ymf753_controls_spdif, ARRAY_SIZE(snd_ac97_ymf753_controls_spdif))) < 0)
347 static struct snd_ac97_build_ops patch_yamaha_ymf753_ops = {
348 .build_3d = patch_yamaha_ymf753_3d,
349 .build_post_spdif = patch_yamaha_ymf753_post_spdif
352 int patch_yamaha_ymf753(ac97_t * ac97)
354 /* Patch for Yamaha YMF753, Copyright (c) by David Shust, dshust@shustring.com.
355 This chip has nonstandard and extended behaviour with regard to its S/PDIF output.
356 The AC'97 spec states that the S/PDIF signal is to be output at pin 48.
357 The YMF753 will ouput the S/PDIF signal to pin 43, 47 (EAPD), or 48.
358 By default, no output pin is selected, and the S/PDIF signal is not output.
359 There is also a bit to mute S/PDIF output in a vendor-specific register.
361 ac97->build_ops = &patch_yamaha_ymf753_ops;
362 ac97->caps |= AC97_BC_BASS_TREBLE;
363 ac97->caps |= 0x04 << 10; /* Yamaha 3D enhancement */
368 * May 2, 2003 Liam Girdwood <liam.girdwood@wolfsonmicro.com>
369 * removed broken wolfson00 patch.
370 * added support for WM9705,WM9708,WM9709,WM9710,WM9711,WM9712 and WM9717.
373 int patch_wolfson03(ac97_t * ac97)
375 /* This is known to work for the ViewSonic ViewPad 1000
376 Randolph Bentson <bentson@holmsjoen.com> */
378 // WM9703/9707/9708/9717
379 snd_ac97_write_cache(ac97, AC97_WM97XX_FMIXER_VOL, 0x0808);
380 snd_ac97_write_cache(ac97, AC97_GENERAL_PURPOSE, 0x8000);
384 int patch_wolfson04(ac97_t * ac97)
387 // set front and rear mixer volume
388 snd_ac97_write_cache(ac97, AC97_WM97XX_FMIXER_VOL, 0x0808);
389 snd_ac97_write_cache(ac97, AC97_WM9704_RMIXER_VOL, 0x0808);
391 // patch for DVD noise
392 snd_ac97_write_cache(ac97, AC97_WM9704_TEST, 0x0200);
395 snd_ac97_write_cache(ac97, AC97_WM9704_RPCM_VOL, 0x0808);
397 // set rear surround volume
398 snd_ac97_write_cache(ac97, AC97_SURROUND_MASTER, 0x0000);
402 int patch_wolfson05(ac97_t * ac97)
405 // set front mixer volume
406 snd_ac97_write_cache(ac97, AC97_WM97XX_FMIXER_VOL, 0x0808);
410 int patch_wolfson11(ac97_t * ac97)
414 snd_ac97_write_cache(ac97, AC97_WM9711_OUT3VOL, 0x0808);
418 static const char* wm9713_mic_mixer[] = {"Stereo", "Mic1", "Mic2", "Mute"};
419 static const char* wm9713_rec_mux[] = {"Stereo", "Left", "Right", "Mute"};
420 static const char* wm9713_rec_src_l[] = {"Mic1", "Mic2", "Line L", "Mono In", "HP Mix L", "Spk Mix", "Mono Mix", "Zh"};
421 static const char* wm9713_rec_src_r[] = {"Mic1", "Mic2", "Line R", "Mono In", "HP Mix R", "Spk Mix", "Mono Mix", "Zh"};
423 static const struct ac97_enum wm9713_enum[] = {
424 AC97_ENUM_SINGLE(AC97_LINE, 3, 4, wm9713_mic_mixer),
425 AC97_ENUM_SINGLE(AC97_VIDEO, 14, 4, wm9713_rec_mux),
426 AC97_ENUM_SINGLE(AC97_VIDEO, 9, 4, wm9713_rec_mux),
427 AC97_ENUM_SINGLE(AC97_VIDEO, 3, 8, wm9713_rec_src_l),
428 AC97_ENUM_SINGLE(AC97_VIDEO, 0, 8, wm9713_rec_src_r),
431 static const snd_kcontrol_new_t wm13_snd_ac97_controls_line_in[] = {
432 AC97_DOUBLE("Line In Volume", AC97_PC_BEEP, 8, 0, 31, 1),
433 AC97_SINGLE("Line In to Headphone Mute", AC97_PC_BEEP, 15, 1, 1),
434 AC97_SINGLE("Line In to Speaker Mute", AC97_PC_BEEP, 14, 1, 1),
435 AC97_SINGLE("Line In to Mono Mute", AC97_PC_BEEP, 13, 1, 1),
438 static const snd_kcontrol_new_t wm13_snd_ac97_controls_dac[] = {
439 AC97_DOUBLE("DAC Volume", AC97_PHONE, 8, 0, 31, 1),
440 AC97_SINGLE("DAC to Headphone Mute", AC97_PHONE, 15, 1, 1),
441 AC97_SINGLE("DAC to Speaker Mute", AC97_PHONE, 14, 1, 1),
442 AC97_SINGLE("DAC to Mono Mute", AC97_PHONE, 13, 1, 1),
445 static const snd_kcontrol_new_t wm13_snd_ac97_controls_mic[] = {
446 AC97_SINGLE("MICA Volume", AC97_MIC, 8, 31, 1),
447 AC97_SINGLE("MICB Volume", AC97_MIC, 0, 31, 1),
448 AC97_SINGLE("MICA to Mono Mute", AC97_LINE, 7, 1, 1),
449 AC97_SINGLE("MICB to Mono Mute", AC97_LINE, 6, 1, 1),
450 AC97_SINGLE("MIC Boost (+20dB)", AC97_LINE, 5, 1, 1),
451 AC97_ENUM("MIC Headphone Routing", wm9713_enum[0]),
452 AC97_SINGLE("MIC Headphone Mixer Volume", AC97_LINE, 0, 7, 1)
455 static const snd_kcontrol_new_t wm13_snd_ac97_controls_adc[] = {
456 AC97_SINGLE("ADC Mute", AC97_CD, 15, 1, 1),
457 AC97_DOUBLE("Gain Step Size (1.5dB/0.75dB)", AC97_CD, 14, 6, 1, 1),
458 AC97_DOUBLE("ADC Volume",AC97_CD, 8, 0, 15, 0),
459 AC97_SINGLE("ADC Zero Cross", AC97_CD, 7, 1, 1),
462 static const snd_kcontrol_new_t wm13_snd_ac97_controls_recsel[] = {
463 AC97_ENUM("Record to Headphone Path", wm9713_enum[1]),
464 AC97_SINGLE("Record to Headphone Volume", AC97_VIDEO, 11, 7, 0),
465 AC97_ENUM("Record to Mono Path", wm9713_enum[2]),
466 AC97_SINGLE("Record to Mono Boost (+20dB)", AC97_VIDEO, 8, 1, 0),
467 AC97_SINGLE("Record ADC Boost (+20dB)", AC97_VIDEO, 6, 1, 0),
468 AC97_ENUM("Record Select Left", wm9713_enum[3]),
469 AC97_ENUM("Record Select Right", wm9713_enum[4]),
472 static int patch_wolfson_wm9713_specific(ac97_t * ac97)
476 for (i = 0; i < ARRAY_SIZE(wm13_snd_ac97_controls_line_in); i++) {
477 if ((err = snd_ctl_add(ac97->bus->card, snd_ac97_cnew(&wm13_snd_ac97_controls_line_in[i], ac97))) < 0)
480 snd_ac97_write_cache(ac97, AC97_PC_BEEP, 0x0808);
482 for (i = 0; i < ARRAY_SIZE(wm13_snd_ac97_controls_dac); i++) {
483 if ((err = snd_ctl_add(ac97->bus->card, snd_ac97_cnew(&wm13_snd_ac97_controls_dac[i], ac97))) < 0)
486 snd_ac97_write_cache(ac97, AC97_PHONE, 0x0808);
488 for (i = 0; i < ARRAY_SIZE(wm13_snd_ac97_controls_mic); i++) {
489 if ((err = snd_ctl_add(ac97->bus->card, snd_ac97_cnew(&wm13_snd_ac97_controls_mic[i], ac97))) < 0)
492 snd_ac97_write_cache(ac97, AC97_MIC, 0x0808);
493 snd_ac97_write_cache(ac97, AC97_LINE, 0x00da);
495 for (i = 0; i < ARRAY_SIZE(wm13_snd_ac97_controls_adc); i++) {
496 if ((err = snd_ctl_add(ac97->bus->card, snd_ac97_cnew(&wm13_snd_ac97_controls_adc[i], ac97))) < 0)
499 snd_ac97_write_cache(ac97, AC97_CD, 0x0808);
501 for (i = 0; i < ARRAY_SIZE(wm13_snd_ac97_controls_recsel); i++) {
502 if ((err = snd_ctl_add(ac97->bus->card, snd_ac97_cnew(&wm13_snd_ac97_controls_recsel[i], ac97))) < 0)
505 snd_ac97_write_cache(ac97, AC97_VIDEO, 0xd612);
506 snd_ac97_write_cache(ac97, AC97_REC_GAIN, 0x1ba0);
512 static void patch_wolfson_wm9713_suspend (ac97_t * ac97)
514 snd_ac97_write_cache(ac97, AC97_EXTENDED_MID, 0xfeff);
515 snd_ac97_write_cache(ac97, AC97_EXTENDED_MSTATUS, 0xffff);
518 static void patch_wolfson_wm9713_resume (ac97_t * ac97)
520 snd_ac97_write_cache(ac97, AC97_EXTENDED_MID, 0xda00);
521 snd_ac97_write_cache(ac97, AC97_EXTENDED_MSTATUS, 0x3810);
522 snd_ac97_write_cache(ac97, AC97_POWERDOWN, 0x0);
526 static struct snd_ac97_build_ops patch_wolfson_wm9713_ops = {
527 .build_specific = patch_wolfson_wm9713_specific,
529 .suspend = patch_wolfson_wm9713_suspend,
530 .resume = patch_wolfson_wm9713_resume
534 int patch_wolfson13(ac97_t * ac97)
536 ac97->build_ops = &patch_wolfson_wm9713_ops;
538 ac97->flags |= AC97_HAS_NO_REC_GAIN | AC97_STEREO_MUTES | AC97_HAS_NO_PHONE |
539 AC97_HAS_NO_PC_BEEP | AC97_HAS_NO_VIDEO | AC97_HAS_NO_CD;
541 snd_ac97_write_cache(ac97, AC97_EXTENDED_MID, 0xda00);
542 snd_ac97_write_cache(ac97, AC97_EXTENDED_MSTATUS, 0x3810);
543 snd_ac97_write_cache(ac97, AC97_POWERDOWN, 0x0);
551 int patch_tritech_tr28028(ac97_t * ac97)
553 snd_ac97_write_cache(ac97, 0x26, 0x0300);
554 snd_ac97_write_cache(ac97, 0x26, 0x0000);
555 snd_ac97_write_cache(ac97, AC97_SURROUND_MASTER, 0x0000);
556 snd_ac97_write_cache(ac97, AC97_SPDIF, 0x0000);
561 * Sigmatel STAC97xx codecs
563 static int patch_sigmatel_stac9700_3d(ac97_t * ac97)
565 snd_kcontrol_t *kctl;
568 if ((err = snd_ctl_add(ac97->bus->card, kctl = snd_ac97_cnew(&snd_ac97_controls_3d[0], ac97))) < 0)
570 strcpy(kctl->id.name, "3D Control Sigmatel - Depth");
571 kctl->private_value = AC97_SINGLE_VALUE(AC97_3D_CONTROL, 2, 3, 0);
572 snd_ac97_write_cache(ac97, AC97_3D_CONTROL, 0x0000);
576 static int patch_sigmatel_stac9708_3d(ac97_t * ac97)
578 snd_kcontrol_t *kctl;
581 if ((err = snd_ctl_add(ac97->bus->card, kctl = snd_ac97_cnew(&snd_ac97_controls_3d[0], ac97))) < 0)
583 strcpy(kctl->id.name, "3D Control Sigmatel - Depth");
584 kctl->private_value = AC97_SINGLE_VALUE(AC97_3D_CONTROL, 0, 3, 0);
585 if ((err = snd_ctl_add(ac97->bus->card, kctl = snd_ac97_cnew(&snd_ac97_controls_3d[0], ac97))) < 0)
587 strcpy(kctl->id.name, "3D Control Sigmatel - Rear Depth");
588 kctl->private_value = AC97_SINGLE_VALUE(AC97_3D_CONTROL, 2, 3, 0);
589 snd_ac97_write_cache(ac97, AC97_3D_CONTROL, 0x0000);
593 static const snd_kcontrol_new_t snd_ac97_sigmatel_4speaker =
594 AC97_SINGLE("Sigmatel 4-Speaker Stereo Playback Switch", AC97_SIGMATEL_DAC2INVERT, 2, 1, 0);
596 static const snd_kcontrol_new_t snd_ac97_sigmatel_phaseinvert =
597 AC97_SINGLE("Sigmatel Surround Phase Inversion Playback Switch", AC97_SIGMATEL_DAC2INVERT, 3, 1, 0);
599 static const snd_kcontrol_new_t snd_ac97_sigmatel_controls[] = {
600 AC97_SINGLE("Sigmatel DAC 6dB Attenuate", AC97_SIGMATEL_ANALOG, 1, 1, 0),
601 AC97_SINGLE("Sigmatel ADC 6dB Attenuate", AC97_SIGMATEL_ANALOG, 0, 1, 0)
604 static int patch_sigmatel_stac97xx_specific(ac97_t * ac97)
608 snd_ac97_write_cache(ac97, AC97_SIGMATEL_ANALOG, snd_ac97_read(ac97, AC97_SIGMATEL_ANALOG) & ~0x0003);
609 if (snd_ac97_try_bit(ac97, AC97_SIGMATEL_ANALOG, 1))
610 if ((err = patch_build_controls(ac97, &snd_ac97_sigmatel_controls[0], 1)) < 0)
612 if (snd_ac97_try_bit(ac97, AC97_SIGMATEL_ANALOG, 0))
613 if ((err = patch_build_controls(ac97, &snd_ac97_sigmatel_controls[1], 1)) < 0)
615 if (snd_ac97_try_bit(ac97, AC97_SIGMATEL_DAC2INVERT, 2))
616 if ((err = patch_build_controls(ac97, &snd_ac97_sigmatel_4speaker, 1)) < 0)
618 if (snd_ac97_try_bit(ac97, AC97_SIGMATEL_DAC2INVERT, 3))
619 if ((err = patch_build_controls(ac97, &snd_ac97_sigmatel_phaseinvert, 1)) < 0)
624 static struct snd_ac97_build_ops patch_sigmatel_stac9700_ops = {
625 .build_3d = patch_sigmatel_stac9700_3d,
626 .build_specific = patch_sigmatel_stac97xx_specific
629 int patch_sigmatel_stac9700(ac97_t * ac97)
631 ac97->build_ops = &patch_sigmatel_stac9700_ops;
635 static int snd_ac97_stac9708_put_bias(snd_kcontrol_t *kcontrol, snd_ctl_elem_value_t *ucontrol)
637 ac97_t *ac97 = snd_kcontrol_chip(kcontrol);
640 down(&ac97->page_mutex);
641 snd_ac97_write(ac97, AC97_SIGMATEL_BIAS1, 0xabba);
642 err = snd_ac97_update_bits(ac97, AC97_SIGMATEL_BIAS2, 0x0010,
643 (ucontrol->value.integer.value[0] & 1) << 4);
644 snd_ac97_write(ac97, AC97_SIGMATEL_BIAS1, 0);
645 up(&ac97->page_mutex);
649 static const snd_kcontrol_new_t snd_ac97_stac9708_bias_control = {
650 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
651 .name = "Sigmatel Output Bias Switch",
652 .info = snd_ac97_info_volsw,
653 .get = snd_ac97_get_volsw,
654 .put = snd_ac97_stac9708_put_bias,
655 .private_value = AC97_SINGLE_VALUE(AC97_SIGMATEL_BIAS2, 4, 1, 0),
658 static int patch_sigmatel_stac9708_specific(ac97_t *ac97)
662 snd_ac97_rename_vol_ctl(ac97, "Headphone Playback", "Sigmatel Surround Playback");
663 if ((err = patch_build_controls(ac97, &snd_ac97_stac9708_bias_control, 1)) < 0)
665 return patch_sigmatel_stac97xx_specific(ac97);
668 static struct snd_ac97_build_ops patch_sigmatel_stac9708_ops = {
669 .build_3d = patch_sigmatel_stac9708_3d,
670 .build_specific = patch_sigmatel_stac9708_specific
673 int patch_sigmatel_stac9708(ac97_t * ac97)
675 unsigned int codec72, codec6c;
677 ac97->build_ops = &patch_sigmatel_stac9708_ops;
678 ac97->caps |= 0x10; /* HP (sigmatel surround) support */
680 codec72 = snd_ac97_read(ac97, AC97_SIGMATEL_BIAS2) & 0x8000;
681 codec6c = snd_ac97_read(ac97, AC97_SIGMATEL_ANALOG);
683 if ((codec72==0) && (codec6c==0)) {
684 snd_ac97_write_cache(ac97, AC97_SIGMATEL_CIC1, 0xabba);
685 snd_ac97_write_cache(ac97, AC97_SIGMATEL_CIC2, 0x1000);
686 snd_ac97_write_cache(ac97, AC97_SIGMATEL_BIAS1, 0xabba);
687 snd_ac97_write_cache(ac97, AC97_SIGMATEL_BIAS2, 0x0007);
688 } else if ((codec72==0x8000) && (codec6c==0)) {
689 snd_ac97_write_cache(ac97, AC97_SIGMATEL_CIC1, 0xabba);
690 snd_ac97_write_cache(ac97, AC97_SIGMATEL_CIC2, 0x1001);
691 snd_ac97_write_cache(ac97, AC97_SIGMATEL_DAC2INVERT, 0x0008);
692 } else if ((codec72==0x8000) && (codec6c==0x0080)) {
695 snd_ac97_write_cache(ac97, AC97_SIGMATEL_MULTICHN, 0x0000);
699 int patch_sigmatel_stac9721(ac97_t * ac97)
701 ac97->build_ops = &patch_sigmatel_stac9700_ops;
702 if (snd_ac97_read(ac97, AC97_SIGMATEL_ANALOG) == 0) {
703 // patch for SigmaTel
704 snd_ac97_write_cache(ac97, AC97_SIGMATEL_CIC1, 0xabba);
705 snd_ac97_write_cache(ac97, AC97_SIGMATEL_CIC2, 0x4000);
706 snd_ac97_write_cache(ac97, AC97_SIGMATEL_BIAS1, 0xabba);
707 snd_ac97_write_cache(ac97, AC97_SIGMATEL_BIAS2, 0x0002);
709 snd_ac97_write_cache(ac97, AC97_SIGMATEL_MULTICHN, 0x0000);
713 int patch_sigmatel_stac9744(ac97_t * ac97)
715 // patch for SigmaTel
716 ac97->build_ops = &patch_sigmatel_stac9700_ops;
717 snd_ac97_write_cache(ac97, AC97_SIGMATEL_CIC1, 0xabba);
718 snd_ac97_write_cache(ac97, AC97_SIGMATEL_CIC2, 0x0000); /* is this correct? --jk */
719 snd_ac97_write_cache(ac97, AC97_SIGMATEL_BIAS1, 0xabba);
720 snd_ac97_write_cache(ac97, AC97_SIGMATEL_BIAS2, 0x0002);
721 snd_ac97_write_cache(ac97, AC97_SIGMATEL_MULTICHN, 0x0000);
725 int patch_sigmatel_stac9756(ac97_t * ac97)
727 // patch for SigmaTel
728 ac97->build_ops = &patch_sigmatel_stac9700_ops;
729 snd_ac97_write_cache(ac97, AC97_SIGMATEL_CIC1, 0xabba);
730 snd_ac97_write_cache(ac97, AC97_SIGMATEL_CIC2, 0x0000); /* is this correct? --jk */
731 snd_ac97_write_cache(ac97, AC97_SIGMATEL_BIAS1, 0xabba);
732 snd_ac97_write_cache(ac97, AC97_SIGMATEL_BIAS2, 0x0002);
733 snd_ac97_write_cache(ac97, AC97_SIGMATEL_MULTICHN, 0x0000);
737 static int snd_ac97_stac9758_output_jack_info(snd_kcontrol_t *kcontrol, snd_ctl_elem_info_t *uinfo)
739 static char *texts[5] = { "Input/Disabled", "Front Output",
740 "Rear Output", "Center/LFE Output", "Mixer Output" };
742 uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED;
744 uinfo->value.enumerated.items = 5;
745 if (uinfo->value.enumerated.item > 4)
746 uinfo->value.enumerated.item = 4;
747 strcpy(uinfo->value.enumerated.name, texts[uinfo->value.enumerated.item]);
751 static int snd_ac97_stac9758_output_jack_get(snd_kcontrol_t *kcontrol, snd_ctl_elem_value_t* ucontrol)
753 ac97_t *ac97 = snd_kcontrol_chip(kcontrol);
754 int shift = kcontrol->private_value;
757 val = ac97->regs[AC97_SIGMATEL_OUTSEL] >> shift;
759 ucontrol->value.enumerated.item[0] = 0;
761 ucontrol->value.enumerated.item[0] = 1 + (val & 3);
765 static int snd_ac97_stac9758_output_jack_put(snd_kcontrol_t *kcontrol, snd_ctl_elem_value_t *ucontrol)
767 ac97_t *ac97 = snd_kcontrol_chip(kcontrol);
768 int shift = kcontrol->private_value;
771 if (ucontrol->value.enumerated.item[0] > 4)
773 if (ucontrol->value.enumerated.item[0] == 0)
776 val = 4 | (ucontrol->value.enumerated.item[0] - 1);
777 return ac97_update_bits_page(ac97, AC97_SIGMATEL_OUTSEL,
778 7 << shift, val << shift, 0);
781 static int snd_ac97_stac9758_input_jack_info(snd_kcontrol_t *kcontrol, snd_ctl_elem_info_t *uinfo)
783 static char *texts[7] = { "Mic2 Jack", "Mic1 Jack", "Line In Jack",
784 "Front Jack", "Rear Jack", "Center/LFE Jack", "Mute" };
786 uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED;
788 uinfo->value.enumerated.items = 7;
789 if (uinfo->value.enumerated.item > 6)
790 uinfo->value.enumerated.item = 6;
791 strcpy(uinfo->value.enumerated.name, texts[uinfo->value.enumerated.item]);
795 static int snd_ac97_stac9758_input_jack_get(snd_kcontrol_t *kcontrol, snd_ctl_elem_value_t* ucontrol)
797 ac97_t *ac97 = snd_kcontrol_chip(kcontrol);
798 int shift = kcontrol->private_value;
801 val = ac97->regs[AC97_SIGMATEL_INSEL];
802 ucontrol->value.enumerated.item[0] = (val >> shift) & 7;
806 static int snd_ac97_stac9758_input_jack_put(snd_kcontrol_t *kcontrol, snd_ctl_elem_value_t *ucontrol)
808 ac97_t *ac97 = snd_kcontrol_chip(kcontrol);
809 int shift = kcontrol->private_value;
811 return ac97_update_bits_page(ac97, AC97_SIGMATEL_INSEL, 7 << shift,
812 ucontrol->value.enumerated.item[0] << shift, 0);
815 static int snd_ac97_stac9758_phonesel_info(snd_kcontrol_t *kcontrol, snd_ctl_elem_info_t *uinfo)
817 static char *texts[3] = { "None", "Front Jack", "Rear Jack" };
819 uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED;
821 uinfo->value.enumerated.items = 3;
822 if (uinfo->value.enumerated.item > 2)
823 uinfo->value.enumerated.item = 2;
824 strcpy(uinfo->value.enumerated.name, texts[uinfo->value.enumerated.item]);
828 static int snd_ac97_stac9758_phonesel_get(snd_kcontrol_t *kcontrol, snd_ctl_elem_value_t* ucontrol)
830 ac97_t *ac97 = snd_kcontrol_chip(kcontrol);
832 ucontrol->value.enumerated.item[0] = ac97->regs[AC97_SIGMATEL_IOMISC] & 3;
836 static int snd_ac97_stac9758_phonesel_put(snd_kcontrol_t *kcontrol, snd_ctl_elem_value_t *ucontrol)
838 ac97_t *ac97 = snd_kcontrol_chip(kcontrol);
840 return ac97_update_bits_page(ac97, AC97_SIGMATEL_IOMISC, 3,
841 ucontrol->value.enumerated.item[0], 0);
844 #define STAC9758_OUTPUT_JACK(xname, shift) \
845 { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = xname, \
846 .info = snd_ac97_stac9758_output_jack_info, \
847 .get = snd_ac97_stac9758_output_jack_get, \
848 .put = snd_ac97_stac9758_output_jack_put, \
849 .private_value = shift }
850 #define STAC9758_INPUT_JACK(xname, shift) \
851 { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = xname, \
852 .info = snd_ac97_stac9758_input_jack_info, \
853 .get = snd_ac97_stac9758_input_jack_get, \
854 .put = snd_ac97_stac9758_input_jack_put, \
855 .private_value = shift }
856 static const snd_kcontrol_new_t snd_ac97_sigmatel_stac9758_controls[] = {
857 STAC9758_OUTPUT_JACK("Mic1 Jack", 1),
858 STAC9758_OUTPUT_JACK("LineIn Jack", 4),
859 STAC9758_OUTPUT_JACK("Front Jack", 7),
860 STAC9758_OUTPUT_JACK("Rear Jack", 10),
861 STAC9758_OUTPUT_JACK("Center/LFE Jack", 13),
862 STAC9758_INPUT_JACK("Mic Input Source", 0),
863 STAC9758_INPUT_JACK("Line Input Source", 8),
865 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
866 .name = "Headphone Amp",
867 .info = snd_ac97_stac9758_phonesel_info,
868 .get = snd_ac97_stac9758_phonesel_get,
869 .put = snd_ac97_stac9758_phonesel_put
871 AC97_SINGLE("Exchange Center/LFE", AC97_SIGMATEL_IOMISC, 4, 1, 0),
872 AC97_SINGLE("Headphone +3dB Boost", AC97_SIGMATEL_IOMISC, 8, 1, 0)
875 static int patch_sigmatel_stac9758_specific(ac97_t *ac97)
879 err = patch_sigmatel_stac97xx_specific(ac97);
882 err = patch_build_controls(ac97, snd_ac97_sigmatel_stac9758_controls,
883 ARRAY_SIZE(snd_ac97_sigmatel_stac9758_controls));
887 snd_ac97_rename_vol_ctl(ac97, "Headphone Playback", "Front Playback");
888 /* DAC-A to Mix = PCM */
889 /* DAC-B direct = Surround */
891 snd_ac97_rename_vol_ctl(ac97, "Video Playback", "Surround Mix Playback");
892 /* DAC-C direct = Center/LFE */
897 static struct snd_ac97_build_ops patch_sigmatel_stac9758_ops = {
898 .build_3d = patch_sigmatel_stac9700_3d,
899 .build_specific = patch_sigmatel_stac9758_specific
902 int patch_sigmatel_stac9758(ac97_t * ac97)
904 static unsigned short regs[4] = {
905 AC97_SIGMATEL_OUTSEL,
906 AC97_SIGMATEL_IOMISC,
908 AC97_SIGMATEL_VARIOUS
910 static unsigned short def_regs[4] = {
911 /* OUTSEL */ 0xd794, /* CL:CL, SR:SR, LO:MX, LI:DS, MI:DS */
913 /* INSEL */ 0x0201, /* LI:LI, MI:M1 */
916 static unsigned short m675_regs[4] = {
917 /* OUTSEL */ 0xfc70, /* CL:MX, SR:MX, LO:DS, LI:MX, MI:DS */
918 /* IOMISC */ 0x2102, /* HP amp on */
919 /* INSEL */ 0x0203, /* LI:LI, MI:FR */
920 /* VARIOUS */ 0x0041 /* stereo mic */
922 unsigned short *pregs = def_regs;
925 /* Gateway M675 notebook */
927 ac97->subsystem_vendor == 0x107b &&
928 ac97->subsystem_device == 0x0601)
931 // patch for SigmaTel
932 ac97->build_ops = &patch_sigmatel_stac9758_ops;
933 /* FIXME: assume only page 0 for writing cache */
934 snd_ac97_update_bits(ac97, AC97_INT_PAGING, AC97_PAGE_MASK, AC97_PAGE_VENDOR);
935 for (i = 0; i < 4; i++)
936 snd_ac97_write_cache(ac97, regs[i], pregs[i]);
938 ac97->flags |= AC97_STEREO_MUTES;
943 * Cirrus Logic CS42xx codecs
945 static const snd_kcontrol_new_t snd_ac97_cirrus_controls_spdif[2] = {
946 AC97_SINGLE(SNDRV_CTL_NAME_IEC958("",PLAYBACK,SWITCH), AC97_CSR_SPDIF, 15, 1, 0),
947 AC97_SINGLE(SNDRV_CTL_NAME_IEC958("",PLAYBACK,NONE) "AC97-SPSA", AC97_CSR_ACMODE, 0, 3, 0)
950 static int patch_cirrus_build_spdif(ac97_t * ac97)
954 /* con mask, pro mask, default */
955 if ((err = patch_build_controls(ac97, &snd_ac97_controls_spdif[0], 3)) < 0)
958 if ((err = patch_build_controls(ac97, &snd_ac97_cirrus_controls_spdif[0], 1)) < 0)
960 switch (ac97->id & AC97_ID_CS_MASK) {
962 if ((err = patch_build_controls(ac97, &snd_ac97_cirrus_controls_spdif[1], 1)) < 0)
966 /* set default PCM S/PDIF params */
967 /* consumer,PCM audio,no copyright,no preemphasis,PCM coder,original,48000Hz */
968 snd_ac97_write_cache(ac97, AC97_CSR_SPDIF, 0x0a20);
972 static struct snd_ac97_build_ops patch_cirrus_ops = {
973 .build_spdif = patch_cirrus_build_spdif
976 int patch_cirrus_spdif(ac97_t * ac97)
978 /* Basically, the cs4201/cs4205/cs4297a has non-standard sp/dif registers.
979 WHY CAN'T ANYONE FOLLOW THE BLOODY SPEC? *sigh*
980 - sp/dif EA ID is not set, but sp/dif is always present.
981 - enable/disable is spdif register bit 15.
982 - sp/dif control register is 0x68. differs from AC97:
983 - valid is bit 14 (vs 15)
985 - only 44.1/48k [00 = 48, 01=44,1] (AC97 is 00=44.1, 10=48)
986 - sp/dif ssource select is in 0x5e bits 0,1.
989 ac97->build_ops = &patch_cirrus_ops;
990 ac97->flags |= AC97_CS_SPDIF;
991 ac97->rates[AC97_RATES_SPDIF] &= ~SNDRV_PCM_RATE_32000;
992 ac97->ext_id |= AC97_EI_SPDIF; /* force the detection of spdif */
993 snd_ac97_write_cache(ac97, AC97_CSR_ACMODE, 0x0080);
997 int patch_cirrus_cs4299(ac97_t * ac97)
999 /* force the detection of PC Beep */
1000 ac97->flags |= AC97_HAS_PC_BEEP;
1002 return patch_cirrus_spdif(ac97);
1008 static const snd_kcontrol_new_t snd_ac97_conexant_controls_spdif[1] = {
1009 AC97_SINGLE(SNDRV_CTL_NAME_IEC958("",PLAYBACK,SWITCH), AC97_CXR_AUDIO_MISC, 3, 1, 0),
1012 static int patch_conexant_build_spdif(ac97_t * ac97)
1016 /* con mask, pro mask, default */
1017 if ((err = patch_build_controls(ac97, &snd_ac97_controls_spdif[0], 3)) < 0)
1020 if ((err = patch_build_controls(ac97, &snd_ac97_conexant_controls_spdif[0], 1)) < 0)
1022 /* set default PCM S/PDIF params */
1023 /* consumer,PCM audio,no copyright,no preemphasis,PCM coder,original,48000Hz */
1024 snd_ac97_write_cache(ac97, AC97_CXR_AUDIO_MISC,
1025 snd_ac97_read(ac97, AC97_CXR_AUDIO_MISC) & ~(AC97_CXR_SPDIFEN|AC97_CXR_COPYRGT|AC97_CXR_SPDIF_MASK));
1029 static struct snd_ac97_build_ops patch_conexant_ops = {
1030 .build_spdif = patch_conexant_build_spdif
1033 int patch_conexant(ac97_t * ac97)
1035 ac97->build_ops = &patch_conexant_ops;
1036 ac97->flags |= AC97_CX_SPDIF;
1037 ac97->ext_id |= AC97_EI_SPDIF; /* force the detection of spdif */
1038 ac97->rates[AC97_RATES_SPDIF] = SNDRV_PCM_RATE_48000; /* 48k only */
1043 * Analog Device AD18xx, AD19xx codecs
1046 static void ad18xx_resume(ac97_t *ac97)
1048 static unsigned short setup_regs[] = {
1049 AC97_AD_MISC, AC97_AD_SERIAL_CFG, AC97_AD_JACK_SPDIF,
1053 for (i = 0; i < (int)ARRAY_SIZE(setup_regs); i++) {
1054 unsigned short reg = setup_regs[i];
1055 if (test_bit(reg, ac97->reg_accessed)) {
1056 snd_ac97_write(ac97, reg, ac97->regs[reg]);
1057 snd_ac97_read(ac97, reg);
1061 if (! (ac97->flags & AC97_AD_MULTI))
1062 /* normal restore */
1063 snd_ac97_restore_status(ac97);
1065 /* restore the AD18xx codec configurations */
1066 for (codec = 0; codec < 3; codec++) {
1067 if (! ac97->spec.ad18xx.id[codec])
1069 /* select single codec */
1070 snd_ac97_update_bits(ac97, AC97_AD_SERIAL_CFG, 0x7000,
1071 ac97->spec.ad18xx.unchained[codec] | ac97->spec.ad18xx.chained[codec]);
1072 ac97->bus->ops->write(ac97, AC97_AD_CODEC_CFG, ac97->spec.ad18xx.codec_cfg[codec]);
1074 /* select all codecs */
1075 snd_ac97_update_bits(ac97, AC97_AD_SERIAL_CFG, 0x7000, 0x7000);
1077 /* restore status */
1078 for (i = 2; i < 0x7c ; i += 2) {
1079 if (i == AC97_POWERDOWN || i == AC97_EXTENDED_ID)
1081 if (test_bit(i, ac97->reg_accessed)) {
1082 /* handle multi codecs for AD18xx */
1083 if (i == AC97_PCM) {
1084 for (codec = 0; codec < 3; codec++) {
1085 if (! ac97->spec.ad18xx.id[codec])
1087 /* select single codec */
1088 snd_ac97_update_bits(ac97, AC97_AD_SERIAL_CFG, 0x7000,
1089 ac97->spec.ad18xx.unchained[codec] | ac97->spec.ad18xx.chained[codec]);
1090 /* update PCM bits */
1091 ac97->bus->ops->write(ac97, AC97_PCM, ac97->spec.ad18xx.pcmreg[codec]);
1093 /* select all codecs */
1094 snd_ac97_update_bits(ac97, AC97_AD_SERIAL_CFG, 0x7000, 0x7000);
1096 } else if (i == AC97_AD_TEST ||
1097 i == AC97_AD_CODEC_CFG ||
1098 i == AC97_AD_SERIAL_CFG)
1099 continue; /* ignore */
1101 snd_ac97_write(ac97, i, ac97->regs[i]);
1102 snd_ac97_read(ac97, i);
1106 snd_ac97_restore_iec958(ac97);
1110 int patch_ad1819(ac97_t * ac97)
1112 unsigned short scfg;
1114 // patch for Analog Devices
1115 scfg = snd_ac97_read(ac97, AC97_AD_SERIAL_CFG);
1116 snd_ac97_write_cache(ac97, AC97_AD_SERIAL_CFG, scfg | 0x7000); /* select all codecs */
1120 static unsigned short patch_ad1881_unchained(ac97_t * ac97, int idx, unsigned short mask)
1124 // test for unchained codec
1125 snd_ac97_update_bits(ac97, AC97_AD_SERIAL_CFG, 0x7000, mask);
1126 snd_ac97_write_cache(ac97, AC97_AD_CODEC_CFG, 0x0000); /* ID0C, ID1C, SDIE = off */
1127 val = snd_ac97_read(ac97, AC97_VENDOR_ID2);
1128 if ((val & 0xff40) != 0x5340)
1130 ac97->spec.ad18xx.unchained[idx] = mask;
1131 ac97->spec.ad18xx.id[idx] = val;
1132 ac97->spec.ad18xx.codec_cfg[idx] = 0x0000;
1136 static int patch_ad1881_chained1(ac97_t * ac97, int idx, unsigned short codec_bits)
1138 static int cfg_bits[3] = { 1<<12, 1<<14, 1<<13 };
1141 snd_ac97_update_bits(ac97, AC97_AD_SERIAL_CFG, 0x7000, cfg_bits[idx]);
1142 snd_ac97_write_cache(ac97, AC97_AD_CODEC_CFG, 0x0004); // SDIE
1143 val = snd_ac97_read(ac97, AC97_VENDOR_ID2);
1144 if ((val & 0xff40) != 0x5340)
1147 snd_ac97_write_cache(ac97, AC97_AD_CODEC_CFG, codec_bits);
1148 ac97->spec.ad18xx.chained[idx] = cfg_bits[idx];
1149 ac97->spec.ad18xx.id[idx] = val;
1150 ac97->spec.ad18xx.codec_cfg[idx] = codec_bits ? codec_bits : 0x0004;
1154 static void patch_ad1881_chained(ac97_t * ac97, int unchained_idx, int cidx1, int cidx2)
1156 // already detected?
1157 if (ac97->spec.ad18xx.unchained[cidx1] || ac97->spec.ad18xx.chained[cidx1])
1159 if (ac97->spec.ad18xx.unchained[cidx2] || ac97->spec.ad18xx.chained[cidx2])
1161 if (cidx1 < 0 && cidx2 < 0)
1163 // test for chained codecs
1164 snd_ac97_update_bits(ac97, AC97_AD_SERIAL_CFG, 0x7000,
1165 ac97->spec.ad18xx.unchained[unchained_idx]);
1166 snd_ac97_write_cache(ac97, AC97_AD_CODEC_CFG, 0x0002); // ID1C
1167 ac97->spec.ad18xx.codec_cfg[unchained_idx] = 0x0002;
1169 if (patch_ad1881_chained1(ac97, cidx1, 0x0006)) // SDIE | ID1C
1170 patch_ad1881_chained1(ac97, cidx2, 0);
1171 else if (patch_ad1881_chained1(ac97, cidx2, 0x0006)) // SDIE | ID1C
1172 patch_ad1881_chained1(ac97, cidx1, 0);
1173 } else if (cidx2 >= 0) {
1174 patch_ad1881_chained1(ac97, cidx2, 0);
1178 static struct snd_ac97_build_ops patch_ad1881_build_ops = {
1180 .resume = ad18xx_resume
1184 int patch_ad1881(ac97_t * ac97)
1186 static const char cfg_idxs[3][2] = {
1192 // patch for Analog Devices
1193 unsigned short codecs[3];
1197 val = snd_ac97_read(ac97, AC97_AD_SERIAL_CFG);
1198 snd_ac97_write_cache(ac97, AC97_AD_SERIAL_CFG, val);
1199 codecs[0] = patch_ad1881_unchained(ac97, 0, (1<<12));
1200 codecs[1] = patch_ad1881_unchained(ac97, 1, (1<<14));
1201 codecs[2] = patch_ad1881_unchained(ac97, 2, (1<<13));
1203 snd_runtime_check(codecs[0] | codecs[1] | codecs[2], goto __end);
1205 for (idx = 0; idx < 3; idx++)
1206 if (ac97->spec.ad18xx.unchained[idx])
1207 patch_ad1881_chained(ac97, idx, cfg_idxs[idx][0], cfg_idxs[idx][1]);
1209 if (ac97->spec.ad18xx.id[1]) {
1210 ac97->flags |= AC97_AD_MULTI;
1211 ac97->scaps |= AC97_SCAP_SURROUND_DAC;
1213 if (ac97->spec.ad18xx.id[2]) {
1214 ac97->flags |= AC97_AD_MULTI;
1215 ac97->scaps |= AC97_SCAP_CENTER_LFE_DAC;
1219 /* select all codecs */
1220 snd_ac97_update_bits(ac97, AC97_AD_SERIAL_CFG, 0x7000, 0x7000);
1221 /* check if only one codec is present */
1222 for (idx = num = 0; idx < 3; idx++)
1223 if (ac97->spec.ad18xx.id[idx])
1226 /* ok, deselect all ID bits */
1227 snd_ac97_write_cache(ac97, AC97_AD_CODEC_CFG, 0x0000);
1228 ac97->spec.ad18xx.codec_cfg[0] =
1229 ac97->spec.ad18xx.codec_cfg[1] =
1230 ac97->spec.ad18xx.codec_cfg[2] = 0x0000;
1232 /* required for AD1886/AD1885 combination */
1233 ac97->ext_id = snd_ac97_read(ac97, AC97_EXTENDED_ID);
1234 if (ac97->spec.ad18xx.id[0]) {
1235 ac97->id &= 0xffff0000;
1236 ac97->id |= ac97->spec.ad18xx.id[0];
1238 ac97->build_ops = &patch_ad1881_build_ops;
1242 static const snd_kcontrol_new_t snd_ac97_controls_ad1885[] = {
1243 AC97_SINGLE("Digital Mono Direct", AC97_AD_MISC, 11, 1, 0),
1244 /* AC97_SINGLE("Digital Audio Mode", AC97_AD_MISC, 12, 1, 0), */ /* seems problematic */
1245 AC97_SINGLE("Low Power Mixer", AC97_AD_MISC, 14, 1, 0),
1246 AC97_SINGLE("Zero Fill DAC", AC97_AD_MISC, 15, 1, 0),
1247 AC97_SINGLE("Headphone Jack Sense", AC97_AD_JACK_SPDIF, 9, 1, 1), /* inverted */
1248 AC97_SINGLE("Line Jack Sense", AC97_AD_JACK_SPDIF, 8, 1, 1), /* inverted */
1251 static int patch_ad1885_specific(ac97_t * ac97)
1255 if ((err = patch_build_controls(ac97, snd_ac97_controls_ad1885, ARRAY_SIZE(snd_ac97_controls_ad1885))) < 0)
1260 static struct snd_ac97_build_ops patch_ad1885_build_ops = {
1261 .build_specific = &patch_ad1885_specific,
1263 .resume = ad18xx_resume
1267 int patch_ad1885(ac97_t * ac97)
1270 /* This is required to deal with the Intel D815EEAL2 */
1271 /* i.e. Line out is actually headphone out from codec */
1274 snd_ac97_write_cache(ac97, AC97_AD_MISC, 0x0404);
1276 ac97->build_ops = &patch_ad1885_build_ops;
1280 int patch_ad1886(ac97_t * ac97)
1283 /* Presario700 workaround */
1284 /* for Jack Sense/SPDIF Register misetting causing */
1285 snd_ac97_write_cache(ac97, AC97_AD_JACK_SPDIF, 0x0010);
1290 #define AC97_AD198X_MBC 0x0003 /* mic boost */
1291 #define AC97_AD198X_MBC_20 0x0000 /* +20dB */
1292 #define AC97_AD198X_MBC_10 0x0001 /* +10dB */
1293 #define AC97_AD198X_MBC_30 0x0002 /* +30dB */
1294 #define AC97_AD198X_VREFD 0x0004 /* VREF high-Z */
1295 #define AC97_AD198X_VREFH 0x0008 /* 2.25V, 3.7V */
1296 #define AC97_AD198X_VREF_0 0x000c /* 0V */
1297 #define AC97_AD198X_SRU 0x0010 /* sample rate unlock */
1298 #define AC97_AD198X_LOSEL 0x0020 /* LINE_OUT amplifiers input select */
1299 #define AC97_AD198X_2MIC 0x0040 /* 2-channel mic select */
1300 #define AC97_AD198X_SPRD 0x0080 /* SPREAD enable */
1301 #define AC97_AD198X_DMIX0 0x0100 /* downmix mode: 0 = 6-to-4, 1 = 6-to-2 downmix */
1302 #define AC97_AD198X_DMIX1 0x0200 /* downmix mode: 1 = enabled */
1303 #define AC97_AD198X_HPSEL 0x0400 /* headphone amplifier input select */
1304 #define AC97_AD198X_CLDIS 0x0800 /* center/lfe disable */
1305 #define AC97_AD198X_LODIS 0x1000 /* LINE_OUT disable */
1306 #define AC97_AD198X_MSPLT 0x2000 /* mute split */
1307 #define AC97_AD198X_AC97NC 0x4000 /* AC97 no compatible mode */
1308 #define AC97_AD198X_DACZ 0x8000 /* DAC zero-fill mode */
1311 static int snd_ac97_ad198x_spdif_source_info(snd_kcontrol_t *kcontrol, snd_ctl_elem_info_t * uinfo)
1313 static char *texts[2] = { "AC-Link", "A/D Converter" };
1315 uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED;
1317 uinfo->value.enumerated.items = 2;
1318 if (uinfo->value.enumerated.item > 1)
1319 uinfo->value.enumerated.item = 1;
1320 strcpy(uinfo->value.enumerated.name, texts[uinfo->value.enumerated.item]);
1324 static int snd_ac97_ad198x_spdif_source_get(snd_kcontrol_t * kcontrol, snd_ctl_elem_value_t * ucontrol)
1326 ac97_t *ac97 = snd_kcontrol_chip(kcontrol);
1329 val = ac97->regs[AC97_AD_SERIAL_CFG];
1330 ucontrol->value.enumerated.item[0] = (val >> 2) & 1;
1334 static int snd_ac97_ad198x_spdif_source_put(snd_kcontrol_t * kcontrol, snd_ctl_elem_value_t * ucontrol)
1336 ac97_t *ac97 = snd_kcontrol_chip(kcontrol);
1339 if (ucontrol->value.enumerated.item[0] > 1)
1341 val = ucontrol->value.enumerated.item[0] << 2;
1342 return snd_ac97_update_bits(ac97, AC97_AD_SERIAL_CFG, 0x0004, val);
1345 static const snd_kcontrol_new_t snd_ac97_ad198x_spdif_source = {
1346 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
1347 .name = SNDRV_CTL_NAME_IEC958("",PLAYBACK,NONE) "Source",
1348 .info = snd_ac97_ad198x_spdif_source_info,
1349 .get = snd_ac97_ad198x_spdif_source_get,
1350 .put = snd_ac97_ad198x_spdif_source_put,
1353 static int patch_ad198x_post_spdif(ac97_t * ac97)
1355 return patch_build_controls(ac97, &snd_ac97_ad198x_spdif_source, 1);
1358 static const snd_kcontrol_new_t snd_ac97_ad1981x_jack_sense[] = {
1359 AC97_SINGLE("Headphone Jack Sense", AC97_AD_JACK_SPDIF, 11, 1, 0),
1360 AC97_SINGLE("Line Jack Sense", AC97_AD_JACK_SPDIF, 12, 1, 0),
1363 static int patch_ad1981a_specific(ac97_t * ac97)
1365 return patch_build_controls(ac97, snd_ac97_ad1981x_jack_sense,
1366 ARRAY_SIZE(snd_ac97_ad1981x_jack_sense));
1369 static struct snd_ac97_build_ops patch_ad1981a_build_ops = {
1370 .build_post_spdif = patch_ad198x_post_spdif,
1371 .build_specific = patch_ad1981a_specific,
1373 .resume = ad18xx_resume
1377 static void check_ad1981_hp_jack_sense(ac97_t *ac97)
1379 u32 subid = ((u32)ac97->subsystem_vendor << 16) | ac97->subsystem_device;
1381 case 0x103c0890: /* HP nc6000 */
1382 case 0x103c006d: /* HP nx9105 */
1383 case 0x17340088: /* FSC Scenic-W */
1384 /* enable headphone jack sense */
1385 snd_ac97_update_bits(ac97, AC97_AD_JACK_SPDIF, 1<<11, 1<<11);
1390 int patch_ad1981a(ac97_t *ac97)
1393 ac97->build_ops = &patch_ad1981a_build_ops;
1394 snd_ac97_update_bits(ac97, AC97_AD_MISC, AC97_AD198X_MSPLT, AC97_AD198X_MSPLT);
1395 ac97->flags |= AC97_STEREO_MUTES;
1396 check_ad1981_hp_jack_sense(ac97);
1400 static const snd_kcontrol_new_t snd_ac97_ad198x_2cmic =
1401 AC97_SINGLE("Stereo Mic", AC97_AD_MISC, 6, 1, 0);
1403 static int patch_ad1981b_specific(ac97_t *ac97)
1407 if ((err = patch_build_controls(ac97, &snd_ac97_ad198x_2cmic, 1)) < 0)
1409 return patch_build_controls(ac97, snd_ac97_ad1981x_jack_sense,
1410 ARRAY_SIZE(snd_ac97_ad1981x_jack_sense));
1413 static struct snd_ac97_build_ops patch_ad1981b_build_ops = {
1414 .build_post_spdif = patch_ad198x_post_spdif,
1415 .build_specific = patch_ad1981b_specific,
1417 .resume = ad18xx_resume
1421 int patch_ad1981b(ac97_t *ac97)
1424 ac97->build_ops = &patch_ad1981b_build_ops;
1425 snd_ac97_update_bits(ac97, AC97_AD_MISC, AC97_AD198X_MSPLT, AC97_AD198X_MSPLT);
1426 ac97->flags |= AC97_STEREO_MUTES;
1427 check_ad1981_hp_jack_sense(ac97);
1431 static int snd_ac97_ad1888_lohpsel_info(snd_kcontrol_t *kcontrol, snd_ctl_elem_info_t *uinfo)
1433 uinfo->type = SNDRV_CTL_ELEM_TYPE_BOOLEAN;
1435 uinfo->value.integer.min = 0;
1436 uinfo->value.integer.max = 1;
1440 static int snd_ac97_ad1888_lohpsel_get(snd_kcontrol_t *kcontrol, snd_ctl_elem_value_t* ucontrol)
1442 ac97_t *ac97 = snd_kcontrol_chip(kcontrol);
1445 val = ac97->regs[AC97_AD_MISC];
1446 ucontrol->value.integer.value[0] = !(val & AC97_AD198X_LOSEL);
1450 static int snd_ac97_ad1888_lohpsel_put(snd_kcontrol_t *kcontrol, snd_ctl_elem_value_t *ucontrol)
1452 ac97_t *ac97 = snd_kcontrol_chip(kcontrol);
1455 val = !ucontrol->value.integer.value[0]
1456 ? (AC97_AD198X_LOSEL | AC97_AD198X_HPSEL) : 0;
1457 return snd_ac97_update_bits(ac97, AC97_AD_MISC,
1458 AC97_AD198X_LOSEL | AC97_AD198X_HPSEL, val);
1461 static int snd_ac97_ad1888_downmix_info(snd_kcontrol_t *kcontrol, snd_ctl_elem_info_t *uinfo)
1463 static char *texts[3] = {"Off", "6 -> 4", "6 -> 2"};
1465 uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED;
1467 uinfo->value.enumerated.items = 3;
1468 if (uinfo->value.enumerated.item > 2)
1469 uinfo->value.enumerated.item = 2;
1470 strcpy(uinfo->value.enumerated.name, texts[uinfo->value.enumerated.item]);
1474 static int snd_ac97_ad1888_downmix_get(snd_kcontrol_t *kcontrol, snd_ctl_elem_value_t* ucontrol)
1476 ac97_t *ac97 = snd_kcontrol_chip(kcontrol);
1479 val = ac97->regs[AC97_AD_MISC];
1480 if (!(val & AC97_AD198X_DMIX1))
1481 ucontrol->value.enumerated.item[0] = 0;
1483 ucontrol->value.enumerated.item[0] = 1 + ((val >> 8) & 1);
1487 static int snd_ac97_ad1888_downmix_put(snd_kcontrol_t *kcontrol, snd_ctl_elem_value_t *ucontrol)
1489 ac97_t *ac97 = snd_kcontrol_chip(kcontrol);
1492 if (ucontrol->value.enumerated.item[0] > 2)
1494 if (ucontrol->value.enumerated.item[0] == 0)
1497 val = AC97_AD198X_DMIX1 |
1498 ((ucontrol->value.enumerated.item[0] - 1) << 8);
1499 return snd_ac97_update_bits(ac97, AC97_AD_MISC,
1500 AC97_AD198X_DMIX0 | AC97_AD198X_DMIX1, val);
1503 static void ad1888_update_jacks(ac97_t *ac97)
1505 /* shared Line-In */
1506 snd_ac97_update_bits(ac97, AC97_AD_MISC, 1 << 12,
1507 is_shared_linein(ac97) ? 0 : 1 << 12);
1509 snd_ac97_update_bits(ac97, AC97_AD_MISC, 1 << 11,
1510 is_shared_micin(ac97) ? 0 : 1 << 13);
1513 static const snd_kcontrol_new_t snd_ac97_ad1888_controls[] = {
1515 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
1516 .name = "Exchange Front/Surround",
1517 .info = snd_ac97_ad1888_lohpsel_info,
1518 .get = snd_ac97_ad1888_lohpsel_get,
1519 .put = snd_ac97_ad1888_lohpsel_put
1521 AC97_SINGLE("Spread Front to Surround and Center/LFE", AC97_AD_MISC, 7, 1, 0),
1523 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
1525 .info = snd_ac97_ad1888_downmix_info,
1526 .get = snd_ac97_ad1888_downmix_get,
1527 .put = snd_ac97_ad1888_downmix_put
1530 AC97_SINGLE("Surround Jack as Input", AC97_AD_MISC, 12, 1, 0),
1531 AC97_SINGLE("Center/LFE Jack as Input", AC97_AD_MISC, 11, 1, 0),
1533 AC97_SURROUND_JACK_MODE_CTL,
1534 AC97_CHANNEL_MODE_CTL,
1538 static int patch_ad1888_specific(ac97_t *ac97)
1540 /* rename 0x04 as "Master" and 0x02 as "Master Surround" */
1541 snd_ac97_rename_vol_ctl(ac97, "Master Playback", "Master Surround Playback");
1542 snd_ac97_rename_vol_ctl(ac97, "Headphone Playback", "Master Playback");
1543 return patch_build_controls(ac97, snd_ac97_ad1888_controls, ARRAY_SIZE(snd_ac97_ad1888_controls));
1546 static struct snd_ac97_build_ops patch_ad1888_build_ops = {
1547 .build_post_spdif = patch_ad198x_post_spdif,
1548 .build_specific = patch_ad1888_specific,
1550 .resume = ad18xx_resume,
1552 .update_jacks = ad1888_update_jacks,
1555 int patch_ad1888(ac97_t * ac97)
1557 unsigned short misc;
1560 ac97->build_ops = &patch_ad1888_build_ops;
1561 /* Switch FRONT/SURROUND LINE-OUT/HP-OUT default connection */
1562 /* it seems that most vendors connect line-out connector to headphone out of AC'97 */
1563 /* AD-compatible mode */
1564 /* Stereo mutes enabled */
1565 misc = snd_ac97_read(ac97, AC97_AD_MISC);
1566 snd_ac97_write_cache(ac97, AC97_AD_MISC, misc |
1570 AC97_AD198X_AC97NC);
1571 ac97->flags |= AC97_STEREO_MUTES;
1575 static int patch_ad1980_specific(ac97_t *ac97)
1579 if ((err = patch_ad1888_specific(ac97)) < 0)
1581 return patch_build_controls(ac97, &snd_ac97_ad198x_2cmic, 1);
1584 static struct snd_ac97_build_ops patch_ad1980_build_ops = {
1585 .build_post_spdif = patch_ad198x_post_spdif,
1586 .build_specific = patch_ad1980_specific,
1588 .resume = ad18xx_resume
1592 int patch_ad1980(ac97_t * ac97)
1595 ac97->build_ops = &patch_ad1980_build_ops;
1599 static const snd_kcontrol_new_t snd_ac97_ad1985_controls[] = {
1600 AC97_SINGLE("Center/LFE Jack as Mic", AC97_AD_SERIAL_CFG, 9, 1, 0),
1601 AC97_SINGLE("Exchange Center/LFE", AC97_AD_SERIAL_CFG, 3, 1, 0)
1604 static int patch_ad1985_specific(ac97_t *ac97)
1608 if ((err = patch_ad1980_specific(ac97)) < 0)
1610 return patch_build_controls(ac97, snd_ac97_ad1985_controls, ARRAY_SIZE(snd_ac97_ad1985_controls));
1613 static struct snd_ac97_build_ops patch_ad1985_build_ops = {
1614 .build_post_spdif = patch_ad198x_post_spdif,
1615 .build_specific = patch_ad1985_specific,
1617 .resume = ad18xx_resume
1621 int patch_ad1985(ac97_t * ac97)
1623 unsigned short misc;
1626 ac97->build_ops = &patch_ad1985_build_ops;
1627 misc = snd_ac97_read(ac97, AC97_AD_MISC);
1628 /* switch front/surround line-out/hp-out */
1629 /* center/LFE, mic in 3.75V mode */
1630 /* AD-compatible mode */
1631 /* Stereo mutes enabled */
1632 /* in accordance with ADI driver: misc | 0x5c28 */
1633 snd_ac97_write_cache(ac97, AC97_AD_MISC, misc |
1640 AC97_AD198X_AC97NC);
1641 ac97->flags |= AC97_STEREO_MUTES;
1642 /* on AD1985 rev. 3, AC'97 revision bits are zero */
1643 ac97->ext_id = (ac97->ext_id & ~AC97_EI_REV_MASK) | AC97_EI_REV_23;
1648 * realtek ALC65x/850 codecs
1650 static void alc650_update_jacks(ac97_t *ac97)
1654 /* shared Line-In */
1655 shared = is_shared_linein(ac97);
1656 snd_ac97_update_bits(ac97, AC97_ALC650_MULTICH, 1 << 9,
1657 shared ? (1 << 9) : 0);
1658 /* update shared Mic */
1659 shared = is_shared_micin(ac97);
1660 /* disable/enable vref */
1661 snd_ac97_update_bits(ac97, AC97_ALC650_CLOCK, 1 << 12,
1662 shared ? (1 << 12) : 0);
1663 /* turn on/off center-on-mic */
1664 snd_ac97_update_bits(ac97, AC97_ALC650_MULTICH, 1 << 10,
1665 shared ? (1 << 10) : 0);
1666 /* GPIO0 high for mic */
1667 snd_ac97_update_bits(ac97, AC97_ALC650_GPIO_STATUS, 0x100,
1668 shared ? 0 : 0x100);
1671 static const snd_kcontrol_new_t snd_ac97_controls_alc650[] = {
1672 AC97_SINGLE("Duplicate Front", AC97_ALC650_MULTICH, 0, 1, 0),
1673 AC97_SINGLE("Surround Down Mix", AC97_ALC650_MULTICH, 1, 1, 0),
1674 AC97_SINGLE("Center/LFE Down Mix", AC97_ALC650_MULTICH, 2, 1, 0),
1675 AC97_SINGLE("Exchange Center/LFE", AC97_ALC650_MULTICH, 3, 1, 0),
1676 /* 4: Analog Input To Surround */
1677 /* 5: Analog Input To Center/LFE */
1678 /* 6: Independent Master Volume Right */
1679 /* 7: Independent Master Volume Left */
1681 /* 9: Line-In/Surround share */
1682 /* 10: Mic/CLFE share */
1683 /* 11-13: in IEC958 controls */
1684 AC97_SINGLE("Swap Surround Slot", AC97_ALC650_MULTICH, 14, 1, 0),
1685 #if 0 /* always set in patch_alc650 */
1686 AC97_SINGLE("IEC958 Input Clock Enable", AC97_ALC650_CLOCK, 0, 1, 0),
1687 AC97_SINGLE("IEC958 Input Pin Enable", AC97_ALC650_CLOCK, 1, 1, 0),
1688 AC97_SINGLE("Surround DAC Switch", AC97_ALC650_SURR_DAC_VOL, 15, 1, 1),
1689 AC97_DOUBLE("Surround DAC Volume", AC97_ALC650_SURR_DAC_VOL, 8, 0, 31, 1),
1690 AC97_SINGLE("Center/LFE DAC Switch", AC97_ALC650_LFE_DAC_VOL, 15, 1, 1),
1691 AC97_DOUBLE("Center/LFE DAC Volume", AC97_ALC650_LFE_DAC_VOL, 8, 0, 31, 1),
1693 AC97_SURROUND_JACK_MODE_CTL,
1694 AC97_CHANNEL_MODE_CTL,
1697 static const snd_kcontrol_new_t snd_ac97_spdif_controls_alc650[] = {
1698 AC97_SINGLE("IEC958 Capture Switch", AC97_ALC650_MULTICH, 11, 1, 0),
1699 AC97_SINGLE("Analog to IEC958 Output", AC97_ALC650_MULTICH, 12, 1, 0),
1700 /* disable this controls since it doesn't work as expected */
1701 /* AC97_SINGLE("IEC958 Input Monitor", AC97_ALC650_MULTICH, 13, 1, 0), */
1704 static int patch_alc650_specific(ac97_t * ac97)
1708 if ((err = patch_build_controls(ac97, snd_ac97_controls_alc650, ARRAY_SIZE(snd_ac97_controls_alc650))) < 0)
1710 if (ac97->ext_id & AC97_EI_SPDIF) {
1711 if ((err = patch_build_controls(ac97, snd_ac97_spdif_controls_alc650, ARRAY_SIZE(snd_ac97_spdif_controls_alc650))) < 0)
1717 static struct snd_ac97_build_ops patch_alc650_ops = {
1718 .build_specific = patch_alc650_specific,
1719 .update_jacks = alc650_update_jacks
1722 int patch_alc650(ac97_t * ac97)
1726 ac97->build_ops = &patch_alc650_ops;
1728 /* determine the revision */
1729 val = snd_ac97_read(ac97, AC97_ALC650_REVISION) & 0x3f;
1731 ac97->id = 0x414c4720; /* Old version */
1732 else if (val < 0x10)
1733 ac97->id = 0x414c4721; /* D version */
1734 else if (val < 0x20)
1735 ac97->id = 0x414c4722; /* E version */
1736 else if (val < 0x30)
1737 ac97->id = 0x414c4723; /* F version */
1739 /* revision E or F */
1740 /* FIXME: what about revision D ? */
1741 ac97->spec.dev_flags = (ac97->id == 0x414c4722 ||
1742 ac97->id == 0x414c4723);
1744 /* enable AC97_ALC650_GPIO_SETUP, AC97_ALC650_CLOCK for R/W */
1745 snd_ac97_write_cache(ac97, AC97_ALC650_GPIO_STATUS,
1746 snd_ac97_read(ac97, AC97_ALC650_GPIO_STATUS) | 0x8000);
1748 /* Enable SPDIF-IN only on Rev.E and above */
1749 val = snd_ac97_read(ac97, AC97_ALC650_CLOCK);
1750 /* SPDIF IN with pin 47 */
1751 if (ac97->spec.dev_flags)
1752 val |= 0x03; /* enable */
1754 val &= ~0x03; /* disable */
1755 snd_ac97_write_cache(ac97, AC97_ALC650_CLOCK, val);
1757 /* set default: slot 3,4,7,8,6,9
1758 spdif-in monitor off, analog-spdif off, spdif-in off
1759 center on mic off, surround on line-in off
1760 downmix off, duplicate front off
1762 snd_ac97_write_cache(ac97, AC97_ALC650_MULTICH, 0);
1764 /* set GPIO0 for mic bias */
1765 /* GPIO0 pin output, no interrupt, high */
1766 snd_ac97_write_cache(ac97, AC97_ALC650_GPIO_SETUP,
1767 snd_ac97_read(ac97, AC97_ALC650_GPIO_SETUP) | 0x01);
1768 snd_ac97_write_cache(ac97, AC97_ALC650_GPIO_STATUS,
1769 (snd_ac97_read(ac97, AC97_ALC650_GPIO_STATUS) | 0x100) & ~0x10);
1771 /* full DAC volume */
1772 snd_ac97_write_cache(ac97, AC97_ALC650_SURR_DAC_VOL, 0x0808);
1773 snd_ac97_write_cache(ac97, AC97_ALC650_LFE_DAC_VOL, 0x0808);
1777 static void alc655_update_jacks(ac97_t *ac97)
1781 /* shared Line-In */
1782 shared = is_shared_linein(ac97);
1783 ac97_update_bits_page(ac97, AC97_ALC650_MULTICH, 1 << 9,
1784 shared ? (1 << 9) : 0, 0);
1785 /* update shared mic */
1786 shared = is_shared_micin(ac97);
1787 /* misc control; vrefout disable */
1788 snd_ac97_update_bits(ac97, AC97_ALC650_CLOCK, 1 << 12,
1789 shared ? (1 << 12) : 0);
1790 ac97_update_bits_page(ac97, AC97_ALC650_MULTICH, 1 << 10,
1791 shared ? (1 << 10) : 0, 0);
1794 static const snd_kcontrol_new_t snd_ac97_controls_alc655[] = {
1795 AC97_PAGE_SINGLE("Duplicate Front", AC97_ALC650_MULTICH, 0, 1, 0, 0),
1796 AC97_SURROUND_JACK_MODE_CTL,
1797 AC97_CHANNEL_MODE_CTL,
1800 static int alc655_iec958_route_info(snd_kcontrol_t *kcontrol, snd_ctl_elem_info_t *uinfo)
1802 static char *texts_655[3] = { "PCM", "Analog In", "IEC958 In" };
1803 static char *texts_658[4] = { "PCM", "Analog1 In", "Analog2 In", "IEC958 In" };
1804 ac97_t *ac97 = snd_kcontrol_chip(kcontrol);
1806 uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED;
1808 uinfo->value.enumerated.items = ac97->spec.dev_flags ? 4 : 3;
1809 if (uinfo->value.enumerated.item >= uinfo->value.enumerated.items)
1810 uinfo->value.enumerated.item = uinfo->value.enumerated.items - 1;
1811 strcpy(uinfo->value.enumerated.name,
1812 ac97->spec.dev_flags ?
1813 texts_658[uinfo->value.enumerated.item] :
1814 texts_655[uinfo->value.enumerated.item]);
1818 static int alc655_iec958_route_get(snd_kcontrol_t *kcontrol, snd_ctl_elem_value_t *ucontrol)
1820 ac97_t *ac97 = snd_kcontrol_chip(kcontrol);
1823 val = ac97->regs[AC97_ALC650_MULTICH];
1824 val = (val >> 12) & 3;
1825 if (ac97->spec.dev_flags && val == 3)
1827 ucontrol->value.enumerated.item[0] = val;
1831 static int alc655_iec958_route_put(snd_kcontrol_t *kcontrol, snd_ctl_elem_value_t *ucontrol)
1833 ac97_t *ac97 = snd_kcontrol_chip(kcontrol);
1835 return ac97_update_bits_page(ac97, AC97_ALC650_MULTICH, 3 << 12,
1836 (unsigned short)ucontrol->value.enumerated.item[0] << 12,
1840 static const snd_kcontrol_new_t snd_ac97_spdif_controls_alc655[] = {
1841 AC97_PAGE_SINGLE("IEC958 Capture Switch", AC97_ALC650_MULTICH, 11, 1, 0, 0),
1842 /* disable this controls since it doesn't work as expected */
1843 /* AC97_PAGE_SINGLE("IEC958 Input Monitor", AC97_ALC650_MULTICH, 14, 1, 0, 0), */
1845 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
1846 .name = "IEC958 Playback Route",
1847 .info = alc655_iec958_route_info,
1848 .get = alc655_iec958_route_get,
1849 .put = alc655_iec958_route_put,
1853 static int patch_alc655_specific(ac97_t * ac97)
1857 if ((err = patch_build_controls(ac97, snd_ac97_controls_alc655, ARRAY_SIZE(snd_ac97_controls_alc655))) < 0)
1859 if (ac97->ext_id & AC97_EI_SPDIF) {
1860 if ((err = patch_build_controls(ac97, snd_ac97_spdif_controls_alc655, ARRAY_SIZE(snd_ac97_spdif_controls_alc655))) < 0)
1866 static struct snd_ac97_build_ops patch_alc655_ops = {
1867 .build_specific = patch_alc655_specific,
1868 .update_jacks = alc655_update_jacks
1871 int patch_alc655(ac97_t * ac97)
1875 ac97->spec.dev_flags = (ac97->id == 0x414c4780); /* ALC658 */
1877 ac97->build_ops = &patch_alc655_ops;
1879 /* assume only page 0 for writing cache */
1880 snd_ac97_update_bits(ac97, AC97_INT_PAGING, AC97_PAGE_MASK, AC97_PAGE_VENDOR);
1882 /* adjust default values */
1883 val = snd_ac97_read(ac97, 0x7a); /* misc control */
1884 if (ac97->id == 0x414c4780) /* ALC658 */
1885 val &= ~(1 << 1); /* Pin 47 is spdif input pin */
1887 val |= (1 << 1); /* Pin 47 is spdif input pin */
1888 val &= ~(1 << 12); /* vref enable */
1889 snd_ac97_write_cache(ac97, 0x7a, val);
1890 /* set default: spdif-in enabled,
1891 spdif-in monitor off, spdif-in PCM off
1892 center on mic off, surround on line-in off
1895 snd_ac97_write_cache(ac97, AC97_ALC650_MULTICH, 1<<15);
1897 /* full DAC volume */
1898 snd_ac97_write_cache(ac97, AC97_ALC650_SURR_DAC_VOL, 0x0808);
1899 snd_ac97_write_cache(ac97, AC97_ALC650_LFE_DAC_VOL, 0x0808);
1904 #define AC97_ALC850_JACK_SELECT 0x76
1905 #define AC97_ALC850_MISC1 0x7a
1907 static void alc850_update_jacks(ac97_t *ac97)
1911 /* shared Line-In */
1912 shared = is_shared_linein(ac97);
1913 /* SURR 1kOhm (bit4), Amp (bit5) */
1914 snd_ac97_update_bits(ac97, AC97_ALC850_MISC1, (1<<4)|(1<<5),
1915 shared ? (1<<5) : (1<<4));
1916 /* LINE-IN = 0, SURROUND = 2 */
1917 snd_ac97_update_bits(ac97, AC97_ALC850_JACK_SELECT, 7 << 12,
1918 shared ? (2<<12) : (0<<12));
1919 /* update shared mic */
1920 shared = is_shared_micin(ac97);
1921 /* Vref disable (bit12), 1kOhm (bit13) */
1922 snd_ac97_update_bits(ac97, AC97_ALC850_MISC1, (1<<12)|(1<<13),
1923 shared ? (1<<12) : (1<<13));
1924 /* MIC-IN = 1, CENTER-LFE = 2 */
1925 snd_ac97_update_bits(ac97, AC97_ALC850_JACK_SELECT, 7 << 4,
1926 shared ? (2<<4) : (1<<4));
1929 static const snd_kcontrol_new_t snd_ac97_controls_alc850[] = {
1930 AC97_PAGE_SINGLE("Duplicate Front", AC97_ALC650_MULTICH, 0, 1, 0, 0),
1931 AC97_SURROUND_JACK_MODE_CTL,
1932 AC97_CHANNEL_MODE_CTL,
1935 static int patch_alc850_specific(ac97_t *ac97)
1939 if ((err = patch_build_controls(ac97, snd_ac97_controls_alc850, ARRAY_SIZE(snd_ac97_controls_alc850))) < 0)
1941 if (ac97->ext_id & AC97_EI_SPDIF) {
1942 if ((err = patch_build_controls(ac97, snd_ac97_spdif_controls_alc655, ARRAY_SIZE(snd_ac97_spdif_controls_alc655))) < 0)
1948 static struct snd_ac97_build_ops patch_alc850_ops = {
1949 .build_specific = patch_alc850_specific,
1950 .update_jacks = alc850_update_jacks
1953 int patch_alc850(ac97_t *ac97)
1955 ac97->build_ops = &patch_alc850_ops;
1957 ac97->spec.dev_flags = 0; /* for IEC958 playback route - ALC655 compatible */
1959 /* assume only page 0 for writing cache */
1960 snd_ac97_update_bits(ac97, AC97_INT_PAGING, AC97_PAGE_MASK, AC97_PAGE_VENDOR);
1962 /* adjust default values */
1963 /* set default: spdif-in enabled,
1964 spdif-in monitor off, spdif-in PCM off
1965 center on mic off, surround on line-in off
1968 snd_ac97_write_cache(ac97, AC97_ALC650_MULTICH, 1<<15);
1969 /* SURR_OUT: on, Surr 1kOhm: on, Surr Amp: off, Front 1kOhm: off
1970 * Front Amp: on, Vref: enable, Center 1kOhm: on, Mix: on
1972 snd_ac97_write_cache(ac97, 0x7a, (1<<1)|(1<<4)|(0<<5)|(1<<6)|
1973 (1<<7)|(0<<12)|(1<<13)|(0<<14));
1974 /* detection UIO2,3: all path floating, UIO3: MIC, Vref2: disable,
1975 * UIO1: FRONT, Vref3: disable, UIO3: LINE, Front-Mic: mute
1977 snd_ac97_write_cache(ac97, 0x76, (0<<0)|(0<<2)|(1<<4)|(1<<7)|(2<<8)|
1978 (1<<11)|(0<<12)|(1<<15));
1980 /* full DAC volume */
1981 snd_ac97_write_cache(ac97, AC97_ALC650_SURR_DAC_VOL, 0x0808);
1982 snd_ac97_write_cache(ac97, AC97_ALC650_LFE_DAC_VOL, 0x0808);
1988 * C-Media CM97xx codecs
1990 static void cm9738_update_jacks(ac97_t *ac97)
1992 /* shared Line-In */
1993 snd_ac97_update_bits(ac97, AC97_CM9738_VENDOR_CTRL, 1 << 10,
1994 is_shared_linein(ac97) ? (1 << 10) : 0);
1997 static const snd_kcontrol_new_t snd_ac97_cm9738_controls[] = {
1998 AC97_SINGLE("Duplicate Front", AC97_CM9738_VENDOR_CTRL, 13, 1, 0),
1999 AC97_SURROUND_JACK_MODE_CTL,
2000 AC97_CHANNEL_MODE_4CH_CTL,
2003 static int patch_cm9738_specific(ac97_t * ac97)
2005 return patch_build_controls(ac97, snd_ac97_cm9738_controls, ARRAY_SIZE(snd_ac97_cm9738_controls));
2008 static struct snd_ac97_build_ops patch_cm9738_ops = {
2009 .build_specific = patch_cm9738_specific,
2010 .update_jacks = cm9738_update_jacks
2013 int patch_cm9738(ac97_t * ac97)
2015 ac97->build_ops = &patch_cm9738_ops;
2016 /* FIXME: can anyone confirm below? */
2017 /* CM9738 has no PCM volume although the register reacts */
2018 ac97->flags |= AC97_HAS_NO_PCM_VOL;
2019 snd_ac97_write_cache(ac97, AC97_PCM, 0x8000);
2024 static int snd_ac97_cmedia_spdif_playback_source_info(snd_kcontrol_t *kcontrol, snd_ctl_elem_info_t * uinfo)
2026 static char *texts[] = { "Analog", "Digital" };
2028 uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED;
2030 uinfo->value.enumerated.items = 2;
2031 if (uinfo->value.enumerated.item > 1)
2032 uinfo->value.enumerated.item = 1;
2033 strcpy(uinfo->value.enumerated.name, texts[uinfo->value.enumerated.item]);
2037 static int snd_ac97_cmedia_spdif_playback_source_get(snd_kcontrol_t * kcontrol, snd_ctl_elem_value_t * ucontrol)
2039 ac97_t *ac97 = snd_kcontrol_chip(kcontrol);
2042 val = ac97->regs[AC97_CM9739_SPDIF_CTRL];
2043 ucontrol->value.enumerated.item[0] = (val >> 1) & 0x01;
2047 static int snd_ac97_cmedia_spdif_playback_source_put(snd_kcontrol_t * kcontrol, snd_ctl_elem_value_t * ucontrol)
2049 ac97_t *ac97 = snd_kcontrol_chip(kcontrol);
2051 return snd_ac97_update_bits(ac97, AC97_CM9739_SPDIF_CTRL,
2053 (ucontrol->value.enumerated.item[0] & 0x01) << 1);
2056 static const snd_kcontrol_new_t snd_ac97_cm9739_controls_spdif[] = {
2057 /* BIT 0: SPDI_EN - always true */
2058 { /* BIT 1: SPDIFS */
2059 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
2060 .name = SNDRV_CTL_NAME_IEC958("",PLAYBACK,NONE) "Source",
2061 .info = snd_ac97_cmedia_spdif_playback_source_info,
2062 .get = snd_ac97_cmedia_spdif_playback_source_get,
2063 .put = snd_ac97_cmedia_spdif_playback_source_put,
2065 /* BIT 2: IG_SPIV */
2066 AC97_SINGLE(SNDRV_CTL_NAME_IEC958("",CAPTURE,NONE) "Valid Switch", AC97_CM9739_SPDIF_CTRL, 2, 1, 0),
2068 AC97_SINGLE(SNDRV_CTL_NAME_IEC958("",CAPTURE,NONE) "Monitor", AC97_CM9739_SPDIF_CTRL, 3, 1, 0),
2069 /* BIT 4: SPI2SDI */
2070 AC97_SINGLE(SNDRV_CTL_NAME_IEC958("",CAPTURE,SWITCH), AC97_CM9739_SPDIF_CTRL, 4, 1, 0),
2071 /* BIT 8: SPD32 - 32bit SPDIF - not supported yet */
2074 static void cm9739_update_jacks(ac97_t *ac97)
2076 /* shared Line-In */
2077 snd_ac97_update_bits(ac97, AC97_CM9739_MULTI_CHAN, 1 << 10,
2078 is_shared_linein(ac97) ? (1 << 10) : 0);
2080 snd_ac97_update_bits(ac97, AC97_CM9739_MULTI_CHAN, 0x3000,
2081 is_shared_micin(ac97) ? 0x1000 : 0x2000);
2084 static const snd_kcontrol_new_t snd_ac97_cm9739_controls[] = {
2085 AC97_SURROUND_JACK_MODE_CTL,
2086 AC97_CHANNEL_MODE_CTL,
2089 static int patch_cm9739_specific(ac97_t * ac97)
2091 return patch_build_controls(ac97, snd_ac97_cm9739_controls, ARRAY_SIZE(snd_ac97_cm9739_controls));
2094 static int patch_cm9739_post_spdif(ac97_t * ac97)
2096 return patch_build_controls(ac97, snd_ac97_cm9739_controls_spdif, ARRAY_SIZE(snd_ac97_cm9739_controls_spdif));
2099 static struct snd_ac97_build_ops patch_cm9739_ops = {
2100 .build_specific = patch_cm9739_specific,
2101 .build_post_spdif = patch_cm9739_post_spdif,
2102 .update_jacks = cm9739_update_jacks
2105 int patch_cm9739(ac97_t * ac97)
2109 ac97->build_ops = &patch_cm9739_ops;
2111 /* CM9739/A has no Master and PCM volume although the register reacts */
2112 ac97->flags |= AC97_HAS_NO_MASTER_VOL | AC97_HAS_NO_PCM_VOL;
2113 snd_ac97_write_cache(ac97, AC97_MASTER, 0x8000);
2114 snd_ac97_write_cache(ac97, AC97_PCM, 0x8000);
2117 val = snd_ac97_read(ac97, AC97_EXTENDED_STATUS);
2118 if (val & AC97_EA_SPCV) {
2119 /* enable spdif in */
2120 snd_ac97_write_cache(ac97, AC97_CM9739_SPDIF_CTRL,
2121 snd_ac97_read(ac97, AC97_CM9739_SPDIF_CTRL) | 0x01);
2122 ac97->rates[AC97_RATES_SPDIF] = SNDRV_PCM_RATE_48000; /* 48k only */
2124 ac97->ext_id &= ~AC97_EI_SPDIF; /* disable extended-id */
2125 ac97->rates[AC97_RATES_SPDIF] = 0;
2128 /* set-up multi channel */
2129 /* bit 14: 0 = SPDIF, 1 = EAPD */
2130 /* bit 13: enable internal vref output for mic */
2131 /* bit 12: disable center/lfe (swithable) */
2132 /* bit 10: disable surround/line (switchable) */
2133 /* bit 9: mix 2 surround off */
2134 /* bit 4: undocumented; 0 mutes the CM9739A, which defaults to 1 */
2135 /* bit 3: undocumented; surround? */
2137 val = snd_ac97_read(ac97, AC97_CM9739_MULTI_CHAN) & (1 << 4);
2140 if (! (ac97->ext_id & AC97_EI_SPDIF))
2142 snd_ac97_write_cache(ac97, AC97_CM9739_MULTI_CHAN, val);
2144 /* FIXME: set up GPIO */
2145 snd_ac97_write_cache(ac97, 0x70, 0x0100);
2146 snd_ac97_write_cache(ac97, 0x72, 0x0020);
2147 /* Special exception for ASUS W1000/CMI9739. It does not have an SPDIF in. */
2149 ac97->subsystem_vendor == 0x1043 &&
2150 ac97->subsystem_device == 0x1843) {
2151 snd_ac97_write_cache(ac97, AC97_CM9739_SPDIF_CTRL,
2152 snd_ac97_read(ac97, AC97_CM9739_SPDIF_CTRL) & ~0x01);
2153 snd_ac97_write_cache(ac97, AC97_CM9739_MULTI_CHAN,
2154 snd_ac97_read(ac97, AC97_CM9739_MULTI_CHAN) | (1 << 14));
2160 #define AC97_CM9761_MULTI_CHAN 0x64
2161 #define AC97_CM9761_FUNC 0x66
2162 #define AC97_CM9761_SPDIF_CTRL 0x6c
2164 static void cm9761_update_jacks(ac97_t *ac97)
2166 unsigned short surr_vals[2][2] = {
2167 { 0x0008, 0x0400 }, /* off, on */
2168 { 0x0000, 0x0408 }, /* off, on (9761-82 rev.B) */
2170 unsigned short clfe_vals[2][2] = {
2171 { 0x2000, 0x1880 }, /* off, on */
2172 { 0x1000, 0x2880 }, /* off, on (9761-82 rev.B) */
2175 /* shared Line-In */
2176 snd_ac97_update_bits(ac97, AC97_CM9761_MULTI_CHAN, 0x0408,
2177 surr_vals[ac97->spec.dev_flags][is_shared_linein(ac97)]);
2179 snd_ac97_update_bits(ac97, AC97_CM9761_MULTI_CHAN, 0x3880,
2180 clfe_vals[ac97->spec.dev_flags][is_shared_micin(ac97)]);
2183 static const snd_kcontrol_new_t snd_ac97_cm9761_controls[] = {
2184 AC97_SURROUND_JACK_MODE_CTL,
2185 AC97_CHANNEL_MODE_CTL,
2188 static int cm9761_spdif_out_source_info(snd_kcontrol_t *kcontrol, snd_ctl_elem_info_t *uinfo)
2190 static char *texts[] = { "AC-Link", "ADC", "SPDIF-In" };
2192 uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED;
2194 uinfo->value.enumerated.items = 3;
2195 if (uinfo->value.enumerated.item > 2)
2196 uinfo->value.enumerated.item = 2;
2197 strcpy(uinfo->value.enumerated.name, texts[uinfo->value.enumerated.item]);
2201 static int cm9761_spdif_out_source_get(snd_kcontrol_t *kcontrol, snd_ctl_elem_value_t *ucontrol)
2203 ac97_t *ac97 = snd_kcontrol_chip(kcontrol);
2205 if (ac97->regs[AC97_CM9761_FUNC] & 0x1)
2206 ucontrol->value.enumerated.item[0] = 2; /* SPDIF-loopback */
2207 else if (ac97->regs[AC97_CM9761_SPDIF_CTRL] & 0x2)
2208 ucontrol->value.enumerated.item[0] = 1; /* ADC loopback */
2210 ucontrol->value.enumerated.item[0] = 0; /* AC-link */
2214 static int cm9761_spdif_out_source_put(snd_kcontrol_t *kcontrol, snd_ctl_elem_value_t *ucontrol)
2216 ac97_t *ac97 = snd_kcontrol_chip(kcontrol);
2218 if (ucontrol->value.enumerated.item[0] == 2)
2219 return snd_ac97_update_bits(ac97, AC97_CM9761_FUNC, 0x1, 0x1);
2220 snd_ac97_update_bits(ac97, AC97_CM9761_FUNC, 0x1, 0);
2221 return snd_ac97_update_bits(ac97, AC97_CM9761_SPDIF_CTRL, 0x2,
2222 ucontrol->value.enumerated.item[0] == 1 ? 0x2 : 0);
2225 static const char *cm9761_dac_clock[] = { "AC-Link", "SPDIF-In", "Both" };
2226 static const struct ac97_enum cm9761_dac_clock_enum =
2227 AC97_ENUM_SINGLE(AC97_CM9761_SPDIF_CTRL, 9, 3, cm9761_dac_clock);
2229 static const snd_kcontrol_new_t snd_ac97_cm9761_controls_spdif[] = {
2230 { /* BIT 1: SPDIFS */
2231 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
2232 .name = SNDRV_CTL_NAME_IEC958("",PLAYBACK,NONE) "Source",
2233 .info = cm9761_spdif_out_source_info,
2234 .get = cm9761_spdif_out_source_get,
2235 .put = cm9761_spdif_out_source_put,
2237 /* BIT 2: IG_SPIV */
2238 AC97_SINGLE(SNDRV_CTL_NAME_IEC958("",CAPTURE,NONE) "Valid Switch", AC97_CM9761_SPDIF_CTRL, 2, 1, 0),
2240 AC97_SINGLE(SNDRV_CTL_NAME_IEC958("",CAPTURE,NONE) "Monitor", AC97_CM9761_SPDIF_CTRL, 3, 1, 0),
2241 /* BIT 4: SPI2SDI */
2242 AC97_SINGLE(SNDRV_CTL_NAME_IEC958("",CAPTURE,SWITCH), AC97_CM9761_SPDIF_CTRL, 4, 1, 0),
2243 /* BIT 9-10: DAC_CTL */
2244 AC97_ENUM("DAC Clock Source", cm9761_dac_clock_enum),
2247 static int patch_cm9761_post_spdif(ac97_t * ac97)
2249 return patch_build_controls(ac97, snd_ac97_cm9761_controls_spdif, ARRAY_SIZE(snd_ac97_cm9761_controls_spdif));
2252 static int patch_cm9761_specific(ac97_t * ac97)
2254 return patch_build_controls(ac97, snd_ac97_cm9761_controls, ARRAY_SIZE(snd_ac97_cm9761_controls));
2257 static struct snd_ac97_build_ops patch_cm9761_ops = {
2258 .build_specific = patch_cm9761_specific,
2259 .build_post_spdif = patch_cm9761_post_spdif,
2260 .update_jacks = cm9761_update_jacks
2263 int patch_cm9761(ac97_t *ac97)
2267 /* CM9761 has no PCM volume although the register reacts */
2268 /* Master volume seems to have _some_ influence on the analog
2271 ac97->flags |= /*AC97_HAS_NO_MASTER_VOL |*/ AC97_HAS_NO_PCM_VOL;
2272 snd_ac97_write_cache(ac97, AC97_MASTER, 0x8808);
2273 snd_ac97_write_cache(ac97, AC97_PCM, 0x8808);
2275 ac97->spec.dev_flags = 0; /* 1 = model 82 revision B */
2276 if (ac97->id == AC97_ID_CM9761_82) {
2278 /* check page 1, reg 0x60 */
2279 val = snd_ac97_read(ac97, AC97_INT_PAGING);
2280 snd_ac97_write_cache(ac97, AC97_INT_PAGING, (val & ~0x0f) | 0x01);
2281 tmp = snd_ac97_read(ac97, 0x60);
2282 ac97->spec.dev_flags = tmp & 1; /* revision B? */
2283 snd_ac97_write_cache(ac97, AC97_INT_PAGING, val);
2286 ac97->build_ops = &patch_cm9761_ops;
2289 /* force the SPDIF bit in ext_id - codec doesn't set this bit! */
2290 ac97->ext_id |= AC97_EI_SPDIF;
2291 /* to be sure: we overwrite the ext status bits */
2292 snd_ac97_write_cache(ac97, AC97_EXTENDED_STATUS, 0x05c0);
2293 /* Don't set 0x0200 here. This results in the silent analog output */
2294 snd_ac97_write_cache(ac97, AC97_CM9761_SPDIF_CTRL, 0x0001); /* enable spdif-in */
2295 ac97->rates[AC97_RATES_SPDIF] = SNDRV_PCM_RATE_48000; /* 48k only */
2297 /* set-up multi channel */
2298 /* bit 15: pc master beep off
2299 * bit 14: pin47 = EAPD/SPDIF
2300 * bit 13: vref ctl [= cm9739]
2301 * bit 12: CLFE control (reverted on rev B)
2302 * bit 11: Mic/center share (reverted on rev B)
2303 * bit 10: suddound/line share
2304 * bit 9: Analog-in mix -> surround
2305 * bit 8: Analog-in mix -> CLFE
2306 * bit 7: Mic/LFE share (mic/center/lfe)
2307 * bit 5: vref select (9761A)
2308 * bit 4: front control
2309 * bit 3: surround control (revereted with rev B)
2312 * bit 0: mic boost level (0=20dB, 1=30dB)
2316 if (ac97->spec.dev_flags)
2321 val = snd_ac97_read(ac97, AC97_CM9761_MULTI_CHAN);
2322 val |= (1 << 4); /* front on */
2323 snd_ac97_write_cache(ac97, AC97_CM9761_MULTI_CHAN, val);
2325 /* FIXME: set up GPIO */
2326 snd_ac97_write_cache(ac97, 0x70, 0x0100);
2327 snd_ac97_write_cache(ac97, 0x72, 0x0020);
2332 #define AC97_CM9780_SIDE 0x60
2333 #define AC97_CM9780_JACK 0x62
2334 #define AC97_CM9780_MIXER 0x64
2335 #define AC97_CM9780_MULTI_CHAN 0x66
2336 #define AC97_CM9780_SPDIF 0x6c
2338 static const char *cm9780_ch_select[] = { "Front", "Side", "Center/LFE", "Rear" };
2339 static const struct ac97_enum cm9780_ch_select_enum =
2340 AC97_ENUM_SINGLE(AC97_CM9780_MULTI_CHAN, 6, 4, cm9780_ch_select);
2341 static const snd_kcontrol_new_t cm9780_controls[] = {
2342 AC97_DOUBLE("Side Playback Switch", AC97_CM9780_SIDE, 15, 7, 1, 1),
2343 AC97_DOUBLE("Side Playback Volume", AC97_CM9780_SIDE, 8, 0, 31, 0),
2344 AC97_ENUM("Side Playback Route", cm9780_ch_select_enum),
2347 static int patch_cm9780_specific(ac97_t *ac97)
2349 return patch_build_controls(ac97, cm9780_controls, ARRAY_SIZE(cm9780_controls));
2352 static struct snd_ac97_build_ops patch_cm9780_ops = {
2353 .build_specific = patch_cm9780_specific,
2354 .build_post_spdif = patch_cm9761_post_spdif /* identical with CM9761 */
2357 int patch_cm9780(ac97_t *ac97)
2361 ac97->build_ops = &patch_cm9780_ops;
2364 if (ac97->ext_id & AC97_EI_SPDIF) {
2365 ac97->rates[AC97_RATES_SPDIF] = SNDRV_PCM_RATE_48000; /* 48k only */
2366 val = snd_ac97_read(ac97, AC97_CM9780_SPDIF);
2367 val |= 0x1; /* SPDI_EN */
2368 snd_ac97_write_cache(ac97, AC97_CM9780_SPDIF, val);
2377 static const snd_kcontrol_new_t snd_ac97_controls_vt1616[] = {
2378 AC97_SINGLE("DC Offset removal", 0x5a, 10, 1, 0),
2379 AC97_SINGLE("Alternate Level to Surround Out", 0x5a, 15, 1, 0),
2380 AC97_SINGLE("Downmix LFE and Center to Front", 0x5a, 12, 1, 0),
2381 AC97_SINGLE("Downmix Surround to Front", 0x5a, 11, 1, 0),
2384 static int patch_vt1616_specific(ac97_t * ac97)
2388 if (snd_ac97_try_bit(ac97, 0x5a, 9))
2389 if ((err = patch_build_controls(ac97, &snd_ac97_controls_vt1616[0], 1)) < 0)
2391 if ((err = patch_build_controls(ac97, &snd_ac97_controls_vt1616[1], ARRAY_SIZE(snd_ac97_controls_vt1616) - 1)) < 0)
2396 static struct snd_ac97_build_ops patch_vt1616_ops = {
2397 .build_specific = patch_vt1616_specific
2400 int patch_vt1616(ac97_t * ac97)
2402 ac97->build_ops = &patch_vt1616_ops;
2408 static void it2646_update_jacks(ac97_t *ac97)
2410 /* shared Line-In */
2411 snd_ac97_update_bits(ac97, 0x76, 1 << 9,
2412 is_shared_linein(ac97) ? (1<<9) : 0);
2414 snd_ac97_update_bits(ac97, 0x76, 1 << 10,
2415 is_shared_micin(ac97) ? (1<<10) : 0);
2418 static const snd_kcontrol_new_t snd_ac97_controls_it2646[] = {
2419 AC97_SURROUND_JACK_MODE_CTL,
2420 AC97_CHANNEL_MODE_CTL,
2423 static const snd_kcontrol_new_t snd_ac97_spdif_controls_it2646[] = {
2424 AC97_SINGLE("IEC958 Capture Switch", 0x76, 11, 1, 0),
2425 AC97_SINGLE("Analog to IEC958 Output", 0x76, 12, 1, 0),
2426 AC97_SINGLE("IEC958 Input Monitor", 0x76, 13, 1, 0),
2429 static int patch_it2646_specific(ac97_t * ac97)
2432 if ((err = patch_build_controls(ac97, snd_ac97_controls_it2646, ARRAY_SIZE(snd_ac97_controls_it2646))) < 0)
2434 if ((err = patch_build_controls(ac97, snd_ac97_spdif_controls_it2646, ARRAY_SIZE(snd_ac97_spdif_controls_it2646))) < 0)
2439 static struct snd_ac97_build_ops patch_it2646_ops = {
2440 .build_specific = patch_it2646_specific,
2441 .update_jacks = it2646_update_jacks
2444 int patch_it2646(ac97_t * ac97)
2446 ac97->build_ops = &patch_it2646_ops;
2447 /* full DAC volume */
2448 snd_ac97_write_cache(ac97, 0x5E, 0x0808);
2449 snd_ac97_write_cache(ac97, 0x7A, 0x0808);
2453 /* Si3036/8 specific registers */
2454 #define AC97_SI3036_CHIP_ID 0x5a
2456 int mpatch_si3036(ac97_t * ac97)
2458 //printk("mpatch_si3036: chip id = %x\n", snd_ac97_read(ac97, 0x5a));
2459 snd_ac97_write_cache(ac97, 0x5c, 0xf210 );
2460 snd_ac97_write_cache(ac97, 0x68, 0);