xref: /openbmc/linux/sound/pci/ac97/ac97_patch.c (revision eed65649)
11da177e4SLinus Torvalds /*
21da177e4SLinus Torvalds  *  Copyright (c) by Jaroslav Kysela <perex@suse.cz>
31da177e4SLinus Torvalds  *  Universal interface for Audio Codec '97
41da177e4SLinus Torvalds  *
51da177e4SLinus Torvalds  *  For more details look to AC '97 component specification revision 2.2
61da177e4SLinus Torvalds  *  by Intel Corporation (http://developer.intel.com) and to datasheets
71da177e4SLinus Torvalds  *  for specific codecs.
81da177e4SLinus Torvalds  *
91da177e4SLinus Torvalds  *
101da177e4SLinus Torvalds  *   This program is free software; you can redistribute it and/or modify
111da177e4SLinus Torvalds  *   it under the terms of the GNU General Public License as published by
121da177e4SLinus Torvalds  *   the Free Software Foundation; either version 2 of the License, or
131da177e4SLinus Torvalds  *   (at your option) any later version.
141da177e4SLinus Torvalds  *
151da177e4SLinus Torvalds  *   This program is distributed in the hope that it will be useful,
161da177e4SLinus Torvalds  *   but WITHOUT ANY WARRANTY; without even the implied warranty of
171da177e4SLinus Torvalds  *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
181da177e4SLinus Torvalds  *   GNU General Public License for more details.
191da177e4SLinus Torvalds  *
201da177e4SLinus Torvalds  *   You should have received a copy of the GNU General Public License
211da177e4SLinus Torvalds  *   along with this program; if not, write to the Free Software
221da177e4SLinus Torvalds  *   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
231da177e4SLinus Torvalds  *
241da177e4SLinus Torvalds  */
251da177e4SLinus Torvalds 
261da177e4SLinus Torvalds #include <sound/driver.h>
271da177e4SLinus Torvalds #include <linux/delay.h>
281da177e4SLinus Torvalds #include <linux/init.h>
291da177e4SLinus Torvalds #include <linux/slab.h>
3062932df8SIngo Molnar #include <linux/mutex.h>
3162932df8SIngo Molnar 
321da177e4SLinus Torvalds #include <sound/core.h>
331da177e4SLinus Torvalds #include <sound/pcm.h>
341da177e4SLinus Torvalds #include <sound/control.h>
351da177e4SLinus Torvalds #include <sound/ac97_codec.h>
361da177e4SLinus Torvalds #include "ac97_patch.h"
371da177e4SLinus Torvalds #include "ac97_id.h"
381da177e4SLinus Torvalds #include "ac97_local.h"
391da177e4SLinus Torvalds 
401da177e4SLinus Torvalds /*
411da177e4SLinus Torvalds  *  Chip specific initialization
421da177e4SLinus Torvalds  */
431da177e4SLinus Torvalds 
44ee42381eSTakashi Iwai static int patch_build_controls(struct snd_ac97 * ac97, const struct snd_kcontrol_new *controls, int count)
451da177e4SLinus Torvalds {
461da177e4SLinus Torvalds 	int idx, err;
471da177e4SLinus Torvalds 
481da177e4SLinus Torvalds 	for (idx = 0; idx < count; idx++)
491da177e4SLinus Torvalds 		if ((err = snd_ctl_add(ac97->bus->card, snd_ac97_cnew(&controls[idx], ac97))) < 0)
501da177e4SLinus Torvalds 			return err;
511da177e4SLinus Torvalds 	return 0;
521da177e4SLinus Torvalds }
531da177e4SLinus Torvalds 
541da177e4SLinus Torvalds /* set to the page, update bits and restore the page */
55ee42381eSTakashi Iwai static int ac97_update_bits_page(struct snd_ac97 *ac97, unsigned short reg, unsigned short mask, unsigned short value, unsigned short page)
561da177e4SLinus Torvalds {
571da177e4SLinus Torvalds 	unsigned short page_save;
581da177e4SLinus Torvalds 	int ret;
591da177e4SLinus Torvalds 
6062932df8SIngo Molnar 	mutex_lock(&ac97->page_mutex);
611da177e4SLinus Torvalds 	page_save = snd_ac97_read(ac97, AC97_INT_PAGING) & AC97_PAGE_MASK;
621da177e4SLinus Torvalds 	snd_ac97_update_bits(ac97, AC97_INT_PAGING, AC97_PAGE_MASK, page);
631da177e4SLinus Torvalds 	ret = snd_ac97_update_bits(ac97, reg, mask, value);
641da177e4SLinus Torvalds 	snd_ac97_update_bits(ac97, AC97_INT_PAGING, AC97_PAGE_MASK, page_save);
6562932df8SIngo Molnar 	mutex_unlock(&ac97->page_mutex); /* unlock paging */
661da177e4SLinus Torvalds 	return ret;
671da177e4SLinus Torvalds }
681da177e4SLinus Torvalds 
69eb8caf30STakashi Iwai /*
70eb8caf30STakashi Iwai  * shared line-in/mic controls
71eb8caf30STakashi Iwai  */
72ee42381eSTakashi Iwai static int ac97_enum_text_info(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_info *uinfo,
73eb8caf30STakashi Iwai 			       const char **texts, unsigned int nums)
74eb8caf30STakashi Iwai {
75eb8caf30STakashi Iwai 	uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED;
76eb8caf30STakashi Iwai 	uinfo->count = 1;
77eb8caf30STakashi Iwai 	uinfo->value.enumerated.items = nums;
78eb8caf30STakashi Iwai 	if (uinfo->value.enumerated.item > nums - 1)
79eb8caf30STakashi Iwai 		uinfo->value.enumerated.item = nums - 1;
80eb8caf30STakashi Iwai 	strcpy(uinfo->value.enumerated.name, texts[uinfo->value.enumerated.item]);
81eb8caf30STakashi Iwai 	return 0;
82eb8caf30STakashi Iwai }
83eb8caf30STakashi Iwai 
84ee42381eSTakashi Iwai static int ac97_surround_jack_mode_info(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_info *uinfo)
85eb8caf30STakashi Iwai {
86eb8caf30STakashi Iwai 	static const char *texts[] = { "Shared", "Independent" };
87eb8caf30STakashi Iwai 	return ac97_enum_text_info(kcontrol, uinfo, texts, 2);
88eb8caf30STakashi Iwai }
89eb8caf30STakashi Iwai 
90ee42381eSTakashi Iwai static int ac97_surround_jack_mode_get(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
91eb8caf30STakashi Iwai {
92ee42381eSTakashi Iwai 	struct snd_ac97 *ac97 = snd_kcontrol_chip(kcontrol);
93eb8caf30STakashi Iwai 
94eb8caf30STakashi Iwai 	ucontrol->value.enumerated.item[0] = ac97->indep_surround;
95eb8caf30STakashi Iwai 	return 0;
96eb8caf30STakashi Iwai }
97eb8caf30STakashi Iwai 
98ee42381eSTakashi Iwai static int ac97_surround_jack_mode_put(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
99eb8caf30STakashi Iwai {
100ee42381eSTakashi Iwai 	struct snd_ac97 *ac97 = snd_kcontrol_chip(kcontrol);
101eb8caf30STakashi Iwai 	unsigned char indep = !!ucontrol->value.enumerated.item[0];
102eb8caf30STakashi Iwai 
103eb8caf30STakashi Iwai 	if (indep != ac97->indep_surround) {
104eb8caf30STakashi Iwai 		ac97->indep_surround = indep;
105eb8caf30STakashi Iwai 		if (ac97->build_ops->update_jacks)
106eb8caf30STakashi Iwai 			ac97->build_ops->update_jacks(ac97);
107eb8caf30STakashi Iwai 		return 1;
108eb8caf30STakashi Iwai 	}
109eb8caf30STakashi Iwai 	return 0;
110eb8caf30STakashi Iwai }
111eb8caf30STakashi Iwai 
112ee42381eSTakashi Iwai static int ac97_channel_mode_info(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_info *uinfo)
113eb8caf30STakashi Iwai {
114eb8caf30STakashi Iwai 	static const char *texts[] = { "2ch", "4ch", "6ch" };
115eb8caf30STakashi Iwai 	if (kcontrol->private_value)
116eb8caf30STakashi Iwai 		return ac97_enum_text_info(kcontrol, uinfo, texts, 2); /* 4ch only */
117eb8caf30STakashi Iwai 	return ac97_enum_text_info(kcontrol, uinfo, texts, 3);
118eb8caf30STakashi Iwai }
119eb8caf30STakashi Iwai 
120ee42381eSTakashi Iwai static int ac97_channel_mode_get(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
121eb8caf30STakashi Iwai {
122ee42381eSTakashi Iwai 	struct snd_ac97 *ac97 = snd_kcontrol_chip(kcontrol);
123eb8caf30STakashi Iwai 
124eb8caf30STakashi Iwai 	ucontrol->value.enumerated.item[0] = ac97->channel_mode;
125eb8caf30STakashi Iwai 	return 0;
126eb8caf30STakashi Iwai }
127eb8caf30STakashi Iwai 
128ee42381eSTakashi Iwai static int ac97_channel_mode_put(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
129eb8caf30STakashi Iwai {
130ee42381eSTakashi Iwai 	struct snd_ac97 *ac97 = snd_kcontrol_chip(kcontrol);
131eb8caf30STakashi Iwai 	unsigned char mode = ucontrol->value.enumerated.item[0];
132eb8caf30STakashi Iwai 
133eb8caf30STakashi Iwai 	if (mode != ac97->channel_mode) {
134eb8caf30STakashi Iwai 		ac97->channel_mode = mode;
135eb8caf30STakashi Iwai 		if (ac97->build_ops->update_jacks)
136eb8caf30STakashi Iwai 			ac97->build_ops->update_jacks(ac97);
137eb8caf30STakashi Iwai 		return 1;
138eb8caf30STakashi Iwai 	}
139eb8caf30STakashi Iwai 	return 0;
140eb8caf30STakashi Iwai }
141eb8caf30STakashi Iwai 
142eb8caf30STakashi Iwai #define AC97_SURROUND_JACK_MODE_CTL \
143eb8caf30STakashi Iwai 	{ \
144eb8caf30STakashi Iwai 		.iface	= SNDRV_CTL_ELEM_IFACE_MIXER, \
145eb8caf30STakashi Iwai 		.name	= "Surround Jack Mode", \
146eb8caf30STakashi Iwai 		.info = ac97_surround_jack_mode_info, \
147eb8caf30STakashi Iwai 		.get = ac97_surround_jack_mode_get, \
148eb8caf30STakashi Iwai 		.put = ac97_surround_jack_mode_put, \
149eb8caf30STakashi Iwai 	}
150eb8caf30STakashi Iwai #define AC97_CHANNEL_MODE_CTL \
151eb8caf30STakashi Iwai 	{ \
152eb8caf30STakashi Iwai 		.iface	= SNDRV_CTL_ELEM_IFACE_MIXER, \
153eb8caf30STakashi Iwai 		.name	= "Channel Mode", \
154eb8caf30STakashi Iwai 		.info = ac97_channel_mode_info, \
155eb8caf30STakashi Iwai 		.get = ac97_channel_mode_get, \
156eb8caf30STakashi Iwai 		.put = ac97_channel_mode_put, \
157eb8caf30STakashi Iwai 	}
158eb8caf30STakashi Iwai #define AC97_CHANNEL_MODE_4CH_CTL \
159eb8caf30STakashi Iwai 	{ \
160eb8caf30STakashi Iwai 		.iface	= SNDRV_CTL_ELEM_IFACE_MIXER, \
161eb8caf30STakashi Iwai 		.name	= "Channel Mode", \
162eb8caf30STakashi Iwai 		.info = ac97_channel_mode_info, \
163eb8caf30STakashi Iwai 		.get = ac97_channel_mode_get, \
164eb8caf30STakashi Iwai 		.put = ac97_channel_mode_put, \
165eb8caf30STakashi Iwai 		.private_value = 1, \
166eb8caf30STakashi Iwai 	}
167eb8caf30STakashi Iwai 
168ee42381eSTakashi Iwai static inline int is_surround_on(struct snd_ac97 *ac97)
1694525c9f3STakashi Iwai {
1704525c9f3STakashi Iwai 	return ac97->channel_mode >= 1;
1714525c9f3STakashi Iwai }
1724525c9f3STakashi Iwai 
173ee42381eSTakashi Iwai static inline int is_clfe_on(struct snd_ac97 *ac97)
1744525c9f3STakashi Iwai {
175eb9b4142STakashi Iwai 	return ac97->channel_mode >= 2;
1764525c9f3STakashi Iwai }
1774525c9f3STakashi Iwai 
178ee42381eSTakashi Iwai static inline int is_shared_linein(struct snd_ac97 *ac97)
179eb8caf30STakashi Iwai {
1804525c9f3STakashi Iwai 	return ! ac97->indep_surround && is_surround_on(ac97);
181eb8caf30STakashi Iwai }
182eb8caf30STakashi Iwai 
183ee42381eSTakashi Iwai static inline int is_shared_micin(struct snd_ac97 *ac97)
184eb8caf30STakashi Iwai {
1854525c9f3STakashi Iwai 	return ! ac97->indep_surround && is_clfe_on(ac97);
186eb8caf30STakashi Iwai }
187eb8caf30STakashi Iwai 
188eb8caf30STakashi Iwai 
1891da177e4SLinus Torvalds /* The following snd_ac97_ymf753_... items added by David Shust (dshust@shustring.com) */
1901da177e4SLinus Torvalds 
1911da177e4SLinus Torvalds /* It is possible to indicate to the Yamaha YMF753 the type of speakers being used. */
192ee42381eSTakashi Iwai static int snd_ac97_ymf753_info_speaker(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_info *uinfo)
1931da177e4SLinus Torvalds {
1941da177e4SLinus Torvalds 	static char *texts[3] = {
1951da177e4SLinus Torvalds 		"Standard", "Small", "Smaller"
1961da177e4SLinus Torvalds 	};
1971da177e4SLinus Torvalds 
1981da177e4SLinus Torvalds 	uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED;
1991da177e4SLinus Torvalds 	uinfo->count = 1;
2001da177e4SLinus Torvalds 	uinfo->value.enumerated.items = 3;
2011da177e4SLinus Torvalds 	if (uinfo->value.enumerated.item > 2)
2021da177e4SLinus Torvalds 		uinfo->value.enumerated.item = 2;
2031da177e4SLinus Torvalds 	strcpy(uinfo->value.enumerated.name, texts[uinfo->value.enumerated.item]);
2041da177e4SLinus Torvalds 	return 0;
2051da177e4SLinus Torvalds }
2061da177e4SLinus Torvalds 
207ee42381eSTakashi Iwai static int snd_ac97_ymf753_get_speaker(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
2081da177e4SLinus Torvalds {
209ee42381eSTakashi Iwai 	struct snd_ac97 *ac97 = snd_kcontrol_chip(kcontrol);
2101da177e4SLinus Torvalds 	unsigned short val;
2111da177e4SLinus Torvalds 
2121da177e4SLinus Torvalds 	val = ac97->regs[AC97_YMF753_3D_MODE_SEL];
2131da177e4SLinus Torvalds 	val = (val >> 10) & 3;
2141da177e4SLinus Torvalds 	if (val > 0)    /* 0 = invalid */
2151da177e4SLinus Torvalds 		val--;
2161da177e4SLinus Torvalds 	ucontrol->value.enumerated.item[0] = val;
2171da177e4SLinus Torvalds 	return 0;
2181da177e4SLinus Torvalds }
2191da177e4SLinus Torvalds 
220ee42381eSTakashi Iwai static int snd_ac97_ymf753_put_speaker(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
2211da177e4SLinus Torvalds {
222ee42381eSTakashi Iwai 	struct snd_ac97 *ac97 = snd_kcontrol_chip(kcontrol);
2231da177e4SLinus Torvalds 	unsigned short val;
2241da177e4SLinus Torvalds 
2251da177e4SLinus Torvalds 	if (ucontrol->value.enumerated.item[0] > 2)
2261da177e4SLinus Torvalds 		return -EINVAL;
2271da177e4SLinus Torvalds 	val = (ucontrol->value.enumerated.item[0] + 1) << 10;
2281da177e4SLinus Torvalds 	return snd_ac97_update(ac97, AC97_YMF753_3D_MODE_SEL, val);
2291da177e4SLinus Torvalds }
2301da177e4SLinus Torvalds 
231ee42381eSTakashi Iwai static const struct snd_kcontrol_new snd_ac97_ymf753_controls_speaker =
2321da177e4SLinus Torvalds {
2331da177e4SLinus Torvalds 	.iface  = SNDRV_CTL_ELEM_IFACE_MIXER,
2341da177e4SLinus Torvalds 	.name   = "3D Control - Speaker",
2351da177e4SLinus Torvalds 	.info   = snd_ac97_ymf753_info_speaker,
2361da177e4SLinus Torvalds 	.get    = snd_ac97_ymf753_get_speaker,
2371da177e4SLinus Torvalds 	.put    = snd_ac97_ymf753_put_speaker,
2381da177e4SLinus Torvalds };
2391da177e4SLinus Torvalds 
2401da177e4SLinus Torvalds /* It is possible to indicate to the Yamaha YMF753 the source to direct to the S/PDIF output. */
241ee42381eSTakashi Iwai static int snd_ac97_ymf753_spdif_source_info(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_info *uinfo)
2421da177e4SLinus Torvalds {
2431da177e4SLinus Torvalds 	static char *texts[2] = { "AC-Link", "A/D Converter" };
2441da177e4SLinus Torvalds 
2451da177e4SLinus Torvalds 	uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED;
2461da177e4SLinus Torvalds 	uinfo->count = 1;
2471da177e4SLinus Torvalds 	uinfo->value.enumerated.items = 2;
2481da177e4SLinus Torvalds 	if (uinfo->value.enumerated.item > 1)
2491da177e4SLinus Torvalds 		uinfo->value.enumerated.item = 1;
2501da177e4SLinus Torvalds 	strcpy(uinfo->value.enumerated.name, texts[uinfo->value.enumerated.item]);
2511da177e4SLinus Torvalds 	return 0;
2521da177e4SLinus Torvalds }
2531da177e4SLinus Torvalds 
254ee42381eSTakashi Iwai static int snd_ac97_ymf753_spdif_source_get(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
2551da177e4SLinus Torvalds {
256ee42381eSTakashi Iwai 	struct snd_ac97 *ac97 = snd_kcontrol_chip(kcontrol);
2571da177e4SLinus Torvalds 	unsigned short val;
2581da177e4SLinus Torvalds 
2591da177e4SLinus Torvalds 	val = ac97->regs[AC97_YMF753_DIT_CTRL2];
2601da177e4SLinus Torvalds 	ucontrol->value.enumerated.item[0] = (val >> 1) & 1;
2611da177e4SLinus Torvalds 	return 0;
2621da177e4SLinus Torvalds }
2631da177e4SLinus Torvalds 
264ee42381eSTakashi Iwai static int snd_ac97_ymf753_spdif_source_put(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
2651da177e4SLinus Torvalds {
266ee42381eSTakashi Iwai 	struct snd_ac97 *ac97 = snd_kcontrol_chip(kcontrol);
2671da177e4SLinus Torvalds 	unsigned short val;
2681da177e4SLinus Torvalds 
2691da177e4SLinus Torvalds 	if (ucontrol->value.enumerated.item[0] > 1)
2701da177e4SLinus Torvalds 		return -EINVAL;
2711da177e4SLinus Torvalds 	val = ucontrol->value.enumerated.item[0] << 1;
2721da177e4SLinus Torvalds 	return snd_ac97_update_bits(ac97, AC97_YMF753_DIT_CTRL2, 0x0002, val);
2731da177e4SLinus Torvalds }
2741da177e4SLinus Torvalds 
2751da177e4SLinus Torvalds /* The AC'97 spec states that the S/PDIF signal is to be output at pin 48.
2761da177e4SLinus Torvalds    The YMF753 will output the S/PDIF signal to pin 43, 47 (EAPD), or 48.
2771da177e4SLinus Torvalds    By default, no output pin is selected, and the S/PDIF signal is not output.
2781da177e4SLinus Torvalds    There is also a bit to mute S/PDIF output in a vendor-specific register. */
279ee42381eSTakashi Iwai static int snd_ac97_ymf753_spdif_output_pin_info(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_info *uinfo)
2801da177e4SLinus Torvalds {
2811da177e4SLinus Torvalds 	static char *texts[3] = { "Disabled", "Pin 43", "Pin 48" };
2821da177e4SLinus Torvalds 
2831da177e4SLinus Torvalds 	uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED;
2841da177e4SLinus Torvalds 	uinfo->count = 1;
2851da177e4SLinus Torvalds 	uinfo->value.enumerated.items = 3;
2861da177e4SLinus Torvalds 	if (uinfo->value.enumerated.item > 2)
2871da177e4SLinus Torvalds 		uinfo->value.enumerated.item = 2;
2881da177e4SLinus Torvalds 	strcpy(uinfo->value.enumerated.name, texts[uinfo->value.enumerated.item]);
2891da177e4SLinus Torvalds 	return 0;
2901da177e4SLinus Torvalds }
2911da177e4SLinus Torvalds 
292ee42381eSTakashi Iwai static int snd_ac97_ymf753_spdif_output_pin_get(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
2931da177e4SLinus Torvalds {
294ee42381eSTakashi Iwai 	struct snd_ac97 *ac97 = snd_kcontrol_chip(kcontrol);
2951da177e4SLinus Torvalds 	unsigned short val;
2961da177e4SLinus Torvalds 
2971da177e4SLinus Torvalds 	val = ac97->regs[AC97_YMF753_DIT_CTRL2];
2981da177e4SLinus Torvalds 	ucontrol->value.enumerated.item[0] = (val & 0x0008) ? 2 : (val & 0x0020) ? 1 : 0;
2991da177e4SLinus Torvalds 	return 0;
3001da177e4SLinus Torvalds }
3011da177e4SLinus Torvalds 
302ee42381eSTakashi Iwai static int snd_ac97_ymf753_spdif_output_pin_put(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
3031da177e4SLinus Torvalds {
304ee42381eSTakashi Iwai 	struct snd_ac97 *ac97 = snd_kcontrol_chip(kcontrol);
3051da177e4SLinus Torvalds 	unsigned short val;
3061da177e4SLinus Torvalds 
3071da177e4SLinus Torvalds 	if (ucontrol->value.enumerated.item[0] > 2)
3081da177e4SLinus Torvalds 		return -EINVAL;
3091da177e4SLinus Torvalds 	val = (ucontrol->value.enumerated.item[0] == 2) ? 0x0008 :
3101da177e4SLinus Torvalds 	      (ucontrol->value.enumerated.item[0] == 1) ? 0x0020 : 0;
3111da177e4SLinus Torvalds 	return snd_ac97_update_bits(ac97, AC97_YMF753_DIT_CTRL2, 0x0028, val);
3121da177e4SLinus Torvalds 	/* The following can be used to direct S/PDIF output to pin 47 (EAPD).
3131da177e4SLinus Torvalds 	   snd_ac97_write_cache(ac97, 0x62, snd_ac97_read(ac97, 0x62) | 0x0008); */
3141da177e4SLinus Torvalds }
3151da177e4SLinus Torvalds 
316ee42381eSTakashi Iwai static const struct snd_kcontrol_new snd_ac97_ymf753_controls_spdif[3] = {
3171da177e4SLinus Torvalds 	{
3181da177e4SLinus Torvalds 		.iface	= SNDRV_CTL_ELEM_IFACE_MIXER,
3191da177e4SLinus Torvalds 		.name	= SNDRV_CTL_NAME_IEC958("",PLAYBACK,NONE) "Source",
3201da177e4SLinus Torvalds 		.info	= snd_ac97_ymf753_spdif_source_info,
3211da177e4SLinus Torvalds 		.get	= snd_ac97_ymf753_spdif_source_get,
3221da177e4SLinus Torvalds 		.put	= snd_ac97_ymf753_spdif_source_put,
3231da177e4SLinus Torvalds 	},
3241da177e4SLinus Torvalds 	{
3251da177e4SLinus Torvalds 		.iface	= SNDRV_CTL_ELEM_IFACE_MIXER,
3261da177e4SLinus Torvalds 		.name	= SNDRV_CTL_NAME_IEC958("",PLAYBACK,NONE) "Output Pin",
3271da177e4SLinus Torvalds 		.info	= snd_ac97_ymf753_spdif_output_pin_info,
3281da177e4SLinus Torvalds 		.get	= snd_ac97_ymf753_spdif_output_pin_get,
3291da177e4SLinus Torvalds 		.put	= snd_ac97_ymf753_spdif_output_pin_put,
3301da177e4SLinus Torvalds 	},
3311da177e4SLinus Torvalds 	AC97_SINGLE(SNDRV_CTL_NAME_IEC958("",NONE,NONE) "Mute", AC97_YMF753_DIT_CTRL2, 2, 1, 1)
3321da177e4SLinus Torvalds };
3331da177e4SLinus Torvalds 
334ee42381eSTakashi Iwai static int patch_yamaha_ymf753_3d(struct snd_ac97 * ac97)
3351da177e4SLinus Torvalds {
336ee42381eSTakashi Iwai 	struct snd_kcontrol *kctl;
3371da177e4SLinus Torvalds 	int err;
3381da177e4SLinus Torvalds 
3391da177e4SLinus Torvalds 	if ((err = snd_ctl_add(ac97->bus->card, kctl = snd_ac97_cnew(&snd_ac97_controls_3d[0], ac97))) < 0)
3401da177e4SLinus Torvalds 		return err;
3411da177e4SLinus Torvalds 	strcpy(kctl->id.name, "3D Control - Wide");
3421da177e4SLinus Torvalds 	kctl->private_value = AC97_SINGLE_VALUE(AC97_3D_CONTROL, 9, 7, 0);
3431da177e4SLinus Torvalds 	snd_ac97_write_cache(ac97, AC97_3D_CONTROL, 0x0000);
3441da177e4SLinus Torvalds 	if ((err = snd_ctl_add(ac97->bus->card, snd_ac97_cnew(&snd_ac97_ymf753_controls_speaker, ac97))) < 0)
3451da177e4SLinus Torvalds 		return err;
3461da177e4SLinus Torvalds 	snd_ac97_write_cache(ac97, AC97_YMF753_3D_MODE_SEL, 0x0c00);
3471da177e4SLinus Torvalds 	return 0;
3481da177e4SLinus Torvalds }
3491da177e4SLinus Torvalds 
350ee42381eSTakashi Iwai static int patch_yamaha_ymf753_post_spdif(struct snd_ac97 * ac97)
3511da177e4SLinus Torvalds {
3521da177e4SLinus Torvalds 	int err;
3531da177e4SLinus Torvalds 
3541da177e4SLinus Torvalds 	if ((err = patch_build_controls(ac97, snd_ac97_ymf753_controls_spdif, ARRAY_SIZE(snd_ac97_ymf753_controls_spdif))) < 0)
3551da177e4SLinus Torvalds 		return err;
3561da177e4SLinus Torvalds 	return 0;
3571da177e4SLinus Torvalds }
3581da177e4SLinus Torvalds 
3591da177e4SLinus Torvalds static struct snd_ac97_build_ops patch_yamaha_ymf753_ops = {
3601da177e4SLinus Torvalds 	.build_3d	= patch_yamaha_ymf753_3d,
3611da177e4SLinus Torvalds 	.build_post_spdif = patch_yamaha_ymf753_post_spdif
3621da177e4SLinus Torvalds };
3631da177e4SLinus Torvalds 
364ee42381eSTakashi Iwai int patch_yamaha_ymf753(struct snd_ac97 * ac97)
3651da177e4SLinus Torvalds {
3661da177e4SLinus Torvalds 	/* Patch for Yamaha YMF753, Copyright (c) by David Shust, dshust@shustring.com.
3671da177e4SLinus Torvalds 	   This chip has nonstandard and extended behaviour with regard to its S/PDIF output.
3681da177e4SLinus Torvalds 	   The AC'97 spec states that the S/PDIF signal is to be output at pin 48.
3691da177e4SLinus Torvalds 	   The YMF753 will ouput the S/PDIF signal to pin 43, 47 (EAPD), or 48.
3701da177e4SLinus Torvalds 	   By default, no output pin is selected, and the S/PDIF signal is not output.
3711da177e4SLinus Torvalds 	   There is also a bit to mute S/PDIF output in a vendor-specific register.
3721da177e4SLinus Torvalds 	*/
3731da177e4SLinus Torvalds 	ac97->build_ops = &patch_yamaha_ymf753_ops;
3741da177e4SLinus Torvalds 	ac97->caps |= AC97_BC_BASS_TREBLE;
3751da177e4SLinus Torvalds 	ac97->caps |= 0x04 << 10; /* Yamaha 3D enhancement */
3761da177e4SLinus Torvalds 	return 0;
3771da177e4SLinus Torvalds }
3781da177e4SLinus Torvalds 
3791da177e4SLinus Torvalds /*
3801da177e4SLinus Torvalds  * May 2, 2003 Liam Girdwood <liam.girdwood@wolfsonmicro.com>
3811da177e4SLinus Torvalds  *  removed broken wolfson00 patch.
3821da177e4SLinus Torvalds  *  added support for WM9705,WM9708,WM9709,WM9710,WM9711,WM9712 and WM9717.
3831da177e4SLinus Torvalds  */
3841da177e4SLinus Torvalds 
385ee42381eSTakashi Iwai static const struct snd_kcontrol_new wm97xx_snd_ac97_controls[] = {
3863998b70fSLiam Girdwood AC97_DOUBLE("Front Playback Volume", AC97_WM97XX_FMIXER_VOL, 8, 0, 31, 1),
3873998b70fSLiam Girdwood AC97_SINGLE("Front Playback Switch", AC97_WM97XX_FMIXER_VOL, 15, 1, 1),
3883998b70fSLiam Girdwood };
3893998b70fSLiam Girdwood 
390ee42381eSTakashi Iwai static int patch_wolfson_wm9703_specific(struct snd_ac97 * ac97)
3911da177e4SLinus Torvalds {
3921da177e4SLinus Torvalds 	/* This is known to work for the ViewSonic ViewPad 1000
3933998b70fSLiam Girdwood 	 * Randolph Bentson <bentson@holmsjoen.com>
3943998b70fSLiam Girdwood 	 * WM9703/9707/9708/9717
3953998b70fSLiam Girdwood 	 */
3963998b70fSLiam Girdwood 	int err, i;
3971da177e4SLinus Torvalds 
3983998b70fSLiam Girdwood 	for (i = 0; i < ARRAY_SIZE(wm97xx_snd_ac97_controls); i++) {
3993998b70fSLiam Girdwood 		if ((err = snd_ctl_add(ac97->bus->card, snd_ac97_cnew(&wm97xx_snd_ac97_controls[i], ac97))) < 0)
4003998b70fSLiam Girdwood 			return err;
4013998b70fSLiam Girdwood 	}
4021da177e4SLinus Torvalds 	snd_ac97_write_cache(ac97,  AC97_WM97XX_FMIXER_VOL, 0x0808);
4031da177e4SLinus Torvalds 	return 0;
4041da177e4SLinus Torvalds }
4051da177e4SLinus Torvalds 
4063998b70fSLiam Girdwood static struct snd_ac97_build_ops patch_wolfson_wm9703_ops = {
4073998b70fSLiam Girdwood 	.build_specific = patch_wolfson_wm9703_specific,
4083998b70fSLiam Girdwood };
4093998b70fSLiam Girdwood 
410ee42381eSTakashi Iwai int patch_wolfson03(struct snd_ac97 * ac97)
4113998b70fSLiam Girdwood {
4123998b70fSLiam Girdwood 	ac97->build_ops = &patch_wolfson_wm9703_ops;
4133998b70fSLiam Girdwood 	return 0;
4143998b70fSLiam Girdwood }
4153998b70fSLiam Girdwood 
416ee42381eSTakashi Iwai static const struct snd_kcontrol_new wm9704_snd_ac97_controls[] = {
4173998b70fSLiam Girdwood AC97_DOUBLE("Front Playback Volume", AC97_WM97XX_FMIXER_VOL, 8, 0, 31, 1),
4183998b70fSLiam Girdwood AC97_SINGLE("Front Playback Switch", AC97_WM97XX_FMIXER_VOL, 15, 1, 1),
4193998b70fSLiam Girdwood AC97_DOUBLE("Rear Playback Volume", AC97_WM9704_RMIXER_VOL, 8, 0, 31, 1),
4203998b70fSLiam Girdwood AC97_SINGLE("Rear Playback Switch", AC97_WM9704_RMIXER_VOL, 15, 1, 1),
4213998b70fSLiam Girdwood AC97_DOUBLE("Rear DAC Volume", AC97_WM9704_RPCM_VOL, 8, 0, 31, 1),
4223998b70fSLiam Girdwood AC97_DOUBLE("Surround Volume", AC97_SURROUND_MASTER, 8, 0, 31, 1),
4233998b70fSLiam Girdwood };
4243998b70fSLiam Girdwood 
425ee42381eSTakashi Iwai static int patch_wolfson_wm9704_specific(struct snd_ac97 * ac97)
4263998b70fSLiam Girdwood {
4273998b70fSLiam Girdwood 	int err, i;
4283998b70fSLiam Girdwood 	for (i = 0; i < ARRAY_SIZE(wm9704_snd_ac97_controls); i++) {
4293998b70fSLiam Girdwood 		if ((err = snd_ctl_add(ac97->bus->card, snd_ac97_cnew(&wm9704_snd_ac97_controls[i], ac97))) < 0)
4303998b70fSLiam Girdwood 			return err;
4313998b70fSLiam Girdwood 	}
4323998b70fSLiam Girdwood 	/* patch for DVD noise */
4333998b70fSLiam Girdwood 	snd_ac97_write_cache(ac97, AC97_WM9704_TEST, 0x0200);
4343998b70fSLiam Girdwood 	return 0;
4353998b70fSLiam Girdwood }
4363998b70fSLiam Girdwood 
4373998b70fSLiam Girdwood static struct snd_ac97_build_ops patch_wolfson_wm9704_ops = {
4383998b70fSLiam Girdwood 	.build_specific = patch_wolfson_wm9704_specific,
4393998b70fSLiam Girdwood };
4403998b70fSLiam Girdwood 
441ee42381eSTakashi Iwai int patch_wolfson04(struct snd_ac97 * ac97)
4421da177e4SLinus Torvalds {
4433998b70fSLiam Girdwood 	/* WM9704M/9704Q */
4443998b70fSLiam Girdwood 	ac97->build_ops = &patch_wolfson_wm9704_ops;
4451da177e4SLinus Torvalds 	return 0;
4461da177e4SLinus Torvalds }
4471da177e4SLinus Torvalds 
448ee42381eSTakashi Iwai static int patch_wolfson_wm9705_specific(struct snd_ac97 * ac97)
4493998b70fSLiam Girdwood {
4503998b70fSLiam Girdwood 	int err, i;
4513998b70fSLiam Girdwood 	for (i = 0; i < ARRAY_SIZE(wm97xx_snd_ac97_controls); i++) {
4523998b70fSLiam Girdwood 		if ((err = snd_ctl_add(ac97->bus->card, snd_ac97_cnew(&wm97xx_snd_ac97_controls[i], ac97))) < 0)
4533998b70fSLiam Girdwood 			return err;
4543998b70fSLiam Girdwood 	}
4553998b70fSLiam Girdwood 	snd_ac97_write_cache(ac97,  0x72, 0x0808);
4563998b70fSLiam Girdwood 	return 0;
4573998b70fSLiam Girdwood }
4583998b70fSLiam Girdwood 
4593998b70fSLiam Girdwood static struct snd_ac97_build_ops patch_wolfson_wm9705_ops = {
4603998b70fSLiam Girdwood 	.build_specific = patch_wolfson_wm9705_specific,
4613998b70fSLiam Girdwood };
4623998b70fSLiam Girdwood 
463ee42381eSTakashi Iwai int patch_wolfson05(struct snd_ac97 * ac97)
4641da177e4SLinus Torvalds {
4653998b70fSLiam Girdwood 	/* WM9705, WM9710 */
4663998b70fSLiam Girdwood 	ac97->build_ops = &patch_wolfson_wm9705_ops;
4671da177e4SLinus Torvalds 	return 0;
4681da177e4SLinus Torvalds }
4691da177e4SLinus Torvalds 
4703998b70fSLiam Girdwood static const char* wm9711_alc_select[] = {"None", "Left", "Right", "Stereo"};
4713998b70fSLiam Girdwood static const char* wm9711_alc_mix[] = {"Stereo", "Right", "Left", "None"};
4723998b70fSLiam Girdwood static const char* wm9711_out3_src[] = {"Left", "VREF", "Left + Right", "Mono"};
4733998b70fSLiam Girdwood static const char* wm9711_out3_lrsrc[] = {"Master Mix", "Headphone Mix"};
4743998b70fSLiam Girdwood static const char* wm9711_rec_adc[] = {"Stereo", "Left", "Right", "Mute"};
4753998b70fSLiam Girdwood static const char* wm9711_base[] = {"Linear Control", "Adaptive Boost"};
4763998b70fSLiam Girdwood static const char* wm9711_rec_gain[] = {"+1.5dB Steps", "+0.75dB Steps"};
4773998b70fSLiam Girdwood static const char* wm9711_mic[] = {"Mic 1", "Differential", "Mic 2", "Stereo"};
4783998b70fSLiam Girdwood static const char* wm9711_rec_sel[] =
4793998b70fSLiam Girdwood 	{"Mic 1", "NC", "NC", "Master Mix", "Line", "Headphone Mix", "Phone Mix", "Phone"};
4803998b70fSLiam Girdwood static const char* wm9711_ng_type[] = {"Constant Gain", "Mute"};
4813998b70fSLiam Girdwood 
4823998b70fSLiam Girdwood static const struct ac97_enum wm9711_enum[] = {
4833998b70fSLiam Girdwood AC97_ENUM_SINGLE(AC97_PCI_SVID, 14, 4, wm9711_alc_select),
4843998b70fSLiam Girdwood AC97_ENUM_SINGLE(AC97_VIDEO, 10, 4, wm9711_alc_mix),
4853998b70fSLiam Girdwood AC97_ENUM_SINGLE(AC97_AUX, 9, 4, wm9711_out3_src),
4863998b70fSLiam Girdwood AC97_ENUM_SINGLE(AC97_AUX, 8, 2, wm9711_out3_lrsrc),
4873998b70fSLiam Girdwood AC97_ENUM_SINGLE(AC97_REC_SEL, 12, 4, wm9711_rec_adc),
4883998b70fSLiam Girdwood AC97_ENUM_SINGLE(AC97_MASTER_TONE, 15, 2, wm9711_base),
4893998b70fSLiam Girdwood AC97_ENUM_DOUBLE(AC97_REC_GAIN, 14, 6, 2, wm9711_rec_gain),
4903998b70fSLiam Girdwood AC97_ENUM_SINGLE(AC97_MIC, 5, 4, wm9711_mic),
4913998b70fSLiam Girdwood AC97_ENUM_DOUBLE(AC97_REC_SEL, 8, 0, 8, wm9711_rec_sel),
4923998b70fSLiam Girdwood AC97_ENUM_SINGLE(AC97_PCI_SVID, 5, 2, wm9711_ng_type),
4933998b70fSLiam Girdwood };
4943998b70fSLiam Girdwood 
495ee42381eSTakashi Iwai static const struct snd_kcontrol_new wm9711_snd_ac97_controls[] = {
4963998b70fSLiam Girdwood AC97_SINGLE("ALC Target Volume", AC97_CODEC_CLASS_REV, 12, 15, 0),
4973998b70fSLiam Girdwood AC97_SINGLE("ALC Hold Time", AC97_CODEC_CLASS_REV, 8, 15, 0),
4983998b70fSLiam Girdwood AC97_SINGLE("ALC Decay Time", AC97_CODEC_CLASS_REV, 4, 15, 0),
4993998b70fSLiam Girdwood AC97_SINGLE("ALC Attack Time", AC97_CODEC_CLASS_REV, 0, 15, 0),
5003998b70fSLiam Girdwood AC97_ENUM("ALC Function", wm9711_enum[0]),
5013998b70fSLiam Girdwood AC97_SINGLE("ALC Max Volume", AC97_PCI_SVID, 11, 7, 1),
5023998b70fSLiam Girdwood AC97_SINGLE("ALC ZC Timeout", AC97_PCI_SVID, 9, 3, 1),
5033998b70fSLiam Girdwood AC97_SINGLE("ALC ZC Switch", AC97_PCI_SVID, 8, 1, 0),
5043998b70fSLiam Girdwood AC97_SINGLE("ALC NG Switch", AC97_PCI_SVID, 7, 1, 0),
5053998b70fSLiam Girdwood AC97_ENUM("ALC NG Type", wm9711_enum[9]),
5063998b70fSLiam Girdwood AC97_SINGLE("ALC NG Threshold", AC97_PCI_SVID, 0, 31, 1),
5073998b70fSLiam Girdwood 
5083998b70fSLiam Girdwood AC97_SINGLE("Side Tone Switch", AC97_VIDEO, 15, 1, 1),
5093998b70fSLiam Girdwood AC97_SINGLE("Side Tone Volume", AC97_VIDEO, 12, 7, 1),
5103998b70fSLiam Girdwood AC97_ENUM("ALC Headphone Mux", wm9711_enum[1]),
5113998b70fSLiam Girdwood AC97_SINGLE("ALC Headphone Volume", AC97_VIDEO, 7, 7, 1),
5123998b70fSLiam Girdwood 
5133998b70fSLiam Girdwood AC97_SINGLE("Out3 Switch", AC97_AUX, 15, 1, 1),
5143998b70fSLiam Girdwood AC97_SINGLE("Out3 ZC Switch", AC97_AUX, 7, 1, 1),
5153998b70fSLiam Girdwood AC97_ENUM("Out3 Mux", wm9711_enum[2]),
5163998b70fSLiam Girdwood AC97_ENUM("Out3 LR Mux", wm9711_enum[3]),
5173998b70fSLiam Girdwood AC97_SINGLE("Out3 Volume", AC97_AUX, 0, 31, 1),
5183998b70fSLiam Girdwood 
5193998b70fSLiam Girdwood AC97_SINGLE("Beep to Headphone Switch", AC97_PC_BEEP, 15, 1, 1),
5203998b70fSLiam Girdwood AC97_SINGLE("Beep to Headphone Volume", AC97_PC_BEEP, 12, 7, 1),
5213998b70fSLiam Girdwood AC97_SINGLE("Beep to Side Tone Switch", AC97_PC_BEEP, 11, 1, 1),
5223998b70fSLiam Girdwood AC97_SINGLE("Beep to Side Tone Volume", AC97_PC_BEEP, 8, 7, 1),
5233998b70fSLiam Girdwood AC97_SINGLE("Beep to Phone Switch", AC97_PC_BEEP, 7, 1, 1),
5243998b70fSLiam Girdwood AC97_SINGLE("Beep to Phone Volume", AC97_PC_BEEP, 4, 7, 1),
5253998b70fSLiam Girdwood 
5263998b70fSLiam Girdwood AC97_SINGLE("Aux to Headphone Switch", AC97_CD, 15, 1, 1),
5273998b70fSLiam Girdwood AC97_SINGLE("Aux to Headphone Volume", AC97_CD, 12, 7, 1),
5283998b70fSLiam Girdwood AC97_SINGLE("Aux to Side Tone Switch", AC97_CD, 11, 1, 1),
5293998b70fSLiam Girdwood AC97_SINGLE("Aux to Side Tone Volume", AC97_CD, 8, 7, 1),
5303998b70fSLiam Girdwood AC97_SINGLE("Aux to Phone Switch", AC97_CD, 7, 1, 1),
5313998b70fSLiam Girdwood AC97_SINGLE("Aux to Phone Volume", AC97_CD, 4, 7, 1),
5323998b70fSLiam Girdwood 
5333998b70fSLiam Girdwood AC97_SINGLE("Phone to Headphone Switch", AC97_PHONE, 15, 1, 1),
5343998b70fSLiam Girdwood AC97_SINGLE("Phone to Master Switch", AC97_PHONE, 14, 1, 1),
5353998b70fSLiam Girdwood 
5363998b70fSLiam Girdwood AC97_SINGLE("Line to Headphone Switch", AC97_LINE, 15, 1, 1),
5373998b70fSLiam Girdwood AC97_SINGLE("Line to Master Switch", AC97_LINE, 14, 1, 1),
5383998b70fSLiam Girdwood AC97_SINGLE("Line to Phone Switch", AC97_LINE, 13, 1, 1),
5393998b70fSLiam Girdwood 
5403998b70fSLiam Girdwood AC97_SINGLE("PCM Playback to Headphone Switch", AC97_PCM, 15, 1, 1),
5413998b70fSLiam Girdwood AC97_SINGLE("PCM Playback to Master Switch", AC97_PCM, 14, 1, 1),
5423998b70fSLiam Girdwood AC97_SINGLE("PCM Playback to Phone Switch", AC97_PCM, 13, 1, 1),
5433998b70fSLiam Girdwood 
5443998b70fSLiam Girdwood AC97_SINGLE("Capture 20dB Boost Switch", AC97_REC_SEL, 14, 1, 0),
5453998b70fSLiam Girdwood AC97_ENUM("Capture to Phone Mux", wm9711_enum[4]),
5463998b70fSLiam Girdwood AC97_SINGLE("Capture to Phone 20dB Boost Switch", AC97_REC_SEL, 11, 1, 1),
5473998b70fSLiam Girdwood AC97_ENUM("Capture Select", wm9711_enum[8]),
5483998b70fSLiam Girdwood 
5493998b70fSLiam Girdwood AC97_SINGLE("3D Upper Cut-off Switch", AC97_3D_CONTROL, 5, 1, 1),
5503998b70fSLiam Girdwood AC97_SINGLE("3D Lower Cut-off Switch", AC97_3D_CONTROL, 4, 1, 1),
5513998b70fSLiam Girdwood 
5523998b70fSLiam Girdwood AC97_ENUM("Bass Control", wm9711_enum[5]),
5533998b70fSLiam Girdwood AC97_SINGLE("Bass Cut-off Switch", AC97_MASTER_TONE, 12, 1, 1),
5543998b70fSLiam Girdwood AC97_SINGLE("Tone Cut-off Switch", AC97_MASTER_TONE, 4, 1, 1),
5553998b70fSLiam Girdwood AC97_SINGLE("Playback Attenuate (-6dB) Switch", AC97_MASTER_TONE, 6, 1, 0),
5563998b70fSLiam Girdwood 
5573998b70fSLiam Girdwood AC97_SINGLE("ADC Switch", AC97_REC_GAIN, 15, 1, 1),
5583998b70fSLiam Girdwood AC97_ENUM("Capture Volume Steps", wm9711_enum[6]),
5593998b70fSLiam Girdwood AC97_DOUBLE("Capture Volume", AC97_REC_GAIN, 8, 0, 15, 1),
5603998b70fSLiam Girdwood AC97_SINGLE("Capture ZC Switch", AC97_REC_GAIN, 7, 1, 0),
5613998b70fSLiam Girdwood 
5623998b70fSLiam Girdwood AC97_SINGLE("Mic 1 to Phone Switch", AC97_MIC, 14, 1, 1),
5633998b70fSLiam Girdwood AC97_SINGLE("Mic 2 to Phone Switch", AC97_MIC, 13, 1, 1),
5643998b70fSLiam Girdwood AC97_ENUM("Mic Select Source", wm9711_enum[7]),
5653998b70fSLiam Girdwood AC97_SINGLE("Mic 1 Volume", AC97_MIC, 8, 32, 1),
566d7f6f115SJames Courtier-Dutton AC97_SINGLE("Mic 20dB Boost Switch", AC97_MIC, 7, 1, 0),
5673998b70fSLiam Girdwood 
5683998b70fSLiam Girdwood AC97_SINGLE("Master ZC Switch", AC97_MASTER, 7, 1, 0),
5693998b70fSLiam Girdwood AC97_SINGLE("Headphone ZC Switch", AC97_HEADPHONE, 7, 1, 0),
5703998b70fSLiam Girdwood AC97_SINGLE("Mono ZC Switch", AC97_MASTER_MONO, 7, 1, 0),
5713998b70fSLiam Girdwood };
5723998b70fSLiam Girdwood 
573ee42381eSTakashi Iwai static int patch_wolfson_wm9711_specific(struct snd_ac97 * ac97)
5743998b70fSLiam Girdwood {
5753998b70fSLiam Girdwood 	int err, i;
5763998b70fSLiam Girdwood 
5773998b70fSLiam Girdwood 	for (i = 0; i < ARRAY_SIZE(wm9711_snd_ac97_controls); i++) {
5783998b70fSLiam Girdwood 		if ((err = snd_ctl_add(ac97->bus->card, snd_ac97_cnew(&wm9711_snd_ac97_controls[i], ac97))) < 0)
5793998b70fSLiam Girdwood 			return err;
5803998b70fSLiam Girdwood 	}
5813998b70fSLiam Girdwood 	snd_ac97_write_cache(ac97,  AC97_CODEC_CLASS_REV, 0x0808);
5823998b70fSLiam Girdwood 	snd_ac97_write_cache(ac97,  AC97_PCI_SVID, 0x0808);
5833998b70fSLiam Girdwood 	snd_ac97_write_cache(ac97,  AC97_VIDEO, 0x0808);
5843998b70fSLiam Girdwood 	snd_ac97_write_cache(ac97,  AC97_AUX, 0x0808);
5853998b70fSLiam Girdwood 	snd_ac97_write_cache(ac97,  AC97_PC_BEEP, 0x0808);
5863998b70fSLiam Girdwood 	snd_ac97_write_cache(ac97,  AC97_CD, 0x0000);
5873998b70fSLiam Girdwood 	return 0;
5883998b70fSLiam Girdwood }
5893998b70fSLiam Girdwood 
5903998b70fSLiam Girdwood static struct snd_ac97_build_ops patch_wolfson_wm9711_ops = {
5913998b70fSLiam Girdwood 	.build_specific = patch_wolfson_wm9711_specific,
5923998b70fSLiam Girdwood };
5933998b70fSLiam Girdwood 
594ee42381eSTakashi Iwai int patch_wolfson11(struct snd_ac97 * ac97)
5951da177e4SLinus Torvalds {
5963998b70fSLiam Girdwood 	/* WM9711, WM9712 */
5973998b70fSLiam Girdwood 	ac97->build_ops = &patch_wolfson_wm9711_ops;
5983998b70fSLiam Girdwood 
5993998b70fSLiam Girdwood 	ac97->flags |= AC97_HAS_NO_REC_GAIN | AC97_STEREO_MUTES | AC97_HAS_NO_MIC |
6003998b70fSLiam Girdwood 		AC97_HAS_NO_PC_BEEP | AC97_HAS_NO_VIDEO | AC97_HAS_NO_CD;
6013998b70fSLiam Girdwood 
6021da177e4SLinus Torvalds 	return 0;
6031da177e4SLinus Torvalds }
6041da177e4SLinus Torvalds 
6051da177e4SLinus Torvalds static const char* wm9713_mic_mixer[] = {"Stereo", "Mic 1", "Mic 2", "Mute"};
6061da177e4SLinus Torvalds static const char* wm9713_rec_mux[] = {"Stereo", "Left", "Right", "Mute"};
6073998b70fSLiam Girdwood static const char* wm9713_rec_src[] =
6083998b70fSLiam Girdwood 	{"Mic 1", "Mic 2", "Line", "Mono In", "Headphone Mix", "Master Mix",
6093998b70fSLiam Girdwood 	"Mono Mix", "Zh"};
6103998b70fSLiam Girdwood static const char* wm9713_rec_gain[] = {"+1.5dB Steps", "+0.75dB Steps"};
6113998b70fSLiam Girdwood static const char* wm9713_alc_select[] = {"None", "Left", "Right", "Stereo"};
6123998b70fSLiam Girdwood static const char* wm9713_mono_pga[] = {"Vmid", "Zh", "Mono Mix", "Inv 1"};
6133998b70fSLiam Girdwood static const char* wm9713_spk_pga[] =
6143998b70fSLiam Girdwood 	{"Vmid", "Zh", "Headphone Mix", "Master Mix", "Inv", "NC", "NC", "NC"};
6153998b70fSLiam Girdwood static const char* wm9713_hp_pga[] = {"Vmid", "Zh", "Headphone Mix", "NC"};
6163998b70fSLiam Girdwood static const char* wm9713_out3_pga[] = {"Vmid", "Zh", "Inv 1", "NC"};
6173998b70fSLiam Girdwood static const char* wm9713_out4_pga[] = {"Vmid", "Zh", "Inv 2", "NC"};
6183998b70fSLiam Girdwood static const char* wm9713_dac_inv[] =
6193998b70fSLiam Girdwood 	{"Off", "Mono Mix", "Master Mix", "Headphone Mix L", "Headphone Mix R",
6203998b70fSLiam Girdwood 	"Headphone Mix Mono", "NC", "Vmid"};
6213998b70fSLiam Girdwood static const char* wm9713_base[] = {"Linear Control", "Adaptive Boost"};
6223998b70fSLiam Girdwood static const char* wm9713_ng_type[] = {"Constant Gain", "Mute"};
6231da177e4SLinus Torvalds 
6241da177e4SLinus Torvalds static const struct ac97_enum wm9713_enum[] = {
6251da177e4SLinus Torvalds AC97_ENUM_SINGLE(AC97_LINE, 3, 4, wm9713_mic_mixer),
6261da177e4SLinus Torvalds AC97_ENUM_SINGLE(AC97_VIDEO, 14, 4, wm9713_rec_mux),
6271da177e4SLinus Torvalds AC97_ENUM_SINGLE(AC97_VIDEO, 9, 4, wm9713_rec_mux),
6283998b70fSLiam Girdwood AC97_ENUM_DOUBLE(AC97_VIDEO, 3, 0, 8, wm9713_rec_src),
6293998b70fSLiam Girdwood AC97_ENUM_DOUBLE(AC97_CD, 14, 6, 2, wm9713_rec_gain),
6303998b70fSLiam Girdwood AC97_ENUM_SINGLE(AC97_PCI_SVID, 14, 4, wm9713_alc_select),
6313998b70fSLiam Girdwood AC97_ENUM_SINGLE(AC97_REC_GAIN, 14, 4, wm9713_mono_pga),
6323998b70fSLiam Girdwood AC97_ENUM_DOUBLE(AC97_REC_GAIN, 11, 8, 8, wm9713_spk_pga),
6333998b70fSLiam Girdwood AC97_ENUM_DOUBLE(AC97_REC_GAIN, 6, 4, 4, wm9713_hp_pga),
6343998b70fSLiam Girdwood AC97_ENUM_SINGLE(AC97_REC_GAIN, 2, 4, wm9713_out3_pga),
6353998b70fSLiam Girdwood AC97_ENUM_SINGLE(AC97_REC_GAIN, 0, 4, wm9713_out4_pga),
6363998b70fSLiam Girdwood AC97_ENUM_DOUBLE(AC97_REC_GAIN_MIC, 13, 10, 8, wm9713_dac_inv),
6373998b70fSLiam Girdwood AC97_ENUM_SINGLE(AC97_GENERAL_PURPOSE, 15, 2, wm9713_base),
6383998b70fSLiam Girdwood AC97_ENUM_SINGLE(AC97_PCI_SVID, 5, 2, wm9713_ng_type),
6391da177e4SLinus Torvalds };
6401da177e4SLinus Torvalds 
641ee42381eSTakashi Iwai static const struct snd_kcontrol_new wm13_snd_ac97_controls[] = {
6421da177e4SLinus Torvalds AC97_DOUBLE("Line In Volume", AC97_PC_BEEP, 8, 0, 31, 1),
6433998b70fSLiam Girdwood AC97_SINGLE("Line In to Headphone Switch", AC97_PC_BEEP, 15, 1, 1),
6443998b70fSLiam Girdwood AC97_SINGLE("Line In to Master Switch", AC97_PC_BEEP, 14, 1, 1),
6453998b70fSLiam Girdwood AC97_SINGLE("Line In to Mono Switch", AC97_PC_BEEP, 13, 1, 1),
6463998b70fSLiam Girdwood 
6473998b70fSLiam Girdwood AC97_DOUBLE("PCM Playback Volume", AC97_PHONE, 8, 0, 31, 1),
6483998b70fSLiam Girdwood AC97_SINGLE("PCM Playback to Headphone Switch", AC97_PHONE, 15, 1, 1),
6493998b70fSLiam Girdwood AC97_SINGLE("PCM Playback to Master Switch", AC97_PHONE, 14, 1, 1),
6503998b70fSLiam Girdwood AC97_SINGLE("PCM Playback to Mono Switch", AC97_PHONE, 13, 1, 1),
6513998b70fSLiam Girdwood 
6523998b70fSLiam Girdwood AC97_SINGLE("Mic 1 Volume", AC97_MIC, 8, 31, 1),
6533998b70fSLiam Girdwood AC97_SINGLE("Mic 2 Volume", AC97_MIC, 0, 31, 1),
6543998b70fSLiam Girdwood AC97_SINGLE("Mic 1 to Mono Switch", AC97_LINE, 7, 1, 1),
6553998b70fSLiam Girdwood AC97_SINGLE("Mic 2 to Mono Switch", AC97_LINE, 6, 1, 1),
656d7f6f115SJames Courtier-Dutton AC97_SINGLE("Mic Boost (+20dB) Switch", AC97_LINE, 5, 1, 0),
6573998b70fSLiam Girdwood AC97_ENUM("Mic to Headphone Mux", wm9713_enum[0]),
6583998b70fSLiam Girdwood AC97_SINGLE("Mic Headphone Mixer Volume", AC97_LINE, 0, 7, 1),
6593998b70fSLiam Girdwood 
6603998b70fSLiam Girdwood AC97_SINGLE("Capture Switch", AC97_CD, 15, 1, 1),
6613998b70fSLiam Girdwood AC97_ENUM("Capture Volume Steps", wm9713_enum[4]),
6623998b70fSLiam Girdwood AC97_DOUBLE("Capture Volume", AC97_CD, 8, 0, 15, 0),
6633998b70fSLiam Girdwood AC97_SINGLE("Capture ZC Switch", AC97_CD, 7, 1, 0),
6643998b70fSLiam Girdwood 
6653998b70fSLiam Girdwood AC97_ENUM("Capture to Headphone Mux", wm9713_enum[1]),
6663998b70fSLiam Girdwood AC97_SINGLE("Capture to Headphone Volume", AC97_VIDEO, 11, 7, 1),
6673998b70fSLiam Girdwood AC97_ENUM("Capture to Mono Mux", wm9713_enum[2]),
6683998b70fSLiam Girdwood AC97_SINGLE("Capture to Mono Boost (+20dB) Switch", AC97_VIDEO, 8, 1, 0),
6693998b70fSLiam Girdwood AC97_SINGLE("Capture ADC Boost (+20dB) Switch", AC97_VIDEO, 6, 1, 0),
6703998b70fSLiam Girdwood AC97_ENUM("Capture Select", wm9713_enum[3]),
6713998b70fSLiam Girdwood 
6723998b70fSLiam Girdwood AC97_SINGLE("ALC Target Volume", AC97_CODEC_CLASS_REV, 12, 15, 0),
6733998b70fSLiam Girdwood AC97_SINGLE("ALC Hold Time", AC97_CODEC_CLASS_REV, 8, 15, 0),
6743998b70fSLiam Girdwood AC97_SINGLE("ALC Decay Time ", AC97_CODEC_CLASS_REV, 4, 15, 0),
6753998b70fSLiam Girdwood AC97_SINGLE("ALC Attack Time", AC97_CODEC_CLASS_REV, 0, 15, 0),
6763998b70fSLiam Girdwood AC97_ENUM("ALC Function", wm9713_enum[5]),
6773998b70fSLiam Girdwood AC97_SINGLE("ALC Max Volume", AC97_PCI_SVID, 11, 7, 0),
6783998b70fSLiam Girdwood AC97_SINGLE("ALC ZC Timeout", AC97_PCI_SVID, 9, 3, 0),
6793998b70fSLiam Girdwood AC97_SINGLE("ALC ZC Switch", AC97_PCI_SVID, 8, 1, 0),
6803998b70fSLiam Girdwood AC97_SINGLE("ALC NG Switch", AC97_PCI_SVID, 7, 1, 0),
6813998b70fSLiam Girdwood AC97_ENUM("ALC NG Type", wm9713_enum[13]),
6823998b70fSLiam Girdwood AC97_SINGLE("ALC NG Threshold", AC97_PCI_SVID, 0, 31, 0),
6833998b70fSLiam Girdwood 
6843998b70fSLiam Girdwood AC97_DOUBLE("Master ZC Switch", AC97_MASTER, 14, 6, 1, 0),
6853998b70fSLiam Girdwood AC97_DOUBLE("Headphone ZC Switch", AC97_HEADPHONE, 14, 6, 1, 0),
6863998b70fSLiam Girdwood AC97_DOUBLE("Out3/4 ZC Switch", AC97_MASTER_MONO, 14, 6, 1, 0),
6873998b70fSLiam Girdwood AC97_SINGLE("Master Right Switch", AC97_MASTER, 7, 1, 1),
6883998b70fSLiam Girdwood AC97_SINGLE("Headphone Right Switch", AC97_HEADPHONE, 7, 1, 1),
6893998b70fSLiam Girdwood AC97_SINGLE("Out3/4 Right Switch", AC97_MASTER_MONO, 7, 1, 1),
6903998b70fSLiam Girdwood 
6913998b70fSLiam Girdwood AC97_SINGLE("Mono In to Headphone Switch", AC97_MASTER_TONE, 15, 1, 1),
6923998b70fSLiam Girdwood AC97_SINGLE("Mono In to Master Switch", AC97_MASTER_TONE, 14, 1, 1),
6933998b70fSLiam Girdwood AC97_SINGLE("Mono In Volume", AC97_MASTER_TONE, 8, 31, 1),
6943998b70fSLiam Girdwood AC97_SINGLE("Mono Switch", AC97_MASTER_TONE, 7, 1, 1),
6953998b70fSLiam Girdwood AC97_SINGLE("Mono ZC Switch", AC97_MASTER_TONE, 6, 1, 0),
6963998b70fSLiam Girdwood AC97_SINGLE("Mono Volume", AC97_MASTER_TONE, 0, 31, 1),
6973998b70fSLiam Girdwood 
6983998b70fSLiam Girdwood AC97_SINGLE("PC Beep to Headphone Switch", AC97_AUX, 15, 1, 1),
6993998b70fSLiam Girdwood AC97_SINGLE("PC Beep to Headphone Volume", AC97_AUX, 12, 7, 1),
7003998b70fSLiam Girdwood AC97_SINGLE("PC Beep to Master Switch", AC97_AUX, 11, 1, 1),
7013998b70fSLiam Girdwood AC97_SINGLE("PC Beep to Master Volume", AC97_AUX, 8, 7, 1),
7023998b70fSLiam Girdwood AC97_SINGLE("PC Beep to Mono Switch", AC97_AUX, 7, 1, 1),
7033998b70fSLiam Girdwood AC97_SINGLE("PC Beep to Mono Volume", AC97_AUX, 4, 7, 1),
7043998b70fSLiam Girdwood 
7053998b70fSLiam Girdwood AC97_SINGLE("Voice to Headphone Switch", AC97_PCM, 15, 1, 1),
7063998b70fSLiam Girdwood AC97_SINGLE("Voice to Headphone Volume", AC97_PCM, 12, 7, 1),
7073998b70fSLiam Girdwood AC97_SINGLE("Voice to Master Switch", AC97_PCM, 11, 1, 1),
7083998b70fSLiam Girdwood AC97_SINGLE("Voice to Master Volume", AC97_PCM, 8, 7, 1),
7093998b70fSLiam Girdwood AC97_SINGLE("Voice to Mono Switch", AC97_PCM, 7, 1, 1),
7103998b70fSLiam Girdwood AC97_SINGLE("Voice to Mono Volume", AC97_PCM, 4, 7, 1),
7113998b70fSLiam Girdwood 
7123998b70fSLiam Girdwood AC97_SINGLE("Aux to Headphone Switch", AC97_REC_SEL, 15, 1, 1),
7133998b70fSLiam Girdwood AC97_SINGLE("Aux to Headphone Volume", AC97_REC_SEL, 12, 7, 1),
7143998b70fSLiam Girdwood AC97_SINGLE("Aux to Master Switch", AC97_REC_SEL, 11, 1, 1),
7153998b70fSLiam Girdwood AC97_SINGLE("Aux to Master Volume", AC97_REC_SEL, 8, 7, 1),
7163998b70fSLiam Girdwood AC97_SINGLE("Aux to Mono Switch", AC97_REC_SEL, 7, 1, 1),
7173998b70fSLiam Girdwood AC97_SINGLE("Aux to Mono Volume", AC97_REC_SEL, 4, 7, 1),
7183998b70fSLiam Girdwood 
7193998b70fSLiam Girdwood AC97_ENUM("Mono Input Mux", wm9713_enum[6]),
7203998b70fSLiam Girdwood AC97_ENUM("Master Input Mux", wm9713_enum[7]),
7213998b70fSLiam Girdwood AC97_ENUM("Headphone Input Mux", wm9713_enum[8]),
7223998b70fSLiam Girdwood AC97_ENUM("Out 3 Input Mux", wm9713_enum[9]),
7233998b70fSLiam Girdwood AC97_ENUM("Out 4 Input Mux", wm9713_enum[10]),
7243998b70fSLiam Girdwood 
7253998b70fSLiam Girdwood AC97_ENUM("Bass Control", wm9713_enum[12]),
7263998b70fSLiam Girdwood AC97_SINGLE("Bass Cut-off Switch", AC97_GENERAL_PURPOSE, 12, 1, 1),
7273998b70fSLiam Girdwood AC97_SINGLE("Tone Cut-off Switch", AC97_GENERAL_PURPOSE, 4, 1, 1),
7283998b70fSLiam Girdwood AC97_SINGLE("Playback Attenuate (-6dB) Switch", AC97_GENERAL_PURPOSE, 6, 1, 0),
7293998b70fSLiam Girdwood AC97_SINGLE("Bass Volume", AC97_GENERAL_PURPOSE, 8, 15, 1),
7303998b70fSLiam Girdwood AC97_SINGLE("Tone Volume", AC97_GENERAL_PURPOSE, 0, 15, 1),
7311da177e4SLinus Torvalds };
7321da177e4SLinus Torvalds 
733ee42381eSTakashi Iwai static const struct snd_kcontrol_new wm13_snd_ac97_controls_3d[] = {
7343998b70fSLiam Girdwood AC97_ENUM("Inv Input Mux", wm9713_enum[11]),
7353998b70fSLiam Girdwood AC97_SINGLE("3D Upper Cut-off Switch", AC97_REC_GAIN_MIC, 5, 1, 0),
7363998b70fSLiam Girdwood AC97_SINGLE("3D Lower Cut-off Switch", AC97_REC_GAIN_MIC, 4, 1, 0),
7373998b70fSLiam Girdwood AC97_SINGLE("3D Depth", AC97_REC_GAIN_MIC, 0, 15, 1),
7381da177e4SLinus Torvalds };
7391da177e4SLinus Torvalds 
740ee42381eSTakashi Iwai static int patch_wolfson_wm9713_3d (struct snd_ac97 * ac97)
7413998b70fSLiam Girdwood {
7423998b70fSLiam Girdwood 	int err, i;
7431da177e4SLinus Torvalds 
7443998b70fSLiam Girdwood 	for (i = 0; i < ARRAY_SIZE(wm13_snd_ac97_controls_3d); i++) {
7453998b70fSLiam Girdwood 		if ((err = snd_ctl_add(ac97->bus->card, snd_ac97_cnew(&wm13_snd_ac97_controls_3d[i], ac97))) < 0)
7463998b70fSLiam Girdwood 			return err;
7473998b70fSLiam Girdwood 	}
7483998b70fSLiam Girdwood 	return 0;
7493998b70fSLiam Girdwood }
7501da177e4SLinus Torvalds 
751ee42381eSTakashi Iwai static int patch_wolfson_wm9713_specific(struct snd_ac97 * ac97)
7521da177e4SLinus Torvalds {
7531da177e4SLinus Torvalds 	int err, i;
7541da177e4SLinus Torvalds 
7553998b70fSLiam Girdwood 	for (i = 0; i < ARRAY_SIZE(wm13_snd_ac97_controls); i++) {
7563998b70fSLiam Girdwood 		if ((err = snd_ctl_add(ac97->bus->card, snd_ac97_cnew(&wm13_snd_ac97_controls[i], ac97))) < 0)
7571da177e4SLinus Torvalds 			return err;
7581da177e4SLinus Torvalds 	}
7591da177e4SLinus Torvalds 	snd_ac97_write_cache(ac97, AC97_PC_BEEP, 0x0808);
7601da177e4SLinus Torvalds 	snd_ac97_write_cache(ac97, AC97_PHONE, 0x0808);
7611da177e4SLinus Torvalds 	snd_ac97_write_cache(ac97, AC97_MIC, 0x0808);
7621da177e4SLinus Torvalds 	snd_ac97_write_cache(ac97, AC97_LINE, 0x00da);
7631da177e4SLinus Torvalds 	snd_ac97_write_cache(ac97, AC97_CD, 0x0808);
7641da177e4SLinus Torvalds 	snd_ac97_write_cache(ac97, AC97_VIDEO, 0xd612);
7651da177e4SLinus Torvalds 	snd_ac97_write_cache(ac97, AC97_REC_GAIN, 0x1ba0);
7661da177e4SLinus Torvalds 	return 0;
7671da177e4SLinus Torvalds }
7681da177e4SLinus Torvalds 
7691da177e4SLinus Torvalds #ifdef CONFIG_PM
770ee42381eSTakashi Iwai static void patch_wolfson_wm9713_suspend (struct snd_ac97 * ac97)
7711da177e4SLinus Torvalds {
7721da177e4SLinus Torvalds 	snd_ac97_write_cache(ac97, AC97_EXTENDED_MID, 0xfeff);
7731da177e4SLinus Torvalds 	snd_ac97_write_cache(ac97, AC97_EXTENDED_MSTATUS, 0xffff);
7741da177e4SLinus Torvalds }
7751da177e4SLinus Torvalds 
776ee42381eSTakashi Iwai static void patch_wolfson_wm9713_resume (struct snd_ac97 * ac97)
7771da177e4SLinus Torvalds {
7781da177e4SLinus Torvalds 	snd_ac97_write_cache(ac97, AC97_EXTENDED_MID, 0xda00);
7791da177e4SLinus Torvalds 	snd_ac97_write_cache(ac97, AC97_EXTENDED_MSTATUS, 0x3810);
7801da177e4SLinus Torvalds 	snd_ac97_write_cache(ac97, AC97_POWERDOWN, 0x0);
7811da177e4SLinus Torvalds }
7821da177e4SLinus Torvalds #endif
7831da177e4SLinus Torvalds 
7841da177e4SLinus Torvalds static struct snd_ac97_build_ops patch_wolfson_wm9713_ops = {
7851da177e4SLinus Torvalds 	.build_specific = patch_wolfson_wm9713_specific,
7863998b70fSLiam Girdwood 	.build_3d = patch_wolfson_wm9713_3d,
7871da177e4SLinus Torvalds #ifdef CONFIG_PM
7881da177e4SLinus Torvalds 	.suspend = patch_wolfson_wm9713_suspend,
7891da177e4SLinus Torvalds 	.resume = patch_wolfson_wm9713_resume
7901da177e4SLinus Torvalds #endif
7911da177e4SLinus Torvalds };
7921da177e4SLinus Torvalds 
793ee42381eSTakashi Iwai int patch_wolfson13(struct snd_ac97 * ac97)
7941da177e4SLinus Torvalds {
7953998b70fSLiam Girdwood 	/* WM9713, WM9714 */
7961da177e4SLinus Torvalds 	ac97->build_ops = &patch_wolfson_wm9713_ops;
7971da177e4SLinus Torvalds 
7981da177e4SLinus Torvalds 	ac97->flags |= AC97_HAS_NO_REC_GAIN | AC97_STEREO_MUTES | AC97_HAS_NO_PHONE |
7993998b70fSLiam Girdwood 		AC97_HAS_NO_PC_BEEP | AC97_HAS_NO_VIDEO | AC97_HAS_NO_CD | AC97_HAS_NO_TONE |
8003998b70fSLiam Girdwood 		AC97_HAS_NO_STD_PCM;
801064d2112SLiam Girdwood     	ac97->scaps &= ~AC97_SCAP_MODEM;
8021da177e4SLinus Torvalds 
8031da177e4SLinus Torvalds 	snd_ac97_write_cache(ac97, AC97_EXTENDED_MID, 0xda00);
8041da177e4SLinus Torvalds 	snd_ac97_write_cache(ac97, AC97_EXTENDED_MSTATUS, 0x3810);
8051da177e4SLinus Torvalds 	snd_ac97_write_cache(ac97, AC97_POWERDOWN, 0x0);
8061da177e4SLinus Torvalds 
8071da177e4SLinus Torvalds 	return 0;
8081da177e4SLinus Torvalds }
8091da177e4SLinus Torvalds 
8101da177e4SLinus Torvalds /*
8111da177e4SLinus Torvalds  * Tritech codec
8121da177e4SLinus Torvalds  */
813ee42381eSTakashi Iwai int patch_tritech_tr28028(struct snd_ac97 * ac97)
8141da177e4SLinus Torvalds {
8151da177e4SLinus Torvalds 	snd_ac97_write_cache(ac97, 0x26, 0x0300);
8161da177e4SLinus Torvalds 	snd_ac97_write_cache(ac97, 0x26, 0x0000);
8171da177e4SLinus Torvalds 	snd_ac97_write_cache(ac97, AC97_SURROUND_MASTER, 0x0000);
8181da177e4SLinus Torvalds 	snd_ac97_write_cache(ac97, AC97_SPDIF, 0x0000);
8191da177e4SLinus Torvalds 	return 0;
8201da177e4SLinus Torvalds }
8211da177e4SLinus Torvalds 
8221da177e4SLinus Torvalds /*
8231da177e4SLinus Torvalds  * Sigmatel STAC97xx codecs
8241da177e4SLinus Torvalds  */
825ee42381eSTakashi Iwai static int patch_sigmatel_stac9700_3d(struct snd_ac97 * ac97)
8261da177e4SLinus Torvalds {
827ee42381eSTakashi Iwai 	struct snd_kcontrol *kctl;
8281da177e4SLinus Torvalds 	int err;
8291da177e4SLinus Torvalds 
8301da177e4SLinus Torvalds 	if ((err = snd_ctl_add(ac97->bus->card, kctl = snd_ac97_cnew(&snd_ac97_controls_3d[0], ac97))) < 0)
8311da177e4SLinus Torvalds 		return err;
8321da177e4SLinus Torvalds 	strcpy(kctl->id.name, "3D Control Sigmatel - Depth");
8331da177e4SLinus Torvalds 	kctl->private_value = AC97_SINGLE_VALUE(AC97_3D_CONTROL, 2, 3, 0);
8341da177e4SLinus Torvalds 	snd_ac97_write_cache(ac97, AC97_3D_CONTROL, 0x0000);
8351da177e4SLinus Torvalds 	return 0;
8361da177e4SLinus Torvalds }
8371da177e4SLinus Torvalds 
838ee42381eSTakashi Iwai static int patch_sigmatel_stac9708_3d(struct snd_ac97 * ac97)
8391da177e4SLinus Torvalds {
840ee42381eSTakashi Iwai 	struct snd_kcontrol *kctl;
8411da177e4SLinus Torvalds 	int err;
8421da177e4SLinus Torvalds 
8431da177e4SLinus Torvalds 	if ((err = snd_ctl_add(ac97->bus->card, kctl = snd_ac97_cnew(&snd_ac97_controls_3d[0], ac97))) < 0)
8441da177e4SLinus Torvalds 		return err;
8451da177e4SLinus Torvalds 	strcpy(kctl->id.name, "3D Control Sigmatel - Depth");
8461da177e4SLinus Torvalds 	kctl->private_value = AC97_SINGLE_VALUE(AC97_3D_CONTROL, 0, 3, 0);
8471da177e4SLinus Torvalds 	if ((err = snd_ctl_add(ac97->bus->card, kctl = snd_ac97_cnew(&snd_ac97_controls_3d[0], ac97))) < 0)
8481da177e4SLinus Torvalds 		return err;
8491da177e4SLinus Torvalds 	strcpy(kctl->id.name, "3D Control Sigmatel - Rear Depth");
8501da177e4SLinus Torvalds 	kctl->private_value = AC97_SINGLE_VALUE(AC97_3D_CONTROL, 2, 3, 0);
8511da177e4SLinus Torvalds 	snd_ac97_write_cache(ac97, AC97_3D_CONTROL, 0x0000);
8521da177e4SLinus Torvalds 	return 0;
8531da177e4SLinus Torvalds }
8541da177e4SLinus Torvalds 
855ee42381eSTakashi Iwai static const struct snd_kcontrol_new snd_ac97_sigmatel_4speaker =
8561da177e4SLinus Torvalds AC97_SINGLE("Sigmatel 4-Speaker Stereo Playback Switch", AC97_SIGMATEL_DAC2INVERT, 2, 1, 0);
8571da177e4SLinus Torvalds 
858ee42381eSTakashi Iwai static const struct snd_kcontrol_new snd_ac97_sigmatel_phaseinvert =
8591da177e4SLinus Torvalds AC97_SINGLE("Sigmatel Surround Phase Inversion Playback Switch", AC97_SIGMATEL_DAC2INVERT, 3, 1, 0);
8601da177e4SLinus Torvalds 
861ee42381eSTakashi Iwai static const struct snd_kcontrol_new snd_ac97_sigmatel_controls[] = {
8621da177e4SLinus Torvalds AC97_SINGLE("Sigmatel DAC 6dB Attenuate", AC97_SIGMATEL_ANALOG, 1, 1, 0),
8631da177e4SLinus Torvalds AC97_SINGLE("Sigmatel ADC 6dB Attenuate", AC97_SIGMATEL_ANALOG, 0, 1, 0)
8641da177e4SLinus Torvalds };
8651da177e4SLinus Torvalds 
866ee42381eSTakashi Iwai static int patch_sigmatel_stac97xx_specific(struct snd_ac97 * ac97)
8671da177e4SLinus Torvalds {
8681da177e4SLinus Torvalds 	int err;
8691da177e4SLinus Torvalds 
8701da177e4SLinus Torvalds 	snd_ac97_write_cache(ac97, AC97_SIGMATEL_ANALOG, snd_ac97_read(ac97, AC97_SIGMATEL_ANALOG) & ~0x0003);
8711da177e4SLinus Torvalds 	if (snd_ac97_try_bit(ac97, AC97_SIGMATEL_ANALOG, 1))
8721da177e4SLinus Torvalds 		if ((err = patch_build_controls(ac97, &snd_ac97_sigmatel_controls[0], 1)) < 0)
8731da177e4SLinus Torvalds 			return err;
8741da177e4SLinus Torvalds 	if (snd_ac97_try_bit(ac97, AC97_SIGMATEL_ANALOG, 0))
8751da177e4SLinus Torvalds 		if ((err = patch_build_controls(ac97, &snd_ac97_sigmatel_controls[1], 1)) < 0)
8761da177e4SLinus Torvalds 			return err;
8771da177e4SLinus Torvalds 	if (snd_ac97_try_bit(ac97, AC97_SIGMATEL_DAC2INVERT, 2))
8781da177e4SLinus Torvalds 		if ((err = patch_build_controls(ac97, &snd_ac97_sigmatel_4speaker, 1)) < 0)
8791da177e4SLinus Torvalds 			return err;
8801da177e4SLinus Torvalds 	if (snd_ac97_try_bit(ac97, AC97_SIGMATEL_DAC2INVERT, 3))
8811da177e4SLinus Torvalds 		if ((err = patch_build_controls(ac97, &snd_ac97_sigmatel_phaseinvert, 1)) < 0)
8821da177e4SLinus Torvalds 			return err;
8831da177e4SLinus Torvalds 	return 0;
8841da177e4SLinus Torvalds }
8851da177e4SLinus Torvalds 
8861da177e4SLinus Torvalds static struct snd_ac97_build_ops patch_sigmatel_stac9700_ops = {
8871da177e4SLinus Torvalds 	.build_3d	= patch_sigmatel_stac9700_3d,
8881da177e4SLinus Torvalds 	.build_specific	= patch_sigmatel_stac97xx_specific
8891da177e4SLinus Torvalds };
8901da177e4SLinus Torvalds 
891ee42381eSTakashi Iwai int patch_sigmatel_stac9700(struct snd_ac97 * ac97)
8921da177e4SLinus Torvalds {
8931da177e4SLinus Torvalds 	ac97->build_ops = &patch_sigmatel_stac9700_ops;
8941da177e4SLinus Torvalds 	return 0;
8951da177e4SLinus Torvalds }
8961da177e4SLinus Torvalds 
897ee42381eSTakashi Iwai static int snd_ac97_stac9708_put_bias(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
8981da177e4SLinus Torvalds {
899ee42381eSTakashi Iwai 	struct snd_ac97 *ac97 = snd_kcontrol_chip(kcontrol);
9001da177e4SLinus Torvalds 	int err;
9011da177e4SLinus Torvalds 
90262932df8SIngo Molnar 	mutex_lock(&ac97->page_mutex);
9031da177e4SLinus Torvalds 	snd_ac97_write(ac97, AC97_SIGMATEL_BIAS1, 0xabba);
9041da177e4SLinus Torvalds 	err = snd_ac97_update_bits(ac97, AC97_SIGMATEL_BIAS2, 0x0010,
9051da177e4SLinus Torvalds 				   (ucontrol->value.integer.value[0] & 1) << 4);
9061da177e4SLinus Torvalds 	snd_ac97_write(ac97, AC97_SIGMATEL_BIAS1, 0);
90762932df8SIngo Molnar 	mutex_unlock(&ac97->page_mutex);
9081da177e4SLinus Torvalds 	return err;
9091da177e4SLinus Torvalds }
9101da177e4SLinus Torvalds 
911ee42381eSTakashi Iwai static const struct snd_kcontrol_new snd_ac97_stac9708_bias_control = {
9121da177e4SLinus Torvalds 	.iface = SNDRV_CTL_ELEM_IFACE_MIXER,
9131da177e4SLinus Torvalds 	.name = "Sigmatel Output Bias Switch",
9141da177e4SLinus Torvalds 	.info = snd_ac97_info_volsw,
9151da177e4SLinus Torvalds 	.get = snd_ac97_get_volsw,
9161da177e4SLinus Torvalds 	.put = snd_ac97_stac9708_put_bias,
9171da177e4SLinus Torvalds 	.private_value = AC97_SINGLE_VALUE(AC97_SIGMATEL_BIAS2, 4, 1, 0),
9181da177e4SLinus Torvalds };
9191da177e4SLinus Torvalds 
920ee42381eSTakashi Iwai static int patch_sigmatel_stac9708_specific(struct snd_ac97 *ac97)
9211da177e4SLinus Torvalds {
9221da177e4SLinus Torvalds 	int err;
9231da177e4SLinus Torvalds 
9241da177e4SLinus Torvalds 	snd_ac97_rename_vol_ctl(ac97, "Headphone Playback", "Sigmatel Surround Playback");
9251da177e4SLinus Torvalds 	if ((err = patch_build_controls(ac97, &snd_ac97_stac9708_bias_control, 1)) < 0)
9261da177e4SLinus Torvalds 		return err;
9271da177e4SLinus Torvalds 	return patch_sigmatel_stac97xx_specific(ac97);
9281da177e4SLinus Torvalds }
9291da177e4SLinus Torvalds 
9301da177e4SLinus Torvalds static struct snd_ac97_build_ops patch_sigmatel_stac9708_ops = {
9311da177e4SLinus Torvalds 	.build_3d	= patch_sigmatel_stac9708_3d,
9321da177e4SLinus Torvalds 	.build_specific	= patch_sigmatel_stac9708_specific
9331da177e4SLinus Torvalds };
9341da177e4SLinus Torvalds 
935ee42381eSTakashi Iwai int patch_sigmatel_stac9708(struct snd_ac97 * ac97)
9361da177e4SLinus Torvalds {
9371da177e4SLinus Torvalds 	unsigned int codec72, codec6c;
9381da177e4SLinus Torvalds 
9391da177e4SLinus Torvalds 	ac97->build_ops = &patch_sigmatel_stac9708_ops;
9401da177e4SLinus Torvalds 	ac97->caps |= 0x10;	/* HP (sigmatel surround) support */
9411da177e4SLinus Torvalds 
9421da177e4SLinus Torvalds 	codec72 = snd_ac97_read(ac97, AC97_SIGMATEL_BIAS2) & 0x8000;
9431da177e4SLinus Torvalds 	codec6c = snd_ac97_read(ac97, AC97_SIGMATEL_ANALOG);
9441da177e4SLinus Torvalds 
9451da177e4SLinus Torvalds 	if ((codec72==0) && (codec6c==0)) {
9461da177e4SLinus Torvalds 		snd_ac97_write_cache(ac97, AC97_SIGMATEL_CIC1, 0xabba);
9471da177e4SLinus Torvalds 		snd_ac97_write_cache(ac97, AC97_SIGMATEL_CIC2, 0x1000);
9481da177e4SLinus Torvalds 		snd_ac97_write_cache(ac97, AC97_SIGMATEL_BIAS1, 0xabba);
9491da177e4SLinus Torvalds 		snd_ac97_write_cache(ac97, AC97_SIGMATEL_BIAS2, 0x0007);
9501da177e4SLinus Torvalds 	} else if ((codec72==0x8000) && (codec6c==0)) {
9511da177e4SLinus Torvalds 		snd_ac97_write_cache(ac97, AC97_SIGMATEL_CIC1, 0xabba);
9521da177e4SLinus Torvalds 		snd_ac97_write_cache(ac97, AC97_SIGMATEL_CIC2, 0x1001);
9531da177e4SLinus Torvalds 		snd_ac97_write_cache(ac97, AC97_SIGMATEL_DAC2INVERT, 0x0008);
9541da177e4SLinus Torvalds 	} else if ((codec72==0x8000) && (codec6c==0x0080)) {
9551da177e4SLinus Torvalds 		/* nothing */
9561da177e4SLinus Torvalds 	}
9571da177e4SLinus Torvalds 	snd_ac97_write_cache(ac97, AC97_SIGMATEL_MULTICHN, 0x0000);
9581da177e4SLinus Torvalds 	return 0;
9591da177e4SLinus Torvalds }
9601da177e4SLinus Torvalds 
961ee42381eSTakashi Iwai int patch_sigmatel_stac9721(struct snd_ac97 * ac97)
9621da177e4SLinus Torvalds {
9631da177e4SLinus Torvalds 	ac97->build_ops = &patch_sigmatel_stac9700_ops;
9641da177e4SLinus Torvalds 	if (snd_ac97_read(ac97, AC97_SIGMATEL_ANALOG) == 0) {
9651da177e4SLinus Torvalds 		// patch for SigmaTel
9661da177e4SLinus Torvalds 		snd_ac97_write_cache(ac97, AC97_SIGMATEL_CIC1, 0xabba);
9671da177e4SLinus Torvalds 		snd_ac97_write_cache(ac97, AC97_SIGMATEL_CIC2, 0x4000);
9681da177e4SLinus Torvalds 		snd_ac97_write_cache(ac97, AC97_SIGMATEL_BIAS1, 0xabba);
9691da177e4SLinus Torvalds 		snd_ac97_write_cache(ac97, AC97_SIGMATEL_BIAS2, 0x0002);
9701da177e4SLinus Torvalds 	}
9711da177e4SLinus Torvalds 	snd_ac97_write_cache(ac97, AC97_SIGMATEL_MULTICHN, 0x0000);
9721da177e4SLinus Torvalds 	return 0;
9731da177e4SLinus Torvalds }
9741da177e4SLinus Torvalds 
975ee42381eSTakashi Iwai int patch_sigmatel_stac9744(struct snd_ac97 * ac97)
9761da177e4SLinus Torvalds {
9771da177e4SLinus Torvalds 	// patch for SigmaTel
9781da177e4SLinus Torvalds 	ac97->build_ops = &patch_sigmatel_stac9700_ops;
9791da177e4SLinus Torvalds 	snd_ac97_write_cache(ac97, AC97_SIGMATEL_CIC1, 0xabba);
9801da177e4SLinus Torvalds 	snd_ac97_write_cache(ac97, AC97_SIGMATEL_CIC2, 0x0000);	/* is this correct? --jk */
9811da177e4SLinus Torvalds 	snd_ac97_write_cache(ac97, AC97_SIGMATEL_BIAS1, 0xabba);
9821da177e4SLinus Torvalds 	snd_ac97_write_cache(ac97, AC97_SIGMATEL_BIAS2, 0x0002);
9831da177e4SLinus Torvalds 	snd_ac97_write_cache(ac97, AC97_SIGMATEL_MULTICHN, 0x0000);
9841da177e4SLinus Torvalds 	return 0;
9851da177e4SLinus Torvalds }
9861da177e4SLinus Torvalds 
987ee42381eSTakashi Iwai int patch_sigmatel_stac9756(struct snd_ac97 * ac97)
9881da177e4SLinus Torvalds {
9891da177e4SLinus Torvalds 	// patch for SigmaTel
9901da177e4SLinus Torvalds 	ac97->build_ops = &patch_sigmatel_stac9700_ops;
9911da177e4SLinus Torvalds 	snd_ac97_write_cache(ac97, AC97_SIGMATEL_CIC1, 0xabba);
9921da177e4SLinus Torvalds 	snd_ac97_write_cache(ac97, AC97_SIGMATEL_CIC2, 0x0000);	/* is this correct? --jk */
9931da177e4SLinus Torvalds 	snd_ac97_write_cache(ac97, AC97_SIGMATEL_BIAS1, 0xabba);
9941da177e4SLinus Torvalds 	snd_ac97_write_cache(ac97, AC97_SIGMATEL_BIAS2, 0x0002);
9951da177e4SLinus Torvalds 	snd_ac97_write_cache(ac97, AC97_SIGMATEL_MULTICHN, 0x0000);
9961da177e4SLinus Torvalds 	return 0;
9971da177e4SLinus Torvalds }
9981da177e4SLinus Torvalds 
999ee42381eSTakashi Iwai static int snd_ac97_stac9758_output_jack_info(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_info *uinfo)
10001da177e4SLinus Torvalds {
10011da177e4SLinus Torvalds 	static char *texts[5] = { "Input/Disabled", "Front Output",
10021da177e4SLinus Torvalds 		"Rear Output", "Center/LFE Output", "Mixer Output" };
10031da177e4SLinus Torvalds 
10041da177e4SLinus Torvalds 	uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED;
10051da177e4SLinus Torvalds 	uinfo->count = 1;
10061da177e4SLinus Torvalds 	uinfo->value.enumerated.items = 5;
10071da177e4SLinus Torvalds 	if (uinfo->value.enumerated.item > 4)
10081da177e4SLinus Torvalds 		uinfo->value.enumerated.item = 4;
10091da177e4SLinus Torvalds 	strcpy(uinfo->value.enumerated.name, texts[uinfo->value.enumerated.item]);
10101da177e4SLinus Torvalds 	return 0;
10111da177e4SLinus Torvalds }
10121da177e4SLinus Torvalds 
1013ee42381eSTakashi Iwai static int snd_ac97_stac9758_output_jack_get(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
10141da177e4SLinus Torvalds {
1015ee42381eSTakashi Iwai 	struct snd_ac97 *ac97 = snd_kcontrol_chip(kcontrol);
10161da177e4SLinus Torvalds 	int shift = kcontrol->private_value;
10171da177e4SLinus Torvalds 	unsigned short val;
10181da177e4SLinus Torvalds 
10191da177e4SLinus Torvalds 	val = ac97->regs[AC97_SIGMATEL_OUTSEL] >> shift;
10201da177e4SLinus Torvalds 	if (!(val & 4))
10211da177e4SLinus Torvalds 		ucontrol->value.enumerated.item[0] = 0;
10221da177e4SLinus Torvalds 	else
10231da177e4SLinus Torvalds 		ucontrol->value.enumerated.item[0] = 1 + (val & 3);
10241da177e4SLinus Torvalds 	return 0;
10251da177e4SLinus Torvalds }
10261da177e4SLinus Torvalds 
1027ee42381eSTakashi Iwai static int snd_ac97_stac9758_output_jack_put(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
10281da177e4SLinus Torvalds {
1029ee42381eSTakashi Iwai 	struct snd_ac97 *ac97 = snd_kcontrol_chip(kcontrol);
10301da177e4SLinus Torvalds 	int shift = kcontrol->private_value;
10311da177e4SLinus Torvalds 	unsigned short val;
10321da177e4SLinus Torvalds 
10331da177e4SLinus Torvalds 	if (ucontrol->value.enumerated.item[0] > 4)
10341da177e4SLinus Torvalds 		return -EINVAL;
10351da177e4SLinus Torvalds 	if (ucontrol->value.enumerated.item[0] == 0)
10361da177e4SLinus Torvalds 		val = 0;
10371da177e4SLinus Torvalds 	else
10381da177e4SLinus Torvalds 		val = 4 | (ucontrol->value.enumerated.item[0] - 1);
10391da177e4SLinus Torvalds 	return ac97_update_bits_page(ac97, AC97_SIGMATEL_OUTSEL,
10401da177e4SLinus Torvalds 				     7 << shift, val << shift, 0);
10411da177e4SLinus Torvalds }
10421da177e4SLinus Torvalds 
1043ee42381eSTakashi Iwai static int snd_ac97_stac9758_input_jack_info(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_info *uinfo)
10441da177e4SLinus Torvalds {
10451da177e4SLinus Torvalds 	static char *texts[7] = { "Mic2 Jack", "Mic1 Jack", "Line In Jack",
10461da177e4SLinus Torvalds 		"Front Jack", "Rear Jack", "Center/LFE Jack", "Mute" };
10471da177e4SLinus Torvalds 
10481da177e4SLinus Torvalds 	uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED;
10491da177e4SLinus Torvalds 	uinfo->count = 1;
10501da177e4SLinus Torvalds 	uinfo->value.enumerated.items = 7;
10511da177e4SLinus Torvalds 	if (uinfo->value.enumerated.item > 6)
10521da177e4SLinus Torvalds 		uinfo->value.enumerated.item = 6;
10531da177e4SLinus Torvalds 	strcpy(uinfo->value.enumerated.name, texts[uinfo->value.enumerated.item]);
10541da177e4SLinus Torvalds 	return 0;
10551da177e4SLinus Torvalds }
10561da177e4SLinus Torvalds 
1057ee42381eSTakashi Iwai static int snd_ac97_stac9758_input_jack_get(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
10581da177e4SLinus Torvalds {
1059ee42381eSTakashi Iwai 	struct snd_ac97 *ac97 = snd_kcontrol_chip(kcontrol);
10601da177e4SLinus Torvalds 	int shift = kcontrol->private_value;
10611da177e4SLinus Torvalds 	unsigned short val;
10621da177e4SLinus Torvalds 
10631da177e4SLinus Torvalds 	val = ac97->regs[AC97_SIGMATEL_INSEL];
10641da177e4SLinus Torvalds 	ucontrol->value.enumerated.item[0] = (val >> shift) & 7;
10651da177e4SLinus Torvalds 	return 0;
10661da177e4SLinus Torvalds }
10671da177e4SLinus Torvalds 
1068ee42381eSTakashi Iwai static int snd_ac97_stac9758_input_jack_put(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
10691da177e4SLinus Torvalds {
1070ee42381eSTakashi Iwai 	struct snd_ac97 *ac97 = snd_kcontrol_chip(kcontrol);
10711da177e4SLinus Torvalds 	int shift = kcontrol->private_value;
10721da177e4SLinus Torvalds 
10731da177e4SLinus Torvalds 	return ac97_update_bits_page(ac97, AC97_SIGMATEL_INSEL, 7 << shift,
10741da177e4SLinus Torvalds 				     ucontrol->value.enumerated.item[0] << shift, 0);
10751da177e4SLinus Torvalds }
10761da177e4SLinus Torvalds 
1077ee42381eSTakashi Iwai static int snd_ac97_stac9758_phonesel_info(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_info *uinfo)
10781da177e4SLinus Torvalds {
10791da177e4SLinus Torvalds 	static char *texts[3] = { "None", "Front Jack", "Rear Jack" };
10801da177e4SLinus Torvalds 
10811da177e4SLinus Torvalds 	uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED;
10821da177e4SLinus Torvalds 	uinfo->count = 1;
10831da177e4SLinus Torvalds 	uinfo->value.enumerated.items = 3;
10841da177e4SLinus Torvalds 	if (uinfo->value.enumerated.item > 2)
10851da177e4SLinus Torvalds 		uinfo->value.enumerated.item = 2;
10861da177e4SLinus Torvalds 	strcpy(uinfo->value.enumerated.name, texts[uinfo->value.enumerated.item]);
10871da177e4SLinus Torvalds 	return 0;
10881da177e4SLinus Torvalds }
10891da177e4SLinus Torvalds 
1090ee42381eSTakashi Iwai static int snd_ac97_stac9758_phonesel_get(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
10911da177e4SLinus Torvalds {
1092ee42381eSTakashi Iwai 	struct snd_ac97 *ac97 = snd_kcontrol_chip(kcontrol);
10931da177e4SLinus Torvalds 
10941da177e4SLinus Torvalds 	ucontrol->value.enumerated.item[0] = ac97->regs[AC97_SIGMATEL_IOMISC] & 3;
10951da177e4SLinus Torvalds 	return 0;
10961da177e4SLinus Torvalds }
10971da177e4SLinus Torvalds 
1098ee42381eSTakashi Iwai static int snd_ac97_stac9758_phonesel_put(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
10991da177e4SLinus Torvalds {
1100ee42381eSTakashi Iwai 	struct snd_ac97 *ac97 = snd_kcontrol_chip(kcontrol);
11011da177e4SLinus Torvalds 
11021da177e4SLinus Torvalds 	return ac97_update_bits_page(ac97, AC97_SIGMATEL_IOMISC, 3,
11031da177e4SLinus Torvalds 				     ucontrol->value.enumerated.item[0], 0);
11041da177e4SLinus Torvalds }
11051da177e4SLinus Torvalds 
11061da177e4SLinus Torvalds #define STAC9758_OUTPUT_JACK(xname, shift) \
11071da177e4SLinus Torvalds {	.iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = xname, \
11081da177e4SLinus Torvalds 	.info = snd_ac97_stac9758_output_jack_info, \
11091da177e4SLinus Torvalds 	.get = snd_ac97_stac9758_output_jack_get, \
11101da177e4SLinus Torvalds 	.put = snd_ac97_stac9758_output_jack_put, \
11111da177e4SLinus Torvalds 	.private_value = shift }
11121da177e4SLinus Torvalds #define STAC9758_INPUT_JACK(xname, shift) \
11131da177e4SLinus Torvalds {	.iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = xname, \
11141da177e4SLinus Torvalds 	.info = snd_ac97_stac9758_input_jack_info, \
11151da177e4SLinus Torvalds 	.get = snd_ac97_stac9758_input_jack_get, \
11161da177e4SLinus Torvalds 	.put = snd_ac97_stac9758_input_jack_put, \
11171da177e4SLinus Torvalds 	.private_value = shift }
1118ee42381eSTakashi Iwai static const struct snd_kcontrol_new snd_ac97_sigmatel_stac9758_controls[] = {
11191da177e4SLinus Torvalds 	STAC9758_OUTPUT_JACK("Mic1 Jack", 1),
11201da177e4SLinus Torvalds 	STAC9758_OUTPUT_JACK("LineIn Jack", 4),
11211da177e4SLinus Torvalds 	STAC9758_OUTPUT_JACK("Front Jack", 7),
11221da177e4SLinus Torvalds 	STAC9758_OUTPUT_JACK("Rear Jack", 10),
11231da177e4SLinus Torvalds 	STAC9758_OUTPUT_JACK("Center/LFE Jack", 13),
11241da177e4SLinus Torvalds 	STAC9758_INPUT_JACK("Mic Input Source", 0),
11251da177e4SLinus Torvalds 	STAC9758_INPUT_JACK("Line Input Source", 8),
11261da177e4SLinus Torvalds 	{
11271da177e4SLinus Torvalds 		.iface = SNDRV_CTL_ELEM_IFACE_MIXER,
11281da177e4SLinus Torvalds 		.name = "Headphone Amp",
11291da177e4SLinus Torvalds 		.info = snd_ac97_stac9758_phonesel_info,
11301da177e4SLinus Torvalds 		.get = snd_ac97_stac9758_phonesel_get,
11311da177e4SLinus Torvalds 		.put = snd_ac97_stac9758_phonesel_put
11321da177e4SLinus Torvalds 	},
11331da177e4SLinus Torvalds 	AC97_SINGLE("Exchange Center/LFE", AC97_SIGMATEL_IOMISC, 4, 1, 0),
11341da177e4SLinus Torvalds 	AC97_SINGLE("Headphone +3dB Boost", AC97_SIGMATEL_IOMISC, 8, 1, 0)
11351da177e4SLinus Torvalds };
11361da177e4SLinus Torvalds 
1137ee42381eSTakashi Iwai static int patch_sigmatel_stac9758_specific(struct snd_ac97 *ac97)
11381da177e4SLinus Torvalds {
11391da177e4SLinus Torvalds 	int err;
11401da177e4SLinus Torvalds 
11411da177e4SLinus Torvalds 	err = patch_sigmatel_stac97xx_specific(ac97);
11421da177e4SLinus Torvalds 	if (err < 0)
11431da177e4SLinus Torvalds 		return err;
11441da177e4SLinus Torvalds 	err = patch_build_controls(ac97, snd_ac97_sigmatel_stac9758_controls,
11451da177e4SLinus Torvalds 				   ARRAY_SIZE(snd_ac97_sigmatel_stac9758_controls));
11461da177e4SLinus Torvalds 	if (err < 0)
11471da177e4SLinus Torvalds 		return err;
11481da177e4SLinus Torvalds 	/* DAC-A direct */
11491da177e4SLinus Torvalds 	snd_ac97_rename_vol_ctl(ac97, "Headphone Playback", "Front Playback");
11501da177e4SLinus Torvalds 	/* DAC-A to Mix = PCM */
11511da177e4SLinus Torvalds 	/* DAC-B direct = Surround */
11521da177e4SLinus Torvalds 	/* DAC-B to Mix */
11531da177e4SLinus Torvalds 	snd_ac97_rename_vol_ctl(ac97, "Video Playback", "Surround Mix Playback");
11541da177e4SLinus Torvalds 	/* DAC-C direct = Center/LFE */
11551da177e4SLinus Torvalds 
11561da177e4SLinus Torvalds 	return 0;
11571da177e4SLinus Torvalds }
11581da177e4SLinus Torvalds 
11591da177e4SLinus Torvalds static struct snd_ac97_build_ops patch_sigmatel_stac9758_ops = {
11601da177e4SLinus Torvalds 	.build_3d	= patch_sigmatel_stac9700_3d,
11611da177e4SLinus Torvalds 	.build_specific	= patch_sigmatel_stac9758_specific
11621da177e4SLinus Torvalds };
11631da177e4SLinus Torvalds 
1164ee42381eSTakashi Iwai int patch_sigmatel_stac9758(struct snd_ac97 * ac97)
11651da177e4SLinus Torvalds {
11661da177e4SLinus Torvalds 	static unsigned short regs[4] = {
11671da177e4SLinus Torvalds 		AC97_SIGMATEL_OUTSEL,
11681da177e4SLinus Torvalds 		AC97_SIGMATEL_IOMISC,
11691da177e4SLinus Torvalds 		AC97_SIGMATEL_INSEL,
11701da177e4SLinus Torvalds 		AC97_SIGMATEL_VARIOUS
11711da177e4SLinus Torvalds 	};
11721da177e4SLinus Torvalds 	static unsigned short def_regs[4] = {
11731da177e4SLinus Torvalds 		/* OUTSEL */ 0xd794, /* CL:CL, SR:SR, LO:MX, LI:DS, MI:DS */
11741da177e4SLinus Torvalds 		/* IOMISC */ 0x2001,
11751da177e4SLinus Torvalds 		/* INSEL */ 0x0201, /* LI:LI, MI:M1 */
11761da177e4SLinus Torvalds 		/* VARIOUS */ 0x0040
11771da177e4SLinus Torvalds 	};
11781da177e4SLinus Torvalds 	static unsigned short m675_regs[4] = {
11791da177e4SLinus Torvalds 		/* OUTSEL */ 0xfc70, /* CL:MX, SR:MX, LO:DS, LI:MX, MI:DS */
11801da177e4SLinus Torvalds 		/* IOMISC */ 0x2102, /* HP amp on */
11811da177e4SLinus Torvalds 		/* INSEL */ 0x0203, /* LI:LI, MI:FR */
11821da177e4SLinus Torvalds 		/* VARIOUS */ 0x0041 /* stereo mic */
11831da177e4SLinus Torvalds 	};
11841da177e4SLinus Torvalds 	unsigned short *pregs = def_regs;
11851da177e4SLinus Torvalds 	int i;
11861da177e4SLinus Torvalds 
11871da177e4SLinus Torvalds 	/* Gateway M675 notebook */
11881da177e4SLinus Torvalds 	if (ac97->pci &&
11891da177e4SLinus Torvalds 	    ac97->subsystem_vendor == 0x107b &&
11901da177e4SLinus Torvalds 	    ac97->subsystem_device == 0x0601)
11911da177e4SLinus Torvalds 	    	pregs = m675_regs;
11921da177e4SLinus Torvalds 
11931da177e4SLinus Torvalds 	// patch for SigmaTel
11941da177e4SLinus Torvalds 	ac97->build_ops = &patch_sigmatel_stac9758_ops;
11951da177e4SLinus Torvalds 	/* FIXME: assume only page 0 for writing cache */
11961da177e4SLinus Torvalds 	snd_ac97_update_bits(ac97, AC97_INT_PAGING, AC97_PAGE_MASK, AC97_PAGE_VENDOR);
11971da177e4SLinus Torvalds 	for (i = 0; i < 4; i++)
11981da177e4SLinus Torvalds 		snd_ac97_write_cache(ac97, regs[i], pregs[i]);
11991da177e4SLinus Torvalds 
12001da177e4SLinus Torvalds 	ac97->flags |= AC97_STEREO_MUTES;
12011da177e4SLinus Torvalds 	return 0;
12021da177e4SLinus Torvalds }
12031da177e4SLinus Torvalds 
12041da177e4SLinus Torvalds /*
12051da177e4SLinus Torvalds  * Cirrus Logic CS42xx codecs
12061da177e4SLinus Torvalds  */
1207ee42381eSTakashi Iwai static const struct snd_kcontrol_new snd_ac97_cirrus_controls_spdif[2] = {
12081da177e4SLinus Torvalds 	AC97_SINGLE(SNDRV_CTL_NAME_IEC958("",PLAYBACK,SWITCH), AC97_CSR_SPDIF, 15, 1, 0),
12091da177e4SLinus Torvalds 	AC97_SINGLE(SNDRV_CTL_NAME_IEC958("",PLAYBACK,NONE) "AC97-SPSA", AC97_CSR_ACMODE, 0, 3, 0)
12101da177e4SLinus Torvalds };
12111da177e4SLinus Torvalds 
1212ee42381eSTakashi Iwai static int patch_cirrus_build_spdif(struct snd_ac97 * ac97)
12131da177e4SLinus Torvalds {
12141da177e4SLinus Torvalds 	int err;
12151da177e4SLinus Torvalds 
12161da177e4SLinus Torvalds 	/* con mask, pro mask, default */
12171da177e4SLinus Torvalds 	if ((err = patch_build_controls(ac97, &snd_ac97_controls_spdif[0], 3)) < 0)
12181da177e4SLinus Torvalds 		return err;
12191da177e4SLinus Torvalds 	/* switch, spsa */
12201da177e4SLinus Torvalds 	if ((err = patch_build_controls(ac97, &snd_ac97_cirrus_controls_spdif[0], 1)) < 0)
12211da177e4SLinus Torvalds 		return err;
12221da177e4SLinus Torvalds 	switch (ac97->id & AC97_ID_CS_MASK) {
12231da177e4SLinus Torvalds 	case AC97_ID_CS4205:
12241da177e4SLinus Torvalds 		if ((err = patch_build_controls(ac97, &snd_ac97_cirrus_controls_spdif[1], 1)) < 0)
12251da177e4SLinus Torvalds 			return err;
12261da177e4SLinus Torvalds 		break;
12271da177e4SLinus Torvalds 	}
12281da177e4SLinus Torvalds 	/* set default PCM S/PDIF params */
12291da177e4SLinus Torvalds 	/* consumer,PCM audio,no copyright,no preemphasis,PCM coder,original,48000Hz */
12301da177e4SLinus Torvalds 	snd_ac97_write_cache(ac97, AC97_CSR_SPDIF, 0x0a20);
12311da177e4SLinus Torvalds 	return 0;
12321da177e4SLinus Torvalds }
12331da177e4SLinus Torvalds 
12341da177e4SLinus Torvalds static struct snd_ac97_build_ops patch_cirrus_ops = {
12351da177e4SLinus Torvalds 	.build_spdif = patch_cirrus_build_spdif
12361da177e4SLinus Torvalds };
12371da177e4SLinus Torvalds 
1238ee42381eSTakashi Iwai int patch_cirrus_spdif(struct snd_ac97 * ac97)
12391da177e4SLinus Torvalds {
12401da177e4SLinus Torvalds 	/* Basically, the cs4201/cs4205/cs4297a has non-standard sp/dif registers.
12411da177e4SLinus Torvalds 	   WHY CAN'T ANYONE FOLLOW THE BLOODY SPEC?  *sigh*
12421da177e4SLinus Torvalds 	   - sp/dif EA ID is not set, but sp/dif is always present.
12431da177e4SLinus Torvalds 	   - enable/disable is spdif register bit 15.
12441da177e4SLinus Torvalds 	   - sp/dif control register is 0x68.  differs from AC97:
12451da177e4SLinus Torvalds 	   - valid is bit 14 (vs 15)
12461da177e4SLinus Torvalds 	   - no DRS
12471da177e4SLinus Torvalds 	   - only 44.1/48k [00 = 48, 01=44,1] (AC97 is 00=44.1, 10=48)
12481da177e4SLinus Torvalds 	   - sp/dif ssource select is in 0x5e bits 0,1.
12491da177e4SLinus Torvalds 	*/
12501da177e4SLinus Torvalds 
12511da177e4SLinus Torvalds 	ac97->build_ops = &patch_cirrus_ops;
12521da177e4SLinus Torvalds 	ac97->flags |= AC97_CS_SPDIF;
12531da177e4SLinus Torvalds 	ac97->rates[AC97_RATES_SPDIF] &= ~SNDRV_PCM_RATE_32000;
12541da177e4SLinus Torvalds         ac97->ext_id |= AC97_EI_SPDIF;	/* force the detection of spdif */
12551da177e4SLinus Torvalds 	snd_ac97_write_cache(ac97, AC97_CSR_ACMODE, 0x0080);
12561da177e4SLinus Torvalds 	return 0;
12571da177e4SLinus Torvalds }
12581da177e4SLinus Torvalds 
1259ee42381eSTakashi Iwai int patch_cirrus_cs4299(struct snd_ac97 * ac97)
12601da177e4SLinus Torvalds {
12611da177e4SLinus Torvalds 	/* force the detection of PC Beep */
12621da177e4SLinus Torvalds 	ac97->flags |= AC97_HAS_PC_BEEP;
12631da177e4SLinus Torvalds 
12641da177e4SLinus Torvalds 	return patch_cirrus_spdif(ac97);
12651da177e4SLinus Torvalds }
12661da177e4SLinus Torvalds 
12671da177e4SLinus Torvalds /*
12681da177e4SLinus Torvalds  * Conexant codecs
12691da177e4SLinus Torvalds  */
1270ee42381eSTakashi Iwai static const struct snd_kcontrol_new snd_ac97_conexant_controls_spdif[1] = {
12711da177e4SLinus Torvalds 	AC97_SINGLE(SNDRV_CTL_NAME_IEC958("",PLAYBACK,SWITCH), AC97_CXR_AUDIO_MISC, 3, 1, 0),
12721da177e4SLinus Torvalds };
12731da177e4SLinus Torvalds 
1274ee42381eSTakashi Iwai static int patch_conexant_build_spdif(struct snd_ac97 * ac97)
12751da177e4SLinus Torvalds {
12761da177e4SLinus Torvalds 	int err;
12771da177e4SLinus Torvalds 
12781da177e4SLinus Torvalds 	/* con mask, pro mask, default */
12791da177e4SLinus Torvalds 	if ((err = patch_build_controls(ac97, &snd_ac97_controls_spdif[0], 3)) < 0)
12801da177e4SLinus Torvalds 		return err;
12811da177e4SLinus Torvalds 	/* switch */
12821da177e4SLinus Torvalds 	if ((err = patch_build_controls(ac97, &snd_ac97_conexant_controls_spdif[0], 1)) < 0)
12831da177e4SLinus Torvalds 		return err;
12841da177e4SLinus Torvalds 	/* set default PCM S/PDIF params */
12851da177e4SLinus Torvalds 	/* consumer,PCM audio,no copyright,no preemphasis,PCM coder,original,48000Hz */
12861da177e4SLinus Torvalds 	snd_ac97_write_cache(ac97, AC97_CXR_AUDIO_MISC,
12871da177e4SLinus Torvalds 			     snd_ac97_read(ac97, AC97_CXR_AUDIO_MISC) & ~(AC97_CXR_SPDIFEN|AC97_CXR_COPYRGT|AC97_CXR_SPDIF_MASK));
12881da177e4SLinus Torvalds 	return 0;
12891da177e4SLinus Torvalds }
12901da177e4SLinus Torvalds 
12911da177e4SLinus Torvalds static struct snd_ac97_build_ops patch_conexant_ops = {
12921da177e4SLinus Torvalds 	.build_spdif = patch_conexant_build_spdif
12931da177e4SLinus Torvalds };
12941da177e4SLinus Torvalds 
1295ee42381eSTakashi Iwai int patch_conexant(struct snd_ac97 * ac97)
12961da177e4SLinus Torvalds {
12971da177e4SLinus Torvalds 	ac97->build_ops = &patch_conexant_ops;
12981da177e4SLinus Torvalds 	ac97->flags |= AC97_CX_SPDIF;
12991da177e4SLinus Torvalds         ac97->ext_id |= AC97_EI_SPDIF;	/* force the detection of spdif */
13001da177e4SLinus Torvalds 	ac97->rates[AC97_RATES_SPDIF] = SNDRV_PCM_RATE_48000; /* 48k only */
13011da177e4SLinus Torvalds 	return 0;
13021da177e4SLinus Torvalds }
13031da177e4SLinus Torvalds 
13041da177e4SLinus Torvalds /*
13051da177e4SLinus Torvalds  * Analog Device AD18xx, AD19xx codecs
13061da177e4SLinus Torvalds  */
13071da177e4SLinus Torvalds #ifdef CONFIG_PM
1308ee42381eSTakashi Iwai static void ad18xx_resume(struct snd_ac97 *ac97)
13091da177e4SLinus Torvalds {
13101da177e4SLinus Torvalds 	static unsigned short setup_regs[] = {
13111da177e4SLinus Torvalds 		AC97_AD_MISC, AC97_AD_SERIAL_CFG, AC97_AD_JACK_SPDIF,
13121da177e4SLinus Torvalds 	};
13131da177e4SLinus Torvalds 	int i, codec;
13141da177e4SLinus Torvalds 
13151da177e4SLinus Torvalds 	for (i = 0; i < (int)ARRAY_SIZE(setup_regs); i++) {
13161da177e4SLinus Torvalds 		unsigned short reg = setup_regs[i];
13171da177e4SLinus Torvalds 		if (test_bit(reg, ac97->reg_accessed)) {
13181da177e4SLinus Torvalds 			snd_ac97_write(ac97, reg, ac97->regs[reg]);
13191da177e4SLinus Torvalds 			snd_ac97_read(ac97, reg);
13201da177e4SLinus Torvalds 		}
13211da177e4SLinus Torvalds 	}
13221da177e4SLinus Torvalds 
13231da177e4SLinus Torvalds 	if (! (ac97->flags & AC97_AD_MULTI))
13241da177e4SLinus Torvalds 		/* normal restore */
13251da177e4SLinus Torvalds 		snd_ac97_restore_status(ac97);
13261da177e4SLinus Torvalds 	else {
13271da177e4SLinus Torvalds 		/* restore the AD18xx codec configurations */
13281da177e4SLinus Torvalds 		for (codec = 0; codec < 3; codec++) {
13291da177e4SLinus Torvalds 			if (! ac97->spec.ad18xx.id[codec])
13301da177e4SLinus Torvalds 				continue;
13311da177e4SLinus Torvalds 			/* select single codec */
13321da177e4SLinus Torvalds 			snd_ac97_update_bits(ac97, AC97_AD_SERIAL_CFG, 0x7000,
13331da177e4SLinus Torvalds 					     ac97->spec.ad18xx.unchained[codec] | ac97->spec.ad18xx.chained[codec]);
13341da177e4SLinus Torvalds 			ac97->bus->ops->write(ac97, AC97_AD_CODEC_CFG, ac97->spec.ad18xx.codec_cfg[codec]);
13351da177e4SLinus Torvalds 		}
13361da177e4SLinus Torvalds 		/* select all codecs */
13371da177e4SLinus Torvalds 		snd_ac97_update_bits(ac97, AC97_AD_SERIAL_CFG, 0x7000, 0x7000);
13381da177e4SLinus Torvalds 
13391da177e4SLinus Torvalds 		/* restore status */
13401da177e4SLinus Torvalds 		for (i = 2; i < 0x7c ; i += 2) {
13411da177e4SLinus Torvalds 			if (i == AC97_POWERDOWN || i == AC97_EXTENDED_ID)
13421da177e4SLinus Torvalds 				continue;
13431da177e4SLinus Torvalds 			if (test_bit(i, ac97->reg_accessed)) {
13441da177e4SLinus Torvalds 				/* handle multi codecs for AD18xx */
13451da177e4SLinus Torvalds 				if (i == AC97_PCM) {
13461da177e4SLinus Torvalds 					for (codec = 0; codec < 3; codec++) {
13471da177e4SLinus Torvalds 						if (! ac97->spec.ad18xx.id[codec])
13481da177e4SLinus Torvalds 							continue;
13491da177e4SLinus Torvalds 						/* select single codec */
13501da177e4SLinus Torvalds 						snd_ac97_update_bits(ac97, AC97_AD_SERIAL_CFG, 0x7000,
13511da177e4SLinus Torvalds 								     ac97->spec.ad18xx.unchained[codec] | ac97->spec.ad18xx.chained[codec]);
13521da177e4SLinus Torvalds 						/* update PCM bits */
13531da177e4SLinus Torvalds 						ac97->bus->ops->write(ac97, AC97_PCM, ac97->spec.ad18xx.pcmreg[codec]);
13541da177e4SLinus Torvalds 					}
13551da177e4SLinus Torvalds 					/* select all codecs */
13561da177e4SLinus Torvalds 					snd_ac97_update_bits(ac97, AC97_AD_SERIAL_CFG, 0x7000, 0x7000);
13571da177e4SLinus Torvalds 					continue;
13581da177e4SLinus Torvalds 				} else if (i == AC97_AD_TEST ||
13591da177e4SLinus Torvalds 					   i == AC97_AD_CODEC_CFG ||
13601da177e4SLinus Torvalds 					   i == AC97_AD_SERIAL_CFG)
13611da177e4SLinus Torvalds 					continue; /* ignore */
13621da177e4SLinus Torvalds 			}
13631da177e4SLinus Torvalds 			snd_ac97_write(ac97, i, ac97->regs[i]);
13641da177e4SLinus Torvalds 			snd_ac97_read(ac97, i);
13651da177e4SLinus Torvalds 		}
13661da177e4SLinus Torvalds 	}
13671da177e4SLinus Torvalds 
13681da177e4SLinus Torvalds 	snd_ac97_restore_iec958(ac97);
13691da177e4SLinus Torvalds }
13701da177e4SLinus Torvalds #endif
13711da177e4SLinus Torvalds 
1372ee42381eSTakashi Iwai int patch_ad1819(struct snd_ac97 * ac97)
13731da177e4SLinus Torvalds {
13741da177e4SLinus Torvalds 	unsigned short scfg;
13751da177e4SLinus Torvalds 
13761da177e4SLinus Torvalds 	// patch for Analog Devices
13771da177e4SLinus Torvalds 	scfg = snd_ac97_read(ac97, AC97_AD_SERIAL_CFG);
13781da177e4SLinus Torvalds 	snd_ac97_write_cache(ac97, AC97_AD_SERIAL_CFG, scfg | 0x7000); /* select all codecs */
13791da177e4SLinus Torvalds 	return 0;
13801da177e4SLinus Torvalds }
13811da177e4SLinus Torvalds 
1382ee42381eSTakashi Iwai static unsigned short patch_ad1881_unchained(struct snd_ac97 * ac97, int idx, unsigned short mask)
13831da177e4SLinus Torvalds {
13841da177e4SLinus Torvalds 	unsigned short val;
13851da177e4SLinus Torvalds 
13861da177e4SLinus Torvalds 	// test for unchained codec
13871da177e4SLinus Torvalds 	snd_ac97_update_bits(ac97, AC97_AD_SERIAL_CFG, 0x7000, mask);
13881da177e4SLinus Torvalds 	snd_ac97_write_cache(ac97, AC97_AD_CODEC_CFG, 0x0000);	/* ID0C, ID1C, SDIE = off */
13891da177e4SLinus Torvalds 	val = snd_ac97_read(ac97, AC97_VENDOR_ID2);
13901da177e4SLinus Torvalds 	if ((val & 0xff40) != 0x5340)
13911da177e4SLinus Torvalds 		return 0;
13921da177e4SLinus Torvalds 	ac97->spec.ad18xx.unchained[idx] = mask;
13931da177e4SLinus Torvalds 	ac97->spec.ad18xx.id[idx] = val;
13941da177e4SLinus Torvalds 	ac97->spec.ad18xx.codec_cfg[idx] = 0x0000;
13951da177e4SLinus Torvalds 	return mask;
13961da177e4SLinus Torvalds }
13971da177e4SLinus Torvalds 
1398ee42381eSTakashi Iwai static int patch_ad1881_chained1(struct snd_ac97 * ac97, int idx, unsigned short codec_bits)
13991da177e4SLinus Torvalds {
14001da177e4SLinus Torvalds 	static int cfg_bits[3] = { 1<<12, 1<<14, 1<<13 };
14011da177e4SLinus Torvalds 	unsigned short val;
14021da177e4SLinus Torvalds 
14031da177e4SLinus Torvalds 	snd_ac97_update_bits(ac97, AC97_AD_SERIAL_CFG, 0x7000, cfg_bits[idx]);
14041da177e4SLinus Torvalds 	snd_ac97_write_cache(ac97, AC97_AD_CODEC_CFG, 0x0004);	// SDIE
14051da177e4SLinus Torvalds 	val = snd_ac97_read(ac97, AC97_VENDOR_ID2);
14061da177e4SLinus Torvalds 	if ((val & 0xff40) != 0x5340)
14071da177e4SLinus Torvalds 		return 0;
14081da177e4SLinus Torvalds 	if (codec_bits)
14091da177e4SLinus Torvalds 		snd_ac97_write_cache(ac97, AC97_AD_CODEC_CFG, codec_bits);
14101da177e4SLinus Torvalds 	ac97->spec.ad18xx.chained[idx] = cfg_bits[idx];
14111da177e4SLinus Torvalds 	ac97->spec.ad18xx.id[idx] = val;
14121da177e4SLinus Torvalds 	ac97->spec.ad18xx.codec_cfg[idx] = codec_bits ? codec_bits : 0x0004;
14131da177e4SLinus Torvalds 	return 1;
14141da177e4SLinus Torvalds }
14151da177e4SLinus Torvalds 
1416ee42381eSTakashi Iwai static void patch_ad1881_chained(struct snd_ac97 * ac97, int unchained_idx, int cidx1, int cidx2)
14171da177e4SLinus Torvalds {
14181da177e4SLinus Torvalds 	// already detected?
14191da177e4SLinus Torvalds 	if (ac97->spec.ad18xx.unchained[cidx1] || ac97->spec.ad18xx.chained[cidx1])
14201da177e4SLinus Torvalds 		cidx1 = -1;
14211da177e4SLinus Torvalds 	if (ac97->spec.ad18xx.unchained[cidx2] || ac97->spec.ad18xx.chained[cidx2])
14221da177e4SLinus Torvalds 		cidx2 = -1;
14231da177e4SLinus Torvalds 	if (cidx1 < 0 && cidx2 < 0)
14241da177e4SLinus Torvalds 		return;
14251da177e4SLinus Torvalds 	// test for chained codecs
14261da177e4SLinus Torvalds 	snd_ac97_update_bits(ac97, AC97_AD_SERIAL_CFG, 0x7000,
14271da177e4SLinus Torvalds 			     ac97->spec.ad18xx.unchained[unchained_idx]);
14281da177e4SLinus Torvalds 	snd_ac97_write_cache(ac97, AC97_AD_CODEC_CFG, 0x0002);		// ID1C
14291da177e4SLinus Torvalds 	ac97->spec.ad18xx.codec_cfg[unchained_idx] = 0x0002;
14301da177e4SLinus Torvalds 	if (cidx1 >= 0) {
14311da177e4SLinus Torvalds 		if (patch_ad1881_chained1(ac97, cidx1, 0x0006))		// SDIE | ID1C
14321da177e4SLinus Torvalds 			patch_ad1881_chained1(ac97, cidx2, 0);
14331da177e4SLinus Torvalds 		else if (patch_ad1881_chained1(ac97, cidx2, 0x0006))	// SDIE | ID1C
14341da177e4SLinus Torvalds 			patch_ad1881_chained1(ac97, cidx1, 0);
14351da177e4SLinus Torvalds 	} else if (cidx2 >= 0) {
14361da177e4SLinus Torvalds 		patch_ad1881_chained1(ac97, cidx2, 0);
14371da177e4SLinus Torvalds 	}
14381da177e4SLinus Torvalds }
14391da177e4SLinus Torvalds 
14401da177e4SLinus Torvalds static struct snd_ac97_build_ops patch_ad1881_build_ops = {
14411da177e4SLinus Torvalds #ifdef CONFIG_PM
14421da177e4SLinus Torvalds 	.resume = ad18xx_resume
14431da177e4SLinus Torvalds #endif
14441da177e4SLinus Torvalds };
14451da177e4SLinus Torvalds 
1446ee42381eSTakashi Iwai int patch_ad1881(struct snd_ac97 * ac97)
14471da177e4SLinus Torvalds {
14481da177e4SLinus Torvalds 	static const char cfg_idxs[3][2] = {
14491da177e4SLinus Torvalds 		{2, 1},
14501da177e4SLinus Torvalds 		{0, 2},
14511da177e4SLinus Torvalds 		{0, 1}
14521da177e4SLinus Torvalds 	};
14531da177e4SLinus Torvalds 
14541da177e4SLinus Torvalds 	// patch for Analog Devices
14551da177e4SLinus Torvalds 	unsigned short codecs[3];
14561da177e4SLinus Torvalds 	unsigned short val;
14571da177e4SLinus Torvalds 	int idx, num;
14581da177e4SLinus Torvalds 
14591da177e4SLinus Torvalds 	val = snd_ac97_read(ac97, AC97_AD_SERIAL_CFG);
14601da177e4SLinus Torvalds 	snd_ac97_write_cache(ac97, AC97_AD_SERIAL_CFG, val);
14611da177e4SLinus Torvalds 	codecs[0] = patch_ad1881_unchained(ac97, 0, (1<<12));
14621da177e4SLinus Torvalds 	codecs[1] = patch_ad1881_unchained(ac97, 1, (1<<14));
14631da177e4SLinus Torvalds 	codecs[2] = patch_ad1881_unchained(ac97, 2, (1<<13));
14641da177e4SLinus Torvalds 
14657c22f1aaSTakashi Iwai 	if (! (codecs[0] || codecs[1] || codecs[2]))
14667c22f1aaSTakashi Iwai 		goto __end;
14671da177e4SLinus Torvalds 
14681da177e4SLinus Torvalds 	for (idx = 0; idx < 3; idx++)
14691da177e4SLinus Torvalds 		if (ac97->spec.ad18xx.unchained[idx])
14701da177e4SLinus Torvalds 			patch_ad1881_chained(ac97, idx, cfg_idxs[idx][0], cfg_idxs[idx][1]);
14711da177e4SLinus Torvalds 
14721da177e4SLinus Torvalds 	if (ac97->spec.ad18xx.id[1]) {
14731da177e4SLinus Torvalds 		ac97->flags |= AC97_AD_MULTI;
14741da177e4SLinus Torvalds 		ac97->scaps |= AC97_SCAP_SURROUND_DAC;
14751da177e4SLinus Torvalds 	}
14761da177e4SLinus Torvalds 	if (ac97->spec.ad18xx.id[2]) {
14771da177e4SLinus Torvalds 		ac97->flags |= AC97_AD_MULTI;
14781da177e4SLinus Torvalds 		ac97->scaps |= AC97_SCAP_CENTER_LFE_DAC;
14791da177e4SLinus Torvalds 	}
14801da177e4SLinus Torvalds 
14811da177e4SLinus Torvalds       __end:
14821da177e4SLinus Torvalds 	/* select all codecs */
14831da177e4SLinus Torvalds 	snd_ac97_update_bits(ac97, AC97_AD_SERIAL_CFG, 0x7000, 0x7000);
14841da177e4SLinus Torvalds 	/* check if only one codec is present */
14851da177e4SLinus Torvalds 	for (idx = num = 0; idx < 3; idx++)
14861da177e4SLinus Torvalds 		if (ac97->spec.ad18xx.id[idx])
14871da177e4SLinus Torvalds 			num++;
14881da177e4SLinus Torvalds 	if (num == 1) {
14891da177e4SLinus Torvalds 		/* ok, deselect all ID bits */
14901da177e4SLinus Torvalds 		snd_ac97_write_cache(ac97, AC97_AD_CODEC_CFG, 0x0000);
14911da177e4SLinus Torvalds 		ac97->spec.ad18xx.codec_cfg[0] =
14921da177e4SLinus Torvalds 			ac97->spec.ad18xx.codec_cfg[1] =
14931da177e4SLinus Torvalds 			ac97->spec.ad18xx.codec_cfg[2] = 0x0000;
14941da177e4SLinus Torvalds 	}
14951da177e4SLinus Torvalds 	/* required for AD1886/AD1885 combination */
14961da177e4SLinus Torvalds 	ac97->ext_id = snd_ac97_read(ac97, AC97_EXTENDED_ID);
14971da177e4SLinus Torvalds 	if (ac97->spec.ad18xx.id[0]) {
14981da177e4SLinus Torvalds 		ac97->id &= 0xffff0000;
14991da177e4SLinus Torvalds 		ac97->id |= ac97->spec.ad18xx.id[0];
15001da177e4SLinus Torvalds 	}
15011da177e4SLinus Torvalds 	ac97->build_ops = &patch_ad1881_build_ops;
15021da177e4SLinus Torvalds 	return 0;
15031da177e4SLinus Torvalds }
15041da177e4SLinus Torvalds 
1505ee42381eSTakashi Iwai static const struct snd_kcontrol_new snd_ac97_controls_ad1885[] = {
15061da177e4SLinus Torvalds 	AC97_SINGLE("Digital Mono Direct", AC97_AD_MISC, 11, 1, 0),
15071da177e4SLinus Torvalds 	/* AC97_SINGLE("Digital Audio Mode", AC97_AD_MISC, 12, 1, 0), */ /* seems problematic */
15081da177e4SLinus Torvalds 	AC97_SINGLE("Low Power Mixer", AC97_AD_MISC, 14, 1, 0),
15091da177e4SLinus Torvalds 	AC97_SINGLE("Zero Fill DAC", AC97_AD_MISC, 15, 1, 0),
15101da177e4SLinus Torvalds 	AC97_SINGLE("Headphone Jack Sense", AC97_AD_JACK_SPDIF, 9, 1, 1), /* inverted */
15111da177e4SLinus Torvalds 	AC97_SINGLE("Line Jack Sense", AC97_AD_JACK_SPDIF, 8, 1, 1), /* inverted */
15121da177e4SLinus Torvalds };
15131da177e4SLinus Torvalds 
1514ee42381eSTakashi Iwai static int patch_ad1885_specific(struct snd_ac97 * ac97)
15151da177e4SLinus Torvalds {
15161da177e4SLinus Torvalds 	int err;
15171da177e4SLinus Torvalds 
15181da177e4SLinus Torvalds 	if ((err = patch_build_controls(ac97, snd_ac97_controls_ad1885, ARRAY_SIZE(snd_ac97_controls_ad1885))) < 0)
15191da177e4SLinus Torvalds 		return err;
15201da177e4SLinus Torvalds 	return 0;
15211da177e4SLinus Torvalds }
15221da177e4SLinus Torvalds 
15231da177e4SLinus Torvalds static struct snd_ac97_build_ops patch_ad1885_build_ops = {
15241da177e4SLinus Torvalds 	.build_specific = &patch_ad1885_specific,
15251da177e4SLinus Torvalds #ifdef CONFIG_PM
15261da177e4SLinus Torvalds 	.resume = ad18xx_resume
15271da177e4SLinus Torvalds #endif
15281da177e4SLinus Torvalds };
15291da177e4SLinus Torvalds 
1530ee42381eSTakashi Iwai int patch_ad1885(struct snd_ac97 * ac97)
15311da177e4SLinus Torvalds {
15321da177e4SLinus Torvalds 	patch_ad1881(ac97);
15331da177e4SLinus Torvalds 	/* This is required to deal with the Intel D815EEAL2 */
15341da177e4SLinus Torvalds 	/* i.e. Line out is actually headphone out from codec */
15351da177e4SLinus Torvalds 
15361da177e4SLinus Torvalds 	/* set default */
15371da177e4SLinus Torvalds 	snd_ac97_write_cache(ac97, AC97_AD_MISC, 0x0404);
15381da177e4SLinus Torvalds 
15391da177e4SLinus Torvalds 	ac97->build_ops = &patch_ad1885_build_ops;
15401da177e4SLinus Torvalds 	return 0;
15411da177e4SLinus Torvalds }
15421da177e4SLinus Torvalds 
1543ee42381eSTakashi Iwai int patch_ad1886(struct snd_ac97 * ac97)
15441da177e4SLinus Torvalds {
15451da177e4SLinus Torvalds 	patch_ad1881(ac97);
15461da177e4SLinus Torvalds 	/* Presario700 workaround */
15471da177e4SLinus Torvalds 	/* for Jack Sense/SPDIF Register misetting causing */
15481da177e4SLinus Torvalds 	snd_ac97_write_cache(ac97, AC97_AD_JACK_SPDIF, 0x0010);
15491da177e4SLinus Torvalds 	return 0;
15501da177e4SLinus Torvalds }
15511da177e4SLinus Torvalds 
15521da177e4SLinus Torvalds /* MISC bits */
15531da177e4SLinus Torvalds #define AC97_AD198X_MBC		0x0003	/* mic boost */
15541da177e4SLinus Torvalds #define AC97_AD198X_MBC_20	0x0000	/* +20dB */
15551da177e4SLinus Torvalds #define AC97_AD198X_MBC_10	0x0001	/* +10dB */
15561da177e4SLinus Torvalds #define AC97_AD198X_MBC_30	0x0002	/* +30dB */
15571da177e4SLinus Torvalds #define AC97_AD198X_VREFD	0x0004	/* VREF high-Z */
15581da177e4SLinus Torvalds #define AC97_AD198X_VREFH	0x0008	/* 2.25V, 3.7V */
15591da177e4SLinus Torvalds #define AC97_AD198X_VREF_0	0x000c	/* 0V */
15601da177e4SLinus Torvalds #define AC97_AD198X_SRU		0x0010	/* sample rate unlock */
15611da177e4SLinus Torvalds #define AC97_AD198X_LOSEL	0x0020	/* LINE_OUT amplifiers input select */
15621da177e4SLinus Torvalds #define AC97_AD198X_2MIC	0x0040	/* 2-channel mic select */
15631da177e4SLinus Torvalds #define AC97_AD198X_SPRD	0x0080	/* SPREAD enable */
15641da177e4SLinus Torvalds #define AC97_AD198X_DMIX0	0x0100	/* downmix mode: 0 = 6-to-4, 1 = 6-to-2 downmix */
15651da177e4SLinus Torvalds #define AC97_AD198X_DMIX1	0x0200	/* downmix mode: 1 = enabled */
15661da177e4SLinus Torvalds #define AC97_AD198X_HPSEL	0x0400	/* headphone amplifier input select */
15671da177e4SLinus Torvalds #define AC97_AD198X_CLDIS	0x0800	/* center/lfe disable */
15681da177e4SLinus Torvalds #define AC97_AD198X_LODIS	0x1000	/* LINE_OUT disable */
15691da177e4SLinus Torvalds #define AC97_AD198X_MSPLT	0x2000	/* mute split */
15701da177e4SLinus Torvalds #define AC97_AD198X_AC97NC	0x4000	/* AC97 no compatible mode */
15711da177e4SLinus Torvalds #define AC97_AD198X_DACZ	0x8000	/* DAC zero-fill mode */
15721da177e4SLinus Torvalds 
15731da177e4SLinus Torvalds 
1574ee42381eSTakashi Iwai static int snd_ac97_ad198x_spdif_source_info(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_info *uinfo)
15751da177e4SLinus Torvalds {
15761da177e4SLinus Torvalds 	static char *texts[2] = { "AC-Link", "A/D Converter" };
15771da177e4SLinus Torvalds 
15781da177e4SLinus Torvalds 	uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED;
15791da177e4SLinus Torvalds 	uinfo->count = 1;
15801da177e4SLinus Torvalds 	uinfo->value.enumerated.items = 2;
15811da177e4SLinus Torvalds 	if (uinfo->value.enumerated.item > 1)
15821da177e4SLinus Torvalds 		uinfo->value.enumerated.item = 1;
15831da177e4SLinus Torvalds 	strcpy(uinfo->value.enumerated.name, texts[uinfo->value.enumerated.item]);
15841da177e4SLinus Torvalds 	return 0;
15851da177e4SLinus Torvalds }
15861da177e4SLinus Torvalds 
1587ee42381eSTakashi Iwai static int snd_ac97_ad198x_spdif_source_get(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
15881da177e4SLinus Torvalds {
1589ee42381eSTakashi Iwai 	struct snd_ac97 *ac97 = snd_kcontrol_chip(kcontrol);
15901da177e4SLinus Torvalds 	unsigned short val;
15911da177e4SLinus Torvalds 
15921da177e4SLinus Torvalds 	val = ac97->regs[AC97_AD_SERIAL_CFG];
15931da177e4SLinus Torvalds 	ucontrol->value.enumerated.item[0] = (val >> 2) & 1;
15941da177e4SLinus Torvalds 	return 0;
15951da177e4SLinus Torvalds }
15961da177e4SLinus Torvalds 
1597ee42381eSTakashi Iwai static int snd_ac97_ad198x_spdif_source_put(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
15981da177e4SLinus Torvalds {
1599ee42381eSTakashi Iwai 	struct snd_ac97 *ac97 = snd_kcontrol_chip(kcontrol);
16001da177e4SLinus Torvalds 	unsigned short val;
16011da177e4SLinus Torvalds 
16021da177e4SLinus Torvalds 	if (ucontrol->value.enumerated.item[0] > 1)
16031da177e4SLinus Torvalds 		return -EINVAL;
16041da177e4SLinus Torvalds 	val = ucontrol->value.enumerated.item[0] << 2;
16051da177e4SLinus Torvalds 	return snd_ac97_update_bits(ac97, AC97_AD_SERIAL_CFG, 0x0004, val);
16061da177e4SLinus Torvalds }
16071da177e4SLinus Torvalds 
1608ee42381eSTakashi Iwai static const struct snd_kcontrol_new snd_ac97_ad198x_spdif_source = {
16091da177e4SLinus Torvalds 	.iface	= SNDRV_CTL_ELEM_IFACE_MIXER,
16101da177e4SLinus Torvalds 	.name	= SNDRV_CTL_NAME_IEC958("",PLAYBACK,NONE) "Source",
16111da177e4SLinus Torvalds 	.info	= snd_ac97_ad198x_spdif_source_info,
16121da177e4SLinus Torvalds 	.get	= snd_ac97_ad198x_spdif_source_get,
16131da177e4SLinus Torvalds 	.put	= snd_ac97_ad198x_spdif_source_put,
16141da177e4SLinus Torvalds };
16151da177e4SLinus Torvalds 
1616ee42381eSTakashi Iwai static int patch_ad198x_post_spdif(struct snd_ac97 * ac97)
16171da177e4SLinus Torvalds {
16181da177e4SLinus Torvalds  	return patch_build_controls(ac97, &snd_ac97_ad198x_spdif_source, 1);
16191da177e4SLinus Torvalds }
16201da177e4SLinus Torvalds 
1621ee42381eSTakashi Iwai static const struct snd_kcontrol_new snd_ac97_ad1981x_jack_sense[] = {
16221da177e4SLinus Torvalds 	AC97_SINGLE("Headphone Jack Sense", AC97_AD_JACK_SPDIF, 11, 1, 0),
16231da177e4SLinus Torvalds 	AC97_SINGLE("Line Jack Sense", AC97_AD_JACK_SPDIF, 12, 1, 0),
16241da177e4SLinus Torvalds };
16251da177e4SLinus Torvalds 
1626128a46a5STakashi Iwai /* black list to avoid HP/Line jack-sense controls
1627128a46a5STakashi Iwai  * (SS vendor << 16 | device)
1628128a46a5STakashi Iwai  */
1629128a46a5STakashi Iwai static unsigned int ad1981_jacks_blacklist[] = {
1630128a46a5STakashi Iwai 	0x10140554, /* Thinkpad T42p/R50p */
1631128a46a5STakashi Iwai 	0 /* end */
1632128a46a5STakashi Iwai };
1633128a46a5STakashi Iwai 
1634128a46a5STakashi Iwai static int check_list(struct snd_ac97 *ac97, const unsigned int *list)
1635128a46a5STakashi Iwai {
1636128a46a5STakashi Iwai 	u32 subid = ((u32)ac97->subsystem_vendor << 16) | ac97->subsystem_device;
1637128a46a5STakashi Iwai 	for (; *list; list++)
1638128a46a5STakashi Iwai 		if (*list == subid)
1639128a46a5STakashi Iwai 			return 1;
1640128a46a5STakashi Iwai 	return 0;
1641128a46a5STakashi Iwai }
1642128a46a5STakashi Iwai 
1643ee42381eSTakashi Iwai static int patch_ad1981a_specific(struct snd_ac97 * ac97)
16441da177e4SLinus Torvalds {
1645128a46a5STakashi Iwai 	if (check_list(ac97, ad1981_jacks_blacklist))
1646128a46a5STakashi Iwai 		return 0;
16471da177e4SLinus Torvalds 	return patch_build_controls(ac97, snd_ac97_ad1981x_jack_sense,
16481da177e4SLinus Torvalds 				    ARRAY_SIZE(snd_ac97_ad1981x_jack_sense));
16491da177e4SLinus Torvalds }
16501da177e4SLinus Torvalds 
16511da177e4SLinus Torvalds static struct snd_ac97_build_ops patch_ad1981a_build_ops = {
16521da177e4SLinus Torvalds 	.build_post_spdif = patch_ad198x_post_spdif,
16531da177e4SLinus Torvalds 	.build_specific = patch_ad1981a_specific,
16541da177e4SLinus Torvalds #ifdef CONFIG_PM
16551da177e4SLinus Torvalds 	.resume = ad18xx_resume
16561da177e4SLinus Torvalds #endif
16571da177e4SLinus Torvalds };
16581da177e4SLinus Torvalds 
1659128a46a5STakashi Iwai /* white list to enable HP jack-sense bits
1660128a46a5STakashi Iwai  * (SS vendor << 16 | device)
1661128a46a5STakashi Iwai  */
1662128a46a5STakashi Iwai static unsigned int ad1981_jacks_whitelist[] = {
1663128a46a5STakashi Iwai 	0x0e11005a, /* HP nc4000/4010 */
1664128a46a5STakashi Iwai 	0x103c0890, /* HP nc6000 */
1665128a46a5STakashi Iwai 	0x103c0938, /* HP nc4220 */
1666128a46a5STakashi Iwai 	0x103c099c, /* HP nx6110 */
1667128a46a5STakashi Iwai 	0x103c0944, /* HP nc6220 */
1668128a46a5STakashi Iwai 	0x103c0934, /* HP nc8220 */
1669128a46a5STakashi Iwai 	0x103c006d, /* HP nx9105 */
1670128a46a5STakashi Iwai 	0x17340088, /* FSC Scenic-W */
1671128a46a5STakashi Iwai 	0 /* end */
1672128a46a5STakashi Iwai };
1673128a46a5STakashi Iwai 
1674ee42381eSTakashi Iwai static void check_ad1981_hp_jack_sense(struct snd_ac97 *ac97)
16751da177e4SLinus Torvalds {
1676128a46a5STakashi Iwai 	if (check_list(ac97, ad1981_jacks_whitelist))
16771da177e4SLinus Torvalds 		/* enable headphone jack sense */
16781da177e4SLinus Torvalds 		snd_ac97_update_bits(ac97, AC97_AD_JACK_SPDIF, 1<<11, 1<<11);
16791da177e4SLinus Torvalds }
16801da177e4SLinus Torvalds 
1681ee42381eSTakashi Iwai int patch_ad1981a(struct snd_ac97 *ac97)
16821da177e4SLinus Torvalds {
16831da177e4SLinus Torvalds 	patch_ad1881(ac97);
16841da177e4SLinus Torvalds 	ac97->build_ops = &patch_ad1981a_build_ops;
16851da177e4SLinus Torvalds 	snd_ac97_update_bits(ac97, AC97_AD_MISC, AC97_AD198X_MSPLT, AC97_AD198X_MSPLT);
16861da177e4SLinus Torvalds 	ac97->flags |= AC97_STEREO_MUTES;
16871da177e4SLinus Torvalds 	check_ad1981_hp_jack_sense(ac97);
16881da177e4SLinus Torvalds 	return 0;
16891da177e4SLinus Torvalds }
16901da177e4SLinus Torvalds 
1691ee42381eSTakashi Iwai static const struct snd_kcontrol_new snd_ac97_ad198x_2cmic =
16921da177e4SLinus Torvalds AC97_SINGLE("Stereo Mic", AC97_AD_MISC, 6, 1, 0);
16931da177e4SLinus Torvalds 
1694ee42381eSTakashi Iwai static int patch_ad1981b_specific(struct snd_ac97 *ac97)
16951da177e4SLinus Torvalds {
16961da177e4SLinus Torvalds 	int err;
16971da177e4SLinus Torvalds 
16981da177e4SLinus Torvalds 	if ((err = patch_build_controls(ac97, &snd_ac97_ad198x_2cmic, 1)) < 0)
16991da177e4SLinus Torvalds 		return err;
1700128a46a5STakashi Iwai 	if (check_list(ac97, ad1981_jacks_blacklist))
1701128a46a5STakashi Iwai 		return 0;
17021da177e4SLinus Torvalds 	return patch_build_controls(ac97, snd_ac97_ad1981x_jack_sense,
17031da177e4SLinus Torvalds 				    ARRAY_SIZE(snd_ac97_ad1981x_jack_sense));
17041da177e4SLinus Torvalds }
17051da177e4SLinus Torvalds 
17061da177e4SLinus Torvalds static struct snd_ac97_build_ops patch_ad1981b_build_ops = {
17071da177e4SLinus Torvalds 	.build_post_spdif = patch_ad198x_post_spdif,
17081da177e4SLinus Torvalds 	.build_specific = patch_ad1981b_specific,
17091da177e4SLinus Torvalds #ifdef CONFIG_PM
17101da177e4SLinus Torvalds 	.resume = ad18xx_resume
17111da177e4SLinus Torvalds #endif
17121da177e4SLinus Torvalds };
17131da177e4SLinus Torvalds 
1714ee42381eSTakashi Iwai int patch_ad1981b(struct snd_ac97 *ac97)
17151da177e4SLinus Torvalds {
17161da177e4SLinus Torvalds 	patch_ad1881(ac97);
17171da177e4SLinus Torvalds 	ac97->build_ops = &patch_ad1981b_build_ops;
17181da177e4SLinus Torvalds 	snd_ac97_update_bits(ac97, AC97_AD_MISC, AC97_AD198X_MSPLT, AC97_AD198X_MSPLT);
17191da177e4SLinus Torvalds 	ac97->flags |= AC97_STEREO_MUTES;
17201da177e4SLinus Torvalds 	check_ad1981_hp_jack_sense(ac97);
17211da177e4SLinus Torvalds 	return 0;
17221da177e4SLinus Torvalds }
17231da177e4SLinus Torvalds 
1724ee42381eSTakashi Iwai static int snd_ac97_ad1888_lohpsel_info(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_info *uinfo)
17251da177e4SLinus Torvalds {
17261da177e4SLinus Torvalds 	uinfo->type = SNDRV_CTL_ELEM_TYPE_BOOLEAN;
17271da177e4SLinus Torvalds 	uinfo->count = 1;
17281da177e4SLinus Torvalds 	uinfo->value.integer.min = 0;
17291da177e4SLinus Torvalds 	uinfo->value.integer.max = 1;
17301da177e4SLinus Torvalds 	return 0;
17311da177e4SLinus Torvalds }
17321da177e4SLinus Torvalds 
1733ee42381eSTakashi Iwai static int snd_ac97_ad1888_lohpsel_get(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
17341da177e4SLinus Torvalds {
1735ee42381eSTakashi Iwai 	struct snd_ac97 *ac97 = snd_kcontrol_chip(kcontrol);
17361da177e4SLinus Torvalds 	unsigned short val;
17371da177e4SLinus Torvalds 
17381da177e4SLinus Torvalds 	val = ac97->regs[AC97_AD_MISC];
17391da177e4SLinus Torvalds 	ucontrol->value.integer.value[0] = !(val & AC97_AD198X_LOSEL);
17401da177e4SLinus Torvalds 	return 0;
17411da177e4SLinus Torvalds }
17421da177e4SLinus Torvalds 
1743ee42381eSTakashi Iwai static int snd_ac97_ad1888_lohpsel_put(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
17441da177e4SLinus Torvalds {
1745ee42381eSTakashi Iwai 	struct snd_ac97 *ac97 = snd_kcontrol_chip(kcontrol);
17461da177e4SLinus Torvalds 	unsigned short val;
17471da177e4SLinus Torvalds 
17481da177e4SLinus Torvalds 	val = !ucontrol->value.integer.value[0]
17491da177e4SLinus Torvalds 		? (AC97_AD198X_LOSEL | AC97_AD198X_HPSEL) : 0;
17501da177e4SLinus Torvalds 	return snd_ac97_update_bits(ac97, AC97_AD_MISC,
17511da177e4SLinus Torvalds 				    AC97_AD198X_LOSEL | AC97_AD198X_HPSEL, val);
17521da177e4SLinus Torvalds }
17531da177e4SLinus Torvalds 
1754ee42381eSTakashi Iwai static int snd_ac97_ad1888_downmix_info(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_info *uinfo)
17551da177e4SLinus Torvalds {
17561da177e4SLinus Torvalds 	static char *texts[3] = {"Off", "6 -> 4", "6 -> 2"};
17571da177e4SLinus Torvalds 
17581da177e4SLinus Torvalds 	uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED;
17591da177e4SLinus Torvalds 	uinfo->count = 1;
17601da177e4SLinus Torvalds 	uinfo->value.enumerated.items = 3;
17611da177e4SLinus Torvalds 	if (uinfo->value.enumerated.item > 2)
17621da177e4SLinus Torvalds 		uinfo->value.enumerated.item = 2;
17631da177e4SLinus Torvalds 	strcpy(uinfo->value.enumerated.name, texts[uinfo->value.enumerated.item]);
17641da177e4SLinus Torvalds 	return 0;
17651da177e4SLinus Torvalds }
17661da177e4SLinus Torvalds 
1767ee42381eSTakashi Iwai static int snd_ac97_ad1888_downmix_get(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
17681da177e4SLinus Torvalds {
1769ee42381eSTakashi Iwai 	struct snd_ac97 *ac97 = snd_kcontrol_chip(kcontrol);
17701da177e4SLinus Torvalds 	unsigned short val;
17711da177e4SLinus Torvalds 
17721da177e4SLinus Torvalds 	val = ac97->regs[AC97_AD_MISC];
17731da177e4SLinus Torvalds 	if (!(val & AC97_AD198X_DMIX1))
17741da177e4SLinus Torvalds 		ucontrol->value.enumerated.item[0] = 0;
17751da177e4SLinus Torvalds 	else
17761da177e4SLinus Torvalds 		ucontrol->value.enumerated.item[0] = 1 + ((val >> 8) & 1);
17771da177e4SLinus Torvalds 	return 0;
17781da177e4SLinus Torvalds }
17791da177e4SLinus Torvalds 
1780ee42381eSTakashi Iwai static int snd_ac97_ad1888_downmix_put(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
17811da177e4SLinus Torvalds {
1782ee42381eSTakashi Iwai 	struct snd_ac97 *ac97 = snd_kcontrol_chip(kcontrol);
17831da177e4SLinus Torvalds 	unsigned short val;
17841da177e4SLinus Torvalds 
17851da177e4SLinus Torvalds 	if (ucontrol->value.enumerated.item[0] > 2)
17861da177e4SLinus Torvalds 		return -EINVAL;
17871da177e4SLinus Torvalds 	if (ucontrol->value.enumerated.item[0] == 0)
17881da177e4SLinus Torvalds 		val = 0;
17891da177e4SLinus Torvalds 	else
17901da177e4SLinus Torvalds 		val = AC97_AD198X_DMIX1 |
17911da177e4SLinus Torvalds 			((ucontrol->value.enumerated.item[0] - 1) << 8);
17921da177e4SLinus Torvalds 	return snd_ac97_update_bits(ac97, AC97_AD_MISC,
17931da177e4SLinus Torvalds 				    AC97_AD198X_DMIX0 | AC97_AD198X_DMIX1, val);
17941da177e4SLinus Torvalds }
17951da177e4SLinus Torvalds 
1796ee42381eSTakashi Iwai static void ad1888_update_jacks(struct snd_ac97 *ac97)
1797eb8caf30STakashi Iwai {
17984525c9f3STakashi Iwai 	unsigned short val = 0;
17994525c9f3STakashi Iwai 	if (! is_shared_linein(ac97))
18004525c9f3STakashi Iwai 		val |= (1 << 12);
18014525c9f3STakashi Iwai 	if (! is_shared_micin(ac97))
18024525c9f3STakashi Iwai 		val |= (1 << 11);
1803eb8caf30STakashi Iwai 	/* shared Line-In */
18044525c9f3STakashi Iwai 	snd_ac97_update_bits(ac97, AC97_AD_MISC, (1 << 11) | (1 << 12), val);
1805eb8caf30STakashi Iwai }
1806eb8caf30STakashi Iwai 
1807ee42381eSTakashi Iwai static const struct snd_kcontrol_new snd_ac97_ad1888_controls[] = {
18081da177e4SLinus Torvalds 	{
18091da177e4SLinus Torvalds 		.iface = SNDRV_CTL_ELEM_IFACE_MIXER,
18101da177e4SLinus Torvalds 		.name = "Exchange Front/Surround",
18111da177e4SLinus Torvalds 		.info = snd_ac97_ad1888_lohpsel_info,
18121da177e4SLinus Torvalds 		.get = snd_ac97_ad1888_lohpsel_get,
18131da177e4SLinus Torvalds 		.put = snd_ac97_ad1888_lohpsel_put
18141da177e4SLinus Torvalds 	},
18151da177e4SLinus Torvalds 	AC97_SINGLE("Spread Front to Surround and Center/LFE", AC97_AD_MISC, 7, 1, 0),
18161da177e4SLinus Torvalds 	{
18171da177e4SLinus Torvalds 		.iface = SNDRV_CTL_ELEM_IFACE_MIXER,
18181da177e4SLinus Torvalds 		.name = "Downmix",
18191da177e4SLinus Torvalds 		.info = snd_ac97_ad1888_downmix_info,
18201da177e4SLinus Torvalds 		.get = snd_ac97_ad1888_downmix_get,
18211da177e4SLinus Torvalds 		.put = snd_ac97_ad1888_downmix_put
18221da177e4SLinus Torvalds 	},
1823eb8caf30STakashi Iwai 	AC97_SURROUND_JACK_MODE_CTL,
1824eb8caf30STakashi Iwai 	AC97_CHANNEL_MODE_CTL,
1825eeacb545SSergey Ulanov 
1826eeacb545SSergey Ulanov 	AC97_SINGLE("Headphone Jack Sense", AC97_AD_JACK_SPDIF, 10, 1, 0),
1827eeacb545SSergey Ulanov 	AC97_SINGLE("Line Jack Sense", AC97_AD_JACK_SPDIF, 12, 1, 0),
18281da177e4SLinus Torvalds };
18291da177e4SLinus Torvalds 
1830ee42381eSTakashi Iwai static int patch_ad1888_specific(struct snd_ac97 *ac97)
18311da177e4SLinus Torvalds {
18321da177e4SLinus Torvalds 	/* rename 0x04 as "Master" and 0x02 as "Master Surround" */
18331da177e4SLinus Torvalds 	snd_ac97_rename_vol_ctl(ac97, "Master Playback", "Master Surround Playback");
18341da177e4SLinus Torvalds 	snd_ac97_rename_vol_ctl(ac97, "Headphone Playback", "Master Playback");
18351da177e4SLinus Torvalds 	return patch_build_controls(ac97, snd_ac97_ad1888_controls, ARRAY_SIZE(snd_ac97_ad1888_controls));
18361da177e4SLinus Torvalds }
18371da177e4SLinus Torvalds 
18381da177e4SLinus Torvalds static struct snd_ac97_build_ops patch_ad1888_build_ops = {
18391da177e4SLinus Torvalds 	.build_post_spdif = patch_ad198x_post_spdif,
18401da177e4SLinus Torvalds 	.build_specific = patch_ad1888_specific,
18411da177e4SLinus Torvalds #ifdef CONFIG_PM
1842eb8caf30STakashi Iwai 	.resume = ad18xx_resume,
18431da177e4SLinus Torvalds #endif
1844eb8caf30STakashi Iwai 	.update_jacks = ad1888_update_jacks,
18451da177e4SLinus Torvalds };
18461da177e4SLinus Torvalds 
1847ee42381eSTakashi Iwai int patch_ad1888(struct snd_ac97 * ac97)
18481da177e4SLinus Torvalds {
18491da177e4SLinus Torvalds 	unsigned short misc;
18501da177e4SLinus Torvalds 
18511da177e4SLinus Torvalds 	patch_ad1881(ac97);
18521da177e4SLinus Torvalds 	ac97->build_ops = &patch_ad1888_build_ops;
18531da177e4SLinus Torvalds 	/* Switch FRONT/SURROUND LINE-OUT/HP-OUT default connection */
18541da177e4SLinus Torvalds 	/* it seems that most vendors connect line-out connector to headphone out of AC'97 */
18551da177e4SLinus Torvalds 	/* AD-compatible mode */
18561da177e4SLinus Torvalds 	/* Stereo mutes enabled */
18571da177e4SLinus Torvalds 	misc = snd_ac97_read(ac97, AC97_AD_MISC);
18581da177e4SLinus Torvalds 	snd_ac97_write_cache(ac97, AC97_AD_MISC, misc |
18591da177e4SLinus Torvalds 			     AC97_AD198X_LOSEL |
18601da177e4SLinus Torvalds 			     AC97_AD198X_HPSEL |
18611da177e4SLinus Torvalds 			     AC97_AD198X_MSPLT |
18621da177e4SLinus Torvalds 			     AC97_AD198X_AC97NC);
18631da177e4SLinus Torvalds 	ac97->flags |= AC97_STEREO_MUTES;
18641da177e4SLinus Torvalds 	return 0;
18651da177e4SLinus Torvalds }
18661da177e4SLinus Torvalds 
1867ee42381eSTakashi Iwai static int patch_ad1980_specific(struct snd_ac97 *ac97)
18681da177e4SLinus Torvalds {
18691da177e4SLinus Torvalds 	int err;
18701da177e4SLinus Torvalds 
18711da177e4SLinus Torvalds 	if ((err = patch_ad1888_specific(ac97)) < 0)
18721da177e4SLinus Torvalds 		return err;
18731da177e4SLinus Torvalds 	return patch_build_controls(ac97, &snd_ac97_ad198x_2cmic, 1);
18741da177e4SLinus Torvalds }
18751da177e4SLinus Torvalds 
18761da177e4SLinus Torvalds static struct snd_ac97_build_ops patch_ad1980_build_ops = {
18771da177e4SLinus Torvalds 	.build_post_spdif = patch_ad198x_post_spdif,
18781da177e4SLinus Torvalds 	.build_specific = patch_ad1980_specific,
18791da177e4SLinus Torvalds #ifdef CONFIG_PM
1880462c4173SClemens Ladisch 	.resume = ad18xx_resume,
18811da177e4SLinus Torvalds #endif
1882462c4173SClemens Ladisch 	.update_jacks = ad1888_update_jacks,
18831da177e4SLinus Torvalds };
18841da177e4SLinus Torvalds 
1885ee42381eSTakashi Iwai int patch_ad1980(struct snd_ac97 * ac97)
18861da177e4SLinus Torvalds {
18871da177e4SLinus Torvalds 	patch_ad1888(ac97);
18881da177e4SLinus Torvalds 	ac97->build_ops = &patch_ad1980_build_ops;
18891da177e4SLinus Torvalds 	return 0;
18901da177e4SLinus Torvalds }
18911da177e4SLinus Torvalds 
1892ee42381eSTakashi Iwai static const struct snd_kcontrol_new snd_ac97_ad1985_controls[] = {
18931da177e4SLinus Torvalds 	AC97_SINGLE("Exchange Center/LFE", AC97_AD_SERIAL_CFG, 3, 1, 0)
18941da177e4SLinus Torvalds };
18951da177e4SLinus Torvalds 
1896ee42381eSTakashi Iwai static void ad1985_update_jacks(struct snd_ac97 *ac97)
1897e5b3f45fSTakashi Iwai {
18984525c9f3STakashi Iwai 	ad1888_update_jacks(ac97);
1899fc232c6eSTakashi Iwai 	snd_ac97_update_bits(ac97, AC97_AD_SERIAL_CFG, 1 << 9,
1900fc232c6eSTakashi Iwai 			     is_shared_micin(ac97) ? 0 : 1 << 9);
1901e5b3f45fSTakashi Iwai }
1902e5b3f45fSTakashi Iwai 
1903ee42381eSTakashi Iwai static int patch_ad1985_specific(struct snd_ac97 *ac97)
19041da177e4SLinus Torvalds {
19051da177e4SLinus Torvalds 	int err;
19061da177e4SLinus Torvalds 
19071da177e4SLinus Torvalds 	if ((err = patch_ad1980_specific(ac97)) < 0)
19081da177e4SLinus Torvalds 		return err;
19091da177e4SLinus Torvalds 	return patch_build_controls(ac97, snd_ac97_ad1985_controls, ARRAY_SIZE(snd_ac97_ad1985_controls));
19101da177e4SLinus Torvalds }
19111da177e4SLinus Torvalds 
19121da177e4SLinus Torvalds static struct snd_ac97_build_ops patch_ad1985_build_ops = {
19131da177e4SLinus Torvalds 	.build_post_spdif = patch_ad198x_post_spdif,
19141da177e4SLinus Torvalds 	.build_specific = patch_ad1985_specific,
19151da177e4SLinus Torvalds #ifdef CONFIG_PM
1916462c4173SClemens Ladisch 	.resume = ad18xx_resume,
19171da177e4SLinus Torvalds #endif
1918e5b3f45fSTakashi Iwai 	.update_jacks = ad1985_update_jacks,
19191da177e4SLinus Torvalds };
19201da177e4SLinus Torvalds 
1921ee42381eSTakashi Iwai int patch_ad1985(struct snd_ac97 * ac97)
19221da177e4SLinus Torvalds {
19231da177e4SLinus Torvalds 	unsigned short misc;
19241da177e4SLinus Torvalds 
19251da177e4SLinus Torvalds 	patch_ad1881(ac97);
19261da177e4SLinus Torvalds 	ac97->build_ops = &patch_ad1985_build_ops;
19271da177e4SLinus Torvalds 	misc = snd_ac97_read(ac97, AC97_AD_MISC);
19281da177e4SLinus Torvalds 	/* switch front/surround line-out/hp-out */
19291da177e4SLinus Torvalds 	/* center/LFE, mic in 3.75V mode */
19301da177e4SLinus Torvalds 	/* AD-compatible mode */
19311da177e4SLinus Torvalds 	/* Stereo mutes enabled */
19321da177e4SLinus Torvalds 	/* in accordance with ADI driver: misc | 0x5c28 */
19331da177e4SLinus Torvalds 	snd_ac97_write_cache(ac97, AC97_AD_MISC, misc |
19341da177e4SLinus Torvalds 			     AC97_AD198X_VREFH |
19351da177e4SLinus Torvalds 			     AC97_AD198X_LOSEL |
19361da177e4SLinus Torvalds 			     AC97_AD198X_HPSEL |
19371da177e4SLinus Torvalds 			     AC97_AD198X_CLDIS |
19381da177e4SLinus Torvalds 			     AC97_AD198X_LODIS |
19391da177e4SLinus Torvalds 			     AC97_AD198X_MSPLT |
19401da177e4SLinus Torvalds 			     AC97_AD198X_AC97NC);
19411da177e4SLinus Torvalds 	ac97->flags |= AC97_STEREO_MUTES;
19421da177e4SLinus Torvalds 	/* on AD1985 rev. 3, AC'97 revision bits are zero */
19431da177e4SLinus Torvalds 	ac97->ext_id = (ac97->ext_id & ~AC97_EI_REV_MASK) | AC97_EI_REV_23;
19441da177e4SLinus Torvalds 	return 0;
19451da177e4SLinus Torvalds }
19461da177e4SLinus Torvalds 
19471da177e4SLinus Torvalds /*
19481da177e4SLinus Torvalds  * realtek ALC65x/850 codecs
19491da177e4SLinus Torvalds  */
1950ee42381eSTakashi Iwai static void alc650_update_jacks(struct snd_ac97 *ac97)
19511da177e4SLinus Torvalds {
1952eb8caf30STakashi Iwai 	int shared;
19531da177e4SLinus Torvalds 
1954eb8caf30STakashi Iwai 	/* shared Line-In */
1955eb8caf30STakashi Iwai 	shared = is_shared_linein(ac97);
1956eb8caf30STakashi Iwai 	snd_ac97_update_bits(ac97, AC97_ALC650_MULTICH, 1 << 9,
1957eb8caf30STakashi Iwai 			     shared ? (1 << 9) : 0);
1958eb8caf30STakashi Iwai 	/* update shared Mic */
1959eb8caf30STakashi Iwai 	shared = is_shared_micin(ac97);
19601da177e4SLinus Torvalds 	/* disable/enable vref */
19611da177e4SLinus Torvalds 	snd_ac97_update_bits(ac97, AC97_ALC650_CLOCK, 1 << 12,
1962eb8caf30STakashi Iwai 			     shared ? (1 << 12) : 0);
19631da177e4SLinus Torvalds 	/* turn on/off center-on-mic */
19641da177e4SLinus Torvalds 	snd_ac97_update_bits(ac97, AC97_ALC650_MULTICH, 1 << 10,
1965eb8caf30STakashi Iwai 			     shared ? (1 << 10) : 0);
19661da177e4SLinus Torvalds 	/* GPIO0 high for mic */
19671da177e4SLinus Torvalds 	snd_ac97_update_bits(ac97, AC97_ALC650_GPIO_STATUS, 0x100,
1968eb8caf30STakashi Iwai 			     shared ? 0 : 0x100);
19691da177e4SLinus Torvalds }
19701da177e4SLinus Torvalds 
1971ee42381eSTakashi Iwai static const struct snd_kcontrol_new snd_ac97_controls_alc650[] = {
19721da177e4SLinus Torvalds 	AC97_SINGLE("Duplicate Front", AC97_ALC650_MULTICH, 0, 1, 0),
19731da177e4SLinus Torvalds 	AC97_SINGLE("Surround Down Mix", AC97_ALC650_MULTICH, 1, 1, 0),
19741da177e4SLinus Torvalds 	AC97_SINGLE("Center/LFE Down Mix", AC97_ALC650_MULTICH, 2, 1, 0),
19751da177e4SLinus Torvalds 	AC97_SINGLE("Exchange Center/LFE", AC97_ALC650_MULTICH, 3, 1, 0),
19761da177e4SLinus Torvalds 	/* 4: Analog Input To Surround */
19771da177e4SLinus Torvalds 	/* 5: Analog Input To Center/LFE */
19781da177e4SLinus Torvalds 	/* 6: Independent Master Volume Right */
19791da177e4SLinus Torvalds 	/* 7: Independent Master Volume Left */
19801da177e4SLinus Torvalds 	/* 8: reserved */
1981eb8caf30STakashi Iwai 	/* 9: Line-In/Surround share */
1982eb8caf30STakashi Iwai 	/* 10: Mic/CLFE share */
19831da177e4SLinus Torvalds 	/* 11-13: in IEC958 controls */
19841da177e4SLinus Torvalds 	AC97_SINGLE("Swap Surround Slot", AC97_ALC650_MULTICH, 14, 1, 0),
19851da177e4SLinus Torvalds #if 0 /* always set in patch_alc650 */
19861da177e4SLinus Torvalds 	AC97_SINGLE("IEC958 Input Clock Enable", AC97_ALC650_CLOCK, 0, 1, 0),
19871da177e4SLinus Torvalds 	AC97_SINGLE("IEC958 Input Pin Enable", AC97_ALC650_CLOCK, 1, 1, 0),
19881da177e4SLinus Torvalds 	AC97_SINGLE("Surround DAC Switch", AC97_ALC650_SURR_DAC_VOL, 15, 1, 1),
19891da177e4SLinus Torvalds 	AC97_DOUBLE("Surround DAC Volume", AC97_ALC650_SURR_DAC_VOL, 8, 0, 31, 1),
19901da177e4SLinus Torvalds 	AC97_SINGLE("Center/LFE DAC Switch", AC97_ALC650_LFE_DAC_VOL, 15, 1, 1),
19911da177e4SLinus Torvalds 	AC97_DOUBLE("Center/LFE DAC Volume", AC97_ALC650_LFE_DAC_VOL, 8, 0, 31, 1),
19921da177e4SLinus Torvalds #endif
1993eb8caf30STakashi Iwai 	AC97_SURROUND_JACK_MODE_CTL,
1994eb8caf30STakashi Iwai 	AC97_CHANNEL_MODE_CTL,
19951da177e4SLinus Torvalds };
19961da177e4SLinus Torvalds 
1997ee42381eSTakashi Iwai static const struct snd_kcontrol_new snd_ac97_spdif_controls_alc650[] = {
199810e8d78aSClemens Ladisch         AC97_SINGLE(SNDRV_CTL_NAME_IEC958("",CAPTURE,SWITCH), AC97_ALC650_MULTICH, 11, 1, 0),
19991da177e4SLinus Torvalds         AC97_SINGLE("Analog to IEC958 Output", AC97_ALC650_MULTICH, 12, 1, 0),
20001da177e4SLinus Torvalds 	/* disable this controls since it doesn't work as expected */
20011da177e4SLinus Torvalds 	/* AC97_SINGLE("IEC958 Input Monitor", AC97_ALC650_MULTICH, 13, 1, 0), */
20021da177e4SLinus Torvalds };
20031da177e4SLinus Torvalds 
2004ee42381eSTakashi Iwai static int patch_alc650_specific(struct snd_ac97 * ac97)
20051da177e4SLinus Torvalds {
20061da177e4SLinus Torvalds 	int err;
20071da177e4SLinus Torvalds 
20081da177e4SLinus Torvalds 	if ((err = patch_build_controls(ac97, snd_ac97_controls_alc650, ARRAY_SIZE(snd_ac97_controls_alc650))) < 0)
20091da177e4SLinus Torvalds 		return err;
20101da177e4SLinus Torvalds 	if (ac97->ext_id & AC97_EI_SPDIF) {
20111da177e4SLinus Torvalds 		if ((err = patch_build_controls(ac97, snd_ac97_spdif_controls_alc650, ARRAY_SIZE(snd_ac97_spdif_controls_alc650))) < 0)
20121da177e4SLinus Torvalds 			return err;
20131da177e4SLinus Torvalds 	}
20141da177e4SLinus Torvalds 	return 0;
20151da177e4SLinus Torvalds }
20161da177e4SLinus Torvalds 
20171da177e4SLinus Torvalds static struct snd_ac97_build_ops patch_alc650_ops = {
2018eb8caf30STakashi Iwai 	.build_specific	= patch_alc650_specific,
2019eb8caf30STakashi Iwai 	.update_jacks = alc650_update_jacks
20201da177e4SLinus Torvalds };
20211da177e4SLinus Torvalds 
2022ee42381eSTakashi Iwai int patch_alc650(struct snd_ac97 * ac97)
20231da177e4SLinus Torvalds {
20241da177e4SLinus Torvalds 	unsigned short val;
20251da177e4SLinus Torvalds 
20261da177e4SLinus Torvalds 	ac97->build_ops = &patch_alc650_ops;
20271da177e4SLinus Torvalds 
20281da177e4SLinus Torvalds 	/* determine the revision */
20291da177e4SLinus Torvalds 	val = snd_ac97_read(ac97, AC97_ALC650_REVISION) & 0x3f;
20301da177e4SLinus Torvalds 	if (val < 3)
20311da177e4SLinus Torvalds 		ac97->id = 0x414c4720;          /* Old version */
20321da177e4SLinus Torvalds 	else if (val < 0x10)
20331da177e4SLinus Torvalds 		ac97->id = 0x414c4721;          /* D version */
20341da177e4SLinus Torvalds 	else if (val < 0x20)
20351da177e4SLinus Torvalds 		ac97->id = 0x414c4722;          /* E version */
20361da177e4SLinus Torvalds 	else if (val < 0x30)
20371da177e4SLinus Torvalds 		ac97->id = 0x414c4723;          /* F version */
20381da177e4SLinus Torvalds 
20391da177e4SLinus Torvalds 	/* revision E or F */
20401da177e4SLinus Torvalds 	/* FIXME: what about revision D ? */
20411da177e4SLinus Torvalds 	ac97->spec.dev_flags = (ac97->id == 0x414c4722 ||
20421da177e4SLinus Torvalds 				ac97->id == 0x414c4723);
20431da177e4SLinus Torvalds 
20441da177e4SLinus Torvalds 	/* enable AC97_ALC650_GPIO_SETUP, AC97_ALC650_CLOCK for R/W */
20451da177e4SLinus Torvalds 	snd_ac97_write_cache(ac97, AC97_ALC650_GPIO_STATUS,
20461da177e4SLinus Torvalds 		snd_ac97_read(ac97, AC97_ALC650_GPIO_STATUS) | 0x8000);
20471da177e4SLinus Torvalds 
20481da177e4SLinus Torvalds 	/* Enable SPDIF-IN only on Rev.E and above */
20491da177e4SLinus Torvalds 	val = snd_ac97_read(ac97, AC97_ALC650_CLOCK);
20501da177e4SLinus Torvalds 	/* SPDIF IN with pin 47 */
2051eed65649STakashi Iwai 	if (ac97->spec.dev_flags &&
2052eed65649STakashi Iwai 	    /* ASUS A6KM requires EAPD */
2053eed65649STakashi Iwai 	    ! (ac97->subsystem_vendor == 0x1043 &&
2054eed65649STakashi Iwai 	       ac97->subsystem_device == 0x1103))
20551da177e4SLinus Torvalds 		val |= 0x03; /* enable */
20561da177e4SLinus Torvalds 	else
20571da177e4SLinus Torvalds 		val &= ~0x03; /* disable */
20581da177e4SLinus Torvalds 	snd_ac97_write_cache(ac97, AC97_ALC650_CLOCK, val);
20591da177e4SLinus Torvalds 
20601da177e4SLinus Torvalds 	/* set default: slot 3,4,7,8,6,9
20611da177e4SLinus Torvalds 	   spdif-in monitor off, analog-spdif off, spdif-in off
20621da177e4SLinus Torvalds 	   center on mic off, surround on line-in off
20631da177e4SLinus Torvalds 	   downmix off, duplicate front off
20641da177e4SLinus Torvalds 	*/
20651da177e4SLinus Torvalds 	snd_ac97_write_cache(ac97, AC97_ALC650_MULTICH, 0);
20661da177e4SLinus Torvalds 
20671da177e4SLinus Torvalds 	/* set GPIO0 for mic bias */
20681da177e4SLinus Torvalds 	/* GPIO0 pin output, no interrupt, high */
20691da177e4SLinus Torvalds 	snd_ac97_write_cache(ac97, AC97_ALC650_GPIO_SETUP,
20701da177e4SLinus Torvalds 			     snd_ac97_read(ac97, AC97_ALC650_GPIO_SETUP) | 0x01);
20711da177e4SLinus Torvalds 	snd_ac97_write_cache(ac97, AC97_ALC650_GPIO_STATUS,
20721da177e4SLinus Torvalds 			     (snd_ac97_read(ac97, AC97_ALC650_GPIO_STATUS) | 0x100) & ~0x10);
20731da177e4SLinus Torvalds 
20741da177e4SLinus Torvalds 	/* full DAC volume */
20751da177e4SLinus Torvalds 	snd_ac97_write_cache(ac97, AC97_ALC650_SURR_DAC_VOL, 0x0808);
20761da177e4SLinus Torvalds 	snd_ac97_write_cache(ac97, AC97_ALC650_LFE_DAC_VOL, 0x0808);
20771da177e4SLinus Torvalds 	return 0;
20781da177e4SLinus Torvalds }
20791da177e4SLinus Torvalds 
2080ee42381eSTakashi Iwai static void alc655_update_jacks(struct snd_ac97 *ac97)
20811da177e4SLinus Torvalds {
2082eb8caf30STakashi Iwai 	int shared;
20831da177e4SLinus Torvalds 
2084eb8caf30STakashi Iwai 	/* shared Line-In */
2085eb8caf30STakashi Iwai 	shared = is_shared_linein(ac97);
2086eb8caf30STakashi Iwai 	ac97_update_bits_page(ac97, AC97_ALC650_MULTICH, 1 << 9,
2087eb8caf30STakashi Iwai 			      shared ? (1 << 9) : 0, 0);
2088eb8caf30STakashi Iwai 	/* update shared mic */
2089eb8caf30STakashi Iwai 	shared = is_shared_micin(ac97);
20901da177e4SLinus Torvalds 	/* misc control; vrefout disable */
20911da177e4SLinus Torvalds 	snd_ac97_update_bits(ac97, AC97_ALC650_CLOCK, 1 << 12,
2092eb8caf30STakashi Iwai 			     shared ? (1 << 12) : 0);
2093eb8caf30STakashi Iwai 	ac97_update_bits_page(ac97, AC97_ALC650_MULTICH, 1 << 10,
2094eb8caf30STakashi Iwai 			      shared ? (1 << 10) : 0, 0);
20951da177e4SLinus Torvalds }
20961da177e4SLinus Torvalds 
2097ee42381eSTakashi Iwai static const struct snd_kcontrol_new snd_ac97_controls_alc655[] = {
20981da177e4SLinus Torvalds 	AC97_PAGE_SINGLE("Duplicate Front", AC97_ALC650_MULTICH, 0, 1, 0, 0),
2099eb8caf30STakashi Iwai 	AC97_SURROUND_JACK_MODE_CTL,
2100eb8caf30STakashi Iwai 	AC97_CHANNEL_MODE_CTL,
21011da177e4SLinus Torvalds };
21021da177e4SLinus Torvalds 
2103ee42381eSTakashi Iwai static int alc655_iec958_route_info(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_info *uinfo)
21041da177e4SLinus Torvalds {
21051da177e4SLinus Torvalds 	static char *texts_655[3] = { "PCM", "Analog In", "IEC958 In" };
21061da177e4SLinus Torvalds 	static char *texts_658[4] = { "PCM", "Analog1 In", "Analog2 In", "IEC958 In" };
2107ee42381eSTakashi Iwai 	struct snd_ac97 *ac97 = snd_kcontrol_chip(kcontrol);
21081da177e4SLinus Torvalds 
21091da177e4SLinus Torvalds 	uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED;
21101da177e4SLinus Torvalds 	uinfo->count = 1;
21111da177e4SLinus Torvalds 	uinfo->value.enumerated.items = ac97->spec.dev_flags ? 4 : 3;
21121da177e4SLinus Torvalds 	if (uinfo->value.enumerated.item >= uinfo->value.enumerated.items)
21131da177e4SLinus Torvalds 		uinfo->value.enumerated.item = uinfo->value.enumerated.items - 1;
21141da177e4SLinus Torvalds 	strcpy(uinfo->value.enumerated.name,
21151da177e4SLinus Torvalds 	       ac97->spec.dev_flags ?
21161da177e4SLinus Torvalds 	       texts_658[uinfo->value.enumerated.item] :
21171da177e4SLinus Torvalds 	       texts_655[uinfo->value.enumerated.item]);
21181da177e4SLinus Torvalds 	return 0;
21191da177e4SLinus Torvalds }
21201da177e4SLinus Torvalds 
2121ee42381eSTakashi Iwai static int alc655_iec958_route_get(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
21221da177e4SLinus Torvalds {
2123ee42381eSTakashi Iwai 	struct snd_ac97 *ac97 = snd_kcontrol_chip(kcontrol);
21241da177e4SLinus Torvalds 	unsigned short val;
21251da177e4SLinus Torvalds 
21261da177e4SLinus Torvalds 	val = ac97->regs[AC97_ALC650_MULTICH];
21271da177e4SLinus Torvalds 	val = (val >> 12) & 3;
21281da177e4SLinus Torvalds 	if (ac97->spec.dev_flags && val == 3)
21291da177e4SLinus Torvalds 		val = 0;
21301da177e4SLinus Torvalds 	ucontrol->value.enumerated.item[0] = val;
21311da177e4SLinus Torvalds 	return 0;
21321da177e4SLinus Torvalds }
21331da177e4SLinus Torvalds 
2134ee42381eSTakashi Iwai static int alc655_iec958_route_put(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
21351da177e4SLinus Torvalds {
2136ee42381eSTakashi Iwai 	struct snd_ac97 *ac97 = snd_kcontrol_chip(kcontrol);
21371da177e4SLinus Torvalds 
21381da177e4SLinus Torvalds 	return ac97_update_bits_page(ac97, AC97_ALC650_MULTICH, 3 << 12,
21391da177e4SLinus Torvalds 				     (unsigned short)ucontrol->value.enumerated.item[0] << 12,
21401da177e4SLinus Torvalds 				     0);
21411da177e4SLinus Torvalds }
21421da177e4SLinus Torvalds 
2143ee42381eSTakashi Iwai static const struct snd_kcontrol_new snd_ac97_spdif_controls_alc655[] = {
214410e8d78aSClemens Ladisch         AC97_PAGE_SINGLE(SNDRV_CTL_NAME_IEC958("",CAPTURE,SWITCH), AC97_ALC650_MULTICH, 11, 1, 0, 0),
21451da177e4SLinus Torvalds 	/* disable this controls since it doesn't work as expected */
21461da177e4SLinus Torvalds         /* AC97_PAGE_SINGLE("IEC958 Input Monitor", AC97_ALC650_MULTICH, 14, 1, 0, 0), */
21471da177e4SLinus Torvalds 	{
21481da177e4SLinus Torvalds 		.iface  = SNDRV_CTL_ELEM_IFACE_MIXER,
2149031c95d4STakashi Iwai 		.name   = SNDRV_CTL_NAME_IEC958("",PLAYBACK,NONE) "Source",
21501da177e4SLinus Torvalds 		.info   = alc655_iec958_route_info,
21511da177e4SLinus Torvalds 		.get    = alc655_iec958_route_get,
21521da177e4SLinus Torvalds 		.put    = alc655_iec958_route_put,
21531da177e4SLinus Torvalds 	},
21541da177e4SLinus Torvalds };
21551da177e4SLinus Torvalds 
2156ee42381eSTakashi Iwai static int patch_alc655_specific(struct snd_ac97 * ac97)
21571da177e4SLinus Torvalds {
21581da177e4SLinus Torvalds 	int err;
21591da177e4SLinus Torvalds 
21601da177e4SLinus Torvalds 	if ((err = patch_build_controls(ac97, snd_ac97_controls_alc655, ARRAY_SIZE(snd_ac97_controls_alc655))) < 0)
21611da177e4SLinus Torvalds 		return err;
21621da177e4SLinus Torvalds 	if (ac97->ext_id & AC97_EI_SPDIF) {
21631da177e4SLinus Torvalds 		if ((err = patch_build_controls(ac97, snd_ac97_spdif_controls_alc655, ARRAY_SIZE(snd_ac97_spdif_controls_alc655))) < 0)
21641da177e4SLinus Torvalds 			return err;
21651da177e4SLinus Torvalds 	}
21661da177e4SLinus Torvalds 	return 0;
21671da177e4SLinus Torvalds }
21681da177e4SLinus Torvalds 
21691da177e4SLinus Torvalds static struct snd_ac97_build_ops patch_alc655_ops = {
2170eb8caf30STakashi Iwai 	.build_specific	= patch_alc655_specific,
2171eb8caf30STakashi Iwai 	.update_jacks = alc655_update_jacks
21721da177e4SLinus Torvalds };
21731da177e4SLinus Torvalds 
2174ee42381eSTakashi Iwai int patch_alc655(struct snd_ac97 * ac97)
21751da177e4SLinus Torvalds {
21761da177e4SLinus Torvalds 	unsigned int val;
21771da177e4SLinus Torvalds 
2178a5022b0dSTakashi Iwai 	if (ac97->id == AC97_ID_ALC658) {
2179a5022b0dSTakashi Iwai 		ac97->spec.dev_flags = 1; /* ALC658 */
2180a5022b0dSTakashi Iwai 		if ((snd_ac97_read(ac97, AC97_ALC650_REVISION) & 0x3f) == 2) {
2181a5022b0dSTakashi Iwai 			ac97->id = AC97_ID_ALC658D;
2182a5022b0dSTakashi Iwai 			ac97->spec.dev_flags = 2;
2183a5022b0dSTakashi Iwai 		}
2184a5022b0dSTakashi Iwai 	}
21851da177e4SLinus Torvalds 
21861da177e4SLinus Torvalds 	ac97->build_ops = &patch_alc655_ops;
21871da177e4SLinus Torvalds 
21881da177e4SLinus Torvalds 	/* assume only page 0 for writing cache */
21891da177e4SLinus Torvalds 	snd_ac97_update_bits(ac97, AC97_INT_PAGING, AC97_PAGE_MASK, AC97_PAGE_VENDOR);
21901da177e4SLinus Torvalds 
21911da177e4SLinus Torvalds 	/* adjust default values */
21921da177e4SLinus Torvalds 	val = snd_ac97_read(ac97, 0x7a); /* misc control */
2193a5022b0dSTakashi Iwai 	if (ac97->spec.dev_flags) /* ALC658 */
21941da177e4SLinus Torvalds 		val &= ~(1 << 1); /* Pin 47 is spdif input pin */
2195ee71508eSTakashi Iwai 	else { /* ALC655 */
2196ee71508eSTakashi Iwai 		if (ac97->subsystem_vendor == 0x1462 &&
2197ee71508eSTakashi Iwai 		    ac97->subsystem_device == 0x0131) /* MSI S270 laptop */
2198ee71508eSTakashi Iwai 			val &= ~(1 << 1); /* Pin 47 is EAPD (for internal speaker) */
2199ee71508eSTakashi Iwai 		else
22001da177e4SLinus Torvalds 			val |= (1 << 1); /* Pin 47 is spdif input pin */
2201ee71508eSTakashi Iwai 	}
22021da177e4SLinus Torvalds 	val &= ~(1 << 12); /* vref enable */
22031da177e4SLinus Torvalds 	snd_ac97_write_cache(ac97, 0x7a, val);
22041da177e4SLinus Torvalds 	/* set default: spdif-in enabled,
22051da177e4SLinus Torvalds 	   spdif-in monitor off, spdif-in PCM off
22061da177e4SLinus Torvalds 	   center on mic off, surround on line-in off
22071da177e4SLinus Torvalds 	   duplicate front off
22081da177e4SLinus Torvalds 	*/
22091da177e4SLinus Torvalds 	snd_ac97_write_cache(ac97, AC97_ALC650_MULTICH, 1<<15);
22101da177e4SLinus Torvalds 
22111da177e4SLinus Torvalds 	/* full DAC volume */
22121da177e4SLinus Torvalds 	snd_ac97_write_cache(ac97, AC97_ALC650_SURR_DAC_VOL, 0x0808);
22131da177e4SLinus Torvalds 	snd_ac97_write_cache(ac97, AC97_ALC650_LFE_DAC_VOL, 0x0808);
2214a5022b0dSTakashi Iwai 
2215a5022b0dSTakashi Iwai 	/* update undocumented bit... */
2216a5022b0dSTakashi Iwai 	if (ac97->id == AC97_ID_ALC658D)
2217a5022b0dSTakashi Iwai 		snd_ac97_update_bits(ac97, 0x74, 0x0800, 0x0800);
2218a5022b0dSTakashi Iwai 
22191da177e4SLinus Torvalds 	return 0;
22201da177e4SLinus Torvalds }
22211da177e4SLinus Torvalds 
22221da177e4SLinus Torvalds 
22231da177e4SLinus Torvalds #define AC97_ALC850_JACK_SELECT	0x76
22241da177e4SLinus Torvalds #define AC97_ALC850_MISC1	0x7a
22251da177e4SLinus Torvalds 
2226ee42381eSTakashi Iwai static void alc850_update_jacks(struct snd_ac97 *ac97)
22271da177e4SLinus Torvalds {
2228eb8caf30STakashi Iwai 	int shared;
22291da177e4SLinus Torvalds 
2230eb8caf30STakashi Iwai 	/* shared Line-In */
2231eb8caf30STakashi Iwai 	shared = is_shared_linein(ac97);
22321da177e4SLinus Torvalds 	/* SURR 1kOhm (bit4), Amp (bit5) */
22331da177e4SLinus Torvalds 	snd_ac97_update_bits(ac97, AC97_ALC850_MISC1, (1<<4)|(1<<5),
2234eb8caf30STakashi Iwai 			     shared ? (1<<5) : (1<<4));
22351da177e4SLinus Torvalds 	/* LINE-IN = 0, SURROUND = 2 */
2236eb8caf30STakashi Iwai 	snd_ac97_update_bits(ac97, AC97_ALC850_JACK_SELECT, 7 << 12,
2237eb8caf30STakashi Iwai 			     shared ? (2<<12) : (0<<12));
2238eb8caf30STakashi Iwai 	/* update shared mic */
2239eb8caf30STakashi Iwai 	shared = is_shared_micin(ac97);
22401da177e4SLinus Torvalds 	/* Vref disable (bit12), 1kOhm (bit13) */
22411da177e4SLinus Torvalds 	snd_ac97_update_bits(ac97, AC97_ALC850_MISC1, (1<<12)|(1<<13),
2242eb8caf30STakashi Iwai 			     shared ? (1<<12) : (1<<13));
2243da79e44dSTakashi Iwai 	/* MIC-IN = 1, CENTER-LFE = 5 */
2244eb8caf30STakashi Iwai 	snd_ac97_update_bits(ac97, AC97_ALC850_JACK_SELECT, 7 << 4,
2245da79e44dSTakashi Iwai 			     shared ? (5<<4) : (1<<4));
22461da177e4SLinus Torvalds }
22471da177e4SLinus Torvalds 
2248ee42381eSTakashi Iwai static const struct snd_kcontrol_new snd_ac97_controls_alc850[] = {
22491da177e4SLinus Torvalds 	AC97_PAGE_SINGLE("Duplicate Front", AC97_ALC650_MULTICH, 0, 1, 0, 0),
225067e1b51eSSergey Vlasov 	AC97_SINGLE("Mic Front Input Switch", AC97_ALC850_JACK_SELECT, 15, 1, 1),
2251eb8caf30STakashi Iwai 	AC97_SURROUND_JACK_MODE_CTL,
2252eb8caf30STakashi Iwai 	AC97_CHANNEL_MODE_CTL,
22531da177e4SLinus Torvalds };
22541da177e4SLinus Torvalds 
2255ee42381eSTakashi Iwai static int patch_alc850_specific(struct snd_ac97 *ac97)
22561da177e4SLinus Torvalds {
22571da177e4SLinus Torvalds 	int err;
22581da177e4SLinus Torvalds 
22591da177e4SLinus Torvalds 	if ((err = patch_build_controls(ac97, snd_ac97_controls_alc850, ARRAY_SIZE(snd_ac97_controls_alc850))) < 0)
22601da177e4SLinus Torvalds 		return err;
22611da177e4SLinus Torvalds 	if (ac97->ext_id & AC97_EI_SPDIF) {
22621da177e4SLinus Torvalds 		if ((err = patch_build_controls(ac97, snd_ac97_spdif_controls_alc655, ARRAY_SIZE(snd_ac97_spdif_controls_alc655))) < 0)
22631da177e4SLinus Torvalds 			return err;
22641da177e4SLinus Torvalds 	}
22651da177e4SLinus Torvalds 	return 0;
22661da177e4SLinus Torvalds }
22671da177e4SLinus Torvalds 
22681da177e4SLinus Torvalds static struct snd_ac97_build_ops patch_alc850_ops = {
2269eb8caf30STakashi Iwai 	.build_specific	= patch_alc850_specific,
2270eb8caf30STakashi Iwai 	.update_jacks = alc850_update_jacks
22711da177e4SLinus Torvalds };
22721da177e4SLinus Torvalds 
2273ee42381eSTakashi Iwai int patch_alc850(struct snd_ac97 *ac97)
22741da177e4SLinus Torvalds {
22751da177e4SLinus Torvalds 	ac97->build_ops = &patch_alc850_ops;
22761da177e4SLinus Torvalds 
22771da177e4SLinus Torvalds 	ac97->spec.dev_flags = 0; /* for IEC958 playback route - ALC655 compatible */
22781da177e4SLinus Torvalds 
22791da177e4SLinus Torvalds 	/* assume only page 0 for writing cache */
22801da177e4SLinus Torvalds 	snd_ac97_update_bits(ac97, AC97_INT_PAGING, AC97_PAGE_MASK, AC97_PAGE_VENDOR);
22811da177e4SLinus Torvalds 
22821da177e4SLinus Torvalds 	/* adjust default values */
22831da177e4SLinus Torvalds 	/* set default: spdif-in enabled,
22841da177e4SLinus Torvalds 	   spdif-in monitor off, spdif-in PCM off
22851da177e4SLinus Torvalds 	   center on mic off, surround on line-in off
22861da177e4SLinus Torvalds 	   duplicate front off
22871da177e4SLinus Torvalds 	*/
22881da177e4SLinus Torvalds 	snd_ac97_write_cache(ac97, AC97_ALC650_MULTICH, 1<<15);
22891da177e4SLinus Torvalds 	/* SURR_OUT: on, Surr 1kOhm: on, Surr Amp: off, Front 1kOhm: off
22901da177e4SLinus Torvalds 	 * Front Amp: on, Vref: enable, Center 1kOhm: on, Mix: on
22911da177e4SLinus Torvalds 	 */
22921da177e4SLinus Torvalds 	snd_ac97_write_cache(ac97, 0x7a, (1<<1)|(1<<4)|(0<<5)|(1<<6)|
22931da177e4SLinus Torvalds 			     (1<<7)|(0<<12)|(1<<13)|(0<<14));
22941da177e4SLinus Torvalds 	/* detection UIO2,3: all path floating, UIO3: MIC, Vref2: disable,
22951da177e4SLinus Torvalds 	 * UIO1: FRONT, Vref3: disable, UIO3: LINE, Front-Mic: mute
22961da177e4SLinus Torvalds 	 */
22971da177e4SLinus Torvalds 	snd_ac97_write_cache(ac97, 0x76, (0<<0)|(0<<2)|(1<<4)|(1<<7)|(2<<8)|
22981da177e4SLinus Torvalds 			     (1<<11)|(0<<12)|(1<<15));
22991da177e4SLinus Torvalds 
23001da177e4SLinus Torvalds 	/* full DAC volume */
23011da177e4SLinus Torvalds 	snd_ac97_write_cache(ac97, AC97_ALC650_SURR_DAC_VOL, 0x0808);
23021da177e4SLinus Torvalds 	snd_ac97_write_cache(ac97, AC97_ALC650_LFE_DAC_VOL, 0x0808);
23031da177e4SLinus Torvalds 	return 0;
23041da177e4SLinus Torvalds }
23051da177e4SLinus Torvalds 
23061da177e4SLinus Torvalds 
23071da177e4SLinus Torvalds /*
23081da177e4SLinus Torvalds  * C-Media CM97xx codecs
23091da177e4SLinus Torvalds  */
2310ee42381eSTakashi Iwai static void cm9738_update_jacks(struct snd_ac97 *ac97)
2311eb8caf30STakashi Iwai {
2312eb8caf30STakashi Iwai 	/* shared Line-In */
2313eb8caf30STakashi Iwai 	snd_ac97_update_bits(ac97, AC97_CM9738_VENDOR_CTRL, 1 << 10,
2314eb8caf30STakashi Iwai 			     is_shared_linein(ac97) ? (1 << 10) : 0);
2315eb8caf30STakashi Iwai }
2316eb8caf30STakashi Iwai 
2317ee42381eSTakashi Iwai static const struct snd_kcontrol_new snd_ac97_cm9738_controls[] = {
23181da177e4SLinus Torvalds 	AC97_SINGLE("Duplicate Front", AC97_CM9738_VENDOR_CTRL, 13, 1, 0),
2319eb8caf30STakashi Iwai 	AC97_SURROUND_JACK_MODE_CTL,
2320eb8caf30STakashi Iwai 	AC97_CHANNEL_MODE_4CH_CTL,
23211da177e4SLinus Torvalds };
23221da177e4SLinus Torvalds 
2323ee42381eSTakashi Iwai static int patch_cm9738_specific(struct snd_ac97 * ac97)
23241da177e4SLinus Torvalds {
23251da177e4SLinus Torvalds 	return patch_build_controls(ac97, snd_ac97_cm9738_controls, ARRAY_SIZE(snd_ac97_cm9738_controls));
23261da177e4SLinus Torvalds }
23271da177e4SLinus Torvalds 
23281da177e4SLinus Torvalds static struct snd_ac97_build_ops patch_cm9738_ops = {
2329eb8caf30STakashi Iwai 	.build_specific	= patch_cm9738_specific,
2330eb8caf30STakashi Iwai 	.update_jacks = cm9738_update_jacks
23311da177e4SLinus Torvalds };
23321da177e4SLinus Torvalds 
2333ee42381eSTakashi Iwai int patch_cm9738(struct snd_ac97 * ac97)
23341da177e4SLinus Torvalds {
23351da177e4SLinus Torvalds 	ac97->build_ops = &patch_cm9738_ops;
23361da177e4SLinus Torvalds 	/* FIXME: can anyone confirm below? */
23371da177e4SLinus Torvalds 	/* CM9738 has no PCM volume although the register reacts */
23381da177e4SLinus Torvalds 	ac97->flags |= AC97_HAS_NO_PCM_VOL;
23391da177e4SLinus Torvalds 	snd_ac97_write_cache(ac97, AC97_PCM, 0x8000);
23401da177e4SLinus Torvalds 
23411da177e4SLinus Torvalds 	return 0;
23421da177e4SLinus Torvalds }
23431da177e4SLinus Torvalds 
2344ee42381eSTakashi Iwai static int snd_ac97_cmedia_spdif_playback_source_info(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_info *uinfo)
23451da177e4SLinus Torvalds {
23461da177e4SLinus Torvalds 	static char *texts[] = { "Analog", "Digital" };
23471da177e4SLinus Torvalds 
23481da177e4SLinus Torvalds 	uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED;
23491da177e4SLinus Torvalds 	uinfo->count = 1;
23501da177e4SLinus Torvalds 	uinfo->value.enumerated.items = 2;
23511da177e4SLinus Torvalds 	if (uinfo->value.enumerated.item > 1)
23521da177e4SLinus Torvalds 		uinfo->value.enumerated.item = 1;
23531da177e4SLinus Torvalds 	strcpy(uinfo->value.enumerated.name, texts[uinfo->value.enumerated.item]);
23541da177e4SLinus Torvalds 	return 0;
23551da177e4SLinus Torvalds }
23561da177e4SLinus Torvalds 
2357ee42381eSTakashi Iwai static int snd_ac97_cmedia_spdif_playback_source_get(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
23581da177e4SLinus Torvalds {
2359ee42381eSTakashi Iwai 	struct snd_ac97 *ac97 = snd_kcontrol_chip(kcontrol);
23601da177e4SLinus Torvalds 	unsigned short val;
23611da177e4SLinus Torvalds 
23621da177e4SLinus Torvalds 	val = ac97->regs[AC97_CM9739_SPDIF_CTRL];
23631da177e4SLinus Torvalds 	ucontrol->value.enumerated.item[0] = (val >> 1) & 0x01;
23641da177e4SLinus Torvalds 	return 0;
23651da177e4SLinus Torvalds }
23661da177e4SLinus Torvalds 
2367ee42381eSTakashi Iwai static int snd_ac97_cmedia_spdif_playback_source_put(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
23681da177e4SLinus Torvalds {
2369ee42381eSTakashi Iwai 	struct snd_ac97 *ac97 = snd_kcontrol_chip(kcontrol);
23701da177e4SLinus Torvalds 
23711da177e4SLinus Torvalds 	return snd_ac97_update_bits(ac97, AC97_CM9739_SPDIF_CTRL,
23721da177e4SLinus Torvalds 				    0x01 << 1,
23731da177e4SLinus Torvalds 				    (ucontrol->value.enumerated.item[0] & 0x01) << 1);
23741da177e4SLinus Torvalds }
23751da177e4SLinus Torvalds 
2376ee42381eSTakashi Iwai static const struct snd_kcontrol_new snd_ac97_cm9739_controls_spdif[] = {
23771da177e4SLinus Torvalds 	/* BIT 0: SPDI_EN - always true */
23781da177e4SLinus Torvalds 	{ /* BIT 1: SPDIFS */
23791da177e4SLinus Torvalds 		.iface	= SNDRV_CTL_ELEM_IFACE_MIXER,
23801da177e4SLinus Torvalds 		.name	= SNDRV_CTL_NAME_IEC958("",PLAYBACK,NONE) "Source",
23811da177e4SLinus Torvalds 		.info	= snd_ac97_cmedia_spdif_playback_source_info,
23821da177e4SLinus Torvalds 		.get	= snd_ac97_cmedia_spdif_playback_source_get,
23831da177e4SLinus Torvalds 		.put	= snd_ac97_cmedia_spdif_playback_source_put,
23841da177e4SLinus Torvalds 	},
23851da177e4SLinus Torvalds 	/* BIT 2: IG_SPIV */
23861da177e4SLinus Torvalds 	AC97_SINGLE(SNDRV_CTL_NAME_IEC958("",CAPTURE,NONE) "Valid Switch", AC97_CM9739_SPDIF_CTRL, 2, 1, 0),
23871da177e4SLinus Torvalds 	/* BIT 3: SPI2F */
23881da177e4SLinus Torvalds 	AC97_SINGLE(SNDRV_CTL_NAME_IEC958("",CAPTURE,NONE) "Monitor", AC97_CM9739_SPDIF_CTRL, 3, 1, 0),
23891da177e4SLinus Torvalds 	/* BIT 4: SPI2SDI */
23901da177e4SLinus Torvalds 	AC97_SINGLE(SNDRV_CTL_NAME_IEC958("",CAPTURE,SWITCH), AC97_CM9739_SPDIF_CTRL, 4, 1, 0),
23911da177e4SLinus Torvalds 	/* BIT 8: SPD32 - 32bit SPDIF - not supported yet */
23921da177e4SLinus Torvalds };
23931da177e4SLinus Torvalds 
2394ee42381eSTakashi Iwai static void cm9739_update_jacks(struct snd_ac97 *ac97)
23951da177e4SLinus Torvalds {
2396eb8caf30STakashi Iwai 	/* shared Line-In */
2397eb8caf30STakashi Iwai 	snd_ac97_update_bits(ac97, AC97_CM9739_MULTI_CHAN, 1 << 10,
2398eb8caf30STakashi Iwai 			     is_shared_linein(ac97) ? (1 << 10) : 0);
2399eb8caf30STakashi Iwai 	/* shared Mic */
2400eb8caf30STakashi Iwai 	snd_ac97_update_bits(ac97, AC97_CM9739_MULTI_CHAN, 0x3000,
2401eb8caf30STakashi Iwai 			     is_shared_micin(ac97) ? 0x1000 : 0x2000);
24021da177e4SLinus Torvalds }
24031da177e4SLinus Torvalds 
2404ee42381eSTakashi Iwai static const struct snd_kcontrol_new snd_ac97_cm9739_controls[] = {
2405eb8caf30STakashi Iwai 	AC97_SURROUND_JACK_MODE_CTL,
2406eb8caf30STakashi Iwai 	AC97_CHANNEL_MODE_CTL,
24071da177e4SLinus Torvalds };
24081da177e4SLinus Torvalds 
2409ee42381eSTakashi Iwai static int patch_cm9739_specific(struct snd_ac97 * ac97)
24101da177e4SLinus Torvalds {
24111da177e4SLinus Torvalds 	return patch_build_controls(ac97, snd_ac97_cm9739_controls, ARRAY_SIZE(snd_ac97_cm9739_controls));
24121da177e4SLinus Torvalds }
24131da177e4SLinus Torvalds 
2414ee42381eSTakashi Iwai static int patch_cm9739_post_spdif(struct snd_ac97 * ac97)
24151da177e4SLinus Torvalds {
24161da177e4SLinus Torvalds 	return patch_build_controls(ac97, snd_ac97_cm9739_controls_spdif, ARRAY_SIZE(snd_ac97_cm9739_controls_spdif));
24171da177e4SLinus Torvalds }
24181da177e4SLinus Torvalds 
24191da177e4SLinus Torvalds static struct snd_ac97_build_ops patch_cm9739_ops = {
24201da177e4SLinus Torvalds 	.build_specific	= patch_cm9739_specific,
2421eb8caf30STakashi Iwai 	.build_post_spdif = patch_cm9739_post_spdif,
2422eb8caf30STakashi Iwai 	.update_jacks = cm9739_update_jacks
24231da177e4SLinus Torvalds };
24241da177e4SLinus Torvalds 
2425ee42381eSTakashi Iwai int patch_cm9739(struct snd_ac97 * ac97)
24261da177e4SLinus Torvalds {
24271da177e4SLinus Torvalds 	unsigned short val;
24281da177e4SLinus Torvalds 
24291da177e4SLinus Torvalds 	ac97->build_ops = &patch_cm9739_ops;
24301da177e4SLinus Torvalds 
24311da177e4SLinus Torvalds 	/* CM9739/A has no Master and PCM volume although the register reacts */
24321da177e4SLinus Torvalds 	ac97->flags |= AC97_HAS_NO_MASTER_VOL | AC97_HAS_NO_PCM_VOL;
24331da177e4SLinus Torvalds 	snd_ac97_write_cache(ac97, AC97_MASTER, 0x8000);
24341da177e4SLinus Torvalds 	snd_ac97_write_cache(ac97, AC97_PCM, 0x8000);
24351da177e4SLinus Torvalds 
24361da177e4SLinus Torvalds 	/* check spdif */
24371da177e4SLinus Torvalds 	val = snd_ac97_read(ac97, AC97_EXTENDED_STATUS);
24381da177e4SLinus Torvalds 	if (val & AC97_EA_SPCV) {
24391da177e4SLinus Torvalds 		/* enable spdif in */
24401da177e4SLinus Torvalds 		snd_ac97_write_cache(ac97, AC97_CM9739_SPDIF_CTRL,
24411da177e4SLinus Torvalds 				     snd_ac97_read(ac97, AC97_CM9739_SPDIF_CTRL) | 0x01);
24421da177e4SLinus Torvalds 		ac97->rates[AC97_RATES_SPDIF] = SNDRV_PCM_RATE_48000; /* 48k only */
24431da177e4SLinus Torvalds 	} else {
24441da177e4SLinus Torvalds 		ac97->ext_id &= ~AC97_EI_SPDIF; /* disable extended-id */
24451da177e4SLinus Torvalds 		ac97->rates[AC97_RATES_SPDIF] = 0;
24461da177e4SLinus Torvalds 	}
24471da177e4SLinus Torvalds 
24481da177e4SLinus Torvalds 	/* set-up multi channel */
24491da177e4SLinus Torvalds 	/* bit 14: 0 = SPDIF, 1 = EAPD */
24501da177e4SLinus Torvalds 	/* bit 13: enable internal vref output for mic */
24511da177e4SLinus Torvalds 	/* bit 12: disable center/lfe (swithable) */
24521da177e4SLinus Torvalds 	/* bit 10: disable surround/line (switchable) */
24531da177e4SLinus Torvalds 	/* bit 9: mix 2 surround off */
24541da177e4SLinus Torvalds 	/* bit 4: undocumented; 0 mutes the CM9739A, which defaults to 1 */
24551da177e4SLinus Torvalds 	/* bit 3: undocumented; surround? */
24561da177e4SLinus Torvalds 	/* bit 0: dB */
24571da177e4SLinus Torvalds 	val = snd_ac97_read(ac97, AC97_CM9739_MULTI_CHAN) & (1 << 4);
24581da177e4SLinus Torvalds 	val |= (1 << 3);
24591da177e4SLinus Torvalds 	val |= (1 << 13);
24601da177e4SLinus Torvalds 	if (! (ac97->ext_id & AC97_EI_SPDIF))
24611da177e4SLinus Torvalds 		val |= (1 << 14);
24621da177e4SLinus Torvalds 	snd_ac97_write_cache(ac97, AC97_CM9739_MULTI_CHAN, val);
24631da177e4SLinus Torvalds 
24641da177e4SLinus Torvalds 	/* FIXME: set up GPIO */
24651da177e4SLinus Torvalds 	snd_ac97_write_cache(ac97, 0x70, 0x0100);
24661da177e4SLinus Torvalds 	snd_ac97_write_cache(ac97, 0x72, 0x0020);
24671da177e4SLinus Torvalds 	/* Special exception for ASUS W1000/CMI9739. It does not have an SPDIF in. */
24681da177e4SLinus Torvalds 	if (ac97->pci &&
24691da177e4SLinus Torvalds 	     ac97->subsystem_vendor == 0x1043 &&
24701da177e4SLinus Torvalds 	     ac97->subsystem_device == 0x1843) {
24711da177e4SLinus Torvalds 		snd_ac97_write_cache(ac97, AC97_CM9739_SPDIF_CTRL,
24721da177e4SLinus Torvalds 			snd_ac97_read(ac97, AC97_CM9739_SPDIF_CTRL) & ~0x01);
24731da177e4SLinus Torvalds 		snd_ac97_write_cache(ac97, AC97_CM9739_MULTI_CHAN,
24741da177e4SLinus Torvalds 			snd_ac97_read(ac97, AC97_CM9739_MULTI_CHAN) | (1 << 14));
24751da177e4SLinus Torvalds 	}
24761da177e4SLinus Torvalds 
24771da177e4SLinus Torvalds 	return 0;
24781da177e4SLinus Torvalds }
24791da177e4SLinus Torvalds 
24801da177e4SLinus Torvalds #define AC97_CM9761_MULTI_CHAN	0x64
24815f0dccf8STakashi Iwai #define AC97_CM9761_FUNC	0x66
24821da177e4SLinus Torvalds #define AC97_CM9761_SPDIF_CTRL	0x6c
24831da177e4SLinus Torvalds 
2484ee42381eSTakashi Iwai static void cm9761_update_jacks(struct snd_ac97 *ac97)
24851da177e4SLinus Torvalds {
24864525c9f3STakashi Iwai 	/* FIXME: check the bits for each model
24874525c9f3STakashi Iwai 	 *        model 83 is confirmed to work
24884525c9f3STakashi Iwai 	 */
24894525c9f3STakashi Iwai 	static unsigned short surr_on[3][2] = {
24904525c9f3STakashi Iwai 		{ 0x0008, 0x0000 }, /* 9761-78 & 82 */
24914525c9f3STakashi Iwai 		{ 0x0000, 0x0008 }, /* 9761-82 rev.B */
24924525c9f3STakashi Iwai 		{ 0x0000, 0x0008 }, /* 9761-83 */
24931da177e4SLinus Torvalds 	};
24944525c9f3STakashi Iwai 	static unsigned short clfe_on[3][2] = {
24954525c9f3STakashi Iwai 		{ 0x0000, 0x1000 }, /* 9761-78 & 82 */
24964525c9f3STakashi Iwai 		{ 0x1000, 0x0000 }, /* 9761-82 rev.B */
24974525c9f3STakashi Iwai 		{ 0x0000, 0x1000 }, /* 9761-83 */
24981da177e4SLinus Torvalds 	};
24994525c9f3STakashi Iwai 	static unsigned short surr_shared[3][2] = {
25004525c9f3STakashi Iwai 		{ 0x0000, 0x0400 }, /* 9761-78 & 82 */
25014525c9f3STakashi Iwai 		{ 0x0000, 0x0400 }, /* 9761-82 rev.B */
25024525c9f3STakashi Iwai 		{ 0x0000, 0x0400 }, /* 9761-83 */
25034525c9f3STakashi Iwai 	};
25044525c9f3STakashi Iwai 	static unsigned short clfe_shared[3][2] = {
25054525c9f3STakashi Iwai 		{ 0x2000, 0x0880 }, /* 9761-78 & 82 */
25064525c9f3STakashi Iwai 		{ 0x0000, 0x2880 }, /* 9761-82 rev.B */
25074525c9f3STakashi Iwai 		{ 0x2000, 0x0800 }, /* 9761-83 */
25084525c9f3STakashi Iwai 	};
25094525c9f3STakashi Iwai 	unsigned short val = 0;
2510eb8caf30STakashi Iwai 
25114525c9f3STakashi Iwai 	val |= surr_on[ac97->spec.dev_flags][is_surround_on(ac97)];
25124525c9f3STakashi Iwai 	val |= clfe_on[ac97->spec.dev_flags][is_clfe_on(ac97)];
25134525c9f3STakashi Iwai 	val |= surr_shared[ac97->spec.dev_flags][is_shared_linein(ac97)];
25144525c9f3STakashi Iwai 	val |= clfe_shared[ac97->spec.dev_flags][is_shared_micin(ac97)];
25154525c9f3STakashi Iwai 
25164525c9f3STakashi Iwai 	snd_ac97_update_bits(ac97, AC97_CM9761_MULTI_CHAN, 0x3c88, val);
25171da177e4SLinus Torvalds }
25181da177e4SLinus Torvalds 
2519ee42381eSTakashi Iwai static const struct snd_kcontrol_new snd_ac97_cm9761_controls[] = {
2520eb8caf30STakashi Iwai 	AC97_SURROUND_JACK_MODE_CTL,
2521eb8caf30STakashi Iwai 	AC97_CHANNEL_MODE_CTL,
25221da177e4SLinus Torvalds };
25231da177e4SLinus Torvalds 
2524ee42381eSTakashi Iwai static int cm9761_spdif_out_source_info(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_info *uinfo)
25255f0dccf8STakashi Iwai {
25265f0dccf8STakashi Iwai 	static char *texts[] = { "AC-Link", "ADC", "SPDIF-In" };
25275f0dccf8STakashi Iwai 
25285f0dccf8STakashi Iwai 	uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED;
25295f0dccf8STakashi Iwai 	uinfo->count = 1;
25305f0dccf8STakashi Iwai 	uinfo->value.enumerated.items = 3;
25315f0dccf8STakashi Iwai 	if (uinfo->value.enumerated.item > 2)
25325f0dccf8STakashi Iwai 		uinfo->value.enumerated.item = 2;
25335f0dccf8STakashi Iwai 	strcpy(uinfo->value.enumerated.name, texts[uinfo->value.enumerated.item]);
25345f0dccf8STakashi Iwai 	return 0;
25355f0dccf8STakashi Iwai }
25365f0dccf8STakashi Iwai 
2537ee42381eSTakashi Iwai static int cm9761_spdif_out_source_get(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
25385f0dccf8STakashi Iwai {
2539ee42381eSTakashi Iwai 	struct snd_ac97 *ac97 = snd_kcontrol_chip(kcontrol);
25405f0dccf8STakashi Iwai 
25415f0dccf8STakashi Iwai 	if (ac97->regs[AC97_CM9761_FUNC] & 0x1)
25425f0dccf8STakashi Iwai 		ucontrol->value.enumerated.item[0] = 2; /* SPDIF-loopback */
25435f0dccf8STakashi Iwai 	else if (ac97->regs[AC97_CM9761_SPDIF_CTRL] & 0x2)
25445f0dccf8STakashi Iwai 		ucontrol->value.enumerated.item[0] = 1; /* ADC loopback */
25455f0dccf8STakashi Iwai 	else
25465f0dccf8STakashi Iwai 		ucontrol->value.enumerated.item[0] = 0; /* AC-link */
25475f0dccf8STakashi Iwai 	return 0;
25485f0dccf8STakashi Iwai }
25495f0dccf8STakashi Iwai 
2550ee42381eSTakashi Iwai static int cm9761_spdif_out_source_put(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
25515f0dccf8STakashi Iwai {
2552ee42381eSTakashi Iwai 	struct snd_ac97 *ac97 = snd_kcontrol_chip(kcontrol);
25535f0dccf8STakashi Iwai 
25545f0dccf8STakashi Iwai 	if (ucontrol->value.enumerated.item[0] == 2)
25555f0dccf8STakashi Iwai 		return snd_ac97_update_bits(ac97, AC97_CM9761_FUNC, 0x1, 0x1);
25565f0dccf8STakashi Iwai 	snd_ac97_update_bits(ac97, AC97_CM9761_FUNC, 0x1, 0);
25575f0dccf8STakashi Iwai 	return snd_ac97_update_bits(ac97, AC97_CM9761_SPDIF_CTRL, 0x2,
25585f0dccf8STakashi Iwai 				    ucontrol->value.enumerated.item[0] == 1 ? 0x2 : 0);
25595f0dccf8STakashi Iwai }
25605f0dccf8STakashi Iwai 
25615f0dccf8STakashi Iwai static const char *cm9761_dac_clock[] = { "AC-Link", "SPDIF-In", "Both" };
25625f0dccf8STakashi Iwai static const struct ac97_enum cm9761_dac_clock_enum =
25635f0dccf8STakashi Iwai 	AC97_ENUM_SINGLE(AC97_CM9761_SPDIF_CTRL, 9, 3, cm9761_dac_clock);
25645f0dccf8STakashi Iwai 
2565ee42381eSTakashi Iwai static const struct snd_kcontrol_new snd_ac97_cm9761_controls_spdif[] = {
25665f0dccf8STakashi Iwai 	{ /* BIT 1: SPDIFS */
25675f0dccf8STakashi Iwai 		.iface	= SNDRV_CTL_ELEM_IFACE_MIXER,
25685f0dccf8STakashi Iwai 		.name	= SNDRV_CTL_NAME_IEC958("",PLAYBACK,NONE) "Source",
25695f0dccf8STakashi Iwai 		.info = cm9761_spdif_out_source_info,
25705f0dccf8STakashi Iwai 		.get = cm9761_spdif_out_source_get,
25715f0dccf8STakashi Iwai 		.put = cm9761_spdif_out_source_put,
25725f0dccf8STakashi Iwai 	},
25735f0dccf8STakashi Iwai 	/* BIT 2: IG_SPIV */
25745f0dccf8STakashi Iwai 	AC97_SINGLE(SNDRV_CTL_NAME_IEC958("",CAPTURE,NONE) "Valid Switch", AC97_CM9761_SPDIF_CTRL, 2, 1, 0),
25755f0dccf8STakashi Iwai 	/* BIT 3: SPI2F */
25765f0dccf8STakashi Iwai 	AC97_SINGLE(SNDRV_CTL_NAME_IEC958("",CAPTURE,NONE) "Monitor", AC97_CM9761_SPDIF_CTRL, 3, 1, 0),
25775f0dccf8STakashi Iwai 	/* BIT 4: SPI2SDI */
25785f0dccf8STakashi Iwai 	AC97_SINGLE(SNDRV_CTL_NAME_IEC958("",CAPTURE,SWITCH), AC97_CM9761_SPDIF_CTRL, 4, 1, 0),
25795f0dccf8STakashi Iwai 	/* BIT 9-10: DAC_CTL */
25805f0dccf8STakashi Iwai 	AC97_ENUM("DAC Clock Source", cm9761_dac_clock_enum),
25815f0dccf8STakashi Iwai };
25825f0dccf8STakashi Iwai 
2583ee42381eSTakashi Iwai static int patch_cm9761_post_spdif(struct snd_ac97 * ac97)
25845f0dccf8STakashi Iwai {
25855f0dccf8STakashi Iwai 	return patch_build_controls(ac97, snd_ac97_cm9761_controls_spdif, ARRAY_SIZE(snd_ac97_cm9761_controls_spdif));
25865f0dccf8STakashi Iwai }
25875f0dccf8STakashi Iwai 
2588ee42381eSTakashi Iwai static int patch_cm9761_specific(struct snd_ac97 * ac97)
25891da177e4SLinus Torvalds {
25901da177e4SLinus Torvalds 	return patch_build_controls(ac97, snd_ac97_cm9761_controls, ARRAY_SIZE(snd_ac97_cm9761_controls));
25911da177e4SLinus Torvalds }
25921da177e4SLinus Torvalds 
25931da177e4SLinus Torvalds static struct snd_ac97_build_ops patch_cm9761_ops = {
25941da177e4SLinus Torvalds 	.build_specific	= patch_cm9761_specific,
2595eb8caf30STakashi Iwai 	.build_post_spdif = patch_cm9761_post_spdif,
2596eb8caf30STakashi Iwai 	.update_jacks = cm9761_update_jacks
25971da177e4SLinus Torvalds };
25981da177e4SLinus Torvalds 
2599ee42381eSTakashi Iwai int patch_cm9761(struct snd_ac97 *ac97)
26001da177e4SLinus Torvalds {
26011da177e4SLinus Torvalds 	unsigned short val;
26021da177e4SLinus Torvalds 
26031da177e4SLinus Torvalds 	/* CM9761 has no PCM volume although the register reacts */
26041da177e4SLinus Torvalds 	/* Master volume seems to have _some_ influence on the analog
26051da177e4SLinus Torvalds 	 * input sounds
26061da177e4SLinus Torvalds 	 */
26071da177e4SLinus Torvalds 	ac97->flags |= /*AC97_HAS_NO_MASTER_VOL |*/ AC97_HAS_NO_PCM_VOL;
26081da177e4SLinus Torvalds 	snd_ac97_write_cache(ac97, AC97_MASTER, 0x8808);
26091da177e4SLinus Torvalds 	snd_ac97_write_cache(ac97, AC97_PCM, 0x8808);
26101da177e4SLinus Torvalds 
26114525c9f3STakashi Iwai 	ac97->spec.dev_flags = 0; /* 1 = model 82 revision B, 2 = model 83 */
26121da177e4SLinus Torvalds 	if (ac97->id == AC97_ID_CM9761_82) {
26131da177e4SLinus Torvalds 		unsigned short tmp;
26141da177e4SLinus Torvalds 		/* check page 1, reg 0x60 */
26151da177e4SLinus Torvalds 		val = snd_ac97_read(ac97, AC97_INT_PAGING);
26161da177e4SLinus Torvalds 		snd_ac97_write_cache(ac97, AC97_INT_PAGING, (val & ~0x0f) | 0x01);
26171da177e4SLinus Torvalds 		tmp = snd_ac97_read(ac97, 0x60);
26181da177e4SLinus Torvalds 		ac97->spec.dev_flags = tmp & 1; /* revision B? */
26191da177e4SLinus Torvalds 		snd_ac97_write_cache(ac97, AC97_INT_PAGING, val);
26204525c9f3STakashi Iwai 	} else if (ac97->id == AC97_ID_CM9761_83)
26214525c9f3STakashi Iwai 		ac97->spec.dev_flags = 2;
26221da177e4SLinus Torvalds 
26231da177e4SLinus Torvalds 	ac97->build_ops = &patch_cm9761_ops;
26241da177e4SLinus Torvalds 
26251da177e4SLinus Torvalds 	/* enable spdif */
26261da177e4SLinus Torvalds 	/* force the SPDIF bit in ext_id - codec doesn't set this bit! */
26271da177e4SLinus Torvalds         ac97->ext_id |= AC97_EI_SPDIF;
26281da177e4SLinus Torvalds 	/* to be sure: we overwrite the ext status bits */
26291da177e4SLinus Torvalds 	snd_ac97_write_cache(ac97, AC97_EXTENDED_STATUS, 0x05c0);
26301da177e4SLinus Torvalds 	/* Don't set 0x0200 here.  This results in the silent analog output */
26315f0dccf8STakashi Iwai 	snd_ac97_write_cache(ac97, AC97_CM9761_SPDIF_CTRL, 0x0001); /* enable spdif-in */
26321da177e4SLinus Torvalds 	ac97->rates[AC97_RATES_SPDIF] = SNDRV_PCM_RATE_48000; /* 48k only */
26331da177e4SLinus Torvalds 
26341da177e4SLinus Torvalds 	/* set-up multi channel */
26351da177e4SLinus Torvalds 	/* bit 15: pc master beep off
26365f0dccf8STakashi Iwai 	 * bit 14: pin47 = EAPD/SPDIF
26371da177e4SLinus Torvalds 	 * bit 13: vref ctl [= cm9739]
26385f0dccf8STakashi Iwai 	 * bit 12: CLFE control (reverted on rev B)
26395f0dccf8STakashi Iwai 	 * bit 11: Mic/center share (reverted on rev B)
26405f0dccf8STakashi Iwai 	 * bit 10: suddound/line share
26415f0dccf8STakashi Iwai 	 * bit  9: Analog-in mix -> surround
26425f0dccf8STakashi Iwai 	 * bit  8: Analog-in mix -> CLFE
26435f0dccf8STakashi Iwai 	 * bit  7: Mic/LFE share (mic/center/lfe)
26445f0dccf8STakashi Iwai 	 * bit  5: vref select (9761A)
26455f0dccf8STakashi Iwai 	 * bit  4: front control
26465f0dccf8STakashi Iwai 	 * bit  3: surround control (revereted with rev B)
26475f0dccf8STakashi Iwai 	 * bit  2: front mic
26485f0dccf8STakashi Iwai 	 * bit  1: stereo mic
26495f0dccf8STakashi Iwai 	 * bit  0: mic boost level (0=20dB, 1=30dB)
26501da177e4SLinus Torvalds 	 */
26511da177e4SLinus Torvalds 
26521da177e4SLinus Torvalds #if 0
26531da177e4SLinus Torvalds 	if (ac97->spec.dev_flags)
26541da177e4SLinus Torvalds 		val = 0x0214;
26551da177e4SLinus Torvalds 	else
26561da177e4SLinus Torvalds 		val = 0x321c;
26571da177e4SLinus Torvalds #endif
26581da177e4SLinus Torvalds 	val = snd_ac97_read(ac97, AC97_CM9761_MULTI_CHAN);
26591da177e4SLinus Torvalds 	val |= (1 << 4); /* front on */
26601da177e4SLinus Torvalds 	snd_ac97_write_cache(ac97, AC97_CM9761_MULTI_CHAN, val);
26611da177e4SLinus Torvalds 
26621da177e4SLinus Torvalds 	/* FIXME: set up GPIO */
26631da177e4SLinus Torvalds 	snd_ac97_write_cache(ac97, 0x70, 0x0100);
26641da177e4SLinus Torvalds 	snd_ac97_write_cache(ac97, 0x72, 0x0020);
26651da177e4SLinus Torvalds 
26661da177e4SLinus Torvalds 	return 0;
26671da177e4SLinus Torvalds }
26681da177e4SLinus Torvalds 
26695f0dccf8STakashi Iwai #define AC97_CM9780_SIDE	0x60
26705f0dccf8STakashi Iwai #define AC97_CM9780_JACK	0x62
26715f0dccf8STakashi Iwai #define AC97_CM9780_MIXER	0x64
26725f0dccf8STakashi Iwai #define AC97_CM9780_MULTI_CHAN	0x66
26735f0dccf8STakashi Iwai #define AC97_CM9780_SPDIF	0x6c
26745f0dccf8STakashi Iwai 
26755f0dccf8STakashi Iwai static const char *cm9780_ch_select[] = { "Front", "Side", "Center/LFE", "Rear" };
26765f0dccf8STakashi Iwai static const struct ac97_enum cm9780_ch_select_enum =
26775f0dccf8STakashi Iwai 	AC97_ENUM_SINGLE(AC97_CM9780_MULTI_CHAN, 6, 4, cm9780_ch_select);
2678ee42381eSTakashi Iwai static const struct snd_kcontrol_new cm9780_controls[] = {
26795f0dccf8STakashi Iwai 	AC97_DOUBLE("Side Playback Switch", AC97_CM9780_SIDE, 15, 7, 1, 1),
26805f0dccf8STakashi Iwai 	AC97_DOUBLE("Side Playback Volume", AC97_CM9780_SIDE, 8, 0, 31, 0),
26815f0dccf8STakashi Iwai 	AC97_ENUM("Side Playback Route", cm9780_ch_select_enum),
26825f0dccf8STakashi Iwai };
26835f0dccf8STakashi Iwai 
2684ee42381eSTakashi Iwai static int patch_cm9780_specific(struct snd_ac97 *ac97)
26855f0dccf8STakashi Iwai {
26865f0dccf8STakashi Iwai 	return patch_build_controls(ac97, cm9780_controls, ARRAY_SIZE(cm9780_controls));
26875f0dccf8STakashi Iwai }
26885f0dccf8STakashi Iwai 
26895f0dccf8STakashi Iwai static struct snd_ac97_build_ops patch_cm9780_ops = {
26905f0dccf8STakashi Iwai 	.build_specific	= patch_cm9780_specific,
26915f0dccf8STakashi Iwai 	.build_post_spdif = patch_cm9761_post_spdif	/* identical with CM9761 */
26925f0dccf8STakashi Iwai };
26935f0dccf8STakashi Iwai 
2694ee42381eSTakashi Iwai int patch_cm9780(struct snd_ac97 *ac97)
26955f0dccf8STakashi Iwai {
26965f0dccf8STakashi Iwai 	unsigned short val;
26975f0dccf8STakashi Iwai 
26985f0dccf8STakashi Iwai 	ac97->build_ops = &patch_cm9780_ops;
26995f0dccf8STakashi Iwai 
27005f0dccf8STakashi Iwai 	/* enable spdif */
27015f0dccf8STakashi Iwai 	if (ac97->ext_id & AC97_EI_SPDIF) {
27025f0dccf8STakashi Iwai 		ac97->rates[AC97_RATES_SPDIF] = SNDRV_PCM_RATE_48000; /* 48k only */
27035f0dccf8STakashi Iwai 		val = snd_ac97_read(ac97, AC97_CM9780_SPDIF);
27045f0dccf8STakashi Iwai 		val |= 0x1; /* SPDI_EN */
27055f0dccf8STakashi Iwai 		snd_ac97_write_cache(ac97, AC97_CM9780_SPDIF, val);
27065f0dccf8STakashi Iwai 	}
27075f0dccf8STakashi Iwai 
27085f0dccf8STakashi Iwai 	return 0;
27095f0dccf8STakashi Iwai }
27101da177e4SLinus Torvalds 
27111da177e4SLinus Torvalds /*
27121da177e4SLinus Torvalds  * VIA VT1616 codec
27131da177e4SLinus Torvalds  */
2714ee42381eSTakashi Iwai static const struct snd_kcontrol_new snd_ac97_controls_vt1616[] = {
27151da177e4SLinus Torvalds AC97_SINGLE("DC Offset removal", 0x5a, 10, 1, 0),
27161da177e4SLinus Torvalds AC97_SINGLE("Alternate Level to Surround Out", 0x5a, 15, 1, 0),
27171da177e4SLinus Torvalds AC97_SINGLE("Downmix LFE and Center to Front", 0x5a, 12, 1, 0),
27181da177e4SLinus Torvalds AC97_SINGLE("Downmix Surround to Front", 0x5a, 11, 1, 0),
27191da177e4SLinus Torvalds };
27201da177e4SLinus Torvalds 
2721ee42381eSTakashi Iwai static int patch_vt1616_specific(struct snd_ac97 * ac97)
27221da177e4SLinus Torvalds {
27231da177e4SLinus Torvalds 	int err;
27241da177e4SLinus Torvalds 
27251da177e4SLinus Torvalds 	if (snd_ac97_try_bit(ac97, 0x5a, 9))
27261da177e4SLinus Torvalds 		if ((err = patch_build_controls(ac97, &snd_ac97_controls_vt1616[0], 1)) < 0)
27271da177e4SLinus Torvalds 			return err;
27281da177e4SLinus Torvalds 	if ((err = patch_build_controls(ac97, &snd_ac97_controls_vt1616[1], ARRAY_SIZE(snd_ac97_controls_vt1616) - 1)) < 0)
27291da177e4SLinus Torvalds 		return err;
27301da177e4SLinus Torvalds 	return 0;
27311da177e4SLinus Torvalds }
27321da177e4SLinus Torvalds 
27331da177e4SLinus Torvalds static struct snd_ac97_build_ops patch_vt1616_ops = {
27341da177e4SLinus Torvalds 	.build_specific	= patch_vt1616_specific
27351da177e4SLinus Torvalds };
27361da177e4SLinus Torvalds 
2737ee42381eSTakashi Iwai int patch_vt1616(struct snd_ac97 * ac97)
27381da177e4SLinus Torvalds {
27391da177e4SLinus Torvalds 	ac97->build_ops = &patch_vt1616_ops;
27401da177e4SLinus Torvalds 	return 0;
27411da177e4SLinus Torvalds }
27421da177e4SLinus Torvalds 
2743eb8caf30STakashi Iwai /*
27444b499486SPhilip Prindeville  * VT1617A codec
27454b499486SPhilip Prindeville  */
2746ee42381eSTakashi Iwai int patch_vt1617a(struct snd_ac97 * ac97)
27474b499486SPhilip Prindeville {
27484b499486SPhilip Prindeville 	ac97->ext_id |= AC97_EI_SPDIF;	/* force the detection of spdif */
27494b499486SPhilip Prindeville 	ac97->rates[AC97_RATES_SPDIF] = SNDRV_PCM_RATE_44100 | SNDRV_PCM_RATE_48000;
27504b499486SPhilip Prindeville 	return 0;
27514b499486SPhilip Prindeville }
27524b499486SPhilip Prindeville 
27534b499486SPhilip Prindeville /*
2754eb8caf30STakashi Iwai  */
2755ee42381eSTakashi Iwai static void it2646_update_jacks(struct snd_ac97 *ac97)
2756eb8caf30STakashi Iwai {
2757eb8caf30STakashi Iwai 	/* shared Line-In */
2758eb8caf30STakashi Iwai 	snd_ac97_update_bits(ac97, 0x76, 1 << 9,
2759eb8caf30STakashi Iwai 			     is_shared_linein(ac97) ? (1<<9) : 0);
2760eb8caf30STakashi Iwai 	/* shared Mic */
2761eb8caf30STakashi Iwai 	snd_ac97_update_bits(ac97, 0x76, 1 << 10,
2762eb8caf30STakashi Iwai 			     is_shared_micin(ac97) ? (1<<10) : 0);
2763eb8caf30STakashi Iwai }
2764eb8caf30STakashi Iwai 
2765ee42381eSTakashi Iwai static const struct snd_kcontrol_new snd_ac97_controls_it2646[] = {
2766eb8caf30STakashi Iwai 	AC97_SURROUND_JACK_MODE_CTL,
2767eb8caf30STakashi Iwai 	AC97_CHANNEL_MODE_CTL,
27681da177e4SLinus Torvalds };
27691da177e4SLinus Torvalds 
2770ee42381eSTakashi Iwai static const struct snd_kcontrol_new snd_ac97_spdif_controls_it2646[] = {
277110e8d78aSClemens Ladisch 	AC97_SINGLE(SNDRV_CTL_NAME_IEC958("",CAPTURE,SWITCH), 0x76, 11, 1, 0),
27721da177e4SLinus Torvalds 	AC97_SINGLE("Analog to IEC958 Output", 0x76, 12, 1, 0),
27731da177e4SLinus Torvalds 	AC97_SINGLE("IEC958 Input Monitor", 0x76, 13, 1, 0),
27741da177e4SLinus Torvalds };
27751da177e4SLinus Torvalds 
2776ee42381eSTakashi Iwai static int patch_it2646_specific(struct snd_ac97 * ac97)
27771da177e4SLinus Torvalds {
27781da177e4SLinus Torvalds 	int err;
27791da177e4SLinus Torvalds 	if ((err = patch_build_controls(ac97, snd_ac97_controls_it2646, ARRAY_SIZE(snd_ac97_controls_it2646))) < 0)
27801da177e4SLinus Torvalds 		return err;
27811da177e4SLinus Torvalds 	if ((err = patch_build_controls(ac97, snd_ac97_spdif_controls_it2646, ARRAY_SIZE(snd_ac97_spdif_controls_it2646))) < 0)
27821da177e4SLinus Torvalds 		return err;
27831da177e4SLinus Torvalds 	return 0;
27841da177e4SLinus Torvalds }
27851da177e4SLinus Torvalds 
27861da177e4SLinus Torvalds static struct snd_ac97_build_ops patch_it2646_ops = {
2787eb8caf30STakashi Iwai 	.build_specific	= patch_it2646_specific,
2788eb8caf30STakashi Iwai 	.update_jacks = it2646_update_jacks
27891da177e4SLinus Torvalds };
27901da177e4SLinus Torvalds 
2791ee42381eSTakashi Iwai int patch_it2646(struct snd_ac97 * ac97)
27921da177e4SLinus Torvalds {
27931da177e4SLinus Torvalds 	ac97->build_ops = &patch_it2646_ops;
27941da177e4SLinus Torvalds 	/* full DAC volume */
27951da177e4SLinus Torvalds 	snd_ac97_write_cache(ac97, 0x5E, 0x0808);
27961da177e4SLinus Torvalds 	snd_ac97_write_cache(ac97, 0x7A, 0x0808);
27971da177e4SLinus Torvalds 	return 0;
27981da177e4SLinus Torvalds }
27991da177e4SLinus Torvalds 
280087d61c29SSasha Khapyorsky /*
280187d61c29SSasha Khapyorsky  * Si3036 codec
280287d61c29SSasha Khapyorsky  */
280387d61c29SSasha Khapyorsky 
28041da177e4SLinus Torvalds #define AC97_SI3036_CHIP_ID     0x5a
280587d61c29SSasha Khapyorsky #define AC97_SI3036_LINE_CFG    0x5c
280687d61c29SSasha Khapyorsky 
2807ee42381eSTakashi Iwai static const struct snd_kcontrol_new snd_ac97_controls_si3036[] = {
280887d61c29SSasha Khapyorsky AC97_DOUBLE("Modem Speaker Volume", 0x5c, 14, 12, 3, 1)
280987d61c29SSasha Khapyorsky };
281087d61c29SSasha Khapyorsky 
2811ee42381eSTakashi Iwai static int patch_si3036_specific(struct snd_ac97 * ac97)
281287d61c29SSasha Khapyorsky {
281327bcaa69SSasha Khapyorsky 	int idx, err;
281427bcaa69SSasha Khapyorsky 	for (idx = 0; idx < ARRAY_SIZE(snd_ac97_controls_si3036); idx++)
281527bcaa69SSasha Khapyorsky 		if ((err = snd_ctl_add(ac97->bus->card, snd_ctl_new1(&snd_ac97_controls_si3036[idx], ac97))) < 0)
281627bcaa69SSasha Khapyorsky 			return err;
281727bcaa69SSasha Khapyorsky 	return 0;
281887d61c29SSasha Khapyorsky }
281987d61c29SSasha Khapyorsky 
282087d61c29SSasha Khapyorsky static struct snd_ac97_build_ops patch_si3036_ops = {
282187d61c29SSasha Khapyorsky 	.build_specific	= patch_si3036_specific,
282287d61c29SSasha Khapyorsky };
28231da177e4SLinus Torvalds 
2824ee42381eSTakashi Iwai int mpatch_si3036(struct snd_ac97 * ac97)
28251da177e4SLinus Torvalds {
282687d61c29SSasha Khapyorsky 	ac97->build_ops = &patch_si3036_ops;
28271da177e4SLinus Torvalds 	snd_ac97_write_cache(ac97, 0x5c, 0xf210 );
28281da177e4SLinus Torvalds 	snd_ac97_write_cache(ac97, 0x68, 0);
28291da177e4SLinus Torvalds 	return 0;
28301da177e4SLinus Torvalds }
2831ba22429dSCharl Coetzee 
2832ba22429dSCharl Coetzee /*
2833ba22429dSCharl Coetzee  * LM 4550 Codec
2834ba22429dSCharl Coetzee  *
2835ba22429dSCharl Coetzee  * We use a static resolution table since LM4550 codec cannot be
2836ba22429dSCharl Coetzee  * properly autoprobed to determine the resolution via
2837ba22429dSCharl Coetzee  * check_volume_resolution().
2838ba22429dSCharl Coetzee  */
2839ba22429dSCharl Coetzee 
2840ba22429dSCharl Coetzee static struct snd_ac97_res_table lm4550_restbl[] = {
2841ba22429dSCharl Coetzee 	{ AC97_MASTER, 0x1f1f },
2842ba22429dSCharl Coetzee 	{ AC97_HEADPHONE, 0x1f1f },
2843ba22429dSCharl Coetzee 	{ AC97_MASTER_MONO, 0x001f },
2844ba22429dSCharl Coetzee 	{ AC97_PC_BEEP, 0x001f },	/* LSB is ignored */
2845ba22429dSCharl Coetzee 	{ AC97_PHONE, 0x001f },
2846ba22429dSCharl Coetzee 	{ AC97_MIC, 0x001f },
2847ba22429dSCharl Coetzee 	{ AC97_LINE, 0x1f1f },
2848ba22429dSCharl Coetzee 	{ AC97_CD, 0x1f1f },
2849ba22429dSCharl Coetzee 	{ AC97_VIDEO, 0x1f1f },
2850ba22429dSCharl Coetzee 	{ AC97_AUX, 0x1f1f },
2851ba22429dSCharl Coetzee 	{ AC97_PCM, 0x1f1f },
2852ba22429dSCharl Coetzee 	{ AC97_REC_GAIN, 0x0f0f },
2853ba22429dSCharl Coetzee 	{ } /* terminator */
2854ba22429dSCharl Coetzee };
2855ba22429dSCharl Coetzee 
2856ba22429dSCharl Coetzee int patch_lm4550(struct snd_ac97 *ac97)
2857ba22429dSCharl Coetzee {
2858ba22429dSCharl Coetzee 	ac97->res_table = lm4550_restbl;
2859ba22429dSCharl Coetzee 	return 0;
2860ba22429dSCharl Coetzee }
2861