xref: /linux/sound/pci/ac97/ac97_patch.c (revision 79790b6818e96c58fe2bffee1b418c16e64e7b80)
11a59d1b8SThomas Gleixner // SPDX-License-Identifier: GPL-2.0-or-later
21da177e4SLinus Torvalds /*
3c1017a4cSJaroslav Kysela  *  Copyright (c) by Jaroslav Kysela <perex@perex.cz>
41da177e4SLinus Torvalds  *  Universal interface for Audio Codec '97
51da177e4SLinus Torvalds  *
61da177e4SLinus Torvalds  *  For more details look to AC '97 component specification revision 2.2
71da177e4SLinus Torvalds  *  by Intel Corporation (http://developer.intel.com) and to datasheets
81da177e4SLinus Torvalds  *  for specific codecs.
91da177e4SLinus Torvalds  */
101da177e4SLinus Torvalds 
111da177e4SLinus Torvalds #include "ac97_local.h"
12ac519028STakashi Iwai #include "ac97_patch.h"
131da177e4SLinus Torvalds 
141da177e4SLinus Torvalds /*
156ba9256cSAndreas Mohr  *  Forward declarations
166ba9256cSAndreas Mohr  */
176ba9256cSAndreas Mohr 
186ba9256cSAndreas Mohr static struct snd_kcontrol *snd_ac97_find_mixer_ctl(struct snd_ac97 *ac97,
196ba9256cSAndreas Mohr 						    const char *name);
206ba9256cSAndreas Mohr static int snd_ac97_add_vmaster(struct snd_ac97 *ac97, char *name,
211bc10bb6STakashi Iwai 				const unsigned int *tlv,
229ab0cb30STakashi Iwai 				const char * const *followers);
236ba9256cSAndreas Mohr 
246ba9256cSAndreas Mohr /*
251da177e4SLinus Torvalds  *  Chip specific initialization
261da177e4SLinus Torvalds  */
271da177e4SLinus Torvalds 
patch_build_controls(struct snd_ac97 * ac97,const struct snd_kcontrol_new * controls,int count)28ee42381eSTakashi Iwai static int patch_build_controls(struct snd_ac97 * ac97, const struct snd_kcontrol_new *controls, int count)
291da177e4SLinus Torvalds {
301da177e4SLinus Torvalds 	int idx, err;
311da177e4SLinus Torvalds 
32e66fd362STakashi Iwai 	for (idx = 0; idx < count; idx++) {
33e66fd362STakashi Iwai 		err = snd_ctl_add(ac97->bus->card, snd_ac97_cnew(&controls[idx], ac97));
34e66fd362STakashi Iwai 		if (err < 0)
351da177e4SLinus Torvalds 			return err;
36e66fd362STakashi Iwai 	}
371da177e4SLinus Torvalds 	return 0;
381da177e4SLinus Torvalds }
391da177e4SLinus Torvalds 
402f3482fbSTakashi Iwai /* replace with a new TLV */
reset_tlv(struct snd_ac97 * ac97,const char * name,const unsigned int * tlv)412f3482fbSTakashi Iwai static void reset_tlv(struct snd_ac97 *ac97, const char *name,
420cb29ea0STakashi Iwai 		      const unsigned int *tlv)
432f3482fbSTakashi Iwai {
442f3482fbSTakashi Iwai 	struct snd_kcontrol *kctl;
45*cecc34aeSTakashi Iwai 
46*cecc34aeSTakashi Iwai 	kctl = snd_ctl_find_id_mixer(ac97->bus->card, name);
472f3482fbSTakashi Iwai 	if (kctl && kctl->tlv.p)
482f3482fbSTakashi Iwai 		kctl->tlv.p = tlv;
492f3482fbSTakashi Iwai }
502f3482fbSTakashi Iwai 
511da177e4SLinus Torvalds /* set to the page, update bits and restore the page */
ac97_update_bits_page(struct snd_ac97 * ac97,unsigned short reg,unsigned short mask,unsigned short value,unsigned short page)52ee42381eSTakashi Iwai static int ac97_update_bits_page(struct snd_ac97 *ac97, unsigned short reg, unsigned short mask, unsigned short value, unsigned short page)
531da177e4SLinus Torvalds {
541da177e4SLinus Torvalds 	unsigned short page_save;
551da177e4SLinus Torvalds 	int ret;
561da177e4SLinus Torvalds 
5762932df8SIngo Molnar 	mutex_lock(&ac97->page_mutex);
581da177e4SLinus Torvalds 	page_save = snd_ac97_read(ac97, AC97_INT_PAGING) & AC97_PAGE_MASK;
591da177e4SLinus Torvalds 	snd_ac97_update_bits(ac97, AC97_INT_PAGING, AC97_PAGE_MASK, page);
601da177e4SLinus Torvalds 	ret = snd_ac97_update_bits(ac97, reg, mask, value);
611da177e4SLinus Torvalds 	snd_ac97_update_bits(ac97, AC97_INT_PAGING, AC97_PAGE_MASK, page_save);
6262932df8SIngo Molnar 	mutex_unlock(&ac97->page_mutex); /* unlock paging */
631da177e4SLinus Torvalds 	return ret;
641da177e4SLinus Torvalds }
651da177e4SLinus Torvalds 
66eb8caf30STakashi Iwai /*
67eb8caf30STakashi Iwai  * shared line-in/mic controls
68eb8caf30STakashi Iwai  */
ac97_surround_jack_mode_info(struct snd_kcontrol * kcontrol,struct snd_ctl_elem_info * uinfo)69ee42381eSTakashi Iwai static int ac97_surround_jack_mode_info(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_info *uinfo)
70eb8caf30STakashi Iwai {
713b7a00dcSTakashi Iwai 	static const char * const texts[] = { "Shared", "Independent" };
723b7a00dcSTakashi Iwai 
733b7a00dcSTakashi Iwai 	return snd_ctl_enum_info(uinfo, 1, 2, texts);
74eb8caf30STakashi Iwai }
75eb8caf30STakashi Iwai 
ac97_surround_jack_mode_get(struct snd_kcontrol * kcontrol,struct snd_ctl_elem_value * ucontrol)76ee42381eSTakashi Iwai static int ac97_surround_jack_mode_get(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
77eb8caf30STakashi Iwai {
78ee42381eSTakashi Iwai 	struct snd_ac97 *ac97 = snd_kcontrol_chip(kcontrol);
79eb8caf30STakashi Iwai 
80eb8caf30STakashi Iwai 	ucontrol->value.enumerated.item[0] = ac97->indep_surround;
81eb8caf30STakashi Iwai 	return 0;
82eb8caf30STakashi Iwai }
83eb8caf30STakashi Iwai 
ac97_surround_jack_mode_put(struct snd_kcontrol * kcontrol,struct snd_ctl_elem_value * ucontrol)84ee42381eSTakashi Iwai static int ac97_surround_jack_mode_put(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
85eb8caf30STakashi Iwai {
86ee42381eSTakashi Iwai 	struct snd_ac97 *ac97 = snd_kcontrol_chip(kcontrol);
87eb8caf30STakashi Iwai 	unsigned char indep = !!ucontrol->value.enumerated.item[0];
88eb8caf30STakashi Iwai 
89eb8caf30STakashi Iwai 	if (indep != ac97->indep_surround) {
90eb8caf30STakashi Iwai 		ac97->indep_surround = indep;
91eb8caf30STakashi Iwai 		if (ac97->build_ops->update_jacks)
92eb8caf30STakashi Iwai 			ac97->build_ops->update_jacks(ac97);
93eb8caf30STakashi Iwai 		return 1;
94eb8caf30STakashi Iwai 	}
95eb8caf30STakashi Iwai 	return 0;
96eb8caf30STakashi Iwai }
97eb8caf30STakashi Iwai 
ac97_channel_mode_info(struct snd_kcontrol * kcontrol,struct snd_ctl_elem_info * uinfo)98ee42381eSTakashi Iwai static int ac97_channel_mode_info(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_info *uinfo)
99eb8caf30STakashi Iwai {
1003b7a00dcSTakashi Iwai 	static const char * const texts[] = { "2ch", "4ch", "6ch", "8ch" };
1013b7a00dcSTakashi Iwai 
1023b7a00dcSTakashi Iwai 	return snd_ctl_enum_info(uinfo, 1, kcontrol->private_value, texts);
103eb8caf30STakashi Iwai }
104eb8caf30STakashi Iwai 
ac97_channel_mode_get(struct snd_kcontrol * kcontrol,struct snd_ctl_elem_value * ucontrol)105ee42381eSTakashi Iwai static int ac97_channel_mode_get(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
106eb8caf30STakashi Iwai {
107ee42381eSTakashi Iwai 	struct snd_ac97 *ac97 = snd_kcontrol_chip(kcontrol);
108eb8caf30STakashi Iwai 
109eb8caf30STakashi Iwai 	ucontrol->value.enumerated.item[0] = ac97->channel_mode;
110eb8caf30STakashi Iwai 	return 0;
111eb8caf30STakashi Iwai }
112eb8caf30STakashi Iwai 
ac97_channel_mode_put(struct snd_kcontrol * kcontrol,struct snd_ctl_elem_value * ucontrol)113ee42381eSTakashi Iwai static int ac97_channel_mode_put(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
114eb8caf30STakashi Iwai {
115ee42381eSTakashi Iwai 	struct snd_ac97 *ac97 = snd_kcontrol_chip(kcontrol);
116eb8caf30STakashi Iwai 	unsigned char mode = ucontrol->value.enumerated.item[0];
117eb8caf30STakashi Iwai 
1184235a317STakashi Iwai 	if (mode >= kcontrol->private_value)
1194e98d6a7STakashi Iwai 		return -EINVAL;
1204e98d6a7STakashi Iwai 
121eb8caf30STakashi Iwai 	if (mode != ac97->channel_mode) {
122eb8caf30STakashi Iwai 		ac97->channel_mode = mode;
123eb8caf30STakashi Iwai 		if (ac97->build_ops->update_jacks)
124eb8caf30STakashi Iwai 			ac97->build_ops->update_jacks(ac97);
125eb8caf30STakashi Iwai 		return 1;
126eb8caf30STakashi Iwai 	}
127eb8caf30STakashi Iwai 	return 0;
128eb8caf30STakashi Iwai }
129eb8caf30STakashi Iwai 
130eb8caf30STakashi Iwai #define AC97_SURROUND_JACK_MODE_CTL \
131eb8caf30STakashi Iwai 	{ \
132eb8caf30STakashi Iwai 		.iface	= SNDRV_CTL_ELEM_IFACE_MIXER, \
133eb8caf30STakashi Iwai 		.name	= "Surround Jack Mode", \
134eb8caf30STakashi Iwai 		.info = ac97_surround_jack_mode_info, \
135eb8caf30STakashi Iwai 		.get = ac97_surround_jack_mode_get, \
136eb8caf30STakashi Iwai 		.put = ac97_surround_jack_mode_put, \
137eb8caf30STakashi Iwai 	}
1384235a317STakashi Iwai /* 6ch */
139eb8caf30STakashi Iwai #define AC97_CHANNEL_MODE_CTL \
140eb8caf30STakashi Iwai 	{ \
141eb8caf30STakashi Iwai 		.iface	= SNDRV_CTL_ELEM_IFACE_MIXER, \
142eb8caf30STakashi Iwai 		.name	= "Channel Mode", \
143eb8caf30STakashi Iwai 		.info = ac97_channel_mode_info, \
144eb8caf30STakashi Iwai 		.get = ac97_channel_mode_get, \
145eb8caf30STakashi Iwai 		.put = ac97_channel_mode_put, \
1464235a317STakashi Iwai 		.private_value = 3, \
147eb8caf30STakashi Iwai 	}
1484235a317STakashi Iwai /* 4ch */
149eb8caf30STakashi Iwai #define AC97_CHANNEL_MODE_4CH_CTL \
150eb8caf30STakashi Iwai 	{ \
151eb8caf30STakashi Iwai 		.iface	= SNDRV_CTL_ELEM_IFACE_MIXER, \
152eb8caf30STakashi Iwai 		.name	= "Channel Mode", \
153eb8caf30STakashi Iwai 		.info = ac97_channel_mode_info, \
154eb8caf30STakashi Iwai 		.get = ac97_channel_mode_get, \
155eb8caf30STakashi Iwai 		.put = ac97_channel_mode_put, \
1564235a317STakashi Iwai 		.private_value = 2, \
1574235a317STakashi Iwai 	}
1584235a317STakashi Iwai /* 8ch */
1594235a317STakashi Iwai #define AC97_CHANNEL_MODE_8CH_CTL \
1604235a317STakashi Iwai 	{ \
1614235a317STakashi Iwai 		.iface  = SNDRV_CTL_ELEM_IFACE_MIXER, \
1624235a317STakashi Iwai 		.name   = "Channel Mode", \
1634235a317STakashi Iwai 		.info = ac97_channel_mode_info, \
1644235a317STakashi Iwai 		.get = ac97_channel_mode_get, \
1654235a317STakashi Iwai 		.put = ac97_channel_mode_put, \
1664235a317STakashi Iwai 		.private_value = 4, \
167eb8caf30STakashi Iwai 	}
168eb8caf30STakashi Iwai 
is_surround_on(struct snd_ac97 * ac97)169ee42381eSTakashi Iwai static inline int is_surround_on(struct snd_ac97 *ac97)
1704525c9f3STakashi Iwai {
1714525c9f3STakashi Iwai 	return ac97->channel_mode >= 1;
1724525c9f3STakashi Iwai }
1734525c9f3STakashi Iwai 
is_clfe_on(struct snd_ac97 * ac97)174ee42381eSTakashi Iwai static inline int is_clfe_on(struct snd_ac97 *ac97)
1754525c9f3STakashi Iwai {
176eb9b4142STakashi Iwai 	return ac97->channel_mode >= 2;
1774525c9f3STakashi Iwai }
1784525c9f3STakashi Iwai 
179831466f4SRandy Cushman /* system has shared jacks with surround out enabled */
is_shared_surrout(struct snd_ac97 * ac97)180831466f4SRandy Cushman static inline int is_shared_surrout(struct snd_ac97 *ac97)
181eb8caf30STakashi Iwai {
1824525c9f3STakashi Iwai 	return !ac97->indep_surround && is_surround_on(ac97);
183eb8caf30STakashi Iwai }
184eb8caf30STakashi Iwai 
185831466f4SRandy Cushman /* system has shared jacks with center/lfe out enabled */
is_shared_clfeout(struct snd_ac97 * ac97)186831466f4SRandy Cushman static inline int is_shared_clfeout(struct snd_ac97 *ac97)
187eb8caf30STakashi Iwai {
1884525c9f3STakashi Iwai 	return !ac97->indep_surround && is_clfe_on(ac97);
189eb8caf30STakashi Iwai }
190eb8caf30STakashi Iwai 
191831466f4SRandy Cushman /* system has shared jacks with line in enabled */
is_shared_linein(struct snd_ac97 * ac97)192831466f4SRandy Cushman static inline int is_shared_linein(struct snd_ac97 *ac97)
193831466f4SRandy Cushman {
194831466f4SRandy Cushman 	return !ac97->indep_surround && !is_surround_on(ac97);
195831466f4SRandy Cushman }
196831466f4SRandy Cushman 
197831466f4SRandy Cushman /* system has shared jacks with mic in enabled */
is_shared_micin(struct snd_ac97 * ac97)198831466f4SRandy Cushman static inline int is_shared_micin(struct snd_ac97 *ac97)
199831466f4SRandy Cushman {
200831466f4SRandy Cushman 	return !ac97->indep_surround && !is_clfe_on(ac97);
201831466f4SRandy Cushman }
202831466f4SRandy Cushman 
alc850_is_aux_back_surround(struct snd_ac97 * ac97)2034235a317STakashi Iwai static inline int alc850_is_aux_back_surround(struct snd_ac97 *ac97)
2044235a317STakashi Iwai {
2054235a317STakashi Iwai 	return is_surround_on(ac97);
2064235a317STakashi Iwai }
207eb8caf30STakashi Iwai 
2081da177e4SLinus Torvalds /* The following snd_ac97_ymf753_... items added by David Shust (dshust@shustring.com) */
20943115f58SKeita Maehara /* Modified for YMF743 by Keita Maehara <maehara@debian.org> */
2101da177e4SLinus Torvalds 
21113043984SKeita Maehara /* It is possible to indicate to the Yamaha YMF7x3 the type of
21213043984SKeita Maehara    speakers being used. */
21313043984SKeita Maehara 
snd_ac97_ymf7x3_info_speaker(struct snd_kcontrol * kcontrol,struct snd_ctl_elem_info * uinfo)21413043984SKeita Maehara static int snd_ac97_ymf7x3_info_speaker(struct snd_kcontrol *kcontrol,
21513043984SKeita Maehara 					struct snd_ctl_elem_info *uinfo)
2161da177e4SLinus Torvalds {
2173b7a00dcSTakashi Iwai 	static const char * const texts[3] = {
2181da177e4SLinus Torvalds 		"Standard", "Small", "Smaller"
2191da177e4SLinus Torvalds 	};
2201da177e4SLinus Torvalds 
2213b7a00dcSTakashi Iwai 	return snd_ctl_enum_info(uinfo, 1, 3, texts);
2221da177e4SLinus Torvalds }
2231da177e4SLinus Torvalds 
snd_ac97_ymf7x3_get_speaker(struct snd_kcontrol * kcontrol,struct snd_ctl_elem_value * ucontrol)22413043984SKeita Maehara static int snd_ac97_ymf7x3_get_speaker(struct snd_kcontrol *kcontrol,
22513043984SKeita Maehara 				       struct snd_ctl_elem_value *ucontrol)
2261da177e4SLinus Torvalds {
227ee42381eSTakashi Iwai 	struct snd_ac97 *ac97 = snd_kcontrol_chip(kcontrol);
2281da177e4SLinus Torvalds 	unsigned short val;
2291da177e4SLinus Torvalds 
23013043984SKeita Maehara 	val = ac97->regs[AC97_YMF7X3_3D_MODE_SEL];
2311da177e4SLinus Torvalds 	val = (val >> 10) & 3;
2321da177e4SLinus Torvalds 	if (val > 0)    /* 0 = invalid */
2331da177e4SLinus Torvalds 		val--;
2341da177e4SLinus Torvalds 	ucontrol->value.enumerated.item[0] = val;
2351da177e4SLinus Torvalds 	return 0;
2361da177e4SLinus Torvalds }
2371da177e4SLinus Torvalds 
snd_ac97_ymf7x3_put_speaker(struct snd_kcontrol * kcontrol,struct snd_ctl_elem_value * ucontrol)23813043984SKeita Maehara static int snd_ac97_ymf7x3_put_speaker(struct snd_kcontrol *kcontrol,
23913043984SKeita Maehara 				       struct snd_ctl_elem_value *ucontrol)
2401da177e4SLinus Torvalds {
241ee42381eSTakashi Iwai 	struct snd_ac97 *ac97 = snd_kcontrol_chip(kcontrol);
2421da177e4SLinus Torvalds 	unsigned short val;
2431da177e4SLinus Torvalds 
2441da177e4SLinus Torvalds 	if (ucontrol->value.enumerated.item[0] > 2)
2451da177e4SLinus Torvalds 		return -EINVAL;
2461da177e4SLinus Torvalds 	val = (ucontrol->value.enumerated.item[0] + 1) << 10;
24713043984SKeita Maehara 	return snd_ac97_update(ac97, AC97_YMF7X3_3D_MODE_SEL, val);
2481da177e4SLinus Torvalds }
2491da177e4SLinus Torvalds 
25013043984SKeita Maehara static const struct snd_kcontrol_new snd_ac97_ymf7x3_controls_speaker =
2511da177e4SLinus Torvalds {
2521da177e4SLinus Torvalds 	.iface  = SNDRV_CTL_ELEM_IFACE_MIXER,
2531da177e4SLinus Torvalds 	.name   = "3D Control - Speaker",
25413043984SKeita Maehara 	.info   = snd_ac97_ymf7x3_info_speaker,
25513043984SKeita Maehara 	.get    = snd_ac97_ymf7x3_get_speaker,
25613043984SKeita Maehara 	.put    = snd_ac97_ymf7x3_put_speaker,
2571da177e4SLinus Torvalds };
2581da177e4SLinus Torvalds 
25913043984SKeita Maehara /* It is possible to indicate to the Yamaha YMF7x3 the source to
26013043984SKeita Maehara    direct to the S/PDIF output. */
snd_ac97_ymf7x3_spdif_source_info(struct snd_kcontrol * kcontrol,struct snd_ctl_elem_info * uinfo)26113043984SKeita Maehara static int snd_ac97_ymf7x3_spdif_source_info(struct snd_kcontrol *kcontrol,
26213043984SKeita Maehara 					     struct snd_ctl_elem_info *uinfo)
2631da177e4SLinus Torvalds {
2643b7a00dcSTakashi Iwai 	static const char * const texts[2] = { "AC-Link", "A/D Converter" };
2651da177e4SLinus Torvalds 
2663b7a00dcSTakashi Iwai 	return snd_ctl_enum_info(uinfo, 1, 2, texts);
2671da177e4SLinus Torvalds }
2681da177e4SLinus Torvalds 
snd_ac97_ymf7x3_spdif_source_get(struct snd_kcontrol * kcontrol,struct snd_ctl_elem_value * ucontrol)26913043984SKeita Maehara static int snd_ac97_ymf7x3_spdif_source_get(struct snd_kcontrol *kcontrol,
27013043984SKeita Maehara 					    struct snd_ctl_elem_value *ucontrol)
2711da177e4SLinus Torvalds {
272ee42381eSTakashi Iwai 	struct snd_ac97 *ac97 = snd_kcontrol_chip(kcontrol);
2731da177e4SLinus Torvalds 	unsigned short val;
2741da177e4SLinus Torvalds 
27513043984SKeita Maehara 	val = ac97->regs[AC97_YMF7X3_DIT_CTRL];
2761da177e4SLinus Torvalds 	ucontrol->value.enumerated.item[0] = (val >> 1) & 1;
2771da177e4SLinus Torvalds 	return 0;
2781da177e4SLinus Torvalds }
2791da177e4SLinus Torvalds 
snd_ac97_ymf7x3_spdif_source_put(struct snd_kcontrol * kcontrol,struct snd_ctl_elem_value * ucontrol)28013043984SKeita Maehara static int snd_ac97_ymf7x3_spdif_source_put(struct snd_kcontrol *kcontrol,
28113043984SKeita Maehara 					    struct snd_ctl_elem_value *ucontrol)
2821da177e4SLinus Torvalds {
283ee42381eSTakashi Iwai 	struct snd_ac97 *ac97 = snd_kcontrol_chip(kcontrol);
2841da177e4SLinus Torvalds 	unsigned short val;
2851da177e4SLinus Torvalds 
2861da177e4SLinus Torvalds 	if (ucontrol->value.enumerated.item[0] > 1)
2871da177e4SLinus Torvalds 		return -EINVAL;
2881da177e4SLinus Torvalds 	val = ucontrol->value.enumerated.item[0] << 1;
28913043984SKeita Maehara 	return snd_ac97_update_bits(ac97, AC97_YMF7X3_DIT_CTRL, 0x0002, val);
2901da177e4SLinus Torvalds }
2911da177e4SLinus Torvalds 
patch_yamaha_ymf7x3_3d(struct snd_ac97 * ac97)29243115f58SKeita Maehara static int patch_yamaha_ymf7x3_3d(struct snd_ac97 *ac97)
29343115f58SKeita Maehara {
29443115f58SKeita Maehara 	struct snd_kcontrol *kctl;
29543115f58SKeita Maehara 	int err;
29643115f58SKeita Maehara 
29743115f58SKeita Maehara 	kctl = snd_ac97_cnew(&snd_ac97_controls_3d[0], ac97);
29843115f58SKeita Maehara 	err = snd_ctl_add(ac97->bus->card, kctl);
29943115f58SKeita Maehara 	if (err < 0)
30043115f58SKeita Maehara 		return err;
30143115f58SKeita Maehara 	strcpy(kctl->id.name, "3D Control - Wide");
30243115f58SKeita Maehara 	kctl->private_value = AC97_SINGLE_VALUE(AC97_3D_CONTROL, 9, 7, 0);
30343115f58SKeita Maehara 	snd_ac97_write_cache(ac97, AC97_3D_CONTROL, 0x0000);
30443115f58SKeita Maehara 	err = snd_ctl_add(ac97->bus->card,
30543115f58SKeita Maehara 			  snd_ac97_cnew(&snd_ac97_ymf7x3_controls_speaker,
30643115f58SKeita Maehara 					ac97));
30743115f58SKeita Maehara 	if (err < 0)
30843115f58SKeita Maehara 		return err;
30943115f58SKeita Maehara 	snd_ac97_write_cache(ac97, AC97_YMF7X3_3D_MODE_SEL, 0x0c00);
31043115f58SKeita Maehara 	return 0;
31143115f58SKeita Maehara }
31243115f58SKeita Maehara 
31343115f58SKeita Maehara static const struct snd_kcontrol_new snd_ac97_yamaha_ymf743_controls_spdif[3] =
31443115f58SKeita Maehara {
31543115f58SKeita Maehara 	AC97_SINGLE(SNDRV_CTL_NAME_IEC958("", PLAYBACK, SWITCH),
31643115f58SKeita Maehara 		    AC97_YMF7X3_DIT_CTRL, 0, 1, 0),
31743115f58SKeita Maehara 	{
31843115f58SKeita Maehara 		.iface	= SNDRV_CTL_ELEM_IFACE_MIXER,
31943115f58SKeita Maehara 		.name	= SNDRV_CTL_NAME_IEC958("", PLAYBACK, NONE) "Source",
32043115f58SKeita Maehara 		.info	= snd_ac97_ymf7x3_spdif_source_info,
32143115f58SKeita Maehara 		.get	= snd_ac97_ymf7x3_spdif_source_get,
32243115f58SKeita Maehara 		.put	= snd_ac97_ymf7x3_spdif_source_put,
32343115f58SKeita Maehara 	},
32443115f58SKeita Maehara 	AC97_SINGLE(SNDRV_CTL_NAME_IEC958("", NONE, NONE) "Mute",
32543115f58SKeita Maehara 		    AC97_YMF7X3_DIT_CTRL, 2, 1, 1)
32643115f58SKeita Maehara };
32743115f58SKeita Maehara 
patch_yamaha_ymf743_build_spdif(struct snd_ac97 * ac97)32843115f58SKeita Maehara static int patch_yamaha_ymf743_build_spdif(struct snd_ac97 *ac97)
32943115f58SKeita Maehara {
33043115f58SKeita Maehara 	int err;
33143115f58SKeita Maehara 
33243115f58SKeita Maehara 	err = patch_build_controls(ac97, &snd_ac97_controls_spdif[0], 3);
33343115f58SKeita Maehara 	if (err < 0)
33443115f58SKeita Maehara 		return err;
33543115f58SKeita Maehara 	err = patch_build_controls(ac97,
33643115f58SKeita Maehara 				   snd_ac97_yamaha_ymf743_controls_spdif, 3);
33743115f58SKeita Maehara 	if (err < 0)
33843115f58SKeita Maehara 		return err;
33943115f58SKeita Maehara 	/* set default PCM S/PDIF params */
34043115f58SKeita Maehara 	/* PCM audio,no copyright,no preemphasis,PCM coder,original */
34143115f58SKeita Maehara 	snd_ac97_write_cache(ac97, AC97_YMF7X3_DIT_CTRL, 0xa201);
34243115f58SKeita Maehara 	return 0;
34343115f58SKeita Maehara }
34443115f58SKeita Maehara 
3453e8b3b90SHanno Boeck static const struct snd_ac97_build_ops patch_yamaha_ymf743_ops = {
34643115f58SKeita Maehara 	.build_spdif	= patch_yamaha_ymf743_build_spdif,
34743115f58SKeita Maehara 	.build_3d	= patch_yamaha_ymf7x3_3d,
34843115f58SKeita Maehara };
34943115f58SKeita Maehara 
patch_yamaha_ymf743(struct snd_ac97 * ac97)35043115f58SKeita Maehara static int patch_yamaha_ymf743(struct snd_ac97 *ac97)
35143115f58SKeita Maehara {
35243115f58SKeita Maehara 	ac97->build_ops = &patch_yamaha_ymf743_ops;
35343115f58SKeita Maehara 	ac97->caps |= AC97_BC_BASS_TREBLE;
35443115f58SKeita Maehara 	ac97->caps |= 0x04 << 10; /* Yamaha 3D enhancement */
35543115f58SKeita Maehara 	ac97->rates[AC97_RATES_SPDIF] = SNDRV_PCM_RATE_48000; /* 48k only */
35643115f58SKeita Maehara 	ac97->ext_id |= AC97_EI_SPDIF; /* force the detection of spdif */
35743115f58SKeita Maehara 	return 0;
35843115f58SKeita Maehara }
35943115f58SKeita Maehara 
3601da177e4SLinus Torvalds /* The AC'97 spec states that the S/PDIF signal is to be output at pin 48.
3611da177e4SLinus Torvalds    The YMF753 will output the S/PDIF signal to pin 43, 47 (EAPD), or 48.
3621da177e4SLinus Torvalds    By default, no output pin is selected, and the S/PDIF signal is not output.
3631da177e4SLinus Torvalds    There is also a bit to mute S/PDIF output in a vendor-specific register. */
snd_ac97_ymf753_spdif_output_pin_info(struct snd_kcontrol * kcontrol,struct snd_ctl_elem_info * uinfo)364ee42381eSTakashi Iwai static int snd_ac97_ymf753_spdif_output_pin_info(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_info *uinfo)
3651da177e4SLinus Torvalds {
3663b7a00dcSTakashi Iwai 	static const char * const texts[3] = { "Disabled", "Pin 43", "Pin 48" };
3671da177e4SLinus Torvalds 
3683b7a00dcSTakashi Iwai 	return snd_ctl_enum_info(uinfo, 1, 3, texts);
3691da177e4SLinus Torvalds }
3701da177e4SLinus Torvalds 
snd_ac97_ymf753_spdif_output_pin_get(struct snd_kcontrol * kcontrol,struct snd_ctl_elem_value * ucontrol)371ee42381eSTakashi Iwai static int snd_ac97_ymf753_spdif_output_pin_get(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
3721da177e4SLinus Torvalds {
373ee42381eSTakashi Iwai 	struct snd_ac97 *ac97 = snd_kcontrol_chip(kcontrol);
3741da177e4SLinus Torvalds 	unsigned short val;
3751da177e4SLinus Torvalds 
37613043984SKeita Maehara 	val = ac97->regs[AC97_YMF7X3_DIT_CTRL];
3771da177e4SLinus Torvalds 	ucontrol->value.enumerated.item[0] = (val & 0x0008) ? 2 : (val & 0x0020) ? 1 : 0;
3781da177e4SLinus Torvalds 	return 0;
3791da177e4SLinus Torvalds }
3801da177e4SLinus Torvalds 
snd_ac97_ymf753_spdif_output_pin_put(struct snd_kcontrol * kcontrol,struct snd_ctl_elem_value * ucontrol)381ee42381eSTakashi Iwai static int snd_ac97_ymf753_spdif_output_pin_put(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
3821da177e4SLinus Torvalds {
383ee42381eSTakashi Iwai 	struct snd_ac97 *ac97 = snd_kcontrol_chip(kcontrol);
3841da177e4SLinus Torvalds 	unsigned short val;
3851da177e4SLinus Torvalds 
3861da177e4SLinus Torvalds 	if (ucontrol->value.enumerated.item[0] > 2)
3871da177e4SLinus Torvalds 		return -EINVAL;
3881da177e4SLinus Torvalds 	val = (ucontrol->value.enumerated.item[0] == 2) ? 0x0008 :
3891da177e4SLinus Torvalds 	      (ucontrol->value.enumerated.item[0] == 1) ? 0x0020 : 0;
39013043984SKeita Maehara 	return snd_ac97_update_bits(ac97, AC97_YMF7X3_DIT_CTRL, 0x0028, val);
3911da177e4SLinus Torvalds 	/* The following can be used to direct S/PDIF output to pin 47 (EAPD).
3921da177e4SLinus Torvalds 	   snd_ac97_write_cache(ac97, 0x62, snd_ac97_read(ac97, 0x62) | 0x0008); */
3931da177e4SLinus Torvalds }
3941da177e4SLinus Torvalds 
395ee42381eSTakashi Iwai static const struct snd_kcontrol_new snd_ac97_ymf753_controls_spdif[3] = {
3961da177e4SLinus Torvalds 	{
3971da177e4SLinus Torvalds 		.iface	= SNDRV_CTL_ELEM_IFACE_MIXER,
3981da177e4SLinus Torvalds 		.name	= SNDRV_CTL_NAME_IEC958("",PLAYBACK,NONE) "Source",
39913043984SKeita Maehara 		.info	= snd_ac97_ymf7x3_spdif_source_info,
40013043984SKeita Maehara 		.get	= snd_ac97_ymf7x3_spdif_source_get,
40113043984SKeita Maehara 		.put	= snd_ac97_ymf7x3_spdif_source_put,
4021da177e4SLinus Torvalds 	},
4031da177e4SLinus Torvalds 	{
4041da177e4SLinus Torvalds 		.iface	= SNDRV_CTL_ELEM_IFACE_MIXER,
4051da177e4SLinus Torvalds 		.name	= SNDRV_CTL_NAME_IEC958("",PLAYBACK,NONE) "Output Pin",
4061da177e4SLinus Torvalds 		.info	= snd_ac97_ymf753_spdif_output_pin_info,
4071da177e4SLinus Torvalds 		.get	= snd_ac97_ymf753_spdif_output_pin_get,
4081da177e4SLinus Torvalds 		.put	= snd_ac97_ymf753_spdif_output_pin_put,
4091da177e4SLinus Torvalds 	},
41013043984SKeita Maehara 	AC97_SINGLE(SNDRV_CTL_NAME_IEC958("", NONE, NONE) "Mute",
41113043984SKeita Maehara 		    AC97_YMF7X3_DIT_CTRL, 2, 1, 1)
4121da177e4SLinus Torvalds };
4131da177e4SLinus Torvalds 
patch_yamaha_ymf753_post_spdif(struct snd_ac97 * ac97)414ee42381eSTakashi Iwai static int patch_yamaha_ymf753_post_spdif(struct snd_ac97 * ac97)
4151da177e4SLinus Torvalds {
4161da177e4SLinus Torvalds 	int err;
4171da177e4SLinus Torvalds 
418e66fd362STakashi Iwai 	err = patch_build_controls(ac97, snd_ac97_ymf753_controls_spdif, ARRAY_SIZE(snd_ac97_ymf753_controls_spdif));
419e66fd362STakashi Iwai 	if (err < 0)
4201da177e4SLinus Torvalds 		return err;
4211da177e4SLinus Torvalds 	return 0;
4221da177e4SLinus Torvalds }
4231da177e4SLinus Torvalds 
4243e8b3b90SHanno Boeck static const struct snd_ac97_build_ops patch_yamaha_ymf753_ops = {
42513043984SKeita Maehara 	.build_3d	= patch_yamaha_ymf7x3_3d,
4261da177e4SLinus Torvalds 	.build_post_spdif = patch_yamaha_ymf753_post_spdif
4271da177e4SLinus Torvalds };
4281da177e4SLinus Torvalds 
patch_yamaha_ymf753(struct snd_ac97 * ac97)429ac519028STakashi Iwai static int patch_yamaha_ymf753(struct snd_ac97 * ac97)
4301da177e4SLinus Torvalds {
4311da177e4SLinus Torvalds 	/* Patch for Yamaha YMF753, Copyright (c) by David Shust, dshust@shustring.com.
4321da177e4SLinus Torvalds 	   This chip has nonstandard and extended behaviour with regard to its S/PDIF output.
4331da177e4SLinus Torvalds 	   The AC'97 spec states that the S/PDIF signal is to be output at pin 48.
4341da177e4SLinus Torvalds 	   The YMF753 will ouput the S/PDIF signal to pin 43, 47 (EAPD), or 48.
4351da177e4SLinus Torvalds 	   By default, no output pin is selected, and the S/PDIF signal is not output.
4361da177e4SLinus Torvalds 	   There is also a bit to mute S/PDIF output in a vendor-specific register.
4371da177e4SLinus Torvalds 	*/
4381da177e4SLinus Torvalds 	ac97->build_ops = &patch_yamaha_ymf753_ops;
4391da177e4SLinus Torvalds 	ac97->caps |= AC97_BC_BASS_TREBLE;
4401da177e4SLinus Torvalds 	ac97->caps |= 0x04 << 10; /* Yamaha 3D enhancement */
4411da177e4SLinus Torvalds 	return 0;
4421da177e4SLinus Torvalds }
4431da177e4SLinus Torvalds 
4441da177e4SLinus Torvalds /*
445d331124dSLiam Girdwood  * May 2, 2003 Liam Girdwood <lrg@slimlogic.co.uk>
4461da177e4SLinus Torvalds  *  removed broken wolfson00 patch.
4471da177e4SLinus Torvalds  *  added support for WM9705,WM9708,WM9709,WM9710,WM9711,WM9712 and WM9717.
4481da177e4SLinus Torvalds  */
4491da177e4SLinus Torvalds 
450ee42381eSTakashi Iwai static const struct snd_kcontrol_new wm97xx_snd_ac97_controls[] = {
4513998b70fSLiam Girdwood AC97_DOUBLE("Front Playback Volume", AC97_WM97XX_FMIXER_VOL, 8, 0, 31, 1),
4523998b70fSLiam Girdwood AC97_SINGLE("Front Playback Switch", AC97_WM97XX_FMIXER_VOL, 15, 1, 1),
4533998b70fSLiam Girdwood };
4543998b70fSLiam Girdwood 
patch_wolfson_wm9703_specific(struct snd_ac97 * ac97)455ee42381eSTakashi Iwai static int patch_wolfson_wm9703_specific(struct snd_ac97 * ac97)
4561da177e4SLinus Torvalds {
4571da177e4SLinus Torvalds 	/* This is known to work for the ViewSonic ViewPad 1000
4583998b70fSLiam Girdwood 	 * Randolph Bentson <bentson@holmsjoen.com>
4593998b70fSLiam Girdwood 	 * WM9703/9707/9708/9717
4603998b70fSLiam Girdwood 	 */
4613998b70fSLiam Girdwood 	int err, i;
4621da177e4SLinus Torvalds 
4633998b70fSLiam Girdwood 	for (i = 0; i < ARRAY_SIZE(wm97xx_snd_ac97_controls); i++) {
464e66fd362STakashi Iwai 		err = snd_ctl_add(ac97->bus->card, snd_ac97_cnew(&wm97xx_snd_ac97_controls[i], ac97));
465e66fd362STakashi Iwai 		if (err < 0)
4663998b70fSLiam Girdwood 			return err;
4673998b70fSLiam Girdwood 	}
4681da177e4SLinus Torvalds 	snd_ac97_write_cache(ac97,  AC97_WM97XX_FMIXER_VOL, 0x0808);
4691da177e4SLinus Torvalds 	return 0;
4701da177e4SLinus Torvalds }
4711da177e4SLinus Torvalds 
4723e8b3b90SHanno Boeck static const struct snd_ac97_build_ops patch_wolfson_wm9703_ops = {
4733998b70fSLiam Girdwood 	.build_specific = patch_wolfson_wm9703_specific,
4743998b70fSLiam Girdwood };
4753998b70fSLiam Girdwood 
patch_wolfson03(struct snd_ac97 * ac97)476ac519028STakashi Iwai static int patch_wolfson03(struct snd_ac97 * ac97)
4773998b70fSLiam Girdwood {
4783998b70fSLiam Girdwood 	ac97->build_ops = &patch_wolfson_wm9703_ops;
4793998b70fSLiam Girdwood 	return 0;
4803998b70fSLiam Girdwood }
4813998b70fSLiam Girdwood 
482ee42381eSTakashi Iwai static const struct snd_kcontrol_new wm9704_snd_ac97_controls[] = {
4833998b70fSLiam Girdwood AC97_DOUBLE("Front Playback Volume", AC97_WM97XX_FMIXER_VOL, 8, 0, 31, 1),
4843998b70fSLiam Girdwood AC97_SINGLE("Front Playback Switch", AC97_WM97XX_FMIXER_VOL, 15, 1, 1),
4853998b70fSLiam Girdwood AC97_DOUBLE("Rear Playback Volume", AC97_WM9704_RMIXER_VOL, 8, 0, 31, 1),
4863998b70fSLiam Girdwood AC97_SINGLE("Rear Playback Switch", AC97_WM9704_RMIXER_VOL, 15, 1, 1),
4873998b70fSLiam Girdwood AC97_DOUBLE("Rear DAC Volume", AC97_WM9704_RPCM_VOL, 8, 0, 31, 1),
4883998b70fSLiam Girdwood AC97_DOUBLE("Surround Volume", AC97_SURROUND_MASTER, 8, 0, 31, 1),
4893998b70fSLiam Girdwood };
4903998b70fSLiam Girdwood 
patch_wolfson_wm9704_specific(struct snd_ac97 * ac97)491ee42381eSTakashi Iwai static int patch_wolfson_wm9704_specific(struct snd_ac97 * ac97)
4923998b70fSLiam Girdwood {
4933998b70fSLiam Girdwood 	int err, i;
4943998b70fSLiam Girdwood 	for (i = 0; i < ARRAY_SIZE(wm9704_snd_ac97_controls); i++) {
495e66fd362STakashi Iwai 		err = snd_ctl_add(ac97->bus->card, snd_ac97_cnew(&wm9704_snd_ac97_controls[i], ac97));
496e66fd362STakashi Iwai 		if (err < 0)
4973998b70fSLiam Girdwood 			return err;
4983998b70fSLiam Girdwood 	}
4993998b70fSLiam Girdwood 	/* patch for DVD noise */
5003998b70fSLiam Girdwood 	snd_ac97_write_cache(ac97, AC97_WM9704_TEST, 0x0200);
5013998b70fSLiam Girdwood 	return 0;
5023998b70fSLiam Girdwood }
5033998b70fSLiam Girdwood 
5043e8b3b90SHanno Boeck static const struct snd_ac97_build_ops patch_wolfson_wm9704_ops = {
5053998b70fSLiam Girdwood 	.build_specific = patch_wolfson_wm9704_specific,
5063998b70fSLiam Girdwood };
5073998b70fSLiam Girdwood 
patch_wolfson04(struct snd_ac97 * ac97)508ac519028STakashi Iwai static int patch_wolfson04(struct snd_ac97 * ac97)
5091da177e4SLinus Torvalds {
5103998b70fSLiam Girdwood 	/* WM9704M/9704Q */
5113998b70fSLiam Girdwood 	ac97->build_ops = &patch_wolfson_wm9704_ops;
5121da177e4SLinus Torvalds 	return 0;
5131da177e4SLinus Torvalds }
5141da177e4SLinus Torvalds 
patch_wolfson05(struct snd_ac97 * ac97)515ac519028STakashi Iwai static int patch_wolfson05(struct snd_ac97 * ac97)
5161da177e4SLinus Torvalds {
5173998b70fSLiam Girdwood 	/* WM9705, WM9710 */
518dd3533ecSKrzysztof Helt 	ac97->build_ops = &patch_wolfson_wm9703_ops;
5191459c784SRodolfo Giometti #ifdef CONFIG_TOUCHSCREEN_WM9705
5201459c784SRodolfo Giometti 	/* WM9705 touchscreen uses AUX and VIDEO for touch */
5218f88820eSLiam Girdwood 	ac97->flags |= AC97_HAS_NO_VIDEO | AC97_HAS_NO_AUX;
5221459c784SRodolfo Giometti #endif
5231da177e4SLinus Torvalds 	return 0;
5241da177e4SLinus Torvalds }
5251da177e4SLinus Torvalds 
5263998b70fSLiam Girdwood static const char* wm9711_alc_select[] = {"None", "Left", "Right", "Stereo"};
5273998b70fSLiam Girdwood static const char* wm9711_alc_mix[] = {"Stereo", "Right", "Left", "None"};
5283998b70fSLiam Girdwood static const char* wm9711_out3_src[] = {"Left", "VREF", "Left + Right", "Mono"};
5293998b70fSLiam Girdwood static const char* wm9711_out3_lrsrc[] = {"Master Mix", "Headphone Mix"};
5303998b70fSLiam Girdwood static const char* wm9711_rec_adc[] = {"Stereo", "Left", "Right", "Mute"};
5313998b70fSLiam Girdwood static const char* wm9711_base[] = {"Linear Control", "Adaptive Boost"};
5323998b70fSLiam Girdwood static const char* wm9711_rec_gain[] = {"+1.5dB Steps", "+0.75dB Steps"};
5333998b70fSLiam Girdwood static const char* wm9711_mic[] = {"Mic 1", "Differential", "Mic 2", "Stereo"};
5343998b70fSLiam Girdwood static const char* wm9711_rec_sel[] =
5353998b70fSLiam Girdwood 	{"Mic 1", "NC", "NC", "Master Mix", "Line", "Headphone Mix", "Phone Mix", "Phone"};
5363998b70fSLiam Girdwood static const char* wm9711_ng_type[] = {"Constant Gain", "Mute"};
5373998b70fSLiam Girdwood 
5383998b70fSLiam Girdwood static const struct ac97_enum wm9711_enum[] = {
5393998b70fSLiam Girdwood AC97_ENUM_SINGLE(AC97_PCI_SVID, 14, 4, wm9711_alc_select),
5403998b70fSLiam Girdwood AC97_ENUM_SINGLE(AC97_VIDEO, 10, 4, wm9711_alc_mix),
5413998b70fSLiam Girdwood AC97_ENUM_SINGLE(AC97_AUX, 9, 4, wm9711_out3_src),
5423998b70fSLiam Girdwood AC97_ENUM_SINGLE(AC97_AUX, 8, 2, wm9711_out3_lrsrc),
5433998b70fSLiam Girdwood AC97_ENUM_SINGLE(AC97_REC_SEL, 12, 4, wm9711_rec_adc),
5443998b70fSLiam Girdwood AC97_ENUM_SINGLE(AC97_MASTER_TONE, 15, 2, wm9711_base),
5453998b70fSLiam Girdwood AC97_ENUM_DOUBLE(AC97_REC_GAIN, 14, 6, 2, wm9711_rec_gain),
5463998b70fSLiam Girdwood AC97_ENUM_SINGLE(AC97_MIC, 5, 4, wm9711_mic),
5473998b70fSLiam Girdwood AC97_ENUM_DOUBLE(AC97_REC_SEL, 8, 0, 8, wm9711_rec_sel),
5483998b70fSLiam Girdwood AC97_ENUM_SINGLE(AC97_PCI_SVID, 5, 2, wm9711_ng_type),
5493998b70fSLiam Girdwood };
5503998b70fSLiam Girdwood 
551ee42381eSTakashi Iwai static const struct snd_kcontrol_new wm9711_snd_ac97_controls[] = {
5523998b70fSLiam Girdwood AC97_SINGLE("ALC Target Volume", AC97_CODEC_CLASS_REV, 12, 15, 0),
5533998b70fSLiam Girdwood AC97_SINGLE("ALC Hold Time", AC97_CODEC_CLASS_REV, 8, 15, 0),
5543998b70fSLiam Girdwood AC97_SINGLE("ALC Decay Time", AC97_CODEC_CLASS_REV, 4, 15, 0),
5553998b70fSLiam Girdwood AC97_SINGLE("ALC Attack Time", AC97_CODEC_CLASS_REV, 0, 15, 0),
5563998b70fSLiam Girdwood AC97_ENUM("ALC Function", wm9711_enum[0]),
5573998b70fSLiam Girdwood AC97_SINGLE("ALC Max Volume", AC97_PCI_SVID, 11, 7, 1),
5583998b70fSLiam Girdwood AC97_SINGLE("ALC ZC Timeout", AC97_PCI_SVID, 9, 3, 1),
5593998b70fSLiam Girdwood AC97_SINGLE("ALC ZC Switch", AC97_PCI_SVID, 8, 1, 0),
5603998b70fSLiam Girdwood AC97_SINGLE("ALC NG Switch", AC97_PCI_SVID, 7, 1, 0),
5613998b70fSLiam Girdwood AC97_ENUM("ALC NG Type", wm9711_enum[9]),
5623998b70fSLiam Girdwood AC97_SINGLE("ALC NG Threshold", AC97_PCI_SVID, 0, 31, 1),
5633998b70fSLiam Girdwood 
5643998b70fSLiam Girdwood AC97_SINGLE("Side Tone Switch", AC97_VIDEO, 15, 1, 1),
5653998b70fSLiam Girdwood AC97_SINGLE("Side Tone Volume", AC97_VIDEO, 12, 7, 1),
5663998b70fSLiam Girdwood AC97_ENUM("ALC Headphone Mux", wm9711_enum[1]),
5673998b70fSLiam Girdwood AC97_SINGLE("ALC Headphone Volume", AC97_VIDEO, 7, 7, 1),
5683998b70fSLiam Girdwood 
5693998b70fSLiam Girdwood AC97_SINGLE("Out3 Switch", AC97_AUX, 15, 1, 1),
5702aedbda6SLuke Zhang AC97_SINGLE("Out3 ZC Switch", AC97_AUX, 7, 1, 0),
5713998b70fSLiam Girdwood AC97_ENUM("Out3 Mux", wm9711_enum[2]),
5723998b70fSLiam Girdwood AC97_ENUM("Out3 LR Mux", wm9711_enum[3]),
5733998b70fSLiam Girdwood AC97_SINGLE("Out3 Volume", AC97_AUX, 0, 31, 1),
5743998b70fSLiam Girdwood 
5753998b70fSLiam Girdwood AC97_SINGLE("Beep to Headphone Switch", AC97_PC_BEEP, 15, 1, 1),
5763998b70fSLiam Girdwood AC97_SINGLE("Beep to Headphone Volume", AC97_PC_BEEP, 12, 7, 1),
5773998b70fSLiam Girdwood AC97_SINGLE("Beep to Side Tone Switch", AC97_PC_BEEP, 11, 1, 1),
5783998b70fSLiam Girdwood AC97_SINGLE("Beep to Side Tone Volume", AC97_PC_BEEP, 8, 7, 1),
5793998b70fSLiam Girdwood AC97_SINGLE("Beep to Phone Switch", AC97_PC_BEEP, 7, 1, 1),
5803998b70fSLiam Girdwood AC97_SINGLE("Beep to Phone Volume", AC97_PC_BEEP, 4, 7, 1),
5813998b70fSLiam Girdwood 
5823998b70fSLiam Girdwood AC97_SINGLE("Aux to Headphone Switch", AC97_CD, 15, 1, 1),
5833998b70fSLiam Girdwood AC97_SINGLE("Aux to Headphone Volume", AC97_CD, 12, 7, 1),
5843998b70fSLiam Girdwood AC97_SINGLE("Aux to Side Tone Switch", AC97_CD, 11, 1, 1),
5853998b70fSLiam Girdwood AC97_SINGLE("Aux to Side Tone Volume", AC97_CD, 8, 7, 1),
5863998b70fSLiam Girdwood AC97_SINGLE("Aux to Phone Switch", AC97_CD, 7, 1, 1),
5873998b70fSLiam Girdwood AC97_SINGLE("Aux to Phone Volume", AC97_CD, 4, 7, 1),
5883998b70fSLiam Girdwood 
5893998b70fSLiam Girdwood AC97_SINGLE("Phone to Headphone Switch", AC97_PHONE, 15, 1, 1),
5903998b70fSLiam Girdwood AC97_SINGLE("Phone to Master Switch", AC97_PHONE, 14, 1, 1),
5913998b70fSLiam Girdwood 
5923998b70fSLiam Girdwood AC97_SINGLE("Line to Headphone Switch", AC97_LINE, 15, 1, 1),
5933998b70fSLiam Girdwood AC97_SINGLE("Line to Master Switch", AC97_LINE, 14, 1, 1),
5943998b70fSLiam Girdwood AC97_SINGLE("Line to Phone Switch", AC97_LINE, 13, 1, 1),
5953998b70fSLiam Girdwood 
5963998b70fSLiam Girdwood AC97_SINGLE("PCM Playback to Headphone Switch", AC97_PCM, 15, 1, 1),
5973998b70fSLiam Girdwood AC97_SINGLE("PCM Playback to Master Switch", AC97_PCM, 14, 1, 1),
5983998b70fSLiam Girdwood AC97_SINGLE("PCM Playback to Phone Switch", AC97_PCM, 13, 1, 1),
5993998b70fSLiam Girdwood 
6003998b70fSLiam Girdwood AC97_SINGLE("Capture 20dB Boost Switch", AC97_REC_SEL, 14, 1, 0),
6013998b70fSLiam Girdwood AC97_ENUM("Capture to Phone Mux", wm9711_enum[4]),
6023998b70fSLiam Girdwood AC97_SINGLE("Capture to Phone 20dB Boost Switch", AC97_REC_SEL, 11, 1, 1),
6033998b70fSLiam Girdwood AC97_ENUM("Capture Select", wm9711_enum[8]),
6043998b70fSLiam Girdwood 
6053998b70fSLiam Girdwood AC97_SINGLE("3D Upper Cut-off Switch", AC97_3D_CONTROL, 5, 1, 1),
6063998b70fSLiam Girdwood AC97_SINGLE("3D Lower Cut-off Switch", AC97_3D_CONTROL, 4, 1, 1),
6073998b70fSLiam Girdwood 
6083998b70fSLiam Girdwood AC97_ENUM("Bass Control", wm9711_enum[5]),
6093998b70fSLiam Girdwood AC97_SINGLE("Bass Cut-off Switch", AC97_MASTER_TONE, 12, 1, 1),
6103998b70fSLiam Girdwood AC97_SINGLE("Tone Cut-off Switch", AC97_MASTER_TONE, 4, 1, 1),
6113998b70fSLiam Girdwood AC97_SINGLE("Playback Attenuate (-6dB) Switch", AC97_MASTER_TONE, 6, 1, 0),
6123998b70fSLiam Girdwood 
6133998b70fSLiam Girdwood AC97_SINGLE("ADC Switch", AC97_REC_GAIN, 15, 1, 1),
6143998b70fSLiam Girdwood AC97_ENUM("Capture Volume Steps", wm9711_enum[6]),
6152aedbda6SLuke Zhang AC97_DOUBLE("Capture Volume", AC97_REC_GAIN, 8, 0, 63, 1),
6163998b70fSLiam Girdwood AC97_SINGLE("Capture ZC Switch", AC97_REC_GAIN, 7, 1, 0),
6173998b70fSLiam Girdwood 
6183998b70fSLiam Girdwood AC97_SINGLE("Mic 1 to Phone Switch", AC97_MIC, 14, 1, 1),
6193998b70fSLiam Girdwood AC97_SINGLE("Mic 2 to Phone Switch", AC97_MIC, 13, 1, 1),
6203998b70fSLiam Girdwood AC97_ENUM("Mic Select Source", wm9711_enum[7]),
6212aedbda6SLuke Zhang AC97_SINGLE("Mic 1 Volume", AC97_MIC, 8, 31, 1),
6222aedbda6SLuke Zhang AC97_SINGLE("Mic 2 Volume", AC97_MIC, 0, 31, 1),
623d7f6f115SJames Courtier-Dutton AC97_SINGLE("Mic 20dB Boost Switch", AC97_MIC, 7, 1, 0),
6243998b70fSLiam Girdwood 
6250264b3b6SJuergen Beisert AC97_SINGLE("Master Left Inv Switch", AC97_MASTER, 6, 1, 0),
6263998b70fSLiam Girdwood AC97_SINGLE("Master ZC Switch", AC97_MASTER, 7, 1, 0),
6273998b70fSLiam Girdwood AC97_SINGLE("Headphone ZC Switch", AC97_HEADPHONE, 7, 1, 0),
6283998b70fSLiam Girdwood AC97_SINGLE("Mono ZC Switch", AC97_MASTER_MONO, 7, 1, 0),
6293998b70fSLiam Girdwood };
6303998b70fSLiam Girdwood 
patch_wolfson_wm9711_specific(struct snd_ac97 * ac97)631ee42381eSTakashi Iwai static int patch_wolfson_wm9711_specific(struct snd_ac97 * ac97)
6323998b70fSLiam Girdwood {
6333998b70fSLiam Girdwood 	int err, i;
6343998b70fSLiam Girdwood 
6353998b70fSLiam Girdwood 	for (i = 0; i < ARRAY_SIZE(wm9711_snd_ac97_controls); i++) {
636e66fd362STakashi Iwai 		err = snd_ctl_add(ac97->bus->card, snd_ac97_cnew(&wm9711_snd_ac97_controls[i], ac97));
637e66fd362STakashi Iwai 		if (err < 0)
6383998b70fSLiam Girdwood 			return err;
6393998b70fSLiam Girdwood 	}
6403998b70fSLiam Girdwood 	snd_ac97_write_cache(ac97,  AC97_CODEC_CLASS_REV, 0x0808);
6413998b70fSLiam Girdwood 	snd_ac97_write_cache(ac97,  AC97_PCI_SVID, 0x0808);
6423998b70fSLiam Girdwood 	snd_ac97_write_cache(ac97,  AC97_VIDEO, 0x0808);
6433998b70fSLiam Girdwood 	snd_ac97_write_cache(ac97,  AC97_AUX, 0x0808);
6443998b70fSLiam Girdwood 	snd_ac97_write_cache(ac97,  AC97_PC_BEEP, 0x0808);
6453998b70fSLiam Girdwood 	snd_ac97_write_cache(ac97,  AC97_CD, 0x0000);
6463998b70fSLiam Girdwood 	return 0;
6473998b70fSLiam Girdwood }
6483998b70fSLiam Girdwood 
6493e8b3b90SHanno Boeck static const struct snd_ac97_build_ops patch_wolfson_wm9711_ops = {
6503998b70fSLiam Girdwood 	.build_specific = patch_wolfson_wm9711_specific,
6513998b70fSLiam Girdwood };
6523998b70fSLiam Girdwood 
patch_wolfson11(struct snd_ac97 * ac97)653ac519028STakashi Iwai static int patch_wolfson11(struct snd_ac97 * ac97)
6541da177e4SLinus Torvalds {
6553998b70fSLiam Girdwood 	/* WM9711, WM9712 */
6563998b70fSLiam Girdwood 	ac97->build_ops = &patch_wolfson_wm9711_ops;
6573998b70fSLiam Girdwood 
6583998b70fSLiam Girdwood 	ac97->flags |= AC97_HAS_NO_REC_GAIN | AC97_STEREO_MUTES | AC97_HAS_NO_MIC |
6593998b70fSLiam Girdwood 		AC97_HAS_NO_PC_BEEP | AC97_HAS_NO_VIDEO | AC97_HAS_NO_CD;
6603998b70fSLiam Girdwood 
6611da177e4SLinus Torvalds 	return 0;
6621da177e4SLinus Torvalds }
6631da177e4SLinus Torvalds 
6641da177e4SLinus Torvalds static const char* wm9713_mic_mixer[] = {"Stereo", "Mic 1", "Mic 2", "Mute"};
6651da177e4SLinus Torvalds static const char* wm9713_rec_mux[] = {"Stereo", "Left", "Right", "Mute"};
6663998b70fSLiam Girdwood static const char* wm9713_rec_src[] =
6673998b70fSLiam Girdwood 	{"Mic 1", "Mic 2", "Line", "Mono In", "Headphone Mix", "Master Mix",
6683998b70fSLiam Girdwood 	"Mono Mix", "Zh"};
6693998b70fSLiam Girdwood static const char* wm9713_rec_gain[] = {"+1.5dB Steps", "+0.75dB Steps"};
6703998b70fSLiam Girdwood static const char* wm9713_alc_select[] = {"None", "Left", "Right", "Stereo"};
6713998b70fSLiam Girdwood static const char* wm9713_mono_pga[] = {"Vmid", "Zh", "Mono Mix", "Inv 1"};
6723998b70fSLiam Girdwood static const char* wm9713_spk_pga[] =
6733998b70fSLiam Girdwood 	{"Vmid", "Zh", "Headphone Mix", "Master Mix", "Inv", "NC", "NC", "NC"};
6743998b70fSLiam Girdwood static const char* wm9713_hp_pga[] = {"Vmid", "Zh", "Headphone Mix", "NC"};
6753998b70fSLiam Girdwood static const char* wm9713_out3_pga[] = {"Vmid", "Zh", "Inv 1", "NC"};
6763998b70fSLiam Girdwood static const char* wm9713_out4_pga[] = {"Vmid", "Zh", "Inv 2", "NC"};
6773998b70fSLiam Girdwood static const char* wm9713_dac_inv[] =
6783998b70fSLiam Girdwood 	{"Off", "Mono Mix", "Master Mix", "Headphone Mix L", "Headphone Mix R",
6793998b70fSLiam Girdwood 	"Headphone Mix Mono", "NC", "Vmid"};
6803998b70fSLiam Girdwood static const char* wm9713_base[] = {"Linear Control", "Adaptive Boost"};
6813998b70fSLiam Girdwood static const char* wm9713_ng_type[] = {"Constant Gain", "Mute"};
6821da177e4SLinus Torvalds 
6831da177e4SLinus Torvalds static const struct ac97_enum wm9713_enum[] = {
6841da177e4SLinus Torvalds AC97_ENUM_SINGLE(AC97_LINE, 3, 4, wm9713_mic_mixer),
6851da177e4SLinus Torvalds AC97_ENUM_SINGLE(AC97_VIDEO, 14, 4, wm9713_rec_mux),
6861da177e4SLinus Torvalds AC97_ENUM_SINGLE(AC97_VIDEO, 9, 4, wm9713_rec_mux),
6873998b70fSLiam Girdwood AC97_ENUM_DOUBLE(AC97_VIDEO, 3, 0, 8, wm9713_rec_src),
6883998b70fSLiam Girdwood AC97_ENUM_DOUBLE(AC97_CD, 14, 6, 2, wm9713_rec_gain),
6893998b70fSLiam Girdwood AC97_ENUM_SINGLE(AC97_PCI_SVID, 14, 4, wm9713_alc_select),
6903998b70fSLiam Girdwood AC97_ENUM_SINGLE(AC97_REC_GAIN, 14, 4, wm9713_mono_pga),
6913998b70fSLiam Girdwood AC97_ENUM_DOUBLE(AC97_REC_GAIN, 11, 8, 8, wm9713_spk_pga),
6923998b70fSLiam Girdwood AC97_ENUM_DOUBLE(AC97_REC_GAIN, 6, 4, 4, wm9713_hp_pga),
6933998b70fSLiam Girdwood AC97_ENUM_SINGLE(AC97_REC_GAIN, 2, 4, wm9713_out3_pga),
6943998b70fSLiam Girdwood AC97_ENUM_SINGLE(AC97_REC_GAIN, 0, 4, wm9713_out4_pga),
6953998b70fSLiam Girdwood AC97_ENUM_DOUBLE(AC97_REC_GAIN_MIC, 13, 10, 8, wm9713_dac_inv),
6963998b70fSLiam Girdwood AC97_ENUM_SINGLE(AC97_GENERAL_PURPOSE, 15, 2, wm9713_base),
6973998b70fSLiam Girdwood AC97_ENUM_SINGLE(AC97_PCI_SVID, 5, 2, wm9713_ng_type),
6981da177e4SLinus Torvalds };
6991da177e4SLinus Torvalds 
700ee42381eSTakashi Iwai static const struct snd_kcontrol_new wm13_snd_ac97_controls[] = {
7011da177e4SLinus Torvalds AC97_DOUBLE("Line In Volume", AC97_PC_BEEP, 8, 0, 31, 1),
7023998b70fSLiam Girdwood AC97_SINGLE("Line In to Headphone Switch", AC97_PC_BEEP, 15, 1, 1),
7033998b70fSLiam Girdwood AC97_SINGLE("Line In to Master Switch", AC97_PC_BEEP, 14, 1, 1),
7043998b70fSLiam Girdwood AC97_SINGLE("Line In to Mono Switch", AC97_PC_BEEP, 13, 1, 1),
7053998b70fSLiam Girdwood 
7063998b70fSLiam Girdwood AC97_DOUBLE("PCM Playback Volume", AC97_PHONE, 8, 0, 31, 1),
7073998b70fSLiam Girdwood AC97_SINGLE("PCM Playback to Headphone Switch", AC97_PHONE, 15, 1, 1),
7083998b70fSLiam Girdwood AC97_SINGLE("PCM Playback to Master Switch", AC97_PHONE, 14, 1, 1),
7093998b70fSLiam Girdwood AC97_SINGLE("PCM Playback to Mono Switch", AC97_PHONE, 13, 1, 1),
7103998b70fSLiam Girdwood 
7113998b70fSLiam Girdwood AC97_SINGLE("Mic 1 Volume", AC97_MIC, 8, 31, 1),
7123998b70fSLiam Girdwood AC97_SINGLE("Mic 2 Volume", AC97_MIC, 0, 31, 1),
7133998b70fSLiam Girdwood AC97_SINGLE("Mic 1 to Mono Switch", AC97_LINE, 7, 1, 1),
7143998b70fSLiam Girdwood AC97_SINGLE("Mic 2 to Mono Switch", AC97_LINE, 6, 1, 1),
715d7f6f115SJames Courtier-Dutton AC97_SINGLE("Mic Boost (+20dB) Switch", AC97_LINE, 5, 1, 0),
7163998b70fSLiam Girdwood AC97_ENUM("Mic to Headphone Mux", wm9713_enum[0]),
7173998b70fSLiam Girdwood AC97_SINGLE("Mic Headphone Mixer Volume", AC97_LINE, 0, 7, 1),
7183998b70fSLiam Girdwood 
7193998b70fSLiam Girdwood AC97_SINGLE("Capture Switch", AC97_CD, 15, 1, 1),
7203998b70fSLiam Girdwood AC97_ENUM("Capture Volume Steps", wm9713_enum[4]),
7213998b70fSLiam Girdwood AC97_DOUBLE("Capture Volume", AC97_CD, 8, 0, 15, 0),
7223998b70fSLiam Girdwood AC97_SINGLE("Capture ZC Switch", AC97_CD, 7, 1, 0),
7233998b70fSLiam Girdwood 
7243998b70fSLiam Girdwood AC97_ENUM("Capture to Headphone Mux", wm9713_enum[1]),
7253998b70fSLiam Girdwood AC97_SINGLE("Capture to Headphone Volume", AC97_VIDEO, 11, 7, 1),
7263998b70fSLiam Girdwood AC97_ENUM("Capture to Mono Mux", wm9713_enum[2]),
7273998b70fSLiam Girdwood AC97_SINGLE("Capture to Mono Boost (+20dB) Switch", AC97_VIDEO, 8, 1, 0),
7283998b70fSLiam Girdwood AC97_SINGLE("Capture ADC Boost (+20dB) Switch", AC97_VIDEO, 6, 1, 0),
7293998b70fSLiam Girdwood AC97_ENUM("Capture Select", wm9713_enum[3]),
7303998b70fSLiam Girdwood 
7313998b70fSLiam Girdwood AC97_SINGLE("ALC Target Volume", AC97_CODEC_CLASS_REV, 12, 15, 0),
7323998b70fSLiam Girdwood AC97_SINGLE("ALC Hold Time", AC97_CODEC_CLASS_REV, 8, 15, 0),
7333998b70fSLiam Girdwood AC97_SINGLE("ALC Decay Time ", AC97_CODEC_CLASS_REV, 4, 15, 0),
7343998b70fSLiam Girdwood AC97_SINGLE("ALC Attack Time", AC97_CODEC_CLASS_REV, 0, 15, 0),
7353998b70fSLiam Girdwood AC97_ENUM("ALC Function", wm9713_enum[5]),
7363998b70fSLiam Girdwood AC97_SINGLE("ALC Max Volume", AC97_PCI_SVID, 11, 7, 0),
7373998b70fSLiam Girdwood AC97_SINGLE("ALC ZC Timeout", AC97_PCI_SVID, 9, 3, 0),
7383998b70fSLiam Girdwood AC97_SINGLE("ALC ZC Switch", AC97_PCI_SVID, 8, 1, 0),
7393998b70fSLiam Girdwood AC97_SINGLE("ALC NG Switch", AC97_PCI_SVID, 7, 1, 0),
7403998b70fSLiam Girdwood AC97_ENUM("ALC NG Type", wm9713_enum[13]),
7413998b70fSLiam Girdwood AC97_SINGLE("ALC NG Threshold", AC97_PCI_SVID, 0, 31, 0),
7423998b70fSLiam Girdwood 
7433998b70fSLiam Girdwood AC97_DOUBLE("Master ZC Switch", AC97_MASTER, 14, 6, 1, 0),
7443998b70fSLiam Girdwood AC97_DOUBLE("Headphone ZC Switch", AC97_HEADPHONE, 14, 6, 1, 0),
7453998b70fSLiam Girdwood AC97_DOUBLE("Out3/4 ZC Switch", AC97_MASTER_MONO, 14, 6, 1, 0),
7463998b70fSLiam Girdwood AC97_SINGLE("Master Right Switch", AC97_MASTER, 7, 1, 1),
7473998b70fSLiam Girdwood AC97_SINGLE("Headphone Right Switch", AC97_HEADPHONE, 7, 1, 1),
7483998b70fSLiam Girdwood AC97_SINGLE("Out3/4 Right Switch", AC97_MASTER_MONO, 7, 1, 1),
7493998b70fSLiam Girdwood 
7503998b70fSLiam Girdwood AC97_SINGLE("Mono In to Headphone Switch", AC97_MASTER_TONE, 15, 1, 1),
7513998b70fSLiam Girdwood AC97_SINGLE("Mono In to Master Switch", AC97_MASTER_TONE, 14, 1, 1),
7523998b70fSLiam Girdwood AC97_SINGLE("Mono In Volume", AC97_MASTER_TONE, 8, 31, 1),
7533998b70fSLiam Girdwood AC97_SINGLE("Mono Switch", AC97_MASTER_TONE, 7, 1, 1),
7543998b70fSLiam Girdwood AC97_SINGLE("Mono ZC Switch", AC97_MASTER_TONE, 6, 1, 0),
7553998b70fSLiam Girdwood AC97_SINGLE("Mono Volume", AC97_MASTER_TONE, 0, 31, 1),
7563998b70fSLiam Girdwood 
757d355c82aSJaroslav Kysela AC97_SINGLE("Beep to Headphone Switch", AC97_AUX, 15, 1, 1),
758d355c82aSJaroslav Kysela AC97_SINGLE("Beep to Headphone Volume", AC97_AUX, 12, 7, 1),
759d355c82aSJaroslav Kysela AC97_SINGLE("Beep to Master Switch", AC97_AUX, 11, 1, 1),
760d355c82aSJaroslav Kysela AC97_SINGLE("Beep to Master Volume", AC97_AUX, 8, 7, 1),
761d355c82aSJaroslav Kysela AC97_SINGLE("Beep to Mono Switch", AC97_AUX, 7, 1, 1),
762d355c82aSJaroslav Kysela AC97_SINGLE("Beep to Mono Volume", AC97_AUX, 4, 7, 1),
7633998b70fSLiam Girdwood 
7643998b70fSLiam Girdwood AC97_SINGLE("Voice to Headphone Switch", AC97_PCM, 15, 1, 1),
7653998b70fSLiam Girdwood AC97_SINGLE("Voice to Headphone Volume", AC97_PCM, 12, 7, 1),
7663998b70fSLiam Girdwood AC97_SINGLE("Voice to Master Switch", AC97_PCM, 11, 1, 1),
7673998b70fSLiam Girdwood AC97_SINGLE("Voice to Master Volume", AC97_PCM, 8, 7, 1),
7683998b70fSLiam Girdwood AC97_SINGLE("Voice to Mono Switch", AC97_PCM, 7, 1, 1),
7693998b70fSLiam Girdwood AC97_SINGLE("Voice to Mono Volume", AC97_PCM, 4, 7, 1),
7703998b70fSLiam Girdwood 
7713998b70fSLiam Girdwood AC97_SINGLE("Aux to Headphone Switch", AC97_REC_SEL, 15, 1, 1),
7723998b70fSLiam Girdwood AC97_SINGLE("Aux to Headphone Volume", AC97_REC_SEL, 12, 7, 1),
7733998b70fSLiam Girdwood AC97_SINGLE("Aux to Master Switch", AC97_REC_SEL, 11, 1, 1),
7743998b70fSLiam Girdwood AC97_SINGLE("Aux to Master Volume", AC97_REC_SEL, 8, 7, 1),
7753998b70fSLiam Girdwood AC97_SINGLE("Aux to Mono Switch", AC97_REC_SEL, 7, 1, 1),
7763998b70fSLiam Girdwood AC97_SINGLE("Aux to Mono Volume", AC97_REC_SEL, 4, 7, 1),
7773998b70fSLiam Girdwood 
7783998b70fSLiam Girdwood AC97_ENUM("Mono Input Mux", wm9713_enum[6]),
7793998b70fSLiam Girdwood AC97_ENUM("Master Input Mux", wm9713_enum[7]),
7803998b70fSLiam Girdwood AC97_ENUM("Headphone Input Mux", wm9713_enum[8]),
7813998b70fSLiam Girdwood AC97_ENUM("Out 3 Input Mux", wm9713_enum[9]),
7823998b70fSLiam Girdwood AC97_ENUM("Out 4 Input Mux", wm9713_enum[10]),
7833998b70fSLiam Girdwood 
7843998b70fSLiam Girdwood AC97_ENUM("Bass Control", wm9713_enum[12]),
7853998b70fSLiam Girdwood AC97_SINGLE("Bass Cut-off Switch", AC97_GENERAL_PURPOSE, 12, 1, 1),
7863998b70fSLiam Girdwood AC97_SINGLE("Tone Cut-off Switch", AC97_GENERAL_PURPOSE, 4, 1, 1),
7873998b70fSLiam Girdwood AC97_SINGLE("Playback Attenuate (-6dB) Switch", AC97_GENERAL_PURPOSE, 6, 1, 0),
7883998b70fSLiam Girdwood AC97_SINGLE("Bass Volume", AC97_GENERAL_PURPOSE, 8, 15, 1),
7893998b70fSLiam Girdwood AC97_SINGLE("Tone Volume", AC97_GENERAL_PURPOSE, 0, 15, 1),
7901da177e4SLinus Torvalds };
7911da177e4SLinus Torvalds 
792ee42381eSTakashi Iwai static const struct snd_kcontrol_new wm13_snd_ac97_controls_3d[] = {
7933998b70fSLiam Girdwood AC97_ENUM("Inv Input Mux", wm9713_enum[11]),
7943998b70fSLiam Girdwood AC97_SINGLE("3D Upper Cut-off Switch", AC97_REC_GAIN_MIC, 5, 1, 0),
7953998b70fSLiam Girdwood AC97_SINGLE("3D Lower Cut-off Switch", AC97_REC_GAIN_MIC, 4, 1, 0),
7963998b70fSLiam Girdwood AC97_SINGLE("3D Depth", AC97_REC_GAIN_MIC, 0, 15, 1),
7971da177e4SLinus Torvalds };
7981da177e4SLinus Torvalds 
patch_wolfson_wm9713_3d(struct snd_ac97 * ac97)799ee42381eSTakashi Iwai static int patch_wolfson_wm9713_3d (struct snd_ac97 * ac97)
8003998b70fSLiam Girdwood {
8013998b70fSLiam Girdwood 	int err, i;
8021da177e4SLinus Torvalds 
8033998b70fSLiam Girdwood 	for (i = 0; i < ARRAY_SIZE(wm13_snd_ac97_controls_3d); i++) {
804e66fd362STakashi Iwai 		err = snd_ctl_add(ac97->bus->card, snd_ac97_cnew(&wm13_snd_ac97_controls_3d[i], ac97));
805e66fd362STakashi Iwai 		if (err < 0)
8063998b70fSLiam Girdwood 			return err;
8073998b70fSLiam Girdwood 	}
8083998b70fSLiam Girdwood 	return 0;
8093998b70fSLiam Girdwood }
8101da177e4SLinus Torvalds 
patch_wolfson_wm9713_specific(struct snd_ac97 * ac97)811ee42381eSTakashi Iwai static int patch_wolfson_wm9713_specific(struct snd_ac97 * ac97)
8121da177e4SLinus Torvalds {
8131da177e4SLinus Torvalds 	int err, i;
8141da177e4SLinus Torvalds 
8153998b70fSLiam Girdwood 	for (i = 0; i < ARRAY_SIZE(wm13_snd_ac97_controls); i++) {
816e66fd362STakashi Iwai 		err = snd_ctl_add(ac97->bus->card, snd_ac97_cnew(&wm13_snd_ac97_controls[i], ac97));
817e66fd362STakashi Iwai 		if (err < 0)
8181da177e4SLinus Torvalds 			return err;
8191da177e4SLinus Torvalds 	}
8201da177e4SLinus Torvalds 	snd_ac97_write_cache(ac97, AC97_PC_BEEP, 0x0808);
8211da177e4SLinus Torvalds 	snd_ac97_write_cache(ac97, AC97_PHONE, 0x0808);
8221da177e4SLinus Torvalds 	snd_ac97_write_cache(ac97, AC97_MIC, 0x0808);
8231da177e4SLinus Torvalds 	snd_ac97_write_cache(ac97, AC97_LINE, 0x00da);
8241da177e4SLinus Torvalds 	snd_ac97_write_cache(ac97, AC97_CD, 0x0808);
8251da177e4SLinus Torvalds 	snd_ac97_write_cache(ac97, AC97_VIDEO, 0xd612);
8261da177e4SLinus Torvalds 	snd_ac97_write_cache(ac97, AC97_REC_GAIN, 0x1ba0);
8271da177e4SLinus Torvalds 	return 0;
8281da177e4SLinus Torvalds }
8291da177e4SLinus Torvalds 
8301da177e4SLinus Torvalds #ifdef CONFIG_PM
patch_wolfson_wm9713_suspend(struct snd_ac97 * ac97)831ee42381eSTakashi Iwai static void patch_wolfson_wm9713_suspend (struct snd_ac97 * ac97)
8321da177e4SLinus Torvalds {
8331da177e4SLinus Torvalds 	snd_ac97_write_cache(ac97, AC97_EXTENDED_MID, 0xfeff);
8341da177e4SLinus Torvalds 	snd_ac97_write_cache(ac97, AC97_EXTENDED_MSTATUS, 0xffff);
8351da177e4SLinus Torvalds }
8361da177e4SLinus Torvalds 
patch_wolfson_wm9713_resume(struct snd_ac97 * ac97)837ee42381eSTakashi Iwai static void patch_wolfson_wm9713_resume (struct snd_ac97 * ac97)
8381da177e4SLinus Torvalds {
8391da177e4SLinus Torvalds 	snd_ac97_write_cache(ac97, AC97_EXTENDED_MID, 0xda00);
8401da177e4SLinus Torvalds 	snd_ac97_write_cache(ac97, AC97_EXTENDED_MSTATUS, 0x3810);
8411da177e4SLinus Torvalds 	snd_ac97_write_cache(ac97, AC97_POWERDOWN, 0x0);
8421da177e4SLinus Torvalds }
8431da177e4SLinus Torvalds #endif
8441da177e4SLinus Torvalds 
8453e8b3b90SHanno Boeck static const struct snd_ac97_build_ops patch_wolfson_wm9713_ops = {
8461da177e4SLinus Torvalds 	.build_specific = patch_wolfson_wm9713_specific,
8473998b70fSLiam Girdwood 	.build_3d = patch_wolfson_wm9713_3d,
8481da177e4SLinus Torvalds #ifdef CONFIG_PM
8491da177e4SLinus Torvalds 	.suspend = patch_wolfson_wm9713_suspend,
8501da177e4SLinus Torvalds 	.resume = patch_wolfson_wm9713_resume
8511da177e4SLinus Torvalds #endif
8521da177e4SLinus Torvalds };
8531da177e4SLinus Torvalds 
patch_wolfson13(struct snd_ac97 * ac97)854ac519028STakashi Iwai static int patch_wolfson13(struct snd_ac97 * ac97)
8551da177e4SLinus Torvalds {
8563998b70fSLiam Girdwood 	/* WM9713, WM9714 */
8571da177e4SLinus Torvalds 	ac97->build_ops = &patch_wolfson_wm9713_ops;
8581da177e4SLinus Torvalds 
8591da177e4SLinus Torvalds 	ac97->flags |= AC97_HAS_NO_REC_GAIN | AC97_STEREO_MUTES | AC97_HAS_NO_PHONE |
8603998b70fSLiam Girdwood 		AC97_HAS_NO_PC_BEEP | AC97_HAS_NO_VIDEO | AC97_HAS_NO_CD | AC97_HAS_NO_TONE |
8613998b70fSLiam Girdwood 		AC97_HAS_NO_STD_PCM;
862064d2112SLiam Girdwood     	ac97->scaps &= ~AC97_SCAP_MODEM;
8631da177e4SLinus Torvalds 
8641da177e4SLinus Torvalds 	snd_ac97_write_cache(ac97, AC97_EXTENDED_MID, 0xda00);
8651da177e4SLinus Torvalds 	snd_ac97_write_cache(ac97, AC97_EXTENDED_MSTATUS, 0x3810);
8661da177e4SLinus Torvalds 	snd_ac97_write_cache(ac97, AC97_POWERDOWN, 0x0);
8671da177e4SLinus Torvalds 
8681da177e4SLinus Torvalds 	return 0;
8691da177e4SLinus Torvalds }
8701da177e4SLinus Torvalds 
8711da177e4SLinus Torvalds /*
8721da177e4SLinus Torvalds  * Tritech codec
8731da177e4SLinus Torvalds  */
patch_tritech_tr28028(struct snd_ac97 * ac97)874ac519028STakashi Iwai static int patch_tritech_tr28028(struct snd_ac97 * ac97)
8751da177e4SLinus Torvalds {
8761da177e4SLinus Torvalds 	snd_ac97_write_cache(ac97, 0x26, 0x0300);
8771da177e4SLinus Torvalds 	snd_ac97_write_cache(ac97, 0x26, 0x0000);
8781da177e4SLinus Torvalds 	snd_ac97_write_cache(ac97, AC97_SURROUND_MASTER, 0x0000);
8791da177e4SLinus Torvalds 	snd_ac97_write_cache(ac97, AC97_SPDIF, 0x0000);
8801da177e4SLinus Torvalds 	return 0;
8811da177e4SLinus Torvalds }
8821da177e4SLinus Torvalds 
8831da177e4SLinus Torvalds /*
8841da177e4SLinus Torvalds  * Sigmatel STAC97xx codecs
8851da177e4SLinus Torvalds  */
patch_sigmatel_stac9700_3d(struct snd_ac97 * ac97)886ee42381eSTakashi Iwai static int patch_sigmatel_stac9700_3d(struct snd_ac97 * ac97)
8871da177e4SLinus Torvalds {
888ee42381eSTakashi Iwai 	struct snd_kcontrol *kctl;
8891da177e4SLinus Torvalds 	int err;
8901da177e4SLinus Torvalds 
891e66fd362STakashi Iwai 	err = snd_ctl_add(ac97->bus->card, kctl = snd_ac97_cnew(&snd_ac97_controls_3d[0], ac97));
892e66fd362STakashi Iwai 	if (err < 0)
8931da177e4SLinus Torvalds 		return err;
8941da177e4SLinus Torvalds 	strcpy(kctl->id.name, "3D Control Sigmatel - Depth");
8951da177e4SLinus Torvalds 	kctl->private_value = AC97_SINGLE_VALUE(AC97_3D_CONTROL, 2, 3, 0);
8961da177e4SLinus Torvalds 	snd_ac97_write_cache(ac97, AC97_3D_CONTROL, 0x0000);
8971da177e4SLinus Torvalds 	return 0;
8981da177e4SLinus Torvalds }
8991da177e4SLinus Torvalds 
patch_sigmatel_stac9708_3d(struct snd_ac97 * ac97)900ee42381eSTakashi Iwai static int patch_sigmatel_stac9708_3d(struct snd_ac97 * ac97)
9011da177e4SLinus Torvalds {
902ee42381eSTakashi Iwai 	struct snd_kcontrol *kctl;
9031da177e4SLinus Torvalds 	int err;
9041da177e4SLinus Torvalds 
905e66fd362STakashi Iwai 	kctl = snd_ac97_cnew(&snd_ac97_controls_3d[0], ac97);
906e66fd362STakashi Iwai 	err = snd_ctl_add(ac97->bus->card, kctl);
907e66fd362STakashi Iwai 	if (err < 0)
9081da177e4SLinus Torvalds 		return err;
9091da177e4SLinus Torvalds 	strcpy(kctl->id.name, "3D Control Sigmatel - Depth");
9101da177e4SLinus Torvalds 	kctl->private_value = AC97_SINGLE_VALUE(AC97_3D_CONTROL, 0, 3, 0);
911e66fd362STakashi Iwai 	kctl = snd_ac97_cnew(&snd_ac97_controls_3d[0], ac97);
912e66fd362STakashi Iwai 	err = snd_ctl_add(ac97->bus->card, kctl);
913e66fd362STakashi Iwai 	if (err < 0)
9141da177e4SLinus Torvalds 		return err;
9151da177e4SLinus Torvalds 	strcpy(kctl->id.name, "3D Control Sigmatel - Rear Depth");
9161da177e4SLinus Torvalds 	kctl->private_value = AC97_SINGLE_VALUE(AC97_3D_CONTROL, 2, 3, 0);
9171da177e4SLinus Torvalds 	snd_ac97_write_cache(ac97, AC97_3D_CONTROL, 0x0000);
9181da177e4SLinus Torvalds 	return 0;
9191da177e4SLinus Torvalds }
9201da177e4SLinus Torvalds 
921ee42381eSTakashi Iwai static const struct snd_kcontrol_new snd_ac97_sigmatel_4speaker =
922afe6d7e3SAndreas Mohr AC97_SINGLE("Sigmatel 4-Speaker Stereo Playback Switch",
923afe6d7e3SAndreas Mohr 		AC97_SIGMATEL_DAC2INVERT, 2, 1, 0);
9241da177e4SLinus Torvalds 
925afe6d7e3SAndreas Mohr /* "Sigmatel " removed due to excessive name length: */
926ee42381eSTakashi Iwai static const struct snd_kcontrol_new snd_ac97_sigmatel_phaseinvert =
927afe6d7e3SAndreas Mohr AC97_SINGLE("Surround Phase Inversion Playback Switch",
928afe6d7e3SAndreas Mohr 		AC97_SIGMATEL_DAC2INVERT, 3, 1, 0);
9291da177e4SLinus Torvalds 
930ee42381eSTakashi Iwai static const struct snd_kcontrol_new snd_ac97_sigmatel_controls[] = {
9311da177e4SLinus Torvalds AC97_SINGLE("Sigmatel DAC 6dB Attenuate", AC97_SIGMATEL_ANALOG, 1, 1, 0),
9321da177e4SLinus Torvalds AC97_SINGLE("Sigmatel ADC 6dB Attenuate", AC97_SIGMATEL_ANALOG, 0, 1, 0)
9331da177e4SLinus Torvalds };
9341da177e4SLinus Torvalds 
patch_sigmatel_stac97xx_specific(struct snd_ac97 * ac97)935ee42381eSTakashi Iwai static int patch_sigmatel_stac97xx_specific(struct snd_ac97 * ac97)
9361da177e4SLinus Torvalds {
9371da177e4SLinus Torvalds 	int err;
9381da177e4SLinus Torvalds 
9391da177e4SLinus Torvalds 	snd_ac97_write_cache(ac97, AC97_SIGMATEL_ANALOG, snd_ac97_read(ac97, AC97_SIGMATEL_ANALOG) & ~0x0003);
940e66fd362STakashi Iwai 	if (snd_ac97_try_bit(ac97, AC97_SIGMATEL_ANALOG, 1)) {
941e66fd362STakashi Iwai 		err = patch_build_controls(ac97, &snd_ac97_sigmatel_controls[0], 1);
942e66fd362STakashi Iwai 		if (err < 0)
9431da177e4SLinus Torvalds 			return err;
944e66fd362STakashi Iwai 	}
945e66fd362STakashi Iwai 	if (snd_ac97_try_bit(ac97, AC97_SIGMATEL_ANALOG, 0)) {
946e66fd362STakashi Iwai 		err = patch_build_controls(ac97, &snd_ac97_sigmatel_controls[1], 1);
947e66fd362STakashi Iwai 		if (err < 0)
9481da177e4SLinus Torvalds 			return err;
949e66fd362STakashi Iwai 	}
950e66fd362STakashi Iwai 	if (snd_ac97_try_bit(ac97, AC97_SIGMATEL_DAC2INVERT, 2)) {
951e66fd362STakashi Iwai 		err = patch_build_controls(ac97, &snd_ac97_sigmatel_4speaker, 1);
952e66fd362STakashi Iwai 		if (err < 0)
9531da177e4SLinus Torvalds 			return err;
954e66fd362STakashi Iwai 	}
955e66fd362STakashi Iwai 	if (snd_ac97_try_bit(ac97, AC97_SIGMATEL_DAC2INVERT, 3)) {
956e66fd362STakashi Iwai 		err = patch_build_controls(ac97, &snd_ac97_sigmatel_phaseinvert, 1);
957e66fd362STakashi Iwai 		if (err < 0)
9581da177e4SLinus Torvalds 			return err;
959e66fd362STakashi Iwai 	}
9601da177e4SLinus Torvalds 	return 0;
9611da177e4SLinus Torvalds }
9621da177e4SLinus Torvalds 
9633e8b3b90SHanno Boeck static const struct snd_ac97_build_ops patch_sigmatel_stac9700_ops = {
9641da177e4SLinus Torvalds 	.build_3d	= patch_sigmatel_stac9700_3d,
9651da177e4SLinus Torvalds 	.build_specific	= patch_sigmatel_stac97xx_specific
9661da177e4SLinus Torvalds };
9671da177e4SLinus Torvalds 
patch_sigmatel_stac9700(struct snd_ac97 * ac97)968ac519028STakashi Iwai static int patch_sigmatel_stac9700(struct snd_ac97 * ac97)
9691da177e4SLinus Torvalds {
9701da177e4SLinus Torvalds 	ac97->build_ops = &patch_sigmatel_stac9700_ops;
9711da177e4SLinus Torvalds 	return 0;
9721da177e4SLinus Torvalds }
9731da177e4SLinus Torvalds 
snd_ac97_stac9708_put_bias(struct snd_kcontrol * kcontrol,struct snd_ctl_elem_value * ucontrol)974ee42381eSTakashi Iwai static int snd_ac97_stac9708_put_bias(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
9751da177e4SLinus Torvalds {
976ee42381eSTakashi Iwai 	struct snd_ac97 *ac97 = snd_kcontrol_chip(kcontrol);
9771da177e4SLinus Torvalds 	int err;
9781da177e4SLinus Torvalds 
97962932df8SIngo Molnar 	mutex_lock(&ac97->page_mutex);
9801da177e4SLinus Torvalds 	snd_ac97_write(ac97, AC97_SIGMATEL_BIAS1, 0xabba);
9811da177e4SLinus Torvalds 	err = snd_ac97_update_bits(ac97, AC97_SIGMATEL_BIAS2, 0x0010,
9821da177e4SLinus Torvalds 				   (ucontrol->value.integer.value[0] & 1) << 4);
9831da177e4SLinus Torvalds 	snd_ac97_write(ac97, AC97_SIGMATEL_BIAS1, 0);
98462932df8SIngo Molnar 	mutex_unlock(&ac97->page_mutex);
9851da177e4SLinus Torvalds 	return err;
9861da177e4SLinus Torvalds }
9871da177e4SLinus Torvalds 
988ee42381eSTakashi Iwai static const struct snd_kcontrol_new snd_ac97_stac9708_bias_control = {
9891da177e4SLinus Torvalds 	.iface = SNDRV_CTL_ELEM_IFACE_MIXER,
9901da177e4SLinus Torvalds 	.name = "Sigmatel Output Bias Switch",
9911da177e4SLinus Torvalds 	.info = snd_ac97_info_volsw,
9921da177e4SLinus Torvalds 	.get = snd_ac97_get_volsw,
9931da177e4SLinus Torvalds 	.put = snd_ac97_stac9708_put_bias,
9941da177e4SLinus Torvalds 	.private_value = AC97_SINGLE_VALUE(AC97_SIGMATEL_BIAS2, 4, 1, 0),
9951da177e4SLinus Torvalds };
9961da177e4SLinus Torvalds 
patch_sigmatel_stac9708_specific(struct snd_ac97 * ac97)997ee42381eSTakashi Iwai static int patch_sigmatel_stac9708_specific(struct snd_ac97 *ac97)
9981da177e4SLinus Torvalds {
9991da177e4SLinus Torvalds 	int err;
10001da177e4SLinus Torvalds 
1001e4c3bf0fSJames C Georgas 	/* the register bit is writable, but the function is not implemented: */
1002e4c3bf0fSJames C Georgas 	snd_ac97_remove_ctl(ac97, "PCM Out Path & Mute", NULL);
1003e4c3bf0fSJames C Georgas 
10041da177e4SLinus Torvalds 	snd_ac97_rename_vol_ctl(ac97, "Headphone Playback", "Sigmatel Surround Playback");
1005e66fd362STakashi Iwai 	err = patch_build_controls(ac97, &snd_ac97_stac9708_bias_control, 1);
1006e66fd362STakashi Iwai 	if (err < 0)
10071da177e4SLinus Torvalds 		return err;
10081da177e4SLinus Torvalds 	return patch_sigmatel_stac97xx_specific(ac97);
10091da177e4SLinus Torvalds }
10101da177e4SLinus Torvalds 
10113e8b3b90SHanno Boeck static const struct snd_ac97_build_ops patch_sigmatel_stac9708_ops = {
10121da177e4SLinus Torvalds 	.build_3d	= patch_sigmatel_stac9708_3d,
10131da177e4SLinus Torvalds 	.build_specific	= patch_sigmatel_stac9708_specific
10141da177e4SLinus Torvalds };
10151da177e4SLinus Torvalds 
patch_sigmatel_stac9708(struct snd_ac97 * ac97)1016ac519028STakashi Iwai static int patch_sigmatel_stac9708(struct snd_ac97 * ac97)
10171da177e4SLinus Torvalds {
10181da177e4SLinus Torvalds 	unsigned int codec72, codec6c;
10191da177e4SLinus Torvalds 
10201da177e4SLinus Torvalds 	ac97->build_ops = &patch_sigmatel_stac9708_ops;
10211da177e4SLinus Torvalds 	ac97->caps |= 0x10;	/* HP (sigmatel surround) support */
10221da177e4SLinus Torvalds 
10231da177e4SLinus Torvalds 	codec72 = snd_ac97_read(ac97, AC97_SIGMATEL_BIAS2) & 0x8000;
10241da177e4SLinus Torvalds 	codec6c = snd_ac97_read(ac97, AC97_SIGMATEL_ANALOG);
10251da177e4SLinus Torvalds 
10261da177e4SLinus Torvalds 	if ((codec72==0) && (codec6c==0)) {
10271da177e4SLinus Torvalds 		snd_ac97_write_cache(ac97, AC97_SIGMATEL_CIC1, 0xabba);
10281da177e4SLinus Torvalds 		snd_ac97_write_cache(ac97, AC97_SIGMATEL_CIC2, 0x1000);
10291da177e4SLinus Torvalds 		snd_ac97_write_cache(ac97, AC97_SIGMATEL_BIAS1, 0xabba);
10301da177e4SLinus Torvalds 		snd_ac97_write_cache(ac97, AC97_SIGMATEL_BIAS2, 0x0007);
10311da177e4SLinus Torvalds 	} else if ((codec72==0x8000) && (codec6c==0)) {
10321da177e4SLinus Torvalds 		snd_ac97_write_cache(ac97, AC97_SIGMATEL_CIC1, 0xabba);
10331da177e4SLinus Torvalds 		snd_ac97_write_cache(ac97, AC97_SIGMATEL_CIC2, 0x1001);
10341da177e4SLinus Torvalds 		snd_ac97_write_cache(ac97, AC97_SIGMATEL_DAC2INVERT, 0x0008);
10351da177e4SLinus Torvalds 	} else if ((codec72==0x8000) && (codec6c==0x0080)) {
10361da177e4SLinus Torvalds 		/* nothing */
10371da177e4SLinus Torvalds 	}
10381da177e4SLinus Torvalds 	snd_ac97_write_cache(ac97, AC97_SIGMATEL_MULTICHN, 0x0000);
10391da177e4SLinus Torvalds 	return 0;
10401da177e4SLinus Torvalds }
10411da177e4SLinus Torvalds 
patch_sigmatel_stac9721(struct snd_ac97 * ac97)1042ac519028STakashi Iwai static int patch_sigmatel_stac9721(struct snd_ac97 * ac97)
10431da177e4SLinus Torvalds {
10441da177e4SLinus Torvalds 	ac97->build_ops = &patch_sigmatel_stac9700_ops;
10451da177e4SLinus Torvalds 	if (snd_ac97_read(ac97, AC97_SIGMATEL_ANALOG) == 0) {
10461da177e4SLinus Torvalds 		// patch for SigmaTel
10471da177e4SLinus Torvalds 		snd_ac97_write_cache(ac97, AC97_SIGMATEL_CIC1, 0xabba);
10481da177e4SLinus Torvalds 		snd_ac97_write_cache(ac97, AC97_SIGMATEL_CIC2, 0x4000);
10491da177e4SLinus Torvalds 		snd_ac97_write_cache(ac97, AC97_SIGMATEL_BIAS1, 0xabba);
10501da177e4SLinus Torvalds 		snd_ac97_write_cache(ac97, AC97_SIGMATEL_BIAS2, 0x0002);
10511da177e4SLinus Torvalds 	}
10521da177e4SLinus Torvalds 	snd_ac97_write_cache(ac97, AC97_SIGMATEL_MULTICHN, 0x0000);
10531da177e4SLinus Torvalds 	return 0;
10541da177e4SLinus Torvalds }
10551da177e4SLinus Torvalds 
patch_sigmatel_stac9744(struct snd_ac97 * ac97)1056ac519028STakashi Iwai static int patch_sigmatel_stac9744(struct snd_ac97 * ac97)
10571da177e4SLinus Torvalds {
10581da177e4SLinus Torvalds 	// patch for SigmaTel
10591da177e4SLinus Torvalds 	ac97->build_ops = &patch_sigmatel_stac9700_ops;
10601da177e4SLinus Torvalds 	snd_ac97_write_cache(ac97, AC97_SIGMATEL_CIC1, 0xabba);
10611da177e4SLinus Torvalds 	snd_ac97_write_cache(ac97, AC97_SIGMATEL_CIC2, 0x0000);	/* is this correct? --jk */
10621da177e4SLinus Torvalds 	snd_ac97_write_cache(ac97, AC97_SIGMATEL_BIAS1, 0xabba);
10631da177e4SLinus Torvalds 	snd_ac97_write_cache(ac97, AC97_SIGMATEL_BIAS2, 0x0002);
10641da177e4SLinus Torvalds 	snd_ac97_write_cache(ac97, AC97_SIGMATEL_MULTICHN, 0x0000);
10651da177e4SLinus Torvalds 	return 0;
10661da177e4SLinus Torvalds }
10671da177e4SLinus Torvalds 
patch_sigmatel_stac9756(struct snd_ac97 * ac97)1068ac519028STakashi Iwai static int patch_sigmatel_stac9756(struct snd_ac97 * ac97)
10691da177e4SLinus Torvalds {
10701da177e4SLinus Torvalds 	// patch for SigmaTel
10711da177e4SLinus Torvalds 	ac97->build_ops = &patch_sigmatel_stac9700_ops;
10721da177e4SLinus Torvalds 	snd_ac97_write_cache(ac97, AC97_SIGMATEL_CIC1, 0xabba);
10731da177e4SLinus Torvalds 	snd_ac97_write_cache(ac97, AC97_SIGMATEL_CIC2, 0x0000);	/* is this correct? --jk */
10741da177e4SLinus Torvalds 	snd_ac97_write_cache(ac97, AC97_SIGMATEL_BIAS1, 0xabba);
10751da177e4SLinus Torvalds 	snd_ac97_write_cache(ac97, AC97_SIGMATEL_BIAS2, 0x0002);
10761da177e4SLinus Torvalds 	snd_ac97_write_cache(ac97, AC97_SIGMATEL_MULTICHN, 0x0000);
10771da177e4SLinus Torvalds 	return 0;
10781da177e4SLinus Torvalds }
10791da177e4SLinus Torvalds 
snd_ac97_stac9758_output_jack_info(struct snd_kcontrol * kcontrol,struct snd_ctl_elem_info * uinfo)1080ee42381eSTakashi Iwai static int snd_ac97_stac9758_output_jack_info(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_info *uinfo)
10811da177e4SLinus Torvalds {
10823b7a00dcSTakashi Iwai 	static const char * const texts[5] = {
10833b7a00dcSTakashi Iwai 		"Input/Disabled", "Front Output",
10841da177e4SLinus Torvalds 		"Rear Output", "Center/LFE Output", "Mixer Output" };
10851da177e4SLinus Torvalds 
10863b7a00dcSTakashi Iwai 	return snd_ctl_enum_info(uinfo, 1, 5, texts);
10871da177e4SLinus Torvalds }
10881da177e4SLinus Torvalds 
snd_ac97_stac9758_output_jack_get(struct snd_kcontrol * kcontrol,struct snd_ctl_elem_value * ucontrol)1089ee42381eSTakashi Iwai static int snd_ac97_stac9758_output_jack_get(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
10901da177e4SLinus Torvalds {
1091ee42381eSTakashi Iwai 	struct snd_ac97 *ac97 = snd_kcontrol_chip(kcontrol);
10921da177e4SLinus Torvalds 	int shift = kcontrol->private_value;
10931da177e4SLinus Torvalds 	unsigned short val;
10941da177e4SLinus Torvalds 
10951da177e4SLinus Torvalds 	val = ac97->regs[AC97_SIGMATEL_OUTSEL] >> shift;
10961da177e4SLinus Torvalds 	if (!(val & 4))
10971da177e4SLinus Torvalds 		ucontrol->value.enumerated.item[0] = 0;
10981da177e4SLinus Torvalds 	else
10991da177e4SLinus Torvalds 		ucontrol->value.enumerated.item[0] = 1 + (val & 3);
11001da177e4SLinus Torvalds 	return 0;
11011da177e4SLinus Torvalds }
11021da177e4SLinus Torvalds 
snd_ac97_stac9758_output_jack_put(struct snd_kcontrol * kcontrol,struct snd_ctl_elem_value * ucontrol)1103ee42381eSTakashi Iwai static int snd_ac97_stac9758_output_jack_put(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
11041da177e4SLinus Torvalds {
1105ee42381eSTakashi Iwai 	struct snd_ac97 *ac97 = snd_kcontrol_chip(kcontrol);
11061da177e4SLinus Torvalds 	int shift = kcontrol->private_value;
11071da177e4SLinus Torvalds 	unsigned short val;
11081da177e4SLinus Torvalds 
11091da177e4SLinus Torvalds 	if (ucontrol->value.enumerated.item[0] > 4)
11101da177e4SLinus Torvalds 		return -EINVAL;
11111da177e4SLinus Torvalds 	if (ucontrol->value.enumerated.item[0] == 0)
11121da177e4SLinus Torvalds 		val = 0;
11131da177e4SLinus Torvalds 	else
11141da177e4SLinus Torvalds 		val = 4 | (ucontrol->value.enumerated.item[0] - 1);
11151da177e4SLinus Torvalds 	return ac97_update_bits_page(ac97, AC97_SIGMATEL_OUTSEL,
11161da177e4SLinus Torvalds 				     7 << shift, val << shift, 0);
11171da177e4SLinus Torvalds }
11181da177e4SLinus Torvalds 
snd_ac97_stac9758_input_jack_info(struct snd_kcontrol * kcontrol,struct snd_ctl_elem_info * uinfo)1119ee42381eSTakashi Iwai static int snd_ac97_stac9758_input_jack_info(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_info *uinfo)
11201da177e4SLinus Torvalds {
11213b7a00dcSTakashi Iwai 	static const char * const texts[7] = {
11223b7a00dcSTakashi Iwai 		"Mic2 Jack", "Mic1 Jack", "Line In Jack",
11231da177e4SLinus Torvalds 		"Front Jack", "Rear Jack", "Center/LFE Jack", "Mute" };
11241da177e4SLinus Torvalds 
11253b7a00dcSTakashi Iwai 	return snd_ctl_enum_info(uinfo, 1, 7, texts);
11261da177e4SLinus Torvalds }
11271da177e4SLinus Torvalds 
snd_ac97_stac9758_input_jack_get(struct snd_kcontrol * kcontrol,struct snd_ctl_elem_value * ucontrol)1128ee42381eSTakashi Iwai static int snd_ac97_stac9758_input_jack_get(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
11291da177e4SLinus Torvalds {
1130ee42381eSTakashi Iwai 	struct snd_ac97 *ac97 = snd_kcontrol_chip(kcontrol);
11311da177e4SLinus Torvalds 	int shift = kcontrol->private_value;
11321da177e4SLinus Torvalds 	unsigned short val;
11331da177e4SLinus Torvalds 
11341da177e4SLinus Torvalds 	val = ac97->regs[AC97_SIGMATEL_INSEL];
11351da177e4SLinus Torvalds 	ucontrol->value.enumerated.item[0] = (val >> shift) & 7;
11361da177e4SLinus Torvalds 	return 0;
11371da177e4SLinus Torvalds }
11381da177e4SLinus Torvalds 
snd_ac97_stac9758_input_jack_put(struct snd_kcontrol * kcontrol,struct snd_ctl_elem_value * ucontrol)1139ee42381eSTakashi Iwai static int snd_ac97_stac9758_input_jack_put(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
11401da177e4SLinus Torvalds {
1141ee42381eSTakashi Iwai 	struct snd_ac97 *ac97 = snd_kcontrol_chip(kcontrol);
11421da177e4SLinus Torvalds 	int shift = kcontrol->private_value;
11431da177e4SLinus Torvalds 
11441da177e4SLinus Torvalds 	return ac97_update_bits_page(ac97, AC97_SIGMATEL_INSEL, 7 << shift,
11451da177e4SLinus Torvalds 				     ucontrol->value.enumerated.item[0] << shift, 0);
11461da177e4SLinus Torvalds }
11471da177e4SLinus Torvalds 
snd_ac97_stac9758_phonesel_info(struct snd_kcontrol * kcontrol,struct snd_ctl_elem_info * uinfo)1148ee42381eSTakashi Iwai static int snd_ac97_stac9758_phonesel_info(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_info *uinfo)
11491da177e4SLinus Torvalds {
11503b7a00dcSTakashi Iwai 	static const char * const texts[3] = {
11513b7a00dcSTakashi Iwai 		"None", "Front Jack", "Rear Jack"
11523b7a00dcSTakashi Iwai 	};
11531da177e4SLinus Torvalds 
11543b7a00dcSTakashi Iwai 	return snd_ctl_enum_info(uinfo, 1, 3, texts);
11551da177e4SLinus Torvalds }
11561da177e4SLinus Torvalds 
snd_ac97_stac9758_phonesel_get(struct snd_kcontrol * kcontrol,struct snd_ctl_elem_value * ucontrol)1157ee42381eSTakashi Iwai static int snd_ac97_stac9758_phonesel_get(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
11581da177e4SLinus Torvalds {
1159ee42381eSTakashi Iwai 	struct snd_ac97 *ac97 = snd_kcontrol_chip(kcontrol);
11601da177e4SLinus Torvalds 
11611da177e4SLinus Torvalds 	ucontrol->value.enumerated.item[0] = ac97->regs[AC97_SIGMATEL_IOMISC] & 3;
11621da177e4SLinus Torvalds 	return 0;
11631da177e4SLinus Torvalds }
11641da177e4SLinus Torvalds 
snd_ac97_stac9758_phonesel_put(struct snd_kcontrol * kcontrol,struct snd_ctl_elem_value * ucontrol)1165ee42381eSTakashi Iwai static int snd_ac97_stac9758_phonesel_put(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
11661da177e4SLinus Torvalds {
1167ee42381eSTakashi Iwai 	struct snd_ac97 *ac97 = snd_kcontrol_chip(kcontrol);
11681da177e4SLinus Torvalds 
11691da177e4SLinus Torvalds 	return ac97_update_bits_page(ac97, AC97_SIGMATEL_IOMISC, 3,
11701da177e4SLinus Torvalds 				     ucontrol->value.enumerated.item[0], 0);
11711da177e4SLinus Torvalds }
11721da177e4SLinus Torvalds 
11731da177e4SLinus Torvalds #define STAC9758_OUTPUT_JACK(xname, shift) \
11741da177e4SLinus Torvalds {	.iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = xname, \
11751da177e4SLinus Torvalds 	.info = snd_ac97_stac9758_output_jack_info, \
11761da177e4SLinus Torvalds 	.get = snd_ac97_stac9758_output_jack_get, \
11771da177e4SLinus Torvalds 	.put = snd_ac97_stac9758_output_jack_put, \
11781da177e4SLinus Torvalds 	.private_value = shift }
11791da177e4SLinus Torvalds #define STAC9758_INPUT_JACK(xname, shift) \
11801da177e4SLinus Torvalds {	.iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = xname, \
11811da177e4SLinus Torvalds 	.info = snd_ac97_stac9758_input_jack_info, \
11821da177e4SLinus Torvalds 	.get = snd_ac97_stac9758_input_jack_get, \
11831da177e4SLinus Torvalds 	.put = snd_ac97_stac9758_input_jack_put, \
11841da177e4SLinus Torvalds 	.private_value = shift }
1185ee42381eSTakashi Iwai static const struct snd_kcontrol_new snd_ac97_sigmatel_stac9758_controls[] = {
11861da177e4SLinus Torvalds 	STAC9758_OUTPUT_JACK("Mic1 Jack", 1),
11871da177e4SLinus Torvalds 	STAC9758_OUTPUT_JACK("LineIn Jack", 4),
11881da177e4SLinus Torvalds 	STAC9758_OUTPUT_JACK("Front Jack", 7),
11891da177e4SLinus Torvalds 	STAC9758_OUTPUT_JACK("Rear Jack", 10),
11901da177e4SLinus Torvalds 	STAC9758_OUTPUT_JACK("Center/LFE Jack", 13),
11911da177e4SLinus Torvalds 	STAC9758_INPUT_JACK("Mic Input Source", 0),
11921da177e4SLinus Torvalds 	STAC9758_INPUT_JACK("Line Input Source", 8),
11931da177e4SLinus Torvalds 	{
11941da177e4SLinus Torvalds 		.iface = SNDRV_CTL_ELEM_IFACE_MIXER,
11951da177e4SLinus Torvalds 		.name = "Headphone Amp",
11961da177e4SLinus Torvalds 		.info = snd_ac97_stac9758_phonesel_info,
11971da177e4SLinus Torvalds 		.get = snd_ac97_stac9758_phonesel_get,
11981da177e4SLinus Torvalds 		.put = snd_ac97_stac9758_phonesel_put
11991da177e4SLinus Torvalds 	},
12001da177e4SLinus Torvalds 	AC97_SINGLE("Exchange Center/LFE", AC97_SIGMATEL_IOMISC, 4, 1, 0),
12011da177e4SLinus Torvalds 	AC97_SINGLE("Headphone +3dB Boost", AC97_SIGMATEL_IOMISC, 8, 1, 0)
12021da177e4SLinus Torvalds };
12031da177e4SLinus Torvalds 
patch_sigmatel_stac9758_specific(struct snd_ac97 * ac97)1204ee42381eSTakashi Iwai static int patch_sigmatel_stac9758_specific(struct snd_ac97 *ac97)
12051da177e4SLinus Torvalds {
12061da177e4SLinus Torvalds 	int err;
12071da177e4SLinus Torvalds 
12081da177e4SLinus Torvalds 	err = patch_sigmatel_stac97xx_specific(ac97);
12091da177e4SLinus Torvalds 	if (err < 0)
12101da177e4SLinus Torvalds 		return err;
12111da177e4SLinus Torvalds 	err = patch_build_controls(ac97, snd_ac97_sigmatel_stac9758_controls,
12121da177e4SLinus Torvalds 				   ARRAY_SIZE(snd_ac97_sigmatel_stac9758_controls));
12131da177e4SLinus Torvalds 	if (err < 0)
12141da177e4SLinus Torvalds 		return err;
12151da177e4SLinus Torvalds 	/* DAC-A direct */
12161da177e4SLinus Torvalds 	snd_ac97_rename_vol_ctl(ac97, "Headphone Playback", "Front Playback");
12171da177e4SLinus Torvalds 	/* DAC-A to Mix = PCM */
12181da177e4SLinus Torvalds 	/* DAC-B direct = Surround */
12191da177e4SLinus Torvalds 	/* DAC-B to Mix */
12201da177e4SLinus Torvalds 	snd_ac97_rename_vol_ctl(ac97, "Video Playback", "Surround Mix Playback");
12211da177e4SLinus Torvalds 	/* DAC-C direct = Center/LFE */
12221da177e4SLinus Torvalds 
12231da177e4SLinus Torvalds 	return 0;
12241da177e4SLinus Torvalds }
12251da177e4SLinus Torvalds 
12263e8b3b90SHanno Boeck static const struct snd_ac97_build_ops patch_sigmatel_stac9758_ops = {
12271da177e4SLinus Torvalds 	.build_3d	= patch_sigmatel_stac9700_3d,
12281da177e4SLinus Torvalds 	.build_specific	= patch_sigmatel_stac9758_specific
12291da177e4SLinus Torvalds };
12301da177e4SLinus Torvalds 
patch_sigmatel_stac9758(struct snd_ac97 * ac97)1231ac519028STakashi Iwai static int patch_sigmatel_stac9758(struct snd_ac97 * ac97)
12321da177e4SLinus Torvalds {
12331675bfc0STakashi Iwai 	static const unsigned short regs[4] = {
12341da177e4SLinus Torvalds 		AC97_SIGMATEL_OUTSEL,
12351da177e4SLinus Torvalds 		AC97_SIGMATEL_IOMISC,
12361da177e4SLinus Torvalds 		AC97_SIGMATEL_INSEL,
12371da177e4SLinus Torvalds 		AC97_SIGMATEL_VARIOUS
12381da177e4SLinus Torvalds 	};
12391675bfc0STakashi Iwai 	static const unsigned short def_regs[4] = {
12401da177e4SLinus Torvalds 		/* OUTSEL */ 0xd794, /* CL:CL, SR:SR, LO:MX, LI:DS, MI:DS */
12411da177e4SLinus Torvalds 		/* IOMISC */ 0x2001,
12421da177e4SLinus Torvalds 		/* INSEL */ 0x0201, /* LI:LI, MI:M1 */
12431da177e4SLinus Torvalds 		/* VARIOUS */ 0x0040
12441da177e4SLinus Torvalds 	};
12451675bfc0STakashi Iwai 	static const unsigned short m675_regs[4] = {
12461da177e4SLinus Torvalds 		/* OUTSEL */ 0xfc70, /* CL:MX, SR:MX, LO:DS, LI:MX, MI:DS */
12471da177e4SLinus Torvalds 		/* IOMISC */ 0x2102, /* HP amp on */
12481da177e4SLinus Torvalds 		/* INSEL */ 0x0203, /* LI:LI, MI:FR */
12491da177e4SLinus Torvalds 		/* VARIOUS */ 0x0041 /* stereo mic */
12501da177e4SLinus Torvalds 	};
12511675bfc0STakashi Iwai 	const unsigned short *pregs = def_regs;
12521da177e4SLinus Torvalds 	int i;
12531da177e4SLinus Torvalds 
12541da177e4SLinus Torvalds 	/* Gateway M675 notebook */
12551da177e4SLinus Torvalds 	if (ac97->pci &&
12561da177e4SLinus Torvalds 	    ac97->subsystem_vendor == 0x107b &&
12571da177e4SLinus Torvalds 	    ac97->subsystem_device == 0x0601)
12581da177e4SLinus Torvalds 	    	pregs = m675_regs;
12591da177e4SLinus Torvalds 
12601da177e4SLinus Torvalds 	// patch for SigmaTel
12611da177e4SLinus Torvalds 	ac97->build_ops = &patch_sigmatel_stac9758_ops;
12621da177e4SLinus Torvalds 	/* FIXME: assume only page 0 for writing cache */
12631da177e4SLinus Torvalds 	snd_ac97_update_bits(ac97, AC97_INT_PAGING, AC97_PAGE_MASK, AC97_PAGE_VENDOR);
12641da177e4SLinus Torvalds 	for (i = 0; i < 4; i++)
12651da177e4SLinus Torvalds 		snd_ac97_write_cache(ac97, regs[i], pregs[i]);
12661da177e4SLinus Torvalds 
12671da177e4SLinus Torvalds 	ac97->flags |= AC97_STEREO_MUTES;
12681da177e4SLinus Torvalds 	return 0;
12691da177e4SLinus Torvalds }
12701da177e4SLinus Torvalds 
12711da177e4SLinus Torvalds /*
12721da177e4SLinus Torvalds  * Cirrus Logic CS42xx codecs
12731da177e4SLinus Torvalds  */
1274ee42381eSTakashi Iwai static const struct snd_kcontrol_new snd_ac97_cirrus_controls_spdif[2] = {
12751da177e4SLinus Torvalds 	AC97_SINGLE(SNDRV_CTL_NAME_IEC958("",PLAYBACK,SWITCH), AC97_CSR_SPDIF, 15, 1, 0),
12761da177e4SLinus Torvalds 	AC97_SINGLE(SNDRV_CTL_NAME_IEC958("",PLAYBACK,NONE) "AC97-SPSA", AC97_CSR_ACMODE, 0, 3, 0)
12771da177e4SLinus Torvalds };
12781da177e4SLinus Torvalds 
patch_cirrus_build_spdif(struct snd_ac97 * ac97)1279ee42381eSTakashi Iwai static int patch_cirrus_build_spdif(struct snd_ac97 * ac97)
12801da177e4SLinus Torvalds {
12811da177e4SLinus Torvalds 	int err;
12821da177e4SLinus Torvalds 
12831da177e4SLinus Torvalds 	/* con mask, pro mask, default */
1284e66fd362STakashi Iwai 	err = patch_build_controls(ac97, &snd_ac97_controls_spdif[0], 3);
1285e66fd362STakashi Iwai 	if (err < 0)
12861da177e4SLinus Torvalds 		return err;
12871da177e4SLinus Torvalds 	/* switch, spsa */
1288e66fd362STakashi Iwai 	err = patch_build_controls(ac97, &snd_ac97_cirrus_controls_spdif[0], 1);
1289e66fd362STakashi Iwai 	if (err < 0)
12901da177e4SLinus Torvalds 		return err;
12911da177e4SLinus Torvalds 	switch (ac97->id & AC97_ID_CS_MASK) {
12921da177e4SLinus Torvalds 	case AC97_ID_CS4205:
1293e66fd362STakashi Iwai 		err = patch_build_controls(ac97, &snd_ac97_cirrus_controls_spdif[1], 1);
1294e66fd362STakashi Iwai 		if (err < 0)
12951da177e4SLinus Torvalds 			return err;
12961da177e4SLinus Torvalds 		break;
12971da177e4SLinus Torvalds 	}
12981da177e4SLinus Torvalds 	/* set default PCM S/PDIF params */
12991da177e4SLinus Torvalds 	/* consumer,PCM audio,no copyright,no preemphasis,PCM coder,original,48000Hz */
13001da177e4SLinus Torvalds 	snd_ac97_write_cache(ac97, AC97_CSR_SPDIF, 0x0a20);
13011da177e4SLinus Torvalds 	return 0;
13021da177e4SLinus Torvalds }
13031da177e4SLinus Torvalds 
13043e8b3b90SHanno Boeck static const struct snd_ac97_build_ops patch_cirrus_ops = {
13051da177e4SLinus Torvalds 	.build_spdif = patch_cirrus_build_spdif
13061da177e4SLinus Torvalds };
13071da177e4SLinus Torvalds 
patch_cirrus_spdif(struct snd_ac97 * ac97)1308ac519028STakashi Iwai static int patch_cirrus_spdif(struct snd_ac97 * ac97)
13091da177e4SLinus Torvalds {
13101da177e4SLinus Torvalds 	/* Basically, the cs4201/cs4205/cs4297a has non-standard sp/dif registers.
13111da177e4SLinus Torvalds 	   WHY CAN'T ANYONE FOLLOW THE BLOODY SPEC?  *sigh*
13121da177e4SLinus Torvalds 	   - sp/dif EA ID is not set, but sp/dif is always present.
13131da177e4SLinus Torvalds 	   - enable/disable is spdif register bit 15.
13141da177e4SLinus Torvalds 	   - sp/dif control register is 0x68.  differs from AC97:
13151da177e4SLinus Torvalds 	   - valid is bit 14 (vs 15)
13161da177e4SLinus Torvalds 	   - no DRS
13171da177e4SLinus Torvalds 	   - only 44.1/48k [00 = 48, 01=44,1] (AC97 is 00=44.1, 10=48)
13181da177e4SLinus Torvalds 	   - sp/dif ssource select is in 0x5e bits 0,1.
13191da177e4SLinus Torvalds 	*/
13201da177e4SLinus Torvalds 
13211da177e4SLinus Torvalds 	ac97->build_ops = &patch_cirrus_ops;
13221da177e4SLinus Torvalds 	ac97->flags |= AC97_CS_SPDIF;
13231da177e4SLinus Torvalds 	ac97->rates[AC97_RATES_SPDIF] &= ~SNDRV_PCM_RATE_32000;
13241da177e4SLinus Torvalds         ac97->ext_id |= AC97_EI_SPDIF;	/* force the detection of spdif */
13251da177e4SLinus Torvalds 	snd_ac97_write_cache(ac97, AC97_CSR_ACMODE, 0x0080);
13261da177e4SLinus Torvalds 	return 0;
13271da177e4SLinus Torvalds }
13281da177e4SLinus Torvalds 
patch_cirrus_cs4299(struct snd_ac97 * ac97)1329ac519028STakashi Iwai static int patch_cirrus_cs4299(struct snd_ac97 * ac97)
13301da177e4SLinus Torvalds {
13311da177e4SLinus Torvalds 	/* force the detection of PC Beep */
13321da177e4SLinus Torvalds 	ac97->flags |= AC97_HAS_PC_BEEP;
13331da177e4SLinus Torvalds 
13341da177e4SLinus Torvalds 	return patch_cirrus_spdif(ac97);
13351da177e4SLinus Torvalds }
13361da177e4SLinus Torvalds 
13371da177e4SLinus Torvalds /*
13381da177e4SLinus Torvalds  * Conexant codecs
13391da177e4SLinus Torvalds  */
1340ee42381eSTakashi Iwai static const struct snd_kcontrol_new snd_ac97_conexant_controls_spdif[1] = {
13411da177e4SLinus Torvalds 	AC97_SINGLE(SNDRV_CTL_NAME_IEC958("",PLAYBACK,SWITCH), AC97_CXR_AUDIO_MISC, 3, 1, 0),
13421da177e4SLinus Torvalds };
13431da177e4SLinus Torvalds 
patch_conexant_build_spdif(struct snd_ac97 * ac97)1344ee42381eSTakashi Iwai static int patch_conexant_build_spdif(struct snd_ac97 * ac97)
13451da177e4SLinus Torvalds {
13461da177e4SLinus Torvalds 	int err;
13471da177e4SLinus Torvalds 
13481da177e4SLinus Torvalds 	/* con mask, pro mask, default */
1349e66fd362STakashi Iwai 	err = patch_build_controls(ac97, &snd_ac97_controls_spdif[0], 3);
1350e66fd362STakashi Iwai 	if (err < 0)
13511da177e4SLinus Torvalds 		return err;
13521da177e4SLinus Torvalds 	/* switch */
1353e66fd362STakashi Iwai 	err = patch_build_controls(ac97, &snd_ac97_conexant_controls_spdif[0], 1);
1354e66fd362STakashi Iwai 	if (err < 0)
13551da177e4SLinus Torvalds 		return err;
13561da177e4SLinus Torvalds 	/* set default PCM S/PDIF params */
13571da177e4SLinus Torvalds 	/* consumer,PCM audio,no copyright,no preemphasis,PCM coder,original,48000Hz */
13581da177e4SLinus Torvalds 	snd_ac97_write_cache(ac97, AC97_CXR_AUDIO_MISC,
13591da177e4SLinus Torvalds 			     snd_ac97_read(ac97, AC97_CXR_AUDIO_MISC) & ~(AC97_CXR_SPDIFEN|AC97_CXR_COPYRGT|AC97_CXR_SPDIF_MASK));
13601da177e4SLinus Torvalds 	return 0;
13611da177e4SLinus Torvalds }
13621da177e4SLinus Torvalds 
13633e8b3b90SHanno Boeck static const struct snd_ac97_build_ops patch_conexant_ops = {
13641da177e4SLinus Torvalds 	.build_spdif = patch_conexant_build_spdif
13651da177e4SLinus Torvalds };
13661da177e4SLinus Torvalds 
patch_conexant(struct snd_ac97 * ac97)1367ac519028STakashi Iwai static int patch_conexant(struct snd_ac97 * ac97)
13681da177e4SLinus Torvalds {
13691da177e4SLinus Torvalds 	ac97->build_ops = &patch_conexant_ops;
13701da177e4SLinus Torvalds 	ac97->flags |= AC97_CX_SPDIF;
13711da177e4SLinus Torvalds         ac97->ext_id |= AC97_EI_SPDIF;	/* force the detection of spdif */
13721da177e4SLinus Torvalds 	ac97->rates[AC97_RATES_SPDIF] = SNDRV_PCM_RATE_48000; /* 48k only */
13731da177e4SLinus Torvalds 	return 0;
13741da177e4SLinus Torvalds }
13751da177e4SLinus Torvalds 
patch_cx20551(struct snd_ac97 * ac97)1376ac519028STakashi Iwai static int patch_cx20551(struct snd_ac97 *ac97)
13779e292c00STakashi Iwai {
13789e292c00STakashi Iwai 	snd_ac97_update_bits(ac97, 0x5c, 0x01, 0x01);
13799e292c00STakashi Iwai 	return 0;
13809e292c00STakashi Iwai }
13819e292c00STakashi Iwai 
13821da177e4SLinus Torvalds /*
1383aa08ff0fSGeert Uytterhoeven  * Analog Devices AD18xx, AD19xx codecs
13841da177e4SLinus Torvalds  */
13851da177e4SLinus Torvalds #ifdef CONFIG_PM
ad18xx_resume(struct snd_ac97 * ac97)1386ee42381eSTakashi Iwai static void ad18xx_resume(struct snd_ac97 *ac97)
13871da177e4SLinus Torvalds {
13881675bfc0STakashi Iwai 	static const unsigned short setup_regs[] = {
13891da177e4SLinus Torvalds 		AC97_AD_MISC, AC97_AD_SERIAL_CFG, AC97_AD_JACK_SPDIF,
13901da177e4SLinus Torvalds 	};
13911da177e4SLinus Torvalds 	int i, codec;
13921da177e4SLinus Torvalds 
13931da177e4SLinus Torvalds 	for (i = 0; i < (int)ARRAY_SIZE(setup_regs); i++) {
13941da177e4SLinus Torvalds 		unsigned short reg = setup_regs[i];
13951da177e4SLinus Torvalds 		if (test_bit(reg, ac97->reg_accessed)) {
13961da177e4SLinus Torvalds 			snd_ac97_write(ac97, reg, ac97->regs[reg]);
13971da177e4SLinus Torvalds 			snd_ac97_read(ac97, reg);
13981da177e4SLinus Torvalds 		}
13991da177e4SLinus Torvalds 	}
14001da177e4SLinus Torvalds 
14011da177e4SLinus Torvalds 	if (! (ac97->flags & AC97_AD_MULTI))
14021da177e4SLinus Torvalds 		/* normal restore */
14031da177e4SLinus Torvalds 		snd_ac97_restore_status(ac97);
14041da177e4SLinus Torvalds 	else {
14051da177e4SLinus Torvalds 		/* restore the AD18xx codec configurations */
14061da177e4SLinus Torvalds 		for (codec = 0; codec < 3; codec++) {
14071da177e4SLinus Torvalds 			if (! ac97->spec.ad18xx.id[codec])
14081da177e4SLinus Torvalds 				continue;
14091da177e4SLinus Torvalds 			/* select single codec */
14101da177e4SLinus Torvalds 			snd_ac97_update_bits(ac97, AC97_AD_SERIAL_CFG, 0x7000,
14111da177e4SLinus Torvalds 					     ac97->spec.ad18xx.unchained[codec] | ac97->spec.ad18xx.chained[codec]);
14121da177e4SLinus Torvalds 			ac97->bus->ops->write(ac97, AC97_AD_CODEC_CFG, ac97->spec.ad18xx.codec_cfg[codec]);
14131da177e4SLinus Torvalds 		}
14141da177e4SLinus Torvalds 		/* select all codecs */
14151da177e4SLinus Torvalds 		snd_ac97_update_bits(ac97, AC97_AD_SERIAL_CFG, 0x7000, 0x7000);
14161da177e4SLinus Torvalds 
14171da177e4SLinus Torvalds 		/* restore status */
14181da177e4SLinus Torvalds 		for (i = 2; i < 0x7c ; i += 2) {
14191da177e4SLinus Torvalds 			if (i == AC97_POWERDOWN || i == AC97_EXTENDED_ID)
14201da177e4SLinus Torvalds 				continue;
14211da177e4SLinus Torvalds 			if (test_bit(i, ac97->reg_accessed)) {
14221da177e4SLinus Torvalds 				/* handle multi codecs for AD18xx */
14231da177e4SLinus Torvalds 				if (i == AC97_PCM) {
14241da177e4SLinus Torvalds 					for (codec = 0; codec < 3; codec++) {
14251da177e4SLinus Torvalds 						if (! ac97->spec.ad18xx.id[codec])
14261da177e4SLinus Torvalds 							continue;
14271da177e4SLinus Torvalds 						/* select single codec */
14281da177e4SLinus Torvalds 						snd_ac97_update_bits(ac97, AC97_AD_SERIAL_CFG, 0x7000,
14291da177e4SLinus Torvalds 								     ac97->spec.ad18xx.unchained[codec] | ac97->spec.ad18xx.chained[codec]);
14301da177e4SLinus Torvalds 						/* update PCM bits */
14311da177e4SLinus Torvalds 						ac97->bus->ops->write(ac97, AC97_PCM, ac97->spec.ad18xx.pcmreg[codec]);
14321da177e4SLinus Torvalds 					}
14331da177e4SLinus Torvalds 					/* select all codecs */
14341da177e4SLinus Torvalds 					snd_ac97_update_bits(ac97, AC97_AD_SERIAL_CFG, 0x7000, 0x7000);
14351da177e4SLinus Torvalds 					continue;
14361da177e4SLinus Torvalds 				} else if (i == AC97_AD_TEST ||
14371da177e4SLinus Torvalds 					   i == AC97_AD_CODEC_CFG ||
14381da177e4SLinus Torvalds 					   i == AC97_AD_SERIAL_CFG)
14391da177e4SLinus Torvalds 					continue; /* ignore */
14401da177e4SLinus Torvalds 			}
14411da177e4SLinus Torvalds 			snd_ac97_write(ac97, i, ac97->regs[i]);
14421da177e4SLinus Torvalds 			snd_ac97_read(ac97, i);
14431da177e4SLinus Torvalds 		}
14441da177e4SLinus Torvalds 	}
14451da177e4SLinus Torvalds 
14461da177e4SLinus Torvalds 	snd_ac97_restore_iec958(ac97);
14471da177e4SLinus Torvalds }
14481561f09aSJaya Kumar 
ad1888_resume(struct snd_ac97 * ac97)14491561f09aSJaya Kumar static void ad1888_resume(struct snd_ac97 *ac97)
14501561f09aSJaya Kumar {
14511561f09aSJaya Kumar 	ad18xx_resume(ac97);
14521561f09aSJaya Kumar 	snd_ac97_write_cache(ac97, AC97_CODEC_CLASS_REV, 0x8080);
14531561f09aSJaya Kumar }
14541561f09aSJaya Kumar 
14551da177e4SLinus Torvalds #endif
14561da177e4SLinus Torvalds 
1457bd25b7caSVille Syrjala static const struct snd_ac97_res_table ad1819_restbl[] = {
1458bd25b7caSVille Syrjala 	{ AC97_PHONE, 0x9f1f },
1459bd25b7caSVille Syrjala 	{ AC97_MIC, 0x9f1f },
1460bd25b7caSVille Syrjala 	{ AC97_LINE, 0x9f1f },
1461bd25b7caSVille Syrjala 	{ AC97_CD, 0x9f1f },
1462bd25b7caSVille Syrjala 	{ AC97_VIDEO, 0x9f1f },
1463bd25b7caSVille Syrjala 	{ AC97_AUX, 0x9f1f },
1464bd25b7caSVille Syrjala 	{ AC97_PCM, 0x9f1f },
1465bd25b7caSVille Syrjala 	{ } /* terminator */
1466bd25b7caSVille Syrjala };
1467bd25b7caSVille Syrjala 
patch_ad1819(struct snd_ac97 * ac97)1468ac519028STakashi Iwai static int patch_ad1819(struct snd_ac97 * ac97)
14691da177e4SLinus Torvalds {
14701da177e4SLinus Torvalds 	unsigned short scfg;
14711da177e4SLinus Torvalds 
14721da177e4SLinus Torvalds 	// patch for Analog Devices
14731da177e4SLinus Torvalds 	scfg = snd_ac97_read(ac97, AC97_AD_SERIAL_CFG);
14741da177e4SLinus Torvalds 	snd_ac97_write_cache(ac97, AC97_AD_SERIAL_CFG, scfg | 0x7000); /* select all codecs */
1475bd25b7caSVille Syrjala 	ac97->res_table = ad1819_restbl;
14761da177e4SLinus Torvalds 	return 0;
14771da177e4SLinus Torvalds }
14781da177e4SLinus Torvalds 
patch_ad1881_unchained(struct snd_ac97 * ac97,int idx,unsigned short mask)1479ee42381eSTakashi Iwai static unsigned short patch_ad1881_unchained(struct snd_ac97 * ac97, int idx, unsigned short mask)
14801da177e4SLinus Torvalds {
14811da177e4SLinus Torvalds 	unsigned short val;
14821da177e4SLinus Torvalds 
14831da177e4SLinus Torvalds 	// test for unchained codec
14841da177e4SLinus Torvalds 	snd_ac97_update_bits(ac97, AC97_AD_SERIAL_CFG, 0x7000, mask);
14851da177e4SLinus Torvalds 	snd_ac97_write_cache(ac97, AC97_AD_CODEC_CFG, 0x0000);	/* ID0C, ID1C, SDIE = off */
14861da177e4SLinus Torvalds 	val = snd_ac97_read(ac97, AC97_VENDOR_ID2);
14871da177e4SLinus Torvalds 	if ((val & 0xff40) != 0x5340)
14881da177e4SLinus Torvalds 		return 0;
14891da177e4SLinus Torvalds 	ac97->spec.ad18xx.unchained[idx] = mask;
14901da177e4SLinus Torvalds 	ac97->spec.ad18xx.id[idx] = val;
14911da177e4SLinus Torvalds 	ac97->spec.ad18xx.codec_cfg[idx] = 0x0000;
14921da177e4SLinus Torvalds 	return mask;
14931da177e4SLinus Torvalds }
14941da177e4SLinus Torvalds 
patch_ad1881_chained1(struct snd_ac97 * ac97,int idx,unsigned short codec_bits)1495ee42381eSTakashi Iwai static int patch_ad1881_chained1(struct snd_ac97 * ac97, int idx, unsigned short codec_bits)
14961da177e4SLinus Torvalds {
14971675bfc0STakashi Iwai 	static const int cfg_bits[3] = { 1<<12, 1<<14, 1<<13 };
14981da177e4SLinus Torvalds 	unsigned short val;
14991da177e4SLinus Torvalds 
15001da177e4SLinus Torvalds 	snd_ac97_update_bits(ac97, AC97_AD_SERIAL_CFG, 0x7000, cfg_bits[idx]);
15011da177e4SLinus Torvalds 	snd_ac97_write_cache(ac97, AC97_AD_CODEC_CFG, 0x0004);	// SDIE
15021da177e4SLinus Torvalds 	val = snd_ac97_read(ac97, AC97_VENDOR_ID2);
15031da177e4SLinus Torvalds 	if ((val & 0xff40) != 0x5340)
15041da177e4SLinus Torvalds 		return 0;
15051da177e4SLinus Torvalds 	if (codec_bits)
15061da177e4SLinus Torvalds 		snd_ac97_write_cache(ac97, AC97_AD_CODEC_CFG, codec_bits);
15071da177e4SLinus Torvalds 	ac97->spec.ad18xx.chained[idx] = cfg_bits[idx];
15081da177e4SLinus Torvalds 	ac97->spec.ad18xx.id[idx] = val;
15091da177e4SLinus Torvalds 	ac97->spec.ad18xx.codec_cfg[idx] = codec_bits ? codec_bits : 0x0004;
15101da177e4SLinus Torvalds 	return 1;
15111da177e4SLinus Torvalds }
15121da177e4SLinus Torvalds 
patch_ad1881_chained(struct snd_ac97 * ac97,int unchained_idx,int cidx1,int cidx2)1513ee42381eSTakashi Iwai static void patch_ad1881_chained(struct snd_ac97 * ac97, int unchained_idx, int cidx1, int cidx2)
15141da177e4SLinus Torvalds {
15151da177e4SLinus Torvalds 	// already detected?
15161da177e4SLinus Torvalds 	if (ac97->spec.ad18xx.unchained[cidx1] || ac97->spec.ad18xx.chained[cidx1])
15171da177e4SLinus Torvalds 		cidx1 = -1;
15181da177e4SLinus Torvalds 	if (ac97->spec.ad18xx.unchained[cidx2] || ac97->spec.ad18xx.chained[cidx2])
15191da177e4SLinus Torvalds 		cidx2 = -1;
15201da177e4SLinus Torvalds 	if (cidx1 < 0 && cidx2 < 0)
15211da177e4SLinus Torvalds 		return;
15221da177e4SLinus Torvalds 	// test for chained codecs
15231da177e4SLinus Torvalds 	snd_ac97_update_bits(ac97, AC97_AD_SERIAL_CFG, 0x7000,
15241da177e4SLinus Torvalds 			     ac97->spec.ad18xx.unchained[unchained_idx]);
15251da177e4SLinus Torvalds 	snd_ac97_write_cache(ac97, AC97_AD_CODEC_CFG, 0x0002);		// ID1C
15261da177e4SLinus Torvalds 	ac97->spec.ad18xx.codec_cfg[unchained_idx] = 0x0002;
15271da177e4SLinus Torvalds 	if (cidx1 >= 0) {
1528c19bcdc6STakashi Iwai 		if (cidx2 < 0)
1529c19bcdc6STakashi Iwai 			patch_ad1881_chained1(ac97, cidx1, 0);
1530c19bcdc6STakashi Iwai 		else if (patch_ad1881_chained1(ac97, cidx1, 0x0006))	// SDIE | ID1C
15311da177e4SLinus Torvalds 			patch_ad1881_chained1(ac97, cidx2, 0);
15321da177e4SLinus Torvalds 		else if (patch_ad1881_chained1(ac97, cidx2, 0x0006))	// SDIE | ID1C
15331da177e4SLinus Torvalds 			patch_ad1881_chained1(ac97, cidx1, 0);
15341da177e4SLinus Torvalds 	} else if (cidx2 >= 0) {
15351da177e4SLinus Torvalds 		patch_ad1881_chained1(ac97, cidx2, 0);
15361da177e4SLinus Torvalds 	}
15371da177e4SLinus Torvalds }
15381da177e4SLinus Torvalds 
15393e8b3b90SHanno Boeck static const struct snd_ac97_build_ops patch_ad1881_build_ops = {
15401da177e4SLinus Torvalds #ifdef CONFIG_PM
15411da177e4SLinus Torvalds 	.resume = ad18xx_resume
15421da177e4SLinus Torvalds #endif
15431da177e4SLinus Torvalds };
15441da177e4SLinus Torvalds 
patch_ad1881(struct snd_ac97 * ac97)1545ac519028STakashi Iwai static int patch_ad1881(struct snd_ac97 * ac97)
15461da177e4SLinus Torvalds {
15471da177e4SLinus Torvalds 	static const char cfg_idxs[3][2] = {
15481da177e4SLinus Torvalds 		{2, 1},
15491da177e4SLinus Torvalds 		{0, 2},
15501da177e4SLinus Torvalds 		{0, 1}
15511da177e4SLinus Torvalds 	};
15521da177e4SLinus Torvalds 
15531da177e4SLinus Torvalds 	// patch for Analog Devices
15541da177e4SLinus Torvalds 	unsigned short codecs[3];
15551da177e4SLinus Torvalds 	unsigned short val;
15561da177e4SLinus Torvalds 	int idx, num;
15571da177e4SLinus Torvalds 
15581da177e4SLinus Torvalds 	val = snd_ac97_read(ac97, AC97_AD_SERIAL_CFG);
15591da177e4SLinus Torvalds 	snd_ac97_write_cache(ac97, AC97_AD_SERIAL_CFG, val);
15601da177e4SLinus Torvalds 	codecs[0] = patch_ad1881_unchained(ac97, 0, (1<<12));
15611da177e4SLinus Torvalds 	codecs[1] = patch_ad1881_unchained(ac97, 1, (1<<14));
15621da177e4SLinus Torvalds 	codecs[2] = patch_ad1881_unchained(ac97, 2, (1<<13));
15631da177e4SLinus Torvalds 
15647c22f1aaSTakashi Iwai 	if (! (codecs[0] || codecs[1] || codecs[2]))
15657c22f1aaSTakashi Iwai 		goto __end;
15661da177e4SLinus Torvalds 
15671da177e4SLinus Torvalds 	for (idx = 0; idx < 3; idx++)
15681da177e4SLinus Torvalds 		if (ac97->spec.ad18xx.unchained[idx])
15691da177e4SLinus Torvalds 			patch_ad1881_chained(ac97, idx, cfg_idxs[idx][0], cfg_idxs[idx][1]);
15701da177e4SLinus Torvalds 
15711da177e4SLinus Torvalds 	if (ac97->spec.ad18xx.id[1]) {
15721da177e4SLinus Torvalds 		ac97->flags |= AC97_AD_MULTI;
15731da177e4SLinus Torvalds 		ac97->scaps |= AC97_SCAP_SURROUND_DAC;
15741da177e4SLinus Torvalds 	}
15751da177e4SLinus Torvalds 	if (ac97->spec.ad18xx.id[2]) {
15761da177e4SLinus Torvalds 		ac97->flags |= AC97_AD_MULTI;
15771da177e4SLinus Torvalds 		ac97->scaps |= AC97_SCAP_CENTER_LFE_DAC;
15781da177e4SLinus Torvalds 	}
15791da177e4SLinus Torvalds 
15801da177e4SLinus Torvalds       __end:
15811da177e4SLinus Torvalds 	/* select all codecs */
15821da177e4SLinus Torvalds 	snd_ac97_update_bits(ac97, AC97_AD_SERIAL_CFG, 0x7000, 0x7000);
15831da177e4SLinus Torvalds 	/* check if only one codec is present */
15841da177e4SLinus Torvalds 	for (idx = num = 0; idx < 3; idx++)
15851da177e4SLinus Torvalds 		if (ac97->spec.ad18xx.id[idx])
15861da177e4SLinus Torvalds 			num++;
15871da177e4SLinus Torvalds 	if (num == 1) {
15881da177e4SLinus Torvalds 		/* ok, deselect all ID bits */
15891da177e4SLinus Torvalds 		snd_ac97_write_cache(ac97, AC97_AD_CODEC_CFG, 0x0000);
15901da177e4SLinus Torvalds 		ac97->spec.ad18xx.codec_cfg[0] =
15911da177e4SLinus Torvalds 			ac97->spec.ad18xx.codec_cfg[1] =
15921da177e4SLinus Torvalds 			ac97->spec.ad18xx.codec_cfg[2] = 0x0000;
15931da177e4SLinus Torvalds 	}
15941da177e4SLinus Torvalds 	/* required for AD1886/AD1885 combination */
15951da177e4SLinus Torvalds 	ac97->ext_id = snd_ac97_read(ac97, AC97_EXTENDED_ID);
15961da177e4SLinus Torvalds 	if (ac97->spec.ad18xx.id[0]) {
15971da177e4SLinus Torvalds 		ac97->id &= 0xffff0000;
15981da177e4SLinus Torvalds 		ac97->id |= ac97->spec.ad18xx.id[0];
15991da177e4SLinus Torvalds 	}
16001da177e4SLinus Torvalds 	ac97->build_ops = &patch_ad1881_build_ops;
16011da177e4SLinus Torvalds 	return 0;
16021da177e4SLinus Torvalds }
16031da177e4SLinus Torvalds 
1604ee42381eSTakashi Iwai static const struct snd_kcontrol_new snd_ac97_controls_ad1885[] = {
16051da177e4SLinus Torvalds 	AC97_SINGLE("Digital Mono Direct", AC97_AD_MISC, 11, 1, 0),
16061da177e4SLinus Torvalds 	/* AC97_SINGLE("Digital Audio Mode", AC97_AD_MISC, 12, 1, 0), */ /* seems problematic */
16071da177e4SLinus Torvalds 	AC97_SINGLE("Low Power Mixer", AC97_AD_MISC, 14, 1, 0),
16081da177e4SLinus Torvalds 	AC97_SINGLE("Zero Fill DAC", AC97_AD_MISC, 15, 1, 0),
16091da177e4SLinus Torvalds 	AC97_SINGLE("Headphone Jack Sense", AC97_AD_JACK_SPDIF, 9, 1, 1), /* inverted */
16101da177e4SLinus Torvalds 	AC97_SINGLE("Line Jack Sense", AC97_AD_JACK_SPDIF, 8, 1, 1), /* inverted */
16111da177e4SLinus Torvalds };
16121da177e4SLinus Torvalds 
16130cb29ea0STakashi Iwai static const DECLARE_TLV_DB_SCALE(db_scale_6bit_6db_max, -8850, 150, 0);
16142f3482fbSTakashi Iwai 
patch_ad1885_specific(struct snd_ac97 * ac97)1615ee42381eSTakashi Iwai static int patch_ad1885_specific(struct snd_ac97 * ac97)
16161da177e4SLinus Torvalds {
16171da177e4SLinus Torvalds 	int err;
16181da177e4SLinus Torvalds 
1619e66fd362STakashi Iwai 	err = patch_build_controls(ac97, snd_ac97_controls_ad1885, ARRAY_SIZE(snd_ac97_controls_ad1885));
1620e66fd362STakashi Iwai 	if (err < 0)
16211da177e4SLinus Torvalds 		return err;
16222f3482fbSTakashi Iwai 	reset_tlv(ac97, "Headphone Playback Volume",
16232f3482fbSTakashi Iwai 		  db_scale_6bit_6db_max);
16241da177e4SLinus Torvalds 	return 0;
16251da177e4SLinus Torvalds }
16261da177e4SLinus Torvalds 
16273e8b3b90SHanno Boeck static const struct snd_ac97_build_ops patch_ad1885_build_ops = {
16281da177e4SLinus Torvalds 	.build_specific = &patch_ad1885_specific,
16291da177e4SLinus Torvalds #ifdef CONFIG_PM
16301da177e4SLinus Torvalds 	.resume = ad18xx_resume
16311da177e4SLinus Torvalds #endif
16321da177e4SLinus Torvalds };
16331da177e4SLinus Torvalds 
patch_ad1885(struct snd_ac97 * ac97)1634ac519028STakashi Iwai static int patch_ad1885(struct snd_ac97 * ac97)
16351da177e4SLinus Torvalds {
16361da177e4SLinus Torvalds 	patch_ad1881(ac97);
16371da177e4SLinus Torvalds 	/* This is required to deal with the Intel D815EEAL2 */
16381da177e4SLinus Torvalds 	/* i.e. Line out is actually headphone out from codec */
16391da177e4SLinus Torvalds 
16401da177e4SLinus Torvalds 	/* set default */
16411da177e4SLinus Torvalds 	snd_ac97_write_cache(ac97, AC97_AD_MISC, 0x0404);
16421da177e4SLinus Torvalds 
16431da177e4SLinus Torvalds 	ac97->build_ops = &patch_ad1885_build_ops;
16441da177e4SLinus Torvalds 	return 0;
16451da177e4SLinus Torvalds }
16461da177e4SLinus Torvalds 
patch_ad1886_specific(struct snd_ac97 * ac97)16472f3482fbSTakashi Iwai static int patch_ad1886_specific(struct snd_ac97 * ac97)
16482f3482fbSTakashi Iwai {
16492f3482fbSTakashi Iwai 	reset_tlv(ac97, "Headphone Playback Volume",
16502f3482fbSTakashi Iwai 		  db_scale_6bit_6db_max);
16512f3482fbSTakashi Iwai 	return 0;
16522f3482fbSTakashi Iwai }
16532f3482fbSTakashi Iwai 
16543e8b3b90SHanno Boeck static const struct snd_ac97_build_ops patch_ad1886_build_ops = {
16552f3482fbSTakashi Iwai 	.build_specific = &patch_ad1886_specific,
16562f3482fbSTakashi Iwai #ifdef CONFIG_PM
16572f3482fbSTakashi Iwai 	.resume = ad18xx_resume
16582f3482fbSTakashi Iwai #endif
16592f3482fbSTakashi Iwai };
16602f3482fbSTakashi Iwai 
patch_ad1886(struct snd_ac97 * ac97)1661ac519028STakashi Iwai static int patch_ad1886(struct snd_ac97 * ac97)
16621da177e4SLinus Torvalds {
16631da177e4SLinus Torvalds 	patch_ad1881(ac97);
16641da177e4SLinus Torvalds 	/* Presario700 workaround */
16651da177e4SLinus Torvalds 	/* for Jack Sense/SPDIF Register misetting causing */
16661da177e4SLinus Torvalds 	snd_ac97_write_cache(ac97, AC97_AD_JACK_SPDIF, 0x0010);
16672f3482fbSTakashi Iwai 	ac97->build_ops = &patch_ad1886_build_ops;
16681da177e4SLinus Torvalds 	return 0;
16691da177e4SLinus Torvalds }
16701da177e4SLinus Torvalds 
167167e9f4b6SRandy Cushman /* MISC bits (AD1888/AD1980/AD1985 register 0x76) */
16721da177e4SLinus Torvalds #define AC97_AD198X_MBC		0x0003	/* mic boost */
16731da177e4SLinus Torvalds #define AC97_AD198X_MBC_20	0x0000	/* +20dB */
16741da177e4SLinus Torvalds #define AC97_AD198X_MBC_10	0x0001	/* +10dB */
16751da177e4SLinus Torvalds #define AC97_AD198X_MBC_30	0x0002	/* +30dB */
16761da177e4SLinus Torvalds #define AC97_AD198X_VREFD	0x0004	/* VREF high-Z */
16776428ea1bSRandy Cushman #define AC97_AD198X_VREFH	0x0008	/* 0=2.25V, 1=3.7V */
16786428ea1bSRandy Cushman #define AC97_AD198X_VREF_0	0x000c	/* 0V (AD1985 only) */
16796428ea1bSRandy Cushman #define AC97_AD198X_VREF_MASK	(AC97_AD198X_VREFH | AC97_AD198X_VREFD)
16806428ea1bSRandy Cushman #define AC97_AD198X_VREF_SHIFT	2
16811da177e4SLinus Torvalds #define AC97_AD198X_SRU		0x0010	/* sample rate unlock */
16821da177e4SLinus Torvalds #define AC97_AD198X_LOSEL	0x0020	/* LINE_OUT amplifiers input select */
16831da177e4SLinus Torvalds #define AC97_AD198X_2MIC	0x0040	/* 2-channel mic select */
16841da177e4SLinus Torvalds #define AC97_AD198X_SPRD	0x0080	/* SPREAD enable */
16856428ea1bSRandy Cushman #define AC97_AD198X_DMIX0	0x0100	/* downmix mode: */
16866428ea1bSRandy Cushman 					/*  0 = 6-to-4, 1 = 6-to-2 downmix */
16871da177e4SLinus Torvalds #define AC97_AD198X_DMIX1	0x0200	/* downmix mode: 1 = enabled */
16881da177e4SLinus Torvalds #define AC97_AD198X_HPSEL	0x0400	/* headphone amplifier input select */
16891da177e4SLinus Torvalds #define AC97_AD198X_CLDIS	0x0800	/* center/lfe disable */
16901da177e4SLinus Torvalds #define AC97_AD198X_LODIS	0x1000	/* LINE_OUT disable */
16911da177e4SLinus Torvalds #define AC97_AD198X_MSPLT	0x2000	/* mute split */
16921da177e4SLinus Torvalds #define AC97_AD198X_AC97NC	0x4000	/* AC97 no compatible mode */
16931da177e4SLinus Torvalds #define AC97_AD198X_DACZ	0x8000	/* DAC zero-fill mode */
16941da177e4SLinus Torvalds 
169567e9f4b6SRandy Cushman /* MISC 1 bits (AD1986 register 0x76) */
169667e9f4b6SRandy Cushman #define AC97_AD1986_MBC		0x0003	/* mic boost */
169767e9f4b6SRandy Cushman #define AC97_AD1986_MBC_20	0x0000	/* +20dB */
169867e9f4b6SRandy Cushman #define AC97_AD1986_MBC_10	0x0001	/* +10dB */
169967e9f4b6SRandy Cushman #define AC97_AD1986_MBC_30	0x0002	/* +30dB */
170067e9f4b6SRandy Cushman #define AC97_AD1986_LISEL0	0x0004	/* LINE_IN select bit 0 */
170167e9f4b6SRandy Cushman #define AC97_AD1986_LISEL1	0x0008	/* LINE_IN select bit 1 */
170267e9f4b6SRandy Cushman #define AC97_AD1986_LISEL_MASK	(AC97_AD1986_LISEL1 | AC97_AD1986_LISEL0)
170367e9f4b6SRandy Cushman #define AC97_AD1986_LISEL_LI	0x0000  /* LINE_IN pins as LINE_IN source */
170467e9f4b6SRandy Cushman #define AC97_AD1986_LISEL_SURR	0x0004  /* SURROUND pins as LINE_IN source */
170567e9f4b6SRandy Cushman #define AC97_AD1986_LISEL_MIC	0x0008  /* MIC_1/2 pins as LINE_IN source */
170667e9f4b6SRandy Cushman #define AC97_AD1986_SRU		0x0010	/* sample rate unlock */
170767e9f4b6SRandy Cushman #define AC97_AD1986_SOSEL	0x0020	/* SURROUND_OUT amplifiers input sel */
170867e9f4b6SRandy Cushman #define AC97_AD1986_2MIC	0x0040	/* 2-channel mic select */
170967e9f4b6SRandy Cushman #define AC97_AD1986_SPRD	0x0080	/* SPREAD enable */
171067e9f4b6SRandy Cushman #define AC97_AD1986_DMIX0	0x0100	/* downmix mode: */
171167e9f4b6SRandy Cushman 					/*  0 = 6-to-4, 1 = 6-to-2 downmix */
171267e9f4b6SRandy Cushman #define AC97_AD1986_DMIX1	0x0200	/* downmix mode: 1 = enabled */
171367e9f4b6SRandy Cushman #define AC97_AD1986_CLDIS	0x0800	/* center/lfe disable */
171467e9f4b6SRandy Cushman #define AC97_AD1986_SODIS	0x1000	/* SURROUND_OUT disable */
171567e9f4b6SRandy Cushman #define AC97_AD1986_MSPLT	0x2000	/* mute split (read only 1) */
171667e9f4b6SRandy Cushman #define AC97_AD1986_AC97NC	0x4000	/* AC97 no compatible mode (r/o 1) */
171767e9f4b6SRandy Cushman #define AC97_AD1986_DACZ	0x8000	/* DAC zero-fill mode */
171867e9f4b6SRandy Cushman 
171967e9f4b6SRandy Cushman /* MISC 2 bits (AD1986 register 0x70) */
172067e9f4b6SRandy Cushman #define AC97_AD_MISC2		0x70	/* Misc Control Bits 2 (AD1986) */
172167e9f4b6SRandy Cushman 
172267e9f4b6SRandy Cushman #define AC97_AD1986_CVREF0	0x0004	/* C/LFE VREF_OUT 2.25V */
172367e9f4b6SRandy Cushman #define AC97_AD1986_CVREF1	0x0008	/* C/LFE VREF_OUT 0V */
172467e9f4b6SRandy Cushman #define AC97_AD1986_CVREF2	0x0010	/* C/LFE VREF_OUT 3.7V */
172567e9f4b6SRandy Cushman #define AC97_AD1986_CVREF_MASK \
172667e9f4b6SRandy Cushman 	(AC97_AD1986_CVREF2 | AC97_AD1986_CVREF1 | AC97_AD1986_CVREF0)
172767e9f4b6SRandy Cushman #define AC97_AD1986_JSMAP	0x0020	/* Jack Sense Mapping 1 = alternate */
172867e9f4b6SRandy Cushman #define AC97_AD1986_MMDIS	0x0080	/* Mono Mute Disable */
172967e9f4b6SRandy Cushman #define AC97_AD1986_MVREF0	0x0400	/* MIC VREF_OUT 2.25V */
173067e9f4b6SRandy Cushman #define AC97_AD1986_MVREF1	0x0800	/* MIC VREF_OUT 0V */
173167e9f4b6SRandy Cushman #define AC97_AD1986_MVREF2	0x1000	/* MIC VREF_OUT 3.7V */
173267e9f4b6SRandy Cushman #define AC97_AD1986_MVREF_MASK \
173367e9f4b6SRandy Cushman 	(AC97_AD1986_MVREF2 | AC97_AD1986_MVREF1 | AC97_AD1986_MVREF0)
173467e9f4b6SRandy Cushman 
173567e9f4b6SRandy Cushman /* MISC 3 bits (AD1986 register 0x7a) */
173667e9f4b6SRandy Cushman #define AC97_AD_MISC3		0x7a	/* Misc Control Bits 3 (AD1986) */
173767e9f4b6SRandy Cushman 
173867e9f4b6SRandy Cushman #define AC97_AD1986_MMIX	0x0004	/* Mic Mix, left/right */
173967e9f4b6SRandy Cushman #define AC97_AD1986_GPO		0x0008	/* General Purpose Out */
174067e9f4b6SRandy Cushman #define AC97_AD1986_LOHPEN	0x0010	/* LINE_OUT headphone drive */
174167e9f4b6SRandy Cushman #define AC97_AD1986_LVREF0	0x0100	/* LINE_OUT VREF_OUT 2.25V */
174267e9f4b6SRandy Cushman #define AC97_AD1986_LVREF1	0x0200	/* LINE_OUT VREF_OUT 0V */
174367e9f4b6SRandy Cushman #define AC97_AD1986_LVREF2	0x0400	/* LINE_OUT VREF_OUT 3.7V */
174467e9f4b6SRandy Cushman #define AC97_AD1986_LVREF_MASK \
174567e9f4b6SRandy Cushman 	(AC97_AD1986_LVREF2 | AC97_AD1986_LVREF1 | AC97_AD1986_LVREF0)
174667e9f4b6SRandy Cushman #define AC97_AD1986_JSINVA	0x0800	/* Jack Sense Invert SENSE_A */
174767e9f4b6SRandy Cushman #define AC97_AD1986_LOSEL	0x1000	/* LINE_OUT amplifiers input select */
174867e9f4b6SRandy Cushman #define AC97_AD1986_HPSEL0	0x2000	/* Headphone amplifiers */
174967e9f4b6SRandy Cushman 					/*   input select Surround DACs */
175067e9f4b6SRandy Cushman #define AC97_AD1986_HPSEL1	0x4000	/* Headphone amplifiers input */
175167e9f4b6SRandy Cushman 					/*   select C/LFE DACs */
175267e9f4b6SRandy Cushman #define AC97_AD1986_JSINVB	0x8000	/* Jack Sense Invert SENSE_B */
175367e9f4b6SRandy Cushman 
175467e9f4b6SRandy Cushman /* Serial Config bits (AD1986 register 0x74) (incomplete) */
175567e9f4b6SRandy Cushman #define AC97_AD1986_OMS0	0x0100	/* Optional Mic Selector bit 0 */
175667e9f4b6SRandy Cushman #define AC97_AD1986_OMS1	0x0200	/* Optional Mic Selector bit 1 */
175767e9f4b6SRandy Cushman #define AC97_AD1986_OMS2	0x0400	/* Optional Mic Selector bit 2 */
175867e9f4b6SRandy Cushman #define AC97_AD1986_OMS_MASK \
175967e9f4b6SRandy Cushman 	(AC97_AD1986_OMS2 | AC97_AD1986_OMS1 | AC97_AD1986_OMS0)
176067e9f4b6SRandy Cushman #define AC97_AD1986_OMS_M	0x0000  /* MIC_1/2 pins are MIC sources */
176167e9f4b6SRandy Cushman #define AC97_AD1986_OMS_L	0x0100  /* LINE_IN pins are MIC sources */
176267e9f4b6SRandy Cushman #define AC97_AD1986_OMS_C	0x0200  /* Center/LFE pins are MCI sources */
176367e9f4b6SRandy Cushman #define AC97_AD1986_OMS_MC	0x0400  /* Mix of MIC and C/LFE pins */
176467e9f4b6SRandy Cushman 					/*   are MIC sources */
176567e9f4b6SRandy Cushman #define AC97_AD1986_OMS_ML	0x0500  /* MIX of MIC and LINE_IN pins */
176667e9f4b6SRandy Cushman 					/*   are MIC sources */
176767e9f4b6SRandy Cushman #define AC97_AD1986_OMS_LC	0x0600  /* MIX of LINE_IN and C/LFE pins */
176867e9f4b6SRandy Cushman 					/*   are MIC sources */
176967e9f4b6SRandy Cushman #define AC97_AD1986_OMS_MLC	0x0700  /* MIX of MIC, LINE_IN, C/LFE pins */
177067e9f4b6SRandy Cushman 					/*   are MIC sources */
177167e9f4b6SRandy Cushman 
17721da177e4SLinus Torvalds 
snd_ac97_ad198x_spdif_source_info(struct snd_kcontrol * kcontrol,struct snd_ctl_elem_info * uinfo)1773ee42381eSTakashi Iwai static int snd_ac97_ad198x_spdif_source_info(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_info *uinfo)
17741da177e4SLinus Torvalds {
17753b7a00dcSTakashi Iwai 	static const char * const texts[2] = { "AC-Link", "A/D Converter" };
17761da177e4SLinus Torvalds 
17773b7a00dcSTakashi Iwai 	return snd_ctl_enum_info(uinfo, 1, 2, texts);
17781da177e4SLinus Torvalds }
17791da177e4SLinus Torvalds 
snd_ac97_ad198x_spdif_source_get(struct snd_kcontrol * kcontrol,struct snd_ctl_elem_value * ucontrol)1780ee42381eSTakashi Iwai static int snd_ac97_ad198x_spdif_source_get(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 	val = ac97->regs[AC97_AD_SERIAL_CFG];
17861da177e4SLinus Torvalds 	ucontrol->value.enumerated.item[0] = (val >> 2) & 1;
17871da177e4SLinus Torvalds 	return 0;
17881da177e4SLinus Torvalds }
17891da177e4SLinus Torvalds 
snd_ac97_ad198x_spdif_source_put(struct snd_kcontrol * kcontrol,struct snd_ctl_elem_value * ucontrol)1790ee42381eSTakashi Iwai static int snd_ac97_ad198x_spdif_source_put(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
17911da177e4SLinus Torvalds {
1792ee42381eSTakashi Iwai 	struct snd_ac97 *ac97 = snd_kcontrol_chip(kcontrol);
17931da177e4SLinus Torvalds 	unsigned short val;
17941da177e4SLinus Torvalds 
17951da177e4SLinus Torvalds 	if (ucontrol->value.enumerated.item[0] > 1)
17961da177e4SLinus Torvalds 		return -EINVAL;
17971da177e4SLinus Torvalds 	val = ucontrol->value.enumerated.item[0] << 2;
17981da177e4SLinus Torvalds 	return snd_ac97_update_bits(ac97, AC97_AD_SERIAL_CFG, 0x0004, val);
17991da177e4SLinus Torvalds }
18001da177e4SLinus Torvalds 
1801ee42381eSTakashi Iwai static const struct snd_kcontrol_new snd_ac97_ad198x_spdif_source = {
18021da177e4SLinus Torvalds 	.iface	= SNDRV_CTL_ELEM_IFACE_MIXER,
18031da177e4SLinus Torvalds 	.name	= SNDRV_CTL_NAME_IEC958("",PLAYBACK,NONE) "Source",
18041da177e4SLinus Torvalds 	.info	= snd_ac97_ad198x_spdif_source_info,
18051da177e4SLinus Torvalds 	.get	= snd_ac97_ad198x_spdif_source_get,
18061da177e4SLinus Torvalds 	.put	= snd_ac97_ad198x_spdif_source_put,
18071da177e4SLinus Torvalds };
18081da177e4SLinus Torvalds 
patch_ad198x_post_spdif(struct snd_ac97 * ac97)1809ee42381eSTakashi Iwai static int patch_ad198x_post_spdif(struct snd_ac97 * ac97)
18101da177e4SLinus Torvalds {
18111da177e4SLinus Torvalds  	return patch_build_controls(ac97, &snd_ac97_ad198x_spdif_source, 1);
18121da177e4SLinus Torvalds }
18131da177e4SLinus Torvalds 
1814ee42381eSTakashi Iwai static const struct snd_kcontrol_new snd_ac97_ad1981x_jack_sense[] = {
18151da177e4SLinus Torvalds 	AC97_SINGLE("Headphone Jack Sense", AC97_AD_JACK_SPDIF, 11, 1, 0),
18161da177e4SLinus Torvalds 	AC97_SINGLE("Line Jack Sense", AC97_AD_JACK_SPDIF, 12, 1, 0),
18171da177e4SLinus Torvalds };
18181da177e4SLinus Torvalds 
18197933d669STakashi Iwai /* deny list to avoid HP/Line jack-sense controls
1820128a46a5STakashi Iwai  * (SS vendor << 16 | device)
1821128a46a5STakashi Iwai  */
18227933d669STakashi Iwai static const unsigned int ad1981_jacks_denylist[] = {
1823a31e8c72STakashi Iwai 	0x10140523, /* Thinkpad R40 */
1824a31e8c72STakashi Iwai 	0x10140534, /* Thinkpad X31 */
1825a43c4d4dSTakashi Iwai 	0x10140537, /* Thinkpad T41p */
1826e1f7f02bSDaniel T Chen 	0x1014053e, /* Thinkpad R40e */
1827128a46a5STakashi Iwai 	0x10140554, /* Thinkpad T42p/R50p */
18288286c53eSDaniel T Chen 	0x10140567, /* Thinkpad T43p 2668-G7U */
18298286c53eSDaniel T Chen 	0x10140581, /* Thinkpad X41-2527 */
1830af9a75ddSDaniel T Chen 	0x10280160, /* Dell Dimension 2400 */
18318286c53eSDaniel T Chen 	0x104380b0, /* Asus A7V8X-MX */
18328286c53eSDaniel T Chen 	0x11790241, /* Toshiba Satellite A-15 S127 */
18335cd165e7SDaniel Chen 	0x1179ff10, /* Toshiba P500 */
18348286c53eSDaniel T Chen 	0x144dc01a, /* Samsung NP-X20C004/SEG */
1835128a46a5STakashi Iwai 	0 /* end */
1836128a46a5STakashi Iwai };
1837128a46a5STakashi Iwai 
check_list(struct snd_ac97 * ac97,const unsigned int * list)1838128a46a5STakashi Iwai static int check_list(struct snd_ac97 *ac97, const unsigned int *list)
1839128a46a5STakashi Iwai {
1840128a46a5STakashi Iwai 	u32 subid = ((u32)ac97->subsystem_vendor << 16) | ac97->subsystem_device;
1841128a46a5STakashi Iwai 	for (; *list; list++)
1842128a46a5STakashi Iwai 		if (*list == subid)
1843128a46a5STakashi Iwai 			return 1;
1844128a46a5STakashi Iwai 	return 0;
1845128a46a5STakashi Iwai }
1846128a46a5STakashi Iwai 
patch_ad1981a_specific(struct snd_ac97 * ac97)1847ee42381eSTakashi Iwai static int patch_ad1981a_specific(struct snd_ac97 * ac97)
18481da177e4SLinus Torvalds {
18497933d669STakashi Iwai 	if (check_list(ac97, ad1981_jacks_denylist))
1850128a46a5STakashi Iwai 		return 0;
18511da177e4SLinus Torvalds 	return patch_build_controls(ac97, snd_ac97_ad1981x_jack_sense,
18521da177e4SLinus Torvalds 				    ARRAY_SIZE(snd_ac97_ad1981x_jack_sense));
18531da177e4SLinus Torvalds }
18541da177e4SLinus Torvalds 
18553e8b3b90SHanno Boeck static const struct snd_ac97_build_ops patch_ad1981a_build_ops = {
18561da177e4SLinus Torvalds 	.build_post_spdif = patch_ad198x_post_spdif,
18571da177e4SLinus Torvalds 	.build_specific = patch_ad1981a_specific,
18581da177e4SLinus Torvalds #ifdef CONFIG_PM
18591da177e4SLinus Torvalds 	.resume = ad18xx_resume
18601da177e4SLinus Torvalds #endif
18611da177e4SLinus Torvalds };
18621da177e4SLinus Torvalds 
18637933d669STakashi Iwai /* allow list to enable HP jack-sense bits
1864128a46a5STakashi Iwai  * (SS vendor << 16 | device)
1865128a46a5STakashi Iwai  */
18667933d669STakashi Iwai static const unsigned int ad1981_jacks_allowlist[] = {
1867128a46a5STakashi Iwai 	0x0e11005a, /* HP nc4000/4010 */
1868128a46a5STakashi Iwai 	0x103c0890, /* HP nc6000 */
1869128a46a5STakashi Iwai 	0x103c0938, /* HP nc4220 */
1870128a46a5STakashi Iwai 	0x103c099c, /* HP nx6110 */
1871128a46a5STakashi Iwai 	0x103c0944, /* HP nc6220 */
1872128a46a5STakashi Iwai 	0x103c0934, /* HP nc8220 */
1873128a46a5STakashi Iwai 	0x103c006d, /* HP nx9105 */
1874eade7b28SDaniel T Chen 	0x103c300d, /* HP Compaq dc5100 SFF(PT003AW) */
1875128a46a5STakashi Iwai 	0x17340088, /* FSC Scenic-W */
1876128a46a5STakashi Iwai 	0 /* end */
1877128a46a5STakashi Iwai };
1878128a46a5STakashi Iwai 
check_ad1981_hp_jack_sense(struct snd_ac97 * ac97)1879ee42381eSTakashi Iwai static void check_ad1981_hp_jack_sense(struct snd_ac97 *ac97)
18801da177e4SLinus Torvalds {
18817933d669STakashi Iwai 	if (check_list(ac97, ad1981_jacks_allowlist))
18821da177e4SLinus Torvalds 		/* enable headphone jack sense */
18831da177e4SLinus Torvalds 		snd_ac97_update_bits(ac97, AC97_AD_JACK_SPDIF, 1<<11, 1<<11);
18841da177e4SLinus Torvalds }
18851da177e4SLinus Torvalds 
patch_ad1981a(struct snd_ac97 * ac97)1886ac519028STakashi Iwai static int patch_ad1981a(struct snd_ac97 *ac97)
18871da177e4SLinus Torvalds {
18881da177e4SLinus Torvalds 	patch_ad1881(ac97);
18891da177e4SLinus Torvalds 	ac97->build_ops = &patch_ad1981a_build_ops;
18901da177e4SLinus Torvalds 	snd_ac97_update_bits(ac97, AC97_AD_MISC, AC97_AD198X_MSPLT, AC97_AD198X_MSPLT);
18911da177e4SLinus Torvalds 	ac97->flags |= AC97_STEREO_MUTES;
18921da177e4SLinus Torvalds 	check_ad1981_hp_jack_sense(ac97);
18931da177e4SLinus Torvalds 	return 0;
18941da177e4SLinus Torvalds }
18951da177e4SLinus Torvalds 
1896ee42381eSTakashi Iwai static const struct snd_kcontrol_new snd_ac97_ad198x_2cmic =
18971da177e4SLinus Torvalds AC97_SINGLE("Stereo Mic", AC97_AD_MISC, 6, 1, 0);
18981da177e4SLinus Torvalds 
patch_ad1981b_specific(struct snd_ac97 * ac97)1899ee42381eSTakashi Iwai static int patch_ad1981b_specific(struct snd_ac97 *ac97)
19001da177e4SLinus Torvalds {
19011da177e4SLinus Torvalds 	int err;
19021da177e4SLinus Torvalds 
1903e66fd362STakashi Iwai 	err = patch_build_controls(ac97, &snd_ac97_ad198x_2cmic, 1);
1904e66fd362STakashi Iwai 	if (err < 0)
19051da177e4SLinus Torvalds 		return err;
19067933d669STakashi Iwai 	if (check_list(ac97, ad1981_jacks_denylist))
1907128a46a5STakashi Iwai 		return 0;
19081da177e4SLinus Torvalds 	return patch_build_controls(ac97, snd_ac97_ad1981x_jack_sense,
19091da177e4SLinus Torvalds 				    ARRAY_SIZE(snd_ac97_ad1981x_jack_sense));
19101da177e4SLinus Torvalds }
19111da177e4SLinus Torvalds 
19123e8b3b90SHanno Boeck static const struct snd_ac97_build_ops patch_ad1981b_build_ops = {
19131da177e4SLinus Torvalds 	.build_post_spdif = patch_ad198x_post_spdif,
19141da177e4SLinus Torvalds 	.build_specific = patch_ad1981b_specific,
19151da177e4SLinus Torvalds #ifdef CONFIG_PM
19161da177e4SLinus Torvalds 	.resume = ad18xx_resume
19171da177e4SLinus Torvalds #endif
19181da177e4SLinus Torvalds };
19191da177e4SLinus Torvalds 
patch_ad1981b(struct snd_ac97 * ac97)1920ac519028STakashi Iwai static int patch_ad1981b(struct snd_ac97 *ac97)
19211da177e4SLinus Torvalds {
19221da177e4SLinus Torvalds 	patch_ad1881(ac97);
19231da177e4SLinus Torvalds 	ac97->build_ops = &patch_ad1981b_build_ops;
19241da177e4SLinus Torvalds 	snd_ac97_update_bits(ac97, AC97_AD_MISC, AC97_AD198X_MSPLT, AC97_AD198X_MSPLT);
19251da177e4SLinus Torvalds 	ac97->flags |= AC97_STEREO_MUTES;
19261da177e4SLinus Torvalds 	check_ad1981_hp_jack_sense(ac97);
19271da177e4SLinus Torvalds 	return 0;
19281da177e4SLinus Torvalds }
19291da177e4SLinus Torvalds 
1930a5ce8890STakashi Iwai #define snd_ac97_ad1888_lohpsel_info	snd_ctl_boolean_mono_info
19311da177e4SLinus Torvalds 
snd_ac97_ad1888_lohpsel_get(struct snd_kcontrol * kcontrol,struct snd_ctl_elem_value * ucontrol)1932ee42381eSTakashi Iwai static int snd_ac97_ad1888_lohpsel_get(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
19331da177e4SLinus Torvalds {
1934ee42381eSTakashi Iwai 	struct snd_ac97 *ac97 = snd_kcontrol_chip(kcontrol);
19351da177e4SLinus Torvalds 	unsigned short val;
19361da177e4SLinus Torvalds 
19371da177e4SLinus Torvalds 	val = ac97->regs[AC97_AD_MISC];
19381da177e4SLinus Torvalds 	ucontrol->value.integer.value[0] = !(val & AC97_AD198X_LOSEL);
1939e48d6d97STakashi Iwai 	if (ac97->spec.ad18xx.lo_as_master)
1940e48d6d97STakashi Iwai 		ucontrol->value.integer.value[0] =
1941e48d6d97STakashi Iwai 			!ucontrol->value.integer.value[0];
19421da177e4SLinus Torvalds 	return 0;
19431da177e4SLinus Torvalds }
19441da177e4SLinus Torvalds 
snd_ac97_ad1888_lohpsel_put(struct snd_kcontrol * kcontrol,struct snd_ctl_elem_value * ucontrol)1945ee42381eSTakashi Iwai static int snd_ac97_ad1888_lohpsel_put(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
19461da177e4SLinus Torvalds {
1947ee42381eSTakashi Iwai 	struct snd_ac97 *ac97 = snd_kcontrol_chip(kcontrol);
19481da177e4SLinus Torvalds 	unsigned short val;
19491da177e4SLinus Torvalds 
1950e48d6d97STakashi Iwai 	val = !ucontrol->value.integer.value[0];
1951e48d6d97STakashi Iwai 	if (ac97->spec.ad18xx.lo_as_master)
1952e48d6d97STakashi Iwai 		val = !val;
1953e48d6d97STakashi Iwai 	val = val ? (AC97_AD198X_LOSEL | AC97_AD198X_HPSEL) : 0;
19541da177e4SLinus Torvalds 	return snd_ac97_update_bits(ac97, AC97_AD_MISC,
19551da177e4SLinus Torvalds 				    AC97_AD198X_LOSEL | AC97_AD198X_HPSEL, val);
19561da177e4SLinus Torvalds }
19571da177e4SLinus Torvalds 
snd_ac97_ad1888_downmix_info(struct snd_kcontrol * kcontrol,struct snd_ctl_elem_info * uinfo)1958ee42381eSTakashi Iwai static int snd_ac97_ad1888_downmix_info(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_info *uinfo)
19591da177e4SLinus Torvalds {
19603b7a00dcSTakashi Iwai 	static const char * const texts[3] = {"Off", "6 -> 4", "6 -> 2"};
19611da177e4SLinus Torvalds 
19623b7a00dcSTakashi Iwai 	return snd_ctl_enum_info(uinfo, 1, 3, texts);
19631da177e4SLinus Torvalds }
19641da177e4SLinus Torvalds 
snd_ac97_ad1888_downmix_get(struct snd_kcontrol * kcontrol,struct snd_ctl_elem_value * ucontrol)1965ee42381eSTakashi Iwai static int snd_ac97_ad1888_downmix_get(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
19661da177e4SLinus Torvalds {
1967ee42381eSTakashi Iwai 	struct snd_ac97 *ac97 = snd_kcontrol_chip(kcontrol);
19681da177e4SLinus Torvalds 	unsigned short val;
19691da177e4SLinus Torvalds 
19701da177e4SLinus Torvalds 	val = ac97->regs[AC97_AD_MISC];
19711da177e4SLinus Torvalds 	if (!(val & AC97_AD198X_DMIX1))
19721da177e4SLinus Torvalds 		ucontrol->value.enumerated.item[0] = 0;
19731da177e4SLinus Torvalds 	else
19741da177e4SLinus Torvalds 		ucontrol->value.enumerated.item[0] = 1 + ((val >> 8) & 1);
19751da177e4SLinus Torvalds 	return 0;
19761da177e4SLinus Torvalds }
19771da177e4SLinus Torvalds 
snd_ac97_ad1888_downmix_put(struct snd_kcontrol * kcontrol,struct snd_ctl_elem_value * ucontrol)1978ee42381eSTakashi Iwai static int snd_ac97_ad1888_downmix_put(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
19791da177e4SLinus Torvalds {
1980ee42381eSTakashi Iwai 	struct snd_ac97 *ac97 = snd_kcontrol_chip(kcontrol);
19811da177e4SLinus Torvalds 	unsigned short val;
19821da177e4SLinus Torvalds 
19831da177e4SLinus Torvalds 	if (ucontrol->value.enumerated.item[0] > 2)
19841da177e4SLinus Torvalds 		return -EINVAL;
19851da177e4SLinus Torvalds 	if (ucontrol->value.enumerated.item[0] == 0)
19861da177e4SLinus Torvalds 		val = 0;
19871da177e4SLinus Torvalds 	else
19881da177e4SLinus Torvalds 		val = AC97_AD198X_DMIX1 |
19891da177e4SLinus Torvalds 			((ucontrol->value.enumerated.item[0] - 1) << 8);
19901da177e4SLinus Torvalds 	return snd_ac97_update_bits(ac97, AC97_AD_MISC,
19911da177e4SLinus Torvalds 				    AC97_AD198X_DMIX0 | AC97_AD198X_DMIX1, val);
19921da177e4SLinus Torvalds }
19931da177e4SLinus Torvalds 
ad1888_update_jacks(struct snd_ac97 * ac97)1994ee42381eSTakashi Iwai static void ad1888_update_jacks(struct snd_ac97 *ac97)
1995eb8caf30STakashi Iwai {
19964525c9f3STakashi Iwai 	unsigned short val = 0;
1997c26a8de2SRandy Cushman 	/* clear LODIS if shared jack is to be used for Surround out */
1998e48d6d97STakashi Iwai 	if (!ac97->spec.ad18xx.lo_as_master && is_shared_linein(ac97))
19994525c9f3STakashi Iwai 		val |= (1 << 12);
2000c26a8de2SRandy Cushman 	/* clear CLDIS if shared jack is to be used for C/LFE out */
2001c26a8de2SRandy Cushman 	if (is_shared_micin(ac97))
20024525c9f3STakashi Iwai 		val |= (1 << 11);
2003eb8caf30STakashi Iwai 	/* shared Line-In */
20044525c9f3STakashi Iwai 	snd_ac97_update_bits(ac97, AC97_AD_MISC, (1 << 11) | (1 << 12), val);
2005eb8caf30STakashi Iwai }
2006eb8caf30STakashi Iwai 
2007ee42381eSTakashi Iwai static const struct snd_kcontrol_new snd_ac97_ad1888_controls[] = {
20081da177e4SLinus Torvalds 	{
20091da177e4SLinus Torvalds 		.iface = SNDRV_CTL_ELEM_IFACE_MIXER,
20101da177e4SLinus Torvalds 		.name = "Exchange Front/Surround",
20111da177e4SLinus Torvalds 		.info = snd_ac97_ad1888_lohpsel_info,
20121da177e4SLinus Torvalds 		.get = snd_ac97_ad1888_lohpsel_get,
20131da177e4SLinus Torvalds 		.put = snd_ac97_ad1888_lohpsel_put
20141da177e4SLinus Torvalds 	},
20150bed7b29SAndres Salomon 	AC97_SINGLE("V_REFOUT Enable", AC97_AD_MISC, AC97_AD_VREFD_SHIFT, 1, 1),
20160bed7b29SAndres Salomon 	AC97_SINGLE("High Pass Filter Enable", AC97_AD_TEST2,
20170bed7b29SAndres Salomon 			AC97_AD_HPFD_SHIFT, 1, 1),
20181da177e4SLinus Torvalds 	AC97_SINGLE("Spread Front to Surround and Center/LFE", AC97_AD_MISC, 7, 1, 0),
20191da177e4SLinus Torvalds 	{
20201da177e4SLinus Torvalds 		.iface = SNDRV_CTL_ELEM_IFACE_MIXER,
20211da177e4SLinus Torvalds 		.name = "Downmix",
20221da177e4SLinus Torvalds 		.info = snd_ac97_ad1888_downmix_info,
20231da177e4SLinus Torvalds 		.get = snd_ac97_ad1888_downmix_get,
20241da177e4SLinus Torvalds 		.put = snd_ac97_ad1888_downmix_put
20251da177e4SLinus Torvalds 	},
2026eb8caf30STakashi Iwai 	AC97_SURROUND_JACK_MODE_CTL,
2027eb8caf30STakashi Iwai 	AC97_CHANNEL_MODE_CTL,
2028eeacb545SSergey Ulanov 
2029eeacb545SSergey Ulanov 	AC97_SINGLE("Headphone Jack Sense", AC97_AD_JACK_SPDIF, 10, 1, 0),
2030eeacb545SSergey Ulanov 	AC97_SINGLE("Line Jack Sense", AC97_AD_JACK_SPDIF, 12, 1, 0),
20311da177e4SLinus Torvalds };
20321da177e4SLinus Torvalds 
patch_ad1888_specific(struct snd_ac97 * ac97)2033ee42381eSTakashi Iwai static int patch_ad1888_specific(struct snd_ac97 *ac97)
20341da177e4SLinus Torvalds {
2035e48d6d97STakashi Iwai 	if (!ac97->spec.ad18xx.lo_as_master) {
20361da177e4SLinus Torvalds 		/* rename 0x04 as "Master" and 0x02 as "Master Surround" */
2037e48d6d97STakashi Iwai 		snd_ac97_rename_vol_ctl(ac97, "Master Playback",
2038e48d6d97STakashi Iwai 					"Master Surround Playback");
2039e48d6d97STakashi Iwai 		snd_ac97_rename_vol_ctl(ac97, "Headphone Playback",
2040e48d6d97STakashi Iwai 					"Master Playback");
2041e48d6d97STakashi Iwai 	}
20421da177e4SLinus Torvalds 	return patch_build_controls(ac97, snd_ac97_ad1888_controls, ARRAY_SIZE(snd_ac97_ad1888_controls));
20431da177e4SLinus Torvalds }
20441da177e4SLinus Torvalds 
20453e8b3b90SHanno Boeck static const struct snd_ac97_build_ops patch_ad1888_build_ops = {
20461da177e4SLinus Torvalds 	.build_post_spdif = patch_ad198x_post_spdif,
20471da177e4SLinus Torvalds 	.build_specific = patch_ad1888_specific,
20481da177e4SLinus Torvalds #ifdef CONFIG_PM
20491561f09aSJaya Kumar 	.resume = ad1888_resume,
20501da177e4SLinus Torvalds #endif
2051eb8caf30STakashi Iwai 	.update_jacks = ad1888_update_jacks,
20521da177e4SLinus Torvalds };
20531da177e4SLinus Torvalds 
patch_ad1888(struct snd_ac97 * ac97)2054ac519028STakashi Iwai static int patch_ad1888(struct snd_ac97 * ac97)
20551da177e4SLinus Torvalds {
20561da177e4SLinus Torvalds 	unsigned short misc;
20571da177e4SLinus Torvalds 
20581da177e4SLinus Torvalds 	patch_ad1881(ac97);
20591da177e4SLinus Torvalds 	ac97->build_ops = &patch_ad1888_build_ops;
2060e48d6d97STakashi Iwai 
2061e48d6d97STakashi Iwai 	/*
2062e48d6d97STakashi Iwai 	 * LO can be used as a real line-out on some devices,
2063e48d6d97STakashi Iwai 	 * and we need to revert the front/surround mixer switches
2064e48d6d97STakashi Iwai 	 */
2065e48d6d97STakashi Iwai 	if (ac97->subsystem_vendor == 0x1043 &&
2066e48d6d97STakashi Iwai 	    ac97->subsystem_device == 0x1193) /* ASUS A9T laptop */
2067e48d6d97STakashi Iwai 		ac97->spec.ad18xx.lo_as_master = 1;
2068e48d6d97STakashi Iwai 
2069e48d6d97STakashi Iwai 	misc = snd_ac97_read(ac97, AC97_AD_MISC);
20701da177e4SLinus Torvalds 	/* AD-compatible mode */
20711da177e4SLinus Torvalds 	/* Stereo mutes enabled */
2072e48d6d97STakashi Iwai 	misc |= AC97_AD198X_MSPLT | AC97_AD198X_AC97NC;
2073e48d6d97STakashi Iwai 	if (!ac97->spec.ad18xx.lo_as_master)
2074e48d6d97STakashi Iwai 		/* Switch FRONT/SURROUND LINE-OUT/HP-OUT default connection */
2075e48d6d97STakashi Iwai 		/* it seems that most vendors connect line-out connector to
2076e48d6d97STakashi Iwai 		 * headphone out of AC'97
2077e48d6d97STakashi Iwai 		 */
2078e48d6d97STakashi Iwai 		misc |= AC97_AD198X_LOSEL | AC97_AD198X_HPSEL;
2079e48d6d97STakashi Iwai 
2080e48d6d97STakashi Iwai 	snd_ac97_write_cache(ac97, AC97_AD_MISC, misc);
20811da177e4SLinus Torvalds 	ac97->flags |= AC97_STEREO_MUTES;
20821da177e4SLinus Torvalds 	return 0;
20831da177e4SLinus Torvalds }
20841da177e4SLinus Torvalds 
patch_ad1980_specific(struct snd_ac97 * ac97)2085ee42381eSTakashi Iwai static int patch_ad1980_specific(struct snd_ac97 *ac97)
20861da177e4SLinus Torvalds {
20871da177e4SLinus Torvalds 	int err;
20881da177e4SLinus Torvalds 
2089e66fd362STakashi Iwai 	err = patch_ad1888_specific(ac97);
2090e66fd362STakashi Iwai 	if (err < 0)
20911da177e4SLinus Torvalds 		return err;
20921da177e4SLinus Torvalds 	return patch_build_controls(ac97, &snd_ac97_ad198x_2cmic, 1);
20931da177e4SLinus Torvalds }
20941da177e4SLinus Torvalds 
20953e8b3b90SHanno Boeck static const struct snd_ac97_build_ops patch_ad1980_build_ops = {
20961da177e4SLinus Torvalds 	.build_post_spdif = patch_ad198x_post_spdif,
20971da177e4SLinus Torvalds 	.build_specific = patch_ad1980_specific,
20981da177e4SLinus Torvalds #ifdef CONFIG_PM
2099462c4173SClemens Ladisch 	.resume = ad18xx_resume,
21001da177e4SLinus Torvalds #endif
2101462c4173SClemens Ladisch 	.update_jacks = ad1888_update_jacks,
21021da177e4SLinus Torvalds };
21031da177e4SLinus Torvalds 
patch_ad1980(struct snd_ac97 * ac97)2104ac519028STakashi Iwai static int patch_ad1980(struct snd_ac97 * ac97)
21051da177e4SLinus Torvalds {
21061da177e4SLinus Torvalds 	patch_ad1888(ac97);
21071da177e4SLinus Torvalds 	ac97->build_ops = &patch_ad1980_build_ops;
21081da177e4SLinus Torvalds 	return 0;
21091da177e4SLinus Torvalds }
21101da177e4SLinus Torvalds 
snd_ac97_ad1985_vrefout_info(struct snd_kcontrol * kcontrol,struct snd_ctl_elem_info * uinfo)21116428ea1bSRandy Cushman static int snd_ac97_ad1985_vrefout_info(struct snd_kcontrol *kcontrol,
21126428ea1bSRandy Cushman 					struct snd_ctl_elem_info *uinfo)
21136428ea1bSRandy Cushman {
21143b7a00dcSTakashi Iwai 	static const char * const texts[4] = {
21153b7a00dcSTakashi Iwai 		"High-Z", "3.7 V", "2.25 V", "0 V"
21163b7a00dcSTakashi Iwai 	};
21176428ea1bSRandy Cushman 
21183b7a00dcSTakashi Iwai 	return snd_ctl_enum_info(uinfo, 1, 4, texts);
21196428ea1bSRandy Cushman }
21206428ea1bSRandy Cushman 
snd_ac97_ad1985_vrefout_get(struct snd_kcontrol * kcontrol,struct snd_ctl_elem_value * ucontrol)21216428ea1bSRandy Cushman static int snd_ac97_ad1985_vrefout_get(struct snd_kcontrol *kcontrol,
21226428ea1bSRandy Cushman 				       struct snd_ctl_elem_value *ucontrol)
21236428ea1bSRandy Cushman {
21246428ea1bSRandy Cushman 	static const int reg2ctrl[4] = {2, 0, 1, 3};
21256428ea1bSRandy Cushman 	struct snd_ac97 *ac97 = snd_kcontrol_chip(kcontrol);
21266428ea1bSRandy Cushman 	unsigned short val;
21276428ea1bSRandy Cushman 	val = (ac97->regs[AC97_AD_MISC] & AC97_AD198X_VREF_MASK)
21286428ea1bSRandy Cushman 	      >> AC97_AD198X_VREF_SHIFT;
21296428ea1bSRandy Cushman 	ucontrol->value.enumerated.item[0] = reg2ctrl[val];
21306428ea1bSRandy Cushman 	return 0;
21316428ea1bSRandy Cushman }
21326428ea1bSRandy Cushman 
snd_ac97_ad1985_vrefout_put(struct snd_kcontrol * kcontrol,struct snd_ctl_elem_value * ucontrol)21336428ea1bSRandy Cushman static int snd_ac97_ad1985_vrefout_put(struct snd_kcontrol *kcontrol,
21346428ea1bSRandy Cushman 				       struct snd_ctl_elem_value *ucontrol)
21356428ea1bSRandy Cushman {
21366428ea1bSRandy Cushman 	static const int ctrl2reg[4] = {1, 2, 0, 3};
21376428ea1bSRandy Cushman 	struct snd_ac97 *ac97 = snd_kcontrol_chip(kcontrol);
21386428ea1bSRandy Cushman 	unsigned short val;
21396428ea1bSRandy Cushman 
21404e98d6a7STakashi Iwai 	if (ucontrol->value.enumerated.item[0] > 3)
21416428ea1bSRandy Cushman 		return -EINVAL;
21426428ea1bSRandy Cushman 	val = ctrl2reg[ucontrol->value.enumerated.item[0]]
21436428ea1bSRandy Cushman 	      << AC97_AD198X_VREF_SHIFT;
21446428ea1bSRandy Cushman 	return snd_ac97_update_bits(ac97, AC97_AD_MISC,
21456428ea1bSRandy Cushman 				    AC97_AD198X_VREF_MASK, val);
21466428ea1bSRandy Cushman }
21476428ea1bSRandy Cushman 
2148ee42381eSTakashi Iwai static const struct snd_kcontrol_new snd_ac97_ad1985_controls[] = {
21496428ea1bSRandy Cushman 	AC97_SINGLE("Exchange Center/LFE", AC97_AD_SERIAL_CFG, 3, 1, 0),
21506428ea1bSRandy Cushman 	{
21516428ea1bSRandy Cushman 		.iface = SNDRV_CTL_ELEM_IFACE_MIXER,
21526428ea1bSRandy Cushman 		.name = "Exchange Front/Surround",
21536428ea1bSRandy Cushman 		.info = snd_ac97_ad1888_lohpsel_info,
21546428ea1bSRandy Cushman 		.get = snd_ac97_ad1888_lohpsel_get,
21556428ea1bSRandy Cushman 		.put = snd_ac97_ad1888_lohpsel_put
21566428ea1bSRandy Cushman 	},
21576428ea1bSRandy Cushman 	AC97_SINGLE("High Pass Filter Enable", AC97_AD_TEST2, 12, 1, 1),
21586428ea1bSRandy Cushman 	AC97_SINGLE("Spread Front to Surround and Center/LFE",
21596428ea1bSRandy Cushman 		    AC97_AD_MISC, 7, 1, 0),
21606428ea1bSRandy Cushman 	{
21616428ea1bSRandy Cushman 		.iface = SNDRV_CTL_ELEM_IFACE_MIXER,
21626428ea1bSRandy Cushman 		.name = "Downmix",
21636428ea1bSRandy Cushman 		.info = snd_ac97_ad1888_downmix_info,
21646428ea1bSRandy Cushman 		.get = snd_ac97_ad1888_downmix_get,
21656428ea1bSRandy Cushman 		.put = snd_ac97_ad1888_downmix_put
21666428ea1bSRandy Cushman 	},
21676428ea1bSRandy Cushman 	{
21686428ea1bSRandy Cushman 		.iface = SNDRV_CTL_ELEM_IFACE_MIXER,
21696428ea1bSRandy Cushman 		.name = "V_REFOUT",
21706428ea1bSRandy Cushman 		.info = snd_ac97_ad1985_vrefout_info,
21716428ea1bSRandy Cushman 		.get = snd_ac97_ad1985_vrefout_get,
21726428ea1bSRandy Cushman 		.put = snd_ac97_ad1985_vrefout_put
21736428ea1bSRandy Cushman 	},
21746428ea1bSRandy Cushman 	AC97_SURROUND_JACK_MODE_CTL,
21756428ea1bSRandy Cushman 	AC97_CHANNEL_MODE_CTL,
21766428ea1bSRandy Cushman 
21776428ea1bSRandy Cushman 	AC97_SINGLE("Headphone Jack Sense", AC97_AD_JACK_SPDIF, 10, 1, 0),
21786428ea1bSRandy Cushman 	AC97_SINGLE("Line Jack Sense", AC97_AD_JACK_SPDIF, 12, 1, 0),
21791da177e4SLinus Torvalds };
21801da177e4SLinus Torvalds 
ad1985_update_jacks(struct snd_ac97 * ac97)2181ee42381eSTakashi Iwai static void ad1985_update_jacks(struct snd_ac97 *ac97)
2182e5b3f45fSTakashi Iwai {
21834525c9f3STakashi Iwai 	ad1888_update_jacks(ac97);
2184c26a8de2SRandy Cushman 	/* clear OMS if shared jack is to be used for C/LFE out */
2185fc232c6eSTakashi Iwai 	snd_ac97_update_bits(ac97, AC97_AD_SERIAL_CFG, 1 << 9,
2186c26a8de2SRandy Cushman 			     is_shared_micin(ac97) ? 1 << 9 : 0);
2187e5b3f45fSTakashi Iwai }
2188e5b3f45fSTakashi Iwai 
patch_ad1985_specific(struct snd_ac97 * ac97)2189ee42381eSTakashi Iwai static int patch_ad1985_specific(struct snd_ac97 *ac97)
21901da177e4SLinus Torvalds {
21911da177e4SLinus Torvalds 	int err;
21921da177e4SLinus Torvalds 
21936428ea1bSRandy Cushman 	/* rename 0x04 as "Master" and 0x02 as "Master Surround" */
21946428ea1bSRandy Cushman 	snd_ac97_rename_vol_ctl(ac97, "Master Playback",
21956428ea1bSRandy Cushman 				"Master Surround Playback");
21966428ea1bSRandy Cushman 	snd_ac97_rename_vol_ctl(ac97, "Headphone Playback", "Master Playback");
21976428ea1bSRandy Cushman 
2198e66fd362STakashi Iwai 	err = patch_build_controls(ac97, &snd_ac97_ad198x_2cmic, 1);
2199e66fd362STakashi Iwai 	if (err < 0)
22001da177e4SLinus Torvalds 		return err;
22016428ea1bSRandy Cushman 
22026428ea1bSRandy Cushman 	return patch_build_controls(ac97, snd_ac97_ad1985_controls,
22036428ea1bSRandy Cushman 				    ARRAY_SIZE(snd_ac97_ad1985_controls));
22041da177e4SLinus Torvalds }
22051da177e4SLinus Torvalds 
22063e8b3b90SHanno Boeck static const struct snd_ac97_build_ops patch_ad1985_build_ops = {
22071da177e4SLinus Torvalds 	.build_post_spdif = patch_ad198x_post_spdif,
22081da177e4SLinus Torvalds 	.build_specific = patch_ad1985_specific,
22091da177e4SLinus Torvalds #ifdef CONFIG_PM
2210462c4173SClemens Ladisch 	.resume = ad18xx_resume,
22111da177e4SLinus Torvalds #endif
2212e5b3f45fSTakashi Iwai 	.update_jacks = ad1985_update_jacks,
22131da177e4SLinus Torvalds };
22141da177e4SLinus Torvalds 
patch_ad1985(struct snd_ac97 * ac97)2215ac519028STakashi Iwai static int patch_ad1985(struct snd_ac97 * ac97)
22161da177e4SLinus Torvalds {
22171da177e4SLinus Torvalds 	unsigned short misc;
22181da177e4SLinus Torvalds 
22191da177e4SLinus Torvalds 	patch_ad1881(ac97);
22201da177e4SLinus Torvalds 	ac97->build_ops = &patch_ad1985_build_ops;
22211da177e4SLinus Torvalds 	misc = snd_ac97_read(ac97, AC97_AD_MISC);
22221da177e4SLinus Torvalds 	/* switch front/surround line-out/hp-out */
22231da177e4SLinus Torvalds 	/* AD-compatible mode */
22241da177e4SLinus Torvalds 	/* Stereo mutes enabled */
22251da177e4SLinus Torvalds 	snd_ac97_write_cache(ac97, AC97_AD_MISC, misc |
22261da177e4SLinus Torvalds 			     AC97_AD198X_LOSEL |
22271da177e4SLinus Torvalds 			     AC97_AD198X_HPSEL |
22281da177e4SLinus Torvalds 			     AC97_AD198X_MSPLT |
22291da177e4SLinus Torvalds 			     AC97_AD198X_AC97NC);
22301da177e4SLinus Torvalds 	ac97->flags |= AC97_STEREO_MUTES;
22316428ea1bSRandy Cushman 
22326428ea1bSRandy Cushman 	/* update current jack configuration */
22336428ea1bSRandy Cushman 	ad1985_update_jacks(ac97);
22346428ea1bSRandy Cushman 
22351da177e4SLinus Torvalds 	/* on AD1985 rev. 3, AC'97 revision bits are zero */
22361da177e4SLinus Torvalds 	ac97->ext_id = (ac97->ext_id & ~AC97_EI_REV_MASK) | AC97_EI_REV_23;
22371da177e4SLinus Torvalds 	return 0;
22381da177e4SLinus Torvalds }
22391da177e4SLinus Torvalds 
2240a5ce8890STakashi Iwai #define snd_ac97_ad1986_bool_info	snd_ctl_boolean_mono_info
224167e9f4b6SRandy Cushman 
snd_ac97_ad1986_lososel_get(struct snd_kcontrol * kcontrol,struct snd_ctl_elem_value * ucontrol)224267e9f4b6SRandy Cushman static int snd_ac97_ad1986_lososel_get(struct snd_kcontrol *kcontrol,
224367e9f4b6SRandy Cushman 				       struct snd_ctl_elem_value *ucontrol)
224467e9f4b6SRandy Cushman {
224567e9f4b6SRandy Cushman 	struct snd_ac97 *ac97 = snd_kcontrol_chip(kcontrol);
224667e9f4b6SRandy Cushman 	unsigned short val;
224767e9f4b6SRandy Cushman 
224867e9f4b6SRandy Cushman 	val = ac97->regs[AC97_AD_MISC3];
224967e9f4b6SRandy Cushman 	ucontrol->value.integer.value[0] = (val & AC97_AD1986_LOSEL) != 0;
225067e9f4b6SRandy Cushman 	return 0;
225167e9f4b6SRandy Cushman }
225267e9f4b6SRandy Cushman 
snd_ac97_ad1986_lososel_put(struct snd_kcontrol * kcontrol,struct snd_ctl_elem_value * ucontrol)225367e9f4b6SRandy Cushman static int snd_ac97_ad1986_lososel_put(struct snd_kcontrol *kcontrol,
225467e9f4b6SRandy Cushman 				       struct snd_ctl_elem_value *ucontrol)
225567e9f4b6SRandy Cushman {
225667e9f4b6SRandy Cushman 	struct snd_ac97 *ac97 = snd_kcontrol_chip(kcontrol);
225767e9f4b6SRandy Cushman 	int ret0;
225867e9f4b6SRandy Cushman 	int ret1;
225967e9f4b6SRandy Cushman 	int sprd = (ac97->regs[AC97_AD_MISC] & AC97_AD1986_SPRD) != 0;
226067e9f4b6SRandy Cushman 
226167e9f4b6SRandy Cushman 	ret0 = snd_ac97_update_bits(ac97, AC97_AD_MISC3, AC97_AD1986_LOSEL,
226267e9f4b6SRandy Cushman 					ucontrol->value.integer.value[0] != 0
226367e9f4b6SRandy Cushman 				    ? AC97_AD1986_LOSEL : 0);
226467e9f4b6SRandy Cushman 	if (ret0 < 0)
226567e9f4b6SRandy Cushman 		return ret0;
226667e9f4b6SRandy Cushman 
226767e9f4b6SRandy Cushman 	/* SOSEL is set to values of "Spread" or "Exchange F/S" controls */
226867e9f4b6SRandy Cushman 	ret1 = snd_ac97_update_bits(ac97, AC97_AD_MISC, AC97_AD1986_SOSEL,
226967e9f4b6SRandy Cushman 				    (ucontrol->value.integer.value[0] != 0
227067e9f4b6SRandy Cushman 				     || sprd)
227167e9f4b6SRandy Cushman 				    ? AC97_AD1986_SOSEL : 0);
227267e9f4b6SRandy Cushman 	if (ret1 < 0)
227367e9f4b6SRandy Cushman 		return ret1;
227467e9f4b6SRandy Cushman 
227567e9f4b6SRandy Cushman 	return (ret0 > 0 || ret1 > 0) ? 1 : 0;
227667e9f4b6SRandy Cushman }
227767e9f4b6SRandy Cushman 
snd_ac97_ad1986_spread_get(struct snd_kcontrol * kcontrol,struct snd_ctl_elem_value * ucontrol)227867e9f4b6SRandy Cushman static int snd_ac97_ad1986_spread_get(struct snd_kcontrol *kcontrol,
227967e9f4b6SRandy Cushman 				      struct snd_ctl_elem_value *ucontrol)
228067e9f4b6SRandy Cushman {
228167e9f4b6SRandy Cushman 	struct snd_ac97 *ac97 = snd_kcontrol_chip(kcontrol);
228267e9f4b6SRandy Cushman 	unsigned short val;
228367e9f4b6SRandy Cushman 
228467e9f4b6SRandy Cushman 	val = ac97->regs[AC97_AD_MISC];
228567e9f4b6SRandy Cushman 	ucontrol->value.integer.value[0] = (val & AC97_AD1986_SPRD) != 0;
228667e9f4b6SRandy Cushman 	return 0;
228767e9f4b6SRandy Cushman }
228867e9f4b6SRandy Cushman 
snd_ac97_ad1986_spread_put(struct snd_kcontrol * kcontrol,struct snd_ctl_elem_value * ucontrol)228967e9f4b6SRandy Cushman static int snd_ac97_ad1986_spread_put(struct snd_kcontrol *kcontrol,
229067e9f4b6SRandy Cushman 				      struct snd_ctl_elem_value *ucontrol)
229167e9f4b6SRandy Cushman {
229267e9f4b6SRandy Cushman 	struct snd_ac97 *ac97 = snd_kcontrol_chip(kcontrol);
229367e9f4b6SRandy Cushman 	int ret0;
229467e9f4b6SRandy Cushman 	int ret1;
229567e9f4b6SRandy Cushman 	int sprd = (ac97->regs[AC97_AD_MISC3] & AC97_AD1986_LOSEL) != 0;
229667e9f4b6SRandy Cushman 
229767e9f4b6SRandy Cushman 	ret0 = snd_ac97_update_bits(ac97, AC97_AD_MISC, AC97_AD1986_SPRD,
229867e9f4b6SRandy Cushman 					ucontrol->value.integer.value[0] != 0
229967e9f4b6SRandy Cushman 				    ? AC97_AD1986_SPRD : 0);
230067e9f4b6SRandy Cushman 	if (ret0 < 0)
230167e9f4b6SRandy Cushman 		return ret0;
230267e9f4b6SRandy Cushman 
230367e9f4b6SRandy Cushman 	/* SOSEL is set to values of "Spread" or "Exchange F/S" controls */
230467e9f4b6SRandy Cushman 	ret1 = snd_ac97_update_bits(ac97, AC97_AD_MISC, AC97_AD1986_SOSEL,
230567e9f4b6SRandy Cushman 				    (ucontrol->value.integer.value[0] != 0
230667e9f4b6SRandy Cushman 				     || sprd)
230767e9f4b6SRandy Cushman 				    ? AC97_AD1986_SOSEL : 0);
230867e9f4b6SRandy Cushman 	if (ret1 < 0)
230967e9f4b6SRandy Cushman 		return ret1;
231067e9f4b6SRandy Cushman 
231167e9f4b6SRandy Cushman 	return (ret0 > 0 || ret1 > 0) ? 1 : 0;
231267e9f4b6SRandy Cushman }
231367e9f4b6SRandy Cushman 
snd_ac97_ad1986_miclisel_get(struct snd_kcontrol * kcontrol,struct snd_ctl_elem_value * ucontrol)231467e9f4b6SRandy Cushman static int snd_ac97_ad1986_miclisel_get(struct snd_kcontrol *kcontrol,
231567e9f4b6SRandy Cushman 					struct snd_ctl_elem_value *ucontrol)
231667e9f4b6SRandy Cushman {
231767e9f4b6SRandy Cushman 	struct snd_ac97 *ac97 = snd_kcontrol_chip(kcontrol);
231867e9f4b6SRandy Cushman 
231967e9f4b6SRandy Cushman 	ucontrol->value.integer.value[0] = ac97->spec.ad18xx.swap_mic_linein;
232067e9f4b6SRandy Cushman 	return 0;
232167e9f4b6SRandy Cushman }
232267e9f4b6SRandy Cushman 
snd_ac97_ad1986_miclisel_put(struct snd_kcontrol * kcontrol,struct snd_ctl_elem_value * ucontrol)232367e9f4b6SRandy Cushman static int snd_ac97_ad1986_miclisel_put(struct snd_kcontrol *kcontrol,
232467e9f4b6SRandy Cushman 					struct snd_ctl_elem_value *ucontrol)
232567e9f4b6SRandy Cushman {
232667e9f4b6SRandy Cushman 	struct snd_ac97 *ac97 = snd_kcontrol_chip(kcontrol);
232767e9f4b6SRandy Cushman 	unsigned char swap = ucontrol->value.integer.value[0] != 0;
232867e9f4b6SRandy Cushman 
232967e9f4b6SRandy Cushman 	if (swap != ac97->spec.ad18xx.swap_mic_linein) {
233067e9f4b6SRandy Cushman 		ac97->spec.ad18xx.swap_mic_linein = swap;
233167e9f4b6SRandy Cushman 		if (ac97->build_ops->update_jacks)
233267e9f4b6SRandy Cushman 			ac97->build_ops->update_jacks(ac97);
233367e9f4b6SRandy Cushman 		return 1;
233467e9f4b6SRandy Cushman 	}
233567e9f4b6SRandy Cushman 	return 0;
233667e9f4b6SRandy Cushman }
233767e9f4b6SRandy Cushman 
snd_ac97_ad1986_vrefout_get(struct snd_kcontrol * kcontrol,struct snd_ctl_elem_value * ucontrol)233867e9f4b6SRandy Cushman static int snd_ac97_ad1986_vrefout_get(struct snd_kcontrol *kcontrol,
233967e9f4b6SRandy Cushman 				       struct snd_ctl_elem_value *ucontrol)
234067e9f4b6SRandy Cushman {
234167e9f4b6SRandy Cushman 	/* Use MIC_1/2 V_REFOUT as the "get" value */
234267e9f4b6SRandy Cushman 	struct snd_ac97 *ac97 = snd_kcontrol_chip(kcontrol);
234367e9f4b6SRandy Cushman 	unsigned short val;
234467e9f4b6SRandy Cushman 	unsigned short reg = ac97->regs[AC97_AD_MISC2];
234567e9f4b6SRandy Cushman 	if ((reg & AC97_AD1986_MVREF0) != 0)
234667e9f4b6SRandy Cushman 		val = 2;
234767e9f4b6SRandy Cushman 	else if ((reg & AC97_AD1986_MVREF1) != 0)
234867e9f4b6SRandy Cushman 		val = 3;
234967e9f4b6SRandy Cushman 	else if ((reg & AC97_AD1986_MVREF2) != 0)
235067e9f4b6SRandy Cushman 		val = 1;
235167e9f4b6SRandy Cushman 	else
235267e9f4b6SRandy Cushman 		val = 0;
235367e9f4b6SRandy Cushman 	ucontrol->value.enumerated.item[0] = val;
235467e9f4b6SRandy Cushman 	return 0;
235567e9f4b6SRandy Cushman }
235667e9f4b6SRandy Cushman 
snd_ac97_ad1986_vrefout_put(struct snd_kcontrol * kcontrol,struct snd_ctl_elem_value * ucontrol)235767e9f4b6SRandy Cushman static int snd_ac97_ad1986_vrefout_put(struct snd_kcontrol *kcontrol,
235867e9f4b6SRandy Cushman 				       struct snd_ctl_elem_value *ucontrol)
235967e9f4b6SRandy Cushman {
236067e9f4b6SRandy Cushman 	struct snd_ac97 *ac97 = snd_kcontrol_chip(kcontrol);
236167e9f4b6SRandy Cushman 	unsigned short cval;
236267e9f4b6SRandy Cushman 	unsigned short lval;
236367e9f4b6SRandy Cushman 	unsigned short mval;
236467e9f4b6SRandy Cushman 	int cret;
236567e9f4b6SRandy Cushman 	int lret;
236667e9f4b6SRandy Cushman 	int mret;
236767e9f4b6SRandy Cushman 
236867e9f4b6SRandy Cushman 	switch (ucontrol->value.enumerated.item[0])
236967e9f4b6SRandy Cushman 	{
237067e9f4b6SRandy Cushman 	case 0: /* High-Z */
237167e9f4b6SRandy Cushman 		cval = 0;
237267e9f4b6SRandy Cushman 		lval = 0;
237367e9f4b6SRandy Cushman 		mval = 0;
237467e9f4b6SRandy Cushman 		break;
237567e9f4b6SRandy Cushman 	case 1: /* 3.7 V */
237667e9f4b6SRandy Cushman 		cval = AC97_AD1986_CVREF2;
237767e9f4b6SRandy Cushman 		lval = AC97_AD1986_LVREF2;
237867e9f4b6SRandy Cushman 		mval = AC97_AD1986_MVREF2;
237967e9f4b6SRandy Cushman 		break;
238067e9f4b6SRandy Cushman 	case 2: /* 2.25 V */
238167e9f4b6SRandy Cushman 		cval = AC97_AD1986_CVREF0;
238267e9f4b6SRandy Cushman 		lval = AC97_AD1986_LVREF0;
238367e9f4b6SRandy Cushman 		mval = AC97_AD1986_MVREF0;
238467e9f4b6SRandy Cushman 		break;
238567e9f4b6SRandy Cushman 	case 3: /* 0 V */
238667e9f4b6SRandy Cushman 		cval = AC97_AD1986_CVREF1;
238767e9f4b6SRandy Cushman 		lval = AC97_AD1986_LVREF1;
238867e9f4b6SRandy Cushman 		mval = AC97_AD1986_MVREF1;
238967e9f4b6SRandy Cushman 		break;
239067e9f4b6SRandy Cushman 	default:
239167e9f4b6SRandy Cushman 		return -EINVAL;
239267e9f4b6SRandy Cushman 	}
239367e9f4b6SRandy Cushman 
239467e9f4b6SRandy Cushman 	cret = snd_ac97_update_bits(ac97, AC97_AD_MISC2,
239567e9f4b6SRandy Cushman 				    AC97_AD1986_CVREF_MASK, cval);
239667e9f4b6SRandy Cushman 	if (cret < 0)
239767e9f4b6SRandy Cushman 		return cret;
239867e9f4b6SRandy Cushman 	lret = snd_ac97_update_bits(ac97, AC97_AD_MISC3,
239967e9f4b6SRandy Cushman 				    AC97_AD1986_LVREF_MASK, lval);
240067e9f4b6SRandy Cushman 	if (lret < 0)
240167e9f4b6SRandy Cushman 		return lret;
240267e9f4b6SRandy Cushman 	mret = snd_ac97_update_bits(ac97, AC97_AD_MISC2,
240367e9f4b6SRandy Cushman 				    AC97_AD1986_MVREF_MASK, mval);
240467e9f4b6SRandy Cushman 	if (mret < 0)
240567e9f4b6SRandy Cushman 		return mret;
240667e9f4b6SRandy Cushman 
240767e9f4b6SRandy Cushman 	return (cret > 0 || lret > 0 || mret > 0) ? 1 : 0;
240867e9f4b6SRandy Cushman }
240967e9f4b6SRandy Cushman 
241067e9f4b6SRandy Cushman static const struct snd_kcontrol_new snd_ac97_ad1986_controls[] = {
241167e9f4b6SRandy Cushman 	AC97_SINGLE("Exchange Center/LFE", AC97_AD_SERIAL_CFG, 3, 1, 0),
241267e9f4b6SRandy Cushman 	{
241367e9f4b6SRandy Cushman 		.iface = SNDRV_CTL_ELEM_IFACE_MIXER,
241467e9f4b6SRandy Cushman 		.name = "Exchange Front/Surround",
241567e9f4b6SRandy Cushman 		.info = snd_ac97_ad1986_bool_info,
241667e9f4b6SRandy Cushman 		.get = snd_ac97_ad1986_lososel_get,
241767e9f4b6SRandy Cushman 		.put = snd_ac97_ad1986_lososel_put
241867e9f4b6SRandy Cushman 	},
241967e9f4b6SRandy Cushman 	{
242067e9f4b6SRandy Cushman 		.iface = SNDRV_CTL_ELEM_IFACE_MIXER,
242167e9f4b6SRandy Cushman 		.name = "Exchange Mic/Line In",
242267e9f4b6SRandy Cushman 		.info = snd_ac97_ad1986_bool_info,
242367e9f4b6SRandy Cushman 		.get = snd_ac97_ad1986_miclisel_get,
242467e9f4b6SRandy Cushman 		.put = snd_ac97_ad1986_miclisel_put
242567e9f4b6SRandy Cushman 	},
242667e9f4b6SRandy Cushman 	{
242767e9f4b6SRandy Cushman 		.iface = SNDRV_CTL_ELEM_IFACE_MIXER,
242867e9f4b6SRandy Cushman 		.name = "Spread Front to Surround and Center/LFE",
242967e9f4b6SRandy Cushman 		.info = snd_ac97_ad1986_bool_info,
243067e9f4b6SRandy Cushman 		.get = snd_ac97_ad1986_spread_get,
243167e9f4b6SRandy Cushman 		.put = snd_ac97_ad1986_spread_put
243267e9f4b6SRandy Cushman 	},
243367e9f4b6SRandy Cushman 	{
243467e9f4b6SRandy Cushman 		.iface = SNDRV_CTL_ELEM_IFACE_MIXER,
243567e9f4b6SRandy Cushman 		.name = "Downmix",
243667e9f4b6SRandy Cushman 		.info = snd_ac97_ad1888_downmix_info,
243767e9f4b6SRandy Cushman 		.get = snd_ac97_ad1888_downmix_get,
243867e9f4b6SRandy Cushman 		.put = snd_ac97_ad1888_downmix_put
243967e9f4b6SRandy Cushman 	},
244067e9f4b6SRandy Cushman 	{
244167e9f4b6SRandy Cushman 		.iface = SNDRV_CTL_ELEM_IFACE_MIXER,
244267e9f4b6SRandy Cushman 		.name = "V_REFOUT",
244367e9f4b6SRandy Cushman 		.info = snd_ac97_ad1985_vrefout_info,
244467e9f4b6SRandy Cushman 		.get = snd_ac97_ad1986_vrefout_get,
244567e9f4b6SRandy Cushman 		.put = snd_ac97_ad1986_vrefout_put
244667e9f4b6SRandy Cushman 	},
244767e9f4b6SRandy Cushman 	AC97_SURROUND_JACK_MODE_CTL,
244867e9f4b6SRandy Cushman 	AC97_CHANNEL_MODE_CTL,
244967e9f4b6SRandy Cushman 
245067e9f4b6SRandy Cushman 	AC97_SINGLE("Headphone Jack Sense", AC97_AD_JACK_SPDIF, 10, 1, 0),
245167e9f4b6SRandy Cushman 	AC97_SINGLE("Line Jack Sense", AC97_AD_JACK_SPDIF, 12, 1, 0)
245267e9f4b6SRandy Cushman };
245367e9f4b6SRandy Cushman 
ad1986_update_jacks(struct snd_ac97 * ac97)245467e9f4b6SRandy Cushman static void ad1986_update_jacks(struct snd_ac97 *ac97)
245567e9f4b6SRandy Cushman {
245667e9f4b6SRandy Cushman 	unsigned short misc_val = 0;
245767e9f4b6SRandy Cushman 	unsigned short ser_val;
245867e9f4b6SRandy Cushman 
245967e9f4b6SRandy Cushman 	/* disable SURROUND and CENTER/LFE if not surround mode */
246067e9f4b6SRandy Cushman 	if (!is_surround_on(ac97))
246167e9f4b6SRandy Cushman 		misc_val |= AC97_AD1986_SODIS;
246267e9f4b6SRandy Cushman 	if (!is_clfe_on(ac97))
246367e9f4b6SRandy Cushman 		misc_val |= AC97_AD1986_CLDIS;
246467e9f4b6SRandy Cushman 
246567e9f4b6SRandy Cushman 	/* select line input (default=LINE_IN, SURROUND or MIC_1/2) */
246667e9f4b6SRandy Cushman 	if (is_shared_linein(ac97))
246767e9f4b6SRandy Cushman 		misc_val |= AC97_AD1986_LISEL_SURR;
246867e9f4b6SRandy Cushman 	else if (ac97->spec.ad18xx.swap_mic_linein != 0)
246967e9f4b6SRandy Cushman 		misc_val |= AC97_AD1986_LISEL_MIC;
247067e9f4b6SRandy Cushman 	snd_ac97_update_bits(ac97, AC97_AD_MISC,
247167e9f4b6SRandy Cushman 			     AC97_AD1986_SODIS | AC97_AD1986_CLDIS |
247267e9f4b6SRandy Cushman 			     AC97_AD1986_LISEL_MASK,
247367e9f4b6SRandy Cushman 			     misc_val);
247467e9f4b6SRandy Cushman 
247567e9f4b6SRandy Cushman 	/* select microphone input (MIC_1/2, Center/LFE or LINE_IN) */
247667e9f4b6SRandy Cushman 	if (is_shared_micin(ac97))
247767e9f4b6SRandy Cushman 		ser_val = AC97_AD1986_OMS_C;
247867e9f4b6SRandy Cushman 	else if (ac97->spec.ad18xx.swap_mic_linein != 0)
247967e9f4b6SRandy Cushman 		ser_val = AC97_AD1986_OMS_L;
248067e9f4b6SRandy Cushman 	else
248167e9f4b6SRandy Cushman 		ser_val = AC97_AD1986_OMS_M;
248267e9f4b6SRandy Cushman 	snd_ac97_update_bits(ac97, AC97_AD_SERIAL_CFG,
248367e9f4b6SRandy Cushman 			     AC97_AD1986_OMS_MASK,
248467e9f4b6SRandy Cushman 			     ser_val);
248567e9f4b6SRandy Cushman }
248667e9f4b6SRandy Cushman 
patch_ad1986_specific(struct snd_ac97 * ac97)248767e9f4b6SRandy Cushman static int patch_ad1986_specific(struct snd_ac97 *ac97)
248867e9f4b6SRandy Cushman {
248967e9f4b6SRandy Cushman 	int err;
249067e9f4b6SRandy Cushman 
2491e66fd362STakashi Iwai 	err = patch_build_controls(ac97, &snd_ac97_ad198x_2cmic, 1);
2492e66fd362STakashi Iwai 	if (err < 0)
249367e9f4b6SRandy Cushman 		return err;
249467e9f4b6SRandy Cushman 
249567e9f4b6SRandy Cushman 	return patch_build_controls(ac97, snd_ac97_ad1986_controls,
249667e9f4b6SRandy Cushman 				    ARRAY_SIZE(snd_ac97_ad1985_controls));
249767e9f4b6SRandy Cushman }
249867e9f4b6SRandy Cushman 
24993e8b3b90SHanno Boeck static const struct snd_ac97_build_ops patch_ad1986_build_ops = {
250067e9f4b6SRandy Cushman 	.build_post_spdif = patch_ad198x_post_spdif,
250167e9f4b6SRandy Cushman 	.build_specific = patch_ad1986_specific,
250267e9f4b6SRandy Cushman #ifdef CONFIG_PM
250367e9f4b6SRandy Cushman 	.resume = ad18xx_resume,
250467e9f4b6SRandy Cushman #endif
250567e9f4b6SRandy Cushman 	.update_jacks = ad1986_update_jacks,
250667e9f4b6SRandy Cushman };
250767e9f4b6SRandy Cushman 
patch_ad1986(struct snd_ac97 * ac97)2508ac519028STakashi Iwai static int patch_ad1986(struct snd_ac97 * ac97)
250967e9f4b6SRandy Cushman {
251067e9f4b6SRandy Cushman 	patch_ad1881(ac97);
251167e9f4b6SRandy Cushman 	ac97->build_ops = &patch_ad1986_build_ops;
251267e9f4b6SRandy Cushman 	ac97->flags |= AC97_STEREO_MUTES;
251367e9f4b6SRandy Cushman 
251467e9f4b6SRandy Cushman 	/* update current jack configuration */
251567e9f4b6SRandy Cushman 	ad1986_update_jacks(ac97);
251667e9f4b6SRandy Cushman 
251767e9f4b6SRandy Cushman 	return 0;
251867e9f4b6SRandy Cushman }
251967e9f4b6SRandy Cushman 
25208f4f4ef6STakashi Iwai /*
25218f4f4ef6STakashi Iwai  * realtek ALC203: use mono-out for pin 37
25228f4f4ef6STakashi Iwai  */
patch_alc203(struct snd_ac97 * ac97)25238f4f4ef6STakashi Iwai static int patch_alc203(struct snd_ac97 *ac97)
25248f4f4ef6STakashi Iwai {
25258f4f4ef6STakashi Iwai 	snd_ac97_update_bits(ac97, 0x7a, 0x400, 0x400);
25268f4f4ef6STakashi Iwai 	return 0;
25278f4f4ef6STakashi Iwai }
252867e9f4b6SRandy Cushman 
25291da177e4SLinus Torvalds /*
25301da177e4SLinus Torvalds  * realtek ALC65x/850 codecs
25311da177e4SLinus Torvalds  */
alc650_update_jacks(struct snd_ac97 * ac97)2532ee42381eSTakashi Iwai static void alc650_update_jacks(struct snd_ac97 *ac97)
25331da177e4SLinus Torvalds {
2534eb8caf30STakashi Iwai 	int shared;
25351da177e4SLinus Torvalds 
2536831466f4SRandy Cushman 	/* shared Line-In / Surround Out */
2537831466f4SRandy Cushman 	shared = is_shared_surrout(ac97);
2538eb8caf30STakashi Iwai 	snd_ac97_update_bits(ac97, AC97_ALC650_MULTICH, 1 << 9,
2539eb8caf30STakashi Iwai 			     shared ? (1 << 9) : 0);
2540831466f4SRandy Cushman 	/* update shared Mic In / Center/LFE Out */
2541831466f4SRandy Cushman 	shared = is_shared_clfeout(ac97);
25421da177e4SLinus Torvalds 	/* disable/enable vref */
25431da177e4SLinus Torvalds 	snd_ac97_update_bits(ac97, AC97_ALC650_CLOCK, 1 << 12,
2544eb8caf30STakashi Iwai 			     shared ? (1 << 12) : 0);
25451da177e4SLinus Torvalds 	/* turn on/off center-on-mic */
25461da177e4SLinus Torvalds 	snd_ac97_update_bits(ac97, AC97_ALC650_MULTICH, 1 << 10,
2547eb8caf30STakashi Iwai 			     shared ? (1 << 10) : 0);
25481da177e4SLinus Torvalds 	/* GPIO0 high for mic */
25491da177e4SLinus Torvalds 	snd_ac97_update_bits(ac97, AC97_ALC650_GPIO_STATUS, 0x100,
2550eb8caf30STakashi Iwai 			     shared ? 0 : 0x100);
25511da177e4SLinus Torvalds }
25521da177e4SLinus Torvalds 
alc650_swap_surround_put(struct snd_kcontrol * kcontrol,struct snd_ctl_elem_value * ucontrol)2553833a493bSTakashi Iwai static int alc650_swap_surround_put(struct snd_kcontrol *kcontrol,
2554833a493bSTakashi Iwai 				    struct snd_ctl_elem_value *ucontrol)
2555833a493bSTakashi Iwai {
2556833a493bSTakashi Iwai 	struct snd_ac97 *ac97 = snd_kcontrol_chip(kcontrol);
2557833a493bSTakashi Iwai 	struct snd_pcm_chmap *map = ac97->chmaps[SNDRV_PCM_STREAM_PLAYBACK];
2558833a493bSTakashi Iwai 
2559833a493bSTakashi Iwai 	if (map) {
2560833a493bSTakashi Iwai 		if (ucontrol->value.integer.value[0])
2561833a493bSTakashi Iwai 			map->chmap = snd_pcm_std_chmaps;
2562833a493bSTakashi Iwai 		else
2563833a493bSTakashi Iwai 			map->chmap = snd_pcm_alt_chmaps;
2564833a493bSTakashi Iwai 	}
2565833a493bSTakashi Iwai 	return snd_ac97_put_volsw(kcontrol, ucontrol);
2566833a493bSTakashi Iwai }
2567833a493bSTakashi Iwai 
2568ee42381eSTakashi Iwai static const struct snd_kcontrol_new snd_ac97_controls_alc650[] = {
25691da177e4SLinus Torvalds 	AC97_SINGLE("Duplicate Front", AC97_ALC650_MULTICH, 0, 1, 0),
25701da177e4SLinus Torvalds 	AC97_SINGLE("Surround Down Mix", AC97_ALC650_MULTICH, 1, 1, 0),
25711da177e4SLinus Torvalds 	AC97_SINGLE("Center/LFE Down Mix", AC97_ALC650_MULTICH, 2, 1, 0),
25721da177e4SLinus Torvalds 	AC97_SINGLE("Exchange Center/LFE", AC97_ALC650_MULTICH, 3, 1, 0),
25731da177e4SLinus Torvalds 	/* 4: Analog Input To Surround */
25741da177e4SLinus Torvalds 	/* 5: Analog Input To Center/LFE */
25751da177e4SLinus Torvalds 	/* 6: Independent Master Volume Right */
25761da177e4SLinus Torvalds 	/* 7: Independent Master Volume Left */
25771da177e4SLinus Torvalds 	/* 8: reserved */
2578eb8caf30STakashi Iwai 	/* 9: Line-In/Surround share */
2579eb8caf30STakashi Iwai 	/* 10: Mic/CLFE share */
25801da177e4SLinus Torvalds 	/* 11-13: in IEC958 controls */
2581833a493bSTakashi Iwai 	{
2582833a493bSTakashi Iwai 		.iface = SNDRV_CTL_ELEM_IFACE_MIXER,
2583833a493bSTakashi Iwai 		.name = "Swap Surround Slot",
2584833a493bSTakashi Iwai 		.info = snd_ac97_info_volsw,
2585833a493bSTakashi Iwai 		.get = snd_ac97_get_volsw,
2586833a493bSTakashi Iwai 		.put = alc650_swap_surround_put,
2587833a493bSTakashi Iwai 		.private_value =  AC97_SINGLE_VALUE(AC97_ALC650_MULTICH, 14, 1, 0),
2588833a493bSTakashi Iwai 	},
25891da177e4SLinus Torvalds #if 0 /* always set in patch_alc650 */
25901da177e4SLinus Torvalds 	AC97_SINGLE("IEC958 Input Clock Enable", AC97_ALC650_CLOCK, 0, 1, 0),
25911da177e4SLinus Torvalds 	AC97_SINGLE("IEC958 Input Pin Enable", AC97_ALC650_CLOCK, 1, 1, 0),
25921da177e4SLinus Torvalds 	AC97_SINGLE("Surround DAC Switch", AC97_ALC650_SURR_DAC_VOL, 15, 1, 1),
25931da177e4SLinus Torvalds 	AC97_DOUBLE("Surround DAC Volume", AC97_ALC650_SURR_DAC_VOL, 8, 0, 31, 1),
25941da177e4SLinus Torvalds 	AC97_SINGLE("Center/LFE DAC Switch", AC97_ALC650_LFE_DAC_VOL, 15, 1, 1),
25951da177e4SLinus Torvalds 	AC97_DOUBLE("Center/LFE DAC Volume", AC97_ALC650_LFE_DAC_VOL, 8, 0, 31, 1),
25961da177e4SLinus Torvalds #endif
2597eb8caf30STakashi Iwai 	AC97_SURROUND_JACK_MODE_CTL,
2598eb8caf30STakashi Iwai 	AC97_CHANNEL_MODE_CTL,
25991da177e4SLinus Torvalds };
26001da177e4SLinus Torvalds 
2601ee42381eSTakashi Iwai static const struct snd_kcontrol_new snd_ac97_spdif_controls_alc650[] = {
260210e8d78aSClemens Ladisch         AC97_SINGLE(SNDRV_CTL_NAME_IEC958("",CAPTURE,SWITCH), AC97_ALC650_MULTICH, 11, 1, 0),
26031da177e4SLinus Torvalds         AC97_SINGLE("Analog to IEC958 Output", AC97_ALC650_MULTICH, 12, 1, 0),
26041da177e4SLinus Torvalds 	/* disable this controls since it doesn't work as expected */
26051da177e4SLinus Torvalds 	/* AC97_SINGLE("IEC958 Input Monitor", AC97_ALC650_MULTICH, 13, 1, 0), */
26061da177e4SLinus Torvalds };
26071da177e4SLinus Torvalds 
26080cb29ea0STakashi Iwai static const DECLARE_TLV_DB_SCALE(db_scale_5bit_3db_max, -4350, 150, 0);
26092f3482fbSTakashi Iwai 
patch_alc650_specific(struct snd_ac97 * ac97)2610ee42381eSTakashi Iwai static int patch_alc650_specific(struct snd_ac97 * ac97)
26111da177e4SLinus Torvalds {
26121da177e4SLinus Torvalds 	int err;
26131da177e4SLinus Torvalds 
2614e66fd362STakashi Iwai 	err = patch_build_controls(ac97, snd_ac97_controls_alc650, ARRAY_SIZE(snd_ac97_controls_alc650));
2615e66fd362STakashi Iwai 	if (err < 0)
26161da177e4SLinus Torvalds 		return err;
26171da177e4SLinus Torvalds 	if (ac97->ext_id & AC97_EI_SPDIF) {
2618e66fd362STakashi Iwai 		err = patch_build_controls(ac97, snd_ac97_spdif_controls_alc650, ARRAY_SIZE(snd_ac97_spdif_controls_alc650));
2619e66fd362STakashi Iwai 		if (err < 0)
26201da177e4SLinus Torvalds 			return err;
26211da177e4SLinus Torvalds 	}
26222f3482fbSTakashi Iwai 	if (ac97->id != AC97_ID_ALC650F)
26232f3482fbSTakashi Iwai 		reset_tlv(ac97, "Master Playback Volume",
26242f3482fbSTakashi Iwai 			  db_scale_5bit_3db_max);
26251da177e4SLinus Torvalds 	return 0;
26261da177e4SLinus Torvalds }
26271da177e4SLinus Torvalds 
26283e8b3b90SHanno Boeck static const struct snd_ac97_build_ops patch_alc650_ops = {
2629eb8caf30STakashi Iwai 	.build_specific	= patch_alc650_specific,
2630eb8caf30STakashi Iwai 	.update_jacks = alc650_update_jacks
26311da177e4SLinus Torvalds };
26321da177e4SLinus Torvalds 
patch_alc650(struct snd_ac97 * ac97)2633ac519028STakashi Iwai static int patch_alc650(struct snd_ac97 * ac97)
26341da177e4SLinus Torvalds {
26351da177e4SLinus Torvalds 	unsigned short val;
26361da177e4SLinus Torvalds 
26371da177e4SLinus Torvalds 	ac97->build_ops = &patch_alc650_ops;
26381da177e4SLinus Torvalds 
26391da177e4SLinus Torvalds 	/* determine the revision */
26401da177e4SLinus Torvalds 	val = snd_ac97_read(ac97, AC97_ALC650_REVISION) & 0x3f;
26411da177e4SLinus Torvalds 	if (val < 3)
26421da177e4SLinus Torvalds 		ac97->id = 0x414c4720;          /* Old version */
26431da177e4SLinus Torvalds 	else if (val < 0x10)
26441da177e4SLinus Torvalds 		ac97->id = 0x414c4721;          /* D version */
26451da177e4SLinus Torvalds 	else if (val < 0x20)
26461da177e4SLinus Torvalds 		ac97->id = 0x414c4722;          /* E version */
26471da177e4SLinus Torvalds 	else if (val < 0x30)
26481da177e4SLinus Torvalds 		ac97->id = 0x414c4723;          /* F version */
26491da177e4SLinus Torvalds 
26501da177e4SLinus Torvalds 	/* revision E or F */
26511da177e4SLinus Torvalds 	/* FIXME: what about revision D ? */
26521da177e4SLinus Torvalds 	ac97->spec.dev_flags = (ac97->id == 0x414c4722 ||
26531da177e4SLinus Torvalds 				ac97->id == 0x414c4723);
26541da177e4SLinus Torvalds 
26551da177e4SLinus Torvalds 	/* enable AC97_ALC650_GPIO_SETUP, AC97_ALC650_CLOCK for R/W */
26561da177e4SLinus Torvalds 	snd_ac97_write_cache(ac97, AC97_ALC650_GPIO_STATUS,
26571da177e4SLinus Torvalds 		snd_ac97_read(ac97, AC97_ALC650_GPIO_STATUS) | 0x8000);
26581da177e4SLinus Torvalds 
26591da177e4SLinus Torvalds 	/* Enable SPDIF-IN only on Rev.E and above */
26601da177e4SLinus Torvalds 	val = snd_ac97_read(ac97, AC97_ALC650_CLOCK);
26611da177e4SLinus Torvalds 	/* SPDIF IN with pin 47 */
2662eed65649STakashi Iwai 	if (ac97->spec.dev_flags &&
2663eed65649STakashi Iwai 	    /* ASUS A6KM requires EAPD */
2664eed65649STakashi Iwai 	    ! (ac97->subsystem_vendor == 0x1043 &&
2665eed65649STakashi Iwai 	       ac97->subsystem_device == 0x1103))
26661da177e4SLinus Torvalds 		val |= 0x03; /* enable */
26671da177e4SLinus Torvalds 	else
26681da177e4SLinus Torvalds 		val &= ~0x03; /* disable */
26691da177e4SLinus Torvalds 	snd_ac97_write_cache(ac97, AC97_ALC650_CLOCK, val);
26701da177e4SLinus Torvalds 
26711da177e4SLinus Torvalds 	/* set default: slot 3,4,7,8,6,9
26721da177e4SLinus Torvalds 	   spdif-in monitor off, analog-spdif off, spdif-in off
26731da177e4SLinus Torvalds 	   center on mic off, surround on line-in off
26741da177e4SLinus Torvalds 	   downmix off, duplicate front off
26751da177e4SLinus Torvalds 	*/
26761da177e4SLinus Torvalds 	snd_ac97_write_cache(ac97, AC97_ALC650_MULTICH, 0);
26771da177e4SLinus Torvalds 
26781da177e4SLinus Torvalds 	/* set GPIO0 for mic bias */
26791da177e4SLinus Torvalds 	/* GPIO0 pin output, no interrupt, high */
26801da177e4SLinus Torvalds 	snd_ac97_write_cache(ac97, AC97_ALC650_GPIO_SETUP,
26811da177e4SLinus Torvalds 			     snd_ac97_read(ac97, AC97_ALC650_GPIO_SETUP) | 0x01);
26821da177e4SLinus Torvalds 	snd_ac97_write_cache(ac97, AC97_ALC650_GPIO_STATUS,
26831da177e4SLinus Torvalds 			     (snd_ac97_read(ac97, AC97_ALC650_GPIO_STATUS) | 0x100) & ~0x10);
26841da177e4SLinus Torvalds 
26851da177e4SLinus Torvalds 	/* full DAC volume */
26861da177e4SLinus Torvalds 	snd_ac97_write_cache(ac97, AC97_ALC650_SURR_DAC_VOL, 0x0808);
26871da177e4SLinus Torvalds 	snd_ac97_write_cache(ac97, AC97_ALC650_LFE_DAC_VOL, 0x0808);
26881da177e4SLinus Torvalds 	return 0;
26891da177e4SLinus Torvalds }
26901da177e4SLinus Torvalds 
alc655_update_jacks(struct snd_ac97 * ac97)2691ee42381eSTakashi Iwai static void alc655_update_jacks(struct snd_ac97 *ac97)
26921da177e4SLinus Torvalds {
2693eb8caf30STakashi Iwai 	int shared;
26941da177e4SLinus Torvalds 
2695831466f4SRandy Cushman 	/* shared Line-In / Surround Out */
2696831466f4SRandy Cushman 	shared = is_shared_surrout(ac97);
2697eb8caf30STakashi Iwai 	ac97_update_bits_page(ac97, AC97_ALC650_MULTICH, 1 << 9,
2698eb8caf30STakashi Iwai 			      shared ? (1 << 9) : 0, 0);
2699831466f4SRandy Cushman 	/* update shared Mic In / Center/LFE Out */
2700831466f4SRandy Cushman 	shared = is_shared_clfeout(ac97);
27011da177e4SLinus Torvalds 	/* misc control; vrefout disable */
27021da177e4SLinus Torvalds 	snd_ac97_update_bits(ac97, AC97_ALC650_CLOCK, 1 << 12,
2703eb8caf30STakashi Iwai 			     shared ? (1 << 12) : 0);
2704eb8caf30STakashi Iwai 	ac97_update_bits_page(ac97, AC97_ALC650_MULTICH, 1 << 10,
2705eb8caf30STakashi Iwai 			      shared ? (1 << 10) : 0, 0);
27061da177e4SLinus Torvalds }
27071da177e4SLinus Torvalds 
2708ee42381eSTakashi Iwai static const struct snd_kcontrol_new snd_ac97_controls_alc655[] = {
27091da177e4SLinus Torvalds 	AC97_PAGE_SINGLE("Duplicate Front", AC97_ALC650_MULTICH, 0, 1, 0, 0),
2710eb8caf30STakashi Iwai 	AC97_SURROUND_JACK_MODE_CTL,
2711eb8caf30STakashi Iwai 	AC97_CHANNEL_MODE_CTL,
27121da177e4SLinus Torvalds };
27131da177e4SLinus Torvalds 
alc655_iec958_route_info(struct snd_kcontrol * kcontrol,struct snd_ctl_elem_info * uinfo)2714ee42381eSTakashi Iwai static int alc655_iec958_route_info(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_info *uinfo)
27151da177e4SLinus Torvalds {
27163b7a00dcSTakashi Iwai 	static const char * const texts_655[3] = {
27173b7a00dcSTakashi Iwai 		"PCM", "Analog In", "IEC958 In"
27183b7a00dcSTakashi Iwai 	};
27193b7a00dcSTakashi Iwai 	static const char * const texts_658[4] = {
27203b7a00dcSTakashi Iwai 		"PCM", "Analog1 In", "Analog2 In", "IEC958 In"
27213b7a00dcSTakashi Iwai 	};
2722ee42381eSTakashi Iwai 	struct snd_ac97 *ac97 = snd_kcontrol_chip(kcontrol);
27231da177e4SLinus Torvalds 
27243b7a00dcSTakashi Iwai 	if (ac97->spec.dev_flags)
27253b7a00dcSTakashi Iwai 		return snd_ctl_enum_info(uinfo, 1, 4, texts_658);
27263b7a00dcSTakashi Iwai 	else
27273b7a00dcSTakashi Iwai 		return snd_ctl_enum_info(uinfo, 1, 3, texts_655);
27281da177e4SLinus Torvalds }
27291da177e4SLinus Torvalds 
alc655_iec958_route_get(struct snd_kcontrol * kcontrol,struct snd_ctl_elem_value * ucontrol)2730ee42381eSTakashi Iwai static int alc655_iec958_route_get(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
27311da177e4SLinus Torvalds {
2732ee42381eSTakashi Iwai 	struct snd_ac97 *ac97 = snd_kcontrol_chip(kcontrol);
27331da177e4SLinus Torvalds 	unsigned short val;
27341da177e4SLinus Torvalds 
27351da177e4SLinus Torvalds 	val = ac97->regs[AC97_ALC650_MULTICH];
27361da177e4SLinus Torvalds 	val = (val >> 12) & 3;
27371da177e4SLinus Torvalds 	if (ac97->spec.dev_flags && val == 3)
27381da177e4SLinus Torvalds 		val = 0;
27391da177e4SLinus Torvalds 	ucontrol->value.enumerated.item[0] = val;
27401da177e4SLinus Torvalds 	return 0;
27411da177e4SLinus Torvalds }
27421da177e4SLinus Torvalds 
alc655_iec958_route_put(struct snd_kcontrol * kcontrol,struct snd_ctl_elem_value * ucontrol)2743ee42381eSTakashi Iwai static int alc655_iec958_route_put(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
27441da177e4SLinus Torvalds {
2745ee42381eSTakashi Iwai 	struct snd_ac97 *ac97 = snd_kcontrol_chip(kcontrol);
27461da177e4SLinus Torvalds 
27471da177e4SLinus Torvalds 	return ac97_update_bits_page(ac97, AC97_ALC650_MULTICH, 3 << 12,
27481da177e4SLinus Torvalds 				     (unsigned short)ucontrol->value.enumerated.item[0] << 12,
27491da177e4SLinus Torvalds 				     0);
27501da177e4SLinus Torvalds }
27511da177e4SLinus Torvalds 
2752ee42381eSTakashi Iwai static const struct snd_kcontrol_new snd_ac97_spdif_controls_alc655[] = {
275310e8d78aSClemens Ladisch         AC97_PAGE_SINGLE(SNDRV_CTL_NAME_IEC958("",CAPTURE,SWITCH), AC97_ALC650_MULTICH, 11, 1, 0, 0),
27541da177e4SLinus Torvalds 	/* disable this controls since it doesn't work as expected */
27551da177e4SLinus Torvalds         /* AC97_PAGE_SINGLE("IEC958 Input Monitor", AC97_ALC650_MULTICH, 14, 1, 0, 0), */
27561da177e4SLinus Torvalds 	{
27571da177e4SLinus Torvalds 		.iface  = SNDRV_CTL_ELEM_IFACE_MIXER,
2758031c95d4STakashi Iwai 		.name   = SNDRV_CTL_NAME_IEC958("",PLAYBACK,NONE) "Source",
27591da177e4SLinus Torvalds 		.info   = alc655_iec958_route_info,
27601da177e4SLinus Torvalds 		.get    = alc655_iec958_route_get,
27611da177e4SLinus Torvalds 		.put    = alc655_iec958_route_put,
27621da177e4SLinus Torvalds 	},
27631da177e4SLinus Torvalds };
27641da177e4SLinus Torvalds 
patch_alc655_specific(struct snd_ac97 * ac97)2765ee42381eSTakashi Iwai static int patch_alc655_specific(struct snd_ac97 * ac97)
27661da177e4SLinus Torvalds {
27671da177e4SLinus Torvalds 	int err;
27681da177e4SLinus Torvalds 
2769e66fd362STakashi Iwai 	err = patch_build_controls(ac97, snd_ac97_controls_alc655, ARRAY_SIZE(snd_ac97_controls_alc655));
2770e66fd362STakashi Iwai 	if (err < 0)
27711da177e4SLinus Torvalds 		return err;
27721da177e4SLinus Torvalds 	if (ac97->ext_id & AC97_EI_SPDIF) {
2773e66fd362STakashi Iwai 		err = patch_build_controls(ac97, snd_ac97_spdif_controls_alc655, ARRAY_SIZE(snd_ac97_spdif_controls_alc655));
2774e66fd362STakashi Iwai 		if (err < 0)
27751da177e4SLinus Torvalds 			return err;
27761da177e4SLinus Torvalds 	}
27771da177e4SLinus Torvalds 	return 0;
27781da177e4SLinus Torvalds }
27791da177e4SLinus Torvalds 
27803e8b3b90SHanno Boeck static const struct snd_ac97_build_ops patch_alc655_ops = {
2781eb8caf30STakashi Iwai 	.build_specific	= patch_alc655_specific,
2782eb8caf30STakashi Iwai 	.update_jacks = alc655_update_jacks
27831da177e4SLinus Torvalds };
27841da177e4SLinus Torvalds 
patch_alc655(struct snd_ac97 * ac97)2785ac519028STakashi Iwai static int patch_alc655(struct snd_ac97 * ac97)
27861da177e4SLinus Torvalds {
27871da177e4SLinus Torvalds 	unsigned int val;
27881da177e4SLinus Torvalds 
2789a5022b0dSTakashi Iwai 	if (ac97->id == AC97_ID_ALC658) {
2790a5022b0dSTakashi Iwai 		ac97->spec.dev_flags = 1; /* ALC658 */
2791a5022b0dSTakashi Iwai 		if ((snd_ac97_read(ac97, AC97_ALC650_REVISION) & 0x3f) == 2) {
2792a5022b0dSTakashi Iwai 			ac97->id = AC97_ID_ALC658D;
2793a5022b0dSTakashi Iwai 			ac97->spec.dev_flags = 2;
2794a5022b0dSTakashi Iwai 		}
2795a5022b0dSTakashi Iwai 	}
27961da177e4SLinus Torvalds 
27971da177e4SLinus Torvalds 	ac97->build_ops = &patch_alc655_ops;
27981da177e4SLinus Torvalds 
27991da177e4SLinus Torvalds 	/* assume only page 0 for writing cache */
28001da177e4SLinus Torvalds 	snd_ac97_update_bits(ac97, AC97_INT_PAGING, AC97_PAGE_MASK, AC97_PAGE_VENDOR);
28011da177e4SLinus Torvalds 
28021da177e4SLinus Torvalds 	/* adjust default values */
28031da177e4SLinus Torvalds 	val = snd_ac97_read(ac97, 0x7a); /* misc control */
2804a5022b0dSTakashi Iwai 	if (ac97->spec.dev_flags) /* ALC658 */
28051da177e4SLinus Torvalds 		val &= ~(1 << 1); /* Pin 47 is spdif input pin */
2806ee71508eSTakashi Iwai 	else { /* ALC655 */
2807ee71508eSTakashi Iwai 		if (ac97->subsystem_vendor == 0x1462 &&
2808d244bf89SMagnus Sandin 		    (ac97->subsystem_device == 0x0131 || /* MSI S270 laptop */
2809e7d24f0bSJaroslav Kysela 		     ac97->subsystem_device == 0x0161 || /* LG K1 Express */
2810cbcc2c4cSJerome Demange 		     ac97->subsystem_device == 0x0351 || /* MSI L725 laptop */
2811592a82e8STakashi Iwai 		     ac97->subsystem_device == 0x0471 || /* MSI L720 laptop */
2812cbcc2c4cSJerome Demange 		     ac97->subsystem_device == 0x0061))  /* MSI S250 laptop */
2813ee71508eSTakashi Iwai 			val &= ~(1 << 1); /* Pin 47 is EAPD (for internal speaker) */
2814ee71508eSTakashi Iwai 		else
28151da177e4SLinus Torvalds 			val |= (1 << 1); /* Pin 47 is spdif input pin */
2816c872e8caSTakashi Iwai 		/* this seems missing on some hardwares */
2817c872e8caSTakashi Iwai 		ac97->ext_id |= AC97_EI_SPDIF;
2818ee71508eSTakashi Iwai 	}
28191da177e4SLinus Torvalds 	val &= ~(1 << 12); /* vref enable */
28201da177e4SLinus Torvalds 	snd_ac97_write_cache(ac97, 0x7a, val);
28211da177e4SLinus Torvalds 	/* set default: spdif-in enabled,
28221da177e4SLinus Torvalds 	   spdif-in monitor off, spdif-in PCM off
28231da177e4SLinus Torvalds 	   center on mic off, surround on line-in off
28241da177e4SLinus Torvalds 	   duplicate front off
28251da177e4SLinus Torvalds 	*/
28261da177e4SLinus Torvalds 	snd_ac97_write_cache(ac97, AC97_ALC650_MULTICH, 1<<15);
28271da177e4SLinus Torvalds 
28281da177e4SLinus Torvalds 	/* full DAC volume */
28291da177e4SLinus Torvalds 	snd_ac97_write_cache(ac97, AC97_ALC650_SURR_DAC_VOL, 0x0808);
28301da177e4SLinus Torvalds 	snd_ac97_write_cache(ac97, AC97_ALC650_LFE_DAC_VOL, 0x0808);
2831a5022b0dSTakashi Iwai 
2832a5022b0dSTakashi Iwai 	/* update undocumented bit... */
2833a5022b0dSTakashi Iwai 	if (ac97->id == AC97_ID_ALC658D)
2834a5022b0dSTakashi Iwai 		snd_ac97_update_bits(ac97, 0x74, 0x0800, 0x0800);
2835a5022b0dSTakashi Iwai 
28361da177e4SLinus Torvalds 	return 0;
28371da177e4SLinus Torvalds }
28381da177e4SLinus Torvalds 
28391da177e4SLinus Torvalds 
28401da177e4SLinus Torvalds #define AC97_ALC850_JACK_SELECT	0x76
28411da177e4SLinus Torvalds #define AC97_ALC850_MISC1	0x7a
28424235a317STakashi Iwai #define AC97_ALC850_MULTICH    0x6a
28431da177e4SLinus Torvalds 
alc850_update_jacks(struct snd_ac97 * ac97)2844ee42381eSTakashi Iwai static void alc850_update_jacks(struct snd_ac97 *ac97)
28451da177e4SLinus Torvalds {
2846eb8caf30STakashi Iwai 	int shared;
28474235a317STakashi Iwai 	int aux_is_back_surround;
28481da177e4SLinus Torvalds 
2849831466f4SRandy Cushman 	/* shared Line-In / Surround Out */
2850831466f4SRandy Cushman 	shared = is_shared_surrout(ac97);
28511da177e4SLinus Torvalds 	/* SURR 1kOhm (bit4), Amp (bit5) */
28521da177e4SLinus Torvalds 	snd_ac97_update_bits(ac97, AC97_ALC850_MISC1, (1<<4)|(1<<5),
2853eb8caf30STakashi Iwai 			     shared ? (1<<5) : (1<<4));
28541da177e4SLinus Torvalds 	/* LINE-IN = 0, SURROUND = 2 */
2855eb8caf30STakashi Iwai 	snd_ac97_update_bits(ac97, AC97_ALC850_JACK_SELECT, 7 << 12,
2856eb8caf30STakashi Iwai 			     shared ? (2<<12) : (0<<12));
2857831466f4SRandy Cushman 	/* update shared Mic In / Center/LFE Out */
2858831466f4SRandy Cushman 	shared = is_shared_clfeout(ac97);
28591da177e4SLinus Torvalds 	/* Vref disable (bit12), 1kOhm (bit13) */
28601da177e4SLinus Torvalds 	snd_ac97_update_bits(ac97, AC97_ALC850_MISC1, (1<<12)|(1<<13),
2861eb8caf30STakashi Iwai 			     shared ? (1<<12) : (1<<13));
2862da79e44dSTakashi Iwai 	/* MIC-IN = 1, CENTER-LFE = 5 */
2863eb8caf30STakashi Iwai 	snd_ac97_update_bits(ac97, AC97_ALC850_JACK_SELECT, 7 << 4,
2864da79e44dSTakashi Iwai 			     shared ? (5<<4) : (1<<4));
28654235a317STakashi Iwai 
28664235a317STakashi Iwai 	aux_is_back_surround = alc850_is_aux_back_surround(ac97);
28674235a317STakashi Iwai 	/* Aux is Back Surround */
28684235a317STakashi Iwai 	snd_ac97_update_bits(ac97, AC97_ALC850_MULTICH, 1 << 10,
28694235a317STakashi Iwai 				 aux_is_back_surround ? (1<<10) : (0<<10));
28701da177e4SLinus Torvalds }
28711da177e4SLinus Torvalds 
2872ee42381eSTakashi Iwai static const struct snd_kcontrol_new snd_ac97_controls_alc850[] = {
28731da177e4SLinus Torvalds 	AC97_PAGE_SINGLE("Duplicate Front", AC97_ALC650_MULTICH, 0, 1, 0, 0),
287467e1b51eSSergey Vlasov 	AC97_SINGLE("Mic Front Input Switch", AC97_ALC850_JACK_SELECT, 15, 1, 1),
2875eb8caf30STakashi Iwai 	AC97_SURROUND_JACK_MODE_CTL,
28764235a317STakashi Iwai 	AC97_CHANNEL_MODE_8CH_CTL,
28771da177e4SLinus Torvalds };
28781da177e4SLinus Torvalds 
patch_alc850_specific(struct snd_ac97 * ac97)2879ee42381eSTakashi Iwai static int patch_alc850_specific(struct snd_ac97 *ac97)
28801da177e4SLinus Torvalds {
28811da177e4SLinus Torvalds 	int err;
28821da177e4SLinus Torvalds 
2883e66fd362STakashi Iwai 	err = patch_build_controls(ac97, snd_ac97_controls_alc850, ARRAY_SIZE(snd_ac97_controls_alc850));
2884e66fd362STakashi Iwai 	if (err < 0)
28851da177e4SLinus Torvalds 		return err;
28861da177e4SLinus Torvalds 	if (ac97->ext_id & AC97_EI_SPDIF) {
2887e66fd362STakashi Iwai 		err = patch_build_controls(ac97, snd_ac97_spdif_controls_alc655, ARRAY_SIZE(snd_ac97_spdif_controls_alc655));
2888e66fd362STakashi Iwai 		if (err < 0)
28891da177e4SLinus Torvalds 			return err;
28901da177e4SLinus Torvalds 	}
28911da177e4SLinus Torvalds 	return 0;
28921da177e4SLinus Torvalds }
28931da177e4SLinus Torvalds 
28943e8b3b90SHanno Boeck static const struct snd_ac97_build_ops patch_alc850_ops = {
2895eb8caf30STakashi Iwai 	.build_specific	= patch_alc850_specific,
2896eb8caf30STakashi Iwai 	.update_jacks = alc850_update_jacks
28971da177e4SLinus Torvalds };
28981da177e4SLinus Torvalds 
patch_alc850(struct snd_ac97 * ac97)2899ac519028STakashi Iwai static int patch_alc850(struct snd_ac97 *ac97)
29001da177e4SLinus Torvalds {
29011da177e4SLinus Torvalds 	ac97->build_ops = &patch_alc850_ops;
29021da177e4SLinus Torvalds 
29031da177e4SLinus Torvalds 	ac97->spec.dev_flags = 0; /* for IEC958 playback route - ALC655 compatible */
29044235a317STakashi Iwai 	ac97->flags |= AC97_HAS_8CH;
29051da177e4SLinus Torvalds 
29061da177e4SLinus Torvalds 	/* assume only page 0 for writing cache */
29071da177e4SLinus Torvalds 	snd_ac97_update_bits(ac97, AC97_INT_PAGING, AC97_PAGE_MASK, AC97_PAGE_VENDOR);
29081da177e4SLinus Torvalds 
29091da177e4SLinus Torvalds 	/* adjust default values */
29101da177e4SLinus Torvalds 	/* set default: spdif-in enabled,
29111da177e4SLinus Torvalds 	   spdif-in monitor off, spdif-in PCM off
29121da177e4SLinus Torvalds 	   center on mic off, surround on line-in off
29131da177e4SLinus Torvalds 	   duplicate front off
29144235a317STakashi Iwai 	   NB default bit 10=0 = Aux is Capture, not Back Surround
29151da177e4SLinus Torvalds 	*/
29161da177e4SLinus Torvalds 	snd_ac97_write_cache(ac97, AC97_ALC650_MULTICH, 1<<15);
29171da177e4SLinus Torvalds 	/* SURR_OUT: on, Surr 1kOhm: on, Surr Amp: off, Front 1kOhm: off
29181da177e4SLinus Torvalds 	 * Front Amp: on, Vref: enable, Center 1kOhm: on, Mix: on
29191da177e4SLinus Torvalds 	 */
29201da177e4SLinus Torvalds 	snd_ac97_write_cache(ac97, 0x7a, (1<<1)|(1<<4)|(0<<5)|(1<<6)|
29211da177e4SLinus Torvalds 			     (1<<7)|(0<<12)|(1<<13)|(0<<14));
29221da177e4SLinus Torvalds 	/* detection UIO2,3: all path floating, UIO3: MIC, Vref2: disable,
29231da177e4SLinus Torvalds 	 * UIO1: FRONT, Vref3: disable, UIO3: LINE, Front-Mic: mute
29241da177e4SLinus Torvalds 	 */
29251da177e4SLinus Torvalds 	snd_ac97_write_cache(ac97, 0x76, (0<<0)|(0<<2)|(1<<4)|(1<<7)|(2<<8)|
29261da177e4SLinus Torvalds 			     (1<<11)|(0<<12)|(1<<15));
29271da177e4SLinus Torvalds 
29281da177e4SLinus Torvalds 	/* full DAC volume */
29291da177e4SLinus Torvalds 	snd_ac97_write_cache(ac97, AC97_ALC650_SURR_DAC_VOL, 0x0808);
29301da177e4SLinus Torvalds 	snd_ac97_write_cache(ac97, AC97_ALC650_LFE_DAC_VOL, 0x0808);
29311da177e4SLinus Torvalds 	return 0;
29321da177e4SLinus Torvalds }
29331da177e4SLinus Torvalds 
patch_aztech_azf3328_specific(struct snd_ac97 * ac97)29346ba9256cSAndreas Mohr static int patch_aztech_azf3328_specific(struct snd_ac97 *ac97)
29356ba9256cSAndreas Mohr {
29366ba9256cSAndreas Mohr 	struct snd_kcontrol *kctl_3d_center =
29376ba9256cSAndreas Mohr 		snd_ac97_find_mixer_ctl(ac97, "3D Control - Center");
29386ba9256cSAndreas Mohr 	struct snd_kcontrol *kctl_3d_depth =
29396ba9256cSAndreas Mohr 		snd_ac97_find_mixer_ctl(ac97, "3D Control - Depth");
29406ba9256cSAndreas Mohr 
29416ba9256cSAndreas Mohr 	/*
29426ba9256cSAndreas Mohr 	 * 3D register is different from AC97 standard layout
29436ba9256cSAndreas Mohr 	 * (also do some renaming, to resemble Windows driver naming)
29446ba9256cSAndreas Mohr 	 */
29456ba9256cSAndreas Mohr 	if (kctl_3d_center) {
29466ba9256cSAndreas Mohr 		kctl_3d_center->private_value =
29476ba9256cSAndreas Mohr 			AC97_SINGLE_VALUE(AC97_3D_CONTROL, 1, 0x07, 0);
29486ba9256cSAndreas Mohr 		snd_ac97_rename_vol_ctl(ac97,
29496ba9256cSAndreas Mohr 			"3D Control - Center", "3D Control - Width"
29506ba9256cSAndreas Mohr 		);
29516ba9256cSAndreas Mohr 	}
29526ba9256cSAndreas Mohr 	if (kctl_3d_depth)
29536ba9256cSAndreas Mohr 		kctl_3d_depth->private_value =
29546ba9256cSAndreas Mohr 			AC97_SINGLE_VALUE(AC97_3D_CONTROL, 8, 0x03, 0);
29556ba9256cSAndreas Mohr 
29566ba9256cSAndreas Mohr 	/* Aztech Windows driver calls the
29576ba9256cSAndreas Mohr 	   equivalent control "Modem Playback", thus rename it: */
29586ba9256cSAndreas Mohr 	snd_ac97_rename_vol_ctl(ac97,
29596ba9256cSAndreas Mohr 		"Master Mono Playback", "Modem Playback"
29606ba9256cSAndreas Mohr 	);
29616ba9256cSAndreas Mohr 	snd_ac97_rename_vol_ctl(ac97,
29626ba9256cSAndreas Mohr 		"Headphone Playback", "FM Synth Playback"
29636ba9256cSAndreas Mohr 	);
29646ba9256cSAndreas Mohr 
29656ba9256cSAndreas Mohr 	return 0;
29666ba9256cSAndreas Mohr }
29676ba9256cSAndreas Mohr 
29686ba9256cSAndreas Mohr static const struct snd_ac97_build_ops patch_aztech_azf3328_ops = {
29696ba9256cSAndreas Mohr 	.build_specific	= patch_aztech_azf3328_specific
29706ba9256cSAndreas Mohr };
29716ba9256cSAndreas Mohr 
patch_aztech_azf3328(struct snd_ac97 * ac97)29726ba9256cSAndreas Mohr static int patch_aztech_azf3328(struct snd_ac97 *ac97)
29736ba9256cSAndreas Mohr {
29746ba9256cSAndreas Mohr 	ac97->build_ops = &patch_aztech_azf3328_ops;
29756ba9256cSAndreas Mohr 	return 0;
29766ba9256cSAndreas Mohr }
29771da177e4SLinus Torvalds 
29781da177e4SLinus Torvalds /*
29791da177e4SLinus Torvalds  * C-Media CM97xx codecs
29801da177e4SLinus Torvalds  */
cm9738_update_jacks(struct snd_ac97 * ac97)2981ee42381eSTakashi Iwai static void cm9738_update_jacks(struct snd_ac97 *ac97)
2982eb8caf30STakashi Iwai {
2983831466f4SRandy Cushman 	/* shared Line-In / Surround Out */
2984eb8caf30STakashi Iwai 	snd_ac97_update_bits(ac97, AC97_CM9738_VENDOR_CTRL, 1 << 10,
2985831466f4SRandy Cushman 			     is_shared_surrout(ac97) ? (1 << 10) : 0);
2986eb8caf30STakashi Iwai }
2987eb8caf30STakashi Iwai 
2988ee42381eSTakashi Iwai static const struct snd_kcontrol_new snd_ac97_cm9738_controls[] = {
29891da177e4SLinus Torvalds 	AC97_SINGLE("Duplicate Front", AC97_CM9738_VENDOR_CTRL, 13, 1, 0),
2990eb8caf30STakashi Iwai 	AC97_SURROUND_JACK_MODE_CTL,
2991eb8caf30STakashi Iwai 	AC97_CHANNEL_MODE_4CH_CTL,
29921da177e4SLinus Torvalds };
29931da177e4SLinus Torvalds 
patch_cm9738_specific(struct snd_ac97 * ac97)2994ee42381eSTakashi Iwai static int patch_cm9738_specific(struct snd_ac97 * ac97)
29951da177e4SLinus Torvalds {
29961da177e4SLinus Torvalds 	return patch_build_controls(ac97, snd_ac97_cm9738_controls, ARRAY_SIZE(snd_ac97_cm9738_controls));
29971da177e4SLinus Torvalds }
29981da177e4SLinus Torvalds 
29993e8b3b90SHanno Boeck static const struct snd_ac97_build_ops patch_cm9738_ops = {
3000eb8caf30STakashi Iwai 	.build_specific	= patch_cm9738_specific,
3001eb8caf30STakashi Iwai 	.update_jacks = cm9738_update_jacks
30021da177e4SLinus Torvalds };
30031da177e4SLinus Torvalds 
patch_cm9738(struct snd_ac97 * ac97)3004ac519028STakashi Iwai static int patch_cm9738(struct snd_ac97 * ac97)
30051da177e4SLinus Torvalds {
30061da177e4SLinus Torvalds 	ac97->build_ops = &patch_cm9738_ops;
30071da177e4SLinus Torvalds 	/* FIXME: can anyone confirm below? */
30081da177e4SLinus Torvalds 	/* CM9738 has no PCM volume although the register reacts */
30091da177e4SLinus Torvalds 	ac97->flags |= AC97_HAS_NO_PCM_VOL;
30101da177e4SLinus Torvalds 	snd_ac97_write_cache(ac97, AC97_PCM, 0x8000);
30111da177e4SLinus Torvalds 
30121da177e4SLinus Torvalds 	return 0;
30131da177e4SLinus Torvalds }
30141da177e4SLinus Torvalds 
snd_ac97_cmedia_spdif_playback_source_info(struct snd_kcontrol * kcontrol,struct snd_ctl_elem_info * uinfo)3015ee42381eSTakashi Iwai static int snd_ac97_cmedia_spdif_playback_source_info(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_info *uinfo)
30161da177e4SLinus Torvalds {
30173b7a00dcSTakashi Iwai 	static const char * const texts[] = { "Analog", "Digital" };
30181da177e4SLinus Torvalds 
30193b7a00dcSTakashi Iwai 	return snd_ctl_enum_info(uinfo, 1, 2, texts);
30201da177e4SLinus Torvalds }
30211da177e4SLinus Torvalds 
snd_ac97_cmedia_spdif_playback_source_get(struct snd_kcontrol * kcontrol,struct snd_ctl_elem_value * ucontrol)3022ee42381eSTakashi Iwai static int snd_ac97_cmedia_spdif_playback_source_get(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
30231da177e4SLinus Torvalds {
3024ee42381eSTakashi Iwai 	struct snd_ac97 *ac97 = snd_kcontrol_chip(kcontrol);
30251da177e4SLinus Torvalds 	unsigned short val;
30261da177e4SLinus Torvalds 
30271da177e4SLinus Torvalds 	val = ac97->regs[AC97_CM9739_SPDIF_CTRL];
30281da177e4SLinus Torvalds 	ucontrol->value.enumerated.item[0] = (val >> 1) & 0x01;
30291da177e4SLinus Torvalds 	return 0;
30301da177e4SLinus Torvalds }
30311da177e4SLinus Torvalds 
snd_ac97_cmedia_spdif_playback_source_put(struct snd_kcontrol * kcontrol,struct snd_ctl_elem_value * ucontrol)3032ee42381eSTakashi Iwai static int snd_ac97_cmedia_spdif_playback_source_put(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
30331da177e4SLinus Torvalds {
3034ee42381eSTakashi Iwai 	struct snd_ac97 *ac97 = snd_kcontrol_chip(kcontrol);
30351da177e4SLinus Torvalds 
30361da177e4SLinus Torvalds 	return snd_ac97_update_bits(ac97, AC97_CM9739_SPDIF_CTRL,
30371da177e4SLinus Torvalds 				    0x01 << 1,
30381da177e4SLinus Torvalds 				    (ucontrol->value.enumerated.item[0] & 0x01) << 1);
30391da177e4SLinus Torvalds }
30401da177e4SLinus Torvalds 
3041ee42381eSTakashi Iwai static const struct snd_kcontrol_new snd_ac97_cm9739_controls_spdif[] = {
30421da177e4SLinus Torvalds 	/* BIT 0: SPDI_EN - always true */
30431da177e4SLinus Torvalds 	{ /* BIT 1: SPDIFS */
30441da177e4SLinus Torvalds 		.iface	= SNDRV_CTL_ELEM_IFACE_MIXER,
30451da177e4SLinus Torvalds 		.name	= SNDRV_CTL_NAME_IEC958("",PLAYBACK,NONE) "Source",
30461da177e4SLinus Torvalds 		.info	= snd_ac97_cmedia_spdif_playback_source_info,
30471da177e4SLinus Torvalds 		.get	= snd_ac97_cmedia_spdif_playback_source_get,
30481da177e4SLinus Torvalds 		.put	= snd_ac97_cmedia_spdif_playback_source_put,
30491da177e4SLinus Torvalds 	},
30501da177e4SLinus Torvalds 	/* BIT 2: IG_SPIV */
30511da177e4SLinus Torvalds 	AC97_SINGLE(SNDRV_CTL_NAME_IEC958("",CAPTURE,NONE) "Valid Switch", AC97_CM9739_SPDIF_CTRL, 2, 1, 0),
30521da177e4SLinus Torvalds 	/* BIT 3: SPI2F */
30531da177e4SLinus Torvalds 	AC97_SINGLE(SNDRV_CTL_NAME_IEC958("",CAPTURE,NONE) "Monitor", AC97_CM9739_SPDIF_CTRL, 3, 1, 0),
30541da177e4SLinus Torvalds 	/* BIT 4: SPI2SDI */
30551da177e4SLinus Torvalds 	AC97_SINGLE(SNDRV_CTL_NAME_IEC958("",CAPTURE,SWITCH), AC97_CM9739_SPDIF_CTRL, 4, 1, 0),
30561da177e4SLinus Torvalds 	/* BIT 8: SPD32 - 32bit SPDIF - not supported yet */
30571da177e4SLinus Torvalds };
30581da177e4SLinus Torvalds 
cm9739_update_jacks(struct snd_ac97 * ac97)3059ee42381eSTakashi Iwai static void cm9739_update_jacks(struct snd_ac97 *ac97)
30601da177e4SLinus Torvalds {
3061831466f4SRandy Cushman 	/* shared Line-In / Surround Out */
3062eb8caf30STakashi Iwai 	snd_ac97_update_bits(ac97, AC97_CM9739_MULTI_CHAN, 1 << 10,
3063831466f4SRandy Cushman 			     is_shared_surrout(ac97) ? (1 << 10) : 0);
3064831466f4SRandy Cushman 	/* shared Mic In / Center/LFE Out **/
3065eb8caf30STakashi Iwai 	snd_ac97_update_bits(ac97, AC97_CM9739_MULTI_CHAN, 0x3000,
3066831466f4SRandy Cushman 			     is_shared_clfeout(ac97) ? 0x1000 : 0x2000);
30671da177e4SLinus Torvalds }
30681da177e4SLinus Torvalds 
3069ee42381eSTakashi Iwai static const struct snd_kcontrol_new snd_ac97_cm9739_controls[] = {
3070eb8caf30STakashi Iwai 	AC97_SURROUND_JACK_MODE_CTL,
3071eb8caf30STakashi Iwai 	AC97_CHANNEL_MODE_CTL,
30721da177e4SLinus Torvalds };
30731da177e4SLinus Torvalds 
patch_cm9739_specific(struct snd_ac97 * ac97)3074ee42381eSTakashi Iwai static int patch_cm9739_specific(struct snd_ac97 * ac97)
30751da177e4SLinus Torvalds {
30761da177e4SLinus Torvalds 	return patch_build_controls(ac97, snd_ac97_cm9739_controls, ARRAY_SIZE(snd_ac97_cm9739_controls));
30771da177e4SLinus Torvalds }
30781da177e4SLinus Torvalds 
patch_cm9739_post_spdif(struct snd_ac97 * ac97)3079ee42381eSTakashi Iwai static int patch_cm9739_post_spdif(struct snd_ac97 * ac97)
30801da177e4SLinus Torvalds {
30811da177e4SLinus Torvalds 	return patch_build_controls(ac97, snd_ac97_cm9739_controls_spdif, ARRAY_SIZE(snd_ac97_cm9739_controls_spdif));
30821da177e4SLinus Torvalds }
30831da177e4SLinus Torvalds 
30843e8b3b90SHanno Boeck static const struct snd_ac97_build_ops patch_cm9739_ops = {
30851da177e4SLinus Torvalds 	.build_specific	= patch_cm9739_specific,
3086eb8caf30STakashi Iwai 	.build_post_spdif = patch_cm9739_post_spdif,
3087eb8caf30STakashi Iwai 	.update_jacks = cm9739_update_jacks
30881da177e4SLinus Torvalds };
30891da177e4SLinus Torvalds 
patch_cm9739(struct snd_ac97 * ac97)3090ac519028STakashi Iwai static int patch_cm9739(struct snd_ac97 * ac97)
30911da177e4SLinus Torvalds {
30921da177e4SLinus Torvalds 	unsigned short val;
30931da177e4SLinus Torvalds 
30941da177e4SLinus Torvalds 	ac97->build_ops = &patch_cm9739_ops;
30951da177e4SLinus Torvalds 
30961da177e4SLinus Torvalds 	/* CM9739/A has no Master and PCM volume although the register reacts */
30971da177e4SLinus Torvalds 	ac97->flags |= AC97_HAS_NO_MASTER_VOL | AC97_HAS_NO_PCM_VOL;
30981da177e4SLinus Torvalds 	snd_ac97_write_cache(ac97, AC97_MASTER, 0x8000);
30991da177e4SLinus Torvalds 	snd_ac97_write_cache(ac97, AC97_PCM, 0x8000);
31001da177e4SLinus Torvalds 
31011da177e4SLinus Torvalds 	/* check spdif */
31021da177e4SLinus Torvalds 	val = snd_ac97_read(ac97, AC97_EXTENDED_STATUS);
31031da177e4SLinus Torvalds 	if (val & AC97_EA_SPCV) {
31041da177e4SLinus Torvalds 		/* enable spdif in */
31051da177e4SLinus Torvalds 		snd_ac97_write_cache(ac97, AC97_CM9739_SPDIF_CTRL,
31061da177e4SLinus Torvalds 				     snd_ac97_read(ac97, AC97_CM9739_SPDIF_CTRL) | 0x01);
31071da177e4SLinus Torvalds 		ac97->rates[AC97_RATES_SPDIF] = SNDRV_PCM_RATE_48000; /* 48k only */
31081da177e4SLinus Torvalds 	} else {
31091da177e4SLinus Torvalds 		ac97->ext_id &= ~AC97_EI_SPDIF; /* disable extended-id */
31101da177e4SLinus Torvalds 		ac97->rates[AC97_RATES_SPDIF] = 0;
31111da177e4SLinus Torvalds 	}
31121da177e4SLinus Torvalds 
31131da177e4SLinus Torvalds 	/* set-up multi channel */
31141da177e4SLinus Torvalds 	/* bit 14: 0 = SPDIF, 1 = EAPD */
31151da177e4SLinus Torvalds 	/* bit 13: enable internal vref output for mic */
311608a7e621SMasahiro Yamada 	/* bit 12: disable center/lfe (switchable) */
31171da177e4SLinus Torvalds 	/* bit 10: disable surround/line (switchable) */
31181da177e4SLinus Torvalds 	/* bit 9: mix 2 surround off */
31191da177e4SLinus Torvalds 	/* bit 4: undocumented; 0 mutes the CM9739A, which defaults to 1 */
31201da177e4SLinus Torvalds 	/* bit 3: undocumented; surround? */
31211da177e4SLinus Torvalds 	/* bit 0: dB */
31221da177e4SLinus Torvalds 	val = snd_ac97_read(ac97, AC97_CM9739_MULTI_CHAN) & (1 << 4);
31231da177e4SLinus Torvalds 	val |= (1 << 3);
31241da177e4SLinus Torvalds 	val |= (1 << 13);
31251da177e4SLinus Torvalds 	if (! (ac97->ext_id & AC97_EI_SPDIF))
31261da177e4SLinus Torvalds 		val |= (1 << 14);
31271da177e4SLinus Torvalds 	snd_ac97_write_cache(ac97, AC97_CM9739_MULTI_CHAN, val);
31281da177e4SLinus Torvalds 
31291da177e4SLinus Torvalds 	/* FIXME: set up GPIO */
31301da177e4SLinus Torvalds 	snd_ac97_write_cache(ac97, 0x70, 0x0100);
31311da177e4SLinus Torvalds 	snd_ac97_write_cache(ac97, 0x72, 0x0020);
31321da177e4SLinus Torvalds 	/* Special exception for ASUS W1000/CMI9739. It does not have an SPDIF in. */
31331da177e4SLinus Torvalds 	if (ac97->pci &&
31341da177e4SLinus Torvalds 	     ac97->subsystem_vendor == 0x1043 &&
31351da177e4SLinus Torvalds 	     ac97->subsystem_device == 0x1843) {
31361da177e4SLinus Torvalds 		snd_ac97_write_cache(ac97, AC97_CM9739_SPDIF_CTRL,
31371da177e4SLinus Torvalds 			snd_ac97_read(ac97, AC97_CM9739_SPDIF_CTRL) & ~0x01);
31381da177e4SLinus Torvalds 		snd_ac97_write_cache(ac97, AC97_CM9739_MULTI_CHAN,
31391da177e4SLinus Torvalds 			snd_ac97_read(ac97, AC97_CM9739_MULTI_CHAN) | (1 << 14));
31401da177e4SLinus Torvalds 	}
31411da177e4SLinus Torvalds 
31421da177e4SLinus Torvalds 	return 0;
31431da177e4SLinus Torvalds }
31441da177e4SLinus Torvalds 
31451da177e4SLinus Torvalds #define AC97_CM9761_MULTI_CHAN	0x64
31465f0dccf8STakashi Iwai #define AC97_CM9761_FUNC	0x66
31471da177e4SLinus Torvalds #define AC97_CM9761_SPDIF_CTRL	0x6c
31481da177e4SLinus Torvalds 
cm9761_update_jacks(struct snd_ac97 * ac97)3149ee42381eSTakashi Iwai static void cm9761_update_jacks(struct snd_ac97 *ac97)
31501da177e4SLinus Torvalds {
31514525c9f3STakashi Iwai 	/* FIXME: check the bits for each model
31524525c9f3STakashi Iwai 	 *        model 83 is confirmed to work
31534525c9f3STakashi Iwai 	 */
31541675bfc0STakashi Iwai 	static const unsigned short surr_on[3][2] = {
31554525c9f3STakashi Iwai 		{ 0x0008, 0x0000 }, /* 9761-78 & 82 */
31564525c9f3STakashi Iwai 		{ 0x0000, 0x0008 }, /* 9761-82 rev.B */
31574525c9f3STakashi Iwai 		{ 0x0000, 0x0008 }, /* 9761-83 */
31581da177e4SLinus Torvalds 	};
31591675bfc0STakashi Iwai 	static const unsigned short clfe_on[3][2] = {
31604525c9f3STakashi Iwai 		{ 0x0000, 0x1000 }, /* 9761-78 & 82 */
31614525c9f3STakashi Iwai 		{ 0x1000, 0x0000 }, /* 9761-82 rev.B */
31624525c9f3STakashi Iwai 		{ 0x0000, 0x1000 }, /* 9761-83 */
31631da177e4SLinus Torvalds 	};
31641675bfc0STakashi Iwai 	static const unsigned short surr_shared[3][2] = {
31654525c9f3STakashi Iwai 		{ 0x0000, 0x0400 }, /* 9761-78 & 82 */
31664525c9f3STakashi Iwai 		{ 0x0000, 0x0400 }, /* 9761-82 rev.B */
31674525c9f3STakashi Iwai 		{ 0x0000, 0x0400 }, /* 9761-83 */
31684525c9f3STakashi Iwai 	};
31691675bfc0STakashi Iwai 	static const unsigned short clfe_shared[3][2] = {
31704525c9f3STakashi Iwai 		{ 0x2000, 0x0880 }, /* 9761-78 & 82 */
31714525c9f3STakashi Iwai 		{ 0x0000, 0x2880 }, /* 9761-82 rev.B */
31724525c9f3STakashi Iwai 		{ 0x2000, 0x0800 }, /* 9761-83 */
31734525c9f3STakashi Iwai 	};
31744525c9f3STakashi Iwai 	unsigned short val = 0;
3175eb8caf30STakashi Iwai 
31764525c9f3STakashi Iwai 	val |= surr_on[ac97->spec.dev_flags][is_surround_on(ac97)];
31774525c9f3STakashi Iwai 	val |= clfe_on[ac97->spec.dev_flags][is_clfe_on(ac97)];
3178831466f4SRandy Cushman 	val |= surr_shared[ac97->spec.dev_flags][is_shared_surrout(ac97)];
3179831466f4SRandy Cushman 	val |= clfe_shared[ac97->spec.dev_flags][is_shared_clfeout(ac97)];
31804525c9f3STakashi Iwai 
31814525c9f3STakashi Iwai 	snd_ac97_update_bits(ac97, AC97_CM9761_MULTI_CHAN, 0x3c88, val);
31821da177e4SLinus Torvalds }
31831da177e4SLinus Torvalds 
3184ee42381eSTakashi Iwai static const struct snd_kcontrol_new snd_ac97_cm9761_controls[] = {
3185eb8caf30STakashi Iwai 	AC97_SURROUND_JACK_MODE_CTL,
3186eb8caf30STakashi Iwai 	AC97_CHANNEL_MODE_CTL,
31871da177e4SLinus Torvalds };
31881da177e4SLinus Torvalds 
cm9761_spdif_out_source_info(struct snd_kcontrol * kcontrol,struct snd_ctl_elem_info * uinfo)3189ee42381eSTakashi Iwai static int cm9761_spdif_out_source_info(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_info *uinfo)
31905f0dccf8STakashi Iwai {
31913b7a00dcSTakashi Iwai 	static const char * const texts[] = { "AC-Link", "ADC", "SPDIF-In" };
31925f0dccf8STakashi Iwai 
31933b7a00dcSTakashi Iwai 	return snd_ctl_enum_info(uinfo, 1, 3, texts);
31945f0dccf8STakashi Iwai }
31955f0dccf8STakashi Iwai 
cm9761_spdif_out_source_get(struct snd_kcontrol * kcontrol,struct snd_ctl_elem_value * ucontrol)3196ee42381eSTakashi Iwai static int cm9761_spdif_out_source_get(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
31975f0dccf8STakashi Iwai {
3198ee42381eSTakashi Iwai 	struct snd_ac97 *ac97 = snd_kcontrol_chip(kcontrol);
31995f0dccf8STakashi Iwai 
32005f0dccf8STakashi Iwai 	if (ac97->regs[AC97_CM9761_FUNC] & 0x1)
32015f0dccf8STakashi Iwai 		ucontrol->value.enumerated.item[0] = 2; /* SPDIF-loopback */
32025f0dccf8STakashi Iwai 	else if (ac97->regs[AC97_CM9761_SPDIF_CTRL] & 0x2)
32035f0dccf8STakashi Iwai 		ucontrol->value.enumerated.item[0] = 1; /* ADC loopback */
32045f0dccf8STakashi Iwai 	else
32055f0dccf8STakashi Iwai 		ucontrol->value.enumerated.item[0] = 0; /* AC-link */
32065f0dccf8STakashi Iwai 	return 0;
32075f0dccf8STakashi Iwai }
32085f0dccf8STakashi Iwai 
cm9761_spdif_out_source_put(struct snd_kcontrol * kcontrol,struct snd_ctl_elem_value * ucontrol)3209ee42381eSTakashi Iwai static int cm9761_spdif_out_source_put(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
32105f0dccf8STakashi Iwai {
3211ee42381eSTakashi Iwai 	struct snd_ac97 *ac97 = snd_kcontrol_chip(kcontrol);
32125f0dccf8STakashi Iwai 
32135f0dccf8STakashi Iwai 	if (ucontrol->value.enumerated.item[0] == 2)
32145f0dccf8STakashi Iwai 		return snd_ac97_update_bits(ac97, AC97_CM9761_FUNC, 0x1, 0x1);
32155f0dccf8STakashi Iwai 	snd_ac97_update_bits(ac97, AC97_CM9761_FUNC, 0x1, 0);
32165f0dccf8STakashi Iwai 	return snd_ac97_update_bits(ac97, AC97_CM9761_SPDIF_CTRL, 0x2,
32175f0dccf8STakashi Iwai 				    ucontrol->value.enumerated.item[0] == 1 ? 0x2 : 0);
32185f0dccf8STakashi Iwai }
32195f0dccf8STakashi Iwai 
32201bc10bb6STakashi Iwai static const char * const cm9761_dac_clock[] = {
32211bc10bb6STakashi Iwai 	"AC-Link", "SPDIF-In", "Both"
32221bc10bb6STakashi Iwai };
32235f0dccf8STakashi Iwai static const struct ac97_enum cm9761_dac_clock_enum =
32245f0dccf8STakashi Iwai 	AC97_ENUM_SINGLE(AC97_CM9761_SPDIF_CTRL, 9, 3, cm9761_dac_clock);
32255f0dccf8STakashi Iwai 
3226ee42381eSTakashi Iwai static const struct snd_kcontrol_new snd_ac97_cm9761_controls_spdif[] = {
32275f0dccf8STakashi Iwai 	{ /* BIT 1: SPDIFS */
32285f0dccf8STakashi Iwai 		.iface	= SNDRV_CTL_ELEM_IFACE_MIXER,
32295f0dccf8STakashi Iwai 		.name	= SNDRV_CTL_NAME_IEC958("",PLAYBACK,NONE) "Source",
32305f0dccf8STakashi Iwai 		.info = cm9761_spdif_out_source_info,
32315f0dccf8STakashi Iwai 		.get = cm9761_spdif_out_source_get,
32325f0dccf8STakashi Iwai 		.put = cm9761_spdif_out_source_put,
32335f0dccf8STakashi Iwai 	},
32345f0dccf8STakashi Iwai 	/* BIT 2: IG_SPIV */
32355f0dccf8STakashi Iwai 	AC97_SINGLE(SNDRV_CTL_NAME_IEC958("",CAPTURE,NONE) "Valid Switch", AC97_CM9761_SPDIF_CTRL, 2, 1, 0),
32365f0dccf8STakashi Iwai 	/* BIT 3: SPI2F */
32375f0dccf8STakashi Iwai 	AC97_SINGLE(SNDRV_CTL_NAME_IEC958("",CAPTURE,NONE) "Monitor", AC97_CM9761_SPDIF_CTRL, 3, 1, 0),
32385f0dccf8STakashi Iwai 	/* BIT 4: SPI2SDI */
32395f0dccf8STakashi Iwai 	AC97_SINGLE(SNDRV_CTL_NAME_IEC958("",CAPTURE,SWITCH), AC97_CM9761_SPDIF_CTRL, 4, 1, 0),
32405f0dccf8STakashi Iwai 	/* BIT 9-10: DAC_CTL */
32415f0dccf8STakashi Iwai 	AC97_ENUM("DAC Clock Source", cm9761_dac_clock_enum),
32425f0dccf8STakashi Iwai };
32435f0dccf8STakashi Iwai 
patch_cm9761_post_spdif(struct snd_ac97 * ac97)3244ee42381eSTakashi Iwai static int patch_cm9761_post_spdif(struct snd_ac97 * ac97)
32455f0dccf8STakashi Iwai {
32465f0dccf8STakashi Iwai 	return patch_build_controls(ac97, snd_ac97_cm9761_controls_spdif, ARRAY_SIZE(snd_ac97_cm9761_controls_spdif));
32475f0dccf8STakashi Iwai }
32485f0dccf8STakashi Iwai 
patch_cm9761_specific(struct snd_ac97 * ac97)3249ee42381eSTakashi Iwai static int patch_cm9761_specific(struct snd_ac97 * ac97)
32501da177e4SLinus Torvalds {
32511da177e4SLinus Torvalds 	return patch_build_controls(ac97, snd_ac97_cm9761_controls, ARRAY_SIZE(snd_ac97_cm9761_controls));
32521da177e4SLinus Torvalds }
32531da177e4SLinus Torvalds 
32543e8b3b90SHanno Boeck static const struct snd_ac97_build_ops patch_cm9761_ops = {
32551da177e4SLinus Torvalds 	.build_specific	= patch_cm9761_specific,
3256eb8caf30STakashi Iwai 	.build_post_spdif = patch_cm9761_post_spdif,
3257eb8caf30STakashi Iwai 	.update_jacks = cm9761_update_jacks
32581da177e4SLinus Torvalds };
32591da177e4SLinus Torvalds 
patch_cm9761(struct snd_ac97 * ac97)3260ac519028STakashi Iwai static int patch_cm9761(struct snd_ac97 *ac97)
32611da177e4SLinus Torvalds {
32621da177e4SLinus Torvalds 	unsigned short val;
32631da177e4SLinus Torvalds 
32641da177e4SLinus Torvalds 	/* CM9761 has no PCM volume although the register reacts */
32651da177e4SLinus Torvalds 	/* Master volume seems to have _some_ influence on the analog
32661da177e4SLinus Torvalds 	 * input sounds
32671da177e4SLinus Torvalds 	 */
32681da177e4SLinus Torvalds 	ac97->flags |= /*AC97_HAS_NO_MASTER_VOL |*/ AC97_HAS_NO_PCM_VOL;
32691da177e4SLinus Torvalds 	snd_ac97_write_cache(ac97, AC97_MASTER, 0x8808);
32701da177e4SLinus Torvalds 	snd_ac97_write_cache(ac97, AC97_PCM, 0x8808);
32711da177e4SLinus Torvalds 
32724525c9f3STakashi Iwai 	ac97->spec.dev_flags = 0; /* 1 = model 82 revision B, 2 = model 83 */
32731da177e4SLinus Torvalds 	if (ac97->id == AC97_ID_CM9761_82) {
32741da177e4SLinus Torvalds 		unsigned short tmp;
32751da177e4SLinus Torvalds 		/* check page 1, reg 0x60 */
32761da177e4SLinus Torvalds 		val = snd_ac97_read(ac97, AC97_INT_PAGING);
32771da177e4SLinus Torvalds 		snd_ac97_write_cache(ac97, AC97_INT_PAGING, (val & ~0x0f) | 0x01);
32781da177e4SLinus Torvalds 		tmp = snd_ac97_read(ac97, 0x60);
32791da177e4SLinus Torvalds 		ac97->spec.dev_flags = tmp & 1; /* revision B? */
32801da177e4SLinus Torvalds 		snd_ac97_write_cache(ac97, AC97_INT_PAGING, val);
32814525c9f3STakashi Iwai 	} else if (ac97->id == AC97_ID_CM9761_83)
32824525c9f3STakashi Iwai 		ac97->spec.dev_flags = 2;
32831da177e4SLinus Torvalds 
32841da177e4SLinus Torvalds 	ac97->build_ops = &patch_cm9761_ops;
32851da177e4SLinus Torvalds 
32861da177e4SLinus Torvalds 	/* enable spdif */
32871da177e4SLinus Torvalds 	/* force the SPDIF bit in ext_id - codec doesn't set this bit! */
32881da177e4SLinus Torvalds         ac97->ext_id |= AC97_EI_SPDIF;
32891da177e4SLinus Torvalds 	/* to be sure: we overwrite the ext status bits */
32901da177e4SLinus Torvalds 	snd_ac97_write_cache(ac97, AC97_EXTENDED_STATUS, 0x05c0);
32911da177e4SLinus Torvalds 	/* Don't set 0x0200 here.  This results in the silent analog output */
32925f0dccf8STakashi Iwai 	snd_ac97_write_cache(ac97, AC97_CM9761_SPDIF_CTRL, 0x0001); /* enable spdif-in */
32931da177e4SLinus Torvalds 	ac97->rates[AC97_RATES_SPDIF] = SNDRV_PCM_RATE_48000; /* 48k only */
32941da177e4SLinus Torvalds 
32951da177e4SLinus Torvalds 	/* set-up multi channel */
32961da177e4SLinus Torvalds 	/* bit 15: pc master beep off
32975f0dccf8STakashi Iwai 	 * bit 14: pin47 = EAPD/SPDIF
32981da177e4SLinus Torvalds 	 * bit 13: vref ctl [= cm9739]
32995f0dccf8STakashi Iwai 	 * bit 12: CLFE control (reverted on rev B)
33005f0dccf8STakashi Iwai 	 * bit 11: Mic/center share (reverted on rev B)
33015f0dccf8STakashi Iwai 	 * bit 10: suddound/line share
33025f0dccf8STakashi Iwai 	 * bit  9: Analog-in mix -> surround
33035f0dccf8STakashi Iwai 	 * bit  8: Analog-in mix -> CLFE
33045f0dccf8STakashi Iwai 	 * bit  7: Mic/LFE share (mic/center/lfe)
33055f0dccf8STakashi Iwai 	 * bit  5: vref select (9761A)
33065f0dccf8STakashi Iwai 	 * bit  4: front control
33075f0dccf8STakashi Iwai 	 * bit  3: surround control (revereted with rev B)
33085f0dccf8STakashi Iwai 	 * bit  2: front mic
33095f0dccf8STakashi Iwai 	 * bit  1: stereo mic
33105f0dccf8STakashi Iwai 	 * bit  0: mic boost level (0=20dB, 1=30dB)
33111da177e4SLinus Torvalds 	 */
33121da177e4SLinus Torvalds 
33131da177e4SLinus Torvalds #if 0
33141da177e4SLinus Torvalds 	if (ac97->spec.dev_flags)
33151da177e4SLinus Torvalds 		val = 0x0214;
33161da177e4SLinus Torvalds 	else
33171da177e4SLinus Torvalds 		val = 0x321c;
33181da177e4SLinus Torvalds #endif
33191da177e4SLinus Torvalds 	val = snd_ac97_read(ac97, AC97_CM9761_MULTI_CHAN);
33201da177e4SLinus Torvalds 	val |= (1 << 4); /* front on */
33211da177e4SLinus Torvalds 	snd_ac97_write_cache(ac97, AC97_CM9761_MULTI_CHAN, val);
33221da177e4SLinus Torvalds 
33231da177e4SLinus Torvalds 	/* FIXME: set up GPIO */
33241da177e4SLinus Torvalds 	snd_ac97_write_cache(ac97, 0x70, 0x0100);
33251da177e4SLinus Torvalds 	snd_ac97_write_cache(ac97, 0x72, 0x0020);
33261da177e4SLinus Torvalds 
33271da177e4SLinus Torvalds 	return 0;
33281da177e4SLinus Torvalds }
33291da177e4SLinus Torvalds 
33305f0dccf8STakashi Iwai #define AC97_CM9780_SIDE	0x60
33315f0dccf8STakashi Iwai #define AC97_CM9780_JACK	0x62
33325f0dccf8STakashi Iwai #define AC97_CM9780_MIXER	0x64
33335f0dccf8STakashi Iwai #define AC97_CM9780_MULTI_CHAN	0x66
33345f0dccf8STakashi Iwai #define AC97_CM9780_SPDIF	0x6c
33355f0dccf8STakashi Iwai 
33361bc10bb6STakashi Iwai static const char * const cm9780_ch_select[] = {
33371bc10bb6STakashi Iwai 	"Front", "Side", "Center/LFE", "Rear"
33381bc10bb6STakashi Iwai };
33395f0dccf8STakashi Iwai static const struct ac97_enum cm9780_ch_select_enum =
33405f0dccf8STakashi Iwai 	AC97_ENUM_SINGLE(AC97_CM9780_MULTI_CHAN, 6, 4, cm9780_ch_select);
3341ee42381eSTakashi Iwai static const struct snd_kcontrol_new cm9780_controls[] = {
33425f0dccf8STakashi Iwai 	AC97_DOUBLE("Side Playback Switch", AC97_CM9780_SIDE, 15, 7, 1, 1),
33435f0dccf8STakashi Iwai 	AC97_DOUBLE("Side Playback Volume", AC97_CM9780_SIDE, 8, 0, 31, 0),
33445f0dccf8STakashi Iwai 	AC97_ENUM("Side Playback Route", cm9780_ch_select_enum),
33455f0dccf8STakashi Iwai };
33465f0dccf8STakashi Iwai 
patch_cm9780_specific(struct snd_ac97 * ac97)3347ee42381eSTakashi Iwai static int patch_cm9780_specific(struct snd_ac97 *ac97)
33485f0dccf8STakashi Iwai {
33495f0dccf8STakashi Iwai 	return patch_build_controls(ac97, cm9780_controls, ARRAY_SIZE(cm9780_controls));
33505f0dccf8STakashi Iwai }
33515f0dccf8STakashi Iwai 
33523e8b3b90SHanno Boeck static const struct snd_ac97_build_ops patch_cm9780_ops = {
33535f0dccf8STakashi Iwai 	.build_specific	= patch_cm9780_specific,
33545f0dccf8STakashi Iwai 	.build_post_spdif = patch_cm9761_post_spdif	/* identical with CM9761 */
33555f0dccf8STakashi Iwai };
33565f0dccf8STakashi Iwai 
patch_cm9780(struct snd_ac97 * ac97)3357ac519028STakashi Iwai static int patch_cm9780(struct snd_ac97 *ac97)
33585f0dccf8STakashi Iwai {
33595f0dccf8STakashi Iwai 	unsigned short val;
33605f0dccf8STakashi Iwai 
33615f0dccf8STakashi Iwai 	ac97->build_ops = &patch_cm9780_ops;
33625f0dccf8STakashi Iwai 
33635f0dccf8STakashi Iwai 	/* enable spdif */
33645f0dccf8STakashi Iwai 	if (ac97->ext_id & AC97_EI_SPDIF) {
33655f0dccf8STakashi Iwai 		ac97->rates[AC97_RATES_SPDIF] = SNDRV_PCM_RATE_48000; /* 48k only */
33665f0dccf8STakashi Iwai 		val = snd_ac97_read(ac97, AC97_CM9780_SPDIF);
33675f0dccf8STakashi Iwai 		val |= 0x1; /* SPDI_EN */
33685f0dccf8STakashi Iwai 		snd_ac97_write_cache(ac97, AC97_CM9780_SPDIF, val);
33695f0dccf8STakashi Iwai 	}
33705f0dccf8STakashi Iwai 
33715f0dccf8STakashi Iwai 	return 0;
33725f0dccf8STakashi Iwai }
33731da177e4SLinus Torvalds 
33741da177e4SLinus Torvalds /*
3375d6482288SMaciej S. Szmigiero  * VIA VT1613 codec
3376d6482288SMaciej S. Szmigiero  */
3377d6482288SMaciej S. Szmigiero static const struct snd_kcontrol_new snd_ac97_controls_vt1613[] = {
3378d6482288SMaciej S. Szmigiero AC97_SINGLE("DC Offset removal", 0x5a, 10, 1, 0),
3379d6482288SMaciej S. Szmigiero };
3380d6482288SMaciej S. Szmigiero 
patch_vt1613_specific(struct snd_ac97 * ac97)3381d6482288SMaciej S. Szmigiero static int patch_vt1613_specific(struct snd_ac97 *ac97)
3382d6482288SMaciej S. Szmigiero {
33835371fc0eSFabio Estevam 	return patch_build_controls(ac97, &snd_ac97_controls_vt1613[0],
3384d6482288SMaciej S. Szmigiero 				    ARRAY_SIZE(snd_ac97_controls_vt1613));
3385d6482288SMaciej S. Szmigiero };
3386d6482288SMaciej S. Szmigiero 
3387d6482288SMaciej S. Szmigiero static const struct snd_ac97_build_ops patch_vt1613_ops = {
3388d6482288SMaciej S. Szmigiero 	.build_specific	= patch_vt1613_specific
3389d6482288SMaciej S. Szmigiero };
3390d6482288SMaciej S. Szmigiero 
patch_vt1613(struct snd_ac97 * ac97)3391d6482288SMaciej S. Szmigiero static int patch_vt1613(struct snd_ac97 *ac97)
3392d6482288SMaciej S. Szmigiero {
3393d6482288SMaciej S. Szmigiero 	ac97->build_ops = &patch_vt1613_ops;
3394d6482288SMaciej S. Szmigiero 
3395d6482288SMaciej S. Szmigiero 	ac97->flags |= AC97_HAS_NO_VIDEO;
3396d6482288SMaciej S. Szmigiero 	ac97->caps |= AC97_BC_HEADPHONE;
3397d6482288SMaciej S. Szmigiero 
3398d6482288SMaciej S. Szmigiero 	return 0;
3399d6482288SMaciej S. Szmigiero }
3400d6482288SMaciej S. Szmigiero 
3401d6482288SMaciej S. Szmigiero /*
34021da177e4SLinus Torvalds  * VIA VT1616 codec
34031da177e4SLinus Torvalds  */
3404ee42381eSTakashi Iwai static const struct snd_kcontrol_new snd_ac97_controls_vt1616[] = {
34051da177e4SLinus Torvalds AC97_SINGLE("DC Offset removal", 0x5a, 10, 1, 0),
34061da177e4SLinus Torvalds AC97_SINGLE("Alternate Level to Surround Out", 0x5a, 15, 1, 0),
34071da177e4SLinus Torvalds AC97_SINGLE("Downmix LFE and Center to Front", 0x5a, 12, 1, 0),
34081da177e4SLinus Torvalds AC97_SINGLE("Downmix Surround to Front", 0x5a, 11, 1, 0),
34091da177e4SLinus Torvalds };
34101da177e4SLinus Torvalds 
34119ab0cb30STakashi Iwai static const char * const follower_vols_vt1616[] = {
341287af38daSDaniel Jacobowitz 	"Front Playback Volume",
341387af38daSDaniel Jacobowitz 	"Surround Playback Volume",
341487af38daSDaniel Jacobowitz 	"Center Playback Volume",
341587af38daSDaniel Jacobowitz 	"LFE Playback Volume",
341687af38daSDaniel Jacobowitz 	NULL
341787af38daSDaniel Jacobowitz };
341887af38daSDaniel Jacobowitz 
34199ab0cb30STakashi Iwai static const char * const follower_sws_vt1616[] = {
342087af38daSDaniel Jacobowitz 	"Front Playback Switch",
342187af38daSDaniel Jacobowitz 	"Surround Playback Switch",
342287af38daSDaniel Jacobowitz 	"Center Playback Switch",
342387af38daSDaniel Jacobowitz 	"LFE Playback Switch",
342487af38daSDaniel Jacobowitz 	NULL
342587af38daSDaniel Jacobowitz };
342687af38daSDaniel Jacobowitz 
342787af38daSDaniel Jacobowitz /* find a mixer control element with the given name */
snd_ac97_find_mixer_ctl(struct snd_ac97 * ac97,const char * name)342887af38daSDaniel Jacobowitz static struct snd_kcontrol *snd_ac97_find_mixer_ctl(struct snd_ac97 *ac97,
342987af38daSDaniel Jacobowitz 						    const char *name)
343087af38daSDaniel Jacobowitz {
3431ebc1bfebSTakashi Iwai 	return snd_ctl_find_id_mixer(ac97->bus->card, name);
343287af38daSDaniel Jacobowitz }
343387af38daSDaniel Jacobowitz 
34349ab0cb30STakashi Iwai /* create a virtual master control and add followers */
snd_ac97_add_vmaster(struct snd_ac97 * ac97,char * name,const unsigned int * tlv,const char * const * followers)343513c2108dSAdrian Bunk static int snd_ac97_add_vmaster(struct snd_ac97 *ac97, char *name,
34361bc10bb6STakashi Iwai 				const unsigned int *tlv,
34379ab0cb30STakashi Iwai 				const char * const *followers)
343887af38daSDaniel Jacobowitz {
343987af38daSDaniel Jacobowitz 	struct snd_kcontrol *kctl;
344087af38daSDaniel Jacobowitz 	int err;
344187af38daSDaniel Jacobowitz 
344287af38daSDaniel Jacobowitz 	kctl = snd_ctl_make_virtual_master(name, tlv);
344387af38daSDaniel Jacobowitz 	if (!kctl)
344487af38daSDaniel Jacobowitz 		return -ENOMEM;
344587af38daSDaniel Jacobowitz 	err = snd_ctl_add(ac97->bus->card, kctl);
344687af38daSDaniel Jacobowitz 	if (err < 0)
344787af38daSDaniel Jacobowitz 		return err;
344887af38daSDaniel Jacobowitz 
34491caf64d9STakashi Iwai 	return snd_ctl_add_followers(ac97->bus->card, kctl, followers);
345087af38daSDaniel Jacobowitz }
345187af38daSDaniel Jacobowitz 
patch_vt1616_specific(struct snd_ac97 * ac97)3452ee42381eSTakashi Iwai static int patch_vt1616_specific(struct snd_ac97 * ac97)
34531da177e4SLinus Torvalds {
345487af38daSDaniel Jacobowitz 	struct snd_kcontrol *kctl;
34551da177e4SLinus Torvalds 	int err;
34561da177e4SLinus Torvalds 
3457e66fd362STakashi Iwai 	if (snd_ac97_try_bit(ac97, 0x5a, 9)) {
3458e66fd362STakashi Iwai 		err = patch_build_controls(ac97, &snd_ac97_controls_vt1616[0], 1);
3459e66fd362STakashi Iwai 		if (err < 0)
34601da177e4SLinus Torvalds 			return err;
3461e66fd362STakashi Iwai 	}
3462e66fd362STakashi Iwai 	err = patch_build_controls(ac97, &snd_ac97_controls_vt1616[1], ARRAY_SIZE(snd_ac97_controls_vt1616) - 1);
3463e66fd362STakashi Iwai 	if (err < 0)
34641da177e4SLinus Torvalds 		return err;
346587af38daSDaniel Jacobowitz 
346687af38daSDaniel Jacobowitz 	/* There is already a misnamed master switch.  Rename it.  */
346787af38daSDaniel Jacobowitz 	kctl = snd_ac97_find_mixer_ctl(ac97, "Master Playback Volume");
346887af38daSDaniel Jacobowitz 	if (!kctl)
346987af38daSDaniel Jacobowitz 		return -EINVAL;
347087af38daSDaniel Jacobowitz 
347187af38daSDaniel Jacobowitz 	snd_ac97_rename_vol_ctl(ac97, "Master Playback", "Front Playback");
347287af38daSDaniel Jacobowitz 
347387af38daSDaniel Jacobowitz 	err = snd_ac97_add_vmaster(ac97, "Master Playback Volume",
34749ab0cb30STakashi Iwai 				   kctl->tlv.p, follower_vols_vt1616);
347587af38daSDaniel Jacobowitz 	if (err < 0)
347687af38daSDaniel Jacobowitz 		return err;
347787af38daSDaniel Jacobowitz 
347887af38daSDaniel Jacobowitz 	err = snd_ac97_add_vmaster(ac97, "Master Playback Switch",
34799ab0cb30STakashi Iwai 				   NULL, follower_sws_vt1616);
348087af38daSDaniel Jacobowitz 	if (err < 0)
348187af38daSDaniel Jacobowitz 		return err;
348287af38daSDaniel Jacobowitz 
34831da177e4SLinus Torvalds 	return 0;
34841da177e4SLinus Torvalds }
34851da177e4SLinus Torvalds 
34863e8b3b90SHanno Boeck static const struct snd_ac97_build_ops patch_vt1616_ops = {
34871da177e4SLinus Torvalds 	.build_specific	= patch_vt1616_specific
34881da177e4SLinus Torvalds };
34891da177e4SLinus Torvalds 
patch_vt1616(struct snd_ac97 * ac97)3490ac519028STakashi Iwai static int patch_vt1616(struct snd_ac97 * ac97)
34911da177e4SLinus Torvalds {
34921da177e4SLinus Torvalds 	ac97->build_ops = &patch_vt1616_ops;
34931da177e4SLinus Torvalds 	return 0;
34941da177e4SLinus Torvalds }
34951da177e4SLinus Torvalds 
3496eb8caf30STakashi Iwai /*
34974b499486SPhilip Prindeville  * VT1617A codec
34984b499486SPhilip Prindeville  */
3499e9024cccSJohn Utz 
3500e9024cccSJohn Utz /*
3501e9024cccSJohn Utz  * unfortunately, the vt1617a stashes the twiddlers required for
35029e285e1aSJohn L. Utz III  * noodling the i/o jacks on 2 different regs. that means that we can't
3503e9024cccSJohn Utz  * use the easy way provided by AC97_ENUM_DOUBLE() we have to write
3504e9024cccSJohn Utz  * are own funcs.
3505e9024cccSJohn Utz  *
3506e9024cccSJohn Utz  * NB: this is absolutely and utterly different from the vt1618. dunno
3507e9024cccSJohn Utz  * about the 1616.
3508e9024cccSJohn Utz  */
3509e9024cccSJohn Utz 
3510e9024cccSJohn Utz /* copied from ac97_surround_jack_mode_info() */
snd_ac97_vt1617a_smart51_info(struct snd_kcontrol * kcontrol,struct snd_ctl_elem_info * uinfo)3511e9024cccSJohn Utz static int snd_ac97_vt1617a_smart51_info(struct snd_kcontrol *kcontrol,
3512e9024cccSJohn Utz 					 struct snd_ctl_elem_info *uinfo)
35134b499486SPhilip Prindeville {
3514e9024cccSJohn Utz 	/* ordering in this list reflects vt1617a docs for Reg 20 and
3515e9024cccSJohn Utz 	 * 7a and Table 6 that lays out the matrix NB WRT Table6: SM51
3516e9024cccSJohn Utz 	 * is SM51EN *AND* it's Bit14, not Bit15 so the table is very
3517e9024cccSJohn Utz 	 * counter-intuitive */
3518e9024cccSJohn Utz 
35193b7a00dcSTakashi Iwai 	static const char * const texts[] = {"LineIn Mic1", "LineIn Mic1 Mic3",
3520e9024cccSJohn Utz 				       "Surr LFE/C Mic3", "LineIn LFE/C Mic3",
3521e9024cccSJohn Utz 				       "LineIn Mic2", "LineIn Mic2 Mic1",
3522e9024cccSJohn Utz 				       "Surr LFE Mic1", "Surr LFE Mic1 Mic2"};
35233b7a00dcSTakashi Iwai 
35243b7a00dcSTakashi Iwai 	return snd_ctl_enum_info(uinfo, 1, 8, texts);
3525e9024cccSJohn Utz }
3526e9024cccSJohn Utz 
snd_ac97_vt1617a_smart51_get(struct snd_kcontrol * kcontrol,struct snd_ctl_elem_value * ucontrol)3527e9024cccSJohn Utz static int snd_ac97_vt1617a_smart51_get(struct snd_kcontrol *kcontrol,
3528e9024cccSJohn Utz 					struct snd_ctl_elem_value *ucontrol)
3529e9024cccSJohn Utz {
3530e9024cccSJohn Utz 	ushort usSM51, usMS;
3531e9024cccSJohn Utz 
3532e9024cccSJohn Utz 	struct snd_ac97 *pac97;
3533e9024cccSJohn Utz 
3534e9024cccSJohn Utz 	pac97 = snd_kcontrol_chip(kcontrol); /* grab codec handle */
3535e9024cccSJohn Utz 
35369e285e1aSJohn L. Utz III 	/* grab our desired bits, then mash them together in a manner
3537e9024cccSJohn Utz 	 * consistent with Table 6 on page 17 in the 1617a docs */
3538e9024cccSJohn Utz 
3539e9024cccSJohn Utz 	usSM51 = snd_ac97_read(pac97, 0x7a) >> 14;
3540e9024cccSJohn Utz 	usMS   = snd_ac97_read(pac97, 0x20) >> 8;
3541e9024cccSJohn Utz 
3542e9024cccSJohn Utz 	ucontrol->value.enumerated.item[0] = (usSM51 << 1) + usMS;
3543e9024cccSJohn Utz 
3544e9024cccSJohn Utz 	return 0;
3545e9024cccSJohn Utz }
3546e9024cccSJohn Utz 
snd_ac97_vt1617a_smart51_put(struct snd_kcontrol * kcontrol,struct snd_ctl_elem_value * ucontrol)3547e9024cccSJohn Utz static int snd_ac97_vt1617a_smart51_put(struct snd_kcontrol *kcontrol,
3548e9024cccSJohn Utz 					struct snd_ctl_elem_value *ucontrol)
3549e9024cccSJohn Utz {
3550e9024cccSJohn Utz 	ushort usSM51, usMS, usReg;
3551e9024cccSJohn Utz 
3552e9024cccSJohn Utz 	struct snd_ac97 *pac97;
3553e9024cccSJohn Utz 
3554e9024cccSJohn Utz 	pac97 = snd_kcontrol_chip(kcontrol); /* grab codec handle */
3555e9024cccSJohn Utz 
3556e9024cccSJohn Utz 	usSM51 = ucontrol->value.enumerated.item[0] >> 1;
3557e9024cccSJohn Utz 	usMS   = ucontrol->value.enumerated.item[0] &  1;
3558e9024cccSJohn Utz 
3559e9024cccSJohn Utz 	/* push our values into the register - consider that things will be left
3560e9024cccSJohn Utz 	 * in a funky state if the write fails */
3561e9024cccSJohn Utz 
3562e9024cccSJohn Utz 	usReg = snd_ac97_read(pac97, 0x7a);
3563e9024cccSJohn Utz 	snd_ac97_write_cache(pac97, 0x7a, (usReg & 0x3FFF) + (usSM51 << 14));
3564e9024cccSJohn Utz 	usReg = snd_ac97_read(pac97, 0x20);
3565e9024cccSJohn Utz 	snd_ac97_write_cache(pac97, 0x20, (usReg & 0xFEFF) + (usMS   <<  8));
3566e9024cccSJohn Utz 
3567e9024cccSJohn Utz 	return 0;
3568e9024cccSJohn Utz }
3569e9024cccSJohn Utz 
3570e9024cccSJohn Utz static const struct snd_kcontrol_new snd_ac97_controls_vt1617a[] = {
3571e9024cccSJohn Utz 
3572e9024cccSJohn Utz 	AC97_SINGLE("Center/LFE Exchange", 0x5a, 8, 1, 0),
3573e9024cccSJohn Utz 	/*
3574e9024cccSJohn Utz 	 * These are used to enable/disable surround sound on motherboards
3575e9024cccSJohn Utz 	 * that have 3 bidirectional analog jacks
3576e9024cccSJohn Utz 	 */
3577e9024cccSJohn Utz 	{
3578e9024cccSJohn Utz 		.iface         = SNDRV_CTL_ELEM_IFACE_MIXER,
3579e9024cccSJohn Utz 		.name          = "Smart 5.1 Select",
3580e9024cccSJohn Utz 		.info          = snd_ac97_vt1617a_smart51_info,
3581e9024cccSJohn Utz 		.get           = snd_ac97_vt1617a_smart51_get,
3582e9024cccSJohn Utz 		.put           = snd_ac97_vt1617a_smart51_put,
3583e9024cccSJohn Utz 	},
3584e9024cccSJohn Utz };
3585e9024cccSJohn Utz 
patch_vt1617a(struct snd_ac97 * ac97)3586b03671a8SHarvey Harrison static int patch_vt1617a(struct snd_ac97 * ac97)
3587e9024cccSJohn Utz {
3588e9024cccSJohn Utz 	int err = 0;
35892e75d050STakashi Iwai 	int val;
3590e9024cccSJohn Utz 
3591e9024cccSJohn Utz 	/* we choose to not fail out at this point, but we tell the
3592e9024cccSJohn Utz 	   caller when we return */
3593e9024cccSJohn Utz 
3594e9024cccSJohn Utz 	err = patch_build_controls(ac97, &snd_ac97_controls_vt1617a[0],
3595e9024cccSJohn Utz 				   ARRAY_SIZE(snd_ac97_controls_vt1617a));
3596e9024cccSJohn Utz 
3597e9024cccSJohn Utz 	/* bring analog power consumption to normal by turning off the
3598e9024cccSJohn Utz 	 * headphone amplifier, like WinXP driver for EPIA SP
35999f458e7fSAndrey Liakhovets 	 */
36002e75d050STakashi Iwai 	/* We need to check the bit before writing it.
36012e75d050STakashi Iwai 	 * On some (many?) hardwares, setting bit actually clears it!
36022e75d050STakashi Iwai 	 */
36032e75d050STakashi Iwai 	val = snd_ac97_read(ac97, 0x5c);
36042e75d050STakashi Iwai 	if (!(val & 0x20))
36059f458e7fSAndrey Liakhovets 		snd_ac97_write_cache(ac97, 0x5c, 0x20);
36062e75d050STakashi Iwai 
36074b499486SPhilip Prindeville 	ac97->ext_id |= AC97_EI_SPDIF;	/* force the detection of spdif */
36084b499486SPhilip Prindeville 	ac97->rates[AC97_RATES_SPDIF] = SNDRV_PCM_RATE_44100 | SNDRV_PCM_RATE_48000;
36099f428175SDaniel Jacobowitz 	ac97->build_ops = &patch_vt1616_ops;
3610e9024cccSJohn Utz 
3611e9024cccSJohn Utz 	return err;
36124b499486SPhilip Prindeville }
36134b499486SPhilip Prindeville 
36149e285e1aSJohn L. Utz III /* VIA VT1618 8 CHANNEL AC97 CODEC
36159e285e1aSJohn L. Utz III  *
36169e285e1aSJohn L. Utz III  * VIA implements 'Smart 5.1' completely differently on the 1618 than
36179e285e1aSJohn L. Utz III  * it does on the 1617a. awesome! They seem to have sourced this
36189e285e1aSJohn L. Utz III  * particular revision of the technology from somebody else, it's
36199e285e1aSJohn L. Utz III  * called Universal Audio Jack and it shows up on some other folk's chips
36209e285e1aSJohn L. Utz III  * as well.
36219e285e1aSJohn L. Utz III  *
36229e285e1aSJohn L. Utz III  * ordering in this list reflects vt1618 docs for Reg 60h and
36239e285e1aSJohn L. Utz III  * the block diagram, DACs are as follows:
36249e285e1aSJohn L. Utz III  *
36259e285e1aSJohn L. Utz III  *        OUT_O -> Front,
36269e285e1aSJohn L. Utz III  *	  OUT_1 -> Surround,
36279e285e1aSJohn L. Utz III  *	  OUT_2 -> C/LFE
36289e285e1aSJohn L. Utz III  *
36299e285e1aSJohn L. Utz III  * Unlike the 1617a, each OUT has a consistent set of mappings
36309e285e1aSJohn L. Utz III  * for all bitpatterns other than 00:
36319e285e1aSJohn L. Utz III  *
36329e285e1aSJohn L. Utz III  *        01       Unmixed Output
36339e285e1aSJohn L. Utz III  *        10       Line In
36349e285e1aSJohn L. Utz III  *        11       Mic  In
36359e285e1aSJohn L. Utz III  *
36369e285e1aSJohn L. Utz III  * Special Case of 00:
36379e285e1aSJohn L. Utz III  *
36389e285e1aSJohn L. Utz III  *        OUT_0    Mixed Output
36399e285e1aSJohn L. Utz III  *        OUT_1    Reserved
36409e285e1aSJohn L. Utz III  *        OUT_2    Reserved
36419e285e1aSJohn L. Utz III  *
36429e285e1aSJohn L. Utz III  * I have no idea what the hell Reserved does, but on an MSI
36439e285e1aSJohn L. Utz III  * CN700T, i have to set it to get 5.1 output - YMMV, bad
36449e285e1aSJohn L. Utz III  * shit may happen.
36459e285e1aSJohn L. Utz III  *
36469e285e1aSJohn L. Utz III  * If other chips use Universal Audio Jack, then this code might be applicable
36479e285e1aSJohn L. Utz III  * to them.
36489e285e1aSJohn L. Utz III  */
36499e285e1aSJohn L. Utz III 
36509e285e1aSJohn L. Utz III struct vt1618_uaj_item {
36519e285e1aSJohn L. Utz III 	unsigned short mask;
36529e285e1aSJohn L. Utz III 	unsigned short shift;
36531bc10bb6STakashi Iwai 	const char * const items[4];
36549e285e1aSJohn L. Utz III };
36559e285e1aSJohn L. Utz III 
36569e285e1aSJohn L. Utz III /* This list reflects the vt1618 docs for Vendor Defined Register 0x60. */
36579e285e1aSJohn L. Utz III 
36581675bfc0STakashi Iwai static const struct vt1618_uaj_item vt1618_uaj[3] = {
36599e285e1aSJohn L. Utz III 	{
36609e285e1aSJohn L. Utz III 		/* speaker jack */
36619e285e1aSJohn L. Utz III 		.mask  = 0x03,
36629e285e1aSJohn L. Utz III 		.shift = 0,
36639e285e1aSJohn L. Utz III 		.items = {
36649e285e1aSJohn L. Utz III 			"Speaker Out", "DAC Unmixed Out", "Line In", "Mic In"
36659e285e1aSJohn L. Utz III 		}
36669e285e1aSJohn L. Utz III 	},
36679e285e1aSJohn L. Utz III 	{
36689e285e1aSJohn L. Utz III 		/* line jack */
36699e285e1aSJohn L. Utz III 		.mask  = 0x0c,
36709e285e1aSJohn L. Utz III 		.shift = 2,
36719e285e1aSJohn L. Utz III 		.items = {
36729e285e1aSJohn L. Utz III 			"Surround Out", "DAC Unmixed Out", "Line In", "Mic In"
36739e285e1aSJohn L. Utz III 		}
36749e285e1aSJohn L. Utz III 	},
36759e285e1aSJohn L. Utz III 	{
36769e285e1aSJohn L. Utz III 		/* mic jack */
36779e285e1aSJohn L. Utz III 		.mask  = 0x30,
36789e285e1aSJohn L. Utz III 		.shift = 4,
36799e285e1aSJohn L. Utz III 		.items = {
36809e285e1aSJohn L. Utz III 			"Center LFE Out", "DAC Unmixed Out", "Line In", "Mic In"
36819e285e1aSJohn L. Utz III 		},
36829e285e1aSJohn L. Utz III 	},
36839e285e1aSJohn L. Utz III };
36849e285e1aSJohn L. Utz III 
snd_ac97_vt1618_UAJ_info(struct snd_kcontrol * kcontrol,struct snd_ctl_elem_info * uinfo)36859e285e1aSJohn L. Utz III static int snd_ac97_vt1618_UAJ_info(struct snd_kcontrol *kcontrol,
36869e285e1aSJohn L. Utz III 				    struct snd_ctl_elem_info *uinfo)
36879e285e1aSJohn L. Utz III {
36883b7a00dcSTakashi Iwai 	return snd_ctl_enum_info(uinfo, 1, 4,
36893b7a00dcSTakashi Iwai 				 vt1618_uaj[kcontrol->private_value].items);
36909e285e1aSJohn L. Utz III }
36919e285e1aSJohn L. Utz III 
36929e285e1aSJohn L. Utz III /* All of the vt1618 Universal Audio Jack twiddlers are on
36939e285e1aSJohn L. Utz III  * Vendor Defined Register 0x60, page 0. The bits, and thus
36949e285e1aSJohn L. Utz III  * the mask, are the only thing that changes
36959e285e1aSJohn L. Utz III  */
snd_ac97_vt1618_UAJ_get(struct snd_kcontrol * kcontrol,struct snd_ctl_elem_value * ucontrol)36969e285e1aSJohn L. Utz III static int snd_ac97_vt1618_UAJ_get(struct snd_kcontrol *kcontrol,
36979e285e1aSJohn L. Utz III 				   struct snd_ctl_elem_value *ucontrol)
36989e285e1aSJohn L. Utz III {
36999e285e1aSJohn L. Utz III 	unsigned short datpag, uaj;
37009e285e1aSJohn L. Utz III 	struct snd_ac97 *pac97 = snd_kcontrol_chip(kcontrol);
37019e285e1aSJohn L. Utz III 
37029e285e1aSJohn L. Utz III 	mutex_lock(&pac97->page_mutex);
37039e285e1aSJohn L. Utz III 
37049e285e1aSJohn L. Utz III 	datpag = snd_ac97_read(pac97, AC97_INT_PAGING) & AC97_PAGE_MASK;
37059e285e1aSJohn L. Utz III 	snd_ac97_update_bits(pac97, AC97_INT_PAGING, AC97_PAGE_MASK, 0);
37069e285e1aSJohn L. Utz III 
37079e285e1aSJohn L. Utz III 	uaj = snd_ac97_read(pac97, 0x60) &
37089e285e1aSJohn L. Utz III 		vt1618_uaj[kcontrol->private_value].mask;
37099e285e1aSJohn L. Utz III 
37109e285e1aSJohn L. Utz III 	snd_ac97_update_bits(pac97, AC97_INT_PAGING, AC97_PAGE_MASK, datpag);
37119e285e1aSJohn L. Utz III 	mutex_unlock(&pac97->page_mutex);
37129e285e1aSJohn L. Utz III 
37139e285e1aSJohn L. Utz III 	ucontrol->value.enumerated.item[0] = uaj >>
37149e285e1aSJohn L. Utz III 		vt1618_uaj[kcontrol->private_value].shift;
37159e285e1aSJohn L. Utz III 
37169e285e1aSJohn L. Utz III 	return 0;
37179e285e1aSJohn L. Utz III }
37189e285e1aSJohn L. Utz III 
snd_ac97_vt1618_UAJ_put(struct snd_kcontrol * kcontrol,struct snd_ctl_elem_value * ucontrol)37199e285e1aSJohn L. Utz III static int snd_ac97_vt1618_UAJ_put(struct snd_kcontrol *kcontrol,
37209e285e1aSJohn L. Utz III 				   struct snd_ctl_elem_value *ucontrol)
37219e285e1aSJohn L. Utz III {
37229e285e1aSJohn L. Utz III 	return ac97_update_bits_page(snd_kcontrol_chip(kcontrol), 0x60,
37239e285e1aSJohn L. Utz III 				     vt1618_uaj[kcontrol->private_value].mask,
37249e285e1aSJohn L. Utz III 				     ucontrol->value.enumerated.item[0]<<
37259e285e1aSJohn L. Utz III 				     vt1618_uaj[kcontrol->private_value].shift,
37269e285e1aSJohn L. Utz III 				     0);
37279e285e1aSJohn L. Utz III }
37289e285e1aSJohn L. Utz III 
37299e285e1aSJohn L. Utz III /* config aux in jack - not found on 3 jack motherboards or soundcards */
37309e285e1aSJohn L. Utz III 
snd_ac97_vt1618_aux_info(struct snd_kcontrol * kcontrol,struct snd_ctl_elem_info * uinfo)37319e285e1aSJohn L. Utz III static int snd_ac97_vt1618_aux_info(struct snd_kcontrol *kcontrol,
37329e285e1aSJohn L. Utz III 				     struct snd_ctl_elem_info *uinfo)
37339e285e1aSJohn L. Utz III {
37343b7a00dcSTakashi Iwai 	static const char * const txt_aux[] = {"Aux In", "Back Surr Out"};
37359e285e1aSJohn L. Utz III 
37363b7a00dcSTakashi Iwai 	return snd_ctl_enum_info(uinfo, 1, 2, txt_aux);
37379e285e1aSJohn L. Utz III }
37389e285e1aSJohn L. Utz III 
snd_ac97_vt1618_aux_get(struct snd_kcontrol * kcontrol,struct snd_ctl_elem_value * ucontrol)37399e285e1aSJohn L. Utz III static int snd_ac97_vt1618_aux_get(struct snd_kcontrol *kcontrol,
37409e285e1aSJohn L. Utz III 				   struct snd_ctl_elem_value *ucontrol)
37419e285e1aSJohn L. Utz III {
37429e285e1aSJohn L. Utz III 	ucontrol->value.enumerated.item[0] =
37439e285e1aSJohn L. Utz III 		(snd_ac97_read(snd_kcontrol_chip(kcontrol), 0x5c) & 0x0008)>>3;
37449e285e1aSJohn L. Utz III 	return 0;
37459e285e1aSJohn L. Utz III }
37469e285e1aSJohn L. Utz III 
snd_ac97_vt1618_aux_put(struct snd_kcontrol * kcontrol,struct snd_ctl_elem_value * ucontrol)37479e285e1aSJohn L. Utz III static int snd_ac97_vt1618_aux_put(struct snd_kcontrol *kcontrol,
37489e285e1aSJohn L. Utz III 				   struct snd_ctl_elem_value *ucontrol)
37499e285e1aSJohn L. Utz III {
37509e285e1aSJohn L. Utz III 	/* toggle surround rear dac power */
37519e285e1aSJohn L. Utz III 
37529e285e1aSJohn L. Utz III 	snd_ac97_update_bits(snd_kcontrol_chip(kcontrol), 0x5c, 0x0008,
37539e285e1aSJohn L. Utz III 			     ucontrol->value.enumerated.item[0] << 3);
37549e285e1aSJohn L. Utz III 
37559e285e1aSJohn L. Utz III 	/* toggle aux in surround rear out jack */
37569e285e1aSJohn L. Utz III 
37579e285e1aSJohn L. Utz III 	return snd_ac97_update_bits(snd_kcontrol_chip(kcontrol), 0x76, 0x0008,
37589e285e1aSJohn L. Utz III 				    ucontrol->value.enumerated.item[0] << 3);
37599e285e1aSJohn L. Utz III }
37609e285e1aSJohn L. Utz III 
37619e285e1aSJohn L. Utz III static const struct snd_kcontrol_new snd_ac97_controls_vt1618[] = {
37629e285e1aSJohn L. Utz III 	AC97_SINGLE("Exchange Center/LFE", 0x5a,  8, 1,     0),
37639e285e1aSJohn L. Utz III 	AC97_SINGLE("DC Offset",           0x5a, 10, 1,     0),
37649e285e1aSJohn L. Utz III 	AC97_SINGLE("Soft Mute",           0x5c,  0, 1,     1),
37659e285e1aSJohn L. Utz III 	AC97_SINGLE("Headphone Amp",       0x5c,  5, 1,     1),
37669e285e1aSJohn L. Utz III 	AC97_DOUBLE("Back Surr Volume",    0x5e,  8, 0, 31, 1),
37679e285e1aSJohn L. Utz III 	AC97_SINGLE("Back Surr Switch",    0x5e, 15, 1,     1),
37689e285e1aSJohn L. Utz III 	{
37699e285e1aSJohn L. Utz III 		.iface         = SNDRV_CTL_ELEM_IFACE_MIXER,
37709e285e1aSJohn L. Utz III 		.name          = "Speaker Jack Mode",
37719e285e1aSJohn L. Utz III 		.info          = snd_ac97_vt1618_UAJ_info,
37729e285e1aSJohn L. Utz III 		.get           = snd_ac97_vt1618_UAJ_get,
37739e285e1aSJohn L. Utz III 		.put           = snd_ac97_vt1618_UAJ_put,
37749e285e1aSJohn L. Utz III 		.private_value = 0
37759e285e1aSJohn L. Utz III 	},
37769e285e1aSJohn L. Utz III 	{
37779e285e1aSJohn L. Utz III 		.iface         = SNDRV_CTL_ELEM_IFACE_MIXER,
37789e285e1aSJohn L. Utz III 		.name          = "Line Jack Mode",
37799e285e1aSJohn L. Utz III 		.info          = snd_ac97_vt1618_UAJ_info,
37809e285e1aSJohn L. Utz III 		.get           = snd_ac97_vt1618_UAJ_get,
37819e285e1aSJohn L. Utz III 		.put           = snd_ac97_vt1618_UAJ_put,
37829e285e1aSJohn L. Utz III 		.private_value = 1
37839e285e1aSJohn L. Utz III 	},
37849e285e1aSJohn L. Utz III 	{
37859e285e1aSJohn L. Utz III 		.iface         = SNDRV_CTL_ELEM_IFACE_MIXER,
37869e285e1aSJohn L. Utz III 		.name          = "Mic Jack Mode",
37879e285e1aSJohn L. Utz III 		.info          = snd_ac97_vt1618_UAJ_info,
37889e285e1aSJohn L. Utz III 		.get           = snd_ac97_vt1618_UAJ_get,
37899e285e1aSJohn L. Utz III 		.put           = snd_ac97_vt1618_UAJ_put,
37909e285e1aSJohn L. Utz III 		.private_value = 2
37919e285e1aSJohn L. Utz III 	},
37929e285e1aSJohn L. Utz III 	{
37939e285e1aSJohn L. Utz III 		.iface         = SNDRV_CTL_ELEM_IFACE_MIXER,
37949e285e1aSJohn L. Utz III 		.name          = "Aux Jack Mode",
37959e285e1aSJohn L. Utz III 		.info          = snd_ac97_vt1618_aux_info,
37969e285e1aSJohn L. Utz III 		.get           = snd_ac97_vt1618_aux_get,
37979e285e1aSJohn L. Utz III 		.put           = snd_ac97_vt1618_aux_put,
37989e285e1aSJohn L. Utz III 	}
37999e285e1aSJohn L. Utz III };
38009e285e1aSJohn L. Utz III 
patch_vt1618(struct snd_ac97 * ac97)3801b03671a8SHarvey Harrison static int patch_vt1618(struct snd_ac97 *ac97)
38029e285e1aSJohn L. Utz III {
38039e285e1aSJohn L. Utz III 	return patch_build_controls(ac97, snd_ac97_controls_vt1618,
38049e285e1aSJohn L. Utz III 				    ARRAY_SIZE(snd_ac97_controls_vt1618));
38059e285e1aSJohn L. Utz III }
38069e285e1aSJohn L. Utz III 
38074b499486SPhilip Prindeville /*
3808eb8caf30STakashi Iwai  */
it2646_update_jacks(struct snd_ac97 * ac97)3809ee42381eSTakashi Iwai static void it2646_update_jacks(struct snd_ac97 *ac97)
3810eb8caf30STakashi Iwai {
3811831466f4SRandy Cushman 	/* shared Line-In / Surround Out */
3812eb8caf30STakashi Iwai 	snd_ac97_update_bits(ac97, 0x76, 1 << 9,
3813831466f4SRandy Cushman 			     is_shared_surrout(ac97) ? (1<<9) : 0);
3814831466f4SRandy Cushman 	/* shared Mic / Center/LFE Out */
3815eb8caf30STakashi Iwai 	snd_ac97_update_bits(ac97, 0x76, 1 << 10,
3816831466f4SRandy Cushman 			     is_shared_clfeout(ac97) ? (1<<10) : 0);
3817eb8caf30STakashi Iwai }
3818eb8caf30STakashi Iwai 
3819ee42381eSTakashi Iwai static const struct snd_kcontrol_new snd_ac97_controls_it2646[] = {
3820eb8caf30STakashi Iwai 	AC97_SURROUND_JACK_MODE_CTL,
3821eb8caf30STakashi Iwai 	AC97_CHANNEL_MODE_CTL,
38221da177e4SLinus Torvalds };
38231da177e4SLinus Torvalds 
3824ee42381eSTakashi Iwai static const struct snd_kcontrol_new snd_ac97_spdif_controls_it2646[] = {
382510e8d78aSClemens Ladisch 	AC97_SINGLE(SNDRV_CTL_NAME_IEC958("",CAPTURE,SWITCH), 0x76, 11, 1, 0),
38261da177e4SLinus Torvalds 	AC97_SINGLE("Analog to IEC958 Output", 0x76, 12, 1, 0),
38271da177e4SLinus Torvalds 	AC97_SINGLE("IEC958 Input Monitor", 0x76, 13, 1, 0),
38281da177e4SLinus Torvalds };
38291da177e4SLinus Torvalds 
patch_it2646_specific(struct snd_ac97 * ac97)3830ee42381eSTakashi Iwai static int patch_it2646_specific(struct snd_ac97 * ac97)
38311da177e4SLinus Torvalds {
38321da177e4SLinus Torvalds 	int err;
3833e66fd362STakashi Iwai 	err = patch_build_controls(ac97, snd_ac97_controls_it2646, ARRAY_SIZE(snd_ac97_controls_it2646));
3834e66fd362STakashi Iwai 	if (err < 0)
38351da177e4SLinus Torvalds 		return err;
3836e66fd362STakashi Iwai 	err = patch_build_controls(ac97, snd_ac97_spdif_controls_it2646, ARRAY_SIZE(snd_ac97_spdif_controls_it2646));
3837e66fd362STakashi Iwai 	if (err < 0)
38381da177e4SLinus Torvalds 		return err;
38391da177e4SLinus Torvalds 	return 0;
38401da177e4SLinus Torvalds }
38411da177e4SLinus Torvalds 
38423e8b3b90SHanno Boeck static const struct snd_ac97_build_ops patch_it2646_ops = {
3843eb8caf30STakashi Iwai 	.build_specific	= patch_it2646_specific,
3844eb8caf30STakashi Iwai 	.update_jacks = it2646_update_jacks
38451da177e4SLinus Torvalds };
38461da177e4SLinus Torvalds 
patch_it2646(struct snd_ac97 * ac97)3847ac519028STakashi Iwai static int patch_it2646(struct snd_ac97 * ac97)
38481da177e4SLinus Torvalds {
38491da177e4SLinus Torvalds 	ac97->build_ops = &patch_it2646_ops;
38501da177e4SLinus Torvalds 	/* full DAC volume */
38511da177e4SLinus Torvalds 	snd_ac97_write_cache(ac97, 0x5E, 0x0808);
38521da177e4SLinus Torvalds 	snd_ac97_write_cache(ac97, 0x7A, 0x0808);
38531da177e4SLinus Torvalds 	return 0;
38541da177e4SLinus Torvalds }
38551da177e4SLinus Torvalds 
385687d61c29SSasha Khapyorsky /*
385787d61c29SSasha Khapyorsky  * Si3036 codec
385887d61c29SSasha Khapyorsky  */
385987d61c29SSasha Khapyorsky 
38601da177e4SLinus Torvalds #define AC97_SI3036_CHIP_ID     0x5a
386187d61c29SSasha Khapyorsky #define AC97_SI3036_LINE_CFG    0x5c
386287d61c29SSasha Khapyorsky 
3863ee42381eSTakashi Iwai static const struct snd_kcontrol_new snd_ac97_controls_si3036[] = {
386487d61c29SSasha Khapyorsky AC97_DOUBLE("Modem Speaker Volume", 0x5c, 14, 12, 3, 1)
386587d61c29SSasha Khapyorsky };
386687d61c29SSasha Khapyorsky 
patch_si3036_specific(struct snd_ac97 * ac97)3867ee42381eSTakashi Iwai static int patch_si3036_specific(struct snd_ac97 * ac97)
386887d61c29SSasha Khapyorsky {
386927bcaa69SSasha Khapyorsky 	int idx, err;
3870e66fd362STakashi Iwai 	for (idx = 0; idx < ARRAY_SIZE(snd_ac97_controls_si3036); idx++) {
3871e66fd362STakashi Iwai 		err = snd_ctl_add(ac97->bus->card, snd_ctl_new1(&snd_ac97_controls_si3036[idx], ac97));
3872e66fd362STakashi Iwai 		if (err < 0)
387327bcaa69SSasha Khapyorsky 			return err;
3874e66fd362STakashi Iwai 	}
387527bcaa69SSasha Khapyorsky 	return 0;
387687d61c29SSasha Khapyorsky }
387787d61c29SSasha Khapyorsky 
38783e8b3b90SHanno Boeck static const struct snd_ac97_build_ops patch_si3036_ops = {
387987d61c29SSasha Khapyorsky 	.build_specific	= patch_si3036_specific,
388087d61c29SSasha Khapyorsky };
38811da177e4SLinus Torvalds 
mpatch_si3036(struct snd_ac97 * ac97)3882ac519028STakashi Iwai static int mpatch_si3036(struct snd_ac97 * ac97)
38831da177e4SLinus Torvalds {
388487d61c29SSasha Khapyorsky 	ac97->build_ops = &patch_si3036_ops;
38851da177e4SLinus Torvalds 	snd_ac97_write_cache(ac97, 0x5c, 0xf210 );
38861da177e4SLinus Torvalds 	snd_ac97_write_cache(ac97, 0x68, 0);
38871da177e4SLinus Torvalds 	return 0;
38881da177e4SLinus Torvalds }
3889ba22429dSCharl Coetzee 
3890ba22429dSCharl Coetzee /*
3891ba22429dSCharl Coetzee  * LM 4550 Codec
3892ba22429dSCharl Coetzee  *
3893ba22429dSCharl Coetzee  * We use a static resolution table since LM4550 codec cannot be
3894ba22429dSCharl Coetzee  * properly autoprobed to determine the resolution via
3895ba22429dSCharl Coetzee  * check_volume_resolution().
3896ba22429dSCharl Coetzee  */
3897ba22429dSCharl Coetzee 
3898c0476b98STakashi Iwai static const struct snd_ac97_res_table lm4550_restbl[] = {
3899ba22429dSCharl Coetzee 	{ AC97_MASTER, 0x1f1f },
3900ba22429dSCharl Coetzee 	{ AC97_HEADPHONE, 0x1f1f },
3901ba22429dSCharl Coetzee 	{ AC97_MASTER_MONO, 0x001f },
3902ba22429dSCharl Coetzee 	{ AC97_PC_BEEP, 0x001f },	/* LSB is ignored */
3903ba22429dSCharl Coetzee 	{ AC97_PHONE, 0x001f },
3904ba22429dSCharl Coetzee 	{ AC97_MIC, 0x001f },
3905ba22429dSCharl Coetzee 	{ AC97_LINE, 0x1f1f },
3906ba22429dSCharl Coetzee 	{ AC97_CD, 0x1f1f },
3907ba22429dSCharl Coetzee 	{ AC97_VIDEO, 0x1f1f },
3908ba22429dSCharl Coetzee 	{ AC97_AUX, 0x1f1f },
3909ba22429dSCharl Coetzee 	{ AC97_PCM, 0x1f1f },
3910ba22429dSCharl Coetzee 	{ AC97_REC_GAIN, 0x0f0f },
3911ba22429dSCharl Coetzee 	{ } /* terminator */
3912ba22429dSCharl Coetzee };
3913ba22429dSCharl Coetzee 
patch_lm4550(struct snd_ac97 * ac97)3914ac519028STakashi Iwai static int patch_lm4550(struct snd_ac97 *ac97)
3915ba22429dSCharl Coetzee {
3916ba22429dSCharl Coetzee 	ac97->res_table = lm4550_restbl;
3917ba22429dSCharl Coetzee 	return 0;
3918ba22429dSCharl Coetzee }
3919