xref: /linux/sound/pci/ac97/ac97_patch.c (revision aa08ff0f345ef68829bab30ddb5a23e9d99301b7)
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,
221bc10bb6STakashi Iwai 				const char * const *slaves);
236ba9256cSAndreas Mohr 
246ba9256cSAndreas Mohr /*
251da177e4SLinus Torvalds  *  Chip specific initialization
261da177e4SLinus Torvalds  */
271da177e4SLinus Torvalds 
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 
321da177e4SLinus Torvalds 	for (idx = 0; idx < count; idx++)
331da177e4SLinus Torvalds 		if ((err = snd_ctl_add(ac97->bus->card, snd_ac97_cnew(&controls[idx], ac97))) < 0)
341da177e4SLinus Torvalds 			return err;
351da177e4SLinus Torvalds 	return 0;
361da177e4SLinus Torvalds }
371da177e4SLinus Torvalds 
382f3482fbSTakashi Iwai /* replace with a new TLV */
392f3482fbSTakashi Iwai static void reset_tlv(struct snd_ac97 *ac97, const char *name,
400cb29ea0STakashi Iwai 		      const unsigned int *tlv)
412f3482fbSTakashi Iwai {
422f3482fbSTakashi Iwai 	struct snd_ctl_elem_id sid;
432f3482fbSTakashi Iwai 	struct snd_kcontrol *kctl;
442f3482fbSTakashi Iwai 	memset(&sid, 0, sizeof(sid));
452f3482fbSTakashi Iwai 	strcpy(sid.name, name);
462f3482fbSTakashi Iwai 	sid.iface = SNDRV_CTL_ELEM_IFACE_MIXER;
472f3482fbSTakashi Iwai 	kctl = snd_ctl_find_id(ac97->bus->card, &sid);
482f3482fbSTakashi Iwai 	if (kctl && kctl->tlv.p)
492f3482fbSTakashi Iwai 		kctl->tlv.p = tlv;
502f3482fbSTakashi Iwai }
512f3482fbSTakashi Iwai 
521da177e4SLinus Torvalds /* set to the page, update bits and restore the page */
53ee42381eSTakashi Iwai static int ac97_update_bits_page(struct snd_ac97 *ac97, unsigned short reg, unsigned short mask, unsigned short value, unsigned short page)
541da177e4SLinus Torvalds {
551da177e4SLinus Torvalds 	unsigned short page_save;
561da177e4SLinus Torvalds 	int ret;
571da177e4SLinus Torvalds 
5862932df8SIngo Molnar 	mutex_lock(&ac97->page_mutex);
591da177e4SLinus Torvalds 	page_save = snd_ac97_read(ac97, AC97_INT_PAGING) & AC97_PAGE_MASK;
601da177e4SLinus Torvalds 	snd_ac97_update_bits(ac97, AC97_INT_PAGING, AC97_PAGE_MASK, page);
611da177e4SLinus Torvalds 	ret = snd_ac97_update_bits(ac97, reg, mask, value);
621da177e4SLinus Torvalds 	snd_ac97_update_bits(ac97, AC97_INT_PAGING, AC97_PAGE_MASK, page_save);
6362932df8SIngo Molnar 	mutex_unlock(&ac97->page_mutex); /* unlock paging */
641da177e4SLinus Torvalds 	return ret;
651da177e4SLinus Torvalds }
661da177e4SLinus Torvalds 
67eb8caf30STakashi Iwai /*
68eb8caf30STakashi Iwai  * shared line-in/mic controls
69eb8caf30STakashi Iwai  */
70ee42381eSTakashi Iwai static int ac97_surround_jack_mode_info(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_info *uinfo)
71eb8caf30STakashi Iwai {
723b7a00dcSTakashi Iwai 	static const char * const texts[] = { "Shared", "Independent" };
733b7a00dcSTakashi Iwai 
743b7a00dcSTakashi Iwai 	return snd_ctl_enum_info(uinfo, 1, 2, texts);
75eb8caf30STakashi Iwai }
76eb8caf30STakashi Iwai 
77ee42381eSTakashi Iwai static int ac97_surround_jack_mode_get(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
78eb8caf30STakashi Iwai {
79ee42381eSTakashi Iwai 	struct snd_ac97 *ac97 = snd_kcontrol_chip(kcontrol);
80eb8caf30STakashi Iwai 
81eb8caf30STakashi Iwai 	ucontrol->value.enumerated.item[0] = ac97->indep_surround;
82eb8caf30STakashi Iwai 	return 0;
83eb8caf30STakashi Iwai }
84eb8caf30STakashi Iwai 
85ee42381eSTakashi Iwai static int ac97_surround_jack_mode_put(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
86eb8caf30STakashi Iwai {
87ee42381eSTakashi Iwai 	struct snd_ac97 *ac97 = snd_kcontrol_chip(kcontrol);
88eb8caf30STakashi Iwai 	unsigned char indep = !!ucontrol->value.enumerated.item[0];
89eb8caf30STakashi Iwai 
90eb8caf30STakashi Iwai 	if (indep != ac97->indep_surround) {
91eb8caf30STakashi Iwai 		ac97->indep_surround = indep;
92eb8caf30STakashi Iwai 		if (ac97->build_ops->update_jacks)
93eb8caf30STakashi Iwai 			ac97->build_ops->update_jacks(ac97);
94eb8caf30STakashi Iwai 		return 1;
95eb8caf30STakashi Iwai 	}
96eb8caf30STakashi Iwai 	return 0;
97eb8caf30STakashi Iwai }
98eb8caf30STakashi Iwai 
99ee42381eSTakashi Iwai static int ac97_channel_mode_info(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_info *uinfo)
100eb8caf30STakashi Iwai {
1013b7a00dcSTakashi Iwai 	static const char * const texts[] = { "2ch", "4ch", "6ch", "8ch" };
1023b7a00dcSTakashi Iwai 
1033b7a00dcSTakashi Iwai 	return snd_ctl_enum_info(uinfo, 1, kcontrol->private_value, texts);
104eb8caf30STakashi Iwai }
105eb8caf30STakashi Iwai 
106ee42381eSTakashi Iwai static int ac97_channel_mode_get(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
107eb8caf30STakashi Iwai {
108ee42381eSTakashi Iwai 	struct snd_ac97 *ac97 = snd_kcontrol_chip(kcontrol);
109eb8caf30STakashi Iwai 
110eb8caf30STakashi Iwai 	ucontrol->value.enumerated.item[0] = ac97->channel_mode;
111eb8caf30STakashi Iwai 	return 0;
112eb8caf30STakashi Iwai }
113eb8caf30STakashi Iwai 
114ee42381eSTakashi Iwai static int ac97_channel_mode_put(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
115eb8caf30STakashi Iwai {
116ee42381eSTakashi Iwai 	struct snd_ac97 *ac97 = snd_kcontrol_chip(kcontrol);
117eb8caf30STakashi Iwai 	unsigned char mode = ucontrol->value.enumerated.item[0];
118eb8caf30STakashi Iwai 
1194235a317STakashi Iwai 	if (mode >= kcontrol->private_value)
1204e98d6a7STakashi Iwai 		return -EINVAL;
1214e98d6a7STakashi Iwai 
122eb8caf30STakashi Iwai 	if (mode != ac97->channel_mode) {
123eb8caf30STakashi Iwai 		ac97->channel_mode = mode;
124eb8caf30STakashi Iwai 		if (ac97->build_ops->update_jacks)
125eb8caf30STakashi Iwai 			ac97->build_ops->update_jacks(ac97);
126eb8caf30STakashi Iwai 		return 1;
127eb8caf30STakashi Iwai 	}
128eb8caf30STakashi Iwai 	return 0;
129eb8caf30STakashi Iwai }
130eb8caf30STakashi Iwai 
131eb8caf30STakashi Iwai #define AC97_SURROUND_JACK_MODE_CTL \
132eb8caf30STakashi Iwai 	{ \
133eb8caf30STakashi Iwai 		.iface	= SNDRV_CTL_ELEM_IFACE_MIXER, \
134eb8caf30STakashi Iwai 		.name	= "Surround Jack Mode", \
135eb8caf30STakashi Iwai 		.info = ac97_surround_jack_mode_info, \
136eb8caf30STakashi Iwai 		.get = ac97_surround_jack_mode_get, \
137eb8caf30STakashi Iwai 		.put = ac97_surround_jack_mode_put, \
138eb8caf30STakashi Iwai 	}
1394235a317STakashi Iwai /* 6ch */
140eb8caf30STakashi Iwai #define AC97_CHANNEL_MODE_CTL \
141eb8caf30STakashi Iwai 	{ \
142eb8caf30STakashi Iwai 		.iface	= SNDRV_CTL_ELEM_IFACE_MIXER, \
143eb8caf30STakashi Iwai 		.name	= "Channel Mode", \
144eb8caf30STakashi Iwai 		.info = ac97_channel_mode_info, \
145eb8caf30STakashi Iwai 		.get = ac97_channel_mode_get, \
146eb8caf30STakashi Iwai 		.put = ac97_channel_mode_put, \
1474235a317STakashi Iwai 		.private_value = 3, \
148eb8caf30STakashi Iwai 	}
1494235a317STakashi Iwai /* 4ch */
150eb8caf30STakashi Iwai #define AC97_CHANNEL_MODE_4CH_CTL \
151eb8caf30STakashi Iwai 	{ \
152eb8caf30STakashi Iwai 		.iface	= SNDRV_CTL_ELEM_IFACE_MIXER, \
153eb8caf30STakashi Iwai 		.name	= "Channel Mode", \
154eb8caf30STakashi Iwai 		.info = ac97_channel_mode_info, \
155eb8caf30STakashi Iwai 		.get = ac97_channel_mode_get, \
156eb8caf30STakashi Iwai 		.put = ac97_channel_mode_put, \
1574235a317STakashi Iwai 		.private_value = 2, \
1584235a317STakashi Iwai 	}
1594235a317STakashi Iwai /* 8ch */
1604235a317STakashi Iwai #define AC97_CHANNEL_MODE_8CH_CTL \
1614235a317STakashi Iwai 	{ \
1624235a317STakashi Iwai 		.iface  = SNDRV_CTL_ELEM_IFACE_MIXER, \
1634235a317STakashi Iwai 		.name   = "Channel Mode", \
1644235a317STakashi Iwai 		.info = ac97_channel_mode_info, \
1654235a317STakashi Iwai 		.get = ac97_channel_mode_get, \
1664235a317STakashi Iwai 		.put = ac97_channel_mode_put, \
1674235a317STakashi Iwai 		.private_value = 4, \
168eb8caf30STakashi Iwai 	}
169eb8caf30STakashi Iwai 
170ee42381eSTakashi Iwai static inline int is_surround_on(struct snd_ac97 *ac97)
1714525c9f3STakashi Iwai {
1724525c9f3STakashi Iwai 	return ac97->channel_mode >= 1;
1734525c9f3STakashi Iwai }
1744525c9f3STakashi Iwai 
175ee42381eSTakashi Iwai static inline int is_clfe_on(struct snd_ac97 *ac97)
1764525c9f3STakashi Iwai {
177eb9b4142STakashi Iwai 	return ac97->channel_mode >= 2;
1784525c9f3STakashi Iwai }
1794525c9f3STakashi Iwai 
180831466f4SRandy Cushman /* system has shared jacks with surround out enabled */
181831466f4SRandy Cushman static inline int is_shared_surrout(struct snd_ac97 *ac97)
182eb8caf30STakashi Iwai {
1834525c9f3STakashi Iwai 	return !ac97->indep_surround && is_surround_on(ac97);
184eb8caf30STakashi Iwai }
185eb8caf30STakashi Iwai 
186831466f4SRandy Cushman /* system has shared jacks with center/lfe out enabled */
187831466f4SRandy Cushman static inline int is_shared_clfeout(struct snd_ac97 *ac97)
188eb8caf30STakashi Iwai {
1894525c9f3STakashi Iwai 	return !ac97->indep_surround && is_clfe_on(ac97);
190eb8caf30STakashi Iwai }
191eb8caf30STakashi Iwai 
192831466f4SRandy Cushman /* system has shared jacks with line in enabled */
193831466f4SRandy Cushman static inline int is_shared_linein(struct snd_ac97 *ac97)
194831466f4SRandy Cushman {
195831466f4SRandy Cushman 	return !ac97->indep_surround && !is_surround_on(ac97);
196831466f4SRandy Cushman }
197831466f4SRandy Cushman 
198831466f4SRandy Cushman /* system has shared jacks with mic in enabled */
199831466f4SRandy Cushman static inline int is_shared_micin(struct snd_ac97 *ac97)
200831466f4SRandy Cushman {
201831466f4SRandy Cushman 	return !ac97->indep_surround && !is_clfe_on(ac97);
202831466f4SRandy Cushman }
203831466f4SRandy Cushman 
2044235a317STakashi Iwai static inline int alc850_is_aux_back_surround(struct snd_ac97 *ac97)
2054235a317STakashi Iwai {
2064235a317STakashi Iwai 	return is_surround_on(ac97);
2074235a317STakashi Iwai }
208eb8caf30STakashi Iwai 
2091da177e4SLinus Torvalds /* The following snd_ac97_ymf753_... items added by David Shust (dshust@shustring.com) */
21043115f58SKeita Maehara /* Modified for YMF743 by Keita Maehara <maehara@debian.org> */
2111da177e4SLinus Torvalds 
21213043984SKeita Maehara /* It is possible to indicate to the Yamaha YMF7x3 the type of
21313043984SKeita Maehara    speakers being used. */
21413043984SKeita Maehara 
21513043984SKeita Maehara static int snd_ac97_ymf7x3_info_speaker(struct snd_kcontrol *kcontrol,
21613043984SKeita Maehara 					struct snd_ctl_elem_info *uinfo)
2171da177e4SLinus Torvalds {
2183b7a00dcSTakashi Iwai 	static const char * const texts[3] = {
2191da177e4SLinus Torvalds 		"Standard", "Small", "Smaller"
2201da177e4SLinus Torvalds 	};
2211da177e4SLinus Torvalds 
2223b7a00dcSTakashi Iwai 	return snd_ctl_enum_info(uinfo, 1, 3, texts);
2231da177e4SLinus Torvalds }
2241da177e4SLinus Torvalds 
22513043984SKeita Maehara static int snd_ac97_ymf7x3_get_speaker(struct snd_kcontrol *kcontrol,
22613043984SKeita Maehara 				       struct snd_ctl_elem_value *ucontrol)
2271da177e4SLinus Torvalds {
228ee42381eSTakashi Iwai 	struct snd_ac97 *ac97 = snd_kcontrol_chip(kcontrol);
2291da177e4SLinus Torvalds 	unsigned short val;
2301da177e4SLinus Torvalds 
23113043984SKeita Maehara 	val = ac97->regs[AC97_YMF7X3_3D_MODE_SEL];
2321da177e4SLinus Torvalds 	val = (val >> 10) & 3;
2331da177e4SLinus Torvalds 	if (val > 0)    /* 0 = invalid */
2341da177e4SLinus Torvalds 		val--;
2351da177e4SLinus Torvalds 	ucontrol->value.enumerated.item[0] = val;
2361da177e4SLinus Torvalds 	return 0;
2371da177e4SLinus Torvalds }
2381da177e4SLinus Torvalds 
23913043984SKeita Maehara static int snd_ac97_ymf7x3_put_speaker(struct snd_kcontrol *kcontrol,
24013043984SKeita Maehara 				       struct snd_ctl_elem_value *ucontrol)
2411da177e4SLinus Torvalds {
242ee42381eSTakashi Iwai 	struct snd_ac97 *ac97 = snd_kcontrol_chip(kcontrol);
2431da177e4SLinus Torvalds 	unsigned short val;
2441da177e4SLinus Torvalds 
2451da177e4SLinus Torvalds 	if (ucontrol->value.enumerated.item[0] > 2)
2461da177e4SLinus Torvalds 		return -EINVAL;
2471da177e4SLinus Torvalds 	val = (ucontrol->value.enumerated.item[0] + 1) << 10;
24813043984SKeita Maehara 	return snd_ac97_update(ac97, AC97_YMF7X3_3D_MODE_SEL, val);
2491da177e4SLinus Torvalds }
2501da177e4SLinus Torvalds 
25113043984SKeita Maehara static const struct snd_kcontrol_new snd_ac97_ymf7x3_controls_speaker =
2521da177e4SLinus Torvalds {
2531da177e4SLinus Torvalds 	.iface  = SNDRV_CTL_ELEM_IFACE_MIXER,
2541da177e4SLinus Torvalds 	.name   = "3D Control - Speaker",
25513043984SKeita Maehara 	.info   = snd_ac97_ymf7x3_info_speaker,
25613043984SKeita Maehara 	.get    = snd_ac97_ymf7x3_get_speaker,
25713043984SKeita Maehara 	.put    = snd_ac97_ymf7x3_put_speaker,
2581da177e4SLinus Torvalds };
2591da177e4SLinus Torvalds 
26013043984SKeita Maehara /* It is possible to indicate to the Yamaha YMF7x3 the source to
26113043984SKeita Maehara    direct to the S/PDIF output. */
26213043984SKeita Maehara static int snd_ac97_ymf7x3_spdif_source_info(struct snd_kcontrol *kcontrol,
26313043984SKeita Maehara 					     struct snd_ctl_elem_info *uinfo)
2641da177e4SLinus Torvalds {
2653b7a00dcSTakashi Iwai 	static const char * const texts[2] = { "AC-Link", "A/D Converter" };
2661da177e4SLinus Torvalds 
2673b7a00dcSTakashi Iwai 	return snd_ctl_enum_info(uinfo, 1, 2, texts);
2681da177e4SLinus Torvalds }
2691da177e4SLinus Torvalds 
27013043984SKeita Maehara static int snd_ac97_ymf7x3_spdif_source_get(struct snd_kcontrol *kcontrol,
27113043984SKeita Maehara 					    struct snd_ctl_elem_value *ucontrol)
2721da177e4SLinus Torvalds {
273ee42381eSTakashi Iwai 	struct snd_ac97 *ac97 = snd_kcontrol_chip(kcontrol);
2741da177e4SLinus Torvalds 	unsigned short val;
2751da177e4SLinus Torvalds 
27613043984SKeita Maehara 	val = ac97->regs[AC97_YMF7X3_DIT_CTRL];
2771da177e4SLinus Torvalds 	ucontrol->value.enumerated.item[0] = (val >> 1) & 1;
2781da177e4SLinus Torvalds 	return 0;
2791da177e4SLinus Torvalds }
2801da177e4SLinus Torvalds 
28113043984SKeita Maehara static int snd_ac97_ymf7x3_spdif_source_put(struct snd_kcontrol *kcontrol,
28213043984SKeita Maehara 					    struct snd_ctl_elem_value *ucontrol)
2831da177e4SLinus Torvalds {
284ee42381eSTakashi Iwai 	struct snd_ac97 *ac97 = snd_kcontrol_chip(kcontrol);
2851da177e4SLinus Torvalds 	unsigned short val;
2861da177e4SLinus Torvalds 
2871da177e4SLinus Torvalds 	if (ucontrol->value.enumerated.item[0] > 1)
2881da177e4SLinus Torvalds 		return -EINVAL;
2891da177e4SLinus Torvalds 	val = ucontrol->value.enumerated.item[0] << 1;
29013043984SKeita Maehara 	return snd_ac97_update_bits(ac97, AC97_YMF7X3_DIT_CTRL, 0x0002, val);
2911da177e4SLinus Torvalds }
2921da177e4SLinus Torvalds 
29343115f58SKeita Maehara static int patch_yamaha_ymf7x3_3d(struct snd_ac97 *ac97)
29443115f58SKeita Maehara {
29543115f58SKeita Maehara 	struct snd_kcontrol *kctl;
29643115f58SKeita Maehara 	int err;
29743115f58SKeita Maehara 
29843115f58SKeita Maehara 	kctl = snd_ac97_cnew(&snd_ac97_controls_3d[0], ac97);
29943115f58SKeita Maehara 	err = snd_ctl_add(ac97->bus->card, kctl);
30043115f58SKeita Maehara 	if (err < 0)
30143115f58SKeita Maehara 		return err;
30243115f58SKeita Maehara 	strcpy(kctl->id.name, "3D Control - Wide");
30343115f58SKeita Maehara 	kctl->private_value = AC97_SINGLE_VALUE(AC97_3D_CONTROL, 9, 7, 0);
30443115f58SKeita Maehara 	snd_ac97_write_cache(ac97, AC97_3D_CONTROL, 0x0000);
30543115f58SKeita Maehara 	err = snd_ctl_add(ac97->bus->card,
30643115f58SKeita Maehara 			  snd_ac97_cnew(&snd_ac97_ymf7x3_controls_speaker,
30743115f58SKeita Maehara 					ac97));
30843115f58SKeita Maehara 	if (err < 0)
30943115f58SKeita Maehara 		return err;
31043115f58SKeita Maehara 	snd_ac97_write_cache(ac97, AC97_YMF7X3_3D_MODE_SEL, 0x0c00);
31143115f58SKeita Maehara 	return 0;
31243115f58SKeita Maehara }
31343115f58SKeita Maehara 
31443115f58SKeita Maehara static const struct snd_kcontrol_new snd_ac97_yamaha_ymf743_controls_spdif[3] =
31543115f58SKeita Maehara {
31643115f58SKeita Maehara 	AC97_SINGLE(SNDRV_CTL_NAME_IEC958("", PLAYBACK, SWITCH),
31743115f58SKeita Maehara 		    AC97_YMF7X3_DIT_CTRL, 0, 1, 0),
31843115f58SKeita Maehara 	{
31943115f58SKeita Maehara 		.iface	= SNDRV_CTL_ELEM_IFACE_MIXER,
32043115f58SKeita Maehara 		.name	= SNDRV_CTL_NAME_IEC958("", PLAYBACK, NONE) "Source",
32143115f58SKeita Maehara 		.info	= snd_ac97_ymf7x3_spdif_source_info,
32243115f58SKeita Maehara 		.get	= snd_ac97_ymf7x3_spdif_source_get,
32343115f58SKeita Maehara 		.put	= snd_ac97_ymf7x3_spdif_source_put,
32443115f58SKeita Maehara 	},
32543115f58SKeita Maehara 	AC97_SINGLE(SNDRV_CTL_NAME_IEC958("", NONE, NONE) "Mute",
32643115f58SKeita Maehara 		    AC97_YMF7X3_DIT_CTRL, 2, 1, 1)
32743115f58SKeita Maehara };
32843115f58SKeita Maehara 
32943115f58SKeita Maehara static int patch_yamaha_ymf743_build_spdif(struct snd_ac97 *ac97)
33043115f58SKeita Maehara {
33143115f58SKeita Maehara 	int err;
33243115f58SKeita Maehara 
33343115f58SKeita Maehara 	err = patch_build_controls(ac97, &snd_ac97_controls_spdif[0], 3);
33443115f58SKeita Maehara 	if (err < 0)
33543115f58SKeita Maehara 		return err;
33643115f58SKeita Maehara 	err = patch_build_controls(ac97,
33743115f58SKeita Maehara 				   snd_ac97_yamaha_ymf743_controls_spdif, 3);
33843115f58SKeita Maehara 	if (err < 0)
33943115f58SKeita Maehara 		return err;
34043115f58SKeita Maehara 	/* set default PCM S/PDIF params */
34143115f58SKeita Maehara 	/* PCM audio,no copyright,no preemphasis,PCM coder,original */
34243115f58SKeita Maehara 	snd_ac97_write_cache(ac97, AC97_YMF7X3_DIT_CTRL, 0xa201);
34343115f58SKeita Maehara 	return 0;
34443115f58SKeita Maehara }
34543115f58SKeita Maehara 
3463e8b3b90SHanno Boeck static const struct snd_ac97_build_ops patch_yamaha_ymf743_ops = {
34743115f58SKeita Maehara 	.build_spdif	= patch_yamaha_ymf743_build_spdif,
34843115f58SKeita Maehara 	.build_3d	= patch_yamaha_ymf7x3_3d,
34943115f58SKeita Maehara };
35043115f58SKeita Maehara 
35143115f58SKeita Maehara static int patch_yamaha_ymf743(struct snd_ac97 *ac97)
35243115f58SKeita Maehara {
35343115f58SKeita Maehara 	ac97->build_ops = &patch_yamaha_ymf743_ops;
35443115f58SKeita Maehara 	ac97->caps |= AC97_BC_BASS_TREBLE;
35543115f58SKeita Maehara 	ac97->caps |= 0x04 << 10; /* Yamaha 3D enhancement */
35643115f58SKeita Maehara 	ac97->rates[AC97_RATES_SPDIF] = SNDRV_PCM_RATE_48000; /* 48k only */
35743115f58SKeita Maehara 	ac97->ext_id |= AC97_EI_SPDIF; /* force the detection of spdif */
35843115f58SKeita Maehara 	return 0;
35943115f58SKeita Maehara }
36043115f58SKeita Maehara 
3611da177e4SLinus Torvalds /* The AC'97 spec states that the S/PDIF signal is to be output at pin 48.
3621da177e4SLinus Torvalds    The YMF753 will output the S/PDIF signal to pin 43, 47 (EAPD), or 48.
3631da177e4SLinus Torvalds    By default, no output pin is selected, and the S/PDIF signal is not output.
3641da177e4SLinus Torvalds    There is also a bit to mute S/PDIF output in a vendor-specific register. */
365ee42381eSTakashi Iwai static int snd_ac97_ymf753_spdif_output_pin_info(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_info *uinfo)
3661da177e4SLinus Torvalds {
3673b7a00dcSTakashi Iwai 	static const char * const texts[3] = { "Disabled", "Pin 43", "Pin 48" };
3681da177e4SLinus Torvalds 
3693b7a00dcSTakashi Iwai 	return snd_ctl_enum_info(uinfo, 1, 3, texts);
3701da177e4SLinus Torvalds }
3711da177e4SLinus Torvalds 
372ee42381eSTakashi Iwai static int snd_ac97_ymf753_spdif_output_pin_get(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
3731da177e4SLinus Torvalds {
374ee42381eSTakashi Iwai 	struct snd_ac97 *ac97 = snd_kcontrol_chip(kcontrol);
3751da177e4SLinus Torvalds 	unsigned short val;
3761da177e4SLinus Torvalds 
37713043984SKeita Maehara 	val = ac97->regs[AC97_YMF7X3_DIT_CTRL];
3781da177e4SLinus Torvalds 	ucontrol->value.enumerated.item[0] = (val & 0x0008) ? 2 : (val & 0x0020) ? 1 : 0;
3791da177e4SLinus Torvalds 	return 0;
3801da177e4SLinus Torvalds }
3811da177e4SLinus Torvalds 
382ee42381eSTakashi Iwai static int snd_ac97_ymf753_spdif_output_pin_put(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
3831da177e4SLinus Torvalds {
384ee42381eSTakashi Iwai 	struct snd_ac97 *ac97 = snd_kcontrol_chip(kcontrol);
3851da177e4SLinus Torvalds 	unsigned short val;
3861da177e4SLinus Torvalds 
3871da177e4SLinus Torvalds 	if (ucontrol->value.enumerated.item[0] > 2)
3881da177e4SLinus Torvalds 		return -EINVAL;
3891da177e4SLinus Torvalds 	val = (ucontrol->value.enumerated.item[0] == 2) ? 0x0008 :
3901da177e4SLinus Torvalds 	      (ucontrol->value.enumerated.item[0] == 1) ? 0x0020 : 0;
39113043984SKeita Maehara 	return snd_ac97_update_bits(ac97, AC97_YMF7X3_DIT_CTRL, 0x0028, val);
3921da177e4SLinus Torvalds 	/* The following can be used to direct S/PDIF output to pin 47 (EAPD).
3931da177e4SLinus Torvalds 	   snd_ac97_write_cache(ac97, 0x62, snd_ac97_read(ac97, 0x62) | 0x0008); */
3941da177e4SLinus Torvalds }
3951da177e4SLinus Torvalds 
396ee42381eSTakashi Iwai static const struct snd_kcontrol_new snd_ac97_ymf753_controls_spdif[3] = {
3971da177e4SLinus Torvalds 	{
3981da177e4SLinus Torvalds 		.iface	= SNDRV_CTL_ELEM_IFACE_MIXER,
3991da177e4SLinus Torvalds 		.name	= SNDRV_CTL_NAME_IEC958("",PLAYBACK,NONE) "Source",
40013043984SKeita Maehara 		.info	= snd_ac97_ymf7x3_spdif_source_info,
40113043984SKeita Maehara 		.get	= snd_ac97_ymf7x3_spdif_source_get,
40213043984SKeita Maehara 		.put	= snd_ac97_ymf7x3_spdif_source_put,
4031da177e4SLinus Torvalds 	},
4041da177e4SLinus Torvalds 	{
4051da177e4SLinus Torvalds 		.iface	= SNDRV_CTL_ELEM_IFACE_MIXER,
4061da177e4SLinus Torvalds 		.name	= SNDRV_CTL_NAME_IEC958("",PLAYBACK,NONE) "Output Pin",
4071da177e4SLinus Torvalds 		.info	= snd_ac97_ymf753_spdif_output_pin_info,
4081da177e4SLinus Torvalds 		.get	= snd_ac97_ymf753_spdif_output_pin_get,
4091da177e4SLinus Torvalds 		.put	= snd_ac97_ymf753_spdif_output_pin_put,
4101da177e4SLinus Torvalds 	},
41113043984SKeita Maehara 	AC97_SINGLE(SNDRV_CTL_NAME_IEC958("", NONE, NONE) "Mute",
41213043984SKeita Maehara 		    AC97_YMF7X3_DIT_CTRL, 2, 1, 1)
4131da177e4SLinus Torvalds };
4141da177e4SLinus Torvalds 
415ee42381eSTakashi Iwai static int patch_yamaha_ymf753_post_spdif(struct snd_ac97 * ac97)
4161da177e4SLinus Torvalds {
4171da177e4SLinus Torvalds 	int err;
4181da177e4SLinus Torvalds 
4191da177e4SLinus Torvalds 	if ((err = patch_build_controls(ac97, snd_ac97_ymf753_controls_spdif, ARRAY_SIZE(snd_ac97_ymf753_controls_spdif))) < 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 
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 
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++) {
4643998b70fSLiam Girdwood 		if ((err = snd_ctl_add(ac97->bus->card, snd_ac97_cnew(&wm97xx_snd_ac97_controls[i], ac97))) < 0)
4653998b70fSLiam Girdwood 			return err;
4663998b70fSLiam Girdwood 	}
4671da177e4SLinus Torvalds 	snd_ac97_write_cache(ac97,  AC97_WM97XX_FMIXER_VOL, 0x0808);
4681da177e4SLinus Torvalds 	return 0;
4691da177e4SLinus Torvalds }
4701da177e4SLinus Torvalds 
4713e8b3b90SHanno Boeck static const struct snd_ac97_build_ops patch_wolfson_wm9703_ops = {
4723998b70fSLiam Girdwood 	.build_specific = patch_wolfson_wm9703_specific,
4733998b70fSLiam Girdwood };
4743998b70fSLiam Girdwood 
475ac519028STakashi Iwai static int patch_wolfson03(struct snd_ac97 * ac97)
4763998b70fSLiam Girdwood {
4773998b70fSLiam Girdwood 	ac97->build_ops = &patch_wolfson_wm9703_ops;
4783998b70fSLiam Girdwood 	return 0;
4793998b70fSLiam Girdwood }
4803998b70fSLiam Girdwood 
481ee42381eSTakashi Iwai static const struct snd_kcontrol_new wm9704_snd_ac97_controls[] = {
4823998b70fSLiam Girdwood AC97_DOUBLE("Front Playback Volume", AC97_WM97XX_FMIXER_VOL, 8, 0, 31, 1),
4833998b70fSLiam Girdwood AC97_SINGLE("Front Playback Switch", AC97_WM97XX_FMIXER_VOL, 15, 1, 1),
4843998b70fSLiam Girdwood AC97_DOUBLE("Rear Playback Volume", AC97_WM9704_RMIXER_VOL, 8, 0, 31, 1),
4853998b70fSLiam Girdwood AC97_SINGLE("Rear Playback Switch", AC97_WM9704_RMIXER_VOL, 15, 1, 1),
4863998b70fSLiam Girdwood AC97_DOUBLE("Rear DAC Volume", AC97_WM9704_RPCM_VOL, 8, 0, 31, 1),
4873998b70fSLiam Girdwood AC97_DOUBLE("Surround Volume", AC97_SURROUND_MASTER, 8, 0, 31, 1),
4883998b70fSLiam Girdwood };
4893998b70fSLiam Girdwood 
490ee42381eSTakashi Iwai static int patch_wolfson_wm9704_specific(struct snd_ac97 * ac97)
4913998b70fSLiam Girdwood {
4923998b70fSLiam Girdwood 	int err, i;
4933998b70fSLiam Girdwood 	for (i = 0; i < ARRAY_SIZE(wm9704_snd_ac97_controls); i++) {
4943998b70fSLiam Girdwood 		if ((err = snd_ctl_add(ac97->bus->card, snd_ac97_cnew(&wm9704_snd_ac97_controls[i], ac97))) < 0)
4953998b70fSLiam Girdwood 			return err;
4963998b70fSLiam Girdwood 	}
4973998b70fSLiam Girdwood 	/* patch for DVD noise */
4983998b70fSLiam Girdwood 	snd_ac97_write_cache(ac97, AC97_WM9704_TEST, 0x0200);
4993998b70fSLiam Girdwood 	return 0;
5003998b70fSLiam Girdwood }
5013998b70fSLiam Girdwood 
5023e8b3b90SHanno Boeck static const struct snd_ac97_build_ops patch_wolfson_wm9704_ops = {
5033998b70fSLiam Girdwood 	.build_specific = patch_wolfson_wm9704_specific,
5043998b70fSLiam Girdwood };
5053998b70fSLiam Girdwood 
506ac519028STakashi Iwai static int patch_wolfson04(struct snd_ac97 * ac97)
5071da177e4SLinus Torvalds {
5083998b70fSLiam Girdwood 	/* WM9704M/9704Q */
5093998b70fSLiam Girdwood 	ac97->build_ops = &patch_wolfson_wm9704_ops;
5101da177e4SLinus Torvalds 	return 0;
5111da177e4SLinus Torvalds }
5121da177e4SLinus Torvalds 
513ac519028STakashi Iwai static int patch_wolfson05(struct snd_ac97 * ac97)
5141da177e4SLinus Torvalds {
5153998b70fSLiam Girdwood 	/* WM9705, WM9710 */
516dd3533ecSKrzysztof Helt 	ac97->build_ops = &patch_wolfson_wm9703_ops;
5171459c784SRodolfo Giometti #ifdef CONFIG_TOUCHSCREEN_WM9705
5181459c784SRodolfo Giometti 	/* WM9705 touchscreen uses AUX and VIDEO for touch */
5198f88820eSLiam Girdwood 	ac97->flags |= AC97_HAS_NO_VIDEO | AC97_HAS_NO_AUX;
5201459c784SRodolfo Giometti #endif
5211da177e4SLinus Torvalds 	return 0;
5221da177e4SLinus Torvalds }
5231da177e4SLinus Torvalds 
5243998b70fSLiam Girdwood static const char* wm9711_alc_select[] = {"None", "Left", "Right", "Stereo"};
5253998b70fSLiam Girdwood static const char* wm9711_alc_mix[] = {"Stereo", "Right", "Left", "None"};
5263998b70fSLiam Girdwood static const char* wm9711_out3_src[] = {"Left", "VREF", "Left + Right", "Mono"};
5273998b70fSLiam Girdwood static const char* wm9711_out3_lrsrc[] = {"Master Mix", "Headphone Mix"};
5283998b70fSLiam Girdwood static const char* wm9711_rec_adc[] = {"Stereo", "Left", "Right", "Mute"};
5293998b70fSLiam Girdwood static const char* wm9711_base[] = {"Linear Control", "Adaptive Boost"};
5303998b70fSLiam Girdwood static const char* wm9711_rec_gain[] = {"+1.5dB Steps", "+0.75dB Steps"};
5313998b70fSLiam Girdwood static const char* wm9711_mic[] = {"Mic 1", "Differential", "Mic 2", "Stereo"};
5323998b70fSLiam Girdwood static const char* wm9711_rec_sel[] =
5333998b70fSLiam Girdwood 	{"Mic 1", "NC", "NC", "Master Mix", "Line", "Headphone Mix", "Phone Mix", "Phone"};
5343998b70fSLiam Girdwood static const char* wm9711_ng_type[] = {"Constant Gain", "Mute"};
5353998b70fSLiam Girdwood 
5363998b70fSLiam Girdwood static const struct ac97_enum wm9711_enum[] = {
5373998b70fSLiam Girdwood AC97_ENUM_SINGLE(AC97_PCI_SVID, 14, 4, wm9711_alc_select),
5383998b70fSLiam Girdwood AC97_ENUM_SINGLE(AC97_VIDEO, 10, 4, wm9711_alc_mix),
5393998b70fSLiam Girdwood AC97_ENUM_SINGLE(AC97_AUX, 9, 4, wm9711_out3_src),
5403998b70fSLiam Girdwood AC97_ENUM_SINGLE(AC97_AUX, 8, 2, wm9711_out3_lrsrc),
5413998b70fSLiam Girdwood AC97_ENUM_SINGLE(AC97_REC_SEL, 12, 4, wm9711_rec_adc),
5423998b70fSLiam Girdwood AC97_ENUM_SINGLE(AC97_MASTER_TONE, 15, 2, wm9711_base),
5433998b70fSLiam Girdwood AC97_ENUM_DOUBLE(AC97_REC_GAIN, 14, 6, 2, wm9711_rec_gain),
5443998b70fSLiam Girdwood AC97_ENUM_SINGLE(AC97_MIC, 5, 4, wm9711_mic),
5453998b70fSLiam Girdwood AC97_ENUM_DOUBLE(AC97_REC_SEL, 8, 0, 8, wm9711_rec_sel),
5463998b70fSLiam Girdwood AC97_ENUM_SINGLE(AC97_PCI_SVID, 5, 2, wm9711_ng_type),
5473998b70fSLiam Girdwood };
5483998b70fSLiam Girdwood 
549ee42381eSTakashi Iwai static const struct snd_kcontrol_new wm9711_snd_ac97_controls[] = {
5503998b70fSLiam Girdwood AC97_SINGLE("ALC Target Volume", AC97_CODEC_CLASS_REV, 12, 15, 0),
5513998b70fSLiam Girdwood AC97_SINGLE("ALC Hold Time", AC97_CODEC_CLASS_REV, 8, 15, 0),
5523998b70fSLiam Girdwood AC97_SINGLE("ALC Decay Time", AC97_CODEC_CLASS_REV, 4, 15, 0),
5533998b70fSLiam Girdwood AC97_SINGLE("ALC Attack Time", AC97_CODEC_CLASS_REV, 0, 15, 0),
5543998b70fSLiam Girdwood AC97_ENUM("ALC Function", wm9711_enum[0]),
5553998b70fSLiam Girdwood AC97_SINGLE("ALC Max Volume", AC97_PCI_SVID, 11, 7, 1),
5563998b70fSLiam Girdwood AC97_SINGLE("ALC ZC Timeout", AC97_PCI_SVID, 9, 3, 1),
5573998b70fSLiam Girdwood AC97_SINGLE("ALC ZC Switch", AC97_PCI_SVID, 8, 1, 0),
5583998b70fSLiam Girdwood AC97_SINGLE("ALC NG Switch", AC97_PCI_SVID, 7, 1, 0),
5593998b70fSLiam Girdwood AC97_ENUM("ALC NG Type", wm9711_enum[9]),
5603998b70fSLiam Girdwood AC97_SINGLE("ALC NG Threshold", AC97_PCI_SVID, 0, 31, 1),
5613998b70fSLiam Girdwood 
5623998b70fSLiam Girdwood AC97_SINGLE("Side Tone Switch", AC97_VIDEO, 15, 1, 1),
5633998b70fSLiam Girdwood AC97_SINGLE("Side Tone Volume", AC97_VIDEO, 12, 7, 1),
5643998b70fSLiam Girdwood AC97_ENUM("ALC Headphone Mux", wm9711_enum[1]),
5653998b70fSLiam Girdwood AC97_SINGLE("ALC Headphone Volume", AC97_VIDEO, 7, 7, 1),
5663998b70fSLiam Girdwood 
5673998b70fSLiam Girdwood AC97_SINGLE("Out3 Switch", AC97_AUX, 15, 1, 1),
5682aedbda6SLuke Zhang AC97_SINGLE("Out3 ZC Switch", AC97_AUX, 7, 1, 0),
5693998b70fSLiam Girdwood AC97_ENUM("Out3 Mux", wm9711_enum[2]),
5703998b70fSLiam Girdwood AC97_ENUM("Out3 LR Mux", wm9711_enum[3]),
5713998b70fSLiam Girdwood AC97_SINGLE("Out3 Volume", AC97_AUX, 0, 31, 1),
5723998b70fSLiam Girdwood 
5733998b70fSLiam Girdwood AC97_SINGLE("Beep to Headphone Switch", AC97_PC_BEEP, 15, 1, 1),
5743998b70fSLiam Girdwood AC97_SINGLE("Beep to Headphone Volume", AC97_PC_BEEP, 12, 7, 1),
5753998b70fSLiam Girdwood AC97_SINGLE("Beep to Side Tone Switch", AC97_PC_BEEP, 11, 1, 1),
5763998b70fSLiam Girdwood AC97_SINGLE("Beep to Side Tone Volume", AC97_PC_BEEP, 8, 7, 1),
5773998b70fSLiam Girdwood AC97_SINGLE("Beep to Phone Switch", AC97_PC_BEEP, 7, 1, 1),
5783998b70fSLiam Girdwood AC97_SINGLE("Beep to Phone Volume", AC97_PC_BEEP, 4, 7, 1),
5793998b70fSLiam Girdwood 
5803998b70fSLiam Girdwood AC97_SINGLE("Aux to Headphone Switch", AC97_CD, 15, 1, 1),
5813998b70fSLiam Girdwood AC97_SINGLE("Aux to Headphone Volume", AC97_CD, 12, 7, 1),
5823998b70fSLiam Girdwood AC97_SINGLE("Aux to Side Tone Switch", AC97_CD, 11, 1, 1),
5833998b70fSLiam Girdwood AC97_SINGLE("Aux to Side Tone Volume", AC97_CD, 8, 7, 1),
5843998b70fSLiam Girdwood AC97_SINGLE("Aux to Phone Switch", AC97_CD, 7, 1, 1),
5853998b70fSLiam Girdwood AC97_SINGLE("Aux to Phone Volume", AC97_CD, 4, 7, 1),
5863998b70fSLiam Girdwood 
5873998b70fSLiam Girdwood AC97_SINGLE("Phone to Headphone Switch", AC97_PHONE, 15, 1, 1),
5883998b70fSLiam Girdwood AC97_SINGLE("Phone to Master Switch", AC97_PHONE, 14, 1, 1),
5893998b70fSLiam Girdwood 
5903998b70fSLiam Girdwood AC97_SINGLE("Line to Headphone Switch", AC97_LINE, 15, 1, 1),
5913998b70fSLiam Girdwood AC97_SINGLE("Line to Master Switch", AC97_LINE, 14, 1, 1),
5923998b70fSLiam Girdwood AC97_SINGLE("Line to Phone Switch", AC97_LINE, 13, 1, 1),
5933998b70fSLiam Girdwood 
5943998b70fSLiam Girdwood AC97_SINGLE("PCM Playback to Headphone Switch", AC97_PCM, 15, 1, 1),
5953998b70fSLiam Girdwood AC97_SINGLE("PCM Playback to Master Switch", AC97_PCM, 14, 1, 1),
5963998b70fSLiam Girdwood AC97_SINGLE("PCM Playback to Phone Switch", AC97_PCM, 13, 1, 1),
5973998b70fSLiam Girdwood 
5983998b70fSLiam Girdwood AC97_SINGLE("Capture 20dB Boost Switch", AC97_REC_SEL, 14, 1, 0),
5993998b70fSLiam Girdwood AC97_ENUM("Capture to Phone Mux", wm9711_enum[4]),
6003998b70fSLiam Girdwood AC97_SINGLE("Capture to Phone 20dB Boost Switch", AC97_REC_SEL, 11, 1, 1),
6013998b70fSLiam Girdwood AC97_ENUM("Capture Select", wm9711_enum[8]),
6023998b70fSLiam Girdwood 
6033998b70fSLiam Girdwood AC97_SINGLE("3D Upper Cut-off Switch", AC97_3D_CONTROL, 5, 1, 1),
6043998b70fSLiam Girdwood AC97_SINGLE("3D Lower Cut-off Switch", AC97_3D_CONTROL, 4, 1, 1),
6053998b70fSLiam Girdwood 
6063998b70fSLiam Girdwood AC97_ENUM("Bass Control", wm9711_enum[5]),
6073998b70fSLiam Girdwood AC97_SINGLE("Bass Cut-off Switch", AC97_MASTER_TONE, 12, 1, 1),
6083998b70fSLiam Girdwood AC97_SINGLE("Tone Cut-off Switch", AC97_MASTER_TONE, 4, 1, 1),
6093998b70fSLiam Girdwood AC97_SINGLE("Playback Attenuate (-6dB) Switch", AC97_MASTER_TONE, 6, 1, 0),
6103998b70fSLiam Girdwood 
6113998b70fSLiam Girdwood AC97_SINGLE("ADC Switch", AC97_REC_GAIN, 15, 1, 1),
6123998b70fSLiam Girdwood AC97_ENUM("Capture Volume Steps", wm9711_enum[6]),
6132aedbda6SLuke Zhang AC97_DOUBLE("Capture Volume", AC97_REC_GAIN, 8, 0, 63, 1),
6143998b70fSLiam Girdwood AC97_SINGLE("Capture ZC Switch", AC97_REC_GAIN, 7, 1, 0),
6153998b70fSLiam Girdwood 
6163998b70fSLiam Girdwood AC97_SINGLE("Mic 1 to Phone Switch", AC97_MIC, 14, 1, 1),
6173998b70fSLiam Girdwood AC97_SINGLE("Mic 2 to Phone Switch", AC97_MIC, 13, 1, 1),
6183998b70fSLiam Girdwood AC97_ENUM("Mic Select Source", wm9711_enum[7]),
6192aedbda6SLuke Zhang AC97_SINGLE("Mic 1 Volume", AC97_MIC, 8, 31, 1),
6202aedbda6SLuke Zhang AC97_SINGLE("Mic 2 Volume", AC97_MIC, 0, 31, 1),
621d7f6f115SJames Courtier-Dutton AC97_SINGLE("Mic 20dB Boost Switch", AC97_MIC, 7, 1, 0),
6223998b70fSLiam Girdwood 
6230264b3b6SJuergen Beisert AC97_SINGLE("Master Left Inv Switch", AC97_MASTER, 6, 1, 0),
6243998b70fSLiam Girdwood AC97_SINGLE("Master ZC Switch", AC97_MASTER, 7, 1, 0),
6253998b70fSLiam Girdwood AC97_SINGLE("Headphone ZC Switch", AC97_HEADPHONE, 7, 1, 0),
6263998b70fSLiam Girdwood AC97_SINGLE("Mono ZC Switch", AC97_MASTER_MONO, 7, 1, 0),
6273998b70fSLiam Girdwood };
6283998b70fSLiam Girdwood 
629ee42381eSTakashi Iwai static int patch_wolfson_wm9711_specific(struct snd_ac97 * ac97)
6303998b70fSLiam Girdwood {
6313998b70fSLiam Girdwood 	int err, i;
6323998b70fSLiam Girdwood 
6333998b70fSLiam Girdwood 	for (i = 0; i < ARRAY_SIZE(wm9711_snd_ac97_controls); i++) {
6343998b70fSLiam Girdwood 		if ((err = snd_ctl_add(ac97->bus->card, snd_ac97_cnew(&wm9711_snd_ac97_controls[i], ac97))) < 0)
6353998b70fSLiam Girdwood 			return err;
6363998b70fSLiam Girdwood 	}
6373998b70fSLiam Girdwood 	snd_ac97_write_cache(ac97,  AC97_CODEC_CLASS_REV, 0x0808);
6383998b70fSLiam Girdwood 	snd_ac97_write_cache(ac97,  AC97_PCI_SVID, 0x0808);
6393998b70fSLiam Girdwood 	snd_ac97_write_cache(ac97,  AC97_VIDEO, 0x0808);
6403998b70fSLiam Girdwood 	snd_ac97_write_cache(ac97,  AC97_AUX, 0x0808);
6413998b70fSLiam Girdwood 	snd_ac97_write_cache(ac97,  AC97_PC_BEEP, 0x0808);
6423998b70fSLiam Girdwood 	snd_ac97_write_cache(ac97,  AC97_CD, 0x0000);
6433998b70fSLiam Girdwood 	return 0;
6443998b70fSLiam Girdwood }
6453998b70fSLiam Girdwood 
6463e8b3b90SHanno Boeck static const struct snd_ac97_build_ops patch_wolfson_wm9711_ops = {
6473998b70fSLiam Girdwood 	.build_specific = patch_wolfson_wm9711_specific,
6483998b70fSLiam Girdwood };
6493998b70fSLiam Girdwood 
650ac519028STakashi Iwai static int patch_wolfson11(struct snd_ac97 * ac97)
6511da177e4SLinus Torvalds {
6523998b70fSLiam Girdwood 	/* WM9711, WM9712 */
6533998b70fSLiam Girdwood 	ac97->build_ops = &patch_wolfson_wm9711_ops;
6543998b70fSLiam Girdwood 
6553998b70fSLiam Girdwood 	ac97->flags |= AC97_HAS_NO_REC_GAIN | AC97_STEREO_MUTES | AC97_HAS_NO_MIC |
6563998b70fSLiam Girdwood 		AC97_HAS_NO_PC_BEEP | AC97_HAS_NO_VIDEO | AC97_HAS_NO_CD;
6573998b70fSLiam Girdwood 
6581da177e4SLinus Torvalds 	return 0;
6591da177e4SLinus Torvalds }
6601da177e4SLinus Torvalds 
6611da177e4SLinus Torvalds static const char* wm9713_mic_mixer[] = {"Stereo", "Mic 1", "Mic 2", "Mute"};
6621da177e4SLinus Torvalds static const char* wm9713_rec_mux[] = {"Stereo", "Left", "Right", "Mute"};
6633998b70fSLiam Girdwood static const char* wm9713_rec_src[] =
6643998b70fSLiam Girdwood 	{"Mic 1", "Mic 2", "Line", "Mono In", "Headphone Mix", "Master Mix",
6653998b70fSLiam Girdwood 	"Mono Mix", "Zh"};
6663998b70fSLiam Girdwood static const char* wm9713_rec_gain[] = {"+1.5dB Steps", "+0.75dB Steps"};
6673998b70fSLiam Girdwood static const char* wm9713_alc_select[] = {"None", "Left", "Right", "Stereo"};
6683998b70fSLiam Girdwood static const char* wm9713_mono_pga[] = {"Vmid", "Zh", "Mono Mix", "Inv 1"};
6693998b70fSLiam Girdwood static const char* wm9713_spk_pga[] =
6703998b70fSLiam Girdwood 	{"Vmid", "Zh", "Headphone Mix", "Master Mix", "Inv", "NC", "NC", "NC"};
6713998b70fSLiam Girdwood static const char* wm9713_hp_pga[] = {"Vmid", "Zh", "Headphone Mix", "NC"};
6723998b70fSLiam Girdwood static const char* wm9713_out3_pga[] = {"Vmid", "Zh", "Inv 1", "NC"};
6733998b70fSLiam Girdwood static const char* wm9713_out4_pga[] = {"Vmid", "Zh", "Inv 2", "NC"};
6743998b70fSLiam Girdwood static const char* wm9713_dac_inv[] =
6753998b70fSLiam Girdwood 	{"Off", "Mono Mix", "Master Mix", "Headphone Mix L", "Headphone Mix R",
6763998b70fSLiam Girdwood 	"Headphone Mix Mono", "NC", "Vmid"};
6773998b70fSLiam Girdwood static const char* wm9713_base[] = {"Linear Control", "Adaptive Boost"};
6783998b70fSLiam Girdwood static const char* wm9713_ng_type[] = {"Constant Gain", "Mute"};
6791da177e4SLinus Torvalds 
6801da177e4SLinus Torvalds static const struct ac97_enum wm9713_enum[] = {
6811da177e4SLinus Torvalds AC97_ENUM_SINGLE(AC97_LINE, 3, 4, wm9713_mic_mixer),
6821da177e4SLinus Torvalds AC97_ENUM_SINGLE(AC97_VIDEO, 14, 4, wm9713_rec_mux),
6831da177e4SLinus Torvalds AC97_ENUM_SINGLE(AC97_VIDEO, 9, 4, wm9713_rec_mux),
6843998b70fSLiam Girdwood AC97_ENUM_DOUBLE(AC97_VIDEO, 3, 0, 8, wm9713_rec_src),
6853998b70fSLiam Girdwood AC97_ENUM_DOUBLE(AC97_CD, 14, 6, 2, wm9713_rec_gain),
6863998b70fSLiam Girdwood AC97_ENUM_SINGLE(AC97_PCI_SVID, 14, 4, wm9713_alc_select),
6873998b70fSLiam Girdwood AC97_ENUM_SINGLE(AC97_REC_GAIN, 14, 4, wm9713_mono_pga),
6883998b70fSLiam Girdwood AC97_ENUM_DOUBLE(AC97_REC_GAIN, 11, 8, 8, wm9713_spk_pga),
6893998b70fSLiam Girdwood AC97_ENUM_DOUBLE(AC97_REC_GAIN, 6, 4, 4, wm9713_hp_pga),
6903998b70fSLiam Girdwood AC97_ENUM_SINGLE(AC97_REC_GAIN, 2, 4, wm9713_out3_pga),
6913998b70fSLiam Girdwood AC97_ENUM_SINGLE(AC97_REC_GAIN, 0, 4, wm9713_out4_pga),
6923998b70fSLiam Girdwood AC97_ENUM_DOUBLE(AC97_REC_GAIN_MIC, 13, 10, 8, wm9713_dac_inv),
6933998b70fSLiam Girdwood AC97_ENUM_SINGLE(AC97_GENERAL_PURPOSE, 15, 2, wm9713_base),
6943998b70fSLiam Girdwood AC97_ENUM_SINGLE(AC97_PCI_SVID, 5, 2, wm9713_ng_type),
6951da177e4SLinus Torvalds };
6961da177e4SLinus Torvalds 
697ee42381eSTakashi Iwai static const struct snd_kcontrol_new wm13_snd_ac97_controls[] = {
6981da177e4SLinus Torvalds AC97_DOUBLE("Line In Volume", AC97_PC_BEEP, 8, 0, 31, 1),
6993998b70fSLiam Girdwood AC97_SINGLE("Line In to Headphone Switch", AC97_PC_BEEP, 15, 1, 1),
7003998b70fSLiam Girdwood AC97_SINGLE("Line In to Master Switch", AC97_PC_BEEP, 14, 1, 1),
7013998b70fSLiam Girdwood AC97_SINGLE("Line In to Mono Switch", AC97_PC_BEEP, 13, 1, 1),
7023998b70fSLiam Girdwood 
7033998b70fSLiam Girdwood AC97_DOUBLE("PCM Playback Volume", AC97_PHONE, 8, 0, 31, 1),
7043998b70fSLiam Girdwood AC97_SINGLE("PCM Playback to Headphone Switch", AC97_PHONE, 15, 1, 1),
7053998b70fSLiam Girdwood AC97_SINGLE("PCM Playback to Master Switch", AC97_PHONE, 14, 1, 1),
7063998b70fSLiam Girdwood AC97_SINGLE("PCM Playback to Mono Switch", AC97_PHONE, 13, 1, 1),
7073998b70fSLiam Girdwood 
7083998b70fSLiam Girdwood AC97_SINGLE("Mic 1 Volume", AC97_MIC, 8, 31, 1),
7093998b70fSLiam Girdwood AC97_SINGLE("Mic 2 Volume", AC97_MIC, 0, 31, 1),
7103998b70fSLiam Girdwood AC97_SINGLE("Mic 1 to Mono Switch", AC97_LINE, 7, 1, 1),
7113998b70fSLiam Girdwood AC97_SINGLE("Mic 2 to Mono Switch", AC97_LINE, 6, 1, 1),
712d7f6f115SJames Courtier-Dutton AC97_SINGLE("Mic Boost (+20dB) Switch", AC97_LINE, 5, 1, 0),
7133998b70fSLiam Girdwood AC97_ENUM("Mic to Headphone Mux", wm9713_enum[0]),
7143998b70fSLiam Girdwood AC97_SINGLE("Mic Headphone Mixer Volume", AC97_LINE, 0, 7, 1),
7153998b70fSLiam Girdwood 
7163998b70fSLiam Girdwood AC97_SINGLE("Capture Switch", AC97_CD, 15, 1, 1),
7173998b70fSLiam Girdwood AC97_ENUM("Capture Volume Steps", wm9713_enum[4]),
7183998b70fSLiam Girdwood AC97_DOUBLE("Capture Volume", AC97_CD, 8, 0, 15, 0),
7193998b70fSLiam Girdwood AC97_SINGLE("Capture ZC Switch", AC97_CD, 7, 1, 0),
7203998b70fSLiam Girdwood 
7213998b70fSLiam Girdwood AC97_ENUM("Capture to Headphone Mux", wm9713_enum[1]),
7223998b70fSLiam Girdwood AC97_SINGLE("Capture to Headphone Volume", AC97_VIDEO, 11, 7, 1),
7233998b70fSLiam Girdwood AC97_ENUM("Capture to Mono Mux", wm9713_enum[2]),
7243998b70fSLiam Girdwood AC97_SINGLE("Capture to Mono Boost (+20dB) Switch", AC97_VIDEO, 8, 1, 0),
7253998b70fSLiam Girdwood AC97_SINGLE("Capture ADC Boost (+20dB) Switch", AC97_VIDEO, 6, 1, 0),
7263998b70fSLiam Girdwood AC97_ENUM("Capture Select", wm9713_enum[3]),
7273998b70fSLiam Girdwood 
7283998b70fSLiam Girdwood AC97_SINGLE("ALC Target Volume", AC97_CODEC_CLASS_REV, 12, 15, 0),
7293998b70fSLiam Girdwood AC97_SINGLE("ALC Hold Time", AC97_CODEC_CLASS_REV, 8, 15, 0),
7303998b70fSLiam Girdwood AC97_SINGLE("ALC Decay Time ", AC97_CODEC_CLASS_REV, 4, 15, 0),
7313998b70fSLiam Girdwood AC97_SINGLE("ALC Attack Time", AC97_CODEC_CLASS_REV, 0, 15, 0),
7323998b70fSLiam Girdwood AC97_ENUM("ALC Function", wm9713_enum[5]),
7333998b70fSLiam Girdwood AC97_SINGLE("ALC Max Volume", AC97_PCI_SVID, 11, 7, 0),
7343998b70fSLiam Girdwood AC97_SINGLE("ALC ZC Timeout", AC97_PCI_SVID, 9, 3, 0),
7353998b70fSLiam Girdwood AC97_SINGLE("ALC ZC Switch", AC97_PCI_SVID, 8, 1, 0),
7363998b70fSLiam Girdwood AC97_SINGLE("ALC NG Switch", AC97_PCI_SVID, 7, 1, 0),
7373998b70fSLiam Girdwood AC97_ENUM("ALC NG Type", wm9713_enum[13]),
7383998b70fSLiam Girdwood AC97_SINGLE("ALC NG Threshold", AC97_PCI_SVID, 0, 31, 0),
7393998b70fSLiam Girdwood 
7403998b70fSLiam Girdwood AC97_DOUBLE("Master ZC Switch", AC97_MASTER, 14, 6, 1, 0),
7413998b70fSLiam Girdwood AC97_DOUBLE("Headphone ZC Switch", AC97_HEADPHONE, 14, 6, 1, 0),
7423998b70fSLiam Girdwood AC97_DOUBLE("Out3/4 ZC Switch", AC97_MASTER_MONO, 14, 6, 1, 0),
7433998b70fSLiam Girdwood AC97_SINGLE("Master Right Switch", AC97_MASTER, 7, 1, 1),
7443998b70fSLiam Girdwood AC97_SINGLE("Headphone Right Switch", AC97_HEADPHONE, 7, 1, 1),
7453998b70fSLiam Girdwood AC97_SINGLE("Out3/4 Right Switch", AC97_MASTER_MONO, 7, 1, 1),
7463998b70fSLiam Girdwood 
7473998b70fSLiam Girdwood AC97_SINGLE("Mono In to Headphone Switch", AC97_MASTER_TONE, 15, 1, 1),
7483998b70fSLiam Girdwood AC97_SINGLE("Mono In to Master Switch", AC97_MASTER_TONE, 14, 1, 1),
7493998b70fSLiam Girdwood AC97_SINGLE("Mono In Volume", AC97_MASTER_TONE, 8, 31, 1),
7503998b70fSLiam Girdwood AC97_SINGLE("Mono Switch", AC97_MASTER_TONE, 7, 1, 1),
7513998b70fSLiam Girdwood AC97_SINGLE("Mono ZC Switch", AC97_MASTER_TONE, 6, 1, 0),
7523998b70fSLiam Girdwood AC97_SINGLE("Mono Volume", AC97_MASTER_TONE, 0, 31, 1),
7533998b70fSLiam Girdwood 
754d355c82aSJaroslav Kysela AC97_SINGLE("Beep to Headphone Switch", AC97_AUX, 15, 1, 1),
755d355c82aSJaroslav Kysela AC97_SINGLE("Beep to Headphone Volume", AC97_AUX, 12, 7, 1),
756d355c82aSJaroslav Kysela AC97_SINGLE("Beep to Master Switch", AC97_AUX, 11, 1, 1),
757d355c82aSJaroslav Kysela AC97_SINGLE("Beep to Master Volume", AC97_AUX, 8, 7, 1),
758d355c82aSJaroslav Kysela AC97_SINGLE("Beep to Mono Switch", AC97_AUX, 7, 1, 1),
759d355c82aSJaroslav Kysela AC97_SINGLE("Beep to Mono Volume", AC97_AUX, 4, 7, 1),
7603998b70fSLiam Girdwood 
7613998b70fSLiam Girdwood AC97_SINGLE("Voice to Headphone Switch", AC97_PCM, 15, 1, 1),
7623998b70fSLiam Girdwood AC97_SINGLE("Voice to Headphone Volume", AC97_PCM, 12, 7, 1),
7633998b70fSLiam Girdwood AC97_SINGLE("Voice to Master Switch", AC97_PCM, 11, 1, 1),
7643998b70fSLiam Girdwood AC97_SINGLE("Voice to Master Volume", AC97_PCM, 8, 7, 1),
7653998b70fSLiam Girdwood AC97_SINGLE("Voice to Mono Switch", AC97_PCM, 7, 1, 1),
7663998b70fSLiam Girdwood AC97_SINGLE("Voice to Mono Volume", AC97_PCM, 4, 7, 1),
7673998b70fSLiam Girdwood 
7683998b70fSLiam Girdwood AC97_SINGLE("Aux to Headphone Switch", AC97_REC_SEL, 15, 1, 1),
7693998b70fSLiam Girdwood AC97_SINGLE("Aux to Headphone Volume", AC97_REC_SEL, 12, 7, 1),
7703998b70fSLiam Girdwood AC97_SINGLE("Aux to Master Switch", AC97_REC_SEL, 11, 1, 1),
7713998b70fSLiam Girdwood AC97_SINGLE("Aux to Master Volume", AC97_REC_SEL, 8, 7, 1),
7723998b70fSLiam Girdwood AC97_SINGLE("Aux to Mono Switch", AC97_REC_SEL, 7, 1, 1),
7733998b70fSLiam Girdwood AC97_SINGLE("Aux to Mono Volume", AC97_REC_SEL, 4, 7, 1),
7743998b70fSLiam Girdwood 
7753998b70fSLiam Girdwood AC97_ENUM("Mono Input Mux", wm9713_enum[6]),
7763998b70fSLiam Girdwood AC97_ENUM("Master Input Mux", wm9713_enum[7]),
7773998b70fSLiam Girdwood AC97_ENUM("Headphone Input Mux", wm9713_enum[8]),
7783998b70fSLiam Girdwood AC97_ENUM("Out 3 Input Mux", wm9713_enum[9]),
7793998b70fSLiam Girdwood AC97_ENUM("Out 4 Input Mux", wm9713_enum[10]),
7803998b70fSLiam Girdwood 
7813998b70fSLiam Girdwood AC97_ENUM("Bass Control", wm9713_enum[12]),
7823998b70fSLiam Girdwood AC97_SINGLE("Bass Cut-off Switch", AC97_GENERAL_PURPOSE, 12, 1, 1),
7833998b70fSLiam Girdwood AC97_SINGLE("Tone Cut-off Switch", AC97_GENERAL_PURPOSE, 4, 1, 1),
7843998b70fSLiam Girdwood AC97_SINGLE("Playback Attenuate (-6dB) Switch", AC97_GENERAL_PURPOSE, 6, 1, 0),
7853998b70fSLiam Girdwood AC97_SINGLE("Bass Volume", AC97_GENERAL_PURPOSE, 8, 15, 1),
7863998b70fSLiam Girdwood AC97_SINGLE("Tone Volume", AC97_GENERAL_PURPOSE, 0, 15, 1),
7871da177e4SLinus Torvalds };
7881da177e4SLinus Torvalds 
789ee42381eSTakashi Iwai static const struct snd_kcontrol_new wm13_snd_ac97_controls_3d[] = {
7903998b70fSLiam Girdwood AC97_ENUM("Inv Input Mux", wm9713_enum[11]),
7913998b70fSLiam Girdwood AC97_SINGLE("3D Upper Cut-off Switch", AC97_REC_GAIN_MIC, 5, 1, 0),
7923998b70fSLiam Girdwood AC97_SINGLE("3D Lower Cut-off Switch", AC97_REC_GAIN_MIC, 4, 1, 0),
7933998b70fSLiam Girdwood AC97_SINGLE("3D Depth", AC97_REC_GAIN_MIC, 0, 15, 1),
7941da177e4SLinus Torvalds };
7951da177e4SLinus Torvalds 
796ee42381eSTakashi Iwai static int patch_wolfson_wm9713_3d (struct snd_ac97 * ac97)
7973998b70fSLiam Girdwood {
7983998b70fSLiam Girdwood 	int err, i;
7991da177e4SLinus Torvalds 
8003998b70fSLiam Girdwood 	for (i = 0; i < ARRAY_SIZE(wm13_snd_ac97_controls_3d); i++) {
8013998b70fSLiam Girdwood 		if ((err = snd_ctl_add(ac97->bus->card, snd_ac97_cnew(&wm13_snd_ac97_controls_3d[i], ac97))) < 0)
8023998b70fSLiam Girdwood 			return err;
8033998b70fSLiam Girdwood 	}
8043998b70fSLiam Girdwood 	return 0;
8053998b70fSLiam Girdwood }
8061da177e4SLinus Torvalds 
807ee42381eSTakashi Iwai static int patch_wolfson_wm9713_specific(struct snd_ac97 * ac97)
8081da177e4SLinus Torvalds {
8091da177e4SLinus Torvalds 	int err, i;
8101da177e4SLinus Torvalds 
8113998b70fSLiam Girdwood 	for (i = 0; i < ARRAY_SIZE(wm13_snd_ac97_controls); i++) {
8123998b70fSLiam Girdwood 		if ((err = snd_ctl_add(ac97->bus->card, snd_ac97_cnew(&wm13_snd_ac97_controls[i], ac97))) < 0)
8131da177e4SLinus Torvalds 			return err;
8141da177e4SLinus Torvalds 	}
8151da177e4SLinus Torvalds 	snd_ac97_write_cache(ac97, AC97_PC_BEEP, 0x0808);
8161da177e4SLinus Torvalds 	snd_ac97_write_cache(ac97, AC97_PHONE, 0x0808);
8171da177e4SLinus Torvalds 	snd_ac97_write_cache(ac97, AC97_MIC, 0x0808);
8181da177e4SLinus Torvalds 	snd_ac97_write_cache(ac97, AC97_LINE, 0x00da);
8191da177e4SLinus Torvalds 	snd_ac97_write_cache(ac97, AC97_CD, 0x0808);
8201da177e4SLinus Torvalds 	snd_ac97_write_cache(ac97, AC97_VIDEO, 0xd612);
8211da177e4SLinus Torvalds 	snd_ac97_write_cache(ac97, AC97_REC_GAIN, 0x1ba0);
8221da177e4SLinus Torvalds 	return 0;
8231da177e4SLinus Torvalds }
8241da177e4SLinus Torvalds 
8251da177e4SLinus Torvalds #ifdef CONFIG_PM
826ee42381eSTakashi Iwai static void patch_wolfson_wm9713_suspend (struct snd_ac97 * ac97)
8271da177e4SLinus Torvalds {
8281da177e4SLinus Torvalds 	snd_ac97_write_cache(ac97, AC97_EXTENDED_MID, 0xfeff);
8291da177e4SLinus Torvalds 	snd_ac97_write_cache(ac97, AC97_EXTENDED_MSTATUS, 0xffff);
8301da177e4SLinus Torvalds }
8311da177e4SLinus Torvalds 
832ee42381eSTakashi Iwai static void patch_wolfson_wm9713_resume (struct snd_ac97 * ac97)
8331da177e4SLinus Torvalds {
8341da177e4SLinus Torvalds 	snd_ac97_write_cache(ac97, AC97_EXTENDED_MID, 0xda00);
8351da177e4SLinus Torvalds 	snd_ac97_write_cache(ac97, AC97_EXTENDED_MSTATUS, 0x3810);
8361da177e4SLinus Torvalds 	snd_ac97_write_cache(ac97, AC97_POWERDOWN, 0x0);
8371da177e4SLinus Torvalds }
8381da177e4SLinus Torvalds #endif
8391da177e4SLinus Torvalds 
8403e8b3b90SHanno Boeck static const struct snd_ac97_build_ops patch_wolfson_wm9713_ops = {
8411da177e4SLinus Torvalds 	.build_specific = patch_wolfson_wm9713_specific,
8423998b70fSLiam Girdwood 	.build_3d = patch_wolfson_wm9713_3d,
8431da177e4SLinus Torvalds #ifdef CONFIG_PM
8441da177e4SLinus Torvalds 	.suspend = patch_wolfson_wm9713_suspend,
8451da177e4SLinus Torvalds 	.resume = patch_wolfson_wm9713_resume
8461da177e4SLinus Torvalds #endif
8471da177e4SLinus Torvalds };
8481da177e4SLinus Torvalds 
849ac519028STakashi Iwai static int patch_wolfson13(struct snd_ac97 * ac97)
8501da177e4SLinus Torvalds {
8513998b70fSLiam Girdwood 	/* WM9713, WM9714 */
8521da177e4SLinus Torvalds 	ac97->build_ops = &patch_wolfson_wm9713_ops;
8531da177e4SLinus Torvalds 
8541da177e4SLinus Torvalds 	ac97->flags |= AC97_HAS_NO_REC_GAIN | AC97_STEREO_MUTES | AC97_HAS_NO_PHONE |
8553998b70fSLiam Girdwood 		AC97_HAS_NO_PC_BEEP | AC97_HAS_NO_VIDEO | AC97_HAS_NO_CD | AC97_HAS_NO_TONE |
8563998b70fSLiam Girdwood 		AC97_HAS_NO_STD_PCM;
857064d2112SLiam Girdwood     	ac97->scaps &= ~AC97_SCAP_MODEM;
8581da177e4SLinus Torvalds 
8591da177e4SLinus Torvalds 	snd_ac97_write_cache(ac97, AC97_EXTENDED_MID, 0xda00);
8601da177e4SLinus Torvalds 	snd_ac97_write_cache(ac97, AC97_EXTENDED_MSTATUS, 0x3810);
8611da177e4SLinus Torvalds 	snd_ac97_write_cache(ac97, AC97_POWERDOWN, 0x0);
8621da177e4SLinus Torvalds 
8631da177e4SLinus Torvalds 	return 0;
8641da177e4SLinus Torvalds }
8651da177e4SLinus Torvalds 
8661da177e4SLinus Torvalds /*
8671da177e4SLinus Torvalds  * Tritech codec
8681da177e4SLinus Torvalds  */
869ac519028STakashi Iwai static int patch_tritech_tr28028(struct snd_ac97 * ac97)
8701da177e4SLinus Torvalds {
8711da177e4SLinus Torvalds 	snd_ac97_write_cache(ac97, 0x26, 0x0300);
8721da177e4SLinus Torvalds 	snd_ac97_write_cache(ac97, 0x26, 0x0000);
8731da177e4SLinus Torvalds 	snd_ac97_write_cache(ac97, AC97_SURROUND_MASTER, 0x0000);
8741da177e4SLinus Torvalds 	snd_ac97_write_cache(ac97, AC97_SPDIF, 0x0000);
8751da177e4SLinus Torvalds 	return 0;
8761da177e4SLinus Torvalds }
8771da177e4SLinus Torvalds 
8781da177e4SLinus Torvalds /*
8791da177e4SLinus Torvalds  * Sigmatel STAC97xx codecs
8801da177e4SLinus Torvalds  */
881ee42381eSTakashi Iwai static int patch_sigmatel_stac9700_3d(struct snd_ac97 * ac97)
8821da177e4SLinus Torvalds {
883ee42381eSTakashi Iwai 	struct snd_kcontrol *kctl;
8841da177e4SLinus Torvalds 	int err;
8851da177e4SLinus Torvalds 
8861da177e4SLinus Torvalds 	if ((err = snd_ctl_add(ac97->bus->card, kctl = snd_ac97_cnew(&snd_ac97_controls_3d[0], ac97))) < 0)
8871da177e4SLinus Torvalds 		return err;
8881da177e4SLinus Torvalds 	strcpy(kctl->id.name, "3D Control Sigmatel - Depth");
8891da177e4SLinus Torvalds 	kctl->private_value = AC97_SINGLE_VALUE(AC97_3D_CONTROL, 2, 3, 0);
8901da177e4SLinus Torvalds 	snd_ac97_write_cache(ac97, AC97_3D_CONTROL, 0x0000);
8911da177e4SLinus Torvalds 	return 0;
8921da177e4SLinus Torvalds }
8931da177e4SLinus Torvalds 
894ee42381eSTakashi Iwai static int patch_sigmatel_stac9708_3d(struct snd_ac97 * ac97)
8951da177e4SLinus Torvalds {
896ee42381eSTakashi Iwai 	struct snd_kcontrol *kctl;
8971da177e4SLinus Torvalds 	int err;
8981da177e4SLinus Torvalds 
8991da177e4SLinus Torvalds 	if ((err = snd_ctl_add(ac97->bus->card, kctl = snd_ac97_cnew(&snd_ac97_controls_3d[0], ac97))) < 0)
9001da177e4SLinus Torvalds 		return err;
9011da177e4SLinus Torvalds 	strcpy(kctl->id.name, "3D Control Sigmatel - Depth");
9021da177e4SLinus Torvalds 	kctl->private_value = AC97_SINGLE_VALUE(AC97_3D_CONTROL, 0, 3, 0);
9031da177e4SLinus Torvalds 	if ((err = snd_ctl_add(ac97->bus->card, kctl = snd_ac97_cnew(&snd_ac97_controls_3d[0], ac97))) < 0)
9041da177e4SLinus Torvalds 		return err;
9051da177e4SLinus Torvalds 	strcpy(kctl->id.name, "3D Control Sigmatel - Rear Depth");
9061da177e4SLinus Torvalds 	kctl->private_value = AC97_SINGLE_VALUE(AC97_3D_CONTROL, 2, 3, 0);
9071da177e4SLinus Torvalds 	snd_ac97_write_cache(ac97, AC97_3D_CONTROL, 0x0000);
9081da177e4SLinus Torvalds 	return 0;
9091da177e4SLinus Torvalds }
9101da177e4SLinus Torvalds 
911ee42381eSTakashi Iwai static const struct snd_kcontrol_new snd_ac97_sigmatel_4speaker =
912afe6d7e3SAndreas Mohr AC97_SINGLE("Sigmatel 4-Speaker Stereo Playback Switch",
913afe6d7e3SAndreas Mohr 		AC97_SIGMATEL_DAC2INVERT, 2, 1, 0);
9141da177e4SLinus Torvalds 
915afe6d7e3SAndreas Mohr /* "Sigmatel " removed due to excessive name length: */
916ee42381eSTakashi Iwai static const struct snd_kcontrol_new snd_ac97_sigmatel_phaseinvert =
917afe6d7e3SAndreas Mohr AC97_SINGLE("Surround Phase Inversion Playback Switch",
918afe6d7e3SAndreas Mohr 		AC97_SIGMATEL_DAC2INVERT, 3, 1, 0);
9191da177e4SLinus Torvalds 
920ee42381eSTakashi Iwai static const struct snd_kcontrol_new snd_ac97_sigmatel_controls[] = {
9211da177e4SLinus Torvalds AC97_SINGLE("Sigmatel DAC 6dB Attenuate", AC97_SIGMATEL_ANALOG, 1, 1, 0),
9221da177e4SLinus Torvalds AC97_SINGLE("Sigmatel ADC 6dB Attenuate", AC97_SIGMATEL_ANALOG, 0, 1, 0)
9231da177e4SLinus Torvalds };
9241da177e4SLinus Torvalds 
925ee42381eSTakashi Iwai static int patch_sigmatel_stac97xx_specific(struct snd_ac97 * ac97)
9261da177e4SLinus Torvalds {
9271da177e4SLinus Torvalds 	int err;
9281da177e4SLinus Torvalds 
9291da177e4SLinus Torvalds 	snd_ac97_write_cache(ac97, AC97_SIGMATEL_ANALOG, snd_ac97_read(ac97, AC97_SIGMATEL_ANALOG) & ~0x0003);
9301da177e4SLinus Torvalds 	if (snd_ac97_try_bit(ac97, AC97_SIGMATEL_ANALOG, 1))
9311da177e4SLinus Torvalds 		if ((err = patch_build_controls(ac97, &snd_ac97_sigmatel_controls[0], 1)) < 0)
9321da177e4SLinus Torvalds 			return err;
9331da177e4SLinus Torvalds 	if (snd_ac97_try_bit(ac97, AC97_SIGMATEL_ANALOG, 0))
9341da177e4SLinus Torvalds 		if ((err = patch_build_controls(ac97, &snd_ac97_sigmatel_controls[1], 1)) < 0)
9351da177e4SLinus Torvalds 			return err;
9361da177e4SLinus Torvalds 	if (snd_ac97_try_bit(ac97, AC97_SIGMATEL_DAC2INVERT, 2))
9371da177e4SLinus Torvalds 		if ((err = patch_build_controls(ac97, &snd_ac97_sigmatel_4speaker, 1)) < 0)
9381da177e4SLinus Torvalds 			return err;
9391da177e4SLinus Torvalds 	if (snd_ac97_try_bit(ac97, AC97_SIGMATEL_DAC2INVERT, 3))
9401da177e4SLinus Torvalds 		if ((err = patch_build_controls(ac97, &snd_ac97_sigmatel_phaseinvert, 1)) < 0)
9411da177e4SLinus Torvalds 			return err;
9421da177e4SLinus Torvalds 	return 0;
9431da177e4SLinus Torvalds }
9441da177e4SLinus Torvalds 
9453e8b3b90SHanno Boeck static const struct snd_ac97_build_ops patch_sigmatel_stac9700_ops = {
9461da177e4SLinus Torvalds 	.build_3d	= patch_sigmatel_stac9700_3d,
9471da177e4SLinus Torvalds 	.build_specific	= patch_sigmatel_stac97xx_specific
9481da177e4SLinus Torvalds };
9491da177e4SLinus Torvalds 
950ac519028STakashi Iwai static int patch_sigmatel_stac9700(struct snd_ac97 * ac97)
9511da177e4SLinus Torvalds {
9521da177e4SLinus Torvalds 	ac97->build_ops = &patch_sigmatel_stac9700_ops;
9531da177e4SLinus Torvalds 	return 0;
9541da177e4SLinus Torvalds }
9551da177e4SLinus Torvalds 
956ee42381eSTakashi Iwai static int snd_ac97_stac9708_put_bias(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
9571da177e4SLinus Torvalds {
958ee42381eSTakashi Iwai 	struct snd_ac97 *ac97 = snd_kcontrol_chip(kcontrol);
9591da177e4SLinus Torvalds 	int err;
9601da177e4SLinus Torvalds 
96162932df8SIngo Molnar 	mutex_lock(&ac97->page_mutex);
9621da177e4SLinus Torvalds 	snd_ac97_write(ac97, AC97_SIGMATEL_BIAS1, 0xabba);
9631da177e4SLinus Torvalds 	err = snd_ac97_update_bits(ac97, AC97_SIGMATEL_BIAS2, 0x0010,
9641da177e4SLinus Torvalds 				   (ucontrol->value.integer.value[0] & 1) << 4);
9651da177e4SLinus Torvalds 	snd_ac97_write(ac97, AC97_SIGMATEL_BIAS1, 0);
96662932df8SIngo Molnar 	mutex_unlock(&ac97->page_mutex);
9671da177e4SLinus Torvalds 	return err;
9681da177e4SLinus Torvalds }
9691da177e4SLinus Torvalds 
970ee42381eSTakashi Iwai static const struct snd_kcontrol_new snd_ac97_stac9708_bias_control = {
9711da177e4SLinus Torvalds 	.iface = SNDRV_CTL_ELEM_IFACE_MIXER,
9721da177e4SLinus Torvalds 	.name = "Sigmatel Output Bias Switch",
9731da177e4SLinus Torvalds 	.info = snd_ac97_info_volsw,
9741da177e4SLinus Torvalds 	.get = snd_ac97_get_volsw,
9751da177e4SLinus Torvalds 	.put = snd_ac97_stac9708_put_bias,
9761da177e4SLinus Torvalds 	.private_value = AC97_SINGLE_VALUE(AC97_SIGMATEL_BIAS2, 4, 1, 0),
9771da177e4SLinus Torvalds };
9781da177e4SLinus Torvalds 
979ee42381eSTakashi Iwai static int patch_sigmatel_stac9708_specific(struct snd_ac97 *ac97)
9801da177e4SLinus Torvalds {
9811da177e4SLinus Torvalds 	int err;
9821da177e4SLinus Torvalds 
983e4c3bf0fSJames C Georgas 	/* the register bit is writable, but the function is not implemented: */
984e4c3bf0fSJames C Georgas 	snd_ac97_remove_ctl(ac97, "PCM Out Path & Mute", NULL);
985e4c3bf0fSJames C Georgas 
9861da177e4SLinus Torvalds 	snd_ac97_rename_vol_ctl(ac97, "Headphone Playback", "Sigmatel Surround Playback");
9871da177e4SLinus Torvalds 	if ((err = patch_build_controls(ac97, &snd_ac97_stac9708_bias_control, 1)) < 0)
9881da177e4SLinus Torvalds 		return err;
9891da177e4SLinus Torvalds 	return patch_sigmatel_stac97xx_specific(ac97);
9901da177e4SLinus Torvalds }
9911da177e4SLinus Torvalds 
9923e8b3b90SHanno Boeck static const struct snd_ac97_build_ops patch_sigmatel_stac9708_ops = {
9931da177e4SLinus Torvalds 	.build_3d	= patch_sigmatel_stac9708_3d,
9941da177e4SLinus Torvalds 	.build_specific	= patch_sigmatel_stac9708_specific
9951da177e4SLinus Torvalds };
9961da177e4SLinus Torvalds 
997ac519028STakashi Iwai static int patch_sigmatel_stac9708(struct snd_ac97 * ac97)
9981da177e4SLinus Torvalds {
9991da177e4SLinus Torvalds 	unsigned int codec72, codec6c;
10001da177e4SLinus Torvalds 
10011da177e4SLinus Torvalds 	ac97->build_ops = &patch_sigmatel_stac9708_ops;
10021da177e4SLinus Torvalds 	ac97->caps |= 0x10;	/* HP (sigmatel surround) support */
10031da177e4SLinus Torvalds 
10041da177e4SLinus Torvalds 	codec72 = snd_ac97_read(ac97, AC97_SIGMATEL_BIAS2) & 0x8000;
10051da177e4SLinus Torvalds 	codec6c = snd_ac97_read(ac97, AC97_SIGMATEL_ANALOG);
10061da177e4SLinus Torvalds 
10071da177e4SLinus Torvalds 	if ((codec72==0) && (codec6c==0)) {
10081da177e4SLinus Torvalds 		snd_ac97_write_cache(ac97, AC97_SIGMATEL_CIC1, 0xabba);
10091da177e4SLinus Torvalds 		snd_ac97_write_cache(ac97, AC97_SIGMATEL_CIC2, 0x1000);
10101da177e4SLinus Torvalds 		snd_ac97_write_cache(ac97, AC97_SIGMATEL_BIAS1, 0xabba);
10111da177e4SLinus Torvalds 		snd_ac97_write_cache(ac97, AC97_SIGMATEL_BIAS2, 0x0007);
10121da177e4SLinus Torvalds 	} else if ((codec72==0x8000) && (codec6c==0)) {
10131da177e4SLinus Torvalds 		snd_ac97_write_cache(ac97, AC97_SIGMATEL_CIC1, 0xabba);
10141da177e4SLinus Torvalds 		snd_ac97_write_cache(ac97, AC97_SIGMATEL_CIC2, 0x1001);
10151da177e4SLinus Torvalds 		snd_ac97_write_cache(ac97, AC97_SIGMATEL_DAC2INVERT, 0x0008);
10161da177e4SLinus Torvalds 	} else if ((codec72==0x8000) && (codec6c==0x0080)) {
10171da177e4SLinus Torvalds 		/* nothing */
10181da177e4SLinus Torvalds 	}
10191da177e4SLinus Torvalds 	snd_ac97_write_cache(ac97, AC97_SIGMATEL_MULTICHN, 0x0000);
10201da177e4SLinus Torvalds 	return 0;
10211da177e4SLinus Torvalds }
10221da177e4SLinus Torvalds 
1023ac519028STakashi Iwai static int patch_sigmatel_stac9721(struct snd_ac97 * ac97)
10241da177e4SLinus Torvalds {
10251da177e4SLinus Torvalds 	ac97->build_ops = &patch_sigmatel_stac9700_ops;
10261da177e4SLinus Torvalds 	if (snd_ac97_read(ac97, AC97_SIGMATEL_ANALOG) == 0) {
10271da177e4SLinus Torvalds 		// patch for SigmaTel
10281da177e4SLinus Torvalds 		snd_ac97_write_cache(ac97, AC97_SIGMATEL_CIC1, 0xabba);
10291da177e4SLinus Torvalds 		snd_ac97_write_cache(ac97, AC97_SIGMATEL_CIC2, 0x4000);
10301da177e4SLinus Torvalds 		snd_ac97_write_cache(ac97, AC97_SIGMATEL_BIAS1, 0xabba);
10311da177e4SLinus Torvalds 		snd_ac97_write_cache(ac97, AC97_SIGMATEL_BIAS2, 0x0002);
10321da177e4SLinus Torvalds 	}
10331da177e4SLinus Torvalds 	snd_ac97_write_cache(ac97, AC97_SIGMATEL_MULTICHN, 0x0000);
10341da177e4SLinus Torvalds 	return 0;
10351da177e4SLinus Torvalds }
10361da177e4SLinus Torvalds 
1037ac519028STakashi Iwai static int patch_sigmatel_stac9744(struct snd_ac97 * ac97)
10381da177e4SLinus Torvalds {
10391da177e4SLinus Torvalds 	// patch for SigmaTel
10401da177e4SLinus Torvalds 	ac97->build_ops = &patch_sigmatel_stac9700_ops;
10411da177e4SLinus Torvalds 	snd_ac97_write_cache(ac97, AC97_SIGMATEL_CIC1, 0xabba);
10421da177e4SLinus Torvalds 	snd_ac97_write_cache(ac97, AC97_SIGMATEL_CIC2, 0x0000);	/* is this correct? --jk */
10431da177e4SLinus Torvalds 	snd_ac97_write_cache(ac97, AC97_SIGMATEL_BIAS1, 0xabba);
10441da177e4SLinus Torvalds 	snd_ac97_write_cache(ac97, AC97_SIGMATEL_BIAS2, 0x0002);
10451da177e4SLinus Torvalds 	snd_ac97_write_cache(ac97, AC97_SIGMATEL_MULTICHN, 0x0000);
10461da177e4SLinus Torvalds 	return 0;
10471da177e4SLinus Torvalds }
10481da177e4SLinus Torvalds 
1049ac519028STakashi Iwai static int patch_sigmatel_stac9756(struct snd_ac97 * ac97)
10501da177e4SLinus Torvalds {
10511da177e4SLinus Torvalds 	// patch for SigmaTel
10521da177e4SLinus Torvalds 	ac97->build_ops = &patch_sigmatel_stac9700_ops;
10531da177e4SLinus Torvalds 	snd_ac97_write_cache(ac97, AC97_SIGMATEL_CIC1, 0xabba);
10541da177e4SLinus Torvalds 	snd_ac97_write_cache(ac97, AC97_SIGMATEL_CIC2, 0x0000);	/* is this correct? --jk */
10551da177e4SLinus Torvalds 	snd_ac97_write_cache(ac97, AC97_SIGMATEL_BIAS1, 0xabba);
10561da177e4SLinus Torvalds 	snd_ac97_write_cache(ac97, AC97_SIGMATEL_BIAS2, 0x0002);
10571da177e4SLinus Torvalds 	snd_ac97_write_cache(ac97, AC97_SIGMATEL_MULTICHN, 0x0000);
10581da177e4SLinus Torvalds 	return 0;
10591da177e4SLinus Torvalds }
10601da177e4SLinus Torvalds 
1061ee42381eSTakashi Iwai static int snd_ac97_stac9758_output_jack_info(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_info *uinfo)
10621da177e4SLinus Torvalds {
10633b7a00dcSTakashi Iwai 	static const char * const texts[5] = {
10643b7a00dcSTakashi Iwai 		"Input/Disabled", "Front Output",
10651da177e4SLinus Torvalds 		"Rear Output", "Center/LFE Output", "Mixer Output" };
10661da177e4SLinus Torvalds 
10673b7a00dcSTakashi Iwai 	return snd_ctl_enum_info(uinfo, 1, 5, texts);
10681da177e4SLinus Torvalds }
10691da177e4SLinus Torvalds 
1070ee42381eSTakashi Iwai static int snd_ac97_stac9758_output_jack_get(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
10711da177e4SLinus Torvalds {
1072ee42381eSTakashi Iwai 	struct snd_ac97 *ac97 = snd_kcontrol_chip(kcontrol);
10731da177e4SLinus Torvalds 	int shift = kcontrol->private_value;
10741da177e4SLinus Torvalds 	unsigned short val;
10751da177e4SLinus Torvalds 
10761da177e4SLinus Torvalds 	val = ac97->regs[AC97_SIGMATEL_OUTSEL] >> shift;
10771da177e4SLinus Torvalds 	if (!(val & 4))
10781da177e4SLinus Torvalds 		ucontrol->value.enumerated.item[0] = 0;
10791da177e4SLinus Torvalds 	else
10801da177e4SLinus Torvalds 		ucontrol->value.enumerated.item[0] = 1 + (val & 3);
10811da177e4SLinus Torvalds 	return 0;
10821da177e4SLinus Torvalds }
10831da177e4SLinus Torvalds 
1084ee42381eSTakashi Iwai static int snd_ac97_stac9758_output_jack_put(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
10851da177e4SLinus Torvalds {
1086ee42381eSTakashi Iwai 	struct snd_ac97 *ac97 = snd_kcontrol_chip(kcontrol);
10871da177e4SLinus Torvalds 	int shift = kcontrol->private_value;
10881da177e4SLinus Torvalds 	unsigned short val;
10891da177e4SLinus Torvalds 
10901da177e4SLinus Torvalds 	if (ucontrol->value.enumerated.item[0] > 4)
10911da177e4SLinus Torvalds 		return -EINVAL;
10921da177e4SLinus Torvalds 	if (ucontrol->value.enumerated.item[0] == 0)
10931da177e4SLinus Torvalds 		val = 0;
10941da177e4SLinus Torvalds 	else
10951da177e4SLinus Torvalds 		val = 4 | (ucontrol->value.enumerated.item[0] - 1);
10961da177e4SLinus Torvalds 	return ac97_update_bits_page(ac97, AC97_SIGMATEL_OUTSEL,
10971da177e4SLinus Torvalds 				     7 << shift, val << shift, 0);
10981da177e4SLinus Torvalds }
10991da177e4SLinus Torvalds 
1100ee42381eSTakashi Iwai static int snd_ac97_stac9758_input_jack_info(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_info *uinfo)
11011da177e4SLinus Torvalds {
11023b7a00dcSTakashi Iwai 	static const char * const texts[7] = {
11033b7a00dcSTakashi Iwai 		"Mic2 Jack", "Mic1 Jack", "Line In Jack",
11041da177e4SLinus Torvalds 		"Front Jack", "Rear Jack", "Center/LFE Jack", "Mute" };
11051da177e4SLinus Torvalds 
11063b7a00dcSTakashi Iwai 	return snd_ctl_enum_info(uinfo, 1, 7, texts);
11071da177e4SLinus Torvalds }
11081da177e4SLinus Torvalds 
1109ee42381eSTakashi Iwai static int snd_ac97_stac9758_input_jack_get(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
11101da177e4SLinus Torvalds {
1111ee42381eSTakashi Iwai 	struct snd_ac97 *ac97 = snd_kcontrol_chip(kcontrol);
11121da177e4SLinus Torvalds 	int shift = kcontrol->private_value;
11131da177e4SLinus Torvalds 	unsigned short val;
11141da177e4SLinus Torvalds 
11151da177e4SLinus Torvalds 	val = ac97->regs[AC97_SIGMATEL_INSEL];
11161da177e4SLinus Torvalds 	ucontrol->value.enumerated.item[0] = (val >> shift) & 7;
11171da177e4SLinus Torvalds 	return 0;
11181da177e4SLinus Torvalds }
11191da177e4SLinus Torvalds 
1120ee42381eSTakashi Iwai static int snd_ac97_stac9758_input_jack_put(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
11211da177e4SLinus Torvalds {
1122ee42381eSTakashi Iwai 	struct snd_ac97 *ac97 = snd_kcontrol_chip(kcontrol);
11231da177e4SLinus Torvalds 	int shift = kcontrol->private_value;
11241da177e4SLinus Torvalds 
11251da177e4SLinus Torvalds 	return ac97_update_bits_page(ac97, AC97_SIGMATEL_INSEL, 7 << shift,
11261da177e4SLinus Torvalds 				     ucontrol->value.enumerated.item[0] << shift, 0);
11271da177e4SLinus Torvalds }
11281da177e4SLinus Torvalds 
1129ee42381eSTakashi Iwai static int snd_ac97_stac9758_phonesel_info(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_info *uinfo)
11301da177e4SLinus Torvalds {
11313b7a00dcSTakashi Iwai 	static const char * const texts[3] = {
11323b7a00dcSTakashi Iwai 		"None", "Front Jack", "Rear Jack"
11333b7a00dcSTakashi Iwai 	};
11341da177e4SLinus Torvalds 
11353b7a00dcSTakashi Iwai 	return snd_ctl_enum_info(uinfo, 1, 3, texts);
11361da177e4SLinus Torvalds }
11371da177e4SLinus Torvalds 
1138ee42381eSTakashi Iwai static int snd_ac97_stac9758_phonesel_get(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
11391da177e4SLinus Torvalds {
1140ee42381eSTakashi Iwai 	struct snd_ac97 *ac97 = snd_kcontrol_chip(kcontrol);
11411da177e4SLinus Torvalds 
11421da177e4SLinus Torvalds 	ucontrol->value.enumerated.item[0] = ac97->regs[AC97_SIGMATEL_IOMISC] & 3;
11431da177e4SLinus Torvalds 	return 0;
11441da177e4SLinus Torvalds }
11451da177e4SLinus Torvalds 
1146ee42381eSTakashi Iwai static int snd_ac97_stac9758_phonesel_put(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
11471da177e4SLinus Torvalds {
1148ee42381eSTakashi Iwai 	struct snd_ac97 *ac97 = snd_kcontrol_chip(kcontrol);
11491da177e4SLinus Torvalds 
11501da177e4SLinus Torvalds 	return ac97_update_bits_page(ac97, AC97_SIGMATEL_IOMISC, 3,
11511da177e4SLinus Torvalds 				     ucontrol->value.enumerated.item[0], 0);
11521da177e4SLinus Torvalds }
11531da177e4SLinus Torvalds 
11541da177e4SLinus Torvalds #define STAC9758_OUTPUT_JACK(xname, shift) \
11551da177e4SLinus Torvalds {	.iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = xname, \
11561da177e4SLinus Torvalds 	.info = snd_ac97_stac9758_output_jack_info, \
11571da177e4SLinus Torvalds 	.get = snd_ac97_stac9758_output_jack_get, \
11581da177e4SLinus Torvalds 	.put = snd_ac97_stac9758_output_jack_put, \
11591da177e4SLinus Torvalds 	.private_value = shift }
11601da177e4SLinus Torvalds #define STAC9758_INPUT_JACK(xname, shift) \
11611da177e4SLinus Torvalds {	.iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = xname, \
11621da177e4SLinus Torvalds 	.info = snd_ac97_stac9758_input_jack_info, \
11631da177e4SLinus Torvalds 	.get = snd_ac97_stac9758_input_jack_get, \
11641da177e4SLinus Torvalds 	.put = snd_ac97_stac9758_input_jack_put, \
11651da177e4SLinus Torvalds 	.private_value = shift }
1166ee42381eSTakashi Iwai static const struct snd_kcontrol_new snd_ac97_sigmatel_stac9758_controls[] = {
11671da177e4SLinus Torvalds 	STAC9758_OUTPUT_JACK("Mic1 Jack", 1),
11681da177e4SLinus Torvalds 	STAC9758_OUTPUT_JACK("LineIn Jack", 4),
11691da177e4SLinus Torvalds 	STAC9758_OUTPUT_JACK("Front Jack", 7),
11701da177e4SLinus Torvalds 	STAC9758_OUTPUT_JACK("Rear Jack", 10),
11711da177e4SLinus Torvalds 	STAC9758_OUTPUT_JACK("Center/LFE Jack", 13),
11721da177e4SLinus Torvalds 	STAC9758_INPUT_JACK("Mic Input Source", 0),
11731da177e4SLinus Torvalds 	STAC9758_INPUT_JACK("Line Input Source", 8),
11741da177e4SLinus Torvalds 	{
11751da177e4SLinus Torvalds 		.iface = SNDRV_CTL_ELEM_IFACE_MIXER,
11761da177e4SLinus Torvalds 		.name = "Headphone Amp",
11771da177e4SLinus Torvalds 		.info = snd_ac97_stac9758_phonesel_info,
11781da177e4SLinus Torvalds 		.get = snd_ac97_stac9758_phonesel_get,
11791da177e4SLinus Torvalds 		.put = snd_ac97_stac9758_phonesel_put
11801da177e4SLinus Torvalds 	},
11811da177e4SLinus Torvalds 	AC97_SINGLE("Exchange Center/LFE", AC97_SIGMATEL_IOMISC, 4, 1, 0),
11821da177e4SLinus Torvalds 	AC97_SINGLE("Headphone +3dB Boost", AC97_SIGMATEL_IOMISC, 8, 1, 0)
11831da177e4SLinus Torvalds };
11841da177e4SLinus Torvalds 
1185ee42381eSTakashi Iwai static int patch_sigmatel_stac9758_specific(struct snd_ac97 *ac97)
11861da177e4SLinus Torvalds {
11871da177e4SLinus Torvalds 	int err;
11881da177e4SLinus Torvalds 
11891da177e4SLinus Torvalds 	err = patch_sigmatel_stac97xx_specific(ac97);
11901da177e4SLinus Torvalds 	if (err < 0)
11911da177e4SLinus Torvalds 		return err;
11921da177e4SLinus Torvalds 	err = patch_build_controls(ac97, snd_ac97_sigmatel_stac9758_controls,
11931da177e4SLinus Torvalds 				   ARRAY_SIZE(snd_ac97_sigmatel_stac9758_controls));
11941da177e4SLinus Torvalds 	if (err < 0)
11951da177e4SLinus Torvalds 		return err;
11961da177e4SLinus Torvalds 	/* DAC-A direct */
11971da177e4SLinus Torvalds 	snd_ac97_rename_vol_ctl(ac97, "Headphone Playback", "Front Playback");
11981da177e4SLinus Torvalds 	/* DAC-A to Mix = PCM */
11991da177e4SLinus Torvalds 	/* DAC-B direct = Surround */
12001da177e4SLinus Torvalds 	/* DAC-B to Mix */
12011da177e4SLinus Torvalds 	snd_ac97_rename_vol_ctl(ac97, "Video Playback", "Surround Mix Playback");
12021da177e4SLinus Torvalds 	/* DAC-C direct = Center/LFE */
12031da177e4SLinus Torvalds 
12041da177e4SLinus Torvalds 	return 0;
12051da177e4SLinus Torvalds }
12061da177e4SLinus Torvalds 
12073e8b3b90SHanno Boeck static const struct snd_ac97_build_ops patch_sigmatel_stac9758_ops = {
12081da177e4SLinus Torvalds 	.build_3d	= patch_sigmatel_stac9700_3d,
12091da177e4SLinus Torvalds 	.build_specific	= patch_sigmatel_stac9758_specific
12101da177e4SLinus Torvalds };
12111da177e4SLinus Torvalds 
1212ac519028STakashi Iwai static int patch_sigmatel_stac9758(struct snd_ac97 * ac97)
12131da177e4SLinus Torvalds {
12141675bfc0STakashi Iwai 	static const unsigned short regs[4] = {
12151da177e4SLinus Torvalds 		AC97_SIGMATEL_OUTSEL,
12161da177e4SLinus Torvalds 		AC97_SIGMATEL_IOMISC,
12171da177e4SLinus Torvalds 		AC97_SIGMATEL_INSEL,
12181da177e4SLinus Torvalds 		AC97_SIGMATEL_VARIOUS
12191da177e4SLinus Torvalds 	};
12201675bfc0STakashi Iwai 	static const unsigned short def_regs[4] = {
12211da177e4SLinus Torvalds 		/* OUTSEL */ 0xd794, /* CL:CL, SR:SR, LO:MX, LI:DS, MI:DS */
12221da177e4SLinus Torvalds 		/* IOMISC */ 0x2001,
12231da177e4SLinus Torvalds 		/* INSEL */ 0x0201, /* LI:LI, MI:M1 */
12241da177e4SLinus Torvalds 		/* VARIOUS */ 0x0040
12251da177e4SLinus Torvalds 	};
12261675bfc0STakashi Iwai 	static const unsigned short m675_regs[4] = {
12271da177e4SLinus Torvalds 		/* OUTSEL */ 0xfc70, /* CL:MX, SR:MX, LO:DS, LI:MX, MI:DS */
12281da177e4SLinus Torvalds 		/* IOMISC */ 0x2102, /* HP amp on */
12291da177e4SLinus Torvalds 		/* INSEL */ 0x0203, /* LI:LI, MI:FR */
12301da177e4SLinus Torvalds 		/* VARIOUS */ 0x0041 /* stereo mic */
12311da177e4SLinus Torvalds 	};
12321675bfc0STakashi Iwai 	const unsigned short *pregs = def_regs;
12331da177e4SLinus Torvalds 	int i;
12341da177e4SLinus Torvalds 
12351da177e4SLinus Torvalds 	/* Gateway M675 notebook */
12361da177e4SLinus Torvalds 	if (ac97->pci &&
12371da177e4SLinus Torvalds 	    ac97->subsystem_vendor == 0x107b &&
12381da177e4SLinus Torvalds 	    ac97->subsystem_device == 0x0601)
12391da177e4SLinus Torvalds 	    	pregs = m675_regs;
12401da177e4SLinus Torvalds 
12411da177e4SLinus Torvalds 	// patch for SigmaTel
12421da177e4SLinus Torvalds 	ac97->build_ops = &patch_sigmatel_stac9758_ops;
12431da177e4SLinus Torvalds 	/* FIXME: assume only page 0 for writing cache */
12441da177e4SLinus Torvalds 	snd_ac97_update_bits(ac97, AC97_INT_PAGING, AC97_PAGE_MASK, AC97_PAGE_VENDOR);
12451da177e4SLinus Torvalds 	for (i = 0; i < 4; i++)
12461da177e4SLinus Torvalds 		snd_ac97_write_cache(ac97, regs[i], pregs[i]);
12471da177e4SLinus Torvalds 
12481da177e4SLinus Torvalds 	ac97->flags |= AC97_STEREO_MUTES;
12491da177e4SLinus Torvalds 	return 0;
12501da177e4SLinus Torvalds }
12511da177e4SLinus Torvalds 
12521da177e4SLinus Torvalds /*
12531da177e4SLinus Torvalds  * Cirrus Logic CS42xx codecs
12541da177e4SLinus Torvalds  */
1255ee42381eSTakashi Iwai static const struct snd_kcontrol_new snd_ac97_cirrus_controls_spdif[2] = {
12561da177e4SLinus Torvalds 	AC97_SINGLE(SNDRV_CTL_NAME_IEC958("",PLAYBACK,SWITCH), AC97_CSR_SPDIF, 15, 1, 0),
12571da177e4SLinus Torvalds 	AC97_SINGLE(SNDRV_CTL_NAME_IEC958("",PLAYBACK,NONE) "AC97-SPSA", AC97_CSR_ACMODE, 0, 3, 0)
12581da177e4SLinus Torvalds };
12591da177e4SLinus Torvalds 
1260ee42381eSTakashi Iwai static int patch_cirrus_build_spdif(struct snd_ac97 * ac97)
12611da177e4SLinus Torvalds {
12621da177e4SLinus Torvalds 	int err;
12631da177e4SLinus Torvalds 
12641da177e4SLinus Torvalds 	/* con mask, pro mask, default */
12651da177e4SLinus Torvalds 	if ((err = patch_build_controls(ac97, &snd_ac97_controls_spdif[0], 3)) < 0)
12661da177e4SLinus Torvalds 		return err;
12671da177e4SLinus Torvalds 	/* switch, spsa */
12681da177e4SLinus Torvalds 	if ((err = patch_build_controls(ac97, &snd_ac97_cirrus_controls_spdif[0], 1)) < 0)
12691da177e4SLinus Torvalds 		return err;
12701da177e4SLinus Torvalds 	switch (ac97->id & AC97_ID_CS_MASK) {
12711da177e4SLinus Torvalds 	case AC97_ID_CS4205:
12721da177e4SLinus Torvalds 		if ((err = patch_build_controls(ac97, &snd_ac97_cirrus_controls_spdif[1], 1)) < 0)
12731da177e4SLinus Torvalds 			return err;
12741da177e4SLinus Torvalds 		break;
12751da177e4SLinus Torvalds 	}
12761da177e4SLinus Torvalds 	/* set default PCM S/PDIF params */
12771da177e4SLinus Torvalds 	/* consumer,PCM audio,no copyright,no preemphasis,PCM coder,original,48000Hz */
12781da177e4SLinus Torvalds 	snd_ac97_write_cache(ac97, AC97_CSR_SPDIF, 0x0a20);
12791da177e4SLinus Torvalds 	return 0;
12801da177e4SLinus Torvalds }
12811da177e4SLinus Torvalds 
12823e8b3b90SHanno Boeck static const struct snd_ac97_build_ops patch_cirrus_ops = {
12831da177e4SLinus Torvalds 	.build_spdif = patch_cirrus_build_spdif
12841da177e4SLinus Torvalds };
12851da177e4SLinus Torvalds 
1286ac519028STakashi Iwai static int patch_cirrus_spdif(struct snd_ac97 * ac97)
12871da177e4SLinus Torvalds {
12881da177e4SLinus Torvalds 	/* Basically, the cs4201/cs4205/cs4297a has non-standard sp/dif registers.
12891da177e4SLinus Torvalds 	   WHY CAN'T ANYONE FOLLOW THE BLOODY SPEC?  *sigh*
12901da177e4SLinus Torvalds 	   - sp/dif EA ID is not set, but sp/dif is always present.
12911da177e4SLinus Torvalds 	   - enable/disable is spdif register bit 15.
12921da177e4SLinus Torvalds 	   - sp/dif control register is 0x68.  differs from AC97:
12931da177e4SLinus Torvalds 	   - valid is bit 14 (vs 15)
12941da177e4SLinus Torvalds 	   - no DRS
12951da177e4SLinus Torvalds 	   - only 44.1/48k [00 = 48, 01=44,1] (AC97 is 00=44.1, 10=48)
12961da177e4SLinus Torvalds 	   - sp/dif ssource select is in 0x5e bits 0,1.
12971da177e4SLinus Torvalds 	*/
12981da177e4SLinus Torvalds 
12991da177e4SLinus Torvalds 	ac97->build_ops = &patch_cirrus_ops;
13001da177e4SLinus Torvalds 	ac97->flags |= AC97_CS_SPDIF;
13011da177e4SLinus Torvalds 	ac97->rates[AC97_RATES_SPDIF] &= ~SNDRV_PCM_RATE_32000;
13021da177e4SLinus Torvalds         ac97->ext_id |= AC97_EI_SPDIF;	/* force the detection of spdif */
13031da177e4SLinus Torvalds 	snd_ac97_write_cache(ac97, AC97_CSR_ACMODE, 0x0080);
13041da177e4SLinus Torvalds 	return 0;
13051da177e4SLinus Torvalds }
13061da177e4SLinus Torvalds 
1307ac519028STakashi Iwai static int patch_cirrus_cs4299(struct snd_ac97 * ac97)
13081da177e4SLinus Torvalds {
13091da177e4SLinus Torvalds 	/* force the detection of PC Beep */
13101da177e4SLinus Torvalds 	ac97->flags |= AC97_HAS_PC_BEEP;
13111da177e4SLinus Torvalds 
13121da177e4SLinus Torvalds 	return patch_cirrus_spdif(ac97);
13131da177e4SLinus Torvalds }
13141da177e4SLinus Torvalds 
13151da177e4SLinus Torvalds /*
13161da177e4SLinus Torvalds  * Conexant codecs
13171da177e4SLinus Torvalds  */
1318ee42381eSTakashi Iwai static const struct snd_kcontrol_new snd_ac97_conexant_controls_spdif[1] = {
13191da177e4SLinus Torvalds 	AC97_SINGLE(SNDRV_CTL_NAME_IEC958("",PLAYBACK,SWITCH), AC97_CXR_AUDIO_MISC, 3, 1, 0),
13201da177e4SLinus Torvalds };
13211da177e4SLinus Torvalds 
1322ee42381eSTakashi Iwai static int patch_conexant_build_spdif(struct snd_ac97 * ac97)
13231da177e4SLinus Torvalds {
13241da177e4SLinus Torvalds 	int err;
13251da177e4SLinus Torvalds 
13261da177e4SLinus Torvalds 	/* con mask, pro mask, default */
13271da177e4SLinus Torvalds 	if ((err = patch_build_controls(ac97, &snd_ac97_controls_spdif[0], 3)) < 0)
13281da177e4SLinus Torvalds 		return err;
13291da177e4SLinus Torvalds 	/* switch */
13301da177e4SLinus Torvalds 	if ((err = patch_build_controls(ac97, &snd_ac97_conexant_controls_spdif[0], 1)) < 0)
13311da177e4SLinus Torvalds 		return err;
13321da177e4SLinus Torvalds 	/* set default PCM S/PDIF params */
13331da177e4SLinus Torvalds 	/* consumer,PCM audio,no copyright,no preemphasis,PCM coder,original,48000Hz */
13341da177e4SLinus Torvalds 	snd_ac97_write_cache(ac97, AC97_CXR_AUDIO_MISC,
13351da177e4SLinus Torvalds 			     snd_ac97_read(ac97, AC97_CXR_AUDIO_MISC) & ~(AC97_CXR_SPDIFEN|AC97_CXR_COPYRGT|AC97_CXR_SPDIF_MASK));
13361da177e4SLinus Torvalds 	return 0;
13371da177e4SLinus Torvalds }
13381da177e4SLinus Torvalds 
13393e8b3b90SHanno Boeck static const struct snd_ac97_build_ops patch_conexant_ops = {
13401da177e4SLinus Torvalds 	.build_spdif = patch_conexant_build_spdif
13411da177e4SLinus Torvalds };
13421da177e4SLinus Torvalds 
1343ac519028STakashi Iwai static int patch_conexant(struct snd_ac97 * ac97)
13441da177e4SLinus Torvalds {
13451da177e4SLinus Torvalds 	ac97->build_ops = &patch_conexant_ops;
13461da177e4SLinus Torvalds 	ac97->flags |= AC97_CX_SPDIF;
13471da177e4SLinus Torvalds         ac97->ext_id |= AC97_EI_SPDIF;	/* force the detection of spdif */
13481da177e4SLinus Torvalds 	ac97->rates[AC97_RATES_SPDIF] = SNDRV_PCM_RATE_48000; /* 48k only */
13491da177e4SLinus Torvalds 	return 0;
13501da177e4SLinus Torvalds }
13511da177e4SLinus Torvalds 
1352ac519028STakashi Iwai static int patch_cx20551(struct snd_ac97 *ac97)
13539e292c00STakashi Iwai {
13549e292c00STakashi Iwai 	snd_ac97_update_bits(ac97, 0x5c, 0x01, 0x01);
13559e292c00STakashi Iwai 	return 0;
13569e292c00STakashi Iwai }
13579e292c00STakashi Iwai 
13581da177e4SLinus Torvalds /*
1359*aa08ff0fSGeert Uytterhoeven  * Analog Devices AD18xx, AD19xx codecs
13601da177e4SLinus Torvalds  */
13611da177e4SLinus Torvalds #ifdef CONFIG_PM
1362ee42381eSTakashi Iwai static void ad18xx_resume(struct snd_ac97 *ac97)
13631da177e4SLinus Torvalds {
13641675bfc0STakashi Iwai 	static const unsigned short setup_regs[] = {
13651da177e4SLinus Torvalds 		AC97_AD_MISC, AC97_AD_SERIAL_CFG, AC97_AD_JACK_SPDIF,
13661da177e4SLinus Torvalds 	};
13671da177e4SLinus Torvalds 	int i, codec;
13681da177e4SLinus Torvalds 
13691da177e4SLinus Torvalds 	for (i = 0; i < (int)ARRAY_SIZE(setup_regs); i++) {
13701da177e4SLinus Torvalds 		unsigned short reg = setup_regs[i];
13711da177e4SLinus Torvalds 		if (test_bit(reg, ac97->reg_accessed)) {
13721da177e4SLinus Torvalds 			snd_ac97_write(ac97, reg, ac97->regs[reg]);
13731da177e4SLinus Torvalds 			snd_ac97_read(ac97, reg);
13741da177e4SLinus Torvalds 		}
13751da177e4SLinus Torvalds 	}
13761da177e4SLinus Torvalds 
13771da177e4SLinus Torvalds 	if (! (ac97->flags & AC97_AD_MULTI))
13781da177e4SLinus Torvalds 		/* normal restore */
13791da177e4SLinus Torvalds 		snd_ac97_restore_status(ac97);
13801da177e4SLinus Torvalds 	else {
13811da177e4SLinus Torvalds 		/* restore the AD18xx codec configurations */
13821da177e4SLinus Torvalds 		for (codec = 0; codec < 3; codec++) {
13831da177e4SLinus Torvalds 			if (! ac97->spec.ad18xx.id[codec])
13841da177e4SLinus Torvalds 				continue;
13851da177e4SLinus Torvalds 			/* select single codec */
13861da177e4SLinus Torvalds 			snd_ac97_update_bits(ac97, AC97_AD_SERIAL_CFG, 0x7000,
13871da177e4SLinus Torvalds 					     ac97->spec.ad18xx.unchained[codec] | ac97->spec.ad18xx.chained[codec]);
13881da177e4SLinus Torvalds 			ac97->bus->ops->write(ac97, AC97_AD_CODEC_CFG, ac97->spec.ad18xx.codec_cfg[codec]);
13891da177e4SLinus Torvalds 		}
13901da177e4SLinus Torvalds 		/* select all codecs */
13911da177e4SLinus Torvalds 		snd_ac97_update_bits(ac97, AC97_AD_SERIAL_CFG, 0x7000, 0x7000);
13921da177e4SLinus Torvalds 
13931da177e4SLinus Torvalds 		/* restore status */
13941da177e4SLinus Torvalds 		for (i = 2; i < 0x7c ; i += 2) {
13951da177e4SLinus Torvalds 			if (i == AC97_POWERDOWN || i == AC97_EXTENDED_ID)
13961da177e4SLinus Torvalds 				continue;
13971da177e4SLinus Torvalds 			if (test_bit(i, ac97->reg_accessed)) {
13981da177e4SLinus Torvalds 				/* handle multi codecs for AD18xx */
13991da177e4SLinus Torvalds 				if (i == AC97_PCM) {
14001da177e4SLinus Torvalds 					for (codec = 0; codec < 3; codec++) {
14011da177e4SLinus Torvalds 						if (! ac97->spec.ad18xx.id[codec])
14021da177e4SLinus Torvalds 							continue;
14031da177e4SLinus Torvalds 						/* select single codec */
14041da177e4SLinus Torvalds 						snd_ac97_update_bits(ac97, AC97_AD_SERIAL_CFG, 0x7000,
14051da177e4SLinus Torvalds 								     ac97->spec.ad18xx.unchained[codec] | ac97->spec.ad18xx.chained[codec]);
14061da177e4SLinus Torvalds 						/* update PCM bits */
14071da177e4SLinus Torvalds 						ac97->bus->ops->write(ac97, AC97_PCM, ac97->spec.ad18xx.pcmreg[codec]);
14081da177e4SLinus Torvalds 					}
14091da177e4SLinus Torvalds 					/* select all codecs */
14101da177e4SLinus Torvalds 					snd_ac97_update_bits(ac97, AC97_AD_SERIAL_CFG, 0x7000, 0x7000);
14111da177e4SLinus Torvalds 					continue;
14121da177e4SLinus Torvalds 				} else if (i == AC97_AD_TEST ||
14131da177e4SLinus Torvalds 					   i == AC97_AD_CODEC_CFG ||
14141da177e4SLinus Torvalds 					   i == AC97_AD_SERIAL_CFG)
14151da177e4SLinus Torvalds 					continue; /* ignore */
14161da177e4SLinus Torvalds 			}
14171da177e4SLinus Torvalds 			snd_ac97_write(ac97, i, ac97->regs[i]);
14181da177e4SLinus Torvalds 			snd_ac97_read(ac97, i);
14191da177e4SLinus Torvalds 		}
14201da177e4SLinus Torvalds 	}
14211da177e4SLinus Torvalds 
14221da177e4SLinus Torvalds 	snd_ac97_restore_iec958(ac97);
14231da177e4SLinus Torvalds }
14241561f09aSJaya Kumar 
14251561f09aSJaya Kumar static void ad1888_resume(struct snd_ac97 *ac97)
14261561f09aSJaya Kumar {
14271561f09aSJaya Kumar 	ad18xx_resume(ac97);
14281561f09aSJaya Kumar 	snd_ac97_write_cache(ac97, AC97_CODEC_CLASS_REV, 0x8080);
14291561f09aSJaya Kumar }
14301561f09aSJaya Kumar 
14311da177e4SLinus Torvalds #endif
14321da177e4SLinus Torvalds 
1433bd25b7caSVille Syrjala static const struct snd_ac97_res_table ad1819_restbl[] = {
1434bd25b7caSVille Syrjala 	{ AC97_PHONE, 0x9f1f },
1435bd25b7caSVille Syrjala 	{ AC97_MIC, 0x9f1f },
1436bd25b7caSVille Syrjala 	{ AC97_LINE, 0x9f1f },
1437bd25b7caSVille Syrjala 	{ AC97_CD, 0x9f1f },
1438bd25b7caSVille Syrjala 	{ AC97_VIDEO, 0x9f1f },
1439bd25b7caSVille Syrjala 	{ AC97_AUX, 0x9f1f },
1440bd25b7caSVille Syrjala 	{ AC97_PCM, 0x9f1f },
1441bd25b7caSVille Syrjala 	{ } /* terminator */
1442bd25b7caSVille Syrjala };
1443bd25b7caSVille Syrjala 
1444ac519028STakashi Iwai static int patch_ad1819(struct snd_ac97 * ac97)
14451da177e4SLinus Torvalds {
14461da177e4SLinus Torvalds 	unsigned short scfg;
14471da177e4SLinus Torvalds 
14481da177e4SLinus Torvalds 	// patch for Analog Devices
14491da177e4SLinus Torvalds 	scfg = snd_ac97_read(ac97, AC97_AD_SERIAL_CFG);
14501da177e4SLinus Torvalds 	snd_ac97_write_cache(ac97, AC97_AD_SERIAL_CFG, scfg | 0x7000); /* select all codecs */
1451bd25b7caSVille Syrjala 	ac97->res_table = ad1819_restbl;
14521da177e4SLinus Torvalds 	return 0;
14531da177e4SLinus Torvalds }
14541da177e4SLinus Torvalds 
1455ee42381eSTakashi Iwai static unsigned short patch_ad1881_unchained(struct snd_ac97 * ac97, int idx, unsigned short mask)
14561da177e4SLinus Torvalds {
14571da177e4SLinus Torvalds 	unsigned short val;
14581da177e4SLinus Torvalds 
14591da177e4SLinus Torvalds 	// test for unchained codec
14601da177e4SLinus Torvalds 	snd_ac97_update_bits(ac97, AC97_AD_SERIAL_CFG, 0x7000, mask);
14611da177e4SLinus Torvalds 	snd_ac97_write_cache(ac97, AC97_AD_CODEC_CFG, 0x0000);	/* ID0C, ID1C, SDIE = off */
14621da177e4SLinus Torvalds 	val = snd_ac97_read(ac97, AC97_VENDOR_ID2);
14631da177e4SLinus Torvalds 	if ((val & 0xff40) != 0x5340)
14641da177e4SLinus Torvalds 		return 0;
14651da177e4SLinus Torvalds 	ac97->spec.ad18xx.unchained[idx] = mask;
14661da177e4SLinus Torvalds 	ac97->spec.ad18xx.id[idx] = val;
14671da177e4SLinus Torvalds 	ac97->spec.ad18xx.codec_cfg[idx] = 0x0000;
14681da177e4SLinus Torvalds 	return mask;
14691da177e4SLinus Torvalds }
14701da177e4SLinus Torvalds 
1471ee42381eSTakashi Iwai static int patch_ad1881_chained1(struct snd_ac97 * ac97, int idx, unsigned short codec_bits)
14721da177e4SLinus Torvalds {
14731675bfc0STakashi Iwai 	static const int cfg_bits[3] = { 1<<12, 1<<14, 1<<13 };
14741da177e4SLinus Torvalds 	unsigned short val;
14751da177e4SLinus Torvalds 
14761da177e4SLinus Torvalds 	snd_ac97_update_bits(ac97, AC97_AD_SERIAL_CFG, 0x7000, cfg_bits[idx]);
14771da177e4SLinus Torvalds 	snd_ac97_write_cache(ac97, AC97_AD_CODEC_CFG, 0x0004);	// SDIE
14781da177e4SLinus Torvalds 	val = snd_ac97_read(ac97, AC97_VENDOR_ID2);
14791da177e4SLinus Torvalds 	if ((val & 0xff40) != 0x5340)
14801da177e4SLinus Torvalds 		return 0;
14811da177e4SLinus Torvalds 	if (codec_bits)
14821da177e4SLinus Torvalds 		snd_ac97_write_cache(ac97, AC97_AD_CODEC_CFG, codec_bits);
14831da177e4SLinus Torvalds 	ac97->spec.ad18xx.chained[idx] = cfg_bits[idx];
14841da177e4SLinus Torvalds 	ac97->spec.ad18xx.id[idx] = val;
14851da177e4SLinus Torvalds 	ac97->spec.ad18xx.codec_cfg[idx] = codec_bits ? codec_bits : 0x0004;
14861da177e4SLinus Torvalds 	return 1;
14871da177e4SLinus Torvalds }
14881da177e4SLinus Torvalds 
1489ee42381eSTakashi Iwai static void patch_ad1881_chained(struct snd_ac97 * ac97, int unchained_idx, int cidx1, int cidx2)
14901da177e4SLinus Torvalds {
14911da177e4SLinus Torvalds 	// already detected?
14921da177e4SLinus Torvalds 	if (ac97->spec.ad18xx.unchained[cidx1] || ac97->spec.ad18xx.chained[cidx1])
14931da177e4SLinus Torvalds 		cidx1 = -1;
14941da177e4SLinus Torvalds 	if (ac97->spec.ad18xx.unchained[cidx2] || ac97->spec.ad18xx.chained[cidx2])
14951da177e4SLinus Torvalds 		cidx2 = -1;
14961da177e4SLinus Torvalds 	if (cidx1 < 0 && cidx2 < 0)
14971da177e4SLinus Torvalds 		return;
14981da177e4SLinus Torvalds 	// test for chained codecs
14991da177e4SLinus Torvalds 	snd_ac97_update_bits(ac97, AC97_AD_SERIAL_CFG, 0x7000,
15001da177e4SLinus Torvalds 			     ac97->spec.ad18xx.unchained[unchained_idx]);
15011da177e4SLinus Torvalds 	snd_ac97_write_cache(ac97, AC97_AD_CODEC_CFG, 0x0002);		// ID1C
15021da177e4SLinus Torvalds 	ac97->spec.ad18xx.codec_cfg[unchained_idx] = 0x0002;
15031da177e4SLinus Torvalds 	if (cidx1 >= 0) {
1504c19bcdc6STakashi Iwai 		if (cidx2 < 0)
1505c19bcdc6STakashi Iwai 			patch_ad1881_chained1(ac97, cidx1, 0);
1506c19bcdc6STakashi Iwai 		else if (patch_ad1881_chained1(ac97, cidx1, 0x0006))	// SDIE | ID1C
15071da177e4SLinus Torvalds 			patch_ad1881_chained1(ac97, cidx2, 0);
15081da177e4SLinus Torvalds 		else if (patch_ad1881_chained1(ac97, cidx2, 0x0006))	// SDIE | ID1C
15091da177e4SLinus Torvalds 			patch_ad1881_chained1(ac97, cidx1, 0);
15101da177e4SLinus Torvalds 	} else if (cidx2 >= 0) {
15111da177e4SLinus Torvalds 		patch_ad1881_chained1(ac97, cidx2, 0);
15121da177e4SLinus Torvalds 	}
15131da177e4SLinus Torvalds }
15141da177e4SLinus Torvalds 
15153e8b3b90SHanno Boeck static const struct snd_ac97_build_ops patch_ad1881_build_ops = {
15161da177e4SLinus Torvalds #ifdef CONFIG_PM
15171da177e4SLinus Torvalds 	.resume = ad18xx_resume
15181da177e4SLinus Torvalds #endif
15191da177e4SLinus Torvalds };
15201da177e4SLinus Torvalds 
1521ac519028STakashi Iwai static int patch_ad1881(struct snd_ac97 * ac97)
15221da177e4SLinus Torvalds {
15231da177e4SLinus Torvalds 	static const char cfg_idxs[3][2] = {
15241da177e4SLinus Torvalds 		{2, 1},
15251da177e4SLinus Torvalds 		{0, 2},
15261da177e4SLinus Torvalds 		{0, 1}
15271da177e4SLinus Torvalds 	};
15281da177e4SLinus Torvalds 
15291da177e4SLinus Torvalds 	// patch for Analog Devices
15301da177e4SLinus Torvalds 	unsigned short codecs[3];
15311da177e4SLinus Torvalds 	unsigned short val;
15321da177e4SLinus Torvalds 	int idx, num;
15331da177e4SLinus Torvalds 
15341da177e4SLinus Torvalds 	val = snd_ac97_read(ac97, AC97_AD_SERIAL_CFG);
15351da177e4SLinus Torvalds 	snd_ac97_write_cache(ac97, AC97_AD_SERIAL_CFG, val);
15361da177e4SLinus Torvalds 	codecs[0] = patch_ad1881_unchained(ac97, 0, (1<<12));
15371da177e4SLinus Torvalds 	codecs[1] = patch_ad1881_unchained(ac97, 1, (1<<14));
15381da177e4SLinus Torvalds 	codecs[2] = patch_ad1881_unchained(ac97, 2, (1<<13));
15391da177e4SLinus Torvalds 
15407c22f1aaSTakashi Iwai 	if (! (codecs[0] || codecs[1] || codecs[2]))
15417c22f1aaSTakashi Iwai 		goto __end;
15421da177e4SLinus Torvalds 
15431da177e4SLinus Torvalds 	for (idx = 0; idx < 3; idx++)
15441da177e4SLinus Torvalds 		if (ac97->spec.ad18xx.unchained[idx])
15451da177e4SLinus Torvalds 			patch_ad1881_chained(ac97, idx, cfg_idxs[idx][0], cfg_idxs[idx][1]);
15461da177e4SLinus Torvalds 
15471da177e4SLinus Torvalds 	if (ac97->spec.ad18xx.id[1]) {
15481da177e4SLinus Torvalds 		ac97->flags |= AC97_AD_MULTI;
15491da177e4SLinus Torvalds 		ac97->scaps |= AC97_SCAP_SURROUND_DAC;
15501da177e4SLinus Torvalds 	}
15511da177e4SLinus Torvalds 	if (ac97->spec.ad18xx.id[2]) {
15521da177e4SLinus Torvalds 		ac97->flags |= AC97_AD_MULTI;
15531da177e4SLinus Torvalds 		ac97->scaps |= AC97_SCAP_CENTER_LFE_DAC;
15541da177e4SLinus Torvalds 	}
15551da177e4SLinus Torvalds 
15561da177e4SLinus Torvalds       __end:
15571da177e4SLinus Torvalds 	/* select all codecs */
15581da177e4SLinus Torvalds 	snd_ac97_update_bits(ac97, AC97_AD_SERIAL_CFG, 0x7000, 0x7000);
15591da177e4SLinus Torvalds 	/* check if only one codec is present */
15601da177e4SLinus Torvalds 	for (idx = num = 0; idx < 3; idx++)
15611da177e4SLinus Torvalds 		if (ac97->spec.ad18xx.id[idx])
15621da177e4SLinus Torvalds 			num++;
15631da177e4SLinus Torvalds 	if (num == 1) {
15641da177e4SLinus Torvalds 		/* ok, deselect all ID bits */
15651da177e4SLinus Torvalds 		snd_ac97_write_cache(ac97, AC97_AD_CODEC_CFG, 0x0000);
15661da177e4SLinus Torvalds 		ac97->spec.ad18xx.codec_cfg[0] =
15671da177e4SLinus Torvalds 			ac97->spec.ad18xx.codec_cfg[1] =
15681da177e4SLinus Torvalds 			ac97->spec.ad18xx.codec_cfg[2] = 0x0000;
15691da177e4SLinus Torvalds 	}
15701da177e4SLinus Torvalds 	/* required for AD1886/AD1885 combination */
15711da177e4SLinus Torvalds 	ac97->ext_id = snd_ac97_read(ac97, AC97_EXTENDED_ID);
15721da177e4SLinus Torvalds 	if (ac97->spec.ad18xx.id[0]) {
15731da177e4SLinus Torvalds 		ac97->id &= 0xffff0000;
15741da177e4SLinus Torvalds 		ac97->id |= ac97->spec.ad18xx.id[0];
15751da177e4SLinus Torvalds 	}
15761da177e4SLinus Torvalds 	ac97->build_ops = &patch_ad1881_build_ops;
15771da177e4SLinus Torvalds 	return 0;
15781da177e4SLinus Torvalds }
15791da177e4SLinus Torvalds 
1580ee42381eSTakashi Iwai static const struct snd_kcontrol_new snd_ac97_controls_ad1885[] = {
15811da177e4SLinus Torvalds 	AC97_SINGLE("Digital Mono Direct", AC97_AD_MISC, 11, 1, 0),
15821da177e4SLinus Torvalds 	/* AC97_SINGLE("Digital Audio Mode", AC97_AD_MISC, 12, 1, 0), */ /* seems problematic */
15831da177e4SLinus Torvalds 	AC97_SINGLE("Low Power Mixer", AC97_AD_MISC, 14, 1, 0),
15841da177e4SLinus Torvalds 	AC97_SINGLE("Zero Fill DAC", AC97_AD_MISC, 15, 1, 0),
15851da177e4SLinus Torvalds 	AC97_SINGLE("Headphone Jack Sense", AC97_AD_JACK_SPDIF, 9, 1, 1), /* inverted */
15861da177e4SLinus Torvalds 	AC97_SINGLE("Line Jack Sense", AC97_AD_JACK_SPDIF, 8, 1, 1), /* inverted */
15871da177e4SLinus Torvalds };
15881da177e4SLinus Torvalds 
15890cb29ea0STakashi Iwai static const DECLARE_TLV_DB_SCALE(db_scale_6bit_6db_max, -8850, 150, 0);
15902f3482fbSTakashi Iwai 
1591ee42381eSTakashi Iwai static int patch_ad1885_specific(struct snd_ac97 * ac97)
15921da177e4SLinus Torvalds {
15931da177e4SLinus Torvalds 	int err;
15941da177e4SLinus Torvalds 
15951da177e4SLinus Torvalds 	if ((err = patch_build_controls(ac97, snd_ac97_controls_ad1885, ARRAY_SIZE(snd_ac97_controls_ad1885))) < 0)
15961da177e4SLinus Torvalds 		return err;
15972f3482fbSTakashi Iwai 	reset_tlv(ac97, "Headphone Playback Volume",
15982f3482fbSTakashi Iwai 		  db_scale_6bit_6db_max);
15991da177e4SLinus Torvalds 	return 0;
16001da177e4SLinus Torvalds }
16011da177e4SLinus Torvalds 
16023e8b3b90SHanno Boeck static const struct snd_ac97_build_ops patch_ad1885_build_ops = {
16031da177e4SLinus Torvalds 	.build_specific = &patch_ad1885_specific,
16041da177e4SLinus Torvalds #ifdef CONFIG_PM
16051da177e4SLinus Torvalds 	.resume = ad18xx_resume
16061da177e4SLinus Torvalds #endif
16071da177e4SLinus Torvalds };
16081da177e4SLinus Torvalds 
1609ac519028STakashi Iwai static int patch_ad1885(struct snd_ac97 * ac97)
16101da177e4SLinus Torvalds {
16111da177e4SLinus Torvalds 	patch_ad1881(ac97);
16121da177e4SLinus Torvalds 	/* This is required to deal with the Intel D815EEAL2 */
16131da177e4SLinus Torvalds 	/* i.e. Line out is actually headphone out from codec */
16141da177e4SLinus Torvalds 
16151da177e4SLinus Torvalds 	/* set default */
16161da177e4SLinus Torvalds 	snd_ac97_write_cache(ac97, AC97_AD_MISC, 0x0404);
16171da177e4SLinus Torvalds 
16181da177e4SLinus Torvalds 	ac97->build_ops = &patch_ad1885_build_ops;
16191da177e4SLinus Torvalds 	return 0;
16201da177e4SLinus Torvalds }
16211da177e4SLinus Torvalds 
16222f3482fbSTakashi Iwai static int patch_ad1886_specific(struct snd_ac97 * ac97)
16232f3482fbSTakashi Iwai {
16242f3482fbSTakashi Iwai 	reset_tlv(ac97, "Headphone Playback Volume",
16252f3482fbSTakashi Iwai 		  db_scale_6bit_6db_max);
16262f3482fbSTakashi Iwai 	return 0;
16272f3482fbSTakashi Iwai }
16282f3482fbSTakashi Iwai 
16293e8b3b90SHanno Boeck static const struct snd_ac97_build_ops patch_ad1886_build_ops = {
16302f3482fbSTakashi Iwai 	.build_specific = &patch_ad1886_specific,
16312f3482fbSTakashi Iwai #ifdef CONFIG_PM
16322f3482fbSTakashi Iwai 	.resume = ad18xx_resume
16332f3482fbSTakashi Iwai #endif
16342f3482fbSTakashi Iwai };
16352f3482fbSTakashi Iwai 
1636ac519028STakashi Iwai static int patch_ad1886(struct snd_ac97 * ac97)
16371da177e4SLinus Torvalds {
16381da177e4SLinus Torvalds 	patch_ad1881(ac97);
16391da177e4SLinus Torvalds 	/* Presario700 workaround */
16401da177e4SLinus Torvalds 	/* for Jack Sense/SPDIF Register misetting causing */
16411da177e4SLinus Torvalds 	snd_ac97_write_cache(ac97, AC97_AD_JACK_SPDIF, 0x0010);
16422f3482fbSTakashi Iwai 	ac97->build_ops = &patch_ad1886_build_ops;
16431da177e4SLinus Torvalds 	return 0;
16441da177e4SLinus Torvalds }
16451da177e4SLinus Torvalds 
164667e9f4b6SRandy Cushman /* MISC bits (AD1888/AD1980/AD1985 register 0x76) */
16471da177e4SLinus Torvalds #define AC97_AD198X_MBC		0x0003	/* mic boost */
16481da177e4SLinus Torvalds #define AC97_AD198X_MBC_20	0x0000	/* +20dB */
16491da177e4SLinus Torvalds #define AC97_AD198X_MBC_10	0x0001	/* +10dB */
16501da177e4SLinus Torvalds #define AC97_AD198X_MBC_30	0x0002	/* +30dB */
16511da177e4SLinus Torvalds #define AC97_AD198X_VREFD	0x0004	/* VREF high-Z */
16526428ea1bSRandy Cushman #define AC97_AD198X_VREFH	0x0008	/* 0=2.25V, 1=3.7V */
16536428ea1bSRandy Cushman #define AC97_AD198X_VREF_0	0x000c	/* 0V (AD1985 only) */
16546428ea1bSRandy Cushman #define AC97_AD198X_VREF_MASK	(AC97_AD198X_VREFH | AC97_AD198X_VREFD)
16556428ea1bSRandy Cushman #define AC97_AD198X_VREF_SHIFT	2
16561da177e4SLinus Torvalds #define AC97_AD198X_SRU		0x0010	/* sample rate unlock */
16571da177e4SLinus Torvalds #define AC97_AD198X_LOSEL	0x0020	/* LINE_OUT amplifiers input select */
16581da177e4SLinus Torvalds #define AC97_AD198X_2MIC	0x0040	/* 2-channel mic select */
16591da177e4SLinus Torvalds #define AC97_AD198X_SPRD	0x0080	/* SPREAD enable */
16606428ea1bSRandy Cushman #define AC97_AD198X_DMIX0	0x0100	/* downmix mode: */
16616428ea1bSRandy Cushman 					/*  0 = 6-to-4, 1 = 6-to-2 downmix */
16621da177e4SLinus Torvalds #define AC97_AD198X_DMIX1	0x0200	/* downmix mode: 1 = enabled */
16631da177e4SLinus Torvalds #define AC97_AD198X_HPSEL	0x0400	/* headphone amplifier input select */
16641da177e4SLinus Torvalds #define AC97_AD198X_CLDIS	0x0800	/* center/lfe disable */
16651da177e4SLinus Torvalds #define AC97_AD198X_LODIS	0x1000	/* LINE_OUT disable */
16661da177e4SLinus Torvalds #define AC97_AD198X_MSPLT	0x2000	/* mute split */
16671da177e4SLinus Torvalds #define AC97_AD198X_AC97NC	0x4000	/* AC97 no compatible mode */
16681da177e4SLinus Torvalds #define AC97_AD198X_DACZ	0x8000	/* DAC zero-fill mode */
16691da177e4SLinus Torvalds 
167067e9f4b6SRandy Cushman /* MISC 1 bits (AD1986 register 0x76) */
167167e9f4b6SRandy Cushman #define AC97_AD1986_MBC		0x0003	/* mic boost */
167267e9f4b6SRandy Cushman #define AC97_AD1986_MBC_20	0x0000	/* +20dB */
167367e9f4b6SRandy Cushman #define AC97_AD1986_MBC_10	0x0001	/* +10dB */
167467e9f4b6SRandy Cushman #define AC97_AD1986_MBC_30	0x0002	/* +30dB */
167567e9f4b6SRandy Cushman #define AC97_AD1986_LISEL0	0x0004	/* LINE_IN select bit 0 */
167667e9f4b6SRandy Cushman #define AC97_AD1986_LISEL1	0x0008	/* LINE_IN select bit 1 */
167767e9f4b6SRandy Cushman #define AC97_AD1986_LISEL_MASK	(AC97_AD1986_LISEL1 | AC97_AD1986_LISEL0)
167867e9f4b6SRandy Cushman #define AC97_AD1986_LISEL_LI	0x0000  /* LINE_IN pins as LINE_IN source */
167967e9f4b6SRandy Cushman #define AC97_AD1986_LISEL_SURR	0x0004  /* SURROUND pins as LINE_IN source */
168067e9f4b6SRandy Cushman #define AC97_AD1986_LISEL_MIC	0x0008  /* MIC_1/2 pins as LINE_IN source */
168167e9f4b6SRandy Cushman #define AC97_AD1986_SRU		0x0010	/* sample rate unlock */
168267e9f4b6SRandy Cushman #define AC97_AD1986_SOSEL	0x0020	/* SURROUND_OUT amplifiers input sel */
168367e9f4b6SRandy Cushman #define AC97_AD1986_2MIC	0x0040	/* 2-channel mic select */
168467e9f4b6SRandy Cushman #define AC97_AD1986_SPRD	0x0080	/* SPREAD enable */
168567e9f4b6SRandy Cushman #define AC97_AD1986_DMIX0	0x0100	/* downmix mode: */
168667e9f4b6SRandy Cushman 					/*  0 = 6-to-4, 1 = 6-to-2 downmix */
168767e9f4b6SRandy Cushman #define AC97_AD1986_DMIX1	0x0200	/* downmix mode: 1 = enabled */
168867e9f4b6SRandy Cushman #define AC97_AD1986_CLDIS	0x0800	/* center/lfe disable */
168967e9f4b6SRandy Cushman #define AC97_AD1986_SODIS	0x1000	/* SURROUND_OUT disable */
169067e9f4b6SRandy Cushman #define AC97_AD1986_MSPLT	0x2000	/* mute split (read only 1) */
169167e9f4b6SRandy Cushman #define AC97_AD1986_AC97NC	0x4000	/* AC97 no compatible mode (r/o 1) */
169267e9f4b6SRandy Cushman #define AC97_AD1986_DACZ	0x8000	/* DAC zero-fill mode */
169367e9f4b6SRandy Cushman 
169467e9f4b6SRandy Cushman /* MISC 2 bits (AD1986 register 0x70) */
169567e9f4b6SRandy Cushman #define AC97_AD_MISC2		0x70	/* Misc Control Bits 2 (AD1986) */
169667e9f4b6SRandy Cushman 
169767e9f4b6SRandy Cushman #define AC97_AD1986_CVREF0	0x0004	/* C/LFE VREF_OUT 2.25V */
169867e9f4b6SRandy Cushman #define AC97_AD1986_CVREF1	0x0008	/* C/LFE VREF_OUT 0V */
169967e9f4b6SRandy Cushman #define AC97_AD1986_CVREF2	0x0010	/* C/LFE VREF_OUT 3.7V */
170067e9f4b6SRandy Cushman #define AC97_AD1986_CVREF_MASK \
170167e9f4b6SRandy Cushman 	(AC97_AD1986_CVREF2 | AC97_AD1986_CVREF1 | AC97_AD1986_CVREF0)
170267e9f4b6SRandy Cushman #define AC97_AD1986_JSMAP	0x0020	/* Jack Sense Mapping 1 = alternate */
170367e9f4b6SRandy Cushman #define AC97_AD1986_MMDIS	0x0080	/* Mono Mute Disable */
170467e9f4b6SRandy Cushman #define AC97_AD1986_MVREF0	0x0400	/* MIC VREF_OUT 2.25V */
170567e9f4b6SRandy Cushman #define AC97_AD1986_MVREF1	0x0800	/* MIC VREF_OUT 0V */
170667e9f4b6SRandy Cushman #define AC97_AD1986_MVREF2	0x1000	/* MIC VREF_OUT 3.7V */
170767e9f4b6SRandy Cushman #define AC97_AD1986_MVREF_MASK \
170867e9f4b6SRandy Cushman 	(AC97_AD1986_MVREF2 | AC97_AD1986_MVREF1 | AC97_AD1986_MVREF0)
170967e9f4b6SRandy Cushman 
171067e9f4b6SRandy Cushman /* MISC 3 bits (AD1986 register 0x7a) */
171167e9f4b6SRandy Cushman #define AC97_AD_MISC3		0x7a	/* Misc Control Bits 3 (AD1986) */
171267e9f4b6SRandy Cushman 
171367e9f4b6SRandy Cushman #define AC97_AD1986_MMIX	0x0004	/* Mic Mix, left/right */
171467e9f4b6SRandy Cushman #define AC97_AD1986_GPO		0x0008	/* General Purpose Out */
171567e9f4b6SRandy Cushman #define AC97_AD1986_LOHPEN	0x0010	/* LINE_OUT headphone drive */
171667e9f4b6SRandy Cushman #define AC97_AD1986_LVREF0	0x0100	/* LINE_OUT VREF_OUT 2.25V */
171767e9f4b6SRandy Cushman #define AC97_AD1986_LVREF1	0x0200	/* LINE_OUT VREF_OUT 0V */
171867e9f4b6SRandy Cushman #define AC97_AD1986_LVREF2	0x0400	/* LINE_OUT VREF_OUT 3.7V */
171967e9f4b6SRandy Cushman #define AC97_AD1986_LVREF_MASK \
172067e9f4b6SRandy Cushman 	(AC97_AD1986_LVREF2 | AC97_AD1986_LVREF1 | AC97_AD1986_LVREF0)
172167e9f4b6SRandy Cushman #define AC97_AD1986_JSINVA	0x0800	/* Jack Sense Invert SENSE_A */
172267e9f4b6SRandy Cushman #define AC97_AD1986_LOSEL	0x1000	/* LINE_OUT amplifiers input select */
172367e9f4b6SRandy Cushman #define AC97_AD1986_HPSEL0	0x2000	/* Headphone amplifiers */
172467e9f4b6SRandy Cushman 					/*   input select Surround DACs */
172567e9f4b6SRandy Cushman #define AC97_AD1986_HPSEL1	0x4000	/* Headphone amplifiers input */
172667e9f4b6SRandy Cushman 					/*   select C/LFE DACs */
172767e9f4b6SRandy Cushman #define AC97_AD1986_JSINVB	0x8000	/* Jack Sense Invert SENSE_B */
172867e9f4b6SRandy Cushman 
172967e9f4b6SRandy Cushman /* Serial Config bits (AD1986 register 0x74) (incomplete) */
173067e9f4b6SRandy Cushman #define AC97_AD1986_OMS0	0x0100	/* Optional Mic Selector bit 0 */
173167e9f4b6SRandy Cushman #define AC97_AD1986_OMS1	0x0200	/* Optional Mic Selector bit 1 */
173267e9f4b6SRandy Cushman #define AC97_AD1986_OMS2	0x0400	/* Optional Mic Selector bit 2 */
173367e9f4b6SRandy Cushman #define AC97_AD1986_OMS_MASK \
173467e9f4b6SRandy Cushman 	(AC97_AD1986_OMS2 | AC97_AD1986_OMS1 | AC97_AD1986_OMS0)
173567e9f4b6SRandy Cushman #define AC97_AD1986_OMS_M	0x0000  /* MIC_1/2 pins are MIC sources */
173667e9f4b6SRandy Cushman #define AC97_AD1986_OMS_L	0x0100  /* LINE_IN pins are MIC sources */
173767e9f4b6SRandy Cushman #define AC97_AD1986_OMS_C	0x0200  /* Center/LFE pins are MCI sources */
173867e9f4b6SRandy Cushman #define AC97_AD1986_OMS_MC	0x0400  /* Mix of MIC and C/LFE pins */
173967e9f4b6SRandy Cushman 					/*   are MIC sources */
174067e9f4b6SRandy Cushman #define AC97_AD1986_OMS_ML	0x0500  /* MIX of MIC and LINE_IN pins */
174167e9f4b6SRandy Cushman 					/*   are MIC sources */
174267e9f4b6SRandy Cushman #define AC97_AD1986_OMS_LC	0x0600  /* MIX of LINE_IN and C/LFE pins */
174367e9f4b6SRandy Cushman 					/*   are MIC sources */
174467e9f4b6SRandy Cushman #define AC97_AD1986_OMS_MLC	0x0700  /* MIX of MIC, LINE_IN, C/LFE pins */
174567e9f4b6SRandy Cushman 					/*   are MIC sources */
174667e9f4b6SRandy Cushman 
17471da177e4SLinus Torvalds 
1748ee42381eSTakashi Iwai static int snd_ac97_ad198x_spdif_source_info(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_info *uinfo)
17491da177e4SLinus Torvalds {
17503b7a00dcSTakashi Iwai 	static const char * const texts[2] = { "AC-Link", "A/D Converter" };
17511da177e4SLinus Torvalds 
17523b7a00dcSTakashi Iwai 	return snd_ctl_enum_info(uinfo, 1, 2, texts);
17531da177e4SLinus Torvalds }
17541da177e4SLinus Torvalds 
1755ee42381eSTakashi Iwai static int snd_ac97_ad198x_spdif_source_get(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
17561da177e4SLinus Torvalds {
1757ee42381eSTakashi Iwai 	struct snd_ac97 *ac97 = snd_kcontrol_chip(kcontrol);
17581da177e4SLinus Torvalds 	unsigned short val;
17591da177e4SLinus Torvalds 
17601da177e4SLinus Torvalds 	val = ac97->regs[AC97_AD_SERIAL_CFG];
17611da177e4SLinus Torvalds 	ucontrol->value.enumerated.item[0] = (val >> 2) & 1;
17621da177e4SLinus Torvalds 	return 0;
17631da177e4SLinus Torvalds }
17641da177e4SLinus Torvalds 
1765ee42381eSTakashi Iwai static int snd_ac97_ad198x_spdif_source_put(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
17661da177e4SLinus Torvalds {
1767ee42381eSTakashi Iwai 	struct snd_ac97 *ac97 = snd_kcontrol_chip(kcontrol);
17681da177e4SLinus Torvalds 	unsigned short val;
17691da177e4SLinus Torvalds 
17701da177e4SLinus Torvalds 	if (ucontrol->value.enumerated.item[0] > 1)
17711da177e4SLinus Torvalds 		return -EINVAL;
17721da177e4SLinus Torvalds 	val = ucontrol->value.enumerated.item[0] << 2;
17731da177e4SLinus Torvalds 	return snd_ac97_update_bits(ac97, AC97_AD_SERIAL_CFG, 0x0004, val);
17741da177e4SLinus Torvalds }
17751da177e4SLinus Torvalds 
1776ee42381eSTakashi Iwai static const struct snd_kcontrol_new snd_ac97_ad198x_spdif_source = {
17771da177e4SLinus Torvalds 	.iface	= SNDRV_CTL_ELEM_IFACE_MIXER,
17781da177e4SLinus Torvalds 	.name	= SNDRV_CTL_NAME_IEC958("",PLAYBACK,NONE) "Source",
17791da177e4SLinus Torvalds 	.info	= snd_ac97_ad198x_spdif_source_info,
17801da177e4SLinus Torvalds 	.get	= snd_ac97_ad198x_spdif_source_get,
17811da177e4SLinus Torvalds 	.put	= snd_ac97_ad198x_spdif_source_put,
17821da177e4SLinus Torvalds };
17831da177e4SLinus Torvalds 
1784ee42381eSTakashi Iwai static int patch_ad198x_post_spdif(struct snd_ac97 * ac97)
17851da177e4SLinus Torvalds {
17861da177e4SLinus Torvalds  	return patch_build_controls(ac97, &snd_ac97_ad198x_spdif_source, 1);
17871da177e4SLinus Torvalds }
17881da177e4SLinus Torvalds 
1789ee42381eSTakashi Iwai static const struct snd_kcontrol_new snd_ac97_ad1981x_jack_sense[] = {
17901da177e4SLinus Torvalds 	AC97_SINGLE("Headphone Jack Sense", AC97_AD_JACK_SPDIF, 11, 1, 0),
17911da177e4SLinus Torvalds 	AC97_SINGLE("Line Jack Sense", AC97_AD_JACK_SPDIF, 12, 1, 0),
17921da177e4SLinus Torvalds };
17931da177e4SLinus Torvalds 
1794128a46a5STakashi Iwai /* black list to avoid HP/Line jack-sense controls
1795128a46a5STakashi Iwai  * (SS vendor << 16 | device)
1796128a46a5STakashi Iwai  */
17971675bfc0STakashi Iwai static const unsigned int ad1981_jacks_blacklist[] = {
1798a31e8c72STakashi Iwai 	0x10140523, /* Thinkpad R40 */
1799a31e8c72STakashi Iwai 	0x10140534, /* Thinkpad X31 */
1800a43c4d4dSTakashi Iwai 	0x10140537, /* Thinkpad T41p */
1801e1f7f02bSDaniel T Chen 	0x1014053e, /* Thinkpad R40e */
1802128a46a5STakashi Iwai 	0x10140554, /* Thinkpad T42p/R50p */
18038286c53eSDaniel T Chen 	0x10140567, /* Thinkpad T43p 2668-G7U */
18048286c53eSDaniel T Chen 	0x10140581, /* Thinkpad X41-2527 */
1805af9a75ddSDaniel T Chen 	0x10280160, /* Dell Dimension 2400 */
18068286c53eSDaniel T Chen 	0x104380b0, /* Asus A7V8X-MX */
18078286c53eSDaniel T Chen 	0x11790241, /* Toshiba Satellite A-15 S127 */
18085cd165e7SDaniel Chen 	0x1179ff10, /* Toshiba P500 */
18098286c53eSDaniel T Chen 	0x144dc01a, /* Samsung NP-X20C004/SEG */
1810128a46a5STakashi Iwai 	0 /* end */
1811128a46a5STakashi Iwai };
1812128a46a5STakashi Iwai 
1813128a46a5STakashi Iwai static int check_list(struct snd_ac97 *ac97, const unsigned int *list)
1814128a46a5STakashi Iwai {
1815128a46a5STakashi Iwai 	u32 subid = ((u32)ac97->subsystem_vendor << 16) | ac97->subsystem_device;
1816128a46a5STakashi Iwai 	for (; *list; list++)
1817128a46a5STakashi Iwai 		if (*list == subid)
1818128a46a5STakashi Iwai 			return 1;
1819128a46a5STakashi Iwai 	return 0;
1820128a46a5STakashi Iwai }
1821128a46a5STakashi Iwai 
1822ee42381eSTakashi Iwai static int patch_ad1981a_specific(struct snd_ac97 * ac97)
18231da177e4SLinus Torvalds {
1824128a46a5STakashi Iwai 	if (check_list(ac97, ad1981_jacks_blacklist))
1825128a46a5STakashi Iwai 		return 0;
18261da177e4SLinus Torvalds 	return patch_build_controls(ac97, snd_ac97_ad1981x_jack_sense,
18271da177e4SLinus Torvalds 				    ARRAY_SIZE(snd_ac97_ad1981x_jack_sense));
18281da177e4SLinus Torvalds }
18291da177e4SLinus Torvalds 
18303e8b3b90SHanno Boeck static const struct snd_ac97_build_ops patch_ad1981a_build_ops = {
18311da177e4SLinus Torvalds 	.build_post_spdif = patch_ad198x_post_spdif,
18321da177e4SLinus Torvalds 	.build_specific = patch_ad1981a_specific,
18331da177e4SLinus Torvalds #ifdef CONFIG_PM
18341da177e4SLinus Torvalds 	.resume = ad18xx_resume
18351da177e4SLinus Torvalds #endif
18361da177e4SLinus Torvalds };
18371da177e4SLinus Torvalds 
1838128a46a5STakashi Iwai /* white list to enable HP jack-sense bits
1839128a46a5STakashi Iwai  * (SS vendor << 16 | device)
1840128a46a5STakashi Iwai  */
18411675bfc0STakashi Iwai static const unsigned int ad1981_jacks_whitelist[] = {
1842128a46a5STakashi Iwai 	0x0e11005a, /* HP nc4000/4010 */
1843128a46a5STakashi Iwai 	0x103c0890, /* HP nc6000 */
1844128a46a5STakashi Iwai 	0x103c0938, /* HP nc4220 */
1845128a46a5STakashi Iwai 	0x103c099c, /* HP nx6110 */
1846128a46a5STakashi Iwai 	0x103c0944, /* HP nc6220 */
1847128a46a5STakashi Iwai 	0x103c0934, /* HP nc8220 */
1848128a46a5STakashi Iwai 	0x103c006d, /* HP nx9105 */
1849eade7b28SDaniel T Chen 	0x103c300d, /* HP Compaq dc5100 SFF(PT003AW) */
1850128a46a5STakashi Iwai 	0x17340088, /* FSC Scenic-W */
1851128a46a5STakashi Iwai 	0 /* end */
1852128a46a5STakashi Iwai };
1853128a46a5STakashi Iwai 
1854ee42381eSTakashi Iwai static void check_ad1981_hp_jack_sense(struct snd_ac97 *ac97)
18551da177e4SLinus Torvalds {
1856128a46a5STakashi Iwai 	if (check_list(ac97, ad1981_jacks_whitelist))
18571da177e4SLinus Torvalds 		/* enable headphone jack sense */
18581da177e4SLinus Torvalds 		snd_ac97_update_bits(ac97, AC97_AD_JACK_SPDIF, 1<<11, 1<<11);
18591da177e4SLinus Torvalds }
18601da177e4SLinus Torvalds 
1861ac519028STakashi Iwai static int patch_ad1981a(struct snd_ac97 *ac97)
18621da177e4SLinus Torvalds {
18631da177e4SLinus Torvalds 	patch_ad1881(ac97);
18641da177e4SLinus Torvalds 	ac97->build_ops = &patch_ad1981a_build_ops;
18651da177e4SLinus Torvalds 	snd_ac97_update_bits(ac97, AC97_AD_MISC, AC97_AD198X_MSPLT, AC97_AD198X_MSPLT);
18661da177e4SLinus Torvalds 	ac97->flags |= AC97_STEREO_MUTES;
18671da177e4SLinus Torvalds 	check_ad1981_hp_jack_sense(ac97);
18681da177e4SLinus Torvalds 	return 0;
18691da177e4SLinus Torvalds }
18701da177e4SLinus Torvalds 
1871ee42381eSTakashi Iwai static const struct snd_kcontrol_new snd_ac97_ad198x_2cmic =
18721da177e4SLinus Torvalds AC97_SINGLE("Stereo Mic", AC97_AD_MISC, 6, 1, 0);
18731da177e4SLinus Torvalds 
1874ee42381eSTakashi Iwai static int patch_ad1981b_specific(struct snd_ac97 *ac97)
18751da177e4SLinus Torvalds {
18761da177e4SLinus Torvalds 	int err;
18771da177e4SLinus Torvalds 
18781da177e4SLinus Torvalds 	if ((err = patch_build_controls(ac97, &snd_ac97_ad198x_2cmic, 1)) < 0)
18791da177e4SLinus Torvalds 		return err;
1880128a46a5STakashi Iwai 	if (check_list(ac97, ad1981_jacks_blacklist))
1881128a46a5STakashi Iwai 		return 0;
18821da177e4SLinus Torvalds 	return patch_build_controls(ac97, snd_ac97_ad1981x_jack_sense,
18831da177e4SLinus Torvalds 				    ARRAY_SIZE(snd_ac97_ad1981x_jack_sense));
18841da177e4SLinus Torvalds }
18851da177e4SLinus Torvalds 
18863e8b3b90SHanno Boeck static const struct snd_ac97_build_ops patch_ad1981b_build_ops = {
18871da177e4SLinus Torvalds 	.build_post_spdif = patch_ad198x_post_spdif,
18881da177e4SLinus Torvalds 	.build_specific = patch_ad1981b_specific,
18891da177e4SLinus Torvalds #ifdef CONFIG_PM
18901da177e4SLinus Torvalds 	.resume = ad18xx_resume
18911da177e4SLinus Torvalds #endif
18921da177e4SLinus Torvalds };
18931da177e4SLinus Torvalds 
1894ac519028STakashi Iwai static int patch_ad1981b(struct snd_ac97 *ac97)
18951da177e4SLinus Torvalds {
18961da177e4SLinus Torvalds 	patch_ad1881(ac97);
18971da177e4SLinus Torvalds 	ac97->build_ops = &patch_ad1981b_build_ops;
18981da177e4SLinus Torvalds 	snd_ac97_update_bits(ac97, AC97_AD_MISC, AC97_AD198X_MSPLT, AC97_AD198X_MSPLT);
18991da177e4SLinus Torvalds 	ac97->flags |= AC97_STEREO_MUTES;
19001da177e4SLinus Torvalds 	check_ad1981_hp_jack_sense(ac97);
19011da177e4SLinus Torvalds 	return 0;
19021da177e4SLinus Torvalds }
19031da177e4SLinus Torvalds 
1904a5ce8890STakashi Iwai #define snd_ac97_ad1888_lohpsel_info	snd_ctl_boolean_mono_info
19051da177e4SLinus Torvalds 
1906ee42381eSTakashi Iwai static int snd_ac97_ad1888_lohpsel_get(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
19071da177e4SLinus Torvalds {
1908ee42381eSTakashi Iwai 	struct snd_ac97 *ac97 = snd_kcontrol_chip(kcontrol);
19091da177e4SLinus Torvalds 	unsigned short val;
19101da177e4SLinus Torvalds 
19111da177e4SLinus Torvalds 	val = ac97->regs[AC97_AD_MISC];
19121da177e4SLinus Torvalds 	ucontrol->value.integer.value[0] = !(val & AC97_AD198X_LOSEL);
1913e48d6d97STakashi Iwai 	if (ac97->spec.ad18xx.lo_as_master)
1914e48d6d97STakashi Iwai 		ucontrol->value.integer.value[0] =
1915e48d6d97STakashi Iwai 			!ucontrol->value.integer.value[0];
19161da177e4SLinus Torvalds 	return 0;
19171da177e4SLinus Torvalds }
19181da177e4SLinus Torvalds 
1919ee42381eSTakashi Iwai static int snd_ac97_ad1888_lohpsel_put(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
19201da177e4SLinus Torvalds {
1921ee42381eSTakashi Iwai 	struct snd_ac97 *ac97 = snd_kcontrol_chip(kcontrol);
19221da177e4SLinus Torvalds 	unsigned short val;
19231da177e4SLinus Torvalds 
1924e48d6d97STakashi Iwai 	val = !ucontrol->value.integer.value[0];
1925e48d6d97STakashi Iwai 	if (ac97->spec.ad18xx.lo_as_master)
1926e48d6d97STakashi Iwai 		val = !val;
1927e48d6d97STakashi Iwai 	val = val ? (AC97_AD198X_LOSEL | AC97_AD198X_HPSEL) : 0;
19281da177e4SLinus Torvalds 	return snd_ac97_update_bits(ac97, AC97_AD_MISC,
19291da177e4SLinus Torvalds 				    AC97_AD198X_LOSEL | AC97_AD198X_HPSEL, val);
19301da177e4SLinus Torvalds }
19311da177e4SLinus Torvalds 
1932ee42381eSTakashi Iwai static int snd_ac97_ad1888_downmix_info(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_info *uinfo)
19331da177e4SLinus Torvalds {
19343b7a00dcSTakashi Iwai 	static const char * const texts[3] = {"Off", "6 -> 4", "6 -> 2"};
19351da177e4SLinus Torvalds 
19363b7a00dcSTakashi Iwai 	return snd_ctl_enum_info(uinfo, 1, 3, texts);
19371da177e4SLinus Torvalds }
19381da177e4SLinus Torvalds 
1939ee42381eSTakashi Iwai static int snd_ac97_ad1888_downmix_get(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
19401da177e4SLinus Torvalds {
1941ee42381eSTakashi Iwai 	struct snd_ac97 *ac97 = snd_kcontrol_chip(kcontrol);
19421da177e4SLinus Torvalds 	unsigned short val;
19431da177e4SLinus Torvalds 
19441da177e4SLinus Torvalds 	val = ac97->regs[AC97_AD_MISC];
19451da177e4SLinus Torvalds 	if (!(val & AC97_AD198X_DMIX1))
19461da177e4SLinus Torvalds 		ucontrol->value.enumerated.item[0] = 0;
19471da177e4SLinus Torvalds 	else
19481da177e4SLinus Torvalds 		ucontrol->value.enumerated.item[0] = 1 + ((val >> 8) & 1);
19491da177e4SLinus Torvalds 	return 0;
19501da177e4SLinus Torvalds }
19511da177e4SLinus Torvalds 
1952ee42381eSTakashi Iwai static int snd_ac97_ad1888_downmix_put(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
19531da177e4SLinus Torvalds {
1954ee42381eSTakashi Iwai 	struct snd_ac97 *ac97 = snd_kcontrol_chip(kcontrol);
19551da177e4SLinus Torvalds 	unsigned short val;
19561da177e4SLinus Torvalds 
19571da177e4SLinus Torvalds 	if (ucontrol->value.enumerated.item[0] > 2)
19581da177e4SLinus Torvalds 		return -EINVAL;
19591da177e4SLinus Torvalds 	if (ucontrol->value.enumerated.item[0] == 0)
19601da177e4SLinus Torvalds 		val = 0;
19611da177e4SLinus Torvalds 	else
19621da177e4SLinus Torvalds 		val = AC97_AD198X_DMIX1 |
19631da177e4SLinus Torvalds 			((ucontrol->value.enumerated.item[0] - 1) << 8);
19641da177e4SLinus Torvalds 	return snd_ac97_update_bits(ac97, AC97_AD_MISC,
19651da177e4SLinus Torvalds 				    AC97_AD198X_DMIX0 | AC97_AD198X_DMIX1, val);
19661da177e4SLinus Torvalds }
19671da177e4SLinus Torvalds 
1968ee42381eSTakashi Iwai static void ad1888_update_jacks(struct snd_ac97 *ac97)
1969eb8caf30STakashi Iwai {
19704525c9f3STakashi Iwai 	unsigned short val = 0;
1971c26a8de2SRandy Cushman 	/* clear LODIS if shared jack is to be used for Surround out */
1972e48d6d97STakashi Iwai 	if (!ac97->spec.ad18xx.lo_as_master && is_shared_linein(ac97))
19734525c9f3STakashi Iwai 		val |= (1 << 12);
1974c26a8de2SRandy Cushman 	/* clear CLDIS if shared jack is to be used for C/LFE out */
1975c26a8de2SRandy Cushman 	if (is_shared_micin(ac97))
19764525c9f3STakashi Iwai 		val |= (1 << 11);
1977eb8caf30STakashi Iwai 	/* shared Line-In */
19784525c9f3STakashi Iwai 	snd_ac97_update_bits(ac97, AC97_AD_MISC, (1 << 11) | (1 << 12), val);
1979eb8caf30STakashi Iwai }
1980eb8caf30STakashi Iwai 
1981ee42381eSTakashi Iwai static const struct snd_kcontrol_new snd_ac97_ad1888_controls[] = {
19821da177e4SLinus Torvalds 	{
19831da177e4SLinus Torvalds 		.iface = SNDRV_CTL_ELEM_IFACE_MIXER,
19841da177e4SLinus Torvalds 		.name = "Exchange Front/Surround",
19851da177e4SLinus Torvalds 		.info = snd_ac97_ad1888_lohpsel_info,
19861da177e4SLinus Torvalds 		.get = snd_ac97_ad1888_lohpsel_get,
19871da177e4SLinus Torvalds 		.put = snd_ac97_ad1888_lohpsel_put
19881da177e4SLinus Torvalds 	},
19890bed7b29SAndres Salomon 	AC97_SINGLE("V_REFOUT Enable", AC97_AD_MISC, AC97_AD_VREFD_SHIFT, 1, 1),
19900bed7b29SAndres Salomon 	AC97_SINGLE("High Pass Filter Enable", AC97_AD_TEST2,
19910bed7b29SAndres Salomon 			AC97_AD_HPFD_SHIFT, 1, 1),
19921da177e4SLinus Torvalds 	AC97_SINGLE("Spread Front to Surround and Center/LFE", AC97_AD_MISC, 7, 1, 0),
19931da177e4SLinus Torvalds 	{
19941da177e4SLinus Torvalds 		.iface = SNDRV_CTL_ELEM_IFACE_MIXER,
19951da177e4SLinus Torvalds 		.name = "Downmix",
19961da177e4SLinus Torvalds 		.info = snd_ac97_ad1888_downmix_info,
19971da177e4SLinus Torvalds 		.get = snd_ac97_ad1888_downmix_get,
19981da177e4SLinus Torvalds 		.put = snd_ac97_ad1888_downmix_put
19991da177e4SLinus Torvalds 	},
2000eb8caf30STakashi Iwai 	AC97_SURROUND_JACK_MODE_CTL,
2001eb8caf30STakashi Iwai 	AC97_CHANNEL_MODE_CTL,
2002eeacb545SSergey Ulanov 
2003eeacb545SSergey Ulanov 	AC97_SINGLE("Headphone Jack Sense", AC97_AD_JACK_SPDIF, 10, 1, 0),
2004eeacb545SSergey Ulanov 	AC97_SINGLE("Line Jack Sense", AC97_AD_JACK_SPDIF, 12, 1, 0),
20051da177e4SLinus Torvalds };
20061da177e4SLinus Torvalds 
2007ee42381eSTakashi Iwai static int patch_ad1888_specific(struct snd_ac97 *ac97)
20081da177e4SLinus Torvalds {
2009e48d6d97STakashi Iwai 	if (!ac97->spec.ad18xx.lo_as_master) {
20101da177e4SLinus Torvalds 		/* rename 0x04 as "Master" and 0x02 as "Master Surround" */
2011e48d6d97STakashi Iwai 		snd_ac97_rename_vol_ctl(ac97, "Master Playback",
2012e48d6d97STakashi Iwai 					"Master Surround Playback");
2013e48d6d97STakashi Iwai 		snd_ac97_rename_vol_ctl(ac97, "Headphone Playback",
2014e48d6d97STakashi Iwai 					"Master Playback");
2015e48d6d97STakashi Iwai 	}
20161da177e4SLinus Torvalds 	return patch_build_controls(ac97, snd_ac97_ad1888_controls, ARRAY_SIZE(snd_ac97_ad1888_controls));
20171da177e4SLinus Torvalds }
20181da177e4SLinus Torvalds 
20193e8b3b90SHanno Boeck static const struct snd_ac97_build_ops patch_ad1888_build_ops = {
20201da177e4SLinus Torvalds 	.build_post_spdif = patch_ad198x_post_spdif,
20211da177e4SLinus Torvalds 	.build_specific = patch_ad1888_specific,
20221da177e4SLinus Torvalds #ifdef CONFIG_PM
20231561f09aSJaya Kumar 	.resume = ad1888_resume,
20241da177e4SLinus Torvalds #endif
2025eb8caf30STakashi Iwai 	.update_jacks = ad1888_update_jacks,
20261da177e4SLinus Torvalds };
20271da177e4SLinus Torvalds 
2028ac519028STakashi Iwai static int patch_ad1888(struct snd_ac97 * ac97)
20291da177e4SLinus Torvalds {
20301da177e4SLinus Torvalds 	unsigned short misc;
20311da177e4SLinus Torvalds 
20321da177e4SLinus Torvalds 	patch_ad1881(ac97);
20331da177e4SLinus Torvalds 	ac97->build_ops = &patch_ad1888_build_ops;
2034e48d6d97STakashi Iwai 
2035e48d6d97STakashi Iwai 	/*
2036e48d6d97STakashi Iwai 	 * LO can be used as a real line-out on some devices,
2037e48d6d97STakashi Iwai 	 * and we need to revert the front/surround mixer switches
2038e48d6d97STakashi Iwai 	 */
2039e48d6d97STakashi Iwai 	if (ac97->subsystem_vendor == 0x1043 &&
2040e48d6d97STakashi Iwai 	    ac97->subsystem_device == 0x1193) /* ASUS A9T laptop */
2041e48d6d97STakashi Iwai 		ac97->spec.ad18xx.lo_as_master = 1;
2042e48d6d97STakashi Iwai 
2043e48d6d97STakashi Iwai 	misc = snd_ac97_read(ac97, AC97_AD_MISC);
20441da177e4SLinus Torvalds 	/* AD-compatible mode */
20451da177e4SLinus Torvalds 	/* Stereo mutes enabled */
2046e48d6d97STakashi Iwai 	misc |= AC97_AD198X_MSPLT | AC97_AD198X_AC97NC;
2047e48d6d97STakashi Iwai 	if (!ac97->spec.ad18xx.lo_as_master)
2048e48d6d97STakashi Iwai 		/* Switch FRONT/SURROUND LINE-OUT/HP-OUT default connection */
2049e48d6d97STakashi Iwai 		/* it seems that most vendors connect line-out connector to
2050e48d6d97STakashi Iwai 		 * headphone out of AC'97
2051e48d6d97STakashi Iwai 		 */
2052e48d6d97STakashi Iwai 		misc |= AC97_AD198X_LOSEL | AC97_AD198X_HPSEL;
2053e48d6d97STakashi Iwai 
2054e48d6d97STakashi Iwai 	snd_ac97_write_cache(ac97, AC97_AD_MISC, misc);
20551da177e4SLinus Torvalds 	ac97->flags |= AC97_STEREO_MUTES;
20561da177e4SLinus Torvalds 	return 0;
20571da177e4SLinus Torvalds }
20581da177e4SLinus Torvalds 
2059ee42381eSTakashi Iwai static int patch_ad1980_specific(struct snd_ac97 *ac97)
20601da177e4SLinus Torvalds {
20611da177e4SLinus Torvalds 	int err;
20621da177e4SLinus Torvalds 
20631da177e4SLinus Torvalds 	if ((err = patch_ad1888_specific(ac97)) < 0)
20641da177e4SLinus Torvalds 		return err;
20651da177e4SLinus Torvalds 	return patch_build_controls(ac97, &snd_ac97_ad198x_2cmic, 1);
20661da177e4SLinus Torvalds }
20671da177e4SLinus Torvalds 
20683e8b3b90SHanno Boeck static const struct snd_ac97_build_ops patch_ad1980_build_ops = {
20691da177e4SLinus Torvalds 	.build_post_spdif = patch_ad198x_post_spdif,
20701da177e4SLinus Torvalds 	.build_specific = patch_ad1980_specific,
20711da177e4SLinus Torvalds #ifdef CONFIG_PM
2072462c4173SClemens Ladisch 	.resume = ad18xx_resume,
20731da177e4SLinus Torvalds #endif
2074462c4173SClemens Ladisch 	.update_jacks = ad1888_update_jacks,
20751da177e4SLinus Torvalds };
20761da177e4SLinus Torvalds 
2077ac519028STakashi Iwai static int patch_ad1980(struct snd_ac97 * ac97)
20781da177e4SLinus Torvalds {
20791da177e4SLinus Torvalds 	patch_ad1888(ac97);
20801da177e4SLinus Torvalds 	ac97->build_ops = &patch_ad1980_build_ops;
20811da177e4SLinus Torvalds 	return 0;
20821da177e4SLinus Torvalds }
20831da177e4SLinus Torvalds 
20846428ea1bSRandy Cushman static int snd_ac97_ad1985_vrefout_info(struct snd_kcontrol *kcontrol,
20856428ea1bSRandy Cushman 					struct snd_ctl_elem_info *uinfo)
20866428ea1bSRandy Cushman {
20873b7a00dcSTakashi Iwai 	static const char * const texts[4] = {
20883b7a00dcSTakashi Iwai 		"High-Z", "3.7 V", "2.25 V", "0 V"
20893b7a00dcSTakashi Iwai 	};
20906428ea1bSRandy Cushman 
20913b7a00dcSTakashi Iwai 	return snd_ctl_enum_info(uinfo, 1, 4, texts);
20926428ea1bSRandy Cushman }
20936428ea1bSRandy Cushman 
20946428ea1bSRandy Cushman static int snd_ac97_ad1985_vrefout_get(struct snd_kcontrol *kcontrol,
20956428ea1bSRandy Cushman 				       struct snd_ctl_elem_value *ucontrol)
20966428ea1bSRandy Cushman {
20976428ea1bSRandy Cushman 	static const int reg2ctrl[4] = {2, 0, 1, 3};
20986428ea1bSRandy Cushman 	struct snd_ac97 *ac97 = snd_kcontrol_chip(kcontrol);
20996428ea1bSRandy Cushman 	unsigned short val;
21006428ea1bSRandy Cushman 	val = (ac97->regs[AC97_AD_MISC] & AC97_AD198X_VREF_MASK)
21016428ea1bSRandy Cushman 	      >> AC97_AD198X_VREF_SHIFT;
21026428ea1bSRandy Cushman 	ucontrol->value.enumerated.item[0] = reg2ctrl[val];
21036428ea1bSRandy Cushman 	return 0;
21046428ea1bSRandy Cushman }
21056428ea1bSRandy Cushman 
21066428ea1bSRandy Cushman static int snd_ac97_ad1985_vrefout_put(struct snd_kcontrol *kcontrol,
21076428ea1bSRandy Cushman 				       struct snd_ctl_elem_value *ucontrol)
21086428ea1bSRandy Cushman {
21096428ea1bSRandy Cushman 	static const int ctrl2reg[4] = {1, 2, 0, 3};
21106428ea1bSRandy Cushman 	struct snd_ac97 *ac97 = snd_kcontrol_chip(kcontrol);
21116428ea1bSRandy Cushman 	unsigned short val;
21126428ea1bSRandy Cushman 
21134e98d6a7STakashi Iwai 	if (ucontrol->value.enumerated.item[0] > 3)
21146428ea1bSRandy Cushman 		return -EINVAL;
21156428ea1bSRandy Cushman 	val = ctrl2reg[ucontrol->value.enumerated.item[0]]
21166428ea1bSRandy Cushman 	      << AC97_AD198X_VREF_SHIFT;
21176428ea1bSRandy Cushman 	return snd_ac97_update_bits(ac97, AC97_AD_MISC,
21186428ea1bSRandy Cushman 				    AC97_AD198X_VREF_MASK, val);
21196428ea1bSRandy Cushman }
21206428ea1bSRandy Cushman 
2121ee42381eSTakashi Iwai static const struct snd_kcontrol_new snd_ac97_ad1985_controls[] = {
21226428ea1bSRandy Cushman 	AC97_SINGLE("Exchange Center/LFE", AC97_AD_SERIAL_CFG, 3, 1, 0),
21236428ea1bSRandy Cushman 	{
21246428ea1bSRandy Cushman 		.iface = SNDRV_CTL_ELEM_IFACE_MIXER,
21256428ea1bSRandy Cushman 		.name = "Exchange Front/Surround",
21266428ea1bSRandy Cushman 		.info = snd_ac97_ad1888_lohpsel_info,
21276428ea1bSRandy Cushman 		.get = snd_ac97_ad1888_lohpsel_get,
21286428ea1bSRandy Cushman 		.put = snd_ac97_ad1888_lohpsel_put
21296428ea1bSRandy Cushman 	},
21306428ea1bSRandy Cushman 	AC97_SINGLE("High Pass Filter Enable", AC97_AD_TEST2, 12, 1, 1),
21316428ea1bSRandy Cushman 	AC97_SINGLE("Spread Front to Surround and Center/LFE",
21326428ea1bSRandy Cushman 		    AC97_AD_MISC, 7, 1, 0),
21336428ea1bSRandy Cushman 	{
21346428ea1bSRandy Cushman 		.iface = SNDRV_CTL_ELEM_IFACE_MIXER,
21356428ea1bSRandy Cushman 		.name = "Downmix",
21366428ea1bSRandy Cushman 		.info = snd_ac97_ad1888_downmix_info,
21376428ea1bSRandy Cushman 		.get = snd_ac97_ad1888_downmix_get,
21386428ea1bSRandy Cushman 		.put = snd_ac97_ad1888_downmix_put
21396428ea1bSRandy Cushman 	},
21406428ea1bSRandy Cushman 	{
21416428ea1bSRandy Cushman 		.iface = SNDRV_CTL_ELEM_IFACE_MIXER,
21426428ea1bSRandy Cushman 		.name = "V_REFOUT",
21436428ea1bSRandy Cushman 		.info = snd_ac97_ad1985_vrefout_info,
21446428ea1bSRandy Cushman 		.get = snd_ac97_ad1985_vrefout_get,
21456428ea1bSRandy Cushman 		.put = snd_ac97_ad1985_vrefout_put
21466428ea1bSRandy Cushman 	},
21476428ea1bSRandy Cushman 	AC97_SURROUND_JACK_MODE_CTL,
21486428ea1bSRandy Cushman 	AC97_CHANNEL_MODE_CTL,
21496428ea1bSRandy Cushman 
21506428ea1bSRandy Cushman 	AC97_SINGLE("Headphone Jack Sense", AC97_AD_JACK_SPDIF, 10, 1, 0),
21516428ea1bSRandy Cushman 	AC97_SINGLE("Line Jack Sense", AC97_AD_JACK_SPDIF, 12, 1, 0),
21521da177e4SLinus Torvalds };
21531da177e4SLinus Torvalds 
2154ee42381eSTakashi Iwai static void ad1985_update_jacks(struct snd_ac97 *ac97)
2155e5b3f45fSTakashi Iwai {
21564525c9f3STakashi Iwai 	ad1888_update_jacks(ac97);
2157c26a8de2SRandy Cushman 	/* clear OMS if shared jack is to be used for C/LFE out */
2158fc232c6eSTakashi Iwai 	snd_ac97_update_bits(ac97, AC97_AD_SERIAL_CFG, 1 << 9,
2159c26a8de2SRandy Cushman 			     is_shared_micin(ac97) ? 1 << 9 : 0);
2160e5b3f45fSTakashi Iwai }
2161e5b3f45fSTakashi Iwai 
2162ee42381eSTakashi Iwai static int patch_ad1985_specific(struct snd_ac97 *ac97)
21631da177e4SLinus Torvalds {
21641da177e4SLinus Torvalds 	int err;
21651da177e4SLinus Torvalds 
21666428ea1bSRandy Cushman 	/* rename 0x04 as "Master" and 0x02 as "Master Surround" */
21676428ea1bSRandy Cushman 	snd_ac97_rename_vol_ctl(ac97, "Master Playback",
21686428ea1bSRandy Cushman 				"Master Surround Playback");
21696428ea1bSRandy Cushman 	snd_ac97_rename_vol_ctl(ac97, "Headphone Playback", "Master Playback");
21706428ea1bSRandy Cushman 
21716428ea1bSRandy Cushman 	if ((err = patch_build_controls(ac97, &snd_ac97_ad198x_2cmic, 1)) < 0)
21721da177e4SLinus Torvalds 		return err;
21736428ea1bSRandy Cushman 
21746428ea1bSRandy Cushman 	return patch_build_controls(ac97, snd_ac97_ad1985_controls,
21756428ea1bSRandy Cushman 				    ARRAY_SIZE(snd_ac97_ad1985_controls));
21761da177e4SLinus Torvalds }
21771da177e4SLinus Torvalds 
21783e8b3b90SHanno Boeck static const struct snd_ac97_build_ops patch_ad1985_build_ops = {
21791da177e4SLinus Torvalds 	.build_post_spdif = patch_ad198x_post_spdif,
21801da177e4SLinus Torvalds 	.build_specific = patch_ad1985_specific,
21811da177e4SLinus Torvalds #ifdef CONFIG_PM
2182462c4173SClemens Ladisch 	.resume = ad18xx_resume,
21831da177e4SLinus Torvalds #endif
2184e5b3f45fSTakashi Iwai 	.update_jacks = ad1985_update_jacks,
21851da177e4SLinus Torvalds };
21861da177e4SLinus Torvalds 
2187ac519028STakashi Iwai static int patch_ad1985(struct snd_ac97 * ac97)
21881da177e4SLinus Torvalds {
21891da177e4SLinus Torvalds 	unsigned short misc;
21901da177e4SLinus Torvalds 
21911da177e4SLinus Torvalds 	patch_ad1881(ac97);
21921da177e4SLinus Torvalds 	ac97->build_ops = &patch_ad1985_build_ops;
21931da177e4SLinus Torvalds 	misc = snd_ac97_read(ac97, AC97_AD_MISC);
21941da177e4SLinus Torvalds 	/* switch front/surround line-out/hp-out */
21951da177e4SLinus Torvalds 	/* AD-compatible mode */
21961da177e4SLinus Torvalds 	/* Stereo mutes enabled */
21971da177e4SLinus Torvalds 	snd_ac97_write_cache(ac97, AC97_AD_MISC, misc |
21981da177e4SLinus Torvalds 			     AC97_AD198X_LOSEL |
21991da177e4SLinus Torvalds 			     AC97_AD198X_HPSEL |
22001da177e4SLinus Torvalds 			     AC97_AD198X_MSPLT |
22011da177e4SLinus Torvalds 			     AC97_AD198X_AC97NC);
22021da177e4SLinus Torvalds 	ac97->flags |= AC97_STEREO_MUTES;
22036428ea1bSRandy Cushman 
22046428ea1bSRandy Cushman 	/* update current jack configuration */
22056428ea1bSRandy Cushman 	ad1985_update_jacks(ac97);
22066428ea1bSRandy Cushman 
22071da177e4SLinus Torvalds 	/* on AD1985 rev. 3, AC'97 revision bits are zero */
22081da177e4SLinus Torvalds 	ac97->ext_id = (ac97->ext_id & ~AC97_EI_REV_MASK) | AC97_EI_REV_23;
22091da177e4SLinus Torvalds 	return 0;
22101da177e4SLinus Torvalds }
22111da177e4SLinus Torvalds 
2212a5ce8890STakashi Iwai #define snd_ac97_ad1986_bool_info	snd_ctl_boolean_mono_info
221367e9f4b6SRandy Cushman 
221467e9f4b6SRandy Cushman static int snd_ac97_ad1986_lososel_get(struct snd_kcontrol *kcontrol,
221567e9f4b6SRandy Cushman 				       struct snd_ctl_elem_value *ucontrol)
221667e9f4b6SRandy Cushman {
221767e9f4b6SRandy Cushman 	struct snd_ac97 *ac97 = snd_kcontrol_chip(kcontrol);
221867e9f4b6SRandy Cushman 	unsigned short val;
221967e9f4b6SRandy Cushman 
222067e9f4b6SRandy Cushman 	val = ac97->regs[AC97_AD_MISC3];
222167e9f4b6SRandy Cushman 	ucontrol->value.integer.value[0] = (val & AC97_AD1986_LOSEL) != 0;
222267e9f4b6SRandy Cushman 	return 0;
222367e9f4b6SRandy Cushman }
222467e9f4b6SRandy Cushman 
222567e9f4b6SRandy Cushman static int snd_ac97_ad1986_lososel_put(struct snd_kcontrol *kcontrol,
222667e9f4b6SRandy Cushman 				       struct snd_ctl_elem_value *ucontrol)
222767e9f4b6SRandy Cushman {
222867e9f4b6SRandy Cushman 	struct snd_ac97 *ac97 = snd_kcontrol_chip(kcontrol);
222967e9f4b6SRandy Cushman 	int ret0;
223067e9f4b6SRandy Cushman 	int ret1;
223167e9f4b6SRandy Cushman 	int sprd = (ac97->regs[AC97_AD_MISC] & AC97_AD1986_SPRD) != 0;
223267e9f4b6SRandy Cushman 
223367e9f4b6SRandy Cushman 	ret0 = snd_ac97_update_bits(ac97, AC97_AD_MISC3, AC97_AD1986_LOSEL,
223467e9f4b6SRandy Cushman 					ucontrol->value.integer.value[0] != 0
223567e9f4b6SRandy Cushman 				    ? AC97_AD1986_LOSEL : 0);
223667e9f4b6SRandy Cushman 	if (ret0 < 0)
223767e9f4b6SRandy Cushman 		return ret0;
223867e9f4b6SRandy Cushman 
223967e9f4b6SRandy Cushman 	/* SOSEL is set to values of "Spread" or "Exchange F/S" controls */
224067e9f4b6SRandy Cushman 	ret1 = snd_ac97_update_bits(ac97, AC97_AD_MISC, AC97_AD1986_SOSEL,
224167e9f4b6SRandy Cushman 				    (ucontrol->value.integer.value[0] != 0
224267e9f4b6SRandy Cushman 				     || sprd)
224367e9f4b6SRandy Cushman 				    ? AC97_AD1986_SOSEL : 0);
224467e9f4b6SRandy Cushman 	if (ret1 < 0)
224567e9f4b6SRandy Cushman 		return ret1;
224667e9f4b6SRandy Cushman 
224767e9f4b6SRandy Cushman 	return (ret0 > 0 || ret1 > 0) ? 1 : 0;
224867e9f4b6SRandy Cushman }
224967e9f4b6SRandy Cushman 
225067e9f4b6SRandy Cushman static int snd_ac97_ad1986_spread_get(struct snd_kcontrol *kcontrol,
225167e9f4b6SRandy Cushman 				      struct snd_ctl_elem_value *ucontrol)
225267e9f4b6SRandy Cushman {
225367e9f4b6SRandy Cushman 	struct snd_ac97 *ac97 = snd_kcontrol_chip(kcontrol);
225467e9f4b6SRandy Cushman 	unsigned short val;
225567e9f4b6SRandy Cushman 
225667e9f4b6SRandy Cushman 	val = ac97->regs[AC97_AD_MISC];
225767e9f4b6SRandy Cushman 	ucontrol->value.integer.value[0] = (val & AC97_AD1986_SPRD) != 0;
225867e9f4b6SRandy Cushman 	return 0;
225967e9f4b6SRandy Cushman }
226067e9f4b6SRandy Cushman 
226167e9f4b6SRandy Cushman static int snd_ac97_ad1986_spread_put(struct snd_kcontrol *kcontrol,
226267e9f4b6SRandy Cushman 				      struct snd_ctl_elem_value *ucontrol)
226367e9f4b6SRandy Cushman {
226467e9f4b6SRandy Cushman 	struct snd_ac97 *ac97 = snd_kcontrol_chip(kcontrol);
226567e9f4b6SRandy Cushman 	int ret0;
226667e9f4b6SRandy Cushman 	int ret1;
226767e9f4b6SRandy Cushman 	int sprd = (ac97->regs[AC97_AD_MISC3] & AC97_AD1986_LOSEL) != 0;
226867e9f4b6SRandy Cushman 
226967e9f4b6SRandy Cushman 	ret0 = snd_ac97_update_bits(ac97, AC97_AD_MISC, AC97_AD1986_SPRD,
227067e9f4b6SRandy Cushman 					ucontrol->value.integer.value[0] != 0
227167e9f4b6SRandy Cushman 				    ? AC97_AD1986_SPRD : 0);
227267e9f4b6SRandy Cushman 	if (ret0 < 0)
227367e9f4b6SRandy Cushman 		return ret0;
227467e9f4b6SRandy Cushman 
227567e9f4b6SRandy Cushman 	/* SOSEL is set to values of "Spread" or "Exchange F/S" controls */
227667e9f4b6SRandy Cushman 	ret1 = snd_ac97_update_bits(ac97, AC97_AD_MISC, AC97_AD1986_SOSEL,
227767e9f4b6SRandy Cushman 				    (ucontrol->value.integer.value[0] != 0
227867e9f4b6SRandy Cushman 				     || sprd)
227967e9f4b6SRandy Cushman 				    ? AC97_AD1986_SOSEL : 0);
228067e9f4b6SRandy Cushman 	if (ret1 < 0)
228167e9f4b6SRandy Cushman 		return ret1;
228267e9f4b6SRandy Cushman 
228367e9f4b6SRandy Cushman 	return (ret0 > 0 || ret1 > 0) ? 1 : 0;
228467e9f4b6SRandy Cushman }
228567e9f4b6SRandy Cushman 
228667e9f4b6SRandy Cushman static int snd_ac97_ad1986_miclisel_get(struct snd_kcontrol *kcontrol,
228767e9f4b6SRandy Cushman 					struct snd_ctl_elem_value *ucontrol)
228867e9f4b6SRandy Cushman {
228967e9f4b6SRandy Cushman 	struct snd_ac97 *ac97 = snd_kcontrol_chip(kcontrol);
229067e9f4b6SRandy Cushman 
229167e9f4b6SRandy Cushman 	ucontrol->value.integer.value[0] = ac97->spec.ad18xx.swap_mic_linein;
229267e9f4b6SRandy Cushman 	return 0;
229367e9f4b6SRandy Cushman }
229467e9f4b6SRandy Cushman 
229567e9f4b6SRandy Cushman static int snd_ac97_ad1986_miclisel_put(struct snd_kcontrol *kcontrol,
229667e9f4b6SRandy Cushman 					struct snd_ctl_elem_value *ucontrol)
229767e9f4b6SRandy Cushman {
229867e9f4b6SRandy Cushman 	struct snd_ac97 *ac97 = snd_kcontrol_chip(kcontrol);
229967e9f4b6SRandy Cushman 	unsigned char swap = ucontrol->value.integer.value[0] != 0;
230067e9f4b6SRandy Cushman 
230167e9f4b6SRandy Cushman 	if (swap != ac97->spec.ad18xx.swap_mic_linein) {
230267e9f4b6SRandy Cushman 		ac97->spec.ad18xx.swap_mic_linein = swap;
230367e9f4b6SRandy Cushman 		if (ac97->build_ops->update_jacks)
230467e9f4b6SRandy Cushman 			ac97->build_ops->update_jacks(ac97);
230567e9f4b6SRandy Cushman 		return 1;
230667e9f4b6SRandy Cushman 	}
230767e9f4b6SRandy Cushman 	return 0;
230867e9f4b6SRandy Cushman }
230967e9f4b6SRandy Cushman 
231067e9f4b6SRandy Cushman static int snd_ac97_ad1986_vrefout_get(struct snd_kcontrol *kcontrol,
231167e9f4b6SRandy Cushman 				       struct snd_ctl_elem_value *ucontrol)
231267e9f4b6SRandy Cushman {
231367e9f4b6SRandy Cushman 	/* Use MIC_1/2 V_REFOUT as the "get" value */
231467e9f4b6SRandy Cushman 	struct snd_ac97 *ac97 = snd_kcontrol_chip(kcontrol);
231567e9f4b6SRandy Cushman 	unsigned short val;
231667e9f4b6SRandy Cushman 	unsigned short reg = ac97->regs[AC97_AD_MISC2];
231767e9f4b6SRandy Cushman 	if ((reg & AC97_AD1986_MVREF0) != 0)
231867e9f4b6SRandy Cushman 		val = 2;
231967e9f4b6SRandy Cushman 	else if ((reg & AC97_AD1986_MVREF1) != 0)
232067e9f4b6SRandy Cushman 		val = 3;
232167e9f4b6SRandy Cushman 	else if ((reg & AC97_AD1986_MVREF2) != 0)
232267e9f4b6SRandy Cushman 		val = 1;
232367e9f4b6SRandy Cushman 	else
232467e9f4b6SRandy Cushman 		val = 0;
232567e9f4b6SRandy Cushman 	ucontrol->value.enumerated.item[0] = val;
232667e9f4b6SRandy Cushman 	return 0;
232767e9f4b6SRandy Cushman }
232867e9f4b6SRandy Cushman 
232967e9f4b6SRandy Cushman static int snd_ac97_ad1986_vrefout_put(struct snd_kcontrol *kcontrol,
233067e9f4b6SRandy Cushman 				       struct snd_ctl_elem_value *ucontrol)
233167e9f4b6SRandy Cushman {
233267e9f4b6SRandy Cushman 	struct snd_ac97 *ac97 = snd_kcontrol_chip(kcontrol);
233367e9f4b6SRandy Cushman 	unsigned short cval;
233467e9f4b6SRandy Cushman 	unsigned short lval;
233567e9f4b6SRandy Cushman 	unsigned short mval;
233667e9f4b6SRandy Cushman 	int cret;
233767e9f4b6SRandy Cushman 	int lret;
233867e9f4b6SRandy Cushman 	int mret;
233967e9f4b6SRandy Cushman 
234067e9f4b6SRandy Cushman 	switch (ucontrol->value.enumerated.item[0])
234167e9f4b6SRandy Cushman 	{
234267e9f4b6SRandy Cushman 	case 0: /* High-Z */
234367e9f4b6SRandy Cushman 		cval = 0;
234467e9f4b6SRandy Cushman 		lval = 0;
234567e9f4b6SRandy Cushman 		mval = 0;
234667e9f4b6SRandy Cushman 		break;
234767e9f4b6SRandy Cushman 	case 1: /* 3.7 V */
234867e9f4b6SRandy Cushman 		cval = AC97_AD1986_CVREF2;
234967e9f4b6SRandy Cushman 		lval = AC97_AD1986_LVREF2;
235067e9f4b6SRandy Cushman 		mval = AC97_AD1986_MVREF2;
235167e9f4b6SRandy Cushman 		break;
235267e9f4b6SRandy Cushman 	case 2: /* 2.25 V */
235367e9f4b6SRandy Cushman 		cval = AC97_AD1986_CVREF0;
235467e9f4b6SRandy Cushman 		lval = AC97_AD1986_LVREF0;
235567e9f4b6SRandy Cushman 		mval = AC97_AD1986_MVREF0;
235667e9f4b6SRandy Cushman 		break;
235767e9f4b6SRandy Cushman 	case 3: /* 0 V */
235867e9f4b6SRandy Cushman 		cval = AC97_AD1986_CVREF1;
235967e9f4b6SRandy Cushman 		lval = AC97_AD1986_LVREF1;
236067e9f4b6SRandy Cushman 		mval = AC97_AD1986_MVREF1;
236167e9f4b6SRandy Cushman 		break;
236267e9f4b6SRandy Cushman 	default:
236367e9f4b6SRandy Cushman 		return -EINVAL;
236467e9f4b6SRandy Cushman 	}
236567e9f4b6SRandy Cushman 
236667e9f4b6SRandy Cushman 	cret = snd_ac97_update_bits(ac97, AC97_AD_MISC2,
236767e9f4b6SRandy Cushman 				    AC97_AD1986_CVREF_MASK, cval);
236867e9f4b6SRandy Cushman 	if (cret < 0)
236967e9f4b6SRandy Cushman 		return cret;
237067e9f4b6SRandy Cushman 	lret = snd_ac97_update_bits(ac97, AC97_AD_MISC3,
237167e9f4b6SRandy Cushman 				    AC97_AD1986_LVREF_MASK, lval);
237267e9f4b6SRandy Cushman 	if (lret < 0)
237367e9f4b6SRandy Cushman 		return lret;
237467e9f4b6SRandy Cushman 	mret = snd_ac97_update_bits(ac97, AC97_AD_MISC2,
237567e9f4b6SRandy Cushman 				    AC97_AD1986_MVREF_MASK, mval);
237667e9f4b6SRandy Cushman 	if (mret < 0)
237767e9f4b6SRandy Cushman 		return mret;
237867e9f4b6SRandy Cushman 
237967e9f4b6SRandy Cushman 	return (cret > 0 || lret > 0 || mret > 0) ? 1 : 0;
238067e9f4b6SRandy Cushman }
238167e9f4b6SRandy Cushman 
238267e9f4b6SRandy Cushman static const struct snd_kcontrol_new snd_ac97_ad1986_controls[] = {
238367e9f4b6SRandy Cushman 	AC97_SINGLE("Exchange Center/LFE", AC97_AD_SERIAL_CFG, 3, 1, 0),
238467e9f4b6SRandy Cushman 	{
238567e9f4b6SRandy Cushman 		.iface = SNDRV_CTL_ELEM_IFACE_MIXER,
238667e9f4b6SRandy Cushman 		.name = "Exchange Front/Surround",
238767e9f4b6SRandy Cushman 		.info = snd_ac97_ad1986_bool_info,
238867e9f4b6SRandy Cushman 		.get = snd_ac97_ad1986_lososel_get,
238967e9f4b6SRandy Cushman 		.put = snd_ac97_ad1986_lososel_put
239067e9f4b6SRandy Cushman 	},
239167e9f4b6SRandy Cushman 	{
239267e9f4b6SRandy Cushman 		.iface = SNDRV_CTL_ELEM_IFACE_MIXER,
239367e9f4b6SRandy Cushman 		.name = "Exchange Mic/Line In",
239467e9f4b6SRandy Cushman 		.info = snd_ac97_ad1986_bool_info,
239567e9f4b6SRandy Cushman 		.get = snd_ac97_ad1986_miclisel_get,
239667e9f4b6SRandy Cushman 		.put = snd_ac97_ad1986_miclisel_put
239767e9f4b6SRandy Cushman 	},
239867e9f4b6SRandy Cushman 	{
239967e9f4b6SRandy Cushman 		.iface = SNDRV_CTL_ELEM_IFACE_MIXER,
240067e9f4b6SRandy Cushman 		.name = "Spread Front to Surround and Center/LFE",
240167e9f4b6SRandy Cushman 		.info = snd_ac97_ad1986_bool_info,
240267e9f4b6SRandy Cushman 		.get = snd_ac97_ad1986_spread_get,
240367e9f4b6SRandy Cushman 		.put = snd_ac97_ad1986_spread_put
240467e9f4b6SRandy Cushman 	},
240567e9f4b6SRandy Cushman 	{
240667e9f4b6SRandy Cushman 		.iface = SNDRV_CTL_ELEM_IFACE_MIXER,
240767e9f4b6SRandy Cushman 		.name = "Downmix",
240867e9f4b6SRandy Cushman 		.info = snd_ac97_ad1888_downmix_info,
240967e9f4b6SRandy Cushman 		.get = snd_ac97_ad1888_downmix_get,
241067e9f4b6SRandy Cushman 		.put = snd_ac97_ad1888_downmix_put
241167e9f4b6SRandy Cushman 	},
241267e9f4b6SRandy Cushman 	{
241367e9f4b6SRandy Cushman 		.iface = SNDRV_CTL_ELEM_IFACE_MIXER,
241467e9f4b6SRandy Cushman 		.name = "V_REFOUT",
241567e9f4b6SRandy Cushman 		.info = snd_ac97_ad1985_vrefout_info,
241667e9f4b6SRandy Cushman 		.get = snd_ac97_ad1986_vrefout_get,
241767e9f4b6SRandy Cushman 		.put = snd_ac97_ad1986_vrefout_put
241867e9f4b6SRandy Cushman 	},
241967e9f4b6SRandy Cushman 	AC97_SURROUND_JACK_MODE_CTL,
242067e9f4b6SRandy Cushman 	AC97_CHANNEL_MODE_CTL,
242167e9f4b6SRandy Cushman 
242267e9f4b6SRandy Cushman 	AC97_SINGLE("Headphone Jack Sense", AC97_AD_JACK_SPDIF, 10, 1, 0),
242367e9f4b6SRandy Cushman 	AC97_SINGLE("Line Jack Sense", AC97_AD_JACK_SPDIF, 12, 1, 0)
242467e9f4b6SRandy Cushman };
242567e9f4b6SRandy Cushman 
242667e9f4b6SRandy Cushman static void ad1986_update_jacks(struct snd_ac97 *ac97)
242767e9f4b6SRandy Cushman {
242867e9f4b6SRandy Cushman 	unsigned short misc_val = 0;
242967e9f4b6SRandy Cushman 	unsigned short ser_val;
243067e9f4b6SRandy Cushman 
243167e9f4b6SRandy Cushman 	/* disable SURROUND and CENTER/LFE if not surround mode */
243267e9f4b6SRandy Cushman 	if (!is_surround_on(ac97))
243367e9f4b6SRandy Cushman 		misc_val |= AC97_AD1986_SODIS;
243467e9f4b6SRandy Cushman 	if (!is_clfe_on(ac97))
243567e9f4b6SRandy Cushman 		misc_val |= AC97_AD1986_CLDIS;
243667e9f4b6SRandy Cushman 
243767e9f4b6SRandy Cushman 	/* select line input (default=LINE_IN, SURROUND or MIC_1/2) */
243867e9f4b6SRandy Cushman 	if (is_shared_linein(ac97))
243967e9f4b6SRandy Cushman 		misc_val |= AC97_AD1986_LISEL_SURR;
244067e9f4b6SRandy Cushman 	else if (ac97->spec.ad18xx.swap_mic_linein != 0)
244167e9f4b6SRandy Cushman 		misc_val |= AC97_AD1986_LISEL_MIC;
244267e9f4b6SRandy Cushman 	snd_ac97_update_bits(ac97, AC97_AD_MISC,
244367e9f4b6SRandy Cushman 			     AC97_AD1986_SODIS | AC97_AD1986_CLDIS |
244467e9f4b6SRandy Cushman 			     AC97_AD1986_LISEL_MASK,
244567e9f4b6SRandy Cushman 			     misc_val);
244667e9f4b6SRandy Cushman 
244767e9f4b6SRandy Cushman 	/* select microphone input (MIC_1/2, Center/LFE or LINE_IN) */
244867e9f4b6SRandy Cushman 	if (is_shared_micin(ac97))
244967e9f4b6SRandy Cushman 		ser_val = AC97_AD1986_OMS_C;
245067e9f4b6SRandy Cushman 	else if (ac97->spec.ad18xx.swap_mic_linein != 0)
245167e9f4b6SRandy Cushman 		ser_val = AC97_AD1986_OMS_L;
245267e9f4b6SRandy Cushman 	else
245367e9f4b6SRandy Cushman 		ser_val = AC97_AD1986_OMS_M;
245467e9f4b6SRandy Cushman 	snd_ac97_update_bits(ac97, AC97_AD_SERIAL_CFG,
245567e9f4b6SRandy Cushman 			     AC97_AD1986_OMS_MASK,
245667e9f4b6SRandy Cushman 			     ser_val);
245767e9f4b6SRandy Cushman }
245867e9f4b6SRandy Cushman 
245967e9f4b6SRandy Cushman static int patch_ad1986_specific(struct snd_ac97 *ac97)
246067e9f4b6SRandy Cushman {
246167e9f4b6SRandy Cushman 	int err;
246267e9f4b6SRandy Cushman 
246367e9f4b6SRandy Cushman 	if ((err = patch_build_controls(ac97, &snd_ac97_ad198x_2cmic, 1)) < 0)
246467e9f4b6SRandy Cushman 		return err;
246567e9f4b6SRandy Cushman 
246667e9f4b6SRandy Cushman 	return patch_build_controls(ac97, snd_ac97_ad1986_controls,
246767e9f4b6SRandy Cushman 				    ARRAY_SIZE(snd_ac97_ad1985_controls));
246867e9f4b6SRandy Cushman }
246967e9f4b6SRandy Cushman 
24703e8b3b90SHanno Boeck static const struct snd_ac97_build_ops patch_ad1986_build_ops = {
247167e9f4b6SRandy Cushman 	.build_post_spdif = patch_ad198x_post_spdif,
247267e9f4b6SRandy Cushman 	.build_specific = patch_ad1986_specific,
247367e9f4b6SRandy Cushman #ifdef CONFIG_PM
247467e9f4b6SRandy Cushman 	.resume = ad18xx_resume,
247567e9f4b6SRandy Cushman #endif
247667e9f4b6SRandy Cushman 	.update_jacks = ad1986_update_jacks,
247767e9f4b6SRandy Cushman };
247867e9f4b6SRandy Cushman 
2479ac519028STakashi Iwai static int patch_ad1986(struct snd_ac97 * ac97)
248067e9f4b6SRandy Cushman {
248167e9f4b6SRandy Cushman 	patch_ad1881(ac97);
248267e9f4b6SRandy Cushman 	ac97->build_ops = &patch_ad1986_build_ops;
248367e9f4b6SRandy Cushman 	ac97->flags |= AC97_STEREO_MUTES;
248467e9f4b6SRandy Cushman 
248567e9f4b6SRandy Cushman 	/* update current jack configuration */
248667e9f4b6SRandy Cushman 	ad1986_update_jacks(ac97);
248767e9f4b6SRandy Cushman 
248867e9f4b6SRandy Cushman 	return 0;
248967e9f4b6SRandy Cushman }
249067e9f4b6SRandy Cushman 
24918f4f4ef6STakashi Iwai /*
24928f4f4ef6STakashi Iwai  * realtek ALC203: use mono-out for pin 37
24938f4f4ef6STakashi Iwai  */
24948f4f4ef6STakashi Iwai static int patch_alc203(struct snd_ac97 *ac97)
24958f4f4ef6STakashi Iwai {
24968f4f4ef6STakashi Iwai 	snd_ac97_update_bits(ac97, 0x7a, 0x400, 0x400);
24978f4f4ef6STakashi Iwai 	return 0;
24988f4f4ef6STakashi Iwai }
249967e9f4b6SRandy Cushman 
25001da177e4SLinus Torvalds /*
25011da177e4SLinus Torvalds  * realtek ALC65x/850 codecs
25021da177e4SLinus Torvalds  */
2503ee42381eSTakashi Iwai static void alc650_update_jacks(struct snd_ac97 *ac97)
25041da177e4SLinus Torvalds {
2505eb8caf30STakashi Iwai 	int shared;
25061da177e4SLinus Torvalds 
2507831466f4SRandy Cushman 	/* shared Line-In / Surround Out */
2508831466f4SRandy Cushman 	shared = is_shared_surrout(ac97);
2509eb8caf30STakashi Iwai 	snd_ac97_update_bits(ac97, AC97_ALC650_MULTICH, 1 << 9,
2510eb8caf30STakashi Iwai 			     shared ? (1 << 9) : 0);
2511831466f4SRandy Cushman 	/* update shared Mic In / Center/LFE Out */
2512831466f4SRandy Cushman 	shared = is_shared_clfeout(ac97);
25131da177e4SLinus Torvalds 	/* disable/enable vref */
25141da177e4SLinus Torvalds 	snd_ac97_update_bits(ac97, AC97_ALC650_CLOCK, 1 << 12,
2515eb8caf30STakashi Iwai 			     shared ? (1 << 12) : 0);
25161da177e4SLinus Torvalds 	/* turn on/off center-on-mic */
25171da177e4SLinus Torvalds 	snd_ac97_update_bits(ac97, AC97_ALC650_MULTICH, 1 << 10,
2518eb8caf30STakashi Iwai 			     shared ? (1 << 10) : 0);
25191da177e4SLinus Torvalds 	/* GPIO0 high for mic */
25201da177e4SLinus Torvalds 	snd_ac97_update_bits(ac97, AC97_ALC650_GPIO_STATUS, 0x100,
2521eb8caf30STakashi Iwai 			     shared ? 0 : 0x100);
25221da177e4SLinus Torvalds }
25231da177e4SLinus Torvalds 
2524833a493bSTakashi Iwai static int alc650_swap_surround_put(struct snd_kcontrol *kcontrol,
2525833a493bSTakashi Iwai 				    struct snd_ctl_elem_value *ucontrol)
2526833a493bSTakashi Iwai {
2527833a493bSTakashi Iwai 	struct snd_ac97 *ac97 = snd_kcontrol_chip(kcontrol);
2528833a493bSTakashi Iwai 	struct snd_pcm_chmap *map = ac97->chmaps[SNDRV_PCM_STREAM_PLAYBACK];
2529833a493bSTakashi Iwai 
2530833a493bSTakashi Iwai 	if (map) {
2531833a493bSTakashi Iwai 		if (ucontrol->value.integer.value[0])
2532833a493bSTakashi Iwai 			map->chmap = snd_pcm_std_chmaps;
2533833a493bSTakashi Iwai 		else
2534833a493bSTakashi Iwai 			map->chmap = snd_pcm_alt_chmaps;
2535833a493bSTakashi Iwai 	}
2536833a493bSTakashi Iwai 	return snd_ac97_put_volsw(kcontrol, ucontrol);
2537833a493bSTakashi Iwai }
2538833a493bSTakashi Iwai 
2539ee42381eSTakashi Iwai static const struct snd_kcontrol_new snd_ac97_controls_alc650[] = {
25401da177e4SLinus Torvalds 	AC97_SINGLE("Duplicate Front", AC97_ALC650_MULTICH, 0, 1, 0),
25411da177e4SLinus Torvalds 	AC97_SINGLE("Surround Down Mix", AC97_ALC650_MULTICH, 1, 1, 0),
25421da177e4SLinus Torvalds 	AC97_SINGLE("Center/LFE Down Mix", AC97_ALC650_MULTICH, 2, 1, 0),
25431da177e4SLinus Torvalds 	AC97_SINGLE("Exchange Center/LFE", AC97_ALC650_MULTICH, 3, 1, 0),
25441da177e4SLinus Torvalds 	/* 4: Analog Input To Surround */
25451da177e4SLinus Torvalds 	/* 5: Analog Input To Center/LFE */
25461da177e4SLinus Torvalds 	/* 6: Independent Master Volume Right */
25471da177e4SLinus Torvalds 	/* 7: Independent Master Volume Left */
25481da177e4SLinus Torvalds 	/* 8: reserved */
2549eb8caf30STakashi Iwai 	/* 9: Line-In/Surround share */
2550eb8caf30STakashi Iwai 	/* 10: Mic/CLFE share */
25511da177e4SLinus Torvalds 	/* 11-13: in IEC958 controls */
2552833a493bSTakashi Iwai 	{
2553833a493bSTakashi Iwai 		.iface = SNDRV_CTL_ELEM_IFACE_MIXER,
2554833a493bSTakashi Iwai 		.name = "Swap Surround Slot",
2555833a493bSTakashi Iwai 		.info = snd_ac97_info_volsw,
2556833a493bSTakashi Iwai 		.get = snd_ac97_get_volsw,
2557833a493bSTakashi Iwai 		.put = alc650_swap_surround_put,
2558833a493bSTakashi Iwai 		.private_value =  AC97_SINGLE_VALUE(AC97_ALC650_MULTICH, 14, 1, 0),
2559833a493bSTakashi Iwai 	},
25601da177e4SLinus Torvalds #if 0 /* always set in patch_alc650 */
25611da177e4SLinus Torvalds 	AC97_SINGLE("IEC958 Input Clock Enable", AC97_ALC650_CLOCK, 0, 1, 0),
25621da177e4SLinus Torvalds 	AC97_SINGLE("IEC958 Input Pin Enable", AC97_ALC650_CLOCK, 1, 1, 0),
25631da177e4SLinus Torvalds 	AC97_SINGLE("Surround DAC Switch", AC97_ALC650_SURR_DAC_VOL, 15, 1, 1),
25641da177e4SLinus Torvalds 	AC97_DOUBLE("Surround DAC Volume", AC97_ALC650_SURR_DAC_VOL, 8, 0, 31, 1),
25651da177e4SLinus Torvalds 	AC97_SINGLE("Center/LFE DAC Switch", AC97_ALC650_LFE_DAC_VOL, 15, 1, 1),
25661da177e4SLinus Torvalds 	AC97_DOUBLE("Center/LFE DAC Volume", AC97_ALC650_LFE_DAC_VOL, 8, 0, 31, 1),
25671da177e4SLinus Torvalds #endif
2568eb8caf30STakashi Iwai 	AC97_SURROUND_JACK_MODE_CTL,
2569eb8caf30STakashi Iwai 	AC97_CHANNEL_MODE_CTL,
25701da177e4SLinus Torvalds };
25711da177e4SLinus Torvalds 
2572ee42381eSTakashi Iwai static const struct snd_kcontrol_new snd_ac97_spdif_controls_alc650[] = {
257310e8d78aSClemens Ladisch         AC97_SINGLE(SNDRV_CTL_NAME_IEC958("",CAPTURE,SWITCH), AC97_ALC650_MULTICH, 11, 1, 0),
25741da177e4SLinus Torvalds         AC97_SINGLE("Analog to IEC958 Output", AC97_ALC650_MULTICH, 12, 1, 0),
25751da177e4SLinus Torvalds 	/* disable this controls since it doesn't work as expected */
25761da177e4SLinus Torvalds 	/* AC97_SINGLE("IEC958 Input Monitor", AC97_ALC650_MULTICH, 13, 1, 0), */
25771da177e4SLinus Torvalds };
25781da177e4SLinus Torvalds 
25790cb29ea0STakashi Iwai static const DECLARE_TLV_DB_SCALE(db_scale_5bit_3db_max, -4350, 150, 0);
25802f3482fbSTakashi Iwai 
2581ee42381eSTakashi Iwai static int patch_alc650_specific(struct snd_ac97 * ac97)
25821da177e4SLinus Torvalds {
25831da177e4SLinus Torvalds 	int err;
25841da177e4SLinus Torvalds 
25851da177e4SLinus Torvalds 	if ((err = patch_build_controls(ac97, snd_ac97_controls_alc650, ARRAY_SIZE(snd_ac97_controls_alc650))) < 0)
25861da177e4SLinus Torvalds 		return err;
25871da177e4SLinus Torvalds 	if (ac97->ext_id & AC97_EI_SPDIF) {
25881da177e4SLinus Torvalds 		if ((err = patch_build_controls(ac97, snd_ac97_spdif_controls_alc650, ARRAY_SIZE(snd_ac97_spdif_controls_alc650))) < 0)
25891da177e4SLinus Torvalds 			return err;
25901da177e4SLinus Torvalds 	}
25912f3482fbSTakashi Iwai 	if (ac97->id != AC97_ID_ALC650F)
25922f3482fbSTakashi Iwai 		reset_tlv(ac97, "Master Playback Volume",
25932f3482fbSTakashi Iwai 			  db_scale_5bit_3db_max);
25941da177e4SLinus Torvalds 	return 0;
25951da177e4SLinus Torvalds }
25961da177e4SLinus Torvalds 
25973e8b3b90SHanno Boeck static const struct snd_ac97_build_ops patch_alc650_ops = {
2598eb8caf30STakashi Iwai 	.build_specific	= patch_alc650_specific,
2599eb8caf30STakashi Iwai 	.update_jacks = alc650_update_jacks
26001da177e4SLinus Torvalds };
26011da177e4SLinus Torvalds 
2602ac519028STakashi Iwai static int patch_alc650(struct snd_ac97 * ac97)
26031da177e4SLinus Torvalds {
26041da177e4SLinus Torvalds 	unsigned short val;
26051da177e4SLinus Torvalds 
26061da177e4SLinus Torvalds 	ac97->build_ops = &patch_alc650_ops;
26071da177e4SLinus Torvalds 
26081da177e4SLinus Torvalds 	/* determine the revision */
26091da177e4SLinus Torvalds 	val = snd_ac97_read(ac97, AC97_ALC650_REVISION) & 0x3f;
26101da177e4SLinus Torvalds 	if (val < 3)
26111da177e4SLinus Torvalds 		ac97->id = 0x414c4720;          /* Old version */
26121da177e4SLinus Torvalds 	else if (val < 0x10)
26131da177e4SLinus Torvalds 		ac97->id = 0x414c4721;          /* D version */
26141da177e4SLinus Torvalds 	else if (val < 0x20)
26151da177e4SLinus Torvalds 		ac97->id = 0x414c4722;          /* E version */
26161da177e4SLinus Torvalds 	else if (val < 0x30)
26171da177e4SLinus Torvalds 		ac97->id = 0x414c4723;          /* F version */
26181da177e4SLinus Torvalds 
26191da177e4SLinus Torvalds 	/* revision E or F */
26201da177e4SLinus Torvalds 	/* FIXME: what about revision D ? */
26211da177e4SLinus Torvalds 	ac97->spec.dev_flags = (ac97->id == 0x414c4722 ||
26221da177e4SLinus Torvalds 				ac97->id == 0x414c4723);
26231da177e4SLinus Torvalds 
26241da177e4SLinus Torvalds 	/* enable AC97_ALC650_GPIO_SETUP, AC97_ALC650_CLOCK for R/W */
26251da177e4SLinus Torvalds 	snd_ac97_write_cache(ac97, AC97_ALC650_GPIO_STATUS,
26261da177e4SLinus Torvalds 		snd_ac97_read(ac97, AC97_ALC650_GPIO_STATUS) | 0x8000);
26271da177e4SLinus Torvalds 
26281da177e4SLinus Torvalds 	/* Enable SPDIF-IN only on Rev.E and above */
26291da177e4SLinus Torvalds 	val = snd_ac97_read(ac97, AC97_ALC650_CLOCK);
26301da177e4SLinus Torvalds 	/* SPDIF IN with pin 47 */
2631eed65649STakashi Iwai 	if (ac97->spec.dev_flags &&
2632eed65649STakashi Iwai 	    /* ASUS A6KM requires EAPD */
2633eed65649STakashi Iwai 	    ! (ac97->subsystem_vendor == 0x1043 &&
2634eed65649STakashi Iwai 	       ac97->subsystem_device == 0x1103))
26351da177e4SLinus Torvalds 		val |= 0x03; /* enable */
26361da177e4SLinus Torvalds 	else
26371da177e4SLinus Torvalds 		val &= ~0x03; /* disable */
26381da177e4SLinus Torvalds 	snd_ac97_write_cache(ac97, AC97_ALC650_CLOCK, val);
26391da177e4SLinus Torvalds 
26401da177e4SLinus Torvalds 	/* set default: slot 3,4,7,8,6,9
26411da177e4SLinus Torvalds 	   spdif-in monitor off, analog-spdif off, spdif-in off
26421da177e4SLinus Torvalds 	   center on mic off, surround on line-in off
26431da177e4SLinus Torvalds 	   downmix off, duplicate front off
26441da177e4SLinus Torvalds 	*/
26451da177e4SLinus Torvalds 	snd_ac97_write_cache(ac97, AC97_ALC650_MULTICH, 0);
26461da177e4SLinus Torvalds 
26471da177e4SLinus Torvalds 	/* set GPIO0 for mic bias */
26481da177e4SLinus Torvalds 	/* GPIO0 pin output, no interrupt, high */
26491da177e4SLinus Torvalds 	snd_ac97_write_cache(ac97, AC97_ALC650_GPIO_SETUP,
26501da177e4SLinus Torvalds 			     snd_ac97_read(ac97, AC97_ALC650_GPIO_SETUP) | 0x01);
26511da177e4SLinus Torvalds 	snd_ac97_write_cache(ac97, AC97_ALC650_GPIO_STATUS,
26521da177e4SLinus Torvalds 			     (snd_ac97_read(ac97, AC97_ALC650_GPIO_STATUS) | 0x100) & ~0x10);
26531da177e4SLinus Torvalds 
26541da177e4SLinus Torvalds 	/* full DAC volume */
26551da177e4SLinus Torvalds 	snd_ac97_write_cache(ac97, AC97_ALC650_SURR_DAC_VOL, 0x0808);
26561da177e4SLinus Torvalds 	snd_ac97_write_cache(ac97, AC97_ALC650_LFE_DAC_VOL, 0x0808);
26571da177e4SLinus Torvalds 	return 0;
26581da177e4SLinus Torvalds }
26591da177e4SLinus Torvalds 
2660ee42381eSTakashi Iwai static void alc655_update_jacks(struct snd_ac97 *ac97)
26611da177e4SLinus Torvalds {
2662eb8caf30STakashi Iwai 	int shared;
26631da177e4SLinus Torvalds 
2664831466f4SRandy Cushman 	/* shared Line-In / Surround Out */
2665831466f4SRandy Cushman 	shared = is_shared_surrout(ac97);
2666eb8caf30STakashi Iwai 	ac97_update_bits_page(ac97, AC97_ALC650_MULTICH, 1 << 9,
2667eb8caf30STakashi Iwai 			      shared ? (1 << 9) : 0, 0);
2668831466f4SRandy Cushman 	/* update shared Mic In / Center/LFE Out */
2669831466f4SRandy Cushman 	shared = is_shared_clfeout(ac97);
26701da177e4SLinus Torvalds 	/* misc control; vrefout disable */
26711da177e4SLinus Torvalds 	snd_ac97_update_bits(ac97, AC97_ALC650_CLOCK, 1 << 12,
2672eb8caf30STakashi Iwai 			     shared ? (1 << 12) : 0);
2673eb8caf30STakashi Iwai 	ac97_update_bits_page(ac97, AC97_ALC650_MULTICH, 1 << 10,
2674eb8caf30STakashi Iwai 			      shared ? (1 << 10) : 0, 0);
26751da177e4SLinus Torvalds }
26761da177e4SLinus Torvalds 
2677ee42381eSTakashi Iwai static const struct snd_kcontrol_new snd_ac97_controls_alc655[] = {
26781da177e4SLinus Torvalds 	AC97_PAGE_SINGLE("Duplicate Front", AC97_ALC650_MULTICH, 0, 1, 0, 0),
2679eb8caf30STakashi Iwai 	AC97_SURROUND_JACK_MODE_CTL,
2680eb8caf30STakashi Iwai 	AC97_CHANNEL_MODE_CTL,
26811da177e4SLinus Torvalds };
26821da177e4SLinus Torvalds 
2683ee42381eSTakashi Iwai static int alc655_iec958_route_info(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_info *uinfo)
26841da177e4SLinus Torvalds {
26853b7a00dcSTakashi Iwai 	static const char * const texts_655[3] = {
26863b7a00dcSTakashi Iwai 		"PCM", "Analog In", "IEC958 In"
26873b7a00dcSTakashi Iwai 	};
26883b7a00dcSTakashi Iwai 	static const char * const texts_658[4] = {
26893b7a00dcSTakashi Iwai 		"PCM", "Analog1 In", "Analog2 In", "IEC958 In"
26903b7a00dcSTakashi Iwai 	};
2691ee42381eSTakashi Iwai 	struct snd_ac97 *ac97 = snd_kcontrol_chip(kcontrol);
26921da177e4SLinus Torvalds 
26933b7a00dcSTakashi Iwai 	if (ac97->spec.dev_flags)
26943b7a00dcSTakashi Iwai 		return snd_ctl_enum_info(uinfo, 1, 4, texts_658);
26953b7a00dcSTakashi Iwai 	else
26963b7a00dcSTakashi Iwai 		return snd_ctl_enum_info(uinfo, 1, 3, texts_655);
26971da177e4SLinus Torvalds }
26981da177e4SLinus Torvalds 
2699ee42381eSTakashi Iwai static int alc655_iec958_route_get(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
27001da177e4SLinus Torvalds {
2701ee42381eSTakashi Iwai 	struct snd_ac97 *ac97 = snd_kcontrol_chip(kcontrol);
27021da177e4SLinus Torvalds 	unsigned short val;
27031da177e4SLinus Torvalds 
27041da177e4SLinus Torvalds 	val = ac97->regs[AC97_ALC650_MULTICH];
27051da177e4SLinus Torvalds 	val = (val >> 12) & 3;
27061da177e4SLinus Torvalds 	if (ac97->spec.dev_flags && val == 3)
27071da177e4SLinus Torvalds 		val = 0;
27081da177e4SLinus Torvalds 	ucontrol->value.enumerated.item[0] = val;
27091da177e4SLinus Torvalds 	return 0;
27101da177e4SLinus Torvalds }
27111da177e4SLinus Torvalds 
2712ee42381eSTakashi Iwai static int alc655_iec958_route_put(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
27131da177e4SLinus Torvalds {
2714ee42381eSTakashi Iwai 	struct snd_ac97 *ac97 = snd_kcontrol_chip(kcontrol);
27151da177e4SLinus Torvalds 
27161da177e4SLinus Torvalds 	return ac97_update_bits_page(ac97, AC97_ALC650_MULTICH, 3 << 12,
27171da177e4SLinus Torvalds 				     (unsigned short)ucontrol->value.enumerated.item[0] << 12,
27181da177e4SLinus Torvalds 				     0);
27191da177e4SLinus Torvalds }
27201da177e4SLinus Torvalds 
2721ee42381eSTakashi Iwai static const struct snd_kcontrol_new snd_ac97_spdif_controls_alc655[] = {
272210e8d78aSClemens Ladisch         AC97_PAGE_SINGLE(SNDRV_CTL_NAME_IEC958("",CAPTURE,SWITCH), AC97_ALC650_MULTICH, 11, 1, 0, 0),
27231da177e4SLinus Torvalds 	/* disable this controls since it doesn't work as expected */
27241da177e4SLinus Torvalds         /* AC97_PAGE_SINGLE("IEC958 Input Monitor", AC97_ALC650_MULTICH, 14, 1, 0, 0), */
27251da177e4SLinus Torvalds 	{
27261da177e4SLinus Torvalds 		.iface  = SNDRV_CTL_ELEM_IFACE_MIXER,
2727031c95d4STakashi Iwai 		.name   = SNDRV_CTL_NAME_IEC958("",PLAYBACK,NONE) "Source",
27281da177e4SLinus Torvalds 		.info   = alc655_iec958_route_info,
27291da177e4SLinus Torvalds 		.get    = alc655_iec958_route_get,
27301da177e4SLinus Torvalds 		.put    = alc655_iec958_route_put,
27311da177e4SLinus Torvalds 	},
27321da177e4SLinus Torvalds };
27331da177e4SLinus Torvalds 
2734ee42381eSTakashi Iwai static int patch_alc655_specific(struct snd_ac97 * ac97)
27351da177e4SLinus Torvalds {
27361da177e4SLinus Torvalds 	int err;
27371da177e4SLinus Torvalds 
27381da177e4SLinus Torvalds 	if ((err = patch_build_controls(ac97, snd_ac97_controls_alc655, ARRAY_SIZE(snd_ac97_controls_alc655))) < 0)
27391da177e4SLinus Torvalds 		return err;
27401da177e4SLinus Torvalds 	if (ac97->ext_id & AC97_EI_SPDIF) {
27411da177e4SLinus Torvalds 		if ((err = patch_build_controls(ac97, snd_ac97_spdif_controls_alc655, ARRAY_SIZE(snd_ac97_spdif_controls_alc655))) < 0)
27421da177e4SLinus Torvalds 			return err;
27431da177e4SLinus Torvalds 	}
27441da177e4SLinus Torvalds 	return 0;
27451da177e4SLinus Torvalds }
27461da177e4SLinus Torvalds 
27473e8b3b90SHanno Boeck static const struct snd_ac97_build_ops patch_alc655_ops = {
2748eb8caf30STakashi Iwai 	.build_specific	= patch_alc655_specific,
2749eb8caf30STakashi Iwai 	.update_jacks = alc655_update_jacks
27501da177e4SLinus Torvalds };
27511da177e4SLinus Torvalds 
2752ac519028STakashi Iwai static int patch_alc655(struct snd_ac97 * ac97)
27531da177e4SLinus Torvalds {
27541da177e4SLinus Torvalds 	unsigned int val;
27551da177e4SLinus Torvalds 
2756a5022b0dSTakashi Iwai 	if (ac97->id == AC97_ID_ALC658) {
2757a5022b0dSTakashi Iwai 		ac97->spec.dev_flags = 1; /* ALC658 */
2758a5022b0dSTakashi Iwai 		if ((snd_ac97_read(ac97, AC97_ALC650_REVISION) & 0x3f) == 2) {
2759a5022b0dSTakashi Iwai 			ac97->id = AC97_ID_ALC658D;
2760a5022b0dSTakashi Iwai 			ac97->spec.dev_flags = 2;
2761a5022b0dSTakashi Iwai 		}
2762a5022b0dSTakashi Iwai 	}
27631da177e4SLinus Torvalds 
27641da177e4SLinus Torvalds 	ac97->build_ops = &patch_alc655_ops;
27651da177e4SLinus Torvalds 
27661da177e4SLinus Torvalds 	/* assume only page 0 for writing cache */
27671da177e4SLinus Torvalds 	snd_ac97_update_bits(ac97, AC97_INT_PAGING, AC97_PAGE_MASK, AC97_PAGE_VENDOR);
27681da177e4SLinus Torvalds 
27691da177e4SLinus Torvalds 	/* adjust default values */
27701da177e4SLinus Torvalds 	val = snd_ac97_read(ac97, 0x7a); /* misc control */
2771a5022b0dSTakashi Iwai 	if (ac97->spec.dev_flags) /* ALC658 */
27721da177e4SLinus Torvalds 		val &= ~(1 << 1); /* Pin 47 is spdif input pin */
2773ee71508eSTakashi Iwai 	else { /* ALC655 */
2774ee71508eSTakashi Iwai 		if (ac97->subsystem_vendor == 0x1462 &&
2775d244bf89SMagnus Sandin 		    (ac97->subsystem_device == 0x0131 || /* MSI S270 laptop */
2776e7d24f0bSJaroslav Kysela 		     ac97->subsystem_device == 0x0161 || /* LG K1 Express */
2777cbcc2c4cSJerome Demange 		     ac97->subsystem_device == 0x0351 || /* MSI L725 laptop */
2778592a82e8STakashi Iwai 		     ac97->subsystem_device == 0x0471 || /* MSI L720 laptop */
2779cbcc2c4cSJerome Demange 		     ac97->subsystem_device == 0x0061))  /* MSI S250 laptop */
2780ee71508eSTakashi Iwai 			val &= ~(1 << 1); /* Pin 47 is EAPD (for internal speaker) */
2781ee71508eSTakashi Iwai 		else
27821da177e4SLinus Torvalds 			val |= (1 << 1); /* Pin 47 is spdif input pin */
2783c872e8caSTakashi Iwai 		/* this seems missing on some hardwares */
2784c872e8caSTakashi Iwai 		ac97->ext_id |= AC97_EI_SPDIF;
2785ee71508eSTakashi Iwai 	}
27861da177e4SLinus Torvalds 	val &= ~(1 << 12); /* vref enable */
27871da177e4SLinus Torvalds 	snd_ac97_write_cache(ac97, 0x7a, val);
27881da177e4SLinus Torvalds 	/* set default: spdif-in enabled,
27891da177e4SLinus Torvalds 	   spdif-in monitor off, spdif-in PCM off
27901da177e4SLinus Torvalds 	   center on mic off, surround on line-in off
27911da177e4SLinus Torvalds 	   duplicate front off
27921da177e4SLinus Torvalds 	*/
27931da177e4SLinus Torvalds 	snd_ac97_write_cache(ac97, AC97_ALC650_MULTICH, 1<<15);
27941da177e4SLinus Torvalds 
27951da177e4SLinus Torvalds 	/* full DAC volume */
27961da177e4SLinus Torvalds 	snd_ac97_write_cache(ac97, AC97_ALC650_SURR_DAC_VOL, 0x0808);
27971da177e4SLinus Torvalds 	snd_ac97_write_cache(ac97, AC97_ALC650_LFE_DAC_VOL, 0x0808);
2798a5022b0dSTakashi Iwai 
2799a5022b0dSTakashi Iwai 	/* update undocumented bit... */
2800a5022b0dSTakashi Iwai 	if (ac97->id == AC97_ID_ALC658D)
2801a5022b0dSTakashi Iwai 		snd_ac97_update_bits(ac97, 0x74, 0x0800, 0x0800);
2802a5022b0dSTakashi Iwai 
28031da177e4SLinus Torvalds 	return 0;
28041da177e4SLinus Torvalds }
28051da177e4SLinus Torvalds 
28061da177e4SLinus Torvalds 
28071da177e4SLinus Torvalds #define AC97_ALC850_JACK_SELECT	0x76
28081da177e4SLinus Torvalds #define AC97_ALC850_MISC1	0x7a
28094235a317STakashi Iwai #define AC97_ALC850_MULTICH    0x6a
28101da177e4SLinus Torvalds 
2811ee42381eSTakashi Iwai static void alc850_update_jacks(struct snd_ac97 *ac97)
28121da177e4SLinus Torvalds {
2813eb8caf30STakashi Iwai 	int shared;
28144235a317STakashi Iwai 	int aux_is_back_surround;
28151da177e4SLinus Torvalds 
2816831466f4SRandy Cushman 	/* shared Line-In / Surround Out */
2817831466f4SRandy Cushman 	shared = is_shared_surrout(ac97);
28181da177e4SLinus Torvalds 	/* SURR 1kOhm (bit4), Amp (bit5) */
28191da177e4SLinus Torvalds 	snd_ac97_update_bits(ac97, AC97_ALC850_MISC1, (1<<4)|(1<<5),
2820eb8caf30STakashi Iwai 			     shared ? (1<<5) : (1<<4));
28211da177e4SLinus Torvalds 	/* LINE-IN = 0, SURROUND = 2 */
2822eb8caf30STakashi Iwai 	snd_ac97_update_bits(ac97, AC97_ALC850_JACK_SELECT, 7 << 12,
2823eb8caf30STakashi Iwai 			     shared ? (2<<12) : (0<<12));
2824831466f4SRandy Cushman 	/* update shared Mic In / Center/LFE Out */
2825831466f4SRandy Cushman 	shared = is_shared_clfeout(ac97);
28261da177e4SLinus Torvalds 	/* Vref disable (bit12), 1kOhm (bit13) */
28271da177e4SLinus Torvalds 	snd_ac97_update_bits(ac97, AC97_ALC850_MISC1, (1<<12)|(1<<13),
2828eb8caf30STakashi Iwai 			     shared ? (1<<12) : (1<<13));
2829da79e44dSTakashi Iwai 	/* MIC-IN = 1, CENTER-LFE = 5 */
2830eb8caf30STakashi Iwai 	snd_ac97_update_bits(ac97, AC97_ALC850_JACK_SELECT, 7 << 4,
2831da79e44dSTakashi Iwai 			     shared ? (5<<4) : (1<<4));
28324235a317STakashi Iwai 
28334235a317STakashi Iwai 	aux_is_back_surround = alc850_is_aux_back_surround(ac97);
28344235a317STakashi Iwai 	/* Aux is Back Surround */
28354235a317STakashi Iwai 	snd_ac97_update_bits(ac97, AC97_ALC850_MULTICH, 1 << 10,
28364235a317STakashi Iwai 				 aux_is_back_surround ? (1<<10) : (0<<10));
28371da177e4SLinus Torvalds }
28381da177e4SLinus Torvalds 
2839ee42381eSTakashi Iwai static const struct snd_kcontrol_new snd_ac97_controls_alc850[] = {
28401da177e4SLinus Torvalds 	AC97_PAGE_SINGLE("Duplicate Front", AC97_ALC650_MULTICH, 0, 1, 0, 0),
284167e1b51eSSergey Vlasov 	AC97_SINGLE("Mic Front Input Switch", AC97_ALC850_JACK_SELECT, 15, 1, 1),
2842eb8caf30STakashi Iwai 	AC97_SURROUND_JACK_MODE_CTL,
28434235a317STakashi Iwai 	AC97_CHANNEL_MODE_8CH_CTL,
28441da177e4SLinus Torvalds };
28451da177e4SLinus Torvalds 
2846ee42381eSTakashi Iwai static int patch_alc850_specific(struct snd_ac97 *ac97)
28471da177e4SLinus Torvalds {
28481da177e4SLinus Torvalds 	int err;
28491da177e4SLinus Torvalds 
28501da177e4SLinus Torvalds 	if ((err = patch_build_controls(ac97, snd_ac97_controls_alc850, ARRAY_SIZE(snd_ac97_controls_alc850))) < 0)
28511da177e4SLinus Torvalds 		return err;
28521da177e4SLinus Torvalds 	if (ac97->ext_id & AC97_EI_SPDIF) {
28531da177e4SLinus Torvalds 		if ((err = patch_build_controls(ac97, snd_ac97_spdif_controls_alc655, ARRAY_SIZE(snd_ac97_spdif_controls_alc655))) < 0)
28541da177e4SLinus Torvalds 			return err;
28551da177e4SLinus Torvalds 	}
28561da177e4SLinus Torvalds 	return 0;
28571da177e4SLinus Torvalds }
28581da177e4SLinus Torvalds 
28593e8b3b90SHanno Boeck static const struct snd_ac97_build_ops patch_alc850_ops = {
2860eb8caf30STakashi Iwai 	.build_specific	= patch_alc850_specific,
2861eb8caf30STakashi Iwai 	.update_jacks = alc850_update_jacks
28621da177e4SLinus Torvalds };
28631da177e4SLinus Torvalds 
2864ac519028STakashi Iwai static int patch_alc850(struct snd_ac97 *ac97)
28651da177e4SLinus Torvalds {
28661da177e4SLinus Torvalds 	ac97->build_ops = &patch_alc850_ops;
28671da177e4SLinus Torvalds 
28681da177e4SLinus Torvalds 	ac97->spec.dev_flags = 0; /* for IEC958 playback route - ALC655 compatible */
28694235a317STakashi Iwai 	ac97->flags |= AC97_HAS_8CH;
28701da177e4SLinus Torvalds 
28711da177e4SLinus Torvalds 	/* assume only page 0 for writing cache */
28721da177e4SLinus Torvalds 	snd_ac97_update_bits(ac97, AC97_INT_PAGING, AC97_PAGE_MASK, AC97_PAGE_VENDOR);
28731da177e4SLinus Torvalds 
28741da177e4SLinus Torvalds 	/* adjust default values */
28751da177e4SLinus Torvalds 	/* set default: spdif-in enabled,
28761da177e4SLinus Torvalds 	   spdif-in monitor off, spdif-in PCM off
28771da177e4SLinus Torvalds 	   center on mic off, surround on line-in off
28781da177e4SLinus Torvalds 	   duplicate front off
28794235a317STakashi Iwai 	   NB default bit 10=0 = Aux is Capture, not Back Surround
28801da177e4SLinus Torvalds 	*/
28811da177e4SLinus Torvalds 	snd_ac97_write_cache(ac97, AC97_ALC650_MULTICH, 1<<15);
28821da177e4SLinus Torvalds 	/* SURR_OUT: on, Surr 1kOhm: on, Surr Amp: off, Front 1kOhm: off
28831da177e4SLinus Torvalds 	 * Front Amp: on, Vref: enable, Center 1kOhm: on, Mix: on
28841da177e4SLinus Torvalds 	 */
28851da177e4SLinus Torvalds 	snd_ac97_write_cache(ac97, 0x7a, (1<<1)|(1<<4)|(0<<5)|(1<<6)|
28861da177e4SLinus Torvalds 			     (1<<7)|(0<<12)|(1<<13)|(0<<14));
28871da177e4SLinus Torvalds 	/* detection UIO2,3: all path floating, UIO3: MIC, Vref2: disable,
28881da177e4SLinus Torvalds 	 * UIO1: FRONT, Vref3: disable, UIO3: LINE, Front-Mic: mute
28891da177e4SLinus Torvalds 	 */
28901da177e4SLinus Torvalds 	snd_ac97_write_cache(ac97, 0x76, (0<<0)|(0<<2)|(1<<4)|(1<<7)|(2<<8)|
28911da177e4SLinus Torvalds 			     (1<<11)|(0<<12)|(1<<15));
28921da177e4SLinus Torvalds 
28931da177e4SLinus Torvalds 	/* full DAC volume */
28941da177e4SLinus Torvalds 	snd_ac97_write_cache(ac97, AC97_ALC650_SURR_DAC_VOL, 0x0808);
28951da177e4SLinus Torvalds 	snd_ac97_write_cache(ac97, AC97_ALC650_LFE_DAC_VOL, 0x0808);
28961da177e4SLinus Torvalds 	return 0;
28971da177e4SLinus Torvalds }
28981da177e4SLinus Torvalds 
28996ba9256cSAndreas Mohr static int patch_aztech_azf3328_specific(struct snd_ac97 *ac97)
29006ba9256cSAndreas Mohr {
29016ba9256cSAndreas Mohr 	struct snd_kcontrol *kctl_3d_center =
29026ba9256cSAndreas Mohr 		snd_ac97_find_mixer_ctl(ac97, "3D Control - Center");
29036ba9256cSAndreas Mohr 	struct snd_kcontrol *kctl_3d_depth =
29046ba9256cSAndreas Mohr 		snd_ac97_find_mixer_ctl(ac97, "3D Control - Depth");
29056ba9256cSAndreas Mohr 
29066ba9256cSAndreas Mohr 	/*
29076ba9256cSAndreas Mohr 	 * 3D register is different from AC97 standard layout
29086ba9256cSAndreas Mohr 	 * (also do some renaming, to resemble Windows driver naming)
29096ba9256cSAndreas Mohr 	 */
29106ba9256cSAndreas Mohr 	if (kctl_3d_center) {
29116ba9256cSAndreas Mohr 		kctl_3d_center->private_value =
29126ba9256cSAndreas Mohr 			AC97_SINGLE_VALUE(AC97_3D_CONTROL, 1, 0x07, 0);
29136ba9256cSAndreas Mohr 		snd_ac97_rename_vol_ctl(ac97,
29146ba9256cSAndreas Mohr 			"3D Control - Center", "3D Control - Width"
29156ba9256cSAndreas Mohr 		);
29166ba9256cSAndreas Mohr 	}
29176ba9256cSAndreas Mohr 	if (kctl_3d_depth)
29186ba9256cSAndreas Mohr 		kctl_3d_depth->private_value =
29196ba9256cSAndreas Mohr 			AC97_SINGLE_VALUE(AC97_3D_CONTROL, 8, 0x03, 0);
29206ba9256cSAndreas Mohr 
29216ba9256cSAndreas Mohr 	/* Aztech Windows driver calls the
29226ba9256cSAndreas Mohr 	   equivalent control "Modem Playback", thus rename it: */
29236ba9256cSAndreas Mohr 	snd_ac97_rename_vol_ctl(ac97,
29246ba9256cSAndreas Mohr 		"Master Mono Playback", "Modem Playback"
29256ba9256cSAndreas Mohr 	);
29266ba9256cSAndreas Mohr 	snd_ac97_rename_vol_ctl(ac97,
29276ba9256cSAndreas Mohr 		"Headphone Playback", "FM Synth Playback"
29286ba9256cSAndreas Mohr 	);
29296ba9256cSAndreas Mohr 
29306ba9256cSAndreas Mohr 	return 0;
29316ba9256cSAndreas Mohr }
29326ba9256cSAndreas Mohr 
29336ba9256cSAndreas Mohr static const struct snd_ac97_build_ops patch_aztech_azf3328_ops = {
29346ba9256cSAndreas Mohr 	.build_specific	= patch_aztech_azf3328_specific
29356ba9256cSAndreas Mohr };
29366ba9256cSAndreas Mohr 
29376ba9256cSAndreas Mohr static int patch_aztech_azf3328(struct snd_ac97 *ac97)
29386ba9256cSAndreas Mohr {
29396ba9256cSAndreas Mohr 	ac97->build_ops = &patch_aztech_azf3328_ops;
29406ba9256cSAndreas Mohr 	return 0;
29416ba9256cSAndreas Mohr }
29421da177e4SLinus Torvalds 
29431da177e4SLinus Torvalds /*
29441da177e4SLinus Torvalds  * C-Media CM97xx codecs
29451da177e4SLinus Torvalds  */
2946ee42381eSTakashi Iwai static void cm9738_update_jacks(struct snd_ac97 *ac97)
2947eb8caf30STakashi Iwai {
2948831466f4SRandy Cushman 	/* shared Line-In / Surround Out */
2949eb8caf30STakashi Iwai 	snd_ac97_update_bits(ac97, AC97_CM9738_VENDOR_CTRL, 1 << 10,
2950831466f4SRandy Cushman 			     is_shared_surrout(ac97) ? (1 << 10) : 0);
2951eb8caf30STakashi Iwai }
2952eb8caf30STakashi Iwai 
2953ee42381eSTakashi Iwai static const struct snd_kcontrol_new snd_ac97_cm9738_controls[] = {
29541da177e4SLinus Torvalds 	AC97_SINGLE("Duplicate Front", AC97_CM9738_VENDOR_CTRL, 13, 1, 0),
2955eb8caf30STakashi Iwai 	AC97_SURROUND_JACK_MODE_CTL,
2956eb8caf30STakashi Iwai 	AC97_CHANNEL_MODE_4CH_CTL,
29571da177e4SLinus Torvalds };
29581da177e4SLinus Torvalds 
2959ee42381eSTakashi Iwai static int patch_cm9738_specific(struct snd_ac97 * ac97)
29601da177e4SLinus Torvalds {
29611da177e4SLinus Torvalds 	return patch_build_controls(ac97, snd_ac97_cm9738_controls, ARRAY_SIZE(snd_ac97_cm9738_controls));
29621da177e4SLinus Torvalds }
29631da177e4SLinus Torvalds 
29643e8b3b90SHanno Boeck static const struct snd_ac97_build_ops patch_cm9738_ops = {
2965eb8caf30STakashi Iwai 	.build_specific	= patch_cm9738_specific,
2966eb8caf30STakashi Iwai 	.update_jacks = cm9738_update_jacks
29671da177e4SLinus Torvalds };
29681da177e4SLinus Torvalds 
2969ac519028STakashi Iwai static int patch_cm9738(struct snd_ac97 * ac97)
29701da177e4SLinus Torvalds {
29711da177e4SLinus Torvalds 	ac97->build_ops = &patch_cm9738_ops;
29721da177e4SLinus Torvalds 	/* FIXME: can anyone confirm below? */
29731da177e4SLinus Torvalds 	/* CM9738 has no PCM volume although the register reacts */
29741da177e4SLinus Torvalds 	ac97->flags |= AC97_HAS_NO_PCM_VOL;
29751da177e4SLinus Torvalds 	snd_ac97_write_cache(ac97, AC97_PCM, 0x8000);
29761da177e4SLinus Torvalds 
29771da177e4SLinus Torvalds 	return 0;
29781da177e4SLinus Torvalds }
29791da177e4SLinus Torvalds 
2980ee42381eSTakashi Iwai static int snd_ac97_cmedia_spdif_playback_source_info(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_info *uinfo)
29811da177e4SLinus Torvalds {
29823b7a00dcSTakashi Iwai 	static const char * const texts[] = { "Analog", "Digital" };
29831da177e4SLinus Torvalds 
29843b7a00dcSTakashi Iwai 	return snd_ctl_enum_info(uinfo, 1, 2, texts);
29851da177e4SLinus Torvalds }
29861da177e4SLinus Torvalds 
2987ee42381eSTakashi Iwai static int snd_ac97_cmedia_spdif_playback_source_get(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
29881da177e4SLinus Torvalds {
2989ee42381eSTakashi Iwai 	struct snd_ac97 *ac97 = snd_kcontrol_chip(kcontrol);
29901da177e4SLinus Torvalds 	unsigned short val;
29911da177e4SLinus Torvalds 
29921da177e4SLinus Torvalds 	val = ac97->regs[AC97_CM9739_SPDIF_CTRL];
29931da177e4SLinus Torvalds 	ucontrol->value.enumerated.item[0] = (val >> 1) & 0x01;
29941da177e4SLinus Torvalds 	return 0;
29951da177e4SLinus Torvalds }
29961da177e4SLinus Torvalds 
2997ee42381eSTakashi Iwai static int snd_ac97_cmedia_spdif_playback_source_put(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
29981da177e4SLinus Torvalds {
2999ee42381eSTakashi Iwai 	struct snd_ac97 *ac97 = snd_kcontrol_chip(kcontrol);
30001da177e4SLinus Torvalds 
30011da177e4SLinus Torvalds 	return snd_ac97_update_bits(ac97, AC97_CM9739_SPDIF_CTRL,
30021da177e4SLinus Torvalds 				    0x01 << 1,
30031da177e4SLinus Torvalds 				    (ucontrol->value.enumerated.item[0] & 0x01) << 1);
30041da177e4SLinus Torvalds }
30051da177e4SLinus Torvalds 
3006ee42381eSTakashi Iwai static const struct snd_kcontrol_new snd_ac97_cm9739_controls_spdif[] = {
30071da177e4SLinus Torvalds 	/* BIT 0: SPDI_EN - always true */
30081da177e4SLinus Torvalds 	{ /* BIT 1: SPDIFS */
30091da177e4SLinus Torvalds 		.iface	= SNDRV_CTL_ELEM_IFACE_MIXER,
30101da177e4SLinus Torvalds 		.name	= SNDRV_CTL_NAME_IEC958("",PLAYBACK,NONE) "Source",
30111da177e4SLinus Torvalds 		.info	= snd_ac97_cmedia_spdif_playback_source_info,
30121da177e4SLinus Torvalds 		.get	= snd_ac97_cmedia_spdif_playback_source_get,
30131da177e4SLinus Torvalds 		.put	= snd_ac97_cmedia_spdif_playback_source_put,
30141da177e4SLinus Torvalds 	},
30151da177e4SLinus Torvalds 	/* BIT 2: IG_SPIV */
30161da177e4SLinus Torvalds 	AC97_SINGLE(SNDRV_CTL_NAME_IEC958("",CAPTURE,NONE) "Valid Switch", AC97_CM9739_SPDIF_CTRL, 2, 1, 0),
30171da177e4SLinus Torvalds 	/* BIT 3: SPI2F */
30181da177e4SLinus Torvalds 	AC97_SINGLE(SNDRV_CTL_NAME_IEC958("",CAPTURE,NONE) "Monitor", AC97_CM9739_SPDIF_CTRL, 3, 1, 0),
30191da177e4SLinus Torvalds 	/* BIT 4: SPI2SDI */
30201da177e4SLinus Torvalds 	AC97_SINGLE(SNDRV_CTL_NAME_IEC958("",CAPTURE,SWITCH), AC97_CM9739_SPDIF_CTRL, 4, 1, 0),
30211da177e4SLinus Torvalds 	/* BIT 8: SPD32 - 32bit SPDIF - not supported yet */
30221da177e4SLinus Torvalds };
30231da177e4SLinus Torvalds 
3024ee42381eSTakashi Iwai static void cm9739_update_jacks(struct snd_ac97 *ac97)
30251da177e4SLinus Torvalds {
3026831466f4SRandy Cushman 	/* shared Line-In / Surround Out */
3027eb8caf30STakashi Iwai 	snd_ac97_update_bits(ac97, AC97_CM9739_MULTI_CHAN, 1 << 10,
3028831466f4SRandy Cushman 			     is_shared_surrout(ac97) ? (1 << 10) : 0);
3029831466f4SRandy Cushman 	/* shared Mic In / Center/LFE Out **/
3030eb8caf30STakashi Iwai 	snd_ac97_update_bits(ac97, AC97_CM9739_MULTI_CHAN, 0x3000,
3031831466f4SRandy Cushman 			     is_shared_clfeout(ac97) ? 0x1000 : 0x2000);
30321da177e4SLinus Torvalds }
30331da177e4SLinus Torvalds 
3034ee42381eSTakashi Iwai static const struct snd_kcontrol_new snd_ac97_cm9739_controls[] = {
3035eb8caf30STakashi Iwai 	AC97_SURROUND_JACK_MODE_CTL,
3036eb8caf30STakashi Iwai 	AC97_CHANNEL_MODE_CTL,
30371da177e4SLinus Torvalds };
30381da177e4SLinus Torvalds 
3039ee42381eSTakashi Iwai static int patch_cm9739_specific(struct snd_ac97 * ac97)
30401da177e4SLinus Torvalds {
30411da177e4SLinus Torvalds 	return patch_build_controls(ac97, snd_ac97_cm9739_controls, ARRAY_SIZE(snd_ac97_cm9739_controls));
30421da177e4SLinus Torvalds }
30431da177e4SLinus Torvalds 
3044ee42381eSTakashi Iwai static int patch_cm9739_post_spdif(struct snd_ac97 * ac97)
30451da177e4SLinus Torvalds {
30461da177e4SLinus Torvalds 	return patch_build_controls(ac97, snd_ac97_cm9739_controls_spdif, ARRAY_SIZE(snd_ac97_cm9739_controls_spdif));
30471da177e4SLinus Torvalds }
30481da177e4SLinus Torvalds 
30493e8b3b90SHanno Boeck static const struct snd_ac97_build_ops patch_cm9739_ops = {
30501da177e4SLinus Torvalds 	.build_specific	= patch_cm9739_specific,
3051eb8caf30STakashi Iwai 	.build_post_spdif = patch_cm9739_post_spdif,
3052eb8caf30STakashi Iwai 	.update_jacks = cm9739_update_jacks
30531da177e4SLinus Torvalds };
30541da177e4SLinus Torvalds 
3055ac519028STakashi Iwai static int patch_cm9739(struct snd_ac97 * ac97)
30561da177e4SLinus Torvalds {
30571da177e4SLinus Torvalds 	unsigned short val;
30581da177e4SLinus Torvalds 
30591da177e4SLinus Torvalds 	ac97->build_ops = &patch_cm9739_ops;
30601da177e4SLinus Torvalds 
30611da177e4SLinus Torvalds 	/* CM9739/A has no Master and PCM volume although the register reacts */
30621da177e4SLinus Torvalds 	ac97->flags |= AC97_HAS_NO_MASTER_VOL | AC97_HAS_NO_PCM_VOL;
30631da177e4SLinus Torvalds 	snd_ac97_write_cache(ac97, AC97_MASTER, 0x8000);
30641da177e4SLinus Torvalds 	snd_ac97_write_cache(ac97, AC97_PCM, 0x8000);
30651da177e4SLinus Torvalds 
30661da177e4SLinus Torvalds 	/* check spdif */
30671da177e4SLinus Torvalds 	val = snd_ac97_read(ac97, AC97_EXTENDED_STATUS);
30681da177e4SLinus Torvalds 	if (val & AC97_EA_SPCV) {
30691da177e4SLinus Torvalds 		/* enable spdif in */
30701da177e4SLinus Torvalds 		snd_ac97_write_cache(ac97, AC97_CM9739_SPDIF_CTRL,
30711da177e4SLinus Torvalds 				     snd_ac97_read(ac97, AC97_CM9739_SPDIF_CTRL) | 0x01);
30721da177e4SLinus Torvalds 		ac97->rates[AC97_RATES_SPDIF] = SNDRV_PCM_RATE_48000; /* 48k only */
30731da177e4SLinus Torvalds 	} else {
30741da177e4SLinus Torvalds 		ac97->ext_id &= ~AC97_EI_SPDIF; /* disable extended-id */
30751da177e4SLinus Torvalds 		ac97->rates[AC97_RATES_SPDIF] = 0;
30761da177e4SLinus Torvalds 	}
30771da177e4SLinus Torvalds 
30781da177e4SLinus Torvalds 	/* set-up multi channel */
30791da177e4SLinus Torvalds 	/* bit 14: 0 = SPDIF, 1 = EAPD */
30801da177e4SLinus Torvalds 	/* bit 13: enable internal vref output for mic */
308108a7e621SMasahiro Yamada 	/* bit 12: disable center/lfe (switchable) */
30821da177e4SLinus Torvalds 	/* bit 10: disable surround/line (switchable) */
30831da177e4SLinus Torvalds 	/* bit 9: mix 2 surround off */
30841da177e4SLinus Torvalds 	/* bit 4: undocumented; 0 mutes the CM9739A, which defaults to 1 */
30851da177e4SLinus Torvalds 	/* bit 3: undocumented; surround? */
30861da177e4SLinus Torvalds 	/* bit 0: dB */
30871da177e4SLinus Torvalds 	val = snd_ac97_read(ac97, AC97_CM9739_MULTI_CHAN) & (1 << 4);
30881da177e4SLinus Torvalds 	val |= (1 << 3);
30891da177e4SLinus Torvalds 	val |= (1 << 13);
30901da177e4SLinus Torvalds 	if (! (ac97->ext_id & AC97_EI_SPDIF))
30911da177e4SLinus Torvalds 		val |= (1 << 14);
30921da177e4SLinus Torvalds 	snd_ac97_write_cache(ac97, AC97_CM9739_MULTI_CHAN, val);
30931da177e4SLinus Torvalds 
30941da177e4SLinus Torvalds 	/* FIXME: set up GPIO */
30951da177e4SLinus Torvalds 	snd_ac97_write_cache(ac97, 0x70, 0x0100);
30961da177e4SLinus Torvalds 	snd_ac97_write_cache(ac97, 0x72, 0x0020);
30971da177e4SLinus Torvalds 	/* Special exception for ASUS W1000/CMI9739. It does not have an SPDIF in. */
30981da177e4SLinus Torvalds 	if (ac97->pci &&
30991da177e4SLinus Torvalds 	     ac97->subsystem_vendor == 0x1043 &&
31001da177e4SLinus Torvalds 	     ac97->subsystem_device == 0x1843) {
31011da177e4SLinus Torvalds 		snd_ac97_write_cache(ac97, AC97_CM9739_SPDIF_CTRL,
31021da177e4SLinus Torvalds 			snd_ac97_read(ac97, AC97_CM9739_SPDIF_CTRL) & ~0x01);
31031da177e4SLinus Torvalds 		snd_ac97_write_cache(ac97, AC97_CM9739_MULTI_CHAN,
31041da177e4SLinus Torvalds 			snd_ac97_read(ac97, AC97_CM9739_MULTI_CHAN) | (1 << 14));
31051da177e4SLinus Torvalds 	}
31061da177e4SLinus Torvalds 
31071da177e4SLinus Torvalds 	return 0;
31081da177e4SLinus Torvalds }
31091da177e4SLinus Torvalds 
31101da177e4SLinus Torvalds #define AC97_CM9761_MULTI_CHAN	0x64
31115f0dccf8STakashi Iwai #define AC97_CM9761_FUNC	0x66
31121da177e4SLinus Torvalds #define AC97_CM9761_SPDIF_CTRL	0x6c
31131da177e4SLinus Torvalds 
3114ee42381eSTakashi Iwai static void cm9761_update_jacks(struct snd_ac97 *ac97)
31151da177e4SLinus Torvalds {
31164525c9f3STakashi Iwai 	/* FIXME: check the bits for each model
31174525c9f3STakashi Iwai 	 *        model 83 is confirmed to work
31184525c9f3STakashi Iwai 	 */
31191675bfc0STakashi Iwai 	static const unsigned short surr_on[3][2] = {
31204525c9f3STakashi Iwai 		{ 0x0008, 0x0000 }, /* 9761-78 & 82 */
31214525c9f3STakashi Iwai 		{ 0x0000, 0x0008 }, /* 9761-82 rev.B */
31224525c9f3STakashi Iwai 		{ 0x0000, 0x0008 }, /* 9761-83 */
31231da177e4SLinus Torvalds 	};
31241675bfc0STakashi Iwai 	static const unsigned short clfe_on[3][2] = {
31254525c9f3STakashi Iwai 		{ 0x0000, 0x1000 }, /* 9761-78 & 82 */
31264525c9f3STakashi Iwai 		{ 0x1000, 0x0000 }, /* 9761-82 rev.B */
31274525c9f3STakashi Iwai 		{ 0x0000, 0x1000 }, /* 9761-83 */
31281da177e4SLinus Torvalds 	};
31291675bfc0STakashi Iwai 	static const unsigned short surr_shared[3][2] = {
31304525c9f3STakashi Iwai 		{ 0x0000, 0x0400 }, /* 9761-78 & 82 */
31314525c9f3STakashi Iwai 		{ 0x0000, 0x0400 }, /* 9761-82 rev.B */
31324525c9f3STakashi Iwai 		{ 0x0000, 0x0400 }, /* 9761-83 */
31334525c9f3STakashi Iwai 	};
31341675bfc0STakashi Iwai 	static const unsigned short clfe_shared[3][2] = {
31354525c9f3STakashi Iwai 		{ 0x2000, 0x0880 }, /* 9761-78 & 82 */
31364525c9f3STakashi Iwai 		{ 0x0000, 0x2880 }, /* 9761-82 rev.B */
31374525c9f3STakashi Iwai 		{ 0x2000, 0x0800 }, /* 9761-83 */
31384525c9f3STakashi Iwai 	};
31394525c9f3STakashi Iwai 	unsigned short val = 0;
3140eb8caf30STakashi Iwai 
31414525c9f3STakashi Iwai 	val |= surr_on[ac97->spec.dev_flags][is_surround_on(ac97)];
31424525c9f3STakashi Iwai 	val |= clfe_on[ac97->spec.dev_flags][is_clfe_on(ac97)];
3143831466f4SRandy Cushman 	val |= surr_shared[ac97->spec.dev_flags][is_shared_surrout(ac97)];
3144831466f4SRandy Cushman 	val |= clfe_shared[ac97->spec.dev_flags][is_shared_clfeout(ac97)];
31454525c9f3STakashi Iwai 
31464525c9f3STakashi Iwai 	snd_ac97_update_bits(ac97, AC97_CM9761_MULTI_CHAN, 0x3c88, val);
31471da177e4SLinus Torvalds }
31481da177e4SLinus Torvalds 
3149ee42381eSTakashi Iwai static const struct snd_kcontrol_new snd_ac97_cm9761_controls[] = {
3150eb8caf30STakashi Iwai 	AC97_SURROUND_JACK_MODE_CTL,
3151eb8caf30STakashi Iwai 	AC97_CHANNEL_MODE_CTL,
31521da177e4SLinus Torvalds };
31531da177e4SLinus Torvalds 
3154ee42381eSTakashi Iwai static int cm9761_spdif_out_source_info(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_info *uinfo)
31555f0dccf8STakashi Iwai {
31563b7a00dcSTakashi Iwai 	static const char * const texts[] = { "AC-Link", "ADC", "SPDIF-In" };
31575f0dccf8STakashi Iwai 
31583b7a00dcSTakashi Iwai 	return snd_ctl_enum_info(uinfo, 1, 3, texts);
31595f0dccf8STakashi Iwai }
31605f0dccf8STakashi Iwai 
3161ee42381eSTakashi Iwai static int cm9761_spdif_out_source_get(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
31625f0dccf8STakashi Iwai {
3163ee42381eSTakashi Iwai 	struct snd_ac97 *ac97 = snd_kcontrol_chip(kcontrol);
31645f0dccf8STakashi Iwai 
31655f0dccf8STakashi Iwai 	if (ac97->regs[AC97_CM9761_FUNC] & 0x1)
31665f0dccf8STakashi Iwai 		ucontrol->value.enumerated.item[0] = 2; /* SPDIF-loopback */
31675f0dccf8STakashi Iwai 	else if (ac97->regs[AC97_CM9761_SPDIF_CTRL] & 0x2)
31685f0dccf8STakashi Iwai 		ucontrol->value.enumerated.item[0] = 1; /* ADC loopback */
31695f0dccf8STakashi Iwai 	else
31705f0dccf8STakashi Iwai 		ucontrol->value.enumerated.item[0] = 0; /* AC-link */
31715f0dccf8STakashi Iwai 	return 0;
31725f0dccf8STakashi Iwai }
31735f0dccf8STakashi Iwai 
3174ee42381eSTakashi Iwai static int cm9761_spdif_out_source_put(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
31755f0dccf8STakashi Iwai {
3176ee42381eSTakashi Iwai 	struct snd_ac97 *ac97 = snd_kcontrol_chip(kcontrol);
31775f0dccf8STakashi Iwai 
31785f0dccf8STakashi Iwai 	if (ucontrol->value.enumerated.item[0] == 2)
31795f0dccf8STakashi Iwai 		return snd_ac97_update_bits(ac97, AC97_CM9761_FUNC, 0x1, 0x1);
31805f0dccf8STakashi Iwai 	snd_ac97_update_bits(ac97, AC97_CM9761_FUNC, 0x1, 0);
31815f0dccf8STakashi Iwai 	return snd_ac97_update_bits(ac97, AC97_CM9761_SPDIF_CTRL, 0x2,
31825f0dccf8STakashi Iwai 				    ucontrol->value.enumerated.item[0] == 1 ? 0x2 : 0);
31835f0dccf8STakashi Iwai }
31845f0dccf8STakashi Iwai 
31851bc10bb6STakashi Iwai static const char * const cm9761_dac_clock[] = {
31861bc10bb6STakashi Iwai 	"AC-Link", "SPDIF-In", "Both"
31871bc10bb6STakashi Iwai };
31885f0dccf8STakashi Iwai static const struct ac97_enum cm9761_dac_clock_enum =
31895f0dccf8STakashi Iwai 	AC97_ENUM_SINGLE(AC97_CM9761_SPDIF_CTRL, 9, 3, cm9761_dac_clock);
31905f0dccf8STakashi Iwai 
3191ee42381eSTakashi Iwai static const struct snd_kcontrol_new snd_ac97_cm9761_controls_spdif[] = {
31925f0dccf8STakashi Iwai 	{ /* BIT 1: SPDIFS */
31935f0dccf8STakashi Iwai 		.iface	= SNDRV_CTL_ELEM_IFACE_MIXER,
31945f0dccf8STakashi Iwai 		.name	= SNDRV_CTL_NAME_IEC958("",PLAYBACK,NONE) "Source",
31955f0dccf8STakashi Iwai 		.info = cm9761_spdif_out_source_info,
31965f0dccf8STakashi Iwai 		.get = cm9761_spdif_out_source_get,
31975f0dccf8STakashi Iwai 		.put = cm9761_spdif_out_source_put,
31985f0dccf8STakashi Iwai 	},
31995f0dccf8STakashi Iwai 	/* BIT 2: IG_SPIV */
32005f0dccf8STakashi Iwai 	AC97_SINGLE(SNDRV_CTL_NAME_IEC958("",CAPTURE,NONE) "Valid Switch", AC97_CM9761_SPDIF_CTRL, 2, 1, 0),
32015f0dccf8STakashi Iwai 	/* BIT 3: SPI2F */
32025f0dccf8STakashi Iwai 	AC97_SINGLE(SNDRV_CTL_NAME_IEC958("",CAPTURE,NONE) "Monitor", AC97_CM9761_SPDIF_CTRL, 3, 1, 0),
32035f0dccf8STakashi Iwai 	/* BIT 4: SPI2SDI */
32045f0dccf8STakashi Iwai 	AC97_SINGLE(SNDRV_CTL_NAME_IEC958("",CAPTURE,SWITCH), AC97_CM9761_SPDIF_CTRL, 4, 1, 0),
32055f0dccf8STakashi Iwai 	/* BIT 9-10: DAC_CTL */
32065f0dccf8STakashi Iwai 	AC97_ENUM("DAC Clock Source", cm9761_dac_clock_enum),
32075f0dccf8STakashi Iwai };
32085f0dccf8STakashi Iwai 
3209ee42381eSTakashi Iwai static int patch_cm9761_post_spdif(struct snd_ac97 * ac97)
32105f0dccf8STakashi Iwai {
32115f0dccf8STakashi Iwai 	return patch_build_controls(ac97, snd_ac97_cm9761_controls_spdif, ARRAY_SIZE(snd_ac97_cm9761_controls_spdif));
32125f0dccf8STakashi Iwai }
32135f0dccf8STakashi Iwai 
3214ee42381eSTakashi Iwai static int patch_cm9761_specific(struct snd_ac97 * ac97)
32151da177e4SLinus Torvalds {
32161da177e4SLinus Torvalds 	return patch_build_controls(ac97, snd_ac97_cm9761_controls, ARRAY_SIZE(snd_ac97_cm9761_controls));
32171da177e4SLinus Torvalds }
32181da177e4SLinus Torvalds 
32193e8b3b90SHanno Boeck static const struct snd_ac97_build_ops patch_cm9761_ops = {
32201da177e4SLinus Torvalds 	.build_specific	= patch_cm9761_specific,
3221eb8caf30STakashi Iwai 	.build_post_spdif = patch_cm9761_post_spdif,
3222eb8caf30STakashi Iwai 	.update_jacks = cm9761_update_jacks
32231da177e4SLinus Torvalds };
32241da177e4SLinus Torvalds 
3225ac519028STakashi Iwai static int patch_cm9761(struct snd_ac97 *ac97)
32261da177e4SLinus Torvalds {
32271da177e4SLinus Torvalds 	unsigned short val;
32281da177e4SLinus Torvalds 
32291da177e4SLinus Torvalds 	/* CM9761 has no PCM volume although the register reacts */
32301da177e4SLinus Torvalds 	/* Master volume seems to have _some_ influence on the analog
32311da177e4SLinus Torvalds 	 * input sounds
32321da177e4SLinus Torvalds 	 */
32331da177e4SLinus Torvalds 	ac97->flags |= /*AC97_HAS_NO_MASTER_VOL |*/ AC97_HAS_NO_PCM_VOL;
32341da177e4SLinus Torvalds 	snd_ac97_write_cache(ac97, AC97_MASTER, 0x8808);
32351da177e4SLinus Torvalds 	snd_ac97_write_cache(ac97, AC97_PCM, 0x8808);
32361da177e4SLinus Torvalds 
32374525c9f3STakashi Iwai 	ac97->spec.dev_flags = 0; /* 1 = model 82 revision B, 2 = model 83 */
32381da177e4SLinus Torvalds 	if (ac97->id == AC97_ID_CM9761_82) {
32391da177e4SLinus Torvalds 		unsigned short tmp;
32401da177e4SLinus Torvalds 		/* check page 1, reg 0x60 */
32411da177e4SLinus Torvalds 		val = snd_ac97_read(ac97, AC97_INT_PAGING);
32421da177e4SLinus Torvalds 		snd_ac97_write_cache(ac97, AC97_INT_PAGING, (val & ~0x0f) | 0x01);
32431da177e4SLinus Torvalds 		tmp = snd_ac97_read(ac97, 0x60);
32441da177e4SLinus Torvalds 		ac97->spec.dev_flags = tmp & 1; /* revision B? */
32451da177e4SLinus Torvalds 		snd_ac97_write_cache(ac97, AC97_INT_PAGING, val);
32464525c9f3STakashi Iwai 	} else if (ac97->id == AC97_ID_CM9761_83)
32474525c9f3STakashi Iwai 		ac97->spec.dev_flags = 2;
32481da177e4SLinus Torvalds 
32491da177e4SLinus Torvalds 	ac97->build_ops = &patch_cm9761_ops;
32501da177e4SLinus Torvalds 
32511da177e4SLinus Torvalds 	/* enable spdif */
32521da177e4SLinus Torvalds 	/* force the SPDIF bit in ext_id - codec doesn't set this bit! */
32531da177e4SLinus Torvalds         ac97->ext_id |= AC97_EI_SPDIF;
32541da177e4SLinus Torvalds 	/* to be sure: we overwrite the ext status bits */
32551da177e4SLinus Torvalds 	snd_ac97_write_cache(ac97, AC97_EXTENDED_STATUS, 0x05c0);
32561da177e4SLinus Torvalds 	/* Don't set 0x0200 here.  This results in the silent analog output */
32575f0dccf8STakashi Iwai 	snd_ac97_write_cache(ac97, AC97_CM9761_SPDIF_CTRL, 0x0001); /* enable spdif-in */
32581da177e4SLinus Torvalds 	ac97->rates[AC97_RATES_SPDIF] = SNDRV_PCM_RATE_48000; /* 48k only */
32591da177e4SLinus Torvalds 
32601da177e4SLinus Torvalds 	/* set-up multi channel */
32611da177e4SLinus Torvalds 	/* bit 15: pc master beep off
32625f0dccf8STakashi Iwai 	 * bit 14: pin47 = EAPD/SPDIF
32631da177e4SLinus Torvalds 	 * bit 13: vref ctl [= cm9739]
32645f0dccf8STakashi Iwai 	 * bit 12: CLFE control (reverted on rev B)
32655f0dccf8STakashi Iwai 	 * bit 11: Mic/center share (reverted on rev B)
32665f0dccf8STakashi Iwai 	 * bit 10: suddound/line share
32675f0dccf8STakashi Iwai 	 * bit  9: Analog-in mix -> surround
32685f0dccf8STakashi Iwai 	 * bit  8: Analog-in mix -> CLFE
32695f0dccf8STakashi Iwai 	 * bit  7: Mic/LFE share (mic/center/lfe)
32705f0dccf8STakashi Iwai 	 * bit  5: vref select (9761A)
32715f0dccf8STakashi Iwai 	 * bit  4: front control
32725f0dccf8STakashi Iwai 	 * bit  3: surround control (revereted with rev B)
32735f0dccf8STakashi Iwai 	 * bit  2: front mic
32745f0dccf8STakashi Iwai 	 * bit  1: stereo mic
32755f0dccf8STakashi Iwai 	 * bit  0: mic boost level (0=20dB, 1=30dB)
32761da177e4SLinus Torvalds 	 */
32771da177e4SLinus Torvalds 
32781da177e4SLinus Torvalds #if 0
32791da177e4SLinus Torvalds 	if (ac97->spec.dev_flags)
32801da177e4SLinus Torvalds 		val = 0x0214;
32811da177e4SLinus Torvalds 	else
32821da177e4SLinus Torvalds 		val = 0x321c;
32831da177e4SLinus Torvalds #endif
32841da177e4SLinus Torvalds 	val = snd_ac97_read(ac97, AC97_CM9761_MULTI_CHAN);
32851da177e4SLinus Torvalds 	val |= (1 << 4); /* front on */
32861da177e4SLinus Torvalds 	snd_ac97_write_cache(ac97, AC97_CM9761_MULTI_CHAN, val);
32871da177e4SLinus Torvalds 
32881da177e4SLinus Torvalds 	/* FIXME: set up GPIO */
32891da177e4SLinus Torvalds 	snd_ac97_write_cache(ac97, 0x70, 0x0100);
32901da177e4SLinus Torvalds 	snd_ac97_write_cache(ac97, 0x72, 0x0020);
32911da177e4SLinus Torvalds 
32921da177e4SLinus Torvalds 	return 0;
32931da177e4SLinus Torvalds }
32941da177e4SLinus Torvalds 
32955f0dccf8STakashi Iwai #define AC97_CM9780_SIDE	0x60
32965f0dccf8STakashi Iwai #define AC97_CM9780_JACK	0x62
32975f0dccf8STakashi Iwai #define AC97_CM9780_MIXER	0x64
32985f0dccf8STakashi Iwai #define AC97_CM9780_MULTI_CHAN	0x66
32995f0dccf8STakashi Iwai #define AC97_CM9780_SPDIF	0x6c
33005f0dccf8STakashi Iwai 
33011bc10bb6STakashi Iwai static const char * const cm9780_ch_select[] = {
33021bc10bb6STakashi Iwai 	"Front", "Side", "Center/LFE", "Rear"
33031bc10bb6STakashi Iwai };
33045f0dccf8STakashi Iwai static const struct ac97_enum cm9780_ch_select_enum =
33055f0dccf8STakashi Iwai 	AC97_ENUM_SINGLE(AC97_CM9780_MULTI_CHAN, 6, 4, cm9780_ch_select);
3306ee42381eSTakashi Iwai static const struct snd_kcontrol_new cm9780_controls[] = {
33075f0dccf8STakashi Iwai 	AC97_DOUBLE("Side Playback Switch", AC97_CM9780_SIDE, 15, 7, 1, 1),
33085f0dccf8STakashi Iwai 	AC97_DOUBLE("Side Playback Volume", AC97_CM9780_SIDE, 8, 0, 31, 0),
33095f0dccf8STakashi Iwai 	AC97_ENUM("Side Playback Route", cm9780_ch_select_enum),
33105f0dccf8STakashi Iwai };
33115f0dccf8STakashi Iwai 
3312ee42381eSTakashi Iwai static int patch_cm9780_specific(struct snd_ac97 *ac97)
33135f0dccf8STakashi Iwai {
33145f0dccf8STakashi Iwai 	return patch_build_controls(ac97, cm9780_controls, ARRAY_SIZE(cm9780_controls));
33155f0dccf8STakashi Iwai }
33165f0dccf8STakashi Iwai 
33173e8b3b90SHanno Boeck static const struct snd_ac97_build_ops patch_cm9780_ops = {
33185f0dccf8STakashi Iwai 	.build_specific	= patch_cm9780_specific,
33195f0dccf8STakashi Iwai 	.build_post_spdif = patch_cm9761_post_spdif	/* identical with CM9761 */
33205f0dccf8STakashi Iwai };
33215f0dccf8STakashi Iwai 
3322ac519028STakashi Iwai static int patch_cm9780(struct snd_ac97 *ac97)
33235f0dccf8STakashi Iwai {
33245f0dccf8STakashi Iwai 	unsigned short val;
33255f0dccf8STakashi Iwai 
33265f0dccf8STakashi Iwai 	ac97->build_ops = &patch_cm9780_ops;
33275f0dccf8STakashi Iwai 
33285f0dccf8STakashi Iwai 	/* enable spdif */
33295f0dccf8STakashi Iwai 	if (ac97->ext_id & AC97_EI_SPDIF) {
33305f0dccf8STakashi Iwai 		ac97->rates[AC97_RATES_SPDIF] = SNDRV_PCM_RATE_48000; /* 48k only */
33315f0dccf8STakashi Iwai 		val = snd_ac97_read(ac97, AC97_CM9780_SPDIF);
33325f0dccf8STakashi Iwai 		val |= 0x1; /* SPDI_EN */
33335f0dccf8STakashi Iwai 		snd_ac97_write_cache(ac97, AC97_CM9780_SPDIF, val);
33345f0dccf8STakashi Iwai 	}
33355f0dccf8STakashi Iwai 
33365f0dccf8STakashi Iwai 	return 0;
33375f0dccf8STakashi Iwai }
33381da177e4SLinus Torvalds 
33391da177e4SLinus Torvalds /*
3340d6482288SMaciej S. Szmigiero  * VIA VT1613 codec
3341d6482288SMaciej S. Szmigiero  */
3342d6482288SMaciej S. Szmigiero static const struct snd_kcontrol_new snd_ac97_controls_vt1613[] = {
3343d6482288SMaciej S. Szmigiero AC97_SINGLE("DC Offset removal", 0x5a, 10, 1, 0),
3344d6482288SMaciej S. Szmigiero };
3345d6482288SMaciej S. Szmigiero 
3346d6482288SMaciej S. Szmigiero static int patch_vt1613_specific(struct snd_ac97 *ac97)
3347d6482288SMaciej S. Szmigiero {
33485371fc0eSFabio Estevam 	return patch_build_controls(ac97, &snd_ac97_controls_vt1613[0],
3349d6482288SMaciej S. Szmigiero 				    ARRAY_SIZE(snd_ac97_controls_vt1613));
3350d6482288SMaciej S. Szmigiero };
3351d6482288SMaciej S. Szmigiero 
3352d6482288SMaciej S. Szmigiero static const struct snd_ac97_build_ops patch_vt1613_ops = {
3353d6482288SMaciej S. Szmigiero 	.build_specific	= patch_vt1613_specific
3354d6482288SMaciej S. Szmigiero };
3355d6482288SMaciej S. Szmigiero 
3356d6482288SMaciej S. Szmigiero static int patch_vt1613(struct snd_ac97 *ac97)
3357d6482288SMaciej S. Szmigiero {
3358d6482288SMaciej S. Szmigiero 	ac97->build_ops = &patch_vt1613_ops;
3359d6482288SMaciej S. Szmigiero 
3360d6482288SMaciej S. Szmigiero 	ac97->flags |= AC97_HAS_NO_VIDEO;
3361d6482288SMaciej S. Szmigiero 	ac97->caps |= AC97_BC_HEADPHONE;
3362d6482288SMaciej S. Szmigiero 
3363d6482288SMaciej S. Szmigiero 	return 0;
3364d6482288SMaciej S. Szmigiero }
3365d6482288SMaciej S. Szmigiero 
3366d6482288SMaciej S. Szmigiero /*
33671da177e4SLinus Torvalds  * VIA VT1616 codec
33681da177e4SLinus Torvalds  */
3369ee42381eSTakashi Iwai static const struct snd_kcontrol_new snd_ac97_controls_vt1616[] = {
33701da177e4SLinus Torvalds AC97_SINGLE("DC Offset removal", 0x5a, 10, 1, 0),
33711da177e4SLinus Torvalds AC97_SINGLE("Alternate Level to Surround Out", 0x5a, 15, 1, 0),
33721da177e4SLinus Torvalds AC97_SINGLE("Downmix LFE and Center to Front", 0x5a, 12, 1, 0),
33731da177e4SLinus Torvalds AC97_SINGLE("Downmix Surround to Front", 0x5a, 11, 1, 0),
33741da177e4SLinus Torvalds };
33751da177e4SLinus Torvalds 
33761bc10bb6STakashi Iwai static const char * const slave_vols_vt1616[] = {
337787af38daSDaniel Jacobowitz 	"Front Playback Volume",
337887af38daSDaniel Jacobowitz 	"Surround Playback Volume",
337987af38daSDaniel Jacobowitz 	"Center Playback Volume",
338087af38daSDaniel Jacobowitz 	"LFE Playback Volume",
338187af38daSDaniel Jacobowitz 	NULL
338287af38daSDaniel Jacobowitz };
338387af38daSDaniel Jacobowitz 
33841bc10bb6STakashi Iwai static const char * const slave_sws_vt1616[] = {
338587af38daSDaniel Jacobowitz 	"Front Playback Switch",
338687af38daSDaniel Jacobowitz 	"Surround Playback Switch",
338787af38daSDaniel Jacobowitz 	"Center Playback Switch",
338887af38daSDaniel Jacobowitz 	"LFE Playback Switch",
338987af38daSDaniel Jacobowitz 	NULL
339087af38daSDaniel Jacobowitz };
339187af38daSDaniel Jacobowitz 
339287af38daSDaniel Jacobowitz /* find a mixer control element with the given name */
339387af38daSDaniel Jacobowitz static struct snd_kcontrol *snd_ac97_find_mixer_ctl(struct snd_ac97 *ac97,
339487af38daSDaniel Jacobowitz 						    const char *name)
339587af38daSDaniel Jacobowitz {
339687af38daSDaniel Jacobowitz 	struct snd_ctl_elem_id id;
339787af38daSDaniel Jacobowitz 	memset(&id, 0, sizeof(id));
339887af38daSDaniel Jacobowitz 	id.iface = SNDRV_CTL_ELEM_IFACE_MIXER;
339987af38daSDaniel Jacobowitz 	strcpy(id.name, name);
340087af38daSDaniel Jacobowitz 	return snd_ctl_find_id(ac97->bus->card, &id);
340187af38daSDaniel Jacobowitz }
340287af38daSDaniel Jacobowitz 
340387af38daSDaniel Jacobowitz /* create a virtual master control and add slaves */
340413c2108dSAdrian Bunk static int snd_ac97_add_vmaster(struct snd_ac97 *ac97, char *name,
34051bc10bb6STakashi Iwai 				const unsigned int *tlv,
34061bc10bb6STakashi Iwai 				const char * const *slaves)
340787af38daSDaniel Jacobowitz {
340887af38daSDaniel Jacobowitz 	struct snd_kcontrol *kctl;
34091bc10bb6STakashi Iwai 	const char * const *s;
341087af38daSDaniel Jacobowitz 	int err;
341187af38daSDaniel Jacobowitz 
341287af38daSDaniel Jacobowitz 	kctl = snd_ctl_make_virtual_master(name, tlv);
341387af38daSDaniel Jacobowitz 	if (!kctl)
341487af38daSDaniel Jacobowitz 		return -ENOMEM;
341587af38daSDaniel Jacobowitz 	err = snd_ctl_add(ac97->bus->card, kctl);
341687af38daSDaniel Jacobowitz 	if (err < 0)
341787af38daSDaniel Jacobowitz 		return err;
341887af38daSDaniel Jacobowitz 
341987af38daSDaniel Jacobowitz 	for (s = slaves; *s; s++) {
342087af38daSDaniel Jacobowitz 		struct snd_kcontrol *sctl;
342187af38daSDaniel Jacobowitz 
342287af38daSDaniel Jacobowitz 		sctl = snd_ac97_find_mixer_ctl(ac97, *s);
342387af38daSDaniel Jacobowitz 		if (!sctl) {
342438c16e34STakashi Iwai 			dev_dbg(ac97->bus->card->dev,
342538c16e34STakashi Iwai 				"Cannot find slave %s, skipped\n", *s);
342687af38daSDaniel Jacobowitz 			continue;
342787af38daSDaniel Jacobowitz 		}
342887af38daSDaniel Jacobowitz 		err = snd_ctl_add_slave(kctl, sctl);
342987af38daSDaniel Jacobowitz 		if (err < 0)
343087af38daSDaniel Jacobowitz 			return err;
343187af38daSDaniel Jacobowitz 	}
343287af38daSDaniel Jacobowitz 	return 0;
343387af38daSDaniel Jacobowitz }
343487af38daSDaniel Jacobowitz 
3435ee42381eSTakashi Iwai static int patch_vt1616_specific(struct snd_ac97 * ac97)
34361da177e4SLinus Torvalds {
343787af38daSDaniel Jacobowitz 	struct snd_kcontrol *kctl;
34381da177e4SLinus Torvalds 	int err;
34391da177e4SLinus Torvalds 
34401da177e4SLinus Torvalds 	if (snd_ac97_try_bit(ac97, 0x5a, 9))
34411da177e4SLinus Torvalds 		if ((err = patch_build_controls(ac97, &snd_ac97_controls_vt1616[0], 1)) < 0)
34421da177e4SLinus Torvalds 			return err;
34431da177e4SLinus Torvalds 	if ((err = patch_build_controls(ac97, &snd_ac97_controls_vt1616[1], ARRAY_SIZE(snd_ac97_controls_vt1616) - 1)) < 0)
34441da177e4SLinus Torvalds 		return err;
344587af38daSDaniel Jacobowitz 
344687af38daSDaniel Jacobowitz 	/* There is already a misnamed master switch.  Rename it.  */
344787af38daSDaniel Jacobowitz 	kctl = snd_ac97_find_mixer_ctl(ac97, "Master Playback Volume");
344887af38daSDaniel Jacobowitz 	if (!kctl)
344987af38daSDaniel Jacobowitz 		return -EINVAL;
345087af38daSDaniel Jacobowitz 
345187af38daSDaniel Jacobowitz 	snd_ac97_rename_vol_ctl(ac97, "Master Playback", "Front Playback");
345287af38daSDaniel Jacobowitz 
345387af38daSDaniel Jacobowitz 	err = snd_ac97_add_vmaster(ac97, "Master Playback Volume",
345487af38daSDaniel Jacobowitz 				   kctl->tlv.p, slave_vols_vt1616);
345587af38daSDaniel Jacobowitz 	if (err < 0)
345687af38daSDaniel Jacobowitz 		return err;
345787af38daSDaniel Jacobowitz 
345887af38daSDaniel Jacobowitz 	err = snd_ac97_add_vmaster(ac97, "Master Playback Switch",
345987af38daSDaniel Jacobowitz 				   NULL, slave_sws_vt1616);
346087af38daSDaniel Jacobowitz 	if (err < 0)
346187af38daSDaniel Jacobowitz 		return err;
346287af38daSDaniel Jacobowitz 
34631da177e4SLinus Torvalds 	return 0;
34641da177e4SLinus Torvalds }
34651da177e4SLinus Torvalds 
34663e8b3b90SHanno Boeck static const struct snd_ac97_build_ops patch_vt1616_ops = {
34671da177e4SLinus Torvalds 	.build_specific	= patch_vt1616_specific
34681da177e4SLinus Torvalds };
34691da177e4SLinus Torvalds 
3470ac519028STakashi Iwai static int patch_vt1616(struct snd_ac97 * ac97)
34711da177e4SLinus Torvalds {
34721da177e4SLinus Torvalds 	ac97->build_ops = &patch_vt1616_ops;
34731da177e4SLinus Torvalds 	return 0;
34741da177e4SLinus Torvalds }
34751da177e4SLinus Torvalds 
3476eb8caf30STakashi Iwai /*
34774b499486SPhilip Prindeville  * VT1617A codec
34784b499486SPhilip Prindeville  */
3479e9024cccSJohn Utz 
3480e9024cccSJohn Utz /*
3481e9024cccSJohn Utz  * unfortunately, the vt1617a stashes the twiddlers required for
34829e285e1aSJohn L. Utz III  * noodling the i/o jacks on 2 different regs. that means that we can't
3483e9024cccSJohn Utz  * use the easy way provided by AC97_ENUM_DOUBLE() we have to write
3484e9024cccSJohn Utz  * are own funcs.
3485e9024cccSJohn Utz  *
3486e9024cccSJohn Utz  * NB: this is absolutely and utterly different from the vt1618. dunno
3487e9024cccSJohn Utz  * about the 1616.
3488e9024cccSJohn Utz  */
3489e9024cccSJohn Utz 
3490e9024cccSJohn Utz /* copied from ac97_surround_jack_mode_info() */
3491e9024cccSJohn Utz static int snd_ac97_vt1617a_smart51_info(struct snd_kcontrol *kcontrol,
3492e9024cccSJohn Utz 					 struct snd_ctl_elem_info *uinfo)
34934b499486SPhilip Prindeville {
3494e9024cccSJohn Utz 	/* ordering in this list reflects vt1617a docs for Reg 20 and
3495e9024cccSJohn Utz 	 * 7a and Table 6 that lays out the matrix NB WRT Table6: SM51
3496e9024cccSJohn Utz 	 * is SM51EN *AND* it's Bit14, not Bit15 so the table is very
3497e9024cccSJohn Utz 	 * counter-intuitive */
3498e9024cccSJohn Utz 
34993b7a00dcSTakashi Iwai 	static const char * const texts[] = {"LineIn Mic1", "LineIn Mic1 Mic3",
3500e9024cccSJohn Utz 				       "Surr LFE/C Mic3", "LineIn LFE/C Mic3",
3501e9024cccSJohn Utz 				       "LineIn Mic2", "LineIn Mic2 Mic1",
3502e9024cccSJohn Utz 				       "Surr LFE Mic1", "Surr LFE Mic1 Mic2"};
35033b7a00dcSTakashi Iwai 
35043b7a00dcSTakashi Iwai 	return snd_ctl_enum_info(uinfo, 1, 8, texts);
3505e9024cccSJohn Utz }
3506e9024cccSJohn Utz 
3507e9024cccSJohn Utz static int snd_ac97_vt1617a_smart51_get(struct snd_kcontrol *kcontrol,
3508e9024cccSJohn Utz 					struct snd_ctl_elem_value *ucontrol)
3509e9024cccSJohn Utz {
3510e9024cccSJohn Utz 	ushort usSM51, usMS;
3511e9024cccSJohn Utz 
3512e9024cccSJohn Utz 	struct snd_ac97 *pac97;
3513e9024cccSJohn Utz 
3514e9024cccSJohn Utz 	pac97 = snd_kcontrol_chip(kcontrol); /* grab codec handle */
3515e9024cccSJohn Utz 
35169e285e1aSJohn L. Utz III 	/* grab our desired bits, then mash them together in a manner
3517e9024cccSJohn Utz 	 * consistent with Table 6 on page 17 in the 1617a docs */
3518e9024cccSJohn Utz 
3519e9024cccSJohn Utz 	usSM51 = snd_ac97_read(pac97, 0x7a) >> 14;
3520e9024cccSJohn Utz 	usMS   = snd_ac97_read(pac97, 0x20) >> 8;
3521e9024cccSJohn Utz 
3522e9024cccSJohn Utz 	ucontrol->value.enumerated.item[0] = (usSM51 << 1) + usMS;
3523e9024cccSJohn Utz 
3524e9024cccSJohn Utz 	return 0;
3525e9024cccSJohn Utz }
3526e9024cccSJohn Utz 
3527e9024cccSJohn Utz static int snd_ac97_vt1617a_smart51_put(struct snd_kcontrol *kcontrol,
3528e9024cccSJohn Utz 					struct snd_ctl_elem_value *ucontrol)
3529e9024cccSJohn Utz {
3530e9024cccSJohn Utz 	ushort usSM51, usMS, usReg;
3531e9024cccSJohn Utz 
3532e9024cccSJohn Utz 	struct snd_ac97 *pac97;
3533e9024cccSJohn Utz 
3534e9024cccSJohn Utz 	pac97 = snd_kcontrol_chip(kcontrol); /* grab codec handle */
3535e9024cccSJohn Utz 
3536e9024cccSJohn Utz 	usSM51 = ucontrol->value.enumerated.item[0] >> 1;
3537e9024cccSJohn Utz 	usMS   = ucontrol->value.enumerated.item[0] &  1;
3538e9024cccSJohn Utz 
3539e9024cccSJohn Utz 	/* push our values into the register - consider that things will be left
3540e9024cccSJohn Utz 	 * in a funky state if the write fails */
3541e9024cccSJohn Utz 
3542e9024cccSJohn Utz 	usReg = snd_ac97_read(pac97, 0x7a);
3543e9024cccSJohn Utz 	snd_ac97_write_cache(pac97, 0x7a, (usReg & 0x3FFF) + (usSM51 << 14));
3544e9024cccSJohn Utz 	usReg = snd_ac97_read(pac97, 0x20);
3545e9024cccSJohn Utz 	snd_ac97_write_cache(pac97, 0x20, (usReg & 0xFEFF) + (usMS   <<  8));
3546e9024cccSJohn Utz 
3547e9024cccSJohn Utz 	return 0;
3548e9024cccSJohn Utz }
3549e9024cccSJohn Utz 
3550e9024cccSJohn Utz static const struct snd_kcontrol_new snd_ac97_controls_vt1617a[] = {
3551e9024cccSJohn Utz 
3552e9024cccSJohn Utz 	AC97_SINGLE("Center/LFE Exchange", 0x5a, 8, 1, 0),
3553e9024cccSJohn Utz 	/*
3554e9024cccSJohn Utz 	 * These are used to enable/disable surround sound on motherboards
3555e9024cccSJohn Utz 	 * that have 3 bidirectional analog jacks
3556e9024cccSJohn Utz 	 */
3557e9024cccSJohn Utz 	{
3558e9024cccSJohn Utz 		.iface         = SNDRV_CTL_ELEM_IFACE_MIXER,
3559e9024cccSJohn Utz 		.name          = "Smart 5.1 Select",
3560e9024cccSJohn Utz 		.info          = snd_ac97_vt1617a_smart51_info,
3561e9024cccSJohn Utz 		.get           = snd_ac97_vt1617a_smart51_get,
3562e9024cccSJohn Utz 		.put           = snd_ac97_vt1617a_smart51_put,
3563e9024cccSJohn Utz 	},
3564e9024cccSJohn Utz };
3565e9024cccSJohn Utz 
3566b03671a8SHarvey Harrison static int patch_vt1617a(struct snd_ac97 * ac97)
3567e9024cccSJohn Utz {
3568e9024cccSJohn Utz 	int err = 0;
35692e75d050STakashi Iwai 	int val;
3570e9024cccSJohn Utz 
3571e9024cccSJohn Utz 	/* we choose to not fail out at this point, but we tell the
3572e9024cccSJohn Utz 	   caller when we return */
3573e9024cccSJohn Utz 
3574e9024cccSJohn Utz 	err = patch_build_controls(ac97, &snd_ac97_controls_vt1617a[0],
3575e9024cccSJohn Utz 				   ARRAY_SIZE(snd_ac97_controls_vt1617a));
3576e9024cccSJohn Utz 
3577e9024cccSJohn Utz 	/* bring analog power consumption to normal by turning off the
3578e9024cccSJohn Utz 	 * headphone amplifier, like WinXP driver for EPIA SP
35799f458e7fSAndrey Liakhovets 	 */
35802e75d050STakashi Iwai 	/* We need to check the bit before writing it.
35812e75d050STakashi Iwai 	 * On some (many?) hardwares, setting bit actually clears it!
35822e75d050STakashi Iwai 	 */
35832e75d050STakashi Iwai 	val = snd_ac97_read(ac97, 0x5c);
35842e75d050STakashi Iwai 	if (!(val & 0x20))
35859f458e7fSAndrey Liakhovets 		snd_ac97_write_cache(ac97, 0x5c, 0x20);
35862e75d050STakashi Iwai 
35874b499486SPhilip Prindeville 	ac97->ext_id |= AC97_EI_SPDIF;	/* force the detection of spdif */
35884b499486SPhilip Prindeville 	ac97->rates[AC97_RATES_SPDIF] = SNDRV_PCM_RATE_44100 | SNDRV_PCM_RATE_48000;
35899f428175SDaniel Jacobowitz 	ac97->build_ops = &patch_vt1616_ops;
3590e9024cccSJohn Utz 
3591e9024cccSJohn Utz 	return err;
35924b499486SPhilip Prindeville }
35934b499486SPhilip Prindeville 
35949e285e1aSJohn L. Utz III /* VIA VT1618 8 CHANNEL AC97 CODEC
35959e285e1aSJohn L. Utz III  *
35969e285e1aSJohn L. Utz III  * VIA implements 'Smart 5.1' completely differently on the 1618 than
35979e285e1aSJohn L. Utz III  * it does on the 1617a. awesome! They seem to have sourced this
35989e285e1aSJohn L. Utz III  * particular revision of the technology from somebody else, it's
35999e285e1aSJohn L. Utz III  * called Universal Audio Jack and it shows up on some other folk's chips
36009e285e1aSJohn L. Utz III  * as well.
36019e285e1aSJohn L. Utz III  *
36029e285e1aSJohn L. Utz III  * ordering in this list reflects vt1618 docs for Reg 60h and
36039e285e1aSJohn L. Utz III  * the block diagram, DACs are as follows:
36049e285e1aSJohn L. Utz III  *
36059e285e1aSJohn L. Utz III  *        OUT_O -> Front,
36069e285e1aSJohn L. Utz III  *	  OUT_1 -> Surround,
36079e285e1aSJohn L. Utz III  *	  OUT_2 -> C/LFE
36089e285e1aSJohn L. Utz III  *
36099e285e1aSJohn L. Utz III  * Unlike the 1617a, each OUT has a consistent set of mappings
36109e285e1aSJohn L. Utz III  * for all bitpatterns other than 00:
36119e285e1aSJohn L. Utz III  *
36129e285e1aSJohn L. Utz III  *        01       Unmixed Output
36139e285e1aSJohn L. Utz III  *        10       Line In
36149e285e1aSJohn L. Utz III  *        11       Mic  In
36159e285e1aSJohn L. Utz III  *
36169e285e1aSJohn L. Utz III  * Special Case of 00:
36179e285e1aSJohn L. Utz III  *
36189e285e1aSJohn L. Utz III  *        OUT_0    Mixed Output
36199e285e1aSJohn L. Utz III  *        OUT_1    Reserved
36209e285e1aSJohn L. Utz III  *        OUT_2    Reserved
36219e285e1aSJohn L. Utz III  *
36229e285e1aSJohn L. Utz III  * I have no idea what the hell Reserved does, but on an MSI
36239e285e1aSJohn L. Utz III  * CN700T, i have to set it to get 5.1 output - YMMV, bad
36249e285e1aSJohn L. Utz III  * shit may happen.
36259e285e1aSJohn L. Utz III  *
36269e285e1aSJohn L. Utz III  * If other chips use Universal Audio Jack, then this code might be applicable
36279e285e1aSJohn L. Utz III  * to them.
36289e285e1aSJohn L. Utz III  */
36299e285e1aSJohn L. Utz III 
36309e285e1aSJohn L. Utz III struct vt1618_uaj_item {
36319e285e1aSJohn L. Utz III 	unsigned short mask;
36329e285e1aSJohn L. Utz III 	unsigned short shift;
36331bc10bb6STakashi Iwai 	const char * const items[4];
36349e285e1aSJohn L. Utz III };
36359e285e1aSJohn L. Utz III 
36369e285e1aSJohn L. Utz III /* This list reflects the vt1618 docs for Vendor Defined Register 0x60. */
36379e285e1aSJohn L. Utz III 
36381675bfc0STakashi Iwai static const struct vt1618_uaj_item vt1618_uaj[3] = {
36399e285e1aSJohn L. Utz III 	{
36409e285e1aSJohn L. Utz III 		/* speaker jack */
36419e285e1aSJohn L. Utz III 		.mask  = 0x03,
36429e285e1aSJohn L. Utz III 		.shift = 0,
36439e285e1aSJohn L. Utz III 		.items = {
36449e285e1aSJohn L. Utz III 			"Speaker Out", "DAC Unmixed Out", "Line In", "Mic In"
36459e285e1aSJohn L. Utz III 		}
36469e285e1aSJohn L. Utz III 	},
36479e285e1aSJohn L. Utz III 	{
36489e285e1aSJohn L. Utz III 		/* line jack */
36499e285e1aSJohn L. Utz III 		.mask  = 0x0c,
36509e285e1aSJohn L. Utz III 		.shift = 2,
36519e285e1aSJohn L. Utz III 		.items = {
36529e285e1aSJohn L. Utz III 			"Surround Out", "DAC Unmixed Out", "Line In", "Mic In"
36539e285e1aSJohn L. Utz III 		}
36549e285e1aSJohn L. Utz III 	},
36559e285e1aSJohn L. Utz III 	{
36569e285e1aSJohn L. Utz III 		/* mic jack */
36579e285e1aSJohn L. Utz III 		.mask  = 0x30,
36589e285e1aSJohn L. Utz III 		.shift = 4,
36599e285e1aSJohn L. Utz III 		.items = {
36609e285e1aSJohn L. Utz III 			"Center LFE Out", "DAC Unmixed Out", "Line In", "Mic In"
36619e285e1aSJohn L. Utz III 		},
36629e285e1aSJohn L. Utz III 	},
36639e285e1aSJohn L. Utz III };
36649e285e1aSJohn L. Utz III 
36659e285e1aSJohn L. Utz III static int snd_ac97_vt1618_UAJ_info(struct snd_kcontrol *kcontrol,
36669e285e1aSJohn L. Utz III 				    struct snd_ctl_elem_info *uinfo)
36679e285e1aSJohn L. Utz III {
36683b7a00dcSTakashi Iwai 	return snd_ctl_enum_info(uinfo, 1, 4,
36693b7a00dcSTakashi Iwai 				 vt1618_uaj[kcontrol->private_value].items);
36709e285e1aSJohn L. Utz III }
36719e285e1aSJohn L. Utz III 
36729e285e1aSJohn L. Utz III /* All of the vt1618 Universal Audio Jack twiddlers are on
36739e285e1aSJohn L. Utz III  * Vendor Defined Register 0x60, page 0. The bits, and thus
36749e285e1aSJohn L. Utz III  * the mask, are the only thing that changes
36759e285e1aSJohn L. Utz III  */
36769e285e1aSJohn L. Utz III static int snd_ac97_vt1618_UAJ_get(struct snd_kcontrol *kcontrol,
36779e285e1aSJohn L. Utz III 				   struct snd_ctl_elem_value *ucontrol)
36789e285e1aSJohn L. Utz III {
36799e285e1aSJohn L. Utz III 	unsigned short datpag, uaj;
36809e285e1aSJohn L. Utz III 	struct snd_ac97 *pac97 = snd_kcontrol_chip(kcontrol);
36819e285e1aSJohn L. Utz III 
36829e285e1aSJohn L. Utz III 	mutex_lock(&pac97->page_mutex);
36839e285e1aSJohn L. Utz III 
36849e285e1aSJohn L. Utz III 	datpag = snd_ac97_read(pac97, AC97_INT_PAGING) & AC97_PAGE_MASK;
36859e285e1aSJohn L. Utz III 	snd_ac97_update_bits(pac97, AC97_INT_PAGING, AC97_PAGE_MASK, 0);
36869e285e1aSJohn L. Utz III 
36879e285e1aSJohn L. Utz III 	uaj = snd_ac97_read(pac97, 0x60) &
36889e285e1aSJohn L. Utz III 		vt1618_uaj[kcontrol->private_value].mask;
36899e285e1aSJohn L. Utz III 
36909e285e1aSJohn L. Utz III 	snd_ac97_update_bits(pac97, AC97_INT_PAGING, AC97_PAGE_MASK, datpag);
36919e285e1aSJohn L. Utz III 	mutex_unlock(&pac97->page_mutex);
36929e285e1aSJohn L. Utz III 
36939e285e1aSJohn L. Utz III 	ucontrol->value.enumerated.item[0] = uaj >>
36949e285e1aSJohn L. Utz III 		vt1618_uaj[kcontrol->private_value].shift;
36959e285e1aSJohn L. Utz III 
36969e285e1aSJohn L. Utz III 	return 0;
36979e285e1aSJohn L. Utz III }
36989e285e1aSJohn L. Utz III 
36999e285e1aSJohn L. Utz III static int snd_ac97_vt1618_UAJ_put(struct snd_kcontrol *kcontrol,
37009e285e1aSJohn L. Utz III 				   struct snd_ctl_elem_value *ucontrol)
37019e285e1aSJohn L. Utz III {
37029e285e1aSJohn L. Utz III 	return ac97_update_bits_page(snd_kcontrol_chip(kcontrol), 0x60,
37039e285e1aSJohn L. Utz III 				     vt1618_uaj[kcontrol->private_value].mask,
37049e285e1aSJohn L. Utz III 				     ucontrol->value.enumerated.item[0]<<
37059e285e1aSJohn L. Utz III 				     vt1618_uaj[kcontrol->private_value].shift,
37069e285e1aSJohn L. Utz III 				     0);
37079e285e1aSJohn L. Utz III }
37089e285e1aSJohn L. Utz III 
37099e285e1aSJohn L. Utz III /* config aux in jack - not found on 3 jack motherboards or soundcards */
37109e285e1aSJohn L. Utz III 
37119e285e1aSJohn L. Utz III static int snd_ac97_vt1618_aux_info(struct snd_kcontrol *kcontrol,
37129e285e1aSJohn L. Utz III 				     struct snd_ctl_elem_info *uinfo)
37139e285e1aSJohn L. Utz III {
37143b7a00dcSTakashi Iwai 	static const char * const txt_aux[] = {"Aux In", "Back Surr Out"};
37159e285e1aSJohn L. Utz III 
37163b7a00dcSTakashi Iwai 	return snd_ctl_enum_info(uinfo, 1, 2, txt_aux);
37179e285e1aSJohn L. Utz III }
37189e285e1aSJohn L. Utz III 
37199e285e1aSJohn L. Utz III static int snd_ac97_vt1618_aux_get(struct snd_kcontrol *kcontrol,
37209e285e1aSJohn L. Utz III 				   struct snd_ctl_elem_value *ucontrol)
37219e285e1aSJohn L. Utz III {
37229e285e1aSJohn L. Utz III 	ucontrol->value.enumerated.item[0] =
37239e285e1aSJohn L. Utz III 		(snd_ac97_read(snd_kcontrol_chip(kcontrol), 0x5c) & 0x0008)>>3;
37249e285e1aSJohn L. Utz III 	return 0;
37259e285e1aSJohn L. Utz III }
37269e285e1aSJohn L. Utz III 
37279e285e1aSJohn L. Utz III static int snd_ac97_vt1618_aux_put(struct snd_kcontrol *kcontrol,
37289e285e1aSJohn L. Utz III 				   struct snd_ctl_elem_value *ucontrol)
37299e285e1aSJohn L. Utz III {
37309e285e1aSJohn L. Utz III 	/* toggle surround rear dac power */
37319e285e1aSJohn L. Utz III 
37329e285e1aSJohn L. Utz III 	snd_ac97_update_bits(snd_kcontrol_chip(kcontrol), 0x5c, 0x0008,
37339e285e1aSJohn L. Utz III 			     ucontrol->value.enumerated.item[0] << 3);
37349e285e1aSJohn L. Utz III 
37359e285e1aSJohn L. Utz III 	/* toggle aux in surround rear out jack */
37369e285e1aSJohn L. Utz III 
37379e285e1aSJohn L. Utz III 	return snd_ac97_update_bits(snd_kcontrol_chip(kcontrol), 0x76, 0x0008,
37389e285e1aSJohn L. Utz III 				    ucontrol->value.enumerated.item[0] << 3);
37399e285e1aSJohn L. Utz III }
37409e285e1aSJohn L. Utz III 
37419e285e1aSJohn L. Utz III static const struct snd_kcontrol_new snd_ac97_controls_vt1618[] = {
37429e285e1aSJohn L. Utz III 	AC97_SINGLE("Exchange Center/LFE", 0x5a,  8, 1,     0),
37439e285e1aSJohn L. Utz III 	AC97_SINGLE("DC Offset",           0x5a, 10, 1,     0),
37449e285e1aSJohn L. Utz III 	AC97_SINGLE("Soft Mute",           0x5c,  0, 1,     1),
37459e285e1aSJohn L. Utz III 	AC97_SINGLE("Headphone Amp",       0x5c,  5, 1,     1),
37469e285e1aSJohn L. Utz III 	AC97_DOUBLE("Back Surr Volume",    0x5e,  8, 0, 31, 1),
37479e285e1aSJohn L. Utz III 	AC97_SINGLE("Back Surr Switch",    0x5e, 15, 1,     1),
37489e285e1aSJohn L. Utz III 	{
37499e285e1aSJohn L. Utz III 		.iface         = SNDRV_CTL_ELEM_IFACE_MIXER,
37509e285e1aSJohn L. Utz III 		.name          = "Speaker Jack Mode",
37519e285e1aSJohn L. Utz III 		.info          = snd_ac97_vt1618_UAJ_info,
37529e285e1aSJohn L. Utz III 		.get           = snd_ac97_vt1618_UAJ_get,
37539e285e1aSJohn L. Utz III 		.put           = snd_ac97_vt1618_UAJ_put,
37549e285e1aSJohn L. Utz III 		.private_value = 0
37559e285e1aSJohn L. Utz III 	},
37569e285e1aSJohn L. Utz III 	{
37579e285e1aSJohn L. Utz III 		.iface         = SNDRV_CTL_ELEM_IFACE_MIXER,
37589e285e1aSJohn L. Utz III 		.name          = "Line Jack Mode",
37599e285e1aSJohn L. Utz III 		.info          = snd_ac97_vt1618_UAJ_info,
37609e285e1aSJohn L. Utz III 		.get           = snd_ac97_vt1618_UAJ_get,
37619e285e1aSJohn L. Utz III 		.put           = snd_ac97_vt1618_UAJ_put,
37629e285e1aSJohn L. Utz III 		.private_value = 1
37639e285e1aSJohn L. Utz III 	},
37649e285e1aSJohn L. Utz III 	{
37659e285e1aSJohn L. Utz III 		.iface         = SNDRV_CTL_ELEM_IFACE_MIXER,
37669e285e1aSJohn L. Utz III 		.name          = "Mic Jack Mode",
37679e285e1aSJohn L. Utz III 		.info          = snd_ac97_vt1618_UAJ_info,
37689e285e1aSJohn L. Utz III 		.get           = snd_ac97_vt1618_UAJ_get,
37699e285e1aSJohn L. Utz III 		.put           = snd_ac97_vt1618_UAJ_put,
37709e285e1aSJohn L. Utz III 		.private_value = 2
37719e285e1aSJohn L. Utz III 	},
37729e285e1aSJohn L. Utz III 	{
37739e285e1aSJohn L. Utz III 		.iface         = SNDRV_CTL_ELEM_IFACE_MIXER,
37749e285e1aSJohn L. Utz III 		.name          = "Aux Jack Mode",
37759e285e1aSJohn L. Utz III 		.info          = snd_ac97_vt1618_aux_info,
37769e285e1aSJohn L. Utz III 		.get           = snd_ac97_vt1618_aux_get,
37779e285e1aSJohn L. Utz III 		.put           = snd_ac97_vt1618_aux_put,
37789e285e1aSJohn L. Utz III 	}
37799e285e1aSJohn L. Utz III };
37809e285e1aSJohn L. Utz III 
3781b03671a8SHarvey Harrison static int patch_vt1618(struct snd_ac97 *ac97)
37829e285e1aSJohn L. Utz III {
37839e285e1aSJohn L. Utz III 	return patch_build_controls(ac97, snd_ac97_controls_vt1618,
37849e285e1aSJohn L. Utz III 				    ARRAY_SIZE(snd_ac97_controls_vt1618));
37859e285e1aSJohn L. Utz III }
37869e285e1aSJohn L. Utz III 
37874b499486SPhilip Prindeville /*
3788eb8caf30STakashi Iwai  */
3789ee42381eSTakashi Iwai static void it2646_update_jacks(struct snd_ac97 *ac97)
3790eb8caf30STakashi Iwai {
3791831466f4SRandy Cushman 	/* shared Line-In / Surround Out */
3792eb8caf30STakashi Iwai 	snd_ac97_update_bits(ac97, 0x76, 1 << 9,
3793831466f4SRandy Cushman 			     is_shared_surrout(ac97) ? (1<<9) : 0);
3794831466f4SRandy Cushman 	/* shared Mic / Center/LFE Out */
3795eb8caf30STakashi Iwai 	snd_ac97_update_bits(ac97, 0x76, 1 << 10,
3796831466f4SRandy Cushman 			     is_shared_clfeout(ac97) ? (1<<10) : 0);
3797eb8caf30STakashi Iwai }
3798eb8caf30STakashi Iwai 
3799ee42381eSTakashi Iwai static const struct snd_kcontrol_new snd_ac97_controls_it2646[] = {
3800eb8caf30STakashi Iwai 	AC97_SURROUND_JACK_MODE_CTL,
3801eb8caf30STakashi Iwai 	AC97_CHANNEL_MODE_CTL,
38021da177e4SLinus Torvalds };
38031da177e4SLinus Torvalds 
3804ee42381eSTakashi Iwai static const struct snd_kcontrol_new snd_ac97_spdif_controls_it2646[] = {
380510e8d78aSClemens Ladisch 	AC97_SINGLE(SNDRV_CTL_NAME_IEC958("",CAPTURE,SWITCH), 0x76, 11, 1, 0),
38061da177e4SLinus Torvalds 	AC97_SINGLE("Analog to IEC958 Output", 0x76, 12, 1, 0),
38071da177e4SLinus Torvalds 	AC97_SINGLE("IEC958 Input Monitor", 0x76, 13, 1, 0),
38081da177e4SLinus Torvalds };
38091da177e4SLinus Torvalds 
3810ee42381eSTakashi Iwai static int patch_it2646_specific(struct snd_ac97 * ac97)
38111da177e4SLinus Torvalds {
38121da177e4SLinus Torvalds 	int err;
38131da177e4SLinus Torvalds 	if ((err = patch_build_controls(ac97, snd_ac97_controls_it2646, ARRAY_SIZE(snd_ac97_controls_it2646))) < 0)
38141da177e4SLinus Torvalds 		return err;
38151da177e4SLinus Torvalds 	if ((err = patch_build_controls(ac97, snd_ac97_spdif_controls_it2646, ARRAY_SIZE(snd_ac97_spdif_controls_it2646))) < 0)
38161da177e4SLinus Torvalds 		return err;
38171da177e4SLinus Torvalds 	return 0;
38181da177e4SLinus Torvalds }
38191da177e4SLinus Torvalds 
38203e8b3b90SHanno Boeck static const struct snd_ac97_build_ops patch_it2646_ops = {
3821eb8caf30STakashi Iwai 	.build_specific	= patch_it2646_specific,
3822eb8caf30STakashi Iwai 	.update_jacks = it2646_update_jacks
38231da177e4SLinus Torvalds };
38241da177e4SLinus Torvalds 
3825ac519028STakashi Iwai static int patch_it2646(struct snd_ac97 * ac97)
38261da177e4SLinus Torvalds {
38271da177e4SLinus Torvalds 	ac97->build_ops = &patch_it2646_ops;
38281da177e4SLinus Torvalds 	/* full DAC volume */
38291da177e4SLinus Torvalds 	snd_ac97_write_cache(ac97, 0x5E, 0x0808);
38301da177e4SLinus Torvalds 	snd_ac97_write_cache(ac97, 0x7A, 0x0808);
38311da177e4SLinus Torvalds 	return 0;
38321da177e4SLinus Torvalds }
38331da177e4SLinus Torvalds 
383487d61c29SSasha Khapyorsky /*
383587d61c29SSasha Khapyorsky  * Si3036 codec
383687d61c29SSasha Khapyorsky  */
383787d61c29SSasha Khapyorsky 
38381da177e4SLinus Torvalds #define AC97_SI3036_CHIP_ID     0x5a
383987d61c29SSasha Khapyorsky #define AC97_SI3036_LINE_CFG    0x5c
384087d61c29SSasha Khapyorsky 
3841ee42381eSTakashi Iwai static const struct snd_kcontrol_new snd_ac97_controls_si3036[] = {
384287d61c29SSasha Khapyorsky AC97_DOUBLE("Modem Speaker Volume", 0x5c, 14, 12, 3, 1)
384387d61c29SSasha Khapyorsky };
384487d61c29SSasha Khapyorsky 
3845ee42381eSTakashi Iwai static int patch_si3036_specific(struct snd_ac97 * ac97)
384687d61c29SSasha Khapyorsky {
384727bcaa69SSasha Khapyorsky 	int idx, err;
384827bcaa69SSasha Khapyorsky 	for (idx = 0; idx < ARRAY_SIZE(snd_ac97_controls_si3036); idx++)
384927bcaa69SSasha Khapyorsky 		if ((err = snd_ctl_add(ac97->bus->card, snd_ctl_new1(&snd_ac97_controls_si3036[idx], ac97))) < 0)
385027bcaa69SSasha Khapyorsky 			return err;
385127bcaa69SSasha Khapyorsky 	return 0;
385287d61c29SSasha Khapyorsky }
385387d61c29SSasha Khapyorsky 
38543e8b3b90SHanno Boeck static const struct snd_ac97_build_ops patch_si3036_ops = {
385587d61c29SSasha Khapyorsky 	.build_specific	= patch_si3036_specific,
385687d61c29SSasha Khapyorsky };
38571da177e4SLinus Torvalds 
3858ac519028STakashi Iwai static int mpatch_si3036(struct snd_ac97 * ac97)
38591da177e4SLinus Torvalds {
386087d61c29SSasha Khapyorsky 	ac97->build_ops = &patch_si3036_ops;
38611da177e4SLinus Torvalds 	snd_ac97_write_cache(ac97, 0x5c, 0xf210 );
38621da177e4SLinus Torvalds 	snd_ac97_write_cache(ac97, 0x68, 0);
38631da177e4SLinus Torvalds 	return 0;
38641da177e4SLinus Torvalds }
3865ba22429dSCharl Coetzee 
3866ba22429dSCharl Coetzee /*
3867ba22429dSCharl Coetzee  * LM 4550 Codec
3868ba22429dSCharl Coetzee  *
3869ba22429dSCharl Coetzee  * We use a static resolution table since LM4550 codec cannot be
3870ba22429dSCharl Coetzee  * properly autoprobed to determine the resolution via
3871ba22429dSCharl Coetzee  * check_volume_resolution().
3872ba22429dSCharl Coetzee  */
3873ba22429dSCharl Coetzee 
3874c0476b98STakashi Iwai static const struct snd_ac97_res_table lm4550_restbl[] = {
3875ba22429dSCharl Coetzee 	{ AC97_MASTER, 0x1f1f },
3876ba22429dSCharl Coetzee 	{ AC97_HEADPHONE, 0x1f1f },
3877ba22429dSCharl Coetzee 	{ AC97_MASTER_MONO, 0x001f },
3878ba22429dSCharl Coetzee 	{ AC97_PC_BEEP, 0x001f },	/* LSB is ignored */
3879ba22429dSCharl Coetzee 	{ AC97_PHONE, 0x001f },
3880ba22429dSCharl Coetzee 	{ AC97_MIC, 0x001f },
3881ba22429dSCharl Coetzee 	{ AC97_LINE, 0x1f1f },
3882ba22429dSCharl Coetzee 	{ AC97_CD, 0x1f1f },
3883ba22429dSCharl Coetzee 	{ AC97_VIDEO, 0x1f1f },
3884ba22429dSCharl Coetzee 	{ AC97_AUX, 0x1f1f },
3885ba22429dSCharl Coetzee 	{ AC97_PCM, 0x1f1f },
3886ba22429dSCharl Coetzee 	{ AC97_REC_GAIN, 0x0f0f },
3887ba22429dSCharl Coetzee 	{ } /* terminator */
3888ba22429dSCharl Coetzee };
3889ba22429dSCharl Coetzee 
3890ac519028STakashi Iwai static int patch_lm4550(struct snd_ac97 *ac97)
3891ba22429dSCharl Coetzee {
3892ba22429dSCharl Coetzee 	ac97->res_table = lm4550_restbl;
3893ba22429dSCharl Coetzee 	return 0;
3894ba22429dSCharl Coetzee }
389582466ad7SMike Rapoport 
389682466ad7SMike Rapoport /*
389782466ad7SMike Rapoport  *  UCB1400 codec (http://www.semiconductors.philips.com/acrobat_download/datasheets/UCB1400-02.pdf)
389882466ad7SMike Rapoport  */
389982466ad7SMike Rapoport static const struct snd_kcontrol_new snd_ac97_controls_ucb1400[] = {
390082466ad7SMike Rapoport /* enable/disable headphone driver which allows direct connection to
390182466ad7SMike Rapoport    stereo headphone without the use of external DC blocking
390282466ad7SMike Rapoport    capacitors */
390382466ad7SMike Rapoport AC97_SINGLE("Headphone Driver", 0x6a, 6, 1, 0),
390482466ad7SMike Rapoport /* Filter used to compensate the DC offset is added in the ADC to remove idle
390582466ad7SMike Rapoport    tones from the audio band. */
390682466ad7SMike Rapoport AC97_SINGLE("DC Filter", 0x6a, 4, 1, 0),
390782466ad7SMike Rapoport /* Control smart-low-power mode feature. Allows automatic power down
390882466ad7SMike Rapoport    of unused blocks in the ADC analog front end and the PLL. */
390982466ad7SMike Rapoport AC97_SINGLE("Smart Low Power Mode", 0x6c, 4, 3, 0),
391082466ad7SMike Rapoport };
391182466ad7SMike Rapoport 
391282466ad7SMike Rapoport static int patch_ucb1400_specific(struct snd_ac97 * ac97)
391382466ad7SMike Rapoport {
391482466ad7SMike Rapoport 	int idx, err;
391582466ad7SMike Rapoport 	for (idx = 0; idx < ARRAY_SIZE(snd_ac97_controls_ucb1400); idx++)
391682466ad7SMike Rapoport 		if ((err = snd_ctl_add(ac97->bus->card, snd_ctl_new1(&snd_ac97_controls_ucb1400[idx], ac97))) < 0)
391782466ad7SMike Rapoport 			return err;
391882466ad7SMike Rapoport 	return 0;
391982466ad7SMike Rapoport }
392082466ad7SMike Rapoport 
39213e8b3b90SHanno Boeck static const struct snd_ac97_build_ops patch_ucb1400_ops = {
392282466ad7SMike Rapoport 	.build_specific	= patch_ucb1400_specific,
392382466ad7SMike Rapoport };
392482466ad7SMike Rapoport 
3925ac519028STakashi Iwai static int patch_ucb1400(struct snd_ac97 * ac97)
392682466ad7SMike Rapoport {
392782466ad7SMike Rapoport 	ac97->build_ops = &patch_ucb1400_ops;
392882466ad7SMike Rapoport 	/* enable headphone driver and smart low power mode by default */
392925552e87SMike Rapoport 	snd_ac97_write_cache(ac97, 0x6a, 0x0050);
393025552e87SMike Rapoport 	snd_ac97_write_cache(ac97, 0x6c, 0x0030);
393182466ad7SMike Rapoport 	return 0;
393282466ad7SMike Rapoport }
3933