mm: bug in set_page_dirty_buffers
[linux/fpc-iii.git] / sound / pci / ac97 / ac97_patch.c
blob094cfc1f3a190157b7bd7c0e3436cf00a9dcf858
1 /*
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
7 * for specific codecs.
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 <linux/mutex.h>
32 #include <sound/core.h>
33 #include <sound/pcm.h>
34 #include <sound/control.h>
35 #include <sound/ac97_codec.h>
36 #include "ac97_patch.h"
37 #include "ac97_id.h"
38 #include "ac97_local.h"
41 * Chip specific initialization
44 static int patch_build_controls(struct snd_ac97 * ac97, const struct snd_kcontrol_new *controls, int count)
46 int idx, err;
48 for (idx = 0; idx < count; idx++)
49 if ((err = snd_ctl_add(ac97->bus->card, snd_ac97_cnew(&controls[idx], ac97))) < 0)
50 return err;
51 return 0;
54 /* set to the page, update bits and restore the page */
55 static int ac97_update_bits_page(struct snd_ac97 *ac97, unsigned short reg, unsigned short mask, unsigned short value, unsigned short page)
57 unsigned short page_save;
58 int ret;
60 mutex_lock(&ac97->page_mutex);
61 page_save = snd_ac97_read(ac97, AC97_INT_PAGING) & AC97_PAGE_MASK;
62 snd_ac97_update_bits(ac97, AC97_INT_PAGING, AC97_PAGE_MASK, page);
63 ret = snd_ac97_update_bits(ac97, reg, mask, value);
64 snd_ac97_update_bits(ac97, AC97_INT_PAGING, AC97_PAGE_MASK, page_save);
65 mutex_unlock(&ac97->page_mutex); /* unlock paging */
66 return ret;
70 * shared line-in/mic controls
72 static int ac97_enum_text_info(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_info *uinfo,
73 const char **texts, unsigned int nums)
75 uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED;
76 uinfo->count = 1;
77 uinfo->value.enumerated.items = nums;
78 if (uinfo->value.enumerated.item > nums - 1)
79 uinfo->value.enumerated.item = nums - 1;
80 strcpy(uinfo->value.enumerated.name, texts[uinfo->value.enumerated.item]);
81 return 0;
84 static int ac97_surround_jack_mode_info(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_info *uinfo)
86 static const char *texts[] = { "Shared", "Independent" };
87 return ac97_enum_text_info(kcontrol, uinfo, texts, 2);
90 static int ac97_surround_jack_mode_get(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
92 struct snd_ac97 *ac97 = snd_kcontrol_chip(kcontrol);
94 ucontrol->value.enumerated.item[0] = ac97->indep_surround;
95 return 0;
98 static int ac97_surround_jack_mode_put(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
100 struct snd_ac97 *ac97 = snd_kcontrol_chip(kcontrol);
101 unsigned char indep = !!ucontrol->value.enumerated.item[0];
103 if (indep != ac97->indep_surround) {
104 ac97->indep_surround = indep;
105 if (ac97->build_ops->update_jacks)
106 ac97->build_ops->update_jacks(ac97);
107 return 1;
109 return 0;
112 static int ac97_channel_mode_info(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_info *uinfo)
114 static const char *texts[] = { "2ch", "4ch", "6ch" };
115 if (kcontrol->private_value)
116 return ac97_enum_text_info(kcontrol, uinfo, texts, 2); /* 4ch only */
117 return ac97_enum_text_info(kcontrol, uinfo, texts, 3);
120 static int ac97_channel_mode_get(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
122 struct snd_ac97 *ac97 = snd_kcontrol_chip(kcontrol);
124 ucontrol->value.enumerated.item[0] = ac97->channel_mode;
125 return 0;
128 static int ac97_channel_mode_put(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
130 struct snd_ac97 *ac97 = snd_kcontrol_chip(kcontrol);
131 unsigned char mode = ucontrol->value.enumerated.item[0];
133 if (mode != ac97->channel_mode) {
134 ac97->channel_mode = mode;
135 if (ac97->build_ops->update_jacks)
136 ac97->build_ops->update_jacks(ac97);
137 return 1;
139 return 0;
142 #define AC97_SURROUND_JACK_MODE_CTL \
144 .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \
145 .name = "Surround Jack Mode", \
146 .info = ac97_surround_jack_mode_info, \
147 .get = ac97_surround_jack_mode_get, \
148 .put = ac97_surround_jack_mode_put, \
150 #define AC97_CHANNEL_MODE_CTL \
152 .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \
153 .name = "Channel Mode", \
154 .info = ac97_channel_mode_info, \
155 .get = ac97_channel_mode_get, \
156 .put = ac97_channel_mode_put, \
158 #define AC97_CHANNEL_MODE_4CH_CTL \
160 .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \
161 .name = "Channel Mode", \
162 .info = ac97_channel_mode_info, \
163 .get = ac97_channel_mode_get, \
164 .put = ac97_channel_mode_put, \
165 .private_value = 1, \
168 static inline int is_surround_on(struct snd_ac97 *ac97)
170 return ac97->channel_mode >= 1;
173 static inline int is_clfe_on(struct snd_ac97 *ac97)
175 return ac97->channel_mode >= 2;
178 static inline int is_shared_linein(struct snd_ac97 *ac97)
180 return ! ac97->indep_surround && is_surround_on(ac97);
183 static inline int is_shared_micin(struct snd_ac97 *ac97)
185 return ! ac97->indep_surround && is_clfe_on(ac97);
189 /* The following snd_ac97_ymf753_... items added by David Shust (dshust@shustring.com) */
191 /* It is possible to indicate to the Yamaha YMF753 the type of speakers being used. */
192 static int snd_ac97_ymf753_info_speaker(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_info *uinfo)
194 static char *texts[3] = {
195 "Standard", "Small", "Smaller"
198 uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED;
199 uinfo->count = 1;
200 uinfo->value.enumerated.items = 3;
201 if (uinfo->value.enumerated.item > 2)
202 uinfo->value.enumerated.item = 2;
203 strcpy(uinfo->value.enumerated.name, texts[uinfo->value.enumerated.item]);
204 return 0;
207 static int snd_ac97_ymf753_get_speaker(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
209 struct snd_ac97 *ac97 = snd_kcontrol_chip(kcontrol);
210 unsigned short val;
212 val = ac97->regs[AC97_YMF753_3D_MODE_SEL];
213 val = (val >> 10) & 3;
214 if (val > 0) /* 0 = invalid */
215 val--;
216 ucontrol->value.enumerated.item[0] = val;
217 return 0;
220 static int snd_ac97_ymf753_put_speaker(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
222 struct snd_ac97 *ac97 = snd_kcontrol_chip(kcontrol);
223 unsigned short val;
225 if (ucontrol->value.enumerated.item[0] > 2)
226 return -EINVAL;
227 val = (ucontrol->value.enumerated.item[0] + 1) << 10;
228 return snd_ac97_update(ac97, AC97_YMF753_3D_MODE_SEL, val);
231 static const struct snd_kcontrol_new snd_ac97_ymf753_controls_speaker =
233 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
234 .name = "3D Control - Speaker",
235 .info = snd_ac97_ymf753_info_speaker,
236 .get = snd_ac97_ymf753_get_speaker,
237 .put = snd_ac97_ymf753_put_speaker,
240 /* It is possible to indicate to the Yamaha YMF753 the source to direct to the S/PDIF output. */
241 static int snd_ac97_ymf753_spdif_source_info(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_info *uinfo)
243 static char *texts[2] = { "AC-Link", "A/D Converter" };
245 uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED;
246 uinfo->count = 1;
247 uinfo->value.enumerated.items = 2;
248 if (uinfo->value.enumerated.item > 1)
249 uinfo->value.enumerated.item = 1;
250 strcpy(uinfo->value.enumerated.name, texts[uinfo->value.enumerated.item]);
251 return 0;
254 static int snd_ac97_ymf753_spdif_source_get(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
256 struct snd_ac97 *ac97 = snd_kcontrol_chip(kcontrol);
257 unsigned short val;
259 val = ac97->regs[AC97_YMF753_DIT_CTRL2];
260 ucontrol->value.enumerated.item[0] = (val >> 1) & 1;
261 return 0;
264 static int snd_ac97_ymf753_spdif_source_put(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
266 struct snd_ac97 *ac97 = snd_kcontrol_chip(kcontrol);
267 unsigned short val;
269 if (ucontrol->value.enumerated.item[0] > 1)
270 return -EINVAL;
271 val = ucontrol->value.enumerated.item[0] << 1;
272 return snd_ac97_update_bits(ac97, AC97_YMF753_DIT_CTRL2, 0x0002, val);
275 /* The AC'97 spec states that the S/PDIF signal is to be output at pin 48.
276 The YMF753 will output the S/PDIF signal to pin 43, 47 (EAPD), or 48.
277 By default, no output pin is selected, and the S/PDIF signal is not output.
278 There is also a bit to mute S/PDIF output in a vendor-specific register. */
279 static int snd_ac97_ymf753_spdif_output_pin_info(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_info *uinfo)
281 static char *texts[3] = { "Disabled", "Pin 43", "Pin 48" };
283 uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED;
284 uinfo->count = 1;
285 uinfo->value.enumerated.items = 3;
286 if (uinfo->value.enumerated.item > 2)
287 uinfo->value.enumerated.item = 2;
288 strcpy(uinfo->value.enumerated.name, texts[uinfo->value.enumerated.item]);
289 return 0;
292 static int snd_ac97_ymf753_spdif_output_pin_get(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
294 struct snd_ac97 *ac97 = snd_kcontrol_chip(kcontrol);
295 unsigned short val;
297 val = ac97->regs[AC97_YMF753_DIT_CTRL2];
298 ucontrol->value.enumerated.item[0] = (val & 0x0008) ? 2 : (val & 0x0020) ? 1 : 0;
299 return 0;
302 static int snd_ac97_ymf753_spdif_output_pin_put(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
304 struct snd_ac97 *ac97 = snd_kcontrol_chip(kcontrol);
305 unsigned short val;
307 if (ucontrol->value.enumerated.item[0] > 2)
308 return -EINVAL;
309 val = (ucontrol->value.enumerated.item[0] == 2) ? 0x0008 :
310 (ucontrol->value.enumerated.item[0] == 1) ? 0x0020 : 0;
311 return snd_ac97_update_bits(ac97, AC97_YMF753_DIT_CTRL2, 0x0028, val);
312 /* The following can be used to direct S/PDIF output to pin 47 (EAPD).
313 snd_ac97_write_cache(ac97, 0x62, snd_ac97_read(ac97, 0x62) | 0x0008); */
316 static const struct snd_kcontrol_new snd_ac97_ymf753_controls_spdif[3] = {
318 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
319 .name = SNDRV_CTL_NAME_IEC958("",PLAYBACK,NONE) "Source",
320 .info = snd_ac97_ymf753_spdif_source_info,
321 .get = snd_ac97_ymf753_spdif_source_get,
322 .put = snd_ac97_ymf753_spdif_source_put,
325 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
326 .name = SNDRV_CTL_NAME_IEC958("",PLAYBACK,NONE) "Output Pin",
327 .info = snd_ac97_ymf753_spdif_output_pin_info,
328 .get = snd_ac97_ymf753_spdif_output_pin_get,
329 .put = snd_ac97_ymf753_spdif_output_pin_put,
331 AC97_SINGLE(SNDRV_CTL_NAME_IEC958("",NONE,NONE) "Mute", AC97_YMF753_DIT_CTRL2, 2, 1, 1)
334 static int patch_yamaha_ymf753_3d(struct snd_ac97 * ac97)
336 struct snd_kcontrol *kctl;
337 int err;
339 if ((err = snd_ctl_add(ac97->bus->card, kctl = snd_ac97_cnew(&snd_ac97_controls_3d[0], ac97))) < 0)
340 return err;
341 strcpy(kctl->id.name, "3D Control - Wide");
342 kctl->private_value = AC97_SINGLE_VALUE(AC97_3D_CONTROL, 9, 7, 0);
343 snd_ac97_write_cache(ac97, AC97_3D_CONTROL, 0x0000);
344 if ((err = snd_ctl_add(ac97->bus->card, snd_ac97_cnew(&snd_ac97_ymf753_controls_speaker, ac97))) < 0)
345 return err;
346 snd_ac97_write_cache(ac97, AC97_YMF753_3D_MODE_SEL, 0x0c00);
347 return 0;
350 static int patch_yamaha_ymf753_post_spdif(struct snd_ac97 * ac97)
352 int err;
354 if ((err = patch_build_controls(ac97, snd_ac97_ymf753_controls_spdif, ARRAY_SIZE(snd_ac97_ymf753_controls_spdif))) < 0)
355 return err;
356 return 0;
359 static struct snd_ac97_build_ops patch_yamaha_ymf753_ops = {
360 .build_3d = patch_yamaha_ymf753_3d,
361 .build_post_spdif = patch_yamaha_ymf753_post_spdif
364 int patch_yamaha_ymf753(struct snd_ac97 * ac97)
366 /* Patch for Yamaha YMF753, Copyright (c) by David Shust, dshust@shustring.com.
367 This chip has nonstandard and extended behaviour with regard to its S/PDIF output.
368 The AC'97 spec states that the S/PDIF signal is to be output at pin 48.
369 The YMF753 will ouput the S/PDIF signal to pin 43, 47 (EAPD), or 48.
370 By default, no output pin is selected, and the S/PDIF signal is not output.
371 There is also a bit to mute S/PDIF output in a vendor-specific register.
373 ac97->build_ops = &patch_yamaha_ymf753_ops;
374 ac97->caps |= AC97_BC_BASS_TREBLE;
375 ac97->caps |= 0x04 << 10; /* Yamaha 3D enhancement */
376 return 0;
380 * May 2, 2003 Liam Girdwood <liam.girdwood@wolfsonmicro.com>
381 * removed broken wolfson00 patch.
382 * added support for WM9705,WM9708,WM9709,WM9710,WM9711,WM9712 and WM9717.
385 static const struct snd_kcontrol_new wm97xx_snd_ac97_controls[] = {
386 AC97_DOUBLE("Front Playback Volume", AC97_WM97XX_FMIXER_VOL, 8, 0, 31, 1),
387 AC97_SINGLE("Front Playback Switch", AC97_WM97XX_FMIXER_VOL, 15, 1, 1),
390 static int patch_wolfson_wm9703_specific(struct snd_ac97 * ac97)
392 /* This is known to work for the ViewSonic ViewPad 1000
393 * Randolph Bentson <bentson@holmsjoen.com>
394 * WM9703/9707/9708/9717
396 int err, i;
398 for (i = 0; i < ARRAY_SIZE(wm97xx_snd_ac97_controls); i++) {
399 if ((err = snd_ctl_add(ac97->bus->card, snd_ac97_cnew(&wm97xx_snd_ac97_controls[i], ac97))) < 0)
400 return err;
402 snd_ac97_write_cache(ac97, AC97_WM97XX_FMIXER_VOL, 0x0808);
403 return 0;
406 static struct snd_ac97_build_ops patch_wolfson_wm9703_ops = {
407 .build_specific = patch_wolfson_wm9703_specific,
410 int patch_wolfson03(struct snd_ac97 * ac97)
412 ac97->build_ops = &patch_wolfson_wm9703_ops;
413 return 0;
416 static const struct snd_kcontrol_new wm9704_snd_ac97_controls[] = {
417 AC97_DOUBLE("Front Playback Volume", AC97_WM97XX_FMIXER_VOL, 8, 0, 31, 1),
418 AC97_SINGLE("Front Playback Switch", AC97_WM97XX_FMIXER_VOL, 15, 1, 1),
419 AC97_DOUBLE("Rear Playback Volume", AC97_WM9704_RMIXER_VOL, 8, 0, 31, 1),
420 AC97_SINGLE("Rear Playback Switch", AC97_WM9704_RMIXER_VOL, 15, 1, 1),
421 AC97_DOUBLE("Rear DAC Volume", AC97_WM9704_RPCM_VOL, 8, 0, 31, 1),
422 AC97_DOUBLE("Surround Volume", AC97_SURROUND_MASTER, 8, 0, 31, 1),
425 static int patch_wolfson_wm9704_specific(struct snd_ac97 * ac97)
427 int err, i;
428 for (i = 0; i < ARRAY_SIZE(wm9704_snd_ac97_controls); i++) {
429 if ((err = snd_ctl_add(ac97->bus->card, snd_ac97_cnew(&wm9704_snd_ac97_controls[i], ac97))) < 0)
430 return err;
432 /* patch for DVD noise */
433 snd_ac97_write_cache(ac97, AC97_WM9704_TEST, 0x0200);
434 return 0;
437 static struct snd_ac97_build_ops patch_wolfson_wm9704_ops = {
438 .build_specific = patch_wolfson_wm9704_specific,
441 int patch_wolfson04(struct snd_ac97 * ac97)
443 /* WM9704M/9704Q */
444 ac97->build_ops = &patch_wolfson_wm9704_ops;
445 return 0;
448 static int patch_wolfson_wm9705_specific(struct snd_ac97 * ac97)
450 int err, i;
451 for (i = 0; i < ARRAY_SIZE(wm97xx_snd_ac97_controls); i++) {
452 if ((err = snd_ctl_add(ac97->bus->card, snd_ac97_cnew(&wm97xx_snd_ac97_controls[i], ac97))) < 0)
453 return err;
455 snd_ac97_write_cache(ac97, 0x72, 0x0808);
456 return 0;
459 static struct snd_ac97_build_ops patch_wolfson_wm9705_ops = {
460 .build_specific = patch_wolfson_wm9705_specific,
463 int patch_wolfson05(struct snd_ac97 * ac97)
465 /* WM9705, WM9710 */
466 ac97->build_ops = &patch_wolfson_wm9705_ops;
467 #ifdef CONFIG_TOUCHSCREEN_WM9705
468 /* WM9705 touchscreen uses AUX and VIDEO for touch */
469 ac97->flags |=3D AC97_HAS_NO_VIDEO | AC97_HAS_NO_AUX;
470 #endif
471 return 0;
474 static const char* wm9711_alc_select[] = {"None", "Left", "Right", "Stereo"};
475 static const char* wm9711_alc_mix[] = {"Stereo", "Right", "Left", "None"};
476 static const char* wm9711_out3_src[] = {"Left", "VREF", "Left + Right", "Mono"};
477 static const char* wm9711_out3_lrsrc[] = {"Master Mix", "Headphone Mix"};
478 static const char* wm9711_rec_adc[] = {"Stereo", "Left", "Right", "Mute"};
479 static const char* wm9711_base[] = {"Linear Control", "Adaptive Boost"};
480 static const char* wm9711_rec_gain[] = {"+1.5dB Steps", "+0.75dB Steps"};
481 static const char* wm9711_mic[] = {"Mic 1", "Differential", "Mic 2", "Stereo"};
482 static const char* wm9711_rec_sel[] =
483 {"Mic 1", "NC", "NC", "Master Mix", "Line", "Headphone Mix", "Phone Mix", "Phone"};
484 static const char* wm9711_ng_type[] = {"Constant Gain", "Mute"};
486 static const struct ac97_enum wm9711_enum[] = {
487 AC97_ENUM_SINGLE(AC97_PCI_SVID, 14, 4, wm9711_alc_select),
488 AC97_ENUM_SINGLE(AC97_VIDEO, 10, 4, wm9711_alc_mix),
489 AC97_ENUM_SINGLE(AC97_AUX, 9, 4, wm9711_out3_src),
490 AC97_ENUM_SINGLE(AC97_AUX, 8, 2, wm9711_out3_lrsrc),
491 AC97_ENUM_SINGLE(AC97_REC_SEL, 12, 4, wm9711_rec_adc),
492 AC97_ENUM_SINGLE(AC97_MASTER_TONE, 15, 2, wm9711_base),
493 AC97_ENUM_DOUBLE(AC97_REC_GAIN, 14, 6, 2, wm9711_rec_gain),
494 AC97_ENUM_SINGLE(AC97_MIC, 5, 4, wm9711_mic),
495 AC97_ENUM_DOUBLE(AC97_REC_SEL, 8, 0, 8, wm9711_rec_sel),
496 AC97_ENUM_SINGLE(AC97_PCI_SVID, 5, 2, wm9711_ng_type),
499 static const struct snd_kcontrol_new wm9711_snd_ac97_controls[] = {
500 AC97_SINGLE("ALC Target Volume", AC97_CODEC_CLASS_REV, 12, 15, 0),
501 AC97_SINGLE("ALC Hold Time", AC97_CODEC_CLASS_REV, 8, 15, 0),
502 AC97_SINGLE("ALC Decay Time", AC97_CODEC_CLASS_REV, 4, 15, 0),
503 AC97_SINGLE("ALC Attack Time", AC97_CODEC_CLASS_REV, 0, 15, 0),
504 AC97_ENUM("ALC Function", wm9711_enum[0]),
505 AC97_SINGLE("ALC Max Volume", AC97_PCI_SVID, 11, 7, 1),
506 AC97_SINGLE("ALC ZC Timeout", AC97_PCI_SVID, 9, 3, 1),
507 AC97_SINGLE("ALC ZC Switch", AC97_PCI_SVID, 8, 1, 0),
508 AC97_SINGLE("ALC NG Switch", AC97_PCI_SVID, 7, 1, 0),
509 AC97_ENUM("ALC NG Type", wm9711_enum[9]),
510 AC97_SINGLE("ALC NG Threshold", AC97_PCI_SVID, 0, 31, 1),
512 AC97_SINGLE("Side Tone Switch", AC97_VIDEO, 15, 1, 1),
513 AC97_SINGLE("Side Tone Volume", AC97_VIDEO, 12, 7, 1),
514 AC97_ENUM("ALC Headphone Mux", wm9711_enum[1]),
515 AC97_SINGLE("ALC Headphone Volume", AC97_VIDEO, 7, 7, 1),
517 AC97_SINGLE("Out3 Switch", AC97_AUX, 15, 1, 1),
518 AC97_SINGLE("Out3 ZC Switch", AC97_AUX, 7, 1, 1),
519 AC97_ENUM("Out3 Mux", wm9711_enum[2]),
520 AC97_ENUM("Out3 LR Mux", wm9711_enum[3]),
521 AC97_SINGLE("Out3 Volume", AC97_AUX, 0, 31, 1),
523 AC97_SINGLE("Beep to Headphone Switch", AC97_PC_BEEP, 15, 1, 1),
524 AC97_SINGLE("Beep to Headphone Volume", AC97_PC_BEEP, 12, 7, 1),
525 AC97_SINGLE("Beep to Side Tone Switch", AC97_PC_BEEP, 11, 1, 1),
526 AC97_SINGLE("Beep to Side Tone Volume", AC97_PC_BEEP, 8, 7, 1),
527 AC97_SINGLE("Beep to Phone Switch", AC97_PC_BEEP, 7, 1, 1),
528 AC97_SINGLE("Beep to Phone Volume", AC97_PC_BEEP, 4, 7, 1),
530 AC97_SINGLE("Aux to Headphone Switch", AC97_CD, 15, 1, 1),
531 AC97_SINGLE("Aux to Headphone Volume", AC97_CD, 12, 7, 1),
532 AC97_SINGLE("Aux to Side Tone Switch", AC97_CD, 11, 1, 1),
533 AC97_SINGLE("Aux to Side Tone Volume", AC97_CD, 8, 7, 1),
534 AC97_SINGLE("Aux to Phone Switch", AC97_CD, 7, 1, 1),
535 AC97_SINGLE("Aux to Phone Volume", AC97_CD, 4, 7, 1),
537 AC97_SINGLE("Phone to Headphone Switch", AC97_PHONE, 15, 1, 1),
538 AC97_SINGLE("Phone to Master Switch", AC97_PHONE, 14, 1, 1),
540 AC97_SINGLE("Line to Headphone Switch", AC97_LINE, 15, 1, 1),
541 AC97_SINGLE("Line to Master Switch", AC97_LINE, 14, 1, 1),
542 AC97_SINGLE("Line to Phone Switch", AC97_LINE, 13, 1, 1),
544 AC97_SINGLE("PCM Playback to Headphone Switch", AC97_PCM, 15, 1, 1),
545 AC97_SINGLE("PCM Playback to Master Switch", AC97_PCM, 14, 1, 1),
546 AC97_SINGLE("PCM Playback to Phone Switch", AC97_PCM, 13, 1, 1),
548 AC97_SINGLE("Capture 20dB Boost Switch", AC97_REC_SEL, 14, 1, 0),
549 AC97_ENUM("Capture to Phone Mux", wm9711_enum[4]),
550 AC97_SINGLE("Capture to Phone 20dB Boost Switch", AC97_REC_SEL, 11, 1, 1),
551 AC97_ENUM("Capture Select", wm9711_enum[8]),
553 AC97_SINGLE("3D Upper Cut-off Switch", AC97_3D_CONTROL, 5, 1, 1),
554 AC97_SINGLE("3D Lower Cut-off Switch", AC97_3D_CONTROL, 4, 1, 1),
556 AC97_ENUM("Bass Control", wm9711_enum[5]),
557 AC97_SINGLE("Bass Cut-off Switch", AC97_MASTER_TONE, 12, 1, 1),
558 AC97_SINGLE("Tone Cut-off Switch", AC97_MASTER_TONE, 4, 1, 1),
559 AC97_SINGLE("Playback Attenuate (-6dB) Switch", AC97_MASTER_TONE, 6, 1, 0),
561 AC97_SINGLE("ADC Switch", AC97_REC_GAIN, 15, 1, 1),
562 AC97_ENUM("Capture Volume Steps", wm9711_enum[6]),
563 AC97_DOUBLE("Capture Volume", AC97_REC_GAIN, 8, 0, 15, 1),
564 AC97_SINGLE("Capture ZC Switch", AC97_REC_GAIN, 7, 1, 0),
566 AC97_SINGLE("Mic 1 to Phone Switch", AC97_MIC, 14, 1, 1),
567 AC97_SINGLE("Mic 2 to Phone Switch", AC97_MIC, 13, 1, 1),
568 AC97_ENUM("Mic Select Source", wm9711_enum[7]),
569 AC97_SINGLE("Mic 1 Volume", AC97_MIC, 8, 32, 1),
570 AC97_SINGLE("Mic 20dB Boost Switch", AC97_MIC, 7, 1, 0),
572 AC97_SINGLE("Master ZC Switch", AC97_MASTER, 7, 1, 0),
573 AC97_SINGLE("Headphone ZC Switch", AC97_HEADPHONE, 7, 1, 0),
574 AC97_SINGLE("Mono ZC Switch", AC97_MASTER_MONO, 7, 1, 0),
577 static int patch_wolfson_wm9711_specific(struct snd_ac97 * ac97)
579 int err, i;
581 for (i = 0; i < ARRAY_SIZE(wm9711_snd_ac97_controls); i++) {
582 if ((err = snd_ctl_add(ac97->bus->card, snd_ac97_cnew(&wm9711_snd_ac97_controls[i], ac97))) < 0)
583 return err;
585 snd_ac97_write_cache(ac97, AC97_CODEC_CLASS_REV, 0x0808);
586 snd_ac97_write_cache(ac97, AC97_PCI_SVID, 0x0808);
587 snd_ac97_write_cache(ac97, AC97_VIDEO, 0x0808);
588 snd_ac97_write_cache(ac97, AC97_AUX, 0x0808);
589 snd_ac97_write_cache(ac97, AC97_PC_BEEP, 0x0808);
590 snd_ac97_write_cache(ac97, AC97_CD, 0x0000);
591 return 0;
594 static struct snd_ac97_build_ops patch_wolfson_wm9711_ops = {
595 .build_specific = patch_wolfson_wm9711_specific,
598 int patch_wolfson11(struct snd_ac97 * ac97)
600 /* WM9711, WM9712 */
601 ac97->build_ops = &patch_wolfson_wm9711_ops;
603 ac97->flags |= AC97_HAS_NO_REC_GAIN | AC97_STEREO_MUTES | AC97_HAS_NO_MIC |
604 AC97_HAS_NO_PC_BEEP | AC97_HAS_NO_VIDEO | AC97_HAS_NO_CD;
606 return 0;
609 static const char* wm9713_mic_mixer[] = {"Stereo", "Mic 1", "Mic 2", "Mute"};
610 static const char* wm9713_rec_mux[] = {"Stereo", "Left", "Right", "Mute"};
611 static const char* wm9713_rec_src[] =
612 {"Mic 1", "Mic 2", "Line", "Mono In", "Headphone Mix", "Master Mix",
613 "Mono Mix", "Zh"};
614 static const char* wm9713_rec_gain[] = {"+1.5dB Steps", "+0.75dB Steps"};
615 static const char* wm9713_alc_select[] = {"None", "Left", "Right", "Stereo"};
616 static const char* wm9713_mono_pga[] = {"Vmid", "Zh", "Mono Mix", "Inv 1"};
617 static const char* wm9713_spk_pga[] =
618 {"Vmid", "Zh", "Headphone Mix", "Master Mix", "Inv", "NC", "NC", "NC"};
619 static const char* wm9713_hp_pga[] = {"Vmid", "Zh", "Headphone Mix", "NC"};
620 static const char* wm9713_out3_pga[] = {"Vmid", "Zh", "Inv 1", "NC"};
621 static const char* wm9713_out4_pga[] = {"Vmid", "Zh", "Inv 2", "NC"};
622 static const char* wm9713_dac_inv[] =
623 {"Off", "Mono Mix", "Master Mix", "Headphone Mix L", "Headphone Mix R",
624 "Headphone Mix Mono", "NC", "Vmid"};
625 static const char* wm9713_base[] = {"Linear Control", "Adaptive Boost"};
626 static const char* wm9713_ng_type[] = {"Constant Gain", "Mute"};
628 static const struct ac97_enum wm9713_enum[] = {
629 AC97_ENUM_SINGLE(AC97_LINE, 3, 4, wm9713_mic_mixer),
630 AC97_ENUM_SINGLE(AC97_VIDEO, 14, 4, wm9713_rec_mux),
631 AC97_ENUM_SINGLE(AC97_VIDEO, 9, 4, wm9713_rec_mux),
632 AC97_ENUM_DOUBLE(AC97_VIDEO, 3, 0, 8, wm9713_rec_src),
633 AC97_ENUM_DOUBLE(AC97_CD, 14, 6, 2, wm9713_rec_gain),
634 AC97_ENUM_SINGLE(AC97_PCI_SVID, 14, 4, wm9713_alc_select),
635 AC97_ENUM_SINGLE(AC97_REC_GAIN, 14, 4, wm9713_mono_pga),
636 AC97_ENUM_DOUBLE(AC97_REC_GAIN, 11, 8, 8, wm9713_spk_pga),
637 AC97_ENUM_DOUBLE(AC97_REC_GAIN, 6, 4, 4, wm9713_hp_pga),
638 AC97_ENUM_SINGLE(AC97_REC_GAIN, 2, 4, wm9713_out3_pga),
639 AC97_ENUM_SINGLE(AC97_REC_GAIN, 0, 4, wm9713_out4_pga),
640 AC97_ENUM_DOUBLE(AC97_REC_GAIN_MIC, 13, 10, 8, wm9713_dac_inv),
641 AC97_ENUM_SINGLE(AC97_GENERAL_PURPOSE, 15, 2, wm9713_base),
642 AC97_ENUM_SINGLE(AC97_PCI_SVID, 5, 2, wm9713_ng_type),
645 static const struct snd_kcontrol_new wm13_snd_ac97_controls[] = {
646 AC97_DOUBLE("Line In Volume", AC97_PC_BEEP, 8, 0, 31, 1),
647 AC97_SINGLE("Line In to Headphone Switch", AC97_PC_BEEP, 15, 1, 1),
648 AC97_SINGLE("Line In to Master Switch", AC97_PC_BEEP, 14, 1, 1),
649 AC97_SINGLE("Line In to Mono Switch", AC97_PC_BEEP, 13, 1, 1),
651 AC97_DOUBLE("PCM Playback Volume", AC97_PHONE, 8, 0, 31, 1),
652 AC97_SINGLE("PCM Playback to Headphone Switch", AC97_PHONE, 15, 1, 1),
653 AC97_SINGLE("PCM Playback to Master Switch", AC97_PHONE, 14, 1, 1),
654 AC97_SINGLE("PCM Playback to Mono Switch", AC97_PHONE, 13, 1, 1),
656 AC97_SINGLE("Mic 1 Volume", AC97_MIC, 8, 31, 1),
657 AC97_SINGLE("Mic 2 Volume", AC97_MIC, 0, 31, 1),
658 AC97_SINGLE("Mic 1 to Mono Switch", AC97_LINE, 7, 1, 1),
659 AC97_SINGLE("Mic 2 to Mono Switch", AC97_LINE, 6, 1, 1),
660 AC97_SINGLE("Mic Boost (+20dB) Switch", AC97_LINE, 5, 1, 0),
661 AC97_ENUM("Mic to Headphone Mux", wm9713_enum[0]),
662 AC97_SINGLE("Mic Headphone Mixer Volume", AC97_LINE, 0, 7, 1),
664 AC97_SINGLE("Capture Switch", AC97_CD, 15, 1, 1),
665 AC97_ENUM("Capture Volume Steps", wm9713_enum[4]),
666 AC97_DOUBLE("Capture Volume", AC97_CD, 8, 0, 15, 0),
667 AC97_SINGLE("Capture ZC Switch", AC97_CD, 7, 1, 0),
669 AC97_ENUM("Capture to Headphone Mux", wm9713_enum[1]),
670 AC97_SINGLE("Capture to Headphone Volume", AC97_VIDEO, 11, 7, 1),
671 AC97_ENUM("Capture to Mono Mux", wm9713_enum[2]),
672 AC97_SINGLE("Capture to Mono Boost (+20dB) Switch", AC97_VIDEO, 8, 1, 0),
673 AC97_SINGLE("Capture ADC Boost (+20dB) Switch", AC97_VIDEO, 6, 1, 0),
674 AC97_ENUM("Capture Select", wm9713_enum[3]),
676 AC97_SINGLE("ALC Target Volume", AC97_CODEC_CLASS_REV, 12, 15, 0),
677 AC97_SINGLE("ALC Hold Time", AC97_CODEC_CLASS_REV, 8, 15, 0),
678 AC97_SINGLE("ALC Decay Time ", AC97_CODEC_CLASS_REV, 4, 15, 0),
679 AC97_SINGLE("ALC Attack Time", AC97_CODEC_CLASS_REV, 0, 15, 0),
680 AC97_ENUM("ALC Function", wm9713_enum[5]),
681 AC97_SINGLE("ALC Max Volume", AC97_PCI_SVID, 11, 7, 0),
682 AC97_SINGLE("ALC ZC Timeout", AC97_PCI_SVID, 9, 3, 0),
683 AC97_SINGLE("ALC ZC Switch", AC97_PCI_SVID, 8, 1, 0),
684 AC97_SINGLE("ALC NG Switch", AC97_PCI_SVID, 7, 1, 0),
685 AC97_ENUM("ALC NG Type", wm9713_enum[13]),
686 AC97_SINGLE("ALC NG Threshold", AC97_PCI_SVID, 0, 31, 0),
688 AC97_DOUBLE("Master ZC Switch", AC97_MASTER, 14, 6, 1, 0),
689 AC97_DOUBLE("Headphone ZC Switch", AC97_HEADPHONE, 14, 6, 1, 0),
690 AC97_DOUBLE("Out3/4 ZC Switch", AC97_MASTER_MONO, 14, 6, 1, 0),
691 AC97_SINGLE("Master Right Switch", AC97_MASTER, 7, 1, 1),
692 AC97_SINGLE("Headphone Right Switch", AC97_HEADPHONE, 7, 1, 1),
693 AC97_SINGLE("Out3/4 Right Switch", AC97_MASTER_MONO, 7, 1, 1),
695 AC97_SINGLE("Mono In to Headphone Switch", AC97_MASTER_TONE, 15, 1, 1),
696 AC97_SINGLE("Mono In to Master Switch", AC97_MASTER_TONE, 14, 1, 1),
697 AC97_SINGLE("Mono In Volume", AC97_MASTER_TONE, 8, 31, 1),
698 AC97_SINGLE("Mono Switch", AC97_MASTER_TONE, 7, 1, 1),
699 AC97_SINGLE("Mono ZC Switch", AC97_MASTER_TONE, 6, 1, 0),
700 AC97_SINGLE("Mono Volume", AC97_MASTER_TONE, 0, 31, 1),
702 AC97_SINGLE("PC Beep to Headphone Switch", AC97_AUX, 15, 1, 1),
703 AC97_SINGLE("PC Beep to Headphone Volume", AC97_AUX, 12, 7, 1),
704 AC97_SINGLE("PC Beep to Master Switch", AC97_AUX, 11, 1, 1),
705 AC97_SINGLE("PC Beep to Master Volume", AC97_AUX, 8, 7, 1),
706 AC97_SINGLE("PC Beep to Mono Switch", AC97_AUX, 7, 1, 1),
707 AC97_SINGLE("PC Beep to Mono Volume", AC97_AUX, 4, 7, 1),
709 AC97_SINGLE("Voice to Headphone Switch", AC97_PCM, 15, 1, 1),
710 AC97_SINGLE("Voice to Headphone Volume", AC97_PCM, 12, 7, 1),
711 AC97_SINGLE("Voice to Master Switch", AC97_PCM, 11, 1, 1),
712 AC97_SINGLE("Voice to Master Volume", AC97_PCM, 8, 7, 1),
713 AC97_SINGLE("Voice to Mono Switch", AC97_PCM, 7, 1, 1),
714 AC97_SINGLE("Voice to Mono Volume", AC97_PCM, 4, 7, 1),
716 AC97_SINGLE("Aux to Headphone Switch", AC97_REC_SEL, 15, 1, 1),
717 AC97_SINGLE("Aux to Headphone Volume", AC97_REC_SEL, 12, 7, 1),
718 AC97_SINGLE("Aux to Master Switch", AC97_REC_SEL, 11, 1, 1),
719 AC97_SINGLE("Aux to Master Volume", AC97_REC_SEL, 8, 7, 1),
720 AC97_SINGLE("Aux to Mono Switch", AC97_REC_SEL, 7, 1, 1),
721 AC97_SINGLE("Aux to Mono Volume", AC97_REC_SEL, 4, 7, 1),
723 AC97_ENUM("Mono Input Mux", wm9713_enum[6]),
724 AC97_ENUM("Master Input Mux", wm9713_enum[7]),
725 AC97_ENUM("Headphone Input Mux", wm9713_enum[8]),
726 AC97_ENUM("Out 3 Input Mux", wm9713_enum[9]),
727 AC97_ENUM("Out 4 Input Mux", wm9713_enum[10]),
729 AC97_ENUM("Bass Control", wm9713_enum[12]),
730 AC97_SINGLE("Bass Cut-off Switch", AC97_GENERAL_PURPOSE, 12, 1, 1),
731 AC97_SINGLE("Tone Cut-off Switch", AC97_GENERAL_PURPOSE, 4, 1, 1),
732 AC97_SINGLE("Playback Attenuate (-6dB) Switch", AC97_GENERAL_PURPOSE, 6, 1, 0),
733 AC97_SINGLE("Bass Volume", AC97_GENERAL_PURPOSE, 8, 15, 1),
734 AC97_SINGLE("Tone Volume", AC97_GENERAL_PURPOSE, 0, 15, 1),
737 static const struct snd_kcontrol_new wm13_snd_ac97_controls_3d[] = {
738 AC97_ENUM("Inv Input Mux", wm9713_enum[11]),
739 AC97_SINGLE("3D Upper Cut-off Switch", AC97_REC_GAIN_MIC, 5, 1, 0),
740 AC97_SINGLE("3D Lower Cut-off Switch", AC97_REC_GAIN_MIC, 4, 1, 0),
741 AC97_SINGLE("3D Depth", AC97_REC_GAIN_MIC, 0, 15, 1),
744 static int patch_wolfson_wm9713_3d (struct snd_ac97 * ac97)
746 int err, i;
748 for (i = 0; i < ARRAY_SIZE(wm13_snd_ac97_controls_3d); i++) {
749 if ((err = snd_ctl_add(ac97->bus->card, snd_ac97_cnew(&wm13_snd_ac97_controls_3d[i], ac97))) < 0)
750 return err;
752 return 0;
755 static int patch_wolfson_wm9713_specific(struct snd_ac97 * ac97)
757 int err, i;
759 for (i = 0; i < ARRAY_SIZE(wm13_snd_ac97_controls); i++) {
760 if ((err = snd_ctl_add(ac97->bus->card, snd_ac97_cnew(&wm13_snd_ac97_controls[i], ac97))) < 0)
761 return err;
763 snd_ac97_write_cache(ac97, AC97_PC_BEEP, 0x0808);
764 snd_ac97_write_cache(ac97, AC97_PHONE, 0x0808);
765 snd_ac97_write_cache(ac97, AC97_MIC, 0x0808);
766 snd_ac97_write_cache(ac97, AC97_LINE, 0x00da);
767 snd_ac97_write_cache(ac97, AC97_CD, 0x0808);
768 snd_ac97_write_cache(ac97, AC97_VIDEO, 0xd612);
769 snd_ac97_write_cache(ac97, AC97_REC_GAIN, 0x1ba0);
770 return 0;
773 #ifdef CONFIG_PM
774 static void patch_wolfson_wm9713_suspend (struct snd_ac97 * ac97)
776 snd_ac97_write_cache(ac97, AC97_EXTENDED_MID, 0xfeff);
777 snd_ac97_write_cache(ac97, AC97_EXTENDED_MSTATUS, 0xffff);
780 static void patch_wolfson_wm9713_resume (struct snd_ac97 * ac97)
782 snd_ac97_write_cache(ac97, AC97_EXTENDED_MID, 0xda00);
783 snd_ac97_write_cache(ac97, AC97_EXTENDED_MSTATUS, 0x3810);
784 snd_ac97_write_cache(ac97, AC97_POWERDOWN, 0x0);
786 #endif
788 static struct snd_ac97_build_ops patch_wolfson_wm9713_ops = {
789 .build_specific = patch_wolfson_wm9713_specific,
790 .build_3d = patch_wolfson_wm9713_3d,
791 #ifdef CONFIG_PM
792 .suspend = patch_wolfson_wm9713_suspend,
793 .resume = patch_wolfson_wm9713_resume
794 #endif
797 int patch_wolfson13(struct snd_ac97 * ac97)
799 /* WM9713, WM9714 */
800 ac97->build_ops = &patch_wolfson_wm9713_ops;
802 ac97->flags |= AC97_HAS_NO_REC_GAIN | AC97_STEREO_MUTES | AC97_HAS_NO_PHONE |
803 AC97_HAS_NO_PC_BEEP | AC97_HAS_NO_VIDEO | AC97_HAS_NO_CD | AC97_HAS_NO_TONE |
804 AC97_HAS_NO_STD_PCM;
805 ac97->scaps &= ~AC97_SCAP_MODEM;
807 snd_ac97_write_cache(ac97, AC97_EXTENDED_MID, 0xda00);
808 snd_ac97_write_cache(ac97, AC97_EXTENDED_MSTATUS, 0x3810);
809 snd_ac97_write_cache(ac97, AC97_POWERDOWN, 0x0);
811 return 0;
815 * Tritech codec
817 int patch_tritech_tr28028(struct snd_ac97 * ac97)
819 snd_ac97_write_cache(ac97, 0x26, 0x0300);
820 snd_ac97_write_cache(ac97, 0x26, 0x0000);
821 snd_ac97_write_cache(ac97, AC97_SURROUND_MASTER, 0x0000);
822 snd_ac97_write_cache(ac97, AC97_SPDIF, 0x0000);
823 return 0;
827 * Sigmatel STAC97xx codecs
829 static int patch_sigmatel_stac9700_3d(struct snd_ac97 * ac97)
831 struct snd_kcontrol *kctl;
832 int err;
834 if ((err = snd_ctl_add(ac97->bus->card, kctl = snd_ac97_cnew(&snd_ac97_controls_3d[0], ac97))) < 0)
835 return err;
836 strcpy(kctl->id.name, "3D Control Sigmatel - Depth");
837 kctl->private_value = AC97_SINGLE_VALUE(AC97_3D_CONTROL, 2, 3, 0);
838 snd_ac97_write_cache(ac97, AC97_3D_CONTROL, 0x0000);
839 return 0;
842 static int patch_sigmatel_stac9708_3d(struct snd_ac97 * ac97)
844 struct snd_kcontrol *kctl;
845 int err;
847 if ((err = snd_ctl_add(ac97->bus->card, kctl = snd_ac97_cnew(&snd_ac97_controls_3d[0], ac97))) < 0)
848 return err;
849 strcpy(kctl->id.name, "3D Control Sigmatel - Depth");
850 kctl->private_value = AC97_SINGLE_VALUE(AC97_3D_CONTROL, 0, 3, 0);
851 if ((err = snd_ctl_add(ac97->bus->card, kctl = snd_ac97_cnew(&snd_ac97_controls_3d[0], ac97))) < 0)
852 return err;
853 strcpy(kctl->id.name, "3D Control Sigmatel - Rear Depth");
854 kctl->private_value = AC97_SINGLE_VALUE(AC97_3D_CONTROL, 2, 3, 0);
855 snd_ac97_write_cache(ac97, AC97_3D_CONTROL, 0x0000);
856 return 0;
859 static const struct snd_kcontrol_new snd_ac97_sigmatel_4speaker =
860 AC97_SINGLE("Sigmatel 4-Speaker Stereo Playback Switch", AC97_SIGMATEL_DAC2INVERT, 2, 1, 0);
862 static const struct snd_kcontrol_new snd_ac97_sigmatel_phaseinvert =
863 AC97_SINGLE("Sigmatel Surround Phase Inversion Playback Switch", AC97_SIGMATEL_DAC2INVERT, 3, 1, 0);
865 static const struct snd_kcontrol_new snd_ac97_sigmatel_controls[] = {
866 AC97_SINGLE("Sigmatel DAC 6dB Attenuate", AC97_SIGMATEL_ANALOG, 1, 1, 0),
867 AC97_SINGLE("Sigmatel ADC 6dB Attenuate", AC97_SIGMATEL_ANALOG, 0, 1, 0)
870 static int patch_sigmatel_stac97xx_specific(struct snd_ac97 * ac97)
872 int err;
874 snd_ac97_write_cache(ac97, AC97_SIGMATEL_ANALOG, snd_ac97_read(ac97, AC97_SIGMATEL_ANALOG) & ~0x0003);
875 if (snd_ac97_try_bit(ac97, AC97_SIGMATEL_ANALOG, 1))
876 if ((err = patch_build_controls(ac97, &snd_ac97_sigmatel_controls[0], 1)) < 0)
877 return err;
878 if (snd_ac97_try_bit(ac97, AC97_SIGMATEL_ANALOG, 0))
879 if ((err = patch_build_controls(ac97, &snd_ac97_sigmatel_controls[1], 1)) < 0)
880 return err;
881 if (snd_ac97_try_bit(ac97, AC97_SIGMATEL_DAC2INVERT, 2))
882 if ((err = patch_build_controls(ac97, &snd_ac97_sigmatel_4speaker, 1)) < 0)
883 return err;
884 if (snd_ac97_try_bit(ac97, AC97_SIGMATEL_DAC2INVERT, 3))
885 if ((err = patch_build_controls(ac97, &snd_ac97_sigmatel_phaseinvert, 1)) < 0)
886 return err;
887 return 0;
890 static struct snd_ac97_build_ops patch_sigmatel_stac9700_ops = {
891 .build_3d = patch_sigmatel_stac9700_3d,
892 .build_specific = patch_sigmatel_stac97xx_specific
895 int patch_sigmatel_stac9700(struct snd_ac97 * ac97)
897 ac97->build_ops = &patch_sigmatel_stac9700_ops;
898 return 0;
901 static int snd_ac97_stac9708_put_bias(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
903 struct snd_ac97 *ac97 = snd_kcontrol_chip(kcontrol);
904 int err;
906 mutex_lock(&ac97->page_mutex);
907 snd_ac97_write(ac97, AC97_SIGMATEL_BIAS1, 0xabba);
908 err = snd_ac97_update_bits(ac97, AC97_SIGMATEL_BIAS2, 0x0010,
909 (ucontrol->value.integer.value[0] & 1) << 4);
910 snd_ac97_write(ac97, AC97_SIGMATEL_BIAS1, 0);
911 mutex_unlock(&ac97->page_mutex);
912 return err;
915 static const struct snd_kcontrol_new snd_ac97_stac9708_bias_control = {
916 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
917 .name = "Sigmatel Output Bias Switch",
918 .info = snd_ac97_info_volsw,
919 .get = snd_ac97_get_volsw,
920 .put = snd_ac97_stac9708_put_bias,
921 .private_value = AC97_SINGLE_VALUE(AC97_SIGMATEL_BIAS2, 4, 1, 0),
924 static int patch_sigmatel_stac9708_specific(struct snd_ac97 *ac97)
926 int err;
928 snd_ac97_rename_vol_ctl(ac97, "Headphone Playback", "Sigmatel Surround Playback");
929 if ((err = patch_build_controls(ac97, &snd_ac97_stac9708_bias_control, 1)) < 0)
930 return err;
931 return patch_sigmatel_stac97xx_specific(ac97);
934 static struct snd_ac97_build_ops patch_sigmatel_stac9708_ops = {
935 .build_3d = patch_sigmatel_stac9708_3d,
936 .build_specific = patch_sigmatel_stac9708_specific
939 int patch_sigmatel_stac9708(struct snd_ac97 * ac97)
941 unsigned int codec72, codec6c;
943 ac97->build_ops = &patch_sigmatel_stac9708_ops;
944 ac97->caps |= 0x10; /* HP (sigmatel surround) support */
946 codec72 = snd_ac97_read(ac97, AC97_SIGMATEL_BIAS2) & 0x8000;
947 codec6c = snd_ac97_read(ac97, AC97_SIGMATEL_ANALOG);
949 if ((codec72==0) && (codec6c==0)) {
950 snd_ac97_write_cache(ac97, AC97_SIGMATEL_CIC1, 0xabba);
951 snd_ac97_write_cache(ac97, AC97_SIGMATEL_CIC2, 0x1000);
952 snd_ac97_write_cache(ac97, AC97_SIGMATEL_BIAS1, 0xabba);
953 snd_ac97_write_cache(ac97, AC97_SIGMATEL_BIAS2, 0x0007);
954 } else if ((codec72==0x8000) && (codec6c==0)) {
955 snd_ac97_write_cache(ac97, AC97_SIGMATEL_CIC1, 0xabba);
956 snd_ac97_write_cache(ac97, AC97_SIGMATEL_CIC2, 0x1001);
957 snd_ac97_write_cache(ac97, AC97_SIGMATEL_DAC2INVERT, 0x0008);
958 } else if ((codec72==0x8000) && (codec6c==0x0080)) {
959 /* nothing */
961 snd_ac97_write_cache(ac97, AC97_SIGMATEL_MULTICHN, 0x0000);
962 return 0;
965 int patch_sigmatel_stac9721(struct snd_ac97 * ac97)
967 ac97->build_ops = &patch_sigmatel_stac9700_ops;
968 if (snd_ac97_read(ac97, AC97_SIGMATEL_ANALOG) == 0) {
969 // patch for SigmaTel
970 snd_ac97_write_cache(ac97, AC97_SIGMATEL_CIC1, 0xabba);
971 snd_ac97_write_cache(ac97, AC97_SIGMATEL_CIC2, 0x4000);
972 snd_ac97_write_cache(ac97, AC97_SIGMATEL_BIAS1, 0xabba);
973 snd_ac97_write_cache(ac97, AC97_SIGMATEL_BIAS2, 0x0002);
975 snd_ac97_write_cache(ac97, AC97_SIGMATEL_MULTICHN, 0x0000);
976 return 0;
979 int patch_sigmatel_stac9744(struct snd_ac97 * ac97)
981 // patch for SigmaTel
982 ac97->build_ops = &patch_sigmatel_stac9700_ops;
983 snd_ac97_write_cache(ac97, AC97_SIGMATEL_CIC1, 0xabba);
984 snd_ac97_write_cache(ac97, AC97_SIGMATEL_CIC2, 0x0000); /* is this correct? --jk */
985 snd_ac97_write_cache(ac97, AC97_SIGMATEL_BIAS1, 0xabba);
986 snd_ac97_write_cache(ac97, AC97_SIGMATEL_BIAS2, 0x0002);
987 snd_ac97_write_cache(ac97, AC97_SIGMATEL_MULTICHN, 0x0000);
988 return 0;
991 int patch_sigmatel_stac9756(struct snd_ac97 * ac97)
993 // patch for SigmaTel
994 ac97->build_ops = &patch_sigmatel_stac9700_ops;
995 snd_ac97_write_cache(ac97, AC97_SIGMATEL_CIC1, 0xabba);
996 snd_ac97_write_cache(ac97, AC97_SIGMATEL_CIC2, 0x0000); /* is this correct? --jk */
997 snd_ac97_write_cache(ac97, AC97_SIGMATEL_BIAS1, 0xabba);
998 snd_ac97_write_cache(ac97, AC97_SIGMATEL_BIAS2, 0x0002);
999 snd_ac97_write_cache(ac97, AC97_SIGMATEL_MULTICHN, 0x0000);
1000 return 0;
1003 static int snd_ac97_stac9758_output_jack_info(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_info *uinfo)
1005 static char *texts[5] = { "Input/Disabled", "Front Output",
1006 "Rear Output", "Center/LFE Output", "Mixer Output" };
1008 uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED;
1009 uinfo->count = 1;
1010 uinfo->value.enumerated.items = 5;
1011 if (uinfo->value.enumerated.item > 4)
1012 uinfo->value.enumerated.item = 4;
1013 strcpy(uinfo->value.enumerated.name, texts[uinfo->value.enumerated.item]);
1014 return 0;
1017 static int snd_ac97_stac9758_output_jack_get(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
1019 struct snd_ac97 *ac97 = snd_kcontrol_chip(kcontrol);
1020 int shift = kcontrol->private_value;
1021 unsigned short val;
1023 val = ac97->regs[AC97_SIGMATEL_OUTSEL] >> shift;
1024 if (!(val & 4))
1025 ucontrol->value.enumerated.item[0] = 0;
1026 else
1027 ucontrol->value.enumerated.item[0] = 1 + (val & 3);
1028 return 0;
1031 static int snd_ac97_stac9758_output_jack_put(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
1033 struct snd_ac97 *ac97 = snd_kcontrol_chip(kcontrol);
1034 int shift = kcontrol->private_value;
1035 unsigned short val;
1037 if (ucontrol->value.enumerated.item[0] > 4)
1038 return -EINVAL;
1039 if (ucontrol->value.enumerated.item[0] == 0)
1040 val = 0;
1041 else
1042 val = 4 | (ucontrol->value.enumerated.item[0] - 1);
1043 return ac97_update_bits_page(ac97, AC97_SIGMATEL_OUTSEL,
1044 7 << shift, val << shift, 0);
1047 static int snd_ac97_stac9758_input_jack_info(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_info *uinfo)
1049 static char *texts[7] = { "Mic2 Jack", "Mic1 Jack", "Line In Jack",
1050 "Front Jack", "Rear Jack", "Center/LFE Jack", "Mute" };
1052 uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED;
1053 uinfo->count = 1;
1054 uinfo->value.enumerated.items = 7;
1055 if (uinfo->value.enumerated.item > 6)
1056 uinfo->value.enumerated.item = 6;
1057 strcpy(uinfo->value.enumerated.name, texts[uinfo->value.enumerated.item]);
1058 return 0;
1061 static int snd_ac97_stac9758_input_jack_get(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
1063 struct snd_ac97 *ac97 = snd_kcontrol_chip(kcontrol);
1064 int shift = kcontrol->private_value;
1065 unsigned short val;
1067 val = ac97->regs[AC97_SIGMATEL_INSEL];
1068 ucontrol->value.enumerated.item[0] = (val >> shift) & 7;
1069 return 0;
1072 static int snd_ac97_stac9758_input_jack_put(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
1074 struct snd_ac97 *ac97 = snd_kcontrol_chip(kcontrol);
1075 int shift = kcontrol->private_value;
1077 return ac97_update_bits_page(ac97, AC97_SIGMATEL_INSEL, 7 << shift,
1078 ucontrol->value.enumerated.item[0] << shift, 0);
1081 static int snd_ac97_stac9758_phonesel_info(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_info *uinfo)
1083 static char *texts[3] = { "None", "Front Jack", "Rear Jack" };
1085 uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED;
1086 uinfo->count = 1;
1087 uinfo->value.enumerated.items = 3;
1088 if (uinfo->value.enumerated.item > 2)
1089 uinfo->value.enumerated.item = 2;
1090 strcpy(uinfo->value.enumerated.name, texts[uinfo->value.enumerated.item]);
1091 return 0;
1094 static int snd_ac97_stac9758_phonesel_get(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
1096 struct snd_ac97 *ac97 = snd_kcontrol_chip(kcontrol);
1098 ucontrol->value.enumerated.item[0] = ac97->regs[AC97_SIGMATEL_IOMISC] & 3;
1099 return 0;
1102 static int snd_ac97_stac9758_phonesel_put(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
1104 struct snd_ac97 *ac97 = snd_kcontrol_chip(kcontrol);
1106 return ac97_update_bits_page(ac97, AC97_SIGMATEL_IOMISC, 3,
1107 ucontrol->value.enumerated.item[0], 0);
1110 #define STAC9758_OUTPUT_JACK(xname, shift) \
1111 { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = xname, \
1112 .info = snd_ac97_stac9758_output_jack_info, \
1113 .get = snd_ac97_stac9758_output_jack_get, \
1114 .put = snd_ac97_stac9758_output_jack_put, \
1115 .private_value = shift }
1116 #define STAC9758_INPUT_JACK(xname, shift) \
1117 { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = xname, \
1118 .info = snd_ac97_stac9758_input_jack_info, \
1119 .get = snd_ac97_stac9758_input_jack_get, \
1120 .put = snd_ac97_stac9758_input_jack_put, \
1121 .private_value = shift }
1122 static const struct snd_kcontrol_new snd_ac97_sigmatel_stac9758_controls[] = {
1123 STAC9758_OUTPUT_JACK("Mic1 Jack", 1),
1124 STAC9758_OUTPUT_JACK("LineIn Jack", 4),
1125 STAC9758_OUTPUT_JACK("Front Jack", 7),
1126 STAC9758_OUTPUT_JACK("Rear Jack", 10),
1127 STAC9758_OUTPUT_JACK("Center/LFE Jack", 13),
1128 STAC9758_INPUT_JACK("Mic Input Source", 0),
1129 STAC9758_INPUT_JACK("Line Input Source", 8),
1131 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
1132 .name = "Headphone Amp",
1133 .info = snd_ac97_stac9758_phonesel_info,
1134 .get = snd_ac97_stac9758_phonesel_get,
1135 .put = snd_ac97_stac9758_phonesel_put
1137 AC97_SINGLE("Exchange Center/LFE", AC97_SIGMATEL_IOMISC, 4, 1, 0),
1138 AC97_SINGLE("Headphone +3dB Boost", AC97_SIGMATEL_IOMISC, 8, 1, 0)
1141 static int patch_sigmatel_stac9758_specific(struct snd_ac97 *ac97)
1143 int err;
1145 err = patch_sigmatel_stac97xx_specific(ac97);
1146 if (err < 0)
1147 return err;
1148 err = patch_build_controls(ac97, snd_ac97_sigmatel_stac9758_controls,
1149 ARRAY_SIZE(snd_ac97_sigmatel_stac9758_controls));
1150 if (err < 0)
1151 return err;
1152 /* DAC-A direct */
1153 snd_ac97_rename_vol_ctl(ac97, "Headphone Playback", "Front Playback");
1154 /* DAC-A to Mix = PCM */
1155 /* DAC-B direct = Surround */
1156 /* DAC-B to Mix */
1157 snd_ac97_rename_vol_ctl(ac97, "Video Playback", "Surround Mix Playback");
1158 /* DAC-C direct = Center/LFE */
1160 return 0;
1163 static struct snd_ac97_build_ops patch_sigmatel_stac9758_ops = {
1164 .build_3d = patch_sigmatel_stac9700_3d,
1165 .build_specific = patch_sigmatel_stac9758_specific
1168 int patch_sigmatel_stac9758(struct snd_ac97 * ac97)
1170 static unsigned short regs[4] = {
1171 AC97_SIGMATEL_OUTSEL,
1172 AC97_SIGMATEL_IOMISC,
1173 AC97_SIGMATEL_INSEL,
1174 AC97_SIGMATEL_VARIOUS
1176 static unsigned short def_regs[4] = {
1177 /* OUTSEL */ 0xd794, /* CL:CL, SR:SR, LO:MX, LI:DS, MI:DS */
1178 /* IOMISC */ 0x2001,
1179 /* INSEL */ 0x0201, /* LI:LI, MI:M1 */
1180 /* VARIOUS */ 0x0040
1182 static unsigned short m675_regs[4] = {
1183 /* OUTSEL */ 0xfc70, /* CL:MX, SR:MX, LO:DS, LI:MX, MI:DS */
1184 /* IOMISC */ 0x2102, /* HP amp on */
1185 /* INSEL */ 0x0203, /* LI:LI, MI:FR */
1186 /* VARIOUS */ 0x0041 /* stereo mic */
1188 unsigned short *pregs = def_regs;
1189 int i;
1191 /* Gateway M675 notebook */
1192 if (ac97->pci &&
1193 ac97->subsystem_vendor == 0x107b &&
1194 ac97->subsystem_device == 0x0601)
1195 pregs = m675_regs;
1197 // patch for SigmaTel
1198 ac97->build_ops = &patch_sigmatel_stac9758_ops;
1199 /* FIXME: assume only page 0 for writing cache */
1200 snd_ac97_update_bits(ac97, AC97_INT_PAGING, AC97_PAGE_MASK, AC97_PAGE_VENDOR);
1201 for (i = 0; i < 4; i++)
1202 snd_ac97_write_cache(ac97, regs[i], pregs[i]);
1204 ac97->flags |= AC97_STEREO_MUTES;
1205 return 0;
1209 * Cirrus Logic CS42xx codecs
1211 static const struct snd_kcontrol_new snd_ac97_cirrus_controls_spdif[2] = {
1212 AC97_SINGLE(SNDRV_CTL_NAME_IEC958("",PLAYBACK,SWITCH), AC97_CSR_SPDIF, 15, 1, 0),
1213 AC97_SINGLE(SNDRV_CTL_NAME_IEC958("",PLAYBACK,NONE) "AC97-SPSA", AC97_CSR_ACMODE, 0, 3, 0)
1216 static int patch_cirrus_build_spdif(struct snd_ac97 * ac97)
1218 int err;
1220 /* con mask, pro mask, default */
1221 if ((err = patch_build_controls(ac97, &snd_ac97_controls_spdif[0], 3)) < 0)
1222 return err;
1223 /* switch, spsa */
1224 if ((err = patch_build_controls(ac97, &snd_ac97_cirrus_controls_spdif[0], 1)) < 0)
1225 return err;
1226 switch (ac97->id & AC97_ID_CS_MASK) {
1227 case AC97_ID_CS4205:
1228 if ((err = patch_build_controls(ac97, &snd_ac97_cirrus_controls_spdif[1], 1)) < 0)
1229 return err;
1230 break;
1232 /* set default PCM S/PDIF params */
1233 /* consumer,PCM audio,no copyright,no preemphasis,PCM coder,original,48000Hz */
1234 snd_ac97_write_cache(ac97, AC97_CSR_SPDIF, 0x0a20);
1235 return 0;
1238 static struct snd_ac97_build_ops patch_cirrus_ops = {
1239 .build_spdif = patch_cirrus_build_spdif
1242 int patch_cirrus_spdif(struct snd_ac97 * ac97)
1244 /* Basically, the cs4201/cs4205/cs4297a has non-standard sp/dif registers.
1245 WHY CAN'T ANYONE FOLLOW THE BLOODY SPEC? *sigh*
1246 - sp/dif EA ID is not set, but sp/dif is always present.
1247 - enable/disable is spdif register bit 15.
1248 - sp/dif control register is 0x68. differs from AC97:
1249 - valid is bit 14 (vs 15)
1250 - no DRS
1251 - only 44.1/48k [00 = 48, 01=44,1] (AC97 is 00=44.1, 10=48)
1252 - sp/dif ssource select is in 0x5e bits 0,1.
1255 ac97->build_ops = &patch_cirrus_ops;
1256 ac97->flags |= AC97_CS_SPDIF;
1257 ac97->rates[AC97_RATES_SPDIF] &= ~SNDRV_PCM_RATE_32000;
1258 ac97->ext_id |= AC97_EI_SPDIF; /* force the detection of spdif */
1259 snd_ac97_write_cache(ac97, AC97_CSR_ACMODE, 0x0080);
1260 return 0;
1263 int patch_cirrus_cs4299(struct snd_ac97 * ac97)
1265 /* force the detection of PC Beep */
1266 ac97->flags |= AC97_HAS_PC_BEEP;
1268 return patch_cirrus_spdif(ac97);
1272 * Conexant codecs
1274 static const struct snd_kcontrol_new snd_ac97_conexant_controls_spdif[1] = {
1275 AC97_SINGLE(SNDRV_CTL_NAME_IEC958("",PLAYBACK,SWITCH), AC97_CXR_AUDIO_MISC, 3, 1, 0),
1278 static int patch_conexant_build_spdif(struct snd_ac97 * ac97)
1280 int err;
1282 /* con mask, pro mask, default */
1283 if ((err = patch_build_controls(ac97, &snd_ac97_controls_spdif[0], 3)) < 0)
1284 return err;
1285 /* switch */
1286 if ((err = patch_build_controls(ac97, &snd_ac97_conexant_controls_spdif[0], 1)) < 0)
1287 return err;
1288 /* set default PCM S/PDIF params */
1289 /* consumer,PCM audio,no copyright,no preemphasis,PCM coder,original,48000Hz */
1290 snd_ac97_write_cache(ac97, AC97_CXR_AUDIO_MISC,
1291 snd_ac97_read(ac97, AC97_CXR_AUDIO_MISC) & ~(AC97_CXR_SPDIFEN|AC97_CXR_COPYRGT|AC97_CXR_SPDIF_MASK));
1292 return 0;
1295 static struct snd_ac97_build_ops patch_conexant_ops = {
1296 .build_spdif = patch_conexant_build_spdif
1299 int patch_conexant(struct snd_ac97 * ac97)
1301 ac97->build_ops = &patch_conexant_ops;
1302 ac97->flags |= AC97_CX_SPDIF;
1303 ac97->ext_id |= AC97_EI_SPDIF; /* force the detection of spdif */
1304 ac97->rates[AC97_RATES_SPDIF] = SNDRV_PCM_RATE_48000; /* 48k only */
1305 return 0;
1309 * Analog Device AD18xx, AD19xx codecs
1311 #ifdef CONFIG_PM
1312 static void ad18xx_resume(struct snd_ac97 *ac97)
1314 static unsigned short setup_regs[] = {
1315 AC97_AD_MISC, AC97_AD_SERIAL_CFG, AC97_AD_JACK_SPDIF,
1317 int i, codec;
1319 for (i = 0; i < (int)ARRAY_SIZE(setup_regs); i++) {
1320 unsigned short reg = setup_regs[i];
1321 if (test_bit(reg, ac97->reg_accessed)) {
1322 snd_ac97_write(ac97, reg, ac97->regs[reg]);
1323 snd_ac97_read(ac97, reg);
1327 if (! (ac97->flags & AC97_AD_MULTI))
1328 /* normal restore */
1329 snd_ac97_restore_status(ac97);
1330 else {
1331 /* restore the AD18xx codec configurations */
1332 for (codec = 0; codec < 3; codec++) {
1333 if (! ac97->spec.ad18xx.id[codec])
1334 continue;
1335 /* select single codec */
1336 snd_ac97_update_bits(ac97, AC97_AD_SERIAL_CFG, 0x7000,
1337 ac97->spec.ad18xx.unchained[codec] | ac97->spec.ad18xx.chained[codec]);
1338 ac97->bus->ops->write(ac97, AC97_AD_CODEC_CFG, ac97->spec.ad18xx.codec_cfg[codec]);
1340 /* select all codecs */
1341 snd_ac97_update_bits(ac97, AC97_AD_SERIAL_CFG, 0x7000, 0x7000);
1343 /* restore status */
1344 for (i = 2; i < 0x7c ; i += 2) {
1345 if (i == AC97_POWERDOWN || i == AC97_EXTENDED_ID)
1346 continue;
1347 if (test_bit(i, ac97->reg_accessed)) {
1348 /* handle multi codecs for AD18xx */
1349 if (i == AC97_PCM) {
1350 for (codec = 0; codec < 3; codec++) {
1351 if (! ac97->spec.ad18xx.id[codec])
1352 continue;
1353 /* select single codec */
1354 snd_ac97_update_bits(ac97, AC97_AD_SERIAL_CFG, 0x7000,
1355 ac97->spec.ad18xx.unchained[codec] | ac97->spec.ad18xx.chained[codec]);
1356 /* update PCM bits */
1357 ac97->bus->ops->write(ac97, AC97_PCM, ac97->spec.ad18xx.pcmreg[codec]);
1359 /* select all codecs */
1360 snd_ac97_update_bits(ac97, AC97_AD_SERIAL_CFG, 0x7000, 0x7000);
1361 continue;
1362 } else if (i == AC97_AD_TEST ||
1363 i == AC97_AD_CODEC_CFG ||
1364 i == AC97_AD_SERIAL_CFG)
1365 continue; /* ignore */
1367 snd_ac97_write(ac97, i, ac97->regs[i]);
1368 snd_ac97_read(ac97, i);
1372 snd_ac97_restore_iec958(ac97);
1375 static void ad1888_resume(struct snd_ac97 *ac97)
1377 ad18xx_resume(ac97);
1378 snd_ac97_write_cache(ac97, AC97_CODEC_CLASS_REV, 0x8080);
1381 #endif
1383 int patch_ad1819(struct snd_ac97 * ac97)
1385 unsigned short scfg;
1387 // patch for Analog Devices
1388 scfg = snd_ac97_read(ac97, AC97_AD_SERIAL_CFG);
1389 snd_ac97_write_cache(ac97, AC97_AD_SERIAL_CFG, scfg | 0x7000); /* select all codecs */
1390 return 0;
1393 static unsigned short patch_ad1881_unchained(struct snd_ac97 * ac97, int idx, unsigned short mask)
1395 unsigned short val;
1397 // test for unchained codec
1398 snd_ac97_update_bits(ac97, AC97_AD_SERIAL_CFG, 0x7000, mask);
1399 snd_ac97_write_cache(ac97, AC97_AD_CODEC_CFG, 0x0000); /* ID0C, ID1C, SDIE = off */
1400 val = snd_ac97_read(ac97, AC97_VENDOR_ID2);
1401 if ((val & 0xff40) != 0x5340)
1402 return 0;
1403 ac97->spec.ad18xx.unchained[idx] = mask;
1404 ac97->spec.ad18xx.id[idx] = val;
1405 ac97->spec.ad18xx.codec_cfg[idx] = 0x0000;
1406 return mask;
1409 static int patch_ad1881_chained1(struct snd_ac97 * ac97, int idx, unsigned short codec_bits)
1411 static int cfg_bits[3] = { 1<<12, 1<<14, 1<<13 };
1412 unsigned short val;
1414 snd_ac97_update_bits(ac97, AC97_AD_SERIAL_CFG, 0x7000, cfg_bits[idx]);
1415 snd_ac97_write_cache(ac97, AC97_AD_CODEC_CFG, 0x0004); // SDIE
1416 val = snd_ac97_read(ac97, AC97_VENDOR_ID2);
1417 if ((val & 0xff40) != 0x5340)
1418 return 0;
1419 if (codec_bits)
1420 snd_ac97_write_cache(ac97, AC97_AD_CODEC_CFG, codec_bits);
1421 ac97->spec.ad18xx.chained[idx] = cfg_bits[idx];
1422 ac97->spec.ad18xx.id[idx] = val;
1423 ac97->spec.ad18xx.codec_cfg[idx] = codec_bits ? codec_bits : 0x0004;
1424 return 1;
1427 static void patch_ad1881_chained(struct snd_ac97 * ac97, int unchained_idx, int cidx1, int cidx2)
1429 // already detected?
1430 if (ac97->spec.ad18xx.unchained[cidx1] || ac97->spec.ad18xx.chained[cidx1])
1431 cidx1 = -1;
1432 if (ac97->spec.ad18xx.unchained[cidx2] || ac97->spec.ad18xx.chained[cidx2])
1433 cidx2 = -1;
1434 if (cidx1 < 0 && cidx2 < 0)
1435 return;
1436 // test for chained codecs
1437 snd_ac97_update_bits(ac97, AC97_AD_SERIAL_CFG, 0x7000,
1438 ac97->spec.ad18xx.unchained[unchained_idx]);
1439 snd_ac97_write_cache(ac97, AC97_AD_CODEC_CFG, 0x0002); // ID1C
1440 ac97->spec.ad18xx.codec_cfg[unchained_idx] = 0x0002;
1441 if (cidx1 >= 0) {
1442 if (patch_ad1881_chained1(ac97, cidx1, 0x0006)) // SDIE | ID1C
1443 patch_ad1881_chained1(ac97, cidx2, 0);
1444 else if (patch_ad1881_chained1(ac97, cidx2, 0x0006)) // SDIE | ID1C
1445 patch_ad1881_chained1(ac97, cidx1, 0);
1446 } else if (cidx2 >= 0) {
1447 patch_ad1881_chained1(ac97, cidx2, 0);
1451 static struct snd_ac97_build_ops patch_ad1881_build_ops = {
1452 #ifdef CONFIG_PM
1453 .resume = ad18xx_resume
1454 #endif
1457 int patch_ad1881(struct snd_ac97 * ac97)
1459 static const char cfg_idxs[3][2] = {
1460 {2, 1},
1461 {0, 2},
1462 {0, 1}
1465 // patch for Analog Devices
1466 unsigned short codecs[3];
1467 unsigned short val;
1468 int idx, num;
1470 val = snd_ac97_read(ac97, AC97_AD_SERIAL_CFG);
1471 snd_ac97_write_cache(ac97, AC97_AD_SERIAL_CFG, val);
1472 codecs[0] = patch_ad1881_unchained(ac97, 0, (1<<12));
1473 codecs[1] = patch_ad1881_unchained(ac97, 1, (1<<14));
1474 codecs[2] = patch_ad1881_unchained(ac97, 2, (1<<13));
1476 if (! (codecs[0] || codecs[1] || codecs[2]))
1477 goto __end;
1479 for (idx = 0; idx < 3; idx++)
1480 if (ac97->spec.ad18xx.unchained[idx])
1481 patch_ad1881_chained(ac97, idx, cfg_idxs[idx][0], cfg_idxs[idx][1]);
1483 if (ac97->spec.ad18xx.id[1]) {
1484 ac97->flags |= AC97_AD_MULTI;
1485 ac97->scaps |= AC97_SCAP_SURROUND_DAC;
1487 if (ac97->spec.ad18xx.id[2]) {
1488 ac97->flags |= AC97_AD_MULTI;
1489 ac97->scaps |= AC97_SCAP_CENTER_LFE_DAC;
1492 __end:
1493 /* select all codecs */
1494 snd_ac97_update_bits(ac97, AC97_AD_SERIAL_CFG, 0x7000, 0x7000);
1495 /* check if only one codec is present */
1496 for (idx = num = 0; idx < 3; idx++)
1497 if (ac97->spec.ad18xx.id[idx])
1498 num++;
1499 if (num == 1) {
1500 /* ok, deselect all ID bits */
1501 snd_ac97_write_cache(ac97, AC97_AD_CODEC_CFG, 0x0000);
1502 ac97->spec.ad18xx.codec_cfg[0] =
1503 ac97->spec.ad18xx.codec_cfg[1] =
1504 ac97->spec.ad18xx.codec_cfg[2] = 0x0000;
1506 /* required for AD1886/AD1885 combination */
1507 ac97->ext_id = snd_ac97_read(ac97, AC97_EXTENDED_ID);
1508 if (ac97->spec.ad18xx.id[0]) {
1509 ac97->id &= 0xffff0000;
1510 ac97->id |= ac97->spec.ad18xx.id[0];
1512 ac97->build_ops = &patch_ad1881_build_ops;
1513 return 0;
1516 static const struct snd_kcontrol_new snd_ac97_controls_ad1885[] = {
1517 AC97_SINGLE("Digital Mono Direct", AC97_AD_MISC, 11, 1, 0),
1518 /* AC97_SINGLE("Digital Audio Mode", AC97_AD_MISC, 12, 1, 0), */ /* seems problematic */
1519 AC97_SINGLE("Low Power Mixer", AC97_AD_MISC, 14, 1, 0),
1520 AC97_SINGLE("Zero Fill DAC", AC97_AD_MISC, 15, 1, 0),
1521 AC97_SINGLE("Headphone Jack Sense", AC97_AD_JACK_SPDIF, 9, 1, 1), /* inverted */
1522 AC97_SINGLE("Line Jack Sense", AC97_AD_JACK_SPDIF, 8, 1, 1), /* inverted */
1525 static int patch_ad1885_specific(struct snd_ac97 * ac97)
1527 int err;
1529 if ((err = patch_build_controls(ac97, snd_ac97_controls_ad1885, ARRAY_SIZE(snd_ac97_controls_ad1885))) < 0)
1530 return err;
1531 return 0;
1534 static struct snd_ac97_build_ops patch_ad1885_build_ops = {
1535 .build_specific = &patch_ad1885_specific,
1536 #ifdef CONFIG_PM
1537 .resume = ad18xx_resume
1538 #endif
1541 int patch_ad1885(struct snd_ac97 * ac97)
1543 patch_ad1881(ac97);
1544 /* This is required to deal with the Intel D815EEAL2 */
1545 /* i.e. Line out is actually headphone out from codec */
1547 /* set default */
1548 snd_ac97_write_cache(ac97, AC97_AD_MISC, 0x0404);
1550 ac97->build_ops = &patch_ad1885_build_ops;
1551 return 0;
1554 int patch_ad1886(struct snd_ac97 * ac97)
1556 patch_ad1881(ac97);
1557 /* Presario700 workaround */
1558 /* for Jack Sense/SPDIF Register misetting causing */
1559 snd_ac97_write_cache(ac97, AC97_AD_JACK_SPDIF, 0x0010);
1560 return 0;
1563 /* MISC bits */
1564 #define AC97_AD198X_MBC 0x0003 /* mic boost */
1565 #define AC97_AD198X_MBC_20 0x0000 /* +20dB */
1566 #define AC97_AD198X_MBC_10 0x0001 /* +10dB */
1567 #define AC97_AD198X_MBC_30 0x0002 /* +30dB */
1568 #define AC97_AD198X_VREFD 0x0004 /* VREF high-Z */
1569 #define AC97_AD198X_VREFH 0x0008 /* 2.25V, 3.7V */
1570 #define AC97_AD198X_VREF_0 0x000c /* 0V */
1571 #define AC97_AD198X_SRU 0x0010 /* sample rate unlock */
1572 #define AC97_AD198X_LOSEL 0x0020 /* LINE_OUT amplifiers input select */
1573 #define AC97_AD198X_2MIC 0x0040 /* 2-channel mic select */
1574 #define AC97_AD198X_SPRD 0x0080 /* SPREAD enable */
1575 #define AC97_AD198X_DMIX0 0x0100 /* downmix mode: 0 = 6-to-4, 1 = 6-to-2 downmix */
1576 #define AC97_AD198X_DMIX1 0x0200 /* downmix mode: 1 = enabled */
1577 #define AC97_AD198X_HPSEL 0x0400 /* headphone amplifier input select */
1578 #define AC97_AD198X_CLDIS 0x0800 /* center/lfe disable */
1579 #define AC97_AD198X_LODIS 0x1000 /* LINE_OUT disable */
1580 #define AC97_AD198X_MSPLT 0x2000 /* mute split */
1581 #define AC97_AD198X_AC97NC 0x4000 /* AC97 no compatible mode */
1582 #define AC97_AD198X_DACZ 0x8000 /* DAC zero-fill mode */
1585 static int snd_ac97_ad198x_spdif_source_info(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_info *uinfo)
1587 static char *texts[2] = { "AC-Link", "A/D Converter" };
1589 uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED;
1590 uinfo->count = 1;
1591 uinfo->value.enumerated.items = 2;
1592 if (uinfo->value.enumerated.item > 1)
1593 uinfo->value.enumerated.item = 1;
1594 strcpy(uinfo->value.enumerated.name, texts[uinfo->value.enumerated.item]);
1595 return 0;
1598 static int snd_ac97_ad198x_spdif_source_get(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
1600 struct snd_ac97 *ac97 = snd_kcontrol_chip(kcontrol);
1601 unsigned short val;
1603 val = ac97->regs[AC97_AD_SERIAL_CFG];
1604 ucontrol->value.enumerated.item[0] = (val >> 2) & 1;
1605 return 0;
1608 static int snd_ac97_ad198x_spdif_source_put(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
1610 struct snd_ac97 *ac97 = snd_kcontrol_chip(kcontrol);
1611 unsigned short val;
1613 if (ucontrol->value.enumerated.item[0] > 1)
1614 return -EINVAL;
1615 val = ucontrol->value.enumerated.item[0] << 2;
1616 return snd_ac97_update_bits(ac97, AC97_AD_SERIAL_CFG, 0x0004, val);
1619 static const struct snd_kcontrol_new snd_ac97_ad198x_spdif_source = {
1620 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
1621 .name = SNDRV_CTL_NAME_IEC958("",PLAYBACK,NONE) "Source",
1622 .info = snd_ac97_ad198x_spdif_source_info,
1623 .get = snd_ac97_ad198x_spdif_source_get,
1624 .put = snd_ac97_ad198x_spdif_source_put,
1627 static int patch_ad198x_post_spdif(struct snd_ac97 * ac97)
1629 return patch_build_controls(ac97, &snd_ac97_ad198x_spdif_source, 1);
1632 static const struct snd_kcontrol_new snd_ac97_ad1981x_jack_sense[] = {
1633 AC97_SINGLE("Headphone Jack Sense", AC97_AD_JACK_SPDIF, 11, 1, 0),
1634 AC97_SINGLE("Line Jack Sense", AC97_AD_JACK_SPDIF, 12, 1, 0),
1637 /* black list to avoid HP/Line jack-sense controls
1638 * (SS vendor << 16 | device)
1640 static unsigned int ad1981_jacks_blacklist[] = {
1641 0x10140537, /* Thinkpad T41p */
1642 0x10140554, /* Thinkpad T42p/R50p */
1643 0 /* end */
1646 static int check_list(struct snd_ac97 *ac97, const unsigned int *list)
1648 u32 subid = ((u32)ac97->subsystem_vendor << 16) | ac97->subsystem_device;
1649 for (; *list; list++)
1650 if (*list == subid)
1651 return 1;
1652 return 0;
1655 static int patch_ad1981a_specific(struct snd_ac97 * ac97)
1657 if (check_list(ac97, ad1981_jacks_blacklist))
1658 return 0;
1659 return patch_build_controls(ac97, snd_ac97_ad1981x_jack_sense,
1660 ARRAY_SIZE(snd_ac97_ad1981x_jack_sense));
1663 static struct snd_ac97_build_ops patch_ad1981a_build_ops = {
1664 .build_post_spdif = patch_ad198x_post_spdif,
1665 .build_specific = patch_ad1981a_specific,
1666 #ifdef CONFIG_PM
1667 .resume = ad18xx_resume
1668 #endif
1671 /* white list to enable HP jack-sense bits
1672 * (SS vendor << 16 | device)
1674 static unsigned int ad1981_jacks_whitelist[] = {
1675 0x0e11005a, /* HP nc4000/4010 */
1676 0x103c0890, /* HP nc6000 */
1677 0x103c0938, /* HP nc4220 */
1678 0x103c099c, /* HP nx6110 */
1679 0x103c0944, /* HP nc6220 */
1680 0x103c0934, /* HP nc8220 */
1681 0x103c006d, /* HP nx9105 */
1682 0x17340088, /* FSC Scenic-W */
1683 0 /* end */
1686 static void check_ad1981_hp_jack_sense(struct snd_ac97 *ac97)
1688 if (check_list(ac97, ad1981_jacks_whitelist))
1689 /* enable headphone jack sense */
1690 snd_ac97_update_bits(ac97, AC97_AD_JACK_SPDIF, 1<<11, 1<<11);
1693 int patch_ad1981a(struct snd_ac97 *ac97)
1695 patch_ad1881(ac97);
1696 ac97->build_ops = &patch_ad1981a_build_ops;
1697 snd_ac97_update_bits(ac97, AC97_AD_MISC, AC97_AD198X_MSPLT, AC97_AD198X_MSPLT);
1698 ac97->flags |= AC97_STEREO_MUTES;
1699 check_ad1981_hp_jack_sense(ac97);
1700 return 0;
1703 static const struct snd_kcontrol_new snd_ac97_ad198x_2cmic =
1704 AC97_SINGLE("Stereo Mic", AC97_AD_MISC, 6, 1, 0);
1706 static int patch_ad1981b_specific(struct snd_ac97 *ac97)
1708 int err;
1710 if ((err = patch_build_controls(ac97, &snd_ac97_ad198x_2cmic, 1)) < 0)
1711 return err;
1712 if (check_list(ac97, ad1981_jacks_blacklist))
1713 return 0;
1714 return patch_build_controls(ac97, snd_ac97_ad1981x_jack_sense,
1715 ARRAY_SIZE(snd_ac97_ad1981x_jack_sense));
1718 static struct snd_ac97_build_ops patch_ad1981b_build_ops = {
1719 .build_post_spdif = patch_ad198x_post_spdif,
1720 .build_specific = patch_ad1981b_specific,
1721 #ifdef CONFIG_PM
1722 .resume = ad18xx_resume
1723 #endif
1726 int patch_ad1981b(struct snd_ac97 *ac97)
1728 patch_ad1881(ac97);
1729 ac97->build_ops = &patch_ad1981b_build_ops;
1730 snd_ac97_update_bits(ac97, AC97_AD_MISC, AC97_AD198X_MSPLT, AC97_AD198X_MSPLT);
1731 ac97->flags |= AC97_STEREO_MUTES;
1732 check_ad1981_hp_jack_sense(ac97);
1733 return 0;
1736 static int snd_ac97_ad1888_lohpsel_info(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_info *uinfo)
1738 uinfo->type = SNDRV_CTL_ELEM_TYPE_BOOLEAN;
1739 uinfo->count = 1;
1740 uinfo->value.integer.min = 0;
1741 uinfo->value.integer.max = 1;
1742 return 0;
1745 static int snd_ac97_ad1888_lohpsel_get(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
1747 struct snd_ac97 *ac97 = snd_kcontrol_chip(kcontrol);
1748 unsigned short val;
1750 val = ac97->regs[AC97_AD_MISC];
1751 ucontrol->value.integer.value[0] = !(val & AC97_AD198X_LOSEL);
1752 return 0;
1755 static int snd_ac97_ad1888_lohpsel_put(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
1757 struct snd_ac97 *ac97 = snd_kcontrol_chip(kcontrol);
1758 unsigned short val;
1760 val = !ucontrol->value.integer.value[0]
1761 ? (AC97_AD198X_LOSEL | AC97_AD198X_HPSEL) : 0;
1762 return snd_ac97_update_bits(ac97, AC97_AD_MISC,
1763 AC97_AD198X_LOSEL | AC97_AD198X_HPSEL, val);
1766 static int snd_ac97_ad1888_downmix_info(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_info *uinfo)
1768 static char *texts[3] = {"Off", "6 -> 4", "6 -> 2"};
1770 uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED;
1771 uinfo->count = 1;
1772 uinfo->value.enumerated.items = 3;
1773 if (uinfo->value.enumerated.item > 2)
1774 uinfo->value.enumerated.item = 2;
1775 strcpy(uinfo->value.enumerated.name, texts[uinfo->value.enumerated.item]);
1776 return 0;
1779 static int snd_ac97_ad1888_downmix_get(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
1781 struct snd_ac97 *ac97 = snd_kcontrol_chip(kcontrol);
1782 unsigned short val;
1784 val = ac97->regs[AC97_AD_MISC];
1785 if (!(val & AC97_AD198X_DMIX1))
1786 ucontrol->value.enumerated.item[0] = 0;
1787 else
1788 ucontrol->value.enumerated.item[0] = 1 + ((val >> 8) & 1);
1789 return 0;
1792 static int snd_ac97_ad1888_downmix_put(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
1794 struct snd_ac97 *ac97 = snd_kcontrol_chip(kcontrol);
1795 unsigned short val;
1797 if (ucontrol->value.enumerated.item[0] > 2)
1798 return -EINVAL;
1799 if (ucontrol->value.enumerated.item[0] == 0)
1800 val = 0;
1801 else
1802 val = AC97_AD198X_DMIX1 |
1803 ((ucontrol->value.enumerated.item[0] - 1) << 8);
1804 return snd_ac97_update_bits(ac97, AC97_AD_MISC,
1805 AC97_AD198X_DMIX0 | AC97_AD198X_DMIX1, val);
1808 static void ad1888_update_jacks(struct snd_ac97 *ac97)
1810 unsigned short val = 0;
1811 if (! is_shared_linein(ac97))
1812 val |= (1 << 12);
1813 if (! is_shared_micin(ac97))
1814 val |= (1 << 11);
1815 /* shared Line-In */
1816 snd_ac97_update_bits(ac97, AC97_AD_MISC, (1 << 11) | (1 << 12), val);
1819 static const struct snd_kcontrol_new snd_ac97_ad1888_controls[] = {
1821 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
1822 .name = "Exchange Front/Surround",
1823 .info = snd_ac97_ad1888_lohpsel_info,
1824 .get = snd_ac97_ad1888_lohpsel_get,
1825 .put = snd_ac97_ad1888_lohpsel_put
1827 AC97_SINGLE("V_REFOUT Enable", AC97_AD_MISC, 2, 1, 1),
1828 AC97_SINGLE("High Pass Filter Enable", AC97_AD_TEST2, 12, 1, 1),
1829 AC97_SINGLE("Spread Front to Surround and Center/LFE", AC97_AD_MISC, 7, 1, 0),
1831 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
1832 .name = "Downmix",
1833 .info = snd_ac97_ad1888_downmix_info,
1834 .get = snd_ac97_ad1888_downmix_get,
1835 .put = snd_ac97_ad1888_downmix_put
1837 AC97_SURROUND_JACK_MODE_CTL,
1838 AC97_CHANNEL_MODE_CTL,
1840 AC97_SINGLE("Headphone Jack Sense", AC97_AD_JACK_SPDIF, 10, 1, 0),
1841 AC97_SINGLE("Line Jack Sense", AC97_AD_JACK_SPDIF, 12, 1, 0),
1844 static int patch_ad1888_specific(struct snd_ac97 *ac97)
1846 /* rename 0x04 as "Master" and 0x02 as "Master Surround" */
1847 snd_ac97_rename_vol_ctl(ac97, "Master Playback", "Master Surround Playback");
1848 snd_ac97_rename_vol_ctl(ac97, "Headphone Playback", "Master Playback");
1849 return patch_build_controls(ac97, snd_ac97_ad1888_controls, ARRAY_SIZE(snd_ac97_ad1888_controls));
1852 static struct snd_ac97_build_ops patch_ad1888_build_ops = {
1853 .build_post_spdif = patch_ad198x_post_spdif,
1854 .build_specific = patch_ad1888_specific,
1855 #ifdef CONFIG_PM
1856 .resume = ad1888_resume,
1857 #endif
1858 .update_jacks = ad1888_update_jacks,
1861 int patch_ad1888(struct snd_ac97 * ac97)
1863 unsigned short misc;
1865 patch_ad1881(ac97);
1866 ac97->build_ops = &patch_ad1888_build_ops;
1867 /* Switch FRONT/SURROUND LINE-OUT/HP-OUT default connection */
1868 /* it seems that most vendors connect line-out connector to headphone out of AC'97 */
1869 /* AD-compatible mode */
1870 /* Stereo mutes enabled */
1871 misc = snd_ac97_read(ac97, AC97_AD_MISC);
1872 snd_ac97_write_cache(ac97, AC97_AD_MISC, misc |
1873 AC97_AD198X_LOSEL |
1874 AC97_AD198X_HPSEL |
1875 AC97_AD198X_MSPLT |
1876 AC97_AD198X_AC97NC);
1877 ac97->flags |= AC97_STEREO_MUTES;
1878 return 0;
1881 static int patch_ad1980_specific(struct snd_ac97 *ac97)
1883 int err;
1885 if ((err = patch_ad1888_specific(ac97)) < 0)
1886 return err;
1887 return patch_build_controls(ac97, &snd_ac97_ad198x_2cmic, 1);
1890 static struct snd_ac97_build_ops patch_ad1980_build_ops = {
1891 .build_post_spdif = patch_ad198x_post_spdif,
1892 .build_specific = patch_ad1980_specific,
1893 #ifdef CONFIG_PM
1894 .resume = ad18xx_resume,
1895 #endif
1896 .update_jacks = ad1888_update_jacks,
1899 int patch_ad1980(struct snd_ac97 * ac97)
1901 patch_ad1888(ac97);
1902 ac97->build_ops = &patch_ad1980_build_ops;
1903 return 0;
1906 static const struct snd_kcontrol_new snd_ac97_ad1985_controls[] = {
1907 AC97_SINGLE("Exchange Center/LFE", AC97_AD_SERIAL_CFG, 3, 1, 0)
1910 static void ad1985_update_jacks(struct snd_ac97 *ac97)
1912 ad1888_update_jacks(ac97);
1913 snd_ac97_update_bits(ac97, AC97_AD_SERIAL_CFG, 1 << 9,
1914 is_shared_micin(ac97) ? 0 : 1 << 9);
1917 static int patch_ad1985_specific(struct snd_ac97 *ac97)
1919 int err;
1921 if ((err = patch_ad1980_specific(ac97)) < 0)
1922 return err;
1923 return patch_build_controls(ac97, snd_ac97_ad1985_controls, ARRAY_SIZE(snd_ac97_ad1985_controls));
1926 static struct snd_ac97_build_ops patch_ad1985_build_ops = {
1927 .build_post_spdif = patch_ad198x_post_spdif,
1928 .build_specific = patch_ad1985_specific,
1929 #ifdef CONFIG_PM
1930 .resume = ad18xx_resume,
1931 #endif
1932 .update_jacks = ad1985_update_jacks,
1935 int patch_ad1985(struct snd_ac97 * ac97)
1937 unsigned short misc;
1939 patch_ad1881(ac97);
1940 ac97->build_ops = &patch_ad1985_build_ops;
1941 misc = snd_ac97_read(ac97, AC97_AD_MISC);
1942 /* switch front/surround line-out/hp-out */
1943 /* center/LFE, mic in 3.75V mode */
1944 /* AD-compatible mode */
1945 /* Stereo mutes enabled */
1946 /* in accordance with ADI driver: misc | 0x5c28 */
1947 snd_ac97_write_cache(ac97, AC97_AD_MISC, misc |
1948 AC97_AD198X_VREFH |
1949 AC97_AD198X_LOSEL |
1950 AC97_AD198X_HPSEL |
1951 AC97_AD198X_CLDIS |
1952 AC97_AD198X_LODIS |
1953 AC97_AD198X_MSPLT |
1954 AC97_AD198X_AC97NC);
1955 ac97->flags |= AC97_STEREO_MUTES;
1956 /* on AD1985 rev. 3, AC'97 revision bits are zero */
1957 ac97->ext_id = (ac97->ext_id & ~AC97_EI_REV_MASK) | AC97_EI_REV_23;
1958 return 0;
1962 * realtek ALC65x/850 codecs
1964 static void alc650_update_jacks(struct snd_ac97 *ac97)
1966 int shared;
1968 /* shared Line-In */
1969 shared = is_shared_linein(ac97);
1970 snd_ac97_update_bits(ac97, AC97_ALC650_MULTICH, 1 << 9,
1971 shared ? (1 << 9) : 0);
1972 /* update shared Mic */
1973 shared = is_shared_micin(ac97);
1974 /* disable/enable vref */
1975 snd_ac97_update_bits(ac97, AC97_ALC650_CLOCK, 1 << 12,
1976 shared ? (1 << 12) : 0);
1977 /* turn on/off center-on-mic */
1978 snd_ac97_update_bits(ac97, AC97_ALC650_MULTICH, 1 << 10,
1979 shared ? (1 << 10) : 0);
1980 /* GPIO0 high for mic */
1981 snd_ac97_update_bits(ac97, AC97_ALC650_GPIO_STATUS, 0x100,
1982 shared ? 0 : 0x100);
1985 static const struct snd_kcontrol_new snd_ac97_controls_alc650[] = {
1986 AC97_SINGLE("Duplicate Front", AC97_ALC650_MULTICH, 0, 1, 0),
1987 AC97_SINGLE("Surround Down Mix", AC97_ALC650_MULTICH, 1, 1, 0),
1988 AC97_SINGLE("Center/LFE Down Mix", AC97_ALC650_MULTICH, 2, 1, 0),
1989 AC97_SINGLE("Exchange Center/LFE", AC97_ALC650_MULTICH, 3, 1, 0),
1990 /* 4: Analog Input To Surround */
1991 /* 5: Analog Input To Center/LFE */
1992 /* 6: Independent Master Volume Right */
1993 /* 7: Independent Master Volume Left */
1994 /* 8: reserved */
1995 /* 9: Line-In/Surround share */
1996 /* 10: Mic/CLFE share */
1997 /* 11-13: in IEC958 controls */
1998 AC97_SINGLE("Swap Surround Slot", AC97_ALC650_MULTICH, 14, 1, 0),
1999 #if 0 /* always set in patch_alc650 */
2000 AC97_SINGLE("IEC958 Input Clock Enable", AC97_ALC650_CLOCK, 0, 1, 0),
2001 AC97_SINGLE("IEC958 Input Pin Enable", AC97_ALC650_CLOCK, 1, 1, 0),
2002 AC97_SINGLE("Surround DAC Switch", AC97_ALC650_SURR_DAC_VOL, 15, 1, 1),
2003 AC97_DOUBLE("Surround DAC Volume", AC97_ALC650_SURR_DAC_VOL, 8, 0, 31, 1),
2004 AC97_SINGLE("Center/LFE DAC Switch", AC97_ALC650_LFE_DAC_VOL, 15, 1, 1),
2005 AC97_DOUBLE("Center/LFE DAC Volume", AC97_ALC650_LFE_DAC_VOL, 8, 0, 31, 1),
2006 #endif
2007 AC97_SURROUND_JACK_MODE_CTL,
2008 AC97_CHANNEL_MODE_CTL,
2011 static const struct snd_kcontrol_new snd_ac97_spdif_controls_alc650[] = {
2012 AC97_SINGLE(SNDRV_CTL_NAME_IEC958("",CAPTURE,SWITCH), AC97_ALC650_MULTICH, 11, 1, 0),
2013 AC97_SINGLE("Analog to IEC958 Output", AC97_ALC650_MULTICH, 12, 1, 0),
2014 /* disable this controls since it doesn't work as expected */
2015 /* AC97_SINGLE("IEC958 Input Monitor", AC97_ALC650_MULTICH, 13, 1, 0), */
2018 static int patch_alc650_specific(struct snd_ac97 * ac97)
2020 int err;
2022 if ((err = patch_build_controls(ac97, snd_ac97_controls_alc650, ARRAY_SIZE(snd_ac97_controls_alc650))) < 0)
2023 return err;
2024 if (ac97->ext_id & AC97_EI_SPDIF) {
2025 if ((err = patch_build_controls(ac97, snd_ac97_spdif_controls_alc650, ARRAY_SIZE(snd_ac97_spdif_controls_alc650))) < 0)
2026 return err;
2028 return 0;
2031 static struct snd_ac97_build_ops patch_alc650_ops = {
2032 .build_specific = patch_alc650_specific,
2033 .update_jacks = alc650_update_jacks
2036 int patch_alc650(struct snd_ac97 * ac97)
2038 unsigned short val;
2040 ac97->build_ops = &patch_alc650_ops;
2042 /* determine the revision */
2043 val = snd_ac97_read(ac97, AC97_ALC650_REVISION) & 0x3f;
2044 if (val < 3)
2045 ac97->id = 0x414c4720; /* Old version */
2046 else if (val < 0x10)
2047 ac97->id = 0x414c4721; /* D version */
2048 else if (val < 0x20)
2049 ac97->id = 0x414c4722; /* E version */
2050 else if (val < 0x30)
2051 ac97->id = 0x414c4723; /* F version */
2053 /* revision E or F */
2054 /* FIXME: what about revision D ? */
2055 ac97->spec.dev_flags = (ac97->id == 0x414c4722 ||
2056 ac97->id == 0x414c4723);
2058 /* enable AC97_ALC650_GPIO_SETUP, AC97_ALC650_CLOCK for R/W */
2059 snd_ac97_write_cache(ac97, AC97_ALC650_GPIO_STATUS,
2060 snd_ac97_read(ac97, AC97_ALC650_GPIO_STATUS) | 0x8000);
2062 /* Enable SPDIF-IN only on Rev.E and above */
2063 val = snd_ac97_read(ac97, AC97_ALC650_CLOCK);
2064 /* SPDIF IN with pin 47 */
2065 if (ac97->spec.dev_flags &&
2066 /* ASUS A6KM requires EAPD */
2067 ! (ac97->subsystem_vendor == 0x1043 &&
2068 ac97->subsystem_device == 0x1103))
2069 val |= 0x03; /* enable */
2070 else
2071 val &= ~0x03; /* disable */
2072 snd_ac97_write_cache(ac97, AC97_ALC650_CLOCK, val);
2074 /* set default: slot 3,4,7,8,6,9
2075 spdif-in monitor off, analog-spdif off, spdif-in off
2076 center on mic off, surround on line-in off
2077 downmix off, duplicate front off
2079 snd_ac97_write_cache(ac97, AC97_ALC650_MULTICH, 0);
2081 /* set GPIO0 for mic bias */
2082 /* GPIO0 pin output, no interrupt, high */
2083 snd_ac97_write_cache(ac97, AC97_ALC650_GPIO_SETUP,
2084 snd_ac97_read(ac97, AC97_ALC650_GPIO_SETUP) | 0x01);
2085 snd_ac97_write_cache(ac97, AC97_ALC650_GPIO_STATUS,
2086 (snd_ac97_read(ac97, AC97_ALC650_GPIO_STATUS) | 0x100) & ~0x10);
2088 /* full DAC volume */
2089 snd_ac97_write_cache(ac97, AC97_ALC650_SURR_DAC_VOL, 0x0808);
2090 snd_ac97_write_cache(ac97, AC97_ALC650_LFE_DAC_VOL, 0x0808);
2091 return 0;
2094 static void alc655_update_jacks(struct snd_ac97 *ac97)
2096 int shared;
2098 /* shared Line-In */
2099 shared = is_shared_linein(ac97);
2100 ac97_update_bits_page(ac97, AC97_ALC650_MULTICH, 1 << 9,
2101 shared ? (1 << 9) : 0, 0);
2102 /* update shared mic */
2103 shared = is_shared_micin(ac97);
2104 /* misc control; vrefout disable */
2105 snd_ac97_update_bits(ac97, AC97_ALC650_CLOCK, 1 << 12,
2106 shared ? (1 << 12) : 0);
2107 ac97_update_bits_page(ac97, AC97_ALC650_MULTICH, 1 << 10,
2108 shared ? (1 << 10) : 0, 0);
2111 static const struct snd_kcontrol_new snd_ac97_controls_alc655[] = {
2112 AC97_PAGE_SINGLE("Duplicate Front", AC97_ALC650_MULTICH, 0, 1, 0, 0),
2113 AC97_SURROUND_JACK_MODE_CTL,
2114 AC97_CHANNEL_MODE_CTL,
2117 static int alc655_iec958_route_info(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_info *uinfo)
2119 static char *texts_655[3] = { "PCM", "Analog In", "IEC958 In" };
2120 static char *texts_658[4] = { "PCM", "Analog1 In", "Analog2 In", "IEC958 In" };
2121 struct snd_ac97 *ac97 = snd_kcontrol_chip(kcontrol);
2123 uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED;
2124 uinfo->count = 1;
2125 uinfo->value.enumerated.items = ac97->spec.dev_flags ? 4 : 3;
2126 if (uinfo->value.enumerated.item >= uinfo->value.enumerated.items)
2127 uinfo->value.enumerated.item = uinfo->value.enumerated.items - 1;
2128 strcpy(uinfo->value.enumerated.name,
2129 ac97->spec.dev_flags ?
2130 texts_658[uinfo->value.enumerated.item] :
2131 texts_655[uinfo->value.enumerated.item]);
2132 return 0;
2135 static int alc655_iec958_route_get(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
2137 struct snd_ac97 *ac97 = snd_kcontrol_chip(kcontrol);
2138 unsigned short val;
2140 val = ac97->regs[AC97_ALC650_MULTICH];
2141 val = (val >> 12) & 3;
2142 if (ac97->spec.dev_flags && val == 3)
2143 val = 0;
2144 ucontrol->value.enumerated.item[0] = val;
2145 return 0;
2148 static int alc655_iec958_route_put(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
2150 struct snd_ac97 *ac97 = snd_kcontrol_chip(kcontrol);
2152 return ac97_update_bits_page(ac97, AC97_ALC650_MULTICH, 3 << 12,
2153 (unsigned short)ucontrol->value.enumerated.item[0] << 12,
2157 static const struct snd_kcontrol_new snd_ac97_spdif_controls_alc655[] = {
2158 AC97_PAGE_SINGLE(SNDRV_CTL_NAME_IEC958("",CAPTURE,SWITCH), AC97_ALC650_MULTICH, 11, 1, 0, 0),
2159 /* disable this controls since it doesn't work as expected */
2160 /* AC97_PAGE_SINGLE("IEC958 Input Monitor", AC97_ALC650_MULTICH, 14, 1, 0, 0), */
2162 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
2163 .name = SNDRV_CTL_NAME_IEC958("",PLAYBACK,NONE) "Source",
2164 .info = alc655_iec958_route_info,
2165 .get = alc655_iec958_route_get,
2166 .put = alc655_iec958_route_put,
2170 static int patch_alc655_specific(struct snd_ac97 * ac97)
2172 int err;
2174 if ((err = patch_build_controls(ac97, snd_ac97_controls_alc655, ARRAY_SIZE(snd_ac97_controls_alc655))) < 0)
2175 return err;
2176 if (ac97->ext_id & AC97_EI_SPDIF) {
2177 if ((err = patch_build_controls(ac97, snd_ac97_spdif_controls_alc655, ARRAY_SIZE(snd_ac97_spdif_controls_alc655))) < 0)
2178 return err;
2180 return 0;
2183 static struct snd_ac97_build_ops patch_alc655_ops = {
2184 .build_specific = patch_alc655_specific,
2185 .update_jacks = alc655_update_jacks
2188 int patch_alc655(struct snd_ac97 * ac97)
2190 unsigned int val;
2192 if (ac97->id == AC97_ID_ALC658) {
2193 ac97->spec.dev_flags = 1; /* ALC658 */
2194 if ((snd_ac97_read(ac97, AC97_ALC650_REVISION) & 0x3f) == 2) {
2195 ac97->id = AC97_ID_ALC658D;
2196 ac97->spec.dev_flags = 2;
2200 ac97->build_ops = &patch_alc655_ops;
2202 /* assume only page 0 for writing cache */
2203 snd_ac97_update_bits(ac97, AC97_INT_PAGING, AC97_PAGE_MASK, AC97_PAGE_VENDOR);
2205 /* adjust default values */
2206 val = snd_ac97_read(ac97, 0x7a); /* misc control */
2207 if (ac97->spec.dev_flags) /* ALC658 */
2208 val &= ~(1 << 1); /* Pin 47 is spdif input pin */
2209 else { /* ALC655 */
2210 if (ac97->subsystem_vendor == 0x1462 &&
2211 ac97->subsystem_device == 0x0131) /* MSI S270 laptop */
2212 val &= ~(1 << 1); /* Pin 47 is EAPD (for internal speaker) */
2213 else
2214 val |= (1 << 1); /* Pin 47 is spdif input pin */
2216 val &= ~(1 << 12); /* vref enable */
2217 snd_ac97_write_cache(ac97, 0x7a, val);
2218 /* set default: spdif-in enabled,
2219 spdif-in monitor off, spdif-in PCM off
2220 center on mic off, surround on line-in off
2221 duplicate front off
2223 snd_ac97_write_cache(ac97, AC97_ALC650_MULTICH, 1<<15);
2225 /* full DAC volume */
2226 snd_ac97_write_cache(ac97, AC97_ALC650_SURR_DAC_VOL, 0x0808);
2227 snd_ac97_write_cache(ac97, AC97_ALC650_LFE_DAC_VOL, 0x0808);
2229 /* update undocumented bit... */
2230 if (ac97->id == AC97_ID_ALC658D)
2231 snd_ac97_update_bits(ac97, 0x74, 0x0800, 0x0800);
2233 return 0;
2237 #define AC97_ALC850_JACK_SELECT 0x76
2238 #define AC97_ALC850_MISC1 0x7a
2240 static void alc850_update_jacks(struct snd_ac97 *ac97)
2242 int shared;
2244 /* shared Line-In */
2245 shared = is_shared_linein(ac97);
2246 /* SURR 1kOhm (bit4), Amp (bit5) */
2247 snd_ac97_update_bits(ac97, AC97_ALC850_MISC1, (1<<4)|(1<<5),
2248 shared ? (1<<5) : (1<<4));
2249 /* LINE-IN = 0, SURROUND = 2 */
2250 snd_ac97_update_bits(ac97, AC97_ALC850_JACK_SELECT, 7 << 12,
2251 shared ? (2<<12) : (0<<12));
2252 /* update shared mic */
2253 shared = is_shared_micin(ac97);
2254 /* Vref disable (bit12), 1kOhm (bit13) */
2255 snd_ac97_update_bits(ac97, AC97_ALC850_MISC1, (1<<12)|(1<<13),
2256 shared ? (1<<12) : (1<<13));
2257 /* MIC-IN = 1, CENTER-LFE = 5 */
2258 snd_ac97_update_bits(ac97, AC97_ALC850_JACK_SELECT, 7 << 4,
2259 shared ? (5<<4) : (1<<4));
2262 static const struct snd_kcontrol_new snd_ac97_controls_alc850[] = {
2263 AC97_PAGE_SINGLE("Duplicate Front", AC97_ALC650_MULTICH, 0, 1, 0, 0),
2264 AC97_SINGLE("Mic Front Input Switch", AC97_ALC850_JACK_SELECT, 15, 1, 1),
2265 AC97_SURROUND_JACK_MODE_CTL,
2266 AC97_CHANNEL_MODE_CTL,
2269 static int patch_alc850_specific(struct snd_ac97 *ac97)
2271 int err;
2273 if ((err = patch_build_controls(ac97, snd_ac97_controls_alc850, ARRAY_SIZE(snd_ac97_controls_alc850))) < 0)
2274 return err;
2275 if (ac97->ext_id & AC97_EI_SPDIF) {
2276 if ((err = patch_build_controls(ac97, snd_ac97_spdif_controls_alc655, ARRAY_SIZE(snd_ac97_spdif_controls_alc655))) < 0)
2277 return err;
2279 return 0;
2282 static struct snd_ac97_build_ops patch_alc850_ops = {
2283 .build_specific = patch_alc850_specific,
2284 .update_jacks = alc850_update_jacks
2287 int patch_alc850(struct snd_ac97 *ac97)
2289 ac97->build_ops = &patch_alc850_ops;
2291 ac97->spec.dev_flags = 0; /* for IEC958 playback route - ALC655 compatible */
2293 /* assume only page 0 for writing cache */
2294 snd_ac97_update_bits(ac97, AC97_INT_PAGING, AC97_PAGE_MASK, AC97_PAGE_VENDOR);
2296 /* adjust default values */
2297 /* set default: spdif-in enabled,
2298 spdif-in monitor off, spdif-in PCM off
2299 center on mic off, surround on line-in off
2300 duplicate front off
2302 snd_ac97_write_cache(ac97, AC97_ALC650_MULTICH, 1<<15);
2303 /* SURR_OUT: on, Surr 1kOhm: on, Surr Amp: off, Front 1kOhm: off
2304 * Front Amp: on, Vref: enable, Center 1kOhm: on, Mix: on
2306 snd_ac97_write_cache(ac97, 0x7a, (1<<1)|(1<<4)|(0<<5)|(1<<6)|
2307 (1<<7)|(0<<12)|(1<<13)|(0<<14));
2308 /* detection UIO2,3: all path floating, UIO3: MIC, Vref2: disable,
2309 * UIO1: FRONT, Vref3: disable, UIO3: LINE, Front-Mic: mute
2311 snd_ac97_write_cache(ac97, 0x76, (0<<0)|(0<<2)|(1<<4)|(1<<7)|(2<<8)|
2312 (1<<11)|(0<<12)|(1<<15));
2314 /* full DAC volume */
2315 snd_ac97_write_cache(ac97, AC97_ALC650_SURR_DAC_VOL, 0x0808);
2316 snd_ac97_write_cache(ac97, AC97_ALC650_LFE_DAC_VOL, 0x0808);
2317 return 0;
2322 * C-Media CM97xx codecs
2324 static void cm9738_update_jacks(struct snd_ac97 *ac97)
2326 /* shared Line-In */
2327 snd_ac97_update_bits(ac97, AC97_CM9738_VENDOR_CTRL, 1 << 10,
2328 is_shared_linein(ac97) ? (1 << 10) : 0);
2331 static const struct snd_kcontrol_new snd_ac97_cm9738_controls[] = {
2332 AC97_SINGLE("Duplicate Front", AC97_CM9738_VENDOR_CTRL, 13, 1, 0),
2333 AC97_SURROUND_JACK_MODE_CTL,
2334 AC97_CHANNEL_MODE_4CH_CTL,
2337 static int patch_cm9738_specific(struct snd_ac97 * ac97)
2339 return patch_build_controls(ac97, snd_ac97_cm9738_controls, ARRAY_SIZE(snd_ac97_cm9738_controls));
2342 static struct snd_ac97_build_ops patch_cm9738_ops = {
2343 .build_specific = patch_cm9738_specific,
2344 .update_jacks = cm9738_update_jacks
2347 int patch_cm9738(struct snd_ac97 * ac97)
2349 ac97->build_ops = &patch_cm9738_ops;
2350 /* FIXME: can anyone confirm below? */
2351 /* CM9738 has no PCM volume although the register reacts */
2352 ac97->flags |= AC97_HAS_NO_PCM_VOL;
2353 snd_ac97_write_cache(ac97, AC97_PCM, 0x8000);
2355 return 0;
2358 static int snd_ac97_cmedia_spdif_playback_source_info(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_info *uinfo)
2360 static char *texts[] = { "Analog", "Digital" };
2362 uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED;
2363 uinfo->count = 1;
2364 uinfo->value.enumerated.items = 2;
2365 if (uinfo->value.enumerated.item > 1)
2366 uinfo->value.enumerated.item = 1;
2367 strcpy(uinfo->value.enumerated.name, texts[uinfo->value.enumerated.item]);
2368 return 0;
2371 static int snd_ac97_cmedia_spdif_playback_source_get(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
2373 struct snd_ac97 *ac97 = snd_kcontrol_chip(kcontrol);
2374 unsigned short val;
2376 val = ac97->regs[AC97_CM9739_SPDIF_CTRL];
2377 ucontrol->value.enumerated.item[0] = (val >> 1) & 0x01;
2378 return 0;
2381 static int snd_ac97_cmedia_spdif_playback_source_put(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
2383 struct snd_ac97 *ac97 = snd_kcontrol_chip(kcontrol);
2385 return snd_ac97_update_bits(ac97, AC97_CM9739_SPDIF_CTRL,
2386 0x01 << 1,
2387 (ucontrol->value.enumerated.item[0] & 0x01) << 1);
2390 static const struct snd_kcontrol_new snd_ac97_cm9739_controls_spdif[] = {
2391 /* BIT 0: SPDI_EN - always true */
2392 { /* BIT 1: SPDIFS */
2393 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
2394 .name = SNDRV_CTL_NAME_IEC958("",PLAYBACK,NONE) "Source",
2395 .info = snd_ac97_cmedia_spdif_playback_source_info,
2396 .get = snd_ac97_cmedia_spdif_playback_source_get,
2397 .put = snd_ac97_cmedia_spdif_playback_source_put,
2399 /* BIT 2: IG_SPIV */
2400 AC97_SINGLE(SNDRV_CTL_NAME_IEC958("",CAPTURE,NONE) "Valid Switch", AC97_CM9739_SPDIF_CTRL, 2, 1, 0),
2401 /* BIT 3: SPI2F */
2402 AC97_SINGLE(SNDRV_CTL_NAME_IEC958("",CAPTURE,NONE) "Monitor", AC97_CM9739_SPDIF_CTRL, 3, 1, 0),
2403 /* BIT 4: SPI2SDI */
2404 AC97_SINGLE(SNDRV_CTL_NAME_IEC958("",CAPTURE,SWITCH), AC97_CM9739_SPDIF_CTRL, 4, 1, 0),
2405 /* BIT 8: SPD32 - 32bit SPDIF - not supported yet */
2408 static void cm9739_update_jacks(struct snd_ac97 *ac97)
2410 /* shared Line-In */
2411 snd_ac97_update_bits(ac97, AC97_CM9739_MULTI_CHAN, 1 << 10,
2412 is_shared_linein(ac97) ? (1 << 10) : 0);
2413 /* shared Mic */
2414 snd_ac97_update_bits(ac97, AC97_CM9739_MULTI_CHAN, 0x3000,
2415 is_shared_micin(ac97) ? 0x1000 : 0x2000);
2418 static const struct snd_kcontrol_new snd_ac97_cm9739_controls[] = {
2419 AC97_SURROUND_JACK_MODE_CTL,
2420 AC97_CHANNEL_MODE_CTL,
2423 static int patch_cm9739_specific(struct snd_ac97 * ac97)
2425 return patch_build_controls(ac97, snd_ac97_cm9739_controls, ARRAY_SIZE(snd_ac97_cm9739_controls));
2428 static int patch_cm9739_post_spdif(struct snd_ac97 * ac97)
2430 return patch_build_controls(ac97, snd_ac97_cm9739_controls_spdif, ARRAY_SIZE(snd_ac97_cm9739_controls_spdif));
2433 static struct snd_ac97_build_ops patch_cm9739_ops = {
2434 .build_specific = patch_cm9739_specific,
2435 .build_post_spdif = patch_cm9739_post_spdif,
2436 .update_jacks = cm9739_update_jacks
2439 int patch_cm9739(struct snd_ac97 * ac97)
2441 unsigned short val;
2443 ac97->build_ops = &patch_cm9739_ops;
2445 /* CM9739/A has no Master and PCM volume although the register reacts */
2446 ac97->flags |= AC97_HAS_NO_MASTER_VOL | AC97_HAS_NO_PCM_VOL;
2447 snd_ac97_write_cache(ac97, AC97_MASTER, 0x8000);
2448 snd_ac97_write_cache(ac97, AC97_PCM, 0x8000);
2450 /* check spdif */
2451 val = snd_ac97_read(ac97, AC97_EXTENDED_STATUS);
2452 if (val & AC97_EA_SPCV) {
2453 /* enable spdif in */
2454 snd_ac97_write_cache(ac97, AC97_CM9739_SPDIF_CTRL,
2455 snd_ac97_read(ac97, AC97_CM9739_SPDIF_CTRL) | 0x01);
2456 ac97->rates[AC97_RATES_SPDIF] = SNDRV_PCM_RATE_48000; /* 48k only */
2457 } else {
2458 ac97->ext_id &= ~AC97_EI_SPDIF; /* disable extended-id */
2459 ac97->rates[AC97_RATES_SPDIF] = 0;
2462 /* set-up multi channel */
2463 /* bit 14: 0 = SPDIF, 1 = EAPD */
2464 /* bit 13: enable internal vref output for mic */
2465 /* bit 12: disable center/lfe (swithable) */
2466 /* bit 10: disable surround/line (switchable) */
2467 /* bit 9: mix 2 surround off */
2468 /* bit 4: undocumented; 0 mutes the CM9739A, which defaults to 1 */
2469 /* bit 3: undocumented; surround? */
2470 /* bit 0: dB */
2471 val = snd_ac97_read(ac97, AC97_CM9739_MULTI_CHAN) & (1 << 4);
2472 val |= (1 << 3);
2473 val |= (1 << 13);
2474 if (! (ac97->ext_id & AC97_EI_SPDIF))
2475 val |= (1 << 14);
2476 snd_ac97_write_cache(ac97, AC97_CM9739_MULTI_CHAN, val);
2478 /* FIXME: set up GPIO */
2479 snd_ac97_write_cache(ac97, 0x70, 0x0100);
2480 snd_ac97_write_cache(ac97, 0x72, 0x0020);
2481 /* Special exception for ASUS W1000/CMI9739. It does not have an SPDIF in. */
2482 if (ac97->pci &&
2483 ac97->subsystem_vendor == 0x1043 &&
2484 ac97->subsystem_device == 0x1843) {
2485 snd_ac97_write_cache(ac97, AC97_CM9739_SPDIF_CTRL,
2486 snd_ac97_read(ac97, AC97_CM9739_SPDIF_CTRL) & ~0x01);
2487 snd_ac97_write_cache(ac97, AC97_CM9739_MULTI_CHAN,
2488 snd_ac97_read(ac97, AC97_CM9739_MULTI_CHAN) | (1 << 14));
2491 return 0;
2494 #define AC97_CM9761_MULTI_CHAN 0x64
2495 #define AC97_CM9761_FUNC 0x66
2496 #define AC97_CM9761_SPDIF_CTRL 0x6c
2498 static void cm9761_update_jacks(struct snd_ac97 *ac97)
2500 /* FIXME: check the bits for each model
2501 * model 83 is confirmed to work
2503 static unsigned short surr_on[3][2] = {
2504 { 0x0008, 0x0000 }, /* 9761-78 & 82 */
2505 { 0x0000, 0x0008 }, /* 9761-82 rev.B */
2506 { 0x0000, 0x0008 }, /* 9761-83 */
2508 static unsigned short clfe_on[3][2] = {
2509 { 0x0000, 0x1000 }, /* 9761-78 & 82 */
2510 { 0x1000, 0x0000 }, /* 9761-82 rev.B */
2511 { 0x0000, 0x1000 }, /* 9761-83 */
2513 static unsigned short surr_shared[3][2] = {
2514 { 0x0000, 0x0400 }, /* 9761-78 & 82 */
2515 { 0x0000, 0x0400 }, /* 9761-82 rev.B */
2516 { 0x0000, 0x0400 }, /* 9761-83 */
2518 static unsigned short clfe_shared[3][2] = {
2519 { 0x2000, 0x0880 }, /* 9761-78 & 82 */
2520 { 0x0000, 0x2880 }, /* 9761-82 rev.B */
2521 { 0x2000, 0x0800 }, /* 9761-83 */
2523 unsigned short val = 0;
2525 val |= surr_on[ac97->spec.dev_flags][is_surround_on(ac97)];
2526 val |= clfe_on[ac97->spec.dev_flags][is_clfe_on(ac97)];
2527 val |= surr_shared[ac97->spec.dev_flags][is_shared_linein(ac97)];
2528 val |= clfe_shared[ac97->spec.dev_flags][is_shared_micin(ac97)];
2530 snd_ac97_update_bits(ac97, AC97_CM9761_MULTI_CHAN, 0x3c88, val);
2533 static const struct snd_kcontrol_new snd_ac97_cm9761_controls[] = {
2534 AC97_SURROUND_JACK_MODE_CTL,
2535 AC97_CHANNEL_MODE_CTL,
2538 static int cm9761_spdif_out_source_info(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_info *uinfo)
2540 static char *texts[] = { "AC-Link", "ADC", "SPDIF-In" };
2542 uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED;
2543 uinfo->count = 1;
2544 uinfo->value.enumerated.items = 3;
2545 if (uinfo->value.enumerated.item > 2)
2546 uinfo->value.enumerated.item = 2;
2547 strcpy(uinfo->value.enumerated.name, texts[uinfo->value.enumerated.item]);
2548 return 0;
2551 static int cm9761_spdif_out_source_get(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
2553 struct snd_ac97 *ac97 = snd_kcontrol_chip(kcontrol);
2555 if (ac97->regs[AC97_CM9761_FUNC] & 0x1)
2556 ucontrol->value.enumerated.item[0] = 2; /* SPDIF-loopback */
2557 else if (ac97->regs[AC97_CM9761_SPDIF_CTRL] & 0x2)
2558 ucontrol->value.enumerated.item[0] = 1; /* ADC loopback */
2559 else
2560 ucontrol->value.enumerated.item[0] = 0; /* AC-link */
2561 return 0;
2564 static int cm9761_spdif_out_source_put(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
2566 struct snd_ac97 *ac97 = snd_kcontrol_chip(kcontrol);
2568 if (ucontrol->value.enumerated.item[0] == 2)
2569 return snd_ac97_update_bits(ac97, AC97_CM9761_FUNC, 0x1, 0x1);
2570 snd_ac97_update_bits(ac97, AC97_CM9761_FUNC, 0x1, 0);
2571 return snd_ac97_update_bits(ac97, AC97_CM9761_SPDIF_CTRL, 0x2,
2572 ucontrol->value.enumerated.item[0] == 1 ? 0x2 : 0);
2575 static const char *cm9761_dac_clock[] = { "AC-Link", "SPDIF-In", "Both" };
2576 static const struct ac97_enum cm9761_dac_clock_enum =
2577 AC97_ENUM_SINGLE(AC97_CM9761_SPDIF_CTRL, 9, 3, cm9761_dac_clock);
2579 static const struct snd_kcontrol_new snd_ac97_cm9761_controls_spdif[] = {
2580 { /* BIT 1: SPDIFS */
2581 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
2582 .name = SNDRV_CTL_NAME_IEC958("",PLAYBACK,NONE) "Source",
2583 .info = cm9761_spdif_out_source_info,
2584 .get = cm9761_spdif_out_source_get,
2585 .put = cm9761_spdif_out_source_put,
2587 /* BIT 2: IG_SPIV */
2588 AC97_SINGLE(SNDRV_CTL_NAME_IEC958("",CAPTURE,NONE) "Valid Switch", AC97_CM9761_SPDIF_CTRL, 2, 1, 0),
2589 /* BIT 3: SPI2F */
2590 AC97_SINGLE(SNDRV_CTL_NAME_IEC958("",CAPTURE,NONE) "Monitor", AC97_CM9761_SPDIF_CTRL, 3, 1, 0),
2591 /* BIT 4: SPI2SDI */
2592 AC97_SINGLE(SNDRV_CTL_NAME_IEC958("",CAPTURE,SWITCH), AC97_CM9761_SPDIF_CTRL, 4, 1, 0),
2593 /* BIT 9-10: DAC_CTL */
2594 AC97_ENUM("DAC Clock Source", cm9761_dac_clock_enum),
2597 static int patch_cm9761_post_spdif(struct snd_ac97 * ac97)
2599 return patch_build_controls(ac97, snd_ac97_cm9761_controls_spdif, ARRAY_SIZE(snd_ac97_cm9761_controls_spdif));
2602 static int patch_cm9761_specific(struct snd_ac97 * ac97)
2604 return patch_build_controls(ac97, snd_ac97_cm9761_controls, ARRAY_SIZE(snd_ac97_cm9761_controls));
2607 static struct snd_ac97_build_ops patch_cm9761_ops = {
2608 .build_specific = patch_cm9761_specific,
2609 .build_post_spdif = patch_cm9761_post_spdif,
2610 .update_jacks = cm9761_update_jacks
2613 int patch_cm9761(struct snd_ac97 *ac97)
2615 unsigned short val;
2617 /* CM9761 has no PCM volume although the register reacts */
2618 /* Master volume seems to have _some_ influence on the analog
2619 * input sounds
2621 ac97->flags |= /*AC97_HAS_NO_MASTER_VOL |*/ AC97_HAS_NO_PCM_VOL;
2622 snd_ac97_write_cache(ac97, AC97_MASTER, 0x8808);
2623 snd_ac97_write_cache(ac97, AC97_PCM, 0x8808);
2625 ac97->spec.dev_flags = 0; /* 1 = model 82 revision B, 2 = model 83 */
2626 if (ac97->id == AC97_ID_CM9761_82) {
2627 unsigned short tmp;
2628 /* check page 1, reg 0x60 */
2629 val = snd_ac97_read(ac97, AC97_INT_PAGING);
2630 snd_ac97_write_cache(ac97, AC97_INT_PAGING, (val & ~0x0f) | 0x01);
2631 tmp = snd_ac97_read(ac97, 0x60);
2632 ac97->spec.dev_flags = tmp & 1; /* revision B? */
2633 snd_ac97_write_cache(ac97, AC97_INT_PAGING, val);
2634 } else if (ac97->id == AC97_ID_CM9761_83)
2635 ac97->spec.dev_flags = 2;
2637 ac97->build_ops = &patch_cm9761_ops;
2639 /* enable spdif */
2640 /* force the SPDIF bit in ext_id - codec doesn't set this bit! */
2641 ac97->ext_id |= AC97_EI_SPDIF;
2642 /* to be sure: we overwrite the ext status bits */
2643 snd_ac97_write_cache(ac97, AC97_EXTENDED_STATUS, 0x05c0);
2644 /* Don't set 0x0200 here. This results in the silent analog output */
2645 snd_ac97_write_cache(ac97, AC97_CM9761_SPDIF_CTRL, 0x0001); /* enable spdif-in */
2646 ac97->rates[AC97_RATES_SPDIF] = SNDRV_PCM_RATE_48000; /* 48k only */
2648 /* set-up multi channel */
2649 /* bit 15: pc master beep off
2650 * bit 14: pin47 = EAPD/SPDIF
2651 * bit 13: vref ctl [= cm9739]
2652 * bit 12: CLFE control (reverted on rev B)
2653 * bit 11: Mic/center share (reverted on rev B)
2654 * bit 10: suddound/line share
2655 * bit 9: Analog-in mix -> surround
2656 * bit 8: Analog-in mix -> CLFE
2657 * bit 7: Mic/LFE share (mic/center/lfe)
2658 * bit 5: vref select (9761A)
2659 * bit 4: front control
2660 * bit 3: surround control (revereted with rev B)
2661 * bit 2: front mic
2662 * bit 1: stereo mic
2663 * bit 0: mic boost level (0=20dB, 1=30dB)
2666 #if 0
2667 if (ac97->spec.dev_flags)
2668 val = 0x0214;
2669 else
2670 val = 0x321c;
2671 #endif
2672 val = snd_ac97_read(ac97, AC97_CM9761_MULTI_CHAN);
2673 val |= (1 << 4); /* front on */
2674 snd_ac97_write_cache(ac97, AC97_CM9761_MULTI_CHAN, val);
2676 /* FIXME: set up GPIO */
2677 snd_ac97_write_cache(ac97, 0x70, 0x0100);
2678 snd_ac97_write_cache(ac97, 0x72, 0x0020);
2680 return 0;
2683 #define AC97_CM9780_SIDE 0x60
2684 #define AC97_CM9780_JACK 0x62
2685 #define AC97_CM9780_MIXER 0x64
2686 #define AC97_CM9780_MULTI_CHAN 0x66
2687 #define AC97_CM9780_SPDIF 0x6c
2689 static const char *cm9780_ch_select[] = { "Front", "Side", "Center/LFE", "Rear" };
2690 static const struct ac97_enum cm9780_ch_select_enum =
2691 AC97_ENUM_SINGLE(AC97_CM9780_MULTI_CHAN, 6, 4, cm9780_ch_select);
2692 static const struct snd_kcontrol_new cm9780_controls[] = {
2693 AC97_DOUBLE("Side Playback Switch", AC97_CM9780_SIDE, 15, 7, 1, 1),
2694 AC97_DOUBLE("Side Playback Volume", AC97_CM9780_SIDE, 8, 0, 31, 0),
2695 AC97_ENUM("Side Playback Route", cm9780_ch_select_enum),
2698 static int patch_cm9780_specific(struct snd_ac97 *ac97)
2700 return patch_build_controls(ac97, cm9780_controls, ARRAY_SIZE(cm9780_controls));
2703 static struct snd_ac97_build_ops patch_cm9780_ops = {
2704 .build_specific = patch_cm9780_specific,
2705 .build_post_spdif = patch_cm9761_post_spdif /* identical with CM9761 */
2708 int patch_cm9780(struct snd_ac97 *ac97)
2710 unsigned short val;
2712 ac97->build_ops = &patch_cm9780_ops;
2714 /* enable spdif */
2715 if (ac97->ext_id & AC97_EI_SPDIF) {
2716 ac97->rates[AC97_RATES_SPDIF] = SNDRV_PCM_RATE_48000; /* 48k only */
2717 val = snd_ac97_read(ac97, AC97_CM9780_SPDIF);
2718 val |= 0x1; /* SPDI_EN */
2719 snd_ac97_write_cache(ac97, AC97_CM9780_SPDIF, val);
2722 return 0;
2726 * VIA VT1616 codec
2728 static const struct snd_kcontrol_new snd_ac97_controls_vt1616[] = {
2729 AC97_SINGLE("DC Offset removal", 0x5a, 10, 1, 0),
2730 AC97_SINGLE("Alternate Level to Surround Out", 0x5a, 15, 1, 0),
2731 AC97_SINGLE("Downmix LFE and Center to Front", 0x5a, 12, 1, 0),
2732 AC97_SINGLE("Downmix Surround to Front", 0x5a, 11, 1, 0),
2735 static int patch_vt1616_specific(struct snd_ac97 * ac97)
2737 int err;
2739 if (snd_ac97_try_bit(ac97, 0x5a, 9))
2740 if ((err = patch_build_controls(ac97, &snd_ac97_controls_vt1616[0], 1)) < 0)
2741 return err;
2742 if ((err = patch_build_controls(ac97, &snd_ac97_controls_vt1616[1], ARRAY_SIZE(snd_ac97_controls_vt1616) - 1)) < 0)
2743 return err;
2744 return 0;
2747 static struct snd_ac97_build_ops patch_vt1616_ops = {
2748 .build_specific = patch_vt1616_specific
2751 int patch_vt1616(struct snd_ac97 * ac97)
2753 ac97->build_ops = &patch_vt1616_ops;
2754 return 0;
2758 * VT1617A codec
2760 int patch_vt1617a(struct snd_ac97 * ac97)
2762 ac97->ext_id |= AC97_EI_SPDIF; /* force the detection of spdif */
2763 ac97->rates[AC97_RATES_SPDIF] = SNDRV_PCM_RATE_44100 | SNDRV_PCM_RATE_48000;
2764 return 0;
2769 static void it2646_update_jacks(struct snd_ac97 *ac97)
2771 /* shared Line-In */
2772 snd_ac97_update_bits(ac97, 0x76, 1 << 9,
2773 is_shared_linein(ac97) ? (1<<9) : 0);
2774 /* shared Mic */
2775 snd_ac97_update_bits(ac97, 0x76, 1 << 10,
2776 is_shared_micin(ac97) ? (1<<10) : 0);
2779 static const struct snd_kcontrol_new snd_ac97_controls_it2646[] = {
2780 AC97_SURROUND_JACK_MODE_CTL,
2781 AC97_CHANNEL_MODE_CTL,
2784 static const struct snd_kcontrol_new snd_ac97_spdif_controls_it2646[] = {
2785 AC97_SINGLE(SNDRV_CTL_NAME_IEC958("",CAPTURE,SWITCH), 0x76, 11, 1, 0),
2786 AC97_SINGLE("Analog to IEC958 Output", 0x76, 12, 1, 0),
2787 AC97_SINGLE("IEC958 Input Monitor", 0x76, 13, 1, 0),
2790 static int patch_it2646_specific(struct snd_ac97 * ac97)
2792 int err;
2793 if ((err = patch_build_controls(ac97, snd_ac97_controls_it2646, ARRAY_SIZE(snd_ac97_controls_it2646))) < 0)
2794 return err;
2795 if ((err = patch_build_controls(ac97, snd_ac97_spdif_controls_it2646, ARRAY_SIZE(snd_ac97_spdif_controls_it2646))) < 0)
2796 return err;
2797 return 0;
2800 static struct snd_ac97_build_ops patch_it2646_ops = {
2801 .build_specific = patch_it2646_specific,
2802 .update_jacks = it2646_update_jacks
2805 int patch_it2646(struct snd_ac97 * ac97)
2807 ac97->build_ops = &patch_it2646_ops;
2808 /* full DAC volume */
2809 snd_ac97_write_cache(ac97, 0x5E, 0x0808);
2810 snd_ac97_write_cache(ac97, 0x7A, 0x0808);
2811 return 0;
2815 * Si3036 codec
2818 #define AC97_SI3036_CHIP_ID 0x5a
2819 #define AC97_SI3036_LINE_CFG 0x5c
2821 static const struct snd_kcontrol_new snd_ac97_controls_si3036[] = {
2822 AC97_DOUBLE("Modem Speaker Volume", 0x5c, 14, 12, 3, 1)
2825 static int patch_si3036_specific(struct snd_ac97 * ac97)
2827 int idx, err;
2828 for (idx = 0; idx < ARRAY_SIZE(snd_ac97_controls_si3036); idx++)
2829 if ((err = snd_ctl_add(ac97->bus->card, snd_ctl_new1(&snd_ac97_controls_si3036[idx], ac97))) < 0)
2830 return err;
2831 return 0;
2834 static struct snd_ac97_build_ops patch_si3036_ops = {
2835 .build_specific = patch_si3036_specific,
2838 int mpatch_si3036(struct snd_ac97 * ac97)
2840 ac97->build_ops = &patch_si3036_ops;
2841 snd_ac97_write_cache(ac97, 0x5c, 0xf210 );
2842 snd_ac97_write_cache(ac97, 0x68, 0);
2843 return 0;
2847 * LM 4550 Codec
2849 * We use a static resolution table since LM4550 codec cannot be
2850 * properly autoprobed to determine the resolution via
2851 * check_volume_resolution().
2854 static struct snd_ac97_res_table lm4550_restbl[] = {
2855 { AC97_MASTER, 0x1f1f },
2856 { AC97_HEADPHONE, 0x1f1f },
2857 { AC97_MASTER_MONO, 0x001f },
2858 { AC97_PC_BEEP, 0x001f }, /* LSB is ignored */
2859 { AC97_PHONE, 0x001f },
2860 { AC97_MIC, 0x001f },
2861 { AC97_LINE, 0x1f1f },
2862 { AC97_CD, 0x1f1f },
2863 { AC97_VIDEO, 0x1f1f },
2864 { AC97_AUX, 0x1f1f },
2865 { AC97_PCM, 0x1f1f },
2866 { AC97_REC_GAIN, 0x0f0f },
2867 { } /* terminator */
2870 int patch_lm4550(struct snd_ac97 *ac97)
2872 ac97->res_table = lm4550_restbl;
2873 return 0;